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;
56 -- Set to point to error reporting procedure
58 ALI_Suffix : constant String := ".ali";
59 -- File suffix for ali files
61 Object_Suffix : constant String := Get_Object_Suffix.all;
62 -- File suffix for object files
64 type Name_Location is record
66 Location : Source_Ptr;
67 Found : Boolean := False;
69 -- Information about file names found in string list attribute
70 -- Source_Files or in a source list file, stored in hash table
71 -- Source_Names, used by procedure
72 -- Ada_Check.Get_Path_Names_And_Record_Sources.
74 No_Name_Location : constant Name_Location :=
75 (Name => No_Name, Location => No_Location, Found => False);
77 package Source_Names is new GNAT.HTable.Simple_HTable
78 (Header_Num => Header_Num,
79 Element => Name_Location,
80 No_Element => No_Name_Location,
84 -- Hash table to store file names found in string list attribute
85 -- Source_Files or in a source list file, stored in hash table
86 -- Source_Names, used by procedure
87 -- Ada_Check.Get_Path_Names_And_Record_Sources.
89 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
90 (Header_Num => Header_Num,
96 -- Hash table to store recursive source directories, to avoid looking
97 -- several times, and to avoid cycles that may be introduced by symbolic
100 type Unit_Info is record
104 No_Unit : constant Unit_Info := (Specification, No_Name);
106 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
107 (Header_Num => Header_Num,
108 Element => Unit_Info,
109 No_Element => No_Unit,
113 -- A hash table to store naming exceptions for Ada
115 function Hash (Unit : Unit_Info) return Header_Num;
117 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
118 (Header_Num => Header_Num,
120 No_Element => No_Name,
124 -- A table to check if a unit with an exceptional name will hide
125 -- a source with a file name following the naming convention.
127 function ALI_File_Name (Source : String) return String;
128 -- Return the ALI file name corresponding to a source.
130 procedure Check_Ada_Naming_Scheme
131 (Project : Project_Id;
132 Naming : Naming_Data);
133 -- Check that the package Naming is correct.
135 procedure Check_Ada_Name
138 -- Check that a name is a valid Ada unit name.
140 procedure Check_For_Source
141 (File_Name : Name_Id;
143 Project : Project_Id;
144 Data : in out Project_Data;
145 Location : Source_Ptr;
146 Language : Other_Programming_Language;
148 Naming_Exception : Boolean);
149 -- Check if a file in a source directory is a source for a specific
150 -- language other than Ada.
152 procedure Check_Naming_Scheme
153 (Data : in out Project_Data;
154 Project : Project_Id);
155 -- Check the naming scheme part of Data
157 function Check_Project
159 Root_Project : Project_Id;
160 Extending : Boolean) return Boolean;
161 -- Returns True if P is Root_Project or, if Extending is True, a project
162 -- extended by Root_Project.
164 function Compute_Directory_Last (Dir : String) return Natural;
165 -- Return the index of the last significant character in Dir. This is used
166 -- to avoid duplicates '/' at the end of directory names
169 (Project : Project_Id;
171 Flag_Location : Source_Ptr);
172 -- Output an error message. If Error_Report is null, simply call
173 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
176 procedure Find_Sources
177 (Project : Project_Id;
178 Data : in out Project_Data;
179 For_Language : Programming_Language;
180 Follow_Links : Boolean := False);
181 -- Find all the sources in all of the source directories of a project for
182 -- a specified language.
184 procedure Free_Ada_Naming_Exceptions;
185 -- Free the internal hash tables used for checking naming exceptions
187 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
188 -- Get the mains of a project from attribute Main, if it exists, and put
189 -- them in the project data.
191 procedure Get_Sources_From_File
193 Location : Source_Ptr;
194 Project : Project_Id);
195 -- Get the list of sources from a text file and put them in hash table
199 (Canonical_File_Name : Name_Id;
200 Naming : Naming_Data;
201 Unit_Name : out Name_Id;
202 Unit_Kind : out Spec_Or_Body;
203 Needs_Pragma : out Boolean);
204 -- Find out, from a file name, the unit name, the unit kind and if a
205 -- specific SFN pragma is needed. If the file name corresponds to no
206 -- unit, then Unit_Name will be No_Name.
208 function Is_Illegal_Suffix
210 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
211 -- Returns True if the string Suffix cannot be used as
212 -- a spec suffix, a body suffix or a separate suffix.
214 procedure Locate_Directory
218 Display : out Name_Id);
219 -- Locate a directory.
220 -- Returns No_Name if directory does not exist.
222 function Path_Name_Of
223 (File_Name : Name_Id;
224 Directory : Name_Id) return String;
225 -- Returns the path name of a (non project) file.
226 -- Returns an empty string if file cannot be found.
228 procedure Prepare_Ada_Naming_Exceptions
229 (List : Array_Element_Id;
230 Kind : Spec_Or_Body);
231 -- Prepare the internal hash tables used for checking naming exceptions
232 -- for Ada. Insert all elements of List in the tables.
234 function Project_Extends
235 (Extending : Project_Id;
236 Extended : Project_Id) return Boolean;
237 -- Returns True if Extending is extending directly or indirectly Extended.
239 procedure Record_Ada_Source
240 (File_Name : Name_Id;
242 Project : Project_Id;
243 Data : in out Project_Data;
244 Location : Source_Ptr;
245 Current_Source : in out String_List_Id;
246 Source_Recorded : in out Boolean;
247 Follow_Links : Boolean);
248 -- Put a unit in the list of units of a project, if the file name
249 -- corresponds to a valid unit name.
251 procedure Record_Other_Sources
252 (Project : Project_Id;
253 Data : in out Project_Data;
254 Language : Programming_Language;
255 Naming_Exceptions : Boolean);
256 -- Record the sources of a language in a project.
257 -- When Naming_Exceptions is True, mark the found sources as such, to
258 -- later remove those that are not named in a list of sources.
260 procedure Show_Source_Dirs (Project : Project_Id);
261 -- List all the source directories of a project.
264 (Language : Programming_Language;
265 Naming : Naming_Data) return Name_Id;
266 -- Get the suffix for the source of a language from a package naming.
267 -- If not specified, return the default for the language.
274 (Project : Project_Id;
275 Report_Error : Put_Line_Access;
276 Follow_Links : Boolean)
279 Languages : Variable_Value := Nil_Variable_Value;
281 Extending : Boolean := False;
283 procedure Get_Path_Names_And_Record_Sources;
284 -- Find the path names of the source files in the Source_Names table
285 -- in the source directories and record those that are Ada sources.
287 procedure Get_Sources_From_File
289 Location : Source_Ptr);
290 -- Get the sources of a project from a text file
292 procedure Warn_If_Not_Sources
293 (Conventions : Array_Element_Id;
295 -- Check that individual naming conventions apply to immediate
296 -- sources of the project; if not, issue a warning.
298 ---------------------------------------
299 -- Get_Path_Names_And_Record_Sources --
300 ---------------------------------------
302 procedure Get_Path_Names_And_Record_Sources is
303 Source_Dir : String_List_Id := Data.Source_Dirs;
304 Element : String_Element;
309 Canonical_Name : Name_Id;
310 Name_Str : String (1 .. 1_024);
314 Current_Source : String_List_Id := Nil_String;
316 First_Error : Boolean := True;
318 Source_Recorded : Boolean := False;
321 -- We look in all source directories for the file names in the
322 -- hash table Source_Names
324 while Source_Dir /= Nil_String loop
325 Source_Recorded := False;
326 Element := String_Elements.Table (Source_Dir);
329 Dir_Path : constant String := Get_Name_String (Element.Value);
331 if Current_Verbosity = High then
332 Write_Str ("checking directory """);
333 Write_Str (Dir_Path);
337 Open (Dir, Dir_Path);
340 Read (Dir, Name_Str, Last);
343 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
345 Canonical_Case_File_Name (Name_Str (1 .. Last));
347 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
348 Canonical_Name := Name_Find;
349 NL := Source_Names.Get (Canonical_Name);
351 if NL /= No_Name_Location and then not NL.Found then
353 Source_Names.Set (Canonical_Name, NL);
354 Name_Len := Dir_Path'Length;
355 Name_Buffer (1 .. Name_Len) := Dir_Path;
356 Add_Char_To_Name_Buffer (Directory_Separator);
357 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
360 if Current_Verbosity = High then
361 Write_Str (" found ");
362 Write_Line (Get_Name_String (Name));
365 -- Register the source if it is an Ada compilation unit..
372 Location => NL.Location,
373 Current_Source => Current_Source,
374 Source_Recorded => Source_Recorded,
375 Follow_Links => Follow_Links);
382 if Source_Recorded then
383 String_Elements.Table (Source_Dir).Flag := True;
386 Source_Dir := Element.Next;
389 -- It is an error if a source file name in a source list or
390 -- in a source list file is not found.
392 NL := Source_Names.Get_First;
394 while NL /= No_Name_Location loop
396 Err_Vars.Error_Msg_Name_1 := NL.Name;
401 "source file { cannot be found",
403 First_Error := False;
408 "\source file { cannot be found",
413 NL := Source_Names.Get_Next;
415 end Get_Path_Names_And_Record_Sources;
417 ---------------------------
418 -- Get_Sources_From_File --
419 ---------------------------
421 procedure Get_Sources_From_File
423 Location : Source_Ptr)
426 -- Get the list of sources from the file and put them in hash table
429 Get_Sources_From_File (Path, Location, Project);
431 -- Look in the source directories to find those sources
433 Get_Path_Names_And_Record_Sources;
435 -- We should have found at least one source.
436 -- If not, report an error.
438 if Data.Sources = Nil_String then
440 "there are no Ada sources in this project",
443 end Get_Sources_From_File;
445 -------------------------
446 -- Warn_If_Not_Sources --
447 -------------------------
449 procedure Warn_If_Not_Sources
450 (Conventions : Array_Element_Id;
453 Conv : Array_Element_Id := Conventions;
455 The_Unit_Id : Unit_Id;
456 The_Unit_Data : Unit_Data;
457 Location : Source_Ptr;
460 while Conv /= No_Array_Element loop
461 Unit := Array_Elements.Table (Conv).Index;
462 Error_Msg_Name_1 := Unit;
463 Get_Name_String (Unit);
464 To_Lower (Name_Buffer (1 .. Name_Len));
466 The_Unit_Id := Units_Htable.Get (Unit);
467 Location := Array_Elements.Table (Conv).Value.Location;
469 if The_Unit_Id = Prj.Com.No_Unit then
476 The_Unit_Data := Units.Table (The_Unit_Id);
480 (The_Unit_Data.File_Names (Specification).Project,
485 "?unit{ has no spec in this project",
491 (The_Unit_Data.File_Names (Com.Body_Part).Project,
496 "?unit{ has no body in this project",
502 Conv := Array_Elements.Table (Conv).Next;
504 end Warn_If_Not_Sources;
506 -- Start of processing for Ada_Check
509 Language_Independent_Check (Project, Report_Error);
511 Error_Report := Report_Error;
513 Data := Projects.Table (Project);
514 Extending := Data.Extends /= No_Project;
515 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
517 Data.Naming.Current_Language := Name_Ada;
518 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
520 if not Languages.Default then
522 Current : String_List_Id := Languages.Values;
523 Element : String_Element;
524 Ada_Found : Boolean := False;
527 Look_For_Ada : while Current /= Nil_String loop
528 Element := String_Elements.Table (Current);
529 Get_Name_String (Element.Value);
530 To_Lower (Name_Buffer (1 .. Name_Len));
532 if Name_Buffer (1 .. Name_Len) = "ada" then
537 Current := Element.Next;
538 end loop Look_For_Ada;
540 if not Ada_Found then
542 -- Mark the project file as having no sources for Ada
544 Data.Sources_Present := False;
549 Check_Naming_Scheme (Data, Project);
551 Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
552 Prepare_Ada_Naming_Exceptions (Data.Naming.Specs, Specification);
554 -- If we have source directories, then find the sources
556 if Data.Sources_Present then
557 if Data.Source_Dirs = Nil_String then
558 Data.Sources_Present := False;
562 Sources : constant Variable_Value :=
565 Data.Decl.Attributes);
567 Source_List_File : constant Variable_Value :=
569 (Name_Source_List_File,
570 Data.Decl.Attributes);
572 Locally_Removed : constant Variable_Value :=
574 (Name_Locally_Removed_Files,
575 Data.Decl.Attributes);
580 (Sources.Kind = List,
581 "Source_Files is not a list");
584 (Source_List_File.Kind = Single,
585 "Source_List_File is not a single string");
587 if not Sources.Default then
588 if not Source_List_File.Default then
591 "?both variables source_files and " &
592 "source_list_file are present",
593 Source_List_File.Location);
596 -- Sources is a list of file names
599 Current : String_List_Id := Sources.Values;
600 Element : String_Element;
601 Location : Source_Ptr;
607 Data.Sources_Present := Current /= Nil_String;
609 while Current /= Nil_String loop
610 Element := String_Elements.Table (Current);
611 Get_Name_String (Element.Value);
612 Canonical_Case_File_Name
613 (Name_Buffer (1 .. Name_Len));
616 -- If the element has no location, then use the
617 -- location of Sources to report possible errors.
619 if Element.Location = No_Location then
620 Location := Sources.Location;
623 Location := Element.Location;
630 Location => Location,
633 Current := Element.Next;
636 Get_Path_Names_And_Record_Sources;
639 -- No source_files specified
641 -- We check Source_List_File has been specified.
643 elsif not Source_List_File.Default then
645 -- Source_List_File is the name of the file
646 -- that contains the source file names
649 Source_File_Path_Name : constant String :=
651 (Source_List_File.Value,
655 if Source_File_Path_Name'Length = 0 then
656 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
659 "file with sources { does not exist",
660 Source_List_File.Location);
663 Get_Sources_From_File
664 (Source_File_Path_Name,
665 Source_List_File.Location);
670 -- Neither Source_Files nor Source_List_File has been
671 -- specified. Find all the files that satisfy the naming
672 -- scheme in all the source directories.
674 Find_Sources (Project, Data, Lang_Ada, Follow_Links);
677 -- If there are sources that are locally removed, mark them as
678 -- such in the Units table.
680 if not Locally_Removed.Default then
682 -- Sources can be locally removed only in extending
685 if Data.Extends = No_Project then
688 "Locally_Removed_Files can only be used " &
689 "in an extending project file",
690 Locally_Removed.Location);
694 Current : String_List_Id :=
695 Locally_Removed.Values;
696 Element : String_Element;
697 Location : Source_Ptr;
701 Extended : Project_Id;
704 while Current /= Nil_String loop
705 Element := String_Elements.Table (Current);
706 Get_Name_String (Element.Value);
707 Canonical_Case_File_Name
708 (Name_Buffer (1 .. Name_Len));
711 -- If the element has no location, then use the
712 -- location of Locally_Removed to report
715 if Element.Location = No_Location then
716 Location := Locally_Removed.Location;
719 Location := Element.Location;
724 for Index in 1 .. Units.Last loop
725 Unit := Units.Table (Index);
728 Unit.File_Names (Specification).Name = Name
732 -- Check that this is from a project that
733 -- the current project extends, but not the
736 Extended := Unit.File_Names
737 (Specification).Project;
739 if Extended = Project then
742 "cannot remove a source " &
743 "of the same project",
747 Project_Extends (Project, Extended)
750 (Specification).Path := Slash;
752 (Specification).Needs_Pragma := False;
753 Units.Table (Index) := Unit;
754 Add_Forbidden_File_Name
755 (Unit.File_Names (Specification).Name);
761 "cannot remove a source from " &
767 Unit.File_Names (Body_Part).Name = Name
771 -- Check that this is from a project that
772 -- the current project extends, but not the
775 Extended := Unit.File_Names
778 if Extended = Project then
781 "cannot remove a source " &
782 "of the same project",
786 Project_Extends (Project, Extended)
788 Unit.File_Names (Body_Part).Path := Slash;
789 Unit.File_Names (Body_Part).Needs_Pragma
791 Units.Table (Index) := Unit;
792 Add_Forbidden_File_Name
793 (Unit.File_Names (Body_Part).Name);
801 Err_Vars.Error_Msg_Name_1 := Name;
802 Error_Msg (Project, "unknown file {", Location);
805 Current := Element.Next;
814 if Data.Sources_Present then
816 -- Check that all individual naming conventions apply to
817 -- sources of this project file.
819 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
820 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
823 -- If it is a library project file, check if it is a standalone library
826 Standalone_Library : declare
827 Lib_Interfaces : constant Prj.Variable_Value :=
829 (Snames.Name_Library_Interface,
830 Data.Decl.Attributes);
831 Lib_Auto_Init : constant Prj.Variable_Value :=
833 (Snames.Name_Library_Auto_Init,
834 Data.Decl.Attributes);
836 Lib_Src_Dir : constant Prj.Variable_Value :=
838 (Snames.Name_Library_Src_Dir,
839 Data.Decl.Attributes);
841 Lib_Symbol_File : constant Prj.Variable_Value :=
843 (Snames.Name_Library_Symbol_File,
844 Data.Decl.Attributes);
846 Lib_Symbol_Policy : constant Prj.Variable_Value :=
848 (Snames.Name_Library_Symbol_Policy,
849 Data.Decl.Attributes);
851 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
853 (Snames.Name_Library_Reference_Symbol_File,
854 Data.Decl.Attributes);
856 Auto_Init_Supported : constant Boolean :=
858 Standalone_Library_Auto_Init_Is_Supported;
860 OK : Boolean := True;
863 pragma Assert (Lib_Interfaces.Kind = List);
865 -- It is a stand-alone library project file if attribute
866 -- Library_Interface is defined.
868 if not Lib_Interfaces.Default then
870 Interfaces : String_List_Id := Lib_Interfaces.Values;
871 Interface_ALIs : String_List_Id := Nil_String;
873 The_Unit_Id : Unit_Id;
874 The_Unit_Data : Unit_Data;
876 procedure Add_ALI_For (Source : Name_Id);
877 -- Add an ALI file name to the list of Interface ALIs
883 procedure Add_ALI_For (Source : Name_Id) is
885 Get_Name_String (Source);
888 ALI : constant String :=
889 ALI_File_Name (Name_Buffer (1 .. Name_Len));
890 ALI_Name_Id : Name_Id;
892 Name_Len := ALI'Length;
893 Name_Buffer (1 .. Name_Len) := ALI;
894 ALI_Name_Id := Name_Find;
896 String_Elements.Increment_Last;
897 String_Elements.Table (String_Elements.Last) :=
898 (Value => ALI_Name_Id,
899 Display_Value => ALI_Name_Id,
900 Location => String_Elements.Table
901 (Interfaces).Location,
903 Next => Interface_ALIs);
904 Interface_ALIs := String_Elements.Last;
909 Data.Standalone_Library := True;
911 -- Library_Interface cannot be an empty list
913 if Interfaces = Nil_String then
916 "Library_Interface cannot be an empty list",
917 Lib_Interfaces.Location);
920 -- Process each unit name specified in the attribute
921 -- Library_Interface.
923 while Interfaces /= Nil_String loop
925 (String_Elements.Table (Interfaces).Value);
926 To_Lower (Name_Buffer (1 .. Name_Len));
931 "an interface cannot be an empty string",
932 String_Elements.Table (Interfaces).Location);
936 Error_Msg_Name_1 := Unit;
937 The_Unit_Id := Units_Htable.Get (Unit);
939 if The_Unit_Id = Prj.Com.No_Unit then
943 String_Elements.Table (Interfaces).Location);
946 -- Check that the unit is part of the project
948 The_Unit_Data := Units.Table (The_Unit_Id);
950 if The_Unit_Data.File_Names
951 (Com.Body_Part).Name /= No_Name
952 and then The_Unit_Data.File_Names
953 (Com.Body_Part).Path /= Slash
956 (The_Unit_Data.File_Names (Body_Part).Project,
959 -- There is a body for this unit.
960 -- If there is no spec, we need to check
961 -- that it is not a subunit.
963 if The_Unit_Data.File_Names
964 (Specification).Name = No_Name
967 Src_Ind : Source_File_Index;
970 Src_Ind := Sinput.P.Load_Project_File
972 (The_Unit_Data.File_Names
975 if Sinput.P.Source_File_Is_Subunit
981 "it cannot be an interface",
982 String_Elements.Table
983 (Interfaces).Location);
988 -- The unit is not a subunit, so we add
989 -- to the Interface ALIs the ALI file
990 -- corresponding to the body.
993 (The_Unit_Data.File_Names (Body_Part).Name);
998 "{ is not an unit of this project",
999 String_Elements.Table
1000 (Interfaces).Location);
1003 elsif The_Unit_Data.File_Names
1004 (Com.Specification).Name /= No_Name
1005 and then The_Unit_Data.File_Names
1006 (Com.Specification).Path /= Slash
1007 and then Check_Project
1008 (The_Unit_Data.File_Names
1009 (Specification).Project,
1013 -- The unit is part of the project, it has
1014 -- a spec, but no body. We add to the Interface
1015 -- ALIs the ALI file corresponding to the spec.
1018 (The_Unit_Data.File_Names (Specification).Name);
1023 "{ is not an unit of this project",
1024 String_Elements.Table (Interfaces).Location);
1030 Interfaces := String_Elements.Table (Interfaces).Next;
1033 -- Put the list of Interface ALIs in the project data
1035 Data.Lib_Interface_ALIs := Interface_ALIs;
1037 -- Check value of attribute Library_Auto_Init and set
1038 -- Lib_Auto_Init accordingly.
1040 if Lib_Auto_Init.Default then
1042 -- If no attribute Library_Auto_Init is declared, then
1043 -- set auto init only if it is supported.
1045 Data.Lib_Auto_Init := Auto_Init_Supported;
1048 Get_Name_String (Lib_Auto_Init.Value);
1049 To_Lower (Name_Buffer (1 .. Name_Len));
1051 if Name_Buffer (1 .. Name_Len) = "false" then
1052 Data.Lib_Auto_Init := False;
1054 elsif Name_Buffer (1 .. Name_Len) = "true" then
1055 if Auto_Init_Supported then
1056 Data.Lib_Auto_Init := True;
1059 -- Library_Auto_Init cannot be "true" if auto init
1064 "library auto init not supported " &
1066 Lib_Auto_Init.Location);
1072 "invalid value for attribute Library_Auto_Init",
1073 Lib_Auto_Init.Location);
1078 -- If attribute Library_Src_Dir is defined and not the
1079 -- empty string, check if the directory exist and is not
1080 -- the object directory or one of the source directories.
1081 -- This is the directory where copies of the interface
1082 -- sources will be copied. Note that this directory may be
1083 -- the library directory.
1085 if Lib_Src_Dir.Value /= Empty_String then
1087 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1091 (Dir_Id, Data.Display_Directory,
1092 Data.Library_Src_Dir,
1093 Data.Display_Library_Src_Dir);
1095 -- If directory does not exist, report an error
1097 if Data.Library_Src_Dir = No_Name then
1099 -- Get the absolute name of the library directory
1100 -- that does not exist, to report an error.
1103 Dir_Name : constant String :=
1104 Get_Name_String (Dir_Id);
1107 if Is_Absolute_Path (Dir_Name) then
1108 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1111 Get_Name_String (Data.Directory);
1113 if Name_Buffer (Name_Len) /=
1116 Name_Len := Name_Len + 1;
1117 Name_Buffer (Name_Len) :=
1118 Directory_Separator;
1123 Name_Len + Dir_Name'Length) :=
1125 Name_Len := Name_Len + Dir_Name'Length;
1126 Err_Vars.Error_Msg_Name_1 := Name_Find;
1133 "Directory { does not exist",
1134 Lib_Src_Dir.Location);
1137 -- Report an error if it is the same as the object
1140 elsif Data.Library_Src_Dir = Data.Object_Directory then
1143 "directory to copy interfaces cannot be " &
1144 "the object directory",
1145 Lib_Src_Dir.Location);
1146 Data.Library_Src_Dir := No_Name;
1148 -- Check if it is the same as one of the source
1153 Src_Dirs : String_List_Id := Data.Source_Dirs;
1154 Src_Dir : String_Element;
1157 while Src_Dirs /= Nil_String loop
1158 Src_Dir := String_Elements.Table (Src_Dirs);
1159 Src_Dirs := Src_Dir.Next;
1161 -- Report an error if it is one of the
1162 -- source directories.
1164 if Data.Library_Src_Dir = Src_Dir.Value then
1167 "directory to copy interfaces cannot " &
1168 "be one of the source directories",
1169 Lib_Src_Dir.Location);
1170 Data.Library_Src_Dir := No_Name;
1176 if Data.Library_Src_Dir /= No_Name
1177 and then Current_Verbosity = High
1179 Write_Str ("Directory to copy interfaces =""");
1180 Write_Str (Get_Name_String (Data.Library_Dir));
1187 if not Lib_Symbol_File.Default then
1188 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1190 Get_Name_String (Lib_Symbol_File.Value);
1192 if Name_Len = 0 then
1195 "symbol file name cannot be an empty string",
1196 Lib_Symbol_File.Location);
1199 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1202 for J in 1 .. Name_Len loop
1203 if Name_Buffer (J) = '/'
1204 or else Name_Buffer (J) = Directory_Separator
1213 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1216 "symbol file name { is illegal. " &
1217 "Name canot include directory info.",
1218 Lib_Symbol_File.Location);
1223 if not Lib_Symbol_Policy.Default then
1225 Value : constant String :=
1227 (Get_Name_String (Lib_Symbol_Policy.Value));
1230 if Value = "autonomous" or else Value = "default" then
1231 Data.Symbol_Data.Symbol_Policy := Autonomous;
1233 elsif Value = "compliant" then
1234 Data.Symbol_Data.Symbol_Policy := Compliant;
1236 elsif Value = "controlled" then
1237 Data.Symbol_Data.Symbol_Policy := Controlled;
1242 "illegal value for Library_Symbol_Policy",
1243 Lib_Symbol_Policy.Location);
1248 if Lib_Ref_Symbol_File.Default then
1249 if Data.Symbol_Data.Symbol_Policy /= Autonomous then
1252 "a reference symbol file need to be defined",
1253 Lib_Symbol_Policy.Location);
1257 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1259 Get_Name_String (Lib_Symbol_File.Value);
1261 if Name_Len = 0 then
1264 "reference symbol file name cannot be an empty string",
1265 Lib_Symbol_File.Location);
1268 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1271 for J in 1 .. Name_Len loop
1272 if Name_Buffer (J) = '/'
1273 or else Name_Buffer (J) = Directory_Separator
1282 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1285 "reference symbol file { name is illegal. " &
1286 "Name canot include directory info.",
1287 Lib_Ref_Symbol_File.Location);
1290 if not Is_Regular_File
1291 (Get_Name_String (Data.Object_Directory) &
1292 Directory_Separator &
1293 Get_Name_String (Lib_Ref_Symbol_File.Value))
1295 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1298 "library reference symbol file { does not exist",
1299 Lib_Ref_Symbol_File.Location);
1302 if Data.Symbol_Data.Symbol_File /= No_Name then
1306 (Data.Symbol_Data.Symbol_File);
1308 Reference : String :=
1310 (Data.Symbol_Data.Reference);
1313 Canonical_Case_File_Name (Symbol);
1314 Canonical_Case_File_Name (Reference);
1316 if Symbol = Reference then
1319 "reference symbol file and symbol file " &
1320 "cannot be the same file",
1321 Lib_Ref_Symbol_File.Location);
1328 end Standalone_Library;
1331 -- Put the list of Mains, if any, in the project data
1333 Get_Mains (Project, Data);
1335 Projects.Table (Project) := Data;
1337 Free_Ada_Naming_Exceptions;
1344 function ALI_File_Name (Source : String) return String is
1346 -- If the source name has an extension, then replace it with
1349 for Index in reverse Source'First + 1 .. Source'Last loop
1350 if Source (Index) = '.' then
1351 return Source (Source'First .. Index - 1) & ALI_Suffix;
1355 -- If there is no dot, or if it is the first character, just add the
1358 return Source & ALI_Suffix;
1361 --------------------
1362 -- Check_Ada_Name --
1363 --------------------
1365 procedure Check_Ada_Name
1369 The_Name : String := Name;
1370 Real_Name : Name_Id;
1371 Need_Letter : Boolean := True;
1372 Last_Underscore : Boolean := False;
1373 OK : Boolean := The_Name'Length > 0;
1376 To_Lower (The_Name);
1378 Name_Len := The_Name'Length;
1379 Name_Buffer (1 .. Name_Len) := The_Name;
1380 Real_Name := Name_Find;
1382 -- Check first that the given name is not an Ada reserved word
1384 if Get_Name_Table_Byte (Real_Name) /= 0
1385 and then Real_Name /= Name_Project
1386 and then Real_Name /= Name_Extends
1387 and then Real_Name /= Name_External
1391 if Current_Verbosity = High then
1392 Write_Str (The_Name);
1393 Write_Line (" is an Ada reserved word.");
1399 for Index in The_Name'Range loop
1402 -- We need a letter (at the beginning, and following a dot),
1403 -- but we don't have one.
1405 if Is_Letter (The_Name (Index)) then
1406 Need_Letter := False;
1411 if Current_Verbosity = High then
1412 Write_Int (Types.Int (Index));
1414 Write_Char (The_Name (Index));
1415 Write_Line ("' is not a letter.");
1421 elsif Last_Underscore
1422 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1424 -- Two underscores are illegal, and a dot cannot follow
1429 if Current_Verbosity = High then
1430 Write_Int (Types.Int (Index));
1432 Write_Char (The_Name (Index));
1433 Write_Line ("' is illegal here.");
1438 elsif The_Name (Index) = '.' then
1440 -- We need a letter after a dot
1442 Need_Letter := True;
1444 elsif The_Name (Index) = '_' then
1445 Last_Underscore := True;
1448 -- We need an letter or a digit
1450 Last_Underscore := False;
1452 if not Is_Alphanumeric (The_Name (Index)) then
1455 if Current_Verbosity = High then
1456 Write_Int (Types.Int (Index));
1458 Write_Char (The_Name (Index));
1459 Write_Line ("' is not alphanumeric.");
1467 -- Cannot end with an underscore or a dot
1469 OK := OK and then not Need_Letter and then not Last_Underscore;
1475 -- Signal a problem with No_Name
1481 ----------------------
1482 -- Check_For_Source --
1483 ----------------------
1485 procedure Check_For_Source
1486 (File_Name : Name_Id;
1487 Path_Name : Name_Id;
1488 Project : Project_Id;
1489 Data : in out Project_Data;
1490 Location : Source_Ptr;
1491 Language : Other_Programming_Language;
1493 Naming_Exception : Boolean)
1495 Name : String := Get_Name_String (File_Name);
1496 Real_Location : Source_Ptr := Location;
1499 Canonical_Case_File_Name (Name);
1501 -- A file is a source of a language if Naming_Exception is True (case
1502 -- of naming exceptions) or if its file name ends with the suffix.
1504 if Naming_Exception or else
1505 (Name'Length > Suffix'Length and then
1506 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
1508 if Real_Location = No_Location then
1509 Real_Location := Data.Location;
1513 Path : String := Get_Name_String (Path_Name);
1516 -- The path name id (in canonical case)
1519 -- The file name id (in canonical case)
1522 -- The object file name
1524 Obj_Path_Id : Name_Id;
1525 -- The object path name
1528 -- The dependency file name
1530 Dep_Path_Id : Name_Id;
1531 -- The dependency path name
1533 Dot_Pos : Natural := 0;
1534 -- Position of the last dot in Name
1536 Source : Other_Source;
1537 Source_Id : Other_Source_Id := Data.First_Other_Source;
1540 Canonical_Case_File_Name (Path);
1542 -- Get the file name id
1544 Name_Len := Name'Length;
1545 Name_Buffer (1 .. Name_Len) := Name;
1546 File_Id := Name_Find;
1548 -- Get the path name id
1550 Name_Len := Path'Length;
1551 Name_Buffer (1 .. Name_Len) := Path;
1552 Path_Id := Name_Find;
1554 -- Find the position of the last dot
1556 for J in reverse Name'Range loop
1557 if Name (J) = '.' then
1563 if Dot_Pos <= Name'First then
1564 Dot_Pos := Name'Last + 1;
1567 -- Compute the object file name
1569 Get_Name_String (File_Id);
1570 Name_Len := Dot_Pos - Name'First;
1572 for J in Object_Suffix'Range loop
1573 Name_Len := Name_Len + 1;
1574 Name_Buffer (Name_Len) := Object_Suffix (J);
1577 Obj_Id := Name_Find;
1579 -- Compute the object path name
1581 Get_Name_String (Data.Object_Directory);
1583 if Name_Buffer (Name_Len) /= Directory_Separator and then
1584 Name_Buffer (Name_Len) /= '/'
1586 Name_Len := Name_Len + 1;
1587 Name_Buffer (Name_Len) := Directory_Separator;
1590 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
1591 Obj_Path_Id := Name_Find;
1593 -- Compute the dependency file name
1595 Get_Name_String (File_Id);
1596 Name_Len := Dot_Pos - Name'First + 1;
1597 Name_Buffer (Name_Len) := '.';
1598 Name_Len := Name_Len + 1;
1599 Name_Buffer (Name_Len) := 'd';
1600 Dep_Id := Name_Find;
1602 -- Compute the dependency path name
1604 Get_Name_String (Data.Object_Directory);
1606 if Name_Buffer (Name_Len) /= Directory_Separator and then
1607 Name_Buffer (Name_Len) /= '/'
1609 Name_Len := Name_Len + 1;
1610 Name_Buffer (Name_Len) := Directory_Separator;
1613 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
1614 Dep_Path_Id := Name_Find;
1616 -- Check if source is already in the list of source for this
1617 -- project: it may have already been specified as a naming
1618 -- exception for the same language or an other language, or they
1619 -- may be two identical file names in different source
1622 while Source_Id /= No_Other_Source loop
1623 Source := Other_Sources.Table (Source_Id);
1624 Source_Id := Source.Next;
1626 if Source.File_Name = File_Id then
1627 -- Two sources of different languages cannot have the same
1630 if Source.Language /= Language then
1631 Error_Msg_Name_1 := File_Name;
1634 "{ cannot be a source of several languages",
1638 -- No problem if a file has already been specified as
1639 -- a naming exception of this language.
1641 elsif Source.Path_Name = Path_Id then
1642 -- Reset the naming exception flag, if this is not a
1643 -- naming exception.
1645 if not Naming_Exception then
1646 Other_Sources.Table (Source_Id).Naming_Exception :=
1652 -- There are several files with the same names, but the
1653 -- order of the source directories is known (no /**):
1654 -- only the first one encountered is kept, the other ones
1657 elsif Data.Known_Order_Of_Source_Dirs then
1660 -- But it is an error if the order of the source directories
1664 Error_Msg_Name_1 := File_Name;
1667 "{ is found in several source directories",
1672 -- Two sources with different file names cannot have the same
1673 -- object file name.
1675 elsif Source.Object_Name = Obj_Id then
1676 Error_Msg_Name_1 := File_Id;
1677 Error_Msg_Name_2 := Source.File_Name;
1678 Error_Msg_Name_3 := Obj_Id;
1681 "{ and { have the same object file {",
1687 if Current_Verbosity = High then
1688 Write_Str (" found ");
1689 Write_Str (Lang_Display_Names (Language).all);
1690 Write_Str (" source """);
1691 Write_Str (Get_Name_String (File_Name));
1693 Write_Str (" object path = ");
1694 Write_Line (Get_Name_String (Obj_Path_Id));
1697 -- Create the Other_Source record
1699 (Language => Language,
1700 File_Name => File_Id,
1701 Path_Name => Path_Id,
1702 Source_TS => File_Stamp (Path_Id),
1703 Object_Name => Obj_Id,
1704 Object_Path => Obj_Path_Id,
1705 Object_TS => File_Stamp (Obj_Path_Id),
1707 Dep_Path => Dep_Path_Id,
1708 Dep_TS => File_Stamp (Dep_Path_Id),
1709 Naming_Exception => Naming_Exception,
1710 Next => No_Other_Source);
1712 -- And add it to the Other_Sources table
1714 Other_Sources.Increment_Last;
1715 Other_Sources.Table (Other_Sources.Last) := Source;
1717 -- There are sources of languages other than Ada in this project
1718 Data.Sources_Present := True;
1720 -- And there are sources of this language in this project
1722 Data.Languages (Language) := True;
1724 -- Add this source to the list of sources of languages other than
1725 -- Ada of the project.
1727 if Data.First_Other_Source = No_Other_Source then
1728 Data.First_Other_Source := Other_Sources.Last;
1731 Other_Sources.Table (Data.Last_Other_Source).Next :=
1735 Data.Last_Other_Source := Other_Sources.Last;
1738 end Check_For_Source;
1740 -----------------------------
1741 -- Check_Ada_Naming_Scheme --
1742 -----------------------------
1744 procedure Check_Ada_Naming_Scheme
1745 (Project : Project_Id;
1746 Naming : Naming_Data)
1749 -- Only check if we are not using the standard naming scheme
1751 if Naming /= Standard_Naming_Data then
1753 Dot_Replacement : constant String :=
1755 (Naming.Dot_Replacement);
1757 Spec_Suffix : constant String :=
1759 (Naming.Current_Spec_Suffix);
1761 Body_Suffix : constant String :=
1763 (Naming.Current_Body_Suffix);
1765 Separate_Suffix : constant String :=
1767 (Naming.Separate_Suffix);
1770 -- Dot_Replacement cannot
1772 -- - start or end with an alphanumeric
1773 -- - be a single '_'
1774 -- - start with an '_' followed by an alphanumeric
1775 -- - contain a '.' except if it is "."
1777 if Dot_Replacement'Length = 0
1778 or else Is_Alphanumeric
1779 (Dot_Replacement (Dot_Replacement'First))
1780 or else Is_Alphanumeric
1781 (Dot_Replacement (Dot_Replacement'Last))
1782 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1784 (Dot_Replacement'Length = 1
1787 (Dot_Replacement (Dot_Replacement'First + 1))))
1788 or else (Dot_Replacement'Length > 1
1790 Index (Source => Dot_Replacement,
1791 Pattern => ".") /= 0)
1795 '"' & Dot_Replacement &
1796 """ is illegal for Dot_Replacement.",
1797 Naming.Dot_Repl_Loc);
1803 if Is_Illegal_Suffix
1804 (Spec_Suffix, Dot_Replacement = ".")
1806 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1809 "{ is illegal for Spec_Suffix",
1810 Naming.Spec_Suffix_Loc);
1813 if Is_Illegal_Suffix
1814 (Body_Suffix, Dot_Replacement = ".")
1816 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1819 "{ is illegal for Body_Suffix",
1820 Naming.Body_Suffix_Loc);
1823 if Body_Suffix /= Separate_Suffix then
1824 if Is_Illegal_Suffix
1825 (Separate_Suffix, Dot_Replacement = ".")
1827 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1830 "{ is illegal for Separate_Suffix",
1831 Naming.Sep_Suffix_Loc);
1835 -- Spec_Suffix cannot have the same termination as
1836 -- Body_Suffix or Separate_Suffix
1838 if Spec_Suffix'Length <= Body_Suffix'Length
1840 Body_Suffix (Body_Suffix'Last -
1841 Spec_Suffix'Length + 1 ..
1842 Body_Suffix'Last) = Spec_Suffix
1848 """) cannot end with" &
1849 " Spec_Suffix (""" &
1850 Spec_Suffix & """).",
1851 Naming.Body_Suffix_Loc);
1854 if Body_Suffix /= Separate_Suffix
1855 and then Spec_Suffix'Length <= Separate_Suffix'Length
1858 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1860 Separate_Suffix'Last) = Spec_Suffix
1864 "Separate_Suffix (""" &
1866 """) cannot end with" &
1867 " Spec_Suffix (""" &
1868 Spec_Suffix & """).",
1869 Naming.Sep_Suffix_Loc);
1873 end Check_Ada_Naming_Scheme;
1875 -------------------------
1876 -- Check_Naming_Scheme --
1877 -------------------------
1879 procedure Check_Naming_Scheme
1880 (Data : in out Project_Data;
1881 Project : Project_Id)
1883 Naming_Id : constant Package_Id :=
1884 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1886 Naming : Package_Element;
1888 procedure Check_Unit_Names (List : Array_Element_Id);
1889 -- Check that a list of unit names contains only valid names.
1891 ----------------------
1892 -- Check_Unit_Names --
1893 ----------------------
1895 procedure Check_Unit_Names (List : Array_Element_Id) is
1896 Current : Array_Element_Id := List;
1897 Element : Array_Element;
1898 Unit_Name : Name_Id;
1901 -- Loop through elements of the string list
1903 while Current /= No_Array_Element loop
1904 Element := Array_Elements.Table (Current);
1906 -- Put file name in canonical case
1908 Get_Name_String (Element.Value.Value);
1909 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1910 Element.Value.Value := Name_Find;
1912 -- Check that it contains a valid unit name
1914 Get_Name_String (Element.Index);
1915 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1917 if Unit_Name = No_Name then
1918 Err_Vars.Error_Msg_Name_1 := Element.Index;
1921 "{ is not a valid unit name.",
1922 Element.Value.Location);
1925 if Current_Verbosity = High then
1926 Write_Str (" Unit (""");
1927 Write_Str (Get_Name_String (Unit_Name));
1931 Element.Index := Unit_Name;
1932 Array_Elements.Table (Current) := Element;
1935 Current := Element.Next;
1937 end Check_Unit_Names;
1939 -- Start of processing for Check_Naming_Scheme
1942 -- If there is a package Naming, we will put in Data.Naming what is in
1943 -- this package Naming.
1945 if Naming_Id /= No_Package then
1946 Naming := Packages.Table (Naming_Id);
1948 if Current_Verbosity = High then
1949 Write_Line ("Checking ""Naming"" for Ada.");
1953 Bodies : constant Array_Element_Id :=
1954 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
1956 Specs : constant Array_Element_Id :=
1957 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
1960 if Bodies /= No_Array_Element then
1962 -- We have elements in the array Body_Part
1964 if Current_Verbosity = High then
1965 Write_Line ("Found Bodies.");
1968 Data.Naming.Bodies := Bodies;
1969 Check_Unit_Names (Bodies);
1972 if Current_Verbosity = High then
1973 Write_Line ("No Bodies.");
1977 if Specs /= No_Array_Element then
1979 -- We have elements in the array Specs
1981 if Current_Verbosity = High then
1982 Write_Line ("Found Specs.");
1985 Data.Naming.Specs := Specs;
1986 Check_Unit_Names (Specs);
1989 if Current_Verbosity = High then
1990 Write_Line ("No Specs.");
1995 -- We are now checking if variables Dot_Replacement, Casing,
1996 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1999 -- For each variable, if it does not exist, we do nothing,
2000 -- because we already have the default.
2002 -- Check Dot_Replacement
2005 Dot_Replacement : constant Variable_Value :=
2007 (Name_Dot_Replacement,
2008 Naming.Decl.Attributes);
2011 pragma Assert (Dot_Replacement.Kind = Single,
2012 "Dot_Replacement is not a single string");
2014 if not Dot_Replacement.Default then
2015 Get_Name_String (Dot_Replacement.Value);
2017 if Name_Len = 0 then
2020 "Dot_Replacement cannot be empty",
2021 Dot_Replacement.Location);
2024 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2025 Data.Naming.Dot_Replacement := Name_Find;
2026 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2031 if Current_Verbosity = High then
2032 Write_Str (" Dot_Replacement = """);
2033 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
2041 Casing_String : constant Variable_Value :=
2043 (Name_Casing, Naming.Decl.Attributes);
2046 pragma Assert (Casing_String.Kind = Single,
2047 "Casing is not a single string");
2049 if not Casing_String.Default then
2051 Casing_Image : constant String :=
2052 Get_Name_String (Casing_String.Value);
2055 Casing_Value : constant Casing_Type :=
2056 Value (Casing_Image);
2058 -- Ignore Casing on platforms where file names are
2059 -- case-insensitive.
2061 if not File_Names_Case_Sensitive then
2062 Data.Naming.Casing := All_Lower_Case;
2065 Data.Naming.Casing := Casing_Value;
2070 when Constraint_Error =>
2071 if Casing_Image'Length = 0 then
2074 "Casing cannot be an empty string",
2075 Casing_String.Location);
2078 Name_Len := Casing_Image'Length;
2079 Name_Buffer (1 .. Name_Len) := Casing_Image;
2080 Err_Vars.Error_Msg_Name_1 := Name_Find;
2083 "{ is not a correct Casing",
2084 Casing_String.Location);
2090 if Current_Verbosity = High then
2091 Write_Str (" Casing = ");
2092 Write_Str (Image (Data.Naming.Casing));
2097 -- Check Spec_Suffix
2100 Ada_Spec_Suffix : constant Variable_Value :=
2103 In_Array => Data.Naming.Spec_Suffix);
2106 if Ada_Spec_Suffix.Kind = Single
2107 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2109 Get_Name_String (Ada_Spec_Suffix.Value);
2110 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2111 Data.Naming.Current_Spec_Suffix := Name_Find;
2112 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2115 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2119 if Current_Verbosity = High then
2120 Write_Str (" Spec_Suffix = """);
2121 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2126 -- Check Body_Suffix
2129 Ada_Body_Suffix : constant Variable_Value :=
2132 In_Array => Data.Naming.Body_Suffix);
2135 if Ada_Body_Suffix.Kind = Single
2136 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2138 Get_Name_String (Ada_Body_Suffix.Value);
2139 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2140 Data.Naming.Current_Body_Suffix := Name_Find;
2141 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2144 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2148 if Current_Verbosity = High then
2149 Write_Str (" Body_Suffix = """);
2150 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
2155 -- Check Separate_Suffix
2158 Ada_Sep_Suffix : constant Variable_Value :=
2160 (Variable_Name => Name_Separate_Suffix,
2161 In_Variables => Naming.Decl.Attributes);
2164 if Ada_Sep_Suffix.Default then
2165 Data.Naming.Separate_Suffix :=
2166 Data.Naming.Current_Body_Suffix;
2169 Get_Name_String (Ada_Sep_Suffix.Value);
2171 if Name_Len = 0 then
2174 "Separate_Suffix cannot be empty",
2175 Ada_Sep_Suffix.Location);
2178 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2179 Data.Naming.Separate_Suffix := Name_Find;
2180 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
2185 if Current_Verbosity = High then
2186 Write_Str (" Separate_Suffix = """);
2187 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
2192 -- Check if Data.Naming is valid
2194 Check_Ada_Naming_Scheme (Project, Data.Naming);
2197 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2198 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2199 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
2201 end Check_Naming_Scheme;
2207 function Check_Project
2209 Root_Project : Project_Id;
2210 Extending : Boolean) return Boolean
2213 if P = Root_Project then
2216 elsif Extending then
2218 Data : Project_Data := Projects.Table (Root_Project);
2221 while Data.Extends /= No_Project loop
2222 if P = Data.Extends then
2226 Data := Projects.Table (Data.Extends);
2234 ----------------------------
2235 -- Compute_Directory_Last --
2236 ----------------------------
2238 function Compute_Directory_Last (Dir : String) return Natural is
2241 and then (Dir (Dir'Last - 1) = Directory_Separator
2242 or else Dir (Dir'Last - 1) = '/')
2244 return Dir'Last - 1;
2248 end Compute_Directory_Last;
2255 (Project : Project_Id;
2257 Flag_Location : Source_Ptr)
2259 Error_Buffer : String (1 .. 5_000);
2260 Error_Last : Natural := 0;
2261 Msg_Name : Natural := 0;
2262 First : Positive := Msg'First;
2264 procedure Add (C : Character);
2265 -- Add a character to the buffer
2267 procedure Add (S : String);
2268 -- Add a string to the buffer
2270 procedure Add (Id : Name_Id);
2271 -- Add a name to the buffer
2277 procedure Add (C : Character) is
2279 Error_Last := Error_Last + 1;
2280 Error_Buffer (Error_Last) := C;
2283 procedure Add (S : String) is
2285 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2286 Error_Last := Error_Last + S'Length;
2289 procedure Add (Id : Name_Id) is
2291 Get_Name_String (Id);
2292 Add (Name_Buffer (1 .. Name_Len));
2295 -- Start of processing for Error_Msg
2298 if Error_Report = null then
2299 Prj.Err.Error_Msg (Msg, Flag_Location);
2303 if Msg (First) = '\' then
2305 -- Continuation character, ignore.
2309 elsif Msg (First) = '?' then
2311 -- Warning character. It is always the first one in this package
2317 for Index in First .. Msg'Last loop
2318 if Msg (Index) = '{' or else Msg (Index) = '%' then
2320 -- Include a name between double quotes.
2322 Msg_Name := Msg_Name + 1;
2326 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2327 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2328 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2330 when others => null;
2341 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2348 procedure Find_Sources
2349 (Project : Project_Id;
2350 Data : in out Project_Data;
2351 For_Language : Programming_Language;
2352 Follow_Links : Boolean := False)
2354 Source_Dir : String_List_Id := Data.Source_Dirs;
2355 Element : String_Element;
2357 Current_Source : String_List_Id := Nil_String;
2358 Source_Recorded : Boolean := False;
2361 if Current_Verbosity = High then
2362 Write_Line ("Looking for sources:");
2365 -- For each subdirectory
2367 while Source_Dir /= Nil_String loop
2369 Source_Recorded := False;
2370 Element := String_Elements.Table (Source_Dir);
2371 if Element.Value /= No_Name then
2372 Get_Name_String (Element.Display_Value);
2375 Source_Directory : constant String :=
2376 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2377 Dir_Last : constant Natural :=
2378 Compute_Directory_Last (Source_Directory);
2381 if Current_Verbosity = High then
2382 Write_Str ("Source_Dir = ");
2383 Write_Line (Source_Directory);
2386 -- We look to every entry in the source directory
2388 Open (Dir, Source_Directory
2389 (Source_Directory'First .. Dir_Last));
2392 Read (Dir, Name_Buffer, Name_Len);
2394 if Current_Verbosity = High then
2395 Write_Str (" Checking ");
2396 Write_Line (Name_Buffer (1 .. Name_Len));
2399 exit when Name_Len = 0;
2402 File_Name : constant Name_Id := Name_Find;
2403 Path : constant String :=
2405 (Name => Name_Buffer (1 .. Name_Len),
2406 Directory => Source_Directory
2407 (Source_Directory'First .. Dir_Last),
2408 Resolve_Links => Follow_Links,
2409 Case_Sensitive => True);
2410 Path_Name : Name_Id;
2413 Name_Len := Path'Length;
2414 Name_Buffer (1 .. Name_Len) := Path;
2415 Path_Name := Name_Find;
2417 if For_Language = Lang_Ada then
2418 -- We attempt to register it as a source.
2419 -- However, there is no error if the file
2420 -- does not contain a valid source.
2421 -- But there is an error if we have a
2422 -- duplicate unit name.
2425 (File_Name => File_Name,
2426 Path_Name => Path_Name,
2429 Location => No_Location,
2430 Current_Source => Current_Source,
2431 Source_Recorded => Source_Recorded,
2432 Follow_Links => Follow_Links);
2436 (File_Name => File_Name,
2437 Path_Name => Path_Name,
2440 Location => No_Location,
2441 Language => For_Language,
2444 (Data.Impl_Suffixes (For_Language)),
2445 Naming_Exception => False);
2455 when Directory_Error =>
2459 if Source_Recorded then
2460 String_Elements.Table (Source_Dir).Flag := True;
2463 Source_Dir := Element.Next;
2466 if Current_Verbosity = High then
2467 Write_Line ("end Looking for sources.");
2470 if For_Language = Lang_Ada then
2471 -- If we have looked for sources and found none, then
2472 -- it is an error, except if it is an extending project.
2473 -- If a non extending project is not supposed to contain
2474 -- any source, then we never call Find_Sources.
2476 if Current_Source /= Nil_String then
2477 Data.Sources_Present := True;
2479 elsif Data.Extends = No_Project then
2482 "there are no Ada sources in this project",
2488 --------------------------------
2489 -- Free_Ada_Naming_Exceptions --
2490 --------------------------------
2492 procedure Free_Ada_Naming_Exceptions is
2494 Ada_Naming_Exceptions.Reset;
2495 Reverse_Ada_Naming_Exceptions.Reset;
2496 end Free_Ada_Naming_Exceptions;
2502 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2503 Mains : constant Variable_Value :=
2504 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2507 Data.Mains := Mains.Values;
2509 -- If no Mains were specified, and if we are an extending
2510 -- project, inherit the Mains from the project we are extending.
2512 if Mains.Default then
2513 if Data.Extends /= No_Project then
2514 Data.Mains := Projects.Table (Data.Extends).Mains;
2517 -- In a library project file, Main cannot be specified
2519 elsif Data.Library then
2522 "a library project file cannot have Main specified",
2527 ---------------------------
2528 -- Get_Sources_From_File --
2529 ---------------------------
2531 procedure Get_Sources_From_File
2533 Location : Source_Ptr;
2534 Project : Project_Id)
2536 File : Prj.Util.Text_File;
2537 Line : String (1 .. 250);
2539 Source_Name : Name_Id;
2544 if Current_Verbosity = High then
2545 Write_Str ("Opening """);
2552 Prj.Util.Open (File, Path);
2554 if not Prj.Util.Is_Valid (File) then
2555 Error_Msg (Project, "file does not exist", Location);
2557 -- Read the lines one by one
2559 while not Prj.Util.End_Of_File (File) loop
2560 Prj.Util.Get_Line (File, Line, Last);
2562 -- A non empty, non comment line should contain a file name
2565 and then (Last = 1 or else Line (1 .. 2) /= "--")
2567 -- ??? we should check that there is no directory information
2570 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2571 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2572 Source_Name := Name_Find;
2576 (Name => Source_Name,
2577 Location => Location,
2582 Prj.Util.Close (File);
2585 end Get_Sources_From_File;
2592 (Canonical_File_Name : Name_Id;
2593 Naming : Naming_Data;
2594 Unit_Name : out Name_Id;
2595 Unit_Kind : out Spec_Or_Body;
2596 Needs_Pragma : out Boolean)
2598 function Check_Exception (Canonical : Name_Id) return Boolean;
2599 pragma Inline (Check_Exception);
2600 -- Check if Canonical is one of the exceptions in List.
2601 -- Returns True if Get_Unit should exit
2603 ---------------------
2604 -- Check_Exception --
2605 ---------------------
2607 function Check_Exception (Canonical : Name_Id) return Boolean is
2608 Info : Unit_Info := Ada_Naming_Exceptions.Get (Canonical);
2612 if Info = No_Unit then
2613 if Hostparm.OpenVMS then
2614 VMS_Name := Canonical;
2615 Get_Name_String (VMS_Name);
2617 if Name_Buffer (Name_Len) = '.' then
2618 Name_Len := Name_Len - 1;
2619 VMS_Name := Name_Find;
2622 Info := Ada_Naming_Exceptions.Get (VMS_Name);
2625 if Info = No_Unit then
2630 Unit_Kind := Info.Kind;
2631 Unit_Name := Info.Unit;
2632 Needs_Pragma := True;
2634 end Check_Exception;
2636 -- Start of processing for Get_Unit
2639 Needs_Pragma := False;
2641 if Check_Exception (Canonical_File_Name) then
2645 Get_Name_String (Canonical_File_Name);
2648 File : String := Name_Buffer (1 .. Name_Len);
2649 First : constant Positive := File'First;
2650 Last : Natural := File'Last;
2651 Standard_GNAT : Boolean;
2655 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2656 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2658 -- Check if the end of the file name is Specification_Append
2660 Get_Name_String (Naming.Current_Spec_Suffix);
2662 if File'Length > Name_Len
2663 and then File (Last - Name_Len + 1 .. Last) =
2664 Name_Buffer (1 .. Name_Len)
2668 Unit_Kind := Specification;
2669 Last := Last - Name_Len;
2671 if Current_Verbosity = High then
2672 Write_Str (" Specification: ");
2673 Write_Line (File (First .. Last));
2677 Get_Name_String (Naming.Current_Body_Suffix);
2679 -- Check if the end of the file name is Body_Append
2681 if File'Length > Name_Len
2682 and then File (Last - Name_Len + 1 .. Last) =
2683 Name_Buffer (1 .. Name_Len)
2687 Unit_Kind := Body_Part;
2688 Last := Last - Name_Len;
2690 if Current_Verbosity = High then
2691 Write_Str (" Body: ");
2692 Write_Line (File (First .. Last));
2695 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2696 Get_Name_String (Naming.Separate_Suffix);
2698 -- Check if the end of the file name is Separate_Append
2700 if File'Length > Name_Len
2701 and then File (Last - Name_Len + 1 .. Last) =
2702 Name_Buffer (1 .. Name_Len)
2704 -- We have a separate (a body)
2706 Unit_Kind := Body_Part;
2707 Last := Last - Name_Len;
2709 if Current_Verbosity = High then
2710 Write_Str (" Separate: ");
2711 Write_Line (File (First .. Last));
2725 -- This is not a source file
2727 Unit_Name := No_Name;
2728 Unit_Kind := Specification;
2730 if Current_Verbosity = High then
2731 Write_Line (" Not a valid file name.");
2737 Get_Name_String (Naming.Dot_Replacement);
2739 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2741 if Name_Buffer (1 .. Name_Len) /= "." then
2743 -- If Dot_Replacement is not a single dot,
2744 -- then there should not be any dot in the name.
2746 for Index in First .. Last loop
2747 if File (Index) = '.' then
2748 if Current_Verbosity = High then
2750 (" Not a valid file name (some dot not replaced).");
2753 Unit_Name := No_Name;
2759 -- Replace the substring Dot_Replacement with dots
2762 Index : Positive := First;
2765 while Index <= Last - Name_Len + 1 loop
2767 if File (Index .. Index + Name_Len - 1) =
2768 Name_Buffer (1 .. Name_Len)
2770 File (Index) := '.';
2772 if Name_Len > 1 and then Index < Last then
2773 File (Index + 1 .. Last - Name_Len + 1) :=
2774 File (Index + Name_Len .. Last);
2777 Last := Last - Name_Len + 1;
2785 -- Check if the casing is right
2788 Src : String := File (First .. Last);
2791 case Naming.Casing is
2792 when All_Lower_Case =>
2795 Mapping => Lower_Case_Map);
2797 when All_Upper_Case =>
2800 Mapping => Upper_Case_Map);
2802 when Mixed_Case | Unknown =>
2806 if Src /= File (First .. Last) then
2807 if Current_Verbosity = High then
2808 Write_Line (" Not a valid file name (casing).");
2811 Unit_Name := No_Name;
2815 -- We put the name in lower case
2819 Mapping => Lower_Case_Map);
2821 -- In the standard GNAT naming scheme, check for special cases:
2822 -- children or separates of A, G, I or S, and run time sources.
2824 if Standard_GNAT and then Src'Length >= 3 then
2826 S1 : constant Character := Src (Src'First);
2827 S2 : constant Character := Src (Src'First + 1);
2830 if S1 = 'a' or else S1 = 'g'
2831 or else S1 = 'i' or else S1 = 's'
2833 -- Children or separates of packages A, G, I or S
2835 if (Hostparm.OpenVMS and then S2 = '$')
2836 or else (not Hostparm.OpenVMS and then S2 = '~')
2838 Src (Src'First + 1) := '.';
2840 -- If it is potentially a run time source, disable
2841 -- filling of the mapping file to avoid warnings.
2844 Set_Mapping_File_Initial_State_To_Empty;
2851 if Current_Verbosity = High then
2856 -- Now, we check if this name is a valid unit name
2858 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2868 function Hash (Unit : Unit_Info) return Header_Num is
2870 return Header_Num (Unit.Unit mod 2048);
2873 -----------------------
2874 -- Is_Illegal_Suffix --
2875 -----------------------
2877 function Is_Illegal_Suffix
2879 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2882 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2886 -- If dot replacement is a single dot, and first character of
2887 -- suffix is also a dot
2889 if Dot_Replacement_Is_A_Single_Dot
2890 and then Suffix (Suffix'First) = '.'
2892 for Index in Suffix'First + 1 .. Suffix'Last loop
2894 -- If there is another dot
2896 if Suffix (Index) = '.' then
2898 -- It is illegal to have a letter following the initial dot
2900 return Is_Letter (Suffix (Suffix'First + 1));
2908 end Is_Illegal_Suffix;
2910 --------------------------------
2911 -- Language_Independent_Check --
2912 --------------------------------
2914 procedure Language_Independent_Check
2915 (Project : Project_Id;
2916 Report_Error : Put_Line_Access)
2918 Last_Source_Dir : String_List_Id := Nil_String;
2919 Data : Project_Data := Projects.Table (Project);
2921 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2922 -- Find one or several source directories, and add them
2923 -- to the list of source directories of the project.
2925 ----------------------
2926 -- Find_Source_Dirs --
2927 ----------------------
2929 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2930 Directory : constant String := Get_Name_String (From);
2931 Element : String_Element;
2933 procedure Recursive_Find_Dirs (Path : Name_Id);
2934 -- Find all the subdirectories (recursively) of Path and add them
2935 -- to the list of source directories of the project.
2937 -------------------------
2938 -- Recursive_Find_Dirs --
2939 -------------------------
2941 procedure Recursive_Find_Dirs (Path : Name_Id) is
2943 Name : String (1 .. 250);
2945 List : String_List_Id := Data.Source_Dirs;
2946 Element : String_Element;
2947 Found : Boolean := False;
2949 Non_Canonical_Path : Name_Id := No_Name;
2950 Canonical_Path : Name_Id := No_Name;
2952 The_Path : constant String :=
2953 Normalize_Pathname (Get_Name_String (Path)) &
2954 Directory_Separator;
2956 The_Path_Last : constant Natural :=
2957 Compute_Directory_Last (The_Path);
2960 Name_Len := The_Path_Last - The_Path'First + 1;
2961 Name_Buffer (1 .. Name_Len) :=
2962 The_Path (The_Path'First .. The_Path_Last);
2963 Non_Canonical_Path := Name_Find;
2964 Get_Name_String (Non_Canonical_Path);
2965 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2966 Canonical_Path := Name_Find;
2968 -- To avoid processing the same directory several times, check
2969 -- if the directory is already in Recursive_Dirs. If it is,
2970 -- then there is nothing to do, just return. If it is not, put
2971 -- it there and continue recursive processing.
2973 if Recursive_Dirs.Get (Canonical_Path) then
2977 Recursive_Dirs.Set (Canonical_Path, True);
2980 -- Check if directory is already in list
2982 while List /= Nil_String loop
2983 Element := String_Elements.Table (List);
2985 if Element.Value /= No_Name then
2986 Found := Element.Value = Canonical_Path;
2990 List := Element.Next;
2993 -- If directory is not already in list, put it there
2996 if Current_Verbosity = High then
2998 Write_Line (The_Path (The_Path'First .. The_Path_Last));
3001 String_Elements.Increment_Last;
3003 (Value => Canonical_Path,
3004 Display_Value => Non_Canonical_Path,
3005 Location => No_Location,
3007 Next => Nil_String);
3009 -- Case of first source directory
3011 if Last_Source_Dir = Nil_String then
3012 Data.Source_Dirs := String_Elements.Last;
3014 -- Here we already have source directories.
3017 -- Link the previous last to the new one
3019 String_Elements.Table (Last_Source_Dir).Next :=
3020 String_Elements.Last;
3023 -- And register this source directory as the new last
3025 Last_Source_Dir := String_Elements.Last;
3026 String_Elements.Table (Last_Source_Dir) := Element;
3029 -- Now look for subdirectories. We do that even when this
3030 -- directory is already in the list, because some of its
3031 -- subdirectories may not be in the list yet.
3033 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3036 Read (Dir, Name, Last);
3039 if Name (1 .. Last) /= "."
3040 and then Name (1 .. Last) /= ".."
3044 if Current_Verbosity = High then
3045 Write_Str (" Checking ");
3046 Write_Line (Name (1 .. Last));
3050 Path_Name : constant String :=
3052 (Name => Name (1 .. Last),
3055 (The_Path'First .. The_Path_Last),
3056 Resolve_Links => False,
3057 Case_Sensitive => True);
3060 if Is_Directory (Path_Name) then
3062 -- We have found a new subdirectory, call self
3064 Name_Len := Path_Name'Length;
3065 Name_Buffer (1 .. Name_Len) := Path_Name;
3066 Recursive_Find_Dirs (Name_Find);
3075 when Directory_Error =>
3077 end Recursive_Find_Dirs;
3079 -- Start of processing for Find_Source_Dirs
3082 if Current_Verbosity = High then
3083 Write_Str ("Find_Source_Dirs (""");
3084 Write_Str (Directory);
3088 -- First, check if we are looking for a directory tree,
3089 -- indicated by "/**" at the end.
3091 if Directory'Length >= 3
3092 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3093 and then (Directory (Directory'Last - 2) = '/'
3095 Directory (Directory'Last - 2) = Directory_Separator)
3097 Data.Known_Order_Of_Source_Dirs := False;
3099 Name_Len := Directory'Length - 3;
3101 if Name_Len = 0 then
3103 -- This is the case of "/**": all directories
3104 -- in the file system.
3107 Name_Buffer (1) := Directory (Directory'First);
3110 Name_Buffer (1 .. Name_Len) :=
3111 Directory (Directory'First .. Directory'Last - 3);
3114 if Current_Verbosity = High then
3115 Write_Str ("Looking for all subdirectories of """);
3116 Write_Str (Name_Buffer (1 .. Name_Len));
3121 Base_Dir : constant Name_Id := Name_Find;
3122 Root_Dir : constant String :=
3124 (Name => Get_Name_String (Base_Dir),
3126 Get_Name_String (Data.Display_Directory),
3127 Resolve_Links => False,
3128 Case_Sensitive => True);
3131 if Root_Dir'Length = 0 then
3132 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3134 if Location = No_Location then
3137 "{ is not a valid directory.",
3142 "{ is not a valid directory.",
3147 -- We have an existing directory,
3148 -- we register it and all of its subdirectories.
3150 if Current_Verbosity = High then
3151 Write_Line ("Looking for source directories:");
3154 Name_Len := Root_Dir'Length;
3155 Name_Buffer (1 .. Name_Len) := Root_Dir;
3156 Recursive_Find_Dirs (Name_Find);
3158 if Current_Verbosity = High then
3159 Write_Line ("End of looking for source directories.");
3164 -- We have a single directory
3168 Path_Name : Name_Id;
3169 Display_Path_Name : Name_Id;
3172 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3173 if Path_Name = No_Name then
3174 Err_Vars.Error_Msg_Name_1 := From;
3176 if Location = No_Location then
3179 "{ is not a valid directory",
3184 "{ is not a valid directory",
3189 -- As it is an existing directory, we add it to
3190 -- the list of directories.
3192 String_Elements.Increment_Last;
3193 Element.Value := Path_Name;
3194 Element.Display_Value := Display_Path_Name;
3196 if Last_Source_Dir = Nil_String then
3198 -- This is the first source directory
3200 Data.Source_Dirs := String_Elements.Last;
3203 -- We already have source directories,
3204 -- link the previous last to the new one.
3206 String_Elements.Table (Last_Source_Dir).Next :=
3207 String_Elements.Last;
3210 -- And register this source directory as the new last
3212 Last_Source_Dir := String_Elements.Last;
3213 String_Elements.Table (Last_Source_Dir) := Element;
3217 end Find_Source_Dirs;
3219 -- Start of processing for Language_Independent_Check
3222 if Data.Language_Independent_Checked then
3226 Data.Language_Independent_Checked := True;
3228 Error_Report := Report_Error;
3230 Recursive_Dirs.Reset;
3232 if Current_Verbosity = High then
3233 Write_Line ("Starting to look for directories");
3236 -- Check the object directory
3239 Object_Dir : constant Variable_Value :=
3240 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3243 pragma Assert (Object_Dir.Kind = Single,
3244 "Object_Dir is not a single string");
3246 -- We set the object directory to its default
3248 Data.Object_Directory := Data.Directory;
3249 Data.Display_Object_Dir := Data.Display_Directory;
3251 if Object_Dir.Value /= Empty_String then
3253 Get_Name_String (Object_Dir.Value);
3255 if Name_Len = 0 then
3258 "Object_Dir cannot be empty",
3259 Object_Dir.Location);
3262 -- We check that the specified object directory
3266 (Object_Dir.Value, Data.Display_Directory,
3267 Data.Object_Directory, Data.Display_Object_Dir);
3269 if Data.Object_Directory = No_Name then
3270 -- The object directory does not exist, report an error
3271 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3274 "the object directory { cannot be found",
3277 -- Do not keep a nil Object_Directory. Set it to the
3278 -- specified (relative or absolute) path.
3279 -- This is for the benefit of tools that recover from
3280 -- errors; for example, these tools could create the
3281 -- non existent directory.
3283 Data.Display_Object_Dir := Object_Dir.Value;
3284 Get_Name_String (Object_Dir.Value);
3285 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3286 Data.Object_Directory := Name_Find;
3292 if Current_Verbosity = High then
3293 if Data.Object_Directory = No_Name then
3294 Write_Line ("No object directory");
3296 Write_Str ("Object directory: """);
3297 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3302 -- Check the exec directory
3305 Exec_Dir : constant Variable_Value :=
3306 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3309 pragma Assert (Exec_Dir.Kind = Single,
3310 "Exec_Dir is not a single string");
3312 -- We set the object directory to its default
3314 Data.Exec_Directory := Data.Object_Directory;
3315 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3317 if Exec_Dir.Value /= Empty_String then
3319 Get_Name_String (Exec_Dir.Value);
3321 if Name_Len = 0 then
3324 "Exec_Dir cannot be empty",
3328 -- We check that the specified object directory
3332 (Exec_Dir.Value, Data.Directory,
3333 Data.Exec_Directory, Data.Display_Exec_Dir);
3335 if Data.Exec_Directory = No_Name then
3336 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3339 "the exec directory { cannot be found",
3346 if Current_Verbosity = High then
3347 if Data.Exec_Directory = No_Name then
3348 Write_Line ("No exec directory");
3350 Write_Str ("Exec directory: """);
3351 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3356 -- Look for the source directories
3359 Source_Dirs : constant Variable_Value :=
3361 (Name_Source_Dirs, Data.Decl.Attributes);
3364 if Current_Verbosity = High then
3365 Write_Line ("Starting to look for source directories");
3368 pragma Assert (Source_Dirs.Kind = List,
3369 "Source_Dirs is not a list");
3371 if Source_Dirs.Default then
3373 -- No Source_Dirs specified: the single source directory
3374 -- is the one containing the project file
3376 String_Elements.Increment_Last;
3377 Data.Source_Dirs := String_Elements.Last;
3378 String_Elements.Table (Data.Source_Dirs) :=
3379 (Value => Data.Directory,
3380 Display_Value => Data.Display_Directory,
3381 Location => No_Location,
3383 Next => Nil_String);
3385 if Current_Verbosity = High then
3386 Write_Line ("Single source directory:");
3388 Write_Str (Get_Name_String (Data.Display_Directory));
3392 elsif Source_Dirs.Values = Nil_String then
3394 -- If Source_Dirs is an empty string list, this means
3395 -- that this project contains no source. For projects that
3396 -- don't extend other projects, this also means that there is no
3397 -- need for an object directory, if not specified.
3399 if Data.Extends = No_Project
3400 and then Data.Object_Directory = Data.Directory
3402 Data.Object_Directory := No_Name;
3405 Data.Source_Dirs := Nil_String;
3406 Data.Sources_Present := False;
3410 Source_Dir : String_List_Id := Source_Dirs.Values;
3411 Element : String_Element;
3414 -- We will find the source directories for each
3415 -- element of the list
3417 while Source_Dir /= Nil_String loop
3418 Element := String_Elements.Table (Source_Dir);
3419 Find_Source_Dirs (Element.Value, Element.Location);
3420 Source_Dir := Element.Next;
3425 if Current_Verbosity = High then
3426 Write_Line ("Putting source directories in canonical cases");
3430 Current : String_List_Id := Data.Source_Dirs;
3431 Element : String_Element;
3434 while Current /= Nil_String loop
3435 Element := String_Elements.Table (Current);
3436 if Element.Value /= No_Name then
3437 Get_Name_String (Element.Value);
3438 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3439 Element.Value := Name_Find;
3440 String_Elements.Table (Current) := Element;
3443 Current := Element.Next;
3448 -- Library attributes
3451 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3453 Lib_Dir : constant Prj.Variable_Value :=
3454 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3456 Lib_Name : constant Prj.Variable_Value :=
3457 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3459 Lib_Version : constant Prj.Variable_Value :=
3461 (Snames.Name_Library_Version, Attributes);
3463 The_Lib_Kind : constant Prj.Variable_Value :=
3465 (Snames.Name_Library_Kind, Attributes);
3468 -- Special case of extending project
3470 if Data.Extends /= No_Project then
3472 Extended_Data : constant Project_Data :=
3473 Projects.Table (Data.Extends);
3476 -- If the project extended is a library project, we inherit
3477 -- the library name, if it is not redefined; we check that
3478 -- the library directory is specified; and we reset the
3479 -- library flag for the extended project.
3481 if Extended_Data.Library then
3482 if Lib_Name.Default then
3483 Data.Library_Name := Extended_Data.Library_Name;
3486 if Lib_Dir.Default then
3488 -- If the extending project is a virtual project, we
3489 -- put the error message in the library project that
3490 -- is extended, rather than in the extending all project.
3491 -- Of course, we cannot put it in the virtual extending
3492 -- project, because it has no source.
3494 if Data.Virtual then
3495 Error_Msg_Name_1 := Extended_Data.Name;
3499 "library project % cannot be virtually extended",
3500 Extended_Data.Location);
3505 "a project extending a library project must " &
3506 "specify an attribute Library_Dir",
3511 Projects.Table (Data.Extends).Library := False;
3516 pragma Assert (Lib_Dir.Kind = Single);
3518 if Lib_Dir.Value = Empty_String then
3520 if Current_Verbosity = High then
3521 Write_Line ("No library directory");
3525 -- Find path name, check that it is a directory
3528 (Lib_Dir.Value, Data.Display_Directory,
3529 Data.Library_Dir, Data.Display_Library_Dir);
3531 if Data.Library_Dir = No_Name then
3533 -- Get the absolute name of the library directory that
3534 -- does not exist, to report an error.
3537 Dir_Name : constant String :=
3538 Get_Name_String (Lib_Dir.Value);
3540 if Is_Absolute_Path (Dir_Name) then
3541 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3544 Get_Name_String (Data.Display_Directory);
3546 if Name_Buffer (Name_Len) /= Directory_Separator then
3547 Name_Len := Name_Len + 1;
3548 Name_Buffer (Name_Len) := Directory_Separator;
3552 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3554 Name_Len := Name_Len + Dir_Name'Length;
3555 Err_Vars.Error_Msg_Name_1 := Name_Find;
3562 "library directory { does not exist",
3566 elsif Data.Library_Dir = Data.Object_Directory then
3569 "library directory cannot be the same " &
3570 "as object directory",
3572 Data.Library_Dir := No_Name;
3573 Data.Display_Library_Dir := No_Name;
3576 if Current_Verbosity = High then
3577 Write_Str ("Library directory =""");
3578 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3584 pragma Assert (Lib_Name.Kind = Single);
3586 if Lib_Name.Value = Empty_String then
3587 if Current_Verbosity = High
3588 and then Data.Library_Name = No_Name
3590 Write_Line ("No library name");
3594 -- There is no restriction on the syntax of library names
3596 Data.Library_Name := Lib_Name.Value;
3599 if Data.Library_Name /= No_Name
3600 and then Current_Verbosity = High
3602 Write_Str ("Library name = """);
3603 Write_Str (Get_Name_String (Data.Library_Name));
3608 Data.Library_Dir /= No_Name
3610 Data.Library_Name /= No_Name;
3612 if Data.Library then
3613 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3616 "?libraries are not supported on this platform",
3618 Data.Library := False;
3621 pragma Assert (Lib_Version.Kind = Single);
3623 if Lib_Version.Value = Empty_String then
3624 if Current_Verbosity = High then
3625 Write_Line ("No library version specified");
3629 Data.Lib_Internal_Name := Lib_Version.Value;
3632 pragma Assert (The_Lib_Kind.Kind = Single);
3634 if The_Lib_Kind.Value = Empty_String then
3635 if Current_Verbosity = High then
3636 Write_Line ("No library kind specified");
3640 Get_Name_String (The_Lib_Kind.Value);
3643 Kind_Name : constant String :=
3644 To_Lower (Name_Buffer (1 .. Name_Len));
3646 OK : Boolean := True;
3649 if Kind_Name = "static" then
3650 Data.Library_Kind := Static;
3652 elsif Kind_Name = "dynamic" then
3653 Data.Library_Kind := Dynamic;
3655 elsif Kind_Name = "relocatable" then
3656 Data.Library_Kind := Relocatable;
3661 "illegal value for Library_Kind",
3662 The_Lib_Kind.Location);
3666 if Current_Verbosity = High and then OK then
3667 Write_Str ("Library kind = ");
3668 Write_Line (Kind_Name);
3671 if Data.Library_Kind /= Static and then
3672 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3676 "only static libraries are supported " &
3678 The_Lib_Kind.Location);
3679 Data.Library := False;
3684 if Data.Library and then Current_Verbosity = High then
3685 Write_Line ("This is a library project file");
3692 if Current_Verbosity = High then
3693 Show_Source_Dirs (Project);
3697 Naming_Id : constant Package_Id :=
3698 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3700 Naming : Package_Element;
3703 -- If there is a package Naming, we will put in Data.Naming
3704 -- what is in this package Naming.
3706 if Naming_Id /= No_Package then
3707 Naming := Packages.Table (Naming_Id);
3709 if Current_Verbosity = High then
3710 Write_Line ("Checking ""Naming"".");
3713 -- Check Spec_Suffix
3716 Spec_Suffixs : Array_Element_Id :=
3719 Naming.Decl.Arrays);
3720 Suffix : Array_Element_Id;
3721 Element : Array_Element;
3722 Suffix2 : Array_Element_Id;
3725 -- If some suffixs have been specified, we make sure that
3726 -- for each language for which a default suffix has been
3727 -- specified, there is a suffix specified, either the one
3728 -- in the project file or if there were none, the default.
3730 if Spec_Suffixs /= No_Array_Element then
3731 Suffix := Data.Naming.Spec_Suffix;
3733 while Suffix /= No_Array_Element loop
3734 Element := Array_Elements.Table (Suffix);
3735 Suffix2 := Spec_Suffixs;
3737 while Suffix2 /= No_Array_Element loop
3738 exit when Array_Elements.Table (Suffix2).Index =
3740 Suffix2 := Array_Elements.Table (Suffix2).Next;
3743 -- There is a registered default suffix, but no
3744 -- suffix specified in the project file.
3745 -- Add the default to the array.
3747 if Suffix2 = No_Array_Element then
3748 Array_Elements.Increment_Last;
3749 Array_Elements.Table (Array_Elements.Last) :=
3750 (Index => Element.Index,
3751 Index_Case_Sensitive => False,
3752 Value => Element.Value,
3753 Next => Spec_Suffixs);
3754 Spec_Suffixs := Array_Elements.Last;
3757 Suffix := Element.Next;
3760 -- Put the resulting array as the specification suffixs
3762 Data.Naming.Spec_Suffix := Spec_Suffixs;
3767 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3768 Element : Array_Element;
3771 while Current /= No_Array_Element loop
3772 Element := Array_Elements.Table (Current);
3773 Get_Name_String (Element.Value.Value);
3775 if Name_Len = 0 then
3778 "Spec_Suffix cannot be empty",
3779 Element.Value.Location);
3782 Array_Elements.Table (Current) := Element;
3783 Current := Element.Next;
3787 -- Check Body_Suffix
3790 Impl_Suffixs : Array_Element_Id :=
3793 Naming.Decl.Arrays);
3795 Suffix : Array_Element_Id;
3796 Element : Array_Element;
3797 Suffix2 : Array_Element_Id;
3800 -- If some suffixs have been specified, we make sure that
3801 -- for each language for which a default suffix has been
3802 -- specified, there is a suffix specified, either the one
3803 -- in the project file or if there were noe, the default.
3805 if Impl_Suffixs /= No_Array_Element then
3806 Suffix := Data.Naming.Body_Suffix;
3808 while Suffix /= No_Array_Element loop
3809 Element := Array_Elements.Table (Suffix);
3810 Suffix2 := Impl_Suffixs;
3812 while Suffix2 /= No_Array_Element loop
3813 exit when Array_Elements.Table (Suffix2).Index =
3815 Suffix2 := Array_Elements.Table (Suffix2).Next;
3818 -- There is a registered default suffix, but no
3819 -- suffix specified in the project file.
3820 -- Add the default to the array.
3822 if Suffix2 = No_Array_Element then
3823 Array_Elements.Increment_Last;
3824 Array_Elements.Table (Array_Elements.Last) :=
3825 (Index => Element.Index,
3826 Index_Case_Sensitive => False,
3827 Value => Element.Value,
3828 Next => Impl_Suffixs);
3829 Impl_Suffixs := Array_Elements.Last;
3832 Suffix := Element.Next;
3835 -- Put the resulting array as the implementation suffixs
3837 Data.Naming.Body_Suffix := Impl_Suffixs;
3842 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3843 Element : Array_Element;
3846 while Current /= No_Array_Element loop
3847 Element := Array_Elements.Table (Current);
3848 Get_Name_String (Element.Value.Value);
3850 if Name_Len = 0 then
3853 "Body_Suffix cannot be empty",
3854 Element.Value.Location);
3857 Array_Elements.Table (Current) := Element;
3858 Current := Element.Next;
3862 -- Get the exceptions, if any
3864 Data.Naming.Specification_Exceptions :=
3866 (Name_Specification_Exceptions,
3867 In_Arrays => Naming.Decl.Arrays);
3869 Data.Naming.Implementation_Exceptions :=
3871 (Name_Implementation_Exceptions,
3872 In_Arrays => Naming.Decl.Arrays);
3876 Projects.Table (Project) := Data;
3877 end Language_Independent_Check;
3879 ----------------------
3880 -- Locate_Directory --
3881 ----------------------
3883 procedure Locate_Directory
3887 Display : out Name_Id)
3889 The_Name : constant String := Get_Name_String (Name);
3890 The_Parent : constant String :=
3891 Get_Name_String (Parent) & Directory_Separator;
3892 The_Parent_Last : constant Natural :=
3893 Compute_Directory_Last (The_Parent);
3896 if Current_Verbosity = High then
3897 Write_Str ("Locate_Directory (""");
3898 Write_Str (The_Name);
3899 Write_Str (""", """);
3900 Write_Str (The_Parent);
3907 if Is_Absolute_Path (The_Name) then
3908 if Is_Directory (The_Name) then
3910 Normed : constant String :=
3913 Resolve_Links => False,
3914 Case_Sensitive => True);
3916 Canonical_Path : constant String :=
3919 Resolve_Links => True,
3920 Case_Sensitive => False);
3923 Name_Len := Normed'Length;
3924 Name_Buffer (1 .. Name_Len) := Normed;
3925 Display := Name_Find;
3927 Name_Len := Canonical_Path'Length;
3928 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3935 Full_Path : constant String :=
3936 The_Parent (The_Parent'First .. The_Parent_Last) &
3940 if Is_Directory (Full_Path) then
3942 Normed : constant String :=
3945 Resolve_Links => False,
3946 Case_Sensitive => True);
3948 Canonical_Path : constant String :=
3951 Resolve_Links => True,
3952 Case_Sensitive => False);
3955 Name_Len := Normed'Length;
3956 Name_Buffer (1 .. Name_Len) := Normed;
3957 Display := Name_Find;
3959 Name_Len := Canonical_Path'Length;
3960 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3966 end Locate_Directory;
3968 ---------------------------
3969 -- Other_Languages_Check --
3970 ---------------------------
3972 procedure Other_Languages_Check
3973 (Project : Project_Id;
3974 Report_Error : Put_Line_Access) is
3976 Data : Project_Data;
3978 Languages : Variable_Value := Nil_Variable_Value;
3981 Language_Independent_Check (Project, Report_Error);
3983 Error_Report := Report_Error;
3985 Data := Projects.Table (Project);
3986 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
3988 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
3990 if Data.Sources_Present then
3991 -- Check if languages other than Ada are specified in this project
3993 if Languages.Default then
3994 -- Attribute Languages is not specified. So, it defaults to
3995 -- a project of language Ada only.
3997 Data.Languages (Lang_Ada) := True;
3999 -- No sources of languages other than Ada
4001 Data.Sources_Present := False;
4005 Current : String_List_Id := Languages.Values;
4006 Element : String_Element;
4007 OK : Boolean := False;
4009 -- Assumethat there is no language other than Ada specified.
4010 -- If in fact there is at least one, we will set back
4011 -- Sources_Present to True.
4013 Data.Sources_Present := False;
4015 -- Look through all the languages specified in attribute
4016 -- Languages, if any
4018 while Current /= Nil_String loop
4019 Element := String_Elements.Table (Current);
4020 Get_Name_String (Element.Value);
4021 To_Lower (Name_Buffer (1 .. Name_Len));
4024 -- Check if it is a known language
4026 Lang_Loop : for Lang in Programming_Language loop
4028 Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4030 -- Yes, this is a known language
4034 -- Indicate the presence of this language
4035 Data.Languages (Lang) := True;
4037 -- If it is a language other than Ada, indicate that
4038 -- there should be some sources of a language other
4041 if Lang /= Lang_Ada then
4042 Data.Sources_Present := True;
4049 -- We don't support this language: report an error
4052 Error_Msg_Name_1 := Element.Value;
4055 "unknown programming language {",
4059 Current := Element.Next;
4065 -- If there may be some sources, look for them
4067 if Data.Sources_Present then
4068 -- Set Source_Present to False. It will be set back to True whenever
4069 -- a source is found.
4071 Data.Sources_Present := False;
4073 for Lang in Other_Programming_Language loop
4074 -- For each language (other than Ada) in the project file
4076 if Data.Languages (Lang) then
4077 -- Reset the indication that there are sources of this
4078 -- language. It will be set back to True whenever we find a
4079 -- source of the language.
4081 Data.Languages (Lang) := False;
4083 -- First, get the source suffix for the language
4085 Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4087 -- Then, deal with the naming exceptions, if any
4092 Naming_Exceptions : constant Variable_Value :=
4094 (Index => Lang_Name_Ids (Lang),
4095 In_Array => Data.Naming.Implementation_Exceptions);
4096 Element_Id : String_List_Id;
4097 Element : String_Element;
4099 Source_Found : Boolean := False;
4101 -- If there are naming exceptions, look through them one
4104 if Naming_Exceptions /= Nil_Variable_Value then
4105 Element_Id := Naming_Exceptions.Values;
4107 while Element_Id /= Nil_String loop
4108 Element := String_Elements.Table (Element_Id);
4109 Get_Name_String (Element.Value);
4110 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4111 File_Id := Name_Find;
4113 -- Put each naming exception in the Source_Names
4114 -- hash table, but if there are repetition, don't
4115 -- bother after the first instance.
4117 if Source_Names.Get (File_Id) = No_Name_Location then
4118 Source_Found := True;
4122 Location => Element.Location,
4126 Element_Id := Element.Next;
4129 -- If there is at least one naming exception, record
4130 -- those that are found in the source directories.
4132 if Source_Found then
4133 Record_Other_Sources
4134 (Project => Project,
4137 Naming_Exceptions => True);
4143 -- Now, check if a list of sources is declared either through
4144 -- a string list (attribute Source_Files) or a text file
4145 -- (attribute Source_List_File).
4146 -- If a source list is declared, we will consider only those
4147 -- naming exceptions that are on the list.
4150 Sources : constant Variable_Value :=
4153 Data.Decl.Attributes);
4155 Source_List_File : constant Variable_Value :=
4157 (Name_Source_List_File,
4158 Data.Decl.Attributes);
4162 (Sources.Kind = List,
4163 "Source_Files is not a list");
4166 (Source_List_File.Kind = Single,
4167 "Source_List_File is not a single string");
4169 if not Sources.Default then
4170 if not Source_List_File.Default then
4173 "?both variables source_files and " &
4174 "source_list_file are present",
4175 Source_List_File.Location);
4178 -- Sources is a list of file names
4181 Current : String_List_Id := Sources.Values;
4182 Element : String_Element;
4183 Location : Source_Ptr;
4189 -- Put all the sources in the Source_Names hash
4192 while Current /= Nil_String loop
4193 Element := String_Elements.Table (Current);
4194 Get_Name_String (Element.Value);
4195 Canonical_Case_File_Name
4196 (Name_Buffer (1 .. Name_Len));
4199 -- If the element has no location, then use the
4200 -- location of Sources to report possible errors.
4202 if Element.Location = No_Location then
4203 Location := Sources.Location;
4206 Location := Element.Location;
4213 Location => Location,
4216 Current := Element.Next;
4219 -- And look for their directories
4221 Record_Other_Sources
4222 (Project => Project,
4225 Naming_Exceptions => False);
4228 -- No source_files specified.
4229 -- We check if Source_List_File has been specified.
4231 elsif not Source_List_File.Default then
4233 -- Source_List_File is the name of the file
4234 -- that contains the source file names
4237 Source_File_Path_Name : constant String :=
4239 (Source_List_File.Value,
4243 if Source_File_Path_Name'Length = 0 then
4244 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4247 "file with sources { does not exist",
4248 Source_List_File.Location);
4251 -- Read the file, putting each source in the
4252 -- Source_Names hash table.
4254 Get_Sources_From_File
4255 (Source_File_Path_Name,
4256 Source_List_File.Location,
4259 -- And look for their directories.
4261 Record_Other_Sources
4262 (Project => Project,
4265 Naming_Exceptions => False);
4270 -- Neither Source_Files nor Source_List_File has been
4271 -- specified. Find all the files that satisfy
4272 -- the naming scheme in all the source directories.
4273 -- All the naming exceptions that effectively exist are
4274 -- also part of the source of this language.
4276 Find_Sources (Project, Data, Lang);
4284 -- Finally, get the mains, if any
4286 Get_Mains (Project, Data);
4288 Projects.Table (Project) := Data;
4290 end Other_Languages_Check;
4296 function Path_Name_Of
4297 (File_Name : Name_Id;
4298 Directory : Name_Id) return String
4300 Result : String_Access;
4301 The_Directory : constant String := Get_Name_String (Directory);
4304 Get_Name_String (File_Name);
4305 Result := Locate_Regular_File
4306 (File_Name => Name_Buffer (1 .. Name_Len),
4307 Path => The_Directory);
4309 if Result = null then
4312 Canonical_Case_File_Name (Result.all);
4317 -------------------------------
4318 -- Prepare_Ada_Naming_Exceptions --
4319 -------------------------------
4321 procedure Prepare_Ada_Naming_Exceptions
4322 (List : Array_Element_Id;
4323 Kind : Spec_Or_Body)
4325 Current : Array_Element_Id := List;
4326 Element : Array_Element;
4329 -- Traverse the list
4331 while Current /= No_Array_Element loop
4332 Element := Array_Elements.Table (Current);
4334 if Element.Index /= No_Name then
4335 Ada_Naming_Exceptions.Set
4336 (Element.Value.Value,
4337 (Kind => Kind, Unit => Element.Index));
4338 Reverse_Ada_Naming_Exceptions.Set
4339 ((Kind => Kind, Unit => Element.Index),
4340 Element.Value.Value);
4343 Current := Element.Next;
4345 end Prepare_Ada_Naming_Exceptions;
4347 ---------------------
4348 -- Project_Extends --
4349 ---------------------
4351 function Project_Extends
4352 (Extending : Project_Id;
4353 Extended : Project_Id) return Boolean
4355 Current : Project_Id := Extending;
4358 if Current = No_Project then
4361 elsif Current = Extended then
4365 Current := Projects.Table (Current).Extends;
4367 end Project_Extends;
4369 -----------------------
4370 -- Record_Ada_Source --
4371 -----------------------
4373 procedure Record_Ada_Source
4374 (File_Name : Name_Id;
4375 Path_Name : Name_Id;
4376 Project : Project_Id;
4377 Data : in out Project_Data;
4378 Location : Source_Ptr;
4379 Current_Source : in out String_List_Id;
4380 Source_Recorded : in out Boolean;
4381 Follow_Links : Boolean)
4383 Canonical_File_Name : Name_Id;
4384 Canonical_Path_Name : Name_Id;
4385 Unit_Name : Name_Id;
4386 Unit_Kind : Spec_Or_Body;
4387 Needs_Pragma : Boolean;
4389 The_Location : Source_Ptr := Location;
4390 Previous_Source : constant String_List_Id := Current_Source;
4391 Except_Name : Name_Id := No_Name;
4393 Unit_Prj : Unit_Project;
4396 Get_Name_String (File_Name);
4397 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4398 Canonical_File_Name := Name_Find;
4401 Canonical_Path : constant String :=
4403 (Get_Name_String (Path_Name),
4404 Resolve_Links => Follow_Links,
4405 Case_Sensitive => False);
4408 Add_Str_To_Name_Buffer (Canonical_Path);
4409 Canonical_Path_Name := Name_Find;
4412 -- Find out the unit name, the unit kind and if it needs
4413 -- a specific SFN pragma.
4416 (Canonical_File_Name => Canonical_File_Name,
4417 Naming => Data.Naming,
4418 Unit_Name => Unit_Name,
4419 Unit_Kind => Unit_Kind,
4420 Needs_Pragma => Needs_Pragma);
4422 if Unit_Name = No_Name then
4423 if Current_Verbosity = High then
4425 Write_Str (Get_Name_String (Canonical_File_Name));
4426 Write_Line (""" is not a valid source file name (ignored).");
4430 -- Check to see if the source has been hidden by an exception,
4431 -- but only if it is not an exception.
4433 if not Needs_Pragma then
4435 Reverse_Ada_Naming_Exceptions.Get ((Unit_Kind, Unit_Name));
4437 if Except_Name /= No_Name then
4438 if Current_Verbosity = High then
4440 Write_Str (Get_Name_String (Canonical_File_Name));
4441 Write_Str (""" contains a unit that is found in """);
4442 Write_Str (Get_Name_String (Except_Name));
4443 Write_Line (""" (ignored).");
4446 -- The file is not included in the source of the project,
4447 -- because it is hidden by the exception.
4448 -- So, there is nothing else to do.
4454 -- Put the file name in the list of sources of the project
4456 String_Elements.Increment_Last;
4457 String_Elements.Table (String_Elements.Last) :=
4458 (Value => Canonical_File_Name,
4459 Display_Value => File_Name,
4460 Location => No_Location,
4462 Next => Nil_String);
4464 if Current_Source = Nil_String then
4465 Data.Sources := String_Elements.Last;
4468 String_Elements.Table (Current_Source).Next :=
4469 String_Elements.Last;
4472 Current_Source := String_Elements.Last;
4474 -- Put the unit in unit list
4477 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4478 The_Unit_Data : Unit_Data;
4481 if Current_Verbosity = High then
4482 Write_Str ("Putting ");
4483 Write_Str (Get_Name_String (Unit_Name));
4484 Write_Line (" in the unit list.");
4487 -- The unit is already in the list, but may be it is
4488 -- only the other unit kind (spec or body), or what is
4489 -- in the unit list is a unit of a project we are extending.
4491 if The_Unit /= Prj.Com.No_Unit then
4492 The_Unit_Data := Units.Table (The_Unit);
4494 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4495 or else Project_Extends
4497 The_Unit_Data.File_Names (Unit_Kind).Project)
4499 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4500 Remove_Forbidden_File_Name
4501 (The_Unit_Data.File_Names (Unit_Kind).Name);
4504 -- Record the file name in the hash table Files_Htable
4506 Unit_Prj := (Unit => The_Unit, Project => Project);
4507 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4509 The_Unit_Data.File_Names (Unit_Kind) :=
4510 (Name => Canonical_File_Name,
4511 Display_Name => File_Name,
4512 Path => Canonical_Path_Name,
4513 Display_Path => Path_Name,
4515 Needs_Pragma => Needs_Pragma);
4516 Units.Table (The_Unit) := The_Unit_Data;
4517 Source_Recorded := True;
4519 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4520 and then (Data.Known_Order_Of_Source_Dirs or else
4521 The_Unit_Data.File_Names (Unit_Kind).Path =
4522 Canonical_Path_Name)
4524 if Previous_Source = Nil_String then
4525 Data.Sources := Nil_String;
4527 String_Elements.Table (Previous_Source).Next :=
4529 String_Elements.Decrement_Last;
4532 Current_Source := Previous_Source;
4535 -- It is an error to have two units with the same name
4536 -- and the same kind (spec or body).
4538 if The_Location = No_Location then
4539 The_Location := Projects.Table (Project).Location;
4542 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4543 Error_Msg (Project, "duplicate source {", The_Location);
4545 Err_Vars.Error_Msg_Name_1 :=
4547 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4548 Err_Vars.Error_Msg_Name_2 :=
4549 The_Unit_Data.File_Names (Unit_Kind).Path;
4550 Error_Msg (Project, "\ project file {, {", The_Location);
4552 Err_Vars.Error_Msg_Name_1 := Projects.Table (Project).Name;
4553 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4554 Error_Msg (Project, "\ project file {, {", The_Location);
4558 -- It is a new unit, create a new record
4561 -- First, check if there is no other unit with this file name
4562 -- in another project. If it is, report an error.
4564 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4566 if Unit_Prj /= No_Unit_Project then
4567 Error_Msg_Name_1 := File_Name;
4568 Error_Msg_Name_2 := Projects.Table (Unit_Prj.Project).Name;
4571 "{ is already a source of project {",
4575 Units.Increment_Last;
4576 The_Unit := Units.Last;
4577 Units_Htable.Set (Unit_Name, The_Unit);
4578 Unit_Prj := (Unit => The_Unit, Project => Project);
4579 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4580 The_Unit_Data.Name := Unit_Name;
4581 The_Unit_Data.File_Names (Unit_Kind) :=
4582 (Name => Canonical_File_Name,
4583 Display_Name => File_Name,
4584 Path => Canonical_Path_Name,
4585 Display_Path => Path_Name,
4587 Needs_Pragma => Needs_Pragma);
4588 Units.Table (The_Unit) := The_Unit_Data;
4589 Source_Recorded := True;
4594 end Record_Ada_Source;
4596 --------------------------
4597 -- Record_Other_Sources --
4598 --------------------------
4600 procedure Record_Other_Sources
4601 (Project : Project_Id;
4602 Data : in out Project_Data;
4603 Language : Programming_Language;
4604 Naming_Exceptions : Boolean)
4606 Source_Dir : String_List_Id := Data.Source_Dirs;
4607 Element : String_Element;
4611 Canonical_Name : Name_Id;
4612 Name_Str : String (1 .. 1_024);
4613 Last : Natural := 0;
4616 First_Error : Boolean := True;
4618 Suffix : constant String :=
4619 Get_Name_String (Data.Impl_Suffixes (Language));
4622 while Source_Dir /= Nil_String loop
4623 Element := String_Elements.Table (Source_Dir);
4626 Dir_Path : constant String := Get_Name_String (Element.Value);
4628 if Current_Verbosity = High then
4629 Write_Str ("checking directory """);
4630 Write_Str (Dir_Path);
4631 Write_Str (""" for ");
4633 if Naming_Exceptions then
4634 Write_Str ("naming exceptions");
4637 Write_Str ("sources");
4640 Write_Str (" of Language ");
4641 Write_Line (Lang_Display_Names (Language).all);
4644 Open (Dir, Dir_Path);
4647 Read (Dir, Name_Str, Last);
4651 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4654 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4655 Canonical_Name := Name_Find;
4656 NL := Source_Names.Get (Canonical_Name);
4658 if NL /= No_Name_Location then
4660 if not Data.Known_Order_Of_Source_Dirs then
4661 Error_Msg_Name_1 := Canonical_Name;
4664 "{ is found in several source directories",
4670 Source_Names.Set (Canonical_Name, NL);
4671 Name_Len := Dir_Path'Length;
4672 Name_Buffer (1 .. Name_Len) := Dir_Path;
4673 Add_Char_To_Name_Buffer (Directory_Separator);
4674 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4678 (File_Name => Canonical_Name,
4682 Location => NL.Location,
4683 Language => Language,
4685 Naming_Exception => Naming_Exceptions);
4694 Source_Dir := Element.Next;
4697 if not Naming_Exceptions then
4699 NL := Source_Names.Get_First;
4701 -- It is an error if a source file name in a source list or
4702 -- in a source list file is not found.
4704 while NL /= No_Name_Location loop
4705 if not NL.Found then
4706 Err_Vars.Error_Msg_Name_1 := NL.Name;
4711 "source file { cannot be found",
4713 First_Error := False;
4718 "\source file { cannot be found",
4723 NL := Source_Names.Get_Next;
4726 -- Any naming exception of this language that is not in a list
4727 -- of sources must be removed.
4730 Source_Id : Other_Source_Id := Data.First_Other_Source;
4731 Prev_Id : Other_Source_Id := No_Other_Source;
4732 Source : Other_Source;
4734 while Source_Id /= No_Other_Source loop
4735 Source := Other_Sources.Table (Source_Id);
4737 if Source.Language = Language
4738 and then Source.Naming_Exception
4740 if Current_Verbosity = High then
4741 Write_Str ("Naming exception """);
4742 Write_Str (Get_Name_String (Source.File_Name));
4743 Write_Str (""" is not in the list of sources,");
4744 Write_Line (" so it is removed.");
4747 if Prev_Id = No_Other_Source then
4748 Data.First_Other_Source := Source.Next;
4751 Other_Sources.Table (Prev_Id).Next := Source.Next;
4754 Source_Id := Source.Next;
4756 if Source_Id = No_Other_Source then
4757 Data.Last_Other_Source := Prev_Id;
4761 Prev_Id := Source_Id;
4762 Source_Id := Source.Next;
4767 end Record_Other_Sources;
4769 ----------------------
4770 -- Show_Source_Dirs --
4771 ----------------------
4773 procedure Show_Source_Dirs (Project : Project_Id) is
4774 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4775 Element : String_Element;
4778 Write_Line ("Source_Dirs:");
4780 while Current /= Nil_String loop
4781 Element := String_Elements.Table (Current);
4783 Write_Line (Get_Name_String (Element.Value));
4784 Current := Element.Next;
4787 Write_Line ("end Source_Dirs.");
4788 end Show_Source_Dirs;
4795 (Language : Programming_Language;
4796 Naming : Naming_Data) return Name_Id
4798 Suffix : constant Variable_Value :=
4800 (Index => Lang_Name_Ids (Language),
4801 In_Array => Naming.Body_Suffix);
4803 -- If no suffix for this language is found in package Naming, use the
4806 if Suffix = Nil_Variable_Value then
4808 Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4810 -- Otherwise use the one specified
4813 Get_Name_String (Suffix.Value);
4816 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));