1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with GNAT.Case_Util; use GNAT.Case_Util;
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
28 with GNAT.Dynamic_HTables;
30 with Err_Vars; use Err_Vars;
32 with Osint; use Osint;
33 with Output; use Output;
34 with Prj.Err; use Prj.Err;
35 with Prj.Util; use Prj.Util;
37 with Snames; use Snames;
38 with Targparm; use Targparm;
40 with Ada.Characters.Handling; use Ada.Characters.Handling;
41 with Ada.Directories; use Ada.Directories;
42 with Ada.Strings; use Ada.Strings;
43 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
44 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
46 package body Prj.Nmsc is
48 No_Continuation_String : aliased String := "";
49 Continuation_String : aliased String := "\";
50 -- Used in Check_Library for continuation error messages at the same
53 type Name_Location is record
54 Name : File_Name_Type; -- ??? duplicates the key
55 Location : Source_Ptr;
56 Source : Source_Id := No_Source;
57 Found : Boolean := False;
59 No_Name_Location : constant Name_Location :=
60 (No_File, No_Location, No_Source, False);
61 package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
62 (Header_Num => Header_Num,
63 Element => Name_Location,
64 No_Element => No_Name_Location,
65 Key => File_Name_Type,
68 -- Information about file names found in string list attribute
69 -- (Source_Files or Source_List_File).
70 -- Except is set to True if source is a naming exception in the project.
71 -- This is used to check that all referenced files were indeed found on the
74 type Unit_Exception is record
75 Name : Name_Id; -- ??? duplicates the key
76 Spec : File_Name_Type;
77 Impl : File_Name_Type;
80 No_Unit_Exception : constant Unit_Exception := (No_Name, No_File, No_File);
82 package Unit_Exceptions_Htable is new GNAT.Dynamic_HTables.Simple_HTable
83 (Header_Num => Header_Num,
84 Element => Unit_Exception,
85 No_Element => No_Unit_Exception,
89 -- Record special naming schemes for Ada units (name of spec file and name
90 -- of implementation file). The elements in this list come from the naming
91 -- exceptions specified in the project files.
93 type File_Found is record
94 File : File_Name_Type := No_File;
95 Found : Boolean := False;
96 Location : Source_Ptr := No_Location;
99 No_File_Found : constant File_Found := (No_File, False, No_Location);
101 package Excluded_Sources_Htable is new GNAT.Dynamic_HTables.Simple_HTable
102 (Header_Num => Header_Num,
103 Element => File_Found,
104 No_Element => No_File_Found,
105 Key => File_Name_Type,
108 -- A hash table to store the base names of excluded files, if any
110 package Object_File_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
111 (Header_Num => Header_Num,
112 Element => Source_Id,
113 No_Element => No_Source,
114 Key => File_Name_Type,
117 -- A hash table to store the object file names for a project, to check that
118 -- two different sources have different object file names.
120 type Project_Processing_Data is record
121 Project : Project_Id;
122 Source_Names : Source_Names_Htable.Instance;
123 Unit_Exceptions : Unit_Exceptions_Htable.Instance;
124 Excluded : Excluded_Sources_Htable.Instance;
126 Source_List_File_Location : Source_Ptr;
127 -- Location of the Source_List_File attribute, for error messages
129 -- This is similar to Tree_Processing_Data, but contains project-specific
130 -- information which is only useful while processing the project, and can
131 -- be discarded as soon as we have finished processing the project
133 package Files_Htable is new GNAT.Dynamic_HTables.Simple_HTable
134 (Header_Num => Header_Num,
135 Element => Source_Id,
136 No_Element => No_Source,
137 Key => File_Name_Type,
140 -- Mapping from base file names to Source_Id (containing full info about
143 type Tree_Processing_Data is record
144 Tree : Project_Tree_Ref;
145 File_To_Source : Files_Htable.Instance;
146 Flags : Prj.Processing_Flags;
148 -- Temporary data which is needed while parsing a project. It does not need
149 -- to be kept in memory once a project has been fully loaded, but is
150 -- necessary while performing consistency checks (duplicate sources,...)
151 -- This data must be initialized before processing any project, and the
152 -- same data is used for processing all projects in the tree.
155 (Data : out Tree_Processing_Data;
156 Tree : Project_Tree_Ref;
157 Flags : Prj.Processing_Flags);
160 procedure Free (Data : in out Tree_Processing_Data);
161 -- Free the memory occupied by Data
164 (Project : Project_Id;
165 Data : in out Tree_Processing_Data);
166 -- Process the naming scheme for a single project
169 (Data : in out Project_Processing_Data;
170 Project : Project_Id);
171 procedure Free (Data : in out Project_Processing_Data);
172 -- Initialize or free memory for a project-specific data
174 procedure Find_Excluded_Sources
175 (Project : in out Project_Processing_Data;
176 Data : in out Tree_Processing_Data);
177 -- Find the list of files that should not be considered as source files
178 -- for this project. Sets the list in the Project.Excluded_Sources_Htable.
180 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
181 -- Override the reference kind for a source file. This properly updates
182 -- the unit data if necessary.
184 procedure Load_Naming_Exceptions
185 (Project : in out Project_Processing_Data;
186 Data : in out Tree_Processing_Data);
187 -- All source files in Data.First_Source are considered as naming
188 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
193 Data : in out Tree_Processing_Data;
194 Project : Project_Id;
195 Source_Dir_Rank : Natural;
196 Lang_Id : Language_Ptr;
198 File_Name : File_Name_Type;
199 Display_File : File_Name_Type;
200 Naming_Exception : Boolean := False;
201 Path : Path_Information := No_Path_Information;
202 Alternate_Languages : Language_List := null;
203 Unit : Name_Id := No_Name;
205 Locally_Removed : Boolean := False;
206 Location : Source_Ptr := No_Location);
207 -- Add a new source to the different lists: list of all sources in the
208 -- project tree, list of source of a project and list of sources of a
211 -- If Path is specified, the file is also added to Source_Paths_HT.
213 -- Location is used for error messages
215 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
216 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
217 -- This alters Name_Buffer
219 function Suffix_Matches
221 Suffix : File_Name_Type) return Boolean;
222 -- True if the file name ends with the given suffix. Always returns False
223 -- if Suffix is No_Name.
225 procedure Replace_Into_Name_Buffer
228 Replacement : Character);
229 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
230 -- converted to lower-case at the same time.
232 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
233 -- Check that a name is a valid Ada unit name
235 procedure Check_Package_Naming
236 (Project : Project_Id;
237 Data : in out Tree_Processing_Data;
238 Bodies : out Array_Element_Id;
239 Specs : out Array_Element_Id);
240 -- Check the naming scheme part of Data, and initialize the naming scheme
241 -- data in the config of the various languages. This also returns the
242 -- naming scheme exceptions for unit-based languages (Bodies and Specs are
243 -- associative arrays mapping individual unit names to source file names).
245 procedure Check_Configuration
246 (Project : Project_Id;
247 Data : in out Tree_Processing_Data);
248 -- Check the configuration attributes for the project
250 procedure Check_If_Externally_Built
251 (Project : Project_Id;
252 Data : in out Tree_Processing_Data);
253 -- Check attribute Externally_Built of project Project in project tree
254 -- Data.Tree and modify its data Data if it has the value "true".
256 procedure Check_Interfaces
257 (Project : Project_Id;
258 Data : in out Tree_Processing_Data);
259 -- If a list of sources is specified in attribute Interfaces, set
260 -- In_Interfaces only for the sources specified in the list.
262 procedure Check_Library_Attributes
263 (Project : Project_Id;
264 Data : in out Tree_Processing_Data);
265 -- Check the library attributes of project Project in project tree
266 -- and modify its data Data accordingly.
268 procedure Check_Programming_Languages
269 (Project : Project_Id;
270 Data : in out Tree_Processing_Data);
271 -- Check attribute Languages for the project with data Data in project
272 -- tree Data.Tree and set the components of Data for all the programming
273 -- languages indicated in attribute Languages, if any.
275 procedure Check_Stand_Alone_Library
276 (Project : Project_Id;
277 Data : in out Tree_Processing_Data);
278 -- Check if project Project in project tree Data.Tree is a Stand-Alone
279 -- Library project, and modify its data Data accordingly if it is one.
281 function Compute_Directory_Last (Dir : String) return Natural;
282 -- Return the index of the last significant character in Dir. This is used
283 -- to avoid duplicate '/' (slash) characters at the end of directory names.
285 procedure Search_Directories
286 (Project : in out Project_Processing_Data;
287 Data : in out Tree_Processing_Data;
288 For_All_Sources : Boolean);
289 -- Search the source directories to find the sources. If For_All_Sources is
290 -- True, check each regular file name against the naming schemes of the
291 -- various languages. Otherwise consider only the file names in hash table
292 -- Source_Names. If Allow_Duplicate_Basenames then files with identical
293 -- base names are permitted within a project for source-based languages
294 -- (never for unit based languages).
297 (Project : in out Project_Processing_Data;
298 Data : in out Tree_Processing_Data;
299 Source_Dir_Rank : Natural;
300 Path : Path_Name_Type;
301 File_Name : File_Name_Type;
302 Display_File_Name : File_Name_Type;
303 Locally_Removed : Boolean;
304 For_All_Sources : Boolean);
305 -- Check if file File_Name is a valid source of the project. This is used
306 -- in multi-language mode only. When the file matches one of the naming
307 -- schemes, it is added to various htables through Add_Source and to
308 -- Source_Paths_Htable.
310 -- Name is the name of the candidate file. It hasn't been normalized yet
311 -- and is the direct result of readdir().
313 -- File_Name is the same as Name, but has been normalized.
314 -- Display_File_Name, however, has not been normalized.
316 -- Source_Directory is the directory in which the file was found. It is
317 -- neither normalized nor has had links resolved, and must not end with a
318 -- a directory separator, to avoid duplicates later on.
320 -- If For_All_Sources is True, then all possible file names are analyzed
321 -- otherwise only those currently set in the Source_Names hash table.
323 procedure Check_File_Naming_Schemes
324 (In_Tree : Project_Tree_Ref;
325 Project : Project_Processing_Data;
326 File_Name : File_Name_Type;
327 Alternate_Languages : out Language_List;
328 Language : out Language_Ptr;
329 Display_Language_Name : out Name_Id;
331 Lang_Kind : out Language_Kind;
332 Kind : out Source_Kind);
333 -- Check if the file name File_Name conforms to one of the naming schemes
334 -- of the project. If the file does not match one of the naming schemes,
335 -- set Language to No_Language_Index. Filename is the name of the file
336 -- being investigated. It has been normalized (case-folded). File_Name is
339 procedure Get_Directories
340 (Project : Project_Id;
341 Data : in out Tree_Processing_Data);
342 -- Get the object directory, the exec directory and the source directories
346 (Project : Project_Id;
347 Data : in out Tree_Processing_Data);
348 -- Get the mains of a project from attribute Main, if it exists, and put
349 -- them in the project data.
351 procedure Get_Sources_From_File
353 Location : Source_Ptr;
354 Project : in out Project_Processing_Data;
355 Data : in out Tree_Processing_Data);
356 -- Get the list of sources from a text file and put them in hash table
359 procedure Find_Sources
360 (Project : in out Project_Processing_Data;
361 Data : in out Tree_Processing_Data);
362 -- Process the Source_Files and Source_List_File attributes, and store the
363 -- list of source files into the Source_Names htable. When these attributes
364 -- are not defined, find all files matching the naming schemes in the
365 -- source directories. If Allow_Duplicate_Basenames, then files with the
366 -- same base names are authorized within a project for source-based
367 -- languages (never for unit based languages)
369 procedure Compute_Unit_Name
370 (File_Name : File_Name_Type;
371 Naming : Lang_Naming_Data;
372 Kind : out Source_Kind;
374 Project : Project_Processing_Data;
375 In_Tree : Project_Tree_Ref);
376 -- Check whether the file matches the naming scheme. If it does,
377 -- compute its unit name. If Unit is set to No_Name on exit, none of the
378 -- other out parameters are relevant.
380 procedure Check_Illegal_Suffix
381 (Project : Project_Id;
382 Suffix : File_Name_Type;
383 Dot_Replacement : File_Name_Type;
384 Attribute_Name : String;
385 Location : Source_Ptr;
386 Data : in out Tree_Processing_Data);
387 -- Display an error message if the given suffix is illegal for some reason.
388 -- The name of the attribute we are testing is specified in Attribute_Name,
389 -- which is used in the error message. Location is the location where the
390 -- suffix is defined.
392 procedure Locate_Directory
393 (Project : Project_Id;
394 Name : File_Name_Type;
395 Path : out Path_Information;
396 Dir_Exists : out Boolean;
397 Data : in out Tree_Processing_Data;
398 Create : String := "";
399 Location : Source_Ptr := No_Location;
400 Must_Exist : Boolean := True;
401 Externally_Built : Boolean := False);
402 -- Locate a directory. Name is the directory name. Relative paths are
403 -- resolved relative to the project's directory. If the directory does not
404 -- exist and Setup_Projects is True and Create is a non null string, an
405 -- attempt is made to create the directory. If the directory does not
406 -- exist, it is either created if Setup_Projects is False (and then
407 -- returned), or simply returned without checking for its existence (if
408 -- Must_Exist is False) or No_Path_Information is returned. In all cases,
409 -- Dir_Exists indicates whether the directory now exists. Create is also
410 -- used for debugging traces to show which path we are computing.
412 procedure Look_For_Sources
413 (Project : in out Project_Processing_Data;
414 Data : in out Tree_Processing_Data);
415 -- Find all the sources of project Project in project tree Data.Tree and
416 -- update its Data accordingly. This assumes that Data.First_Source has
417 -- been initialized with the list of excluded sources and special naming
420 function Path_Name_Of
421 (File_Name : File_Name_Type;
422 Directory : Path_Name_Type) return String;
423 -- Returns the path name of a (non project) file. Returns an empty string
424 -- if file cannot be found.
426 procedure Remove_Source
428 Replaced_By : Source_Id);
429 -- Remove a file from the list of sources of a project. This might be
430 -- because the file is replaced by another one in an extending project,
431 -- or because a file was added as a naming exception but was not found
434 procedure Report_No_Sources
435 (Project : Project_Id;
437 Data : Tree_Processing_Data;
438 Location : Source_Ptr;
439 Continuation : Boolean := False);
440 -- Report an error or a warning depending on the value of When_No_Sources
441 -- when there are no sources for language Lang_Name.
443 procedure Show_Source_Dirs
444 (Project : Project_Id; In_Tree : Project_Tree_Ref);
445 -- List all the source directories of a project
447 procedure Write_Attr (Name, Value : String);
448 -- Debug print a value for a specific property. Does nothing when not in
451 ------------------------------
452 -- Replace_Into_Name_Buffer --
453 ------------------------------
455 procedure Replace_Into_Name_Buffer
458 Replacement : Character)
460 Max : constant Integer := Str'Last - Pattern'Length + 1;
467 while J <= Str'Last loop
468 Name_Len := Name_Len + 1;
471 and then Str (J .. J + Pattern'Length - 1) = Pattern
473 Name_Buffer (Name_Len) := Replacement;
474 J := J + Pattern'Length;
477 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
481 end Replace_Into_Name_Buffer;
487 function Suffix_Matches
489 Suffix : File_Name_Type) return Boolean
491 Min_Prefix_Length : Natural := 0;
494 if Suffix = No_File or else Suffix = Empty_File then
499 Suf : String := Get_Name_String (Suffix);
502 -- On non case-sensitive systems, use proper suffix casing
504 Canonical_Case_File_Name (Suf);
506 -- The file name must end with the suffix (which is not an extension)
507 -- For instance a suffix "configure.in" must match a file with the
508 -- same name. To avoid dummy cases, though, a suffix starting with
509 -- '.' requires a file that is at least one character longer ('.cpp'
510 -- should not match a file with the same name)
512 if Suf (Suf'First) = '.' then
513 Min_Prefix_Length := 1;
516 return Filename'Length >= Suf'Length + Min_Prefix_Length
518 (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
526 procedure Write_Attr (Name, Value : String) is
528 if Current_Verbosity = High then
529 Write_Str (" " & Name & " = """);
542 Data : in out Tree_Processing_Data;
543 Project : Project_Id;
544 Source_Dir_Rank : Natural;
545 Lang_Id : Language_Ptr;
547 File_Name : File_Name_Type;
548 Display_File : File_Name_Type;
549 Naming_Exception : Boolean := False;
550 Path : Path_Information := No_Path_Information;
551 Alternate_Languages : Language_List := null;
552 Unit : Name_Id := No_Name;
554 Locally_Removed : Boolean := False;
555 Location : Source_Ptr := No_Location)
557 Config : constant Language_Config := Lang_Id.Config;
561 Prev_Unit : Unit_Index := No_Unit_Index;
563 Source_To_Replace : Source_Id := No_Source;
566 -- Check if the same file name or unit is used in the prj tree
570 if Unit /= No_Name then
571 Prev_Unit := Units_Htable.Get (Data.Tree.Units_HT, Unit);
574 if Prev_Unit /= No_Unit_Index
575 and then (Kind = Impl or else Kind = Spec)
576 and then Prev_Unit.File_Names (Kind) /= null
578 -- Suspicious, we need to check later whether this is authorized
581 Source := Prev_Unit.File_Names (Kind);
584 Source := Files_Htable.Get (Data.File_To_Source, File_Name);
586 if Source /= No_Source
587 and then Source.Index = Index
593 -- Duplication of file/unit in same project is allowed if order of
594 -- source directories is known.
596 if Add_Src = False then
599 if Project = Source.Project then
600 if Prev_Unit = No_Unit_Index then
601 if Data.Flags.Allow_Duplicate_Basenames then
604 elsif Source_Dir_Rank /= Source.Source_Dir_Rank then
608 Error_Msg_File_1 := File_Name;
610 (Data.Flags, "duplicate source file name {",
616 if Source_Dir_Rank /= Source.Source_Dir_Rank then
619 -- We might be seeing the same file through a different path
620 -- (for instance because of symbolic links).
622 elsif Source.Path.Name /= Path.Name then
623 Error_Msg_Name_1 := Unit;
625 (Data.Flags, "duplicate unit %%", Location, Project);
630 -- Do not allow the same unit name in different projects, except
631 -- if one is extending the other.
633 -- For a file based language, the same file name replaces a file
634 -- in a project being extended, but it is allowed to have the same
635 -- file name in unrelated projects.
637 elsif Is_Extending (Project, Source.Project) then
638 if not Locally_Removed then
639 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 (Data.Flags, "\ project %%, %%", Location, Project);
662 Error_Msg_Name_1 := Source.Project.Name;
663 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
665 (Data.Flags, "\ project %%, %%", Location, Project);
668 Error_Msg_Name_1 := Unit;
669 Error_Msg_Name_2 := Source.Project.Name;
671 (Data.Flags, "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, Project);
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.Source_Dir_Rank := Source_Dir_Rank;
729 Id.Language := Lang_Id;
731 Id.Alternate_Languages := Alternate_Languages;
732 Id.Locally_Removed := Locally_Removed;
734 Id.File := File_Name;
735 Id.Display_File := Display_File;
736 Id.Dep_Name := Dependency_Name
737 (File_Name, Lang_Id.Config.Dependency_Kind);
738 Id.Naming_Exception := Naming_Exception;
740 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
743 if Unit /= No_Name then
745 -- Note: we might be creating a dummy unit here, when we in fact have
746 -- a separate. For instance, file file-bar.adb will initially be
747 -- assumed to be the IMPL of unit "file.bar". Only later on (in
748 -- Check_Object_Files) will we parse those units that only have an
749 -- impl and no spec to make sure whether we have a Separate in fact
750 -- (that significantly reduces the number of times we need to parse
751 -- the files, since we are then only interested in those with no
752 -- spec). We still need those dummy units in the table, since that's
753 -- the name we find in the ALI file
755 UData := Units_Htable.Get (Data.Tree.Units_HT, Unit);
757 if UData = No_Unit_Index then
758 UData := new Unit_Data;
760 Units_Htable.Set (Data.Tree.Units_HT, Unit, UData);
765 -- Note that this updates Unit information as well
767 Override_Kind (Id, Kind);
770 if Is_Compilable (Id) and then Config.Object_Generated then
771 Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
772 Id.Switches := Switches_Name (File_Name);
775 if Path /= No_Path_Information then
777 Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id);
780 -- Add the source to the language list
782 Id.Next_In_Lang := Lang_Id.First_Source;
783 Lang_Id.First_Source := Id;
785 if Source_To_Replace /= No_Source then
786 Remove_Source (Source_To_Replace, Id);
789 Files_Htable.Set (Data.File_To_Source, File_Name, Id);
792 ------------------------------
793 -- Canonical_Case_File_Name --
794 ------------------------------
796 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
798 if Osint.File_Names_Case_Sensitive then
799 return File_Name_Type (Name);
801 Get_Name_String (Name);
802 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
805 end Canonical_Case_File_Name;
812 (Project : Project_Id;
813 Data : in out Tree_Processing_Data)
815 Specs : Array_Element_Id;
816 Bodies : Array_Element_Id;
817 Extending : Boolean := False;
818 Prj_Data : Project_Processing_Data;
821 Initialize (Prj_Data, Project);
823 Check_If_Externally_Built (Project, Data);
825 -- Object, exec and source directories
827 Get_Directories (Project, Data);
829 -- Get the programming languages
831 Check_Programming_Languages (Project, Data);
833 if Project.Qualifier = Dry
834 and then Project.Source_Dirs /= Nil_String
837 Source_Dirs : constant Variable_Value :=
840 Project.Decl.Attributes, Data.Tree);
841 Source_Files : constant Variable_Value :=
844 Project.Decl.Attributes, Data.Tree);
845 Source_List_File : constant Variable_Value :=
847 (Name_Source_List_File,
848 Project.Decl.Attributes, Data.Tree);
849 Languages : constant Variable_Value :=
852 Project.Decl.Attributes, Data.Tree);
855 if Source_Dirs.Values = Nil_String
856 and then Source_Files.Values = Nil_String
857 and then Languages.Values = Nil_String
858 and then Source_List_File.Default
860 Project.Source_Dirs := Nil_String;
865 "at least one of Source_Files, Source_Dirs or Languages "
866 & "must be declared empty for an abstract project",
867 Project.Location, Project);
872 -- Check configuration. This must be done even for gnatmake (even though
873 -- no user configuration file was provided) since the default config we
874 -- generate indicates whether libraries are supported for instance.
876 Check_Configuration (Project, Data);
878 -- Library attributes
880 Check_Library_Attributes (Project, Data);
882 if Current_Verbosity = High then
883 Show_Source_Dirs (Project, Data.Tree);
886 Extending := Project.Extends /= No_Project;
888 Check_Package_Naming (Project, Data, Bodies => Bodies, Specs => Specs);
892 if Project.Source_Dirs /= Nil_String then
893 Look_For_Sources (Prj_Data, Data);
895 if not Project.Externally_Built
896 and then not Extending
899 Language : Language_Ptr;
901 Alt_Lang : Language_List;
902 Continuation : Boolean := False;
903 Iter : Source_Iterator;
906 Language := Project.Languages;
907 while Language /= No_Language_Index loop
909 -- If there are no sources for this language, check if there
910 -- are sources for which this is an alternate language.
912 if Language.First_Source = No_Source
913 and then (Data.Flags.Require_Sources_Other_Lang
914 or else Language.Name = Name_Ada)
916 Iter := For_Each_Source (In_Tree => Data.Tree,
919 Source := Element (Iter);
920 exit Source_Loop when Source = No_Source
921 or else Source.Language = Language;
923 Alt_Lang := Source.Alternate_Languages;
924 while Alt_Lang /= null loop
925 exit Source_Loop when Alt_Lang.Language = Language;
926 Alt_Lang := Alt_Lang.Next;
930 end loop Source_Loop;
932 if Source = No_Source then
936 Get_Name_String (Language.Display_Name),
938 Prj_Data.Source_List_File_Location,
940 Continuation := True;
944 Language := Language.Next;
950 -- If a list of sources is specified in attribute Interfaces, set
951 -- In_Interfaces only for the sources specified in the list.
953 Check_Interfaces (Project, Data);
955 -- If it is a library project file, check if it is a standalone library
957 if Project.Library then
958 Check_Stand_Alone_Library (Project, Data);
961 -- Put the list of Mains, if any, in the project data
963 Get_Mains (Project, Data);
972 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
973 The_Name : String := Name;
975 Need_Letter : Boolean := True;
976 Last_Underscore : Boolean := False;
977 OK : Boolean := The_Name'Length > 0;
980 function Is_Reserved (Name : Name_Id) return Boolean;
981 function Is_Reserved (S : String) return Boolean;
982 -- Check that the given name is not an Ada 95 reserved word. The reason
983 -- for the Ada 95 here is that we do not want to exclude the case of an
984 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
985 -- name would be rejected anyway by the compiler. That means there is no
986 -- requirement that the project file parser reject this.
992 function Is_Reserved (S : String) return Boolean is
995 Add_Str_To_Name_Buffer (S);
996 return Is_Reserved (Name_Find);
1003 function Is_Reserved (Name : Name_Id) return Boolean is
1005 if Get_Name_Table_Byte (Name) /= 0
1006 and then Name /= Name_Project
1007 and then Name /= Name_Extends
1008 and then Name /= Name_External
1009 and then Name not in Ada_2005_Reserved_Words
1013 if Current_Verbosity = High then
1014 Write_Str (The_Name);
1015 Write_Line (" is an Ada reserved word.");
1025 -- Start of processing for Check_Ada_Name
1028 To_Lower (The_Name);
1030 Name_Len := The_Name'Length;
1031 Name_Buffer (1 .. Name_Len) := The_Name;
1033 -- Special cases of children of packages A, G, I and S on VMS
1035 if OpenVMS_On_Target
1036 and then Name_Len > 3
1037 and then Name_Buffer (2 .. 3) = "__"
1039 ((Name_Buffer (1) = 'a') or else
1040 (Name_Buffer (1) = 'g') or else
1041 (Name_Buffer (1) = 'i') or else
1042 (Name_Buffer (1) = 's'))
1044 Name_Buffer (2) := '.';
1045 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1046 Name_Len := Name_Len - 1;
1049 Real_Name := Name_Find;
1051 if Is_Reserved (Real_Name) then
1055 First := The_Name'First;
1057 for Index in The_Name'Range loop
1060 -- We need a letter (at the beginning, and following a dot),
1061 -- but we don't have one.
1063 if Is_Letter (The_Name (Index)) then
1064 Need_Letter := False;
1069 if Current_Verbosity = High then
1070 Write_Int (Types.Int (Index));
1072 Write_Char (The_Name (Index));
1073 Write_Line ("' is not a letter.");
1079 elsif Last_Underscore
1080 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1082 -- Two underscores are illegal, and a dot cannot follow
1087 if Current_Verbosity = High then
1088 Write_Int (Types.Int (Index));
1090 Write_Char (The_Name (Index));
1091 Write_Line ("' is illegal here.");
1096 elsif The_Name (Index) = '.' then
1098 -- First, check if the name before the dot is not a reserved word
1100 if Is_Reserved (The_Name (First .. Index - 1)) then
1106 -- We need a letter after a dot
1108 Need_Letter := True;
1110 elsif The_Name (Index) = '_' then
1111 Last_Underscore := True;
1114 -- We need an letter or a digit
1116 Last_Underscore := False;
1118 if not Is_Alphanumeric (The_Name (Index)) then
1121 if Current_Verbosity = High then
1122 Write_Int (Types.Int (Index));
1124 Write_Char (The_Name (Index));
1125 Write_Line ("' is not alphanumeric.");
1133 -- Cannot end with an underscore or a dot
1135 OK := OK and then not Need_Letter and then not Last_Underscore;
1138 if First /= Name'First and then
1139 Is_Reserved (The_Name (First .. The_Name'Last))
1147 -- Signal a problem with No_Name
1153 -------------------------
1154 -- Check_Configuration --
1155 -------------------------
1157 procedure Check_Configuration
1158 (Project : Project_Id;
1159 Data : in out Tree_Processing_Data)
1161 Dot_Replacement : File_Name_Type := No_File;
1162 Casing : Casing_Type := All_Lower_Case;
1163 Separate_Suffix : File_Name_Type := No_File;
1165 Lang_Index : Language_Ptr := No_Language_Index;
1166 -- The index of the language data being checked
1168 Prev_Index : Language_Ptr := No_Language_Index;
1169 -- The index of the previous language
1171 procedure Process_Project_Level_Simple_Attributes;
1172 -- Process the simple attributes at the project level
1174 procedure Process_Project_Level_Array_Attributes;
1175 -- Process the associate array attributes at the project level
1177 procedure Process_Packages;
1178 -- Read the packages of the project
1180 ----------------------
1181 -- Process_Packages --
1182 ----------------------
1184 procedure Process_Packages is
1185 Packages : Package_Id;
1186 Element : Package_Element;
1188 procedure Process_Binder (Arrays : Array_Id);
1189 -- Process the associate array attributes of package Binder
1191 procedure Process_Builder (Attributes : Variable_Id);
1192 -- Process the simple attributes of package Builder
1194 procedure Process_Compiler (Arrays : Array_Id);
1195 -- Process the associate array attributes of package Compiler
1197 procedure Process_Naming (Attributes : Variable_Id);
1198 -- Process the simple attributes of package Naming
1200 procedure Process_Naming (Arrays : Array_Id);
1201 -- Process the associate array attributes of package Naming
1203 procedure Process_Linker (Attributes : Variable_Id);
1204 -- Process the simple attributes of package Linker of a
1205 -- configuration project.
1207 --------------------
1208 -- Process_Binder --
1209 --------------------
1211 procedure Process_Binder (Arrays : Array_Id) is
1212 Current_Array_Id : Array_Id;
1213 Current_Array : Array_Data;
1214 Element_Id : Array_Element_Id;
1215 Element : Array_Element;
1218 -- Process the associative array attribute of package Binder
1220 Current_Array_Id := Arrays;
1221 while Current_Array_Id /= No_Array loop
1222 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1224 Element_Id := Current_Array.Value;
1225 while Element_Id /= No_Array_Element loop
1226 Element := Data.Tree.Array_Elements.Table (Element_Id);
1228 if Element.Index /= All_Other_Names then
1230 -- Get the name of the language
1233 Get_Language_From_Name
1234 (Project, Get_Name_String (Element.Index));
1236 if Lang_Index /= No_Language_Index then
1237 case Current_Array.Name is
1240 -- Attribute Driver (<language>)
1242 Lang_Index.Config.Binder_Driver :=
1243 File_Name_Type (Element.Value.Value);
1245 when Name_Required_Switches =>
1248 Lang_Index.Config.Binder_Required_Switches,
1249 From_List => Element.Value.Values,
1250 In_Tree => Data.Tree);
1254 -- Attribute Prefix (<language>)
1256 Lang_Index.Config.Binder_Prefix :=
1257 Element.Value.Value;
1259 when Name_Objects_Path =>
1261 -- Attribute Objects_Path (<language>)
1263 Lang_Index.Config.Objects_Path :=
1264 Element.Value.Value;
1266 when Name_Objects_Path_File =>
1268 -- Attribute Objects_Path (<language>)
1270 Lang_Index.Config.Objects_Path_File :=
1271 Element.Value.Value;
1279 Element_Id := Element.Next;
1282 Current_Array_Id := Current_Array.Next;
1286 ---------------------
1287 -- Process_Builder --
1288 ---------------------
1290 procedure Process_Builder (Attributes : Variable_Id) is
1291 Attribute_Id : Variable_Id;
1292 Attribute : Variable;
1295 -- Process non associated array attribute from package Builder
1297 Attribute_Id := Attributes;
1298 while Attribute_Id /= No_Variable loop
1300 Data.Tree.Variable_Elements.Table (Attribute_Id);
1302 if not Attribute.Value.Default then
1303 if Attribute.Name = Name_Executable_Suffix then
1305 -- Attribute Executable_Suffix: the suffix of the
1308 Project.Config.Executable_Suffix :=
1309 Attribute.Value.Value;
1313 Attribute_Id := Attribute.Next;
1315 end Process_Builder;
1317 ----------------------
1318 -- Process_Compiler --
1319 ----------------------
1321 procedure Process_Compiler (Arrays : Array_Id) is
1322 Current_Array_Id : Array_Id;
1323 Current_Array : Array_Data;
1324 Element_Id : Array_Element_Id;
1325 Element : Array_Element;
1326 List : String_List_Id;
1329 -- Process the associative array attribute of package Compiler
1331 Current_Array_Id := Arrays;
1332 while Current_Array_Id /= No_Array loop
1333 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1335 Element_Id := Current_Array.Value;
1336 while Element_Id /= No_Array_Element loop
1337 Element := Data.Tree.Array_Elements.Table (Element_Id);
1339 if Element.Index /= All_Other_Names then
1341 -- Get the name of the language
1343 Lang_Index := Get_Language_From_Name
1344 (Project, Get_Name_String (Element.Index));
1346 if Lang_Index /= No_Language_Index then
1347 case Current_Array.Name is
1348 when Name_Dependency_Switches =>
1350 -- Attribute Dependency_Switches (<language>)
1352 if Lang_Index.Config.Dependency_Kind = None then
1353 Lang_Index.Config.Dependency_Kind := Makefile;
1356 List := Element.Value.Values;
1358 if List /= Nil_String then
1360 Lang_Index.Config.Dependency_Option,
1362 In_Tree => Data.Tree);
1365 when Name_Dependency_Driver =>
1367 -- Attribute Dependency_Driver (<language>)
1369 if Lang_Index.Config.Dependency_Kind = None then
1370 Lang_Index.Config.Dependency_Kind := Makefile;
1373 List := Element.Value.Values;
1375 if List /= Nil_String then
1377 Lang_Index.Config.Compute_Dependency,
1379 In_Tree => Data.Tree);
1382 when Name_Include_Switches =>
1384 -- Attribute Include_Switches (<language>)
1386 List := Element.Value.Values;
1388 if List = Nil_String then
1390 (Data.Flags, "include option cannot be null",
1391 Element.Value.Location, Project);
1394 Put (Into_List => Lang_Index.Config.Include_Option,
1396 In_Tree => Data.Tree);
1398 when Name_Include_Path =>
1400 -- Attribute Include_Path (<language>)
1402 Lang_Index.Config.Include_Path :=
1403 Element.Value.Value;
1405 when Name_Include_Path_File =>
1407 -- Attribute Include_Path_File (<language>)
1409 Lang_Index.Config.Include_Path_File :=
1410 Element.Value.Value;
1414 -- Attribute Driver (<language>)
1416 Lang_Index.Config.Compiler_Driver :=
1417 File_Name_Type (Element.Value.Value);
1419 when Name_Required_Switches |
1420 Name_Leading_Required_Switches =>
1423 Compiler_Leading_Required_Switches,
1424 From_List => Element.Value.Values,
1425 In_Tree => Data.Tree);
1427 when Name_Trailing_Required_Switches =>
1430 Compiler_Trailing_Required_Switches,
1431 From_List => Element.Value.Values,
1432 In_Tree => Data.Tree);
1434 when Name_Multi_Unit_Switches =>
1436 Lang_Index.Config.Multi_Unit_Switches,
1437 From_List => Element.Value.Values,
1438 In_Tree => Data.Tree);
1440 when Name_Multi_Unit_Object_Separator =>
1441 Get_Name_String (Element.Value.Value);
1443 if Name_Len /= 1 then
1446 "multi-unit object separator must have " &
1447 "a single character",
1448 Element.Value.Location, Project);
1450 elsif Name_Buffer (1) = ' ' then
1453 "multi-unit object separator cannot be " &
1455 Element.Value.Location, Project);
1458 Lang_Index.Config.Multi_Unit_Object_Separator :=
1462 when Name_Path_Syntax =>
1464 Lang_Index.Config.Path_Syntax :=
1465 Path_Syntax_Kind'Value
1466 (Get_Name_String (Element.Value.Value));
1469 when Constraint_Error =>
1472 "invalid value for Path_Syntax",
1473 Element.Value.Location, Project);
1476 when Name_Object_File_Suffix =>
1477 if Get_Name_String (Element.Value.Value) = "" then
1480 "object file suffix cannot be empty",
1481 Element.Value.Location, Project);
1484 Lang_Index.Config.Object_File_Suffix :=
1485 Element.Value.Value;
1488 when Name_Object_File_Switches =>
1490 Lang_Index.Config.Object_File_Switches,
1491 From_List => Element.Value.Values,
1492 In_Tree => Data.Tree);
1494 when Name_Pic_Option =>
1496 -- Attribute Compiler_Pic_Option (<language>)
1498 List := Element.Value.Values;
1500 if List = Nil_String then
1503 "compiler PIC option cannot be null",
1504 Element.Value.Location, Project);
1508 Lang_Index.Config.Compilation_PIC_Option,
1510 In_Tree => Data.Tree);
1512 when Name_Mapping_File_Switches =>
1514 -- Attribute Mapping_File_Switches (<language>)
1516 List := Element.Value.Values;
1518 if List = Nil_String then
1521 "mapping file switches cannot be null",
1522 Element.Value.Location, Project);
1526 Lang_Index.Config.Mapping_File_Switches,
1528 In_Tree => Data.Tree);
1530 when Name_Mapping_Spec_Suffix =>
1532 -- Attribute Mapping_Spec_Suffix (<language>)
1534 Lang_Index.Config.Mapping_Spec_Suffix :=
1535 File_Name_Type (Element.Value.Value);
1537 when Name_Mapping_Body_Suffix =>
1539 -- Attribute Mapping_Body_Suffix (<language>)
1541 Lang_Index.Config.Mapping_Body_Suffix :=
1542 File_Name_Type (Element.Value.Value);
1544 when Name_Config_File_Switches =>
1546 -- Attribute Config_File_Switches (<language>)
1548 List := Element.Value.Values;
1550 if List = Nil_String then
1553 "config file switches cannot be null",
1554 Element.Value.Location, Project);
1558 Lang_Index.Config.Config_File_Switches,
1560 In_Tree => Data.Tree);
1562 when Name_Objects_Path =>
1564 -- Attribute Objects_Path (<language>)
1566 Lang_Index.Config.Objects_Path :=
1567 Element.Value.Value;
1569 when Name_Objects_Path_File =>
1571 -- Attribute Objects_Path_File (<language>)
1573 Lang_Index.Config.Objects_Path_File :=
1574 Element.Value.Value;
1576 when Name_Config_Body_File_Name =>
1578 -- Attribute Config_Body_File_Name (<language>)
1580 Lang_Index.Config.Config_Body :=
1581 Element.Value.Value;
1583 when Name_Config_Body_File_Name_Index =>
1585 -- Attribute Config_Body_File_Name_Index
1588 Lang_Index.Config.Config_Body_Index :=
1589 Element.Value.Value;
1591 when Name_Config_Body_File_Name_Pattern =>
1593 -- Attribute Config_Body_File_Name_Pattern
1596 Lang_Index.Config.Config_Body_Pattern :=
1597 Element.Value.Value;
1599 when Name_Config_Spec_File_Name =>
1601 -- Attribute Config_Spec_File_Name (<language>)
1603 Lang_Index.Config.Config_Spec :=
1604 Element.Value.Value;
1606 when Name_Config_Spec_File_Name_Index =>
1608 -- Attribute Config_Spec_File_Name_Index
1611 Lang_Index.Config.Config_Spec_Index :=
1612 Element.Value.Value;
1614 when Name_Config_Spec_File_Name_Pattern =>
1616 -- Attribute Config_Spec_File_Name_Pattern
1619 Lang_Index.Config.Config_Spec_Pattern :=
1620 Element.Value.Value;
1622 when Name_Config_File_Unique =>
1624 -- Attribute Config_File_Unique (<language>)
1627 Lang_Index.Config.Config_File_Unique :=
1629 (Get_Name_String (Element.Value.Value));
1631 when Constraint_Error =>
1634 "illegal value for Config_File_Unique",
1635 Element.Value.Location, Project);
1644 Element_Id := Element.Next;
1647 Current_Array_Id := Current_Array.Next;
1649 end Process_Compiler;
1651 --------------------
1652 -- Process_Naming --
1653 --------------------
1655 procedure Process_Naming (Attributes : Variable_Id) is
1656 Attribute_Id : Variable_Id;
1657 Attribute : Variable;
1660 -- Process non associated array attribute from package Naming
1662 Attribute_Id := Attributes;
1663 while Attribute_Id /= No_Variable loop
1664 Attribute := Data.Tree.Variable_Elements.Table (Attribute_Id);
1666 if not Attribute.Value.Default then
1667 if Attribute.Name = Name_Separate_Suffix then
1669 -- Attribute Separate_Suffix
1671 Get_Name_String (Attribute.Value.Value);
1672 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1673 Separate_Suffix := Name_Find;
1675 elsif Attribute.Name = Name_Casing then
1681 Value (Get_Name_String (Attribute.Value.Value));
1684 when Constraint_Error =>
1687 "invalid value for Casing",
1688 Attribute.Value.Location, Project);
1691 elsif Attribute.Name = Name_Dot_Replacement then
1693 -- Attribute Dot_Replacement
1695 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1700 Attribute_Id := Attribute.Next;
1704 procedure Process_Naming (Arrays : Array_Id) is
1705 Current_Array_Id : Array_Id;
1706 Current_Array : Array_Data;
1707 Element_Id : Array_Element_Id;
1708 Element : Array_Element;
1711 -- Process the associative array attribute of package Naming
1713 Current_Array_Id := Arrays;
1714 while Current_Array_Id /= No_Array loop
1715 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1717 Element_Id := Current_Array.Value;
1718 while Element_Id /= No_Array_Element loop
1719 Element := Data.Tree.Array_Elements.Table (Element_Id);
1721 -- Get the name of the language
1723 Lang_Index := Get_Language_From_Name
1724 (Project, Get_Name_String (Element.Index));
1726 if Lang_Index /= No_Language_Index then
1727 case Current_Array.Name is
1728 when Name_Spec_Suffix | Name_Specification_Suffix =>
1730 -- Attribute Spec_Suffix (<language>)
1732 Get_Name_String (Element.Value.Value);
1733 Canonical_Case_File_Name
1734 (Name_Buffer (1 .. Name_Len));
1735 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1738 when Name_Implementation_Suffix | Name_Body_Suffix =>
1740 Get_Name_String (Element.Value.Value);
1741 Canonical_Case_File_Name
1742 (Name_Buffer (1 .. Name_Len));
1744 -- Attribute Body_Suffix (<language>)
1746 Lang_Index.Config.Naming_Data.Body_Suffix :=
1748 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1749 Lang_Index.Config.Naming_Data.Body_Suffix;
1756 Element_Id := Element.Next;
1759 Current_Array_Id := Current_Array.Next;
1763 --------------------
1764 -- Process_Linker --
1765 --------------------
1767 procedure Process_Linker (Attributes : Variable_Id) is
1768 Attribute_Id : Variable_Id;
1769 Attribute : Variable;
1772 -- Process non associated array attribute from package Linker
1774 Attribute_Id := Attributes;
1775 while Attribute_Id /= No_Variable loop
1777 Data.Tree.Variable_Elements.Table (Attribute_Id);
1779 if not Attribute.Value.Default then
1780 if Attribute.Name = Name_Driver then
1782 -- Attribute Linker'Driver: the default linker to use
1784 Project.Config.Linker :=
1785 Path_Name_Type (Attribute.Value.Value);
1787 -- Linker'Driver is also used to link shared libraries
1788 -- if the obsolescent attribute Library_GCC has not been
1791 if Project.Config.Shared_Lib_Driver = No_File then
1792 Project.Config.Shared_Lib_Driver :=
1793 File_Name_Type (Attribute.Value.Value);
1796 elsif Attribute.Name = Name_Required_Switches then
1798 -- Attribute Required_Switches: the minimum
1799 -- options to use when invoking the linker
1801 Put (Into_List => Project.Config.Minimum_Linker_Options,
1802 From_List => Attribute.Value.Values,
1803 In_Tree => Data.Tree);
1805 elsif Attribute.Name = Name_Map_File_Option then
1806 Project.Config.Map_File_Option := Attribute.Value.Value;
1808 elsif Attribute.Name = Name_Max_Command_Line_Length then
1810 Project.Config.Max_Command_Line_Length :=
1811 Natural'Value (Get_Name_String
1812 (Attribute.Value.Value));
1815 when Constraint_Error =>
1818 "value must be positive or equal to 0",
1819 Attribute.Value.Location, Project);
1822 elsif Attribute.Name = Name_Response_File_Format then
1827 Get_Name_String (Attribute.Value.Value);
1828 To_Lower (Name_Buffer (1 .. Name_Len));
1831 if Name = Name_None then
1832 Project.Config.Resp_File_Format := None;
1834 elsif Name = Name_Gnu then
1835 Project.Config.Resp_File_Format := GNU;
1837 elsif Name = Name_Object_List then
1838 Project.Config.Resp_File_Format := Object_List;
1840 elsif Name = Name_Option_List then
1841 Project.Config.Resp_File_Format := Option_List;
1846 "illegal response file format",
1847 Attribute.Value.Location, Project);
1851 elsif Attribute.Name = Name_Response_File_Switches then
1852 Put (Into_List => Project.Config.Resp_File_Options,
1853 From_List => Attribute.Value.Values,
1854 In_Tree => Data.Tree);
1858 Attribute_Id := Attribute.Next;
1862 -- Start of processing for Process_Packages
1865 Packages := Project.Decl.Packages;
1866 while Packages /= No_Package loop
1867 Element := Data.Tree.Packages.Table (Packages);
1869 case Element.Name is
1872 -- Process attributes of package Binder
1874 Process_Binder (Element.Decl.Arrays);
1876 when Name_Builder =>
1878 -- Process attributes of package Builder
1880 Process_Builder (Element.Decl.Attributes);
1882 when Name_Compiler =>
1884 -- Process attributes of package Compiler
1886 Process_Compiler (Element.Decl.Arrays);
1890 -- Process attributes of package Linker
1892 Process_Linker (Element.Decl.Attributes);
1896 -- Process attributes of package Naming
1898 Process_Naming (Element.Decl.Attributes);
1899 Process_Naming (Element.Decl.Arrays);
1905 Packages := Element.Next;
1907 end Process_Packages;
1909 ---------------------------------------------
1910 -- Process_Project_Level_Simple_Attributes --
1911 ---------------------------------------------
1913 procedure Process_Project_Level_Simple_Attributes is
1914 Attribute_Id : Variable_Id;
1915 Attribute : Variable;
1916 List : String_List_Id;
1919 -- Process non associated array attribute at project level
1921 Attribute_Id := Project.Decl.Attributes;
1922 while Attribute_Id /= No_Variable loop
1924 Data.Tree.Variable_Elements.Table (Attribute_Id);
1926 if not Attribute.Value.Default then
1927 if Attribute.Name = Name_Target then
1929 -- Attribute Target: the target specified
1931 Project.Config.Target := Attribute.Value.Value;
1933 elsif Attribute.Name = Name_Library_Builder then
1935 -- Attribute Library_Builder: the application to invoke
1936 -- to build libraries.
1938 Project.Config.Library_Builder :=
1939 Path_Name_Type (Attribute.Value.Value);
1941 elsif Attribute.Name = Name_Archive_Builder then
1943 -- Attribute Archive_Builder: the archive builder
1944 -- (usually "ar") and its minimum options (usually "cr").
1946 List := Attribute.Value.Values;
1948 if List = Nil_String then
1951 "archive builder cannot be null",
1952 Attribute.Value.Location, Project);
1955 Put (Into_List => Project.Config.Archive_Builder,
1957 In_Tree => Data.Tree);
1959 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1961 -- Attribute Archive_Builder: the archive builder
1962 -- (usually "ar") and its minimum options (usually "cr").
1964 List := Attribute.Value.Values;
1966 if List /= Nil_String then
1969 Project.Config.Archive_Builder_Append_Option,
1971 In_Tree => Data.Tree);
1974 elsif Attribute.Name = Name_Archive_Indexer then
1976 -- Attribute Archive_Indexer: the optional archive
1977 -- indexer (usually "ranlib") with its minimum options
1980 List := Attribute.Value.Values;
1982 if List = Nil_String then
1985 "archive indexer cannot be null",
1986 Attribute.Value.Location, Project);
1989 Put (Into_List => Project.Config.Archive_Indexer,
1991 In_Tree => Data.Tree);
1993 elsif Attribute.Name = Name_Library_Partial_Linker then
1995 -- Attribute Library_Partial_Linker: the optional linker
1996 -- driver with its minimum options, to partially link
1999 List := Attribute.Value.Values;
2001 if List = Nil_String then
2004 "partial linker cannot be null",
2005 Attribute.Value.Location, Project);
2008 Put (Into_List => Project.Config.Lib_Partial_Linker,
2010 In_Tree => Data.Tree);
2012 elsif Attribute.Name = Name_Library_GCC then
2013 Project.Config.Shared_Lib_Driver :=
2014 File_Name_Type (Attribute.Value.Value);
2017 "?Library_'G'C'C is an obsolescent attribute, " &
2018 "use Linker''Driver instead",
2019 Attribute.Value.Location, Project);
2021 elsif Attribute.Name = Name_Archive_Suffix then
2022 Project.Config.Archive_Suffix :=
2023 File_Name_Type (Attribute.Value.Value);
2025 elsif Attribute.Name = Name_Linker_Executable_Option then
2027 -- Attribute Linker_Executable_Option: optional options
2028 -- to specify an executable name. Defaults to "-o".
2030 List := Attribute.Value.Values;
2032 if List = Nil_String then
2035 "linker executable option cannot be null",
2036 Attribute.Value.Location, Project);
2039 Put (Into_List => Project.Config.Linker_Executable_Option,
2041 In_Tree => Data.Tree);
2043 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2045 -- Attribute Linker_Lib_Dir_Option: optional options
2046 -- to specify a library search directory. Defaults to
2049 Get_Name_String (Attribute.Value.Value);
2051 if Name_Len = 0 then
2054 "linker library directory option cannot be empty",
2055 Attribute.Value.Location, Project);
2058 Project.Config.Linker_Lib_Dir_Option :=
2059 Attribute.Value.Value;
2061 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2063 -- Attribute Linker_Lib_Name_Option: optional options
2064 -- to specify the name of a library to be linked in.
2065 -- Defaults to "-l".
2067 Get_Name_String (Attribute.Value.Value);
2069 if Name_Len = 0 then
2072 "linker library name option cannot be empty",
2073 Attribute.Value.Location, Project);
2076 Project.Config.Linker_Lib_Name_Option :=
2077 Attribute.Value.Value;
2079 elsif Attribute.Name = Name_Run_Path_Option then
2081 -- Attribute Run_Path_Option: optional options to
2082 -- specify a path for libraries.
2084 List := Attribute.Value.Values;
2086 if List /= Nil_String then
2087 Put (Into_List => Project.Config.Run_Path_Option,
2089 In_Tree => Data.Tree);
2092 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2094 pragma Unsuppress (All_Checks);
2096 Project.Config.Separate_Run_Path_Options :=
2097 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2099 when Constraint_Error =>
2102 "invalid value """ &
2103 Get_Name_String (Attribute.Value.Value) &
2104 """ for Separate_Run_Path_Options",
2105 Attribute.Value.Location, Project);
2108 elsif Attribute.Name = Name_Library_Support then
2110 pragma Unsuppress (All_Checks);
2112 Project.Config.Lib_Support :=
2113 Library_Support'Value (Get_Name_String
2114 (Attribute.Value.Value));
2116 when Constraint_Error =>
2119 "invalid value """ &
2120 Get_Name_String (Attribute.Value.Value) &
2121 """ for Library_Support",
2122 Attribute.Value.Location, Project);
2125 elsif Attribute.Name = Name_Shared_Library_Prefix then
2126 Project.Config.Shared_Lib_Prefix :=
2127 File_Name_Type (Attribute.Value.Value);
2129 elsif Attribute.Name = Name_Shared_Library_Suffix then
2130 Project.Config.Shared_Lib_Suffix :=
2131 File_Name_Type (Attribute.Value.Value);
2133 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2135 pragma Unsuppress (All_Checks);
2137 Project.Config.Symbolic_Link_Supported :=
2138 Boolean'Value (Get_Name_String
2139 (Attribute.Value.Value));
2141 when Constraint_Error =>
2145 & Get_Name_String (Attribute.Value.Value)
2146 & """ for Symbolic_Link_Supported",
2147 Attribute.Value.Location, Project);
2151 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2154 pragma Unsuppress (All_Checks);
2156 Project.Config.Lib_Maj_Min_Id_Supported :=
2157 Boolean'Value (Get_Name_String
2158 (Attribute.Value.Value));
2160 when Constraint_Error =>
2163 "invalid value """ &
2164 Get_Name_String (Attribute.Value.Value) &
2165 """ for Library_Major_Minor_Id_Supported",
2166 Attribute.Value.Location, Project);
2169 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2171 pragma Unsuppress (All_Checks);
2173 Project.Config.Auto_Init_Supported :=
2174 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2176 when Constraint_Error =>
2180 & Get_Name_String (Attribute.Value.Value)
2181 & """ for Library_Auto_Init_Supported",
2182 Attribute.Value.Location, Project);
2185 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2186 List := Attribute.Value.Values;
2188 if List /= Nil_String then
2189 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2191 In_Tree => Data.Tree);
2194 elsif Attribute.Name = Name_Library_Version_Switches then
2195 List := Attribute.Value.Values;
2197 if List /= Nil_String then
2198 Put (Into_List => Project.Config.Lib_Version_Options,
2200 In_Tree => Data.Tree);
2205 Attribute_Id := Attribute.Next;
2207 end Process_Project_Level_Simple_Attributes;
2209 --------------------------------------------
2210 -- Process_Project_Level_Array_Attributes --
2211 --------------------------------------------
2213 procedure Process_Project_Level_Array_Attributes is
2214 Current_Array_Id : Array_Id;
2215 Current_Array : Array_Data;
2216 Element_Id : Array_Element_Id;
2217 Element : Array_Element;
2218 List : String_List_Id;
2221 -- Process the associative array attributes at project level
2223 Current_Array_Id := Project.Decl.Arrays;
2224 while Current_Array_Id /= No_Array loop
2225 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
2227 Element_Id := Current_Array.Value;
2228 while Element_Id /= No_Array_Element loop
2229 Element := Data.Tree.Array_Elements.Table (Element_Id);
2231 -- Get the name of the language
2234 Get_Language_From_Name
2235 (Project, Get_Name_String (Element.Index));
2237 if Lang_Index /= No_Language_Index then
2238 case Current_Array.Name is
2239 when Name_Inherit_Source_Path =>
2240 List := Element.Value.Values;
2242 if List /= Nil_String then
2245 Lang_Index.Config.Include_Compatible_Languages,
2247 In_Tree => Data.Tree,
2248 Lower_Case => True);
2251 when Name_Toolchain_Description =>
2253 -- Attribute Toolchain_Description (<language>)
2255 Lang_Index.Config.Toolchain_Description :=
2256 Element.Value.Value;
2258 when Name_Toolchain_Version =>
2260 -- Attribute Toolchain_Version (<language>)
2262 Lang_Index.Config.Toolchain_Version :=
2263 Element.Value.Value;
2265 when Name_Runtime_Library_Dir =>
2267 -- Attribute Runtime_Library_Dir (<language>)
2269 Lang_Index.Config.Runtime_Library_Dir :=
2270 Element.Value.Value;
2272 when Name_Runtime_Source_Dir =>
2274 -- Attribute Runtime_Library_Dir (<language>)
2276 Lang_Index.Config.Runtime_Source_Dir :=
2277 Element.Value.Value;
2279 when Name_Object_Generated =>
2281 pragma Unsuppress (All_Checks);
2287 (Get_Name_String (Element.Value.Value));
2289 Lang_Index.Config.Object_Generated := Value;
2291 -- If no object is generated, no object may be
2295 Lang_Index.Config.Objects_Linked := False;
2299 when Constraint_Error =>
2303 & Get_Name_String (Element.Value.Value)
2304 & """ for Object_Generated",
2305 Element.Value.Location, Project);
2308 when Name_Objects_Linked =>
2310 pragma Unsuppress (All_Checks);
2316 (Get_Name_String (Element.Value.Value));
2318 -- No change if Object_Generated is False, as this
2319 -- forces Objects_Linked to be False too.
2321 if Lang_Index.Config.Object_Generated then
2322 Lang_Index.Config.Objects_Linked := Value;
2326 when Constraint_Error =>
2330 & Get_Name_String (Element.Value.Value)
2331 & """ for Objects_Linked",
2332 Element.Value.Location, Project);
2339 Element_Id := Element.Next;
2342 Current_Array_Id := Current_Array.Next;
2344 end Process_Project_Level_Array_Attributes;
2346 -- Start of processing for Check_Configuration
2349 Process_Project_Level_Simple_Attributes;
2350 Process_Project_Level_Array_Attributes;
2353 -- For unit based languages, set Casing, Dot_Replacement and
2354 -- Separate_Suffix in Naming_Data.
2356 Lang_Index := Project.Languages;
2357 while Lang_Index /= No_Language_Index loop
2358 if Lang_Index.Name = Name_Ada then
2359 Lang_Index.Config.Naming_Data.Casing := Casing;
2360 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2362 if Separate_Suffix /= No_File then
2363 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2370 Lang_Index := Lang_Index.Next;
2373 -- Give empty names to various prefixes/suffixes, if they have not
2374 -- been specified in the configuration.
2376 if Project.Config.Archive_Suffix = No_File then
2377 Project.Config.Archive_Suffix := Empty_File;
2380 if Project.Config.Shared_Lib_Prefix = No_File then
2381 Project.Config.Shared_Lib_Prefix := Empty_File;
2384 if Project.Config.Shared_Lib_Suffix = No_File then
2385 Project.Config.Shared_Lib_Suffix := Empty_File;
2388 Lang_Index := Project.Languages;
2389 while Lang_Index /= No_Language_Index loop
2391 -- For all languages, Compiler_Driver needs to be specified. This is
2392 -- only needed if we do intend to compile (not in GPS for instance).
2394 if Data.Flags.Compiler_Driver_Mandatory
2395 and then Lang_Index.Config.Compiler_Driver = No_File
2397 Error_Msg_Name_1 := Lang_Index.Display_Name;
2400 "?no compiler specified for language %%" &
2401 ", ignoring all its sources",
2402 No_Location, Project);
2404 if Lang_Index = Project.Languages then
2405 Project.Languages := Lang_Index.Next;
2407 Prev_Index.Next := Lang_Index.Next;
2410 elsif Lang_Index.Name = Name_Ada then
2411 Prev_Index := Lang_Index;
2413 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2414 -- Body_Suffix need to be specified.
2416 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2419 "Dot_Replacement not specified for Ada",
2420 No_Location, Project);
2423 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2426 "Spec_Suffix not specified for Ada",
2427 No_Location, Project);
2430 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2433 "Body_Suffix not specified for Ada",
2434 No_Location, Project);
2438 Prev_Index := Lang_Index;
2440 -- For file based languages, either Spec_Suffix or Body_Suffix
2441 -- need to be specified.
2443 if Data.Flags.Require_Sources_Other_Lang
2444 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2445 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2447 Error_Msg_Name_1 := Lang_Index.Display_Name;
2450 "no suffixes specified for %%",
2451 No_Location, Project);
2455 Lang_Index := Lang_Index.Next;
2457 end Check_Configuration;
2459 -------------------------------
2460 -- Check_If_Externally_Built --
2461 -------------------------------
2463 procedure Check_If_Externally_Built
2464 (Project : Project_Id;
2465 Data : in out Tree_Processing_Data)
2467 Externally_Built : constant Variable_Value :=
2469 (Name_Externally_Built,
2470 Project.Decl.Attributes, Data.Tree);
2473 if not Externally_Built.Default then
2474 Get_Name_String (Externally_Built.Value);
2475 To_Lower (Name_Buffer (1 .. Name_Len));
2477 if Name_Buffer (1 .. Name_Len) = "true" then
2478 Project.Externally_Built := True;
2480 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2481 Error_Msg (Data.Flags,
2482 "Externally_Built may only be true or false",
2483 Externally_Built.Location, Project);
2487 -- A virtual project extending an externally built project is itself
2488 -- externally built.
2490 if Project.Virtual and then Project.Extends /= No_Project then
2491 Project.Externally_Built := Project.Extends.Externally_Built;
2494 if Current_Verbosity = High then
2495 Write_Str ("Project is ");
2497 if not Project.Externally_Built then
2501 Write_Line ("externally built.");
2503 end Check_If_Externally_Built;
2505 ----------------------
2506 -- Check_Interfaces --
2507 ----------------------
2509 procedure Check_Interfaces
2510 (Project : Project_Id;
2511 Data : in out Tree_Processing_Data)
2513 Interfaces : constant Prj.Variable_Value :=
2515 (Snames.Name_Interfaces,
2516 Project.Decl.Attributes,
2519 List : String_List_Id;
2520 Element : String_Element;
2521 Name : File_Name_Type;
2522 Iter : Source_Iterator;
2524 Project_2 : Project_Id;
2528 if not Interfaces.Default then
2530 -- Set In_Interfaces to False for all sources. It will be set to True
2531 -- later for the sources in the Interfaces list.
2533 Project_2 := Project;
2534 while Project_2 /= No_Project loop
2535 Iter := For_Each_Source (Data.Tree, Project_2);
2537 Source := Prj.Element (Iter);
2538 exit when Source = No_Source;
2539 Source.In_Interfaces := False;
2543 Project_2 := Project_2.Extends;
2546 List := Interfaces.Values;
2547 while List /= Nil_String loop
2548 Element := Data.Tree.String_Elements.Table (List);
2549 Name := Canonical_Case_File_Name (Element.Value);
2551 Project_2 := Project;
2553 while Project_2 /= No_Project loop
2554 Iter := For_Each_Source (Data.Tree, Project_2);
2557 Source := Prj.Element (Iter);
2558 exit when Source = No_Source;
2560 if Source.File = Name then
2561 if not Source.Locally_Removed then
2562 Source.In_Interfaces := True;
2563 Source.Declared_In_Interfaces := True;
2565 Other := Other_Part (Source);
2567 if Other /= No_Source then
2568 Other.In_Interfaces := True;
2569 Other.Declared_In_Interfaces := True;
2572 if Current_Verbosity = High then
2573 Write_Str (" interface: ");
2574 Write_Line (Get_Name_String (Source.Path.Name));
2584 Project_2 := Project_2.Extends;
2587 if Source = No_Source then
2588 Error_Msg_File_1 := File_Name_Type (Element.Value);
2589 Error_Msg_Name_1 := Project.Name;
2593 "{ cannot be an interface of project %% "
2594 & "as it is not one of its sources",
2595 Element.Location, Project);
2598 List := Element.Next;
2601 Project.Interfaces_Defined := True;
2603 elsif Project.Extends /= No_Project then
2604 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2606 if Project.Interfaces_Defined then
2607 Iter := For_Each_Source (Data.Tree, Project);
2609 Source := Prj.Element (Iter);
2610 exit when Source = No_Source;
2612 if not Source.Declared_In_Interfaces then
2613 Source.In_Interfaces := False;
2620 end Check_Interfaces;
2622 --------------------------
2623 -- Check_Package_Naming --
2624 --------------------------
2626 procedure Check_Package_Naming
2627 (Project : Project_Id;
2628 Data : in out Tree_Processing_Data;
2629 Bodies : out Array_Element_Id;
2630 Specs : out Array_Element_Id)
2632 Naming_Id : constant Package_Id :=
2634 (Name_Naming, Project.Decl.Packages, Data.Tree);
2635 Naming : Package_Element;
2637 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2639 procedure Check_Naming;
2640 -- Check the validity of the Naming package (suffixes valid, ...)
2642 procedure Check_Common
2643 (Dot_Replacement : in out File_Name_Type;
2644 Casing : in out Casing_Type;
2645 Casing_Defined : out Boolean;
2646 Separate_Suffix : in out File_Name_Type;
2647 Sep_Suffix_Loc : out Source_Ptr);
2648 -- Check attributes common
2650 procedure Process_Exceptions_File_Based
2651 (Lang_Id : Language_Ptr;
2652 Kind : Source_Kind);
2653 procedure Process_Exceptions_Unit_Based
2654 (Lang_Id : Language_Ptr;
2655 Kind : Source_Kind);
2656 -- Process the naming exceptions for the two types of languages
2658 procedure Initialize_Naming_Data;
2659 -- Initialize internal naming data for the various languages
2665 procedure Check_Common
2666 (Dot_Replacement : in out File_Name_Type;
2667 Casing : in out Casing_Type;
2668 Casing_Defined : out Boolean;
2669 Separate_Suffix : in out File_Name_Type;
2670 Sep_Suffix_Loc : out Source_Ptr)
2672 Dot_Repl : constant Variable_Value :=
2674 (Name_Dot_Replacement,
2675 Naming.Decl.Attributes,
2677 Casing_String : constant Variable_Value :=
2680 Naming.Decl.Attributes,
2682 Sep_Suffix : constant Variable_Value :=
2684 (Name_Separate_Suffix,
2685 Naming.Decl.Attributes,
2687 Dot_Repl_Loc : Source_Ptr;
2690 Sep_Suffix_Loc := No_Location;
2692 if not Dot_Repl.Default then
2694 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2696 if Length_Of_Name (Dot_Repl.Value) = 0 then
2698 (Data.Flags, "Dot_Replacement cannot be empty",
2699 Dot_Repl.Location, Project);
2702 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2703 Dot_Repl_Loc := Dot_Repl.Location;
2706 Repl : constant String := Get_Name_String (Dot_Replacement);
2709 -- Dot_Replacement cannot
2711 -- - start or end with an alphanumeric
2712 -- - be a single '_'
2713 -- - start with an '_' followed by an alphanumeric
2714 -- - contain a '.' except if it is "."
2717 or else Is_Alphanumeric (Repl (Repl'First))
2718 or else Is_Alphanumeric (Repl (Repl'Last))
2719 or else (Repl (Repl'First) = '_'
2723 Is_Alphanumeric (Repl (Repl'First + 1))))
2724 or else (Repl'Length > 1
2726 Index (Source => Repl, Pattern => ".") /= 0)
2731 """ is illegal for Dot_Replacement.",
2732 Dot_Repl_Loc, Project);
2737 if Dot_Replacement /= No_File then
2739 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2742 Casing_Defined := False;
2744 if not Casing_String.Default then
2746 (Casing_String.Kind = Single, "Casing is not a string");
2749 Casing_Image : constant String :=
2750 Get_Name_String (Casing_String.Value);
2753 if Casing_Image'Length = 0 then
2756 "Casing cannot be an empty string",
2757 Casing_String.Location, Project);
2760 Casing := Value (Casing_Image);
2761 Casing_Defined := True;
2764 when Constraint_Error =>
2765 Name_Len := Casing_Image'Length;
2766 Name_Buffer (1 .. Name_Len) := Casing_Image;
2767 Err_Vars.Error_Msg_Name_1 := Name_Find;
2770 "%% is not a correct Casing",
2771 Casing_String.Location, Project);
2775 Write_Attr ("Casing", Image (Casing));
2777 if not Sep_Suffix.Default then
2778 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2781 "Separate_Suffix cannot be empty",
2782 Sep_Suffix.Location, Project);
2785 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2786 Sep_Suffix_Loc := Sep_Suffix.Location;
2788 Check_Illegal_Suffix
2789 (Project, Separate_Suffix,
2790 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
2795 if Separate_Suffix /= No_File then
2797 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2801 -----------------------------------
2802 -- Process_Exceptions_File_Based --
2803 -----------------------------------
2805 procedure Process_Exceptions_File_Based
2806 (Lang_Id : Language_Ptr;
2809 Lang : constant Name_Id := Lang_Id.Name;
2810 Exceptions : Array_Element_Id;
2811 Exception_List : Variable_Value;
2812 Element_Id : String_List_Id;
2813 Element : String_Element;
2814 File_Name : File_Name_Type;
2816 Iter : Source_Iterator;
2823 (Name_Implementation_Exceptions,
2824 In_Arrays => Naming.Decl.Arrays,
2825 In_Tree => Data.Tree);
2830 (Name_Specification_Exceptions,
2831 In_Arrays => Naming.Decl.Arrays,
2832 In_Tree => Data.Tree);
2835 Exception_List := Value_Of
2837 In_Array => Exceptions,
2838 In_Tree => Data.Tree);
2840 if Exception_List /= Nil_Variable_Value then
2841 Element_Id := Exception_List.Values;
2842 while Element_Id /= Nil_String loop
2843 Element := Data.Tree.String_Elements.Table (Element_Id);
2844 File_Name := Canonical_Case_File_Name (Element.Value);
2846 Iter := For_Each_Source (Data.Tree, Project);
2848 Source := Prj.Element (Iter);
2849 exit when Source = No_Source or else Source.File = File_Name;
2853 if Source = No_Source then
2858 Source_Dir_Rank => 0,
2861 File_Name => File_Name,
2862 Display_File => File_Name_Type (Element.Value),
2863 Naming_Exception => True);
2866 -- Check if the file name is already recorded for another
2867 -- language or another kind.
2869 if Source.Language /= Lang_Id then
2872 "the same file cannot be a source of two languages",
2873 Element.Location, Project);
2875 elsif Source.Kind /= Kind then
2878 "the same file cannot be a source and a template",
2879 Element.Location, Project);
2882 -- If the file is already recorded for the same
2883 -- language and the same kind, it means that the file
2884 -- name appears several times in the *_Exceptions
2885 -- attribute; so there is nothing to do.
2888 Element_Id := Element.Next;
2891 end Process_Exceptions_File_Based;
2893 -----------------------------------
2894 -- Process_Exceptions_Unit_Based --
2895 -----------------------------------
2897 procedure Process_Exceptions_Unit_Based
2898 (Lang_Id : Language_Ptr;
2901 Lang : constant Name_Id := Lang_Id.Name;
2902 Exceptions : Array_Element_Id;
2903 Element : Array_Element;
2906 File_Name : File_Name_Type;
2915 In_Arrays => Naming.Decl.Arrays,
2916 In_Tree => Data.Tree);
2918 if Exceptions = No_Array_Element then
2921 (Name_Implementation,
2922 In_Arrays => Naming.Decl.Arrays,
2923 In_Tree => Data.Tree);
2930 In_Arrays => Naming.Decl.Arrays,
2931 In_Tree => Data.Tree);
2933 if Exceptions = No_Array_Element then
2937 In_Arrays => Naming.Decl.Arrays,
2938 In_Tree => Data.Tree);
2942 while Exceptions /= No_Array_Element loop
2943 Element := Data.Tree.Array_Elements.Table (Exceptions);
2944 File_Name := Canonical_Case_File_Name (Element.Value.Value);
2946 Get_Name_String (Element.Index);
2947 To_Lower (Name_Buffer (1 .. Name_Len));
2949 Index := Element.Value.Index;
2951 -- For Ada, check if it is a valid unit name
2953 if Lang = Name_Ada then
2954 Get_Name_String (Element.Index);
2955 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2957 if Unit = No_Name then
2958 Err_Vars.Error_Msg_Name_1 := Element.Index;
2961 "%% is not a valid unit name.",
2962 Element.Value.Location, Project);
2966 if Unit /= No_Name then
2971 Source_Dir_Rank => 0,
2974 File_Name => File_Name,
2975 Display_File => File_Name_Type (Element.Value.Value),
2978 Location => Element.Value.Location,
2979 Naming_Exception => True);
2982 Exceptions := Element.Next;
2984 end Process_Exceptions_Unit_Based;
2990 procedure Check_Naming is
2991 Dot_Replacement : File_Name_Type :=
2993 (First_Name_Id + Character'Pos ('-'));
2994 Separate_Suffix : File_Name_Type := No_File;
2995 Casing : Casing_Type := All_Lower_Case;
2996 Casing_Defined : Boolean;
2997 Lang_Id : Language_Ptr;
2998 Sep_Suffix_Loc : Source_Ptr;
2999 Suffix : Variable_Value;
3004 (Dot_Replacement => Dot_Replacement,
3006 Casing_Defined => Casing_Defined,
3007 Separate_Suffix => Separate_Suffix,
3008 Sep_Suffix_Loc => Sep_Suffix_Loc);
3010 -- For all unit based languages, if any, set the specified value
3011 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3012 -- systematically overwrite, since the defaults come from the
3013 -- configuration file.
3015 if Dot_Replacement /= No_File
3016 or else Casing_Defined
3017 or else Separate_Suffix /= No_File
3019 Lang_Id := Project.Languages;
3020 while Lang_Id /= No_Language_Index loop
3021 if Lang_Id.Config.Kind = Unit_Based then
3022 if Dot_Replacement /= No_File then
3023 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3027 if Casing_Defined then
3028 Lang_Id.Config.Naming_Data.Casing := Casing;
3032 Lang_Id := Lang_Id.Next;
3036 -- Next, get the spec and body suffixes
3038 Lang_Id := Project.Languages;
3039 while Lang_Id /= No_Language_Index loop
3040 Lang := Lang_Id.Name;
3046 Attribute_Or_Array_Name => Name_Spec_Suffix,
3047 In_Package => Naming_Id,
3048 In_Tree => Data.Tree);
3050 if Suffix = Nil_Variable_Value then
3053 Attribute_Or_Array_Name => Name_Specification_Suffix,
3054 In_Package => Naming_Id,
3055 In_Tree => Data.Tree);
3058 if Suffix /= Nil_Variable_Value then
3059 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3060 File_Name_Type (Suffix.Value);
3062 Check_Illegal_Suffix
3064 Lang_Id.Config.Naming_Data.Spec_Suffix,
3065 Lang_Id.Config.Naming_Data.Dot_Replacement,
3066 "Spec_Suffix", Suffix.Location, Data);
3070 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3078 Attribute_Or_Array_Name => Name_Body_Suffix,
3079 In_Package => Naming_Id,
3080 In_Tree => Data.Tree);
3082 if Suffix = Nil_Variable_Value then
3086 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3087 In_Package => Naming_Id,
3088 In_Tree => Data.Tree);
3091 if Suffix /= Nil_Variable_Value then
3092 Lang_Id.Config.Naming_Data.Body_Suffix :=
3093 File_Name_Type (Suffix.Value);
3095 -- The default value of separate suffix should be the same as
3096 -- the body suffix, so we need to compute that first.
3098 if Separate_Suffix = No_File then
3099 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3100 Lang_Id.Config.Naming_Data.Body_Suffix;
3104 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3106 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3110 Check_Illegal_Suffix
3112 Lang_Id.Config.Naming_Data.Body_Suffix,
3113 Lang_Id.Config.Naming_Data.Dot_Replacement,
3114 "Body_Suffix", Suffix.Location, Data);
3118 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3120 elsif Separate_Suffix /= No_File then
3121 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3124 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3125 -- since that would cause a clear ambiguity. Note that we do allow
3126 -- a Spec_Suffix to have the same termination as one of these,
3127 -- which causes a potential ambiguity, but we resolve that my
3128 -- matching the longest possible suffix.
3130 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3131 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3132 Lang_Id.Config.Naming_Data.Body_Suffix
3137 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3138 & """) cannot be the same as Spec_Suffix.",
3139 Ada_Body_Suffix_Loc, Project);
3142 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3143 Lang_Id.Config.Naming_Data.Separate_Suffix
3144 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3145 Lang_Id.Config.Naming_Data.Separate_Suffix
3149 "Separate_Suffix ("""
3151 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3152 & """) cannot be the same as Spec_Suffix.",
3153 Sep_Suffix_Loc, Project);
3156 Lang_Id := Lang_Id.Next;
3159 -- Get the naming exceptions for all languages
3161 for Kind in Spec .. Impl loop
3162 Lang_Id := Project.Languages;
3163 while Lang_Id /= No_Language_Index loop
3164 case Lang_Id.Config.Kind is
3166 Process_Exceptions_File_Based (Lang_Id, Kind);
3169 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3172 Lang_Id := Lang_Id.Next;
3177 ----------------------------
3178 -- Initialize_Naming_Data --
3179 ----------------------------
3181 procedure Initialize_Naming_Data is
3182 Specs : Array_Element_Id :=
3188 Impls : Array_Element_Id :=
3194 Lang : Language_Ptr;
3195 Lang_Name : Name_Id;
3196 Value : Variable_Value;
3197 Extended : Project_Id;
3200 -- At this stage, the project already contains the default extensions
3201 -- for the various languages. We now merge those suffixes read in the
3202 -- user project, and they override the default.
3204 while Specs /= No_Array_Element loop
3205 Lang_Name := Data.Tree.Array_Elements.Table (Specs).Index;
3207 Get_Language_From_Name
3208 (Project, Name => Get_Name_String (Lang_Name));
3210 -- An extending project inherits its parent projects' languages
3211 -- so if needed we should create entries for those languages
3214 Extended := Project.Extends;
3215 while Extended /= null loop
3216 Lang := Get_Language_From_Name
3217 (Extended, Name => Get_Name_String (Lang_Name));
3218 exit when Lang /= null;
3220 Extended := Extended.Extends;
3223 if Lang /= null then
3224 Lang := new Language_Data'(Lang.all);
3225 Lang.First_Source := null;
3226 Lang.Next := Project.Languages;
3227 Project.Languages := Lang;
3231 -- If language was not found in project or the projects it extends
3234 if Current_Verbosity = High then
3236 ("Ignoring spec naming data for "
3237 & Get_Name_String (Lang_Name)
3238 & " since language is not defined for this project");
3242 Value := Data.Tree.Array_Elements.Table (Specs).Value;
3244 if Value.Kind = Single then
3245 Lang.Config.Naming_Data.Spec_Suffix :=
3246 Canonical_Case_File_Name (Value.Value);
3250 Specs := Data.Tree.Array_Elements.Table (Specs).Next;
3253 while Impls /= No_Array_Element loop
3254 Lang_Name := Data.Tree.Array_Elements.Table (Impls).Index;
3256 Get_Language_From_Name
3257 (Project, Name => Get_Name_String (Lang_Name));
3260 if Current_Verbosity = High then
3262 ("Ignoring impl naming data for "
3263 & Get_Name_String (Lang_Name)
3264 & " since language is not defined for this project");
3267 Value := Data.Tree.Array_Elements.Table (Impls).Value;
3269 if Lang.Name = Name_Ada then
3270 Ada_Body_Suffix_Loc := Value.Location;
3273 if Value.Kind = Single then
3274 Lang.Config.Naming_Data.Body_Suffix :=
3275 Canonical_Case_File_Name (Value.Value);
3279 Impls := Data.Tree.Array_Elements.Table (Impls).Next;
3281 end Initialize_Naming_Data;
3283 -- Start of processing for Check_Naming_Schemes
3286 Specs := No_Array_Element;
3287 Bodies := No_Array_Element;
3289 -- No Naming package or parsing a configuration file? nothing to do
3291 if Naming_Id /= No_Package
3292 and then Project.Qualifier /= Configuration
3294 Naming := Data.Tree.Packages.Table (Naming_Id);
3296 if Current_Verbosity = High then
3297 Write_Line ("Checking package Naming for project "
3298 & Get_Name_String (Project.Name));
3301 Initialize_Naming_Data;
3304 end Check_Package_Naming;
3306 ------------------------------
3307 -- Check_Library_Attributes --
3308 ------------------------------
3310 procedure Check_Library_Attributes
3311 (Project : Project_Id;
3312 Data : in out Tree_Processing_Data)
3314 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3316 Lib_Dir : constant Prj.Variable_Value :=
3318 (Snames.Name_Library_Dir, Attributes, Data.Tree);
3320 Lib_Name : constant Prj.Variable_Value :=
3322 (Snames.Name_Library_Name, Attributes, Data.Tree);
3324 Lib_Version : constant Prj.Variable_Value :=
3326 (Snames.Name_Library_Version, Attributes, Data.Tree);
3328 Lib_ALI_Dir : constant Prj.Variable_Value :=
3330 (Snames.Name_Library_Ali_Dir, Attributes, Data.Tree);
3332 Lib_GCC : constant Prj.Variable_Value :=
3334 (Snames.Name_Library_GCC, Attributes, Data.Tree);
3336 The_Lib_Kind : constant Prj.Variable_Value :=
3338 (Snames.Name_Library_Kind, Attributes, Data.Tree);
3340 Imported_Project_List : Project_List;
3342 Continuation : String_Access := No_Continuation_String'Access;
3344 Support_For_Libraries : Library_Support;
3346 Library_Directory_Present : Boolean;
3348 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3349 -- Check if an imported or extended project if also a library project
3355 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3357 Iter : Source_Iterator;
3360 if Proj /= No_Project then
3361 if not Proj.Library then
3363 -- The only not library projects that are OK are those that
3364 -- have no sources. However, header files from non-Ada
3365 -- languages are OK, as there is nothing to compile.
3367 Iter := For_Each_Source (Data.Tree, Proj);
3369 Src_Id := Prj.Element (Iter);
3370 exit when Src_Id = No_Source
3371 or else Src_Id.Language.Config.Kind /= File_Based
3372 or else Src_Id.Kind /= Spec;
3376 if Src_Id /= No_Source then
3377 Error_Msg_Name_1 := Project.Name;
3378 Error_Msg_Name_2 := Proj.Name;
3381 if Project.Library_Kind /= Static then
3385 "shared library project %% cannot extend " &
3386 "project %% that is not a library project",
3387 Project.Location, Project);
3388 Continuation := Continuation_String'Access;
3391 elsif (not Unchecked_Shared_Lib_Imports)
3392 and then Project.Library_Kind /= Static
3397 "shared library project %% cannot import project %% " &
3398 "that is not a shared library project",
3399 Project.Location, Project);
3400 Continuation := Continuation_String'Access;
3404 elsif Project.Library_Kind /= Static and then
3405 Proj.Library_Kind = Static
3407 Error_Msg_Name_1 := Project.Name;
3408 Error_Msg_Name_2 := Proj.Name;
3414 "shared library project %% cannot extend static " &
3415 "library project %%",
3416 Project.Location, Project);
3417 Continuation := Continuation_String'Access;
3419 elsif not Unchecked_Shared_Lib_Imports then
3423 "shared library project %% cannot import static " &
3424 "library project %%",
3425 Project.Location, Project);
3426 Continuation := Continuation_String'Access;
3433 Dir_Exists : Boolean;
3435 -- Start of processing for Check_Library_Attributes
3438 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3440 -- Special case of extending project
3442 if Project.Extends /= No_Project then
3444 -- If the project extended is a library project, we inherit the
3445 -- library name, if it is not redefined; we check that the library
3446 -- directory is specified.
3448 if Project.Extends.Library then
3449 if Project.Qualifier = Standard then
3452 "a standard project cannot extend a library project",
3453 Project.Location, Project);
3456 if Lib_Name.Default then
3457 Project.Library_Name := Project.Extends.Library_Name;
3460 if Lib_Dir.Default then
3461 if not Project.Virtual then
3464 "a project extending a library project must " &
3465 "specify an attribute Library_Dir",
3466 Project.Location, Project);
3469 -- For a virtual project extending a library project,
3470 -- inherit library directory.
3472 Project.Library_Dir := Project.Extends.Library_Dir;
3473 Library_Directory_Present := True;
3480 pragma Assert (Lib_Name.Kind = Single);
3482 if Lib_Name.Value = Empty_String then
3483 if Current_Verbosity = High
3484 and then Project.Library_Name = No_Name
3486 Write_Line ("No library name");
3490 -- There is no restriction on the syntax of library names
3492 Project.Library_Name := Lib_Name.Value;
3495 if Project.Library_Name /= No_Name then
3496 if Current_Verbosity = High then
3498 ("Library name", Get_Name_String (Project.Library_Name));
3501 pragma Assert (Lib_Dir.Kind = Single);
3503 if not Library_Directory_Present then
3504 if Current_Verbosity = High then
3505 Write_Line ("No library directory");
3509 -- Find path name (unless inherited), check that it is a directory
3511 if Project.Library_Dir = No_Path_Information then
3514 File_Name_Type (Lib_Dir.Value),
3515 Path => Project.Library_Dir,
3516 Dir_Exists => Dir_Exists,
3518 Create => "library",
3519 Must_Exist => False,
3520 Location => Lib_Dir.Location,
3521 Externally_Built => Project.Externally_Built);
3527 (Project.Library_Dir.Display_Name));
3530 if not Dir_Exists then
3532 -- Get the absolute name of the library directory that
3533 -- does not exist, to report an error.
3535 Err_Vars.Error_Msg_File_1 :=
3536 File_Name_Type (Project.Library_Dir.Display_Name);
3539 "library directory { does not exist",
3540 Lib_Dir.Location, Project);
3542 -- The library directory cannot be the same as the Object
3545 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3548 "library directory cannot be the same " &
3549 "as object directory",
3550 Lib_Dir.Location, Project);
3551 Project.Library_Dir := No_Path_Information;
3555 OK : Boolean := True;
3556 Dirs_Id : String_List_Id;
3557 Dir_Elem : String_Element;
3561 -- The library directory cannot be the same as a source
3562 -- directory of the current project.
3564 Dirs_Id := Project.Source_Dirs;
3565 while Dirs_Id /= Nil_String loop
3566 Dir_Elem := Data.Tree.String_Elements.Table (Dirs_Id);
3567 Dirs_Id := Dir_Elem.Next;
3569 if Project.Library_Dir.Name =
3570 Path_Name_Type (Dir_Elem.Value)
3572 Err_Vars.Error_Msg_File_1 :=
3573 File_Name_Type (Dir_Elem.Value);
3576 "library directory cannot be the same " &
3577 "as source directory {",
3578 Lib_Dir.Location, Project);
3586 -- The library directory cannot be the same as a source
3587 -- directory of another project either.
3589 Pid := Data.Tree.Projects;
3591 exit Project_Loop when Pid = null;
3593 if Pid.Project /= Project then
3594 Dirs_Id := Pid.Project.Source_Dirs;
3596 Dir_Loop : while Dirs_Id /= Nil_String loop
3598 Data.Tree.String_Elements.Table (Dirs_Id);
3599 Dirs_Id := Dir_Elem.Next;
3601 if Project.Library_Dir.Name =
3602 Path_Name_Type (Dir_Elem.Value)
3604 Err_Vars.Error_Msg_File_1 :=
3605 File_Name_Type (Dir_Elem.Value);
3606 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3610 "library directory cannot be the same " &
3611 "as source directory { of project %%",
3612 Lib_Dir.Location, Project);
3620 end loop Project_Loop;
3624 Project.Library_Dir := No_Path_Information;
3626 elsif Current_Verbosity = High then
3628 -- Display the Library directory in high verbosity
3631 ("Library directory",
3632 Get_Name_String (Project.Library_Dir.Display_Name));
3641 Project.Library_Dir /= No_Path_Information
3642 and then Project.Library_Name /= No_Name;
3644 if Project.Extends = No_Project then
3645 case Project.Qualifier is
3647 if Project.Library then
3650 "a standard project cannot be a library project",
3651 Lib_Name.Location, Project);
3655 if not Project.Library then
3656 if Project.Library_Dir = No_Path_Information then
3659 "\attribute Library_Dir not declared",
3660 Project.Location, Project);
3663 if Project.Library_Name = No_Name then
3666 "\attribute Library_Name not declared",
3667 Project.Location, Project);
3677 if Project.Library then
3678 Support_For_Libraries := Project.Config.Lib_Support;
3680 if Support_For_Libraries = Prj.None then
3683 "?libraries are not supported on this platform",
3684 Lib_Name.Location, Project);
3685 Project.Library := False;
3688 if Lib_ALI_Dir.Value = Empty_String then
3689 if Current_Verbosity = High then
3690 Write_Line ("No library ALI directory specified");
3693 Project.Library_ALI_Dir := Project.Library_Dir;
3696 -- Find path name, check that it is a directory
3700 File_Name_Type (Lib_ALI_Dir.Value),
3701 Path => Project.Library_ALI_Dir,
3702 Create => "library ALI",
3703 Dir_Exists => Dir_Exists,
3705 Must_Exist => False,
3706 Location => Lib_ALI_Dir.Location,
3707 Externally_Built => Project.Externally_Built);
3709 if not Dir_Exists then
3711 -- Get the absolute name of the library ALI directory that
3712 -- does not exist, to report an error.
3714 Err_Vars.Error_Msg_File_1 :=
3715 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3718 "library 'A'L'I directory { does not exist",
3719 Lib_ALI_Dir.Location, Project);
3722 if Project.Library_ALI_Dir /= Project.Library_Dir then
3724 -- The library ALI directory cannot be the same as the
3725 -- Object directory.
3727 if Project.Library_ALI_Dir = Project.Object_Directory then
3730 "library 'A'L'I directory cannot be the same " &
3731 "as object directory",
3732 Lib_ALI_Dir.Location, Project);
3733 Project.Library_ALI_Dir := No_Path_Information;
3737 OK : Boolean := True;
3738 Dirs_Id : String_List_Id;
3739 Dir_Elem : String_Element;
3743 -- The library ALI directory cannot be the same as
3744 -- a source directory of the current project.
3746 Dirs_Id := Project.Source_Dirs;
3747 while Dirs_Id /= Nil_String loop
3749 Data.Tree.String_Elements.Table (Dirs_Id);
3750 Dirs_Id := Dir_Elem.Next;
3752 if Project.Library_ALI_Dir.Name =
3753 Path_Name_Type (Dir_Elem.Value)
3755 Err_Vars.Error_Msg_File_1 :=
3756 File_Name_Type (Dir_Elem.Value);
3759 "library 'A'L'I directory cannot be " &
3760 "the same as source directory {",
3761 Lib_ALI_Dir.Location, Project);
3769 -- The library ALI directory cannot be the same as
3770 -- a source directory of another project either.
3772 Pid := Data.Tree.Projects;
3773 ALI_Project_Loop : loop
3774 exit ALI_Project_Loop when Pid = null;
3776 if Pid.Project /= Project then
3777 Dirs_Id := Pid.Project.Source_Dirs;
3780 while Dirs_Id /= Nil_String loop
3782 Data.Tree.String_Elements.Table
3784 Dirs_Id := Dir_Elem.Next;
3786 if Project.Library_ALI_Dir.Name =
3787 Path_Name_Type (Dir_Elem.Value)
3789 Err_Vars.Error_Msg_File_1 :=
3790 File_Name_Type (Dir_Elem.Value);
3791 Err_Vars.Error_Msg_Name_1 :=
3796 "library 'A'L'I directory cannot " &
3797 "be the same as source directory " &
3799 Lib_ALI_Dir.Location, Project);
3801 exit ALI_Project_Loop;
3803 end loop ALI_Dir_Loop;
3806 end loop ALI_Project_Loop;
3810 Project.Library_ALI_Dir := No_Path_Information;
3812 elsif Current_Verbosity = High then
3814 -- Display Library ALI directory in high verbosity
3819 (Project.Library_ALI_Dir.Display_Name));
3826 pragma Assert (Lib_Version.Kind = Single);
3828 if Lib_Version.Value = Empty_String then
3829 if Current_Verbosity = High then
3830 Write_Line ("No library version specified");
3834 Project.Lib_Internal_Name := Lib_Version.Value;
3837 pragma Assert (The_Lib_Kind.Kind = Single);
3839 if The_Lib_Kind.Value = Empty_String then
3840 if Current_Verbosity = High then
3841 Write_Line ("No library kind specified");
3845 Get_Name_String (The_Lib_Kind.Value);
3848 Kind_Name : constant String :=
3849 To_Lower (Name_Buffer (1 .. Name_Len));
3851 OK : Boolean := True;
3854 if Kind_Name = "static" then
3855 Project.Library_Kind := Static;
3857 elsif Kind_Name = "dynamic" then
3858 Project.Library_Kind := Dynamic;
3860 elsif Kind_Name = "relocatable" then
3861 Project.Library_Kind := Relocatable;
3866 "illegal value for Library_Kind",
3867 The_Lib_Kind.Location, Project);
3871 if Current_Verbosity = High and then OK then
3872 Write_Attr ("Library kind", Kind_Name);
3875 if Project.Library_Kind /= Static then
3876 if Support_For_Libraries = Prj.Static_Only then
3879 "only static libraries are supported " &
3881 The_Lib_Kind.Location, Project);
3882 Project.Library := False;
3885 -- Check if (obsolescent) attribute Library_GCC or
3886 -- Linker'Driver is declared.
3888 if Lib_GCC.Value /= Empty_String then
3891 "?Library_'G'C'C is an obsolescent attribute, " &
3892 "use Linker''Driver instead",
3893 Lib_GCC.Location, Project);
3894 Project.Config.Shared_Lib_Driver :=
3895 File_Name_Type (Lib_GCC.Value);
3899 Linker : constant Package_Id :=
3902 Project.Decl.Packages,
3904 Driver : constant Variable_Value :=
3907 Attribute_Or_Array_Name =>
3909 In_Package => Linker,
3910 In_Tree => Data.Tree);
3913 if Driver /= Nil_Variable_Value
3914 and then Driver.Value /= Empty_String
3916 Project.Config.Shared_Lib_Driver :=
3917 File_Name_Type (Driver.Value);
3926 if Project.Library then
3927 if Current_Verbosity = High then
3928 Write_Line ("This is a library project file");
3931 Check_Library (Project.Extends, Extends => True);
3933 Imported_Project_List := Project.Imported_Projects;
3934 while Imported_Project_List /= null loop
3936 (Imported_Project_List.Project,
3938 Imported_Project_List := Imported_Project_List.Next;
3945 -- Check if Linker'Switches or Linker'Default_Switches are declared.
3946 -- Warn if they are declared, as it is a common error to think that
3947 -- library are "linked" with Linker switches.
3949 if Project.Library then
3951 Linker_Package_Id : constant Package_Id :=
3954 Project.Decl.Packages, Data.Tree);
3955 Linker_Package : Package_Element;
3956 Switches : Array_Element_Id := No_Array_Element;
3959 if Linker_Package_Id /= No_Package then
3960 Linker_Package := Data.Tree.Packages.Table (Linker_Package_Id);
3964 (Name => Name_Switches,
3965 In_Arrays => Linker_Package.Decl.Arrays,
3966 In_Tree => Data.Tree);
3968 if Switches = No_Array_Element then
3971 (Name => Name_Default_Switches,
3972 In_Arrays => Linker_Package.Decl.Arrays,
3973 In_Tree => Data.Tree);
3976 if Switches /= No_Array_Element then
3979 "?Linker switches not taken into account in library " &
3981 No_Location, Project);
3987 if Project.Extends /= No_Project then
3988 Project.Extends.Library := False;
3990 end Check_Library_Attributes;
3992 ---------------------------------
3993 -- Check_Programming_Languages --
3994 ---------------------------------
3996 procedure Check_Programming_Languages
3997 (Project : Project_Id;
3998 Data : in out Tree_Processing_Data)
4000 Languages : Variable_Value := Nil_Variable_Value;
4001 Def_Lang : Variable_Value := Nil_Variable_Value;
4002 Def_Lang_Id : Name_Id;
4004 procedure Add_Language (Name, Display_Name : Name_Id);
4005 -- Add a new language to the list of languages for the project.
4006 -- Nothing is done if the language has already been defined
4012 procedure Add_Language (Name, Display_Name : Name_Id) is
4013 Lang : Language_Ptr;
4016 Lang := Project.Languages;
4017 while Lang /= No_Language_Index loop
4018 if Name = Lang.Name then
4025 Lang := new Language_Data'(No_Language_Data);
4026 Lang.Next := Project.Languages;
4027 Project.Languages := Lang;
4029 Lang.Display_Name := Display_Name;
4031 if Name = Name_Ada then
4032 Lang.Config.Kind := Unit_Based;
4033 Lang.Config.Dependency_Kind := ALI_File;
4035 Lang.Config.Kind := File_Based;
4039 -- Start of processing for Check_Programming_Languages
4042 Project.Languages := null;
4044 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Data.Tree);
4047 (Name_Default_Language, Project.Decl.Attributes, Data.Tree);
4049 if Project.Source_Dirs /= Nil_String then
4051 -- Check if languages are specified in this project
4053 if Languages.Default then
4055 -- Fail if there is no default language defined
4057 if Def_Lang.Default then
4060 "no languages defined for this project",
4061 Project.Location, Project);
4062 Def_Lang_Id := No_Name;
4065 Get_Name_String (Def_Lang.Value);
4066 To_Lower (Name_Buffer (1 .. Name_Len));
4067 Def_Lang_Id := Name_Find;
4070 if Def_Lang_Id /= No_Name then
4071 Get_Name_String (Def_Lang_Id);
4072 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4074 (Name => Def_Lang_Id,
4075 Display_Name => Name_Find);
4080 Current : String_List_Id := Languages.Values;
4081 Element : String_Element;
4084 -- If there are no languages declared, there are no sources
4086 if Current = Nil_String then
4087 Project.Source_Dirs := Nil_String;
4089 if Project.Qualifier = Standard then
4092 "a standard project must have at least one language",
4093 Languages.Location, Project);
4097 -- Look through all the languages specified in attribute
4100 while Current /= Nil_String loop
4101 Element := Data.Tree.String_Elements.Table (Current);
4102 Get_Name_String (Element.Value);
4103 To_Lower (Name_Buffer (1 .. Name_Len));
4107 Display_Name => Element.Value);
4109 Current := Element.Next;
4115 end Check_Programming_Languages;
4117 -------------------------------
4118 -- Check_Stand_Alone_Library --
4119 -------------------------------
4121 procedure Check_Stand_Alone_Library
4122 (Project : Project_Id;
4123 Data : in out Tree_Processing_Data)
4125 Lib_Interfaces : constant Prj.Variable_Value :=
4127 (Snames.Name_Library_Interface,
4128 Project.Decl.Attributes,
4131 Lib_Auto_Init : constant Prj.Variable_Value :=
4133 (Snames.Name_Library_Auto_Init,
4134 Project.Decl.Attributes,
4137 Lib_Src_Dir : constant Prj.Variable_Value :=
4139 (Snames.Name_Library_Src_Dir,
4140 Project.Decl.Attributes,
4143 Lib_Symbol_File : constant Prj.Variable_Value :=
4145 (Snames.Name_Library_Symbol_File,
4146 Project.Decl.Attributes,
4149 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4151 (Snames.Name_Library_Symbol_Policy,
4152 Project.Decl.Attributes,
4155 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4157 (Snames.Name_Library_Reference_Symbol_File,
4158 Project.Decl.Attributes,
4161 Auto_Init_Supported : Boolean;
4162 OK : Boolean := True;
4164 Next_Proj : Project_Id;
4165 Iter : Source_Iterator;
4168 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4170 pragma Assert (Lib_Interfaces.Kind = List);
4172 -- It is a stand-alone library project file if attribute
4173 -- Library_Interface is defined.
4175 if not Lib_Interfaces.Default then
4177 Interfaces : String_List_Id := Lib_Interfaces.Values;
4178 Interface_ALIs : String_List_Id := Nil_String;
4182 Project.Standalone_Library := True;
4184 -- Library_Interface cannot be an empty list
4186 if Interfaces = Nil_String then
4189 "Library_Interface cannot be an empty list",
4190 Lib_Interfaces.Location, Project);
4193 -- Process each unit name specified in the attribute
4194 -- Library_Interface.
4196 while Interfaces /= Nil_String loop
4198 (Data.Tree.String_Elements.Table (Interfaces).Value);
4199 To_Lower (Name_Buffer (1 .. Name_Len));
4201 if Name_Len = 0 then
4204 "an interface cannot be an empty string",
4205 Data.Tree.String_Elements.Table (Interfaces).Location,
4210 Error_Msg_Name_1 := Unit;
4212 Next_Proj := Project.Extends;
4213 Iter := For_Each_Source (Data.Tree, Project);
4215 while Prj.Element (Iter) /= No_Source
4217 (Prj.Element (Iter).Unit = null
4218 or else Prj.Element (Iter).Unit.Name /= Unit)
4223 Source := Prj.Element (Iter);
4224 exit when Source /= No_Source
4225 or else Next_Proj = No_Project;
4227 Iter := For_Each_Source (Data.Tree, Next_Proj);
4228 Next_Proj := Next_Proj.Extends;
4231 if Source /= No_Source then
4232 if Source.Kind = Sep then
4233 Source := No_Source;
4235 elsif Source.Kind = Spec
4236 and then Other_Part (Source) /= No_Source
4238 Source := Other_Part (Source);
4242 if Source /= No_Source then
4243 if Source.Project /= Project
4244 and then not Is_Extending (Project, Source.Project)
4246 Source := No_Source;
4250 if Source = No_Source then
4253 "%% is not a unit of this project",
4254 Data.Tree.String_Elements.Table
4255 (Interfaces).Location, Project);
4258 if Source.Kind = Spec
4259 and then Other_Part (Source) /= No_Source
4261 Source := Other_Part (Source);
4264 String_Element_Table.Increment_Last
4265 (Data.Tree.String_Elements);
4267 Data.Tree.String_Elements.Table
4268 (String_Element_Table.Last
4269 (Data.Tree.String_Elements)) :=
4270 (Value => Name_Id (Source.Dep_Name),
4272 Display_Value => Name_Id (Source.Dep_Name),
4274 Data.Tree.String_Elements.Table
4275 (Interfaces).Location,
4277 Next => Interface_ALIs);
4280 String_Element_Table.Last
4281 (Data.Tree.String_Elements);
4285 Interfaces := Data.Tree.String_Elements.Table (Interfaces).Next;
4288 -- Put the list of Interface ALIs in the project data
4290 Project.Lib_Interface_ALIs := Interface_ALIs;
4292 -- Check value of attribute Library_Auto_Init and set
4293 -- Lib_Auto_Init accordingly.
4295 if Lib_Auto_Init.Default then
4297 -- If no attribute Library_Auto_Init is declared, then set auto
4298 -- init only if it is supported.
4300 Project.Lib_Auto_Init := Auto_Init_Supported;
4303 Get_Name_String (Lib_Auto_Init.Value);
4304 To_Lower (Name_Buffer (1 .. Name_Len));
4306 if Name_Buffer (1 .. Name_Len) = "false" then
4307 Project.Lib_Auto_Init := False;
4309 elsif Name_Buffer (1 .. Name_Len) = "true" then
4310 if Auto_Init_Supported then
4311 Project.Lib_Auto_Init := True;
4314 -- Library_Auto_Init cannot be "true" if auto init is not
4319 "library auto init not supported " &
4321 Lib_Auto_Init.Location, Project);
4327 "invalid value for attribute Library_Auto_Init",
4328 Lib_Auto_Init.Location, Project);
4333 -- If attribute Library_Src_Dir is defined and not the empty string,
4334 -- check if the directory exist and is not the object directory or
4335 -- one of the source directories. This is the directory where copies
4336 -- of the interface sources will be copied. Note that this directory
4337 -- may be the library directory.
4339 if Lib_Src_Dir.Value /= Empty_String then
4341 Dir_Id : constant File_Name_Type :=
4342 File_Name_Type (Lib_Src_Dir.Value);
4343 Dir_Exists : Boolean;
4349 Path => Project.Library_Src_Dir,
4350 Dir_Exists => Dir_Exists,
4352 Must_Exist => False,
4353 Create => "library source copy",
4354 Location => Lib_Src_Dir.Location,
4355 Externally_Built => Project.Externally_Built);
4357 -- If directory does not exist, report an error
4359 if not Dir_Exists then
4361 -- Get the absolute name of the library directory that does
4362 -- not exist, to report an error.
4364 Err_Vars.Error_Msg_File_1 :=
4365 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4368 "Directory { does not exist",
4369 Lib_Src_Dir.Location, Project);
4371 -- Report error if it is the same as the object directory
4373 elsif Project.Library_Src_Dir = Project.Object_Directory then
4376 "directory to copy interfaces cannot be " &
4377 "the object directory",
4378 Lib_Src_Dir.Location, Project);
4379 Project.Library_Src_Dir := No_Path_Information;
4383 Src_Dirs : String_List_Id;
4384 Src_Dir : String_Element;
4388 -- Interface copy directory cannot be one of the source
4389 -- directory of the current project.
4391 Src_Dirs := Project.Source_Dirs;
4392 while Src_Dirs /= Nil_String loop
4393 Src_Dir := Data.Tree.String_Elements.Table (Src_Dirs);
4395 -- Report error if it is one of the source directories
4397 if Project.Library_Src_Dir.Name =
4398 Path_Name_Type (Src_Dir.Value)
4402 "directory to copy interfaces cannot " &
4403 "be one of the source directories",
4404 Lib_Src_Dir.Location, Project);
4405 Project.Library_Src_Dir := No_Path_Information;
4409 Src_Dirs := Src_Dir.Next;
4412 if Project.Library_Src_Dir /= No_Path_Information then
4414 -- It cannot be a source directory of any other
4417 Pid := Data.Tree.Projects;
4419 exit Project_Loop when Pid = null;
4421 Src_Dirs := Pid.Project.Source_Dirs;
4422 Dir_Loop : while Src_Dirs /= Nil_String loop
4424 Data.Tree.String_Elements.Table (Src_Dirs);
4426 -- Report error if it is one of the source
4429 if Project.Library_Src_Dir.Name =
4430 Path_Name_Type (Src_Dir.Value)
4433 File_Name_Type (Src_Dir.Value);
4434 Error_Msg_Name_1 := Pid.Project.Name;
4437 "directory to copy interfaces cannot " &
4438 "be the same as source directory { of " &
4440 Lib_Src_Dir.Location, Project);
4441 Project.Library_Src_Dir :=
4442 No_Path_Information;
4446 Src_Dirs := Src_Dir.Next;
4450 end loop Project_Loop;
4454 -- In high verbosity, if there is a valid Library_Src_Dir,
4455 -- display its path name.
4457 if Project.Library_Src_Dir /= No_Path_Information
4458 and then Current_Verbosity = High
4461 ("Directory to copy interfaces",
4462 Get_Name_String (Project.Library_Src_Dir.Name));
4468 -- Check the symbol related attributes
4470 -- First, the symbol policy
4472 if not Lib_Symbol_Policy.Default then
4474 Value : constant String :=
4476 (Get_Name_String (Lib_Symbol_Policy.Value));
4479 -- Symbol policy must hove one of a limited number of values
4481 if Value = "autonomous" or else Value = "default" then
4482 Project.Symbol_Data.Symbol_Policy := Autonomous;
4484 elsif Value = "compliant" then
4485 Project.Symbol_Data.Symbol_Policy := Compliant;
4487 elsif Value = "controlled" then
4488 Project.Symbol_Data.Symbol_Policy := Controlled;
4490 elsif Value = "restricted" then
4491 Project.Symbol_Data.Symbol_Policy := Restricted;
4493 elsif Value = "direct" then
4494 Project.Symbol_Data.Symbol_Policy := Direct;
4499 "illegal value for Library_Symbol_Policy",
4500 Lib_Symbol_Policy.Location, Project);
4505 -- If attribute Library_Symbol_File is not specified, symbol policy
4506 -- cannot be Restricted.
4508 if Lib_Symbol_File.Default then
4509 if Project.Symbol_Data.Symbol_Policy = Restricted then
4512 "Library_Symbol_File needs to be defined when " &
4513 "symbol policy is Restricted",
4514 Lib_Symbol_Policy.Location, Project);
4518 -- Library_Symbol_File is defined
4520 Project.Symbol_Data.Symbol_File :=
4521 Path_Name_Type (Lib_Symbol_File.Value);
4523 Get_Name_String (Lib_Symbol_File.Value);
4525 if Name_Len = 0 then
4528 "symbol file name cannot be an empty string",
4529 Lib_Symbol_File.Location, Project);
4532 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4535 for J in 1 .. Name_Len loop
4536 if Name_Buffer (J) = '/'
4537 or else Name_Buffer (J) = Directory_Separator
4546 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4549 "symbol file name { is illegal. " &
4550 "Name cannot include directory info.",
4551 Lib_Symbol_File.Location, Project);
4556 -- If attribute Library_Reference_Symbol_File is not defined,
4557 -- symbol policy cannot be Compliant or Controlled.
4559 if Lib_Ref_Symbol_File.Default then
4560 if Project.Symbol_Data.Symbol_Policy = Compliant
4561 or else Project.Symbol_Data.Symbol_Policy = Controlled
4565 "a reference symbol file needs to be defined",
4566 Lib_Symbol_Policy.Location, Project);
4570 -- Library_Reference_Symbol_File is defined, check file exists
4572 Project.Symbol_Data.Reference :=
4573 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4575 Get_Name_String (Lib_Ref_Symbol_File.Value);
4577 if Name_Len = 0 then
4580 "reference symbol file name cannot be an empty string",
4581 Lib_Symbol_File.Location, Project);
4584 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4586 Add_Str_To_Name_Buffer
4587 (Get_Name_String (Project.Directory.Name));
4588 Add_Str_To_Name_Buffer
4589 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4590 Project.Symbol_Data.Reference := Name_Find;
4593 if not Is_Regular_File
4594 (Get_Name_String (Project.Symbol_Data.Reference))
4597 File_Name_Type (Lib_Ref_Symbol_File.Value);
4599 -- For controlled and direct symbol policies, it is an error
4600 -- if the reference symbol file does not exist. For other
4601 -- symbol policies, this is just a warning
4604 Project.Symbol_Data.Symbol_Policy /= Controlled
4605 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4609 "<library reference symbol file { does not exist",
4610 Lib_Ref_Symbol_File.Location, Project);
4612 -- In addition in the non-controlled case, if symbol policy
4613 -- is Compliant, it is changed to Autonomous, because there
4614 -- is no reference to check against, and we don't want to
4615 -- fail in this case.
4617 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4618 if Project.Symbol_Data.Symbol_Policy = Compliant then
4619 Project.Symbol_Data.Symbol_Policy := Autonomous;
4624 -- If both the reference symbol file and the symbol file are
4625 -- defined, then check that they are not the same file.
4627 if Project.Symbol_Data.Symbol_File /= No_Path then
4628 Get_Name_String (Project.Symbol_Data.Symbol_File);
4630 if Name_Len > 0 then
4632 -- We do not need to pass a Directory to
4633 -- Normalize_Pathname, since the path_information
4634 -- already contains absolute information.
4636 Symb_Path : constant String :=
4639 (Project.Object_Directory.Name) &
4640 Name_Buffer (1 .. Name_Len),
4643 Opt.Follow_Links_For_Files);
4644 Ref_Path : constant String :=
4647 (Project.Symbol_Data.Reference),
4650 Opt.Follow_Links_For_Files);
4652 if Symb_Path = Ref_Path then
4655 "library reference symbol file and library" &
4656 " symbol file cannot be the same file",
4657 Lib_Ref_Symbol_File.Location, Project);
4665 end Check_Stand_Alone_Library;
4667 ----------------------------
4668 -- Compute_Directory_Last --
4669 ----------------------------
4671 function Compute_Directory_Last (Dir : String) return Natural is
4674 and then (Dir (Dir'Last - 1) = Directory_Separator
4676 Dir (Dir'Last - 1) = '/')
4678 return Dir'Last - 1;
4682 end Compute_Directory_Last;
4684 ---------------------
4685 -- Get_Directories --
4686 ---------------------
4688 procedure Get_Directories
4689 (Project : Project_Id;
4690 Data : in out Tree_Processing_Data)
4692 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
4693 (Header_Num => Header_Num,
4695 No_Element => False,
4699 -- Hash table stores recursive source directories, to avoid looking
4700 -- several times, and to avoid cycles that may be introduced by symbolic
4703 Visited : Recursive_Dirs.Instance;
4705 Object_Dir : constant Variable_Value :=
4707 (Name_Object_Dir, Project.Decl.Attributes, Data.Tree);
4709 Exec_Dir : constant Variable_Value :=
4711 (Name_Exec_Dir, Project.Decl.Attributes, Data.Tree);
4713 Source_Dirs : constant Variable_Value :=
4715 (Name_Source_Dirs, Project.Decl.Attributes, Data.Tree);
4717 Excluded_Source_Dirs : constant Variable_Value :=
4719 (Name_Excluded_Source_Dirs,
4720 Project.Decl.Attributes,
4723 Source_Files : constant Variable_Value :=
4726 Project.Decl.Attributes, Data.Tree);
4728 Last_Source_Dir : String_List_Id := Nil_String;
4729 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
4731 Languages : constant Variable_Value :=
4733 (Name_Languages, Project.Decl.Attributes, Data.Tree);
4735 procedure Find_Source_Dirs
4736 (From : File_Name_Type;
4737 Location : Source_Ptr;
4739 Removed : Boolean := False);
4740 -- Find one or several source directories, and add (or remove, if
4741 -- Removed is True) them to list of source directories of the project.
4743 ----------------------
4744 -- Find_Source_Dirs --
4745 ----------------------
4747 procedure Find_Source_Dirs
4748 (From : File_Name_Type;
4749 Location : Source_Ptr;
4751 Removed : Boolean := False)
4753 Directory : constant String := Get_Name_String (From);
4755 procedure Add_To_Or_Remove_From_List
4757 Display_Path_Id : Name_Id);
4758 -- When Removed = False, the directory Path_Id to the list of
4759 -- source_dirs if not already in the list. When Removed = True,
4760 -- removed directory Path_Id if in the list.
4762 procedure Recursive_Find_Dirs (Path : Name_Id);
4763 -- Find all the subdirectories (recursively) of Path and add them
4764 -- to the list of source directories of the project.
4766 --------------------------------
4767 -- Add_To_Or_Remove_From_List --
4768 --------------------------------
4770 procedure Add_To_Or_Remove_From_List
4772 Display_Path_Id : Name_Id)
4774 List : String_List_Id;
4775 Prev : String_List_Id;
4776 Rank_List : Number_List_Index;
4777 Prev_Rank : Number_List_Index;
4778 Element : String_Element;
4782 Prev_Rank := No_Number_List;
4783 List := Project.Source_Dirs;
4784 Rank_List := Project.Source_Dir_Ranks;
4785 while List /= Nil_String loop
4786 Element := Data.Tree.String_Elements.Table (List);
4787 exit when Element.Value = Path_Id;
4789 List := Element.Next;
4790 Prev_Rank := Rank_List;
4791 Rank_List := Data.Tree.Number_Lists.Table (Prev_Rank).Next;
4794 -- The directory is in the list if List is not Nil_String
4796 if not Removed and then List = Nil_String then
4797 if Current_Verbosity = High then
4798 Write_Str (" Adding Source Dir=");
4799 Write_Line (Get_Name_String (Path_Id));
4802 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4806 Display_Value => Display_Path_Id,
4807 Location => No_Location,
4809 Next => Nil_String);
4811 Number_List_Table.Increment_Last (Data.Tree.Number_Lists);
4813 if Last_Source_Dir = Nil_String then
4815 -- This is the first source directory
4817 Project.Source_Dirs :=
4818 String_Element_Table.Last (Data.Tree.String_Elements);
4819 Project.Source_Dir_Ranks :=
4820 Number_List_Table.Last (Data.Tree.Number_Lists);
4823 -- We already have source directories, link the previous
4824 -- last to the new one.
4826 Data.Tree.String_Elements.Table (Last_Source_Dir).Next :=
4827 String_Element_Table.Last (Data.Tree.String_Elements);
4828 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
4829 Number_List_Table.Last (Data.Tree.Number_Lists);
4832 -- And register this source directory as the new last
4835 String_Element_Table.Last (Data.Tree.String_Elements);
4836 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4837 Last_Src_Dir_Rank :=
4838 Number_List_Table.Last (Data.Tree.Number_Lists);
4839 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank) :=
4840 (Number => Rank, Next => No_Number_List);
4842 elsif Removed and then List /= Nil_String then
4844 -- Remove source dir, if present
4846 if Prev = Nil_String then
4847 Project.Source_Dirs :=
4848 Data.Tree.String_Elements.Table (List).Next;
4849 Project.Source_Dir_Ranks :=
4850 Data.Tree.Number_Lists.Table (Rank_List).Next;
4853 Data.Tree.String_Elements.Table (Prev).Next :=
4854 Data.Tree.String_Elements.Table (List).Next;
4855 Data.Tree.Number_Lists.Table (Prev_Rank).Next :=
4856 Data.Tree.Number_Lists.Table (Rank_List).Next;
4859 end Add_To_Or_Remove_From_List;
4861 -------------------------
4862 -- Recursive_Find_Dirs --
4863 -------------------------
4865 procedure Recursive_Find_Dirs (Path : Name_Id) is
4867 Name : String (1 .. 250);
4870 Non_Canonical_Path : Name_Id := No_Name;
4871 Canonical_Path : Name_Id := No_Name;
4873 The_Path : constant String :=
4875 (Get_Name_String (Path),
4877 Get_Name_String (Project.Directory.Display_Name),
4878 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4879 Directory_Separator;
4881 The_Path_Last : constant Natural :=
4882 Compute_Directory_Last (The_Path);
4885 Name_Len := The_Path_Last - The_Path'First + 1;
4886 Name_Buffer (1 .. Name_Len) :=
4887 The_Path (The_Path'First .. The_Path_Last);
4888 Non_Canonical_Path := Name_Find;
4890 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4892 -- To avoid processing the same directory several times, check
4893 -- if the directory is already in Recursive_Dirs. If it is, then
4894 -- there is nothing to do, just return. If it is not, put it there
4895 -- and continue recursive processing.
4898 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4901 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4905 Add_To_Or_Remove_From_List
4906 (Path_Id => Canonical_Path,
4907 Display_Path_Id => Non_Canonical_Path);
4909 -- Now look for subdirectories. Do that even when this directory
4910 -- is already in the list, because some of its subdirectories may
4911 -- not be in the list yet.
4913 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4916 Read (Dir, Name, Last);
4919 if Name (1 .. Last) /= "."
4920 and then Name (1 .. Last) /= ".."
4922 -- Avoid . and .. directories
4924 if Current_Verbosity = High then
4925 Write_Str (" Checking ");
4926 Write_Line (Name (1 .. Last));
4930 Path_Name : constant String :=
4932 (Name => Name (1 .. Last),
4935 (The_Path'First .. The_Path_Last),
4937 Opt.Follow_Links_For_Dirs,
4938 Case_Sensitive => True);
4941 if Is_Directory (Path_Name) then
4943 -- We have found a new subdirectory, call self
4945 Name_Len := Path_Name'Length;
4946 Name_Buffer (1 .. Name_Len) := Path_Name;
4947 Recursive_Find_Dirs (Name_Find);
4956 when Directory_Error =>
4958 end Recursive_Find_Dirs;
4960 -- Start of processing for Find_Source_Dirs
4963 if Current_Verbosity = High and then not Removed then
4964 Write_Str ("Find_Source_Dirs (""");
4965 Write_Str (Directory);
4967 Write_Str (Rank'Img);
4971 -- First, check if we are looking for a directory tree, indicated
4972 -- by "/**" at the end.
4974 if Directory'Length >= 3
4975 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
4976 and then (Directory (Directory'Last - 2) = '/'
4978 Directory (Directory'Last - 2) = Directory_Separator)
4980 Name_Len := Directory'Length - 3;
4982 if Name_Len = 0 then
4984 -- Case of "/**": all directories in file system
4987 Name_Buffer (1) := Directory (Directory'First);
4990 Name_Buffer (1 .. Name_Len) :=
4991 Directory (Directory'First .. Directory'Last - 3);
4994 if Current_Verbosity = High then
4995 Write_Str ("Looking for all subdirectories of """);
4996 Write_Str (Name_Buffer (1 .. Name_Len));
5001 Base_Dir : constant File_Name_Type := Name_Find;
5002 Root_Dir : constant String :=
5004 (Name => Get_Name_String (Base_Dir),
5007 (Project.Directory.Display_Name),
5009 Opt.Follow_Links_For_Dirs,
5010 Case_Sensitive => True);
5013 if Root_Dir'Length = 0 then
5014 Err_Vars.Error_Msg_File_1 := Base_Dir;
5016 if Location = No_Location then
5019 "{ is not a valid directory.",
5020 Project.Location, Project);
5024 "{ is not a valid directory.",
5029 -- We have an existing directory, we register it and all of
5030 -- its subdirectories.
5032 if Current_Verbosity = High then
5033 Write_Line ("Looking for source directories:");
5036 Name_Len := Root_Dir'Length;
5037 Name_Buffer (1 .. Name_Len) := Root_Dir;
5038 Recursive_Find_Dirs (Name_Find);
5040 if Current_Verbosity = High then
5041 Write_Line ("End of looking for source directories.");
5046 -- We have a single directory
5050 Path_Name : Path_Information;
5051 Dir_Exists : Boolean;
5055 (Project => Project,
5058 Dir_Exists => Dir_Exists,
5060 Must_Exist => False);
5062 if not Dir_Exists then
5063 Err_Vars.Error_Msg_File_1 := From;
5065 if Location = No_Location then
5068 "{ is not a valid directory",
5069 Project.Location, Project);
5073 "{ is not a valid directory",
5079 Path : constant String :=
5082 Get_Name_String (Path_Name.Name),
5084 Get_Name_String (Project.Directory.Name),
5085 Resolve_Links => Opt.Follow_Links_For_Dirs,
5086 Case_Sensitive => True) &
5087 Directory_Separator;
5089 Last_Path : constant Natural :=
5090 Compute_Directory_Last (Path);
5092 Display_Path : constant String :=
5094 (Path_Name.Display_Name);
5095 Last_Display_Path : constant Natural :=
5096 Compute_Directory_Last
5098 Display_Path_Id : Name_Id;
5102 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5103 Path_Id := Name_Find;
5106 Add_Str_To_Name_Buffer
5108 (Display_Path'First .. Last_Display_Path));
5109 Display_Path_Id := Name_Find;
5111 Add_To_Or_Remove_From_List
5112 (Path_Id => Path_Id,
5113 Display_Path_Id => Display_Path_Id);
5119 Recursive_Dirs.Reset (Visited);
5120 end Find_Source_Dirs;
5122 -- Start of processing for Get_Directories
5124 Dir_Exists : Boolean;
5127 if Current_Verbosity = High then
5128 Write_Line ("Starting to look for directories");
5131 -- Set the object directory to its default which may be nil, if there
5132 -- is no sources in the project.
5134 if (((not Source_Files.Default)
5135 and then Source_Files.Values = Nil_String)
5137 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5139 ((not Languages.Default) and then Languages.Values = Nil_String))
5140 and then Project.Extends = No_Project
5142 Project.Object_Directory := No_Path_Information;
5144 Project.Object_Directory := Project.Directory;
5147 -- Check the object directory
5149 if Object_Dir.Value /= Empty_String then
5150 Get_Name_String (Object_Dir.Value);
5152 if Name_Len = 0 then
5155 "Object_Dir cannot be empty",
5156 Object_Dir.Location, Project);
5159 -- We check that the specified object directory does exist.
5160 -- However, even when it doesn't exist, we set it to a default
5161 -- value. This is for the benefit of tools that recover from
5162 -- errors; for example, these tools could create the non existent
5163 -- directory. We always return an absolute directory name though.
5167 File_Name_Type (Object_Dir.Value),
5168 Path => Project.Object_Directory,
5170 Dir_Exists => Dir_Exists,
5172 Location => Object_Dir.Location,
5173 Must_Exist => False,
5174 Externally_Built => Project.Externally_Built);
5177 and then not Project.Externally_Built
5179 -- The object directory does not exist, report an error if
5180 -- the project is not externally built.
5182 Err_Vars.Error_Msg_File_1 :=
5183 File_Name_Type (Object_Dir.Value);
5185 case Data.Flags.Require_Obj_Dirs is
5189 "object directory { not found",
5190 Project.Location, Project);
5194 "?object directory { not found",
5195 Project.Location, Project);
5202 elsif Project.Object_Directory /= No_Path_Information
5203 and then Subdirs /= null
5206 Name_Buffer (1) := '.';
5210 Path => Project.Object_Directory,
5212 Dir_Exists => Dir_Exists,
5214 Location => Object_Dir.Location,
5215 Externally_Built => Project.Externally_Built);
5218 if Current_Verbosity = High then
5219 if Project.Object_Directory = No_Path_Information then
5220 Write_Line ("No object directory");
5223 ("Object directory",
5224 Get_Name_String (Project.Object_Directory.Display_Name));
5228 -- Check the exec directory
5230 -- We set the object directory to its default
5232 Project.Exec_Directory := Project.Object_Directory;
5234 if Exec_Dir.Value /= Empty_String then
5235 Get_Name_String (Exec_Dir.Value);
5237 if Name_Len = 0 then
5240 "Exec_Dir cannot be empty",
5241 Exec_Dir.Location, Project);
5244 -- We check that the specified exec directory does exist
5248 File_Name_Type (Exec_Dir.Value),
5249 Path => Project.Exec_Directory,
5250 Dir_Exists => Dir_Exists,
5253 Location => Exec_Dir.Location,
5254 Externally_Built => Project.Externally_Built);
5256 if not Dir_Exists then
5257 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5260 "exec directory { not found",
5261 Project.Location, Project);
5266 if Current_Verbosity = High then
5267 if Project.Exec_Directory = No_Path_Information then
5268 Write_Line ("No exec directory");
5270 Write_Str ("Exec directory: """);
5271 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5276 -- Look for the source directories
5278 if Current_Verbosity = High then
5279 Write_Line ("Starting to look for source directories");
5282 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5284 if (not Source_Files.Default)
5285 and then Source_Files.Values = Nil_String
5287 Project.Source_Dirs := Nil_String;
5289 if Project.Qualifier = Standard then
5292 "a standard project cannot have no sources",
5293 Source_Files.Location, Project);
5296 elsif Source_Dirs.Default then
5298 -- No Source_Dirs specified: the single source directory is the one
5299 -- containing the project file.
5301 String_Element_Table.Append (Data.Tree.String_Elements,
5302 (Value => Name_Id (Project.Directory.Name),
5303 Display_Value => Name_Id (Project.Directory.Display_Name),
5304 Location => No_Location,
5309 Project.Source_Dirs :=
5310 String_Element_Table.Last (Data.Tree.String_Elements);
5312 Number_List_Table.Append
5313 (Data.Tree.Number_Lists,
5314 (Number => 1, Next => No_Number_List));
5316 Project.Source_Dir_Ranks :=
5317 Number_List_Table.Last (Data.Tree.Number_Lists);
5319 if Current_Verbosity = High then
5321 ("Default source directory",
5322 Get_Name_String (Project.Directory.Display_Name));
5325 elsif Source_Dirs.Values = Nil_String then
5326 if Project.Qualifier = Standard then
5329 "a standard project cannot have no source directories",
5330 Source_Dirs.Location, Project);
5333 Project.Source_Dirs := Nil_String;
5337 Source_Dir : String_List_Id;
5338 Element : String_Element;
5341 -- Process the source directories for each element of the list
5343 Source_Dir := Source_Dirs.Values;
5345 while Source_Dir /= Nil_String loop
5346 Element := Data.Tree.String_Elements.Table (Source_Dir);
5349 (File_Name_Type (Element.Value), Element.Location, Rank);
5350 Source_Dir := Element.Next;
5355 if not Excluded_Source_Dirs.Default
5356 and then Excluded_Source_Dirs.Values /= Nil_String
5359 Source_Dir : String_List_Id;
5360 Element : String_Element;
5363 -- Process the source directories for each element of the list
5365 Source_Dir := Excluded_Source_Dirs.Values;
5366 while Source_Dir /= Nil_String loop
5367 Element := Data.Tree.String_Elements.Table (Source_Dir);
5369 (File_Name_Type (Element.Value),
5373 Source_Dir := Element.Next;
5378 if Current_Verbosity = High then
5379 Write_Line ("Putting source directories in canonical cases");
5383 Current : String_List_Id := Project.Source_Dirs;
5384 Element : String_Element;
5387 while Current /= Nil_String loop
5388 Element := Data.Tree.String_Elements.Table (Current);
5389 if Element.Value /= No_Name then
5391 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5392 Data.Tree.String_Elements.Table (Current) := Element;
5395 Current := Element.Next;
5398 end Get_Directories;
5405 (Project : Project_Id;
5406 Data : in out Tree_Processing_Data)
5408 Mains : constant Variable_Value :=
5410 (Name_Main, Project.Decl.Attributes, Data.Tree);
5411 List : String_List_Id;
5412 Elem : String_Element;
5415 Project.Mains := Mains.Values;
5417 -- If no Mains were specified, and if we are an extending project,
5418 -- inherit the Mains from the project we are extending.
5420 if Mains.Default then
5421 if not Project.Library and then Project.Extends /= No_Project then
5422 Project.Mains := Project.Extends.Mains;
5425 -- In a library project file, Main cannot be specified
5427 elsif Project.Library then
5430 "a library project file cannot have Main specified",
5431 Mains.Location, Project);
5434 List := Mains.Values;
5435 while List /= Nil_String loop
5436 Elem := Data.Tree.String_Elements.Table (List);
5438 if Length_Of_Name (Elem.Value) = 0 then
5441 "?a main cannot have an empty name",
5442 Elem.Location, Project);
5451 ---------------------------
5452 -- Get_Sources_From_File --
5453 ---------------------------
5455 procedure Get_Sources_From_File
5457 Location : Source_Ptr;
5458 Project : in out Project_Processing_Data;
5459 Data : in out Tree_Processing_Data)
5461 File : Prj.Util.Text_File;
5462 Line : String (1 .. 250);
5464 Source_Name : File_Name_Type;
5465 Name_Loc : Name_Location;
5468 if Current_Verbosity = High then
5469 Write_Str ("Opening """);
5476 Prj.Util.Open (File, Path);
5478 if not Prj.Util.Is_Valid (File) then
5480 (Data.Flags, "file does not exist", Location, Project.Project);
5483 -- Read the lines one by one
5485 while not Prj.Util.End_Of_File (File) loop
5486 Prj.Util.Get_Line (File, Line, Last);
5488 -- A non empty, non comment line should contain a file name
5491 and then (Last = 1 or else Line (1 .. 2) /= "--")
5494 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5495 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5496 Source_Name := Name_Find;
5498 -- Check that there is no directory information
5500 for J in 1 .. Last loop
5501 if Line (J) = '/' or else Line (J) = Directory_Separator then
5502 Error_Msg_File_1 := Source_Name;
5505 "file name cannot include directory information ({)",
5506 Location, Project.Project);
5511 Name_Loc := Source_Names_Htable.Get
5512 (Project.Source_Names, Source_Name);
5514 if Name_Loc = No_Name_Location then
5516 (Name => Source_Name,
5517 Location => Location,
5518 Source => No_Source,
5522 Source_Names_Htable.Set
5523 (Project.Source_Names, Source_Name, Name_Loc);
5527 Prj.Util.Close (File);
5530 end Get_Sources_From_File;
5532 -----------------------
5533 -- Compute_Unit_Name --
5534 -----------------------
5536 procedure Compute_Unit_Name
5537 (File_Name : File_Name_Type;
5538 Naming : Lang_Naming_Data;
5539 Kind : out Source_Kind;
5541 Project : Project_Processing_Data;
5542 In_Tree : Project_Tree_Ref)
5544 Filename : constant String := Get_Name_String (File_Name);
5545 Last : Integer := Filename'Last;
5550 Unit_Except : Unit_Exception;
5551 Masked : Boolean := False;
5557 if Naming.Separate_Suffix = No_File
5558 or else Naming.Body_Suffix = No_File
5559 or else Naming.Spec_Suffix = No_File
5564 if Naming.Dot_Replacement = No_File then
5565 if Current_Verbosity = High then
5566 Write_Line (" No dot_replacement specified");
5572 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5573 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5574 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5576 -- Choose the longest suffix that matches. If there are several matches,
5577 -- give priority to specs, then bodies, then separates.
5579 if Naming.Separate_Suffix /= Naming.Body_Suffix
5580 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5582 Last := Filename'Last - Sep_Len;
5586 if Filename'Last - Body_Len <= Last
5587 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5589 Last := Natural'Min (Last, Filename'Last - Body_Len);
5593 if Filename'Last - Spec_Len <= Last
5594 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5596 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5600 if Last = Filename'Last then
5601 if Current_Verbosity = High then
5602 Write_Line (" no matching suffix");
5608 -- Check that the casing matches
5610 if File_Names_Case_Sensitive then
5611 case Naming.Casing is
5612 when All_Lower_Case =>
5613 for J in Filename'First .. Last loop
5614 if Is_Letter (Filename (J))
5615 and then not Is_Lower (Filename (J))
5617 if Current_Verbosity = High then
5618 Write_Line (" Invalid casing");
5625 when All_Upper_Case =>
5626 for J in Filename'First .. Last loop
5627 if Is_Letter (Filename (J))
5628 and then not Is_Upper (Filename (J))
5630 if Current_Verbosity = High then
5631 Write_Line (" Invalid casing");
5638 when Mixed_Case | Unknown =>
5643 -- If Dot_Replacement is not a single dot, then there should not
5644 -- be any dot in the name.
5647 Dot_Repl : constant String :=
5648 Get_Name_String (Naming.Dot_Replacement);
5651 if Dot_Repl /= "." then
5652 for Index in Filename'First .. Last loop
5653 if Filename (Index) = '.' then
5654 if Current_Verbosity = High then
5655 Write_Line (" Invalid name, contains dot");
5662 Replace_Into_Name_Buffer
5663 (Filename (Filename'First .. Last), Dot_Repl, '.');
5666 Name_Len := Last - Filename'First + 1;
5667 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5669 (Source => Name_Buffer (1 .. Name_Len),
5670 Mapping => Lower_Case_Map);
5674 -- In the standard GNAT naming scheme, check for special cases: children
5675 -- or separates of A, G, I or S, and run time sources.
5677 if Is_Standard_GNAT_Naming (Naming)
5678 and then Name_Len >= 3
5681 S1 : constant Character := Name_Buffer (1);
5682 S2 : constant Character := Name_Buffer (2);
5683 S3 : constant Character := Name_Buffer (3);
5691 -- Children or separates of packages A, G, I or S. These names
5692 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5693 -- versions (x__... and x~...) are allowed in all platforms,
5694 -- because it is not possible to know the platform before
5695 -- processing of the project files.
5697 if S2 = '_' and then S3 = '_' then
5698 Name_Buffer (2) := '.';
5699 Name_Buffer (3 .. Name_Len - 1) :=
5700 Name_Buffer (4 .. Name_Len);
5701 Name_Len := Name_Len - 1;
5704 Name_Buffer (2) := '.';
5708 -- If it is potentially a run time source
5716 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5717 -- that this is a valid unit name
5719 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5721 -- If there is a naming exception for the same unit, the file is not
5722 -- a source for the unit.
5724 if Unit /= No_Name then
5726 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5729 Masked := Unit_Except.Spec /= No_File
5731 Unit_Except.Spec /= File_Name;
5733 Masked := Unit_Except.Impl /= No_File
5735 Unit_Except.Impl /= File_Name;
5739 if Current_Verbosity = High then
5740 Write_Str (" """ & Filename & """ contains the ");
5743 Write_Str ("spec of a unit found in """);
5744 Write_Str (Get_Name_String (Unit_Except.Spec));
5746 Write_Str ("body of a unit found in """);
5747 Write_Str (Get_Name_String (Unit_Except.Impl));
5750 Write_Line (""" (ignored)");
5758 and then Current_Verbosity = High
5761 when Spec => Write_Str (" spec of ");
5762 when Impl => Write_Str (" body of ");
5763 when Sep => Write_Str (" sep of ");
5766 Write_Line (Get_Name_String (Unit));
5768 end Compute_Unit_Name;
5770 --------------------------
5771 -- Check_Illegal_Suffix --
5772 --------------------------
5774 procedure Check_Illegal_Suffix
5775 (Project : Project_Id;
5776 Suffix : File_Name_Type;
5777 Dot_Replacement : File_Name_Type;
5778 Attribute_Name : String;
5779 Location : Source_Ptr;
5780 Data : in out Tree_Processing_Data)
5782 Suffix_Str : constant String := Get_Name_String (Suffix);
5785 if Suffix_Str'Length = 0 then
5791 elsif Index (Suffix_Str, ".") = 0 then
5792 Err_Vars.Error_Msg_File_1 := Suffix;
5795 "{ is illegal for " & Attribute_Name & ": must have a dot",
5800 -- Case of dot replacement is a single dot, and first character of
5801 -- suffix is also a dot.
5803 if Dot_Replacement /= No_File
5804 and then Get_Name_String (Dot_Replacement) = "."
5805 and then Suffix_Str (Suffix_Str'First) = '.'
5807 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5809 -- If there are multiple dots in the name
5811 if Suffix_Str (Index) = '.' then
5813 -- It is illegal to have a letter following the initial dot
5815 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5816 Err_Vars.Error_Msg_File_1 := Suffix;
5819 "{ is illegal for " & Attribute_Name
5820 & ": ambiguous prefix when Dot_Replacement is a dot",
5827 end Check_Illegal_Suffix;
5829 ----------------------
5830 -- Locate_Directory --
5831 ----------------------
5833 procedure Locate_Directory
5834 (Project : Project_Id;
5835 Name : File_Name_Type;
5836 Path : out Path_Information;
5837 Dir_Exists : out Boolean;
5838 Data : in out Tree_Processing_Data;
5839 Create : String := "";
5840 Location : Source_Ptr := No_Location;
5841 Must_Exist : Boolean := True;
5842 Externally_Built : Boolean := False)
5844 Parent : constant Path_Name_Type :=
5845 Project.Directory.Display_Name;
5846 The_Parent : constant String :=
5847 Get_Name_String (Parent);
5848 The_Parent_Last : constant Natural :=
5849 Compute_Directory_Last (The_Parent);
5850 Full_Name : File_Name_Type;
5851 The_Name : File_Name_Type;
5854 Get_Name_String (Name);
5856 -- Add Subdirs.all if it is a directory that may be created and
5857 -- Subdirs is not null;
5859 if Create /= "" and then Subdirs /= null then
5860 if Name_Buffer (Name_Len) /= Directory_Separator then
5861 Add_Char_To_Name_Buffer (Directory_Separator);
5864 Add_Str_To_Name_Buffer (Subdirs.all);
5867 -- Convert '/' to directory separator (for Windows)
5869 for J in 1 .. Name_Len loop
5870 if Name_Buffer (J) = '/' then
5871 Name_Buffer (J) := Directory_Separator;
5875 The_Name := Name_Find;
5877 if Current_Verbosity = High then
5878 Write_Str ("Locate_Directory (""");
5879 Write_Str (Get_Name_String (The_Name));
5880 Write_Str (""", """);
5881 Write_Str (The_Parent);
5885 Path := No_Path_Information;
5886 Dir_Exists := False;
5888 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5889 Full_Name := The_Name;
5893 Add_Str_To_Name_Buffer
5894 (The_Parent (The_Parent'First .. The_Parent_Last));
5895 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5896 Full_Name := Name_Find;
5900 Full_Path_Name : String_Access :=
5901 new String'(Get_Name_String (Full_Name));
5904 if (Setup_Projects or else Subdirs /= null)
5905 and then Create'Length > 0
5907 if not Is_Directory (Full_Path_Name.all) then
5909 -- If project is externally built, do not create a subdir,
5910 -- use the specified directory, without the subdir.
5912 if Externally_Built then
5913 if Is_Absolute_Path (Get_Name_String (Name)) then
5914 Get_Name_String (Name);
5918 Add_Str_To_Name_Buffer
5919 (The_Parent (The_Parent'First .. The_Parent_Last));
5920 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5923 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5927 Create_Path (Full_Path_Name.all);
5929 if not Quiet_Output then
5931 Write_Str (" directory """);
5932 Write_Str (Full_Path_Name.all);
5933 Write_Str (""" created for project ");
5934 Write_Line (Get_Name_String (Project.Name));
5941 "could not create " & Create &
5942 " directory " & Full_Path_Name.all,
5949 Dir_Exists := Is_Directory (Full_Path_Name.all);
5951 if not Must_Exist or else Dir_Exists then
5953 Normed : constant String :=
5955 (Full_Path_Name.all,
5957 The_Parent (The_Parent'First .. The_Parent_Last),
5958 Resolve_Links => False,
5959 Case_Sensitive => True);
5961 Canonical_Path : constant String :=
5966 (The_Parent'First .. The_Parent_Last),
5968 Opt.Follow_Links_For_Dirs,
5969 Case_Sensitive => False);
5972 Name_Len := Normed'Length;
5973 Name_Buffer (1 .. Name_Len) := Normed;
5975 -- Directories should always end with a directory separator
5977 if Name_Buffer (Name_Len) /= Directory_Separator then
5978 Add_Char_To_Name_Buffer (Directory_Separator);
5981 Path.Display_Name := Name_Find;
5983 Name_Len := Canonical_Path'Length;
5984 Name_Buffer (1 .. Name_Len) := Canonical_Path;
5986 if Name_Buffer (Name_Len) /= Directory_Separator then
5987 Add_Char_To_Name_Buffer (Directory_Separator);
5990 Path.Name := Name_Find;
5994 Free (Full_Path_Name);
5996 end Locate_Directory;
5998 ---------------------------
5999 -- Find_Excluded_Sources --
6000 ---------------------------
6002 procedure Find_Excluded_Sources
6003 (Project : in out Project_Processing_Data;
6004 Data : in out Tree_Processing_Data)
6006 Excluded_Source_List_File : constant Variable_Value :=
6008 (Name_Excluded_Source_List_File,
6009 Project.Project.Decl.Attributes,
6011 Excluded_Sources : Variable_Value := Util.Value_Of
6012 (Name_Excluded_Source_Files,
6013 Project.Project.Decl.Attributes,
6016 Current : String_List_Id;
6017 Element : String_Element;
6018 Location : Source_Ptr;
6019 Name : File_Name_Type;
6020 File : Prj.Util.Text_File;
6021 Line : String (1 .. 300);
6023 Locally_Removed : Boolean := False;
6026 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6028 if Excluded_Sources.Default then
6029 Locally_Removed := True;
6032 (Name_Locally_Removed_Files,
6033 Project.Project.Decl.Attributes, Data.Tree);
6036 -- If there are excluded sources, put them in the table
6038 if not Excluded_Sources.Default then
6039 if not Excluded_Source_List_File.Default then
6040 if Locally_Removed then
6043 "?both attributes Locally_Removed_Files and " &
6044 "Excluded_Source_List_File are present",
6045 Excluded_Source_List_File.Location, Project.Project);
6049 "?both attributes Excluded_Source_Files and " &
6050 "Excluded_Source_List_File are present",
6051 Excluded_Source_List_File.Location, Project.Project);
6055 Current := Excluded_Sources.Values;
6056 while Current /= Nil_String loop
6057 Element := Data.Tree.String_Elements.Table (Current);
6058 Name := Canonical_Case_File_Name (Element.Value);
6060 -- If the element has no location, then use the location of
6061 -- Excluded_Sources to report possible errors.
6063 if Element.Location = No_Location then
6064 Location := Excluded_Sources.Location;
6066 Location := Element.Location;
6069 Excluded_Sources_Htable.Set
6070 (Project.Excluded, Name, (Name, False, Location));
6071 Current := Element.Next;
6074 elsif not Excluded_Source_List_File.Default then
6075 Location := Excluded_Source_List_File.Location;
6078 Source_File_Path_Name : constant String :=
6081 (Excluded_Source_List_File.Value),
6082 Project.Project.Directory.Name);
6085 if Source_File_Path_Name'Length = 0 then
6086 Err_Vars.Error_Msg_File_1 :=
6087 File_Name_Type (Excluded_Source_List_File.Value);
6090 "file with excluded sources { does not exist",
6091 Excluded_Source_List_File.Location, Project.Project);
6096 Prj.Util.Open (File, Source_File_Path_Name);
6098 if not Prj.Util.Is_Valid (File) then
6100 (Data.Flags, "file does not exist",
6101 Location, Project.Project);
6103 -- Read the lines one by one
6105 while not Prj.Util.End_Of_File (File) loop
6106 Prj.Util.Get_Line (File, Line, Last);
6108 -- Non empty, non comment line should contain a file name
6111 and then (Last = 1 or else Line (1 .. 2) /= "--")
6114 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6115 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6118 -- Check that there is no directory information
6120 for J in 1 .. Last loop
6122 or else Line (J) = Directory_Separator
6124 Error_Msg_File_1 := Name;
6127 "file name cannot include " &
6128 "directory information ({)",
6129 Location, Project.Project);
6134 Excluded_Sources_Htable.Set
6135 (Project.Excluded, Name, (Name, False, Location));
6139 Prj.Util.Close (File);
6144 end Find_Excluded_Sources;
6150 procedure Find_Sources
6151 (Project : in out Project_Processing_Data;
6152 Data : in out Tree_Processing_Data)
6154 Sources : constant Variable_Value :=
6157 Project.Project.Decl.Attributes,
6160 Source_List_File : constant Variable_Value :=
6162 (Name_Source_List_File,
6163 Project.Project.Decl.Attributes,
6166 Name_Loc : Name_Location;
6167 Has_Explicit_Sources : Boolean;
6170 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6172 (Source_List_File.Kind = Single,
6173 "Source_List_File is not a single string");
6175 Project.Source_List_File_Location := Source_List_File.Location;
6177 -- If the user has specified a Source_Files attribute
6179 if not Sources.Default then
6180 if not Source_List_File.Default then
6183 "?both attributes source_files and " &
6184 "source_list_file are present",
6185 Source_List_File.Location, Project.Project);
6188 -- Sources is a list of file names
6191 Current : String_List_Id := Sources.Values;
6192 Element : String_Element;
6193 Location : Source_Ptr;
6194 Name : File_Name_Type;
6197 if Current = Nil_String then
6198 Project.Project.Languages := No_Language_Index;
6200 -- This project contains no source. For projects that don't
6201 -- extend other projects, this also means that there is no
6202 -- need for an object directory, if not specified.
6204 if Project.Project.Extends = No_Project
6205 and then Project.Project.Object_Directory =
6206 Project.Project.Directory
6208 Project.Project.Object_Directory := No_Path_Information;
6212 while Current /= Nil_String loop
6213 Element := Data.Tree.String_Elements.Table (Current);
6214 Name := Canonical_Case_File_Name (Element.Value);
6215 Get_Name_String (Element.Value);
6217 -- If the element has no location, then use the location of
6218 -- Sources to report possible errors.
6220 if Element.Location = No_Location then
6221 Location := Sources.Location;
6223 Location := Element.Location;
6226 -- Check that there is no directory information
6228 for J in 1 .. Name_Len loop
6229 if Name_Buffer (J) = '/'
6230 or else Name_Buffer (J) = Directory_Separator
6232 Error_Msg_File_1 := Name;
6235 "file name cannot include directory " &
6237 Location, Project.Project);
6242 -- Check whether the file is already there: the same file name
6243 -- may be in the list. If the source is missing, the error will
6244 -- be on the first mention of the source file name.
6246 Name_Loc := Source_Names_Htable.Get
6247 (Project.Source_Names, Name);
6249 if Name_Loc = No_Name_Location then
6252 Location => Location,
6253 Source => No_Source,
6255 Source_Names_Htable.Set
6256 (Project.Source_Names, Name, Name_Loc);
6259 Current := Element.Next;
6262 Has_Explicit_Sources := True;
6265 -- If we have no Source_Files attribute, check the Source_List_File
6268 elsif not Source_List_File.Default then
6270 -- Source_List_File is the name of the file that contains the source
6274 Source_File_Path_Name : constant String :=
6276 (File_Name_Type (Source_List_File.Value),
6277 Project.Project.Directory.Name);
6280 Has_Explicit_Sources := True;
6282 if Source_File_Path_Name'Length = 0 then
6283 Err_Vars.Error_Msg_File_1 :=
6284 File_Name_Type (Source_List_File.Value);
6287 "file with sources { does not exist",
6288 Source_List_File.Location, Project.Project);
6291 Get_Sources_From_File
6292 (Source_File_Path_Name, Source_List_File.Location,
6298 -- Neither Source_Files nor Source_List_File has been specified. Find
6299 -- all the files that satisfy the naming scheme in all the source
6302 Has_Explicit_Sources := False;
6308 For_All_Sources => Sources.Default and then Source_List_File.Default);
6310 -- Check if all exceptions have been found
6314 Iter : Source_Iterator;
6317 Iter := For_Each_Source (Data.Tree, Project.Project);
6319 Source := Prj.Element (Iter);
6320 exit when Source = No_Source;
6322 if Source.Naming_Exception
6323 and then Source.Path = No_Path_Information
6325 if Source.Unit /= No_Unit_Index then
6327 -- For multi-unit source files, source_id gets duplicated
6328 -- once for every unit. Only the first source_id got its
6329 -- full path set. So if it isn't set for that first one,
6330 -- the file wasn't found. Otherwise we need to update for
6331 -- units after the first one.
6334 or else Source.Index = 1
6336 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6337 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6340 "source file %% for unit %% not found",
6341 No_Location, Project.Project);
6344 Source.Path := Files_Htable.Get
6345 (Data.File_To_Source, Source.File).Path;
6347 if Current_Verbosity = High then
6348 if Source.Path /= No_Path_Information then
6349 Write_Line ("Setting full path for "
6350 & Get_Name_String (Source.File)
6351 & " at" & Source.Index'Img
6353 & Get_Name_String (Source.Path.Name));
6359 if Source.Path = No_Path_Information then
6360 Remove_Source (Source, No_Source);
6368 -- It is an error if a source file name in a source list or in a source
6369 -- list file is not found.
6371 if Has_Explicit_Sources then
6374 First_Error : Boolean;
6377 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6378 First_Error := True;
6379 while NL /= No_Name_Location loop
6380 if not NL.Found then
6381 Err_Vars.Error_Msg_File_1 := NL.Name;
6386 "source file { not found",
6387 NL.Location, Project.Project);
6388 First_Error := False;
6393 "\source file { not found",
6394 NL.Location, Project.Project);
6398 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6408 procedure Initialize
6409 (Data : out Tree_Processing_Data;
6410 Tree : Project_Tree_Ref;
6411 Flags : Prj.Processing_Flags)
6414 Files_Htable.Reset (Data.File_To_Source);
6416 Data.Flags := Flags;
6423 procedure Free (Data : in out Tree_Processing_Data) is
6425 Files_Htable.Reset (Data.File_To_Source);
6432 procedure Initialize
6433 (Data : in out Project_Processing_Data;
6434 Project : Project_Id)
6437 Data.Project := Project;
6444 procedure Free (Data : in out Project_Processing_Data) is
6446 Source_Names_Htable.Reset (Data.Source_Names);
6447 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6448 Excluded_Sources_Htable.Reset (Data.Excluded);
6451 -------------------------------
6452 -- Check_File_Naming_Schemes --
6453 -------------------------------
6455 procedure Check_File_Naming_Schemes
6456 (In_Tree : Project_Tree_Ref;
6457 Project : Project_Processing_Data;
6458 File_Name : File_Name_Type;
6459 Alternate_Languages : out Language_List;
6460 Language : out Language_Ptr;
6461 Display_Language_Name : out Name_Id;
6463 Lang_Kind : out Language_Kind;
6464 Kind : out Source_Kind)
6466 Filename : constant String := Get_Name_String (File_Name);
6467 Config : Language_Config;
6468 Tmp_Lang : Language_Ptr;
6470 Header_File : Boolean := False;
6471 -- True if we found at least one language for which the file is a header
6472 -- In such a case, we search for all possible languages where this is
6473 -- also a header (C and C++ for instance), since the file might be used
6474 -- for several such languages.
6476 procedure Check_File_Based_Lang;
6477 -- Does the naming scheme test for file-based languages. For those,
6478 -- there is no Unit. Just check if the file name has the implementation
6479 -- or, if it is specified, the template suffix of the language.
6481 -- Returns True if the file belongs to the current language and we
6482 -- should stop searching for matching languages. Not that a given header
6483 -- file could belong to several languages (C and C++ for instance). Thus
6484 -- if we found a header we'll check whether it matches other languages.
6486 ---------------------------
6487 -- Check_File_Based_Lang --
6488 ---------------------------
6490 procedure Check_File_Based_Lang is
6493 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6497 Language := Tmp_Lang;
6499 if Current_Verbosity = High then
6500 Write_Str (" implementation of language ");
6501 Write_Line (Get_Name_String (Display_Language_Name));
6504 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6505 if Current_Verbosity = High then
6506 Write_Str (" header of language ");
6507 Write_Line (Get_Name_String (Display_Language_Name));
6511 Alternate_Languages := new Language_List_Element'
6512 (Language => Language,
6513 Next => Alternate_Languages);
6516 Header_File := True;
6519 Language := Tmp_Lang;
6522 end Check_File_Based_Lang;
6524 -- Start of processing for Check_File_Naming_Schemes
6527 Language := No_Language_Index;
6528 Alternate_Languages := null;
6529 Display_Language_Name := No_Name;
6531 Lang_Kind := File_Based;
6534 Tmp_Lang := Project.Project.Languages;
6535 while Tmp_Lang /= No_Language_Index loop
6536 if Current_Verbosity = High then
6538 (" Testing language "
6539 & Get_Name_String (Tmp_Lang.Name)
6540 & " Header_File=" & Header_File'Img);
6543 Display_Language_Name := Tmp_Lang.Display_Name;
6544 Config := Tmp_Lang.Config;
6545 Lang_Kind := Config.Kind;
6549 Check_File_Based_Lang;
6550 exit when Kind = Impl;
6554 -- We know it belongs to a least a file_based language, no
6555 -- need to check unit-based ones.
6557 if not Header_File then
6559 (File_Name => File_Name,
6560 Naming => Config.Naming_Data,
6564 In_Tree => In_Tree);
6566 if Unit /= No_Name then
6567 Language := Tmp_Lang;
6573 Tmp_Lang := Tmp_Lang.Next;
6576 if Language = No_Language_Index
6577 and then Current_Verbosity = High
6579 Write_Line (" not a source of any language");
6581 end Check_File_Naming_Schemes;
6587 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6589 -- If the file was previously already associated with a unit, change it
6591 if Source.Unit /= null
6592 and then Source.Kind in Spec_Or_Body
6593 and then Source.Unit.File_Names (Source.Kind) /= null
6595 -- If we had another file referencing the same unit (for instance it
6596 -- was in an extended project), that source file is in fact invisible
6597 -- from now on, and in particular doesn't belong to the same unit.
6599 if Source.Unit.File_Names (Source.Kind) /= Source then
6600 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6603 Source.Unit.File_Names (Source.Kind) := null;
6606 Source.Kind := Kind;
6608 if Current_Verbosity = High
6609 and then Source.File /= No_File
6611 Write_Line ("Override kind for "
6612 & Get_Name_String (Source.File)
6613 & " kind=" & Source.Kind'Img);
6616 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6617 Source.Unit.File_Names (Source.Kind) := Source;
6625 procedure Check_File
6626 (Project : in out Project_Processing_Data;
6627 Data : in out Tree_Processing_Data;
6628 Source_Dir_Rank : Natural;
6629 Path : Path_Name_Type;
6630 File_Name : File_Name_Type;
6631 Display_File_Name : File_Name_Type;
6632 Locally_Removed : Boolean;
6633 For_All_Sources : Boolean)
6635 Canonical_Path : constant Path_Name_Type :=
6637 (Canonical_Case_File_Name (Name_Id (Path)));
6639 Name_Loc : Name_Location :=
6640 Source_Names_Htable.Get
6641 (Project.Source_Names, File_Name);
6642 Check_Name : Boolean := False;
6643 Alternate_Languages : Language_List;
6644 Language : Language_Ptr;
6646 Src_Ind : Source_File_Index;
6648 Display_Language_Name : Name_Id;
6649 Lang_Kind : Language_Kind;
6650 Kind : Source_Kind := Spec;
6653 if Current_Verbosity = High then
6654 Write_Line ("Checking file:");
6655 Write_Str (" Path = ");
6656 Write_Line (Get_Name_String (Path));
6657 Write_Str (" Rank =");
6658 Write_Line (Source_Dir_Rank'Img);
6661 if Name_Loc = No_Name_Location then
6662 Check_Name := For_All_Sources;
6665 if Name_Loc.Found then
6667 -- Check if it is OK to have the same file name in several
6668 -- source directories.
6670 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6671 Error_Msg_File_1 := File_Name;
6674 "{ is found in several source directories",
6675 Name_Loc.Location, Project.Project);
6679 Name_Loc.Found := True;
6681 Source_Names_Htable.Set
6682 (Project.Source_Names, File_Name, Name_Loc);
6684 if Name_Loc.Source = No_Source then
6688 Name_Loc.Source.Path := (Canonical_Path, Path);
6690 Source_Paths_Htable.Set
6691 (Data.Tree.Source_Paths_HT,
6695 -- Check if this is a subunit
6697 if Name_Loc.Source.Unit /= No_Unit_Index
6698 and then Name_Loc.Source.Kind = Impl
6700 Src_Ind := Sinput.P.Load_Project_File
6701 (Get_Name_String (Canonical_Path));
6703 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6704 Override_Kind (Name_Loc.Source, Sep);
6709 (Data.File_To_Source, File_Name, Name_Loc.Source);
6715 Check_File_Naming_Schemes
6716 (In_Tree => Data.Tree,
6718 File_Name => File_Name,
6719 Alternate_Languages => Alternate_Languages,
6720 Language => Language,
6721 Display_Language_Name => Display_Language_Name,
6723 Lang_Kind => Lang_Kind,
6726 if Language = No_Language_Index then
6728 -- A file name in a list must be a source of a language
6730 if Data.Flags.Error_On_Unknown_Language
6731 and then Name_Loc.Found
6733 Error_Msg_File_1 := File_Name;
6736 "language unknown for {",
6737 Name_Loc.Location, Project.Project);
6743 Project => Project.Project,
6744 Source_Dir_Rank => Source_Dir_Rank,
6745 Lang_Id => Language,
6748 Alternate_Languages => Alternate_Languages,
6749 File_Name => File_Name,
6750 Display_File => Display_File_Name,
6752 Locally_Removed => Locally_Removed,
6753 Path => (Canonical_Path, Path));
6755 -- If it is a source specified in a list, update the entry in
6756 -- the Source_Names table.
6758 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6759 Name_Loc.Source := Source;
6760 Source_Names_Htable.Set
6761 (Project.Source_Names, File_Name, Name_Loc);
6767 ------------------------
6768 -- Search_Directories --
6769 ------------------------
6771 procedure Search_Directories
6772 (Project : in out Project_Processing_Data;
6773 Data : in out Tree_Processing_Data;
6774 For_All_Sources : Boolean)
6776 Source_Dir : String_List_Id;
6777 Element : String_Element;
6778 Src_Dir_Rank : Number_List_Index;
6779 Num_Nod : Number_Node;
6781 Name : String (1 .. 1_000);
6783 File_Name : File_Name_Type;
6784 Display_File_Name : File_Name_Type;
6787 if Current_Verbosity = High then
6788 Write_Line ("Looking for sources:");
6791 -- Loop through subdirectories
6793 Source_Dir := Project.Project.Source_Dirs;
6794 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
6795 while Source_Dir /= Nil_String loop
6797 Num_Nod := Data.Tree.Number_Lists.Table (Src_Dir_Rank);
6798 Element := Data.Tree.String_Elements.Table (Source_Dir);
6800 if Element.Value /= No_Name then
6801 Get_Name_String (Element.Display_Value);
6803 if Current_Verbosity = High then
6804 Write_Str ("Directory: ");
6805 Write_Str (Name_Buffer (1 .. Name_Len));
6806 Write_Line (Num_Nod.Number'Img);
6810 Source_Directory : constant String :=
6811 Name_Buffer (1 .. Name_Len) &
6812 Directory_Separator;
6814 Dir_Last : constant Natural :=
6815 Compute_Directory_Last
6819 if Current_Verbosity = High then
6820 Write_Attr ("Source_Dir", Source_Directory);
6823 -- We look to every entry in the source directory
6825 Open (Dir, Source_Directory);
6828 Read (Dir, Name, Last);
6832 -- ??? Duplicate system call here, we just did a a
6833 -- similar one. Maybe Ada.Directories would be more
6834 -- appropriate here.
6837 (Source_Directory & Name (1 .. Last))
6839 if Current_Verbosity = High then
6840 Write_Str (" Checking ");
6841 Write_Line (Name (1 .. Last));
6845 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6846 Display_File_Name := Name_Find;
6848 if Osint.File_Names_Case_Sensitive then
6849 File_Name := Display_File_Name;
6851 Canonical_Case_File_Name
6852 (Name_Buffer (1 .. Name_Len));
6853 File_Name := Name_Find;
6857 Path_Name : constant String :=
6862 (Source_Directory'First ..
6865 Opt.Follow_Links_For_Files,
6866 Case_Sensitive => True);
6867 -- Case_Sensitive set True (no folding)
6869 Path : Path_Name_Type;
6870 FF : File_Found := Excluded_Sources_Htable.Get
6871 (Project.Excluded, File_Name);
6872 To_Remove : Boolean := False;
6875 Name_Len := Path_Name'Length;
6876 Name_Buffer (1 .. Name_Len) := Path_Name;
6879 if FF /= No_File_Found then
6880 if not FF.Found then
6882 Excluded_Sources_Htable.Set
6883 (Project.Excluded, File_Name, FF);
6885 if Current_Verbosity = High then
6886 Write_Str (" excluded source """);
6887 Write_Str (Get_Name_String (File_Name));
6891 -- Will mark the file as removed, but we
6892 -- still need to add it to the list: if we
6893 -- don't, the file will not appear in the
6894 -- mapping file and will cause the compiler
6902 (Project => Project,
6903 Source_Dir_Rank => Num_Nod.Number,
6906 File_Name => File_Name,
6907 Locally_Removed => To_Remove,
6908 Display_File_Name => Display_File_Name,
6909 For_All_Sources => For_All_Sources);
6919 when Directory_Error =>
6923 Source_Dir := Element.Next;
6924 Src_Dir_Rank := Num_Nod.Next;
6927 if Current_Verbosity = High then
6928 Write_Line ("end Looking for sources.");
6930 end Search_Directories;
6932 ----------------------------
6933 -- Load_Naming_Exceptions --
6934 ----------------------------
6936 procedure Load_Naming_Exceptions
6937 (Project : in out Project_Processing_Data;
6938 Data : in out Tree_Processing_Data)
6941 Iter : Source_Iterator;
6944 Iter := For_Each_Source (Data.Tree, Project.Project);
6946 Source := Prj.Element (Iter);
6947 exit when Source = No_Source;
6949 -- An excluded file cannot also be an exception file name
6951 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
6954 Error_Msg_File_1 := Source.File;
6957 "{ cannot be both excluded and an exception file name",
6958 No_Location, Project.Project);
6961 if Current_Verbosity = High then
6962 Write_Str ("Naming exception: Putting source file ");
6963 Write_Str (Get_Name_String (Source.File));
6964 Write_Line (" in Source_Names");
6967 Source_Names_Htable.Set
6968 (Project.Source_Names,
6971 (Name => Source.File,
6972 Location => No_Location,
6976 -- If this is an Ada exception, record in table Unit_Exceptions
6978 if Source.Unit /= No_Unit_Index then
6980 Unit_Except : Unit_Exception :=
6981 Unit_Exceptions_Htable.Get
6982 (Project.Unit_Exceptions, Source.Unit.Name);
6985 Unit_Except.Name := Source.Unit.Name;
6987 if Source.Kind = Spec then
6988 Unit_Except.Spec := Source.File;
6990 Unit_Except.Impl := Source.File;
6993 Unit_Exceptions_Htable.Set
6994 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7000 end Load_Naming_Exceptions;
7002 ----------------------
7003 -- Look_For_Sources --
7004 ----------------------
7006 procedure Look_For_Sources
7007 (Project : in out Project_Processing_Data;
7008 Data : in out Tree_Processing_Data)
7010 Object_Files : Object_File_Names_Htable.Instance;
7011 Iter : Source_Iterator;
7014 procedure Check_Object (Src : Source_Id);
7015 -- Check if object file name of Src is already used in the project tree,
7016 -- and report an error if so.
7018 procedure Check_Object_Files;
7019 -- Check that no two sources of this project have the same object file
7021 procedure Mark_Excluded_Sources;
7022 -- Mark as such the sources that are declared as excluded
7028 procedure Check_Object (Src : Source_Id) is
7032 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7034 -- We cannot just check on "Source /= Src", since we might have
7035 -- two different entries for the same file (and since that's
7036 -- the same file it is expected that it has the same object)
7038 if Source /= No_Source
7039 and then Source.Path /= Src.Path
7041 Error_Msg_File_1 := Src.File;
7042 Error_Msg_File_2 := Source.File;
7045 "{ and { have the same object file name",
7046 No_Location, Project.Project);
7049 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7053 ---------------------------
7054 -- Mark_Excluded_Sources --
7055 ---------------------------
7057 procedure Mark_Excluded_Sources is
7058 Source : Source_Id := No_Source;
7059 Excluded : File_Found;
7063 -- Minor optimization: if there are no excluded files, no need to
7064 -- traverse the list of sources. We cannot however also check whether
7065 -- the existing exceptions have ".Found" set to True (indicating we
7066 -- found them before) because we need to do some final processing on
7067 -- them in any case.
7069 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7072 Proj := Project.Project;
7073 while Proj /= No_Project loop
7074 Iter := For_Each_Source (Data.Tree, Proj);
7075 while Prj.Element (Iter) /= No_Source loop
7076 Source := Prj.Element (Iter);
7077 Excluded := Excluded_Sources_Htable.Get
7078 (Project.Excluded, Source.File);
7080 if Excluded /= No_File_Found then
7081 Source.Locally_Removed := True;
7082 Source.In_Interfaces := False;
7084 if Current_Verbosity = High then
7085 Write_Str ("Removing file ");
7087 (Get_Name_String (Excluded.File)
7088 & " " & Get_Name_String (Source.Project.Name));
7091 Excluded_Sources_Htable.Remove
7092 (Project.Excluded, Source.File);
7098 Proj := Proj.Extends;
7102 -- If we have any excluded element left, that means we did not find
7105 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7106 while Excluded /= No_File_Found loop
7107 if not Excluded.Found then
7109 -- Check if the file belongs to another imported project to
7110 -- provide a better error message.
7113 (In_Tree => Data.Tree,
7114 Project => Project.Project,
7115 In_Imported_Only => True,
7116 Base_Name => Excluded.File);
7118 Err_Vars.Error_Msg_File_1 := Excluded.File;
7120 if Src = No_Source then
7123 "unknown file {", Excluded.Location, Project.Project);
7127 "cannot remove a source from an imported project: {",
7128 Excluded.Location, Project.Project);
7132 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7134 end Mark_Excluded_Sources;
7136 ------------------------
7137 -- Check_Object_Files --
7138 ------------------------
7140 procedure Check_Object_Files is
7141 Iter : Source_Iterator;
7143 Src_Ind : Source_File_Index;
7146 Iter := For_Each_Source (Data.Tree);
7148 Src_Id := Prj.Element (Iter);
7149 exit when Src_Id = No_Source;
7151 if Is_Compilable (Src_Id)
7152 and then Src_Id.Language.Config.Object_Generated
7153 and then Is_Extending (Project.Project, Src_Id.Project)
7155 if Src_Id.Unit = No_Unit_Index then
7156 if Src_Id.Kind = Impl then
7157 Check_Object (Src_Id);
7163 if Other_Part (Src_Id) = No_Source then
7164 Check_Object (Src_Id);
7171 if Other_Part (Src_Id) /= No_Source then
7172 Check_Object (Src_Id);
7175 -- Check if it is a subunit
7178 Sinput.P.Load_Project_File
7179 (Get_Name_String (Src_Id.Path.Name));
7181 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7182 Override_Kind (Src_Id, Sep);
7184 Check_Object (Src_Id);
7193 end Check_Object_Files;
7195 -- Start of processing for Look_For_Sources
7198 Find_Excluded_Sources (Project, Data);
7200 if Project.Project.Languages /= No_Language_Index then
7201 Load_Naming_Exceptions (Project, Data);
7202 Find_Sources (Project, Data);
7203 Mark_Excluded_Sources;
7207 Object_File_Names_Htable.Reset (Object_Files);
7208 end Look_For_Sources;
7214 function Path_Name_Of
7215 (File_Name : File_Name_Type;
7216 Directory : Path_Name_Type) return String
7218 Result : String_Access;
7219 The_Directory : constant String := Get_Name_String (Directory);
7222 Get_Name_String (File_Name);
7225 (File_Name => Name_Buffer (1 .. Name_Len),
7226 Path => The_Directory);
7228 if Result = null then
7232 R : String := Result.all;
7235 Canonical_Case_File_Name (R);
7245 procedure Remove_Source
7247 Replaced_By : Source_Id)
7252 if Current_Verbosity = High then
7253 Write_Str ("Removing source ");
7254 Write_Str (Get_Name_String (Id.File));
7256 if Id.Index /= 0 then
7257 Write_Str (" at" & Id.Index'Img);
7263 if Replaced_By /= No_Source then
7264 Id.Replaced_By := Replaced_By;
7265 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7268 Id.In_Interfaces := False;
7269 Id.Locally_Removed := True;
7271 -- ??? Should we remove the source from the unit ? The file is not used,
7272 -- so probably should not be referenced from the unit. On the other hand
7273 -- it might give useful additional info
7274 -- if Id.Unit /= null then
7275 -- Id.Unit.File_Names (Id.Kind) := null;
7278 Source := Id.Language.First_Source;
7281 Id.Language.First_Source := Id.Next_In_Lang;
7284 while Source.Next_In_Lang /= Id loop
7285 Source := Source.Next_In_Lang;
7288 Source.Next_In_Lang := Id.Next_In_Lang;
7292 -----------------------
7293 -- Report_No_Sources --
7294 -----------------------
7296 procedure Report_No_Sources
7297 (Project : Project_Id;
7299 Data : Tree_Processing_Data;
7300 Location : Source_Ptr;
7301 Continuation : Boolean := False)
7304 case Data.Flags.When_No_Sources is
7308 when Warning | Error =>
7310 Msg : constant String :=
7313 " sources in this project";
7316 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7318 if Continuation then
7319 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7321 Error_Msg (Data.Flags, Msg, Location, Project);
7325 end Report_No_Sources;
7327 ----------------------
7328 -- Show_Source_Dirs --
7329 ----------------------
7331 procedure Show_Source_Dirs
7332 (Project : Project_Id;
7333 In_Tree : Project_Tree_Ref)
7335 Current : String_List_Id;
7336 Element : String_Element;
7339 Write_Line ("Source_Dirs:");
7341 Current := Project.Source_Dirs;
7342 while Current /= Nil_String loop
7343 Element := In_Tree.String_Elements.Table (Current);
7345 Write_Line (Get_Name_String (Element.Value));
7346 Current := Element.Next;
7349 Write_Line ("end Source_Dirs.");
7350 end Show_Source_Dirs;
7352 ---------------------------
7353 -- Process_Naming_Scheme --
7354 ---------------------------
7356 procedure Process_Naming_Scheme
7357 (Tree : Project_Tree_Ref;
7358 Root_Project : Project_Id;
7359 Flags : Processing_Flags)
7361 procedure Recursive_Check
7362 (Project : Project_Id;
7363 Data : in out Tree_Processing_Data);
7364 -- Check_Naming_Scheme for the project
7366 ---------------------
7367 -- Recursive_Check --
7368 ---------------------
7370 procedure Recursive_Check
7371 (Project : Project_Id;
7372 Data : in out Tree_Processing_Data)
7375 if Verbose_Mode then
7376 Write_Str ("Processing_Naming_Scheme for project """);
7377 Write_Str (Get_Name_String (Project.Name));
7381 Prj.Nmsc.Check (Project, Data);
7382 end Recursive_Check;
7384 procedure Check_All_Projects is new
7385 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7387 Data : Tree_Processing_Data;
7389 -- Start of processing for Process_Naming_Scheme
7391 Initialize (Data, Tree => Tree, Flags => Flags);
7392 Check_All_Projects (Root_Project, Data, Imported_First => True);
7394 end Process_Naming_Scheme;