OSDN Git Service

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