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_Name
155 -- Check that a name is a valid Ada unit name.
157 procedure Check_Ada_Naming_Scheme
158 (Data : in out Project_Data;
159 Project : Project_Id);
160 -- Check the naming scheme part of Data
162 procedure Check_Ada_Naming_Scheme_Validity
163 (Project : Project_Id;
164 Naming : Naming_Data);
165 -- Check that the package Naming is correct.
167 procedure Check_For_Source
168 (File_Name : Name_Id;
170 Project : Project_Id;
171 Data : in out Project_Data;
172 Location : Source_Ptr;
173 Language : Other_Programming_Language;
175 Naming_Exception : Boolean);
176 -- Check if a file in a source directory is a source for a specific
177 -- language other than Ada.
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.Ada_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.Ada_Sources_Present := False;
574 Check_Ada_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.Ada_Sources_Present then
582 if Data.Source_Dirs = Nil_String then
583 Data.Ada_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.Ada_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.Ada_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
1758 Data.Other_Sources_Present := True;
1760 -- And there are sources of this language in this project
1762 Data.Languages (Language) := True;
1764 -- Add this source to the list of sources of languages other than
1765 -- Ada of the project.
1767 if Data.First_Other_Source = No_Other_Source then
1768 Data.First_Other_Source := Other_Sources.Last;
1771 Other_Sources.Table (Data.Last_Other_Source).Next :=
1775 Data.Last_Other_Source := Other_Sources.Last;
1778 end Check_For_Source;
1780 --------------------------------------
1781 -- Check_Ada_Naming_Scheme_Validity --
1782 --------------------------------------
1784 procedure Check_Ada_Naming_Scheme_Validity
1785 (Project : Project_Id;
1786 Naming : Naming_Data)
1789 -- Only check if we are not using the standard naming scheme
1791 if Naming /= Standard_Naming_Data then
1793 Dot_Replacement : constant String :=
1795 (Naming.Dot_Replacement);
1797 Spec_Suffix : constant String :=
1799 (Naming.Current_Spec_Suffix);
1801 Body_Suffix : constant String :=
1803 (Naming.Current_Body_Suffix);
1805 Separate_Suffix : constant String :=
1807 (Naming.Separate_Suffix);
1810 -- Dot_Replacement cannot
1812 -- - start or end with an alphanumeric
1813 -- - be a single '_'
1814 -- - start with an '_' followed by an alphanumeric
1815 -- - contain a '.' except if it is "."
1817 if Dot_Replacement'Length = 0
1818 or else Is_Alphanumeric
1819 (Dot_Replacement (Dot_Replacement'First))
1820 or else Is_Alphanumeric
1821 (Dot_Replacement (Dot_Replacement'Last))
1822 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1824 (Dot_Replacement'Length = 1
1827 (Dot_Replacement (Dot_Replacement'First + 1))))
1828 or else (Dot_Replacement'Length > 1
1830 Index (Source => Dot_Replacement,
1831 Pattern => ".") /= 0)
1835 '"' & Dot_Replacement &
1836 """ is illegal for Dot_Replacement.",
1837 Naming.Dot_Repl_Loc);
1843 if Is_Illegal_Suffix
1844 (Spec_Suffix, Dot_Replacement = ".")
1846 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1849 "{ is illegal for Spec_Suffix",
1850 Naming.Spec_Suffix_Loc);
1853 if Is_Illegal_Suffix
1854 (Body_Suffix, Dot_Replacement = ".")
1856 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1859 "{ is illegal for Body_Suffix",
1860 Naming.Body_Suffix_Loc);
1863 if Body_Suffix /= Separate_Suffix then
1864 if Is_Illegal_Suffix
1865 (Separate_Suffix, Dot_Replacement = ".")
1867 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1870 "{ is illegal for Separate_Suffix",
1871 Naming.Sep_Suffix_Loc);
1875 -- Spec_Suffix cannot have the same termination as
1876 -- Body_Suffix or Separate_Suffix
1878 if Spec_Suffix'Length <= Body_Suffix'Length
1880 Body_Suffix (Body_Suffix'Last -
1881 Spec_Suffix'Length + 1 ..
1882 Body_Suffix'Last) = Spec_Suffix
1888 """) cannot end with" &
1889 " Spec_Suffix (""" &
1890 Spec_Suffix & """).",
1891 Naming.Body_Suffix_Loc);
1894 if Body_Suffix /= Separate_Suffix
1895 and then Spec_Suffix'Length <= Separate_Suffix'Length
1898 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1900 Separate_Suffix'Last) = Spec_Suffix
1904 "Separate_Suffix (""" &
1906 """) cannot end with" &
1907 " Spec_Suffix (""" &
1908 Spec_Suffix & """).",
1909 Naming.Sep_Suffix_Loc);
1913 end Check_Ada_Naming_Scheme_Validity;
1915 -----------------------------
1916 -- Check_Ada_Naming_Scheme --
1917 -----------------------------
1919 procedure Check_Ada_Naming_Scheme
1920 (Data : in out Project_Data;
1921 Project : Project_Id)
1923 Naming_Id : constant Package_Id :=
1924 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1926 Naming : Package_Element;
1928 procedure Check_Unit_Names (List : Array_Element_Id);
1929 -- Check that a list of unit names contains only valid names.
1931 ----------------------
1932 -- Check_Unit_Names --
1933 ----------------------
1935 procedure Check_Unit_Names (List : Array_Element_Id) is
1936 Current : Array_Element_Id := List;
1937 Element : Array_Element;
1938 Unit_Name : Name_Id;
1941 -- Loop through elements of the string list
1943 while Current /= No_Array_Element loop
1944 Element := Array_Elements.Table (Current);
1946 -- Put file name in canonical case
1948 Get_Name_String (Element.Value.Value);
1949 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1950 Element.Value.Value := Name_Find;
1952 -- Check that it contains a valid unit name
1954 Get_Name_String (Element.Index);
1955 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1957 if Unit_Name = No_Name then
1958 Err_Vars.Error_Msg_Name_1 := Element.Index;
1961 "{ is not a valid unit name.",
1962 Element.Value.Location);
1965 if Current_Verbosity = High then
1966 Write_Str (" Unit (""");
1967 Write_Str (Get_Name_String (Unit_Name));
1971 Element.Index := Unit_Name;
1972 Array_Elements.Table (Current) := Element;
1975 Current := Element.Next;
1977 end Check_Unit_Names;
1979 -- Start of processing for Check_Ada_Naming_Scheme
1982 -- If there is a package Naming, we will put in Data.Naming what is in
1983 -- this package Naming.
1985 if Naming_Id /= No_Package then
1986 Naming := Packages.Table (Naming_Id);
1988 if Current_Verbosity = High then
1989 Write_Line ("Checking ""Naming"" for Ada.");
1993 Bodies : constant Array_Element_Id :=
1994 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
1996 Specs : constant Array_Element_Id :=
1997 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
2000 if Bodies /= No_Array_Element then
2002 -- We have elements in the array Body_Part
2004 if Current_Verbosity = High then
2005 Write_Line ("Found Bodies.");
2008 Data.Naming.Bodies := Bodies;
2009 Check_Unit_Names (Bodies);
2012 if Current_Verbosity = High then
2013 Write_Line ("No Bodies.");
2017 if Specs /= No_Array_Element then
2019 -- We have elements in the array Specs
2021 if Current_Verbosity = High then
2022 Write_Line ("Found Specs.");
2025 Data.Naming.Specs := Specs;
2026 Check_Unit_Names (Specs);
2029 if Current_Verbosity = High then
2030 Write_Line ("No Specs.");
2035 -- We are now checking if variables Dot_Replacement, Casing,
2036 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
2039 -- For each variable, if it does not exist, we do nothing,
2040 -- because we already have the default.
2042 -- Check Dot_Replacement
2045 Dot_Replacement : constant Variable_Value :=
2047 (Name_Dot_Replacement,
2048 Naming.Decl.Attributes);
2051 pragma Assert (Dot_Replacement.Kind = Single,
2052 "Dot_Replacement is not a single string");
2054 if not Dot_Replacement.Default then
2055 Get_Name_String (Dot_Replacement.Value);
2057 if Name_Len = 0 then
2060 "Dot_Replacement cannot be empty",
2061 Dot_Replacement.Location);
2064 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2065 Data.Naming.Dot_Replacement := Name_Find;
2066 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2071 if Current_Verbosity = High then
2072 Write_Str (" Dot_Replacement = """);
2073 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
2081 Casing_String : constant Variable_Value :=
2083 (Name_Casing, Naming.Decl.Attributes);
2086 pragma Assert (Casing_String.Kind = Single,
2087 "Casing is not a single string");
2089 if not Casing_String.Default then
2091 Casing_Image : constant String :=
2092 Get_Name_String (Casing_String.Value);
2095 Casing_Value : constant Casing_Type :=
2096 Value (Casing_Image);
2098 -- Ignore Casing on platforms where file names are
2099 -- case-insensitive.
2101 if not File_Names_Case_Sensitive then
2102 Data.Naming.Casing := All_Lower_Case;
2105 Data.Naming.Casing := Casing_Value;
2110 when Constraint_Error =>
2111 if Casing_Image'Length = 0 then
2114 "Casing cannot be an empty string",
2115 Casing_String.Location);
2118 Name_Len := Casing_Image'Length;
2119 Name_Buffer (1 .. Name_Len) := Casing_Image;
2120 Err_Vars.Error_Msg_Name_1 := Name_Find;
2123 "{ is not a correct Casing",
2124 Casing_String.Location);
2130 if Current_Verbosity = High then
2131 Write_Str (" Casing = ");
2132 Write_Str (Image (Data.Naming.Casing));
2137 -- Check Spec_Suffix
2140 Ada_Spec_Suffix : constant Variable_Value :=
2144 In_Array => Data.Naming.Spec_Suffix);
2147 if Ada_Spec_Suffix.Kind = Single
2148 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2150 Get_Name_String (Ada_Spec_Suffix.Value);
2151 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2152 Data.Naming.Current_Spec_Suffix := Name_Find;
2153 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2156 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2160 if Current_Verbosity = High then
2161 Write_Str (" Spec_Suffix = """);
2162 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2167 -- Check Body_Suffix
2170 Ada_Body_Suffix : constant Variable_Value :=
2174 In_Array => Data.Naming.Body_Suffix);
2177 if Ada_Body_Suffix.Kind = Single
2178 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2180 Get_Name_String (Ada_Body_Suffix.Value);
2181 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2182 Data.Naming.Current_Body_Suffix := Name_Find;
2183 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2186 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2190 if Current_Verbosity = High then
2191 Write_Str (" Body_Suffix = """);
2192 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
2197 -- Check Separate_Suffix
2200 Ada_Sep_Suffix : constant Variable_Value :=
2202 (Variable_Name => Name_Separate_Suffix,
2203 In_Variables => Naming.Decl.Attributes);
2206 if Ada_Sep_Suffix.Default then
2207 Data.Naming.Separate_Suffix :=
2208 Data.Naming.Current_Body_Suffix;
2211 Get_Name_String (Ada_Sep_Suffix.Value);
2213 if Name_Len = 0 then
2216 "Separate_Suffix cannot be empty",
2217 Ada_Sep_Suffix.Location);
2220 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2221 Data.Naming.Separate_Suffix := Name_Find;
2222 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
2227 if Current_Verbosity = High then
2228 Write_Str (" Separate_Suffix = """);
2229 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
2234 -- Check if Data.Naming is valid
2236 Check_Ada_Naming_Scheme_Validity (Project, Data.Naming);
2239 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2240 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2241 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
2243 end Check_Ada_Naming_Scheme;
2249 function Check_Project
2251 Root_Project : Project_Id;
2252 Extending : Boolean) return Boolean
2255 if P = Root_Project then
2258 elsif Extending then
2260 Data : Project_Data := Projects.Table (Root_Project);
2263 while Data.Extends /= No_Project loop
2264 if P = Data.Extends then
2268 Data := Projects.Table (Data.Extends);
2276 ----------------------------
2277 -- Compute_Directory_Last --
2278 ----------------------------
2280 function Compute_Directory_Last (Dir : String) return Natural is
2283 and then (Dir (Dir'Last - 1) = Directory_Separator
2284 or else Dir (Dir'Last - 1) = '/')
2286 return Dir'Last - 1;
2290 end Compute_Directory_Last;
2297 (Project : Project_Id;
2299 Flag_Location : Source_Ptr)
2301 Error_Buffer : String (1 .. 5_000);
2302 Error_Last : Natural := 0;
2303 Msg_Name : Natural := 0;
2304 First : Positive := Msg'First;
2306 procedure Add (C : Character);
2307 -- Add a character to the buffer
2309 procedure Add (S : String);
2310 -- Add a string to the buffer
2312 procedure Add (Id : Name_Id);
2313 -- Add a name to the buffer
2319 procedure Add (C : Character) is
2321 Error_Last := Error_Last + 1;
2322 Error_Buffer (Error_Last) := C;
2325 procedure Add (S : String) is
2327 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2328 Error_Last := Error_Last + S'Length;
2331 procedure Add (Id : Name_Id) is
2333 Get_Name_String (Id);
2334 Add (Name_Buffer (1 .. Name_Len));
2337 -- Start of processing for Error_Msg
2340 if Error_Report = null then
2341 Prj.Err.Error_Msg (Msg, Flag_Location);
2345 if Msg (First) = '\' then
2347 -- Continuation character, ignore.
2351 elsif Msg (First) = '?' then
2353 -- Warning character. It is always the first one in this package
2359 for Index in First .. Msg'Last loop
2360 if Msg (Index) = '{' or else Msg (Index) = '%' then
2362 -- Include a name between double quotes.
2364 Msg_Name := Msg_Name + 1;
2368 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2369 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2370 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2372 when others => null;
2383 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2390 procedure Find_Sources
2391 (Project : Project_Id;
2392 Data : in out Project_Data;
2393 For_Language : Programming_Language;
2394 Follow_Links : Boolean := False)
2396 Source_Dir : String_List_Id := Data.Source_Dirs;
2397 Element : String_Element;
2399 Current_Source : String_List_Id := Nil_String;
2400 Source_Recorded : Boolean := False;
2403 if Current_Verbosity = High then
2404 Write_Line ("Looking for sources:");
2407 -- For each subdirectory
2409 while Source_Dir /= Nil_String loop
2411 Source_Recorded := False;
2412 Element := String_Elements.Table (Source_Dir);
2413 if Element.Value /= No_Name then
2414 Get_Name_String (Element.Display_Value);
2417 Source_Directory : constant String :=
2418 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2419 Dir_Last : constant Natural :=
2420 Compute_Directory_Last (Source_Directory);
2423 if Current_Verbosity = High then
2424 Write_Str ("Source_Dir = ");
2425 Write_Line (Source_Directory);
2428 -- We look to every entry in the source directory
2430 Open (Dir, Source_Directory
2431 (Source_Directory'First .. Dir_Last));
2434 Read (Dir, Name_Buffer, Name_Len);
2436 if Current_Verbosity = High then
2437 Write_Str (" Checking ");
2438 Write_Line (Name_Buffer (1 .. Name_Len));
2441 exit when Name_Len = 0;
2444 File_Name : constant Name_Id := Name_Find;
2445 Path : constant String :=
2447 (Name => Name_Buffer (1 .. Name_Len),
2448 Directory => Source_Directory
2449 (Source_Directory'First .. Dir_Last),
2450 Resolve_Links => Follow_Links,
2451 Case_Sensitive => True);
2452 Path_Name : Name_Id;
2455 Name_Len := Path'Length;
2456 Name_Buffer (1 .. Name_Len) := Path;
2457 Path_Name := Name_Find;
2459 if For_Language = Lang_Ada then
2460 -- We attempt to register it as a source.
2461 -- However, there is no error if the file
2462 -- does not contain a valid source.
2463 -- But there is an error if we have a
2464 -- duplicate unit name.
2467 (File_Name => File_Name,
2468 Path_Name => Path_Name,
2471 Location => No_Location,
2472 Current_Source => Current_Source,
2473 Source_Recorded => Source_Recorded,
2474 Follow_Links => Follow_Links);
2478 (File_Name => File_Name,
2479 Path_Name => Path_Name,
2482 Location => No_Location,
2483 Language => For_Language,
2486 (Data.Impl_Suffixes (For_Language)),
2487 Naming_Exception => False);
2497 when Directory_Error =>
2501 if Source_Recorded then
2502 String_Elements.Table (Source_Dir).Flag := True;
2505 Source_Dir := Element.Next;
2508 if Current_Verbosity = High then
2509 Write_Line ("end Looking for sources.");
2512 if For_Language = Lang_Ada then
2513 -- If we have looked for sources and found none, then
2514 -- it is an error, except if it is an extending project.
2515 -- If a non extending project is not supposed to contain
2516 -- any source, then we never call Find_Sources.
2518 if Current_Source /= Nil_String then
2519 Data.Ada_Sources_Present := True;
2521 elsif Data.Extends = No_Project then
2524 "there are no Ada sources in this project",
2530 --------------------------------
2531 -- Free_Ada_Naming_Exceptions --
2532 --------------------------------
2534 procedure Free_Ada_Naming_Exceptions is
2536 Ada_Naming_Exception_Table.Set_Last (0);
2537 Ada_Naming_Exceptions.Reset;
2538 Reverse_Ada_Naming_Exceptions.Reset;
2539 end Free_Ada_Naming_Exceptions;
2545 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2546 Mains : constant Variable_Value :=
2547 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2550 Data.Mains := Mains.Values;
2552 -- If no Mains were specified, and if we are an extending
2553 -- project, inherit the Mains from the project we are extending.
2555 if Mains.Default then
2556 if Data.Extends /= No_Project then
2557 Data.Mains := Projects.Table (Data.Extends).Mains;
2560 -- In a library project file, Main cannot be specified
2562 elsif Data.Library then
2565 "a library project file cannot have Main specified",
2570 ---------------------------
2571 -- Get_Sources_From_File --
2572 ---------------------------
2574 procedure Get_Sources_From_File
2576 Location : Source_Ptr;
2577 Project : Project_Id)
2579 File : Prj.Util.Text_File;
2580 Line : String (1 .. 250);
2582 Source_Name : Name_Id;
2587 if Current_Verbosity = High then
2588 Write_Str ("Opening """);
2595 Prj.Util.Open (File, Path);
2597 if not Prj.Util.Is_Valid (File) then
2598 Error_Msg (Project, "file does not exist", Location);
2600 -- Read the lines one by one
2602 while not Prj.Util.End_Of_File (File) loop
2603 Prj.Util.Get_Line (File, Line, Last);
2605 -- A non empty, non comment line should contain a file name
2608 and then (Last = 1 or else Line (1 .. 2) /= "--")
2610 -- ??? we should check that there is no directory information
2613 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2614 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2615 Source_Name := Name_Find;
2619 (Name => Source_Name,
2620 Location => Location,
2625 Prj.Util.Close (File);
2628 end Get_Sources_From_File;
2635 (Canonical_File_Name : Name_Id;
2636 Naming : Naming_Data;
2637 Exception_Id : out Ada_Naming_Exception_Id;
2638 Unit_Name : out Name_Id;
2639 Unit_Kind : out Spec_Or_Body;
2640 Needs_Pragma : out Boolean)
2642 Info_Id : Ada_Naming_Exception_Id
2643 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
2647 if Info_Id = No_Ada_Naming_Exception then
2648 if Hostparm.OpenVMS then
2649 VMS_Name := Canonical_File_Name;
2650 Get_Name_String (VMS_Name);
2652 if Name_Buffer (Name_Len) = '.' then
2653 Name_Len := Name_Len - 1;
2654 VMS_Name := Name_Find;
2657 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
2662 if Info_Id /= No_Ada_Naming_Exception then
2663 Exception_Id := Info_Id;
2664 Unit_Name := No_Name;
2665 Unit_Kind := Specification;
2666 Needs_Pragma := True;
2670 Needs_Pragma := False;
2671 Exception_Id := No_Ada_Naming_Exception;
2673 Get_Name_String (Canonical_File_Name);
2676 File : String := Name_Buffer (1 .. Name_Len);
2677 First : constant Positive := File'First;
2678 Last : Natural := File'Last;
2679 Standard_GNAT : Boolean;
2683 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2684 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2686 -- Check if the end of the file name is Specification_Append
2688 Get_Name_String (Naming.Current_Spec_Suffix);
2690 if File'Length > Name_Len
2691 and then File (Last - Name_Len + 1 .. Last) =
2692 Name_Buffer (1 .. Name_Len)
2696 Unit_Kind := Specification;
2697 Last := Last - Name_Len;
2699 if Current_Verbosity = High then
2700 Write_Str (" Specification: ");
2701 Write_Line (File (First .. Last));
2705 Get_Name_String (Naming.Current_Body_Suffix);
2707 -- Check if the end of the file name is Body_Append
2709 if File'Length > Name_Len
2710 and then File (Last - Name_Len + 1 .. Last) =
2711 Name_Buffer (1 .. Name_Len)
2715 Unit_Kind := Body_Part;
2716 Last := Last - Name_Len;
2718 if Current_Verbosity = High then
2719 Write_Str (" Body: ");
2720 Write_Line (File (First .. Last));
2723 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2724 Get_Name_String (Naming.Separate_Suffix);
2726 -- Check if the end of the file name is Separate_Append
2728 if File'Length > Name_Len
2729 and then File (Last - Name_Len + 1 .. Last) =
2730 Name_Buffer (1 .. Name_Len)
2732 -- We have a separate (a body)
2734 Unit_Kind := Body_Part;
2735 Last := Last - Name_Len;
2737 if Current_Verbosity = High then
2738 Write_Str (" Separate: ");
2739 Write_Line (File (First .. Last));
2753 -- This is not a source file
2755 Unit_Name := No_Name;
2756 Unit_Kind := Specification;
2758 if Current_Verbosity = High then
2759 Write_Line (" Not a valid file name.");
2765 Get_Name_String (Naming.Dot_Replacement);
2767 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2769 if Name_Buffer (1 .. Name_Len) /= "." then
2771 -- If Dot_Replacement is not a single dot,
2772 -- then there should not be any dot in the name.
2774 for Index in First .. Last loop
2775 if File (Index) = '.' then
2776 if Current_Verbosity = High then
2778 (" Not a valid file name (some dot not replaced).");
2781 Unit_Name := No_Name;
2787 -- Replace the substring Dot_Replacement with dots
2790 Index : Positive := First;
2793 while Index <= Last - Name_Len + 1 loop
2795 if File (Index .. Index + Name_Len - 1) =
2796 Name_Buffer (1 .. Name_Len)
2798 File (Index) := '.';
2800 if Name_Len > 1 and then Index < Last then
2801 File (Index + 1 .. Last - Name_Len + 1) :=
2802 File (Index + Name_Len .. Last);
2805 Last := Last - Name_Len + 1;
2813 -- Check if the casing is right
2816 Src : String := File (First .. Last);
2819 case Naming.Casing is
2820 when All_Lower_Case =>
2823 Mapping => Lower_Case_Map);
2825 when All_Upper_Case =>
2828 Mapping => Upper_Case_Map);
2830 when Mixed_Case | Unknown =>
2834 if Src /= File (First .. Last) then
2835 if Current_Verbosity = High then
2836 Write_Line (" Not a valid file name (casing).");
2839 Unit_Name := No_Name;
2843 -- We put the name in lower case
2847 Mapping => Lower_Case_Map);
2849 -- In the standard GNAT naming scheme, check for special cases:
2850 -- children or separates of A, G, I or S, and run time sources.
2852 if Standard_GNAT and then Src'Length >= 3 then
2854 S1 : constant Character := Src (Src'First);
2855 S2 : constant Character := Src (Src'First + 1);
2858 if S1 = 'a' or else S1 = 'g'
2859 or else S1 = 'i' or else S1 = 's'
2861 -- Children or separates of packages A, G, I or S
2863 if (Hostparm.OpenVMS and then S2 = '$')
2864 or else (not Hostparm.OpenVMS and then S2 = '~')
2866 Src (Src'First + 1) := '.';
2868 -- If it is potentially a run time source, disable
2869 -- filling of the mapping file to avoid warnings.
2872 Set_Mapping_File_Initial_State_To_Empty;
2879 if Current_Verbosity = High then
2884 -- Now, we check if this name is a valid unit name
2886 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2896 function Hash (Unit : Unit_Info) return Header_Num is
2898 return Header_Num (Unit.Unit mod 2048);
2901 -----------------------
2902 -- Is_Illegal_Suffix --
2903 -----------------------
2905 function Is_Illegal_Suffix
2907 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2910 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2914 -- If dot replacement is a single dot, and first character of
2915 -- suffix is also a dot
2917 if Dot_Replacement_Is_A_Single_Dot
2918 and then Suffix (Suffix'First) = '.'
2920 for Index in Suffix'First + 1 .. Suffix'Last loop
2922 -- If there is another dot
2924 if Suffix (Index) = '.' then
2926 -- It is illegal to have a letter following the initial dot
2928 return Is_Letter (Suffix (Suffix'First + 1));
2936 end Is_Illegal_Suffix;
2938 --------------------------------
2939 -- Language_Independent_Check --
2940 --------------------------------
2942 procedure Language_Independent_Check
2943 (Project : Project_Id;
2944 Report_Error : Put_Line_Access)
2946 Last_Source_Dir : String_List_Id := Nil_String;
2947 Data : Project_Data := Projects.Table (Project);
2949 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2950 -- Find one or several source directories, and add them
2951 -- to the list of source directories of the project.
2953 ----------------------
2954 -- Find_Source_Dirs --
2955 ----------------------
2957 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2958 Directory : constant String := Get_Name_String (From);
2959 Element : String_Element;
2961 procedure Recursive_Find_Dirs (Path : Name_Id);
2962 -- Find all the subdirectories (recursively) of Path and add them
2963 -- to the list of source directories of the project.
2965 -------------------------
2966 -- Recursive_Find_Dirs --
2967 -------------------------
2969 procedure Recursive_Find_Dirs (Path : Name_Id) is
2971 Name : String (1 .. 250);
2973 List : String_List_Id := Data.Source_Dirs;
2974 Element : String_Element;
2975 Found : Boolean := False;
2977 Non_Canonical_Path : Name_Id := No_Name;
2978 Canonical_Path : Name_Id := No_Name;
2980 The_Path : constant String :=
2981 Normalize_Pathname (Get_Name_String (Path)) &
2982 Directory_Separator;
2984 The_Path_Last : constant Natural :=
2985 Compute_Directory_Last (The_Path);
2988 Name_Len := The_Path_Last - The_Path'First + 1;
2989 Name_Buffer (1 .. Name_Len) :=
2990 The_Path (The_Path'First .. The_Path_Last);
2991 Non_Canonical_Path := Name_Find;
2992 Get_Name_String (Non_Canonical_Path);
2993 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2994 Canonical_Path := Name_Find;
2996 -- To avoid processing the same directory several times, check
2997 -- if the directory is already in Recursive_Dirs. If it is,
2998 -- then there is nothing to do, just return. If it is not, put
2999 -- it there and continue recursive processing.
3001 if Recursive_Dirs.Get (Canonical_Path) then
3005 Recursive_Dirs.Set (Canonical_Path, True);
3008 -- Check if directory is already in list
3010 while List /= Nil_String loop
3011 Element := String_Elements.Table (List);
3013 if Element.Value /= No_Name then
3014 Found := Element.Value = Canonical_Path;
3018 List := Element.Next;
3021 -- If directory is not already in list, put it there
3024 if Current_Verbosity = High then
3026 Write_Line (The_Path (The_Path'First .. The_Path_Last));
3029 String_Elements.Increment_Last;
3031 (Value => Canonical_Path,
3032 Display_Value => Non_Canonical_Path,
3033 Location => No_Location,
3038 -- Case of first source directory
3040 if Last_Source_Dir = Nil_String then
3041 Data.Source_Dirs := String_Elements.Last;
3043 -- Here we already have source directories.
3046 -- Link the previous last to the new one
3048 String_Elements.Table (Last_Source_Dir).Next :=
3049 String_Elements.Last;
3052 -- And register this source directory as the new last
3054 Last_Source_Dir := String_Elements.Last;
3055 String_Elements.Table (Last_Source_Dir) := Element;
3058 -- Now look for subdirectories. We do that even when this
3059 -- directory is already in the list, because some of its
3060 -- subdirectories may not be in the list yet.
3062 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3065 Read (Dir, Name, Last);
3068 if Name (1 .. Last) /= "."
3069 and then Name (1 .. Last) /= ".."
3073 if Current_Verbosity = High then
3074 Write_Str (" Checking ");
3075 Write_Line (Name (1 .. Last));
3079 Path_Name : constant String :=
3081 (Name => Name (1 .. Last),
3084 (The_Path'First .. The_Path_Last),
3085 Resolve_Links => False,
3086 Case_Sensitive => True);
3089 if Is_Directory (Path_Name) then
3091 -- We have found a new subdirectory, call self
3093 Name_Len := Path_Name'Length;
3094 Name_Buffer (1 .. Name_Len) := Path_Name;
3095 Recursive_Find_Dirs (Name_Find);
3104 when Directory_Error =>
3106 end Recursive_Find_Dirs;
3108 -- Start of processing for Find_Source_Dirs
3111 if Current_Verbosity = High then
3112 Write_Str ("Find_Source_Dirs (""");
3113 Write_Str (Directory);
3117 -- First, check if we are looking for a directory tree,
3118 -- indicated by "/**" at the end.
3120 if Directory'Length >= 3
3121 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3122 and then (Directory (Directory'Last - 2) = '/'
3124 Directory (Directory'Last - 2) = Directory_Separator)
3126 Data.Known_Order_Of_Source_Dirs := False;
3128 Name_Len := Directory'Length - 3;
3130 if Name_Len = 0 then
3132 -- This is the case of "/**": all directories
3133 -- in the file system.
3136 Name_Buffer (1) := Directory (Directory'First);
3139 Name_Buffer (1 .. Name_Len) :=
3140 Directory (Directory'First .. Directory'Last - 3);
3143 if Current_Verbosity = High then
3144 Write_Str ("Looking for all subdirectories of """);
3145 Write_Str (Name_Buffer (1 .. Name_Len));
3150 Base_Dir : constant Name_Id := Name_Find;
3151 Root_Dir : constant String :=
3153 (Name => Get_Name_String (Base_Dir),
3155 Get_Name_String (Data.Display_Directory),
3156 Resolve_Links => False,
3157 Case_Sensitive => True);
3160 if Root_Dir'Length = 0 then
3161 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3163 if Location = No_Location then
3166 "{ is not a valid directory.",
3171 "{ is not a valid directory.",
3176 -- We have an existing directory,
3177 -- we register it and all of its subdirectories.
3179 if Current_Verbosity = High then
3180 Write_Line ("Looking for source directories:");
3183 Name_Len := Root_Dir'Length;
3184 Name_Buffer (1 .. Name_Len) := Root_Dir;
3185 Recursive_Find_Dirs (Name_Find);
3187 if Current_Verbosity = High then
3188 Write_Line ("End of looking for source directories.");
3193 -- We have a single directory
3197 Path_Name : Name_Id;
3198 Display_Path_Name : Name_Id;
3201 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3202 if Path_Name = No_Name then
3203 Err_Vars.Error_Msg_Name_1 := From;
3205 if Location = No_Location then
3208 "{ is not a valid directory",
3213 "{ is not a valid directory",
3218 -- As it is an existing directory, we add it to
3219 -- the list of directories.
3221 String_Elements.Increment_Last;
3222 Element.Value := Path_Name;
3223 Element.Display_Value := Display_Path_Name;
3225 if Last_Source_Dir = Nil_String then
3227 -- This is the first source directory
3229 Data.Source_Dirs := String_Elements.Last;
3232 -- We already have source directories,
3233 -- link the previous last to the new one.
3235 String_Elements.Table (Last_Source_Dir).Next :=
3236 String_Elements.Last;
3239 -- And register this source directory as the new last
3241 Last_Source_Dir := String_Elements.Last;
3242 String_Elements.Table (Last_Source_Dir) := Element;
3246 end Find_Source_Dirs;
3248 -- Start of processing for Language_Independent_Check
3251 if Data.Language_Independent_Checked then
3255 Data.Language_Independent_Checked := True;
3257 Error_Report := Report_Error;
3259 Recursive_Dirs.Reset;
3261 if Current_Verbosity = High then
3262 Write_Line ("Starting to look for directories");
3265 -- Check the object directory
3268 Object_Dir : constant Variable_Value :=
3269 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3272 pragma Assert (Object_Dir.Kind = Single,
3273 "Object_Dir is not a single string");
3275 -- We set the object directory to its default
3277 Data.Object_Directory := Data.Directory;
3278 Data.Display_Object_Dir := Data.Display_Directory;
3280 if Object_Dir.Value /= Empty_String then
3282 Get_Name_String (Object_Dir.Value);
3284 if Name_Len = 0 then
3287 "Object_Dir cannot be empty",
3288 Object_Dir.Location);
3291 -- We check that the specified object directory
3295 (Object_Dir.Value, Data.Display_Directory,
3296 Data.Object_Directory, Data.Display_Object_Dir);
3298 if Data.Object_Directory = No_Name then
3299 -- The object directory does not exist, report an error
3300 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3303 "the object directory { cannot be found",
3306 -- Do not keep a nil Object_Directory. Set it to the
3307 -- specified (relative or absolute) path.
3308 -- This is for the benefit of tools that recover from
3309 -- errors; for example, these tools could create the
3310 -- non existent directory.
3312 Data.Display_Object_Dir := Object_Dir.Value;
3313 Get_Name_String (Object_Dir.Value);
3314 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3315 Data.Object_Directory := Name_Find;
3321 if Current_Verbosity = High then
3322 if Data.Object_Directory = No_Name then
3323 Write_Line ("No object directory");
3325 Write_Str ("Object directory: """);
3326 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3331 -- Check the exec directory
3334 Exec_Dir : constant Variable_Value :=
3335 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3338 pragma Assert (Exec_Dir.Kind = Single,
3339 "Exec_Dir is not a single string");
3341 -- We set the object directory to its default
3343 Data.Exec_Directory := Data.Object_Directory;
3344 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3346 if Exec_Dir.Value /= Empty_String then
3348 Get_Name_String (Exec_Dir.Value);
3350 if Name_Len = 0 then
3353 "Exec_Dir cannot be empty",
3357 -- We check that the specified object directory
3361 (Exec_Dir.Value, Data.Directory,
3362 Data.Exec_Directory, Data.Display_Exec_Dir);
3364 if Data.Exec_Directory = No_Name then
3365 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3368 "the exec directory { cannot be found",
3375 if Current_Verbosity = High then
3376 if Data.Exec_Directory = No_Name then
3377 Write_Line ("No exec directory");
3379 Write_Str ("Exec directory: """);
3380 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3385 -- Look for the source directories
3388 Source_Dirs : constant Variable_Value :=
3390 (Name_Source_Dirs, Data.Decl.Attributes);
3393 if Current_Verbosity = High then
3394 Write_Line ("Starting to look for source directories");
3397 pragma Assert (Source_Dirs.Kind = List,
3398 "Source_Dirs is not a list");
3400 if Source_Dirs.Default then
3402 -- No Source_Dirs specified: the single source directory
3403 -- is the one containing the project file
3405 String_Elements.Increment_Last;
3406 Data.Source_Dirs := String_Elements.Last;
3407 String_Elements.Table (Data.Source_Dirs) :=
3408 (Value => Data.Directory,
3409 Display_Value => Data.Display_Directory,
3410 Location => No_Location,
3415 if Current_Verbosity = High then
3416 Write_Line ("Single source directory:");
3418 Write_Str (Get_Name_String (Data.Display_Directory));
3422 elsif Source_Dirs.Values = Nil_String then
3424 -- If Source_Dirs is an empty string list, this means
3425 -- that this project contains no source. For projects that
3426 -- don't extend other projects, this also means that there is no
3427 -- need for an object directory, if not specified.
3429 if Data.Extends = No_Project
3430 and then Data.Object_Directory = Data.Directory
3432 Data.Object_Directory := No_Name;
3435 Data.Source_Dirs := Nil_String;
3436 Data.Ada_Sources_Present := False;
3437 Data.Other_Sources_Present := False;
3441 Source_Dir : String_List_Id := Source_Dirs.Values;
3442 Element : String_Element;
3445 -- We will find the source directories for each
3446 -- element of the list
3448 while Source_Dir /= Nil_String loop
3449 Element := String_Elements.Table (Source_Dir);
3450 Find_Source_Dirs (Element.Value, Element.Location);
3451 Source_Dir := Element.Next;
3456 if Current_Verbosity = High then
3457 Write_Line ("Putting source directories in canonical cases");
3461 Current : String_List_Id := Data.Source_Dirs;
3462 Element : String_Element;
3465 while Current /= Nil_String loop
3466 Element := String_Elements.Table (Current);
3467 if Element.Value /= No_Name then
3468 Get_Name_String (Element.Value);
3469 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3470 Element.Value := Name_Find;
3471 String_Elements.Table (Current) := Element;
3474 Current := Element.Next;
3479 -- Library attributes
3482 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3484 Lib_Dir : constant Prj.Variable_Value :=
3485 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3487 Lib_Name : constant Prj.Variable_Value :=
3488 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3490 Lib_Version : constant Prj.Variable_Value :=
3492 (Snames.Name_Library_Version, Attributes);
3494 The_Lib_Kind : constant Prj.Variable_Value :=
3496 (Snames.Name_Library_Kind, Attributes);
3499 -- Special case of extending project
3501 if Data.Extends /= No_Project then
3503 Extended_Data : constant Project_Data :=
3504 Projects.Table (Data.Extends);
3507 -- If the project extended is a library project, we inherit
3508 -- the library name, if it is not redefined; we check that
3509 -- the library directory is specified; and we reset the
3510 -- library flag for the extended project.
3512 if Extended_Data.Library then
3513 if Lib_Name.Default then
3514 Data.Library_Name := Extended_Data.Library_Name;
3517 if Lib_Dir.Default then
3519 -- If the extending project is a virtual project, we
3520 -- put the error message in the library project that
3521 -- is extended, rather than in the extending all project.
3522 -- Of course, we cannot put it in the virtual extending
3523 -- project, because it has no source.
3525 if Data.Virtual then
3526 Error_Msg_Name_1 := Extended_Data.Name;
3530 "library project % cannot be virtually extended",
3531 Extended_Data.Location);
3536 "a project extending a library project must " &
3537 "specify an attribute Library_Dir",
3542 Projects.Table (Data.Extends).Library := False;
3547 pragma Assert (Lib_Dir.Kind = Single);
3549 if Lib_Dir.Value = Empty_String then
3551 if Current_Verbosity = High then
3552 Write_Line ("No library directory");
3556 -- Find path name, check that it is a directory
3559 (Lib_Dir.Value, Data.Display_Directory,
3560 Data.Library_Dir, Data.Display_Library_Dir);
3562 if Data.Library_Dir = No_Name then
3564 -- Get the absolute name of the library directory that
3565 -- does not exist, to report an error.
3568 Dir_Name : constant String :=
3569 Get_Name_String (Lib_Dir.Value);
3571 if Is_Absolute_Path (Dir_Name) then
3572 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3575 Get_Name_String (Data.Display_Directory);
3577 if Name_Buffer (Name_Len) /= Directory_Separator then
3578 Name_Len := Name_Len + 1;
3579 Name_Buffer (Name_Len) := Directory_Separator;
3583 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3585 Name_Len := Name_Len + Dir_Name'Length;
3586 Err_Vars.Error_Msg_Name_1 := Name_Find;
3593 "library directory { does not exist",
3597 elsif Data.Library_Dir = Data.Object_Directory then
3600 "library directory cannot be the same " &
3601 "as object directory",
3603 Data.Library_Dir := No_Name;
3604 Data.Display_Library_Dir := No_Name;
3607 if Current_Verbosity = High then
3608 Write_Str ("Library directory =""");
3609 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3615 pragma Assert (Lib_Name.Kind = Single);
3617 if Lib_Name.Value = Empty_String then
3618 if Current_Verbosity = High
3619 and then Data.Library_Name = No_Name
3621 Write_Line ("No library name");
3625 -- There is no restriction on the syntax of library names
3627 Data.Library_Name := Lib_Name.Value;
3630 if Data.Library_Name /= No_Name
3631 and then Current_Verbosity = High
3633 Write_Str ("Library name = """);
3634 Write_Str (Get_Name_String (Data.Library_Name));
3639 Data.Library_Dir /= No_Name
3641 Data.Library_Name /= No_Name;
3643 if Data.Library then
3644 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3647 "?libraries are not supported on this platform",
3649 Data.Library := False;
3652 pragma Assert (Lib_Version.Kind = Single);
3654 if Lib_Version.Value = Empty_String then
3655 if Current_Verbosity = High then
3656 Write_Line ("No library version specified");
3660 Data.Lib_Internal_Name := Lib_Version.Value;
3663 pragma Assert (The_Lib_Kind.Kind = Single);
3665 if The_Lib_Kind.Value = Empty_String then
3666 if Current_Verbosity = High then
3667 Write_Line ("No library kind specified");
3671 Get_Name_String (The_Lib_Kind.Value);
3674 Kind_Name : constant String :=
3675 To_Lower (Name_Buffer (1 .. Name_Len));
3677 OK : Boolean := True;
3680 if Kind_Name = "static" then
3681 Data.Library_Kind := Static;
3683 elsif Kind_Name = "dynamic" then
3684 Data.Library_Kind := Dynamic;
3686 elsif Kind_Name = "relocatable" then
3687 Data.Library_Kind := Relocatable;
3692 "illegal value for Library_Kind",
3693 The_Lib_Kind.Location);
3697 if Current_Verbosity = High and then OK then
3698 Write_Str ("Library kind = ");
3699 Write_Line (Kind_Name);
3702 if Data.Library_Kind /= Static and then
3703 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3707 "only static libraries are supported " &
3709 The_Lib_Kind.Location);
3710 Data.Library := False;
3715 if Data.Library and then Current_Verbosity = High then
3716 Write_Line ("This is a library project file");
3723 if Current_Verbosity = High then
3724 Show_Source_Dirs (Project);
3728 Naming_Id : constant Package_Id :=
3729 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3731 Naming : Package_Element;
3734 -- If there is a package Naming, we will put in Data.Naming
3735 -- what is in this package Naming.
3737 if Naming_Id /= No_Package then
3738 Naming := Packages.Table (Naming_Id);
3740 if Current_Verbosity = High then
3741 Write_Line ("Checking ""Naming"".");
3744 -- Check Spec_Suffix
3747 Spec_Suffixs : Array_Element_Id :=
3750 Naming.Decl.Arrays);
3751 Suffix : Array_Element_Id;
3752 Element : Array_Element;
3753 Suffix2 : Array_Element_Id;
3756 -- If some suffixs have been specified, we make sure that
3757 -- for each language for which a default suffix has been
3758 -- specified, there is a suffix specified, either the one
3759 -- in the project file or if there were none, the default.
3761 if Spec_Suffixs /= No_Array_Element then
3762 Suffix := Data.Naming.Spec_Suffix;
3764 while Suffix /= No_Array_Element loop
3765 Element := Array_Elements.Table (Suffix);
3766 Suffix2 := Spec_Suffixs;
3768 while Suffix2 /= No_Array_Element loop
3769 exit when Array_Elements.Table (Suffix2).Index =
3771 Suffix2 := Array_Elements.Table (Suffix2).Next;
3774 -- There is a registered default suffix, but no
3775 -- suffix specified in the project file.
3776 -- Add the default to the array.
3778 if Suffix2 = No_Array_Element then
3779 Array_Elements.Increment_Last;
3780 Array_Elements.Table (Array_Elements.Last) :=
3781 (Index => Element.Index,
3782 Src_Index => Element.Src_Index,
3783 Index_Case_Sensitive => False,
3784 Value => Element.Value,
3785 Next => Spec_Suffixs);
3786 Spec_Suffixs := Array_Elements.Last;
3789 Suffix := Element.Next;
3792 -- Put the resulting array as the specification suffixs
3794 Data.Naming.Spec_Suffix := Spec_Suffixs;
3799 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3800 Element : Array_Element;
3803 while Current /= No_Array_Element loop
3804 Element := Array_Elements.Table (Current);
3805 Get_Name_String (Element.Value.Value);
3807 if Name_Len = 0 then
3810 "Spec_Suffix cannot be empty",
3811 Element.Value.Location);
3814 Array_Elements.Table (Current) := Element;
3815 Current := Element.Next;
3819 -- Check Body_Suffix
3822 Impl_Suffixs : Array_Element_Id :=
3825 Naming.Decl.Arrays);
3827 Suffix : Array_Element_Id;
3828 Element : Array_Element;
3829 Suffix2 : Array_Element_Id;
3832 -- If some suffixs have been specified, we make sure that
3833 -- for each language for which a default suffix has been
3834 -- specified, there is a suffix specified, either the one
3835 -- in the project file or if there were noe, the default.
3837 if Impl_Suffixs /= No_Array_Element then
3838 Suffix := Data.Naming.Body_Suffix;
3840 while Suffix /= No_Array_Element loop
3841 Element := Array_Elements.Table (Suffix);
3842 Suffix2 := Impl_Suffixs;
3844 while Suffix2 /= No_Array_Element loop
3845 exit when Array_Elements.Table (Suffix2).Index =
3847 Suffix2 := Array_Elements.Table (Suffix2).Next;
3850 -- There is a registered default suffix, but no
3851 -- suffix specified in the project file.
3852 -- Add the default to the array.
3854 if Suffix2 = No_Array_Element then
3855 Array_Elements.Increment_Last;
3856 Array_Elements.Table (Array_Elements.Last) :=
3857 (Index => Element.Index,
3858 Src_Index => Element.Src_Index,
3859 Index_Case_Sensitive => False,
3860 Value => Element.Value,
3861 Next => Impl_Suffixs);
3862 Impl_Suffixs := Array_Elements.Last;
3865 Suffix := Element.Next;
3868 -- Put the resulting array as the implementation suffixs
3870 Data.Naming.Body_Suffix := Impl_Suffixs;
3875 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3876 Element : Array_Element;
3879 while Current /= No_Array_Element loop
3880 Element := Array_Elements.Table (Current);
3881 Get_Name_String (Element.Value.Value);
3883 if Name_Len = 0 then
3886 "Body_Suffix cannot be empty",
3887 Element.Value.Location);
3890 Array_Elements.Table (Current) := Element;
3891 Current := Element.Next;
3895 -- Get the exceptions, if any
3897 Data.Naming.Specification_Exceptions :=
3899 (Name_Specification_Exceptions,
3900 In_Arrays => Naming.Decl.Arrays);
3902 Data.Naming.Implementation_Exceptions :=
3904 (Name_Implementation_Exceptions,
3905 In_Arrays => Naming.Decl.Arrays);
3909 Projects.Table (Project) := Data;
3910 end Language_Independent_Check;
3912 ----------------------
3913 -- Locate_Directory --
3914 ----------------------
3916 procedure Locate_Directory
3920 Display : out Name_Id)
3922 The_Name : constant String := Get_Name_String (Name);
3923 The_Parent : constant String :=
3924 Get_Name_String (Parent) & Directory_Separator;
3925 The_Parent_Last : constant Natural :=
3926 Compute_Directory_Last (The_Parent);
3929 if Current_Verbosity = High then
3930 Write_Str ("Locate_Directory (""");
3931 Write_Str (The_Name);
3932 Write_Str (""", """);
3933 Write_Str (The_Parent);
3940 if Is_Absolute_Path (The_Name) then
3941 if Is_Directory (The_Name) then
3943 Normed : constant String :=
3946 Resolve_Links => False,
3947 Case_Sensitive => True);
3949 Canonical_Path : constant String :=
3952 Resolve_Links => True,
3953 Case_Sensitive => False);
3956 Name_Len := Normed'Length;
3957 Name_Buffer (1 .. Name_Len) := Normed;
3958 Display := Name_Find;
3960 Name_Len := Canonical_Path'Length;
3961 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3968 Full_Path : constant String :=
3969 The_Parent (The_Parent'First .. The_Parent_Last) &
3973 if Is_Directory (Full_Path) then
3975 Normed : constant String :=
3978 Resolve_Links => False,
3979 Case_Sensitive => True);
3981 Canonical_Path : constant String :=
3984 Resolve_Links => True,
3985 Case_Sensitive => False);
3988 Name_Len := Normed'Length;
3989 Name_Buffer (1 .. Name_Len) := Normed;
3990 Display := Name_Find;
3992 Name_Len := Canonical_Path'Length;
3993 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3999 end Locate_Directory;
4001 ---------------------------
4002 -- Other_Languages_Check --
4003 ---------------------------
4005 procedure Other_Languages_Check
4006 (Project : Project_Id;
4007 Report_Error : Put_Line_Access) is
4009 Data : Project_Data;
4011 Languages : Variable_Value := Nil_Variable_Value;
4014 Language_Independent_Check (Project, Report_Error);
4016 Error_Report := Report_Error;
4018 Data := Projects.Table (Project);
4019 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
4021 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4023 if Data.Other_Sources_Present then
4024 -- Check if languages other than Ada are specified in this project
4026 if Languages.Default then
4027 -- Attribute Languages is not specified. So, it defaults to
4028 -- a project of language Ada only.
4030 Data.Languages (Lang_Ada) := True;
4032 -- No sources of languages other than Ada
4034 Data.Other_Sources_Present := False;
4038 Current : String_List_Id := Languages.Values;
4039 Element : String_Element;
4040 OK : Boolean := False;
4042 -- Assumethat there is no language other than Ada specified.
4043 -- If in fact there is at least one, we will set back
4044 -- Other_Sources_Present to True.
4046 Data.Other_Sources_Present := False;
4048 -- Look through all the languages specified in attribute
4049 -- Languages, if any
4051 while Current /= Nil_String loop
4052 Element := String_Elements.Table (Current);
4053 Get_Name_String (Element.Value);
4054 To_Lower (Name_Buffer (1 .. Name_Len));
4057 -- Check if it is a known language
4059 Lang_Loop : for Lang in Programming_Language loop
4061 Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4063 -- Yes, this is a known language
4067 -- Indicate the presence of this language
4068 Data.Languages (Lang) := True;
4070 -- If it is a language other than Ada, indicate that
4071 -- there should be some sources of a language other
4074 if Lang /= Lang_Ada then
4075 Data.Other_Sources_Present := True;
4082 -- We don't support this language: report an error
4085 Error_Msg_Name_1 := Element.Value;
4088 "unknown programming language {",
4092 Current := Element.Next;
4098 -- If there may be some sources, look for them
4100 if Data.Other_Sources_Present then
4101 -- Set Source_Present to False. It will be set back to True whenever
4102 -- a source is found.
4104 Data.Other_Sources_Present := False;
4106 for Lang in Other_Programming_Language loop
4107 -- For each language (other than Ada) in the project file
4109 if Data.Languages (Lang) then
4110 -- Reset the indication that there are sources of this
4111 -- language. It will be set back to True whenever we find a
4112 -- source of the language.
4114 Data.Languages (Lang) := False;
4116 -- First, get the source suffix for the language
4118 Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4120 -- Then, deal with the naming exceptions, if any
4125 Naming_Exceptions : constant Variable_Value :=
4127 (Index => Lang_Name_Ids (Lang),
4129 In_Array => Data.Naming.Implementation_Exceptions);
4130 Element_Id : String_List_Id;
4131 Element : String_Element;
4133 Source_Found : Boolean := False;
4135 -- If there are naming exceptions, look through them one
4138 if Naming_Exceptions /= Nil_Variable_Value then
4139 Element_Id := Naming_Exceptions.Values;
4141 while Element_Id /= Nil_String loop
4142 Element := String_Elements.Table (Element_Id);
4143 Get_Name_String (Element.Value);
4144 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4145 File_Id := Name_Find;
4147 -- Put each naming exception in the Source_Names
4148 -- hash table, but if there are repetition, don't
4149 -- bother after the first instance.
4151 if Source_Names.Get (File_Id) = No_Name_Location then
4152 Source_Found := True;
4156 Location => Element.Location,
4160 Element_Id := Element.Next;
4163 -- If there is at least one naming exception, record
4164 -- those that are found in the source directories.
4166 if Source_Found then
4167 Record_Other_Sources
4168 (Project => Project,
4171 Naming_Exceptions => True);
4177 -- Now, check if a list of sources is declared either through
4178 -- a string list (attribute Source_Files) or a text file
4179 -- (attribute Source_List_File).
4180 -- If a source list is declared, we will consider only those
4181 -- naming exceptions that are on the list.
4184 Sources : constant Variable_Value :=
4187 Data.Decl.Attributes);
4189 Source_List_File : constant Variable_Value :=
4191 (Name_Source_List_File,
4192 Data.Decl.Attributes);
4196 (Sources.Kind = List,
4197 "Source_Files is not a list");
4200 (Source_List_File.Kind = Single,
4201 "Source_List_File is not a single string");
4203 if not Sources.Default then
4204 if not Source_List_File.Default then
4207 "?both variables source_files and " &
4208 "source_list_file are present",
4209 Source_List_File.Location);
4212 -- Sources is a list of file names
4215 Current : String_List_Id := Sources.Values;
4216 Element : String_Element;
4217 Location : Source_Ptr;
4223 -- Put all the sources in the Source_Names hash
4226 while Current /= Nil_String loop
4227 Element := String_Elements.Table (Current);
4228 Get_Name_String (Element.Value);
4229 Canonical_Case_File_Name
4230 (Name_Buffer (1 .. Name_Len));
4233 -- If the element has no location, then use the
4234 -- location of Sources to report possible errors.
4236 if Element.Location = No_Location then
4237 Location := Sources.Location;
4240 Location := Element.Location;
4247 Location => Location,
4250 Current := Element.Next;
4253 -- And look for their directories
4255 Record_Other_Sources
4256 (Project => Project,
4259 Naming_Exceptions => False);
4262 -- No source_files specified.
4263 -- We check if Source_List_File has been specified.
4265 elsif not Source_List_File.Default then
4267 -- Source_List_File is the name of the file
4268 -- that contains the source file names
4271 Source_File_Path_Name : constant String :=
4273 (Source_List_File.Value,
4277 if Source_File_Path_Name'Length = 0 then
4278 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4281 "file with sources { does not exist",
4282 Source_List_File.Location);
4285 -- Read the file, putting each source in the
4286 -- Source_Names hash table.
4288 Get_Sources_From_File
4289 (Source_File_Path_Name,
4290 Source_List_File.Location,
4293 -- And look for their directories.
4295 Record_Other_Sources
4296 (Project => Project,
4299 Naming_Exceptions => False);
4304 -- Neither Source_Files nor Source_List_File has been
4305 -- specified. Find all the files that satisfy
4306 -- the naming scheme in all the source directories.
4307 -- All the naming exceptions that effectively exist are
4308 -- also part of the source of this language.
4310 Find_Sources (Project, Data, Lang);
4318 -- Finally, get the mains, if any
4320 Get_Mains (Project, Data);
4322 Projects.Table (Project) := Data;
4324 end Other_Languages_Check;
4330 function Path_Name_Of
4331 (File_Name : Name_Id;
4332 Directory : Name_Id) return String
4334 Result : String_Access;
4335 The_Directory : constant String := Get_Name_String (Directory);
4338 Get_Name_String (File_Name);
4339 Result := Locate_Regular_File
4340 (File_Name => Name_Buffer (1 .. Name_Len),
4341 Path => The_Directory);
4343 if Result = null then
4346 Canonical_Case_File_Name (Result.all);
4351 -------------------------------
4352 -- Prepare_Ada_Naming_Exceptions --
4353 -------------------------------
4355 procedure Prepare_Ada_Naming_Exceptions
4356 (List : Array_Element_Id;
4357 Kind : Spec_Or_Body)
4359 Current : Array_Element_Id := List;
4360 Element : Array_Element;
4365 -- Traverse the list
4367 while Current /= No_Array_Element loop
4368 Element := Array_Elements.Table (Current);
4370 if Element.Index /= No_Name then
4373 Unit => Element.Index,
4374 Next => No_Ada_Naming_Exception);
4375 Reverse_Ada_Naming_Exceptions.Set
4376 (Unit, (Element.Value.Value, Element.Value.Index));
4377 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4378 Ada_Naming_Exception_Table.Increment_Last;
4379 Ada_Naming_Exception_Table.Table
4380 (Ada_Naming_Exception_Table.Last) := Unit;
4381 Ada_Naming_Exceptions.Set
4382 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4385 Current := Element.Next;
4387 end Prepare_Ada_Naming_Exceptions;
4389 ---------------------
4390 -- Project_Extends --
4391 ---------------------
4393 function Project_Extends
4394 (Extending : Project_Id;
4395 Extended : Project_Id) return Boolean
4397 Current : Project_Id := Extending;
4400 if Current = No_Project then
4403 elsif Current = Extended then
4407 Current := Projects.Table (Current).Extends;
4409 end Project_Extends;
4411 -----------------------
4412 -- Record_Ada_Source --
4413 -----------------------
4415 procedure Record_Ada_Source
4416 (File_Name : Name_Id;
4417 Path_Name : Name_Id;
4418 Project : Project_Id;
4419 Data : in out Project_Data;
4420 Location : Source_Ptr;
4421 Current_Source : in out String_List_Id;
4422 Source_Recorded : in out Boolean;
4423 Follow_Links : Boolean)
4425 Canonical_File_Name : Name_Id;
4426 Canonical_Path_Name : Name_Id;
4427 Exception_Id : Ada_Naming_Exception_Id;
4428 Unit_Name : Name_Id;
4429 Unit_Kind : Spec_Or_Body;
4430 Unit_Index : Int := 0;
4432 Name_Index : Name_And_Index;
4433 Needs_Pragma : Boolean;
4435 The_Location : Source_Ptr := Location;
4436 Previous_Source : constant String_List_Id := Current_Source;
4437 Except_Name : Name_And_Index := No_Name_And_Index;
4439 Unit_Prj : Unit_Project;
4441 File_Name_Recorded : Boolean := False;
4444 Get_Name_String (File_Name);
4445 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4446 Canonical_File_Name := Name_Find;
4449 Canonical_Path : constant String :=
4451 (Get_Name_String (Path_Name),
4452 Resolve_Links => Follow_Links,
4453 Case_Sensitive => False);
4456 Add_Str_To_Name_Buffer (Canonical_Path);
4457 Canonical_Path_Name := Name_Find;
4460 -- Find out the unit name, the unit kind and if it needs
4461 -- a specific SFN pragma.
4464 (Canonical_File_Name => Canonical_File_Name,
4465 Naming => Data.Naming,
4466 Exception_Id => Exception_Id,
4467 Unit_Name => Unit_Name,
4468 Unit_Kind => Unit_Kind,
4469 Needs_Pragma => Needs_Pragma);
4471 if Exception_Id = No_Ada_Naming_Exception and then
4474 if Current_Verbosity = High then
4476 Write_Str (Get_Name_String (Canonical_File_Name));
4477 Write_Line (""" is not a valid source file name (ignored).");
4482 -- Check to see if the source has been hidden by an exception,
4483 -- but only if it is not an exception.
4485 if not Needs_Pragma then
4487 Reverse_Ada_Naming_Exceptions.Get
4488 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4490 if Except_Name /= No_Name_And_Index then
4491 if Current_Verbosity = High then
4493 Write_Str (Get_Name_String (Canonical_File_Name));
4494 Write_Str (""" contains a unit that is found in """);
4495 Write_Str (Get_Name_String (Except_Name.Name));
4496 Write_Line (""" (ignored).");
4499 -- The file is not included in the source of the project,
4500 -- because it is hidden by the exception.
4501 -- So, there is nothing else to do.
4508 if Exception_Id /= No_Ada_Naming_Exception then
4509 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4510 Exception_Id := Info.Next;
4511 Info.Next := No_Ada_Naming_Exception;
4512 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4514 Unit_Name := Info.Unit;
4515 Unit_Index := Name_Index.Index;
4516 Unit_Kind := Info.Kind;
4518 -- Put the file name in the list of sources of the project
4520 if not File_Name_Recorded then
4521 String_Elements.Increment_Last;
4522 String_Elements.Table (String_Elements.Last) :=
4523 (Value => Canonical_File_Name,
4524 Display_Value => File_Name,
4525 Location => No_Location,
4528 Index => Unit_Index);
4531 if Current_Source = Nil_String then
4532 Data.Sources := String_Elements.Last;
4535 String_Elements.Table (Current_Source).Next :=
4536 String_Elements.Last;
4539 Current_Source := String_Elements.Last;
4541 -- Put the unit in unit list
4544 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4545 The_Unit_Data : Unit_Data;
4548 if Current_Verbosity = High then
4549 Write_Str ("Putting ");
4550 Write_Str (Get_Name_String (Unit_Name));
4551 Write_Line (" in the unit list.");
4554 -- The unit is already in the list, but may be it is
4555 -- only the other unit kind (spec or body), or what is
4556 -- in the unit list is a unit of a project we are extending.
4558 if The_Unit /= Prj.Com.No_Unit then
4559 The_Unit_Data := Units.Table (The_Unit);
4561 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4562 or else Project_Extends
4564 The_Unit_Data.File_Names (Unit_Kind).Project)
4566 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4567 Remove_Forbidden_File_Name
4568 (The_Unit_Data.File_Names (Unit_Kind).Name);
4571 -- Record the file name in the hash table Files_Htable
4573 Unit_Prj := (Unit => The_Unit, Project => Project);
4574 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4576 The_Unit_Data.File_Names (Unit_Kind) :=
4577 (Name => Canonical_File_Name,
4578 Index => Unit_Index,
4579 Display_Name => File_Name,
4580 Path => Canonical_Path_Name,
4581 Display_Path => Path_Name,
4583 Needs_Pragma => Needs_Pragma);
4584 Units.Table (The_Unit) := The_Unit_Data;
4585 Source_Recorded := True;
4587 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4588 and then (Data.Known_Order_Of_Source_Dirs or else
4589 The_Unit_Data.File_Names (Unit_Kind).Path =
4590 Canonical_Path_Name)
4592 if Previous_Source = Nil_String then
4593 Data.Sources := Nil_String;
4595 String_Elements.Table (Previous_Source).Next :=
4597 String_Elements.Decrement_Last;
4600 Current_Source := Previous_Source;
4603 -- It is an error to have two units with the same name
4604 -- and the same kind (spec or body).
4606 if The_Location = No_Location then
4607 The_Location := Projects.Table (Project).Location;
4610 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4611 Error_Msg (Project, "duplicate source {", The_Location);
4613 Err_Vars.Error_Msg_Name_1 :=
4615 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4616 Err_Vars.Error_Msg_Name_2 :=
4617 The_Unit_Data.File_Names (Unit_Kind).Path;
4619 (Project, "\ project file {, {", The_Location);
4621 Err_Vars.Error_Msg_Name_1 :=
4622 Projects.Table (Project).Name;
4623 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4625 (Project, "\ project file {, {", The_Location);
4629 -- It is a new unit, create a new record
4632 -- First, check if there is no other unit with this file
4633 -- name in another project. If it is, report an error.
4634 -- Of course, we do that only for the first unit in the
4637 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4639 if not File_Name_Recorded and then
4640 Unit_Prj /= No_Unit_Project
4642 Error_Msg_Name_1 := File_Name;
4644 Projects.Table (Unit_Prj.Project).Name;
4647 "{ is already a source of project {",
4651 Units.Increment_Last;
4652 The_Unit := Units.Last;
4653 Units_Htable.Set (Unit_Name, The_Unit);
4654 Unit_Prj := (Unit => The_Unit, Project => Project);
4655 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4656 The_Unit_Data.Name := Unit_Name;
4657 The_Unit_Data.File_Names (Unit_Kind) :=
4658 (Name => Canonical_File_Name,
4659 Index => Unit_Index,
4660 Display_Name => File_Name,
4661 Path => Canonical_Path_Name,
4662 Display_Path => Path_Name,
4664 Needs_Pragma => Needs_Pragma);
4665 Units.Table (The_Unit) := The_Unit_Data;
4666 Source_Recorded := True;
4671 exit when Exception_Id = No_Ada_Naming_Exception;
4672 File_Name_Recorded := True;
4675 end Record_Ada_Source;
4677 --------------------------
4678 -- Record_Other_Sources --
4679 --------------------------
4681 procedure Record_Other_Sources
4682 (Project : Project_Id;
4683 Data : in out Project_Data;
4684 Language : Programming_Language;
4685 Naming_Exceptions : Boolean)
4687 Source_Dir : String_List_Id := Data.Source_Dirs;
4688 Element : String_Element;
4692 Canonical_Name : Name_Id;
4693 Name_Str : String (1 .. 1_024);
4694 Last : Natural := 0;
4697 First_Error : Boolean := True;
4699 Suffix : constant String :=
4700 Get_Name_String (Data.Impl_Suffixes (Language));
4703 while Source_Dir /= Nil_String loop
4704 Element := String_Elements.Table (Source_Dir);
4707 Dir_Path : constant String := Get_Name_String (Element.Value);
4709 if Current_Verbosity = High then
4710 Write_Str ("checking directory """);
4711 Write_Str (Dir_Path);
4712 Write_Str (""" for ");
4714 if Naming_Exceptions then
4715 Write_Str ("naming exceptions");
4718 Write_Str ("sources");
4721 Write_Str (" of Language ");
4722 Write_Line (Lang_Display_Names (Language).all);
4725 Open (Dir, Dir_Path);
4728 Read (Dir, Name_Str, Last);
4732 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4735 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4736 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4737 Canonical_Name := Name_Find;
4738 NL := Source_Names.Get (Canonical_Name);
4740 if NL /= No_Name_Location then
4742 if not Data.Known_Order_Of_Source_Dirs then
4743 Error_Msg_Name_1 := Canonical_Name;
4746 "{ is found in several source directories",
4752 Source_Names.Set (Canonical_Name, NL);
4753 Name_Len := Dir_Path'Length;
4754 Name_Buffer (1 .. Name_Len) := Dir_Path;
4755 Add_Char_To_Name_Buffer (Directory_Separator);
4756 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4760 (File_Name => Canonical_Name,
4764 Location => NL.Location,
4765 Language => Language,
4767 Naming_Exception => Naming_Exceptions);
4776 Source_Dir := Element.Next;
4779 if not Naming_Exceptions then
4781 NL := Source_Names.Get_First;
4783 -- It is an error if a source file name in a source list or
4784 -- in a source list file is not found.
4786 while NL /= No_Name_Location loop
4787 if not NL.Found then
4788 Err_Vars.Error_Msg_Name_1 := NL.Name;
4793 "source file { cannot be found",
4795 First_Error := False;
4800 "\source file { cannot be found",
4805 NL := Source_Names.Get_Next;
4808 -- Any naming exception of this language that is not in a list
4809 -- of sources must be removed.
4812 Source_Id : Other_Source_Id := Data.First_Other_Source;
4813 Prev_Id : Other_Source_Id := No_Other_Source;
4814 Source : Other_Source;
4816 while Source_Id /= No_Other_Source loop
4817 Source := Other_Sources.Table (Source_Id);
4819 if Source.Language = Language
4820 and then Source.Naming_Exception
4822 if Current_Verbosity = High then
4823 Write_Str ("Naming exception """);
4824 Write_Str (Get_Name_String (Source.File_Name));
4825 Write_Str (""" is not in the list of sources,");
4826 Write_Line (" so it is removed.");
4829 if Prev_Id = No_Other_Source then
4830 Data.First_Other_Source := Source.Next;
4833 Other_Sources.Table (Prev_Id).Next := Source.Next;
4836 Source_Id := Source.Next;
4838 if Source_Id = No_Other_Source then
4839 Data.Last_Other_Source := Prev_Id;
4843 Prev_Id := Source_Id;
4844 Source_Id := Source.Next;
4849 end Record_Other_Sources;
4851 ----------------------
4852 -- Show_Source_Dirs --
4853 ----------------------
4855 procedure Show_Source_Dirs (Project : Project_Id) is
4856 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4857 Element : String_Element;
4860 Write_Line ("Source_Dirs:");
4862 while Current /= Nil_String loop
4863 Element := String_Elements.Table (Current);
4865 Write_Line (Get_Name_String (Element.Value));
4866 Current := Element.Next;
4869 Write_Line ("end Source_Dirs.");
4870 end Show_Source_Dirs;
4877 (Language : Programming_Language;
4878 Naming : Naming_Data) return Name_Id
4880 Suffix : constant Variable_Value :=
4882 (Index => Lang_Name_Ids (Language),
4884 In_Array => Naming.Body_Suffix);
4886 -- If no suffix for this language is found in package Naming, use the
4889 if Suffix = Nil_Variable_Value then
4891 Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4893 -- Otherwise use the one specified
4896 Get_Name_String (Suffix.Value);
4899 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));