1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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
.Env
; use Prj
.Env
;
37 with Prj
.Util
; use Prj
.Util
;
39 with Snames
; use Snames
;
40 with Table
; use Table
;
42 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
43 with Ada
.Strings
; use Ada
.Strings
;
44 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
45 with Ada
.Strings
.Maps
.Constants
; use Ada
.Strings
.Maps
.Constants
;
47 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
48 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
51 package body Prj
.Nmsc
is
53 Error_Report
: Put_Line_Access
:= null;
54 -- Set to point to error reporting procedure
56 ALI_Suffix
: constant String := ".ali";
57 -- File suffix for ali files
59 Object_Suffix
: constant String := Get_Object_Suffix
.all;
60 -- File suffix for object files
62 type Name_Location
is record
64 Location
: Source_Ptr
;
65 Found
: Boolean := False;
67 -- Information about file names found in string list attribute
68 -- Source_Files or in a source list file, stored in hash table
69 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
71 No_Name_Location
: constant Name_Location
:=
72 (Name
=> No_Name
, Location
=> No_Location
, Found
=> False);
74 package Source_Names
is new GNAT
.HTable
.Simple_HTable
75 (Header_Num
=> Header_Num
,
76 Element
=> Name_Location
,
77 No_Element
=> No_Name_Location
,
81 -- Hash table to store file names found in string list attribute
82 -- Source_Files or in a source list file, stored in hash table
83 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
85 package Recursive_Dirs
is new GNAT
.HTable
.Simple_HTable
86 (Header_Num
=> Header_Num
,
92 -- Hash table to store recursive source directories, to avoid looking
93 -- several times, and to avoid cycles that may be introduced by symbolic
96 type Ada_Naming_Exception_Id
is new Nat
;
97 No_Ada_Naming_Exception
: constant Ada_Naming_Exception_Id
:= 0;
99 type Unit_Info
is record
102 Next
: Ada_Naming_Exception_Id
:= No_Ada_Naming_Exception
;
104 -- No_Unit : constant Unit_Info :=
105 -- (Specification, No_Name, No_Ada_Naming_Exception);
107 package Ada_Naming_Exception_Table
is new Table
.Table
108 (Table_Component_Type
=> Unit_Info
,
109 Table_Index_Type
=> Ada_Naming_Exception_Id
,
110 Table_Low_Bound
=> 1,
112 Table_Increment
=> 100,
113 Table_Name
=> "Prj.Nmsc.Ada_Naming_Exception_Table");
115 package Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
116 (Header_Num
=> Header_Num
,
117 Element
=> Ada_Naming_Exception_Id
,
118 No_Element
=> No_Ada_Naming_Exception
,
122 -- A hash table to store naming exceptions for Ada. For each file name
123 -- there is one or several unit in table Ada_Naming_Exception_Table.
125 function Hash
(Unit
: Unit_Info
) return Header_Num
;
127 type Name_And_Index
is record
128 Name
: Name_Id
:= No_Name
;
131 No_Name_And_Index
: constant Name_And_Index
:=
132 (Name
=> No_Name
, Index
=> 0);
134 package Reverse_Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
135 (Header_Num
=> Header_Num
,
136 Element
=> Name_And_Index
,
137 No_Element
=> No_Name_And_Index
,
141 -- A table to check if a unit with an exceptional name will hide
142 -- a source with a file name following the naming convention.
144 function ALI_File_Name
(Source
: String) return String;
145 -- Return the ALI file name corresponding to a source
147 procedure Check_Ada_Name
(Name
: String; Unit
: out Name_Id
);
148 -- Check that a name is a valid Ada unit name
150 procedure Check_Naming_Scheme
151 (Data
: in out Project_Data
;
152 Project
: Project_Id
;
153 In_Tree
: Project_Tree_Ref
);
154 -- Check the naming scheme part of Data
156 procedure Check_Ada_Naming_Scheme_Validity
157 (Project
: Project_Id
;
158 In_Tree
: Project_Tree_Ref
;
159 Naming
: Naming_Data
);
160 -- Check that the package Naming is correct
162 procedure Check_For_Source
163 (File_Name
: Name_Id
;
165 Project
: Project_Id
;
166 In_Tree
: Project_Tree_Ref
;
167 Data
: in out Project_Data
;
168 Location
: Source_Ptr
;
169 Language
: Language_Index
;
171 Naming_Exception
: Boolean);
172 -- Check if a file, with name File_Name and path Path_Name, in a source
173 -- directory is a source for language Language in project Project of
174 -- project tree In_Tree. ???
176 procedure Check_If_Externally_Built
177 (Project
: Project_Id
;
178 In_Tree
: Project_Tree_Ref
;
179 Data
: in out Project_Data
);
180 -- Check attribute Externally_Built of project Project in project tree
181 -- In_Tree and modify its data Data if it has the value "true".
183 procedure Check_Library_Attributes
184 (Project
: Project_Id
;
185 In_Tree
: Project_Tree_Ref
;
186 Data
: in out Project_Data
);
187 -- Check the library attributes of project Project in project tree In_Tree
188 -- and modify its data Data accordingly.
190 procedure Check_Package_Naming
191 (Project
: Project_Id
;
192 In_Tree
: Project_Tree_Ref
;
193 Data
: in out Project_Data
);
194 -- Check package Naming of project Project in project tree In_Tree and
195 -- modify its data Data accordingly.
197 procedure Check_Programming_Languages
198 (In_Tree
: Project_Tree_Ref
; Data
: in out Project_Data
);
199 -- Check attribute Languages for the project with data Data in project
200 -- tree In_Tree and set the components of Data for all the programming
201 -- languages indicated in attribute Languages, if any.
203 function Check_Project
205 Root_Project
: Project_Id
;
206 In_Tree
: Project_Tree_Ref
;
207 Extending
: Boolean) return Boolean;
208 -- Returns True if P is Root_Project or, if Extending is True, a project
209 -- extended by Root_Project.
211 procedure Check_Stand_Alone_Library
212 (Project
: Project_Id
;
213 In_Tree
: Project_Tree_Ref
;
214 Data
: in out Project_Data
;
215 Extending
: Boolean);
216 -- Check if project Project in project tree In_Tree is a Stand-Alone
217 -- Library project, and modify its data Data accordingly if it is one.
219 function Compute_Directory_Last
(Dir
: String) return Natural;
220 -- Return the index of the last significant character in Dir. This is used
221 -- to avoid duplicates '/' at the end of directory names
223 function Body_Suffix_Of
224 (Language
: Language_Index
;
225 In_Project
: Project_Data
;
226 In_Tree
: Project_Tree_Ref
)
228 -- Returns the suffix of sources of language Language in project In_Project
229 -- in project tree In_Tree.
232 (Project
: Project_Id
;
233 In_Tree
: Project_Tree_Ref
;
235 Flag_Location
: Source_Ptr
);
236 -- Output an error message. If Error_Report is null, simply call
237 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
240 procedure Find_Sources
241 (Project
: Project_Id
;
242 In_Tree
: Project_Tree_Ref
;
243 Data
: in out Project_Data
;
244 For_Language
: Language_Index
;
245 Follow_Links
: Boolean := False);
246 -- Find all the sources in all of the source directories of a project for
247 -- a specified language.
249 procedure Free_Ada_Naming_Exceptions
;
250 -- Free the internal hash tables used for checking naming exceptions
252 procedure Get_Directories
253 (Project
: Project_Id
;
254 In_Tree
: Project_Tree_Ref
;
255 Data
: in out Project_Data
);
256 -- Get the object directory, the exec directory and the source directories
260 (Project
: Project_Id
;
261 In_Tree
: Project_Tree_Ref
;
262 Data
: in out Project_Data
);
263 -- Get the mains of a project from attribute Main, if it exists, and put
264 -- them in the project data.
266 procedure Get_Sources_From_File
268 Location
: Source_Ptr
;
269 Project
: Project_Id
;
270 In_Tree
: Project_Tree_Ref
);
271 -- Get the list of sources from a text file and put them in hash table
275 (Canonical_File_Name
: Name_Id
;
276 Naming
: Naming_Data
;
277 Exception_Id
: out Ada_Naming_Exception_Id
;
278 Unit_Name
: out Name_Id
;
279 Unit_Kind
: out Spec_Or_Body
;
280 Needs_Pragma
: out Boolean);
281 -- Find out, from a file name, the unit name, the unit kind and if a
282 -- specific SFN pragma is needed. If the file name corresponds to no
283 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
284 -- or an exception to the naming scheme, then Exception_Id is set to
285 -- the unit or units that the source contains.
287 function Is_Illegal_Suffix
289 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean;
290 -- Returns True if the string Suffix cannot be used as
291 -- a spec suffix, a body suffix or a separate suffix.
293 procedure Locate_Directory
297 Display
: out Name_Id
);
298 -- Locate a directory (returns No_Name for Dir and Display if directory
299 -- does not exist). Name is the directory name. Parent is the root
300 -- directory, if Name is a relative path name. Dir is the canonical case
301 -- path name of the directory, Display is the directory path name for
304 procedure Look_For_Sources
305 (Project
: Project_Id
;
306 In_Tree
: Project_Tree_Ref
;
307 Data
: in out Project_Data
;
308 Follow_Links
: Boolean);
309 -- Find all the sources of a project
311 function Path_Name_Of
312 (File_Name
: Name_Id
;
313 Directory
: Name_Id
) return String;
314 -- Returns the path name of a (non project) file.
315 -- Returns an empty string if file cannot be found.
317 procedure Prepare_Ada_Naming_Exceptions
318 (List
: Array_Element_Id
;
319 In_Tree
: Project_Tree_Ref
;
320 Kind
: Spec_Or_Body
);
321 -- Prepare the internal hash tables used for checking naming exceptions
322 -- for Ada. Insert all elements of List in the tables.
324 function Project_Extends
325 (Extending
: Project_Id
;
326 Extended
: Project_Id
;
327 In_Tree
: Project_Tree_Ref
) return Boolean;
328 -- Returns True if Extending is extending Extended either directly or
331 procedure Record_Ada_Source
332 (File_Name
: Name_Id
;
334 Project
: Project_Id
;
335 In_Tree
: Project_Tree_Ref
;
336 Data
: in out Project_Data
;
337 Location
: Source_Ptr
;
338 Current_Source
: in out String_List_Id
;
339 Source_Recorded
: in out Boolean;
340 Follow_Links
: Boolean);
341 -- Put a unit in the list of units of a project, if the file name
342 -- corresponds to a valid unit name.
344 procedure Record_Other_Sources
345 (Project
: Project_Id
;
346 In_Tree
: Project_Tree_Ref
;
347 Data
: in out Project_Data
;
348 Language
: Language_Index
;
349 Naming_Exceptions
: Boolean);
350 -- Record the sources of a language in a project.
351 -- When Naming_Exceptions is True, mark the found sources as such, to
352 -- later remove those that are not named in a list of sources.
354 procedure Show_Source_Dirs
355 (Project
: Project_Id
; In_Tree
: Project_Tree_Ref
);
356 -- List all the source directories of a project
359 (Language
: Language_Index
;
360 Naming
: Naming_Data
;
361 In_Tree
: Project_Tree_Ref
) return Name_Id
;
362 -- Get the suffix for the source of a language from a package naming.
363 -- If not specified, return the default for the language.
365 procedure Warn_If_Not_Sources
366 (Project
: Project_Id
;
367 In_Tree
: Project_Tree_Ref
;
368 Conventions
: Array_Element_Id
;
370 Extending
: Boolean);
371 -- Check that individual naming conventions apply to immediate
372 -- sources of the project; if not, issue a warning.
378 function ALI_File_Name
(Source
: String) return String is
380 -- If the source name has an extension, then replace it with
383 for Index
in reverse Source
'First + 1 .. Source
'Last loop
384 if Source
(Index
) = '.' then
385 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
389 -- If there is no dot, or if it is the first character, just add the
392 return Source
& ALI_Suffix
;
400 (Project
: Project_Id
;
401 In_Tree
: Project_Tree_Ref
;
402 Report_Error
: Put_Line_Access
;
403 Follow_Links
: Boolean)
405 Data
: Project_Data
:= In_Tree
.Projects
.Table
(Project
);
406 Extending
: Boolean := False;
409 Error_Report
:= Report_Error
;
411 Recursive_Dirs
.Reset
;
413 -- Object, exec and source directories
415 Get_Directories
(Project
, In_Tree
, Data
);
417 -- Get the programming languages
419 Check_Programming_Languages
(In_Tree
, Data
);
421 -- Library attributes
423 Check_Library_Attributes
(Project
, In_Tree
, Data
);
425 Check_If_Externally_Built
(Project
, In_Tree
, Data
);
427 if Current_Verbosity
= High
then
428 Show_Source_Dirs
(Project
, In_Tree
);
431 Check_Package_Naming
(Project
, In_Tree
, Data
);
433 Extending
:= Data
.Extends
/= No_Project
;
435 Check_Naming_Scheme
(Data
, Project
, In_Tree
);
437 Prepare_Ada_Naming_Exceptions
438 (Data
.Naming
.Bodies
, In_Tree
, Body_Part
);
439 Prepare_Ada_Naming_Exceptions
440 (Data
.Naming
.Specs
, In_Tree
, Specification
);
444 if Data
.Source_Dirs
/= Nil_String
then
445 Look_For_Sources
(Project
, In_Tree
, Data
, Follow_Links
);
448 if Data
.Ada_Sources_Present
then
450 -- Check that all individual naming conventions apply to sources of
451 -- this project file.
454 (Project
, In_Tree
, Data
.Naming
.Bodies
,
456 Extending
=> Extending
);
458 (Project
, In_Tree
, Data
.Naming
.Specs
,
460 Extending
=> Extending
);
463 -- If it is a library project file, check if it is a standalone library
466 Check_Stand_Alone_Library
(Project
, In_Tree
, Data
, Extending
);
469 -- Put the list of Mains, if any, in the project data
471 Get_Mains
(Project
, In_Tree
, Data
);
473 -- Update the project data in the Projects table
475 In_Tree
.Projects
.Table
(Project
) := Data
;
477 Free_Ada_Naming_Exceptions
;
484 procedure Check_Ada_Name
(Name
: String; Unit
: out Name_Id
) is
485 The_Name
: String := Name
;
487 Need_Letter
: Boolean := True;
488 Last_Underscore
: Boolean := False;
489 OK
: Boolean := The_Name
'Length > 0;
494 Name_Len
:= The_Name
'Length;
495 Name_Buffer
(1 .. Name_Len
) := The_Name
;
496 Real_Name
:= Name_Find
;
498 -- Check first that the given name is not an Ada reserved word
500 if Get_Name_Table_Byte
(Real_Name
) /= 0
501 and then Real_Name
/= Name_Project
502 and then Real_Name
/= Name_Extends
503 and then Real_Name
/= Name_External
507 if Current_Verbosity
= High
then
508 Write_Str
(The_Name
);
509 Write_Line
(" is an Ada reserved word.");
515 for Index
in The_Name
'Range loop
518 -- We need a letter (at the beginning, and following a dot),
519 -- but we don't have one.
521 if Is_Letter
(The_Name
(Index
)) then
522 Need_Letter
:= False;
527 if Current_Verbosity
= High
then
528 Write_Int
(Types
.Int
(Index
));
530 Write_Char
(The_Name
(Index
));
531 Write_Line
("' is not a letter.");
537 elsif Last_Underscore
538 and then (The_Name
(Index
) = '_' or else The_Name
(Index
) = '.')
540 -- Two underscores are illegal, and a dot cannot follow
545 if Current_Verbosity
= High
then
546 Write_Int
(Types
.Int
(Index
));
548 Write_Char
(The_Name
(Index
));
549 Write_Line
("' is illegal here.");
554 elsif The_Name
(Index
) = '.' then
556 -- We need a letter after a dot
560 elsif The_Name
(Index
) = '_' then
561 Last_Underscore
:= True;
564 -- We need an letter or a digit
566 Last_Underscore
:= False;
568 if not Is_Alphanumeric
(The_Name
(Index
)) then
571 if Current_Verbosity
= High
then
572 Write_Int
(Types
.Int
(Index
));
574 Write_Char
(The_Name
(Index
));
575 Write_Line
("' is not alphanumeric.");
583 -- Cannot end with an underscore or a dot
585 OK
:= OK
and then not Need_Letter
and then not Last_Underscore
;
591 -- Signal a problem with No_Name
597 --------------------------------------
598 -- Check_Ada_Naming_Scheme_Validity --
599 --------------------------------------
601 procedure Check_Ada_Naming_Scheme_Validity
602 (Project
: Project_Id
;
603 In_Tree
: Project_Tree_Ref
;
604 Naming
: Naming_Data
)
607 -- Only check if we are not using the Default naming scheme
609 if Naming
/= In_Tree
.Private_Part
.Default_Naming
then
611 Dot_Replacement
: constant String :=
613 (Naming
.Dot_Replacement
);
615 Spec_Suffix
: constant String :=
617 (Naming
.Ada_Spec_Suffix
);
619 Body_Suffix
: constant String :=
621 (Naming
.Ada_Body_Suffix
);
623 Separate_Suffix
: constant String :=
625 (Naming
.Separate_Suffix
);
628 -- Dot_Replacement cannot
630 -- - start or end with an alphanumeric
632 -- - start with an '_' followed by an alphanumeric
633 -- - contain a '.' except if it is "."
635 if Dot_Replacement
'Length = 0
636 or else Is_Alphanumeric
637 (Dot_Replacement
(Dot_Replacement
'First))
638 or else Is_Alphanumeric
639 (Dot_Replacement
(Dot_Replacement
'Last))
640 or else (Dot_Replacement
(Dot_Replacement
'First) = '_'
642 (Dot_Replacement
'Length = 1
645 (Dot_Replacement
(Dot_Replacement
'First + 1))))
646 or else (Dot_Replacement
'Length > 1
648 Index
(Source
=> Dot_Replacement
,
649 Pattern
=> ".") /= 0)
653 '"' & Dot_Replacement
&
654 """ is illegal for Dot_Replacement.",
655 Naming
.Dot_Repl_Loc
);
662 (Spec_Suffix
, Dot_Replacement
= ".")
664 Err_Vars
.Error_Msg_Name_1
:= Naming
.Ada_Spec_Suffix
;
667 "{ is illegal for Spec_Suffix",
668 Naming
.Spec_Suffix_Loc
);
672 (Body_Suffix
, Dot_Replacement
= ".")
674 Err_Vars
.Error_Msg_Name_1
:= Naming
.Ada_Body_Suffix
;
677 "{ is illegal for Body_Suffix",
678 Naming
.Body_Suffix_Loc
);
681 if Body_Suffix
/= Separate_Suffix
then
683 (Separate_Suffix
, Dot_Replacement
= ".")
685 Err_Vars
.Error_Msg_Name_1
:= Naming
.Separate_Suffix
;
688 "{ is illegal for Separate_Suffix",
689 Naming
.Sep_Suffix_Loc
);
693 -- Spec_Suffix cannot have the same termination as
694 -- Body_Suffix or Separate_Suffix
696 if Spec_Suffix
'Length <= Body_Suffix
'Length
698 Body_Suffix
(Body_Suffix
'Last -
699 Spec_Suffix
'Length + 1 ..
700 Body_Suffix
'Last) = Spec_Suffix
706 """) cannot end with" &
708 Spec_Suffix
& """).",
709 Naming
.Body_Suffix_Loc
);
712 if Body_Suffix
/= Separate_Suffix
713 and then Spec_Suffix
'Length <= Separate_Suffix
'Length
716 (Separate_Suffix
'Last - Spec_Suffix
'Length + 1
718 Separate_Suffix
'Last) = Spec_Suffix
722 "Separate_Suffix (""" &
724 """) cannot end with" &
726 Spec_Suffix
& """).",
727 Naming
.Sep_Suffix_Loc
);
731 end Check_Ada_Naming_Scheme_Validity
;
733 ----------------------
734 -- Check_For_Source --
735 ----------------------
737 procedure Check_For_Source
738 (File_Name
: Name_Id
;
740 Project
: Project_Id
;
741 In_Tree
: Project_Tree_Ref
;
742 Data
: in out Project_Data
;
743 Location
: Source_Ptr
;
744 Language
: Language_Index
;
746 Naming_Exception
: Boolean)
748 Name
: String := Get_Name_String
(File_Name
);
749 Real_Location
: Source_Ptr
:= Location
;
752 Canonical_Case_File_Name
(Name
);
754 -- A file is a source of a language if Naming_Exception is True (case
755 -- of naming exceptions) or if its file name ends with the suffix.
757 if Naming_Exception
or else
758 (Name
'Length > Suffix
'Length and then
759 Name
(Name
'Last - Suffix
'Length + 1 .. Name
'Last) = Suffix
)
761 if Real_Location
= No_Location
then
762 Real_Location
:= Data
.Location
;
766 Path
: String := Get_Name_String
(Path_Name
);
769 -- The path name id (in canonical case)
772 -- The file name id (in canonical case)
775 -- The object file name
777 Obj_Path_Id
: Name_Id
;
778 -- The object path name
781 -- The dependency file name
783 Dep_Path_Id
: Name_Id
;
784 -- The dependency path name
786 Dot_Pos
: Natural := 0;
787 -- Position of the last dot in Name
789 Source
: Other_Source
;
790 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
793 Canonical_Case_File_Name
(Path
);
795 -- Get the file name id
797 Name_Len
:= Name
'Length;
798 Name_Buffer
(1 .. Name_Len
) := Name
;
799 File_Id
:= Name_Find
;
801 -- Get the path name id
803 Name_Len
:= Path
'Length;
804 Name_Buffer
(1 .. Name_Len
) := Path
;
805 Path_Id
:= Name_Find
;
807 -- Find the position of the last dot
809 for J
in reverse Name
'Range loop
810 if Name
(J
) = '.' then
816 if Dot_Pos
<= Name
'First then
817 Dot_Pos
:= Name
'Last + 1;
820 -- Compute the object file name
822 Get_Name_String
(File_Id
);
823 Name_Len
:= Dot_Pos
- Name
'First;
825 for J
in Object_Suffix
'Range loop
826 Name_Len
:= Name_Len
+ 1;
827 Name_Buffer
(Name_Len
) := Object_Suffix
(J
);
832 -- Compute the object path name
834 Get_Name_String
(Data
.Object_Directory
);
836 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
837 Name_Buffer
(Name_Len
) /= '/'
839 Name_Len
:= Name_Len
+ 1;
840 Name_Buffer
(Name_Len
) := Directory_Separator
;
843 Add_Str_To_Name_Buffer
(Get_Name_String
(Obj_Id
));
844 Obj_Path_Id
:= Name_Find
;
846 -- Compute the dependency file name
848 Get_Name_String
(File_Id
);
849 Name_Len
:= Dot_Pos
- Name
'First + 1;
850 Name_Buffer
(Name_Len
) := '.';
851 Name_Len
:= Name_Len
+ 1;
852 Name_Buffer
(Name_Len
) := 'd';
855 -- Compute the dependency path name
857 Get_Name_String
(Data
.Object_Directory
);
859 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
860 Name_Buffer
(Name_Len
) /= '/'
862 Name_Len
:= Name_Len
+ 1;
863 Name_Buffer
(Name_Len
) := Directory_Separator
;
866 Add_Str_To_Name_Buffer
(Get_Name_String
(Dep_Id
));
867 Dep_Path_Id
:= Name_Find
;
869 -- Check if source is already in the list of source for this
870 -- project: it may have already been specified as a naming
871 -- exception for the same language or an other language, or
872 -- they may be two identical file names in different source
875 while Source_Id
/= No_Other_Source
loop
876 Source
:= In_Tree
.Other_Sources
.Table
(Source_Id
);
878 if Source
.File_Name
= File_Id
then
880 -- Two sources of different languages cannot have the same
883 if Source
.Language
/= Language
then
884 Error_Msg_Name_1
:= File_Name
;
887 "{ cannot be a source of several languages",
891 -- No problem if a file has already been specified as
892 -- a naming exception of this language.
894 elsif Source
.Path_Name
= Path_Id
then
896 -- Reset the naming exception flag, if this is not a
899 if not Naming_Exception
then
900 In_Tree
.Other_Sources
.Table
901 (Source_Id
).Naming_Exception
:= False;
906 -- There are several files with the same names, but the
907 -- order of the source directories is known (no /**):
908 -- only the first one encountered is kept, the other ones
911 elsif Data
.Known_Order_Of_Source_Dirs
then
914 -- But it is an error if the order of the source directories
918 Error_Msg_Name_1
:= File_Name
;
921 "{ is found in several source directories",
926 -- Two sources with different file names cannot have the same
929 elsif Source
.Object_Name
= Obj_Id
then
930 Error_Msg_Name_1
:= File_Id
;
931 Error_Msg_Name_2
:= Source
.File_Name
;
932 Error_Msg_Name_3
:= Obj_Id
;
935 "{ and { have the same object file {",
940 Source_Id
:= Source
.Next
;
943 if Current_Verbosity
= High
then
944 Write_Str
(" found ");
945 Display_Language_Name
(Language
);
946 Write_Str
(" source """);
947 Write_Str
(Get_Name_String
(File_Name
));
949 Write_Str
(" object path = ");
950 Write_Line
(Get_Name_String
(Obj_Path_Id
));
953 -- Create the Other_Source record
956 (Language
=> Language
,
957 File_Name
=> File_Id
,
958 Path_Name
=> Path_Id
,
959 Source_TS
=> File_Stamp
(Path_Id
),
960 Object_Name
=> Obj_Id
,
961 Object_Path
=> Obj_Path_Id
,
962 Object_TS
=> File_Stamp
(Obj_Path_Id
),
964 Dep_Path
=> Dep_Path_Id
,
965 Dep_TS
=> File_Stamp
(Dep_Path_Id
),
966 Naming_Exception
=> Naming_Exception
,
967 Next
=> No_Other_Source
);
969 -- And add it to the Other_Sources table
971 Other_Source_Table
.Increment_Last
972 (In_Tree
.Other_Sources
);
973 In_Tree
.Other_Sources
.Table
974 (Other_Source_Table
.Last
(In_Tree
.Other_Sources
)) :=
977 -- There are sources of languages other than Ada in this project
979 Data
.Other_Sources_Present
:= True;
981 -- And there are sources of this language in this project
983 Set
(Language
, True, Data
, In_Tree
);
985 -- Add this source to the list of sources of languages other than
986 -- Ada of the project.
988 if Data
.First_Other_Source
= No_Other_Source
then
989 Data
.First_Other_Source
:=
990 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
993 In_Tree
.Other_Sources
.Table
(Data
.Last_Other_Source
).Next
:=
994 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
997 Data
.Last_Other_Source
:=
998 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
1001 end Check_For_Source
;
1003 -------------------------------
1004 -- Check_If_Externally_Built --
1005 -------------------------------
1007 procedure Check_If_Externally_Built
1008 (Project
: Project_Id
;
1009 In_Tree
: Project_Tree_Ref
;
1010 Data
: in out Project_Data
)
1012 Externally_Built
: constant Variable_Value
:=
1014 (Name_Externally_Built
,
1015 Data
.Decl
.Attributes
, In_Tree
);
1018 if not Externally_Built
.Default
then
1019 Get_Name_String
(Externally_Built
.Value
);
1020 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1022 if Name_Buffer
(1 .. Name_Len
) = "true" then
1023 Data
.Externally_Built
:= True;
1025 elsif Name_Buffer
(1 .. Name_Len
) /= "false" then
1026 Error_Msg
(Project
, In_Tree
,
1027 "Externally_Built may only be true or false",
1028 Externally_Built
.Location
);
1032 if Current_Verbosity
= High
then
1033 Write_Str
("Project is ");
1035 if not Data
.Externally_Built
then
1039 Write_Line
("externally built.");
1041 end Check_If_Externally_Built
;
1043 -----------------------------
1044 -- Check_Naming_Scheme --
1045 -----------------------------
1047 procedure Check_Naming_Scheme
1048 (Data
: in out Project_Data
;
1049 Project
: Project_Id
;
1050 In_Tree
: Project_Tree_Ref
)
1052 Naming_Id
: constant Package_Id
:=
1053 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
, In_Tree
);
1055 Naming
: Package_Element
;
1057 procedure Check_Unit_Names
(List
: Array_Element_Id
);
1058 -- Check that a list of unit names contains only valid names
1060 ----------------------
1061 -- Check_Unit_Names --
1062 ----------------------
1064 procedure Check_Unit_Names
(List
: Array_Element_Id
) is
1065 Current
: Array_Element_Id
:= List
;
1066 Element
: Array_Element
;
1067 Unit_Name
: Name_Id
;
1070 -- Loop through elements of the string list
1072 while Current
/= No_Array_Element
loop
1073 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1075 -- Put file name in canonical case
1077 Get_Name_String
(Element
.Value
.Value
);
1078 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1079 Element
.Value
.Value
:= Name_Find
;
1081 -- Check that it contains a valid unit name
1083 Get_Name_String
(Element
.Index
);
1084 Check_Ada_Name
(Name_Buffer
(1 .. Name_Len
), Unit_Name
);
1086 if Unit_Name
= No_Name
then
1087 Err_Vars
.Error_Msg_Name_1
:= Element
.Index
;
1090 "{ is not a valid unit name.",
1091 Element
.Value
.Location
);
1094 if Current_Verbosity
= High
then
1095 Write_Str
(" Unit (""");
1096 Write_Str
(Get_Name_String
(Unit_Name
));
1100 Element
.Index
:= Unit_Name
;
1101 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1104 Current
:= Element
.Next
;
1106 end Check_Unit_Names
;
1108 -- Start of processing for Check_Naming_Scheme
1111 -- If there is a package Naming, we will put in Data.Naming what is in
1112 -- this package Naming.
1114 if Naming_Id
/= No_Package
then
1115 Naming
:= In_Tree
.Packages
.Table
(Naming_Id
);
1117 if Current_Verbosity
= High
then
1118 Write_Line
("Checking ""Naming"" for Ada.");
1122 Bodies
: constant Array_Element_Id
:=
1123 Util
.Value_Of
(Name_Body
, Naming
.Decl
.Arrays
, In_Tree
);
1125 Specs
: constant Array_Element_Id
:=
1126 Util
.Value_Of
(Name_Spec
, Naming
.Decl
.Arrays
, In_Tree
);
1129 if Bodies
/= No_Array_Element
then
1131 -- We have elements in the array Body_Part
1133 if Current_Verbosity
= High
then
1134 Write_Line
("Found Bodies.");
1137 Data
.Naming
.Bodies
:= Bodies
;
1138 Check_Unit_Names
(Bodies
);
1141 if Current_Verbosity
= High
then
1142 Write_Line
("No Bodies.");
1146 if Specs
/= No_Array_Element
then
1148 -- We have elements in the array Specs
1150 if Current_Verbosity
= High
then
1151 Write_Line
("Found Specs.");
1154 Data
.Naming
.Specs
:= Specs
;
1155 Check_Unit_Names
(Specs
);
1158 if Current_Verbosity
= High
then
1159 Write_Line
("No Specs.");
1164 -- We are now checking if variables Dot_Replacement, Casing,
1165 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1168 -- For each variable, if it does not exist, we do nothing,
1169 -- because we already have the default.
1171 -- Check Dot_Replacement
1174 Dot_Replacement
: constant Variable_Value
:=
1176 (Name_Dot_Replacement
,
1177 Naming
.Decl
.Attributes
, In_Tree
);
1180 pragma Assert
(Dot_Replacement
.Kind
= Single
,
1181 "Dot_Replacement is not a single string");
1183 if not Dot_Replacement
.Default
then
1184 Get_Name_String
(Dot_Replacement
.Value
);
1186 if Name_Len
= 0 then
1189 "Dot_Replacement cannot be empty",
1190 Dot_Replacement
.Location
);
1193 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1194 Data
.Naming
.Dot_Replacement
:= Name_Find
;
1195 Data
.Naming
.Dot_Repl_Loc
:= Dot_Replacement
.Location
;
1200 if Current_Verbosity
= High
then
1201 Write_Str
(" Dot_Replacement = """);
1202 Write_Str
(Get_Name_String
(Data
.Naming
.Dot_Replacement
));
1210 Casing_String
: constant Variable_Value
:=
1212 (Name_Casing
, Naming
.Decl
.Attributes
, In_Tree
);
1215 pragma Assert
(Casing_String
.Kind
= Single
,
1216 "Casing is not a single string");
1218 if not Casing_String
.Default
then
1220 Casing_Image
: constant String :=
1221 Get_Name_String
(Casing_String
.Value
);
1224 Casing_Value
: constant Casing_Type
:=
1225 Value
(Casing_Image
);
1227 Data
.Naming
.Casing
:= Casing_Value
;
1231 when Constraint_Error
=>
1232 if Casing_Image
'Length = 0 then
1235 "Casing cannot be an empty string",
1236 Casing_String
.Location
);
1239 Name_Len
:= Casing_Image
'Length;
1240 Name_Buffer
(1 .. Name_Len
) := Casing_Image
;
1241 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
1244 "{ is not a correct Casing",
1245 Casing_String
.Location
);
1251 if Current_Verbosity
= High
then
1252 Write_Str
(" Casing = ");
1253 Write_Str
(Image
(Data
.Naming
.Casing
));
1258 -- Check Spec_Suffix
1261 Ada_Spec_Suffix
: constant Variable_Value
:=
1265 In_Array
=> Data
.Naming
.Spec_Suffix
,
1266 In_Tree
=> In_Tree
);
1269 if Ada_Spec_Suffix
.Kind
= Single
1270 and then Get_Name_String
(Ada_Spec_Suffix
.Value
) /= ""
1272 Get_Name_String
(Ada_Spec_Suffix
.Value
);
1273 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1274 Data
.Naming
.Ada_Spec_Suffix
:= Name_Find
;
1275 Data
.Naming
.Spec_Suffix_Loc
:= Ada_Spec_Suffix
.Location
;
1278 Data
.Naming
.Ada_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
1282 if Current_Verbosity
= High
then
1283 Write_Str
(" Spec_Suffix = """);
1284 Write_Str
(Get_Name_String
(Data
.Naming
.Ada_Spec_Suffix
));
1289 -- Check Body_Suffix
1292 Ada_Body_Suffix
: constant Variable_Value
:=
1296 In_Array
=> Data
.Naming
.Body_Suffix
,
1297 In_Tree
=> In_Tree
);
1300 if Ada_Body_Suffix
.Kind
= Single
1301 and then Get_Name_String
(Ada_Body_Suffix
.Value
) /= ""
1303 Get_Name_String
(Ada_Body_Suffix
.Value
);
1304 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1305 Data
.Naming
.Ada_Body_Suffix
:= Name_Find
;
1306 Data
.Naming
.Body_Suffix_Loc
:= Ada_Body_Suffix
.Location
;
1309 Data
.Naming
.Ada_Body_Suffix
:= Default_Ada_Body_Suffix
;
1313 if Current_Verbosity
= High
then
1314 Write_Str
(" Body_Suffix = """);
1315 Write_Str
(Get_Name_String
(Data
.Naming
.Ada_Body_Suffix
));
1320 -- Check Separate_Suffix
1323 Ada_Sep_Suffix
: constant Variable_Value
:=
1325 (Variable_Name
=> Name_Separate_Suffix
,
1326 In_Variables
=> Naming
.Decl
.Attributes
,
1327 In_Tree
=> In_Tree
);
1330 if Ada_Sep_Suffix
.Default
then
1331 Data
.Naming
.Separate_Suffix
:=
1332 Data
.Naming
.Ada_Body_Suffix
;
1335 Get_Name_String
(Ada_Sep_Suffix
.Value
);
1337 if Name_Len
= 0 then
1340 "Separate_Suffix cannot be empty",
1341 Ada_Sep_Suffix
.Location
);
1344 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1345 Data
.Naming
.Separate_Suffix
:= Name_Find
;
1346 Data
.Naming
.Sep_Suffix_Loc
:= Ada_Sep_Suffix
.Location
;
1351 if Current_Verbosity
= High
then
1352 Write_Str
(" Separate_Suffix = """);
1353 Write_Str
(Get_Name_String
(Data
.Naming
.Separate_Suffix
));
1358 -- Check if Data.Naming is valid
1360 Check_Ada_Naming_Scheme_Validity
(Project
, In_Tree
, Data
.Naming
);
1363 Data
.Naming
.Ada_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
1364 Data
.Naming
.Ada_Body_Suffix
:= Default_Ada_Body_Suffix
;
1365 Data
.Naming
.Separate_Suffix
:= Default_Ada_Body_Suffix
;
1367 end Check_Naming_Scheme
;
1369 ------------------------------
1370 -- Check_Library_Attributes --
1371 ------------------------------
1373 procedure Check_Library_Attributes
1374 (Project
: Project_Id
;
1375 In_Tree
: Project_Tree_Ref
;
1376 Data
: in out Project_Data
)
1378 Attributes
: constant Prj
.Variable_Id
:= Data
.Decl
.Attributes
;
1380 Lib_Dir
: constant Prj
.Variable_Value
:=
1382 (Snames
.Name_Library_Dir
, Attributes
, In_Tree
);
1384 Lib_Name
: constant Prj
.Variable_Value
:=
1386 (Snames
.Name_Library_Name
, Attributes
, In_Tree
);
1388 Lib_Version
: constant Prj
.Variable_Value
:=
1390 (Snames
.Name_Library_Version
, Attributes
, In_Tree
);
1392 The_Lib_Kind
: constant Prj
.Variable_Value
:=
1394 (Snames
.Name_Library_Kind
, Attributes
, In_Tree
);
1397 -- Special case of extending project
1399 if Data
.Extends
/= No_Project
then
1401 Extended_Data
: constant Project_Data
:=
1402 In_Tree
.Projects
.Table
(Data
.Extends
);
1405 -- If the project extended is a library project, we inherit
1406 -- the library name, if it is not redefined; we check that
1407 -- the library directory is specified; and we reset the
1408 -- library flag for the extended project.
1410 if Extended_Data
.Library
then
1411 if Lib_Name
.Default
then
1412 Data
.Library_Name
:= Extended_Data
.Library_Name
;
1415 if Lib_Dir
.Default
then
1416 if not Data
.Virtual
then
1419 "a project extending a library project must " &
1420 "specify an attribute Library_Dir",
1425 In_Tree
.Projects
.Table
(Data
.Extends
).Library
:=
1431 pragma Assert
(Lib_Dir
.Kind
= Single
);
1433 if Lib_Dir
.Value
= Empty_String
then
1434 if Current_Verbosity
= High
then
1435 Write_Line
("No library directory");
1439 -- Find path name, check that it is a directory
1442 (Lib_Dir
.Value
, Data
.Display_Directory
,
1443 Data
.Library_Dir
, Data
.Display_Library_Dir
);
1445 if Data
.Library_Dir
= No_Name
then
1447 -- Get the absolute name of the library directory that
1448 -- does not exist, to report an error.
1451 Dir_Name
: constant String := Get_Name_String
(Lib_Dir
.Value
);
1454 if Is_Absolute_Path
(Dir_Name
) then
1455 Err_Vars
.Error_Msg_Name_1
:= Lib_Dir
.Value
;
1458 Get_Name_String
(Data
.Display_Directory
);
1460 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
1461 Name_Len
:= Name_Len
+ 1;
1462 Name_Buffer
(Name_Len
) := Directory_Separator
;
1466 (Name_Len
+ 1 .. Name_Len
+ Dir_Name
'Length) :=
1468 Name_Len
:= Name_Len
+ Dir_Name
'Length;
1469 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
1476 "library directory { does not exist",
1480 -- The library directory cannot be the same as the Object directory
1482 elsif Data
.Library_Dir
= Data
.Object_Directory
then
1485 "library directory cannot be the same " &
1486 "as object directory",
1488 Data
.Library_Dir
:= No_Name
;
1489 Data
.Display_Library_Dir
:= No_Name
;
1491 -- Display the Library directory in high verbosity
1494 if Current_Verbosity
= High
then
1495 Write_Str
("Library directory =""");
1496 Write_Str
(Get_Name_String
(Data
.Display_Library_Dir
));
1502 pragma Assert
(Lib_Name
.Kind
= Single
);
1504 if Lib_Name
.Value
= Empty_String
then
1505 if Current_Verbosity
= High
1506 and then Data
.Library_Name
= No_Name
1508 Write_Line
("No library name");
1512 -- There is no restriction on the syntax of library names
1514 Data
.Library_Name
:= Lib_Name
.Value
;
1517 if Data
.Library_Name
/= No_Name
1518 and then Current_Verbosity
= High
1520 Write_Str
("Library name = """);
1521 Write_Str
(Get_Name_String
(Data
.Library_Name
));
1526 Data
.Library_Dir
/= No_Name
1528 Data
.Library_Name
/= No_Name
;
1530 if Data
.Library
then
1531 if MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.None
then
1534 "?libraries are not supported on this platform",
1536 Data
.Library
:= False;
1539 pragma Assert
(Lib_Version
.Kind
= Single
);
1541 if Lib_Version
.Value
= Empty_String
then
1542 if Current_Verbosity
= High
then
1543 Write_Line
("No library version specified");
1547 Data
.Lib_Internal_Name
:= Lib_Version
.Value
;
1550 pragma Assert
(The_Lib_Kind
.Kind
= Single
);
1552 if The_Lib_Kind
.Value
= Empty_String
then
1553 if Current_Verbosity
= High
then
1554 Write_Line
("No library kind specified");
1558 Get_Name_String
(The_Lib_Kind
.Value
);
1561 Kind_Name
: constant String :=
1562 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1564 OK
: Boolean := True;
1567 if Kind_Name
= "static" then
1568 Data
.Library_Kind
:= Static
;
1570 elsif Kind_Name
= "dynamic" then
1571 Data
.Library_Kind
:= Dynamic
;
1573 elsif Kind_Name
= "relocatable" then
1574 Data
.Library_Kind
:= Relocatable
;
1579 "illegal value for Library_Kind",
1580 The_Lib_Kind
.Location
);
1584 if Current_Verbosity
= High
and then OK
then
1585 Write_Str
("Library kind = ");
1586 Write_Line
(Kind_Name
);
1589 if Data
.Library_Kind
/= Static
and then
1590 MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.Static_Only
1594 "only static libraries are supported " &
1596 The_Lib_Kind
.Location
);
1597 Data
.Library
:= False;
1602 if Data
.Library
and then Current_Verbosity
= High
then
1603 Write_Line
("This is a library project file");
1608 end Check_Library_Attributes
;
1610 --------------------------
1611 -- Check_Package_Naming --
1612 --------------------------
1614 procedure Check_Package_Naming
1615 (Project
: Project_Id
;
1616 In_Tree
: Project_Tree_Ref
;
1617 Data
: in out Project_Data
)
1619 Naming_Id
: constant Package_Id
:=
1620 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
, In_Tree
);
1622 Naming
: Package_Element
;
1625 -- If there is a package Naming, we will put in Data.Naming
1626 -- what is in this package Naming.
1628 if Naming_Id
/= No_Package
then
1629 Naming
:= In_Tree
.Packages
.Table
(Naming_Id
);
1631 if Current_Verbosity
= High
then
1632 Write_Line
("Checking ""Naming"".");
1635 -- Check Spec_Suffix
1638 Spec_Suffixs
: Array_Element_Id
:=
1644 Suffix
: Array_Element_Id
;
1645 Element
: Array_Element
;
1646 Suffix2
: Array_Element_Id
;
1649 -- If some suffixs have been specified, we make sure that
1650 -- for each language for which a default suffix has been
1651 -- specified, there is a suffix specified, either the one
1652 -- in the project file or if there were none, the default.
1654 if Spec_Suffixs
/= No_Array_Element
then
1655 Suffix
:= Data
.Naming
.Spec_Suffix
;
1657 while Suffix
/= No_Array_Element
loop
1659 In_Tree
.Array_Elements
.Table
(Suffix
);
1660 Suffix2
:= Spec_Suffixs
;
1662 while Suffix2
/= No_Array_Element
loop
1663 exit when In_Tree
.Array_Elements
.Table
1664 (Suffix2
).Index
= Element
.Index
;
1665 Suffix2
:= In_Tree
.Array_Elements
.Table
1669 -- There is a registered default suffix, but no
1670 -- suffix specified in the project file.
1671 -- Add the default to the array.
1673 if Suffix2
= No_Array_Element
then
1674 Array_Element_Table
.Increment_Last
1675 (In_Tree
.Array_Elements
);
1676 In_Tree
.Array_Elements
.Table
1677 (Array_Element_Table
.Last
1678 (In_Tree
.Array_Elements
)) :=
1679 (Index
=> Element
.Index
,
1680 Src_Index
=> Element
.Src_Index
,
1681 Index_Case_Sensitive
=> False,
1682 Value
=> Element
.Value
,
1683 Next
=> Spec_Suffixs
);
1684 Spec_Suffixs
:= Array_Element_Table
.Last
1685 (In_Tree
.Array_Elements
);
1688 Suffix
:= Element
.Next
;
1691 -- Put the resulting array as the specification suffixs
1693 Data
.Naming
.Spec_Suffix
:= Spec_Suffixs
;
1698 Current
: Array_Element_Id
:= Data
.Naming
.Spec_Suffix
;
1699 Element
: Array_Element
;
1702 while Current
/= No_Array_Element
loop
1703 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1704 Get_Name_String
(Element
.Value
.Value
);
1706 if Name_Len
= 0 then
1709 "Spec_Suffix cannot be empty",
1710 Element
.Value
.Location
);
1713 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1714 Current
:= Element
.Next
;
1718 -- Check Body_Suffix
1721 Impl_Suffixs
: Array_Element_Id
:=
1727 Suffix
: Array_Element_Id
;
1728 Element
: Array_Element
;
1729 Suffix2
: Array_Element_Id
;
1732 -- If some suffixes have been specified, we make sure that
1733 -- for each language for which a default suffix has been
1734 -- specified, there is a suffix specified, either the one
1735 -- in the project file or if there were noe, the default.
1737 if Impl_Suffixs
/= No_Array_Element
then
1738 Suffix
:= Data
.Naming
.Body_Suffix
;
1740 while Suffix
/= No_Array_Element
loop
1742 In_Tree
.Array_Elements
.Table
(Suffix
);
1743 Suffix2
:= Impl_Suffixs
;
1745 while Suffix2
/= No_Array_Element
loop
1746 exit when In_Tree
.Array_Elements
.Table
1747 (Suffix2
).Index
= Element
.Index
;
1748 Suffix2
:= In_Tree
.Array_Elements
.Table
1752 -- There is a registered default suffix, but no suffix was
1753 -- specified in the project file. Add the default to the
1756 if Suffix2
= No_Array_Element
then
1757 Array_Element_Table
.Increment_Last
1758 (In_Tree
.Array_Elements
);
1759 In_Tree
.Array_Elements
.Table
1760 (Array_Element_Table
.Last
1761 (In_Tree
.Array_Elements
)) :=
1762 (Index
=> Element
.Index
,
1763 Src_Index
=> Element
.Src_Index
,
1764 Index_Case_Sensitive
=> False,
1765 Value
=> Element
.Value
,
1766 Next
=> Impl_Suffixs
);
1767 Impl_Suffixs
:= Array_Element_Table
.Last
1768 (In_Tree
.Array_Elements
);
1771 Suffix
:= Element
.Next
;
1774 -- Put the resulting array as the implementation suffixs
1776 Data
.Naming
.Body_Suffix
:= Impl_Suffixs
;
1781 Current
: Array_Element_Id
:= Data
.Naming
.Body_Suffix
;
1782 Element
: Array_Element
;
1785 while Current
/= No_Array_Element
loop
1786 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1787 Get_Name_String
(Element
.Value
.Value
);
1789 if Name_Len
= 0 then
1792 "Body_Suffix cannot be empty",
1793 Element
.Value
.Location
);
1796 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1797 Current
:= Element
.Next
;
1801 -- Get the exceptions, if any
1803 Data
.Naming
.Specification_Exceptions
:=
1805 (Name_Specification_Exceptions
,
1806 In_Arrays
=> Naming
.Decl
.Arrays
,
1807 In_Tree
=> In_Tree
);
1809 Data
.Naming
.Implementation_Exceptions
:=
1811 (Name_Implementation_Exceptions
,
1812 In_Arrays
=> Naming
.Decl
.Arrays
,
1813 In_Tree
=> In_Tree
);
1815 end Check_Package_Naming
;
1817 ---------------------------------
1818 -- Check_Programming_Languages --
1819 ---------------------------------
1821 procedure Check_Programming_Languages
1822 (In_Tree
: Project_Tree_Ref
;
1823 Data
: in out Project_Data
)
1825 Languages
: Variable_Value
:= Nil_Variable_Value
;
1829 Prj
.Util
.Value_Of
(Name_Languages
, Data
.Decl
.Attributes
, In_Tree
);
1830 Data
.Ada_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
1831 Data
.Other_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
1833 if Data
.Source_Dirs
/= Nil_String
then
1835 -- Check if languages are specified in this project
1837 if Languages
.Default
then
1839 -- Attribute Languages is not specified. So, it defaults to
1840 -- a project of language Ada only.
1842 Data
.Languages
(Ada_Language_Index
) := True;
1844 -- No sources of languages other than Ada
1846 Data
.Other_Sources_Present
:= False;
1850 Current
: String_List_Id
:= Languages
.Values
;
1851 Element
: String_Element
;
1852 Lang_Name
: Name_Id
;
1853 Index
: Language_Index
;
1856 -- Assume that there is no language specified yet
1858 Data
.Other_Sources_Present
:= False;
1859 Data
.Ada_Sources_Present
:= False;
1861 -- Look through all the languages specified in attribute
1862 -- Languages, if any
1864 while Current
/= Nil_String
loop
1866 In_Tree
.String_Elements
.Table
(Current
);
1867 Get_Name_String
(Element
.Value
);
1868 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1869 Lang_Name
:= Name_Find
;
1870 Index
:= Language_Indexes
.Get
(Lang_Name
);
1872 if Index
= No_Language_Index
then
1873 Add_Language_Name
(Lang_Name
);
1874 Index
:= Last_Language_Index
;
1877 Set
(Index
, True, Data
, In_Tree
);
1878 Set
(Language_Processing
=> Default_Language_Processing_Data
,
1879 For_Language
=> Index
,
1881 In_Tree
=> In_Tree
);
1883 if Index
= Ada_Language_Index
then
1884 Data
.Ada_Sources_Present
:= True;
1887 Data
.Other_Sources_Present
:= True;
1890 Current
:= Element
.Next
;
1895 end Check_Programming_Languages
;
1901 function Check_Project
1903 Root_Project
: Project_Id
;
1904 In_Tree
: Project_Tree_Ref
;
1905 Extending
: Boolean) return Boolean
1908 if P
= Root_Project
then
1911 elsif Extending
then
1913 Data
: Project_Data
:= In_Tree
.Projects
.Table
(Root_Project
);
1916 while Data
.Extends
/= No_Project
loop
1917 if P
= Data
.Extends
then
1921 Data
:= In_Tree
.Projects
.Table
(Data
.Extends
);
1929 -------------------------------
1930 -- Check_Stand_Alone_Library --
1931 -------------------------------
1933 procedure Check_Stand_Alone_Library
1934 (Project
: Project_Id
;
1935 In_Tree
: Project_Tree_Ref
;
1936 Data
: in out Project_Data
;
1937 Extending
: Boolean)
1939 Lib_Interfaces
: constant Prj
.Variable_Value
:=
1941 (Snames
.Name_Library_Interface
,
1942 Data
.Decl
.Attributes
,
1945 Lib_Auto_Init
: constant Prj
.Variable_Value
:=
1947 (Snames
.Name_Library_Auto_Init
,
1948 Data
.Decl
.Attributes
,
1951 Lib_Src_Dir
: constant Prj
.Variable_Value
:=
1953 (Snames
.Name_Library_Src_Dir
,
1954 Data
.Decl
.Attributes
,
1957 Lib_Symbol_File
: constant Prj
.Variable_Value
:=
1959 (Snames
.Name_Library_Symbol_File
,
1960 Data
.Decl
.Attributes
,
1963 Lib_Symbol_Policy
: constant Prj
.Variable_Value
:=
1965 (Snames
.Name_Library_Symbol_Policy
,
1966 Data
.Decl
.Attributes
,
1969 Lib_Ref_Symbol_File
: constant Prj
.Variable_Value
:=
1971 (Snames
.Name_Library_Reference_Symbol_File
,
1972 Data
.Decl
.Attributes
,
1975 Auto_Init_Supported
: constant Boolean :=
1977 Standalone_Library_Auto_Init_Is_Supported
;
1979 OK
: Boolean := True;
1982 pragma Assert
(Lib_Interfaces
.Kind
= List
);
1984 -- It is a stand-alone library project file if attribute
1985 -- Library_Interface is defined.
1987 if not Lib_Interfaces
.Default
then
1988 SAL_Library
: declare
1989 Interfaces
: String_List_Id
:= Lib_Interfaces
.Values
;
1990 Interface_ALIs
: String_List_Id
:= Nil_String
;
1992 The_Unit_Id
: Unit_Id
;
1993 The_Unit_Data
: Unit_Data
;
1995 procedure Add_ALI_For
(Source
: Name_Id
);
1996 -- Add an ALI file name to the list of Interface ALIs
2002 procedure Add_ALI_For
(Source
: Name_Id
) is
2004 Get_Name_String
(Source
);
2007 ALI
: constant String :=
2008 ALI_File_Name
(Name_Buffer
(1 .. Name_Len
));
2009 ALI_Name_Id
: Name_Id
;
2011 Name_Len
:= ALI
'Length;
2012 Name_Buffer
(1 .. Name_Len
) := ALI
;
2013 ALI_Name_Id
:= Name_Find
;
2015 String_Element_Table
.Increment_Last
2016 (In_Tree
.String_Elements
);
2017 In_Tree
.String_Elements
.Table
2018 (String_Element_Table
.Last
2019 (In_Tree
.String_Elements
)) :=
2020 (Value
=> ALI_Name_Id
,
2022 Display_Value
=> ALI_Name_Id
,
2024 In_Tree
.String_Elements
.Table
2025 (Interfaces
).Location
,
2027 Next
=> Interface_ALIs
);
2028 Interface_ALIs
:= String_Element_Table
.Last
2029 (In_Tree
.String_Elements
);
2033 -- Start of processing for SAL_Library
2036 Data
.Standalone_Library
:= True;
2038 -- Library_Interface cannot be an empty list
2040 if Interfaces
= Nil_String
then
2043 "Library_Interface cannot be an empty list",
2044 Lib_Interfaces
.Location
);
2047 -- Process each unit name specified in the attribute
2048 -- Library_Interface.
2050 while Interfaces
/= Nil_String
loop
2052 (In_Tree
.String_Elements
.Table
2053 (Interfaces
).Value
);
2054 To_Lower
(Name_Buffer
(1 .. Name_Len
));
2056 if Name_Len
= 0 then
2059 "an interface cannot be an empty string",
2060 In_Tree
.String_Elements
.Table
2061 (Interfaces
).Location
);
2065 Error_Msg_Name_1
:= Unit
;
2067 Units_Htable
.Get
(In_Tree
.Units_HT
, Unit
);
2069 if The_Unit_Id
= No_Unit
then
2073 In_Tree
.String_Elements
.Table
2074 (Interfaces
).Location
);
2077 -- Check that the unit is part of the project
2080 In_Tree
.Units
.Table
(The_Unit_Id
);
2082 if The_Unit_Data
.File_Names
(Body_Part
).Name
/= No_Name
2083 and then The_Unit_Data
.File_Names
(Body_Part
).Path
/=
2087 (The_Unit_Data
.File_Names
(Body_Part
).Project
,
2088 Project
, In_Tree
, Extending
)
2090 -- There is a body for this unit.
2091 -- If there is no spec, we need to check
2092 -- that it is not a subunit.
2094 if The_Unit_Data
.File_Names
2095 (Specification
).Name
= No_Name
2098 Src_Ind
: Source_File_Index
;
2101 Src_Ind
:= Sinput
.P
.Load_Project_File
2103 (The_Unit_Data
.File_Names
2106 if Sinput
.P
.Source_File_Is_Subunit
2111 "{ is a subunit; " &
2112 "it cannot be an interface",
2114 String_Elements
.Table
2115 (Interfaces
).Location
);
2120 -- The unit is not a subunit, so we add
2121 -- to the Interface ALIs the ALI file
2122 -- corresponding to the body.
2125 (The_Unit_Data
.File_Names
(Body_Part
).Name
);
2130 "{ is not an unit of this project",
2131 In_Tree
.String_Elements
.Table
2132 (Interfaces
).Location
);
2135 elsif The_Unit_Data
.File_Names
2136 (Specification
).Name
/= No_Name
2137 and then The_Unit_Data
.File_Names
2138 (Specification
).Path
/= Slash
2139 and then Check_Project
2140 (The_Unit_Data
.File_Names
2141 (Specification
).Project
,
2142 Project
, In_Tree
, Extending
)
2145 -- The unit is part of the project, it has
2146 -- a spec, but no body. We add to the Interface
2147 -- ALIs the ALI file corresponding to the spec.
2150 (The_Unit_Data
.File_Names
(Specification
).Name
);
2155 "{ is not an unit of this project",
2156 In_Tree
.String_Elements
.Table
2157 (Interfaces
).Location
);
2164 In_Tree
.String_Elements
.Table
(Interfaces
).Next
;
2167 -- Put the list of Interface ALIs in the project data
2169 Data
.Lib_Interface_ALIs
:= Interface_ALIs
;
2171 -- Check value of attribute Library_Auto_Init and set
2172 -- Lib_Auto_Init accordingly.
2174 if Lib_Auto_Init
.Default
then
2176 -- If no attribute Library_Auto_Init is declared, then
2177 -- set auto init only if it is supported.
2179 Data
.Lib_Auto_Init
:= Auto_Init_Supported
;
2182 Get_Name_String
(Lib_Auto_Init
.Value
);
2183 To_Lower
(Name_Buffer
(1 .. Name_Len
));
2185 if Name_Buffer
(1 .. Name_Len
) = "false" then
2186 Data
.Lib_Auto_Init
:= False;
2188 elsif Name_Buffer
(1 .. Name_Len
) = "true" then
2189 if Auto_Init_Supported
then
2190 Data
.Lib_Auto_Init
:= True;
2193 -- Library_Auto_Init cannot be "true" if auto init
2198 "library auto init not supported " &
2200 Lib_Auto_Init
.Location
);
2206 "invalid value for attribute Library_Auto_Init",
2207 Lib_Auto_Init
.Location
);
2212 -- If attribute Library_Src_Dir is defined and not the
2213 -- empty string, check if the directory exist and is not
2214 -- the object directory or one of the source directories.
2215 -- This is the directory where copies of the interface
2216 -- sources will be copied. Note that this directory may be
2217 -- the library directory.
2219 if Lib_Src_Dir
.Value
/= Empty_String
then
2221 Dir_Id
: constant Name_Id
:= Lib_Src_Dir
.Value
;
2225 (Dir_Id
, Data
.Display_Directory
,
2226 Data
.Library_Src_Dir
,
2227 Data
.Display_Library_Src_Dir
);
2229 -- If directory does not exist, report an error
2231 if Data
.Library_Src_Dir
= No_Name
then
2233 -- Get the absolute name of the library directory
2234 -- that does not exist, to report an error.
2237 Dir_Name
: constant String :=
2238 Get_Name_String
(Dir_Id
);
2241 if Is_Absolute_Path
(Dir_Name
) then
2242 Err_Vars
.Error_Msg_Name_1
:= Dir_Id
;
2245 Get_Name_String
(Data
.Directory
);
2247 if Name_Buffer
(Name_Len
) /=
2250 Name_Len
:= Name_Len
+ 1;
2251 Name_Buffer
(Name_Len
) :=
2252 Directory_Separator
;
2257 Name_Len
+ Dir_Name
'Length) :=
2259 Name_Len
:= Name_Len
+ Dir_Name
'Length;
2260 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
2267 "Directory { does not exist",
2268 Lib_Src_Dir
.Location
);
2271 -- Report an error if it is the same as the object
2274 elsif Data
.Library_Src_Dir
= Data
.Object_Directory
then
2277 "directory to copy interfaces cannot be " &
2278 "the object directory",
2279 Lib_Src_Dir
.Location
);
2280 Data
.Library_Src_Dir
:= No_Name
;
2282 -- Check if it is same as one of the source directories
2286 Src_Dirs
: String_List_Id
:= Data
.Source_Dirs
;
2287 Src_Dir
: String_Element
;
2290 while Src_Dirs
/= Nil_String
loop
2291 Src_Dir
:= In_Tree
.String_Elements
.Table
2293 Src_Dirs
:= Src_Dir
.Next
;
2295 -- Report error if it is one of the source directories
2297 if Data
.Library_Src_Dir
= Src_Dir
.Value
then
2300 "directory to copy interfaces cannot " &
2301 "be one of the source directories",
2302 Lib_Src_Dir
.Location
);
2303 Data
.Library_Src_Dir
:= No_Name
;
2309 -- In high verbosity, if there is a valid Library_Src_Dir,
2310 -- display its path name.
2312 if Data
.Library_Src_Dir
/= No_Name
2313 and then Current_Verbosity
= High
2315 Write_Str
("Directory to copy interfaces =""");
2316 Write_Str
(Get_Name_String
(Data
.Library_Src_Dir
));
2323 -- Check the symbol related attributes
2325 -- First, the symbol policy
2327 if not Lib_Symbol_Policy
.Default
then
2329 Value
: constant String :=
2331 (Get_Name_String
(Lib_Symbol_Policy
.Value
));
2334 -- Symbol policy must hove one of a limited number of values
2336 if Value
= "autonomous" or else Value
= "default" then
2337 Data
.Symbol_Data
.Symbol_Policy
:= Autonomous
;
2339 elsif Value
= "compliant" then
2340 Data
.Symbol_Data
.Symbol_Policy
:= Compliant
;
2342 elsif Value
= "controlled" then
2343 Data
.Symbol_Data
.Symbol_Policy
:= Controlled
;
2345 elsif Value
= "restricted" then
2346 Data
.Symbol_Data
.Symbol_Policy
:= Restricted
;
2351 "illegal value for Library_Symbol_Policy",
2352 Lib_Symbol_Policy
.Location
);
2357 -- If attribute Library_Symbol_File is not specified, symbol policy
2358 -- cannot be Restricted.
2360 if Lib_Symbol_File
.Default
then
2361 if Data
.Symbol_Data
.Symbol_Policy
= Restricted
then
2364 "Library_Symbol_File needs to be defined when " &
2365 "symbol policy is Restricted",
2366 Lib_Symbol_Policy
.Location
);
2370 -- Library_Symbol_File is defined. Check that the file exists
2372 Data
.Symbol_Data
.Symbol_File
:= Lib_Symbol_File
.Value
;
2374 Get_Name_String
(Lib_Symbol_File
.Value
);
2376 if Name_Len
= 0 then
2379 "symbol file name cannot be an empty string",
2380 Lib_Symbol_File
.Location
);
2383 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
2386 for J
in 1 .. Name_Len
loop
2387 if Name_Buffer
(J
) = '/'
2388 or else Name_Buffer
(J
) = Directory_Separator
2397 Error_Msg_Name_1
:= Lib_Symbol_File
.Value
;
2400 "symbol file name { is illegal. " &
2401 "Name canot include directory info.",
2402 Lib_Symbol_File
.Location
);
2407 -- If attribute Library_Reference_Symbol_File is not defined,
2408 -- symbol policy cannot be Compilant or Controlled.
2410 if Lib_Ref_Symbol_File
.Default
then
2411 if Data
.Symbol_Data
.Symbol_Policy
= Compliant
2412 or else Data
.Symbol_Data
.Symbol_Policy
= Controlled
2416 "a reference symbol file need to be defined",
2417 Lib_Symbol_Policy
.Location
);
2421 -- Library_Reference_Symbol_File is defined, check file exists
2423 Data
.Symbol_Data
.Reference
:= Lib_Ref_Symbol_File
.Value
;
2425 Get_Name_String
(Lib_Ref_Symbol_File
.Value
);
2427 if Name_Len
= 0 then
2430 "reference symbol file name cannot be an empty string",
2431 Lib_Symbol_File
.Location
);
2434 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
2437 for J
in 1 .. Name_Len
loop
2438 if Name_Buffer
(J
) = '/'
2439 or else Name_Buffer
(J
) = Directory_Separator
2448 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
2451 "reference symbol file { name is illegal. " &
2452 "Name canot include directory info.",
2453 Lib_Ref_Symbol_File
.Location
);
2456 if not Is_Regular_File
2457 (Get_Name_String
(Data
.Object_Directory
) &
2458 Directory_Separator
&
2459 Get_Name_String
(Lib_Ref_Symbol_File
.Value
))
2461 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
2463 -- For controlled symbol policy, it is an error if the
2464 -- reference symbol file does not exist. For other symbol
2465 -- policies, this is just a warning
2468 Data
.Symbol_Data
.Symbol_Policy
/= Controlled
;
2472 "<library reference symbol file { does not exist",
2473 Lib_Ref_Symbol_File
.Location
);
2475 -- In addition in the non-controlled case, if symbol policy
2476 -- is Compliant, it is changed to Autonomous, because there
2477 -- is no reference to check against, and we don't want to
2478 -- fail in this case.
2480 if Data
.Symbol_Data
.Symbol_Policy
/= Controlled
then
2481 if Data
.Symbol_Data
.Symbol_Policy
= Compliant
then
2482 Data
.Symbol_Data
.Symbol_Policy
:= Autonomous
;
2489 end Check_Stand_Alone_Library
;
2491 ----------------------------
2492 -- Compute_Directory_Last --
2493 ----------------------------
2495 function Compute_Directory_Last
(Dir
: String) return Natural is
2498 and then (Dir
(Dir
'Last - 1) = Directory_Separator
2499 or else Dir
(Dir
'Last - 1) = '/')
2501 return Dir
'Last - 1;
2505 end Compute_Directory_Last
;
2507 --------------------
2508 -- Body_Suffix_Of --
2509 --------------------
2511 function Body_Suffix_Of
2512 (Language
: Language_Index
;
2513 In_Project
: Project_Data
;
2514 In_Tree
: Project_Tree_Ref
) return String
2516 Suffix_Id
: constant Name_Id
:=
2517 Suffix_Of
(Language
, In_Project
, In_Tree
);
2519 if Suffix_Id
/= No_Name
then
2520 return Get_Name_String
(Suffix_Id
);
2522 return "." & Get_Name_String
(Language_Names
.Table
(Language
));
2531 (Project
: Project_Id
;
2532 In_Tree
: Project_Tree_Ref
;
2534 Flag_Location
: Source_Ptr
)
2536 Error_Buffer
: String (1 .. 5_000
);
2537 Error_Last
: Natural := 0;
2538 Msg_Name
: Natural := 0;
2539 First
: Positive := Msg
'First;
2541 procedure Add
(C
: Character);
2542 -- Add a character to the buffer
2544 procedure Add
(S
: String);
2545 -- Add a string to the buffer
2547 procedure Add
(Id
: Name_Id
);
2548 -- Add a name to the buffer
2554 procedure Add
(C
: Character) is
2556 Error_Last
:= Error_Last
+ 1;
2557 Error_Buffer
(Error_Last
) := C
;
2560 procedure Add
(S
: String) is
2562 Error_Buffer
(Error_Last
+ 1 .. Error_Last
+ S
'Length) := S
;
2563 Error_Last
:= Error_Last
+ S
'Length;
2566 procedure Add
(Id
: Name_Id
) is
2568 Get_Name_String
(Id
);
2569 Add
(Name_Buffer
(1 .. Name_Len
));
2572 -- Start of processing for Error_Msg
2575 if Error_Report
= null then
2576 Prj
.Err
.Error_Msg
(Msg
, Flag_Location
);
2580 -- Ignore continuation character
2582 if Msg
(First
) = '\' then
2585 -- Warniung character is always the first one in this package
2586 -- this is an undoocumented kludge!!!
2588 elsif Msg
(First
) = '?' then
2592 elsif Msg
(First
) = '<' then
2595 if Err_Vars
.Error_Msg_Warn
then
2600 for Index
in First
.. Msg
'Last loop
2601 if Msg
(Index
) = '{' or else Msg
(Index
) = '%' then
2603 -- Include a name between double quotes
2605 Msg_Name
:= Msg_Name
+ 1;
2609 when 1 => Add
(Err_Vars
.Error_Msg_Name_1
);
2610 when 2 => Add
(Err_Vars
.Error_Msg_Name_2
);
2611 when 3 => Add
(Err_Vars
.Error_Msg_Name_3
);
2613 when others => null;
2624 Error_Report
(Error_Buffer
(1 .. Error_Last
), Project
, In_Tree
);
2631 procedure Find_Sources
2632 (Project
: Project_Id
;
2633 In_Tree
: Project_Tree_Ref
;
2634 Data
: in out Project_Data
;
2635 For_Language
: Language_Index
;
2636 Follow_Links
: Boolean := False)
2638 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
2639 Element
: String_Element
;
2641 Current_Source
: String_List_Id
:= Nil_String
;
2642 Source_Recorded
: Boolean := False;
2645 if Current_Verbosity
= High
then
2646 Write_Line
("Looking for sources:");
2649 -- For each subdirectory
2651 while Source_Dir
/= Nil_String
loop
2653 Source_Recorded
:= False;
2654 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
2655 if Element
.Value
/= No_Name
then
2656 Get_Name_String
(Element
.Display_Value
);
2659 Source_Directory
: constant String :=
2660 Name_Buffer
(1 .. Name_Len
) & Directory_Separator
;
2661 Dir_Last
: constant Natural :=
2662 Compute_Directory_Last
(Source_Directory
);
2665 if Current_Verbosity
= High
then
2666 Write_Str
("Source_Dir = ");
2667 Write_Line
(Source_Directory
);
2670 -- We look to every entry in the source directory
2672 Open
(Dir
, Source_Directory
2673 (Source_Directory
'First .. Dir_Last
));
2676 Read
(Dir
, Name_Buffer
, Name_Len
);
2678 if Current_Verbosity
= High
then
2679 Write_Str
(" Checking ");
2680 Write_Line
(Name_Buffer
(1 .. Name_Len
));
2683 exit when Name_Len
= 0;
2686 File_Name
: constant Name_Id
:= Name_Find
;
2687 Path
: constant String :=
2689 (Name
=> Name_Buffer
(1 .. Name_Len
),
2690 Directory
=> Source_Directory
2691 (Source_Directory
'First .. Dir_Last
),
2692 Resolve_Links
=> Follow_Links
,
2693 Case_Sensitive
=> True);
2694 Path_Name
: Name_Id
;
2697 Name_Len
:= Path
'Length;
2698 Name_Buffer
(1 .. Name_Len
) := Path
;
2699 Path_Name
:= Name_Find
;
2701 if For_Language
= Ada_Language_Index
then
2703 -- We attempt to register it as a source. However,
2704 -- there is no error if the file does not contain
2705 -- a valid source. But there is an error if we have
2706 -- a duplicate unit name.
2709 (File_Name
=> File_Name
,
2710 Path_Name
=> Path_Name
,
2714 Location
=> No_Location
,
2715 Current_Source
=> Current_Source
,
2716 Source_Recorded
=> Source_Recorded
,
2717 Follow_Links
=> Follow_Links
);
2721 (File_Name
=> File_Name
,
2722 Path_Name
=> Path_Name
,
2726 Location
=> No_Location
,
2727 Language
=> For_Language
,
2729 Body_Suffix_Of
(For_Language
, Data
, In_Tree
),
2730 Naming_Exception
=> False);
2740 when Directory_Error
=>
2744 if Source_Recorded
then
2745 In_Tree
.String_Elements
.Table
(Source_Dir
).Flag
:=
2749 Source_Dir
:= Element
.Next
;
2752 if Current_Verbosity
= High
then
2753 Write_Line
("end Looking for sources.");
2756 if For_Language
= Ada_Language_Index
then
2758 -- If we have looked for sources and found none, then
2759 -- it is an error, except if it is an extending project.
2760 -- If a non extending project is not supposed to contain
2761 -- any source, then we never call Find_Sources.
2763 if Current_Source
/= Nil_String
then
2764 Data
.Ada_Sources_Present
:= True;
2766 elsif Data
.Extends
= No_Project
then
2769 "there are no Ada sources in this project",
2775 --------------------------------
2776 -- Free_Ada_Naming_Exceptions --
2777 --------------------------------
2779 procedure Free_Ada_Naming_Exceptions
is
2781 Ada_Naming_Exception_Table
.Set_Last
(0);
2782 Ada_Naming_Exceptions
.Reset
;
2783 Reverse_Ada_Naming_Exceptions
.Reset
;
2784 end Free_Ada_Naming_Exceptions
;
2786 ---------------------
2787 -- Get_Directories --
2788 ---------------------
2790 procedure Get_Directories
2791 (Project
: Project_Id
;
2792 In_Tree
: Project_Tree_Ref
;
2793 Data
: in out Project_Data
)
2795 Object_Dir
: constant Variable_Value
:=
2797 (Name_Object_Dir
, Data
.Decl
.Attributes
, In_Tree
);
2799 Exec_Dir
: constant Variable_Value
:=
2801 (Name_Exec_Dir
, Data
.Decl
.Attributes
, In_Tree
);
2803 Source_Dirs
: constant Variable_Value
:=
2805 (Name_Source_Dirs
, Data
.Decl
.Attributes
, In_Tree
);
2807 Last_Source_Dir
: String_List_Id
:= Nil_String
;
2809 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
);
2810 -- Find one or several source directories, and add them
2811 -- to the list of source directories of the project.
2813 ----------------------
2814 -- Find_Source_Dirs --
2815 ----------------------
2817 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
) is
2818 Directory
: constant String := Get_Name_String
(From
);
2819 Element
: String_Element
;
2821 procedure Recursive_Find_Dirs
(Path
: Name_Id
);
2822 -- Find all the subdirectories (recursively) of Path and add them
2823 -- to the list of source directories of the project.
2825 -------------------------
2826 -- Recursive_Find_Dirs --
2827 -------------------------
2829 procedure Recursive_Find_Dirs
(Path
: Name_Id
) is
2831 Name
: String (1 .. 250);
2833 List
: String_List_Id
:= Data
.Source_Dirs
;
2834 Element
: String_Element
;
2835 Found
: Boolean := False;
2837 Non_Canonical_Path
: Name_Id
:= No_Name
;
2838 Canonical_Path
: Name_Id
:= No_Name
;
2840 The_Path
: constant String :=
2841 Normalize_Pathname
(Get_Name_String
(Path
)) &
2842 Directory_Separator
;
2844 The_Path_Last
: constant Natural :=
2845 Compute_Directory_Last
(The_Path
);
2848 Name_Len
:= The_Path_Last
- The_Path
'First + 1;
2849 Name_Buffer
(1 .. Name_Len
) :=
2850 The_Path
(The_Path
'First .. The_Path_Last
);
2851 Non_Canonical_Path
:= Name_Find
;
2852 Get_Name_String
(Non_Canonical_Path
);
2853 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2854 Canonical_Path
:= Name_Find
;
2856 -- To avoid processing the same directory several times, check
2857 -- if the directory is already in Recursive_Dirs. If it is,
2858 -- then there is nothing to do, just return. If it is not, put
2859 -- it there and continue recursive processing.
2861 if Recursive_Dirs
.Get
(Canonical_Path
) then
2865 Recursive_Dirs
.Set
(Canonical_Path
, True);
2868 -- Check if directory is already in list
2870 while List
/= Nil_String
loop
2871 Element
:= In_Tree
.String_Elements
.Table
(List
);
2873 if Element
.Value
/= No_Name
then
2874 Found
:= Element
.Value
= Canonical_Path
;
2878 List
:= Element
.Next
;
2881 -- If directory is not already in list, put it there
2884 if Current_Verbosity
= High
then
2886 Write_Line
(The_Path
(The_Path
'First .. The_Path_Last
));
2889 String_Element_Table
.Increment_Last
2890 (In_Tree
.String_Elements
);
2892 (Value
=> Canonical_Path
,
2893 Display_Value
=> Non_Canonical_Path
,
2894 Location
=> No_Location
,
2899 -- Case of first source directory
2901 if Last_Source_Dir
= Nil_String
then
2902 Data
.Source_Dirs
:= String_Element_Table
.Last
2903 (In_Tree
.String_Elements
);
2905 -- Here we already have source directories
2908 -- Link the previous last to the new one
2910 In_Tree
.String_Elements
.Table
2911 (Last_Source_Dir
).Next
:=
2912 String_Element_Table
.Last
2913 (In_Tree
.String_Elements
);
2916 -- And register this source directory as the new last
2918 Last_Source_Dir
:= String_Element_Table
.Last
2919 (In_Tree
.String_Elements
);
2920 In_Tree
.String_Elements
.Table
(Last_Source_Dir
) :=
2924 -- Now look for subdirectories. We do that even when this
2925 -- directory is already in the list, because some of its
2926 -- subdirectories may not be in the list yet.
2928 Open
(Dir
, The_Path
(The_Path
'First .. The_Path_Last
));
2931 Read
(Dir
, Name
, Last
);
2934 if Name
(1 .. Last
) /= "."
2935 and then Name
(1 .. Last
) /= ".."
2937 -- Avoid . and .. directories
2939 if Current_Verbosity
= High
then
2940 Write_Str
(" Checking ");
2941 Write_Line
(Name
(1 .. Last
));
2945 Path_Name
: constant String :=
2947 (Name
=> Name
(1 .. Last
),
2950 (The_Path
'First .. The_Path_Last
),
2951 Resolve_Links
=> False,
2952 Case_Sensitive
=> True);
2955 if Is_Directory
(Path_Name
) then
2957 -- We have found a new subdirectory, call self
2959 Name_Len
:= Path_Name
'Length;
2960 Name_Buffer
(1 .. Name_Len
) := Path_Name
;
2961 Recursive_Find_Dirs
(Name_Find
);
2970 when Directory_Error
=>
2972 end Recursive_Find_Dirs
;
2974 -- Start of processing for Find_Source_Dirs
2977 if Current_Verbosity
= High
then
2978 Write_Str
("Find_Source_Dirs (""");
2979 Write_Str
(Directory
);
2983 -- First, check if we are looking for a directory tree,
2984 -- indicated by "/**" at the end.
2986 if Directory
'Length >= 3
2987 and then Directory
(Directory
'Last - 1 .. Directory
'Last) = "**"
2988 and then (Directory
(Directory
'Last - 2) = '/'
2990 Directory
(Directory
'Last - 2) = Directory_Separator
)
2992 Data
.Known_Order_Of_Source_Dirs
:= False;
2994 Name_Len
:= Directory
'Length - 3;
2996 if Name_Len
= 0 then
2998 -- This is the case of "/**": all directories
2999 -- in the file system.
3002 Name_Buffer
(1) := Directory
(Directory
'First);
3005 Name_Buffer
(1 .. Name_Len
) :=
3006 Directory
(Directory
'First .. Directory
'Last - 3);
3009 if Current_Verbosity
= High
then
3010 Write_Str
("Looking for all subdirectories of """);
3011 Write_Str
(Name_Buffer
(1 .. Name_Len
));
3016 Base_Dir
: constant Name_Id
:= Name_Find
;
3017 Root_Dir
: constant String :=
3019 (Name
=> Get_Name_String
(Base_Dir
),
3021 Get_Name_String
(Data
.Display_Directory
),
3022 Resolve_Links
=> False,
3023 Case_Sensitive
=> True);
3026 if Root_Dir
'Length = 0 then
3027 Err_Vars
.Error_Msg_Name_1
:= Base_Dir
;
3029 if Location
= No_Location
then
3032 "{ is not a valid directory.",
3037 "{ is not a valid directory.",
3042 -- We have an existing directory, we register it and all
3043 -- of its subdirectories.
3045 if Current_Verbosity
= High
then
3046 Write_Line
("Looking for source directories:");
3049 Name_Len
:= Root_Dir
'Length;
3050 Name_Buffer
(1 .. Name_Len
) := Root_Dir
;
3051 Recursive_Find_Dirs
(Name_Find
);
3053 if Current_Verbosity
= High
then
3054 Write_Line
("End of looking for source directories.");
3059 -- We have a single directory
3063 Path_Name
: Name_Id
;
3064 Display_Path_Name
: Name_Id
;
3068 (From
, Data
.Display_Directory
, Path_Name
, Display_Path_Name
);
3070 if Path_Name
= No_Name
then
3071 Err_Vars
.Error_Msg_Name_1
:= From
;
3073 if Location
= No_Location
then
3076 "{ is not a valid directory",
3081 "{ is not a valid directory",
3086 -- As it is an existing directory, we add it to
3087 -- the list of directories.
3089 String_Element_Table
.Increment_Last
3090 (In_Tree
.String_Elements
);
3091 Element
.Value
:= Path_Name
;
3092 Element
.Display_Value
:= Display_Path_Name
;
3094 if Last_Source_Dir
= Nil_String
then
3096 -- This is the first source directory
3098 Data
.Source_Dirs
:= String_Element_Table
.Last
3099 (In_Tree
.String_Elements
);
3102 -- We already have source directories,
3103 -- link the previous last to the new one.
3105 In_Tree
.String_Elements
.Table
3106 (Last_Source_Dir
).Next
:=
3107 String_Element_Table
.Last
3108 (In_Tree
.String_Elements
);
3111 -- And register this source directory as the new last
3113 Last_Source_Dir
:= String_Element_Table
.Last
3114 (In_Tree
.String_Elements
);
3115 In_Tree
.String_Elements
.Table
3116 (Last_Source_Dir
) := Element
;
3120 end Find_Source_Dirs
;
3122 -- Start of processing for Get_Directories
3125 if Current_Verbosity
= High
then
3126 Write_Line
("Starting to look for directories");
3129 -- Check the object directory
3131 pragma Assert
(Object_Dir
.Kind
= Single
,
3132 "Object_Dir is not a single string");
3134 -- We set the object directory to its default
3136 Data
.Object_Directory
:= Data
.Directory
;
3137 Data
.Display_Object_Dir
:= Data
.Display_Directory
;
3139 if Object_Dir
.Value
/= Empty_String
then
3140 Get_Name_String
(Object_Dir
.Value
);
3142 if Name_Len
= 0 then
3145 "Object_Dir cannot be empty",
3146 Object_Dir
.Location
);
3149 -- We check that the specified object directory does exist
3152 (Object_Dir
.Value
, Data
.Display_Directory
,
3153 Data
.Object_Directory
, Data
.Display_Object_Dir
);
3155 if Data
.Object_Directory
= No_Name
then
3157 -- The object directory does not exist, report an error
3159 Err_Vars
.Error_Msg_Name_1
:= Object_Dir
.Value
;
3162 "the object directory { cannot be found",
3165 -- Do not keep a nil Object_Directory. Set it to the specified
3166 -- (relative or absolute) path. This is for the benefit of
3167 -- tools that recover from errors; for example, these tools
3168 -- could create the non existent directory.
3170 Data
.Display_Object_Dir
:= Object_Dir
.Value
;
3171 Get_Name_String
(Object_Dir
.Value
);
3172 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3173 Data
.Object_Directory
:= Name_Find
;
3178 if Current_Verbosity
= High
then
3179 if Data
.Object_Directory
= No_Name
then
3180 Write_Line
("No object directory");
3182 Write_Str
("Object directory: """);
3183 Write_Str
(Get_Name_String
(Data
.Display_Object_Dir
));
3188 -- Check the exec directory
3190 pragma Assert
(Exec_Dir
.Kind
= Single
,
3191 "Exec_Dir is not a single string");
3193 -- We set the object directory to its default
3195 Data
.Exec_Directory
:= Data
.Object_Directory
;
3196 Data
.Display_Exec_Dir
:= Data
.Display_Object_Dir
;
3198 if Exec_Dir
.Value
/= Empty_String
then
3199 Get_Name_String
(Exec_Dir
.Value
);
3201 if Name_Len
= 0 then
3204 "Exec_Dir cannot be empty",
3208 -- We check that the specified object directory
3212 (Exec_Dir
.Value
, Data
.Directory
,
3213 Data
.Exec_Directory
, Data
.Display_Exec_Dir
);
3215 if Data
.Exec_Directory
= No_Name
then
3216 Err_Vars
.Error_Msg_Name_1
:= Exec_Dir
.Value
;
3219 "the exec directory { cannot be found",
3225 if Current_Verbosity
= High
then
3226 if Data
.Exec_Directory
= No_Name
then
3227 Write_Line
("No exec directory");
3229 Write_Str
("Exec directory: """);
3230 Write_Str
(Get_Name_String
(Data
.Display_Exec_Dir
));
3235 -- Look for the source directories
3237 if Current_Verbosity
= High
then
3238 Write_Line
("Starting to look for source directories");
3241 pragma Assert
(Source_Dirs
.Kind
= List
, "Source_Dirs is not a list");
3243 if Source_Dirs
.Default
then
3245 -- No Source_Dirs specified: the single source directory
3246 -- is the one containing the project file
3248 String_Element_Table
.Increment_Last
3249 (In_Tree
.String_Elements
);
3250 Data
.Source_Dirs
:= String_Element_Table
.Last
3251 (In_Tree
.String_Elements
);
3252 In_Tree
.String_Elements
.Table
(Data
.Source_Dirs
) :=
3253 (Value
=> Data
.Directory
,
3254 Display_Value
=> Data
.Display_Directory
,
3255 Location
=> No_Location
,
3260 if Current_Verbosity
= High
then
3261 Write_Line
("Single source directory:");
3263 Write_Str
(Get_Name_String
(Data
.Display_Directory
));
3267 elsif Source_Dirs
.Values
= Nil_String
then
3269 -- If Source_Dirs is an empty string list, this means
3270 -- that this project contains no source. For projects that
3271 -- don't extend other projects, this also means that there is no
3272 -- need for an object directory, if not specified.
3274 if Data
.Extends
= No_Project
3275 and then Data
.Object_Directory
= Data
.Directory
3277 Data
.Object_Directory
:= No_Name
;
3280 Data
.Source_Dirs
:= Nil_String
;
3281 Data
.Ada_Sources_Present
:= False;
3282 Data
.Other_Sources_Present
:= False;
3286 Source_Dir
: String_List_Id
:= Source_Dirs
.Values
;
3287 Element
: String_Element
;
3290 -- We will find the source directories for each
3291 -- element of the list
3293 while Source_Dir
/= Nil_String
loop
3295 In_Tree
.String_Elements
.Table
(Source_Dir
);
3296 Find_Source_Dirs
(Element
.Value
, Element
.Location
);
3297 Source_Dir
:= Element
.Next
;
3302 if Current_Verbosity
= High
then
3303 Write_Line
("Putting source directories in canonical cases");
3307 Current
: String_List_Id
:= Data
.Source_Dirs
;
3308 Element
: String_Element
;
3311 while Current
/= Nil_String
loop
3312 Element
:= In_Tree
.String_Elements
.Table
(Current
);
3313 if Element
.Value
/= No_Name
then
3314 Get_Name_String
(Element
.Value
);
3315 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3316 Element
.Value
:= Name_Find
;
3317 In_Tree
.String_Elements
.Table
(Current
) := Element
;
3320 Current
:= Element
.Next
;
3324 end Get_Directories
;
3331 (Project
: Project_Id
;
3332 In_Tree
: Project_Tree_Ref
;
3333 Data
: in out Project_Data
) is
3334 Mains
: constant Variable_Value
:=
3335 Prj
.Util
.Value_Of
(Name_Main
, Data
.Decl
.Attributes
, In_Tree
);
3338 Data
.Mains
:= Mains
.Values
;
3340 -- If no Mains were specified, and if we are an extending
3341 -- project, inherit the Mains from the project we are extending.
3343 if Mains
.Default
then
3344 if Data
.Extends
/= No_Project
then
3346 In_Tree
.Projects
.Table
(Data
.Extends
).Mains
;
3349 -- In a library project file, Main cannot be specified
3351 elsif Data
.Library
then
3354 "a library project file cannot have Main specified",
3359 ---------------------------
3360 -- Get_Sources_From_File --
3361 ---------------------------
3363 procedure Get_Sources_From_File
3365 Location
: Source_Ptr
;
3366 Project
: Project_Id
;
3367 In_Tree
: Project_Tree_Ref
)
3369 File
: Prj
.Util
.Text_File
;
3370 Line
: String (1 .. 250);
3372 Source_Name
: Name_Id
;
3377 if Current_Verbosity
= High
then
3378 Write_Str
("Opening """);
3385 Prj
.Util
.Open
(File
, Path
);
3387 if not Prj
.Util
.Is_Valid
(File
) then
3388 Error_Msg
(Project
, In_Tree
, "file does not exist", Location
);
3390 -- Read the lines one by one
3392 while not Prj
.Util
.End_Of_File
(File
) loop
3393 Prj
.Util
.Get_Line
(File
, Line
, Last
);
3395 -- A non empty, non comment line should contain a file name
3398 and then (Last
= 1 or else Line
(1 .. 2) /= "--")
3400 -- ??? we should check that there is no directory information
3403 Name_Buffer
(1 .. Name_Len
) := Line
(1 .. Last
);
3404 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3405 Source_Name
:= Name_Find
;
3409 (Name
=> Source_Name
,
3410 Location
=> Location
,
3415 Prj
.Util
.Close
(File
);
3418 end Get_Sources_From_File
;
3425 (Canonical_File_Name
: Name_Id
;
3426 Naming
: Naming_Data
;
3427 Exception_Id
: out Ada_Naming_Exception_Id
;
3428 Unit_Name
: out Name_Id
;
3429 Unit_Kind
: out Spec_Or_Body
;
3430 Needs_Pragma
: out Boolean)
3432 Info_Id
: Ada_Naming_Exception_Id
3433 := Ada_Naming_Exceptions
.Get
(Canonical_File_Name
);
3437 if Info_Id
= No_Ada_Naming_Exception
then
3438 if Hostparm
.OpenVMS
then
3439 VMS_Name
:= Canonical_File_Name
;
3440 Get_Name_String
(VMS_Name
);
3442 if Name_Buffer
(Name_Len
) = '.' then
3443 Name_Len
:= Name_Len
- 1;
3444 VMS_Name
:= Name_Find
;
3447 Info_Id
:= Ada_Naming_Exceptions
.Get
(VMS_Name
);
3452 if Info_Id
/= No_Ada_Naming_Exception
then
3453 Exception_Id
:= Info_Id
;
3454 Unit_Name
:= No_Name
;
3455 Unit_Kind
:= Specification
;
3456 Needs_Pragma
:= True;
3460 Needs_Pragma
:= False;
3461 Exception_Id
:= No_Ada_Naming_Exception
;
3463 Get_Name_String
(Canonical_File_Name
);
3466 File
: String := Name_Buffer
(1 .. Name_Len
);
3467 First
: constant Positive := File
'First;
3468 Last
: Natural := File
'Last;
3469 Standard_GNAT
: Boolean;
3473 Naming
.Ada_Spec_Suffix
= Default_Ada_Spec_Suffix
3474 and then Naming
.Ada_Body_Suffix
= Default_Ada_Body_Suffix
;
3476 -- Check if the end of the file name is Specification_Append
3478 Get_Name_String
(Naming
.Ada_Spec_Suffix
);
3480 if File
'Length > Name_Len
3481 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3482 Name_Buffer
(1 .. Name_Len
)
3486 Unit_Kind
:= Specification
;
3487 Last
:= Last
- Name_Len
;
3489 if Current_Verbosity
= High
then
3490 Write_Str
(" Specification: ");
3491 Write_Line
(File
(First
.. Last
));
3495 Get_Name_String
(Naming
.Ada_Body_Suffix
);
3497 -- Check if the end of the file name is Body_Append
3499 if File
'Length > Name_Len
3500 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3501 Name_Buffer
(1 .. Name_Len
)
3505 Unit_Kind
:= Body_Part
;
3506 Last
:= Last
- Name_Len
;
3508 if Current_Verbosity
= High
then
3509 Write_Str
(" Body: ");
3510 Write_Line
(File
(First
.. Last
));
3513 elsif Naming
.Separate_Suffix
/= Naming
.Ada_Spec_Suffix
then
3514 Get_Name_String
(Naming
.Separate_Suffix
);
3516 -- Check if the end of the file name is Separate_Append
3518 if File
'Length > Name_Len
3519 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3520 Name_Buffer
(1 .. Name_Len
)
3522 -- We have a separate (a body)
3524 Unit_Kind
:= Body_Part
;
3525 Last
:= Last
- Name_Len
;
3527 if Current_Verbosity
= High
then
3528 Write_Str
(" Separate: ");
3529 Write_Line
(File
(First
.. Last
));
3543 -- This is not a source file
3545 Unit_Name
:= No_Name
;
3546 Unit_Kind
:= Specification
;
3548 if Current_Verbosity
= High
then
3549 Write_Line
(" Not a valid file name.");
3555 Get_Name_String
(Naming
.Dot_Replacement
);
3557 Standard_GNAT
and then Name_Buffer
(1 .. Name_Len
) = "-";
3559 if Name_Buffer
(1 .. Name_Len
) /= "." then
3561 -- If Dot_Replacement is not a single dot, then there should
3562 -- not be any dot in the name.
3564 for Index
in First
.. Last
loop
3565 if File
(Index
) = '.' then
3566 if Current_Verbosity
= High
then
3568 (" Not a valid file name (some dot not replaced).");
3571 Unit_Name
:= No_Name
;
3577 -- Replace the substring Dot_Replacement with dots
3580 Index
: Positive := First
;
3583 while Index
<= Last
- Name_Len
+ 1 loop
3585 if File
(Index
.. Index
+ Name_Len
- 1) =
3586 Name_Buffer
(1 .. Name_Len
)
3588 File
(Index
) := '.';
3590 if Name_Len
> 1 and then Index
< Last
then
3591 File
(Index
+ 1 .. Last
- Name_Len
+ 1) :=
3592 File
(Index
+ Name_Len
.. Last
);
3595 Last
:= Last
- Name_Len
+ 1;
3603 -- Check if the casing is right
3606 Src
: String := File
(First
.. Last
);
3609 case Naming
.Casing
is
3610 when All_Lower_Case
=>
3613 Mapping
=> Lower_Case_Map
);
3615 when All_Upper_Case
=>
3618 Mapping
=> Upper_Case_Map
);
3620 when Mixed_Case | Unknown
=>
3624 if Src
/= File
(First
.. Last
) then
3625 if Current_Verbosity
= High
then
3626 Write_Line
(" Not a valid file name (casing).");
3629 Unit_Name
:= No_Name
;
3633 -- We put the name in lower case
3637 Mapping
=> Lower_Case_Map
);
3639 -- In the standard GNAT naming scheme, check for special cases:
3640 -- children or separates of A, G, I or S, and run time sources.
3642 if Standard_GNAT
and then Src
'Length >= 3 then
3644 S1
: constant Character := Src
(Src
'First);
3645 S2
: constant Character := Src
(Src
'First + 1);
3648 if S1
= 'a' or else S1
= 'g'
3649 or else S1
= 'i' or else S1
= 's'
3651 -- Children or separates of packages A, G, I or S
3653 if (Hostparm
.OpenVMS
and then S2
= '$')
3654 or else (not Hostparm
.OpenVMS
and then S2
= '~')
3656 Src
(Src
'First + 1) := '.';
3658 -- If it is potentially a run time source, disable
3659 -- filling of the mapping file to avoid warnings.
3662 Set_Mapping_File_Initial_State_To_Empty
;
3669 if Current_Verbosity
= High
then
3674 -- Now, we check if this name is a valid unit name
3676 Check_Ada_Name
(Name
=> Src
, Unit
=> Unit_Name
);
3686 function Hash
(Unit
: Unit_Info
) return Header_Num
is
3688 return Header_Num
(Unit
.Unit
mod 2048);
3691 -----------------------
3692 -- Is_Illegal_Suffix --
3693 -----------------------
3695 function Is_Illegal_Suffix
3697 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean
3700 if Suffix
'Length = 0 or else Index
(Suffix
, ".") = 0 then
3704 -- If dot replacement is a single dot, and first character of
3705 -- suffix is also a dot
3707 if Dot_Replacement_Is_A_Single_Dot
3708 and then Suffix
(Suffix
'First) = '.'
3710 for Index
in Suffix
'First + 1 .. Suffix
'Last loop
3712 -- If there is another dot
3714 if Suffix
(Index
) = '.' then
3716 -- It is illegal to have a letter following the initial dot
3718 return Is_Letter
(Suffix
(Suffix
'First + 1));
3726 end Is_Illegal_Suffix
;
3728 ----------------------
3729 -- Locate_Directory --
3730 ----------------------
3732 procedure Locate_Directory
3736 Display
: out Name_Id
)
3738 The_Name
: constant String := Get_Name_String
(Name
);
3740 The_Parent
: constant String :=
3741 Get_Name_String
(Parent
) & Directory_Separator
;
3743 The_Parent_Last
: constant Natural :=
3744 Compute_Directory_Last
(The_Parent
);
3747 if Current_Verbosity
= High
then
3748 Write_Str
("Locate_Directory (""");
3749 Write_Str
(The_Name
);
3750 Write_Str
(""", """);
3751 Write_Str
(The_Parent
);
3758 if Is_Absolute_Path
(The_Name
) then
3759 if Is_Directory
(The_Name
) then
3761 Normed
: constant String :=
3764 Resolve_Links
=> False,
3765 Case_Sensitive
=> True);
3767 Canonical_Path
: constant String :=
3770 Resolve_Links
=> True,
3771 Case_Sensitive
=> False);
3774 Name_Len
:= Normed
'Length;
3775 Name_Buffer
(1 .. Name_Len
) := Normed
;
3776 Display
:= Name_Find
;
3778 Name_Len
:= Canonical_Path
'Length;
3779 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3786 Full_Path
: constant String :=
3787 The_Parent
(The_Parent
'First .. The_Parent_Last
) &
3791 if Is_Directory
(Full_Path
) then
3793 Normed
: constant String :=
3796 Resolve_Links
=> False,
3797 Case_Sensitive
=> True);
3799 Canonical_Path
: constant String :=
3802 Resolve_Links
=> True,
3803 Case_Sensitive
=> False);
3806 Name_Len
:= Normed
'Length;
3807 Name_Buffer
(1 .. Name_Len
) := Normed
;
3808 Display
:= Name_Find
;
3810 Name_Len
:= Canonical_Path
'Length;
3811 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3817 end Locate_Directory
;
3819 ----------------------
3820 -- Look_For_Sources --
3821 ----------------------
3823 procedure Look_For_Sources
3824 (Project
: Project_Id
;
3825 In_Tree
: Project_Tree_Ref
;
3826 Data
: in out Project_Data
;
3827 Follow_Links
: Boolean)
3829 procedure Get_Path_Names_And_Record_Sources
(Follow_Links
: Boolean);
3830 -- Find the path names of the source files in the Source_Names table
3831 -- in the source directories and record those that are Ada sources.
3833 procedure Get_Sources_From_File
3835 Location
: Source_Ptr
);
3836 -- Get the sources of a project from a text file
3838 ---------------------------------------
3839 -- Get_Path_Names_And_Record_Sources --
3840 ---------------------------------------
3842 procedure Get_Path_Names_And_Record_Sources
(Follow_Links
: Boolean) is
3843 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
3844 Element
: String_Element
;
3849 Canonical_Name
: Name_Id
;
3850 Name_Str
: String (1 .. 1_024
);
3851 Last
: Natural := 0;
3854 Current_Source
: String_List_Id
:= Nil_String
;
3856 First_Error
: Boolean := True;
3858 Source_Recorded
: Boolean := False;
3861 -- We look in all source directories for the file names in the
3862 -- hash table Source_Names
3864 while Source_Dir
/= Nil_String
loop
3865 Source_Recorded
:= False;
3866 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
3869 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
3871 if Current_Verbosity
= High
then
3872 Write_Str
("checking directory """);
3873 Write_Str
(Dir_Path
);
3877 Open
(Dir
, Dir_Path
);
3880 Read
(Dir
, Name_Str
, Last
);
3883 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
3885 Canonical_Case_File_Name
(Name_Str
(1 .. Last
));
3887 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
3888 Canonical_Name
:= Name_Find
;
3889 NL
:= Source_Names
.Get
(Canonical_Name
);
3891 if NL
/= No_Name_Location
and then not NL
.Found
then
3893 Source_Names
.Set
(Canonical_Name
, NL
);
3894 Name_Len
:= Dir_Path
'Length;
3895 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
3897 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
3898 Add_Char_To_Name_Buffer
(Directory_Separator
);
3901 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
3904 if Current_Verbosity
= High
then
3905 Write_Str
(" found ");
3906 Write_Line
(Get_Name_String
(Name
));
3909 -- Register the source if it is an Ada compilation unit
3917 Location
=> NL
.Location
,
3918 Current_Source
=> Current_Source
,
3919 Source_Recorded
=> Source_Recorded
,
3920 Follow_Links
=> Follow_Links
);
3927 if Source_Recorded
then
3928 In_Tree
.String_Elements
.Table
(Source_Dir
).Flag
:=
3932 Source_Dir
:= Element
.Next
;
3935 -- It is an error if a source file name in a source list or
3936 -- in a source list file is not found.
3938 NL
:= Source_Names
.Get_First
;
3940 while NL
/= No_Name_Location
loop
3941 if not NL
.Found
then
3942 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
3947 "source file { cannot be found",
3949 First_Error
:= False;
3954 "\source file { cannot be found",
3959 NL
:= Source_Names
.Get_Next
;
3961 end Get_Path_Names_And_Record_Sources
;
3963 ---------------------------
3964 -- Get_Sources_From_File --
3965 ---------------------------
3967 procedure Get_Sources_From_File
3969 Location
: Source_Ptr
)
3972 -- Get the list of sources from the file and put them in hash table
3975 Get_Sources_From_File
(Path
, Location
, Project
, In_Tree
);
3977 -- Look in the source directories to find those sources
3979 Get_Path_Names_And_Record_Sources
(Follow_Links
);
3981 -- We should have found at least one source.
3982 -- If not, report an error.
3984 if Data
.Sources
= Nil_String
then
3985 Error_Msg
(Project
, In_Tree
,
3986 "there are no Ada sources in this project",
3989 end Get_Sources_From_File
;
3992 if Data
.Ada_Sources_Present
then
3994 Sources
: constant Variable_Value
:=
3997 Data
.Decl
.Attributes
,
4000 Source_List_File
: constant Variable_Value
:=
4002 (Name_Source_List_File
,
4003 Data
.Decl
.Attributes
,
4006 Locally_Removed
: constant Variable_Value
:=
4008 (Name_Locally_Removed_Files
,
4009 Data
.Decl
.Attributes
,
4014 (Sources
.Kind
= List
,
4015 "Source_Files is not a list");
4018 (Source_List_File
.Kind
= Single
,
4019 "Source_List_File is not a single string");
4021 if not Sources
.Default
then
4022 if not Source_List_File
.Default
then
4025 "?both variables source_files and " &
4026 "source_list_file are present",
4027 Source_List_File
.Location
);
4030 -- Sources is a list of file names
4033 Current
: String_List_Id
:= Sources
.Values
;
4034 Element
: String_Element
;
4035 Location
: Source_Ptr
;
4041 Data
.Ada_Sources_Present
:= Current
/= Nil_String
;
4043 while Current
/= Nil_String
loop
4045 In_Tree
.String_Elements
.Table
(Current
);
4046 Get_Name_String
(Element
.Value
);
4047 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4050 -- If the element has no location, then use the
4051 -- location of Sources to report possible errors.
4053 if Element
.Location
= No_Location
then
4054 Location
:= Sources
.Location
;
4056 Location
:= Element
.Location
;
4063 Location
=> Location
,
4066 Current
:= Element
.Next
;
4069 Get_Path_Names_And_Record_Sources
(Follow_Links
);
4072 -- No source_files specified
4074 -- We check Source_List_File has been specified
4076 elsif not Source_List_File
.Default
then
4078 -- Source_List_File is the name of the file
4079 -- that contains the source file names
4082 Source_File_Path_Name
: constant String :=
4084 (Source_List_File
.Value
,
4088 if Source_File_Path_Name
'Length = 0 then
4089 Err_Vars
.Error_Msg_Name_1
:= Source_List_File
.Value
;
4092 "file with sources { does not exist",
4093 Source_List_File
.Location
);
4096 Get_Sources_From_File
4097 (Source_File_Path_Name
,
4098 Source_List_File
.Location
);
4103 -- Neither Source_Files nor Source_List_File has been
4104 -- specified. Find all the files that satisfy the naming
4105 -- scheme in all the source directories.
4108 (Project
, In_Tree
, Data
, Ada_Language_Index
, Follow_Links
);
4111 -- If there are sources that are locally removed, mark them as
4112 -- such in the Units table.
4114 if not Locally_Removed
.Default
then
4116 -- Sources can be locally removed only in extending
4119 if Data
.Extends
= No_Project
then
4122 "Locally_Removed_Files can only be used " &
4123 "in an extending project file",
4124 Locally_Removed
.Location
);
4128 Current
: String_List_Id
:= Locally_Removed
.Values
;
4129 Element
: String_Element
;
4130 Location
: Source_Ptr
;
4134 Extended
: Project_Id
;
4137 while Current
/= Nil_String
loop
4139 In_Tree
.String_Elements
.Table
(Current
);
4140 Get_Name_String
(Element
.Value
);
4141 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4144 -- If the element has no location, then use the
4145 -- location of Locally_Removed to report
4148 if Element
.Location
= No_Location
then
4149 Location
:= Locally_Removed
.Location
;
4151 Location
:= Element
.Location
;
4156 for Index
in Unit_Table
.First
..
4157 Unit_Table
.Last
(In_Tree
.Units
)
4159 Unit
:= In_Tree
.Units
.Table
(Index
);
4161 if Unit
.File_Names
(Specification
).Name
= Name
then
4164 -- Check that this is from a project that
4165 -- the current project extends, but not the
4168 Extended
:= Unit
.File_Names
4169 (Specification
).Project
;
4171 if Extended
= Project
then
4174 "cannot remove a source " &
4175 "of the same project",
4179 Project_Extends
(Project
, Extended
, In_Tree
)
4182 (Specification
).Path
:= Slash
;
4184 (Specification
).Needs_Pragma
:= False;
4185 In_Tree
.Units
.Table
(Index
) :=
4187 Add_Forbidden_File_Name
4188 (Unit
.File_Names
(Specification
).Name
);
4194 "cannot remove a source from " &
4200 Unit
.File_Names
(Body_Part
).Name
= Name
4204 -- Check that this is from a project that
4205 -- the current project extends, but not the
4208 Extended
:= Unit
.File_Names
4209 (Body_Part
).Project
;
4211 if Extended
= Project
then
4214 "cannot remove a source " &
4215 "of the same project",
4219 Project_Extends
(Project
, Extended
, In_Tree
)
4221 Unit
.File_Names
(Body_Part
).Path
:= Slash
;
4222 Unit
.File_Names
(Body_Part
).Needs_Pragma
4224 In_Tree
.Units
.Table
(Index
) :=
4226 Add_Forbidden_File_Name
4227 (Unit
.File_Names
(Body_Part
).Name
);
4235 Err_Vars
.Error_Msg_Name_1
:= Name
;
4237 (Project
, In_Tree
, "unknown file {", Location
);
4240 Current
:= Element
.Next
;
4248 if Data
.Other_Sources_Present
then
4250 -- Set Source_Present to False. It will be set back to True
4251 -- whenever a source is found.
4253 Data
.Other_Sources_Present
:= False;
4254 for Lang
in Ada_Language_Index
+ 1 .. Last_Language_Index
loop
4256 -- For each language (other than Ada) in the project file
4258 if Is_Present
(Lang
, Data
, In_Tree
) then
4260 -- Reset the indication that there are sources of this
4261 -- language. It will be set back to True whenever we find a
4262 -- source of the language.
4264 Set
(Lang
, False, Data
, In_Tree
);
4266 -- First, get the source suffix for the language
4268 Set
(Suffix
=> Suffix_For
(Lang
, Data
.Naming
, In_Tree
),
4269 For_Language
=> Lang
,
4271 In_Tree
=> In_Tree
);
4273 -- Then, deal with the naming exceptions, if any
4278 Naming_Exceptions
: constant Variable_Value
:=
4280 (Index
=> Language_Names
.Table
(Lang
),
4282 In_Array
=> Data
.Naming
.Implementation_Exceptions
,
4283 In_Tree
=> In_Tree
);
4284 Element_Id
: String_List_Id
;
4285 Element
: String_Element
;
4287 Source_Found
: Boolean := False;
4290 -- If there are naming exceptions, look through them one
4293 if Naming_Exceptions
/= Nil_Variable_Value
then
4294 Element_Id
:= Naming_Exceptions
.Values
;
4296 while Element_Id
/= Nil_String
loop
4297 Element
:= In_Tree
.String_Elements
.Table
4299 Get_Name_String
(Element
.Value
);
4300 Canonical_Case_File_Name
4301 (Name_Buffer
(1 .. Name_Len
));
4302 File_Id
:= Name_Find
;
4304 -- Put each naming exception in the Source_Names
4305 -- hash table, but if there are repetition, don't
4306 -- bother after the first instance.
4309 Source_Names
.Get
(File_Id
) = No_Name_Location
4311 Source_Found
:= True;
4315 Location
=> Element
.Location
,
4319 Element_Id
:= Element
.Next
;
4322 -- If there is at least one naming exception, record
4323 -- those that are found in the source directories.
4325 if Source_Found
then
4326 Record_Other_Sources
4327 (Project
=> Project
,
4331 Naming_Exceptions
=> True);
4337 -- Now, check if a list of sources is declared either through
4338 -- a string list (attribute Source_Files) or a text file
4339 -- (attribute Source_List_File). If a source list is declared,
4340 -- we will consider only those naming exceptions that are
4344 Sources
: constant Variable_Value
:=
4347 Data
.Decl
.Attributes
,
4350 Source_List_File
: constant Variable_Value
:=
4352 (Name_Source_List_File
,
4353 Data
.Decl
.Attributes
,
4358 (Sources
.Kind
= List
,
4359 "Source_Files is not a list");
4362 (Source_List_File
.Kind
= Single
,
4363 "Source_List_File is not a single string");
4365 if not Sources
.Default
then
4366 if not Source_List_File
.Default
then
4369 "?both variables source_files and " &
4370 "source_list_file are present",
4371 Source_List_File
.Location
);
4374 -- Sources is a list of file names
4377 Current
: String_List_Id
:= Sources
.Values
;
4378 Element
: String_Element
;
4379 Location
: Source_Ptr
;
4385 -- Put all the sources in the Source_Names hash table
4387 while Current
/= Nil_String
loop
4389 In_Tree
.String_Elements
.Table
4391 Get_Name_String
(Element
.Value
);
4392 Canonical_Case_File_Name
4393 (Name_Buffer
(1 .. Name_Len
));
4396 -- If the element has no location, then use the
4397 -- location of Sources to report possible errors.
4399 if Element
.Location
= No_Location
then
4400 Location
:= Sources
.Location
;
4402 Location
:= Element
.Location
;
4409 Location
=> Location
,
4412 Current
:= Element
.Next
;
4415 -- And look for their directories
4417 Record_Other_Sources
4418 (Project
=> Project
,
4422 Naming_Exceptions
=> False);
4425 -- No source_files specified
4427 -- We check if Source_List_File has been specified
4429 elsif not Source_List_File
.Default
then
4431 -- Source_List_File is the name of the file
4432 -- that contains the source file names
4435 Source_File_Path_Name
: constant String :=
4437 (Source_List_File
.Value
,
4441 if Source_File_Path_Name
'Length = 0 then
4442 Err_Vars
.Error_Msg_Name_1
:=
4443 Source_List_File
.Value
;
4446 "file with sources { does not exist",
4447 Source_List_File
.Location
);
4450 -- Read the file, putting each source in the
4451 -- Source_Names hash table.
4453 Get_Sources_From_File
4454 (Source_File_Path_Name
,
4455 Source_List_File
.Location
,
4458 -- And look for their directories
4460 Record_Other_Sources
4461 (Project
=> Project
,
4465 Naming_Exceptions
=> False);
4469 -- Neither Source_Files nor Source_List_File was specified
4472 -- Find all the files that satisfy the naming scheme in
4473 -- all the source directories. All the naming exceptions
4474 -- that effectively exist are also part of the source
4475 -- of this language.
4477 Find_Sources
(Project
, In_Tree
, Data
, Lang
);
4483 end Look_For_Sources
;
4489 function Path_Name_Of
4490 (File_Name
: Name_Id
;
4491 Directory
: Name_Id
) return String
4493 Result
: String_Access
;
4495 The_Directory
: constant String := Get_Name_String
(Directory
);
4498 Get_Name_String
(File_Name
);
4499 Result
:= Locate_Regular_File
4500 (File_Name
=> Name_Buffer
(1 .. Name_Len
),
4501 Path
=> The_Directory
);
4503 if Result
= null then
4506 Canonical_Case_File_Name
(Result
.all);
4511 -------------------------------
4512 -- Prepare_Ada_Naming_Exceptions --
4513 -------------------------------
4515 procedure Prepare_Ada_Naming_Exceptions
4516 (List
: Array_Element_Id
;
4517 In_Tree
: Project_Tree_Ref
;
4518 Kind
: Spec_Or_Body
)
4520 Current
: Array_Element_Id
:= List
;
4521 Element
: Array_Element
;
4526 -- Traverse the list
4528 while Current
/= No_Array_Element
loop
4529 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
4531 if Element
.Index
/= No_Name
then
4534 Unit
=> Element
.Index
,
4535 Next
=> No_Ada_Naming_Exception
);
4536 Reverse_Ada_Naming_Exceptions
.Set
4537 (Unit
, (Element
.Value
.Value
, Element
.Value
.Index
));
4538 Unit
.Next
:= Ada_Naming_Exceptions
.Get
(Element
.Value
.Value
);
4539 Ada_Naming_Exception_Table
.Increment_Last
;
4540 Ada_Naming_Exception_Table
.Table
4541 (Ada_Naming_Exception_Table
.Last
) := Unit
;
4542 Ada_Naming_Exceptions
.Set
4543 (Element
.Value
.Value
, Ada_Naming_Exception_Table
.Last
);
4546 Current
:= Element
.Next
;
4548 end Prepare_Ada_Naming_Exceptions
;
4550 ---------------------
4551 -- Project_Extends --
4552 ---------------------
4554 function Project_Extends
4555 (Extending
: Project_Id
;
4556 Extended
: Project_Id
;
4557 In_Tree
: Project_Tree_Ref
) return Boolean
4559 Current
: Project_Id
:= Extending
;
4562 if Current
= No_Project
then
4565 elsif Current
= Extended
then
4569 Current
:= In_Tree
.Projects
.Table
(Current
).Extends
;
4571 end Project_Extends
;
4573 -----------------------
4574 -- Record_Ada_Source --
4575 -----------------------
4577 procedure Record_Ada_Source
4578 (File_Name
: Name_Id
;
4579 Path_Name
: Name_Id
;
4580 Project
: Project_Id
;
4581 In_Tree
: Project_Tree_Ref
;
4582 Data
: in out Project_Data
;
4583 Location
: Source_Ptr
;
4584 Current_Source
: in out String_List_Id
;
4585 Source_Recorded
: in out Boolean;
4586 Follow_Links
: Boolean)
4588 Canonical_File_Name
: Name_Id
;
4589 Canonical_Path_Name
: Name_Id
;
4591 Exception_Id
: Ada_Naming_Exception_Id
;
4592 Unit_Name
: Name_Id
;
4593 Unit_Kind
: Spec_Or_Body
;
4594 Unit_Index
: Int
:= 0;
4596 Name_Index
: Name_And_Index
;
4597 Needs_Pragma
: Boolean;
4599 The_Location
: Source_Ptr
:= Location
;
4600 Previous_Source
: constant String_List_Id
:= Current_Source
;
4601 Except_Name
: Name_And_Index
:= No_Name_And_Index
;
4603 Unit_Prj
: Unit_Project
;
4605 File_Name_Recorded
: Boolean := False;
4608 Get_Name_String
(File_Name
);
4609 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4610 Canonical_File_Name
:= Name_Find
;
4613 Canonical_Path
: constant String :=
4615 (Get_Name_String
(Path_Name
),
4616 Resolve_Links
=> Follow_Links
,
4617 Case_Sensitive
=> False);
4620 Add_Str_To_Name_Buffer
(Canonical_Path
);
4621 Canonical_Path_Name
:= Name_Find
;
4624 -- Find out the unit name, the unit kind and if it needs
4625 -- a specific SFN pragma.
4628 (Canonical_File_Name
=> Canonical_File_Name
,
4629 Naming
=> Data
.Naming
,
4630 Exception_Id
=> Exception_Id
,
4631 Unit_Name
=> Unit_Name
,
4632 Unit_Kind
=> Unit_Kind
,
4633 Needs_Pragma
=> Needs_Pragma
);
4635 if Exception_Id
= No_Ada_Naming_Exception
and then
4638 if Current_Verbosity
= High
then
4640 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4641 Write_Line
(""" is not a valid source file name (ignored).");
4645 -- Check to see if the source has been hidden by an exception,
4646 -- but only if it is not an exception.
4648 if not Needs_Pragma
then
4650 Reverse_Ada_Naming_Exceptions
.Get
4651 ((Unit_Kind
, Unit_Name
, No_Ada_Naming_Exception
));
4653 if Except_Name
/= No_Name_And_Index
then
4654 if Current_Verbosity
= High
then
4656 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4657 Write_Str
(""" contains a unit that is found in """);
4658 Write_Str
(Get_Name_String
(Except_Name
.Name
));
4659 Write_Line
(""" (ignored).");
4662 -- The file is not included in the source of the project,
4663 -- because it is hidden by the exception.
4664 -- So, there is nothing else to do.
4671 if Exception_Id
/= No_Ada_Naming_Exception
then
4672 Info
:= Ada_Naming_Exception_Table
.Table
(Exception_Id
);
4673 Exception_Id
:= Info
.Next
;
4674 Info
.Next
:= No_Ada_Naming_Exception
;
4675 Name_Index
:= Reverse_Ada_Naming_Exceptions
.Get
(Info
);
4677 Unit_Name
:= Info
.Unit
;
4678 Unit_Index
:= Name_Index
.Index
;
4679 Unit_Kind
:= Info
.Kind
;
4682 -- Put the file name in the list of sources of the project
4684 if not File_Name_Recorded
then
4685 String_Element_Table
.Increment_Last
4686 (In_Tree
.String_Elements
);
4687 In_Tree
.String_Elements
.Table
4688 (String_Element_Table
.Last
4689 (In_Tree
.String_Elements
)) :=
4690 (Value
=> Canonical_File_Name
,
4691 Display_Value
=> File_Name
,
4692 Location
=> No_Location
,
4695 Index
=> Unit_Index
);
4698 if Current_Source
= Nil_String
then
4699 Data
.Sources
:= String_Element_Table
.Last
4700 (In_Tree
.String_Elements
);
4702 In_Tree
.String_Elements
.Table
4703 (Current_Source
).Next
:=
4704 String_Element_Table
.Last
4705 (In_Tree
.String_Elements
);
4708 Current_Source
:= String_Element_Table
.Last
4709 (In_Tree
.String_Elements
);
4711 -- Put the unit in unit list
4714 The_Unit
: Unit_Id
:=
4715 Units_Htable
.Get
(In_Tree
.Units_HT
, Unit_Name
);
4716 The_Unit_Data
: Unit_Data
;
4719 if Current_Verbosity
= High
then
4720 Write_Str
("Putting ");
4721 Write_Str
(Get_Name_String
(Unit_Name
));
4722 Write_Line
(" in the unit list.");
4725 -- The unit is already in the list, but may be it is
4726 -- only the other unit kind (spec or body), or what is
4727 -- in the unit list is a unit of a project we are extending.
4729 if The_Unit
/= No_Unit
then
4730 The_Unit_Data
:= In_Tree
.Units
.Table
(The_Unit
);
4732 if The_Unit_Data
.File_Names
(Unit_Kind
).Name
= No_Name
4733 or else Project_Extends
4735 The_Unit_Data
.File_Names
(Unit_Kind
).Project
,
4738 if The_Unit_Data
.File_Names
(Unit_Kind
).Path
= Slash
then
4739 Remove_Forbidden_File_Name
4740 (The_Unit_Data
.File_Names
(Unit_Kind
).Name
);
4743 -- Record the file name in the hash table Files_Htable
4745 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4748 Canonical_File_Name
,
4751 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4752 (Name
=> Canonical_File_Name
,
4753 Index
=> Unit_Index
,
4754 Display_Name
=> File_Name
,
4755 Path
=> Canonical_Path_Name
,
4756 Display_Path
=> Path_Name
,
4758 Needs_Pragma
=> Needs_Pragma
);
4759 In_Tree
.Units
.Table
(The_Unit
) :=
4761 Source_Recorded
:= True;
4763 elsif The_Unit_Data
.File_Names
(Unit_Kind
).Project
= Project
4764 and then (Data
.Known_Order_Of_Source_Dirs
or else
4765 The_Unit_Data
.File_Names
(Unit_Kind
).Path
=
4766 Canonical_Path_Name
)
4768 if Previous_Source
= Nil_String
then
4769 Data
.Sources
:= Nil_String
;
4771 In_Tree
.String_Elements
.Table
4772 (Previous_Source
).Next
:= Nil_String
;
4773 String_Element_Table
.Decrement_Last
4774 (In_Tree
.String_Elements
);
4777 Current_Source
:= Previous_Source
;
4780 -- It is an error to have two units with the same name
4781 -- and the same kind (spec or body).
4783 if The_Location
= No_Location
then
4785 In_Tree
.Projects
.Table
4789 Err_Vars
.Error_Msg_Name_1
:= Unit_Name
;
4791 (Project
, In_Tree
, "duplicate source {", The_Location
);
4793 Err_Vars
.Error_Msg_Name_1
:=
4794 In_Tree
.Projects
.Table
4795 (The_Unit_Data
.File_Names
(Unit_Kind
).Project
).Name
;
4796 Err_Vars
.Error_Msg_Name_2
:=
4797 The_Unit_Data
.File_Names
(Unit_Kind
).Path
;
4800 "\ project file {, {", The_Location
);
4802 Err_Vars
.Error_Msg_Name_1
:=
4803 In_Tree
.Projects
.Table
(Project
).Name
;
4804 Err_Vars
.Error_Msg_Name_2
:= Canonical_Path_Name
;
4807 "\ project file {, {", The_Location
);
4810 -- It is a new unit, create a new record
4813 -- First, check if there is no other unit with this file
4814 -- name in another project. If it is, report an error.
4815 -- Of course, we do that only for the first unit in the
4818 Unit_Prj
:= Files_Htable
.Get
4819 (In_Tree
.Files_HT
, Canonical_File_Name
);
4821 if not File_Name_Recorded
and then
4822 Unit_Prj
/= No_Unit_Project
4824 Error_Msg_Name_1
:= File_Name
;
4826 In_Tree
.Projects
.Table
4827 (Unit_Prj
.Project
).Name
;
4830 "{ is already a source of project {",
4834 Unit_Table
.Increment_Last
(In_Tree
.Units
);
4835 The_Unit
:= Unit_Table
.Last
(In_Tree
.Units
);
4837 (In_Tree
.Units_HT
, Unit_Name
, The_Unit
);
4838 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4841 Canonical_File_Name
,
4843 The_Unit_Data
.Name
:= Unit_Name
;
4844 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4845 (Name
=> Canonical_File_Name
,
4846 Index
=> Unit_Index
,
4847 Display_Name
=> File_Name
,
4848 Path
=> Canonical_Path_Name
,
4849 Display_Path
=> Path_Name
,
4851 Needs_Pragma
=> Needs_Pragma
);
4852 In_Tree
.Units
.Table
(The_Unit
) :=
4854 Source_Recorded
:= True;
4859 exit when Exception_Id
= No_Ada_Naming_Exception
;
4860 File_Name_Recorded
:= True;
4863 end Record_Ada_Source
;
4865 --------------------------
4866 -- Record_Other_Sources --
4867 --------------------------
4869 procedure Record_Other_Sources
4870 (Project
: Project_Id
;
4871 In_Tree
: Project_Tree_Ref
;
4872 Data
: in out Project_Data
;
4873 Language
: Language_Index
;
4874 Naming_Exceptions
: Boolean)
4876 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
4877 Element
: String_Element
;
4881 Canonical_Name
: Name_Id
;
4883 Name_Str
: String (1 .. 1_024
);
4884 Last
: Natural := 0;
4887 First_Error
: Boolean := True;
4889 Suffix
: constant String := Body_Suffix_Of
(Language
, Data
, In_Tree
);
4892 while Source_Dir
/= Nil_String
loop
4893 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
4896 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
4899 if Current_Verbosity
= High
then
4900 Write_Str
("checking directory """);
4901 Write_Str
(Dir_Path
);
4902 Write_Str
(""" for ");
4904 if Naming_Exceptions
then
4905 Write_Str
("naming exceptions");
4908 Write_Str
("sources");
4911 Write_Str
(" of Language ");
4912 Display_Language_Name
(Language
);
4915 Open
(Dir
, Dir_Path
);
4918 Read
(Dir
, Name_Str
, Last
);
4922 (Dir_Path
& Directory_Separator
& Name_Str
(1 .. Last
))
4925 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
4926 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4927 Canonical_Name
:= Name_Find
;
4928 NL
:= Source_Names
.Get
(Canonical_Name
);
4930 if NL
/= No_Name_Location
then
4932 if not Data
.Known_Order_Of_Source_Dirs
then
4933 Error_Msg_Name_1
:= Canonical_Name
;
4936 "{ is found in several source directories",
4942 Source_Names
.Set
(Canonical_Name
, NL
);
4943 Name_Len
:= Dir_Path
'Length;
4944 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
4945 Add_Char_To_Name_Buffer
(Directory_Separator
);
4946 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
4950 (File_Name
=> Canonical_Name
,
4955 Location
=> NL
.Location
,
4956 Language
=> Language
,
4958 Naming_Exception
=> Naming_Exceptions
);
4967 Source_Dir
:= Element
.Next
;
4970 if not Naming_Exceptions
then
4971 NL
:= Source_Names
.Get_First
;
4973 -- It is an error if a source file name in a source list or
4974 -- in a source list file is not found.
4976 while NL
/= No_Name_Location
loop
4977 if not NL
.Found
then
4978 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
4983 "source file { cannot be found",
4985 First_Error
:= False;
4990 "\source file { cannot be found",
4995 NL
:= Source_Names
.Get_Next
;
4998 -- Any naming exception of this language that is not in a list
4999 -- of sources must be removed.
5002 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
5003 Prev_Id
: Other_Source_Id
:= No_Other_Source
;
5004 Source
: Other_Source
;
5007 while Source_Id
/= No_Other_Source
loop
5008 Source
:= In_Tree
.Other_Sources
.Table
(Source_Id
);
5010 if Source
.Language
= Language
5011 and then Source
.Naming_Exception
5013 if Current_Verbosity
= High
then
5014 Write_Str
("Naming exception """);
5015 Write_Str
(Get_Name_String
(Source
.File_Name
));
5016 Write_Str
(""" is not in the list of sources,");
5017 Write_Line
(" so it is removed.");
5020 if Prev_Id
= No_Other_Source
then
5021 Data
.First_Other_Source
:= Source
.Next
;
5024 In_Tree
.Other_Sources
.Table
5025 (Prev_Id
).Next
:= Source
.Next
;
5028 Source_Id
:= Source
.Next
;
5030 if Source_Id
= No_Other_Source
then
5031 Data
.Last_Other_Source
:= Prev_Id
;
5035 Prev_Id
:= Source_Id
;
5036 Source_Id
:= Source
.Next
;
5041 end Record_Other_Sources
;
5043 ----------------------
5044 -- Show_Source_Dirs --
5045 ----------------------
5047 procedure Show_Source_Dirs
5048 (Project
: Project_Id
;
5049 In_Tree
: Project_Tree_Ref
)
5051 Current
: String_List_Id
;
5052 Element
: String_Element
;
5055 Write_Line
("Source_Dirs:");
5057 Current
:= In_Tree
.Projects
.Table
(Project
).Source_Dirs
;
5058 while Current
/= Nil_String
loop
5059 Element
:= In_Tree
.String_Elements
.Table
(Current
);
5061 Write_Line
(Get_Name_String
(Element
.Value
));
5062 Current
:= Element
.Next
;
5065 Write_Line
("end Source_Dirs.");
5066 end Show_Source_Dirs
;
5073 (Language
: Language_Index
;
5074 Naming
: Naming_Data
;
5075 In_Tree
: Project_Tree_Ref
) return Name_Id
5077 Suffix
: constant Variable_Value
:=
5079 (Index
=> Language_Names
.Table
(Language
),
5081 In_Array
=> Naming
.Body_Suffix
,
5082 In_Tree
=> In_Tree
);
5084 -- If no suffix for this language in package Naming, use the default
5086 if Suffix
= Nil_Variable_Value
then
5090 when Ada_Language_Index
=>
5091 Add_Str_To_Name_Buffer
(".adb");
5093 when C_Language_Index
=>
5094 Add_Str_To_Name_Buffer
(".c");
5096 when C_Plus_Plus_Language_Index
=>
5097 Add_Str_To_Name_Buffer
(".cpp");
5103 -- Otherwise use the one specified
5106 Get_Name_String
(Suffix
.Value
);
5109 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
5113 -------------------------
5114 -- Warn_If_Not_Sources --
5115 -------------------------
5117 -- comments needed in this body ???
5119 procedure Warn_If_Not_Sources
5120 (Project
: Project_Id
;
5121 In_Tree
: Project_Tree_Ref
;
5122 Conventions
: Array_Element_Id
;
5124 Extending
: Boolean)
5126 Conv
: Array_Element_Id
:= Conventions
;
5128 The_Unit_Id
: Unit_Id
;
5129 The_Unit_Data
: Unit_Data
;
5130 Location
: Source_Ptr
;
5133 while Conv
/= No_Array_Element
loop
5134 Unit
:= In_Tree
.Array_Elements
.Table
(Conv
).Index
;
5135 Error_Msg_Name_1
:= Unit
;
5136 Get_Name_String
(Unit
);
5137 To_Lower
(Name_Buffer
(1 .. Name_Len
));
5139 The_Unit_Id
:= Units_Htable
.Get
5140 (In_Tree
.Units_HT
, Unit
);
5141 Location
:= In_Tree
.Array_Elements
.Table
5142 (Conv
).Value
.Location
;
5144 if The_Unit_Id
= No_Unit
then
5151 The_Unit_Data
:= In_Tree
.Units
.Table
(The_Unit_Id
);
5154 if not Check_Project
5155 (The_Unit_Data
.File_Names
(Specification
).Project
,
5156 Project
, In_Tree
, Extending
)
5160 "?unit{ has no spec in this project",
5165 if not Check_Project
5166 (The_Unit_Data
.File_Names
(Body_Part
).Project
,
5167 Project
, In_Tree
, Extending
)
5171 "?unit{ has no body in this project",
5177 Conv
:= In_Tree
.Array_Elements
.Table
(Conv
).Next
;
5179 end Warn_If_Not_Sources
;