OSDN Git Service

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