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;
33 with Osint; use Osint;
34 with Output; use Output;
35 with MLib.Tgt; use MLib.Tgt;
36 with Prj.Com; use Prj.Com;
37 with Prj.Env; use Prj.Env;
39 with Prj.Util; use Prj.Util;
41 with Snames; use Snames;
42 with Table; use Table;
43 with Types; use Types;
45 with Ada.Characters.Handling; use Ada.Characters.Handling;
46 with Ada.Strings; use Ada.Strings;
47 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
48 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
50 with GNAT.Case_Util; use GNAT.Case_Util;
51 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
52 with GNAT.OS_Lib; use GNAT.OS_Lib;
55 package body Prj.Nmsc is
57 Error_Report : Put_Line_Access := null;
58 -- Set to point to error reporting procedure
60 ALI_Suffix : constant String := ".ali";
61 -- File suffix for ali files
63 Object_Suffix : constant String := Get_Object_Suffix.all;
64 -- File suffix for object files
66 type Name_Location is record
68 Location : Source_Ptr;
69 Found : Boolean := False;
71 -- Information about file names found in string list attribute
72 -- Source_Files or in a source list file, stored in hash table
73 -- Source_Names, used by procedure
74 -- Ada_Check.Get_Path_Names_And_Record_Sources.
76 No_Name_Location : constant Name_Location :=
77 (Name => No_Name, Location => No_Location, Found => False);
79 package Source_Names is new GNAT.HTable.Simple_HTable
80 (Header_Num => Header_Num,
81 Element => Name_Location,
82 No_Element => No_Name_Location,
86 -- Hash table to store file names found in string list attribute
87 -- Source_Files or in a source list file, stored in hash table
88 -- Source_Names, used by procedure
89 -- Ada_Check.Get_Path_Names_And_Record_Sources.
91 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
92 (Header_Num => Header_Num,
98 -- Hash table to store recursive source directories, to avoid looking
99 -- several times, and to avoid cycles that may be introduced by symbolic
102 type Ada_Naming_Exception_Id is new Nat;
103 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
105 type Unit_Info is record
108 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
110 -- No_Unit : constant Unit_Info :=
111 -- (Specification, No_Name, No_Ada_Naming_Exception);
113 package Ada_Naming_Exception_Table is new Table.Table
114 (Table_Component_Type => Unit_Info,
115 Table_Index_Type => Ada_Naming_Exception_Id,
116 Table_Low_Bound => 1,
118 Table_Increment => 100,
119 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
121 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
122 (Header_Num => Header_Num,
123 Element => Ada_Naming_Exception_Id,
124 No_Element => No_Ada_Naming_Exception,
128 -- A hash table to store naming exceptions for Ada. For each file name
129 -- there is one or several unit in table Ada_Naming_Exception_Table.
131 function Hash (Unit : Unit_Info) return Header_Num;
133 type Name_And_Index is record
134 Name : Name_Id := No_Name;
137 No_Name_And_Index : constant Name_And_Index :=
138 (Name => No_Name, Index => 0);
140 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
141 (Header_Num => Header_Num,
142 Element => Name_And_Index,
143 No_Element => No_Name_And_Index,
147 -- A table to check if a unit with an exceptional name will hide
148 -- a source with a file name following the naming convention.
150 function ALI_File_Name (Source : String) return String;
151 -- Return the ALI file name corresponding to a source.
153 procedure Check_Ada_Name
156 -- Check that a name is a valid Ada unit name.
158 procedure Check_Ada_Naming_Scheme
159 (Data : in out Project_Data;
160 Project : Project_Id);
161 -- Check the naming scheme part of Data
163 procedure Check_Ada_Naming_Scheme_Validity
164 (Project : Project_Id;
165 Naming : Naming_Data);
166 -- Check that the package Naming is correct.
168 procedure Check_For_Source
169 (File_Name : Name_Id;
171 Project : Project_Id;
172 Data : in out Project_Data;
173 Location : Source_Ptr;
174 Language : Other_Programming_Language;
176 Naming_Exception : Boolean);
177 -- Check if a file in a source directory is a source for a specific
178 -- language other than Ada.
180 function Check_Project
182 Root_Project : Project_Id;
183 Extending : Boolean) return Boolean;
184 -- Returns True if P is Root_Project or, if Extending is True, a project
185 -- extended by Root_Project.
187 function Compute_Directory_Last (Dir : String) return Natural;
188 -- Return the index of the last significant character in Dir. This is used
189 -- to avoid duplicates '/' at the end of directory names
192 (Project : Project_Id;
194 Flag_Location : Source_Ptr);
195 -- Output an error message. If Error_Report is null, simply call
196 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
199 procedure Find_Sources
200 (Project : Project_Id;
201 Data : in out Project_Data;
202 For_Language : Programming_Language;
203 Follow_Links : Boolean := False);
204 -- Find all the sources in all of the source directories of a project for
205 -- a specified language.
207 procedure Free_Ada_Naming_Exceptions;
208 -- Free the internal hash tables used for checking naming exceptions
210 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
211 -- Get the mains of a project from attribute Main, if it exists, and put
212 -- them in the project data.
214 procedure Get_Sources_From_File
216 Location : Source_Ptr;
217 Project : Project_Id);
218 -- Get the list of sources from a text file and put them in hash table
222 (Canonical_File_Name : Name_Id;
223 Naming : Naming_Data;
224 Exception_Id : out Ada_Naming_Exception_Id;
225 Unit_Name : out Name_Id;
226 Unit_Kind : out Spec_Or_Body;
227 Needs_Pragma : out Boolean);
228 -- Find out, from a file name, the unit name, the unit kind and if a
229 -- specific SFN pragma is needed. If the file name corresponds to no
230 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
231 -- or an exception to the naming scheme, then Exception_Id is set to
232 -- the unit or units that the source contains.
234 function Is_Illegal_Suffix
236 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
237 -- Returns True if the string Suffix cannot be used as
238 -- a spec suffix, a body suffix or a separate suffix.
240 procedure Locate_Directory
244 Display : out Name_Id;
245 Project : Project_Id := No_Project;
247 Location : Source_Ptr := No_Location);
248 -- Locate a directory. Dir is the canonical path name. Display is the
249 -- path name for display purpose.
250 -- When the directory does not exist, Setup_Projects is True and Kind is
251 -- not the empty string, an attempt is made to create the directory.
252 -- Returns No_Name in Dir and Display if directory does not exist or
253 -- cannot be created.
255 function Path_Name_Of
256 (File_Name : Name_Id;
257 Directory : Name_Id) return String;
258 -- Returns the path name of a (non project) file.
259 -- Returns an empty string if file cannot be found.
261 procedure Prepare_Ada_Naming_Exceptions
262 (List : Array_Element_Id;
263 Kind : Spec_Or_Body);
264 -- Prepare the internal hash tables used for checking naming exceptions
265 -- for Ada. Insert all elements of List in the tables.
267 function Project_Extends
268 (Extending : Project_Id;
269 Extended : Project_Id) return Boolean;
270 -- Returns True if Extending is extending directly or indirectly Extended.
272 procedure Record_Ada_Source
273 (File_Name : Name_Id;
275 Project : Project_Id;
276 Data : in out Project_Data;
277 Location : Source_Ptr;
278 Current_Source : in out String_List_Id;
279 Source_Recorded : in out Boolean;
280 Follow_Links : Boolean);
281 -- Put a unit in the list of units of a project, if the file name
282 -- corresponds to a valid unit name.
284 procedure Record_Other_Sources
285 (Project : Project_Id;
286 Data : in out Project_Data;
287 Language : Programming_Language;
288 Naming_Exceptions : Boolean);
289 -- Record the sources of a language in a project.
290 -- When Naming_Exceptions is True, mark the found sources as such, to
291 -- later remove those that are not named in a list of sources.
293 procedure Show_Source_Dirs (Project : Project_Id);
294 -- List all the source directories of a project.
297 (Language : Programming_Language;
298 Naming : Naming_Data) return Name_Id;
299 -- Get the suffix for the source of a language from a package naming.
300 -- If not specified, return the default for the language.
307 (Project : Project_Id;
308 Report_Error : Put_Line_Access;
309 Follow_Links : Boolean)
312 Languages : Variable_Value := Nil_Variable_Value;
314 Extending : Boolean := False;
316 procedure Get_Path_Names_And_Record_Sources;
317 -- Find the path names of the source files in the Source_Names table
318 -- in the source directories and record those that are Ada sources.
320 procedure Get_Sources_From_File
322 Location : Source_Ptr);
323 -- Get the sources of a project from a text file
325 procedure Warn_If_Not_Sources
326 (Conventions : Array_Element_Id;
328 -- Check that individual naming conventions apply to immediate
329 -- sources of the project; if not, issue a warning.
331 ---------------------------------------
332 -- Get_Path_Names_And_Record_Sources --
333 ---------------------------------------
335 procedure Get_Path_Names_And_Record_Sources is
336 Source_Dir : String_List_Id := Data.Source_Dirs;
337 Element : String_Element;
342 Canonical_Name : Name_Id;
343 Name_Str : String (1 .. 1_024);
347 Current_Source : String_List_Id := Nil_String;
349 First_Error : Boolean := True;
351 Source_Recorded : Boolean := False;
354 -- We look in all source directories for the file names in the
355 -- hash table Source_Names
357 while Source_Dir /= Nil_String loop
358 Source_Recorded := False;
359 Element := String_Elements.Table (Source_Dir);
362 Dir_Path : constant String := Get_Name_String (Element.Value);
364 if Current_Verbosity = High then
365 Write_Str ("checking directory """);
366 Write_Str (Dir_Path);
370 Open (Dir, Dir_Path);
373 Read (Dir, Name_Str, Last);
376 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
378 Canonical_Case_File_Name (Name_Str (1 .. Last));
380 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
381 Canonical_Name := Name_Find;
382 NL := Source_Names.Get (Canonical_Name);
384 if NL /= No_Name_Location and then not NL.Found then
386 Source_Names.Set (Canonical_Name, NL);
387 Name_Len := Dir_Path'Length;
388 Name_Buffer (1 .. Name_Len) := Dir_Path;
389 Add_Char_To_Name_Buffer (Directory_Separator);
390 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
393 if Current_Verbosity = High then
394 Write_Str (" found ");
395 Write_Line (Get_Name_String (Name));
398 -- Register the source if it is an Ada compilation unit.
405 Location => NL.Location,
406 Current_Source => Current_Source,
407 Source_Recorded => Source_Recorded,
408 Follow_Links => Follow_Links);
415 if Source_Recorded then
416 String_Elements.Table (Source_Dir).Flag := True;
419 Source_Dir := Element.Next;
422 -- It is an error if a source file name in a source list or
423 -- in a source list file is not found.
425 NL := Source_Names.Get_First;
427 while NL /= No_Name_Location loop
429 Err_Vars.Error_Msg_Name_1 := NL.Name;
434 "source file { cannot be found",
436 First_Error := False;
441 "\source file { cannot be found",
446 NL := Source_Names.Get_Next;
448 end Get_Path_Names_And_Record_Sources;
450 ---------------------------
451 -- Get_Sources_From_File --
452 ---------------------------
454 procedure Get_Sources_From_File
456 Location : Source_Ptr)
459 -- Get the list of sources from the file and put them in hash table
462 Get_Sources_From_File (Path, Location, Project);
464 -- Look in the source directories to find those sources
466 Get_Path_Names_And_Record_Sources;
468 -- We should have found at least one source.
469 -- If not, report an error.
471 if Data.Sources = Nil_String then
473 "there are no Ada sources in this project",
476 end Get_Sources_From_File;
478 -------------------------
479 -- Warn_If_Not_Sources --
480 -------------------------
482 procedure Warn_If_Not_Sources
483 (Conventions : Array_Element_Id;
486 Conv : Array_Element_Id := Conventions;
488 The_Unit_Id : Unit_Id;
489 The_Unit_Data : Unit_Data;
490 Location : Source_Ptr;
493 while Conv /= No_Array_Element loop
494 Unit := Array_Elements.Table (Conv).Index;
495 Error_Msg_Name_1 := Unit;
496 Get_Name_String (Unit);
497 To_Lower (Name_Buffer (1 .. Name_Len));
499 The_Unit_Id := Units_Htable.Get (Unit);
500 Location := Array_Elements.Table (Conv).Value.Location;
502 if The_Unit_Id = Prj.Com.No_Unit then
509 The_Unit_Data := Units.Table (The_Unit_Id);
513 (The_Unit_Data.File_Names (Specification).Project,
518 "?unit{ has no spec in this project",
524 (The_Unit_Data.File_Names (Com.Body_Part).Project,
529 "?unit{ has no body in this project",
535 Conv := Array_Elements.Table (Conv).Next;
537 end Warn_If_Not_Sources;
539 -- Start of processing for Ada_Check
542 Language_Independent_Check (Project, Report_Error);
544 Error_Report := Report_Error;
546 Data := Projects.Table (Project);
547 Extending := Data.Extends /= No_Project;
548 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
550 Data.Naming.Current_Language := Name_Ada;
551 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
553 if not Languages.Default then
555 Current : String_List_Id := Languages.Values;
556 Element : String_Element;
557 Ada_Found : Boolean := False;
560 Look_For_Ada : while Current /= Nil_String loop
561 Element := String_Elements.Table (Current);
562 Get_Name_String (Element.Value);
563 To_Lower (Name_Buffer (1 .. Name_Len));
565 if Name_Buffer (1 .. Name_Len) = "ada" then
570 Current := Element.Next;
571 end loop Look_For_Ada;
573 if not Ada_Found then
575 -- Mark the project file as having no sources for Ada
577 Data.Ada_Sources_Present := False;
582 Check_Ada_Naming_Scheme (Data, Project);
584 Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
585 Prepare_Ada_Naming_Exceptions (Data.Naming.Specs, Specification);
587 -- If we have source directories, then find the sources
589 if Data.Ada_Sources_Present then
590 if Data.Source_Dirs = Nil_String then
591 Data.Ada_Sources_Present := False;
595 Sources : constant Variable_Value :=
598 Data.Decl.Attributes);
600 Source_List_File : constant Variable_Value :=
602 (Name_Source_List_File,
603 Data.Decl.Attributes);
605 Locally_Removed : constant Variable_Value :=
607 (Name_Locally_Removed_Files,
608 Data.Decl.Attributes);
612 (Sources.Kind = List,
613 "Source_Files is not a list");
616 (Source_List_File.Kind = Single,
617 "Source_List_File is not a single string");
619 if not Sources.Default then
620 if not Source_List_File.Default then
623 "?both variables source_files and " &
624 "source_list_file are present",
625 Source_List_File.Location);
628 -- Sources is a list of file names
631 Current : String_List_Id := Sources.Values;
632 Element : String_Element;
633 Location : Source_Ptr;
639 Data.Ada_Sources_Present := Current /= Nil_String;
641 while Current /= Nil_String loop
642 Element := String_Elements.Table (Current);
643 Get_Name_String (Element.Value);
644 Canonical_Case_File_Name
645 (Name_Buffer (1 .. Name_Len));
648 -- If the element has no location, then use the
649 -- location of Sources to report possible errors.
651 if Element.Location = No_Location then
652 Location := Sources.Location;
655 Location := Element.Location;
662 Location => Location,
665 Current := Element.Next;
668 Get_Path_Names_And_Record_Sources;
671 -- No source_files specified
673 -- We check Source_List_File has been specified.
675 elsif not Source_List_File.Default then
677 -- Source_List_File is the name of the file
678 -- that contains the source file names
681 Source_File_Path_Name : constant String :=
683 (Source_List_File.Value,
687 if Source_File_Path_Name'Length = 0 then
688 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
691 "file with sources { does not exist",
692 Source_List_File.Location);
695 Get_Sources_From_File
696 (Source_File_Path_Name,
697 Source_List_File.Location);
702 -- Neither Source_Files nor Source_List_File has been
703 -- specified. Find all the files that satisfy the naming
704 -- scheme in all the source directories.
706 Find_Sources (Project, Data, Lang_Ada, Follow_Links);
709 -- If there are sources that are locally removed, mark them as
710 -- such in the Units table.
712 if not Locally_Removed.Default then
714 -- Sources can be locally removed only in extending
717 if Data.Extends = No_Project then
720 "Locally_Removed_Files can only be used " &
721 "in an extending project file",
722 Locally_Removed.Location);
726 Current : String_List_Id :=
727 Locally_Removed.Values;
728 Element : String_Element;
729 Location : Source_Ptr;
733 Extended : Project_Id;
736 while Current /= Nil_String loop
737 Element := String_Elements.Table (Current);
738 Get_Name_String (Element.Value);
739 Canonical_Case_File_Name
740 (Name_Buffer (1 .. Name_Len));
743 -- If the element has no location, then use the
744 -- location of Locally_Removed to report
747 if Element.Location = No_Location then
748 Location := Locally_Removed.Location;
751 Location := Element.Location;
756 for Index in 1 .. Units.Last loop
757 Unit := Units.Table (Index);
760 Unit.File_Names (Specification).Name = Name
764 -- Check that this is from a project that
765 -- the current project extends, but not the
768 Extended := Unit.File_Names
769 (Specification).Project;
771 if Extended = Project then
774 "cannot remove a source " &
775 "of the same project",
779 Project_Extends (Project, Extended)
782 (Specification).Path := Slash;
784 (Specification).Needs_Pragma := False;
785 Units.Table (Index) := Unit;
786 Add_Forbidden_File_Name
787 (Unit.File_Names (Specification).Name);
793 "cannot remove a source from " &
799 Unit.File_Names (Body_Part).Name = Name
803 -- Check that this is from a project that
804 -- the current project extends, but not the
807 Extended := Unit.File_Names
810 if Extended = Project then
813 "cannot remove a source " &
814 "of the same project",
818 Project_Extends (Project, Extended)
820 Unit.File_Names (Body_Part).Path := Slash;
821 Unit.File_Names (Body_Part).Needs_Pragma
823 Units.Table (Index) := Unit;
824 Add_Forbidden_File_Name
825 (Unit.File_Names (Body_Part).Name);
833 Err_Vars.Error_Msg_Name_1 := Name;
834 Error_Msg (Project, "unknown file {", Location);
837 Current := Element.Next;
846 if Data.Ada_Sources_Present then
848 -- Check that all individual naming conventions apply to
849 -- sources of this project file.
851 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
852 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
855 -- If it is a library project file, check if it is a standalone library
858 Standalone_Library : declare
859 Lib_Interfaces : constant Prj.Variable_Value :=
861 (Snames.Name_Library_Interface,
862 Data.Decl.Attributes);
863 Lib_Auto_Init : constant Prj.Variable_Value :=
865 (Snames.Name_Library_Auto_Init,
866 Data.Decl.Attributes);
868 Lib_Src_Dir : constant Prj.Variable_Value :=
870 (Snames.Name_Library_Src_Dir,
871 Data.Decl.Attributes);
873 Lib_Symbol_File : constant Prj.Variable_Value :=
875 (Snames.Name_Library_Symbol_File,
876 Data.Decl.Attributes);
878 Lib_Symbol_Policy : constant Prj.Variable_Value :=
880 (Snames.Name_Library_Symbol_Policy,
881 Data.Decl.Attributes);
883 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
885 (Snames.Name_Library_Reference_Symbol_File,
886 Data.Decl.Attributes);
888 Auto_Init_Supported : constant Boolean :=
890 Standalone_Library_Auto_Init_Is_Supported;
892 OK : Boolean := True;
895 pragma Assert (Lib_Interfaces.Kind = List);
897 -- It is a stand-alone library project file if attribute
898 -- Library_Interface is defined.
900 if not Lib_Interfaces.Default then
902 Interfaces : String_List_Id := Lib_Interfaces.Values;
903 Interface_ALIs : String_List_Id := Nil_String;
905 The_Unit_Id : Unit_Id;
906 The_Unit_Data : Unit_Data;
908 procedure Add_ALI_For (Source : Name_Id);
909 -- Add an ALI file name to the list of Interface ALIs
915 procedure Add_ALI_For (Source : Name_Id) is
917 Get_Name_String (Source);
920 ALI : constant String :=
921 ALI_File_Name (Name_Buffer (1 .. Name_Len));
922 ALI_Name_Id : Name_Id;
924 Name_Len := ALI'Length;
925 Name_Buffer (1 .. Name_Len) := ALI;
926 ALI_Name_Id := Name_Find;
928 String_Elements.Increment_Last;
929 String_Elements.Table (String_Elements.Last) :=
930 (Value => ALI_Name_Id,
932 Display_Value => ALI_Name_Id,
933 Location => String_Elements.Table
934 (Interfaces).Location,
936 Next => Interface_ALIs);
937 Interface_ALIs := String_Elements.Last;
942 Data.Standalone_Library := True;
944 -- Library_Interface cannot be an empty list
946 if Interfaces = Nil_String then
949 "Library_Interface cannot be an empty list",
950 Lib_Interfaces.Location);
953 -- Process each unit name specified in the attribute
954 -- Library_Interface.
956 while Interfaces /= Nil_String loop
958 (String_Elements.Table (Interfaces).Value);
959 To_Lower (Name_Buffer (1 .. Name_Len));
964 "an interface cannot be an empty string",
965 String_Elements.Table (Interfaces).Location);
969 Error_Msg_Name_1 := Unit;
970 The_Unit_Id := Units_Htable.Get (Unit);
972 if The_Unit_Id = Prj.Com.No_Unit then
976 String_Elements.Table (Interfaces).Location);
979 -- Check that the unit is part of the project
981 The_Unit_Data := Units.Table (The_Unit_Id);
983 if The_Unit_Data.File_Names
984 (Com.Body_Part).Name /= No_Name
985 and then The_Unit_Data.File_Names
986 (Com.Body_Part).Path /= Slash
989 (The_Unit_Data.File_Names (Body_Part).Project,
992 -- There is a body for this unit.
993 -- If there is no spec, we need to check
994 -- that it is not a subunit.
996 if The_Unit_Data.File_Names
997 (Specification).Name = No_Name
1000 Src_Ind : Source_File_Index;
1003 Src_Ind := Sinput.P.Load_Project_File
1005 (The_Unit_Data.File_Names
1008 if Sinput.P.Source_File_Is_Subunit
1013 "{ is a subunit; " &
1014 "it cannot be an interface",
1015 String_Elements.Table
1016 (Interfaces).Location);
1021 -- The unit is not a subunit, so we add
1022 -- to the Interface ALIs the ALI file
1023 -- corresponding to the body.
1026 (The_Unit_Data.File_Names (Body_Part).Name);
1031 "{ is not an unit of this project",
1032 String_Elements.Table
1033 (Interfaces).Location);
1036 elsif The_Unit_Data.File_Names
1037 (Com.Specification).Name /= No_Name
1038 and then The_Unit_Data.File_Names
1039 (Com.Specification).Path /= Slash
1040 and then Check_Project
1041 (The_Unit_Data.File_Names
1042 (Specification).Project,
1046 -- The unit is part of the project, it has
1047 -- a spec, but no body. We add to the Interface
1048 -- ALIs the ALI file corresponding to the spec.
1051 (The_Unit_Data.File_Names (Specification).Name);
1056 "{ is not an unit of this project",
1057 String_Elements.Table (Interfaces).Location);
1063 Interfaces := String_Elements.Table (Interfaces).Next;
1066 -- Put the list of Interface ALIs in the project data
1068 Data.Lib_Interface_ALIs := Interface_ALIs;
1070 -- Check value of attribute Library_Auto_Init and set
1071 -- Lib_Auto_Init accordingly.
1073 if Lib_Auto_Init.Default then
1075 -- If no attribute Library_Auto_Init is declared, then
1076 -- set auto init only if it is supported.
1078 Data.Lib_Auto_Init := Auto_Init_Supported;
1081 Get_Name_String (Lib_Auto_Init.Value);
1082 To_Lower (Name_Buffer (1 .. Name_Len));
1084 if Name_Buffer (1 .. Name_Len) = "false" then
1085 Data.Lib_Auto_Init := False;
1087 elsif Name_Buffer (1 .. Name_Len) = "true" then
1088 if Auto_Init_Supported then
1089 Data.Lib_Auto_Init := True;
1092 -- Library_Auto_Init cannot be "true" if auto init
1097 "library auto init not supported " &
1099 Lib_Auto_Init.Location);
1105 "invalid value for attribute Library_Auto_Init",
1106 Lib_Auto_Init.Location);
1111 -- If attribute Library_Src_Dir is defined and not the
1112 -- empty string, check if the directory exist and is not
1113 -- the object directory or one of the source directories.
1114 -- This is the directory where copies of the interface
1115 -- sources will be copied. Note that this directory may be
1116 -- the library directory. If setting up projects (gnat setup)
1117 -- and the directory does not exist, attempt to create it.
1119 if Lib_Src_Dir.Value /= Empty_String then
1121 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1125 (Dir_Id, Data.Display_Directory,
1126 Data.Library_Src_Dir,
1127 Data.Display_Library_Src_Dir,
1129 Kind => "library interface copy",
1130 Location => Lib_Src_Dir.Location);
1132 -- If directory does not exist, report an error. No need
1133 -- to do that if Setup_Projects is True, as an error
1134 -- has already been reported by Locate_Directory.
1136 if not Setup_Projects
1137 and then Data.Library_Src_Dir = No_Name
1140 -- Get the absolute name of the library directory
1141 -- that does not exist, to report an error.
1144 Dir_Name : constant String :=
1145 Get_Name_String (Dir_Id);
1148 if Is_Absolute_Path (Dir_Name) then
1149 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1152 Get_Name_String (Data.Directory);
1154 if Name_Buffer (Name_Len) /=
1157 Name_Len := Name_Len + 1;
1158 Name_Buffer (Name_Len) :=
1159 Directory_Separator;
1164 Name_Len + Dir_Name'Length) :=
1166 Name_Len := Name_Len + Dir_Name'Length;
1167 Err_Vars.Error_Msg_Name_1 := Name_Find;
1174 "Directory { does not exist",
1175 Lib_Src_Dir.Location);
1178 -- Report an error if it is the same as the object
1181 elsif Data.Library_Src_Dir = Data.Object_Directory then
1184 "directory to copy interfaces cannot be " &
1185 "the object directory",
1186 Lib_Src_Dir.Location);
1187 Data.Library_Src_Dir := No_Name;
1189 -- Check if it is the same as one of the source
1194 Src_Dirs : String_List_Id := Data.Source_Dirs;
1195 Src_Dir : String_Element;
1198 while Src_Dirs /= Nil_String loop
1199 Src_Dir := String_Elements.Table (Src_Dirs);
1200 Src_Dirs := Src_Dir.Next;
1202 -- Report an error if it is one of the
1203 -- source directories.
1205 if Data.Library_Src_Dir = Src_Dir.Value then
1208 "directory to copy interfaces cannot " &
1209 "be one of the source directories",
1210 Lib_Src_Dir.Location);
1211 Data.Library_Src_Dir := No_Name;
1217 if Data.Library_Src_Dir /= No_Name
1218 and then Current_Verbosity = High
1220 Write_Str ("Directory to copy interfaces =""");
1221 Write_Str (Get_Name_String (Data.Library_Dir));
1228 if not Lib_Symbol_Policy.Default then
1230 Value : constant String :=
1232 (Get_Name_String (Lib_Symbol_Policy.Value));
1235 if Value = "autonomous" or else Value = "default" then
1236 Data.Symbol_Data.Symbol_Policy := Autonomous;
1238 elsif Value = "compliant" then
1239 Data.Symbol_Data.Symbol_Policy := Compliant;
1241 elsif Value = "controlled" then
1242 Data.Symbol_Data.Symbol_Policy := Controlled;
1244 elsif Value = "restricted" then
1245 Data.Symbol_Data.Symbol_Policy := Restricted;
1250 "illegal value for Library_Symbol_Policy",
1251 Lib_Symbol_Policy.Location);
1256 if Lib_Symbol_File.Default then
1257 if Data.Symbol_Data.Symbol_Policy = Restricted then
1260 "Library_Symbol_File needs to be defined when " &
1261 "symbol policy is Restricted",
1262 Lib_Symbol_Policy.Location);
1266 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1268 Get_Name_String (Lib_Symbol_File.Value);
1270 if Name_Len = 0 then
1273 "symbol file name cannot be an empty string",
1274 Lib_Symbol_File.Location);
1277 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1280 for J in 1 .. Name_Len loop
1281 if Name_Buffer (J) = '/'
1282 or else Name_Buffer (J) = Directory_Separator
1291 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1294 "symbol file name { is illegal. " &
1295 "Name canot include directory info.",
1296 Lib_Symbol_File.Location);
1301 if Lib_Ref_Symbol_File.Default then
1302 if Data.Symbol_Data.Symbol_Policy = Compliant
1303 or else Data.Symbol_Data.Symbol_Policy = Controlled
1307 "a reference symbol file need to be defined",
1308 Lib_Symbol_Policy.Location);
1312 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1314 Get_Name_String (Lib_Ref_Symbol_File.Value);
1316 if Name_Len = 0 then
1319 "reference symbol file name cannot be an empty string",
1320 Lib_Symbol_File.Location);
1323 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1326 for J in 1 .. Name_Len loop
1327 if Name_Buffer (J) = '/'
1328 or else Name_Buffer (J) = Directory_Separator
1337 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1340 "reference symbol file { name is illegal. " &
1341 "Name canot include directory info.",
1342 Lib_Ref_Symbol_File.Location);
1345 if not Is_Regular_File
1346 (Get_Name_String (Data.Object_Directory) &
1347 Directory_Separator &
1348 Get_Name_String (Lib_Ref_Symbol_File.Value))
1350 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1353 "library reference symbol file { does not exist",
1354 Lib_Ref_Symbol_File.Location);
1357 if Data.Symbol_Data.Symbol_File /= No_Name then
1361 (Data.Symbol_Data.Symbol_File);
1363 Reference : String :=
1365 (Data.Symbol_Data.Reference);
1368 Canonical_Case_File_Name (Symbol);
1369 Canonical_Case_File_Name (Reference);
1371 if Symbol = Reference then
1374 "reference symbol file and symbol file " &
1375 "cannot be the same file",
1376 Lib_Ref_Symbol_File.Location);
1383 end Standalone_Library;
1386 -- Put the list of Mains, if any, in the project data
1388 Get_Mains (Project, Data);
1390 Projects.Table (Project) := Data;
1392 Free_Ada_Naming_Exceptions;
1399 function ALI_File_Name (Source : String) return String is
1401 -- If the source name has an extension, then replace it with
1404 for Index in reverse Source'First + 1 .. Source'Last loop
1405 if Source (Index) = '.' then
1406 return Source (Source'First .. Index - 1) & ALI_Suffix;
1410 -- If there is no dot, or if it is the first character, just add the
1413 return Source & ALI_Suffix;
1416 --------------------
1417 -- Check_Ada_Name --
1418 --------------------
1420 procedure Check_Ada_Name
1424 The_Name : String := Name;
1425 Real_Name : Name_Id;
1426 Need_Letter : Boolean := True;
1427 Last_Underscore : Boolean := False;
1428 OK : Boolean := The_Name'Length > 0;
1431 To_Lower (The_Name);
1433 Name_Len := The_Name'Length;
1434 Name_Buffer (1 .. Name_Len) := The_Name;
1435 Real_Name := Name_Find;
1437 -- Check first that the given name is not an Ada reserved word
1439 if Get_Name_Table_Byte (Real_Name) /= 0
1440 and then Real_Name /= Name_Project
1441 and then Real_Name /= Name_Extends
1442 and then Real_Name /= Name_External
1446 if Current_Verbosity = High then
1447 Write_Str (The_Name);
1448 Write_Line (" is an Ada reserved word.");
1454 for Index in The_Name'Range loop
1457 -- We need a letter (at the beginning, and following a dot),
1458 -- but we don't have one.
1460 if Is_Letter (The_Name (Index)) then
1461 Need_Letter := False;
1466 if Current_Verbosity = High then
1467 Write_Int (Types.Int (Index));
1469 Write_Char (The_Name (Index));
1470 Write_Line ("' is not a letter.");
1476 elsif Last_Underscore
1477 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1479 -- Two underscores are illegal, and a dot cannot follow
1484 if Current_Verbosity = High then
1485 Write_Int (Types.Int (Index));
1487 Write_Char (The_Name (Index));
1488 Write_Line ("' is illegal here.");
1493 elsif The_Name (Index) = '.' then
1495 -- We need a letter after a dot
1497 Need_Letter := True;
1499 elsif The_Name (Index) = '_' then
1500 Last_Underscore := True;
1503 -- We need an letter or a digit
1505 Last_Underscore := False;
1507 if not Is_Alphanumeric (The_Name (Index)) then
1510 if Current_Verbosity = High then
1511 Write_Int (Types.Int (Index));
1513 Write_Char (The_Name (Index));
1514 Write_Line ("' is not alphanumeric.");
1522 -- Cannot end with an underscore or a dot
1524 OK := OK and then not Need_Letter and then not Last_Underscore;
1530 -- Signal a problem with No_Name
1536 ----------------------
1537 -- Check_For_Source --
1538 ----------------------
1540 procedure Check_For_Source
1541 (File_Name : Name_Id;
1542 Path_Name : Name_Id;
1543 Project : Project_Id;
1544 Data : in out Project_Data;
1545 Location : Source_Ptr;
1546 Language : Other_Programming_Language;
1548 Naming_Exception : Boolean)
1550 Name : String := Get_Name_String (File_Name);
1551 Real_Location : Source_Ptr := Location;
1554 Canonical_Case_File_Name (Name);
1556 -- A file is a source of a language if Naming_Exception is True (case
1557 -- of naming exceptions) or if its file name ends with the suffix.
1559 if Naming_Exception or else
1560 (Name'Length > Suffix'Length and then
1561 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
1563 if Real_Location = No_Location then
1564 Real_Location := Data.Location;
1568 Path : String := Get_Name_String (Path_Name);
1571 -- The path name id (in canonical case)
1574 -- The file name id (in canonical case)
1577 -- The object file name
1579 Obj_Path_Id : Name_Id;
1580 -- The object path name
1583 -- The dependency file name
1585 Dep_Path_Id : Name_Id;
1586 -- The dependency path name
1588 Dot_Pos : Natural := 0;
1589 -- Position of the last dot in Name
1591 Source : Other_Source;
1592 Source_Id : Other_Source_Id := Data.First_Other_Source;
1595 Canonical_Case_File_Name (Path);
1597 -- Get the file name id
1599 Name_Len := Name'Length;
1600 Name_Buffer (1 .. Name_Len) := Name;
1601 File_Id := Name_Find;
1603 -- Get the path name id
1605 Name_Len := Path'Length;
1606 Name_Buffer (1 .. Name_Len) := Path;
1607 Path_Id := Name_Find;
1609 -- Find the position of the last dot
1611 for J in reverse Name'Range loop
1612 if Name (J) = '.' then
1618 if Dot_Pos <= Name'First then
1619 Dot_Pos := Name'Last + 1;
1622 -- Compute the object file name
1624 Get_Name_String (File_Id);
1625 Name_Len := Dot_Pos - Name'First;
1627 for J in Object_Suffix'Range loop
1628 Name_Len := Name_Len + 1;
1629 Name_Buffer (Name_Len) := Object_Suffix (J);
1632 Obj_Id := Name_Find;
1634 -- Compute the object path name
1636 Get_Name_String (Data.Object_Directory);
1638 if Name_Buffer (Name_Len) /= Directory_Separator and then
1639 Name_Buffer (Name_Len) /= '/'
1641 Name_Len := Name_Len + 1;
1642 Name_Buffer (Name_Len) := Directory_Separator;
1645 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
1646 Obj_Path_Id := Name_Find;
1648 -- Compute the dependency file name
1650 Get_Name_String (File_Id);
1651 Name_Len := Dot_Pos - Name'First + 1;
1652 Name_Buffer (Name_Len) := '.';
1653 Name_Len := Name_Len + 1;
1654 Name_Buffer (Name_Len) := 'd';
1655 Dep_Id := Name_Find;
1657 -- Compute the dependency path name
1659 Get_Name_String (Data.Object_Directory);
1661 if Name_Buffer (Name_Len) /= Directory_Separator and then
1662 Name_Buffer (Name_Len) /= '/'
1664 Name_Len := Name_Len + 1;
1665 Name_Buffer (Name_Len) := Directory_Separator;
1668 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
1669 Dep_Path_Id := Name_Find;
1671 -- Check if source is already in the list of source for this
1672 -- project: it may have already been specified as a naming
1673 -- exception for the same language or an other language, or they
1674 -- may be two identical file names in different source
1677 while Source_Id /= No_Other_Source loop
1678 Source := Other_Sources.Table (Source_Id);
1679 Source_Id := Source.Next;
1681 if Source.File_Name = File_Id then
1682 -- Two sources of different languages cannot have the same
1685 if Source.Language /= Language then
1686 Error_Msg_Name_1 := File_Name;
1689 "{ cannot be a source of several languages",
1693 -- No problem if a file has already been specified as
1694 -- a naming exception of this language.
1696 elsif Source.Path_Name = Path_Id then
1697 -- Reset the naming exception flag, if this is not a
1698 -- naming exception.
1700 if not Naming_Exception then
1701 Other_Sources.Table (Source_Id).Naming_Exception :=
1707 -- There are several files with the same names, but the
1708 -- order of the source directories is known (no /**):
1709 -- only the first one encountered is kept, the other ones
1712 elsif Data.Known_Order_Of_Source_Dirs then
1715 -- But it is an error if the order of the source directories
1719 Error_Msg_Name_1 := File_Name;
1722 "{ is found in several source directories",
1727 -- Two sources with different file names cannot have the same
1728 -- object file name.
1730 elsif Source.Object_Name = Obj_Id then
1731 Error_Msg_Name_1 := File_Id;
1732 Error_Msg_Name_2 := Source.File_Name;
1733 Error_Msg_Name_3 := Obj_Id;
1736 "{ and { have the same object file {",
1742 if Current_Verbosity = High then
1743 Write_Str (" found ");
1744 Write_Str (Lang_Display_Names (Language).all);
1745 Write_Str (" source """);
1746 Write_Str (Get_Name_String (File_Name));
1748 Write_Str (" object path = ");
1749 Write_Line (Get_Name_String (Obj_Path_Id));
1752 -- Create the Other_Source record
1754 (Language => Language,
1755 File_Name => File_Id,
1756 Path_Name => Path_Id,
1757 Source_TS => File_Stamp (Path_Id),
1758 Object_Name => Obj_Id,
1759 Object_Path => Obj_Path_Id,
1760 Object_TS => File_Stamp (Obj_Path_Id),
1762 Dep_Path => Dep_Path_Id,
1763 Dep_TS => File_Stamp (Dep_Path_Id),
1764 Naming_Exception => Naming_Exception,
1765 Next => No_Other_Source);
1767 -- And add it to the Other_Sources table
1769 Other_Sources.Increment_Last;
1770 Other_Sources.Table (Other_Sources.Last) := Source;
1772 -- There are sources of languages other than Ada in this project
1774 Data.Other_Sources_Present := True;
1776 -- And there are sources of this language in this project
1778 Data.Languages (Language) := True;
1780 -- Add this source to the list of sources of languages other than
1781 -- Ada of the project.
1783 if Data.First_Other_Source = No_Other_Source then
1784 Data.First_Other_Source := Other_Sources.Last;
1787 Other_Sources.Table (Data.Last_Other_Source).Next :=
1791 Data.Last_Other_Source := Other_Sources.Last;
1794 end Check_For_Source;
1796 --------------------------------------
1797 -- Check_Ada_Naming_Scheme_Validity --
1798 --------------------------------------
1800 procedure Check_Ada_Naming_Scheme_Validity
1801 (Project : Project_Id;
1802 Naming : Naming_Data)
1805 -- Only check if we are not using the standard naming scheme
1807 if Naming /= Standard_Naming_Data then
1809 Dot_Replacement : constant String :=
1811 (Naming.Dot_Replacement);
1813 Spec_Suffix : constant String :=
1815 (Naming.Current_Spec_Suffix);
1817 Body_Suffix : constant String :=
1819 (Naming.Current_Body_Suffix);
1821 Separate_Suffix : constant String :=
1823 (Naming.Separate_Suffix);
1826 -- Dot_Replacement cannot
1828 -- - start or end with an alphanumeric
1829 -- - be a single '_'
1830 -- - start with an '_' followed by an alphanumeric
1831 -- - contain a '.' except if it is "."
1833 if Dot_Replacement'Length = 0
1834 or else Is_Alphanumeric
1835 (Dot_Replacement (Dot_Replacement'First))
1836 or else Is_Alphanumeric
1837 (Dot_Replacement (Dot_Replacement'Last))
1838 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1840 (Dot_Replacement'Length = 1
1843 (Dot_Replacement (Dot_Replacement'First + 1))))
1844 or else (Dot_Replacement'Length > 1
1846 Index (Source => Dot_Replacement,
1847 Pattern => ".") /= 0)
1851 '"' & Dot_Replacement &
1852 """ is illegal for Dot_Replacement.",
1853 Naming.Dot_Repl_Loc);
1859 if Is_Illegal_Suffix
1860 (Spec_Suffix, Dot_Replacement = ".")
1862 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1865 "{ is illegal for Spec_Suffix",
1866 Naming.Spec_Suffix_Loc);
1869 if Is_Illegal_Suffix
1870 (Body_Suffix, Dot_Replacement = ".")
1872 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1875 "{ is illegal for Body_Suffix",
1876 Naming.Body_Suffix_Loc);
1879 if Body_Suffix /= Separate_Suffix then
1880 if Is_Illegal_Suffix
1881 (Separate_Suffix, Dot_Replacement = ".")
1883 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1886 "{ is illegal for Separate_Suffix",
1887 Naming.Sep_Suffix_Loc);
1891 -- Spec_Suffix cannot have the same termination as
1892 -- Body_Suffix or Separate_Suffix
1894 if Spec_Suffix'Length <= Body_Suffix'Length
1896 Body_Suffix (Body_Suffix'Last -
1897 Spec_Suffix'Length + 1 ..
1898 Body_Suffix'Last) = Spec_Suffix
1904 """) cannot end with" &
1905 " Spec_Suffix (""" &
1906 Spec_Suffix & """).",
1907 Naming.Body_Suffix_Loc);
1910 if Body_Suffix /= Separate_Suffix
1911 and then Spec_Suffix'Length <= Separate_Suffix'Length
1914 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1916 Separate_Suffix'Last) = Spec_Suffix
1920 "Separate_Suffix (""" &
1922 """) cannot end with" &
1923 " Spec_Suffix (""" &
1924 Spec_Suffix & """).",
1925 Naming.Sep_Suffix_Loc);
1929 end Check_Ada_Naming_Scheme_Validity;
1931 -----------------------------
1932 -- Check_Ada_Naming_Scheme --
1933 -----------------------------
1935 procedure Check_Ada_Naming_Scheme
1936 (Data : in out Project_Data;
1937 Project : Project_Id)
1939 Naming_Id : constant Package_Id :=
1940 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1942 Naming : Package_Element;
1944 procedure Check_Unit_Names (List : Array_Element_Id);
1945 -- Check that a list of unit names contains only valid names.
1947 ----------------------
1948 -- Check_Unit_Names --
1949 ----------------------
1951 procedure Check_Unit_Names (List : Array_Element_Id) is
1952 Current : Array_Element_Id := List;
1953 Element : Array_Element;
1954 Unit_Name : Name_Id;
1957 -- Loop through elements of the string list
1959 while Current /= No_Array_Element loop
1960 Element := Array_Elements.Table (Current);
1962 -- Put file name in canonical case
1964 Get_Name_String (Element.Value.Value);
1965 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1966 Element.Value.Value := Name_Find;
1968 -- Check that it contains a valid unit name
1970 Get_Name_String (Element.Index);
1971 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1973 if Unit_Name = No_Name then
1974 Err_Vars.Error_Msg_Name_1 := Element.Index;
1977 "{ is not a valid unit name.",
1978 Element.Value.Location);
1981 if Current_Verbosity = High then
1982 Write_Str (" Unit (""");
1983 Write_Str (Get_Name_String (Unit_Name));
1987 Element.Index := Unit_Name;
1988 Array_Elements.Table (Current) := Element;
1991 Current := Element.Next;
1993 end Check_Unit_Names;
1995 -- Start of processing for Check_Ada_Naming_Scheme
1998 -- If there is a package Naming, we will put in Data.Naming what is in
1999 -- this package Naming.
2001 if Naming_Id /= No_Package then
2002 Naming := Packages.Table (Naming_Id);
2004 if Current_Verbosity = High then
2005 Write_Line ("Checking ""Naming"" for Ada.");
2009 Bodies : constant Array_Element_Id :=
2010 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
2012 Specs : constant Array_Element_Id :=
2013 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
2016 if Bodies /= No_Array_Element then
2018 -- We have elements in the array Body_Part
2020 if Current_Verbosity = High then
2021 Write_Line ("Found Bodies.");
2024 Data.Naming.Bodies := Bodies;
2025 Check_Unit_Names (Bodies);
2028 if Current_Verbosity = High then
2029 Write_Line ("No Bodies.");
2033 if Specs /= No_Array_Element then
2035 -- We have elements in the array Specs
2037 if Current_Verbosity = High then
2038 Write_Line ("Found Specs.");
2041 Data.Naming.Specs := Specs;
2042 Check_Unit_Names (Specs);
2045 if Current_Verbosity = High then
2046 Write_Line ("No Specs.");
2051 -- We are now checking if variables Dot_Replacement, Casing,
2052 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
2055 -- For each variable, if it does not exist, we do nothing,
2056 -- because we already have the default.
2058 -- Check Dot_Replacement
2061 Dot_Replacement : constant Variable_Value :=
2063 (Name_Dot_Replacement,
2064 Naming.Decl.Attributes);
2067 pragma Assert (Dot_Replacement.Kind = Single,
2068 "Dot_Replacement is not a single string");
2070 if not Dot_Replacement.Default then
2071 Get_Name_String (Dot_Replacement.Value);
2073 if Name_Len = 0 then
2076 "Dot_Replacement cannot be empty",
2077 Dot_Replacement.Location);
2080 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2081 Data.Naming.Dot_Replacement := Name_Find;
2082 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2087 if Current_Verbosity = High then
2088 Write_Str (" Dot_Replacement = """);
2089 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
2097 Casing_String : constant Variable_Value :=
2099 (Name_Casing, Naming.Decl.Attributes);
2102 pragma Assert (Casing_String.Kind = Single,
2103 "Casing is not a single string");
2105 if not Casing_String.Default then
2107 Casing_Image : constant String :=
2108 Get_Name_String (Casing_String.Value);
2111 Casing_Value : constant Casing_Type :=
2112 Value (Casing_Image);
2114 -- Ignore Casing on platforms where file names are
2115 -- case-insensitive.
2117 if not File_Names_Case_Sensitive then
2118 Data.Naming.Casing := All_Lower_Case;
2121 Data.Naming.Casing := Casing_Value;
2126 when Constraint_Error =>
2127 if Casing_Image'Length = 0 then
2130 "Casing cannot be an empty string",
2131 Casing_String.Location);
2134 Name_Len := Casing_Image'Length;
2135 Name_Buffer (1 .. Name_Len) := Casing_Image;
2136 Err_Vars.Error_Msg_Name_1 := Name_Find;
2139 "{ is not a correct Casing",
2140 Casing_String.Location);
2146 if Current_Verbosity = High then
2147 Write_Str (" Casing = ");
2148 Write_Str (Image (Data.Naming.Casing));
2153 -- Check Spec_Suffix
2156 Ada_Spec_Suffix : constant Variable_Value :=
2160 In_Array => Data.Naming.Spec_Suffix);
2163 if Ada_Spec_Suffix.Kind = Single
2164 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2166 Get_Name_String (Ada_Spec_Suffix.Value);
2167 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2168 Data.Naming.Current_Spec_Suffix := Name_Find;
2169 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2172 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2176 if Current_Verbosity = High then
2177 Write_Str (" Spec_Suffix = """);
2178 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2183 -- Check Body_Suffix
2186 Ada_Body_Suffix : constant Variable_Value :=
2190 In_Array => Data.Naming.Body_Suffix);
2193 if Ada_Body_Suffix.Kind = Single
2194 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2196 Get_Name_String (Ada_Body_Suffix.Value);
2197 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2198 Data.Naming.Current_Body_Suffix := Name_Find;
2199 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2202 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2206 if Current_Verbosity = High then
2207 Write_Str (" Body_Suffix = """);
2208 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
2213 -- Check Separate_Suffix
2216 Ada_Sep_Suffix : constant Variable_Value :=
2218 (Variable_Name => Name_Separate_Suffix,
2219 In_Variables => Naming.Decl.Attributes);
2222 if Ada_Sep_Suffix.Default then
2223 Data.Naming.Separate_Suffix :=
2224 Data.Naming.Current_Body_Suffix;
2227 Get_Name_String (Ada_Sep_Suffix.Value);
2229 if Name_Len = 0 then
2232 "Separate_Suffix cannot be empty",
2233 Ada_Sep_Suffix.Location);
2236 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2237 Data.Naming.Separate_Suffix := Name_Find;
2238 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
2243 if Current_Verbosity = High then
2244 Write_Str (" Separate_Suffix = """);
2245 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
2250 -- Check if Data.Naming is valid
2252 Check_Ada_Naming_Scheme_Validity (Project, Data.Naming);
2255 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2256 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2257 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
2259 end Check_Ada_Naming_Scheme;
2265 function Check_Project
2267 Root_Project : Project_Id;
2268 Extending : Boolean) return Boolean
2271 if P = Root_Project then
2274 elsif Extending then
2276 Data : Project_Data := Projects.Table (Root_Project);
2279 while Data.Extends /= No_Project loop
2280 if P = Data.Extends then
2284 Data := Projects.Table (Data.Extends);
2292 ----------------------------
2293 -- Compute_Directory_Last --
2294 ----------------------------
2296 function Compute_Directory_Last (Dir : String) return Natural is
2299 and then (Dir (Dir'Last - 1) = Directory_Separator
2300 or else Dir (Dir'Last - 1) = '/')
2302 return Dir'Last - 1;
2306 end Compute_Directory_Last;
2313 (Project : Project_Id;
2315 Flag_Location : Source_Ptr)
2317 Error_Buffer : String (1 .. 5_000);
2318 Error_Last : Natural := 0;
2319 Msg_Name : Natural := 0;
2320 First : Positive := Msg'First;
2322 procedure Add (C : Character);
2323 -- Add a character to the buffer
2325 procedure Add (S : String);
2326 -- Add a string to the buffer
2328 procedure Add (Id : Name_Id);
2329 -- Add a name to the buffer
2335 procedure Add (C : Character) is
2337 Error_Last := Error_Last + 1;
2338 Error_Buffer (Error_Last) := C;
2341 procedure Add (S : String) is
2343 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2344 Error_Last := Error_Last + S'Length;
2347 procedure Add (Id : Name_Id) is
2349 Get_Name_String (Id);
2350 Add (Name_Buffer (1 .. Name_Len));
2353 -- Start of processing for Error_Msg
2356 if Error_Report = null then
2357 Prj.Err.Error_Msg (Msg, Flag_Location);
2361 if Msg (First) = '\' then
2363 -- Continuation character, ignore.
2367 elsif Msg (First) = '?' then
2369 -- Warning character. It is always the first one in this package
2375 for Index in First .. Msg'Last loop
2376 if Msg (Index) = '{' or else Msg (Index) = '%' then
2378 -- Include a name between double quotes.
2380 Msg_Name := Msg_Name + 1;
2384 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2385 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2386 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2388 when others => null;
2399 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2406 procedure Find_Sources
2407 (Project : Project_Id;
2408 Data : in out Project_Data;
2409 For_Language : Programming_Language;
2410 Follow_Links : Boolean := False)
2412 Source_Dir : String_List_Id := Data.Source_Dirs;
2413 Element : String_Element;
2415 Current_Source : String_List_Id := Nil_String;
2416 Source_Recorded : Boolean := False;
2419 if Current_Verbosity = High then
2420 Write_Line ("Looking for sources:");
2423 -- For each subdirectory
2425 while Source_Dir /= Nil_String loop
2427 Source_Recorded := False;
2428 Element := String_Elements.Table (Source_Dir);
2429 if Element.Value /= No_Name then
2430 Get_Name_String (Element.Display_Value);
2433 Source_Directory : constant String :=
2434 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2435 Dir_Last : constant Natural :=
2436 Compute_Directory_Last (Source_Directory);
2439 if Current_Verbosity = High then
2440 Write_Str ("Source_Dir = ");
2441 Write_Line (Source_Directory);
2444 -- We look to every entry in the source directory
2446 Open (Dir, Source_Directory
2447 (Source_Directory'First .. Dir_Last));
2450 Read (Dir, Name_Buffer, Name_Len);
2452 if Current_Verbosity = High then
2453 Write_Str (" Checking ");
2454 Write_Line (Name_Buffer (1 .. Name_Len));
2457 exit when Name_Len = 0;
2460 File_Name : constant Name_Id := Name_Find;
2461 Path : constant String :=
2463 (Name => Name_Buffer (1 .. Name_Len),
2464 Directory => Source_Directory
2465 (Source_Directory'First .. Dir_Last),
2466 Resolve_Links => Follow_Links,
2467 Case_Sensitive => True);
2468 Path_Name : Name_Id;
2471 Name_Len := Path'Length;
2472 Name_Buffer (1 .. Name_Len) := Path;
2473 Path_Name := Name_Find;
2475 if For_Language = Lang_Ada then
2476 -- We attempt to register it as a source.
2477 -- However, there is no error if the file
2478 -- does not contain a valid source.
2479 -- But there is an error if we have a
2480 -- duplicate unit name.
2483 (File_Name => File_Name,
2484 Path_Name => Path_Name,
2487 Location => No_Location,
2488 Current_Source => Current_Source,
2489 Source_Recorded => Source_Recorded,
2490 Follow_Links => Follow_Links);
2494 (File_Name => File_Name,
2495 Path_Name => Path_Name,
2498 Location => No_Location,
2499 Language => For_Language,
2502 (Data.Impl_Suffixes (For_Language)),
2503 Naming_Exception => False);
2513 when Directory_Error =>
2517 if Source_Recorded then
2518 String_Elements.Table (Source_Dir).Flag := True;
2521 Source_Dir := Element.Next;
2524 if Current_Verbosity = High then
2525 Write_Line ("end Looking for sources.");
2528 if For_Language = Lang_Ada then
2529 -- If we have looked for sources and found none, then
2530 -- it is an error, except if it is an extending project.
2531 -- If a non extending project is not supposed to contain
2532 -- any source, then we never call Find_Sources.
2533 -- No error either when setting up projects (gnat setup).
2535 if Current_Source /= Nil_String then
2536 Data.Ada_Sources_Present := True;
2538 elsif not Setup_Projects and then Data.Extends = No_Project then
2541 "there are no Ada sources in this project",
2547 --------------------------------
2548 -- Free_Ada_Naming_Exceptions --
2549 --------------------------------
2551 procedure Free_Ada_Naming_Exceptions is
2553 Ada_Naming_Exception_Table.Set_Last (0);
2554 Ada_Naming_Exceptions.Reset;
2555 Reverse_Ada_Naming_Exceptions.Reset;
2556 end Free_Ada_Naming_Exceptions;
2562 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2563 Mains : constant Variable_Value :=
2564 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2567 Data.Mains := Mains.Values;
2569 -- If no Mains were specified, and if we are an extending
2570 -- project, inherit the Mains from the project we are extending.
2572 if Mains.Default then
2573 if Data.Extends /= No_Project then
2574 Data.Mains := Projects.Table (Data.Extends).Mains;
2577 -- In a library project file, Main cannot be specified
2579 elsif Data.Library then
2582 "a library project file cannot have Main specified",
2587 ---------------------------
2588 -- Get_Sources_From_File --
2589 ---------------------------
2591 procedure Get_Sources_From_File
2593 Location : Source_Ptr;
2594 Project : Project_Id)
2596 File : Prj.Util.Text_File;
2597 Line : String (1 .. 250);
2599 Source_Name : Name_Id;
2604 if Current_Verbosity = High then
2605 Write_Str ("Opening """);
2612 Prj.Util.Open (File, Path);
2614 if not Prj.Util.Is_Valid (File) then
2615 Error_Msg (Project, "file does not exist", Location);
2617 -- Read the lines one by one
2619 while not Prj.Util.End_Of_File (File) loop
2620 Prj.Util.Get_Line (File, Line, Last);
2622 -- A non empty, non comment line should contain a file name
2625 and then (Last = 1 or else Line (1 .. 2) /= "--")
2627 -- ??? we should check that there is no directory information
2630 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2631 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2632 Source_Name := Name_Find;
2636 (Name => Source_Name,
2637 Location => Location,
2642 Prj.Util.Close (File);
2645 end Get_Sources_From_File;
2652 (Canonical_File_Name : Name_Id;
2653 Naming : Naming_Data;
2654 Exception_Id : out Ada_Naming_Exception_Id;
2655 Unit_Name : out Name_Id;
2656 Unit_Kind : out Spec_Or_Body;
2657 Needs_Pragma : out Boolean)
2659 Info_Id : Ada_Naming_Exception_Id
2660 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
2664 if Info_Id = No_Ada_Naming_Exception then
2665 if Hostparm.OpenVMS then
2666 VMS_Name := Canonical_File_Name;
2667 Get_Name_String (VMS_Name);
2669 if Name_Buffer (Name_Len) = '.' then
2670 Name_Len := Name_Len - 1;
2671 VMS_Name := Name_Find;
2674 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
2679 if Info_Id /= No_Ada_Naming_Exception then
2680 Exception_Id := Info_Id;
2681 Unit_Name := No_Name;
2682 Unit_Kind := Specification;
2683 Needs_Pragma := True;
2687 Needs_Pragma := False;
2688 Exception_Id := No_Ada_Naming_Exception;
2690 Get_Name_String (Canonical_File_Name);
2693 File : String := Name_Buffer (1 .. Name_Len);
2694 First : constant Positive := File'First;
2695 Last : Natural := File'Last;
2696 Standard_GNAT : Boolean;
2700 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2701 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2703 -- Check if the end of the file name is Specification_Append
2705 Get_Name_String (Naming.Current_Spec_Suffix);
2707 if File'Length > Name_Len
2708 and then File (Last - Name_Len + 1 .. Last) =
2709 Name_Buffer (1 .. Name_Len)
2713 Unit_Kind := Specification;
2714 Last := Last - Name_Len;
2716 if Current_Verbosity = High then
2717 Write_Str (" Specification: ");
2718 Write_Line (File (First .. Last));
2722 Get_Name_String (Naming.Current_Body_Suffix);
2724 -- Check if the end of the file name is Body_Append
2726 if File'Length > Name_Len
2727 and then File (Last - Name_Len + 1 .. Last) =
2728 Name_Buffer (1 .. Name_Len)
2732 Unit_Kind := Body_Part;
2733 Last := Last - Name_Len;
2735 if Current_Verbosity = High then
2736 Write_Str (" Body: ");
2737 Write_Line (File (First .. Last));
2740 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2741 Get_Name_String (Naming.Separate_Suffix);
2743 -- Check if the end of the file name is Separate_Append
2745 if File'Length > Name_Len
2746 and then File (Last - Name_Len + 1 .. Last) =
2747 Name_Buffer (1 .. Name_Len)
2749 -- We have a separate (a body)
2751 Unit_Kind := Body_Part;
2752 Last := Last - Name_Len;
2754 if Current_Verbosity = High then
2755 Write_Str (" Separate: ");
2756 Write_Line (File (First .. Last));
2770 -- This is not a source file
2772 Unit_Name := No_Name;
2773 Unit_Kind := Specification;
2775 if Current_Verbosity = High then
2776 Write_Line (" Not a valid file name.");
2782 Get_Name_String (Naming.Dot_Replacement);
2784 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2786 if Name_Buffer (1 .. Name_Len) /= "." then
2788 -- If Dot_Replacement is not a single dot,
2789 -- then there should not be any dot in the name.
2791 for Index in First .. Last loop
2792 if File (Index) = '.' then
2793 if Current_Verbosity = High then
2795 (" Not a valid file name (some dot not replaced).");
2798 Unit_Name := No_Name;
2804 -- Replace the substring Dot_Replacement with dots
2807 Index : Positive := First;
2810 while Index <= Last - Name_Len + 1 loop
2812 if File (Index .. Index + Name_Len - 1) =
2813 Name_Buffer (1 .. Name_Len)
2815 File (Index) := '.';
2817 if Name_Len > 1 and then Index < Last then
2818 File (Index + 1 .. Last - Name_Len + 1) :=
2819 File (Index + Name_Len .. Last);
2822 Last := Last - Name_Len + 1;
2830 -- Check if the casing is right
2833 Src : String := File (First .. Last);
2836 case Naming.Casing is
2837 when All_Lower_Case =>
2840 Mapping => Lower_Case_Map);
2842 when All_Upper_Case =>
2845 Mapping => Upper_Case_Map);
2847 when Mixed_Case | Unknown =>
2851 if Src /= File (First .. Last) then
2852 if Current_Verbosity = High then
2853 Write_Line (" Not a valid file name (casing).");
2856 Unit_Name := No_Name;
2860 -- We put the name in lower case
2864 Mapping => Lower_Case_Map);
2866 -- In the standard GNAT naming scheme, check for special cases:
2867 -- children or separates of A, G, I or S, and run time sources.
2869 if Standard_GNAT and then Src'Length >= 3 then
2871 S1 : constant Character := Src (Src'First);
2872 S2 : constant Character := Src (Src'First + 1);
2875 if S1 = 'a' or else S1 = 'g'
2876 or else S1 = 'i' or else S1 = 's'
2878 -- Children or separates of packages A, G, I or S
2880 if (Hostparm.OpenVMS and then S2 = '$')
2881 or else (not Hostparm.OpenVMS and then S2 = '~')
2883 Src (Src'First + 1) := '.';
2885 -- If it is potentially a run time source, disable
2886 -- filling of the mapping file to avoid warnings.
2889 Set_Mapping_File_Initial_State_To_Empty;
2896 if Current_Verbosity = High then
2901 -- Now, we check if this name is a valid unit name
2903 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2913 function Hash (Unit : Unit_Info) return Header_Num is
2915 return Header_Num (Unit.Unit mod 2048);
2918 -----------------------
2919 -- Is_Illegal_Suffix --
2920 -----------------------
2922 function Is_Illegal_Suffix
2924 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2927 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2931 -- If dot replacement is a single dot, and first character of
2932 -- suffix is also a dot
2934 if Dot_Replacement_Is_A_Single_Dot
2935 and then Suffix (Suffix'First) = '.'
2937 for Index in Suffix'First + 1 .. Suffix'Last loop
2939 -- If there is another dot
2941 if Suffix (Index) = '.' then
2943 -- It is illegal to have a letter following the initial dot
2945 return Is_Letter (Suffix (Suffix'First + 1));
2953 end Is_Illegal_Suffix;
2955 --------------------------------
2956 -- Language_Independent_Check --
2957 --------------------------------
2959 procedure Language_Independent_Check
2960 (Project : Project_Id;
2961 Report_Error : Put_Line_Access)
2963 Last_Source_Dir : String_List_Id := Nil_String;
2964 Data : Project_Data := Projects.Table (Project);
2966 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2967 -- Find one or several source directories, and add them
2968 -- to the list of source directories of the project.
2970 ----------------------
2971 -- Find_Source_Dirs --
2972 ----------------------
2974 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2975 Directory : constant String := Get_Name_String (From);
2976 Element : String_Element;
2978 procedure Recursive_Find_Dirs (Path : Name_Id);
2979 -- Find all the subdirectories (recursively) of Path and add them
2980 -- to the list of source directories of the project.
2982 -------------------------
2983 -- Recursive_Find_Dirs --
2984 -------------------------
2986 procedure Recursive_Find_Dirs (Path : Name_Id) is
2988 Name : String (1 .. 250);
2990 List : String_List_Id := Data.Source_Dirs;
2991 Element : String_Element;
2992 Found : Boolean := False;
2994 Non_Canonical_Path : Name_Id := No_Name;
2995 Canonical_Path : Name_Id := No_Name;
2997 The_Path : constant String :=
2998 Normalize_Pathname (Get_Name_String (Path)) &
2999 Directory_Separator;
3001 The_Path_Last : constant Natural :=
3002 Compute_Directory_Last (The_Path);
3005 Name_Len := The_Path_Last - The_Path'First + 1;
3006 Name_Buffer (1 .. Name_Len) :=
3007 The_Path (The_Path'First .. The_Path_Last);
3008 Non_Canonical_Path := Name_Find;
3009 Get_Name_String (Non_Canonical_Path);
3010 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3011 Canonical_Path := Name_Find;
3013 -- To avoid processing the same directory several times, check
3014 -- if the directory is already in Recursive_Dirs. If it is,
3015 -- then there is nothing to do, just return. If it is not, put
3016 -- it there and continue recursive processing.
3018 if Recursive_Dirs.Get (Canonical_Path) then
3022 Recursive_Dirs.Set (Canonical_Path, True);
3025 -- Check if directory is already in list
3027 while List /= Nil_String loop
3028 Element := String_Elements.Table (List);
3030 if Element.Value /= No_Name then
3031 Found := Element.Value = Canonical_Path;
3035 List := Element.Next;
3038 -- If directory is not already in list, put it there
3041 if Current_Verbosity = High then
3043 Write_Line (The_Path (The_Path'First .. The_Path_Last));
3046 String_Elements.Increment_Last;
3048 (Value => Canonical_Path,
3049 Display_Value => Non_Canonical_Path,
3050 Location => No_Location,
3055 -- Case of first source directory
3057 if Last_Source_Dir = Nil_String then
3058 Data.Source_Dirs := String_Elements.Last;
3060 -- Here we already have source directories.
3063 -- Link the previous last to the new one
3065 String_Elements.Table (Last_Source_Dir).Next :=
3066 String_Elements.Last;
3069 -- And register this source directory as the new last
3071 Last_Source_Dir := String_Elements.Last;
3072 String_Elements.Table (Last_Source_Dir) := Element;
3075 -- Now look for subdirectories. We do that even when this
3076 -- directory is already in the list, because some of its
3077 -- subdirectories may not be in the list yet.
3079 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3082 Read (Dir, Name, Last);
3085 if Name (1 .. Last) /= "."
3086 and then Name (1 .. Last) /= ".."
3090 if Current_Verbosity = High then
3091 Write_Str (" Checking ");
3092 Write_Line (Name (1 .. Last));
3096 Path_Name : constant String :=
3098 (Name => Name (1 .. Last),
3101 (The_Path'First .. The_Path_Last),
3102 Resolve_Links => False,
3103 Case_Sensitive => True);
3106 if Is_Directory (Path_Name) then
3108 -- We have found a new subdirectory, call self
3110 Name_Len := Path_Name'Length;
3111 Name_Buffer (1 .. Name_Len) := Path_Name;
3112 Recursive_Find_Dirs (Name_Find);
3121 when Directory_Error =>
3123 end Recursive_Find_Dirs;
3125 -- Start of processing for Find_Source_Dirs
3128 if Current_Verbosity = High then
3129 Write_Str ("Find_Source_Dirs (""");
3130 Write_Str (Directory);
3134 -- First, check if we are looking for a directory tree,
3135 -- indicated by "/**" at the end.
3137 if Directory'Length >= 3
3138 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3139 and then (Directory (Directory'Last - 2) = '/'
3141 Directory (Directory'Last - 2) = Directory_Separator)
3143 Data.Known_Order_Of_Source_Dirs := False;
3145 Name_Len := Directory'Length - 3;
3147 if Name_Len = 0 then
3149 -- This is the case of "/**": all directories
3150 -- in the file system.
3153 Name_Buffer (1) := Directory (Directory'First);
3156 Name_Buffer (1 .. Name_Len) :=
3157 Directory (Directory'First .. Directory'Last - 3);
3160 if Current_Verbosity = High then
3161 Write_Str ("Looking for all subdirectories of """);
3162 Write_Str (Name_Buffer (1 .. Name_Len));
3167 Base_Dir : constant Name_Id := Name_Find;
3168 Root_Dir : constant String :=
3170 (Name => Get_Name_String (Base_Dir),
3172 Get_Name_String (Data.Display_Directory),
3173 Resolve_Links => False,
3174 Case_Sensitive => True);
3177 if Root_Dir'Length = 0 then
3178 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3180 if Location = No_Location then
3183 "{ is not a valid directory.",
3188 "{ is not a valid directory.",
3193 -- We have an existing directory,
3194 -- we register it and all of its subdirectories.
3196 if Current_Verbosity = High then
3197 Write_Line ("Looking for source directories:");
3200 Name_Len := Root_Dir'Length;
3201 Name_Buffer (1 .. Name_Len) := Root_Dir;
3202 Recursive_Find_Dirs (Name_Find);
3204 if Current_Verbosity = High then
3205 Write_Line ("End of looking for source directories.");
3210 -- We have a single directory
3214 Path_Name : Name_Id;
3215 Display_Path_Name : Name_Id;
3218 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3219 if Path_Name = No_Name then
3220 Err_Vars.Error_Msg_Name_1 := From;
3222 if Location = No_Location then
3225 "{ is not a valid directory",
3230 "{ is not a valid directory",
3235 -- As it is an existing directory, we add it to
3236 -- the list of directories.
3238 String_Elements.Increment_Last;
3239 Element.Value := Path_Name;
3240 Element.Display_Value := Display_Path_Name;
3242 if Last_Source_Dir = Nil_String then
3244 -- This is the first source directory
3246 Data.Source_Dirs := String_Elements.Last;
3249 -- We already have source directories,
3250 -- link the previous last to the new one.
3252 String_Elements.Table (Last_Source_Dir).Next :=
3253 String_Elements.Last;
3256 -- And register this source directory as the new last
3258 Last_Source_Dir := String_Elements.Last;
3259 String_Elements.Table (Last_Source_Dir) := Element;
3263 end Find_Source_Dirs;
3265 -- Start of processing for Language_Independent_Check
3268 if Data.Language_Independent_Checked then
3272 Data.Language_Independent_Checked := True;
3274 Error_Report := Report_Error;
3276 Recursive_Dirs.Reset;
3278 if Current_Verbosity = High then
3279 Write_Line ("Starting to look for directories");
3282 -- Check the object directory
3285 Object_Dir : constant Variable_Value :=
3286 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3289 pragma Assert (Object_Dir.Kind = Single,
3290 "Object_Dir is not a single string");
3292 -- We set the object directory to its default
3294 Data.Object_Directory := Data.Directory;
3295 Data.Display_Object_Dir := Data.Display_Directory;
3297 if Object_Dir.Value /= Empty_String then
3299 Get_Name_String (Object_Dir.Value);
3301 if Name_Len = 0 then
3304 "Object_Dir cannot be empty",
3305 Object_Dir.Location);
3308 -- We check that the specified object directory
3309 -- does exist, and attempt to create it if setting up projects
3313 (Object_Dir.Value, Data.Display_Directory,
3314 Data.Object_Directory, Data.Display_Object_Dir,
3315 Project => Project, Kind => "object",
3316 Location => Object_Dir.Location);
3318 if not Setup_Projects
3319 and then Data.Object_Directory = No_Name
3321 -- The object directory does not exist, report an error
3322 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3325 "the object directory { cannot be found",
3328 -- Do not keep a nil Object_Directory. Set it to the
3329 -- specified (relative or absolute) path.
3330 -- This is for the benefit of tools that recover from
3331 -- errors; for example, these tools could create the
3332 -- non existent directory.
3334 Data.Display_Object_Dir := Object_Dir.Value;
3335 Get_Name_String (Object_Dir.Value);
3336 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3337 Data.Object_Directory := Name_Find;
3343 if Current_Verbosity = High then
3344 if Data.Object_Directory = No_Name then
3345 Write_Line ("No object directory");
3347 Write_Str ("Object directory: """);
3348 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3353 -- Check the exec directory
3356 Exec_Dir : constant Variable_Value :=
3357 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3360 pragma Assert (Exec_Dir.Kind = Single,
3361 "Exec_Dir is not a single string");
3363 -- We set the object directory to its default
3365 Data.Exec_Directory := Data.Object_Directory;
3366 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3368 if Exec_Dir.Value /= Empty_String then
3370 Get_Name_String (Exec_Dir.Value);
3372 if Name_Len = 0 then
3375 "Exec_Dir cannot be empty",
3379 -- We check that the specified exec directory does exist and
3380 -- attempt to create it if setting up projects (gnat setup).
3383 (Exec_Dir.Value, Data.Directory,
3384 Data.Exec_Directory, Data.Display_Exec_Dir,
3385 Project => Project, Kind => "exec",
3386 Location => Exec_Dir.Location);
3388 if not Setup_Projects
3389 and then Data.Exec_Directory = No_Name
3391 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3394 "the exec directory { cannot be found",
3401 if Current_Verbosity = High then
3402 if Data.Exec_Directory = No_Name then
3403 Write_Line ("No exec directory");
3405 Write_Str ("Exec directory: """);
3406 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3411 -- Look for the source directories
3414 Source_Dirs : constant Variable_Value :=
3416 (Name_Source_Dirs, Data.Decl.Attributes);
3419 if Current_Verbosity = High then
3420 Write_Line ("Starting to look for source directories");
3423 pragma Assert (Source_Dirs.Kind = List,
3424 "Source_Dirs is not a list");
3426 if Source_Dirs.Default then
3428 -- No Source_Dirs specified: the single source directory
3429 -- is the one containing the project file
3431 String_Elements.Increment_Last;
3432 Data.Source_Dirs := String_Elements.Last;
3433 String_Elements.Table (Data.Source_Dirs) :=
3434 (Value => Data.Directory,
3435 Display_Value => Data.Display_Directory,
3436 Location => No_Location,
3441 if Current_Verbosity = High then
3442 Write_Line ("Single source directory:");
3444 Write_Str (Get_Name_String (Data.Display_Directory));
3448 elsif Source_Dirs.Values = Nil_String then
3450 -- If Source_Dirs is an empty string list, this means
3451 -- that this project contains no source. For projects that
3452 -- don't extend other projects, this also means that there is no
3453 -- need for an object directory, if not specified.
3455 if Data.Extends = No_Project
3456 and then Data.Object_Directory = Data.Directory
3458 Data.Object_Directory := No_Name;
3461 Data.Source_Dirs := Nil_String;
3462 Data.Ada_Sources_Present := False;
3463 Data.Other_Sources_Present := False;
3467 Source_Dir : String_List_Id := Source_Dirs.Values;
3468 Element : String_Element;
3471 -- We will find the source directories for each
3472 -- element of the list
3474 while Source_Dir /= Nil_String loop
3475 Element := String_Elements.Table (Source_Dir);
3476 Find_Source_Dirs (Element.Value, Element.Location);
3477 Source_Dir := Element.Next;
3482 if Current_Verbosity = High then
3483 Write_Line ("Putting source directories in canonical cases");
3487 Current : String_List_Id := Data.Source_Dirs;
3488 Element : String_Element;
3491 while Current /= Nil_String loop
3492 Element := String_Elements.Table (Current);
3493 if Element.Value /= No_Name then
3494 Get_Name_String (Element.Value);
3495 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3496 Element.Value := Name_Find;
3497 String_Elements.Table (Current) := Element;
3500 Current := Element.Next;
3505 -- Library attributes
3508 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3510 Lib_Dir : constant Prj.Variable_Value :=
3511 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3513 Lib_Name : constant Prj.Variable_Value :=
3514 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3516 Lib_Version : constant Prj.Variable_Value :=
3518 (Snames.Name_Library_Version, Attributes);
3520 The_Lib_Kind : constant Prj.Variable_Value :=
3522 (Snames.Name_Library_Kind, Attributes);
3525 -- Special case of extending project
3527 if Data.Extends /= No_Project then
3529 Extended_Data : constant Project_Data :=
3530 Projects.Table (Data.Extends);
3533 -- If the project extended is a library project, we inherit
3534 -- the library name, if it is not redefined; we check that
3535 -- the library directory is specified; and we reset the
3536 -- library flag for the extended project.
3538 if Extended_Data.Library then
3539 if Lib_Name.Default then
3540 Data.Library_Name := Extended_Data.Library_Name;
3543 if Lib_Dir.Default then
3545 -- If the extending project is a virtual project, we
3546 -- put the error message in the library project that
3547 -- is extended, rather than in the extending all project.
3548 -- Of course, we cannot put it in the virtual extending
3549 -- project, because it has no source.
3551 if Data.Virtual then
3552 Error_Msg_Name_1 := Extended_Data.Name;
3556 "library project % cannot be virtually extended",
3557 Extended_Data.Location);
3562 "a project extending a library project must " &
3563 "specify an attribute Library_Dir",
3568 Projects.Table (Data.Extends).Library := False;
3573 pragma Assert (Lib_Dir.Kind = Single);
3575 if Lib_Dir.Value = Empty_String then
3577 if Current_Verbosity = High then
3578 Write_Line ("No library directory");
3582 -- Find path name, check that it is a directory, and attempt
3583 -- to create it if setting up projects (gnat setup).
3586 (Lib_Dir.Value, Data.Display_Directory,
3587 Data.Library_Dir, Data.Display_Library_Dir,
3588 Project => Project, Kind => "library",
3589 Location => Lib_Dir.Location);
3591 if not Setup_Projects and then Data.Library_Dir = No_Name then
3593 -- Get the absolute name of the library directory that
3594 -- does not exist, to report an error.
3597 Dir_Name : constant String :=
3598 Get_Name_String (Lib_Dir.Value);
3600 if Is_Absolute_Path (Dir_Name) then
3601 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3604 Get_Name_String (Data.Display_Directory);
3606 if Name_Buffer (Name_Len) /= Directory_Separator then
3607 Name_Len := Name_Len + 1;
3608 Name_Buffer (Name_Len) := Directory_Separator;
3612 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3614 Name_Len := Name_Len + Dir_Name'Length;
3615 Err_Vars.Error_Msg_Name_1 := Name_Find;
3622 "library directory { does not exist",
3626 elsif Data.Library_Dir = Data.Object_Directory then
3629 "library directory cannot be the same " &
3630 "as object directory",
3632 Data.Library_Dir := No_Name;
3633 Data.Display_Library_Dir := No_Name;
3636 if Current_Verbosity = High then
3637 Write_Str ("Library directory =""");
3638 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3644 pragma Assert (Lib_Name.Kind = Single);
3646 if Lib_Name.Value = Empty_String then
3647 if Current_Verbosity = High
3648 and then Data.Library_Name = No_Name
3650 Write_Line ("No library name");
3654 -- There is no restriction on the syntax of library names
3656 Data.Library_Name := Lib_Name.Value;
3659 if Data.Library_Name /= No_Name
3660 and then Current_Verbosity = High
3662 Write_Str ("Library name = """);
3663 Write_Str (Get_Name_String (Data.Library_Name));
3668 Data.Library_Dir /= No_Name
3670 Data.Library_Name /= No_Name;
3672 if Data.Library then
3673 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3676 "?libraries are not supported on this platform",
3678 Data.Library := False;
3681 pragma Assert (Lib_Version.Kind = Single);
3683 if Lib_Version.Value = Empty_String then
3684 if Current_Verbosity = High then
3685 Write_Line ("No library version specified");
3689 Data.Lib_Internal_Name := Lib_Version.Value;
3692 pragma Assert (The_Lib_Kind.Kind = Single);
3694 if The_Lib_Kind.Value = Empty_String then
3695 if Current_Verbosity = High then
3696 Write_Line ("No library kind specified");
3700 Get_Name_String (The_Lib_Kind.Value);
3703 Kind_Name : constant String :=
3704 To_Lower (Name_Buffer (1 .. Name_Len));
3706 OK : Boolean := True;
3709 if Kind_Name = "static" then
3710 Data.Library_Kind := Static;
3712 elsif Kind_Name = "dynamic" then
3713 Data.Library_Kind := Dynamic;
3715 elsif Kind_Name = "relocatable" then
3716 Data.Library_Kind := Relocatable;
3721 "illegal value for Library_Kind",
3722 The_Lib_Kind.Location);
3726 if Current_Verbosity = High and then OK then
3727 Write_Str ("Library kind = ");
3728 Write_Line (Kind_Name);
3731 if Data.Library_Kind /= Static and then
3732 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3736 "only static libraries are supported " &
3738 The_Lib_Kind.Location);
3739 Data.Library := False;
3744 if Data.Library and then Current_Verbosity = High then
3745 Write_Line ("This is a library project file");
3752 if Current_Verbosity = High then
3753 Show_Source_Dirs (Project);
3757 Naming_Id : constant Package_Id :=
3758 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3760 Naming : Package_Element;
3763 -- If there is a package Naming, we will put in Data.Naming
3764 -- what is in this package Naming.
3766 if Naming_Id /= No_Package then
3767 Naming := Packages.Table (Naming_Id);
3769 if Current_Verbosity = High then
3770 Write_Line ("Checking ""Naming"".");
3773 -- Check Spec_Suffix
3776 Spec_Suffixs : Array_Element_Id :=
3779 Naming.Decl.Arrays);
3780 Suffix : Array_Element_Id;
3781 Element : Array_Element;
3782 Suffix2 : Array_Element_Id;
3785 -- If some suffixs have been specified, we make sure that
3786 -- for each language for which a default suffix has been
3787 -- specified, there is a suffix specified, either the one
3788 -- in the project file or if there were none, the default.
3790 if Spec_Suffixs /= No_Array_Element then
3791 Suffix := Data.Naming.Spec_Suffix;
3793 while Suffix /= No_Array_Element loop
3794 Element := Array_Elements.Table (Suffix);
3795 Suffix2 := Spec_Suffixs;
3797 while Suffix2 /= No_Array_Element loop
3798 exit when Array_Elements.Table (Suffix2).Index =
3800 Suffix2 := Array_Elements.Table (Suffix2).Next;
3803 -- There is a registered default suffix, but no
3804 -- suffix specified in the project file.
3805 -- Add the default to the array.
3807 if Suffix2 = No_Array_Element then
3808 Array_Elements.Increment_Last;
3809 Array_Elements.Table (Array_Elements.Last) :=
3810 (Index => Element.Index,
3811 Src_Index => Element.Src_Index,
3812 Index_Case_Sensitive => False,
3813 Value => Element.Value,
3814 Next => Spec_Suffixs);
3815 Spec_Suffixs := Array_Elements.Last;
3818 Suffix := Element.Next;
3821 -- Put the resulting array as the specification suffixs
3823 Data.Naming.Spec_Suffix := Spec_Suffixs;
3828 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3829 Element : Array_Element;
3832 while Current /= No_Array_Element loop
3833 Element := Array_Elements.Table (Current);
3834 Get_Name_String (Element.Value.Value);
3836 if Name_Len = 0 then
3839 "Spec_Suffix cannot be empty",
3840 Element.Value.Location);
3843 Array_Elements.Table (Current) := Element;
3844 Current := Element.Next;
3848 -- Check Body_Suffix
3851 Impl_Suffixs : Array_Element_Id :=
3854 Naming.Decl.Arrays);
3856 Suffix : Array_Element_Id;
3857 Element : Array_Element;
3858 Suffix2 : Array_Element_Id;
3861 -- If some suffixs have been specified, we make sure that
3862 -- for each language for which a default suffix has been
3863 -- specified, there is a suffix specified, either the one
3864 -- in the project file or if there were noe, the default.
3866 if Impl_Suffixs /= No_Array_Element then
3867 Suffix := Data.Naming.Body_Suffix;
3869 while Suffix /= No_Array_Element loop
3870 Element := Array_Elements.Table (Suffix);
3871 Suffix2 := Impl_Suffixs;
3873 while Suffix2 /= No_Array_Element loop
3874 exit when Array_Elements.Table (Suffix2).Index =
3876 Suffix2 := Array_Elements.Table (Suffix2).Next;
3879 -- There is a registered default suffix, but no
3880 -- suffix specified in the project file.
3881 -- Add the default to the array.
3883 if Suffix2 = No_Array_Element then
3884 Array_Elements.Increment_Last;
3885 Array_Elements.Table (Array_Elements.Last) :=
3886 (Index => Element.Index,
3887 Src_Index => Element.Src_Index,
3888 Index_Case_Sensitive => False,
3889 Value => Element.Value,
3890 Next => Impl_Suffixs);
3891 Impl_Suffixs := Array_Elements.Last;
3894 Suffix := Element.Next;
3897 -- Put the resulting array as the implementation suffixs
3899 Data.Naming.Body_Suffix := Impl_Suffixs;
3904 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3905 Element : Array_Element;
3908 while Current /= No_Array_Element loop
3909 Element := Array_Elements.Table (Current);
3910 Get_Name_String (Element.Value.Value);
3912 if Name_Len = 0 then
3915 "Body_Suffix cannot be empty",
3916 Element.Value.Location);
3919 Array_Elements.Table (Current) := Element;
3920 Current := Element.Next;
3924 -- Get the exceptions, if any
3926 Data.Naming.Specification_Exceptions :=
3928 (Name_Specification_Exceptions,
3929 In_Arrays => Naming.Decl.Arrays);
3931 Data.Naming.Implementation_Exceptions :=
3933 (Name_Implementation_Exceptions,
3934 In_Arrays => Naming.Decl.Arrays);
3938 Projects.Table (Project) := Data;
3939 end Language_Independent_Check;
3941 ----------------------
3942 -- Locate_Directory --
3943 ----------------------
3945 procedure Locate_Directory
3949 Display : out Name_Id;
3950 Project : Project_Id := No_Project;
3951 Kind : String := "";
3952 Location : Source_Ptr := No_Location)
3954 The_Name : constant String := Get_Name_String (Name);
3955 The_Parent : constant String :=
3956 Get_Name_String (Parent) & Directory_Separator;
3957 The_Parent_Last : constant Natural :=
3958 Compute_Directory_Last (The_Parent);
3960 procedure Create_Directory (Absolute_Path : String);
3961 -- Attempt to create a new directory
3963 procedure Get_Names_For (Absolute_Path : String);
3964 -- Create name ids Dir and Display for directory Absolute_Path
3966 ----------------------
3967 -- Create_Directory --
3968 ----------------------
3970 procedure Create_Directory (Absolute_Path : String) is
3972 -- Attempt to create the directory
3974 Make_Dir (Absolute_Path);
3976 -- Setup Dir and Display if creation was successful
3978 Get_Names_For (Absolute_Path);
3981 when Directory_Error =>
3984 "could not create " & Kind & " directory """ &
3985 Absolute_Path & """",
3987 end Create_Directory;
3993 procedure Get_Names_For (Absolute_Path : String) is
3994 Normed : constant String :=
3997 Resolve_Links => False,
3998 Case_Sensitive => True);
4000 Canonical_Path : constant String :=
4003 Resolve_Links => True,
4004 Case_Sensitive => False);
4007 Name_Len := Normed'Length;
4008 Name_Buffer (1 .. Name_Len) := Normed;
4009 Display := Name_Find;
4011 Name_Len := Canonical_Path'Length;
4012 Name_Buffer (1 .. Name_Len) := Canonical_Path;
4016 -- Start of processing for Locate_Directory
4019 if Current_Verbosity = High then
4020 Write_Str ("Locate_Directory (""");
4021 Write_Str (The_Name);
4022 Write_Str (""", """);
4023 Write_Str (The_Parent);
4030 if Is_Absolute_Path (The_Name) then
4031 if Is_Directory (The_Name) then
4032 Get_Names_For (The_Name);
4034 elsif Kind /= "" and then Setup_Projects then
4035 Create_Directory (The_Name);
4040 Full_Path : constant String :=
4041 The_Parent (The_Parent'First .. The_Parent_Last) &
4045 if Is_Directory (Full_Path) then
4046 Get_Names_For (Full_Path);
4048 elsif Kind /= "" and then Setup_Projects then
4049 Create_Directory (Full_Path);
4053 end Locate_Directory;
4055 ---------------------------
4056 -- Other_Languages_Check --
4057 ---------------------------
4059 procedure Other_Languages_Check
4060 (Project : Project_Id;
4061 Report_Error : Put_Line_Access) is
4063 Data : Project_Data;
4065 Languages : Variable_Value := Nil_Variable_Value;
4068 Language_Independent_Check (Project, Report_Error);
4070 Error_Report := Report_Error;
4072 Data := Projects.Table (Project);
4073 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
4075 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4077 if Data.Other_Sources_Present then
4078 -- Check if languages other than Ada are specified in this project
4080 if Languages.Default then
4081 -- Attribute Languages is not specified. So, it defaults to
4082 -- a project of language Ada only.
4084 Data.Languages (Lang_Ada) := True;
4086 -- No sources of languages other than Ada
4088 Data.Other_Sources_Present := False;
4092 Current : String_List_Id := Languages.Values;
4093 Element : String_Element;
4094 OK : Boolean := False;
4096 -- Assumethat there is no language other than Ada specified.
4097 -- If in fact there is at least one, we will set back
4098 -- Other_Sources_Present to True.
4100 Data.Other_Sources_Present := False;
4102 -- Look through all the languages specified in attribute
4103 -- Languages, if any
4105 while Current /= Nil_String loop
4106 Element := String_Elements.Table (Current);
4107 Get_Name_String (Element.Value);
4108 To_Lower (Name_Buffer (1 .. Name_Len));
4111 -- Check if it is a known language
4113 Lang_Loop : for Lang in Programming_Language loop
4115 Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4117 -- Yes, this is a known language
4121 -- Indicate the presence of this language
4122 Data.Languages (Lang) := True;
4124 -- If it is a language other than Ada, indicate that
4125 -- there should be some sources of a language other
4128 if Lang /= Lang_Ada then
4129 Data.Other_Sources_Present := True;
4136 -- We don't support this language: report an error
4139 Error_Msg_Name_1 := Element.Value;
4142 "unknown programming language {",
4146 Current := Element.Next;
4152 -- If there may be some sources, look for them
4154 if Data.Other_Sources_Present then
4155 -- Set Source_Present to False. It will be set back to True whenever
4156 -- a source is found.
4158 Data.Other_Sources_Present := False;
4160 for Lang in Other_Programming_Language loop
4161 -- For each language (other than Ada) in the project file
4163 if Data.Languages (Lang) then
4164 -- Reset the indication that there are sources of this
4165 -- language. It will be set back to True whenever we find a
4166 -- source of the language.
4168 Data.Languages (Lang) := False;
4170 -- First, get the source suffix for the language
4172 Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4174 -- Then, deal with the naming exceptions, if any
4179 Naming_Exceptions : constant Variable_Value :=
4181 (Index => Lang_Name_Ids (Lang),
4183 In_Array => Data.Naming.Implementation_Exceptions);
4184 Element_Id : String_List_Id;
4185 Element : String_Element;
4187 Source_Found : Boolean := False;
4189 -- If there are naming exceptions, look through them one
4192 if Naming_Exceptions /= Nil_Variable_Value then
4193 Element_Id := Naming_Exceptions.Values;
4195 while Element_Id /= Nil_String loop
4196 Element := String_Elements.Table (Element_Id);
4197 Get_Name_String (Element.Value);
4198 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4199 File_Id := Name_Find;
4201 -- Put each naming exception in the Source_Names
4202 -- hash table, but if there are repetition, don't
4203 -- bother after the first instance.
4205 if Source_Names.Get (File_Id) = No_Name_Location then
4206 Source_Found := True;
4210 Location => Element.Location,
4214 Element_Id := Element.Next;
4217 -- If there is at least one naming exception, record
4218 -- those that are found in the source directories.
4220 if Source_Found then
4221 Record_Other_Sources
4222 (Project => Project,
4225 Naming_Exceptions => True);
4231 -- Now, check if a list of sources is declared either through
4232 -- a string list (attribute Source_Files) or a text file
4233 -- (attribute Source_List_File).
4234 -- If a source list is declared, we will consider only those
4235 -- naming exceptions that are on the list.
4238 Sources : constant Variable_Value :=
4241 Data.Decl.Attributes);
4243 Source_List_File : constant Variable_Value :=
4245 (Name_Source_List_File,
4246 Data.Decl.Attributes);
4250 (Sources.Kind = List,
4251 "Source_Files is not a list");
4254 (Source_List_File.Kind = Single,
4255 "Source_List_File is not a single string");
4257 if not Sources.Default then
4258 if not Source_List_File.Default then
4261 "?both variables source_files and " &
4262 "source_list_file are present",
4263 Source_List_File.Location);
4266 -- Sources is a list of file names
4269 Current : String_List_Id := Sources.Values;
4270 Element : String_Element;
4271 Location : Source_Ptr;
4277 -- Put all the sources in the Source_Names hash
4280 while Current /= Nil_String loop
4281 Element := String_Elements.Table (Current);
4282 Get_Name_String (Element.Value);
4283 Canonical_Case_File_Name
4284 (Name_Buffer (1 .. Name_Len));
4287 -- If the element has no location, then use the
4288 -- location of Sources to report possible errors.
4290 if Element.Location = No_Location then
4291 Location := Sources.Location;
4294 Location := Element.Location;
4301 Location => Location,
4304 Current := Element.Next;
4307 -- And look for their directories
4309 Record_Other_Sources
4310 (Project => Project,
4313 Naming_Exceptions => False);
4316 -- No source_files specified.
4317 -- We check if Source_List_File has been specified.
4319 elsif not Source_List_File.Default then
4321 -- Source_List_File is the name of the file
4322 -- that contains the source file names
4325 Source_File_Path_Name : constant String :=
4327 (Source_List_File.Value,
4331 if Source_File_Path_Name'Length = 0 then
4332 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4335 "file with sources { does not exist",
4336 Source_List_File.Location);
4339 -- Read the file, putting each source in the
4340 -- Source_Names hash table.
4342 Get_Sources_From_File
4343 (Source_File_Path_Name,
4344 Source_List_File.Location,
4347 -- And look for their directories.
4349 Record_Other_Sources
4350 (Project => Project,
4353 Naming_Exceptions => False);
4358 -- Neither Source_Files nor Source_List_File has been
4359 -- specified. Find all the files that satisfy
4360 -- the naming scheme in all the source directories.
4361 -- All the naming exceptions that effectively exist are
4362 -- also part of the source of this language.
4364 Find_Sources (Project, Data, Lang);
4372 -- Finally, get the mains, if any
4374 Get_Mains (Project, Data);
4376 Projects.Table (Project) := Data;
4378 end Other_Languages_Check;
4384 function Path_Name_Of
4385 (File_Name : Name_Id;
4386 Directory : Name_Id) return String
4388 Result : String_Access;
4389 The_Directory : constant String := Get_Name_String (Directory);
4392 Get_Name_String (File_Name);
4393 Result := Locate_Regular_File
4394 (File_Name => Name_Buffer (1 .. Name_Len),
4395 Path => The_Directory);
4397 if Result = null then
4400 Canonical_Case_File_Name (Result.all);
4405 -------------------------------
4406 -- Prepare_Ada_Naming_Exceptions --
4407 -------------------------------
4409 procedure Prepare_Ada_Naming_Exceptions
4410 (List : Array_Element_Id;
4411 Kind : Spec_Or_Body)
4413 Current : Array_Element_Id := List;
4414 Element : Array_Element;
4419 -- Traverse the list
4421 while Current /= No_Array_Element loop
4422 Element := Array_Elements.Table (Current);
4424 if Element.Index /= No_Name then
4427 Unit => Element.Index,
4428 Next => No_Ada_Naming_Exception);
4429 Reverse_Ada_Naming_Exceptions.Set
4430 (Unit, (Element.Value.Value, Element.Value.Index));
4431 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4432 Ada_Naming_Exception_Table.Increment_Last;
4433 Ada_Naming_Exception_Table.Table
4434 (Ada_Naming_Exception_Table.Last) := Unit;
4435 Ada_Naming_Exceptions.Set
4436 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4439 Current := Element.Next;
4441 end Prepare_Ada_Naming_Exceptions;
4443 ---------------------
4444 -- Project_Extends --
4445 ---------------------
4447 function Project_Extends
4448 (Extending : Project_Id;
4449 Extended : Project_Id) return Boolean
4451 Current : Project_Id := Extending;
4454 if Current = No_Project then
4457 elsif Current = Extended then
4461 Current := Projects.Table (Current).Extends;
4463 end Project_Extends;
4465 -----------------------
4466 -- Record_Ada_Source --
4467 -----------------------
4469 procedure Record_Ada_Source
4470 (File_Name : Name_Id;
4471 Path_Name : Name_Id;
4472 Project : Project_Id;
4473 Data : in out Project_Data;
4474 Location : Source_Ptr;
4475 Current_Source : in out String_List_Id;
4476 Source_Recorded : in out Boolean;
4477 Follow_Links : Boolean)
4479 Canonical_File_Name : Name_Id;
4480 Canonical_Path_Name : Name_Id;
4481 Exception_Id : Ada_Naming_Exception_Id;
4482 Unit_Name : Name_Id;
4483 Unit_Kind : Spec_Or_Body;
4484 Unit_Index : Int := 0;
4486 Name_Index : Name_And_Index;
4487 Needs_Pragma : Boolean;
4489 The_Location : Source_Ptr := Location;
4490 Previous_Source : constant String_List_Id := Current_Source;
4491 Except_Name : Name_And_Index := No_Name_And_Index;
4493 Unit_Prj : Unit_Project;
4495 File_Name_Recorded : Boolean := False;
4498 Get_Name_String (File_Name);
4499 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4500 Canonical_File_Name := Name_Find;
4503 Canonical_Path : constant String :=
4505 (Get_Name_String (Path_Name),
4506 Resolve_Links => Follow_Links,
4507 Case_Sensitive => False);
4510 Add_Str_To_Name_Buffer (Canonical_Path);
4511 Canonical_Path_Name := Name_Find;
4514 -- Find out the unit name, the unit kind and if it needs
4515 -- a specific SFN pragma.
4518 (Canonical_File_Name => Canonical_File_Name,
4519 Naming => Data.Naming,
4520 Exception_Id => Exception_Id,
4521 Unit_Name => Unit_Name,
4522 Unit_Kind => Unit_Kind,
4523 Needs_Pragma => Needs_Pragma);
4525 if Exception_Id = No_Ada_Naming_Exception and then
4528 if Current_Verbosity = High then
4530 Write_Str (Get_Name_String (Canonical_File_Name));
4531 Write_Line (""" is not a valid source file name (ignored).");
4536 -- Check to see if the source has been hidden by an exception,
4537 -- but only if it is not an exception.
4539 if not Needs_Pragma then
4541 Reverse_Ada_Naming_Exceptions.Get
4542 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4544 if Except_Name /= No_Name_And_Index then
4545 if Current_Verbosity = High then
4547 Write_Str (Get_Name_String (Canonical_File_Name));
4548 Write_Str (""" contains a unit that is found in """);
4549 Write_Str (Get_Name_String (Except_Name.Name));
4550 Write_Line (""" (ignored).");
4553 -- The file is not included in the source of the project,
4554 -- because it is hidden by the exception.
4555 -- So, there is nothing else to do.
4562 if Exception_Id /= No_Ada_Naming_Exception then
4563 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4564 Exception_Id := Info.Next;
4565 Info.Next := No_Ada_Naming_Exception;
4566 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4568 Unit_Name := Info.Unit;
4569 Unit_Index := Name_Index.Index;
4570 Unit_Kind := Info.Kind;
4572 -- Put the file name in the list of sources of the project
4574 if not File_Name_Recorded then
4575 String_Elements.Increment_Last;
4576 String_Elements.Table (String_Elements.Last) :=
4577 (Value => Canonical_File_Name,
4578 Display_Value => File_Name,
4579 Location => No_Location,
4582 Index => Unit_Index);
4585 if Current_Source = Nil_String then
4586 Data.Sources := String_Elements.Last;
4589 String_Elements.Table (Current_Source).Next :=
4590 String_Elements.Last;
4593 Current_Source := String_Elements.Last;
4595 -- Put the unit in unit list
4598 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4599 The_Unit_Data : Unit_Data;
4602 if Current_Verbosity = High then
4603 Write_Str ("Putting ");
4604 Write_Str (Get_Name_String (Unit_Name));
4605 Write_Line (" in the unit list.");
4608 -- The unit is already in the list, but may be it is
4609 -- only the other unit kind (spec or body), or what is
4610 -- in the unit list is a unit of a project we are extending.
4612 if The_Unit /= Prj.Com.No_Unit then
4613 The_Unit_Data := Units.Table (The_Unit);
4615 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4616 or else Project_Extends
4618 The_Unit_Data.File_Names (Unit_Kind).Project)
4620 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4621 Remove_Forbidden_File_Name
4622 (The_Unit_Data.File_Names (Unit_Kind).Name);
4625 -- Record the file name in the hash table Files_Htable
4627 Unit_Prj := (Unit => The_Unit, Project => Project);
4628 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4630 The_Unit_Data.File_Names (Unit_Kind) :=
4631 (Name => Canonical_File_Name,
4632 Index => Unit_Index,
4633 Display_Name => File_Name,
4634 Path => Canonical_Path_Name,
4635 Display_Path => Path_Name,
4637 Needs_Pragma => Needs_Pragma);
4638 Units.Table (The_Unit) := The_Unit_Data;
4639 Source_Recorded := True;
4641 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4642 and then (Data.Known_Order_Of_Source_Dirs or else
4643 The_Unit_Data.File_Names (Unit_Kind).Path =
4644 Canonical_Path_Name)
4646 if Previous_Source = Nil_String then
4647 Data.Sources := Nil_String;
4649 String_Elements.Table (Previous_Source).Next :=
4651 String_Elements.Decrement_Last;
4654 Current_Source := Previous_Source;
4657 -- It is an error to have two units with the same name
4658 -- and the same kind (spec or body).
4660 if The_Location = No_Location then
4661 The_Location := Projects.Table (Project).Location;
4664 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4665 Error_Msg (Project, "duplicate source {", The_Location);
4667 Err_Vars.Error_Msg_Name_1 :=
4669 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4670 Err_Vars.Error_Msg_Name_2 :=
4671 The_Unit_Data.File_Names (Unit_Kind).Path;
4673 (Project, "\ project file {, {", The_Location);
4675 Err_Vars.Error_Msg_Name_1 :=
4676 Projects.Table (Project).Name;
4677 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4679 (Project, "\ project file {, {", The_Location);
4683 -- It is a new unit, create a new record
4686 -- First, check if there is no other unit with this file
4687 -- name in another project. If it is, report an error.
4688 -- Of course, we do that only for the first unit in the
4691 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4693 if not File_Name_Recorded and then
4694 Unit_Prj /= No_Unit_Project
4696 Error_Msg_Name_1 := File_Name;
4698 Projects.Table (Unit_Prj.Project).Name;
4701 "{ is already a source of project {",
4705 Units.Increment_Last;
4706 The_Unit := Units.Last;
4707 Units_Htable.Set (Unit_Name, The_Unit);
4708 Unit_Prj := (Unit => The_Unit, Project => Project);
4709 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4710 The_Unit_Data.Name := Unit_Name;
4711 The_Unit_Data.File_Names (Unit_Kind) :=
4712 (Name => Canonical_File_Name,
4713 Index => Unit_Index,
4714 Display_Name => File_Name,
4715 Path => Canonical_Path_Name,
4716 Display_Path => Path_Name,
4718 Needs_Pragma => Needs_Pragma);
4719 Units.Table (The_Unit) := The_Unit_Data;
4720 Source_Recorded := True;
4725 exit when Exception_Id = No_Ada_Naming_Exception;
4726 File_Name_Recorded := True;
4729 end Record_Ada_Source;
4731 --------------------------
4732 -- Record_Other_Sources --
4733 --------------------------
4735 procedure Record_Other_Sources
4736 (Project : Project_Id;
4737 Data : in out Project_Data;
4738 Language : Programming_Language;
4739 Naming_Exceptions : Boolean)
4741 Source_Dir : String_List_Id := Data.Source_Dirs;
4742 Element : String_Element;
4746 Canonical_Name : Name_Id;
4747 Name_Str : String (1 .. 1_024);
4748 Last : Natural := 0;
4751 First_Error : Boolean := True;
4753 Suffix : constant String :=
4754 Get_Name_String (Data.Impl_Suffixes (Language));
4757 while Source_Dir /= Nil_String loop
4758 Element := String_Elements.Table (Source_Dir);
4761 Dir_Path : constant String := Get_Name_String (Element.Value);
4763 if Current_Verbosity = High then
4764 Write_Str ("checking directory """);
4765 Write_Str (Dir_Path);
4766 Write_Str (""" for ");
4768 if Naming_Exceptions then
4769 Write_Str ("naming exceptions");
4772 Write_Str ("sources");
4775 Write_Str (" of Language ");
4776 Write_Line (Lang_Display_Names (Language).all);
4779 Open (Dir, Dir_Path);
4782 Read (Dir, Name_Str, Last);
4786 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4789 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4790 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4791 Canonical_Name := Name_Find;
4792 NL := Source_Names.Get (Canonical_Name);
4794 if NL /= No_Name_Location then
4796 if not Data.Known_Order_Of_Source_Dirs then
4797 Error_Msg_Name_1 := Canonical_Name;
4800 "{ is found in several source directories",
4806 Source_Names.Set (Canonical_Name, NL);
4807 Name_Len := Dir_Path'Length;
4808 Name_Buffer (1 .. Name_Len) := Dir_Path;
4809 Add_Char_To_Name_Buffer (Directory_Separator);
4810 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4814 (File_Name => Canonical_Name,
4818 Location => NL.Location,
4819 Language => Language,
4821 Naming_Exception => Naming_Exceptions);
4830 Source_Dir := Element.Next;
4833 if not Naming_Exceptions then
4835 NL := Source_Names.Get_First;
4837 -- It is an error if a source file name in a source list or
4838 -- in a source list file is not found.
4840 while NL /= No_Name_Location loop
4841 if not NL.Found then
4842 Err_Vars.Error_Msg_Name_1 := NL.Name;
4847 "source file { cannot be found",
4849 First_Error := False;
4854 "\source file { cannot be found",
4859 NL := Source_Names.Get_Next;
4862 -- Any naming exception of this language that is not in a list
4863 -- of sources must be removed.
4866 Source_Id : Other_Source_Id := Data.First_Other_Source;
4867 Prev_Id : Other_Source_Id := No_Other_Source;
4868 Source : Other_Source;
4870 while Source_Id /= No_Other_Source loop
4871 Source := Other_Sources.Table (Source_Id);
4873 if Source.Language = Language
4874 and then Source.Naming_Exception
4876 if Current_Verbosity = High then
4877 Write_Str ("Naming exception """);
4878 Write_Str (Get_Name_String (Source.File_Name));
4879 Write_Str (""" is not in the list of sources,");
4880 Write_Line (" so it is removed.");
4883 if Prev_Id = No_Other_Source then
4884 Data.First_Other_Source := Source.Next;
4887 Other_Sources.Table (Prev_Id).Next := Source.Next;
4890 Source_Id := Source.Next;
4892 if Source_Id = No_Other_Source then
4893 Data.Last_Other_Source := Prev_Id;
4897 Prev_Id := Source_Id;
4898 Source_Id := Source.Next;
4903 end Record_Other_Sources;
4905 ----------------------
4906 -- Show_Source_Dirs --
4907 ----------------------
4909 procedure Show_Source_Dirs (Project : Project_Id) is
4910 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4911 Element : String_Element;
4914 Write_Line ("Source_Dirs:");
4916 while Current /= Nil_String loop
4917 Element := String_Elements.Table (Current);
4919 Write_Line (Get_Name_String (Element.Value));
4920 Current := Element.Next;
4923 Write_Line ("end Source_Dirs.");
4924 end Show_Source_Dirs;
4931 (Language : Programming_Language;
4932 Naming : Naming_Data) return Name_Id
4934 Suffix : constant Variable_Value :=
4936 (Index => Lang_Name_Ids (Language),
4938 In_Array => Naming.Body_Suffix);
4940 -- If no suffix for this language is found in package Naming, use the
4943 if Suffix = Nil_Variable_Value then
4945 Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4947 -- Otherwise use the one specified
4950 Get_Name_String (Suffix.Value);
4953 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));