OSDN Git Service

2009-04-09 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-nmsc.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             P R J . N M S C                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2000-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
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.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with GNAT.Case_Util;             use GNAT.Case_Util;
27 with GNAT.Directory_Operations;  use GNAT.Directory_Operations;
28 with GNAT.HTable;
29
30 with Err_Vars; use Err_Vars;
31 with Fmap;     use Fmap;
32 with Hostparm;
33 with MLib.Tgt;
34 with Opt;      use Opt;
35 with Osint;    use Osint;
36 with Output;   use Output;
37 with Prj.Env;  use Prj.Env;
38 with Prj.Err;
39 with Prj.Util; use Prj.Util;
40 with Sinput.P;
41 with Snames;   use Snames;
42 with Table;    use Table;
43 with Targparm; use Targparm;
44
45 with Ada.Characters.Handling;    use Ada.Characters.Handling;
46 with Ada.Directories;            use Ada.Directories;
47 with Ada.Strings;                use Ada.Strings;
48 with Ada.Strings.Fixed;          use Ada.Strings.Fixed;
49 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
50
51 package body Prj.Nmsc is
52
53    No_Continuation_String : aliased String := "";
54    Continuation_String    : aliased String := "\";
55    --  Used in Check_Library for continuation error messages at the same
56    --  location.
57
58    Error_Report : Put_Line_Access := null;
59    --  Set to point to error reporting procedure
60
61    When_No_Sources : Error_Warning := Error;
62    --  Indicates what should be done when there is no Ada sources in a non
63    --  extending Ada project.
64
65    ALI_Suffix   : constant String := ".ali";
66    --  File suffix for ali files
67
68    type Name_Location is record
69       Name     : File_Name_Type;
70       Location : Source_Ptr;
71       Source   : Source_Id := No_Source;
72       Except   : Boolean := False;
73       Found    : Boolean := False;
74    end record;
75    --  Information about file names found in string list attribute
76    --  Source_Files or in a source list file, stored in hash table
77    --  Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
78
79    No_Name_Location : constant Name_Location :=
80                         (Name     => No_File,
81                          Location => No_Location,
82                          Source   => No_Source,
83                          Except   => False,
84                          Found    => False);
85
86    package Source_Names is new GNAT.HTable.Simple_HTable
87      (Header_Num => Header_Num,
88       Element    => Name_Location,
89       No_Element => No_Name_Location,
90       Key        => File_Name_Type,
91       Hash       => Hash,
92       Equal      => "=");
93    --  Hash table to store file names found in string list attribute
94    --  Source_Files or in a source list file, stored in hash table
95    --  Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
96
97    --  More documentation needed on what unit exceptions are about ???
98
99    type Unit_Exception is record
100       Name : Name_Id;
101       Spec : File_Name_Type;
102       Impl : File_Name_Type;
103    end record;
104
105    No_Unit_Exception : constant Unit_Exception :=
106                          (Name => No_Name,
107                           Spec => No_File,
108                           Impl => No_File);
109
110    package Unit_Exceptions is new GNAT.HTable.Simple_HTable
111      (Header_Num => Header_Num,
112       Element    => Unit_Exception,
113       No_Element => No_Unit_Exception,
114       Key        => Name_Id,
115       Hash       => Hash,
116       Equal      => "=");
117    --  Hash table to store the unit exceptions
118
119    package Recursive_Dirs is new GNAT.HTable.Simple_HTable
120      (Header_Num => Header_Num,
121       Element    => Boolean,
122       No_Element => False,
123       Key        => Name_Id,
124       Hash       => Hash,
125       Equal      => "=");
126    --  Hash table to store recursive source directories, to avoid looking
127    --  several times, and to avoid cycles that may be introduced by symbolic
128    --  links.
129
130    type Ada_Naming_Exception_Id is new Nat;
131    No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
132
133    type Unit_Info is record
134       Kind : Spec_Or_Body;
135       Unit : Name_Id;
136       Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
137    end record;
138    --  Comment needed???
139
140    --  Why is the following commented out ???
141    --  No_Unit : constant Unit_Info :=
142    --              (Specification, No_Name, No_Ada_Naming_Exception);
143
144    package Ada_Naming_Exception_Table is new Table.Table
145      (Table_Component_Type => Unit_Info,
146       Table_Index_Type     => Ada_Naming_Exception_Id,
147       Table_Low_Bound      => 1,
148       Table_Initial        => 20,
149       Table_Increment      => 100,
150       Table_Name           => "Prj.Nmsc.Ada_Naming_Exception_Table");
151
152    package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
153      (Header_Num => Header_Num,
154       Element    => Ada_Naming_Exception_Id,
155       No_Element => No_Ada_Naming_Exception,
156       Key        => File_Name_Type,
157       Hash       => Hash,
158       Equal      => "=");
159    --  A hash table to store naming exceptions for Ada. For each file name
160    --  there is one or several unit in table Ada_Naming_Exception_Table.
161
162    package Object_File_Names is new GNAT.HTable.Simple_HTable
163      (Header_Num => Header_Num,
164       Element    => File_Name_Type,
165       No_Element => No_File,
166       Key        => File_Name_Type,
167       Hash       => Hash,
168       Equal      => "=");
169    --  A hash table to store the object file names for a project, to check that
170    --  two different sources have different object file names.
171
172    type File_Found is record
173       File     : File_Name_Type  := No_File;
174       Found    : Boolean         := False;
175       Location : Source_Ptr      := No_Location;
176    end record;
177    No_File_Found : constant File_Found := (No_File, False, No_Location);
178    --  Comments needed ???
179
180    package Excluded_Sources_Htable is new GNAT.HTable.Simple_HTable
181      (Header_Num => Header_Num,
182       Element    => File_Found,
183       No_Element => No_File_Found,
184       Key        => File_Name_Type,
185       Hash       => Hash,
186       Equal      => "=");
187    --  A hash table to store the excluded files, if any. This is filled by
188    --  Find_Excluded_Sources below.
189
190    procedure Find_Excluded_Sources
191      (Project : Project_Id;
192       In_Tree : Project_Tree_Ref;
193       Data    : Project_Data);
194    --  Find the list of files that should not be considered as source files
195    --  for this project. Sets the list in the Excluded_Sources_Htable.
196
197    function Hash (Unit : Unit_Info) return Header_Num;
198
199    type Name_And_Index is record
200       Name  : Name_Id := No_Name;
201       Index : Int     := 0;
202    end record;
203    No_Name_And_Index : constant Name_And_Index :=
204                          (Name => No_Name, Index => 0);
205
206    package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
207      (Header_Num => Header_Num,
208       Element    => Name_And_Index,
209       No_Element => No_Name_And_Index,
210       Key        => Unit_Info,
211       Hash       => Hash,
212       Equal      => "=");
213    --  A table to check if a unit with an exceptional name will hide a source
214    --  with a file name following the naming convention.
215
216    procedure Add_Source
217      (Id                  : out Source_Id;
218       Data                : in out Project_Data;
219       In_Tree             : Project_Tree_Ref;
220       Project             : Project_Id;
221       Lang                : Name_Id;
222       Lang_Id             : Language_Index;
223       Kind                : Source_Kind;
224       File_Name           : File_Name_Type;
225       Display_File        : File_Name_Type;
226       Lang_Kind           : Language_Kind;
227       Naming_Exception    : Boolean := False;
228       Path                : Path_Name_Type := No_Path;
229       Display_Path        : Path_Name_Type := No_Path;
230       Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
231       Other_Part          : Source_Id := No_Source;
232       Unit                : Name_Id   := No_Name;
233       Index               : Int       := 0;
234       Source_To_Replace   : Source_Id := No_Source);
235    --  Add a new source to the different lists: list of all sources in the
236    --  project tree, list of source of a project and list of sources of a
237    --  language.
238    --
239    --  If Path is specified, the file is also added to Source_Paths_HT.
240    --  If Source_To_Replace is specified, it points to the source in the
241    --  extended project that the new file is overriding.
242
243    function ALI_File_Name (Source : String) return String;
244    --  Return the ALI file name corresponding to a source
245
246    procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
247    --  Check that a name is a valid Ada unit name
248
249    procedure Check_Naming_Schemes
250      (Data    : in out Project_Data;
251       Project : Project_Id;
252       In_Tree : Project_Tree_Ref);
253    --  Check the naming scheme part of Data
254
255    procedure Check_Ada_Naming_Scheme_Validity
256      (Project : Project_Id;
257       In_Tree : Project_Tree_Ref;
258       Naming  : Naming_Data);
259    --  Check that the package Naming is correct
260
261    procedure Check_Configuration
262      (Project : Project_Id;
263       In_Tree : Project_Tree_Ref;
264       Data    : in out Project_Data);
265    --  Check the configuration attributes for the project
266
267    procedure Check_If_Externally_Built
268      (Project : Project_Id;
269       In_Tree : Project_Tree_Ref;
270       Data    : in out Project_Data);
271    --  Check attribute Externally_Built of project Project in project tree
272    --  In_Tree and modify its data Data if it has the value "true".
273
274    procedure Check_Interfaces
275      (Project : Project_Id;
276       In_Tree : Project_Tree_Ref;
277       Data    : in out Project_Data);
278    --  If a list of sources is specified in attribute Interfaces, set
279    --  In_Interfaces only for the sources specified in the list.
280
281    procedure Check_Library_Attributes
282      (Project     : Project_Id;
283       In_Tree     : Project_Tree_Ref;
284       Current_Dir : String;
285       Data        : in out Project_Data);
286    --  Check the library attributes of project Project in project tree In_Tree
287    --  and modify its data Data accordingly.
288    --  Current_Dir should represent the current directory, and is passed for
289    --  efficiency to avoid system calls to recompute it.
290
291    procedure Check_Package_Naming
292      (Project : Project_Id;
293       In_Tree : Project_Tree_Ref;
294       Data    : in out Project_Data);
295    --  Check package Naming of project Project in project tree In_Tree and
296    --  modify its data Data accordingly.
297
298    procedure Check_Programming_Languages
299      (In_Tree : Project_Tree_Ref;
300       Project : Project_Id;
301       Data    : in out Project_Data);
302    --  Check attribute Languages for the project with data Data in project
303    --  tree In_Tree and set the components of Data for all the programming
304    --  languages indicated in attribute Languages, if any.
305
306    function Check_Project
307      (P            : Project_Id;
308       Root_Project : Project_Id;
309       In_Tree      : Project_Tree_Ref;
310       Extending    : Boolean) return Boolean;
311    --  Returns True if P is Root_Project or, if Extending is True, a project
312    --  extended by Root_Project.
313
314    procedure Check_Stand_Alone_Library
315      (Project     : Project_Id;
316       In_Tree     : Project_Tree_Ref;
317       Data        : in out Project_Data;
318       Current_Dir : String;
319       Extending   : Boolean);
320    --  Check if project Project in project tree In_Tree is a Stand-Alone
321    --  Library project, and modify its data Data accordingly if it is one.
322    --  Current_Dir should represent the current directory, and is passed for
323    --  efficiency to avoid system calls to recompute it.
324
325    procedure Get_Path_Names_And_Record_Ada_Sources
326      (Project     : Project_Id;
327       In_Tree     : Project_Tree_Ref;
328       Data        : in out Project_Data;
329       Current_Dir : String);
330    --  Find the path names of the source files in the Source_Names table
331    --  in the source directories and record those that are Ada sources.
332
333    function Compute_Directory_Last (Dir : String) return Natural;
334    --  Return the index of the last significant character in Dir. This is used
335    --  to avoid duplicate '/' (slash) characters at the end of directory names.
336
337    procedure Error_Msg
338      (Project       : Project_Id;
339       In_Tree       : Project_Tree_Ref;
340       Msg           : String;
341       Flag_Location : Source_Ptr);
342    --  Output an error message. If Error_Report is null, simply call
343    --  Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
344    --  Error_Report.
345
346    procedure Find_Ada_Sources
347      (Project      : Project_Id;
348       In_Tree      : Project_Tree_Ref;
349       Data         : in out Project_Data;
350       Current_Dir  : String);
351    --  Find all the Ada sources in all of the source directories of a project
352    --  Current_Dir should represent the current directory, and is passed for
353    --  efficiency to avoid system calls to recompute it.
354
355    procedure Search_Directories
356      (Project         : Project_Id;
357       In_Tree         : Project_Tree_Ref;
358       Data            : in out Project_Data;
359       For_All_Sources : Boolean);
360    --  Search the source directories to find the sources.
361    --  If For_All_Sources is True, check each regular file name against the
362    --  naming schemes of the different languages. Otherwise consider only the
363    --  file names in the hash table Source_Names.
364
365    procedure Check_File
366      (Project           : Project_Id;
367       In_Tree           : Project_Tree_Ref;
368       Data              : in out Project_Data;
369       Name              : String;
370       File_Name         : File_Name_Type;
371       Display_File_Name : File_Name_Type;
372       Source_Directory  : String;
373       For_All_Sources   : Boolean);
374    --  Check if file File_Name is a valid source of the project. This is used
375    --  in multi-language mode only.
376    --  When the file matches one of the naming schemes, it is added to
377    --  various htables through Add_Source and to Source_Paths_Htable.
378    --
379    --  Name is the name of the candidate file. It hasn't been normalized yet
380    --  and is the direct result of readdir().
381    --
382    --  File_Name is the same as Name, but has been normalized.
383    --  Display_File_Name, however, has not been normalized.
384    --
385    --  Source_Directory is the directory in which the file
386    --  was found. It hasn't been normalized (nor has had links resolved).
387    --  It should not end with a directory separator, to avoid duplicates
388    --  later on.
389    --
390    --  If For_All_Sources is True, then all possible file names are analyzed
391    --  otherwise only those currently set in the Source_Names htable.
392
393    procedure Check_Naming_Schemes
394      (In_Tree               : Project_Tree_Ref;
395       Data                  : in out Project_Data;
396       Filename              : String;
397       File_Name             : File_Name_Type;
398       Alternate_Languages   : out Alternate_Language_Id;
399       Language              : out Language_Index;
400       Language_Name         : out Name_Id;
401       Display_Language_Name : out Name_Id;
402       Unit                  : out Name_Id;
403       Lang_Kind             : out Language_Kind;
404       Kind                  : out Source_Kind);
405    --  Check if the file name File_Name conforms to one of the naming
406    --  schemes of the project.
407    --
408    --  If the file does not match one of the naming schemes, set Language
409    --  to No_Language_Index.
410    --
411    --  Filename is the name of the file being investigated. It has been
412    --  normalized (case-folded). File_Name is the same value.
413
414    procedure Free_Ada_Naming_Exceptions;
415    --  Free the internal hash tables used for checking naming exceptions
416
417    procedure Get_Directories
418      (Project : Project_Id;
419       In_Tree : Project_Tree_Ref;
420       Current_Dir : String;
421       Data    : in out Project_Data);
422    --  Get the object directory, the exec directory and the source directories
423    --  of a project.
424    --
425    --  Current_Dir should represent the current directory, and is passed for
426    --  efficiency to avoid system calls to recompute it.
427
428    procedure Get_Mains
429      (Project : Project_Id;
430       In_Tree : Project_Tree_Ref;
431       Data    : in out Project_Data);
432    --  Get the mains of a project from attribute Main, if it exists, and put
433    --  them in the project data.
434
435    procedure Get_Sources_From_File
436      (Path     : String;
437       Location : Source_Ptr;
438       Project  : Project_Id;
439       In_Tree  : Project_Tree_Ref);
440    --  Get the list of sources from a text file and put them in hash table
441    --  Source_Names.
442
443    procedure Find_Explicit_Sources
444      (Current_Dir : String;
445       Project     : Project_Id;
446       In_Tree     : Project_Tree_Ref;
447       Data        : in out Project_Data);
448    --  Process the Source_Files and Source_List_File attributes, and store
449    --  the list of source files into the Source_Names htable.
450    --
451    --  Lang indicates which language is being processed when in Ada_Only mode
452    --  (all languages are processed anyway when in Multi_Language mode).
453
454    procedure Get_Unit
455      (In_Tree             : Project_Tree_Ref;
456       Canonical_File_Name : File_Name_Type;
457       Naming              : Naming_Data;
458       Exception_Id        : out Ada_Naming_Exception_Id;
459       Unit_Name           : out Name_Id;
460       Unit_Kind           : out Spec_Or_Body;
461       Needs_Pragma        : out Boolean);
462    --  Find out, from a file name, the unit name, the unit kind and if a
463    --  specific SFN pragma is needed. If the file name corresponds to no unit,
464    --  then Unit_Name will be No_Name. If the file is a multi-unit source or an
465    --  exception to the naming scheme, then Exception_Id is set to the unit or
466    --  units that the source contains.
467
468    function Is_Illegal_Suffix
469      (Suffix                          : String;
470       Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
471    --  Returns True if the string Suffix cannot be used as a spec suffix, a
472    --  body suffix or a separate suffix.
473
474    procedure Locate_Directory
475      (Project  : Project_Id;
476       In_Tree  : Project_Tree_Ref;
477       Name     : File_Name_Type;
478       Parent   : Path_Name_Type;
479       Dir      : out Path_Name_Type;
480       Display  : out Path_Name_Type;
481       Create   : String := "";
482       Current_Dir : String;
483       Location : Source_Ptr := No_Location);
484    --  Locate a directory. Name is the directory name. Parent is the root
485    --  directory, if Name a relative path name. Dir is set to the canonical
486    --  case path name of the directory, and Display is the directory path name
487    --  for display purposes. If the directory does not exist and Project_Setup
488    --  is True and Create is a non null string, an attempt is made to create
489    --  the directory. If the directory does not exist and Project_Setup is
490    --  false, then Dir and Display are set to No_Name.
491    --
492    --  Current_Dir should represent the current directory, and is passed for
493    --  efficiency to avoid system calls to recompute it.
494
495    procedure Look_For_Sources
496      (Project     : Project_Id;
497       In_Tree     : Project_Tree_Ref;
498       Data        : in out Project_Data;
499       Current_Dir : String);
500    --  Find all the sources of project Project in project tree In_Tree and
501    --  update its Data accordingly.
502    --
503    --  Current_Dir should represent the current directory, and is passed for
504    --  efficiency to avoid system calls to recompute it.
505
506    function Path_Name_Of
507      (File_Name : File_Name_Type;
508       Directory : Path_Name_Type) return String;
509    --  Returns the path name of a (non project) file. Returns an empty string
510    --  if file cannot be found.
511
512    procedure Prepare_Ada_Naming_Exceptions
513      (List    : Array_Element_Id;
514       In_Tree : Project_Tree_Ref;
515       Kind    : Spec_Or_Body);
516    --  Prepare the internal hash tables used for checking naming exceptions
517    --  for Ada. Insert all elements of List in the tables.
518
519    function Project_Extends
520      (Extending : Project_Id;
521       Extended  : Project_Id;
522       In_Tree   : Project_Tree_Ref) return Boolean;
523    --  Returns True if Extending is extending Extended either directly or
524    --  indirectly.
525
526    procedure Record_Ada_Source
527      (File_Name       : File_Name_Type;
528       Path_Name       : Path_Name_Type;
529       Project         : Project_Id;
530       In_Tree         : Project_Tree_Ref;
531       Data            : in out Project_Data;
532       Location        : Source_Ptr;
533       Current_Source  : in out String_List_Id;
534       Source_Recorded : in out Boolean;
535       Current_Dir     : String);
536    --  Put a unit in the list of units of a project, if the file name
537    --  corresponds to a valid unit name.
538    --
539    --  Current_Dir should represent the current directory, and is passed for
540    --  efficiency to avoid system calls to recompute it.
541
542    procedure Remove_Source
543      (Id          : Source_Id;
544       Replaced_By : Source_Id;
545       Project     : Project_Id;
546       Data        : in out Project_Data;
547       In_Tree     : Project_Tree_Ref);
548    --  ??? needs comment
549
550    procedure Report_No_Sources
551      (Project      : Project_Id;
552       Lang_Name    : String;
553       In_Tree      : Project_Tree_Ref;
554       Location     : Source_Ptr;
555       Continuation : Boolean := False);
556    --  Report an error or a warning depending on the value of When_No_Sources
557    --  when there are no sources for language Lang_Name.
558
559    procedure Show_Source_Dirs
560      (Data : Project_Data; In_Tree : Project_Tree_Ref);
561    --  List all the source directories of a project
562
563    procedure Warn_If_Not_Sources
564      (Project     : Project_Id;
565       In_Tree     : Project_Tree_Ref;
566       Conventions : Array_Element_Id;
567       Specs       : Boolean;
568       Extending   : Boolean);
569    --  Check that individual naming conventions apply to immediate sources of
570    --  the project. If not, issue a warning.
571
572    ----------------
573    -- Add_Source --
574    ----------------
575
576    procedure Add_Source
577      (Id                  : out Source_Id;
578       Data                : in out Project_Data;
579       In_Tree             : Project_Tree_Ref;
580       Project             : Project_Id;
581       Lang                : Name_Id;
582       Lang_Id             : Language_Index;
583       Kind                : Source_Kind;
584       File_Name           : File_Name_Type;
585       Display_File        : File_Name_Type;
586       Lang_Kind           : Language_Kind;
587       Naming_Exception    : Boolean := False;
588       Path                : Path_Name_Type := No_Path;
589       Display_Path        : Path_Name_Type := No_Path;
590       Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
591       Other_Part          : Source_Id := No_Source;
592       Unit                : Name_Id   := No_Name;
593       Index               : Int       := 0;
594       Source_To_Replace   : Source_Id := No_Source)
595    is
596       Source   : constant Source_Id := Data.Last_Source;
597       Src_Data : Source_Data := No_Source_Data;
598       Config   : constant Language_Config :=
599                    In_Tree.Languages_Data.Table (Lang_Id).Config;
600
601    begin
602       --  This is a new source so create an entry for it in the Sources table
603
604       Source_Data_Table.Increment_Last (In_Tree.Sources);
605       Id := Source_Data_Table.Last (In_Tree.Sources);
606
607       if Current_Verbosity = High then
608          Write_Str ("Adding source #");
609          Write_Str (Id'Img);
610          Write_Str (", File : ");
611          Write_Str (Get_Name_String (File_Name));
612
613          if Lang_Kind = Unit_Based then
614             Write_Str (", Unit : ");
615             Write_Str (Get_Name_String (Unit));
616          end if;
617
618          Write_Eol;
619       end if;
620
621       Src_Data.Project             := Project;
622       Src_Data.Language_Name       := Lang;
623       Src_Data.Language            := Lang_Id;
624       Src_Data.Lang_Kind           := Lang_Kind;
625       Src_Data.Compiled            := In_Tree.Languages_Data.Table
626                                         (Lang_Id).Config.Compiler_Driver /=
627                                                               Empty_File_Name;
628       Src_Data.Kind                := Kind;
629       Src_Data.Alternate_Languages := Alternate_Languages;
630       Src_Data.Other_Part          := Other_Part;
631
632       Src_Data.Object_Exists := Config.Object_Generated;
633       Src_Data.Object_Linked := Config.Objects_Linked;
634
635       if Other_Part /= No_Source then
636          In_Tree.Sources.Table (Other_Part).Other_Part := Id;
637       end if;
638
639       Src_Data.Unit                := Unit;
640       Src_Data.Index               := Index;
641       Src_Data.File                := File_Name;
642       Src_Data.Display_File        := Display_File;
643       Src_Data.Dependency          := In_Tree.Languages_Data.Table
644                                         (Lang_Id).Config.Dependency_Kind;
645       Src_Data.Naming_Exception    := Naming_Exception;
646
647       if Src_Data.Compiled and then Src_Data.Object_Exists then
648          Src_Data.Object   := Object_Name (File_Name);
649          Src_Data.Dep_Name :=
650            Dependency_Name (File_Name, Src_Data.Dependency);
651          Src_Data.Switches := Switches_Name (File_Name);
652       end if;
653
654       if Path /= No_Path then
655          Src_Data.Path := (Path, Display_Path);
656          Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path, Id);
657       end if;
658
659       --  Add the source id to the Unit_Sources_HT hash table, if the unit name
660       --  is not null.
661
662       if Unit /= No_Name then
663          Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
664       end if;
665
666       --  Add the source to the global list
667
668       Src_Data.Next_In_Sources := In_Tree.First_Source;
669       In_Tree.First_Source := Id;
670
671       --  Add the source to the project list
672
673       if Source = No_Source then
674          Data.First_Source := Id;
675       else
676          In_Tree.Sources.Table (Source).Next_In_Project := Id;
677       end if;
678
679       Data.Last_Source := Id;
680
681       --  Add the source to the language list
682
683       Src_Data.Next_In_Lang :=
684         In_Tree.Languages_Data.Table (Lang_Id).First_Source;
685       In_Tree.Languages_Data.Table (Lang_Id).First_Source := Id;
686
687       In_Tree.Sources.Table (Id) := Src_Data;
688
689       if Source_To_Replace /= No_Source then
690          Remove_Source (Source_To_Replace, Id, Project, Data, In_Tree);
691       end if;
692    end Add_Source;
693
694    -------------------
695    -- ALI_File_Name --
696    -------------------
697
698    function ALI_File_Name (Source : String) return String is
699    begin
700       --  If the source name has an extension, then replace it with
701       --  the ALI suffix.
702
703       for Index in reverse Source'First + 1 .. Source'Last loop
704          if Source (Index) = '.' then
705             return Source (Source'First .. Index - 1) & ALI_Suffix;
706          end if;
707       end loop;
708
709       --  If there is no dot, or if it is the first character, just add the
710       --  ALI suffix.
711
712       return Source & ALI_Suffix;
713    end ALI_File_Name;
714
715    -----------
716    -- Check --
717    -----------
718
719    procedure Check
720      (Project         : Project_Id;
721       In_Tree         : Project_Tree_Ref;
722       Report_Error    : Put_Line_Access;
723       When_No_Sources : Error_Warning;
724       Current_Dir     : String)
725    is
726       Data      : Project_Data := In_Tree.Projects.Table (Project);
727       Extending : Boolean := False;
728
729    begin
730       Nmsc.When_No_Sources := When_No_Sources;
731       Error_Report := Report_Error;
732
733       Recursive_Dirs.Reset;
734
735       Check_If_Externally_Built (Project, In_Tree, Data);
736
737       --  Object, exec and source directories
738
739       Get_Directories (Project, In_Tree, Current_Dir, Data);
740
741       --  Get the programming languages
742
743       Check_Programming_Languages (In_Tree, Project, Data);
744
745       if Data.Qualifier = Dry and then Data.Source_Dirs /= Nil_String then
746          Error_Msg
747            (Project, In_Tree,
748             "an abstract project need to have no language, no sources or no " &
749             "source directories",
750             Data.Location);
751       end if;
752
753       --  Check configuration in multi language mode
754
755       if Must_Check_Configuration then
756          Check_Configuration (Project, In_Tree, Data);
757       end if;
758
759       --  Library attributes
760
761       Check_Library_Attributes (Project, In_Tree, Current_Dir, Data);
762
763       if Current_Verbosity = High then
764          Show_Source_Dirs (Data, In_Tree);
765       end if;
766
767       Check_Package_Naming (Project, In_Tree, Data);
768
769       Extending := Data.Extends /= No_Project;
770
771       Check_Naming_Schemes (Data, Project, In_Tree);
772
773       if Get_Mode = Ada_Only then
774          Prepare_Ada_Naming_Exceptions
775            (Data.Naming.Bodies, In_Tree, Body_Part);
776          Prepare_Ada_Naming_Exceptions
777            (Data.Naming.Specs, In_Tree, Specification);
778       end if;
779
780       --  Find the sources
781
782       if Data.Source_Dirs /= Nil_String then
783          Look_For_Sources (Project, In_Tree, Data, Current_Dir);
784
785          if Get_Mode = Ada_Only then
786
787             --  Check that all individual naming conventions apply to sources
788             --  of this project file.
789
790             Warn_If_Not_Sources
791               (Project, In_Tree, Data.Naming.Bodies,
792                Specs     => False,
793                Extending => Extending);
794             Warn_If_Not_Sources
795               (Project, In_Tree, Data.Naming.Specs,
796                Specs     => True,
797                Extending => Extending);
798
799          elsif Get_Mode = Multi_Language and then
800                (not Data.Externally_Built) and then
801                (not Extending)
802          then
803             declare
804                Language      : Language_Index;
805                Source        : Source_Id;
806                Alt_Lang      : Alternate_Language_Id;
807                Alt_Lang_Data : Alternate_Language_Data;
808                Continuation  : Boolean := False;
809
810             begin
811                Language := Data.First_Language_Processing;
812                while Language /= No_Language_Index loop
813                   Source := Data.First_Source;
814                   Source_Loop : while Source /= No_Source loop
815                      declare
816                         Src_Data : Source_Data renames
817                                      In_Tree.Sources.Table (Source);
818
819                      begin
820                         exit Source_Loop when Src_Data.Language = Language;
821
822                         Alt_Lang := Src_Data.Alternate_Languages;
823
824                         Alternate_Loop :
825                         while Alt_Lang /= No_Alternate_Language loop
826                            Alt_Lang_Data :=
827                              In_Tree.Alt_Langs.Table (Alt_Lang);
828                            exit Source_Loop
829                            when Alt_Lang_Data.Language = Language;
830                            Alt_Lang := Alt_Lang_Data.Next;
831                         end loop Alternate_Loop;
832
833                         Source := Src_Data.Next_In_Project;
834                      end;
835                   end loop Source_Loop;
836
837                   if Source = No_Source then
838                      Report_No_Sources
839                        (Project,
840                         Get_Name_String
841                           (In_Tree.Languages_Data.Table
842                              (Language).Display_Name),
843                         In_Tree,
844                         Data.Location,
845                         Continuation);
846                      Continuation := True;
847                   end if;
848
849                   Language := In_Tree.Languages_Data.Table (Language).Next;
850                end loop;
851             end;
852          end if;
853       end if;
854
855       if Get_Mode = Multi_Language then
856
857          --  If a list of sources is specified in attribute Interfaces, set
858          --  In_Interfaces only for the sources specified in the list.
859
860          Check_Interfaces (Project, In_Tree, Data);
861       end if;
862
863       --  If it is a library project file, check if it is a standalone library
864
865       if Data.Library then
866          Check_Stand_Alone_Library
867            (Project, In_Tree, Data, Current_Dir, Extending);
868       end if;
869
870       --  Put the list of Mains, if any, in the project data
871
872       Get_Mains (Project, In_Tree, Data);
873
874       --  Update the project data in the Projects table
875
876       In_Tree.Projects.Table (Project) := Data;
877
878       Free_Ada_Naming_Exceptions;
879    end Check;
880
881    --------------------
882    -- Check_Ada_Name --
883    --------------------
884
885    procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
886       The_Name        : String := Name;
887       Real_Name       : Name_Id;
888       Need_Letter     : Boolean := True;
889       Last_Underscore : Boolean := False;
890       OK              : Boolean := The_Name'Length > 0;
891       First           : Positive;
892
893       function Is_Reserved (Name : Name_Id) return Boolean;
894       function Is_Reserved (S    : String)  return Boolean;
895       --  Check that the given name is not an Ada 95 reserved word. The reason
896       --  for the Ada 95 here is that we do not want to exclude the case of an
897       --  Ada 95 unit called Interface (for example). In Ada 2005, such a unit
898       --  name would be rejected anyway by the compiler. That means there is no
899       --  requirement that the project file parser reject this.
900
901       -----------------
902       -- Is_Reserved --
903       -----------------
904
905       function Is_Reserved (S : String) return Boolean is
906       begin
907          Name_Len := 0;
908          Add_Str_To_Name_Buffer (S);
909          return Is_Reserved (Name_Find);
910       end Is_Reserved;
911
912       -----------------
913       -- Is_Reserved --
914       -----------------
915
916       function Is_Reserved (Name : Name_Id) return Boolean is
917       begin
918          if Get_Name_Table_Byte (Name) /= 0
919            and then Name /= Name_Project
920            and then Name /= Name_Extends
921            and then Name /= Name_External
922            and then Name not in Ada_2005_Reserved_Words
923          then
924             Unit := No_Name;
925
926             if Current_Verbosity = High then
927                Write_Str (The_Name);
928                Write_Line (" is an Ada reserved word.");
929             end if;
930
931             return True;
932
933          else
934             return False;
935          end if;
936       end Is_Reserved;
937
938    --  Start of processing for Check_Ada_Name
939
940    begin
941       To_Lower (The_Name);
942
943       Name_Len := The_Name'Length;
944       Name_Buffer (1 .. Name_Len) := The_Name;
945
946       --  Special cases of children of packages A, G, I and S on VMS
947
948       if OpenVMS_On_Target
949         and then Name_Len > 3
950         and then Name_Buffer (2 .. 3) = "__"
951         and then
952           ((Name_Buffer (1) = 'a') or else
953            (Name_Buffer (1) = 'g') or else
954            (Name_Buffer (1) = 'i') or else
955            (Name_Buffer (1) = 's'))
956       then
957          Name_Buffer (2) := '.';
958          Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
959          Name_Len := Name_Len - 1;
960       end if;
961
962       Real_Name := Name_Find;
963
964       if Is_Reserved (Real_Name) then
965          return;
966       end if;
967
968       First := The_Name'First;
969
970       for Index in The_Name'Range loop
971          if Need_Letter then
972
973             --  We need a letter (at the beginning, and following a dot),
974             --  but we don't have one.
975
976             if Is_Letter (The_Name (Index)) then
977                Need_Letter := False;
978
979             else
980                OK := False;
981
982                if Current_Verbosity = High then
983                   Write_Int  (Types.Int (Index));
984                   Write_Str  (": '");
985                   Write_Char (The_Name (Index));
986                   Write_Line ("' is not a letter.");
987                end if;
988
989                exit;
990             end if;
991
992          elsif Last_Underscore
993            and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
994          then
995             --  Two underscores are illegal, and a dot cannot follow
996             --  an underscore.
997
998             OK := False;
999
1000             if Current_Verbosity = High then
1001                Write_Int  (Types.Int (Index));
1002                Write_Str  (": '");
1003                Write_Char (The_Name (Index));
1004                Write_Line ("' is illegal here.");
1005             end if;
1006
1007             exit;
1008
1009          elsif The_Name (Index) = '.' then
1010
1011             --  First, check if the name before the dot is not a reserved word
1012             if Is_Reserved (The_Name (First .. Index - 1)) then
1013                return;
1014             end if;
1015
1016             First := Index + 1;
1017
1018             --  We need a letter after a dot
1019
1020             Need_Letter := True;
1021
1022          elsif The_Name (Index) = '_' then
1023             Last_Underscore := True;
1024
1025          else
1026             --  We need an letter or a digit
1027
1028             Last_Underscore := False;
1029
1030             if not Is_Alphanumeric (The_Name (Index)) then
1031                OK := False;
1032
1033                if Current_Verbosity = High then
1034                   Write_Int  (Types.Int (Index));
1035                   Write_Str  (": '");
1036                   Write_Char (The_Name (Index));
1037                   Write_Line ("' is not alphanumeric.");
1038                end if;
1039
1040                exit;
1041             end if;
1042          end if;
1043       end loop;
1044
1045       --  Cannot end with an underscore or a dot
1046
1047       OK := OK and then not Need_Letter and then not Last_Underscore;
1048
1049       if OK then
1050          if First /= Name'First and then
1051            Is_Reserved (The_Name (First .. The_Name'Last))
1052          then
1053             return;
1054          end if;
1055
1056          Unit := Real_Name;
1057
1058       else
1059          --  Signal a problem with No_Name
1060
1061          Unit := No_Name;
1062       end if;
1063    end Check_Ada_Name;
1064
1065    --------------------------------------
1066    -- Check_Ada_Naming_Scheme_Validity --
1067    --------------------------------------
1068
1069    procedure Check_Ada_Naming_Scheme_Validity
1070      (Project : Project_Id;
1071       In_Tree : Project_Tree_Ref;
1072       Naming  : Naming_Data)
1073    is
1074    begin
1075       --  Only check if we are not using the Default naming scheme
1076
1077       if Naming /= In_Tree.Private_Part.Default_Naming then
1078          declare
1079             Dot_Replacement : constant String :=
1080                                 Get_Name_String
1081                                   (Naming.Dot_Replacement);
1082
1083             Spec_Suffix : constant String :=
1084                                   Spec_Suffix_Of (In_Tree, "ada", Naming);
1085
1086             Body_Suffix : constant String :=
1087                                   Body_Suffix_Of (In_Tree, "ada", Naming);
1088
1089             Separate_Suffix : constant String :=
1090                                 Get_Name_String
1091                                   (Naming.Separate_Suffix);
1092
1093          begin
1094             --  Dot_Replacement cannot
1095
1096             --   - be empty
1097             --   - start or end with an alphanumeric
1098             --   - be a single '_'
1099             --   - start with an '_' followed by an alphanumeric
1100             --   - contain a '.' except if it is "."
1101
1102             if Dot_Replacement'Length = 0
1103               or else Is_Alphanumeric
1104                         (Dot_Replacement (Dot_Replacement'First))
1105               or else Is_Alphanumeric
1106                         (Dot_Replacement (Dot_Replacement'Last))
1107               or else (Dot_Replacement (Dot_Replacement'First) = '_'
1108                         and then
1109                         (Dot_Replacement'Length = 1
1110                           or else
1111                            Is_Alphanumeric
1112                              (Dot_Replacement (Dot_Replacement'First + 1))))
1113               or else (Dot_Replacement'Length > 1
1114                          and then
1115                            Index (Source => Dot_Replacement,
1116                                   Pattern => ".") /= 0)
1117             then
1118                Error_Msg
1119                  (Project, In_Tree,
1120                   '"' & Dot_Replacement &
1121                   """ is illegal for Dot_Replacement.",
1122                   Naming.Dot_Repl_Loc);
1123             end if;
1124
1125             --  Suffixes cannot
1126             --   - be empty
1127
1128             if Is_Illegal_Suffix
1129                  (Spec_Suffix, Dot_Replacement = ".")
1130             then
1131                Err_Vars.Error_Msg_File_1 :=
1132                  Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
1133                Error_Msg
1134                  (Project, In_Tree,
1135                   "{ is illegal for Spec_Suffix",
1136                   Naming.Ada_Spec_Suffix_Loc);
1137             end if;
1138
1139             if Is_Illegal_Suffix
1140                  (Body_Suffix, Dot_Replacement = ".")
1141             then
1142                Err_Vars.Error_Msg_File_1 :=
1143                  Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
1144                Error_Msg
1145                  (Project, In_Tree,
1146                   "{ is illegal for Body_Suffix",
1147                   Naming.Ada_Body_Suffix_Loc);
1148             end if;
1149
1150             if Body_Suffix /= Separate_Suffix then
1151                if Is_Illegal_Suffix
1152                     (Separate_Suffix, Dot_Replacement = ".")
1153                then
1154                   Err_Vars.Error_Msg_File_1 := Naming.Separate_Suffix;
1155                   Error_Msg
1156                     (Project, In_Tree,
1157                      "{ is illegal for Separate_Suffix",
1158                      Naming.Sep_Suffix_Loc);
1159                end if;
1160             end if;
1161
1162             --  Spec_Suffix cannot be equal to Body_Suffix Separate_Suffix,
1163             --  since that would cause a clear ambiguity. Note that we do
1164             --  allow a Spec_Suffix to have the same termination as one of
1165             --  these, which causes a potential ambiguity, but we resolve
1166             --  that my matching the longest possible suffix.
1167
1168             if Spec_Suffix = Body_Suffix then
1169                Error_Msg
1170                  (Project, In_Tree,
1171                   "Body_Suffix (""" &
1172                   Body_Suffix &
1173                   """) cannot be the same as Spec_Suffix.",
1174                   Naming.Ada_Body_Suffix_Loc);
1175             end if;
1176
1177             if Body_Suffix /= Separate_Suffix
1178               and then Spec_Suffix = Separate_Suffix
1179             then
1180                Error_Msg
1181                  (Project, In_Tree,
1182                   "Separate_Suffix (""" &
1183                   Separate_Suffix &
1184                   """) cannot be the same as Spec_Suffix.",
1185                   Naming.Sep_Suffix_Loc);
1186             end if;
1187          end;
1188       end if;
1189    end Check_Ada_Naming_Scheme_Validity;
1190
1191    -------------------------
1192    -- Check_Configuration --
1193    -------------------------
1194
1195    procedure Check_Configuration
1196      (Project : Project_Id;
1197       In_Tree : Project_Tree_Ref;
1198       Data    : in out Project_Data)
1199    is
1200       Dot_Replacement : File_Name_Type := No_File;
1201       Casing          : Casing_Type    := All_Lower_Case;
1202       Separate_Suffix : File_Name_Type := No_File;
1203
1204       Lang_Index : Language_Index := No_Language_Index;
1205       --  The index of the language data being checked
1206
1207       Prev_Index : Language_Index := No_Language_Index;
1208       --  The index of the previous language
1209
1210       Current_Language : Name_Id := No_Name;
1211       --  The name of the language
1212
1213       Lang_Data : Language_Data;
1214       --  The data of the language being checked
1215
1216       procedure Get_Language_Index_Of (Language : Name_Id);
1217       --  Get the language index of Language, if Language is one of the
1218       --  languages of the project.
1219
1220       procedure Process_Project_Level_Simple_Attributes;
1221       --  Process the simple attributes at the project level
1222
1223       procedure Process_Project_Level_Array_Attributes;
1224       --  Process the associate array attributes at the project level
1225
1226       procedure Process_Packages;
1227       --  Read the packages of the project
1228
1229       ---------------------------
1230       -- Get_Language_Index_Of --
1231       ---------------------------
1232
1233       procedure Get_Language_Index_Of (Language : Name_Id) is
1234          Real_Language : Name_Id;
1235
1236       begin
1237          Get_Name_String (Language);
1238          To_Lower (Name_Buffer (1 .. Name_Len));
1239          Real_Language := Name_Find;
1240
1241          --  Nothing to do if the language is the same as the current language
1242
1243          if Current_Language /= Real_Language then
1244             Lang_Index := Data.First_Language_Processing;
1245             while Lang_Index /= No_Language_Index loop
1246                exit when In_Tree.Languages_Data.Table (Lang_Index).Name =
1247                  Real_Language;
1248                Lang_Index :=
1249                  In_Tree.Languages_Data.Table (Lang_Index).Next;
1250             end loop;
1251
1252             if Lang_Index = No_Language_Index then
1253                Current_Language := No_Name;
1254             else
1255                Current_Language := Real_Language;
1256             end if;
1257          end if;
1258       end Get_Language_Index_Of;
1259
1260       ----------------------
1261       -- Process_Packages --
1262       ----------------------
1263
1264       procedure Process_Packages is
1265          Packages : Package_Id;
1266          Element  : Package_Element;
1267
1268          procedure Process_Binder (Arrays : Array_Id);
1269          --  Process the associate array attributes of package Binder
1270
1271          procedure Process_Builder (Attributes : Variable_Id);
1272          --  Process the simple attributes of package Builder
1273
1274          procedure Process_Compiler (Arrays : Array_Id);
1275          --  Process the associate array attributes of package Compiler
1276
1277          procedure Process_Naming (Attributes : Variable_Id);
1278          --  Process the simple attributes of package Naming
1279
1280          procedure Process_Naming (Arrays : Array_Id);
1281          --  Process the associate array attributes of package Naming
1282
1283          procedure Process_Linker (Attributes : Variable_Id);
1284          --  Process the simple attributes of package Linker of a
1285          --  configuration project.
1286
1287          --------------------
1288          -- Process_Binder --
1289          --------------------
1290
1291          procedure Process_Binder (Arrays : Array_Id) is
1292             Current_Array_Id : Array_Id;
1293             Current_Array    : Array_Data;
1294             Element_Id       : Array_Element_Id;
1295             Element          : Array_Element;
1296
1297          begin
1298             --  Process the associative array attribute of package Binder
1299
1300             Current_Array_Id := Arrays;
1301             while Current_Array_Id /= No_Array loop
1302                Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1303
1304                Element_Id := Current_Array.Value;
1305                while Element_Id /= No_Array_Element loop
1306                   Element := In_Tree.Array_Elements.Table (Element_Id);
1307
1308                   if Element.Index /= All_Other_Names then
1309
1310                      --  Get the name of the language
1311
1312                      Get_Language_Index_Of (Element.Index);
1313
1314                      if Lang_Index /= No_Language_Index then
1315                         case Current_Array.Name is
1316                         when Name_Driver =>
1317
1318                            --  Attribute Driver (<language>)
1319
1320                            In_Tree.Languages_Data.Table
1321                              (Lang_Index).Config.Binder_Driver :=
1322                              File_Name_Type (Element.Value.Value);
1323
1324                         when Name_Required_Switches =>
1325                            Put (Into_List =>
1326                                 In_Tree.Languages_Data.Table
1327                                   (Lang_Index).Config.Binder_Required_Switches,
1328                                 From_List => Element.Value.Values,
1329                                 In_Tree   => In_Tree);
1330
1331                         when Name_Prefix =>
1332
1333                            --  Attribute Prefix (<language>)
1334
1335                            In_Tree.Languages_Data.Table
1336                              (Lang_Index).Config.Binder_Prefix :=
1337                              Element.Value.Value;
1338
1339                         when Name_Objects_Path =>
1340
1341                            --  Attribute Objects_Path (<language>)
1342
1343                            In_Tree.Languages_Data.Table
1344                              (Lang_Index).Config.Objects_Path :=
1345                              Element.Value.Value;
1346
1347                         when Name_Objects_Path_File =>
1348
1349                            --  Attribute Objects_Path (<language>)
1350
1351                            In_Tree.Languages_Data.Table
1352                              (Lang_Index).Config.Objects_Path_File :=
1353                              Element.Value.Value;
1354
1355                         when others =>
1356                            null;
1357                         end case;
1358                      end if;
1359                   end if;
1360
1361                   Element_Id := Element.Next;
1362                end loop;
1363
1364                Current_Array_Id := Current_Array.Next;
1365             end loop;
1366          end Process_Binder;
1367
1368          ---------------------
1369          -- Process_Builder --
1370          ---------------------
1371
1372          procedure Process_Builder (Attributes : Variable_Id) is
1373             Attribute_Id : Variable_Id;
1374             Attribute    : Variable;
1375
1376          begin
1377             --  Process non associated array attribute from package Builder
1378
1379             Attribute_Id := Attributes;
1380             while Attribute_Id /= No_Variable loop
1381                Attribute :=
1382                  In_Tree.Variable_Elements.Table (Attribute_Id);
1383
1384                if not Attribute.Value.Default then
1385                   if Attribute.Name = Name_Executable_Suffix then
1386
1387                      --  Attribute Executable_Suffix: the suffix of the
1388                      --  executables.
1389
1390                      Data.Config.Executable_Suffix :=
1391                        Attribute.Value.Value;
1392                   end if;
1393                end if;
1394
1395                Attribute_Id := Attribute.Next;
1396             end loop;
1397          end Process_Builder;
1398
1399          ----------------------
1400          -- Process_Compiler --
1401          ----------------------
1402
1403          procedure Process_Compiler (Arrays : Array_Id) is
1404             Current_Array_Id : Array_Id;
1405             Current_Array    : Array_Data;
1406             Element_Id       : Array_Element_Id;
1407             Element          : Array_Element;
1408             List             : String_List_Id;
1409
1410          begin
1411             --  Process the associative array attribute of package Compiler
1412
1413             Current_Array_Id := Arrays;
1414             while Current_Array_Id /= No_Array loop
1415                Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1416
1417                Element_Id := Current_Array.Value;
1418                while Element_Id /= No_Array_Element loop
1419                   Element := In_Tree.Array_Elements.Table (Element_Id);
1420
1421                   if Element.Index /= All_Other_Names then
1422
1423                      --  Get the name of the language
1424
1425                      Get_Language_Index_Of (Element.Index);
1426
1427                      if Lang_Index /= No_Language_Index then
1428                         case Current_Array.Name is
1429                         when Name_Dependency_Switches =>
1430
1431                            --  Attribute Dependency_Switches (<language>)
1432
1433                            if In_Tree.Languages_Data.Table
1434                                (Lang_Index).Config.Dependency_Kind = None
1435                            then
1436                               In_Tree.Languages_Data.Table
1437                                 (Lang_Index).Config.Dependency_Kind :=
1438                                   Makefile;
1439                            end if;
1440
1441                            List := Element.Value.Values;
1442
1443                            if List /= Nil_String then
1444                               Put (Into_List =>
1445                                      In_Tree.Languages_Data.Table
1446                                        (Lang_Index).Config.Dependency_Option,
1447                                    From_List => List,
1448                                    In_Tree   => In_Tree);
1449                            end if;
1450
1451                         when Name_Dependency_Driver =>
1452
1453                            --  Attribute Dependency_Driver (<language>)
1454
1455                            if In_Tree.Languages_Data.Table
1456                                (Lang_Index).Config.Dependency_Kind = None
1457                            then
1458                               In_Tree.Languages_Data.Table
1459                                 (Lang_Index).Config.Dependency_Kind :=
1460                                   Makefile;
1461                            end if;
1462
1463                            List := Element.Value.Values;
1464
1465                            if List /= Nil_String then
1466                               Put (Into_List =>
1467                                      In_Tree.Languages_Data.Table
1468                                        (Lang_Index).Config.Compute_Dependency,
1469                                    From_List => List,
1470                                    In_Tree   => In_Tree);
1471                            end if;
1472
1473                         when Name_Include_Switches =>
1474
1475                            --  Attribute Include_Switches (<language>)
1476
1477                            List := Element.Value.Values;
1478
1479                            if List = Nil_String then
1480                               Error_Msg
1481                                 (Project,
1482                                  In_Tree,
1483                                  "include option cannot be null",
1484                                  Element.Value.Location);
1485                            end if;
1486
1487                            Put (Into_List =>
1488                                 In_Tree.Languages_Data.Table
1489                                   (Lang_Index).Config.Include_Option,
1490                                 From_List => List,
1491                                 In_Tree   => In_Tree);
1492
1493                         when Name_Include_Path =>
1494
1495                            --  Attribute Include_Path (<language>)
1496
1497                            In_Tree.Languages_Data.Table
1498                              (Lang_Index).Config.Include_Path :=
1499                              Element.Value.Value;
1500
1501                         when Name_Include_Path_File =>
1502
1503                            --  Attribute Include_Path_File (<language>)
1504
1505                            In_Tree.Languages_Data.Table
1506                              (Lang_Index).Config.Include_Path_File :=
1507                                Element.Value.Value;
1508
1509                         when Name_Driver =>
1510
1511                            --  Attribute Driver (<language>)
1512
1513                            Get_Name_String (Element.Value.Value);
1514
1515                            In_Tree.Languages_Data.Table
1516                              (Lang_Index).Config.Compiler_Driver :=
1517                                File_Name_Type (Element.Value.Value);
1518
1519                         when Name_Required_Switches =>
1520                            Put (Into_List =>
1521                                 In_Tree.Languages_Data.Table
1522                                   (Lang_Index).Config.
1523                                     Compiler_Required_Switches,
1524                                 From_List => Element.Value.Values,
1525                                 In_Tree   => In_Tree);
1526
1527                         when Name_Path_Syntax =>
1528                            begin
1529                               In_Tree.Languages_Data.Table
1530                                 (Lang_Index).Config.Path_Syntax :=
1531                                   Path_Syntax_Kind'Value
1532                                     (Get_Name_String (Element.Value.Value));
1533
1534                            exception
1535                               when Constraint_Error =>
1536                                  Error_Msg
1537                                    (Project,
1538                                     In_Tree,
1539                                     "invalid value for Path_Syntax",
1540                                     Element.Value.Location);
1541                            end;
1542
1543                         when Name_Pic_Option =>
1544
1545                            --  Attribute Compiler_Pic_Option (<language>)
1546
1547                            List := Element.Value.Values;
1548
1549                            if List = Nil_String then
1550                               Error_Msg
1551                                 (Project,
1552                                  In_Tree,
1553                                  "compiler PIC option cannot be null",
1554                                  Element.Value.Location);
1555                            end if;
1556
1557                            Put (Into_List =>
1558                                 In_Tree.Languages_Data.Table
1559                                   (Lang_Index).Config.Compilation_PIC_Option,
1560                                 From_List => List,
1561                                 In_Tree   => In_Tree);
1562
1563                         when Name_Mapping_File_Switches =>
1564
1565                            --  Attribute Mapping_File_Switches (<language>)
1566
1567                            List := Element.Value.Values;
1568
1569                            if List = Nil_String then
1570                               Error_Msg
1571                                 (Project,
1572                                  In_Tree,
1573                                  "mapping file switches cannot be null",
1574                                  Element.Value.Location);
1575                            end if;
1576
1577                            Put (Into_List =>
1578                                 In_Tree.Languages_Data.Table
1579                                   (Lang_Index).Config.Mapping_File_Switches,
1580                                 From_List => List,
1581                                 In_Tree   => In_Tree);
1582
1583                         when Name_Mapping_Spec_Suffix =>
1584
1585                            --  Attribute Mapping_Spec_Suffix (<language>)
1586
1587                            In_Tree.Languages_Data.Table
1588                              (Lang_Index).Config.Mapping_Spec_Suffix :=
1589                                File_Name_Type (Element.Value.Value);
1590
1591                         when Name_Mapping_Body_Suffix =>
1592
1593                            --  Attribute Mapping_Body_Suffix (<language>)
1594
1595                            In_Tree.Languages_Data.Table
1596                              (Lang_Index).Config.Mapping_Body_Suffix :=
1597                                File_Name_Type (Element.Value.Value);
1598
1599                         when Name_Config_File_Switches =>
1600
1601                            --  Attribute Config_File_Switches (<language>)
1602
1603                            List := Element.Value.Values;
1604
1605                            if List = Nil_String then
1606                               Error_Msg
1607                                 (Project,
1608                                  In_Tree,
1609                                  "config file switches cannot be null",
1610                                  Element.Value.Location);
1611                            end if;
1612
1613                            Put (Into_List =>
1614                                   In_Tree.Languages_Data.Table
1615                                     (Lang_Index).Config.Config_File_Switches,
1616                                 From_List => List,
1617                                 In_Tree   => In_Tree);
1618
1619                         when Name_Objects_Path =>
1620
1621                            --  Attribute Objects_Path (<language>)
1622
1623                            In_Tree.Languages_Data.Table
1624                              (Lang_Index).Config.Objects_Path :=
1625                                Element.Value.Value;
1626
1627                         when Name_Objects_Path_File =>
1628
1629                            --  Attribute Objects_Path_File (<language>)
1630
1631                            In_Tree.Languages_Data.Table
1632                              (Lang_Index).Config.Objects_Path_File :=
1633                                Element.Value.Value;
1634
1635                         when Name_Config_Body_File_Name =>
1636
1637                            --  Attribute Config_Body_File_Name (<language>)
1638
1639                            In_Tree.Languages_Data.Table
1640                              (Lang_Index).Config.Config_Body :=
1641                                Element.Value.Value;
1642
1643                         when Name_Config_Body_File_Name_Pattern =>
1644
1645                            --  Attribute Config_Body_File_Name_Pattern
1646                            --  (<language>)
1647
1648                            In_Tree.Languages_Data.Table
1649                              (Lang_Index).Config.Config_Body_Pattern :=
1650                                Element.Value.Value;
1651
1652                         when Name_Config_Spec_File_Name =>
1653
1654                            --  Attribute Config_Spec_File_Name (<language>)
1655
1656                            In_Tree.Languages_Data.Table
1657                              (Lang_Index).Config.Config_Spec :=
1658                                Element.Value.Value;
1659
1660                         when Name_Config_Spec_File_Name_Pattern =>
1661
1662                            --  Attribute Config_Spec_File_Name_Pattern
1663                            --  (<language>)
1664
1665                            In_Tree.Languages_Data.Table
1666                              (Lang_Index).Config.Config_Spec_Pattern :=
1667                              Element.Value.Value;
1668
1669                         when Name_Config_File_Unique =>
1670
1671                            --  Attribute Config_File_Unique (<language>)
1672
1673                            begin
1674                               In_Tree.Languages_Data.Table
1675                                 (Lang_Index).Config.Config_File_Unique :=
1676                                   Boolean'Value
1677                                     (Get_Name_String (Element.Value.Value));
1678                            exception
1679                               when Constraint_Error =>
1680                                  Error_Msg
1681                                    (Project,
1682                                     In_Tree,
1683                                     "illegal value for Config_File_Unique",
1684                                     Element.Value.Location);
1685                            end;
1686
1687                         when others =>
1688                            null;
1689                         end case;
1690                      end if;
1691                   end if;
1692
1693                   Element_Id := Element.Next;
1694                end loop;
1695
1696                Current_Array_Id := Current_Array.Next;
1697             end loop;
1698          end Process_Compiler;
1699
1700          --------------------
1701          -- Process_Naming --
1702          --------------------
1703
1704          procedure Process_Naming (Attributes : Variable_Id) is
1705             Attribute_Id : Variable_Id;
1706             Attribute    : Variable;
1707
1708          begin
1709             --  Process non associated array attribute from package Naming
1710
1711             Attribute_Id := Attributes;
1712             while Attribute_Id /= No_Variable loop
1713                Attribute := In_Tree.Variable_Elements.Table (Attribute_Id);
1714
1715                if not Attribute.Value.Default then
1716                   if Attribute.Name = Name_Separate_Suffix then
1717
1718                      --  Attribute Separate_Suffix
1719
1720                      Separate_Suffix := File_Name_Type (Attribute.Value.Value);
1721
1722                   elsif Attribute.Name = Name_Casing then
1723
1724                      --  Attribute Casing
1725
1726                      begin
1727                         Casing :=
1728                           Value (Get_Name_String (Attribute.Value.Value));
1729
1730                      exception
1731                         when Constraint_Error =>
1732                            Error_Msg
1733                              (Project,
1734                               In_Tree,
1735                               "invalid value for Casing",
1736                               Attribute.Value.Location);
1737                      end;
1738
1739                   elsif Attribute.Name = Name_Dot_Replacement then
1740
1741                      --  Attribute Dot_Replacement
1742
1743                      Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1744
1745                   end if;
1746                end if;
1747
1748                Attribute_Id := Attribute.Next;
1749             end loop;
1750          end Process_Naming;
1751
1752          procedure Process_Naming (Arrays : Array_Id) is
1753             Current_Array_Id : Array_Id;
1754             Current_Array    : Array_Data;
1755             Element_Id       : Array_Element_Id;
1756             Element          : Array_Element;
1757          begin
1758             --  Process the associative array attribute of package Naming
1759
1760             Current_Array_Id := Arrays;
1761             while Current_Array_Id /= No_Array loop
1762                Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1763
1764                Element_Id := Current_Array.Value;
1765                while Element_Id /= No_Array_Element loop
1766                   Element := In_Tree.Array_Elements.Table (Element_Id);
1767
1768                   --  Get the name of the language
1769
1770                   Get_Language_Index_Of (Element.Index);
1771
1772                   if Lang_Index /= No_Language_Index then
1773                      case Current_Array.Name is
1774                         when Name_Specification_Suffix | Name_Spec_Suffix =>
1775
1776                            --  Attribute Spec_Suffix (<language>)
1777
1778                            In_Tree.Languages_Data.Table
1779                              (Lang_Index).Config.Naming_Data.Spec_Suffix :=
1780                                File_Name_Type (Element.Value.Value);
1781
1782                         when Name_Implementation_Suffix | Name_Body_Suffix =>
1783
1784                            --  Attribute Body_Suffix (<language>)
1785
1786                            In_Tree.Languages_Data.Table
1787                              (Lang_Index).Config.Naming_Data.Body_Suffix :=
1788                                File_Name_Type (Element.Value.Value);
1789
1790                            In_Tree.Languages_Data.Table
1791                              (Lang_Index).Config.Naming_Data.Separate_Suffix :=
1792                                File_Name_Type (Element.Value.Value);
1793
1794                         when others =>
1795                            null;
1796                      end case;
1797                   end if;
1798
1799                   Element_Id := Element.Next;
1800                end loop;
1801
1802                Current_Array_Id := Current_Array.Next;
1803             end loop;
1804          end Process_Naming;
1805
1806          --------------------
1807          -- Process_Linker --
1808          --------------------
1809
1810          procedure Process_Linker (Attributes : Variable_Id) is
1811             Attribute_Id : Variable_Id;
1812             Attribute    : Variable;
1813
1814          begin
1815             --  Process non associated array attribute from package Linker
1816
1817             Attribute_Id := Attributes;
1818             while Attribute_Id /= No_Variable loop
1819                Attribute :=
1820                  In_Tree.Variable_Elements.Table (Attribute_Id);
1821
1822                if not Attribute.Value.Default then
1823                   if Attribute.Name = Name_Driver then
1824
1825                      --  Attribute Linker'Driver: the default linker to use
1826
1827                      Data.Config.Linker :=
1828                        Path_Name_Type (Attribute.Value.Value);
1829
1830                   elsif Attribute.Name = Name_Required_Switches then
1831
1832                      --  Attribute Required_Switches: the minimum
1833                      --  options to use when invoking the linker
1834
1835                      Put (Into_List =>
1836                             Data.Config.Minimum_Linker_Options,
1837                           From_List => Attribute.Value.Values,
1838                           In_Tree   => In_Tree);
1839
1840                   elsif Attribute.Name = Name_Map_File_Option then
1841                      Data.Config.Map_File_Option := Attribute.Value.Value;
1842                   end if;
1843                end if;
1844
1845                Attribute_Id := Attribute.Next;
1846             end loop;
1847          end Process_Linker;
1848
1849       --  Start of processing for Process_Packages
1850
1851       begin
1852          Packages := Data.Decl.Packages;
1853          while Packages /= No_Package loop
1854             Element := In_Tree.Packages.Table (Packages);
1855
1856             case Element.Name is
1857                when Name_Binder =>
1858
1859                   --  Process attributes of package Binder
1860
1861                   Process_Binder (Element.Decl.Arrays);
1862
1863                when Name_Builder =>
1864
1865                   --  Process attributes of package Builder
1866
1867                   Process_Builder (Element.Decl.Attributes);
1868
1869                when Name_Compiler =>
1870
1871                   --  Process attributes of package Compiler
1872
1873                   Process_Compiler (Element.Decl.Arrays);
1874
1875                when Name_Linker =>
1876
1877                   --  Process attributes of package Linker
1878
1879                   Process_Linker (Element.Decl.Attributes);
1880
1881                when Name_Naming =>
1882
1883                   --  Process attributes of package Naming
1884
1885                   Process_Naming (Element.Decl.Attributes);
1886                   Process_Naming (Element.Decl.Arrays);
1887
1888                when others =>
1889                   null;
1890             end case;
1891
1892             Packages := Element.Next;
1893          end loop;
1894       end Process_Packages;
1895
1896       ---------------------------------------------
1897       -- Process_Project_Level_Simple_Attributes --
1898       ---------------------------------------------
1899
1900       procedure Process_Project_Level_Simple_Attributes is
1901          Attribute_Id : Variable_Id;
1902          Attribute    : Variable;
1903          List         : String_List_Id;
1904
1905       begin
1906          --  Process non associated array attribute at project level
1907
1908          Attribute_Id := Data.Decl.Attributes;
1909          while Attribute_Id /= No_Variable loop
1910             Attribute :=
1911               In_Tree.Variable_Elements.Table (Attribute_Id);
1912
1913             if not Attribute.Value.Default then
1914                if Attribute.Name = Name_Library_Builder then
1915
1916                   --  Attribute Library_Builder: the application to invoke
1917                   --  to build libraries.
1918
1919                   Data.Config.Library_Builder :=
1920                     Path_Name_Type (Attribute.Value.Value);
1921
1922                elsif Attribute.Name = Name_Archive_Builder then
1923
1924                   --  Attribute Archive_Builder: the archive builder
1925                   --  (usually "ar") and its minimum options (usually "cr").
1926
1927                   List := Attribute.Value.Values;
1928
1929                   if List = Nil_String then
1930                      Error_Msg
1931                        (Project,
1932                         In_Tree,
1933                         "archive builder cannot be null",
1934                         Attribute.Value.Location);
1935                   end if;
1936
1937                   Put (Into_List => Data.Config.Archive_Builder,
1938                        From_List => List,
1939                        In_Tree   => In_Tree);
1940
1941                elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1942
1943                   --  Attribute Archive_Builder: the archive builder
1944                   --  (usually "ar") and its minimum options (usually "cr").
1945
1946                   List := Attribute.Value.Values;
1947
1948                   if List /= Nil_String then
1949                      Put
1950                        (Into_List => Data.Config.Archive_Builder_Append_Option,
1951                         From_List => List,
1952                         In_Tree   => In_Tree);
1953                   end if;
1954
1955                elsif Attribute.Name = Name_Archive_Indexer then
1956
1957                   --  Attribute Archive_Indexer: the optional archive
1958                   --  indexer (usually "ranlib") with its minimum options
1959                   --  (usually none).
1960
1961                   List := Attribute.Value.Values;
1962
1963                   if List = Nil_String then
1964                      Error_Msg
1965                        (Project,
1966                         In_Tree,
1967                         "archive indexer cannot be null",
1968                         Attribute.Value.Location);
1969                   end if;
1970
1971                   Put (Into_List => Data.Config.Archive_Indexer,
1972                        From_List => List,
1973                        In_Tree   => In_Tree);
1974
1975                elsif Attribute.Name = Name_Library_Partial_Linker then
1976
1977                   --  Attribute Library_Partial_Linker: the optional linker
1978                   --  driver with its minimum options, to partially link
1979                   --  archives.
1980
1981                   List := Attribute.Value.Values;
1982
1983                   if List = Nil_String then
1984                      Error_Msg
1985                        (Project,
1986                         In_Tree,
1987                         "partial linker cannot be null",
1988                         Attribute.Value.Location);
1989                   end if;
1990
1991                   Put (Into_List => Data.Config.Lib_Partial_Linker,
1992                        From_List => List,
1993                        In_Tree   => In_Tree);
1994
1995                elsif Attribute.Name = Name_Library_GCC then
1996                   Data.Config.Shared_Lib_Driver :=
1997                     File_Name_Type (Attribute.Value.Value);
1998
1999                elsif Attribute.Name = Name_Archive_Suffix then
2000                   Data.Config.Archive_Suffix :=
2001                     File_Name_Type (Attribute.Value.Value);
2002
2003                elsif Attribute.Name = Name_Linker_Executable_Option then
2004
2005                   --  Attribute Linker_Executable_Option: optional options
2006                   --  to specify an executable name. Defaults to "-o".
2007
2008                   List := Attribute.Value.Values;
2009
2010                   if List = Nil_String then
2011                      Error_Msg
2012                        (Project,
2013                         In_Tree,
2014                         "linker executable option cannot be null",
2015                         Attribute.Value.Location);
2016                   end if;
2017
2018                   Put (Into_List => Data.Config.Linker_Executable_Option,
2019                        From_List => List,
2020                        In_Tree   => In_Tree);
2021
2022                elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2023
2024                   --  Attribute Linker_Lib_Dir_Option: optional options
2025                   --  to specify a library search directory. Defaults to
2026                   --  "-L".
2027
2028                   Get_Name_String (Attribute.Value.Value);
2029
2030                   if Name_Len = 0 then
2031                      Error_Msg
2032                        (Project,
2033                         In_Tree,
2034                         "linker library directory option cannot be empty",
2035                         Attribute.Value.Location);
2036                   end if;
2037
2038                   Data.Config.Linker_Lib_Dir_Option := Attribute.Value.Value;
2039
2040                elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2041
2042                   --  Attribute Linker_Lib_Name_Option: optional options
2043                   --  to specify the name of a library to be linked in.
2044                   --  Defaults to "-l".
2045
2046                   Get_Name_String (Attribute.Value.Value);
2047
2048                   if Name_Len = 0 then
2049                      Error_Msg
2050                        (Project,
2051                         In_Tree,
2052                         "linker library name option cannot be empty",
2053                         Attribute.Value.Location);
2054                   end if;
2055
2056                   Data.Config.Linker_Lib_Name_Option := Attribute.Value.Value;
2057
2058                elsif Attribute.Name = Name_Run_Path_Option then
2059
2060                   --  Attribute Run_Path_Option: optional options to
2061                   --  specify a path for libraries.
2062
2063                   List := Attribute.Value.Values;
2064
2065                   if List /= Nil_String then
2066                      Put (Into_List => Data.Config.Run_Path_Option,
2067                           From_List => List,
2068                           In_Tree   => In_Tree);
2069                   end if;
2070
2071                elsif Attribute.Name = Name_Library_Support then
2072                   declare
2073                      pragma Unsuppress (All_Checks);
2074                   begin
2075                      Data.Config.Lib_Support :=
2076                        Library_Support'Value (Get_Name_String
2077                                               (Attribute.Value.Value));
2078                   exception
2079                      when Constraint_Error =>
2080                         Error_Msg
2081                           (Project,
2082                            In_Tree,
2083                            "invalid value """ &
2084                            Get_Name_String (Attribute.Value.Value) &
2085                            """ for Library_Support",
2086                            Attribute.Value.Location);
2087                   end;
2088
2089                elsif Attribute.Name = Name_Shared_Library_Prefix then
2090                   Data.Config.Shared_Lib_Prefix :=
2091                     File_Name_Type (Attribute.Value.Value);
2092
2093                elsif Attribute.Name = Name_Shared_Library_Suffix then
2094                   Data.Config.Shared_Lib_Suffix :=
2095                     File_Name_Type (Attribute.Value.Value);
2096
2097                elsif Attribute.Name = Name_Symbolic_Link_Supported then
2098                   declare
2099                      pragma Unsuppress (All_Checks);
2100                   begin
2101                      Data.Config.Symbolic_Link_Supported :=
2102                        Boolean'Value (Get_Name_String
2103                                       (Attribute.Value.Value));
2104                   exception
2105                      when Constraint_Error =>
2106                         Error_Msg
2107                           (Project,
2108                            In_Tree,
2109                            "invalid value """
2110                              & Get_Name_String (Attribute.Value.Value)
2111                              & """ for Symbolic_Link_Supported",
2112                            Attribute.Value.Location);
2113                   end;
2114
2115                elsif
2116                  Attribute.Name = Name_Library_Major_Minor_Id_Supported
2117                then
2118                   declare
2119                      pragma Unsuppress (All_Checks);
2120                   begin
2121                      Data.Config.Lib_Maj_Min_Id_Supported :=
2122                        Boolean'Value (Get_Name_String
2123                                       (Attribute.Value.Value));
2124                   exception
2125                      when Constraint_Error =>
2126                         Error_Msg
2127                           (Project,
2128                            In_Tree,
2129                            "invalid value """ &
2130                            Get_Name_String (Attribute.Value.Value) &
2131                            """ for Library_Major_Minor_Id_Supported",
2132                            Attribute.Value.Location);
2133                   end;
2134
2135                elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2136                   declare
2137                      pragma Unsuppress (All_Checks);
2138                   begin
2139                      Data.Config.Auto_Init_Supported :=
2140                        Boolean'Value (Get_Name_String (Attribute.Value.Value));
2141                   exception
2142                      when Constraint_Error =>
2143                         Error_Msg
2144                           (Project,
2145                            In_Tree,
2146                            "invalid value """
2147                              & Get_Name_String (Attribute.Value.Value)
2148                              & """ for Library_Auto_Init_Supported",
2149                            Attribute.Value.Location);
2150                   end;
2151
2152                elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2153                   List := Attribute.Value.Values;
2154
2155                   if List /= Nil_String then
2156                      Put (Into_List => Data.Config.Shared_Lib_Min_Options,
2157                           From_List => List,
2158                           In_Tree   => In_Tree);
2159                   end if;
2160
2161                elsif Attribute.Name = Name_Library_Version_Switches then
2162                   List := Attribute.Value.Values;
2163
2164                   if List /= Nil_String then
2165                      Put (Into_List => Data.Config.Lib_Version_Options,
2166                           From_List => List,
2167                           In_Tree   => In_Tree);
2168                   end if;
2169                end if;
2170             end if;
2171
2172             Attribute_Id := Attribute.Next;
2173          end loop;
2174       end Process_Project_Level_Simple_Attributes;
2175
2176       --------------------------------------------
2177       -- Process_Project_Level_Array_Attributes --
2178       --------------------------------------------
2179
2180       procedure Process_Project_Level_Array_Attributes is
2181          Current_Array_Id : Array_Id;
2182          Current_Array    : Array_Data;
2183          Element_Id       : Array_Element_Id;
2184          Element          : Array_Element;
2185          List             : String_List_Id;
2186
2187       begin
2188          --  Process the associative array attributes at project level
2189
2190          Current_Array_Id := Data.Decl.Arrays;
2191          while Current_Array_Id /= No_Array loop
2192             Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
2193
2194             Element_Id := Current_Array.Value;
2195             while Element_Id /= No_Array_Element loop
2196                Element := In_Tree.Array_Elements.Table (Element_Id);
2197
2198                --  Get the name of the language
2199
2200                Get_Language_Index_Of (Element.Index);
2201
2202                if Lang_Index /= No_Language_Index then
2203                   case Current_Array.Name is
2204                      when Name_Inherit_Source_Path =>
2205                         List := Element.Value.Values;
2206
2207                         if List /= Nil_String then
2208                            Put
2209                              (Into_List  =>
2210                                 In_Tree.Languages_Data.Table (Lang_Index).
2211                                   Config.Include_Compatible_Languages,
2212                               From_List  => List,
2213                               In_Tree    => In_Tree,
2214                               Lower_Case => True);
2215                         end if;
2216
2217                      when Name_Toolchain_Description =>
2218
2219                         --  Attribute Toolchain_Description (<language>)
2220
2221                         In_Tree.Languages_Data.Table
2222                           (Lang_Index).Config.Toolchain_Description :=
2223                           Element.Value.Value;
2224
2225                      when Name_Toolchain_Version =>
2226
2227                         --  Attribute Toolchain_Version (<language>)
2228
2229                         In_Tree.Languages_Data.Table
2230                           (Lang_Index).Config.Toolchain_Version :=
2231                           Element.Value.Value;
2232
2233                      when Name_Runtime_Library_Dir =>
2234
2235                         --  Attribute Runtime_Library_Dir (<language>)
2236
2237                         In_Tree.Languages_Data.Table
2238                           (Lang_Index).Config.Runtime_Library_Dir :=
2239                           Element.Value.Value;
2240
2241                      when Name_Object_Generated =>
2242                         declare
2243                            pragma Unsuppress (All_Checks);
2244                            Value : Boolean;
2245
2246                         begin
2247                            Value :=
2248                              Boolean'Value
2249                                (Get_Name_String (Element.Value.Value));
2250
2251                            In_Tree.Languages_Data.Table
2252                              (Lang_Index).Config.Object_Generated := Value;
2253
2254                            --  If no object is generated, no object may be
2255                            --  linked.
2256
2257                            if not Value then
2258                               In_Tree.Languages_Data.Table
2259                                 (Lang_Index).Config.Objects_Linked := False;
2260                            end if;
2261
2262                         exception
2263                            when Constraint_Error =>
2264                               Error_Msg
2265                                 (Project,
2266                                  In_Tree,
2267                                  "invalid value """
2268                                  & Get_Name_String (Element.Value.Value)
2269                                  & """ for Object_Generated",
2270                                  Element.Value.Location);
2271                         end;
2272
2273                      when Name_Objects_Linked =>
2274                         declare
2275                            pragma Unsuppress (All_Checks);
2276                            Value : Boolean;
2277
2278                         begin
2279                            Value :=
2280                              Boolean'Value
2281                                (Get_Name_String (Element.Value.Value));
2282
2283                            --  No change if Object_Generated is False, as this
2284                            --  forces Objects_Linked to be False too.
2285
2286                            if In_Tree.Languages_Data.Table
2287                              (Lang_Index).Config.Object_Generated
2288                            then
2289                               In_Tree.Languages_Data.Table
2290                                 (Lang_Index).Config.Objects_Linked :=
2291                                 Value;
2292                            end if;
2293
2294                         exception
2295                            when Constraint_Error =>
2296                               Error_Msg
2297                                 (Project,
2298                                  In_Tree,
2299                                  "invalid value """
2300                                  & Get_Name_String (Element.Value.Value)
2301                                  & """ for Objects_Linked",
2302                                  Element.Value.Location);
2303                         end;
2304                      when others =>
2305                         null;
2306                   end case;
2307                end if;
2308
2309                Element_Id := Element.Next;
2310             end loop;
2311
2312             Current_Array_Id := Current_Array.Next;
2313          end loop;
2314       end Process_Project_Level_Array_Attributes;
2315
2316    begin
2317       Process_Project_Level_Simple_Attributes;
2318       Process_Project_Level_Array_Attributes;
2319       Process_Packages;
2320
2321       --  For unit based languages, set Casing, Dot_Replacement and
2322       --  Separate_Suffix in Naming_Data.
2323
2324       Lang_Index := Data.First_Language_Processing;
2325       while Lang_Index /= No_Language_Index loop
2326          if In_Tree.Languages_Data.Table
2327            (Lang_Index).Name = Name_Ada
2328          then
2329             In_Tree.Languages_Data.Table
2330               (Lang_Index).Config.Naming_Data.Casing := Casing;
2331             In_Tree.Languages_Data.Table
2332               (Lang_Index).Config.Naming_Data.Dot_Replacement :=
2333               Dot_Replacement;
2334
2335             if Separate_Suffix /= No_File then
2336                In_Tree.Languages_Data.Table
2337                  (Lang_Index).Config.Naming_Data.Separate_Suffix :=
2338                  Separate_Suffix;
2339             end if;
2340
2341             exit;
2342          end if;
2343
2344          Lang_Index := In_Tree.Languages_Data.Table (Lang_Index).Next;
2345       end loop;
2346
2347       --  Give empty names to various prefixes/suffixes, if they have not
2348       --  been specified in the configuration.
2349
2350       if Data.Config.Archive_Suffix = No_File then
2351          Data.Config.Archive_Suffix := Empty_File;
2352       end if;
2353
2354       if Data.Config.Shared_Lib_Prefix = No_File then
2355          Data.Config.Shared_Lib_Prefix := Empty_File;
2356       end if;
2357
2358       if Data.Config.Shared_Lib_Suffix = No_File then
2359          Data.Config.Shared_Lib_Suffix := Empty_File;
2360       end if;
2361
2362       Lang_Index := Data.First_Language_Processing;
2363       while Lang_Index /= No_Language_Index loop
2364          Lang_Data := In_Tree.Languages_Data.Table (Lang_Index);
2365
2366          Current_Language := Lang_Data.Display_Name;
2367
2368          --  For all languages, Compiler_Driver needs to be specified
2369
2370          if Lang_Data.Config.Compiler_Driver = No_File then
2371             Error_Msg_Name_1 := Current_Language;
2372             Error_Msg
2373               (Project,
2374                In_Tree,
2375                "?no compiler specified for language %%" &
2376                ", ignoring all its sources",
2377                No_Location);
2378
2379             if Lang_Index = Data.First_Language_Processing then
2380                Data.First_Language_Processing :=
2381                  Lang_Data.Next;
2382             else
2383                In_Tree.Languages_Data.Table (Prev_Index).Next :=
2384                  Lang_Data.Next;
2385             end if;
2386
2387          elsif Lang_Data.Name = Name_Ada then
2388             Prev_Index := Lang_Index;
2389
2390             --  For unit based languages, Dot_Replacement, Spec_Suffix and
2391             --  Body_Suffix need to be specified.
2392
2393             if Lang_Data.Config.Naming_Data.Dot_Replacement = No_File then
2394                Error_Msg
2395                  (Project,
2396                   In_Tree,
2397                   "Dot_Replacement not specified for Ada",
2398                   No_Location);
2399             end if;
2400
2401             if Lang_Data.Config.Naming_Data.Spec_Suffix = No_File then
2402                Error_Msg
2403                  (Project,
2404                   In_Tree,
2405                   "Spec_Suffix not specified for Ada",
2406                   No_Location);
2407             end if;
2408
2409             if Lang_Data.Config.Naming_Data.Body_Suffix = No_File then
2410                Error_Msg
2411                  (Project,
2412                   In_Tree,
2413                   "Body_Suffix not specified for Ada",
2414                   No_Location);
2415             end if;
2416
2417          else
2418             Prev_Index := Lang_Index;
2419
2420             --  For file based languages, either Spec_Suffix or Body_Suffix
2421             --  need to be specified.
2422
2423             if Lang_Data.Config.Naming_Data.Spec_Suffix = No_File and then
2424               Lang_Data.Config.Naming_Data.Body_Suffix = No_File
2425             then
2426                Error_Msg_Name_1 := Current_Language;
2427                Error_Msg
2428                  (Project,
2429                   In_Tree,
2430                   "no suffixes specified for %%",
2431                   No_Location);
2432             end if;
2433          end if;
2434
2435          Lang_Index := Lang_Data.Next;
2436       end loop;
2437    end Check_Configuration;
2438
2439    -------------------------------
2440    -- Check_If_Externally_Built --
2441    -------------------------------
2442
2443    procedure Check_If_Externally_Built
2444      (Project : Project_Id;
2445       In_Tree : Project_Tree_Ref;
2446       Data    : in out Project_Data)
2447    is
2448       Externally_Built : constant Variable_Value :=
2449                            Util.Value_Of
2450                             (Name_Externally_Built,
2451                              Data.Decl.Attributes, In_Tree);
2452
2453    begin
2454       if not Externally_Built.Default then
2455          Get_Name_String (Externally_Built.Value);
2456          To_Lower (Name_Buffer (1 .. Name_Len));
2457
2458          if Name_Buffer (1 .. Name_Len) = "true" then
2459             Data.Externally_Built := True;
2460
2461          elsif Name_Buffer (1 .. Name_Len) /= "false" then
2462             Error_Msg (Project, In_Tree,
2463                        "Externally_Built may only be true or false",
2464                        Externally_Built.Location);
2465          end if;
2466       end if;
2467
2468       --  A virtual project extending an externally built project is itself
2469       --  externally built.
2470
2471       if Data.Virtual and then Data.Extends /= No_Project then
2472          Data.Externally_Built :=
2473            In_Tree.Projects.Table (Data.Extends).Externally_Built;
2474       end if;
2475
2476       if Current_Verbosity = High then
2477          Write_Str ("Project is ");
2478
2479          if not Data.Externally_Built then
2480             Write_Str ("not ");
2481          end if;
2482
2483          Write_Line ("externally built.");
2484       end if;
2485    end Check_If_Externally_Built;
2486
2487    ----------------------
2488    -- Check_Interfaces --
2489    ----------------------
2490
2491    procedure Check_Interfaces
2492      (Project : Project_Id;
2493       In_Tree : Project_Tree_Ref;
2494       Data    : in out Project_Data)
2495    is
2496       Interfaces : constant Prj.Variable_Value :=
2497                      Prj.Util.Value_Of
2498                        (Snames.Name_Interfaces,
2499                         Data.Decl.Attributes,
2500                         In_Tree);
2501
2502       List    : String_List_Id;
2503       Element : String_Element;
2504       Name    : File_Name_Type;
2505
2506       Source   : Source_Id;
2507
2508       Project_2 : Project_Id;
2509       Data_2     : Project_Data;
2510
2511    begin
2512       if not Interfaces.Default then
2513
2514          --  Set In_Interfaces to False for all sources. It will be set to True
2515          --  later for the sources in the Interfaces list.
2516
2517          Project_2 := Project;
2518          Data_2    := Data;
2519          loop
2520             Source := Data_2.First_Source;
2521             while Source /= No_Source loop
2522                declare
2523                   Src_Data : Source_Data renames
2524                                In_Tree.Sources.Table (Source);
2525                begin
2526                   Src_Data.In_Interfaces := False;
2527                   Source := Src_Data.Next_In_Project;
2528                end;
2529             end loop;
2530
2531             Project_2 := Data_2.Extends;
2532
2533             exit when Project_2 = No_Project;
2534
2535             Data_2 := In_Tree.Projects.Table (Project_2);
2536          end loop;
2537
2538          List := Interfaces.Values;
2539          while List /= Nil_String loop
2540             Element := In_Tree.String_Elements.Table (List);
2541             Get_Name_String (Element.Value);
2542             Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2543             Name := Name_Find;
2544
2545             Project_2 := Project;
2546             Data_2 := Data;
2547             Big_Loop :
2548             loop
2549                Source := Data_2.First_Source;
2550                while Source /= No_Source loop
2551                   declare
2552                      Src_Data : Source_Data renames
2553                                   In_Tree.Sources.Table (Source);
2554
2555                   begin
2556                      if Src_Data.File = Name then
2557                         if not Src_Data.Locally_Removed then
2558                            Src_Data.In_Interfaces := True;
2559                            Src_Data.Declared_In_Interfaces := True;
2560
2561                            if Src_Data.Other_Part /= No_Source then
2562                               In_Tree.Sources.Table
2563                                 (Src_Data.Other_Part).In_Interfaces := True;
2564                               In_Tree.Sources.Table
2565                                 (Src_Data.Other_Part).Declared_In_Interfaces :=
2566                                 True;
2567                            end if;
2568
2569                            if Current_Verbosity = High then
2570                               Write_Str ("   interface: ");
2571                               Write_Line
2572                                 (Get_Name_String (Src_Data.Path.Name));
2573                            end if;
2574                         end if;
2575
2576                         exit Big_Loop;
2577                      end if;
2578
2579                      Source := Src_Data.Next_In_Project;
2580                   end;
2581                end loop;
2582
2583                Project_2 := Data_2.Extends;
2584
2585                exit Big_Loop when Project_2 = No_Project;
2586
2587                Data_2 := In_Tree.Projects.Table (Project_2);
2588             end loop Big_Loop;
2589
2590             if Source = No_Source then
2591                Error_Msg_File_1 := File_Name_Type (Element.Value);
2592                Error_Msg_Name_1 := Data.Name;
2593
2594                Error_Msg
2595                  (Project,
2596                   In_Tree,
2597                   "{ cannot be an interface of project %% " &
2598                   "as it is not one of its sources",
2599                   Element.Location);
2600             end if;
2601
2602             List := Element.Next;
2603          end loop;
2604
2605          Data.Interfaces_Defined := True;
2606
2607       elsif Data.Extends /= No_Project then
2608          Data.Interfaces_Defined :=
2609            In_Tree.Projects.Table (Data.Extends).Interfaces_Defined;
2610
2611          if Data.Interfaces_Defined then
2612             Source := Data.First_Source;
2613             while Source /= No_Source loop
2614                declare
2615                   Src_Data : Source_Data renames
2616                                In_Tree.Sources.Table (Source);
2617
2618                begin
2619                   if not Src_Data.Declared_In_Interfaces then
2620                      Src_Data.In_Interfaces := False;
2621                   end if;
2622
2623                   Source := Src_Data.Next_In_Project;
2624                end;
2625             end loop;
2626          end if;
2627       end if;
2628    end Check_Interfaces;
2629
2630    --------------------------
2631    -- Check_Naming_Schemes --
2632    --------------------------
2633
2634    procedure Check_Naming_Schemes
2635      (Data    : in out Project_Data;
2636       Project : Project_Id;
2637       In_Tree : Project_Tree_Ref)
2638    is
2639       Naming_Id : constant Package_Id :=
2640                     Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
2641       Naming    : Package_Element;
2642
2643       procedure Check_Unit_Names (List : Array_Element_Id);
2644       --  Check that a list of unit names contains only valid names
2645
2646       procedure Get_Exceptions (Kind : Source_Kind);
2647       --  Comment required ???
2648
2649       procedure Get_Unit_Exceptions (Kind : Source_Kind);
2650       --  Comment required ???
2651
2652       ----------------------
2653       -- Check_Unit_Names --
2654       ----------------------
2655
2656       procedure Check_Unit_Names (List : Array_Element_Id) is
2657          Current   : Array_Element_Id;
2658          Element   : Array_Element;
2659          Unit_Name : Name_Id;
2660
2661       begin
2662          --  Loop through elements of the string list
2663
2664          Current := List;
2665          while Current /= No_Array_Element loop
2666             Element := In_Tree.Array_Elements.Table (Current);
2667
2668             --  Put file name in canonical case
2669
2670             if not Osint.File_Names_Case_Sensitive then
2671                Get_Name_String (Element.Value.Value);
2672                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2673                Element.Value.Value := Name_Find;
2674             end if;
2675
2676             --  Check that it contains a valid unit name
2677
2678             Get_Name_String (Element.Index);
2679             Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
2680
2681             if Unit_Name = No_Name then
2682                Err_Vars.Error_Msg_Name_1 := Element.Index;
2683                Error_Msg
2684                  (Project, In_Tree,
2685                   "%% is not a valid unit name.",
2686                   Element.Value.Location);
2687
2688             else
2689                if Current_Verbosity = High then
2690                   Write_Str ("    Unit (""");
2691                   Write_Str (Get_Name_String (Unit_Name));
2692                   Write_Line (""")");
2693                end if;
2694
2695                Element.Index := Unit_Name;
2696                In_Tree.Array_Elements.Table (Current) := Element;
2697             end if;
2698
2699             Current := Element.Next;
2700          end loop;
2701       end Check_Unit_Names;
2702
2703       --------------------
2704       -- Get_Exceptions --
2705       --------------------
2706
2707       procedure Get_Exceptions (Kind : Source_Kind) is
2708          Exceptions     : Array_Element_Id;
2709          Exception_List : Variable_Value;
2710          Element_Id     : String_List_Id;
2711          Element        : String_Element;
2712          File_Name      : File_Name_Type;
2713          Lang_Id        : Language_Index;
2714          Lang           : Name_Id;
2715          Lang_Kind      : Language_Kind;
2716          Source         : Source_Id;
2717
2718       begin
2719          if Kind = Impl then
2720             Exceptions :=
2721               Value_Of
2722                 (Name_Implementation_Exceptions,
2723                  In_Arrays => Naming.Decl.Arrays,
2724                  In_Tree   => In_Tree);
2725
2726          else
2727             Exceptions :=
2728               Value_Of
2729                 (Name_Specification_Exceptions,
2730                  In_Arrays => Naming.Decl.Arrays,
2731                  In_Tree   => In_Tree);
2732          end if;
2733
2734          Lang_Id := Data.First_Language_Processing;
2735          while Lang_Id /= No_Language_Index loop
2736             if In_Tree.Languages_Data.Table (Lang_Id).Config.Kind =
2737                                                                File_Based
2738             then
2739                Lang := In_Tree.Languages_Data.Table (Lang_Id).Name;
2740                Lang_Kind :=
2741                  In_Tree.Languages_Data.Table (Lang_Id).Config.Kind;
2742
2743                Exception_List := Value_Of
2744                  (Index    => Lang,
2745                   In_Array => Exceptions,
2746                   In_Tree  => In_Tree);
2747
2748                if Exception_List /= Nil_Variable_Value then
2749                   Element_Id := Exception_List.Values;
2750                   while Element_Id /= Nil_String loop
2751                      Element := In_Tree.String_Elements.Table (Element_Id);
2752
2753                      if Osint.File_Names_Case_Sensitive then
2754                         File_Name := File_Name_Type (Element.Value);
2755                      else
2756                         Get_Name_String (Element.Value);
2757                         Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2758                         File_Name := Name_Find;
2759                      end if;
2760
2761                      Source := Data.First_Source;
2762                      while Source /= No_Source
2763                        and then
2764                        In_Tree.Sources.Table (Source).File /= File_Name
2765                      loop
2766                         Source :=
2767                           In_Tree.Sources.Table (Source).Next_In_Project;
2768                      end loop;
2769
2770                      if Source = No_Source then
2771                         Add_Source
2772                           (Id           => Source,
2773                            Data         => Data,
2774                            In_Tree      => In_Tree,
2775                            Project      => Project,
2776                            Lang         => Lang,
2777                            Lang_Id      => Lang_Id,
2778                            Kind         => Kind,
2779                            File_Name    => File_Name,
2780                            Display_File => File_Name_Type (Element.Value),
2781                            Naming_Exception => True,
2782                            Lang_Kind    => Lang_Kind);
2783
2784                      else
2785                         --  Check if the file name is already recorded for
2786                         --  another language or another kind.
2787
2788                         if
2789                           In_Tree.Sources.Table (Source).Language /= Lang_Id
2790                         then
2791                            Error_Msg
2792                              (Project,
2793                               In_Tree,
2794                               "the same file cannot be a source " &
2795                               "of two languages",
2796                               Element.Location);
2797
2798                         elsif In_Tree.Sources.Table (Source).Kind /= Kind then
2799                            Error_Msg
2800                              (Project,
2801                               In_Tree,
2802                               "the same file cannot be a source " &
2803                               "and a template",
2804                               Element.Location);
2805                         end if;
2806
2807                         --  If the file is already recorded for the same
2808                         --  language and the same kind, it means that the file
2809                         --  name appears several times in the *_Exceptions
2810                         --  attribute; so there is nothing to do.
2811
2812                      end if;
2813
2814                      Element_Id := Element.Next;
2815                   end loop;
2816                end if;
2817             end if;
2818
2819             Lang_Id := In_Tree.Languages_Data.Table (Lang_Id).Next;
2820          end loop;
2821       end Get_Exceptions;
2822
2823       -------------------------
2824       -- Get_Unit_Exceptions --
2825       -------------------------
2826
2827       procedure Get_Unit_Exceptions (Kind : Source_Kind) is
2828          Exceptions : Array_Element_Id;
2829          Element    : Array_Element;
2830          Unit       : Name_Id;
2831          Index      : Int;
2832          File_Name  : File_Name_Type;
2833          Lang_Id    : constant Language_Index :=
2834                         Data.Unit_Based_Language_Index;
2835          Lang       : constant Name_Id :=
2836                         Data.Unit_Based_Language_Name;
2837
2838          Source            : Source_Id;
2839          Source_To_Replace : Source_Id := No_Source;
2840
2841          Other_Project : Project_Id;
2842          Other_Part    : Source_Id := No_Source;
2843
2844       begin
2845          if Lang_Id = No_Language_Index or else Lang = No_Name then
2846             return;
2847          end if;
2848
2849          if Kind = Impl then
2850             Exceptions := Value_Of
2851               (Name_Body,
2852                In_Arrays => Naming.Decl.Arrays,
2853                In_Tree   => In_Tree);
2854
2855             if Exceptions = No_Array_Element then
2856                Exceptions :=
2857                  Value_Of
2858                    (Name_Implementation,
2859                     In_Arrays => Naming.Decl.Arrays,
2860                     In_Tree   => In_Tree);
2861             end if;
2862
2863          else
2864             Exceptions :=
2865               Value_Of
2866                 (Name_Spec,
2867                  In_Arrays => Naming.Decl.Arrays,
2868                  In_Tree   => In_Tree);
2869
2870             if Exceptions = No_Array_Element then
2871                Exceptions := Value_Of
2872                  (Name_Specification,
2873                   In_Arrays => Naming.Decl.Arrays,
2874                   In_Tree   => In_Tree);
2875             end if;
2876
2877          end if;
2878
2879          while Exceptions /= No_Array_Element loop
2880             Element := In_Tree.Array_Elements.Table (Exceptions);
2881
2882             if Osint.File_Names_Case_Sensitive then
2883                File_Name := File_Name_Type (Element.Value.Value);
2884             else
2885                Get_Name_String (Element.Value.Value);
2886                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2887                File_Name := Name_Find;
2888             end if;
2889
2890             Get_Name_String (Element.Index);
2891             To_Lower (Name_Buffer (1 .. Name_Len));
2892             Unit := Name_Find;
2893
2894             Index := Element.Value.Index;
2895
2896             --  For Ada, check if it is a valid unit name
2897
2898             if Lang = Name_Ada then
2899                Get_Name_String (Element.Index);
2900                Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2901
2902                if Unit = No_Name then
2903                   Err_Vars.Error_Msg_Name_1 := Element.Index;
2904                   Error_Msg
2905                     (Project, In_Tree,
2906                      "%% is not a valid unit name.",
2907                      Element.Value.Location);
2908                end if;
2909             end if;
2910
2911             if Unit /= No_Name then
2912
2913                --  Check if the source already exists
2914
2915                Source := In_Tree.First_Source;
2916                Source_To_Replace := No_Source;
2917
2918                while Source /= No_Source and then
2919                  (In_Tree.Sources.Table (Source).Unit /= Unit or else
2920                   In_Tree.Sources.Table (Source).Index /= Index)
2921                loop
2922                   Source := In_Tree.Sources.Table (Source).Next_In_Sources;
2923                end loop;
2924
2925                if Source /= No_Source then
2926                   if In_Tree.Sources.Table (Source).Kind /= Kind then
2927                      Other_Part := Source;
2928
2929                      loop
2930                         Source :=
2931                           In_Tree.Sources.Table (Source).Next_In_Sources;
2932
2933                         exit when Source = No_Source or else
2934                           (In_Tree.Sources.Table (Source).Unit = Unit
2935                            and then
2936                            In_Tree.Sources.Table (Source).Index = Index);
2937                      end loop;
2938                   end if;
2939
2940                   if Source /= No_Source then
2941                      Other_Project := In_Tree.Sources.Table (Source).Project;
2942
2943                      if Is_Extending (Project, Other_Project, In_Tree) then
2944                         Other_Part :=
2945                           In_Tree.Sources.Table (Source).Other_Part;
2946
2947                         --  Record the source to be removed
2948
2949                         Source_To_Replace := Source;
2950                         Source := No_Source;
2951
2952                      else
2953                         Error_Msg_Name_1 := Unit;
2954                         Error_Msg_Name_2 :=
2955                           In_Tree.Projects.Table (Other_Project).Name;
2956                         Error_Msg
2957                           (Project,
2958                            In_Tree,
2959                            "%% is already a source of project %%",
2960                            Element.Value.Location);
2961                      end if;
2962                   end if;
2963                end if;
2964
2965                if Source = No_Source then
2966                   Add_Source
2967                     (Id           => Source,
2968                      Data         => Data,
2969                      In_Tree      => In_Tree,
2970                      Project      => Project,
2971                      Lang         => Lang,
2972                      Lang_Id      => Lang_Id,
2973                      Kind         => Kind,
2974                      File_Name    => File_Name,
2975                      Display_File => File_Name_Type (Element.Value.Value),
2976                      Lang_Kind    => Unit_Based,
2977                      Other_Part   => Other_Part,
2978                      Unit         => Unit,
2979                      Index        => Index,
2980                      Naming_Exception => True,
2981                      Source_To_Replace => Source_To_Replace);
2982                end if;
2983             end if;
2984
2985             Exceptions := Element.Next;
2986          end loop;
2987
2988       end Get_Unit_Exceptions;
2989
2990    --  Start of processing for Check_Naming_Schemes
2991
2992    begin
2993       if Get_Mode = Ada_Only then
2994
2995          --  If there is a package Naming, we will put in Data.Naming what is
2996          --  in this package Naming.
2997
2998          if Naming_Id /= No_Package then
2999             Naming := In_Tree.Packages.Table (Naming_Id);
3000
3001             if Current_Verbosity = High then
3002                Write_Line ("Checking ""Naming"" for Ada.");
3003             end if;
3004
3005             declare
3006                Bodies : constant Array_Element_Id :=
3007                           Util.Value_Of
3008                             (Name_Body, Naming.Decl.Arrays, In_Tree);
3009
3010                Specs  : constant Array_Element_Id :=
3011                           Util.Value_Of
3012                             (Name_Spec, Naming.Decl.Arrays, In_Tree);
3013
3014             begin
3015                if Bodies /= No_Array_Element then
3016
3017                   --  We have elements in the array Body_Part
3018
3019                   if Current_Verbosity = High then
3020                      Write_Line ("Found Bodies.");
3021                   end if;
3022
3023                   Data.Naming.Bodies := Bodies;
3024                   Check_Unit_Names (Bodies);
3025
3026                else
3027                   if Current_Verbosity = High then
3028                      Write_Line ("No Bodies.");
3029                   end if;
3030                end if;
3031
3032                if Specs /= No_Array_Element then
3033
3034                   --  We have elements in the array Specs
3035
3036                   if Current_Verbosity = High then
3037                      Write_Line ("Found Specs.");
3038                   end if;
3039
3040                   Data.Naming.Specs := Specs;
3041                   Check_Unit_Names (Specs);
3042
3043                else
3044                   if Current_Verbosity = High then
3045                      Write_Line ("No Specs.");
3046                   end if;
3047                end if;
3048             end;
3049
3050             --  We are now checking if variables Dot_Replacement, Casing,
3051             --  Spec_Suffix, Body_Suffix and/or Separate_Suffix exist.
3052
3053             --  For each variable, if it does not exist, we do nothing,
3054             --  because we already have the default.
3055
3056             --  Check Dot_Replacement
3057
3058             declare
3059                Dot_Replacement : constant Variable_Value :=
3060                                    Util.Value_Of
3061                                      (Name_Dot_Replacement,
3062                                       Naming.Decl.Attributes, In_Tree);
3063
3064             begin
3065                pragma Assert (Dot_Replacement.Kind = Single,
3066                               "Dot_Replacement is not a single string");
3067
3068                if not Dot_Replacement.Default then
3069                   Get_Name_String (Dot_Replacement.Value);
3070
3071                   if Name_Len = 0 then
3072                      Error_Msg
3073                        (Project, In_Tree,
3074                         "Dot_Replacement cannot be empty",
3075                         Dot_Replacement.Location);
3076
3077                   else
3078                      if Osint.File_Names_Case_Sensitive then
3079                         Data.Naming.Dot_Replacement :=
3080                           File_Name_Type (Dot_Replacement.Value);
3081                      else
3082                         Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3083                         Data.Naming.Dot_Replacement := Name_Find;
3084                      end if;
3085                      Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
3086                   end if;
3087                end if;
3088             end;
3089
3090             if Current_Verbosity = High then
3091                Write_Str  ("  Dot_Replacement = """);
3092                Write_Str  (Get_Name_String (Data.Naming.Dot_Replacement));
3093                Write_Char ('"');
3094                Write_Eol;
3095             end if;
3096
3097             --  Check Casing
3098
3099             declare
3100                Casing_String : constant Variable_Value :=
3101                                  Util.Value_Of
3102                                    (Name_Casing,
3103                                     Naming.Decl.Attributes,
3104                                     In_Tree);
3105
3106             begin
3107                pragma Assert (Casing_String.Kind = Single,
3108                               "Casing is not a single string");
3109
3110                if not Casing_String.Default then
3111                   declare
3112                      Casing_Image : constant String :=
3113                                       Get_Name_String (Casing_String.Value);
3114                   begin
3115                      declare
3116                         Casing_Value : constant Casing_Type :=
3117                                          Value (Casing_Image);
3118                      begin
3119                         Data.Naming.Casing := Casing_Value;
3120                      end;
3121
3122                   exception
3123                      when Constraint_Error =>
3124                         if Casing_Image'Length = 0 then
3125                            Error_Msg
3126                              (Project, In_Tree,
3127                               "Casing cannot be an empty string",
3128                               Casing_String.Location);
3129
3130                         else
3131                            Name_Len := Casing_Image'Length;
3132                            Name_Buffer (1 .. Name_Len) := Casing_Image;
3133                            Err_Vars.Error_Msg_Name_1 := Name_Find;
3134                            Error_Msg
3135                              (Project, In_Tree,
3136                               "%% is not a correct Casing",
3137                               Casing_String.Location);
3138                         end if;
3139                   end;
3140                end if;
3141             end;
3142
3143             if Current_Verbosity = High then
3144                Write_Str  ("  Casing = ");
3145                Write_Str  (Image (Data.Naming.Casing));
3146                Write_Char ('.');
3147                Write_Eol;
3148             end if;
3149
3150             --  Check Spec_Suffix
3151
3152             declare
3153                Ada_Spec_Suffix : constant Variable_Value :=
3154                                    Prj.Util.Value_Of
3155                                      (Index     => Name_Ada,
3156                                       Src_Index => 0,
3157                                       In_Array  => Data.Naming.Spec_Suffix,
3158                                       In_Tree   => In_Tree);
3159
3160             begin
3161                if Ada_Spec_Suffix.Kind = Single
3162                  and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
3163                then
3164                   Get_Name_String (Ada_Spec_Suffix.Value);
3165                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3166                   Set_Spec_Suffix (In_Tree, "ada", Data.Naming, Name_Find);
3167                   Data.Naming.Ada_Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
3168
3169                else
3170                   Set_Spec_Suffix
3171                     (In_Tree,
3172                      "ada",
3173                      Data.Naming,
3174                      Default_Ada_Spec_Suffix);
3175                end if;
3176             end;
3177
3178             if Current_Verbosity = High then
3179                Write_Str  ("  Spec_Suffix = """);
3180                Write_Str  (Spec_Suffix_Of (In_Tree, "ada", Data.Naming));
3181                Write_Char ('"');
3182                Write_Eol;
3183             end if;
3184
3185             --  Check Body_Suffix
3186
3187             declare
3188                Ada_Body_Suffix : constant Variable_Value :=
3189                                    Prj.Util.Value_Of
3190                                      (Index     => Name_Ada,
3191                                       Src_Index => 0,
3192                                       In_Array  => Data.Naming.Body_Suffix,
3193                                       In_Tree   => In_Tree);
3194
3195             begin
3196                if Ada_Body_Suffix.Kind = Single
3197                  and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
3198                then
3199                   Get_Name_String (Ada_Body_Suffix.Value);
3200                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3201                   Set_Body_Suffix (In_Tree, "ada", Data.Naming, Name_Find);
3202                   Data.Naming.Ada_Body_Suffix_Loc := Ada_Body_Suffix.Location;
3203
3204                else
3205                   Set_Body_Suffix
3206                     (In_Tree,
3207                      "ada",
3208                      Data.Naming,
3209                      Default_Ada_Body_Suffix);
3210                end if;
3211             end;
3212
3213             if Current_Verbosity = High then
3214                Write_Str  ("  Body_Suffix = """);
3215                Write_Str  (Body_Suffix_Of (In_Tree, "ada", Data.Naming));
3216                Write_Char ('"');
3217                Write_Eol;
3218             end if;
3219
3220             --  Check Separate_Suffix
3221
3222             declare
3223                Ada_Sep_Suffix : constant Variable_Value :=
3224                                   Prj.Util.Value_Of
3225                                     (Variable_Name => Name_Separate_Suffix,
3226                                      In_Variables  => Naming.Decl.Attributes,
3227                                      In_Tree       => In_Tree);
3228
3229             begin
3230                if Ada_Sep_Suffix.Default then
3231                   Data.Naming.Separate_Suffix :=
3232                     Body_Suffix_Id_Of (In_Tree, Name_Ada, Data.Naming);
3233
3234                else
3235                   Get_Name_String (Ada_Sep_Suffix.Value);
3236
3237                   if Name_Len = 0 then
3238                      Error_Msg
3239                        (Project, In_Tree,
3240                         "Separate_Suffix cannot be empty",
3241                         Ada_Sep_Suffix.Location);
3242
3243                   else
3244                      Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3245                      Data.Naming.Separate_Suffix := Name_Find;
3246                      Data.Naming.Sep_Suffix_Loc  := Ada_Sep_Suffix.Location;
3247                   end if;
3248                end if;
3249             end;
3250
3251             if Current_Verbosity = High then
3252                Write_Str  ("  Separate_Suffix = """);
3253                Write_Str  (Get_Name_String (Data.Naming.Separate_Suffix));
3254                Write_Char ('"');
3255                Write_Eol;
3256             end if;
3257
3258             --  Check if Data.Naming is valid
3259
3260             Check_Ada_Naming_Scheme_Validity (Project, In_Tree, Data.Naming);
3261          end if;
3262
3263       elsif not In_Configuration then
3264
3265          --  Look into package Naming, if there is one
3266
3267          if Naming_Id /= No_Package then
3268             Naming := In_Tree.Packages.Table (Naming_Id);
3269
3270             if Current_Verbosity = High then
3271                Write_Line ("Checking package Naming.");
3272             end if;
3273
3274             --  We are now checking if attribute Dot_Replacement, Casing,
3275             --  and/or Separate_Suffix exist.
3276
3277             --  For each attribute, if it does not exist, we do nothing,
3278             --  because we already have the default.
3279             --  Otherwise, for all unit-based languages, we put the declared
3280             --  value in the language config.
3281
3282             declare
3283                Dot_Repl        : constant  Variable_Value :=
3284                                    Util.Value_Of
3285                                      (Name_Dot_Replacement,
3286                                       Naming.Decl.Attributes, In_Tree);
3287                Dot_Replacement : File_Name_Type := No_File;
3288
3289                Casing_String : constant Variable_Value :=
3290                                  Util.Value_Of
3291                                    (Name_Casing,
3292                                     Naming.Decl.Attributes,
3293                                     In_Tree);
3294                Casing          : Casing_Type;
3295                Casing_Defined  : Boolean := False;
3296
3297                Sep_Suffix : constant Variable_Value :=
3298                               Prj.Util.Value_Of
3299                                 (Variable_Name => Name_Separate_Suffix,
3300                                  In_Variables  => Naming.Decl.Attributes,
3301                                  In_Tree       => In_Tree);
3302                Separate_Suffix : File_Name_Type := No_File;
3303
3304                Lang_Id : Language_Index;
3305             begin
3306                --  Check attribute Dot_Replacement
3307
3308                if not Dot_Repl.Default then
3309                   Get_Name_String (Dot_Repl.Value);
3310
3311                   if Name_Len = 0 then
3312                      Error_Msg
3313                        (Project, In_Tree,
3314                         "Dot_Replacement cannot be empty",
3315                         Dot_Repl.Location);
3316
3317                   else
3318                      Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3319                      Dot_Replacement := Name_Find;
3320
3321                      if Current_Verbosity = High then
3322                         Write_Str  ("  Dot_Replacement = """);
3323                         Write_Str  (Get_Name_String (Dot_Replacement));
3324                         Write_Char ('"');
3325                         Write_Eol;
3326                      end if;
3327                   end if;
3328                end if;
3329
3330                --  Check attribute Casing
3331
3332                if not Casing_String.Default then
3333                   declare
3334                      Casing_Image : constant String :=
3335                                       Get_Name_String (Casing_String.Value);
3336                   begin
3337                      declare
3338                         Casing_Value : constant Casing_Type :=
3339                                          Value (Casing_Image);
3340                      begin
3341                         Casing := Casing_Value;
3342                         Casing_Defined := True;
3343
3344                         if Current_Verbosity = High then
3345                            Write_Str  ("  Casing = ");
3346                            Write_Str  (Image (Casing));
3347                            Write_Char ('.');
3348                            Write_Eol;
3349                         end if;
3350                      end;
3351
3352                   exception
3353                      when Constraint_Error =>
3354                         if Casing_Image'Length = 0 then
3355                            Error_Msg
3356                              (Project, In_Tree,
3357                               "Casing cannot be an empty string",
3358                               Casing_String.Location);
3359
3360                         else
3361                            Name_Len := Casing_Image'Length;
3362                            Name_Buffer (1 .. Name_Len) := Casing_Image;
3363                            Err_Vars.Error_Msg_Name_1 := Name_Find;
3364                            Error_Msg
3365                              (Project, In_Tree,
3366                               "%% is not a correct Casing",
3367                               Casing_String.Location);
3368                         end if;
3369                   end;
3370                end if;
3371
3372                if not Sep_Suffix.Default then
3373                   Get_Name_String (Sep_Suffix.Value);
3374
3375                   if Name_Len = 0 then
3376                      Error_Msg
3377                        (Project, In_Tree,
3378                         "Separate_Suffix cannot be empty",
3379                         Sep_Suffix.Location);
3380
3381                   else
3382                      Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3383                      Separate_Suffix := Name_Find;
3384
3385                      if Current_Verbosity = High then
3386                         Write_Str ("  Separate_Suffix = """);
3387                         Write_Str (Get_Name_String (Separate_Suffix));
3388                         Write_Char ('"');
3389                         Write_Eol;
3390                      end if;
3391                   end if;
3392                end if;
3393
3394                --  For all unit based languages, if any, set the specified
3395                --  value of Dot_Replacement, Casing and/or Separate_Suffix.
3396
3397                if Dot_Replacement /= No_File
3398                  or else Casing_Defined
3399                  or else Separate_Suffix /= No_File
3400                then
3401                   Lang_Id := Data.First_Language_Processing;
3402                   while Lang_Id /= No_Language_Index loop
3403                      if In_Tree.Languages_Data.Table
3404                        (Lang_Id).Config.Kind = Unit_Based
3405                      then
3406                         if Dot_Replacement /= No_File then
3407                            In_Tree.Languages_Data.Table
3408                              (Lang_Id).Config.Naming_Data.Dot_Replacement :=
3409                              Dot_Replacement;
3410                         end if;
3411
3412                         if Casing_Defined then
3413                            In_Tree.Languages_Data.Table
3414                              (Lang_Id).Config.Naming_Data.Casing := Casing;
3415                         end if;
3416
3417                         if Separate_Suffix /= No_File then
3418                            In_Tree.Languages_Data.Table
3419                              (Lang_Id).Config.Naming_Data.Separate_Suffix :=
3420                                Separate_Suffix;
3421                         end if;
3422                      end if;
3423
3424                      Lang_Id :=
3425                        In_Tree.Languages_Data.Table (Lang_Id).Next;
3426                   end loop;
3427                end if;
3428             end;
3429
3430             --  Next, get the spec and body suffixes
3431
3432             declare
3433                Suffix  : Variable_Value;
3434                Lang_Id : Language_Index;
3435                Lang    : Name_Id;
3436
3437             begin
3438                Lang_Id := Data.First_Language_Processing;
3439                while Lang_Id /= No_Language_Index loop
3440                   Lang := In_Tree.Languages_Data.Table (Lang_Id).Name;
3441
3442                   --  Spec_Suffix
3443
3444                   Suffix := Value_Of
3445                     (Name                    => Lang,
3446                      Attribute_Or_Array_Name => Name_Spec_Suffix,
3447                      In_Package              => Naming_Id,
3448                      In_Tree                 => In_Tree);
3449
3450                   if Suffix = Nil_Variable_Value then
3451                      Suffix := Value_Of
3452                        (Name                    => Lang,
3453                         Attribute_Or_Array_Name => Name_Specification_Suffix,
3454                         In_Package              => Naming_Id,
3455                         In_Tree                 => In_Tree);
3456                   end if;
3457
3458                   if Suffix /= Nil_Variable_Value then
3459                      In_Tree.Languages_Data.Table (Lang_Id).
3460                        Config.Naming_Data.Spec_Suffix :=
3461                          File_Name_Type (Suffix.Value);
3462                   end if;
3463
3464                   --  Body_Suffix
3465
3466                   Suffix := Value_Of
3467                     (Name                    => Lang,
3468                      Attribute_Or_Array_Name => Name_Body_Suffix,
3469                      In_Package              => Naming_Id,
3470                      In_Tree                 => In_Tree);
3471
3472                   if Suffix = Nil_Variable_Value then
3473                      Suffix := Value_Of
3474                        (Name                    => Lang,
3475                         Attribute_Or_Array_Name => Name_Implementation_Suffix,
3476                         In_Package              => Naming_Id,
3477                         In_Tree                 => In_Tree);
3478                   end if;
3479
3480                   if Suffix /= Nil_Variable_Value then
3481                      In_Tree.Languages_Data.Table (Lang_Id).
3482                        Config.Naming_Data.Body_Suffix :=
3483                          File_Name_Type (Suffix.Value);
3484                   end if;
3485
3486                   Lang_Id := In_Tree.Languages_Data.Table (Lang_Id).Next;
3487                end loop;
3488             end;
3489
3490             --  Get the exceptions for file based languages
3491
3492             Get_Exceptions (Spec);
3493             Get_Exceptions (Impl);
3494
3495             --  Get the exceptions for unit based languages
3496
3497             Get_Unit_Exceptions (Spec);
3498             Get_Unit_Exceptions (Impl);
3499
3500          end if;
3501       end if;
3502    end Check_Naming_Schemes;
3503
3504    ------------------------------
3505    -- Check_Library_Attributes --
3506    ------------------------------
3507
3508    procedure Check_Library_Attributes
3509      (Project : Project_Id;
3510       In_Tree : Project_Tree_Ref;
3511       Current_Dir : String;
3512       Data    : in out Project_Data)
3513    is
3514       Attributes   : constant Prj.Variable_Id := Data.Decl.Attributes;
3515
3516       Lib_Dir      : constant Prj.Variable_Value :=
3517                        Prj.Util.Value_Of
3518                          (Snames.Name_Library_Dir, Attributes, In_Tree);
3519
3520       Lib_Name     : constant Prj.Variable_Value :=
3521                        Prj.Util.Value_Of
3522                          (Snames.Name_Library_Name, Attributes, In_Tree);
3523
3524       Lib_Version  : constant Prj.Variable_Value :=
3525                        Prj.Util.Value_Of
3526                          (Snames.Name_Library_Version, Attributes, In_Tree);
3527
3528       Lib_ALI_Dir  : constant Prj.Variable_Value :=
3529                        Prj.Util.Value_Of
3530                          (Snames.Name_Library_Ali_Dir, Attributes, In_Tree);
3531
3532       The_Lib_Kind : constant Prj.Variable_Value :=
3533                        Prj.Util.Value_Of
3534                          (Snames.Name_Library_Kind, Attributes, In_Tree);
3535
3536       Imported_Project_List : Project_List := Empty_Project_List;
3537
3538       Continuation : String_Access := No_Continuation_String'Access;
3539
3540       Support_For_Libraries : Library_Support;
3541
3542       Library_Directory_Present : Boolean;
3543
3544       procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3545       --  Check if an imported or extended project if also a library project
3546
3547       -------------------
3548       -- Check_Library --
3549       -------------------
3550
3551       procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3552          Proj_Data : Project_Data;
3553          Src_Id    : Source_Id;
3554
3555       begin
3556          if Proj /= No_Project then
3557             Proj_Data := In_Tree.Projects.Table (Proj);
3558
3559             if not Proj_Data.Library then
3560
3561                --  The only not library projects that are OK are those that
3562                --  have no sources. However, header files from non-Ada
3563                --  languages are OK, as there is nothing to compile.
3564
3565                Src_Id := Proj_Data.First_Source;
3566                while Src_Id /= No_Source loop
3567                   declare
3568                      Src : Source_Data renames In_Tree.Sources.Table (Src_Id);
3569                   begin
3570                      exit when Src.Lang_Kind /= File_Based
3571                        or else Src.Kind /= Spec;
3572                      Src_Id := Src.Next_In_Project;
3573                   end;
3574                end loop;
3575
3576                if Src_Id /= No_Source then
3577                   Error_Msg_Name_1 := Data.Name;
3578                   Error_Msg_Name_2 := Proj_Data.Name;
3579
3580                   if Extends then
3581                      if Data.Library_Kind /= Static then
3582                         Error_Msg
3583                           (Project, In_Tree,
3584                            Continuation.all &
3585                            "shared library project %% cannot extend " &
3586                            "project %% that is not a library project",
3587                            Data.Location);
3588                         Continuation := Continuation_String'Access;
3589                      end if;
3590
3591                   elsif Data.Library_Kind /= Static then
3592                      Error_Msg
3593                        (Project, In_Tree,
3594                         Continuation.all &
3595                         "shared library project %% cannot import project %% " &
3596                         "that is not a shared library project",
3597                         Data.Location);
3598                      Continuation := Continuation_String'Access;
3599                   end if;
3600                end if;
3601
3602             elsif Data.Library_Kind /= Static and then
3603                   Proj_Data.Library_Kind = Static
3604             then
3605                Error_Msg_Name_1 := Data.Name;
3606                Error_Msg_Name_2 := Proj_Data.Name;
3607
3608                if Extends then
3609                   Error_Msg
3610                     (Project, In_Tree,
3611                      Continuation.all &
3612                      "shared library project %% cannot extend static " &
3613                      "library project %%",
3614                      Data.Location);
3615
3616                else
3617                   Error_Msg
3618                     (Project, In_Tree,
3619                      Continuation.all &
3620                      "shared library project %% cannot import static " &
3621                      "library project %%",
3622                      Data.Location);
3623                end if;
3624
3625                Continuation := Continuation_String'Access;
3626             end if;
3627          end if;
3628       end Check_Library;
3629
3630    --  Start of processing for Check_Library_Attributes
3631
3632    begin
3633       Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3634
3635       --  Special case of extending project
3636
3637       if Data.Extends /= No_Project then
3638          declare
3639             Extended_Data : constant Project_Data :=
3640                               In_Tree.Projects.Table (Data.Extends);
3641
3642          begin
3643             --  If the project extended is a library project, we inherit the
3644             --  library name, if it is not redefined; we check that the library
3645             --  directory is specified.
3646
3647             if Extended_Data.Library then
3648                if Data.Qualifier = Standard then
3649                   Error_Msg
3650                     (Project, In_Tree,
3651                      "a standard project cannot extend a library project",
3652                      Data.Location);
3653
3654                else
3655                   if Lib_Name.Default then
3656                      Data.Library_Name := Extended_Data.Library_Name;
3657                   end if;
3658
3659                   if Lib_Dir.Default then
3660                      if not Data.Virtual then
3661                         Error_Msg
3662                           (Project, In_Tree,
3663                            "a project extending a library project must " &
3664                            "specify an attribute Library_Dir",
3665                            Data.Location);
3666
3667                      else
3668                         --  For a virtual project extending a library project,
3669                         --  inherit library directory.
3670
3671                         Data.Library_Dir := Extended_Data.Library_Dir;
3672                         Library_Directory_Present := True;
3673                      end if;
3674                   end if;
3675                end if;
3676             end if;
3677          end;
3678       end if;
3679
3680       pragma Assert (Lib_Name.Kind = Single);
3681
3682       if Lib_Name.Value = Empty_String then
3683          if Current_Verbosity = High
3684            and then Data.Library_Name = No_Name
3685          then
3686             Write_Line ("No library name");
3687          end if;
3688
3689       else
3690          --  There is no restriction on the syntax of library names
3691
3692          Data.Library_Name := Lib_Name.Value;
3693       end if;
3694
3695       if Data.Library_Name /= No_Name then
3696          if Current_Verbosity = High then
3697             Write_Str ("Library name = """);
3698             Write_Str (Get_Name_String (Data.Library_Name));
3699             Write_Line ("""");
3700          end if;
3701
3702          pragma Assert (Lib_Dir.Kind = Single);
3703
3704          if not Library_Directory_Present then
3705             if Current_Verbosity = High then
3706                Write_Line ("No library directory");
3707             end if;
3708
3709          else
3710             --  Find path name (unless inherited), check that it is a directory
3711
3712             if Data.Library_Dir = No_Path_Information then
3713                Locate_Directory
3714                  (Project,
3715                   In_Tree,
3716                   File_Name_Type (Lib_Dir.Value),
3717                   Data.Directory.Display_Name,
3718                   Data.Library_Dir.Name,
3719                   Data.Library_Dir.Display_Name,
3720                   Create      => "library",
3721                   Current_Dir => Current_Dir,
3722                   Location    => Lib_Dir.Location);
3723             end if;
3724
3725             if Data.Library_Dir = No_Path_Information then
3726
3727                --  Get the absolute name of the library directory that
3728                --  does not exist, to report an error.
3729
3730                declare
3731                   Dir_Name : constant String :=
3732                                Get_Name_String (Lib_Dir.Value);
3733
3734                begin
3735                   if Is_Absolute_Path (Dir_Name) then
3736                      Err_Vars.Error_Msg_File_1 :=
3737                        File_Name_Type (Lib_Dir.Value);
3738
3739                   else
3740                      Get_Name_String (Data.Directory.Display_Name);
3741
3742                      if Name_Buffer (Name_Len) /= Directory_Separator then
3743                         Name_Len := Name_Len + 1;
3744                         Name_Buffer (Name_Len) := Directory_Separator;
3745                      end if;
3746
3747                      Name_Buffer
3748                        (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3749                        Dir_Name;
3750                      Name_Len := Name_Len + Dir_Name'Length;
3751                      Err_Vars.Error_Msg_File_1 := Name_Find;
3752                   end if;
3753
3754                   --  Report the error
3755
3756                   Error_Msg
3757                     (Project, In_Tree,
3758                      "library directory { does not exist",
3759                      Lib_Dir.Location);
3760                end;
3761
3762                --  The library directory cannot be the same as the Object
3763                --  directory.
3764
3765             elsif Data.Library_Dir.Name = Data.Object_Directory.Name then
3766                Error_Msg
3767                  (Project, In_Tree,
3768                   "library directory cannot be the same " &
3769                   "as object directory",
3770                   Lib_Dir.Location);
3771                Data.Library_Dir := No_Path_Information;
3772
3773             else
3774                declare
3775                   OK       : Boolean := True;
3776                   Dirs_Id  : String_List_Id;
3777                   Dir_Elem : String_Element;
3778
3779                begin
3780                   --  The library directory cannot be the same as a source
3781                   --  directory of the current project.
3782
3783                   Dirs_Id := Data.Source_Dirs;
3784                   while Dirs_Id /= Nil_String loop
3785                      Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3786                      Dirs_Id  := Dir_Elem.Next;
3787
3788                      if
3789                        Data.Library_Dir.Name = Path_Name_Type (Dir_Elem.Value)
3790                      then
3791                         Err_Vars.Error_Msg_File_1 :=
3792                           File_Name_Type (Dir_Elem.Value);
3793                         Error_Msg
3794                           (Project, In_Tree,
3795                            "library directory cannot be the same " &
3796                            "as source directory {",
3797                            Lib_Dir.Location);
3798                         OK := False;
3799                         exit;
3800                      end if;
3801                   end loop;
3802
3803                   if OK then
3804
3805                      --  The library directory cannot be the same as a source
3806                      --  directory of another project either.
3807
3808                      Project_Loop :
3809                      for Pid in 1 .. Project_Table.Last (In_Tree.Projects) loop
3810                         if Pid /= Project then
3811                            Dirs_Id := In_Tree.Projects.Table (Pid).Source_Dirs;
3812
3813                            Dir_Loop : while Dirs_Id /= Nil_String loop
3814                               Dir_Elem :=
3815                                 In_Tree.String_Elements.Table (Dirs_Id);
3816                               Dirs_Id  := Dir_Elem.Next;
3817
3818                               if Data.Library_Dir.Name =
3819                                 Path_Name_Type (Dir_Elem.Value)
3820                               then
3821                                  Err_Vars.Error_Msg_File_1 :=
3822                                    File_Name_Type (Dir_Elem.Value);
3823                                  Err_Vars.Error_Msg_Name_1 :=
3824                                    In_Tree.Projects.Table (Pid).Name;
3825
3826                                  Error_Msg
3827                                    (Project, In_Tree,
3828                                     "library directory cannot be the same " &
3829                                     "as source directory { of project %%",
3830                                     Lib_Dir.Location);
3831                                  OK := False;
3832                                  exit Project_Loop;
3833                               end if;
3834                            end loop Dir_Loop;
3835                         end if;
3836                      end loop Project_Loop;
3837                   end if;
3838
3839                   if not OK then
3840                      Data.Library_Dir := No_Path_Information;
3841
3842                   elsif Current_Verbosity = High then
3843
3844                      --  Display the Library directory in high verbosity
3845
3846                      Write_Str ("Library directory =""");
3847                      Write_Str
3848                        (Get_Name_String (Data.Library_Dir.Display_Name));
3849                      Write_Line ("""");
3850                   end if;
3851                end;
3852             end if;
3853          end if;
3854
3855       end if;
3856
3857       Data.Library :=
3858         Data.Library_Dir /= No_Path_Information
3859         and then
3860       Data.Library_Name /= No_Name;
3861
3862       if Data.Extends = No_Project then
3863          case Data.Qualifier is
3864             when Standard =>
3865                if Data.Library then
3866                   Error_Msg
3867                     (Project, In_Tree,
3868                      "a standard project cannot be a library project",
3869                      Lib_Name.Location);
3870                end if;
3871
3872             when Library =>
3873                if not Data.Library then
3874                   Error_Msg
3875                     (Project, In_Tree,
3876                      "not a library project",
3877                      Data.Location);
3878                end if;
3879
3880             when others =>
3881                null;
3882
3883          end case;
3884       end if;
3885
3886       if Data.Library then
3887          if Get_Mode = Multi_Language then
3888             Support_For_Libraries := Data.Config.Lib_Support;
3889
3890          else
3891             Support_For_Libraries := MLib.Tgt.Support_For_Libraries;
3892          end if;
3893
3894          if Support_For_Libraries = Prj.None then
3895             Error_Msg
3896               (Project, In_Tree,
3897                "?libraries are not supported on this platform",
3898                Lib_Name.Location);
3899             Data.Library := False;
3900
3901          else
3902             if Lib_ALI_Dir.Value = Empty_String then
3903                if Current_Verbosity = High then
3904                   Write_Line ("No library ALI directory specified");
3905                end if;
3906                Data.Library_ALI_Dir := Data.Library_Dir;
3907
3908             else
3909                --  Find path name, check that it is a directory
3910
3911                Locate_Directory
3912                  (Project,
3913                   In_Tree,
3914                   File_Name_Type (Lib_ALI_Dir.Value),
3915                   Data.Directory.Display_Name,
3916                   Data.Library_ALI_Dir.Name,
3917                   Data.Library_ALI_Dir.Display_Name,
3918                   Create   => "library ALI",
3919                   Current_Dir => Current_Dir,
3920                   Location => Lib_ALI_Dir.Location);
3921
3922                if Data.Library_ALI_Dir = No_Path_Information then
3923
3924                   --  Get the absolute name of the library ALI directory that
3925                   --  does not exist, to report an error.
3926
3927                   declare
3928                      Dir_Name : constant String :=
3929                                   Get_Name_String (Lib_ALI_Dir.Value);
3930
3931                   begin
3932                      if Is_Absolute_Path (Dir_Name) then
3933                         Err_Vars.Error_Msg_File_1 :=
3934                           File_Name_Type (Lib_Dir.Value);
3935
3936                      else
3937                         Get_Name_String (Data.Directory.Display_Name);
3938
3939                         if Name_Buffer (Name_Len) /= Directory_Separator then
3940                            Name_Len := Name_Len + 1;
3941                            Name_Buffer (Name_Len) := Directory_Separator;
3942                         end if;
3943
3944                         Name_Buffer
3945                           (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3946                           Dir_Name;
3947                         Name_Len := Name_Len + Dir_Name'Length;
3948                         Err_Vars.Error_Msg_File_1 := Name_Find;
3949                      end if;
3950
3951                      --  Report the error
3952
3953                      Error_Msg
3954                        (Project, In_Tree,
3955                         "library 'A'L'I directory { does not exist",
3956                         Lib_ALI_Dir.Location);
3957                   end;
3958                end if;
3959
3960                if Data.Library_ALI_Dir /= Data.Library_Dir then
3961
3962                   --  The library ALI directory cannot be the same as the
3963                   --  Object directory.
3964
3965                   if Data.Library_ALI_Dir = Data.Object_Directory then
3966                      Error_Msg
3967                        (Project, In_Tree,
3968                         "library 'A'L'I directory cannot be the same " &
3969                         "as object directory",
3970                         Lib_ALI_Dir.Location);
3971                      Data.Library_ALI_Dir := No_Path_Information;
3972
3973                   else
3974                      declare
3975                         OK       : Boolean := True;
3976                         Dirs_Id  : String_List_Id;
3977                         Dir_Elem : String_Element;
3978
3979                      begin
3980                         --  The library ALI directory cannot be the same as
3981                         --  a source directory of the current project.
3982
3983                         Dirs_Id := Data.Source_Dirs;
3984                         while Dirs_Id /= Nil_String loop
3985                            Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3986                            Dirs_Id  := Dir_Elem.Next;
3987
3988                            if Data.Library_ALI_Dir.Name =
3989                              Path_Name_Type (Dir_Elem.Value)
3990                            then
3991                               Err_Vars.Error_Msg_File_1 :=
3992                                 File_Name_Type (Dir_Elem.Value);
3993                               Error_Msg
3994                                 (Project, In_Tree,
3995                                  "library 'A'L'I directory cannot be " &
3996                                  "the same as source directory {",
3997                                  Lib_ALI_Dir.Location);
3998                               OK := False;
3999                               exit;
4000                            end if;
4001                         end loop;
4002
4003                         if OK then
4004
4005                            --  The library ALI directory cannot be the same as
4006                            --  a source directory of another project either.
4007
4008                            ALI_Project_Loop :
4009                            for
4010                              Pid in 1 .. Project_Table.Last (In_Tree.Projects)
4011                            loop
4012                               if Pid /= Project then
4013                                  Dirs_Id :=
4014                                    In_Tree.Projects.Table (Pid).Source_Dirs;
4015
4016                                  ALI_Dir_Loop :
4017                                  while Dirs_Id /= Nil_String loop
4018                                     Dir_Elem :=
4019                                       In_Tree.String_Elements.Table (Dirs_Id);
4020                                     Dirs_Id  := Dir_Elem.Next;
4021
4022                                     if Data.Library_ALI_Dir.Name =
4023                                         Path_Name_Type (Dir_Elem.Value)
4024                                     then
4025                                        Err_Vars.Error_Msg_File_1 :=
4026                                          File_Name_Type (Dir_Elem.Value);
4027                                        Err_Vars.Error_Msg_Name_1 :=
4028                                          In_Tree.Projects.Table (Pid).Name;
4029
4030                                        Error_Msg
4031                                          (Project, In_Tree,
4032                                           "library 'A'L'I directory cannot " &
4033                                           "be the same as source directory " &
4034                                           "{ of project %%",
4035                                           Lib_ALI_Dir.Location);
4036                                        OK := False;
4037                                        exit ALI_Project_Loop;
4038                                     end if;
4039                                  end loop ALI_Dir_Loop;
4040                               end if;
4041                            end loop ALI_Project_Loop;
4042                         end if;
4043
4044                         if not OK then
4045                            Data.Library_ALI_Dir := No_Path_Information;
4046
4047                         elsif Current_Verbosity = High then
4048
4049                            --  Display the Library ALI directory in high
4050                            --  verbosity.
4051
4052                            Write_Str ("Library ALI directory =""");
4053                            Write_Str
4054                              (Get_Name_String
4055                                 (Data.Library_ALI_Dir.Display_Name));
4056                            Write_Line ("""");
4057                         end if;
4058                      end;
4059                   end if;
4060                end if;
4061             end if;
4062
4063             pragma Assert (Lib_Version.Kind = Single);
4064
4065             if Lib_Version.Value = Empty_String then
4066                if Current_Verbosity = High then
4067                   Write_Line ("No library version specified");
4068                end if;
4069
4070             else
4071                Data.Lib_Internal_Name := Lib_Version.Value;
4072             end if;
4073
4074             pragma Assert (The_Lib_Kind.Kind = Single);
4075
4076             if The_Lib_Kind.Value = Empty_String then
4077                if Current_Verbosity = High then
4078                   Write_Line ("No library kind specified");
4079                end if;
4080
4081             else
4082                Get_Name_String (The_Lib_Kind.Value);
4083
4084                declare
4085                   Kind_Name : constant String :=
4086                                 To_Lower (Name_Buffer (1 .. Name_Len));
4087
4088                   OK : Boolean := True;
4089
4090                begin
4091                   if Kind_Name = "static" then
4092                      Data.Library_Kind := Static;
4093
4094                   elsif Kind_Name = "dynamic" then
4095                      Data.Library_Kind := Dynamic;
4096
4097                   elsif Kind_Name = "relocatable" then
4098                      Data.Library_Kind := Relocatable;
4099
4100                   else
4101                      Error_Msg
4102                        (Project, In_Tree,
4103                         "illegal value for Library_Kind",
4104                         The_Lib_Kind.Location);
4105                      OK := False;
4106                   end if;
4107
4108                   if Current_Verbosity = High and then OK then
4109                      Write_Str ("Library kind = ");
4110                      Write_Line (Kind_Name);
4111                   end if;
4112
4113                   if Data.Library_Kind /= Static and then
4114                     Support_For_Libraries = Prj.Static_Only
4115                   then
4116                      Error_Msg
4117                        (Project, In_Tree,
4118                         "only static libraries are supported " &
4119                         "on this platform",
4120                         The_Lib_Kind.Location);
4121                      Data.Library := False;
4122                   end if;
4123                end;
4124             end if;
4125
4126             if Data.Library then
4127                if Current_Verbosity = High then
4128                   Write_Line ("This is a library project file");
4129                end if;
4130
4131                if Get_Mode = Multi_Language then
4132                   Check_Library (Data.Extends, Extends => True);
4133
4134                   Imported_Project_List := Data.Imported_Projects;
4135                   while Imported_Project_List /= Empty_Project_List loop
4136                      Check_Library
4137                        (In_Tree.Project_Lists.Table
4138                           (Imported_Project_List).Project,
4139                         Extends => False);
4140                      Imported_Project_List :=
4141                        In_Tree.Project_Lists.Table
4142                          (Imported_Project_List).Next;
4143                   end loop;
4144                end if;
4145             end if;
4146
4147          end if;
4148       end if;
4149
4150       --  Check if Linker'Switches or Linker'Default_Switches are declared.
4151       --  Warn if they are declared, as it is a common error to think that
4152       --  library are "linked" with Linker switches.
4153
4154       if Data.Library then
4155          declare
4156             Linker_Package_Id : constant Package_Id :=
4157                                   Util.Value_Of
4158                                     (Name_Linker, Data.Decl.Packages, In_Tree);
4159             Linker_Package    : Package_Element;
4160             Switches          : Array_Element_Id := No_Array_Element;
4161
4162          begin
4163             if Linker_Package_Id /= No_Package then
4164                Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
4165
4166                Switches :=
4167                  Value_Of
4168                    (Name      => Name_Switches,
4169                     In_Arrays => Linker_Package.Decl.Arrays,
4170                     In_Tree   => In_Tree);
4171
4172                if Switches = No_Array_Element then
4173                   Switches :=
4174                     Value_Of
4175                       (Name      => Name_Default_Switches,
4176                        In_Arrays => Linker_Package.Decl.Arrays,
4177                        In_Tree   => In_Tree);
4178                end if;
4179
4180                if Switches /= No_Array_Element then
4181                   Error_Msg
4182                     (Project, In_Tree,
4183                      "?Linker switches not taken into account in library " &
4184                      "projects",
4185                      No_Location);
4186                end if;
4187             end if;
4188          end;
4189       end if;
4190
4191       if Data.Extends /= No_Project then
4192          In_Tree.Projects.Table (Data.Extends).Library := False;
4193       end if;
4194    end Check_Library_Attributes;
4195
4196    --------------------------
4197    -- Check_Package_Naming --
4198    --------------------------
4199
4200    procedure Check_Package_Naming
4201      (Project : Project_Id;
4202       In_Tree : Project_Tree_Ref;
4203       Data    : in out Project_Data)
4204    is
4205       Naming_Id : constant Package_Id :=
4206                     Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
4207
4208       Naming    : Package_Element;
4209
4210    begin
4211       --  If there is a package Naming, we will put in Data.Naming
4212       --  what is in this package Naming.
4213
4214       if Naming_Id /= No_Package then
4215          Naming := In_Tree.Packages.Table (Naming_Id);
4216
4217          if Current_Verbosity = High then
4218             Write_Line ("Checking ""Naming"".");
4219          end if;
4220
4221          --  Check Spec_Suffix
4222
4223          declare
4224             Spec_Suffixs : Array_Element_Id :=
4225                              Util.Value_Of
4226                                (Name_Spec_Suffix,
4227                                 Naming.Decl.Arrays,
4228                                 In_Tree);
4229
4230             Suffix  : Array_Element_Id;
4231             Element : Array_Element;
4232             Suffix2 : Array_Element_Id;
4233
4234          begin
4235             --  If some suffixes have been specified, we make sure that
4236             --  for each language for which a default suffix has been
4237             --  specified, there is a suffix specified, either the one
4238             --  in the project file or if there were none, the default.
4239
4240             if Spec_Suffixs /= No_Array_Element then
4241                Suffix := Data.Naming.Spec_Suffix;
4242
4243                while Suffix /= No_Array_Element loop
4244                   Element :=
4245                     In_Tree.Array_Elements.Table (Suffix);
4246                   Suffix2 := Spec_Suffixs;
4247
4248                   while Suffix2 /= No_Array_Element loop
4249                      exit when In_Tree.Array_Elements.Table
4250                                 (Suffix2).Index = Element.Index;
4251                      Suffix2 := In_Tree.Array_Elements.Table
4252                                  (Suffix2).Next;
4253                   end loop;
4254
4255                   --  There is a registered default suffix, but no
4256                   --  suffix specified in the project file.
4257                   --  Add the default to the array.
4258
4259                   if Suffix2 = No_Array_Element then
4260                      Array_Element_Table.Increment_Last
4261                        (In_Tree.Array_Elements);
4262                      In_Tree.Array_Elements.Table
4263                        (Array_Element_Table.Last
4264                           (In_Tree.Array_Elements)) :=
4265                        (Index                => Element.Index,
4266                         Src_Index            => Element.Src_Index,
4267                         Index_Case_Sensitive => False,
4268                         Value                => Element.Value,
4269                         Next                 => Spec_Suffixs);
4270                      Spec_Suffixs := Array_Element_Table.Last
4271                                        (In_Tree.Array_Elements);
4272                   end if;
4273
4274                   Suffix := Element.Next;
4275                end loop;
4276
4277                --  Put the resulting array as the specification suffixes
4278
4279                Data.Naming.Spec_Suffix := Spec_Suffixs;
4280             end if;
4281          end;
4282
4283          declare
4284             Current : Array_Element_Id;
4285             Element : Array_Element;
4286
4287          begin
4288             Current := Data.Naming.Spec_Suffix;
4289             while Current /= No_Array_Element loop
4290                Element := In_Tree.Array_Elements.Table (Current);
4291                Get_Name_String (Element.Value.Value);
4292
4293                if Name_Len = 0 then
4294                   Error_Msg
4295                     (Project, In_Tree,
4296                      "Spec_Suffix cannot be empty",
4297                      Element.Value.Location);
4298                end if;
4299
4300                In_Tree.Array_Elements.Table (Current) := Element;
4301                Current := Element.Next;
4302             end loop;
4303          end;
4304
4305          --  Check Body_Suffix
4306
4307          declare
4308             Impl_Suffixs : Array_Element_Id :=
4309                              Util.Value_Of
4310                                (Name_Body_Suffix,
4311                                 Naming.Decl.Arrays,
4312                                 In_Tree);
4313
4314             Suffix  : Array_Element_Id;
4315             Element : Array_Element;
4316             Suffix2 : Array_Element_Id;
4317
4318          begin
4319             --  If some suffixes have been specified, we make sure that
4320             --  for each language for which a default suffix has been
4321             --  specified, there is a suffix specified, either the one
4322             --  in the project file or if there were none, the default.
4323
4324             if Impl_Suffixs /= No_Array_Element then
4325                Suffix := Data.Naming.Body_Suffix;
4326                while Suffix /= No_Array_Element loop
4327                   Element :=
4328                     In_Tree.Array_Elements.Table (Suffix);
4329
4330                   Suffix2 := Impl_Suffixs;
4331                   while Suffix2 /= No_Array_Element loop
4332                      exit when In_Tree.Array_Elements.Table
4333                                 (Suffix2).Index = Element.Index;
4334                      Suffix2 := In_Tree.Array_Elements.Table
4335                                   (Suffix2).Next;
4336                   end loop;
4337
4338                   --  There is a registered default suffix, but no suffix was
4339                   --  specified in the project file. Add default to the array.
4340
4341                   if Suffix2 = No_Array_Element then
4342                      Array_Element_Table.Increment_Last
4343                        (In_Tree.Array_Elements);
4344                      In_Tree.Array_Elements.Table
4345                        (Array_Element_Table.Last
4346                           (In_Tree.Array_Elements)) :=
4347                        (Index                => Element.Index,
4348                         Src_Index            => Element.Src_Index,
4349                         Index_Case_Sensitive => False,
4350                         Value                => Element.Value,
4351                         Next                 => Impl_Suffixs);
4352                      Impl_Suffixs := Array_Element_Table.Last
4353                                        (In_Tree.Array_Elements);
4354                   end if;
4355
4356                   Suffix := Element.Next;
4357                end loop;
4358
4359                --  Put the resulting array as the implementation suffixes
4360
4361                Data.Naming.Body_Suffix := Impl_Suffixs;
4362             end if;
4363          end;
4364
4365          declare
4366             Current : Array_Element_Id;
4367             Element : Array_Element;
4368
4369          begin
4370             Current := Data.Naming.Body_Suffix;
4371             while Current /= No_Array_Element loop
4372                Element := In_Tree.Array_Elements.Table (Current);
4373                Get_Name_String (Element.Value.Value);
4374
4375                if Name_Len = 0 then
4376                   Error_Msg
4377                     (Project, In_Tree,
4378                      "Body_Suffix cannot be empty",
4379                      Element.Value.Location);
4380                end if;
4381
4382                In_Tree.Array_Elements.Table (Current) := Element;
4383                Current := Element.Next;
4384             end loop;
4385          end;
4386
4387          --  Get the exceptions, if any
4388
4389          Data.Naming.Specification_Exceptions :=
4390            Util.Value_Of
4391              (Name_Specification_Exceptions,
4392               In_Arrays => Naming.Decl.Arrays,
4393               In_Tree   => In_Tree);
4394
4395          Data.Naming.Implementation_Exceptions :=
4396            Util.Value_Of
4397              (Name_Implementation_Exceptions,
4398               In_Arrays => Naming.Decl.Arrays,
4399               In_Tree   => In_Tree);
4400       end if;
4401    end Check_Package_Naming;
4402
4403    ---------------------------------
4404    -- Check_Programming_Languages --
4405    ---------------------------------
4406
4407    procedure Check_Programming_Languages
4408      (In_Tree : Project_Tree_Ref;
4409       Project : Project_Id;
4410       Data    : in out Project_Data)
4411    is
4412       Languages   : Variable_Value := Nil_Variable_Value;
4413       Def_Lang    : Variable_Value := Nil_Variable_Value;
4414       Def_Lang_Id : Name_Id;
4415
4416    begin
4417       Data.First_Language_Processing := No_Language_Index;
4418       Languages :=
4419         Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes, In_Tree);
4420       Def_Lang :=
4421         Prj.Util.Value_Of
4422           (Name_Default_Language, Data.Decl.Attributes, In_Tree);
4423       Data.Ada_Sources_Present   := Data.Source_Dirs /= Nil_String;
4424       Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4425
4426       if Data.Source_Dirs /= Nil_String then
4427
4428          --  Check if languages are specified in this project
4429
4430          if Languages.Default then
4431
4432             --  Attribute Languages is not specified. So, it defaults to
4433             --  a project of the default language only.
4434
4435             Name_List_Table.Increment_Last (In_Tree.Name_Lists);
4436             Data.Languages := Name_List_Table.Last (In_Tree.Name_Lists);
4437
4438             --  In Ada_Only mode, the default language is Ada
4439
4440             if Get_Mode = Ada_Only then
4441                In_Tree.Name_Lists.Table (Data.Languages) :=
4442                  (Name => Name_Ada, Next => No_Name_List);
4443
4444                --  Attribute Languages is not specified. So, it defaults to
4445                --  a project of language Ada only. No sources of languages
4446                --  other than Ada
4447
4448                Data.Other_Sources_Present := False;
4449
4450             else
4451                --  Fail if there is no default language defined
4452
4453                if Def_Lang.Default then
4454                   if not Default_Language_Is_Ada then
4455                      Error_Msg
4456                        (Project,
4457                         In_Tree,
4458                         "no languages defined for this project",
4459                         Data.Location);
4460                      Def_Lang_Id := No_Name;
4461                   else
4462                      Def_Lang_Id := Name_Ada;
4463                   end if;
4464
4465                else
4466                   Get_Name_String (Def_Lang.Value);
4467                   To_Lower (Name_Buffer (1 .. Name_Len));
4468                   Def_Lang_Id := Name_Find;
4469                end if;
4470
4471                if Def_Lang_Id /=  No_Name then
4472                   In_Tree.Name_Lists.Table (Data.Languages) :=
4473                     (Name => Def_Lang_Id, Next => No_Name_List);
4474
4475                   Language_Data_Table.Increment_Last (In_Tree.Languages_Data);
4476
4477                   Data.First_Language_Processing :=
4478                     Language_Data_Table.Last (In_Tree.Languages_Data);
4479                   In_Tree.Languages_Data.Table
4480                     (Data.First_Language_Processing) := No_Language_Data;
4481                   In_Tree.Languages_Data.Table
4482                     (Data.First_Language_Processing).Name := Def_Lang_Id;
4483                   Get_Name_String (Def_Lang_Id);
4484                   Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4485                   In_Tree.Languages_Data.Table
4486                     (Data.First_Language_Processing).Display_Name := Name_Find;
4487
4488                   if Def_Lang_Id = Name_Ada then
4489                      In_Tree.Languages_Data.Table
4490                        (Data.First_Language_Processing).Config.Kind
4491                        := Unit_Based;
4492                      In_Tree.Languages_Data.Table
4493                        (Data.First_Language_Processing).Config.Dependency_Kind
4494                        := ALI_File;
4495                      Data.Unit_Based_Language_Name := Name_Ada;
4496                      Data.Unit_Based_Language_Index :=
4497                        Data.First_Language_Processing;
4498                   else
4499                      In_Tree.Languages_Data.Table
4500                        (Data.First_Language_Processing).Config.Kind
4501                        := File_Based;
4502                   end if;
4503                end if;
4504             end if;
4505
4506          else
4507             declare
4508                Current           : String_List_Id := Languages.Values;
4509                Element           : String_Element;
4510                Lang_Name         : Name_Id;
4511                Index             : Language_Index;
4512                Lang_Data         : Language_Data;
4513                NL_Id             : Name_List_Index := No_Name_List;
4514
4515             begin
4516                --  Assume there are no language declared
4517
4518                Data.Ada_Sources_Present := False;
4519                Data.Other_Sources_Present := False;
4520
4521                --  If there are no languages declared, there are no sources
4522
4523                if Current = Nil_String then
4524                   Data.Source_Dirs := Nil_String;
4525
4526                   if Data.Qualifier = Standard then
4527                      Error_Msg
4528                        (Project,
4529                         In_Tree,
4530                         "a standard project cannot have no language declared",
4531                         Languages.Location);
4532                   end if;
4533
4534                else
4535                   --  Look through all the languages specified in attribute
4536                   --  Languages.
4537
4538                   while Current /= Nil_String loop
4539                      Element :=
4540                        In_Tree.String_Elements.Table (Current);
4541                      Get_Name_String (Element.Value);
4542                      To_Lower (Name_Buffer (1 .. Name_Len));
4543                      Lang_Name := Name_Find;
4544
4545                      NL_Id := Data.Languages;
4546                      while NL_Id /= No_Name_List loop
4547                         exit when
4548                           Lang_Name = In_Tree.Name_Lists.Table (NL_Id).Name;
4549                         NL_Id := In_Tree.Name_Lists.Table (NL_Id).Next;
4550                      end loop;
4551
4552                      if NL_Id = No_Name_List then
4553                         Name_List_Table.Increment_Last (In_Tree.Name_Lists);
4554
4555                         if Data.Languages = No_Name_List then
4556                            Data.Languages :=
4557                              Name_List_Table.Last (In_Tree.Name_Lists);
4558
4559                         else
4560                            NL_Id := Data.Languages;
4561                            while In_Tree.Name_Lists.Table (NL_Id).Next /=
4562                                    No_Name_List
4563                            loop
4564                               NL_Id := In_Tree.Name_Lists.Table (NL_Id).Next;
4565                            end loop;
4566
4567                            In_Tree.Name_Lists.Table (NL_Id).Next :=
4568                              Name_List_Table.Last (In_Tree.Name_Lists);
4569                         end if;
4570
4571                         NL_Id := Name_List_Table.Last (In_Tree.Name_Lists);
4572                         In_Tree.Name_Lists.Table (NL_Id) :=
4573                           (Lang_Name, No_Name_List);
4574
4575                         if Get_Mode = Ada_Only then
4576                            --  Check for language Ada
4577
4578                            if Lang_Name = Name_Ada then
4579                               Data.Ada_Sources_Present := True;
4580
4581                            else
4582                               Data.Other_Sources_Present := True;
4583                            end if;
4584
4585                         else
4586                            Language_Data_Table.Increment_Last
4587                                                  (In_Tree.Languages_Data);
4588                            Index :=
4589                              Language_Data_Table.Last (In_Tree.Languages_Data);
4590                            Lang_Data.Name := Lang_Name;
4591                            Lang_Data.Display_Name := Element.Value;
4592                            Lang_Data.Next := Data.First_Language_Processing;
4593
4594                            if Lang_Name = Name_Ada then
4595                               Lang_Data.Config.Kind := Unit_Based;
4596                               Lang_Data.Config.Dependency_Kind := ALI_File;
4597                               Data.Unit_Based_Language_Name := Name_Ada;
4598                               Data.Unit_Based_Language_Index := Index;
4599
4600                            else
4601                               Lang_Data.Config.Kind := File_Based;
4602                               Lang_Data.Config.Dependency_Kind := None;
4603                            end if;
4604
4605                            In_Tree.Languages_Data.Table (Index) := Lang_Data;
4606                            Data.First_Language_Processing := Index;
4607                         end if;
4608                      end if;
4609
4610                      Current := Element.Next;
4611                   end loop;
4612                end if;
4613             end;
4614          end if;
4615       end if;
4616    end Check_Programming_Languages;
4617
4618    -------------------
4619    -- Check_Project --
4620    -------------------
4621
4622    function Check_Project
4623      (P            : Project_Id;
4624       Root_Project : Project_Id;
4625       In_Tree      : Project_Tree_Ref;
4626       Extending    : Boolean) return Boolean
4627    is
4628    begin
4629       if P = Root_Project then
4630          return True;
4631
4632       elsif Extending then
4633          declare
4634             Data : Project_Data := In_Tree.Projects.Table (Root_Project);
4635
4636          begin
4637             while Data.Extends /= No_Project loop
4638                if P = Data.Extends then
4639                   return True;
4640                end if;
4641
4642                Data := In_Tree.Projects.Table (Data.Extends);
4643             end loop;
4644          end;
4645       end if;
4646
4647       return False;
4648    end Check_Project;
4649
4650    -------------------------------
4651    -- Check_Stand_Alone_Library --
4652    -------------------------------
4653
4654    procedure Check_Stand_Alone_Library
4655      (Project     : Project_Id;
4656       In_Tree     : Project_Tree_Ref;
4657       Data        : in out Project_Data;
4658       Current_Dir : String;
4659       Extending   : Boolean)
4660    is
4661       Lib_Interfaces      : constant Prj.Variable_Value :=
4662                               Prj.Util.Value_Of
4663                                 (Snames.Name_Library_Interface,
4664                                  Data.Decl.Attributes,
4665                                  In_Tree);
4666
4667       Lib_Auto_Init       : constant Prj.Variable_Value :=
4668                               Prj.Util.Value_Of
4669                                 (Snames.Name_Library_Auto_Init,
4670                                  Data.Decl.Attributes,
4671                                  In_Tree);
4672
4673       Lib_Src_Dir         : constant Prj.Variable_Value :=
4674                               Prj.Util.Value_Of
4675                                 (Snames.Name_Library_Src_Dir,
4676                                  Data.Decl.Attributes,
4677                                  In_Tree);
4678
4679       Lib_Symbol_File     : constant Prj.Variable_Value :=
4680                               Prj.Util.Value_Of
4681                                 (Snames.Name_Library_Symbol_File,
4682                                  Data.Decl.Attributes,
4683                                  In_Tree);
4684
4685       Lib_Symbol_Policy   : constant Prj.Variable_Value :=
4686                               Prj.Util.Value_Of
4687                                 (Snames.Name_Library_Symbol_Policy,
4688                                  Data.Decl.Attributes,
4689                                  In_Tree);
4690
4691       Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4692                               Prj.Util.Value_Of
4693                                 (Snames.Name_Library_Reference_Symbol_File,
4694                                  Data.Decl.Attributes,
4695                                  In_Tree);
4696
4697       Auto_Init_Supported : Boolean;
4698       OK                  : Boolean := True;
4699       Source              : Source_Id;
4700       Next_Proj           : Project_Id;
4701
4702    begin
4703       if Get_Mode = Multi_Language then
4704          Auto_Init_Supported := Data.Config.Auto_Init_Supported;
4705       else
4706          Auto_Init_Supported :=
4707            MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported;
4708       end if;
4709
4710       pragma Assert (Lib_Interfaces.Kind = List);
4711
4712       --  It is a stand-alone library project file if attribute
4713       --  Library_Interface is defined.
4714
4715       if not Lib_Interfaces.Default then
4716          SAL_Library : declare
4717             Interfaces     : String_List_Id := Lib_Interfaces.Values;
4718             Interface_ALIs : String_List_Id := Nil_String;
4719             Unit           : Name_Id;
4720             The_Unit_Id    : Unit_Index;
4721             The_Unit_Data  : Unit_Data;
4722
4723             procedure Add_ALI_For (Source : File_Name_Type);
4724             --  Add an ALI file name to the list of Interface ALIs
4725
4726             -----------------
4727             -- Add_ALI_For --
4728             -----------------
4729
4730             procedure Add_ALI_For (Source : File_Name_Type) is
4731             begin
4732                Get_Name_String (Source);
4733
4734                declare
4735                   ALI         : constant String :=
4736                                   ALI_File_Name (Name_Buffer (1 .. Name_Len));
4737                   ALI_Name_Id : Name_Id;
4738
4739                begin
4740                   Name_Len := ALI'Length;
4741                   Name_Buffer (1 .. Name_Len) := ALI;
4742                   ALI_Name_Id := Name_Find;
4743
4744                   String_Element_Table.Increment_Last
4745                     (In_Tree.String_Elements);
4746                   In_Tree.String_Elements.Table
4747                     (String_Element_Table.Last
4748                       (In_Tree.String_Elements)) :=
4749                     (Value         => ALI_Name_Id,
4750                      Index         => 0,
4751                      Display_Value => ALI_Name_Id,
4752                      Location      =>
4753                        In_Tree.String_Elements.Table
4754                          (Interfaces).Location,
4755                      Flag          => False,
4756                      Next          => Interface_ALIs);
4757                   Interface_ALIs := String_Element_Table.Last
4758                                       (In_Tree.String_Elements);
4759                end;
4760             end Add_ALI_For;
4761
4762          --  Start of processing for SAL_Library
4763
4764          begin
4765             Data.Standalone_Library := True;
4766
4767             --  Library_Interface cannot be an empty list
4768
4769             if Interfaces = Nil_String then
4770                Error_Msg
4771                  (Project, In_Tree,
4772                   "Library_Interface cannot be an empty list",
4773                   Lib_Interfaces.Location);
4774             end if;
4775
4776             --  Process each unit name specified in the attribute
4777             --  Library_Interface.
4778
4779             while Interfaces /= Nil_String loop
4780                Get_Name_String
4781                  (In_Tree.String_Elements.Table (Interfaces).Value);
4782                To_Lower (Name_Buffer (1 .. Name_Len));
4783
4784                if Name_Len = 0 then
4785                   Error_Msg
4786                     (Project, In_Tree,
4787                      "an interface cannot be an empty string",
4788                      In_Tree.String_Elements.Table (Interfaces).Location);
4789
4790                else
4791                   Unit := Name_Find;
4792                   Error_Msg_Name_1 := Unit;
4793
4794                   if Get_Mode = Ada_Only then
4795                      The_Unit_Id :=
4796                        Units_Htable.Get (In_Tree.Units_HT, Unit);
4797
4798                      if The_Unit_Id = No_Unit_Index then
4799                         Error_Msg
4800                           (Project, In_Tree,
4801                            "unknown unit %%",
4802                            In_Tree.String_Elements.Table
4803                              (Interfaces).Location);
4804
4805                      else
4806                         --  Check that the unit is part of the project
4807
4808                         The_Unit_Data :=
4809                           In_Tree.Units.Table (The_Unit_Id);
4810
4811                         if The_Unit_Data.File_Names (Body_Part).Name /= No_File
4812                           and then The_Unit_Data.File_Names
4813                                      (Body_Part).Path.Name /= Slash
4814                         then
4815                            if Check_Project
4816                              (The_Unit_Data.File_Names (Body_Part).Project,
4817                               Project, In_Tree, Extending)
4818                            then
4819                               --  There is a body for this unit.
4820                               --  If there is no spec, we need to check
4821                               --  that it is not a subunit.
4822
4823                               if The_Unit_Data.File_Names
4824                                 (Specification).Name = No_File
4825                               then
4826                                  declare
4827                                     Src_Ind : Source_File_Index;
4828
4829                                  begin
4830                                     Src_Ind := Sinput.P.Load_Project_File
4831                                       (Get_Name_String
4832                                          (The_Unit_Data.File_Names
4833                                             (Body_Part).Path.Name));
4834
4835                                     if Sinput.P.Source_File_Is_Subunit
4836                                       (Src_Ind)
4837                                     then
4838                                        Error_Msg
4839                                          (Project, In_Tree,
4840                                           "%% is a subunit; " &
4841                                           "it cannot be an interface",
4842                                           In_Tree.
4843                                             String_Elements.Table
4844                                               (Interfaces).Location);
4845                                     end if;
4846                                  end;
4847                               end if;
4848
4849                               --  The unit is not a subunit, so we add
4850                               --  to the Interface ALIs the ALI file
4851                               --  corresponding to the body.
4852
4853                               Add_ALI_For
4854                                 (The_Unit_Data.File_Names (Body_Part).Name);
4855
4856                            else
4857                               Error_Msg
4858                                 (Project, In_Tree,
4859                                  "%% is not an unit of this project",
4860                                  In_Tree.String_Elements.Table
4861                                    (Interfaces).Location);
4862                            end if;
4863
4864                         elsif The_Unit_Data.File_Names
4865                           (Specification).Name /= No_File
4866                           and then The_Unit_Data.File_Names
4867                             (Specification).Path.Name /= Slash
4868                           and then Check_Project
4869                             (The_Unit_Data.File_Names
4870                                  (Specification).Project,
4871                              Project, In_Tree, Extending)
4872
4873                         then
4874                            --  The unit is part of the project, it has
4875                            --  a spec, but no body. We add to the Interface
4876                            --  ALIs the ALI file corresponding to the spec.
4877
4878                            Add_ALI_For
4879                              (The_Unit_Data.File_Names (Specification).Name);
4880
4881                         else
4882                            Error_Msg
4883                              (Project, In_Tree,
4884                               "%% is not an unit of this project",
4885                               In_Tree.String_Elements.Table
4886                                 (Interfaces).Location);
4887                         end if;
4888                      end if;
4889
4890                   else
4891                      --  Multi_Language mode
4892
4893                      Next_Proj := Data.Extends;
4894                      Source := Data.First_Source;
4895
4896                      loop
4897                         while Source /= No_Source and then
4898                               In_Tree.Sources.Table (Source).Unit /= Unit
4899                         loop
4900                            Source :=
4901                              In_Tree.Sources.Table (Source).Next_In_Project;
4902                         end loop;
4903
4904                         exit when Source /= No_Source or else
4905                                   Next_Proj = No_Project;
4906
4907                         Source :=
4908                           In_Tree.Projects.Table (Next_Proj).First_Source;
4909                         Next_Proj :=
4910                           In_Tree.Projects.Table (Next_Proj).Extends;
4911                      end loop;
4912
4913                      if Source /= No_Source then
4914                         if In_Tree.Sources.Table (Source).Kind = Sep then
4915                            Source := No_Source;
4916
4917                         elsif In_Tree.Sources.Table (Source).Kind = Spec
4918                           and then
4919                           In_Tree.Sources.Table (Source).Other_Part /=
4920                           No_Source
4921                         then
4922                            Source := In_Tree.Sources.Table (Source).Other_Part;
4923                         end if;
4924                      end if;
4925
4926                      if Source /= No_Source then
4927                         if In_Tree.Sources.Table (Source).Project /= Project
4928                           and then
4929                             not Is_Extending
4930                               (Project,
4931                                In_Tree.Sources.Table (Source).Project,
4932                                In_Tree)
4933                         then
4934                            Source := No_Source;
4935                         end if;
4936                      end if;
4937
4938                      if Source = No_Source then
4939                            Error_Msg
4940                              (Project, In_Tree,
4941                               "%% is not an unit of this project",
4942                               In_Tree.String_Elements.Table
4943                                 (Interfaces).Location);
4944
4945                      else
4946                         if In_Tree.Sources.Table (Source).Kind = Spec and then
4947                           In_Tree.Sources.Table (Source).Other_Part /=
4948                             No_Source
4949                         then
4950                            Source := In_Tree.Sources.Table (Source).Other_Part;
4951                         end if;
4952
4953                         String_Element_Table.Increment_Last
4954                           (In_Tree.String_Elements);
4955                         In_Tree.String_Elements.Table
4956                           (String_Element_Table.Last
4957                              (In_Tree.String_Elements)) :=
4958                           (Value         =>
4959                              Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
4960                            Index         => 0,
4961                            Display_Value =>
4962                              Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
4963                            Location      =>
4964                              In_Tree.String_Elements.Table
4965                                (Interfaces).Location,
4966                            Flag          => False,
4967                            Next          => Interface_ALIs);
4968                         Interface_ALIs := String_Element_Table.Last
4969                           (In_Tree.String_Elements);
4970                      end if;
4971
4972                   end if;
4973
4974                end if;
4975
4976                Interfaces :=
4977                  In_Tree.String_Elements.Table (Interfaces).Next;
4978             end loop;
4979
4980             --  Put the list of Interface ALIs in the project data
4981
4982             Data.Lib_Interface_ALIs := Interface_ALIs;
4983
4984             --  Check value of attribute Library_Auto_Init and set
4985             --  Lib_Auto_Init accordingly.
4986
4987             if Lib_Auto_Init.Default then
4988
4989                --  If no attribute Library_Auto_Init is declared, then set auto
4990                --  init only if it is supported.
4991
4992                Data.Lib_Auto_Init := Auto_Init_Supported;
4993
4994             else
4995                Get_Name_String (Lib_Auto_Init.Value);
4996                To_Lower (Name_Buffer (1 .. Name_Len));
4997
4998                if Name_Buffer (1 .. Name_Len) = "false" then
4999                   Data.Lib_Auto_Init := False;
5000
5001                elsif Name_Buffer (1 .. Name_Len) = "true" then
5002                   if Auto_Init_Supported then
5003                      Data.Lib_Auto_Init := True;
5004
5005                   else
5006                      --  Library_Auto_Init cannot be "true" if auto init is not
5007                      --  supported
5008
5009                      Error_Msg
5010                        (Project, In_Tree,
5011                         "library auto init not supported " &
5012                         "on this platform",
5013                         Lib_Auto_Init.Location);
5014                   end if;
5015
5016                else
5017                   Error_Msg
5018                     (Project, In_Tree,
5019                      "invalid value for attribute Library_Auto_Init",
5020                      Lib_Auto_Init.Location);
5021                end if;
5022             end if;
5023          end SAL_Library;
5024
5025          --  If attribute Library_Src_Dir is defined and not the empty string,
5026          --  check if the directory exist and is not the object directory or
5027          --  one of the source directories. This is the directory where copies
5028          --  of the interface sources will be copied. Note that this directory
5029          --  may be the library directory.
5030
5031          if Lib_Src_Dir.Value /= Empty_String then
5032             declare
5033                Dir_Id : constant File_Name_Type :=
5034                           File_Name_Type (Lib_Src_Dir.Value);
5035
5036             begin
5037                Locate_Directory
5038                  (Project,
5039                   In_Tree,
5040                   Dir_Id,
5041                   Data.Directory.Display_Name,
5042                   Data.Library_Src_Dir.Name,
5043                   Data.Library_Src_Dir.Display_Name,
5044                   Create => "library source copy",
5045                   Current_Dir => Current_Dir,
5046                   Location => Lib_Src_Dir.Location);
5047
5048                --  If directory does not exist, report an error
5049
5050                if Data.Library_Src_Dir = No_Path_Information then
5051
5052                   --  Get the absolute name of the library directory that does
5053                   --  not exist, to report an error.
5054
5055                   declare
5056                      Dir_Name : constant String :=
5057                                   Get_Name_String (Dir_Id);
5058
5059                   begin
5060                      if Is_Absolute_Path (Dir_Name) then
5061                         Err_Vars.Error_Msg_File_1 := Dir_Id;
5062
5063                      else
5064                         Get_Name_String (Data.Directory.Name);
5065
5066                         if Name_Buffer (Name_Len) /=
5067                           Directory_Separator
5068                         then
5069                            Name_Len := Name_Len + 1;
5070                            Name_Buffer (Name_Len) :=
5071                              Directory_Separator;
5072                         end if;
5073
5074                         Name_Buffer
5075                           (Name_Len + 1 ..
5076                              Name_Len + Dir_Name'Length) :=
5077                             Dir_Name;
5078                         Name_Len := Name_Len + Dir_Name'Length;
5079                         Err_Vars.Error_Msg_Name_1 := Name_Find;
5080                      end if;
5081
5082                      --  Report the error
5083
5084                      Error_Msg_File_1 := Dir_Id;
5085                      Error_Msg
5086                        (Project, In_Tree,
5087                         "Directory { does not exist",
5088                         Lib_Src_Dir.Location);
5089                   end;
5090
5091                   --  Report error if it is the same as the object directory
5092
5093                elsif Data.Library_Src_Dir = Data.Object_Directory then
5094                   Error_Msg
5095                     (Project, In_Tree,
5096                      "directory to copy interfaces cannot be " &
5097                      "the object directory",
5098                      Lib_Src_Dir.Location);
5099                   Data.Library_Src_Dir := No_Path_Information;
5100
5101                else
5102                   declare
5103                      Src_Dirs : String_List_Id;
5104                      Src_Dir  : String_Element;
5105
5106                   begin
5107                      --  Interface copy directory cannot be one of the source
5108                      --  directory of the current project.
5109
5110                      Src_Dirs := Data.Source_Dirs;
5111                      while Src_Dirs /= Nil_String loop
5112                         Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
5113
5114                         --  Report error if it is one of the source directories
5115
5116                         if Data.Library_Src_Dir.Name =
5117                           Path_Name_Type (Src_Dir.Value)
5118                         then
5119                            Error_Msg
5120                              (Project, In_Tree,
5121                               "directory to copy interfaces cannot " &
5122                               "be one of the source directories",
5123                               Lib_Src_Dir.Location);
5124                            Data.Library_Src_Dir := No_Path_Information;
5125                            exit;
5126                         end if;
5127
5128                         Src_Dirs := Src_Dir.Next;
5129                      end loop;
5130
5131                      if Data.Library_Src_Dir /= No_Path_Information then
5132
5133                         --  It cannot be a source directory of any other
5134                         --  project either.
5135
5136                         Project_Loop : for Pid in 1 ..
5137                           Project_Table.Last (In_Tree.Projects)
5138                         loop
5139                            Src_Dirs :=
5140                              In_Tree.Projects.Table (Pid).Source_Dirs;
5141                            Dir_Loop : while Src_Dirs /= Nil_String loop
5142                               Src_Dir :=
5143                                 In_Tree.String_Elements.Table (Src_Dirs);
5144
5145                               --  Report error if it is one of the source
5146                               --  directories
5147
5148                               if Data.Library_Src_Dir.Name =
5149                                 Path_Name_Type (Src_Dir.Value)
5150                               then
5151                                  Error_Msg_File_1 :=
5152                                    File_Name_Type (Src_Dir.Value);
5153                                  Error_Msg_Name_1 :=
5154                                    In_Tree.Projects.Table (Pid).Name;
5155                                  Error_Msg
5156                                    (Project, In_Tree,
5157                                     "directory to copy interfaces cannot " &
5158                                     "be the same as source directory { of " &
5159                                     "project %%",
5160                                     Lib_Src_Dir.Location);
5161                                  Data.Library_Src_Dir := No_Path_Information;
5162                                  exit Project_Loop;
5163                               end if;
5164
5165                               Src_Dirs := Src_Dir.Next;
5166                            end loop Dir_Loop;
5167                         end loop Project_Loop;
5168                      end if;
5169                   end;
5170
5171                   --  In high verbosity, if there is a valid Library_Src_Dir,
5172                   --  display its path name.
5173
5174                   if Data.Library_Src_Dir /= No_Path_Information
5175                     and then Current_Verbosity = High
5176                   then
5177                      Write_Str ("Directory to copy interfaces =""");
5178                      Write_Str (Get_Name_String (Data.Library_Src_Dir.Name));
5179                      Write_Line ("""");
5180                   end if;
5181                end if;
5182             end;
5183          end if;
5184
5185          --  Check the symbol related attributes
5186
5187          --  First, the symbol policy
5188
5189          if not Lib_Symbol_Policy.Default then
5190             declare
5191                Value : constant String :=
5192                  To_Lower
5193                    (Get_Name_String (Lib_Symbol_Policy.Value));
5194
5195             begin
5196                --  Symbol policy must hove one of a limited number of values
5197
5198                if Value = "autonomous" or else Value = "default" then
5199                   Data.Symbol_Data.Symbol_Policy := Autonomous;
5200
5201                elsif Value = "compliant" then
5202                   Data.Symbol_Data.Symbol_Policy := Compliant;
5203
5204                elsif Value = "controlled" then
5205                   Data.Symbol_Data.Symbol_Policy := Controlled;
5206
5207                elsif Value = "restricted" then
5208                   Data.Symbol_Data.Symbol_Policy := Restricted;
5209
5210                elsif Value = "direct" then
5211                   Data.Symbol_Data.Symbol_Policy := Direct;
5212
5213                else
5214                   Error_Msg
5215                     (Project, In_Tree,
5216                      "illegal value for Library_Symbol_Policy",
5217                      Lib_Symbol_Policy.Location);
5218                end if;
5219             end;
5220          end if;
5221
5222          --  If attribute Library_Symbol_File is not specified, symbol policy
5223          --  cannot be Restricted.
5224
5225          if Lib_Symbol_File.Default then
5226             if Data.Symbol_Data.Symbol_Policy = Restricted then
5227                Error_Msg
5228                  (Project, In_Tree,
5229                   "Library_Symbol_File needs to be defined when " &
5230                   "symbol policy is Restricted",
5231                   Lib_Symbol_Policy.Location);
5232             end if;
5233
5234          else
5235             --  Library_Symbol_File is defined
5236
5237             Data.Symbol_Data.Symbol_File :=
5238               Path_Name_Type (Lib_Symbol_File.Value);
5239
5240             Get_Name_String (Lib_Symbol_File.Value);
5241
5242             if Name_Len = 0 then
5243                Error_Msg
5244                  (Project, In_Tree,
5245                   "symbol file name cannot be an empty string",
5246                   Lib_Symbol_File.Location);
5247
5248             else
5249                OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
5250
5251                if OK then
5252                   for J in 1 .. Name_Len loop
5253                      if Name_Buffer (J) = '/'
5254                        or else Name_Buffer (J) = Directory_Separator
5255                      then
5256                         OK := False;
5257                         exit;
5258                      end if;
5259                   end loop;
5260                end if;
5261
5262                if not OK then
5263                   Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
5264                   Error_Msg
5265                     (Project, In_Tree,
5266                      "symbol file name { is illegal. " &
5267                      "Name cannot include directory info.",
5268                      Lib_Symbol_File.Location);
5269                end if;
5270             end if;
5271          end if;
5272
5273          --  If attribute Library_Reference_Symbol_File is not defined,
5274          --  symbol policy cannot be Compliant or Controlled.
5275
5276          if Lib_Ref_Symbol_File.Default then
5277             if Data.Symbol_Data.Symbol_Policy = Compliant
5278               or else Data.Symbol_Data.Symbol_Policy = Controlled
5279             then
5280                Error_Msg
5281                  (Project, In_Tree,
5282                   "a reference symbol file need to be defined",
5283                   Lib_Symbol_Policy.Location);
5284             end if;
5285
5286          else
5287             --  Library_Reference_Symbol_File is defined, check file exists
5288
5289             Data.Symbol_Data.Reference :=
5290               Path_Name_Type (Lib_Ref_Symbol_File.Value);
5291
5292             Get_Name_String (Lib_Ref_Symbol_File.Value);
5293
5294             if Name_Len = 0 then
5295                Error_Msg
5296                  (Project, In_Tree,
5297                   "reference symbol file name cannot be an empty string",
5298                   Lib_Symbol_File.Location);
5299
5300             else
5301                if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
5302                   Name_Len := 0;
5303                   Add_Str_To_Name_Buffer
5304                     (Get_Name_String (Data.Directory.Name));
5305                   Add_Char_To_Name_Buffer (Directory_Separator);
5306                   Add_Str_To_Name_Buffer
5307                     (Get_Name_String (Lib_Ref_Symbol_File.Value));
5308                   Data.Symbol_Data.Reference := Name_Find;
5309                end if;
5310
5311                if not Is_Regular_File
5312                  (Get_Name_String (Data.Symbol_Data.Reference))
5313                then
5314                   Error_Msg_File_1 :=
5315                     File_Name_Type (Lib_Ref_Symbol_File.Value);
5316
5317                   --  For controlled and direct symbol policies, it is an error
5318                   --  if the reference symbol file does not exist. For other
5319                   --  symbol policies, this is just a warning
5320
5321                   Error_Msg_Warn :=
5322                     Data.Symbol_Data.Symbol_Policy /= Controlled
5323                     and then Data.Symbol_Data.Symbol_Policy /= Direct;
5324
5325                   Error_Msg
5326                     (Project, In_Tree,
5327                      "<library reference symbol file { does not exist",
5328                      Lib_Ref_Symbol_File.Location);
5329
5330                   --  In addition in the non-controlled case, if symbol policy
5331                   --  is Compliant, it is changed to Autonomous, because there
5332                   --  is no reference to check against, and we don't want to
5333                   --  fail in this case.
5334
5335                   if Data.Symbol_Data.Symbol_Policy /= Controlled then
5336                      if Data.Symbol_Data.Symbol_Policy = Compliant then
5337                         Data.Symbol_Data.Symbol_Policy := Autonomous;
5338                      end if;
5339                   end if;
5340                end if;
5341
5342                --  If both the reference symbol file and the symbol file are
5343                --  defined, then check that they are not the same file.
5344
5345                if Data.Symbol_Data.Symbol_File /= No_Path then
5346                   Get_Name_String (Data.Symbol_Data.Symbol_File);
5347
5348                   if Name_Len > 0 then
5349                      declare
5350                         Symb_Path : constant String :=
5351                                       Normalize_Pathname
5352                                         (Get_Name_String
5353                                            (Data.Object_Directory.Name) &
5354                                          Directory_Separator &
5355                                          Name_Buffer (1 .. Name_Len),
5356                                          Directory     => Current_Dir,
5357                                          Resolve_Links =>
5358                                            Opt.Follow_Links_For_Files);
5359                         Ref_Path  : constant String :=
5360                                       Normalize_Pathname
5361                                         (Get_Name_String
5362                                            (Data.Symbol_Data.Reference),
5363                                          Directory     => Current_Dir,
5364                                          Resolve_Links =>
5365                                            Opt.Follow_Links_For_Files);
5366                      begin
5367                         if Symb_Path = Ref_Path then
5368                            Error_Msg
5369                              (Project, In_Tree,
5370                               "library reference symbol file and library" &
5371                               " symbol file cannot be the same file",
5372                               Lib_Ref_Symbol_File.Location);
5373                         end if;
5374                      end;
5375                   end if;
5376                end if;
5377             end if;
5378          end if;
5379       end if;
5380    end Check_Stand_Alone_Library;
5381
5382    ----------------------------
5383    -- Compute_Directory_Last --
5384    ----------------------------
5385
5386    function Compute_Directory_Last (Dir : String) return Natural is
5387    begin
5388       if Dir'Length > 1
5389         and then (Dir (Dir'Last - 1) = Directory_Separator
5390                   or else Dir (Dir'Last - 1) = '/')
5391       then
5392          return Dir'Last - 1;
5393       else
5394          return Dir'Last;
5395       end if;
5396    end Compute_Directory_Last;
5397
5398    ---------------
5399    -- Error_Msg --
5400    ---------------
5401
5402    procedure Error_Msg
5403      (Project       : Project_Id;
5404       In_Tree       : Project_Tree_Ref;
5405       Msg           : String;
5406       Flag_Location : Source_Ptr)
5407    is
5408       Real_Location : Source_Ptr := Flag_Location;
5409       Error_Buffer  : String (1 .. 5_000);
5410       Error_Last    : Natural := 0;
5411       Name_Number   : Natural := 0;
5412       File_Number   : Natural := 0;
5413       First         : Positive := Msg'First;
5414       Index         : Positive;
5415
5416       procedure Add (C : Character);
5417       --  Add a character to the buffer
5418
5419       procedure Add (S : String);
5420       --  Add a string to the buffer
5421
5422       procedure Add_Name;
5423       --  Add a name to the buffer
5424
5425       procedure Add_File;
5426       --  Add a file name to the buffer
5427
5428       ---------
5429       -- Add --
5430       ---------
5431
5432       procedure Add (C : Character) is
5433       begin
5434          Error_Last := Error_Last + 1;
5435          Error_Buffer (Error_Last) := C;
5436       end Add;
5437
5438       procedure Add (S : String) is
5439       begin
5440          Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
5441          Error_Last := Error_Last + S'Length;
5442       end Add;
5443
5444       --------------
5445       -- Add_File --
5446       --------------
5447
5448       procedure Add_File is
5449          File : File_Name_Type;
5450
5451       begin
5452          Add ('"');
5453          File_Number := File_Number + 1;
5454
5455          case File_Number is
5456             when 1 =>
5457                File := Err_Vars.Error_Msg_File_1;
5458             when 2 =>
5459                File := Err_Vars.Error_Msg_File_2;
5460             when 3 =>
5461                File := Err_Vars.Error_Msg_File_3;
5462             when others =>
5463                null;
5464          end case;
5465
5466          Get_Name_String (File);
5467          Add (Name_Buffer (1 .. Name_Len));
5468          Add ('"');
5469       end Add_File;
5470
5471       --------------
5472       -- Add_Name --
5473       --------------
5474
5475       procedure Add_Name is
5476          Name : Name_Id;
5477
5478       begin
5479          Add ('"');
5480          Name_Number := Name_Number + 1;
5481
5482          case Name_Number is
5483             when 1 =>
5484                Name := Err_Vars.Error_Msg_Name_1;
5485             when 2 =>
5486                Name := Err_Vars.Error_Msg_Name_2;
5487             when 3 =>
5488                Name := Err_Vars.Error_Msg_Name_3;
5489             when others =>
5490                null;
5491          end case;
5492
5493          Get_Name_String (Name);
5494          Add (Name_Buffer (1 .. Name_Len));
5495          Add ('"');
5496       end Add_Name;
5497
5498    --  Start of processing for Error_Msg
5499
5500    begin
5501       --  If location of error is unknown, use the location of the project
5502
5503       if Real_Location = No_Location then
5504          Real_Location := In_Tree.Projects.Table (Project).Location;
5505       end if;
5506
5507       if Error_Report = null then
5508          Prj.Err.Error_Msg (Msg, Real_Location);
5509          return;
5510       end if;
5511
5512       --  Ignore continuation character
5513
5514       if Msg (First) = '\' then
5515          First := First + 1;
5516       end if;
5517
5518       --  Warning character is always the first one in this package
5519       --  this is an undocumented kludge???
5520
5521       if Msg (First) = '?' then
5522          First := First + 1;
5523          Add ("Warning: ");
5524
5525       elsif Msg (First) = '<' then
5526          First := First + 1;
5527
5528          if Err_Vars.Error_Msg_Warn then
5529             Add ("Warning: ");
5530          end if;
5531       end if;
5532
5533       Index := First;
5534       while Index <= Msg'Last loop
5535          if Msg (Index) = '{' then
5536             Add_File;
5537
5538          elsif Msg (Index) = '%' then
5539             if Index < Msg'Last and then Msg (Index + 1) = '%' then
5540                Index := Index + 1;
5541             end if;
5542
5543             Add_Name;
5544          else
5545             Add (Msg (Index));
5546          end if;
5547          Index := Index + 1;
5548
5549       end loop;
5550
5551       Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
5552    end Error_Msg;
5553
5554    ----------------------
5555    -- Find_Ada_Sources --
5556    ----------------------
5557
5558    procedure Find_Ada_Sources
5559      (Project      : Project_Id;
5560       In_Tree      : Project_Tree_Ref;
5561       Data         : in out Project_Data;
5562       Current_Dir  : String)
5563    is
5564       Source_Dir      : String_List_Id := Data.Source_Dirs;
5565       Element         : String_Element;
5566       Dir             : Dir_Type;
5567       Current_Source  : String_List_Id := Nil_String;
5568       Source_Recorded : Boolean := False;
5569
5570    begin
5571       if Current_Verbosity = High then
5572          Write_Line ("Looking for sources:");
5573       end if;
5574
5575       --  For each subdirectory
5576
5577       while Source_Dir /= Nil_String loop
5578          begin
5579             Source_Recorded := False;
5580             Element := In_Tree.String_Elements.Table (Source_Dir);
5581             if Element.Value /= No_Name then
5582                Get_Name_String (Element.Display_Value);
5583
5584                declare
5585                   Source_Directory : constant String :=
5586                     Name_Buffer (1 .. Name_Len) & Directory_Separator;
5587                   Dir_Last  : constant Natural :=
5588                      Compute_Directory_Last (Source_Directory);
5589
5590                begin
5591                   if Current_Verbosity = High then
5592                      Write_Str ("Source_Dir = ");
5593                      Write_Line (Source_Directory);
5594                   end if;
5595
5596                   --  We look at every entry in the source directory
5597
5598                   Open (Dir,
5599                         Source_Directory (Source_Directory'First .. Dir_Last));
5600
5601                   loop
5602                      Read (Dir, Name_Buffer, Name_Len);
5603
5604                      if Current_Verbosity = High then
5605                         Write_Str  ("   Checking ");
5606                         Write_Line (Name_Buffer (1 .. Name_Len));
5607                      end if;
5608
5609                      exit when Name_Len = 0;
5610
5611                      declare
5612                         File_Name : constant File_Name_Type := Name_Find;
5613
5614                         --  ??? We could probably optimize the following call:
5615                         --  we need to resolve links only once for the
5616                         --  directory itself, and then do a single call to
5617                         --  readlink() for each file. Unfortunately that would
5618                         --  require a change in Normalize_Pathname so that it
5619                         --  has the option of not resolving links for its
5620                         --  Directory parameter, only for Name.
5621
5622                         Path : constant String :=
5623                                  Normalize_Pathname
5624                                    (Name      => Name_Buffer (1 .. Name_Len),
5625                                     Directory =>
5626                                       Source_Directory
5627                                         (Source_Directory'First .. Dir_Last),
5628                                     Resolve_Links =>
5629                                       Opt.Follow_Links_For_Files,
5630                                     Case_Sensitive => True);
5631
5632                         Path_Name : Path_Name_Type;
5633
5634                      begin
5635                         Name_Len := Path'Length;
5636                         Name_Buffer (1 .. Name_Len) := Path;
5637                         Path_Name := Name_Find;
5638
5639                         --  We attempt to register it as a source. However,
5640                         --  there is no error if the file does not contain a
5641                         --  valid source. But there is an error if we have a
5642                         --  duplicate unit name.
5643
5644                         Record_Ada_Source
5645                           (File_Name       => File_Name,
5646                            Path_Name       => Path_Name,
5647                            Project         => Project,
5648                            In_Tree         => In_Tree,
5649                            Data            => Data,
5650                            Location        => No_Location,
5651                            Current_Source  => Current_Source,
5652                            Source_Recorded => Source_Recorded,
5653                            Current_Dir     => Current_Dir);
5654                      end;
5655                   end loop;
5656
5657                   Close (Dir);
5658                end;
5659             end if;
5660
5661          exception
5662             when Directory_Error =>
5663                null;
5664          end;
5665
5666          if Source_Recorded then
5667             In_Tree.String_Elements.Table (Source_Dir).Flag :=
5668               True;
5669          end if;
5670
5671          Source_Dir := Element.Next;
5672       end loop;
5673
5674       if Current_Verbosity = High then
5675          Write_Line ("end Looking for sources.");
5676       end if;
5677
5678    end Find_Ada_Sources;
5679
5680    --------------------------------
5681    -- Free_Ada_Naming_Exceptions --
5682    --------------------------------
5683
5684    procedure Free_Ada_Naming_Exceptions is
5685    begin
5686       Ada_Naming_Exception_Table.Set_Last (0);
5687       Ada_Naming_Exceptions.Reset;
5688       Reverse_Ada_Naming_Exceptions.Reset;
5689    end Free_Ada_Naming_Exceptions;
5690
5691    ---------------------
5692    -- Get_Directories --
5693    ---------------------
5694
5695    procedure Get_Directories
5696      (Project     : Project_Id;
5697       In_Tree     : Project_Tree_Ref;
5698       Current_Dir : String;
5699       Data        : in out Project_Data)
5700    is
5701       Object_Dir  : constant Variable_Value :=
5702                       Util.Value_Of
5703                         (Name_Object_Dir, Data.Decl.Attributes, In_Tree);
5704
5705       Exec_Dir : constant Variable_Value :=
5706                    Util.Value_Of
5707                      (Name_Exec_Dir, Data.Decl.Attributes, In_Tree);
5708
5709       Source_Dirs : constant Variable_Value :=
5710                       Util.Value_Of
5711                         (Name_Source_Dirs, Data.Decl.Attributes, In_Tree);
5712
5713       Excluded_Source_Dirs : constant Variable_Value :=
5714                               Util.Value_Of
5715                                 (Name_Excluded_Source_Dirs,
5716                                  Data.Decl.Attributes,
5717                                  In_Tree);
5718
5719       Source_Files : constant Variable_Value :=
5720                       Util.Value_Of
5721                         (Name_Source_Files, Data.Decl.Attributes, In_Tree);
5722
5723       Last_Source_Dir : String_List_Id  := Nil_String;
5724
5725       procedure Find_Source_Dirs
5726         (From     : File_Name_Type;
5727          Location : Source_Ptr;
5728          Removed  : Boolean := False);
5729       --  Find one or several source directories, and add (or remove, if
5730       --  Removed is True) them to list of source directories of the project.
5731
5732       ----------------------
5733       -- Find_Source_Dirs --
5734       ----------------------
5735
5736       procedure Find_Source_Dirs
5737         (From     : File_Name_Type;
5738          Location : Source_Ptr;
5739          Removed  : Boolean := False)
5740       is
5741          Directory : constant String := Get_Name_String (From);
5742          Element   : String_Element;
5743
5744          procedure Recursive_Find_Dirs (Path : Name_Id);
5745          --  Find all the subdirectories (recursively) of Path and add them
5746          --  to the list of source directories of the project.
5747
5748          -------------------------
5749          -- Recursive_Find_Dirs --
5750          -------------------------
5751
5752          procedure Recursive_Find_Dirs (Path : Name_Id) is
5753             Dir     : Dir_Type;
5754             Name    : String (1 .. 250);
5755             Last    : Natural;
5756             List    : String_List_Id;
5757             Prev    : String_List_Id;
5758             Element : String_Element;
5759             Found   : Boolean := False;
5760
5761             Non_Canonical_Path : Name_Id := No_Name;
5762             Canonical_Path     : Name_Id := No_Name;
5763
5764             The_Path : constant String :=
5765                          Normalize_Pathname
5766                            (Get_Name_String (Path),
5767                             Directory     => Current_Dir,
5768                             Resolve_Links => Opt.Follow_Links_For_Dirs) &
5769                          Directory_Separator;
5770
5771             The_Path_Last : constant Natural :=
5772                               Compute_Directory_Last (The_Path);
5773
5774          begin
5775             Name_Len := The_Path_Last - The_Path'First + 1;
5776             Name_Buffer (1 .. Name_Len) :=
5777               The_Path (The_Path'First .. The_Path_Last);
5778             Non_Canonical_Path := Name_Find;
5779
5780             if Osint.File_Names_Case_Sensitive then
5781                Canonical_Path := Non_Canonical_Path;
5782             else
5783                Get_Name_String (Non_Canonical_Path);
5784                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5785                Canonical_Path := Name_Find;
5786             end if;
5787
5788             --  To avoid processing the same directory several times, check
5789             --  if the directory is already in Recursive_Dirs. If it is, then
5790             --  there is nothing to do, just return. If it is not, put it there
5791             --  and continue recursive processing.
5792
5793             if not Removed then
5794                if Recursive_Dirs.Get (Canonical_Path) then
5795                   return;
5796                else
5797                   Recursive_Dirs.Set (Canonical_Path, True);
5798                end if;
5799             end if;
5800
5801             --  Check if directory is already in list
5802
5803             List := Data.Source_Dirs;
5804             Prev := Nil_String;
5805             while List /= Nil_String loop
5806                Element := In_Tree.String_Elements.Table (List);
5807
5808                if Element.Value /= No_Name then
5809                   Found := Element.Value = Canonical_Path;
5810                   exit when Found;
5811                end if;
5812
5813                Prev := List;
5814                List := Element.Next;
5815             end loop;
5816
5817             --  If directory is not already in list, put it there
5818
5819             if (not Removed) and (not Found) then
5820                if Current_Verbosity = High then
5821                   Write_Str  ("   ");
5822                   Write_Line (The_Path (The_Path'First .. The_Path_Last));
5823                end if;
5824
5825                String_Element_Table.Increment_Last
5826                  (In_Tree.String_Elements);
5827                Element :=
5828                  (Value         => Canonical_Path,
5829                   Display_Value => Non_Canonical_Path,
5830                   Location      => No_Location,
5831                   Flag          => False,
5832                   Next          => Nil_String,
5833                   Index         => 0);
5834
5835                --  Case of first source directory
5836
5837                if Last_Source_Dir = Nil_String then
5838                   Data.Source_Dirs := String_Element_Table.Last
5839                                         (In_Tree.String_Elements);
5840
5841                   --  Here we already have source directories
5842
5843                else
5844                   --  Link the previous last to the new one
5845
5846                   In_Tree.String_Elements.Table
5847                     (Last_Source_Dir).Next :=
5848                       String_Element_Table.Last
5849                         (In_Tree.String_Elements);
5850                end if;
5851
5852                --  And register this source directory as the new last
5853
5854                Last_Source_Dir  := String_Element_Table.Last
5855                  (In_Tree.String_Elements);
5856                In_Tree.String_Elements.Table (Last_Source_Dir) :=
5857                  Element;
5858
5859             elsif Removed and Found then
5860                if Prev = Nil_String then
5861                   Data.Source_Dirs :=
5862                     In_Tree.String_Elements.Table (List).Next;
5863                else
5864                   In_Tree.String_Elements.Table (Prev).Next :=
5865                     In_Tree.String_Elements.Table (List).Next;
5866                end if;
5867             end if;
5868
5869             --  Now look for subdirectories. We do that even when this
5870             --  directory is already in the list, because some of its
5871             --  subdirectories may not be in the list yet.
5872
5873             Open (Dir, The_Path (The_Path'First .. The_Path_Last));
5874
5875             loop
5876                Read (Dir, Name, Last);
5877                exit when Last = 0;
5878
5879                if Name (1 .. Last) /= "."
5880                  and then Name (1 .. Last) /= ".."
5881                then
5882                   --  Avoid . and .. directories
5883
5884                   if Current_Verbosity = High then
5885                      Write_Str  ("   Checking ");
5886                      Write_Line (Name (1 .. Last));
5887                   end if;
5888
5889                   declare
5890                      Path_Name : constant String :=
5891                        Normalize_Pathname
5892                          (Name      => Name (1 .. Last),
5893                           Directory =>
5894                             The_Path (The_Path'First .. The_Path_Last),
5895                           Resolve_Links  => Opt.Follow_Links_For_Dirs,
5896                           Case_Sensitive => True);
5897
5898                   begin
5899                      if Is_Directory (Path_Name) then
5900                         --  We have found a new subdirectory, call self
5901
5902                         Name_Len := Path_Name'Length;
5903                         Name_Buffer (1 .. Name_Len) := Path_Name;
5904                         Recursive_Find_Dirs (Name_Find);
5905                      end if;
5906                   end;
5907                end if;
5908             end loop;
5909
5910             Close (Dir);
5911
5912          exception
5913             when Directory_Error =>
5914                null;
5915          end Recursive_Find_Dirs;
5916
5917       --  Start of processing for Find_Source_Dirs
5918
5919       begin
5920          if Current_Verbosity = High and then not Removed then
5921             Write_Str ("Find_Source_Dirs (""");
5922             Write_Str (Directory);
5923             Write_Line (""")");
5924          end if;
5925
5926          --  First, check if we are looking for a directory tree, indicated
5927          --  by "/**" at the end.
5928
5929          if Directory'Length >= 3
5930            and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5931            and then (Directory (Directory'Last - 2) = '/'
5932                        or else
5933                      Directory (Directory'Last - 2) = Directory_Separator)
5934          then
5935             if not Removed then
5936                Data.Known_Order_Of_Source_Dirs := False;
5937             end if;
5938
5939             Name_Len := Directory'Length - 3;
5940
5941             if Name_Len = 0 then
5942
5943                --  Case of "/**": all directories in file system
5944
5945                Name_Len := 1;
5946                Name_Buffer (1) := Directory (Directory'First);
5947
5948             else
5949                Name_Buffer (1 .. Name_Len) :=
5950                  Directory (Directory'First .. Directory'Last - 3);
5951             end if;
5952
5953             if Current_Verbosity = High then
5954                Write_Str ("Looking for all subdirectories of """);
5955                Write_Str (Name_Buffer (1 .. Name_Len));
5956                Write_Line ("""");
5957             end if;
5958
5959             declare
5960                Base_Dir : constant File_Name_Type := Name_Find;
5961                Root_Dir : constant String :=
5962                             Normalize_Pathname
5963                               (Name      => Get_Name_String (Base_Dir),
5964                                Directory =>
5965                                  Get_Name_String (Data.Directory.Display_Name),
5966                                Resolve_Links  => False,
5967                                Case_Sensitive => True);
5968
5969             begin
5970                if Root_Dir'Length = 0 then
5971                   Err_Vars.Error_Msg_File_1 := Base_Dir;
5972
5973                   if Location = No_Location then
5974                      Error_Msg
5975                        (Project, In_Tree,
5976                         "{ is not a valid directory.",
5977                         Data.Location);
5978                   else
5979                      Error_Msg
5980                        (Project, In_Tree,
5981                         "{ is not a valid directory.",
5982                         Location);
5983                   end if;
5984
5985                else
5986                   --  We have an existing directory, we register it and all of
5987                   --  its subdirectories.
5988
5989                   if Current_Verbosity = High then
5990                      Write_Line ("Looking for source directories:");
5991                   end if;
5992
5993                   Name_Len := Root_Dir'Length;
5994                   Name_Buffer (1 .. Name_Len) := Root_Dir;
5995                   Recursive_Find_Dirs (Name_Find);
5996
5997                   if Current_Verbosity = High then
5998                      Write_Line ("End of looking for source directories.");
5999                   end if;
6000                end if;
6001             end;
6002
6003          --  We have a single directory
6004
6005          else
6006             declare
6007                Path_Name         : Path_Name_Type;
6008                Display_Path_Name : Path_Name_Type;
6009                List              : String_List_Id;
6010                Prev              : String_List_Id;
6011
6012             begin
6013                Locate_Directory
6014                  (Project     => Project,
6015                   In_Tree     => In_Tree,
6016                   Name        => From,
6017                   Parent      => Data.Directory.Display_Name,
6018                   Dir         => Path_Name,
6019                   Display     => Display_Path_Name,
6020                   Current_Dir => Current_Dir);
6021
6022                if Path_Name = No_Path then
6023                   Err_Vars.Error_Msg_File_1 := From;
6024
6025                   if Location = No_Location then
6026                      Error_Msg
6027                        (Project, In_Tree,
6028                         "{ is not a valid directory",
6029                         Data.Location);
6030                   else
6031                      Error_Msg
6032                        (Project, In_Tree,
6033                         "{ is not a valid directory",
6034                         Location);
6035                   end if;
6036
6037                else
6038                   declare
6039                      Path              : constant String :=
6040                                            Get_Name_String (Path_Name) &
6041                                            Directory_Separator;
6042                      Last_Path         : constant Natural :=
6043                                            Compute_Directory_Last (Path);
6044                      Path_Id           : Name_Id;
6045                      Display_Path      : constant String :=
6046                                            Get_Name_String
6047                                              (Display_Path_Name) &
6048                                            Directory_Separator;
6049                      Last_Display_Path : constant Natural :=
6050                                            Compute_Directory_Last
6051                                              (Display_Path);
6052                      Display_Path_Id   : Name_Id;
6053
6054                   begin
6055                      Name_Len := 0;
6056                      Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
6057                      Path_Id := Name_Find;
6058                      Name_Len := 0;
6059                      Add_Str_To_Name_Buffer
6060                        (Display_Path
6061                           (Display_Path'First .. Last_Display_Path));
6062                      Display_Path_Id := Name_Find;
6063
6064                      if not Removed then
6065
6066                         --  As it is an existing directory, we add it to the
6067                         --  list of directories.
6068
6069                         String_Element_Table.Increment_Last
6070                           (In_Tree.String_Elements);
6071                         Element :=
6072                           (Value         => Path_Id,
6073                            Index         => 0,
6074                            Display_Value => Display_Path_Id,
6075                            Location      => No_Location,
6076                            Flag          => False,
6077                            Next          => Nil_String);
6078
6079                         if Last_Source_Dir = Nil_String then
6080
6081                            --  This is the first source directory
6082
6083                            Data.Source_Dirs := String_Element_Table.Last
6084                              (In_Tree.String_Elements);
6085
6086                         else
6087                            --  We already have source directories, link the
6088                            --  previous last to the new one.
6089
6090                            In_Tree.String_Elements.Table
6091                              (Last_Source_Dir).Next :=
6092                              String_Element_Table.Last
6093                                (In_Tree.String_Elements);
6094                         end if;
6095
6096                         --  And register this source directory as the new last
6097
6098                         Last_Source_Dir := String_Element_Table.Last
6099                           (In_Tree.String_Elements);
6100                         In_Tree.String_Elements.Table
6101                           (Last_Source_Dir) := Element;
6102
6103                      else
6104                         --  Remove source dir, if present
6105
6106                         List := Data.Source_Dirs;
6107                         Prev := Nil_String;
6108
6109                         --  Look for source dir in current list
6110
6111                         while List /= Nil_String loop
6112                            Element := In_Tree.String_Elements.Table (List);
6113                            exit when Element.Value = Path_Id;
6114                            Prev := List;
6115                            List := Element.Next;
6116                         end loop;
6117
6118                         if List /= Nil_String then
6119                            --  Source dir was found, remove it from the list
6120
6121                            if Prev = Nil_String then
6122                               Data.Source_Dirs :=
6123                                 In_Tree.String_Elements.Table (List).Next;
6124
6125                            else
6126                               In_Tree.String_Elements.Table (Prev).Next :=
6127                                 In_Tree.String_Elements.Table (List).Next;
6128                            end if;
6129                         end if;
6130                      end if;
6131                   end;
6132                end if;
6133             end;
6134          end if;
6135       end Find_Source_Dirs;
6136
6137    --  Start of processing for Get_Directories
6138
6139    begin
6140       if Current_Verbosity = High then
6141          Write_Line ("Starting to look for directories");
6142       end if;
6143
6144       --  Check the object directory
6145
6146       pragma Assert (Object_Dir.Kind = Single,
6147                      "Object_Dir is not a single string");
6148
6149       --  We set the object directory to its default
6150
6151       Data.Object_Directory := Data.Directory;
6152
6153       if Object_Dir.Value /= Empty_String then
6154          Get_Name_String (Object_Dir.Value);
6155
6156          if Name_Len = 0 then
6157             Error_Msg
6158               (Project, In_Tree,
6159                "Object_Dir cannot be empty",
6160                Object_Dir.Location);
6161
6162          else
6163             --  We check that the specified object directory does exist
6164
6165             Locate_Directory
6166               (Project,
6167                In_Tree,
6168                File_Name_Type (Object_Dir.Value),
6169                Data.Directory.Display_Name,
6170                Data.Object_Directory.Name,
6171                Data.Object_Directory.Display_Name,
6172                Create   => "object",
6173                Location => Object_Dir.Location,
6174                Current_Dir => Current_Dir);
6175
6176             if Data.Object_Directory = No_Path_Information then
6177
6178                --  The object directory does not exist, report an error if the
6179                --  project is not externally built.
6180
6181                if not Data.Externally_Built then
6182                   Err_Vars.Error_Msg_File_1 :=
6183                     File_Name_Type (Object_Dir.Value);
6184                   Error_Msg
6185                     (Project, In_Tree,
6186                      "the object directory { cannot be found",
6187                      Data.Location);
6188                end if;
6189
6190                --  Do not keep a nil Object_Directory. Set it to the specified
6191                --  (relative or absolute) path. This is for the benefit of
6192                --  tools that recover from errors; for example, these tools
6193                --  could create the non existent directory.
6194
6195                Data.Object_Directory.Display_Name :=
6196                  Path_Name_Type (Object_Dir.Value);
6197
6198                if Osint.File_Names_Case_Sensitive then
6199                   Data.Object_Directory.Name :=
6200                     Path_Name_Type (Object_Dir.Value);
6201                else
6202                   Get_Name_String (Object_Dir.Value);
6203                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6204                   Data.Object_Directory.Name := Name_Find;
6205                end if;
6206             end if;
6207          end if;
6208
6209       elsif Subdirs /= null then
6210          Name_Len := 1;
6211          Name_Buffer (1) := '.';
6212          Locate_Directory
6213            (Project,
6214             In_Tree,
6215             Name_Find,
6216             Data.Directory.Display_Name,
6217             Data.Object_Directory.Name,
6218             Data.Object_Directory.Display_Name,
6219             Create      => "object",
6220             Location    => Object_Dir.Location,
6221             Current_Dir => Current_Dir);
6222       end if;
6223
6224       if Current_Verbosity = High then
6225          if Data.Object_Directory = No_Path_Information then
6226             Write_Line ("No object directory");
6227          else
6228             Write_Str ("Object directory: """);
6229             Write_Str (Get_Name_String (Data.Object_Directory.Display_Name));
6230             Write_Line ("""");
6231          end if;
6232       end if;
6233
6234       --  Check the exec directory
6235
6236       pragma Assert (Exec_Dir.Kind = Single,
6237                      "Exec_Dir is not a single string");
6238
6239       --  We set the object directory to its default
6240
6241       Data.Exec_Directory   := Data.Object_Directory;
6242
6243       if Exec_Dir.Value /= Empty_String then
6244          Get_Name_String (Exec_Dir.Value);
6245
6246          if Name_Len = 0 then
6247             Error_Msg
6248               (Project, In_Tree,
6249                "Exec_Dir cannot be empty",
6250                Exec_Dir.Location);
6251
6252          else
6253             --  We check that the specified exec directory does exist
6254
6255             Locate_Directory
6256               (Project,
6257                In_Tree,
6258                File_Name_Type (Exec_Dir.Value),
6259                Data.Directory.Display_Name,
6260                Data.Exec_Directory.Name,
6261                Data.Exec_Directory.Display_Name,
6262                Create   => "exec",
6263                Location => Exec_Dir.Location,
6264                Current_Dir => Current_Dir);
6265
6266             if Data.Exec_Directory = No_Path_Information then
6267                Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
6268                Error_Msg
6269                  (Project, In_Tree,
6270                   "the exec directory { cannot be found",
6271                   Data.Location);
6272             end if;
6273          end if;
6274       end if;
6275
6276       if Current_Verbosity = High then
6277          if Data.Exec_Directory = No_Path_Information then
6278             Write_Line ("No exec directory");
6279          else
6280             Write_Str ("Exec directory: """);
6281             Write_Str (Get_Name_String (Data.Exec_Directory.Display_Name));
6282             Write_Line ("""");
6283          end if;
6284       end if;
6285
6286       --  Look for the source directories
6287
6288       if Current_Verbosity = High then
6289          Write_Line ("Starting to look for source directories");
6290       end if;
6291
6292       pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
6293
6294       if (not Source_Files.Default) and then
6295         Source_Files.Values = Nil_String
6296       then
6297          Data.Source_Dirs := Nil_String;
6298
6299          if Data.Qualifier = Standard then
6300             Error_Msg
6301               (Project,
6302                In_Tree,
6303                "a standard project cannot have no sources",
6304                Source_Files.Location);
6305          end if;
6306
6307          if Data.Extends = No_Project
6308            and then Data.Object_Directory = Data.Directory
6309          then
6310             Data.Object_Directory := No_Path_Information;
6311          end if;
6312
6313       elsif Source_Dirs.Default then
6314
6315          --  No Source_Dirs specified: the single source directory is the one
6316          --  containing the project file
6317
6318          String_Element_Table.Increment_Last
6319            (In_Tree.String_Elements);
6320          Data.Source_Dirs := String_Element_Table.Last
6321            (In_Tree.String_Elements);
6322          In_Tree.String_Elements.Table (Data.Source_Dirs) :=
6323            (Value         => Name_Id (Data.Directory.Name),
6324             Display_Value => Name_Id (Data.Directory.Display_Name),
6325             Location      => No_Location,
6326             Flag          => False,
6327             Next          => Nil_String,
6328             Index         => 0);
6329
6330          if Current_Verbosity = High then
6331             Write_Line ("Single source directory:");
6332             Write_Str ("    """);
6333             Write_Str (Get_Name_String (Data.Directory.Display_Name));
6334             Write_Line ("""");
6335          end if;
6336
6337       elsif Source_Dirs.Values = Nil_String then
6338          if Data.Qualifier = Standard then
6339             Error_Msg
6340               (Project,
6341                In_Tree,
6342                "a standard project cannot have no source directories",
6343                Source_Dirs.Location);
6344          end if;
6345
6346          --  If Source_Dirs is an empty string list, this means that this
6347          --  project contains no source. For projects that don't extend other
6348          --  projects, this also means that there is no need for an object
6349          --  directory, if not specified.
6350
6351          if Data.Extends = No_Project
6352            and then  Data.Object_Directory = Data.Directory
6353          then
6354             Data.Object_Directory := No_Path_Information;
6355          end if;
6356
6357          Data.Source_Dirs := Nil_String;
6358
6359       else
6360          declare
6361             Source_Dir : String_List_Id;
6362             Element    : String_Element;
6363
6364          begin
6365             --  Process the source directories for each element of the list
6366
6367             Source_Dir := Source_Dirs.Values;
6368             while Source_Dir /= Nil_String loop
6369                Element := In_Tree.String_Elements.Table (Source_Dir);
6370                Find_Source_Dirs
6371                  (File_Name_Type (Element.Value), Element.Location);
6372                Source_Dir := Element.Next;
6373             end loop;
6374          end;
6375       end if;
6376
6377       if not Excluded_Source_Dirs.Default
6378         and then Excluded_Source_Dirs.Values /= Nil_String
6379       then
6380          declare
6381             Source_Dir : String_List_Id;
6382             Element    : String_Element;
6383
6384          begin
6385             --  Process the source directories for each element of the list
6386
6387             Source_Dir := Excluded_Source_Dirs.Values;
6388             while Source_Dir /= Nil_String loop
6389                Element := In_Tree.String_Elements.Table (Source_Dir);
6390                Find_Source_Dirs
6391                  (File_Name_Type (Element.Value),
6392                   Element.Location,
6393                   Removed => True);
6394                Source_Dir := Element.Next;
6395             end loop;
6396          end;
6397       end if;
6398
6399       if Current_Verbosity = High then
6400          Write_Line ("Putting source directories in canonical cases");
6401       end if;
6402
6403       declare
6404          Current : String_List_Id := Data.Source_Dirs;
6405          Element : String_Element;
6406
6407       begin
6408          while Current /= Nil_String loop
6409             Element := In_Tree.String_Elements.Table (Current);
6410             if Element.Value /= No_Name then
6411                if not Osint.File_Names_Case_Sensitive then
6412                   Get_Name_String (Element.Value);
6413                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6414                   Element.Value := Name_Find;
6415                end if;
6416
6417                In_Tree.String_Elements.Table (Current) := Element;
6418             end if;
6419
6420             Current := Element.Next;
6421          end loop;
6422       end;
6423
6424    end Get_Directories;
6425
6426    ---------------
6427    -- Get_Mains --
6428    ---------------
6429
6430    procedure Get_Mains
6431      (Project : Project_Id;
6432       In_Tree : Project_Tree_Ref;
6433       Data    : in out Project_Data)
6434    is
6435       Mains : constant Variable_Value :=
6436                 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes, In_Tree);
6437       List  : String_List_Id;
6438       Elem  : String_Element;
6439
6440    begin
6441       Data.Mains := Mains.Values;
6442
6443       --  If no Mains were specified, and if we are an extending project,
6444       --  inherit the Mains from the project we are extending.
6445
6446       if Mains.Default then
6447          if not Data.Library and then Data.Extends /= No_Project then
6448             Data.Mains :=
6449               In_Tree.Projects.Table (Data.Extends).Mains;
6450          end if;
6451
6452       --  In a library project file, Main cannot be specified
6453
6454       elsif Data.Library then
6455          Error_Msg
6456            (Project, In_Tree,
6457             "a library project file cannot have Main specified",
6458             Mains.Location);
6459
6460       else
6461          List := Mains.Values;
6462          while List /= Nil_String loop
6463             Elem := In_Tree.String_Elements.Table (List);
6464
6465             if Length_Of_Name (Elem.Value) = 0 then
6466                Error_Msg
6467                  (Project, In_Tree,
6468                   "?a main cannot have an empty name",
6469                   Elem.Location);
6470                exit;
6471             end if;
6472
6473             List := Elem.Next;
6474          end loop;
6475       end if;
6476    end Get_Mains;
6477
6478    ---------------------------
6479    -- Get_Sources_From_File --
6480    ---------------------------
6481
6482    procedure Get_Sources_From_File
6483      (Path     : String;
6484       Location : Source_Ptr;
6485       Project  : Project_Id;
6486       In_Tree  : Project_Tree_Ref)
6487    is
6488       File        : Prj.Util.Text_File;
6489       Line        : String (1 .. 250);
6490       Last        : Natural;
6491       Source_Name : File_Name_Type;
6492       Name_Loc    : Name_Location;
6493
6494    begin
6495       if Get_Mode = Ada_Only then
6496          Source_Names.Reset;
6497       end if;
6498
6499       if Current_Verbosity = High then
6500          Write_Str  ("Opening """);
6501          Write_Str  (Path);
6502          Write_Line (""".");
6503       end if;
6504
6505       --  Open the file
6506
6507       Prj.Util.Open (File, Path);
6508
6509       if not Prj.Util.Is_Valid (File) then
6510          Error_Msg (Project, In_Tree, "file does not exist", Location);
6511
6512       else
6513          --  Read the lines one by one
6514
6515          while not Prj.Util.End_Of_File (File) loop
6516             Prj.Util.Get_Line (File, Line, Last);
6517
6518             --  A non empty, non comment line should contain a file name
6519
6520             if Last /= 0
6521               and then (Last = 1 or else Line (1 .. 2) /= "--")
6522             then
6523                Name_Len := Last;
6524                Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6525                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6526                Source_Name := Name_Find;
6527
6528                --  Check that there is no directory information
6529
6530                for J in 1 .. Last loop
6531                   if Line (J) = '/' or else Line (J) = Directory_Separator then
6532                      Error_Msg_File_1 := Source_Name;
6533                      Error_Msg
6534                        (Project,
6535                         In_Tree,
6536                         "file name cannot include directory information ({)",
6537                         Location);
6538                      exit;
6539                   end if;
6540                end loop;
6541
6542                Name_Loc := Source_Names.Get (Source_Name);
6543
6544                if Name_Loc = No_Name_Location then
6545                   Name_Loc :=
6546                     (Name     => Source_Name,
6547                      Location => Location,
6548                      Source   => No_Source,
6549                      Except   => False,
6550                      Found    => False);
6551                end if;
6552
6553                Source_Names.Set (Source_Name, Name_Loc);
6554             end if;
6555          end loop;
6556
6557          Prj.Util.Close (File);
6558
6559       end if;
6560    end Get_Sources_From_File;
6561
6562    --------------
6563    -- Get_Unit --
6564    --------------
6565
6566    procedure Get_Unit
6567      (In_Tree             : Project_Tree_Ref;
6568       Canonical_File_Name : File_Name_Type;
6569       Naming              : Naming_Data;
6570       Exception_Id        : out Ada_Naming_Exception_Id;
6571       Unit_Name           : out Name_Id;
6572       Unit_Kind           : out Spec_Or_Body;
6573       Needs_Pragma        : out Boolean)
6574    is
6575       Info_Id  : Ada_Naming_Exception_Id :=
6576                    Ada_Naming_Exceptions.Get (Canonical_File_Name);
6577       VMS_Name : File_Name_Type;
6578
6579    begin
6580       if Info_Id = No_Ada_Naming_Exception then
6581          if Hostparm.OpenVMS then
6582             VMS_Name := Canonical_File_Name;
6583             Get_Name_String (VMS_Name);
6584
6585             if Name_Buffer (Name_Len) = '.' then
6586                Name_Len := Name_Len - 1;
6587                VMS_Name := Name_Find;
6588             end if;
6589
6590             Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
6591          end if;
6592
6593       end if;
6594
6595       if Info_Id /= No_Ada_Naming_Exception then
6596          Exception_Id := Info_Id;
6597          Unit_Name := No_Name;
6598          Unit_Kind := Specification;
6599          Needs_Pragma := True;
6600          return;
6601       end if;
6602
6603       Needs_Pragma := False;
6604       Exception_Id := No_Ada_Naming_Exception;
6605
6606       Get_Name_String (Canonical_File_Name);
6607
6608       --  How about some comments and a name for this declare block ???
6609       --  In fact the whole code below needs more comments ???
6610
6611       declare
6612          File          : String := Name_Buffer (1 .. Name_Len);
6613          First         : constant Positive := File'First;
6614          Last          : Natural           := File'Last;
6615          Standard_GNAT : Boolean;
6616          Spec          : constant File_Name_Type :=
6617                            Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
6618          Body_Suff     : constant File_Name_Type :=
6619                            Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
6620
6621       begin
6622          Standard_GNAT := Spec = Default_Ada_Spec_Suffix
6623             and then Body_Suff = Default_Ada_Body_Suffix;
6624
6625          declare
6626             Spec_Suffix : constant String := Get_Name_String (Spec);
6627             Body_Suffix : constant String := Get_Name_String (Body_Suff);
6628             Sep_Suffix  : constant String :=
6629                             Get_Name_String (Naming.Separate_Suffix);
6630
6631             May_Be_Spec : Boolean;
6632             May_Be_Body : Boolean;
6633             May_Be_Sep  : Boolean;
6634
6635          begin
6636             May_Be_Spec :=
6637               File'Length > Spec_Suffix'Length
6638               and then
6639               File (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix;
6640
6641             May_Be_Body :=
6642               File'Length > Body_Suffix'Length
6643               and then
6644               File (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix;
6645
6646             May_Be_Sep :=
6647               File'Length > Sep_Suffix'Length
6648               and then
6649               File (Last - Sep_Suffix'Length + 1 .. Last) = Sep_Suffix;
6650
6651             --  If two May_Be_ booleans are True, always choose the longer one
6652
6653             if May_Be_Spec then
6654                if May_Be_Body and then
6655                  Spec_Suffix'Length < Body_Suffix'Length
6656                then
6657                   Unit_Kind := Body_Part;
6658
6659                   if May_Be_Sep and then
6660                     Body_Suffix'Length < Sep_Suffix'Length
6661                   then
6662                      Last := Last - Sep_Suffix'Length;
6663                      May_Be_Body := False;
6664
6665                   else
6666                      Last := Last - Body_Suffix'Length;
6667                      May_Be_Sep := False;
6668                   end if;
6669
6670                elsif May_Be_Sep and then
6671                      Spec_Suffix'Length < Sep_Suffix'Length
6672                then
6673                   Unit_Kind := Body_Part;
6674                   Last := Last - Sep_Suffix'Length;
6675
6676                else
6677                   Unit_Kind := Specification;
6678                   Last := Last - Spec_Suffix'Length;
6679                end if;
6680
6681             elsif May_Be_Body then
6682                Unit_Kind := Body_Part;
6683
6684                if May_Be_Sep and then
6685                   Body_Suffix'Length < Sep_Suffix'Length
6686                then
6687                   Last := Last - Sep_Suffix'Length;
6688                   May_Be_Body := False;
6689                else
6690                   Last := Last - Body_Suffix'Length;
6691                   May_Be_Sep := False;
6692                end if;
6693
6694             elsif May_Be_Sep then
6695                Unit_Kind := Body_Part;
6696                Last := Last - Sep_Suffix'Length;
6697
6698             else
6699                Last := 0;
6700             end if;
6701
6702             if Last = 0 then
6703
6704                --  This is not a source file
6705
6706                Unit_Name := No_Name;
6707                Unit_Kind := Specification;
6708
6709                if Current_Verbosity = High then
6710                   Write_Line ("   Not a valid file name.");
6711                end if;
6712
6713                return;
6714
6715             elsif Current_Verbosity = High then
6716                case Unit_Kind is
6717                when Specification =>
6718                   Write_Str  ("   Specification: ");
6719                   Write_Line (File (First .. Last + Spec_Suffix'Length));
6720
6721                when Body_Part =>
6722                   if May_Be_Body then
6723                      Write_Str  ("   Body: ");
6724                      Write_Line (File (First .. Last + Body_Suffix'Length));
6725
6726                   else
6727                      Write_Str  ("   Separate: ");
6728                      Write_Line (File (First .. Last + Sep_Suffix'Length));
6729                   end if;
6730                end case;
6731             end if;
6732          end;
6733
6734          Get_Name_String (Naming.Dot_Replacement);
6735          Standard_GNAT :=
6736            Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
6737
6738          if Name_Buffer (1 .. Name_Len) /= "." then
6739
6740             --  If Dot_Replacement is not a single dot, then there should not
6741             --  be any dot in the name.
6742
6743             for Index in First .. Last loop
6744                if File (Index) = '.' then
6745                   if Current_Verbosity = High then
6746                      Write_Line
6747                        ("   Not a valid file name (some dot not replaced).");
6748                   end if;
6749
6750                   Unit_Name := No_Name;
6751                   return;
6752
6753                end if;
6754             end loop;
6755
6756             --  Replace the substring Dot_Replacement with dots
6757
6758             declare
6759                Index : Positive := First;
6760
6761             begin
6762                while Index <= Last - Name_Len + 1 loop
6763
6764                   if File (Index .. Index + Name_Len - 1) =
6765                     Name_Buffer (1 .. Name_Len)
6766                   then
6767                      File (Index) := '.';
6768
6769                      if Name_Len > 1 and then Index < Last then
6770                         File (Index + 1 .. Last - Name_Len + 1) :=
6771                           File (Index + Name_Len .. Last);
6772                      end if;
6773
6774                      Last := Last - Name_Len + 1;
6775                   end if;
6776
6777                   Index := Index + 1;
6778                end loop;
6779             end;
6780          end if;
6781
6782          --  Check if the file casing is right
6783
6784          declare
6785             Src      : String := File (First .. Last);
6786             Src_Last : Positive := Last;
6787
6788          begin
6789             --  If casing is significant, deal with upper/lower case translate
6790
6791             if File_Names_Case_Sensitive then
6792                case Naming.Casing is
6793                   when All_Lower_Case =>
6794                      Fixed.Translate
6795                        (Source  => Src,
6796                         Mapping => Lower_Case_Map);
6797
6798                   when All_Upper_Case =>
6799                      Fixed.Translate
6800                        (Source  => Src,
6801                         Mapping => Upper_Case_Map);
6802
6803                   when Mixed_Case | Unknown =>
6804                      null;
6805                end case;
6806
6807                if Src /= File (First .. Last) then
6808                   if Current_Verbosity = High then
6809                      Write_Line ("   Not a valid file name (casing).");
6810                   end if;
6811
6812                   Unit_Name := No_Name;
6813                   return;
6814                end if;
6815             end if;
6816
6817             --  Put the name in lower case
6818
6819             Fixed.Translate
6820               (Source  => Src,
6821                Mapping => Lower_Case_Map);
6822
6823             --  In the standard GNAT naming scheme, check for special cases:
6824             --  children or separates of A, G, I or S, and run time sources.
6825
6826             if Standard_GNAT and then Src'Length >= 3 then
6827                declare
6828                   S1 : constant Character := Src (Src'First);
6829                   S2 : constant Character := Src (Src'First + 1);
6830                   S3 : constant Character := Src (Src'First + 2);
6831
6832                begin
6833                   if S1 = 'a' or else
6834                      S1 = 'g' or else
6835                      S1 = 'i' or else
6836                      S1 = 's'
6837                   then
6838                      --  Children or separates of packages A, G, I or S. These
6839                      --  names are x__ ... or x~... (where x is a, g, i, or s).
6840                      --  Both versions (x__... and x~...) are allowed in all
6841                      --  platforms, because it is not possible to know the
6842                      --  platform before processing of the project files.
6843
6844                      if S2 = '_' and then S3 = '_' then
6845                         Src (Src'First + 1) := '.';
6846                         Src_Last := Src_Last - 1;
6847                         Src (Src'First + 2 .. Src_Last) :=
6848                           Src (Src'First + 3 .. Src_Last + 1);
6849
6850                      elsif S2 = '~' then
6851                         Src (Src'First + 1) := '.';
6852
6853                      --  If it is potentially a run time source, disable
6854                      --  filling of the mapping file to avoid warnings.
6855
6856                      elsif S2 = '.' then
6857                         Set_Mapping_File_Initial_State_To_Empty;
6858                      end if;
6859                   end if;
6860                end;
6861             end if;
6862
6863             if Current_Verbosity = High then
6864                Write_Str  ("      ");
6865                Write_Line (Src (Src'First .. Src_Last));
6866             end if;
6867
6868             --  Now, we check if this name is a valid unit name
6869
6870             Check_Ada_Name
6871               (Name => Src (Src'First .. Src_Last), Unit => Unit_Name);
6872          end;
6873
6874       end;
6875    end Get_Unit;
6876
6877    ----------
6878    -- Hash --
6879    ----------
6880
6881    function Hash (Unit : Unit_Info) return Header_Num is
6882    begin
6883       return Header_Num (Unit.Unit mod 2048);
6884    end Hash;
6885
6886    -----------------------
6887    -- Is_Illegal_Suffix --
6888    -----------------------
6889
6890    function Is_Illegal_Suffix
6891      (Suffix                          : String;
6892       Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
6893    is
6894    begin
6895       if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
6896          return True;
6897       end if;
6898
6899       --  If dot replacement is a single dot, and first character of suffix is
6900       --  also a dot
6901
6902       if Dot_Replacement_Is_A_Single_Dot
6903         and then Suffix (Suffix'First) = '.'
6904       then
6905          for Index in Suffix'First + 1 .. Suffix'Last loop
6906
6907             --  If there is another dot
6908
6909             if Suffix (Index) = '.' then
6910
6911                --  It is illegal to have a letter following the initial dot
6912
6913                return Is_Letter (Suffix (Suffix'First + 1));
6914             end if;
6915          end loop;
6916       end if;
6917
6918       --  Everything is OK
6919
6920       return False;
6921    end Is_Illegal_Suffix;
6922
6923    ----------------------
6924    -- Locate_Directory --
6925    ----------------------
6926
6927    procedure Locate_Directory
6928      (Project     : Project_Id;
6929       In_Tree     : Project_Tree_Ref;
6930       Name        : File_Name_Type;
6931       Parent      : Path_Name_Type;
6932       Dir         : out Path_Name_Type;
6933       Display     : out Path_Name_Type;
6934       Create      : String := "";
6935       Current_Dir : String;
6936       Location    : Source_Ptr := No_Location)
6937    is
6938       The_Parent      : constant String :=
6939                           Get_Name_String (Parent) & Directory_Separator;
6940
6941       The_Parent_Last : constant Natural :=
6942                           Compute_Directory_Last (The_Parent);
6943
6944       Full_Name       : File_Name_Type;
6945
6946       The_Name        : File_Name_Type;
6947
6948    begin
6949       Get_Name_String (Name);
6950
6951       --  Add Subdirs.all if it is a directory that may be created and
6952       --  Subdirs is not null;
6953
6954       if Create /= "" and then Subdirs /= null then
6955          if Name_Buffer (Name_Len) /= Directory_Separator then
6956             Add_Char_To_Name_Buffer (Directory_Separator);
6957          end if;
6958
6959          Add_Str_To_Name_Buffer (Subdirs.all);
6960       end if;
6961
6962       --  Convert '/' to directory separator (for Windows)
6963
6964       for J in 1 .. Name_Len loop
6965          if Name_Buffer (J) = '/' then
6966             Name_Buffer (J) := Directory_Separator;
6967          end if;
6968       end loop;
6969
6970       The_Name := Name_Find;
6971
6972       if Current_Verbosity = High then
6973          Write_Str ("Locate_Directory (""");
6974          Write_Str (Get_Name_String (The_Name));
6975          Write_Str (""", """);
6976          Write_Str (The_Parent);
6977          Write_Line (""")");
6978       end if;
6979
6980       Dir     := No_Path;
6981       Display := No_Path;
6982
6983       if Is_Absolute_Path (Get_Name_String (The_Name)) then
6984          Full_Name := The_Name;
6985
6986       else
6987          Name_Len := 0;
6988          Add_Str_To_Name_Buffer
6989            (The_Parent (The_Parent'First .. The_Parent_Last));
6990          Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
6991          Full_Name := Name_Find;
6992       end if;
6993
6994       declare
6995          Full_Path_Name : constant String := Get_Name_String (Full_Name);
6996
6997       begin
6998          if (Setup_Projects or else Subdirs /= null)
6999            and then Create'Length > 0
7000            and then not Is_Directory (Full_Path_Name)
7001          then
7002             begin
7003                Create_Path (Full_Path_Name);
7004
7005                if not Quiet_Output then
7006                   Write_Str (Create);
7007                   Write_Str (" directory """);
7008                   Write_Str (Full_Path_Name);
7009                   Write_Line (""" created");
7010                end if;
7011
7012             exception
7013                when Use_Error =>
7014                   Error_Msg
7015                     (Project, In_Tree,
7016                      "could not create " & Create &
7017                      " directory " & Full_Path_Name,
7018                      Location);
7019             end;
7020          end if;
7021
7022          if Is_Directory (Full_Path_Name) then
7023             declare
7024                Normed : constant String :=
7025                           Normalize_Pathname
7026                             (Full_Path_Name,
7027                              Directory      => Current_Dir,
7028                              Resolve_Links  => False,
7029                              Case_Sensitive => True);
7030
7031                Canonical_Path : constant String :=
7032                                   Normalize_Pathname
7033                                     (Normed,
7034                                      Directory      => Current_Dir,
7035                                      Resolve_Links  =>
7036                                         Opt.Follow_Links_For_Dirs,
7037                                      Case_Sensitive => False);
7038
7039             begin
7040                Name_Len := Normed'Length;
7041                Name_Buffer (1 .. Name_Len) := Normed;
7042                Display := Name_Find;
7043
7044                Name_Len := Canonical_Path'Length;
7045                Name_Buffer (1 .. Name_Len) := Canonical_Path;
7046                Dir := Name_Find;
7047             end;
7048          end if;
7049       end;
7050    end Locate_Directory;
7051
7052    ---------------------------
7053    -- Find_Excluded_Sources --
7054    ---------------------------
7055
7056    procedure Find_Excluded_Sources
7057      (Project : Project_Id;
7058       In_Tree : Project_Tree_Ref;
7059       Data    : Project_Data)
7060    is
7061       Excluded_Sources : Variable_Value;
7062
7063       Excluded_Source_List_File : Variable_Value;
7064
7065       Current          : String_List_Id;
7066
7067       Element : String_Element;
7068
7069       Location : Source_Ptr;
7070
7071       Name : File_Name_Type;
7072
7073       File : Prj.Util.Text_File;
7074       Line : String (1 .. 300);
7075       Last : Natural;
7076
7077       Locally_Removed : Boolean := False;
7078    begin
7079       Excluded_Source_List_File :=
7080         Util.Value_Of
7081           (Name_Excluded_Source_List_File, Data.Decl.Attributes, In_Tree);
7082
7083       Excluded_Sources :=
7084         Util.Value_Of
7085           (Name_Excluded_Source_Files, Data.Decl.Attributes, In_Tree);
7086
7087       --  If Excluded_Source_Files is not declared, check
7088       --  Locally_Removed_Files.
7089
7090       if Excluded_Sources.Default then
7091          Locally_Removed := True;
7092          Excluded_Sources :=
7093            Util.Value_Of
7094              (Name_Locally_Removed_Files, Data.Decl.Attributes, In_Tree);
7095       end if;
7096
7097       Excluded_Sources_Htable.Reset;
7098
7099       --  If there are excluded sources, put them in the table
7100
7101       if not Excluded_Sources.Default then
7102          if not Excluded_Source_List_File.Default then
7103             if Locally_Removed then
7104                Error_Msg
7105                  (Project, In_Tree,
7106                   "?both attributes Locally_Removed_Files and " &
7107                   "Excluded_Source_List_File are present",
7108                   Excluded_Source_List_File.Location);
7109             else
7110                Error_Msg
7111                  (Project, In_Tree,
7112                   "?both attributes Excluded_Source_Files and " &
7113                   "Excluded_Source_List_File are present",
7114                   Excluded_Source_List_File.Location);
7115             end if;
7116          end if;
7117
7118          Current := Excluded_Sources.Values;
7119          while Current /= Nil_String loop
7120             Element := In_Tree.String_Elements.Table (Current);
7121
7122             if Osint.File_Names_Case_Sensitive then
7123                Name := File_Name_Type (Element.Value);
7124             else
7125                Get_Name_String (Element.Value);
7126                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7127                Name := Name_Find;
7128             end if;
7129
7130             --  If the element has no location, then use the location
7131             --  of Excluded_Sources to report possible errors.
7132
7133             if Element.Location = No_Location then
7134                Location := Excluded_Sources.Location;
7135             else
7136                Location := Element.Location;
7137             end if;
7138
7139             Excluded_Sources_Htable.Set (Name, (Name, False, Location));
7140             Current := Element.Next;
7141          end loop;
7142
7143       elsif not Excluded_Source_List_File.Default then
7144          Location := Excluded_Source_List_File.Location;
7145
7146          declare
7147             Source_File_Path_Name : constant String :=
7148                                       Path_Name_Of
7149                                         (File_Name_Type
7150                                            (Excluded_Source_List_File.Value),
7151                                          Data.Directory.Name);
7152
7153          begin
7154             if Source_File_Path_Name'Length = 0 then
7155                Err_Vars.Error_Msg_File_1 :=
7156                  File_Name_Type (Excluded_Source_List_File.Value);
7157                Error_Msg
7158                  (Project, In_Tree,
7159                   "file with excluded sources { does not exist",
7160                   Excluded_Source_List_File.Location);
7161
7162             else
7163                --  Open the file
7164
7165                Prj.Util.Open (File, Source_File_Path_Name);
7166
7167                if not Prj.Util.Is_Valid (File) then
7168                   Error_Msg
7169                     (Project, In_Tree, "file does not exist", Location);
7170                else
7171                   --  Read the lines one by one
7172
7173                   while not Prj.Util.End_Of_File (File) loop
7174                      Prj.Util.Get_Line (File, Line, Last);
7175
7176                      --  A non empty, non comment line should contain a file
7177                      --  name
7178
7179                      if Last /= 0
7180                        and then (Last = 1 or else Line (1 .. 2) /= "--")
7181                      then
7182                         Name_Len := Last;
7183                         Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
7184                         Canonical_Case_File_Name
7185                           (Name_Buffer (1 .. Name_Len));
7186                         Name := Name_Find;
7187
7188                         --  Check that there is no directory information
7189
7190                         for J in 1 .. Last loop
7191                            if Line (J) = '/'
7192                              or else Line (J) = Directory_Separator
7193                            then
7194                               Error_Msg_File_1 := Name;
7195                               Error_Msg
7196                                 (Project,
7197                                  In_Tree,
7198                                  "file name cannot include " &
7199                                  "directory information ({)",
7200                                  Location);
7201                               exit;
7202                            end if;
7203                         end loop;
7204
7205                         Excluded_Sources_Htable.Set
7206                           (Name, (Name, False, Location));
7207                      end if;
7208                   end loop;
7209
7210                   Prj.Util.Close (File);
7211                end if;
7212             end if;
7213          end;
7214       end if;
7215    end Find_Excluded_Sources;
7216
7217    ---------------------------
7218    -- Find_Explicit_Sources --
7219    ---------------------------
7220
7221    procedure Find_Explicit_Sources
7222      (Current_Dir : String;
7223       Project     : Project_Id;
7224       In_Tree     : Project_Tree_Ref;
7225       Data        : in out Project_Data)
7226    is
7227       Sources          : constant Variable_Value :=
7228                            Util.Value_Of
7229                              (Name_Source_Files,
7230                               Data.Decl.Attributes,
7231                               In_Tree);
7232       Source_List_File : constant Variable_Value :=
7233                            Util.Value_Of
7234                              (Name_Source_List_File,
7235                               Data.Decl.Attributes,
7236                               In_Tree);
7237       Name_Loc         : Name_Location;
7238
7239    begin
7240       pragma Assert (Sources.Kind = List, "Source_Files is not a list");
7241       pragma Assert
7242         (Source_List_File.Kind = Single,
7243          "Source_List_File is not a single string");
7244
7245       --  If the user has specified a Sources attribute
7246
7247       if not Sources.Default then
7248          if not Source_List_File.Default then
7249             Error_Msg
7250               (Project, In_Tree,
7251                "?both attributes source_files and " &
7252                "source_list_file are present",
7253                Source_List_File.Location);
7254          end if;
7255
7256          --  Sources is a list of file names
7257
7258          declare
7259             Current  : String_List_Id := Sources.Values;
7260             Element  : String_Element;
7261             Location : Source_Ptr;
7262             Name     : File_Name_Type;
7263
7264          begin
7265             if Get_Mode = Ada_Only then
7266                Data.Ada_Sources_Present := Current /= Nil_String;
7267             end if;
7268
7269             if Get_Mode = Multi_Language then
7270                if Current = Nil_String then
7271                   Data.First_Language_Processing := No_Language_Index;
7272
7273                   --  This project contains no source. For projects that
7274                   --  don't extend other projects, this also means that
7275                   --  there is no need for an object directory, if not
7276                   --  specified.
7277
7278                   if Data.Extends = No_Project
7279                     and then Data.Object_Directory = Data.Directory
7280                   then
7281                      Data.Object_Directory := No_Path_Information;
7282                   end if;
7283                end if;
7284             end if;
7285
7286             while Current /= Nil_String loop
7287                Element := In_Tree.String_Elements.Table (Current);
7288                Get_Name_String (Element.Value);
7289
7290                if Osint.File_Names_Case_Sensitive then
7291                   Name := File_Name_Type (Element.Value);
7292                else
7293                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7294                   Name := Name_Find;
7295                end if;
7296
7297                --  If the element has no location, then use the
7298                --  location of Sources to report possible errors.
7299
7300                if Element.Location = No_Location then
7301                   Location := Sources.Location;
7302                else
7303                   Location := Element.Location;
7304                end if;
7305
7306                --  Check that there is no directory information
7307
7308                for J in 1 .. Name_Len loop
7309                   if Name_Buffer (J) = '/'
7310                     or else Name_Buffer (J) = Directory_Separator
7311                   then
7312                      Error_Msg_File_1 := Name;
7313                      Error_Msg
7314                        (Project,
7315                         In_Tree,
7316                         "file name cannot include directory " &
7317                         "information ({)",
7318                         Location);
7319                      exit;
7320                   end if;
7321                end loop;
7322
7323                --  In Multi_Language mode, check whether the file is
7324                --  already there: the same file name may be in the list; if
7325                --  the source is missing, the error will be on the first
7326                --  mention of the source file name.
7327
7328                case Get_Mode is
7329                   when Ada_Only =>
7330                      Name_Loc := No_Name_Location;
7331                   when Multi_Language =>
7332                      Name_Loc := Source_Names.Get (Name);
7333                end case;
7334
7335                if Name_Loc = No_Name_Location then
7336                   Name_Loc :=
7337                     (Name     => Name,
7338                      Location => Location,
7339                      Source   => No_Source,
7340                      Except   => False,
7341                      Found    => False);
7342                   Source_Names.Set (Name, Name_Loc);
7343                end if;
7344
7345                Current := Element.Next;
7346             end loop;
7347
7348             if Get_Mode = Ada_Only then
7349                Get_Path_Names_And_Record_Ada_Sources
7350                  (Project, In_Tree, Data, Current_Dir);
7351             end if;
7352          end;
7353
7354          --  If we have no Source_Files attribute, check the Source_List_File
7355          --  attribute
7356
7357       elsif not Source_List_File.Default then
7358
7359          --  Source_List_File is the name of the file
7360          --  that contains the source file names
7361
7362          declare
7363             Source_File_Path_Name : constant String :=
7364               Path_Name_Of
7365                 (File_Name_Type (Source_List_File.Value), Data.Directory.Name);
7366
7367          begin
7368             if Source_File_Path_Name'Length = 0 then
7369                Err_Vars.Error_Msg_File_1 :=
7370                  File_Name_Type (Source_List_File.Value);
7371                Error_Msg
7372                  (Project, In_Tree,
7373                   "file with sources { does not exist",
7374                   Source_List_File.Location);
7375
7376             else
7377                Get_Sources_From_File
7378                  (Source_File_Path_Name, Source_List_File.Location,
7379                   Project, In_Tree);
7380
7381                if Get_Mode = Ada_Only then
7382                   --  Look in the source directories to find those sources
7383
7384                   Get_Path_Names_And_Record_Ada_Sources
7385                     (Project, In_Tree, Data, Current_Dir);
7386                end if;
7387             end if;
7388          end;
7389
7390       else
7391          --  Neither Source_Files nor Source_List_File has been
7392          --  specified. Find all the files that satisfy the naming
7393          --  scheme in all the source directories.
7394
7395          if Get_Mode = Ada_Only then
7396             Find_Ada_Sources (Project, In_Tree, Data, Current_Dir);
7397          end if;
7398       end if;
7399
7400       if Get_Mode = Multi_Language then
7401          Search_Directories
7402            (Project, In_Tree, Data,
7403             For_All_Sources =>
7404               Sources.Default and then Source_List_File.Default);
7405
7406          --  Check if all exceptions have been found.
7407          --  For Ada, it is an error if an exception is not found.
7408          --  For other language, the source is simply removed.
7409
7410          declare
7411             Source : Source_Id;
7412
7413          begin
7414             Source := Data.First_Source;
7415             while Source /= No_Source loop
7416                declare
7417                   Src_Data : Source_Data renames
7418                                In_Tree.Sources.Table (Source);
7419
7420                begin
7421                   if Src_Data.Naming_Exception
7422                     and then Src_Data.Path = No_Path_Information
7423                   then
7424                      if Src_Data.Unit /= No_Name then
7425                         Error_Msg_Name_1 := Name_Id (Src_Data.Display_File);
7426                         Error_Msg_Name_2 := Name_Id (Src_Data.Unit);
7427                         Error_Msg
7428                           (Project, In_Tree,
7429                            "source file %% for unit %% not found",
7430                            No_Location);
7431                      end if;
7432
7433                      Remove_Source (Source, No_Source, Project, Data, In_Tree);
7434                   end if;
7435
7436                   Source := Src_Data.Next_In_Project;
7437                end;
7438             end loop;
7439          end;
7440
7441          --  Check that all sources in Source_Files or the file
7442          --  Source_List_File has been found.
7443
7444          declare
7445             Name_Loc : Name_Location;
7446
7447          begin
7448             Name_Loc := Source_Names.Get_First;
7449             while Name_Loc /= No_Name_Location loop
7450                if (not Name_Loc.Except) and then (not Name_Loc.Found) then
7451                   Error_Msg_Name_1 := Name_Id (Name_Loc.Name);
7452                   Error_Msg
7453                     (Project,
7454                      In_Tree,
7455                      "file %% not found",
7456                      Name_Loc.Location);
7457                end if;
7458
7459                Name_Loc := Source_Names.Get_Next;
7460             end loop;
7461          end;
7462       end if;
7463
7464       if Get_Mode = Ada_Only
7465         and then Data.Extends = No_Project
7466       then
7467          --  We should have found at least one source, if not report an error
7468
7469          if Data.Ada_Sources = Nil_String then
7470             Report_No_Sources
7471               (Project, "Ada", In_Tree, Source_List_File.Location);
7472          end if;
7473       end if;
7474
7475    end Find_Explicit_Sources;
7476
7477    -------------------------------------------
7478    -- Get_Path_Names_And_Record_Ada_Sources --
7479    -------------------------------------------
7480
7481    procedure Get_Path_Names_And_Record_Ada_Sources
7482      (Project     : Project_Id;
7483       In_Tree     : Project_Tree_Ref;
7484       Data        : in out Project_Data;
7485       Current_Dir : String)
7486    is
7487       Source_Dir      : String_List_Id;
7488       Element         : String_Element;
7489       Path            : Path_Name_Type;
7490       Dir             : Dir_Type;
7491       Name            : File_Name_Type;
7492       Canonical_Name  : File_Name_Type;
7493       Name_Str        : String (1 .. 1_024);
7494       Last            : Natural := 0;
7495       NL              : Name_Location;
7496       Current_Source  : String_List_Id := Nil_String;
7497       First_Error     : Boolean := True;
7498       Source_Recorded : Boolean := False;
7499
7500    begin
7501       --  We look in all source directories for the file names in the hash
7502       --  table Source_Names.
7503
7504       Source_Dir := Data.Source_Dirs;
7505       while Source_Dir /= Nil_String loop
7506          Source_Recorded := False;
7507          Element := In_Tree.String_Elements.Table (Source_Dir);
7508
7509          declare
7510             Dir_Path : constant String :=
7511               Get_Name_String (Element.Display_Value);
7512          begin
7513             if Current_Verbosity = High then
7514                Write_Str ("checking directory """);
7515                Write_Str (Dir_Path);
7516                Write_Line ("""");
7517             end if;
7518
7519             Open (Dir, Dir_Path);
7520
7521             loop
7522                Read (Dir, Name_Str, Last);
7523                exit when Last = 0;
7524
7525                Name_Len := Last;
7526                Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
7527                Name := Name_Find;
7528
7529                if Osint.File_Names_Case_Sensitive then
7530                   Canonical_Name := Name;
7531                else
7532                   Canonical_Case_File_Name (Name_Str (1 .. Last));
7533                   Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
7534                   Canonical_Name := Name_Find;
7535                end if;
7536
7537                NL := Source_Names.Get (Canonical_Name);
7538
7539                if NL /= No_Name_Location and then not NL.Found then
7540                   NL.Found := True;
7541                   Source_Names.Set (Canonical_Name, NL);
7542                   Name_Len := Dir_Path'Length;
7543                   Name_Buffer (1 .. Name_Len) := Dir_Path;
7544
7545                   if Name_Buffer (Name_Len) /= Directory_Separator then
7546                      Add_Char_To_Name_Buffer (Directory_Separator);
7547                   end if;
7548
7549                   Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
7550                   Path := Name_Find;
7551
7552                   if Current_Verbosity = High then
7553                      Write_Str  ("  found ");
7554                      Write_Line (Get_Name_String (Name));
7555                   end if;
7556
7557                   --  Register the source if it is an Ada compilation unit
7558
7559                   Record_Ada_Source
7560                     (File_Name       => Name,
7561                      Path_Name       => Path,
7562                      Project         => Project,
7563                      In_Tree         => In_Tree,
7564                      Data            => Data,
7565                      Location        => NL.Location,
7566                      Current_Source  => Current_Source,
7567                      Source_Recorded => Source_Recorded,
7568                      Current_Dir     => Current_Dir);
7569                end if;
7570             end loop;
7571
7572             Close (Dir);
7573          end;
7574
7575          if Source_Recorded then
7576             In_Tree.String_Elements.Table (Source_Dir).Flag :=
7577               True;
7578          end if;
7579
7580          Source_Dir := Element.Next;
7581       end loop;
7582
7583       --  It is an error if a source file name in a source list or
7584       --  in a source list file is not found.
7585
7586       NL := Source_Names.Get_First;
7587       while NL /= No_Name_Location loop
7588          if not NL.Found then
7589             Err_Vars.Error_Msg_File_1 := NL.Name;
7590
7591             if First_Error then
7592                Error_Msg
7593                  (Project, In_Tree,
7594                   "source file { cannot be found",
7595                   NL.Location);
7596                First_Error := False;
7597
7598             else
7599                Error_Msg
7600                  (Project, In_Tree,
7601                   "\source file { cannot be found",
7602                   NL.Location);
7603             end if;
7604          end if;
7605
7606          NL := Source_Names.Get_Next;
7607       end loop;
7608    end Get_Path_Names_And_Record_Ada_Sources;
7609
7610    --------------------------
7611    -- Check_Naming_Schemes --
7612    --------------------------
7613
7614    procedure Check_Naming_Schemes
7615      (In_Tree               : Project_Tree_Ref;
7616       Data                  : in out Project_Data;
7617       Filename              : String;
7618       File_Name             : File_Name_Type;
7619       Alternate_Languages   : out Alternate_Language_Id;
7620       Language              : out Language_Index;
7621       Language_Name         : out Name_Id;
7622       Display_Language_Name : out Name_Id;
7623       Unit                  : out Name_Id;
7624       Lang_Kind             : out Language_Kind;
7625       Kind                  : out Source_Kind)
7626    is
7627       Last           : Positive := Filename'Last;
7628       Config         : Language_Config;
7629       Lang           : Name_List_Index := Data.Languages;
7630       Header_File    : Boolean := False;
7631       First_Language : Language_Index;
7632       OK             : Boolean;
7633
7634       Last_Spec : Natural;
7635       Last_Body : Natural;
7636       Last_Sep  : Natural;
7637
7638    begin
7639       Unit := No_Name;
7640       Alternate_Languages := No_Alternate_Language;
7641
7642       while Lang /= No_Name_List loop
7643          Language_Name := In_Tree.Name_Lists.Table (Lang).Name;
7644          Language      := Data.First_Language_Processing;
7645
7646          if Current_Verbosity = High then
7647             Write_Line
7648               ("     Testing language "
7649                & Get_Name_String (Language_Name)
7650                & " Header_File=" & Header_File'Img);
7651          end if;
7652
7653          while Language /= No_Language_Index loop
7654             if In_Tree.Languages_Data.Table (Language).Name =
7655               Language_Name
7656             then
7657                Display_Language_Name :=
7658                  In_Tree.Languages_Data.Table (Language).Display_Name;
7659                Config := In_Tree.Languages_Data.Table (Language).Config;
7660                Lang_Kind := Config.Kind;
7661
7662                if Config.Kind = File_Based then
7663
7664                   --  For file based languages, there is no Unit. Just
7665                   --  check if the file name has the implementation or,
7666                   --  if it is specified, the template suffix of the
7667                   --  language.
7668
7669                   Unit := No_Name;
7670
7671                   if not Header_File
7672                     and then Config.Naming_Data.Body_Suffix /= No_File
7673                   then
7674                      declare
7675                         Impl_Suffix : constant String :=
7676                           Get_Name_String (Config.Naming_Data.Body_Suffix);
7677
7678                      begin
7679                         if Filename'Length > Impl_Suffix'Length
7680                           and then
7681                             Filename
7682                               (Last - Impl_Suffix'Length + 1 .. Last) =
7683                               Impl_Suffix
7684                         then
7685                            Kind := Impl;
7686
7687                            if Current_Verbosity = High then
7688                               Write_Str ("     source of language ");
7689                               Write_Line
7690                                 (Get_Name_String (Display_Language_Name));
7691                            end if;
7692
7693                            return;
7694                         end if;
7695                      end;
7696                   end if;
7697
7698                   if Config.Naming_Data.Spec_Suffix /= No_File then
7699                      declare
7700                         Spec_Suffix : constant String :=
7701                           Get_Name_String
7702                             (Config.Naming_Data.Spec_Suffix);
7703
7704                      begin
7705                         if Filename'Length > Spec_Suffix'Length
7706                           and then
7707                             Filename
7708                               (Last - Spec_Suffix'Length + 1 .. Last) =
7709                               Spec_Suffix
7710                         then
7711                            Kind := Spec;
7712
7713                            if Current_Verbosity = High then
7714                               Write_Str ("     header file of language ");
7715                               Write_Line
7716                                 (Get_Name_String (Display_Language_Name));
7717                            end if;
7718
7719                            if Header_File then
7720                               Alternate_Language_Table.Increment_Last
7721                                 (In_Tree.Alt_Langs);
7722                               In_Tree.Alt_Langs.Table
7723                                 (Alternate_Language_Table.Last
7724                                    (In_Tree.Alt_Langs)) :=
7725                                 (Language => Language,
7726                                  Next     => Alternate_Languages);
7727                               Alternate_Languages :=
7728                                 Alternate_Language_Table.Last
7729                                   (In_Tree.Alt_Langs);
7730                            else
7731                               Header_File    := True;
7732                               First_Language := Language;
7733                            end if;
7734                         end if;
7735                      end;
7736                   end if;
7737
7738                elsif not Header_File then
7739                   --  Unit based language
7740
7741                   OK := Config.Naming_Data.Dot_Replacement /= No_File;
7742
7743                   if OK then
7744
7745                      --  Check casing
7746                      --  ??? Are we doing this once per file in the project ?
7747                      --  It should be done only once per project.
7748
7749                      case Config.Naming_Data.Casing is
7750                         when All_Lower_Case =>
7751                            for J in Filename'Range loop
7752                               if Is_Letter (Filename (J)) then
7753                                  if not Is_Lower (Filename (J)) then
7754                                     OK := False;
7755                                     exit;
7756                                  end if;
7757                               end if;
7758                            end loop;
7759
7760                         when All_Upper_Case =>
7761                            for J in Filename'Range loop
7762                               if Is_Letter (Filename (J)) then
7763                                  if not Is_Upper (Filename (J)) then
7764                                     OK := False;
7765                                     exit;
7766                                  end if;
7767                               end if;
7768                            end loop;
7769
7770                         when Mixed_Case =>
7771                            null;
7772
7773                         when others =>
7774                            OK := False;
7775                      end case;
7776                   end if;
7777
7778                   if OK then
7779                      Last_Spec := Natural'Last;
7780                      Last_Body := Natural'Last;
7781                      Last_Sep  := Natural'Last;
7782
7783                      if Config.Naming_Data.Separate_Suffix /= No_File
7784                        and then
7785                          Config.Naming_Data.Separate_Suffix /=
7786                            Config.Naming_Data.Body_Suffix
7787                      then
7788                         declare
7789                            Suffix : constant String :=
7790                              Get_Name_String
7791                                (Config.Naming_Data.Separate_Suffix);
7792                         begin
7793                            if Filename'Length > Suffix'Length
7794                              and then
7795                                Filename
7796                                  (Last - Suffix'Length + 1 .. Last) =
7797                                  Suffix
7798                            then
7799                               Last_Sep := Last - Suffix'Length;
7800                            end if;
7801                         end;
7802                      end if;
7803
7804                      if Config.Naming_Data.Body_Suffix /= No_File then
7805                         declare
7806                            Suffix : constant String :=
7807                              Get_Name_String
7808                                (Config.Naming_Data.Body_Suffix);
7809                         begin
7810                            if Filename'Length > Suffix'Length
7811                              and then
7812                                Filename
7813                                  (Last - Suffix'Length + 1 .. Last) =
7814                                  Suffix
7815                            then
7816                               Last_Body := Last - Suffix'Length;
7817                            end if;
7818                         end;
7819                      end if;
7820
7821                      if Config.Naming_Data.Spec_Suffix /= No_File then
7822                         declare
7823                            Suffix : constant String :=
7824                              Get_Name_String
7825                                (Config.Naming_Data.Spec_Suffix);
7826                         begin
7827                            if Filename'Length > Suffix'Length
7828                              and then
7829                                Filename
7830                                  (Last - Suffix'Length + 1 .. Last) =
7831                                  Suffix
7832                            then
7833                               Last_Spec := Last - Suffix'Length;
7834                            end if;
7835                         end;
7836                      end if;
7837
7838                      declare
7839                         Last_Min : constant Natural :=
7840                                      Natural'Min (Natural'Min (Last_Spec,
7841                                                                Last_Body),
7842                                                                Last_Sep);
7843
7844                      begin
7845                         OK := Last_Min < Last;
7846
7847                         if OK then
7848                            Last := Last_Min;
7849
7850                            if Last_Min = Last_Spec then
7851                               Kind := Spec;
7852
7853                            elsif Last_Min = Last_Body then
7854                               Kind := Impl;
7855
7856                            else
7857                               Kind := Sep;
7858                            end if;
7859                         end if;
7860                      end;
7861                   end if;
7862
7863                   if OK then
7864
7865                      --  Replace dot replacements with dots
7866
7867                      Name_Len := 0;
7868
7869                      declare
7870                         J : Positive := Filename'First;
7871
7872                         Dot_Replacement : constant String :=
7873                           Get_Name_String
7874                             (Config.Naming_Data.
7875                                  Dot_Replacement);
7876
7877                         Max : constant Positive :=
7878                           Last - Dot_Replacement'Length + 1;
7879
7880                      begin
7881                         loop
7882                            Name_Len := Name_Len + 1;
7883
7884                            if J <= Max and then
7885                              Filename
7886                                (J .. J + Dot_Replacement'Length - 1) =
7887                                Dot_Replacement
7888                            then
7889                               Name_Buffer (Name_Len) := '.';
7890                               J := J + Dot_Replacement'Length;
7891
7892                            else
7893                               if Filename (J) = '.' then
7894                                  OK := False;
7895                                  exit;
7896                               end if;
7897
7898                               Name_Buffer (Name_Len) :=
7899                                 GNAT.Case_Util.To_Lower (Filename (J));
7900                               J := J + 1;
7901                            end if;
7902
7903                            exit when J > Last;
7904                         end loop;
7905                      end;
7906                   end if;
7907
7908                   if OK then
7909
7910                      --  The name buffer should contain the name of the
7911                      --  the unit, if it is one.
7912
7913                      --  Check that this is a valid unit name
7914
7915                      Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
7916
7917                      if Unit /= No_Name then
7918
7919                         if Current_Verbosity = High then
7920                            if Kind = Spec then
7921                               Write_Str ("     spec of ");
7922                            else
7923                               Write_Str ("     body of ");
7924                            end if;
7925
7926                            Write_Str (Get_Name_String (Unit));
7927                            Write_Str (" (language ");
7928                            Write_Str
7929                              (Get_Name_String (Display_Language_Name));
7930                            Write_Line (")");
7931                         end if;
7932
7933                         --  Comments required, declare block should
7934                         --  be named ???
7935
7936                         declare
7937                            Unit_Except : constant Unit_Exception :=
7938                              Unit_Exceptions.Get (Unit);
7939
7940                            procedure Masked_Unit (Spec : Boolean);
7941                            --  Indicate that there is an exception for
7942                            --  the same unit, so the file is not a
7943                            --  source for the unit.
7944
7945                            -----------------
7946                            -- Masked_Unit --
7947                            -----------------
7948
7949                            procedure Masked_Unit (Spec : Boolean) is
7950                            begin
7951                               if Current_Verbosity = High then
7952                                  Write_Str ("   """);
7953                                  Write_Str (Filename);
7954                                  Write_Str (""" contains the ");
7955
7956                                  if Spec then
7957                                     Write_Str ("spec");
7958                                  else
7959                                     Write_Str ("body");
7960                                  end if;
7961
7962                                  Write_Str
7963                                    (" of a unit that is found in """);
7964
7965                                  if Spec then
7966                                     Write_Str
7967                                       (Get_Name_String
7968                                          (Unit_Except.Spec));
7969                                  else
7970                                     Write_Str
7971                                       (Get_Name_String
7972                                          (Unit_Except.Impl));
7973                                  end if;
7974
7975                                  Write_Line (""" (ignored)");
7976                               end if;
7977
7978                               Language := No_Language_Index;
7979                            end Masked_Unit;
7980
7981                         begin
7982                            if Kind = Spec then
7983                               if Unit_Except.Spec /= No_File
7984                                 and then Unit_Except.Spec /= File_Name
7985                               then
7986                                  Masked_Unit (Spec => True);
7987                               end if;
7988
7989                            else
7990                               if Unit_Except.Impl /= No_File
7991                                 and then Unit_Except.Impl /= File_Name
7992                               then
7993                                  Masked_Unit (Spec => False);
7994                               end if;
7995                            end if;
7996                         end;
7997
7998                         return;
7999                      end if;
8000                   end if;
8001                end if;
8002             end if;
8003
8004             Language := In_Tree.Languages_Data.Table (Language).Next;
8005          end loop;
8006
8007          Lang := In_Tree.Name_Lists.Table (Lang).Next;
8008       end loop;
8009
8010       --  Comment needed here ???
8011
8012       if Header_File then
8013          Language := First_Language;
8014
8015       else
8016          Language := No_Language_Index;
8017
8018          if Current_Verbosity = High then
8019             Write_Line ("     not a source of any language");
8020          end if;
8021       end if;
8022    end Check_Naming_Schemes;
8023
8024    ----------------
8025    -- Check_File --
8026    ----------------
8027
8028    procedure Check_File
8029      (Project           : Project_Id;
8030       In_Tree           : Project_Tree_Ref;
8031       Data              : in out Project_Data;
8032       Name              : String;
8033       File_Name         : File_Name_Type;
8034       Display_File_Name : File_Name_Type;
8035       Source_Directory  : String;
8036       For_All_Sources   : Boolean)
8037    is
8038       Display_Path    : constant String :=
8039         Normalize_Pathname
8040           (Name           => Name,
8041            Directory      => Source_Directory,
8042            Resolve_Links  => Opt.Follow_Links_For_Files,
8043            Case_Sensitive => True);
8044
8045       Name_Loc          : Name_Location := Source_Names.Get (File_Name);
8046       Path_Id           : Path_Name_Type;
8047       Display_Path_Id   : Path_Name_Type;
8048       Check_Name        : Boolean := False;
8049       Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
8050       Language          : Language_Index;
8051       Source            : Source_Id;
8052       Other_Part        : Source_Id;
8053       Add_Src           : Boolean;
8054       Src_Ind           : Source_File_Index;
8055       Unit              : Name_Id;
8056       Source_To_Replace : Source_Id := No_Source;
8057       Language_Name         : Name_Id;
8058       Display_Language_Name : Name_Id;
8059       Lang_Kind             : Language_Kind;
8060       Kind                  : Source_Kind := Spec;
8061
8062    begin
8063       Name_Len := Display_Path'Length;
8064       Name_Buffer (1 .. Name_Len) := Display_Path;
8065       Display_Path_Id := Name_Find;
8066
8067       if Osint.File_Names_Case_Sensitive then
8068          Path_Id := Display_Path_Id;
8069       else
8070          Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
8071          Path_Id := Name_Find;
8072       end if;
8073
8074       if Name_Loc = No_Name_Location then
8075          Check_Name := For_All_Sources;
8076
8077       else
8078          if Name_Loc.Found then
8079
8080             --  Check if it is OK to have the same file name in several
8081             --  source directories.
8082
8083             if not Data.Known_Order_Of_Source_Dirs then
8084                Error_Msg_File_1 := File_Name;
8085                Error_Msg
8086                  (Project, In_Tree,
8087                   "{ is found in several source directories",
8088                   Name_Loc.Location);
8089             end if;
8090
8091          else
8092             Name_Loc.Found := True;
8093
8094             Source_Names.Set (File_Name, Name_Loc);
8095
8096             if Name_Loc.Source = No_Source then
8097                Check_Name := True;
8098
8099             else
8100                In_Tree.Sources.Table (Name_Loc.Source).Path :=
8101                  (Path_Id, Display_Path_Id);
8102
8103                Source_Paths_Htable.Set
8104                  (In_Tree.Source_Paths_HT,
8105                   Path_Id,
8106                   Name_Loc.Source);
8107
8108                --  Check if this is a subunit
8109
8110                if In_Tree.Sources.Table (Name_Loc.Source).Unit /= No_Name
8111                  and then
8112                    In_Tree.Sources.Table (Name_Loc.Source).Kind = Impl
8113                then
8114                   Src_Ind := Sinput.P.Load_Project_File
8115                     (Get_Name_String (Path_Id));
8116
8117                   if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
8118                      In_Tree.Sources.Table (Name_Loc.Source).Kind := Sep;
8119                   end if;
8120                end if;
8121             end if;
8122          end if;
8123       end if;
8124
8125       if Check_Name then
8126          Other_Part := No_Source;
8127
8128          Check_Naming_Schemes
8129            (In_Tree               => In_Tree,
8130             Data                  => Data,
8131             Filename              => Get_Name_String (File_Name),
8132             File_Name             => File_Name,
8133             Alternate_Languages   => Alternate_Languages,
8134             Language              => Language,
8135             Language_Name         => Language_Name,
8136             Display_Language_Name => Display_Language_Name,
8137             Unit                  => Unit,
8138             Lang_Kind             => Lang_Kind,
8139             Kind                  => Kind);
8140
8141          if Language = No_Language_Index then
8142
8143             --  A file name in a list must be a source of a language
8144
8145             if Name_Loc.Found then
8146                Error_Msg_File_1 := File_Name;
8147                Error_Msg
8148                  (Project,
8149                   In_Tree,
8150                   "language unknown for {",
8151                   Name_Loc.Location);
8152             end if;
8153
8154          else
8155             --  Check if the same file name or unit is used in the prj tree
8156
8157             Source := In_Tree.First_Source;
8158             Add_Src := True;
8159             while Source /= No_Source loop
8160                declare
8161                   Src_Data : Source_Data renames
8162                                In_Tree.Sources.Table (Source);
8163
8164                begin
8165                   if Unit /= No_Name
8166                     and then Src_Data.Unit = Unit
8167                     and then
8168                       ((Src_Data.Kind = Spec and then Kind = Impl)
8169                          or else
8170                        (Src_Data.Kind = Impl and then Kind = Spec))
8171                   then
8172                      Other_Part := Source;
8173
8174                   elsif (Unit /= No_Name
8175                          and then Src_Data.Unit = Unit
8176                          and then
8177                            (Src_Data.Kind = Kind
8178                              or else
8179                                (Src_Data.Kind = Sep  and then Kind = Impl)
8180                              or else
8181                                (Src_Data.Kind = Impl and then Kind = Sep)))
8182                     or else
8183                       (Unit = No_Name and then Src_Data.File = File_Name)
8184                   then
8185                      --  Duplication of file/unit in same project is only
8186                      --  allowed if order of source directories is known.
8187
8188                      if Project = Src_Data.Project then
8189                         if Data.Known_Order_Of_Source_Dirs then
8190                            Add_Src := False;
8191
8192                         elsif Unit /= No_Name then
8193                            Error_Msg_Name_1 := Unit;
8194                            Error_Msg
8195                              (Project, In_Tree, "duplicate unit %%",
8196                               No_Location);
8197                            Add_Src := False;
8198
8199                         else
8200                            Error_Msg_File_1 := File_Name;
8201                            Error_Msg
8202                              (Project, In_Tree, "duplicate source file name {",
8203                               No_Location);
8204                            Add_Src := False;
8205                         end if;
8206
8207                         --  Do not allow the same unit name in different
8208                         --  projects, except if one is extending the other.
8209
8210                         --  For a file based language, the same file name
8211                         --  replaces a file in a project being extended, but
8212                         --  it is allowed to have the same file name in
8213                         --  unrelated projects.
8214
8215                      elsif Is_Extending
8216                        (Project, Src_Data.Project, In_Tree)
8217                      then
8218                         Source_To_Replace := Source;
8219
8220                      elsif Unit /= No_Name
8221                        and then not Src_Data.Locally_Removed
8222                      then
8223                         Error_Msg_Name_1 := Unit;
8224                         Error_Msg
8225                           (Project, In_Tree,
8226                            "unit %% cannot belong to several projects",
8227                            No_Location);
8228
8229                         Error_Msg_Name_1 :=
8230                           In_Tree.Projects.Table (Project).Name;
8231                         Error_Msg_Name_2 := Name_Id (Display_Path_Id);
8232                         Error_Msg
8233                           (Project, In_Tree, "\  project %%, %%", No_Location);
8234
8235                         Error_Msg_Name_1 :=
8236                           In_Tree.Projects.Table (Src_Data.Project).Name;
8237                         Error_Msg_Name_2 :=
8238                           Name_Id (Src_Data.Path.Display_Name);
8239                         Error_Msg
8240                           (Project, In_Tree, "\  project %%, %%", No_Location);
8241
8242                         Add_Src := False;
8243                      end if;
8244                   end if;
8245
8246                   Source := Src_Data.Next_In_Sources;
8247                end;
8248             end loop;
8249
8250             if Add_Src then
8251                Add_Source
8252                  (Id                  => Source,
8253                   Data                => Data,
8254                   In_Tree             => In_Tree,
8255                   Project             => Project,
8256                   Lang                => Language_Name,
8257                   Lang_Id             => Language,
8258                   Lang_Kind           => Lang_Kind,
8259                   Kind                => Kind,
8260                   Alternate_Languages => Alternate_Languages,
8261                   File_Name           => File_Name,
8262                   Display_File        => Display_File_Name,
8263                   Other_Part          => Other_Part,
8264                   Unit                => Unit,
8265                   Path                => Path_Id,
8266                   Display_Path        => Display_Path_Id,
8267                   Source_To_Replace   => Source_To_Replace);
8268             end if;
8269          end if;
8270       end if;
8271    end Check_File;
8272
8273    ------------------------
8274    -- Search_Directories --
8275    ------------------------
8276
8277    procedure Search_Directories
8278      (Project         : Project_Id;
8279       In_Tree         : Project_Tree_Ref;
8280       Data            : in out Project_Data;
8281       For_All_Sources : Boolean)
8282    is
8283       Source_Dir        : String_List_Id;
8284       Element           : String_Element;
8285       Dir               : Dir_Type;
8286       Name              : String (1 .. 1_000);
8287       Last              : Natural;
8288       File_Name         : File_Name_Type;
8289       Display_File_Name : File_Name_Type;
8290
8291    begin
8292       if Current_Verbosity = High then
8293          Write_Line ("Looking for sources:");
8294       end if;
8295
8296       --  Loop through subdirectories
8297
8298       Source_Dir := Data.Source_Dirs;
8299       while Source_Dir /= Nil_String loop
8300          begin
8301             Element := In_Tree.String_Elements.Table (Source_Dir);
8302             if Element.Value /= No_Name then
8303                Get_Name_String (Element.Display_Value);
8304
8305                declare
8306                   Source_Directory : constant String :=
8307                                        Name_Buffer (1 .. Name_Len) &
8308                                          Directory_Separator;
8309
8310                   Dir_Last : constant Natural :=
8311                                        Compute_Directory_Last
8312                                          (Source_Directory);
8313
8314                begin
8315                   if Current_Verbosity = High then
8316                      Write_Str ("Source_Dir = ");
8317                      Write_Line (Source_Directory);
8318                   end if;
8319
8320                   --  We look to every entry in the source directory
8321
8322                   Open (Dir, Source_Directory);
8323
8324                   loop
8325                      Read (Dir, Name, Last);
8326
8327                      exit when Last = 0;
8328
8329                      --  ??? Duplicate system call here, we just did a
8330                      --  a similar one. Maybe Ada.Directories would be more
8331                      --  appropriate here
8332
8333                      if Is_Regular_File
8334                        (Source_Directory & Name (1 .. Last))
8335                      then
8336                         if Current_Verbosity = High then
8337                            Write_Str  ("   Checking ");
8338                            Write_Line (Name (1 .. Last));
8339                         end if;
8340
8341                         Name_Len := Last;
8342                         Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8343                         Display_File_Name := Name_Find;
8344
8345                         if Osint.File_Names_Case_Sensitive then
8346                            File_Name := Display_File_Name;
8347                         else
8348                            Canonical_Case_File_Name
8349                              (Name_Buffer (1 .. Name_Len));
8350                            File_Name := Name_Find;
8351                         end if;
8352
8353                         declare
8354                            FF : File_Found :=
8355                                   Excluded_Sources_Htable.Get (File_Name);
8356
8357                         begin
8358                            if FF /= No_File_Found then
8359                               if not FF.Found then
8360                                  FF.Found := True;
8361                                  Excluded_Sources_Htable.Set
8362                                    (File_Name, FF);
8363
8364                                  if Current_Verbosity = High then
8365                                     Write_Str ("     excluded source """);
8366                                     Write_Str (Get_Name_String (File_Name));
8367                                     Write_Line ("""");
8368                                  end if;
8369                               end if;
8370
8371                            else
8372                               Check_File
8373                                 (Project           => Project,
8374                                  In_Tree           => In_Tree,
8375                                  Data              => Data,
8376                                  Name              => Name (1 .. Last),
8377                                  File_Name         => File_Name,
8378                                  Display_File_Name => Display_File_Name,
8379                                  Source_Directory  => Source_Directory
8380                                    (Source_Directory'First .. Dir_Last),
8381                                  For_All_Sources   => For_All_Sources);
8382                            end if;
8383                         end;
8384                      end if;
8385                   end loop;
8386
8387                   Close (Dir);
8388                end;
8389             end if;
8390
8391          exception
8392             when Directory_Error =>
8393                null;
8394          end;
8395
8396          Source_Dir := Element.Next;
8397       end loop;
8398
8399       if Current_Verbosity = High then
8400          Write_Line ("end Looking for sources.");
8401       end if;
8402    end Search_Directories;
8403
8404    ----------------------
8405    -- Look_For_Sources --
8406    ----------------------
8407
8408    procedure Look_For_Sources
8409      (Project     : Project_Id;
8410       In_Tree     : Project_Tree_Ref;
8411       Data        : in out Project_Data;
8412       Current_Dir : String)
8413    is
8414       procedure Remove_Locally_Removed_Files_From_Units;
8415       --  Mark all locally removed sources as such in the Units table
8416
8417       procedure Process_Sources_In_Multi_Language_Mode;
8418       --  Find all source files when in multi language mode
8419
8420       ---------------------------------------------
8421       -- Remove_Locally_Removed_Files_From_Units --
8422       ---------------------------------------------
8423
8424       procedure Remove_Locally_Removed_Files_From_Units is
8425          Excluded : File_Found;
8426          OK       : Boolean;
8427          Unit     : Unit_Data;
8428          Extended : Project_Id;
8429
8430       begin
8431          Excluded := Excluded_Sources_Htable.Get_First;
8432          while Excluded /= No_File_Found loop
8433             OK := False;
8434
8435             For_Each_Unit :
8436             for Index in Unit_Table.First ..
8437               Unit_Table.Last (In_Tree.Units)
8438             loop
8439                Unit := In_Tree.Units.Table (Index);
8440
8441                for Kind in Spec_Or_Body'Range loop
8442                   if Unit.File_Names (Kind).Name = Excluded.File then
8443                      OK := True;
8444
8445                      --  Check that this is from the current project or
8446                      --  that the current project extends.
8447
8448                      Extended := Unit.File_Names (Kind).Project;
8449
8450                      if Extended = Project
8451                        or else Project_Extends (Project, Extended, In_Tree)
8452                      then
8453                         Unit.File_Names (Kind).Path.Name := Slash;
8454                         Unit.File_Names (Kind).Needs_Pragma := False;
8455                         In_Tree.Units.Table (Index) := Unit;
8456                         Add_Forbidden_File_Name
8457                           (Unit.File_Names (Kind).Name);
8458                      else
8459                         Error_Msg
8460                           (Project, In_Tree,
8461                            "cannot remove a source from " &
8462                            "another project",
8463                            Excluded.Location);
8464                      end if;
8465                      exit For_Each_Unit;
8466                   end if;
8467                end loop;
8468             end loop For_Each_Unit;
8469
8470             if not OK then
8471                Err_Vars.Error_Msg_File_1 := Excluded.File;
8472                Error_Msg
8473                  (Project, In_Tree, "unknown file {", Excluded.Location);
8474             end if;
8475
8476             Excluded := Excluded_Sources_Htable.Get_Next;
8477          end loop;
8478       end Remove_Locally_Removed_Files_From_Units;
8479
8480       --------------------------------------------
8481       -- Process_Sources_In_Multi_Language_Mode --
8482       --------------------------------------------
8483
8484       procedure Process_Sources_In_Multi_Language_Mode is
8485          Source   : Source_Id;
8486          Name_Loc : Name_Location;
8487          OK       : Boolean;
8488          FF       : File_Found;
8489
8490       begin
8491          --  First, put all naming exceptions if any, in the Source_Names table
8492
8493          Unit_Exceptions.Reset;
8494
8495          Source := Data.First_Source;
8496          while Source /= No_Source loop
8497             declare
8498                Src_Data : Source_Data renames In_Tree.Sources.Table (Source);
8499
8500             begin
8501                --  An excluded file cannot also be an exception file name
8502
8503                if Excluded_Sources_Htable.Get (Src_Data.File) /=
8504                  No_File_Found
8505                then
8506                   Error_Msg_File_1 := Src_Data.File;
8507                   Error_Msg
8508                     (Project, In_Tree,
8509                      "{ cannot be both excluded and an exception file name",
8510                      No_Location);
8511                end if;
8512
8513                Name_Loc := (Name     => Src_Data.File,
8514                             Location => No_Location,
8515                             Source   => Source,
8516                             Except   => Src_Data.Unit /= No_Name,
8517                             Found    => False);
8518
8519                if Current_Verbosity = High then
8520                   Write_Str ("Putting source #");
8521                   Write_Str (Source'Img);
8522                   Write_Str (", file ");
8523                   Write_Str (Get_Name_String (Src_Data.File));
8524                   Write_Line (" in Source_Names");
8525                end if;
8526
8527                Source_Names.Set (K => Src_Data.File, E => Name_Loc);
8528
8529                --  If this is an Ada exception, record in table Unit_Exceptions
8530
8531                if Src_Data.Unit /= No_Name then
8532                   declare
8533                      Unit_Except : Unit_Exception :=
8534                                      Unit_Exceptions.Get (Src_Data.Unit);
8535
8536                   begin
8537                      Unit_Except.Name := Src_Data.Unit;
8538
8539                      if Src_Data.Kind = Spec then
8540                         Unit_Except.Spec := Src_Data.File;
8541                      else
8542                         Unit_Except.Impl := Src_Data.File;
8543                      end if;
8544
8545                      Unit_Exceptions.Set (Src_Data.Unit, Unit_Except);
8546                   end;
8547                end if;
8548
8549                Source := Src_Data.Next_In_Project;
8550             end;
8551          end loop;
8552
8553          Find_Explicit_Sources
8554            (Current_Dir, Project, In_Tree, Data);
8555
8556          --  Mark as such the sources that are declared as excluded
8557
8558          FF := Excluded_Sources_Htable.Get_First;
8559          while FF /= No_File_Found loop
8560             OK     := False;
8561             Source := In_Tree.First_Source;
8562             while Source /= No_Source loop
8563                declare
8564                   Src_Data : Source_Data renames
8565                                In_Tree.Sources.Table (Source);
8566
8567                begin
8568                   if Src_Data.File = FF.File then
8569
8570                      --  Check that this is from this project or a project that
8571                      --  the current project extends.
8572
8573                      if Src_Data.Project = Project or else
8574                        Is_Extending (Project, Src_Data.Project, In_Tree)
8575                      then
8576                         Src_Data.Locally_Removed := True;
8577                         Src_Data.In_Interfaces := False;
8578                         Add_Forbidden_File_Name (FF.File);
8579                         OK := True;
8580                         exit;
8581                      end if;
8582                   end if;
8583
8584                   Source := Src_Data.Next_In_Sources;
8585                end;
8586             end loop;
8587
8588             if not FF.Found and not OK then
8589                Err_Vars.Error_Msg_File_1 := FF.File;
8590                Error_Msg (Project, In_Tree, "unknown file {", FF.Location);
8591             end if;
8592
8593             FF := Excluded_Sources_Htable.Get_Next;
8594          end loop;
8595
8596          --  Check that two sources of this project do not have the same object
8597          --  file name.
8598
8599          Check_Object_File_Names : declare
8600             Src_Id      : Source_Id;
8601             Source_Name : File_Name_Type;
8602
8603             procedure Check_Object (Src_Data : Source_Data);
8604             --  Check if object file name of the current source is already in
8605             --  hash table Object_File_Names. If it is, report an error. If it
8606             --  is not, put it there with the file name of the current source.
8607
8608             ------------------
8609             -- Check_Object --
8610             ------------------
8611
8612             procedure Check_Object (Src_Data : Source_Data) is
8613             begin
8614                Source_Name := Object_File_Names.Get (Src_Data.Object);
8615
8616                if Source_Name /= No_File then
8617                   Error_Msg_File_1 := Src_Data.File;
8618                   Error_Msg_File_2 := Source_Name;
8619                   Error_Msg
8620                     (Project,
8621                      In_Tree,
8622                      "{ and { have the same object file name",
8623                      No_Location);
8624
8625                else
8626                   Object_File_Names.Set (Src_Data.Object, Src_Data.File);
8627                end if;
8628             end Check_Object;
8629
8630          --  Start of processing for Check_Object_File_Names
8631
8632          begin
8633             Object_File_Names.Reset;
8634             Src_Id := In_Tree.First_Source;
8635             while Src_Id /= No_Source loop
8636                declare
8637                   Src_Data : Source_Data renames
8638                                In_Tree.Sources.Table (Src_Id);
8639
8640                begin
8641                   if Src_Data.Compiled and then Src_Data.Object_Exists
8642                     and then Project_Extends
8643                                (Project, Src_Data.Project, In_Tree)
8644                   then
8645                      if Src_Data.Unit = No_Name then
8646                         if Src_Data.Kind = Impl then
8647                            Check_Object (Src_Data);
8648                         end if;
8649
8650                      else
8651                         case Src_Data.Kind is
8652                            when Spec =>
8653                               if Src_Data.Other_Part = No_Source then
8654                                  Check_Object (Src_Data);
8655                               end if;
8656
8657                            when Sep =>
8658                               null;
8659
8660                            when Impl =>
8661                               if Src_Data.Other_Part /= No_Source then
8662                                  Check_Object (Src_Data);
8663
8664                               else
8665                                  --  Check if it is a subunit
8666
8667                                  declare
8668                                     Src_Ind : constant Source_File_Index :=
8669                                                 Sinput.P.Load_Project_File
8670                                                  (Get_Name_String
8671                                                    (Src_Data.Path.Name));
8672                                  begin
8673                                     if Sinput.P.Source_File_Is_Subunit
8674                                       (Src_Ind)
8675                                     then
8676                                        In_Tree.Sources.Table (Src_Id).Kind :=
8677                                          Sep;
8678                                     else
8679                                        Check_Object (Src_Data);
8680                                     end if;
8681                                  end;
8682                               end if;
8683                         end case;
8684                      end if;
8685                   end if;
8686
8687                   Src_Id := Src_Data.Next_In_Sources;
8688                end;
8689             end loop;
8690          end Check_Object_File_Names;
8691       end Process_Sources_In_Multi_Language_Mode;
8692
8693    --  Start of processing for Look_For_Sources
8694
8695    begin
8696       Source_Names.Reset;
8697       Find_Excluded_Sources (Project, In_Tree, Data);
8698
8699       case Get_Mode is
8700          when Ada_Only =>
8701             if Is_A_Language (In_Tree, Data, Name_Ada) then
8702                Find_Explicit_Sources (Current_Dir, Project, In_Tree, Data);
8703                Remove_Locally_Removed_Files_From_Units;
8704             end if;
8705
8706          when Multi_Language =>
8707             if Data.First_Language_Processing /= No_Language_Index then
8708                Process_Sources_In_Multi_Language_Mode;
8709             end if;
8710       end case;
8711    end Look_For_Sources;
8712
8713    ------------------
8714    -- Path_Name_Of --
8715    ------------------
8716
8717    function Path_Name_Of
8718      (File_Name : File_Name_Type;
8719       Directory : Path_Name_Type) return String
8720    is
8721       Result        : String_Access;
8722       The_Directory : constant String := Get_Name_String (Directory);
8723
8724    begin
8725       Get_Name_String (File_Name);
8726       Result :=
8727         Locate_Regular_File
8728           (File_Name => Name_Buffer (1 .. Name_Len),
8729            Path      => The_Directory);
8730
8731       if Result = null then
8732          return "";
8733       else
8734          Canonical_Case_File_Name (Result.all);
8735          return Result.all;
8736       end if;
8737    end Path_Name_Of;
8738
8739    -------------------------------
8740    -- Prepare_Ada_Naming_Exceptions --
8741    -------------------------------
8742
8743    procedure Prepare_Ada_Naming_Exceptions
8744      (List    : Array_Element_Id;
8745       In_Tree : Project_Tree_Ref;
8746       Kind    : Spec_Or_Body)
8747    is
8748       Current : Array_Element_Id;
8749       Element : Array_Element;
8750       Unit    : Unit_Info;
8751
8752    begin
8753       --  Traverse the list
8754
8755       Current := List;
8756       while Current /= No_Array_Element loop
8757          Element := In_Tree.Array_Elements.Table (Current);
8758
8759          if Element.Index /= No_Name then
8760             Unit :=
8761               (Kind => Kind,
8762                Unit => Element.Index,
8763                Next => No_Ada_Naming_Exception);
8764             Reverse_Ada_Naming_Exceptions.Set
8765               (Unit, (Element.Value.Value, Element.Value.Index));
8766             Unit.Next :=
8767               Ada_Naming_Exceptions.Get (File_Name_Type (Element.Value.Value));
8768             Ada_Naming_Exception_Table.Increment_Last;
8769             Ada_Naming_Exception_Table.Table
8770               (Ada_Naming_Exception_Table.Last) := Unit;
8771             Ada_Naming_Exceptions.Set
8772               (File_Name_Type (Element.Value.Value),
8773                Ada_Naming_Exception_Table.Last);
8774          end if;
8775
8776          Current := Element.Next;
8777       end loop;
8778    end Prepare_Ada_Naming_Exceptions;
8779
8780    ---------------------
8781    -- Project_Extends --
8782    ---------------------
8783
8784    function Project_Extends
8785      (Extending : Project_Id;
8786       Extended  : Project_Id;
8787       In_Tree   : Project_Tree_Ref) return Boolean
8788    is
8789       Current : Project_Id := Extending;
8790
8791    begin
8792       loop
8793          if Current = No_Project then
8794             return False;
8795
8796          elsif Current = Extended then
8797             return True;
8798          end if;
8799
8800          Current := In_Tree.Projects.Table (Current).Extends;
8801       end loop;
8802    end Project_Extends;
8803
8804    -----------------------
8805    -- Record_Ada_Source --
8806    -----------------------
8807
8808    procedure Record_Ada_Source
8809      (File_Name       : File_Name_Type;
8810       Path_Name       : Path_Name_Type;
8811       Project         : Project_Id;
8812       In_Tree         : Project_Tree_Ref;
8813       Data            : in out Project_Data;
8814       Location        : Source_Ptr;
8815       Current_Source  : in out String_List_Id;
8816       Source_Recorded : in out Boolean;
8817       Current_Dir     : String)
8818    is
8819       Canonical_File_Name : File_Name_Type;
8820       Canonical_Path_Name : Path_Name_Type;
8821
8822       Exception_Id : Ada_Naming_Exception_Id;
8823       Unit_Name    : Name_Id;
8824       Unit_Kind    : Spec_Or_Body;
8825       Unit_Ind     : Int := 0;
8826       Info         : Unit_Info;
8827       Name_Index   : Name_And_Index;
8828       Needs_Pragma : Boolean;
8829
8830       The_Location    : Source_Ptr              := Location;
8831       Previous_Source : constant String_List_Id := Current_Source;
8832       Except_Name     : Name_And_Index          := No_Name_And_Index;
8833
8834       Unit_Prj : Unit_Project;
8835
8836       File_Name_Recorded : Boolean := False;
8837
8838    begin
8839       if Osint.File_Names_Case_Sensitive then
8840          Canonical_File_Name := File_Name;
8841          Canonical_Path_Name := Path_Name;
8842       else
8843          Get_Name_String (File_Name);
8844          Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
8845          Canonical_File_Name := Name_Find;
8846
8847          declare
8848             Canonical_Path : constant String :=
8849                                Normalize_Pathname
8850                                  (Get_Name_String (Path_Name),
8851                                   Directory      => Current_Dir,
8852                                   Resolve_Links  => Opt.Follow_Links_For_Files,
8853                                   Case_Sensitive => False);
8854          begin
8855             Name_Len := 0;
8856             Add_Str_To_Name_Buffer (Canonical_Path);
8857             Canonical_Path_Name := Name_Find;
8858          end;
8859       end if;
8860
8861       --  Find out the unit name, the unit kind and if it needs
8862       --  a specific SFN pragma.
8863
8864       Get_Unit
8865         (In_Tree             => In_Tree,
8866          Canonical_File_Name => Canonical_File_Name,
8867          Naming              => Data.Naming,
8868          Exception_Id        => Exception_Id,
8869          Unit_Name           => Unit_Name,
8870          Unit_Kind           => Unit_Kind,
8871          Needs_Pragma        => Needs_Pragma);
8872
8873       if Exception_Id = No_Ada_Naming_Exception
8874         and then Unit_Name = No_Name
8875       then
8876          if Current_Verbosity = High then
8877             Write_Str  ("   """);
8878             Write_Str  (Get_Name_String (Canonical_File_Name));
8879             Write_Line (""" is not a valid source file name (ignored).");
8880          end if;
8881
8882       else
8883          --  Check to see if the source has been hidden by an exception,
8884          --  but only if it is not an exception.
8885
8886          if not Needs_Pragma then
8887             Except_Name :=
8888               Reverse_Ada_Naming_Exceptions.Get
8889                 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
8890
8891             if Except_Name /= No_Name_And_Index then
8892                if Current_Verbosity = High then
8893                   Write_Str  ("   """);
8894                   Write_Str  (Get_Name_String (Canonical_File_Name));
8895                   Write_Str  (""" contains a unit that is found in """);
8896                   Write_Str  (Get_Name_String (Except_Name.Name));
8897                   Write_Line (""" (ignored).");
8898                end if;
8899
8900                --  The file is not included in the source of the project since
8901                --  it is hidden by the exception. So, nothing else to do.
8902
8903                return;
8904             end if;
8905          end if;
8906
8907          loop
8908             if Exception_Id /= No_Ada_Naming_Exception then
8909                Info := Ada_Naming_Exception_Table.Table (Exception_Id);
8910                Exception_Id := Info.Next;
8911                Info.Next := No_Ada_Naming_Exception;
8912                Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
8913
8914                Unit_Name := Info.Unit;
8915                Unit_Ind  := Name_Index.Index;
8916                Unit_Kind := Info.Kind;
8917             end if;
8918
8919             --  Put the file name in the list of sources of the project
8920
8921             String_Element_Table.Increment_Last (In_Tree.String_Elements);
8922             In_Tree.String_Elements.Table
8923               (String_Element_Table.Last (In_Tree.String_Elements)) :=
8924                 (Value         => Name_Id (Canonical_File_Name),
8925                  Display_Value => Name_Id (File_Name),
8926                  Location      => No_Location,
8927                  Flag          => False,
8928                  Next          => Nil_String,
8929                  Index         => Unit_Ind);
8930
8931             if Current_Source = Nil_String then
8932                Data.Ada_Sources :=
8933                  String_Element_Table.Last (In_Tree.String_Elements);
8934             else
8935                In_Tree.String_Elements.Table (Current_Source).Next :=
8936                  String_Element_Table.Last (In_Tree.String_Elements);
8937             end if;
8938
8939             Current_Source :=
8940               String_Element_Table.Last (In_Tree.String_Elements);
8941
8942             --  Put the unit in unit list
8943
8944             declare
8945                The_Unit : Unit_Index :=
8946                             Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
8947
8948                The_Unit_Data : Unit_Data;
8949
8950             begin
8951                if Current_Verbosity = High then
8952                   Write_Str  ("Putting ");
8953                   Write_Str  (Get_Name_String (Unit_Name));
8954                   Write_Line (" in the unit list.");
8955                end if;
8956
8957                --  The unit is already in the list, but may be it is
8958                --  only the other unit kind (spec or body), or what is
8959                --  in the unit list is a unit of a project we are extending.
8960
8961                if The_Unit /= No_Unit_Index then
8962                   The_Unit_Data := In_Tree.Units.Table (The_Unit);
8963
8964                   if (The_Unit_Data.File_Names (Unit_Kind).Name =
8965                                                           Canonical_File_Name
8966                         and then
8967                         The_Unit_Data.File_Names
8968                           (Unit_Kind).Path.Name = Slash)
8969                     or else The_Unit_Data.File_Names (Unit_Kind).Name = No_File
8970                     or else Project_Extends
8971                       (Data.Extends,
8972                        The_Unit_Data.File_Names (Unit_Kind).Project,
8973                        In_Tree)
8974                   then
8975                      if
8976                        The_Unit_Data.File_Names (Unit_Kind).Path.Name = Slash
8977                      then
8978                         Remove_Forbidden_File_Name
8979                           (The_Unit_Data.File_Names (Unit_Kind).Name);
8980                      end if;
8981
8982                      --  Record the file name in the hash table Files_Htable
8983
8984                      Unit_Prj := (Unit => The_Unit, Project => Project);
8985                      Files_Htable.Set
8986                        (In_Tree.Files_HT,
8987                         Canonical_File_Name,
8988                         Unit_Prj);
8989
8990                      The_Unit_Data.File_Names (Unit_Kind) :=
8991                        (Name         => Canonical_File_Name,
8992                         Index        => Unit_Ind,
8993                         Display_Name => File_Name,
8994                         Path         => (Canonical_Path_Name, Path_Name),
8995                         Project      => Project,
8996                         Needs_Pragma => Needs_Pragma);
8997                      In_Tree.Units.Table (The_Unit) := The_Unit_Data;
8998                      Source_Recorded := True;
8999
9000                   elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
9001                     and then (Data.Known_Order_Of_Source_Dirs
9002                                 or else
9003                                 The_Unit_Data.File_Names
9004                                   (Unit_Kind).Path.Name = Canonical_Path_Name)
9005                   then
9006                      if Previous_Source = Nil_String then
9007                         Data.Ada_Sources := Nil_String;
9008                      else
9009                         In_Tree.String_Elements.Table (Previous_Source).Next :=
9010                           Nil_String;
9011                         String_Element_Table.Decrement_Last
9012                           (In_Tree.String_Elements);
9013                      end if;
9014
9015                      Current_Source := Previous_Source;
9016
9017                   else
9018                      --  It is an error to have two units with the same name
9019                      --  and the same kind (spec or body).
9020
9021                      if The_Location = No_Location then
9022                         The_Location :=
9023                           In_Tree.Projects.Table (Project).Location;
9024                      end if;
9025
9026                      Err_Vars.Error_Msg_Name_1 := Unit_Name;
9027                      Error_Msg
9028                        (Project, In_Tree, "duplicate unit %%", The_Location);
9029
9030                      Err_Vars.Error_Msg_Name_1 :=
9031                        In_Tree.Projects.Table
9032                          (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
9033                      Err_Vars.Error_Msg_File_1 :=
9034                        File_Name_Type
9035                          (The_Unit_Data.File_Names (Unit_Kind).Path.Name);
9036                      Error_Msg
9037                        (Project, In_Tree,
9038                         "\   project file %%, {", The_Location);
9039
9040                      Err_Vars.Error_Msg_Name_1 :=
9041                        In_Tree.Projects.Table (Project).Name;
9042                      Err_Vars.Error_Msg_File_1 :=
9043                        File_Name_Type (Canonical_Path_Name);
9044                      Error_Msg
9045                        (Project, In_Tree,
9046                         "\   project file %%, {", The_Location);
9047                   end if;
9048
9049                --  It is a new unit, create a new record
9050
9051                else
9052                   --  First, check if there is no other unit with this file
9053                   --  name in another project. If it is, report error but note
9054                   --  we do that only for the first unit in the source file.
9055
9056                   Unit_Prj :=
9057                     Files_Htable.Get (In_Tree.Files_HT, Canonical_File_Name);
9058
9059                   if not File_Name_Recorded and then
9060                     Unit_Prj /= No_Unit_Project
9061                   then
9062                      Error_Msg_File_1 := File_Name;
9063                      Error_Msg_Name_1 :=
9064                        In_Tree.Projects.Table (Unit_Prj.Project).Name;
9065                      Error_Msg
9066                        (Project, In_Tree,
9067                         "{ is already a source of project %%",
9068                         Location);
9069
9070                   else
9071                      Unit_Table.Increment_Last (In_Tree.Units);
9072                      The_Unit := Unit_Table.Last (In_Tree.Units);
9073                      Units_Htable.Set
9074                        (In_Tree.Units_HT, Unit_Name, The_Unit);
9075                      Unit_Prj := (Unit => The_Unit, Project => Project);
9076                      Files_Htable.Set
9077                        (In_Tree.Files_HT,
9078                         Canonical_File_Name,
9079                         Unit_Prj);
9080                      The_Unit_Data.Name := Unit_Name;
9081                      The_Unit_Data.File_Names (Unit_Kind) :=
9082                        (Name         => Canonical_File_Name,
9083                         Index        => Unit_Ind,
9084                         Display_Name => File_Name,
9085                         Path         => (Canonical_Path_Name, Path_Name),
9086                         Project      => Project,
9087                         Needs_Pragma => Needs_Pragma);
9088                      In_Tree.Units.Table (The_Unit) := The_Unit_Data;
9089                      Source_Recorded := True;
9090                   end if;
9091                end if;
9092             end;
9093
9094             exit when Exception_Id = No_Ada_Naming_Exception;
9095             File_Name_Recorded := True;
9096          end loop;
9097       end if;
9098    end Record_Ada_Source;
9099
9100    -------------------
9101    -- Remove_Source --
9102    -------------------
9103
9104    procedure Remove_Source
9105      (Id          : Source_Id;
9106       Replaced_By : Source_Id;
9107       Project     : Project_Id;
9108       Data        : in out Project_Data;
9109       In_Tree     : Project_Tree_Ref)
9110    is
9111       Src_Data : constant Source_Data := In_Tree.Sources.Table (Id);
9112       Source   : Source_Id;
9113
9114    begin
9115       if Current_Verbosity = High then
9116          Write_Str ("Removing source #");
9117          Write_Line (Id'Img);
9118       end if;
9119
9120       if Replaced_By /= No_Source then
9121          In_Tree.Sources.Table (Id).Replaced_By := Replaced_By;
9122          In_Tree.Sources.Table (Replaced_By).Declared_In_Interfaces :=
9123            In_Tree.Sources.Table (Id).Declared_In_Interfaces;
9124       end if;
9125
9126       --  Remove the source from the global source list
9127
9128       Source := In_Tree.First_Source;
9129
9130       if Source = Id then
9131          In_Tree.First_Source := Src_Data.Next_In_Sources;
9132
9133       else
9134          while In_Tree.Sources.Table (Source).Next_In_Sources /= Id loop
9135             Source := In_Tree.Sources.Table (Source).Next_In_Sources;
9136          end loop;
9137
9138          In_Tree.Sources.Table (Source).Next_In_Sources :=
9139            Src_Data.Next_In_Sources;
9140       end if;
9141
9142       --  Remove the source from the project list
9143
9144       if Src_Data.Project = Project then
9145          Source := Data.First_Source;
9146
9147          if Source = Id then
9148             Data.First_Source := Src_Data.Next_In_Project;
9149
9150             if Src_Data.Next_In_Project = No_Source then
9151                Data.Last_Source := No_Source;
9152             end if;
9153
9154          else
9155             while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
9156                Source := In_Tree.Sources.Table (Source).Next_In_Project;
9157             end loop;
9158
9159             In_Tree.Sources.Table (Source).Next_In_Project :=
9160               Src_Data.Next_In_Project;
9161
9162             if Src_Data.Next_In_Project = No_Source then
9163                In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
9164             end if;
9165          end if;
9166
9167       else
9168          Source := In_Tree.Projects.Table (Src_Data.Project).First_Source;
9169
9170          if Source = Id then
9171             In_Tree.Projects.Table (Src_Data.Project).First_Source :=
9172               Src_Data.Next_In_Project;
9173
9174             if Src_Data.Next_In_Project = No_Source then
9175                In_Tree.Projects.Table (Src_Data.Project).Last_Source :=
9176                  No_Source;
9177             end if;
9178
9179          else
9180             while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
9181                Source := In_Tree.Sources.Table (Source).Next_In_Project;
9182             end loop;
9183
9184             In_Tree.Sources.Table (Source).Next_In_Project :=
9185               Src_Data.Next_In_Project;
9186
9187             if Src_Data.Next_In_Project = No_Source then
9188                In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
9189             end if;
9190          end if;
9191       end if;
9192
9193       --  Remove source from the language list
9194
9195       Source := In_Tree.Languages_Data.Table (Src_Data.Language).First_Source;
9196
9197       if Source = Id then
9198          In_Tree.Languages_Data.Table (Src_Data.Language).First_Source :=
9199            Src_Data.Next_In_Lang;
9200
9201       else
9202          while In_Tree.Sources.Table (Source).Next_In_Lang /= Id loop
9203             Source := In_Tree.Sources.Table (Source).Next_In_Lang;
9204          end loop;
9205
9206          In_Tree.Sources.Table (Source).Next_In_Lang :=
9207            Src_Data.Next_In_Lang;
9208       end if;
9209    end Remove_Source;
9210
9211    -----------------------
9212    -- Report_No_Sources --
9213    -----------------------
9214
9215    procedure Report_No_Sources
9216      (Project      : Project_Id;
9217       Lang_Name    : String;
9218       In_Tree      : Project_Tree_Ref;
9219       Location     : Source_Ptr;
9220       Continuation : Boolean := False)
9221    is
9222    begin
9223       case When_No_Sources is
9224          when Silent =>
9225             null;
9226
9227          when Warning | Error =>
9228             declare
9229                Msg : constant String :=
9230                        "<there are no " &
9231                        Lang_Name &
9232                        " sources in this project";
9233
9234             begin
9235                Error_Msg_Warn := When_No_Sources = Warning;
9236
9237                if Continuation then
9238                   Error_Msg
9239                     (Project, In_Tree, "\" & Msg, Location);
9240
9241                else
9242                   Error_Msg
9243                     (Project, In_Tree, Msg, Location);
9244                end if;
9245             end;
9246       end case;
9247    end Report_No_Sources;
9248
9249    ----------------------
9250    -- Show_Source_Dirs --
9251    ----------------------
9252
9253    procedure Show_Source_Dirs
9254      (Data    : Project_Data;
9255       In_Tree : Project_Tree_Ref)
9256    is
9257       Current : String_List_Id;
9258       Element : String_Element;
9259
9260    begin
9261       Write_Line ("Source_Dirs:");
9262
9263       Current := Data.Source_Dirs;
9264       while Current /= Nil_String loop
9265          Element := In_Tree.String_Elements.Table (Current);
9266          Write_Str  ("   ");
9267          Write_Line (Get_Name_String (Element.Value));
9268          Current := Element.Next;
9269       end loop;
9270
9271       Write_Line ("end Source_Dirs.");
9272    end Show_Source_Dirs;
9273
9274    -------------------------
9275    -- Warn_If_Not_Sources --
9276    -------------------------
9277
9278    --  comments needed in this body ???
9279
9280    procedure Warn_If_Not_Sources
9281      (Project     : Project_Id;
9282       In_Tree     : Project_Tree_Ref;
9283       Conventions : Array_Element_Id;
9284       Specs       : Boolean;
9285       Extending   : Boolean)
9286    is
9287       Conv          : Array_Element_Id;
9288       Unit          : Name_Id;
9289       The_Unit_Id   : Unit_Index;
9290       The_Unit_Data : Unit_Data;
9291       Location      : Source_Ptr;
9292
9293    begin
9294       Conv := Conventions;
9295       while Conv /= No_Array_Element loop
9296          Unit := In_Tree.Array_Elements.Table (Conv).Index;
9297          Error_Msg_Name_1 := Unit;
9298          Get_Name_String (Unit);
9299          To_Lower (Name_Buffer (1 .. Name_Len));
9300          Unit := Name_Find;
9301          The_Unit_Id := Units_Htable.Get (In_Tree.Units_HT, Unit);
9302          Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
9303
9304          if The_Unit_Id = No_Unit_Index then
9305             Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
9306
9307          else
9308             The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
9309             Error_Msg_Name_2 :=
9310               In_Tree.Array_Elements.Table (Conv).Value.Value;
9311
9312             if Specs then
9313                if not Check_Project
9314                  (The_Unit_Data.File_Names (Specification).Project,
9315                   Project, In_Tree, Extending)
9316                then
9317                   Error_Msg
9318                     (Project, In_Tree,
9319                      "?source of spec of unit %% (%%)" &
9320                      " cannot be found in this project",
9321                      Location);
9322                end if;
9323
9324             else
9325                if not Check_Project
9326                  (The_Unit_Data.File_Names (Body_Part).Project,
9327                   Project, In_Tree, Extending)
9328                then
9329                   Error_Msg
9330                     (Project, In_Tree,
9331                      "?source of body of unit %% (%%)" &
9332                      " cannot be found in this project",
9333                      Location);
9334                end if;
9335             end if;
9336          end if;
9337
9338          Conv := In_Tree.Array_Elements.Table (Conv).Next;
9339       end loop;
9340    end Warn_If_Not_Sources;
9341
9342 end Prj.Nmsc;