1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with GNAT.Case_Util; use GNAT.Case_Util;
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
28 with GNAT.Dynamic_HTables;
30 with Err_Vars; use Err_Vars;
32 with Osint; use Osint;
33 with Output; use Output;
35 with Prj.Util; use Prj.Util;
37 with Snames; use Snames;
38 with Targparm; use Targparm;
40 with Ada.Characters.Handling; use Ada.Characters.Handling;
41 with Ada.Directories; use Ada.Directories;
42 with Ada.Strings; use Ada.Strings;
43 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
44 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
46 package body Prj.Nmsc is
48 No_Continuation_String : aliased String := "";
49 Continuation_String : aliased String := "\";
50 -- Used in Check_Library for continuation error messages at the same
53 type Name_Location is record
54 Name : File_Name_Type; -- ??? duplicates the key
55 Location : Source_Ptr;
56 Source : Source_Id := No_Source;
57 Found : Boolean := False;
59 No_Name_Location : constant Name_Location :=
60 (No_File, No_Location, No_Source, False);
61 package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
62 (Header_Num => Header_Num,
63 Element => Name_Location,
64 No_Element => No_Name_Location,
65 Key => File_Name_Type,
68 -- Information about file names found in string list attribute
69 -- (Source_Files or Source_List_File).
70 -- Except is set to True if source is a naming exception in the project.
71 -- This is used to check that all referenced files were indeed found on the
74 type Unit_Exception is record
75 Name : Name_Id; -- ??? duplicates the key
76 Spec : File_Name_Type;
77 Impl : File_Name_Type;
80 No_Unit_Exception : constant Unit_Exception := (No_Name, No_File, No_File);
82 package Unit_Exceptions_Htable is new GNAT.Dynamic_HTables.Simple_HTable
83 (Header_Num => Header_Num,
84 Element => Unit_Exception,
85 No_Element => No_Unit_Exception,
89 -- Record special naming schemes for Ada units (name of spec file and name
90 -- of implementation file). The elements in this list come from the naming
91 -- exceptions specified in the project files.
93 type File_Found is record
94 File : File_Name_Type := No_File;
95 Found : Boolean := False;
96 Location : Source_Ptr := No_Location;
99 No_File_Found : constant File_Found := (No_File, False, No_Location);
101 package Excluded_Sources_Htable is new GNAT.Dynamic_HTables.Simple_HTable
102 (Header_Num => Header_Num,
103 Element => File_Found,
104 No_Element => No_File_Found,
105 Key => File_Name_Type,
108 -- A hash table to store the base names of excluded files, if any.
110 package Object_File_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
111 (Header_Num => Header_Num,
112 Element => Source_Id,
113 No_Element => No_Source,
114 Key => File_Name_Type,
117 -- A hash table to store the object file names for a project, to check that
118 -- two different sources have different object file names.
120 type Project_Processing_Data is record
121 Project : Project_Id;
122 Source_Names : Source_Names_Htable.Instance;
123 Unit_Exceptions : Unit_Exceptions_Htable.Instance;
124 Excluded : Excluded_Sources_Htable.Instance;
126 Source_List_File_Location : Source_Ptr;
127 -- Location of the Source_List_File attribute, for error messages
129 -- This is similar to Tree_Processing_Data, but contains project-specific
130 -- information which is only useful while processing the project, and can
131 -- be discarded as soon as we have finished processing the project
133 package Files_Htable is new GNAT.Dynamic_HTables.Simple_HTable
134 (Header_Num => Header_Num,
135 Element => Source_Id,
136 No_Element => No_Source,
137 Key => File_Name_Type,
140 -- Mapping from base file names to Source_Id (containing full info about
143 type Tree_Processing_Data is record
144 Tree : Project_Tree_Ref;
145 File_To_Source : Files_Htable.Instance;
146 Flags : Prj.Processing_Flags;
148 -- Temporary data which is needed while parsing a project. It does not need
149 -- to be kept in memory once a project has been fully loaded, but is
150 -- necessary while performing consistency checks (duplicate sources,...)
151 -- This data must be initialized before processing any project, and the
152 -- same data is used for processing all projects in the tree.
155 (Data : out Tree_Processing_Data;
156 Tree : Project_Tree_Ref;
157 Flags : Prj.Processing_Flags);
160 procedure Free (Data : in out Tree_Processing_Data);
161 -- Free the memory occupied by Data
164 (Project : Project_Id;
165 Data : in out Tree_Processing_Data);
166 -- Process the naming scheme for a single project.
169 (Data : in out Project_Processing_Data;
170 Project : Project_Id);
171 procedure Free (Data : in out Project_Processing_Data);
172 -- Initialize or free memory for a project-specific data
174 procedure Find_Excluded_Sources
175 (Project : in out Project_Processing_Data;
176 Data : in out Tree_Processing_Data);
177 -- Find the list of files that should not be considered as source files
178 -- for this project. Sets the list in the Project.Excluded_Sources_Htable.
180 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
181 -- Override the reference kind for a source file. This properly updates
182 -- the unit data if necessary.
184 procedure Load_Naming_Exceptions
185 (Project : in out Project_Processing_Data;
186 Data : in out Tree_Processing_Data);
187 -- All source files in Data.First_Source are considered as naming
188 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
193 Data : in out Tree_Processing_Data;
194 Project : Project_Id;
195 Lang_Id : Language_Ptr;
197 File_Name : File_Name_Type;
198 Display_File : File_Name_Type;
199 Naming_Exception : Boolean := False;
200 Path : Path_Information := No_Path_Information;
201 Alternate_Languages : Language_List := null;
202 Unit : Name_Id := No_Name;
204 Location : Source_Ptr := No_Location);
205 -- Add a new source to the different lists: list of all sources in the
206 -- project tree, list of source of a project and list of sources of a
209 -- If Path is specified, the file is also added to Source_Paths_HT.
211 -- Location is used for error messages
213 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
214 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
215 -- This alters Name_Buffer
217 function Suffix_Matches
219 Suffix : File_Name_Type) return Boolean;
220 -- True if the file name ends with the given suffix. Always returns False
221 -- if Suffix is No_Name.
223 procedure Replace_Into_Name_Buffer
226 Replacement : Character);
227 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
228 -- converted to lower-case at the same time.
230 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
231 -- Check that a name is a valid Ada unit name
233 procedure Check_Package_Naming
234 (Project : Project_Id;
235 Data : in out Tree_Processing_Data;
236 Bodies : out Array_Element_Id;
237 Specs : out Array_Element_Id);
238 -- Check the naming scheme part of Data, and initialize the naming scheme
239 -- data in the config of the various languages. This also returns the
240 -- naming scheme exceptions for unit-based languages (Bodies and Specs are
241 -- associative arrays mapping individual unit names to source file names).
243 procedure Check_Configuration
244 (Project : Project_Id;
245 Data : in out Tree_Processing_Data);
246 -- Check the configuration attributes for the project
248 procedure Check_If_Externally_Built
249 (Project : Project_Id;
250 Data : in out Tree_Processing_Data);
251 -- Check attribute Externally_Built of project Project in project tree
252 -- Data.Tree and modify its data Data if it has the value "true".
254 procedure Check_Interfaces
255 (Project : Project_Id;
256 Data : in out Tree_Processing_Data);
257 -- If a list of sources is specified in attribute Interfaces, set
258 -- In_Interfaces only for the sources specified in the list.
260 procedure Check_Library_Attributes
261 (Project : Project_Id;
262 Data : in out Tree_Processing_Data);
263 -- Check the library attributes of project Project in project tree
264 -- and modify its data Data accordingly.
266 procedure Check_Programming_Languages
267 (Project : Project_Id;
268 Data : in out Tree_Processing_Data);
269 -- Check attribute Languages for the project with data Data in project
270 -- tree Data.Tree and set the components of Data for all the programming
271 -- languages indicated in attribute Languages, if any.
273 procedure Check_Stand_Alone_Library
274 (Project : Project_Id;
275 Data : in out Tree_Processing_Data);
276 -- Check if project Project in project tree Data.Tree is a Stand-Alone
277 -- Library project, and modify its data Data accordingly if it is one.
279 function Compute_Directory_Last (Dir : String) return Natural;
280 -- Return the index of the last significant character in Dir. This is used
281 -- to avoid duplicate '/' (slash) characters at the end of directory names.
284 (Project : Project_Id;
286 Flag_Location : Source_Ptr;
287 Data : Tree_Processing_Data);
288 -- Output an error message. If Data.Error_Report is null, simply call
289 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
290 -- Error_Report. If Msg starts with "?", this is a warning, and the
291 -- string "Warning :" is adding at the beginning. If Msg starts with "<",
292 -- see comment for Err_Vars.Error_Msg_Warn
294 procedure Search_Directories
295 (Project : in out Project_Processing_Data;
296 Data : in out Tree_Processing_Data;
297 For_All_Sources : Boolean);
298 -- Search the source directories to find the sources. If For_All_Sources is
299 -- True, check each regular file name against the naming schemes of the
300 -- different languages. Otherwise consider only the file names in the hash
301 -- table Source_Names. If Allow_Duplicate_Basenames, then files with the
302 -- same base names are authorized within a project for source-based
303 -- languages (never for unit based languages)
306 (Project : in out Project_Processing_Data;
307 Data : in out Tree_Processing_Data;
308 Path : Path_Name_Type;
309 File_Name : File_Name_Type;
310 Display_File_Name : File_Name_Type;
311 Locally_Removed : Boolean;
312 For_All_Sources : Boolean);
313 -- Check if file File_Name is a valid source of the project. This is used
314 -- in multi-language mode only. When the file matches one of the naming
315 -- schemes, it is added to various htables through Add_Source and to
316 -- Source_Paths_Htable.
318 -- Name is the name of the candidate file. It hasn't been normalized yet
319 -- and is the direct result of readdir().
321 -- File_Name is the same as Name, but has been normalized.
322 -- Display_File_Name, however, has not been normalized.
324 -- Source_Directory is the directory in which the file
325 -- was found. It hasn't been normalized (nor has had links resolved).
326 -- It should not end with a directory separator, to avoid duplicates
329 -- If For_All_Sources is True, then all possible file names are analyzed
330 -- otherwise only those currently set in the Source_Names htable.
332 procedure Check_File_Naming_Schemes
333 (In_Tree : Project_Tree_Ref;
334 Project : Project_Processing_Data;
335 File_Name : File_Name_Type;
336 Alternate_Languages : out Language_List;
337 Language : out Language_Ptr;
338 Display_Language_Name : out Name_Id;
340 Lang_Kind : out Language_Kind;
341 Kind : out Source_Kind);
342 -- Check if the file name File_Name conforms to one of the naming schemes
343 -- of the project. If the file does not match one of the naming schemes,
344 -- set Language to No_Language_Index. Filename is the name of the file
345 -- being investigated. It has been normalized (case-folded). File_Name is
348 procedure Get_Directories
349 (Project : Project_Id;
350 Data : in out Tree_Processing_Data);
351 -- Get the object directory, the exec directory and the source directories
355 (Project : Project_Id;
356 Data : in out Tree_Processing_Data);
357 -- Get the mains of a project from attribute Main, if it exists, and put
358 -- them in the project data.
360 procedure Get_Sources_From_File
362 Location : Source_Ptr;
363 Project : in out Project_Processing_Data;
364 Data : in out Tree_Processing_Data);
365 -- Get the list of sources from a text file and put them in hash table
368 procedure Find_Sources
369 (Project : in out Project_Processing_Data;
370 Data : in out Tree_Processing_Data);
371 -- Process the Source_Files and Source_List_File attributes, and store the
372 -- list of source files into the Source_Names htable. When these attributes
373 -- are not defined, find all files matching the naming schemes in the
374 -- source directories. If Allow_Duplicate_Basenames, then files with the
375 -- same base names are authorized within a project for source-based
376 -- languages (never for unit based languages)
378 procedure Compute_Unit_Name
379 (File_Name : File_Name_Type;
380 Naming : Lang_Naming_Data;
381 Kind : out Source_Kind;
383 Project : Project_Processing_Data;
384 In_Tree : Project_Tree_Ref);
385 -- Check whether the file matches the naming scheme. If it does,
386 -- compute its unit name. If Unit is set to No_Name on exit, none of the
387 -- other out parameters are relevant.
389 procedure Check_Illegal_Suffix
390 (Project : Project_Id;
391 Suffix : File_Name_Type;
392 Dot_Replacement : File_Name_Type;
393 Attribute_Name : String;
394 Location : Source_Ptr;
395 Data : in out Tree_Processing_Data);
396 -- Display an error message if the given suffix is illegal for some reason.
397 -- The name of the attribute we are testing is specified in Attribute_Name,
398 -- which is used in the error message. Location is the location where the
399 -- suffix is defined.
401 procedure Locate_Directory
402 (Project : Project_Id;
403 Name : File_Name_Type;
404 Path : out Path_Information;
405 Dir_Exists : out Boolean;
406 Data : in out Tree_Processing_Data;
407 Create : String := "";
408 Location : Source_Ptr := No_Location;
409 Must_Exist : Boolean := True;
410 Externally_Built : Boolean := False);
411 -- Locate a directory. Name is the directory name. Relative paths are
412 -- resolved relative to the project's directory. If the directory does not
413 -- exist and Setup_Projects is True and Create is a non null string, an
414 -- attempt is made to create the directory. If the directory does not
415 -- exist, it is either created if Setup_Projects is False (and then
416 -- returned), or simply returned without checking for its existence (if
417 -- Must_Exist is False) or No_Path_Information is returned. In all cases,
418 -- Dir_Exists indicates whether the directory now exists. Create is also
419 -- used for debugging traces to show which path we are computing.
421 procedure Look_For_Sources
422 (Project : in out Project_Processing_Data;
423 Data : in out Tree_Processing_Data);
424 -- Find all the sources of project Project in project tree Data.Tree and
425 -- update its Data accordingly. This assumes that Data.First_Source has
426 -- been initialized with the list of excluded sources and special naming
429 function Path_Name_Of
430 (File_Name : File_Name_Type;
431 Directory : Path_Name_Type) return String;
432 -- Returns the path name of a (non project) file. Returns an empty string
433 -- if file cannot be found.
435 procedure Remove_Source
437 Replaced_By : Source_Id);
438 -- Remove a file from the list of sources of a project. This might be
439 -- because the file is replaced by another one in an extending project,
440 -- or because a file was added as a naming exception but was not found
443 procedure Report_No_Sources
444 (Project : Project_Id;
446 Data : Tree_Processing_Data;
447 Location : Source_Ptr;
448 Continuation : Boolean := False);
449 -- Report an error or a warning depending on the value of When_No_Sources
450 -- when there are no sources for language Lang_Name.
452 procedure Show_Source_Dirs
453 (Project : Project_Id; In_Tree : Project_Tree_Ref);
454 -- List all the source directories of a project
456 procedure Write_Attr (Name, Value : String);
457 -- Debug print a value for a specific property. Does nothing when not in
460 ------------------------------
461 -- Replace_Into_Name_Buffer --
462 ------------------------------
464 procedure Replace_Into_Name_Buffer
467 Replacement : Character)
469 Max : constant Integer := Str'Last - Pattern'Length + 1;
476 while J <= Str'Last loop
477 Name_Len := Name_Len + 1;
480 and then Str (J .. J + Pattern'Length - 1) = Pattern
482 Name_Buffer (Name_Len) := Replacement;
483 J := J + Pattern'Length;
486 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
490 end Replace_Into_Name_Buffer;
496 function Suffix_Matches
498 Suffix : File_Name_Type) return Boolean
500 Min_Prefix_Length : Natural := 0;
503 if Suffix = No_File or else Suffix = Empty_File then
508 Suf : constant String := Get_Name_String (Suffix);
511 -- The file name must end with the suffix (which is not an extension)
512 -- For instance a suffix "configure.in" must match a file with the
513 -- same name. To avoid dummy cases, though, a suffix starting with
514 -- '.' requires a file that is at least one character longer ('.cpp'
515 -- should not match a file with the same name)
517 if Suf (Suf'First) = '.' then
518 Min_Prefix_Length := 1;
521 return Filename'Length >= Suf'Length + Min_Prefix_Length
523 (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
531 procedure Write_Attr (Name, Value : String) is
533 if Current_Verbosity = High then
534 Write_Str (" " & Name & " = """);
547 Data : in out Tree_Processing_Data;
548 Project : Project_Id;
549 Lang_Id : Language_Ptr;
551 File_Name : File_Name_Type;
552 Display_File : File_Name_Type;
553 Naming_Exception : Boolean := False;
554 Path : Path_Information := No_Path_Information;
555 Alternate_Languages : Language_List := null;
556 Unit : Name_Id := No_Name;
558 Location : Source_Ptr := No_Location)
560 Config : constant Language_Config := Lang_Id.Config;
564 Prev_Unit : Unit_Index := No_Unit_Index;
565 Source_To_Replace : Source_Id := No_Source;
568 -- Check if the same file name or unit is used in the prj tree
572 if Unit /= No_Name then
573 Prev_Unit := Units_Htable.Get (Data.Tree.Units_HT, Unit);
576 if Prev_Unit /= No_Unit_Index
577 and then (Kind = Impl or Kind = Spec)
578 and then Prev_Unit.File_Names (Kind) /= null
580 -- Suspicious, we need to check later whether this is authorized
583 Source := Prev_Unit.File_Names (Kind);
586 Source := Files_Htable.Get (Data.File_To_Source, File_Name);
588 if Source /= No_Source
589 and then Source.Index = Index
595 -- Duplication of file/unit in same project is allowed if order of
596 -- source directories is known.
598 if Add_Src = False then
601 if Project = Source.Project then
602 if Prev_Unit = No_Unit_Index then
603 if Data.Flags.Allow_Duplicate_Basenames then
606 elsif Project.Known_Order_Of_Source_Dirs then
610 Error_Msg_File_1 := File_Name;
612 (Project, "duplicate source file name {",
618 if Project.Known_Order_Of_Source_Dirs then
621 -- We might be seeing the same file through a different path
622 -- (for instance because of symbolic links).
624 elsif Source.Path.Name /= Path.Name then
625 Error_Msg_Name_1 := Unit;
627 (Project, "duplicate unit %%", Location, Data);
632 -- Do not allow the same unit name in different projects,
633 -- except if one is extending the other.
635 -- For a file based language, the same file name replaces
636 -- a file in a project being extended, but it is allowed
637 -- to have the same file name in unrelated projects.
639 elsif Is_Extending (Project, Source.Project) then
640 Source_To_Replace := Source;
642 elsif Prev_Unit /= No_Unit_Index
643 and then not Source.Locally_Removed
645 -- Path is set if this is a source we found on the disk, in which
646 -- case we can provide more explicit error message. Path is unset
647 -- when the source is added from one of the naming exceptions in
650 if Path /= No_Path_Information then
651 Error_Msg_Name_1 := Unit;
654 "unit %% cannot belong to several projects",
657 Error_Msg_Name_1 := Project.Name;
658 Error_Msg_Name_2 := Name_Id (Path.Name);
660 (Project, "\ project %%, %%", Location, Data);
662 Error_Msg_Name_1 := Source.Project.Name;
663 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
665 (Project, "\ project %%, %%", Location, Data);
668 Error_Msg_Name_1 := Unit;
669 Error_Msg_Name_2 := Source.Project.Name;
671 (Project, "unit %% already belongs to project %%",
677 elsif not Source.Locally_Removed
678 and then not Data.Flags.Allow_Duplicate_Basenames
679 and then Lang_Id.Config.Kind = Unit_Based
681 Error_Msg_File_1 := File_Name;
682 Error_Msg_File_2 := File_Name_Type (Source.Project.Name);
685 "{ is already a source of project {", Location, Data);
687 -- Add the file anyway, to avoid further warnings like "language
700 Id := new Source_Data;
702 if Current_Verbosity = High then
703 Write_Str ("Adding source File: ");
704 Write_Str (Get_Name_String (File_Name));
707 Write_Str (" at" & Index'Img);
710 if Lang_Id.Config.Kind = Unit_Based then
711 Write_Str (" Unit: ");
713 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
714 -- (see test extended_projects).
716 if Unit /= No_Name then
717 Write_Str (Get_Name_String (Unit));
720 Write_Str (" Kind: ");
721 Write_Str (Source_Kind'Image (Kind));
727 Id.Project := Project;
728 Id.Language := Lang_Id;
730 Id.Alternate_Languages := Alternate_Languages;
732 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
735 if Unit /= No_Name then
736 UData := Units_Htable.Get (Data.Tree.Units_HT, Unit);
738 if UData = No_Unit_Index then
739 UData := new Unit_Data;
741 Units_Htable.Set (Data.Tree.Units_HT, Unit, UData);
746 -- Note that this updates Unit information as well
748 Override_Kind (Id, Kind);
752 Id.File := File_Name;
753 Id.Display_File := Display_File;
754 Id.Dep_Name := Dependency_Name
755 (File_Name, Lang_Id.Config.Dependency_Kind);
756 Id.Naming_Exception := Naming_Exception;
758 if Is_Compilable (Id) and then Config.Object_Generated then
759 Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
760 Id.Switches := Switches_Name (File_Name);
763 if Path /= No_Path_Information then
765 Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id);
768 -- Add the source to the language list
770 Id.Next_In_Lang := Lang_Id.First_Source;
771 Lang_Id.First_Source := Id;
773 if Source_To_Replace /= No_Source then
774 Remove_Source (Source_To_Replace, Id);
777 Files_Htable.Set (Data.File_To_Source, File_Name, Id);
780 ------------------------------
781 -- Canonical_Case_File_Name --
782 ------------------------------
784 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
786 if Osint.File_Names_Case_Sensitive then
787 return File_Name_Type (Name);
789 Get_Name_String (Name);
790 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
793 end Canonical_Case_File_Name;
800 (Project : Project_Id;
801 Data : in out Tree_Processing_Data)
803 Specs : Array_Element_Id;
804 Bodies : Array_Element_Id;
805 Extending : Boolean := False;
806 Prj_Data : Project_Processing_Data;
809 Initialize (Prj_Data, Project);
811 Check_If_Externally_Built (Project, Data);
813 -- Object, exec and source directories
815 Get_Directories (Project, Data);
817 -- Get the programming languages
819 Check_Programming_Languages (Project, Data);
821 if Project.Qualifier = Dry
822 and then Project.Source_Dirs /= Nil_String
825 Source_Dirs : constant Variable_Value :=
828 Project.Decl.Attributes, Data.Tree);
829 Source_Files : constant Variable_Value :=
832 Project.Decl.Attributes, Data.Tree);
833 Source_List_File : constant Variable_Value :=
835 (Name_Source_List_File,
836 Project.Decl.Attributes, Data.Tree);
837 Languages : constant Variable_Value :=
840 Project.Decl.Attributes, Data.Tree);
843 if Source_Dirs.Values = Nil_String
844 and then Source_Files.Values = Nil_String
845 and then Languages.Values = Nil_String
846 and then Source_List_File.Default
848 Project.Source_Dirs := Nil_String;
853 "at least one of Source_Files, Source_Dirs or Languages "
854 & "must be declared empty for an abstract project",
855 Project.Location, Data);
860 -- Check configuration. This must be done even for gnatmake (even though
861 -- no user configuration file was provided) since the default config we
862 -- generate indicates whether libraries are supported for instance.
864 Check_Configuration (Project, Data);
866 -- Library attributes
868 Check_Library_Attributes (Project, Data);
870 if Current_Verbosity = High then
871 Show_Source_Dirs (Project, Data.Tree);
874 Extending := Project.Extends /= No_Project;
876 Check_Package_Naming (Project, Data, Bodies => Bodies, Specs => Specs);
880 if Project.Source_Dirs /= Nil_String then
881 Look_For_Sources (Prj_Data, Data);
883 if not Project.Externally_Built
884 and then not Extending
887 Language : Language_Ptr;
889 Alt_Lang : Language_List;
890 Continuation : Boolean := False;
891 Iter : Source_Iterator;
894 Language := Project.Languages;
895 while Language /= No_Language_Index loop
897 -- If there are no sources for this language, check if there
898 -- are sources for which this is an alternate language.
900 if Language.First_Source = No_Source
901 and then (Data.Flags.Require_Sources_Other_Lang
902 or else Language.Name = Name_Ada)
904 Iter := For_Each_Source (In_Tree => Data.Tree,
907 Source := Element (Iter);
908 exit Source_Loop when Source = No_Source
909 or else Source.Language = Language;
911 Alt_Lang := Source.Alternate_Languages;
912 while Alt_Lang /= null loop
913 exit Source_Loop when Alt_Lang.Language = Language;
914 Alt_Lang := Alt_Lang.Next;
918 end loop Source_Loop;
920 if Source = No_Source then
924 Get_Name_String (Language.Display_Name),
926 Prj_Data.Source_List_File_Location,
928 Continuation := True;
932 Language := Language.Next;
938 -- If a list of sources is specified in attribute Interfaces, set
939 -- In_Interfaces only for the sources specified in the list.
941 Check_Interfaces (Project, Data);
943 -- If it is a library project file, check if it is a standalone library
945 if Project.Library then
946 Check_Stand_Alone_Library (Project, Data);
949 -- Put the list of Mains, if any, in the project data
951 Get_Mains (Project, Data);
960 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
961 The_Name : String := Name;
963 Need_Letter : Boolean := True;
964 Last_Underscore : Boolean := False;
965 OK : Boolean := The_Name'Length > 0;
968 function Is_Reserved (Name : Name_Id) return Boolean;
969 function Is_Reserved (S : String) return Boolean;
970 -- Check that the given name is not an Ada 95 reserved word. The reason
971 -- for the Ada 95 here is that we do not want to exclude the case of an
972 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
973 -- name would be rejected anyway by the compiler. That means there is no
974 -- requirement that the project file parser reject this.
980 function Is_Reserved (S : String) return Boolean is
983 Add_Str_To_Name_Buffer (S);
984 return Is_Reserved (Name_Find);
991 function Is_Reserved (Name : Name_Id) return Boolean is
993 if Get_Name_Table_Byte (Name) /= 0
994 and then Name /= Name_Project
995 and then Name /= Name_Extends
996 and then Name /= Name_External
997 and then Name not in Ada_2005_Reserved_Words
1001 if Current_Verbosity = High then
1002 Write_Str (The_Name);
1003 Write_Line (" is an Ada reserved word.");
1013 -- Start of processing for Check_Ada_Name
1016 To_Lower (The_Name);
1018 Name_Len := The_Name'Length;
1019 Name_Buffer (1 .. Name_Len) := The_Name;
1021 -- Special cases of children of packages A, G, I and S on VMS
1023 if OpenVMS_On_Target
1024 and then Name_Len > 3
1025 and then Name_Buffer (2 .. 3) = "__"
1027 ((Name_Buffer (1) = 'a') or else
1028 (Name_Buffer (1) = 'g') or else
1029 (Name_Buffer (1) = 'i') or else
1030 (Name_Buffer (1) = 's'))
1032 Name_Buffer (2) := '.';
1033 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1034 Name_Len := Name_Len - 1;
1037 Real_Name := Name_Find;
1039 if Is_Reserved (Real_Name) then
1043 First := The_Name'First;
1045 for Index in The_Name'Range loop
1048 -- We need a letter (at the beginning, and following a dot),
1049 -- but we don't have one.
1051 if Is_Letter (The_Name (Index)) then
1052 Need_Letter := False;
1057 if Current_Verbosity = High then
1058 Write_Int (Types.Int (Index));
1060 Write_Char (The_Name (Index));
1061 Write_Line ("' is not a letter.");
1067 elsif Last_Underscore
1068 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1070 -- Two underscores are illegal, and a dot cannot follow
1075 if Current_Verbosity = High then
1076 Write_Int (Types.Int (Index));
1078 Write_Char (The_Name (Index));
1079 Write_Line ("' is illegal here.");
1084 elsif The_Name (Index) = '.' then
1086 -- First, check if the name before the dot is not a reserved word
1088 if Is_Reserved (The_Name (First .. Index - 1)) then
1094 -- We need a letter after a dot
1096 Need_Letter := True;
1098 elsif The_Name (Index) = '_' then
1099 Last_Underscore := True;
1102 -- We need an letter or a digit
1104 Last_Underscore := False;
1106 if not Is_Alphanumeric (The_Name (Index)) then
1109 if Current_Verbosity = High then
1110 Write_Int (Types.Int (Index));
1112 Write_Char (The_Name (Index));
1113 Write_Line ("' is not alphanumeric.");
1121 -- Cannot end with an underscore or a dot
1123 OK := OK and then not Need_Letter and then not Last_Underscore;
1126 if First /= Name'First and then
1127 Is_Reserved (The_Name (First .. The_Name'Last))
1135 -- Signal a problem with No_Name
1141 -------------------------
1142 -- Check_Configuration --
1143 -------------------------
1145 procedure Check_Configuration
1146 (Project : Project_Id;
1147 Data : in out Tree_Processing_Data)
1149 Dot_Replacement : File_Name_Type := No_File;
1150 Casing : Casing_Type := All_Lower_Case;
1151 Separate_Suffix : File_Name_Type := No_File;
1153 Lang_Index : Language_Ptr := No_Language_Index;
1154 -- The index of the language data being checked
1156 Prev_Index : Language_Ptr := No_Language_Index;
1157 -- The index of the previous language
1159 procedure Process_Project_Level_Simple_Attributes;
1160 -- Process the simple attributes at the project level
1162 procedure Process_Project_Level_Array_Attributes;
1163 -- Process the associate array attributes at the project level
1165 procedure Process_Packages;
1166 -- Read the packages of the project
1168 ----------------------
1169 -- Process_Packages --
1170 ----------------------
1172 procedure Process_Packages is
1173 Packages : Package_Id;
1174 Element : Package_Element;
1176 procedure Process_Binder (Arrays : Array_Id);
1177 -- Process the associate array attributes of package Binder
1179 procedure Process_Builder (Attributes : Variable_Id);
1180 -- Process the simple attributes of package Builder
1182 procedure Process_Compiler (Arrays : Array_Id);
1183 -- Process the associate array attributes of package Compiler
1185 procedure Process_Naming (Attributes : Variable_Id);
1186 -- Process the simple attributes of package Naming
1188 procedure Process_Naming (Arrays : Array_Id);
1189 -- Process the associate array attributes of package Naming
1191 procedure Process_Linker (Attributes : Variable_Id);
1192 -- Process the simple attributes of package Linker of a
1193 -- configuration project.
1195 --------------------
1196 -- Process_Binder --
1197 --------------------
1199 procedure Process_Binder (Arrays : Array_Id) is
1200 Current_Array_Id : Array_Id;
1201 Current_Array : Array_Data;
1202 Element_Id : Array_Element_Id;
1203 Element : Array_Element;
1206 -- Process the associative array attribute of package Binder
1208 Current_Array_Id := Arrays;
1209 while Current_Array_Id /= No_Array loop
1210 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1212 Element_Id := Current_Array.Value;
1213 while Element_Id /= No_Array_Element loop
1214 Element := Data.Tree.Array_Elements.Table (Element_Id);
1216 if Element.Index /= All_Other_Names then
1218 -- Get the name of the language
1221 Get_Language_From_Name
1222 (Project, Get_Name_String (Element.Index));
1224 if Lang_Index /= No_Language_Index then
1225 case Current_Array.Name is
1228 -- Attribute Driver (<language>)
1230 Lang_Index.Config.Binder_Driver :=
1231 File_Name_Type (Element.Value.Value);
1233 when Name_Required_Switches =>
1236 Lang_Index.Config.Binder_Required_Switches,
1237 From_List => Element.Value.Values,
1238 In_Tree => Data.Tree);
1242 -- Attribute Prefix (<language>)
1244 Lang_Index.Config.Binder_Prefix :=
1245 Element.Value.Value;
1247 when Name_Objects_Path =>
1249 -- Attribute Objects_Path (<language>)
1251 Lang_Index.Config.Objects_Path :=
1252 Element.Value.Value;
1254 when Name_Objects_Path_File =>
1256 -- Attribute Objects_Path (<language>)
1258 Lang_Index.Config.Objects_Path_File :=
1259 Element.Value.Value;
1267 Element_Id := Element.Next;
1270 Current_Array_Id := Current_Array.Next;
1274 ---------------------
1275 -- Process_Builder --
1276 ---------------------
1278 procedure Process_Builder (Attributes : Variable_Id) is
1279 Attribute_Id : Variable_Id;
1280 Attribute : Variable;
1283 -- Process non associated array attribute from package Builder
1285 Attribute_Id := Attributes;
1286 while Attribute_Id /= No_Variable loop
1288 Data.Tree.Variable_Elements.Table (Attribute_Id);
1290 if not Attribute.Value.Default then
1291 if Attribute.Name = Name_Executable_Suffix then
1293 -- Attribute Executable_Suffix: the suffix of the
1296 Project.Config.Executable_Suffix :=
1297 Attribute.Value.Value;
1301 Attribute_Id := Attribute.Next;
1303 end Process_Builder;
1305 ----------------------
1306 -- Process_Compiler --
1307 ----------------------
1309 procedure Process_Compiler (Arrays : Array_Id) is
1310 Current_Array_Id : Array_Id;
1311 Current_Array : Array_Data;
1312 Element_Id : Array_Element_Id;
1313 Element : Array_Element;
1314 List : String_List_Id;
1317 -- Process the associative array attribute of package Compiler
1319 Current_Array_Id := Arrays;
1320 while Current_Array_Id /= No_Array loop
1321 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1323 Element_Id := Current_Array.Value;
1324 while Element_Id /= No_Array_Element loop
1325 Element := Data.Tree.Array_Elements.Table (Element_Id);
1327 if Element.Index /= All_Other_Names then
1329 -- Get the name of the language
1331 Lang_Index := Get_Language_From_Name
1332 (Project, Get_Name_String (Element.Index));
1334 if Lang_Index /= No_Language_Index then
1335 case Current_Array.Name is
1336 when Name_Dependency_Switches =>
1338 -- Attribute Dependency_Switches (<language>)
1340 if Lang_Index.Config.Dependency_Kind = None then
1341 Lang_Index.Config.Dependency_Kind := Makefile;
1344 List := Element.Value.Values;
1346 if List /= Nil_String then
1348 Lang_Index.Config.Dependency_Option,
1350 In_Tree => Data.Tree);
1353 when Name_Dependency_Driver =>
1355 -- Attribute Dependency_Driver (<language>)
1357 if Lang_Index.Config.Dependency_Kind = None then
1358 Lang_Index.Config.Dependency_Kind := Makefile;
1361 List := Element.Value.Values;
1363 if List /= Nil_String then
1365 Lang_Index.Config.Compute_Dependency,
1367 In_Tree => Data.Tree);
1370 when Name_Include_Switches =>
1372 -- Attribute Include_Switches (<language>)
1374 List := Element.Value.Values;
1376 if List = Nil_String then
1378 (Project, "include option cannot be null",
1379 Element.Value.Location, Data);
1382 Put (Into_List => Lang_Index.Config.Include_Option,
1384 In_Tree => Data.Tree);
1386 when Name_Include_Path =>
1388 -- Attribute Include_Path (<language>)
1390 Lang_Index.Config.Include_Path :=
1391 Element.Value.Value;
1393 when Name_Include_Path_File =>
1395 -- Attribute Include_Path_File (<language>)
1397 Lang_Index.Config.Include_Path_File :=
1398 Element.Value.Value;
1402 -- Attribute Driver (<language>)
1404 Lang_Index.Config.Compiler_Driver :=
1405 File_Name_Type (Element.Value.Value);
1407 when Name_Required_Switches |
1408 Name_Leading_Required_Switches =>
1411 Compiler_Leading_Required_Switches,
1412 From_List => Element.Value.Values,
1413 In_Tree => Data.Tree);
1415 when Name_Trailing_Required_Switches =>
1418 Compiler_Trailing_Required_Switches,
1419 From_List => Element.Value.Values,
1420 In_Tree => Data.Tree);
1422 when Name_Path_Syntax =>
1424 Lang_Index.Config.Path_Syntax :=
1425 Path_Syntax_Kind'Value
1426 (Get_Name_String (Element.Value.Value));
1429 when Constraint_Error =>
1431 (Project, "invalid value for Path_Syntax",
1432 Element.Value.Location, Data);
1435 when Name_Object_File_Suffix =>
1436 if Get_Name_String (Element.Value.Value) = "" then
1438 (Project, "object file suffix cannot be empty",
1439 Element.Value.Location, Data);
1442 Lang_Index.Config.Object_File_Suffix :=
1443 Element.Value.Value;
1446 when Name_Object_File_Switches =>
1448 Lang_Index.Config.Object_File_Switches,
1449 From_List => Element.Value.Values,
1450 In_Tree => Data.Tree);
1452 when Name_Pic_Option =>
1454 -- Attribute Compiler_Pic_Option (<language>)
1456 List := Element.Value.Values;
1458 if List = Nil_String then
1460 (Project, "compiler PIC option cannot be null",
1461 Element.Value.Location, Data);
1465 Lang_Index.Config.Compilation_PIC_Option,
1467 In_Tree => Data.Tree);
1469 when Name_Mapping_File_Switches =>
1471 -- Attribute Mapping_File_Switches (<language>)
1473 List := Element.Value.Values;
1475 if List = Nil_String then
1478 "mapping file switches cannot be null",
1479 Element.Value.Location, Data);
1483 Lang_Index.Config.Mapping_File_Switches,
1485 In_Tree => Data.Tree);
1487 when Name_Mapping_Spec_Suffix =>
1489 -- Attribute Mapping_Spec_Suffix (<language>)
1491 Lang_Index.Config.Mapping_Spec_Suffix :=
1492 File_Name_Type (Element.Value.Value);
1494 when Name_Mapping_Body_Suffix =>
1496 -- Attribute Mapping_Body_Suffix (<language>)
1498 Lang_Index.Config.Mapping_Body_Suffix :=
1499 File_Name_Type (Element.Value.Value);
1501 when Name_Config_File_Switches =>
1503 -- Attribute Config_File_Switches (<language>)
1505 List := Element.Value.Values;
1507 if List = Nil_String then
1510 "config file switches cannot be null",
1511 Element.Value.Location, Data);
1515 Lang_Index.Config.Config_File_Switches,
1517 In_Tree => Data.Tree);
1519 when Name_Objects_Path =>
1521 -- Attribute Objects_Path (<language>)
1523 Lang_Index.Config.Objects_Path :=
1524 Element.Value.Value;
1526 when Name_Objects_Path_File =>
1528 -- Attribute Objects_Path_File (<language>)
1530 Lang_Index.Config.Objects_Path_File :=
1531 Element.Value.Value;
1533 when Name_Config_Body_File_Name =>
1535 -- Attribute Config_Body_File_Name (<language>)
1537 Lang_Index.Config.Config_Body :=
1538 Element.Value.Value;
1540 when Name_Config_Body_File_Name_Pattern =>
1542 -- Attribute Config_Body_File_Name_Pattern
1545 Lang_Index.Config.Config_Body_Pattern :=
1546 Element.Value.Value;
1548 when Name_Config_Spec_File_Name =>
1550 -- Attribute Config_Spec_File_Name (<language>)
1552 Lang_Index.Config.Config_Spec :=
1553 Element.Value.Value;
1555 when Name_Config_Spec_File_Name_Pattern =>
1557 -- Attribute Config_Spec_File_Name_Pattern
1560 Lang_Index.Config.Config_Spec_Pattern :=
1561 Element.Value.Value;
1563 when Name_Config_File_Unique =>
1565 -- Attribute Config_File_Unique (<language>)
1568 Lang_Index.Config.Config_File_Unique :=
1570 (Get_Name_String (Element.Value.Value));
1572 when Constraint_Error =>
1575 "illegal value for Config_File_Unique",
1576 Element.Value.Location, Data);
1585 Element_Id := Element.Next;
1588 Current_Array_Id := Current_Array.Next;
1590 end Process_Compiler;
1592 --------------------
1593 -- Process_Naming --
1594 --------------------
1596 procedure Process_Naming (Attributes : Variable_Id) is
1597 Attribute_Id : Variable_Id;
1598 Attribute : Variable;
1601 -- Process non associated array attribute from package Naming
1603 Attribute_Id := Attributes;
1604 while Attribute_Id /= No_Variable loop
1605 Attribute := Data.Tree.Variable_Elements.Table (Attribute_Id);
1607 if not Attribute.Value.Default then
1608 if Attribute.Name = Name_Separate_Suffix then
1610 -- Attribute Separate_Suffix
1612 Get_Name_String (Attribute.Value.Value);
1613 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1614 Separate_Suffix := Name_Find;
1616 elsif Attribute.Name = Name_Casing then
1622 Value (Get_Name_String (Attribute.Value.Value));
1625 when Constraint_Error =>
1628 "invalid value for Casing",
1629 Attribute.Value.Location, Data);
1632 elsif Attribute.Name = Name_Dot_Replacement then
1634 -- Attribute Dot_Replacement
1636 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1641 Attribute_Id := Attribute.Next;
1645 procedure Process_Naming (Arrays : Array_Id) is
1646 Current_Array_Id : Array_Id;
1647 Current_Array : Array_Data;
1648 Element_Id : Array_Element_Id;
1649 Element : Array_Element;
1652 -- Process the associative array attribute of package Naming
1654 Current_Array_Id := Arrays;
1655 while Current_Array_Id /= No_Array loop
1656 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1658 Element_Id := Current_Array.Value;
1659 while Element_Id /= No_Array_Element loop
1660 Element := Data.Tree.Array_Elements.Table (Element_Id);
1662 -- Get the name of the language
1664 Lang_Index := Get_Language_From_Name
1665 (Project, Get_Name_String (Element.Index));
1667 if Lang_Index /= No_Language_Index then
1668 case Current_Array.Name is
1669 when Name_Spec_Suffix | Name_Specification_Suffix =>
1671 -- Attribute Spec_Suffix (<language>)
1673 Get_Name_String (Element.Value.Value);
1674 Canonical_Case_File_Name
1675 (Name_Buffer (1 .. Name_Len));
1676 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1679 when Name_Implementation_Suffix | Name_Body_Suffix =>
1681 Get_Name_String (Element.Value.Value);
1682 Canonical_Case_File_Name
1683 (Name_Buffer (1 .. Name_Len));
1685 -- Attribute Body_Suffix (<language>)
1687 Lang_Index.Config.Naming_Data.Body_Suffix :=
1689 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1690 Lang_Index.Config.Naming_Data.Body_Suffix;
1697 Element_Id := Element.Next;
1700 Current_Array_Id := Current_Array.Next;
1704 --------------------
1705 -- Process_Linker --
1706 --------------------
1708 procedure Process_Linker (Attributes : Variable_Id) is
1709 Attribute_Id : Variable_Id;
1710 Attribute : Variable;
1713 -- Process non associated array attribute from package Linker
1715 Attribute_Id := Attributes;
1716 while Attribute_Id /= No_Variable loop
1718 Data.Tree.Variable_Elements.Table (Attribute_Id);
1720 if not Attribute.Value.Default then
1721 if Attribute.Name = Name_Driver then
1723 -- Attribute Linker'Driver: the default linker to use
1725 Project.Config.Linker :=
1726 Path_Name_Type (Attribute.Value.Value);
1728 -- Linker'Driver is also used to link shared libraries
1729 -- if the obsolescent attribute Library_GCC has not been
1732 if Project.Config.Shared_Lib_Driver = No_File then
1733 Project.Config.Shared_Lib_Driver :=
1734 File_Name_Type (Attribute.Value.Value);
1737 elsif Attribute.Name = Name_Required_Switches then
1739 -- Attribute Required_Switches: the minimum
1740 -- options to use when invoking the linker
1742 Put (Into_List => Project.Config.Minimum_Linker_Options,
1743 From_List => Attribute.Value.Values,
1744 In_Tree => Data.Tree);
1746 elsif Attribute.Name = Name_Map_File_Option then
1747 Project.Config.Map_File_Option := Attribute.Value.Value;
1749 elsif Attribute.Name = Name_Max_Command_Line_Length then
1751 Project.Config.Max_Command_Line_Length :=
1752 Natural'Value (Get_Name_String
1753 (Attribute.Value.Value));
1756 when Constraint_Error =>
1759 "value must be positive or equal to 0",
1760 Attribute.Value.Location, Data);
1763 elsif Attribute.Name = Name_Response_File_Format then
1768 Get_Name_String (Attribute.Value.Value);
1769 To_Lower (Name_Buffer (1 .. Name_Len));
1772 if Name = Name_None then
1773 Project.Config.Resp_File_Format := None;
1775 elsif Name = Name_Gnu then
1776 Project.Config.Resp_File_Format := GNU;
1778 elsif Name = Name_Object_List then
1779 Project.Config.Resp_File_Format := Object_List;
1781 elsif Name = Name_Option_List then
1782 Project.Config.Resp_File_Format := Option_List;
1787 "illegal response file format",
1788 Attribute.Value.Location, Data);
1792 elsif Attribute.Name = Name_Response_File_Switches then
1793 Put (Into_List => Project.Config.Resp_File_Options,
1794 From_List => Attribute.Value.Values,
1795 In_Tree => Data.Tree);
1799 Attribute_Id := Attribute.Next;
1803 -- Start of processing for Process_Packages
1806 Packages := Project.Decl.Packages;
1807 while Packages /= No_Package loop
1808 Element := Data.Tree.Packages.Table (Packages);
1810 case Element.Name is
1813 -- Process attributes of package Binder
1815 Process_Binder (Element.Decl.Arrays);
1817 when Name_Builder =>
1819 -- Process attributes of package Builder
1821 Process_Builder (Element.Decl.Attributes);
1823 when Name_Compiler =>
1825 -- Process attributes of package Compiler
1827 Process_Compiler (Element.Decl.Arrays);
1831 -- Process attributes of package Linker
1833 Process_Linker (Element.Decl.Attributes);
1837 -- Process attributes of package Naming
1839 Process_Naming (Element.Decl.Attributes);
1840 Process_Naming (Element.Decl.Arrays);
1846 Packages := Element.Next;
1848 end Process_Packages;
1850 ---------------------------------------------
1851 -- Process_Project_Level_Simple_Attributes --
1852 ---------------------------------------------
1854 procedure Process_Project_Level_Simple_Attributes is
1855 Attribute_Id : Variable_Id;
1856 Attribute : Variable;
1857 List : String_List_Id;
1860 -- Process non associated array attribute at project level
1862 Attribute_Id := Project.Decl.Attributes;
1863 while Attribute_Id /= No_Variable loop
1865 Data.Tree.Variable_Elements.Table (Attribute_Id);
1867 if not Attribute.Value.Default then
1868 if Attribute.Name = Name_Target then
1870 -- Attribute Target: the target specified
1872 Project.Config.Target := Attribute.Value.Value;
1874 elsif Attribute.Name = Name_Library_Builder then
1876 -- Attribute Library_Builder: the application to invoke
1877 -- to build libraries.
1879 Project.Config.Library_Builder :=
1880 Path_Name_Type (Attribute.Value.Value);
1882 elsif Attribute.Name = Name_Archive_Builder then
1884 -- Attribute Archive_Builder: the archive builder
1885 -- (usually "ar") and its minimum options (usually "cr").
1887 List := Attribute.Value.Values;
1889 if List = Nil_String then
1892 "archive builder cannot be null",
1893 Attribute.Value.Location, Data);
1896 Put (Into_List => Project.Config.Archive_Builder,
1898 In_Tree => Data.Tree);
1900 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1902 -- Attribute Archive_Builder: the archive builder
1903 -- (usually "ar") and its minimum options (usually "cr").
1905 List := Attribute.Value.Values;
1907 if List /= Nil_String then
1910 Project.Config.Archive_Builder_Append_Option,
1912 In_Tree => Data.Tree);
1915 elsif Attribute.Name = Name_Archive_Indexer then
1917 -- Attribute Archive_Indexer: the optional archive
1918 -- indexer (usually "ranlib") with its minimum options
1921 List := Attribute.Value.Values;
1923 if List = Nil_String then
1926 "archive indexer cannot be null",
1927 Attribute.Value.Location, Data);
1930 Put (Into_List => Project.Config.Archive_Indexer,
1932 In_Tree => Data.Tree);
1934 elsif Attribute.Name = Name_Library_Partial_Linker then
1936 -- Attribute Library_Partial_Linker: the optional linker
1937 -- driver with its minimum options, to partially link
1940 List := Attribute.Value.Values;
1942 if List = Nil_String then
1945 "partial linker cannot be null",
1946 Attribute.Value.Location, Data);
1949 Put (Into_List => Project.Config.Lib_Partial_Linker,
1951 In_Tree => Data.Tree);
1953 elsif Attribute.Name = Name_Library_GCC then
1954 Project.Config.Shared_Lib_Driver :=
1955 File_Name_Type (Attribute.Value.Value);
1958 "?Library_'G'C'C is an obsolescent attribute, " &
1959 "use Linker''Driver instead",
1960 Attribute.Value.Location, Data);
1962 elsif Attribute.Name = Name_Archive_Suffix then
1963 Project.Config.Archive_Suffix :=
1964 File_Name_Type (Attribute.Value.Value);
1966 elsif Attribute.Name = Name_Linker_Executable_Option then
1968 -- Attribute Linker_Executable_Option: optional options
1969 -- to specify an executable name. Defaults to "-o".
1971 List := Attribute.Value.Values;
1973 if List = Nil_String then
1976 "linker executable option cannot be null",
1977 Attribute.Value.Location, Data);
1980 Put (Into_List => Project.Config.Linker_Executable_Option,
1982 In_Tree => Data.Tree);
1984 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
1986 -- Attribute Linker_Lib_Dir_Option: optional options
1987 -- to specify a library search directory. Defaults to
1990 Get_Name_String (Attribute.Value.Value);
1992 if Name_Len = 0 then
1995 "linker library directory option cannot be empty",
1996 Attribute.Value.Location, Data);
1999 Project.Config.Linker_Lib_Dir_Option :=
2000 Attribute.Value.Value;
2002 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2004 -- Attribute Linker_Lib_Name_Option: optional options
2005 -- to specify the name of a library to be linked in.
2006 -- Defaults to "-l".
2008 Get_Name_String (Attribute.Value.Value);
2010 if Name_Len = 0 then
2013 "linker library name option cannot be empty",
2014 Attribute.Value.Location, Data);
2017 Project.Config.Linker_Lib_Name_Option :=
2018 Attribute.Value.Value;
2020 elsif Attribute.Name = Name_Run_Path_Option then
2022 -- Attribute Run_Path_Option: optional options to
2023 -- specify a path for libraries.
2025 List := Attribute.Value.Values;
2027 if List /= Nil_String then
2028 Put (Into_List => Project.Config.Run_Path_Option,
2030 In_Tree => Data.Tree);
2033 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2035 pragma Unsuppress (All_Checks);
2037 Project.Config.Separate_Run_Path_Options :=
2038 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2040 when Constraint_Error =>
2043 "invalid value """ &
2044 Get_Name_String (Attribute.Value.Value) &
2045 """ for Separate_Run_Path_Options",
2046 Attribute.Value.Location, Data);
2049 elsif Attribute.Name = Name_Library_Support then
2051 pragma Unsuppress (All_Checks);
2053 Project.Config.Lib_Support :=
2054 Library_Support'Value (Get_Name_String
2055 (Attribute.Value.Value));
2057 when Constraint_Error =>
2060 "invalid value """ &
2061 Get_Name_String (Attribute.Value.Value) &
2062 """ for Library_Support",
2063 Attribute.Value.Location, Data);
2066 elsif Attribute.Name = Name_Shared_Library_Prefix then
2067 Project.Config.Shared_Lib_Prefix :=
2068 File_Name_Type (Attribute.Value.Value);
2070 elsif Attribute.Name = Name_Shared_Library_Suffix then
2071 Project.Config.Shared_Lib_Suffix :=
2072 File_Name_Type (Attribute.Value.Value);
2074 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2076 pragma Unsuppress (All_Checks);
2078 Project.Config.Symbolic_Link_Supported :=
2079 Boolean'Value (Get_Name_String
2080 (Attribute.Value.Value));
2082 when Constraint_Error =>
2086 & Get_Name_String (Attribute.Value.Value)
2087 & """ for Symbolic_Link_Supported",
2088 Attribute.Value.Location, Data);
2092 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2095 pragma Unsuppress (All_Checks);
2097 Project.Config.Lib_Maj_Min_Id_Supported :=
2098 Boolean'Value (Get_Name_String
2099 (Attribute.Value.Value));
2101 when Constraint_Error =>
2104 "invalid value """ &
2105 Get_Name_String (Attribute.Value.Value) &
2106 """ for Library_Major_Minor_Id_Supported",
2107 Attribute.Value.Location, Data);
2110 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2112 pragma Unsuppress (All_Checks);
2114 Project.Config.Auto_Init_Supported :=
2115 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2117 when Constraint_Error =>
2121 & Get_Name_String (Attribute.Value.Value)
2122 & """ for Library_Auto_Init_Supported",
2123 Attribute.Value.Location, Data);
2126 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2127 List := Attribute.Value.Values;
2129 if List /= Nil_String then
2130 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2132 In_Tree => Data.Tree);
2135 elsif Attribute.Name = Name_Library_Version_Switches then
2136 List := Attribute.Value.Values;
2138 if List /= Nil_String then
2139 Put (Into_List => Project.Config.Lib_Version_Options,
2141 In_Tree => Data.Tree);
2146 Attribute_Id := Attribute.Next;
2148 end Process_Project_Level_Simple_Attributes;
2150 --------------------------------------------
2151 -- Process_Project_Level_Array_Attributes --
2152 --------------------------------------------
2154 procedure Process_Project_Level_Array_Attributes is
2155 Current_Array_Id : Array_Id;
2156 Current_Array : Array_Data;
2157 Element_Id : Array_Element_Id;
2158 Element : Array_Element;
2159 List : String_List_Id;
2162 -- Process the associative array attributes at project level
2164 Current_Array_Id := Project.Decl.Arrays;
2165 while Current_Array_Id /= No_Array loop
2166 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
2168 Element_Id := Current_Array.Value;
2169 while Element_Id /= No_Array_Element loop
2170 Element := Data.Tree.Array_Elements.Table (Element_Id);
2172 -- Get the name of the language
2175 Get_Language_From_Name
2176 (Project, Get_Name_String (Element.Index));
2178 if Lang_Index /= No_Language_Index then
2179 case Current_Array.Name is
2180 when Name_Inherit_Source_Path =>
2181 List := Element.Value.Values;
2183 if List /= Nil_String then
2186 Lang_Index.Config.Include_Compatible_Languages,
2188 In_Tree => Data.Tree,
2189 Lower_Case => True);
2192 when Name_Toolchain_Description =>
2194 -- Attribute Toolchain_Description (<language>)
2196 Lang_Index.Config.Toolchain_Description :=
2197 Element.Value.Value;
2199 when Name_Toolchain_Version =>
2201 -- Attribute Toolchain_Version (<language>)
2203 Lang_Index.Config.Toolchain_Version :=
2204 Element.Value.Value;
2206 when Name_Runtime_Library_Dir =>
2208 -- Attribute Runtime_Library_Dir (<language>)
2210 Lang_Index.Config.Runtime_Library_Dir :=
2211 Element.Value.Value;
2213 when Name_Runtime_Source_Dir =>
2215 -- Attribute Runtime_Library_Dir (<language>)
2217 Lang_Index.Config.Runtime_Source_Dir :=
2218 Element.Value.Value;
2220 when Name_Object_Generated =>
2222 pragma Unsuppress (All_Checks);
2228 (Get_Name_String (Element.Value.Value));
2230 Lang_Index.Config.Object_Generated := Value;
2232 -- If no object is generated, no object may be
2236 Lang_Index.Config.Objects_Linked := False;
2240 when Constraint_Error =>
2244 & Get_Name_String (Element.Value.Value)
2245 & """ for Object_Generated",
2246 Element.Value.Location, Data);
2249 when Name_Objects_Linked =>
2251 pragma Unsuppress (All_Checks);
2257 (Get_Name_String (Element.Value.Value));
2259 -- No change if Object_Generated is False, as this
2260 -- forces Objects_Linked to be False too.
2262 if Lang_Index.Config.Object_Generated then
2263 Lang_Index.Config.Objects_Linked := Value;
2267 when Constraint_Error =>
2271 & Get_Name_String (Element.Value.Value)
2272 & """ for Objects_Linked",
2273 Element.Value.Location, Data);
2280 Element_Id := Element.Next;
2283 Current_Array_Id := Current_Array.Next;
2285 end Process_Project_Level_Array_Attributes;
2287 -- Start of processing for Check_Configuration
2290 Process_Project_Level_Simple_Attributes;
2291 Process_Project_Level_Array_Attributes;
2294 -- For unit based languages, set Casing, Dot_Replacement and
2295 -- Separate_Suffix in Naming_Data.
2297 Lang_Index := Project.Languages;
2298 while Lang_Index /= No_Language_Index loop
2299 if Lang_Index.Name = Name_Ada then
2300 Lang_Index.Config.Naming_Data.Casing := Casing;
2301 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2303 if Separate_Suffix /= No_File then
2304 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2311 Lang_Index := Lang_Index.Next;
2314 -- Give empty names to various prefixes/suffixes, if they have not
2315 -- been specified in the configuration.
2317 if Project.Config.Archive_Suffix = No_File then
2318 Project.Config.Archive_Suffix := Empty_File;
2321 if Project.Config.Shared_Lib_Prefix = No_File then
2322 Project.Config.Shared_Lib_Prefix := Empty_File;
2325 if Project.Config.Shared_Lib_Suffix = No_File then
2326 Project.Config.Shared_Lib_Suffix := Empty_File;
2329 Lang_Index := Project.Languages;
2330 while Lang_Index /= No_Language_Index loop
2332 -- For all languages, Compiler_Driver needs to be specified. This is
2333 -- only needed if we do intend to compile (not in GPS for instance).
2335 if Data.Flags.Compiler_Driver_Mandatory
2336 and then Lang_Index.Config.Compiler_Driver = No_File
2338 Error_Msg_Name_1 := Lang_Index.Display_Name;
2341 "?no compiler specified for language %%" &
2342 ", ignoring all its sources",
2345 if Lang_Index = Project.Languages then
2346 Project.Languages := Lang_Index.Next;
2348 Prev_Index.Next := Lang_Index.Next;
2351 elsif Lang_Index.Name = Name_Ada then
2352 Prev_Index := Lang_Index;
2354 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2355 -- Body_Suffix need to be specified.
2357 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2360 "Dot_Replacement not specified for Ada",
2364 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2367 "Spec_Suffix not specified for Ada",
2371 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2374 "Body_Suffix not specified for Ada",
2379 Prev_Index := Lang_Index;
2381 -- For file based languages, either Spec_Suffix or Body_Suffix
2382 -- need to be specified.
2384 if Data.Flags.Require_Sources_Other_Lang
2385 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2386 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2388 Error_Msg_Name_1 := Lang_Index.Display_Name;
2391 "no suffixes specified for %%",
2396 Lang_Index := Lang_Index.Next;
2398 end Check_Configuration;
2400 -------------------------------
2401 -- Check_If_Externally_Built --
2402 -------------------------------
2404 procedure Check_If_Externally_Built
2405 (Project : Project_Id;
2406 Data : in out Tree_Processing_Data)
2408 Externally_Built : constant Variable_Value :=
2410 (Name_Externally_Built,
2411 Project.Decl.Attributes, Data.Tree);
2414 if not Externally_Built.Default then
2415 Get_Name_String (Externally_Built.Value);
2416 To_Lower (Name_Buffer (1 .. Name_Len));
2418 if Name_Buffer (1 .. Name_Len) = "true" then
2419 Project.Externally_Built := True;
2421 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2423 "Externally_Built may only be true or false",
2424 Externally_Built.Location, Data);
2428 -- A virtual project extending an externally built project is itself
2429 -- externally built.
2431 if Project.Virtual and then Project.Extends /= No_Project then
2432 Project.Externally_Built := Project.Extends.Externally_Built;
2435 if Current_Verbosity = High then
2436 Write_Str ("Project is ");
2438 if not Project.Externally_Built then
2442 Write_Line ("externally built.");
2444 end Check_If_Externally_Built;
2446 ----------------------
2447 -- Check_Interfaces --
2448 ----------------------
2450 procedure Check_Interfaces
2451 (Project : Project_Id;
2452 Data : in out Tree_Processing_Data)
2454 Interfaces : constant Prj.Variable_Value :=
2456 (Snames.Name_Interfaces,
2457 Project.Decl.Attributes,
2460 List : String_List_Id;
2461 Element : String_Element;
2462 Name : File_Name_Type;
2463 Iter : Source_Iterator;
2465 Project_2 : Project_Id;
2469 if not Interfaces.Default then
2471 -- Set In_Interfaces to False for all sources. It will be set to True
2472 -- later for the sources in the Interfaces list.
2474 Project_2 := Project;
2475 while Project_2 /= No_Project loop
2476 Iter := For_Each_Source (Data.Tree, Project_2);
2478 Source := Prj.Element (Iter);
2479 exit when Source = No_Source;
2480 Source.In_Interfaces := False;
2484 Project_2 := Project_2.Extends;
2487 List := Interfaces.Values;
2488 while List /= Nil_String loop
2489 Element := Data.Tree.String_Elements.Table (List);
2490 Name := Canonical_Case_File_Name (Element.Value);
2492 Project_2 := Project;
2494 while Project_2 /= No_Project loop
2495 Iter := For_Each_Source (Data.Tree, Project_2);
2498 Source := Prj.Element (Iter);
2499 exit when Source = No_Source;
2501 if Source.File = Name then
2502 if not Source.Locally_Removed then
2503 Source.In_Interfaces := True;
2504 Source.Declared_In_Interfaces := True;
2506 Other := Other_Part (Source);
2508 if Other /= No_Source then
2509 Other.In_Interfaces := True;
2510 Other.Declared_In_Interfaces := True;
2513 if Current_Verbosity = High then
2514 Write_Str (" interface: ");
2515 Write_Line (Get_Name_String (Source.Path.Name));
2525 Project_2 := Project_2.Extends;
2528 if Source = No_Source then
2529 Error_Msg_File_1 := File_Name_Type (Element.Value);
2530 Error_Msg_Name_1 := Project.Name;
2534 "{ cannot be an interface of project %% "
2535 & "as it is not one of its sources",
2536 Element.Location, Data);
2539 List := Element.Next;
2542 Project.Interfaces_Defined := True;
2544 elsif Project.Extends /= No_Project then
2545 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2547 if Project.Interfaces_Defined then
2548 Iter := For_Each_Source (Data.Tree, Project);
2550 Source := Prj.Element (Iter);
2551 exit when Source = No_Source;
2553 if not Source.Declared_In_Interfaces then
2554 Source.In_Interfaces := False;
2561 end Check_Interfaces;
2563 --------------------------
2564 -- Check_Package_Naming --
2565 --------------------------
2567 procedure Check_Package_Naming
2568 (Project : Project_Id;
2569 Data : in out Tree_Processing_Data;
2570 Bodies : out Array_Element_Id;
2571 Specs : out Array_Element_Id)
2573 Naming_Id : constant Package_Id :=
2575 (Name_Naming, Project.Decl.Packages, Data.Tree);
2576 Naming : Package_Element;
2578 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2580 procedure Check_Naming;
2581 -- Check the validity of the Naming package (suffixes valid, ...)
2583 procedure Check_Common
2584 (Dot_Replacement : in out File_Name_Type;
2585 Casing : in out Casing_Type;
2586 Casing_Defined : out Boolean;
2587 Separate_Suffix : in out File_Name_Type;
2588 Sep_Suffix_Loc : out Source_Ptr);
2589 -- Check attributes common
2591 procedure Process_Exceptions_File_Based
2592 (Lang_Id : Language_Ptr;
2593 Kind : Source_Kind);
2594 procedure Process_Exceptions_Unit_Based
2595 (Lang_Id : Language_Ptr;
2596 Kind : Source_Kind);
2597 -- Process the naming exceptions for the two types of languages
2599 procedure Initialize_Naming_Data;
2600 -- Initialize internal naming data for the various languages
2606 procedure Check_Common
2607 (Dot_Replacement : in out File_Name_Type;
2608 Casing : in out Casing_Type;
2609 Casing_Defined : out Boolean;
2610 Separate_Suffix : in out File_Name_Type;
2611 Sep_Suffix_Loc : out Source_Ptr)
2613 Dot_Repl : constant Variable_Value :=
2615 (Name_Dot_Replacement,
2616 Naming.Decl.Attributes,
2618 Casing_String : constant Variable_Value :=
2621 Naming.Decl.Attributes,
2623 Sep_Suffix : constant Variable_Value :=
2625 (Name_Separate_Suffix,
2626 Naming.Decl.Attributes,
2628 Dot_Repl_Loc : Source_Ptr;
2631 Sep_Suffix_Loc := No_Location;
2633 if not Dot_Repl.Default then
2635 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2637 if Length_Of_Name (Dot_Repl.Value) = 0 then
2639 (Project, "Dot_Replacement cannot be empty",
2640 Dot_Repl.Location, Data);
2643 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2644 Dot_Repl_Loc := Dot_Repl.Location;
2647 Repl : constant String := Get_Name_String (Dot_Replacement);
2650 -- Dot_Replacement cannot
2652 -- - start or end with an alphanumeric
2653 -- - be a single '_'
2654 -- - start with an '_' followed by an alphanumeric
2655 -- - contain a '.' except if it is "."
2658 or else Is_Alphanumeric (Repl (Repl'First))
2659 or else Is_Alphanumeric (Repl (Repl'Last))
2660 or else (Repl (Repl'First) = '_'
2664 Is_Alphanumeric (Repl (Repl'First + 1))))
2665 or else (Repl'Length > 1
2667 Index (Source => Repl, Pattern => ".") /= 0)
2672 """ is illegal for Dot_Replacement.",
2673 Dot_Repl_Loc, Data);
2678 if Dot_Replacement /= No_File then
2680 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2683 Casing_Defined := False;
2685 if not Casing_String.Default then
2687 (Casing_String.Kind = Single, "Casing is not a string");
2690 Casing_Image : constant String :=
2691 Get_Name_String (Casing_String.Value);
2694 if Casing_Image'Length = 0 then
2697 "Casing cannot be an empty string",
2698 Casing_String.Location, Data);
2701 Casing := Value (Casing_Image);
2702 Casing_Defined := True;
2705 when Constraint_Error =>
2706 Name_Len := Casing_Image'Length;
2707 Name_Buffer (1 .. Name_Len) := Casing_Image;
2708 Err_Vars.Error_Msg_Name_1 := Name_Find;
2711 "%% is not a correct Casing",
2712 Casing_String.Location, Data);
2716 Write_Attr ("Casing", Image (Casing));
2718 if not Sep_Suffix.Default then
2719 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2722 "Separate_Suffix cannot be empty",
2723 Sep_Suffix.Location, Data);
2726 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2727 Sep_Suffix_Loc := Sep_Suffix.Location;
2729 Check_Illegal_Suffix
2730 (Project, Separate_Suffix,
2731 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
2736 if Separate_Suffix /= No_File then
2738 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2742 -----------------------------------
2743 -- Process_Exceptions_File_Based --
2744 -----------------------------------
2746 procedure Process_Exceptions_File_Based
2747 (Lang_Id : Language_Ptr;
2750 Lang : constant Name_Id := Lang_Id.Name;
2751 Exceptions : Array_Element_Id;
2752 Exception_List : Variable_Value;
2753 Element_Id : String_List_Id;
2754 Element : String_Element;
2755 File_Name : File_Name_Type;
2757 Iter : Source_Iterator;
2764 (Name_Implementation_Exceptions,
2765 In_Arrays => Naming.Decl.Arrays,
2766 In_Tree => Data.Tree);
2771 (Name_Specification_Exceptions,
2772 In_Arrays => Naming.Decl.Arrays,
2773 In_Tree => Data.Tree);
2776 Exception_List := Value_Of
2778 In_Array => Exceptions,
2779 In_Tree => Data.Tree);
2781 if Exception_List /= Nil_Variable_Value then
2782 Element_Id := Exception_List.Values;
2783 while Element_Id /= Nil_String loop
2784 Element := Data.Tree.String_Elements.Table (Element_Id);
2785 File_Name := Canonical_Case_File_Name (Element.Value);
2787 Iter := For_Each_Source (Data.Tree, Project);
2789 Source := Prj.Element (Iter);
2790 exit when Source = No_Source or else Source.File = File_Name;
2794 if Source = No_Source then
2801 File_Name => File_Name,
2802 Display_File => File_Name_Type (Element.Value),
2803 Naming_Exception => True);
2806 -- Check if the file name is already recorded for another
2807 -- language or another kind.
2809 if Source.Language /= Lang_Id then
2812 "the same file cannot be a source of two languages",
2813 Element.Location, Data);
2815 elsif Source.Kind /= Kind then
2818 "the same file cannot be a source and a template",
2819 Element.Location, Data);
2822 -- If the file is already recorded for the same
2823 -- language and the same kind, it means that the file
2824 -- name appears several times in the *_Exceptions
2825 -- attribute; so there is nothing to do.
2828 Element_Id := Element.Next;
2831 end Process_Exceptions_File_Based;
2833 -----------------------------------
2834 -- Process_Exceptions_Unit_Based --
2835 -----------------------------------
2837 procedure Process_Exceptions_Unit_Based
2838 (Lang_Id : Language_Ptr;
2841 Lang : constant Name_Id := Lang_Id.Name;
2842 Exceptions : Array_Element_Id;
2843 Element : Array_Element;
2846 File_Name : File_Name_Type;
2855 In_Arrays => Naming.Decl.Arrays,
2856 In_Tree => Data.Tree);
2858 if Exceptions = No_Array_Element then
2861 (Name_Implementation,
2862 In_Arrays => Naming.Decl.Arrays,
2863 In_Tree => Data.Tree);
2870 In_Arrays => Naming.Decl.Arrays,
2871 In_Tree => Data.Tree);
2873 if Exceptions = No_Array_Element then
2877 In_Arrays => Naming.Decl.Arrays,
2878 In_Tree => Data.Tree);
2882 while Exceptions /= No_Array_Element loop
2883 Element := Data.Tree.Array_Elements.Table (Exceptions);
2884 File_Name := Canonical_Case_File_Name (Element.Value.Value);
2886 Get_Name_String (Element.Index);
2887 To_Lower (Name_Buffer (1 .. Name_Len));
2889 Index := Element.Value.Index;
2891 -- For Ada, check if it is a valid unit name
2893 if Lang = Name_Ada then
2894 Get_Name_String (Element.Index);
2895 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2897 if Unit = No_Name then
2898 Err_Vars.Error_Msg_Name_1 := Element.Index;
2901 "%% is not a valid unit name.",
2902 Element.Value.Location, Data);
2906 if Unit /= No_Name then
2913 File_Name => File_Name,
2914 Display_File => File_Name_Type (Element.Value.Value),
2917 Location => Element.Value.Location,
2918 Naming_Exception => True);
2921 Exceptions := Element.Next;
2923 end Process_Exceptions_Unit_Based;
2929 procedure Check_Naming is
2930 Dot_Replacement : File_Name_Type :=
2932 (First_Name_Id + Character'Pos ('-'));
2933 Separate_Suffix : File_Name_Type := No_File;
2934 Casing : Casing_Type := All_Lower_Case;
2935 Casing_Defined : Boolean;
2936 Lang_Id : Language_Ptr;
2937 Sep_Suffix_Loc : Source_Ptr;
2938 Suffix : Variable_Value;
2943 (Dot_Replacement => Dot_Replacement,
2945 Casing_Defined => Casing_Defined,
2946 Separate_Suffix => Separate_Suffix,
2947 Sep_Suffix_Loc => Sep_Suffix_Loc);
2949 -- For all unit based languages, if any, set the specified value
2950 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
2951 -- systematically overwrite, since the defaults come from the
2952 -- configuration file.
2954 if Dot_Replacement /= No_File
2955 or else Casing_Defined
2956 or else Separate_Suffix /= No_File
2958 Lang_Id := Project.Languages;
2959 while Lang_Id /= No_Language_Index loop
2960 if Lang_Id.Config.Kind = Unit_Based then
2961 if Dot_Replacement /= No_File then
2962 Lang_Id.Config.Naming_Data.Dot_Replacement :=
2966 if Casing_Defined then
2967 Lang_Id.Config.Naming_Data.Casing := Casing;
2971 Lang_Id := Lang_Id.Next;
2975 -- Next, get the spec and body suffixes
2977 Lang_Id := Project.Languages;
2978 while Lang_Id /= No_Language_Index loop
2979 Lang := Lang_Id.Name;
2985 Attribute_Or_Array_Name => Name_Spec_Suffix,
2986 In_Package => Naming_Id,
2987 In_Tree => Data.Tree);
2989 if Suffix = Nil_Variable_Value then
2992 Attribute_Or_Array_Name => Name_Specification_Suffix,
2993 In_Package => Naming_Id,
2994 In_Tree => Data.Tree);
2997 if Suffix /= Nil_Variable_Value then
2998 Lang_Id.Config.Naming_Data.Spec_Suffix :=
2999 File_Name_Type (Suffix.Value);
3001 Check_Illegal_Suffix
3003 Lang_Id.Config.Naming_Data.Spec_Suffix,
3004 Lang_Id.Config.Naming_Data.Dot_Replacement,
3005 "Spec_Suffix", Suffix.Location, Data);
3009 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3017 Attribute_Or_Array_Name => Name_Body_Suffix,
3018 In_Package => Naming_Id,
3019 In_Tree => Data.Tree);
3021 if Suffix = Nil_Variable_Value then
3025 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3026 In_Package => Naming_Id,
3027 In_Tree => Data.Tree);
3030 if Suffix /= Nil_Variable_Value then
3031 Lang_Id.Config.Naming_Data.Body_Suffix :=
3032 File_Name_Type (Suffix.Value);
3034 -- The default value of separate suffix should be the same as
3035 -- the body suffix, so we need to compute that first.
3037 if Separate_Suffix = No_File then
3038 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3039 Lang_Id.Config.Naming_Data.Body_Suffix;
3043 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3045 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3049 Check_Illegal_Suffix
3051 Lang_Id.Config.Naming_Data.Body_Suffix,
3052 Lang_Id.Config.Naming_Data.Dot_Replacement,
3053 "Body_Suffix", Suffix.Location, Data);
3057 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3059 elsif Separate_Suffix /= No_File then
3060 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3063 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3064 -- since that would cause a clear ambiguity. Note that we do allow
3065 -- a Spec_Suffix to have the same termination as one of these,
3066 -- which causes a potential ambiguity, but we resolve that my
3067 -- matching the longest possible suffix.
3069 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3070 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3071 Lang_Id.Config.Naming_Data.Body_Suffix
3076 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3077 & """) cannot be the same as Spec_Suffix.",
3078 Ada_Body_Suffix_Loc, Data);
3081 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3082 Lang_Id.Config.Naming_Data.Separate_Suffix
3083 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3084 Lang_Id.Config.Naming_Data.Separate_Suffix
3088 "Separate_Suffix ("""
3090 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3091 & """) cannot be the same as Spec_Suffix.",
3092 Sep_Suffix_Loc, Data);
3095 Lang_Id := Lang_Id.Next;
3098 -- Get the naming exceptions for all languages
3100 for Kind in Spec .. Impl loop
3101 Lang_Id := Project.Languages;
3102 while Lang_Id /= No_Language_Index loop
3103 case Lang_Id.Config.Kind is
3105 Process_Exceptions_File_Based (Lang_Id, Kind);
3108 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3111 Lang_Id := Lang_Id.Next;
3116 ----------------------------
3117 -- Initialize_Naming_Data --
3118 ----------------------------
3120 procedure Initialize_Naming_Data is
3121 Specs : Array_Element_Id :=
3127 Impls : Array_Element_Id :=
3133 Lang : Language_Ptr;
3134 Lang_Name : Name_Id;
3135 Value : Variable_Value;
3136 Extended : Project_Id;
3139 -- At this stage, the project already contains the default extensions
3140 -- for the various languages. We now merge those suffixes read in the
3141 -- user project, and they override the default.
3143 while Specs /= No_Array_Element loop
3144 Lang_Name := Data.Tree.Array_Elements.Table (Specs).Index;
3146 Get_Language_From_Name
3147 (Project, Name => Get_Name_String (Lang_Name));
3149 -- An extending project inherits its parent projects' languages
3150 -- so if needed we should create entries for those languages
3153 Extended := Project.Extends;
3154 while Extended /= null loop
3155 Lang := Get_Language_From_Name
3156 (Extended, Name => Get_Name_String (Lang_Name));
3157 exit when Lang /= null;
3159 Extended := Extended.Extends;
3162 if Lang /= null then
3163 Lang := new Language_Data'(Lang.all);
3164 Lang.First_Source := null;
3165 Lang.Next := Project.Languages;
3166 Project.Languages := Lang;
3170 -- If language was not found in project or the projects it extends
3173 if Current_Verbosity = High then
3175 ("Ignoring spec naming data for "
3176 & Get_Name_String (Lang_Name)
3177 & " since language is not defined for this project");
3181 Value := Data.Tree.Array_Elements.Table (Specs).Value;
3183 if Value.Kind = Single then
3184 Lang.Config.Naming_Data.Spec_Suffix :=
3185 Canonical_Case_File_Name (Value.Value);
3189 Specs := Data.Tree.Array_Elements.Table (Specs).Next;
3192 while Impls /= No_Array_Element loop
3193 Lang_Name := Data.Tree.Array_Elements.Table (Impls).Index;
3195 Get_Language_From_Name
3196 (Project, Name => Get_Name_String (Lang_Name));
3199 if Current_Verbosity = High then
3201 ("Ignoring impl naming data for "
3202 & Get_Name_String (Lang_Name)
3203 & " since language is not defined for this project");
3206 Value := Data.Tree.Array_Elements.Table (Impls).Value;
3208 if Lang.Name = Name_Ada then
3209 Ada_Body_Suffix_Loc := Value.Location;
3212 if Value.Kind = Single then
3213 Lang.Config.Naming_Data.Body_Suffix :=
3214 Canonical_Case_File_Name (Value.Value);
3218 Impls := Data.Tree.Array_Elements.Table (Impls).Next;
3220 end Initialize_Naming_Data;
3222 -- Start of processing for Check_Naming_Schemes
3225 Specs := No_Array_Element;
3226 Bodies := No_Array_Element;
3228 -- No Naming package or parsing a configuration file? nothing to do
3230 if Naming_Id /= No_Package
3231 and Project.Qualifier /= Configuration
3233 Naming := Data.Tree.Packages.Table (Naming_Id);
3235 if Current_Verbosity = High then
3236 Write_Line ("Checking package Naming for project "
3237 & Get_Name_String (Project.Name));
3240 Initialize_Naming_Data;
3243 end Check_Package_Naming;
3245 ------------------------------
3246 -- Check_Library_Attributes --
3247 ------------------------------
3249 procedure Check_Library_Attributes
3250 (Project : Project_Id;
3251 Data : in out Tree_Processing_Data)
3253 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3255 Lib_Dir : constant Prj.Variable_Value :=
3257 (Snames.Name_Library_Dir, Attributes, Data.Tree);
3259 Lib_Name : constant Prj.Variable_Value :=
3261 (Snames.Name_Library_Name, Attributes, Data.Tree);
3263 Lib_Version : constant Prj.Variable_Value :=
3265 (Snames.Name_Library_Version, Attributes, Data.Tree);
3267 Lib_ALI_Dir : constant Prj.Variable_Value :=
3269 (Snames.Name_Library_Ali_Dir, Attributes, Data.Tree);
3271 Lib_GCC : constant Prj.Variable_Value :=
3273 (Snames.Name_Library_GCC, Attributes, Data.Tree);
3275 The_Lib_Kind : constant Prj.Variable_Value :=
3277 (Snames.Name_Library_Kind, Attributes, Data.Tree);
3279 Imported_Project_List : Project_List;
3281 Continuation : String_Access := No_Continuation_String'Access;
3283 Support_For_Libraries : Library_Support;
3285 Library_Directory_Present : Boolean;
3287 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3288 -- Check if an imported or extended project if also a library project
3294 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3296 Iter : Source_Iterator;
3299 if Proj /= No_Project then
3300 if not Proj.Library then
3302 -- The only not library projects that are OK are those that
3303 -- have no sources. However, header files from non-Ada
3304 -- languages are OK, as there is nothing to compile.
3306 Iter := For_Each_Source (Data.Tree, Proj);
3308 Src_Id := Prj.Element (Iter);
3309 exit when Src_Id = No_Source
3310 or else Src_Id.Language.Config.Kind /= File_Based
3311 or else Src_Id.Kind /= Spec;
3315 if Src_Id /= No_Source then
3316 Error_Msg_Name_1 := Project.Name;
3317 Error_Msg_Name_2 := Proj.Name;
3320 if Project.Library_Kind /= Static then
3324 "shared library project %% cannot extend " &
3325 "project %% that is not a library project",
3326 Project.Location, Data);
3327 Continuation := Continuation_String'Access;
3330 elsif (not Unchecked_Shared_Lib_Imports)
3331 and then Project.Library_Kind /= Static
3336 "shared library project %% cannot import project %% " &
3337 "that is not a shared library project",
3338 Project.Location, Data);
3339 Continuation := Continuation_String'Access;
3343 elsif Project.Library_Kind /= Static and then
3344 Proj.Library_Kind = Static
3346 Error_Msg_Name_1 := Project.Name;
3347 Error_Msg_Name_2 := Proj.Name;
3353 "shared library project %% cannot extend static " &
3354 "library project %%",
3355 Project.Location, Data);
3356 Continuation := Continuation_String'Access;
3358 elsif not Unchecked_Shared_Lib_Imports then
3362 "shared library project %% cannot import static " &
3363 "library project %%",
3364 Project.Location, Data);
3365 Continuation := Continuation_String'Access;
3372 Dir_Exists : Boolean;
3374 -- Start of processing for Check_Library_Attributes
3377 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3379 -- Special case of extending project
3381 if Project.Extends /= No_Project then
3383 -- If the project extended is a library project, we inherit the
3384 -- library name, if it is not redefined; we check that the library
3385 -- directory is specified.
3387 if Project.Extends.Library then
3388 if Project.Qualifier = Standard then
3391 "a standard project cannot extend a library project",
3392 Project.Location, Data);
3395 if Lib_Name.Default then
3396 Project.Library_Name := Project.Extends.Library_Name;
3399 if Lib_Dir.Default then
3400 if not Project.Virtual then
3403 "a project extending a library project must " &
3404 "specify an attribute Library_Dir",
3405 Project.Location, Data);
3408 -- For a virtual project extending a library project,
3409 -- inherit library directory.
3411 Project.Library_Dir := Project.Extends.Library_Dir;
3412 Library_Directory_Present := True;
3419 pragma Assert (Lib_Name.Kind = Single);
3421 if Lib_Name.Value = Empty_String then
3422 if Current_Verbosity = High
3423 and then Project.Library_Name = No_Name
3425 Write_Line ("No library name");
3429 -- There is no restriction on the syntax of library names
3431 Project.Library_Name := Lib_Name.Value;
3434 if Project.Library_Name /= No_Name then
3435 if Current_Verbosity = High then
3437 ("Library name", Get_Name_String (Project.Library_Name));
3440 pragma Assert (Lib_Dir.Kind = Single);
3442 if not Library_Directory_Present then
3443 if Current_Verbosity = High then
3444 Write_Line ("No library directory");
3448 -- Find path name (unless inherited), check that it is a directory
3450 if Project.Library_Dir = No_Path_Information then
3453 File_Name_Type (Lib_Dir.Value),
3454 Path => Project.Library_Dir,
3455 Dir_Exists => Dir_Exists,
3457 Create => "library",
3458 Must_Exist => False,
3459 Location => Lib_Dir.Location,
3460 Externally_Built => Project.Externally_Built);
3466 (Project.Library_Dir.Display_Name));
3469 if not Dir_Exists then
3471 -- Get the absolute name of the library directory that
3472 -- does not exist, to report an error.
3474 Err_Vars.Error_Msg_File_1 :=
3475 File_Name_Type (Project.Library_Dir.Display_Name);
3478 "library directory { does not exist",
3479 Lib_Dir.Location, Data);
3481 -- The library directory cannot be the same as the Object
3484 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3487 "library directory cannot be the same " &
3488 "as object directory",
3489 Lib_Dir.Location, Data);
3490 Project.Library_Dir := No_Path_Information;
3494 OK : Boolean := True;
3495 Dirs_Id : String_List_Id;
3496 Dir_Elem : String_Element;
3500 -- The library directory cannot be the same as a source
3501 -- directory of the current project.
3503 Dirs_Id := Project.Source_Dirs;
3504 while Dirs_Id /= Nil_String loop
3505 Dir_Elem := Data.Tree.String_Elements.Table (Dirs_Id);
3506 Dirs_Id := Dir_Elem.Next;
3508 if Project.Library_Dir.Name =
3509 Path_Name_Type (Dir_Elem.Value)
3511 Err_Vars.Error_Msg_File_1 :=
3512 File_Name_Type (Dir_Elem.Value);
3515 "library directory cannot be the same " &
3516 "as source directory {",
3517 Lib_Dir.Location, Data);
3525 -- The library directory cannot be the same as a source
3526 -- directory of another project either.
3528 Pid := Data.Tree.Projects;
3530 exit Project_Loop when Pid = null;
3532 if Pid.Project /= Project then
3533 Dirs_Id := Pid.Project.Source_Dirs;
3535 Dir_Loop : while Dirs_Id /= Nil_String loop
3537 Data.Tree.String_Elements.Table (Dirs_Id);
3538 Dirs_Id := Dir_Elem.Next;
3540 if Project.Library_Dir.Name =
3541 Path_Name_Type (Dir_Elem.Value)
3543 Err_Vars.Error_Msg_File_1 :=
3544 File_Name_Type (Dir_Elem.Value);
3545 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3549 "library directory cannot be the same " &
3550 "as source directory { of project %%",
3551 Lib_Dir.Location, Data);
3559 end loop Project_Loop;
3563 Project.Library_Dir := No_Path_Information;
3565 elsif Current_Verbosity = High then
3567 -- Display the Library directory in high verbosity
3570 ("Library directory",
3571 Get_Name_String (Project.Library_Dir.Display_Name));
3580 Project.Library_Dir /= No_Path_Information
3581 and then Project.Library_Name /= No_Name;
3583 if Project.Extends = No_Project then
3584 case Project.Qualifier is
3586 if Project.Library then
3589 "a standard project cannot be a library project",
3590 Lib_Name.Location, Data);
3594 if not Project.Library then
3595 if Project.Library_Dir = No_Path_Information then
3598 "\attribute Library_Dir not declared",
3599 Project.Location, Data);
3602 if Project.Library_Name = No_Name then
3605 "\attribute Library_Name not declared",
3606 Project.Location, Data);
3616 if Project.Library then
3617 Support_For_Libraries := Project.Config.Lib_Support;
3619 if Support_For_Libraries = Prj.None then
3622 "?libraries are not supported on this platform",
3623 Lib_Name.Location, Data);
3624 Project.Library := False;
3627 if Lib_ALI_Dir.Value = Empty_String then
3628 if Current_Verbosity = High then
3629 Write_Line ("No library ALI directory specified");
3632 Project.Library_ALI_Dir := Project.Library_Dir;
3635 -- Find path name, check that it is a directory
3639 File_Name_Type (Lib_ALI_Dir.Value),
3640 Path => Project.Library_ALI_Dir,
3641 Create => "library ALI",
3642 Dir_Exists => Dir_Exists,
3644 Must_Exist => False,
3645 Location => Lib_ALI_Dir.Location,
3646 Externally_Built => Project.Externally_Built);
3648 if not Dir_Exists then
3650 -- Get the absolute name of the library ALI directory that
3651 -- does not exist, to report an error.
3653 Err_Vars.Error_Msg_File_1 :=
3654 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3657 "library 'A'L'I directory { does not exist",
3658 Lib_ALI_Dir.Location, Data);
3661 if Project.Library_ALI_Dir /= Project.Library_Dir then
3663 -- The library ALI directory cannot be the same as the
3664 -- Object directory.
3666 if Project.Library_ALI_Dir = Project.Object_Directory then
3669 "library 'A'L'I directory cannot be the same " &
3670 "as object directory",
3671 Lib_ALI_Dir.Location, Data);
3672 Project.Library_ALI_Dir := No_Path_Information;
3676 OK : Boolean := True;
3677 Dirs_Id : String_List_Id;
3678 Dir_Elem : String_Element;
3682 -- The library ALI directory cannot be the same as
3683 -- a source directory of the current project.
3685 Dirs_Id := Project.Source_Dirs;
3686 while Dirs_Id /= Nil_String loop
3688 Data.Tree.String_Elements.Table (Dirs_Id);
3689 Dirs_Id := Dir_Elem.Next;
3691 if Project.Library_ALI_Dir.Name =
3692 Path_Name_Type (Dir_Elem.Value)
3694 Err_Vars.Error_Msg_File_1 :=
3695 File_Name_Type (Dir_Elem.Value);
3698 "library 'A'L'I directory cannot be " &
3699 "the same as source directory {",
3700 Lib_ALI_Dir.Location, Data);
3708 -- The library ALI directory cannot be the same as
3709 -- a source directory of another project either.
3711 Pid := Data.Tree.Projects;
3712 ALI_Project_Loop : loop
3713 exit ALI_Project_Loop when Pid = null;
3715 if Pid.Project /= Project then
3716 Dirs_Id := Pid.Project.Source_Dirs;
3719 while Dirs_Id /= Nil_String loop
3721 Data.Tree.String_Elements.Table
3723 Dirs_Id := Dir_Elem.Next;
3725 if Project.Library_ALI_Dir.Name =
3726 Path_Name_Type (Dir_Elem.Value)
3728 Err_Vars.Error_Msg_File_1 :=
3729 File_Name_Type (Dir_Elem.Value);
3730 Err_Vars.Error_Msg_Name_1 :=
3735 "library 'A'L'I directory cannot " &
3736 "be the same as source directory " &
3738 Lib_ALI_Dir.Location, Data);
3740 exit ALI_Project_Loop;
3742 end loop ALI_Dir_Loop;
3745 end loop ALI_Project_Loop;
3749 Project.Library_ALI_Dir := No_Path_Information;
3751 elsif Current_Verbosity = High then
3753 -- Display Library ALI directory in high verbosity
3758 (Project.Library_ALI_Dir.Display_Name));
3765 pragma Assert (Lib_Version.Kind = Single);
3767 if Lib_Version.Value = Empty_String then
3768 if Current_Verbosity = High then
3769 Write_Line ("No library version specified");
3773 Project.Lib_Internal_Name := Lib_Version.Value;
3776 pragma Assert (The_Lib_Kind.Kind = Single);
3778 if The_Lib_Kind.Value = Empty_String then
3779 if Current_Verbosity = High then
3780 Write_Line ("No library kind specified");
3784 Get_Name_String (The_Lib_Kind.Value);
3787 Kind_Name : constant String :=
3788 To_Lower (Name_Buffer (1 .. Name_Len));
3790 OK : Boolean := True;
3793 if Kind_Name = "static" then
3794 Project.Library_Kind := Static;
3796 elsif Kind_Name = "dynamic" then
3797 Project.Library_Kind := Dynamic;
3799 elsif Kind_Name = "relocatable" then
3800 Project.Library_Kind := Relocatable;
3805 "illegal value for Library_Kind",
3806 The_Lib_Kind.Location, Data);
3810 if Current_Verbosity = High and then OK then
3811 Write_Attr ("Library kind", Kind_Name);
3814 if Project.Library_Kind /= Static then
3815 if Support_For_Libraries = Prj.Static_Only then
3818 "only static libraries are supported " &
3820 The_Lib_Kind.Location, Data);
3821 Project.Library := False;
3824 -- Check if (obsolescent) attribute Library_GCC or
3825 -- Linker'Driver is declared.
3827 if Lib_GCC.Value /= Empty_String then
3830 "?Library_'G'C'C is an obsolescent attribute, " &
3831 "use Linker''Driver instead",
3832 Lib_GCC.Location, Data);
3833 Project.Config.Shared_Lib_Driver :=
3834 File_Name_Type (Lib_GCC.Value);
3838 Linker : constant Package_Id :=
3841 Project.Decl.Packages,
3843 Driver : constant Variable_Value :=
3846 Attribute_Or_Array_Name =>
3848 In_Package => Linker,
3849 In_Tree => Data.Tree);
3852 if Driver /= Nil_Variable_Value
3853 and then Driver.Value /= Empty_String
3855 Project.Config.Shared_Lib_Driver :=
3856 File_Name_Type (Driver.Value);
3865 if Project.Library then
3866 if Current_Verbosity = High then
3867 Write_Line ("This is a library project file");
3870 Check_Library (Project.Extends, Extends => True);
3872 Imported_Project_List := Project.Imported_Projects;
3873 while Imported_Project_List /= null loop
3875 (Imported_Project_List.Project,
3877 Imported_Project_List := Imported_Project_List.Next;
3884 -- Check if Linker'Switches or Linker'Default_Switches are declared.
3885 -- Warn if they are declared, as it is a common error to think that
3886 -- library are "linked" with Linker switches.
3888 if Project.Library then
3890 Linker_Package_Id : constant Package_Id :=
3893 Project.Decl.Packages, Data.Tree);
3894 Linker_Package : Package_Element;
3895 Switches : Array_Element_Id := No_Array_Element;
3898 if Linker_Package_Id /= No_Package then
3899 Linker_Package := Data.Tree.Packages.Table (Linker_Package_Id);
3903 (Name => Name_Switches,
3904 In_Arrays => Linker_Package.Decl.Arrays,
3905 In_Tree => Data.Tree);
3907 if Switches = No_Array_Element then
3910 (Name => Name_Default_Switches,
3911 In_Arrays => Linker_Package.Decl.Arrays,
3912 In_Tree => Data.Tree);
3915 if Switches /= No_Array_Element then
3918 "?Linker switches not taken into account in library " &
3926 if Project.Extends /= No_Project then
3927 Project.Extends.Library := False;
3929 end Check_Library_Attributes;
3931 ---------------------------------
3932 -- Check_Programming_Languages --
3933 ---------------------------------
3935 procedure Check_Programming_Languages
3936 (Project : Project_Id;
3937 Data : in out Tree_Processing_Data)
3939 Languages : Variable_Value := Nil_Variable_Value;
3940 Def_Lang : Variable_Value := Nil_Variable_Value;
3941 Def_Lang_Id : Name_Id;
3943 procedure Add_Language (Name, Display_Name : Name_Id);
3944 -- Add a new language to the list of languages for the project.
3945 -- Nothing is done if the language has already been defined
3951 procedure Add_Language (Name, Display_Name : Name_Id) is
3952 Lang : Language_Ptr;
3955 Lang := Project.Languages;
3956 while Lang /= No_Language_Index loop
3957 if Name = Lang.Name then
3964 Lang := new Language_Data'(No_Language_Data);
3965 Lang.Next := Project.Languages;
3966 Project.Languages := Lang;
3968 Lang.Display_Name := Display_Name;
3970 if Name = Name_Ada then
3971 Lang.Config.Kind := Unit_Based;
3972 Lang.Config.Dependency_Kind := ALI_File;
3974 Lang.Config.Kind := File_Based;
3978 -- Start of processing for Check_Programming_Languages
3981 Project.Languages := null;
3983 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Data.Tree);
3986 (Name_Default_Language, Project.Decl.Attributes, Data.Tree);
3988 if Project.Source_Dirs /= Nil_String then
3990 -- Check if languages are specified in this project
3992 if Languages.Default then
3994 -- Fail if there is no default language defined
3996 if Def_Lang.Default then
3999 "no languages defined for this project",
4000 Project.Location, Data);
4001 Def_Lang_Id := No_Name;
4004 Get_Name_String (Def_Lang.Value);
4005 To_Lower (Name_Buffer (1 .. Name_Len));
4006 Def_Lang_Id := Name_Find;
4009 if Def_Lang_Id /= No_Name then
4010 Get_Name_String (Def_Lang_Id);
4011 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4013 (Name => Def_Lang_Id,
4014 Display_Name => Name_Find);
4019 Current : String_List_Id := Languages.Values;
4020 Element : String_Element;
4023 -- If there are no languages declared, there are no sources
4025 if Current = Nil_String then
4026 Project.Source_Dirs := Nil_String;
4028 if Project.Qualifier = Standard then
4031 "a standard project must have at least one language",
4032 Languages.Location, Data);
4036 -- Look through all the languages specified in attribute
4039 while Current /= Nil_String loop
4040 Element := Data.Tree.String_Elements.Table (Current);
4041 Get_Name_String (Element.Value);
4042 To_Lower (Name_Buffer (1 .. Name_Len));
4046 Display_Name => Element.Value);
4048 Current := Element.Next;
4054 end Check_Programming_Languages;
4056 -------------------------------
4057 -- Check_Stand_Alone_Library --
4058 -------------------------------
4060 procedure Check_Stand_Alone_Library
4061 (Project : Project_Id;
4062 Data : in out Tree_Processing_Data)
4064 Lib_Interfaces : constant Prj.Variable_Value :=
4066 (Snames.Name_Library_Interface,
4067 Project.Decl.Attributes,
4070 Lib_Auto_Init : constant Prj.Variable_Value :=
4072 (Snames.Name_Library_Auto_Init,
4073 Project.Decl.Attributes,
4076 Lib_Src_Dir : constant Prj.Variable_Value :=
4078 (Snames.Name_Library_Src_Dir,
4079 Project.Decl.Attributes,
4082 Lib_Symbol_File : constant Prj.Variable_Value :=
4084 (Snames.Name_Library_Symbol_File,
4085 Project.Decl.Attributes,
4088 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4090 (Snames.Name_Library_Symbol_Policy,
4091 Project.Decl.Attributes,
4094 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4096 (Snames.Name_Library_Reference_Symbol_File,
4097 Project.Decl.Attributes,
4100 Auto_Init_Supported : Boolean;
4101 OK : Boolean := True;
4103 Next_Proj : Project_Id;
4104 Iter : Source_Iterator;
4107 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4109 pragma Assert (Lib_Interfaces.Kind = List);
4111 -- It is a stand-alone library project file if attribute
4112 -- Library_Interface is defined.
4114 if not Lib_Interfaces.Default then
4116 Interfaces : String_List_Id := Lib_Interfaces.Values;
4117 Interface_ALIs : String_List_Id := Nil_String;
4121 Project.Standalone_Library := True;
4123 -- Library_Interface cannot be an empty list
4125 if Interfaces = Nil_String then
4128 "Library_Interface cannot be an empty list",
4129 Lib_Interfaces.Location, Data);
4132 -- Process each unit name specified in the attribute
4133 -- Library_Interface.
4135 while Interfaces /= Nil_String loop
4137 (Data.Tree.String_Elements.Table (Interfaces).Value);
4138 To_Lower (Name_Buffer (1 .. Name_Len));
4140 if Name_Len = 0 then
4143 "an interface cannot be an empty string",
4144 Data.Tree.String_Elements.Table (Interfaces).Location,
4149 Error_Msg_Name_1 := Unit;
4151 Next_Proj := Project.Extends;
4152 Iter := For_Each_Source (Data.Tree, Project);
4154 while Prj.Element (Iter) /= No_Source
4156 (Prj.Element (Iter).Unit = null
4157 or else Prj.Element (Iter).Unit.Name /= Unit)
4162 Source := Prj.Element (Iter);
4163 exit when Source /= No_Source
4164 or else Next_Proj = No_Project;
4166 Iter := For_Each_Source (Data.Tree, Next_Proj);
4167 Next_Proj := Next_Proj.Extends;
4170 if Source /= No_Source then
4171 if Source.Kind = Sep then
4172 Source := No_Source;
4174 elsif Source.Kind = Spec
4175 and then Other_Part (Source) /= No_Source
4177 Source := Other_Part (Source);
4181 if Source /= No_Source then
4182 if Source.Project /= Project
4183 and then not Is_Extending (Project, Source.Project)
4185 Source := No_Source;
4189 if Source = No_Source then
4192 "%% is not a unit of this project",
4193 Data.Tree.String_Elements.Table
4194 (Interfaces).Location, Data);
4197 if Source.Kind = Spec
4198 and then Other_Part (Source) /= No_Source
4200 Source := Other_Part (Source);
4203 String_Element_Table.Increment_Last
4204 (Data.Tree.String_Elements);
4206 Data.Tree.String_Elements.Table
4207 (String_Element_Table.Last
4208 (Data.Tree.String_Elements)) :=
4209 (Value => Name_Id (Source.Dep_Name),
4211 Display_Value => Name_Id (Source.Dep_Name),
4213 Data.Tree.String_Elements.Table
4214 (Interfaces).Location,
4216 Next => Interface_ALIs);
4219 String_Element_Table.Last
4220 (Data.Tree.String_Elements);
4224 Interfaces := Data.Tree.String_Elements.Table (Interfaces).Next;
4227 -- Put the list of Interface ALIs in the project data
4229 Project.Lib_Interface_ALIs := Interface_ALIs;
4231 -- Check value of attribute Library_Auto_Init and set
4232 -- Lib_Auto_Init accordingly.
4234 if Lib_Auto_Init.Default then
4236 -- If no attribute Library_Auto_Init is declared, then set auto
4237 -- init only if it is supported.
4239 Project.Lib_Auto_Init := Auto_Init_Supported;
4242 Get_Name_String (Lib_Auto_Init.Value);
4243 To_Lower (Name_Buffer (1 .. Name_Len));
4245 if Name_Buffer (1 .. Name_Len) = "false" then
4246 Project.Lib_Auto_Init := False;
4248 elsif Name_Buffer (1 .. Name_Len) = "true" then
4249 if Auto_Init_Supported then
4250 Project.Lib_Auto_Init := True;
4253 -- Library_Auto_Init cannot be "true" if auto init is not
4258 "library auto init not supported " &
4260 Lib_Auto_Init.Location, Data);
4266 "invalid value for attribute Library_Auto_Init",
4267 Lib_Auto_Init.Location, Data);
4272 -- If attribute Library_Src_Dir is defined and not the empty string,
4273 -- check if the directory exist and is not the object directory or
4274 -- one of the source directories. This is the directory where copies
4275 -- of the interface sources will be copied. Note that this directory
4276 -- may be the library directory.
4278 if Lib_Src_Dir.Value /= Empty_String then
4280 Dir_Id : constant File_Name_Type :=
4281 File_Name_Type (Lib_Src_Dir.Value);
4282 Dir_Exists : Boolean;
4288 Path => Project.Library_Src_Dir,
4289 Dir_Exists => Dir_Exists,
4291 Must_Exist => False,
4292 Create => "library source copy",
4293 Location => Lib_Src_Dir.Location,
4294 Externally_Built => Project.Externally_Built);
4296 -- If directory does not exist, report an error
4298 if not Dir_Exists then
4300 -- Get the absolute name of the library directory that does
4301 -- not exist, to report an error.
4303 Err_Vars.Error_Msg_File_1 :=
4304 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4307 "Directory { does not exist",
4308 Lib_Src_Dir.Location, Data);
4310 -- Report error if it is the same as the object directory
4312 elsif Project.Library_Src_Dir = Project.Object_Directory then
4315 "directory to copy interfaces cannot be " &
4316 "the object directory",
4317 Lib_Src_Dir.Location, Data);
4318 Project.Library_Src_Dir := No_Path_Information;
4322 Src_Dirs : String_List_Id;
4323 Src_Dir : String_Element;
4327 -- Interface copy directory cannot be one of the source
4328 -- directory of the current project.
4330 Src_Dirs := Project.Source_Dirs;
4331 while Src_Dirs /= Nil_String loop
4332 Src_Dir := Data.Tree.String_Elements.Table (Src_Dirs);
4334 -- Report error if it is one of the source directories
4336 if Project.Library_Src_Dir.Name =
4337 Path_Name_Type (Src_Dir.Value)
4341 "directory to copy interfaces cannot " &
4342 "be one of the source directories",
4343 Lib_Src_Dir.Location, Data);
4344 Project.Library_Src_Dir := No_Path_Information;
4348 Src_Dirs := Src_Dir.Next;
4351 if Project.Library_Src_Dir /= No_Path_Information then
4353 -- It cannot be a source directory of any other
4356 Pid := Data.Tree.Projects;
4358 exit Project_Loop when Pid = null;
4360 Src_Dirs := Pid.Project.Source_Dirs;
4361 Dir_Loop : while Src_Dirs /= Nil_String loop
4363 Data.Tree.String_Elements.Table (Src_Dirs);
4365 -- Report error if it is one of the source
4368 if Project.Library_Src_Dir.Name =
4369 Path_Name_Type (Src_Dir.Value)
4372 File_Name_Type (Src_Dir.Value);
4373 Error_Msg_Name_1 := Pid.Project.Name;
4376 "directory to copy interfaces cannot " &
4377 "be the same as source directory { of " &
4379 Lib_Src_Dir.Location, Data);
4380 Project.Library_Src_Dir :=
4381 No_Path_Information;
4385 Src_Dirs := Src_Dir.Next;
4389 end loop Project_Loop;
4393 -- In high verbosity, if there is a valid Library_Src_Dir,
4394 -- display its path name.
4396 if Project.Library_Src_Dir /= No_Path_Information
4397 and then Current_Verbosity = High
4400 ("Directory to copy interfaces",
4401 Get_Name_String (Project.Library_Src_Dir.Name));
4407 -- Check the symbol related attributes
4409 -- First, the symbol policy
4411 if not Lib_Symbol_Policy.Default then
4413 Value : constant String :=
4415 (Get_Name_String (Lib_Symbol_Policy.Value));
4418 -- Symbol policy must hove one of a limited number of values
4420 if Value = "autonomous" or else Value = "default" then
4421 Project.Symbol_Data.Symbol_Policy := Autonomous;
4423 elsif Value = "compliant" then
4424 Project.Symbol_Data.Symbol_Policy := Compliant;
4426 elsif Value = "controlled" then
4427 Project.Symbol_Data.Symbol_Policy := Controlled;
4429 elsif Value = "restricted" then
4430 Project.Symbol_Data.Symbol_Policy := Restricted;
4432 elsif Value = "direct" then
4433 Project.Symbol_Data.Symbol_Policy := Direct;
4438 "illegal value for Library_Symbol_Policy",
4439 Lib_Symbol_Policy.Location, Data);
4444 -- If attribute Library_Symbol_File is not specified, symbol policy
4445 -- cannot be Restricted.
4447 if Lib_Symbol_File.Default then
4448 if Project.Symbol_Data.Symbol_Policy = Restricted then
4451 "Library_Symbol_File needs to be defined when " &
4452 "symbol policy is Restricted",
4453 Lib_Symbol_Policy.Location, Data);
4457 -- Library_Symbol_File is defined
4459 Project.Symbol_Data.Symbol_File :=
4460 Path_Name_Type (Lib_Symbol_File.Value);
4462 Get_Name_String (Lib_Symbol_File.Value);
4464 if Name_Len = 0 then
4467 "symbol file name cannot be an empty string",
4468 Lib_Symbol_File.Location, Data);
4471 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4474 for J in 1 .. Name_Len loop
4475 if Name_Buffer (J) = '/'
4476 or else Name_Buffer (J) = Directory_Separator
4485 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4488 "symbol file name { is illegal. " &
4489 "Name cannot include directory info.",
4490 Lib_Symbol_File.Location, Data);
4495 -- If attribute Library_Reference_Symbol_File is not defined,
4496 -- symbol policy cannot be Compliant or Controlled.
4498 if Lib_Ref_Symbol_File.Default then
4499 if Project.Symbol_Data.Symbol_Policy = Compliant
4500 or else Project.Symbol_Data.Symbol_Policy = Controlled
4504 "a reference symbol file needs to be defined",
4505 Lib_Symbol_Policy.Location, Data);
4509 -- Library_Reference_Symbol_File is defined, check file exists
4511 Project.Symbol_Data.Reference :=
4512 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4514 Get_Name_String (Lib_Ref_Symbol_File.Value);
4516 if Name_Len = 0 then
4519 "reference symbol file name cannot be an empty string",
4520 Lib_Symbol_File.Location, Data);
4523 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4525 Add_Str_To_Name_Buffer
4526 (Get_Name_String (Project.Directory.Name));
4527 Add_Str_To_Name_Buffer
4528 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4529 Project.Symbol_Data.Reference := Name_Find;
4532 if not Is_Regular_File
4533 (Get_Name_String (Project.Symbol_Data.Reference))
4536 File_Name_Type (Lib_Ref_Symbol_File.Value);
4538 -- For controlled and direct symbol policies, it is an error
4539 -- if the reference symbol file does not exist. For other
4540 -- symbol policies, this is just a warning
4543 Project.Symbol_Data.Symbol_Policy /= Controlled
4544 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4548 "<library reference symbol file { does not exist",
4549 Lib_Ref_Symbol_File.Location, Data);
4551 -- In addition in the non-controlled case, if symbol policy
4552 -- is Compliant, it is changed to Autonomous, because there
4553 -- is no reference to check against, and we don't want to
4554 -- fail in this case.
4556 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4557 if Project.Symbol_Data.Symbol_Policy = Compliant then
4558 Project.Symbol_Data.Symbol_Policy := Autonomous;
4563 -- If both the reference symbol file and the symbol file are
4564 -- defined, then check that they are not the same file.
4566 if Project.Symbol_Data.Symbol_File /= No_Path then
4567 Get_Name_String (Project.Symbol_Data.Symbol_File);
4569 if Name_Len > 0 then
4571 -- We do not need to pass a Directory to
4572 -- Normalize_Pathname, since the path_information
4573 -- already contains absolute information.
4575 Symb_Path : constant String :=
4578 (Project.Object_Directory.Name) &
4579 Name_Buffer (1 .. Name_Len),
4582 Opt.Follow_Links_For_Files);
4583 Ref_Path : constant String :=
4586 (Project.Symbol_Data.Reference),
4589 Opt.Follow_Links_For_Files);
4591 if Symb_Path = Ref_Path then
4594 "library reference symbol file and library" &
4595 " symbol file cannot be the same file",
4596 Lib_Ref_Symbol_File.Location, Data);
4604 end Check_Stand_Alone_Library;
4606 ----------------------------
4607 -- Compute_Directory_Last --
4608 ----------------------------
4610 function Compute_Directory_Last (Dir : String) return Natural is
4613 and then (Dir (Dir'Last - 1) = Directory_Separator
4615 Dir (Dir'Last - 1) = '/')
4617 return Dir'Last - 1;
4621 end Compute_Directory_Last;
4628 (Project : Project_Id;
4630 Flag_Location : Source_Ptr;
4631 Data : Tree_Processing_Data)
4633 Real_Location : Source_Ptr := Flag_Location;
4634 Error_Buffer : String (1 .. 5_000);
4635 Error_Last : Natural := 0;
4636 Name_Number : Natural := 0;
4637 File_Number : Natural := 0;
4638 First : Positive := Msg'First;
4641 procedure Add (C : Character);
4642 -- Add a character to the buffer
4644 procedure Add (S : String);
4645 -- Add a string to the buffer
4648 -- Add a name to the buffer
4651 -- Add a file name to the buffer
4657 procedure Add (C : Character) is
4659 Error_Last := Error_Last + 1;
4660 Error_Buffer (Error_Last) := C;
4663 procedure Add (S : String) is
4665 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
4666 Error_Last := Error_Last + S'Length;
4673 procedure Add_File is
4674 File : File_Name_Type;
4678 File_Number := File_Number + 1;
4682 File := Err_Vars.Error_Msg_File_1;
4684 File := Err_Vars.Error_Msg_File_2;
4686 File := Err_Vars.Error_Msg_File_3;
4691 Get_Name_String (File);
4692 Add (Name_Buffer (1 .. Name_Len));
4700 procedure Add_Name is
4705 Name_Number := Name_Number + 1;
4709 Name := Err_Vars.Error_Msg_Name_1;
4711 Name := Err_Vars.Error_Msg_Name_2;
4713 Name := Err_Vars.Error_Msg_Name_3;
4718 Get_Name_String (Name);
4719 Add (Name_Buffer (1 .. Name_Len));
4723 -- Start of processing for Error_Msg
4726 -- Display the error message in the traces so that it appears in the
4727 -- correct location in the traces (otherwise error messages are only
4728 -- displayed at the end and it is difficult to see when they were
4731 if Current_Verbosity = High then
4732 Write_Line ("ERROR: " & Msg);
4735 -- If location of error is unknown, use the location of the project
4737 if Real_Location = No_Location then
4738 Real_Location := Project.Location;
4741 if Data.Flags.Report_Error = null then
4742 Prj.Err.Error_Msg (Msg, Real_Location);
4746 -- Ignore continuation character
4748 if Msg (First) = '\' then
4752 if Msg (First) = '?' then
4756 elsif Msg (First) = '<' then
4759 if Err_Vars.Error_Msg_Warn then
4765 while Index <= Msg'Last loop
4766 if Msg (Index) = '{' then
4769 elsif Msg (Index) = '%' then
4770 if Index < Msg'Last and then Msg (Index + 1) = '%' then
4784 Data.Flags.Report_Error
4785 (Error_Buffer (1 .. Error_Last), Project, Data.Tree);
4788 ---------------------
4789 -- Get_Directories --
4790 ---------------------
4792 procedure Get_Directories
4793 (Project : Project_Id;
4794 Data : in out Tree_Processing_Data)
4796 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
4797 (Header_Num => Header_Num,
4799 No_Element => False,
4803 -- Hash table stores recursive source directories, to avoid looking
4804 -- several times, and to avoid cycles that may be introduced by symbolic
4807 Visited : Recursive_Dirs.Instance;
4809 Object_Dir : constant Variable_Value :=
4811 (Name_Object_Dir, Project.Decl.Attributes, Data.Tree);
4813 Exec_Dir : constant Variable_Value :=
4815 (Name_Exec_Dir, Project.Decl.Attributes, Data.Tree);
4817 Source_Dirs : constant Variable_Value :=
4819 (Name_Source_Dirs, Project.Decl.Attributes, Data.Tree);
4821 Excluded_Source_Dirs : constant Variable_Value :=
4823 (Name_Excluded_Source_Dirs,
4824 Project.Decl.Attributes,
4827 Source_Files : constant Variable_Value :=
4830 Project.Decl.Attributes, Data.Tree);
4832 Last_Source_Dir : String_List_Id := Nil_String;
4834 Languages : constant Variable_Value :=
4836 (Name_Languages, Project.Decl.Attributes, Data.Tree);
4838 procedure Find_Source_Dirs
4839 (From : File_Name_Type;
4840 Location : Source_Ptr;
4841 Removed : Boolean := False);
4842 -- Find one or several source directories, and add (or remove, if
4843 -- Removed is True) them to list of source directories of the project.
4845 ----------------------
4846 -- Find_Source_Dirs --
4847 ----------------------
4849 procedure Find_Source_Dirs
4850 (From : File_Name_Type;
4851 Location : Source_Ptr;
4852 Removed : Boolean := False)
4854 Directory : constant String := Get_Name_String (From);
4855 Element : String_Element;
4857 procedure Recursive_Find_Dirs (Path : Name_Id);
4858 -- Find all the subdirectories (recursively) of Path and add them
4859 -- to the list of source directories of the project.
4861 -------------------------
4862 -- Recursive_Find_Dirs --
4863 -------------------------
4865 procedure Recursive_Find_Dirs (Path : Name_Id) is
4867 Name : String (1 .. 250);
4869 List : String_List_Id;
4870 Prev : String_List_Id;
4871 Element : String_Element;
4872 Found : Boolean := False;
4874 Non_Canonical_Path : Name_Id := No_Name;
4875 Canonical_Path : Name_Id := No_Name;
4877 The_Path : constant String :=
4879 (Get_Name_String (Path),
4881 Get_Name_String (Project.Directory.Display_Name),
4882 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4883 Directory_Separator;
4885 The_Path_Last : constant Natural :=
4886 Compute_Directory_Last (The_Path);
4889 Name_Len := The_Path_Last - The_Path'First + 1;
4890 Name_Buffer (1 .. Name_Len) :=
4891 The_Path (The_Path'First .. The_Path_Last);
4892 Non_Canonical_Path := Name_Find;
4894 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4896 -- To avoid processing the same directory several times, check
4897 -- if the directory is already in Recursive_Dirs. If it is, then
4898 -- there is nothing to do, just return. If it is not, put it there
4899 -- and continue recursive processing.
4902 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4905 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4909 -- Check if directory is already in list
4911 List := Project.Source_Dirs;
4913 while List /= Nil_String loop
4914 Element := Data.Tree.String_Elements.Table (List);
4916 if Element.Value /= No_Name then
4917 Found := Element.Value = Canonical_Path;
4922 List := Element.Next;
4925 -- If directory is not already in list, put it there
4927 if (not Removed) and (not Found) then
4928 if Current_Verbosity = High then
4930 Write_Line (The_Path (The_Path'First .. The_Path_Last));
4933 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4935 (Value => Canonical_Path,
4936 Display_Value => Non_Canonical_Path,
4937 Location => No_Location,
4942 -- Case of first source directory
4944 if Last_Source_Dir = Nil_String then
4945 Project.Source_Dirs :=
4946 String_Element_Table.Last (Data.Tree.String_Elements);
4948 -- Here we already have source directories
4951 -- Link the previous last to the new one
4953 Data.Tree.String_Elements.Table
4954 (Last_Source_Dir).Next :=
4955 String_Element_Table.Last (Data.Tree.String_Elements);
4958 -- And register this source directory as the new last
4961 String_Element_Table.Last (Data.Tree.String_Elements);
4962 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4964 elsif Removed and Found then
4965 if Prev = Nil_String then
4966 Project.Source_Dirs :=
4967 Data.Tree.String_Elements.Table (List).Next;
4969 Data.Tree.String_Elements.Table (Prev).Next :=
4970 Data.Tree.String_Elements.Table (List).Next;
4974 -- Now look for subdirectories. We do that even when this
4975 -- directory is already in the list, because some of its
4976 -- subdirectories may not be in the list yet.
4978 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4981 Read (Dir, Name, Last);
4984 if Name (1 .. Last) /= "."
4985 and then Name (1 .. Last) /= ".."
4987 -- Avoid . and .. directories
4989 if Current_Verbosity = High then
4990 Write_Str (" Checking ");
4991 Write_Line (Name (1 .. Last));
4995 Path_Name : constant String :=
4997 (Name => Name (1 .. Last),
4999 The_Path (The_Path'First .. The_Path_Last),
5000 Resolve_Links => Opt.Follow_Links_For_Dirs,
5001 Case_Sensitive => True);
5004 if Is_Directory (Path_Name) then
5006 -- We have found a new subdirectory, call self
5008 Name_Len := Path_Name'Length;
5009 Name_Buffer (1 .. Name_Len) := Path_Name;
5010 Recursive_Find_Dirs (Name_Find);
5019 when Directory_Error =>
5021 end Recursive_Find_Dirs;
5023 -- Start of processing for Find_Source_Dirs
5026 if Current_Verbosity = High and then not Removed then
5027 Write_Str ("Find_Source_Dirs (""");
5028 Write_Str (Directory);
5032 -- First, check if we are looking for a directory tree, indicated
5033 -- by "/**" at the end.
5035 if Directory'Length >= 3
5036 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5037 and then (Directory (Directory'Last - 2) = '/'
5039 Directory (Directory'Last - 2) = Directory_Separator)
5042 Project.Known_Order_Of_Source_Dirs := False;
5045 Name_Len := Directory'Length - 3;
5047 if Name_Len = 0 then
5049 -- Case of "/**": all directories in file system
5052 Name_Buffer (1) := Directory (Directory'First);
5055 Name_Buffer (1 .. Name_Len) :=
5056 Directory (Directory'First .. Directory'Last - 3);
5059 if Current_Verbosity = High then
5060 Write_Str ("Looking for all subdirectories of """);
5061 Write_Str (Name_Buffer (1 .. Name_Len));
5066 Base_Dir : constant File_Name_Type := Name_Find;
5067 Root_Dir : constant String :=
5069 (Name => Get_Name_String (Base_Dir),
5072 (Project.Directory.Display_Name),
5073 Resolve_Links => False,
5074 Case_Sensitive => True);
5077 if Root_Dir'Length = 0 then
5078 Err_Vars.Error_Msg_File_1 := Base_Dir;
5080 if Location = No_Location then
5083 "{ is not a valid directory.",
5084 Project.Location, Data);
5088 "{ is not a valid directory.",
5093 -- We have an existing directory, we register it and all of
5094 -- its subdirectories.
5096 if Current_Verbosity = High then
5097 Write_Line ("Looking for source directories:");
5100 Name_Len := Root_Dir'Length;
5101 Name_Buffer (1 .. Name_Len) := Root_Dir;
5102 Recursive_Find_Dirs (Name_Find);
5104 if Current_Verbosity = High then
5105 Write_Line ("End of looking for source directories.");
5110 -- We have a single directory
5114 Path_Name : Path_Information;
5115 List : String_List_Id;
5116 Prev : String_List_Id;
5117 Dir_Exists : Boolean;
5121 (Project => Project,
5124 Dir_Exists => Dir_Exists,
5126 Must_Exist => False);
5128 if not Dir_Exists then
5129 Err_Vars.Error_Msg_File_1 := From;
5131 if Location = No_Location then
5134 "{ is not a valid directory",
5135 Project.Location, Data);
5139 "{ is not a valid directory",
5145 Path : constant String :=
5146 Get_Name_String (Path_Name.Name);
5147 Last_Path : constant Natural :=
5148 Compute_Directory_Last (Path);
5150 Display_Path : constant String :=
5152 (Path_Name.Display_Name);
5153 Last_Display_Path : constant Natural :=
5154 Compute_Directory_Last
5156 Display_Path_Id : Name_Id;
5160 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5161 Path_Id := Name_Find;
5163 Add_Str_To_Name_Buffer
5165 (Display_Path'First .. Last_Display_Path));
5166 Display_Path_Id := Name_Find;
5170 -- As it is an existing directory, we add it to the
5171 -- list of directories.
5173 String_Element_Table.Increment_Last
5174 (Data.Tree.String_Elements);
5178 Display_Value => Display_Path_Id,
5179 Location => No_Location,
5181 Next => Nil_String);
5183 if Last_Source_Dir = Nil_String then
5185 -- This is the first source directory
5187 Project.Source_Dirs := String_Element_Table.Last
5188 (Data.Tree.String_Elements);
5191 -- We already have source directories, link the
5192 -- previous last to the new one.
5194 Data.Tree.String_Elements.Table
5195 (Last_Source_Dir).Next :=
5196 String_Element_Table.Last
5197 (Data.Tree.String_Elements);
5200 -- And register this source directory as the new last
5202 Last_Source_Dir := String_Element_Table.Last
5203 (Data.Tree.String_Elements);
5204 Data.Tree.String_Elements.Table
5205 (Last_Source_Dir) := Element;
5208 -- Remove source dir, if present
5212 -- Look for source dir in current list
5214 List := Project.Source_Dirs;
5215 while List /= Nil_String loop
5216 Element := Data.Tree.String_Elements.Table (List);
5217 exit when Element.Value = Path_Id;
5219 List := Element.Next;
5222 if List /= Nil_String then
5223 -- Source dir was found, remove it from the list
5225 if Prev = Nil_String then
5226 Project.Source_Dirs :=
5227 Data.Tree.String_Elements.Table (List).Next;
5230 Data.Tree.String_Elements.Table (Prev).Next :=
5231 Data.Tree.String_Elements.Table (List).Next;
5240 Recursive_Dirs.Reset (Visited);
5241 end Find_Source_Dirs;
5243 -- Start of processing for Get_Directories
5245 Dir_Exists : Boolean;
5248 if Current_Verbosity = High then
5249 Write_Line ("Starting to look for directories");
5252 -- Set the object directory to its default which may be nil, if there
5253 -- is no sources in the project.
5255 if (((not Source_Files.Default)
5256 and then Source_Files.Values = Nil_String)
5258 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5260 ((not Languages.Default) and then Languages.Values = Nil_String))
5261 and then Project.Extends = No_Project
5263 Project.Object_Directory := No_Path_Information;
5265 Project.Object_Directory := Project.Directory;
5268 -- Check the object directory
5270 if Object_Dir.Value /= Empty_String then
5271 Get_Name_String (Object_Dir.Value);
5273 if Name_Len = 0 then
5276 "Object_Dir cannot be empty",
5277 Object_Dir.Location, Data);
5280 -- We check that the specified object directory does exist.
5281 -- However, even when it doesn't exist, we set it to a default
5282 -- value. This is for the benefit of tools that recover from
5283 -- errors; for example, these tools could create the non existent
5284 -- directory. We always return an absolute directory name though.
5288 File_Name_Type (Object_Dir.Value),
5289 Path => Project.Object_Directory,
5291 Dir_Exists => Dir_Exists,
5293 Location => Object_Dir.Location,
5294 Must_Exist => False,
5295 Externally_Built => Project.Externally_Built);
5298 and then not Project.Externally_Built
5300 -- The object directory does not exist, report an error if
5301 -- the project is not externally built.
5303 Err_Vars.Error_Msg_File_1 :=
5304 File_Name_Type (Object_Dir.Value);
5307 "object directory { not found",
5308 Project.Location, Data);
5312 elsif Project.Object_Directory /= No_Path_Information
5313 and then Subdirs /= null
5316 Name_Buffer (1) := '.';
5320 Path => Project.Object_Directory,
5322 Dir_Exists => Dir_Exists,
5324 Location => Object_Dir.Location,
5325 Externally_Built => Project.Externally_Built);
5328 if Current_Verbosity = High then
5329 if Project.Object_Directory = No_Path_Information then
5330 Write_Line ("No object directory");
5333 ("Object directory",
5334 Get_Name_String (Project.Object_Directory.Display_Name));
5338 -- Check the exec directory
5340 -- We set the object directory to its default
5342 Project.Exec_Directory := Project.Object_Directory;
5344 if Exec_Dir.Value /= Empty_String then
5345 Get_Name_String (Exec_Dir.Value);
5347 if Name_Len = 0 then
5350 "Exec_Dir cannot be empty",
5351 Exec_Dir.Location, Data);
5354 -- We check that the specified exec directory does exist
5358 File_Name_Type (Exec_Dir.Value),
5359 Path => Project.Exec_Directory,
5360 Dir_Exists => Dir_Exists,
5363 Location => Exec_Dir.Location,
5364 Externally_Built => Project.Externally_Built);
5366 if not Dir_Exists then
5367 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5370 "exec directory { not found",
5371 Project.Location, Data);
5376 if Current_Verbosity = High then
5377 if Project.Exec_Directory = No_Path_Information then
5378 Write_Line ("No exec directory");
5380 Write_Str ("Exec directory: """);
5381 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5386 -- Look for the source directories
5388 if Current_Verbosity = High then
5389 Write_Line ("Starting to look for source directories");
5392 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5394 if (not Source_Files.Default)
5395 and then Source_Files.Values = Nil_String
5397 Project.Source_Dirs := Nil_String;
5399 if Project.Qualifier = Standard then
5402 "a standard project cannot have no sources",
5403 Source_Files.Location, Data);
5406 elsif Source_Dirs.Default then
5408 -- No Source_Dirs specified: the single source directory is the one
5409 -- containing the project file.
5411 String_Element_Table.Append (Data.Tree.String_Elements,
5412 (Value => Name_Id (Project.Directory.Name),
5413 Display_Value => Name_Id (Project.Directory.Display_Name),
5414 Location => No_Location,
5419 Project.Source_Dirs :=
5420 String_Element_Table.Last (Data.Tree.String_Elements);
5422 if Current_Verbosity = High then
5424 ("Default source directory",
5425 Get_Name_String (Project.Directory.Display_Name));
5428 elsif Source_Dirs.Values = Nil_String then
5429 if Project.Qualifier = Standard then
5432 "a standard project cannot have no source directories",
5433 Source_Dirs.Location, Data);
5436 Project.Source_Dirs := Nil_String;
5440 Source_Dir : String_List_Id;
5441 Element : String_Element;
5444 -- Process the source directories for each element of the list
5446 Source_Dir := Source_Dirs.Values;
5447 while Source_Dir /= Nil_String loop
5448 Element := Data.Tree.String_Elements.Table (Source_Dir);
5450 (File_Name_Type (Element.Value), Element.Location);
5451 Source_Dir := Element.Next;
5456 if not Excluded_Source_Dirs.Default
5457 and then Excluded_Source_Dirs.Values /= Nil_String
5460 Source_Dir : String_List_Id;
5461 Element : String_Element;
5464 -- Process the source directories for each element of the list
5466 Source_Dir := Excluded_Source_Dirs.Values;
5467 while Source_Dir /= Nil_String loop
5468 Element := Data.Tree.String_Elements.Table (Source_Dir);
5470 (File_Name_Type (Element.Value),
5473 Source_Dir := Element.Next;
5478 if Current_Verbosity = High then
5479 Write_Line ("Putting source directories in canonical cases");
5483 Current : String_List_Id := Project.Source_Dirs;
5484 Element : String_Element;
5487 while Current /= Nil_String loop
5488 Element := Data.Tree.String_Elements.Table (Current);
5489 if Element.Value /= No_Name then
5491 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5492 Data.Tree.String_Elements.Table (Current) := Element;
5495 Current := Element.Next;
5498 end Get_Directories;
5505 (Project : Project_Id;
5506 Data : in out Tree_Processing_Data)
5508 Mains : constant Variable_Value :=
5510 (Name_Main, Project.Decl.Attributes, Data.Tree);
5511 List : String_List_Id;
5512 Elem : String_Element;
5515 Project.Mains := Mains.Values;
5517 -- If no Mains were specified, and if we are an extending project,
5518 -- inherit the Mains from the project we are extending.
5520 if Mains.Default then
5521 if not Project.Library and then Project.Extends /= No_Project then
5522 Project.Mains := Project.Extends.Mains;
5525 -- In a library project file, Main cannot be specified
5527 elsif Project.Library then
5530 "a library project file cannot have Main specified",
5531 Mains.Location, Data);
5534 List := Mains.Values;
5535 while List /= Nil_String loop
5536 Elem := Data.Tree.String_Elements.Table (List);
5538 if Length_Of_Name (Elem.Value) = 0 then
5541 "?a main cannot have an empty name",
5542 Elem.Location, Data);
5551 ---------------------------
5552 -- Get_Sources_From_File --
5553 ---------------------------
5555 procedure Get_Sources_From_File
5557 Location : Source_Ptr;
5558 Project : in out Project_Processing_Data;
5559 Data : in out Tree_Processing_Data)
5561 File : Prj.Util.Text_File;
5562 Line : String (1 .. 250);
5564 Source_Name : File_Name_Type;
5565 Name_Loc : Name_Location;
5568 if Current_Verbosity = High then
5569 Write_Str ("Opening """);
5576 Prj.Util.Open (File, Path);
5578 if not Prj.Util.Is_Valid (File) then
5579 Error_Msg (Project.Project, "file does not exist", Location, Data);
5582 -- Read the lines one by one
5584 while not Prj.Util.End_Of_File (File) loop
5585 Prj.Util.Get_Line (File, Line, Last);
5587 -- A non empty, non comment line should contain a file name
5590 and then (Last = 1 or else Line (1 .. 2) /= "--")
5593 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5594 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5595 Source_Name := Name_Find;
5597 -- Check that there is no directory information
5599 for J in 1 .. Last loop
5600 if Line (J) = '/' or else Line (J) = Directory_Separator then
5601 Error_Msg_File_1 := Source_Name;
5604 "file name cannot include directory information ({)",
5610 Name_Loc := Source_Names_Htable.Get
5611 (Project.Source_Names, Source_Name);
5613 if Name_Loc = No_Name_Location then
5615 (Name => Source_Name,
5616 Location => Location,
5617 Source => No_Source,
5621 Source_Names_Htable.Set
5622 (Project.Source_Names, Source_Name, Name_Loc);
5626 Prj.Util.Close (File);
5629 end Get_Sources_From_File;
5631 -----------------------
5632 -- Compute_Unit_Name --
5633 -----------------------
5635 procedure Compute_Unit_Name
5636 (File_Name : File_Name_Type;
5637 Naming : Lang_Naming_Data;
5638 Kind : out Source_Kind;
5640 Project : Project_Processing_Data;
5641 In_Tree : Project_Tree_Ref)
5643 Filename : constant String := Get_Name_String (File_Name);
5644 Last : Integer := Filename'Last;
5649 Unit_Except : Unit_Exception;
5650 Masked : Boolean := False;
5656 if Naming.Separate_Suffix = No_File
5657 or else Naming.Body_Suffix = No_File
5658 or else Naming.Spec_Suffix = No_File
5663 if Naming.Dot_Replacement = No_File then
5664 if Current_Verbosity = High then
5665 Write_Line (" No dot_replacement specified");
5671 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5672 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5673 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5675 -- Choose the longest suffix that matches. If there are several matches,
5676 -- give priority to specs, then bodies, then separates.
5678 if Naming.Separate_Suffix /= Naming.Body_Suffix
5679 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5681 Last := Filename'Last - Sep_Len;
5685 if Filename'Last - Body_Len <= Last
5686 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5688 Last := Natural'Min (Last, Filename'Last - Body_Len);
5692 if Filename'Last - Spec_Len <= Last
5693 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5695 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5699 if Last = Filename'Last then
5700 if Current_Verbosity = High then
5701 Write_Line (" no matching suffix");
5707 -- Check that the casing matches
5709 if File_Names_Case_Sensitive then
5710 case Naming.Casing is
5711 when All_Lower_Case =>
5712 for J in Filename'First .. Last loop
5713 if Is_Letter (Filename (J))
5714 and then not Is_Lower (Filename (J))
5716 if Current_Verbosity = High then
5717 Write_Line (" Invalid casing");
5724 when All_Upper_Case =>
5725 for J in Filename'First .. Last loop
5726 if Is_Letter (Filename (J))
5727 and then not Is_Upper (Filename (J))
5729 if Current_Verbosity = High then
5730 Write_Line (" Invalid casing");
5737 when Mixed_Case | Unknown =>
5742 -- If Dot_Replacement is not a single dot, then there should not
5743 -- be any dot in the name.
5746 Dot_Repl : constant String :=
5747 Get_Name_String (Naming.Dot_Replacement);
5750 if Dot_Repl /= "." then
5751 for Index in Filename'First .. Last loop
5752 if Filename (Index) = '.' then
5753 if Current_Verbosity = High then
5754 Write_Line (" Invalid name, contains dot");
5761 Replace_Into_Name_Buffer
5762 (Filename (Filename'First .. Last), Dot_Repl, '.');
5765 Name_Len := Last - Filename'First + 1;
5766 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5768 (Source => Name_Buffer (1 .. Name_Len),
5769 Mapping => Lower_Case_Map);
5773 -- In the standard GNAT naming scheme, check for special cases: children
5774 -- or separates of A, G, I or S, and run time sources.
5776 if Is_Standard_GNAT_Naming (Naming)
5777 and then Name_Len >= 3
5780 S1 : constant Character := Name_Buffer (1);
5781 S2 : constant Character := Name_Buffer (2);
5782 S3 : constant Character := Name_Buffer (3);
5790 -- Children or separates of packages A, G, I or S. These names
5791 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5792 -- versions (x__... and x~...) are allowed in all platforms,
5793 -- because it is not possible to know the platform before
5794 -- processing of the project files.
5796 if S2 = '_' and then S3 = '_' then
5797 Name_Buffer (2) := '.';
5798 Name_Buffer (3 .. Name_Len - 1) :=
5799 Name_Buffer (4 .. Name_Len);
5800 Name_Len := Name_Len - 1;
5803 Name_Buffer (2) := '.';
5807 -- If it is potentially a run time source
5815 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5816 -- that this is a valid unit name
5818 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5820 -- If there is a naming exception for the same unit, the file is not
5821 -- a source for the unit.
5823 if Unit /= No_Name then
5825 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5828 Masked := Unit_Except.Spec /= No_File
5830 Unit_Except.Spec /= File_Name;
5832 Masked := Unit_Except.Impl /= No_File
5834 Unit_Except.Impl /= File_Name;
5838 if Current_Verbosity = High then
5839 Write_Str (" """ & Filename & """ contains the ");
5842 Write_Str ("spec of a unit found in """);
5843 Write_Str (Get_Name_String (Unit_Except.Spec));
5845 Write_Str ("body of a unit found in """);
5846 Write_Str (Get_Name_String (Unit_Except.Impl));
5849 Write_Line (""" (ignored)");
5857 and then Current_Verbosity = High
5860 when Spec => Write_Str (" spec of ");
5861 when Impl => Write_Str (" body of ");
5862 when Sep => Write_Str (" sep of ");
5865 Write_Line (Get_Name_String (Unit));
5867 end Compute_Unit_Name;
5869 --------------------------
5870 -- Check_Illegal_Suffix --
5871 --------------------------
5873 procedure Check_Illegal_Suffix
5874 (Project : Project_Id;
5875 Suffix : File_Name_Type;
5876 Dot_Replacement : File_Name_Type;
5877 Attribute_Name : String;
5878 Location : Source_Ptr;
5879 Data : in out Tree_Processing_Data)
5881 Suffix_Str : constant String := Get_Name_String (Suffix);
5884 if Suffix_Str'Length = 0 then
5890 elsif Index (Suffix_Str, ".") = 0 then
5891 Err_Vars.Error_Msg_File_1 := Suffix;
5894 "{ is illegal for " & Attribute_Name & ": must have a dot",
5899 -- Case of dot replacement is a single dot, and first character of
5900 -- suffix is also a dot.
5902 if Dot_Replacement /= No_File
5903 and then Get_Name_String (Dot_Replacement) = "."
5904 and then Suffix_Str (Suffix_Str'First) = '.'
5906 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5908 -- If there are multiple dots in the name
5910 if Suffix_Str (Index) = '.' then
5912 -- It is illegal to have a letter following the initial dot
5914 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5915 Err_Vars.Error_Msg_File_1 := Suffix;
5918 "{ is illegal for " & Attribute_Name
5919 & ": ambiguous prefix when Dot_Replacement is a dot",
5926 end Check_Illegal_Suffix;
5928 ----------------------
5929 -- Locate_Directory --
5930 ----------------------
5932 procedure Locate_Directory
5933 (Project : Project_Id;
5934 Name : File_Name_Type;
5935 Path : out Path_Information;
5936 Dir_Exists : out Boolean;
5937 Data : in out Tree_Processing_Data;
5938 Create : String := "";
5939 Location : Source_Ptr := No_Location;
5940 Must_Exist : Boolean := True;
5941 Externally_Built : Boolean := False)
5943 Parent : constant Path_Name_Type :=
5944 Project.Directory.Display_Name;
5945 The_Parent : constant String :=
5946 Get_Name_String (Parent);
5947 The_Parent_Last : constant Natural :=
5948 Compute_Directory_Last (The_Parent);
5949 Full_Name : File_Name_Type;
5950 The_Name : File_Name_Type;
5953 Get_Name_String (Name);
5955 -- Add Subdirs.all if it is a directory that may be created and
5956 -- Subdirs is not null;
5958 if Create /= "" and then Subdirs /= null then
5959 if Name_Buffer (Name_Len) /= Directory_Separator then
5960 Add_Char_To_Name_Buffer (Directory_Separator);
5963 Add_Str_To_Name_Buffer (Subdirs.all);
5966 -- Convert '/' to directory separator (for Windows)
5968 for J in 1 .. Name_Len loop
5969 if Name_Buffer (J) = '/' then
5970 Name_Buffer (J) := Directory_Separator;
5974 The_Name := Name_Find;
5976 if Current_Verbosity = High then
5977 Write_Str ("Locate_Directory (""");
5978 Write_Str (Get_Name_String (The_Name));
5979 Write_Str (""", """);
5980 Write_Str (The_Parent);
5984 Path := No_Path_Information;
5985 Dir_Exists := False;
5987 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5988 Full_Name := The_Name;
5992 Add_Str_To_Name_Buffer
5993 (The_Parent (The_Parent'First .. The_Parent_Last));
5994 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5995 Full_Name := Name_Find;
5999 Full_Path_Name : String_Access :=
6000 new String'(Get_Name_String (Full_Name));
6003 if (Setup_Projects or else Subdirs /= null)
6004 and then Create'Length > 0
6006 if not Is_Directory (Full_Path_Name.all) then
6008 -- If project is externally built, do not create a subdir,
6009 -- use the specified directory, without the subdir.
6011 if Externally_Built then
6012 if Is_Absolute_Path (Get_Name_String (Name)) then
6013 Get_Name_String (Name);
6017 Add_Str_To_Name_Buffer
6018 (The_Parent (The_Parent'First .. The_Parent_Last));
6019 Add_Str_To_Name_Buffer (Get_Name_String (Name));
6022 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
6026 Create_Path (Full_Path_Name.all);
6028 if not Quiet_Output then
6030 Write_Str (" directory """);
6031 Write_Str (Full_Path_Name.all);
6032 Write_Str (""" created for project ");
6033 Write_Line (Get_Name_String (Project.Name));
6040 "could not create " & Create &
6041 " directory " & Full_Path_Name.all,
6048 Dir_Exists := Is_Directory (Full_Path_Name.all);
6050 if not Must_Exist or else Dir_Exists then
6052 Normed : constant String :=
6054 (Full_Path_Name.all,
6056 The_Parent (The_Parent'First .. The_Parent_Last),
6057 Resolve_Links => False,
6058 Case_Sensitive => True);
6060 Canonical_Path : constant String :=
6065 (The_Parent'First .. The_Parent_Last),
6067 Opt.Follow_Links_For_Dirs,
6068 Case_Sensitive => False);
6071 Name_Len := Normed'Length;
6072 Name_Buffer (1 .. Name_Len) := Normed;
6074 -- Directories should always end with a directory separator
6076 if Name_Buffer (Name_Len) /= Directory_Separator then
6077 Add_Char_To_Name_Buffer (Directory_Separator);
6080 Path.Display_Name := Name_Find;
6082 Name_Len := Canonical_Path'Length;
6083 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6085 if Name_Buffer (Name_Len) /= Directory_Separator then
6086 Add_Char_To_Name_Buffer (Directory_Separator);
6089 Path.Name := Name_Find;
6093 Free (Full_Path_Name);
6095 end Locate_Directory;
6097 ---------------------------
6098 -- Find_Excluded_Sources --
6099 ---------------------------
6101 procedure Find_Excluded_Sources
6102 (Project : in out Project_Processing_Data;
6103 Data : in out Tree_Processing_Data)
6105 Excluded_Source_List_File : constant Variable_Value :=
6107 (Name_Excluded_Source_List_File,
6108 Project.Project.Decl.Attributes,
6110 Excluded_Sources : Variable_Value := Util.Value_Of
6111 (Name_Excluded_Source_Files,
6112 Project.Project.Decl.Attributes,
6115 Current : String_List_Id;
6116 Element : String_Element;
6117 Location : Source_Ptr;
6118 Name : File_Name_Type;
6119 File : Prj.Util.Text_File;
6120 Line : String (1 .. 300);
6122 Locally_Removed : Boolean := False;
6125 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6127 if Excluded_Sources.Default then
6128 Locally_Removed := True;
6131 (Name_Locally_Removed_Files,
6132 Project.Project.Decl.Attributes, Data.Tree);
6135 -- If there are excluded sources, put them in the table
6137 if not Excluded_Sources.Default then
6138 if not Excluded_Source_List_File.Default then
6139 if Locally_Removed then
6142 "?both attributes Locally_Removed_Files and " &
6143 "Excluded_Source_List_File are present",
6144 Excluded_Source_List_File.Location, Data);
6148 "?both attributes Excluded_Source_Files and " &
6149 "Excluded_Source_List_File are present",
6150 Excluded_Source_List_File.Location, Data);
6154 Current := Excluded_Sources.Values;
6155 while Current /= Nil_String loop
6156 Element := Data.Tree.String_Elements.Table (Current);
6157 Name := Canonical_Case_File_Name (Element.Value);
6159 -- If the element has no location, then use the location of
6160 -- Excluded_Sources to report possible errors.
6162 if Element.Location = No_Location then
6163 Location := Excluded_Sources.Location;
6165 Location := Element.Location;
6168 Excluded_Sources_Htable.Set
6169 (Project.Excluded, Name, (Name, False, Location));
6170 Current := Element.Next;
6173 elsif not Excluded_Source_List_File.Default then
6174 Location := Excluded_Source_List_File.Location;
6177 Source_File_Path_Name : constant String :=
6180 (Excluded_Source_List_File.Value),
6181 Project.Project.Directory.Name);
6184 if Source_File_Path_Name'Length = 0 then
6185 Err_Vars.Error_Msg_File_1 :=
6186 File_Name_Type (Excluded_Source_List_File.Value);
6189 "file with excluded sources { does not exist",
6190 Excluded_Source_List_File.Location, Data);
6195 Prj.Util.Open (File, Source_File_Path_Name);
6197 if not Prj.Util.Is_Valid (File) then
6199 (Project.Project, "file does not exist", Location, Data);
6201 -- Read the lines one by one
6203 while not Prj.Util.End_Of_File (File) loop
6204 Prj.Util.Get_Line (File, Line, Last);
6206 -- Non empty, non comment line should contain a file name
6209 and then (Last = 1 or else Line (1 .. 2) /= "--")
6212 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6213 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6216 -- Check that there is no directory information
6218 for J in 1 .. Last loop
6220 or else Line (J) = Directory_Separator
6222 Error_Msg_File_1 := Name;
6225 "file name cannot include " &
6226 "directory information ({)",
6232 Excluded_Sources_Htable.Set
6233 (Project.Excluded, Name, (Name, False, Location));
6237 Prj.Util.Close (File);
6242 end Find_Excluded_Sources;
6248 procedure Find_Sources
6249 (Project : in out Project_Processing_Data;
6250 Data : in out Tree_Processing_Data)
6252 Sources : constant Variable_Value :=
6255 Project.Project.Decl.Attributes,
6258 Source_List_File : constant Variable_Value :=
6260 (Name_Source_List_File,
6261 Project.Project.Decl.Attributes,
6264 Name_Loc : Name_Location;
6265 Has_Explicit_Sources : Boolean;
6268 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6270 (Source_List_File.Kind = Single,
6271 "Source_List_File is not a single string");
6273 Project.Source_List_File_Location := Source_List_File.Location;
6275 -- If the user has specified a Source_Files attribute
6277 if not Sources.Default then
6278 if not Source_List_File.Default then
6281 "?both attributes source_files and " &
6282 "source_list_file are present",
6283 Source_List_File.Location, Data);
6286 -- Sources is a list of file names
6289 Current : String_List_Id := Sources.Values;
6290 Element : String_Element;
6291 Location : Source_Ptr;
6292 Name : File_Name_Type;
6295 if Current = Nil_String then
6296 Project.Project.Languages := No_Language_Index;
6298 -- This project contains no source. For projects that don't
6299 -- extend other projects, this also means that there is no
6300 -- need for an object directory, if not specified.
6302 if Project.Project.Extends = No_Project
6303 and then Project.Project.Object_Directory =
6304 Project.Project.Directory
6306 Project.Project.Object_Directory := No_Path_Information;
6310 while Current /= Nil_String loop
6311 Element := Data.Tree.String_Elements.Table (Current);
6312 Name := Canonical_Case_File_Name (Element.Value);
6313 Get_Name_String (Element.Value);
6315 -- If the element has no location, then use the location of
6316 -- Sources to report possible errors.
6318 if Element.Location = No_Location then
6319 Location := Sources.Location;
6321 Location := Element.Location;
6324 -- Check that there is no directory information
6326 for J in 1 .. Name_Len loop
6327 if Name_Buffer (J) = '/'
6328 or else Name_Buffer (J) = Directory_Separator
6330 Error_Msg_File_1 := Name;
6333 "file name cannot include directory " &
6340 -- Check whether the file is already there: the same file name
6341 -- may be in the list. If the source is missing, the error will
6342 -- be on the first mention of the source file name.
6344 Name_Loc := Source_Names_Htable.Get
6345 (Project.Source_Names, Name);
6347 if Name_Loc = No_Name_Location then
6350 Location => Location,
6351 Source => No_Source,
6353 Source_Names_Htable.Set
6354 (Project.Source_Names, Name, Name_Loc);
6357 Current := Element.Next;
6360 Has_Explicit_Sources := True;
6363 -- If we have no Source_Files attribute, check the Source_List_File
6366 elsif not Source_List_File.Default then
6368 -- Source_List_File is the name of the file that contains the source
6372 Source_File_Path_Name : constant String :=
6374 (File_Name_Type (Source_List_File.Value),
6375 Project.Project.Directory.Name);
6378 Has_Explicit_Sources := True;
6380 if Source_File_Path_Name'Length = 0 then
6381 Err_Vars.Error_Msg_File_1 :=
6382 File_Name_Type (Source_List_File.Value);
6385 "file with sources { does not exist",
6386 Source_List_File.Location, Data);
6389 Get_Sources_From_File
6390 (Source_File_Path_Name, Source_List_File.Location,
6396 -- Neither Source_Files nor Source_List_File has been specified. Find
6397 -- all the files that satisfy the naming scheme in all the source
6400 Has_Explicit_Sources := False;
6406 For_All_Sources => Sources.Default and then Source_List_File.Default);
6408 -- Check if all exceptions have been found.
6412 Iter : Source_Iterator;
6415 Iter := For_Each_Source (Data.Tree, Project.Project);
6417 Source := Prj.Element (Iter);
6418 exit when Source = No_Source;
6420 if Source.Naming_Exception
6421 and then Source.Path = No_Path_Information
6423 if Source.Unit /= No_Unit_Index then
6425 -- For multi-unit source files, source_id gets duplicated
6426 -- once for every unit. Only the first source_id got its
6427 -- full path set. So if it isn't set for that first one,
6428 -- the file wasn't found. Otherwise we need to update for
6429 -- units after the first one.
6432 or else Source.Index = 1
6434 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6435 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6438 "source file %% for unit %% not found",
6443 Source.Path := Files_Htable.Get
6444 (Data.File_To_Source, Source.File).Path;
6446 if Current_Verbosity = High then
6447 if Source.Path /= No_Path_Information then
6448 Write_Line ("Setting full path for "
6449 & Get_Name_String (Source.File)
6450 & " at" & Source.Index'Img
6452 & Get_Name_String (Source.Path.Name));
6458 if Source.Path = No_Path_Information then
6459 Remove_Source (Source, No_Source);
6467 -- It is an error if a source file name in a source list or in a source
6468 -- list file is not found.
6470 if Has_Explicit_Sources then
6473 First_Error : Boolean;
6476 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6477 First_Error := True;
6478 while NL /= No_Name_Location loop
6479 if not NL.Found then
6480 Err_Vars.Error_Msg_File_1 := NL.Name;
6485 "source file { not found",
6487 First_Error := False;
6492 "\source file { not found",
6497 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6507 procedure Initialize
6508 (Data : out Tree_Processing_Data;
6509 Tree : Project_Tree_Ref;
6510 Flags : Prj.Processing_Flags)
6513 Files_Htable.Reset (Data.File_To_Source);
6515 Data.Flags := Flags;
6522 procedure Free (Data : in out Tree_Processing_Data) is
6524 Files_Htable.Reset (Data.File_To_Source);
6531 procedure Initialize
6532 (Data : in out Project_Processing_Data;
6533 Project : Project_Id)
6536 Data.Project := Project;
6543 procedure Free (Data : in out Project_Processing_Data) is
6545 Source_Names_Htable.Reset (Data.Source_Names);
6546 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6547 Excluded_Sources_Htable.Reset (Data.Excluded);
6550 -------------------------------
6551 -- Check_File_Naming_Schemes --
6552 -------------------------------
6554 procedure Check_File_Naming_Schemes
6555 (In_Tree : Project_Tree_Ref;
6556 Project : Project_Processing_Data;
6557 File_Name : File_Name_Type;
6558 Alternate_Languages : out Language_List;
6559 Language : out Language_Ptr;
6560 Display_Language_Name : out Name_Id;
6562 Lang_Kind : out Language_Kind;
6563 Kind : out Source_Kind)
6565 Filename : constant String := Get_Name_String (File_Name);
6566 Config : Language_Config;
6567 Tmp_Lang : Language_Ptr;
6569 Header_File : Boolean := False;
6570 -- True if we found at least one language for which the file is a header
6571 -- In such a case, we search for all possible languages where this is
6572 -- also a header (C and C++ for instance), since the file might be used
6573 -- for several such languages.
6575 procedure Check_File_Based_Lang;
6576 -- Does the naming scheme test for file-based languages. For those,
6577 -- there is no Unit. Just check if the file name has the implementation
6578 -- or, if it is specified, the template suffix of the language.
6580 -- Returns True if the file belongs to the current language and we
6581 -- should stop searching for matching languages. Not that a given header
6582 -- file could belong to several languages (C and C++ for instance). Thus
6583 -- if we found a header we'll check whether it matches other languages.
6585 ---------------------------
6586 -- Check_File_Based_Lang --
6587 ---------------------------
6589 procedure Check_File_Based_Lang is
6592 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6596 Language := Tmp_Lang;
6598 if Current_Verbosity = High then
6599 Write_Str (" implementation of language ");
6600 Write_Line (Get_Name_String (Display_Language_Name));
6603 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6604 if Current_Verbosity = High then
6605 Write_Str (" header of language ");
6606 Write_Line (Get_Name_String (Display_Language_Name));
6610 Alternate_Languages := new Language_List_Element'
6611 (Language => Language,
6612 Next => Alternate_Languages);
6615 Header_File := True;
6618 Language := Tmp_Lang;
6621 end Check_File_Based_Lang;
6623 -- Start of processing for Check_File_Naming_Schemes
6626 Language := No_Language_Index;
6627 Alternate_Languages := null;
6628 Display_Language_Name := No_Name;
6630 Lang_Kind := File_Based;
6633 Tmp_Lang := Project.Project.Languages;
6634 while Tmp_Lang /= No_Language_Index loop
6635 if Current_Verbosity = High then
6637 (" Testing language "
6638 & Get_Name_String (Tmp_Lang.Name)
6639 & " Header_File=" & Header_File'Img);
6642 Display_Language_Name := Tmp_Lang.Display_Name;
6643 Config := Tmp_Lang.Config;
6644 Lang_Kind := Config.Kind;
6648 Check_File_Based_Lang;
6649 exit when Kind = Impl;
6653 -- We know it belongs to a least a file_based language, no
6654 -- need to check unit-based ones.
6656 if not Header_File then
6658 (File_Name => File_Name,
6659 Naming => Config.Naming_Data,
6663 In_Tree => In_Tree);
6665 if Unit /= No_Name then
6666 Language := Tmp_Lang;
6672 Tmp_Lang := Tmp_Lang.Next;
6675 if Language = No_Language_Index
6676 and then Current_Verbosity = High
6678 Write_Line (" not a source of any language");
6680 end Check_File_Naming_Schemes;
6686 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6688 -- If the file was previously already associated with a unit, change it
6690 if Source.Unit /= null
6691 and then Source.Kind in Spec_Or_Body
6692 and then Source.Unit.File_Names (Source.Kind) /= null
6694 -- If we had another file referencing the same unit (for instance it
6695 -- was in an extended project), that source file is in fact invisible
6696 -- from now on, and in particular doesn't belong to the same unit.
6698 if Source.Unit.File_Names (Source.Kind) /= Source then
6699 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6702 Source.Unit.File_Names (Source.Kind) := null;
6705 Source.Kind := Kind;
6707 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6708 Source.Unit.File_Names (Source.Kind) := Source;
6716 procedure Check_File
6717 (Project : in out Project_Processing_Data;
6718 Data : in out Tree_Processing_Data;
6719 Path : Path_Name_Type;
6720 File_Name : File_Name_Type;
6721 Display_File_Name : File_Name_Type;
6722 Locally_Removed : Boolean;
6723 For_All_Sources : Boolean)
6725 Canonical_Path : constant Path_Name_Type :=
6727 (Canonical_Case_File_Name (Name_Id (Path)));
6729 Name_Loc : Name_Location :=
6730 Source_Names_Htable.Get
6731 (Project.Source_Names, File_Name);
6732 Check_Name : Boolean := False;
6733 Alternate_Languages : Language_List;
6734 Language : Language_Ptr;
6736 Src_Ind : Source_File_Index;
6738 Display_Language_Name : Name_Id;
6739 Lang_Kind : Language_Kind;
6740 Kind : Source_Kind := Spec;
6743 if Name_Loc = No_Name_Location then
6744 Check_Name := For_All_Sources;
6747 if Name_Loc.Found then
6749 -- Check if it is OK to have the same file name in several
6750 -- source directories.
6752 if not Project.Project.Known_Order_Of_Source_Dirs then
6753 Error_Msg_File_1 := File_Name;
6756 "{ is found in several source directories",
6757 Name_Loc.Location, Data);
6761 Name_Loc.Found := True;
6763 Source_Names_Htable.Set
6764 (Project.Source_Names, File_Name, Name_Loc);
6766 if Name_Loc.Source = No_Source then
6770 Name_Loc.Source.Path := (Canonical_Path, Path);
6772 Source_Paths_Htable.Set
6773 (Data.Tree.Source_Paths_HT,
6777 -- Check if this is a subunit
6779 if Name_Loc.Source.Unit /= No_Unit_Index
6780 and then Name_Loc.Source.Kind = Impl
6782 Src_Ind := Sinput.P.Load_Project_File
6783 (Get_Name_String (Canonical_Path));
6785 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6786 Override_Kind (Name_Loc.Source, Sep);
6791 (Data.File_To_Source, File_Name, Name_Loc.Source);
6797 Check_File_Naming_Schemes
6798 (In_Tree => Data.Tree,
6800 File_Name => File_Name,
6801 Alternate_Languages => Alternate_Languages,
6802 Language => Language,
6803 Display_Language_Name => Display_Language_Name,
6805 Lang_Kind => Lang_Kind,
6808 if Language = No_Language_Index then
6810 -- A file name in a list must be a source of a language
6812 if Data.Flags.Error_On_Unknown_Language
6813 and then Name_Loc.Found
6815 Error_Msg_File_1 := File_Name;
6818 "language unknown for {",
6819 Name_Loc.Location, Data);
6825 Project => Project.Project,
6826 Lang_Id => Language,
6829 Alternate_Languages => Alternate_Languages,
6830 File_Name => File_Name,
6831 Display_File => Display_File_Name,
6833 Path => (Canonical_Path, Path));
6835 if Source /= No_Source then
6836 Source.Locally_Removed := Locally_Removed;
6842 ------------------------
6843 -- Search_Directories --
6844 ------------------------
6846 procedure Search_Directories
6847 (Project : in out Project_Processing_Data;
6848 Data : in out Tree_Processing_Data;
6849 For_All_Sources : Boolean)
6851 Source_Dir : String_List_Id;
6852 Element : String_Element;
6854 Name : String (1 .. 1_000);
6856 File_Name : File_Name_Type;
6857 Display_File_Name : File_Name_Type;
6860 if Current_Verbosity = High then
6861 Write_Line ("Looking for sources:");
6864 -- Loop through subdirectories
6866 Source_Dir := Project.Project.Source_Dirs;
6867 while Source_Dir /= Nil_String loop
6869 Element := Data.Tree.String_Elements.Table (Source_Dir);
6870 if Element.Value /= No_Name then
6871 Get_Name_String (Element.Display_Value);
6874 Source_Directory : constant String :=
6875 Name_Buffer (1 .. Name_Len) &
6876 Directory_Separator;
6878 Dir_Last : constant Natural :=
6879 Compute_Directory_Last
6883 if Current_Verbosity = High then
6884 Write_Attr ("Source_Dir", Source_Directory);
6887 -- We look to every entry in the source directory
6889 Open (Dir, Source_Directory);
6892 Read (Dir, Name, Last);
6896 -- ??? Duplicate system call here, we just did a a
6897 -- similar one. Maybe Ada.Directories would be more
6898 -- appropriate here.
6901 (Source_Directory & Name (1 .. Last))
6903 if Current_Verbosity = High then
6904 Write_Str (" Checking ");
6905 Write_Line (Name (1 .. Last));
6909 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6910 Display_File_Name := Name_Find;
6912 if Osint.File_Names_Case_Sensitive then
6913 File_Name := Display_File_Name;
6915 Canonical_Case_File_Name
6916 (Name_Buffer (1 .. Name_Len));
6917 File_Name := Name_Find;
6921 Path_Name : constant String :=
6926 (Source_Directory'First ..
6929 Opt.Follow_Links_For_Files,
6930 Case_Sensitive => True);
6931 -- Case_Sensitive set True (no folding)
6933 Path : Path_Name_Type;
6934 FF : File_Found := Excluded_Sources_Htable.Get
6935 (Project.Excluded, File_Name);
6936 To_Remove : Boolean := False;
6939 Name_Len := Path_Name'Length;
6940 Name_Buffer (1 .. Name_Len) := Path_Name;
6943 if FF /= No_File_Found then
6944 if not FF.Found then
6946 Excluded_Sources_Htable.Set
6947 (Project.Excluded, File_Name, FF);
6949 if Current_Verbosity = High then
6950 Write_Str (" excluded source """);
6951 Write_Str (Get_Name_String (File_Name));
6955 -- Will mark the file as removed, but we
6956 -- still need to add it to the list: if we
6957 -- don't, the file will not appear in the
6958 -- mapping file and will cause the compiler
6966 (Project => Project,
6969 File_Name => File_Name,
6970 Locally_Removed => To_Remove,
6971 Display_File_Name => Display_File_Name,
6972 For_All_Sources => For_All_Sources);
6982 when Directory_Error =>
6986 Source_Dir := Element.Next;
6989 if Current_Verbosity = High then
6990 Write_Line ("end Looking for sources.");
6992 end Search_Directories;
6994 ----------------------------
6995 -- Load_Naming_Exceptions --
6996 ----------------------------
6998 procedure Load_Naming_Exceptions
6999 (Project : in out Project_Processing_Data;
7000 Data : in out Tree_Processing_Data)
7003 Iter : Source_Iterator;
7006 Iter := For_Each_Source (Data.Tree, Project.Project);
7008 Source := Prj.Element (Iter);
7009 exit when Source = No_Source;
7011 -- An excluded file cannot also be an exception file name
7013 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
7016 Error_Msg_File_1 := Source.File;
7019 "{ cannot be both excluded and an exception file name",
7023 if Current_Verbosity = High then
7024 Write_Str ("Naming exception: Putting source file ");
7025 Write_Str (Get_Name_String (Source.File));
7026 Write_Line (" in Source_Names");
7029 Source_Names_Htable.Set
7030 (Project.Source_Names,
7033 (Name => Source.File,
7034 Location => No_Location,
7038 -- If this is an Ada exception, record in table Unit_Exceptions
7040 if Source.Unit /= No_Unit_Index then
7042 Unit_Except : Unit_Exception :=
7043 Unit_Exceptions_Htable.Get
7044 (Project.Unit_Exceptions, Source.Unit.Name);
7047 Unit_Except.Name := Source.Unit.Name;
7049 if Source.Kind = Spec then
7050 Unit_Except.Spec := Source.File;
7052 Unit_Except.Impl := Source.File;
7055 Unit_Exceptions_Htable.Set
7056 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7062 end Load_Naming_Exceptions;
7064 ----------------------
7065 -- Look_For_Sources --
7066 ----------------------
7068 procedure Look_For_Sources
7069 (Project : in out Project_Processing_Data;
7070 Data : in out Tree_Processing_Data)
7072 Object_Files : Object_File_Names_Htable.Instance;
7073 Iter : Source_Iterator;
7076 procedure Check_Object (Src : Source_Id);
7077 -- Check if object file name of Src is already used in the project tree,
7078 -- and report an error if so.
7080 procedure Check_Object_Files;
7081 -- Check that no two sources of this project have the same object file
7083 procedure Mark_Excluded_Sources;
7084 -- Mark as such the sources that are declared as excluded
7090 procedure Check_Object (Src : Source_Id) is
7094 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7096 -- We cannot just check on "Source /= Src", since we might have
7097 -- two different entries for the same file (and since that's
7098 -- the same file it is expected that it has the same object)
7100 if Source /= No_Source
7101 and then Source.Path /= Src.Path
7103 Error_Msg_File_1 := Src.File;
7104 Error_Msg_File_2 := Source.File;
7107 "{ and { have the same object file name",
7111 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7115 ---------------------------
7116 -- Mark_Excluded_Sources --
7117 ---------------------------
7119 procedure Mark_Excluded_Sources is
7120 Source : Source_Id := No_Source;
7121 Excluded : File_Found;
7125 -- Minor optimization: if there are no excluded files, no need to
7126 -- traverse the list of sources. We cannot however also check whether
7127 -- the existing exceptions have ".Found" set to True (indicating we
7128 -- found them before) because we need to do some final processing on
7129 -- them in any case.
7131 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7134 Proj := Project.Project;
7135 while Proj /= No_Project loop
7136 Iter := For_Each_Source (Data.Tree, Proj);
7137 while Prj.Element (Iter) /= No_Source loop
7138 Source := Prj.Element (Iter);
7139 Excluded := Excluded_Sources_Htable.Get
7140 (Project.Excluded, Source.File);
7142 if Excluded /= No_File_Found then
7143 Source.Locally_Removed := True;
7144 Source.In_Interfaces := False;
7146 if Current_Verbosity = High then
7147 Write_Str ("Removing file ");
7149 (Get_Name_String (Excluded.File)
7150 & " " & Get_Name_String (Source.Project.Name));
7153 Excluded_Sources_Htable.Remove
7154 (Project.Excluded, Source.File);
7160 Proj := Proj.Extends;
7164 -- If we have any excluded element left, that means we did not find
7167 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7168 while Excluded /= No_File_Found loop
7169 if not Excluded.Found then
7171 -- Check if the file belongs to another imported project to
7172 -- provide a better error message.
7175 (In_Tree => Data.Tree,
7176 Project => Project.Project,
7177 In_Imported_Only => True,
7178 Base_Name => Excluded.File);
7180 Err_Vars.Error_Msg_File_1 := Excluded.File;
7182 if Src = No_Source then
7185 "unknown file {", Excluded.Location, Data);
7189 "cannot remove a source from an imported project: {",
7190 Excluded.Location, Data);
7194 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7196 end Mark_Excluded_Sources;
7198 ------------------------
7199 -- Check_Object_Files --
7200 ------------------------
7202 procedure Check_Object_Files is
7203 Iter : Source_Iterator;
7205 Src_Ind : Source_File_Index;
7208 Iter := For_Each_Source (Data.Tree);
7210 Src_Id := Prj.Element (Iter);
7211 exit when Src_Id = No_Source;
7213 if Is_Compilable (Src_Id)
7214 and then Src_Id.Language.Config.Object_Generated
7215 and then Is_Extending (Project.Project, Src_Id.Project)
7217 if Src_Id.Unit = No_Unit_Index then
7218 if Src_Id.Kind = Impl then
7219 Check_Object (Src_Id);
7225 if Other_Part (Src_Id) = No_Source then
7226 Check_Object (Src_Id);
7233 if Other_Part (Src_Id) /= No_Source then
7234 Check_Object (Src_Id);
7237 -- Check if it is a subunit
7240 Sinput.P.Load_Project_File
7241 (Get_Name_String (Src_Id.Path.Name));
7243 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7244 Override_Kind (Src_Id, Sep);
7246 Check_Object (Src_Id);
7255 end Check_Object_Files;
7257 -- Start of processing for Look_For_Sources
7260 Find_Excluded_Sources (Project, Data);
7262 if Project.Project.Languages /= No_Language_Index then
7263 Load_Naming_Exceptions (Project, Data);
7264 Find_Sources (Project, Data);
7265 Mark_Excluded_Sources;
7269 Object_File_Names_Htable.Reset (Object_Files);
7270 end Look_For_Sources;
7276 function Path_Name_Of
7277 (File_Name : File_Name_Type;
7278 Directory : Path_Name_Type) return String
7280 Result : String_Access;
7281 The_Directory : constant String := Get_Name_String (Directory);
7284 Get_Name_String (File_Name);
7287 (File_Name => Name_Buffer (1 .. Name_Len),
7288 Path => The_Directory);
7290 if Result = null then
7294 R : String := Result.all;
7297 Canonical_Case_File_Name (R);
7307 procedure Remove_Source
7309 Replaced_By : Source_Id)
7314 if Current_Verbosity = High then
7315 Write_Str ("Removing source ");
7316 Write_Line (Get_Name_String (Id.File) & " at" & Id.Index'Img);
7319 if Replaced_By /= No_Source then
7320 Id.Replaced_By := Replaced_By;
7321 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7324 Id.In_Interfaces := False;
7325 Id.Locally_Removed := True;
7327 -- ??? Should we remove the source from the unit ? The file is not used,
7328 -- so probably should not be referenced from the unit. On the other hand
7329 -- it might give useful additional info
7330 -- if Id.Unit /= null then
7331 -- Id.Unit.File_Names (Id.Kind) := null;
7334 Source := Id.Language.First_Source;
7337 Id.Language.First_Source := Id.Next_In_Lang;
7340 while Source.Next_In_Lang /= Id loop
7341 Source := Source.Next_In_Lang;
7344 Source.Next_In_Lang := Id.Next_In_Lang;
7348 -----------------------
7349 -- Report_No_Sources --
7350 -----------------------
7352 procedure Report_No_Sources
7353 (Project : Project_Id;
7355 Data : Tree_Processing_Data;
7356 Location : Source_Ptr;
7357 Continuation : Boolean := False)
7360 case Data.Flags.When_No_Sources is
7364 when Warning | Error =>
7366 Msg : constant String :=
7369 " sources in this project";
7372 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7374 if Continuation then
7375 Error_Msg (Project, "\" & Msg, Location, Data);
7377 Error_Msg (Project, Msg, Location, Data);
7381 end Report_No_Sources;
7383 ----------------------
7384 -- Show_Source_Dirs --
7385 ----------------------
7387 procedure Show_Source_Dirs
7388 (Project : Project_Id;
7389 In_Tree : Project_Tree_Ref)
7391 Current : String_List_Id;
7392 Element : String_Element;
7395 Write_Line ("Source_Dirs:");
7397 Current := Project.Source_Dirs;
7398 while Current /= Nil_String loop
7399 Element := In_Tree.String_Elements.Table (Current);
7401 Write_Line (Get_Name_String (Element.Value));
7402 Current := Element.Next;
7405 Write_Line ("end Source_Dirs.");
7406 end Show_Source_Dirs;
7408 ---------------------------
7409 -- Process_Naming_Scheme --
7410 ---------------------------
7412 procedure Process_Naming_Scheme
7413 (Tree : Project_Tree_Ref;
7414 Root_Project : Project_Id;
7415 Flags : Processing_Flags)
7417 procedure Recursive_Check
7418 (Project : Project_Id;
7419 Data : in out Tree_Processing_Data);
7420 -- Check_Naming_Scheme for the project
7422 ---------------------
7423 -- Recursive_Check --
7424 ---------------------
7426 procedure Recursive_Check
7427 (Project : Project_Id;
7428 Data : in out Tree_Processing_Data)
7431 if Verbose_Mode then
7432 Write_Str ("Processing_Naming_Scheme for project """);
7433 Write_Str (Get_Name_String (Project.Name));
7437 Prj.Nmsc.Check (Project, Data);
7438 end Recursive_Check;
7440 procedure Check_All_Projects is new
7441 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7443 Data : Tree_Processing_Data;
7445 -- Start of processing for Process_Naming_Scheme
7447 Initialize (Data, Tree => Tree, Flags => Flags);
7448 Check_All_Projects (Root_Project, Data, Imported_First => True);
7450 end Process_Naming_Scheme;