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 Table; use Table;
42 with Types; use Types;
44 with Ada.Characters.Handling; use Ada.Characters.Handling;
45 with Ada.Strings; use Ada.Strings;
46 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
47 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
49 with GNAT.Case_Util; use GNAT.Case_Util;
50 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
51 with GNAT.OS_Lib; use GNAT.OS_Lib;
54 package body Prj.Nmsc is
56 Error_Report : Put_Line_Access := null;
57 -- Set to point to error reporting procedure
59 ALI_Suffix : constant String := ".ali";
60 -- File suffix for ali files
62 Object_Suffix : constant String := Get_Object_Suffix.all;
63 -- File suffix for object files
65 type Name_Location is record
67 Location : Source_Ptr;
68 Found : Boolean := False;
70 -- Information about file names found in string list attribute
71 -- Source_Files or in a source list file, stored in hash table
72 -- Source_Names, used by procedure
73 -- Ada_Check.Get_Path_Names_And_Record_Sources.
75 No_Name_Location : constant Name_Location :=
76 (Name => No_Name, Location => No_Location, Found => False);
78 package Source_Names is new GNAT.HTable.Simple_HTable
79 (Header_Num => Header_Num,
80 Element => Name_Location,
81 No_Element => No_Name_Location,
85 -- Hash table to store file names found in string list attribute
86 -- Source_Files or in a source list file, stored in hash table
87 -- Source_Names, used by procedure
88 -- Ada_Check.Get_Path_Names_And_Record_Sources.
90 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
91 (Header_Num => Header_Num,
97 -- Hash table to store recursive source directories, to avoid looking
98 -- several times, and to avoid cycles that may be introduced by symbolic
101 type Ada_Naming_Exception_Id is new Nat;
102 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
104 type Unit_Info is record
107 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
109 -- No_Unit : constant Unit_Info :=
110 -- (Specification, No_Name, No_Ada_Naming_Exception);
112 package Ada_Naming_Exception_Table is new Table.Table
113 (Table_Component_Type => Unit_Info,
114 Table_Index_Type => Ada_Naming_Exception_Id,
115 Table_Low_Bound => 1,
117 Table_Increment => 100,
118 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
120 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
121 (Header_Num => Header_Num,
122 Element => Ada_Naming_Exception_Id,
123 No_Element => No_Ada_Naming_Exception,
127 -- A hash table to store naming exceptions for Ada. For each file name
128 -- there is one or several unit in table Ada_Naming_Exception_Table.
130 function Hash (Unit : Unit_Info) return Header_Num;
132 type Name_And_Index is record
133 Name : Name_Id := No_Name;
136 No_Name_And_Index : constant Name_And_Index :=
137 (Name => No_Name, Index => 0);
139 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
140 (Header_Num => Header_Num,
141 Element => Name_And_Index,
142 No_Element => No_Name_And_Index,
146 -- A table to check if a unit with an exceptional name will hide
147 -- a source with a file name following the naming convention.
149 function ALI_File_Name (Source : String) return String;
150 -- Return the ALI file name corresponding to a source.
152 procedure Check_Ada_Naming_Scheme
153 (Project : Project_Id;
154 Naming : Naming_Data);
155 -- Check that the package Naming is correct.
157 procedure Check_Ada_Name
160 -- Check that a name is a valid Ada unit name.
162 procedure Check_For_Source
163 (File_Name : Name_Id;
165 Project : Project_Id;
166 Data : in out Project_Data;
167 Location : Source_Ptr;
168 Language : Other_Programming_Language;
170 Naming_Exception : Boolean);
171 -- Check if a file in a source directory is a source for a specific
172 -- language other than Ada.
174 procedure Check_Naming_Scheme
175 (Data : in out Project_Data;
176 Project : Project_Id);
177 -- Check the naming scheme part of Data
179 function Check_Project
181 Root_Project : Project_Id;
182 Extending : Boolean) return Boolean;
183 -- Returns True if P is Root_Project or, if Extending is True, a project
184 -- extended by Root_Project.
186 function Compute_Directory_Last (Dir : String) return Natural;
187 -- Return the index of the last significant character in Dir. This is used
188 -- to avoid duplicates '/' at the end of directory names
191 (Project : Project_Id;
193 Flag_Location : Source_Ptr);
194 -- Output an error message. If Error_Report is null, simply call
195 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
198 procedure Find_Sources
199 (Project : Project_Id;
200 Data : in out Project_Data;
201 For_Language : Programming_Language;
202 Follow_Links : Boolean := False);
203 -- Find all the sources in all of the source directories of a project for
204 -- a specified language.
206 procedure Free_Ada_Naming_Exceptions;
207 -- Free the internal hash tables used for checking naming exceptions
209 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
210 -- Get the mains of a project from attribute Main, if it exists, and put
211 -- them in the project data.
213 procedure Get_Sources_From_File
215 Location : Source_Ptr;
216 Project : Project_Id);
217 -- Get the list of sources from a text file and put them in hash table
221 (Canonical_File_Name : Name_Id;
222 Naming : Naming_Data;
223 Exception_Id : out Ada_Naming_Exception_Id;
224 Unit_Name : out Name_Id;
225 Unit_Kind : out Spec_Or_Body;
226 Needs_Pragma : out Boolean);
227 -- Find out, from a file name, the unit name, the unit kind and if a
228 -- specific SFN pragma is needed. If the file name corresponds to no
229 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
230 -- or an exception to the naming scheme, then Exception_Id is set to
231 -- the unit or units that the source contains.
233 function Is_Illegal_Suffix
235 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
236 -- Returns True if the string Suffix cannot be used as
237 -- a spec suffix, a body suffix or a separate suffix.
239 procedure Locate_Directory
243 Display : out Name_Id);
244 -- Locate a directory.
245 -- Returns No_Name if directory does not exist.
247 function Path_Name_Of
248 (File_Name : Name_Id;
249 Directory : Name_Id) return String;
250 -- Returns the path name of a (non project) file.
251 -- Returns an empty string if file cannot be found.
253 procedure Prepare_Ada_Naming_Exceptions
254 (List : Array_Element_Id;
255 Kind : Spec_Or_Body);
256 -- Prepare the internal hash tables used for checking naming exceptions
257 -- for Ada. Insert all elements of List in the tables.
259 function Project_Extends
260 (Extending : Project_Id;
261 Extended : Project_Id) return Boolean;
262 -- Returns True if Extending is extending directly or indirectly Extended.
264 procedure Record_Ada_Source
265 (File_Name : Name_Id;
267 Project : Project_Id;
268 Data : in out Project_Data;
269 Location : Source_Ptr;
270 Current_Source : in out String_List_Id;
271 Source_Recorded : in out Boolean;
272 Follow_Links : Boolean);
273 -- Put a unit in the list of units of a project, if the file name
274 -- corresponds to a valid unit name.
276 procedure Record_Other_Sources
277 (Project : Project_Id;
278 Data : in out Project_Data;
279 Language : Programming_Language;
280 Naming_Exceptions : Boolean);
281 -- Record the sources of a language in a project.
282 -- When Naming_Exceptions is True, mark the found sources as such, to
283 -- later remove those that are not named in a list of sources.
285 procedure Show_Source_Dirs (Project : Project_Id);
286 -- List all the source directories of a project.
289 (Language : Programming_Language;
290 Naming : Naming_Data) return Name_Id;
291 -- Get the suffix for the source of a language from a package naming.
292 -- If not specified, return the default for the language.
299 (Project : Project_Id;
300 Report_Error : Put_Line_Access;
301 Follow_Links : Boolean)
304 Languages : Variable_Value := Nil_Variable_Value;
306 Extending : Boolean := False;
308 procedure Get_Path_Names_And_Record_Sources;
309 -- Find the path names of the source files in the Source_Names table
310 -- in the source directories and record those that are Ada sources.
312 procedure Get_Sources_From_File
314 Location : Source_Ptr);
315 -- Get the sources of a project from a text file
317 procedure Warn_If_Not_Sources
318 (Conventions : Array_Element_Id;
320 -- Check that individual naming conventions apply to immediate
321 -- sources of the project; if not, issue a warning.
323 ---------------------------------------
324 -- Get_Path_Names_And_Record_Sources --
325 ---------------------------------------
327 procedure Get_Path_Names_And_Record_Sources is
328 Source_Dir : String_List_Id := Data.Source_Dirs;
329 Element : String_Element;
334 Canonical_Name : Name_Id;
335 Name_Str : String (1 .. 1_024);
339 Current_Source : String_List_Id := Nil_String;
341 First_Error : Boolean := True;
343 Source_Recorded : Boolean := False;
346 -- We look in all source directories for the file names in the
347 -- hash table Source_Names
349 while Source_Dir /= Nil_String loop
350 Source_Recorded := False;
351 Element := String_Elements.Table (Source_Dir);
354 Dir_Path : constant String := Get_Name_String (Element.Value);
356 if Current_Verbosity = High then
357 Write_Str ("checking directory """);
358 Write_Str (Dir_Path);
362 Open (Dir, Dir_Path);
365 Read (Dir, Name_Str, Last);
368 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
370 Canonical_Case_File_Name (Name_Str (1 .. Last));
372 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
373 Canonical_Name := Name_Find;
374 NL := Source_Names.Get (Canonical_Name);
376 if NL /= No_Name_Location and then not NL.Found then
378 Source_Names.Set (Canonical_Name, NL);
379 Name_Len := Dir_Path'Length;
380 Name_Buffer (1 .. Name_Len) := Dir_Path;
381 Add_Char_To_Name_Buffer (Directory_Separator);
382 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
385 if Current_Verbosity = High then
386 Write_Str (" found ");
387 Write_Line (Get_Name_String (Name));
390 -- Register the source if it is an Ada compilation unit.
397 Location => NL.Location,
398 Current_Source => Current_Source,
399 Source_Recorded => Source_Recorded,
400 Follow_Links => Follow_Links);
407 if Source_Recorded then
408 String_Elements.Table (Source_Dir).Flag := True;
411 Source_Dir := Element.Next;
414 -- It is an error if a source file name in a source list or
415 -- in a source list file is not found.
417 NL := Source_Names.Get_First;
419 while NL /= No_Name_Location loop
421 Err_Vars.Error_Msg_Name_1 := NL.Name;
426 "source file { cannot be found",
428 First_Error := False;
433 "\source file { cannot be found",
438 NL := Source_Names.Get_Next;
440 end Get_Path_Names_And_Record_Sources;
442 ---------------------------
443 -- Get_Sources_From_File --
444 ---------------------------
446 procedure Get_Sources_From_File
448 Location : Source_Ptr)
451 -- Get the list of sources from the file and put them in hash table
454 Get_Sources_From_File (Path, Location, Project);
456 -- Look in the source directories to find those sources
458 Get_Path_Names_And_Record_Sources;
460 -- We should have found at least one source.
461 -- If not, report an error.
463 if Data.Sources = Nil_String then
465 "there are no Ada sources in this project",
468 end Get_Sources_From_File;
470 -------------------------
471 -- Warn_If_Not_Sources --
472 -------------------------
474 procedure Warn_If_Not_Sources
475 (Conventions : Array_Element_Id;
478 Conv : Array_Element_Id := Conventions;
480 The_Unit_Id : Unit_Id;
481 The_Unit_Data : Unit_Data;
482 Location : Source_Ptr;
485 while Conv /= No_Array_Element loop
486 Unit := Array_Elements.Table (Conv).Index;
487 Error_Msg_Name_1 := Unit;
488 Get_Name_String (Unit);
489 To_Lower (Name_Buffer (1 .. Name_Len));
491 The_Unit_Id := Units_Htable.Get (Unit);
492 Location := Array_Elements.Table (Conv).Value.Location;
494 if The_Unit_Id = Prj.Com.No_Unit then
501 The_Unit_Data := Units.Table (The_Unit_Id);
505 (The_Unit_Data.File_Names (Specification).Project,
510 "?unit{ has no spec in this project",
516 (The_Unit_Data.File_Names (Com.Body_Part).Project,
521 "?unit{ has no body in this project",
527 Conv := Array_Elements.Table (Conv).Next;
529 end Warn_If_Not_Sources;
531 -- Start of processing for Ada_Check
534 Language_Independent_Check (Project, Report_Error);
536 Error_Report := Report_Error;
538 Data := Projects.Table (Project);
539 Extending := Data.Extends /= No_Project;
540 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
542 Data.Naming.Current_Language := Name_Ada;
543 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
545 if not Languages.Default then
547 Current : String_List_Id := Languages.Values;
548 Element : String_Element;
549 Ada_Found : Boolean := False;
552 Look_For_Ada : while Current /= Nil_String loop
553 Element := String_Elements.Table (Current);
554 Get_Name_String (Element.Value);
555 To_Lower (Name_Buffer (1 .. Name_Len));
557 if Name_Buffer (1 .. Name_Len) = "ada" then
562 Current := Element.Next;
563 end loop Look_For_Ada;
565 if not Ada_Found then
567 -- Mark the project file as having no sources for Ada
569 Data.Sources_Present := False;
574 Check_Naming_Scheme (Data, Project);
576 Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
577 Prepare_Ada_Naming_Exceptions (Data.Naming.Specs, Specification);
579 -- If we have source directories, then find the sources
581 if Data.Sources_Present then
582 if Data.Source_Dirs = Nil_String then
583 Data.Sources_Present := False;
587 Sources : constant Variable_Value :=
590 Data.Decl.Attributes);
592 Source_List_File : constant Variable_Value :=
594 (Name_Source_List_File,
595 Data.Decl.Attributes);
597 Locally_Removed : constant Variable_Value :=
599 (Name_Locally_Removed_Files,
600 Data.Decl.Attributes);
604 (Sources.Kind = List,
605 "Source_Files is not a list");
608 (Source_List_File.Kind = Single,
609 "Source_List_File is not a single string");
611 if not Sources.Default then
612 if not Source_List_File.Default then
615 "?both variables source_files and " &
616 "source_list_file are present",
617 Source_List_File.Location);
620 -- Sources is a list of file names
623 Current : String_List_Id := Sources.Values;
624 Element : String_Element;
625 Location : Source_Ptr;
631 Data.Sources_Present := Current /= Nil_String;
633 while Current /= Nil_String loop
634 Element := String_Elements.Table (Current);
635 Get_Name_String (Element.Value);
636 Canonical_Case_File_Name
637 (Name_Buffer (1 .. Name_Len));
640 -- If the element has no location, then use the
641 -- location of Sources to report possible errors.
643 if Element.Location = No_Location then
644 Location := Sources.Location;
647 Location := Element.Location;
654 Location => Location,
657 Current := Element.Next;
660 Get_Path_Names_And_Record_Sources;
663 -- No source_files specified
665 -- We check Source_List_File has been specified.
667 elsif not Source_List_File.Default then
669 -- Source_List_File is the name of the file
670 -- that contains the source file names
673 Source_File_Path_Name : constant String :=
675 (Source_List_File.Value,
679 if Source_File_Path_Name'Length = 0 then
680 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
683 "file with sources { does not exist",
684 Source_List_File.Location);
687 Get_Sources_From_File
688 (Source_File_Path_Name,
689 Source_List_File.Location);
694 -- Neither Source_Files nor Source_List_File has been
695 -- specified. Find all the files that satisfy the naming
696 -- scheme in all the source directories.
698 Find_Sources (Project, Data, Lang_Ada, Follow_Links);
701 -- If there are sources that are locally removed, mark them as
702 -- such in the Units table.
704 if not Locally_Removed.Default then
706 -- Sources can be locally removed only in extending
709 if Data.Extends = No_Project then
712 "Locally_Removed_Files can only be used " &
713 "in an extending project file",
714 Locally_Removed.Location);
718 Current : String_List_Id :=
719 Locally_Removed.Values;
720 Element : String_Element;
721 Location : Source_Ptr;
725 Extended : Project_Id;
728 while Current /= Nil_String loop
729 Element := String_Elements.Table (Current);
730 Get_Name_String (Element.Value);
731 Canonical_Case_File_Name
732 (Name_Buffer (1 .. Name_Len));
735 -- If the element has no location, then use the
736 -- location of Locally_Removed to report
739 if Element.Location = No_Location then
740 Location := Locally_Removed.Location;
743 Location := Element.Location;
748 for Index in 1 .. Units.Last loop
749 Unit := Units.Table (Index);
752 Unit.File_Names (Specification).Name = Name
756 -- Check that this is from a project that
757 -- the current project extends, but not the
760 Extended := Unit.File_Names
761 (Specification).Project;
763 if Extended = Project then
766 "cannot remove a source " &
767 "of the same project",
771 Project_Extends (Project, Extended)
774 (Specification).Path := Slash;
776 (Specification).Needs_Pragma := False;
777 Units.Table (Index) := Unit;
778 Add_Forbidden_File_Name
779 (Unit.File_Names (Specification).Name);
785 "cannot remove a source from " &
791 Unit.File_Names (Body_Part).Name = Name
795 -- Check that this is from a project that
796 -- the current project extends, but not the
799 Extended := Unit.File_Names
802 if Extended = Project then
805 "cannot remove a source " &
806 "of the same project",
810 Project_Extends (Project, Extended)
812 Unit.File_Names (Body_Part).Path := Slash;
813 Unit.File_Names (Body_Part).Needs_Pragma
815 Units.Table (Index) := Unit;
816 Add_Forbidden_File_Name
817 (Unit.File_Names (Body_Part).Name);
825 Err_Vars.Error_Msg_Name_1 := Name;
826 Error_Msg (Project, "unknown file {", Location);
829 Current := Element.Next;
838 if Data.Sources_Present then
840 -- Check that all individual naming conventions apply to
841 -- sources of this project file.
843 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
844 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
847 -- If it is a library project file, check if it is a standalone library
850 Standalone_Library : declare
851 Lib_Interfaces : constant Prj.Variable_Value :=
853 (Snames.Name_Library_Interface,
854 Data.Decl.Attributes);
855 Lib_Auto_Init : constant Prj.Variable_Value :=
857 (Snames.Name_Library_Auto_Init,
858 Data.Decl.Attributes);
860 Lib_Src_Dir : constant Prj.Variable_Value :=
862 (Snames.Name_Library_Src_Dir,
863 Data.Decl.Attributes);
865 Lib_Symbol_File : constant Prj.Variable_Value :=
867 (Snames.Name_Library_Symbol_File,
868 Data.Decl.Attributes);
870 Lib_Symbol_Policy : constant Prj.Variable_Value :=
872 (Snames.Name_Library_Symbol_Policy,
873 Data.Decl.Attributes);
875 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
877 (Snames.Name_Library_Reference_Symbol_File,
878 Data.Decl.Attributes);
880 Auto_Init_Supported : constant Boolean :=
882 Standalone_Library_Auto_Init_Is_Supported;
884 OK : Boolean := True;
887 pragma Assert (Lib_Interfaces.Kind = List);
889 -- It is a stand-alone library project file if attribute
890 -- Library_Interface is defined.
892 if not Lib_Interfaces.Default then
894 Interfaces : String_List_Id := Lib_Interfaces.Values;
895 Interface_ALIs : String_List_Id := Nil_String;
897 The_Unit_Id : Unit_Id;
898 The_Unit_Data : Unit_Data;
900 procedure Add_ALI_For (Source : Name_Id);
901 -- Add an ALI file name to the list of Interface ALIs
907 procedure Add_ALI_For (Source : Name_Id) is
909 Get_Name_String (Source);
912 ALI : constant String :=
913 ALI_File_Name (Name_Buffer (1 .. Name_Len));
914 ALI_Name_Id : Name_Id;
916 Name_Len := ALI'Length;
917 Name_Buffer (1 .. Name_Len) := ALI;
918 ALI_Name_Id := Name_Find;
920 String_Elements.Increment_Last;
921 String_Elements.Table (String_Elements.Last) :=
922 (Value => ALI_Name_Id,
924 Display_Value => ALI_Name_Id,
925 Location => String_Elements.Table
926 (Interfaces).Location,
928 Next => Interface_ALIs);
929 Interface_ALIs := String_Elements.Last;
934 Data.Standalone_Library := True;
936 -- Library_Interface cannot be an empty list
938 if Interfaces = Nil_String then
941 "Library_Interface cannot be an empty list",
942 Lib_Interfaces.Location);
945 -- Process each unit name specified in the attribute
946 -- Library_Interface.
948 while Interfaces /= Nil_String loop
950 (String_Elements.Table (Interfaces).Value);
951 To_Lower (Name_Buffer (1 .. Name_Len));
956 "an interface cannot be an empty string",
957 String_Elements.Table (Interfaces).Location);
961 Error_Msg_Name_1 := Unit;
962 The_Unit_Id := Units_Htable.Get (Unit);
964 if The_Unit_Id = Prj.Com.No_Unit then
968 String_Elements.Table (Interfaces).Location);
971 -- Check that the unit is part of the project
973 The_Unit_Data := Units.Table (The_Unit_Id);
975 if The_Unit_Data.File_Names
976 (Com.Body_Part).Name /= No_Name
977 and then The_Unit_Data.File_Names
978 (Com.Body_Part).Path /= Slash
981 (The_Unit_Data.File_Names (Body_Part).Project,
984 -- There is a body for this unit.
985 -- If there is no spec, we need to check
986 -- that it is not a subunit.
988 if The_Unit_Data.File_Names
989 (Specification).Name = No_Name
992 Src_Ind : Source_File_Index;
995 Src_Ind := Sinput.P.Load_Project_File
997 (The_Unit_Data.File_Names
1000 if Sinput.P.Source_File_Is_Subunit
1005 "{ is a subunit; " &
1006 "it cannot be an interface",
1007 String_Elements.Table
1008 (Interfaces).Location);
1013 -- The unit is not a subunit, so we add
1014 -- to the Interface ALIs the ALI file
1015 -- corresponding to the body.
1018 (The_Unit_Data.File_Names (Body_Part).Name);
1023 "{ is not an unit of this project",
1024 String_Elements.Table
1025 (Interfaces).Location);
1028 elsif The_Unit_Data.File_Names
1029 (Com.Specification).Name /= No_Name
1030 and then The_Unit_Data.File_Names
1031 (Com.Specification).Path /= Slash
1032 and then Check_Project
1033 (The_Unit_Data.File_Names
1034 (Specification).Project,
1038 -- The unit is part of the project, it has
1039 -- a spec, but no body. We add to the Interface
1040 -- ALIs the ALI file corresponding to the spec.
1043 (The_Unit_Data.File_Names (Specification).Name);
1048 "{ is not an unit of this project",
1049 String_Elements.Table (Interfaces).Location);
1055 Interfaces := String_Elements.Table (Interfaces).Next;
1058 -- Put the list of Interface ALIs in the project data
1060 Data.Lib_Interface_ALIs := Interface_ALIs;
1062 -- Check value of attribute Library_Auto_Init and set
1063 -- Lib_Auto_Init accordingly.
1065 if Lib_Auto_Init.Default then
1067 -- If no attribute Library_Auto_Init is declared, then
1068 -- set auto init only if it is supported.
1070 Data.Lib_Auto_Init := Auto_Init_Supported;
1073 Get_Name_String (Lib_Auto_Init.Value);
1074 To_Lower (Name_Buffer (1 .. Name_Len));
1076 if Name_Buffer (1 .. Name_Len) = "false" then
1077 Data.Lib_Auto_Init := False;
1079 elsif Name_Buffer (1 .. Name_Len) = "true" then
1080 if Auto_Init_Supported then
1081 Data.Lib_Auto_Init := True;
1084 -- Library_Auto_Init cannot be "true" if auto init
1089 "library auto init not supported " &
1091 Lib_Auto_Init.Location);
1097 "invalid value for attribute Library_Auto_Init",
1098 Lib_Auto_Init.Location);
1103 -- If attribute Library_Src_Dir is defined and not the
1104 -- empty string, check if the directory exist and is not
1105 -- the object directory or one of the source directories.
1106 -- This is the directory where copies of the interface
1107 -- sources will be copied. Note that this directory may be
1108 -- the library directory.
1110 if Lib_Src_Dir.Value /= Empty_String then
1112 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1116 (Dir_Id, Data.Display_Directory,
1117 Data.Library_Src_Dir,
1118 Data.Display_Library_Src_Dir);
1120 -- If directory does not exist, report an error
1122 if Data.Library_Src_Dir = No_Name then
1124 -- Get the absolute name of the library directory
1125 -- that does not exist, to report an error.
1128 Dir_Name : constant String :=
1129 Get_Name_String (Dir_Id);
1132 if Is_Absolute_Path (Dir_Name) then
1133 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1136 Get_Name_String (Data.Directory);
1138 if Name_Buffer (Name_Len) /=
1141 Name_Len := Name_Len + 1;
1142 Name_Buffer (Name_Len) :=
1143 Directory_Separator;
1148 Name_Len + Dir_Name'Length) :=
1150 Name_Len := Name_Len + Dir_Name'Length;
1151 Err_Vars.Error_Msg_Name_1 := Name_Find;
1158 "Directory { does not exist",
1159 Lib_Src_Dir.Location);
1162 -- Report an error if it is the same as the object
1165 elsif Data.Library_Src_Dir = Data.Object_Directory then
1168 "directory to copy interfaces cannot be " &
1169 "the object directory",
1170 Lib_Src_Dir.Location);
1171 Data.Library_Src_Dir := No_Name;
1173 -- Check if it is the same as one of the source
1178 Src_Dirs : String_List_Id := Data.Source_Dirs;
1179 Src_Dir : String_Element;
1182 while Src_Dirs /= Nil_String loop
1183 Src_Dir := String_Elements.Table (Src_Dirs);
1184 Src_Dirs := Src_Dir.Next;
1186 -- Report an error if it is one of the
1187 -- source directories.
1189 if Data.Library_Src_Dir = Src_Dir.Value then
1192 "directory to copy interfaces cannot " &
1193 "be one of the source directories",
1194 Lib_Src_Dir.Location);
1195 Data.Library_Src_Dir := No_Name;
1201 if Data.Library_Src_Dir /= No_Name
1202 and then Current_Verbosity = High
1204 Write_Str ("Directory to copy interfaces =""");
1205 Write_Str (Get_Name_String (Data.Library_Dir));
1212 if not Lib_Symbol_Policy.Default then
1214 Value : constant String :=
1216 (Get_Name_String (Lib_Symbol_Policy.Value));
1219 if Value = "autonomous" or else Value = "default" then
1220 Data.Symbol_Data.Symbol_Policy := Autonomous;
1222 elsif Value = "compliant" then
1223 Data.Symbol_Data.Symbol_Policy := Compliant;
1225 elsif Value = "controlled" then
1226 Data.Symbol_Data.Symbol_Policy := Controlled;
1228 elsif Value = "restricted" then
1229 Data.Symbol_Data.Symbol_Policy := Restricted;
1234 "illegal value for Library_Symbol_Policy",
1235 Lib_Symbol_Policy.Location);
1240 if Lib_Symbol_File.Default then
1241 if Data.Symbol_Data.Symbol_Policy = Restricted then
1244 "Library_Symbol_File needs to be defined when " &
1245 "symbol policy is Restricted",
1246 Lib_Symbol_Policy.Location);
1250 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1252 Get_Name_String (Lib_Symbol_File.Value);
1254 if Name_Len = 0 then
1257 "symbol file name cannot be an empty string",
1258 Lib_Symbol_File.Location);
1261 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1264 for J in 1 .. Name_Len loop
1265 if Name_Buffer (J) = '/'
1266 or else Name_Buffer (J) = Directory_Separator
1275 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1278 "symbol file name { is illegal. " &
1279 "Name canot include directory info.",
1280 Lib_Symbol_File.Location);
1285 if Lib_Ref_Symbol_File.Default then
1286 if Data.Symbol_Data.Symbol_Policy = Compliant
1287 or else Data.Symbol_Data.Symbol_Policy = Controlled
1291 "a reference symbol file need to be defined",
1292 Lib_Symbol_Policy.Location);
1296 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1298 Get_Name_String (Lib_Ref_Symbol_File.Value);
1300 if Name_Len = 0 then
1303 "reference symbol file name cannot be an empty string",
1304 Lib_Symbol_File.Location);
1307 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1310 for J in 1 .. Name_Len loop
1311 if Name_Buffer (J) = '/'
1312 or else Name_Buffer (J) = Directory_Separator
1321 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1324 "reference symbol file { name is illegal. " &
1325 "Name canot include directory info.",
1326 Lib_Ref_Symbol_File.Location);
1329 if not Is_Regular_File
1330 (Get_Name_String (Data.Object_Directory) &
1331 Directory_Separator &
1332 Get_Name_String (Lib_Ref_Symbol_File.Value))
1334 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1337 "library reference symbol file { does not exist",
1338 Lib_Ref_Symbol_File.Location);
1341 if Data.Symbol_Data.Symbol_File /= No_Name then
1345 (Data.Symbol_Data.Symbol_File);
1347 Reference : String :=
1349 (Data.Symbol_Data.Reference);
1352 Canonical_Case_File_Name (Symbol);
1353 Canonical_Case_File_Name (Reference);
1355 if Symbol = Reference then
1358 "reference symbol file and symbol file " &
1359 "cannot be the same file",
1360 Lib_Ref_Symbol_File.Location);
1367 end Standalone_Library;
1370 -- Put the list of Mains, if any, in the project data
1372 Get_Mains (Project, Data);
1374 Projects.Table (Project) := Data;
1376 Free_Ada_Naming_Exceptions;
1383 function ALI_File_Name (Source : String) return String is
1385 -- If the source name has an extension, then replace it with
1388 for Index in reverse Source'First + 1 .. Source'Last loop
1389 if Source (Index) = '.' then
1390 return Source (Source'First .. Index - 1) & ALI_Suffix;
1394 -- If there is no dot, or if it is the first character, just add the
1397 return Source & ALI_Suffix;
1400 --------------------
1401 -- Check_Ada_Name --
1402 --------------------
1404 procedure Check_Ada_Name
1408 The_Name : String := Name;
1409 Real_Name : Name_Id;
1410 Need_Letter : Boolean := True;
1411 Last_Underscore : Boolean := False;
1412 OK : Boolean := The_Name'Length > 0;
1415 To_Lower (The_Name);
1417 Name_Len := The_Name'Length;
1418 Name_Buffer (1 .. Name_Len) := The_Name;
1419 Real_Name := Name_Find;
1421 -- Check first that the given name is not an Ada reserved word
1423 if Get_Name_Table_Byte (Real_Name) /= 0
1424 and then Real_Name /= Name_Project
1425 and then Real_Name /= Name_Extends
1426 and then Real_Name /= Name_External
1430 if Current_Verbosity = High then
1431 Write_Str (The_Name);
1432 Write_Line (" is an Ada reserved word.");
1438 for Index in The_Name'Range loop
1441 -- We need a letter (at the beginning, and following a dot),
1442 -- but we don't have one.
1444 if Is_Letter (The_Name (Index)) then
1445 Need_Letter := False;
1450 if Current_Verbosity = High then
1451 Write_Int (Types.Int (Index));
1453 Write_Char (The_Name (Index));
1454 Write_Line ("' is not a letter.");
1460 elsif Last_Underscore
1461 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1463 -- Two underscores are illegal, and a dot cannot follow
1468 if Current_Verbosity = High then
1469 Write_Int (Types.Int (Index));
1471 Write_Char (The_Name (Index));
1472 Write_Line ("' is illegal here.");
1477 elsif The_Name (Index) = '.' then
1479 -- We need a letter after a dot
1481 Need_Letter := True;
1483 elsif The_Name (Index) = '_' then
1484 Last_Underscore := True;
1487 -- We need an letter or a digit
1489 Last_Underscore := False;
1491 if not Is_Alphanumeric (The_Name (Index)) then
1494 if Current_Verbosity = High then
1495 Write_Int (Types.Int (Index));
1497 Write_Char (The_Name (Index));
1498 Write_Line ("' is not alphanumeric.");
1506 -- Cannot end with an underscore or a dot
1508 OK := OK and then not Need_Letter and then not Last_Underscore;
1514 -- Signal a problem with No_Name
1520 ----------------------
1521 -- Check_For_Source --
1522 ----------------------
1524 procedure Check_For_Source
1525 (File_Name : Name_Id;
1526 Path_Name : Name_Id;
1527 Project : Project_Id;
1528 Data : in out Project_Data;
1529 Location : Source_Ptr;
1530 Language : Other_Programming_Language;
1532 Naming_Exception : Boolean)
1534 Name : String := Get_Name_String (File_Name);
1535 Real_Location : Source_Ptr := Location;
1538 Canonical_Case_File_Name (Name);
1540 -- A file is a source of a language if Naming_Exception is True (case
1541 -- of naming exceptions) or if its file name ends with the suffix.
1543 if Naming_Exception or else
1544 (Name'Length > Suffix'Length and then
1545 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
1547 if Real_Location = No_Location then
1548 Real_Location := Data.Location;
1552 Path : String := Get_Name_String (Path_Name);
1555 -- The path name id (in canonical case)
1558 -- The file name id (in canonical case)
1561 -- The object file name
1563 Obj_Path_Id : Name_Id;
1564 -- The object path name
1567 -- The dependency file name
1569 Dep_Path_Id : Name_Id;
1570 -- The dependency path name
1572 Dot_Pos : Natural := 0;
1573 -- Position of the last dot in Name
1575 Source : Other_Source;
1576 Source_Id : Other_Source_Id := Data.First_Other_Source;
1579 Canonical_Case_File_Name (Path);
1581 -- Get the file name id
1583 Name_Len := Name'Length;
1584 Name_Buffer (1 .. Name_Len) := Name;
1585 File_Id := Name_Find;
1587 -- Get the path name id
1589 Name_Len := Path'Length;
1590 Name_Buffer (1 .. Name_Len) := Path;
1591 Path_Id := Name_Find;
1593 -- Find the position of the last dot
1595 for J in reverse Name'Range loop
1596 if Name (J) = '.' then
1602 if Dot_Pos <= Name'First then
1603 Dot_Pos := Name'Last + 1;
1606 -- Compute the object file name
1608 Get_Name_String (File_Id);
1609 Name_Len := Dot_Pos - Name'First;
1611 for J in Object_Suffix'Range loop
1612 Name_Len := Name_Len + 1;
1613 Name_Buffer (Name_Len) := Object_Suffix (J);
1616 Obj_Id := Name_Find;
1618 -- Compute the object path name
1620 Get_Name_String (Data.Object_Directory);
1622 if Name_Buffer (Name_Len) /= Directory_Separator and then
1623 Name_Buffer (Name_Len) /= '/'
1625 Name_Len := Name_Len + 1;
1626 Name_Buffer (Name_Len) := Directory_Separator;
1629 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
1630 Obj_Path_Id := Name_Find;
1632 -- Compute the dependency file name
1634 Get_Name_String (File_Id);
1635 Name_Len := Dot_Pos - Name'First + 1;
1636 Name_Buffer (Name_Len) := '.';
1637 Name_Len := Name_Len + 1;
1638 Name_Buffer (Name_Len) := 'd';
1639 Dep_Id := Name_Find;
1641 -- Compute the dependency path name
1643 Get_Name_String (Data.Object_Directory);
1645 if Name_Buffer (Name_Len) /= Directory_Separator and then
1646 Name_Buffer (Name_Len) /= '/'
1648 Name_Len := Name_Len + 1;
1649 Name_Buffer (Name_Len) := Directory_Separator;
1652 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
1653 Dep_Path_Id := Name_Find;
1655 -- Check if source is already in the list of source for this
1656 -- project: it may have already been specified as a naming
1657 -- exception for the same language or an other language, or they
1658 -- may be two identical file names in different source
1661 while Source_Id /= No_Other_Source loop
1662 Source := Other_Sources.Table (Source_Id);
1663 Source_Id := Source.Next;
1665 if Source.File_Name = File_Id then
1666 -- Two sources of different languages cannot have the same
1669 if Source.Language /= Language then
1670 Error_Msg_Name_1 := File_Name;
1673 "{ cannot be a source of several languages",
1677 -- No problem if a file has already been specified as
1678 -- a naming exception of this language.
1680 elsif Source.Path_Name = Path_Id then
1681 -- Reset the naming exception flag, if this is not a
1682 -- naming exception.
1684 if not Naming_Exception then
1685 Other_Sources.Table (Source_Id).Naming_Exception :=
1691 -- There are several files with the same names, but the
1692 -- order of the source directories is known (no /**):
1693 -- only the first one encountered is kept, the other ones
1696 elsif Data.Known_Order_Of_Source_Dirs then
1699 -- But it is an error if the order of the source directories
1703 Error_Msg_Name_1 := File_Name;
1706 "{ is found in several source directories",
1711 -- Two sources with different file names cannot have the same
1712 -- object file name.
1714 elsif Source.Object_Name = Obj_Id then
1715 Error_Msg_Name_1 := File_Id;
1716 Error_Msg_Name_2 := Source.File_Name;
1717 Error_Msg_Name_3 := Obj_Id;
1720 "{ and { have the same object file {",
1726 if Current_Verbosity = High then
1727 Write_Str (" found ");
1728 Write_Str (Lang_Display_Names (Language).all);
1729 Write_Str (" source """);
1730 Write_Str (Get_Name_String (File_Name));
1732 Write_Str (" object path = ");
1733 Write_Line (Get_Name_String (Obj_Path_Id));
1736 -- Create the Other_Source record
1738 (Language => Language,
1739 File_Name => File_Id,
1740 Path_Name => Path_Id,
1741 Source_TS => File_Stamp (Path_Id),
1742 Object_Name => Obj_Id,
1743 Object_Path => Obj_Path_Id,
1744 Object_TS => File_Stamp (Obj_Path_Id),
1746 Dep_Path => Dep_Path_Id,
1747 Dep_TS => File_Stamp (Dep_Path_Id),
1748 Naming_Exception => Naming_Exception,
1749 Next => No_Other_Source);
1751 -- And add it to the Other_Sources table
1753 Other_Sources.Increment_Last;
1754 Other_Sources.Table (Other_Sources.Last) := Source;
1756 -- There are sources of languages other than Ada in this project
1757 Data.Sources_Present := True;
1759 -- And there are sources of this language in this project
1761 Data.Languages (Language) := True;
1763 -- Add this source to the list of sources of languages other than
1764 -- Ada of the project.
1766 if Data.First_Other_Source = No_Other_Source then
1767 Data.First_Other_Source := Other_Sources.Last;
1770 Other_Sources.Table (Data.Last_Other_Source).Next :=
1774 Data.Last_Other_Source := Other_Sources.Last;
1777 end Check_For_Source;
1779 -----------------------------
1780 -- Check_Ada_Naming_Scheme --
1781 -----------------------------
1783 procedure Check_Ada_Naming_Scheme
1784 (Project : Project_Id;
1785 Naming : Naming_Data)
1788 -- Only check if we are not using the standard naming scheme
1790 if Naming /= Standard_Naming_Data then
1792 Dot_Replacement : constant String :=
1794 (Naming.Dot_Replacement);
1796 Spec_Suffix : constant String :=
1798 (Naming.Current_Spec_Suffix);
1800 Body_Suffix : constant String :=
1802 (Naming.Current_Body_Suffix);
1804 Separate_Suffix : constant String :=
1806 (Naming.Separate_Suffix);
1809 -- Dot_Replacement cannot
1811 -- - start or end with an alphanumeric
1812 -- - be a single '_'
1813 -- - start with an '_' followed by an alphanumeric
1814 -- - contain a '.' except if it is "."
1816 if Dot_Replacement'Length = 0
1817 or else Is_Alphanumeric
1818 (Dot_Replacement (Dot_Replacement'First))
1819 or else Is_Alphanumeric
1820 (Dot_Replacement (Dot_Replacement'Last))
1821 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1823 (Dot_Replacement'Length = 1
1826 (Dot_Replacement (Dot_Replacement'First + 1))))
1827 or else (Dot_Replacement'Length > 1
1829 Index (Source => Dot_Replacement,
1830 Pattern => ".") /= 0)
1834 '"' & Dot_Replacement &
1835 """ is illegal for Dot_Replacement.",
1836 Naming.Dot_Repl_Loc);
1842 if Is_Illegal_Suffix
1843 (Spec_Suffix, Dot_Replacement = ".")
1845 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1848 "{ is illegal for Spec_Suffix",
1849 Naming.Spec_Suffix_Loc);
1852 if Is_Illegal_Suffix
1853 (Body_Suffix, Dot_Replacement = ".")
1855 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1858 "{ is illegal for Body_Suffix",
1859 Naming.Body_Suffix_Loc);
1862 if Body_Suffix /= Separate_Suffix then
1863 if Is_Illegal_Suffix
1864 (Separate_Suffix, Dot_Replacement = ".")
1866 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1869 "{ is illegal for Separate_Suffix",
1870 Naming.Sep_Suffix_Loc);
1874 -- Spec_Suffix cannot have the same termination as
1875 -- Body_Suffix or Separate_Suffix
1877 if Spec_Suffix'Length <= Body_Suffix'Length
1879 Body_Suffix (Body_Suffix'Last -
1880 Spec_Suffix'Length + 1 ..
1881 Body_Suffix'Last) = Spec_Suffix
1887 """) cannot end with" &
1888 " Spec_Suffix (""" &
1889 Spec_Suffix & """).",
1890 Naming.Body_Suffix_Loc);
1893 if Body_Suffix /= Separate_Suffix
1894 and then Spec_Suffix'Length <= Separate_Suffix'Length
1897 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1899 Separate_Suffix'Last) = Spec_Suffix
1903 "Separate_Suffix (""" &
1905 """) cannot end with" &
1906 " Spec_Suffix (""" &
1907 Spec_Suffix & """).",
1908 Naming.Sep_Suffix_Loc);
1912 end Check_Ada_Naming_Scheme;
1914 -------------------------
1915 -- Check_Naming_Scheme --
1916 -------------------------
1918 procedure Check_Naming_Scheme
1919 (Data : in out Project_Data;
1920 Project : Project_Id)
1922 Naming_Id : constant Package_Id :=
1923 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1925 Naming : Package_Element;
1927 procedure Check_Unit_Names (List : Array_Element_Id);
1928 -- Check that a list of unit names contains only valid names.
1930 ----------------------
1931 -- Check_Unit_Names --
1932 ----------------------
1934 procedure Check_Unit_Names (List : Array_Element_Id) is
1935 Current : Array_Element_Id := List;
1936 Element : Array_Element;
1937 Unit_Name : Name_Id;
1940 -- Loop through elements of the string list
1942 while Current /= No_Array_Element loop
1943 Element := Array_Elements.Table (Current);
1945 -- Put file name in canonical case
1947 Get_Name_String (Element.Value.Value);
1948 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1949 Element.Value.Value := Name_Find;
1951 -- Check that it contains a valid unit name
1953 Get_Name_String (Element.Index);
1954 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1956 if Unit_Name = No_Name then
1957 Err_Vars.Error_Msg_Name_1 := Element.Index;
1960 "{ is not a valid unit name.",
1961 Element.Value.Location);
1964 if Current_Verbosity = High then
1965 Write_Str (" Unit (""");
1966 Write_Str (Get_Name_String (Unit_Name));
1970 Element.Index := Unit_Name;
1971 Array_Elements.Table (Current) := Element;
1974 Current := Element.Next;
1976 end Check_Unit_Names;
1978 -- Start of processing for Check_Naming_Scheme
1981 -- If there is a package Naming, we will put in Data.Naming what is in
1982 -- this package Naming.
1984 if Naming_Id /= No_Package then
1985 Naming := Packages.Table (Naming_Id);
1987 if Current_Verbosity = High then
1988 Write_Line ("Checking ""Naming"" for Ada.");
1992 Bodies : constant Array_Element_Id :=
1993 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
1995 Specs : constant Array_Element_Id :=
1996 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
1999 if Bodies /= No_Array_Element then
2001 -- We have elements in the array Body_Part
2003 if Current_Verbosity = High then
2004 Write_Line ("Found Bodies.");
2007 Data.Naming.Bodies := Bodies;
2008 Check_Unit_Names (Bodies);
2011 if Current_Verbosity = High then
2012 Write_Line ("No Bodies.");
2016 if Specs /= No_Array_Element then
2018 -- We have elements in the array Specs
2020 if Current_Verbosity = High then
2021 Write_Line ("Found Specs.");
2024 Data.Naming.Specs := Specs;
2025 Check_Unit_Names (Specs);
2028 if Current_Verbosity = High then
2029 Write_Line ("No Specs.");
2034 -- We are now checking if variables Dot_Replacement, Casing,
2035 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
2038 -- For each variable, if it does not exist, we do nothing,
2039 -- because we already have the default.
2041 -- Check Dot_Replacement
2044 Dot_Replacement : constant Variable_Value :=
2046 (Name_Dot_Replacement,
2047 Naming.Decl.Attributes);
2050 pragma Assert (Dot_Replacement.Kind = Single,
2051 "Dot_Replacement is not a single string");
2053 if not Dot_Replacement.Default then
2054 Get_Name_String (Dot_Replacement.Value);
2056 if Name_Len = 0 then
2059 "Dot_Replacement cannot be empty",
2060 Dot_Replacement.Location);
2063 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2064 Data.Naming.Dot_Replacement := Name_Find;
2065 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2070 if Current_Verbosity = High then
2071 Write_Str (" Dot_Replacement = """);
2072 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
2080 Casing_String : constant Variable_Value :=
2082 (Name_Casing, Naming.Decl.Attributes);
2085 pragma Assert (Casing_String.Kind = Single,
2086 "Casing is not a single string");
2088 if not Casing_String.Default then
2090 Casing_Image : constant String :=
2091 Get_Name_String (Casing_String.Value);
2094 Casing_Value : constant Casing_Type :=
2095 Value (Casing_Image);
2097 -- Ignore Casing on platforms where file names are
2098 -- case-insensitive.
2100 if not File_Names_Case_Sensitive then
2101 Data.Naming.Casing := All_Lower_Case;
2104 Data.Naming.Casing := Casing_Value;
2109 when Constraint_Error =>
2110 if Casing_Image'Length = 0 then
2113 "Casing cannot be an empty string",
2114 Casing_String.Location);
2117 Name_Len := Casing_Image'Length;
2118 Name_Buffer (1 .. Name_Len) := Casing_Image;
2119 Err_Vars.Error_Msg_Name_1 := Name_Find;
2122 "{ is not a correct Casing",
2123 Casing_String.Location);
2129 if Current_Verbosity = High then
2130 Write_Str (" Casing = ");
2131 Write_Str (Image (Data.Naming.Casing));
2136 -- Check Spec_Suffix
2139 Ada_Spec_Suffix : constant Variable_Value :=
2143 In_Array => Data.Naming.Spec_Suffix);
2146 if Ada_Spec_Suffix.Kind = Single
2147 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2149 Get_Name_String (Ada_Spec_Suffix.Value);
2150 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2151 Data.Naming.Current_Spec_Suffix := Name_Find;
2152 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2155 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2159 if Current_Verbosity = High then
2160 Write_Str (" Spec_Suffix = """);
2161 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2166 -- Check Body_Suffix
2169 Ada_Body_Suffix : constant Variable_Value :=
2173 In_Array => Data.Naming.Body_Suffix);
2176 if Ada_Body_Suffix.Kind = Single
2177 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2179 Get_Name_String (Ada_Body_Suffix.Value);
2180 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2181 Data.Naming.Current_Body_Suffix := Name_Find;
2182 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2185 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2189 if Current_Verbosity = High then
2190 Write_Str (" Body_Suffix = """);
2191 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
2196 -- Check Separate_Suffix
2199 Ada_Sep_Suffix : constant Variable_Value :=
2201 (Variable_Name => Name_Separate_Suffix,
2202 In_Variables => Naming.Decl.Attributes);
2205 if Ada_Sep_Suffix.Default then
2206 Data.Naming.Separate_Suffix :=
2207 Data.Naming.Current_Body_Suffix;
2210 Get_Name_String (Ada_Sep_Suffix.Value);
2212 if Name_Len = 0 then
2215 "Separate_Suffix cannot be empty",
2216 Ada_Sep_Suffix.Location);
2219 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2220 Data.Naming.Separate_Suffix := Name_Find;
2221 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
2226 if Current_Verbosity = High then
2227 Write_Str (" Separate_Suffix = """);
2228 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
2233 -- Check if Data.Naming is valid
2235 Check_Ada_Naming_Scheme (Project, Data.Naming);
2238 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2239 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2240 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
2242 end Check_Naming_Scheme;
2248 function Check_Project
2250 Root_Project : Project_Id;
2251 Extending : Boolean) return Boolean
2254 if P = Root_Project then
2257 elsif Extending then
2259 Data : Project_Data := Projects.Table (Root_Project);
2262 while Data.Extends /= No_Project loop
2263 if P = Data.Extends then
2267 Data := Projects.Table (Data.Extends);
2275 ----------------------------
2276 -- Compute_Directory_Last --
2277 ----------------------------
2279 function Compute_Directory_Last (Dir : String) return Natural is
2282 and then (Dir (Dir'Last - 1) = Directory_Separator
2283 or else Dir (Dir'Last - 1) = '/')
2285 return Dir'Last - 1;
2289 end Compute_Directory_Last;
2296 (Project : Project_Id;
2298 Flag_Location : Source_Ptr)
2300 Error_Buffer : String (1 .. 5_000);
2301 Error_Last : Natural := 0;
2302 Msg_Name : Natural := 0;
2303 First : Positive := Msg'First;
2305 procedure Add (C : Character);
2306 -- Add a character to the buffer
2308 procedure Add (S : String);
2309 -- Add a string to the buffer
2311 procedure Add (Id : Name_Id);
2312 -- Add a name to the buffer
2318 procedure Add (C : Character) is
2320 Error_Last := Error_Last + 1;
2321 Error_Buffer (Error_Last) := C;
2324 procedure Add (S : String) is
2326 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2327 Error_Last := Error_Last + S'Length;
2330 procedure Add (Id : Name_Id) is
2332 Get_Name_String (Id);
2333 Add (Name_Buffer (1 .. Name_Len));
2336 -- Start of processing for Error_Msg
2339 if Error_Report = null then
2340 Prj.Err.Error_Msg (Msg, Flag_Location);
2344 if Msg (First) = '\' then
2346 -- Continuation character, ignore.
2350 elsif Msg (First) = '?' then
2352 -- Warning character. It is always the first one in this package
2358 for Index in First .. Msg'Last loop
2359 if Msg (Index) = '{' or else Msg (Index) = '%' then
2361 -- Include a name between double quotes.
2363 Msg_Name := Msg_Name + 1;
2367 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2368 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2369 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2371 when others => null;
2382 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2389 procedure Find_Sources
2390 (Project : Project_Id;
2391 Data : in out Project_Data;
2392 For_Language : Programming_Language;
2393 Follow_Links : Boolean := False)
2395 Source_Dir : String_List_Id := Data.Source_Dirs;
2396 Element : String_Element;
2398 Current_Source : String_List_Id := Nil_String;
2399 Source_Recorded : Boolean := False;
2402 if Current_Verbosity = High then
2403 Write_Line ("Looking for sources:");
2406 -- For each subdirectory
2408 while Source_Dir /= Nil_String loop
2410 Source_Recorded := False;
2411 Element := String_Elements.Table (Source_Dir);
2412 if Element.Value /= No_Name then
2413 Get_Name_String (Element.Display_Value);
2416 Source_Directory : constant String :=
2417 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2418 Dir_Last : constant Natural :=
2419 Compute_Directory_Last (Source_Directory);
2422 if Current_Verbosity = High then
2423 Write_Str ("Source_Dir = ");
2424 Write_Line (Source_Directory);
2427 -- We look to every entry in the source directory
2429 Open (Dir, Source_Directory
2430 (Source_Directory'First .. Dir_Last));
2433 Read (Dir, Name_Buffer, Name_Len);
2435 if Current_Verbosity = High then
2436 Write_Str (" Checking ");
2437 Write_Line (Name_Buffer (1 .. Name_Len));
2440 exit when Name_Len = 0;
2443 File_Name : constant Name_Id := Name_Find;
2444 Path : constant String :=
2446 (Name => Name_Buffer (1 .. Name_Len),
2447 Directory => Source_Directory
2448 (Source_Directory'First .. Dir_Last),
2449 Resolve_Links => Follow_Links,
2450 Case_Sensitive => True);
2451 Path_Name : Name_Id;
2454 Name_Len := Path'Length;
2455 Name_Buffer (1 .. Name_Len) := Path;
2456 Path_Name := Name_Find;
2458 if For_Language = Lang_Ada then
2459 -- We attempt to register it as a source.
2460 -- However, there is no error if the file
2461 -- does not contain a valid source.
2462 -- But there is an error if we have a
2463 -- duplicate unit name.
2466 (File_Name => File_Name,
2467 Path_Name => Path_Name,
2470 Location => No_Location,
2471 Current_Source => Current_Source,
2472 Source_Recorded => Source_Recorded,
2473 Follow_Links => Follow_Links);
2477 (File_Name => File_Name,
2478 Path_Name => Path_Name,
2481 Location => No_Location,
2482 Language => For_Language,
2485 (Data.Impl_Suffixes (For_Language)),
2486 Naming_Exception => False);
2496 when Directory_Error =>
2500 if Source_Recorded then
2501 String_Elements.Table (Source_Dir).Flag := True;
2504 Source_Dir := Element.Next;
2507 if Current_Verbosity = High then
2508 Write_Line ("end Looking for sources.");
2511 if For_Language = Lang_Ada then
2512 -- If we have looked for sources and found none, then
2513 -- it is an error, except if it is an extending project.
2514 -- If a non extending project is not supposed to contain
2515 -- any source, then we never call Find_Sources.
2517 if Current_Source /= Nil_String then
2518 Data.Sources_Present := True;
2520 elsif Data.Extends = No_Project then
2523 "there are no Ada sources in this project",
2529 --------------------------------
2530 -- Free_Ada_Naming_Exceptions --
2531 --------------------------------
2533 procedure Free_Ada_Naming_Exceptions is
2535 Ada_Naming_Exception_Table.Set_Last (0);
2536 Ada_Naming_Exceptions.Reset;
2537 Reverse_Ada_Naming_Exceptions.Reset;
2538 end Free_Ada_Naming_Exceptions;
2544 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2545 Mains : constant Variable_Value :=
2546 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2549 Data.Mains := Mains.Values;
2551 -- If no Mains were specified, and if we are an extending
2552 -- project, inherit the Mains from the project we are extending.
2554 if Mains.Default then
2555 if Data.Extends /= No_Project then
2556 Data.Mains := Projects.Table (Data.Extends).Mains;
2559 -- In a library project file, Main cannot be specified
2561 elsif Data.Library then
2564 "a library project file cannot have Main specified",
2569 ---------------------------
2570 -- Get_Sources_From_File --
2571 ---------------------------
2573 procedure Get_Sources_From_File
2575 Location : Source_Ptr;
2576 Project : Project_Id)
2578 File : Prj.Util.Text_File;
2579 Line : String (1 .. 250);
2581 Source_Name : Name_Id;
2586 if Current_Verbosity = High then
2587 Write_Str ("Opening """);
2594 Prj.Util.Open (File, Path);
2596 if not Prj.Util.Is_Valid (File) then
2597 Error_Msg (Project, "file does not exist", Location);
2599 -- Read the lines one by one
2601 while not Prj.Util.End_Of_File (File) loop
2602 Prj.Util.Get_Line (File, Line, Last);
2604 -- A non empty, non comment line should contain a file name
2607 and then (Last = 1 or else Line (1 .. 2) /= "--")
2609 -- ??? we should check that there is no directory information
2612 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2613 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2614 Source_Name := Name_Find;
2618 (Name => Source_Name,
2619 Location => Location,
2624 Prj.Util.Close (File);
2627 end Get_Sources_From_File;
2634 (Canonical_File_Name : Name_Id;
2635 Naming : Naming_Data;
2636 Exception_Id : out Ada_Naming_Exception_Id;
2637 Unit_Name : out Name_Id;
2638 Unit_Kind : out Spec_Or_Body;
2639 Needs_Pragma : out Boolean)
2641 Info_Id : Ada_Naming_Exception_Id
2642 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
2646 if Info_Id = No_Ada_Naming_Exception then
2647 if Hostparm.OpenVMS then
2648 VMS_Name := Canonical_File_Name;
2649 Get_Name_String (VMS_Name);
2651 if Name_Buffer (Name_Len) = '.' then
2652 Name_Len := Name_Len - 1;
2653 VMS_Name := Name_Find;
2656 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
2661 if Info_Id /= No_Ada_Naming_Exception then
2662 Exception_Id := Info_Id;
2663 Unit_Name := No_Name;
2664 Unit_Kind := Specification;
2665 Needs_Pragma := True;
2669 Needs_Pragma := False;
2670 Exception_Id := No_Ada_Naming_Exception;
2672 Get_Name_String (Canonical_File_Name);
2675 File : String := Name_Buffer (1 .. Name_Len);
2676 First : constant Positive := File'First;
2677 Last : Natural := File'Last;
2678 Standard_GNAT : Boolean;
2682 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2683 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2685 -- Check if the end of the file name is Specification_Append
2687 Get_Name_String (Naming.Current_Spec_Suffix);
2689 if File'Length > Name_Len
2690 and then File (Last - Name_Len + 1 .. Last) =
2691 Name_Buffer (1 .. Name_Len)
2695 Unit_Kind := Specification;
2696 Last := Last - Name_Len;
2698 if Current_Verbosity = High then
2699 Write_Str (" Specification: ");
2700 Write_Line (File (First .. Last));
2704 Get_Name_String (Naming.Current_Body_Suffix);
2706 -- Check if the end of the file name is Body_Append
2708 if File'Length > Name_Len
2709 and then File (Last - Name_Len + 1 .. Last) =
2710 Name_Buffer (1 .. Name_Len)
2714 Unit_Kind := Body_Part;
2715 Last := Last - Name_Len;
2717 if Current_Verbosity = High then
2718 Write_Str (" Body: ");
2719 Write_Line (File (First .. Last));
2722 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2723 Get_Name_String (Naming.Separate_Suffix);
2725 -- Check if the end of the file name is Separate_Append
2727 if File'Length > Name_Len
2728 and then File (Last - Name_Len + 1 .. Last) =
2729 Name_Buffer (1 .. Name_Len)
2731 -- We have a separate (a body)
2733 Unit_Kind := Body_Part;
2734 Last := Last - Name_Len;
2736 if Current_Verbosity = High then
2737 Write_Str (" Separate: ");
2738 Write_Line (File (First .. Last));
2752 -- This is not a source file
2754 Unit_Name := No_Name;
2755 Unit_Kind := Specification;
2757 if Current_Verbosity = High then
2758 Write_Line (" Not a valid file name.");
2764 Get_Name_String (Naming.Dot_Replacement);
2766 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2768 if Name_Buffer (1 .. Name_Len) /= "." then
2770 -- If Dot_Replacement is not a single dot,
2771 -- then there should not be any dot in the name.
2773 for Index in First .. Last loop
2774 if File (Index) = '.' then
2775 if Current_Verbosity = High then
2777 (" Not a valid file name (some dot not replaced).");
2780 Unit_Name := No_Name;
2786 -- Replace the substring Dot_Replacement with dots
2789 Index : Positive := First;
2792 while Index <= Last - Name_Len + 1 loop
2794 if File (Index .. Index + Name_Len - 1) =
2795 Name_Buffer (1 .. Name_Len)
2797 File (Index) := '.';
2799 if Name_Len > 1 and then Index < Last then
2800 File (Index + 1 .. Last - Name_Len + 1) :=
2801 File (Index + Name_Len .. Last);
2804 Last := Last - Name_Len + 1;
2812 -- Check if the casing is right
2815 Src : String := File (First .. Last);
2818 case Naming.Casing is
2819 when All_Lower_Case =>
2822 Mapping => Lower_Case_Map);
2824 when All_Upper_Case =>
2827 Mapping => Upper_Case_Map);
2829 when Mixed_Case | Unknown =>
2833 if Src /= File (First .. Last) then
2834 if Current_Verbosity = High then
2835 Write_Line (" Not a valid file name (casing).");
2838 Unit_Name := No_Name;
2842 -- We put the name in lower case
2846 Mapping => Lower_Case_Map);
2848 -- In the standard GNAT naming scheme, check for special cases:
2849 -- children or separates of A, G, I or S, and run time sources.
2851 if Standard_GNAT and then Src'Length >= 3 then
2853 S1 : constant Character := Src (Src'First);
2854 S2 : constant Character := Src (Src'First + 1);
2857 if S1 = 'a' or else S1 = 'g'
2858 or else S1 = 'i' or else S1 = 's'
2860 -- Children or separates of packages A, G, I or S
2862 if (Hostparm.OpenVMS and then S2 = '$')
2863 or else (not Hostparm.OpenVMS and then S2 = '~')
2865 Src (Src'First + 1) := '.';
2867 -- If it is potentially a run time source, disable
2868 -- filling of the mapping file to avoid warnings.
2871 Set_Mapping_File_Initial_State_To_Empty;
2878 if Current_Verbosity = High then
2883 -- Now, we check if this name is a valid unit name
2885 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2895 function Hash (Unit : Unit_Info) return Header_Num is
2897 return Header_Num (Unit.Unit mod 2048);
2900 -----------------------
2901 -- Is_Illegal_Suffix --
2902 -----------------------
2904 function Is_Illegal_Suffix
2906 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2909 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2913 -- If dot replacement is a single dot, and first character of
2914 -- suffix is also a dot
2916 if Dot_Replacement_Is_A_Single_Dot
2917 and then Suffix (Suffix'First) = '.'
2919 for Index in Suffix'First + 1 .. Suffix'Last loop
2921 -- If there is another dot
2923 if Suffix (Index) = '.' then
2925 -- It is illegal to have a letter following the initial dot
2927 return Is_Letter (Suffix (Suffix'First + 1));
2935 end Is_Illegal_Suffix;
2937 --------------------------------
2938 -- Language_Independent_Check --
2939 --------------------------------
2941 procedure Language_Independent_Check
2942 (Project : Project_Id;
2943 Report_Error : Put_Line_Access)
2945 Last_Source_Dir : String_List_Id := Nil_String;
2946 Data : Project_Data := Projects.Table (Project);
2948 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2949 -- Find one or several source directories, and add them
2950 -- to the list of source directories of the project.
2952 ----------------------
2953 -- Find_Source_Dirs --
2954 ----------------------
2956 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2957 Directory : constant String := Get_Name_String (From);
2958 Element : String_Element;
2960 procedure Recursive_Find_Dirs (Path : Name_Id);
2961 -- Find all the subdirectories (recursively) of Path and add them
2962 -- to the list of source directories of the project.
2964 -------------------------
2965 -- Recursive_Find_Dirs --
2966 -------------------------
2968 procedure Recursive_Find_Dirs (Path : Name_Id) is
2970 Name : String (1 .. 250);
2972 List : String_List_Id := Data.Source_Dirs;
2973 Element : String_Element;
2974 Found : Boolean := False;
2976 Non_Canonical_Path : Name_Id := No_Name;
2977 Canonical_Path : Name_Id := No_Name;
2979 The_Path : constant String :=
2980 Normalize_Pathname (Get_Name_String (Path)) &
2981 Directory_Separator;
2983 The_Path_Last : constant Natural :=
2984 Compute_Directory_Last (The_Path);
2987 Name_Len := The_Path_Last - The_Path'First + 1;
2988 Name_Buffer (1 .. Name_Len) :=
2989 The_Path (The_Path'First .. The_Path_Last);
2990 Non_Canonical_Path := Name_Find;
2991 Get_Name_String (Non_Canonical_Path);
2992 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2993 Canonical_Path := Name_Find;
2995 -- To avoid processing the same directory several times, check
2996 -- if the directory is already in Recursive_Dirs. If it is,
2997 -- then there is nothing to do, just return. If it is not, put
2998 -- it there and continue recursive processing.
3000 if Recursive_Dirs.Get (Canonical_Path) then
3004 Recursive_Dirs.Set (Canonical_Path, True);
3007 -- Check if directory is already in list
3009 while List /= Nil_String loop
3010 Element := String_Elements.Table (List);
3012 if Element.Value /= No_Name then
3013 Found := Element.Value = Canonical_Path;
3017 List := Element.Next;
3020 -- If directory is not already in list, put it there
3023 if Current_Verbosity = High then
3025 Write_Line (The_Path (The_Path'First .. The_Path_Last));
3028 String_Elements.Increment_Last;
3030 (Value => Canonical_Path,
3031 Display_Value => Non_Canonical_Path,
3032 Location => No_Location,
3037 -- Case of first source directory
3039 if Last_Source_Dir = Nil_String then
3040 Data.Source_Dirs := String_Elements.Last;
3042 -- Here we already have source directories.
3045 -- Link the previous last to the new one
3047 String_Elements.Table (Last_Source_Dir).Next :=
3048 String_Elements.Last;
3051 -- And register this source directory as the new last
3053 Last_Source_Dir := String_Elements.Last;
3054 String_Elements.Table (Last_Source_Dir) := Element;
3057 -- Now look for subdirectories. We do that even when this
3058 -- directory is already in the list, because some of its
3059 -- subdirectories may not be in the list yet.
3061 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3064 Read (Dir, Name, Last);
3067 if Name (1 .. Last) /= "."
3068 and then Name (1 .. Last) /= ".."
3072 if Current_Verbosity = High then
3073 Write_Str (" Checking ");
3074 Write_Line (Name (1 .. Last));
3078 Path_Name : constant String :=
3080 (Name => Name (1 .. Last),
3083 (The_Path'First .. The_Path_Last),
3084 Resolve_Links => False,
3085 Case_Sensitive => True);
3088 if Is_Directory (Path_Name) then
3090 -- We have found a new subdirectory, call self
3092 Name_Len := Path_Name'Length;
3093 Name_Buffer (1 .. Name_Len) := Path_Name;
3094 Recursive_Find_Dirs (Name_Find);
3103 when Directory_Error =>
3105 end Recursive_Find_Dirs;
3107 -- Start of processing for Find_Source_Dirs
3110 if Current_Verbosity = High then
3111 Write_Str ("Find_Source_Dirs (""");
3112 Write_Str (Directory);
3116 -- First, check if we are looking for a directory tree,
3117 -- indicated by "/**" at the end.
3119 if Directory'Length >= 3
3120 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3121 and then (Directory (Directory'Last - 2) = '/'
3123 Directory (Directory'Last - 2) = Directory_Separator)
3125 Data.Known_Order_Of_Source_Dirs := False;
3127 Name_Len := Directory'Length - 3;
3129 if Name_Len = 0 then
3131 -- This is the case of "/**": all directories
3132 -- in the file system.
3135 Name_Buffer (1) := Directory (Directory'First);
3138 Name_Buffer (1 .. Name_Len) :=
3139 Directory (Directory'First .. Directory'Last - 3);
3142 if Current_Verbosity = High then
3143 Write_Str ("Looking for all subdirectories of """);
3144 Write_Str (Name_Buffer (1 .. Name_Len));
3149 Base_Dir : constant Name_Id := Name_Find;
3150 Root_Dir : constant String :=
3152 (Name => Get_Name_String (Base_Dir),
3154 Get_Name_String (Data.Display_Directory),
3155 Resolve_Links => False,
3156 Case_Sensitive => True);
3159 if Root_Dir'Length = 0 then
3160 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3162 if Location = No_Location then
3165 "{ is not a valid directory.",
3170 "{ is not a valid directory.",
3175 -- We have an existing directory,
3176 -- we register it and all of its subdirectories.
3178 if Current_Verbosity = High then
3179 Write_Line ("Looking for source directories:");
3182 Name_Len := Root_Dir'Length;
3183 Name_Buffer (1 .. Name_Len) := Root_Dir;
3184 Recursive_Find_Dirs (Name_Find);
3186 if Current_Verbosity = High then
3187 Write_Line ("End of looking for source directories.");
3192 -- We have a single directory
3196 Path_Name : Name_Id;
3197 Display_Path_Name : Name_Id;
3200 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3201 if Path_Name = No_Name then
3202 Err_Vars.Error_Msg_Name_1 := From;
3204 if Location = No_Location then
3207 "{ is not a valid directory",
3212 "{ is not a valid directory",
3217 -- As it is an existing directory, we add it to
3218 -- the list of directories.
3220 String_Elements.Increment_Last;
3221 Element.Value := Path_Name;
3222 Element.Display_Value := Display_Path_Name;
3224 if Last_Source_Dir = Nil_String then
3226 -- This is the first source directory
3228 Data.Source_Dirs := String_Elements.Last;
3231 -- We already have source directories,
3232 -- link the previous last to the new one.
3234 String_Elements.Table (Last_Source_Dir).Next :=
3235 String_Elements.Last;
3238 -- And register this source directory as the new last
3240 Last_Source_Dir := String_Elements.Last;
3241 String_Elements.Table (Last_Source_Dir) := Element;
3245 end Find_Source_Dirs;
3247 -- Start of processing for Language_Independent_Check
3250 if Data.Language_Independent_Checked then
3254 Data.Language_Independent_Checked := True;
3256 Error_Report := Report_Error;
3258 Recursive_Dirs.Reset;
3260 if Current_Verbosity = High then
3261 Write_Line ("Starting to look for directories");
3264 -- Check the object directory
3267 Object_Dir : constant Variable_Value :=
3268 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3271 pragma Assert (Object_Dir.Kind = Single,
3272 "Object_Dir is not a single string");
3274 -- We set the object directory to its default
3276 Data.Object_Directory := Data.Directory;
3277 Data.Display_Object_Dir := Data.Display_Directory;
3279 if Object_Dir.Value /= Empty_String then
3281 Get_Name_String (Object_Dir.Value);
3283 if Name_Len = 0 then
3286 "Object_Dir cannot be empty",
3287 Object_Dir.Location);
3290 -- We check that the specified object directory
3294 (Object_Dir.Value, Data.Display_Directory,
3295 Data.Object_Directory, Data.Display_Object_Dir);
3297 if Data.Object_Directory = No_Name then
3298 -- The object directory does not exist, report an error
3299 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3302 "the object directory { cannot be found",
3305 -- Do not keep a nil Object_Directory. Set it to the
3306 -- specified (relative or absolute) path.
3307 -- This is for the benefit of tools that recover from
3308 -- errors; for example, these tools could create the
3309 -- non existent directory.
3311 Data.Display_Object_Dir := Object_Dir.Value;
3312 Get_Name_String (Object_Dir.Value);
3313 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3314 Data.Object_Directory := Name_Find;
3320 if Current_Verbosity = High then
3321 if Data.Object_Directory = No_Name then
3322 Write_Line ("No object directory");
3324 Write_Str ("Object directory: """);
3325 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3330 -- Check the exec directory
3333 Exec_Dir : constant Variable_Value :=
3334 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3337 pragma Assert (Exec_Dir.Kind = Single,
3338 "Exec_Dir is not a single string");
3340 -- We set the object directory to its default
3342 Data.Exec_Directory := Data.Object_Directory;
3343 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3345 if Exec_Dir.Value /= Empty_String then
3347 Get_Name_String (Exec_Dir.Value);
3349 if Name_Len = 0 then
3352 "Exec_Dir cannot be empty",
3356 -- We check that the specified object directory
3360 (Exec_Dir.Value, Data.Directory,
3361 Data.Exec_Directory, Data.Display_Exec_Dir);
3363 if Data.Exec_Directory = No_Name then
3364 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3367 "the exec directory { cannot be found",
3374 if Current_Verbosity = High then
3375 if Data.Exec_Directory = No_Name then
3376 Write_Line ("No exec directory");
3378 Write_Str ("Exec directory: """);
3379 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3384 -- Look for the source directories
3387 Source_Dirs : constant Variable_Value :=
3389 (Name_Source_Dirs, Data.Decl.Attributes);
3392 if Current_Verbosity = High then
3393 Write_Line ("Starting to look for source directories");
3396 pragma Assert (Source_Dirs.Kind = List,
3397 "Source_Dirs is not a list");
3399 if Source_Dirs.Default then
3401 -- No Source_Dirs specified: the single source directory
3402 -- is the one containing the project file
3404 String_Elements.Increment_Last;
3405 Data.Source_Dirs := String_Elements.Last;
3406 String_Elements.Table (Data.Source_Dirs) :=
3407 (Value => Data.Directory,
3408 Display_Value => Data.Display_Directory,
3409 Location => No_Location,
3414 if Current_Verbosity = High then
3415 Write_Line ("Single source directory:");
3417 Write_Str (Get_Name_String (Data.Display_Directory));
3421 elsif Source_Dirs.Values = Nil_String then
3423 -- If Source_Dirs is an empty string list, this means
3424 -- that this project contains no source. For projects that
3425 -- don't extend other projects, this also means that there is no
3426 -- need for an object directory, if not specified.
3428 if Data.Extends = No_Project
3429 and then Data.Object_Directory = Data.Directory
3431 Data.Object_Directory := No_Name;
3434 Data.Source_Dirs := Nil_String;
3435 Data.Sources_Present := False;
3439 Source_Dir : String_List_Id := Source_Dirs.Values;
3440 Element : String_Element;
3443 -- We will find the source directories for each
3444 -- element of the list
3446 while Source_Dir /= Nil_String loop
3447 Element := String_Elements.Table (Source_Dir);
3448 Find_Source_Dirs (Element.Value, Element.Location);
3449 Source_Dir := Element.Next;
3454 if Current_Verbosity = High then
3455 Write_Line ("Putting source directories in canonical cases");
3459 Current : String_List_Id := Data.Source_Dirs;
3460 Element : String_Element;
3463 while Current /= Nil_String loop
3464 Element := String_Elements.Table (Current);
3465 if Element.Value /= No_Name then
3466 Get_Name_String (Element.Value);
3467 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3468 Element.Value := Name_Find;
3469 String_Elements.Table (Current) := Element;
3472 Current := Element.Next;
3477 -- Library attributes
3480 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3482 Lib_Dir : constant Prj.Variable_Value :=
3483 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3485 Lib_Name : constant Prj.Variable_Value :=
3486 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3488 Lib_Version : constant Prj.Variable_Value :=
3490 (Snames.Name_Library_Version, Attributes);
3492 The_Lib_Kind : constant Prj.Variable_Value :=
3494 (Snames.Name_Library_Kind, Attributes);
3497 -- Special case of extending project
3499 if Data.Extends /= No_Project then
3501 Extended_Data : constant Project_Data :=
3502 Projects.Table (Data.Extends);
3505 -- If the project extended is a library project, we inherit
3506 -- the library name, if it is not redefined; we check that
3507 -- the library directory is specified; and we reset the
3508 -- library flag for the extended project.
3510 if Extended_Data.Library then
3511 if Lib_Name.Default then
3512 Data.Library_Name := Extended_Data.Library_Name;
3515 if Lib_Dir.Default then
3517 -- If the extending project is a virtual project, we
3518 -- put the error message in the library project that
3519 -- is extended, rather than in the extending all project.
3520 -- Of course, we cannot put it in the virtual extending
3521 -- project, because it has no source.
3523 if Data.Virtual then
3524 Error_Msg_Name_1 := Extended_Data.Name;
3528 "library project % cannot be virtually extended",
3529 Extended_Data.Location);
3534 "a project extending a library project must " &
3535 "specify an attribute Library_Dir",
3540 Projects.Table (Data.Extends).Library := False;
3545 pragma Assert (Lib_Dir.Kind = Single);
3547 if Lib_Dir.Value = Empty_String then
3549 if Current_Verbosity = High then
3550 Write_Line ("No library directory");
3554 -- Find path name, check that it is a directory
3557 (Lib_Dir.Value, Data.Display_Directory,
3558 Data.Library_Dir, Data.Display_Library_Dir);
3560 if Data.Library_Dir = No_Name then
3562 -- Get the absolute name of the library directory that
3563 -- does not exist, to report an error.
3566 Dir_Name : constant String :=
3567 Get_Name_String (Lib_Dir.Value);
3569 if Is_Absolute_Path (Dir_Name) then
3570 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3573 Get_Name_String (Data.Display_Directory);
3575 if Name_Buffer (Name_Len) /= Directory_Separator then
3576 Name_Len := Name_Len + 1;
3577 Name_Buffer (Name_Len) := Directory_Separator;
3581 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3583 Name_Len := Name_Len + Dir_Name'Length;
3584 Err_Vars.Error_Msg_Name_1 := Name_Find;
3591 "library directory { does not exist",
3595 elsif Data.Library_Dir = Data.Object_Directory then
3598 "library directory cannot be the same " &
3599 "as object directory",
3601 Data.Library_Dir := No_Name;
3602 Data.Display_Library_Dir := No_Name;
3605 if Current_Verbosity = High then
3606 Write_Str ("Library directory =""");
3607 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3613 pragma Assert (Lib_Name.Kind = Single);
3615 if Lib_Name.Value = Empty_String then
3616 if Current_Verbosity = High
3617 and then Data.Library_Name = No_Name
3619 Write_Line ("No library name");
3623 -- There is no restriction on the syntax of library names
3625 Data.Library_Name := Lib_Name.Value;
3628 if Data.Library_Name /= No_Name
3629 and then Current_Verbosity = High
3631 Write_Str ("Library name = """);
3632 Write_Str (Get_Name_String (Data.Library_Name));
3637 Data.Library_Dir /= No_Name
3639 Data.Library_Name /= No_Name;
3641 if Data.Library then
3642 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3645 "?libraries are not supported on this platform",
3647 Data.Library := False;
3650 pragma Assert (Lib_Version.Kind = Single);
3652 if Lib_Version.Value = Empty_String then
3653 if Current_Verbosity = High then
3654 Write_Line ("No library version specified");
3658 Data.Lib_Internal_Name := Lib_Version.Value;
3661 pragma Assert (The_Lib_Kind.Kind = Single);
3663 if The_Lib_Kind.Value = Empty_String then
3664 if Current_Verbosity = High then
3665 Write_Line ("No library kind specified");
3669 Get_Name_String (The_Lib_Kind.Value);
3672 Kind_Name : constant String :=
3673 To_Lower (Name_Buffer (1 .. Name_Len));
3675 OK : Boolean := True;
3678 if Kind_Name = "static" then
3679 Data.Library_Kind := Static;
3681 elsif Kind_Name = "dynamic" then
3682 Data.Library_Kind := Dynamic;
3684 elsif Kind_Name = "relocatable" then
3685 Data.Library_Kind := Relocatable;
3690 "illegal value for Library_Kind",
3691 The_Lib_Kind.Location);
3695 if Current_Verbosity = High and then OK then
3696 Write_Str ("Library kind = ");
3697 Write_Line (Kind_Name);
3700 if Data.Library_Kind /= Static and then
3701 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3705 "only static libraries are supported " &
3707 The_Lib_Kind.Location);
3708 Data.Library := False;
3713 if Data.Library and then Current_Verbosity = High then
3714 Write_Line ("This is a library project file");
3721 if Current_Verbosity = High then
3722 Show_Source_Dirs (Project);
3726 Naming_Id : constant Package_Id :=
3727 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3729 Naming : Package_Element;
3732 -- If there is a package Naming, we will put in Data.Naming
3733 -- what is in this package Naming.
3735 if Naming_Id /= No_Package then
3736 Naming := Packages.Table (Naming_Id);
3738 if Current_Verbosity = High then
3739 Write_Line ("Checking ""Naming"".");
3742 -- Check Spec_Suffix
3745 Spec_Suffixs : Array_Element_Id :=
3748 Naming.Decl.Arrays);
3749 Suffix : Array_Element_Id;
3750 Element : Array_Element;
3751 Suffix2 : Array_Element_Id;
3754 -- If some suffixs have been specified, we make sure that
3755 -- for each language for which a default suffix has been
3756 -- specified, there is a suffix specified, either the one
3757 -- in the project file or if there were none, the default.
3759 if Spec_Suffixs /= No_Array_Element then
3760 Suffix := Data.Naming.Spec_Suffix;
3762 while Suffix /= No_Array_Element loop
3763 Element := Array_Elements.Table (Suffix);
3764 Suffix2 := Spec_Suffixs;
3766 while Suffix2 /= No_Array_Element loop
3767 exit when Array_Elements.Table (Suffix2).Index =
3769 Suffix2 := Array_Elements.Table (Suffix2).Next;
3772 -- There is a registered default suffix, but no
3773 -- suffix specified in the project file.
3774 -- Add the default to the array.
3776 if Suffix2 = No_Array_Element then
3777 Array_Elements.Increment_Last;
3778 Array_Elements.Table (Array_Elements.Last) :=
3779 (Index => Element.Index,
3780 Src_Index => Element.Src_Index,
3781 Index_Case_Sensitive => False,
3782 Value => Element.Value,
3783 Next => Spec_Suffixs);
3784 Spec_Suffixs := Array_Elements.Last;
3787 Suffix := Element.Next;
3790 -- Put the resulting array as the specification suffixs
3792 Data.Naming.Spec_Suffix := Spec_Suffixs;
3797 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3798 Element : Array_Element;
3801 while Current /= No_Array_Element loop
3802 Element := Array_Elements.Table (Current);
3803 Get_Name_String (Element.Value.Value);
3805 if Name_Len = 0 then
3808 "Spec_Suffix cannot be empty",
3809 Element.Value.Location);
3812 Array_Elements.Table (Current) := Element;
3813 Current := Element.Next;
3817 -- Check Body_Suffix
3820 Impl_Suffixs : Array_Element_Id :=
3823 Naming.Decl.Arrays);
3825 Suffix : Array_Element_Id;
3826 Element : Array_Element;
3827 Suffix2 : Array_Element_Id;
3830 -- If some suffixs have been specified, we make sure that
3831 -- for each language for which a default suffix has been
3832 -- specified, there is a suffix specified, either the one
3833 -- in the project file or if there were noe, the default.
3835 if Impl_Suffixs /= No_Array_Element then
3836 Suffix := Data.Naming.Body_Suffix;
3838 while Suffix /= No_Array_Element loop
3839 Element := Array_Elements.Table (Suffix);
3840 Suffix2 := Impl_Suffixs;
3842 while Suffix2 /= No_Array_Element loop
3843 exit when Array_Elements.Table (Suffix2).Index =
3845 Suffix2 := Array_Elements.Table (Suffix2).Next;
3848 -- There is a registered default suffix, but no
3849 -- suffix specified in the project file.
3850 -- Add the default to the array.
3852 if Suffix2 = No_Array_Element then
3853 Array_Elements.Increment_Last;
3854 Array_Elements.Table (Array_Elements.Last) :=
3855 (Index => Element.Index,
3856 Src_Index => Element.Src_Index,
3857 Index_Case_Sensitive => False,
3858 Value => Element.Value,
3859 Next => Impl_Suffixs);
3860 Impl_Suffixs := Array_Elements.Last;
3863 Suffix := Element.Next;
3866 -- Put the resulting array as the implementation suffixs
3868 Data.Naming.Body_Suffix := Impl_Suffixs;
3873 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3874 Element : Array_Element;
3877 while Current /= No_Array_Element loop
3878 Element := Array_Elements.Table (Current);
3879 Get_Name_String (Element.Value.Value);
3881 if Name_Len = 0 then
3884 "Body_Suffix cannot be empty",
3885 Element.Value.Location);
3888 Array_Elements.Table (Current) := Element;
3889 Current := Element.Next;
3893 -- Get the exceptions, if any
3895 Data.Naming.Specification_Exceptions :=
3897 (Name_Specification_Exceptions,
3898 In_Arrays => Naming.Decl.Arrays);
3900 Data.Naming.Implementation_Exceptions :=
3902 (Name_Implementation_Exceptions,
3903 In_Arrays => Naming.Decl.Arrays);
3907 Projects.Table (Project) := Data;
3908 end Language_Independent_Check;
3910 ----------------------
3911 -- Locate_Directory --
3912 ----------------------
3914 procedure Locate_Directory
3918 Display : out Name_Id)
3920 The_Name : constant String := Get_Name_String (Name);
3921 The_Parent : constant String :=
3922 Get_Name_String (Parent) & Directory_Separator;
3923 The_Parent_Last : constant Natural :=
3924 Compute_Directory_Last (The_Parent);
3927 if Current_Verbosity = High then
3928 Write_Str ("Locate_Directory (""");
3929 Write_Str (The_Name);
3930 Write_Str (""", """);
3931 Write_Str (The_Parent);
3938 if Is_Absolute_Path (The_Name) then
3939 if Is_Directory (The_Name) then
3941 Normed : constant String :=
3944 Resolve_Links => False,
3945 Case_Sensitive => True);
3947 Canonical_Path : constant String :=
3950 Resolve_Links => True,
3951 Case_Sensitive => False);
3954 Name_Len := Normed'Length;
3955 Name_Buffer (1 .. Name_Len) := Normed;
3956 Display := Name_Find;
3958 Name_Len := Canonical_Path'Length;
3959 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3966 Full_Path : constant String :=
3967 The_Parent (The_Parent'First .. The_Parent_Last) &
3971 if Is_Directory (Full_Path) then
3973 Normed : constant String :=
3976 Resolve_Links => False,
3977 Case_Sensitive => True);
3979 Canonical_Path : constant String :=
3982 Resolve_Links => True,
3983 Case_Sensitive => False);
3986 Name_Len := Normed'Length;
3987 Name_Buffer (1 .. Name_Len) := Normed;
3988 Display := Name_Find;
3990 Name_Len := Canonical_Path'Length;
3991 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3997 end Locate_Directory;
3999 ---------------------------
4000 -- Other_Languages_Check --
4001 ---------------------------
4003 procedure Other_Languages_Check
4004 (Project : Project_Id;
4005 Report_Error : Put_Line_Access) is
4007 Data : Project_Data;
4009 Languages : Variable_Value := Nil_Variable_Value;
4012 Language_Independent_Check (Project, Report_Error);
4014 Error_Report := Report_Error;
4016 Data := Projects.Table (Project);
4017 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
4019 Data.Sources_Present := Data.Source_Dirs /= Nil_String;
4021 if Data.Sources_Present then
4022 -- Check if languages other than Ada are specified in this project
4024 if Languages.Default then
4025 -- Attribute Languages is not specified. So, it defaults to
4026 -- a project of language Ada only.
4028 Data.Languages (Lang_Ada) := True;
4030 -- No sources of languages other than Ada
4032 Data.Sources_Present := False;
4036 Current : String_List_Id := Languages.Values;
4037 Element : String_Element;
4038 OK : Boolean := False;
4040 -- Assumethat there is no language other than Ada specified.
4041 -- If in fact there is at least one, we will set back
4042 -- Sources_Present to True.
4044 Data.Sources_Present := False;
4046 -- Look through all the languages specified in attribute
4047 -- Languages, if any
4049 while Current /= Nil_String loop
4050 Element := String_Elements.Table (Current);
4051 Get_Name_String (Element.Value);
4052 To_Lower (Name_Buffer (1 .. Name_Len));
4055 -- Check if it is a known language
4057 Lang_Loop : for Lang in Programming_Language loop
4059 Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4061 -- Yes, this is a known language
4065 -- Indicate the presence of this language
4066 Data.Languages (Lang) := True;
4068 -- If it is a language other than Ada, indicate that
4069 -- there should be some sources of a language other
4072 if Lang /= Lang_Ada then
4073 Data.Sources_Present := True;
4080 -- We don't support this language: report an error
4083 Error_Msg_Name_1 := Element.Value;
4086 "unknown programming language {",
4090 Current := Element.Next;
4096 -- If there may be some sources, look for them
4098 if Data.Sources_Present then
4099 -- Set Source_Present to False. It will be set back to True whenever
4100 -- a source is found.
4102 Data.Sources_Present := False;
4104 for Lang in Other_Programming_Language loop
4105 -- For each language (other than Ada) in the project file
4107 if Data.Languages (Lang) then
4108 -- Reset the indication that there are sources of this
4109 -- language. It will be set back to True whenever we find a
4110 -- source of the language.
4112 Data.Languages (Lang) := False;
4114 -- First, get the source suffix for the language
4116 Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4118 -- Then, deal with the naming exceptions, if any
4123 Naming_Exceptions : constant Variable_Value :=
4125 (Index => Lang_Name_Ids (Lang),
4127 In_Array => Data.Naming.Implementation_Exceptions);
4128 Element_Id : String_List_Id;
4129 Element : String_Element;
4131 Source_Found : Boolean := False;
4133 -- If there are naming exceptions, look through them one
4136 if Naming_Exceptions /= Nil_Variable_Value then
4137 Element_Id := Naming_Exceptions.Values;
4139 while Element_Id /= Nil_String loop
4140 Element := String_Elements.Table (Element_Id);
4141 Get_Name_String (Element.Value);
4142 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4143 File_Id := Name_Find;
4145 -- Put each naming exception in the Source_Names
4146 -- hash table, but if there are repetition, don't
4147 -- bother after the first instance.
4149 if Source_Names.Get (File_Id) = No_Name_Location then
4150 Source_Found := True;
4154 Location => Element.Location,
4158 Element_Id := Element.Next;
4161 -- If there is at least one naming exception, record
4162 -- those that are found in the source directories.
4164 if Source_Found then
4165 Record_Other_Sources
4166 (Project => Project,
4169 Naming_Exceptions => True);
4175 -- Now, check if a list of sources is declared either through
4176 -- a string list (attribute Source_Files) or a text file
4177 -- (attribute Source_List_File).
4178 -- If a source list is declared, we will consider only those
4179 -- naming exceptions that are on the list.
4182 Sources : constant Variable_Value :=
4185 Data.Decl.Attributes);
4187 Source_List_File : constant Variable_Value :=
4189 (Name_Source_List_File,
4190 Data.Decl.Attributes);
4194 (Sources.Kind = List,
4195 "Source_Files is not a list");
4198 (Source_List_File.Kind = Single,
4199 "Source_List_File is not a single string");
4201 if not Sources.Default then
4202 if not Source_List_File.Default then
4205 "?both variables source_files and " &
4206 "source_list_file are present",
4207 Source_List_File.Location);
4210 -- Sources is a list of file names
4213 Current : String_List_Id := Sources.Values;
4214 Element : String_Element;
4215 Location : Source_Ptr;
4221 -- Put all the sources in the Source_Names hash
4224 while Current /= Nil_String loop
4225 Element := String_Elements.Table (Current);
4226 Get_Name_String (Element.Value);
4227 Canonical_Case_File_Name
4228 (Name_Buffer (1 .. Name_Len));
4231 -- If the element has no location, then use the
4232 -- location of Sources to report possible errors.
4234 if Element.Location = No_Location then
4235 Location := Sources.Location;
4238 Location := Element.Location;
4245 Location => Location,
4248 Current := Element.Next;
4251 -- And look for their directories
4253 Record_Other_Sources
4254 (Project => Project,
4257 Naming_Exceptions => False);
4260 -- No source_files specified.
4261 -- We check if Source_List_File has been specified.
4263 elsif not Source_List_File.Default then
4265 -- Source_List_File is the name of the file
4266 -- that contains the source file names
4269 Source_File_Path_Name : constant String :=
4271 (Source_List_File.Value,
4275 if Source_File_Path_Name'Length = 0 then
4276 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4279 "file with sources { does not exist",
4280 Source_List_File.Location);
4283 -- Read the file, putting each source in the
4284 -- Source_Names hash table.
4286 Get_Sources_From_File
4287 (Source_File_Path_Name,
4288 Source_List_File.Location,
4291 -- And look for their directories.
4293 Record_Other_Sources
4294 (Project => Project,
4297 Naming_Exceptions => False);
4302 -- Neither Source_Files nor Source_List_File has been
4303 -- specified. Find all the files that satisfy
4304 -- the naming scheme in all the source directories.
4305 -- All the naming exceptions that effectively exist are
4306 -- also part of the source of this language.
4308 Find_Sources (Project, Data, Lang);
4316 -- Finally, get the mains, if any
4318 Get_Mains (Project, Data);
4320 Projects.Table (Project) := Data;
4322 end Other_Languages_Check;
4328 function Path_Name_Of
4329 (File_Name : Name_Id;
4330 Directory : Name_Id) return String
4332 Result : String_Access;
4333 The_Directory : constant String := Get_Name_String (Directory);
4336 Get_Name_String (File_Name);
4337 Result := Locate_Regular_File
4338 (File_Name => Name_Buffer (1 .. Name_Len),
4339 Path => The_Directory);
4341 if Result = null then
4344 Canonical_Case_File_Name (Result.all);
4349 -------------------------------
4350 -- Prepare_Ada_Naming_Exceptions --
4351 -------------------------------
4353 procedure Prepare_Ada_Naming_Exceptions
4354 (List : Array_Element_Id;
4355 Kind : Spec_Or_Body)
4357 Current : Array_Element_Id := List;
4358 Element : Array_Element;
4363 -- Traverse the list
4365 while Current /= No_Array_Element loop
4366 Element := Array_Elements.Table (Current);
4368 if Element.Index /= No_Name then
4371 Unit => Element.Index,
4372 Next => No_Ada_Naming_Exception);
4373 Reverse_Ada_Naming_Exceptions.Set
4374 (Unit, (Element.Value.Value, Element.Value.Index));
4375 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4376 Ada_Naming_Exception_Table.Increment_Last;
4377 Ada_Naming_Exception_Table.Table
4378 (Ada_Naming_Exception_Table.Last) := Unit;
4379 Ada_Naming_Exceptions.Set
4380 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4383 Current := Element.Next;
4385 end Prepare_Ada_Naming_Exceptions;
4387 ---------------------
4388 -- Project_Extends --
4389 ---------------------
4391 function Project_Extends
4392 (Extending : Project_Id;
4393 Extended : Project_Id) return Boolean
4395 Current : Project_Id := Extending;
4398 if Current = No_Project then
4401 elsif Current = Extended then
4405 Current := Projects.Table (Current).Extends;
4407 end Project_Extends;
4409 -----------------------
4410 -- Record_Ada_Source --
4411 -----------------------
4413 procedure Record_Ada_Source
4414 (File_Name : Name_Id;
4415 Path_Name : Name_Id;
4416 Project : Project_Id;
4417 Data : in out Project_Data;
4418 Location : Source_Ptr;
4419 Current_Source : in out String_List_Id;
4420 Source_Recorded : in out Boolean;
4421 Follow_Links : Boolean)
4423 Canonical_File_Name : Name_Id;
4424 Canonical_Path_Name : Name_Id;
4425 Exception_Id : Ada_Naming_Exception_Id;
4426 Unit_Name : Name_Id;
4427 Unit_Kind : Spec_Or_Body;
4428 Unit_Index : Int := 0;
4430 Name_Index : Name_And_Index;
4431 Needs_Pragma : Boolean;
4433 The_Location : Source_Ptr := Location;
4434 Previous_Source : constant String_List_Id := Current_Source;
4435 Except_Name : Name_And_Index := No_Name_And_Index;
4437 Unit_Prj : Unit_Project;
4439 File_Name_Recorded : Boolean := False;
4442 Get_Name_String (File_Name);
4443 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4444 Canonical_File_Name := Name_Find;
4447 Canonical_Path : constant String :=
4449 (Get_Name_String (Path_Name),
4450 Resolve_Links => Follow_Links,
4451 Case_Sensitive => False);
4454 Add_Str_To_Name_Buffer (Canonical_Path);
4455 Canonical_Path_Name := Name_Find;
4458 -- Find out the unit name, the unit kind and if it needs
4459 -- a specific SFN pragma.
4462 (Canonical_File_Name => Canonical_File_Name,
4463 Naming => Data.Naming,
4464 Exception_Id => Exception_Id,
4465 Unit_Name => Unit_Name,
4466 Unit_Kind => Unit_Kind,
4467 Needs_Pragma => Needs_Pragma);
4469 if Exception_Id = No_Ada_Naming_Exception and then
4472 if Current_Verbosity = High then
4474 Write_Str (Get_Name_String (Canonical_File_Name));
4475 Write_Line (""" is not a valid source file name (ignored).");
4480 -- Check to see if the source has been hidden by an exception,
4481 -- but only if it is not an exception.
4483 if not Needs_Pragma then
4485 Reverse_Ada_Naming_Exceptions.Get
4486 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4488 if Except_Name /= No_Name_And_Index then
4489 if Current_Verbosity = High then
4491 Write_Str (Get_Name_String (Canonical_File_Name));
4492 Write_Str (""" contains a unit that is found in """);
4493 Write_Str (Get_Name_String (Except_Name.Name));
4494 Write_Line (""" (ignored).");
4497 -- The file is not included in the source of the project,
4498 -- because it is hidden by the exception.
4499 -- So, there is nothing else to do.
4506 if Exception_Id /= No_Ada_Naming_Exception then
4507 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4508 Exception_Id := Info.Next;
4509 Info.Next := No_Ada_Naming_Exception;
4510 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4512 Unit_Name := Info.Unit;
4513 Unit_Index := Name_Index.Index;
4514 Unit_Kind := Info.Kind;
4516 -- Put the file name in the list of sources of the project
4518 if not File_Name_Recorded then
4519 String_Elements.Increment_Last;
4520 String_Elements.Table (String_Elements.Last) :=
4521 (Value => Canonical_File_Name,
4522 Display_Value => File_Name,
4523 Location => No_Location,
4526 Index => Unit_Index);
4529 if Current_Source = Nil_String then
4530 Data.Sources := String_Elements.Last;
4533 String_Elements.Table (Current_Source).Next :=
4534 String_Elements.Last;
4537 Current_Source := String_Elements.Last;
4539 -- Put the unit in unit list
4542 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4543 The_Unit_Data : Unit_Data;
4546 if Current_Verbosity = High then
4547 Write_Str ("Putting ");
4548 Write_Str (Get_Name_String (Unit_Name));
4549 Write_Line (" in the unit list.");
4552 -- The unit is already in the list, but may be it is
4553 -- only the other unit kind (spec or body), or what is
4554 -- in the unit list is a unit of a project we are extending.
4556 if The_Unit /= Prj.Com.No_Unit then
4557 The_Unit_Data := Units.Table (The_Unit);
4559 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4560 or else Project_Extends
4562 The_Unit_Data.File_Names (Unit_Kind).Project)
4564 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4565 Remove_Forbidden_File_Name
4566 (The_Unit_Data.File_Names (Unit_Kind).Name);
4569 -- Record the file name in the hash table Files_Htable
4571 Unit_Prj := (Unit => The_Unit, Project => Project);
4572 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4574 The_Unit_Data.File_Names (Unit_Kind) :=
4575 (Name => Canonical_File_Name,
4576 Index => Unit_Index,
4577 Display_Name => File_Name,
4578 Path => Canonical_Path_Name,
4579 Display_Path => Path_Name,
4581 Needs_Pragma => Needs_Pragma);
4582 Units.Table (The_Unit) := The_Unit_Data;
4583 Source_Recorded := True;
4585 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4586 and then (Data.Known_Order_Of_Source_Dirs or else
4587 The_Unit_Data.File_Names (Unit_Kind).Path =
4588 Canonical_Path_Name)
4590 if Previous_Source = Nil_String then
4591 Data.Sources := Nil_String;
4593 String_Elements.Table (Previous_Source).Next :=
4595 String_Elements.Decrement_Last;
4598 Current_Source := Previous_Source;
4601 -- It is an error to have two units with the same name
4602 -- and the same kind (spec or body).
4604 if The_Location = No_Location then
4605 The_Location := Projects.Table (Project).Location;
4608 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4609 Error_Msg (Project, "duplicate source {", The_Location);
4611 Err_Vars.Error_Msg_Name_1 :=
4613 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4614 Err_Vars.Error_Msg_Name_2 :=
4615 The_Unit_Data.File_Names (Unit_Kind).Path;
4617 (Project, "\ project file {, {", The_Location);
4619 Err_Vars.Error_Msg_Name_1 :=
4620 Projects.Table (Project).Name;
4621 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4623 (Project, "\ project file {, {", The_Location);
4627 -- It is a new unit, create a new record
4630 -- First, check if there is no other unit with this file
4631 -- name in another project. If it is, report an error.
4632 -- Of course, we do that only for the first unit in the
4635 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4637 if not File_Name_Recorded and then
4638 Unit_Prj /= No_Unit_Project
4640 Error_Msg_Name_1 := File_Name;
4642 Projects.Table (Unit_Prj.Project).Name;
4645 "{ is already a source of project {",
4649 Units.Increment_Last;
4650 The_Unit := Units.Last;
4651 Units_Htable.Set (Unit_Name, The_Unit);
4652 Unit_Prj := (Unit => The_Unit, Project => Project);
4653 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4654 The_Unit_Data.Name := Unit_Name;
4655 The_Unit_Data.File_Names (Unit_Kind) :=
4656 (Name => Canonical_File_Name,
4657 Index => Unit_Index,
4658 Display_Name => File_Name,
4659 Path => Canonical_Path_Name,
4660 Display_Path => Path_Name,
4662 Needs_Pragma => Needs_Pragma);
4663 Units.Table (The_Unit) := The_Unit_Data;
4664 Source_Recorded := True;
4669 exit when Exception_Id = No_Ada_Naming_Exception;
4670 File_Name_Recorded := True;
4673 end Record_Ada_Source;
4675 --------------------------
4676 -- Record_Other_Sources --
4677 --------------------------
4679 procedure Record_Other_Sources
4680 (Project : Project_Id;
4681 Data : in out Project_Data;
4682 Language : Programming_Language;
4683 Naming_Exceptions : Boolean)
4685 Source_Dir : String_List_Id := Data.Source_Dirs;
4686 Element : String_Element;
4690 Canonical_Name : Name_Id;
4691 Name_Str : String (1 .. 1_024);
4692 Last : Natural := 0;
4695 First_Error : Boolean := True;
4697 Suffix : constant String :=
4698 Get_Name_String (Data.Impl_Suffixes (Language));
4701 while Source_Dir /= Nil_String loop
4702 Element := String_Elements.Table (Source_Dir);
4705 Dir_Path : constant String := Get_Name_String (Element.Value);
4707 if Current_Verbosity = High then
4708 Write_Str ("checking directory """);
4709 Write_Str (Dir_Path);
4710 Write_Str (""" for ");
4712 if Naming_Exceptions then
4713 Write_Str ("naming exceptions");
4716 Write_Str ("sources");
4719 Write_Str (" of Language ");
4720 Write_Line (Lang_Display_Names (Language).all);
4723 Open (Dir, Dir_Path);
4726 Read (Dir, Name_Str, Last);
4730 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4733 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4734 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4735 Canonical_Name := Name_Find;
4736 NL := Source_Names.Get (Canonical_Name);
4738 if NL /= No_Name_Location then
4740 if not Data.Known_Order_Of_Source_Dirs then
4741 Error_Msg_Name_1 := Canonical_Name;
4744 "{ is found in several source directories",
4750 Source_Names.Set (Canonical_Name, NL);
4751 Name_Len := Dir_Path'Length;
4752 Name_Buffer (1 .. Name_Len) := Dir_Path;
4753 Add_Char_To_Name_Buffer (Directory_Separator);
4754 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4758 (File_Name => Canonical_Name,
4762 Location => NL.Location,
4763 Language => Language,
4765 Naming_Exception => Naming_Exceptions);
4774 Source_Dir := Element.Next;
4777 if not Naming_Exceptions then
4779 NL := Source_Names.Get_First;
4781 -- It is an error if a source file name in a source list or
4782 -- in a source list file is not found.
4784 while NL /= No_Name_Location loop
4785 if not NL.Found then
4786 Err_Vars.Error_Msg_Name_1 := NL.Name;
4791 "source file { cannot be found",
4793 First_Error := False;
4798 "\source file { cannot be found",
4803 NL := Source_Names.Get_Next;
4806 -- Any naming exception of this language that is not in a list
4807 -- of sources must be removed.
4810 Source_Id : Other_Source_Id := Data.First_Other_Source;
4811 Prev_Id : Other_Source_Id := No_Other_Source;
4812 Source : Other_Source;
4814 while Source_Id /= No_Other_Source loop
4815 Source := Other_Sources.Table (Source_Id);
4817 if Source.Language = Language
4818 and then Source.Naming_Exception
4820 if Current_Verbosity = High then
4821 Write_Str ("Naming exception """);
4822 Write_Str (Get_Name_String (Source.File_Name));
4823 Write_Str (""" is not in the list of sources,");
4824 Write_Line (" so it is removed.");
4827 if Prev_Id = No_Other_Source then
4828 Data.First_Other_Source := Source.Next;
4831 Other_Sources.Table (Prev_Id).Next := Source.Next;
4834 Source_Id := Source.Next;
4836 if Source_Id = No_Other_Source then
4837 Data.Last_Other_Source := Prev_Id;
4841 Prev_Id := Source_Id;
4842 Source_Id := Source.Next;
4847 end Record_Other_Sources;
4849 ----------------------
4850 -- Show_Source_Dirs --
4851 ----------------------
4853 procedure Show_Source_Dirs (Project : Project_Id) is
4854 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4855 Element : String_Element;
4858 Write_Line ("Source_Dirs:");
4860 while Current /= Nil_String loop
4861 Element := String_Elements.Table (Current);
4863 Write_Line (Get_Name_String (Element.Value));
4864 Current := Element.Next;
4867 Write_Line ("end Source_Dirs.");
4868 end Show_Source_Dirs;
4875 (Language : Programming_Language;
4876 Naming : Naming_Data) return Name_Id
4878 Suffix : constant Variable_Value :=
4880 (Index => Lang_Name_Ids (Language),
4882 In_Array => Naming.Body_Suffix);
4884 -- If no suffix for this language is found in package Naming, use the
4887 if Suffix = Nil_Variable_Value then
4889 Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4891 -- Otherwise use the one specified
4894 Get_Name_String (Suffix.Value);
4897 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));