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;
40 with Ada.Characters.Handling; use Ada.Characters.Handling;
41 with Ada.Directories; use Ada.Directories;
42 with Ada.Strings; use Ada.Strings;
43 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
44 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
46 with GNAT.Case_Util; use GNAT.Case_Util;
47 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
48 with GNAT.Dynamic_HTables;
49 with GNAT.Regexp; use GNAT.Regexp;
52 package body Prj.Nmsc is
54 No_Continuation_String : aliased String := "";
55 Continuation_String : aliased String := "\";
56 -- Used in Check_Library for continuation error messages at the same
59 type Name_Location is record
60 Name : File_Name_Type;
61 -- Key is duplicated, so that it is known when using functions Get_First
62 -- and Get_Next, as these functions only return an Element.
64 Location : Source_Ptr;
65 Source : Source_Id := No_Source;
66 Listed : Boolean := False;
67 Found : Boolean := False;
70 No_Name_Location : constant Name_Location :=
72 Location => No_Location,
77 package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
78 (Header_Num => Header_Num,
79 Element => Name_Location,
80 No_Element => No_Name_Location,
81 Key => File_Name_Type,
84 -- File name information found in string list attribute (Source_Files or
85 -- Source_List_File). 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 : Naming_Exception_Type := No;
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_Abstract_Project
285 (Project : Project_Id;
286 Data : in out Tree_Processing_Data);
287 -- Check abstract projects attributes
289 procedure Check_Configuration
290 (Project : Project_Id;
291 Data : in out Tree_Processing_Data);
292 -- Check the configuration attributes for the project
294 procedure Check_If_Externally_Built
295 (Project : Project_Id;
296 Data : in out Tree_Processing_Data);
297 -- Check attribute Externally_Built of project Project in project tree
298 -- Data.Tree and modify its data Data if it has the value "true".
300 procedure Check_Interfaces
301 (Project : Project_Id;
302 Data : in out Tree_Processing_Data);
303 -- If a list of sources is specified in attribute Interfaces, set
304 -- In_Interfaces only for the sources specified in the list.
306 procedure Check_Library_Attributes
307 (Project : Project_Id;
308 Data : in out Tree_Processing_Data);
309 -- Check the library attributes of project Project in project tree
310 -- and modify its data Data accordingly.
312 procedure Check_Package_Naming
313 (Project : Project_Id;
314 Data : in out Tree_Processing_Data);
315 -- Check the naming scheme part of Data, and initialize the naming scheme
316 -- data in the config of the various languages.
318 procedure Check_Programming_Languages
319 (Project : Project_Id;
320 Data : in out Tree_Processing_Data);
321 -- Check attribute Languages for the project with data Data in project
322 -- tree Data.Tree and set the components of Data for all the programming
323 -- languages indicated in attribute Languages, if any.
325 procedure Check_Stand_Alone_Library
326 (Project : Project_Id;
327 Data : in out Tree_Processing_Data);
328 -- Check if project Project in project tree Data.Tree is a Stand-Alone
329 -- Library project, and modify its data Data accordingly if it is one.
331 procedure Check_Unit_Name (Name : String; Unit : out Name_Id);
332 -- Check that a name is a valid unit name
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 : Naming_Exception_Type := No;
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 and then Source.Index = Index then
673 -- Duplication of file/unit in same project is allowed if order of
674 -- source directories is known, or if there is no compiler for the
677 if Add_Src = False then
680 if Project = Source.Project then
681 if Prev_Unit = No_Unit_Index then
682 if Data.Flags.Allow_Duplicate_Basenames then
685 elsif Lang_Id.Config.Compiler_Driver = Empty_File then
688 elsif Source_Dir_Rank /= Source.Source_Dir_Rank then
692 Error_Msg_File_1 := File_Name;
694 (Data.Flags, "duplicate source file name {",
700 if Source_Dir_Rank /= Source.Source_Dir_Rank then
703 -- We might be seeing the same file through a different path
704 -- (for instance because of symbolic links).
706 elsif Source.Path.Name /= Path.Name then
707 if not Source.Duplicate_Unit then
708 Error_Msg_Name_1 := Unit;
710 (Data.Flags, "\duplicate unit %%", Location, Project);
711 Source.Duplicate_Unit := True;
718 -- Do not allow the same unit name in different projects, except
719 -- if one is extending the other.
721 -- For a file based language, the same file name replaces a file
722 -- in a project being extended, but it is allowed to have the same
723 -- file name in unrelated projects.
725 elsif Is_Extending (Project, Source.Project) then
726 if not Locally_Removed and then Naming_Exception /= Inherited then
727 Source_To_Replace := Source;
730 elsif Prev_Unit /= No_Unit_Index
731 and then Prev_Unit.File_Names (Kind) /= null
732 and then not Source.Locally_Removed
734 -- Path is set if this is a source we found on the disk, in which
735 -- case we can provide more explicit error message. Path is unset
736 -- when the source is added from one of the naming exceptions in
739 if Path /= No_Path_Information then
740 Error_Msg_Name_1 := Unit;
743 "unit %% cannot belong to several projects",
746 Error_Msg_Name_1 := Project.Name;
747 Error_Msg_Name_2 := Name_Id (Path.Display_Name);
749 (Data.Flags, "\ project %%, %%", Location, Project);
751 Error_Msg_Name_1 := Source.Project.Name;
752 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
754 (Data.Flags, "\ project %%, %%", Location, Project);
757 Error_Msg_Name_1 := Unit;
758 Error_Msg_Name_2 := Source.Project.Name;
760 (Data.Flags, "unit %% already belongs to project %%",
766 elsif not Source.Locally_Removed
767 and then not Data.Flags.Allow_Duplicate_Basenames
768 and then Lang_Id.Config.Kind = Unit_Based
769 and then Source.Language.Config.Kind = Unit_Based
771 Error_Msg_File_1 := File_Name;
772 Error_Msg_File_2 := File_Name_Type (Source.Project.Name);
775 "{ is already a source of project {", Location, Project);
777 -- Add the file anyway, to avoid further warnings like "language
790 Id := new Source_Data;
792 if Current_Verbosity = High then
794 Write_Str ("adding source File: ");
795 Write_Str (Get_Name_String (Display_File));
798 Write_Str (" at" & Index'Img);
801 if Lang_Id.Config.Kind = Unit_Based then
802 Write_Str (" Unit: ");
804 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
805 -- (see test extended_projects).
807 if Unit /= No_Name then
808 Write_Str (Get_Name_String (Unit));
811 Write_Str (" Kind: ");
812 Write_Str (Source_Kind'Image (Kind));
818 Id.Project := Project;
819 Id.Location := Location;
820 Id.Source_Dir_Rank := Source_Dir_Rank;
821 Id.Language := Lang_Id;
823 Id.Alternate_Languages := Alternate_Languages;
824 Id.Locally_Removed := Locally_Removed;
826 Id.File := File_Name;
827 Id.Display_File := Display_File;
828 Id.Dep_Name := Dependency_Name
829 (File_Name, Lang_Id.Config.Dependency_Kind);
830 Id.Naming_Exception := Naming_Exception;
831 Id.Object := Object_Name
832 (File_Name, Config.Object_File_Suffix);
833 Id.Switches := Switches_Name (File_Name);
835 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
838 if Unit /= No_Name then
840 -- Note: we might be creating a dummy unit here, when we in fact have
841 -- a separate. For instance, file file-bar.adb will initially be
842 -- assumed to be the IMPL of unit "file.bar". Only later on (in
843 -- Check_Object_Files) will we parse those units that only have an
844 -- impl and no spec to make sure whether we have a Separate in fact
845 -- (that significantly reduces the number of times we need to parse
846 -- the files, since we are then only interested in those with no
847 -- spec). We still need those dummy units in the table, since that's
848 -- the name we find in the ALI file
850 UData := Units_Htable.Get (Data.Tree.Units_HT, Unit);
852 if UData = No_Unit_Index then
853 UData := new Unit_Data;
856 if Naming_Exception /= Inherited then
857 Units_Htable.Set (Data.Tree.Units_HT, Unit, UData);
863 -- Note that this updates Unit information as well
865 if Naming_Exception /= Inherited then
866 Override_Kind (Id, Kind);
870 if Path /= No_Path_Information then
872 Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id);
875 Id.Next_With_File_Name :=
876 Source_Files_Htable.Get (Data.Tree.Source_Files_HT, File_Name);
877 Source_Files_Htable.Set (Data.Tree.Source_Files_HT, File_Name, Id);
880 Project.Has_Multi_Unit_Sources := True;
883 -- Add the source to the language list
885 Id.Next_In_Lang := Lang_Id.First_Source;
886 Lang_Id.First_Source := Id;
888 if Source_To_Replace /= No_Source then
889 Remove_Source (Data.Tree, Source_To_Replace, Id);
892 if Data.Tree.Replaced_Source_Number > 0
894 Replaced_Source_HTable.Get
895 (Data.Tree.Replaced_Sources, Id.File) /= No_File
897 Replaced_Source_HTable.Remove (Data.Tree.Replaced_Sources, Id.File);
898 Data.Tree.Replaced_Source_Number :=
899 Data.Tree.Replaced_Source_Number - 1;
903 ------------------------------
904 -- Canonical_Case_File_Name --
905 ------------------------------
907 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
909 if Osint.File_Names_Case_Sensitive then
910 return File_Name_Type (Name);
912 Get_Name_String (Name);
913 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
916 end Canonical_Case_File_Name;
918 ---------------------------------
919 -- Process_Aggregated_Projects --
920 ---------------------------------
922 procedure Process_Aggregated_Projects
923 (Tree : Project_Tree_Ref;
924 Project : Project_Id;
925 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
926 Flags : Processing_Flags)
928 Data : Tree_Processing_Data :=
930 Node_Tree => Node_Tree,
933 Project_Files : constant Prj.Variable_Value :=
935 (Snames.Name_Project_Files,
936 Project.Decl.Attributes,
939 Project_Path_For_Aggregate : Prj.Env.Project_Search_Path;
941 procedure Found_Project_File (Path : Path_Information; Rank : Natural);
942 -- Called for each project file aggregated by Project
944 procedure Expand_Project_Files is
945 new Expand_Subdirectory_Pattern (Callback => Found_Project_File);
946 -- Search for all project files referenced by the patterns given in
947 -- parameter. Calls Found_Project_File for each of them.
949 ------------------------
950 -- Found_Project_File --
951 ------------------------
953 procedure Found_Project_File (Path : Path_Information; Rank : Natural) is
954 pragma Unreferenced (Rank);
957 if Path.Name /= Project.Path.Name then
958 Debug_Output ("aggregates: ", Name_Id (Path.Display_Name));
960 -- For usual "with" statement, this phase will have been done when
961 -- parsing the project itself. However, for aggregate projects, we
962 -- can only do this when processing the aggregate project, since
963 -- the exact list of project files or project directories can
964 -- depend on scenario variables.
966 -- We only load the projects explicitly here, but do not process
967 -- them. For the processing, Prj.Proc will take care of processing
968 -- them, within the same call to Recursive_Process (thus avoiding
969 -- the processing of a given project multiple times).
971 -- ??? We might already have loaded the project
973 Add_Aggregated_Project (Project, Path => Path.Name);
976 Debug_Output ("pattern returned the aggregate itself, ignored");
978 end Found_Project_File;
980 -- Start of processing for Check_Aggregate_Project
983 pragma Assert (Project.Qualifier in Aggregate_Project);
985 if Project_Files.Default then
986 Error_Msg_Name_1 := Snames.Name_Project_Files;
989 "Attribute %% must be specified in aggregate project",
990 Project.Location, Project);
994 -- The aggregated projects are only searched relative to the directory
995 -- of the aggregate project, not in the default project path.
997 Initialize_Empty (Project_Path_For_Aggregate);
999 Free (Project.Aggregated_Projects);
1001 -- Look for aggregated projects. For similarity with source files and
1002 -- dirs, the aggregated project files are not searched for on the
1003 -- project path, and are only found through the path specified in
1004 -- the Project_Files attribute.
1006 Expand_Project_Files
1007 (Project => Project,
1009 Patterns => Project_Files.Values,
1010 Ignore => Nil_String,
1011 Search_For => Search_Files,
1012 Resolve_Links => Opt.Follow_Links_For_Files);
1014 Free (Project_Path_For_Aggregate);
1015 end Process_Aggregated_Projects;
1022 (Project : Project_Id;
1023 Data : in out Tree_Processing_Data)
1025 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
1026 Prj_Data : Project_Processing_Data;
1029 Debug_Increase_Indent ("check", Project.Name);
1031 Initialize (Prj_Data, Project);
1033 Check_If_Externally_Built (Project, Data);
1035 case Project.Qualifier is
1039 when Aggregate_Library =>
1040 if Project.Object_Directory = No_Path_Information then
1041 Project.Object_Directory := Project.Directory;
1045 Get_Directories (Project, Data);
1046 Check_Programming_Languages (Project, Data);
1048 if Current_Verbosity = High then
1049 Show_Source_Dirs (Project, Shared);
1052 if Project.Qualifier = Dry then
1053 Check_Abstract_Project (Project, Data);
1057 -- Check configuration. This must be done even for gnatmake (even though
1058 -- no user configuration file was provided) since the default config we
1059 -- generate indicates whether libraries are supported for instance.
1061 Check_Configuration (Project, Data);
1063 if Project.Qualifier /= Aggregate then
1064 Check_Library_Attributes (Project, Data);
1065 Check_Package_Naming (Project, Data);
1067 -- An aggregate library has no source, no need to look for them
1069 if Project.Qualifier /= Aggregate_Library then
1070 Look_For_Sources (Prj_Data, Data);
1073 Check_Interfaces (Project, Data);
1075 if Project.Library then
1076 Check_Stand_Alone_Library (Project, Data);
1079 Get_Mains (Project, Data);
1084 Debug_Decrease_Indent ("done check");
1087 ----------------------------
1088 -- Check_Abstract_Project --
1089 ----------------------------
1091 procedure Check_Abstract_Project
1092 (Project : Project_Id;
1093 Data : in out Tree_Processing_Data)
1095 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
1097 Source_Dirs : constant Variable_Value :=
1100 Project.Decl.Attributes, Shared);
1101 Source_Files : constant Variable_Value :=
1104 Project.Decl.Attributes, Shared);
1105 Source_List_File : constant Variable_Value :=
1107 (Name_Source_List_File,
1108 Project.Decl.Attributes, Shared);
1109 Languages : constant Variable_Value :=
1112 Project.Decl.Attributes, Shared);
1115 if Project.Source_Dirs /= Nil_String then
1116 if Source_Dirs.Values = Nil_String
1117 and then Source_Files.Values = Nil_String
1118 and then Languages.Values = Nil_String
1119 and then Source_List_File.Default
1121 Project.Source_Dirs := Nil_String;
1126 "at least one of Source_Files, Source_Dirs or Languages "
1127 & "must be declared empty for an abstract project",
1128 Project.Location, Project);
1131 end Check_Abstract_Project;
1133 -------------------------
1134 -- Check_Configuration --
1135 -------------------------
1137 procedure Check_Configuration
1138 (Project : Project_Id;
1139 Data : in out Tree_Processing_Data)
1141 Shared : constant Shared_Project_Tree_Data_Access :=
1144 Dot_Replacement : File_Name_Type := No_File;
1145 Casing : Casing_Type := All_Lower_Case;
1146 Separate_Suffix : File_Name_Type := No_File;
1148 Lang_Index : Language_Ptr := No_Language_Index;
1149 -- The index of the language data being checked
1151 Prev_Index : Language_Ptr := No_Language_Index;
1152 -- The index of the previous language
1154 procedure Process_Project_Level_Simple_Attributes;
1155 -- Process the simple attributes at the project level
1157 procedure Process_Project_Level_Array_Attributes;
1158 -- Process the associate array attributes at the project level
1160 procedure Process_Packages;
1161 -- Read the packages of the project
1163 ----------------------
1164 -- Process_Packages --
1165 ----------------------
1167 procedure Process_Packages is
1168 Packages : Package_Id;
1169 Element : Package_Element;
1171 procedure Process_Binder (Arrays : Array_Id);
1172 -- Process the associate array attributes of package Binder
1174 procedure Process_Builder (Attributes : Variable_Id);
1175 -- Process the simple attributes of package Builder
1177 procedure Process_Compiler (Arrays : Array_Id);
1178 -- Process the associate array attributes of package Compiler
1180 procedure Process_Naming (Attributes : Variable_Id);
1181 -- Process the simple attributes of package Naming
1183 procedure Process_Naming (Arrays : Array_Id);
1184 -- Process the associate array attributes of package Naming
1186 procedure Process_Linker (Attributes : Variable_Id);
1187 -- Process the simple attributes of package Linker of a
1188 -- configuration project.
1190 --------------------
1191 -- Process_Binder --
1192 --------------------
1194 procedure Process_Binder (Arrays : Array_Id) is
1195 Current_Array_Id : Array_Id;
1196 Current_Array : Array_Data;
1197 Element_Id : Array_Element_Id;
1198 Element : Array_Element;
1201 -- Process the associative array attribute of package Binder
1203 Current_Array_Id := Arrays;
1204 while Current_Array_Id /= No_Array loop
1205 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1207 Element_Id := Current_Array.Value;
1208 while Element_Id /= No_Array_Element loop
1209 Element := Shared.Array_Elements.Table (Element_Id);
1211 if Element.Index /= All_Other_Names then
1213 -- Get the name of the language
1216 Get_Language_From_Name
1217 (Project, Get_Name_String (Element.Index));
1219 if Lang_Index /= No_Language_Index then
1220 case Current_Array.Name is
1223 -- Attribute Driver (<language>)
1225 Lang_Index.Config.Binder_Driver :=
1226 File_Name_Type (Element.Value.Value);
1228 when Name_Required_Switches =>
1231 Lang_Index.Config.Binder_Required_Switches,
1232 From_List => Element.Value.Values,
1233 In_Tree => Data.Tree);
1237 -- Attribute Prefix (<language>)
1239 Lang_Index.Config.Binder_Prefix :=
1240 Element.Value.Value;
1242 when Name_Objects_Path =>
1244 -- Attribute Objects_Path (<language>)
1246 Lang_Index.Config.Objects_Path :=
1247 Element.Value.Value;
1249 when Name_Objects_Path_File =>
1251 -- Attribute Objects_Path (<language>)
1253 Lang_Index.Config.Objects_Path_File :=
1254 Element.Value.Value;
1262 Element_Id := Element.Next;
1265 Current_Array_Id := Current_Array.Next;
1269 ---------------------
1270 -- Process_Builder --
1271 ---------------------
1273 procedure Process_Builder (Attributes : Variable_Id) is
1274 Attribute_Id : Variable_Id;
1275 Attribute : Variable;
1278 -- Process non associated array attribute from package Builder
1280 Attribute_Id := Attributes;
1281 while Attribute_Id /= No_Variable loop
1282 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1284 if not Attribute.Value.Default then
1285 if Attribute.Name = Name_Executable_Suffix then
1287 -- Attribute Executable_Suffix: the suffix of the
1290 Project.Config.Executable_Suffix :=
1291 Attribute.Value.Value;
1295 Attribute_Id := Attribute.Next;
1297 end Process_Builder;
1299 ----------------------
1300 -- Process_Compiler --
1301 ----------------------
1303 procedure Process_Compiler (Arrays : Array_Id) is
1304 Current_Array_Id : Array_Id;
1305 Current_Array : Array_Data;
1306 Element_Id : Array_Element_Id;
1307 Element : Array_Element;
1308 List : String_List_Id;
1311 -- Process the associative array attribute of package Compiler
1313 Current_Array_Id := Arrays;
1314 while Current_Array_Id /= No_Array loop
1315 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1317 Element_Id := Current_Array.Value;
1318 while Element_Id /= No_Array_Element loop
1319 Element := Shared.Array_Elements.Table (Element_Id);
1321 if Element.Index /= All_Other_Names then
1323 -- Get the name of the language
1325 Lang_Index := Get_Language_From_Name
1326 (Project, Get_Name_String (Element.Index));
1328 if Lang_Index /= No_Language_Index then
1329 case Current_Array.Name is
1331 -- Attribute Dependency_Kind (<language>)
1333 when Name_Dependency_Kind =>
1334 Get_Name_String (Element.Value.Value);
1337 Lang_Index.Config.Dependency_Kind :=
1338 Dependency_File_Kind'Value
1339 (Name_Buffer (1 .. Name_Len));
1342 when Constraint_Error =>
1345 "illegal value for Dependency_Kind",
1346 Element.Value.Location,
1350 -- Attribute Dependency_Switches (<language>)
1352 when Name_Dependency_Switches =>
1353 if Lang_Index.Config.Dependency_Kind = None then
1354 Lang_Index.Config.Dependency_Kind := Makefile;
1357 List := Element.Value.Values;
1359 if List /= Nil_String then
1361 Lang_Index.Config.Dependency_Option,
1363 In_Tree => Data.Tree);
1366 -- Attribute Dependency_Driver (<language>)
1368 when Name_Dependency_Driver =>
1369 if Lang_Index.Config.Dependency_Kind = None then
1370 Lang_Index.Config.Dependency_Kind := Makefile;
1373 List := Element.Value.Values;
1375 if List /= Nil_String then
1377 Lang_Index.Config.Compute_Dependency,
1379 In_Tree => Data.Tree);
1382 -- Attribute Language_Kind (<language>)
1384 when Name_Language_Kind =>
1385 Get_Name_String (Element.Value.Value);
1388 Lang_Index.Config.Kind :=
1390 (Name_Buffer (1 .. Name_Len));
1393 when Constraint_Error =>
1396 "illegal value for Language_Kind",
1397 Element.Value.Location,
1401 -- Attribute Include_Switches (<language>)
1403 when Name_Include_Switches =>
1404 List := Element.Value.Values;
1406 if List = Nil_String then
1408 (Data.Flags, "include option cannot be null",
1409 Element.Value.Location, Project);
1412 Put (Into_List => Lang_Index.Config.Include_Option,
1414 In_Tree => Data.Tree);
1416 -- Attribute Include_Path (<language>)
1418 when Name_Include_Path =>
1419 Lang_Index.Config.Include_Path :=
1420 Element.Value.Value;
1422 -- Attribute Include_Path_File (<language>)
1424 when Name_Include_Path_File =>
1425 Lang_Index.Config.Include_Path_File :=
1426 Element.Value.Value;
1428 -- Attribute Driver (<language>)
1431 Lang_Index.Config.Compiler_Driver :=
1432 File_Name_Type (Element.Value.Value);
1434 when Name_Required_Switches
1435 | Name_Leading_Required_Switches
1439 Compiler_Leading_Required_Switches,
1440 From_List => Element.Value.Values,
1441 In_Tree => Data.Tree);
1443 when Name_Trailing_Required_Switches =>
1446 Compiler_Trailing_Required_Switches,
1447 From_List => Element.Value.Values,
1448 In_Tree => Data.Tree);
1450 when Name_Multi_Unit_Switches =>
1452 Lang_Index.Config.Multi_Unit_Switches,
1453 From_List => Element.Value.Values,
1454 In_Tree => Data.Tree);
1456 when Name_Multi_Unit_Object_Separator =>
1457 Get_Name_String (Element.Value.Value);
1459 if Name_Len /= 1 then
1462 "multi-unit object separator must have " &
1463 "a single character",
1464 Element.Value.Location, Project);
1466 elsif Name_Buffer (1) = ' ' then
1469 "multi-unit object separator cannot be " &
1471 Element.Value.Location, Project);
1474 Lang_Index.Config.Multi_Unit_Object_Separator :=
1478 when Name_Path_Syntax =>
1480 Lang_Index.Config.Path_Syntax :=
1481 Path_Syntax_Kind'Value
1482 (Get_Name_String (Element.Value.Value));
1485 when Constraint_Error =>
1488 "invalid value for Path_Syntax",
1489 Element.Value.Location, Project);
1492 when Name_Source_File_Switches =>
1494 Lang_Index.Config.Source_File_Switches,
1495 From_List => Element.Value.Values,
1496 In_Tree => Data.Tree);
1498 when Name_Object_File_Suffix =>
1499 if Get_Name_String (Element.Value.Value) = "" then
1502 "object file suffix cannot be empty",
1503 Element.Value.Location, Project);
1506 Lang_Index.Config.Object_File_Suffix :=
1507 Element.Value.Value;
1510 when Name_Object_File_Switches =>
1512 Lang_Index.Config.Object_File_Switches,
1513 From_List => Element.Value.Values,
1514 In_Tree => Data.Tree);
1516 -- Attribute Compiler_Pic_Option (<language>)
1518 when Name_Pic_Option =>
1519 List := Element.Value.Values;
1521 if List = Nil_String then
1524 "compiler PIC option cannot be null",
1525 Element.Value.Location, Project);
1529 Lang_Index.Config.Compilation_PIC_Option,
1531 In_Tree => Data.Tree);
1533 -- Attribute Mapping_File_Switches (<language>)
1535 when Name_Mapping_File_Switches =>
1536 List := Element.Value.Values;
1538 if List = Nil_String then
1541 "mapping file switches cannot be null",
1542 Element.Value.Location, Project);
1546 Lang_Index.Config.Mapping_File_Switches,
1548 In_Tree => Data.Tree);
1550 -- Attribute Mapping_Spec_Suffix (<language>)
1552 when Name_Mapping_Spec_Suffix =>
1553 Lang_Index.Config.Mapping_Spec_Suffix :=
1554 File_Name_Type (Element.Value.Value);
1556 -- Attribute Mapping_Body_Suffix (<language>)
1558 when Name_Mapping_Body_Suffix =>
1559 Lang_Index.Config.Mapping_Body_Suffix :=
1560 File_Name_Type (Element.Value.Value);
1562 -- Attribute Config_File_Switches (<language>)
1564 when Name_Config_File_Switches =>
1565 List := Element.Value.Values;
1567 if List = Nil_String then
1570 "config file switches cannot be null",
1571 Element.Value.Location, Project);
1575 Lang_Index.Config.Config_File_Switches,
1577 In_Tree => Data.Tree);
1579 -- Attribute Objects_Path (<language>)
1581 when Name_Objects_Path =>
1582 Lang_Index.Config.Objects_Path :=
1583 Element.Value.Value;
1585 -- Attribute Objects_Path_File (<language>)
1587 when Name_Objects_Path_File =>
1588 Lang_Index.Config.Objects_Path_File :=
1589 Element.Value.Value;
1591 -- Attribute Config_Body_File_Name (<language>)
1593 when Name_Config_Body_File_Name =>
1594 Lang_Index.Config.Config_Body :=
1595 Element.Value.Value;
1597 -- Attribute Config_Body_File_Name_Index (< Language>)
1599 when Name_Config_Body_File_Name_Index =>
1600 Lang_Index.Config.Config_Body_Index :=
1601 Element.Value.Value;
1603 -- Attribute Config_Body_File_Name_Pattern(<language>)
1605 when Name_Config_Body_File_Name_Pattern =>
1606 Lang_Index.Config.Config_Body_Pattern :=
1607 Element.Value.Value;
1609 -- Attribute Config_Spec_File_Name (<language>)
1611 when Name_Config_Spec_File_Name =>
1612 Lang_Index.Config.Config_Spec :=
1613 Element.Value.Value;
1615 -- Attribute Config_Spec_File_Name_Index (<language>)
1617 when Name_Config_Spec_File_Name_Index =>
1618 Lang_Index.Config.Config_Spec_Index :=
1619 Element.Value.Value;
1621 -- Attribute Config_Spec_File_Name_Pattern(<language>)
1623 when Name_Config_Spec_File_Name_Pattern =>
1624 Lang_Index.Config.Config_Spec_Pattern :=
1625 Element.Value.Value;
1627 -- Attribute Config_File_Unique (<language>)
1629 when Name_Config_File_Unique =>
1631 Lang_Index.Config.Config_File_Unique :=
1633 (Get_Name_String (Element.Value.Value));
1635 when Constraint_Error =>
1638 "illegal value for Config_File_Unique",
1639 Element.Value.Location, Project);
1648 Element_Id := Element.Next;
1651 Current_Array_Id := Current_Array.Next;
1653 end Process_Compiler;
1655 --------------------
1656 -- Process_Naming --
1657 --------------------
1659 procedure Process_Naming (Attributes : Variable_Id) is
1660 Attribute_Id : Variable_Id;
1661 Attribute : Variable;
1664 -- Process non associated array attribute from package Naming
1666 Attribute_Id := Attributes;
1667 while Attribute_Id /= No_Variable loop
1668 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1670 if not Attribute.Value.Default then
1671 if Attribute.Name = Name_Separate_Suffix then
1673 -- Attribute Separate_Suffix
1675 Get_Name_String (Attribute.Value.Value);
1676 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1677 Separate_Suffix := Name_Find;
1679 elsif Attribute.Name = Name_Casing then
1685 Value (Get_Name_String (Attribute.Value.Value));
1688 when Constraint_Error =>
1691 "invalid value for Casing",
1692 Attribute.Value.Location, Project);
1695 elsif Attribute.Name = Name_Dot_Replacement then
1697 -- Attribute Dot_Replacement
1699 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1704 Attribute_Id := Attribute.Next;
1708 procedure Process_Naming (Arrays : Array_Id) is
1709 Current_Array_Id : Array_Id;
1710 Current_Array : Array_Data;
1711 Element_Id : Array_Element_Id;
1712 Element : Array_Element;
1715 -- Process the associative array attribute of package Naming
1717 Current_Array_Id := Arrays;
1718 while Current_Array_Id /= No_Array loop
1719 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1721 Element_Id := Current_Array.Value;
1722 while Element_Id /= No_Array_Element loop
1723 Element := Shared.Array_Elements.Table (Element_Id);
1725 -- Get the name of the language
1727 Lang_Index := Get_Language_From_Name
1728 (Project, Get_Name_String (Element.Index));
1730 if Lang_Index /= No_Language_Index then
1731 case Current_Array.Name is
1732 when Name_Spec_Suffix | Name_Specification_Suffix =>
1734 -- Attribute Spec_Suffix (<language>)
1736 Get_Name_String (Element.Value.Value);
1737 Canonical_Case_File_Name
1738 (Name_Buffer (1 .. Name_Len));
1739 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1742 when Name_Implementation_Suffix | Name_Body_Suffix =>
1744 Get_Name_String (Element.Value.Value);
1745 Canonical_Case_File_Name
1746 (Name_Buffer (1 .. Name_Len));
1748 -- Attribute Body_Suffix (<language>)
1750 Lang_Index.Config.Naming_Data.Body_Suffix :=
1752 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1753 Lang_Index.Config.Naming_Data.Body_Suffix;
1760 Element_Id := Element.Next;
1763 Current_Array_Id := Current_Array.Next;
1767 --------------------
1768 -- Process_Linker --
1769 --------------------
1771 procedure Process_Linker (Attributes : Variable_Id) is
1772 Attribute_Id : Variable_Id;
1773 Attribute : Variable;
1776 -- Process non associated array attribute from package Linker
1778 Attribute_Id := Attributes;
1779 while Attribute_Id /= No_Variable loop
1780 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1782 if not Attribute.Value.Default then
1783 if Attribute.Name = Name_Driver then
1785 -- Attribute Linker'Driver: the default linker to use
1787 Project.Config.Linker :=
1788 Path_Name_Type (Attribute.Value.Value);
1790 -- Linker'Driver is also used to link shared libraries
1791 -- if the obsolescent attribute Library_GCC has not been
1794 if Project.Config.Shared_Lib_Driver = No_File then
1795 Project.Config.Shared_Lib_Driver :=
1796 File_Name_Type (Attribute.Value.Value);
1799 elsif Attribute.Name = Name_Required_Switches then
1801 -- Attribute Required_Switches: the minimum trailing
1802 -- options to use when invoking the linker
1805 Project.Config.Trailing_Linker_Required_Switches,
1806 From_List => Attribute.Value.Values,
1807 In_Tree => Data.Tree);
1809 elsif Attribute.Name = Name_Map_File_Option then
1810 Project.Config.Map_File_Option := Attribute.Value.Value;
1812 elsif Attribute.Name = Name_Max_Command_Line_Length then
1814 Project.Config.Max_Command_Line_Length :=
1815 Natural'Value (Get_Name_String
1816 (Attribute.Value.Value));
1819 when Constraint_Error =>
1822 "value must be positive or equal to 0",
1823 Attribute.Value.Location, Project);
1826 elsif Attribute.Name = Name_Response_File_Format then
1831 Get_Name_String (Attribute.Value.Value);
1832 To_Lower (Name_Buffer (1 .. Name_Len));
1835 if Name = Name_None then
1836 Project.Config.Resp_File_Format := None;
1838 elsif Name = Name_Gnu then
1839 Project.Config.Resp_File_Format := GNU;
1841 elsif Name = Name_Object_List then
1842 Project.Config.Resp_File_Format := Object_List;
1844 elsif Name = Name_Option_List then
1845 Project.Config.Resp_File_Format := Option_List;
1847 elsif Name_Buffer (1 .. Name_Len) = "gcc" then
1848 Project.Config.Resp_File_Format := GCC;
1850 elsif Name_Buffer (1 .. Name_Len) = "gcc_gnu" then
1851 Project.Config.Resp_File_Format := GCC_GNU;
1854 Name_Buffer (1 .. Name_Len) = "gcc_option_list"
1856 Project.Config.Resp_File_Format := GCC_Option_List;
1859 Name_Buffer (1 .. Name_Len) = "gcc_object_list"
1861 Project.Config.Resp_File_Format := GCC_Object_List;
1866 "illegal response file format",
1867 Attribute.Value.Location, Project);
1871 elsif Attribute.Name = Name_Response_File_Switches then
1872 Put (Into_List => Project.Config.Resp_File_Options,
1873 From_List => Attribute.Value.Values,
1874 In_Tree => Data.Tree);
1878 Attribute_Id := Attribute.Next;
1882 -- Start of processing for Process_Packages
1885 Packages := Project.Decl.Packages;
1886 while Packages /= No_Package loop
1887 Element := Shared.Packages.Table (Packages);
1889 case Element.Name is
1892 -- Process attributes of package Binder
1894 Process_Binder (Element.Decl.Arrays);
1896 when Name_Builder =>
1898 -- Process attributes of package Builder
1900 Process_Builder (Element.Decl.Attributes);
1902 when Name_Compiler =>
1904 -- Process attributes of package Compiler
1906 Process_Compiler (Element.Decl.Arrays);
1910 -- Process attributes of package Linker
1912 Process_Linker (Element.Decl.Attributes);
1916 -- Process attributes of package Naming
1918 Process_Naming (Element.Decl.Attributes);
1919 Process_Naming (Element.Decl.Arrays);
1925 Packages := Element.Next;
1927 end Process_Packages;
1929 ---------------------------------------------
1930 -- Process_Project_Level_Simple_Attributes --
1931 ---------------------------------------------
1933 procedure Process_Project_Level_Simple_Attributes is
1934 Attribute_Id : Variable_Id;
1935 Attribute : Variable;
1936 List : String_List_Id;
1939 -- Process non associated array attribute at project level
1941 Attribute_Id := Project.Decl.Attributes;
1942 while Attribute_Id /= No_Variable loop
1943 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1945 if not Attribute.Value.Default then
1946 if Attribute.Name = Name_Target then
1948 -- Attribute Target: the target specified
1950 Project.Config.Target := Attribute.Value.Value;
1952 elsif Attribute.Name = Name_Library_Builder then
1954 -- Attribute Library_Builder: the application to invoke
1955 -- to build libraries.
1957 Project.Config.Library_Builder :=
1958 Path_Name_Type (Attribute.Value.Value);
1960 elsif Attribute.Name = Name_Archive_Builder then
1962 -- Attribute Archive_Builder: the archive builder
1963 -- (usually "ar") and its minimum options (usually "cr").
1965 List := Attribute.Value.Values;
1967 if List = Nil_String then
1970 "archive builder cannot be null",
1971 Attribute.Value.Location, Project);
1974 Put (Into_List => Project.Config.Archive_Builder,
1976 In_Tree => Data.Tree);
1978 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1980 -- Attribute Archive_Builder: the archive builder
1981 -- (usually "ar") and its minimum options (usually "cr").
1983 List := Attribute.Value.Values;
1985 if List /= Nil_String then
1988 Project.Config.Archive_Builder_Append_Option,
1990 In_Tree => Data.Tree);
1993 elsif Attribute.Name = Name_Archive_Indexer then
1995 -- Attribute Archive_Indexer: the optional archive
1996 -- indexer (usually "ranlib") with its minimum options
1999 List := Attribute.Value.Values;
2001 if List = Nil_String then
2004 "archive indexer cannot be null",
2005 Attribute.Value.Location, Project);
2008 Put (Into_List => Project.Config.Archive_Indexer,
2010 In_Tree => Data.Tree);
2012 elsif Attribute.Name = Name_Library_Partial_Linker then
2014 -- Attribute Library_Partial_Linker: the optional linker
2015 -- driver with its minimum options, to partially link
2018 List := Attribute.Value.Values;
2020 if List = Nil_String then
2023 "partial linker cannot be null",
2024 Attribute.Value.Location, Project);
2027 Put (Into_List => Project.Config.Lib_Partial_Linker,
2029 In_Tree => Data.Tree);
2031 elsif Attribute.Name = Name_Library_GCC then
2032 Project.Config.Shared_Lib_Driver :=
2033 File_Name_Type (Attribute.Value.Value);
2036 "?Library_'G'C'C is an obsolescent attribute, " &
2037 "use Linker''Driver instead",
2038 Attribute.Value.Location, Project);
2040 elsif Attribute.Name = Name_Archive_Suffix then
2041 Project.Config.Archive_Suffix :=
2042 File_Name_Type (Attribute.Value.Value);
2044 elsif Attribute.Name = Name_Linker_Executable_Option then
2046 -- Attribute Linker_Executable_Option: optional options
2047 -- to specify an executable name. Defaults to "-o".
2049 List := Attribute.Value.Values;
2051 if List = Nil_String then
2054 "linker executable option cannot be null",
2055 Attribute.Value.Location, Project);
2058 Put (Into_List => Project.Config.Linker_Executable_Option,
2060 In_Tree => Data.Tree);
2062 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2064 -- Attribute Linker_Lib_Dir_Option: optional options
2065 -- to specify a library search directory. Defaults to
2068 Get_Name_String (Attribute.Value.Value);
2070 if Name_Len = 0 then
2073 "linker library directory option cannot be empty",
2074 Attribute.Value.Location, Project);
2077 Project.Config.Linker_Lib_Dir_Option :=
2078 Attribute.Value.Value;
2080 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2082 -- Attribute Linker_Lib_Name_Option: optional options
2083 -- to specify the name of a library to be linked in.
2084 -- Defaults to "-l".
2086 Get_Name_String (Attribute.Value.Value);
2088 if Name_Len = 0 then
2091 "linker library name option cannot be empty",
2092 Attribute.Value.Location, Project);
2095 Project.Config.Linker_Lib_Name_Option :=
2096 Attribute.Value.Value;
2098 elsif Attribute.Name = Name_Run_Path_Option then
2100 -- Attribute Run_Path_Option: optional options to
2101 -- specify a path for libraries.
2103 List := Attribute.Value.Values;
2105 if List /= Nil_String then
2106 Put (Into_List => Project.Config.Run_Path_Option,
2108 In_Tree => Data.Tree);
2111 elsif Attribute.Name = Name_Run_Path_Origin then
2112 Get_Name_String (Attribute.Value.Value);
2114 if Name_Len = 0 then
2117 "run path origin cannot be empty",
2118 Attribute.Value.Location, Project);
2121 Project.Config.Run_Path_Origin := Attribute.Value.Value;
2123 elsif Attribute.Name = Name_Library_Install_Name_Option then
2124 Project.Config.Library_Install_Name_Option :=
2125 Attribute.Value.Value;
2127 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2129 pragma Unsuppress (All_Checks);
2131 Project.Config.Separate_Run_Path_Options :=
2132 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2134 when Constraint_Error =>
2137 "invalid value """ &
2138 Get_Name_String (Attribute.Value.Value) &
2139 """ for Separate_Run_Path_Options",
2140 Attribute.Value.Location, Project);
2143 elsif Attribute.Name = Name_Library_Support then
2145 pragma Unsuppress (All_Checks);
2147 Project.Config.Lib_Support :=
2148 Library_Support'Value (Get_Name_String
2149 (Attribute.Value.Value));
2151 when Constraint_Error =>
2154 "invalid value """ &
2155 Get_Name_String (Attribute.Value.Value) &
2156 """ for Library_Support",
2157 Attribute.Value.Location, Project);
2160 elsif Attribute.Name = Name_Shared_Library_Prefix then
2161 Project.Config.Shared_Lib_Prefix :=
2162 File_Name_Type (Attribute.Value.Value);
2164 elsif Attribute.Name = Name_Shared_Library_Suffix then
2165 Project.Config.Shared_Lib_Suffix :=
2166 File_Name_Type (Attribute.Value.Value);
2168 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2170 pragma Unsuppress (All_Checks);
2172 Project.Config.Symbolic_Link_Supported :=
2173 Boolean'Value (Get_Name_String
2174 (Attribute.Value.Value));
2176 when Constraint_Error =>
2180 & Get_Name_String (Attribute.Value.Value)
2181 & """ for Symbolic_Link_Supported",
2182 Attribute.Value.Location, Project);
2186 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2189 pragma Unsuppress (All_Checks);
2191 Project.Config.Lib_Maj_Min_Id_Supported :=
2192 Boolean'Value (Get_Name_String
2193 (Attribute.Value.Value));
2195 when Constraint_Error =>
2198 "invalid value """ &
2199 Get_Name_String (Attribute.Value.Value) &
2200 """ for Library_Major_Minor_Id_Supported",
2201 Attribute.Value.Location, Project);
2204 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2206 pragma Unsuppress (All_Checks);
2208 Project.Config.Auto_Init_Supported :=
2209 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2211 when Constraint_Error =>
2215 & Get_Name_String (Attribute.Value.Value)
2216 & """ for Library_Auto_Init_Supported",
2217 Attribute.Value.Location, Project);
2220 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2221 List := Attribute.Value.Values;
2223 if List /= Nil_String then
2224 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2226 In_Tree => Data.Tree);
2229 elsif Attribute.Name = Name_Library_Version_Switches then
2230 List := Attribute.Value.Values;
2232 if List /= Nil_String then
2233 Put (Into_List => Project.Config.Lib_Version_Options,
2235 In_Tree => Data.Tree);
2240 Attribute_Id := Attribute.Next;
2242 end Process_Project_Level_Simple_Attributes;
2244 --------------------------------------------
2245 -- Process_Project_Level_Array_Attributes --
2246 --------------------------------------------
2248 procedure Process_Project_Level_Array_Attributes is
2249 Current_Array_Id : Array_Id;
2250 Current_Array : Array_Data;
2251 Element_Id : Array_Element_Id;
2252 Element : Array_Element;
2253 List : String_List_Id;
2256 -- Process the associative array attributes at project level
2258 Current_Array_Id := Project.Decl.Arrays;
2259 while Current_Array_Id /= No_Array loop
2260 Current_Array := Shared.Arrays.Table (Current_Array_Id);
2262 Element_Id := Current_Array.Value;
2263 while Element_Id /= No_Array_Element loop
2264 Element := Shared.Array_Elements.Table (Element_Id);
2266 -- Get the name of the language
2269 Get_Language_From_Name
2270 (Project, Get_Name_String (Element.Index));
2272 if Lang_Index /= No_Language_Index then
2273 case Current_Array.Name is
2274 when Name_Inherit_Source_Path =>
2275 List := Element.Value.Values;
2277 if List /= Nil_String then
2280 Lang_Index.Config.Include_Compatible_Languages,
2282 In_Tree => Data.Tree,
2283 Lower_Case => True);
2286 when Name_Toolchain_Description =>
2288 -- Attribute Toolchain_Description (<language>)
2290 Lang_Index.Config.Toolchain_Description :=
2291 Element.Value.Value;
2293 when Name_Toolchain_Version =>
2295 -- Attribute Toolchain_Version (<language>)
2297 Lang_Index.Config.Toolchain_Version :=
2298 Element.Value.Value;
2300 -- For Ada, set proper checksum computation mode
2302 if Lang_Index.Name = Name_Ada then
2304 Vers : constant String :=
2305 Get_Name_String (Element.Value.Value);
2306 pragma Assert (Vers'First = 1);
2309 -- Version 6.3 or earlier
2312 and then Vers (1 .. 5) = "GNAT "
2313 and then Vers (7) = '.'
2317 (Vers (6) = '6' and then Vers (8) < '4'))
2319 Checksum_GNAT_6_3 := True;
2321 -- Version 5.03 or earlier
2324 or else (Vers (6) = '5'
2325 and then Vers (Vers'Last) < '4')
2327 Checksum_GNAT_5_03 := True;
2329 -- Version 5.02 or earlier
2332 or else Vers (Vers'Last) < '3'
2334 Checksum_Accumulate_Token_Checksum :=
2342 when Name_Runtime_Library_Dir =>
2344 -- Attribute Runtime_Library_Dir (<language>)
2346 Lang_Index.Config.Runtime_Library_Dir :=
2347 Element.Value.Value;
2349 when Name_Runtime_Source_Dir =>
2351 -- Attribute Runtime_Source_Dir (<language>)
2353 Lang_Index.Config.Runtime_Source_Dir :=
2354 Element.Value.Value;
2356 when Name_Object_Generated =>
2358 pragma Unsuppress (All_Checks);
2364 (Get_Name_String (Element.Value.Value));
2366 Lang_Index.Config.Object_Generated := Value;
2368 -- If no object is generated, no object may be
2372 Lang_Index.Config.Objects_Linked := False;
2376 when Constraint_Error =>
2380 & Get_Name_String (Element.Value.Value)
2381 & """ for Object_Generated",
2382 Element.Value.Location, Project);
2385 when Name_Objects_Linked =>
2387 pragma Unsuppress (All_Checks);
2393 (Get_Name_String (Element.Value.Value));
2395 -- No change if Object_Generated is False, as this
2396 -- forces Objects_Linked to be False too.
2398 if Lang_Index.Config.Object_Generated then
2399 Lang_Index.Config.Objects_Linked := Value;
2403 when Constraint_Error =>
2407 & Get_Name_String (Element.Value.Value)
2408 & """ for Objects_Linked",
2409 Element.Value.Location, Project);
2416 Element_Id := Element.Next;
2419 Current_Array_Id := Current_Array.Next;
2421 end Process_Project_Level_Array_Attributes;
2423 -- Start of processing for Check_Configuration
2426 Process_Project_Level_Simple_Attributes;
2427 Process_Project_Level_Array_Attributes;
2430 -- For unit based languages, set Casing, Dot_Replacement and
2431 -- Separate_Suffix in Naming_Data.
2433 Lang_Index := Project.Languages;
2434 while Lang_Index /= No_Language_Index loop
2435 if Lang_Index.Config.Kind = Unit_Based then
2436 Lang_Index.Config.Naming_Data.Casing := Casing;
2437 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2439 if Separate_Suffix /= No_File then
2440 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2447 Lang_Index := Lang_Index.Next;
2450 -- Give empty names to various prefixes/suffixes, if they have not
2451 -- been specified in the configuration.
2453 if Project.Config.Archive_Suffix = No_File then
2454 Project.Config.Archive_Suffix := Empty_File;
2457 if Project.Config.Shared_Lib_Prefix = No_File then
2458 Project.Config.Shared_Lib_Prefix := Empty_File;
2461 if Project.Config.Shared_Lib_Suffix = No_File then
2462 Project.Config.Shared_Lib_Suffix := Empty_File;
2465 Lang_Index := Project.Languages;
2466 while Lang_Index /= No_Language_Index loop
2468 -- For all languages, Compiler_Driver needs to be specified. This is
2469 -- only needed if we do intend to compile (not in GPS for instance).
2471 if Data.Flags.Compiler_Driver_Mandatory
2472 and then Lang_Index.Config.Compiler_Driver = No_File
2474 Error_Msg_Name_1 := Lang_Index.Display_Name;
2477 "?no compiler specified for language %%" &
2478 ", ignoring all its sources",
2479 No_Location, Project);
2481 if Lang_Index = Project.Languages then
2482 Project.Languages := Lang_Index.Next;
2484 Prev_Index.Next := Lang_Index.Next;
2487 elsif Lang_Index.Config.Kind = Unit_Based then
2488 Prev_Index := Lang_Index;
2490 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2491 -- Body_Suffix need to be specified.
2493 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2496 "Dot_Replacement not specified for " &
2497 Get_Name_String (Lang_Index.Name),
2498 No_Location, Project);
2501 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2504 "Spec_Suffix not specified for " &
2505 Get_Name_String (Lang_Index.Name),
2506 No_Location, Project);
2509 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2512 "Body_Suffix not specified for " &
2513 Get_Name_String (Lang_Index.Name),
2514 No_Location, Project);
2518 Prev_Index := Lang_Index;
2520 -- For file based languages, either Spec_Suffix or Body_Suffix
2521 -- need to be specified.
2523 if Data.Flags.Require_Sources_Other_Lang
2524 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2525 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2527 Error_Msg_Name_1 := Lang_Index.Display_Name;
2530 "no suffixes specified for %%",
2531 No_Location, Project);
2535 Lang_Index := Lang_Index.Next;
2537 end Check_Configuration;
2539 -------------------------------
2540 -- Check_If_Externally_Built --
2541 -------------------------------
2543 procedure Check_If_Externally_Built
2544 (Project : Project_Id;
2545 Data : in out Tree_Processing_Data)
2547 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2548 Externally_Built : constant Variable_Value :=
2550 (Name_Externally_Built,
2551 Project.Decl.Attributes, Shared);
2554 if not Externally_Built.Default then
2555 Get_Name_String (Externally_Built.Value);
2556 To_Lower (Name_Buffer (1 .. Name_Len));
2558 if Name_Buffer (1 .. Name_Len) = "true" then
2559 Project.Externally_Built := True;
2561 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2562 Error_Msg (Data.Flags,
2563 "Externally_Built may only be true or false",
2564 Externally_Built.Location, Project);
2568 -- A virtual project extending an externally built project is itself
2569 -- externally built.
2571 if Project.Virtual and then Project.Extends /= No_Project then
2572 Project.Externally_Built := Project.Extends.Externally_Built;
2575 if Project.Externally_Built then
2576 Debug_Output ("project is externally built");
2578 Debug_Output ("project is not externally built");
2580 end Check_If_Externally_Built;
2582 ----------------------
2583 -- Check_Interfaces --
2584 ----------------------
2586 procedure Check_Interfaces
2587 (Project : Project_Id;
2588 Data : in out Tree_Processing_Data)
2590 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2592 Interfaces : constant Prj.Variable_Value :=
2594 (Snames.Name_Interfaces,
2595 Project.Decl.Attributes,
2598 Library_Interface : constant Prj.Variable_Value :=
2600 (Snames.Name_Library_Interface,
2601 Project.Decl.Attributes,
2604 List : String_List_Id;
2605 Element : String_Element;
2606 Name : File_Name_Type;
2607 Iter : Source_Iterator;
2609 Project_2 : Project_Id;
2613 if not Interfaces.Default then
2615 -- Set In_Interfaces to False for all sources. It will be set to True
2616 -- later for the sources in the Interfaces list.
2618 Project_2 := Project;
2619 while Project_2 /= No_Project loop
2620 Iter := For_Each_Source (Data.Tree, Project_2);
2622 Source := Prj.Element (Iter);
2623 exit when Source = No_Source;
2624 Source.In_Interfaces := False;
2628 Project_2 := Project_2.Extends;
2631 List := Interfaces.Values;
2632 while List /= Nil_String loop
2633 Element := Shared.String_Elements.Table (List);
2634 Name := Canonical_Case_File_Name (Element.Value);
2636 Project_2 := Project;
2638 while Project_2 /= No_Project loop
2639 Iter := For_Each_Source (Data.Tree, Project_2);
2642 Source := Prj.Element (Iter);
2643 exit when Source = No_Source;
2645 if Source.File = Name then
2646 if not Source.Locally_Removed then
2647 Source.In_Interfaces := True;
2648 Source.Declared_In_Interfaces := True;
2650 Other := Other_Part (Source);
2652 if Other /= No_Source then
2653 Other.In_Interfaces := True;
2654 Other.Declared_In_Interfaces := True;
2658 ("interface: ", Name_Id (Source.Path.Name));
2667 Project_2 := Project_2.Extends;
2670 if Source = No_Source then
2671 Error_Msg_File_1 := File_Name_Type (Element.Value);
2672 Error_Msg_Name_1 := Project.Name;
2676 "{ cannot be an interface of project %% "
2677 & "as it is not one of its sources",
2678 Element.Location, Project);
2681 List := Element.Next;
2684 Project.Interfaces_Defined := True;
2686 elsif Project.Library and then not Library_Interface.Default then
2688 -- Set In_Interfaces to False for all sources. It will be set to True
2689 -- later for the sources in the Library_Interface list.
2691 Project_2 := Project;
2692 while Project_2 /= No_Project loop
2693 Iter := For_Each_Source (Data.Tree, Project_2);
2695 Source := Prj.Element (Iter);
2696 exit when Source = No_Source;
2697 Source.In_Interfaces := False;
2701 Project_2 := Project_2.Extends;
2704 List := Library_Interface.Values;
2705 while List /= Nil_String loop
2706 Element := Shared.String_Elements.Table (List);
2707 Get_Name_String (Element.Value);
2708 To_Lower (Name_Buffer (1 .. Name_Len));
2711 Project_2 := Project;
2713 while Project_2 /= No_Project loop
2714 Iter := For_Each_Source (Data.Tree, Project_2);
2717 Source := Prj.Element (Iter);
2718 exit when Source = No_Source;
2720 if Source.Unit /= No_Unit_Index and then
2721 Source.Unit.Name = Name_Id (Name)
2723 if not Source.Locally_Removed then
2724 Source.In_Interfaces := True;
2725 Source.Declared_In_Interfaces := True;
2727 Other := Other_Part (Source);
2729 if Other /= No_Source then
2730 Other.In_Interfaces := True;
2731 Other.Declared_In_Interfaces := True;
2735 ("interface: ", Name_Id (Source.Path.Name));
2744 Project_2 := Project_2.Extends;
2745 end loop Big_Loop_2;
2747 List := Element.Next;
2750 Project.Interfaces_Defined := True;
2752 elsif Project.Extends /= No_Project
2753 and then Project.Extends.Interfaces_Defined
2755 Project.Interfaces_Defined := True;
2757 Iter := For_Each_Source (Data.Tree, Project);
2759 Source := Prj.Element (Iter);
2760 exit when Source = No_Source;
2762 if not Source.Declared_In_Interfaces then
2763 Source.In_Interfaces := False;
2769 end Check_Interfaces;
2771 ------------------------------
2772 -- Check_Library_Attributes --
2773 ------------------------------
2775 -- This procedure is awfully long (over 700 lines) should be broken up???
2777 procedure Check_Library_Attributes
2778 (Project : Project_Id;
2779 Data : in out Tree_Processing_Data)
2781 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2783 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
2785 Lib_Dir : constant Prj.Variable_Value :=
2787 (Snames.Name_Library_Dir, Attributes, Shared);
2789 Lib_Name : constant Prj.Variable_Value :=
2791 (Snames.Name_Library_Name, Attributes, Shared);
2793 Lib_Version : constant Prj.Variable_Value :=
2795 (Snames.Name_Library_Version, Attributes, Shared);
2797 Lib_ALI_Dir : constant Prj.Variable_Value :=
2799 (Snames.Name_Library_Ali_Dir, Attributes, Shared);
2801 Lib_GCC : constant Prj.Variable_Value :=
2803 (Snames.Name_Library_GCC, Attributes, Shared);
2805 The_Lib_Kind : constant Prj.Variable_Value :=
2807 (Snames.Name_Library_Kind, Attributes, Shared);
2809 Imported_Project_List : Project_List;
2811 Continuation : String_Access := No_Continuation_String'Access;
2813 Support_For_Libraries : Library_Support;
2815 Library_Directory_Present : Boolean;
2817 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
2818 -- Check if an imported or extended project if also a library project
2824 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
2826 Iter : Source_Iterator;
2829 if Proj /= No_Project then
2830 if not Proj.Library then
2832 -- The only not library projects that are OK are those that
2833 -- have no sources. However, header files from non-Ada
2834 -- languages are OK, as there is nothing to compile.
2836 Iter := For_Each_Source (Data.Tree, Proj);
2838 Src_Id := Prj.Element (Iter);
2839 exit when Src_Id = No_Source
2840 or else Src_Id.Language.Config.Kind /= File_Based
2841 or else Src_Id.Kind /= Spec;
2845 if Src_Id /= No_Source then
2846 Error_Msg_Name_1 := Project.Name;
2847 Error_Msg_Name_2 := Proj.Name;
2850 if Project.Library_Kind /= Static then
2854 "shared library project %% cannot extend " &
2855 "project %% that is not a library project",
2856 Project.Location, Project);
2857 Continuation := Continuation_String'Access;
2860 elsif (not Unchecked_Shared_Lib_Imports)
2861 and then Project.Library_Kind /= Static
2866 "shared library project %% cannot import project %% " &
2867 "that is not a shared library project",
2868 Project.Location, Project);
2869 Continuation := Continuation_String'Access;
2873 elsif Project.Library_Kind /= Static and then
2874 Proj.Library_Kind = Static
2876 Error_Msg_Name_1 := Project.Name;
2877 Error_Msg_Name_2 := Proj.Name;
2883 "shared library project %% cannot extend static " &
2884 "library project %%",
2885 Project.Location, Project);
2886 Continuation := Continuation_String'Access;
2888 elsif not Unchecked_Shared_Lib_Imports then
2892 "shared library project %% cannot import static " &
2893 "library project %%",
2894 Project.Location, Project);
2895 Continuation := Continuation_String'Access;
2902 Dir_Exists : Boolean;
2904 -- Start of processing for Check_Library_Attributes
2907 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
2909 -- Special case of extending project
2911 if Project.Extends /= No_Project then
2913 -- If the project extended is a library project, we inherit the
2914 -- library name, if it is not redefined; we check that the library
2915 -- directory is specified.
2917 if Project.Extends.Library then
2918 if Project.Qualifier = Standard then
2921 "a standard project cannot extend a library project",
2922 Project.Location, Project);
2925 if Lib_Name.Default then
2926 Project.Library_Name := Project.Extends.Library_Name;
2929 if Lib_Dir.Default then
2930 if not Project.Virtual then
2933 "a project extending a library project must " &
2934 "specify an attribute Library_Dir",
2935 Project.Location, Project);
2938 -- For a virtual project extending a library project,
2939 -- inherit library directory and library kind.
2941 Project.Library_Dir := Project.Extends.Library_Dir;
2942 Library_Directory_Present := True;
2943 Project.Library_Kind := Project.Extends.Library_Kind;
2950 pragma Assert (Lib_Name.Kind = Single);
2952 if Lib_Name.Value = Empty_String then
2953 if Current_Verbosity = High
2954 and then Project.Library_Name = No_Name
2957 Write_Line ("no library name");
2961 -- There is no restriction on the syntax of library names
2963 Project.Library_Name := Lib_Name.Value;
2966 if Project.Library_Name /= No_Name then
2967 if Current_Verbosity = High then
2969 ("Library name: ", Get_Name_String (Project.Library_Name));
2972 pragma Assert (Lib_Dir.Kind = Single);
2974 if not Library_Directory_Present then
2975 Debug_Output ("no library directory");
2978 -- Find path name (unless inherited), check that it is a directory
2980 if Project.Library_Dir = No_Path_Information then
2983 File_Name_Type (Lib_Dir.Value),
2984 Path => Project.Library_Dir,
2985 Dir_Exists => Dir_Exists,
2987 Create => "library",
2988 Must_Exist => False,
2989 Location => Lib_Dir.Location,
2990 Externally_Built => Project.Externally_Built);
2995 (Get_Name_String (Project.Library_Dir.Display_Name));
2998 if not Dir_Exists then
3000 -- Get the absolute name of the library directory that
3001 -- does not exist, to report an error.
3003 Err_Vars.Error_Msg_File_1 :=
3004 File_Name_Type (Project.Library_Dir.Display_Name);
3007 "library directory { does not exist",
3008 Lib_Dir.Location, Project);
3010 elsif not Project.Externally_Built then
3012 -- Library directory cannot be the same as Object directory
3014 if Project.Library_Dir.Name = Project.Object_Directory.Name then
3017 "library directory cannot be the same " &
3018 "as object directory",
3019 Lib_Dir.Location, Project);
3020 Project.Library_Dir := No_Path_Information;
3024 OK : Boolean := True;
3025 Dirs_Id : String_List_Id;
3026 Dir_Elem : String_Element;
3030 -- The library directory cannot be the same as a source
3031 -- directory of the current project.
3033 Dirs_Id := Project.Source_Dirs;
3034 while Dirs_Id /= Nil_String loop
3035 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
3036 Dirs_Id := Dir_Elem.Next;
3038 if Project.Library_Dir.Name =
3039 Path_Name_Type (Dir_Elem.Value)
3041 Err_Vars.Error_Msg_File_1 :=
3042 File_Name_Type (Dir_Elem.Value);
3045 "library directory cannot be the same " &
3046 "as source directory {",
3047 Lib_Dir.Location, Project);
3055 -- The library directory cannot be the same as a
3056 -- source directory of another project either.
3058 Pid := Data.Tree.Projects;
3060 exit Project_Loop when Pid = null;
3062 if Pid.Project /= Project then
3063 Dirs_Id := Pid.Project.Source_Dirs;
3065 Dir_Loop : while Dirs_Id /= Nil_String loop
3067 Shared.String_Elements.Table (Dirs_Id);
3068 Dirs_Id := Dir_Elem.Next;
3070 if Project.Library_Dir.Name =
3071 Path_Name_Type (Dir_Elem.Value)
3073 Err_Vars.Error_Msg_File_1 :=
3074 File_Name_Type (Dir_Elem.Value);
3075 Err_Vars.Error_Msg_Name_1 :=
3080 "library directory cannot be the same" &
3081 " as source directory { of project %%",
3082 Lib_Dir.Location, Project);
3090 end loop Project_Loop;
3094 Project.Library_Dir := No_Path_Information;
3096 elsif Current_Verbosity = High then
3098 -- Display the Library directory in high verbosity
3101 ("Library directory",
3102 Get_Name_String (Project.Library_Dir.Display_Name));
3112 Project.Library_Dir /= No_Path_Information
3113 and then Project.Library_Name /= No_Name;
3115 if Project.Extends = No_Project then
3116 case Project.Qualifier is
3118 if Project.Library then
3121 "a standard project cannot be a library project",
3122 Lib_Name.Location, Project);
3126 if not Project.Library then
3127 if Project.Library_Name = No_Name then
3130 "attribute Library_Name not declared",
3131 Project.Location, Project);
3133 if not Library_Directory_Present then
3136 "\attribute Library_Dir not declared",
3137 Project.Location, Project);
3140 elsif Project.Library_Dir = No_Path_Information then
3143 "attribute Library_Dir not declared",
3144 Project.Location, Project);
3154 if Project.Library then
3155 Support_For_Libraries := Project.Config.Lib_Support;
3157 if Support_For_Libraries = Prj.None then
3160 "?libraries are not supported on this platform",
3161 Lib_Name.Location, Project);
3162 Project.Library := False;
3165 if Lib_ALI_Dir.Value = Empty_String then
3166 Debug_Output ("no library ALI directory specified");
3167 Project.Library_ALI_Dir := Project.Library_Dir;
3170 -- Find path name, check that it is a directory
3174 File_Name_Type (Lib_ALI_Dir.Value),
3175 Path => Project.Library_ALI_Dir,
3176 Create => "library ALI",
3177 Dir_Exists => Dir_Exists,
3179 Must_Exist => False,
3180 Location => Lib_ALI_Dir.Location,
3181 Externally_Built => Project.Externally_Built);
3183 if not Dir_Exists then
3185 -- Get the absolute name of the library ALI directory that
3186 -- does not exist, to report an error.
3188 Err_Vars.Error_Msg_File_1 :=
3189 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3192 "library 'A'L'I directory { does not exist",
3193 Lib_ALI_Dir.Location, Project);
3196 if (not Project.Externally_Built) and then
3197 Project.Library_ALI_Dir /= Project.Library_Dir
3199 -- The library ALI directory cannot be the same as the
3200 -- Object directory.
3202 if Project.Library_ALI_Dir = Project.Object_Directory then
3205 "library 'A'L'I directory cannot be the same " &
3206 "as object directory",
3207 Lib_ALI_Dir.Location, Project);
3208 Project.Library_ALI_Dir := No_Path_Information;
3212 OK : Boolean := True;
3213 Dirs_Id : String_List_Id;
3214 Dir_Elem : String_Element;
3218 -- The library ALI directory cannot be the same as
3219 -- a source directory of the current project.
3221 Dirs_Id := Project.Source_Dirs;
3222 while Dirs_Id /= Nil_String loop
3223 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
3224 Dirs_Id := Dir_Elem.Next;
3226 if Project.Library_ALI_Dir.Name =
3227 Path_Name_Type (Dir_Elem.Value)
3229 Err_Vars.Error_Msg_File_1 :=
3230 File_Name_Type (Dir_Elem.Value);
3233 "library 'A'L'I directory cannot be " &
3234 "the same as source directory {",
3235 Lib_ALI_Dir.Location, Project);
3243 -- The library ALI directory cannot be the same as
3244 -- a source directory of another project either.
3246 Pid := Data.Tree.Projects;
3247 ALI_Project_Loop : loop
3248 exit ALI_Project_Loop when Pid = null;
3250 if Pid.Project /= Project then
3251 Dirs_Id := Pid.Project.Source_Dirs;
3254 while Dirs_Id /= Nil_String loop
3256 Shared.String_Elements.Table (Dirs_Id);
3257 Dirs_Id := Dir_Elem.Next;
3259 if Project.Library_ALI_Dir.Name =
3260 Path_Name_Type (Dir_Elem.Value)
3262 Err_Vars.Error_Msg_File_1 :=
3263 File_Name_Type (Dir_Elem.Value);
3264 Err_Vars.Error_Msg_Name_1 :=
3269 "library 'A'L'I directory cannot " &
3270 "be the same as source directory " &
3272 Lib_ALI_Dir.Location, Project);
3274 exit ALI_Project_Loop;
3276 end loop ALI_Dir_Loop;
3279 end loop ALI_Project_Loop;
3283 Project.Library_ALI_Dir := No_Path_Information;
3285 elsif Current_Verbosity = High then
3287 -- Display Library ALI directory in high verbosity
3292 (Project.Library_ALI_Dir.Display_Name));
3299 pragma Assert (Lib_Version.Kind = Single);
3301 if Lib_Version.Value = Empty_String then
3302 Debug_Output ("no library version specified");
3305 Project.Lib_Internal_Name := Lib_Version.Value;
3308 pragma Assert (The_Lib_Kind.Kind = Single);
3310 if The_Lib_Kind.Value = Empty_String then
3311 Debug_Output ("no library kind specified");
3314 Get_Name_String (The_Lib_Kind.Value);
3317 Kind_Name : constant String :=
3318 To_Lower (Name_Buffer (1 .. Name_Len));
3320 OK : Boolean := True;
3323 if Kind_Name = "static" then
3324 Project.Library_Kind := Static;
3326 elsif Kind_Name = "dynamic" then
3327 Project.Library_Kind := Dynamic;
3329 elsif Kind_Name = "relocatable" then
3330 Project.Library_Kind := Relocatable;
3335 "illegal value for Library_Kind",
3336 The_Lib_Kind.Location, Project);
3340 if Current_Verbosity = High and then OK then
3341 Write_Attr ("Library kind", Kind_Name);
3344 if Project.Library_Kind /= Static then
3345 if Support_For_Libraries = Prj.Static_Only then
3348 "only static libraries are supported " &
3350 The_Lib_Kind.Location, Project);
3351 Project.Library := False;
3354 -- Check if (obsolescent) attribute Library_GCC or
3355 -- Linker'Driver is declared.
3357 if Lib_GCC.Value /= Empty_String then
3360 "?Library_'G'C'C is an obsolescent attribute, " &
3361 "use Linker''Driver instead",
3362 Lib_GCC.Location, Project);
3363 Project.Config.Shared_Lib_Driver :=
3364 File_Name_Type (Lib_GCC.Value);
3368 Linker : constant Package_Id :=
3371 Project.Decl.Packages,
3373 Driver : constant Variable_Value :=
3376 Attribute_Or_Array_Name =>
3378 In_Package => Linker,
3382 if Driver /= Nil_Variable_Value
3383 and then Driver.Value /= Empty_String
3385 Project.Config.Shared_Lib_Driver :=
3386 File_Name_Type (Driver.Value);
3396 and then Project.Qualifier /= Aggregate_Library
3398 Debug_Output ("this is a library project file");
3400 Check_Library (Project.Extends, Extends => True);
3402 Imported_Project_List := Project.Imported_Projects;
3403 while Imported_Project_List /= null loop
3405 (Imported_Project_List.Project,
3407 Imported_Project_List := Imported_Project_List.Next;
3414 -- Check if Linker'Switches or Linker'Default_Switches are declared.
3415 -- Warn if they are declared, as it is a common error to think that
3416 -- library are "linked" with Linker switches.
3418 if Project.Library then
3420 Linker_Package_Id : constant Package_Id :=
3423 Project.Decl.Packages, Shared);
3424 Linker_Package : Package_Element;
3425 Switches : Array_Element_Id := No_Array_Element;
3428 if Linker_Package_Id /= No_Package then
3429 Linker_Package := Shared.Packages.Table (Linker_Package_Id);
3433 (Name => Name_Switches,
3434 In_Arrays => Linker_Package.Decl.Arrays,
3437 if Switches = No_Array_Element then
3440 (Name => Name_Default_Switches,
3441 In_Arrays => Linker_Package.Decl.Arrays,
3445 if Switches /= No_Array_Element then
3448 "?Linker switches not taken into account in library " &
3450 No_Location, Project);
3456 if Project.Extends /= No_Project and then Project.Extends.Library then
3458 -- Remove the library name from Lib_Data_Table
3460 for J in 1 .. Lib_Data_Table.Last loop
3461 if Lib_Data_Table.Table (J).Proj = Project.Extends then
3462 Lib_Data_Table.Table (J) :=
3463 Lib_Data_Table.Table (Lib_Data_Table.Last);
3464 Lib_Data_Table.Set_Last (Lib_Data_Table.Last - 1);
3470 if Project.Library and then not Lib_Name.Default then
3472 -- Check if the same library name is used in an other library project
3474 for J in 1 .. Lib_Data_Table.Last loop
3475 if Lib_Data_Table.Table (J).Name = Project.Library_Name then
3476 Error_Msg_Name_1 := Lib_Data_Table.Table (J).Proj.Name;
3479 "Library name cannot be the same as in project %%",
3480 Lib_Name.Location, Project);
3481 Project.Library := False;
3487 if Project.Library then
3489 -- Record the library name
3491 Lib_Data_Table.Append
3492 ((Name => Project.Library_Name, Proj => Project));
3494 end Check_Library_Attributes;
3496 --------------------------
3497 -- Check_Package_Naming --
3498 --------------------------
3500 procedure Check_Package_Naming
3501 (Project : Project_Id;
3502 Data : in out Tree_Processing_Data)
3504 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
3505 Naming_Id : constant Package_Id :=
3507 (Name_Naming, Project.Decl.Packages, Shared);
3508 Naming : Package_Element;
3510 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
3512 procedure Check_Naming;
3513 -- Check the validity of the Naming package (suffixes valid, ...)
3515 procedure Check_Common
3516 (Dot_Replacement : in out File_Name_Type;
3517 Casing : in out Casing_Type;
3518 Casing_Defined : out Boolean;
3519 Separate_Suffix : in out File_Name_Type;
3520 Sep_Suffix_Loc : out Source_Ptr);
3521 -- Check attributes common
3523 procedure Process_Exceptions_File_Based
3524 (Lang_Id : Language_Ptr;
3525 Kind : Source_Kind);
3526 procedure Process_Exceptions_Unit_Based
3527 (Lang_Id : Language_Ptr;
3528 Kind : Source_Kind);
3529 -- Process the naming exceptions for the two types of languages
3531 procedure Initialize_Naming_Data;
3532 -- Initialize internal naming data for the various languages
3538 procedure Check_Common
3539 (Dot_Replacement : in out File_Name_Type;
3540 Casing : in out Casing_Type;
3541 Casing_Defined : out Boolean;
3542 Separate_Suffix : in out File_Name_Type;
3543 Sep_Suffix_Loc : out Source_Ptr)
3545 Dot_Repl : constant Variable_Value :=
3547 (Name_Dot_Replacement,
3548 Naming.Decl.Attributes,
3550 Casing_String : constant Variable_Value :=
3553 Naming.Decl.Attributes,
3555 Sep_Suffix : constant Variable_Value :=
3557 (Name_Separate_Suffix,
3558 Naming.Decl.Attributes,
3560 Dot_Repl_Loc : Source_Ptr;
3563 Sep_Suffix_Loc := No_Location;
3565 if not Dot_Repl.Default then
3567 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
3569 if Length_Of_Name (Dot_Repl.Value) = 0 then
3571 (Data.Flags, "Dot_Replacement cannot be empty",
3572 Dot_Repl.Location, Project);
3575 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
3576 Dot_Repl_Loc := Dot_Repl.Location;
3579 Repl : constant String := Get_Name_String (Dot_Replacement);
3582 -- Dot_Replacement cannot
3584 -- - start or end with an alphanumeric
3585 -- - be a single '_'
3586 -- - start with an '_' followed by an alphanumeric
3587 -- - contain a '.' except if it is "."
3590 or else Is_Alphanumeric (Repl (Repl'First))
3591 or else Is_Alphanumeric (Repl (Repl'Last))
3592 or else (Repl (Repl'First) = '_'
3596 Is_Alphanumeric (Repl (Repl'First + 1))))
3597 or else (Repl'Length > 1
3599 Index (Source => Repl, Pattern => ".") /= 0)
3604 """ is illegal for Dot_Replacement.",
3605 Dot_Repl_Loc, Project);
3610 if Dot_Replacement /= No_File then
3612 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
3615 Casing_Defined := False;
3617 if not Casing_String.Default then
3619 (Casing_String.Kind = Single, "Casing is not a string");
3622 Casing_Image : constant String :=
3623 Get_Name_String (Casing_String.Value);
3626 if Casing_Image'Length = 0 then
3629 "Casing cannot be an empty string",
3630 Casing_String.Location, Project);
3633 Casing := Value (Casing_Image);
3634 Casing_Defined := True;
3637 when Constraint_Error =>
3638 Name_Len := Casing_Image'Length;
3639 Name_Buffer (1 .. Name_Len) := Casing_Image;
3640 Err_Vars.Error_Msg_Name_1 := Name_Find;
3643 "%% is not a correct Casing",
3644 Casing_String.Location, Project);
3648 Write_Attr ("Casing", Image (Casing));
3650 if not Sep_Suffix.Default then
3651 if Length_Of_Name (Sep_Suffix.Value) = 0 then
3654 "Separate_Suffix cannot be empty",
3655 Sep_Suffix.Location, Project);
3658 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
3659 Sep_Suffix_Loc := Sep_Suffix.Location;
3661 Check_Illegal_Suffix
3662 (Project, Separate_Suffix,
3663 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
3668 if Separate_Suffix /= No_File then
3670 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
3674 -----------------------------------
3675 -- Process_Exceptions_File_Based --
3676 -----------------------------------
3678 procedure Process_Exceptions_File_Based
3679 (Lang_Id : Language_Ptr;
3682 Lang : constant Name_Id := Lang_Id.Name;
3683 Exceptions : Array_Element_Id;
3684 Exception_List : Variable_Value;
3685 Element_Id : String_List_Id;
3686 Element : String_Element;
3687 File_Name : File_Name_Type;
3695 (Name_Implementation_Exceptions,
3696 In_Arrays => Naming.Decl.Arrays,
3702 (Name_Specification_Exceptions,
3703 In_Arrays => Naming.Decl.Arrays,
3710 In_Array => Exceptions,
3713 if Exception_List /= Nil_Variable_Value then
3714 Element_Id := Exception_List.Values;
3715 while Element_Id /= Nil_String loop
3716 Element := Shared.String_Elements.Table (Element_Id);
3717 File_Name := Canonical_Case_File_Name (Element.Value);
3720 Source_Files_Htable.Get
3721 (Data.Tree.Source_Files_HT, File_Name);
3722 while Source /= No_Source
3723 and then Source.Project /= Project
3725 Source := Source.Next_With_File_Name;
3728 if Source = No_Source then
3733 Source_Dir_Rank => 0,
3736 File_Name => File_Name,
3737 Display_File => File_Name_Type (Element.Value),
3738 Naming_Exception => Yes,
3739 Location => Element.Location);
3742 -- Check if the file name is already recorded for another
3743 -- language or another kind.
3745 if Source.Language /= Lang_Id then
3748 "the same file cannot be a source of two languages",
3749 Element.Location, Project);
3751 elsif Source.Kind /= Kind then
3754 "the same file cannot be a source and a template",
3755 Element.Location, Project);
3758 -- If the file is already recorded for the same
3759 -- language and the same kind, it means that the file
3760 -- name appears several times in the *_Exceptions
3761 -- attribute; so there is nothing to do.
3764 Element_Id := Element.Next;
3767 end Process_Exceptions_File_Based;
3769 -----------------------------------
3770 -- Process_Exceptions_Unit_Based --
3771 -----------------------------------
3773 procedure Process_Exceptions_Unit_Based
3774 (Lang_Id : Language_Ptr;
3777 Exceptions : Array_Element_Id;
3778 Element : Array_Element;
3781 File_Name : File_Name_Type;
3784 Naming_Exception : Naming_Exception_Type;
3792 In_Arrays => Naming.Decl.Arrays,
3795 if Exceptions = No_Array_Element then
3798 (Name_Implementation,
3799 In_Arrays => Naming.Decl.Arrays,
3807 In_Arrays => Naming.Decl.Arrays,
3810 if Exceptions = No_Array_Element then
3813 (Name_Specification,
3814 In_Arrays => Naming.Decl.Arrays,
3819 while Exceptions /= No_Array_Element loop
3820 Element := Shared.Array_Elements.Table (Exceptions);
3822 if Element.Restricted then
3823 Naming_Exception := Inherited;
3825 Naming_Exception := Yes;
3828 File_Name := Canonical_Case_File_Name (Element.Value.Value);
3830 Get_Name_String (Element.Index);
3831 To_Lower (Name_Buffer (1 .. Name_Len));
3832 Index := Element.Value.Index;
3834 -- Check if it is a valid unit name
3836 Get_Name_String (Element.Index);
3837 Check_Unit_Name (Name_Buffer (1 .. Name_Len), Unit);
3839 if Unit = No_Name then
3840 Err_Vars.Error_Msg_Name_1 := Element.Index;
3843 "%% is not a valid unit name.",
3844 Element.Value.Location, Project);
3847 if Unit /= No_Name then
3852 Source_Dir_Rank => 0,
3855 File_Name => File_Name,
3856 Display_File => File_Name_Type (Element.Value.Value),
3859 Location => Element.Value.Location,
3860 Naming_Exception => Naming_Exception);
3863 Exceptions := Element.Next;
3865 end Process_Exceptions_Unit_Based;
3871 procedure Check_Naming is
3872 Dot_Replacement : File_Name_Type :=
3874 (First_Name_Id + Character'Pos ('-'));
3875 Separate_Suffix : File_Name_Type := No_File;
3876 Casing : Casing_Type := All_Lower_Case;
3877 Casing_Defined : Boolean;
3878 Lang_Id : Language_Ptr;
3879 Sep_Suffix_Loc : Source_Ptr;
3880 Suffix : Variable_Value;
3885 (Dot_Replacement => Dot_Replacement,
3887 Casing_Defined => Casing_Defined,
3888 Separate_Suffix => Separate_Suffix,
3889 Sep_Suffix_Loc => Sep_Suffix_Loc);
3891 -- For all unit based languages, if any, set the specified value
3892 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3893 -- systematically overwrite, since the defaults come from the
3894 -- configuration file.
3896 if Dot_Replacement /= No_File
3897 or else Casing_Defined
3898 or else Separate_Suffix /= No_File
3900 Lang_Id := Project.Languages;
3901 while Lang_Id /= No_Language_Index loop
3902 if Lang_Id.Config.Kind = Unit_Based then
3903 if Dot_Replacement /= No_File then
3904 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3908 if Casing_Defined then
3909 Lang_Id.Config.Naming_Data.Casing := Casing;
3913 Lang_Id := Lang_Id.Next;
3917 -- Next, get the spec and body suffixes
3919 Lang_Id := Project.Languages;
3920 while Lang_Id /= No_Language_Index loop
3921 Lang := Lang_Id.Name;
3927 Attribute_Or_Array_Name => Name_Spec_Suffix,
3928 In_Package => Naming_Id,
3931 if Suffix = Nil_Variable_Value then
3934 Attribute_Or_Array_Name => Name_Specification_Suffix,
3935 In_Package => Naming_Id,
3939 if Suffix /= Nil_Variable_Value then
3940 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3941 File_Name_Type (Suffix.Value);
3943 Check_Illegal_Suffix
3945 Lang_Id.Config.Naming_Data.Spec_Suffix,
3946 Lang_Id.Config.Naming_Data.Dot_Replacement,
3947 "Spec_Suffix", Suffix.Location, Data);
3951 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3959 Attribute_Or_Array_Name => Name_Body_Suffix,
3960 In_Package => Naming_Id,
3963 if Suffix = Nil_Variable_Value then
3967 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3968 In_Package => Naming_Id,
3972 if Suffix /= Nil_Variable_Value then
3973 Lang_Id.Config.Naming_Data.Body_Suffix :=
3974 File_Name_Type (Suffix.Value);
3976 -- The default value of separate suffix should be the same as
3977 -- the body suffix, so we need to compute that first.
3979 if Separate_Suffix = No_File then
3980 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3981 Lang_Id.Config.Naming_Data.Body_Suffix;
3985 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3987 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3991 Check_Illegal_Suffix
3993 Lang_Id.Config.Naming_Data.Body_Suffix,
3994 Lang_Id.Config.Naming_Data.Dot_Replacement,
3995 "Body_Suffix", Suffix.Location, Data);
3999 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
4001 elsif Separate_Suffix /= No_File then
4002 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
4005 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
4006 -- since that would cause a clear ambiguity. Note that we do allow
4007 -- a Spec_Suffix to have the same termination as one of these,
4008 -- which causes a potential ambiguity, but we resolve that by
4009 -- matching the longest possible suffix.
4011 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
4012 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
4013 Lang_Id.Config.Naming_Data.Body_Suffix
4018 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
4019 & """) cannot be the same as Spec_Suffix.",
4020 Ada_Body_Suffix_Loc, Project);
4023 if Lang_Id.Config.Naming_Data.Body_Suffix /=
4024 Lang_Id.Config.Naming_Data.Separate_Suffix
4025 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
4026 Lang_Id.Config.Naming_Data.Separate_Suffix
4030 "Separate_Suffix ("""
4032 (Lang_Id.Config.Naming_Data.Separate_Suffix)
4033 & """) cannot be the same as Spec_Suffix.",
4034 Sep_Suffix_Loc, Project);
4037 Lang_Id := Lang_Id.Next;
4040 -- Get the naming exceptions for all languages
4042 for Kind in Spec_Or_Body loop
4043 Lang_Id := Project.Languages;
4044 while Lang_Id /= No_Language_Index loop
4045 case Lang_Id.Config.Kind is
4047 Process_Exceptions_File_Based (Lang_Id, Kind);
4050 Process_Exceptions_Unit_Based (Lang_Id, Kind);
4053 Lang_Id := Lang_Id.Next;
4058 ----------------------------
4059 -- Initialize_Naming_Data --
4060 ----------------------------
4062 procedure Initialize_Naming_Data is
4063 Specs : Array_Element_Id :=
4069 Impls : Array_Element_Id :=
4075 Lang : Language_Ptr;
4076 Lang_Name : Name_Id;
4077 Value : Variable_Value;
4078 Extended : Project_Id;
4081 -- At this stage, the project already contains the default extensions
4082 -- for the various languages. We now merge those suffixes read in the
4083 -- user project, and they override the default.
4085 while Specs /= No_Array_Element loop
4086 Lang_Name := Shared.Array_Elements.Table (Specs).Index;
4088 Get_Language_From_Name
4089 (Project, Name => Get_Name_String (Lang_Name));
4091 -- An extending project inherits its parent projects' languages
4092 -- so if needed we should create entries for those languages
4095 Extended := Project.Extends;
4096 while Extended /= null loop
4097 Lang := Get_Language_From_Name
4098 (Extended, Name => Get_Name_String (Lang_Name));
4099 exit when Lang /= null;
4101 Extended := Extended.Extends;
4104 if Lang /= null then
4105 Lang := new Language_Data'(Lang.all);
4106 Lang.First_Source := null;
4107 Lang.Next := Project.Languages;
4108 Project.Languages := Lang;
4112 -- If language was not found in project or the projects it extends
4116 ("ignoring spec naming data (lang. not in project): ",
4120 Value := Shared.Array_Elements.Table (Specs).Value;
4122 if Value.Kind = Single then
4123 Lang.Config.Naming_Data.Spec_Suffix :=
4124 Canonical_Case_File_Name (Value.Value);
4128 Specs := Shared.Array_Elements.Table (Specs).Next;
4131 while Impls /= No_Array_Element loop
4132 Lang_Name := Shared.Array_Elements.Table (Impls).Index;
4134 Get_Language_From_Name
4135 (Project, Name => Get_Name_String (Lang_Name));
4139 ("ignoring impl naming data (lang. not in project): ",
4142 Value := Shared.Array_Elements.Table (Impls).Value;
4144 if Lang.Name = Name_Ada then
4145 Ada_Body_Suffix_Loc := Value.Location;
4148 if Value.Kind = Single then
4149 Lang.Config.Naming_Data.Body_Suffix :=
4150 Canonical_Case_File_Name (Value.Value);
4154 Impls := Shared.Array_Elements.Table (Impls).Next;
4156 end Initialize_Naming_Data;
4158 -- Start of processing for Check_Naming_Schemes
4161 -- No Naming package or parsing a configuration file? nothing to do
4163 if Naming_Id /= No_Package
4164 and then Project.Qualifier /= Configuration
4166 Naming := Shared.Packages.Table (Naming_Id);
4167 Debug_Increase_Indent ("checking package Naming for ", Project.Name);
4168 Initialize_Naming_Data;
4170 Debug_Decrease_Indent ("done checking package naming");
4172 end Check_Package_Naming;
4174 ---------------------------------
4175 -- Check_Programming_Languages --
4176 ---------------------------------
4178 procedure Check_Programming_Languages
4179 (Project : Project_Id;
4180 Data : in out Tree_Processing_Data)
4182 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4184 Languages : Variable_Value := Nil_Variable_Value;
4185 Def_Lang : Variable_Value := Nil_Variable_Value;
4186 Def_Lang_Id : Name_Id;
4188 procedure Add_Language (Name, Display_Name : Name_Id);
4189 -- Add a new language to the list of languages for the project.
4190 -- Nothing is done if the language has already been defined
4196 procedure Add_Language (Name, Display_Name : Name_Id) is
4197 Lang : Language_Ptr;
4200 Lang := Project.Languages;
4201 while Lang /= No_Language_Index loop
4202 if Name = Lang.Name then
4209 Lang := new Language_Data'(No_Language_Data);
4210 Lang.Next := Project.Languages;
4211 Project.Languages := Lang;
4213 Lang.Display_Name := Display_Name;
4216 -- Start of processing for Check_Programming_Languages
4219 Project.Languages := null;
4221 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Shared);
4224 (Name_Default_Language, Project.Decl.Attributes, Shared);
4226 if Project.Source_Dirs /= Nil_String then
4228 -- Check if languages are specified in this project
4230 if Languages.Default then
4232 -- Fail if there is no default language defined
4234 if Def_Lang.Default then
4237 "no languages defined for this project",
4238 Project.Location, Project);
4239 Def_Lang_Id := No_Name;
4242 Get_Name_String (Def_Lang.Value);
4243 To_Lower (Name_Buffer (1 .. Name_Len));
4244 Def_Lang_Id := Name_Find;
4247 if Def_Lang_Id /= No_Name then
4248 Get_Name_String (Def_Lang_Id);
4249 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4251 (Name => Def_Lang_Id,
4252 Display_Name => Name_Find);
4257 Current : String_List_Id := Languages.Values;
4258 Element : String_Element;
4261 -- If there are no languages declared, there are no sources
4263 if Current = Nil_String then
4264 Project.Source_Dirs := Nil_String;
4266 if Project.Qualifier = Standard then
4269 "a standard project must have at least one language",
4270 Languages.Location, Project);
4274 -- Look through all the languages specified in attribute
4277 while Current /= Nil_String loop
4278 Element := Shared.String_Elements.Table (Current);
4279 Get_Name_String (Element.Value);
4280 To_Lower (Name_Buffer (1 .. Name_Len));
4284 Display_Name => Element.Value);
4286 Current := Element.Next;
4292 end Check_Programming_Languages;
4294 -------------------------------
4295 -- Check_Stand_Alone_Library --
4296 -------------------------------
4298 procedure Check_Stand_Alone_Library
4299 (Project : Project_Id;
4300 Data : in out Tree_Processing_Data)
4302 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4304 Lib_Name : constant Prj.Variable_Value :=
4306 (Snames.Name_Library_Name,
4307 Project.Decl.Attributes,
4310 Lib_Interfaces : constant Prj.Variable_Value :=
4312 (Snames.Name_Library_Interface,
4313 Project.Decl.Attributes,
4316 Lib_Auto_Init : constant Prj.Variable_Value :=
4318 (Snames.Name_Library_Auto_Init,
4319 Project.Decl.Attributes,
4322 Lib_Src_Dir : constant Prj.Variable_Value :=
4324 (Snames.Name_Library_Src_Dir,
4325 Project.Decl.Attributes,
4328 Lib_Symbol_File : constant Prj.Variable_Value :=
4330 (Snames.Name_Library_Symbol_File,
4331 Project.Decl.Attributes,
4334 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4336 (Snames.Name_Library_Symbol_Policy,
4337 Project.Decl.Attributes,
4340 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4342 (Snames.Name_Library_Reference_Symbol_File,
4343 Project.Decl.Attributes,
4346 Auto_Init_Supported : Boolean;
4347 OK : Boolean := True;
4349 Next_Proj : Project_Id;
4350 Iter : Source_Iterator;
4353 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4355 pragma Assert (Lib_Interfaces.Kind = List);
4357 -- It is a stand-alone library project file if attribute
4358 -- Library_Interface is defined.
4360 if not Lib_Interfaces.Default then
4362 -- The name of a stand-alone library needs to have the syntax of an
4366 Name : constant String := Get_Name_String (Project.Library_Name);
4367 OK : Boolean := Is_Letter (Name (Name'First));
4369 Underline : Boolean := False;
4372 for J in Name'First + 1 .. Name'Last loop
4375 if Is_Alphanumeric (Name (J)) then
4378 elsif Name (J) = '_' then
4390 OK := OK and not Underline;
4395 "Incorrect library name for a Stand-Alone Library",
4396 Lib_Name.Location, Project);
4402 Interfaces : String_List_Id := Lib_Interfaces.Values;
4403 Interface_ALIs : String_List_Id := Nil_String;
4407 Project.Standalone_Library := True;
4409 -- Library_Interface cannot be an empty list
4411 if Interfaces = Nil_String then
4414 "Library_Interface cannot be an empty list",
4415 Lib_Interfaces.Location, Project);
4418 -- Process each unit name specified in the attribute
4419 -- Library_Interface.
4421 while Interfaces /= Nil_String loop
4423 (Shared.String_Elements.Table (Interfaces).Value);
4424 To_Lower (Name_Buffer (1 .. Name_Len));
4426 if Name_Len = 0 then
4429 "an interface cannot be an empty string",
4430 Shared.String_Elements.Table (Interfaces).Location,
4435 Error_Msg_Name_1 := Unit;
4437 Next_Proj := Project.Extends;
4438 Iter := For_Each_Source (Data.Tree, Project);
4440 while Prj.Element (Iter) /= No_Source
4442 (Prj.Element (Iter).Unit = null
4443 or else Prj.Element (Iter).Unit.Name /= Unit)
4448 Source := Prj.Element (Iter);
4449 exit when Source /= No_Source
4450 or else Next_Proj = No_Project;
4452 Iter := For_Each_Source (Data.Tree, Next_Proj);
4453 Next_Proj := Next_Proj.Extends;
4456 if Source /= No_Source then
4457 if Source.Kind = Sep then
4458 Source := No_Source;
4460 elsif Source.Kind = Spec
4461 and then Other_Part (Source) /= No_Source
4463 Source := Other_Part (Source);
4467 if Source /= No_Source then
4468 if Source.Project /= Project
4469 and then not Is_Extending (Project, Source.Project)
4471 Source := No_Source;
4475 if Source = No_Source then
4478 "%% is not a unit of this project",
4479 Shared.String_Elements.Table (Interfaces).Location,
4483 if Source.Kind = Spec
4484 and then Other_Part (Source) /= No_Source
4486 Source := Other_Part (Source);
4489 String_Element_Table.Increment_Last
4490 (Shared.String_Elements);
4492 Shared.String_Elements.Table
4493 (String_Element_Table.Last (Shared.String_Elements)) :=
4494 (Value => Name_Id (Source.Dep_Name),
4496 Display_Value => Name_Id (Source.Dep_Name),
4498 Shared.String_Elements.Table (Interfaces).Location,
4500 Next => Interface_ALIs);
4503 String_Element_Table.Last (Shared.String_Elements);
4507 Interfaces := Shared.String_Elements.Table (Interfaces).Next;
4510 -- Put the list of Interface ALIs in the project data
4512 Project.Lib_Interface_ALIs := Interface_ALIs;
4514 -- Check value of attribute Library_Auto_Init and set
4515 -- Lib_Auto_Init accordingly.
4517 if Lib_Auto_Init.Default then
4519 -- If no attribute Library_Auto_Init is declared, then set auto
4520 -- init only if it is supported.
4522 Project.Lib_Auto_Init := Auto_Init_Supported;
4525 Get_Name_String (Lib_Auto_Init.Value);
4526 To_Lower (Name_Buffer (1 .. Name_Len));
4528 if Name_Buffer (1 .. Name_Len) = "false" then
4529 Project.Lib_Auto_Init := False;
4531 elsif Name_Buffer (1 .. Name_Len) = "true" then
4532 if Auto_Init_Supported then
4533 Project.Lib_Auto_Init := True;
4536 -- Library_Auto_Init cannot be "true" if auto init is not
4541 "library auto init not supported " &
4543 Lib_Auto_Init.Location, Project);
4549 "invalid value for attribute Library_Auto_Init",
4550 Lib_Auto_Init.Location, Project);
4555 -- If attribute Library_Src_Dir is defined and not the empty string,
4556 -- check if the directory exist and is not the object directory or
4557 -- one of the source directories. This is the directory where copies
4558 -- of the interface sources will be copied. Note that this directory
4559 -- may be the library directory.
4561 if Lib_Src_Dir.Value /= Empty_String then
4563 Dir_Id : constant File_Name_Type :=
4564 File_Name_Type (Lib_Src_Dir.Value);
4565 Dir_Exists : Boolean;
4571 Path => Project.Library_Src_Dir,
4572 Dir_Exists => Dir_Exists,
4574 Must_Exist => False,
4575 Create => "library source copy",
4576 Location => Lib_Src_Dir.Location,
4577 Externally_Built => Project.Externally_Built);
4579 -- If directory does not exist, report an error
4581 if not Dir_Exists then
4583 -- Get the absolute name of the library directory that does
4584 -- not exist, to report an error.
4586 Err_Vars.Error_Msg_File_1 :=
4587 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4590 "Directory { does not exist",
4591 Lib_Src_Dir.Location, Project);
4593 -- Report error if it is the same as the object directory
4595 elsif Project.Library_Src_Dir = Project.Object_Directory then
4598 "directory to copy interfaces cannot be " &
4599 "the object directory",
4600 Lib_Src_Dir.Location, Project);
4601 Project.Library_Src_Dir := No_Path_Information;
4605 Src_Dirs : String_List_Id;
4606 Src_Dir : String_Element;
4610 -- Interface copy directory cannot be one of the source
4611 -- directory of the current project.
4613 Src_Dirs := Project.Source_Dirs;
4614 while Src_Dirs /= Nil_String loop
4615 Src_Dir := Shared.String_Elements.Table (Src_Dirs);
4617 -- Report error if it is one of the source directories
4619 if Project.Library_Src_Dir.Name =
4620 Path_Name_Type (Src_Dir.Value)
4624 "directory to copy interfaces cannot " &
4625 "be one of the source directories",
4626 Lib_Src_Dir.Location, Project);
4627 Project.Library_Src_Dir := No_Path_Information;
4631 Src_Dirs := Src_Dir.Next;
4634 if Project.Library_Src_Dir /= No_Path_Information then
4636 -- It cannot be a source directory of any other
4639 Pid := Data.Tree.Projects;
4641 exit Project_Loop when Pid = null;
4643 Src_Dirs := Pid.Project.Source_Dirs;
4644 Dir_Loop : while Src_Dirs /= Nil_String loop
4646 Shared.String_Elements.Table (Src_Dirs);
4648 -- Report error if it is one of the source
4651 if Project.Library_Src_Dir.Name =
4652 Path_Name_Type (Src_Dir.Value)
4655 File_Name_Type (Src_Dir.Value);
4656 Error_Msg_Name_1 := Pid.Project.Name;
4659 "directory to copy interfaces cannot " &
4660 "be the same as source directory { of " &
4662 Lib_Src_Dir.Location, Project);
4663 Project.Library_Src_Dir :=
4664 No_Path_Information;
4668 Src_Dirs := Src_Dir.Next;
4672 end loop Project_Loop;
4676 -- In high verbosity, if there is a valid Library_Src_Dir,
4677 -- display its path name.
4679 if Project.Library_Src_Dir /= No_Path_Information
4680 and then Current_Verbosity = High
4683 ("Directory to copy interfaces",
4684 Get_Name_String (Project.Library_Src_Dir.Name));
4690 -- Check the symbol related attributes
4692 -- First, the symbol policy
4694 if not Lib_Symbol_Policy.Default then
4696 Value : constant String :=
4698 (Get_Name_String (Lib_Symbol_Policy.Value));
4701 -- Symbol policy must hove one of a limited number of values
4703 if Value = "autonomous" or else Value = "default" then
4704 Project.Symbol_Data.Symbol_Policy := Autonomous;
4706 elsif Value = "compliant" then
4707 Project.Symbol_Data.Symbol_Policy := Compliant;
4709 elsif Value = "controlled" then
4710 Project.Symbol_Data.Symbol_Policy := Controlled;
4712 elsif Value = "restricted" then
4713 Project.Symbol_Data.Symbol_Policy := Restricted;
4715 elsif Value = "direct" then
4716 Project.Symbol_Data.Symbol_Policy := Direct;
4721 "illegal value for Library_Symbol_Policy",
4722 Lib_Symbol_Policy.Location, Project);
4727 -- If attribute Library_Symbol_File is not specified, symbol policy
4728 -- cannot be Restricted.
4730 if Lib_Symbol_File.Default then
4731 if Project.Symbol_Data.Symbol_Policy = Restricted then
4734 "Library_Symbol_File needs to be defined when " &
4735 "symbol policy is Restricted",
4736 Lib_Symbol_Policy.Location, Project);
4740 -- Library_Symbol_File is defined
4742 Project.Symbol_Data.Symbol_File :=
4743 Path_Name_Type (Lib_Symbol_File.Value);
4745 Get_Name_String (Lib_Symbol_File.Value);
4747 if Name_Len = 0 then
4750 "symbol file name cannot be an empty string",
4751 Lib_Symbol_File.Location, Project);
4754 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4757 for J in 1 .. Name_Len loop
4758 if Name_Buffer (J) = '/'
4759 or else Name_Buffer (J) = Directory_Separator
4768 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4771 "symbol file name { is illegal. " &
4772 "Name cannot include directory info.",
4773 Lib_Symbol_File.Location, Project);
4778 -- If attribute Library_Reference_Symbol_File is not defined,
4779 -- symbol policy cannot be Compliant or Controlled.
4781 if Lib_Ref_Symbol_File.Default then
4782 if Project.Symbol_Data.Symbol_Policy = Compliant
4783 or else Project.Symbol_Data.Symbol_Policy = Controlled
4787 "a reference symbol file needs to be defined",
4788 Lib_Symbol_Policy.Location, Project);
4792 -- Library_Reference_Symbol_File is defined, check file exists
4794 Project.Symbol_Data.Reference :=
4795 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4797 Get_Name_String (Lib_Ref_Symbol_File.Value);
4799 if Name_Len = 0 then
4802 "reference symbol file name cannot be an empty string",
4803 Lib_Symbol_File.Location, Project);
4806 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4808 Add_Str_To_Name_Buffer
4809 (Get_Name_String (Project.Directory.Name));
4810 Add_Str_To_Name_Buffer
4811 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4812 Project.Symbol_Data.Reference := Name_Find;
4815 if not Is_Regular_File
4816 (Get_Name_String (Project.Symbol_Data.Reference))
4819 File_Name_Type (Lib_Ref_Symbol_File.Value);
4821 -- For controlled and direct symbol policies, it is an error
4822 -- if the reference symbol file does not exist. For other
4823 -- symbol policies, this is just a warning
4826 Project.Symbol_Data.Symbol_Policy /= Controlled
4827 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4831 "<library reference symbol file { does not exist",
4832 Lib_Ref_Symbol_File.Location, Project);
4834 -- In addition in the non-controlled case, if symbol policy
4835 -- is Compliant, it is changed to Autonomous, because there
4836 -- is no reference to check against, and we don't want to
4837 -- fail in this case.
4839 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4840 if Project.Symbol_Data.Symbol_Policy = Compliant then
4841 Project.Symbol_Data.Symbol_Policy := Autonomous;
4846 -- If both the reference symbol file and the symbol file are
4847 -- defined, then check that they are not the same file.
4849 if Project.Symbol_Data.Symbol_File /= No_Path then
4850 Get_Name_String (Project.Symbol_Data.Symbol_File);
4852 if Name_Len > 0 then
4854 -- We do not need to pass a Directory to
4855 -- Normalize_Pathname, since the path_information
4856 -- already contains absolute information.
4858 Symb_Path : constant String :=
4861 (Project.Object_Directory.Name) &
4862 Name_Buffer (1 .. Name_Len),
4865 Opt.Follow_Links_For_Files);
4866 Ref_Path : constant String :=
4869 (Project.Symbol_Data.Reference),
4872 Opt.Follow_Links_For_Files);
4874 if Symb_Path = Ref_Path then
4877 "library reference symbol file and library" &
4878 " symbol file cannot be the same file",
4879 Lib_Ref_Symbol_File.Location, Project);
4887 end Check_Stand_Alone_Library;
4889 ---------------------
4890 -- Check_Unit_Name --
4891 ---------------------
4893 procedure Check_Unit_Name (Name : String; Unit : out Name_Id) is
4894 The_Name : String := Name;
4895 Real_Name : Name_Id;
4896 Need_Letter : Boolean := True;
4897 Last_Underscore : Boolean := False;
4898 OK : Boolean := The_Name'Length > 0;
4901 function Is_Reserved (Name : Name_Id) return Boolean;
4902 function Is_Reserved (S : String) return Boolean;
4903 -- Check that the given name is not an Ada 95 reserved word. The reason
4904 -- for the Ada 95 here is that we do not want to exclude the case of an
4905 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
4906 -- name would be rejected anyway by the compiler. That means there is no
4907 -- requirement that the project file parser reject this.
4913 function Is_Reserved (S : String) return Boolean is
4916 Add_Str_To_Name_Buffer (S);
4917 return Is_Reserved (Name_Find);
4924 function Is_Reserved (Name : Name_Id) return Boolean is
4926 if Get_Name_Table_Byte (Name) /= 0
4927 and then Name /= Name_Project
4928 and then Name /= Name_Extends
4929 and then Name /= Name_External
4930 and then Name not in Ada_2005_Reserved_Words
4933 Debug_Output ("Ada reserved word: ", Name);
4941 -- Start of processing for Check_Unit_Name
4944 To_Lower (The_Name);
4946 Name_Len := The_Name'Length;
4947 Name_Buffer (1 .. Name_Len) := The_Name;
4949 -- Special cases of children of packages A, G, I and S on VMS
4951 if OpenVMS_On_Target
4952 and then Name_Len > 3
4953 and then Name_Buffer (2 .. 3) = "__"
4955 ((Name_Buffer (1) = 'a') or else
4956 (Name_Buffer (1) = 'g') or else
4957 (Name_Buffer (1) = 'i') or else
4958 (Name_Buffer (1) = 's'))
4960 Name_Buffer (2) := '.';
4961 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
4962 Name_Len := Name_Len - 1;
4965 Real_Name := Name_Find;
4967 if Is_Reserved (Real_Name) then
4971 First := The_Name'First;
4973 for Index in The_Name'Range loop
4976 -- We need a letter (at the beginning, and following a dot),
4977 -- but we don't have one.
4979 if Is_Letter (The_Name (Index)) then
4980 Need_Letter := False;
4985 if Current_Verbosity = High then
4987 Write_Int (Types.Int (Index));
4989 Write_Char (The_Name (Index));
4990 Write_Line ("' is not a letter.");
4996 elsif Last_Underscore
4997 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
4999 -- Two underscores are illegal, and a dot cannot follow
5004 if Current_Verbosity = High then
5006 Write_Int (Types.Int (Index));
5008 Write_Char (The_Name (Index));
5009 Write_Line ("' is illegal here.");
5014 elsif The_Name (Index) = '.' then
5016 -- First, check if the name before the dot is not a reserved word
5018 if Is_Reserved (The_Name (First .. Index - 1)) then
5024 -- We need a letter after a dot
5026 Need_Letter := True;
5028 elsif The_Name (Index) = '_' then
5029 Last_Underscore := True;
5032 -- We need an letter or a digit
5034 Last_Underscore := False;
5036 if not Is_Alphanumeric (The_Name (Index)) then
5039 if Current_Verbosity = High then
5041 Write_Int (Types.Int (Index));
5043 Write_Char (The_Name (Index));
5044 Write_Line ("' is not alphanumeric.");
5052 -- Cannot end with an underscore or a dot
5054 OK := OK and then not Need_Letter and then not Last_Underscore;
5057 if First /= Name'First and then
5058 Is_Reserved (The_Name (First .. The_Name'Last))
5066 -- Signal a problem with No_Name
5070 end Check_Unit_Name;
5072 ----------------------------
5073 -- Compute_Directory_Last --
5074 ----------------------------
5076 function Compute_Directory_Last (Dir : String) return Natural is
5079 and then (Dir (Dir'Last - 1) = Directory_Separator
5081 Dir (Dir'Last - 1) = '/')
5083 return Dir'Last - 1;
5087 end Compute_Directory_Last;
5089 ---------------------
5090 -- Get_Directories --
5091 ---------------------
5093 procedure Get_Directories
5094 (Project : Project_Id;
5095 Data : in out Tree_Processing_Data)
5097 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5099 Object_Dir : constant Variable_Value :=
5101 (Name_Object_Dir, Project.Decl.Attributes, Shared);
5103 Exec_Dir : constant Variable_Value :=
5105 (Name_Exec_Dir, Project.Decl.Attributes, Shared);
5107 Source_Dirs : constant Variable_Value :=
5109 (Name_Source_Dirs, Project.Decl.Attributes, Shared);
5111 Ignore_Source_Sub_Dirs : constant Variable_Value :=
5113 (Name_Ignore_Source_Sub_Dirs,
5114 Project.Decl.Attributes,
5117 Excluded_Source_Dirs : constant Variable_Value :=
5119 (Name_Excluded_Source_Dirs,
5120 Project.Decl.Attributes,
5123 Source_Files : constant Variable_Value :=
5126 Project.Decl.Attributes, Shared);
5128 Last_Source_Dir : String_List_Id := Nil_String;
5129 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
5131 Languages : constant Variable_Value :=
5133 (Name_Languages, Project.Decl.Attributes, Shared);
5135 Remove_Source_Dirs : Boolean := False;
5137 procedure Add_To_Or_Remove_From_Source_Dirs
5138 (Path : Path_Information;
5140 -- When Removed = False, the directory Path_Id to the list of
5141 -- source_dirs if not already in the list. When Removed = True,
5142 -- removed directory Path_Id if in the list.
5144 procedure Find_Source_Dirs is new Expand_Subdirectory_Pattern
5145 (Add_To_Or_Remove_From_Source_Dirs);
5147 ---------------------------------------
5148 -- Add_To_Or_Remove_From_Source_Dirs --
5149 ---------------------------------------
5151 procedure Add_To_Or_Remove_From_Source_Dirs
5152 (Path : Path_Information;
5155 List : String_List_Id;
5156 Prev : String_List_Id;
5157 Rank_List : Number_List_Index;
5158 Prev_Rank : Number_List_Index;
5159 Element : String_Element;
5163 Prev_Rank := No_Number_List;
5164 List := Project.Source_Dirs;
5165 Rank_List := Project.Source_Dir_Ranks;
5166 while List /= Nil_String loop
5167 Element := Shared.String_Elements.Table (List);
5168 exit when Element.Value = Name_Id (Path.Name);
5170 List := Element.Next;
5171 Prev_Rank := Rank_List;
5172 Rank_List := Shared.Number_Lists.Table (Prev_Rank).Next;
5175 -- The directory is in the list if List is not Nil_String
5177 if not Remove_Source_Dirs and then List = Nil_String then
5178 Debug_Output ("adding source dir=", Name_Id (Path.Display_Name));
5180 String_Element_Table.Increment_Last (Shared.String_Elements);
5182 (Value => Name_Id (Path.Name),
5184 Display_Value => Name_Id (Path.Display_Name),
5185 Location => No_Location,
5187 Next => Nil_String);
5189 Number_List_Table.Increment_Last (Shared.Number_Lists);
5191 if Last_Source_Dir = Nil_String then
5193 -- This is the first source directory
5195 Project.Source_Dirs :=
5196 String_Element_Table.Last (Shared.String_Elements);
5197 Project.Source_Dir_Ranks :=
5198 Number_List_Table.Last (Shared.Number_Lists);
5201 -- We already have source directories, link the previous
5202 -- last to the new one.
5204 Shared.String_Elements.Table (Last_Source_Dir).Next :=
5205 String_Element_Table.Last (Shared.String_Elements);
5206 Shared.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
5207 Number_List_Table.Last (Shared.Number_Lists);
5210 -- And register this source directory as the new last
5213 String_Element_Table.Last (Shared.String_Elements);
5214 Shared.String_Elements.Table (Last_Source_Dir) := Element;
5215 Last_Src_Dir_Rank := Number_List_Table.Last (Shared.Number_Lists);
5216 Shared.Number_Lists.Table (Last_Src_Dir_Rank) :=
5217 (Number => Rank, Next => No_Number_List);
5219 elsif Remove_Source_Dirs and then List /= Nil_String then
5221 -- Remove source dir if present
5223 if Prev = Nil_String then
5224 Project.Source_Dirs := Shared.String_Elements.Table (List).Next;
5225 Project.Source_Dir_Ranks :=
5226 Shared.Number_Lists.Table (Rank_List).Next;
5229 Shared.String_Elements.Table (Prev).Next :=
5230 Shared.String_Elements.Table (List).Next;
5231 Shared.Number_Lists.Table (Prev_Rank).Next :=
5232 Shared.Number_Lists.Table (Rank_List).Next;
5235 end Add_To_Or_Remove_From_Source_Dirs;
5237 -- Local declarations
5239 Dir_Exists : Boolean;
5241 No_Sources : constant Boolean :=
5242 ((not Source_Files.Default
5243 and then Source_Files.Values = Nil_String)
5245 (not Source_Dirs.Default
5246 and then Source_Dirs.Values = Nil_String)
5248 (not Languages.Default
5249 and then Languages.Values = Nil_String))
5250 and then Project.Extends = No_Project;
5252 -- Start of processing for Get_Directories
5255 Debug_Output ("starting to look for directories");
5257 -- Set the object directory to its default which may be nil, if there
5258 -- is no sources in the project.
5261 Project.Object_Directory := No_Path_Information;
5263 Project.Object_Directory := Project.Directory;
5266 -- Check the object directory
5268 if Object_Dir.Value /= Empty_String then
5269 Get_Name_String (Object_Dir.Value);
5271 if Name_Len = 0 then
5274 "Object_Dir cannot be empty",
5275 Object_Dir.Location, Project);
5277 elsif not No_Sources then
5279 -- We check that the specified object directory does exist.
5280 -- However, even when it doesn't exist, we set it to a default
5281 -- value. This is for the benefit of tools that recover from
5282 -- errors; for example, these tools could create the non existent
5283 -- directory. We always return an absolute directory name though.
5287 File_Name_Type (Object_Dir.Value),
5288 Path => Project.Object_Directory,
5290 Dir_Exists => Dir_Exists,
5292 Location => Object_Dir.Location,
5293 Must_Exist => False,
5294 Externally_Built => Project.Externally_Built);
5296 if not Dir_Exists and then not Project.Externally_Built then
5298 -- The object directory does not exist, report an error if the
5299 -- project is not externally built.
5301 Err_Vars.Error_Msg_File_1 :=
5302 File_Name_Type (Object_Dir.Value);
5304 (Data.Flags, Data.Flags.Require_Obj_Dirs,
5305 "object directory { not found", Project.Location, Project);
5309 elsif not No_Sources and then Subdirs /= null then
5311 Name_Buffer (1) := '.';
5315 Path => Project.Object_Directory,
5317 Dir_Exists => Dir_Exists,
5319 Location => Object_Dir.Location,
5320 Externally_Built => Project.Externally_Built);
5323 if Current_Verbosity = High then
5324 if Project.Object_Directory = No_Path_Information then
5325 Debug_Output ("no object directory");
5328 ("Object directory",
5329 Get_Name_String (Project.Object_Directory.Display_Name));
5333 -- Check the exec directory
5335 -- We set the object directory to its default
5337 Project.Exec_Directory := Project.Object_Directory;
5339 if Exec_Dir.Value /= Empty_String then
5340 Get_Name_String (Exec_Dir.Value);
5342 if Name_Len = 0 then
5345 "Exec_Dir cannot be empty",
5346 Exec_Dir.Location, Project);
5348 elsif not No_Sources then
5350 -- We check that the specified exec directory does exist
5354 File_Name_Type (Exec_Dir.Value),
5355 Path => Project.Exec_Directory,
5356 Dir_Exists => Dir_Exists,
5359 Location => Exec_Dir.Location,
5360 Externally_Built => Project.Externally_Built);
5362 if not Dir_Exists then
5363 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5365 (Data.Flags, Data.Flags.Missing_Source_Files,
5366 "exec directory { not found", Project.Location, Project);
5371 if Current_Verbosity = High then
5372 if Project.Exec_Directory = No_Path_Information then
5373 Debug_Output ("no exec directory");
5376 ("exec directory: ",
5377 Name_Id (Project.Exec_Directory.Display_Name));
5381 -- Look for the source directories
5383 Debug_Output ("starting to look for source directories");
5385 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5387 if not Source_Files.Default
5388 and then Source_Files.Values = Nil_String
5390 Project.Source_Dirs := Nil_String;
5392 if Project.Qualifier = Standard then
5395 "a standard project cannot have no sources",
5396 Source_Files.Location, Project);
5399 elsif Source_Dirs.Default then
5401 -- No Source_Dirs specified: the single source directory is the one
5402 -- containing the project file.
5404 Remove_Source_Dirs := False;
5405 Add_To_Or_Remove_From_Source_Dirs
5406 (Path => (Name => Project.Directory.Name,
5407 Display_Name => Project.Directory.Display_Name),
5411 Remove_Source_Dirs := False;
5413 (Project => Project,
5415 Patterns => Source_Dirs.Values,
5416 Ignore => Ignore_Source_Sub_Dirs.Values,
5417 Search_For => Search_Directories,
5418 Resolve_Links => Opt.Follow_Links_For_Dirs);
5420 if Project.Source_Dirs = Nil_String
5421 and then Project.Qualifier = Standard
5425 "a standard project cannot have no source directories",
5426 Source_Dirs.Location, Project);
5430 if not Excluded_Source_Dirs.Default
5431 and then Excluded_Source_Dirs.Values /= Nil_String
5433 Remove_Source_Dirs := True;
5435 (Project => Project,
5437 Patterns => Excluded_Source_Dirs.Values,
5438 Ignore => Nil_String,
5439 Search_For => Search_Directories,
5440 Resolve_Links => Opt.Follow_Links_For_Dirs);
5443 Debug_Output ("putting source directories in canonical cases");
5446 Current : String_List_Id := Project.Source_Dirs;
5447 Element : String_Element;
5450 while Current /= Nil_String loop
5451 Element := Shared.String_Elements.Table (Current);
5452 if Element.Value /= No_Name then
5454 Name_Id (Canonical_Case_File_Name (Element.Value));
5455 Shared.String_Elements.Table (Current) := Element;
5458 Current := Element.Next;
5461 end Get_Directories;
5468 (Project : Project_Id;
5469 Data : in out Tree_Processing_Data)
5471 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5473 Mains : constant Variable_Value :=
5475 (Name_Main, Project.Decl.Attributes, Shared);
5476 List : String_List_Id;
5477 Elem : String_Element;
5480 Project.Mains := Mains.Values;
5482 -- If no Mains were specified, and if we are an extending project,
5483 -- inherit the Mains from the project we are extending.
5485 if Mains.Default then
5486 if not Project.Library and then Project.Extends /= No_Project then
5487 Project.Mains := Project.Extends.Mains;
5490 -- In a library project file, Main cannot be specified
5492 elsif Project.Library then
5495 "a library project file cannot have Main specified",
5496 Mains.Location, Project);
5499 List := Mains.Values;
5500 while List /= Nil_String loop
5501 Elem := Shared.String_Elements.Table (List);
5503 if Length_Of_Name (Elem.Value) = 0 then
5506 "?a main cannot have an empty name",
5507 Elem.Location, Project);
5516 ---------------------------
5517 -- Get_Sources_From_File --
5518 ---------------------------
5520 procedure Get_Sources_From_File
5522 Location : Source_Ptr;
5523 Project : in out Project_Processing_Data;
5524 Data : in out Tree_Processing_Data)
5526 File : Prj.Util.Text_File;
5527 Line : String (1 .. 250);
5529 Source_Name : File_Name_Type;
5530 Name_Loc : Name_Location;
5533 if Current_Verbosity = High then
5534 Debug_Output ("opening """ & Path & '"');
5539 Prj.Util.Open (File, Path);
5541 if not Prj.Util.Is_Valid (File) then
5543 (Data.Flags, "file does not exist", Location, Project.Project);
5546 -- Read the lines one by one
5548 while not Prj.Util.End_Of_File (File) loop
5549 Prj.Util.Get_Line (File, Line, Last);
5551 -- A non empty, non comment line should contain a file name
5554 and then (Last = 1 or else Line (1 .. 2) /= "--")
5557 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5558 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5559 Source_Name := Name_Find;
5561 -- Check that there is no directory information
5563 for J in 1 .. Last loop
5564 if Line (J) = '/' or else Line (J) = Directory_Separator then
5565 Error_Msg_File_1 := Source_Name;
5568 "file name cannot include directory information ({)",
5569 Location, Project.Project);
5574 Name_Loc := Source_Names_Htable.Get
5575 (Project.Source_Names, Source_Name);
5577 if Name_Loc = No_Name_Location then
5579 (Name => Source_Name,
5580 Location => Location,
5581 Source => No_Source,
5586 Name_Loc.Listed := True;
5589 Source_Names_Htable.Set
5590 (Project.Source_Names, Source_Name, Name_Loc);
5594 Prj.Util.Close (File);
5597 end Get_Sources_From_File;
5603 function No_Space_Img (N : Natural) return String is
5604 Image : constant String := N'Img;
5606 return Image (2 .. Image'Last);
5609 -----------------------
5610 -- Compute_Unit_Name --
5611 -----------------------
5613 procedure Compute_Unit_Name
5614 (File_Name : File_Name_Type;
5615 Naming : Lang_Naming_Data;
5616 Kind : out Source_Kind;
5618 Project : Project_Processing_Data;
5619 In_Tree : Project_Tree_Ref)
5621 Filename : constant String := Get_Name_String (File_Name);
5622 Last : Integer := Filename'Last;
5627 Unit_Except : Unit_Exception;
5628 Masked : Boolean := False;
5634 if Naming.Separate_Suffix = No_File
5635 or else Naming.Body_Suffix = No_File
5636 or else Naming.Spec_Suffix = No_File
5641 if Naming.Dot_Replacement = No_File then
5642 Debug_Output ("no dot_replacement specified");
5646 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5647 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5648 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5650 -- Choose the longest suffix that matches. If there are several matches,
5651 -- give priority to specs, then bodies, then separates.
5653 if Naming.Separate_Suffix /= Naming.Body_Suffix
5654 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5656 Last := Filename'Last - Sep_Len;
5660 if Filename'Last - Body_Len <= Last
5661 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5663 Last := Natural'Min (Last, Filename'Last - Body_Len);
5667 if Filename'Last - Spec_Len <= Last
5668 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5670 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5674 if Last = Filename'Last then
5675 Debug_Output ("no matching suffix");
5679 -- Check that the casing matches
5681 if File_Names_Case_Sensitive then
5682 case Naming.Casing is
5683 when All_Lower_Case =>
5684 for J in Filename'First .. Last loop
5685 if Is_Letter (Filename (J))
5686 and then not Is_Lower (Filename (J))
5688 Debug_Output ("invalid casing");
5693 when All_Upper_Case =>
5694 for J in Filename'First .. Last loop
5695 if Is_Letter (Filename (J))
5696 and then not Is_Upper (Filename (J))
5698 Debug_Output ("invalid casing");
5703 when Mixed_Case | Unknown =>
5708 -- If Dot_Replacement is not a single dot, then there should not
5709 -- be any dot in the name.
5712 Dot_Repl : constant String :=
5713 Get_Name_String (Naming.Dot_Replacement);
5716 if Dot_Repl /= "." then
5717 for Index in Filename'First .. Last loop
5718 if Filename (Index) = '.' then
5719 Debug_Output ("invalid name, contains dot");
5724 Replace_Into_Name_Buffer
5725 (Filename (Filename'First .. Last), Dot_Repl, '.');
5728 Name_Len := Last - Filename'First + 1;
5729 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5731 (Source => Name_Buffer (1 .. Name_Len),
5732 Mapping => Lower_Case_Map);
5736 -- In the standard GNAT naming scheme, check for special cases: children
5737 -- or separates of A, G, I or S, and run time sources.
5739 if Is_Standard_GNAT_Naming (Naming)
5740 and then Name_Len >= 3
5743 S1 : constant Character := Name_Buffer (1);
5744 S2 : constant Character := Name_Buffer (2);
5745 S3 : constant Character := Name_Buffer (3);
5753 -- Children or separates of packages A, G, I or S. These names
5754 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5755 -- versions (x__... and x~...) are allowed in all platforms,
5756 -- because it is not possible to know the platform before
5757 -- processing of the project files.
5759 if S2 = '_' and then S3 = '_' then
5760 Name_Buffer (2) := '.';
5761 Name_Buffer (3 .. Name_Len - 1) :=
5762 Name_Buffer (4 .. Name_Len);
5763 Name_Len := Name_Len - 1;
5766 Name_Buffer (2) := '.';
5770 -- If it is potentially a run time source
5778 -- Name_Buffer contains the name of the unit in lower-cases. Check
5779 -- that this is a valid unit name
5781 Check_Unit_Name (Name_Buffer (1 .. Name_Len), Unit);
5783 -- If there is a naming exception for the same unit, the file is not
5784 -- a source for the unit.
5786 if Unit /= No_Name then
5788 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5791 Masked := Unit_Except.Spec /= No_File
5793 Unit_Except.Spec /= File_Name;
5795 Masked := Unit_Except.Impl /= No_File
5797 Unit_Except.Impl /= File_Name;
5801 if Current_Verbosity = High then
5803 Write_Str (" """ & Filename & """ contains the ");
5806 Write_Str ("spec of a unit found in """);
5807 Write_Str (Get_Name_String (Unit_Except.Spec));
5809 Write_Str ("body of a unit found in """);
5810 Write_Str (Get_Name_String (Unit_Except.Impl));
5813 Write_Line (""" (ignored)");
5821 and then Current_Verbosity = High
5824 when Spec => Debug_Output ("spec of", Unit);
5825 when Impl => Debug_Output ("body of", Unit);
5826 when Sep => Debug_Output ("sep of", Unit);
5829 end Compute_Unit_Name;
5831 --------------------------
5832 -- Check_Illegal_Suffix --
5833 --------------------------
5835 procedure Check_Illegal_Suffix
5836 (Project : Project_Id;
5837 Suffix : File_Name_Type;
5838 Dot_Replacement : File_Name_Type;
5839 Attribute_Name : String;
5840 Location : Source_Ptr;
5841 Data : in out Tree_Processing_Data)
5843 Suffix_Str : constant String := Get_Name_String (Suffix);
5846 if Suffix_Str'Length = 0 then
5852 elsif Index (Suffix_Str, ".") = 0 then
5853 Err_Vars.Error_Msg_File_1 := Suffix;
5856 "{ is illegal for " & Attribute_Name & ": must have a dot",
5861 -- Case of dot replacement is a single dot, and first character of
5862 -- suffix is also a dot.
5864 if Dot_Replacement /= No_File
5865 and then Get_Name_String (Dot_Replacement) = "."
5866 and then Suffix_Str (Suffix_Str'First) = '.'
5868 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5870 -- If there are multiple dots in the name
5872 if Suffix_Str (Index) = '.' then
5874 -- It is illegal to have a letter following the initial dot
5876 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5877 Err_Vars.Error_Msg_File_1 := Suffix;
5880 "{ is illegal for " & Attribute_Name
5881 & ": ambiguous prefix when Dot_Replacement is a dot",
5888 end Check_Illegal_Suffix;
5890 ----------------------
5891 -- Locate_Directory --
5892 ----------------------
5894 procedure Locate_Directory
5895 (Project : Project_Id;
5896 Name : File_Name_Type;
5897 Path : out Path_Information;
5898 Dir_Exists : out Boolean;
5899 Data : in out Tree_Processing_Data;
5900 Create : String := "";
5901 Location : Source_Ptr := No_Location;
5902 Must_Exist : Boolean := True;
5903 Externally_Built : Boolean := False)
5905 Parent : constant Path_Name_Type :=
5906 Project.Directory.Display_Name;
5907 The_Parent : constant String :=
5908 Get_Name_String (Parent);
5909 The_Parent_Last : constant Natural :=
5910 Compute_Directory_Last (The_Parent);
5911 Full_Name : File_Name_Type;
5912 The_Name : File_Name_Type;
5915 Get_Name_String (Name);
5917 -- Add Subdirs.all if it is a directory that may be created and
5918 -- Subdirs is not null;
5920 if Create /= "" and then Subdirs /= null then
5921 if Name_Buffer (Name_Len) /= Directory_Separator then
5922 Add_Char_To_Name_Buffer (Directory_Separator);
5925 Add_Str_To_Name_Buffer (Subdirs.all);
5928 -- Convert '/' to directory separator (for Windows)
5930 for J in 1 .. Name_Len loop
5931 if Name_Buffer (J) = '/' then
5932 Name_Buffer (J) := Directory_Separator;
5936 The_Name := Name_Find;
5938 if Current_Verbosity = High then
5940 Write_Str ("Locate_Directory (""");
5941 Write_Str (Get_Name_String (The_Name));
5942 Write_Str (""", in """);
5943 Write_Str (The_Parent);
5947 Path := No_Path_Information;
5948 Dir_Exists := False;
5950 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5951 Full_Name := The_Name;
5955 Add_Str_To_Name_Buffer
5956 (The_Parent (The_Parent'First .. The_Parent_Last));
5957 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5958 Full_Name := Name_Find;
5962 Full_Path_Name : String_Access :=
5963 new String'(Get_Name_String (Full_Name));
5966 if (Setup_Projects or else Subdirs /= null)
5967 and then Create'Length > 0
5969 if not Is_Directory (Full_Path_Name.all) then
5971 -- If project is externally built, do not create a subdir,
5972 -- use the specified directory, without the subdir.
5974 if Externally_Built then
5975 if Is_Absolute_Path (Get_Name_String (Name)) then
5976 Get_Name_String (Name);
5980 Add_Str_To_Name_Buffer
5981 (The_Parent (The_Parent'First .. The_Parent_Last));
5982 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5985 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5989 Create_Path (Full_Path_Name.all);
5991 if not Quiet_Output then
5993 Write_Str (" directory """);
5994 Write_Str (Full_Path_Name.all);
5995 Write_Str (""" created for project ");
5996 Write_Line (Get_Name_String (Project.Name));
6003 "could not create " & Create &
6004 " directory " & Full_Path_Name.all,
6011 Dir_Exists := Is_Directory (Full_Path_Name.all);
6013 if not Must_Exist or else Dir_Exists then
6015 Normed : constant String :=
6017 (Full_Path_Name.all,
6019 The_Parent (The_Parent'First .. The_Parent_Last),
6020 Resolve_Links => False,
6021 Case_Sensitive => True);
6023 Canonical_Path : constant String :=
6028 (The_Parent'First .. The_Parent_Last),
6030 Opt.Follow_Links_For_Dirs,
6031 Case_Sensitive => False);
6034 Name_Len := Normed'Length;
6035 Name_Buffer (1 .. Name_Len) := Normed;
6037 -- Directories should always end with a directory separator
6039 if Name_Buffer (Name_Len) /= Directory_Separator then
6040 Add_Char_To_Name_Buffer (Directory_Separator);
6043 Path.Display_Name := Name_Find;
6045 Name_Len := Canonical_Path'Length;
6046 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6048 if Name_Buffer (Name_Len) /= Directory_Separator then
6049 Add_Char_To_Name_Buffer (Directory_Separator);
6052 Path.Name := Name_Find;
6056 Free (Full_Path_Name);
6058 end Locate_Directory;
6060 ---------------------------
6061 -- Find_Excluded_Sources --
6062 ---------------------------
6064 procedure Find_Excluded_Sources
6065 (Project : in out Project_Processing_Data;
6066 Data : in out Tree_Processing_Data)
6068 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6070 Excluded_Source_List_File : constant Variable_Value :=
6072 (Name_Excluded_Source_List_File,
6073 Project.Project.Decl.Attributes,
6075 Excluded_Sources : Variable_Value := Util.Value_Of
6076 (Name_Excluded_Source_Files,
6077 Project.Project.Decl.Attributes,
6080 Current : String_List_Id;
6081 Element : String_Element;
6082 Location : Source_Ptr;
6083 Name : File_Name_Type;
6084 File : Prj.Util.Text_File;
6085 Line : String (1 .. 300);
6087 Locally_Removed : Boolean := False;
6090 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6092 if Excluded_Sources.Default then
6093 Locally_Removed := True;
6096 (Name_Locally_Removed_Files,
6097 Project.Project.Decl.Attributes, Shared);
6100 -- If there are excluded sources, put them in the table
6102 if not Excluded_Sources.Default then
6103 if not Excluded_Source_List_File.Default then
6104 if Locally_Removed then
6107 "?both attributes Locally_Removed_Files and " &
6108 "Excluded_Source_List_File are present",
6109 Excluded_Source_List_File.Location, Project.Project);
6113 "?both attributes Excluded_Source_Files and " &
6114 "Excluded_Source_List_File are present",
6115 Excluded_Source_List_File.Location, Project.Project);
6119 Current := Excluded_Sources.Values;
6120 while Current /= Nil_String loop
6121 Element := Shared.String_Elements.Table (Current);
6122 Name := Canonical_Case_File_Name (Element.Value);
6124 -- If the element has no location, then use the location of
6125 -- Excluded_Sources to report possible errors.
6127 if Element.Location = No_Location then
6128 Location := Excluded_Sources.Location;
6130 Location := Element.Location;
6133 Excluded_Sources_Htable.Set
6134 (Project.Excluded, Name,
6135 (Name, No_File, 0, False, Location));
6136 Current := Element.Next;
6139 elsif not Excluded_Source_List_File.Default then
6140 Location := Excluded_Source_List_File.Location;
6143 Source_File_Name : constant File_Name_Type :=
6145 (Excluded_Source_List_File.Value);
6146 Source_File_Line : Natural := 0;
6148 Source_File_Path_Name : constant String :=
6151 Project.Project.Directory.Name);
6154 if Source_File_Path_Name'Length = 0 then
6155 Err_Vars.Error_Msg_File_1 :=
6156 File_Name_Type (Excluded_Source_List_File.Value);
6159 "file with excluded sources { does not exist",
6160 Excluded_Source_List_File.Location, Project.Project);
6165 Prj.Util.Open (File, Source_File_Path_Name);
6167 if not Prj.Util.Is_Valid (File) then
6169 (Data.Flags, "file does not exist",
6170 Location, Project.Project);
6172 -- Read the lines one by one
6174 while not Prj.Util.End_Of_File (File) loop
6175 Prj.Util.Get_Line (File, Line, Last);
6176 Source_File_Line := Source_File_Line + 1;
6178 -- Non empty, non comment line should contain a file name
6181 and then (Last = 1 or else Line (1 .. 2) /= "--")
6184 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6185 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6188 -- Check that there is no directory information
6190 for J in 1 .. Last loop
6192 or else Line (J) = Directory_Separator
6194 Error_Msg_File_1 := Name;
6197 "file name cannot include " &
6198 "directory information ({)",
6199 Location, Project.Project);
6204 Excluded_Sources_Htable.Set
6207 (Name, Source_File_Name, Source_File_Line,
6212 Prj.Util.Close (File);
6217 end Find_Excluded_Sources;
6223 procedure Find_Sources
6224 (Project : in out Project_Processing_Data;
6225 Data : in out Tree_Processing_Data)
6227 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6229 Sources : constant Variable_Value :=
6232 Project.Project.Decl.Attributes,
6235 Source_List_File : constant Variable_Value :=
6237 (Name_Source_List_File,
6238 Project.Project.Decl.Attributes,
6241 Name_Loc : Name_Location;
6242 Has_Explicit_Sources : Boolean;
6245 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6247 (Source_List_File.Kind = Single,
6248 "Source_List_File is not a single string");
6250 Project.Source_List_File_Location := Source_List_File.Location;
6252 -- If the user has specified a Source_Files attribute
6254 if not Sources.Default then
6255 if not Source_List_File.Default then
6258 "?both attributes source_files and " &
6259 "source_list_file are present",
6260 Source_List_File.Location, Project.Project);
6263 -- Sources is a list of file names
6266 Current : String_List_Id := Sources.Values;
6267 Element : String_Element;
6268 Location : Source_Ptr;
6269 Name : File_Name_Type;
6272 if Current = Nil_String then
6273 Project.Project.Languages := No_Language_Index;
6275 -- This project contains no source. For projects that don't
6276 -- extend other projects, this also means that there is no
6277 -- need for an object directory, if not specified.
6279 if Project.Project.Extends = No_Project
6281 Project.Project.Object_Directory = Project.Project.Directory
6283 not (Project.Project.Qualifier = Aggregate_Library)
6285 Project.Project.Object_Directory := No_Path_Information;
6289 while Current /= Nil_String loop
6290 Element := Shared.String_Elements.Table (Current);
6291 Name := Canonical_Case_File_Name (Element.Value);
6292 Get_Name_String (Element.Value);
6294 -- If the element has no location, then use the location of
6295 -- Sources to report possible errors.
6297 if Element.Location = No_Location then
6298 Location := Sources.Location;
6300 Location := Element.Location;
6303 -- Check that there is no directory information
6305 for J in 1 .. Name_Len loop
6306 if Name_Buffer (J) = '/'
6307 or else Name_Buffer (J) = Directory_Separator
6309 Error_Msg_File_1 := Name;
6312 "file name cannot include directory " &
6314 Location, Project.Project);
6319 -- Check whether the file is already there: the same file name
6320 -- may be in the list. If the source is missing, the error will
6321 -- be on the first mention of the source file name.
6323 Name_Loc := Source_Names_Htable.Get
6324 (Project.Source_Names, Name);
6326 if Name_Loc = No_Name_Location then
6329 Location => Location,
6330 Source => No_Source,
6335 Name_Loc.Listed := True;
6338 Source_Names_Htable.Set
6339 (Project.Source_Names, Name, Name_Loc);
6341 Current := Element.Next;
6344 Has_Explicit_Sources := True;
6347 -- If we have no Source_Files attribute, check the Source_List_File
6350 elsif not Source_List_File.Default then
6352 -- Source_List_File is the name of the file that contains the source
6356 Source_File_Path_Name : constant String :=
6359 (Source_List_File.Value),
6361 Directory.Display_Name);
6364 Has_Explicit_Sources := True;
6366 if Source_File_Path_Name'Length = 0 then
6367 Err_Vars.Error_Msg_File_1 :=
6368 File_Name_Type (Source_List_File.Value);
6371 "file with sources { does not exist",
6372 Source_List_File.Location, Project.Project);
6375 Get_Sources_From_File
6376 (Source_File_Path_Name, Source_List_File.Location,
6382 -- Neither Source_Files nor Source_List_File has been specified. Find
6383 -- all the files that satisfy the naming scheme in all the source
6386 Has_Explicit_Sources := False;
6389 -- Remove any exception that is not in the specified list of sources
6391 if Has_Explicit_Sources then
6394 Iter : Source_Iterator;
6401 Iter := For_Each_Source (Data.Tree, Project.Project);
6405 Source := Prj.Element (Iter);
6406 exit Source_Loop when Source = No_Source;
6408 if Source.Naming_Exception /= No then
6409 NL := Source_Names_Htable.Get
6410 (Project.Source_Names, Source.File);
6412 if NL /= No_Name_Location and then not NL.Listed then
6413 -- Remove the exception
6414 Source_Names_Htable.Set
6415 (Project.Source_Names,
6418 Remove_Source (Data.Tree, Source, No_Source);
6420 if Source.Naming_Exception = Yes then
6421 Error_Msg_Name_1 := Name_Id (Source.File);
6424 "? unknown source file %%",
6435 end loop Source_Loop;
6437 exit Iter_Loop when not Again;
6445 For_All_Sources => Sources.Default and then Source_List_File.Default);
6447 -- Check if all exceptions have been found
6451 Iter : Source_Iterator;
6452 Found : Boolean := False;
6455 Iter := For_Each_Source (Data.Tree, Project.Project);
6457 Source := Prj.Element (Iter);
6458 exit when Source = No_Source;
6460 -- If the full source path is unknown for this source_id, there
6461 -- could be several reasons:
6462 -- * we simply did not find the file itself, this is an error
6463 -- * we have a multi-unit source file. Another Source_Id from
6464 -- the same file has received the full path, so we need to
6467 if Source.Path = No_Path_Information then
6468 if Source.Naming_Exception = Yes then
6469 if Source.Unit /= No_Unit_Index then
6472 if Source.Index /= 0 then -- Only multi-unit files
6475 Source_Files_Htable.Get
6476 (Data.Tree.Source_Files_HT, Source.File);
6479 while S /= null loop
6480 if S.Path /= No_Path_Information then
6481 Source.Path := S.Path;
6484 if Current_Verbosity = High then
6486 ("setting full path for "
6487 & Get_Name_String (Source.File)
6488 & " at" & Source.Index'Img
6490 & Get_Name_String (Source.Path.Name));
6496 S := S.Next_With_File_Name;
6502 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6503 Error_Msg_Name_2 := Source.Unit.Name;
6505 (Data.Flags, Data.Flags.Missing_Source_Files,
6506 "source file %% for unit %% not found",
6507 No_Location, Project.Project);
6511 if Source.Path = No_Path_Information then
6512 Remove_Source (Data.Tree, Source, No_Source);
6515 elsif Source.Naming_Exception = Inherited then
6516 Remove_Source (Data.Tree, Source, No_Source);
6524 -- It is an error if a source file name in a source list or in a source
6525 -- list file is not found.
6527 if Has_Explicit_Sources then
6530 First_Error : Boolean;
6533 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6534 First_Error := True;
6535 while NL /= No_Name_Location loop
6536 if not NL.Found then
6537 Err_Vars.Error_Msg_File_1 := NL.Name;
6540 (Data.Flags, Data.Flags.Missing_Source_Files,
6541 "source file { not found",
6542 NL.Location, Project.Project);
6543 First_Error := False;
6546 (Data.Flags, Data.Flags.Missing_Source_Files,
6547 "\source file { not found",
6548 NL.Location, Project.Project);
6552 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6562 procedure Initialize
6563 (Data : out Tree_Processing_Data;
6564 Tree : Project_Tree_Ref;
6565 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
6566 Flags : Prj.Processing_Flags)
6570 Data.Node_Tree := Node_Tree;
6571 Data.Flags := Flags;
6578 procedure Free (Data : in out Tree_Processing_Data) is
6579 pragma Unreferenced (Data);
6588 procedure Initialize
6589 (Data : in out Project_Processing_Data;
6590 Project : Project_Id)
6593 Data.Project := Project;
6600 procedure Free (Data : in out Project_Processing_Data) is
6602 Source_Names_Htable.Reset (Data.Source_Names);
6603 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6604 Excluded_Sources_Htable.Reset (Data.Excluded);
6607 -------------------------------
6608 -- Check_File_Naming_Schemes --
6609 -------------------------------
6611 procedure Check_File_Naming_Schemes
6612 (In_Tree : Project_Tree_Ref;
6613 Project : Project_Processing_Data;
6614 File_Name : File_Name_Type;
6615 Alternate_Languages : out Language_List;
6616 Language : out Language_Ptr;
6617 Display_Language_Name : out Name_Id;
6619 Lang_Kind : out Language_Kind;
6620 Kind : out Source_Kind)
6622 Filename : constant String := Get_Name_String (File_Name);
6623 Config : Language_Config;
6624 Tmp_Lang : Language_Ptr;
6626 Header_File : Boolean := False;
6627 -- True if we found at least one language for which the file is a header
6628 -- In such a case, we search for all possible languages where this is
6629 -- also a header (C and C++ for instance), since the file might be used
6630 -- for several such languages.
6632 procedure Check_File_Based_Lang;
6633 -- Does the naming scheme test for file-based languages. For those,
6634 -- there is no Unit. Just check if the file name has the implementation
6635 -- or, if it is specified, the template suffix of the language.
6637 -- Returns True if the file belongs to the current language and we
6638 -- should stop searching for matching languages. Not that a given header
6639 -- file could belong to several languages (C and C++ for instance). Thus
6640 -- if we found a header we'll check whether it matches other languages.
6642 ---------------------------
6643 -- Check_File_Based_Lang --
6644 ---------------------------
6646 procedure Check_File_Based_Lang is
6649 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6653 Language := Tmp_Lang;
6656 ("implementation of language ", Display_Language_Name);
6658 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6660 ("header of language ", Display_Language_Name);
6663 Alternate_Languages := new Language_List_Element'
6664 (Language => Language,
6665 Next => Alternate_Languages);
6668 Header_File := True;
6671 Language := Tmp_Lang;
6674 end Check_File_Based_Lang;
6676 -- Start of processing for Check_File_Naming_Schemes
6679 Language := No_Language_Index;
6680 Alternate_Languages := null;
6681 Display_Language_Name := No_Name;
6683 Lang_Kind := File_Based;
6686 Tmp_Lang := Project.Project.Languages;
6687 while Tmp_Lang /= No_Language_Index loop
6688 if Current_Verbosity = High then
6690 ("testing language "
6691 & Get_Name_String (Tmp_Lang.Name)
6692 & " Header_File=" & Header_File'Img);
6695 Display_Language_Name := Tmp_Lang.Display_Name;
6696 Config := Tmp_Lang.Config;
6697 Lang_Kind := Config.Kind;
6701 Check_File_Based_Lang;
6702 exit when Kind = Impl;
6706 -- We know it belongs to a least a file_based language, no
6707 -- need to check unit-based ones.
6709 if not Header_File then
6711 (File_Name => File_Name,
6712 Naming => Config.Naming_Data,
6716 In_Tree => In_Tree);
6718 if Unit /= No_Name then
6719 Language := Tmp_Lang;
6725 Tmp_Lang := Tmp_Lang.Next;
6728 if Language = No_Language_Index then
6729 Debug_Output ("not a source of any language");
6731 end Check_File_Naming_Schemes;
6737 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6739 -- If the file was previously already associated with a unit, change it
6741 if Source.Unit /= null
6742 and then Source.Kind in Spec_Or_Body
6743 and then Source.Unit.File_Names (Source.Kind) /= null
6745 -- If we had another file referencing the same unit (for instance it
6746 -- was in an extended project), that source file is in fact invisible
6747 -- from now on, and in particular doesn't belong to the same unit.
6748 -- If the source is an inherited naming exception, then it may not
6749 -- really exist: the source potentially replaced is left untouched.
6751 if Source.Unit.File_Names (Source.Kind) /= Source then
6752 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6755 Source.Unit.File_Names (Source.Kind) := null;
6758 Source.Kind := Kind;
6760 if Current_Verbosity = High
6761 and then Source.File /= No_File
6763 Debug_Output ("override kind for "
6764 & Get_Name_String (Source.File)
6765 & " idx=" & Source.Index'Img
6766 & " kind=" & Source.Kind'Img);
6769 if Source.Unit /= null then
6770 if Source.Kind = Spec then
6771 Source.Unit.File_Names (Spec) := Source;
6774 Source.Unit.File_Names (Impl) := Source;
6783 procedure Check_File
6784 (Project : in out Project_Processing_Data;
6785 Data : in out Tree_Processing_Data;
6786 Source_Dir_Rank : Natural;
6787 Path : Path_Name_Type;
6788 Display_Path : Path_Name_Type;
6789 File_Name : File_Name_Type;
6790 Display_File_Name : File_Name_Type;
6791 Locally_Removed : Boolean;
6792 For_All_Sources : Boolean)
6794 Name_Loc : Name_Location :=
6795 Source_Names_Htable.Get
6796 (Project.Source_Names, File_Name);
6797 Check_Name : Boolean := False;
6798 Alternate_Languages : Language_List;
6799 Language : Language_Ptr;
6801 Src_Ind : Source_File_Index;
6803 Display_Language_Name : Name_Id;
6804 Lang_Kind : Language_Kind;
6805 Kind : Source_Kind := Spec;
6808 if Current_Verbosity = High then
6809 Debug_Increase_Indent
6810 ("checking file (rank=" & Source_Dir_Rank'Img & ")",
6811 Name_Id (Display_Path));
6814 if Name_Loc = No_Name_Location then
6815 Check_Name := For_All_Sources;
6818 if Name_Loc.Found then
6820 -- Check if it is OK to have the same file name in several
6821 -- source directories.
6823 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6824 Error_Msg_File_1 := File_Name;
6827 "{ is found in several source directories",
6828 Name_Loc.Location, Project.Project);
6832 Name_Loc.Found := True;
6834 Source_Names_Htable.Set
6835 (Project.Source_Names, File_Name, Name_Loc);
6837 if Name_Loc.Source = No_Source then
6841 -- Set the full path for the source_id (which might have been
6842 -- created when parsing the naming exceptions, and therefore
6843 -- might not have the full path).
6844 -- We only set this for this source_id, but not for other
6845 -- source_id in the same file (case of multi-unit source files)
6846 -- For the latter, they will be set in Find_Sources when we
6847 -- check that all source_id have known full paths.
6848 -- Doing this later saves one htable lookup per file in the
6849 -- common case where the user is not using multi-unit files.
6851 Name_Loc.Source.Path := (Path, Display_Path);
6853 Source_Paths_Htable.Set
6854 (Data.Tree.Source_Paths_HT, Path, Name_Loc.Source);
6856 -- Check if this is a subunit
6858 if Name_Loc.Source.Unit /= No_Unit_Index
6859 and then Name_Loc.Source.Kind = Impl
6861 Src_Ind := Sinput.P.Load_Project_File
6862 (Get_Name_String (Display_Path));
6864 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6865 Override_Kind (Name_Loc.Source, Sep);
6869 -- If this is an inherited naming exception, make sure that
6870 -- the naming exception it replaces is no longer a source.
6872 if Name_Loc.Source.Naming_Exception = Inherited then
6874 Proj : Project_Id := Name_Loc.Source.Project.Extends;
6875 Iter : Source_Iterator;
6878 while Proj /= No_Project loop
6879 Iter := For_Each_Source (Data.Tree, Proj);
6880 Src := Prj.Element (Iter);
6881 while Src /= No_Source loop
6882 if Src.File = Name_Loc.Source.File then
6883 Src.Replaced_By := Name_Loc.Source;
6888 Src := Prj.Element (Iter);
6891 Proj := Proj.Extends;
6895 if Name_Loc.Source.Unit /= No_Unit_Index then
6896 if Name_Loc.Source.Kind = Spec then
6897 Name_Loc.Source.Unit.File_Names (Spec) :=
6900 elsif Name_Loc.Source.Kind = Impl then
6901 Name_Loc.Source.Unit.File_Names (Impl) :=
6906 (Data.Tree.Units_HT,
6907 Name_Loc.Source.Unit.Name,
6908 Name_Loc.Source.Unit);
6917 Check_File_Naming_Schemes
6918 (In_Tree => Data.Tree,
6920 File_Name => File_Name,
6921 Alternate_Languages => Alternate_Languages,
6922 Language => Language,
6923 Display_Language_Name => Display_Language_Name,
6925 Lang_Kind => Lang_Kind,
6928 if Language = No_Language_Index then
6930 -- A file name in a list must be a source of a language
6932 if Data.Flags.Error_On_Unknown_Language
6933 and then Name_Loc.Found
6935 Error_Msg_File_1 := File_Name;
6938 "language unknown for {",
6939 Name_Loc.Location, Project.Project);
6945 Project => Project.Project,
6946 Source_Dir_Rank => Source_Dir_Rank,
6947 Lang_Id => Language,
6950 Alternate_Languages => Alternate_Languages,
6951 File_Name => File_Name,
6952 Display_File => Display_File_Name,
6954 Locally_Removed => Locally_Removed,
6955 Path => (Path, Display_Path));
6957 -- If it is a source specified in a list, update the entry in
6958 -- the Source_Names table.
6960 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6961 Name_Loc.Source := Source;
6962 Source_Names_Htable.Set
6963 (Project.Source_Names, File_Name, Name_Loc);
6968 Debug_Decrease_Indent;
6971 ---------------------------------
6972 -- Expand_Subdirectory_Pattern --
6973 ---------------------------------
6975 procedure Expand_Subdirectory_Pattern
6976 (Project : Project_Id;
6977 Data : in out Tree_Processing_Data;
6978 Patterns : String_List_Id;
6979 Ignore : String_List_Id;
6980 Search_For : Search_Type;
6981 Resolve_Links : Boolean)
6983 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6985 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
6986 (Header_Num => Header_Num,
6988 No_Element => False,
6989 Key => Path_Name_Type,
6992 -- Hash table stores recursive source directories, to avoid looking
6993 -- several times, and to avoid cycles that may be introduced by symbolic
6996 File_Pattern : GNAT.Regexp.Regexp;
6997 -- Pattern to use when matching file names
6999 Visited : Recursive_Dirs.Instance;
7001 procedure Find_Pattern
7002 (Pattern_Id : Name_Id;
7004 Location : Source_Ptr);
7005 -- Find a specific pattern
7007 function Recursive_Find_Dirs
7008 (Path : Path_Information;
7009 Rank : Natural) return Boolean;
7010 -- Search all the subdirectories (recursively) of Path.
7011 -- Return True if at least one file or directory was processed
7013 function Subdirectory_Matches
7014 (Path : Path_Information;
7015 Rank : Natural) return Boolean;
7016 -- Called when a matching directory was found. If the user is in fact
7017 -- searching for files, we then search for those files matching the
7018 -- pattern within the directory.
7019 -- Return True if at least one file or directory was processed
7021 --------------------------
7022 -- Subdirectory_Matches --
7023 --------------------------
7025 function Subdirectory_Matches
7026 (Path : Path_Information;
7027 Rank : Natural) return Boolean
7030 Name : String (1 .. 250);
7032 Found : Path_Information;
7033 Success : Boolean := False;
7037 when Search_Directories =>
7038 Callback (Path, Rank);
7041 when Search_Files =>
7042 Open (Dir, Get_Name_String (Path.Display_Name));
7044 Read (Dir, Name, Last);
7047 if Name (Name'First .. Last) /= "."
7048 and then Name (Name'First .. Last) /= ".."
7049 and then Match (Name (Name'First .. Last), File_Pattern)
7051 Get_Name_String (Path.Display_Name);
7052 Add_Str_To_Name_Buffer (Name (Name'First .. Last));
7054 Found.Display_Name := Name_Find;
7055 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7056 Found.Name := Name_Find;
7058 Callback (Found, Rank);
7067 end Subdirectory_Matches;
7069 -------------------------
7070 -- Recursive_Find_Dirs --
7071 -------------------------
7073 function Recursive_Find_Dirs
7074 (Path : Path_Information;
7075 Rank : Natural) return Boolean
7077 Path_Str : constant String := Get_Name_String (Path.Display_Name);
7079 Name : String (1 .. 250);
7081 Success : Boolean := False;
7084 Debug_Output ("looking for subdirs of ", Name_Id (Path.Display_Name));
7086 if Recursive_Dirs.Get (Visited, Path.Name) then
7090 Recursive_Dirs.Set (Visited, Path.Name, True);
7092 Success := Subdirectory_Matches (Path, Rank) or Success;
7094 Open (Dir, Path_Str);
7097 Read (Dir, Name, Last);
7100 if Name (1 .. Last) /= "."
7101 and then Name (1 .. Last) /= ".."
7104 Path_Name : constant String :=
7106 (Name => Name (1 .. Last),
7107 Directory => Path_Str,
7108 Resolve_Links => Resolve_Links)
7109 & Directory_Separator;
7110 Path2 : Path_Information;
7111 OK : Boolean := True;
7114 if Is_Directory (Path_Name) then
7115 if Ignore /= Nil_String then
7117 Dir_Name : String := Name (1 .. Last);
7118 List : String_List_Id := Ignore;
7121 Canonical_Case_File_Name (Dir_Name);
7123 while List /= Nil_String loop
7125 (Shared.String_Elements.Table (List).Value);
7126 Canonical_Case_File_Name
7127 (Name_Buffer (1 .. Name_Len));
7128 OK := Name_Buffer (1 .. Name_Len) /= Dir_Name;
7130 List := Shared.String_Elements.Table (List).Next;
7137 Add_Str_To_Name_Buffer (Path_Name);
7138 Path2.Display_Name := Name_Find;
7140 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7141 Path2.Name := Name_Find;
7144 Recursive_Find_Dirs (Path2, Rank) or Success;
7156 when Directory_Error =>
7158 end Recursive_Find_Dirs;
7164 procedure Find_Pattern
7165 (Pattern_Id : Name_Id;
7167 Location : Source_Ptr)
7169 Pattern : constant String := Get_Name_String (Pattern_Id);
7170 Pattern_End : Natural := Pattern'Last;
7171 Recursive : Boolean;
7172 Dir : File_Name_Type;
7173 Path_Name : Path_Information;
7174 Dir_Exists : Boolean;
7175 Has_Error : Boolean := False;
7179 Debug_Increase_Indent ("Find_Pattern", Pattern_Id);
7181 -- If we are looking for files, find the pattern for the files
7183 if Search_For = Search_Files then
7184 while Pattern_End >= Pattern'First
7185 and then Pattern (Pattern_End) /= '/'
7186 and then Pattern (Pattern_End) /= Directory_Separator
7188 Pattern_End := Pattern_End - 1;
7191 if Pattern_End = Pattern'Last then
7192 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7194 (Data.Flags, Data.Flags.Missing_Source_Files,
7195 "Missing file name or pattern in {", Location, Project);
7199 if Current_Verbosity = High then
7201 Write_Str ("file_pattern=");
7202 Write_Str (Pattern (Pattern_End + 1 .. Pattern'Last));
7203 Write_Str (" dir_pattern=");
7204 Write_Line (Pattern (Pattern'First .. Pattern_End));
7207 File_Pattern := Compile
7208 (Pattern (Pattern_End + 1 .. Pattern'Last),
7210 Case_Sensitive => File_Names_Case_Sensitive);
7212 -- If we had just "*.gpr", this is equivalent to "./*.gpr"
7214 if Pattern_End > Pattern'First then
7215 Pattern_End := Pattern_End - 1; -- Skip directory separator
7220 Pattern_End - 1 >= Pattern'First
7221 and then Pattern (Pattern_End - 1 .. Pattern_End) = "**"
7222 and then (Pattern_End - 1 = Pattern'First
7223 or else Pattern (Pattern_End - 2) = '/'
7224 or else Pattern (Pattern_End - 2) = Directory_Separator);
7227 Pattern_End := Pattern_End - 2;
7228 if Pattern_End > Pattern'First then
7229 Pattern_End := Pattern_End - 1; -- Skip '/'
7233 Name_Len := Pattern_End - Pattern'First + 1;
7234 Name_Buffer (1 .. Name_Len) := Pattern (Pattern'First .. Pattern_End);
7238 (Project => Project,
7241 Dir_Exists => Dir_Exists,
7243 Must_Exist => False);
7245 if not Dir_Exists then
7246 Err_Vars.Error_Msg_File_1 := Dir;
7248 (Data.Flags, Data.Flags.Missing_Source_Files,
7249 "{ is not a valid directory", Location, Project);
7250 Has_Error := Data.Flags.Missing_Source_Files = Error;
7253 if not Has_Error then
7254 -- Links have been resolved if necessary, and Path_Name
7255 -- always ends with a directory separator.
7258 Success := Recursive_Find_Dirs (Path_Name, Rank);
7260 Success := Subdirectory_Matches (Path_Name, Rank);
7265 when Search_Directories =>
7266 null; -- Error can't occur
7268 when Search_Files =>
7269 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7271 (Data.Flags, Data.Flags.Missing_Source_Files,
7272 "file { not found", Location, Project);
7277 Debug_Decrease_Indent ("done Find_Pattern");
7282 Pattern_Id : String_List_Id := Patterns;
7283 Element : String_Element;
7284 Rank : Natural := 1;
7286 -- Start of processing for Expand_Subdirectory_Pattern
7289 while Pattern_Id /= Nil_String loop
7290 Element := Shared.String_Elements.Table (Pattern_Id);
7291 Find_Pattern (Element.Value, Rank, Element.Location);
7293 Pattern_Id := Element.Next;
7296 Recursive_Dirs.Reset (Visited);
7297 end Expand_Subdirectory_Pattern;
7299 ------------------------
7300 -- Search_Directories --
7301 ------------------------
7303 procedure Search_Directories
7304 (Project : in out Project_Processing_Data;
7305 Data : in out Tree_Processing_Data;
7306 For_All_Sources : Boolean)
7308 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
7310 Source_Dir : String_List_Id;
7311 Element : String_Element;
7312 Src_Dir_Rank : Number_List_Index;
7313 Num_Nod : Number_Node;
7315 Name : String (1 .. 1_000);
7317 File_Name : File_Name_Type;
7318 Display_File_Name : File_Name_Type;
7321 Debug_Increase_Indent ("looking for sources of", Project.Project.Name);
7323 -- Loop through subdirectories
7325 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
7327 Source_Dir := Project.Project.Source_Dirs;
7328 while Source_Dir /= Nil_String loop
7330 Num_Nod := Shared.Number_Lists.Table (Src_Dir_Rank);
7331 Element := Shared.String_Elements.Table (Source_Dir);
7333 -- Use Element.Value in this test, not Display_Value, because we
7334 -- want the symbolic links to be resolved when appropriate.
7336 if Element.Value /= No_Name then
7338 Source_Directory : constant String :=
7339 Get_Name_String (Element.Value)
7340 & Directory_Separator;
7342 Dir_Last : constant Natural :=
7343 Compute_Directory_Last (Source_Directory);
7345 Display_Source_Directory : constant String :=
7347 (Element.Display_Value)
7348 & Directory_Separator;
7349 -- Display_Source_Directory is to allow us to open a UTF-8
7350 -- encoded directory on Windows.
7353 if Current_Verbosity = High then
7354 Debug_Increase_Indent
7355 ("Source_Dir (node=" & Num_Nod.Number'Img & ") """
7356 & Source_Directory (Source_Directory'First .. Dir_Last)
7360 -- We look to every entry in the source directory
7362 Open (Dir, Display_Source_Directory);
7365 Read (Dir, Name, Last);
7369 -- In fast project loading mode (without -eL), the user
7370 -- guarantees that no directory has a name which is a
7371 -- valid source name, so we can avoid doing a system call
7372 -- here. This provides a very significant speed up on
7373 -- slow file systems (remote files for instance).
7375 if not Opt.Follow_Links_For_Files
7376 or else Is_Regular_File
7377 (Display_Source_Directory & Name (1 .. Last))
7380 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7381 Display_File_Name := Name_Find;
7383 if Osint.File_Names_Case_Sensitive then
7384 File_Name := Display_File_Name;
7386 Canonical_Case_File_Name
7387 (Name_Buffer (1 .. Name_Len));
7388 File_Name := Name_Find;
7392 Path_Name : constant String :=
7397 (Source_Directory'First ..
7400 Opt.Follow_Links_For_Files,
7401 Case_Sensitive => True);
7403 Path : Path_Name_Type;
7405 Excluded_Sources_Htable.Get
7406 (Project.Excluded, File_Name);
7407 To_Remove : Boolean := False;
7410 Name_Len := Path_Name'Length;
7411 Name_Buffer (1 .. Name_Len) := Path_Name;
7413 if Osint.File_Names_Case_Sensitive then
7416 Canonical_Case_File_Name
7417 (Name_Buffer (1 .. Name_Len));
7421 if FF /= No_File_Found then
7422 if not FF.Found then
7424 Excluded_Sources_Htable.Set
7425 (Project.Excluded, File_Name, FF);
7428 ("excluded source ",
7429 Name_Id (Display_File_Name));
7431 -- Will mark the file as removed, but we
7432 -- still need to add it to the list: if we
7433 -- don't, the file will not appear in the
7434 -- mapping file and will cause the compiler
7441 -- Preserve the user's original casing and use of
7442 -- links. The display_value (a directory) already
7443 -- ends with a directory separator by construction,
7444 -- so no need to add one.
7446 Get_Name_String (Element.Display_Value);
7447 Get_Name_String_And_Append (Display_File_Name);
7450 (Project => Project,
7451 Source_Dir_Rank => Num_Nod.Number,
7454 Display_Path => Name_Find,
7455 File_Name => File_Name,
7456 Locally_Removed => To_Remove,
7457 Display_File_Name => Display_File_Name,
7458 For_All_Sources => For_All_Sources);
7462 if Current_Verbosity = High then
7463 Debug_Output ("ignore " & Name (1 .. Last));
7468 Debug_Decrease_Indent;
7474 when Directory_Error =>
7478 Source_Dir := Element.Next;
7479 Src_Dir_Rank := Num_Nod.Next;
7482 Debug_Decrease_Indent ("end looking for sources.");
7483 end Search_Directories;
7485 ----------------------------
7486 -- Load_Naming_Exceptions --
7487 ----------------------------
7489 procedure Load_Naming_Exceptions
7490 (Project : in out Project_Processing_Data;
7491 Data : in out Tree_Processing_Data)
7494 Iter : Source_Iterator;
7497 Iter := For_Each_Source (Data.Tree, Project.Project);
7499 Source := Prj.Element (Iter);
7500 exit when Source = No_Source;
7502 -- An excluded file cannot also be an exception file name
7504 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
7507 Error_Msg_File_1 := Source.File;
7510 "{ cannot be both excluded and an exception file name",
7511 No_Location, Project.Project);
7515 ("naming exception: adding source file to source_Names: ",
7516 Name_Id (Source.File));
7518 Source_Names_Htable.Set
7519 (Project.Source_Names,
7522 (Name => Source.File,
7523 Location => Source.Location,
7528 -- If this is an Ada exception, record in table Unit_Exceptions
7530 if Source.Unit /= No_Unit_Index then
7532 Unit_Except : Unit_Exception :=
7533 Unit_Exceptions_Htable.Get
7534 (Project.Unit_Exceptions, Source.Unit.Name);
7537 Unit_Except.Name := Source.Unit.Name;
7539 if Source.Kind = Spec then
7540 Unit_Except.Spec := Source.File;
7542 Unit_Except.Impl := Source.File;
7545 Unit_Exceptions_Htable.Set
7546 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7552 end Load_Naming_Exceptions;
7554 ----------------------
7555 -- Look_For_Sources --
7556 ----------------------
7558 procedure Look_For_Sources
7559 (Project : in out Project_Processing_Data;
7560 Data : in out Tree_Processing_Data)
7562 Object_Files : Object_File_Names_Htable.Instance;
7563 Iter : Source_Iterator;
7566 procedure Check_Object (Src : Source_Id);
7567 -- Check if object file name of Src is already used in the project tree,
7568 -- and report an error if so.
7570 procedure Check_Object_Files;
7571 -- Check that no two sources of this project have the same object file
7573 procedure Mark_Excluded_Sources;
7574 -- Mark as such the sources that are declared as excluded
7576 procedure Check_Missing_Sources;
7577 -- Check whether one of the languages has no sources, and report an
7578 -- error when appropriate
7580 procedure Get_Sources_From_Source_Info;
7581 -- Get the source information from the tables that were created when a
7582 -- source info file was read.
7584 ---------------------------
7585 -- Check_Missing_Sources --
7586 ---------------------------
7588 procedure Check_Missing_Sources is
7589 Extending : constant Boolean :=
7590 Project.Project.Extends /= No_Project;
7591 Language : Language_Ptr;
7593 Alt_Lang : Language_List;
7594 Continuation : Boolean := False;
7595 Iter : Source_Iterator;
7597 if not Project.Project.Externally_Built
7598 and then not Extending
7600 Language := Project.Project.Languages;
7601 while Language /= No_Language_Index loop
7603 -- If there are no sources for this language, check if there
7604 -- are sources for which this is an alternate language.
7606 if Language.First_Source = No_Source
7607 and then (Data.Flags.Require_Sources_Other_Lang
7608 or else Language.Name = Name_Ada)
7610 Iter := For_Each_Source (In_Tree => Data.Tree,
7611 Project => Project.Project);
7613 Source := Element (Iter);
7614 exit Source_Loop when Source = No_Source
7615 or else Source.Language = Language;
7617 Alt_Lang := Source.Alternate_Languages;
7618 while Alt_Lang /= null loop
7619 exit Source_Loop when Alt_Lang.Language = Language;
7620 Alt_Lang := Alt_Lang.Next;
7624 end loop Source_Loop;
7626 if Source = No_Source then
7629 Get_Name_String (Language.Display_Name),
7631 Project.Source_List_File_Location,
7633 Continuation := True;
7637 Language := Language.Next;
7640 end Check_Missing_Sources;
7646 procedure Check_Object (Src : Source_Id) is
7650 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7652 -- We cannot just check on "Source /= Src", since we might have
7653 -- two different entries for the same file (and since that's
7654 -- the same file it is expected that it has the same object)
7656 if Source /= No_Source
7657 and then Source.Replaced_By = No_Source
7658 and then Source.Path /= Src.Path
7659 and then Is_Extending (Src.Project, Source.Project)
7661 Error_Msg_File_1 := Src.File;
7662 Error_Msg_File_2 := Source.File;
7665 "{ and { have the same object file name",
7666 No_Location, Project.Project);
7669 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7673 ---------------------------
7674 -- Mark_Excluded_Sources --
7675 ---------------------------
7677 procedure Mark_Excluded_Sources is
7678 Source : Source_Id := No_Source;
7679 Excluded : File_Found;
7683 -- Minor optimization: if there are no excluded files, no need to
7684 -- traverse the list of sources. We cannot however also check whether
7685 -- the existing exceptions have ".Found" set to True (indicating we
7686 -- found them before) because we need to do some final processing on
7687 -- them in any case.
7689 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7692 Proj := Project.Project;
7693 while Proj /= No_Project loop
7694 Iter := For_Each_Source (Data.Tree, Proj);
7695 while Prj.Element (Iter) /= No_Source loop
7696 Source := Prj.Element (Iter);
7697 Excluded := Excluded_Sources_Htable.Get
7698 (Project.Excluded, Source.File);
7700 if Excluded /= No_File_Found then
7701 Source.Locally_Removed := True;
7702 Source.In_Interfaces := False;
7704 if Current_Verbosity = High then
7706 Write_Str ("removing file ");
7708 (Get_Name_String (Excluded.File)
7709 & " " & Get_Name_String (Source.Project.Name));
7712 Excluded_Sources_Htable.Remove
7713 (Project.Excluded, Source.File);
7719 Proj := Proj.Extends;
7723 -- If we have any excluded element left, that means we did not find
7726 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7727 while Excluded /= No_File_Found loop
7728 if not Excluded.Found then
7730 -- Check if the file belongs to another imported project to
7731 -- provide a better error message.
7734 (In_Tree => Data.Tree,
7735 Project => Project.Project,
7736 In_Imported_Only => True,
7737 Base_Name => Excluded.File);
7739 Err_Vars.Error_Msg_File_1 := Excluded.File;
7741 if Src = No_Source then
7742 if Excluded.Excl_File = No_File then
7745 "unknown file {", Excluded.Location, Project.Project);
7751 Get_Name_String (Excluded.Excl_File) & ":" &
7752 No_Space_Img (Excluded.Excl_Line) &
7753 ": unknown file {", Excluded.Location, Project.Project);
7757 if Excluded.Excl_File = No_File then
7760 "cannot remove a source from an imported project: {",
7761 Excluded.Location, Project.Project);
7767 Get_Name_String (Excluded.Excl_File) & ":" &
7768 No_Space_Img (Excluded.Excl_Line) &
7769 ": cannot remove a source from an imported project: {",
7770 Excluded.Location, Project.Project);
7775 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7777 end Mark_Excluded_Sources;
7779 ------------------------
7780 -- Check_Object_Files --
7781 ------------------------
7783 procedure Check_Object_Files is
7784 Iter : Source_Iterator;
7786 Src_Ind : Source_File_Index;
7789 Iter := For_Each_Source (Data.Tree);
7791 Src_Id := Prj.Element (Iter);
7792 exit when Src_Id = No_Source;
7794 if Is_Compilable (Src_Id)
7795 and then Src_Id.Language.Config.Object_Generated
7796 and then Is_Extending (Project.Project, Src_Id.Project)
7798 if Src_Id.Unit = No_Unit_Index then
7799 if Src_Id.Kind = Impl then
7800 Check_Object (Src_Id);
7806 if Other_Part (Src_Id) = No_Source then
7807 Check_Object (Src_Id);
7814 if Other_Part (Src_Id) /= No_Source then
7815 Check_Object (Src_Id);
7818 -- Check if it is a subunit
7821 Sinput.P.Load_Project_File
7822 (Get_Name_String (Src_Id.Path.Display_Name));
7824 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7825 Override_Kind (Src_Id, Sep);
7827 Check_Object (Src_Id);
7836 end Check_Object_Files;
7838 ----------------------------------
7839 -- Get_Sources_From_Source_Info --
7840 ----------------------------------
7842 procedure Get_Sources_From_Source_Info is
7843 Iter : Source_Info_Iterator;
7846 Lang_Id : Language_Ptr;
7849 Initialize (Iter, Project.Project.Name);
7852 Src := Source_Info_Of (Iter);
7854 exit when Src = No_Source_Info;
7856 Id := new Source_Data;
7858 Id.Project := Project.Project;
7860 Lang_Id := Project.Project.Languages;
7861 while Lang_Id /= No_Language_Index
7862 and then Lang_Id.Name /= Src.Language
7864 Lang_Id := Lang_Id.Next;
7867 if Lang_Id = No_Language_Index then
7869 ("unknown language " &
7870 Get_Name_String (Src.Language) &
7872 Get_Name_String (Src.Project) &
7873 " in source info file");
7876 Id.Language := Lang_Id;
7877 Id.Kind := Src.Kind;
7878 Id.Index := Src.Index;
7881 (Path_Name_Type (Src.Display_Path_Name),
7882 Path_Name_Type (Src.Path_Name));
7885 Add_Str_To_Name_Buffer
7886 (Directories.Simple_Name (Get_Name_String (Src.Path_Name)));
7887 Id.File := Name_Find;
7889 Id.Next_With_File_Name :=
7890 Source_Files_Htable.Get (Data.Tree.Source_Files_HT, Id.File);
7891 Source_Files_Htable.Set (Data.Tree.Source_Files_HT, Id.File, Id);
7894 Add_Str_To_Name_Buffer
7895 (Directories.Simple_Name
7896 (Get_Name_String (Src.Display_Path_Name)));
7897 Id.Display_File := Name_Find;
7900 Dependency_Name (Id.File, Id.Language.Config.Dependency_Kind);
7901 Id.Naming_Exception := Src.Naming_Exception;
7903 Object_Name (Id.File, Id.Language.Config.Object_File_Suffix);
7904 Id.Switches := Switches_Name (Id.File);
7906 -- Add the source id to the Unit_Sources_HT hash table, if the
7907 -- unit name is not null.
7909 if Src.Kind /= Sep and then Src.Unit_Name /= No_Name then
7912 UData : Unit_Index :=
7914 (Data.Tree.Units_HT, Src.Unit_Name);
7916 if UData = No_Unit_Index then
7917 UData := new Unit_Data;
7918 UData.Name := Src.Unit_Name;
7920 (Data.Tree.Units_HT, Src.Unit_Name, UData);
7926 -- Note that this updates Unit information as well
7928 Override_Kind (Id, Id.Kind);
7931 if Src.Index /= 0 then
7932 Project.Project.Has_Multi_Unit_Sources := True;
7935 -- Add the source to the language list
7937 Id.Next_In_Lang := Id.Language.First_Source;
7938 Id.Language.First_Source := Id;
7942 end Get_Sources_From_Source_Info;
7944 -- Start of processing for Look_For_Sources
7947 if Data.Tree.Source_Info_File_Exists then
7948 Get_Sources_From_Source_Info;
7951 if Project.Project.Source_Dirs /= Nil_String then
7952 Find_Excluded_Sources (Project, Data);
7954 if Project.Project.Languages /= No_Language_Index then
7955 Load_Naming_Exceptions (Project, Data);
7956 Find_Sources (Project, Data);
7957 Mark_Excluded_Sources;
7959 Check_Missing_Sources;
7963 Object_File_Names_Htable.Reset (Object_Files);
7965 end Look_For_Sources;
7971 function Path_Name_Of
7972 (File_Name : File_Name_Type;
7973 Directory : Path_Name_Type) return String
7975 Result : String_Access;
7976 The_Directory : constant String := Get_Name_String (Directory);
7979 Debug_Output ("Path_Name_Of file name=", Name_Id (File_Name));
7980 Debug_Output ("Path_Name_Of directory=", Name_Id (Directory));
7981 Get_Name_String (File_Name);
7984 (File_Name => Name_Buffer (1 .. Name_Len),
7985 Path => The_Directory);
7987 if Result = null then
7991 R : constant String := Result.all;
8003 procedure Remove_Source
8004 (Tree : Project_Tree_Ref;
8006 Replaced_By : Source_Id)
8011 if Current_Verbosity = High then
8013 Write_Str ("removing source ");
8014 Write_Str (Get_Name_String (Id.File));
8016 if Id.Index /= 0 then
8017 Write_Str (" at" & Id.Index'Img);
8023 if Replaced_By /= No_Source then
8024 Id.Replaced_By := Replaced_By;
8025 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
8027 if Id.File /= Replaced_By.File then
8029 Replacement : constant File_Name_Type :=
8030 Replaced_Source_HTable.Get
8031 (Tree.Replaced_Sources, Id.File);
8034 Replaced_Source_HTable.Set
8035 (Tree.Replaced_Sources, Id.File, Replaced_By.File);
8037 if Replacement = No_File then
8038 Tree.Replaced_Source_Number :=
8039 Tree.Replaced_Source_Number + 1;
8045 Id.In_Interfaces := False;
8046 Id.Locally_Removed := True;
8048 -- ??? Should we remove the source from the unit ? The file is not used,
8049 -- so probably should not be referenced from the unit. On the other hand
8050 -- it might give useful additional info
8051 -- if Id.Unit /= null then
8052 -- Id.Unit.File_Names (Id.Kind) := null;
8055 Source := Id.Language.First_Source;
8058 Id.Language.First_Source := Id.Next_In_Lang;
8061 while Source.Next_In_Lang /= Id loop
8062 Source := Source.Next_In_Lang;
8065 Source.Next_In_Lang := Id.Next_In_Lang;
8069 -----------------------
8070 -- Report_No_Sources --
8071 -----------------------
8073 procedure Report_No_Sources
8074 (Project : Project_Id;
8076 Data : Tree_Processing_Data;
8077 Location : Source_Ptr;
8078 Continuation : Boolean := False)
8081 case Data.Flags.When_No_Sources is
8085 when Warning | Error =>
8087 Msg : constant String :=
8089 & Lang_Name & " sources in this project";
8092 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
8094 if Continuation then
8095 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
8097 Error_Msg (Data.Flags, Msg, Location, Project);
8101 end Report_No_Sources;
8103 ----------------------
8104 -- Show_Source_Dirs --
8105 ----------------------
8107 procedure Show_Source_Dirs
8108 (Project : Project_Id;
8109 Shared : Shared_Project_Tree_Data_Access)
8111 Current : String_List_Id;
8112 Element : String_Element;
8115 if Project.Source_Dirs = Nil_String then
8116 Debug_Output ("no Source_Dirs");
8118 Debug_Increase_Indent ("Source_Dirs:");
8120 Current := Project.Source_Dirs;
8121 while Current /= Nil_String loop
8122 Element := Shared.String_Elements.Table (Current);
8123 Debug_Output (Get_Name_String (Element.Display_Value));
8124 Current := Element.Next;
8127 Debug_Decrease_Indent ("end Source_Dirs.");
8129 end Show_Source_Dirs;
8131 ---------------------------
8132 -- Process_Naming_Scheme --
8133 ---------------------------
8135 procedure Process_Naming_Scheme
8136 (Tree : Project_Tree_Ref;
8137 Root_Project : Project_Id;
8138 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
8139 Flags : Processing_Flags)
8141 procedure Recursive_Check
8142 (Project : Project_Id;
8143 Prj_Tree : Project_Tree_Ref;
8144 Data : in out Tree_Processing_Data);
8145 -- Check_Naming_Scheme for the project
8147 ---------------------
8148 -- Recursive_Check --
8149 ---------------------
8151 procedure Recursive_Check
8152 (Project : Project_Id;
8153 Prj_Tree : Project_Tree_Ref;
8154 Data : in out Tree_Processing_Data) is
8156 if Current_Verbosity = High then
8157 Debug_Increase_Indent
8158 ("Processing_Naming_Scheme for project", Project.Name);
8161 Data.Tree := Prj_Tree;
8162 Prj.Nmsc.Check (Project, Data);
8164 if Current_Verbosity = High then
8165 Debug_Decrease_Indent ("done Processing_Naming_Scheme");
8167 end Recursive_Check;
8169 procedure Check_All_Projects is new
8170 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
8172 Data : Tree_Processing_Data;
8174 -- Start of processing for Process_Naming_Scheme
8176 Lib_Data_Table.Init;
8177 Initialize (Data, Tree => Tree, Node_Tree => Node_Tree, Flags => Flags);
8178 Check_All_Projects (Root_Project, Tree, Data, Imported_First => True);
8181 -- Adjust language configs for projects that are extended
8184 List : Project_List;
8187 Lang : Language_Ptr;
8188 Elng : Language_Ptr;
8191 List := Tree.Projects;
8192 while List /= null loop
8193 Proj := List.Project;
8195 while Exte.Extended_By /= No_Project loop
8196 Exte := Exte.Extended_By;
8199 if Exte /= Proj then
8200 Lang := Proj.Languages;
8202 if Lang /= No_Language_Index then
8204 Elng := Get_Language_From_Name
8205 (Exte, Get_Name_String (Lang.Name));
8206 exit when Elng /= No_Language_Index;
8207 Exte := Exte.Extends;
8210 if Elng /= Lang then
8211 Lang.Config := Elng.Config;
8219 end Process_Naming_Scheme;