1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2004 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Err_Vars; use Err_Vars;
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;
38 with Prj.Util; use Prj.Util;
40 with Snames; use Snames;
41 with Types; use Types;
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;
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;
53 package body Prj.Nmsc is
55 Error_Report : Put_Line_Access := null;
57 ALI_Suffix : constant String := ".ali";
59 type Name_Location is record
61 Location : Source_Ptr;
62 Found : Boolean := False;
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.
69 No_Name_Location : constant Name_Location :=
70 (Name => No_Name, Location => No_Location, Found => False);
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,
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.
84 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
85 (Header_Num => Header_Num,
91 -- Hash table to store recursive source directories, to avoid looking
92 -- several times, and to avoid cycles that may be introduced by symbolic
95 function ALI_File_Name (Source : String) return String;
96 -- Return the ALI file name corresponding to a source.
98 procedure Check_Ada_Naming_Scheme
99 (Project : Project_Id;
100 Naming : Naming_Data);
101 -- Check that the package Naming is correct.
103 procedure Check_Ada_Name
106 -- Check that a name is a valid Ada unit name.
109 (Project : Project_Id;
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
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.
126 function Is_Illegal_Suffix
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.
132 procedure Record_Source
133 (File_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.
143 procedure Show_Source_Dirs (Project : Project_Id);
144 -- List all the source directories of a project.
146 procedure Locate_Directory
150 Display : out Name_Id);
151 -- Locate a directory.
152 -- Returns No_Name if directory does not exist.
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.
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.
165 procedure Check_Naming_Scheme
166 (Data : in out Project_Data;
167 Project : Project_Id);
168 -- Check the naming scheme part of Data
170 type Unit_Info is record
174 No_Unit : constant Unit_Info := (Specification, No_Name);
176 package Naming_Exceptions is new GNAT.HTable.Simple_HTable
177 (Header_Num => Header_Num,
178 Element => Unit_Info,
179 No_Element => No_Unit,
184 function Hash (Unit : Unit_Info) return Header_Num;
186 package Reverse_Naming_Exceptions is new GNAT.HTable.Simple_HTable
187 (Header_Num => Header_Num,
189 No_Element => No_Name,
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.
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.
202 procedure Free_Naming_Exceptions;
203 -- Free the internal hash tables used for checking naming exceptions
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
209 ----------------------------
210 -- Compute_Directory_Last --
211 ----------------------------
213 function Compute_Directory_Last (Dir : String) return Natural is
216 and then (Dir (Dir'Last - 1) = Directory_Separator
217 or else Dir (Dir'Last - 1) = '/')
223 end Compute_Directory_Last;
226 -------------------------------
227 -- Prepare_Naming_Exceptions --
228 -------------------------------
230 procedure Prepare_Naming_Exceptions
231 (List : Array_Element_Id;
234 Current : Array_Element_Id := List;
235 Element : Array_Element;
238 while Current /= No_Array_Element loop
239 Element := Array_Elements.Table (Current);
241 if Element.Index /= No_Name then
242 Naming_Exceptions.Set
243 (Element.Value.Value,
244 (Kind => Kind, Unit => Element.Index));
245 Reverse_Naming_Exceptions.Set
246 ((Kind => Kind, Unit => Element.Index),
247 Element.Value.Value);
250 Current := Element.Next;
252 end Prepare_Naming_Exceptions;
258 function Hash (Unit : Unit_Info) return Header_Num is
260 return Header_Num (Unit.Unit mod 2048);
263 ----------------------------
264 -- Free_Naming_Exceptions --
265 ----------------------------
267 procedure Free_Naming_Exceptions is
269 Naming_Exceptions.Reset;
270 Reverse_Naming_Exceptions.Reset;
271 end Free_Naming_Exceptions;
273 -------------------------
274 -- Check_Naming_Scheme --
275 -------------------------
277 procedure Check_Naming_Scheme
278 (Data : in out Project_Data;
279 Project : Project_Id)
281 Naming_Id : constant Package_Id :=
282 Util.Value_Of (Name_Naming, Data.Decl.Packages);
284 Naming : Package_Element;
286 procedure Check_Unit_Names (List : Array_Element_Id);
287 -- Check that a list of unit names contains only valid names.
289 ----------------------
290 -- Check_Unit_Names --
291 ----------------------
293 procedure Check_Unit_Names (List : Array_Element_Id) is
294 Current : Array_Element_Id := List;
295 Element : Array_Element;
299 -- Loop through elements of the string list
301 while Current /= No_Array_Element loop
302 Element := Array_Elements.Table (Current);
304 -- Put file name in canonical case
306 Get_Name_String (Element.Value.Value);
307 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
308 Element.Value.Value := Name_Find;
310 -- Check that it contains a valid unit name
312 Get_Name_String (Element.Index);
313 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
315 if Unit_Name = No_Name then
316 Err_Vars.Error_Msg_Name_1 := Element.Index;
319 "{ is not a valid unit name.",
320 Element.Value.Location);
323 if Current_Verbosity = High then
324 Write_Str (" Unit (""");
325 Write_Str (Get_Name_String (Unit_Name));
329 Element.Index := Unit_Name;
330 Array_Elements.Table (Current) := Element;
333 Current := Element.Next;
335 end Check_Unit_Names;
337 -- Start of processing for Check_Naming_Scheme
340 -- If there is a package Naming, we will put in Data.Naming what is in
341 -- this package Naming.
343 if Naming_Id /= No_Package then
344 Naming := Packages.Table (Naming_Id);
346 if Current_Verbosity = High then
347 Write_Line ("Checking ""Naming"" for Ada.");
351 Bodies : constant Array_Element_Id :=
352 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
354 Specs : constant Array_Element_Id :=
355 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
358 if Bodies /= No_Array_Element then
360 -- We have elements in the array Body_Part
362 if Current_Verbosity = High then
363 Write_Line ("Found Bodies.");
366 Data.Naming.Bodies := Bodies;
367 Check_Unit_Names (Bodies);
370 if Current_Verbosity = High then
371 Write_Line ("No Bodies.");
375 if Specs /= No_Array_Element then
377 -- We have elements in the array Specs
379 if Current_Verbosity = High then
380 Write_Line ("Found Specs.");
383 Data.Naming.Specs := Specs;
384 Check_Unit_Names (Specs);
387 if Current_Verbosity = High then
388 Write_Line ("No Specs.");
393 -- We are now checking if variables Dot_Replacement, Casing,
394 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
397 -- For each variable, if it does not exist, we do nothing,
398 -- because we already have the default.
400 -- Check Dot_Replacement
403 Dot_Replacement : constant Variable_Value :=
405 (Name_Dot_Replacement,
406 Naming.Decl.Attributes);
409 pragma Assert (Dot_Replacement.Kind = Single,
410 "Dot_Replacement is not a single string");
412 if not Dot_Replacement.Default then
413 Get_Name_String (Dot_Replacement.Value);
418 "Dot_Replacement cannot be empty",
419 Dot_Replacement.Location);
422 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
423 Data.Naming.Dot_Replacement := Name_Find;
424 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
429 if Current_Verbosity = High then
430 Write_Str (" Dot_Replacement = """);
431 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
439 Casing_String : constant Variable_Value :=
441 (Name_Casing, Naming.Decl.Attributes);
444 pragma Assert (Casing_String.Kind = Single,
445 "Casing is not a single string");
447 if not Casing_String.Default then
449 Casing_Image : constant String :=
450 Get_Name_String (Casing_String.Value);
453 Casing : constant Casing_Type := Value (Casing_Image);
455 Data.Naming.Casing := Casing;
459 when Constraint_Error =>
460 if Casing_Image'Length = 0 then
463 "Casing cannot be an empty string",
464 Casing_String.Location);
467 Name_Len := Casing_Image'Length;
468 Name_Buffer (1 .. Name_Len) := Casing_Image;
469 Err_Vars.Error_Msg_Name_1 := Name_Find;
472 "{ is not a correct Casing",
473 Casing_String.Location);
479 if Current_Verbosity = High then
480 Write_Str (" Casing = ");
481 Write_Str (Image (Data.Naming.Casing));
489 Ada_Spec_Suffix : constant Variable_Value :=
492 In_Array => Data.Naming.Spec_Suffix);
495 if Ada_Spec_Suffix.Kind = Single
496 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
498 Data.Naming.Current_Spec_Suffix := Ada_Spec_Suffix.Value;
499 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
502 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
506 if Current_Verbosity = High then
507 Write_Str (" Spec_Suffix = """);
508 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
516 Ada_Body_Suffix : constant Variable_Value :=
519 In_Array => Data.Naming.Body_Suffix);
522 if Ada_Body_Suffix.Kind = Single
523 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
525 Data.Naming.Current_Body_Suffix := Ada_Body_Suffix.Value;
526 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
529 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
533 if Current_Verbosity = High then
534 Write_Str (" Body_Suffix = """);
535 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
540 -- Check Separate_Suffix
543 Ada_Sep_Suffix : constant Variable_Value :=
545 (Variable_Name => Name_Separate_Suffix,
546 In_Variables => Naming.Decl.Attributes);
549 if Ada_Sep_Suffix.Default then
550 Data.Naming.Separate_Suffix :=
551 Data.Naming.Current_Body_Suffix;
554 if Get_Name_String (Ada_Sep_Suffix.Value) = "" then
557 "Separate_Suffix cannot be empty",
558 Ada_Sep_Suffix.Location);
561 Data.Naming.Separate_Suffix := Ada_Sep_Suffix.Value;
562 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
567 if Current_Verbosity = High then
568 Write_Str (" Separate_Suffix = """);
569 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
574 -- Check if Data.Naming is valid
576 Check_Ada_Naming_Scheme (Project, Data.Naming);
579 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
580 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
581 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
583 end Check_Naming_Scheme;
590 (Project : Project_Id;
591 Report_Error : Put_Line_Access)
594 Languages : Variable_Value := Nil_Variable_Value;
596 Extending : Boolean := False;
598 function Check_Project (P : Project_Id) return Boolean;
599 -- Returns True if P is Project or a project extended by Project
601 procedure Find_Sources;
602 -- Find all the sources in all of the source directories
605 procedure Get_Path_Names_And_Record_Sources;
606 -- Find the path names of the source files in the Source_Names table
607 -- in the source directories and record those that are Ada sources.
609 procedure Get_Sources_From_File
611 Location : Source_Ptr);
612 -- Get the sources of a project from a text file
614 procedure Warn_If_Not_Sources
615 (Conventions : Array_Element_Id;
617 -- Check that individual naming conventions apply to immediate
618 -- sources of the project; if not, issue a warning.
624 function Check_Project (P : Project_Id) return Boolean is
630 Data : Project_Data := Projects.Table (Project);
633 while Data.Extends /= No_Project loop
634 if P = Data.Extends then
638 Data := Projects.Table (Data.Extends);
650 procedure Find_Sources is
651 Source_Dir : String_List_Id := Data.Source_Dirs;
652 Element : String_Element;
654 Current_Source : String_List_Id := Nil_String;
655 Source_Recorded : Boolean := False;
658 if Current_Verbosity = High then
659 Write_Line ("Looking for sources:");
662 -- For each subdirectory
664 while Source_Dir /= Nil_String loop
666 Source_Recorded := False;
667 Element := String_Elements.Table (Source_Dir);
668 if Element.Value /= No_Name then
670 Source_Directory : constant String :=
671 Get_Name_String (Element.Value);
674 if Current_Verbosity = High then
675 Write_Str ("Source_Dir = ");
676 Write_Line (Source_Directory);
679 -- We look to every entry in the source directory
681 Open (Dir, Source_Directory);
683 -- Canonical_Case_File_Name (Source_Directory);
686 Read (Dir, Name_Buffer, Name_Len);
688 if Current_Verbosity = High then
689 Write_Str (" Checking ");
690 Write_Line (Name_Buffer (1 .. Name_Len));
693 exit when Name_Len = 0;
695 -- Canonical_Case_File_Name
696 -- (Name_Buffer (1 .. Name_Len));
699 File_Name : constant Name_Id := Name_Find;
700 Dir : constant String :=
703 Dir_Last : constant Natural :=
704 Compute_Directory_Last (Dir);
705 Path : constant String :=
707 (Name => Name_Buffer (1 .. Name_Len),
708 Directory => Dir (Dir'First .. Dir_Last));
712 if Is_Regular_File (Path) then
714 Name_Len := Path'Length;
715 Name_Buffer (1 .. Name_Len) := Path;
716 Path_Name := Name_Find;
718 -- We attempt to register it as a source.
719 -- However, there is no error if the file
720 -- does not contain a valid source.
721 -- But there is an error if we have a
722 -- duplicate unit name.
725 (File_Name => File_Name,
726 Path_Name => Path_Name,
729 Location => No_Location,
730 Current_Source => Current_Source,
731 Source_Recorded => Source_Recorded);
741 when Directory_Error =>
745 if Source_Recorded then
746 String_Elements.Table (Source_Dir).Flag := True;
749 Source_Dir := Element.Next;
752 if Current_Verbosity = High then
753 Write_Line ("end Looking for sources.");
756 -- If we have looked for sources and found none, then
757 -- it is an error, except if it is an extending project.
758 -- If a non extending project is not supposed to contain
759 -- any source, then we never call Find_Sources.
761 if Current_Source /= Nil_String then
762 Data.Sources_Present := True;
764 elsif Data.Extends = No_Project then
767 "there are no Ada sources in this project",
772 ---------------------------------------
773 -- Get_Path_Names_And_Record_Sources --
774 ---------------------------------------
776 procedure Get_Path_Names_And_Record_Sources is
777 Source_Dir : String_List_Id := Data.Source_Dirs;
778 Element : String_Element;
783 Canonical_Name : Name_Id;
784 Name_Str : String (1 .. 1_024);
788 Current_Source : String_List_Id := Nil_String;
790 First_Error : Boolean := True;
792 Source_Recorded : Boolean := False;
795 -- We look in all source directories for this file name
797 while Source_Dir /= Nil_String loop
798 Source_Recorded := False;
799 Element := String_Elements.Table (Source_Dir);
802 Dir_Path : constant String := Get_Name_String (Element.Value);
804 if Current_Verbosity = High then
805 Write_Str ("checking directory """);
806 Write_Str (Dir_Path);
810 Open (Dir, Dir_Path);
813 Read (Dir, Name_Str, Last);
816 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
818 Canonical_Case_File_Name (Name_Str (1 .. Last));
820 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
821 Canonical_Name := Name_Find;
822 NL := Source_Names.Get (Canonical_Name);
824 if NL /= No_Name_Location and then not NL.Found then
826 Source_Names.Set (Canonical_Name, NL);
827 Name_Len := Dir_Path'Length;
828 Name_Buffer (1 .. Name_Len) := Dir_Path;
829 Add_Char_To_Name_Buffer (Directory_Separator);
830 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
833 if Current_Verbosity = High then
834 Write_Str (" found ");
835 Write_Line (Get_Name_String (Name));
838 -- Register the source if it is an Ada compilation unit..
845 Location => NL.Location,
846 Current_Source => Current_Source,
847 Source_Recorded => Source_Recorded);
854 if Source_Recorded then
855 String_Elements.Table (Source_Dir).Flag := True;
858 Source_Dir := Element.Next;
861 -- It is an error if a source file name in a source list or
862 -- in a source list file is not found.
864 NL := Source_Names.Get_First;
866 while NL /= No_Name_Location loop
868 Err_Vars.Error_Msg_Name_1 := NL.Name;
873 "source file { cannot be found",
875 First_Error := False;
880 "\source file { cannot be found",
885 NL := Source_Names.Get_Next;
887 end Get_Path_Names_And_Record_Sources;
889 ---------------------------
890 -- Get_Sources_From_File --
891 ---------------------------
893 procedure Get_Sources_From_File
895 Location : Source_Ptr)
897 File : Prj.Util.Text_File;
898 Line : String (1 .. 250);
900 Source_Name : Name_Id;
903 if Current_Verbosity = High then
904 Write_Str ("Opening """);
911 Prj.Util.Open (File, Path);
913 if not Prj.Util.Is_Valid (File) then
914 Error_Msg (Project, "file does not exist", Location);
918 while not Prj.Util.End_Of_File (File) loop
919 Prj.Util.Get_Line (File, Line, Last);
921 -- If the line is not empty and does not start with "--",
922 -- then it should contain a file name. However, if the
923 -- file name does not exist, it may be for another language
924 -- and we don't fail.
927 and then (Last = 1 or else Line (1 .. 2) /= "--")
930 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
931 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
932 Source_Name := Name_Find;
936 (Name => Source_Name,
937 Location => Location,
942 Prj.Util.Close (File);
946 Get_Path_Names_And_Record_Sources;
948 -- We should have found at least one source.
949 -- If not, report an error.
951 if Data.Sources = Nil_String then
953 "there are no Ada sources in this project",
956 end Get_Sources_From_File;
958 -------------------------
959 -- Warn_If_Not_Sources --
960 -------------------------
962 procedure Warn_If_Not_Sources
963 (Conventions : Array_Element_Id;
966 Conv : Array_Element_Id := Conventions;
968 The_Unit_Id : Unit_Id;
969 The_Unit_Data : Unit_Data;
970 Location : Source_Ptr;
973 while Conv /= No_Array_Element loop
974 Unit := Array_Elements.Table (Conv).Index;
975 Error_Msg_Name_1 := Unit;
976 Get_Name_String (Unit);
977 To_Lower (Name_Buffer (1 .. Name_Len));
979 The_Unit_Id := Units_Htable.Get (Unit);
980 Location := Array_Elements.Table (Conv).Value.Location;
982 if The_Unit_Id = Prj.Com.No_Unit then
989 The_Unit_Data := Units.Table (The_Unit_Id);
993 (The_Unit_Data.File_Names (Specification).Project)
997 "?unit{ has no spec in this project",
1002 if not Check_Project
1003 (The_Unit_Data.File_Names (Com.Body_Part).Project)
1007 "?unit{ has no body in this project",
1013 Conv := Array_Elements.Table (Conv).Next;
1015 end Warn_If_Not_Sources;
1017 -- Start of processing for Ada_Check
1020 Language_Independent_Check (Project, Report_Error);
1022 Error_Report := Report_Error;
1024 Data := Projects.Table (Project);
1025 Extending := Data.Extends /= No_Project;
1026 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
1028 Data.Naming.Current_Language := Name_Ada;
1029 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
1031 if not Languages.Default then
1033 Current : String_List_Id := Languages.Values;
1034 Element : String_Element;
1035 Ada_Found : Boolean := False;
1038 Look_For_Ada : while Current /= Nil_String loop
1039 Element := String_Elements.Table (Current);
1040 Get_Name_String (Element.Value);
1041 To_Lower (Name_Buffer (1 .. Name_Len));
1043 if Name_Buffer (1 .. Name_Len) = "ada" then
1048 Current := Element.Next;
1049 end loop Look_For_Ada;
1051 if not Ada_Found then
1053 -- Mark the project file as having no sources for Ada
1055 Data.Sources_Present := False;
1060 Check_Naming_Scheme (Data, Project);
1062 Prepare_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
1063 Prepare_Naming_Exceptions (Data.Naming.Specs, Specification);
1065 -- If we have source directories, then find the sources
1067 if Data.Sources_Present then
1068 if Data.Source_Dirs = Nil_String then
1069 Data.Sources_Present := False;
1073 Sources : constant Variable_Value :=
1076 Data.Decl.Attributes);
1078 Source_List_File : constant Variable_Value :=
1080 (Name_Source_List_File,
1081 Data.Decl.Attributes);
1083 Locally_Removed : constant Variable_Value :=
1085 (Name_Locally_Removed_Files,
1086 Data.Decl.Attributes);
1091 (Sources.Kind = List,
1092 "Source_Files is not a list");
1095 (Source_List_File.Kind = Single,
1096 "Source_List_File is not a single string");
1098 if not Sources.Default then
1099 if not Source_List_File.Default then
1102 "?both variables source_files and " &
1103 "source_list_file are present",
1104 Source_List_File.Location);
1107 -- Sources is a list of file names
1110 Current : String_List_Id := Sources.Values;
1111 Element : String_Element;
1112 Location : Source_Ptr;
1118 Data.Sources_Present := Current /= Nil_String;
1120 while Current /= Nil_String loop
1121 Element := String_Elements.Table (Current);
1122 Get_Name_String (Element.Value);
1123 Canonical_Case_File_Name
1124 (Name_Buffer (1 .. Name_Len));
1127 -- If the element has no location, then use the
1128 -- location of Sources to report possible errors.
1130 if Element.Location = No_Location then
1131 Location := Sources.Location;
1134 Location := Element.Location;
1141 Location => Location,
1144 Current := Element.Next;
1147 Get_Path_Names_And_Record_Sources;
1150 -- No source_files specified.
1151 -- We check Source_List_File has been specified.
1153 elsif not Source_List_File.Default then
1155 -- Source_List_File is the name of the file
1156 -- that contains the source file names
1159 Source_File_Path_Name : constant String :=
1161 (Source_List_File.Value,
1165 if Source_File_Path_Name'Length = 0 then
1166 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
1169 "file with sources { does not exist",
1170 Source_List_File.Location);
1173 Get_Sources_From_File
1174 (Source_File_Path_Name,
1175 Source_List_File.Location);
1180 -- Neither Source_Files nor Source_List_File has been
1182 -- Find all the files that satisfy
1183 -- the naming scheme in all the source directories.
1188 -- If there are sources that are locally removed, mark them as
1189 -- such in the Units table.
1191 if not Locally_Removed.Default then
1192 -- Sources can be locally removed only in extending
1195 if Data.Extends = No_Project then
1198 "Locally_Removed_Files can only be used " &
1199 "in an extending project file",
1200 Locally_Removed.Location);
1204 Current : String_List_Id :=
1205 Locally_Removed.Values;
1206 Element : String_Element;
1207 Location : Source_Ptr;
1211 Extended : Project_Id;
1214 while Current /= Nil_String loop
1215 Element := String_Elements.Table (Current);
1216 Get_Name_String (Element.Value);
1217 Canonical_Case_File_Name
1218 (Name_Buffer (1 .. Name_Len));
1221 -- If the element has no location, then use the
1222 -- location of Locally_Removed to report
1225 if Element.Location = No_Location then
1226 Location := Locally_Removed.Location;
1229 Location := Element.Location;
1234 for Index in 1 .. Units.Last loop
1235 Unit := Units.Table (Index);
1238 Unit.File_Names (Specification).Name = Name
1242 -- Check that this is from a project that
1243 -- the current project extends, but not the
1246 Extended := Unit.File_Names
1247 (Specification).Project;
1249 if Extended = Project then
1252 "cannot remove a source " &
1253 "of the same project",
1257 Project_Extends (Project, Extended)
1260 (Specification).Path := Slash;
1262 (Specification).Needs_Pragma := False;
1263 Units.Table (Index) := Unit;
1264 Add_Forbidden_File_Name
1265 (Unit.File_Names (Specification).Name);
1271 "cannot remove a source from " &
1277 Unit.File_Names (Body_Part).Name = Name
1281 -- Check that this is from a project that
1282 -- the current project extends, but not the
1285 Extended := Unit.File_Names
1286 (Body_Part).Project;
1288 if Extended = Project then
1291 "cannot remove a source " &
1292 "of the same project",
1296 Project_Extends (Project, Extended)
1298 Unit.File_Names (Body_Part).Path := Slash;
1299 Unit.File_Names (Body_Part).Needs_Pragma
1301 Units.Table (Index) := Unit;
1302 Add_Forbidden_File_Name
1303 (Unit.File_Names (Body_Part).Name);
1311 Err_Vars.Error_Msg_Name_1 := Name;
1312 Error_Msg (Project, "unknown file {", Location);
1315 Current := Element.Next;
1324 if Data.Sources_Present then
1326 -- Check that all individual naming conventions apply to
1327 -- sources of this project file.
1329 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
1330 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
1333 -- If it is a library project file, check if it is a standalone library
1335 if Data.Library then
1336 Standalone_Library : declare
1337 Lib_Interfaces : constant Prj.Variable_Value :=
1339 (Snames.Name_Library_Interface,
1340 Data.Decl.Attributes);
1341 Lib_Auto_Init : constant Prj.Variable_Value :=
1343 (Snames.Name_Library_Auto_Init,
1344 Data.Decl.Attributes);
1346 Lib_Src_Dir : constant Prj.Variable_Value :=
1348 (Snames.Name_Library_Src_Dir,
1349 Data.Decl.Attributes);
1351 Lib_Symbol_File : constant Prj.Variable_Value :=
1353 (Snames.Name_Library_Symbol_File,
1354 Data.Decl.Attributes);
1356 Lib_Symbol_Policy : constant Prj.Variable_Value :=
1358 (Snames.Name_Library_Symbol_Policy,
1359 Data.Decl.Attributes);
1361 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
1363 (Snames.Name_Library_Reference_Symbol_File,
1364 Data.Decl.Attributes);
1366 Auto_Init_Supported : constant Boolean :=
1368 Standalone_Library_Auto_Init_Is_Supported;
1370 OK : Boolean := True;
1373 pragma Assert (Lib_Interfaces.Kind = List);
1375 -- It is a stand-alone library project file if attribute
1376 -- Library_Interface is defined.
1378 if not Lib_Interfaces.Default then
1380 Interfaces : String_List_Id := Lib_Interfaces.Values;
1381 Interface_ALIs : String_List_Id := Nil_String;
1383 The_Unit_Id : Unit_Id;
1384 The_Unit_Data : Unit_Data;
1386 procedure Add_ALI_For (Source : Name_Id);
1387 -- Add an ALI file name to the list of Interface ALIs
1393 procedure Add_ALI_For (Source : Name_Id) is
1395 Get_Name_String (Source);
1398 ALI : constant String :=
1399 ALI_File_Name (Name_Buffer (1 .. Name_Len));
1400 ALI_Name_Id : Name_Id;
1402 Name_Len := ALI'Length;
1403 Name_Buffer (1 .. Name_Len) := ALI;
1404 ALI_Name_Id := Name_Find;
1406 String_Elements.Increment_Last;
1407 String_Elements.Table (String_Elements.Last) :=
1408 (Value => ALI_Name_Id,
1409 Display_Value => ALI_Name_Id,
1410 Location => String_Elements.Table
1411 (Interfaces).Location,
1413 Next => Interface_ALIs);
1414 Interface_ALIs := String_Elements.Last;
1419 Data.Standalone_Library := True;
1421 -- Library_Interface cannot be an empty list
1423 if Interfaces = Nil_String then
1426 "Library_Interface cannot be an empty list",
1427 Lib_Interfaces.Location);
1430 -- Process each unit name specified in the attribute
1431 -- Library_Interface.
1433 while Interfaces /= Nil_String loop
1435 (String_Elements.Table (Interfaces).Value);
1436 To_Lower (Name_Buffer (1 .. Name_Len));
1438 if Name_Len = 0 then
1441 "an interface cannot be an empty string",
1442 String_Elements.Table (Interfaces).Location);
1446 Error_Msg_Name_1 := Unit;
1447 The_Unit_Id := Units_Htable.Get (Unit);
1449 if The_Unit_Id = Prj.Com.No_Unit then
1453 String_Elements.Table (Interfaces).Location);
1456 -- Check that the unit is part of the project
1458 The_Unit_Data := Units.Table (The_Unit_Id);
1460 if The_Unit_Data.File_Names
1461 (Com.Body_Part).Name /= No_Name
1462 and then The_Unit_Data.File_Names
1463 (Com.Body_Part).Path /= Slash
1466 (The_Unit_Data.File_Names (Body_Part).Project)
1468 -- There is a body for this unit.
1469 -- If there is no spec, we need to check
1470 -- that it is not a subunit.
1472 if The_Unit_Data.File_Names
1473 (Specification).Name = No_Name
1476 Src_Ind : Source_File_Index;
1479 Src_Ind := Sinput.P.Load_Project_File
1481 (The_Unit_Data.File_Names
1484 if Sinput.P.Source_File_Is_Subunit
1489 "{ is a subunit; " &
1490 "it cannot be an interface",
1491 String_Elements.Table
1492 (Interfaces).Location);
1497 -- The unit is not a subunit, so we add
1498 -- to the Interface ALIs the ALI file
1499 -- corresponding to the body.
1502 (The_Unit_Data.File_Names (Body_Part).Name);
1507 "{ is not an unit of this project",
1508 String_Elements.Table
1509 (Interfaces).Location);
1512 elsif The_Unit_Data.File_Names
1513 (Com.Specification).Name /= No_Name
1514 and then The_Unit_Data.File_Names
1515 (Com.Specification).Path /= Slash
1516 and then Check_Project
1517 (The_Unit_Data.File_Names
1518 (Specification).Project)
1521 -- The unit is part of the project, it has
1522 -- a spec, but no body. We add to the Interface
1523 -- ALIs the ALI file corresponding to the spec.
1526 (The_Unit_Data.File_Names (Specification).Name);
1531 "{ is not an unit of this project",
1532 String_Elements.Table (Interfaces).Location);
1538 Interfaces := String_Elements.Table (Interfaces).Next;
1541 -- Put the list of Interface ALIs in the project data
1543 Data.Lib_Interface_ALIs := Interface_ALIs;
1545 -- Check value of attribute Library_Auto_Init and set
1546 -- Lib_Auto_Init accordingly.
1548 if Lib_Auto_Init.Default then
1549 -- If no attribute Library_Auto_Init is declared, then
1550 -- set auto init only if it is supported.
1552 Data.Lib_Auto_Init := Auto_Init_Supported;
1555 Get_Name_String (Lib_Auto_Init.Value);
1556 To_Lower (Name_Buffer (1 .. Name_Len));
1558 if Name_Buffer (1 .. Name_Len) = "false" then
1559 Data.Lib_Auto_Init := False;
1561 elsif Name_Buffer (1 .. Name_Len) = "true" then
1562 if Auto_Init_Supported then
1563 Data.Lib_Auto_Init := True;
1566 -- Library_Auto_Init cannot be "true" if auto init
1571 "library auto init not supported " &
1573 Lib_Auto_Init.Location);
1579 "invalid value for attribute Library_Auto_Init",
1580 Lib_Auto_Init.Location);
1585 -- If attribute Library_Src_Dir is defined and not the
1586 -- empty string, check if the directory exist and is not
1587 -- the object directory or one of the source directories.
1588 -- This is the directory where copies of the interface
1589 -- sources will be copied. Note that this directory may be
1590 -- the library directory.
1592 if Lib_Src_Dir.Value /= Empty_String then
1594 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1598 (Dir_Id, Data.Display_Directory,
1599 Data.Library_Src_Dir,
1600 Data.Display_Library_Src_Dir);
1602 -- If directory does not exist, report an error
1604 if Data.Library_Src_Dir = No_Name then
1606 -- Get the absolute name of the library directory
1607 -- that does not exist, to report an error.
1610 Dir_Name : constant String :=
1611 Get_Name_String (Dir_Id);
1614 if Is_Absolute_Path (Dir_Name) then
1615 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1618 Get_Name_String (Data.Directory);
1620 if Name_Buffer (Name_Len) /=
1623 Name_Len := Name_Len + 1;
1624 Name_Buffer (Name_Len) :=
1625 Directory_Separator;
1630 Name_Len + Dir_Name'Length) :=
1632 Name_Len := Name_Len + Dir_Name'Length;
1633 Err_Vars.Error_Msg_Name_1 := Name_Find;
1640 "Directory { does not exist",
1641 Lib_Src_Dir.Location);
1644 -- Report an error if it is the same as the object
1647 elsif Data.Library_Src_Dir = Data.Object_Directory then
1650 "directory to copy interfaces cannot be " &
1651 "the object directory",
1652 Lib_Src_Dir.Location);
1653 Data.Library_Src_Dir := No_Name;
1655 -- Check if it is the same as one of the source
1660 Src_Dirs : String_List_Id := Data.Source_Dirs;
1661 Src_Dir : String_Element;
1664 while Src_Dirs /= Nil_String loop
1665 Src_Dir := String_Elements.Table (Src_Dirs);
1666 Src_Dirs := Src_Dir.Next;
1668 -- Report an error if it is one of the
1669 -- source directories.
1671 if Data.Library_Src_Dir = Src_Dir.Value then
1674 "directory to copy interfaces cannot " &
1675 "be one of the source directories",
1676 Lib_Src_Dir.Location);
1677 Data.Library_Src_Dir := No_Name;
1683 if Data.Library_Src_Dir /= No_Name
1684 and then Current_Verbosity = High
1686 Write_Str ("Directory to copy interfaces =""");
1687 Write_Str (Get_Name_String (Data.Library_Dir));
1694 if not Lib_Symbol_File.Default then
1695 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1697 Get_Name_String (Lib_Symbol_File.Value);
1699 if Name_Len = 0 then
1702 "symbol file name cannot be an empty string",
1703 Lib_Symbol_File.Location);
1706 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1709 for J in 1 .. Name_Len loop
1710 if Name_Buffer (J) = '/'
1711 or else Name_Buffer (J) = Directory_Separator
1720 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1723 "symbol file name { is illegal. " &
1724 "Name canot include directory info.",
1725 Lib_Symbol_File.Location);
1730 if not Lib_Symbol_Policy.Default then
1732 Value : constant String :=
1734 (Get_Name_String (Lib_Symbol_Policy.Value));
1737 if Value = "autonomous" or else Value = "default" then
1738 Data.Symbol_Data.Symbol_Policy := Autonomous;
1740 elsif Value = "compliant" then
1741 Data.Symbol_Data.Symbol_Policy := Compliant;
1743 elsif Value = "controlled" then
1744 Data.Symbol_Data.Symbol_Policy := Controlled;
1749 "illegal value for Library_Symbol_Policy",
1750 Lib_Symbol_Policy.Location);
1755 if Lib_Ref_Symbol_File.Default then
1756 if Data.Symbol_Data.Symbol_Policy /= Autonomous then
1759 "a reference symbol file need to be defined",
1760 Lib_Symbol_Policy.Location);
1764 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1766 Get_Name_String (Lib_Symbol_File.Value);
1768 if Name_Len = 0 then
1771 "reference symbol file name cannot be an empty string",
1772 Lib_Symbol_File.Location);
1775 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1778 for J in 1 .. Name_Len loop
1779 if Name_Buffer (J) = '/'
1780 or else Name_Buffer (J) = Directory_Separator
1789 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1792 "reference symbol file { name is illegal. " &
1793 "Name canot include directory info.",
1794 Lib_Ref_Symbol_File.Location);
1797 if not Is_Regular_File
1798 (Get_Name_String (Data.Object_Directory) &
1799 Directory_Separator &
1800 Get_Name_String (Lib_Ref_Symbol_File.Value))
1802 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1805 "library reference symbol file { does not exist",
1806 Lib_Ref_Symbol_File.Location);
1809 if Data.Symbol_Data.Symbol_File /= No_Name then
1813 (Data.Symbol_Data.Symbol_File);
1815 Reference : String :=
1817 (Data.Symbol_Data.Reference);
1820 Canonical_Case_File_Name (Symbol);
1821 Canonical_Case_File_Name (Reference);
1823 if Symbol = Reference then
1826 "reference symbol file and symbol file " &
1827 "cannot be the same file",
1828 Lib_Ref_Symbol_File.Location);
1835 end Standalone_Library;
1838 -- Put the list of Mains, if any, in the project data
1841 Mains : constant Variable_Value :=
1842 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
1845 Data.Mains := Mains.Values;
1847 -- If no Mains were specified, and if we are an extending
1848 -- project, inherit the Mains from the project we are extending.
1850 if Mains.Default then
1851 if Data.Extends /= No_Project then
1852 Data.Mains := Projects.Table (Data.Extends).Mains;
1855 -- In a library project file, Main cannot be specified
1857 elsif Data.Library then
1860 "a library project file cannot have Main specified",
1865 Projects.Table (Project) := Data;
1867 Free_Naming_Exceptions;
1874 function ALI_File_Name (Source : String) return String is
1876 -- If the source name has an extension, then replace it with
1879 for Index in reverse Source'First + 1 .. Source'Last loop
1880 if Source (Index) = '.' then
1881 return Source (Source'First .. Index - 1) & ALI_Suffix;
1885 -- If there is no dot, or if it is the first character, just add the
1888 return Source & ALI_Suffix;
1891 --------------------
1892 -- Check_Ada_Name --
1893 --------------------
1895 procedure Check_Ada_Name
1899 The_Name : String := Name;
1900 Real_Name : Name_Id;
1901 Need_Letter : Boolean := True;
1902 Last_Underscore : Boolean := False;
1903 OK : Boolean := The_Name'Length > 0;
1906 To_Lower (The_Name);
1908 Name_Len := The_Name'Length;
1909 Name_Buffer (1 .. Name_Len) := The_Name;
1910 Real_Name := Name_Find;
1912 -- Check first that the given name is not an Ada reserved word
1914 if Get_Name_Table_Byte (Real_Name) /= 0
1915 and then Real_Name /= Name_Project
1916 and then Real_Name /= Name_Extends
1917 and then Real_Name /= Name_External
1921 if Current_Verbosity = High then
1922 Write_Str (The_Name);
1923 Write_Line (" is an Ada reserved word.");
1929 for Index in The_Name'Range loop
1932 -- We need a letter (at the beginning, and following a dot),
1933 -- but we don't have one.
1935 if Is_Letter (The_Name (Index)) then
1936 Need_Letter := False;
1941 if Current_Verbosity = High then
1942 Write_Int (Types.Int (Index));
1944 Write_Char (The_Name (Index));
1945 Write_Line ("' is not a letter.");
1951 elsif Last_Underscore
1952 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1954 -- Two underscores are illegal, and a dot cannot follow
1959 if Current_Verbosity = High then
1960 Write_Int (Types.Int (Index));
1962 Write_Char (The_Name (Index));
1963 Write_Line ("' is illegal here.");
1968 elsif The_Name (Index) = '.' then
1970 -- We need a letter after a dot
1972 Need_Letter := True;
1974 elsif The_Name (Index) = '_' then
1975 Last_Underscore := True;
1978 -- We need an letter or a digit
1980 Last_Underscore := False;
1982 if not Is_Alphanumeric (The_Name (Index)) then
1985 if Current_Verbosity = High then
1986 Write_Int (Types.Int (Index));
1988 Write_Char (The_Name (Index));
1989 Write_Line ("' is not alphanumeric.");
1997 -- Cannot end with an underscore or a dot
1999 OK := OK and then not Need_Letter and then not Last_Underscore;
2005 -- Signal a problem with No_Name
2011 -----------------------------
2012 -- Check_Ada_Naming_Scheme --
2013 -----------------------------
2015 procedure Check_Ada_Naming_Scheme
2016 (Project : Project_Id;
2017 Naming : Naming_Data)
2020 -- Only check if we are not using the standard naming scheme
2022 if Naming /= Standard_Naming_Data then
2024 Dot_Replacement : constant String :=
2026 (Naming.Dot_Replacement);
2028 Spec_Suffix : constant String :=
2030 (Naming.Current_Spec_Suffix);
2032 Body_Suffix : constant String :=
2034 (Naming.Current_Body_Suffix);
2036 Separate_Suffix : constant String :=
2038 (Naming.Separate_Suffix);
2041 -- Dot_Replacement cannot
2043 -- - start or end with an alphanumeric
2044 -- - be a single '_'
2045 -- - start with an '_' followed by an alphanumeric
2046 -- - contain a '.' except if it is "."
2048 if Dot_Replacement'Length = 0
2049 or else Is_Alphanumeric
2050 (Dot_Replacement (Dot_Replacement'First))
2051 or else Is_Alphanumeric
2052 (Dot_Replacement (Dot_Replacement'Last))
2053 or else (Dot_Replacement (Dot_Replacement'First) = '_'
2055 (Dot_Replacement'Length = 1
2058 (Dot_Replacement (Dot_Replacement'First + 1))))
2059 or else (Dot_Replacement'Length > 1
2061 Index (Source => Dot_Replacement,
2062 Pattern => ".") /= 0)
2066 '"' & Dot_Replacement &
2067 """ is illegal for Dot_Replacement.",
2068 Naming.Dot_Repl_Loc);
2074 if Is_Illegal_Suffix
2075 (Spec_Suffix, Dot_Replacement = ".")
2077 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
2080 "{ is illegal for Spec_Suffix",
2081 Naming.Spec_Suffix_Loc);
2084 if Is_Illegal_Suffix
2085 (Body_Suffix, Dot_Replacement = ".")
2087 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
2090 "{ is illegal for Body_Suffix",
2091 Naming.Body_Suffix_Loc);
2094 if Body_Suffix /= Separate_Suffix then
2095 if Is_Illegal_Suffix
2096 (Separate_Suffix, Dot_Replacement = ".")
2098 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
2101 "{ is illegal for Separate_Suffix",
2102 Naming.Sep_Suffix_Loc);
2106 -- Spec_Suffix cannot have the same termination as
2107 -- Body_Suffix or Separate_Suffix
2109 if Spec_Suffix'Length <= Body_Suffix'Length
2111 Body_Suffix (Body_Suffix'Last -
2112 Spec_Suffix'Length + 1 ..
2113 Body_Suffix'Last) = Spec_Suffix
2119 """) cannot end with" &
2120 " Spec_Suffix (""" &
2121 Spec_Suffix & """).",
2122 Naming.Body_Suffix_Loc);
2125 if Body_Suffix /= Separate_Suffix
2126 and then Spec_Suffix'Length <= Separate_Suffix'Length
2129 (Separate_Suffix'Last - Spec_Suffix'Length + 1
2131 Separate_Suffix'Last) = Spec_Suffix
2135 "Separate_Suffix (""" &
2137 """) cannot end with" &
2138 " Spec_Suffix (""" &
2139 Spec_Suffix & """).",
2140 Naming.Sep_Suffix_Loc);
2144 end Check_Ada_Naming_Scheme;
2151 (Project : Project_Id;
2153 Flag_Location : Source_Ptr)
2155 Error_Buffer : String (1 .. 5_000);
2156 Error_Last : Natural := 0;
2157 Msg_Name : Natural := 0;
2158 First : Positive := Msg'First;
2160 procedure Add (C : Character);
2161 -- Add a character to the buffer
2163 procedure Add (S : String);
2164 -- Add a string to the buffer
2166 procedure Add (Id : Name_Id);
2167 -- Add a name to the buffer
2173 procedure Add (C : Character) is
2175 Error_Last := Error_Last + 1;
2176 Error_Buffer (Error_Last) := C;
2179 procedure Add (S : String) is
2181 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2182 Error_Last := Error_Last + S'Length;
2185 procedure Add (Id : Name_Id) is
2187 Get_Name_String (Id);
2188 Add (Name_Buffer (1 .. Name_Len));
2191 -- Start of processing for Error_Msg
2194 if Error_Report = null then
2195 Prj.Err.Error_Msg (Msg, Flag_Location);
2199 if Msg (First) = '\' then
2201 -- Continuation character, ignore.
2205 elsif Msg (First) = '?' then
2207 -- Warning character. It is always the first one in this package
2213 for Index in First .. Msg'Last loop
2214 if Msg (Index) = '{' or else Msg (Index) = '%' then
2216 -- Include a name between double quotes.
2218 Msg_Name := Msg_Name + 1;
2222 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2223 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2224 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2226 when others => null;
2237 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2245 (Canonical_File_Name : Name_Id;
2246 Naming : Naming_Data;
2247 Unit_Name : out Name_Id;
2248 Unit_Kind : out Spec_Or_Body;
2249 Needs_Pragma : out Boolean)
2251 function Check_Exception (Canonical : Name_Id) return Boolean;
2252 pragma Inline (Check_Exception);
2253 -- Check if Canonical is one of the exceptions in List.
2254 -- Returns True if Get_Unit should exit
2256 ---------------------
2257 -- Check_Exception --
2258 ---------------------
2260 function Check_Exception (Canonical : Name_Id) return Boolean is
2261 Info : Unit_Info := Naming_Exceptions.Get (Canonical);
2265 if Info = No_Unit then
2266 if Hostparm.OpenVMS then
2267 VMS_Name := Canonical;
2268 Get_Name_String (VMS_Name);
2270 if Name_Buffer (Name_Len) = '.' then
2271 Name_Len := Name_Len - 1;
2272 VMS_Name := Name_Find;
2275 Info := Naming_Exceptions.Get (VMS_Name);
2278 if Info = No_Unit then
2283 Unit_Kind := Info.Kind;
2284 Unit_Name := Info.Unit;
2285 Needs_Pragma := True;
2287 end Check_Exception;
2289 -- Start of processing for Get_Unit
2292 Needs_Pragma := False;
2294 if Check_Exception (Canonical_File_Name) then
2298 Get_Name_String (Canonical_File_Name);
2301 File : String := Name_Buffer (1 .. Name_Len);
2302 First : constant Positive := File'First;
2303 Last : Natural := File'Last;
2304 Standard_GNAT : Boolean;
2308 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2309 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2311 -- Check if the end of the file name is Specification_Append
2313 Get_Name_String (Naming.Current_Spec_Suffix);
2315 if File'Length > Name_Len
2316 and then File (Last - Name_Len + 1 .. Last) =
2317 Name_Buffer (1 .. Name_Len)
2321 Unit_Kind := Specification;
2322 Last := Last - Name_Len;
2324 if Current_Verbosity = High then
2325 Write_Str (" Specification: ");
2326 Write_Line (File (First .. Last));
2330 Get_Name_String (Naming.Current_Body_Suffix);
2332 -- Check if the end of the file name is Body_Append
2334 if File'Length > Name_Len
2335 and then File (Last - Name_Len + 1 .. Last) =
2336 Name_Buffer (1 .. Name_Len)
2340 Unit_Kind := Body_Part;
2341 Last := Last - Name_Len;
2343 if Current_Verbosity = High then
2344 Write_Str (" Body: ");
2345 Write_Line (File (First .. Last));
2348 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2349 Get_Name_String (Naming.Separate_Suffix);
2351 -- Check if the end of the file name is Separate_Append
2353 if File'Length > Name_Len
2354 and then File (Last - Name_Len + 1 .. Last) =
2355 Name_Buffer (1 .. Name_Len)
2357 -- We have a separate (a body)
2359 Unit_Kind := Body_Part;
2360 Last := Last - Name_Len;
2362 if Current_Verbosity = High then
2363 Write_Str (" Separate: ");
2364 Write_Line (File (First .. Last));
2378 -- This is not a source file
2380 Unit_Name := No_Name;
2381 Unit_Kind := Specification;
2383 if Current_Verbosity = High then
2384 Write_Line (" Not a valid file name.");
2390 Get_Name_String (Naming.Dot_Replacement);
2392 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2394 if Name_Buffer (1 .. Name_Len) /= "." then
2396 -- If Dot_Replacement is not a single dot,
2397 -- then there should not be any dot in the name.
2399 for Index in First .. Last loop
2400 if File (Index) = '.' then
2401 if Current_Verbosity = High then
2403 (" Not a valid file name (some dot not replaced).");
2406 Unit_Name := No_Name;
2412 -- Replace the substring Dot_Replacement with dots
2415 Index : Positive := First;
2418 while Index <= Last - Name_Len + 1 loop
2420 if File (Index .. Index + Name_Len - 1) =
2421 Name_Buffer (1 .. Name_Len)
2423 File (Index) := '.';
2425 if Name_Len > 1 and then Index < Last then
2426 File (Index + 1 .. Last - Name_Len + 1) :=
2427 File (Index + Name_Len .. Last);
2430 Last := Last - Name_Len + 1;
2438 -- Check if the casing is right
2441 Src : String := File (First .. Last);
2444 case Naming.Casing is
2445 when All_Lower_Case =>
2448 Mapping => Lower_Case_Map);
2450 when All_Upper_Case =>
2453 Mapping => Upper_Case_Map);
2455 when Mixed_Case | Unknown =>
2459 if Src /= File (First .. Last) then
2460 if Current_Verbosity = High then
2461 Write_Line (" Not a valid file name (casing).");
2464 Unit_Name := No_Name;
2468 -- We put the name in lower case
2472 Mapping => Lower_Case_Map);
2474 -- In the standard GNAT naming scheme, check for special cases:
2475 -- children or separates of A, G, I or S, and run time sources.
2477 if Standard_GNAT and then Src'Length >= 3 then
2479 S1 : constant Character := Src (Src'First);
2480 S2 : constant Character := Src (Src'First + 1);
2483 if S1 = 'a' or else S1 = 'g'
2484 or else S1 = 'i' or else S1 = 's'
2486 -- Children or separates of packages A, G, I or S
2488 if (Hostparm.OpenVMS and then S2 = '$')
2489 or else (not Hostparm.OpenVMS and then S2 = '~')
2491 Src (Src'First + 1) := '.';
2493 -- If it is potentially a run time source, disable
2494 -- filling of the mapping file to avoid warnings.
2497 Set_Mapping_File_Initial_State_To_Empty;
2504 if Current_Verbosity = High then
2509 -- Now, we check if this name is a valid unit name
2511 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2517 -----------------------
2518 -- Is_Illegal_Suffix --
2519 -----------------------
2521 function Is_Illegal_Suffix
2523 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2526 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2530 -- If dot replacement is a single dot, and first character of
2531 -- suffix is also a dot
2533 if Dot_Replacement_Is_A_Single_Dot
2534 and then Suffix (Suffix'First) = '.'
2536 for Index in Suffix'First + 1 .. Suffix'Last loop
2538 -- If there is another dot
2540 if Suffix (Index) = '.' then
2542 -- It is illegal to have a letter following the initial dot
2544 return Is_Letter (Suffix (Suffix'First + 1));
2552 end Is_Illegal_Suffix;
2554 --------------------------------
2555 -- Language_Independent_Check --
2556 --------------------------------
2558 procedure Language_Independent_Check
2559 (Project : Project_Id;
2560 Report_Error : Put_Line_Access)
2562 Last_Source_Dir : String_List_Id := Nil_String;
2563 Data : Project_Data := Projects.Table (Project);
2565 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2566 -- Find one or several source directories, and add them
2567 -- to the list of source directories of the project.
2569 ----------------------
2570 -- Find_Source_Dirs --
2571 ----------------------
2573 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2574 Directory : constant String := Get_Name_String (From);
2575 Element : String_Element;
2577 procedure Recursive_Find_Dirs (Path : Name_Id);
2578 -- Find all the subdirectories (recursively) of Path and add them
2579 -- to the list of source directories of the project.
2581 -------------------------
2582 -- Recursive_Find_Dirs --
2583 -------------------------
2585 procedure Recursive_Find_Dirs (Path : Name_Id) is
2587 Name : String (1 .. 250);
2589 List : String_List_Id := Data.Source_Dirs;
2590 Element : String_Element;
2591 Found : Boolean := False;
2593 Non_Canonical_Path : Name_Id := No_Name;
2594 Canonical_Path : Name_Id := No_Name;
2596 The_Path : constant String :=
2597 Normalize_Pathname (Get_Name_String (Path)) &
2598 Directory_Separator;
2600 The_Path_Last : constant Natural :=
2601 Compute_Directory_Last (The_Path);
2604 Name_Len := The_Path_Last - The_Path'First + 1;
2605 Name_Buffer (1 .. Name_Len) :=
2606 The_Path (The_Path'First .. The_Path_Last);
2607 Non_Canonical_Path := Name_Find;
2608 Get_Name_String (Non_Canonical_Path);
2609 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2610 Canonical_Path := Name_Find;
2612 -- To avoid processing the same directory several times, check
2613 -- if the directory is already in Recursive_Dirs. If it is,
2614 -- then there is nothing to do, just return. If it is not, put
2615 -- it there and continue recursive processing.
2617 if Recursive_Dirs.Get (Canonical_Path) then
2621 Recursive_Dirs.Set (Canonical_Path, True);
2624 -- Check if directory is already in list
2626 while List /= Nil_String loop
2627 Element := String_Elements.Table (List);
2629 if Element.Value /= No_Name then
2630 Found := Element.Value = Canonical_Path;
2634 List := Element.Next;
2637 -- If directory is not already in list, put it there
2640 if Current_Verbosity = High then
2642 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2645 String_Elements.Increment_Last;
2647 (Value => Canonical_Path,
2648 Display_Value => Non_Canonical_Path,
2649 Location => No_Location,
2651 Next => Nil_String);
2653 -- Case of first source directory
2655 if Last_Source_Dir = Nil_String then
2656 Data.Source_Dirs := String_Elements.Last;
2658 -- Here we already have source directories.
2661 -- Link the previous last to the new one
2663 String_Elements.Table (Last_Source_Dir).Next :=
2664 String_Elements.Last;
2667 -- And register this source directory as the new last
2669 Last_Source_Dir := String_Elements.Last;
2670 String_Elements.Table (Last_Source_Dir) := Element;
2673 -- Now look for subdirectories. We do that even when this
2674 -- directory is already in the list, because some of its
2675 -- subdirectories may not be in the list yet.
2677 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2680 Read (Dir, Name, Last);
2683 if Name (1 .. Last) /= "."
2684 and then Name (1 .. Last) /= ".."
2688 if Current_Verbosity = High then
2689 Write_Str (" Checking ");
2690 Write_Line (Name (1 .. Last));
2694 Path_Name : constant String :=
2696 (Name => Name (1 .. Last),
2699 (The_Path'First .. The_Path_Last));
2702 if Is_Directory (Path_Name) then
2704 -- We have found a new subdirectory, call self
2706 Name_Len := Path_Name'Length;
2707 Name_Buffer (1 .. Name_Len) := Path_Name;
2708 Recursive_Find_Dirs (Name_Find);
2717 when Directory_Error =>
2719 end Recursive_Find_Dirs;
2721 -- Start of processing for Find_Source_Dirs
2724 if Current_Verbosity = High then
2725 Write_Str ("Find_Source_Dirs (""");
2728 Get_Name_String (From);
2729 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2731 -- Directory := Name_Buffer (1 .. Name_Len);
2732 -- Why is above line commented out ???
2734 if Current_Verbosity = High then
2735 Write_Str (Directory);
2739 -- First, check if we are looking for a directory tree,
2740 -- indicated by "/**" at the end.
2742 if Directory'Length >= 3
2743 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2744 and then (Directory (Directory'Last - 2) = '/'
2746 Directory (Directory'Last - 2) = Directory_Separator)
2748 Data.Known_Order_Of_Source_Dirs := False;
2750 Name_Len := Directory'Length - 3;
2752 if Name_Len = 0 then
2754 -- This is the case of "/**": all directories
2755 -- in the file system.
2758 Name_Buffer (1) := Directory (Directory'First);
2761 Name_Buffer (1 .. Name_Len) :=
2762 Directory (Directory'First .. Directory'Last - 3);
2765 if Current_Verbosity = High then
2766 Write_Str ("Looking for all subdirectories of """);
2767 Write_Str (Name_Buffer (1 .. Name_Len));
2772 Base_Dir : constant Name_Id := Name_Find;
2773 Root_Dir : constant String :=
2775 (Name => Get_Name_String (Base_Dir),
2777 Get_Name_String (Data.Display_Directory));
2780 if Root_Dir'Length = 0 then
2781 Err_Vars.Error_Msg_Name_1 := Base_Dir;
2783 if Location = No_Location then
2786 "{ is not a valid directory.",
2791 "{ is not a valid directory.",
2796 -- We have an existing directory,
2797 -- we register it and all of its subdirectories.
2799 if Current_Verbosity = High then
2800 Write_Line ("Looking for source directories:");
2803 Name_Len := Root_Dir'Length;
2804 Name_Buffer (1 .. Name_Len) := Root_Dir;
2805 Recursive_Find_Dirs (Name_Find);
2807 if Current_Verbosity = High then
2808 Write_Line ("End of looking for source directories.");
2813 -- We have a single directory
2817 Path_Name : Name_Id;
2818 Display_Path_Name : Name_Id;
2821 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
2822 if Path_Name = No_Name then
2823 Err_Vars.Error_Msg_Name_1 := From;
2825 if Location = No_Location then
2828 "{ is not a valid directory",
2833 "{ is not a valid directory",
2838 -- As it is an existing directory, we add it to
2839 -- the list of directories.
2841 String_Elements.Increment_Last;
2842 Element.Value := Path_Name;
2843 Element.Display_Value := Display_Path_Name;
2845 if Last_Source_Dir = Nil_String then
2847 -- This is the first source directory
2849 Data.Source_Dirs := String_Elements.Last;
2852 -- We already have source directories,
2853 -- link the previous last to the new one.
2855 String_Elements.Table (Last_Source_Dir).Next :=
2856 String_Elements.Last;
2859 -- And register this source directory as the new last
2861 Last_Source_Dir := String_Elements.Last;
2862 String_Elements.Table (Last_Source_Dir) := Element;
2866 end Find_Source_Dirs;
2868 -- Start of processing for Language_Independent_Check
2871 if Data.Language_Independent_Checked then
2875 Data.Language_Independent_Checked := True;
2877 Error_Report := Report_Error;
2879 Recursive_Dirs.Reset;
2881 if Current_Verbosity = High then
2882 Write_Line ("Starting to look for directories");
2885 -- Check the object directory
2888 Object_Dir : constant Variable_Value :=
2889 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
2892 pragma Assert (Object_Dir.Kind = Single,
2893 "Object_Dir is not a single string");
2895 -- We set the object directory to its default
2897 Data.Object_Directory := Data.Directory;
2898 Data.Display_Object_Dir := Data.Display_Directory;
2900 if Object_Dir.Value /= Empty_String then
2902 Get_Name_String (Object_Dir.Value);
2904 if Name_Len = 0 then
2907 "Object_Dir cannot be empty",
2908 Object_Dir.Location);
2911 -- We check that the specified object directory
2915 (Object_Dir.Value, Data.Display_Directory,
2916 Data.Object_Directory, Data.Display_Object_Dir);
2918 if Data.Object_Directory = No_Name then
2919 -- The object directory does not exist, report an error
2920 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
2923 "the object directory { cannot be found",
2926 -- Do not keep a nil Object_Directory. Set it to the
2927 -- specified (relative or absolute) path.
2928 -- This is for the benefit of tools that recover from
2929 -- errors; for example, these tools could create the
2930 -- non existent directory.
2932 Data.Display_Object_Dir := Object_Dir.Value;
2933 Get_Name_String (Object_Dir.Value);
2934 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2935 Data.Object_Directory := Name_Find;
2941 if Current_Verbosity = High then
2942 if Data.Object_Directory = No_Name then
2943 Write_Line ("No object directory");
2945 Write_Str ("Object directory: """);
2946 Write_Str (Get_Name_String (Data.Display_Object_Dir));
2951 -- Check the exec directory
2954 Exec_Dir : constant Variable_Value :=
2955 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
2958 pragma Assert (Exec_Dir.Kind = Single,
2959 "Exec_Dir is not a single string");
2961 -- We set the object directory to its default
2963 Data.Exec_Directory := Data.Object_Directory;
2964 Data.Display_Exec_Dir := Data.Display_Object_Dir;
2966 if Exec_Dir.Value /= Empty_String then
2968 Get_Name_String (Exec_Dir.Value);
2970 if Name_Len = 0 then
2973 "Exec_Dir cannot be empty",
2977 -- We check that the specified object directory
2981 (Exec_Dir.Value, Data.Directory,
2982 Data.Exec_Directory, Data.Display_Exec_Dir);
2984 if Data.Exec_Directory = No_Name then
2985 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
2988 "the exec directory { cannot be found",
2995 if Current_Verbosity = High then
2996 if Data.Exec_Directory = No_Name then
2997 Write_Line ("No exec directory");
2999 Write_Str ("Exec directory: """);
3000 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3005 -- Look for the source directories
3008 Source_Dirs : constant Variable_Value :=
3010 (Name_Source_Dirs, Data.Decl.Attributes);
3013 if Current_Verbosity = High then
3014 Write_Line ("Starting to look for source directories");
3017 pragma Assert (Source_Dirs.Kind = List,
3018 "Source_Dirs is not a list");
3020 if Source_Dirs.Default then
3022 -- No Source_Dirs specified: the single source directory
3023 -- is the one containing the project file
3025 String_Elements.Increment_Last;
3026 Data.Source_Dirs := String_Elements.Last;
3027 String_Elements.Table (Data.Source_Dirs) :=
3028 (Value => Data.Directory,
3029 Display_Value => Data.Display_Directory,
3030 Location => No_Location,
3032 Next => Nil_String);
3034 if Current_Verbosity = High then
3035 Write_Line ("Single source directory:");
3037 Write_Str (Get_Name_String (Data.Display_Directory));
3041 elsif Source_Dirs.Values = Nil_String then
3043 -- If Source_Dirs is an empty string list, this means
3044 -- that this project contains no source. For projects that
3045 -- don't extend other projects, this also means that there is no
3046 -- need for an object directory, if not specified.
3048 if Data.Extends = No_Project
3049 and then Data.Object_Directory = Data.Directory
3051 Data.Object_Directory := No_Name;
3054 Data.Source_Dirs := Nil_String;
3055 Data.Sources_Present := False;
3059 Source_Dir : String_List_Id := Source_Dirs.Values;
3060 Element : String_Element;
3063 -- We will find the source directories for each
3064 -- element of the list
3066 while Source_Dir /= Nil_String loop
3067 Element := String_Elements.Table (Source_Dir);
3068 Find_Source_Dirs (Element.Value, Element.Location);
3069 Source_Dir := Element.Next;
3074 if Current_Verbosity = High then
3075 Write_Line ("Putting source directories in canonical cases");
3079 Current : String_List_Id := Data.Source_Dirs;
3080 Element : String_Element;
3083 while Current /= Nil_String loop
3084 Element := String_Elements.Table (Current);
3085 if Element.Value /= No_Name then
3086 Get_Name_String (Element.Value);
3087 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3088 Element.Value := Name_Find;
3089 String_Elements.Table (Current) := Element;
3092 Current := Element.Next;
3097 -- Library attributes
3100 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3102 Lib_Dir : constant Prj.Variable_Value :=
3103 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3105 Lib_Name : constant Prj.Variable_Value :=
3106 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3108 Lib_Version : constant Prj.Variable_Value :=
3110 (Snames.Name_Library_Version, Attributes);
3112 The_Lib_Kind : constant Prj.Variable_Value :=
3114 (Snames.Name_Library_Kind, Attributes);
3117 -- Special case of extending project
3119 if Data.Extends /= No_Project then
3121 Extended_Data : constant Project_Data :=
3122 Projects.Table (Data.Extends);
3125 -- If the project extended is a library project, we inherit
3126 -- the library name, if it is not redefined; we check that
3127 -- the library directory is specified; and we reset the
3128 -- library flag for the extended project.
3130 if Extended_Data.Library then
3131 if Lib_Name.Default then
3132 Data.Library_Name := Extended_Data.Library_Name;
3135 if Lib_Dir.Default then
3137 -- If the extending project is a virtual project, we
3138 -- put the error message in the library project that
3139 -- is extended, rather than in the extending all project.
3140 -- Of course, we cannot put it in the virtual extending
3141 -- project, because it has no source.
3143 if Data.Virtual then
3144 Error_Msg_Name_1 := Extended_Data.Name;
3148 "library project % cannot be virtually extended",
3149 Extended_Data.Location);
3154 "a project extending a library project must " &
3155 "specify an attribute Library_Dir",
3160 Projects.Table (Data.Extends).Library := False;
3165 pragma Assert (Lib_Dir.Kind = Single);
3167 if Lib_Dir.Value = Empty_String then
3169 if Current_Verbosity = High then
3170 Write_Line ("No library directory");
3174 -- Find path name, check that it is a directory
3177 (Lib_Dir.Value, Data.Display_Directory,
3178 Data.Library_Dir, Data.Display_Library_Dir);
3180 if Data.Library_Dir = No_Name then
3182 -- Get the absolute name of the library directory that
3183 -- does not exist, to report an error.
3186 Dir_Name : constant String :=
3187 Get_Name_String (Lib_Dir.Value);
3189 if Is_Absolute_Path (Dir_Name) then
3190 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3193 Get_Name_String (Data.Display_Directory);
3195 if Name_Buffer (Name_Len) /= Directory_Separator then
3196 Name_Len := Name_Len + 1;
3197 Name_Buffer (Name_Len) := Directory_Separator;
3201 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3203 Name_Len := Name_Len + Dir_Name'Length;
3204 Err_Vars.Error_Msg_Name_1 := Name_Find;
3211 "library directory { does not exist",
3215 elsif Data.Library_Dir = Data.Object_Directory then
3218 "library directory cannot be the same " &
3219 "as object directory",
3221 Data.Library_Dir := No_Name;
3222 Data.Display_Library_Dir := No_Name;
3225 if Current_Verbosity = High then
3226 Write_Str ("Library directory =""");
3227 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3233 pragma Assert (Lib_Name.Kind = Single);
3235 if Lib_Name.Value = Empty_String then
3236 if Current_Verbosity = High
3237 and then Data.Library_Name = No_Name
3239 Write_Line ("No library name");
3243 -- There is no restriction on the syntax of library names
3245 Data.Library_Name := Lib_Name.Value;
3248 if Data.Library_Name /= No_Name
3249 and then Current_Verbosity = High
3251 Write_Str ("Library name = """);
3252 Write_Str (Get_Name_String (Data.Library_Name));
3257 Data.Library_Dir /= No_Name
3259 Data.Library_Name /= No_Name;
3261 if Data.Library then
3262 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3265 "?libraries are not supported on this platform",
3267 Data.Library := False;
3270 pragma Assert (Lib_Version.Kind = Single);
3272 if Lib_Version.Value = Empty_String then
3273 if Current_Verbosity = High then
3274 Write_Line ("No library version specified");
3278 Data.Lib_Internal_Name := Lib_Version.Value;
3281 pragma Assert (The_Lib_Kind.Kind = Single);
3283 if The_Lib_Kind.Value = Empty_String then
3284 if Current_Verbosity = High then
3285 Write_Line ("No library kind specified");
3289 Get_Name_String (The_Lib_Kind.Value);
3292 Kind_Name : constant String :=
3293 To_Lower (Name_Buffer (1 .. Name_Len));
3295 OK : Boolean := True;
3298 if Kind_Name = "static" then
3299 Data.Library_Kind := Static;
3301 elsif Kind_Name = "dynamic" then
3302 Data.Library_Kind := Dynamic;
3304 elsif Kind_Name = "relocatable" then
3305 Data.Library_Kind := Relocatable;
3310 "illegal value for Library_Kind",
3311 The_Lib_Kind.Location);
3315 if Current_Verbosity = High and then OK then
3316 Write_Str ("Library kind = ");
3317 Write_Line (Kind_Name);
3320 if Data.Library_Kind /= Static and then
3321 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3325 "only static libraries are supported " &
3327 The_Lib_Kind.Location);
3328 Data.Library := False;
3333 if Data.Library and then Current_Verbosity = High then
3334 Write_Line ("This is a library project file");
3341 if Current_Verbosity = High then
3342 Show_Source_Dirs (Project);
3346 Naming_Id : constant Package_Id :=
3347 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3349 Naming : Package_Element;
3352 -- If there is a package Naming, we will put in Data.Naming
3353 -- what is in this package Naming.
3355 if Naming_Id /= No_Package then
3356 Naming := Packages.Table (Naming_Id);
3358 if Current_Verbosity = High then
3359 Write_Line ("Checking ""Naming"".");
3362 -- Check Spec_Suffix
3365 Spec_Suffixs : Array_Element_Id :=
3368 Naming.Decl.Arrays);
3369 Suffix : Array_Element_Id;
3370 Element : Array_Element;
3371 Suffix2 : Array_Element_Id;
3374 -- If some suffixs have been specified, we make sure that
3375 -- for each language for which a default suffix has been
3376 -- specified, there is a suffix specified, either the one
3377 -- in the project file or if there were none, the default.
3379 if Spec_Suffixs /= No_Array_Element then
3380 Suffix := Data.Naming.Spec_Suffix;
3382 while Suffix /= No_Array_Element loop
3383 Element := Array_Elements.Table (Suffix);
3384 Suffix2 := Spec_Suffixs;
3386 while Suffix2 /= No_Array_Element loop
3387 exit when Array_Elements.Table (Suffix2).Index =
3389 Suffix2 := Array_Elements.Table (Suffix2).Next;
3392 -- There is a registered default suffix, but no
3393 -- suffix specified in the project file.
3394 -- Add the default to the array.
3396 if Suffix2 = No_Array_Element then
3397 Array_Elements.Increment_Last;
3398 Array_Elements.Table (Array_Elements.Last) :=
3399 (Index => Element.Index,
3400 Index_Case_Sensitive => False,
3401 Value => Element.Value,
3402 Next => Spec_Suffixs);
3403 Spec_Suffixs := Array_Elements.Last;
3406 Suffix := Element.Next;
3409 -- Put the resulting array as the specification suffixs
3411 Data.Naming.Spec_Suffix := Spec_Suffixs;
3416 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3417 Element : Array_Element;
3420 while Current /= No_Array_Element loop
3421 Element := Array_Elements.Table (Current);
3422 Get_Name_String (Element.Value.Value);
3424 if Name_Len = 0 then
3427 "Spec_Suffix cannot be empty",
3428 Element.Value.Location);
3431 Array_Elements.Table (Current) := Element;
3432 Current := Element.Next;
3436 -- Check Body_Suffix
3439 Impl_Suffixs : Array_Element_Id :=
3442 Naming.Decl.Arrays);
3444 Suffix : Array_Element_Id;
3445 Element : Array_Element;
3446 Suffix2 : Array_Element_Id;
3449 -- If some suffixs have been specified, we make sure that
3450 -- for each language for which a default suffix has been
3451 -- specified, there is a suffix specified, either the one
3452 -- in the project file or if there were noe, the default.
3454 if Impl_Suffixs /= No_Array_Element then
3455 Suffix := Data.Naming.Body_Suffix;
3457 while Suffix /= No_Array_Element loop
3458 Element := Array_Elements.Table (Suffix);
3459 Suffix2 := Impl_Suffixs;
3461 while Suffix2 /= No_Array_Element loop
3462 exit when Array_Elements.Table (Suffix2).Index =
3464 Suffix2 := Array_Elements.Table (Suffix2).Next;
3467 -- There is a registered default suffix, but no
3468 -- suffix specified in the project file.
3469 -- Add the default to the array.
3471 if Suffix2 = No_Array_Element then
3472 Array_Elements.Increment_Last;
3473 Array_Elements.Table (Array_Elements.Last) :=
3474 (Index => Element.Index,
3475 Index_Case_Sensitive => False,
3476 Value => Element.Value,
3477 Next => Impl_Suffixs);
3478 Impl_Suffixs := Array_Elements.Last;
3481 Suffix := Element.Next;
3484 -- Put the resulting array as the implementation suffixs
3486 Data.Naming.Body_Suffix := Impl_Suffixs;
3491 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3492 Element : Array_Element;
3495 while Current /= No_Array_Element loop
3496 Element := Array_Elements.Table (Current);
3497 Get_Name_String (Element.Value.Value);
3499 if Name_Len = 0 then
3502 "Body_Suffix cannot be empty",
3503 Element.Value.Location);
3506 Array_Elements.Table (Current) := Element;
3507 Current := Element.Next;
3511 -- Get the exceptions, if any
3513 Data.Naming.Specification_Exceptions :=
3515 (Name_Specification_Exceptions,
3516 In_Arrays => Naming.Decl.Arrays);
3518 Data.Naming.Implementation_Exceptions :=
3520 (Name_Implementation_Exceptions,
3521 In_Arrays => Naming.Decl.Arrays);
3525 Projects.Table (Project) := Data;
3526 end Language_Independent_Check;
3528 ----------------------
3529 -- Locate_Directory --
3530 ----------------------
3532 procedure Locate_Directory
3536 Display : out Name_Id)
3538 The_Name : constant String := Get_Name_String (Name);
3539 The_Parent : constant String :=
3540 Get_Name_String (Parent) & Directory_Separator;
3541 The_Parent_Last : constant Natural :=
3542 Compute_Directory_Last (The_Parent);
3545 if Current_Verbosity = High then
3546 Write_Str ("Locate_Directory (""");
3547 Write_Str (The_Name);
3548 Write_Str (""", """);
3549 Write_Str (The_Parent);
3556 if Is_Absolute_Path (The_Name) then
3557 if Is_Directory (The_Name) then
3559 Normed : constant String :=
3560 Normalize_Pathname (The_Name);
3563 Name_Len := Normed'Length;
3564 Name_Buffer (1 .. Name_Len) := Normed;
3565 Display := Name_Find;
3566 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3573 Full_Path : constant String :=
3574 The_Parent (The_Parent'First .. The_Parent_Last) &
3578 if Is_Directory (Full_Path) then
3580 Normed : constant String :=
3581 Normalize_Pathname (Full_Path);
3584 Name_Len := Normed'Length;
3585 Name_Buffer (1 .. Name_Len) := Normed;
3586 Display := Name_Find;
3587 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3593 end Locate_Directory;
3599 function Path_Name_Of
3600 (File_Name : Name_Id;
3601 Directory : Name_Id) return String
3603 Result : String_Access;
3604 The_Directory : constant String := Get_Name_String (Directory);
3607 Get_Name_String (File_Name);
3608 Result := Locate_Regular_File
3609 (File_Name => Name_Buffer (1 .. Name_Len),
3610 Path => The_Directory);
3612 if Result = null then
3615 Canonical_Case_File_Name (Result.all);
3620 ---------------------
3621 -- Project_Extends --
3622 ---------------------
3624 function Project_Extends
3625 (Extending : Project_Id;
3626 Extended : Project_Id) return Boolean
3628 Current : Project_Id := Extending;
3631 if Current = No_Project then
3634 elsif Current = Extended then
3638 Current := Projects.Table (Current).Extends;
3640 end Project_Extends;
3646 procedure Record_Source
3647 (File_Name : Name_Id;
3648 Path_Name : Name_Id;
3649 Project : Project_Id;
3650 Data : in out Project_Data;
3651 Location : Source_Ptr;
3652 Current_Source : in out String_List_Id;
3653 Source_Recorded : in out Boolean)
3655 Canonical_File_Name : Name_Id;
3656 Canonical_Path_Name : Name_Id;
3657 Unit_Name : Name_Id;
3658 Unit_Kind : Spec_Or_Body;
3659 Needs_Pragma : Boolean;
3661 The_Location : Source_Ptr := Location;
3662 Previous_Source : constant String_List_Id := Current_Source;
3663 Except_Name : Name_Id := No_Name;
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;
3673 -- Find out the unit name, the unit kind and if it needs
3674 -- a specific SFN pragma.
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);
3683 if Unit_Name = No_Name then
3684 if Current_Verbosity = High then
3686 Write_Str (Get_Name_String (Canonical_File_Name));
3687 Write_Line (""" is not a valid source file name (ignored).");
3691 -- Check to see if the source has been hidden by an exception,
3692 -- but only if it is not an exception.
3694 if not Needs_Pragma then
3696 Reverse_Naming_Exceptions.Get ((Unit_Kind, Unit_Name));
3698 if Except_Name /= No_Name then
3699 if Current_Verbosity = High then
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).");
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.
3715 -- Put the file name in the list of sources of the project
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,
3723 Next => Nil_String);
3725 if Current_Source = Nil_String then
3726 Data.Sources := String_Elements.Last;
3729 String_Elements.Table (Current_Source).Next :=
3730 String_Elements.Last;
3733 Current_Source := String_Elements.Last;
3735 -- Put the unit in unit list
3738 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
3739 The_Unit_Data : Unit_Data;
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.");
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.
3752 if The_Unit /= Prj.Com.No_Unit then
3753 The_Unit_Data := Units.Table (The_Unit);
3755 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
3756 or else Project_Extends
3758 The_Unit_Data.File_Names (Unit_Kind).Project)
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);
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,
3771 Needs_Pragma => Needs_Pragma);
3772 Units.Table (The_Unit) := The_Unit_Data;
3773 Source_Recorded := True;
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)
3780 if Previous_Source = Nil_String then
3781 Data.Sources := Nil_String;
3783 String_Elements.Table (Previous_Source).Next :=
3785 String_Elements.Decrement_Last;
3788 Current_Source := Previous_Source;
3791 -- It is an error to have two units with the same name
3792 -- and the same kind (spec or body).
3794 if The_Location = No_Location then
3795 The_Location := Projects.Table (Project).Location;
3798 Err_Vars.Error_Msg_Name_1 := Unit_Name;
3799 Error_Msg (Project, "duplicate source {", The_Location);
3801 Err_Vars.Error_Msg_Name_1 :=
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);
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);
3814 -- It is a new unit, create a new record
3817 Units.Increment_Last;
3818 The_Unit := Units.Last;
3819 Units_Htable.Set (Unit_Name, The_Unit);
3820 The_Unit_Data.Name := Unit_Name;
3821 The_Unit_Data.File_Names (Unit_Kind) :=
3822 (Name => Canonical_File_Name,
3823 Display_Name => File_Name,
3824 Path => Canonical_Path_Name,
3825 Display_Path => Path_Name,
3827 Needs_Pragma => Needs_Pragma);
3828 Units.Table (The_Unit) := The_Unit_Data;
3829 Source_Recorded := True;
3835 ----------------------
3836 -- Show_Source_Dirs --
3837 ----------------------
3839 procedure Show_Source_Dirs (Project : Project_Id) is
3840 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
3841 Element : String_Element;
3844 Write_Line ("Source_Dirs:");
3846 while Current /= Nil_String loop
3847 Element := String_Elements.Table (Current);
3849 Write_Line (Get_Name_String (Element.Value));
3850 Current := Element.Next;
3853 Write_Line ("end Source_Dirs.");
3854 end Show_Source_Dirs;