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_Path_Syntax =>
1436 Lang_Index.Config.Path_Syntax :=
1437 Path_Syntax_Kind'Value
1438 (Get_Name_String (Element.Value.Value));
1441 when Constraint_Error =>
1444 "invalid value for Path_Syntax",
1445 Element.Value.Location, Project);
1448 when Name_Object_File_Suffix =>
1449 if Get_Name_String (Element.Value.Value) = "" then
1452 "object file suffix cannot be empty",
1453 Element.Value.Location, Project);
1456 Lang_Index.Config.Object_File_Suffix :=
1457 Element.Value.Value;
1460 when Name_Object_File_Switches =>
1462 Lang_Index.Config.Object_File_Switches,
1463 From_List => Element.Value.Values,
1464 In_Tree => Data.Tree);
1466 when Name_Pic_Option =>
1468 -- Attribute Compiler_Pic_Option (<language>)
1470 List := Element.Value.Values;
1472 if List = Nil_String then
1475 "compiler PIC option cannot be null",
1476 Element.Value.Location, Project);
1480 Lang_Index.Config.Compilation_PIC_Option,
1482 In_Tree => Data.Tree);
1484 when Name_Mapping_File_Switches =>
1486 -- Attribute Mapping_File_Switches (<language>)
1488 List := Element.Value.Values;
1490 if List = Nil_String then
1493 "mapping file switches cannot be null",
1494 Element.Value.Location, Project);
1498 Lang_Index.Config.Mapping_File_Switches,
1500 In_Tree => Data.Tree);
1502 when Name_Mapping_Spec_Suffix =>
1504 -- Attribute Mapping_Spec_Suffix (<language>)
1506 Lang_Index.Config.Mapping_Spec_Suffix :=
1507 File_Name_Type (Element.Value.Value);
1509 when Name_Mapping_Body_Suffix =>
1511 -- Attribute Mapping_Body_Suffix (<language>)
1513 Lang_Index.Config.Mapping_Body_Suffix :=
1514 File_Name_Type (Element.Value.Value);
1516 when Name_Config_File_Switches =>
1518 -- Attribute Config_File_Switches (<language>)
1520 List := Element.Value.Values;
1522 if List = Nil_String then
1525 "config file switches cannot be null",
1526 Element.Value.Location, Project);
1530 Lang_Index.Config.Config_File_Switches,
1532 In_Tree => Data.Tree);
1534 when Name_Objects_Path =>
1536 -- Attribute Objects_Path (<language>)
1538 Lang_Index.Config.Objects_Path :=
1539 Element.Value.Value;
1541 when Name_Objects_Path_File =>
1543 -- Attribute Objects_Path_File (<language>)
1545 Lang_Index.Config.Objects_Path_File :=
1546 Element.Value.Value;
1548 when Name_Config_Body_File_Name =>
1550 -- Attribute Config_Body_File_Name (<language>)
1552 Lang_Index.Config.Config_Body :=
1553 Element.Value.Value;
1555 when Name_Config_Body_File_Name_Pattern =>
1557 -- Attribute Config_Body_File_Name_Pattern
1560 Lang_Index.Config.Config_Body_Pattern :=
1561 Element.Value.Value;
1563 when Name_Config_Spec_File_Name =>
1565 -- Attribute Config_Spec_File_Name (<language>)
1567 Lang_Index.Config.Config_Spec :=
1568 Element.Value.Value;
1570 when Name_Config_Spec_File_Name_Pattern =>
1572 -- Attribute Config_Spec_File_Name_Pattern
1575 Lang_Index.Config.Config_Spec_Pattern :=
1576 Element.Value.Value;
1578 when Name_Config_File_Unique =>
1580 -- Attribute Config_File_Unique (<language>)
1583 Lang_Index.Config.Config_File_Unique :=
1585 (Get_Name_String (Element.Value.Value));
1587 when Constraint_Error =>
1590 "illegal value for Config_File_Unique",
1591 Element.Value.Location, Project);
1600 Element_Id := Element.Next;
1603 Current_Array_Id := Current_Array.Next;
1605 end Process_Compiler;
1607 --------------------
1608 -- Process_Naming --
1609 --------------------
1611 procedure Process_Naming (Attributes : Variable_Id) is
1612 Attribute_Id : Variable_Id;
1613 Attribute : Variable;
1616 -- Process non associated array attribute from package Naming
1618 Attribute_Id := Attributes;
1619 while Attribute_Id /= No_Variable loop
1620 Attribute := Data.Tree.Variable_Elements.Table (Attribute_Id);
1622 if not Attribute.Value.Default then
1623 if Attribute.Name = Name_Separate_Suffix then
1625 -- Attribute Separate_Suffix
1627 Get_Name_String (Attribute.Value.Value);
1628 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1629 Separate_Suffix := Name_Find;
1631 elsif Attribute.Name = Name_Casing then
1637 Value (Get_Name_String (Attribute.Value.Value));
1640 when Constraint_Error =>
1643 "invalid value for Casing",
1644 Attribute.Value.Location, Project);
1647 elsif Attribute.Name = Name_Dot_Replacement then
1649 -- Attribute Dot_Replacement
1651 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1656 Attribute_Id := Attribute.Next;
1660 procedure Process_Naming (Arrays : Array_Id) is
1661 Current_Array_Id : Array_Id;
1662 Current_Array : Array_Data;
1663 Element_Id : Array_Element_Id;
1664 Element : Array_Element;
1667 -- Process the associative array attribute of package Naming
1669 Current_Array_Id := Arrays;
1670 while Current_Array_Id /= No_Array loop
1671 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1673 Element_Id := Current_Array.Value;
1674 while Element_Id /= No_Array_Element loop
1675 Element := Data.Tree.Array_Elements.Table (Element_Id);
1677 -- Get the name of the language
1679 Lang_Index := Get_Language_From_Name
1680 (Project, Get_Name_String (Element.Index));
1682 if Lang_Index /= No_Language_Index then
1683 case Current_Array.Name is
1684 when Name_Spec_Suffix | Name_Specification_Suffix =>
1686 -- Attribute Spec_Suffix (<language>)
1688 Get_Name_String (Element.Value.Value);
1689 Canonical_Case_File_Name
1690 (Name_Buffer (1 .. Name_Len));
1691 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1694 when Name_Implementation_Suffix | Name_Body_Suffix =>
1696 Get_Name_String (Element.Value.Value);
1697 Canonical_Case_File_Name
1698 (Name_Buffer (1 .. Name_Len));
1700 -- Attribute Body_Suffix (<language>)
1702 Lang_Index.Config.Naming_Data.Body_Suffix :=
1704 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1705 Lang_Index.Config.Naming_Data.Body_Suffix;
1712 Element_Id := Element.Next;
1715 Current_Array_Id := Current_Array.Next;
1719 --------------------
1720 -- Process_Linker --
1721 --------------------
1723 procedure Process_Linker (Attributes : Variable_Id) is
1724 Attribute_Id : Variable_Id;
1725 Attribute : Variable;
1728 -- Process non associated array attribute from package Linker
1730 Attribute_Id := Attributes;
1731 while Attribute_Id /= No_Variable loop
1733 Data.Tree.Variable_Elements.Table (Attribute_Id);
1735 if not Attribute.Value.Default then
1736 if Attribute.Name = Name_Driver then
1738 -- Attribute Linker'Driver: the default linker to use
1740 Project.Config.Linker :=
1741 Path_Name_Type (Attribute.Value.Value);
1743 -- Linker'Driver is also used to link shared libraries
1744 -- if the obsolescent attribute Library_GCC has not been
1747 if Project.Config.Shared_Lib_Driver = No_File then
1748 Project.Config.Shared_Lib_Driver :=
1749 File_Name_Type (Attribute.Value.Value);
1752 elsif Attribute.Name = Name_Required_Switches then
1754 -- Attribute Required_Switches: the minimum
1755 -- options to use when invoking the linker
1757 Put (Into_List => Project.Config.Minimum_Linker_Options,
1758 From_List => Attribute.Value.Values,
1759 In_Tree => Data.Tree);
1761 elsif Attribute.Name = Name_Map_File_Option then
1762 Project.Config.Map_File_Option := Attribute.Value.Value;
1764 elsif Attribute.Name = Name_Max_Command_Line_Length then
1766 Project.Config.Max_Command_Line_Length :=
1767 Natural'Value (Get_Name_String
1768 (Attribute.Value.Value));
1771 when Constraint_Error =>
1774 "value must be positive or equal to 0",
1775 Attribute.Value.Location, Project);
1778 elsif Attribute.Name = Name_Response_File_Format then
1783 Get_Name_String (Attribute.Value.Value);
1784 To_Lower (Name_Buffer (1 .. Name_Len));
1787 if Name = Name_None then
1788 Project.Config.Resp_File_Format := None;
1790 elsif Name = Name_Gnu then
1791 Project.Config.Resp_File_Format := GNU;
1793 elsif Name = Name_Object_List then
1794 Project.Config.Resp_File_Format := Object_List;
1796 elsif Name = Name_Option_List then
1797 Project.Config.Resp_File_Format := Option_List;
1802 "illegal response file format",
1803 Attribute.Value.Location, Project);
1807 elsif Attribute.Name = Name_Response_File_Switches then
1808 Put (Into_List => Project.Config.Resp_File_Options,
1809 From_List => Attribute.Value.Values,
1810 In_Tree => Data.Tree);
1814 Attribute_Id := Attribute.Next;
1818 -- Start of processing for Process_Packages
1821 Packages := Project.Decl.Packages;
1822 while Packages /= No_Package loop
1823 Element := Data.Tree.Packages.Table (Packages);
1825 case Element.Name is
1828 -- Process attributes of package Binder
1830 Process_Binder (Element.Decl.Arrays);
1832 when Name_Builder =>
1834 -- Process attributes of package Builder
1836 Process_Builder (Element.Decl.Attributes);
1838 when Name_Compiler =>
1840 -- Process attributes of package Compiler
1842 Process_Compiler (Element.Decl.Arrays);
1846 -- Process attributes of package Linker
1848 Process_Linker (Element.Decl.Attributes);
1852 -- Process attributes of package Naming
1854 Process_Naming (Element.Decl.Attributes);
1855 Process_Naming (Element.Decl.Arrays);
1861 Packages := Element.Next;
1863 end Process_Packages;
1865 ---------------------------------------------
1866 -- Process_Project_Level_Simple_Attributes --
1867 ---------------------------------------------
1869 procedure Process_Project_Level_Simple_Attributes is
1870 Attribute_Id : Variable_Id;
1871 Attribute : Variable;
1872 List : String_List_Id;
1875 -- Process non associated array attribute at project level
1877 Attribute_Id := Project.Decl.Attributes;
1878 while Attribute_Id /= No_Variable loop
1880 Data.Tree.Variable_Elements.Table (Attribute_Id);
1882 if not Attribute.Value.Default then
1883 if Attribute.Name = Name_Target then
1885 -- Attribute Target: the target specified
1887 Project.Config.Target := Attribute.Value.Value;
1889 elsif Attribute.Name = Name_Library_Builder then
1891 -- Attribute Library_Builder: the application to invoke
1892 -- to build libraries.
1894 Project.Config.Library_Builder :=
1895 Path_Name_Type (Attribute.Value.Value);
1897 elsif Attribute.Name = Name_Archive_Builder then
1899 -- Attribute Archive_Builder: the archive builder
1900 -- (usually "ar") and its minimum options (usually "cr").
1902 List := Attribute.Value.Values;
1904 if List = Nil_String then
1907 "archive builder cannot be null",
1908 Attribute.Value.Location, Project);
1911 Put (Into_List => Project.Config.Archive_Builder,
1913 In_Tree => Data.Tree);
1915 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1917 -- Attribute Archive_Builder: the archive builder
1918 -- (usually "ar") and its minimum options (usually "cr").
1920 List := Attribute.Value.Values;
1922 if List /= Nil_String then
1925 Project.Config.Archive_Builder_Append_Option,
1927 In_Tree => Data.Tree);
1930 elsif Attribute.Name = Name_Archive_Indexer then
1932 -- Attribute Archive_Indexer: the optional archive
1933 -- indexer (usually "ranlib") with its minimum options
1936 List := Attribute.Value.Values;
1938 if List = Nil_String then
1941 "archive indexer cannot be null",
1942 Attribute.Value.Location, Project);
1945 Put (Into_List => Project.Config.Archive_Indexer,
1947 In_Tree => Data.Tree);
1949 elsif Attribute.Name = Name_Library_Partial_Linker then
1951 -- Attribute Library_Partial_Linker: the optional linker
1952 -- driver with its minimum options, to partially link
1955 List := Attribute.Value.Values;
1957 if List = Nil_String then
1960 "partial linker cannot be null",
1961 Attribute.Value.Location, Project);
1964 Put (Into_List => Project.Config.Lib_Partial_Linker,
1966 In_Tree => Data.Tree);
1968 elsif Attribute.Name = Name_Library_GCC then
1969 Project.Config.Shared_Lib_Driver :=
1970 File_Name_Type (Attribute.Value.Value);
1973 "?Library_'G'C'C is an obsolescent attribute, " &
1974 "use Linker''Driver instead",
1975 Attribute.Value.Location, Project);
1977 elsif Attribute.Name = Name_Archive_Suffix then
1978 Project.Config.Archive_Suffix :=
1979 File_Name_Type (Attribute.Value.Value);
1981 elsif Attribute.Name = Name_Linker_Executable_Option then
1983 -- Attribute Linker_Executable_Option: optional options
1984 -- to specify an executable name. Defaults to "-o".
1986 List := Attribute.Value.Values;
1988 if List = Nil_String then
1991 "linker executable option cannot be null",
1992 Attribute.Value.Location, Project);
1995 Put (Into_List => Project.Config.Linker_Executable_Option,
1997 In_Tree => Data.Tree);
1999 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2001 -- Attribute Linker_Lib_Dir_Option: optional options
2002 -- to specify a library search directory. Defaults to
2005 Get_Name_String (Attribute.Value.Value);
2007 if Name_Len = 0 then
2010 "linker library directory option cannot be empty",
2011 Attribute.Value.Location, Project);
2014 Project.Config.Linker_Lib_Dir_Option :=
2015 Attribute.Value.Value;
2017 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2019 -- Attribute Linker_Lib_Name_Option: optional options
2020 -- to specify the name of a library to be linked in.
2021 -- Defaults to "-l".
2023 Get_Name_String (Attribute.Value.Value);
2025 if Name_Len = 0 then
2028 "linker library name option cannot be empty",
2029 Attribute.Value.Location, Project);
2032 Project.Config.Linker_Lib_Name_Option :=
2033 Attribute.Value.Value;
2035 elsif Attribute.Name = Name_Run_Path_Option then
2037 -- Attribute Run_Path_Option: optional options to
2038 -- specify a path for libraries.
2040 List := Attribute.Value.Values;
2042 if List /= Nil_String then
2043 Put (Into_List => Project.Config.Run_Path_Option,
2045 In_Tree => Data.Tree);
2048 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2050 pragma Unsuppress (All_Checks);
2052 Project.Config.Separate_Run_Path_Options :=
2053 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2055 when Constraint_Error =>
2058 "invalid value """ &
2059 Get_Name_String (Attribute.Value.Value) &
2060 """ for Separate_Run_Path_Options",
2061 Attribute.Value.Location, Project);
2064 elsif Attribute.Name = Name_Library_Support then
2066 pragma Unsuppress (All_Checks);
2068 Project.Config.Lib_Support :=
2069 Library_Support'Value (Get_Name_String
2070 (Attribute.Value.Value));
2072 when Constraint_Error =>
2075 "invalid value """ &
2076 Get_Name_String (Attribute.Value.Value) &
2077 """ for Library_Support",
2078 Attribute.Value.Location, Project);
2081 elsif Attribute.Name = Name_Shared_Library_Prefix then
2082 Project.Config.Shared_Lib_Prefix :=
2083 File_Name_Type (Attribute.Value.Value);
2085 elsif Attribute.Name = Name_Shared_Library_Suffix then
2086 Project.Config.Shared_Lib_Suffix :=
2087 File_Name_Type (Attribute.Value.Value);
2089 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2091 pragma Unsuppress (All_Checks);
2093 Project.Config.Symbolic_Link_Supported :=
2094 Boolean'Value (Get_Name_String
2095 (Attribute.Value.Value));
2097 when Constraint_Error =>
2101 & Get_Name_String (Attribute.Value.Value)
2102 & """ for Symbolic_Link_Supported",
2103 Attribute.Value.Location, Project);
2107 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2110 pragma Unsuppress (All_Checks);
2112 Project.Config.Lib_Maj_Min_Id_Supported :=
2113 Boolean'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_Major_Minor_Id_Supported",
2122 Attribute.Value.Location, Project);
2125 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2127 pragma Unsuppress (All_Checks);
2129 Project.Config.Auto_Init_Supported :=
2130 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2132 when Constraint_Error =>
2136 & Get_Name_String (Attribute.Value.Value)
2137 & """ for Library_Auto_Init_Supported",
2138 Attribute.Value.Location, Project);
2141 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2142 List := Attribute.Value.Values;
2144 if List /= Nil_String then
2145 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2147 In_Tree => Data.Tree);
2150 elsif Attribute.Name = Name_Library_Version_Switches then
2151 List := Attribute.Value.Values;
2153 if List /= Nil_String then
2154 Put (Into_List => Project.Config.Lib_Version_Options,
2156 In_Tree => Data.Tree);
2161 Attribute_Id := Attribute.Next;
2163 end Process_Project_Level_Simple_Attributes;
2165 --------------------------------------------
2166 -- Process_Project_Level_Array_Attributes --
2167 --------------------------------------------
2169 procedure Process_Project_Level_Array_Attributes is
2170 Current_Array_Id : Array_Id;
2171 Current_Array : Array_Data;
2172 Element_Id : Array_Element_Id;
2173 Element : Array_Element;
2174 List : String_List_Id;
2177 -- Process the associative array attributes at project level
2179 Current_Array_Id := Project.Decl.Arrays;
2180 while Current_Array_Id /= No_Array loop
2181 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
2183 Element_Id := Current_Array.Value;
2184 while Element_Id /= No_Array_Element loop
2185 Element := Data.Tree.Array_Elements.Table (Element_Id);
2187 -- Get the name of the language
2190 Get_Language_From_Name
2191 (Project, Get_Name_String (Element.Index));
2193 if Lang_Index /= No_Language_Index then
2194 case Current_Array.Name is
2195 when Name_Inherit_Source_Path =>
2196 List := Element.Value.Values;
2198 if List /= Nil_String then
2201 Lang_Index.Config.Include_Compatible_Languages,
2203 In_Tree => Data.Tree,
2204 Lower_Case => True);
2207 when Name_Toolchain_Description =>
2209 -- Attribute Toolchain_Description (<language>)
2211 Lang_Index.Config.Toolchain_Description :=
2212 Element.Value.Value;
2214 when Name_Toolchain_Version =>
2216 -- Attribute Toolchain_Version (<language>)
2218 Lang_Index.Config.Toolchain_Version :=
2219 Element.Value.Value;
2221 when Name_Runtime_Library_Dir =>
2223 -- Attribute Runtime_Library_Dir (<language>)
2225 Lang_Index.Config.Runtime_Library_Dir :=
2226 Element.Value.Value;
2228 when Name_Runtime_Source_Dir =>
2230 -- Attribute Runtime_Library_Dir (<language>)
2232 Lang_Index.Config.Runtime_Source_Dir :=
2233 Element.Value.Value;
2235 when Name_Object_Generated =>
2237 pragma Unsuppress (All_Checks);
2243 (Get_Name_String (Element.Value.Value));
2245 Lang_Index.Config.Object_Generated := Value;
2247 -- If no object is generated, no object may be
2251 Lang_Index.Config.Objects_Linked := False;
2255 when Constraint_Error =>
2259 & Get_Name_String (Element.Value.Value)
2260 & """ for Object_Generated",
2261 Element.Value.Location, Project);
2264 when Name_Objects_Linked =>
2266 pragma Unsuppress (All_Checks);
2272 (Get_Name_String (Element.Value.Value));
2274 -- No change if Object_Generated is False, as this
2275 -- forces Objects_Linked to be False too.
2277 if Lang_Index.Config.Object_Generated then
2278 Lang_Index.Config.Objects_Linked := Value;
2282 when Constraint_Error =>
2286 & Get_Name_String (Element.Value.Value)
2287 & """ for Objects_Linked",
2288 Element.Value.Location, Project);
2295 Element_Id := Element.Next;
2298 Current_Array_Id := Current_Array.Next;
2300 end Process_Project_Level_Array_Attributes;
2302 -- Start of processing for Check_Configuration
2305 Process_Project_Level_Simple_Attributes;
2306 Process_Project_Level_Array_Attributes;
2309 -- For unit based languages, set Casing, Dot_Replacement and
2310 -- Separate_Suffix in Naming_Data.
2312 Lang_Index := Project.Languages;
2313 while Lang_Index /= No_Language_Index loop
2314 if Lang_Index.Name = Name_Ada then
2315 Lang_Index.Config.Naming_Data.Casing := Casing;
2316 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2318 if Separate_Suffix /= No_File then
2319 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2326 Lang_Index := Lang_Index.Next;
2329 -- Give empty names to various prefixes/suffixes, if they have not
2330 -- been specified in the configuration.
2332 if Project.Config.Archive_Suffix = No_File then
2333 Project.Config.Archive_Suffix := Empty_File;
2336 if Project.Config.Shared_Lib_Prefix = No_File then
2337 Project.Config.Shared_Lib_Prefix := Empty_File;
2340 if Project.Config.Shared_Lib_Suffix = No_File then
2341 Project.Config.Shared_Lib_Suffix := Empty_File;
2344 Lang_Index := Project.Languages;
2345 while Lang_Index /= No_Language_Index loop
2347 -- For all languages, Compiler_Driver needs to be specified. This is
2348 -- only needed if we do intend to compile (not in GPS for instance).
2350 if Data.Flags.Compiler_Driver_Mandatory
2351 and then Lang_Index.Config.Compiler_Driver = No_File
2353 Error_Msg_Name_1 := Lang_Index.Display_Name;
2356 "?no compiler specified for language %%" &
2357 ", ignoring all its sources",
2358 No_Location, Project);
2360 if Lang_Index = Project.Languages then
2361 Project.Languages := Lang_Index.Next;
2363 Prev_Index.Next := Lang_Index.Next;
2366 elsif Lang_Index.Name = Name_Ada then
2367 Prev_Index := Lang_Index;
2369 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2370 -- Body_Suffix need to be specified.
2372 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2375 "Dot_Replacement not specified for Ada",
2376 No_Location, Project);
2379 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2382 "Spec_Suffix not specified for Ada",
2383 No_Location, Project);
2386 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2389 "Body_Suffix not specified for Ada",
2390 No_Location, Project);
2394 Prev_Index := Lang_Index;
2396 -- For file based languages, either Spec_Suffix or Body_Suffix
2397 -- need to be specified.
2399 if Data.Flags.Require_Sources_Other_Lang
2400 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2401 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2403 Error_Msg_Name_1 := Lang_Index.Display_Name;
2406 "no suffixes specified for %%",
2407 No_Location, Project);
2411 Lang_Index := Lang_Index.Next;
2413 end Check_Configuration;
2415 -------------------------------
2416 -- Check_If_Externally_Built --
2417 -------------------------------
2419 procedure Check_If_Externally_Built
2420 (Project : Project_Id;
2421 Data : in out Tree_Processing_Data)
2423 Externally_Built : constant Variable_Value :=
2425 (Name_Externally_Built,
2426 Project.Decl.Attributes, Data.Tree);
2429 if not Externally_Built.Default then
2430 Get_Name_String (Externally_Built.Value);
2431 To_Lower (Name_Buffer (1 .. Name_Len));
2433 if Name_Buffer (1 .. Name_Len) = "true" then
2434 Project.Externally_Built := True;
2436 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2437 Error_Msg (Data.Flags,
2438 "Externally_Built may only be true or false",
2439 Externally_Built.Location, Project);
2443 -- A virtual project extending an externally built project is itself
2444 -- externally built.
2446 if Project.Virtual and then Project.Extends /= No_Project then
2447 Project.Externally_Built := Project.Extends.Externally_Built;
2450 if Current_Verbosity = High then
2451 Write_Str ("Project is ");
2453 if not Project.Externally_Built then
2457 Write_Line ("externally built.");
2459 end Check_If_Externally_Built;
2461 ----------------------
2462 -- Check_Interfaces --
2463 ----------------------
2465 procedure Check_Interfaces
2466 (Project : Project_Id;
2467 Data : in out Tree_Processing_Data)
2469 Interfaces : constant Prj.Variable_Value :=
2471 (Snames.Name_Interfaces,
2472 Project.Decl.Attributes,
2475 List : String_List_Id;
2476 Element : String_Element;
2477 Name : File_Name_Type;
2478 Iter : Source_Iterator;
2480 Project_2 : Project_Id;
2484 if not Interfaces.Default then
2486 -- Set In_Interfaces to False for all sources. It will be set to True
2487 -- later for the sources in the Interfaces list.
2489 Project_2 := Project;
2490 while Project_2 /= No_Project loop
2491 Iter := For_Each_Source (Data.Tree, Project_2);
2493 Source := Prj.Element (Iter);
2494 exit when Source = No_Source;
2495 Source.In_Interfaces := False;
2499 Project_2 := Project_2.Extends;
2502 List := Interfaces.Values;
2503 while List /= Nil_String loop
2504 Element := Data.Tree.String_Elements.Table (List);
2505 Name := Canonical_Case_File_Name (Element.Value);
2507 Project_2 := Project;
2509 while Project_2 /= No_Project loop
2510 Iter := For_Each_Source (Data.Tree, Project_2);
2513 Source := Prj.Element (Iter);
2514 exit when Source = No_Source;
2516 if Source.File = Name then
2517 if not Source.Locally_Removed then
2518 Source.In_Interfaces := True;
2519 Source.Declared_In_Interfaces := True;
2521 Other := Other_Part (Source);
2523 if Other /= No_Source then
2524 Other.In_Interfaces := True;
2525 Other.Declared_In_Interfaces := True;
2528 if Current_Verbosity = High then
2529 Write_Str (" interface: ");
2530 Write_Line (Get_Name_String (Source.Path.Name));
2540 Project_2 := Project_2.Extends;
2543 if Source = No_Source then
2544 Error_Msg_File_1 := File_Name_Type (Element.Value);
2545 Error_Msg_Name_1 := Project.Name;
2549 "{ cannot be an interface of project %% "
2550 & "as it is not one of its sources",
2551 Element.Location, Project);
2554 List := Element.Next;
2557 Project.Interfaces_Defined := True;
2559 elsif Project.Extends /= No_Project then
2560 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2562 if Project.Interfaces_Defined then
2563 Iter := For_Each_Source (Data.Tree, Project);
2565 Source := Prj.Element (Iter);
2566 exit when Source = No_Source;
2568 if not Source.Declared_In_Interfaces then
2569 Source.In_Interfaces := False;
2576 end Check_Interfaces;
2578 --------------------------
2579 -- Check_Package_Naming --
2580 --------------------------
2582 procedure Check_Package_Naming
2583 (Project : Project_Id;
2584 Data : in out Tree_Processing_Data;
2585 Bodies : out Array_Element_Id;
2586 Specs : out Array_Element_Id)
2588 Naming_Id : constant Package_Id :=
2590 (Name_Naming, Project.Decl.Packages, Data.Tree);
2591 Naming : Package_Element;
2593 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2595 procedure Check_Naming;
2596 -- Check the validity of the Naming package (suffixes valid, ...)
2598 procedure Check_Common
2599 (Dot_Replacement : in out File_Name_Type;
2600 Casing : in out Casing_Type;
2601 Casing_Defined : out Boolean;
2602 Separate_Suffix : in out File_Name_Type;
2603 Sep_Suffix_Loc : out Source_Ptr);
2604 -- Check attributes common
2606 procedure Process_Exceptions_File_Based
2607 (Lang_Id : Language_Ptr;
2608 Kind : Source_Kind);
2609 procedure Process_Exceptions_Unit_Based
2610 (Lang_Id : Language_Ptr;
2611 Kind : Source_Kind);
2612 -- Process the naming exceptions for the two types of languages
2614 procedure Initialize_Naming_Data;
2615 -- Initialize internal naming data for the various languages
2621 procedure Check_Common
2622 (Dot_Replacement : in out File_Name_Type;
2623 Casing : in out Casing_Type;
2624 Casing_Defined : out Boolean;
2625 Separate_Suffix : in out File_Name_Type;
2626 Sep_Suffix_Loc : out Source_Ptr)
2628 Dot_Repl : constant Variable_Value :=
2630 (Name_Dot_Replacement,
2631 Naming.Decl.Attributes,
2633 Casing_String : constant Variable_Value :=
2636 Naming.Decl.Attributes,
2638 Sep_Suffix : constant Variable_Value :=
2640 (Name_Separate_Suffix,
2641 Naming.Decl.Attributes,
2643 Dot_Repl_Loc : Source_Ptr;
2646 Sep_Suffix_Loc := No_Location;
2648 if not Dot_Repl.Default then
2650 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2652 if Length_Of_Name (Dot_Repl.Value) = 0 then
2654 (Data.Flags, "Dot_Replacement cannot be empty",
2655 Dot_Repl.Location, Project);
2658 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2659 Dot_Repl_Loc := Dot_Repl.Location;
2662 Repl : constant String := Get_Name_String (Dot_Replacement);
2665 -- Dot_Replacement cannot
2667 -- - start or end with an alphanumeric
2668 -- - be a single '_'
2669 -- - start with an '_' followed by an alphanumeric
2670 -- - contain a '.' except if it is "."
2673 or else Is_Alphanumeric (Repl (Repl'First))
2674 or else Is_Alphanumeric (Repl (Repl'Last))
2675 or else (Repl (Repl'First) = '_'
2679 Is_Alphanumeric (Repl (Repl'First + 1))))
2680 or else (Repl'Length > 1
2682 Index (Source => Repl, Pattern => ".") /= 0)
2687 """ is illegal for Dot_Replacement.",
2688 Dot_Repl_Loc, Project);
2693 if Dot_Replacement /= No_File then
2695 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2698 Casing_Defined := False;
2700 if not Casing_String.Default then
2702 (Casing_String.Kind = Single, "Casing is not a string");
2705 Casing_Image : constant String :=
2706 Get_Name_String (Casing_String.Value);
2709 if Casing_Image'Length = 0 then
2712 "Casing cannot be an empty string",
2713 Casing_String.Location, Project);
2716 Casing := Value (Casing_Image);
2717 Casing_Defined := True;
2720 when Constraint_Error =>
2721 Name_Len := Casing_Image'Length;
2722 Name_Buffer (1 .. Name_Len) := Casing_Image;
2723 Err_Vars.Error_Msg_Name_1 := Name_Find;
2726 "%% is not a correct Casing",
2727 Casing_String.Location, Project);
2731 Write_Attr ("Casing", Image (Casing));
2733 if not Sep_Suffix.Default then
2734 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2737 "Separate_Suffix cannot be empty",
2738 Sep_Suffix.Location, Project);
2741 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2742 Sep_Suffix_Loc := Sep_Suffix.Location;
2744 Check_Illegal_Suffix
2745 (Project, Separate_Suffix,
2746 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
2751 if Separate_Suffix /= No_File then
2753 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2757 -----------------------------------
2758 -- Process_Exceptions_File_Based --
2759 -----------------------------------
2761 procedure Process_Exceptions_File_Based
2762 (Lang_Id : Language_Ptr;
2765 Lang : constant Name_Id := Lang_Id.Name;
2766 Exceptions : Array_Element_Id;
2767 Exception_List : Variable_Value;
2768 Element_Id : String_List_Id;
2769 Element : String_Element;
2770 File_Name : File_Name_Type;
2772 Iter : Source_Iterator;
2779 (Name_Implementation_Exceptions,
2780 In_Arrays => Naming.Decl.Arrays,
2781 In_Tree => Data.Tree);
2786 (Name_Specification_Exceptions,
2787 In_Arrays => Naming.Decl.Arrays,
2788 In_Tree => Data.Tree);
2791 Exception_List := Value_Of
2793 In_Array => Exceptions,
2794 In_Tree => Data.Tree);
2796 if Exception_List /= Nil_Variable_Value then
2797 Element_Id := Exception_List.Values;
2798 while Element_Id /= Nil_String loop
2799 Element := Data.Tree.String_Elements.Table (Element_Id);
2800 File_Name := Canonical_Case_File_Name (Element.Value);
2802 Iter := For_Each_Source (Data.Tree, Project);
2804 Source := Prj.Element (Iter);
2805 exit when Source = No_Source or else Source.File = File_Name;
2809 if Source = No_Source then
2814 Source_Dir_Rank => 0,
2817 File_Name => File_Name,
2818 Display_File => File_Name_Type (Element.Value),
2819 Naming_Exception => True);
2822 -- Check if the file name is already recorded for another
2823 -- language or another kind.
2825 if Source.Language /= Lang_Id then
2828 "the same file cannot be a source of two languages",
2829 Element.Location, Project);
2831 elsif Source.Kind /= Kind then
2834 "the same file cannot be a source and a template",
2835 Element.Location, Project);
2838 -- If the file is already recorded for the same
2839 -- language and the same kind, it means that the file
2840 -- name appears several times in the *_Exceptions
2841 -- attribute; so there is nothing to do.
2844 Element_Id := Element.Next;
2847 end Process_Exceptions_File_Based;
2849 -----------------------------------
2850 -- Process_Exceptions_Unit_Based --
2851 -----------------------------------
2853 procedure Process_Exceptions_Unit_Based
2854 (Lang_Id : Language_Ptr;
2857 Lang : constant Name_Id := Lang_Id.Name;
2858 Exceptions : Array_Element_Id;
2859 Element : Array_Element;
2862 File_Name : File_Name_Type;
2871 In_Arrays => Naming.Decl.Arrays,
2872 In_Tree => Data.Tree);
2874 if Exceptions = No_Array_Element then
2877 (Name_Implementation,
2878 In_Arrays => Naming.Decl.Arrays,
2879 In_Tree => Data.Tree);
2886 In_Arrays => Naming.Decl.Arrays,
2887 In_Tree => Data.Tree);
2889 if Exceptions = No_Array_Element then
2893 In_Arrays => Naming.Decl.Arrays,
2894 In_Tree => Data.Tree);
2898 while Exceptions /= No_Array_Element loop
2899 Element := Data.Tree.Array_Elements.Table (Exceptions);
2900 File_Name := Canonical_Case_File_Name (Element.Value.Value);
2902 Get_Name_String (Element.Index);
2903 To_Lower (Name_Buffer (1 .. Name_Len));
2905 Index := Element.Value.Index;
2907 -- For Ada, check if it is a valid unit name
2909 if Lang = Name_Ada then
2910 Get_Name_String (Element.Index);
2911 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2913 if Unit = No_Name then
2914 Err_Vars.Error_Msg_Name_1 := Element.Index;
2917 "%% is not a valid unit name.",
2918 Element.Value.Location, Project);
2922 if Unit /= No_Name then
2927 Source_Dir_Rank => 0,
2930 File_Name => File_Name,
2931 Display_File => File_Name_Type (Element.Value.Value),
2934 Location => Element.Value.Location,
2935 Naming_Exception => True);
2938 Exceptions := Element.Next;
2940 end Process_Exceptions_Unit_Based;
2946 procedure Check_Naming is
2947 Dot_Replacement : File_Name_Type :=
2949 (First_Name_Id + Character'Pos ('-'));
2950 Separate_Suffix : File_Name_Type := No_File;
2951 Casing : Casing_Type := All_Lower_Case;
2952 Casing_Defined : Boolean;
2953 Lang_Id : Language_Ptr;
2954 Sep_Suffix_Loc : Source_Ptr;
2955 Suffix : Variable_Value;
2960 (Dot_Replacement => Dot_Replacement,
2962 Casing_Defined => Casing_Defined,
2963 Separate_Suffix => Separate_Suffix,
2964 Sep_Suffix_Loc => Sep_Suffix_Loc);
2966 -- For all unit based languages, if any, set the specified value
2967 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
2968 -- systematically overwrite, since the defaults come from the
2969 -- configuration file.
2971 if Dot_Replacement /= No_File
2972 or else Casing_Defined
2973 or else Separate_Suffix /= No_File
2975 Lang_Id := Project.Languages;
2976 while Lang_Id /= No_Language_Index loop
2977 if Lang_Id.Config.Kind = Unit_Based then
2978 if Dot_Replacement /= No_File then
2979 Lang_Id.Config.Naming_Data.Dot_Replacement :=
2983 if Casing_Defined then
2984 Lang_Id.Config.Naming_Data.Casing := Casing;
2988 Lang_Id := Lang_Id.Next;
2992 -- Next, get the spec and body suffixes
2994 Lang_Id := Project.Languages;
2995 while Lang_Id /= No_Language_Index loop
2996 Lang := Lang_Id.Name;
3002 Attribute_Or_Array_Name => Name_Spec_Suffix,
3003 In_Package => Naming_Id,
3004 In_Tree => Data.Tree);
3006 if Suffix = Nil_Variable_Value then
3009 Attribute_Or_Array_Name => Name_Specification_Suffix,
3010 In_Package => Naming_Id,
3011 In_Tree => Data.Tree);
3014 if Suffix /= Nil_Variable_Value then
3015 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3016 File_Name_Type (Suffix.Value);
3018 Check_Illegal_Suffix
3020 Lang_Id.Config.Naming_Data.Spec_Suffix,
3021 Lang_Id.Config.Naming_Data.Dot_Replacement,
3022 "Spec_Suffix", Suffix.Location, Data);
3026 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3034 Attribute_Or_Array_Name => Name_Body_Suffix,
3035 In_Package => Naming_Id,
3036 In_Tree => Data.Tree);
3038 if Suffix = Nil_Variable_Value then
3042 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3043 In_Package => Naming_Id,
3044 In_Tree => Data.Tree);
3047 if Suffix /= Nil_Variable_Value then
3048 Lang_Id.Config.Naming_Data.Body_Suffix :=
3049 File_Name_Type (Suffix.Value);
3051 -- The default value of separate suffix should be the same as
3052 -- the body suffix, so we need to compute that first.
3054 if Separate_Suffix = No_File then
3055 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3056 Lang_Id.Config.Naming_Data.Body_Suffix;
3060 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3062 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3066 Check_Illegal_Suffix
3068 Lang_Id.Config.Naming_Data.Body_Suffix,
3069 Lang_Id.Config.Naming_Data.Dot_Replacement,
3070 "Body_Suffix", Suffix.Location, Data);
3074 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3076 elsif Separate_Suffix /= No_File then
3077 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3080 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3081 -- since that would cause a clear ambiguity. Note that we do allow
3082 -- a Spec_Suffix to have the same termination as one of these,
3083 -- which causes a potential ambiguity, but we resolve that my
3084 -- matching the longest possible suffix.
3086 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3087 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3088 Lang_Id.Config.Naming_Data.Body_Suffix
3093 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3094 & """) cannot be the same as Spec_Suffix.",
3095 Ada_Body_Suffix_Loc, Project);
3098 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3099 Lang_Id.Config.Naming_Data.Separate_Suffix
3100 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3101 Lang_Id.Config.Naming_Data.Separate_Suffix
3105 "Separate_Suffix ("""
3107 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3108 & """) cannot be the same as Spec_Suffix.",
3109 Sep_Suffix_Loc, Project);
3112 Lang_Id := Lang_Id.Next;
3115 -- Get the naming exceptions for all languages
3117 for Kind in Spec .. Impl loop
3118 Lang_Id := Project.Languages;
3119 while Lang_Id /= No_Language_Index loop
3120 case Lang_Id.Config.Kind is
3122 Process_Exceptions_File_Based (Lang_Id, Kind);
3125 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3128 Lang_Id := Lang_Id.Next;
3133 ----------------------------
3134 -- Initialize_Naming_Data --
3135 ----------------------------
3137 procedure Initialize_Naming_Data is
3138 Specs : Array_Element_Id :=
3144 Impls : Array_Element_Id :=
3150 Lang : Language_Ptr;
3151 Lang_Name : Name_Id;
3152 Value : Variable_Value;
3153 Extended : Project_Id;
3156 -- At this stage, the project already contains the default extensions
3157 -- for the various languages. We now merge those suffixes read in the
3158 -- user project, and they override the default.
3160 while Specs /= No_Array_Element loop
3161 Lang_Name := Data.Tree.Array_Elements.Table (Specs).Index;
3163 Get_Language_From_Name
3164 (Project, Name => Get_Name_String (Lang_Name));
3166 -- An extending project inherits its parent projects' languages
3167 -- so if needed we should create entries for those languages
3170 Extended := Project.Extends;
3171 while Extended /= null loop
3172 Lang := Get_Language_From_Name
3173 (Extended, Name => Get_Name_String (Lang_Name));
3174 exit when Lang /= null;
3176 Extended := Extended.Extends;
3179 if Lang /= null then
3180 Lang := new Language_Data'(Lang.all);
3181 Lang.First_Source := null;
3182 Lang.Next := Project.Languages;
3183 Project.Languages := Lang;
3187 -- If language was not found in project or the projects it extends
3190 if Current_Verbosity = High then
3192 ("Ignoring spec naming data for "
3193 & Get_Name_String (Lang_Name)
3194 & " since language is not defined for this project");
3198 Value := Data.Tree.Array_Elements.Table (Specs).Value;
3200 if Value.Kind = Single then
3201 Lang.Config.Naming_Data.Spec_Suffix :=
3202 Canonical_Case_File_Name (Value.Value);
3206 Specs := Data.Tree.Array_Elements.Table (Specs).Next;
3209 while Impls /= No_Array_Element loop
3210 Lang_Name := Data.Tree.Array_Elements.Table (Impls).Index;
3212 Get_Language_From_Name
3213 (Project, Name => Get_Name_String (Lang_Name));
3216 if Current_Verbosity = High then
3218 ("Ignoring impl naming data for "
3219 & Get_Name_String (Lang_Name)
3220 & " since language is not defined for this project");
3223 Value := Data.Tree.Array_Elements.Table (Impls).Value;
3225 if Lang.Name = Name_Ada then
3226 Ada_Body_Suffix_Loc := Value.Location;
3229 if Value.Kind = Single then
3230 Lang.Config.Naming_Data.Body_Suffix :=
3231 Canonical_Case_File_Name (Value.Value);
3235 Impls := Data.Tree.Array_Elements.Table (Impls).Next;
3237 end Initialize_Naming_Data;
3239 -- Start of processing for Check_Naming_Schemes
3242 Specs := No_Array_Element;
3243 Bodies := No_Array_Element;
3245 -- No Naming package or parsing a configuration file? nothing to do
3247 if Naming_Id /= No_Package
3248 and then Project.Qualifier /= Configuration
3250 Naming := Data.Tree.Packages.Table (Naming_Id);
3252 if Current_Verbosity = High then
3253 Write_Line ("Checking package Naming for project "
3254 & Get_Name_String (Project.Name));
3257 Initialize_Naming_Data;
3260 end Check_Package_Naming;
3262 ------------------------------
3263 -- Check_Library_Attributes --
3264 ------------------------------
3266 procedure Check_Library_Attributes
3267 (Project : Project_Id;
3268 Data : in out Tree_Processing_Data)
3270 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3272 Lib_Dir : constant Prj.Variable_Value :=
3274 (Snames.Name_Library_Dir, Attributes, Data.Tree);
3276 Lib_Name : constant Prj.Variable_Value :=
3278 (Snames.Name_Library_Name, Attributes, Data.Tree);
3280 Lib_Version : constant Prj.Variable_Value :=
3282 (Snames.Name_Library_Version, Attributes, Data.Tree);
3284 Lib_ALI_Dir : constant Prj.Variable_Value :=
3286 (Snames.Name_Library_Ali_Dir, Attributes, Data.Tree);
3288 Lib_GCC : constant Prj.Variable_Value :=
3290 (Snames.Name_Library_GCC, Attributes, Data.Tree);
3292 The_Lib_Kind : constant Prj.Variable_Value :=
3294 (Snames.Name_Library_Kind, Attributes, Data.Tree);
3296 Imported_Project_List : Project_List;
3298 Continuation : String_Access := No_Continuation_String'Access;
3300 Support_For_Libraries : Library_Support;
3302 Library_Directory_Present : Boolean;
3304 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3305 -- Check if an imported or extended project if also a library project
3311 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3313 Iter : Source_Iterator;
3316 if Proj /= No_Project then
3317 if not Proj.Library then
3319 -- The only not library projects that are OK are those that
3320 -- have no sources. However, header files from non-Ada
3321 -- languages are OK, as there is nothing to compile.
3323 Iter := For_Each_Source (Data.Tree, Proj);
3325 Src_Id := Prj.Element (Iter);
3326 exit when Src_Id = No_Source
3327 or else Src_Id.Language.Config.Kind /= File_Based
3328 or else Src_Id.Kind /= Spec;
3332 if Src_Id /= No_Source then
3333 Error_Msg_Name_1 := Project.Name;
3334 Error_Msg_Name_2 := Proj.Name;
3337 if Project.Library_Kind /= Static then
3341 "shared library project %% cannot extend " &
3342 "project %% that is not a library project",
3343 Project.Location, Project);
3344 Continuation := Continuation_String'Access;
3347 elsif (not Unchecked_Shared_Lib_Imports)
3348 and then Project.Library_Kind /= Static
3353 "shared library project %% cannot import project %% " &
3354 "that is not a shared library project",
3355 Project.Location, Project);
3356 Continuation := Continuation_String'Access;
3360 elsif Project.Library_Kind /= Static and then
3361 Proj.Library_Kind = Static
3363 Error_Msg_Name_1 := Project.Name;
3364 Error_Msg_Name_2 := Proj.Name;
3370 "shared library project %% cannot extend static " &
3371 "library project %%",
3372 Project.Location, Project);
3373 Continuation := Continuation_String'Access;
3375 elsif not Unchecked_Shared_Lib_Imports then
3379 "shared library project %% cannot import static " &
3380 "library project %%",
3381 Project.Location, Project);
3382 Continuation := Continuation_String'Access;
3389 Dir_Exists : Boolean;
3391 -- Start of processing for Check_Library_Attributes
3394 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3396 -- Special case of extending project
3398 if Project.Extends /= No_Project then
3400 -- If the project extended is a library project, we inherit the
3401 -- library name, if it is not redefined; we check that the library
3402 -- directory is specified.
3404 if Project.Extends.Library then
3405 if Project.Qualifier = Standard then
3408 "a standard project cannot extend a library project",
3409 Project.Location, Project);
3412 if Lib_Name.Default then
3413 Project.Library_Name := Project.Extends.Library_Name;
3416 if Lib_Dir.Default then
3417 if not Project.Virtual then
3420 "a project extending a library project must " &
3421 "specify an attribute Library_Dir",
3422 Project.Location, Project);
3425 -- For a virtual project extending a library project,
3426 -- inherit library directory.
3428 Project.Library_Dir := Project.Extends.Library_Dir;
3429 Library_Directory_Present := True;
3436 pragma Assert (Lib_Name.Kind = Single);
3438 if Lib_Name.Value = Empty_String then
3439 if Current_Verbosity = High
3440 and then Project.Library_Name = No_Name
3442 Write_Line ("No library name");
3446 -- There is no restriction on the syntax of library names
3448 Project.Library_Name := Lib_Name.Value;
3451 if Project.Library_Name /= No_Name then
3452 if Current_Verbosity = High then
3454 ("Library name", Get_Name_String (Project.Library_Name));
3457 pragma Assert (Lib_Dir.Kind = Single);
3459 if not Library_Directory_Present then
3460 if Current_Verbosity = High then
3461 Write_Line ("No library directory");
3465 -- Find path name (unless inherited), check that it is a directory
3467 if Project.Library_Dir = No_Path_Information then
3470 File_Name_Type (Lib_Dir.Value),
3471 Path => Project.Library_Dir,
3472 Dir_Exists => Dir_Exists,
3474 Create => "library",
3475 Must_Exist => False,
3476 Location => Lib_Dir.Location,
3477 Externally_Built => Project.Externally_Built);
3483 (Project.Library_Dir.Display_Name));
3486 if not Dir_Exists then
3488 -- Get the absolute name of the library directory that
3489 -- does not exist, to report an error.
3491 Err_Vars.Error_Msg_File_1 :=
3492 File_Name_Type (Project.Library_Dir.Display_Name);
3495 "library directory { does not exist",
3496 Lib_Dir.Location, Project);
3498 -- The library directory cannot be the same as the Object
3501 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3504 "library directory cannot be the same " &
3505 "as object directory",
3506 Lib_Dir.Location, Project);
3507 Project.Library_Dir := No_Path_Information;
3511 OK : Boolean := True;
3512 Dirs_Id : String_List_Id;
3513 Dir_Elem : String_Element;
3517 -- The library directory cannot be the same as a source
3518 -- directory of the current project.
3520 Dirs_Id := Project.Source_Dirs;
3521 while Dirs_Id /= Nil_String loop
3522 Dir_Elem := Data.Tree.String_Elements.Table (Dirs_Id);
3523 Dirs_Id := Dir_Elem.Next;
3525 if Project.Library_Dir.Name =
3526 Path_Name_Type (Dir_Elem.Value)
3528 Err_Vars.Error_Msg_File_1 :=
3529 File_Name_Type (Dir_Elem.Value);
3532 "library directory cannot be the same " &
3533 "as source directory {",
3534 Lib_Dir.Location, Project);
3542 -- The library directory cannot be the same as a source
3543 -- directory of another project either.
3545 Pid := Data.Tree.Projects;
3547 exit Project_Loop when Pid = null;
3549 if Pid.Project /= Project then
3550 Dirs_Id := Pid.Project.Source_Dirs;
3552 Dir_Loop : while Dirs_Id /= Nil_String loop
3554 Data.Tree.String_Elements.Table (Dirs_Id);
3555 Dirs_Id := Dir_Elem.Next;
3557 if Project.Library_Dir.Name =
3558 Path_Name_Type (Dir_Elem.Value)
3560 Err_Vars.Error_Msg_File_1 :=
3561 File_Name_Type (Dir_Elem.Value);
3562 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3566 "library directory cannot be the same " &
3567 "as source directory { of project %%",
3568 Lib_Dir.Location, Project);
3576 end loop Project_Loop;
3580 Project.Library_Dir := No_Path_Information;
3582 elsif Current_Verbosity = High then
3584 -- Display the Library directory in high verbosity
3587 ("Library directory",
3588 Get_Name_String (Project.Library_Dir.Display_Name));
3597 Project.Library_Dir /= No_Path_Information
3598 and then Project.Library_Name /= No_Name;
3600 if Project.Extends = No_Project then
3601 case Project.Qualifier is
3603 if Project.Library then
3606 "a standard project cannot be a library project",
3607 Lib_Name.Location, Project);
3611 if not Project.Library then
3612 if Project.Library_Dir = No_Path_Information then
3615 "\attribute Library_Dir not declared",
3616 Project.Location, Project);
3619 if Project.Library_Name = No_Name then
3622 "\attribute Library_Name not declared",
3623 Project.Location, Project);
3633 if Project.Library then
3634 Support_For_Libraries := Project.Config.Lib_Support;
3636 if Support_For_Libraries = Prj.None then
3639 "?libraries are not supported on this platform",
3640 Lib_Name.Location, Project);
3641 Project.Library := False;
3644 if Lib_ALI_Dir.Value = Empty_String then
3645 if Current_Verbosity = High then
3646 Write_Line ("No library ALI directory specified");
3649 Project.Library_ALI_Dir := Project.Library_Dir;
3652 -- Find path name, check that it is a directory
3656 File_Name_Type (Lib_ALI_Dir.Value),
3657 Path => Project.Library_ALI_Dir,
3658 Create => "library ALI",
3659 Dir_Exists => Dir_Exists,
3661 Must_Exist => False,
3662 Location => Lib_ALI_Dir.Location,
3663 Externally_Built => Project.Externally_Built);
3665 if not Dir_Exists then
3667 -- Get the absolute name of the library ALI directory that
3668 -- does not exist, to report an error.
3670 Err_Vars.Error_Msg_File_1 :=
3671 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3674 "library 'A'L'I directory { does not exist",
3675 Lib_ALI_Dir.Location, Project);
3678 if Project.Library_ALI_Dir /= Project.Library_Dir then
3680 -- The library ALI directory cannot be the same as the
3681 -- Object directory.
3683 if Project.Library_ALI_Dir = Project.Object_Directory then
3686 "library 'A'L'I directory cannot be the same " &
3687 "as object directory",
3688 Lib_ALI_Dir.Location, Project);
3689 Project.Library_ALI_Dir := No_Path_Information;
3693 OK : Boolean := True;
3694 Dirs_Id : String_List_Id;
3695 Dir_Elem : String_Element;
3699 -- The library ALI directory cannot be the same as
3700 -- a source directory of the current project.
3702 Dirs_Id := Project.Source_Dirs;
3703 while Dirs_Id /= Nil_String loop
3705 Data.Tree.String_Elements.Table (Dirs_Id);
3706 Dirs_Id := Dir_Elem.Next;
3708 if Project.Library_ALI_Dir.Name =
3709 Path_Name_Type (Dir_Elem.Value)
3711 Err_Vars.Error_Msg_File_1 :=
3712 File_Name_Type (Dir_Elem.Value);
3715 "library 'A'L'I directory cannot be " &
3716 "the same as source directory {",
3717 Lib_ALI_Dir.Location, Project);
3725 -- The library ALI directory cannot be the same as
3726 -- a source directory of another project either.
3728 Pid := Data.Tree.Projects;
3729 ALI_Project_Loop : loop
3730 exit ALI_Project_Loop when Pid = null;
3732 if Pid.Project /= Project then
3733 Dirs_Id := Pid.Project.Source_Dirs;
3736 while Dirs_Id /= Nil_String loop
3738 Data.Tree.String_Elements.Table
3740 Dirs_Id := Dir_Elem.Next;
3742 if Project.Library_ALI_Dir.Name =
3743 Path_Name_Type (Dir_Elem.Value)
3745 Err_Vars.Error_Msg_File_1 :=
3746 File_Name_Type (Dir_Elem.Value);
3747 Err_Vars.Error_Msg_Name_1 :=
3752 "library 'A'L'I directory cannot " &
3753 "be the same as source directory " &
3755 Lib_ALI_Dir.Location, Project);
3757 exit ALI_Project_Loop;
3759 end loop ALI_Dir_Loop;
3762 end loop ALI_Project_Loop;
3766 Project.Library_ALI_Dir := No_Path_Information;
3768 elsif Current_Verbosity = High then
3770 -- Display Library ALI directory in high verbosity
3775 (Project.Library_ALI_Dir.Display_Name));
3782 pragma Assert (Lib_Version.Kind = Single);
3784 if Lib_Version.Value = Empty_String then
3785 if Current_Verbosity = High then
3786 Write_Line ("No library version specified");
3790 Project.Lib_Internal_Name := Lib_Version.Value;
3793 pragma Assert (The_Lib_Kind.Kind = Single);
3795 if The_Lib_Kind.Value = Empty_String then
3796 if Current_Verbosity = High then
3797 Write_Line ("No library kind specified");
3801 Get_Name_String (The_Lib_Kind.Value);
3804 Kind_Name : constant String :=
3805 To_Lower (Name_Buffer (1 .. Name_Len));
3807 OK : Boolean := True;
3810 if Kind_Name = "static" then
3811 Project.Library_Kind := Static;
3813 elsif Kind_Name = "dynamic" then
3814 Project.Library_Kind := Dynamic;
3816 elsif Kind_Name = "relocatable" then
3817 Project.Library_Kind := Relocatable;
3822 "illegal value for Library_Kind",
3823 The_Lib_Kind.Location, Project);
3827 if Current_Verbosity = High and then OK then
3828 Write_Attr ("Library kind", Kind_Name);
3831 if Project.Library_Kind /= Static then
3832 if Support_For_Libraries = Prj.Static_Only then
3835 "only static libraries are supported " &
3837 The_Lib_Kind.Location, Project);
3838 Project.Library := False;
3841 -- Check if (obsolescent) attribute Library_GCC or
3842 -- Linker'Driver is declared.
3844 if Lib_GCC.Value /= Empty_String then
3847 "?Library_'G'C'C is an obsolescent attribute, " &
3848 "use Linker''Driver instead",
3849 Lib_GCC.Location, Project);
3850 Project.Config.Shared_Lib_Driver :=
3851 File_Name_Type (Lib_GCC.Value);
3855 Linker : constant Package_Id :=
3858 Project.Decl.Packages,
3860 Driver : constant Variable_Value :=
3863 Attribute_Or_Array_Name =>
3865 In_Package => Linker,
3866 In_Tree => Data.Tree);
3869 if Driver /= Nil_Variable_Value
3870 and then Driver.Value /= Empty_String
3872 Project.Config.Shared_Lib_Driver :=
3873 File_Name_Type (Driver.Value);
3882 if Project.Library then
3883 if Current_Verbosity = High then
3884 Write_Line ("This is a library project file");
3887 Check_Library (Project.Extends, Extends => True);
3889 Imported_Project_List := Project.Imported_Projects;
3890 while Imported_Project_List /= null loop
3892 (Imported_Project_List.Project,
3894 Imported_Project_List := Imported_Project_List.Next;
3901 -- Check if Linker'Switches or Linker'Default_Switches are declared.
3902 -- Warn if they are declared, as it is a common error to think that
3903 -- library are "linked" with Linker switches.
3905 if Project.Library then
3907 Linker_Package_Id : constant Package_Id :=
3910 Project.Decl.Packages, Data.Tree);
3911 Linker_Package : Package_Element;
3912 Switches : Array_Element_Id := No_Array_Element;
3915 if Linker_Package_Id /= No_Package then
3916 Linker_Package := Data.Tree.Packages.Table (Linker_Package_Id);
3920 (Name => Name_Switches,
3921 In_Arrays => Linker_Package.Decl.Arrays,
3922 In_Tree => Data.Tree);
3924 if Switches = No_Array_Element then
3927 (Name => Name_Default_Switches,
3928 In_Arrays => Linker_Package.Decl.Arrays,
3929 In_Tree => Data.Tree);
3932 if Switches /= No_Array_Element then
3935 "?Linker switches not taken into account in library " &
3937 No_Location, Project);
3943 if Project.Extends /= No_Project then
3944 Project.Extends.Library := False;
3946 end Check_Library_Attributes;
3948 ---------------------------------
3949 -- Check_Programming_Languages --
3950 ---------------------------------
3952 procedure Check_Programming_Languages
3953 (Project : Project_Id;
3954 Data : in out Tree_Processing_Data)
3956 Languages : Variable_Value := Nil_Variable_Value;
3957 Def_Lang : Variable_Value := Nil_Variable_Value;
3958 Def_Lang_Id : Name_Id;
3960 procedure Add_Language (Name, Display_Name : Name_Id);
3961 -- Add a new language to the list of languages for the project.
3962 -- Nothing is done if the language has already been defined
3968 procedure Add_Language (Name, Display_Name : Name_Id) is
3969 Lang : Language_Ptr;
3972 Lang := Project.Languages;
3973 while Lang /= No_Language_Index loop
3974 if Name = Lang.Name then
3981 Lang := new Language_Data'(No_Language_Data);
3982 Lang.Next := Project.Languages;
3983 Project.Languages := Lang;
3985 Lang.Display_Name := Display_Name;
3987 if Name = Name_Ada then
3988 Lang.Config.Kind := Unit_Based;
3989 Lang.Config.Dependency_Kind := ALI_File;
3991 Lang.Config.Kind := File_Based;
3995 -- Start of processing for Check_Programming_Languages
3998 Project.Languages := null;
4000 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Data.Tree);
4003 (Name_Default_Language, Project.Decl.Attributes, Data.Tree);
4005 if Project.Source_Dirs /= Nil_String then
4007 -- Check if languages are specified in this project
4009 if Languages.Default then
4011 -- Fail if there is no default language defined
4013 if Def_Lang.Default then
4016 "no languages defined for this project",
4017 Project.Location, Project);
4018 Def_Lang_Id := No_Name;
4021 Get_Name_String (Def_Lang.Value);
4022 To_Lower (Name_Buffer (1 .. Name_Len));
4023 Def_Lang_Id := Name_Find;
4026 if Def_Lang_Id /= No_Name then
4027 Get_Name_String (Def_Lang_Id);
4028 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4030 (Name => Def_Lang_Id,
4031 Display_Name => Name_Find);
4036 Current : String_List_Id := Languages.Values;
4037 Element : String_Element;
4040 -- If there are no languages declared, there are no sources
4042 if Current = Nil_String then
4043 Project.Source_Dirs := Nil_String;
4045 if Project.Qualifier = Standard then
4048 "a standard project must have at least one language",
4049 Languages.Location, Project);
4053 -- Look through all the languages specified in attribute
4056 while Current /= Nil_String loop
4057 Element := Data.Tree.String_Elements.Table (Current);
4058 Get_Name_String (Element.Value);
4059 To_Lower (Name_Buffer (1 .. Name_Len));
4063 Display_Name => Element.Value);
4065 Current := Element.Next;
4071 end Check_Programming_Languages;
4073 -------------------------------
4074 -- Check_Stand_Alone_Library --
4075 -------------------------------
4077 procedure Check_Stand_Alone_Library
4078 (Project : Project_Id;
4079 Data : in out Tree_Processing_Data)
4081 Lib_Interfaces : constant Prj.Variable_Value :=
4083 (Snames.Name_Library_Interface,
4084 Project.Decl.Attributes,
4087 Lib_Auto_Init : constant Prj.Variable_Value :=
4089 (Snames.Name_Library_Auto_Init,
4090 Project.Decl.Attributes,
4093 Lib_Src_Dir : constant Prj.Variable_Value :=
4095 (Snames.Name_Library_Src_Dir,
4096 Project.Decl.Attributes,
4099 Lib_Symbol_File : constant Prj.Variable_Value :=
4101 (Snames.Name_Library_Symbol_File,
4102 Project.Decl.Attributes,
4105 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4107 (Snames.Name_Library_Symbol_Policy,
4108 Project.Decl.Attributes,
4111 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4113 (Snames.Name_Library_Reference_Symbol_File,
4114 Project.Decl.Attributes,
4117 Auto_Init_Supported : Boolean;
4118 OK : Boolean := True;
4120 Next_Proj : Project_Id;
4121 Iter : Source_Iterator;
4124 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4126 pragma Assert (Lib_Interfaces.Kind = List);
4128 -- It is a stand-alone library project file if attribute
4129 -- Library_Interface is defined.
4131 if not Lib_Interfaces.Default then
4133 Interfaces : String_List_Id := Lib_Interfaces.Values;
4134 Interface_ALIs : String_List_Id := Nil_String;
4138 Project.Standalone_Library := True;
4140 -- Library_Interface cannot be an empty list
4142 if Interfaces = Nil_String then
4145 "Library_Interface cannot be an empty list",
4146 Lib_Interfaces.Location, Project);
4149 -- Process each unit name specified in the attribute
4150 -- Library_Interface.
4152 while Interfaces /= Nil_String loop
4154 (Data.Tree.String_Elements.Table (Interfaces).Value);
4155 To_Lower (Name_Buffer (1 .. Name_Len));
4157 if Name_Len = 0 then
4160 "an interface cannot be an empty string",
4161 Data.Tree.String_Elements.Table (Interfaces).Location,
4166 Error_Msg_Name_1 := Unit;
4168 Next_Proj := Project.Extends;
4169 Iter := For_Each_Source (Data.Tree, Project);
4171 while Prj.Element (Iter) /= No_Source
4173 (Prj.Element (Iter).Unit = null
4174 or else Prj.Element (Iter).Unit.Name /= Unit)
4179 Source := Prj.Element (Iter);
4180 exit when Source /= No_Source
4181 or else Next_Proj = No_Project;
4183 Iter := For_Each_Source (Data.Tree, Next_Proj);
4184 Next_Proj := Next_Proj.Extends;
4187 if Source /= No_Source then
4188 if Source.Kind = Sep then
4189 Source := No_Source;
4191 elsif Source.Kind = Spec
4192 and then Other_Part (Source) /= No_Source
4194 Source := Other_Part (Source);
4198 if Source /= No_Source then
4199 if Source.Project /= Project
4200 and then not Is_Extending (Project, Source.Project)
4202 Source := No_Source;
4206 if Source = No_Source then
4209 "%% is not a unit of this project",
4210 Data.Tree.String_Elements.Table
4211 (Interfaces).Location, Project);
4214 if Source.Kind = Spec
4215 and then Other_Part (Source) /= No_Source
4217 Source := Other_Part (Source);
4220 String_Element_Table.Increment_Last
4221 (Data.Tree.String_Elements);
4223 Data.Tree.String_Elements.Table
4224 (String_Element_Table.Last
4225 (Data.Tree.String_Elements)) :=
4226 (Value => Name_Id (Source.Dep_Name),
4228 Display_Value => Name_Id (Source.Dep_Name),
4230 Data.Tree.String_Elements.Table
4231 (Interfaces).Location,
4233 Next => Interface_ALIs);
4236 String_Element_Table.Last
4237 (Data.Tree.String_Elements);
4241 Interfaces := Data.Tree.String_Elements.Table (Interfaces).Next;
4244 -- Put the list of Interface ALIs in the project data
4246 Project.Lib_Interface_ALIs := Interface_ALIs;
4248 -- Check value of attribute Library_Auto_Init and set
4249 -- Lib_Auto_Init accordingly.
4251 if Lib_Auto_Init.Default then
4253 -- If no attribute Library_Auto_Init is declared, then set auto
4254 -- init only if it is supported.
4256 Project.Lib_Auto_Init := Auto_Init_Supported;
4259 Get_Name_String (Lib_Auto_Init.Value);
4260 To_Lower (Name_Buffer (1 .. Name_Len));
4262 if Name_Buffer (1 .. Name_Len) = "false" then
4263 Project.Lib_Auto_Init := False;
4265 elsif Name_Buffer (1 .. Name_Len) = "true" then
4266 if Auto_Init_Supported then
4267 Project.Lib_Auto_Init := True;
4270 -- Library_Auto_Init cannot be "true" if auto init is not
4275 "library auto init not supported " &
4277 Lib_Auto_Init.Location, Project);
4283 "invalid value for attribute Library_Auto_Init",
4284 Lib_Auto_Init.Location, Project);
4289 -- If attribute Library_Src_Dir is defined and not the empty string,
4290 -- check if the directory exist and is not the object directory or
4291 -- one of the source directories. This is the directory where copies
4292 -- of the interface sources will be copied. Note that this directory
4293 -- may be the library directory.
4295 if Lib_Src_Dir.Value /= Empty_String then
4297 Dir_Id : constant File_Name_Type :=
4298 File_Name_Type (Lib_Src_Dir.Value);
4299 Dir_Exists : Boolean;
4305 Path => Project.Library_Src_Dir,
4306 Dir_Exists => Dir_Exists,
4308 Must_Exist => False,
4309 Create => "library source copy",
4310 Location => Lib_Src_Dir.Location,
4311 Externally_Built => Project.Externally_Built);
4313 -- If directory does not exist, report an error
4315 if not Dir_Exists then
4317 -- Get the absolute name of the library directory that does
4318 -- not exist, to report an error.
4320 Err_Vars.Error_Msg_File_1 :=
4321 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4324 "Directory { does not exist",
4325 Lib_Src_Dir.Location, Project);
4327 -- Report error if it is the same as the object directory
4329 elsif Project.Library_Src_Dir = Project.Object_Directory then
4332 "directory to copy interfaces cannot be " &
4333 "the object directory",
4334 Lib_Src_Dir.Location, Project);
4335 Project.Library_Src_Dir := No_Path_Information;
4339 Src_Dirs : String_List_Id;
4340 Src_Dir : String_Element;
4344 -- Interface copy directory cannot be one of the source
4345 -- directory of the current project.
4347 Src_Dirs := Project.Source_Dirs;
4348 while Src_Dirs /= Nil_String loop
4349 Src_Dir := Data.Tree.String_Elements.Table (Src_Dirs);
4351 -- Report error if it is one of the source directories
4353 if Project.Library_Src_Dir.Name =
4354 Path_Name_Type (Src_Dir.Value)
4358 "directory to copy interfaces cannot " &
4359 "be one of the source directories",
4360 Lib_Src_Dir.Location, Project);
4361 Project.Library_Src_Dir := No_Path_Information;
4365 Src_Dirs := Src_Dir.Next;
4368 if Project.Library_Src_Dir /= No_Path_Information then
4370 -- It cannot be a source directory of any other
4373 Pid := Data.Tree.Projects;
4375 exit Project_Loop when Pid = null;
4377 Src_Dirs := Pid.Project.Source_Dirs;
4378 Dir_Loop : while Src_Dirs /= Nil_String loop
4380 Data.Tree.String_Elements.Table (Src_Dirs);
4382 -- Report error if it is one of the source
4385 if Project.Library_Src_Dir.Name =
4386 Path_Name_Type (Src_Dir.Value)
4389 File_Name_Type (Src_Dir.Value);
4390 Error_Msg_Name_1 := Pid.Project.Name;
4393 "directory to copy interfaces cannot " &
4394 "be the same as source directory { of " &
4396 Lib_Src_Dir.Location, Project);
4397 Project.Library_Src_Dir :=
4398 No_Path_Information;
4402 Src_Dirs := Src_Dir.Next;
4406 end loop Project_Loop;
4410 -- In high verbosity, if there is a valid Library_Src_Dir,
4411 -- display its path name.
4413 if Project.Library_Src_Dir /= No_Path_Information
4414 and then Current_Verbosity = High
4417 ("Directory to copy interfaces",
4418 Get_Name_String (Project.Library_Src_Dir.Name));
4424 -- Check the symbol related attributes
4426 -- First, the symbol policy
4428 if not Lib_Symbol_Policy.Default then
4430 Value : constant String :=
4432 (Get_Name_String (Lib_Symbol_Policy.Value));
4435 -- Symbol policy must hove one of a limited number of values
4437 if Value = "autonomous" or else Value = "default" then
4438 Project.Symbol_Data.Symbol_Policy := Autonomous;
4440 elsif Value = "compliant" then
4441 Project.Symbol_Data.Symbol_Policy := Compliant;
4443 elsif Value = "controlled" then
4444 Project.Symbol_Data.Symbol_Policy := Controlled;
4446 elsif Value = "restricted" then
4447 Project.Symbol_Data.Symbol_Policy := Restricted;
4449 elsif Value = "direct" then
4450 Project.Symbol_Data.Symbol_Policy := Direct;
4455 "illegal value for Library_Symbol_Policy",
4456 Lib_Symbol_Policy.Location, Project);
4461 -- If attribute Library_Symbol_File is not specified, symbol policy
4462 -- cannot be Restricted.
4464 if Lib_Symbol_File.Default then
4465 if Project.Symbol_Data.Symbol_Policy = Restricted then
4468 "Library_Symbol_File needs to be defined when " &
4469 "symbol policy is Restricted",
4470 Lib_Symbol_Policy.Location, Project);
4474 -- Library_Symbol_File is defined
4476 Project.Symbol_Data.Symbol_File :=
4477 Path_Name_Type (Lib_Symbol_File.Value);
4479 Get_Name_String (Lib_Symbol_File.Value);
4481 if Name_Len = 0 then
4484 "symbol file name cannot be an empty string",
4485 Lib_Symbol_File.Location, Project);
4488 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4491 for J in 1 .. Name_Len loop
4492 if Name_Buffer (J) = '/'
4493 or else Name_Buffer (J) = Directory_Separator
4502 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4505 "symbol file name { is illegal. " &
4506 "Name cannot include directory info.",
4507 Lib_Symbol_File.Location, Project);
4512 -- If attribute Library_Reference_Symbol_File is not defined,
4513 -- symbol policy cannot be Compliant or Controlled.
4515 if Lib_Ref_Symbol_File.Default then
4516 if Project.Symbol_Data.Symbol_Policy = Compliant
4517 or else Project.Symbol_Data.Symbol_Policy = Controlled
4521 "a reference symbol file needs to be defined",
4522 Lib_Symbol_Policy.Location, Project);
4526 -- Library_Reference_Symbol_File is defined, check file exists
4528 Project.Symbol_Data.Reference :=
4529 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4531 Get_Name_String (Lib_Ref_Symbol_File.Value);
4533 if Name_Len = 0 then
4536 "reference symbol file name cannot be an empty string",
4537 Lib_Symbol_File.Location, Project);
4540 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4542 Add_Str_To_Name_Buffer
4543 (Get_Name_String (Project.Directory.Name));
4544 Add_Str_To_Name_Buffer
4545 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4546 Project.Symbol_Data.Reference := Name_Find;
4549 if not Is_Regular_File
4550 (Get_Name_String (Project.Symbol_Data.Reference))
4553 File_Name_Type (Lib_Ref_Symbol_File.Value);
4555 -- For controlled and direct symbol policies, it is an error
4556 -- if the reference symbol file does not exist. For other
4557 -- symbol policies, this is just a warning
4560 Project.Symbol_Data.Symbol_Policy /= Controlled
4561 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4565 "<library reference symbol file { does not exist",
4566 Lib_Ref_Symbol_File.Location, Project);
4568 -- In addition in the non-controlled case, if symbol policy
4569 -- is Compliant, it is changed to Autonomous, because there
4570 -- is no reference to check against, and we don't want to
4571 -- fail in this case.
4573 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4574 if Project.Symbol_Data.Symbol_Policy = Compliant then
4575 Project.Symbol_Data.Symbol_Policy := Autonomous;
4580 -- If both the reference symbol file and the symbol file are
4581 -- defined, then check that they are not the same file.
4583 if Project.Symbol_Data.Symbol_File /= No_Path then
4584 Get_Name_String (Project.Symbol_Data.Symbol_File);
4586 if Name_Len > 0 then
4588 -- We do not need to pass a Directory to
4589 -- Normalize_Pathname, since the path_information
4590 -- already contains absolute information.
4592 Symb_Path : constant String :=
4595 (Project.Object_Directory.Name) &
4596 Name_Buffer (1 .. Name_Len),
4599 Opt.Follow_Links_For_Files);
4600 Ref_Path : constant String :=
4603 (Project.Symbol_Data.Reference),
4606 Opt.Follow_Links_For_Files);
4608 if Symb_Path = Ref_Path then
4611 "library reference symbol file and library" &
4612 " symbol file cannot be the same file",
4613 Lib_Ref_Symbol_File.Location, Project);
4621 end Check_Stand_Alone_Library;
4623 ----------------------------
4624 -- Compute_Directory_Last --
4625 ----------------------------
4627 function Compute_Directory_Last (Dir : String) return Natural is
4630 and then (Dir (Dir'Last - 1) = Directory_Separator
4632 Dir (Dir'Last - 1) = '/')
4634 return Dir'Last - 1;
4638 end Compute_Directory_Last;
4640 ---------------------
4641 -- Get_Directories --
4642 ---------------------
4644 procedure Get_Directories
4645 (Project : Project_Id;
4646 Data : in out Tree_Processing_Data)
4648 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
4649 (Header_Num => Header_Num,
4651 No_Element => False,
4655 -- Hash table stores recursive source directories, to avoid looking
4656 -- several times, and to avoid cycles that may be introduced by symbolic
4659 Visited : Recursive_Dirs.Instance;
4661 Object_Dir : constant Variable_Value :=
4663 (Name_Object_Dir, Project.Decl.Attributes, Data.Tree);
4665 Exec_Dir : constant Variable_Value :=
4667 (Name_Exec_Dir, Project.Decl.Attributes, Data.Tree);
4669 Source_Dirs : constant Variable_Value :=
4671 (Name_Source_Dirs, Project.Decl.Attributes, Data.Tree);
4673 Excluded_Source_Dirs : constant Variable_Value :=
4675 (Name_Excluded_Source_Dirs,
4676 Project.Decl.Attributes,
4679 Source_Files : constant Variable_Value :=
4682 Project.Decl.Attributes, Data.Tree);
4684 Last_Source_Dir : String_List_Id := Nil_String;
4685 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
4687 Languages : constant Variable_Value :=
4689 (Name_Languages, Project.Decl.Attributes, Data.Tree);
4691 procedure Find_Source_Dirs
4692 (From : File_Name_Type;
4693 Location : Source_Ptr;
4695 Removed : Boolean := False);
4696 -- Find one or several source directories, and add (or remove, if
4697 -- Removed is True) them to list of source directories of the project.
4699 ----------------------
4700 -- Find_Source_Dirs --
4701 ----------------------
4703 procedure Find_Source_Dirs
4704 (From : File_Name_Type;
4705 Location : Source_Ptr;
4707 Removed : Boolean := False)
4709 Directory : constant String := Get_Name_String (From);
4711 procedure Add_To_Or_Remove_From_List
4713 Display_Path_Id : Name_Id);
4714 -- When Removed = False, the directory Path_Id to the list of
4715 -- source_dirs if not already in the list. When Removed = True,
4716 -- removed directory Path_Id if in the list.
4718 procedure Recursive_Find_Dirs (Path : Name_Id);
4719 -- Find all the subdirectories (recursively) of Path and add them
4720 -- to the list of source directories of the project.
4722 --------------------------------
4723 -- Add_To_Or_Remove_From_List --
4724 --------------------------------
4726 procedure Add_To_Or_Remove_From_List
4728 Display_Path_Id : Name_Id)
4730 List : String_List_Id;
4731 Prev : String_List_Id;
4732 Rank_List : Number_List_Index;
4733 Prev_Rank : Number_List_Index;
4734 Element : String_Element;
4738 Prev_Rank := No_Number_List;
4739 List := Project.Source_Dirs;
4740 Rank_List := Project.Source_Dir_Ranks;
4741 while List /= Nil_String loop
4742 Element := Data.Tree.String_Elements.Table (List);
4743 exit when Element.Value = Path_Id;
4745 List := Element.Next;
4746 Prev_Rank := Rank_List;
4747 Rank_List := Data.Tree.Number_Lists.Table (Prev_Rank).Next;
4750 -- The directory is in the list if List is not Nil_String
4752 if not Removed and then List = Nil_String then
4753 if Current_Verbosity = High then
4754 Write_Str (" Adding Source Dir=");
4755 Write_Line (Get_Name_String (Path_Id));
4758 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4762 Display_Value => Display_Path_Id,
4763 Location => No_Location,
4765 Next => Nil_String);
4767 Number_List_Table.Increment_Last (Data.Tree.Number_Lists);
4769 if Last_Source_Dir = Nil_String then
4771 -- This is the first source directory
4773 Project.Source_Dirs :=
4774 String_Element_Table.Last (Data.Tree.String_Elements);
4775 Project.Source_Dir_Ranks :=
4776 Number_List_Table.Last (Data.Tree.Number_Lists);
4779 -- We already have source directories, link the previous
4780 -- last to the new one.
4782 Data.Tree.String_Elements.Table (Last_Source_Dir).Next :=
4783 String_Element_Table.Last (Data.Tree.String_Elements);
4784 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
4785 Number_List_Table.Last (Data.Tree.Number_Lists);
4788 -- And register this source directory as the new last
4791 String_Element_Table.Last (Data.Tree.String_Elements);
4792 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4793 Last_Src_Dir_Rank :=
4794 Number_List_Table.Last (Data.Tree.Number_Lists);
4795 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank) :=
4796 (Number => Rank, Next => No_Number_List);
4798 elsif Removed and then List /= Nil_String then
4800 -- Remove source dir, if present
4802 if Prev = Nil_String then
4803 Project.Source_Dirs :=
4804 Data.Tree.String_Elements.Table (List).Next;
4805 Project.Source_Dir_Ranks :=
4806 Data.Tree.Number_Lists.Table (Rank_List).Next;
4809 Data.Tree.String_Elements.Table (Prev).Next :=
4810 Data.Tree.String_Elements.Table (List).Next;
4811 Data.Tree.Number_Lists.Table (Prev_Rank).Next :=
4812 Data.Tree.Number_Lists.Table (Rank_List).Next;
4815 end Add_To_Or_Remove_From_List;
4817 -------------------------
4818 -- Recursive_Find_Dirs --
4819 -------------------------
4821 procedure Recursive_Find_Dirs (Path : Name_Id) is
4823 Name : String (1 .. 250);
4826 Non_Canonical_Path : Name_Id := No_Name;
4827 Canonical_Path : Name_Id := No_Name;
4829 The_Path : constant String :=
4831 (Get_Name_String (Path),
4833 Get_Name_String (Project.Directory.Display_Name),
4834 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4835 Directory_Separator;
4837 The_Path_Last : constant Natural :=
4838 Compute_Directory_Last (The_Path);
4841 Name_Len := The_Path_Last - The_Path'First + 1;
4842 Name_Buffer (1 .. Name_Len) :=
4843 The_Path (The_Path'First .. The_Path_Last);
4844 Non_Canonical_Path := Name_Find;
4846 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4848 -- To avoid processing the same directory several times, check
4849 -- if the directory is already in Recursive_Dirs. If it is, then
4850 -- there is nothing to do, just return. If it is not, put it there
4851 -- and continue recursive processing.
4854 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4857 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4861 Add_To_Or_Remove_From_List
4862 (Path_Id => Canonical_Path,
4863 Display_Path_Id => Non_Canonical_Path);
4865 -- Now look for subdirectories. Do that even when this directory
4866 -- is already in the list, because some of its subdirectories may
4867 -- not be in the list yet.
4869 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4872 Read (Dir, Name, Last);
4875 if Name (1 .. Last) /= "."
4876 and then Name (1 .. Last) /= ".."
4878 -- Avoid . and .. directories
4880 if Current_Verbosity = High then
4881 Write_Str (" Checking ");
4882 Write_Line (Name (1 .. Last));
4886 Path_Name : constant String :=
4888 (Name => Name (1 .. Last),
4891 (The_Path'First .. The_Path_Last),
4893 Opt.Follow_Links_For_Dirs,
4894 Case_Sensitive => True);
4897 if Is_Directory (Path_Name) then
4899 -- We have found a new subdirectory, call self
4901 Name_Len := Path_Name'Length;
4902 Name_Buffer (1 .. Name_Len) := Path_Name;
4903 Recursive_Find_Dirs (Name_Find);
4912 when Directory_Error =>
4914 end Recursive_Find_Dirs;
4916 -- Start of processing for Find_Source_Dirs
4919 if Current_Verbosity = High and then not Removed then
4920 Write_Str ("Find_Source_Dirs (""");
4921 Write_Str (Directory);
4923 Write_Str (Rank'Img);
4927 -- First, check if we are looking for a directory tree, indicated
4928 -- by "/**" at the end.
4930 if Directory'Length >= 3
4931 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
4932 and then (Directory (Directory'Last - 2) = '/'
4934 Directory (Directory'Last - 2) = Directory_Separator)
4936 Name_Len := Directory'Length - 3;
4938 if Name_Len = 0 then
4940 -- Case of "/**": all directories in file system
4943 Name_Buffer (1) := Directory (Directory'First);
4946 Name_Buffer (1 .. Name_Len) :=
4947 Directory (Directory'First .. Directory'Last - 3);
4950 if Current_Verbosity = High then
4951 Write_Str ("Looking for all subdirectories of """);
4952 Write_Str (Name_Buffer (1 .. Name_Len));
4957 Base_Dir : constant File_Name_Type := Name_Find;
4958 Root_Dir : constant String :=
4960 (Name => Get_Name_String (Base_Dir),
4963 (Project.Directory.Display_Name),
4965 Opt.Follow_Links_For_Dirs,
4966 Case_Sensitive => True);
4969 if Root_Dir'Length = 0 then
4970 Err_Vars.Error_Msg_File_1 := Base_Dir;
4972 if Location = No_Location then
4975 "{ is not a valid directory.",
4976 Project.Location, Project);
4980 "{ is not a valid directory.",
4985 -- We have an existing directory, we register it and all of
4986 -- its subdirectories.
4988 if Current_Verbosity = High then
4989 Write_Line ("Looking for source directories:");
4992 Name_Len := Root_Dir'Length;
4993 Name_Buffer (1 .. Name_Len) := Root_Dir;
4994 Recursive_Find_Dirs (Name_Find);
4996 if Current_Verbosity = High then
4997 Write_Line ("End of looking for source directories.");
5002 -- We have a single directory
5006 Path_Name : Path_Information;
5007 Dir_Exists : Boolean;
5011 (Project => Project,
5014 Dir_Exists => Dir_Exists,
5016 Must_Exist => False);
5018 if not Dir_Exists then
5019 Err_Vars.Error_Msg_File_1 := From;
5021 if Location = No_Location then
5024 "{ is not a valid directory",
5025 Project.Location, Project);
5029 "{ is not a valid directory",
5035 Path : constant String :=
5038 Get_Name_String (Path_Name.Name),
5040 Get_Name_String (Project.Directory.Name),
5041 Resolve_Links => Opt.Follow_Links_For_Dirs,
5042 Case_Sensitive => True) &
5043 Directory_Separator;
5045 Last_Path : constant Natural :=
5046 Compute_Directory_Last (Path);
5048 Display_Path : constant String :=
5050 (Path_Name.Display_Name);
5051 Last_Display_Path : constant Natural :=
5052 Compute_Directory_Last
5054 Display_Path_Id : Name_Id;
5058 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5059 Path_Id := Name_Find;
5062 Add_Str_To_Name_Buffer
5064 (Display_Path'First .. Last_Display_Path));
5065 Display_Path_Id := Name_Find;
5067 Add_To_Or_Remove_From_List
5068 (Path_Id => Path_Id,
5069 Display_Path_Id => Display_Path_Id);
5075 Recursive_Dirs.Reset (Visited);
5076 end Find_Source_Dirs;
5078 -- Start of processing for Get_Directories
5080 Dir_Exists : Boolean;
5083 if Current_Verbosity = High then
5084 Write_Line ("Starting to look for directories");
5087 -- Set the object directory to its default which may be nil, if there
5088 -- is no sources in the project.
5090 if (((not Source_Files.Default)
5091 and then Source_Files.Values = Nil_String)
5093 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5095 ((not Languages.Default) and then Languages.Values = Nil_String))
5096 and then Project.Extends = No_Project
5098 Project.Object_Directory := No_Path_Information;
5100 Project.Object_Directory := Project.Directory;
5103 -- Check the object directory
5105 if Object_Dir.Value /= Empty_String then
5106 Get_Name_String (Object_Dir.Value);
5108 if Name_Len = 0 then
5111 "Object_Dir cannot be empty",
5112 Object_Dir.Location, Project);
5115 -- We check that the specified object directory does exist.
5116 -- However, even when it doesn't exist, we set it to a default
5117 -- value. This is for the benefit of tools that recover from
5118 -- errors; for example, these tools could create the non existent
5119 -- directory. We always return an absolute directory name though.
5123 File_Name_Type (Object_Dir.Value),
5124 Path => Project.Object_Directory,
5126 Dir_Exists => Dir_Exists,
5128 Location => Object_Dir.Location,
5129 Must_Exist => False,
5130 Externally_Built => Project.Externally_Built);
5133 and then not Project.Externally_Built
5135 -- The object directory does not exist, report an error if
5136 -- the project is not externally built.
5138 Err_Vars.Error_Msg_File_1 :=
5139 File_Name_Type (Object_Dir.Value);
5141 case Data.Flags.Require_Obj_Dirs is
5145 "object directory { not found",
5146 Project.Location, Project);
5150 "?object directory { not found",
5151 Project.Location, Project);
5158 elsif Project.Object_Directory /= No_Path_Information
5159 and then Subdirs /= null
5162 Name_Buffer (1) := '.';
5166 Path => Project.Object_Directory,
5168 Dir_Exists => Dir_Exists,
5170 Location => Object_Dir.Location,
5171 Externally_Built => Project.Externally_Built);
5174 if Current_Verbosity = High then
5175 if Project.Object_Directory = No_Path_Information then
5176 Write_Line ("No object directory");
5179 ("Object directory",
5180 Get_Name_String (Project.Object_Directory.Display_Name));
5184 -- Check the exec directory
5186 -- We set the object directory to its default
5188 Project.Exec_Directory := Project.Object_Directory;
5190 if Exec_Dir.Value /= Empty_String then
5191 Get_Name_String (Exec_Dir.Value);
5193 if Name_Len = 0 then
5196 "Exec_Dir cannot be empty",
5197 Exec_Dir.Location, Project);
5200 -- We check that the specified exec directory does exist
5204 File_Name_Type (Exec_Dir.Value),
5205 Path => Project.Exec_Directory,
5206 Dir_Exists => Dir_Exists,
5209 Location => Exec_Dir.Location,
5210 Externally_Built => Project.Externally_Built);
5212 if not Dir_Exists then
5213 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5216 "exec directory { not found",
5217 Project.Location, Project);
5222 if Current_Verbosity = High then
5223 if Project.Exec_Directory = No_Path_Information then
5224 Write_Line ("No exec directory");
5226 Write_Str ("Exec directory: """);
5227 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5232 -- Look for the source directories
5234 if Current_Verbosity = High then
5235 Write_Line ("Starting to look for source directories");
5238 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5240 if (not Source_Files.Default)
5241 and then Source_Files.Values = Nil_String
5243 Project.Source_Dirs := Nil_String;
5245 if Project.Qualifier = Standard then
5248 "a standard project cannot have no sources",
5249 Source_Files.Location, Project);
5252 elsif Source_Dirs.Default then
5254 -- No Source_Dirs specified: the single source directory is the one
5255 -- containing the project file.
5257 String_Element_Table.Append (Data.Tree.String_Elements,
5258 (Value => Name_Id (Project.Directory.Name),
5259 Display_Value => Name_Id (Project.Directory.Display_Name),
5260 Location => No_Location,
5265 Project.Source_Dirs :=
5266 String_Element_Table.Last (Data.Tree.String_Elements);
5268 Number_List_Table.Append
5269 (Data.Tree.Number_Lists,
5270 (Number => 1, Next => No_Number_List));
5272 Project.Source_Dir_Ranks :=
5273 Number_List_Table.Last (Data.Tree.Number_Lists);
5275 if Current_Verbosity = High then
5277 ("Default source directory",
5278 Get_Name_String (Project.Directory.Display_Name));
5281 elsif Source_Dirs.Values = Nil_String then
5282 if Project.Qualifier = Standard then
5285 "a standard project cannot have no source directories",
5286 Source_Dirs.Location, Project);
5289 Project.Source_Dirs := Nil_String;
5293 Source_Dir : String_List_Id;
5294 Element : String_Element;
5297 -- Process the source directories for each element of the list
5299 Source_Dir := Source_Dirs.Values;
5301 while Source_Dir /= Nil_String loop
5302 Element := Data.Tree.String_Elements.Table (Source_Dir);
5305 (File_Name_Type (Element.Value), Element.Location, Rank);
5306 Source_Dir := Element.Next;
5311 if not Excluded_Source_Dirs.Default
5312 and then Excluded_Source_Dirs.Values /= Nil_String
5315 Source_Dir : String_List_Id;
5316 Element : String_Element;
5319 -- Process the source directories for each element of the list
5321 Source_Dir := Excluded_Source_Dirs.Values;
5322 while Source_Dir /= Nil_String loop
5323 Element := Data.Tree.String_Elements.Table (Source_Dir);
5325 (File_Name_Type (Element.Value),
5329 Source_Dir := Element.Next;
5334 if Current_Verbosity = High then
5335 Write_Line ("Putting source directories in canonical cases");
5339 Current : String_List_Id := Project.Source_Dirs;
5340 Element : String_Element;
5343 while Current /= Nil_String loop
5344 Element := Data.Tree.String_Elements.Table (Current);
5345 if Element.Value /= No_Name then
5347 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5348 Data.Tree.String_Elements.Table (Current) := Element;
5351 Current := Element.Next;
5354 end Get_Directories;
5361 (Project : Project_Id;
5362 Data : in out Tree_Processing_Data)
5364 Mains : constant Variable_Value :=
5366 (Name_Main, Project.Decl.Attributes, Data.Tree);
5367 List : String_List_Id;
5368 Elem : String_Element;
5371 Project.Mains := Mains.Values;
5373 -- If no Mains were specified, and if we are an extending project,
5374 -- inherit the Mains from the project we are extending.
5376 if Mains.Default then
5377 if not Project.Library and then Project.Extends /= No_Project then
5378 Project.Mains := Project.Extends.Mains;
5381 -- In a library project file, Main cannot be specified
5383 elsif Project.Library then
5386 "a library project file cannot have Main specified",
5387 Mains.Location, Project);
5390 List := Mains.Values;
5391 while List /= Nil_String loop
5392 Elem := Data.Tree.String_Elements.Table (List);
5394 if Length_Of_Name (Elem.Value) = 0 then
5397 "?a main cannot have an empty name",
5398 Elem.Location, Project);
5407 ---------------------------
5408 -- Get_Sources_From_File --
5409 ---------------------------
5411 procedure Get_Sources_From_File
5413 Location : Source_Ptr;
5414 Project : in out Project_Processing_Data;
5415 Data : in out Tree_Processing_Data)
5417 File : Prj.Util.Text_File;
5418 Line : String (1 .. 250);
5420 Source_Name : File_Name_Type;
5421 Name_Loc : Name_Location;
5424 if Current_Verbosity = High then
5425 Write_Str ("Opening """);
5432 Prj.Util.Open (File, Path);
5434 if not Prj.Util.Is_Valid (File) then
5436 (Data.Flags, "file does not exist", Location, Project.Project);
5439 -- Read the lines one by one
5441 while not Prj.Util.End_Of_File (File) loop
5442 Prj.Util.Get_Line (File, Line, Last);
5444 -- A non empty, non comment line should contain a file name
5447 and then (Last = 1 or else Line (1 .. 2) /= "--")
5450 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5451 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5452 Source_Name := Name_Find;
5454 -- Check that there is no directory information
5456 for J in 1 .. Last loop
5457 if Line (J) = '/' or else Line (J) = Directory_Separator then
5458 Error_Msg_File_1 := Source_Name;
5461 "file name cannot include directory information ({)",
5462 Location, Project.Project);
5467 Name_Loc := Source_Names_Htable.Get
5468 (Project.Source_Names, Source_Name);
5470 if Name_Loc = No_Name_Location then
5472 (Name => Source_Name,
5473 Location => Location,
5474 Source => No_Source,
5478 Source_Names_Htable.Set
5479 (Project.Source_Names, Source_Name, Name_Loc);
5483 Prj.Util.Close (File);
5486 end Get_Sources_From_File;
5488 -----------------------
5489 -- Compute_Unit_Name --
5490 -----------------------
5492 procedure Compute_Unit_Name
5493 (File_Name : File_Name_Type;
5494 Naming : Lang_Naming_Data;
5495 Kind : out Source_Kind;
5497 Project : Project_Processing_Data;
5498 In_Tree : Project_Tree_Ref)
5500 Filename : constant String := Get_Name_String (File_Name);
5501 Last : Integer := Filename'Last;
5506 Unit_Except : Unit_Exception;
5507 Masked : Boolean := False;
5513 if Naming.Separate_Suffix = No_File
5514 or else Naming.Body_Suffix = No_File
5515 or else Naming.Spec_Suffix = No_File
5520 if Naming.Dot_Replacement = No_File then
5521 if Current_Verbosity = High then
5522 Write_Line (" No dot_replacement specified");
5528 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5529 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5530 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5532 -- Choose the longest suffix that matches. If there are several matches,
5533 -- give priority to specs, then bodies, then separates.
5535 if Naming.Separate_Suffix /= Naming.Body_Suffix
5536 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5538 Last := Filename'Last - Sep_Len;
5542 if Filename'Last - Body_Len <= Last
5543 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5545 Last := Natural'Min (Last, Filename'Last - Body_Len);
5549 if Filename'Last - Spec_Len <= Last
5550 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5552 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5556 if Last = Filename'Last then
5557 if Current_Verbosity = High then
5558 Write_Line (" no matching suffix");
5564 -- Check that the casing matches
5566 if File_Names_Case_Sensitive then
5567 case Naming.Casing is
5568 when All_Lower_Case =>
5569 for J in Filename'First .. Last loop
5570 if Is_Letter (Filename (J))
5571 and then not Is_Lower (Filename (J))
5573 if Current_Verbosity = High then
5574 Write_Line (" Invalid casing");
5581 when All_Upper_Case =>
5582 for J in Filename'First .. Last loop
5583 if Is_Letter (Filename (J))
5584 and then not Is_Upper (Filename (J))
5586 if Current_Verbosity = High then
5587 Write_Line (" Invalid casing");
5594 when Mixed_Case | Unknown =>
5599 -- If Dot_Replacement is not a single dot, then there should not
5600 -- be any dot in the name.
5603 Dot_Repl : constant String :=
5604 Get_Name_String (Naming.Dot_Replacement);
5607 if Dot_Repl /= "." then
5608 for Index in Filename'First .. Last loop
5609 if Filename (Index) = '.' then
5610 if Current_Verbosity = High then
5611 Write_Line (" Invalid name, contains dot");
5618 Replace_Into_Name_Buffer
5619 (Filename (Filename'First .. Last), Dot_Repl, '.');
5622 Name_Len := Last - Filename'First + 1;
5623 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5625 (Source => Name_Buffer (1 .. Name_Len),
5626 Mapping => Lower_Case_Map);
5630 -- In the standard GNAT naming scheme, check for special cases: children
5631 -- or separates of A, G, I or S, and run time sources.
5633 if Is_Standard_GNAT_Naming (Naming)
5634 and then Name_Len >= 3
5637 S1 : constant Character := Name_Buffer (1);
5638 S2 : constant Character := Name_Buffer (2);
5639 S3 : constant Character := Name_Buffer (3);
5647 -- Children or separates of packages A, G, I or S. These names
5648 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5649 -- versions (x__... and x~...) are allowed in all platforms,
5650 -- because it is not possible to know the platform before
5651 -- processing of the project files.
5653 if S2 = '_' and then S3 = '_' then
5654 Name_Buffer (2) := '.';
5655 Name_Buffer (3 .. Name_Len - 1) :=
5656 Name_Buffer (4 .. Name_Len);
5657 Name_Len := Name_Len - 1;
5660 Name_Buffer (2) := '.';
5664 -- If it is potentially a run time source
5672 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5673 -- that this is a valid unit name
5675 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5677 -- If there is a naming exception for the same unit, the file is not
5678 -- a source for the unit.
5680 if Unit /= No_Name then
5682 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5685 Masked := Unit_Except.Spec /= No_File
5687 Unit_Except.Spec /= File_Name;
5689 Masked := Unit_Except.Impl /= No_File
5691 Unit_Except.Impl /= File_Name;
5695 if Current_Verbosity = High then
5696 Write_Str (" """ & Filename & """ contains the ");
5699 Write_Str ("spec of a unit found in """);
5700 Write_Str (Get_Name_String (Unit_Except.Spec));
5702 Write_Str ("body of a unit found in """);
5703 Write_Str (Get_Name_String (Unit_Except.Impl));
5706 Write_Line (""" (ignored)");
5714 and then Current_Verbosity = High
5717 when Spec => Write_Str (" spec of ");
5718 when Impl => Write_Str (" body of ");
5719 when Sep => Write_Str (" sep of ");
5722 Write_Line (Get_Name_String (Unit));
5724 end Compute_Unit_Name;
5726 --------------------------
5727 -- Check_Illegal_Suffix --
5728 --------------------------
5730 procedure Check_Illegal_Suffix
5731 (Project : Project_Id;
5732 Suffix : File_Name_Type;
5733 Dot_Replacement : File_Name_Type;
5734 Attribute_Name : String;
5735 Location : Source_Ptr;
5736 Data : in out Tree_Processing_Data)
5738 Suffix_Str : constant String := Get_Name_String (Suffix);
5741 if Suffix_Str'Length = 0 then
5747 elsif Index (Suffix_Str, ".") = 0 then
5748 Err_Vars.Error_Msg_File_1 := Suffix;
5751 "{ is illegal for " & Attribute_Name & ": must have a dot",
5756 -- Case of dot replacement is a single dot, and first character of
5757 -- suffix is also a dot.
5759 if Dot_Replacement /= No_File
5760 and then Get_Name_String (Dot_Replacement) = "."
5761 and then Suffix_Str (Suffix_Str'First) = '.'
5763 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5765 -- If there are multiple dots in the name
5767 if Suffix_Str (Index) = '.' then
5769 -- It is illegal to have a letter following the initial dot
5771 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5772 Err_Vars.Error_Msg_File_1 := Suffix;
5775 "{ is illegal for " & Attribute_Name
5776 & ": ambiguous prefix when Dot_Replacement is a dot",
5783 end Check_Illegal_Suffix;
5785 ----------------------
5786 -- Locate_Directory --
5787 ----------------------
5789 procedure Locate_Directory
5790 (Project : Project_Id;
5791 Name : File_Name_Type;
5792 Path : out Path_Information;
5793 Dir_Exists : out Boolean;
5794 Data : in out Tree_Processing_Data;
5795 Create : String := "";
5796 Location : Source_Ptr := No_Location;
5797 Must_Exist : Boolean := True;
5798 Externally_Built : Boolean := False)
5800 Parent : constant Path_Name_Type :=
5801 Project.Directory.Display_Name;
5802 The_Parent : constant String :=
5803 Get_Name_String (Parent);
5804 The_Parent_Last : constant Natural :=
5805 Compute_Directory_Last (The_Parent);
5806 Full_Name : File_Name_Type;
5807 The_Name : File_Name_Type;
5810 Get_Name_String (Name);
5812 -- Add Subdirs.all if it is a directory that may be created and
5813 -- Subdirs is not null;
5815 if Create /= "" and then Subdirs /= null then
5816 if Name_Buffer (Name_Len) /= Directory_Separator then
5817 Add_Char_To_Name_Buffer (Directory_Separator);
5820 Add_Str_To_Name_Buffer (Subdirs.all);
5823 -- Convert '/' to directory separator (for Windows)
5825 for J in 1 .. Name_Len loop
5826 if Name_Buffer (J) = '/' then
5827 Name_Buffer (J) := Directory_Separator;
5831 The_Name := Name_Find;
5833 if Current_Verbosity = High then
5834 Write_Str ("Locate_Directory (""");
5835 Write_Str (Get_Name_String (The_Name));
5836 Write_Str (""", """);
5837 Write_Str (The_Parent);
5841 Path := No_Path_Information;
5842 Dir_Exists := False;
5844 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5845 Full_Name := The_Name;
5849 Add_Str_To_Name_Buffer
5850 (The_Parent (The_Parent'First .. The_Parent_Last));
5851 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5852 Full_Name := Name_Find;
5856 Full_Path_Name : String_Access :=
5857 new String'(Get_Name_String (Full_Name));
5860 if (Setup_Projects or else Subdirs /= null)
5861 and then Create'Length > 0
5863 if not Is_Directory (Full_Path_Name.all) then
5865 -- If project is externally built, do not create a subdir,
5866 -- use the specified directory, without the subdir.
5868 if Externally_Built then
5869 if Is_Absolute_Path (Get_Name_String (Name)) then
5870 Get_Name_String (Name);
5874 Add_Str_To_Name_Buffer
5875 (The_Parent (The_Parent'First .. The_Parent_Last));
5876 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5879 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5883 Create_Path (Full_Path_Name.all);
5885 if not Quiet_Output then
5887 Write_Str (" directory """);
5888 Write_Str (Full_Path_Name.all);
5889 Write_Str (""" created for project ");
5890 Write_Line (Get_Name_String (Project.Name));
5897 "could not create " & Create &
5898 " directory " & Full_Path_Name.all,
5905 Dir_Exists := Is_Directory (Full_Path_Name.all);
5907 if not Must_Exist or else Dir_Exists then
5909 Normed : constant String :=
5911 (Full_Path_Name.all,
5913 The_Parent (The_Parent'First .. The_Parent_Last),
5914 Resolve_Links => False,
5915 Case_Sensitive => True);
5917 Canonical_Path : constant String :=
5922 (The_Parent'First .. The_Parent_Last),
5924 Opt.Follow_Links_For_Dirs,
5925 Case_Sensitive => False);
5928 Name_Len := Normed'Length;
5929 Name_Buffer (1 .. Name_Len) := Normed;
5931 -- Directories should always end with a directory separator
5933 if Name_Buffer (Name_Len) /= Directory_Separator then
5934 Add_Char_To_Name_Buffer (Directory_Separator);
5937 Path.Display_Name := Name_Find;
5939 Name_Len := Canonical_Path'Length;
5940 Name_Buffer (1 .. Name_Len) := Canonical_Path;
5942 if Name_Buffer (Name_Len) /= Directory_Separator then
5943 Add_Char_To_Name_Buffer (Directory_Separator);
5946 Path.Name := Name_Find;
5950 Free (Full_Path_Name);
5952 end Locate_Directory;
5954 ---------------------------
5955 -- Find_Excluded_Sources --
5956 ---------------------------
5958 procedure Find_Excluded_Sources
5959 (Project : in out Project_Processing_Data;
5960 Data : in out Tree_Processing_Data)
5962 Excluded_Source_List_File : constant Variable_Value :=
5964 (Name_Excluded_Source_List_File,
5965 Project.Project.Decl.Attributes,
5967 Excluded_Sources : Variable_Value := Util.Value_Of
5968 (Name_Excluded_Source_Files,
5969 Project.Project.Decl.Attributes,
5972 Current : String_List_Id;
5973 Element : String_Element;
5974 Location : Source_Ptr;
5975 Name : File_Name_Type;
5976 File : Prj.Util.Text_File;
5977 Line : String (1 .. 300);
5979 Locally_Removed : Boolean := False;
5982 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
5984 if Excluded_Sources.Default then
5985 Locally_Removed := True;
5988 (Name_Locally_Removed_Files,
5989 Project.Project.Decl.Attributes, Data.Tree);
5992 -- If there are excluded sources, put them in the table
5994 if not Excluded_Sources.Default then
5995 if not Excluded_Source_List_File.Default then
5996 if Locally_Removed then
5999 "?both attributes Locally_Removed_Files and " &
6000 "Excluded_Source_List_File are present",
6001 Excluded_Source_List_File.Location, Project.Project);
6005 "?both attributes Excluded_Source_Files and " &
6006 "Excluded_Source_List_File are present",
6007 Excluded_Source_List_File.Location, Project.Project);
6011 Current := Excluded_Sources.Values;
6012 while Current /= Nil_String loop
6013 Element := Data.Tree.String_Elements.Table (Current);
6014 Name := Canonical_Case_File_Name (Element.Value);
6016 -- If the element has no location, then use the location of
6017 -- Excluded_Sources to report possible errors.
6019 if Element.Location = No_Location then
6020 Location := Excluded_Sources.Location;
6022 Location := Element.Location;
6025 Excluded_Sources_Htable.Set
6026 (Project.Excluded, Name, (Name, False, Location));
6027 Current := Element.Next;
6030 elsif not Excluded_Source_List_File.Default then
6031 Location := Excluded_Source_List_File.Location;
6034 Source_File_Path_Name : constant String :=
6037 (Excluded_Source_List_File.Value),
6038 Project.Project.Directory.Name);
6041 if Source_File_Path_Name'Length = 0 then
6042 Err_Vars.Error_Msg_File_1 :=
6043 File_Name_Type (Excluded_Source_List_File.Value);
6046 "file with excluded sources { does not exist",
6047 Excluded_Source_List_File.Location, Project.Project);
6052 Prj.Util.Open (File, Source_File_Path_Name);
6054 if not Prj.Util.Is_Valid (File) then
6056 (Data.Flags, "file does not exist",
6057 Location, Project.Project);
6059 -- Read the lines one by one
6061 while not Prj.Util.End_Of_File (File) loop
6062 Prj.Util.Get_Line (File, Line, Last);
6064 -- Non empty, non comment line should contain a file name
6067 and then (Last = 1 or else Line (1 .. 2) /= "--")
6070 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6071 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6074 -- Check that there is no directory information
6076 for J in 1 .. Last loop
6078 or else Line (J) = Directory_Separator
6080 Error_Msg_File_1 := Name;
6083 "file name cannot include " &
6084 "directory information ({)",
6085 Location, Project.Project);
6090 Excluded_Sources_Htable.Set
6091 (Project.Excluded, Name, (Name, False, Location));
6095 Prj.Util.Close (File);
6100 end Find_Excluded_Sources;
6106 procedure Find_Sources
6107 (Project : in out Project_Processing_Data;
6108 Data : in out Tree_Processing_Data)
6110 Sources : constant Variable_Value :=
6113 Project.Project.Decl.Attributes,
6116 Source_List_File : constant Variable_Value :=
6118 (Name_Source_List_File,
6119 Project.Project.Decl.Attributes,
6122 Name_Loc : Name_Location;
6123 Has_Explicit_Sources : Boolean;
6126 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6128 (Source_List_File.Kind = Single,
6129 "Source_List_File is not a single string");
6131 Project.Source_List_File_Location := Source_List_File.Location;
6133 -- If the user has specified a Source_Files attribute
6135 if not Sources.Default then
6136 if not Source_List_File.Default then
6139 "?both attributes source_files and " &
6140 "source_list_file are present",
6141 Source_List_File.Location, Project.Project);
6144 -- Sources is a list of file names
6147 Current : String_List_Id := Sources.Values;
6148 Element : String_Element;
6149 Location : Source_Ptr;
6150 Name : File_Name_Type;
6153 if Current = Nil_String then
6154 Project.Project.Languages := No_Language_Index;
6156 -- This project contains no source. For projects that don't
6157 -- extend other projects, this also means that there is no
6158 -- need for an object directory, if not specified.
6160 if Project.Project.Extends = No_Project
6161 and then Project.Project.Object_Directory =
6162 Project.Project.Directory
6164 Project.Project.Object_Directory := No_Path_Information;
6168 while Current /= Nil_String loop
6169 Element := Data.Tree.String_Elements.Table (Current);
6170 Name := Canonical_Case_File_Name (Element.Value);
6171 Get_Name_String (Element.Value);
6173 -- If the element has no location, then use the location of
6174 -- Sources to report possible errors.
6176 if Element.Location = No_Location then
6177 Location := Sources.Location;
6179 Location := Element.Location;
6182 -- Check that there is no directory information
6184 for J in 1 .. Name_Len loop
6185 if Name_Buffer (J) = '/'
6186 or else Name_Buffer (J) = Directory_Separator
6188 Error_Msg_File_1 := Name;
6191 "file name cannot include directory " &
6193 Location, Project.Project);
6198 -- Check whether the file is already there: the same file name
6199 -- may be in the list. If the source is missing, the error will
6200 -- be on the first mention of the source file name.
6202 Name_Loc := Source_Names_Htable.Get
6203 (Project.Source_Names, Name);
6205 if Name_Loc = No_Name_Location then
6208 Location => Location,
6209 Source => No_Source,
6211 Source_Names_Htable.Set
6212 (Project.Source_Names, Name, Name_Loc);
6215 Current := Element.Next;
6218 Has_Explicit_Sources := True;
6221 -- If we have no Source_Files attribute, check the Source_List_File
6224 elsif not Source_List_File.Default then
6226 -- Source_List_File is the name of the file that contains the source
6230 Source_File_Path_Name : constant String :=
6232 (File_Name_Type (Source_List_File.Value),
6233 Project.Project.Directory.Name);
6236 Has_Explicit_Sources := True;
6238 if Source_File_Path_Name'Length = 0 then
6239 Err_Vars.Error_Msg_File_1 :=
6240 File_Name_Type (Source_List_File.Value);
6243 "file with sources { does not exist",
6244 Source_List_File.Location, Project.Project);
6247 Get_Sources_From_File
6248 (Source_File_Path_Name, Source_List_File.Location,
6254 -- Neither Source_Files nor Source_List_File has been specified. Find
6255 -- all the files that satisfy the naming scheme in all the source
6258 Has_Explicit_Sources := False;
6264 For_All_Sources => Sources.Default and then Source_List_File.Default);
6266 -- Check if all exceptions have been found
6270 Iter : Source_Iterator;
6273 Iter := For_Each_Source (Data.Tree, Project.Project);
6275 Source := Prj.Element (Iter);
6276 exit when Source = No_Source;
6278 if Source.Naming_Exception
6279 and then Source.Path = No_Path_Information
6281 if Source.Unit /= No_Unit_Index then
6283 -- For multi-unit source files, source_id gets duplicated
6284 -- once for every unit. Only the first source_id got its
6285 -- full path set. So if it isn't set for that first one,
6286 -- the file wasn't found. Otherwise we need to update for
6287 -- units after the first one.
6290 or else Source.Index = 1
6292 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6293 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6296 "source file %% for unit %% not found",
6297 No_Location, Project.Project);
6300 Source.Path := Files_Htable.Get
6301 (Data.File_To_Source, Source.File).Path;
6303 if Current_Verbosity = High then
6304 if Source.Path /= No_Path_Information then
6305 Write_Line ("Setting full path for "
6306 & Get_Name_String (Source.File)
6307 & " at" & Source.Index'Img
6309 & Get_Name_String (Source.Path.Name));
6315 if Source.Path = No_Path_Information then
6316 Remove_Source (Source, No_Source);
6324 -- It is an error if a source file name in a source list or in a source
6325 -- list file is not found.
6327 if Has_Explicit_Sources then
6330 First_Error : Boolean;
6333 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6334 First_Error := True;
6335 while NL /= No_Name_Location loop
6336 if not NL.Found then
6337 Err_Vars.Error_Msg_File_1 := NL.Name;
6342 "source file { not found",
6343 NL.Location, Project.Project);
6344 First_Error := False;
6349 "\source file { not found",
6350 NL.Location, Project.Project);
6354 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6364 procedure Initialize
6365 (Data : out Tree_Processing_Data;
6366 Tree : Project_Tree_Ref;
6367 Flags : Prj.Processing_Flags)
6370 Files_Htable.Reset (Data.File_To_Source);
6372 Data.Flags := Flags;
6379 procedure Free (Data : in out Tree_Processing_Data) is
6381 Files_Htable.Reset (Data.File_To_Source);
6388 procedure Initialize
6389 (Data : in out Project_Processing_Data;
6390 Project : Project_Id)
6393 Data.Project := Project;
6400 procedure Free (Data : in out Project_Processing_Data) is
6402 Source_Names_Htable.Reset (Data.Source_Names);
6403 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6404 Excluded_Sources_Htable.Reset (Data.Excluded);
6407 -------------------------------
6408 -- Check_File_Naming_Schemes --
6409 -------------------------------
6411 procedure Check_File_Naming_Schemes
6412 (In_Tree : Project_Tree_Ref;
6413 Project : Project_Processing_Data;
6414 File_Name : File_Name_Type;
6415 Alternate_Languages : out Language_List;
6416 Language : out Language_Ptr;
6417 Display_Language_Name : out Name_Id;
6419 Lang_Kind : out Language_Kind;
6420 Kind : out Source_Kind)
6422 Filename : constant String := Get_Name_String (File_Name);
6423 Config : Language_Config;
6424 Tmp_Lang : Language_Ptr;
6426 Header_File : Boolean := False;
6427 -- True if we found at least one language for which the file is a header
6428 -- In such a case, we search for all possible languages where this is
6429 -- also a header (C and C++ for instance), since the file might be used
6430 -- for several such languages.
6432 procedure Check_File_Based_Lang;
6433 -- Does the naming scheme test for file-based languages. For those,
6434 -- there is no Unit. Just check if the file name has the implementation
6435 -- or, if it is specified, the template suffix of the language.
6437 -- Returns True if the file belongs to the current language and we
6438 -- should stop searching for matching languages. Not that a given header
6439 -- file could belong to several languages (C and C++ for instance). Thus
6440 -- if we found a header we'll check whether it matches other languages.
6442 ---------------------------
6443 -- Check_File_Based_Lang --
6444 ---------------------------
6446 procedure Check_File_Based_Lang is
6449 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6453 Language := Tmp_Lang;
6455 if Current_Verbosity = High then
6456 Write_Str (" implementation of language ");
6457 Write_Line (Get_Name_String (Display_Language_Name));
6460 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6461 if Current_Verbosity = High then
6462 Write_Str (" header of language ");
6463 Write_Line (Get_Name_String (Display_Language_Name));
6467 Alternate_Languages := new Language_List_Element'
6468 (Language => Language,
6469 Next => Alternate_Languages);
6472 Header_File := True;
6475 Language := Tmp_Lang;
6478 end Check_File_Based_Lang;
6480 -- Start of processing for Check_File_Naming_Schemes
6483 Language := No_Language_Index;
6484 Alternate_Languages := null;
6485 Display_Language_Name := No_Name;
6487 Lang_Kind := File_Based;
6490 Tmp_Lang := Project.Project.Languages;
6491 while Tmp_Lang /= No_Language_Index loop
6492 if Current_Verbosity = High then
6494 (" Testing language "
6495 & Get_Name_String (Tmp_Lang.Name)
6496 & " Header_File=" & Header_File'Img);
6499 Display_Language_Name := Tmp_Lang.Display_Name;
6500 Config := Tmp_Lang.Config;
6501 Lang_Kind := Config.Kind;
6505 Check_File_Based_Lang;
6506 exit when Kind = Impl;
6510 -- We know it belongs to a least a file_based language, no
6511 -- need to check unit-based ones.
6513 if not Header_File then
6515 (File_Name => File_Name,
6516 Naming => Config.Naming_Data,
6520 In_Tree => In_Tree);
6522 if Unit /= No_Name then
6523 Language := Tmp_Lang;
6529 Tmp_Lang := Tmp_Lang.Next;
6532 if Language = No_Language_Index
6533 and then Current_Verbosity = High
6535 Write_Line (" not a source of any language");
6537 end Check_File_Naming_Schemes;
6543 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6545 -- If the file was previously already associated with a unit, change it
6547 if Source.Unit /= null
6548 and then Source.Kind in Spec_Or_Body
6549 and then Source.Unit.File_Names (Source.Kind) /= null
6551 -- If we had another file referencing the same unit (for instance it
6552 -- was in an extended project), that source file is in fact invisible
6553 -- from now on, and in particular doesn't belong to the same unit.
6555 if Source.Unit.File_Names (Source.Kind) /= Source then
6556 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6559 Source.Unit.File_Names (Source.Kind) := null;
6562 Source.Kind := Kind;
6564 if Current_Verbosity = High
6565 and then Source.File /= No_File
6567 Write_Line ("Override kind for "
6568 & Get_Name_String (Source.File)
6569 & " kind=" & Source.Kind'Img);
6572 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6573 Source.Unit.File_Names (Source.Kind) := Source;
6581 procedure Check_File
6582 (Project : in out Project_Processing_Data;
6583 Data : in out Tree_Processing_Data;
6584 Source_Dir_Rank : Natural;
6585 Path : Path_Name_Type;
6586 File_Name : File_Name_Type;
6587 Display_File_Name : File_Name_Type;
6588 Locally_Removed : Boolean;
6589 For_All_Sources : Boolean)
6591 Canonical_Path : constant Path_Name_Type :=
6593 (Canonical_Case_File_Name (Name_Id (Path)));
6595 Name_Loc : Name_Location :=
6596 Source_Names_Htable.Get
6597 (Project.Source_Names, File_Name);
6598 Check_Name : Boolean := False;
6599 Alternate_Languages : Language_List;
6600 Language : Language_Ptr;
6602 Src_Ind : Source_File_Index;
6604 Display_Language_Name : Name_Id;
6605 Lang_Kind : Language_Kind;
6606 Kind : Source_Kind := Spec;
6609 if Current_Verbosity = High then
6610 Write_Line ("Checking file:");
6611 Write_Str (" Path = ");
6612 Write_Line (Get_Name_String (Path));
6613 Write_Str (" Rank =");
6614 Write_Line (Source_Dir_Rank'Img);
6617 if Name_Loc = No_Name_Location then
6618 Check_Name := For_All_Sources;
6621 if Name_Loc.Found then
6623 -- Check if it is OK to have the same file name in several
6624 -- source directories.
6626 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6627 Error_Msg_File_1 := File_Name;
6630 "{ is found in several source directories",
6631 Name_Loc.Location, Project.Project);
6635 Name_Loc.Found := True;
6637 Source_Names_Htable.Set
6638 (Project.Source_Names, File_Name, Name_Loc);
6640 if Name_Loc.Source = No_Source then
6644 Name_Loc.Source.Path := (Canonical_Path, Path);
6646 Source_Paths_Htable.Set
6647 (Data.Tree.Source_Paths_HT,
6651 -- Check if this is a subunit
6653 if Name_Loc.Source.Unit /= No_Unit_Index
6654 and then Name_Loc.Source.Kind = Impl
6656 Src_Ind := Sinput.P.Load_Project_File
6657 (Get_Name_String (Canonical_Path));
6659 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6660 Override_Kind (Name_Loc.Source, Sep);
6665 (Data.File_To_Source, File_Name, Name_Loc.Source);
6671 Check_File_Naming_Schemes
6672 (In_Tree => Data.Tree,
6674 File_Name => File_Name,
6675 Alternate_Languages => Alternate_Languages,
6676 Language => Language,
6677 Display_Language_Name => Display_Language_Name,
6679 Lang_Kind => Lang_Kind,
6682 if Language = No_Language_Index then
6684 -- A file name in a list must be a source of a language
6686 if Data.Flags.Error_On_Unknown_Language
6687 and then Name_Loc.Found
6689 Error_Msg_File_1 := File_Name;
6692 "language unknown for {",
6693 Name_Loc.Location, Project.Project);
6699 Project => Project.Project,
6700 Source_Dir_Rank => Source_Dir_Rank,
6701 Lang_Id => Language,
6704 Alternate_Languages => Alternate_Languages,
6705 File_Name => File_Name,
6706 Display_File => Display_File_Name,
6708 Locally_Removed => Locally_Removed,
6709 Path => (Canonical_Path, Path));
6711 -- If it is a source specified in a list, update the entry in
6712 -- the Source_Names table.
6714 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6715 Name_Loc.Source := Source;
6716 Source_Names_Htable.Set
6717 (Project.Source_Names, File_Name, Name_Loc);
6723 ------------------------
6724 -- Search_Directories --
6725 ------------------------
6727 procedure Search_Directories
6728 (Project : in out Project_Processing_Data;
6729 Data : in out Tree_Processing_Data;
6730 For_All_Sources : Boolean)
6732 Source_Dir : String_List_Id;
6733 Element : String_Element;
6734 Src_Dir_Rank : Number_List_Index;
6735 Num_Nod : Number_Node;
6737 Name : String (1 .. 1_000);
6739 File_Name : File_Name_Type;
6740 Display_File_Name : File_Name_Type;
6743 if Current_Verbosity = High then
6744 Write_Line ("Looking for sources:");
6747 -- Loop through subdirectories
6749 Source_Dir := Project.Project.Source_Dirs;
6750 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
6751 while Source_Dir /= Nil_String loop
6753 Num_Nod := Data.Tree.Number_Lists.Table (Src_Dir_Rank);
6754 Element := Data.Tree.String_Elements.Table (Source_Dir);
6756 if Element.Value /= No_Name then
6757 Get_Name_String (Element.Display_Value);
6759 if Current_Verbosity = High then
6760 Write_Str ("Directory: ");
6761 Write_Str (Name_Buffer (1 .. Name_Len));
6762 Write_Line (Num_Nod.Number'Img);
6766 Source_Directory : constant String :=
6767 Name_Buffer (1 .. Name_Len) &
6768 Directory_Separator;
6770 Dir_Last : constant Natural :=
6771 Compute_Directory_Last
6775 if Current_Verbosity = High then
6776 Write_Attr ("Source_Dir", Source_Directory);
6779 -- We look to every entry in the source directory
6781 Open (Dir, Source_Directory);
6784 Read (Dir, Name, Last);
6788 -- ??? Duplicate system call here, we just did a a
6789 -- similar one. Maybe Ada.Directories would be more
6790 -- appropriate here.
6793 (Source_Directory & Name (1 .. Last))
6795 if Current_Verbosity = High then
6796 Write_Str (" Checking ");
6797 Write_Line (Name (1 .. Last));
6801 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6802 Display_File_Name := Name_Find;
6804 if Osint.File_Names_Case_Sensitive then
6805 File_Name := Display_File_Name;
6807 Canonical_Case_File_Name
6808 (Name_Buffer (1 .. Name_Len));
6809 File_Name := Name_Find;
6813 Path_Name : constant String :=
6818 (Source_Directory'First ..
6821 Opt.Follow_Links_For_Files,
6822 Case_Sensitive => True);
6823 -- Case_Sensitive set True (no folding)
6825 Path : Path_Name_Type;
6826 FF : File_Found := Excluded_Sources_Htable.Get
6827 (Project.Excluded, File_Name);
6828 To_Remove : Boolean := False;
6831 Name_Len := Path_Name'Length;
6832 Name_Buffer (1 .. Name_Len) := Path_Name;
6835 if FF /= No_File_Found then
6836 if not FF.Found then
6838 Excluded_Sources_Htable.Set
6839 (Project.Excluded, File_Name, FF);
6841 if Current_Verbosity = High then
6842 Write_Str (" excluded source """);
6843 Write_Str (Get_Name_String (File_Name));
6847 -- Will mark the file as removed, but we
6848 -- still need to add it to the list: if we
6849 -- don't, the file will not appear in the
6850 -- mapping file and will cause the compiler
6858 (Project => Project,
6859 Source_Dir_Rank => Num_Nod.Number,
6862 File_Name => File_Name,
6863 Locally_Removed => To_Remove,
6864 Display_File_Name => Display_File_Name,
6865 For_All_Sources => For_All_Sources);
6875 when Directory_Error =>
6879 Source_Dir := Element.Next;
6880 Src_Dir_Rank := Num_Nod.Next;
6883 if Current_Verbosity = High then
6884 Write_Line ("end Looking for sources.");
6886 end Search_Directories;
6888 ----------------------------
6889 -- Load_Naming_Exceptions --
6890 ----------------------------
6892 procedure Load_Naming_Exceptions
6893 (Project : in out Project_Processing_Data;
6894 Data : in out Tree_Processing_Data)
6897 Iter : Source_Iterator;
6900 Iter := For_Each_Source (Data.Tree, Project.Project);
6902 Source := Prj.Element (Iter);
6903 exit when Source = No_Source;
6905 -- An excluded file cannot also be an exception file name
6907 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
6910 Error_Msg_File_1 := Source.File;
6913 "{ cannot be both excluded and an exception file name",
6914 No_Location, Project.Project);
6917 if Current_Verbosity = High then
6918 Write_Str ("Naming exception: Putting source file ");
6919 Write_Str (Get_Name_String (Source.File));
6920 Write_Line (" in Source_Names");
6923 Source_Names_Htable.Set
6924 (Project.Source_Names,
6927 (Name => Source.File,
6928 Location => No_Location,
6932 -- If this is an Ada exception, record in table Unit_Exceptions
6934 if Source.Unit /= No_Unit_Index then
6936 Unit_Except : Unit_Exception :=
6937 Unit_Exceptions_Htable.Get
6938 (Project.Unit_Exceptions, Source.Unit.Name);
6941 Unit_Except.Name := Source.Unit.Name;
6943 if Source.Kind = Spec then
6944 Unit_Except.Spec := Source.File;
6946 Unit_Except.Impl := Source.File;
6949 Unit_Exceptions_Htable.Set
6950 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
6956 end Load_Naming_Exceptions;
6958 ----------------------
6959 -- Look_For_Sources --
6960 ----------------------
6962 procedure Look_For_Sources
6963 (Project : in out Project_Processing_Data;
6964 Data : in out Tree_Processing_Data)
6966 Object_Files : Object_File_Names_Htable.Instance;
6967 Iter : Source_Iterator;
6970 procedure Check_Object (Src : Source_Id);
6971 -- Check if object file name of Src is already used in the project tree,
6972 -- and report an error if so.
6974 procedure Check_Object_Files;
6975 -- Check that no two sources of this project have the same object file
6977 procedure Mark_Excluded_Sources;
6978 -- Mark as such the sources that are declared as excluded
6984 procedure Check_Object (Src : Source_Id) is
6988 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
6990 -- We cannot just check on "Source /= Src", since we might have
6991 -- two different entries for the same file (and since that's
6992 -- the same file it is expected that it has the same object)
6994 if Source /= No_Source
6995 and then Source.Path /= Src.Path
6997 Error_Msg_File_1 := Src.File;
6998 Error_Msg_File_2 := Source.File;
7001 "{ and { have the same object file name",
7002 No_Location, Project.Project);
7005 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7009 ---------------------------
7010 -- Mark_Excluded_Sources --
7011 ---------------------------
7013 procedure Mark_Excluded_Sources is
7014 Source : Source_Id := No_Source;
7015 Excluded : File_Found;
7019 -- Minor optimization: if there are no excluded files, no need to
7020 -- traverse the list of sources. We cannot however also check whether
7021 -- the existing exceptions have ".Found" set to True (indicating we
7022 -- found them before) because we need to do some final processing on
7023 -- them in any case.
7025 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7028 Proj := Project.Project;
7029 while Proj /= No_Project loop
7030 Iter := For_Each_Source (Data.Tree, Proj);
7031 while Prj.Element (Iter) /= No_Source loop
7032 Source := Prj.Element (Iter);
7033 Excluded := Excluded_Sources_Htable.Get
7034 (Project.Excluded, Source.File);
7036 if Excluded /= No_File_Found then
7037 Source.Locally_Removed := True;
7038 Source.In_Interfaces := False;
7040 if Current_Verbosity = High then
7041 Write_Str ("Removing file ");
7043 (Get_Name_String (Excluded.File)
7044 & " " & Get_Name_String (Source.Project.Name));
7047 Excluded_Sources_Htable.Remove
7048 (Project.Excluded, Source.File);
7054 Proj := Proj.Extends;
7058 -- If we have any excluded element left, that means we did not find
7061 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7062 while Excluded /= No_File_Found loop
7063 if not Excluded.Found then
7065 -- Check if the file belongs to another imported project to
7066 -- provide a better error message.
7069 (In_Tree => Data.Tree,
7070 Project => Project.Project,
7071 In_Imported_Only => True,
7072 Base_Name => Excluded.File);
7074 Err_Vars.Error_Msg_File_1 := Excluded.File;
7076 if Src = No_Source then
7079 "unknown file {", Excluded.Location, Project.Project);
7083 "cannot remove a source from an imported project: {",
7084 Excluded.Location, Project.Project);
7088 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7090 end Mark_Excluded_Sources;
7092 ------------------------
7093 -- Check_Object_Files --
7094 ------------------------
7096 procedure Check_Object_Files is
7097 Iter : Source_Iterator;
7099 Src_Ind : Source_File_Index;
7102 Iter := For_Each_Source (Data.Tree);
7104 Src_Id := Prj.Element (Iter);
7105 exit when Src_Id = No_Source;
7107 if Is_Compilable (Src_Id)
7108 and then Src_Id.Language.Config.Object_Generated
7109 and then Is_Extending (Project.Project, Src_Id.Project)
7111 if Src_Id.Unit = No_Unit_Index then
7112 if Src_Id.Kind = Impl then
7113 Check_Object (Src_Id);
7119 if Other_Part (Src_Id) = No_Source then
7120 Check_Object (Src_Id);
7127 if Other_Part (Src_Id) /= No_Source then
7128 Check_Object (Src_Id);
7131 -- Check if it is a subunit
7134 Sinput.P.Load_Project_File
7135 (Get_Name_String (Src_Id.Path.Name));
7137 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7138 Override_Kind (Src_Id, Sep);
7140 Check_Object (Src_Id);
7149 end Check_Object_Files;
7151 -- Start of processing for Look_For_Sources
7154 Find_Excluded_Sources (Project, Data);
7156 if Project.Project.Languages /= No_Language_Index then
7157 Load_Naming_Exceptions (Project, Data);
7158 Find_Sources (Project, Data);
7159 Mark_Excluded_Sources;
7163 Object_File_Names_Htable.Reset (Object_Files);
7164 end Look_For_Sources;
7170 function Path_Name_Of
7171 (File_Name : File_Name_Type;
7172 Directory : Path_Name_Type) return String
7174 Result : String_Access;
7175 The_Directory : constant String := Get_Name_String (Directory);
7178 Get_Name_String (File_Name);
7181 (File_Name => Name_Buffer (1 .. Name_Len),
7182 Path => The_Directory);
7184 if Result = null then
7188 R : String := Result.all;
7191 Canonical_Case_File_Name (R);
7201 procedure Remove_Source
7203 Replaced_By : Source_Id)
7208 if Current_Verbosity = High then
7209 Write_Str ("Removing source ");
7210 Write_Str (Get_Name_String (Id.File));
7212 if Id.Index /= 0 then
7213 Write_Str (" at" & Id.Index'Img);
7219 if Replaced_By /= No_Source then
7220 Id.Replaced_By := Replaced_By;
7221 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7224 Id.In_Interfaces := False;
7225 Id.Locally_Removed := True;
7227 -- ??? Should we remove the source from the unit ? The file is not used,
7228 -- so probably should not be referenced from the unit. On the other hand
7229 -- it might give useful additional info
7230 -- if Id.Unit /= null then
7231 -- Id.Unit.File_Names (Id.Kind) := null;
7234 Source := Id.Language.First_Source;
7237 Id.Language.First_Source := Id.Next_In_Lang;
7240 while Source.Next_In_Lang /= Id loop
7241 Source := Source.Next_In_Lang;
7244 Source.Next_In_Lang := Id.Next_In_Lang;
7248 -----------------------
7249 -- Report_No_Sources --
7250 -----------------------
7252 procedure Report_No_Sources
7253 (Project : Project_Id;
7255 Data : Tree_Processing_Data;
7256 Location : Source_Ptr;
7257 Continuation : Boolean := False)
7260 case Data.Flags.When_No_Sources is
7264 when Warning | Error =>
7266 Msg : constant String :=
7269 " sources in this project";
7272 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7274 if Continuation then
7275 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7277 Error_Msg (Data.Flags, Msg, Location, Project);
7281 end Report_No_Sources;
7283 ----------------------
7284 -- Show_Source_Dirs --
7285 ----------------------
7287 procedure Show_Source_Dirs
7288 (Project : Project_Id;
7289 In_Tree : Project_Tree_Ref)
7291 Current : String_List_Id;
7292 Element : String_Element;
7295 Write_Line ("Source_Dirs:");
7297 Current := Project.Source_Dirs;
7298 while Current /= Nil_String loop
7299 Element := In_Tree.String_Elements.Table (Current);
7301 Write_Line (Get_Name_String (Element.Value));
7302 Current := Element.Next;
7305 Write_Line ("end Source_Dirs.");
7306 end Show_Source_Dirs;
7308 ---------------------------
7309 -- Process_Naming_Scheme --
7310 ---------------------------
7312 procedure Process_Naming_Scheme
7313 (Tree : Project_Tree_Ref;
7314 Root_Project : Project_Id;
7315 Flags : Processing_Flags)
7317 procedure Recursive_Check
7318 (Project : Project_Id;
7319 Data : in out Tree_Processing_Data);
7320 -- Check_Naming_Scheme for the project
7322 ---------------------
7323 -- Recursive_Check --
7324 ---------------------
7326 procedure Recursive_Check
7327 (Project : Project_Id;
7328 Data : in out Tree_Processing_Data)
7331 if Verbose_Mode then
7332 Write_Str ("Processing_Naming_Scheme for project """);
7333 Write_Str (Get_Name_String (Project.Name));
7337 Prj.Nmsc.Check (Project, Data);
7338 end Recursive_Check;
7340 procedure Check_All_Projects is new
7341 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7343 Data : Tree_Processing_Data;
7345 -- Start of processing for Process_Naming_Scheme
7347 Initialize (Data, Tree => Tree, Flags => Flags);
7348 Check_All_Projects (Root_Project, Data, Imported_First => True);
7350 end Process_Naming_Scheme;