OSDN Git Service

PR target/18337
[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-2004 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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Err_Vars; use Err_Vars;
28 with Fmap;     use Fmap;
29 with Hostparm;
30 with MLib.Tgt;
31 with Namet;    use Namet;
32 with Osint;    use Osint;
33 with Output;   use Output;
34 with MLib.Tgt; use MLib.Tgt;
35 with Prj.Com;  use Prj.Com;
36 with Prj.Env;  use Prj.Env;
37 with Prj.Err;
38 with Prj.Util; use Prj.Util;
39 with Sinput.P;
40 with Snames;   use Snames;
41 with Table;    use Table;
42 with Types;    use Types;
43
44 with Ada.Characters.Handling;    use Ada.Characters.Handling;
45 with Ada.Strings;                use Ada.Strings;
46 with Ada.Strings.Fixed;          use Ada.Strings.Fixed;
47 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
48
49 with GNAT.Case_Util;             use GNAT.Case_Util;
50 with GNAT.Directory_Operations;  use GNAT.Directory_Operations;
51 with GNAT.OS_Lib;                use GNAT.OS_Lib;
52 with GNAT.HTable;
53
54 package body Prj.Nmsc is
55
56    Error_Report : Put_Line_Access := null;
57    --  Set to point to error reporting procedure
58
59    ALI_Suffix   : constant String := ".ali";
60    --  File suffix for ali files
61
62    Object_Suffix : constant String := Get_Object_Suffix.all;
63    --  File suffix for object files
64
65    type Name_Location is record
66       Name     : Name_Id;
67       Location : Source_Ptr;
68       Found    : Boolean := False;
69    end record;
70    --  Information about file names found in string list attribute
71    --  Source_Files or in a source list file, stored in hash table
72    --  Source_Names, used by procedure
73    --  Ada_Check.Get_Path_Names_And_Record_Sources.
74
75    No_Name_Location : constant Name_Location :=
76      (Name => No_Name, Location => No_Location, Found => False);
77
78    package Source_Names is new GNAT.HTable.Simple_HTable
79      (Header_Num => Header_Num,
80       Element    => Name_Location,
81       No_Element => No_Name_Location,
82       Key        => Name_Id,
83       Hash       => Hash,
84       Equal      => "=");
85    --  Hash table to store file names found in string list attribute
86    --  Source_Files or in a source list file, stored in hash table
87    --  Source_Names, used by procedure
88    --  Ada_Check.Get_Path_Names_And_Record_Sources.
89
90    package Recursive_Dirs is new GNAT.HTable.Simple_HTable
91      (Header_Num => Header_Num,
92       Element    => Boolean,
93       No_Element => False,
94       Key        => Name_Id,
95       Hash       => Hash,
96       Equal      => "=");
97    --  Hash table to store recursive source directories, to avoid looking
98    --  several times, and to avoid cycles that may be introduced by symbolic
99    --  links.
100
101    type Ada_Naming_Exception_Id is new Nat;
102    No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
103
104    type Unit_Info is record
105       Kind : Spec_Or_Body;
106       Unit : Name_Id;
107       Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
108    end record;
109    --  No_Unit : constant Unit_Info :=
110    --              (Specification, No_Name, No_Ada_Naming_Exception);
111
112    package Ada_Naming_Exception_Table is new Table.Table
113      (Table_Component_Type => Unit_Info,
114       Table_Index_Type     => Ada_Naming_Exception_Id,
115       Table_Low_Bound      => 1,
116       Table_Initial        => 20,
117       Table_Increment      => 100,
118       Table_Name           => "Prj.Nmsc.Ada_Naming_Exception_Table");
119
120    package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
121      (Header_Num => Header_Num,
122       Element    => Ada_Naming_Exception_Id,
123       No_Element => No_Ada_Naming_Exception,
124       Key        => Name_Id,
125       Hash       => Hash,
126       Equal      => "=");
127    --  A hash table to store naming exceptions for Ada. For each file name
128    --  there is one or several unit in table Ada_Naming_Exception_Table.
129
130    function Hash (Unit : Unit_Info) return Header_Num;
131
132    type Name_And_Index is record
133       Name  : Name_Id := No_Name;
134       Index : Int     := 0;
135    end record;
136    No_Name_And_Index : constant Name_And_Index :=
137                          (Name => No_Name, Index => 0);
138
139    package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
140      (Header_Num => Header_Num,
141       Element    => Name_And_Index,
142       No_Element => No_Name_And_Index,
143       Key        => Unit_Info,
144       Hash       => Hash,
145       Equal      => "=");
146    --  A table to check if a unit with an exceptional name will hide
147    --  a source with a file name following the naming convention.
148
149    function ALI_File_Name (Source : String) return String;
150    --  Return the ALI file name corresponding to a source.
151
152    procedure Check_Ada_Name
153      (Name : String;
154       Unit : out Name_Id);
155    --  Check that a name is a valid Ada unit name.
156
157    procedure Check_Ada_Naming_Scheme
158      (Data    : in out Project_Data;
159       Project : Project_Id);
160    --  Check the naming scheme part of Data
161
162    procedure Check_Ada_Naming_Scheme_Validity
163      (Project : Project_Id;
164       Naming  : Naming_Data);
165    --  Check that the package Naming is correct.
166
167    procedure Check_For_Source
168      (File_Name        : Name_Id;
169       Path_Name        : Name_Id;
170       Project          : Project_Id;
171       Data             : in out Project_Data;
172       Location         : Source_Ptr;
173       Language         : Other_Programming_Language;
174       Suffix           : String;
175       Naming_Exception : Boolean);
176    --  Check if a file in a source directory is a source for a specific
177    --  language other than Ada.
178
179    function Check_Project
180      (P            : Project_Id;
181       Root_Project : Project_Id;
182       Extending    : Boolean) return Boolean;
183    --  Returns True if P is Root_Project or, if Extending is True, a project
184    --  extended by Root_Project.
185
186    function Compute_Directory_Last (Dir : String) return Natural;
187    --  Return the index of the last significant character in Dir. This is used
188    --  to avoid duplicates '/' at the end of directory names
189
190    procedure Error_Msg
191      (Project       : Project_Id;
192       Msg           : String;
193       Flag_Location : Source_Ptr);
194    --  Output an error message. If Error_Report is null, simply call
195    --  Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
196    --  Error_Report.
197
198    procedure Find_Sources
199      (Project      : Project_Id;
200       Data         : in out Project_Data;
201       For_Language : Programming_Language;
202       Follow_Links : Boolean := False);
203    --  Find all the sources in all of the source directories of a project for
204    --  a specified language.
205
206    procedure Free_Ada_Naming_Exceptions;
207    --  Free the internal hash tables used for checking naming exceptions
208
209    procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
210    --  Get the mains of a project from attribute Main, if it exists, and put
211    --  them in the project data.
212
213    procedure Get_Sources_From_File
214      (Path     : String;
215       Location : Source_Ptr;
216       Project  : Project_Id);
217    --  Get the list of sources from a text file and put them in hash table
218    --  Source_Names.
219
220    procedure Get_Unit
221      (Canonical_File_Name : Name_Id;
222       Naming              : Naming_Data;
223       Exception_Id        : out Ada_Naming_Exception_Id;
224       Unit_Name           : out Name_Id;
225       Unit_Kind           : out Spec_Or_Body;
226       Needs_Pragma        : out Boolean);
227    --  Find out, from a file name, the unit name, the unit kind and if a
228    --  specific SFN pragma is needed. If the file name corresponds to no
229    --  unit, then Unit_Name will be No_Name. If the file is a multi-unit source
230    --  or an exception to the naming scheme, then Exception_Id is set to
231    --  the unit or units that the source contains.
232
233    function Is_Illegal_Suffix
234      (Suffix                          : String;
235       Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
236    --  Returns True if the string Suffix cannot be used as
237    --  a spec suffix, a body suffix or a separate suffix.
238
239    procedure Locate_Directory
240      (Name    : Name_Id;
241       Parent  : Name_Id;
242       Dir     : out Name_Id;
243       Display : out Name_Id);
244    --  Locate a directory (returns No_Name for Dir and Display if directory
245    --  does not exist). Name is the directory name. Parent is the root
246    --  directory, if Name is a relative path name. Dir is the canonical case
247    --  path name of the directory, Display is the directory path name for
248    --  display purposes.
249
250    function Path_Name_Of
251      (File_Name : Name_Id;
252       Directory : Name_Id) return String;
253    --  Returns the path name of a (non project) file.
254    --  Returns an empty string if file cannot be found.
255
256    procedure Prepare_Ada_Naming_Exceptions
257      (List : Array_Element_Id;
258       Kind : Spec_Or_Body);
259    --  Prepare the internal hash tables used for checking naming exceptions
260    --  for Ada. Insert all elements of List in the tables.
261
262    function Project_Extends
263      (Extending : Project_Id;
264       Extended  : Project_Id) return Boolean;
265    --  Returns True if Extending is extending directly or indirectly Extended.
266
267    procedure Record_Ada_Source
268      (File_Name       : Name_Id;
269       Path_Name       : Name_Id;
270       Project         : Project_Id;
271       Data            : in out Project_Data;
272       Location        : Source_Ptr;
273       Current_Source  : in out String_List_Id;
274       Source_Recorded : in out Boolean;
275       Follow_Links    : Boolean);
276    --  Put a unit in the list of units of a project, if the file name
277    --  corresponds to a valid unit name.
278
279    procedure Record_Other_Sources
280      (Project           : Project_Id;
281       Data              : in out Project_Data;
282       Language          : Programming_Language;
283       Naming_Exceptions : Boolean);
284    --  Record the sources of a language in a project.
285    --  When Naming_Exceptions is True, mark the found sources as such, to
286    --  later remove those that are not named in a list of sources.
287
288    procedure Show_Source_Dirs (Project : Project_Id);
289    --  List all the source directories of a project.
290
291    function Suffix_For
292      (Language : Programming_Language;
293       Naming   : Naming_Data) return Name_Id;
294    --  Get the suffix for the source of a language from a package naming.
295    --  If not specified, return the default for the language.
296
297    ---------------
298    -- Ada_Check --
299    ---------------
300
301    procedure Ada_Check
302      (Project      : Project_Id;
303       Report_Error : Put_Line_Access;
304       Follow_Links : Boolean)
305    is
306       Data         : Project_Data;
307       Languages    : Variable_Value := Nil_Variable_Value;
308
309       Extending    : Boolean := False;
310
311       procedure Get_Path_Names_And_Record_Sources;
312       --  Find the path names of the source files in the Source_Names table
313       --  in the source directories and record those that are Ada sources.
314
315       procedure Get_Sources_From_File
316         (Path     : String;
317          Location : Source_Ptr);
318       --  Get the sources of a project from a text file
319
320       procedure Warn_If_Not_Sources
321         (Conventions : Array_Element_Id;
322          Specs       : Boolean);
323       --  Check that individual naming conventions apply to immediate
324       --  sources of the project; if not, issue a warning.
325
326       ---------------------------------------
327       -- Get_Path_Names_And_Record_Sources --
328       ---------------------------------------
329
330       procedure Get_Path_Names_And_Record_Sources is
331          Source_Dir : String_List_Id := Data.Source_Dirs;
332          Element    : String_Element;
333          Path       : Name_Id;
334
335          Dir      : Dir_Type;
336          Name     : Name_Id;
337          Canonical_Name : Name_Id;
338          Name_Str : String (1 .. 1_024);
339          Last     : Natural := 0;
340          NL       : Name_Location;
341
342          Current_Source : String_List_Id := Nil_String;
343
344          First_Error : Boolean := True;
345
346          Source_Recorded : Boolean := False;
347
348       begin
349          --  We look in all source directories for the file names in the
350          --  hash table Source_Names
351
352          while Source_Dir /= Nil_String loop
353             Source_Recorded := False;
354             Element := String_Elements.Table (Source_Dir);
355
356             declare
357                Dir_Path : constant String := Get_Name_String (Element.Value);
358             begin
359                if Current_Verbosity = High then
360                   Write_Str ("checking directory """);
361                   Write_Str (Dir_Path);
362                   Write_Line ("""");
363                end if;
364
365                Open (Dir, Dir_Path);
366
367                loop
368                   Read (Dir, Name_Str, Last);
369                   exit when Last = 0;
370                   Name_Len := Last;
371                   Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
372                   Name := Name_Find;
373                   Canonical_Case_File_Name (Name_Str (1 .. Last));
374                   Name_Len := Last;
375                   Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
376                   Canonical_Name := Name_Find;
377                   NL := Source_Names.Get (Canonical_Name);
378
379                   if NL /= No_Name_Location and then not NL.Found then
380                      NL.Found := True;
381                      Source_Names.Set (Canonical_Name, NL);
382                      Name_Len := Dir_Path'Length;
383                      Name_Buffer (1 .. Name_Len) := Dir_Path;
384
385                      if Name_Buffer (Name_Len) /= Directory_Separator then
386                         Add_Char_To_Name_Buffer (Directory_Separator);
387                      end if;
388
389                      Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
390                      Path := Name_Find;
391
392                      if Current_Verbosity = High then
393                         Write_Str  ("  found ");
394                         Write_Line (Get_Name_String (Name));
395                      end if;
396
397                      --  Register the source if it is an Ada compilation unit.
398
399                      Record_Ada_Source
400                        (File_Name       => Name,
401                         Path_Name       => Path,
402                         Project         => Project,
403                         Data            => Data,
404                         Location        => NL.Location,
405                         Current_Source  => Current_Source,
406                         Source_Recorded => Source_Recorded,
407                         Follow_Links    => Follow_Links);
408                   end if;
409                end loop;
410
411                Close (Dir);
412             end;
413
414             if Source_Recorded then
415                String_Elements.Table (Source_Dir).Flag := True;
416             end if;
417
418             Source_Dir := Element.Next;
419          end loop;
420
421          --  It is an error if a source file name in a source list or
422          --  in a source list file is not found.
423
424          NL := Source_Names.Get_First;
425
426          while NL /= No_Name_Location loop
427             if not NL.Found then
428                Err_Vars.Error_Msg_Name_1 := NL.Name;
429
430                if First_Error then
431                   Error_Msg
432                     (Project,
433                      "source file { cannot be found",
434                      NL.Location);
435                   First_Error := False;
436
437                else
438                   Error_Msg
439                     (Project,
440                      "\source file { cannot be found",
441                      NL.Location);
442                end if;
443             end if;
444
445             NL := Source_Names.Get_Next;
446          end loop;
447       end Get_Path_Names_And_Record_Sources;
448
449       ---------------------------
450       -- Get_Sources_From_File --
451       ---------------------------
452
453       procedure Get_Sources_From_File
454         (Path     : String;
455          Location : Source_Ptr)
456       is
457       begin
458          --  Get the list of sources from the file and put them in hash table
459          --  Source_Names.
460
461          Get_Sources_From_File (Path, Location, Project);
462
463          --  Look in the source directories to find those sources
464
465          Get_Path_Names_And_Record_Sources;
466
467          --  We should have found at least one source.
468          --  If not, report an error.
469
470          if Data.Sources = Nil_String then
471             Error_Msg (Project,
472                        "there are no Ada sources in this project",
473                        Location);
474          end if;
475       end Get_Sources_From_File;
476
477       -------------------------
478       -- Warn_If_Not_Sources --
479       -------------------------
480
481       procedure Warn_If_Not_Sources
482         (Conventions : Array_Element_Id;
483          Specs       : Boolean)
484       is
485          Conv          : Array_Element_Id := Conventions;
486          Unit          : Name_Id;
487          The_Unit_Id   : Unit_Id;
488          The_Unit_Data : Unit_Data;
489          Location      : Source_Ptr;
490
491       begin
492          while Conv /= No_Array_Element loop
493             Unit := Array_Elements.Table (Conv).Index;
494             Error_Msg_Name_1 := Unit;
495             Get_Name_String (Unit);
496             To_Lower (Name_Buffer (1 .. Name_Len));
497             Unit := Name_Find;
498             The_Unit_Id := Units_Htable.Get (Unit);
499             Location := Array_Elements.Table (Conv).Value.Location;
500
501             if The_Unit_Id = Prj.Com.No_Unit then
502                Error_Msg
503                  (Project,
504                   "?unknown unit {",
505                   Location);
506
507             else
508                The_Unit_Data := Units.Table (The_Unit_Id);
509
510                if Specs then
511                   if not Check_Project
512                     (The_Unit_Data.File_Names (Specification).Project,
513                      Project, Extending)
514                   then
515                      Error_Msg
516                        (Project,
517                         "?unit{ has no spec in this project",
518                         Location);
519                   end if;
520
521                else
522                   if not Check_Project
523                     (The_Unit_Data.File_Names (Com.Body_Part).Project,
524                      Project, Extending)
525                   then
526                      Error_Msg
527                        (Project,
528                         "?unit{ has no body in this project",
529                         Location);
530                   end if;
531                end if;
532             end if;
533
534             Conv := Array_Elements.Table (Conv).Next;
535          end loop;
536       end Warn_If_Not_Sources;
537
538    --  Start of processing for Ada_Check
539
540    begin
541       Language_Independent_Check (Project, Report_Error);
542
543       Error_Report    := Report_Error;
544
545       Data      := Projects.Table (Project);
546       Extending := Data.Extends /= No_Project;
547       Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
548
549       Data.Naming.Current_Language := Name_Ada;
550       Data.Ada_Sources_Present     := Data.Source_Dirs /= Nil_String;
551
552       if not Languages.Default then
553          declare
554             Current   : String_List_Id := Languages.Values;
555             Element   : String_Element;
556             Ada_Found : Boolean := False;
557
558          begin
559             Look_For_Ada : while Current /= Nil_String loop
560                Element := String_Elements.Table (Current);
561                Get_Name_String (Element.Value);
562                To_Lower (Name_Buffer (1 .. Name_Len));
563
564                if Name_Buffer (1 .. Name_Len) = "ada" then
565                   Ada_Found := True;
566                   exit Look_For_Ada;
567                end if;
568
569                Current := Element.Next;
570             end loop Look_For_Ada;
571
572             if not Ada_Found then
573
574                --  Mark the project file as having no sources for Ada
575
576                Data.Ada_Sources_Present := False;
577             end if;
578          end;
579       end if;
580
581       Check_Ada_Naming_Scheme (Data, Project);
582
583       Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
584       Prepare_Ada_Naming_Exceptions (Data.Naming.Specs,  Specification);
585
586       --  If we have source directories, then find the sources
587
588       if Data.Ada_Sources_Present then
589          if Data.Source_Dirs = Nil_String then
590             Data.Ada_Sources_Present := False;
591
592          else
593             declare
594                Sources : constant Variable_Value :=
595                            Util.Value_Of
596                              (Name_Source_Files,
597                               Data.Decl.Attributes);
598
599                Source_List_File : constant Variable_Value :=
600                                     Util.Value_Of
601                                       (Name_Source_List_File,
602                                        Data.Decl.Attributes);
603
604                Locally_Removed : constant Variable_Value :=
605                            Util.Value_Of
606                              (Name_Locally_Removed_Files,
607                               Data.Decl.Attributes);
608
609             begin
610                pragma Assert
611                  (Sources.Kind = List,
612                     "Source_Files is not a list");
613
614                pragma Assert
615                  (Source_List_File.Kind = Single,
616                     "Source_List_File is not a single string");
617
618                if not Sources.Default then
619                   if not Source_List_File.Default then
620                      Error_Msg
621                        (Project,
622                         "?both variables source_files and " &
623                         "source_list_file are present",
624                         Source_List_File.Location);
625                   end if;
626
627                   --  Sources is a list of file names
628
629                   declare
630                      Current        : String_List_Id := Sources.Values;
631                      Element        : String_Element;
632                      Location       : Source_Ptr;
633                      Name           : Name_Id;
634
635                   begin
636                      Source_Names.Reset;
637
638                      Data.Ada_Sources_Present := Current /= Nil_String;
639
640                      while Current /= Nil_String loop
641                         Element := String_Elements.Table (Current);
642                         Get_Name_String (Element.Value);
643                         Canonical_Case_File_Name
644                           (Name_Buffer (1 .. Name_Len));
645                         Name := Name_Find;
646
647                         --  If the element has no location, then use the
648                         --  location of Sources to report possible errors.
649
650                         if Element.Location = No_Location then
651                            Location := Sources.Location;
652
653                         else
654                            Location := Element.Location;
655                         end if;
656
657                         Source_Names.Set
658                           (K => Name,
659                            E =>
660                              (Name     => Name,
661                               Location => Location,
662                               Found    => False));
663
664                         Current := Element.Next;
665                      end loop;
666
667                      Get_Path_Names_And_Record_Sources;
668                   end;
669
670                   --  No source_files specified
671
672                   --  We check Source_List_File has been specified.
673
674                elsif not Source_List_File.Default then
675
676                   --  Source_List_File is the name of the file
677                   --  that contains the source file names
678
679                   declare
680                      Source_File_Path_Name : constant String :=
681                        Path_Name_Of
682                        (Source_List_File.Value,
683                         Data.Directory);
684
685                   begin
686                      if Source_File_Path_Name'Length = 0 then
687                         Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
688                         Error_Msg
689                           (Project,
690                            "file with sources { does not exist",
691                            Source_List_File.Location);
692
693                      else
694                         Get_Sources_From_File
695                           (Source_File_Path_Name,
696                            Source_List_File.Location);
697                      end if;
698                   end;
699
700                else
701                   --  Neither Source_Files nor Source_List_File has been
702                   --  specified. Find all the files that satisfy the naming
703                   --  scheme in all the source directories.
704
705                   Find_Sources (Project, Data, Lang_Ada, Follow_Links);
706                end if;
707
708                --  If there are sources that are locally removed, mark them as
709                --  such in the Units table.
710
711                if not Locally_Removed.Default then
712
713                   --  Sources can be locally removed only in extending
714                   --  project files.
715
716                   if Data.Extends = No_Project then
717                      Error_Msg
718                        (Project,
719                         "Locally_Removed_Files can only be used " &
720                         "in an extending project file",
721                         Locally_Removed.Location);
722
723                   else
724                      declare
725                         Current        : String_List_Id :=
726                                            Locally_Removed.Values;
727                         Element        : String_Element;
728                         Location       : Source_Ptr;
729                         OK             : Boolean;
730                         Unit           : Unit_Data;
731                         Name           : Name_Id;
732                         Extended       : Project_Id;
733
734                      begin
735                         while Current /= Nil_String loop
736                            Element := String_Elements.Table (Current);
737                            Get_Name_String (Element.Value);
738                            Canonical_Case_File_Name
739                              (Name_Buffer (1 .. Name_Len));
740                            Name := Name_Find;
741
742                            --  If the element has no location, then use the
743                            --  location of Locally_Removed to report
744                            --  possible errors.
745
746                            if Element.Location = No_Location then
747                               Location := Locally_Removed.Location;
748
749                            else
750                               Location := Element.Location;
751                            end if;
752
753                            OK := False;
754
755                            for Index in 1 .. Units.Last loop
756                               Unit := Units.Table (Index);
757
758                               if
759                                 Unit.File_Names (Specification).Name = Name
760                               then
761                                  OK := True;
762
763                                  --  Check that this is from a project that
764                                  --  the current project extends, but not the
765                                  --  current project.
766
767                                  Extended := Unit.File_Names
768                                                     (Specification).Project;
769
770                                  if Extended = Project then
771                                     Error_Msg
772                                       (Project,
773                                        "cannot remove a source " &
774                                        "of the same project",
775                                        Location);
776
777                                  elsif
778                                    Project_Extends (Project, Extended)
779                                  then
780                                     Unit.File_Names
781                                       (Specification).Path := Slash;
782                                     Unit.File_Names
783                                       (Specification).Needs_Pragma := False;
784                                     Units.Table (Index) := Unit;
785                                     Add_Forbidden_File_Name
786                                       (Unit.File_Names (Specification).Name);
787                                     exit;
788
789                                  else
790                                     Error_Msg
791                                       (Project,
792                                        "cannot remove a source from " &
793                                        "another project",
794                                        Location);
795                                  end if;
796
797                               elsif
798                                 Unit.File_Names (Body_Part).Name = Name
799                               then
800                                  OK := True;
801
802                                  --  Check that this is from a project that
803                                  --  the current project extends, but not the
804                                  --  current project.
805
806                                  Extended := Unit.File_Names
807                                                     (Body_Part).Project;
808
809                                  if Extended = Project then
810                                     Error_Msg
811                                       (Project,
812                                        "cannot remove a source " &
813                                        "of the same project",
814                                        Location);
815
816                                  elsif
817                                    Project_Extends (Project, Extended)
818                                  then
819                                     Unit.File_Names (Body_Part).Path := Slash;
820                                     Unit.File_Names (Body_Part).Needs_Pragma
821                                       := False;
822                                     Units.Table (Index) := Unit;
823                                     Add_Forbidden_File_Name
824                                       (Unit.File_Names (Body_Part).Name);
825                                     exit;
826                                  end if;
827
828                               end if;
829                            end loop;
830
831                            if not OK then
832                               Err_Vars.Error_Msg_Name_1 := Name;
833                               Error_Msg (Project, "unknown file {", Location);
834                            end if;
835
836                            Current := Element.Next;
837                         end loop;
838                      end;
839                   end if;
840                end if;
841             end;
842          end if;
843       end if;
844
845       if Data.Ada_Sources_Present then
846
847          --  Check that all individual naming conventions apply to
848          --  sources of this project file.
849
850          Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
851          Warn_If_Not_Sources (Data.Naming.Specs,  Specs => True);
852       end if;
853
854       --  If it is a library project file, check if it is a standalone library
855
856       if Data.Library then
857          Standalone_Library : declare
858             Lib_Interfaces : constant Prj.Variable_Value :=
859                                Prj.Util.Value_Of
860                                  (Snames.Name_Library_Interface,
861                                   Data.Decl.Attributes);
862             Lib_Auto_Init  : constant Prj.Variable_Value :=
863                                Prj.Util.Value_Of
864                                  (Snames.Name_Library_Auto_Init,
865                                   Data.Decl.Attributes);
866
867             Lib_Src_Dir : constant Prj.Variable_Value :=
868                             Prj.Util.Value_Of
869                               (Snames.Name_Library_Src_Dir,
870                                Data.Decl.Attributes);
871
872             Lib_Symbol_File : constant Prj.Variable_Value :=
873                                 Prj.Util.Value_Of
874                                   (Snames.Name_Library_Symbol_File,
875                                    Data.Decl.Attributes);
876
877             Lib_Symbol_Policy : constant Prj.Variable_Value :=
878                                   Prj.Util.Value_Of
879                                     (Snames.Name_Library_Symbol_Policy,
880                                      Data.Decl.Attributes);
881
882             Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
883                                   Prj.Util.Value_Of
884                                     (Snames.Name_Library_Reference_Symbol_File,
885                                      Data.Decl.Attributes);
886
887             Auto_Init_Supported : constant Boolean :=
888                                     MLib.Tgt.
889                                      Standalone_Library_Auto_Init_Is_Supported;
890
891             OK : Boolean := True;
892
893          begin
894             pragma Assert (Lib_Interfaces.Kind = List);
895
896             --  It is a stand-alone library project file if attribute
897             --  Library_Interface is defined.
898
899             if not Lib_Interfaces.Default then
900                declare
901                   Interfaces : String_List_Id := Lib_Interfaces.Values;
902                   Interface_ALIs : String_List_Id := Nil_String;
903                   Unit : Name_Id;
904                   The_Unit_Id : Unit_Id;
905                   The_Unit_Data : Unit_Data;
906
907                   procedure Add_ALI_For (Source : Name_Id);
908                   --  Add an ALI file name to the list of Interface ALIs
909
910                   -----------------
911                   -- Add_ALI_For --
912                   -----------------
913
914                   procedure Add_ALI_For (Source : Name_Id) is
915                   begin
916                      Get_Name_String (Source);
917
918                      declare
919                         ALI : constant String :=
920                                 ALI_File_Name (Name_Buffer (1 .. Name_Len));
921                         ALI_Name_Id : Name_Id;
922                      begin
923                         Name_Len := ALI'Length;
924                         Name_Buffer (1 .. Name_Len) := ALI;
925                         ALI_Name_Id := Name_Find;
926
927                         String_Elements.Increment_Last;
928                         String_Elements.Table (String_Elements.Last) :=
929                           (Value    => ALI_Name_Id,
930                            Index    => 0,
931                            Display_Value => ALI_Name_Id,
932                            Location => String_Elements.Table
933                                                          (Interfaces).Location,
934                            Flag     => False,
935                            Next     => Interface_ALIs);
936                         Interface_ALIs := String_Elements.Last;
937                      end;
938                   end Add_ALI_For;
939
940                begin
941                   Data.Standalone_Library := True;
942
943                   --  Library_Interface cannot be an empty list
944
945                   if Interfaces = Nil_String then
946                      Error_Msg
947                        (Project,
948                         "Library_Interface cannot be an empty list",
949                         Lib_Interfaces.Location);
950                   end if;
951
952                   --  Process each unit name specified in the attribute
953                   --  Library_Interface.
954
955                   while Interfaces /= Nil_String loop
956                      Get_Name_String
957                        (String_Elements.Table (Interfaces).Value);
958                      To_Lower (Name_Buffer (1 .. Name_Len));
959
960                      if Name_Len = 0 then
961                         Error_Msg
962                           (Project,
963                            "an interface cannot be an empty string",
964                            String_Elements.Table (Interfaces).Location);
965
966                      else
967                         Unit := Name_Find;
968                         Error_Msg_Name_1 := Unit;
969                         The_Unit_Id := Units_Htable.Get (Unit);
970
971                         if The_Unit_Id = Prj.Com.No_Unit then
972                            Error_Msg
973                              (Project,
974                               "unknown unit {",
975                               String_Elements.Table (Interfaces).Location);
976
977                         else
978                            --  Check that the unit is part of the project
979
980                            The_Unit_Data := Units.Table (The_Unit_Id);
981
982                            if The_Unit_Data.File_Names
983                                 (Com.Body_Part).Name /= No_Name
984                              and then The_Unit_Data.File_Names
985                                         (Com.Body_Part).Path /= Slash
986                            then
987                               if Check_Project
988                                 (The_Unit_Data.File_Names (Body_Part).Project,
989                                  Project, Extending)
990                               then
991                                  --  There is a body for this unit.
992                                  --  If there is no spec, we need to check
993                                  --  that it is not a subunit.
994
995                                  if The_Unit_Data.File_Names
996                                       (Specification).Name = No_Name
997                                  then
998                                     declare
999                                        Src_Ind : Source_File_Index;
1000
1001                                     begin
1002                                        Src_Ind := Sinput.P.Load_Project_File
1003                                                    (Get_Name_String
1004                                                       (The_Unit_Data.File_Names
1005                                                          (Body_Part).Path));
1006
1007                                        if Sinput.P.Source_File_Is_Subunit
1008                                                      (Src_Ind)
1009                                        then
1010                                           Error_Msg
1011                                             (Project,
1012                                              "{ is a subunit; " &
1013                                              "it cannot be an interface",
1014                                              String_Elements.Table
1015                                                (Interfaces).Location);
1016                                        end if;
1017                                     end;
1018                                  end if;
1019
1020                                  --  The unit is not a subunit, so we add
1021                                  --  to the Interface ALIs the ALI file
1022                                  --  corresponding to the body.
1023
1024                                  Add_ALI_For
1025                                    (The_Unit_Data.File_Names (Body_Part).Name);
1026
1027                               else
1028                                  Error_Msg
1029                                    (Project,
1030                                     "{ is not an unit of this project",
1031                                     String_Elements.Table
1032                                       (Interfaces).Location);
1033                               end if;
1034
1035                            elsif The_Unit_Data.File_Names
1036                                    (Com.Specification).Name /= No_Name
1037                               and then The_Unit_Data.File_Names
1038                                          (Com.Specification).Path /= Slash
1039                               and then Check_Project
1040                                          (The_Unit_Data.File_Names
1041                                               (Specification).Project,
1042                                           Project, Extending)
1043
1044                            then
1045                               --  The unit is part of the project, it has
1046                               --  a spec, but no body. We add to the Interface
1047                               --  ALIs the ALI file corresponding to the spec.
1048
1049                               Add_ALI_For
1050                                (The_Unit_Data.File_Names (Specification).Name);
1051
1052                            else
1053                               Error_Msg
1054                                 (Project,
1055                                  "{ is not an unit of this project",
1056                                  String_Elements.Table (Interfaces).Location);
1057                            end if;
1058                         end if;
1059
1060                      end if;
1061
1062                      Interfaces := String_Elements.Table (Interfaces).Next;
1063                   end loop;
1064
1065                   --  Put the list of Interface ALIs in the project data
1066
1067                   Data.Lib_Interface_ALIs := Interface_ALIs;
1068
1069                   --  Check value of attribute Library_Auto_Init and set
1070                   --  Lib_Auto_Init accordingly.
1071
1072                   if Lib_Auto_Init.Default then
1073
1074                      --  If no attribute Library_Auto_Init is declared, then
1075                      --  set auto init only if it is supported.
1076
1077                      Data.Lib_Auto_Init := Auto_Init_Supported;
1078
1079                   else
1080                      Get_Name_String (Lib_Auto_Init.Value);
1081                      To_Lower (Name_Buffer (1 .. Name_Len));
1082
1083                      if Name_Buffer (1 .. Name_Len) = "false" then
1084                         Data.Lib_Auto_Init := False;
1085
1086                      elsif Name_Buffer (1 .. Name_Len) = "true" then
1087                         if Auto_Init_Supported then
1088                            Data.Lib_Auto_Init := True;
1089
1090                         else
1091                            --  Library_Auto_Init cannot be "true" if auto init
1092                            --  is not supported
1093
1094                            Error_Msg
1095                              (Project,
1096                               "library auto init not supported " &
1097                               "on this platform",
1098                               Lib_Auto_Init.Location);
1099                         end if;
1100
1101                      else
1102                         Error_Msg
1103                           (Project,
1104                            "invalid value for attribute Library_Auto_Init",
1105                            Lib_Auto_Init.Location);
1106                      end if;
1107                   end if;
1108                end;
1109
1110                --  If attribute Library_Src_Dir is defined and not the
1111                --  empty string, check if the directory exist and is not
1112                --  the object directory or one of the source directories.
1113                --  This is the directory where copies of the interface
1114                --  sources will be copied. Note that this directory may be
1115                --  the library directory.
1116
1117                if Lib_Src_Dir.Value /= Empty_String then
1118                   declare
1119                      Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1120
1121                   begin
1122                      Locate_Directory
1123                        (Dir_Id, Data.Display_Directory,
1124                         Data.Library_Src_Dir,
1125                         Data.Display_Library_Src_Dir);
1126
1127                      --  If directory does not exist, report an error
1128
1129                      if Data.Library_Src_Dir = No_Name then
1130
1131                         --  Get the absolute name of the library directory
1132                         --  that does not exist, to report an error.
1133
1134                         declare
1135                            Dir_Name : constant String :=
1136                                         Get_Name_String (Dir_Id);
1137
1138                         begin
1139                            if Is_Absolute_Path (Dir_Name) then
1140                               Err_Vars.Error_Msg_Name_1 := Dir_Id;
1141
1142                            else
1143                               Get_Name_String (Data.Directory);
1144
1145                               if Name_Buffer (Name_Len) /=
1146                                 Directory_Separator
1147                               then
1148                                  Name_Len := Name_Len + 1;
1149                                  Name_Buffer (Name_Len) :=
1150                                    Directory_Separator;
1151                               end if;
1152
1153                               Name_Buffer
1154                                 (Name_Len + 1 ..
1155                                    Name_Len + Dir_Name'Length) :=
1156                                   Dir_Name;
1157                               Name_Len := Name_Len + Dir_Name'Length;
1158                               Err_Vars.Error_Msg_Name_1 := Name_Find;
1159                            end if;
1160
1161                            --  Report the error
1162
1163                            Error_Msg
1164                              (Project,
1165                               "Directory { does not exist",
1166                               Lib_Src_Dir.Location);
1167                         end;
1168
1169                      --  Report an error if it is the same as the object
1170                      --  directory.
1171
1172                      elsif Data.Library_Src_Dir = Data.Object_Directory then
1173                         Error_Msg
1174                           (Project,
1175                            "directory to copy interfaces cannot be " &
1176                            "the object directory",
1177                            Lib_Src_Dir.Location);
1178                         Data.Library_Src_Dir := No_Name;
1179
1180                      --  Check if it is the same as one of the source
1181                      --  directories.
1182
1183                      else
1184                         declare
1185                            Src_Dirs : String_List_Id := Data.Source_Dirs;
1186                            Src_Dir  : String_Element;
1187
1188                         begin
1189                            while Src_Dirs /= Nil_String loop
1190                               Src_Dir := String_Elements.Table (Src_Dirs);
1191                               Src_Dirs := Src_Dir.Next;
1192
1193                               --  Report an error if it is one of the
1194                               --  source directories.
1195
1196                               if Data.Library_Src_Dir = Src_Dir.Value then
1197                                  Error_Msg
1198                                    (Project,
1199                                     "directory to copy interfaces cannot " &
1200                                     "be one of the source directories",
1201                                     Lib_Src_Dir.Location);
1202                                  Data.Library_Src_Dir := No_Name;
1203                                  exit;
1204                               end if;
1205                            end loop;
1206                         end;
1207
1208                         if Data.Library_Src_Dir /= No_Name
1209                           and then Current_Verbosity = High
1210                         then
1211                            Write_Str ("Directory to copy interfaces =""");
1212                            Write_Str (Get_Name_String (Data.Library_Dir));
1213                            Write_Line ("""");
1214                         end if;
1215                      end if;
1216                   end;
1217                end if;
1218
1219                if not Lib_Symbol_Policy.Default then
1220                   declare
1221                      Value : constant String :=
1222                                To_Lower
1223                                  (Get_Name_String (Lib_Symbol_Policy.Value));
1224
1225                   begin
1226                      if Value = "autonomous" or else Value = "default" then
1227                         Data.Symbol_Data.Symbol_Policy := Autonomous;
1228
1229                      elsif Value = "compliant" then
1230                         Data.Symbol_Data.Symbol_Policy := Compliant;
1231
1232                      elsif Value = "controlled" then
1233                         Data.Symbol_Data.Symbol_Policy := Controlled;
1234
1235                      elsif Value = "restricted" then
1236                         Data.Symbol_Data.Symbol_Policy := Restricted;
1237
1238                      else
1239                         Error_Msg
1240                           (Project,
1241                            "illegal value for Library_Symbol_Policy",
1242                            Lib_Symbol_Policy.Location);
1243                      end if;
1244                   end;
1245                end if;
1246
1247                if Lib_Symbol_File.Default then
1248                   if Data.Symbol_Data.Symbol_Policy = Restricted then
1249                      Error_Msg
1250                        (Project,
1251                         "Library_Symbol_File needs to be defined when " &
1252                         "symbol policy is Restricted",
1253                         Lib_Symbol_Policy.Location);
1254                   end if;
1255
1256                else
1257                   Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1258
1259                   Get_Name_String (Lib_Symbol_File.Value);
1260
1261                   if Name_Len = 0 then
1262                      Error_Msg
1263                        (Project,
1264                         "symbol file name cannot be an empty string",
1265                         Lib_Symbol_File.Location);
1266
1267                   else
1268                      OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1269
1270                      if OK then
1271                         for J in 1 .. Name_Len loop
1272                            if Name_Buffer (J) = '/'
1273                              or else Name_Buffer (J) = Directory_Separator
1274                            then
1275                               OK := False;
1276                               exit;
1277                            end if;
1278                         end loop;
1279                      end if;
1280
1281                      if not OK then
1282                         Error_Msg_Name_1 := Lib_Symbol_File.Value;
1283                         Error_Msg
1284                           (Project,
1285                            "symbol file name { is illegal. " &
1286                            "Name canot include directory info.",
1287                            Lib_Symbol_File.Location);
1288                      end if;
1289                   end if;
1290                end if;
1291
1292                if Lib_Ref_Symbol_File.Default then
1293                   if Data.Symbol_Data.Symbol_Policy = Compliant
1294                     or else Data.Symbol_Data.Symbol_Policy = Controlled
1295                   then
1296                      Error_Msg
1297                        (Project,
1298                         "a reference symbol file need to be defined",
1299                         Lib_Symbol_Policy.Location);
1300                   end if;
1301
1302                else
1303                   Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1304
1305                   Get_Name_String (Lib_Ref_Symbol_File.Value);
1306
1307                   if Name_Len = 0 then
1308                      Error_Msg
1309                        (Project,
1310                         "reference symbol file name cannot be an empty string",
1311                         Lib_Symbol_File.Location);
1312
1313                   else
1314                      OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1315
1316                      if OK then
1317                         for J in 1 .. Name_Len loop
1318                            if Name_Buffer (J) = '/'
1319                              or else Name_Buffer (J) = Directory_Separator
1320                            then
1321                               OK := False;
1322                               exit;
1323                            end if;
1324                         end loop;
1325                      end if;
1326
1327                      if not OK then
1328                         Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1329                         Error_Msg
1330                           (Project,
1331                            "reference symbol file { name is illegal. " &
1332                            "Name canot include directory info.",
1333                            Lib_Ref_Symbol_File.Location);
1334                      end if;
1335
1336                      if not Is_Regular_File
1337                        (Get_Name_String (Data.Object_Directory) &
1338                         Directory_Separator &
1339                         Get_Name_String (Lib_Ref_Symbol_File.Value))
1340                      then
1341                         Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1342                         Error_Msg
1343                           (Project,
1344                            "library reference symbol file { does not exist",
1345                            Lib_Ref_Symbol_File.Location);
1346                      end if;
1347
1348                      if Data.Symbol_Data.Symbol_File /= No_Name then
1349                         declare
1350                            Symbol : String :=
1351                                       Get_Name_String
1352                                         (Data.Symbol_Data.Symbol_File);
1353
1354                            Reference : String :=
1355                                          Get_Name_String
1356                                            (Data.Symbol_Data.Reference);
1357
1358                         begin
1359                            Canonical_Case_File_Name (Symbol);
1360                            Canonical_Case_File_Name (Reference);
1361
1362                            if Symbol = Reference then
1363                               Error_Msg
1364                                 (Project,
1365                                  "reference symbol file and symbol file " &
1366                                  "cannot be the same file",
1367                                  Lib_Ref_Symbol_File.Location);
1368                            end if;
1369                         end;
1370                      end if;
1371                   end if;
1372                end if;
1373             end if;
1374          end Standalone_Library;
1375       end if;
1376
1377       --  Put the list of Mains, if any, in the project data
1378
1379       Get_Mains (Project, Data);
1380
1381       Projects.Table (Project) := Data;
1382
1383       Free_Ada_Naming_Exceptions;
1384    end Ada_Check;
1385
1386    -------------------
1387    -- ALI_File_Name --
1388    -------------------
1389
1390    function ALI_File_Name (Source : String) return String is
1391    begin
1392       --  If the source name has an extension, then replace it with
1393       --  the ALI suffix.
1394
1395       for Index in reverse Source'First + 1 .. Source'Last loop
1396          if Source (Index) = '.' then
1397             return Source (Source'First .. Index - 1) & ALI_Suffix;
1398          end if;
1399       end loop;
1400
1401       --  If there is no dot, or if it is the first character, just add the
1402       --  ALI suffix.
1403
1404       return Source & ALI_Suffix;
1405    end ALI_File_Name;
1406
1407    --------------------
1408    -- Check_Ada_Name --
1409    --------------------
1410
1411    procedure Check_Ada_Name
1412      (Name : String;
1413       Unit : out Name_Id)
1414    is
1415       The_Name        : String := Name;
1416       Real_Name       : Name_Id;
1417       Need_Letter     : Boolean := True;
1418       Last_Underscore : Boolean := False;
1419       OK              : Boolean := The_Name'Length > 0;
1420
1421    begin
1422       To_Lower (The_Name);
1423
1424       Name_Len := The_Name'Length;
1425       Name_Buffer (1 .. Name_Len) := The_Name;
1426       Real_Name := Name_Find;
1427
1428       --  Check first that the given name is not an Ada reserved word
1429
1430       if Get_Name_Table_Byte (Real_Name) /= 0
1431         and then Real_Name /= Name_Project
1432         and then Real_Name /= Name_Extends
1433         and then Real_Name /= Name_External
1434       then
1435          Unit := No_Name;
1436
1437          if Current_Verbosity = High then
1438             Write_Str (The_Name);
1439             Write_Line (" is an Ada reserved word.");
1440          end if;
1441
1442          return;
1443       end if;
1444
1445       for Index in The_Name'Range loop
1446          if Need_Letter then
1447
1448             --  We need a letter (at the beginning, and following a dot),
1449             --  but we don't have one.
1450
1451             if Is_Letter (The_Name (Index)) then
1452                Need_Letter := False;
1453
1454             else
1455                OK := False;
1456
1457                if Current_Verbosity = High then
1458                   Write_Int  (Types.Int (Index));
1459                   Write_Str  (": '");
1460                   Write_Char (The_Name (Index));
1461                   Write_Line ("' is not a letter.");
1462                end if;
1463
1464                exit;
1465             end if;
1466
1467          elsif Last_Underscore
1468            and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1469          then
1470             --  Two underscores are illegal, and a dot cannot follow
1471             --  an underscore.
1472
1473             OK := False;
1474
1475             if Current_Verbosity = High then
1476                Write_Int  (Types.Int (Index));
1477                Write_Str  (": '");
1478                Write_Char (The_Name (Index));
1479                Write_Line ("' is illegal here.");
1480             end if;
1481
1482             exit;
1483
1484          elsif The_Name (Index) = '.' then
1485
1486             --  We need a letter after a dot
1487
1488             Need_Letter := True;
1489
1490          elsif The_Name (Index) = '_' then
1491             Last_Underscore := True;
1492
1493          else
1494             --  We need an letter or a digit
1495
1496             Last_Underscore := False;
1497
1498             if not Is_Alphanumeric (The_Name (Index)) then
1499                OK := False;
1500
1501                if Current_Verbosity = High then
1502                   Write_Int  (Types.Int (Index));
1503                   Write_Str  (": '");
1504                   Write_Char (The_Name (Index));
1505                   Write_Line ("' is not alphanumeric.");
1506                end if;
1507
1508                exit;
1509             end if;
1510          end if;
1511       end loop;
1512
1513       --  Cannot end with an underscore or a dot
1514
1515       OK := OK and then not Need_Letter and then not Last_Underscore;
1516
1517       if OK then
1518          Unit := Real_Name;
1519
1520       else
1521          --  Signal a problem with No_Name
1522
1523          Unit := No_Name;
1524       end if;
1525    end Check_Ada_Name;
1526
1527    ----------------------
1528    -- Check_For_Source --
1529    ----------------------
1530
1531    procedure Check_For_Source
1532      (File_Name        : Name_Id;
1533       Path_Name        : Name_Id;
1534       Project          : Project_Id;
1535       Data             : in out Project_Data;
1536       Location         : Source_Ptr;
1537       Language         : Other_Programming_Language;
1538       Suffix           : String;
1539       Naming_Exception : Boolean)
1540    is
1541       Name : String := Get_Name_String (File_Name);
1542       Real_Location : Source_Ptr := Location;
1543
1544    begin
1545       Canonical_Case_File_Name (Name);
1546
1547       --  A file is a source of a language if Naming_Exception is True (case
1548       --  of naming exceptions) or if its file name ends with the suffix.
1549
1550       if Naming_Exception or else
1551         (Name'Length > Suffix'Length and then
1552          Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
1553       then
1554          if Real_Location = No_Location then
1555             Real_Location := Data.Location;
1556          end if;
1557
1558          declare
1559             Path : String := Get_Name_String (Path_Name);
1560
1561             Path_Id     : Name_Id;
1562             --  The path name id (in canonical case)
1563
1564             File_Id     : Name_Id;
1565             --  The file name id (in canonical case)
1566
1567             Obj_Id      : Name_Id;
1568             --  The object file name
1569
1570             Obj_Path_Id : Name_Id;
1571             --  The object path name
1572
1573             Dep_Id      : Name_Id;
1574             --  The dependency file name
1575
1576             Dep_Path_Id : Name_Id;
1577             --  The dependency path name
1578
1579             Dot_Pos     : Natural := 0;
1580             --  Position of the last dot in Name
1581
1582             Source      : Other_Source;
1583             Source_Id   : Other_Source_Id := Data.First_Other_Source;
1584
1585          begin
1586             Canonical_Case_File_Name (Path);
1587
1588             --  Get the file name id
1589
1590             Name_Len := Name'Length;
1591             Name_Buffer (1 .. Name_Len) := Name;
1592             File_Id := Name_Find;
1593
1594             --  Get the path name id
1595
1596             Name_Len := Path'Length;
1597             Name_Buffer (1 .. Name_Len) := Path;
1598             Path_Id := Name_Find;
1599
1600             --  Find the position of the last dot
1601
1602             for J in reverse Name'Range loop
1603                if Name (J) = '.' then
1604                   Dot_Pos := J;
1605                   exit;
1606                end if;
1607             end loop;
1608
1609             if Dot_Pos <= Name'First then
1610                Dot_Pos := Name'Last + 1;
1611             end if;
1612
1613             --  Compute the object file name
1614
1615             Get_Name_String (File_Id);
1616             Name_Len := Dot_Pos - Name'First;
1617
1618             for J in Object_Suffix'Range loop
1619                Name_Len := Name_Len + 1;
1620                Name_Buffer (Name_Len) := Object_Suffix (J);
1621             end loop;
1622
1623             Obj_Id := Name_Find;
1624
1625             --  Compute the object path name
1626
1627             Get_Name_String (Data.Object_Directory);
1628
1629             if Name_Buffer (Name_Len) /= Directory_Separator and then
1630               Name_Buffer (Name_Len) /= '/'
1631             then
1632                Name_Len := Name_Len + 1;
1633                Name_Buffer (Name_Len) := Directory_Separator;
1634             end if;
1635
1636             Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
1637             Obj_Path_Id := Name_Find;
1638
1639             --  Compute the dependency file name
1640
1641             Get_Name_String (File_Id);
1642             Name_Len := Dot_Pos - Name'First + 1;
1643             Name_Buffer (Name_Len) := '.';
1644             Name_Len := Name_Len + 1;
1645             Name_Buffer (Name_Len) := 'd';
1646             Dep_Id := Name_Find;
1647
1648             --  Compute the dependency path name
1649
1650             Get_Name_String (Data.Object_Directory);
1651
1652             if Name_Buffer (Name_Len) /= Directory_Separator and then
1653               Name_Buffer (Name_Len) /= '/'
1654             then
1655                Name_Len := Name_Len + 1;
1656                Name_Buffer (Name_Len) := Directory_Separator;
1657             end if;
1658
1659             Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
1660             Dep_Path_Id := Name_Find;
1661
1662             --  Check if source is already in the list of source for this
1663             --  project: it may have already been specified as a naming
1664             --  exception for the same language or an other language, or they
1665             --  may be two identical file names in different source
1666             --  directories.
1667
1668             while Source_Id /= No_Other_Source loop
1669                Source := Other_Sources.Table (Source_Id);
1670                Source_Id := Source.Next;
1671
1672                if Source.File_Name = File_Id then
1673                   --  Two sources of different languages cannot have the same
1674                   --  file name.
1675
1676                   if Source.Language /= Language then
1677                      Error_Msg_Name_1 := File_Name;
1678                      Error_Msg
1679                        (Project,
1680                         "{ cannot be a source of several languages",
1681                         Real_Location);
1682                      return;
1683
1684                   --  No problem if a file has already been specified as
1685                   --  a naming exception of this language.
1686
1687                   elsif Source.Path_Name = Path_Id then
1688                      --  Reset the naming exception flag, if this is not a
1689                      --  naming exception.
1690
1691                      if not Naming_Exception then
1692                         Other_Sources.Table (Source_Id).Naming_Exception :=
1693                           False;
1694                      end if;
1695
1696                      return;
1697
1698                   --  There are several files with the same names, but the
1699                   --  order of the source directories is known (no /**):
1700                   --  only the first one encountered is kept, the other ones
1701                   --  are ignored.
1702
1703                   elsif Data.Known_Order_Of_Source_Dirs then
1704                      return;
1705
1706                   --  But it is an error if the order of the source directories
1707                   --  is not known.
1708
1709                   else
1710                      Error_Msg_Name_1 := File_Name;
1711                      Error_Msg
1712                        (Project,
1713                         "{ is found in several source directories",
1714                         Real_Location);
1715                      return;
1716                   end if;
1717
1718                --  Two sources with different file names cannot have the same
1719                --  object file name.
1720
1721                elsif Source.Object_Name = Obj_Id then
1722                   Error_Msg_Name_1 := File_Id;
1723                   Error_Msg_Name_2 := Source.File_Name;
1724                   Error_Msg_Name_3 := Obj_Id;
1725                   Error_Msg
1726                        (Project,
1727                         "{ and { have the same object file {",
1728                         Real_Location);
1729                      return;
1730                end if;
1731             end loop;
1732
1733             if Current_Verbosity = High then
1734                Write_Str ("      found ");
1735                Write_Str (Lang_Display_Names (Language).all);
1736                Write_Str (" source """);
1737                Write_Str (Get_Name_String (File_Name));
1738                Write_Line ("""");
1739                Write_Str ("      object path = ");
1740                Write_Line (Get_Name_String (Obj_Path_Id));
1741             end if;
1742
1743             --  Create the Other_Source record
1744             Source :=
1745               (Language         => Language,
1746                File_Name        => File_Id,
1747                Path_Name        => Path_Id,
1748                Source_TS        => File_Stamp (Path_Id),
1749                Object_Name      => Obj_Id,
1750                Object_Path      => Obj_Path_Id,
1751                Object_TS        => File_Stamp (Obj_Path_Id),
1752                Dep_Name         => Dep_Id,
1753                Dep_Path         => Dep_Path_Id,
1754                Dep_TS           => File_Stamp (Dep_Path_Id),
1755                Naming_Exception => Naming_Exception,
1756                Next             => No_Other_Source);
1757
1758             --  And add it to the Other_Sources table
1759
1760             Other_Sources.Increment_Last;
1761             Other_Sources.Table (Other_Sources.Last) := Source;
1762
1763             --  There are sources of languages other than Ada in this project
1764
1765             Data.Other_Sources_Present := True;
1766
1767             --  And there are sources of this language in this project
1768
1769             Data.Languages (Language) := True;
1770
1771             --  Add this source to the list of sources of languages other than
1772             --  Ada of the project.
1773
1774             if Data.First_Other_Source = No_Other_Source then
1775                Data.First_Other_Source := Other_Sources.Last;
1776
1777             else
1778                Other_Sources.Table (Data.Last_Other_Source).Next :=
1779                  Other_Sources.Last;
1780             end if;
1781
1782             Data.Last_Other_Source  := Other_Sources.Last;
1783          end;
1784       end if;
1785    end Check_For_Source;
1786
1787    --------------------------------------
1788    -- Check_Ada_Naming_Scheme_Validity --
1789    --------------------------------------
1790
1791    procedure Check_Ada_Naming_Scheme_Validity
1792      (Project : Project_Id;
1793       Naming  : Naming_Data)
1794    is
1795    begin
1796       --  Only check if we are not using the standard naming scheme
1797
1798       if Naming /= Standard_Naming_Data then
1799          declare
1800             Dot_Replacement       : constant String :=
1801                                      Get_Name_String
1802                                        (Naming.Dot_Replacement);
1803
1804             Spec_Suffix : constant String :=
1805                                      Get_Name_String
1806                                        (Naming.Current_Spec_Suffix);
1807
1808             Body_Suffix : constant String :=
1809                                      Get_Name_String
1810                                        (Naming.Current_Body_Suffix);
1811
1812             Separate_Suffix       : constant String :=
1813                                      Get_Name_String
1814                                        (Naming.Separate_Suffix);
1815
1816          begin
1817             --  Dot_Replacement cannot
1818             --   - be empty
1819             --   - start or end with an alphanumeric
1820             --   - be a single '_'
1821             --   - start with an '_' followed by an alphanumeric
1822             --   - contain a '.' except if it is "."
1823
1824             if Dot_Replacement'Length = 0
1825               or else Is_Alphanumeric
1826                         (Dot_Replacement (Dot_Replacement'First))
1827               or else Is_Alphanumeric
1828                         (Dot_Replacement (Dot_Replacement'Last))
1829               or else (Dot_Replacement (Dot_Replacement'First) = '_'
1830                         and then
1831                         (Dot_Replacement'Length = 1
1832                           or else
1833                            Is_Alphanumeric
1834                              (Dot_Replacement (Dot_Replacement'First + 1))))
1835               or else (Dot_Replacement'Length > 1
1836                          and then
1837                            Index (Source => Dot_Replacement,
1838                                   Pattern => ".") /= 0)
1839             then
1840                Error_Msg
1841                  (Project,
1842                   '"' & Dot_Replacement &
1843                   """ is illegal for Dot_Replacement.",
1844                   Naming.Dot_Repl_Loc);
1845             end if;
1846
1847             --  Suffixes cannot
1848             --   - be empty
1849
1850             if Is_Illegal_Suffix
1851                  (Spec_Suffix, Dot_Replacement = ".")
1852             then
1853                Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1854                Error_Msg
1855                  (Project,
1856                   "{ is illegal for Spec_Suffix",
1857                   Naming.Spec_Suffix_Loc);
1858             end if;
1859
1860             if Is_Illegal_Suffix
1861                  (Body_Suffix, Dot_Replacement = ".")
1862             then
1863                Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1864                Error_Msg
1865                  (Project,
1866                   "{ is illegal for Body_Suffix",
1867                   Naming.Body_Suffix_Loc);
1868             end if;
1869
1870             if Body_Suffix /= Separate_Suffix then
1871                if Is_Illegal_Suffix
1872                     (Separate_Suffix, Dot_Replacement = ".")
1873                then
1874                   Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1875                   Error_Msg
1876                     (Project,
1877                      "{ is illegal for Separate_Suffix",
1878                      Naming.Sep_Suffix_Loc);
1879                end if;
1880             end if;
1881
1882             --  Spec_Suffix cannot have the same termination as
1883             --  Body_Suffix or Separate_Suffix
1884
1885             if Spec_Suffix'Length <= Body_Suffix'Length
1886               and then
1887                 Body_Suffix (Body_Suffix'Last -
1888                              Spec_Suffix'Length + 1 ..
1889                              Body_Suffix'Last) = Spec_Suffix
1890             then
1891                Error_Msg
1892                  (Project,
1893                   "Body_Suffix (""" &
1894                   Body_Suffix &
1895                   """) cannot end with" &
1896                   " Spec_Suffix  (""" &
1897                   Spec_Suffix & """).",
1898                   Naming.Body_Suffix_Loc);
1899             end if;
1900
1901             if Body_Suffix /= Separate_Suffix
1902               and then Spec_Suffix'Length <= Separate_Suffix'Length
1903               and then
1904                 Separate_Suffix
1905                   (Separate_Suffix'Last - Spec_Suffix'Length + 1
1906                     ..
1907                    Separate_Suffix'Last) = Spec_Suffix
1908             then
1909                Error_Msg
1910                  (Project,
1911                   "Separate_Suffix (""" &
1912                   Separate_Suffix &
1913                   """) cannot end with" &
1914                   " Spec_Suffix (""" &
1915                   Spec_Suffix & """).",
1916                   Naming.Sep_Suffix_Loc);
1917             end if;
1918          end;
1919       end if;
1920    end Check_Ada_Naming_Scheme_Validity;
1921
1922    -----------------------------
1923    -- Check_Ada_Naming_Scheme --
1924    -----------------------------
1925
1926    procedure Check_Ada_Naming_Scheme
1927      (Data    : in out Project_Data;
1928       Project : Project_Id)
1929    is
1930       Naming_Id : constant Package_Id :=
1931                     Util.Value_Of (Name_Naming, Data.Decl.Packages);
1932
1933       Naming : Package_Element;
1934
1935       procedure Check_Unit_Names (List : Array_Element_Id);
1936       --  Check that a list of unit names contains only valid names.
1937
1938       ----------------------
1939       -- Check_Unit_Names --
1940       ----------------------
1941
1942       procedure Check_Unit_Names (List : Array_Element_Id) is
1943          Current   : Array_Element_Id := List;
1944          Element   : Array_Element;
1945          Unit_Name : Name_Id;
1946
1947       begin
1948          --  Loop through elements of the string list
1949
1950          while Current /= No_Array_Element loop
1951             Element := Array_Elements.Table (Current);
1952
1953             --  Put file name in canonical case
1954
1955             Get_Name_String (Element.Value.Value);
1956             Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1957             Element.Value.Value := Name_Find;
1958
1959             --  Check that it contains a valid unit name
1960
1961             Get_Name_String (Element.Index);
1962             Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1963
1964             if Unit_Name = No_Name then
1965                Err_Vars.Error_Msg_Name_1 := Element.Index;
1966                Error_Msg
1967                  (Project,
1968                   "{ is not a valid unit name.",
1969                   Element.Value.Location);
1970
1971             else
1972                if Current_Verbosity = High then
1973                   Write_Str ("    Unit (""");
1974                   Write_Str (Get_Name_String (Unit_Name));
1975                   Write_Line (""")");
1976                end if;
1977
1978                Element.Index := Unit_Name;
1979                Array_Elements.Table (Current) := Element;
1980             end if;
1981
1982             Current := Element.Next;
1983          end loop;
1984       end Check_Unit_Names;
1985
1986    --  Start of processing for Check_Ada_Naming_Scheme
1987
1988    begin
1989       --  If there is a package Naming, we will put in Data.Naming what is in
1990       --  this package Naming.
1991
1992       if Naming_Id /= No_Package then
1993          Naming := Packages.Table (Naming_Id);
1994
1995          if Current_Verbosity = High then
1996             Write_Line ("Checking ""Naming"" for Ada.");
1997          end if;
1998
1999          declare
2000             Bodies : constant Array_Element_Id :=
2001                        Util.Value_Of (Name_Body, Naming.Decl.Arrays);
2002
2003             Specs : constant Array_Element_Id :=
2004                       Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
2005
2006          begin
2007             if Bodies /= No_Array_Element then
2008
2009                --  We have elements in the array Body_Part
2010
2011                if Current_Verbosity = High then
2012                   Write_Line ("Found Bodies.");
2013                end if;
2014
2015                Data.Naming.Bodies := Bodies;
2016                Check_Unit_Names (Bodies);
2017
2018             else
2019                if Current_Verbosity = High then
2020                   Write_Line ("No Bodies.");
2021                end if;
2022             end if;
2023
2024             if Specs /= No_Array_Element then
2025
2026                --  We have elements in the array Specs
2027
2028                if Current_Verbosity = High then
2029                   Write_Line ("Found Specs.");
2030                end if;
2031
2032                Data.Naming.Specs := Specs;
2033                Check_Unit_Names (Specs);
2034
2035             else
2036                if Current_Verbosity = High then
2037                   Write_Line ("No Specs.");
2038                end if;
2039             end if;
2040          end;
2041
2042          --  We are now checking if variables Dot_Replacement, Casing,
2043          --  Spec_Suffix, Body_Suffix and/or Separate_Suffix
2044          --  exist.
2045
2046          --  For each variable, if it does not exist, we do nothing,
2047          --  because we already have the default.
2048
2049          --  Check Dot_Replacement
2050
2051          declare
2052             Dot_Replacement : constant Variable_Value :=
2053                                 Util.Value_Of
2054                                   (Name_Dot_Replacement,
2055                                    Naming.Decl.Attributes);
2056
2057          begin
2058             pragma Assert (Dot_Replacement.Kind = Single,
2059                            "Dot_Replacement is not a single string");
2060
2061             if not Dot_Replacement.Default then
2062                Get_Name_String (Dot_Replacement.Value);
2063
2064                if Name_Len = 0 then
2065                   Error_Msg
2066                     (Project,
2067                      "Dot_Replacement cannot be empty",
2068                      Dot_Replacement.Location);
2069
2070                else
2071                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2072                   Data.Naming.Dot_Replacement := Name_Find;
2073                   Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2074                end if;
2075             end if;
2076          end;
2077
2078          if Current_Verbosity = High then
2079             Write_Str  ("  Dot_Replacement = """);
2080             Write_Str  (Get_Name_String (Data.Naming.Dot_Replacement));
2081             Write_Char ('"');
2082             Write_Eol;
2083          end if;
2084
2085          --  Check Casing
2086
2087          declare
2088             Casing_String : constant Variable_Value :=
2089                               Util.Value_Of
2090                                 (Name_Casing, Naming.Decl.Attributes);
2091
2092          begin
2093             pragma Assert (Casing_String.Kind = Single,
2094                            "Casing is not a single string");
2095
2096             if not Casing_String.Default then
2097                declare
2098                   Casing_Image : constant String :=
2099                                    Get_Name_String (Casing_String.Value);
2100                begin
2101                   declare
2102                      Casing_Value : constant Casing_Type :=
2103                                       Value (Casing_Image);
2104                   begin
2105                      --  Ignore Casing on platforms where file names are
2106                      --  case-insensitive.
2107
2108                      if not File_Names_Case_Sensitive then
2109                         Data.Naming.Casing := All_Lower_Case;
2110
2111                      else
2112                         Data.Naming.Casing := Casing_Value;
2113                      end if;
2114                   end;
2115
2116                exception
2117                   when Constraint_Error =>
2118                      if Casing_Image'Length = 0 then
2119                         Error_Msg
2120                           (Project,
2121                            "Casing cannot be an empty string",
2122                            Casing_String.Location);
2123
2124                      else
2125                         Name_Len := Casing_Image'Length;
2126                         Name_Buffer (1 .. Name_Len) := Casing_Image;
2127                         Err_Vars.Error_Msg_Name_1 := Name_Find;
2128                         Error_Msg
2129                           (Project,
2130                            "{ is not a correct Casing",
2131                            Casing_String.Location);
2132                      end if;
2133                end;
2134             end if;
2135          end;
2136
2137          if Current_Verbosity = High then
2138             Write_Str  ("  Casing = ");
2139             Write_Str  (Image (Data.Naming.Casing));
2140             Write_Char ('.');
2141             Write_Eol;
2142          end if;
2143
2144          --  Check Spec_Suffix
2145
2146          declare
2147             Ada_Spec_Suffix : constant Variable_Value :=
2148                                 Prj.Util.Value_Of
2149                                   (Index     => Name_Ada,
2150                                    Src_Index => 0,
2151                                    In_Array  => Data.Naming.Spec_Suffix);
2152
2153          begin
2154             if Ada_Spec_Suffix.Kind = Single
2155               and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2156             then
2157                Get_Name_String (Ada_Spec_Suffix.Value);
2158                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2159                Data.Naming.Current_Spec_Suffix := Name_Find;
2160                Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2161
2162             else
2163                Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2164             end if;
2165          end;
2166
2167          if Current_Verbosity = High then
2168             Write_Str  ("  Spec_Suffix = """);
2169             Write_Str  (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2170             Write_Char ('"');
2171             Write_Eol;
2172          end if;
2173
2174          --  Check Body_Suffix
2175
2176          declare
2177             Ada_Body_Suffix : constant Variable_Value :=
2178               Prj.Util.Value_Of
2179                 (Index     => Name_Ada,
2180                  Src_Index => 0,
2181                  In_Array  => Data.Naming.Body_Suffix);
2182
2183          begin
2184             if Ada_Body_Suffix.Kind = Single
2185               and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2186             then
2187                Get_Name_String (Ada_Body_Suffix.Value);
2188                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2189                Data.Naming.Current_Body_Suffix := Name_Find;
2190                Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2191
2192             else
2193                Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2194             end if;
2195          end;
2196
2197          if Current_Verbosity = High then
2198             Write_Str  ("  Body_Suffix = """);
2199             Write_Str  (Get_Name_String (Data.Naming.Current_Body_Suffix));
2200             Write_Char ('"');
2201             Write_Eol;
2202          end if;
2203
2204          --  Check Separate_Suffix
2205
2206          declare
2207             Ada_Sep_Suffix : constant Variable_Value :=
2208                                Prj.Util.Value_Of
2209                                  (Variable_Name => Name_Separate_Suffix,
2210                                   In_Variables  => Naming.Decl.Attributes);
2211
2212          begin
2213             if Ada_Sep_Suffix.Default then
2214                Data.Naming.Separate_Suffix :=
2215                  Data.Naming.Current_Body_Suffix;
2216
2217             else
2218                Get_Name_String (Ada_Sep_Suffix.Value);
2219
2220                if Name_Len = 0 then
2221                   Error_Msg
2222                     (Project,
2223                      "Separate_Suffix cannot be empty",
2224                      Ada_Sep_Suffix.Location);
2225
2226                else
2227                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2228                   Data.Naming.Separate_Suffix := Name_Find;
2229                   Data.Naming.Sep_Suffix_Loc  := Ada_Sep_Suffix.Location;
2230                end if;
2231             end if;
2232          end;
2233
2234          if Current_Verbosity = High then
2235             Write_Str  ("  Separate_Suffix = """);
2236             Write_Str  (Get_Name_String (Data.Naming.Separate_Suffix));
2237             Write_Char ('"');
2238             Write_Eol;
2239          end if;
2240
2241          --  Check if Data.Naming is valid
2242
2243          Check_Ada_Naming_Scheme_Validity (Project, Data.Naming);
2244
2245       else
2246          Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2247          Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2248          Data.Naming.Separate_Suffix     := Default_Ada_Body_Suffix;
2249       end if;
2250    end Check_Ada_Naming_Scheme;
2251
2252    -------------------
2253    -- Check_Project --
2254    -------------------
2255
2256    function Check_Project
2257      (P            : Project_Id;
2258       Root_Project : Project_Id;
2259       Extending    : Boolean) return Boolean
2260    is
2261    begin
2262       if P = Root_Project then
2263          return True;
2264
2265       elsif Extending then
2266          declare
2267             Data : Project_Data := Projects.Table (Root_Project);
2268
2269          begin
2270             while Data.Extends /= No_Project loop
2271                if P = Data.Extends then
2272                   return True;
2273                end if;
2274
2275                Data := Projects.Table (Data.Extends);
2276             end loop;
2277          end;
2278       end if;
2279
2280       return False;
2281    end Check_Project;
2282
2283    ----------------------------
2284    -- Compute_Directory_Last --
2285    ----------------------------
2286
2287    function Compute_Directory_Last (Dir : String) return Natural is
2288    begin
2289       if Dir'Length > 1
2290         and then (Dir (Dir'Last - 1) = Directory_Separator
2291                   or else Dir (Dir'Last - 1) = '/')
2292       then
2293          return Dir'Last - 1;
2294       else
2295          return Dir'Last;
2296       end if;
2297    end Compute_Directory_Last;
2298
2299    ---------------
2300    -- Error_Msg --
2301    ---------------
2302
2303    procedure Error_Msg
2304      (Project       : Project_Id;
2305       Msg           : String;
2306       Flag_Location : Source_Ptr)
2307    is
2308       Error_Buffer : String (1 .. 5_000);
2309       Error_Last   : Natural := 0;
2310       Msg_Name     : Natural := 0;
2311       First        : Positive := Msg'First;
2312
2313       procedure Add (C : Character);
2314       --  Add a character to the buffer
2315
2316       procedure Add (S : String);
2317       --  Add a string to the buffer
2318
2319       procedure Add (Id : Name_Id);
2320       --  Add a name to the buffer
2321
2322       ---------
2323       -- Add --
2324       ---------
2325
2326       procedure Add (C : Character) is
2327       begin
2328          Error_Last := Error_Last + 1;
2329          Error_Buffer (Error_Last) := C;
2330       end Add;
2331
2332       procedure Add (S : String) is
2333       begin
2334          Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2335          Error_Last := Error_Last + S'Length;
2336       end Add;
2337
2338       procedure Add (Id : Name_Id) is
2339       begin
2340          Get_Name_String (Id);
2341          Add (Name_Buffer (1 .. Name_Len));
2342       end Add;
2343
2344    --  Start of processing for Error_Msg
2345
2346    begin
2347       if Error_Report = null then
2348          Prj.Err.Error_Msg (Msg, Flag_Location);
2349          return;
2350       end if;
2351
2352       if Msg (First) = '\' then
2353
2354          --  Continuation character, ignore.
2355
2356          First := First + 1;
2357
2358       elsif Msg (First) = '?' then
2359
2360          --  Warning character. It is always the first one in this package
2361
2362          First := First + 1;
2363          Add ("Warning: ");
2364       end if;
2365
2366       for Index in First .. Msg'Last loop
2367          if Msg (Index) = '{' or else Msg (Index) = '%' then
2368
2369             --  Include a name between double quotes.
2370
2371             Msg_Name := Msg_Name + 1;
2372             Add ('"');
2373
2374             case Msg_Name is
2375                when 1 => Add (Err_Vars.Error_Msg_Name_1);
2376                when 2 => Add (Err_Vars.Error_Msg_Name_2);
2377                when 3 => Add (Err_Vars.Error_Msg_Name_3);
2378
2379                when others => null;
2380             end case;
2381
2382             Add ('"');
2383
2384          else
2385             Add (Msg (Index));
2386          end if;
2387
2388       end loop;
2389
2390       Error_Report (Error_Buffer (1 .. Error_Last), Project);
2391    end Error_Msg;
2392
2393    ------------------
2394    -- Find_Sources --
2395    ------------------
2396
2397    procedure Find_Sources
2398      (Project      : Project_Id;
2399       Data         : in out Project_Data;
2400       For_Language : Programming_Language;
2401       Follow_Links : Boolean := False)
2402    is
2403       Source_Dir      : String_List_Id := Data.Source_Dirs;
2404       Element         : String_Element;
2405       Dir             : Dir_Type;
2406       Current_Source  : String_List_Id := Nil_String;
2407       Source_Recorded : Boolean := False;
2408
2409    begin
2410       if Current_Verbosity = High then
2411          Write_Line ("Looking for sources:");
2412       end if;
2413
2414       --  For each subdirectory
2415
2416       while Source_Dir /= Nil_String loop
2417          begin
2418             Source_Recorded := False;
2419             Element := String_Elements.Table (Source_Dir);
2420             if Element.Value /= No_Name then
2421                Get_Name_String (Element.Display_Value);
2422
2423                declare
2424                   Source_Directory : constant String :=
2425                     Name_Buffer (1 .. Name_Len) & Directory_Separator;
2426                   Dir_Last  : constant Natural :=
2427                      Compute_Directory_Last (Source_Directory);
2428
2429                begin
2430                   if Current_Verbosity = High then
2431                      Write_Str ("Source_Dir = ");
2432                      Write_Line (Source_Directory);
2433                   end if;
2434
2435                   --  We look to every entry in the source directory
2436
2437                   Open (Dir, Source_Directory
2438                                (Source_Directory'First .. Dir_Last));
2439
2440                   loop
2441                      Read (Dir, Name_Buffer, Name_Len);
2442
2443                      if Current_Verbosity = High then
2444                         Write_Str  ("   Checking ");
2445                         Write_Line (Name_Buffer (1 .. Name_Len));
2446                      end if;
2447
2448                      exit when Name_Len = 0;
2449
2450                      declare
2451                         File_Name : constant Name_Id := Name_Find;
2452                         Path      : constant String :=
2453                           Normalize_Pathname
2454                             (Name      => Name_Buffer (1 .. Name_Len),
2455                              Directory => Source_Directory
2456                                (Source_Directory'First .. Dir_Last),
2457                              Resolve_Links => Follow_Links,
2458                              Case_Sensitive => True);
2459                         Path_Name : Name_Id;
2460
2461                      begin
2462                         Name_Len := Path'Length;
2463                         Name_Buffer (1 .. Name_Len) := Path;
2464                         Path_Name := Name_Find;
2465
2466                         if For_Language = Lang_Ada then
2467                            --  We attempt to register it as a source.
2468                            --  However, there is no error if the file
2469                            --  does not contain a valid source.
2470                            --  But there is an error if we have a
2471                            --  duplicate unit name.
2472
2473                            Record_Ada_Source
2474                              (File_Name       => File_Name,
2475                               Path_Name       => Path_Name,
2476                               Project         => Project,
2477                               Data            => Data,
2478                               Location        => No_Location,
2479                               Current_Source  => Current_Source,
2480                               Source_Recorded => Source_Recorded,
2481                               Follow_Links    => Follow_Links);
2482
2483                         else
2484                            Check_For_Source
2485                              (File_Name        => File_Name,
2486                               Path_Name        => Path_Name,
2487                               Project          => Project,
2488                               Data             => Data,
2489                               Location         => No_Location,
2490                               Language         => For_Language,
2491                               Suffix           =>
2492                                 Get_Name_String
2493                                   (Data.Impl_Suffixes (For_Language)),
2494                               Naming_Exception => False);
2495                         end if;
2496                      end;
2497                   end loop;
2498
2499                   Close (Dir);
2500                end;
2501             end if;
2502
2503          exception
2504             when Directory_Error =>
2505                null;
2506          end;
2507
2508          if Source_Recorded then
2509             String_Elements.Table (Source_Dir).Flag := True;
2510          end if;
2511
2512          Source_Dir := Element.Next;
2513       end loop;
2514
2515       if Current_Verbosity = High then
2516          Write_Line ("end Looking for sources.");
2517       end if;
2518
2519       if For_Language = Lang_Ada then
2520          --  If we have looked for sources and found none, then
2521          --  it is an error, except if it is an extending project.
2522          --  If a non extending project is not supposed to contain
2523          --  any source, then we never call Find_Sources.
2524
2525          if Current_Source /= Nil_String then
2526             Data.Ada_Sources_Present := True;
2527
2528          elsif Data.Extends = No_Project then
2529             Error_Msg
2530               (Project,
2531                "there are no Ada sources in this project",
2532                Data.Location);
2533          end if;
2534       end if;
2535    end Find_Sources;
2536
2537    --------------------------------
2538    -- Free_Ada_Naming_Exceptions --
2539    --------------------------------
2540
2541    procedure Free_Ada_Naming_Exceptions is
2542    begin
2543       Ada_Naming_Exception_Table.Set_Last (0);
2544       Ada_Naming_Exceptions.Reset;
2545       Reverse_Ada_Naming_Exceptions.Reset;
2546    end Free_Ada_Naming_Exceptions;
2547
2548    ---------------
2549    -- Get_Mains --
2550    ---------------
2551
2552    procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2553       Mains : constant Variable_Value :=
2554         Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2555
2556    begin
2557       Data.Mains := Mains.Values;
2558
2559       --  If no Mains were specified, and if we are an extending
2560       --  project, inherit the Mains from the project we are extending.
2561
2562       if Mains.Default then
2563          if Data.Extends /= No_Project then
2564             Data.Mains := Projects.Table (Data.Extends).Mains;
2565          end if;
2566
2567       --  In a library project file, Main cannot be specified
2568
2569       elsif Data.Library then
2570          Error_Msg
2571            (Project,
2572             "a library project file cannot have Main specified",
2573             Mains.Location);
2574       end if;
2575    end Get_Mains;
2576
2577    ---------------------------
2578    -- Get_Sources_From_File --
2579    ---------------------------
2580
2581    procedure Get_Sources_From_File
2582      (Path     : String;
2583       Location : Source_Ptr;
2584       Project  : Project_Id)
2585    is
2586       File           : Prj.Util.Text_File;
2587       Line           : String (1 .. 250);
2588       Last           : Natural;
2589       Source_Name    : Name_Id;
2590
2591    begin
2592       Source_Names.Reset;
2593
2594       if Current_Verbosity = High then
2595          Write_Str  ("Opening """);
2596          Write_Str  (Path);
2597          Write_Line (""".");
2598       end if;
2599
2600       --  Open the file
2601
2602       Prj.Util.Open (File, Path);
2603
2604       if not Prj.Util.Is_Valid (File) then
2605          Error_Msg (Project, "file does not exist", Location);
2606       else
2607          --  Read the lines one by one
2608
2609          while not Prj.Util.End_Of_File (File) loop
2610             Prj.Util.Get_Line (File, Line, Last);
2611
2612             --  A non empty, non comment line should contain a file name
2613
2614             if Last /= 0
2615               and then (Last = 1 or else Line (1 .. 2) /= "--")
2616             then
2617                --  ??? we should check that there is no directory information
2618
2619                Name_Len := Last;
2620                Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2621                Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2622                Source_Name := Name_Find;
2623                Source_Names.Set
2624                  (K => Source_Name,
2625                   E =>
2626                     (Name     => Source_Name,
2627                      Location => Location,
2628                      Found    => False));
2629             end if;
2630          end loop;
2631
2632          Prj.Util.Close (File);
2633
2634       end if;
2635    end Get_Sources_From_File;
2636
2637    --------------
2638    -- Get_Unit --
2639    --------------
2640
2641    procedure Get_Unit
2642      (Canonical_File_Name : Name_Id;
2643       Naming              : Naming_Data;
2644       Exception_Id        : out Ada_Naming_Exception_Id;
2645       Unit_Name           : out Name_Id;
2646       Unit_Kind           : out Spec_Or_Body;
2647       Needs_Pragma        : out Boolean)
2648    is
2649       Info_Id  : Ada_Naming_Exception_Id
2650         := Ada_Naming_Exceptions.Get (Canonical_File_Name);
2651       VMS_Name : Name_Id;
2652
2653    begin
2654       if Info_Id = No_Ada_Naming_Exception then
2655          if Hostparm.OpenVMS then
2656             VMS_Name := Canonical_File_Name;
2657             Get_Name_String (VMS_Name);
2658
2659             if Name_Buffer (Name_Len) = '.' then
2660                Name_Len := Name_Len - 1;
2661                VMS_Name := Name_Find;
2662             end if;
2663
2664             Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
2665          end if;
2666
2667       end if;
2668
2669       if Info_Id /= No_Ada_Naming_Exception then
2670          Exception_Id := Info_Id;
2671          Unit_Name := No_Name;
2672          Unit_Kind := Specification;
2673          Needs_Pragma := True;
2674          return;
2675       end if;
2676
2677       Needs_Pragma := False;
2678       Exception_Id := No_Ada_Naming_Exception;
2679
2680       Get_Name_String (Canonical_File_Name);
2681
2682       declare
2683          File          : String := Name_Buffer (1 .. Name_Len);
2684          First         : constant Positive := File'First;
2685          Last          : Natural           := File'Last;
2686          Standard_GNAT : Boolean;
2687
2688       begin
2689          Standard_GNAT :=
2690            Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2691              and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2692
2693          --  Check if the end of the file name is Specification_Append
2694
2695          Get_Name_String (Naming.Current_Spec_Suffix);
2696
2697          if File'Length > Name_Len
2698            and then File (Last - Name_Len + 1 .. Last) =
2699                                                 Name_Buffer (1 .. Name_Len)
2700          then
2701             --  We have a spec
2702
2703             Unit_Kind := Specification;
2704             Last := Last - Name_Len;
2705
2706             if Current_Verbosity = High then
2707                Write_Str  ("   Specification: ");
2708                Write_Line (File (First .. Last));
2709             end if;
2710
2711          else
2712             Get_Name_String (Naming.Current_Body_Suffix);
2713
2714             --  Check if the end of the file name is Body_Append
2715
2716             if File'Length > Name_Len
2717               and then File (Last - Name_Len + 1 .. Last) =
2718                                                 Name_Buffer (1 .. Name_Len)
2719             then
2720                --  We have a body
2721
2722                Unit_Kind := Body_Part;
2723                Last := Last - Name_Len;
2724
2725                if Current_Verbosity = High then
2726                   Write_Str  ("   Body: ");
2727                   Write_Line (File (First .. Last));
2728                end if;
2729
2730             elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2731                Get_Name_String (Naming.Separate_Suffix);
2732
2733                --  Check if the end of the file name is Separate_Append
2734
2735                if File'Length > Name_Len
2736                  and then File (Last - Name_Len + 1 .. Last) =
2737                                                 Name_Buffer (1 .. Name_Len)
2738                then
2739                   --  We have a separate (a body)
2740
2741                   Unit_Kind := Body_Part;
2742                   Last := Last - Name_Len;
2743
2744                   if Current_Verbosity = High then
2745                      Write_Str  ("   Separate: ");
2746                      Write_Line (File (First .. Last));
2747                   end if;
2748
2749                else
2750                   Last := 0;
2751                end if;
2752
2753             else
2754                Last := 0;
2755             end if;
2756          end if;
2757
2758          if Last = 0 then
2759
2760             --  This is not a source file
2761
2762             Unit_Name := No_Name;
2763             Unit_Kind := Specification;
2764
2765             if Current_Verbosity = High then
2766                Write_Line ("   Not a valid file name.");
2767             end if;
2768
2769             return;
2770          end if;
2771
2772          Get_Name_String (Naming.Dot_Replacement);
2773          Standard_GNAT :=
2774            Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2775
2776          if Name_Buffer (1 .. Name_Len) /= "." then
2777
2778             --  If Dot_Replacement is not a single dot,
2779             --  then there should not be any dot in the name.
2780
2781             for Index in First .. Last loop
2782                if File (Index) = '.' then
2783                   if Current_Verbosity = High then
2784                      Write_Line
2785                        ("   Not a valid file name (some dot not replaced).");
2786                   end if;
2787
2788                   Unit_Name := No_Name;
2789                   return;
2790
2791                end if;
2792             end loop;
2793
2794             --  Replace the substring Dot_Replacement with dots
2795
2796             declare
2797                Index : Positive := First;
2798
2799             begin
2800                while Index <= Last - Name_Len + 1 loop
2801
2802                   if File (Index .. Index + Name_Len - 1) =
2803                     Name_Buffer (1 .. Name_Len)
2804                   then
2805                      File (Index) := '.';
2806
2807                      if Name_Len > 1 and then Index < Last then
2808                         File (Index + 1 .. Last - Name_Len + 1) :=
2809                           File (Index + Name_Len .. Last);
2810                      end if;
2811
2812                      Last := Last - Name_Len + 1;
2813                   end if;
2814
2815                   Index := Index + 1;
2816                end loop;
2817             end;
2818          end if;
2819
2820          --  Check if the casing is right
2821
2822          declare
2823             Src : String := File (First .. Last);
2824
2825          begin
2826             case Naming.Casing is
2827                when All_Lower_Case =>
2828                   Fixed.Translate
2829                     (Source  => Src,
2830                      Mapping => Lower_Case_Map);
2831
2832                when All_Upper_Case =>
2833                   Fixed.Translate
2834                     (Source  => Src,
2835                      Mapping => Upper_Case_Map);
2836
2837                when Mixed_Case | Unknown =>
2838                   null;
2839             end case;
2840
2841             if Src /= File (First .. Last) then
2842                if Current_Verbosity = High then
2843                   Write_Line ("   Not a valid file name (casing).");
2844                end if;
2845
2846                Unit_Name := No_Name;
2847                return;
2848             end if;
2849
2850             --  We put the name in lower case
2851
2852             Fixed.Translate
2853               (Source  => Src,
2854                Mapping => Lower_Case_Map);
2855
2856             --  In the standard GNAT naming scheme, check for special cases:
2857             --  children or separates of A, G, I or S, and run time sources.
2858
2859             if Standard_GNAT and then Src'Length >= 3 then
2860                declare
2861                   S1 : constant Character := Src (Src'First);
2862                   S2 : constant Character := Src (Src'First + 1);
2863
2864                begin
2865                   if S1 = 'a' or else S1 = 'g'
2866                     or else S1 = 'i' or else S1 = 's'
2867                   then
2868                      --  Children or separates of packages A, G, I or S
2869
2870                      if (Hostparm.OpenVMS and then S2 = '$')
2871                        or else (not Hostparm.OpenVMS and then S2 = '~')
2872                      then
2873                         Src (Src'First + 1) := '.';
2874
2875                      --  If it is potentially a run time source, disable
2876                      --  filling of the mapping file to avoid warnings.
2877
2878                      elsif S2 = '.' then
2879                         Set_Mapping_File_Initial_State_To_Empty;
2880                      end if;
2881
2882                   end if;
2883                end;
2884             end if;
2885
2886             if Current_Verbosity = High then
2887                Write_Str  ("      ");
2888                Write_Line (Src);
2889             end if;
2890
2891             --  Now, we check if this name is a valid unit name
2892
2893             Check_Ada_Name (Name => Src, Unit => Unit_Name);
2894          end;
2895
2896       end;
2897    end Get_Unit;
2898
2899    ----------
2900    -- Hash --
2901    ----------
2902
2903    function Hash (Unit : Unit_Info) return Header_Num is
2904    begin
2905       return Header_Num (Unit.Unit mod 2048);
2906    end Hash;
2907
2908    -----------------------
2909    -- Is_Illegal_Suffix --
2910    -----------------------
2911
2912    function Is_Illegal_Suffix
2913      (Suffix                          : String;
2914       Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2915    is
2916    begin
2917       if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2918          return True;
2919       end if;
2920
2921       --  If dot replacement is a single dot, and first character of
2922       --  suffix is also a dot
2923
2924       if Dot_Replacement_Is_A_Single_Dot
2925         and then Suffix (Suffix'First) = '.'
2926       then
2927          for Index in Suffix'First + 1 .. Suffix'Last loop
2928
2929             --  If there is another dot
2930
2931             if Suffix (Index) = '.' then
2932
2933                --  It is illegal to have a letter following the initial dot
2934
2935                return Is_Letter (Suffix (Suffix'First + 1));
2936             end if;
2937          end loop;
2938       end if;
2939
2940       --  Everything is OK
2941
2942       return False;
2943    end Is_Illegal_Suffix;
2944
2945    --------------------------------
2946    -- Language_Independent_Check --
2947    --------------------------------
2948
2949    procedure Language_Independent_Check
2950      (Project      : Project_Id;
2951       Report_Error : Put_Line_Access)
2952    is
2953       Last_Source_Dir : String_List_Id  := Nil_String;
2954       Data            : Project_Data    := Projects.Table (Project);
2955
2956       procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2957       --  Find one or several source directories, and add them
2958       --  to the list of source directories of the project.
2959
2960       ----------------------
2961       -- Find_Source_Dirs --
2962       ----------------------
2963
2964       procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2965          Directory : constant String := Get_Name_String (From);
2966          Element   : String_Element;
2967
2968          procedure Recursive_Find_Dirs (Path : Name_Id);
2969          --  Find all the subdirectories (recursively) of Path and add them
2970          --  to the list of source directories of the project.
2971
2972          -------------------------
2973          -- Recursive_Find_Dirs --
2974          -------------------------
2975
2976          procedure Recursive_Find_Dirs (Path : Name_Id) is
2977             Dir      : Dir_Type;
2978             Name     : String (1 .. 250);
2979             Last     : Natural;
2980             List     : String_List_Id := Data.Source_Dirs;
2981             Element  : String_Element;
2982             Found    : Boolean := False;
2983
2984             Non_Canonical_Path : Name_Id := No_Name;
2985             Canonical_Path     : Name_Id := No_Name;
2986
2987             The_Path : constant String :=
2988                          Normalize_Pathname (Get_Name_String (Path)) &
2989                          Directory_Separator;
2990
2991             The_Path_Last : constant Natural :=
2992                               Compute_Directory_Last (The_Path);
2993
2994          begin
2995             Name_Len := The_Path_Last - The_Path'First + 1;
2996             Name_Buffer (1 .. Name_Len) :=
2997               The_Path (The_Path'First .. The_Path_Last);
2998             Non_Canonical_Path := Name_Find;
2999             Get_Name_String (Non_Canonical_Path);
3000             Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3001             Canonical_Path := Name_Find;
3002
3003             --  To avoid processing the same directory several times, check
3004             --  if the directory is already in Recursive_Dirs. If it is,
3005             --  then there is nothing to do, just return. If it is not, put
3006             --  it there and continue recursive processing.
3007
3008             if Recursive_Dirs.Get (Canonical_Path) then
3009                return;
3010
3011             else
3012                Recursive_Dirs.Set (Canonical_Path, True);
3013             end if;
3014
3015             --  Check if directory is already in list
3016
3017             while List /= Nil_String loop
3018                Element := String_Elements.Table (List);
3019
3020                if Element.Value /= No_Name then
3021                   Found := Element.Value = Canonical_Path;
3022                   exit when Found;
3023                end if;
3024
3025                List := Element.Next;
3026             end loop;
3027
3028             --  If directory is not already in list, put it there
3029
3030             if not Found then
3031                if Current_Verbosity = High then
3032                   Write_Str  ("   ");
3033                   Write_Line (The_Path (The_Path'First .. The_Path_Last));
3034                end if;
3035
3036                String_Elements.Increment_Last;
3037                Element :=
3038                  (Value    => Canonical_Path,
3039                   Display_Value => Non_Canonical_Path,
3040                   Location => No_Location,
3041                   Flag     => False,
3042                   Next     => Nil_String,
3043                   Index    => 0);
3044
3045                --  Case of first source directory
3046
3047                if Last_Source_Dir = Nil_String then
3048                   Data.Source_Dirs := String_Elements.Last;
3049
3050                   --  Here we already have source directories.
3051
3052                else
3053                   --  Link the previous last to the new one
3054
3055                   String_Elements.Table (Last_Source_Dir).Next :=
3056                     String_Elements.Last;
3057                end if;
3058
3059                --  And register this source directory as the new last
3060
3061                Last_Source_Dir  := String_Elements.Last;
3062                String_Elements.Table (Last_Source_Dir) := Element;
3063             end if;
3064
3065             --  Now look for subdirectories. We do that even when this
3066             --  directory is already in the list, because some of its
3067             --  subdirectories may not be in the list yet.
3068
3069             Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3070
3071             loop
3072                Read (Dir, Name, Last);
3073                exit when Last = 0;
3074
3075                if Name (1 .. Last) /= "."
3076                  and then Name (1 .. Last) /= ".."
3077                then
3078                   --  Avoid . and ..
3079
3080                   if Current_Verbosity = High then
3081                      Write_Str  ("   Checking ");
3082                      Write_Line (Name (1 .. Last));
3083                   end if;
3084
3085                   declare
3086                      Path_Name : constant String :=
3087                                    Normalize_Pathname
3088                                      (Name      => Name (1 .. Last),
3089                                       Directory =>
3090                                         The_Path
3091                                           (The_Path'First .. The_Path_Last),
3092                                       Resolve_Links  => False,
3093                                       Case_Sensitive => True);
3094
3095                   begin
3096                      if Is_Directory (Path_Name) then
3097
3098                         --  We have found a new subdirectory, call self
3099
3100                         Name_Len := Path_Name'Length;
3101                         Name_Buffer (1 .. Name_Len) := Path_Name;
3102                         Recursive_Find_Dirs (Name_Find);
3103                      end if;
3104                   end;
3105                end if;
3106             end loop;
3107
3108             Close (Dir);
3109
3110          exception
3111             when Directory_Error =>
3112                null;
3113          end Recursive_Find_Dirs;
3114
3115       --  Start of processing for Find_Source_Dirs
3116
3117       begin
3118          if Current_Verbosity = High then
3119             Write_Str ("Find_Source_Dirs (""");
3120             Write_Str (Directory);
3121             Write_Line (""")");
3122          end if;
3123
3124          --  First, check if we are looking for a directory tree,
3125          --  indicated by "/**" at the end.
3126
3127          if Directory'Length >= 3
3128            and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3129            and then (Directory (Directory'Last - 2) = '/'
3130                        or else
3131                      Directory (Directory'Last - 2) = Directory_Separator)
3132          then
3133             Data.Known_Order_Of_Source_Dirs := False;
3134
3135             Name_Len := Directory'Length - 3;
3136
3137             if Name_Len = 0 then
3138
3139                --  This is the case of "/**": all directories
3140                --  in the file system.
3141
3142                Name_Len := 1;
3143                Name_Buffer (1) := Directory (Directory'First);
3144
3145             else
3146                Name_Buffer (1 .. Name_Len) :=
3147                  Directory (Directory'First .. Directory'Last - 3);
3148             end if;
3149
3150             if Current_Verbosity = High then
3151                Write_Str ("Looking for all subdirectories of """);
3152                Write_Str (Name_Buffer (1 .. Name_Len));
3153                Write_Line ("""");
3154             end if;
3155
3156             declare
3157                Base_Dir : constant Name_Id := Name_Find;
3158                Root_Dir : constant String :=
3159                             Normalize_Pathname
3160                               (Name      => Get_Name_String (Base_Dir),
3161                                Directory =>
3162                                  Get_Name_String (Data.Display_Directory),
3163                                Resolve_Links  => False,
3164                                Case_Sensitive => True);
3165
3166             begin
3167                if Root_Dir'Length = 0 then
3168                   Err_Vars.Error_Msg_Name_1 := Base_Dir;
3169
3170                   if Location = No_Location then
3171                      Error_Msg
3172                        (Project,
3173                         "{ is not a valid directory.",
3174                         Data.Location);
3175                   else
3176                      Error_Msg
3177                        (Project,
3178                         "{ is not a valid directory.",
3179                         Location);
3180                   end if;
3181
3182                else
3183                   --  We have an existing directory,
3184                   --  we register it and all of its subdirectories.
3185
3186                   if Current_Verbosity = High then
3187                      Write_Line ("Looking for source directories:");
3188                   end if;
3189
3190                   Name_Len := Root_Dir'Length;
3191                   Name_Buffer (1 .. Name_Len) := Root_Dir;
3192                   Recursive_Find_Dirs (Name_Find);
3193
3194                   if Current_Verbosity = High then
3195                      Write_Line ("End of looking for source directories.");
3196                   end if;
3197                end if;
3198             end;
3199
3200          --  We have a single directory
3201
3202          else
3203             declare
3204                Path_Name : Name_Id;
3205                Display_Path_Name : Name_Id;
3206             begin
3207                Locate_Directory
3208                  (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3209                if Path_Name = No_Name then
3210                   Err_Vars.Error_Msg_Name_1 := From;
3211
3212                   if Location = No_Location then
3213                      Error_Msg
3214                        (Project,
3215                         "{ is not a valid directory",
3216                         Data.Location);
3217                   else
3218                      Error_Msg
3219                        (Project,
3220                         "{ is not a valid directory",
3221                         Location);
3222                   end if;
3223                else
3224
3225                   --  As it is an existing directory, we add it to
3226                   --  the list of directories.
3227
3228                   String_Elements.Increment_Last;
3229                   Element.Value := Path_Name;
3230                   Element.Display_Value := Display_Path_Name;
3231
3232                   if Last_Source_Dir = Nil_String then
3233
3234                      --  This is the first source directory
3235
3236                      Data.Source_Dirs := String_Elements.Last;
3237
3238                   else
3239                      --  We already have source directories,
3240                      --  link the previous last to the new one.
3241
3242                      String_Elements.Table (Last_Source_Dir).Next :=
3243                        String_Elements.Last;
3244                   end if;
3245
3246                   --  And register this source directory as the new last
3247
3248                   Last_Source_Dir := String_Elements.Last;
3249                   String_Elements.Table (Last_Source_Dir) := Element;
3250                end if;
3251             end;
3252          end if;
3253       end Find_Source_Dirs;
3254
3255    --  Start of processing for Language_Independent_Check
3256
3257    begin
3258       if Data.Language_Independent_Checked then
3259          return;
3260       end if;
3261
3262       Data.Language_Independent_Checked := True;
3263
3264       Error_Report := Report_Error;
3265
3266       Recursive_Dirs.Reset;
3267
3268       if Current_Verbosity = High then
3269          Write_Line ("Starting to look for directories");
3270       end if;
3271
3272       --  Check the object directory
3273
3274       declare
3275          Object_Dir : constant Variable_Value :=
3276                         Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3277
3278       begin
3279          pragma Assert (Object_Dir.Kind = Single,
3280                         "Object_Dir is not a single string");
3281
3282          --  We set the object directory to its default
3283
3284          Data.Object_Directory   := Data.Directory;
3285          Data.Display_Object_Dir := Data.Display_Directory;
3286
3287          if Object_Dir.Value /= Empty_String then
3288
3289             Get_Name_String (Object_Dir.Value);
3290
3291             if Name_Len = 0 then
3292                Error_Msg
3293                  (Project,
3294                   "Object_Dir cannot be empty",
3295                   Object_Dir.Location);
3296
3297             else
3298                --  We check that the specified object directory
3299                --  does exist.
3300
3301                Locate_Directory
3302                  (Object_Dir.Value, Data.Display_Directory,
3303                   Data.Object_Directory, Data.Display_Object_Dir);
3304
3305                if Data.Object_Directory = No_Name then
3306                   --  The object directory does not exist, report an error
3307                   Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3308                   Error_Msg
3309                     (Project,
3310                      "the object directory { cannot be found",
3311                      Data.Location);
3312
3313                   --  Do not keep a nil Object_Directory. Set it to the
3314                   --  specified (relative or absolute) path.
3315                   --  This is for the benefit of tools that recover from
3316                   --  errors; for example, these tools could create the
3317                   --  non existent directory.
3318
3319                   Data.Display_Object_Dir := Object_Dir.Value;
3320                   Get_Name_String (Object_Dir.Value);
3321                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3322                   Data.Object_Directory := Name_Find;
3323                end if;
3324             end if;
3325          end if;
3326       end;
3327
3328       if Current_Verbosity = High then
3329          if Data.Object_Directory = No_Name then
3330             Write_Line ("No object directory");
3331          else
3332             Write_Str ("Object directory: """);
3333             Write_Str (Get_Name_String (Data.Display_Object_Dir));
3334             Write_Line ("""");
3335          end if;
3336       end if;
3337
3338       --  Check the exec directory
3339
3340       declare
3341          Exec_Dir : constant Variable_Value :=
3342                       Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3343
3344       begin
3345          pragma Assert (Exec_Dir.Kind = Single,
3346                         "Exec_Dir is not a single string");
3347
3348          --  We set the object directory to its default
3349
3350          Data.Exec_Directory   := Data.Object_Directory;
3351          Data.Display_Exec_Dir := Data.Display_Object_Dir;
3352
3353          if Exec_Dir.Value /= Empty_String then
3354
3355             Get_Name_String (Exec_Dir.Value);
3356
3357             if Name_Len = 0 then
3358                Error_Msg
3359                  (Project,
3360                   "Exec_Dir cannot be empty",
3361                   Exec_Dir.Location);
3362
3363             else
3364                --  We check that the specified object directory
3365                --  does exist.
3366
3367                Locate_Directory
3368                  (Exec_Dir.Value, Data.Directory,
3369                   Data.Exec_Directory, Data.Display_Exec_Dir);
3370
3371                if Data.Exec_Directory = No_Name then
3372                   Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3373                   Error_Msg
3374                     (Project,
3375                      "the exec directory { cannot be found",
3376                      Data.Location);
3377                end if;
3378             end if;
3379          end if;
3380       end;
3381
3382       if Current_Verbosity = High then
3383          if Data.Exec_Directory = No_Name then
3384             Write_Line ("No exec directory");
3385          else
3386             Write_Str ("Exec directory: """);
3387             Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3388             Write_Line ("""");
3389          end if;
3390       end if;
3391
3392       --  Look for the source directories
3393
3394       declare
3395          Source_Dirs : constant Variable_Value :=
3396                          Util.Value_Of
3397                            (Name_Source_Dirs, Data.Decl.Attributes);
3398
3399       begin
3400          if Current_Verbosity = High then
3401             Write_Line ("Starting to look for source directories");
3402          end if;
3403
3404          pragma Assert (Source_Dirs.Kind = List,
3405                           "Source_Dirs is not a list");
3406
3407          if Source_Dirs.Default then
3408
3409             --  No Source_Dirs specified: the single source directory
3410             --  is the one containing the project file
3411
3412             String_Elements.Increment_Last;
3413             Data.Source_Dirs := String_Elements.Last;
3414             String_Elements.Table (Data.Source_Dirs) :=
3415               (Value    => Data.Directory,
3416                Display_Value => Data.Display_Directory,
3417                Location => No_Location,
3418                Flag     => False,
3419                Next     => Nil_String,
3420                Index    => 0);
3421
3422             if Current_Verbosity = High then
3423                Write_Line ("Single source directory:");
3424                Write_Str ("    """);
3425                Write_Str (Get_Name_String (Data.Display_Directory));
3426                Write_Line ("""");
3427             end if;
3428
3429          elsif Source_Dirs.Values = Nil_String then
3430
3431             --  If Source_Dirs is an empty string list, this means
3432             --  that this project contains no source. For projects that
3433             --  don't extend other projects, this also means that there is no
3434             --  need for an object directory, if not specified.
3435
3436             if Data.Extends = No_Project
3437               and then  Data.Object_Directory = Data.Directory
3438             then
3439                Data.Object_Directory := No_Name;
3440             end if;
3441
3442             Data.Source_Dirs           := Nil_String;
3443             Data.Ada_Sources_Present   := False;
3444             Data.Other_Sources_Present := False;
3445
3446          else
3447             declare
3448                Source_Dir : String_List_Id := Source_Dirs.Values;
3449                Element    : String_Element;
3450
3451             begin
3452                --  We will find the source directories for each
3453                --  element of the list
3454
3455                while Source_Dir /= Nil_String loop
3456                   Element := String_Elements.Table (Source_Dir);
3457                   Find_Source_Dirs (Element.Value, Element.Location);
3458                   Source_Dir := Element.Next;
3459                end loop;
3460             end;
3461          end if;
3462
3463          if Current_Verbosity = High then
3464             Write_Line ("Putting source directories in canonical cases");
3465          end if;
3466
3467          declare
3468             Current : String_List_Id := Data.Source_Dirs;
3469             Element : String_Element;
3470
3471          begin
3472             while Current /= Nil_String loop
3473                Element := String_Elements.Table (Current);
3474                if Element.Value /= No_Name then
3475                   Get_Name_String (Element.Value);
3476                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3477                   Element.Value := Name_Find;
3478                   String_Elements.Table (Current) := Element;
3479                end if;
3480
3481                Current := Element.Next;
3482             end loop;
3483          end;
3484       end;
3485
3486       --  Library attributes
3487
3488       declare
3489          Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3490
3491          Lib_Dir : constant Prj.Variable_Value :=
3492                      Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3493
3494          Lib_Name : constant Prj.Variable_Value :=
3495                       Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3496
3497          Lib_Version : constant Prj.Variable_Value :=
3498                          Prj.Util.Value_Of
3499                            (Snames.Name_Library_Version, Attributes);
3500
3501          The_Lib_Kind : constant Prj.Variable_Value :=
3502                           Prj.Util.Value_Of
3503                             (Snames.Name_Library_Kind, Attributes);
3504
3505       begin
3506          --  Special case of extending project
3507
3508          if Data.Extends /= No_Project then
3509             declare
3510                Extended_Data : constant Project_Data :=
3511                  Projects.Table (Data.Extends);
3512
3513             begin
3514                --  If the project extended is a library project, we inherit
3515                --  the library name, if it is not redefined; we check that
3516                --  the library directory is specified; and we reset the
3517                --  library flag for the extended project.
3518
3519                if Extended_Data.Library then
3520                   if Lib_Name.Default then
3521                      Data.Library_Name := Extended_Data.Library_Name;
3522                   end if;
3523
3524                   if Lib_Dir.Default then
3525                      if not Data.Virtual then
3526                         Error_Msg
3527                           (Project,
3528                            "a project extending a library project must " &
3529                            "specify an attribute Library_Dir",
3530                            Data.Location);
3531                      end if;
3532                   end if;
3533
3534                   Projects.Table (Data.Extends).Library := False;
3535                end if;
3536             end;
3537          end if;
3538
3539          pragma Assert (Lib_Dir.Kind = Single);
3540
3541          if Lib_Dir.Value = Empty_String then
3542
3543             if Current_Verbosity = High then
3544                Write_Line ("No library directory");
3545             end if;
3546
3547          else
3548             --  Find path name, check that it is a directory
3549
3550             Locate_Directory
3551               (Lib_Dir.Value, Data.Display_Directory,
3552                Data.Library_Dir, Data.Display_Library_Dir);
3553
3554             if Data.Library_Dir = No_Name then
3555
3556                --  Get the absolute name of the library directory that
3557                --  does not exist, to report an error.
3558
3559                declare
3560                   Dir_Name : constant String :=
3561                     Get_Name_String (Lib_Dir.Value);
3562                begin
3563                   if Is_Absolute_Path (Dir_Name) then
3564                      Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3565
3566                   else
3567                      Get_Name_String (Data.Display_Directory);
3568
3569                      if Name_Buffer (Name_Len) /= Directory_Separator then
3570                         Name_Len := Name_Len + 1;
3571                         Name_Buffer (Name_Len) := Directory_Separator;
3572                      end if;
3573
3574                      Name_Buffer
3575                        (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3576                        Dir_Name;
3577                      Name_Len := Name_Len + Dir_Name'Length;
3578                      Err_Vars.Error_Msg_Name_1 := Name_Find;
3579                   end if;
3580
3581                   --  Report the error
3582
3583                   Error_Msg
3584                     (Project,
3585                      "library directory { does not exist",
3586                      Lib_Dir.Location);
3587                end;
3588
3589             elsif Data.Library_Dir = Data.Object_Directory then
3590                Error_Msg
3591                  (Project,
3592                   "library directory cannot be the same " &
3593                   "as object directory",
3594                   Lib_Dir.Location);
3595                Data.Library_Dir := No_Name;
3596                Data.Display_Library_Dir := No_Name;
3597
3598             else
3599                if Current_Verbosity = High then
3600                   Write_Str ("Library directory =""");
3601                   Write_Str (Get_Name_String (Data.Display_Library_Dir));
3602                   Write_Line ("""");
3603                end if;
3604             end if;
3605          end if;
3606
3607          pragma Assert (Lib_Name.Kind = Single);
3608
3609          if Lib_Name.Value = Empty_String then
3610             if Current_Verbosity = High
3611               and then Data.Library_Name = No_Name
3612             then
3613                Write_Line ("No library name");
3614             end if;
3615
3616          else
3617             --  There is no restriction on the syntax of library names
3618
3619             Data.Library_Name := Lib_Name.Value;
3620          end if;
3621
3622          if Data.Library_Name /= No_Name
3623            and then Current_Verbosity = High
3624          then
3625             Write_Str ("Library name = """);
3626             Write_Str (Get_Name_String (Data.Library_Name));
3627             Write_Line ("""");
3628          end if;
3629
3630          Data.Library :=
3631            Data.Library_Dir /= No_Name
3632              and then
3633            Data.Library_Name /= No_Name;
3634
3635          if Data.Library then
3636             if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3637                Error_Msg
3638                  (Project,
3639                   "?libraries are not supported on this platform",
3640                   Lib_Name.Location);
3641                Data.Library := False;
3642
3643             else
3644                pragma Assert (Lib_Version.Kind = Single);
3645
3646                if Lib_Version.Value = Empty_String then
3647                   if Current_Verbosity = High then
3648                      Write_Line ("No library version specified");
3649                   end if;
3650
3651                else
3652                   Data.Lib_Internal_Name := Lib_Version.Value;
3653                end if;
3654
3655                pragma Assert (The_Lib_Kind.Kind = Single);
3656
3657                if The_Lib_Kind.Value = Empty_String then
3658                   if Current_Verbosity = High then
3659                      Write_Line ("No library kind specified");
3660                   end if;
3661
3662                else
3663                   Get_Name_String (The_Lib_Kind.Value);
3664
3665                   declare
3666                      Kind_Name : constant String :=
3667                                    To_Lower (Name_Buffer (1 .. Name_Len));
3668
3669                      OK : Boolean := True;
3670
3671                   begin
3672                      if Kind_Name = "static" then
3673                         Data.Library_Kind := Static;
3674
3675                      elsif Kind_Name = "dynamic" then
3676                         Data.Library_Kind := Dynamic;
3677
3678                      elsif Kind_Name = "relocatable" then
3679                         Data.Library_Kind := Relocatable;
3680
3681                      else
3682                         Error_Msg
3683                           (Project,
3684                            "illegal value for Library_Kind",
3685                            The_Lib_Kind.Location);
3686                         OK := False;
3687                      end if;
3688
3689                      if Current_Verbosity = High and then OK then
3690                         Write_Str ("Library kind = ");
3691                         Write_Line (Kind_Name);
3692                      end if;
3693
3694                      if Data.Library_Kind /= Static and then
3695                        MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3696                      then
3697                         Error_Msg
3698                           (Project,
3699                            "only static libraries are supported " &
3700                            "on this platform",
3701                           The_Lib_Kind.Location);
3702                         Data.Library := False;
3703                      end if;
3704                   end;
3705                end if;
3706
3707                if Data.Library and then Current_Verbosity = High then
3708                   Write_Line ("This is a library project file");
3709                end if;
3710
3711             end if;
3712          end if;
3713       end;
3714
3715       if Current_Verbosity = High then
3716          Show_Source_Dirs (Project);
3717       end if;
3718
3719       declare
3720          Naming_Id : constant Package_Id :=
3721                        Util.Value_Of (Name_Naming, Data.Decl.Packages);
3722
3723          Naming    : Package_Element;
3724
3725       begin
3726          --  If there is a package Naming, we will put in Data.Naming
3727          --  what is in this package Naming.
3728
3729          if Naming_Id /= No_Package then
3730             Naming := Packages.Table (Naming_Id);
3731
3732             if Current_Verbosity = High then
3733                Write_Line ("Checking ""Naming"".");
3734             end if;
3735
3736             --  Check Spec_Suffix
3737
3738             declare
3739                Spec_Suffixs : Array_Element_Id :=
3740                                 Util.Value_Of
3741                                   (Name_Spec_Suffix,
3742                                    Naming.Decl.Arrays);
3743                Suffix  : Array_Element_Id;
3744                Element : Array_Element;
3745                Suffix2 : Array_Element_Id;
3746
3747             begin
3748                --  If some suffixs have been specified, we make sure that
3749                --  for each language for which a default suffix has been
3750                --  specified, there is a suffix specified, either the one
3751                --  in the project file or if there were none, the default.
3752
3753                if Spec_Suffixs /= No_Array_Element then
3754                   Suffix := Data.Naming.Spec_Suffix;
3755
3756                   while Suffix /= No_Array_Element loop
3757                      Element := Array_Elements.Table (Suffix);
3758                      Suffix2 := Spec_Suffixs;
3759
3760                      while Suffix2 /= No_Array_Element loop
3761                         exit when Array_Elements.Table (Suffix2).Index =
3762                           Element.Index;
3763                         Suffix2 := Array_Elements.Table (Suffix2).Next;
3764                      end loop;
3765
3766                      --  There is a registered default suffix, but no
3767                      --  suffix specified in the project file.
3768                      --  Add the default to the array.
3769
3770                      if Suffix2 = No_Array_Element then
3771                         Array_Elements.Increment_Last;
3772                         Array_Elements.Table (Array_Elements.Last) :=
3773                           (Index     => Element.Index,
3774                            Src_Index => Element.Src_Index,
3775                            Index_Case_Sensitive => False,
3776                            Value     => Element.Value,
3777                            Next      => Spec_Suffixs);
3778                         Spec_Suffixs := Array_Elements.Last;
3779                      end if;
3780
3781                      Suffix := Element.Next;
3782                   end loop;
3783
3784                   --  Put the resulting array as the specification suffixs
3785
3786                   Data.Naming.Spec_Suffix := Spec_Suffixs;
3787                end if;
3788             end;
3789
3790             declare
3791                Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3792                Element : Array_Element;
3793
3794             begin
3795                while Current /= No_Array_Element loop
3796                   Element := Array_Elements.Table (Current);
3797                   Get_Name_String (Element.Value.Value);
3798
3799                   if Name_Len = 0 then
3800                      Error_Msg
3801                        (Project,
3802                         "Spec_Suffix cannot be empty",
3803                         Element.Value.Location);
3804                   end if;
3805
3806                   Array_Elements.Table (Current) := Element;
3807                   Current := Element.Next;
3808                end loop;
3809             end;
3810
3811             --  Check Body_Suffix
3812
3813             declare
3814                Impl_Suffixs : Array_Element_Id :=
3815                                 Util.Value_Of
3816                                   (Name_Body_Suffix,
3817                                    Naming.Decl.Arrays);
3818
3819                Suffix  : Array_Element_Id;
3820                Element : Array_Element;
3821                Suffix2 : Array_Element_Id;
3822
3823             begin
3824                --  If some suffixs have been specified, we make sure that
3825                --  for each language for which a default suffix has been
3826                --  specified, there is a suffix specified, either the one
3827                --  in the project file or if there were noe, the default.
3828
3829                if Impl_Suffixs /= No_Array_Element then
3830                   Suffix := Data.Naming.Body_Suffix;
3831
3832                   while Suffix /= No_Array_Element loop
3833                      Element := Array_Elements.Table (Suffix);
3834                      Suffix2 := Impl_Suffixs;
3835
3836                      while Suffix2 /= No_Array_Element loop
3837                         exit when Array_Elements.Table (Suffix2).Index =
3838                           Element.Index;
3839                         Suffix2 := Array_Elements.Table (Suffix2).Next;
3840                      end loop;
3841
3842                      --  There is a registered default suffix, but no
3843                      --  suffix specified in the project file.
3844                      --  Add the default to the array.
3845
3846                      if Suffix2 = No_Array_Element then
3847                         Array_Elements.Increment_Last;
3848                         Array_Elements.Table (Array_Elements.Last) :=
3849                           (Index => Element.Index,
3850                            Src_Index => Element.Src_Index,
3851                            Index_Case_Sensitive => False,
3852                            Value => Element.Value,
3853                            Next  => Impl_Suffixs);
3854                         Impl_Suffixs := Array_Elements.Last;
3855                      end if;
3856
3857                      Suffix := Element.Next;
3858                   end loop;
3859
3860                   --  Put the resulting array as the implementation suffixs
3861
3862                   Data.Naming.Body_Suffix := Impl_Suffixs;
3863                end if;
3864             end;
3865
3866             declare
3867                Current : Array_Element_Id := Data.Naming.Body_Suffix;
3868                Element : Array_Element;
3869
3870             begin
3871                while Current /= No_Array_Element loop
3872                   Element := Array_Elements.Table (Current);
3873                   Get_Name_String (Element.Value.Value);
3874
3875                   if Name_Len = 0 then
3876                      Error_Msg
3877                        (Project,
3878                         "Body_Suffix cannot be empty",
3879                         Element.Value.Location);
3880                   end if;
3881
3882                   Array_Elements.Table (Current) := Element;
3883                   Current := Element.Next;
3884                end loop;
3885             end;
3886
3887             --  Get the exceptions, if any
3888
3889             Data.Naming.Specification_Exceptions :=
3890               Util.Value_Of
3891                 (Name_Specification_Exceptions,
3892                  In_Arrays => Naming.Decl.Arrays);
3893
3894             Data.Naming.Implementation_Exceptions :=
3895               Util.Value_Of
3896                 (Name_Implementation_Exceptions,
3897                  In_Arrays => Naming.Decl.Arrays);
3898          end if;
3899       end;
3900
3901       Projects.Table (Project) := Data;
3902    end Language_Independent_Check;
3903
3904    ----------------------
3905    -- Locate_Directory --
3906    ----------------------
3907
3908    procedure Locate_Directory
3909      (Name    : Name_Id;
3910       Parent  : Name_Id;
3911       Dir     : out Name_Id;
3912       Display : out Name_Id)
3913    is
3914       The_Name   : constant String := Get_Name_String (Name);
3915       The_Parent : constant String :=
3916                      Get_Name_String (Parent) & Directory_Separator;
3917       The_Parent_Last : constant Natural :=
3918                      Compute_Directory_Last (The_Parent);
3919
3920    begin
3921       if Current_Verbosity = High then
3922          Write_Str ("Locate_Directory (""");
3923          Write_Str (The_Name);
3924          Write_Str (""", """);
3925          Write_Str (The_Parent);
3926          Write_Line (""")");
3927       end if;
3928
3929       Dir     := No_Name;
3930       Display := No_Name;
3931
3932       if Is_Absolute_Path (The_Name) then
3933          if Is_Directory (The_Name) then
3934             declare
3935                Normed : constant String :=
3936                           Normalize_Pathname
3937                             (The_Name,
3938                              Resolve_Links  => False,
3939                              Case_Sensitive => True);
3940
3941                Canonical_Path : constant String :=
3942                                   Normalize_Pathname
3943                                     (Normed,
3944                                      Resolve_Links  => True,
3945                                      Case_Sensitive => False);
3946
3947             begin
3948                Name_Len := Normed'Length;
3949                Name_Buffer (1 .. Name_Len) := Normed;
3950                Display := Name_Find;
3951
3952                Name_Len := Canonical_Path'Length;
3953                Name_Buffer (1 .. Name_Len) := Canonical_Path;
3954                Dir := Name_Find;
3955             end;
3956          end if;
3957
3958       else
3959          declare
3960             Full_Path : constant String :=
3961                           The_Parent (The_Parent'First .. The_Parent_Last) &
3962                           The_Name;
3963
3964          begin
3965             if Is_Directory (Full_Path) then
3966                declare
3967                   Normed : constant String :=
3968                              Normalize_Pathname
3969                                (Full_Path,
3970                                 Resolve_Links  => False,
3971                                 Case_Sensitive => True);
3972
3973                   Canonical_Path : constant String :=
3974                                      Normalize_Pathname
3975                                        (Normed,
3976                                         Resolve_Links  => True,
3977                                         Case_Sensitive => False);
3978
3979                begin
3980                   Name_Len := Normed'Length;
3981                   Name_Buffer (1 .. Name_Len) := Normed;
3982                   Display := Name_Find;
3983
3984                   Name_Len := Canonical_Path'Length;
3985                   Name_Buffer (1 .. Name_Len) := Canonical_Path;
3986                   Dir := Name_Find;
3987                end;
3988             end if;
3989          end;
3990       end if;
3991    end Locate_Directory;
3992
3993    ---------------------------
3994    -- Other_Languages_Check --
3995    ---------------------------
3996
3997    procedure Other_Languages_Check
3998      (Project      : Project_Id;
3999       Report_Error : Put_Line_Access) is
4000
4001       Data         : Project_Data;
4002
4003       Languages    : Variable_Value := Nil_Variable_Value;
4004
4005    begin
4006       Language_Independent_Check (Project, Report_Error);
4007
4008       Error_Report := Report_Error;
4009
4010       Data      := Projects.Table (Project);
4011       Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
4012
4013       Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4014
4015       if Data.Other_Sources_Present then
4016          --  Check if languages other than Ada are specified in this project
4017
4018          if Languages.Default then
4019             --  Attribute Languages is not specified. So, it defaults to
4020             --  a project of language Ada only.
4021
4022             Data.Languages (Lang_Ada) := True;
4023
4024             --  No sources of languages other than Ada
4025
4026             Data.Other_Sources_Present := False;
4027
4028          else
4029             declare
4030                Current        : String_List_Id := Languages.Values;
4031                Element        : String_Element;
4032                OK             : Boolean := False;
4033             begin
4034                --  Assumethat there is no language other than Ada specified.
4035                --  If in fact there is at least one, we will set back
4036                --  Other_Sources_Present to True.
4037
4038                Data.Other_Sources_Present := False;
4039
4040                --  Look through all the languages specified in attribute
4041                --  Languages, if any
4042
4043                while Current /= Nil_String loop
4044                   Element := String_Elements.Table (Current);
4045                   Get_Name_String (Element.Value);
4046                   To_Lower (Name_Buffer (1 .. Name_Len));
4047                   OK := False;
4048
4049                   --  Check if it is a known language
4050
4051                   Lang_Loop : for Lang in Programming_Language loop
4052                      if
4053                        Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4054                      then
4055                         --  Yes, this is a known language
4056
4057                         OK := True;
4058
4059                         --  Indicate the presence of this language
4060                         Data.Languages (Lang) := True;
4061
4062                         --  If it is a language other than Ada, indicate that
4063                         --  there should be some sources of a language other
4064                         --  than Ada.
4065
4066                         if Lang /= Lang_Ada then
4067                            Data.Other_Sources_Present := True;
4068                         end if;
4069
4070                         exit Lang_Loop;
4071                      end if;
4072                   end loop Lang_Loop;
4073
4074                   --  We don't support this language: report an error
4075
4076                   if not OK then
4077                      Error_Msg_Name_1 := Element.Value;
4078                      Error_Msg
4079                        (Project,
4080                         "unknown programming language {",
4081                         Element.Location);
4082                   end if;
4083
4084                   Current := Element.Next;
4085                end loop;
4086             end;
4087          end if;
4088       end if;
4089
4090       --  If there may be some sources, look for them
4091
4092       if Data.Other_Sources_Present then
4093          --  Set Source_Present to False. It will be set back to True whenever
4094          --  a source is found.
4095
4096          Data.Other_Sources_Present := False;
4097
4098          for Lang in Other_Programming_Language loop
4099             --  For each language (other than Ada) in the project file
4100
4101             if Data.Languages (Lang) then
4102                --  Reset the indication that there are sources of this
4103                --  language. It will be set back to True whenever we find a
4104                --  source of the language.
4105
4106                Data.Languages (Lang) := False;
4107
4108                --  First, get the source suffix for the language
4109
4110                Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4111
4112                --  Then, deal with the naming exceptions, if any
4113
4114                Source_Names.Reset;
4115
4116                declare
4117                   Naming_Exceptions : constant Variable_Value :=
4118                     Value_Of
4119                       (Index     => Lang_Name_Ids (Lang),
4120                        Src_Index => 0,
4121                        In_Array  => Data.Naming.Implementation_Exceptions);
4122                   Element_Id : String_List_Id;
4123                   Element    : String_Element;
4124                   File_Id : Name_Id;
4125                   Source_Found : Boolean := False;
4126                begin
4127                   --  If there are naming exceptions, look through them one
4128                   --  by one.
4129
4130                   if Naming_Exceptions /= Nil_Variable_Value then
4131                      Element_Id := Naming_Exceptions.Values;
4132
4133                      while Element_Id /= Nil_String loop
4134                         Element := String_Elements.Table (Element_Id);
4135                         Get_Name_String (Element.Value);
4136                         Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4137                         File_Id := Name_Find;
4138
4139                         --  Put each naming exception in the Source_Names
4140                         --  hash table, but if there are repetition, don't
4141                         --  bother after the first instance.
4142
4143                         if Source_Names.Get (File_Id) = No_Name_Location then
4144                            Source_Found := True;
4145                            Source_Names.Set
4146                              (File_Id,
4147                               (Name     => File_Id,
4148                                Location => Element.Location,
4149                                Found    => False));
4150                         end if;
4151
4152                         Element_Id := Element.Next;
4153                      end loop;
4154
4155                      --  If there is at least one naming exception, record
4156                      --  those that are found in the source directories.
4157
4158                      if Source_Found then
4159                         Record_Other_Sources
4160                           (Project           => Project,
4161                            Data              => Data,
4162                            Language          => Lang,
4163                            Naming_Exceptions => True);
4164                      end if;
4165
4166                   end if;
4167                end;
4168
4169                --  Now, check if a list of sources is declared either through
4170                --  a string list (attribute Source_Files) or a text file
4171                --  (attribute Source_List_File).
4172                --  If a source list is declared, we will consider only those
4173                --  naming exceptions that are on the list.
4174
4175                declare
4176                   Sources : constant Variable_Value :=
4177                     Util.Value_Of
4178                       (Name_Source_Files,
4179                        Data.Decl.Attributes);
4180
4181                   Source_List_File : constant Variable_Value :=
4182                     Util.Value_Of
4183                       (Name_Source_List_File,
4184                        Data.Decl.Attributes);
4185
4186                begin
4187                   pragma Assert
4188                     (Sources.Kind = List,
4189                      "Source_Files is not a list");
4190
4191                   pragma Assert
4192                     (Source_List_File.Kind = Single,
4193                      "Source_List_File is not a single string");
4194
4195                   if not Sources.Default then
4196                      if not Source_List_File.Default then
4197                         Error_Msg
4198                           (Project,
4199                            "?both variables source_files and " &
4200                            "source_list_file are present",
4201                            Source_List_File.Location);
4202                      end if;
4203
4204                      --  Sources is a list of file names
4205
4206                      declare
4207                         Current        : String_List_Id := Sources.Values;
4208                         Element        : String_Element;
4209                         Location       : Source_Ptr;
4210                         Name           : Name_Id;
4211
4212                      begin
4213                         Source_Names.Reset;
4214
4215                         --  Put all the sources in the Source_Names hash
4216                         --  table.
4217
4218                         while Current /= Nil_String loop
4219                            Element := String_Elements.Table (Current);
4220                            Get_Name_String (Element.Value);
4221                            Canonical_Case_File_Name
4222                              (Name_Buffer (1 .. Name_Len));
4223                            Name := Name_Find;
4224
4225                            --  If the element has no location, then use the
4226                            --  location of Sources to report possible errors.
4227
4228                            if Element.Location = No_Location then
4229                               Location := Sources.Location;
4230
4231                            else
4232                               Location := Element.Location;
4233                            end if;
4234
4235                            Source_Names.Set
4236                              (K => Name,
4237                               E =>
4238                                 (Name     => Name,
4239                                  Location => Location,
4240                                  Found    => False));
4241
4242                            Current := Element.Next;
4243                         end loop;
4244
4245                         --  And look for their directories
4246
4247                         Record_Other_Sources
4248                           (Project           => Project,
4249                            Data              => Data,
4250                            Language          => Lang,
4251                            Naming_Exceptions => False);
4252                      end;
4253
4254                      --  No source_files specified.
4255                      --  We check if Source_List_File has been specified.
4256
4257                   elsif not Source_List_File.Default then
4258
4259                      --  Source_List_File is the name of the file
4260                      --  that contains the source file names
4261
4262                      declare
4263                         Source_File_Path_Name : constant String :=
4264                           Path_Name_Of
4265                             (Source_List_File.Value,
4266                              Data.Directory);
4267
4268                      begin
4269                         if Source_File_Path_Name'Length = 0 then
4270                            Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4271                            Error_Msg
4272                              (Project,
4273                               "file with sources { does not exist",
4274                               Source_List_File.Location);
4275
4276                         else
4277                            --  Read the file, putting each source in the
4278                            --  Source_Names hash table.
4279
4280                            Get_Sources_From_File
4281                              (Source_File_Path_Name,
4282                               Source_List_File.Location,
4283                               Project);
4284
4285                            --  And look for their directories.
4286
4287                            Record_Other_Sources
4288                              (Project           => Project,
4289                               Data              => Data,
4290                               Language          => Lang,
4291                               Naming_Exceptions => False);
4292                         end if;
4293                      end;
4294
4295                   else
4296                      --  Neither Source_Files nor Source_List_File has been
4297                      --  specified. Find all the files that satisfy
4298                      --  the naming scheme in all the source directories.
4299                      --  All the naming exceptions that effectively exist are
4300                      --  also part of the source of this language.
4301
4302                      Find_Sources (Project, Data, Lang);
4303                   end if;
4304
4305                end;
4306             end if;
4307          end loop;
4308       end if;
4309
4310       --  Finally, get the mains, if any
4311
4312       Get_Mains (Project, Data);
4313
4314       Projects.Table (Project) := Data;
4315
4316    end Other_Languages_Check;
4317
4318    ------------------
4319    -- Path_Name_Of --
4320    ------------------
4321
4322    function Path_Name_Of
4323      (File_Name : Name_Id;
4324       Directory : Name_Id) return String
4325    is
4326       Result : String_Access;
4327       The_Directory : constant String := Get_Name_String (Directory);
4328
4329    begin
4330       Get_Name_String (File_Name);
4331       Result := Locate_Regular_File
4332         (File_Name => Name_Buffer (1 .. Name_Len),
4333          Path      => The_Directory);
4334
4335       if Result = null then
4336          return "";
4337       else
4338          Canonical_Case_File_Name (Result.all);
4339          return Result.all;
4340       end if;
4341    end Path_Name_Of;
4342
4343    -------------------------------
4344    -- Prepare_Ada_Naming_Exceptions --
4345    -------------------------------
4346
4347    procedure Prepare_Ada_Naming_Exceptions
4348      (List : Array_Element_Id;
4349       Kind : Spec_Or_Body)
4350    is
4351       Current : Array_Element_Id := List;
4352       Element : Array_Element;
4353
4354       Unit : Unit_Info;
4355
4356    begin
4357       --  Traverse the list
4358
4359       while Current /= No_Array_Element loop
4360          Element := Array_Elements.Table (Current);
4361
4362          if Element.Index /= No_Name then
4363             Unit :=
4364               (Kind => Kind,
4365                Unit => Element.Index,
4366                Next => No_Ada_Naming_Exception);
4367             Reverse_Ada_Naming_Exceptions.Set
4368               (Unit, (Element.Value.Value, Element.Value.Index));
4369             Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4370             Ada_Naming_Exception_Table.Increment_Last;
4371             Ada_Naming_Exception_Table.Table
4372               (Ada_Naming_Exception_Table.Last) := Unit;
4373             Ada_Naming_Exceptions.Set
4374               (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4375          end if;
4376
4377          Current := Element.Next;
4378       end loop;
4379    end Prepare_Ada_Naming_Exceptions;
4380
4381    ---------------------
4382    -- Project_Extends --
4383    ---------------------
4384
4385    function Project_Extends
4386      (Extending : Project_Id;
4387       Extended  : Project_Id) return Boolean
4388    is
4389       Current : Project_Id := Extending;
4390    begin
4391       loop
4392          if Current = No_Project then
4393             return False;
4394
4395          elsif Current = Extended then
4396             return True;
4397          end if;
4398
4399          Current := Projects.Table (Current).Extends;
4400       end loop;
4401    end Project_Extends;
4402
4403    -----------------------
4404    -- Record_Ada_Source --
4405    -----------------------
4406
4407    procedure Record_Ada_Source
4408      (File_Name       : Name_Id;
4409       Path_Name       : Name_Id;
4410       Project         : Project_Id;
4411       Data            : in out Project_Data;
4412       Location        : Source_Ptr;
4413       Current_Source  : in out String_List_Id;
4414       Source_Recorded : in out Boolean;
4415       Follow_Links    : Boolean)
4416    is
4417       Canonical_File_Name : Name_Id;
4418       Canonical_Path_Name : Name_Id;
4419       Exception_Id : Ada_Naming_Exception_Id;
4420       Unit_Name    : Name_Id;
4421       Unit_Kind    : Spec_Or_Body;
4422       Unit_Index   : Int := 0;
4423       Info         : Unit_Info;
4424       Name_Index   : Name_And_Index;
4425       Needs_Pragma : Boolean;
4426
4427       The_Location    : Source_Ptr     := Location;
4428       Previous_Source : constant String_List_Id := Current_Source;
4429       Except_Name     : Name_And_Index := No_Name_And_Index;
4430
4431       Unit_Prj : Unit_Project;
4432
4433       File_Name_Recorded : Boolean := False;
4434
4435    begin
4436       Get_Name_String (File_Name);
4437       Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4438       Canonical_File_Name := Name_Find;
4439
4440       declare
4441          Canonical_Path : constant String :=
4442                             Normalize_Pathname
4443                               (Get_Name_String (Path_Name),
4444                                Resolve_Links => Follow_Links,
4445                                Case_Sensitive => False);
4446       begin
4447          Name_Len := 0;
4448          Add_Str_To_Name_Buffer (Canonical_Path);
4449          Canonical_Path_Name := Name_Find;
4450       end;
4451
4452       --  Find out the unit name, the unit kind and if it needs
4453       --  a specific SFN pragma.
4454
4455       Get_Unit
4456         (Canonical_File_Name => Canonical_File_Name,
4457          Naming              => Data.Naming,
4458          Exception_Id        => Exception_Id,
4459          Unit_Name           => Unit_Name,
4460          Unit_Kind           => Unit_Kind,
4461          Needs_Pragma        => Needs_Pragma);
4462
4463       if Exception_Id = No_Ada_Naming_Exception and then
4464         Unit_Name = No_Name
4465       then
4466          if Current_Verbosity = High then
4467             Write_Str  ("   """);
4468             Write_Str  (Get_Name_String (Canonical_File_Name));
4469             Write_Line (""" is not a valid source file name (ignored).");
4470          end if;
4471
4472       else
4473
4474          --  Check to see if the source has been hidden by an exception,
4475          --  but only if it is not an exception.
4476
4477          if not Needs_Pragma then
4478             Except_Name :=
4479               Reverse_Ada_Naming_Exceptions.Get
4480                 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4481
4482             if Except_Name /= No_Name_And_Index then
4483                if Current_Verbosity = High then
4484                   Write_Str  ("   """);
4485                   Write_Str  (Get_Name_String (Canonical_File_Name));
4486                   Write_Str  (""" contains a unit that is found in """);
4487                   Write_Str  (Get_Name_String (Except_Name.Name));
4488                   Write_Line (""" (ignored).");
4489                end if;
4490
4491                --  The file is not included in the source of the project,
4492                --  because it is hidden by the exception.
4493                --  So, there is nothing else to do.
4494
4495                return;
4496             end if;
4497          end if;
4498
4499          loop
4500             if Exception_Id /= No_Ada_Naming_Exception then
4501                Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4502                Exception_Id := Info.Next;
4503                Info.Next := No_Ada_Naming_Exception;
4504                Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4505
4506                Unit_Name  := Info.Unit;
4507                Unit_Index := Name_Index.Index;
4508                Unit_Kind  := Info.Kind;
4509             end if;
4510             --  Put the file name in the list of sources of the project
4511
4512             if not File_Name_Recorded then
4513                String_Elements.Increment_Last;
4514                String_Elements.Table (String_Elements.Last) :=
4515                  (Value         => Canonical_File_Name,
4516                   Display_Value => File_Name,
4517                   Location      => No_Location,
4518                   Flag          => False,
4519                   Next          => Nil_String,
4520                   Index         => Unit_Index);
4521             end if;
4522
4523             if Current_Source = Nil_String then
4524                Data.Sources := String_Elements.Last;
4525
4526             else
4527                String_Elements.Table (Current_Source).Next :=
4528                  String_Elements.Last;
4529             end if;
4530
4531             Current_Source := String_Elements.Last;
4532
4533             --  Put the unit in unit list
4534
4535             declare
4536                The_Unit      : Unit_Id := Units_Htable.Get (Unit_Name);
4537                The_Unit_Data : Unit_Data;
4538
4539             begin
4540                if Current_Verbosity = High then
4541                   Write_Str  ("Putting ");
4542                   Write_Str  (Get_Name_String (Unit_Name));
4543                   Write_Line (" in the unit list.");
4544                end if;
4545
4546                --  The unit is already in the list, but may be it is
4547                --  only the other unit kind (spec or body), or what is
4548                --  in the unit list is a unit of a project we are extending.
4549
4550                if The_Unit /= Prj.Com.No_Unit then
4551                   The_Unit_Data := Units.Table (The_Unit);
4552
4553                   if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4554                     or else Project_Extends
4555                       (Data.Extends,
4556                        The_Unit_Data.File_Names (Unit_Kind).Project)
4557                   then
4558                      if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4559                         Remove_Forbidden_File_Name
4560                           (The_Unit_Data.File_Names (Unit_Kind).Name);
4561                      end if;
4562
4563                      --  Record the file name in the hash table Files_Htable
4564
4565                      Unit_Prj := (Unit => The_Unit, Project => Project);
4566                      Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4567
4568                      The_Unit_Data.File_Names (Unit_Kind) :=
4569                        (Name         => Canonical_File_Name,
4570                         Index        => Unit_Index,
4571                         Display_Name => File_Name,
4572                         Path         => Canonical_Path_Name,
4573                         Display_Path => Path_Name,
4574                         Project      => Project,
4575                         Needs_Pragma => Needs_Pragma);
4576                      Units.Table (The_Unit) := The_Unit_Data;
4577                      Source_Recorded := True;
4578
4579                   elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4580                     and then (Data.Known_Order_Of_Source_Dirs or else
4581                               The_Unit_Data.File_Names (Unit_Kind).Path =
4582                                 Canonical_Path_Name)
4583                   then
4584                      if Previous_Source = Nil_String then
4585                         Data.Sources := Nil_String;
4586                      else
4587                         String_Elements.Table (Previous_Source).Next :=
4588                           Nil_String;
4589                         String_Elements.Decrement_Last;
4590                      end if;
4591
4592                      Current_Source := Previous_Source;
4593
4594                   else
4595                      --  It is an error to have two units with the same name
4596                      --  and the same kind (spec or body).
4597
4598                      if The_Location = No_Location then
4599                         The_Location := Projects.Table (Project).Location;
4600                      end if;
4601
4602                      Err_Vars.Error_Msg_Name_1 := Unit_Name;
4603                      Error_Msg (Project, "duplicate source {", The_Location);
4604
4605                      Err_Vars.Error_Msg_Name_1 :=
4606                        Projects.Table
4607                          (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4608                      Err_Vars.Error_Msg_Name_2 :=
4609                        The_Unit_Data.File_Names (Unit_Kind).Path;
4610                      Error_Msg
4611                        (Project, "\   project file {, {", The_Location);
4612
4613                      Err_Vars.Error_Msg_Name_1 :=
4614                        Projects.Table (Project).Name;
4615                      Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4616                      Error_Msg
4617                        (Project, "\   project file {, {", The_Location);
4618
4619                   end if;
4620
4621                   --  It is a new unit, create a new record
4622
4623                else
4624                   --  First, check if there is no other unit with this file
4625                   --  name in another project. If it is, report an error.
4626                   --  Of course, we do that only for the first unit in the
4627                   --  source file.
4628
4629                   Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4630
4631                   if not File_Name_Recorded and then
4632                     Unit_Prj /= No_Unit_Project
4633                   then
4634                      Error_Msg_Name_1 := File_Name;
4635                      Error_Msg_Name_2 :=
4636                        Projects.Table (Unit_Prj.Project).Name;
4637                      Error_Msg
4638                        (Project,
4639                         "{ is already a source of project {",
4640                         Location);
4641
4642                   else
4643                      Units.Increment_Last;
4644                      The_Unit := Units.Last;
4645                      Units_Htable.Set (Unit_Name, The_Unit);
4646                      Unit_Prj := (Unit => The_Unit, Project => Project);
4647                      Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4648                      The_Unit_Data.Name := Unit_Name;
4649                      The_Unit_Data.File_Names (Unit_Kind) :=
4650                        (Name         => Canonical_File_Name,
4651                         Index        => Unit_Index,
4652                         Display_Name => File_Name,
4653                         Path         => Canonical_Path_Name,
4654                         Display_Path => Path_Name,
4655                         Project      => Project,
4656                         Needs_Pragma => Needs_Pragma);
4657                      Units.Table (The_Unit) := The_Unit_Data;
4658                      Source_Recorded := True;
4659                   end if;
4660                end if;
4661             end;
4662
4663             exit when Exception_Id = No_Ada_Naming_Exception;
4664             File_Name_Recorded := True;
4665          end loop;
4666       end if;
4667    end Record_Ada_Source;
4668
4669    --------------------------
4670    -- Record_Other_Sources --
4671    --------------------------
4672
4673    procedure Record_Other_Sources
4674      (Project           : Project_Id;
4675       Data              : in out Project_Data;
4676       Language          : Programming_Language;
4677       Naming_Exceptions : Boolean)
4678    is
4679       Source_Dir : String_List_Id := Data.Source_Dirs;
4680       Element    : String_Element;
4681       Path       : Name_Id;
4682
4683       Dir      : Dir_Type;
4684       Canonical_Name : Name_Id;
4685       Name_Str : String (1 .. 1_024);
4686       Last     : Natural := 0;
4687       NL       : Name_Location;
4688
4689       First_Error : Boolean := True;
4690
4691       Suffix : constant String :=
4692         Get_Name_String (Data.Impl_Suffixes (Language));
4693
4694    begin
4695       while Source_Dir /= Nil_String loop
4696          Element := String_Elements.Table (Source_Dir);
4697
4698          declare
4699             Dir_Path : constant String := Get_Name_String (Element.Value);
4700          begin
4701             if Current_Verbosity = High then
4702                Write_Str ("checking directory """);
4703                Write_Str (Dir_Path);
4704                Write_Str (""" for ");
4705
4706                if Naming_Exceptions then
4707                   Write_Str ("naming exceptions");
4708
4709                else
4710                   Write_Str ("sources");
4711                end if;
4712
4713                Write_Str (" of Language ");
4714                Write_Line (Lang_Display_Names (Language).all);
4715             end if;
4716
4717             Open (Dir, Dir_Path);
4718
4719             loop
4720                Read (Dir, Name_Str, Last);
4721                exit when Last = 0;
4722
4723                if Is_Regular_File
4724                  (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4725                then
4726                   Name_Len := Last;
4727                   Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4728                   Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4729                   Canonical_Name := Name_Find;
4730                   NL := Source_Names.Get (Canonical_Name);
4731
4732                   if NL /= No_Name_Location then
4733                      if NL.Found then
4734                         if not Data.Known_Order_Of_Source_Dirs then
4735                            Error_Msg_Name_1 := Canonical_Name;
4736                            Error_Msg
4737                              (Project,
4738                               "{ is found in several source directories",
4739                               NL.Location);
4740                         end if;
4741
4742                      else
4743                         NL.Found := True;
4744                         Source_Names.Set (Canonical_Name, NL);
4745                         Name_Len := Dir_Path'Length;
4746                         Name_Buffer (1 .. Name_Len) := Dir_Path;
4747                         Add_Char_To_Name_Buffer (Directory_Separator);
4748                         Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4749                         Path := Name_Find;
4750
4751                         Check_For_Source
4752                           (File_Name        => Canonical_Name,
4753                            Path_Name        => Path,
4754                            Project          => Project,
4755                            Data             => Data,
4756                            Location         => NL.Location,
4757                            Language         => Language,
4758                            Suffix           => Suffix,
4759                            Naming_Exception => Naming_Exceptions);
4760                      end if;
4761                   end if;
4762                end if;
4763             end loop;
4764
4765             Close (Dir);
4766          end;
4767
4768          Source_Dir := Element.Next;
4769       end loop;
4770
4771       if not Naming_Exceptions then
4772
4773          NL := Source_Names.Get_First;
4774
4775          --  It is an error if a source file name in a source list or
4776          --  in a source list file is not found.
4777
4778          while NL /= No_Name_Location loop
4779             if not NL.Found then
4780                Err_Vars.Error_Msg_Name_1 := NL.Name;
4781
4782                if First_Error then
4783                   Error_Msg
4784                     (Project,
4785                      "source file { cannot be found",
4786                      NL.Location);
4787                   First_Error := False;
4788
4789                else
4790                   Error_Msg
4791                     (Project,
4792                      "\source file { cannot be found",
4793                      NL.Location);
4794                end if;
4795             end if;
4796
4797             NL := Source_Names.Get_Next;
4798          end loop;
4799
4800          --  Any naming exception of this language that is not in a list
4801          --  of sources must be removed.
4802
4803          declare
4804             Source_Id : Other_Source_Id := Data.First_Other_Source;
4805             Prev_Id   : Other_Source_Id := No_Other_Source;
4806             Source    : Other_Source;
4807          begin
4808             while Source_Id /= No_Other_Source loop
4809                Source := Other_Sources.Table (Source_Id);
4810
4811                if Source.Language = Language
4812                  and then Source.Naming_Exception
4813                then
4814                   if Current_Verbosity = High then
4815                      Write_Str ("Naming exception """);
4816                      Write_Str (Get_Name_String (Source.File_Name));
4817                      Write_Str (""" is not in the list of sources,");
4818                      Write_Line (" so it is removed.");
4819                   end if;
4820
4821                   if Prev_Id = No_Other_Source then
4822                      Data.First_Other_Source := Source.Next;
4823
4824                   else
4825                      Other_Sources.Table (Prev_Id).Next := Source.Next;
4826                   end if;
4827
4828                   Source_Id := Source.Next;
4829
4830                   if Source_Id = No_Other_Source then
4831                      Data.Last_Other_Source := Prev_Id;
4832                   end if;
4833
4834                else
4835                   Prev_Id := Source_Id;
4836                   Source_Id := Source.Next;
4837                end if;
4838             end loop;
4839          end;
4840       end if;
4841    end Record_Other_Sources;
4842
4843    ----------------------
4844    -- Show_Source_Dirs --
4845    ----------------------
4846
4847    procedure Show_Source_Dirs (Project : Project_Id) is
4848       Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4849       Element : String_Element;
4850
4851    begin
4852       Write_Line ("Source_Dirs:");
4853
4854       while Current /= Nil_String loop
4855          Element := String_Elements.Table (Current);
4856          Write_Str  ("   ");
4857          Write_Line (Get_Name_String (Element.Value));
4858          Current := Element.Next;
4859       end loop;
4860
4861       Write_Line ("end Source_Dirs.");
4862    end Show_Source_Dirs;
4863
4864    ----------------
4865    -- Suffix_For --
4866    ----------------
4867
4868    function Suffix_For
4869      (Language : Programming_Language;
4870       Naming   : Naming_Data) return Name_Id
4871    is
4872       Suffix : constant Variable_Value :=
4873         Value_Of
4874           (Index     => Lang_Name_Ids (Language),
4875            Src_Index => 0,
4876            In_Array  => Naming.Body_Suffix);
4877    begin
4878       --  If no suffix for this language is found in package Naming, use the
4879       --  default.
4880
4881       if Suffix = Nil_Variable_Value then
4882          Name_Len := 0;
4883          Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4884
4885       --  Otherwise use the one specified
4886
4887       else
4888          Get_Name_String (Suffix.Value);
4889       end if;
4890
4891       Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4892       return Name_Find;
4893    end Suffix_For;
4894
4895 end Prj.Nmsc;