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);
4710 Element : String_Element;
4712 procedure Recursive_Find_Dirs (Path : Name_Id);
4713 -- Find all the subdirectories (recursively) of Path and add them
4714 -- to the list of source directories of the project.
4716 -------------------------
4717 -- Recursive_Find_Dirs --
4718 -------------------------
4720 procedure Recursive_Find_Dirs (Path : Name_Id) is
4722 Name : String (1 .. 250);
4724 List : String_List_Id;
4725 Prev : String_List_Id;
4726 Rank_List : Number_List_Index;
4727 Prev_Rank : Number_List_Index;
4728 Element : String_Element;
4729 Found : Boolean := False;
4731 Non_Canonical_Path : Name_Id := No_Name;
4732 Canonical_Path : Name_Id := No_Name;
4734 The_Path : constant String :=
4736 (Get_Name_String (Path),
4738 Get_Name_String (Project.Directory.Display_Name),
4739 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4740 Directory_Separator;
4742 The_Path_Last : constant Natural :=
4743 Compute_Directory_Last (The_Path);
4746 Name_Len := The_Path_Last - The_Path'First + 1;
4747 Name_Buffer (1 .. Name_Len) :=
4748 The_Path (The_Path'First .. The_Path_Last);
4749 Non_Canonical_Path := Name_Find;
4751 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4753 -- To avoid processing the same directory several times, check
4754 -- if the directory is already in Recursive_Dirs. If it is, then
4755 -- there is nothing to do, just return. If it is not, put it there
4756 -- and continue recursive processing.
4759 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4762 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4766 -- Check if directory is already in list
4768 List := Project.Source_Dirs;
4770 Rank_List := Project.Source_Dir_Ranks;
4771 Prev_Rank := No_Number_List;
4772 while List /= Nil_String loop
4773 Element := Data.Tree.String_Elements.Table (List);
4775 if Element.Value /= No_Name then
4776 Found := Element.Value = Canonical_Path;
4781 List := Element.Next;
4782 Prev_Rank := Rank_List;
4783 Rank_List := Data.Tree.Number_Lists.Table (Rank_List).Next;
4786 -- If directory is not already in list, put it there
4788 if (not Removed) and (not Found) then
4789 if Current_Verbosity = High then
4791 Write_Line (The_Path (The_Path'First .. The_Path_Last));
4794 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4796 (Value => Canonical_Path,
4797 Display_Value => Non_Canonical_Path,
4798 Location => No_Location,
4803 Number_List_Table.Increment_Last (Data.Tree.Number_Lists);
4805 -- Case of first source directory
4807 if Last_Source_Dir = Nil_String then
4808 Project.Source_Dirs :=
4809 String_Element_Table.Last (Data.Tree.String_Elements);
4810 Project.Source_Dir_Ranks :=
4811 Number_List_Table.Last (Data.Tree.Number_Lists);
4813 -- Here we already have source directories
4816 -- Link the previous last to the new one
4818 Data.Tree.String_Elements.Table
4819 (Last_Source_Dir).Next :=
4820 String_Element_Table.Last (Data.Tree.String_Elements);
4821 Data.Tree.Number_Lists.Table
4822 (Last_Src_Dir_Rank).Next :=
4823 Number_List_Table.Last (Data.Tree.Number_Lists);
4827 -- And register this source directory as the new last
4830 String_Element_Table.Last (Data.Tree.String_Elements);
4831 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4832 Last_Src_Dir_Rank :=
4833 Number_List_Table.Last (Data.Tree.Number_Lists);
4834 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank) :=
4835 (Number => Rank, Next => No_Number_List);
4837 elsif Removed and Found then
4838 if Prev = Nil_String then
4839 Project.Source_Dirs :=
4840 Data.Tree.String_Elements.Table (List).Next;
4841 Project.Source_Dir_Ranks :=
4842 Data.Tree.Number_Lists.Table (Rank_List).Next;
4844 Data.Tree.String_Elements.Table (Prev).Next :=
4845 Data.Tree.String_Elements.Table (List).Next;
4846 Data.Tree.Number_Lists.Table (Prev_Rank).Next :=
4847 Data.Tree.Number_Lists.Table (Rank_List).Next;
4851 -- Now look for subdirectories. We do that even when this
4852 -- directory is already in the list, because some of its
4853 -- subdirectories may not be in the list yet.
4855 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4858 Read (Dir, Name, Last);
4861 if Name (1 .. Last) /= "."
4862 and then Name (1 .. Last) /= ".."
4864 -- Avoid . and .. directories
4866 if Current_Verbosity = High then
4867 Write_Str (" Checking ");
4868 Write_Line (Name (1 .. Last));
4872 Path_Name : constant String :=
4874 (Name => Name (1 .. Last),
4876 The_Path (The_Path'First .. The_Path_Last),
4877 Resolve_Links => Opt.Follow_Links_For_Dirs,
4878 Case_Sensitive => True);
4881 if Is_Directory (Path_Name) then
4883 -- We have found a new subdirectory, call self
4885 Name_Len := Path_Name'Length;
4886 Name_Buffer (1 .. Name_Len) := Path_Name;
4887 Recursive_Find_Dirs (Name_Find);
4896 when Directory_Error =>
4898 end Recursive_Find_Dirs;
4900 -- Start of processing for Find_Source_Dirs
4903 if Current_Verbosity = High and then not Removed then
4904 Write_Str ("Find_Source_Dirs (""");
4905 Write_Str (Directory);
4907 Write_Str (Rank'Img);
4911 -- First, check if we are looking for a directory tree, indicated
4912 -- by "/**" at the end.
4914 if Directory'Length >= 3
4915 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
4916 and then (Directory (Directory'Last - 2) = '/'
4918 Directory (Directory'Last - 2) = Directory_Separator)
4920 Name_Len := Directory'Length - 3;
4922 if Name_Len = 0 then
4924 -- Case of "/**": all directories in file system
4927 Name_Buffer (1) := Directory (Directory'First);
4930 Name_Buffer (1 .. Name_Len) :=
4931 Directory (Directory'First .. Directory'Last - 3);
4934 if Current_Verbosity = High then
4935 Write_Str ("Looking for all subdirectories of """);
4936 Write_Str (Name_Buffer (1 .. Name_Len));
4941 Base_Dir : constant File_Name_Type := Name_Find;
4942 Root_Dir : constant String :=
4944 (Name => Get_Name_String (Base_Dir),
4947 (Project.Directory.Display_Name),
4948 Resolve_Links => False,
4949 Case_Sensitive => True);
4952 if Root_Dir'Length = 0 then
4953 Err_Vars.Error_Msg_File_1 := Base_Dir;
4955 if Location = No_Location then
4958 "{ is not a valid directory.",
4959 Project.Location, Project);
4963 "{ is not a valid directory.",
4968 -- We have an existing directory, we register it and all of
4969 -- its subdirectories.
4971 if Current_Verbosity = High then
4972 Write_Line ("Looking for source directories:");
4975 Name_Len := Root_Dir'Length;
4976 Name_Buffer (1 .. Name_Len) := Root_Dir;
4977 Recursive_Find_Dirs (Name_Find);
4979 if Current_Verbosity = High then
4980 Write_Line ("End of looking for source directories.");
4985 -- We have a single directory
4989 Path_Name : Path_Information;
4990 List : String_List_Id;
4991 Prev : String_List_Id;
4992 Rank_List : Number_List_Index;
4993 Prev_Rank : Number_List_Index;
4994 Dir_Exists : Boolean;
4998 (Project => Project,
5001 Dir_Exists => Dir_Exists,
5003 Must_Exist => False);
5005 if not Dir_Exists then
5006 Err_Vars.Error_Msg_File_1 := From;
5008 if Location = No_Location then
5011 "{ is not a valid directory",
5012 Project.Location, Project);
5016 "{ is not a valid directory",
5022 Path : constant String :=
5023 Get_Name_String (Path_Name.Name);
5024 Last_Path : constant Natural :=
5025 Compute_Directory_Last (Path);
5027 Display_Path : constant String :=
5029 (Path_Name.Display_Name);
5030 Last_Display_Path : constant Natural :=
5031 Compute_Directory_Last
5033 Display_Path_Id : Name_Id;
5037 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5038 Path_Id := Name_Find;
5040 Add_Str_To_Name_Buffer
5042 (Display_Path'First .. Last_Display_Path));
5043 Display_Path_Id := Name_Find;
5045 -- Check if the directory is already in the list
5048 Prev_Rank := No_Number_List;
5050 -- Look for source dir in current list
5052 List := Project.Source_Dirs;
5053 Rank_List := Project.Source_Dir_Ranks;
5054 while List /= Nil_String loop
5055 Element := Data.Tree.String_Elements.Table (List);
5056 exit when Element.Value = Path_Id;
5058 List := Element.Next;
5059 Prev_Rank := Rank_List;
5061 Data.Tree.Number_Lists.Table (Prev_Rank).Next;
5064 -- The directory is in the list if List is not Nil_String
5068 -- As it is an existing directory, we add it to the
5069 -- list of directories, if not already in the list.
5071 if List = Nil_String then
5072 String_Element_Table.Increment_Last
5073 (Data.Tree.String_Elements);
5077 Display_Value => Display_Path_Id,
5078 Location => No_Location,
5080 Next => Nil_String);
5081 Number_List_Table.Increment_Last
5082 (Data.Tree.Number_Lists);
5084 if Last_Source_Dir = Nil_String then
5086 -- This is the first source directory
5088 Project.Source_Dirs :=
5089 String_Element_Table.Last
5090 (Data.Tree.String_Elements);
5091 Project.Source_Dir_Ranks :=
5092 Number_List_Table.Last
5093 (Data.Tree.Number_Lists);
5096 -- We already have source directories, link the
5097 -- previous last to the new one.
5099 Data.Tree.String_Elements.Table
5100 (Last_Source_Dir).Next :=
5101 String_Element_Table.Last
5102 (Data.Tree.String_Elements);
5103 Data.Tree.Number_Lists.Table
5104 (Last_Src_Dir_Rank).Next :=
5105 Number_List_Table.Last
5106 (Data.Tree.Number_Lists);
5110 -- And register this source directory as the new
5114 String_Element_Table.Last
5115 (Data.Tree.String_Elements);
5116 Data.Tree.String_Elements.Table
5117 (Last_Source_Dir) := Element;
5118 Last_Src_Dir_Rank :=
5119 Number_List_Table.Last
5120 (Data.Tree.Number_Lists);
5121 Data.Tree.Number_Lists.Table
5122 (Last_Src_Dir_Rank) :=
5123 (Number => Rank, Next => No_Number_List);
5127 -- Remove source dir, if present
5129 if List /= Nil_String then
5130 -- Source dir was found, remove it from the list
5132 if Prev = Nil_String then
5133 Project.Source_Dirs :=
5134 Data.Tree.String_Elements.Table (List).Next;
5135 Project.Source_Dir_Ranks :=
5136 Data.Tree.Number_Lists.Table (Rank_List).Next;
5139 Data.Tree.String_Elements.Table (Prev).Next :=
5140 Data.Tree.String_Elements.Table (List).Next;
5141 Data.Tree.Number_Lists.Table (Prev_Rank).Next :=
5142 Data.Tree.Number_Lists.Table (Rank_List).Next;
5151 Recursive_Dirs.Reset (Visited);
5152 end Find_Source_Dirs;
5154 -- Start of processing for Get_Directories
5156 Dir_Exists : Boolean;
5159 if Current_Verbosity = High then
5160 Write_Line ("Starting to look for directories");
5163 -- Set the object directory to its default which may be nil, if there
5164 -- is no sources in the project.
5166 if (((not Source_Files.Default)
5167 and then Source_Files.Values = Nil_String)
5169 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5171 ((not Languages.Default) and then Languages.Values = Nil_String))
5172 and then Project.Extends = No_Project
5174 Project.Object_Directory := No_Path_Information;
5176 Project.Object_Directory := Project.Directory;
5179 -- Check the object directory
5181 if Object_Dir.Value /= Empty_String then
5182 Get_Name_String (Object_Dir.Value);
5184 if Name_Len = 0 then
5187 "Object_Dir cannot be empty",
5188 Object_Dir.Location, Project);
5191 -- We check that the specified object directory does exist.
5192 -- However, even when it doesn't exist, we set it to a default
5193 -- value. This is for the benefit of tools that recover from
5194 -- errors; for example, these tools could create the non existent
5195 -- directory. We always return an absolute directory name though.
5199 File_Name_Type (Object_Dir.Value),
5200 Path => Project.Object_Directory,
5202 Dir_Exists => Dir_Exists,
5204 Location => Object_Dir.Location,
5205 Must_Exist => False,
5206 Externally_Built => Project.Externally_Built);
5209 and then not Project.Externally_Built
5211 -- The object directory does not exist, report an error if
5212 -- the project is not externally built.
5214 Err_Vars.Error_Msg_File_1 :=
5215 File_Name_Type (Object_Dir.Value);
5217 case Data.Flags.Require_Obj_Dirs is
5221 "object directory { not found",
5222 Project.Location, Project);
5226 "?object directory { not found",
5227 Project.Location, Project);
5234 elsif Project.Object_Directory /= No_Path_Information
5235 and then Subdirs /= null
5238 Name_Buffer (1) := '.';
5242 Path => Project.Object_Directory,
5244 Dir_Exists => Dir_Exists,
5246 Location => Object_Dir.Location,
5247 Externally_Built => Project.Externally_Built);
5250 if Current_Verbosity = High then
5251 if Project.Object_Directory = No_Path_Information then
5252 Write_Line ("No object directory");
5255 ("Object directory",
5256 Get_Name_String (Project.Object_Directory.Display_Name));
5260 -- Check the exec directory
5262 -- We set the object directory to its default
5264 Project.Exec_Directory := Project.Object_Directory;
5266 if Exec_Dir.Value /= Empty_String then
5267 Get_Name_String (Exec_Dir.Value);
5269 if Name_Len = 0 then
5272 "Exec_Dir cannot be empty",
5273 Exec_Dir.Location, Project);
5276 -- We check that the specified exec directory does exist
5280 File_Name_Type (Exec_Dir.Value),
5281 Path => Project.Exec_Directory,
5282 Dir_Exists => Dir_Exists,
5285 Location => Exec_Dir.Location,
5286 Externally_Built => Project.Externally_Built);
5288 if not Dir_Exists then
5289 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5292 "exec directory { not found",
5293 Project.Location, Project);
5298 if Current_Verbosity = High then
5299 if Project.Exec_Directory = No_Path_Information then
5300 Write_Line ("No exec directory");
5302 Write_Str ("Exec directory: """);
5303 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5308 -- Look for the source directories
5310 if Current_Verbosity = High then
5311 Write_Line ("Starting to look for source directories");
5314 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5316 if (not Source_Files.Default)
5317 and then Source_Files.Values = Nil_String
5319 Project.Source_Dirs := Nil_String;
5321 if Project.Qualifier = Standard then
5324 "a standard project cannot have no sources",
5325 Source_Files.Location, Project);
5328 elsif Source_Dirs.Default then
5330 -- No Source_Dirs specified: the single source directory is the one
5331 -- containing the project file.
5333 String_Element_Table.Append (Data.Tree.String_Elements,
5334 (Value => Name_Id (Project.Directory.Name),
5335 Display_Value => Name_Id (Project.Directory.Display_Name),
5336 Location => No_Location,
5341 Project.Source_Dirs :=
5342 String_Element_Table.Last (Data.Tree.String_Elements);
5344 Number_List_Table.Append
5345 (Data.Tree.Number_Lists,
5346 (Number => 1, Next => No_Number_List));
5348 Project.Source_Dir_Ranks :=
5349 Number_List_Table.Last (Data.Tree.Number_Lists);
5351 if Current_Verbosity = High then
5353 ("Default source directory",
5354 Get_Name_String (Project.Directory.Display_Name));
5357 elsif Source_Dirs.Values = Nil_String then
5358 if Project.Qualifier = Standard then
5361 "a standard project cannot have no source directories",
5362 Source_Dirs.Location, Project);
5365 Project.Source_Dirs := Nil_String;
5369 Source_Dir : String_List_Id;
5370 Element : String_Element;
5373 -- Process the source directories for each element of the list
5375 Source_Dir := Source_Dirs.Values;
5377 while Source_Dir /= Nil_String loop
5378 Element := Data.Tree.String_Elements.Table (Source_Dir);
5381 (File_Name_Type (Element.Value), Element.Location, Rank);
5382 Source_Dir := Element.Next;
5387 if not Excluded_Source_Dirs.Default
5388 and then Excluded_Source_Dirs.Values /= Nil_String
5391 Source_Dir : String_List_Id;
5392 Element : String_Element;
5395 -- Process the source directories for each element of the list
5397 Source_Dir := Excluded_Source_Dirs.Values;
5398 while Source_Dir /= Nil_String loop
5399 Element := Data.Tree.String_Elements.Table (Source_Dir);
5401 (File_Name_Type (Element.Value),
5405 Source_Dir := Element.Next;
5410 if Current_Verbosity = High then
5411 Write_Line ("Putting source directories in canonical cases");
5415 Current : String_List_Id := Project.Source_Dirs;
5416 Element : String_Element;
5419 while Current /= Nil_String loop
5420 Element := Data.Tree.String_Elements.Table (Current);
5421 if Element.Value /= No_Name then
5423 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5424 Data.Tree.String_Elements.Table (Current) := Element;
5427 Current := Element.Next;
5430 end Get_Directories;
5437 (Project : Project_Id;
5438 Data : in out Tree_Processing_Data)
5440 Mains : constant Variable_Value :=
5442 (Name_Main, Project.Decl.Attributes, Data.Tree);
5443 List : String_List_Id;
5444 Elem : String_Element;
5447 Project.Mains := Mains.Values;
5449 -- If no Mains were specified, and if we are an extending project,
5450 -- inherit the Mains from the project we are extending.
5452 if Mains.Default then
5453 if not Project.Library and then Project.Extends /= No_Project then
5454 Project.Mains := Project.Extends.Mains;
5457 -- In a library project file, Main cannot be specified
5459 elsif Project.Library then
5462 "a library project file cannot have Main specified",
5463 Mains.Location, Project);
5466 List := Mains.Values;
5467 while List /= Nil_String loop
5468 Elem := Data.Tree.String_Elements.Table (List);
5470 if Length_Of_Name (Elem.Value) = 0 then
5473 "?a main cannot have an empty name",
5474 Elem.Location, Project);
5483 ---------------------------
5484 -- Get_Sources_From_File --
5485 ---------------------------
5487 procedure Get_Sources_From_File
5489 Location : Source_Ptr;
5490 Project : in out Project_Processing_Data;
5491 Data : in out Tree_Processing_Data)
5493 File : Prj.Util.Text_File;
5494 Line : String (1 .. 250);
5496 Source_Name : File_Name_Type;
5497 Name_Loc : Name_Location;
5500 if Current_Verbosity = High then
5501 Write_Str ("Opening """);
5508 Prj.Util.Open (File, Path);
5510 if not Prj.Util.Is_Valid (File) then
5512 (Data.Flags, "file does not exist", Location, Project.Project);
5515 -- Read the lines one by one
5517 while not Prj.Util.End_Of_File (File) loop
5518 Prj.Util.Get_Line (File, Line, Last);
5520 -- A non empty, non comment line should contain a file name
5523 and then (Last = 1 or else Line (1 .. 2) /= "--")
5526 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5527 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5528 Source_Name := Name_Find;
5530 -- Check that there is no directory information
5532 for J in 1 .. Last loop
5533 if Line (J) = '/' or else Line (J) = Directory_Separator then
5534 Error_Msg_File_1 := Source_Name;
5537 "file name cannot include directory information ({)",
5538 Location, Project.Project);
5543 Name_Loc := Source_Names_Htable.Get
5544 (Project.Source_Names, Source_Name);
5546 if Name_Loc = No_Name_Location then
5548 (Name => Source_Name,
5549 Location => Location,
5550 Source => No_Source,
5554 Source_Names_Htable.Set
5555 (Project.Source_Names, Source_Name, Name_Loc);
5559 Prj.Util.Close (File);
5562 end Get_Sources_From_File;
5564 -----------------------
5565 -- Compute_Unit_Name --
5566 -----------------------
5568 procedure Compute_Unit_Name
5569 (File_Name : File_Name_Type;
5570 Naming : Lang_Naming_Data;
5571 Kind : out Source_Kind;
5573 Project : Project_Processing_Data;
5574 In_Tree : Project_Tree_Ref)
5576 Filename : constant String := Get_Name_String (File_Name);
5577 Last : Integer := Filename'Last;
5582 Unit_Except : Unit_Exception;
5583 Masked : Boolean := False;
5589 if Naming.Separate_Suffix = No_File
5590 or else Naming.Body_Suffix = No_File
5591 or else Naming.Spec_Suffix = No_File
5596 if Naming.Dot_Replacement = No_File then
5597 if Current_Verbosity = High then
5598 Write_Line (" No dot_replacement specified");
5604 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5605 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5606 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5608 -- Choose the longest suffix that matches. If there are several matches,
5609 -- give priority to specs, then bodies, then separates.
5611 if Naming.Separate_Suffix /= Naming.Body_Suffix
5612 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5614 Last := Filename'Last - Sep_Len;
5618 if Filename'Last - Body_Len <= Last
5619 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5621 Last := Natural'Min (Last, Filename'Last - Body_Len);
5625 if Filename'Last - Spec_Len <= Last
5626 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5628 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5632 if Last = Filename'Last then
5633 if Current_Verbosity = High then
5634 Write_Line (" no matching suffix");
5640 -- Check that the casing matches
5642 if File_Names_Case_Sensitive then
5643 case Naming.Casing is
5644 when All_Lower_Case =>
5645 for J in Filename'First .. Last loop
5646 if Is_Letter (Filename (J))
5647 and then not Is_Lower (Filename (J))
5649 if Current_Verbosity = High then
5650 Write_Line (" Invalid casing");
5657 when All_Upper_Case =>
5658 for J in Filename'First .. Last loop
5659 if Is_Letter (Filename (J))
5660 and then not Is_Upper (Filename (J))
5662 if Current_Verbosity = High then
5663 Write_Line (" Invalid casing");
5670 when Mixed_Case | Unknown =>
5675 -- If Dot_Replacement is not a single dot, then there should not
5676 -- be any dot in the name.
5679 Dot_Repl : constant String :=
5680 Get_Name_String (Naming.Dot_Replacement);
5683 if Dot_Repl /= "." then
5684 for Index in Filename'First .. Last loop
5685 if Filename (Index) = '.' then
5686 if Current_Verbosity = High then
5687 Write_Line (" Invalid name, contains dot");
5694 Replace_Into_Name_Buffer
5695 (Filename (Filename'First .. Last), Dot_Repl, '.');
5698 Name_Len := Last - Filename'First + 1;
5699 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5701 (Source => Name_Buffer (1 .. Name_Len),
5702 Mapping => Lower_Case_Map);
5706 -- In the standard GNAT naming scheme, check for special cases: children
5707 -- or separates of A, G, I or S, and run time sources.
5709 if Is_Standard_GNAT_Naming (Naming)
5710 and then Name_Len >= 3
5713 S1 : constant Character := Name_Buffer (1);
5714 S2 : constant Character := Name_Buffer (2);
5715 S3 : constant Character := Name_Buffer (3);
5723 -- Children or separates of packages A, G, I or S. These names
5724 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5725 -- versions (x__... and x~...) are allowed in all platforms,
5726 -- because it is not possible to know the platform before
5727 -- processing of the project files.
5729 if S2 = '_' and then S3 = '_' then
5730 Name_Buffer (2) := '.';
5731 Name_Buffer (3 .. Name_Len - 1) :=
5732 Name_Buffer (4 .. Name_Len);
5733 Name_Len := Name_Len - 1;
5736 Name_Buffer (2) := '.';
5740 -- If it is potentially a run time source
5748 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5749 -- that this is a valid unit name
5751 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5753 -- If there is a naming exception for the same unit, the file is not
5754 -- a source for the unit.
5756 if Unit /= No_Name then
5758 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5761 Masked := Unit_Except.Spec /= No_File
5763 Unit_Except.Spec /= File_Name;
5765 Masked := Unit_Except.Impl /= No_File
5767 Unit_Except.Impl /= File_Name;
5771 if Current_Verbosity = High then
5772 Write_Str (" """ & Filename & """ contains the ");
5775 Write_Str ("spec of a unit found in """);
5776 Write_Str (Get_Name_String (Unit_Except.Spec));
5778 Write_Str ("body of a unit found in """);
5779 Write_Str (Get_Name_String (Unit_Except.Impl));
5782 Write_Line (""" (ignored)");
5790 and then Current_Verbosity = High
5793 when Spec => Write_Str (" spec of ");
5794 when Impl => Write_Str (" body of ");
5795 when Sep => Write_Str (" sep of ");
5798 Write_Line (Get_Name_String (Unit));
5800 end Compute_Unit_Name;
5802 --------------------------
5803 -- Check_Illegal_Suffix --
5804 --------------------------
5806 procedure Check_Illegal_Suffix
5807 (Project : Project_Id;
5808 Suffix : File_Name_Type;
5809 Dot_Replacement : File_Name_Type;
5810 Attribute_Name : String;
5811 Location : Source_Ptr;
5812 Data : in out Tree_Processing_Data)
5814 Suffix_Str : constant String := Get_Name_String (Suffix);
5817 if Suffix_Str'Length = 0 then
5823 elsif Index (Suffix_Str, ".") = 0 then
5824 Err_Vars.Error_Msg_File_1 := Suffix;
5827 "{ is illegal for " & Attribute_Name & ": must have a dot",
5832 -- Case of dot replacement is a single dot, and first character of
5833 -- suffix is also a dot.
5835 if Dot_Replacement /= No_File
5836 and then Get_Name_String (Dot_Replacement) = "."
5837 and then Suffix_Str (Suffix_Str'First) = '.'
5839 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5841 -- If there are multiple dots in the name
5843 if Suffix_Str (Index) = '.' then
5845 -- It is illegal to have a letter following the initial dot
5847 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5848 Err_Vars.Error_Msg_File_1 := Suffix;
5851 "{ is illegal for " & Attribute_Name
5852 & ": ambiguous prefix when Dot_Replacement is a dot",
5859 end Check_Illegal_Suffix;
5861 ----------------------
5862 -- Locate_Directory --
5863 ----------------------
5865 procedure Locate_Directory
5866 (Project : Project_Id;
5867 Name : File_Name_Type;
5868 Path : out Path_Information;
5869 Dir_Exists : out Boolean;
5870 Data : in out Tree_Processing_Data;
5871 Create : String := "";
5872 Location : Source_Ptr := No_Location;
5873 Must_Exist : Boolean := True;
5874 Externally_Built : Boolean := False)
5876 Parent : constant Path_Name_Type :=
5877 Project.Directory.Display_Name;
5878 The_Parent : constant String :=
5879 Get_Name_String (Parent);
5880 The_Parent_Last : constant Natural :=
5881 Compute_Directory_Last (The_Parent);
5882 Full_Name : File_Name_Type;
5883 The_Name : File_Name_Type;
5886 Get_Name_String (Name);
5888 -- Add Subdirs.all if it is a directory that may be created and
5889 -- Subdirs is not null;
5891 if Create /= "" and then Subdirs /= null then
5892 if Name_Buffer (Name_Len) /= Directory_Separator then
5893 Add_Char_To_Name_Buffer (Directory_Separator);
5896 Add_Str_To_Name_Buffer (Subdirs.all);
5899 -- Convert '/' to directory separator (for Windows)
5901 for J in 1 .. Name_Len loop
5902 if Name_Buffer (J) = '/' then
5903 Name_Buffer (J) := Directory_Separator;
5907 The_Name := Name_Find;
5909 if Current_Verbosity = High then
5910 Write_Str ("Locate_Directory (""");
5911 Write_Str (Get_Name_String (The_Name));
5912 Write_Str (""", """);
5913 Write_Str (The_Parent);
5917 Path := No_Path_Information;
5918 Dir_Exists := False;
5920 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5921 Full_Name := The_Name;
5925 Add_Str_To_Name_Buffer
5926 (The_Parent (The_Parent'First .. The_Parent_Last));
5927 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5928 Full_Name := Name_Find;
5932 Full_Path_Name : String_Access :=
5933 new String'(Get_Name_String (Full_Name));
5936 if (Setup_Projects or else Subdirs /= null)
5937 and then Create'Length > 0
5939 if not Is_Directory (Full_Path_Name.all) then
5941 -- If project is externally built, do not create a subdir,
5942 -- use the specified directory, without the subdir.
5944 if Externally_Built then
5945 if Is_Absolute_Path (Get_Name_String (Name)) then
5946 Get_Name_String (Name);
5950 Add_Str_To_Name_Buffer
5951 (The_Parent (The_Parent'First .. The_Parent_Last));
5952 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5955 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5959 Create_Path (Full_Path_Name.all);
5961 if not Quiet_Output then
5963 Write_Str (" directory """);
5964 Write_Str (Full_Path_Name.all);
5965 Write_Str (""" created for project ");
5966 Write_Line (Get_Name_String (Project.Name));
5973 "could not create " & Create &
5974 " directory " & Full_Path_Name.all,
5981 Dir_Exists := Is_Directory (Full_Path_Name.all);
5983 if not Must_Exist or else Dir_Exists then
5985 Normed : constant String :=
5987 (Full_Path_Name.all,
5989 The_Parent (The_Parent'First .. The_Parent_Last),
5990 Resolve_Links => False,
5991 Case_Sensitive => True);
5993 Canonical_Path : constant String :=
5998 (The_Parent'First .. The_Parent_Last),
6000 Opt.Follow_Links_For_Dirs,
6001 Case_Sensitive => False);
6004 Name_Len := Normed'Length;
6005 Name_Buffer (1 .. Name_Len) := Normed;
6007 -- Directories should always end with a directory separator
6009 if Name_Buffer (Name_Len) /= Directory_Separator then
6010 Add_Char_To_Name_Buffer (Directory_Separator);
6013 Path.Display_Name := Name_Find;
6015 Name_Len := Canonical_Path'Length;
6016 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6018 if Name_Buffer (Name_Len) /= Directory_Separator then
6019 Add_Char_To_Name_Buffer (Directory_Separator);
6022 Path.Name := Name_Find;
6026 Free (Full_Path_Name);
6028 end Locate_Directory;
6030 ---------------------------
6031 -- Find_Excluded_Sources --
6032 ---------------------------
6034 procedure Find_Excluded_Sources
6035 (Project : in out Project_Processing_Data;
6036 Data : in out Tree_Processing_Data)
6038 Excluded_Source_List_File : constant Variable_Value :=
6040 (Name_Excluded_Source_List_File,
6041 Project.Project.Decl.Attributes,
6043 Excluded_Sources : Variable_Value := Util.Value_Of
6044 (Name_Excluded_Source_Files,
6045 Project.Project.Decl.Attributes,
6048 Current : String_List_Id;
6049 Element : String_Element;
6050 Location : Source_Ptr;
6051 Name : File_Name_Type;
6052 File : Prj.Util.Text_File;
6053 Line : String (1 .. 300);
6055 Locally_Removed : Boolean := False;
6058 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6060 if Excluded_Sources.Default then
6061 Locally_Removed := True;
6064 (Name_Locally_Removed_Files,
6065 Project.Project.Decl.Attributes, Data.Tree);
6068 -- If there are excluded sources, put them in the table
6070 if not Excluded_Sources.Default then
6071 if not Excluded_Source_List_File.Default then
6072 if Locally_Removed then
6075 "?both attributes Locally_Removed_Files and " &
6076 "Excluded_Source_List_File are present",
6077 Excluded_Source_List_File.Location, Project.Project);
6081 "?both attributes Excluded_Source_Files and " &
6082 "Excluded_Source_List_File are present",
6083 Excluded_Source_List_File.Location, Project.Project);
6087 Current := Excluded_Sources.Values;
6088 while Current /= Nil_String loop
6089 Element := Data.Tree.String_Elements.Table (Current);
6090 Name := Canonical_Case_File_Name (Element.Value);
6092 -- If the element has no location, then use the location of
6093 -- Excluded_Sources to report possible errors.
6095 if Element.Location = No_Location then
6096 Location := Excluded_Sources.Location;
6098 Location := Element.Location;
6101 Excluded_Sources_Htable.Set
6102 (Project.Excluded, Name, (Name, False, Location));
6103 Current := Element.Next;
6106 elsif not Excluded_Source_List_File.Default then
6107 Location := Excluded_Source_List_File.Location;
6110 Source_File_Path_Name : constant String :=
6113 (Excluded_Source_List_File.Value),
6114 Project.Project.Directory.Name);
6117 if Source_File_Path_Name'Length = 0 then
6118 Err_Vars.Error_Msg_File_1 :=
6119 File_Name_Type (Excluded_Source_List_File.Value);
6122 "file with excluded sources { does not exist",
6123 Excluded_Source_List_File.Location, Project.Project);
6128 Prj.Util.Open (File, Source_File_Path_Name);
6130 if not Prj.Util.Is_Valid (File) then
6132 (Data.Flags, "file does not exist",
6133 Location, Project.Project);
6135 -- Read the lines one by one
6137 while not Prj.Util.End_Of_File (File) loop
6138 Prj.Util.Get_Line (File, Line, Last);
6140 -- Non empty, non comment line should contain a file name
6143 and then (Last = 1 or else Line (1 .. 2) /= "--")
6146 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6147 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6150 -- Check that there is no directory information
6152 for J in 1 .. Last loop
6154 or else Line (J) = Directory_Separator
6156 Error_Msg_File_1 := Name;
6159 "file name cannot include " &
6160 "directory information ({)",
6161 Location, Project.Project);
6166 Excluded_Sources_Htable.Set
6167 (Project.Excluded, Name, (Name, False, Location));
6171 Prj.Util.Close (File);
6176 end Find_Excluded_Sources;
6182 procedure Find_Sources
6183 (Project : in out Project_Processing_Data;
6184 Data : in out Tree_Processing_Data)
6186 Sources : constant Variable_Value :=
6189 Project.Project.Decl.Attributes,
6192 Source_List_File : constant Variable_Value :=
6194 (Name_Source_List_File,
6195 Project.Project.Decl.Attributes,
6198 Name_Loc : Name_Location;
6199 Has_Explicit_Sources : Boolean;
6202 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6204 (Source_List_File.Kind = Single,
6205 "Source_List_File is not a single string");
6207 Project.Source_List_File_Location := Source_List_File.Location;
6209 -- If the user has specified a Source_Files attribute
6211 if not Sources.Default then
6212 if not Source_List_File.Default then
6215 "?both attributes source_files and " &
6216 "source_list_file are present",
6217 Source_List_File.Location, Project.Project);
6220 -- Sources is a list of file names
6223 Current : String_List_Id := Sources.Values;
6224 Element : String_Element;
6225 Location : Source_Ptr;
6226 Name : File_Name_Type;
6229 if Current = Nil_String then
6230 Project.Project.Languages := No_Language_Index;
6232 -- This project contains no source. For projects that don't
6233 -- extend other projects, this also means that there is no
6234 -- need for an object directory, if not specified.
6236 if Project.Project.Extends = No_Project
6237 and then Project.Project.Object_Directory =
6238 Project.Project.Directory
6240 Project.Project.Object_Directory := No_Path_Information;
6244 while Current /= Nil_String loop
6245 Element := Data.Tree.String_Elements.Table (Current);
6246 Name := Canonical_Case_File_Name (Element.Value);
6247 Get_Name_String (Element.Value);
6249 -- If the element has no location, then use the location of
6250 -- Sources to report possible errors.
6252 if Element.Location = No_Location then
6253 Location := Sources.Location;
6255 Location := Element.Location;
6258 -- Check that there is no directory information
6260 for J in 1 .. Name_Len loop
6261 if Name_Buffer (J) = '/'
6262 or else Name_Buffer (J) = Directory_Separator
6264 Error_Msg_File_1 := Name;
6267 "file name cannot include directory " &
6269 Location, Project.Project);
6274 -- Check whether the file is already there: the same file name
6275 -- may be in the list. If the source is missing, the error will
6276 -- be on the first mention of the source file name.
6278 Name_Loc := Source_Names_Htable.Get
6279 (Project.Source_Names, Name);
6281 if Name_Loc = No_Name_Location then
6284 Location => Location,
6285 Source => No_Source,
6287 Source_Names_Htable.Set
6288 (Project.Source_Names, Name, Name_Loc);
6291 Current := Element.Next;
6294 Has_Explicit_Sources := True;
6297 -- If we have no Source_Files attribute, check the Source_List_File
6300 elsif not Source_List_File.Default then
6302 -- Source_List_File is the name of the file that contains the source
6306 Source_File_Path_Name : constant String :=
6308 (File_Name_Type (Source_List_File.Value),
6309 Project.Project.Directory.Name);
6312 Has_Explicit_Sources := True;
6314 if Source_File_Path_Name'Length = 0 then
6315 Err_Vars.Error_Msg_File_1 :=
6316 File_Name_Type (Source_List_File.Value);
6319 "file with sources { does not exist",
6320 Source_List_File.Location, Project.Project);
6323 Get_Sources_From_File
6324 (Source_File_Path_Name, Source_List_File.Location,
6330 -- Neither Source_Files nor Source_List_File has been specified. Find
6331 -- all the files that satisfy the naming scheme in all the source
6334 Has_Explicit_Sources := False;
6340 For_All_Sources => Sources.Default and then Source_List_File.Default);
6342 -- Check if all exceptions have been found
6346 Iter : Source_Iterator;
6349 Iter := For_Each_Source (Data.Tree, Project.Project);
6351 Source := Prj.Element (Iter);
6352 exit when Source = No_Source;
6354 if Source.Naming_Exception
6355 and then Source.Path = No_Path_Information
6357 if Source.Unit /= No_Unit_Index then
6359 -- For multi-unit source files, source_id gets duplicated
6360 -- once for every unit. Only the first source_id got its
6361 -- full path set. So if it isn't set for that first one,
6362 -- the file wasn't found. Otherwise we need to update for
6363 -- units after the first one.
6366 or else Source.Index = 1
6368 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6369 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6372 "source file %% for unit %% not found",
6373 No_Location, Project.Project);
6376 Source.Path := Files_Htable.Get
6377 (Data.File_To_Source, Source.File).Path;
6379 if Current_Verbosity = High then
6380 if Source.Path /= No_Path_Information then
6381 Write_Line ("Setting full path for "
6382 & Get_Name_String (Source.File)
6383 & " at" & Source.Index'Img
6385 & Get_Name_String (Source.Path.Name));
6391 if Source.Path = No_Path_Information then
6392 Remove_Source (Source, No_Source);
6400 -- It is an error if a source file name in a source list or in a source
6401 -- list file is not found.
6403 if Has_Explicit_Sources then
6406 First_Error : Boolean;
6409 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6410 First_Error := True;
6411 while NL /= No_Name_Location loop
6412 if not NL.Found then
6413 Err_Vars.Error_Msg_File_1 := NL.Name;
6418 "source file { not found",
6419 NL.Location, Project.Project);
6420 First_Error := False;
6425 "\source file { not found",
6426 NL.Location, Project.Project);
6430 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6440 procedure Initialize
6441 (Data : out Tree_Processing_Data;
6442 Tree : Project_Tree_Ref;
6443 Flags : Prj.Processing_Flags)
6446 Files_Htable.Reset (Data.File_To_Source);
6448 Data.Flags := Flags;
6455 procedure Free (Data : in out Tree_Processing_Data) is
6457 Files_Htable.Reset (Data.File_To_Source);
6464 procedure Initialize
6465 (Data : in out Project_Processing_Data;
6466 Project : Project_Id)
6469 Data.Project := Project;
6476 procedure Free (Data : in out Project_Processing_Data) is
6478 Source_Names_Htable.Reset (Data.Source_Names);
6479 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6480 Excluded_Sources_Htable.Reset (Data.Excluded);
6483 -------------------------------
6484 -- Check_File_Naming_Schemes --
6485 -------------------------------
6487 procedure Check_File_Naming_Schemes
6488 (In_Tree : Project_Tree_Ref;
6489 Project : Project_Processing_Data;
6490 File_Name : File_Name_Type;
6491 Alternate_Languages : out Language_List;
6492 Language : out Language_Ptr;
6493 Display_Language_Name : out Name_Id;
6495 Lang_Kind : out Language_Kind;
6496 Kind : out Source_Kind)
6498 Filename : constant String := Get_Name_String (File_Name);
6499 Config : Language_Config;
6500 Tmp_Lang : Language_Ptr;
6502 Header_File : Boolean := False;
6503 -- True if we found at least one language for which the file is a header
6504 -- In such a case, we search for all possible languages where this is
6505 -- also a header (C and C++ for instance), since the file might be used
6506 -- for several such languages.
6508 procedure Check_File_Based_Lang;
6509 -- Does the naming scheme test for file-based languages. For those,
6510 -- there is no Unit. Just check if the file name has the implementation
6511 -- or, if it is specified, the template suffix of the language.
6513 -- Returns True if the file belongs to the current language and we
6514 -- should stop searching for matching languages. Not that a given header
6515 -- file could belong to several languages (C and C++ for instance). Thus
6516 -- if we found a header we'll check whether it matches other languages.
6518 ---------------------------
6519 -- Check_File_Based_Lang --
6520 ---------------------------
6522 procedure Check_File_Based_Lang is
6525 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6529 Language := Tmp_Lang;
6531 if Current_Verbosity = High then
6532 Write_Str (" implementation of language ");
6533 Write_Line (Get_Name_String (Display_Language_Name));
6536 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6537 if Current_Verbosity = High then
6538 Write_Str (" header of language ");
6539 Write_Line (Get_Name_String (Display_Language_Name));
6543 Alternate_Languages := new Language_List_Element'
6544 (Language => Language,
6545 Next => Alternate_Languages);
6548 Header_File := True;
6551 Language := Tmp_Lang;
6554 end Check_File_Based_Lang;
6556 -- Start of processing for Check_File_Naming_Schemes
6559 Language := No_Language_Index;
6560 Alternate_Languages := null;
6561 Display_Language_Name := No_Name;
6563 Lang_Kind := File_Based;
6566 Tmp_Lang := Project.Project.Languages;
6567 while Tmp_Lang /= No_Language_Index loop
6568 if Current_Verbosity = High then
6570 (" Testing language "
6571 & Get_Name_String (Tmp_Lang.Name)
6572 & " Header_File=" & Header_File'Img);
6575 Display_Language_Name := Tmp_Lang.Display_Name;
6576 Config := Tmp_Lang.Config;
6577 Lang_Kind := Config.Kind;
6581 Check_File_Based_Lang;
6582 exit when Kind = Impl;
6586 -- We know it belongs to a least a file_based language, no
6587 -- need to check unit-based ones.
6589 if not Header_File then
6591 (File_Name => File_Name,
6592 Naming => Config.Naming_Data,
6596 In_Tree => In_Tree);
6598 if Unit /= No_Name then
6599 Language := Tmp_Lang;
6605 Tmp_Lang := Tmp_Lang.Next;
6608 if Language = No_Language_Index
6609 and then Current_Verbosity = High
6611 Write_Line (" not a source of any language");
6613 end Check_File_Naming_Schemes;
6619 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6621 -- If the file was previously already associated with a unit, change it
6623 if Source.Unit /= null
6624 and then Source.Kind in Spec_Or_Body
6625 and then Source.Unit.File_Names (Source.Kind) /= null
6627 -- If we had another file referencing the same unit (for instance it
6628 -- was in an extended project), that source file is in fact invisible
6629 -- from now on, and in particular doesn't belong to the same unit.
6631 if Source.Unit.File_Names (Source.Kind) /= Source then
6632 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6635 Source.Unit.File_Names (Source.Kind) := null;
6638 Source.Kind := Kind;
6640 if Current_Verbosity = High
6641 and then Source.File /= No_File
6643 Write_Line ("Override kind for "
6644 & Get_Name_String (Source.File)
6645 & " kind=" & Source.Kind'Img);
6648 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6649 Source.Unit.File_Names (Source.Kind) := Source;
6657 procedure Check_File
6658 (Project : in out Project_Processing_Data;
6659 Data : in out Tree_Processing_Data;
6660 Source_Dir_Rank : Natural;
6661 Path : Path_Name_Type;
6662 File_Name : File_Name_Type;
6663 Display_File_Name : File_Name_Type;
6664 Locally_Removed : Boolean;
6665 For_All_Sources : Boolean)
6667 Canonical_Path : constant Path_Name_Type :=
6669 (Canonical_Case_File_Name (Name_Id (Path)));
6671 Name_Loc : Name_Location :=
6672 Source_Names_Htable.Get
6673 (Project.Source_Names, File_Name);
6674 Check_Name : Boolean := False;
6675 Alternate_Languages : Language_List;
6676 Language : Language_Ptr;
6678 Src_Ind : Source_File_Index;
6680 Display_Language_Name : Name_Id;
6681 Lang_Kind : Language_Kind;
6682 Kind : Source_Kind := Spec;
6685 if Current_Verbosity = High then
6686 Write_Line ("Checking file:");
6687 Write_Str (" Path = ");
6688 Write_Line (Get_Name_String (Path));
6689 Write_Str (" Rank =");
6690 Write_Line (Source_Dir_Rank'Img);
6693 if Name_Loc = No_Name_Location then
6694 Check_Name := For_All_Sources;
6697 if Name_Loc.Found then
6699 -- Check if it is OK to have the same file name in several
6700 -- source directories.
6702 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6703 Error_Msg_File_1 := File_Name;
6706 "{ is found in several source directories",
6707 Name_Loc.Location, Project.Project);
6711 Name_Loc.Found := True;
6713 Source_Names_Htable.Set
6714 (Project.Source_Names, File_Name, Name_Loc);
6716 if Name_Loc.Source = No_Source then
6720 Name_Loc.Source.Path := (Canonical_Path, Path);
6722 Source_Paths_Htable.Set
6723 (Data.Tree.Source_Paths_HT,
6727 -- Check if this is a subunit
6729 if Name_Loc.Source.Unit /= No_Unit_Index
6730 and then Name_Loc.Source.Kind = Impl
6732 Src_Ind := Sinput.P.Load_Project_File
6733 (Get_Name_String (Canonical_Path));
6735 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6736 Override_Kind (Name_Loc.Source, Sep);
6741 (Data.File_To_Source, File_Name, Name_Loc.Source);
6747 Check_File_Naming_Schemes
6748 (In_Tree => Data.Tree,
6750 File_Name => File_Name,
6751 Alternate_Languages => Alternate_Languages,
6752 Language => Language,
6753 Display_Language_Name => Display_Language_Name,
6755 Lang_Kind => Lang_Kind,
6758 if Language = No_Language_Index then
6760 -- A file name in a list must be a source of a language
6762 if Data.Flags.Error_On_Unknown_Language
6763 and then Name_Loc.Found
6765 Error_Msg_File_1 := File_Name;
6768 "language unknown for {",
6769 Name_Loc.Location, Project.Project);
6775 Project => Project.Project,
6776 Source_Dir_Rank => Source_Dir_Rank,
6777 Lang_Id => Language,
6780 Alternate_Languages => Alternate_Languages,
6781 File_Name => File_Name,
6782 Display_File => Display_File_Name,
6784 Locally_Removed => Locally_Removed,
6785 Path => (Canonical_Path, Path));
6787 -- If it is a source specified in a list, update the entry in
6788 -- the Source_Names table.
6790 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6791 Name_Loc.Source := Source;
6792 Source_Names_Htable.Set
6793 (Project.Source_Names, File_Name, Name_Loc);
6799 ------------------------
6800 -- Search_Directories --
6801 ------------------------
6803 procedure Search_Directories
6804 (Project : in out Project_Processing_Data;
6805 Data : in out Tree_Processing_Data;
6806 For_All_Sources : Boolean)
6808 Source_Dir : String_List_Id;
6809 Element : String_Element;
6810 Src_Dir_Rank : Number_List_Index;
6811 Num_Nod : Number_Node;
6813 Name : String (1 .. 1_000);
6815 File_Name : File_Name_Type;
6816 Display_File_Name : File_Name_Type;
6819 if Current_Verbosity = High then
6820 Write_Line ("Looking for sources:");
6823 -- Loop through subdirectories
6825 Source_Dir := Project.Project.Source_Dirs;
6826 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
6827 while Source_Dir /= Nil_String loop
6829 Num_Nod := Data.Tree.Number_Lists.Table (Src_Dir_Rank);
6830 Element := Data.Tree.String_Elements.Table (Source_Dir);
6832 if Element.Value /= No_Name then
6833 Get_Name_String (Element.Display_Value);
6835 if Current_Verbosity = High then
6836 Write_Str ("Directory: ");
6837 Write_Str (Name_Buffer (1 .. Name_Len));
6838 Write_Line (Num_Nod.Number'Img);
6842 Source_Directory : constant String :=
6843 Name_Buffer (1 .. Name_Len) &
6844 Directory_Separator;
6846 Dir_Last : constant Natural :=
6847 Compute_Directory_Last
6851 if Current_Verbosity = High then
6852 Write_Attr ("Source_Dir", Source_Directory);
6855 -- We look to every entry in the source directory
6857 Open (Dir, Source_Directory);
6860 Read (Dir, Name, Last);
6864 -- ??? Duplicate system call here, we just did a a
6865 -- similar one. Maybe Ada.Directories would be more
6866 -- appropriate here.
6869 (Source_Directory & Name (1 .. Last))
6871 if Current_Verbosity = High then
6872 Write_Str (" Checking ");
6873 Write_Line (Name (1 .. Last));
6877 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6878 Display_File_Name := Name_Find;
6880 if Osint.File_Names_Case_Sensitive then
6881 File_Name := Display_File_Name;
6883 Canonical_Case_File_Name
6884 (Name_Buffer (1 .. Name_Len));
6885 File_Name := Name_Find;
6889 Path_Name : constant String :=
6894 (Source_Directory'First ..
6897 Opt.Follow_Links_For_Files,
6898 Case_Sensitive => True);
6899 -- Case_Sensitive set True (no folding)
6901 Path : Path_Name_Type;
6902 FF : File_Found := Excluded_Sources_Htable.Get
6903 (Project.Excluded, File_Name);
6904 To_Remove : Boolean := False;
6907 Name_Len := Path_Name'Length;
6908 Name_Buffer (1 .. Name_Len) := Path_Name;
6911 if FF /= No_File_Found then
6912 if not FF.Found then
6914 Excluded_Sources_Htable.Set
6915 (Project.Excluded, File_Name, FF);
6917 if Current_Verbosity = High then
6918 Write_Str (" excluded source """);
6919 Write_Str (Get_Name_String (File_Name));
6923 -- Will mark the file as removed, but we
6924 -- still need to add it to the list: if we
6925 -- don't, the file will not appear in the
6926 -- mapping file and will cause the compiler
6934 (Project => Project,
6935 Source_Dir_Rank => Num_Nod.Number,
6938 File_Name => File_Name,
6939 Locally_Removed => To_Remove,
6940 Display_File_Name => Display_File_Name,
6941 For_All_Sources => For_All_Sources);
6951 when Directory_Error =>
6955 Source_Dir := Element.Next;
6956 Src_Dir_Rank := Num_Nod.Next;
6959 if Current_Verbosity = High then
6960 Write_Line ("end Looking for sources.");
6962 end Search_Directories;
6964 ----------------------------
6965 -- Load_Naming_Exceptions --
6966 ----------------------------
6968 procedure Load_Naming_Exceptions
6969 (Project : in out Project_Processing_Data;
6970 Data : in out Tree_Processing_Data)
6973 Iter : Source_Iterator;
6976 Iter := For_Each_Source (Data.Tree, Project.Project);
6978 Source := Prj.Element (Iter);
6979 exit when Source = No_Source;
6981 -- An excluded file cannot also be an exception file name
6983 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
6986 Error_Msg_File_1 := Source.File;
6989 "{ cannot be both excluded and an exception file name",
6990 No_Location, Project.Project);
6993 if Current_Verbosity = High then
6994 Write_Str ("Naming exception: Putting source file ");
6995 Write_Str (Get_Name_String (Source.File));
6996 Write_Line (" in Source_Names");
6999 Source_Names_Htable.Set
7000 (Project.Source_Names,
7003 (Name => Source.File,
7004 Location => No_Location,
7008 -- If this is an Ada exception, record in table Unit_Exceptions
7010 if Source.Unit /= No_Unit_Index then
7012 Unit_Except : Unit_Exception :=
7013 Unit_Exceptions_Htable.Get
7014 (Project.Unit_Exceptions, Source.Unit.Name);
7017 Unit_Except.Name := Source.Unit.Name;
7019 if Source.Kind = Spec then
7020 Unit_Except.Spec := Source.File;
7022 Unit_Except.Impl := Source.File;
7025 Unit_Exceptions_Htable.Set
7026 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7032 end Load_Naming_Exceptions;
7034 ----------------------
7035 -- Look_For_Sources --
7036 ----------------------
7038 procedure Look_For_Sources
7039 (Project : in out Project_Processing_Data;
7040 Data : in out Tree_Processing_Data)
7042 Object_Files : Object_File_Names_Htable.Instance;
7043 Iter : Source_Iterator;
7046 procedure Check_Object (Src : Source_Id);
7047 -- Check if object file name of Src is already used in the project tree,
7048 -- and report an error if so.
7050 procedure Check_Object_Files;
7051 -- Check that no two sources of this project have the same object file
7053 procedure Mark_Excluded_Sources;
7054 -- Mark as such the sources that are declared as excluded
7060 procedure Check_Object (Src : Source_Id) is
7064 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7066 -- We cannot just check on "Source /= Src", since we might have
7067 -- two different entries for the same file (and since that's
7068 -- the same file it is expected that it has the same object)
7070 if Source /= No_Source
7071 and then Source.Path /= Src.Path
7073 Error_Msg_File_1 := Src.File;
7074 Error_Msg_File_2 := Source.File;
7077 "{ and { have the same object file name",
7078 No_Location, Project.Project);
7081 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7085 ---------------------------
7086 -- Mark_Excluded_Sources --
7087 ---------------------------
7089 procedure Mark_Excluded_Sources is
7090 Source : Source_Id := No_Source;
7091 Excluded : File_Found;
7095 -- Minor optimization: if there are no excluded files, no need to
7096 -- traverse the list of sources. We cannot however also check whether
7097 -- the existing exceptions have ".Found" set to True (indicating we
7098 -- found them before) because we need to do some final processing on
7099 -- them in any case.
7101 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7104 Proj := Project.Project;
7105 while Proj /= No_Project loop
7106 Iter := For_Each_Source (Data.Tree, Proj);
7107 while Prj.Element (Iter) /= No_Source loop
7108 Source := Prj.Element (Iter);
7109 Excluded := Excluded_Sources_Htable.Get
7110 (Project.Excluded, Source.File);
7112 if Excluded /= No_File_Found then
7113 Source.Locally_Removed := True;
7114 Source.In_Interfaces := False;
7116 if Current_Verbosity = High then
7117 Write_Str ("Removing file ");
7119 (Get_Name_String (Excluded.File)
7120 & " " & Get_Name_String (Source.Project.Name));
7123 Excluded_Sources_Htable.Remove
7124 (Project.Excluded, Source.File);
7130 Proj := Proj.Extends;
7134 -- If we have any excluded element left, that means we did not find
7137 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7138 while Excluded /= No_File_Found loop
7139 if not Excluded.Found then
7141 -- Check if the file belongs to another imported project to
7142 -- provide a better error message.
7145 (In_Tree => Data.Tree,
7146 Project => Project.Project,
7147 In_Imported_Only => True,
7148 Base_Name => Excluded.File);
7150 Err_Vars.Error_Msg_File_1 := Excluded.File;
7152 if Src = No_Source then
7155 "unknown file {", Excluded.Location, Project.Project);
7159 "cannot remove a source from an imported project: {",
7160 Excluded.Location, Project.Project);
7164 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7166 end Mark_Excluded_Sources;
7168 ------------------------
7169 -- Check_Object_Files --
7170 ------------------------
7172 procedure Check_Object_Files is
7173 Iter : Source_Iterator;
7175 Src_Ind : Source_File_Index;
7178 Iter := For_Each_Source (Data.Tree);
7180 Src_Id := Prj.Element (Iter);
7181 exit when Src_Id = No_Source;
7183 if Is_Compilable (Src_Id)
7184 and then Src_Id.Language.Config.Object_Generated
7185 and then Is_Extending (Project.Project, Src_Id.Project)
7187 if Src_Id.Unit = No_Unit_Index then
7188 if Src_Id.Kind = Impl then
7189 Check_Object (Src_Id);
7195 if Other_Part (Src_Id) = No_Source then
7196 Check_Object (Src_Id);
7203 if Other_Part (Src_Id) /= No_Source then
7204 Check_Object (Src_Id);
7207 -- Check if it is a subunit
7210 Sinput.P.Load_Project_File
7211 (Get_Name_String (Src_Id.Path.Name));
7213 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7214 Override_Kind (Src_Id, Sep);
7216 Check_Object (Src_Id);
7225 end Check_Object_Files;
7227 -- Start of processing for Look_For_Sources
7230 Find_Excluded_Sources (Project, Data);
7232 if Project.Project.Languages /= No_Language_Index then
7233 Load_Naming_Exceptions (Project, Data);
7234 Find_Sources (Project, Data);
7235 Mark_Excluded_Sources;
7239 Object_File_Names_Htable.Reset (Object_Files);
7240 end Look_For_Sources;
7246 function Path_Name_Of
7247 (File_Name : File_Name_Type;
7248 Directory : Path_Name_Type) return String
7250 Result : String_Access;
7251 The_Directory : constant String := Get_Name_String (Directory);
7254 Get_Name_String (File_Name);
7257 (File_Name => Name_Buffer (1 .. Name_Len),
7258 Path => The_Directory);
7260 if Result = null then
7264 R : String := Result.all;
7267 Canonical_Case_File_Name (R);
7277 procedure Remove_Source
7279 Replaced_By : Source_Id)
7284 if Current_Verbosity = High then
7285 Write_Str ("Removing source ");
7286 Write_Str (Get_Name_String (Id.File));
7288 if Id.Index /= 0 then
7289 Write_Str (" at" & Id.Index'Img);
7295 if Replaced_By /= No_Source then
7296 Id.Replaced_By := Replaced_By;
7297 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7300 Id.In_Interfaces := False;
7301 Id.Locally_Removed := True;
7303 -- ??? Should we remove the source from the unit ? The file is not used,
7304 -- so probably should not be referenced from the unit. On the other hand
7305 -- it might give useful additional info
7306 -- if Id.Unit /= null then
7307 -- Id.Unit.File_Names (Id.Kind) := null;
7310 Source := Id.Language.First_Source;
7313 Id.Language.First_Source := Id.Next_In_Lang;
7316 while Source.Next_In_Lang /= Id loop
7317 Source := Source.Next_In_Lang;
7320 Source.Next_In_Lang := Id.Next_In_Lang;
7324 -----------------------
7325 -- Report_No_Sources --
7326 -----------------------
7328 procedure Report_No_Sources
7329 (Project : Project_Id;
7331 Data : Tree_Processing_Data;
7332 Location : Source_Ptr;
7333 Continuation : Boolean := False)
7336 case Data.Flags.When_No_Sources is
7340 when Warning | Error =>
7342 Msg : constant String :=
7345 " sources in this project";
7348 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7350 if Continuation then
7351 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7353 Error_Msg (Data.Flags, Msg, Location, Project);
7357 end Report_No_Sources;
7359 ----------------------
7360 -- Show_Source_Dirs --
7361 ----------------------
7363 procedure Show_Source_Dirs
7364 (Project : Project_Id;
7365 In_Tree : Project_Tree_Ref)
7367 Current : String_List_Id;
7368 Element : String_Element;
7371 Write_Line ("Source_Dirs:");
7373 Current := Project.Source_Dirs;
7374 while Current /= Nil_String loop
7375 Element := In_Tree.String_Elements.Table (Current);
7377 Write_Line (Get_Name_String (Element.Value));
7378 Current := Element.Next;
7381 Write_Line ("end Source_Dirs.");
7382 end Show_Source_Dirs;
7384 ---------------------------
7385 -- Process_Naming_Scheme --
7386 ---------------------------
7388 procedure Process_Naming_Scheme
7389 (Tree : Project_Tree_Ref;
7390 Root_Project : Project_Id;
7391 Flags : Processing_Flags)
7393 procedure Recursive_Check
7394 (Project : Project_Id;
7395 Data : in out Tree_Processing_Data);
7396 -- Check_Naming_Scheme for the project
7398 ---------------------
7399 -- Recursive_Check --
7400 ---------------------
7402 procedure Recursive_Check
7403 (Project : Project_Id;
7404 Data : in out Tree_Processing_Data)
7407 if Verbose_Mode then
7408 Write_Str ("Processing_Naming_Scheme for project """);
7409 Write_Str (Get_Name_String (Project.Name));
7413 Prj.Nmsc.Check (Project, Data);
7414 end Recursive_Check;
7416 procedure Check_All_Projects is new
7417 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7419 Data : Tree_Processing_Data;
7421 -- Start of processing for Process_Naming_Scheme
7423 Initialize (Data, Tree => Tree, Flags => Flags);
7424 Check_All_Projects (Root_Project, Data, Imported_First => True);
7426 end Process_Naming_Scheme;