1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2004 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Err_Vars
; use Err_Vars
;
31 with Namet
; use Namet
;
32 with Osint
; use Osint
;
33 with Output
; use Output
;
34 with MLib
.Tgt
; use MLib
.Tgt
;
35 with Prj
.Com
; use Prj
.Com
;
36 with Prj
.Env
; use Prj
.Env
;
38 with Prj
.Util
; use Prj
.Util
;
40 with Snames
; use Snames
;
41 with Table
; use Table
;
42 with Types
; use Types
;
44 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
45 with Ada
.Strings
; use Ada
.Strings
;
46 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
47 with Ada
.Strings
.Maps
.Constants
; use Ada
.Strings
.Maps
.Constants
;
49 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
50 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
51 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
54 package body Prj
.Nmsc
is
56 Error_Report
: Put_Line_Access
:= null;
57 -- Set to point to error reporting procedure
59 ALI_Suffix
: constant String := ".ali";
60 -- File suffix for ali files
62 Object_Suffix
: constant String := Get_Object_Suffix
.all;
63 -- File suffix for object files
65 type Name_Location
is record
67 Location
: Source_Ptr
;
68 Found
: Boolean := False;
70 -- Information about file names found in string list attribute
71 -- Source_Files or in a source list file, stored in hash table
72 -- Source_Names, used by procedure
73 -- Ada_Check.Get_Path_Names_And_Record_Sources.
75 No_Name_Location
: constant Name_Location
:=
76 (Name
=> No_Name
, Location
=> No_Location
, Found
=> False);
78 package Source_Names
is new GNAT
.HTable
.Simple_HTable
79 (Header_Num
=> Header_Num
,
80 Element
=> Name_Location
,
81 No_Element
=> No_Name_Location
,
85 -- Hash table to store file names found in string list attribute
86 -- Source_Files or in a source list file, stored in hash table
87 -- Source_Names, used by procedure
88 -- Ada_Check.Get_Path_Names_And_Record_Sources.
90 package Recursive_Dirs
is new GNAT
.HTable
.Simple_HTable
91 (Header_Num
=> Header_Num
,
97 -- Hash table to store recursive source directories, to avoid looking
98 -- several times, and to avoid cycles that may be introduced by symbolic
101 type Ada_Naming_Exception_Id
is new Nat
;
102 No_Ada_Naming_Exception
: constant Ada_Naming_Exception_Id
:= 0;
104 type Unit_Info
is record
107 Next
: Ada_Naming_Exception_Id
:= No_Ada_Naming_Exception
;
109 -- No_Unit : constant Unit_Info :=
110 -- (Specification, No_Name, No_Ada_Naming_Exception);
112 package Ada_Naming_Exception_Table
is new Table
.Table
113 (Table_Component_Type
=> Unit_Info
,
114 Table_Index_Type
=> Ada_Naming_Exception_Id
,
115 Table_Low_Bound
=> 1,
117 Table_Increment
=> 100,
118 Table_Name
=> "Prj.Nmsc.Ada_Naming_Exception_Table");
120 package Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
121 (Header_Num
=> Header_Num
,
122 Element
=> Ada_Naming_Exception_Id
,
123 No_Element
=> No_Ada_Naming_Exception
,
127 -- A hash table to store naming exceptions for Ada. For each file name
128 -- there is one or several unit in table Ada_Naming_Exception_Table.
130 function Hash
(Unit
: Unit_Info
) return Header_Num
;
132 type Name_And_Index
is record
133 Name
: Name_Id
:= No_Name
;
136 No_Name_And_Index
: constant Name_And_Index
:=
137 (Name
=> No_Name
, Index
=> 0);
139 package Reverse_Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
140 (Header_Num
=> Header_Num
,
141 Element
=> Name_And_Index
,
142 No_Element
=> No_Name_And_Index
,
146 -- A table to check if a unit with an exceptional name will hide
147 -- a source with a file name following the naming convention.
149 function ALI_File_Name
(Source
: String) return String;
150 -- Return the ALI file name corresponding to a source.
152 procedure Check_Ada_Name
155 -- Check that a name is a valid Ada unit name.
157 procedure Check_Ada_Naming_Scheme
158 (Data
: in out Project_Data
;
159 Project
: Project_Id
);
160 -- Check the naming scheme part of Data
162 procedure Check_Ada_Naming_Scheme_Validity
163 (Project
: Project_Id
;
164 Naming
: Naming_Data
);
165 -- Check that the package Naming is correct.
167 procedure Check_For_Source
168 (File_Name
: Name_Id
;
170 Project
: Project_Id
;
171 Data
: in out Project_Data
;
172 Location
: Source_Ptr
;
173 Language
: Other_Programming_Language
;
175 Naming_Exception
: Boolean);
176 -- Check if a file in a source directory is a source for a specific
177 -- language other than Ada.
179 function Check_Project
181 Root_Project
: Project_Id
;
182 Extending
: Boolean) return Boolean;
183 -- Returns True if P is Root_Project or, if Extending is True, a project
184 -- extended by Root_Project.
186 function Compute_Directory_Last
(Dir
: String) return Natural;
187 -- Return the index of the last significant character in Dir. This is used
188 -- to avoid duplicates '/' at the end of directory names
191 (Project
: Project_Id
;
193 Flag_Location
: Source_Ptr
);
194 -- Output an error message. If Error_Report is null, simply call
195 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
198 procedure Find_Sources
199 (Project
: Project_Id
;
200 Data
: in out Project_Data
;
201 For_Language
: Programming_Language
;
202 Follow_Links
: Boolean := False);
203 -- Find all the sources in all of the source directories of a project for
204 -- a specified language.
206 procedure Free_Ada_Naming_Exceptions
;
207 -- Free the internal hash tables used for checking naming exceptions
209 procedure Get_Mains
(Project
: Project_Id
; Data
: in out Project_Data
);
210 -- Get the mains of a project from attribute Main, if it exists, and put
211 -- them in the project data.
213 procedure Get_Sources_From_File
215 Location
: Source_Ptr
;
216 Project
: Project_Id
);
217 -- Get the list of sources from a text file and put them in hash table
221 (Canonical_File_Name
: Name_Id
;
222 Naming
: Naming_Data
;
223 Exception_Id
: out Ada_Naming_Exception_Id
;
224 Unit_Name
: out Name_Id
;
225 Unit_Kind
: out Spec_Or_Body
;
226 Needs_Pragma
: out Boolean);
227 -- Find out, from a file name, the unit name, the unit kind and if a
228 -- specific SFN pragma is needed. If the file name corresponds to no
229 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
230 -- or an exception to the naming scheme, then Exception_Id is set to
231 -- the unit or units that the source contains.
233 function Is_Illegal_Suffix
235 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean;
236 -- Returns True if the string Suffix cannot be used as
237 -- a spec suffix, a body suffix or a separate suffix.
239 procedure Locate_Directory
243 Display
: out Name_Id
);
244 -- Locate a directory (returns No_Name for Dir and Display if directory
245 -- does not exist). Name is the directory name. Parent is the root
246 -- directory, if Name is a relative path name. Dir is the canonical case
247 -- path name of the directory, Display is the directory path name for
250 function Path_Name_Of
251 (File_Name
: Name_Id
;
252 Directory
: Name_Id
) return String;
253 -- Returns the path name of a (non project) file.
254 -- Returns an empty string if file cannot be found.
256 procedure Prepare_Ada_Naming_Exceptions
257 (List
: Array_Element_Id
;
258 Kind
: Spec_Or_Body
);
259 -- Prepare the internal hash tables used for checking naming exceptions
260 -- for Ada. Insert all elements of List in the tables.
262 function Project_Extends
263 (Extending
: Project_Id
;
264 Extended
: Project_Id
) return Boolean;
265 -- Returns True if Extending is extending directly or indirectly Extended.
267 procedure Record_Ada_Source
268 (File_Name
: Name_Id
;
270 Project
: Project_Id
;
271 Data
: in out Project_Data
;
272 Location
: Source_Ptr
;
273 Current_Source
: in out String_List_Id
;
274 Source_Recorded
: in out Boolean;
275 Follow_Links
: Boolean);
276 -- Put a unit in the list of units of a project, if the file name
277 -- corresponds to a valid unit name.
279 procedure Record_Other_Sources
280 (Project
: Project_Id
;
281 Data
: in out Project_Data
;
282 Language
: Programming_Language
;
283 Naming_Exceptions
: Boolean);
284 -- Record the sources of a language in a project.
285 -- When Naming_Exceptions is True, mark the found sources as such, to
286 -- later remove those that are not named in a list of sources.
288 procedure Show_Source_Dirs
(Project
: Project_Id
);
289 -- List all the source directories of a project.
292 (Language
: Programming_Language
;
293 Naming
: Naming_Data
) return Name_Id
;
294 -- Get the suffix for the source of a language from a package naming.
295 -- If not specified, return the default for the language.
302 (Project
: Project_Id
;
303 Report_Error
: Put_Line_Access
;
304 Follow_Links
: Boolean)
307 Languages
: Variable_Value
:= Nil_Variable_Value
;
309 Extending
: Boolean := False;
311 procedure Get_Path_Names_And_Record_Sources
;
312 -- Find the path names of the source files in the Source_Names table
313 -- in the source directories and record those that are Ada sources.
315 procedure Get_Sources_From_File
317 Location
: Source_Ptr
);
318 -- Get the sources of a project from a text file
320 procedure Warn_If_Not_Sources
321 (Conventions
: Array_Element_Id
;
323 -- Check that individual naming conventions apply to immediate
324 -- sources of the project; if not, issue a warning.
326 ---------------------------------------
327 -- Get_Path_Names_And_Record_Sources --
328 ---------------------------------------
330 procedure Get_Path_Names_And_Record_Sources
is
331 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
332 Element
: String_Element
;
337 Canonical_Name
: Name_Id
;
338 Name_Str
: String (1 .. 1_024
);
342 Current_Source
: String_List_Id
:= Nil_String
;
344 First_Error
: Boolean := True;
346 Source_Recorded
: Boolean := False;
349 -- We look in all source directories for the file names in the
350 -- hash table Source_Names
352 while Source_Dir
/= Nil_String
loop
353 Source_Recorded
:= False;
354 Element
:= String_Elements
.Table
(Source_Dir
);
357 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
359 if Current_Verbosity
= High
then
360 Write_Str
("checking directory """);
361 Write_Str
(Dir_Path
);
365 Open
(Dir
, Dir_Path
);
368 Read
(Dir
, Name_Str
, Last
);
371 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
373 Canonical_Case_File_Name
(Name_Str
(1 .. Last
));
375 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
376 Canonical_Name
:= Name_Find
;
377 NL
:= Source_Names
.Get
(Canonical_Name
);
379 if NL
/= No_Name_Location
and then not NL
.Found
then
381 Source_Names
.Set
(Canonical_Name
, NL
);
382 Name_Len
:= Dir_Path
'Length;
383 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
385 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
386 Add_Char_To_Name_Buffer
(Directory_Separator
);
389 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
392 if Current_Verbosity
= High
then
393 Write_Str
(" found ");
394 Write_Line
(Get_Name_String
(Name
));
397 -- Register the source if it is an Ada compilation unit.
404 Location
=> NL
.Location
,
405 Current_Source
=> Current_Source
,
406 Source_Recorded
=> Source_Recorded
,
407 Follow_Links
=> Follow_Links
);
414 if Source_Recorded
then
415 String_Elements
.Table
(Source_Dir
).Flag
:= True;
418 Source_Dir
:= Element
.Next
;
421 -- It is an error if a source file name in a source list or
422 -- in a source list file is not found.
424 NL
:= Source_Names
.Get_First
;
426 while NL
/= No_Name_Location
loop
428 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
433 "source file { cannot be found",
435 First_Error
:= False;
440 "\source file { cannot be found",
445 NL
:= Source_Names
.Get_Next
;
447 end Get_Path_Names_And_Record_Sources
;
449 ---------------------------
450 -- Get_Sources_From_File --
451 ---------------------------
453 procedure Get_Sources_From_File
455 Location
: Source_Ptr
)
458 -- Get the list of sources from the file and put them in hash table
461 Get_Sources_From_File
(Path
, Location
, Project
);
463 -- Look in the source directories to find those sources
465 Get_Path_Names_And_Record_Sources
;
467 -- We should have found at least one source.
468 -- If not, report an error.
470 if Data
.Sources
= Nil_String
then
472 "there are no Ada sources in this project",
475 end Get_Sources_From_File
;
477 -------------------------
478 -- Warn_If_Not_Sources --
479 -------------------------
481 procedure Warn_If_Not_Sources
482 (Conventions
: Array_Element_Id
;
485 Conv
: Array_Element_Id
:= Conventions
;
487 The_Unit_Id
: Unit_Id
;
488 The_Unit_Data
: Unit_Data
;
489 Location
: Source_Ptr
;
492 while Conv
/= No_Array_Element
loop
493 Unit
:= Array_Elements
.Table
(Conv
).Index
;
494 Error_Msg_Name_1
:= Unit
;
495 Get_Name_String
(Unit
);
496 To_Lower
(Name_Buffer
(1 .. Name_Len
));
498 The_Unit_Id
:= Units_Htable
.Get
(Unit
);
499 Location
:= Array_Elements
.Table
(Conv
).Value
.Location
;
501 if The_Unit_Id
= Prj
.Com
.No_Unit
then
508 The_Unit_Data
:= Units
.Table
(The_Unit_Id
);
512 (The_Unit_Data
.File_Names
(Specification
).Project
,
517 "?unit{ has no spec in this project",
523 (The_Unit_Data
.File_Names
(Com
.Body_Part
).Project
,
528 "?unit{ has no body in this project",
534 Conv
:= Array_Elements
.Table
(Conv
).Next
;
536 end Warn_If_Not_Sources
;
538 -- Start of processing for Ada_Check
541 Language_Independent_Check
(Project
, Report_Error
);
543 Error_Report
:= Report_Error
;
545 Data
:= Projects
.Table
(Project
);
546 Extending
:= Data
.Extends
/= No_Project
;
547 Languages
:= Prj
.Util
.Value_Of
(Name_Languages
, Data
.Decl
.Attributes
);
549 Data
.Naming
.Current_Language
:= Name_Ada
;
550 Data
.Ada_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
552 if not Languages
.Default
then
554 Current
: String_List_Id
:= Languages
.Values
;
555 Element
: String_Element
;
556 Ada_Found
: Boolean := False;
559 Look_For_Ada
: while Current
/= Nil_String
loop
560 Element
:= String_Elements
.Table
(Current
);
561 Get_Name_String
(Element
.Value
);
562 To_Lower
(Name_Buffer
(1 .. Name_Len
));
564 if Name_Buffer
(1 .. Name_Len
) = "ada" then
569 Current
:= Element
.Next
;
570 end loop Look_For_Ada
;
572 if not Ada_Found
then
574 -- Mark the project file as having no sources for Ada
576 Data
.Ada_Sources_Present
:= False;
581 Check_Ada_Naming_Scheme
(Data
, Project
);
583 Prepare_Ada_Naming_Exceptions
(Data
.Naming
.Bodies
, Body_Part
);
584 Prepare_Ada_Naming_Exceptions
(Data
.Naming
.Specs
, Specification
);
586 -- If we have source directories, then find the sources
588 if Data
.Ada_Sources_Present
then
589 if Data
.Source_Dirs
= Nil_String
then
590 Data
.Ada_Sources_Present
:= False;
594 Sources
: constant Variable_Value
:=
597 Data
.Decl
.Attributes
);
599 Source_List_File
: constant Variable_Value
:=
601 (Name_Source_List_File
,
602 Data
.Decl
.Attributes
);
604 Locally_Removed
: constant Variable_Value
:=
606 (Name_Locally_Removed_Files
,
607 Data
.Decl
.Attributes
);
611 (Sources
.Kind
= List
,
612 "Source_Files is not a list");
615 (Source_List_File
.Kind
= Single
,
616 "Source_List_File is not a single string");
618 if not Sources
.Default
then
619 if not Source_List_File
.Default
then
622 "?both variables source_files and " &
623 "source_list_file are present",
624 Source_List_File
.Location
);
627 -- Sources is a list of file names
630 Current
: String_List_Id
:= Sources
.Values
;
631 Element
: String_Element
;
632 Location
: Source_Ptr
;
638 Data
.Ada_Sources_Present
:= Current
/= Nil_String
;
640 while Current
/= Nil_String
loop
641 Element
:= String_Elements
.Table
(Current
);
642 Get_Name_String
(Element
.Value
);
643 Canonical_Case_File_Name
644 (Name_Buffer
(1 .. Name_Len
));
647 -- If the element has no location, then use the
648 -- location of Sources to report possible errors.
650 if Element
.Location
= No_Location
then
651 Location
:= Sources
.Location
;
654 Location
:= Element
.Location
;
661 Location
=> Location
,
664 Current
:= Element
.Next
;
667 Get_Path_Names_And_Record_Sources
;
670 -- No source_files specified
672 -- We check Source_List_File has been specified.
674 elsif not Source_List_File
.Default
then
676 -- Source_List_File is the name of the file
677 -- that contains the source file names
680 Source_File_Path_Name
: constant String :=
682 (Source_List_File
.Value
,
686 if Source_File_Path_Name
'Length = 0 then
687 Err_Vars
.Error_Msg_Name_1
:= Source_List_File
.Value
;
690 "file with sources { does not exist",
691 Source_List_File
.Location
);
694 Get_Sources_From_File
695 (Source_File_Path_Name
,
696 Source_List_File
.Location
);
701 -- Neither Source_Files nor Source_List_File has been
702 -- specified. Find all the files that satisfy the naming
703 -- scheme in all the source directories.
705 Find_Sources
(Project
, Data
, Lang_Ada
, Follow_Links
);
708 -- If there are sources that are locally removed, mark them as
709 -- such in the Units table.
711 if not Locally_Removed
.Default
then
713 -- Sources can be locally removed only in extending
716 if Data
.Extends
= No_Project
then
719 "Locally_Removed_Files can only be used " &
720 "in an extending project file",
721 Locally_Removed
.Location
);
725 Current
: String_List_Id
:=
726 Locally_Removed
.Values
;
727 Element
: String_Element
;
728 Location
: Source_Ptr
;
732 Extended
: Project_Id
;
735 while Current
/= Nil_String
loop
736 Element
:= String_Elements
.Table
(Current
);
737 Get_Name_String
(Element
.Value
);
738 Canonical_Case_File_Name
739 (Name_Buffer
(1 .. Name_Len
));
742 -- If the element has no location, then use the
743 -- location of Locally_Removed to report
746 if Element
.Location
= No_Location
then
747 Location
:= Locally_Removed
.Location
;
750 Location
:= Element
.Location
;
755 for Index
in 1 .. Units
.Last
loop
756 Unit
:= Units
.Table
(Index
);
759 Unit
.File_Names
(Specification
).Name
= Name
763 -- Check that this is from a project that
764 -- the current project extends, but not the
767 Extended
:= Unit
.File_Names
768 (Specification
).Project
;
770 if Extended
= Project
then
773 "cannot remove a source " &
774 "of the same project",
778 Project_Extends
(Project
, Extended
)
781 (Specification
).Path
:= Slash
;
783 (Specification
).Needs_Pragma
:= False;
784 Units
.Table
(Index
) := Unit
;
785 Add_Forbidden_File_Name
786 (Unit
.File_Names
(Specification
).Name
);
792 "cannot remove a source from " &
798 Unit
.File_Names
(Body_Part
).Name
= Name
802 -- Check that this is from a project that
803 -- the current project extends, but not the
806 Extended
:= Unit
.File_Names
809 if Extended
= Project
then
812 "cannot remove a source " &
813 "of the same project",
817 Project_Extends
(Project
, Extended
)
819 Unit
.File_Names
(Body_Part
).Path
:= Slash
;
820 Unit
.File_Names
(Body_Part
).Needs_Pragma
822 Units
.Table
(Index
) := Unit
;
823 Add_Forbidden_File_Name
824 (Unit
.File_Names
(Body_Part
).Name
);
832 Err_Vars
.Error_Msg_Name_1
:= Name
;
833 Error_Msg
(Project
, "unknown file {", Location
);
836 Current
:= Element
.Next
;
845 if Data
.Ada_Sources_Present
then
847 -- Check that all individual naming conventions apply to
848 -- sources of this project file.
850 Warn_If_Not_Sources
(Data
.Naming
.Bodies
, Specs
=> False);
851 Warn_If_Not_Sources
(Data
.Naming
.Specs
, Specs
=> True);
854 -- If it is a library project file, check if it is a standalone library
857 Standalone_Library
: declare
858 Lib_Interfaces
: constant Prj
.Variable_Value
:=
860 (Snames
.Name_Library_Interface
,
861 Data
.Decl
.Attributes
);
862 Lib_Auto_Init
: constant Prj
.Variable_Value
:=
864 (Snames
.Name_Library_Auto_Init
,
865 Data
.Decl
.Attributes
);
867 Lib_Src_Dir
: constant Prj
.Variable_Value
:=
869 (Snames
.Name_Library_Src_Dir
,
870 Data
.Decl
.Attributes
);
872 Lib_Symbol_File
: constant Prj
.Variable_Value
:=
874 (Snames
.Name_Library_Symbol_File
,
875 Data
.Decl
.Attributes
);
877 Lib_Symbol_Policy
: constant Prj
.Variable_Value
:=
879 (Snames
.Name_Library_Symbol_Policy
,
880 Data
.Decl
.Attributes
);
882 Lib_Ref_Symbol_File
: constant Prj
.Variable_Value
:=
884 (Snames
.Name_Library_Reference_Symbol_File
,
885 Data
.Decl
.Attributes
);
887 Auto_Init_Supported
: constant Boolean :=
889 Standalone_Library_Auto_Init_Is_Supported
;
891 OK
: Boolean := True;
894 pragma Assert
(Lib_Interfaces
.Kind
= List
);
896 -- It is a stand-alone library project file if attribute
897 -- Library_Interface is defined.
899 if not Lib_Interfaces
.Default
then
901 Interfaces
: String_List_Id
:= Lib_Interfaces
.Values
;
902 Interface_ALIs
: String_List_Id
:= Nil_String
;
904 The_Unit_Id
: Unit_Id
;
905 The_Unit_Data
: Unit_Data
;
907 procedure Add_ALI_For
(Source
: Name_Id
);
908 -- Add an ALI file name to the list of Interface ALIs
914 procedure Add_ALI_For
(Source
: Name_Id
) is
916 Get_Name_String
(Source
);
919 ALI
: constant String :=
920 ALI_File_Name
(Name_Buffer
(1 .. Name_Len
));
921 ALI_Name_Id
: Name_Id
;
923 Name_Len
:= ALI
'Length;
924 Name_Buffer
(1 .. Name_Len
) := ALI
;
925 ALI_Name_Id
:= Name_Find
;
927 String_Elements
.Increment_Last
;
928 String_Elements
.Table
(String_Elements
.Last
) :=
929 (Value
=> ALI_Name_Id
,
931 Display_Value
=> ALI_Name_Id
,
932 Location
=> String_Elements
.Table
933 (Interfaces
).Location
,
935 Next
=> Interface_ALIs
);
936 Interface_ALIs
:= String_Elements
.Last
;
941 Data
.Standalone_Library
:= True;
943 -- Library_Interface cannot be an empty list
945 if Interfaces
= Nil_String
then
948 "Library_Interface cannot be an empty list",
949 Lib_Interfaces
.Location
);
952 -- Process each unit name specified in the attribute
953 -- Library_Interface.
955 while Interfaces
/= Nil_String
loop
957 (String_Elements
.Table
(Interfaces
).Value
);
958 To_Lower
(Name_Buffer
(1 .. Name_Len
));
963 "an interface cannot be an empty string",
964 String_Elements
.Table
(Interfaces
).Location
);
968 Error_Msg_Name_1
:= Unit
;
969 The_Unit_Id
:= Units_Htable
.Get
(Unit
);
971 if The_Unit_Id
= Prj
.Com
.No_Unit
then
975 String_Elements
.Table
(Interfaces
).Location
);
978 -- Check that the unit is part of the project
980 The_Unit_Data
:= Units
.Table
(The_Unit_Id
);
982 if The_Unit_Data
.File_Names
983 (Com
.Body_Part
).Name
/= No_Name
984 and then The_Unit_Data
.File_Names
985 (Com
.Body_Part
).Path
/= Slash
988 (The_Unit_Data
.File_Names
(Body_Part
).Project
,
991 -- There is a body for this unit.
992 -- If there is no spec, we need to check
993 -- that it is not a subunit.
995 if The_Unit_Data
.File_Names
996 (Specification
).Name
= No_Name
999 Src_Ind
: Source_File_Index
;
1002 Src_Ind
:= Sinput
.P
.Load_Project_File
1004 (The_Unit_Data
.File_Names
1007 if Sinput
.P
.Source_File_Is_Subunit
1012 "{ is a subunit; " &
1013 "it cannot be an interface",
1014 String_Elements
.Table
1015 (Interfaces
).Location
);
1020 -- The unit is not a subunit, so we add
1021 -- to the Interface ALIs the ALI file
1022 -- corresponding to the body.
1025 (The_Unit_Data
.File_Names
(Body_Part
).Name
);
1030 "{ is not an unit of this project",
1031 String_Elements
.Table
1032 (Interfaces
).Location
);
1035 elsif The_Unit_Data
.File_Names
1036 (Com
.Specification
).Name
/= No_Name
1037 and then The_Unit_Data
.File_Names
1038 (Com
.Specification
).Path
/= Slash
1039 and then Check_Project
1040 (The_Unit_Data
.File_Names
1041 (Specification
).Project
,
1045 -- The unit is part of the project, it has
1046 -- a spec, but no body. We add to the Interface
1047 -- ALIs the ALI file corresponding to the spec.
1050 (The_Unit_Data
.File_Names
(Specification
).Name
);
1055 "{ is not an unit of this project",
1056 String_Elements
.Table
(Interfaces
).Location
);
1062 Interfaces
:= String_Elements
.Table
(Interfaces
).Next
;
1065 -- Put the list of Interface ALIs in the project data
1067 Data
.Lib_Interface_ALIs
:= Interface_ALIs
;
1069 -- Check value of attribute Library_Auto_Init and set
1070 -- Lib_Auto_Init accordingly.
1072 if Lib_Auto_Init
.Default
then
1074 -- If no attribute Library_Auto_Init is declared, then
1075 -- set auto init only if it is supported.
1077 Data
.Lib_Auto_Init
:= Auto_Init_Supported
;
1080 Get_Name_String
(Lib_Auto_Init
.Value
);
1081 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1083 if Name_Buffer
(1 .. Name_Len
) = "false" then
1084 Data
.Lib_Auto_Init
:= False;
1086 elsif Name_Buffer
(1 .. Name_Len
) = "true" then
1087 if Auto_Init_Supported
then
1088 Data
.Lib_Auto_Init
:= True;
1091 -- Library_Auto_Init cannot be "true" if auto init
1096 "library auto init not supported " &
1098 Lib_Auto_Init
.Location
);
1104 "invalid value for attribute Library_Auto_Init",
1105 Lib_Auto_Init
.Location
);
1110 -- If attribute Library_Src_Dir is defined and not the
1111 -- empty string, check if the directory exist and is not
1112 -- the object directory or one of the source directories.
1113 -- This is the directory where copies of the interface
1114 -- sources will be copied. Note that this directory may be
1115 -- the library directory.
1117 if Lib_Src_Dir
.Value
/= Empty_String
then
1119 Dir_Id
: constant Name_Id
:= Lib_Src_Dir
.Value
;
1123 (Dir_Id
, Data
.Display_Directory
,
1124 Data
.Library_Src_Dir
,
1125 Data
.Display_Library_Src_Dir
);
1127 -- If directory does not exist, report an error
1129 if Data
.Library_Src_Dir
= No_Name
then
1131 -- Get the absolute name of the library directory
1132 -- that does not exist, to report an error.
1135 Dir_Name
: constant String :=
1136 Get_Name_String
(Dir_Id
);
1139 if Is_Absolute_Path
(Dir_Name
) then
1140 Err_Vars
.Error_Msg_Name_1
:= Dir_Id
;
1143 Get_Name_String
(Data
.Directory
);
1145 if Name_Buffer
(Name_Len
) /=
1148 Name_Len
:= Name_Len
+ 1;
1149 Name_Buffer
(Name_Len
) :=
1150 Directory_Separator
;
1155 Name_Len
+ Dir_Name
'Length) :=
1157 Name_Len
:= Name_Len
+ Dir_Name
'Length;
1158 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
1165 "Directory { does not exist",
1166 Lib_Src_Dir
.Location
);
1169 -- Report an error if it is the same as the object
1172 elsif Data
.Library_Src_Dir
= Data
.Object_Directory
then
1175 "directory to copy interfaces cannot be " &
1176 "the object directory",
1177 Lib_Src_Dir
.Location
);
1178 Data
.Library_Src_Dir
:= No_Name
;
1180 -- Check if it is the same as one of the source
1185 Src_Dirs
: String_List_Id
:= Data
.Source_Dirs
;
1186 Src_Dir
: String_Element
;
1189 while Src_Dirs
/= Nil_String
loop
1190 Src_Dir
:= String_Elements
.Table
(Src_Dirs
);
1191 Src_Dirs
:= Src_Dir
.Next
;
1193 -- Report an error if it is one of the
1194 -- source directories.
1196 if Data
.Library_Src_Dir
= Src_Dir
.Value
then
1199 "directory to copy interfaces cannot " &
1200 "be one of the source directories",
1201 Lib_Src_Dir
.Location
);
1202 Data
.Library_Src_Dir
:= No_Name
;
1208 if Data
.Library_Src_Dir
/= No_Name
1209 and then Current_Verbosity
= High
1211 Write_Str
("Directory to copy interfaces =""");
1212 Write_Str
(Get_Name_String
(Data
.Library_Dir
));
1219 if not Lib_Symbol_Policy
.Default
then
1221 Value
: constant String :=
1223 (Get_Name_String
(Lib_Symbol_Policy
.Value
));
1226 if Value
= "autonomous" or else Value
= "default" then
1227 Data
.Symbol_Data
.Symbol_Policy
:= Autonomous
;
1229 elsif Value
= "compliant" then
1230 Data
.Symbol_Data
.Symbol_Policy
:= Compliant
;
1232 elsif Value
= "controlled" then
1233 Data
.Symbol_Data
.Symbol_Policy
:= Controlled
;
1235 elsif Value
= "restricted" then
1236 Data
.Symbol_Data
.Symbol_Policy
:= Restricted
;
1241 "illegal value for Library_Symbol_Policy",
1242 Lib_Symbol_Policy
.Location
);
1247 if Lib_Symbol_File
.Default
then
1248 if Data
.Symbol_Data
.Symbol_Policy
= Restricted
then
1251 "Library_Symbol_File needs to be defined when " &
1252 "symbol policy is Restricted",
1253 Lib_Symbol_Policy
.Location
);
1257 Data
.Symbol_Data
.Symbol_File
:= Lib_Symbol_File
.Value
;
1259 Get_Name_String
(Lib_Symbol_File
.Value
);
1261 if Name_Len
= 0 then
1264 "symbol file name cannot be an empty string",
1265 Lib_Symbol_File
.Location
);
1268 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
1271 for J
in 1 .. Name_Len
loop
1272 if Name_Buffer
(J
) = '/'
1273 or else Name_Buffer
(J
) = Directory_Separator
1282 Error_Msg_Name_1
:= Lib_Symbol_File
.Value
;
1285 "symbol file name { is illegal. " &
1286 "Name canot include directory info.",
1287 Lib_Symbol_File
.Location
);
1292 if Lib_Ref_Symbol_File
.Default
then
1293 if Data
.Symbol_Data
.Symbol_Policy
= Compliant
1294 or else Data
.Symbol_Data
.Symbol_Policy
= Controlled
1298 "a reference symbol file need to be defined",
1299 Lib_Symbol_Policy
.Location
);
1303 Data
.Symbol_Data
.Reference
:= Lib_Ref_Symbol_File
.Value
;
1305 Get_Name_String
(Lib_Ref_Symbol_File
.Value
);
1307 if Name_Len
= 0 then
1310 "reference symbol file name cannot be an empty string",
1311 Lib_Symbol_File
.Location
);
1314 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
1317 for J
in 1 .. Name_Len
loop
1318 if Name_Buffer
(J
) = '/'
1319 or else Name_Buffer
(J
) = Directory_Separator
1328 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
1331 "reference symbol file { name is illegal. " &
1332 "Name canot include directory info.",
1333 Lib_Ref_Symbol_File
.Location
);
1336 if not Is_Regular_File
1337 (Get_Name_String
(Data
.Object_Directory
) &
1338 Directory_Separator
&
1339 Get_Name_String
(Lib_Ref_Symbol_File
.Value
))
1341 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
1344 "library reference symbol file { does not exist",
1345 Lib_Ref_Symbol_File
.Location
);
1348 if Data
.Symbol_Data
.Symbol_File
/= No_Name
then
1352 (Data
.Symbol_Data
.Symbol_File
);
1354 Reference
: String :=
1356 (Data
.Symbol_Data
.Reference
);
1359 Canonical_Case_File_Name
(Symbol
);
1360 Canonical_Case_File_Name
(Reference
);
1362 if Symbol
= Reference
then
1365 "reference symbol file and symbol file " &
1366 "cannot be the same file",
1367 Lib_Ref_Symbol_File
.Location
);
1374 end Standalone_Library
;
1377 -- Put the list of Mains, if any, in the project data
1379 Get_Mains
(Project
, Data
);
1381 Projects
.Table
(Project
) := Data
;
1383 Free_Ada_Naming_Exceptions
;
1390 function ALI_File_Name
(Source
: String) return String is
1392 -- If the source name has an extension, then replace it with
1395 for Index
in reverse Source
'First + 1 .. Source
'Last loop
1396 if Source
(Index
) = '.' then
1397 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
1401 -- If there is no dot, or if it is the first character, just add the
1404 return Source
& ALI_Suffix
;
1407 --------------------
1408 -- Check_Ada_Name --
1409 --------------------
1411 procedure Check_Ada_Name
1415 The_Name
: String := Name
;
1416 Real_Name
: Name_Id
;
1417 Need_Letter
: Boolean := True;
1418 Last_Underscore
: Boolean := False;
1419 OK
: Boolean := The_Name
'Length > 0;
1422 To_Lower
(The_Name
);
1424 Name_Len
:= The_Name
'Length;
1425 Name_Buffer
(1 .. Name_Len
) := The_Name
;
1426 Real_Name
:= Name_Find
;
1428 -- Check first that the given name is not an Ada reserved word
1430 if Get_Name_Table_Byte
(Real_Name
) /= 0
1431 and then Real_Name
/= Name_Project
1432 and then Real_Name
/= Name_Extends
1433 and then Real_Name
/= Name_External
1437 if Current_Verbosity
= High
then
1438 Write_Str
(The_Name
);
1439 Write_Line
(" is an Ada reserved word.");
1445 for Index
in The_Name
'Range loop
1448 -- We need a letter (at the beginning, and following a dot),
1449 -- but we don't have one.
1451 if Is_Letter
(The_Name
(Index
)) then
1452 Need_Letter
:= False;
1457 if Current_Verbosity
= High
then
1458 Write_Int
(Types
.Int
(Index
));
1460 Write_Char
(The_Name
(Index
));
1461 Write_Line
("' is not a letter.");
1467 elsif Last_Underscore
1468 and then (The_Name
(Index
) = '_' or else The_Name
(Index
) = '.')
1470 -- Two underscores are illegal, and a dot cannot follow
1475 if Current_Verbosity
= High
then
1476 Write_Int
(Types
.Int
(Index
));
1478 Write_Char
(The_Name
(Index
));
1479 Write_Line
("' is illegal here.");
1484 elsif The_Name
(Index
) = '.' then
1486 -- We need a letter after a dot
1488 Need_Letter
:= True;
1490 elsif The_Name
(Index
) = '_' then
1491 Last_Underscore
:= True;
1494 -- We need an letter or a digit
1496 Last_Underscore
:= False;
1498 if not Is_Alphanumeric
(The_Name
(Index
)) then
1501 if Current_Verbosity
= High
then
1502 Write_Int
(Types
.Int
(Index
));
1504 Write_Char
(The_Name
(Index
));
1505 Write_Line
("' is not alphanumeric.");
1513 -- Cannot end with an underscore or a dot
1515 OK
:= OK
and then not Need_Letter
and then not Last_Underscore
;
1521 -- Signal a problem with No_Name
1527 ----------------------
1528 -- Check_For_Source --
1529 ----------------------
1531 procedure Check_For_Source
1532 (File_Name
: Name_Id
;
1533 Path_Name
: Name_Id
;
1534 Project
: Project_Id
;
1535 Data
: in out Project_Data
;
1536 Location
: Source_Ptr
;
1537 Language
: Other_Programming_Language
;
1539 Naming_Exception
: Boolean)
1541 Name
: String := Get_Name_String
(File_Name
);
1542 Real_Location
: Source_Ptr
:= Location
;
1545 Canonical_Case_File_Name
(Name
);
1547 -- A file is a source of a language if Naming_Exception is True (case
1548 -- of naming exceptions) or if its file name ends with the suffix.
1550 if Naming_Exception
or else
1551 (Name
'Length > Suffix
'Length and then
1552 Name
(Name
'Last - Suffix
'Length + 1 .. Name
'Last) = Suffix
)
1554 if Real_Location
= No_Location
then
1555 Real_Location
:= Data
.Location
;
1559 Path
: String := Get_Name_String
(Path_Name
);
1562 -- The path name id (in canonical case)
1565 -- The file name id (in canonical case)
1568 -- The object file name
1570 Obj_Path_Id
: Name_Id
;
1571 -- The object path name
1574 -- The dependency file name
1576 Dep_Path_Id
: Name_Id
;
1577 -- The dependency path name
1579 Dot_Pos
: Natural := 0;
1580 -- Position of the last dot in Name
1582 Source
: Other_Source
;
1583 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
1586 Canonical_Case_File_Name
(Path
);
1588 -- Get the file name id
1590 Name_Len
:= Name
'Length;
1591 Name_Buffer
(1 .. Name_Len
) := Name
;
1592 File_Id
:= Name_Find
;
1594 -- Get the path name id
1596 Name_Len
:= Path
'Length;
1597 Name_Buffer
(1 .. Name_Len
) := Path
;
1598 Path_Id
:= Name_Find
;
1600 -- Find the position of the last dot
1602 for J
in reverse Name
'Range loop
1603 if Name
(J
) = '.' then
1609 if Dot_Pos
<= Name
'First then
1610 Dot_Pos
:= Name
'Last + 1;
1613 -- Compute the object file name
1615 Get_Name_String
(File_Id
);
1616 Name_Len
:= Dot_Pos
- Name
'First;
1618 for J
in Object_Suffix
'Range loop
1619 Name_Len
:= Name_Len
+ 1;
1620 Name_Buffer
(Name_Len
) := Object_Suffix
(J
);
1623 Obj_Id
:= Name_Find
;
1625 -- Compute the object path name
1627 Get_Name_String
(Data
.Object_Directory
);
1629 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
1630 Name_Buffer
(Name_Len
) /= '/'
1632 Name_Len
:= Name_Len
+ 1;
1633 Name_Buffer
(Name_Len
) := Directory_Separator
;
1636 Add_Str_To_Name_Buffer
(Get_Name_String
(Obj_Id
));
1637 Obj_Path_Id
:= Name_Find
;
1639 -- Compute the dependency file name
1641 Get_Name_String
(File_Id
);
1642 Name_Len
:= Dot_Pos
- Name
'First + 1;
1643 Name_Buffer
(Name_Len
) := '.';
1644 Name_Len
:= Name_Len
+ 1;
1645 Name_Buffer
(Name_Len
) := 'd';
1646 Dep_Id
:= Name_Find
;
1648 -- Compute the dependency path name
1650 Get_Name_String
(Data
.Object_Directory
);
1652 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
1653 Name_Buffer
(Name_Len
) /= '/'
1655 Name_Len
:= Name_Len
+ 1;
1656 Name_Buffer
(Name_Len
) := Directory_Separator
;
1659 Add_Str_To_Name_Buffer
(Get_Name_String
(Dep_Id
));
1660 Dep_Path_Id
:= Name_Find
;
1662 -- Check if source is already in the list of source for this
1663 -- project: it may have already been specified as a naming
1664 -- exception for the same language or an other language, or they
1665 -- may be two identical file names in different source
1668 while Source_Id
/= No_Other_Source
loop
1669 Source
:= Other_Sources
.Table
(Source_Id
);
1670 Source_Id
:= Source
.Next
;
1672 if Source
.File_Name
= File_Id
then
1673 -- Two sources of different languages cannot have the same
1676 if Source
.Language
/= Language
then
1677 Error_Msg_Name_1
:= File_Name
;
1680 "{ cannot be a source of several languages",
1684 -- No problem if a file has already been specified as
1685 -- a naming exception of this language.
1687 elsif Source
.Path_Name
= Path_Id
then
1688 -- Reset the naming exception flag, if this is not a
1689 -- naming exception.
1691 if not Naming_Exception
then
1692 Other_Sources
.Table
(Source_Id
).Naming_Exception
:=
1698 -- There are several files with the same names, but the
1699 -- order of the source directories is known (no /**):
1700 -- only the first one encountered is kept, the other ones
1703 elsif Data
.Known_Order_Of_Source_Dirs
then
1706 -- But it is an error if the order of the source directories
1710 Error_Msg_Name_1
:= File_Name
;
1713 "{ is found in several source directories",
1718 -- Two sources with different file names cannot have the same
1719 -- object file name.
1721 elsif Source
.Object_Name
= Obj_Id
then
1722 Error_Msg_Name_1
:= File_Id
;
1723 Error_Msg_Name_2
:= Source
.File_Name
;
1724 Error_Msg_Name_3
:= Obj_Id
;
1727 "{ and { have the same object file {",
1733 if Current_Verbosity
= High
then
1734 Write_Str
(" found ");
1735 Write_Str
(Lang_Display_Names
(Language
).all);
1736 Write_Str
(" source """);
1737 Write_Str
(Get_Name_String
(File_Name
));
1739 Write_Str
(" object path = ");
1740 Write_Line
(Get_Name_String
(Obj_Path_Id
));
1743 -- Create the Other_Source record
1745 (Language
=> Language
,
1746 File_Name
=> File_Id
,
1747 Path_Name
=> Path_Id
,
1748 Source_TS
=> File_Stamp
(Path_Id
),
1749 Object_Name
=> Obj_Id
,
1750 Object_Path
=> Obj_Path_Id
,
1751 Object_TS
=> File_Stamp
(Obj_Path_Id
),
1753 Dep_Path
=> Dep_Path_Id
,
1754 Dep_TS
=> File_Stamp
(Dep_Path_Id
),
1755 Naming_Exception
=> Naming_Exception
,
1756 Next
=> No_Other_Source
);
1758 -- And add it to the Other_Sources table
1760 Other_Sources
.Increment_Last
;
1761 Other_Sources
.Table
(Other_Sources
.Last
) := Source
;
1763 -- There are sources of languages other than Ada in this project
1765 Data
.Other_Sources_Present
:= True;
1767 -- And there are sources of this language in this project
1769 Data
.Languages
(Language
) := True;
1771 -- Add this source to the list of sources of languages other than
1772 -- Ada of the project.
1774 if Data
.First_Other_Source
= No_Other_Source
then
1775 Data
.First_Other_Source
:= Other_Sources
.Last
;
1778 Other_Sources
.Table
(Data
.Last_Other_Source
).Next
:=
1782 Data
.Last_Other_Source
:= Other_Sources
.Last
;
1785 end Check_For_Source
;
1787 --------------------------------------
1788 -- Check_Ada_Naming_Scheme_Validity --
1789 --------------------------------------
1791 procedure Check_Ada_Naming_Scheme_Validity
1792 (Project
: Project_Id
;
1793 Naming
: Naming_Data
)
1796 -- Only check if we are not using the standard naming scheme
1798 if Naming
/= Standard_Naming_Data
then
1800 Dot_Replacement
: constant String :=
1802 (Naming
.Dot_Replacement
);
1804 Spec_Suffix
: constant String :=
1806 (Naming
.Current_Spec_Suffix
);
1808 Body_Suffix
: constant String :=
1810 (Naming
.Current_Body_Suffix
);
1812 Separate_Suffix
: constant String :=
1814 (Naming
.Separate_Suffix
);
1817 -- Dot_Replacement cannot
1819 -- - start or end with an alphanumeric
1820 -- - be a single '_'
1821 -- - start with an '_' followed by an alphanumeric
1822 -- - contain a '.' except if it is "."
1824 if Dot_Replacement
'Length = 0
1825 or else Is_Alphanumeric
1826 (Dot_Replacement
(Dot_Replacement
'First))
1827 or else Is_Alphanumeric
1828 (Dot_Replacement
(Dot_Replacement
'Last))
1829 or else (Dot_Replacement
(Dot_Replacement
'First) = '_'
1831 (Dot_Replacement
'Length = 1
1834 (Dot_Replacement
(Dot_Replacement
'First + 1))))
1835 or else (Dot_Replacement
'Length > 1
1837 Index
(Source
=> Dot_Replacement
,
1838 Pattern
=> ".") /= 0)
1842 '"' & Dot_Replacement
&
1843 """ is illegal for Dot_Replacement.",
1844 Naming
.Dot_Repl_Loc
);
1850 if Is_Illegal_Suffix
1851 (Spec_Suffix
, Dot_Replacement
= ".")
1853 Err_Vars
.Error_Msg_Name_1
:= Naming
.Current_Spec_Suffix
;
1856 "{ is illegal for Spec_Suffix",
1857 Naming
.Spec_Suffix_Loc
);
1860 if Is_Illegal_Suffix
1861 (Body_Suffix
, Dot_Replacement
= ".")
1863 Err_Vars
.Error_Msg_Name_1
:= Naming
.Current_Body_Suffix
;
1866 "{ is illegal for Body_Suffix",
1867 Naming
.Body_Suffix_Loc
);
1870 if Body_Suffix
/= Separate_Suffix
then
1871 if Is_Illegal_Suffix
1872 (Separate_Suffix
, Dot_Replacement
= ".")
1874 Err_Vars
.Error_Msg_Name_1
:= Naming
.Separate_Suffix
;
1877 "{ is illegal for Separate_Suffix",
1878 Naming
.Sep_Suffix_Loc
);
1882 -- Spec_Suffix cannot have the same termination as
1883 -- Body_Suffix or Separate_Suffix
1885 if Spec_Suffix
'Length <= Body_Suffix
'Length
1887 Body_Suffix
(Body_Suffix
'Last -
1888 Spec_Suffix
'Length + 1 ..
1889 Body_Suffix
'Last) = Spec_Suffix
1895 """) cannot end with" &
1896 " Spec_Suffix (""" &
1897 Spec_Suffix
& """).",
1898 Naming
.Body_Suffix_Loc
);
1901 if Body_Suffix
/= Separate_Suffix
1902 and then Spec_Suffix
'Length <= Separate_Suffix
'Length
1905 (Separate_Suffix
'Last - Spec_Suffix
'Length + 1
1907 Separate_Suffix
'Last) = Spec_Suffix
1911 "Separate_Suffix (""" &
1913 """) cannot end with" &
1914 " Spec_Suffix (""" &
1915 Spec_Suffix
& """).",
1916 Naming
.Sep_Suffix_Loc
);
1920 end Check_Ada_Naming_Scheme_Validity
;
1922 -----------------------------
1923 -- Check_Ada_Naming_Scheme --
1924 -----------------------------
1926 procedure Check_Ada_Naming_Scheme
1927 (Data
: in out Project_Data
;
1928 Project
: Project_Id
)
1930 Naming_Id
: constant Package_Id
:=
1931 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
);
1933 Naming
: Package_Element
;
1935 procedure Check_Unit_Names
(List
: Array_Element_Id
);
1936 -- Check that a list of unit names contains only valid names.
1938 ----------------------
1939 -- Check_Unit_Names --
1940 ----------------------
1942 procedure Check_Unit_Names
(List
: Array_Element_Id
) is
1943 Current
: Array_Element_Id
:= List
;
1944 Element
: Array_Element
;
1945 Unit_Name
: Name_Id
;
1948 -- Loop through elements of the string list
1950 while Current
/= No_Array_Element
loop
1951 Element
:= Array_Elements
.Table
(Current
);
1953 -- Put file name in canonical case
1955 Get_Name_String
(Element
.Value
.Value
);
1956 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1957 Element
.Value
.Value
:= Name_Find
;
1959 -- Check that it contains a valid unit name
1961 Get_Name_String
(Element
.Index
);
1962 Check_Ada_Name
(Name_Buffer
(1 .. Name_Len
), Unit_Name
);
1964 if Unit_Name
= No_Name
then
1965 Err_Vars
.Error_Msg_Name_1
:= Element
.Index
;
1968 "{ is not a valid unit name.",
1969 Element
.Value
.Location
);
1972 if Current_Verbosity
= High
then
1973 Write_Str
(" Unit (""");
1974 Write_Str
(Get_Name_String
(Unit_Name
));
1978 Element
.Index
:= Unit_Name
;
1979 Array_Elements
.Table
(Current
) := Element
;
1982 Current
:= Element
.Next
;
1984 end Check_Unit_Names
;
1986 -- Start of processing for Check_Ada_Naming_Scheme
1989 -- If there is a package Naming, we will put in Data.Naming what is in
1990 -- this package Naming.
1992 if Naming_Id
/= No_Package
then
1993 Naming
:= Packages
.Table
(Naming_Id
);
1995 if Current_Verbosity
= High
then
1996 Write_Line
("Checking ""Naming"" for Ada.");
2000 Bodies
: constant Array_Element_Id
:=
2001 Util
.Value_Of
(Name_Body
, Naming
.Decl
.Arrays
);
2003 Specs
: constant Array_Element_Id
:=
2004 Util
.Value_Of
(Name_Spec
, Naming
.Decl
.Arrays
);
2007 if Bodies
/= No_Array_Element
then
2009 -- We have elements in the array Body_Part
2011 if Current_Verbosity
= High
then
2012 Write_Line
("Found Bodies.");
2015 Data
.Naming
.Bodies
:= Bodies
;
2016 Check_Unit_Names
(Bodies
);
2019 if Current_Verbosity
= High
then
2020 Write_Line
("No Bodies.");
2024 if Specs
/= No_Array_Element
then
2026 -- We have elements in the array Specs
2028 if Current_Verbosity
= High
then
2029 Write_Line
("Found Specs.");
2032 Data
.Naming
.Specs
:= Specs
;
2033 Check_Unit_Names
(Specs
);
2036 if Current_Verbosity
= High
then
2037 Write_Line
("No Specs.");
2042 -- We are now checking if variables Dot_Replacement, Casing,
2043 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
2046 -- For each variable, if it does not exist, we do nothing,
2047 -- because we already have the default.
2049 -- Check Dot_Replacement
2052 Dot_Replacement
: constant Variable_Value
:=
2054 (Name_Dot_Replacement
,
2055 Naming
.Decl
.Attributes
);
2058 pragma Assert
(Dot_Replacement
.Kind
= Single
,
2059 "Dot_Replacement is not a single string");
2061 if not Dot_Replacement
.Default
then
2062 Get_Name_String
(Dot_Replacement
.Value
);
2064 if Name_Len
= 0 then
2067 "Dot_Replacement cannot be empty",
2068 Dot_Replacement
.Location
);
2071 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2072 Data
.Naming
.Dot_Replacement
:= Name_Find
;
2073 Data
.Naming
.Dot_Repl_Loc
:= Dot_Replacement
.Location
;
2078 if Current_Verbosity
= High
then
2079 Write_Str
(" Dot_Replacement = """);
2080 Write_Str
(Get_Name_String
(Data
.Naming
.Dot_Replacement
));
2088 Casing_String
: constant Variable_Value
:=
2090 (Name_Casing
, Naming
.Decl
.Attributes
);
2093 pragma Assert
(Casing_String
.Kind
= Single
,
2094 "Casing is not a single string");
2096 if not Casing_String
.Default
then
2098 Casing_Image
: constant String :=
2099 Get_Name_String
(Casing_String
.Value
);
2102 Casing_Value
: constant Casing_Type
:=
2103 Value
(Casing_Image
);
2105 -- Ignore Casing on platforms where file names are
2106 -- case-insensitive.
2108 if not File_Names_Case_Sensitive
then
2109 Data
.Naming
.Casing
:= All_Lower_Case
;
2112 Data
.Naming
.Casing
:= Casing_Value
;
2117 when Constraint_Error
=>
2118 if Casing_Image
'Length = 0 then
2121 "Casing cannot be an empty string",
2122 Casing_String
.Location
);
2125 Name_Len
:= Casing_Image
'Length;
2126 Name_Buffer
(1 .. Name_Len
) := Casing_Image
;
2127 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
2130 "{ is not a correct Casing",
2131 Casing_String
.Location
);
2137 if Current_Verbosity
= High
then
2138 Write_Str
(" Casing = ");
2139 Write_Str
(Image
(Data
.Naming
.Casing
));
2144 -- Check Spec_Suffix
2147 Ada_Spec_Suffix
: constant Variable_Value
:=
2151 In_Array
=> Data
.Naming
.Spec_Suffix
);
2154 if Ada_Spec_Suffix
.Kind
= Single
2155 and then Get_Name_String
(Ada_Spec_Suffix
.Value
) /= ""
2157 Get_Name_String
(Ada_Spec_Suffix
.Value
);
2158 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2159 Data
.Naming
.Current_Spec_Suffix
:= Name_Find
;
2160 Data
.Naming
.Spec_Suffix_Loc
:= Ada_Spec_Suffix
.Location
;
2163 Data
.Naming
.Current_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
2167 if Current_Verbosity
= High
then
2168 Write_Str
(" Spec_Suffix = """);
2169 Write_Str
(Get_Name_String
(Data
.Naming
.Current_Spec_Suffix
));
2174 -- Check Body_Suffix
2177 Ada_Body_Suffix
: constant Variable_Value
:=
2181 In_Array
=> Data
.Naming
.Body_Suffix
);
2184 if Ada_Body_Suffix
.Kind
= Single
2185 and then Get_Name_String
(Ada_Body_Suffix
.Value
) /= ""
2187 Get_Name_String
(Ada_Body_Suffix
.Value
);
2188 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2189 Data
.Naming
.Current_Body_Suffix
:= Name_Find
;
2190 Data
.Naming
.Body_Suffix_Loc
:= Ada_Body_Suffix
.Location
;
2193 Data
.Naming
.Current_Body_Suffix
:= Default_Ada_Body_Suffix
;
2197 if Current_Verbosity
= High
then
2198 Write_Str
(" Body_Suffix = """);
2199 Write_Str
(Get_Name_String
(Data
.Naming
.Current_Body_Suffix
));
2204 -- Check Separate_Suffix
2207 Ada_Sep_Suffix
: constant Variable_Value
:=
2209 (Variable_Name
=> Name_Separate_Suffix
,
2210 In_Variables
=> Naming
.Decl
.Attributes
);
2213 if Ada_Sep_Suffix
.Default
then
2214 Data
.Naming
.Separate_Suffix
:=
2215 Data
.Naming
.Current_Body_Suffix
;
2218 Get_Name_String
(Ada_Sep_Suffix
.Value
);
2220 if Name_Len
= 0 then
2223 "Separate_Suffix cannot be empty",
2224 Ada_Sep_Suffix
.Location
);
2227 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2228 Data
.Naming
.Separate_Suffix
:= Name_Find
;
2229 Data
.Naming
.Sep_Suffix_Loc
:= Ada_Sep_Suffix
.Location
;
2234 if Current_Verbosity
= High
then
2235 Write_Str
(" Separate_Suffix = """);
2236 Write_Str
(Get_Name_String
(Data
.Naming
.Separate_Suffix
));
2241 -- Check if Data.Naming is valid
2243 Check_Ada_Naming_Scheme_Validity
(Project
, Data
.Naming
);
2246 Data
.Naming
.Current_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
2247 Data
.Naming
.Current_Body_Suffix
:= Default_Ada_Body_Suffix
;
2248 Data
.Naming
.Separate_Suffix
:= Default_Ada_Body_Suffix
;
2250 end Check_Ada_Naming_Scheme
;
2256 function Check_Project
2258 Root_Project
: Project_Id
;
2259 Extending
: Boolean) return Boolean
2262 if P
= Root_Project
then
2265 elsif Extending
then
2267 Data
: Project_Data
:= Projects
.Table
(Root_Project
);
2270 while Data
.Extends
/= No_Project
loop
2271 if P
= Data
.Extends
then
2275 Data
:= Projects
.Table
(Data
.Extends
);
2283 ----------------------------
2284 -- Compute_Directory_Last --
2285 ----------------------------
2287 function Compute_Directory_Last
(Dir
: String) return Natural is
2290 and then (Dir
(Dir
'Last - 1) = Directory_Separator
2291 or else Dir
(Dir
'Last - 1) = '/')
2293 return Dir
'Last - 1;
2297 end Compute_Directory_Last
;
2304 (Project
: Project_Id
;
2306 Flag_Location
: Source_Ptr
)
2308 Error_Buffer
: String (1 .. 5_000
);
2309 Error_Last
: Natural := 0;
2310 Msg_Name
: Natural := 0;
2311 First
: Positive := Msg
'First;
2313 procedure Add
(C
: Character);
2314 -- Add a character to the buffer
2316 procedure Add
(S
: String);
2317 -- Add a string to the buffer
2319 procedure Add
(Id
: Name_Id
);
2320 -- Add a name to the buffer
2326 procedure Add
(C
: Character) is
2328 Error_Last
:= Error_Last
+ 1;
2329 Error_Buffer
(Error_Last
) := C
;
2332 procedure Add
(S
: String) is
2334 Error_Buffer
(Error_Last
+ 1 .. Error_Last
+ S
'Length) := S
;
2335 Error_Last
:= Error_Last
+ S
'Length;
2338 procedure Add
(Id
: Name_Id
) is
2340 Get_Name_String
(Id
);
2341 Add
(Name_Buffer
(1 .. Name_Len
));
2344 -- Start of processing for Error_Msg
2347 if Error_Report
= null then
2348 Prj
.Err
.Error_Msg
(Msg
, Flag_Location
);
2352 if Msg
(First
) = '\' then
2354 -- Continuation character, ignore.
2358 elsif Msg
(First
) = '?' then
2360 -- Warning character. It is always the first one in this package
2366 for Index
in First
.. Msg
'Last loop
2367 if Msg
(Index
) = '{' or else Msg
(Index
) = '%' then
2369 -- Include a name between double quotes.
2371 Msg_Name
:= Msg_Name
+ 1;
2375 when 1 => Add
(Err_Vars
.Error_Msg_Name_1
);
2376 when 2 => Add
(Err_Vars
.Error_Msg_Name_2
);
2377 when 3 => Add
(Err_Vars
.Error_Msg_Name_3
);
2379 when others => null;
2390 Error_Report
(Error_Buffer
(1 .. Error_Last
), Project
);
2397 procedure Find_Sources
2398 (Project
: Project_Id
;
2399 Data
: in out Project_Data
;
2400 For_Language
: Programming_Language
;
2401 Follow_Links
: Boolean := False)
2403 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
2404 Element
: String_Element
;
2406 Current_Source
: String_List_Id
:= Nil_String
;
2407 Source_Recorded
: Boolean := False;
2410 if Current_Verbosity
= High
then
2411 Write_Line
("Looking for sources:");
2414 -- For each subdirectory
2416 while Source_Dir
/= Nil_String
loop
2418 Source_Recorded
:= False;
2419 Element
:= String_Elements
.Table
(Source_Dir
);
2420 if Element
.Value
/= No_Name
then
2421 Get_Name_String
(Element
.Display_Value
);
2424 Source_Directory
: constant String :=
2425 Name_Buffer
(1 .. Name_Len
) & Directory_Separator
;
2426 Dir_Last
: constant Natural :=
2427 Compute_Directory_Last
(Source_Directory
);
2430 if Current_Verbosity
= High
then
2431 Write_Str
("Source_Dir = ");
2432 Write_Line
(Source_Directory
);
2435 -- We look to every entry in the source directory
2437 Open
(Dir
, Source_Directory
2438 (Source_Directory
'First .. Dir_Last
));
2441 Read
(Dir
, Name_Buffer
, Name_Len
);
2443 if Current_Verbosity
= High
then
2444 Write_Str
(" Checking ");
2445 Write_Line
(Name_Buffer
(1 .. Name_Len
));
2448 exit when Name_Len
= 0;
2451 File_Name
: constant Name_Id
:= Name_Find
;
2452 Path
: constant String :=
2454 (Name
=> Name_Buffer
(1 .. Name_Len
),
2455 Directory
=> Source_Directory
2456 (Source_Directory
'First .. Dir_Last
),
2457 Resolve_Links
=> Follow_Links
,
2458 Case_Sensitive
=> True);
2459 Path_Name
: Name_Id
;
2462 Name_Len
:= Path
'Length;
2463 Name_Buffer
(1 .. Name_Len
) := Path
;
2464 Path_Name
:= Name_Find
;
2466 if For_Language
= Lang_Ada
then
2467 -- We attempt to register it as a source.
2468 -- However, there is no error if the file
2469 -- does not contain a valid source.
2470 -- But there is an error if we have a
2471 -- duplicate unit name.
2474 (File_Name
=> File_Name
,
2475 Path_Name
=> Path_Name
,
2478 Location
=> No_Location
,
2479 Current_Source
=> Current_Source
,
2480 Source_Recorded
=> Source_Recorded
,
2481 Follow_Links
=> Follow_Links
);
2485 (File_Name
=> File_Name
,
2486 Path_Name
=> Path_Name
,
2489 Location
=> No_Location
,
2490 Language
=> For_Language
,
2493 (Data
.Impl_Suffixes
(For_Language
)),
2494 Naming_Exception
=> False);
2504 when Directory_Error
=>
2508 if Source_Recorded
then
2509 String_Elements
.Table
(Source_Dir
).Flag
:= True;
2512 Source_Dir
:= Element
.Next
;
2515 if Current_Verbosity
= High
then
2516 Write_Line
("end Looking for sources.");
2519 if For_Language
= Lang_Ada
then
2520 -- If we have looked for sources and found none, then
2521 -- it is an error, except if it is an extending project.
2522 -- If a non extending project is not supposed to contain
2523 -- any source, then we never call Find_Sources.
2525 if Current_Source
/= Nil_String
then
2526 Data
.Ada_Sources_Present
:= True;
2528 elsif Data
.Extends
= No_Project
then
2531 "there are no Ada sources in this project",
2537 --------------------------------
2538 -- Free_Ada_Naming_Exceptions --
2539 --------------------------------
2541 procedure Free_Ada_Naming_Exceptions
is
2543 Ada_Naming_Exception_Table
.Set_Last
(0);
2544 Ada_Naming_Exceptions
.Reset
;
2545 Reverse_Ada_Naming_Exceptions
.Reset
;
2546 end Free_Ada_Naming_Exceptions
;
2552 procedure Get_Mains
(Project
: Project_Id
; Data
: in out Project_Data
) is
2553 Mains
: constant Variable_Value
:=
2554 Prj
.Util
.Value_Of
(Name_Main
, Data
.Decl
.Attributes
);
2557 Data
.Mains
:= Mains
.Values
;
2559 -- If no Mains were specified, and if we are an extending
2560 -- project, inherit the Mains from the project we are extending.
2562 if Mains
.Default
then
2563 if Data
.Extends
/= No_Project
then
2564 Data
.Mains
:= Projects
.Table
(Data
.Extends
).Mains
;
2567 -- In a library project file, Main cannot be specified
2569 elsif Data
.Library
then
2572 "a library project file cannot have Main specified",
2577 ---------------------------
2578 -- Get_Sources_From_File --
2579 ---------------------------
2581 procedure Get_Sources_From_File
2583 Location
: Source_Ptr
;
2584 Project
: Project_Id
)
2586 File
: Prj
.Util
.Text_File
;
2587 Line
: String (1 .. 250);
2589 Source_Name
: Name_Id
;
2594 if Current_Verbosity
= High
then
2595 Write_Str
("Opening """);
2602 Prj
.Util
.Open
(File
, Path
);
2604 if not Prj
.Util
.Is_Valid
(File
) then
2605 Error_Msg
(Project
, "file does not exist", Location
);
2607 -- Read the lines one by one
2609 while not Prj
.Util
.End_Of_File
(File
) loop
2610 Prj
.Util
.Get_Line
(File
, Line
, Last
);
2612 -- A non empty, non comment line should contain a file name
2615 and then (Last
= 1 or else Line
(1 .. 2) /= "--")
2617 -- ??? we should check that there is no directory information
2620 Name_Buffer
(1 .. Name_Len
) := Line
(1 .. Last
);
2621 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2622 Source_Name
:= Name_Find
;
2626 (Name
=> Source_Name
,
2627 Location
=> Location
,
2632 Prj
.Util
.Close
(File
);
2635 end Get_Sources_From_File
;
2642 (Canonical_File_Name
: Name_Id
;
2643 Naming
: Naming_Data
;
2644 Exception_Id
: out Ada_Naming_Exception_Id
;
2645 Unit_Name
: out Name_Id
;
2646 Unit_Kind
: out Spec_Or_Body
;
2647 Needs_Pragma
: out Boolean)
2649 Info_Id
: Ada_Naming_Exception_Id
2650 := Ada_Naming_Exceptions
.Get
(Canonical_File_Name
);
2654 if Info_Id
= No_Ada_Naming_Exception
then
2655 if Hostparm
.OpenVMS
then
2656 VMS_Name
:= Canonical_File_Name
;
2657 Get_Name_String
(VMS_Name
);
2659 if Name_Buffer
(Name_Len
) = '.' then
2660 Name_Len
:= Name_Len
- 1;
2661 VMS_Name
:= Name_Find
;
2664 Info_Id
:= Ada_Naming_Exceptions
.Get
(VMS_Name
);
2669 if Info_Id
/= No_Ada_Naming_Exception
then
2670 Exception_Id
:= Info_Id
;
2671 Unit_Name
:= No_Name
;
2672 Unit_Kind
:= Specification
;
2673 Needs_Pragma
:= True;
2677 Needs_Pragma
:= False;
2678 Exception_Id
:= No_Ada_Naming_Exception
;
2680 Get_Name_String
(Canonical_File_Name
);
2683 File
: String := Name_Buffer
(1 .. Name_Len
);
2684 First
: constant Positive := File
'First;
2685 Last
: Natural := File
'Last;
2686 Standard_GNAT
: Boolean;
2690 Naming
.Current_Spec_Suffix
= Default_Ada_Spec_Suffix
2691 and then Naming
.Current_Body_Suffix
= Default_Ada_Body_Suffix
;
2693 -- Check if the end of the file name is Specification_Append
2695 Get_Name_String
(Naming
.Current_Spec_Suffix
);
2697 if File
'Length > Name_Len
2698 and then File
(Last
- Name_Len
+ 1 .. Last
) =
2699 Name_Buffer
(1 .. Name_Len
)
2703 Unit_Kind
:= Specification
;
2704 Last
:= Last
- Name_Len
;
2706 if Current_Verbosity
= High
then
2707 Write_Str
(" Specification: ");
2708 Write_Line
(File
(First
.. Last
));
2712 Get_Name_String
(Naming
.Current_Body_Suffix
);
2714 -- Check if the end of the file name is Body_Append
2716 if File
'Length > Name_Len
2717 and then File
(Last
- Name_Len
+ 1 .. Last
) =
2718 Name_Buffer
(1 .. Name_Len
)
2722 Unit_Kind
:= Body_Part
;
2723 Last
:= Last
- Name_Len
;
2725 if Current_Verbosity
= High
then
2726 Write_Str
(" Body: ");
2727 Write_Line
(File
(First
.. Last
));
2730 elsif Naming
.Separate_Suffix
/= Naming
.Current_Spec_Suffix
then
2731 Get_Name_String
(Naming
.Separate_Suffix
);
2733 -- Check if the end of the file name is Separate_Append
2735 if File
'Length > Name_Len
2736 and then File
(Last
- Name_Len
+ 1 .. Last
) =
2737 Name_Buffer
(1 .. Name_Len
)
2739 -- We have a separate (a body)
2741 Unit_Kind
:= Body_Part
;
2742 Last
:= Last
- Name_Len
;
2744 if Current_Verbosity
= High
then
2745 Write_Str
(" Separate: ");
2746 Write_Line
(File
(First
.. Last
));
2760 -- This is not a source file
2762 Unit_Name
:= No_Name
;
2763 Unit_Kind
:= Specification
;
2765 if Current_Verbosity
= High
then
2766 Write_Line
(" Not a valid file name.");
2772 Get_Name_String
(Naming
.Dot_Replacement
);
2774 Standard_GNAT
and then Name_Buffer
(1 .. Name_Len
) = "-";
2776 if Name_Buffer
(1 .. Name_Len
) /= "." then
2778 -- If Dot_Replacement is not a single dot,
2779 -- then there should not be any dot in the name.
2781 for Index
in First
.. Last
loop
2782 if File
(Index
) = '.' then
2783 if Current_Verbosity
= High
then
2785 (" Not a valid file name (some dot not replaced).");
2788 Unit_Name
:= No_Name
;
2794 -- Replace the substring Dot_Replacement with dots
2797 Index
: Positive := First
;
2800 while Index
<= Last
- Name_Len
+ 1 loop
2802 if File
(Index
.. Index
+ Name_Len
- 1) =
2803 Name_Buffer
(1 .. Name_Len
)
2805 File
(Index
) := '.';
2807 if Name_Len
> 1 and then Index
< Last
then
2808 File
(Index
+ 1 .. Last
- Name_Len
+ 1) :=
2809 File
(Index
+ Name_Len
.. Last
);
2812 Last
:= Last
- Name_Len
+ 1;
2820 -- Check if the casing is right
2823 Src
: String := File
(First
.. Last
);
2826 case Naming
.Casing
is
2827 when All_Lower_Case
=>
2830 Mapping
=> Lower_Case_Map
);
2832 when All_Upper_Case
=>
2835 Mapping
=> Upper_Case_Map
);
2837 when Mixed_Case | Unknown
=>
2841 if Src
/= File
(First
.. Last
) then
2842 if Current_Verbosity
= High
then
2843 Write_Line
(" Not a valid file name (casing).");
2846 Unit_Name
:= No_Name
;
2850 -- We put the name in lower case
2854 Mapping
=> Lower_Case_Map
);
2856 -- In the standard GNAT naming scheme, check for special cases:
2857 -- children or separates of A, G, I or S, and run time sources.
2859 if Standard_GNAT
and then Src
'Length >= 3 then
2861 S1
: constant Character := Src
(Src
'First);
2862 S2
: constant Character := Src
(Src
'First + 1);
2865 if S1
= 'a' or else S1
= 'g'
2866 or else S1
= 'i' or else S1
= 's'
2868 -- Children or separates of packages A, G, I or S
2870 if (Hostparm
.OpenVMS
and then S2
= '$')
2871 or else (not Hostparm
.OpenVMS
and then S2
= '~')
2873 Src
(Src
'First + 1) := '.';
2875 -- If it is potentially a run time source, disable
2876 -- filling of the mapping file to avoid warnings.
2879 Set_Mapping_File_Initial_State_To_Empty
;
2886 if Current_Verbosity
= High
then
2891 -- Now, we check if this name is a valid unit name
2893 Check_Ada_Name
(Name
=> Src
, Unit
=> Unit_Name
);
2903 function Hash
(Unit
: Unit_Info
) return Header_Num
is
2905 return Header_Num
(Unit
.Unit
mod 2048);
2908 -----------------------
2909 -- Is_Illegal_Suffix --
2910 -----------------------
2912 function Is_Illegal_Suffix
2914 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean
2917 if Suffix
'Length = 0 or else Index
(Suffix
, ".") = 0 then
2921 -- If dot replacement is a single dot, and first character of
2922 -- suffix is also a dot
2924 if Dot_Replacement_Is_A_Single_Dot
2925 and then Suffix
(Suffix
'First) = '.'
2927 for Index
in Suffix
'First + 1 .. Suffix
'Last loop
2929 -- If there is another dot
2931 if Suffix
(Index
) = '.' then
2933 -- It is illegal to have a letter following the initial dot
2935 return Is_Letter
(Suffix
(Suffix
'First + 1));
2943 end Is_Illegal_Suffix
;
2945 --------------------------------
2946 -- Language_Independent_Check --
2947 --------------------------------
2949 procedure Language_Independent_Check
2950 (Project
: Project_Id
;
2951 Report_Error
: Put_Line_Access
)
2953 Last_Source_Dir
: String_List_Id
:= Nil_String
;
2954 Data
: Project_Data
:= Projects
.Table
(Project
);
2956 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
);
2957 -- Find one or several source directories, and add them
2958 -- to the list of source directories of the project.
2960 ----------------------
2961 -- Find_Source_Dirs --
2962 ----------------------
2964 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
) is
2965 Directory
: constant String := Get_Name_String
(From
);
2966 Element
: String_Element
;
2968 procedure Recursive_Find_Dirs
(Path
: Name_Id
);
2969 -- Find all the subdirectories (recursively) of Path and add them
2970 -- to the list of source directories of the project.
2972 -------------------------
2973 -- Recursive_Find_Dirs --
2974 -------------------------
2976 procedure Recursive_Find_Dirs
(Path
: Name_Id
) is
2978 Name
: String (1 .. 250);
2980 List
: String_List_Id
:= Data
.Source_Dirs
;
2981 Element
: String_Element
;
2982 Found
: Boolean := False;
2984 Non_Canonical_Path
: Name_Id
:= No_Name
;
2985 Canonical_Path
: Name_Id
:= No_Name
;
2987 The_Path
: constant String :=
2988 Normalize_Pathname
(Get_Name_String
(Path
)) &
2989 Directory_Separator
;
2991 The_Path_Last
: constant Natural :=
2992 Compute_Directory_Last
(The_Path
);
2995 Name_Len
:= The_Path_Last
- The_Path
'First + 1;
2996 Name_Buffer
(1 .. Name_Len
) :=
2997 The_Path
(The_Path
'First .. The_Path_Last
);
2998 Non_Canonical_Path
:= Name_Find
;
2999 Get_Name_String
(Non_Canonical_Path
);
3000 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3001 Canonical_Path
:= Name_Find
;
3003 -- To avoid processing the same directory several times, check
3004 -- if the directory is already in Recursive_Dirs. If it is,
3005 -- then there is nothing to do, just return. If it is not, put
3006 -- it there and continue recursive processing.
3008 if Recursive_Dirs
.Get
(Canonical_Path
) then
3012 Recursive_Dirs
.Set
(Canonical_Path
, True);
3015 -- Check if directory is already in list
3017 while List
/= Nil_String
loop
3018 Element
:= String_Elements
.Table
(List
);
3020 if Element
.Value
/= No_Name
then
3021 Found
:= Element
.Value
= Canonical_Path
;
3025 List
:= Element
.Next
;
3028 -- If directory is not already in list, put it there
3031 if Current_Verbosity
= High
then
3033 Write_Line
(The_Path
(The_Path
'First .. The_Path_Last
));
3036 String_Elements
.Increment_Last
;
3038 (Value
=> Canonical_Path
,
3039 Display_Value
=> Non_Canonical_Path
,
3040 Location
=> No_Location
,
3045 -- Case of first source directory
3047 if Last_Source_Dir
= Nil_String
then
3048 Data
.Source_Dirs
:= String_Elements
.Last
;
3050 -- Here we already have source directories.
3053 -- Link the previous last to the new one
3055 String_Elements
.Table
(Last_Source_Dir
).Next
:=
3056 String_Elements
.Last
;
3059 -- And register this source directory as the new last
3061 Last_Source_Dir
:= String_Elements
.Last
;
3062 String_Elements
.Table
(Last_Source_Dir
) := Element
;
3065 -- Now look for subdirectories. We do that even when this
3066 -- directory is already in the list, because some of its
3067 -- subdirectories may not be in the list yet.
3069 Open
(Dir
, The_Path
(The_Path
'First .. The_Path_Last
));
3072 Read
(Dir
, Name
, Last
);
3075 if Name
(1 .. Last
) /= "."
3076 and then Name
(1 .. Last
) /= ".."
3080 if Current_Verbosity
= High
then
3081 Write_Str
(" Checking ");
3082 Write_Line
(Name
(1 .. Last
));
3086 Path_Name
: constant String :=
3088 (Name
=> Name
(1 .. Last
),
3091 (The_Path
'First .. The_Path_Last
),
3092 Resolve_Links
=> False,
3093 Case_Sensitive
=> True);
3096 if Is_Directory
(Path_Name
) then
3098 -- We have found a new subdirectory, call self
3100 Name_Len
:= Path_Name
'Length;
3101 Name_Buffer
(1 .. Name_Len
) := Path_Name
;
3102 Recursive_Find_Dirs
(Name_Find
);
3111 when Directory_Error
=>
3113 end Recursive_Find_Dirs
;
3115 -- Start of processing for Find_Source_Dirs
3118 if Current_Verbosity
= High
then
3119 Write_Str
("Find_Source_Dirs (""");
3120 Write_Str
(Directory
);
3124 -- First, check if we are looking for a directory tree,
3125 -- indicated by "/**" at the end.
3127 if Directory
'Length >= 3
3128 and then Directory
(Directory
'Last - 1 .. Directory
'Last) = "**"
3129 and then (Directory
(Directory
'Last - 2) = '/'
3131 Directory
(Directory
'Last - 2) = Directory_Separator
)
3133 Data
.Known_Order_Of_Source_Dirs
:= False;
3135 Name_Len
:= Directory
'Length - 3;
3137 if Name_Len
= 0 then
3139 -- This is the case of "/**": all directories
3140 -- in the file system.
3143 Name_Buffer
(1) := Directory
(Directory
'First);
3146 Name_Buffer
(1 .. Name_Len
) :=
3147 Directory
(Directory
'First .. Directory
'Last - 3);
3150 if Current_Verbosity
= High
then
3151 Write_Str
("Looking for all subdirectories of """);
3152 Write_Str
(Name_Buffer
(1 .. Name_Len
));
3157 Base_Dir
: constant Name_Id
:= Name_Find
;
3158 Root_Dir
: constant String :=
3160 (Name
=> Get_Name_String
(Base_Dir
),
3162 Get_Name_String
(Data
.Display_Directory
),
3163 Resolve_Links
=> False,
3164 Case_Sensitive
=> True);
3167 if Root_Dir
'Length = 0 then
3168 Err_Vars
.Error_Msg_Name_1
:= Base_Dir
;
3170 if Location
= No_Location
then
3173 "{ is not a valid directory.",
3178 "{ is not a valid directory.",
3183 -- We have an existing directory,
3184 -- we register it and all of its subdirectories.
3186 if Current_Verbosity
= High
then
3187 Write_Line
("Looking for source directories:");
3190 Name_Len
:= Root_Dir
'Length;
3191 Name_Buffer
(1 .. Name_Len
) := Root_Dir
;
3192 Recursive_Find_Dirs
(Name_Find
);
3194 if Current_Verbosity
= High
then
3195 Write_Line
("End of looking for source directories.");
3200 -- We have a single directory
3204 Path_Name
: Name_Id
;
3205 Display_Path_Name
: Name_Id
;
3208 (From
, Data
.Display_Directory
, Path_Name
, Display_Path_Name
);
3209 if Path_Name
= No_Name
then
3210 Err_Vars
.Error_Msg_Name_1
:= From
;
3212 if Location
= No_Location
then
3215 "{ is not a valid directory",
3220 "{ is not a valid directory",
3225 -- As it is an existing directory, we add it to
3226 -- the list of directories.
3228 String_Elements
.Increment_Last
;
3229 Element
.Value
:= Path_Name
;
3230 Element
.Display_Value
:= Display_Path_Name
;
3232 if Last_Source_Dir
= Nil_String
then
3234 -- This is the first source directory
3236 Data
.Source_Dirs
:= String_Elements
.Last
;
3239 -- We already have source directories,
3240 -- link the previous last to the new one.
3242 String_Elements
.Table
(Last_Source_Dir
).Next
:=
3243 String_Elements
.Last
;
3246 -- And register this source directory as the new last
3248 Last_Source_Dir
:= String_Elements
.Last
;
3249 String_Elements
.Table
(Last_Source_Dir
) := Element
;
3253 end Find_Source_Dirs
;
3255 -- Start of processing for Language_Independent_Check
3258 if Data
.Language_Independent_Checked
then
3262 Data
.Language_Independent_Checked
:= True;
3264 Error_Report
:= Report_Error
;
3266 Recursive_Dirs
.Reset
;
3268 if Current_Verbosity
= High
then
3269 Write_Line
("Starting to look for directories");
3272 -- Check the object directory
3275 Object_Dir
: constant Variable_Value
:=
3276 Util
.Value_Of
(Name_Object_Dir
, Data
.Decl
.Attributes
);
3279 pragma Assert
(Object_Dir
.Kind
= Single
,
3280 "Object_Dir is not a single string");
3282 -- We set the object directory to its default
3284 Data
.Object_Directory
:= Data
.Directory
;
3285 Data
.Display_Object_Dir
:= Data
.Display_Directory
;
3287 if Object_Dir
.Value
/= Empty_String
then
3289 Get_Name_String
(Object_Dir
.Value
);
3291 if Name_Len
= 0 then
3294 "Object_Dir cannot be empty",
3295 Object_Dir
.Location
);
3298 -- We check that the specified object directory
3302 (Object_Dir
.Value
, Data
.Display_Directory
,
3303 Data
.Object_Directory
, Data
.Display_Object_Dir
);
3305 if Data
.Object_Directory
= No_Name
then
3306 -- The object directory does not exist, report an error
3307 Err_Vars
.Error_Msg_Name_1
:= Object_Dir
.Value
;
3310 "the object directory { cannot be found",
3313 -- Do not keep a nil Object_Directory. Set it to the
3314 -- specified (relative or absolute) path.
3315 -- This is for the benefit of tools that recover from
3316 -- errors; for example, these tools could create the
3317 -- non existent directory.
3319 Data
.Display_Object_Dir
:= Object_Dir
.Value
;
3320 Get_Name_String
(Object_Dir
.Value
);
3321 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3322 Data
.Object_Directory
:= Name_Find
;
3328 if Current_Verbosity
= High
then
3329 if Data
.Object_Directory
= No_Name
then
3330 Write_Line
("No object directory");
3332 Write_Str
("Object directory: """);
3333 Write_Str
(Get_Name_String
(Data
.Display_Object_Dir
));
3338 -- Check the exec directory
3341 Exec_Dir
: constant Variable_Value
:=
3342 Util
.Value_Of
(Name_Exec_Dir
, Data
.Decl
.Attributes
);
3345 pragma Assert
(Exec_Dir
.Kind
= Single
,
3346 "Exec_Dir is not a single string");
3348 -- We set the object directory to its default
3350 Data
.Exec_Directory
:= Data
.Object_Directory
;
3351 Data
.Display_Exec_Dir
:= Data
.Display_Object_Dir
;
3353 if Exec_Dir
.Value
/= Empty_String
then
3355 Get_Name_String
(Exec_Dir
.Value
);
3357 if Name_Len
= 0 then
3360 "Exec_Dir cannot be empty",
3364 -- We check that the specified object directory
3368 (Exec_Dir
.Value
, Data
.Directory
,
3369 Data
.Exec_Directory
, Data
.Display_Exec_Dir
);
3371 if Data
.Exec_Directory
= No_Name
then
3372 Err_Vars
.Error_Msg_Name_1
:= Exec_Dir
.Value
;
3375 "the exec directory { cannot be found",
3382 if Current_Verbosity
= High
then
3383 if Data
.Exec_Directory
= No_Name
then
3384 Write_Line
("No exec directory");
3386 Write_Str
("Exec directory: """);
3387 Write_Str
(Get_Name_String
(Data
.Display_Exec_Dir
));
3392 -- Look for the source directories
3395 Source_Dirs
: constant Variable_Value
:=
3397 (Name_Source_Dirs
, Data
.Decl
.Attributes
);
3400 if Current_Verbosity
= High
then
3401 Write_Line
("Starting to look for source directories");
3404 pragma Assert
(Source_Dirs
.Kind
= List
,
3405 "Source_Dirs is not a list");
3407 if Source_Dirs
.Default
then
3409 -- No Source_Dirs specified: the single source directory
3410 -- is the one containing the project file
3412 String_Elements
.Increment_Last
;
3413 Data
.Source_Dirs
:= String_Elements
.Last
;
3414 String_Elements
.Table
(Data
.Source_Dirs
) :=
3415 (Value
=> Data
.Directory
,
3416 Display_Value
=> Data
.Display_Directory
,
3417 Location
=> No_Location
,
3422 if Current_Verbosity
= High
then
3423 Write_Line
("Single source directory:");
3425 Write_Str
(Get_Name_String
(Data
.Display_Directory
));
3429 elsif Source_Dirs
.Values
= Nil_String
then
3431 -- If Source_Dirs is an empty string list, this means
3432 -- that this project contains no source. For projects that
3433 -- don't extend other projects, this also means that there is no
3434 -- need for an object directory, if not specified.
3436 if Data
.Extends
= No_Project
3437 and then Data
.Object_Directory
= Data
.Directory
3439 Data
.Object_Directory
:= No_Name
;
3442 Data
.Source_Dirs
:= Nil_String
;
3443 Data
.Ada_Sources_Present
:= False;
3444 Data
.Other_Sources_Present
:= False;
3448 Source_Dir
: String_List_Id
:= Source_Dirs
.Values
;
3449 Element
: String_Element
;
3452 -- We will find the source directories for each
3453 -- element of the list
3455 while Source_Dir
/= Nil_String
loop
3456 Element
:= String_Elements
.Table
(Source_Dir
);
3457 Find_Source_Dirs
(Element
.Value
, Element
.Location
);
3458 Source_Dir
:= Element
.Next
;
3463 if Current_Verbosity
= High
then
3464 Write_Line
("Putting source directories in canonical cases");
3468 Current
: String_List_Id
:= Data
.Source_Dirs
;
3469 Element
: String_Element
;
3472 while Current
/= Nil_String
loop
3473 Element
:= String_Elements
.Table
(Current
);
3474 if Element
.Value
/= No_Name
then
3475 Get_Name_String
(Element
.Value
);
3476 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3477 Element
.Value
:= Name_Find
;
3478 String_Elements
.Table
(Current
) := Element
;
3481 Current
:= Element
.Next
;
3486 -- Library attributes
3489 Attributes
: constant Prj
.Variable_Id
:= Data
.Decl
.Attributes
;
3491 Lib_Dir
: constant Prj
.Variable_Value
:=
3492 Prj
.Util
.Value_Of
(Snames
.Name_Library_Dir
, Attributes
);
3494 Lib_Name
: constant Prj
.Variable_Value
:=
3495 Prj
.Util
.Value_Of
(Snames
.Name_Library_Name
, Attributes
);
3497 Lib_Version
: constant Prj
.Variable_Value
:=
3499 (Snames
.Name_Library_Version
, Attributes
);
3501 The_Lib_Kind
: constant Prj
.Variable_Value
:=
3503 (Snames
.Name_Library_Kind
, Attributes
);
3506 -- Special case of extending project
3508 if Data
.Extends
/= No_Project
then
3510 Extended_Data
: constant Project_Data
:=
3511 Projects
.Table
(Data
.Extends
);
3514 -- If the project extended is a library project, we inherit
3515 -- the library name, if it is not redefined; we check that
3516 -- the library directory is specified; and we reset the
3517 -- library flag for the extended project.
3519 if Extended_Data
.Library
then
3520 if Lib_Name
.Default
then
3521 Data
.Library_Name
:= Extended_Data
.Library_Name
;
3524 if Lib_Dir
.Default
then
3525 if not Data
.Virtual
then
3528 "a project extending a library project must " &
3529 "specify an attribute Library_Dir",
3534 Projects
.Table
(Data
.Extends
).Library
:= False;
3539 pragma Assert
(Lib_Dir
.Kind
= Single
);
3541 if Lib_Dir
.Value
= Empty_String
then
3543 if Current_Verbosity
= High
then
3544 Write_Line
("No library directory");
3548 -- Find path name, check that it is a directory
3551 (Lib_Dir
.Value
, Data
.Display_Directory
,
3552 Data
.Library_Dir
, Data
.Display_Library_Dir
);
3554 if Data
.Library_Dir
= No_Name
then
3556 -- Get the absolute name of the library directory that
3557 -- does not exist, to report an error.
3560 Dir_Name
: constant String :=
3561 Get_Name_String
(Lib_Dir
.Value
);
3563 if Is_Absolute_Path
(Dir_Name
) then
3564 Err_Vars
.Error_Msg_Name_1
:= Lib_Dir
.Value
;
3567 Get_Name_String
(Data
.Display_Directory
);
3569 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
3570 Name_Len
:= Name_Len
+ 1;
3571 Name_Buffer
(Name_Len
) := Directory_Separator
;
3575 (Name_Len
+ 1 .. Name_Len
+ Dir_Name
'Length) :=
3577 Name_Len
:= Name_Len
+ Dir_Name
'Length;
3578 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
3585 "library directory { does not exist",
3589 elsif Data
.Library_Dir
= Data
.Object_Directory
then
3592 "library directory cannot be the same " &
3593 "as object directory",
3595 Data
.Library_Dir
:= No_Name
;
3596 Data
.Display_Library_Dir
:= No_Name
;
3599 if Current_Verbosity
= High
then
3600 Write_Str
("Library directory =""");
3601 Write_Str
(Get_Name_String
(Data
.Display_Library_Dir
));
3607 pragma Assert
(Lib_Name
.Kind
= Single
);
3609 if Lib_Name
.Value
= Empty_String
then
3610 if Current_Verbosity
= High
3611 and then Data
.Library_Name
= No_Name
3613 Write_Line
("No library name");
3617 -- There is no restriction on the syntax of library names
3619 Data
.Library_Name
:= Lib_Name
.Value
;
3622 if Data
.Library_Name
/= No_Name
3623 and then Current_Verbosity
= High
3625 Write_Str
("Library name = """);
3626 Write_Str
(Get_Name_String
(Data
.Library_Name
));
3631 Data
.Library_Dir
/= No_Name
3633 Data
.Library_Name
/= No_Name
;
3635 if Data
.Library
then
3636 if MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.None
then
3639 "?libraries are not supported on this platform",
3641 Data
.Library
:= False;
3644 pragma Assert
(Lib_Version
.Kind
= Single
);
3646 if Lib_Version
.Value
= Empty_String
then
3647 if Current_Verbosity
= High
then
3648 Write_Line
("No library version specified");
3652 Data
.Lib_Internal_Name
:= Lib_Version
.Value
;
3655 pragma Assert
(The_Lib_Kind
.Kind
= Single
);
3657 if The_Lib_Kind
.Value
= Empty_String
then
3658 if Current_Verbosity
= High
then
3659 Write_Line
("No library kind specified");
3663 Get_Name_String
(The_Lib_Kind
.Value
);
3666 Kind_Name
: constant String :=
3667 To_Lower
(Name_Buffer
(1 .. Name_Len
));
3669 OK
: Boolean := True;
3672 if Kind_Name
= "static" then
3673 Data
.Library_Kind
:= Static
;
3675 elsif Kind_Name
= "dynamic" then
3676 Data
.Library_Kind
:= Dynamic
;
3678 elsif Kind_Name
= "relocatable" then
3679 Data
.Library_Kind
:= Relocatable
;
3684 "illegal value for Library_Kind",
3685 The_Lib_Kind
.Location
);
3689 if Current_Verbosity
= High
and then OK
then
3690 Write_Str
("Library kind = ");
3691 Write_Line
(Kind_Name
);
3694 if Data
.Library_Kind
/= Static
and then
3695 MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.Static_Only
3699 "only static libraries are supported " &
3701 The_Lib_Kind
.Location
);
3702 Data
.Library
:= False;
3707 if Data
.Library
and then Current_Verbosity
= High
then
3708 Write_Line
("This is a library project file");
3715 if Current_Verbosity
= High
then
3716 Show_Source_Dirs
(Project
);
3720 Naming_Id
: constant Package_Id
:=
3721 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
);
3723 Naming
: Package_Element
;
3726 -- If there is a package Naming, we will put in Data.Naming
3727 -- what is in this package Naming.
3729 if Naming_Id
/= No_Package
then
3730 Naming
:= Packages
.Table
(Naming_Id
);
3732 if Current_Verbosity
= High
then
3733 Write_Line
("Checking ""Naming"".");
3736 -- Check Spec_Suffix
3739 Spec_Suffixs
: Array_Element_Id
:=
3742 Naming
.Decl
.Arrays
);
3743 Suffix
: Array_Element_Id
;
3744 Element
: Array_Element
;
3745 Suffix2
: Array_Element_Id
;
3748 -- If some suffixs have been specified, we make sure that
3749 -- for each language for which a default suffix has been
3750 -- specified, there is a suffix specified, either the one
3751 -- in the project file or if there were none, the default.
3753 if Spec_Suffixs
/= No_Array_Element
then
3754 Suffix
:= Data
.Naming
.Spec_Suffix
;
3756 while Suffix
/= No_Array_Element
loop
3757 Element
:= Array_Elements
.Table
(Suffix
);
3758 Suffix2
:= Spec_Suffixs
;
3760 while Suffix2
/= No_Array_Element
loop
3761 exit when Array_Elements
.Table
(Suffix2
).Index
=
3763 Suffix2
:= Array_Elements
.Table
(Suffix2
).Next
;
3766 -- There is a registered default suffix, but no
3767 -- suffix specified in the project file.
3768 -- Add the default to the array.
3770 if Suffix2
= No_Array_Element
then
3771 Array_Elements
.Increment_Last
;
3772 Array_Elements
.Table
(Array_Elements
.Last
) :=
3773 (Index
=> Element
.Index
,
3774 Src_Index
=> Element
.Src_Index
,
3775 Index_Case_Sensitive
=> False,
3776 Value
=> Element
.Value
,
3777 Next
=> Spec_Suffixs
);
3778 Spec_Suffixs
:= Array_Elements
.Last
;
3781 Suffix
:= Element
.Next
;
3784 -- Put the resulting array as the specification suffixs
3786 Data
.Naming
.Spec_Suffix
:= Spec_Suffixs
;
3791 Current
: Array_Element_Id
:= Data
.Naming
.Spec_Suffix
;
3792 Element
: Array_Element
;
3795 while Current
/= No_Array_Element
loop
3796 Element
:= Array_Elements
.Table
(Current
);
3797 Get_Name_String
(Element
.Value
.Value
);
3799 if Name_Len
= 0 then
3802 "Spec_Suffix cannot be empty",
3803 Element
.Value
.Location
);
3806 Array_Elements
.Table
(Current
) := Element
;
3807 Current
:= Element
.Next
;
3811 -- Check Body_Suffix
3814 Impl_Suffixs
: Array_Element_Id
:=
3817 Naming
.Decl
.Arrays
);
3819 Suffix
: Array_Element_Id
;
3820 Element
: Array_Element
;
3821 Suffix2
: Array_Element_Id
;
3824 -- If some suffixs have been specified, we make sure that
3825 -- for each language for which a default suffix has been
3826 -- specified, there is a suffix specified, either the one
3827 -- in the project file or if there were noe, the default.
3829 if Impl_Suffixs
/= No_Array_Element
then
3830 Suffix
:= Data
.Naming
.Body_Suffix
;
3832 while Suffix
/= No_Array_Element
loop
3833 Element
:= Array_Elements
.Table
(Suffix
);
3834 Suffix2
:= Impl_Suffixs
;
3836 while Suffix2
/= No_Array_Element
loop
3837 exit when Array_Elements
.Table
(Suffix2
).Index
=
3839 Suffix2
:= Array_Elements
.Table
(Suffix2
).Next
;
3842 -- There is a registered default suffix, but no
3843 -- suffix specified in the project file.
3844 -- Add the default to the array.
3846 if Suffix2
= No_Array_Element
then
3847 Array_Elements
.Increment_Last
;
3848 Array_Elements
.Table
(Array_Elements
.Last
) :=
3849 (Index
=> Element
.Index
,
3850 Src_Index
=> Element
.Src_Index
,
3851 Index_Case_Sensitive
=> False,
3852 Value
=> Element
.Value
,
3853 Next
=> Impl_Suffixs
);
3854 Impl_Suffixs
:= Array_Elements
.Last
;
3857 Suffix
:= Element
.Next
;
3860 -- Put the resulting array as the implementation suffixs
3862 Data
.Naming
.Body_Suffix
:= Impl_Suffixs
;
3867 Current
: Array_Element_Id
:= Data
.Naming
.Body_Suffix
;
3868 Element
: Array_Element
;
3871 while Current
/= No_Array_Element
loop
3872 Element
:= Array_Elements
.Table
(Current
);
3873 Get_Name_String
(Element
.Value
.Value
);
3875 if Name_Len
= 0 then
3878 "Body_Suffix cannot be empty",
3879 Element
.Value
.Location
);
3882 Array_Elements
.Table
(Current
) := Element
;
3883 Current
:= Element
.Next
;
3887 -- Get the exceptions, if any
3889 Data
.Naming
.Specification_Exceptions
:=
3891 (Name_Specification_Exceptions
,
3892 In_Arrays
=> Naming
.Decl
.Arrays
);
3894 Data
.Naming
.Implementation_Exceptions
:=
3896 (Name_Implementation_Exceptions
,
3897 In_Arrays
=> Naming
.Decl
.Arrays
);
3901 Projects
.Table
(Project
) := Data
;
3902 end Language_Independent_Check
;
3904 ----------------------
3905 -- Locate_Directory --
3906 ----------------------
3908 procedure Locate_Directory
3912 Display
: out Name_Id
)
3914 The_Name
: constant String := Get_Name_String
(Name
);
3915 The_Parent
: constant String :=
3916 Get_Name_String
(Parent
) & Directory_Separator
;
3917 The_Parent_Last
: constant Natural :=
3918 Compute_Directory_Last
(The_Parent
);
3921 if Current_Verbosity
= High
then
3922 Write_Str
("Locate_Directory (""");
3923 Write_Str
(The_Name
);
3924 Write_Str
(""", """);
3925 Write_Str
(The_Parent
);
3932 if Is_Absolute_Path
(The_Name
) then
3933 if Is_Directory
(The_Name
) then
3935 Normed
: constant String :=
3938 Resolve_Links
=> False,
3939 Case_Sensitive
=> True);
3941 Canonical_Path
: constant String :=
3944 Resolve_Links
=> True,
3945 Case_Sensitive
=> False);
3948 Name_Len
:= Normed
'Length;
3949 Name_Buffer
(1 .. Name_Len
) := Normed
;
3950 Display
:= Name_Find
;
3952 Name_Len
:= Canonical_Path
'Length;
3953 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3960 Full_Path
: constant String :=
3961 The_Parent
(The_Parent
'First .. The_Parent_Last
) &
3965 if Is_Directory
(Full_Path
) then
3967 Normed
: constant String :=
3970 Resolve_Links
=> False,
3971 Case_Sensitive
=> True);
3973 Canonical_Path
: constant String :=
3976 Resolve_Links
=> True,
3977 Case_Sensitive
=> False);
3980 Name_Len
:= Normed
'Length;
3981 Name_Buffer
(1 .. Name_Len
) := Normed
;
3982 Display
:= Name_Find
;
3984 Name_Len
:= Canonical_Path
'Length;
3985 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3991 end Locate_Directory
;
3993 ---------------------------
3994 -- Other_Languages_Check --
3995 ---------------------------
3997 procedure Other_Languages_Check
3998 (Project
: Project_Id
;
3999 Report_Error
: Put_Line_Access
) is
4001 Data
: Project_Data
;
4003 Languages
: Variable_Value
:= Nil_Variable_Value
;
4006 Language_Independent_Check
(Project
, Report_Error
);
4008 Error_Report
:= Report_Error
;
4010 Data
:= Projects
.Table
(Project
);
4011 Languages
:= Prj
.Util
.Value_Of
(Name_Languages
, Data
.Decl
.Attributes
);
4013 Data
.Other_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
4015 if Data
.Other_Sources_Present
then
4016 -- Check if languages other than Ada are specified in this project
4018 if Languages
.Default
then
4019 -- Attribute Languages is not specified. So, it defaults to
4020 -- a project of language Ada only.
4022 Data
.Languages
(Lang_Ada
) := True;
4024 -- No sources of languages other than Ada
4026 Data
.Other_Sources_Present
:= False;
4030 Current
: String_List_Id
:= Languages
.Values
;
4031 Element
: String_Element
;
4032 OK
: Boolean := False;
4034 -- Assumethat there is no language other than Ada specified.
4035 -- If in fact there is at least one, we will set back
4036 -- Other_Sources_Present to True.
4038 Data
.Other_Sources_Present
:= False;
4040 -- Look through all the languages specified in attribute
4041 -- Languages, if any
4043 while Current
/= Nil_String
loop
4044 Element
:= String_Elements
.Table
(Current
);
4045 Get_Name_String
(Element
.Value
);
4046 To_Lower
(Name_Buffer
(1 .. Name_Len
));
4049 -- Check if it is a known language
4051 Lang_Loop
: for Lang
in Programming_Language
loop
4053 Name_Buffer
(1 .. Name_Len
) = Lang_Names
(Lang
).all
4055 -- Yes, this is a known language
4059 -- Indicate the presence of this language
4060 Data
.Languages
(Lang
) := True;
4062 -- If it is a language other than Ada, indicate that
4063 -- there should be some sources of a language other
4066 if Lang
/= Lang_Ada
then
4067 Data
.Other_Sources_Present
:= True;
4074 -- We don't support this language: report an error
4077 Error_Msg_Name_1
:= Element
.Value
;
4080 "unknown programming language {",
4084 Current
:= Element
.Next
;
4090 -- If there may be some sources, look for them
4092 if Data
.Other_Sources_Present
then
4093 -- Set Source_Present to False. It will be set back to True whenever
4094 -- a source is found.
4096 Data
.Other_Sources_Present
:= False;
4098 for Lang
in Other_Programming_Language
loop
4099 -- For each language (other than Ada) in the project file
4101 if Data
.Languages
(Lang
) then
4102 -- Reset the indication that there are sources of this
4103 -- language. It will be set back to True whenever we find a
4104 -- source of the language.
4106 Data
.Languages
(Lang
) := False;
4108 -- First, get the source suffix for the language
4110 Data
.Impl_Suffixes
(Lang
) := Suffix_For
(Lang
, Data
.Naming
);
4112 -- Then, deal with the naming exceptions, if any
4117 Naming_Exceptions
: constant Variable_Value
:=
4119 (Index
=> Lang_Name_Ids
(Lang
),
4121 In_Array
=> Data
.Naming
.Implementation_Exceptions
);
4122 Element_Id
: String_List_Id
;
4123 Element
: String_Element
;
4125 Source_Found
: Boolean := False;
4127 -- If there are naming exceptions, look through them one
4130 if Naming_Exceptions
/= Nil_Variable_Value
then
4131 Element_Id
:= Naming_Exceptions
.Values
;
4133 while Element_Id
/= Nil_String
loop
4134 Element
:= String_Elements
.Table
(Element_Id
);
4135 Get_Name_String
(Element
.Value
);
4136 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4137 File_Id
:= Name_Find
;
4139 -- Put each naming exception in the Source_Names
4140 -- hash table, but if there are repetition, don't
4141 -- bother after the first instance.
4143 if Source_Names
.Get
(File_Id
) = No_Name_Location
then
4144 Source_Found
:= True;
4148 Location
=> Element
.Location
,
4152 Element_Id
:= Element
.Next
;
4155 -- If there is at least one naming exception, record
4156 -- those that are found in the source directories.
4158 if Source_Found
then
4159 Record_Other_Sources
4160 (Project
=> Project
,
4163 Naming_Exceptions
=> True);
4169 -- Now, check if a list of sources is declared either through
4170 -- a string list (attribute Source_Files) or a text file
4171 -- (attribute Source_List_File).
4172 -- If a source list is declared, we will consider only those
4173 -- naming exceptions that are on the list.
4176 Sources
: constant Variable_Value
:=
4179 Data
.Decl
.Attributes
);
4181 Source_List_File
: constant Variable_Value
:=
4183 (Name_Source_List_File
,
4184 Data
.Decl
.Attributes
);
4188 (Sources
.Kind
= List
,
4189 "Source_Files is not a list");
4192 (Source_List_File
.Kind
= Single
,
4193 "Source_List_File is not a single string");
4195 if not Sources
.Default
then
4196 if not Source_List_File
.Default
then
4199 "?both variables source_files and " &
4200 "source_list_file are present",
4201 Source_List_File
.Location
);
4204 -- Sources is a list of file names
4207 Current
: String_List_Id
:= Sources
.Values
;
4208 Element
: String_Element
;
4209 Location
: Source_Ptr
;
4215 -- Put all the sources in the Source_Names hash
4218 while Current
/= Nil_String
loop
4219 Element
:= String_Elements
.Table
(Current
);
4220 Get_Name_String
(Element
.Value
);
4221 Canonical_Case_File_Name
4222 (Name_Buffer
(1 .. Name_Len
));
4225 -- If the element has no location, then use the
4226 -- location of Sources to report possible errors.
4228 if Element
.Location
= No_Location
then
4229 Location
:= Sources
.Location
;
4232 Location
:= Element
.Location
;
4239 Location
=> Location
,
4242 Current
:= Element
.Next
;
4245 -- And look for their directories
4247 Record_Other_Sources
4248 (Project
=> Project
,
4251 Naming_Exceptions
=> False);
4254 -- No source_files specified.
4255 -- We check if Source_List_File has been specified.
4257 elsif not Source_List_File
.Default
then
4259 -- Source_List_File is the name of the file
4260 -- that contains the source file names
4263 Source_File_Path_Name
: constant String :=
4265 (Source_List_File
.Value
,
4269 if Source_File_Path_Name
'Length = 0 then
4270 Err_Vars
.Error_Msg_Name_1
:= Source_List_File
.Value
;
4273 "file with sources { does not exist",
4274 Source_List_File
.Location
);
4277 -- Read the file, putting each source in the
4278 -- Source_Names hash table.
4280 Get_Sources_From_File
4281 (Source_File_Path_Name
,
4282 Source_List_File
.Location
,
4285 -- And look for their directories.
4287 Record_Other_Sources
4288 (Project
=> Project
,
4291 Naming_Exceptions
=> False);
4296 -- Neither Source_Files nor Source_List_File has been
4297 -- specified. Find all the files that satisfy
4298 -- the naming scheme in all the source directories.
4299 -- All the naming exceptions that effectively exist are
4300 -- also part of the source of this language.
4302 Find_Sources
(Project
, Data
, Lang
);
4310 -- Finally, get the mains, if any
4312 Get_Mains
(Project
, Data
);
4314 Projects
.Table
(Project
) := Data
;
4316 end Other_Languages_Check
;
4322 function Path_Name_Of
4323 (File_Name
: Name_Id
;
4324 Directory
: Name_Id
) return String
4326 Result
: String_Access
;
4327 The_Directory
: constant String := Get_Name_String
(Directory
);
4330 Get_Name_String
(File_Name
);
4331 Result
:= Locate_Regular_File
4332 (File_Name
=> Name_Buffer
(1 .. Name_Len
),
4333 Path
=> The_Directory
);
4335 if Result
= null then
4338 Canonical_Case_File_Name
(Result
.all);
4343 -------------------------------
4344 -- Prepare_Ada_Naming_Exceptions --
4345 -------------------------------
4347 procedure Prepare_Ada_Naming_Exceptions
4348 (List
: Array_Element_Id
;
4349 Kind
: Spec_Or_Body
)
4351 Current
: Array_Element_Id
:= List
;
4352 Element
: Array_Element
;
4357 -- Traverse the list
4359 while Current
/= No_Array_Element
loop
4360 Element
:= Array_Elements
.Table
(Current
);
4362 if Element
.Index
/= No_Name
then
4365 Unit
=> Element
.Index
,
4366 Next
=> No_Ada_Naming_Exception
);
4367 Reverse_Ada_Naming_Exceptions
.Set
4368 (Unit
, (Element
.Value
.Value
, Element
.Value
.Index
));
4369 Unit
.Next
:= Ada_Naming_Exceptions
.Get
(Element
.Value
.Value
);
4370 Ada_Naming_Exception_Table
.Increment_Last
;
4371 Ada_Naming_Exception_Table
.Table
4372 (Ada_Naming_Exception_Table
.Last
) := Unit
;
4373 Ada_Naming_Exceptions
.Set
4374 (Element
.Value
.Value
, Ada_Naming_Exception_Table
.Last
);
4377 Current
:= Element
.Next
;
4379 end Prepare_Ada_Naming_Exceptions
;
4381 ---------------------
4382 -- Project_Extends --
4383 ---------------------
4385 function Project_Extends
4386 (Extending
: Project_Id
;
4387 Extended
: Project_Id
) return Boolean
4389 Current
: Project_Id
:= Extending
;
4392 if Current
= No_Project
then
4395 elsif Current
= Extended
then
4399 Current
:= Projects
.Table
(Current
).Extends
;
4401 end Project_Extends
;
4403 -----------------------
4404 -- Record_Ada_Source --
4405 -----------------------
4407 procedure Record_Ada_Source
4408 (File_Name
: Name_Id
;
4409 Path_Name
: Name_Id
;
4410 Project
: Project_Id
;
4411 Data
: in out Project_Data
;
4412 Location
: Source_Ptr
;
4413 Current_Source
: in out String_List_Id
;
4414 Source_Recorded
: in out Boolean;
4415 Follow_Links
: Boolean)
4417 Canonical_File_Name
: Name_Id
;
4418 Canonical_Path_Name
: Name_Id
;
4419 Exception_Id
: Ada_Naming_Exception_Id
;
4420 Unit_Name
: Name_Id
;
4421 Unit_Kind
: Spec_Or_Body
;
4422 Unit_Index
: Int
:= 0;
4424 Name_Index
: Name_And_Index
;
4425 Needs_Pragma
: Boolean;
4427 The_Location
: Source_Ptr
:= Location
;
4428 Previous_Source
: constant String_List_Id
:= Current_Source
;
4429 Except_Name
: Name_And_Index
:= No_Name_And_Index
;
4431 Unit_Prj
: Unit_Project
;
4433 File_Name_Recorded
: Boolean := False;
4436 Get_Name_String
(File_Name
);
4437 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4438 Canonical_File_Name
:= Name_Find
;
4441 Canonical_Path
: constant String :=
4443 (Get_Name_String
(Path_Name
),
4444 Resolve_Links
=> Follow_Links
,
4445 Case_Sensitive
=> False);
4448 Add_Str_To_Name_Buffer
(Canonical_Path
);
4449 Canonical_Path_Name
:= Name_Find
;
4452 -- Find out the unit name, the unit kind and if it needs
4453 -- a specific SFN pragma.
4456 (Canonical_File_Name
=> Canonical_File_Name
,
4457 Naming
=> Data
.Naming
,
4458 Exception_Id
=> Exception_Id
,
4459 Unit_Name
=> Unit_Name
,
4460 Unit_Kind
=> Unit_Kind
,
4461 Needs_Pragma
=> Needs_Pragma
);
4463 if Exception_Id
= No_Ada_Naming_Exception
and then
4466 if Current_Verbosity
= High
then
4468 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4469 Write_Line
(""" is not a valid source file name (ignored).");
4474 -- Check to see if the source has been hidden by an exception,
4475 -- but only if it is not an exception.
4477 if not Needs_Pragma
then
4479 Reverse_Ada_Naming_Exceptions
.Get
4480 ((Unit_Kind
, Unit_Name
, No_Ada_Naming_Exception
));
4482 if Except_Name
/= No_Name_And_Index
then
4483 if Current_Verbosity
= High
then
4485 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4486 Write_Str
(""" contains a unit that is found in """);
4487 Write_Str
(Get_Name_String
(Except_Name
.Name
));
4488 Write_Line
(""" (ignored).");
4491 -- The file is not included in the source of the project,
4492 -- because it is hidden by the exception.
4493 -- So, there is nothing else to do.
4500 if Exception_Id
/= No_Ada_Naming_Exception
then
4501 Info
:= Ada_Naming_Exception_Table
.Table
(Exception_Id
);
4502 Exception_Id
:= Info
.Next
;
4503 Info
.Next
:= No_Ada_Naming_Exception
;
4504 Name_Index
:= Reverse_Ada_Naming_Exceptions
.Get
(Info
);
4506 Unit_Name
:= Info
.Unit
;
4507 Unit_Index
:= Name_Index
.Index
;
4508 Unit_Kind
:= Info
.Kind
;
4510 -- Put the file name in the list of sources of the project
4512 if not File_Name_Recorded
then
4513 String_Elements
.Increment_Last
;
4514 String_Elements
.Table
(String_Elements
.Last
) :=
4515 (Value
=> Canonical_File_Name
,
4516 Display_Value
=> File_Name
,
4517 Location
=> No_Location
,
4520 Index
=> Unit_Index
);
4523 if Current_Source
= Nil_String
then
4524 Data
.Sources
:= String_Elements
.Last
;
4527 String_Elements
.Table
(Current_Source
).Next
:=
4528 String_Elements
.Last
;
4531 Current_Source
:= String_Elements
.Last
;
4533 -- Put the unit in unit list
4536 The_Unit
: Unit_Id
:= Units_Htable
.Get
(Unit_Name
);
4537 The_Unit_Data
: Unit_Data
;
4540 if Current_Verbosity
= High
then
4541 Write_Str
("Putting ");
4542 Write_Str
(Get_Name_String
(Unit_Name
));
4543 Write_Line
(" in the unit list.");
4546 -- The unit is already in the list, but may be it is
4547 -- only the other unit kind (spec or body), or what is
4548 -- in the unit list is a unit of a project we are extending.
4550 if The_Unit
/= Prj
.Com
.No_Unit
then
4551 The_Unit_Data
:= Units
.Table
(The_Unit
);
4553 if The_Unit_Data
.File_Names
(Unit_Kind
).Name
= No_Name
4554 or else Project_Extends
4556 The_Unit_Data
.File_Names
(Unit_Kind
).Project
)
4558 if The_Unit_Data
.File_Names
(Unit_Kind
).Path
= Slash
then
4559 Remove_Forbidden_File_Name
4560 (The_Unit_Data
.File_Names
(Unit_Kind
).Name
);
4563 -- Record the file name in the hash table Files_Htable
4565 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4566 Files_Htable
.Set
(Canonical_File_Name
, Unit_Prj
);
4568 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4569 (Name
=> Canonical_File_Name
,
4570 Index
=> Unit_Index
,
4571 Display_Name
=> File_Name
,
4572 Path
=> Canonical_Path_Name
,
4573 Display_Path
=> Path_Name
,
4575 Needs_Pragma
=> Needs_Pragma
);
4576 Units
.Table
(The_Unit
) := The_Unit_Data
;
4577 Source_Recorded
:= True;
4579 elsif The_Unit_Data
.File_Names
(Unit_Kind
).Project
= Project
4580 and then (Data
.Known_Order_Of_Source_Dirs
or else
4581 The_Unit_Data
.File_Names
(Unit_Kind
).Path
=
4582 Canonical_Path_Name
)
4584 if Previous_Source
= Nil_String
then
4585 Data
.Sources
:= Nil_String
;
4587 String_Elements
.Table
(Previous_Source
).Next
:=
4589 String_Elements
.Decrement_Last
;
4592 Current_Source
:= Previous_Source
;
4595 -- It is an error to have two units with the same name
4596 -- and the same kind (spec or body).
4598 if The_Location
= No_Location
then
4599 The_Location
:= Projects
.Table
(Project
).Location
;
4602 Err_Vars
.Error_Msg_Name_1
:= Unit_Name
;
4603 Error_Msg
(Project
, "duplicate source {", The_Location
);
4605 Err_Vars
.Error_Msg_Name_1
:=
4607 (The_Unit_Data
.File_Names
(Unit_Kind
).Project
).Name
;
4608 Err_Vars
.Error_Msg_Name_2
:=
4609 The_Unit_Data
.File_Names
(Unit_Kind
).Path
;
4611 (Project
, "\ project file {, {", The_Location
);
4613 Err_Vars
.Error_Msg_Name_1
:=
4614 Projects
.Table
(Project
).Name
;
4615 Err_Vars
.Error_Msg_Name_2
:= Canonical_Path_Name
;
4617 (Project
, "\ project file {, {", The_Location
);
4621 -- It is a new unit, create a new record
4624 -- First, check if there is no other unit with this file
4625 -- name in another project. If it is, report an error.
4626 -- Of course, we do that only for the first unit in the
4629 Unit_Prj
:= Files_Htable
.Get
(Canonical_File_Name
);
4631 if not File_Name_Recorded
and then
4632 Unit_Prj
/= No_Unit_Project
4634 Error_Msg_Name_1
:= File_Name
;
4636 Projects
.Table
(Unit_Prj
.Project
).Name
;
4639 "{ is already a source of project {",
4643 Units
.Increment_Last
;
4644 The_Unit
:= Units
.Last
;
4645 Units_Htable
.Set
(Unit_Name
, The_Unit
);
4646 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4647 Files_Htable
.Set
(Canonical_File_Name
, Unit_Prj
);
4648 The_Unit_Data
.Name
:= Unit_Name
;
4649 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4650 (Name
=> Canonical_File_Name
,
4651 Index
=> Unit_Index
,
4652 Display_Name
=> File_Name
,
4653 Path
=> Canonical_Path_Name
,
4654 Display_Path
=> Path_Name
,
4656 Needs_Pragma
=> Needs_Pragma
);
4657 Units
.Table
(The_Unit
) := The_Unit_Data
;
4658 Source_Recorded
:= True;
4663 exit when Exception_Id
= No_Ada_Naming_Exception
;
4664 File_Name_Recorded
:= True;
4667 end Record_Ada_Source
;
4669 --------------------------
4670 -- Record_Other_Sources --
4671 --------------------------
4673 procedure Record_Other_Sources
4674 (Project
: Project_Id
;
4675 Data
: in out Project_Data
;
4676 Language
: Programming_Language
;
4677 Naming_Exceptions
: Boolean)
4679 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
4680 Element
: String_Element
;
4684 Canonical_Name
: Name_Id
;
4685 Name_Str
: String (1 .. 1_024
);
4686 Last
: Natural := 0;
4689 First_Error
: Boolean := True;
4691 Suffix
: constant String :=
4692 Get_Name_String
(Data
.Impl_Suffixes
(Language
));
4695 while Source_Dir
/= Nil_String
loop
4696 Element
:= String_Elements
.Table
(Source_Dir
);
4699 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
4701 if Current_Verbosity
= High
then
4702 Write_Str
("checking directory """);
4703 Write_Str
(Dir_Path
);
4704 Write_Str
(""" for ");
4706 if Naming_Exceptions
then
4707 Write_Str
("naming exceptions");
4710 Write_Str
("sources");
4713 Write_Str
(" of Language ");
4714 Write_Line
(Lang_Display_Names
(Language
).all);
4717 Open
(Dir
, Dir_Path
);
4720 Read
(Dir
, Name_Str
, Last
);
4724 (Dir_Path
& Directory_Separator
& Name_Str
(1 .. Last
))
4727 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
4728 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4729 Canonical_Name
:= Name_Find
;
4730 NL
:= Source_Names
.Get
(Canonical_Name
);
4732 if NL
/= No_Name_Location
then
4734 if not Data
.Known_Order_Of_Source_Dirs
then
4735 Error_Msg_Name_1
:= Canonical_Name
;
4738 "{ is found in several source directories",
4744 Source_Names
.Set
(Canonical_Name
, NL
);
4745 Name_Len
:= Dir_Path
'Length;
4746 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
4747 Add_Char_To_Name_Buffer
(Directory_Separator
);
4748 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
4752 (File_Name
=> Canonical_Name
,
4756 Location
=> NL
.Location
,
4757 Language
=> Language
,
4759 Naming_Exception
=> Naming_Exceptions
);
4768 Source_Dir
:= Element
.Next
;
4771 if not Naming_Exceptions
then
4773 NL
:= Source_Names
.Get_First
;
4775 -- It is an error if a source file name in a source list or
4776 -- in a source list file is not found.
4778 while NL
/= No_Name_Location
loop
4779 if not NL
.Found
then
4780 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
4785 "source file { cannot be found",
4787 First_Error
:= False;
4792 "\source file { cannot be found",
4797 NL
:= Source_Names
.Get_Next
;
4800 -- Any naming exception of this language that is not in a list
4801 -- of sources must be removed.
4804 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
4805 Prev_Id
: Other_Source_Id
:= No_Other_Source
;
4806 Source
: Other_Source
;
4808 while Source_Id
/= No_Other_Source
loop
4809 Source
:= Other_Sources
.Table
(Source_Id
);
4811 if Source
.Language
= Language
4812 and then Source
.Naming_Exception
4814 if Current_Verbosity
= High
then
4815 Write_Str
("Naming exception """);
4816 Write_Str
(Get_Name_String
(Source
.File_Name
));
4817 Write_Str
(""" is not in the list of sources,");
4818 Write_Line
(" so it is removed.");
4821 if Prev_Id
= No_Other_Source
then
4822 Data
.First_Other_Source
:= Source
.Next
;
4825 Other_Sources
.Table
(Prev_Id
).Next
:= Source
.Next
;
4828 Source_Id
:= Source
.Next
;
4830 if Source_Id
= No_Other_Source
then
4831 Data
.Last_Other_Source
:= Prev_Id
;
4835 Prev_Id
:= Source_Id
;
4836 Source_Id
:= Source
.Next
;
4841 end Record_Other_Sources
;
4843 ----------------------
4844 -- Show_Source_Dirs --
4845 ----------------------
4847 procedure Show_Source_Dirs
(Project
: Project_Id
) is
4848 Current
: String_List_Id
:= Projects
.Table
(Project
).Source_Dirs
;
4849 Element
: String_Element
;
4852 Write_Line
("Source_Dirs:");
4854 while Current
/= Nil_String
loop
4855 Element
:= String_Elements
.Table
(Current
);
4857 Write_Line
(Get_Name_String
(Element
.Value
));
4858 Current
:= Element
.Next
;
4861 Write_Line
("end Source_Dirs.");
4862 end Show_Source_Dirs
;
4869 (Language
: Programming_Language
;
4870 Naming
: Naming_Data
) return Name_Id
4872 Suffix
: constant Variable_Value
:=
4874 (Index
=> Lang_Name_Ids
(Language
),
4876 In_Array
=> Naming
.Body_Suffix
);
4878 -- If no suffix for this language is found in package Naming, use the
4881 if Suffix
= Nil_Variable_Value
then
4883 Add_Str_To_Name_Buffer
(Lang_Suffixes
(Language
).all);
4885 -- Otherwise use the one specified
4888 Get_Name_String
(Suffix
.Value
);
4891 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));