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.Display_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);
781 Project.Has_Multi_Unit_Sources := True;
784 -- Add the source to the language list
786 Id.Next_In_Lang := Lang_Id.First_Source;
787 Lang_Id.First_Source := Id;
789 if Source_To_Replace /= No_Source then
790 Remove_Source (Source_To_Replace, Id);
793 Files_Htable.Set (Data.File_To_Source, File_Name, Id);
796 ------------------------------
797 -- Canonical_Case_File_Name --
798 ------------------------------
800 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
802 if Osint.File_Names_Case_Sensitive then
803 return File_Name_Type (Name);
805 Get_Name_String (Name);
806 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
809 end Canonical_Case_File_Name;
816 (Project : Project_Id;
817 Data : in out Tree_Processing_Data)
819 Specs : Array_Element_Id;
820 Bodies : Array_Element_Id;
821 Extending : Boolean := False;
822 Prj_Data : Project_Processing_Data;
825 Initialize (Prj_Data, Project);
827 Check_If_Externally_Built (Project, Data);
829 -- Object, exec and source directories
831 Get_Directories (Project, Data);
833 -- Get the programming languages
835 Check_Programming_Languages (Project, Data);
837 if Project.Qualifier = Dry
838 and then Project.Source_Dirs /= Nil_String
841 Source_Dirs : constant Variable_Value :=
844 Project.Decl.Attributes, Data.Tree);
845 Source_Files : constant Variable_Value :=
848 Project.Decl.Attributes, Data.Tree);
849 Source_List_File : constant Variable_Value :=
851 (Name_Source_List_File,
852 Project.Decl.Attributes, Data.Tree);
853 Languages : constant Variable_Value :=
856 Project.Decl.Attributes, Data.Tree);
859 if Source_Dirs.Values = Nil_String
860 and then Source_Files.Values = Nil_String
861 and then Languages.Values = Nil_String
862 and then Source_List_File.Default
864 Project.Source_Dirs := Nil_String;
869 "at least one of Source_Files, Source_Dirs or Languages "
870 & "must be declared empty for an abstract project",
871 Project.Location, Project);
876 -- Check configuration. This must be done even for gnatmake (even though
877 -- no user configuration file was provided) since the default config we
878 -- generate indicates whether libraries are supported for instance.
880 Check_Configuration (Project, Data);
882 -- Library attributes
884 Check_Library_Attributes (Project, Data);
886 if Current_Verbosity = High then
887 Show_Source_Dirs (Project, Data.Tree);
890 Extending := Project.Extends /= No_Project;
892 Check_Package_Naming (Project, Data, Bodies => Bodies, Specs => Specs);
896 if Project.Source_Dirs /= Nil_String then
897 Look_For_Sources (Prj_Data, Data);
899 if not Project.Externally_Built
900 and then not Extending
903 Language : Language_Ptr;
905 Alt_Lang : Language_List;
906 Continuation : Boolean := False;
907 Iter : Source_Iterator;
910 Language := Project.Languages;
911 while Language /= No_Language_Index loop
913 -- If there are no sources for this language, check if there
914 -- are sources for which this is an alternate language.
916 if Language.First_Source = No_Source
917 and then (Data.Flags.Require_Sources_Other_Lang
918 or else Language.Name = Name_Ada)
920 Iter := For_Each_Source (In_Tree => Data.Tree,
923 Source := Element (Iter);
924 exit Source_Loop when Source = No_Source
925 or else Source.Language = Language;
927 Alt_Lang := Source.Alternate_Languages;
928 while Alt_Lang /= null loop
929 exit Source_Loop when Alt_Lang.Language = Language;
930 Alt_Lang := Alt_Lang.Next;
934 end loop Source_Loop;
936 if Source = No_Source then
940 Get_Name_String (Language.Display_Name),
942 Prj_Data.Source_List_File_Location,
944 Continuation := True;
948 Language := Language.Next;
954 -- If a list of sources is specified in attribute Interfaces, set
955 -- In_Interfaces only for the sources specified in the list.
957 Check_Interfaces (Project, Data);
959 -- If it is a library project file, check if it is a standalone library
961 if Project.Library then
962 Check_Stand_Alone_Library (Project, Data);
965 -- Put the list of Mains, if any, in the project data
967 Get_Mains (Project, Data);
976 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
977 The_Name : String := Name;
979 Need_Letter : Boolean := True;
980 Last_Underscore : Boolean := False;
981 OK : Boolean := The_Name'Length > 0;
984 function Is_Reserved (Name : Name_Id) return Boolean;
985 function Is_Reserved (S : String) return Boolean;
986 -- Check that the given name is not an Ada 95 reserved word. The reason
987 -- for the Ada 95 here is that we do not want to exclude the case of an
988 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
989 -- name would be rejected anyway by the compiler. That means there is no
990 -- requirement that the project file parser reject this.
996 function Is_Reserved (S : String) return Boolean is
999 Add_Str_To_Name_Buffer (S);
1000 return Is_Reserved (Name_Find);
1007 function Is_Reserved (Name : Name_Id) return Boolean is
1009 if Get_Name_Table_Byte (Name) /= 0
1010 and then Name /= Name_Project
1011 and then Name /= Name_Extends
1012 and then Name /= Name_External
1013 and then Name not in Ada_2005_Reserved_Words
1017 if Current_Verbosity = High then
1018 Write_Str (The_Name);
1019 Write_Line (" is an Ada reserved word.");
1029 -- Start of processing for Check_Ada_Name
1032 To_Lower (The_Name);
1034 Name_Len := The_Name'Length;
1035 Name_Buffer (1 .. Name_Len) := The_Name;
1037 -- Special cases of children of packages A, G, I and S on VMS
1039 if OpenVMS_On_Target
1040 and then Name_Len > 3
1041 and then Name_Buffer (2 .. 3) = "__"
1043 ((Name_Buffer (1) = 'a
') or else
1044 (Name_Buffer (1) = 'g
') or else
1045 (Name_Buffer (1) = 'i
') or else
1046 (Name_Buffer (1) = 's
'))
1048 Name_Buffer (2) := '.';
1049 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1050 Name_Len := Name_Len - 1;
1053 Real_Name := Name_Find;
1055 if Is_Reserved (Real_Name) then
1059 First := The_Name'First;
1061 for Index in The_Name'Range loop
1064 -- We need a letter (at the beginning, and following a dot),
1065 -- but we don't have one.
1067 if Is_Letter (The_Name (Index)) then
1068 Need_Letter := False;
1073 if Current_Verbosity = High then
1074 Write_Int (Types.Int (Index));
1076 Write_Char (The_Name (Index));
1077 Write_Line ("' is not a letter.");
1083 elsif Last_Underscore
1084 and then (The_Name (Index) = '_
' or else The_Name (Index) = '.')
1086 -- Two underscores are illegal, and a dot cannot follow
1091 if Current_Verbosity = High then
1092 Write_Int (Types.Int (Index));
1094 Write_Char (The_Name (Index));
1095 Write_Line ("' is illegal here.");
1100 elsif The_Name (Index) = '.' then
1102 -- First, check if the name before the dot is not a reserved word
1104 if Is_Reserved (The_Name (First .. Index - 1)) then
1110 -- We need a letter after a dot
1112 Need_Letter := True;
1114 elsif The_Name (Index) = '_
' then
1115 Last_Underscore := True;
1118 -- We need an letter or a digit
1120 Last_Underscore := False;
1122 if not Is_Alphanumeric (The_Name (Index)) then
1125 if Current_Verbosity = High then
1126 Write_Int (Types.Int (Index));
1128 Write_Char (The_Name (Index));
1129 Write_Line ("' is not alphanumeric.");
1137 -- Cannot end with an underscore or a dot
1139 OK := OK and then not Need_Letter and then not Last_Underscore;
1142 if First /= Name'First and then
1143 Is_Reserved (The_Name (First .. The_Name'Last))
1151 -- Signal a problem with No_Name
1157 -------------------------
1158 -- Check_Configuration --
1159 -------------------------
1161 procedure Check_Configuration
1162 (Project : Project_Id;
1163 Data : in out Tree_Processing_Data)
1165 Dot_Replacement : File_Name_Type := No_File;
1166 Casing : Casing_Type := All_Lower_Case;
1167 Separate_Suffix : File_Name_Type := No_File;
1169 Lang_Index : Language_Ptr := No_Language_Index;
1170 -- The index of the language data being checked
1172 Prev_Index : Language_Ptr := No_Language_Index;
1173 -- The index of the previous language
1175 procedure Process_Project_Level_Simple_Attributes;
1176 -- Process the simple attributes at the project level
1178 procedure Process_Project_Level_Array_Attributes;
1179 -- Process the associate array attributes at the project level
1181 procedure Process_Packages;
1182 -- Read the packages of the project
1184 ----------------------
1185 -- Process_Packages --
1186 ----------------------
1188 procedure Process_Packages is
1189 Packages : Package_Id;
1190 Element : Package_Element;
1192 procedure Process_Binder (Arrays : Array_Id);
1193 -- Process the associate array attributes of package Binder
1195 procedure Process_Builder (Attributes : Variable_Id);
1196 -- Process the simple attributes of package Builder
1198 procedure Process_Compiler (Arrays : Array_Id);
1199 -- Process the associate array attributes of package Compiler
1201 procedure Process_Naming (Attributes : Variable_Id);
1202 -- Process the simple attributes of package Naming
1204 procedure Process_Naming (Arrays : Array_Id);
1205 -- Process the associate array attributes of package Naming
1207 procedure Process_Linker (Attributes : Variable_Id);
1208 -- Process the simple attributes of package Linker of a
1209 -- configuration project.
1211 --------------------
1212 -- Process_Binder --
1213 --------------------
1215 procedure Process_Binder (Arrays : Array_Id) is
1216 Current_Array_Id : Array_Id;
1217 Current_Array : Array_Data;
1218 Element_Id : Array_Element_Id;
1219 Element : Array_Element;
1222 -- Process the associative array attribute of package Binder
1224 Current_Array_Id := Arrays;
1225 while Current_Array_Id /= No_Array loop
1226 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1228 Element_Id := Current_Array.Value;
1229 while Element_Id /= No_Array_Element loop
1230 Element := Data.Tree.Array_Elements.Table (Element_Id);
1232 if Element.Index /= All_Other_Names then
1234 -- Get the name of the language
1237 Get_Language_From_Name
1238 (Project, Get_Name_String (Element.Index));
1240 if Lang_Index /= No_Language_Index then
1241 case Current_Array.Name is
1244 -- Attribute Driver (<language>)
1246 Lang_Index.Config.Binder_Driver :=
1247 File_Name_Type (Element.Value.Value);
1249 when Name_Required_Switches =>
1252 Lang_Index.Config.Binder_Required_Switches,
1253 From_List => Element.Value.Values,
1254 In_Tree => Data.Tree);
1258 -- Attribute Prefix (<language>)
1260 Lang_Index.Config.Binder_Prefix :=
1261 Element.Value.Value;
1263 when Name_Objects_Path =>
1265 -- Attribute Objects_Path (<language>)
1267 Lang_Index.Config.Objects_Path :=
1268 Element.Value.Value;
1270 when Name_Objects_Path_File =>
1272 -- Attribute Objects_Path (<language>)
1274 Lang_Index.Config.Objects_Path_File :=
1275 Element.Value.Value;
1283 Element_Id := Element.Next;
1286 Current_Array_Id := Current_Array.Next;
1290 ---------------------
1291 -- Process_Builder --
1292 ---------------------
1294 procedure Process_Builder (Attributes : Variable_Id) is
1295 Attribute_Id : Variable_Id;
1296 Attribute : Variable;
1299 -- Process non associated array attribute from package Builder
1301 Attribute_Id := Attributes;
1302 while Attribute_Id /= No_Variable loop
1304 Data.Tree.Variable_Elements.Table (Attribute_Id);
1306 if not Attribute.Value.Default then
1307 if Attribute.Name = Name_Executable_Suffix then
1309 -- Attribute Executable_Suffix: the suffix of the
1312 Project.Config.Executable_Suffix :=
1313 Attribute.Value.Value;
1317 Attribute_Id := Attribute.Next;
1319 end Process_Builder;
1321 ----------------------
1322 -- Process_Compiler --
1323 ----------------------
1325 procedure Process_Compiler (Arrays : Array_Id) is
1326 Current_Array_Id : Array_Id;
1327 Current_Array : Array_Data;
1328 Element_Id : Array_Element_Id;
1329 Element : Array_Element;
1330 List : String_List_Id;
1333 -- Process the associative array attribute of package Compiler
1335 Current_Array_Id := Arrays;
1336 while Current_Array_Id /= No_Array loop
1337 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1339 Element_Id := Current_Array.Value;
1340 while Element_Id /= No_Array_Element loop
1341 Element := Data.Tree.Array_Elements.Table (Element_Id);
1343 if Element.Index /= All_Other_Names then
1345 -- Get the name of the language
1347 Lang_Index := Get_Language_From_Name
1348 (Project, Get_Name_String (Element.Index));
1350 if Lang_Index /= No_Language_Index then
1351 case Current_Array.Name is
1352 when Name_Dependency_Switches =>
1354 -- Attribute Dependency_Switches (<language>)
1356 if Lang_Index.Config.Dependency_Kind = None then
1357 Lang_Index.Config.Dependency_Kind := Makefile;
1360 List := Element.Value.Values;
1362 if List /= Nil_String then
1364 Lang_Index.Config.Dependency_Option,
1366 In_Tree => Data.Tree);
1369 when Name_Dependency_Driver =>
1371 -- Attribute Dependency_Driver (<language>)
1373 if Lang_Index.Config.Dependency_Kind = None then
1374 Lang_Index.Config.Dependency_Kind := Makefile;
1377 List := Element.Value.Values;
1379 if List /= Nil_String then
1381 Lang_Index.Config.Compute_Dependency,
1383 In_Tree => Data.Tree);
1386 when Name_Include_Switches =>
1388 -- Attribute Include_Switches (<language>)
1390 List := Element.Value.Values;
1392 if List = Nil_String then
1394 (Data.Flags, "include option cannot be null",
1395 Element.Value.Location, Project);
1398 Put (Into_List => Lang_Index.Config.Include_Option,
1400 In_Tree => Data.Tree);
1402 when Name_Include_Path =>
1404 -- Attribute Include_Path (<language>)
1406 Lang_Index.Config.Include_Path :=
1407 Element.Value.Value;
1409 when Name_Include_Path_File =>
1411 -- Attribute Include_Path_File (<language>)
1413 Lang_Index.Config.Include_Path_File :=
1414 Element.Value.Value;
1418 -- Attribute Driver (<language>)
1420 Lang_Index.Config.Compiler_Driver :=
1421 File_Name_Type (Element.Value.Value);
1423 when Name_Required_Switches |
1424 Name_Leading_Required_Switches =>
1427 Compiler_Leading_Required_Switches,
1428 From_List => Element.Value.Values,
1429 In_Tree => Data.Tree);
1431 when Name_Trailing_Required_Switches =>
1434 Compiler_Trailing_Required_Switches,
1435 From_List => Element.Value.Values,
1436 In_Tree => Data.Tree);
1438 when Name_Multi_Unit_Switches =>
1440 Lang_Index.Config.Multi_Unit_Switches,
1441 From_List => Element.Value.Values,
1442 In_Tree => Data.Tree);
1444 when Name_Multi_Unit_Object_Separator =>
1445 Get_Name_String (Element.Value.Value);
1447 if Name_Len /= 1 then
1450 "multi-unit object separator must have " &
1451 "a single character",
1452 Element.Value.Location, Project);
1454 elsif Name_Buffer (1) = ' ' then
1457 "multi-unit object separator cannot be " &
1459 Element.Value.Location, Project);
1462 Lang_Index.Config.Multi_Unit_Object_Separator :=
1466 when Name_Path_Syntax =>
1468 Lang_Index.Config.Path_Syntax :=
1469 Path_Syntax_Kind'Value
1470 (Get_Name_String (Element.Value.Value));
1473 when Constraint_Error =>
1476 "invalid value for Path_Syntax",
1477 Element.Value.Location, Project);
1480 when Name_Object_File_Suffix =>
1481 if Get_Name_String (Element.Value.Value) = "" then
1484 "object file suffix cannot be empty",
1485 Element.Value.Location, Project);
1488 Lang_Index.Config.Object_File_Suffix :=
1489 Element.Value.Value;
1492 when Name_Object_File_Switches =>
1494 Lang_Index.Config.Object_File_Switches,
1495 From_List => Element.Value.Values,
1496 In_Tree => Data.Tree);
1498 when Name_Pic_Option =>
1500 -- Attribute Compiler_Pic_Option (<language>)
1502 List := Element.Value.Values;
1504 if List = Nil_String then
1507 "compiler PIC option cannot be null",
1508 Element.Value.Location, Project);
1512 Lang_Index.Config.Compilation_PIC_Option,
1514 In_Tree => Data.Tree);
1516 when Name_Mapping_File_Switches =>
1518 -- Attribute Mapping_File_Switches (<language>)
1520 List := Element.Value.Values;
1522 if List = Nil_String then
1525 "mapping file switches cannot be null",
1526 Element.Value.Location, Project);
1530 Lang_Index.Config.Mapping_File_Switches,
1532 In_Tree => Data.Tree);
1534 when Name_Mapping_Spec_Suffix =>
1536 -- Attribute Mapping_Spec_Suffix (<language>)
1538 Lang_Index.Config.Mapping_Spec_Suffix :=
1539 File_Name_Type (Element.Value.Value);
1541 when Name_Mapping_Body_Suffix =>
1543 -- Attribute Mapping_Body_Suffix (<language>)
1545 Lang_Index.Config.Mapping_Body_Suffix :=
1546 File_Name_Type (Element.Value.Value);
1548 when Name_Config_File_Switches =>
1550 -- Attribute Config_File_Switches (<language>)
1552 List := Element.Value.Values;
1554 if List = Nil_String then
1557 "config file switches cannot be null",
1558 Element.Value.Location, Project);
1562 Lang_Index.Config.Config_File_Switches,
1564 In_Tree => Data.Tree);
1566 when Name_Objects_Path =>
1568 -- Attribute Objects_Path (<language>)
1570 Lang_Index.Config.Objects_Path :=
1571 Element.Value.Value;
1573 when Name_Objects_Path_File =>
1575 -- Attribute Objects_Path_File (<language>)
1577 Lang_Index.Config.Objects_Path_File :=
1578 Element.Value.Value;
1580 when Name_Config_Body_File_Name =>
1582 -- Attribute Config_Body_File_Name (<language>)
1584 Lang_Index.Config.Config_Body :=
1585 Element.Value.Value;
1587 when Name_Config_Body_File_Name_Index =>
1589 -- Attribute Config_Body_File_Name_Index
1592 Lang_Index.Config.Config_Body_Index :=
1593 Element.Value.Value;
1595 when Name_Config_Body_File_Name_Pattern =>
1597 -- Attribute Config_Body_File_Name_Pattern
1600 Lang_Index.Config.Config_Body_Pattern :=
1601 Element.Value.Value;
1603 when Name_Config_Spec_File_Name =>
1605 -- Attribute Config_Spec_File_Name (<language>)
1607 Lang_Index.Config.Config_Spec :=
1608 Element.Value.Value;
1610 when Name_Config_Spec_File_Name_Index =>
1612 -- Attribute Config_Spec_File_Name_Index
1615 Lang_Index.Config.Config_Spec_Index :=
1616 Element.Value.Value;
1618 when Name_Config_Spec_File_Name_Pattern =>
1620 -- Attribute Config_Spec_File_Name_Pattern
1623 Lang_Index.Config.Config_Spec_Pattern :=
1624 Element.Value.Value;
1626 when Name_Config_File_Unique =>
1628 -- Attribute Config_File_Unique (<language>)
1631 Lang_Index.Config.Config_File_Unique :=
1633 (Get_Name_String (Element.Value.Value));
1635 when Constraint_Error =>
1638 "illegal value for Config_File_Unique",
1639 Element.Value.Location, Project);
1648 Element_Id := Element.Next;
1651 Current_Array_Id := Current_Array.Next;
1653 end Process_Compiler;
1655 --------------------
1656 -- Process_Naming --
1657 --------------------
1659 procedure Process_Naming (Attributes : Variable_Id) is
1660 Attribute_Id : Variable_Id;
1661 Attribute : Variable;
1664 -- Process non associated array attribute from package Naming
1666 Attribute_Id := Attributes;
1667 while Attribute_Id /= No_Variable loop
1668 Attribute := Data.Tree.Variable_Elements.Table (Attribute_Id);
1670 if not Attribute.Value.Default then
1671 if Attribute.Name = Name_Separate_Suffix then
1673 -- Attribute Separate_Suffix
1675 Get_Name_String (Attribute.Value.Value);
1676 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1677 Separate_Suffix := Name_Find;
1679 elsif Attribute.Name = Name_Casing then
1685 Value (Get_Name_String (Attribute.Value.Value));
1688 when Constraint_Error =>
1691 "invalid value for Casing",
1692 Attribute.Value.Location, Project);
1695 elsif Attribute.Name = Name_Dot_Replacement then
1697 -- Attribute Dot_Replacement
1699 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1704 Attribute_Id := Attribute.Next;
1708 procedure Process_Naming (Arrays : Array_Id) is
1709 Current_Array_Id : Array_Id;
1710 Current_Array : Array_Data;
1711 Element_Id : Array_Element_Id;
1712 Element : Array_Element;
1715 -- Process the associative array attribute of package Naming
1717 Current_Array_Id := Arrays;
1718 while Current_Array_Id /= No_Array loop
1719 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1721 Element_Id := Current_Array.Value;
1722 while Element_Id /= No_Array_Element loop
1723 Element := Data.Tree.Array_Elements.Table (Element_Id);
1725 -- Get the name of the language
1727 Lang_Index := Get_Language_From_Name
1728 (Project, Get_Name_String (Element.Index));
1730 if Lang_Index /= No_Language_Index then
1731 case Current_Array.Name is
1732 when Name_Spec_Suffix | Name_Specification_Suffix =>
1734 -- Attribute Spec_Suffix (<language>)
1736 Get_Name_String (Element.Value.Value);
1737 Canonical_Case_File_Name
1738 (Name_Buffer (1 .. Name_Len));
1739 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1742 when Name_Implementation_Suffix | Name_Body_Suffix =>
1744 Get_Name_String (Element.Value.Value);
1745 Canonical_Case_File_Name
1746 (Name_Buffer (1 .. Name_Len));
1748 -- Attribute Body_Suffix (<language>)
1750 Lang_Index.Config.Naming_Data.Body_Suffix :=
1752 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1753 Lang_Index.Config.Naming_Data.Body_Suffix;
1760 Element_Id := Element.Next;
1763 Current_Array_Id := Current_Array.Next;
1767 --------------------
1768 -- Process_Linker --
1769 --------------------
1771 procedure Process_Linker (Attributes : Variable_Id) is
1772 Attribute_Id : Variable_Id;
1773 Attribute : Variable;
1776 -- Process non associated array attribute from package Linker
1778 Attribute_Id := Attributes;
1779 while Attribute_Id /= No_Variable loop
1781 Data.Tree.Variable_Elements.Table (Attribute_Id);
1783 if not Attribute.Value.Default then
1784 if Attribute.Name = Name_Driver then
1786 -- Attribute Linker'Driver: the default linker to use
1788 Project.Config.Linker :=
1789 Path_Name_Type (Attribute.Value.Value);
1791 -- Linker'Driver is also used to link shared libraries
1792 -- if the obsolescent attribute Library_GCC has not been
1795 if Project.Config.Shared_Lib_Driver = No_File then
1796 Project.Config.Shared_Lib_Driver :=
1797 File_Name_Type (Attribute.Value.Value);
1800 elsif Attribute.Name = Name_Required_Switches then
1802 -- Attribute Required_Switches: the minimum
1803 -- options to use when invoking the linker
1805 Put (Into_List => Project.Config.Minimum_Linker_Options,
1806 From_List => Attribute.Value.Values,
1807 In_Tree => Data.Tree);
1809 elsif Attribute.Name = Name_Map_File_Option then
1810 Project.Config.Map_File_Option := Attribute.Value.Value;
1812 elsif Attribute.Name = Name_Max_Command_Line_Length then
1814 Project.Config.Max_Command_Line_Length :=
1815 Natural'Value (Get_Name_String
1816 (Attribute.Value.Value));
1819 when Constraint_Error =>
1822 "value must be positive or equal to 0",
1823 Attribute.Value.Location, Project);
1826 elsif Attribute.Name = Name_Response_File_Format then
1831 Get_Name_String (Attribute.Value.Value);
1832 To_Lower (Name_Buffer (1 .. Name_Len));
1835 if Name = Name_None then
1836 Project.Config.Resp_File_Format := None;
1838 elsif Name = Name_Gnu then
1839 Project.Config.Resp_File_Format := GNU;
1841 elsif Name = Name_Object_List then
1842 Project.Config.Resp_File_Format := Object_List;
1844 elsif Name = Name_Option_List then
1845 Project.Config.Resp_File_Format := Option_List;
1850 "illegal response file format",
1851 Attribute.Value.Location, Project);
1855 elsif Attribute.Name = Name_Response_File_Switches then
1856 Put (Into_List => Project.Config.Resp_File_Options,
1857 From_List => Attribute.Value.Values,
1858 In_Tree => Data.Tree);
1862 Attribute_Id := Attribute.Next;
1866 -- Start of processing for Process_Packages
1869 Packages := Project.Decl.Packages;
1870 while Packages /= No_Package loop
1871 Element := Data.Tree.Packages.Table (Packages);
1873 case Element.Name is
1876 -- Process attributes of package Binder
1878 Process_Binder (Element.Decl.Arrays);
1880 when Name_Builder =>
1882 -- Process attributes of package Builder
1884 Process_Builder (Element.Decl.Attributes);
1886 when Name_Compiler =>
1888 -- Process attributes of package Compiler
1890 Process_Compiler (Element.Decl.Arrays);
1894 -- Process attributes of package Linker
1896 Process_Linker (Element.Decl.Attributes);
1900 -- Process attributes of package Naming
1902 Process_Naming (Element.Decl.Attributes);
1903 Process_Naming (Element.Decl.Arrays);
1909 Packages := Element.Next;
1911 end Process_Packages;
1913 ---------------------------------------------
1914 -- Process_Project_Level_Simple_Attributes --
1915 ---------------------------------------------
1917 procedure Process_Project_Level_Simple_Attributes is
1918 Attribute_Id : Variable_Id;
1919 Attribute : Variable;
1920 List : String_List_Id;
1923 -- Process non associated array attribute at project level
1925 Attribute_Id := Project.Decl.Attributes;
1926 while Attribute_Id /= No_Variable loop
1928 Data.Tree.Variable_Elements.Table (Attribute_Id);
1930 if not Attribute.Value.Default then
1931 if Attribute.Name = Name_Target then
1933 -- Attribute Target: the target specified
1935 Project.Config.Target := Attribute.Value.Value;
1937 elsif Attribute.Name = Name_Library_Builder then
1939 -- Attribute Library_Builder: the application to invoke
1940 -- to build libraries.
1942 Project.Config.Library_Builder :=
1943 Path_Name_Type (Attribute.Value.Value);
1945 elsif Attribute.Name = Name_Archive_Builder then
1947 -- Attribute Archive_Builder: the archive builder
1948 -- (usually "ar") and its minimum options (usually "cr").
1950 List := Attribute.Value.Values;
1952 if List = Nil_String then
1955 "archive builder cannot be null",
1956 Attribute.Value.Location, Project);
1959 Put (Into_List => Project.Config.Archive_Builder,
1961 In_Tree => Data.Tree);
1963 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1965 -- Attribute Archive_Builder: the archive builder
1966 -- (usually "ar") and its minimum options (usually "cr").
1968 List := Attribute.Value.Values;
1970 if List /= Nil_String then
1973 Project.Config.Archive_Builder_Append_Option,
1975 In_Tree => Data.Tree);
1978 elsif Attribute.Name = Name_Archive_Indexer then
1980 -- Attribute Archive_Indexer: the optional archive
1981 -- indexer (usually "ranlib") with its minimum options
1984 List := Attribute.Value.Values;
1986 if List = Nil_String then
1989 "archive indexer cannot be null",
1990 Attribute.Value.Location, Project);
1993 Put (Into_List => Project.Config.Archive_Indexer,
1995 In_Tree => Data.Tree);
1997 elsif Attribute.Name = Name_Library_Partial_Linker then
1999 -- Attribute Library_Partial_Linker: the optional linker
2000 -- driver with its minimum options, to partially link
2003 List := Attribute.Value.Values;
2005 if List = Nil_String then
2008 "partial linker cannot be null",
2009 Attribute.Value.Location, Project);
2012 Put (Into_List => Project.Config.Lib_Partial_Linker,
2014 In_Tree => Data.Tree);
2016 elsif Attribute.Name = Name_Library_GCC then
2017 Project.Config.Shared_Lib_Driver :=
2018 File_Name_Type (Attribute.Value.Value);
2021 "?Library_'G'C
'C is an obsolescent attribute
, " &
2022 "use Linker
''Driver instead
",
2023 Attribute.Value.Location, Project);
2025 elsif Attribute.Name = Name_Archive_Suffix then
2026 Project.Config.Archive_Suffix :=
2027 File_Name_Type (Attribute.Value.Value);
2029 elsif Attribute.Name = Name_Linker_Executable_Option then
2031 -- Attribute Linker_Executable_Option: optional options
2032 -- to specify an executable name. Defaults to "-o
".
2034 List := Attribute.Value.Values;
2036 if List = Nil_String then
2039 "linker executable option cannot be
null",
2040 Attribute.Value.Location, Project);
2043 Put (Into_List => Project.Config.Linker_Executable_Option,
2045 In_Tree => Data.Tree);
2047 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2049 -- Attribute Linker_Lib_Dir_Option: optional options
2050 -- to specify a library search directory. Defaults to
2053 Get_Name_String (Attribute.Value.Value);
2055 if Name_Len = 0 then
2058 "linker library directory option cannot be empty
",
2059 Attribute.Value.Location, Project);
2062 Project.Config.Linker_Lib_Dir_Option :=
2063 Attribute.Value.Value;
2065 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2067 -- Attribute Linker_Lib_Name_Option: optional options
2068 -- to specify the name of a library to be linked in.
2069 -- Defaults to "-l
".
2071 Get_Name_String (Attribute.Value.Value);
2073 if Name_Len = 0 then
2076 "linker library name option cannot be empty
",
2077 Attribute.Value.Location, Project);
2080 Project.Config.Linker_Lib_Name_Option :=
2081 Attribute.Value.Value;
2083 elsif Attribute.Name = Name_Run_Path_Option then
2085 -- Attribute Run_Path_Option: optional options to
2086 -- specify a path for libraries.
2088 List := Attribute.Value.Values;
2090 if List /= Nil_String then
2091 Put (Into_List => Project.Config.Run_Path_Option,
2093 In_Tree => Data.Tree);
2096 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2098 pragma Unsuppress (All_Checks);
2100 Project.Config.Separate_Run_Path_Options :=
2101 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2103 when Constraint_Error =>
2106 "invalid value
""" &
2107 Get_Name_String (Attribute.Value.Value) &
2108 """ for Separate_Run_Path_Options
",
2109 Attribute.Value.Location, Project);
2112 elsif Attribute.Name = Name_Library_Support then
2114 pragma Unsuppress (All_Checks);
2116 Project.Config.Lib_Support :=
2117 Library_Support'Value (Get_Name_String
2118 (Attribute.Value.Value));
2120 when Constraint_Error =>
2123 "invalid value
""" &
2124 Get_Name_String (Attribute.Value.Value) &
2125 """ for Library_Support
",
2126 Attribute.Value.Location, Project);
2129 elsif Attribute.Name = Name_Shared_Library_Prefix then
2130 Project.Config.Shared_Lib_Prefix :=
2131 File_Name_Type (Attribute.Value.Value);
2133 elsif Attribute.Name = Name_Shared_Library_Suffix then
2134 Project.Config.Shared_Lib_Suffix :=
2135 File_Name_Type (Attribute.Value.Value);
2137 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2139 pragma Unsuppress (All_Checks);
2141 Project.Config.Symbolic_Link_Supported :=
2142 Boolean'Value (Get_Name_String
2143 (Attribute.Value.Value));
2145 when Constraint_Error =>
2149 & Get_Name_String (Attribute.Value.Value)
2150 & """ for Symbolic_Link_Supported
",
2151 Attribute.Value.Location, Project);
2155 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2158 pragma Unsuppress (All_Checks);
2160 Project.Config.Lib_Maj_Min_Id_Supported :=
2161 Boolean'Value (Get_Name_String
2162 (Attribute.Value.Value));
2164 when Constraint_Error =>
2167 "invalid value
""" &
2168 Get_Name_String (Attribute.Value.Value) &
2169 """ for Library_Major_Minor_Id_Supported
",
2170 Attribute.Value.Location, Project);
2173 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2175 pragma Unsuppress (All_Checks);
2177 Project.Config.Auto_Init_Supported :=
2178 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2180 when Constraint_Error =>
2184 & Get_Name_String (Attribute.Value.Value)
2185 & """ for Library_Auto_Init_Supported
",
2186 Attribute.Value.Location, Project);
2189 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2190 List := Attribute.Value.Values;
2192 if List /= Nil_String then
2193 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2195 In_Tree => Data.Tree);
2198 elsif Attribute.Name = Name_Library_Version_Switches then
2199 List := Attribute.Value.Values;
2201 if List /= Nil_String then
2202 Put (Into_List => Project.Config.Lib_Version_Options,
2204 In_Tree => Data.Tree);
2209 Attribute_Id := Attribute.Next;
2211 end Process_Project_Level_Simple_Attributes;
2213 --------------------------------------------
2214 -- Process_Project_Level_Array_Attributes --
2215 --------------------------------------------
2217 procedure Process_Project_Level_Array_Attributes is
2218 Current_Array_Id : Array_Id;
2219 Current_Array : Array_Data;
2220 Element_Id : Array_Element_Id;
2221 Element : Array_Element;
2222 List : String_List_Id;
2225 -- Process the associative array attributes at project level
2227 Current_Array_Id := Project.Decl.Arrays;
2228 while Current_Array_Id /= No_Array loop
2229 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
2231 Element_Id := Current_Array.Value;
2232 while Element_Id /= No_Array_Element loop
2233 Element := Data.Tree.Array_Elements.Table (Element_Id);
2235 -- Get the name of the language
2238 Get_Language_From_Name
2239 (Project, Get_Name_String (Element.Index));
2241 if Lang_Index /= No_Language_Index then
2242 case Current_Array.Name is
2243 when Name_Inherit_Source_Path =>
2244 List := Element.Value.Values;
2246 if List /= Nil_String then
2249 Lang_Index.Config.Include_Compatible_Languages,
2251 In_Tree => Data.Tree,
2252 Lower_Case => True);
2255 when Name_Toolchain_Description =>
2257 -- Attribute Toolchain_Description (<language>)
2259 Lang_Index.Config.Toolchain_Description :=
2260 Element.Value.Value;
2262 when Name_Toolchain_Version =>
2264 -- Attribute Toolchain_Version (<language>)
2266 Lang_Index.Config.Toolchain_Version :=
2267 Element.Value.Value;
2269 when Name_Runtime_Library_Dir =>
2271 -- Attribute Runtime_Library_Dir (<language>)
2273 Lang_Index.Config.Runtime_Library_Dir :=
2274 Element.Value.Value;
2276 when Name_Runtime_Source_Dir =>
2278 -- Attribute Runtime_Library_Dir (<language>)
2280 Lang_Index.Config.Runtime_Source_Dir :=
2281 Element.Value.Value;
2283 when Name_Object_Generated =>
2285 pragma Unsuppress (All_Checks);
2291 (Get_Name_String (Element.Value.Value));
2293 Lang_Index.Config.Object_Generated := Value;
2295 -- If no object is generated, no object may be
2299 Lang_Index.Config.Objects_Linked := False;
2303 when Constraint_Error =>
2307 & Get_Name_String (Element.Value.Value)
2308 & """ for Object_Generated
",
2309 Element.Value.Location, Project);
2312 when Name_Objects_Linked =>
2314 pragma Unsuppress (All_Checks);
2320 (Get_Name_String (Element.Value.Value));
2322 -- No change if Object_Generated is False, as this
2323 -- forces Objects_Linked to be False too.
2325 if Lang_Index.Config.Object_Generated then
2326 Lang_Index.Config.Objects_Linked := Value;
2330 when Constraint_Error =>
2334 & Get_Name_String (Element.Value.Value)
2335 & """ for Objects_Linked
",
2336 Element.Value.Location, Project);
2343 Element_Id := Element.Next;
2346 Current_Array_Id := Current_Array.Next;
2348 end Process_Project_Level_Array_Attributes;
2350 -- Start of processing for Check_Configuration
2353 Process_Project_Level_Simple_Attributes;
2354 Process_Project_Level_Array_Attributes;
2357 -- For unit based languages, set Casing, Dot_Replacement and
2358 -- Separate_Suffix in Naming_Data.
2360 Lang_Index := Project.Languages;
2361 while Lang_Index /= No_Language_Index loop
2362 if Lang_Index.Name = Name_Ada then
2363 Lang_Index.Config.Naming_Data.Casing := Casing;
2364 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2366 if Separate_Suffix /= No_File then
2367 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2374 Lang_Index := Lang_Index.Next;
2377 -- Give empty names to various prefixes/suffixes, if they have not
2378 -- been specified in the configuration.
2380 if Project.Config.Archive_Suffix = No_File then
2381 Project.Config.Archive_Suffix := Empty_File;
2384 if Project.Config.Shared_Lib_Prefix = No_File then
2385 Project.Config.Shared_Lib_Prefix := Empty_File;
2388 if Project.Config.Shared_Lib_Suffix = No_File then
2389 Project.Config.Shared_Lib_Suffix := Empty_File;
2392 Lang_Index := Project.Languages;
2393 while Lang_Index /= No_Language_Index loop
2395 -- For all languages, Compiler_Driver needs to be specified. This is
2396 -- only needed if we do intend to compile (not in GPS for instance).
2398 if Data.Flags.Compiler_Driver_Mandatory
2399 and then Lang_Index.Config.Compiler_Driver = No_File
2401 Error_Msg_Name_1 := Lang_Index.Display_Name;
2404 "?no compiler specified
for language
%%" &
2405 ", ignoring
all its sources
",
2406 No_Location, Project);
2408 if Lang_Index = Project.Languages then
2409 Project.Languages := Lang_Index.Next;
2411 Prev_Index.Next := Lang_Index.Next;
2414 elsif Lang_Index.Name = Name_Ada then
2415 Prev_Index := Lang_Index;
2417 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2418 -- Body_Suffix need to be specified.
2420 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2423 "Dot_Replacement
not specified
for Ada
",
2424 No_Location, Project);
2427 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2430 "Spec_Suffix
not specified
for Ada
",
2431 No_Location, Project);
2434 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2437 "Body_Suffix
not specified
for Ada
",
2438 No_Location, Project);
2442 Prev_Index := Lang_Index;
2444 -- For file based languages, either Spec_Suffix or Body_Suffix
2445 -- need to be specified.
2447 if Data.Flags.Require_Sources_Other_Lang
2448 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2449 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2451 Error_Msg_Name_1 := Lang_Index.Display_Name;
2454 "no suffixes specified
for %%",
2455 No_Location, Project);
2459 Lang_Index := Lang_Index.Next;
2461 end Check_Configuration;
2463 -------------------------------
2464 -- Check_If_Externally_Built --
2465 -------------------------------
2467 procedure Check_If_Externally_Built
2468 (Project : Project_Id;
2469 Data : in out Tree_Processing_Data)
2471 Externally_Built : constant Variable_Value :=
2473 (Name_Externally_Built,
2474 Project.Decl.Attributes, Data.Tree);
2477 if not Externally_Built.Default then
2478 Get_Name_String (Externally_Built.Value);
2479 To_Lower (Name_Buffer (1 .. Name_Len));
2481 if Name_Buffer (1 .. Name_Len) = "true" then
2482 Project.Externally_Built := True;
2484 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2485 Error_Msg (Data.Flags,
2486 "Externally_Built may only be
true or false",
2487 Externally_Built.Location, Project);
2491 -- A virtual project extending an externally built project is itself
2492 -- externally built.
2494 if Project.Virtual and then Project.Extends /= No_Project then
2495 Project.Externally_Built := Project.Extends.Externally_Built;
2498 if Current_Verbosity = High then
2499 Write_Str ("Project
is ");
2501 if not Project.Externally_Built then
2505 Write_Line ("externally built
.");
2507 end Check_If_Externally_Built;
2509 ----------------------
2510 -- Check_Interfaces --
2511 ----------------------
2513 procedure Check_Interfaces
2514 (Project : Project_Id;
2515 Data : in out Tree_Processing_Data)
2517 Interfaces : constant Prj.Variable_Value :=
2519 (Snames.Name_Interfaces,
2520 Project.Decl.Attributes,
2523 Library_Interface : constant Prj.Variable_Value :=
2525 (Snames.Name_Library_Interface,
2526 Project.Decl.Attributes,
2529 List : String_List_Id;
2530 Element : String_Element;
2531 Name : File_Name_Type;
2532 Iter : Source_Iterator;
2534 Project_2 : Project_Id;
2538 if not Interfaces.Default then
2540 -- Set In_Interfaces to False for all sources. It will be set to True
2541 -- later for the sources in the Interfaces list.
2543 Project_2 := Project;
2544 while Project_2 /= No_Project loop
2545 Iter := For_Each_Source (Data.Tree, Project_2);
2547 Source := Prj.Element (Iter);
2548 exit when Source = No_Source;
2549 Source.In_Interfaces := False;
2553 Project_2 := Project_2.Extends;
2556 List := Interfaces.Values;
2557 while List /= Nil_String loop
2558 Element := Data.Tree.String_Elements.Table (List);
2559 Name := Canonical_Case_File_Name (Element.Value);
2561 Project_2 := Project;
2563 while Project_2 /= No_Project loop
2564 Iter := For_Each_Source (Data.Tree, Project_2);
2567 Source := Prj.Element (Iter);
2568 exit when Source = No_Source;
2570 if Source.File = Name then
2571 if not Source.Locally_Removed then
2572 Source.In_Interfaces := True;
2573 Source.Declared_In_Interfaces := True;
2575 Other := Other_Part (Source);
2577 if Other /= No_Source then
2578 Other.In_Interfaces := True;
2579 Other.Declared_In_Interfaces := True;
2582 if Current_Verbosity = High then
2583 Write_Str (" interface
: ");
2584 Write_Line (Get_Name_String (Source.Path.Name));
2594 Project_2 := Project_2.Extends;
2597 if Source = No_Source then
2598 Error_Msg_File_1 := File_Name_Type (Element.Value);
2599 Error_Msg_Name_1 := Project.Name;
2603 "{ cannot be an interface
of project
%% "
2604 & "as it
is not one
of its sources
",
2605 Element.Location, Project);
2608 List := Element.Next;
2611 Project.Interfaces_Defined := True;
2613 elsif Project.Library and then not Library_Interface.Default then
2615 -- Set In_Interfaces to False for all sources. It will be set to True
2616 -- later for the sources in the Library_Interface list.
2618 Project_2 := Project;
2619 while Project_2 /= No_Project loop
2620 Iter := For_Each_Source (Data.Tree, Project_2);
2622 Source := Prj.Element (Iter);
2623 exit when Source = No_Source;
2624 Source.In_Interfaces := False;
2628 Project_2 := Project_2.Extends;
2631 List := Library_Interface.Values;
2632 while List /= Nil_String loop
2633 Element := Data.Tree.String_Elements.Table (List);
2634 Get_Name_String (Element.Value);
2635 To_Lower (Name_Buffer (1 .. Name_Len));
2638 Project_2 := Project;
2640 while Project_2 /= No_Project loop
2641 Iter := For_Each_Source (Data.Tree, Project_2);
2644 Source := Prj.Element (Iter);
2645 exit when Source = No_Source;
2647 if Source.Unit /= No_Unit_Index and then
2648 Source.Unit.Name = Name_Id (Name)
2650 if not Source.Locally_Removed then
2651 Source.In_Interfaces := True;
2652 Source.Declared_In_Interfaces := True;
2654 Other := Other_Part (Source);
2656 if Other /= No_Source then
2657 Other.In_Interfaces := True;
2658 Other.Declared_In_Interfaces := True;
2661 if Current_Verbosity = High then
2662 Write_Str (" interface
: ");
2663 Write_Line (Get_Name_String (Source.Path.Name));
2673 Project_2 := Project_2.Extends;
2674 end loop Big_Loop_2;
2676 List := Element.Next;
2679 Project.Interfaces_Defined := True;
2681 elsif Project.Extends /= No_Project
2682 and then Project.Extends.Interfaces_Defined
2684 Project.Interfaces_Defined := True;
2686 Iter := For_Each_Source (Data.Tree, Project);
2688 Source := Prj.Element (Iter);
2689 exit when Source = No_Source;
2691 if not Source.Declared_In_Interfaces then
2692 Source.In_Interfaces := False;
2698 end Check_Interfaces;
2700 --------------------------
2701 -- Check_Package_Naming --
2702 --------------------------
2704 procedure Check_Package_Naming
2705 (Project : Project_Id;
2706 Data : in out Tree_Processing_Data;
2707 Bodies : out Array_Element_Id;
2708 Specs : out Array_Element_Id)
2710 Naming_Id : constant Package_Id :=
2712 (Name_Naming, Project.Decl.Packages, Data.Tree);
2713 Naming : Package_Element;
2715 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2717 procedure Check_Naming;
2718 -- Check the validity of the Naming package (suffixes valid, ...)
2720 procedure Check_Common
2721 (Dot_Replacement : in out File_Name_Type;
2722 Casing : in out Casing_Type;
2723 Casing_Defined : out Boolean;
2724 Separate_Suffix : in out File_Name_Type;
2725 Sep_Suffix_Loc : out Source_Ptr);
2726 -- Check attributes common
2728 procedure Process_Exceptions_File_Based
2729 (Lang_Id : Language_Ptr;
2730 Kind : Source_Kind);
2731 procedure Process_Exceptions_Unit_Based
2732 (Lang_Id : Language_Ptr;
2733 Kind : Source_Kind);
2734 -- Process the naming exceptions for the two types of languages
2736 procedure Initialize_Naming_Data;
2737 -- Initialize internal naming data for the various languages
2743 procedure Check_Common
2744 (Dot_Replacement : in out File_Name_Type;
2745 Casing : in out Casing_Type;
2746 Casing_Defined : out Boolean;
2747 Separate_Suffix : in out File_Name_Type;
2748 Sep_Suffix_Loc : out Source_Ptr)
2750 Dot_Repl : constant Variable_Value :=
2752 (Name_Dot_Replacement,
2753 Naming.Decl.Attributes,
2755 Casing_String : constant Variable_Value :=
2758 Naming.Decl.Attributes,
2760 Sep_Suffix : constant Variable_Value :=
2762 (Name_Separate_Suffix,
2763 Naming.Decl.Attributes,
2765 Dot_Repl_Loc : Source_Ptr;
2768 Sep_Suffix_Loc := No_Location;
2770 if not Dot_Repl.Default then
2772 (Dot_Repl.Kind = Single, "Dot_Replacement
is not a
string");
2774 if Length_Of_Name (Dot_Repl.Value) = 0 then
2776 (Data.Flags, "Dot_Replacement cannot be empty
",
2777 Dot_Repl.Location, Project);
2780 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2781 Dot_Repl_Loc := Dot_Repl.Location;
2784 Repl : constant String := Get_Name_String (Dot_Replacement);
2787 -- Dot_Replacement cannot
2789 -- - start or end with an alphanumeric
2790 -- - be a single '_'
2791 -- - start with an '_' followed by an alphanumeric
2792 -- - contain a '.' except if it is "."
2795 or else Is_Alphanumeric (Repl (Repl'First))
2796 or else Is_Alphanumeric (Repl (Repl'Last))
2797 or else (Repl (Repl'First) = '_'
2801 Is_Alphanumeric (Repl (Repl'First + 1))))
2802 or else (Repl'Length > 1
2804 Index (Source => Repl, Pattern => ".") /= 0)
2809 """ is illegal for Dot_Replacement.",
2810 Dot_Repl_Loc, Project);
2815 if Dot_Replacement /= No_File then
2817 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2820 Casing_Defined := False;
2822 if not Casing_String.Default then
2824 (Casing_String.Kind = Single, "Casing is not a string");
2827 Casing_Image : constant String :=
2828 Get_Name_String (Casing_String.Value);
2831 if Casing_Image'Length = 0 then
2834 "Casing cannot be an empty string",
2835 Casing_String.Location, Project);
2838 Casing := Value (Casing_Image);
2839 Casing_Defined := True;
2842 when Constraint_Error =>
2843 Name_Len := Casing_Image'Length;
2844 Name_Buffer (1 .. Name_Len) := Casing_Image;
2845 Err_Vars.Error_Msg_Name_1 := Name_Find;
2848 "%% is not a correct Casing",
2849 Casing_String.Location, Project);
2853 Write_Attr ("Casing", Image (Casing));
2855 if not Sep_Suffix.Default then
2856 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2859 "Separate_Suffix cannot be empty",
2860 Sep_Suffix.Location, Project);
2863 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2864 Sep_Suffix_Loc := Sep_Suffix.Location;
2866 Check_Illegal_Suffix
2867 (Project, Separate_Suffix,
2868 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
2873 if Separate_Suffix /= No_File then
2875 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2879 -----------------------------------
2880 -- Process_Exceptions_File_Based --
2881 -----------------------------------
2883 procedure Process_Exceptions_File_Based
2884 (Lang_Id : Language_Ptr;
2887 Lang : constant Name_Id := Lang_Id.Name;
2888 Exceptions : Array_Element_Id;
2889 Exception_List : Variable_Value;
2890 Element_Id : String_List_Id;
2891 Element : String_Element;
2892 File_Name : File_Name_Type;
2894 Iter : Source_Iterator;
2901 (Name_Implementation_Exceptions,
2902 In_Arrays => Naming.Decl.Arrays,
2903 In_Tree => Data.Tree);
2908 (Name_Specification_Exceptions,
2909 In_Arrays => Naming.Decl.Arrays,
2910 In_Tree => Data.Tree);
2913 Exception_List := Value_Of
2915 In_Array => Exceptions,
2916 In_Tree => Data.Tree);
2918 if Exception_List /= Nil_Variable_Value then
2919 Element_Id := Exception_List.Values;
2920 while Element_Id /= Nil_String loop
2921 Element := Data.Tree.String_Elements.Table (Element_Id);
2922 File_Name := Canonical_Case_File_Name (Element.Value);
2924 Iter := For_Each_Source (Data.Tree, Project);
2926 Source := Prj.Element (Iter);
2927 exit when Source = No_Source or else Source.File = File_Name;
2931 if Source = No_Source then
2936 Source_Dir_Rank => 0,
2939 File_Name => File_Name,
2940 Display_File => File_Name_Type (Element.Value),
2941 Naming_Exception => True);
2944 -- Check if the file name is already recorded for another
2945 -- language or another kind.
2947 if Source.Language /= Lang_Id then
2950 "the same file cannot be a source of two languages",
2951 Element.Location, Project);
2953 elsif Source.Kind /= Kind then
2956 "the same file cannot be a source and a template",
2957 Element.Location, Project);
2960 -- If the file is already recorded for the same
2961 -- language and the same kind, it means that the file
2962 -- name appears several times in the *_Exceptions
2963 -- attribute; so there is nothing to do.
2966 Element_Id := Element.Next;
2969 end Process_Exceptions_File_Based;
2971 -----------------------------------
2972 -- Process_Exceptions_Unit_Based --
2973 -----------------------------------
2975 procedure Process_Exceptions_Unit_Based
2976 (Lang_Id : Language_Ptr;
2979 Lang : constant Name_Id := Lang_Id.Name;
2980 Exceptions : Array_Element_Id;
2981 Element : Array_Element;
2984 File_Name : File_Name_Type;
2993 In_Arrays => Naming.Decl.Arrays,
2994 In_Tree => Data.Tree);
2996 if Exceptions = No_Array_Element then
2999 (Name_Implementation,
3000 In_Arrays => Naming.Decl.Arrays,
3001 In_Tree => Data.Tree);
3008 In_Arrays => Naming.Decl.Arrays,
3009 In_Tree => Data.Tree);
3011 if Exceptions = No_Array_Element then
3015 In_Arrays => Naming.Decl.Arrays,
3016 In_Tree => Data.Tree);
3020 while Exceptions /= No_Array_Element loop
3021 Element := Data.Tree.Array_Elements.Table (Exceptions);
3022 File_Name := Canonical_Case_File_Name (Element.Value.Value);
3024 Get_Name_String (Element.Index);
3025 To_Lower (Name_Buffer (1 .. Name_Len));
3027 Index := Element.Value.Index;
3029 -- For Ada, check if it is a valid unit name
3031 if Lang = Name_Ada then
3032 Get_Name_String (Element.Index);
3033 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
3035 if Unit = No_Name then
3036 Err_Vars.Error_Msg_Name_1 := Element.Index;
3039 "%% is not a valid unit name.",
3040 Element.Value.Location, Project);
3044 if Unit /= No_Name then
3049 Source_Dir_Rank => 0,
3052 File_Name => File_Name,
3053 Display_File => File_Name_Type (Element.Value.Value),
3056 Location => Element.Value.Location,
3057 Naming_Exception => True);
3060 Exceptions := Element.Next;
3062 end Process_Exceptions_Unit_Based;
3068 procedure Check_Naming is
3069 Dot_Replacement : File_Name_Type :=
3071 (First_Name_Id + Character'Pos ('-'));
3072 Separate_Suffix : File_Name_Type := No_File;
3073 Casing : Casing_Type := All_Lower_Case;
3074 Casing_Defined : Boolean;
3075 Lang_Id : Language_Ptr;
3076 Sep_Suffix_Loc : Source_Ptr;
3077 Suffix : Variable_Value;
3082 (Dot_Replacement => Dot_Replacement,
3084 Casing_Defined => Casing_Defined,
3085 Separate_Suffix => Separate_Suffix,
3086 Sep_Suffix_Loc => Sep_Suffix_Loc);
3088 -- For all unit based languages, if any, set the specified value
3089 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3090 -- systematically overwrite, since the defaults come from the
3091 -- configuration file.
3093 if Dot_Replacement /= No_File
3094 or else Casing_Defined
3095 or else Separate_Suffix /= No_File
3097 Lang_Id := Project.Languages;
3098 while Lang_Id /= No_Language_Index loop
3099 if Lang_Id.Config.Kind = Unit_Based then
3100 if Dot_Replacement /= No_File then
3101 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3105 if Casing_Defined then
3106 Lang_Id.Config.Naming_Data.Casing := Casing;
3110 Lang_Id := Lang_Id.Next;
3114 -- Next, get the spec and body suffixes
3116 Lang_Id := Project.Languages;
3117 while Lang_Id /= No_Language_Index loop
3118 Lang := Lang_Id.Name;
3124 Attribute_Or_Array_Name => Name_Spec_Suffix,
3125 In_Package => Naming_Id,
3126 In_Tree => Data.Tree);
3128 if Suffix = Nil_Variable_Value then
3131 Attribute_Or_Array_Name => Name_Specification_Suffix,
3132 In_Package => Naming_Id,
3133 In_Tree => Data.Tree);
3136 if Suffix /= Nil_Variable_Value then
3137 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3138 File_Name_Type (Suffix.Value);
3140 Check_Illegal_Suffix
3142 Lang_Id.Config.Naming_Data.Spec_Suffix,
3143 Lang_Id.Config.Naming_Data.Dot_Replacement,
3144 "Spec_Suffix", Suffix.Location, Data);
3148 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3156 Attribute_Or_Array_Name => Name_Body_Suffix,
3157 In_Package => Naming_Id,
3158 In_Tree => Data.Tree);
3160 if Suffix = Nil_Variable_Value then
3164 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3165 In_Package => Naming_Id,
3166 In_Tree => Data.Tree);
3169 if Suffix /= Nil_Variable_Value then
3170 Lang_Id.Config.Naming_Data.Body_Suffix :=
3171 File_Name_Type (Suffix.Value);
3173 -- The default value of separate suffix should be the same as
3174 -- the body suffix, so we need to compute that first.
3176 if Separate_Suffix = No_File then
3177 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3178 Lang_Id.Config.Naming_Data.Body_Suffix;
3182 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3184 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3188 Check_Illegal_Suffix
3190 Lang_Id.Config.Naming_Data.Body_Suffix,
3191 Lang_Id.Config.Naming_Data.Dot_Replacement,
3192 "Body_Suffix", Suffix.Location, Data);
3196 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3198 elsif Separate_Suffix /= No_File then
3199 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3202 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3203 -- since that would cause a clear ambiguity. Note that we do allow
3204 -- a Spec_Suffix to have the same termination as one of these,
3205 -- which causes a potential ambiguity, but we resolve that my
3206 -- matching the longest possible suffix.
3208 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3209 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3210 Lang_Id.Config.Naming_Data.Body_Suffix
3215 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3216 & """) cannot be the same as Spec_Suffix.",
3217 Ada_Body_Suffix_Loc, Project);
3220 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3221 Lang_Id.Config.Naming_Data.Separate_Suffix
3222 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3223 Lang_Id.Config.Naming_Data.Separate_Suffix
3227 "Separate_Suffix ("""
3229 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3230 & """) cannot be the same as Spec_Suffix.",
3231 Sep_Suffix_Loc, Project);
3234 Lang_Id := Lang_Id.Next;
3237 -- Get the naming exceptions for all languages
3239 for Kind in Spec .. Impl loop
3240 Lang_Id := Project.Languages;
3241 while Lang_Id /= No_Language_Index loop
3242 case Lang_Id.Config.Kind is
3244 Process_Exceptions_File_Based (Lang_Id, Kind);
3247 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3250 Lang_Id := Lang_Id.Next;
3255 ----------------------------
3256 -- Initialize_Naming_Data --
3257 ----------------------------
3259 procedure Initialize_Naming_Data is
3260 Specs : Array_Element_Id :=
3266 Impls : Array_Element_Id :=
3272 Lang : Language_Ptr;
3273 Lang_Name : Name_Id;
3274 Value : Variable_Value;
3275 Extended : Project_Id;
3278 -- At this stage, the project already contains the default extensions
3279 -- for the various languages. We now merge those suffixes read in the
3280 -- user project, and they override the default.
3282 while Specs /= No_Array_Element loop
3283 Lang_Name := Data.Tree.Array_Elements.Table (Specs).Index;
3285 Get_Language_From_Name
3286 (Project, Name => Get_Name_String (Lang_Name));
3288 -- An extending project inherits its parent projects' languages
3289 -- so if needed we should create entries for those languages
3292 Extended
:= Project
.Extends
;
3293 while Extended
/= null loop
3294 Lang
:= Get_Language_From_Name
3295 (Extended
, Name
=> Get_Name_String
(Lang_Name
));
3296 exit when Lang
/= null;
3298 Extended
:= Extended
.Extends
;
3301 if Lang
/= null then
3302 Lang
:= new Language_Data
'(Lang.all);
3303 Lang.First_Source := null;
3304 Lang.Next := Project.Languages;
3305 Project.Languages := Lang;
3309 -- If language was not found in project or the projects it extends
3312 if Current_Verbosity = High then
3314 ("Ignoring spec naming data for "
3315 & Get_Name_String (Lang_Name)
3316 & " since language is not defined for this project");
3320 Value := Data.Tree.Array_Elements.Table (Specs).Value;
3322 if Value.Kind = Single then
3323 Lang.Config.Naming_Data.Spec_Suffix :=
3324 Canonical_Case_File_Name (Value.Value);
3328 Specs := Data.Tree.Array_Elements.Table (Specs).Next;
3331 while Impls /= No_Array_Element loop
3332 Lang_Name := Data.Tree.Array_Elements.Table (Impls).Index;
3334 Get_Language_From_Name
3335 (Project, Name => Get_Name_String (Lang_Name));
3338 if Current_Verbosity = High then
3340 ("Ignoring impl naming data for "
3341 & Get_Name_String (Lang_Name)
3342 & " since language is not defined for this project");
3345 Value := Data.Tree.Array_Elements.Table (Impls).Value;
3347 if Lang.Name = Name_Ada then
3348 Ada_Body_Suffix_Loc := Value.Location;
3351 if Value.Kind = Single then
3352 Lang.Config.Naming_Data.Body_Suffix :=
3353 Canonical_Case_File_Name (Value.Value);
3357 Impls := Data.Tree.Array_Elements.Table (Impls).Next;
3359 end Initialize_Naming_Data;
3361 -- Start of processing for Check_Naming_Schemes
3364 Specs := No_Array_Element;
3365 Bodies := No_Array_Element;
3367 -- No Naming package or parsing a configuration file? nothing to do
3369 if Naming_Id /= No_Package
3370 and then Project.Qualifier /= Configuration
3372 Naming := Data.Tree.Packages.Table (Naming_Id);
3374 if Current_Verbosity = High then
3375 Write_Line ("Checking package Naming for project "
3376 & Get_Name_String (Project.Name));
3379 Initialize_Naming_Data;
3382 end Check_Package_Naming;
3384 ------------------------------
3385 -- Check_Library_Attributes --
3386 ------------------------------
3388 procedure Check_Library_Attributes
3389 (Project : Project_Id;
3390 Data : in out Tree_Processing_Data)
3392 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3394 Lib_Dir : constant Prj.Variable_Value :=
3396 (Snames.Name_Library_Dir, Attributes, Data.Tree);
3398 Lib_Name : constant Prj.Variable_Value :=
3400 (Snames.Name_Library_Name, Attributes, Data.Tree);
3402 Lib_Version : constant Prj.Variable_Value :=
3404 (Snames.Name_Library_Version, Attributes, Data.Tree);
3406 Lib_ALI_Dir : constant Prj.Variable_Value :=
3408 (Snames.Name_Library_Ali_Dir, Attributes, Data.Tree);
3410 Lib_GCC : constant Prj.Variable_Value :=
3412 (Snames.Name_Library_GCC, Attributes, Data.Tree);
3414 The_Lib_Kind : constant Prj.Variable_Value :=
3416 (Snames.Name_Library_Kind, Attributes, Data.Tree);
3418 Imported_Project_List : Project_List;
3420 Continuation : String_Access := No_Continuation_String'Access;
3422 Support_For_Libraries : Library_Support;
3424 Library_Directory_Present : Boolean;
3426 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3427 -- Check if an imported or extended project if also a library project
3433 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3435 Iter : Source_Iterator;
3438 if Proj /= No_Project then
3439 if not Proj.Library then
3441 -- The only not library projects that are OK are those that
3442 -- have no sources. However, header files from non-Ada
3443 -- languages are OK, as there is nothing to compile.
3445 Iter := For_Each_Source (Data.Tree, Proj);
3447 Src_Id := Prj.Element (Iter);
3448 exit when Src_Id = No_Source
3449 or else Src_Id.Language.Config.Kind /= File_Based
3450 or else Src_Id.Kind /= Spec;
3454 if Src_Id /= No_Source then
3455 Error_Msg_Name_1 := Project.Name;
3456 Error_Msg_Name_2 := Proj.Name;
3459 if Project.Library_Kind /= Static then
3463 "shared library project %% cannot extend " &
3464 "project %% that is not a library project",
3465 Project.Location, Project);
3466 Continuation := Continuation_String'Access;
3469 elsif (not Unchecked_Shared_Lib_Imports)
3470 and then Project.Library_Kind /= Static
3475 "shared library project %% cannot import project %% " &
3476 "that is not a shared library project",
3477 Project.Location, Project);
3478 Continuation := Continuation_String'Access;
3482 elsif Project.Library_Kind /= Static and then
3483 Proj.Library_Kind = Static
3485 Error_Msg_Name_1 := Project.Name;
3486 Error_Msg_Name_2 := Proj.Name;
3492 "shared library project %% cannot extend static " &
3493 "library project %%",
3494 Project.Location, Project);
3495 Continuation := Continuation_String'Access;
3497 elsif not Unchecked_Shared_Lib_Imports then
3501 "shared library project %% cannot import static " &
3502 "library project %%",
3503 Project.Location, Project);
3504 Continuation := Continuation_String'Access;
3511 Dir_Exists : Boolean;
3513 -- Start of processing for Check_Library_Attributes
3516 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3518 -- Special case of extending project
3520 if Project.Extends /= No_Project then
3522 -- If the project extended is a library project, we inherit the
3523 -- library name, if it is not redefined; we check that the library
3524 -- directory is specified.
3526 if Project.Extends.Library then
3527 if Project.Qualifier = Standard then
3530 "a standard project cannot extend a library project",
3531 Project.Location, Project);
3534 if Lib_Name.Default then
3535 Project.Library_Name := Project.Extends.Library_Name;
3538 if Lib_Dir.Default then
3539 if not Project.Virtual then
3542 "a project extending a library project must " &
3543 "specify an attribute Library_Dir",
3544 Project.Location, Project);
3547 -- For a virtual project extending a library project,
3548 -- inherit library directory.
3550 Project.Library_Dir := Project.Extends.Library_Dir;
3551 Library_Directory_Present := True;
3558 pragma Assert (Lib_Name.Kind = Single);
3560 if Lib_Name.Value = Empty_String then
3561 if Current_Verbosity = High
3562 and then Project.Library_Name = No_Name
3564 Write_Line ("No library name");
3568 -- There is no restriction on the syntax of library names
3570 Project.Library_Name := Lib_Name.Value;
3573 if Project.Library_Name /= No_Name then
3574 if Current_Verbosity = High then
3576 ("Library name", Get_Name_String (Project.Library_Name));
3579 pragma Assert (Lib_Dir.Kind = Single);
3581 if not Library_Directory_Present then
3582 if Current_Verbosity = High then
3583 Write_Line ("No library directory");
3587 -- Find path name (unless inherited), check that it is a directory
3589 if Project.Library_Dir = No_Path_Information then
3592 File_Name_Type (Lib_Dir.Value),
3593 Path => Project.Library_Dir,
3594 Dir_Exists => Dir_Exists,
3596 Create => "library",
3597 Must_Exist => False,
3598 Location => Lib_Dir.Location,
3599 Externally_Built => Project.Externally_Built);
3605 (Project.Library_Dir.Display_Name));
3608 if not Dir_Exists then
3610 -- Get the absolute name of the library directory that
3611 -- does not exist, to report an error.
3613 Err_Vars.Error_Msg_File_1 :=
3614 File_Name_Type (Project.Library_Dir.Display_Name);
3617 "library directory { does not exist",
3618 Lib_Dir.Location, Project);
3620 -- The library directory cannot be the same as the Object
3623 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3626 "library directory cannot be the same " &
3627 "as object directory",
3628 Lib_Dir.Location, Project);
3629 Project.Library_Dir := No_Path_Information;
3633 OK : Boolean := True;
3634 Dirs_Id : String_List_Id;
3635 Dir_Elem : String_Element;
3639 -- The library directory cannot be the same as a source
3640 -- directory of the current project.
3642 Dirs_Id := Project.Source_Dirs;
3643 while Dirs_Id /= Nil_String loop
3644 Dir_Elem := Data.Tree.String_Elements.Table (Dirs_Id);
3645 Dirs_Id := Dir_Elem.Next;
3647 if Project.Library_Dir.Name =
3648 Path_Name_Type (Dir_Elem.Value)
3650 Err_Vars.Error_Msg_File_1 :=
3651 File_Name_Type (Dir_Elem.Value);
3654 "library directory cannot be the same " &
3655 "as source directory {",
3656 Lib_Dir.Location, Project);
3664 -- The library directory cannot be the same as a source
3665 -- directory of another project either.
3667 Pid := Data.Tree.Projects;
3669 exit Project_Loop when Pid = null;
3671 if Pid.Project /= Project then
3672 Dirs_Id := Pid.Project.Source_Dirs;
3674 Dir_Loop : while Dirs_Id /= Nil_String loop
3676 Data.Tree.String_Elements.Table (Dirs_Id);
3677 Dirs_Id := Dir_Elem.Next;
3679 if Project.Library_Dir.Name =
3680 Path_Name_Type (Dir_Elem.Value)
3682 Err_Vars.Error_Msg_File_1 :=
3683 File_Name_Type (Dir_Elem.Value);
3684 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3688 "library directory cannot be the same " &
3689 "as source directory { of project %%",
3690 Lib_Dir.Location, Project);
3698 end loop Project_Loop;
3702 Project.Library_Dir := No_Path_Information;
3704 elsif Current_Verbosity = High then
3706 -- Display the Library directory in high verbosity
3709 ("Library directory",
3710 Get_Name_String (Project.Library_Dir.Display_Name));
3719 Project.Library_Dir /= No_Path_Information
3720 and then Project.Library_Name /= No_Name;
3722 if Project.Extends = No_Project then
3723 case Project.Qualifier is
3725 if Project.Library then
3728 "a standard project cannot be a library project",
3729 Lib_Name.Location, Project);
3733 if not Project.Library then
3734 if Project.Library_Dir = No_Path_Information then
3737 "\attribute Library_Dir not declared",
3738 Project.Location, Project);
3741 if Project.Library_Name = No_Name then
3744 "\attribute Library_Name not declared",
3745 Project.Location, Project);
3755 if Project.Library then
3756 Support_For_Libraries := Project.Config.Lib_Support;
3758 if Support_For_Libraries = Prj.None then
3761 "?libraries are not supported on this platform",
3762 Lib_Name.Location, Project);
3763 Project.Library := False;
3766 if Lib_ALI_Dir.Value = Empty_String then
3767 if Current_Verbosity = High then
3768 Write_Line ("No library ALI directory specified");
3771 Project.Library_ALI_Dir := Project.Library_Dir;
3774 -- Find path name, check that it is a directory
3778 File_Name_Type (Lib_ALI_Dir.Value),
3779 Path => Project.Library_ALI_Dir,
3780 Create => "library ALI",
3781 Dir_Exists => Dir_Exists,
3783 Must_Exist => False,
3784 Location => Lib_ALI_Dir.Location,
3785 Externally_Built => Project.Externally_Built);
3787 if not Dir_Exists then
3789 -- Get the absolute name of the library ALI directory that
3790 -- does not exist, to report an error.
3792 Err_Vars.Error_Msg_File_1 :=
3793 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3796 "library 'A
'L'I directory { does not exist",
3797 Lib_ALI_Dir.Location, Project);
3800 if Project.Library_ALI_Dir /= Project.Library_Dir then
3802 -- The library ALI directory cannot be the same as the
3803 -- Object directory.
3805 if Project.Library_ALI_Dir = Project.Object_Directory then
3808 "library 'A
'L'I directory cannot be the same " &
3809 "as object directory",
3810 Lib_ALI_Dir.Location, Project);
3811 Project.Library_ALI_Dir := No_Path_Information;
3815 OK : Boolean := True;
3816 Dirs_Id : String_List_Id;
3817 Dir_Elem : String_Element;
3821 -- The library ALI directory cannot be the same as
3822 -- a source directory of the current project.
3824 Dirs_Id := Project.Source_Dirs;
3825 while Dirs_Id /= Nil_String loop
3827 Data.Tree.String_Elements.Table (Dirs_Id);
3828 Dirs_Id := Dir_Elem.Next;
3830 if Project.Library_ALI_Dir.Name =
3831 Path_Name_Type (Dir_Elem.Value)
3833 Err_Vars.Error_Msg_File_1 :=
3834 File_Name_Type (Dir_Elem.Value);
3837 "library 'A
'L'I directory cannot be " &
3838 "the same as source directory {",
3839 Lib_ALI_Dir.Location, Project);
3847 -- The library ALI directory cannot be the same as
3848 -- a source directory of another project either.
3850 Pid := Data.Tree.Projects;
3851 ALI_Project_Loop : loop
3852 exit ALI_Project_Loop when Pid = null;
3854 if Pid.Project /= Project then
3855 Dirs_Id := Pid.Project.Source_Dirs;
3858 while Dirs_Id /= Nil_String loop
3860 Data.Tree.String_Elements.Table
3862 Dirs_Id := Dir_Elem.Next;
3864 if Project.Library_ALI_Dir.Name =
3865 Path_Name_Type (Dir_Elem.Value)
3867 Err_Vars.Error_Msg_File_1 :=
3868 File_Name_Type (Dir_Elem.Value);
3869 Err_Vars.Error_Msg_Name_1 :=
3874 "library 'A
'L'I directory cannot " &
3875 "be the same as source directory " &
3877 Lib_ALI_Dir.Location, Project);
3879 exit ALI_Project_Loop;
3881 end loop ALI_Dir_Loop;
3884 end loop ALI_Project_Loop;
3888 Project.Library_ALI_Dir := No_Path_Information;
3890 elsif Current_Verbosity = High then
3892 -- Display Library ALI directory in high verbosity
3897 (Project.Library_ALI_Dir.Display_Name));
3904 pragma Assert (Lib_Version.Kind = Single);
3906 if Lib_Version.Value = Empty_String then
3907 if Current_Verbosity = High then
3908 Write_Line ("No library version specified");
3912 Project.Lib_Internal_Name := Lib_Version.Value;
3915 pragma Assert (The_Lib_Kind.Kind = Single);
3917 if The_Lib_Kind.Value = Empty_String then
3918 if Current_Verbosity = High then
3919 Write_Line ("No library kind specified");
3923 Get_Name_String (The_Lib_Kind.Value);
3926 Kind_Name : constant String :=
3927 To_Lower (Name_Buffer (1 .. Name_Len));
3929 OK : Boolean := True;
3932 if Kind_Name = "static" then
3933 Project.Library_Kind := Static;
3935 elsif Kind_Name = "dynamic" then
3936 Project.Library_Kind := Dynamic;
3938 elsif Kind_Name = "relocatable" then
3939 Project.Library_Kind := Relocatable;
3944 "illegal value for Library_Kind",
3945 The_Lib_Kind.Location, Project);
3949 if Current_Verbosity = High and then OK then
3950 Write_Attr ("Library kind", Kind_Name);
3953 if Project.Library_Kind /= Static then
3954 if Support_For_Libraries = Prj.Static_Only then
3957 "only static libraries are supported " &
3959 The_Lib_Kind.Location, Project);
3960 Project.Library := False;
3963 -- Check if (obsolescent) attribute Library_GCC or
3964 -- Linker'Driver is declared.
3966 if Lib_GCC.Value /= Empty_String then
3969 "?Library_'G'C
'C is an obsolescent attribute
, " &
3970 "use Linker
''Driver instead
",
3971 Lib_GCC.Location, Project);
3972 Project.Config.Shared_Lib_Driver :=
3973 File_Name_Type (Lib_GCC.Value);
3977 Linker : constant Package_Id :=
3980 Project.Decl.Packages,
3982 Driver : constant Variable_Value :=
3985 Attribute_Or_Array_Name =>
3987 In_Package => Linker,
3988 In_Tree => Data.Tree);
3991 if Driver /= Nil_Variable_Value
3992 and then Driver.Value /= Empty_String
3994 Project.Config.Shared_Lib_Driver :=
3995 File_Name_Type (Driver.Value);
4004 if Project.Library then
4005 if Current_Verbosity = High then
4006 Write_Line ("This
is a library project file
");
4009 Check_Library (Project.Extends, Extends => True);
4011 Imported_Project_List := Project.Imported_Projects;
4012 while Imported_Project_List /= null loop
4014 (Imported_Project_List.Project,
4016 Imported_Project_List := Imported_Project_List.Next;
4023 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4024 -- Warn if they are declared, as it is a common error to think that
4025 -- library are "linked
" with Linker switches.
4027 if Project.Library then
4029 Linker_Package_Id : constant Package_Id :=
4032 Project.Decl.Packages, Data.Tree);
4033 Linker_Package : Package_Element;
4034 Switches : Array_Element_Id := No_Array_Element;
4037 if Linker_Package_Id /= No_Package then
4038 Linker_Package := Data.Tree.Packages.Table (Linker_Package_Id);
4042 (Name => Name_Switches,
4043 In_Arrays => Linker_Package.Decl.Arrays,
4044 In_Tree => Data.Tree);
4046 if Switches = No_Array_Element then
4049 (Name => Name_Default_Switches,
4050 In_Arrays => Linker_Package.Decl.Arrays,
4051 In_Tree => Data.Tree);
4054 if Switches /= No_Array_Element then
4057 "?Linker switches
not taken into account
in library
" &
4059 No_Location, Project);
4065 if Project.Extends /= No_Project then
4066 Project.Extends.Library := False;
4068 end Check_Library_Attributes;
4070 ---------------------------------
4071 -- Check_Programming_Languages --
4072 ---------------------------------
4074 procedure Check_Programming_Languages
4075 (Project : Project_Id;
4076 Data : in out Tree_Processing_Data)
4078 Languages : Variable_Value := Nil_Variable_Value;
4079 Def_Lang : Variable_Value := Nil_Variable_Value;
4080 Def_Lang_Id : Name_Id;
4082 procedure Add_Language (Name, Display_Name : Name_Id);
4083 -- Add a new language to the list of languages for the project.
4084 -- Nothing is done if the language has already been defined
4090 procedure Add_Language (Name, Display_Name : Name_Id) is
4091 Lang : Language_Ptr;
4094 Lang := Project.Languages;
4095 while Lang /= No_Language_Index loop
4096 if Name = Lang.Name then
4103 Lang := new Language_Data'(No_Language_Data);
4104 Lang.Next := Project.Languages;
4105 Project.Languages := Lang;
4107 Lang.Display_Name := Display_Name;
4109 if Name = Name_Ada then
4110 Lang.Config.Kind := Unit_Based;
4111 Lang.Config.Dependency_Kind := ALI_File;
4113 Lang.Config.Kind := File_Based;
4117 -- Start of processing for Check_Programming_Languages
4120 Project.Languages := null;
4122 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Data.Tree);
4125 (Name_Default_Language, Project.Decl.Attributes, Data.Tree);
4127 if Project.Source_Dirs /= Nil_String then
4129 -- Check if languages are specified in this project
4131 if Languages.Default then
4133 -- Fail if there is no default language defined
4135 if Def_Lang.Default then
4138 "no languages defined
for this project
",
4139 Project.Location, Project);
4140 Def_Lang_Id := No_Name;
4143 Get_Name_String (Def_Lang.Value);
4144 To_Lower (Name_Buffer (1 .. Name_Len));
4145 Def_Lang_Id := Name_Find;
4148 if Def_Lang_Id /= No_Name then
4149 Get_Name_String (Def_Lang_Id);
4150 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4152 (Name => Def_Lang_Id,
4153 Display_Name => Name_Find);
4158 Current : String_List_Id := Languages.Values;
4159 Element : String_Element;
4162 -- If there are no languages declared, there are no sources
4164 if Current = Nil_String then
4165 Project.Source_Dirs := Nil_String;
4167 if Project.Qualifier = Standard then
4170 "a standard project must have
at least one language
",
4171 Languages.Location, Project);
4175 -- Look through all the languages specified in attribute
4178 while Current /= Nil_String loop
4179 Element := Data.Tree.String_Elements.Table (Current);
4180 Get_Name_String (Element.Value);
4181 To_Lower (Name_Buffer (1 .. Name_Len));
4185 Display_Name => Element.Value);
4187 Current := Element.Next;
4193 end Check_Programming_Languages;
4195 -------------------------------
4196 -- Check_Stand_Alone_Library --
4197 -------------------------------
4199 procedure Check_Stand_Alone_Library
4200 (Project : Project_Id;
4201 Data : in out Tree_Processing_Data)
4203 Lib_Interfaces : constant Prj.Variable_Value :=
4205 (Snames.Name_Library_Interface,
4206 Project.Decl.Attributes,
4209 Lib_Auto_Init : constant Prj.Variable_Value :=
4211 (Snames.Name_Library_Auto_Init,
4212 Project.Decl.Attributes,
4215 Lib_Src_Dir : constant Prj.Variable_Value :=
4217 (Snames.Name_Library_Src_Dir,
4218 Project.Decl.Attributes,
4221 Lib_Symbol_File : constant Prj.Variable_Value :=
4223 (Snames.Name_Library_Symbol_File,
4224 Project.Decl.Attributes,
4227 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4229 (Snames.Name_Library_Symbol_Policy,
4230 Project.Decl.Attributes,
4233 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4235 (Snames.Name_Library_Reference_Symbol_File,
4236 Project.Decl.Attributes,
4239 Auto_Init_Supported : Boolean;
4240 OK : Boolean := True;
4242 Next_Proj : Project_Id;
4243 Iter : Source_Iterator;
4246 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4248 pragma Assert (Lib_Interfaces.Kind = List);
4250 -- It is a stand-alone library project file if attribute
4251 -- Library_Interface is defined.
4253 if not Lib_Interfaces.Default then
4255 Interfaces : String_List_Id := Lib_Interfaces.Values;
4256 Interface_ALIs : String_List_Id := Nil_String;
4260 Project.Standalone_Library := True;
4262 -- Library_Interface cannot be an empty list
4264 if Interfaces = Nil_String then
4267 "Library_Interface cannot be an empty list
",
4268 Lib_Interfaces.Location, Project);
4271 -- Process each unit name specified in the attribute
4272 -- Library_Interface.
4274 while Interfaces /= Nil_String loop
4276 (Data.Tree.String_Elements.Table (Interfaces).Value);
4277 To_Lower (Name_Buffer (1 .. Name_Len));
4279 if Name_Len = 0 then
4282 "an interface cannot be an empty
string",
4283 Data.Tree.String_Elements.Table (Interfaces).Location,
4288 Error_Msg_Name_1 := Unit;
4290 Next_Proj := Project.Extends;
4291 Iter := For_Each_Source (Data.Tree, Project);
4293 while Prj.Element (Iter) /= No_Source
4295 (Prj.Element (Iter).Unit = null
4296 or else Prj.Element (Iter).Unit.Name /= Unit)
4301 Source := Prj.Element (Iter);
4302 exit when Source /= No_Source
4303 or else Next_Proj = No_Project;
4305 Iter := For_Each_Source (Data.Tree, Next_Proj);
4306 Next_Proj := Next_Proj.Extends;
4309 if Source /= No_Source then
4310 if Source.Kind = Sep then
4311 Source := No_Source;
4313 elsif Source.Kind = Spec
4314 and then Other_Part (Source) /= No_Source
4316 Source := Other_Part (Source);
4320 if Source /= No_Source then
4321 if Source.Project /= Project
4322 and then not Is_Extending (Project, Source.Project)
4324 Source := No_Source;
4328 if Source = No_Source then
4331 "%% is not a unit
of this project
",
4332 Data.Tree.String_Elements.Table
4333 (Interfaces).Location, Project);
4336 if Source.Kind = Spec
4337 and then Other_Part (Source) /= No_Source
4339 Source := Other_Part (Source);
4342 String_Element_Table.Increment_Last
4343 (Data.Tree.String_Elements);
4345 Data.Tree.String_Elements.Table
4346 (String_Element_Table.Last
4347 (Data.Tree.String_Elements)) :=
4348 (Value => Name_Id (Source.Dep_Name),
4350 Display_Value => Name_Id (Source.Dep_Name),
4352 Data.Tree.String_Elements.Table
4353 (Interfaces).Location,
4355 Next => Interface_ALIs);
4358 String_Element_Table.Last
4359 (Data.Tree.String_Elements);
4363 Interfaces := Data.Tree.String_Elements.Table (Interfaces).Next;
4366 -- Put the list of Interface ALIs in the project data
4368 Project.Lib_Interface_ALIs := Interface_ALIs;
4370 -- Check value of attribute Library_Auto_Init and set
4371 -- Lib_Auto_Init accordingly.
4373 if Lib_Auto_Init.Default then
4375 -- If no attribute Library_Auto_Init is declared, then set auto
4376 -- init only if it is supported.
4378 Project.Lib_Auto_Init := Auto_Init_Supported;
4381 Get_Name_String (Lib_Auto_Init.Value);
4382 To_Lower (Name_Buffer (1 .. Name_Len));
4384 if Name_Buffer (1 .. Name_Len) = "false" then
4385 Project.Lib_Auto_Init := False;
4387 elsif Name_Buffer (1 .. Name_Len) = "true" then
4388 if Auto_Init_Supported then
4389 Project.Lib_Auto_Init := True;
4392 -- Library_Auto_Init cannot be "true" if auto init is not
4397 "library auto init
not supported
" &
4399 Lib_Auto_Init.Location, Project);
4405 "invalid value
for attribute Library_Auto_Init
",
4406 Lib_Auto_Init.Location, Project);
4411 -- If attribute Library_Src_Dir is defined and not the empty string,
4412 -- check if the directory exist and is not the object directory or
4413 -- one of the source directories. This is the directory where copies
4414 -- of the interface sources will be copied. Note that this directory
4415 -- may be the library directory.
4417 if Lib_Src_Dir.Value /= Empty_String then
4419 Dir_Id : constant File_Name_Type :=
4420 File_Name_Type (Lib_Src_Dir.Value);
4421 Dir_Exists : Boolean;
4427 Path => Project.Library_Src_Dir,
4428 Dir_Exists => Dir_Exists,
4430 Must_Exist => False,
4431 Create => "library source copy
",
4432 Location => Lib_Src_Dir.Location,
4433 Externally_Built => Project.Externally_Built);
4435 -- If directory does not exist, report an error
4437 if not Dir_Exists then
4439 -- Get the absolute name of the library directory that does
4440 -- not exist, to report an error.
4442 Err_Vars.Error_Msg_File_1 :=
4443 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4446 "Directory
{ does
not exist
",
4447 Lib_Src_Dir.Location, Project);
4449 -- Report error if it is the same as the object directory
4451 elsif Project.Library_Src_Dir = Project.Object_Directory then
4454 "directory to copy interfaces cannot be
" &
4455 "the object directory
",
4456 Lib_Src_Dir.Location, Project);
4457 Project.Library_Src_Dir := No_Path_Information;
4461 Src_Dirs : String_List_Id;
4462 Src_Dir : String_Element;
4466 -- Interface copy directory cannot be one of the source
4467 -- directory of the current project.
4469 Src_Dirs := Project.Source_Dirs;
4470 while Src_Dirs /= Nil_String loop
4471 Src_Dir := Data.Tree.String_Elements.Table (Src_Dirs);
4473 -- Report error if it is one of the source directories
4475 if Project.Library_Src_Dir.Name =
4476 Path_Name_Type (Src_Dir.Value)
4480 "directory to copy interfaces cannot
" &
4481 "be one
of the source directories
",
4482 Lib_Src_Dir.Location, Project);
4483 Project.Library_Src_Dir := No_Path_Information;
4487 Src_Dirs := Src_Dir.Next;
4490 if Project.Library_Src_Dir /= No_Path_Information then
4492 -- It cannot be a source directory of any other
4495 Pid := Data.Tree.Projects;
4497 exit Project_Loop when Pid = null;
4499 Src_Dirs := Pid.Project.Source_Dirs;
4500 Dir_Loop : while Src_Dirs /= Nil_String loop
4502 Data.Tree.String_Elements.Table (Src_Dirs);
4504 -- Report error if it is one of the source
4507 if Project.Library_Src_Dir.Name =
4508 Path_Name_Type (Src_Dir.Value)
4511 File_Name_Type (Src_Dir.Value);
4512 Error_Msg_Name_1 := Pid.Project.Name;
4515 "directory to copy interfaces cannot
" &
4516 "be the same as source directory
{ of " &
4518 Lib_Src_Dir.Location, Project);
4519 Project.Library_Src_Dir :=
4520 No_Path_Information;
4524 Src_Dirs := Src_Dir.Next;
4528 end loop Project_Loop;
4532 -- In high verbosity, if there is a valid Library_Src_Dir,
4533 -- display its path name.
4535 if Project.Library_Src_Dir /= No_Path_Information
4536 and then Current_Verbosity = High
4539 ("Directory to copy interfaces
",
4540 Get_Name_String (Project.Library_Src_Dir.Name));
4546 -- Check the symbol related attributes
4548 -- First, the symbol policy
4550 if not Lib_Symbol_Policy.Default then
4552 Value : constant String :=
4554 (Get_Name_String (Lib_Symbol_Policy.Value));
4557 -- Symbol policy must hove one of a limited number of values
4559 if Value = "autonomous
" or else Value = "default
" then
4560 Project.Symbol_Data.Symbol_Policy := Autonomous;
4562 elsif Value = "compliant
" then
4563 Project.Symbol_Data.Symbol_Policy := Compliant;
4565 elsif Value = "controlled
" then
4566 Project.Symbol_Data.Symbol_Policy := Controlled;
4568 elsif Value = "restricted
" then
4569 Project.Symbol_Data.Symbol_Policy := Restricted;
4571 elsif Value = "direct
" then
4572 Project.Symbol_Data.Symbol_Policy := Direct;
4577 "illegal value
for Library_Symbol_Policy
",
4578 Lib_Symbol_Policy.Location, Project);
4583 -- If attribute Library_Symbol_File is not specified, symbol policy
4584 -- cannot be Restricted.
4586 if Lib_Symbol_File.Default then
4587 if Project.Symbol_Data.Symbol_Policy = Restricted then
4590 "Library_Symbol_File needs to be defined
when " &
4591 "symbol policy
is Restricted
",
4592 Lib_Symbol_Policy.Location, Project);
4596 -- Library_Symbol_File is defined
4598 Project.Symbol_Data.Symbol_File :=
4599 Path_Name_Type (Lib_Symbol_File.Value);
4601 Get_Name_String (Lib_Symbol_File.Value);
4603 if Name_Len = 0 then
4606 "symbol file name cannot be an empty
string",
4607 Lib_Symbol_File.Location, Project);
4610 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4613 for J in 1 .. Name_Len loop
4614 if Name_Buffer (J) = '/'
4615 or else Name_Buffer (J) = Directory_Separator
4624 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4627 "symbol file name
{ is illegal
. " &
4628 "Name cannot include directory info
.",
4629 Lib_Symbol_File.Location, Project);
4634 -- If attribute Library_Reference_Symbol_File is not defined,
4635 -- symbol policy cannot be Compliant or Controlled.
4637 if Lib_Ref_Symbol_File.Default then
4638 if Project.Symbol_Data.Symbol_Policy = Compliant
4639 or else Project.Symbol_Data.Symbol_Policy = Controlled
4643 "a reference symbol file needs to be defined
",
4644 Lib_Symbol_Policy.Location, Project);
4648 -- Library_Reference_Symbol_File is defined, check file exists
4650 Project.Symbol_Data.Reference :=
4651 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4653 Get_Name_String (Lib_Ref_Symbol_File.Value);
4655 if Name_Len = 0 then
4658 "reference symbol file name cannot be an empty
string",
4659 Lib_Symbol_File.Location, Project);
4662 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4664 Add_Str_To_Name_Buffer
4665 (Get_Name_String (Project.Directory.Name));
4666 Add_Str_To_Name_Buffer
4667 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4668 Project.Symbol_Data.Reference := Name_Find;
4671 if not Is_Regular_File
4672 (Get_Name_String (Project.Symbol_Data.Reference))
4675 File_Name_Type (Lib_Ref_Symbol_File.Value);
4677 -- For controlled and direct symbol policies, it is an error
4678 -- if the reference symbol file does not exist. For other
4679 -- symbol policies, this is just a warning
4682 Project.Symbol_Data.Symbol_Policy /= Controlled
4683 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4687 "<library reference symbol file
{ does
not exist
",
4688 Lib_Ref_Symbol_File.Location, Project);
4690 -- In addition in the non-controlled case, if symbol policy
4691 -- is Compliant, it is changed to Autonomous, because there
4692 -- is no reference to check against, and we don't want to
4693 -- fail in this case.
4695 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4696 if Project.Symbol_Data.Symbol_Policy = Compliant then
4697 Project.Symbol_Data.Symbol_Policy := Autonomous;
4702 -- If both the reference symbol file and the symbol file are
4703 -- defined, then check that they are not the same file.
4705 if Project.Symbol_Data.Symbol_File /= No_Path then
4706 Get_Name_String (Project.Symbol_Data.Symbol_File);
4708 if Name_Len > 0 then
4710 -- We do not need to pass a Directory to
4711 -- Normalize_Pathname, since the path_information
4712 -- already contains absolute information.
4714 Symb_Path : constant String :=
4717 (Project.Object_Directory.Name) &
4718 Name_Buffer (1 .. Name_Len),
4721 Opt.Follow_Links_For_Files);
4722 Ref_Path : constant String :=
4725 (Project.Symbol_Data.Reference),
4728 Opt.Follow_Links_For_Files);
4730 if Symb_Path = Ref_Path then
4733 "library reference symbol file
and library
" &
4734 " symbol file cannot be the same file
",
4735 Lib_Ref_Symbol_File.Location, Project);
4743 end Check_Stand_Alone_Library;
4745 ----------------------------
4746 -- Compute_Directory_Last --
4747 ----------------------------
4749 function Compute_Directory_Last (Dir : String) return Natural is
4752 and then (Dir (Dir'Last - 1) = Directory_Separator
4754 Dir (Dir'Last - 1) = '/')
4756 return Dir'Last - 1;
4760 end Compute_Directory_Last;
4762 ---------------------
4763 -- Get_Directories --
4764 ---------------------
4766 procedure Get_Directories
4767 (Project : Project_Id;
4768 Data : in out Tree_Processing_Data)
4770 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
4771 (Header_Num => Header_Num,
4773 No_Element => False,
4777 -- Hash table stores recursive source directories, to avoid looking
4778 -- several times, and to avoid cycles that may be introduced by symbolic
4781 Visited : Recursive_Dirs.Instance;
4783 Object_Dir : constant Variable_Value :=
4785 (Name_Object_Dir, Project.Decl.Attributes, Data.Tree);
4787 Exec_Dir : constant Variable_Value :=
4789 (Name_Exec_Dir, Project.Decl.Attributes, Data.Tree);
4791 Source_Dirs : constant Variable_Value :=
4793 (Name_Source_Dirs, Project.Decl.Attributes, Data.Tree);
4795 Excluded_Source_Dirs : constant Variable_Value :=
4797 (Name_Excluded_Source_Dirs,
4798 Project.Decl.Attributes,
4801 Source_Files : constant Variable_Value :=
4804 Project.Decl.Attributes, Data.Tree);
4806 Last_Source_Dir : String_List_Id := Nil_String;
4807 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
4809 Languages : constant Variable_Value :=
4811 (Name_Languages, Project.Decl.Attributes, Data.Tree);
4813 procedure Find_Source_Dirs
4814 (From : File_Name_Type;
4815 Location : Source_Ptr;
4817 Removed : Boolean := False);
4818 -- Find one or several source directories, and add (or remove, if
4819 -- Removed is True) them to list of source directories of the project.
4821 ----------------------
4822 -- Find_Source_Dirs --
4823 ----------------------
4825 procedure Find_Source_Dirs
4826 (From : File_Name_Type;
4827 Location : Source_Ptr;
4829 Removed : Boolean := False)
4831 Directory : constant String := Get_Name_String (From);
4833 procedure Add_To_Or_Remove_From_List
4835 Display_Path_Id : Name_Id);
4836 -- When Removed = False, the directory Path_Id to the list of
4837 -- source_dirs if not already in the list. When Removed = True,
4838 -- removed directory Path_Id if in the list.
4840 procedure Recursive_Find_Dirs (Path : Name_Id);
4841 -- Find all the subdirectories (recursively) of Path and add them
4842 -- to the list of source directories of the project.
4844 --------------------------------
4845 -- Add_To_Or_Remove_From_List --
4846 --------------------------------
4848 procedure Add_To_Or_Remove_From_List
4850 Display_Path_Id : Name_Id)
4852 List : String_List_Id;
4853 Prev : String_List_Id;
4854 Rank_List : Number_List_Index;
4855 Prev_Rank : Number_List_Index;
4856 Element : String_Element;
4860 Prev_Rank := No_Number_List;
4861 List := Project.Source_Dirs;
4862 Rank_List := Project.Source_Dir_Ranks;
4863 while List /= Nil_String loop
4864 Element := Data.Tree.String_Elements.Table (List);
4865 exit when Element.Value = Path_Id;
4867 List := Element.Next;
4868 Prev_Rank := Rank_List;
4869 Rank_List := Data.Tree.Number_Lists.Table (Prev_Rank).Next;
4872 -- The directory is in the list if List is not Nil_String
4874 if not Removed and then List = Nil_String then
4875 if Current_Verbosity = High then
4876 Write_Str (" Adding Source Dir
=");
4877 Write_Line (Get_Name_String (Path_Id));
4880 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4884 Display_Value => Display_Path_Id,
4885 Location => No_Location,
4887 Next => Nil_String);
4889 Number_List_Table.Increment_Last (Data.Tree.Number_Lists);
4891 if Last_Source_Dir = Nil_String then
4893 -- This is the first source directory
4895 Project.Source_Dirs :=
4896 String_Element_Table.Last (Data.Tree.String_Elements);
4897 Project.Source_Dir_Ranks :=
4898 Number_List_Table.Last (Data.Tree.Number_Lists);
4901 -- We already have source directories, link the previous
4902 -- last to the new one.
4904 Data.Tree.String_Elements.Table (Last_Source_Dir).Next :=
4905 String_Element_Table.Last (Data.Tree.String_Elements);
4906 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
4907 Number_List_Table.Last (Data.Tree.Number_Lists);
4910 -- And register this source directory as the new last
4913 String_Element_Table.Last (Data.Tree.String_Elements);
4914 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4915 Last_Src_Dir_Rank :=
4916 Number_List_Table.Last (Data.Tree.Number_Lists);
4917 Data.Tree.Number_Lists.Table (Last_Src_Dir_Rank) :=
4918 (Number => Rank, Next => No_Number_List);
4920 elsif Removed and then List /= Nil_String then
4922 -- Remove source dir, if present
4924 if Prev = Nil_String then
4925 Project.Source_Dirs :=
4926 Data.Tree.String_Elements.Table (List).Next;
4927 Project.Source_Dir_Ranks :=
4928 Data.Tree.Number_Lists.Table (Rank_List).Next;
4931 Data.Tree.String_Elements.Table (Prev).Next :=
4932 Data.Tree.String_Elements.Table (List).Next;
4933 Data.Tree.Number_Lists.Table (Prev_Rank).Next :=
4934 Data.Tree.Number_Lists.Table (Rank_List).Next;
4937 end Add_To_Or_Remove_From_List;
4939 -------------------------
4940 -- Recursive_Find_Dirs --
4941 -------------------------
4943 procedure Recursive_Find_Dirs (Path : Name_Id) is
4945 Name : String (1 .. 250);
4948 Non_Canonical_Path : Name_Id := No_Name;
4949 Canonical_Path : Name_Id := No_Name;
4951 The_Path : constant String :=
4953 (Get_Name_String (Path),
4955 Get_Name_String (Project.Directory.Display_Name),
4956 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4957 Directory_Separator;
4959 The_Path_Last : constant Natural :=
4960 Compute_Directory_Last (The_Path);
4963 Name_Len := The_Path_Last - The_Path'First + 1;
4964 Name_Buffer (1 .. Name_Len) :=
4965 The_Path (The_Path'First .. The_Path_Last);
4966 Non_Canonical_Path := Name_Find;
4968 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4970 -- To avoid processing the same directory several times, check
4971 -- if the directory is already in Recursive_Dirs. If it is, then
4972 -- there is nothing to do, just return. If it is not, put it there
4973 -- and continue recursive processing.
4976 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4979 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4983 Add_To_Or_Remove_From_List
4984 (Path_Id => Canonical_Path,
4985 Display_Path_Id => Non_Canonical_Path);
4987 -- Now look for subdirectories. Do that even when this directory
4988 -- is already in the list, because some of its subdirectories may
4989 -- not be in the list yet.
4991 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4994 Read (Dir, Name, Last);
4997 if Name (1 .. Last) /= "."
4998 and then Name (1 .. Last) /= ".."
5000 -- Avoid . and .. directories
5002 if Current_Verbosity = High then
5003 Write_Str (" Checking
");
5004 Write_Line (Name (1 .. Last));
5008 Path_Name : constant String :=
5010 (Name => Name (1 .. Last),
5013 (The_Path'First .. The_Path_Last),
5015 Opt.Follow_Links_For_Dirs,
5016 Case_Sensitive => True);
5019 if Is_Directory (Path_Name) then
5021 -- We have found a new subdirectory, call self
5023 Name_Len := Path_Name'Length;
5024 Name_Buffer (1 .. Name_Len) := Path_Name;
5025 Recursive_Find_Dirs (Name_Find);
5034 when Directory_Error =>
5036 end Recursive_Find_Dirs;
5038 -- Start of processing for Find_Source_Dirs
5041 if Current_Verbosity = High and then not Removed then
5042 Write_Str ("Find_Source_Dirs
(""");
5043 Write_Str (Directory);
5045 Write_Str (Rank'Img);
5049 -- First, check if we are looking for a directory tree, indicated
5050 -- by "/**" at the end.
5052 if Directory'Length >= 3
5053 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5054 and then (Directory (Directory'Last - 2) = '/'
5056 Directory (Directory'Last - 2) = Directory_Separator)
5058 Name_Len := Directory'Length - 3;
5060 if Name_Len = 0 then
5062 -- Case of "/**": all directories in file system
5065 Name_Buffer (1) := Directory (Directory'First);
5068 Name_Buffer (1 .. Name_Len) :=
5069 Directory (Directory'First .. Directory'Last - 3);
5072 if Current_Verbosity = High then
5073 Write_Str ("Looking
for all subdirectories
of """);
5074 Write_Str (Name_Buffer (1 .. Name_Len));
5079 Base_Dir : constant File_Name_Type := Name_Find;
5080 Root_Dir : constant String :=
5082 (Name => Get_Name_String (Base_Dir),
5085 (Project.Directory.Display_Name),
5087 Opt.Follow_Links_For_Dirs,
5088 Case_Sensitive => True);
5091 if Root_Dir'Length = 0 then
5092 Err_Vars.Error_Msg_File_1 := Base_Dir;
5094 if Location = No_Location then
5097 "{ is not a valid directory
.",
5098 Project.Location, Project);
5102 "{ is not a valid directory
.",
5107 -- We have an existing directory, we register it and all of
5108 -- its subdirectories.
5110 if Current_Verbosity = High then
5111 Write_Line ("Looking
for source directories
:");
5114 Name_Len := Root_Dir'Length;
5115 Name_Buffer (1 .. Name_Len) := Root_Dir;
5116 Recursive_Find_Dirs (Name_Find);
5118 if Current_Verbosity = High then
5119 Write_Line ("End of looking
for source directories
.");
5124 -- We have a single directory
5128 Path_Name : Path_Information;
5129 Dir_Exists : Boolean;
5133 (Project => Project,
5136 Dir_Exists => Dir_Exists,
5138 Must_Exist => False);
5140 if not Dir_Exists then
5141 Err_Vars.Error_Msg_File_1 := From;
5143 if Location = No_Location then
5146 "{ is not a valid directory
",
5147 Project.Location, Project);
5151 "{ is not a valid directory
",
5157 Path : constant String :=
5160 Get_Name_String (Path_Name.Name),
5162 Get_Name_String (Project.Directory.Name),
5163 Resolve_Links => Opt.Follow_Links_For_Dirs,
5164 Case_Sensitive => True) &
5165 Directory_Separator;
5167 Last_Path : constant Natural :=
5168 Compute_Directory_Last (Path);
5170 Display_Path : constant String :=
5172 (Path_Name.Display_Name);
5173 Last_Display_Path : constant Natural :=
5174 Compute_Directory_Last
5176 Display_Path_Id : Name_Id;
5180 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5181 Path_Id := Name_Find;
5184 Add_Str_To_Name_Buffer
5186 (Display_Path'First .. Last_Display_Path));
5187 Display_Path_Id := Name_Find;
5189 Add_To_Or_Remove_From_List
5190 (Path_Id => Path_Id,
5191 Display_Path_Id => Display_Path_Id);
5197 Recursive_Dirs.Reset (Visited);
5198 end Find_Source_Dirs;
5200 -- Start of processing for Get_Directories
5202 Dir_Exists : Boolean;
5205 if Current_Verbosity = High then
5206 Write_Line ("Starting to look
for directories
");
5209 -- Set the object directory to its default which may be nil, if there
5210 -- is no sources in the project.
5212 if (((not Source_Files.Default)
5213 and then Source_Files.Values = Nil_String)
5215 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5217 ((not Languages.Default) and then Languages.Values = Nil_String))
5218 and then Project.Extends = No_Project
5220 Project.Object_Directory := No_Path_Information;
5222 Project.Object_Directory := Project.Directory;
5225 -- Check the object directory
5227 if Object_Dir.Value /= Empty_String then
5228 Get_Name_String (Object_Dir.Value);
5230 if Name_Len = 0 then
5233 "Object_Dir cannot be empty
",
5234 Object_Dir.Location, Project);
5237 -- We check that the specified object directory does exist.
5238 -- However, even when it doesn't exist, we set it to a default
5239 -- value. This is for the benefit of tools that recover from
5240 -- errors; for example, these tools could create the non existent
5241 -- directory. We always return an absolute directory name though.
5245 File_Name_Type (Object_Dir.Value),
5246 Path => Project.Object_Directory,
5248 Dir_Exists => Dir_Exists,
5250 Location => Object_Dir.Location,
5251 Must_Exist => False,
5252 Externally_Built => Project.Externally_Built);
5255 and then not Project.Externally_Built
5257 -- The object directory does not exist, report an error if
5258 -- the project is not externally built.
5260 Err_Vars.Error_Msg_File_1 :=
5261 File_Name_Type (Object_Dir.Value);
5263 case Data.Flags.Require_Obj_Dirs is
5267 "object directory
{ not found
",
5268 Project.Location, Project);
5272 "?object directory
{ not found
",
5273 Project.Location, Project);
5280 elsif Project.Object_Directory /= No_Path_Information
5281 and then Subdirs /= null
5284 Name_Buffer (1) := '.';
5288 Path => Project.Object_Directory,
5290 Dir_Exists => Dir_Exists,
5292 Location => Object_Dir.Location,
5293 Externally_Built => Project.Externally_Built);
5296 if Current_Verbosity = High then
5297 if Project.Object_Directory = No_Path_Information then
5298 Write_Line ("No object directory
");
5301 ("Object directory
",
5302 Get_Name_String (Project.Object_Directory.Display_Name));
5306 -- Check the exec directory
5308 -- We set the object directory to its default
5310 Project.Exec_Directory := Project.Object_Directory;
5312 if Exec_Dir.Value /= Empty_String then
5313 Get_Name_String (Exec_Dir.Value);
5315 if Name_Len = 0 then
5318 "Exec_Dir cannot be empty
",
5319 Exec_Dir.Location, Project);
5322 -- We check that the specified exec directory does exist
5326 File_Name_Type (Exec_Dir.Value),
5327 Path => Project.Exec_Directory,
5328 Dir_Exists => Dir_Exists,
5331 Location => Exec_Dir.Location,
5332 Externally_Built => Project.Externally_Built);
5334 if not Dir_Exists then
5335 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5338 "exec directory
{ not found
",
5339 Project.Location, Project);
5344 if Current_Verbosity = High then
5345 if Project.Exec_Directory = No_Path_Information then
5346 Write_Line ("No exec directory
");
5348 Write_Str ("Exec directory
: """);
5349 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5354 -- Look for the source directories
5356 if Current_Verbosity = High then
5357 Write_Line ("Starting to look
for source directories
");
5360 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs
is not a list
");
5362 if (not Source_Files.Default)
5363 and then Source_Files.Values = Nil_String
5365 Project.Source_Dirs := Nil_String;
5367 if Project.Qualifier = Standard then
5370 "a standard project cannot have no sources
",
5371 Source_Files.Location, Project);
5374 elsif Source_Dirs.Default then
5376 -- No Source_Dirs specified: the single source directory is the one
5377 -- containing the project file.
5379 String_Element_Table.Append (Data.Tree.String_Elements,
5380 (Value => Name_Id (Project.Directory.Name),
5381 Display_Value => Name_Id (Project.Directory.Display_Name),
5382 Location => No_Location,
5387 Project.Source_Dirs :=
5388 String_Element_Table.Last (Data.Tree.String_Elements);
5390 Number_List_Table.Append
5391 (Data.Tree.Number_Lists,
5392 (Number => 1, Next => No_Number_List));
5394 Project.Source_Dir_Ranks :=
5395 Number_List_Table.Last (Data.Tree.Number_Lists);
5397 if Current_Verbosity = High then
5399 ("Default source directory
",
5400 Get_Name_String (Project.Directory.Display_Name));
5403 elsif Source_Dirs.Values = Nil_String then
5404 if Project.Qualifier = Standard then
5407 "a standard project cannot have no source directories
",
5408 Source_Dirs.Location, Project);
5411 Project.Source_Dirs := Nil_String;
5415 Source_Dir : String_List_Id;
5416 Element : String_Element;
5419 -- Process the source directories for each element of the list
5421 Source_Dir := Source_Dirs.Values;
5423 while Source_Dir /= Nil_String loop
5424 Element := Data.Tree.String_Elements.Table (Source_Dir);
5427 (File_Name_Type (Element.Value), Element.Location, Rank);
5428 Source_Dir := Element.Next;
5433 if not Excluded_Source_Dirs.Default
5434 and then Excluded_Source_Dirs.Values /= Nil_String
5437 Source_Dir : String_List_Id;
5438 Element : String_Element;
5441 -- Process the source directories for each element of the list
5443 Source_Dir := Excluded_Source_Dirs.Values;
5444 while Source_Dir /= Nil_String loop
5445 Element := Data.Tree.String_Elements.Table (Source_Dir);
5447 (File_Name_Type (Element.Value),
5451 Source_Dir := Element.Next;
5456 if Current_Verbosity = High then
5457 Write_Line ("Putting source directories
in canonical cases
");
5461 Current : String_List_Id := Project.Source_Dirs;
5462 Element : String_Element;
5465 while Current /= Nil_String loop
5466 Element := Data.Tree.String_Elements.Table (Current);
5467 if Element.Value /= No_Name then
5469 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5470 Data.Tree.String_Elements.Table (Current) := Element;
5473 Current := Element.Next;
5476 end Get_Directories;
5483 (Project : Project_Id;
5484 Data : in out Tree_Processing_Data)
5486 Mains : constant Variable_Value :=
5488 (Name_Main, Project.Decl.Attributes, Data.Tree);
5489 List : String_List_Id;
5490 Elem : String_Element;
5493 Project.Mains := Mains.Values;
5495 -- If no Mains were specified, and if we are an extending project,
5496 -- inherit the Mains from the project we are extending.
5498 if Mains.Default then
5499 if not Project.Library and then Project.Extends /= No_Project then
5500 Project.Mains := Project.Extends.Mains;
5503 -- In a library project file, Main cannot be specified
5505 elsif Project.Library then
5508 "a library project file cannot have Main specified
",
5509 Mains.Location, Project);
5512 List := Mains.Values;
5513 while List /= Nil_String loop
5514 Elem := Data.Tree.String_Elements.Table (List);
5516 if Length_Of_Name (Elem.Value) = 0 then
5519 "?a main cannot have an empty name
",
5520 Elem.Location, Project);
5529 ---------------------------
5530 -- Get_Sources_From_File --
5531 ---------------------------
5533 procedure Get_Sources_From_File
5535 Location : Source_Ptr;
5536 Project : in out Project_Processing_Data;
5537 Data : in out Tree_Processing_Data)
5539 File : Prj.Util.Text_File;
5540 Line : String (1 .. 250);
5542 Source_Name : File_Name_Type;
5543 Name_Loc : Name_Location;
5546 if Current_Verbosity = High then
5547 Write_Str ("Opening
""");
5554 Prj.Util.Open (File, Path);
5556 if not Prj.Util.Is_Valid (File) then
5558 (Data.Flags, "file does
not exist
", Location, Project.Project);
5561 -- Read the lines one by one
5563 while not Prj.Util.End_Of_File (File) loop
5564 Prj.Util.Get_Line (File, Line, Last);
5566 -- A non empty, non comment line should contain a file name
5569 and then (Last = 1 or else Line (1 .. 2) /= "--")
5572 Name_Buffer
(1 .. Name_Len
) := Line
(1 .. Last
);
5573 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
5574 Source_Name
:= Name_Find
;
5576 -- Check that there is no directory information
5578 for J
in 1 .. Last
loop
5579 if Line
(J
) = '/' or else Line
(J
) = Directory_Separator
then
5580 Error_Msg_File_1
:= Source_Name
;
5583 "file name cannot include directory information ({)",
5584 Location
, Project
.Project
);
5589 Name_Loc
:= Source_Names_Htable
.Get
5590 (Project
.Source_Names
, Source_Name
);
5592 if Name_Loc
= No_Name_Location
then
5594 (Name
=> Source_Name
,
5595 Location
=> Location
,
5596 Source
=> No_Source
,
5600 Source_Names_Htable
.Set
5601 (Project
.Source_Names
, Source_Name
, Name_Loc
);
5605 Prj
.Util
.Close
(File
);
5608 end Get_Sources_From_File
;
5610 -----------------------
5611 -- Compute_Unit_Name --
5612 -----------------------
5614 procedure Compute_Unit_Name
5615 (File_Name
: File_Name_Type
;
5616 Naming
: Lang_Naming_Data
;
5617 Kind
: out Source_Kind
;
5619 Project
: Project_Processing_Data
;
5620 In_Tree
: Project_Tree_Ref
)
5622 Filename
: constant String := Get_Name_String
(File_Name
);
5623 Last
: Integer := Filename
'Last;
5628 Unit_Except
: Unit_Exception
;
5629 Masked
: Boolean := False;
5635 if Naming
.Separate_Suffix
= No_File
5636 or else Naming
.Body_Suffix
= No_File
5637 or else Naming
.Spec_Suffix
= No_File
5642 if Naming
.Dot_Replacement
= No_File
then
5643 if Current_Verbosity
= High
then
5644 Write_Line
(" No dot_replacement specified");
5650 Sep_Len
:= Integer (Length_Of_Name
(Naming
.Separate_Suffix
));
5651 Spec_Len
:= Integer (Length_Of_Name
(Naming
.Spec_Suffix
));
5652 Body_Len
:= Integer (Length_Of_Name
(Naming
.Body_Suffix
));
5654 -- Choose the longest suffix that matches. If there are several matches,
5655 -- give priority to specs, then bodies, then separates.
5657 if Naming
.Separate_Suffix
/= Naming
.Body_Suffix
5658 and then Suffix_Matches
(Filename
, Naming
.Separate_Suffix
)
5660 Last
:= Filename
'Last - Sep_Len
;
5664 if Filename
'Last - Body_Len
<= Last
5665 and then Suffix_Matches
(Filename
, Naming
.Body_Suffix
)
5667 Last
:= Natural'Min (Last
, Filename
'Last - Body_Len
);
5671 if Filename
'Last - Spec_Len
<= Last
5672 and then Suffix_Matches
(Filename
, Naming
.Spec_Suffix
)
5674 Last
:= Natural'Min (Last
, Filename
'Last - Spec_Len
);
5678 if Last
= Filename
'Last then
5679 if Current_Verbosity
= High
then
5680 Write_Line
(" no matching suffix");
5686 -- Check that the casing matches
5688 if File_Names_Case_Sensitive
then
5689 case Naming
.Casing
is
5690 when All_Lower_Case
=>
5691 for J
in Filename
'First .. Last
loop
5692 if Is_Letter
(Filename
(J
))
5693 and then not Is_Lower
(Filename
(J
))
5695 if Current_Verbosity
= High
then
5696 Write_Line
(" Invalid casing");
5703 when All_Upper_Case
=>
5704 for J
in Filename
'First .. Last
loop
5705 if Is_Letter
(Filename
(J
))
5706 and then not Is_Upper
(Filename
(J
))
5708 if Current_Verbosity
= High
then
5709 Write_Line
(" Invalid casing");
5716 when Mixed_Case | Unknown
=>
5721 -- If Dot_Replacement is not a single dot, then there should not
5722 -- be any dot in the name.
5725 Dot_Repl
: constant String :=
5726 Get_Name_String
(Naming
.Dot_Replacement
);
5729 if Dot_Repl
/= "." then
5730 for Index
in Filename
'First .. Last
loop
5731 if Filename
(Index
) = '.' then
5732 if Current_Verbosity
= High
then
5733 Write_Line
(" Invalid name, contains dot");
5740 Replace_Into_Name_Buffer
5741 (Filename
(Filename
'First .. Last
), Dot_Repl
, '.');
5744 Name_Len
:= Last
- Filename
'First + 1;
5745 Name_Buffer
(1 .. Name_Len
) := Filename
(Filename
'First .. Last
);
5747 (Source
=> Name_Buffer
(1 .. Name_Len
),
5748 Mapping
=> Lower_Case_Map
);
5752 -- In the standard GNAT naming scheme, check for special cases: children
5753 -- or separates of A, G, I or S, and run time sources.
5755 if Is_Standard_GNAT_Naming
(Naming
)
5756 and then Name_Len
>= 3
5759 S1
: constant Character := Name_Buffer
(1);
5760 S2
: constant Character := Name_Buffer
(2);
5761 S3
: constant Character := Name_Buffer
(3);
5769 -- Children or separates of packages A, G, I or S. These names
5770 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5771 -- versions (x__... and x~...) are allowed in all platforms,
5772 -- because it is not possible to know the platform before
5773 -- processing of the project files.
5775 if S2
= '_' and then S3
= '_' then
5776 Name_Buffer
(2) := '.';
5777 Name_Buffer
(3 .. Name_Len
- 1) :=
5778 Name_Buffer
(4 .. Name_Len
);
5779 Name_Len
:= Name_Len
- 1;
5782 Name_Buffer
(2) := '.';
5786 -- If it is potentially a run time source
5794 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5795 -- that this is a valid unit name
5797 Check_Ada_Name
(Name_Buffer
(1 .. Name_Len
), Unit
);
5799 -- If there is a naming exception for the same unit, the file is not
5800 -- a source for the unit.
5802 if Unit
/= No_Name
then
5804 Unit_Exceptions_Htable
.Get
(Project
.Unit_Exceptions
, Unit
);
5807 Masked
:= Unit_Except
.Spec
/= No_File
5809 Unit_Except
.Spec
/= File_Name
;
5811 Masked
:= Unit_Except
.Impl
/= No_File
5813 Unit_Except
.Impl
/= File_Name
;
5817 if Current_Verbosity
= High
then
5818 Write_Str
(" """ & Filename
& """ contains the ");
5821 Write_Str
("spec of a unit found in """);
5822 Write_Str
(Get_Name_String
(Unit_Except
.Spec
));
5824 Write_Str
("body of a unit found in """);
5825 Write_Str
(Get_Name_String
(Unit_Except
.Impl
));
5828 Write_Line
(""" (ignored)");
5836 and then Current_Verbosity
= High
5839 when Spec
=> Write_Str
(" spec of ");
5840 when Impl
=> Write_Str
(" body of ");
5841 when Sep
=> Write_Str
(" sep of ");
5844 Write_Line
(Get_Name_String
(Unit
));
5846 end Compute_Unit_Name
;
5848 --------------------------
5849 -- Check_Illegal_Suffix --
5850 --------------------------
5852 procedure Check_Illegal_Suffix
5853 (Project
: Project_Id
;
5854 Suffix
: File_Name_Type
;
5855 Dot_Replacement
: File_Name_Type
;
5856 Attribute_Name
: String;
5857 Location
: Source_Ptr
;
5858 Data
: in out Tree_Processing_Data
)
5860 Suffix_Str
: constant String := Get_Name_String
(Suffix
);
5863 if Suffix_Str
'Length = 0 then
5869 elsif Index
(Suffix_Str
, ".") = 0 then
5870 Err_Vars
.Error_Msg_File_1
:= Suffix
;
5873 "{ is illegal for " & Attribute_Name
& ": must have a dot",
5878 -- Case of dot replacement is a single dot, and first character of
5879 -- suffix is also a dot.
5881 if Dot_Replacement
/= No_File
5882 and then Get_Name_String
(Dot_Replacement
) = "."
5883 and then Suffix_Str
(Suffix_Str
'First) = '.'
5885 for Index
in Suffix_Str
'First + 1 .. Suffix_Str
'Last loop
5887 -- If there are multiple dots in the name
5889 if Suffix_Str
(Index
) = '.' then
5891 -- It is illegal to have a letter following the initial dot
5893 if Is_Letter
(Suffix_Str
(Suffix_Str
'First + 1)) then
5894 Err_Vars
.Error_Msg_File_1
:= Suffix
;
5897 "{ is illegal for " & Attribute_Name
5898 & ": ambiguous prefix when Dot_Replacement is a dot",
5905 end Check_Illegal_Suffix
;
5907 ----------------------
5908 -- Locate_Directory --
5909 ----------------------
5911 procedure Locate_Directory
5912 (Project
: Project_Id
;
5913 Name
: File_Name_Type
;
5914 Path
: out Path_Information
;
5915 Dir_Exists
: out Boolean;
5916 Data
: in out Tree_Processing_Data
;
5917 Create
: String := "";
5918 Location
: Source_Ptr
:= No_Location
;
5919 Must_Exist
: Boolean := True;
5920 Externally_Built
: Boolean := False)
5922 Parent
: constant Path_Name_Type
:=
5923 Project
.Directory
.Display_Name
;
5924 The_Parent
: constant String :=
5925 Get_Name_String
(Parent
);
5926 The_Parent_Last
: constant Natural :=
5927 Compute_Directory_Last
(The_Parent
);
5928 Full_Name
: File_Name_Type
;
5929 The_Name
: File_Name_Type
;
5932 Get_Name_String
(Name
);
5934 -- Add Subdirs.all if it is a directory that may be created and
5935 -- Subdirs is not null;
5937 if Create
/= "" and then Subdirs
/= null then
5938 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
5939 Add_Char_To_Name_Buffer
(Directory_Separator
);
5942 Add_Str_To_Name_Buffer
(Subdirs
.all);
5945 -- Convert '/' to directory separator (for Windows)
5947 for J
in 1 .. Name_Len
loop
5948 if Name_Buffer
(J
) = '/' then
5949 Name_Buffer
(J
) := Directory_Separator
;
5953 The_Name
:= Name_Find
;
5955 if Current_Verbosity
= High
then
5956 Write_Str
("Locate_Directory (""");
5957 Write_Str
(Get_Name_String
(The_Name
));
5958 Write_Str
(""", """);
5959 Write_Str
(The_Parent
);
5963 Path
:= No_Path_Information
;
5964 Dir_Exists
:= False;
5966 if Is_Absolute_Path
(Get_Name_String
(The_Name
)) then
5967 Full_Name
:= The_Name
;
5971 Add_Str_To_Name_Buffer
5972 (The_Parent
(The_Parent
'First .. The_Parent_Last
));
5973 Add_Str_To_Name_Buffer
(Get_Name_String
(The_Name
));
5974 Full_Name
:= Name_Find
;
5978 Full_Path_Name
: String_Access
:=
5979 new String'(Get_Name_String (Full_Name));
5982 if (Setup_Projects or else Subdirs /= null)
5983 and then Create'Length > 0
5985 if not Is_Directory (Full_Path_Name.all) then
5987 -- If project is externally built, do not create a subdir,
5988 -- use the specified directory, without the subdir.
5990 if Externally_Built then
5991 if Is_Absolute_Path (Get_Name_String (Name)) then
5992 Get_Name_String (Name);
5996 Add_Str_To_Name_Buffer
5997 (The_Parent (The_Parent'First .. The_Parent_Last));
5998 Add_Str_To_Name_Buffer (Get_Name_String (Name));
6001 Full_Path_Name := new String'(Name_Buffer
(1 .. Name_Len
));
6005 Create_Path
(Full_Path_Name
.all);
6007 if not Quiet_Output
then
6009 Write_Str
(" directory """);
6010 Write_Str
(Full_Path_Name
.all);
6011 Write_Str
(""" created for project ");
6012 Write_Line
(Get_Name_String
(Project
.Name
));
6019 "could not create " & Create
&
6020 " directory " & Full_Path_Name
.all,
6027 Dir_Exists
:= Is_Directory
(Full_Path_Name
.all);
6029 if not Must_Exist
or else Dir_Exists
then
6031 Normed
: constant String :=
6033 (Full_Path_Name
.all,
6035 The_Parent
(The_Parent
'First .. The_Parent_Last
),
6036 Resolve_Links
=> False,
6037 Case_Sensitive
=> True);
6039 Canonical_Path
: constant String :=
6044 (The_Parent
'First .. The_Parent_Last
),
6046 Opt
.Follow_Links_For_Dirs
,
6047 Case_Sensitive
=> False);
6050 Name_Len
:= Normed
'Length;
6051 Name_Buffer
(1 .. Name_Len
) := Normed
;
6053 -- Directories should always end with a directory separator
6055 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
6056 Add_Char_To_Name_Buffer
(Directory_Separator
);
6059 Path
.Display_Name
:= Name_Find
;
6061 Name_Len
:= Canonical_Path
'Length;
6062 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
6064 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
6065 Add_Char_To_Name_Buffer
(Directory_Separator
);
6068 Path
.Name
:= Name_Find
;
6072 Free
(Full_Path_Name
);
6074 end Locate_Directory
;
6076 ---------------------------
6077 -- Find_Excluded_Sources --
6078 ---------------------------
6080 procedure Find_Excluded_Sources
6081 (Project
: in out Project_Processing_Data
;
6082 Data
: in out Tree_Processing_Data
)
6084 Excluded_Source_List_File
: constant Variable_Value
:=
6086 (Name_Excluded_Source_List_File
,
6087 Project
.Project
.Decl
.Attributes
,
6089 Excluded_Sources
: Variable_Value
:= Util
.Value_Of
6090 (Name_Excluded_Source_Files
,
6091 Project
.Project
.Decl
.Attributes
,
6094 Current
: String_List_Id
;
6095 Element
: String_Element
;
6096 Location
: Source_Ptr
;
6097 Name
: File_Name_Type
;
6098 File
: Prj
.Util
.Text_File
;
6099 Line
: String (1 .. 300);
6101 Locally_Removed
: Boolean := False;
6104 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6106 if Excluded_Sources
.Default
then
6107 Locally_Removed
:= True;
6110 (Name_Locally_Removed_Files
,
6111 Project
.Project
.Decl
.Attributes
, Data
.Tree
);
6114 -- If there are excluded sources, put them in the table
6116 if not Excluded_Sources
.Default
then
6117 if not Excluded_Source_List_File
.Default
then
6118 if Locally_Removed
then
6121 "?both attributes Locally_Removed_Files and " &
6122 "Excluded_Source_List_File are present",
6123 Excluded_Source_List_File
.Location
, Project
.Project
);
6127 "?both attributes Excluded_Source_Files and " &
6128 "Excluded_Source_List_File are present",
6129 Excluded_Source_List_File
.Location
, Project
.Project
);
6133 Current
:= Excluded_Sources
.Values
;
6134 while Current
/= Nil_String
loop
6135 Element
:= Data
.Tree
.String_Elements
.Table
(Current
);
6136 Name
:= Canonical_Case_File_Name
(Element
.Value
);
6138 -- If the element has no location, then use the location of
6139 -- Excluded_Sources to report possible errors.
6141 if Element
.Location
= No_Location
then
6142 Location
:= Excluded_Sources
.Location
;
6144 Location
:= Element
.Location
;
6147 Excluded_Sources_Htable
.Set
6148 (Project
.Excluded
, Name
, (Name
, False, Location
));
6149 Current
:= Element
.Next
;
6152 elsif not Excluded_Source_List_File
.Default
then
6153 Location
:= Excluded_Source_List_File
.Location
;
6156 Source_File_Path_Name
: constant String :=
6159 (Excluded_Source_List_File
.Value
),
6160 Project
.Project
.Directory
.Name
);
6163 if Source_File_Path_Name
'Length = 0 then
6164 Err_Vars
.Error_Msg_File_1
:=
6165 File_Name_Type
(Excluded_Source_List_File
.Value
);
6168 "file with excluded sources { does not exist",
6169 Excluded_Source_List_File
.Location
, Project
.Project
);
6174 Prj
.Util
.Open
(File
, Source_File_Path_Name
);
6176 if not Prj
.Util
.Is_Valid
(File
) then
6178 (Data
.Flags
, "file does not exist",
6179 Location
, Project
.Project
);
6181 -- Read the lines one by one
6183 while not Prj
.Util
.End_Of_File
(File
) loop
6184 Prj
.Util
.Get_Line
(File
, Line
, Last
);
6186 -- Non empty, non comment line should contain a file name
6189 and then (Last
= 1 or else Line
(1 .. 2) /= "--")
6192 Name_Buffer
(1 .. Name_Len
) := Line
(1 .. Last
);
6193 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
6196 -- Check that there is no directory information
6198 for J
in 1 .. Last
loop
6200 or else Line
(J
) = Directory_Separator
6202 Error_Msg_File_1
:= Name
;
6205 "file name cannot include " &
6206 "directory information ({)",
6207 Location
, Project
.Project
);
6212 Excluded_Sources_Htable
.Set
6213 (Project
.Excluded
, Name
, (Name
, False, Location
));
6217 Prj
.Util
.Close
(File
);
6222 end Find_Excluded_Sources
;
6228 procedure Find_Sources
6229 (Project
: in out Project_Processing_Data
;
6230 Data
: in out Tree_Processing_Data
)
6232 Sources
: constant Variable_Value
:=
6235 Project
.Project
.Decl
.Attributes
,
6238 Source_List_File
: constant Variable_Value
:=
6240 (Name_Source_List_File
,
6241 Project
.Project
.Decl
.Attributes
,
6244 Name_Loc
: Name_Location
;
6245 Has_Explicit_Sources
: Boolean;
6248 pragma Assert
(Sources
.Kind
= List
, "Source_Files is not a list");
6250 (Source_List_File
.Kind
= Single
,
6251 "Source_List_File is not a single string");
6253 Project
.Source_List_File_Location
:= Source_List_File
.Location
;
6255 -- If the user has specified a Source_Files attribute
6257 if not Sources
.Default
then
6258 if not Source_List_File
.Default
then
6261 "?both attributes source_files and " &
6262 "source_list_file are present",
6263 Source_List_File
.Location
, Project
.Project
);
6266 -- Sources is a list of file names
6269 Current
: String_List_Id
:= Sources
.Values
;
6270 Element
: String_Element
;
6271 Location
: Source_Ptr
;
6272 Name
: File_Name_Type
;
6275 if Current
= Nil_String
then
6276 Project
.Project
.Languages
:= No_Language_Index
;
6278 -- This project contains no source. For projects that don't
6279 -- extend other projects, this also means that there is no
6280 -- need for an object directory, if not specified.
6282 if Project
.Project
.Extends
= No_Project
6283 and then Project
.Project
.Object_Directory
=
6284 Project
.Project
.Directory
6286 Project
.Project
.Object_Directory
:= No_Path_Information
;
6290 while Current
/= Nil_String
loop
6291 Element
:= Data
.Tree
.String_Elements
.Table
(Current
);
6292 Name
:= Canonical_Case_File_Name
(Element
.Value
);
6293 Get_Name_String
(Element
.Value
);
6295 -- If the element has no location, then use the location of
6296 -- Sources to report possible errors.
6298 if Element
.Location
= No_Location
then
6299 Location
:= Sources
.Location
;
6301 Location
:= Element
.Location
;
6304 -- Check that there is no directory information
6306 for J
in 1 .. Name_Len
loop
6307 if Name_Buffer
(J
) = '/'
6308 or else Name_Buffer
(J
) = Directory_Separator
6310 Error_Msg_File_1
:= Name
;
6313 "file name cannot include directory " &
6315 Location
, Project
.Project
);
6320 -- Check whether the file is already there: the same file name
6321 -- may be in the list. If the source is missing, the error will
6322 -- be on the first mention of the source file name.
6324 Name_Loc
:= Source_Names_Htable
.Get
6325 (Project
.Source_Names
, Name
);
6327 if Name_Loc
= No_Name_Location
then
6330 Location
=> Location
,
6331 Source
=> No_Source
,
6333 Source_Names_Htable
.Set
6334 (Project
.Source_Names
, Name
, Name_Loc
);
6337 Current
:= Element
.Next
;
6340 Has_Explicit_Sources
:= True;
6343 -- If we have no Source_Files attribute, check the Source_List_File
6346 elsif not Source_List_File
.Default
then
6348 -- Source_List_File is the name of the file that contains the source
6352 Source_File_Path_Name
: constant String :=
6354 (File_Name_Type
(Source_List_File
.Value
),
6355 Project
.Project
.Directory
.Name
);
6358 Has_Explicit_Sources
:= True;
6360 if Source_File_Path_Name
'Length = 0 then
6361 Err_Vars
.Error_Msg_File_1
:=
6362 File_Name_Type
(Source_List_File
.Value
);
6365 "file with sources { does not exist",
6366 Source_List_File
.Location
, Project
.Project
);
6369 Get_Sources_From_File
6370 (Source_File_Path_Name
, Source_List_File
.Location
,
6376 -- Neither Source_Files nor Source_List_File has been specified. Find
6377 -- all the files that satisfy the naming scheme in all the source
6380 Has_Explicit_Sources
:= False;
6386 For_All_Sources
=> Sources
.Default
and then Source_List_File
.Default
);
6388 -- Check if all exceptions have been found
6392 Iter
: Source_Iterator
;
6395 Iter
:= For_Each_Source
(Data
.Tree
, Project
.Project
);
6397 Source
:= Prj
.Element
(Iter
);
6398 exit when Source
= No_Source
;
6400 if Source
.Naming_Exception
6401 and then Source
.Path
= No_Path_Information
6403 if Source
.Unit
/= No_Unit_Index
then
6405 -- For multi-unit source files, source_id gets duplicated
6406 -- once for every unit. Only the first source_id got its
6407 -- full path set. So if it isn't set for that first one,
6408 -- the file wasn't found. Otherwise we need to update for
6409 -- units after the first one.
6412 or else Source
.Index
= 1
6414 Error_Msg_Name_1
:= Name_Id
(Source
.Display_File
);
6415 Error_Msg_Name_2
:= Name_Id
(Source
.Unit
.Name
);
6418 "source file %% for unit %% not found",
6419 No_Location
, Project
.Project
);
6422 Source
.Path
:= Files_Htable
.Get
6423 (Data
.File_To_Source
, Source
.File
).Path
;
6425 if Current_Verbosity
= High
then
6426 if Source
.Path
/= No_Path_Information
then
6427 Write_Line
("Setting full path for "
6428 & Get_Name_String
(Source
.File
)
6429 & " at" & Source
.Index
'Img
6431 & Get_Name_String
(Source
.Path
.Name
));
6437 if Source
.Path
= No_Path_Information
then
6438 Remove_Source
(Source
, No_Source
);
6446 -- It is an error if a source file name in a source list or in a source
6447 -- list file is not found.
6449 if Has_Explicit_Sources
then
6452 First_Error
: Boolean;
6455 NL
:= Source_Names_Htable
.Get_First
(Project
.Source_Names
);
6456 First_Error
:= True;
6457 while NL
/= No_Name_Location
loop
6458 if not NL
.Found
then
6459 Err_Vars
.Error_Msg_File_1
:= NL
.Name
;
6464 "source file { not found",
6465 NL
.Location
, Project
.Project
);
6466 First_Error
:= False;
6471 "\source file { not found",
6472 NL
.Location
, Project
.Project
);
6476 NL
:= Source_Names_Htable
.Get_Next
(Project
.Source_Names
);
6486 procedure Initialize
6487 (Data
: out Tree_Processing_Data
;
6488 Tree
: Project_Tree_Ref
;
6489 Flags
: Prj
.Processing_Flags
)
6492 Files_Htable
.Reset
(Data
.File_To_Source
);
6494 Data
.Flags
:= Flags
;
6501 procedure Free
(Data
: in out Tree_Processing_Data
) is
6503 Files_Htable
.Reset
(Data
.File_To_Source
);
6510 procedure Initialize
6511 (Data
: in out Project_Processing_Data
;
6512 Project
: Project_Id
)
6515 Data
.Project
:= Project
;
6522 procedure Free
(Data
: in out Project_Processing_Data
) is
6524 Source_Names_Htable
.Reset
(Data
.Source_Names
);
6525 Unit_Exceptions_Htable
.Reset
(Data
.Unit_Exceptions
);
6526 Excluded_Sources_Htable
.Reset
(Data
.Excluded
);
6529 -------------------------------
6530 -- Check_File_Naming_Schemes --
6531 -------------------------------
6533 procedure Check_File_Naming_Schemes
6534 (In_Tree
: Project_Tree_Ref
;
6535 Project
: Project_Processing_Data
;
6536 File_Name
: File_Name_Type
;
6537 Alternate_Languages
: out Language_List
;
6538 Language
: out Language_Ptr
;
6539 Display_Language_Name
: out Name_Id
;
6541 Lang_Kind
: out Language_Kind
;
6542 Kind
: out Source_Kind
)
6544 Filename
: constant String := Get_Name_String
(File_Name
);
6545 Config
: Language_Config
;
6546 Tmp_Lang
: Language_Ptr
;
6548 Header_File
: Boolean := False;
6549 -- True if we found at least one language for which the file is a header
6550 -- In such a case, we search for all possible languages where this is
6551 -- also a header (C and C++ for instance), since the file might be used
6552 -- for several such languages.
6554 procedure Check_File_Based_Lang
;
6555 -- Does the naming scheme test for file-based languages. For those,
6556 -- there is no Unit. Just check if the file name has the implementation
6557 -- or, if it is specified, the template suffix of the language.
6559 -- Returns True if the file belongs to the current language and we
6560 -- should stop searching for matching languages. Not that a given header
6561 -- file could belong to several languages (C and C++ for instance). Thus
6562 -- if we found a header we'll check whether it matches other languages.
6564 ---------------------------
6565 -- Check_File_Based_Lang --
6566 ---------------------------
6568 procedure Check_File_Based_Lang
is
6571 and then Suffix_Matches
(Filename
, Config
.Naming_Data
.Body_Suffix
)
6575 Language
:= Tmp_Lang
;
6577 if Current_Verbosity
= High
then
6578 Write_Str
(" implementation of language ");
6579 Write_Line
(Get_Name_String
(Display_Language_Name
));
6582 elsif Suffix_Matches
(Filename
, Config
.Naming_Data
.Spec_Suffix
) then
6583 if Current_Verbosity
= High
then
6584 Write_Str
(" header of language ");
6585 Write_Line
(Get_Name_String
(Display_Language_Name
));
6589 Alternate_Languages
:= new Language_List_Element
'
6590 (Language => Language,
6591 Next => Alternate_Languages);
6594 Header_File := True;
6597 Language := Tmp_Lang;
6600 end Check_File_Based_Lang;
6602 -- Start of processing for Check_File_Naming_Schemes
6605 Language := No_Language_Index;
6606 Alternate_Languages := null;
6607 Display_Language_Name := No_Name;
6609 Lang_Kind := File_Based;
6612 Tmp_Lang := Project.Project.Languages;
6613 while Tmp_Lang /= No_Language_Index loop
6614 if Current_Verbosity = High then
6616 (" Testing language "
6617 & Get_Name_String (Tmp_Lang.Name)
6618 & " Header_File=" & Header_File'Img);
6621 Display_Language_Name := Tmp_Lang.Display_Name;
6622 Config := Tmp_Lang.Config;
6623 Lang_Kind := Config.Kind;
6627 Check_File_Based_Lang;
6628 exit when Kind = Impl;
6632 -- We know it belongs to a least a file_based language, no
6633 -- need to check unit-based ones.
6635 if not Header_File then
6637 (File_Name => File_Name,
6638 Naming => Config.Naming_Data,
6642 In_Tree => In_Tree);
6644 if Unit /= No_Name then
6645 Language := Tmp_Lang;
6651 Tmp_Lang := Tmp_Lang.Next;
6654 if Language = No_Language_Index
6655 and then Current_Verbosity = High
6657 Write_Line (" not a source of any language");
6659 end Check_File_Naming_Schemes;
6665 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6667 -- If the file was previously already associated with a unit, change it
6669 if Source.Unit /= null
6670 and then Source.Kind in Spec_Or_Body
6671 and then Source.Unit.File_Names (Source.Kind) /= null
6673 -- If we had another file referencing the same unit (for instance it
6674 -- was in an extended project), that source file is in fact invisible
6675 -- from now on, and in particular doesn't belong to the same unit.
6677 if Source.Unit.File_Names (Source.Kind) /= Source then
6678 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6681 Source.Unit.File_Names (Source.Kind) := null;
6684 Source.Kind := Kind;
6686 if Current_Verbosity = High
6687 and then Source.File /= No_File
6689 Write_Line ("Override kind for "
6690 & Get_Name_String (Source.File)
6691 & " kind=" & Source.Kind'Img);
6694 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6695 Source.Unit.File_Names (Source.Kind) := Source;
6703 procedure Check_File
6704 (Project : in out Project_Processing_Data;
6705 Data : in out Tree_Processing_Data;
6706 Source_Dir_Rank : Natural;
6707 Path : Path_Name_Type;
6708 File_Name : File_Name_Type;
6709 Display_File_Name : File_Name_Type;
6710 Locally_Removed : Boolean;
6711 For_All_Sources : Boolean)
6713 Canonical_Path : constant Path_Name_Type :=
6715 (Canonical_Case_File_Name (Name_Id (Path)));
6717 Name_Loc : Name_Location :=
6718 Source_Names_Htable.Get
6719 (Project.Source_Names, File_Name);
6720 Check_Name : Boolean := False;
6721 Alternate_Languages : Language_List;
6722 Language : Language_Ptr;
6724 Src_Ind : Source_File_Index;
6726 Display_Language_Name : Name_Id;
6727 Lang_Kind : Language_Kind;
6728 Kind : Source_Kind := Spec;
6731 if Current_Verbosity = High then
6732 Write_Line ("Checking file:");
6733 Write_Str (" Path = ");
6734 Write_Line (Get_Name_String (Path));
6735 Write_Str (" Rank =");
6736 Write_Line (Source_Dir_Rank'Img);
6739 if Name_Loc = No_Name_Location then
6740 Check_Name := For_All_Sources;
6743 if Name_Loc.Found then
6745 -- Check if it is OK to have the same file name in several
6746 -- source directories.
6748 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6749 Error_Msg_File_1 := File_Name;
6752 "{ is found in several source directories",
6753 Name_Loc.Location, Project.Project);
6757 Name_Loc.Found := True;
6759 Source_Names_Htable.Set
6760 (Project.Source_Names, File_Name, Name_Loc);
6762 if Name_Loc.Source = No_Source then
6766 Name_Loc.Source.Path := (Canonical_Path, Path);
6768 Source_Paths_Htable.Set
6769 (Data.Tree.Source_Paths_HT,
6773 -- Check if this is a subunit
6775 if Name_Loc.Source.Unit /= No_Unit_Index
6776 and then Name_Loc.Source.Kind = Impl
6778 Src_Ind := Sinput.P.Load_Project_File
6779 (Get_Name_String (Canonical_Path));
6781 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6782 Override_Kind (Name_Loc.Source, Sep);
6787 (Data.File_To_Source, File_Name, Name_Loc.Source);
6793 Check_File_Naming_Schemes
6794 (In_Tree => Data.Tree,
6796 File_Name => File_Name,
6797 Alternate_Languages => Alternate_Languages,
6798 Language => Language,
6799 Display_Language_Name => Display_Language_Name,
6801 Lang_Kind => Lang_Kind,
6804 if Language = No_Language_Index then
6806 -- A file name in a list must be a source of a language
6808 if Data.Flags.Error_On_Unknown_Language
6809 and then Name_Loc.Found
6811 Error_Msg_File_1 := File_Name;
6814 "language unknown for {",
6815 Name_Loc.Location, Project.Project);
6821 Project => Project.Project,
6822 Source_Dir_Rank => Source_Dir_Rank,
6823 Lang_Id => Language,
6826 Alternate_Languages => Alternate_Languages,
6827 File_Name => File_Name,
6828 Display_File => Display_File_Name,
6830 Locally_Removed => Locally_Removed,
6831 Path => (Canonical_Path, Path));
6833 -- If it is a source specified in a list, update the entry in
6834 -- the Source_Names table.
6836 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6837 Name_Loc.Source := Source;
6838 Source_Names_Htable.Set
6839 (Project.Source_Names, File_Name, Name_Loc);
6845 ------------------------
6846 -- Search_Directories --
6847 ------------------------
6849 procedure Search_Directories
6850 (Project : in out Project_Processing_Data;
6851 Data : in out Tree_Processing_Data;
6852 For_All_Sources : Boolean)
6854 Source_Dir : String_List_Id;
6855 Element : String_Element;
6856 Src_Dir_Rank : Number_List_Index;
6857 Num_Nod : Number_Node;
6859 Name : String (1 .. 1_000);
6861 File_Name : File_Name_Type;
6862 Display_File_Name : File_Name_Type;
6865 if Current_Verbosity = High then
6866 Write_Line ("Looking for sources:");
6869 -- Loop through subdirectories
6871 Source_Dir := Project.Project.Source_Dirs;
6872 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
6873 while Source_Dir /= Nil_String loop
6875 Num_Nod := Data.Tree.Number_Lists.Table (Src_Dir_Rank);
6876 Element := Data.Tree.String_Elements.Table (Source_Dir);
6878 if Element.Value /= No_Name then
6879 Get_Name_String (Element.Display_Value);
6881 if Current_Verbosity = High then
6882 Write_Str ("Directory: ");
6883 Write_Str (Name_Buffer (1 .. Name_Len));
6884 Write_Line (Num_Nod.Number'Img);
6888 Source_Directory : constant String :=
6889 Name_Buffer (1 .. Name_Len) &
6890 Directory_Separator;
6892 Dir_Last : constant Natural :=
6893 Compute_Directory_Last
6897 if Current_Verbosity = High then
6898 Write_Attr ("Source_Dir", Source_Directory);
6901 -- We look to every entry in the source directory
6903 Open (Dir, Source_Directory);
6906 Read (Dir, Name, Last);
6910 -- In fast project loading mode (without -eL), the user
6911 -- guarantees that no directory has a name which is a
6912 -- valid source name, so we can avoid doing a system call
6913 -- here. This provides a very significant speed up on
6914 -- slow file systems (remote files for instance).
6916 if not Opt.Follow_Links_For_Files
6917 or else Is_Regular_File
6918 (Source_Directory & Name (1 .. Last))
6920 if Current_Verbosity = High then
6921 Write_Str (" Checking ");
6922 Write_Line (Name (1 .. Last));
6926 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6927 Display_File_Name := Name_Find;
6929 if Osint.File_Names_Case_Sensitive then
6930 File_Name := Display_File_Name;
6932 Canonical_Case_File_Name
6933 (Name_Buffer (1 .. Name_Len));
6934 File_Name := Name_Find;
6938 Path_Name : constant String :=
6943 (Source_Directory'First ..
6946 Opt.Follow_Links_For_Files,
6947 Case_Sensitive => True);
6948 -- Case_Sensitive set True (no folding)
6950 Path : Path_Name_Type;
6951 FF : File_Found := Excluded_Sources_Htable.Get
6952 (Project.Excluded, File_Name);
6953 To_Remove : Boolean := False;
6956 Name_Len := Path_Name'Length;
6957 Name_Buffer (1 .. Name_Len) := Path_Name;
6960 if FF /= No_File_Found then
6961 if not FF.Found then
6963 Excluded_Sources_Htable.Set
6964 (Project.Excluded, File_Name, FF);
6966 if Current_Verbosity = High then
6967 Write_Str (" excluded source """);
6968 Write_Str (Get_Name_String (File_Name));
6972 -- Will mark the file as removed, but we
6973 -- still need to add it to the list: if we
6974 -- don't, the file will not appear in the
6975 -- mapping file and will cause the compiler
6983 (Project => Project,
6984 Source_Dir_Rank => Num_Nod.Number,
6987 File_Name => File_Name,
6988 Locally_Removed => To_Remove,
6989 Display_File_Name => Display_File_Name,
6990 For_All_Sources => For_All_Sources);
7000 when Directory_Error =>
7004 Source_Dir := Element.Next;
7005 Src_Dir_Rank := Num_Nod.Next;
7008 if Current_Verbosity = High then
7009 Write_Line ("end Looking for sources.");
7011 end Search_Directories;
7013 ----------------------------
7014 -- Load_Naming_Exceptions --
7015 ----------------------------
7017 procedure Load_Naming_Exceptions
7018 (Project : in out Project_Processing_Data;
7019 Data : in out Tree_Processing_Data)
7022 Iter : Source_Iterator;
7025 Iter := For_Each_Source (Data.Tree, Project.Project);
7027 Source := Prj.Element (Iter);
7028 exit when Source = No_Source;
7030 -- An excluded file cannot also be an exception file name
7032 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
7035 Error_Msg_File_1 := Source.File;
7038 "{ cannot be both excluded and an exception file name",
7039 No_Location, Project.Project);
7042 if Current_Verbosity = High then
7043 Write_Str ("Naming exception: Putting source file ");
7044 Write_Str (Get_Name_String (Source.File));
7045 Write_Line (" in Source_Names");
7048 Source_Names_Htable.Set
7049 (Project.Source_Names,
7052 (Name
=> Source
.File
,
7053 Location
=> No_Location
,
7057 -- If this is an Ada exception, record in table Unit_Exceptions
7059 if Source
.Unit
/= No_Unit_Index
then
7061 Unit_Except
: Unit_Exception
:=
7062 Unit_Exceptions_Htable
.Get
7063 (Project
.Unit_Exceptions
, Source
.Unit
.Name
);
7066 Unit_Except
.Name
:= Source
.Unit
.Name
;
7068 if Source
.Kind
= Spec
then
7069 Unit_Except
.Spec
:= Source
.File
;
7071 Unit_Except
.Impl
:= Source
.File
;
7074 Unit_Exceptions_Htable
.Set
7075 (Project
.Unit_Exceptions
, Source
.Unit
.Name
, Unit_Except
);
7081 end Load_Naming_Exceptions
;
7083 ----------------------
7084 -- Look_For_Sources --
7085 ----------------------
7087 procedure Look_For_Sources
7088 (Project
: in out Project_Processing_Data
;
7089 Data
: in out Tree_Processing_Data
)
7091 Object_Files
: Object_File_Names_Htable
.Instance
;
7092 Iter
: Source_Iterator
;
7095 procedure Check_Object
(Src
: Source_Id
);
7096 -- Check if object file name of Src is already used in the project tree,
7097 -- and report an error if so.
7099 procedure Check_Object_Files
;
7100 -- Check that no two sources of this project have the same object file
7102 procedure Mark_Excluded_Sources
;
7103 -- Mark as such the sources that are declared as excluded
7109 procedure Check_Object
(Src
: Source_Id
) is
7113 Source
:= Object_File_Names_Htable
.Get
(Object_Files
, Src
.Object
);
7115 -- We cannot just check on "Source /= Src", since we might have
7116 -- two different entries for the same file (and since that's
7117 -- the same file it is expected that it has the same object)
7119 if Source
/= No_Source
7120 and then Source
.Path
/= Src
.Path
7122 Error_Msg_File_1
:= Src
.File
;
7123 Error_Msg_File_2
:= Source
.File
;
7126 "{ and { have the same object file name",
7127 No_Location
, Project
.Project
);
7130 Object_File_Names_Htable
.Set
(Object_Files
, Src
.Object
, Src
);
7134 ---------------------------
7135 -- Mark_Excluded_Sources --
7136 ---------------------------
7138 procedure Mark_Excluded_Sources
is
7139 Source
: Source_Id
:= No_Source
;
7140 Excluded
: File_Found
;
7144 -- Minor optimization: if there are no excluded files, no need to
7145 -- traverse the list of sources. We cannot however also check whether
7146 -- the existing exceptions have ".Found" set to True (indicating we
7147 -- found them before) because we need to do some final processing on
7148 -- them in any case.
7150 if Excluded_Sources_Htable
.Get_First
(Project
.Excluded
) /=
7153 Proj
:= Project
.Project
;
7154 while Proj
/= No_Project
loop
7155 Iter
:= For_Each_Source
(Data
.Tree
, Proj
);
7156 while Prj
.Element
(Iter
) /= No_Source
loop
7157 Source
:= Prj
.Element
(Iter
);
7158 Excluded
:= Excluded_Sources_Htable
.Get
7159 (Project
.Excluded
, Source
.File
);
7161 if Excluded
/= No_File_Found
then
7162 Source
.Locally_Removed
:= True;
7163 Source
.In_Interfaces
:= False;
7165 if Current_Verbosity
= High
then
7166 Write_Str
("Removing file ");
7168 (Get_Name_String
(Excluded
.File
)
7169 & " " & Get_Name_String
(Source
.Project
.Name
));
7172 Excluded_Sources_Htable
.Remove
7173 (Project
.Excluded
, Source
.File
);
7179 Proj
:= Proj
.Extends
;
7183 -- If we have any excluded element left, that means we did not find
7186 Excluded
:= Excluded_Sources_Htable
.Get_First
(Project
.Excluded
);
7187 while Excluded
/= No_File_Found
loop
7188 if not Excluded
.Found
then
7190 -- Check if the file belongs to another imported project to
7191 -- provide a better error message.
7194 (In_Tree
=> Data
.Tree
,
7195 Project
=> Project
.Project
,
7196 In_Imported_Only
=> True,
7197 Base_Name
=> Excluded
.File
);
7199 Err_Vars
.Error_Msg_File_1
:= Excluded
.File
;
7201 if Src
= No_Source
then
7204 "unknown file {", Excluded
.Location
, Project
.Project
);
7208 "cannot remove a source from an imported project: {",
7209 Excluded
.Location
, Project
.Project
);
7213 Excluded
:= Excluded_Sources_Htable
.Get_Next
(Project
.Excluded
);
7215 end Mark_Excluded_Sources
;
7217 ------------------------
7218 -- Check_Object_Files --
7219 ------------------------
7221 procedure Check_Object_Files
is
7222 Iter
: Source_Iterator
;
7224 Src_Ind
: Source_File_Index
;
7227 Iter
:= For_Each_Source
(Data
.Tree
);
7229 Src_Id
:= Prj
.Element
(Iter
);
7230 exit when Src_Id
= No_Source
;
7232 if Is_Compilable
(Src_Id
)
7233 and then Src_Id
.Language
.Config
.Object_Generated
7234 and then Is_Extending
(Project
.Project
, Src_Id
.Project
)
7236 if Src_Id
.Unit
= No_Unit_Index
then
7237 if Src_Id
.Kind
= Impl
then
7238 Check_Object
(Src_Id
);
7244 if Other_Part
(Src_Id
) = No_Source
then
7245 Check_Object
(Src_Id
);
7252 if Other_Part
(Src_Id
) /= No_Source
then
7253 Check_Object
(Src_Id
);
7256 -- Check if it is a subunit
7259 Sinput
.P
.Load_Project_File
7260 (Get_Name_String
(Src_Id
.Path
.Name
));
7262 if Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
) then
7263 Override_Kind
(Src_Id
, Sep
);
7265 Check_Object
(Src_Id
);
7274 end Check_Object_Files
;
7276 -- Start of processing for Look_For_Sources
7279 Find_Excluded_Sources
(Project
, Data
);
7281 if Project
.Project
.Languages
/= No_Language_Index
then
7282 Load_Naming_Exceptions
(Project
, Data
);
7283 Find_Sources
(Project
, Data
);
7284 Mark_Excluded_Sources
;
7288 Object_File_Names_Htable
.Reset
(Object_Files
);
7289 end Look_For_Sources
;
7295 function Path_Name_Of
7296 (File_Name
: File_Name_Type
;
7297 Directory
: Path_Name_Type
) return String
7299 Result
: String_Access
;
7300 The_Directory
: constant String := Get_Name_String
(Directory
);
7303 Get_Name_String
(File_Name
);
7306 (File_Name
=> Name_Buffer
(1 .. Name_Len
),
7307 Path
=> The_Directory
);
7309 if Result
= null then
7313 R
: String := Result
.all;
7316 Canonical_Case_File_Name
(R
);
7326 procedure Remove_Source
7328 Replaced_By
: Source_Id
)
7333 if Current_Verbosity
= High
then
7334 Write_Str
("Removing source ");
7335 Write_Str
(Get_Name_String
(Id
.File
));
7337 if Id
.Index
/= 0 then
7338 Write_Str
(" at" & Id
.Index
'Img);
7344 if Replaced_By
/= No_Source
then
7345 Id
.Replaced_By
:= Replaced_By
;
7346 Replaced_By
.Declared_In_Interfaces
:= Id
.Declared_In_Interfaces
;
7349 Id
.In_Interfaces
:= False;
7350 Id
.Locally_Removed
:= True;
7352 -- ??? Should we remove the source from the unit ? The file is not used,
7353 -- so probably should not be referenced from the unit. On the other hand
7354 -- it might give useful additional info
7355 -- if Id.Unit /= null then
7356 -- Id.Unit.File_Names (Id.Kind) := null;
7359 Source
:= Id
.Language
.First_Source
;
7362 Id
.Language
.First_Source
:= Id
.Next_In_Lang
;
7365 while Source
.Next_In_Lang
/= Id
loop
7366 Source
:= Source
.Next_In_Lang
;
7369 Source
.Next_In_Lang
:= Id
.Next_In_Lang
;
7373 -----------------------
7374 -- Report_No_Sources --
7375 -----------------------
7377 procedure Report_No_Sources
7378 (Project
: Project_Id
;
7380 Data
: Tree_Processing_Data
;
7381 Location
: Source_Ptr
;
7382 Continuation
: Boolean := False)
7385 case Data
.Flags
.When_No_Sources
is
7389 when Warning | Error
=>
7391 Msg
: constant String :=
7394 " sources in this project";
7397 Error_Msg_Warn
:= Data
.Flags
.When_No_Sources
= Warning
;
7399 if Continuation
then
7400 Error_Msg
(Data
.Flags
, "\" & Msg, Location, Project);
7402 Error_Msg (Data.Flags, Msg, Location, Project);
7406 end Report_No_Sources;
7408 ----------------------
7409 -- Show_Source_Dirs --
7410 ----------------------
7412 procedure Show_Source_Dirs
7413 (Project : Project_Id;
7414 In_Tree : Project_Tree_Ref)
7416 Current : String_List_Id;
7417 Element : String_Element;
7420 Write_Line ("Source_Dirs
:");
7422 Current := Project.Source_Dirs;
7423 while Current /= Nil_String loop
7424 Element := In_Tree.String_Elements.Table (Current);
7426 Write_Line (Get_Name_String (Element.Value));
7427 Current := Element.Next;
7430 Write_Line ("end Source_Dirs
.");
7431 end Show_Source_Dirs;
7433 ---------------------------
7434 -- Process_Naming_Scheme --
7435 ---------------------------
7437 procedure Process_Naming_Scheme
7438 (Tree : Project_Tree_Ref;
7439 Root_Project : Project_Id;
7440 Flags : Processing_Flags)
7442 procedure Recursive_Check
7443 (Project : Project_Id;
7444 Data : in out Tree_Processing_Data);
7445 -- Check_Naming_Scheme for the project
7447 ---------------------
7448 -- Recursive_Check --
7449 ---------------------
7451 procedure Recursive_Check
7452 (Project : Project_Id;
7453 Data : in out Tree_Processing_Data)
7456 if Verbose_Mode then
7457 Write_Str ("Processing_Naming_Scheme
for project
""");
7458 Write_Str (Get_Name_String (Project.Name));
7462 Prj.Nmsc.Check (Project, Data);
7463 end Recursive_Check;
7465 procedure Check_All_Projects is new
7466 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7468 Data : Tree_Processing_Data;
7470 -- Start of processing for Process_Naming_Scheme
7472 Initialize (Data, Tree => Tree, Flags => Flags);
7473 Check_All_Projects (Root_Project, Data, Imported_First => True);
7475 end Process_Naming_Scheme;