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;
225 -------------------------------
226 -- Prepare_Naming_Exceptions --
227 -------------------------------
229 procedure Prepare_Naming_Exceptions
230 (List : Array_Element_Id;
233 Current : Array_Element_Id := List;
234 Element : Array_Element;
237 while Current /= No_Array_Element loop
238 Element := Array_Elements.Table (Current);
240 if Element.Index /= No_Name then
241 Naming_Exceptions.Set
242 (Element.Value.Value,
243 (Kind => Kind, Unit => Element.Index));
244 Reverse_Naming_Exceptions.Set
245 ((Kind => Kind, Unit => Element.Index),
246 Element.Value.Value);
249 Current := Element.Next;
251 end Prepare_Naming_Exceptions;
257 function Hash (Unit : Unit_Info) return Header_Num is
259 return Header_Num (Unit.Unit mod 2048);
262 ----------------------------
263 -- Free_Naming_Exceptions --
264 ----------------------------
266 procedure Free_Naming_Exceptions is
268 Naming_Exceptions.Reset;
269 Reverse_Naming_Exceptions.Reset;
270 end Free_Naming_Exceptions;
272 -------------------------
273 -- Check_Naming_Scheme --
274 -------------------------
276 procedure Check_Naming_Scheme
277 (Data : in out Project_Data;
278 Project : Project_Id)
280 Naming_Id : constant Package_Id :=
281 Util.Value_Of (Name_Naming, Data.Decl.Packages);
283 Naming : Package_Element;
285 procedure Check_Unit_Names (List : Array_Element_Id);
286 -- Check that a list of unit names contains only valid names.
288 ----------------------
289 -- Check_Unit_Names --
290 ----------------------
292 procedure Check_Unit_Names (List : Array_Element_Id) is
293 Current : Array_Element_Id := List;
294 Element : Array_Element;
298 -- Loop through elements of the string list
300 while Current /= No_Array_Element loop
301 Element := Array_Elements.Table (Current);
303 -- Put file name in canonical case
305 Get_Name_String (Element.Value.Value);
306 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
307 Element.Value.Value := Name_Find;
309 -- Check that it contains a valid unit name
311 Get_Name_String (Element.Index);
312 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
314 if Unit_Name = No_Name then
315 Err_Vars.Error_Msg_Name_1 := Element.Index;
318 "{ is not a valid unit name.",
319 Element.Value.Location);
322 if Current_Verbosity = High then
323 Write_Str (" Unit (""");
324 Write_Str (Get_Name_String (Unit_Name));
328 Element.Index := Unit_Name;
329 Array_Elements.Table (Current) := Element;
332 Current := Element.Next;
334 end Check_Unit_Names;
336 -- Start of processing for Check_Naming_Scheme
339 -- If there is a package Naming, we will put in Data.Naming what is in
340 -- this package Naming.
342 if Naming_Id /= No_Package then
343 Naming := Packages.Table (Naming_Id);
345 if Current_Verbosity = High then
346 Write_Line ("Checking ""Naming"" for Ada.");
350 Bodies : constant Array_Element_Id :=
351 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
353 Specs : constant Array_Element_Id :=
354 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
357 if Bodies /= No_Array_Element then
359 -- We have elements in the array Body_Part
361 if Current_Verbosity = High then
362 Write_Line ("Found Bodies.");
365 Data.Naming.Bodies := Bodies;
366 Check_Unit_Names (Bodies);
369 if Current_Verbosity = High then
370 Write_Line ("No Bodies.");
374 if Specs /= No_Array_Element then
376 -- We have elements in the array Specs
378 if Current_Verbosity = High then
379 Write_Line ("Found Specs.");
382 Data.Naming.Specs := Specs;
383 Check_Unit_Names (Specs);
386 if Current_Verbosity = High then
387 Write_Line ("No Specs.");
392 -- We are now checking if variables Dot_Replacement, Casing,
393 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
396 -- For each variable, if it does not exist, we do nothing,
397 -- because we already have the default.
399 -- Check Dot_Replacement
402 Dot_Replacement : constant Variable_Value :=
404 (Name_Dot_Replacement,
405 Naming.Decl.Attributes);
408 pragma Assert (Dot_Replacement.Kind = Single,
409 "Dot_Replacement is not a single string");
411 if not Dot_Replacement.Default then
412 Get_Name_String (Dot_Replacement.Value);
417 "Dot_Replacement cannot be empty",
418 Dot_Replacement.Location);
421 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
422 Data.Naming.Dot_Replacement := Name_Find;
423 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
428 if Current_Verbosity = High then
429 Write_Str (" Dot_Replacement = """);
430 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
438 Casing_String : constant Variable_Value :=
440 (Name_Casing, Naming.Decl.Attributes);
443 pragma Assert (Casing_String.Kind = Single,
444 "Casing is not a single string");
446 if not Casing_String.Default then
448 Casing_Image : constant String :=
449 Get_Name_String (Casing_String.Value);
452 Casing : constant Casing_Type := Value (Casing_Image);
454 Data.Naming.Casing := Casing;
458 when Constraint_Error =>
459 if Casing_Image'Length = 0 then
462 "Casing cannot be an empty string",
463 Casing_String.Location);
466 Name_Len := Casing_Image'Length;
467 Name_Buffer (1 .. Name_Len) := Casing_Image;
468 Err_Vars.Error_Msg_Name_1 := Name_Find;
471 "{ is not a correct Casing",
472 Casing_String.Location);
478 if Current_Verbosity = High then
479 Write_Str (" Casing = ");
480 Write_Str (Image (Data.Naming.Casing));
488 Ada_Spec_Suffix : constant Variable_Value :=
491 In_Array => Data.Naming.Spec_Suffix);
494 if Ada_Spec_Suffix.Kind = Single
495 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
497 Data.Naming.Current_Spec_Suffix := Ada_Spec_Suffix.Value;
498 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
501 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
505 if Current_Verbosity = High then
506 Write_Str (" Spec_Suffix = """);
507 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
515 Ada_Body_Suffix : constant Variable_Value :=
518 In_Array => Data.Naming.Body_Suffix);
521 if Ada_Body_Suffix.Kind = Single
522 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
524 Data.Naming.Current_Body_Suffix := Ada_Body_Suffix.Value;
525 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
528 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
532 if Current_Verbosity = High then
533 Write_Str (" Body_Suffix = """);
534 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
539 -- Check Separate_Suffix
542 Ada_Sep_Suffix : constant Variable_Value :=
544 (Variable_Name => Name_Separate_Suffix,
545 In_Variables => Naming.Decl.Attributes);
548 if Ada_Sep_Suffix.Default then
549 Data.Naming.Separate_Suffix :=
550 Data.Naming.Current_Body_Suffix;
553 if Get_Name_String (Ada_Sep_Suffix.Value) = "" then
556 "Separate_Suffix cannot be empty",
557 Ada_Sep_Suffix.Location);
560 Data.Naming.Separate_Suffix := Ada_Sep_Suffix.Value;
561 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
566 if Current_Verbosity = High then
567 Write_Str (" Separate_Suffix = """);
568 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
573 -- Check if Data.Naming is valid
575 Check_Ada_Naming_Scheme (Project, Data.Naming);
578 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
579 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
580 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
582 end Check_Naming_Scheme;
589 (Project : Project_Id;
590 Report_Error : Put_Line_Access)
593 Languages : Variable_Value := Nil_Variable_Value;
595 Extending : Boolean := False;
597 function Check_Project (P : Project_Id) return Boolean;
598 -- Returns True if P is Project or a project extended by Project
600 procedure Find_Sources;
601 -- Find all the sources in all of the source directories
604 procedure Get_Path_Names_And_Record_Sources;
605 -- Find the path names of the source files in the Source_Names table
606 -- in the source directories and record those that are Ada sources.
608 procedure Get_Sources_From_File
610 Location : Source_Ptr);
611 -- Get the sources of a project from a text file
613 procedure Warn_If_Not_Sources
614 (Conventions : Array_Element_Id;
616 -- Check that individual naming conventions apply to immediate
617 -- sources of the project; if not, issue a warning.
623 function Check_Project (P : Project_Id) return Boolean is
629 Data : Project_Data := Projects.Table (Project);
632 while Data.Extends /= No_Project loop
633 if P = Data.Extends then
637 Data := Projects.Table (Data.Extends);
649 procedure Find_Sources is
650 Source_Dir : String_List_Id := Data.Source_Dirs;
651 Element : String_Element;
653 Current_Source : String_List_Id := Nil_String;
654 Source_Recorded : Boolean := False;
657 if Current_Verbosity = High then
658 Write_Line ("Looking for sources:");
661 -- For each subdirectory
663 while Source_Dir /= Nil_String loop
665 Source_Recorded := False;
666 Element := String_Elements.Table (Source_Dir);
667 if Element.Value /= No_Name then
669 Source_Directory : constant String :=
670 Get_Name_String (Element.Value);
673 if Current_Verbosity = High then
674 Write_Str ("Source_Dir = ");
675 Write_Line (Source_Directory);
678 -- We look to every entry in the source directory
680 Open (Dir, Source_Directory);
682 -- Canonical_Case_File_Name (Source_Directory);
685 Read (Dir, Name_Buffer, Name_Len);
687 if Current_Verbosity = High then
688 Write_Str (" Checking ");
689 Write_Line (Name_Buffer (1 .. Name_Len));
692 exit when Name_Len = 0;
694 -- Canonical_Case_File_Name
695 -- (Name_Buffer (1 .. Name_Len));
698 File_Name : constant Name_Id := Name_Find;
699 Dir : constant String :=
702 Dir_Last : constant Natural :=
703 Compute_Directory_Last (Dir);
704 Path : constant String :=
706 (Name => Name_Buffer (1 .. Name_Len),
707 Directory => Dir (Dir'First .. Dir_Last));
711 if Is_Regular_File (Path) then
713 Name_Len := Path'Length;
714 Name_Buffer (1 .. Name_Len) := Path;
715 Path_Name := Name_Find;
717 -- We attempt to register it as a source.
718 -- However, there is no error if the file
719 -- does not contain a valid source.
720 -- But there is an error if we have a
721 -- duplicate unit name.
724 (File_Name => File_Name,
725 Path_Name => Path_Name,
728 Location => No_Location,
729 Current_Source => Current_Source,
730 Source_Recorded => Source_Recorded);
740 when Directory_Error =>
744 if Source_Recorded then
745 String_Elements.Table (Source_Dir).Flag := True;
748 Source_Dir := Element.Next;
751 if Current_Verbosity = High then
752 Write_Line ("end Looking for sources.");
755 -- If we have looked for sources and found none, then
756 -- it is an error, except if it is an extending project.
757 -- If a non extending project is not supposed to contain
758 -- any source, then we never call Find_Sources.
760 if Current_Source /= Nil_String then
761 Data.Sources_Present := True;
763 elsif Data.Extends = No_Project then
766 "there are no Ada sources in this project",
771 ---------------------------------------
772 -- Get_Path_Names_And_Record_Sources --
773 ---------------------------------------
775 procedure Get_Path_Names_And_Record_Sources is
776 Source_Dir : String_List_Id := Data.Source_Dirs;
777 Element : String_Element;
782 Canonical_Name : Name_Id;
783 Name_Str : String (1 .. 1_024);
787 Current_Source : String_List_Id := Nil_String;
789 First_Error : Boolean := True;
791 Source_Recorded : Boolean := False;
794 -- We look in all source directories for this file name
796 while Source_Dir /= Nil_String loop
797 Source_Recorded := False;
798 Element := String_Elements.Table (Source_Dir);
801 Dir_Path : constant String := Get_Name_String (Element.Value);
803 if Current_Verbosity = High then
804 Write_Str ("checking directory """);
805 Write_Str (Dir_Path);
809 Open (Dir, Dir_Path);
812 Read (Dir, Name_Str, Last);
815 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
817 Canonical_Case_File_Name (Name_Str (1 .. Last));
819 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
820 Canonical_Name := Name_Find;
821 NL := Source_Names.Get (Canonical_Name);
823 if NL /= No_Name_Location and then not NL.Found then
825 Source_Names.Set (Canonical_Name, NL);
826 Name_Len := Dir_Path'Length;
827 Name_Buffer (1 .. Name_Len) := Dir_Path;
828 Add_Char_To_Name_Buffer (Directory_Separator);
829 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
832 if Current_Verbosity = High then
833 Write_Str (" found ");
834 Write_Line (Get_Name_String (Name));
837 -- Register the source if it is an Ada compilation unit..
844 Location => NL.Location,
845 Current_Source => Current_Source,
846 Source_Recorded => Source_Recorded);
853 if Source_Recorded then
854 String_Elements.Table (Source_Dir).Flag := True;
857 Source_Dir := Element.Next;
860 -- It is an error if a source file name in a source list or
861 -- in a source list file is not found.
863 NL := Source_Names.Get_First;
865 while NL /= No_Name_Location loop
867 Err_Vars.Error_Msg_Name_1 := NL.Name;
872 "source file { cannot be found",
874 First_Error := False;
879 "\source file { cannot be found",
884 NL := Source_Names.Get_Next;
886 end Get_Path_Names_And_Record_Sources;
888 ---------------------------
889 -- Get_Sources_From_File --
890 ---------------------------
892 procedure Get_Sources_From_File
894 Location : Source_Ptr)
896 File : Prj.Util.Text_File;
897 Line : String (1 .. 250);
899 Source_Name : Name_Id;
902 if Current_Verbosity = High then
903 Write_Str ("Opening """);
910 Prj.Util.Open (File, Path);
912 if not Prj.Util.Is_Valid (File) then
913 Error_Msg (Project, "file does not exist", Location);
917 while not Prj.Util.End_Of_File (File) loop
918 Prj.Util.Get_Line (File, Line, Last);
920 -- If the line is not empty and does not start with "--",
921 -- then it should contain a file name. However, if the
922 -- file name does not exist, it may be for another language
923 -- and we don't fail.
926 and then (Last = 1 or else Line (1 .. 2) /= "--")
929 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
930 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
931 Source_Name := Name_Find;
935 (Name => Source_Name,
936 Location => Location,
941 Prj.Util.Close (File);
945 Get_Path_Names_And_Record_Sources;
947 -- We should have found at least one source.
948 -- If not, report an error.
950 if Data.Sources = Nil_String then
952 "there are no Ada sources in this project",
955 end Get_Sources_From_File;
957 -------------------------
958 -- Warn_If_Not_Sources --
959 -------------------------
961 procedure Warn_If_Not_Sources
962 (Conventions : Array_Element_Id;
965 Conv : Array_Element_Id := Conventions;
967 The_Unit_Id : Unit_Id;
968 The_Unit_Data : Unit_Data;
969 Location : Source_Ptr;
972 while Conv /= No_Array_Element loop
973 Unit := Array_Elements.Table (Conv).Index;
974 Error_Msg_Name_1 := Unit;
975 Get_Name_String (Unit);
976 To_Lower (Name_Buffer (1 .. Name_Len));
978 The_Unit_Id := Units_Htable.Get (Unit);
979 Location := Array_Elements.Table (Conv).Value.Location;
981 if The_Unit_Id = Prj.Com.No_Unit then
988 The_Unit_Data := Units.Table (The_Unit_Id);
992 (The_Unit_Data.File_Names (Specification).Project)
996 "?unit{ has no spec in this project",
1001 if not Check_Project
1002 (The_Unit_Data.File_Names (Com.Body_Part).Project)
1006 "?unit{ has no body in this project",
1012 Conv := Array_Elements.Table (Conv).Next;
1014 end Warn_If_Not_Sources;
1016 -- Start of processing for Ada_Check
1019 Language_Independent_Check (Project, Report_Error);
1021 Error_Report := Report_Error;
1023 Data := Projects.Table (Project);
1024 Extending := Data.Extends /= No_Project;
1025 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
1027 Data.Naming.Current_Language := Name_Ada;
1028 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
1030 if not Languages.Default then
1032 Current : String_List_Id := Languages.Values;
1033 Element : String_Element;
1034 Ada_Found : Boolean := False;
1037 Look_For_Ada : while Current /= Nil_String loop
1038 Element := String_Elements.Table (Current);
1039 Get_Name_String (Element.Value);
1040 To_Lower (Name_Buffer (1 .. Name_Len));
1042 if Name_Buffer (1 .. Name_Len) = "ada" then
1047 Current := Element.Next;
1048 end loop Look_For_Ada;
1050 if not Ada_Found then
1052 -- Mark the project file as having no sources for Ada
1054 Data.Sources_Present := False;
1059 Check_Naming_Scheme (Data, Project);
1061 Prepare_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
1062 Prepare_Naming_Exceptions (Data.Naming.Specs, Specification);
1064 -- If we have source directories, then find the sources
1066 if Data.Sources_Present then
1067 if Data.Source_Dirs = Nil_String then
1068 Data.Sources_Present := False;
1072 Sources : constant Variable_Value :=
1075 Data.Decl.Attributes);
1077 Source_List_File : constant Variable_Value :=
1079 (Name_Source_List_File,
1080 Data.Decl.Attributes);
1082 Locally_Removed : constant Variable_Value :=
1084 (Name_Locally_Removed_Files,
1085 Data.Decl.Attributes);
1089 (Sources.Kind = List,
1090 "Source_Files is not a list");
1093 (Source_List_File.Kind = Single,
1094 "Source_List_File is not a single string");
1096 if not Sources.Default then
1097 if not Source_List_File.Default then
1100 "?both variables source_files and " &
1101 "source_list_file are present",
1102 Source_List_File.Location);
1105 -- Sources is a list of file names
1108 Current : String_List_Id := Sources.Values;
1109 Element : String_Element;
1110 Location : Source_Ptr;
1116 Data.Sources_Present := Current /= Nil_String;
1118 while Current /= Nil_String loop
1119 Element := String_Elements.Table (Current);
1120 Get_Name_String (Element.Value);
1121 Canonical_Case_File_Name
1122 (Name_Buffer (1 .. Name_Len));
1125 -- If the element has no location, then use the
1126 -- location of Sources to report possible errors.
1128 if Element.Location = No_Location then
1129 Location := Sources.Location;
1132 Location := Element.Location;
1139 Location => Location,
1142 Current := Element.Next;
1145 Get_Path_Names_And_Record_Sources;
1148 -- No source_files specified.
1149 -- We check Source_List_File has been specified.
1151 elsif not Source_List_File.Default then
1153 -- Source_List_File is the name of the file
1154 -- that contains the source file names
1157 Source_File_Path_Name : constant String :=
1159 (Source_List_File.Value,
1163 if Source_File_Path_Name'Length = 0 then
1164 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
1167 "file with sources { does not exist",
1168 Source_List_File.Location);
1171 Get_Sources_From_File
1172 (Source_File_Path_Name,
1173 Source_List_File.Location);
1178 -- Neither Source_Files nor Source_List_File has been
1180 -- Find all the files that satisfy
1181 -- the naming scheme in all the source directories.
1186 -- If there are sources that are locally removed, mark them as
1187 -- such in the Units table.
1189 if not Locally_Removed.Default then
1190 -- Sources can be locally removed only in extending
1193 if Data.Extends = No_Project then
1196 "Locally_Removed_Files can only be used " &
1197 "in an extending project file",
1198 Locally_Removed.Location);
1202 Current : String_List_Id :=
1203 Locally_Removed.Values;
1204 Element : String_Element;
1205 Location : Source_Ptr;
1209 Extended : Project_Id;
1212 while Current /= Nil_String loop
1213 Element := String_Elements.Table (Current);
1214 Get_Name_String (Element.Value);
1215 Canonical_Case_File_Name
1216 (Name_Buffer (1 .. Name_Len));
1219 -- If the element has no location, then use the
1220 -- location of Locally_Removed to report
1223 if Element.Location = No_Location then
1224 Location := Locally_Removed.Location;
1227 Location := Element.Location;
1232 for Index in 1 .. Units.Last loop
1233 Unit := Units.Table (Index);
1236 Unit.File_Names (Specification).Name = Name
1240 -- Check that this is from a project that
1241 -- the current project extends, but not the
1244 Extended := Unit.File_Names
1245 (Specification).Project;
1247 if Extended = Project then
1250 "cannot remove a source " &
1251 "of the same project",
1255 Project_Extends (Project, Extended)
1258 (Specification).Path := Slash;
1260 (Specification).Needs_Pragma := False;
1261 Units.Table (Index) := Unit;
1262 Add_Forbidden_File_Name
1263 (Unit.File_Names (Specification).Name);
1269 "cannot remove a source from " &
1275 Unit.File_Names (Body_Part).Name = Name
1279 -- Check that this is from a project that
1280 -- the current project extends, but not the
1283 Extended := Unit.File_Names
1284 (Body_Part).Project;
1286 if Extended = Project then
1289 "cannot remove a source " &
1290 "of the same project",
1294 Project_Extends (Project, Extended)
1296 Unit.File_Names (Body_Part).Path := Slash;
1297 Unit.File_Names (Body_Part).Needs_Pragma
1299 Units.Table (Index) := Unit;
1300 Add_Forbidden_File_Name
1301 (Unit.File_Names (Body_Part).Name);
1309 Err_Vars.Error_Msg_Name_1 := Name;
1310 Error_Msg (Project, "unknown file {", Location);
1313 Current := Element.Next;
1322 if Data.Sources_Present then
1324 -- Check that all individual naming conventions apply to
1325 -- sources of this project file.
1327 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
1328 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
1331 -- If it is a library project file, check if it is a standalone library
1333 if Data.Library then
1334 Standalone_Library : declare
1335 Lib_Interfaces : constant Prj.Variable_Value :=
1337 (Snames.Name_Library_Interface,
1338 Data.Decl.Attributes);
1339 Lib_Auto_Init : constant Prj.Variable_Value :=
1341 (Snames.Name_Library_Auto_Init,
1342 Data.Decl.Attributes);
1344 Lib_Src_Dir : constant Prj.Variable_Value :=
1346 (Snames.Name_Library_Src_Dir,
1347 Data.Decl.Attributes);
1349 Lib_Symbol_File : constant Prj.Variable_Value :=
1351 (Snames.Name_Library_Symbol_File,
1352 Data.Decl.Attributes);
1354 Lib_Symbol_Policy : constant Prj.Variable_Value :=
1356 (Snames.Name_Library_Symbol_Policy,
1357 Data.Decl.Attributes);
1359 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
1361 (Snames.Name_Library_Reference_Symbol_File,
1362 Data.Decl.Attributes);
1364 Auto_Init_Supported : constant Boolean :=
1366 Standalone_Library_Auto_Init_Is_Supported;
1368 OK : Boolean := True;
1371 pragma Assert (Lib_Interfaces.Kind = List);
1373 -- It is a stand-alone library project file if attribute
1374 -- Library_Interface is defined.
1376 if not Lib_Interfaces.Default then
1378 Interfaces : String_List_Id := Lib_Interfaces.Values;
1379 Interface_ALIs : String_List_Id := Nil_String;
1381 The_Unit_Id : Unit_Id;
1382 The_Unit_Data : Unit_Data;
1384 procedure Add_ALI_For (Source : Name_Id);
1385 -- Add an ALI file name to the list of Interface ALIs
1391 procedure Add_ALI_For (Source : Name_Id) is
1393 Get_Name_String (Source);
1396 ALI : constant String :=
1397 ALI_File_Name (Name_Buffer (1 .. Name_Len));
1398 ALI_Name_Id : Name_Id;
1400 Name_Len := ALI'Length;
1401 Name_Buffer (1 .. Name_Len) := ALI;
1402 ALI_Name_Id := Name_Find;
1404 String_Elements.Increment_Last;
1405 String_Elements.Table (String_Elements.Last) :=
1406 (Value => ALI_Name_Id,
1407 Display_Value => ALI_Name_Id,
1408 Location => String_Elements.Table
1409 (Interfaces).Location,
1411 Next => Interface_ALIs);
1412 Interface_ALIs := String_Elements.Last;
1417 Data.Standalone_Library := True;
1419 -- Library_Interface cannot be an empty list
1421 if Interfaces = Nil_String then
1424 "Library_Interface cannot be an empty list",
1425 Lib_Interfaces.Location);
1428 -- Process each unit name specified in the attribute
1429 -- Library_Interface.
1431 while Interfaces /= Nil_String loop
1433 (String_Elements.Table (Interfaces).Value);
1434 To_Lower (Name_Buffer (1 .. Name_Len));
1436 if Name_Len = 0 then
1439 "an interface cannot be an empty string",
1440 String_Elements.Table (Interfaces).Location);
1444 Error_Msg_Name_1 := Unit;
1445 The_Unit_Id := Units_Htable.Get (Unit);
1447 if The_Unit_Id = Prj.Com.No_Unit then
1451 String_Elements.Table (Interfaces).Location);
1454 -- Check that the unit is part of the project
1456 The_Unit_Data := Units.Table (The_Unit_Id);
1458 if The_Unit_Data.File_Names
1459 (Com.Body_Part).Name /= No_Name
1460 and then The_Unit_Data.File_Names
1461 (Com.Body_Part).Path /= Slash
1464 (The_Unit_Data.File_Names (Body_Part).Project)
1466 -- There is a body for this unit.
1467 -- If there is no spec, we need to check
1468 -- that it is not a subunit.
1470 if The_Unit_Data.File_Names
1471 (Specification).Name = No_Name
1474 Src_Ind : Source_File_Index;
1477 Src_Ind := Sinput.P.Load_Project_File
1479 (The_Unit_Data.File_Names
1482 if Sinput.P.Source_File_Is_Subunit
1487 "{ is a subunit; " &
1488 "it cannot be an interface",
1489 String_Elements.Table
1490 (Interfaces).Location);
1495 -- The unit is not a subunit, so we add
1496 -- to the Interface ALIs the ALI file
1497 -- corresponding to the body.
1500 (The_Unit_Data.File_Names (Body_Part).Name);
1505 "{ is not an unit of this project",
1506 String_Elements.Table
1507 (Interfaces).Location);
1510 elsif The_Unit_Data.File_Names
1511 (Com.Specification).Name /= No_Name
1512 and then The_Unit_Data.File_Names
1513 (Com.Specification).Path /= Slash
1514 and then Check_Project
1515 (The_Unit_Data.File_Names
1516 (Specification).Project)
1519 -- The unit is part of the project, it has
1520 -- a spec, but no body. We add to the Interface
1521 -- ALIs the ALI file corresponding to the spec.
1524 (The_Unit_Data.File_Names (Specification).Name);
1529 "{ is not an unit of this project",
1530 String_Elements.Table (Interfaces).Location);
1536 Interfaces := String_Elements.Table (Interfaces).Next;
1539 -- Put the list of Interface ALIs in the project data
1541 Data.Lib_Interface_ALIs := Interface_ALIs;
1543 -- Check value of attribute Library_Auto_Init and set
1544 -- Lib_Auto_Init accordingly.
1546 if Lib_Auto_Init.Default then
1547 -- If no attribute Library_Auto_Init is declared, then
1548 -- set auto init only if it is supported.
1550 Data.Lib_Auto_Init := Auto_Init_Supported;
1553 Get_Name_String (Lib_Auto_Init.Value);
1554 To_Lower (Name_Buffer (1 .. Name_Len));
1556 if Name_Buffer (1 .. Name_Len) = "false" then
1557 Data.Lib_Auto_Init := False;
1559 elsif Name_Buffer (1 .. Name_Len) = "true" then
1560 if Auto_Init_Supported then
1561 Data.Lib_Auto_Init := True;
1564 -- Library_Auto_Init cannot be "true" if auto init
1569 "library auto init not supported " &
1571 Lib_Auto_Init.Location);
1577 "invalid value for attribute Library_Auto_Init",
1578 Lib_Auto_Init.Location);
1583 -- If attribute Library_Src_Dir is defined and not the
1584 -- empty string, check if the directory exist and is not
1585 -- the object directory or one of the source directories.
1586 -- This is the directory where copies of the interface
1587 -- sources will be copied. Note that this directory may be
1588 -- the library directory.
1590 if Lib_Src_Dir.Value /= Empty_String then
1592 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1596 (Dir_Id, Data.Display_Directory,
1597 Data.Library_Src_Dir,
1598 Data.Display_Library_Src_Dir);
1600 -- If directory does not exist, report an error
1602 if Data.Library_Src_Dir = No_Name then
1604 -- Get the absolute name of the library directory
1605 -- that does not exist, to report an error.
1608 Dir_Name : constant String :=
1609 Get_Name_String (Dir_Id);
1612 if Is_Absolute_Path (Dir_Name) then
1613 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1616 Get_Name_String (Data.Directory);
1618 if Name_Buffer (Name_Len) /=
1621 Name_Len := Name_Len + 1;
1622 Name_Buffer (Name_Len) :=
1623 Directory_Separator;
1628 Name_Len + Dir_Name'Length) :=
1630 Name_Len := Name_Len + Dir_Name'Length;
1631 Err_Vars.Error_Msg_Name_1 := Name_Find;
1638 "Directory { does not exist",
1639 Lib_Src_Dir.Location);
1642 -- Report an error if it is the same as the object
1645 elsif Data.Library_Src_Dir = Data.Object_Directory then
1648 "directory to copy interfaces cannot be " &
1649 "the object directory",
1650 Lib_Src_Dir.Location);
1651 Data.Library_Src_Dir := No_Name;
1653 -- Check if it is the same as one of the source
1658 Src_Dirs : String_List_Id := Data.Source_Dirs;
1659 Src_Dir : String_Element;
1662 while Src_Dirs /= Nil_String loop
1663 Src_Dir := String_Elements.Table (Src_Dirs);
1664 Src_Dirs := Src_Dir.Next;
1666 -- Report an error if it is one of the
1667 -- source directories.
1669 if Data.Library_Src_Dir = Src_Dir.Value then
1672 "directory to copy interfaces cannot " &
1673 "be one of the source directories",
1674 Lib_Src_Dir.Location);
1675 Data.Library_Src_Dir := No_Name;
1681 if Data.Library_Src_Dir /= No_Name
1682 and then Current_Verbosity = High
1684 Write_Str ("Directory to copy interfaces =""");
1685 Write_Str (Get_Name_String (Data.Library_Dir));
1692 if not Lib_Symbol_File.Default then
1693 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1695 Get_Name_String (Lib_Symbol_File.Value);
1697 if Name_Len = 0 then
1700 "symbol file name cannot be an empty string",
1701 Lib_Symbol_File.Location);
1704 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1707 for J in 1 .. Name_Len loop
1708 if Name_Buffer (J) = '/'
1709 or else Name_Buffer (J) = Directory_Separator
1718 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1721 "symbol file name { is illegal. " &
1722 "Name canot include directory info.",
1723 Lib_Symbol_File.Location);
1728 if not Lib_Symbol_Policy.Default then
1730 Value : constant String :=
1732 (Get_Name_String (Lib_Symbol_Policy.Value));
1735 if Value = "autonomous" or else Value = "default" then
1736 Data.Symbol_Data.Symbol_Policy := Autonomous;
1738 elsif Value = "compliant" then
1739 Data.Symbol_Data.Symbol_Policy := Compliant;
1741 elsif Value = "controlled" then
1742 Data.Symbol_Data.Symbol_Policy := Controlled;
1747 "illegal value for Library_Symbol_Policy",
1748 Lib_Symbol_Policy.Location);
1753 if Lib_Ref_Symbol_File.Default then
1754 if Data.Symbol_Data.Symbol_Policy /= Autonomous then
1757 "a reference symbol file need to be defined",
1758 Lib_Symbol_Policy.Location);
1762 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1764 Get_Name_String (Lib_Symbol_File.Value);
1766 if Name_Len = 0 then
1769 "reference symbol file name cannot be an empty string",
1770 Lib_Symbol_File.Location);
1773 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1776 for J in 1 .. Name_Len loop
1777 if Name_Buffer (J) = '/'
1778 or else Name_Buffer (J) = Directory_Separator
1787 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1790 "reference symbol file { name is illegal. " &
1791 "Name canot include directory info.",
1792 Lib_Ref_Symbol_File.Location);
1795 if not Is_Regular_File
1796 (Get_Name_String (Data.Object_Directory) &
1797 Directory_Separator &
1798 Get_Name_String (Lib_Ref_Symbol_File.Value))
1800 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1803 "library reference symbol file { does not exist",
1804 Lib_Ref_Symbol_File.Location);
1807 if Data.Symbol_Data.Symbol_File /= No_Name then
1811 (Data.Symbol_Data.Symbol_File);
1813 Reference : String :=
1815 (Data.Symbol_Data.Reference);
1818 Canonical_Case_File_Name (Symbol);
1819 Canonical_Case_File_Name (Reference);
1821 if Symbol = Reference then
1824 "reference symbol file and symbol file " &
1825 "cannot be the same file",
1826 Lib_Ref_Symbol_File.Location);
1833 end Standalone_Library;
1836 -- Put the list of Mains, if any, in the project data
1839 Mains : constant Variable_Value :=
1840 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
1843 Data.Mains := Mains.Values;
1845 -- If no Mains were specified, and if we are an extending
1846 -- project, inherit the Mains from the project we are extending.
1848 if Mains.Default then
1849 if Data.Extends /= No_Project then
1850 Data.Mains := Projects.Table (Data.Extends).Mains;
1853 -- In a library project file, Main cannot be specified
1855 elsif Data.Library then
1858 "a library project file cannot have Main specified",
1863 Projects.Table (Project) := Data;
1865 Free_Naming_Exceptions;
1872 function ALI_File_Name (Source : String) return String is
1874 -- If the source name has an extension, then replace it with
1877 for Index in reverse Source'First + 1 .. Source'Last loop
1878 if Source (Index) = '.' then
1879 return Source (Source'First .. Index - 1) & ALI_Suffix;
1883 -- If there is no dot, or if it is the first character, just add the
1886 return Source & ALI_Suffix;
1889 --------------------
1890 -- Check_Ada_Name --
1891 --------------------
1893 procedure Check_Ada_Name
1897 The_Name : String := Name;
1898 Real_Name : Name_Id;
1899 Need_Letter : Boolean := True;
1900 Last_Underscore : Boolean := False;
1901 OK : Boolean := The_Name'Length > 0;
1904 To_Lower (The_Name);
1906 Name_Len := The_Name'Length;
1907 Name_Buffer (1 .. Name_Len) := The_Name;
1908 Real_Name := Name_Find;
1910 -- Check first that the given name is not an Ada reserved word
1912 if Get_Name_Table_Byte (Real_Name) /= 0
1913 and then Real_Name /= Name_Project
1914 and then Real_Name /= Name_Extends
1915 and then Real_Name /= Name_External
1919 if Current_Verbosity = High then
1920 Write_Str (The_Name);
1921 Write_Line (" is an Ada reserved word.");
1927 for Index in The_Name'Range loop
1930 -- We need a letter (at the beginning, and following a dot),
1931 -- but we don't have one.
1933 if Is_Letter (The_Name (Index)) then
1934 Need_Letter := False;
1939 if Current_Verbosity = High then
1940 Write_Int (Types.Int (Index));
1942 Write_Char (The_Name (Index));
1943 Write_Line ("' is not a letter.");
1949 elsif Last_Underscore
1950 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1952 -- Two underscores are illegal, and a dot cannot follow
1957 if Current_Verbosity = High then
1958 Write_Int (Types.Int (Index));
1960 Write_Char (The_Name (Index));
1961 Write_Line ("' is illegal here.");
1966 elsif The_Name (Index) = '.' then
1968 -- We need a letter after a dot
1970 Need_Letter := True;
1972 elsif The_Name (Index) = '_' then
1973 Last_Underscore := True;
1976 -- We need an letter or a digit
1978 Last_Underscore := False;
1980 if not Is_Alphanumeric (The_Name (Index)) then
1983 if Current_Verbosity = High then
1984 Write_Int (Types.Int (Index));
1986 Write_Char (The_Name (Index));
1987 Write_Line ("' is not alphanumeric.");
1995 -- Cannot end with an underscore or a dot
1997 OK := OK and then not Need_Letter and then not Last_Underscore;
2003 -- Signal a problem with No_Name
2009 -----------------------------
2010 -- Check_Ada_Naming_Scheme --
2011 -----------------------------
2013 procedure Check_Ada_Naming_Scheme
2014 (Project : Project_Id;
2015 Naming : Naming_Data)
2018 -- Only check if we are not using the standard naming scheme
2020 if Naming /= Standard_Naming_Data then
2022 Dot_Replacement : constant String :=
2024 (Naming.Dot_Replacement);
2026 Spec_Suffix : constant String :=
2028 (Naming.Current_Spec_Suffix);
2030 Body_Suffix : constant String :=
2032 (Naming.Current_Body_Suffix);
2034 Separate_Suffix : constant String :=
2036 (Naming.Separate_Suffix);
2039 -- Dot_Replacement cannot
2041 -- - start or end with an alphanumeric
2042 -- - be a single '_'
2043 -- - start with an '_' followed by an alphanumeric
2044 -- - contain a '.' except if it is "."
2046 if Dot_Replacement'Length = 0
2047 or else Is_Alphanumeric
2048 (Dot_Replacement (Dot_Replacement'First))
2049 or else Is_Alphanumeric
2050 (Dot_Replacement (Dot_Replacement'Last))
2051 or else (Dot_Replacement (Dot_Replacement'First) = '_'
2053 (Dot_Replacement'Length = 1
2056 (Dot_Replacement (Dot_Replacement'First + 1))))
2057 or else (Dot_Replacement'Length > 1
2059 Index (Source => Dot_Replacement,
2060 Pattern => ".") /= 0)
2064 '"' & Dot_Replacement &
2065 """ is illegal for Dot_Replacement.",
2066 Naming.Dot_Repl_Loc);
2072 if Is_Illegal_Suffix
2073 (Spec_Suffix, Dot_Replacement = ".")
2075 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
2078 "{ is illegal for Spec_Suffix",
2079 Naming.Spec_Suffix_Loc);
2082 if Is_Illegal_Suffix
2083 (Body_Suffix, Dot_Replacement = ".")
2085 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
2088 "{ is illegal for Body_Suffix",
2089 Naming.Body_Suffix_Loc);
2092 if Body_Suffix /= Separate_Suffix then
2093 if Is_Illegal_Suffix
2094 (Separate_Suffix, Dot_Replacement = ".")
2096 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
2099 "{ is illegal for Separate_Suffix",
2100 Naming.Sep_Suffix_Loc);
2104 -- Spec_Suffix cannot have the same termination as
2105 -- Body_Suffix or Separate_Suffix
2107 if Spec_Suffix'Length <= Body_Suffix'Length
2109 Body_Suffix (Body_Suffix'Last -
2110 Spec_Suffix'Length + 1 ..
2111 Body_Suffix'Last) = Spec_Suffix
2117 """) cannot end with" &
2118 " Spec_Suffix (""" &
2119 Spec_Suffix & """).",
2120 Naming.Body_Suffix_Loc);
2123 if Body_Suffix /= Separate_Suffix
2124 and then Spec_Suffix'Length <= Separate_Suffix'Length
2127 (Separate_Suffix'Last - Spec_Suffix'Length + 1
2129 Separate_Suffix'Last) = Spec_Suffix
2133 "Separate_Suffix (""" &
2135 """) cannot end with" &
2136 " Spec_Suffix (""" &
2137 Spec_Suffix & """).",
2138 Naming.Sep_Suffix_Loc);
2142 end Check_Ada_Naming_Scheme;
2149 (Project : Project_Id;
2151 Flag_Location : Source_Ptr)
2153 Error_Buffer : String (1 .. 5_000);
2154 Error_Last : Natural := 0;
2155 Msg_Name : Natural := 0;
2156 First : Positive := Msg'First;
2158 procedure Add (C : Character);
2159 -- Add a character to the buffer
2161 procedure Add (S : String);
2162 -- Add a string to the buffer
2164 procedure Add (Id : Name_Id);
2165 -- Add a name to the buffer
2171 procedure Add (C : Character) is
2173 Error_Last := Error_Last + 1;
2174 Error_Buffer (Error_Last) := C;
2177 procedure Add (S : String) is
2179 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2180 Error_Last := Error_Last + S'Length;
2183 procedure Add (Id : Name_Id) is
2185 Get_Name_String (Id);
2186 Add (Name_Buffer (1 .. Name_Len));
2189 -- Start of processing for Error_Msg
2192 if Error_Report = null then
2193 Prj.Err.Error_Msg (Msg, Flag_Location);
2197 if Msg (First) = '\' then
2199 -- Continuation character, ignore.
2203 elsif Msg (First) = '?' then
2205 -- Warning character. It is always the first one in this package
2211 for Index in First .. Msg'Last loop
2212 if Msg (Index) = '{' or else Msg (Index) = '%' then
2214 -- Include a name between double quotes.
2216 Msg_Name := Msg_Name + 1;
2220 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2221 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2222 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2224 when others => null;
2235 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2243 (Canonical_File_Name : Name_Id;
2244 Naming : Naming_Data;
2245 Unit_Name : out Name_Id;
2246 Unit_Kind : out Spec_Or_Body;
2247 Needs_Pragma : out Boolean)
2249 function Check_Exception (Canonical : Name_Id) return Boolean;
2250 pragma Inline (Check_Exception);
2251 -- Check if Canonical is one of the exceptions in List.
2252 -- Returns True if Get_Unit should exit
2254 ---------------------
2255 -- Check_Exception --
2256 ---------------------
2258 function Check_Exception (Canonical : Name_Id) return Boolean is
2259 Info : Unit_Info := Naming_Exceptions.Get (Canonical);
2263 if Info = No_Unit then
2264 if Hostparm.OpenVMS then
2265 VMS_Name := Canonical;
2266 Get_Name_String (VMS_Name);
2268 if Name_Buffer (Name_Len) = '.' then
2269 Name_Len := Name_Len - 1;
2270 VMS_Name := Name_Find;
2273 Info := Naming_Exceptions.Get (VMS_Name);
2276 if Info = No_Unit then
2281 Unit_Kind := Info.Kind;
2282 Unit_Name := Info.Unit;
2283 Needs_Pragma := True;
2285 end Check_Exception;
2287 -- Start of processing for Get_Unit
2290 Needs_Pragma := False;
2292 if Check_Exception (Canonical_File_Name) then
2296 Get_Name_String (Canonical_File_Name);
2299 File : String := Name_Buffer (1 .. Name_Len);
2300 First : constant Positive := File'First;
2301 Last : Natural := File'Last;
2302 Standard_GNAT : Boolean;
2306 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2307 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2309 -- Check if the end of the file name is Specification_Append
2311 Get_Name_String (Naming.Current_Spec_Suffix);
2313 if File'Length > Name_Len
2314 and then File (Last - Name_Len + 1 .. Last) =
2315 Name_Buffer (1 .. Name_Len)
2319 Unit_Kind := Specification;
2320 Last := Last - Name_Len;
2322 if Current_Verbosity = High then
2323 Write_Str (" Specification: ");
2324 Write_Line (File (First .. Last));
2328 Get_Name_String (Naming.Current_Body_Suffix);
2330 -- Check if the end of the file name is Body_Append
2332 if File'Length > Name_Len
2333 and then File (Last - Name_Len + 1 .. Last) =
2334 Name_Buffer (1 .. Name_Len)
2338 Unit_Kind := Body_Part;
2339 Last := Last - Name_Len;
2341 if Current_Verbosity = High then
2342 Write_Str (" Body: ");
2343 Write_Line (File (First .. Last));
2346 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2347 Get_Name_String (Naming.Separate_Suffix);
2349 -- Check if the end of the file name is Separate_Append
2351 if File'Length > Name_Len
2352 and then File (Last - Name_Len + 1 .. Last) =
2353 Name_Buffer (1 .. Name_Len)
2355 -- We have a separate (a body)
2357 Unit_Kind := Body_Part;
2358 Last := Last - Name_Len;
2360 if Current_Verbosity = High then
2361 Write_Str (" Separate: ");
2362 Write_Line (File (First .. Last));
2376 -- This is not a source file
2378 Unit_Name := No_Name;
2379 Unit_Kind := Specification;
2381 if Current_Verbosity = High then
2382 Write_Line (" Not a valid file name.");
2388 Get_Name_String (Naming.Dot_Replacement);
2390 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2392 if Name_Buffer (1 .. Name_Len) /= "." then
2394 -- If Dot_Replacement is not a single dot,
2395 -- then there should not be any dot in the name.
2397 for Index in First .. Last loop
2398 if File (Index) = '.' then
2399 if Current_Verbosity = High then
2401 (" Not a valid file name (some dot not replaced).");
2404 Unit_Name := No_Name;
2410 -- Replace the substring Dot_Replacement with dots
2413 Index : Positive := First;
2416 while Index <= Last - Name_Len + 1 loop
2418 if File (Index .. Index + Name_Len - 1) =
2419 Name_Buffer (1 .. Name_Len)
2421 File (Index) := '.';
2423 if Name_Len > 1 and then Index < Last then
2424 File (Index + 1 .. Last - Name_Len + 1) :=
2425 File (Index + Name_Len .. Last);
2428 Last := Last - Name_Len + 1;
2436 -- Check if the casing is right
2439 Src : String := File (First .. Last);
2442 case Naming.Casing is
2443 when All_Lower_Case =>
2446 Mapping => Lower_Case_Map);
2448 when All_Upper_Case =>
2451 Mapping => Upper_Case_Map);
2453 when Mixed_Case | Unknown =>
2457 if Src /= File (First .. Last) then
2458 if Current_Verbosity = High then
2459 Write_Line (" Not a valid file name (casing).");
2462 Unit_Name := No_Name;
2466 -- We put the name in lower case
2470 Mapping => Lower_Case_Map);
2472 -- In the standard GNAT naming scheme, check for special cases:
2473 -- children or separates of A, G, I or S, and run time sources.
2475 if Standard_GNAT and then Src'Length >= 3 then
2477 S1 : constant Character := Src (Src'First);
2478 S2 : constant Character := Src (Src'First + 1);
2481 if S1 = 'a' or else S1 = 'g'
2482 or else S1 = 'i' or else S1 = 's'
2484 -- Children or separates of packages A, G, I or S
2486 if (Hostparm.OpenVMS and then S2 = '$')
2487 or else (not Hostparm.OpenVMS and then S2 = '~')
2489 Src (Src'First + 1) := '.';
2491 -- If it is potentially a run time source, disable
2492 -- filling of the mapping file to avoid warnings.
2495 Set_Mapping_File_Initial_State_To_Empty;
2502 if Current_Verbosity = High then
2507 -- Now, we check if this name is a valid unit name
2509 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2515 -----------------------
2516 -- Is_Illegal_Suffix --
2517 -----------------------
2519 function Is_Illegal_Suffix
2521 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2524 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2528 -- If dot replacement is a single dot, and first character of
2529 -- suffix is also a dot
2531 if Dot_Replacement_Is_A_Single_Dot
2532 and then Suffix (Suffix'First) = '.'
2534 for Index in Suffix'First + 1 .. Suffix'Last loop
2536 -- If there is another dot
2538 if Suffix (Index) = '.' then
2540 -- It is illegal to have a letter following the initial dot
2542 return Is_Letter (Suffix (Suffix'First + 1));
2550 end Is_Illegal_Suffix;
2552 --------------------------------
2553 -- Language_Independent_Check --
2554 --------------------------------
2556 procedure Language_Independent_Check
2557 (Project : Project_Id;
2558 Report_Error : Put_Line_Access)
2560 Last_Source_Dir : String_List_Id := Nil_String;
2561 Data : Project_Data := Projects.Table (Project);
2563 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2564 -- Find one or several source directories, and add them
2565 -- to the list of source directories of the project.
2567 ----------------------
2568 -- Find_Source_Dirs --
2569 ----------------------
2571 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2572 Directory : constant String := Get_Name_String (From);
2573 Element : String_Element;
2575 procedure Recursive_Find_Dirs (Path : Name_Id);
2576 -- Find all the subdirectories (recursively) of Path and add them
2577 -- to the list of source directories of the project.
2579 -------------------------
2580 -- Recursive_Find_Dirs --
2581 -------------------------
2583 procedure Recursive_Find_Dirs (Path : Name_Id) is
2585 Name : String (1 .. 250);
2587 List : String_List_Id := Data.Source_Dirs;
2588 Element : String_Element;
2589 Found : Boolean := False;
2591 Non_Canonical_Path : Name_Id := No_Name;
2592 Canonical_Path : Name_Id := No_Name;
2594 The_Path : constant String :=
2595 Normalize_Pathname (Get_Name_String (Path)) &
2596 Directory_Separator;
2598 The_Path_Last : constant Natural :=
2599 Compute_Directory_Last (The_Path);
2602 Name_Len := The_Path_Last - The_Path'First + 1;
2603 Name_Buffer (1 .. Name_Len) :=
2604 The_Path (The_Path'First .. The_Path_Last);
2605 Non_Canonical_Path := Name_Find;
2606 Get_Name_String (Non_Canonical_Path);
2607 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2608 Canonical_Path := Name_Find;
2610 -- To avoid processing the same directory several times, check
2611 -- if the directory is already in Recursive_Dirs. If it is,
2612 -- then there is nothing to do, just return. If it is not, put
2613 -- it there and continue recursive processing.
2615 if Recursive_Dirs.Get (Canonical_Path) then
2619 Recursive_Dirs.Set (Canonical_Path, True);
2622 -- Check if directory is already in list
2624 while List /= Nil_String loop
2625 Element := String_Elements.Table (List);
2627 if Element.Value /= No_Name then
2628 Found := Element.Value = Canonical_Path;
2632 List := Element.Next;
2635 -- If directory is not already in list, put it there
2638 if Current_Verbosity = High then
2640 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2643 String_Elements.Increment_Last;
2645 (Value => Canonical_Path,
2646 Display_Value => Non_Canonical_Path,
2647 Location => No_Location,
2649 Next => Nil_String);
2651 -- Case of first source directory
2653 if Last_Source_Dir = Nil_String then
2654 Data.Source_Dirs := String_Elements.Last;
2656 -- Here we already have source directories.
2659 -- Link the previous last to the new one
2661 String_Elements.Table (Last_Source_Dir).Next :=
2662 String_Elements.Last;
2665 -- And register this source directory as the new last
2667 Last_Source_Dir := String_Elements.Last;
2668 String_Elements.Table (Last_Source_Dir) := Element;
2671 -- Now look for subdirectories. We do that even when this
2672 -- directory is already in the list, because some of its
2673 -- subdirectories may not be in the list yet.
2675 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2678 Read (Dir, Name, Last);
2681 if Name (1 .. Last) /= "."
2682 and then Name (1 .. Last) /= ".."
2686 if Current_Verbosity = High then
2687 Write_Str (" Checking ");
2688 Write_Line (Name (1 .. Last));
2692 Path_Name : constant String :=
2694 (Name => Name (1 .. Last),
2697 (The_Path'First .. The_Path_Last));
2700 if Is_Directory (Path_Name) then
2702 -- We have found a new subdirectory, call self
2704 Name_Len := Path_Name'Length;
2705 Name_Buffer (1 .. Name_Len) := Path_Name;
2706 Recursive_Find_Dirs (Name_Find);
2715 when Directory_Error =>
2717 end Recursive_Find_Dirs;
2719 -- Start of processing for Find_Source_Dirs
2722 if Current_Verbosity = High then
2723 Write_Str ("Find_Source_Dirs (""");
2726 Get_Name_String (From);
2727 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2729 -- Directory := Name_Buffer (1 .. Name_Len);
2730 -- Why is above line commented out ???
2732 if Current_Verbosity = High then
2733 Write_Str (Directory);
2737 -- First, check if we are looking for a directory tree,
2738 -- indicated by "/**" at the end.
2740 if Directory'Length >= 3
2741 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2742 and then (Directory (Directory'Last - 2) = '/'
2744 Directory (Directory'Last - 2) = Directory_Separator)
2746 Data.Known_Order_Of_Source_Dirs := False;
2748 Name_Len := Directory'Length - 3;
2750 if Name_Len = 0 then
2752 -- This is the case of "/**": all directories
2753 -- in the file system.
2756 Name_Buffer (1) := Directory (Directory'First);
2759 Name_Buffer (1 .. Name_Len) :=
2760 Directory (Directory'First .. Directory'Last - 3);
2763 if Current_Verbosity = High then
2764 Write_Str ("Looking for all subdirectories of """);
2765 Write_Str (Name_Buffer (1 .. Name_Len));
2770 Base_Dir : constant Name_Id := Name_Find;
2771 Root_Dir : constant String :=
2773 (Name => Get_Name_String (Base_Dir),
2775 Get_Name_String (Data.Display_Directory));
2778 if Root_Dir'Length = 0 then
2779 Err_Vars.Error_Msg_Name_1 := Base_Dir;
2781 if Location = No_Location then
2784 "{ is not a valid directory.",
2789 "{ is not a valid directory.",
2794 -- We have an existing directory,
2795 -- we register it and all of its subdirectories.
2797 if Current_Verbosity = High then
2798 Write_Line ("Looking for source directories:");
2801 Name_Len := Root_Dir'Length;
2802 Name_Buffer (1 .. Name_Len) := Root_Dir;
2803 Recursive_Find_Dirs (Name_Find);
2805 if Current_Verbosity = High then
2806 Write_Line ("End of looking for source directories.");
2811 -- We have a single directory
2815 Path_Name : Name_Id;
2816 Display_Path_Name : Name_Id;
2819 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
2820 if Path_Name = No_Name then
2821 Err_Vars.Error_Msg_Name_1 := From;
2823 if Location = No_Location then
2826 "{ is not a valid directory",
2831 "{ is not a valid directory",
2836 -- As it is an existing directory, we add it to
2837 -- the list of directories.
2839 String_Elements.Increment_Last;
2840 Element.Value := Path_Name;
2841 Element.Display_Value := Display_Path_Name;
2843 if Last_Source_Dir = Nil_String then
2845 -- This is the first source directory
2847 Data.Source_Dirs := String_Elements.Last;
2850 -- We already have source directories,
2851 -- link the previous last to the new one.
2853 String_Elements.Table (Last_Source_Dir).Next :=
2854 String_Elements.Last;
2857 -- And register this source directory as the new last
2859 Last_Source_Dir := String_Elements.Last;
2860 String_Elements.Table (Last_Source_Dir) := Element;
2864 end Find_Source_Dirs;
2866 -- Start of processing for Language_Independent_Check
2869 if Data.Language_Independent_Checked then
2873 Data.Language_Independent_Checked := True;
2875 Error_Report := Report_Error;
2877 Recursive_Dirs.Reset;
2879 if Current_Verbosity = High then
2880 Write_Line ("Starting to look for directories");
2883 -- Check the object directory
2886 Object_Dir : constant Variable_Value :=
2887 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
2890 pragma Assert (Object_Dir.Kind = Single,
2891 "Object_Dir is not a single string");
2893 -- We set the object directory to its default
2895 Data.Object_Directory := Data.Directory;
2896 Data.Display_Object_Dir := Data.Display_Directory;
2898 if Object_Dir.Value /= Empty_String then
2900 Get_Name_String (Object_Dir.Value);
2902 if Name_Len = 0 then
2905 "Object_Dir cannot be empty",
2906 Object_Dir.Location);
2909 -- We check that the specified object directory
2913 (Object_Dir.Value, Data.Display_Directory,
2914 Data.Object_Directory, Data.Display_Object_Dir);
2916 if Data.Object_Directory = No_Name then
2917 -- The object directory does not exist, report an error
2918 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
2921 "the object directory { cannot be found",
2924 -- Do not keep a nil Object_Directory. Set it to the
2925 -- specified (relative or absolute) path.
2926 -- This is for the benefit of tools that recover from
2927 -- errors; for example, these tools could create the
2928 -- non existent directory.
2930 Data.Display_Object_Dir := Object_Dir.Value;
2931 Get_Name_String (Object_Dir.Value);
2932 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2933 Data.Object_Directory := Name_Find;
2939 if Current_Verbosity = High then
2940 if Data.Object_Directory = No_Name then
2941 Write_Line ("No object directory");
2943 Write_Str ("Object directory: """);
2944 Write_Str (Get_Name_String (Data.Display_Object_Dir));
2949 -- Check the exec directory
2952 Exec_Dir : constant Variable_Value :=
2953 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
2956 pragma Assert (Exec_Dir.Kind = Single,
2957 "Exec_Dir is not a single string");
2959 -- We set the object directory to its default
2961 Data.Exec_Directory := Data.Object_Directory;
2962 Data.Display_Exec_Dir := Data.Display_Object_Dir;
2964 if Exec_Dir.Value /= Empty_String then
2966 Get_Name_String (Exec_Dir.Value);
2968 if Name_Len = 0 then
2971 "Exec_Dir cannot be empty",
2975 -- We check that the specified object directory
2979 (Exec_Dir.Value, Data.Directory,
2980 Data.Exec_Directory, Data.Display_Exec_Dir);
2982 if Data.Exec_Directory = No_Name then
2983 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
2986 "the exec directory { cannot be found",
2993 if Current_Verbosity = High then
2994 if Data.Exec_Directory = No_Name then
2995 Write_Line ("No exec directory");
2997 Write_Str ("Exec directory: """);
2998 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3003 -- Look for the source directories
3006 Source_Dirs : constant Variable_Value :=
3008 (Name_Source_Dirs, Data.Decl.Attributes);
3011 if Current_Verbosity = High then
3012 Write_Line ("Starting to look for source directories");
3015 pragma Assert (Source_Dirs.Kind = List,
3016 "Source_Dirs is not a list");
3018 if Source_Dirs.Default then
3020 -- No Source_Dirs specified: the single source directory
3021 -- is the one containing the project file
3023 String_Elements.Increment_Last;
3024 Data.Source_Dirs := String_Elements.Last;
3025 String_Elements.Table (Data.Source_Dirs) :=
3026 (Value => Data.Directory,
3027 Display_Value => Data.Display_Directory,
3028 Location => No_Location,
3030 Next => Nil_String);
3032 if Current_Verbosity = High then
3033 Write_Line ("Single source directory:");
3035 Write_Str (Get_Name_String (Data.Display_Directory));
3039 elsif Source_Dirs.Values = Nil_String then
3041 -- If Source_Dirs is an empty string list, this means
3042 -- that this project contains no source. For projects that
3043 -- don't extend other projects, this also means that there is no
3044 -- need for an object directory, if not specified.
3046 if Data.Extends = No_Project
3047 and then Data.Object_Directory = Data.Directory
3049 Data.Object_Directory := No_Name;
3052 Data.Source_Dirs := Nil_String;
3053 Data.Sources_Present := False;
3057 Source_Dir : String_List_Id := Source_Dirs.Values;
3058 Element : String_Element;
3061 -- We will find the source directories for each
3062 -- element of the list
3064 while Source_Dir /= Nil_String loop
3065 Element := String_Elements.Table (Source_Dir);
3066 Find_Source_Dirs (Element.Value, Element.Location);
3067 Source_Dir := Element.Next;
3072 if Current_Verbosity = High then
3073 Write_Line ("Putting source directories in canonical cases");
3077 Current : String_List_Id := Data.Source_Dirs;
3078 Element : String_Element;
3081 while Current /= Nil_String loop
3082 Element := String_Elements.Table (Current);
3083 if Element.Value /= No_Name then
3084 Get_Name_String (Element.Value);
3085 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3086 Element.Value := Name_Find;
3087 String_Elements.Table (Current) := Element;
3090 Current := Element.Next;
3095 -- Library attributes
3098 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3100 Lib_Dir : constant Prj.Variable_Value :=
3101 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3103 Lib_Name : constant Prj.Variable_Value :=
3104 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3106 Lib_Version : constant Prj.Variable_Value :=
3108 (Snames.Name_Library_Version, Attributes);
3110 The_Lib_Kind : constant Prj.Variable_Value :=
3112 (Snames.Name_Library_Kind, Attributes);
3115 -- Special case of extending project
3117 if Data.Extends /= No_Project then
3119 Extended_Data : constant Project_Data :=
3120 Projects.Table (Data.Extends);
3123 -- If the project extended is a library project, we inherit
3124 -- the library name, if it is not redefined; we check that
3125 -- the library directory is specified; and we reset the
3126 -- library flag for the extended project.
3128 if Extended_Data.Library then
3129 if Lib_Name.Default then
3130 Data.Library_Name := Extended_Data.Library_Name;
3133 if Lib_Dir.Default then
3135 -- If the extending project is a virtual project, we
3136 -- put the error message in the library project that
3137 -- is extended, rather than in the extending all project.
3138 -- Of course, we cannot put it in the virtual extending
3139 -- project, because it has no source.
3141 if Data.Virtual then
3142 Error_Msg_Name_1 := Extended_Data.Name;
3146 "library project % cannot be virtually extended",
3147 Extended_Data.Location);
3152 "a project extending a library project must " &
3153 "specify an attribute Library_Dir",
3158 Projects.Table (Data.Extends).Library := False;
3163 pragma Assert (Lib_Dir.Kind = Single);
3165 if Lib_Dir.Value = Empty_String then
3167 if Current_Verbosity = High then
3168 Write_Line ("No library directory");
3172 -- Find path name, check that it is a directory
3175 (Lib_Dir.Value, Data.Display_Directory,
3176 Data.Library_Dir, Data.Display_Library_Dir);
3178 if Data.Library_Dir = No_Name then
3180 -- Get the absolute name of the library directory that
3181 -- does not exist, to report an error.
3184 Dir_Name : constant String :=
3185 Get_Name_String (Lib_Dir.Value);
3187 if Is_Absolute_Path (Dir_Name) then
3188 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3191 Get_Name_String (Data.Display_Directory);
3193 if Name_Buffer (Name_Len) /= Directory_Separator then
3194 Name_Len := Name_Len + 1;
3195 Name_Buffer (Name_Len) := Directory_Separator;
3199 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3201 Name_Len := Name_Len + Dir_Name'Length;
3202 Err_Vars.Error_Msg_Name_1 := Name_Find;
3209 "library directory { does not exist",
3213 elsif Data.Library_Dir = Data.Object_Directory then
3216 "library directory cannot be the same " &
3217 "as object directory",
3219 Data.Library_Dir := No_Name;
3220 Data.Display_Library_Dir := No_Name;
3223 if Current_Verbosity = High then
3224 Write_Str ("Library directory =""");
3225 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3231 pragma Assert (Lib_Name.Kind = Single);
3233 if Lib_Name.Value = Empty_String then
3234 if Current_Verbosity = High
3235 and then Data.Library_Name = No_Name
3237 Write_Line ("No library name");
3241 -- There is no restriction on the syntax of library names
3243 Data.Library_Name := Lib_Name.Value;
3246 if Data.Library_Name /= No_Name
3247 and then Current_Verbosity = High
3249 Write_Str ("Library name = """);
3250 Write_Str (Get_Name_String (Data.Library_Name));
3255 Data.Library_Dir /= No_Name
3257 Data.Library_Name /= No_Name;
3259 if Data.Library then
3260 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3263 "?libraries are not supported on this platform",
3265 Data.Library := False;
3268 pragma Assert (Lib_Version.Kind = Single);
3270 if Lib_Version.Value = Empty_String then
3271 if Current_Verbosity = High then
3272 Write_Line ("No library version specified");
3276 Data.Lib_Internal_Name := Lib_Version.Value;
3279 pragma Assert (The_Lib_Kind.Kind = Single);
3281 if The_Lib_Kind.Value = Empty_String then
3282 if Current_Verbosity = High then
3283 Write_Line ("No library kind specified");
3287 Get_Name_String (The_Lib_Kind.Value);
3290 Kind_Name : constant String :=
3291 To_Lower (Name_Buffer (1 .. Name_Len));
3293 OK : Boolean := True;
3296 if Kind_Name = "static" then
3297 Data.Library_Kind := Static;
3299 elsif Kind_Name = "dynamic" then
3300 Data.Library_Kind := Dynamic;
3302 elsif Kind_Name = "relocatable" then
3303 Data.Library_Kind := Relocatable;
3308 "illegal value for Library_Kind",
3309 The_Lib_Kind.Location);
3313 if Current_Verbosity = High and then OK then
3314 Write_Str ("Library kind = ");
3315 Write_Line (Kind_Name);
3318 if Data.Library_Kind /= Static and then
3319 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3323 "only static libraries are supported " &
3325 The_Lib_Kind.Location);
3326 Data.Library := False;
3331 if Data.Library and then Current_Verbosity = High then
3332 Write_Line ("This is a library project file");
3339 if Current_Verbosity = High then
3340 Show_Source_Dirs (Project);
3344 Naming_Id : constant Package_Id :=
3345 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3347 Naming : Package_Element;
3350 -- If there is a package Naming, we will put in Data.Naming
3351 -- what is in this package Naming.
3353 if Naming_Id /= No_Package then
3354 Naming := Packages.Table (Naming_Id);
3356 if Current_Verbosity = High then
3357 Write_Line ("Checking ""Naming"".");
3360 -- Check Spec_Suffix
3363 Spec_Suffixs : Array_Element_Id :=
3366 Naming.Decl.Arrays);
3367 Suffix : Array_Element_Id;
3368 Element : Array_Element;
3369 Suffix2 : Array_Element_Id;
3372 -- If some suffixs have been specified, we make sure that
3373 -- for each language for which a default suffix has been
3374 -- specified, there is a suffix specified, either the one
3375 -- in the project file or if there were none, the default.
3377 if Spec_Suffixs /= No_Array_Element then
3378 Suffix := Data.Naming.Spec_Suffix;
3380 while Suffix /= No_Array_Element loop
3381 Element := Array_Elements.Table (Suffix);
3382 Suffix2 := Spec_Suffixs;
3384 while Suffix2 /= No_Array_Element loop
3385 exit when Array_Elements.Table (Suffix2).Index =
3387 Suffix2 := Array_Elements.Table (Suffix2).Next;
3390 -- There is a registered default suffix, but no
3391 -- suffix specified in the project file.
3392 -- Add the default to the array.
3394 if Suffix2 = No_Array_Element then
3395 Array_Elements.Increment_Last;
3396 Array_Elements.Table (Array_Elements.Last) :=
3397 (Index => Element.Index,
3398 Index_Case_Sensitive => False,
3399 Value => Element.Value,
3400 Next => Spec_Suffixs);
3401 Spec_Suffixs := Array_Elements.Last;
3404 Suffix := Element.Next;
3407 -- Put the resulting array as the specification suffixs
3409 Data.Naming.Spec_Suffix := Spec_Suffixs;
3414 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3415 Element : Array_Element;
3418 while Current /= No_Array_Element loop
3419 Element := Array_Elements.Table (Current);
3420 Get_Name_String (Element.Value.Value);
3422 if Name_Len = 0 then
3425 "Spec_Suffix cannot be empty",
3426 Element.Value.Location);
3429 Array_Elements.Table (Current) := Element;
3430 Current := Element.Next;
3434 -- Check Body_Suffix
3437 Impl_Suffixs : Array_Element_Id :=
3440 Naming.Decl.Arrays);
3442 Suffix : Array_Element_Id;
3443 Element : Array_Element;
3444 Suffix2 : Array_Element_Id;
3447 -- If some suffixs have been specified, we make sure that
3448 -- for each language for which a default suffix has been
3449 -- specified, there is a suffix specified, either the one
3450 -- in the project file or if there were noe, the default.
3452 if Impl_Suffixs /= No_Array_Element then
3453 Suffix := Data.Naming.Body_Suffix;
3455 while Suffix /= No_Array_Element loop
3456 Element := Array_Elements.Table (Suffix);
3457 Suffix2 := Impl_Suffixs;
3459 while Suffix2 /= No_Array_Element loop
3460 exit when Array_Elements.Table (Suffix2).Index =
3462 Suffix2 := Array_Elements.Table (Suffix2).Next;
3465 -- There is a registered default suffix, but no
3466 -- suffix specified in the project file.
3467 -- Add the default to the array.
3469 if Suffix2 = No_Array_Element then
3470 Array_Elements.Increment_Last;
3471 Array_Elements.Table (Array_Elements.Last) :=
3472 (Index => Element.Index,
3473 Index_Case_Sensitive => False,
3474 Value => Element.Value,
3475 Next => Impl_Suffixs);
3476 Impl_Suffixs := Array_Elements.Last;
3479 Suffix := Element.Next;
3482 -- Put the resulting array as the implementation suffixs
3484 Data.Naming.Body_Suffix := Impl_Suffixs;
3489 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3490 Element : Array_Element;
3493 while Current /= No_Array_Element loop
3494 Element := Array_Elements.Table (Current);
3495 Get_Name_String (Element.Value.Value);
3497 if Name_Len = 0 then
3500 "Body_Suffix cannot be empty",
3501 Element.Value.Location);
3504 Array_Elements.Table (Current) := Element;
3505 Current := Element.Next;
3509 -- Get the exceptions, if any
3511 Data.Naming.Specification_Exceptions :=
3513 (Name_Specification_Exceptions,
3514 In_Arrays => Naming.Decl.Arrays);
3516 Data.Naming.Implementation_Exceptions :=
3518 (Name_Implementation_Exceptions,
3519 In_Arrays => Naming.Decl.Arrays);
3523 Projects.Table (Project) := Data;
3524 end Language_Independent_Check;
3526 ----------------------
3527 -- Locate_Directory --
3528 ----------------------
3530 procedure Locate_Directory
3534 Display : out Name_Id)
3536 The_Name : constant String := Get_Name_String (Name);
3537 The_Parent : constant String :=
3538 Get_Name_String (Parent) & Directory_Separator;
3539 The_Parent_Last : constant Natural :=
3540 Compute_Directory_Last (The_Parent);
3543 if Current_Verbosity = High then
3544 Write_Str ("Locate_Directory (""");
3545 Write_Str (The_Name);
3546 Write_Str (""", """);
3547 Write_Str (The_Parent);
3554 if Is_Absolute_Path (The_Name) then
3555 if Is_Directory (The_Name) then
3557 Normed : constant String :=
3558 Normalize_Pathname (The_Name);
3561 Name_Len := Normed'Length;
3562 Name_Buffer (1 .. Name_Len) := Normed;
3563 Display := Name_Find;
3564 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3571 Full_Path : constant String :=
3572 The_Parent (The_Parent'First .. The_Parent_Last) &
3576 if Is_Directory (Full_Path) then
3578 Normed : constant String :=
3579 Normalize_Pathname (Full_Path);
3582 Name_Len := Normed'Length;
3583 Name_Buffer (1 .. Name_Len) := Normed;
3584 Display := Name_Find;
3585 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3591 end Locate_Directory;
3597 function Path_Name_Of
3598 (File_Name : Name_Id;
3599 Directory : Name_Id) return String
3601 Result : String_Access;
3602 The_Directory : constant String := Get_Name_String (Directory);
3605 Get_Name_String (File_Name);
3606 Result := Locate_Regular_File
3607 (File_Name => Name_Buffer (1 .. Name_Len),
3608 Path => The_Directory);
3610 if Result = null then
3613 Canonical_Case_File_Name (Result.all);
3618 ---------------------
3619 -- Project_Extends --
3620 ---------------------
3622 function Project_Extends
3623 (Extending : Project_Id;
3624 Extended : Project_Id) return Boolean
3626 Current : Project_Id := Extending;
3629 if Current = No_Project then
3632 elsif Current = Extended then
3636 Current := Projects.Table (Current).Extends;
3638 end Project_Extends;
3644 procedure Record_Source
3645 (File_Name : Name_Id;
3646 Path_Name : Name_Id;
3647 Project : Project_Id;
3648 Data : in out Project_Data;
3649 Location : Source_Ptr;
3650 Current_Source : in out String_List_Id;
3651 Source_Recorded : in out Boolean)
3653 Canonical_File_Name : Name_Id;
3654 Canonical_Path_Name : Name_Id;
3655 Unit_Name : Name_Id;
3656 Unit_Kind : Spec_Or_Body;
3657 Needs_Pragma : Boolean;
3659 The_Location : Source_Ptr := Location;
3660 Previous_Source : constant String_List_Id := Current_Source;
3661 Except_Name : Name_Id := No_Name;
3663 Unit_Prj : Unit_Project;
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 -- First, check if there is no other unit with this file name
3818 -- in another project. If it is, report an error.
3820 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
3822 if Unit_Prj /= No_Unit_Project then
3823 Error_Msg_Name_1 := File_Name;
3824 Error_Msg_Name_2 := Projects.Table (Unit_Prj.Project).Name;
3827 "{ is already a source of project {",
3831 Units.Increment_Last;
3832 The_Unit := Units.Last;
3833 Units_Htable.Set (Unit_Name, The_Unit);
3834 Unit_Prj := (Unit => The_Unit, Project => Project);
3835 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
3836 The_Unit_Data.Name := Unit_Name;
3837 The_Unit_Data.File_Names (Unit_Kind) :=
3838 (Name => Canonical_File_Name,
3839 Display_Name => File_Name,
3840 Path => Canonical_Path_Name,
3841 Display_Path => Path_Name,
3843 Needs_Pragma => Needs_Pragma);
3844 Units.Table (The_Unit) := The_Unit_Data;
3845 Source_Recorded := True;
3852 ----------------------
3853 -- Show_Source_Dirs --
3854 ----------------------
3856 procedure Show_Source_Dirs (Project : Project_Id) is
3857 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
3858 Element : String_Element;
3861 Write_Line ("Source_Dirs:");
3863 while Current /= Nil_String loop
3864 Element := String_Elements.Table (Current);
3866 Write_Line (Get_Name_String (Element.Value));
3867 Current := Element.Next;
3870 Write_Line ("end Source_Dirs.");
3871 end Show_Source_Dirs;