1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2003 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)
130 -- Returns True if the string Suffix cannot be used as
131 -- a spec suffix, a body suffix or a separate suffix.
133 procedure Record_Source
134 (File_Name : Name_Id;
136 Project : Project_Id;
137 Data : in out Project_Data;
138 Location : Source_Ptr;
139 Current_Source : in out String_List_Id;
140 Source_Recorded : in out Boolean);
141 -- Put a unit in the list of units of a project, if the file name
142 -- corresponds to a valid unit name.
144 procedure Show_Source_Dirs (Project : Project_Id);
145 -- List all the source directories of a project.
147 procedure Locate_Directory
151 Display : out Name_Id);
152 -- Locate a directory.
153 -- Returns No_Name if directory does not exist.
155 function Path_Name_Of
156 (File_Name : Name_Id;
159 -- Returns the path name of a (non project) file.
160 -- Returns an empty string if file cannot be found.
162 function Project_Extends
163 (Extending : Project_Id;
164 Extended : Project_Id)
166 -- Returns True if Extending is extending directly or indirectly Extended.
168 procedure Check_Naming_Scheme
169 (Data : in out Project_Data;
170 Project : Project_Id);
171 -- Check the naming scheme part of Data
173 type Unit_Info is record
177 No_Unit : constant Unit_Info := (Specification, No_Name);
179 package Naming_Exceptions is new GNAT.HTable.Simple_HTable
180 (Header_Num => Header_Num,
181 Element => Unit_Info,
182 No_Element => No_Unit,
187 function Hash (Unit : Unit_Info) return Header_Num;
189 package Reverse_Naming_Exceptions is new GNAT.HTable.Simple_HTable
190 (Header_Num => Header_Num,
192 No_Element => No_Name,
196 -- A table to check if a unit with an exceptional name will hide
197 -- a source with a file name following the naming convention.
199 procedure Prepare_Naming_Exceptions
200 (List : Array_Element_Id;
201 Kind : Spec_Or_Body);
202 -- Prepare the internal hash tables used for checking naming exceptions.
203 -- Insert all elements of List in the tables.
205 procedure Free_Naming_Exceptions;
206 -- Free the internal hash tables used for checking naming exceptions
208 function Compute_Directory_Last (Dir : String) return Natural;
209 -- Return the index of the last significant character in Dir. This is used
210 -- to avoid duplicates '/' at the end of directory names
212 ----------------------------
213 -- Compute_Directory_Last --
214 ----------------------------
216 function Compute_Directory_Last (Dir : String) return Natural is
219 and then (Dir (Dir'Last - 1) = Directory_Separator
220 or else Dir (Dir'Last - 1) = '/')
226 end Compute_Directory_Last;
229 -------------------------------
230 -- Prepare_Naming_Exceptions --
231 -------------------------------
233 procedure Prepare_Naming_Exceptions
234 (List : Array_Element_Id;
237 Current : Array_Element_Id := List;
238 Element : Array_Element;
241 while Current /= No_Array_Element loop
242 Element := Array_Elements.Table (Current);
244 if Element.Index /= No_Name then
245 Naming_Exceptions.Set
246 (Element.Value.Value,
247 (Kind => Kind, Unit => Element.Index));
248 Reverse_Naming_Exceptions.Set
249 ((Kind => Kind, Unit => Element.Index),
250 Element.Value.Value);
253 Current := Element.Next;
255 end Prepare_Naming_Exceptions;
261 function Hash (Unit : Unit_Info) return Header_Num is
263 return Header_Num (Unit.Unit mod 2048);
266 ----------------------------
267 -- Free_Naming_Exceptions --
268 ----------------------------
270 procedure Free_Naming_Exceptions is
272 Naming_Exceptions.Reset;
273 Reverse_Naming_Exceptions.Reset;
274 end Free_Naming_Exceptions;
276 -------------------------
277 -- Check_Naming_Scheme --
278 -------------------------
280 procedure Check_Naming_Scheme
281 (Data : in out Project_Data;
282 Project : Project_Id)
284 Naming_Id : constant Package_Id :=
285 Util.Value_Of (Name_Naming, Data.Decl.Packages);
287 Naming : Package_Element;
289 procedure Check_Unit_Names (List : Array_Element_Id);
290 -- Check that a list of unit names contains only valid names.
292 ----------------------
293 -- Check_Unit_Names --
294 ----------------------
296 procedure Check_Unit_Names (List : Array_Element_Id) is
297 Current : Array_Element_Id := List;
298 Element : Array_Element;
302 -- Loop through elements of the string list
304 while Current /= No_Array_Element loop
305 Element := Array_Elements.Table (Current);
307 -- Put file name in canonical case
309 Get_Name_String (Element.Value.Value);
310 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
311 Element.Value.Value := Name_Find;
313 -- Check that it contains a valid unit name
315 Get_Name_String (Element.Index);
316 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
318 if Unit_Name = No_Name then
319 Err_Vars.Error_Msg_Name_1 := Element.Index;
322 "{ is not a valid unit name.",
323 Element.Value.Location);
326 if Current_Verbosity = High then
327 Write_Str (" Unit (""");
328 Write_Str (Get_Name_String (Unit_Name));
332 Element.Index := Unit_Name;
333 Array_Elements.Table (Current) := Element;
336 Current := Element.Next;
338 end Check_Unit_Names;
340 -- Start of processing for Check_Naming_Scheme
343 -- If there is a package Naming, we will put in Data.Naming what is in
344 -- this package Naming.
346 if Naming_Id /= No_Package then
347 Naming := Packages.Table (Naming_Id);
349 if Current_Verbosity = High then
350 Write_Line ("Checking ""Naming"" for Ada.");
354 Bodies : constant Array_Element_Id :=
355 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
357 Specs : constant Array_Element_Id :=
358 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
361 if Bodies /= No_Array_Element then
363 -- We have elements in the array Body_Part
365 if Current_Verbosity = High then
366 Write_Line ("Found Bodies.");
369 Data.Naming.Bodies := Bodies;
370 Check_Unit_Names (Bodies);
373 if Current_Verbosity = High then
374 Write_Line ("No Bodies.");
378 if Specs /= No_Array_Element then
380 -- We have elements in the array Specs
382 if Current_Verbosity = High then
383 Write_Line ("Found Specs.");
386 Data.Naming.Specs := Specs;
387 Check_Unit_Names (Specs);
390 if Current_Verbosity = High then
391 Write_Line ("No Specs.");
396 -- We are now checking if variables Dot_Replacement, Casing,
397 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
400 -- For each variable, if it does not exist, we do nothing,
401 -- because we already have the default.
403 -- Check Dot_Replacement
406 Dot_Replacement : constant Variable_Value :=
408 (Name_Dot_Replacement,
409 Naming.Decl.Attributes);
412 pragma Assert (Dot_Replacement.Kind = Single,
413 "Dot_Replacement is not a single string");
415 if not Dot_Replacement.Default then
416 Get_Name_String (Dot_Replacement.Value);
421 "Dot_Replacement cannot be empty",
422 Dot_Replacement.Location);
425 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
426 Data.Naming.Dot_Replacement := Name_Find;
427 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
432 if Current_Verbosity = High then
433 Write_Str (" Dot_Replacement = """);
434 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
442 Casing_String : constant Variable_Value :=
444 (Name_Casing, Naming.Decl.Attributes);
447 pragma Assert (Casing_String.Kind = Single,
448 "Casing is not a single string");
450 if not Casing_String.Default then
452 Casing_Image : constant String :=
453 Get_Name_String (Casing_String.Value);
456 Casing : constant Casing_Type := Value (Casing_Image);
458 Data.Naming.Casing := Casing;
462 when Constraint_Error =>
463 if Casing_Image'Length = 0 then
466 "Casing cannot be an empty string",
467 Casing_String.Location);
470 Name_Len := Casing_Image'Length;
471 Name_Buffer (1 .. Name_Len) := Casing_Image;
472 Err_Vars.Error_Msg_Name_1 := Name_Find;
475 "{ is not a correct Casing",
476 Casing_String.Location);
482 if Current_Verbosity = High then
483 Write_Str (" Casing = ");
484 Write_Str (Image (Data.Naming.Casing));
492 Ada_Spec_Suffix : constant Variable_Value :=
495 In_Array => Data.Naming.Spec_Suffix);
498 if Ada_Spec_Suffix.Kind = Single
499 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
501 Data.Naming.Current_Spec_Suffix := Ada_Spec_Suffix.Value;
502 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
505 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
509 if Current_Verbosity = High then
510 Write_Str (" Spec_Suffix = """);
511 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
519 Ada_Body_Suffix : constant Variable_Value :=
522 In_Array => Data.Naming.Body_Suffix);
525 if Ada_Body_Suffix.Kind = Single
526 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
528 Data.Naming.Current_Body_Suffix := Ada_Body_Suffix.Value;
529 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
532 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
536 if Current_Verbosity = High then
537 Write_Str (" Body_Suffix = """);
538 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
543 -- Check Separate_Suffix
546 Ada_Sep_Suffix : constant Variable_Value :=
548 (Variable_Name => Name_Separate_Suffix,
549 In_Variables => Naming.Decl.Attributes);
552 if Ada_Sep_Suffix.Default then
553 Data.Naming.Separate_Suffix :=
554 Data.Naming.Current_Body_Suffix;
557 if Get_Name_String (Ada_Sep_Suffix.Value) = "" then
560 "Separate_Suffix cannot be empty",
561 Ada_Sep_Suffix.Location);
564 Data.Naming.Separate_Suffix := Ada_Sep_Suffix.Value;
565 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
570 if Current_Verbosity = High then
571 Write_Str (" Separate_Suffix = """);
572 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
577 -- Check if Data.Naming is valid
579 Check_Ada_Naming_Scheme (Project, Data.Naming);
582 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
583 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
584 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
586 end Check_Naming_Scheme;
593 (Project : Project_Id;
594 Report_Error : Put_Line_Access)
597 Languages : Variable_Value := Nil_Variable_Value;
599 Extending : Boolean := False;
601 function Check_Project (P : Project_Id) return Boolean;
602 -- Returns True if P is Project or a project extended by Project
604 procedure Find_Sources;
605 -- Find all the sources in all of the source directories
608 procedure Get_Path_Names_And_Record_Sources;
609 -- Find the path names of the source files in the Source_Names table
610 -- in the source directories and record those that are Ada sources.
612 procedure Get_Sources_From_File
614 Location : Source_Ptr);
615 -- Get the sources of a project from a text file
617 procedure Warn_If_Not_Sources
618 (Conventions : Array_Element_Id;
620 -- Check that individual naming conventions apply to immediate
621 -- sources of the project; if not, issue a warning.
627 function Check_Project (P : Project_Id) return Boolean is
633 Data : Project_Data := Projects.Table (Project);
636 while Data.Extends /= No_Project loop
637 if P = Data.Extends then
641 Data := Projects.Table (Data.Extends);
653 procedure Find_Sources is
654 Source_Dir : String_List_Id := Data.Source_Dirs;
655 Element : String_Element;
657 Current_Source : String_List_Id := Nil_String;
658 Source_Recorded : Boolean := False;
661 if Current_Verbosity = High then
662 Write_Line ("Looking for sources:");
665 -- For each subdirectory
667 while Source_Dir /= Nil_String loop
669 Source_Recorded := False;
670 Element := String_Elements.Table (Source_Dir);
671 if Element.Value /= No_Name then
673 Source_Directory : constant String :=
674 Get_Name_String (Element.Value);
677 if Current_Verbosity = High then
678 Write_Str ("Source_Dir = ");
679 Write_Line (Source_Directory);
682 -- We look to every entry in the source directory
684 Open (Dir, Source_Directory);
686 -- Canonical_Case_File_Name (Source_Directory);
689 Read (Dir, Name_Buffer, Name_Len);
691 if Current_Verbosity = High then
692 Write_Str (" Checking ");
693 Write_Line (Name_Buffer (1 .. Name_Len));
696 exit when Name_Len = 0;
698 -- Canonical_Case_File_Name
699 -- (Name_Buffer (1 .. Name_Len));
702 File_Name : constant Name_Id := Name_Find;
703 Dir : constant String :=
706 Dir_Last : constant Natural :=
707 Compute_Directory_Last (Dir);
708 Path : constant String :=
710 (Name => Name_Buffer (1 .. Name_Len),
711 Directory => Dir (Dir'First .. Dir_Last));
715 if Is_Regular_File (Path) then
717 Name_Len := Path'Length;
718 Name_Buffer (1 .. Name_Len) := Path;
719 Path_Name := Name_Find;
721 -- We attempt to register it as a source.
722 -- However, there is no error if the file
723 -- does not contain a valid source.
724 -- But there is an error if we have a
725 -- duplicate unit name.
728 (File_Name => File_Name,
729 Path_Name => Path_Name,
732 Location => No_Location,
733 Current_Source => Current_Source,
734 Source_Recorded => Source_Recorded);
744 when Directory_Error =>
748 if Source_Recorded then
749 String_Elements.Table (Source_Dir).Flag := True;
752 Source_Dir := Element.Next;
755 if Current_Verbosity = High then
756 Write_Line ("end Looking for sources.");
759 -- If we have looked for sources and found none, then
760 -- it is an error, except if it is an extending project.
761 -- If a non extending project is not supposed to contain
762 -- any source, then we never call Find_Sources.
764 if Data.Extends = No_Project
765 and then Current_Source = Nil_String
769 "there are no Ada sources in this project",
774 ---------------------------------------
775 -- Get_Path_Names_And_Record_Sources --
776 ---------------------------------------
778 procedure Get_Path_Names_And_Record_Sources is
779 Source_Dir : String_List_Id := Data.Source_Dirs;
780 Element : String_Element;
785 Canonical_Name : Name_Id;
786 Name_Str : String (1 .. 1_024);
790 Current_Source : String_List_Id := Nil_String;
792 First_Error : Boolean := True;
794 Source_Recorded : Boolean := False;
797 -- We look in all source directories for this file name
799 while Source_Dir /= Nil_String loop
800 Source_Recorded := False;
801 Element := String_Elements.Table (Source_Dir);
804 Dir_Path : constant String := Get_Name_String (Element.Value);
806 if Current_Verbosity = High then
807 Write_Str ("checking directory """);
808 Write_Str (Dir_Path);
812 Open (Dir, Dir_Path);
815 Read (Dir, Name_Str, Last);
818 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
820 Canonical_Case_File_Name (Name_Str (1 .. Last));
822 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
823 Canonical_Name := Name_Find;
824 NL := Source_Names.Get (Canonical_Name);
826 if NL /= No_Name_Location and then not NL.Found then
828 Source_Names.Set (Canonical_Name, NL);
829 Name_Len := Dir_Path'Length;
830 Name_Buffer (1 .. Name_Len) := Dir_Path;
831 Add_Char_To_Name_Buffer (Directory_Separator);
832 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
835 if Current_Verbosity = High then
836 Write_Str (" found ");
837 Write_Line (Get_Name_String (Name));
840 -- Register the source if it is an Ada compilation unit..
847 Location => NL.Location,
848 Current_Source => Current_Source,
849 Source_Recorded => Source_Recorded);
856 if Source_Recorded then
857 String_Elements.Table (Source_Dir).Flag := True;
860 Source_Dir := Element.Next;
863 -- It is an error if a source file name in a source list or
864 -- in a source list file is not found.
866 NL := Source_Names.Get_First;
868 while NL /= No_Name_Location loop
870 Err_Vars.Error_Msg_Name_1 := NL.Name;
875 "source file { cannot be found",
877 First_Error := False;
882 "\source file { cannot be found",
887 NL := Source_Names.Get_Next;
889 end Get_Path_Names_And_Record_Sources;
891 ---------------------------
892 -- Get_Sources_From_File --
893 ---------------------------
895 procedure Get_Sources_From_File
897 Location : Source_Ptr)
899 File : Prj.Util.Text_File;
900 Line : String (1 .. 250);
902 Source_Name : Name_Id;
905 if Current_Verbosity = High then
906 Write_Str ("Opening """);
913 Prj.Util.Open (File, Path);
915 if not Prj.Util.Is_Valid (File) then
916 Error_Msg (Project, "file does not exist", Location);
920 while not Prj.Util.End_Of_File (File) loop
921 Prj.Util.Get_Line (File, Line, Last);
923 -- If the line is not empty and does not start with "--",
924 -- then it should contain a file name. However, if the
925 -- file name does not exist, it may be for another language
926 -- and we don't fail.
929 and then (Last = 1 or else Line (1 .. 2) /= "--")
932 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
933 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
934 Source_Name := Name_Find;
938 (Name => Source_Name,
939 Location => Location,
944 Prj.Util.Close (File);
948 Get_Path_Names_And_Record_Sources;
950 -- We should have found at least one source.
951 -- If not, report an error.
953 if Data.Sources = Nil_String then
955 "there are no Ada sources in this project",
958 end Get_Sources_From_File;
960 -------------------------
961 -- Warn_If_Not_Sources --
962 -------------------------
964 procedure Warn_If_Not_Sources
965 (Conventions : Array_Element_Id;
968 Conv : Array_Element_Id := Conventions;
970 The_Unit_Id : Unit_Id;
971 The_Unit_Data : Unit_Data;
972 Location : Source_Ptr;
975 while Conv /= No_Array_Element loop
976 Unit := Array_Elements.Table (Conv).Index;
977 Error_Msg_Name_1 := Unit;
978 Get_Name_String (Unit);
979 To_Lower (Name_Buffer (1 .. Name_Len));
981 The_Unit_Id := Units_Htable.Get (Unit);
982 Location := Array_Elements.Table (Conv).Value.Location;
984 if The_Unit_Id = Prj.Com.No_Unit then
991 The_Unit_Data := Units.Table (The_Unit_Id);
994 if The_Unit_Data.File_Names (Specification).Project /=
999 "?unit{ has no spec in this project",
1004 if The_Unit_Data.File_Names (Com.Body_Part).Project /=
1009 "?unit{ has no body in this project",
1015 Conv := Array_Elements.Table (Conv).Next;
1017 end Warn_If_Not_Sources;
1019 -- Start of processing for Ada_Check
1022 Language_Independent_Check (Project, Report_Error);
1024 Error_Report := Report_Error;
1026 Data := Projects.Table (Project);
1027 Extending := Data.Extends /= No_Project;
1028 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
1030 Data.Naming.Current_Language := Name_Ada;
1031 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
1033 if not Languages.Default then
1035 Current : String_List_Id := Languages.Values;
1036 Element : String_Element;
1037 Ada_Found : Boolean := False;
1040 Look_For_Ada : while Current /= Nil_String loop
1041 Element := String_Elements.Table (Current);
1042 Get_Name_String (Element.Value);
1043 To_Lower (Name_Buffer (1 .. Name_Len));
1045 if Name_Buffer (1 .. Name_Len) = "ada" then
1050 Current := Element.Next;
1051 end loop Look_For_Ada;
1053 if not Ada_Found then
1055 -- Mark the project file as having no sources for Ada
1057 Data.Sources_Present := False;
1062 Check_Naming_Scheme (Data, Project);
1064 Prepare_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
1065 Prepare_Naming_Exceptions (Data.Naming.Specs, Specification);
1067 -- If we have source directories, then find the sources
1069 if Data.Sources_Present then
1070 if Data.Source_Dirs = Nil_String then
1071 Data.Sources_Present := False;
1075 Sources : constant Variable_Value :=
1078 Data.Decl.Attributes);
1080 Source_List_File : constant Variable_Value :=
1082 (Name_Source_List_File,
1083 Data.Decl.Attributes);
1085 Locally_Removed : constant Variable_Value :=
1087 (Name_Locally_Removed_Files,
1088 Data.Decl.Attributes);
1093 (Sources.Kind = List,
1094 "Source_Files is not a list");
1097 (Source_List_File.Kind = Single,
1098 "Source_List_File is not a single string");
1100 if not Sources.Default then
1101 if not Source_List_File.Default then
1104 "?both variables source_files and " &
1105 "source_list_file are present",
1106 Source_List_File.Location);
1109 -- Sources is a list of file names
1112 Current : String_List_Id := Sources.Values;
1113 Element : String_Element;
1114 Location : Source_Ptr;
1120 Data.Sources_Present := Current /= Nil_String;
1122 while Current /= Nil_String loop
1123 Element := String_Elements.Table (Current);
1124 Get_Name_String (Element.Value);
1125 Canonical_Case_File_Name
1126 (Name_Buffer (1 .. Name_Len));
1129 -- If the element has no location, then use the
1130 -- location of Sources to report possible errors.
1132 if Element.Location = No_Location then
1133 Location := Sources.Location;
1136 Location := Element.Location;
1143 Location => Location,
1146 Current := Element.Next;
1149 Get_Path_Names_And_Record_Sources;
1152 -- No source_files specified.
1153 -- We check Source_List_File has been specified.
1155 elsif not Source_List_File.Default then
1157 -- Source_List_File is the name of the file
1158 -- that contains the source file names
1161 Source_File_Path_Name : constant String :=
1163 (Source_List_File.Value,
1167 if Source_File_Path_Name'Length = 0 then
1168 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
1171 "file with sources { does not exist",
1172 Source_List_File.Location);
1175 Get_Sources_From_File
1176 (Source_File_Path_Name,
1177 Source_List_File.Location);
1182 -- Neither Source_Files nor Source_List_File has been
1184 -- Find all the files that satisfy
1185 -- the naming scheme in all the source directories.
1190 -- If there are sources that are locally removed, mark them as
1191 -- such in the Units table.
1193 if not Locally_Removed.Default then
1194 -- Sources can be locally removed only in extending
1197 if Data.Extends = No_Project then
1200 "Locally_Removed_Files can only be used " &
1201 "in an extending project file",
1202 Locally_Removed.Location);
1206 Current : String_List_Id :=
1207 Locally_Removed.Values;
1208 Element : String_Element;
1209 Location : Source_Ptr;
1213 Extended : Project_Id;
1216 while Current /= Nil_String loop
1217 Element := String_Elements.Table (Current);
1218 Get_Name_String (Element.Value);
1219 Canonical_Case_File_Name
1220 (Name_Buffer (1 .. Name_Len));
1223 -- If the element has no location, then use the
1224 -- location of Locally_Removed to report
1227 if Element.Location = No_Location then
1228 Location := Locally_Removed.Location;
1231 Location := Element.Location;
1236 for Index in 1 .. Units.Last loop
1237 Unit := Units.Table (Index);
1240 Unit.File_Names (Specification).Name = Name
1244 -- Check that this is from a project that
1245 -- the current project extends, but not the
1248 Extended := Unit.File_Names
1249 (Specification).Project;
1251 if Extended = Project then
1254 "cannot remove a source " &
1255 "of the same project",
1259 Project_Extends (Project, Extended)
1262 (Specification).Path := Slash;
1264 (Specification).Needs_Pragma := False;
1265 Units.Table (Index) := Unit;
1266 Add_Forbidden_File_Name
1267 (Unit.File_Names (Specification).Name);
1273 "cannot remove a source from " &
1279 Unit.File_Names (Body_Part).Name = Name
1283 -- Check that this is from a project that
1284 -- the current project extends, but not the
1287 Extended := Unit.File_Names
1288 (Body_Part).Project;
1290 if Extended = Project then
1293 "cannot remove a source " &
1294 "of the same project",
1298 Project_Extends (Project, Extended)
1300 Unit.File_Names (Body_Part).Path := Slash;
1301 Unit.File_Names (Body_Part).Needs_Pragma
1303 Units.Table (Index) := Unit;
1304 Add_Forbidden_File_Name
1305 (Unit.File_Names (Body_Part).Name);
1313 Err_Vars.Error_Msg_Name_1 := Name;
1314 Error_Msg (Project, "unknown file {", Location);
1317 Current := Element.Next;
1326 if Data.Sources_Present then
1328 -- Check that all individual naming conventions apply to
1329 -- sources of this project file.
1331 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
1332 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
1335 -- If it is a library project file, check if it is a standalone library
1337 if Data.Library then
1338 Standalone_Library : declare
1339 Lib_Interfaces : constant Prj.Variable_Value :=
1341 (Snames.Name_Library_Interface,
1342 Data.Decl.Attributes);
1343 Lib_Auto_Init : constant Prj.Variable_Value :=
1345 (Snames.Name_Library_Auto_Init,
1346 Data.Decl.Attributes);
1348 Lib_Src_Dir : constant Prj.Variable_Value :=
1350 (Snames.Name_Library_Src_Dir,
1351 Data.Decl.Attributes);
1354 : constant Boolean :=
1356 Standalone_Library_Auto_Init_Is_Supported;
1359 pragma Assert (Lib_Interfaces.Kind = List);
1361 -- It is a library project file if attribute Library_Interface
1364 if not Lib_Interfaces.Default then
1366 Interfaces : String_List_Id := Lib_Interfaces.Values;
1367 Interface_ALIs : String_List_Id := Nil_String;
1369 The_Unit_Id : Unit_Id;
1370 The_Unit_Data : Unit_Data;
1372 procedure Add_ALI_For (Source : Name_Id);
1373 -- Add an ALI file name to the list of Interface ALIs
1379 procedure Add_ALI_For (Source : Name_Id) is
1381 Get_Name_String (Source);
1384 ALI : constant String :=
1385 ALI_File_Name (Name_Buffer (1 .. Name_Len));
1386 ALI_Name_Id : Name_Id;
1388 Name_Len := ALI'Length;
1389 Name_Buffer (1 .. Name_Len) := ALI;
1390 ALI_Name_Id := Name_Find;
1392 String_Elements.Increment_Last;
1393 String_Elements.Table (String_Elements.Last) :=
1394 (Value => ALI_Name_Id,
1395 Display_Value => No_Name,
1396 Location => String_Elements.Table
1397 (Interfaces).Location,
1399 Next => Interface_ALIs);
1400 Interface_ALIs := String_Elements.Last;
1405 Data.Standalone_Library := True;
1407 -- Library_Interface cannot be an empty list
1409 if Interfaces = Nil_String then
1412 "Library_Interface cannot be an empty list",
1413 Lib_Interfaces.Location);
1416 -- Process each unit name specified in the attribute
1417 -- Library_Interface.
1419 while Interfaces /= Nil_String loop
1421 (String_Elements.Table (Interfaces).Value);
1422 To_Lower (Name_Buffer (1 .. Name_Len));
1424 if Name_Len = 0 then
1427 "an interface cannot be an empty string",
1428 String_Elements.Table (Interfaces).Location);
1432 Error_Msg_Name_1 := Unit;
1433 The_Unit_Id := Units_Htable.Get (Unit);
1435 if The_Unit_Id = Prj.Com.No_Unit then
1439 String_Elements.Table (Interfaces).Location);
1442 -- Check that the unit is part of the project
1444 The_Unit_Data := Units.Table (The_Unit_Id);
1446 if The_Unit_Data.File_Names
1447 (Com.Body_Part).Name /= No_Name
1448 and then The_Unit_Data.File_Names
1449 (Com.Body_Part).Path /= Slash
1452 (The_Unit_Data.File_Names (Body_Part).Project)
1454 -- There is a body for this unit.
1455 -- If there is no spec, we need to check
1456 -- that it is not a subunit.
1458 if The_Unit_Data.File_Names
1459 (Specification).Name = No_Name
1462 Src_Ind : Source_File_Index;
1465 Src_Ind := Sinput.P.Load_Project_File
1467 (The_Unit_Data.File_Names
1470 if Sinput.P.Source_File_Is_Subunit
1475 "{ is a subunit; " &
1476 "it cannot be an interface",
1477 String_Elements.Table
1478 (Interfaces).Location);
1483 -- The unit is not a subunit, so we add
1484 -- to the Interface ALIs the ALI file
1485 -- corresponding to the body.
1488 (The_Unit_Data.File_Names (Body_Part).Name);
1493 "{ is not an unit of this project",
1494 String_Elements.Table
1495 (Interfaces).Location);
1498 elsif The_Unit_Data.File_Names
1499 (Com.Specification).Name /= No_Name
1500 and then The_Unit_Data.File_Names
1501 (Com.Specification).Path /= Slash
1502 and then Check_Project
1503 (The_Unit_Data.File_Names
1504 (Specification).Project)
1507 -- The unit is part of the project, it has
1508 -- a spec, but no body. We add to the Interface
1509 -- ALIs the ALI file corresponding to the spec.
1512 (The_Unit_Data.File_Names (Specification).Name);
1517 "{ is not an unit of this project",
1518 String_Elements.Table (Interfaces).Location);
1524 Interfaces := String_Elements.Table (Interfaces).Next;
1527 -- Put the list of Interface ALIs in the project data
1529 Data.Lib_Interface_ALIs := Interface_ALIs;
1531 -- Check value of attribute Library_Auto_Init and set
1532 -- Lib_Auto_Init accordingly.
1534 if Lib_Auto_Init.Default then
1535 -- If no attribute Library_Auto_Init is declared, then
1536 -- set auto init only if it is supported.
1538 Data.Lib_Auto_Init := Auto_Init_Supported;
1541 Get_Name_String (Lib_Auto_Init.Value);
1542 To_Lower (Name_Buffer (1 .. Name_Len));
1544 if Name_Buffer (1 .. Name_Len) = "false" then
1545 Data.Lib_Auto_Init := False;
1547 elsif Name_Buffer (1 .. Name_Len) = "true" then
1548 if Auto_Init_Supported then
1549 Data.Lib_Auto_Init := True;
1552 -- Library_Auto_Init cannot be "true" if auto init
1557 "library auto init not supported " &
1559 Lib_Auto_Init.Location);
1565 "invalid value for attribute Library_Auto_Init",
1566 Lib_Auto_Init.Location);
1570 if Lib_Src_Dir.Value /= Empty_String then
1572 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1576 (Dir_Id, Data.Display_Directory,
1577 Data.Library_Src_Dir,
1578 Data.Display_Library_Src_Dir);
1580 -- Comment needed here ???
1582 if Data.Library_Src_Dir = No_Name then
1584 -- Get the absolute name of the library directory
1585 -- that does not exist, to report an error.
1588 Dir_Name : constant String :=
1589 Get_Name_String (Dir_Id);
1591 if Is_Absolute_Path (Dir_Name) then
1592 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1595 Get_Name_String (Data.Directory);
1597 if Name_Buffer (Name_Len) /=
1600 Name_Len := Name_Len + 1;
1601 Name_Buffer (Name_Len) :=
1602 Directory_Separator;
1607 Name_Len + Dir_Name'Length) :=
1609 Name_Len := Name_Len + Dir_Name'Length;
1610 Err_Vars.Error_Msg_Name_1 := Name_Find;
1617 "Directory { does not exist",
1618 Lib_Src_Dir.Location);
1621 -- And comment needed here ???
1623 elsif Data.Library_Src_Dir = Data.Object_Directory then
1626 "directory to copy interfaces cannot be " &
1627 "the object directory",
1628 Lib_Src_Dir.Location);
1629 Data.Library_Src_Dir := No_Name;
1631 -- And comment needed here ???
1635 Src_Dirs : String_List_Id := Data.Source_Dirs;
1636 Src_Dir : String_Element;
1638 while Src_Dirs /= Nil_String loop
1639 Src_Dir := String_Elements.Table (Src_Dirs);
1640 Src_Dirs := Src_Dir.Next;
1642 if Data.Library_Src_Dir = Src_Dir.Value then
1645 "directory to copy interfaces cannot " &
1646 "be one of the source directories",
1647 Lib_Src_Dir.Location);
1648 Data.Library_Src_Dir := No_Name;
1654 if Data.Library_Src_Dir /= No_Name
1655 and then Current_Verbosity = High
1657 Write_Str ("Directory to copy interfaces =""");
1658 Write_Str (Get_Name_String (Data.Library_Dir));
1666 end Standalone_Library;
1669 -- Put the list of Mains, if any, in the project data
1672 Mains : constant Variable_Value :=
1673 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
1676 Data.Mains := Mains.Values;
1678 -- If no Mains were specified, and if we are an extending
1679 -- project, inherit the Mains from the project we are extending.
1681 if Mains.Default then
1682 if Data.Extends /= No_Project then
1683 Data.Mains := Projects.Table (Data.Extends).Mains;
1686 -- In a library project file, Main cannot be specified
1688 elsif Data.Library then
1691 "a library project file cannot have Main specified",
1696 Projects.Table (Project) := Data;
1698 Free_Naming_Exceptions;
1705 function ALI_File_Name (Source : String) return String is
1707 -- If the source name has an extension, then replace it with
1710 for Index in reverse Source'First + 1 .. Source'Last loop
1711 if Source (Index) = '.' then
1712 return Source (Source'First .. Index - 1) & ALI_Suffix;
1716 -- If there is no dot, or if it is the first character, just add the
1719 return Source & ALI_Suffix;
1722 --------------------
1723 -- Check_Ada_Name --
1724 --------------------
1726 procedure Check_Ada_Name
1730 The_Name : String := Name;
1731 Real_Name : Name_Id;
1732 Need_Letter : Boolean := True;
1733 Last_Underscore : Boolean := False;
1734 OK : Boolean := The_Name'Length > 0;
1737 To_Lower (The_Name);
1739 Name_Len := The_Name'Length;
1740 Name_Buffer (1 .. Name_Len) := The_Name;
1741 Real_Name := Name_Find;
1743 -- Check first that the given name is not an Ada reserved word
1745 if Get_Name_Table_Byte (Real_Name) /= 0
1746 and then Real_Name /= Name_Project
1747 and then Real_Name /= Name_Extends
1748 and then Real_Name /= Name_External
1752 if Current_Verbosity = High then
1753 Write_Str (The_Name);
1754 Write_Line (" is an Ada reserved word.");
1760 for Index in The_Name'Range loop
1763 -- We need a letter (at the beginning, and following a dot),
1764 -- but we don't have one.
1766 if Is_Letter (The_Name (Index)) then
1767 Need_Letter := False;
1772 if Current_Verbosity = High then
1773 Write_Int (Types.Int (Index));
1775 Write_Char (The_Name (Index));
1776 Write_Line ("' is not a letter.");
1782 elsif Last_Underscore
1783 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1785 -- Two underscores are illegal, and a dot cannot follow
1790 if Current_Verbosity = High then
1791 Write_Int (Types.Int (Index));
1793 Write_Char (The_Name (Index));
1794 Write_Line ("' is illegal here.");
1799 elsif The_Name (Index) = '.' then
1801 -- We need a letter after a dot
1803 Need_Letter := True;
1805 elsif The_Name (Index) = '_' then
1806 Last_Underscore := True;
1809 -- We need an letter or a digit
1811 Last_Underscore := False;
1813 if not Is_Alphanumeric (The_Name (Index)) then
1816 if Current_Verbosity = High then
1817 Write_Int (Types.Int (Index));
1819 Write_Char (The_Name (Index));
1820 Write_Line ("' is not alphanumeric.");
1828 -- Cannot end with an underscore or a dot
1830 OK := OK and then not Need_Letter and then not Last_Underscore;
1836 -- Signal a problem with No_Name
1842 -----------------------------
1843 -- Check_Ada_Naming_Scheme --
1844 -----------------------------
1846 procedure Check_Ada_Naming_Scheme
1847 (Project : Project_Id;
1848 Naming : Naming_Data)
1851 -- Only check if we are not using the standard naming scheme
1853 if Naming /= Standard_Naming_Data then
1855 Dot_Replacement : constant String :=
1857 (Naming.Dot_Replacement);
1859 Spec_Suffix : constant String :=
1861 (Naming.Current_Spec_Suffix);
1863 Body_Suffix : constant String :=
1865 (Naming.Current_Body_Suffix);
1867 Separate_Suffix : constant String :=
1869 (Naming.Separate_Suffix);
1872 -- Dot_Replacement cannot
1874 -- - start or end with an alphanumeric
1875 -- - be a single '_'
1876 -- - start with an '_' followed by an alphanumeric
1877 -- - contain a '.' except if it is "."
1879 if Dot_Replacement'Length = 0
1880 or else Is_Alphanumeric
1881 (Dot_Replacement (Dot_Replacement'First))
1882 or else Is_Alphanumeric
1883 (Dot_Replacement (Dot_Replacement'Last))
1884 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1886 (Dot_Replacement'Length = 1
1889 (Dot_Replacement (Dot_Replacement'First + 1))))
1890 or else (Dot_Replacement'Length > 1
1892 Index (Source => Dot_Replacement,
1893 Pattern => ".") /= 0)
1897 '"' & Dot_Replacement &
1898 """ is illegal for Dot_Replacement.",
1899 Naming.Dot_Repl_Loc);
1905 if Is_Illegal_Suffix
1906 (Spec_Suffix, Dot_Replacement = ".")
1908 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1911 "{ is illegal for Spec_Suffix",
1912 Naming.Spec_Suffix_Loc);
1915 if Is_Illegal_Suffix
1916 (Body_Suffix, Dot_Replacement = ".")
1918 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1921 "{ is illegal for Body_Suffix",
1922 Naming.Body_Suffix_Loc);
1925 if Body_Suffix /= Separate_Suffix then
1926 if Is_Illegal_Suffix
1927 (Separate_Suffix, Dot_Replacement = ".")
1929 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1932 "{ is illegal for Separate_Suffix",
1933 Naming.Sep_Suffix_Loc);
1937 -- Spec_Suffix cannot have the same termination as
1938 -- Body_Suffix or Separate_Suffix
1940 if Spec_Suffix'Length <= Body_Suffix'Length
1942 Body_Suffix (Body_Suffix'Last -
1943 Spec_Suffix'Length + 1 ..
1944 Body_Suffix'Last) = Spec_Suffix
1950 """) cannot end with" &
1951 " Spec_Suffix (""" &
1952 Spec_Suffix & """).",
1953 Naming.Body_Suffix_Loc);
1956 if Body_Suffix /= Separate_Suffix
1957 and then Spec_Suffix'Length <= Separate_Suffix'Length
1960 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1962 Separate_Suffix'Last) = Spec_Suffix
1966 "Separate_Suffix (""" &
1968 """) cannot end with" &
1969 " Spec_Suffix (""" &
1970 Spec_Suffix & """).",
1971 Naming.Sep_Suffix_Loc);
1975 end Check_Ada_Naming_Scheme;
1982 (Project : Project_Id;
1984 Flag_Location : Source_Ptr)
1986 Error_Buffer : String (1 .. 5_000);
1987 Error_Last : Natural := 0;
1988 Msg_Name : Natural := 0;
1989 First : Positive := Msg'First;
1991 procedure Add (C : Character);
1992 -- Add a character to the buffer
1994 procedure Add (S : String);
1995 -- Add a string to the buffer
1997 procedure Add (Id : Name_Id);
1998 -- Add a name to the buffer
2004 procedure Add (C : Character) is
2006 Error_Last := Error_Last + 1;
2007 Error_Buffer (Error_Last) := C;
2010 procedure Add (S : String) is
2012 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2013 Error_Last := Error_Last + S'Length;
2016 procedure Add (Id : Name_Id) is
2018 Get_Name_String (Id);
2019 Add (Name_Buffer (1 .. Name_Len));
2022 -- Start of processing for Error_Msg
2025 if Error_Report = null then
2026 Prj.Err.Error_Msg (Msg, Flag_Location);
2030 if Msg (First) = '\' then
2032 -- Continuation character, ignore.
2036 elsif Msg (First) = '?' then
2038 -- Warning character. It is always the first one in this package
2044 for Index in First .. Msg'Last loop
2045 if Msg (Index) = '{' or else Msg (Index) = '%' then
2047 -- Include a name between double quotes.
2049 Msg_Name := Msg_Name + 1;
2053 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2054 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2055 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2057 when others => null;
2068 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2076 (Canonical_File_Name : Name_Id;
2077 Naming : Naming_Data;
2078 Unit_Name : out Name_Id;
2079 Unit_Kind : out Spec_Or_Body;
2080 Needs_Pragma : out Boolean)
2082 function Check_Exception (Canonical : Name_Id) return Boolean;
2083 pragma Inline (Check_Exception);
2084 -- Check if Canonical is one of the exceptions in List.
2085 -- Returns True if Get_Unit should exit
2087 ---------------------
2088 -- Check_Exception --
2089 ---------------------
2091 function Check_Exception (Canonical : Name_Id) return Boolean is
2092 Info : Unit_Info := Naming_Exceptions.Get (Canonical);
2096 if Info = No_Unit then
2097 if Hostparm.OpenVMS then
2098 VMS_Name := Canonical;
2099 Get_Name_String (VMS_Name);
2101 if Name_Buffer (Name_Len) = '.' then
2102 Name_Len := Name_Len - 1;
2103 VMS_Name := Name_Find;
2106 Info := Naming_Exceptions.Get (VMS_Name);
2109 if Info = No_Unit then
2114 Unit_Kind := Info.Kind;
2115 Unit_Name := Info.Unit;
2116 Needs_Pragma := True;
2118 end Check_Exception;
2120 -- Start of processing for Get_Unit
2123 Needs_Pragma := False;
2125 if Check_Exception (Canonical_File_Name) then
2129 Get_Name_String (Canonical_File_Name);
2132 File : String := Name_Buffer (1 .. Name_Len);
2133 First : constant Positive := File'First;
2134 Last : Natural := File'Last;
2135 Standard_GNAT : Boolean;
2139 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2140 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2142 -- Check if the end of the file name is Specification_Append
2144 Get_Name_String (Naming.Current_Spec_Suffix);
2146 if File'Length > Name_Len
2147 and then File (Last - Name_Len + 1 .. Last) =
2148 Name_Buffer (1 .. Name_Len)
2152 Unit_Kind := Specification;
2153 Last := Last - Name_Len;
2155 if Current_Verbosity = High then
2156 Write_Str (" Specification: ");
2157 Write_Line (File (First .. Last));
2161 Get_Name_String (Naming.Current_Body_Suffix);
2163 -- Check if the end of the file name is Body_Append
2165 if File'Length > Name_Len
2166 and then File (Last - Name_Len + 1 .. Last) =
2167 Name_Buffer (1 .. Name_Len)
2171 Unit_Kind := Body_Part;
2172 Last := Last - Name_Len;
2174 if Current_Verbosity = High then
2175 Write_Str (" Body: ");
2176 Write_Line (File (First .. Last));
2179 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2180 Get_Name_String (Naming.Separate_Suffix);
2182 -- Check if the end of the file name is Separate_Append
2184 if File'Length > Name_Len
2185 and then File (Last - Name_Len + 1 .. Last) =
2186 Name_Buffer (1 .. Name_Len)
2188 -- We have a separate (a body)
2190 Unit_Kind := Body_Part;
2191 Last := Last - Name_Len;
2193 if Current_Verbosity = High then
2194 Write_Str (" Separate: ");
2195 Write_Line (File (First .. Last));
2209 -- This is not a source file
2211 Unit_Name := No_Name;
2212 Unit_Kind := Specification;
2214 if Current_Verbosity = High then
2215 Write_Line (" Not a valid file name.");
2221 Get_Name_String (Naming.Dot_Replacement);
2223 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2225 if Name_Buffer (1 .. Name_Len) /= "." then
2227 -- If Dot_Replacement is not a single dot,
2228 -- then there should not be any dot in the name.
2230 for Index in First .. Last loop
2231 if File (Index) = '.' then
2232 if Current_Verbosity = High then
2234 (" Not a valid file name (some dot not replaced).");
2237 Unit_Name := No_Name;
2243 -- Replace the substring Dot_Replacement with dots
2246 Index : Positive := First;
2249 while Index <= Last - Name_Len + 1 loop
2251 if File (Index .. Index + Name_Len - 1) =
2252 Name_Buffer (1 .. Name_Len)
2254 File (Index) := '.';
2256 if Name_Len > 1 and then Index < Last then
2257 File (Index + 1 .. Last - Name_Len + 1) :=
2258 File (Index + Name_Len .. Last);
2261 Last := Last - Name_Len + 1;
2269 -- Check if the casing is right
2272 Src : String := File (First .. Last);
2275 case Naming.Casing is
2276 when All_Lower_Case =>
2279 Mapping => Lower_Case_Map);
2281 when All_Upper_Case =>
2284 Mapping => Upper_Case_Map);
2286 when Mixed_Case | Unknown =>
2290 if Src /= File (First .. Last) then
2291 if Current_Verbosity = High then
2292 Write_Line (" Not a valid file name (casing).");
2295 Unit_Name := No_Name;
2299 -- We put the name in lower case
2303 Mapping => Lower_Case_Map);
2305 -- In the standard GNAT naming scheme, check for special cases:
2306 -- children or separates of A, G, I or S, and run time sources.
2308 if Standard_GNAT and then Src'Length >= 3 then
2310 S1 : constant Character := Src (Src'First);
2311 S2 : constant Character := Src (Src'First + 1);
2314 if S1 = 'a' or else S1 = 'g'
2315 or else S1 = 'i' or else S1 = 's'
2317 -- Children or separates of packages A, G, I or S
2319 if (Hostparm.OpenVMS and then S2 = '$')
2320 or else (not Hostparm.OpenVMS and then S2 = '~')
2322 Src (Src'First + 1) := '.';
2324 -- If it is potentially a run time source, disable
2325 -- filling of the mapping file to avoid warnings.
2328 Set_Mapping_File_Initial_State_To_Empty;
2335 if Current_Verbosity = High then
2340 -- Now, we check if this name is a valid unit name
2342 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2348 -----------------------
2349 -- Is_Illegal_Suffix --
2350 -----------------------
2352 function Is_Illegal_Suffix
2354 Dot_Replacement_Is_A_Single_Dot : Boolean)
2358 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2362 -- If dot replacement is a single dot, and first character of
2363 -- suffix is also a dot
2365 if Dot_Replacement_Is_A_Single_Dot
2366 and then Suffix (Suffix'First) = '.'
2368 for Index in Suffix'First + 1 .. Suffix'Last loop
2370 -- If there is another dot
2372 if Suffix (Index) = '.' then
2374 -- It is illegal to have a letter following the initial dot
2376 return Is_Letter (Suffix (Suffix'First + 1));
2384 end Is_Illegal_Suffix;
2386 --------------------------------
2387 -- Language_Independent_Check --
2388 --------------------------------
2390 procedure Language_Independent_Check
2391 (Project : Project_Id;
2392 Report_Error : Put_Line_Access)
2394 Last_Source_Dir : String_List_Id := Nil_String;
2395 Data : Project_Data := Projects.Table (Project);
2397 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2398 -- Find one or several source directories, and add them
2399 -- to the list of source directories of the project.
2401 ----------------------
2402 -- Find_Source_Dirs --
2403 ----------------------
2405 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2406 Directory : constant String := Get_Name_String (From);
2407 Canonical_Directory_Id : Name_Id;
2408 Element : String_Element;
2410 procedure Recursive_Find_Dirs (Path : Name_Id);
2411 -- Find all the subdirectories (recursively) of Path
2412 -- and add them to the list of source directories
2415 -------------------------
2416 -- Recursive_Find_Dirs --
2417 -------------------------
2419 procedure Recursive_Find_Dirs (Path : Name_Id) is
2421 Name : String (1 .. 250);
2423 List : String_List_Id := Data.Source_Dirs;
2424 Element : String_Element;
2425 Found : Boolean := False;
2427 Canonical_Path : Name_Id := No_Name;
2430 Get_Name_String (Path);
2431 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2434 The_Path : String :=
2436 (Name => Name_Buffer (1 .. Name_Len)) &
2437 Directory_Separator;
2438 The_Path_Last : constant Natural :=
2439 Compute_Directory_Last (The_Path);
2441 Name_Len := The_Path_Last - The_Path'First + 1;
2442 Name_Buffer (1 .. Name_Len) :=
2443 The_Path (The_Path'First .. The_Path_Last);
2444 Canonical_Path := Name_Find;
2446 -- To avoid processing the same directory several times, check
2447 -- if the directory is already in Recursive_Dirs. If it is,
2448 -- then there is nothing to do, just return. If it is not, put
2449 -- it there and continue recursive processing.
2451 if Recursive_Dirs.Get (Canonical_Path) then
2455 Recursive_Dirs.Set (Canonical_Path, True);
2458 -- Check if directory is already in list
2460 while List /= Nil_String loop
2461 Element := String_Elements.Table (List);
2463 if Element.Value /= No_Name then
2464 Get_Name_String (Element.Value);
2466 The_Path (The_Path'First .. The_Path_Last) =
2467 Name_Buffer (1 .. Name_Len);
2471 List := Element.Next;
2474 -- If directory is not already in list, put it there
2477 if Current_Verbosity = High then
2479 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2482 String_Elements.Increment_Last;
2484 (Value => Canonical_Path,
2485 Display_Value => No_Name,
2486 Location => No_Location,
2488 Next => Nil_String);
2490 -- Case of first source directory
2492 if Last_Source_Dir = Nil_String then
2493 Data.Source_Dirs := String_Elements.Last;
2495 -- Here we already have source directories.
2498 -- Link the previous last to the new one
2500 String_Elements.Table (Last_Source_Dir).Next :=
2501 String_Elements.Last;
2504 -- And register this source directory as the new last
2506 Last_Source_Dir := String_Elements.Last;
2507 String_Elements.Table (Last_Source_Dir) := Element;
2510 -- Now look for subdirectories. We do that even when this
2511 -- directory is already in the list, because some of its
2512 -- subdirectories may not be in the list yet.
2514 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2517 Read (Dir, Name, Last);
2520 if Name (1 .. Last) /= "."
2521 and then Name (1 .. Last) /= ".."
2525 if Current_Verbosity = High then
2526 Write_Str (" Checking ");
2527 Write_Line (Name (1 .. Last));
2531 Path_Name : String :=
2533 (Name => Name (1 .. Last),
2536 (The_Path'First .. The_Path_Last));
2539 Canonical_Case_File_Name (Path_Name);
2541 if Is_Directory (Path_Name) then
2543 -- We have found a new subdirectory, call self
2545 Name_Len := Path_Name'Length;
2546 Name_Buffer (1 .. Name_Len) := Path_Name;
2547 Recursive_Find_Dirs (Name_Find);
2557 when Directory_Error =>
2559 end Recursive_Find_Dirs;
2561 -- Start of processing for Find_Source_Dirs
2564 if Current_Verbosity = High then
2565 Write_Str ("Find_Source_Dirs (""");
2568 Get_Name_String (From);
2569 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2570 -- Directory := Name_Buffer (1 .. Name_Len);
2571 Canonical_Directory_Id := Name_Find;
2573 if Current_Verbosity = High then
2574 Write_Str (Directory);
2578 -- First, check if we are looking for a directory tree,
2579 -- indicated by "/**" at the end.
2581 if Directory'Length >= 3
2582 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2583 and then (Directory (Directory'Last - 2) = '/'
2585 Directory (Directory'Last - 2) = Directory_Separator)
2587 Data.Known_Order_Of_Source_Dirs := False;
2589 Name_Len := Directory'Length - 3;
2591 if Name_Len = 0 then
2593 -- This is the case of "/**": all directories
2594 -- in the file system.
2597 Name_Buffer (1) := Directory (Directory'First);
2600 Name_Buffer (1 .. Name_Len) :=
2601 Directory (Directory'First .. Directory'Last - 3);
2604 if Current_Verbosity = High then
2605 Write_Str ("Looking for all subdirectories of """);
2606 Write_Str (Name_Buffer (1 .. Name_Len));
2611 Base_Dir : constant Name_Id := Name_Find;
2612 Root_Dir : constant String :=
2614 (Name => Get_Name_String (Base_Dir),
2616 Get_Name_String (Data.Display_Directory));
2619 if Root_Dir'Length = 0 then
2620 Err_Vars.Error_Msg_Name_1 := Base_Dir;
2622 if Location = No_Location then
2625 "{ is not a valid directory.",
2630 "{ is not a valid directory.",
2635 -- We have an existing directory,
2636 -- we register it and all of its subdirectories.
2638 if Current_Verbosity = High then
2639 Write_Line ("Looking for source directories:");
2642 Name_Len := Root_Dir'Length;
2643 Name_Buffer (1 .. Name_Len) := Root_Dir;
2644 Recursive_Find_Dirs (Name_Find);
2646 if Current_Verbosity = High then
2647 Write_Line ("End of looking for source directories.");
2652 -- We have a single directory
2656 Path_Name : Name_Id;
2657 Display_Path_Name : Name_Id;
2660 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
2661 if Path_Name = No_Name then
2662 Err_Vars.Error_Msg_Name_1 := From;
2664 if Location = No_Location then
2667 "{ is not a valid directory",
2672 "{ is not a valid directory",
2677 -- As it is an existing directory, we add it to
2678 -- the list of directories.
2680 String_Elements.Increment_Last;
2681 Element.Value := Path_Name;
2682 Element.Display_Value := Display_Path_Name;
2684 if Last_Source_Dir = Nil_String then
2686 -- This is the first source directory
2688 Data.Source_Dirs := String_Elements.Last;
2691 -- We already have source directories,
2692 -- link the previous last to the new one.
2694 String_Elements.Table (Last_Source_Dir).Next :=
2695 String_Elements.Last;
2698 -- And register this source directory as the new last
2700 Last_Source_Dir := String_Elements.Last;
2701 String_Elements.Table (Last_Source_Dir) := Element;
2705 end Find_Source_Dirs;
2707 -- Start of processing for Language_Independent_Check
2710 if Data.Language_Independent_Checked then
2714 Data.Language_Independent_Checked := True;
2716 Error_Report := Report_Error;
2718 Recursive_Dirs.Reset;
2720 if Current_Verbosity = High then
2721 Write_Line ("Starting to look for directories");
2724 -- Check the object directory
2727 Object_Dir : constant Variable_Value :=
2728 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
2731 pragma Assert (Object_Dir.Kind = Single,
2732 "Object_Dir is not a single string");
2734 -- We set the object directory to its default
2736 Data.Object_Directory := Data.Directory;
2737 Data.Display_Object_Dir := Data.Display_Directory;
2739 if Object_Dir.Value /= Empty_String then
2741 Get_Name_String (Object_Dir.Value);
2743 if Name_Len = 0 then
2746 "Object_Dir cannot be empty",
2747 Object_Dir.Location);
2750 -- We check that the specified object directory
2754 (Object_Dir.Value, Data.Display_Directory,
2755 Data.Object_Directory, Data.Display_Object_Dir);
2757 if Data.Object_Directory = No_Name then
2758 -- The object directory does not exist, report an error
2759 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
2762 "the object directory { cannot be found",
2765 -- Do not keep a nil Object_Directory. Set it to the
2766 -- specified (relative or absolute) path.
2767 -- This is for the benefit of tools that recover from
2768 -- errors; for example, these tools could create the
2769 -- non existent directory.
2771 Data.Display_Object_Dir := Object_Dir.Value;
2772 Get_Name_String (Object_Dir.Value);
2773 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2774 Data.Object_Directory := Name_Find;
2780 if Current_Verbosity = High then
2781 if Data.Object_Directory = No_Name then
2782 Write_Line ("No object directory");
2784 Write_Str ("Object directory: """);
2785 Write_Str (Get_Name_String (Data.Display_Object_Dir));
2790 -- Check the exec directory
2793 Exec_Dir : constant Variable_Value :=
2794 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
2797 pragma Assert (Exec_Dir.Kind = Single,
2798 "Exec_Dir is not a single string");
2800 -- We set the object directory to its default
2802 Data.Exec_Directory := Data.Object_Directory;
2803 Data.Display_Exec_Dir := Data.Display_Object_Dir;
2805 if Exec_Dir.Value /= Empty_String then
2807 Get_Name_String (Exec_Dir.Value);
2809 if Name_Len = 0 then
2812 "Exec_Dir cannot be empty",
2816 -- We check that the specified object directory
2820 (Exec_Dir.Value, Data.Directory,
2821 Data.Exec_Directory, Data.Display_Exec_Dir);
2823 if Data.Exec_Directory = No_Name then
2824 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
2827 "the exec directory { cannot be found",
2834 if Current_Verbosity = High then
2835 if Data.Exec_Directory = No_Name then
2836 Write_Line ("No exec directory");
2838 Write_Str ("Exec directory: """);
2839 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
2844 -- Look for the source directories
2847 Source_Dirs : constant Variable_Value :=
2849 (Name_Source_Dirs, Data.Decl.Attributes);
2852 if Current_Verbosity = High then
2853 Write_Line ("Starting to look for source directories");
2856 pragma Assert (Source_Dirs.Kind = List,
2857 "Source_Dirs is not a list");
2859 if Source_Dirs.Default then
2861 -- No Source_Dirs specified: the single source directory
2862 -- is the one containing the project file
2864 String_Elements.Increment_Last;
2865 Data.Source_Dirs := String_Elements.Last;
2866 String_Elements.Table (Data.Source_Dirs) :=
2867 (Value => Data.Directory,
2868 Display_Value => Data.Display_Directory,
2869 Location => No_Location,
2871 Next => Nil_String);
2873 if Current_Verbosity = High then
2874 Write_Line ("Single source directory:");
2876 Write_Str (Get_Name_String (Data.Display_Directory));
2880 elsif Source_Dirs.Values = Nil_String then
2882 -- If Source_Dirs is an empty string list, this means
2883 -- that this project contains no source. For projects that
2884 -- don't extend other projects, this also means that there is no
2885 -- need for an object directory, if not specified.
2887 if Data.Extends = No_Project
2888 and then Data.Object_Directory = Data.Directory
2890 Data.Object_Directory := No_Name;
2893 Data.Source_Dirs := Nil_String;
2894 Data.Sources_Present := False;
2898 Source_Dir : String_List_Id := Source_Dirs.Values;
2899 Element : String_Element;
2902 -- We will find the source directories for each
2903 -- element of the list
2905 while Source_Dir /= Nil_String loop
2906 Element := String_Elements.Table (Source_Dir);
2907 Find_Source_Dirs (Element.Value, Element.Location);
2908 Source_Dir := Element.Next;
2913 if Current_Verbosity = High then
2914 Write_Line ("Putting source directories in canonical cases");
2918 Current : String_List_Id := Data.Source_Dirs;
2919 Element : String_Element;
2922 while Current /= Nil_String loop
2923 Element := String_Elements.Table (Current);
2924 if Element.Value /= No_Name then
2925 Element.Display_Value := Element.Value;
2926 Get_Name_String (Element.Value);
2927 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2928 Element.Value := Name_Find;
2929 String_Elements.Table (Current) := Element;
2932 Current := Element.Next;
2937 -- Library attributes
2940 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
2942 Lib_Dir : constant Prj.Variable_Value :=
2943 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
2945 Lib_Name : constant Prj.Variable_Value :=
2946 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
2948 Lib_Version : constant Prj.Variable_Value :=
2950 (Snames.Name_Library_Version, Attributes);
2952 The_Lib_Kind : constant Prj.Variable_Value :=
2954 (Snames.Name_Library_Kind, Attributes);
2957 -- Special case of extending project
2959 if Data.Extends /= No_Project then
2961 Extended_Data : constant Project_Data :=
2962 Projects.Table (Data.Extends);
2965 -- If the project extended is a library project, we inherit
2966 -- the library name, if it is not redefined; we check that
2967 -- the library directory is specified; and we reset the
2968 -- library flag for the extended project.
2970 if Extended_Data.Library then
2971 if Lib_Name.Default then
2972 Data.Library_Name := Extended_Data.Library_Name;
2975 if Lib_Dir.Default then
2978 "a project extending a library project must specify " &
2979 "an attribute Library_Dir",
2983 Projects.Table (Data.Extends).Library := False;
2988 pragma Assert (Lib_Dir.Kind = Single);
2990 if Lib_Dir.Value = Empty_String then
2992 if Current_Verbosity = High then
2993 Write_Line ("No library directory");
2997 -- Find path name, check that it is a directory
3000 (Lib_Dir.Value, Data.Display_Directory,
3001 Data.Library_Dir, Data.Display_Library_Dir);
3003 if Data.Library_Dir = No_Name then
3004 -- Get the absolute name of the library directory that
3005 -- does not exist, to report an error.
3008 Dir_Name : constant String :=
3009 Get_Name_String (Lib_Dir.Value);
3011 if Is_Absolute_Path (Dir_Name) then
3012 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3015 Get_Name_String (Data.Display_Directory);
3017 if Name_Buffer (Name_Len) /= Directory_Separator then
3018 Name_Len := Name_Len + 1;
3019 Name_Buffer (Name_Len) := Directory_Separator;
3023 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3025 Name_Len := Name_Len + Dir_Name'Length;
3026 Err_Vars.Error_Msg_Name_1 := Name_Find;
3033 "library directory { does not exist",
3037 elsif Data.Library_Dir = Data.Object_Directory then
3040 "library directory cannot be the same " &
3041 "as object directory",
3043 Data.Library_Dir := No_Name;
3044 Data.Display_Library_Dir := No_Name;
3047 if Current_Verbosity = High then
3048 Write_Str ("Library directory =""");
3049 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3055 pragma Assert (Lib_Name.Kind = Single);
3057 if Lib_Name.Value = Empty_String then
3058 if Current_Verbosity = High
3059 and then Data.Library_Name = No_Name
3061 Write_Line ("No library name");
3065 -- There is no restriction on the syntax of library names
3067 Data.Library_Name := Lib_Name.Value;
3070 if Data.Library_Name /= No_Name
3071 and then Current_Verbosity = High
3073 Write_Str ("Library name = """);
3074 Write_Str (Get_Name_String (Data.Library_Name));
3079 Data.Library_Dir /= No_Name
3081 Data.Library_Name /= No_Name;
3083 if Data.Library then
3084 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3087 "?libraries are not supported on this platform",
3089 Data.Library := False;
3092 pragma Assert (Lib_Version.Kind = Single);
3094 if Lib_Version.Value = Empty_String then
3095 if Current_Verbosity = High then
3096 Write_Line ("No library version specified");
3100 Data.Lib_Internal_Name := Lib_Version.Value;
3103 pragma Assert (The_Lib_Kind.Kind = Single);
3105 if The_Lib_Kind.Value = Empty_String then
3106 if Current_Verbosity = High then
3107 Write_Line ("No library kind specified");
3111 Get_Name_String (The_Lib_Kind.Value);
3114 Kind_Name : constant String :=
3115 To_Lower (Name_Buffer (1 .. Name_Len));
3117 OK : Boolean := True;
3120 if Kind_Name = "static" then
3121 Data.Library_Kind := Static;
3123 elsif Kind_Name = "dynamic" then
3124 Data.Library_Kind := Dynamic;
3126 elsif Kind_Name = "relocatable" then
3127 Data.Library_Kind := Relocatable;
3132 "illegal value for Library_Kind",
3133 The_Lib_Kind.Location);
3137 if Current_Verbosity = High and then OK then
3138 Write_Str ("Library kind = ");
3139 Write_Line (Kind_Name);
3142 if Data.Library_Kind /= Static and then
3143 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3147 "only static libraries are supported " &
3149 The_Lib_Kind.Location);
3150 Data.Library := False;
3155 if Data.Library and then Current_Verbosity = High then
3156 Write_Line ("This is a library project file");
3163 if Current_Verbosity = High then
3164 Show_Source_Dirs (Project);
3168 Naming_Id : constant Package_Id :=
3169 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3171 Naming : Package_Element;
3174 -- If there is a package Naming, we will put in Data.Naming
3175 -- what is in this package Naming.
3177 if Naming_Id /= No_Package then
3178 Naming := Packages.Table (Naming_Id);
3180 if Current_Verbosity = High then
3181 Write_Line ("Checking ""Naming"".");
3184 -- Check Spec_Suffix
3187 Spec_Suffixs : Array_Element_Id :=
3190 Naming.Decl.Arrays);
3191 Suffix : Array_Element_Id;
3192 Element : Array_Element;
3193 Suffix2 : Array_Element_Id;
3196 -- If some suffixs have been specified, we make sure that
3197 -- for each language for which a default suffix has been
3198 -- specified, there is a suffix specified, either the one
3199 -- in the project file or if there were none, the default.
3201 if Spec_Suffixs /= No_Array_Element then
3202 Suffix := Data.Naming.Spec_Suffix;
3204 while Suffix /= No_Array_Element loop
3205 Element := Array_Elements.Table (Suffix);
3206 Suffix2 := Spec_Suffixs;
3208 while Suffix2 /= No_Array_Element loop
3209 exit when Array_Elements.Table (Suffix2).Index =
3211 Suffix2 := Array_Elements.Table (Suffix2).Next;
3214 -- There is a registered default suffix, but no
3215 -- suffix specified in the project file.
3216 -- Add the default to the array.
3218 if Suffix2 = No_Array_Element then
3219 Array_Elements.Increment_Last;
3220 Array_Elements.Table (Array_Elements.Last) :=
3221 (Index => Element.Index,
3222 Index_Case_Sensitive => False,
3223 Value => Element.Value,
3224 Next => Spec_Suffixs);
3225 Spec_Suffixs := Array_Elements.Last;
3228 Suffix := Element.Next;
3231 -- Put the resulting array as the specification suffixs
3233 Data.Naming.Spec_Suffix := Spec_Suffixs;
3238 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3239 Element : Array_Element;
3242 while Current /= No_Array_Element loop
3243 Element := Array_Elements.Table (Current);
3244 Get_Name_String (Element.Value.Value);
3246 if Name_Len = 0 then
3249 "Spec_Suffix cannot be empty",
3250 Element.Value.Location);
3253 Array_Elements.Table (Current) := Element;
3254 Current := Element.Next;
3258 -- Check Body_Suffix
3261 Impl_Suffixs : Array_Element_Id :=
3264 Naming.Decl.Arrays);
3266 Suffix : Array_Element_Id;
3267 Element : Array_Element;
3268 Suffix2 : Array_Element_Id;
3271 -- If some suffixs have been specified, we make sure that
3272 -- for each language for which a default suffix has been
3273 -- specified, there is a suffix specified, either the one
3274 -- in the project file or if there were noe, the default.
3276 if Impl_Suffixs /= No_Array_Element then
3277 Suffix := Data.Naming.Body_Suffix;
3279 while Suffix /= No_Array_Element loop
3280 Element := Array_Elements.Table (Suffix);
3281 Suffix2 := Impl_Suffixs;
3283 while Suffix2 /= No_Array_Element loop
3284 exit when Array_Elements.Table (Suffix2).Index =
3286 Suffix2 := Array_Elements.Table (Suffix2).Next;
3289 -- There is a registered default suffix, but no
3290 -- suffix specified in the project file.
3291 -- Add the default to the array.
3293 if Suffix2 = No_Array_Element then
3294 Array_Elements.Increment_Last;
3295 Array_Elements.Table (Array_Elements.Last) :=
3296 (Index => Element.Index,
3297 Index_Case_Sensitive => False,
3298 Value => Element.Value,
3299 Next => Impl_Suffixs);
3300 Impl_Suffixs := Array_Elements.Last;
3303 Suffix := Element.Next;
3306 -- Put the resulting array as the implementation suffixs
3308 Data.Naming.Body_Suffix := Impl_Suffixs;
3313 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3314 Element : Array_Element;
3317 while Current /= No_Array_Element loop
3318 Element := Array_Elements.Table (Current);
3319 Get_Name_String (Element.Value.Value);
3321 if Name_Len = 0 then
3324 "Body_Suffix cannot be empty",
3325 Element.Value.Location);
3328 Array_Elements.Table (Current) := Element;
3329 Current := Element.Next;
3333 -- Get the exceptions, if any
3335 Data.Naming.Specification_Exceptions :=
3337 (Name_Specification_Exceptions,
3338 In_Arrays => Naming.Decl.Arrays);
3340 Data.Naming.Implementation_Exceptions :=
3342 (Name_Implementation_Exceptions,
3343 In_Arrays => Naming.Decl.Arrays);
3347 Projects.Table (Project) := Data;
3348 end Language_Independent_Check;
3350 ----------------------
3351 -- Locate_Directory --
3352 ----------------------
3354 procedure Locate_Directory
3358 Display : out Name_Id)
3360 The_Name : constant String := Get_Name_String (Name);
3361 The_Parent : constant String :=
3362 Get_Name_String (Parent) & Directory_Separator;
3363 The_Parent_Last : constant Natural :=
3364 Compute_Directory_Last (The_Parent);
3367 if Current_Verbosity = High then
3368 Write_Str ("Locate_Directory (""");
3369 Write_Str (The_Name);
3370 Write_Str (""", """);
3371 Write_Str (The_Parent);
3378 if Is_Absolute_Path (The_Name) then
3379 if Is_Directory (The_Name) then
3381 Normed : constant String :=
3382 Normalize_Pathname (The_Name);
3385 Name_Len := Normed'Length;
3386 Name_Buffer (1 .. Name_Len) := Normed;
3387 Display := Name_Find;
3388 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3395 Full_Path : constant String :=
3396 The_Parent (The_Parent'First .. The_Parent_Last) &
3400 if Is_Directory (Full_Path) then
3402 Normed : constant String :=
3403 Normalize_Pathname (Full_Path);
3406 Name_Len := Normed'Length;
3407 Name_Buffer (1 .. Name_Len) := Normed;
3408 Display := Name_Find;
3409 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3415 end Locate_Directory;
3421 function Path_Name_Of
3422 (File_Name : Name_Id;
3423 Directory : Name_Id)
3426 Result : String_Access;
3427 The_Directory : constant String := Get_Name_String (Directory);
3430 Get_Name_String (File_Name);
3431 Result := Locate_Regular_File
3432 (File_Name => Name_Buffer (1 .. Name_Len),
3433 Path => The_Directory);
3435 if Result = null then
3438 Canonical_Case_File_Name (Result.all);
3443 ---------------------
3444 -- Project_Extends --
3445 ---------------------
3447 function Project_Extends
3448 (Extending : Project_Id;
3449 Extended : Project_Id)
3452 Current : Project_Id := Extending;
3455 if Current = No_Project then
3458 elsif Current = Extended then
3462 Current := Projects.Table (Current).Extends;
3464 end Project_Extends;
3470 procedure Record_Source
3471 (File_Name : Name_Id;
3472 Path_Name : Name_Id;
3473 Project : Project_Id;
3474 Data : in out Project_Data;
3475 Location : Source_Ptr;
3476 Current_Source : in out String_List_Id;
3477 Source_Recorded : in out Boolean)
3479 Canonical_File_Name : Name_Id;
3480 Canonical_Path_Name : Name_Id;
3481 Unit_Name : Name_Id;
3482 Unit_Kind : Spec_Or_Body;
3483 Needs_Pragma : Boolean;
3485 The_Location : Source_Ptr := Location;
3486 Previous_Source : constant String_List_Id := Current_Source;
3487 Except_Name : Name_Id := No_Name;
3490 Get_Name_String (File_Name);
3491 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3492 Canonical_File_Name := Name_Find;
3493 Get_Name_String (Path_Name);
3494 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3495 Canonical_Path_Name := Name_Find;
3497 -- Find out the unit name, the unit kind and if it needs
3498 -- a specific SFN pragma.
3501 (Canonical_File_Name => Canonical_File_Name,
3502 Naming => Data.Naming,
3503 Unit_Name => Unit_Name,
3504 Unit_Kind => Unit_Kind,
3505 Needs_Pragma => Needs_Pragma);
3507 if Unit_Name = No_Name then
3508 if Current_Verbosity = High then
3510 Write_Str (Get_Name_String (Canonical_File_Name));
3511 Write_Line (""" is not a valid source file name (ignored).");
3515 -- Check to see if the source has been hidden by an exception,
3516 -- but only if it is not an exception.
3518 if not Needs_Pragma then
3520 Reverse_Naming_Exceptions.Get ((Unit_Kind, Unit_Name));
3522 if Except_Name /= No_Name then
3523 if Current_Verbosity = High then
3525 Write_Str (Get_Name_String (Canonical_File_Name));
3526 Write_Str (""" contains a unit that is found in """);
3527 Write_Str (Get_Name_String (Except_Name));
3528 Write_Line (""" (ignored).");
3531 -- The file is not included in the source of the project,
3532 -- because it is hidden by the exception.
3533 -- So, there is nothing else to do.
3539 -- Put the file name in the list of sources of the project
3541 String_Elements.Increment_Last;
3542 String_Elements.Table (String_Elements.Last) :=
3543 (Value => Canonical_File_Name,
3544 Display_Value => File_Name,
3545 Location => No_Location,
3547 Next => Nil_String);
3549 if Current_Source = Nil_String then
3550 Data.Sources := String_Elements.Last;
3553 String_Elements.Table (Current_Source).Next :=
3554 String_Elements.Last;
3557 Current_Source := String_Elements.Last;
3559 -- Put the unit in unit list
3562 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
3563 The_Unit_Data : Unit_Data;
3566 if Current_Verbosity = High then
3567 Write_Str ("Putting ");
3568 Write_Str (Get_Name_String (Unit_Name));
3569 Write_Line (" in the unit list.");
3572 -- The unit is already in the list, but may be it is
3573 -- only the other unit kind (spec or body), or what is
3574 -- in the unit list is a unit of a project we are extending.
3576 if The_Unit /= Prj.Com.No_Unit then
3577 The_Unit_Data := Units.Table (The_Unit);
3579 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
3580 or else Project_Extends
3582 The_Unit_Data.File_Names (Unit_Kind).Project)
3584 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
3585 Remove_Forbidden_File_Name
3586 (The_Unit_Data.File_Names (Unit_Kind).Name);
3589 The_Unit_Data.File_Names (Unit_Kind) :=
3590 (Name => Canonical_File_Name,
3591 Display_Name => File_Name,
3592 Path => Canonical_Path_Name,
3593 Display_Path => Path_Name,
3595 Needs_Pragma => Needs_Pragma);
3596 Units.Table (The_Unit) := The_Unit_Data;
3597 Source_Recorded := True;
3599 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
3600 and then (Data.Known_Order_Of_Source_Dirs or else
3601 The_Unit_Data.File_Names (Unit_Kind).Path =
3602 Canonical_Path_Name)
3604 if Previous_Source = Nil_String then
3605 Data.Sources := Nil_String;
3607 String_Elements.Table (Previous_Source).Next :=
3609 String_Elements.Decrement_Last;
3612 Current_Source := Previous_Source;
3615 -- It is an error to have two units with the same name
3616 -- and the same kind (spec or body).
3618 if The_Location = No_Location then
3619 The_Location := Projects.Table (Project).Location;
3622 Err_Vars.Error_Msg_Name_1 := Unit_Name;
3623 Error_Msg (Project, "duplicate source {", The_Location);
3625 Err_Vars.Error_Msg_Name_1 :=
3627 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
3628 Err_Vars.Error_Msg_Name_2 :=
3629 The_Unit_Data.File_Names (Unit_Kind).Path;
3630 Error_Msg (Project, "\ project file {, {", The_Location);
3632 Err_Vars.Error_Msg_Name_1 := Projects.Table (Project).Name;
3633 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
3634 Error_Msg (Project, "\ project file {, {", The_Location);
3638 -- It is a new unit, create a new record
3641 Units.Increment_Last;
3642 The_Unit := Units.Last;
3643 Units_Htable.Set (Unit_Name, The_Unit);
3644 The_Unit_Data.Name := Unit_Name;
3645 The_Unit_Data.File_Names (Unit_Kind) :=
3646 (Name => Canonical_File_Name,
3647 Display_Name => File_Name,
3648 Path => Canonical_Path_Name,
3649 Display_Path => Path_Name,
3651 Needs_Pragma => Needs_Pragma);
3652 Units.Table (The_Unit) := The_Unit_Data;
3653 Source_Recorded := True;
3659 ----------------------
3660 -- Show_Source_Dirs --
3661 ----------------------
3663 procedure Show_Source_Dirs (Project : Project_Id) is
3664 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
3665 Element : String_Element;
3668 Write_Line ("Source_Dirs:");
3670 while Current /= Nil_String loop
3671 Element := String_Elements.Table (Current);
3673 Write_Line (Get_Name_String (Element.Value));
3674 Current := Element.Next;
3677 Write_Line ("end Source_Dirs.");
3678 end Show_Source_Dirs;