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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Err_Vars
; use Err_Vars
;
31 with Namet
; use Namet
;
32 with Osint
; use Osint
;
33 with Output
; use Output
;
34 with MLib
.Tgt
; use MLib
.Tgt
;
35 with Prj
.Env
; use Prj
.Env
;
37 with Prj
.Util
; use Prj
.Util
;
39 with Snames
; use Snames
;
40 with Table
; use Table
;
41 with Types
; use Types
;
43 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
44 with Ada
.Strings
; use Ada
.Strings
;
45 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
46 with Ada
.Strings
.Maps
.Constants
; use Ada
.Strings
.Maps
.Constants
;
48 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
49 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
50 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
53 package body Prj
.Nmsc
is
55 Error_Report
: Put_Line_Access
:= null;
56 -- Set to point to error reporting procedure
58 ALI_Suffix
: constant String := ".ali";
59 -- File suffix for ali files
61 Object_Suffix
: constant String := Get_Object_Suffix
.all;
62 -- File suffix for object files
64 type Name_Location
is record
66 Location
: Source_Ptr
;
67 Found
: Boolean := False;
69 -- Information about file names found in string list attribute
70 -- Source_Files or in a source list file, stored in hash table
71 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
73 No_Name_Location
: constant Name_Location
:=
74 (Name
=> No_Name
, Location
=> No_Location
, Found
=> False);
76 package Source_Names
is new GNAT
.HTable
.Simple_HTable
77 (Header_Num
=> Header_Num
,
78 Element
=> Name_Location
,
79 No_Element
=> No_Name_Location
,
83 -- Hash table to store file names found in string list attribute
84 -- Source_Files or in a source list file, stored in hash table
85 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
87 package Recursive_Dirs
is new GNAT
.HTable
.Simple_HTable
88 (Header_Num
=> Header_Num
,
94 -- Hash table to store recursive source directories, to avoid looking
95 -- several times, and to avoid cycles that may be introduced by symbolic
98 type Ada_Naming_Exception_Id
is new Nat
;
99 No_Ada_Naming_Exception
: constant Ada_Naming_Exception_Id
:= 0;
101 type Unit_Info
is record
104 Next
: Ada_Naming_Exception_Id
:= No_Ada_Naming_Exception
;
106 -- No_Unit : constant Unit_Info :=
107 -- (Specification, No_Name, No_Ada_Naming_Exception);
109 package Ada_Naming_Exception_Table
is new Table
.Table
110 (Table_Component_Type
=> Unit_Info
,
111 Table_Index_Type
=> Ada_Naming_Exception_Id
,
112 Table_Low_Bound
=> 1,
114 Table_Increment
=> 100,
115 Table_Name
=> "Prj.Nmsc.Ada_Naming_Exception_Table");
117 package Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
118 (Header_Num
=> Header_Num
,
119 Element
=> Ada_Naming_Exception_Id
,
120 No_Element
=> No_Ada_Naming_Exception
,
124 -- A hash table to store naming exceptions for Ada. For each file name
125 -- there is one or several unit in table Ada_Naming_Exception_Table.
127 function Hash
(Unit
: Unit_Info
) return Header_Num
;
129 type Name_And_Index
is record
130 Name
: Name_Id
:= No_Name
;
133 No_Name_And_Index
: constant Name_And_Index
:=
134 (Name
=> No_Name
, Index
=> 0);
136 package Reverse_Ada_Naming_Exceptions
is new GNAT
.HTable
.Simple_HTable
137 (Header_Num
=> Header_Num
,
138 Element
=> Name_And_Index
,
139 No_Element
=> No_Name_And_Index
,
143 -- A table to check if a unit with an exceptional name will hide
144 -- a source with a file name following the naming convention.
146 function ALI_File_Name
(Source
: String) return String;
147 -- Return the ALI file name corresponding to a source
149 procedure Check_Ada_Name
(Name
: String; Unit
: out Name_Id
);
150 -- Check that a name is a valid Ada unit name
152 procedure Check_Naming_Scheme
153 (Data
: in out Project_Data
;
154 Project
: Project_Id
;
155 In_Tree
: Project_Tree_Ref
);
156 -- Check the naming scheme part of Data
158 procedure Check_Ada_Naming_Scheme_Validity
159 (Project
: Project_Id
;
160 In_Tree
: Project_Tree_Ref
;
161 Naming
: Naming_Data
);
162 -- Check that the package Naming is correct
164 procedure Check_For_Source
165 (File_Name
: Name_Id
;
167 Project
: Project_Id
;
168 In_Tree
: Project_Tree_Ref
;
169 Data
: in out Project_Data
;
170 Location
: Source_Ptr
;
171 Language
: Language_Index
;
173 Naming_Exception
: Boolean);
174 -- Check if a file, with name File_Name and path Path_Name, in a source
175 -- directory is a source for language Language in project Project of
176 -- project tree In_Tree. ???
178 procedure Check_If_Externally_Built
179 (Project
: Project_Id
;
180 In_Tree
: Project_Tree_Ref
;
181 Data
: in out Project_Data
);
182 -- Check attribute Externally_Built of project Project in project tree
183 -- In_Tree and modify its data Data if it has the value "true".
185 procedure Check_Library_Attributes
186 (Project
: Project_Id
;
187 In_Tree
: Project_Tree_Ref
;
188 Data
: in out Project_Data
);
189 -- Check the library attributes of project Project in project tree In_Tree
190 -- and modify its data Data accordingly.
192 procedure Check_Package_Naming
193 (Project
: Project_Id
;
194 In_Tree
: Project_Tree_Ref
;
195 Data
: in out Project_Data
);
196 -- Check package Naming of project Project in project tree In_Tree and
197 -- modify its data Data accordingly.
199 procedure Check_Programming_Languages
200 (In_Tree
: Project_Tree_Ref
; Data
: in out Project_Data
);
201 -- Check attribute Languages for the project with data Data in project
202 -- tree In_Tree and set the components of Data for all the programming
203 -- languages indicated in attribute Languages, if any.
205 function Check_Project
207 Root_Project
: Project_Id
;
208 In_Tree
: Project_Tree_Ref
;
209 Extending
: Boolean) return Boolean;
210 -- Returns True if P is Root_Project or, if Extending is True, a project
211 -- extended by Root_Project.
213 procedure Check_Stand_Alone_Library
214 (Project
: Project_Id
;
215 In_Tree
: Project_Tree_Ref
;
216 Data
: in out Project_Data
;
217 Extending
: Boolean);
218 -- Check if project Project in project tree In_Tree is a Stand-Alone
219 -- Library project, and modify its data Data accordingly if it is one.
221 function Compute_Directory_Last
(Dir
: String) return Natural;
222 -- Return the index of the last significant character in Dir. This is used
223 -- to avoid duplicates '/' at the end of directory names
225 function Body_Suffix_Of
226 (Language
: Language_Index
;
227 In_Project
: Project_Data
;
228 In_Tree
: Project_Tree_Ref
)
230 -- Returns the suffix of sources of language Language in project In_Project
231 -- in project tree In_Tree.
234 (Project
: Project_Id
;
235 In_Tree
: Project_Tree_Ref
;
237 Flag_Location
: Source_Ptr
);
238 -- Output an error message. If Error_Report is null, simply call
239 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
242 procedure Find_Sources
243 (Project
: Project_Id
;
244 In_Tree
: Project_Tree_Ref
;
245 Data
: in out Project_Data
;
246 For_Language
: Language_Index
;
247 Follow_Links
: Boolean := False);
248 -- Find all the sources in all of the source directories of a project for
249 -- a specified language.
251 procedure Free_Ada_Naming_Exceptions
;
252 -- Free the internal hash tables used for checking naming exceptions
254 procedure Get_Directories
255 (Project
: Project_Id
;
256 In_Tree
: Project_Tree_Ref
;
257 Data
: in out Project_Data
);
258 -- Get the object directory, the exec directory and the source directories
262 (Project
: Project_Id
;
263 In_Tree
: Project_Tree_Ref
;
264 Data
: in out Project_Data
);
265 -- Get the mains of a project from attribute Main, if it exists, and put
266 -- them in the project data.
268 procedure Get_Sources_From_File
270 Location
: Source_Ptr
;
271 Project
: Project_Id
;
272 In_Tree
: Project_Tree_Ref
);
273 -- Get the list of sources from a text file and put them in hash table
277 (Canonical_File_Name
: Name_Id
;
278 Naming
: Naming_Data
;
279 Exception_Id
: out Ada_Naming_Exception_Id
;
280 Unit_Name
: out Name_Id
;
281 Unit_Kind
: out Spec_Or_Body
;
282 Needs_Pragma
: out Boolean);
283 -- Find out, from a file name, the unit name, the unit kind and if a
284 -- specific SFN pragma is needed. If the file name corresponds to no
285 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
286 -- or an exception to the naming scheme, then Exception_Id is set to
287 -- the unit or units that the source contains.
289 function Is_Illegal_Suffix
291 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean;
292 -- Returns True if the string Suffix cannot be used as
293 -- a spec suffix, a body suffix or a separate suffix.
295 procedure Locate_Directory
299 Display
: out Name_Id
);
300 -- Locate a directory (returns No_Name for Dir and Display if directory
301 -- does not exist). Name is the directory name. Parent is the root
302 -- directory, if Name is a relative path name. Dir is the canonical case
303 -- path name of the directory, Display is the directory path name for
306 procedure Look_For_Sources
307 (Project
: Project_Id
;
308 In_Tree
: Project_Tree_Ref
;
309 Data
: in out Project_Data
;
310 Follow_Links
: Boolean);
311 -- Find all the sources of a project
313 function Path_Name_Of
314 (File_Name
: Name_Id
;
315 Directory
: Name_Id
) return String;
316 -- Returns the path name of a (non project) file.
317 -- Returns an empty string if file cannot be found.
319 procedure Prepare_Ada_Naming_Exceptions
320 (List
: Array_Element_Id
;
321 In_Tree
: Project_Tree_Ref
;
322 Kind
: Spec_Or_Body
);
323 -- Prepare the internal hash tables used for checking naming exceptions
324 -- for Ada. Insert all elements of List in the tables.
326 function Project_Extends
327 (Extending
: Project_Id
;
328 Extended
: Project_Id
;
329 In_Tree
: Project_Tree_Ref
) return Boolean;
330 -- Returns True if Extending is extending Extended either directly or
333 procedure Record_Ada_Source
334 (File_Name
: Name_Id
;
336 Project
: Project_Id
;
337 In_Tree
: Project_Tree_Ref
;
338 Data
: in out Project_Data
;
339 Location
: Source_Ptr
;
340 Current_Source
: in out String_List_Id
;
341 Source_Recorded
: in out Boolean;
342 Follow_Links
: Boolean);
343 -- Put a unit in the list of units of a project, if the file name
344 -- corresponds to a valid unit name.
346 procedure Record_Other_Sources
347 (Project
: Project_Id
;
348 In_Tree
: Project_Tree_Ref
;
349 Data
: in out Project_Data
;
350 Language
: Language_Index
;
351 Naming_Exceptions
: Boolean);
352 -- Record the sources of a language in a project.
353 -- When Naming_Exceptions is True, mark the found sources as such, to
354 -- later remove those that are not named in a list of sources.
356 procedure Show_Source_Dirs
357 (Project
: Project_Id
; In_Tree
: Project_Tree_Ref
);
358 -- List all the source directories of a project
361 (Language
: Language_Index
;
362 Naming
: Naming_Data
;
363 In_Tree
: Project_Tree_Ref
) return Name_Id
;
364 -- Get the suffix for the source of a language from a package naming.
365 -- If not specified, return the default for the language.
367 procedure Warn_If_Not_Sources
368 (Project
: Project_Id
;
369 In_Tree
: Project_Tree_Ref
;
370 Conventions
: Array_Element_Id
;
372 Extending
: Boolean);
373 -- Check that individual naming conventions apply to immediate
374 -- sources of the project; if not, issue a warning.
380 function ALI_File_Name
(Source
: String) return String is
382 -- If the source name has an extension, then replace it with
385 for Index
in reverse Source
'First + 1 .. Source
'Last loop
386 if Source
(Index
) = '.' then
387 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
391 -- If there is no dot, or if it is the first character, just add the
394 return Source
& ALI_Suffix
;
402 (Project
: Project_Id
;
403 In_Tree
: Project_Tree_Ref
;
404 Report_Error
: Put_Line_Access
;
405 Follow_Links
: Boolean)
407 Data
: Project_Data
:= In_Tree
.Projects
.Table
(Project
);
408 Extending
: Boolean := False;
411 Error_Report
:= Report_Error
;
413 Recursive_Dirs
.Reset
;
415 -- Object, exec and source directories
417 Get_Directories
(Project
, In_Tree
, Data
);
419 -- Get the programming languages
421 Check_Programming_Languages
(In_Tree
, Data
);
423 -- Library attributes
425 Check_Library_Attributes
(Project
, In_Tree
, Data
);
427 Check_If_Externally_Built
(Project
, In_Tree
, Data
);
429 if Current_Verbosity
= High
then
430 Show_Source_Dirs
(Project
, In_Tree
);
433 Check_Package_Naming
(Project
, In_Tree
, Data
);
435 Extending
:= Data
.Extends
/= No_Project
;
437 Check_Naming_Scheme
(Data
, Project
, In_Tree
);
439 Prepare_Ada_Naming_Exceptions
440 (Data
.Naming
.Bodies
, In_Tree
, Body_Part
);
441 Prepare_Ada_Naming_Exceptions
442 (Data
.Naming
.Specs
, In_Tree
, Specification
);
446 if Data
.Source_Dirs
/= Nil_String
then
447 Look_For_Sources
(Project
, In_Tree
, Data
, Follow_Links
);
450 if Data
.Ada_Sources_Present
then
452 -- Check that all individual naming conventions apply to sources of
453 -- this project file.
456 (Project
, In_Tree
, Data
.Naming
.Bodies
,
458 Extending
=> Extending
);
460 (Project
, In_Tree
, Data
.Naming
.Specs
,
462 Extending
=> Extending
);
465 -- If it is a library project file, check if it is a standalone library
468 Check_Stand_Alone_Library
(Project
, In_Tree
, Data
, Extending
);
471 -- Put the list of Mains, if any, in the project data
473 Get_Mains
(Project
, In_Tree
, Data
);
475 -- Update the project data in the Projects table
477 In_Tree
.Projects
.Table
(Project
) := Data
;
479 Free_Ada_Naming_Exceptions
;
486 procedure Check_Ada_Name
(Name
: String; Unit
: out Name_Id
) is
487 The_Name
: String := Name
;
489 Need_Letter
: Boolean := True;
490 Last_Underscore
: Boolean := False;
491 OK
: Boolean := The_Name
'Length > 0;
496 Name_Len
:= The_Name
'Length;
497 Name_Buffer
(1 .. Name_Len
) := The_Name
;
498 Real_Name
:= Name_Find
;
500 -- Check first that the given name is not an Ada reserved word
502 if Get_Name_Table_Byte
(Real_Name
) /= 0
503 and then Real_Name
/= Name_Project
504 and then Real_Name
/= Name_Extends
505 and then Real_Name
/= Name_External
509 if Current_Verbosity
= High
then
510 Write_Str
(The_Name
);
511 Write_Line
(" is an Ada reserved word.");
517 for Index
in The_Name
'Range loop
520 -- We need a letter (at the beginning, and following a dot),
521 -- but we don't have one.
523 if Is_Letter
(The_Name
(Index
)) then
524 Need_Letter
:= False;
529 if Current_Verbosity
= High
then
530 Write_Int
(Types
.Int
(Index
));
532 Write_Char
(The_Name
(Index
));
533 Write_Line
("' is not a letter.");
539 elsif Last_Underscore
540 and then (The_Name
(Index
) = '_' or else The_Name
(Index
) = '.')
542 -- Two underscores are illegal, and a dot cannot follow
547 if Current_Verbosity
= High
then
548 Write_Int
(Types
.Int
(Index
));
550 Write_Char
(The_Name
(Index
));
551 Write_Line
("' is illegal here.");
556 elsif The_Name
(Index
) = '.' then
558 -- We need a letter after a dot
562 elsif The_Name
(Index
) = '_' then
563 Last_Underscore
:= True;
566 -- We need an letter or a digit
568 Last_Underscore
:= False;
570 if not Is_Alphanumeric
(The_Name
(Index
)) then
573 if Current_Verbosity
= High
then
574 Write_Int
(Types
.Int
(Index
));
576 Write_Char
(The_Name
(Index
));
577 Write_Line
("' is not alphanumeric.");
585 -- Cannot end with an underscore or a dot
587 OK
:= OK
and then not Need_Letter
and then not Last_Underscore
;
593 -- Signal a problem with No_Name
599 --------------------------------------
600 -- Check_Ada_Naming_Scheme_Validity --
601 --------------------------------------
603 procedure Check_Ada_Naming_Scheme_Validity
604 (Project
: Project_Id
;
605 In_Tree
: Project_Tree_Ref
;
606 Naming
: Naming_Data
)
609 -- Only check if we are not using the Default naming scheme
611 if Naming
/= In_Tree
.Private_Part
.Default_Naming
then
613 Dot_Replacement
: constant String :=
615 (Naming
.Dot_Replacement
);
617 Spec_Suffix
: constant String :=
619 (Naming
.Ada_Spec_Suffix
);
621 Body_Suffix
: constant String :=
623 (Naming
.Ada_Body_Suffix
);
625 Separate_Suffix
: constant String :=
627 (Naming
.Separate_Suffix
);
630 -- Dot_Replacement cannot
632 -- - start or end with an alphanumeric
634 -- - start with an '_' followed by an alphanumeric
635 -- - contain a '.' except if it is "."
637 if Dot_Replacement
'Length = 0
638 or else Is_Alphanumeric
639 (Dot_Replacement
(Dot_Replacement
'First))
640 or else Is_Alphanumeric
641 (Dot_Replacement
(Dot_Replacement
'Last))
642 or else (Dot_Replacement
(Dot_Replacement
'First) = '_'
644 (Dot_Replacement
'Length = 1
647 (Dot_Replacement
(Dot_Replacement
'First + 1))))
648 or else (Dot_Replacement
'Length > 1
650 Index
(Source
=> Dot_Replacement
,
651 Pattern
=> ".") /= 0)
655 '"' & Dot_Replacement
&
656 """ is illegal for Dot_Replacement.",
657 Naming
.Dot_Repl_Loc
);
664 (Spec_Suffix
, Dot_Replacement
= ".")
666 Err_Vars
.Error_Msg_Name_1
:= Naming
.Ada_Spec_Suffix
;
669 "{ is illegal for Spec_Suffix",
670 Naming
.Spec_Suffix_Loc
);
674 (Body_Suffix
, Dot_Replacement
= ".")
676 Err_Vars
.Error_Msg_Name_1
:= Naming
.Ada_Body_Suffix
;
679 "{ is illegal for Body_Suffix",
680 Naming
.Body_Suffix_Loc
);
683 if Body_Suffix
/= Separate_Suffix
then
685 (Separate_Suffix
, Dot_Replacement
= ".")
687 Err_Vars
.Error_Msg_Name_1
:= Naming
.Separate_Suffix
;
690 "{ is illegal for Separate_Suffix",
691 Naming
.Sep_Suffix_Loc
);
695 -- Spec_Suffix cannot have the same termination as
696 -- Body_Suffix or Separate_Suffix
698 if Spec_Suffix
'Length <= Body_Suffix
'Length
700 Body_Suffix
(Body_Suffix
'Last -
701 Spec_Suffix
'Length + 1 ..
702 Body_Suffix
'Last) = Spec_Suffix
708 """) cannot end with" &
710 Spec_Suffix
& """).",
711 Naming
.Body_Suffix_Loc
);
714 if Body_Suffix
/= Separate_Suffix
715 and then Spec_Suffix
'Length <= Separate_Suffix
'Length
718 (Separate_Suffix
'Last - Spec_Suffix
'Length + 1
720 Separate_Suffix
'Last) = Spec_Suffix
724 "Separate_Suffix (""" &
726 """) cannot end with" &
728 Spec_Suffix
& """).",
729 Naming
.Sep_Suffix_Loc
);
733 end Check_Ada_Naming_Scheme_Validity
;
735 ----------------------
736 -- Check_For_Source --
737 ----------------------
739 procedure Check_For_Source
740 (File_Name
: Name_Id
;
742 Project
: Project_Id
;
743 In_Tree
: Project_Tree_Ref
;
744 Data
: in out Project_Data
;
745 Location
: Source_Ptr
;
746 Language
: Language_Index
;
748 Naming_Exception
: Boolean)
750 Name
: String := Get_Name_String
(File_Name
);
751 Real_Location
: Source_Ptr
:= Location
;
754 Canonical_Case_File_Name
(Name
);
756 -- A file is a source of a language if Naming_Exception is True (case
757 -- of naming exceptions) or if its file name ends with the suffix.
759 if Naming_Exception
or else
760 (Name
'Length > Suffix
'Length and then
761 Name
(Name
'Last - Suffix
'Length + 1 .. Name
'Last) = Suffix
)
763 if Real_Location
= No_Location
then
764 Real_Location
:= Data
.Location
;
768 Path
: String := Get_Name_String
(Path_Name
);
771 -- The path name id (in canonical case)
774 -- The file name id (in canonical case)
777 -- The object file name
779 Obj_Path_Id
: Name_Id
;
780 -- The object path name
783 -- The dependency file name
785 Dep_Path_Id
: Name_Id
;
786 -- The dependency path name
788 Dot_Pos
: Natural := 0;
789 -- Position of the last dot in Name
791 Source
: Other_Source
;
792 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
795 Canonical_Case_File_Name
(Path
);
797 -- Get the file name id
799 Name_Len
:= Name
'Length;
800 Name_Buffer
(1 .. Name_Len
) := Name
;
801 File_Id
:= Name_Find
;
803 -- Get the path name id
805 Name_Len
:= Path
'Length;
806 Name_Buffer
(1 .. Name_Len
) := Path
;
807 Path_Id
:= Name_Find
;
809 -- Find the position of the last dot
811 for J
in reverse Name
'Range loop
812 if Name
(J
) = '.' then
818 if Dot_Pos
<= Name
'First then
819 Dot_Pos
:= Name
'Last + 1;
822 -- Compute the object file name
824 Get_Name_String
(File_Id
);
825 Name_Len
:= Dot_Pos
- Name
'First;
827 for J
in Object_Suffix
'Range loop
828 Name_Len
:= Name_Len
+ 1;
829 Name_Buffer
(Name_Len
) := Object_Suffix
(J
);
834 -- Compute the object path name
836 Get_Name_String
(Data
.Object_Directory
);
838 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
839 Name_Buffer
(Name_Len
) /= '/'
841 Name_Len
:= Name_Len
+ 1;
842 Name_Buffer
(Name_Len
) := Directory_Separator
;
845 Add_Str_To_Name_Buffer
(Get_Name_String
(Obj_Id
));
846 Obj_Path_Id
:= Name_Find
;
848 -- Compute the dependency file name
850 Get_Name_String
(File_Id
);
851 Name_Len
:= Dot_Pos
- Name
'First + 1;
852 Name_Buffer
(Name_Len
) := '.';
853 Name_Len
:= Name_Len
+ 1;
854 Name_Buffer
(Name_Len
) := 'd';
857 -- Compute the dependency path name
859 Get_Name_String
(Data
.Object_Directory
);
861 if Name_Buffer
(Name_Len
) /= Directory_Separator
and then
862 Name_Buffer
(Name_Len
) /= '/'
864 Name_Len
:= Name_Len
+ 1;
865 Name_Buffer
(Name_Len
) := Directory_Separator
;
868 Add_Str_To_Name_Buffer
(Get_Name_String
(Dep_Id
));
869 Dep_Path_Id
:= Name_Find
;
871 -- Check if source is already in the list of source for this
872 -- project: it may have already been specified as a naming
873 -- exception for the same language or an other language, or
874 -- they may be two identical file names in different source
877 while Source_Id
/= No_Other_Source
loop
878 Source
:= In_Tree
.Other_Sources
.Table
(Source_Id
);
879 Source_Id
:= Source
.Next
;
881 if Source
.File_Name
= File_Id
then
883 -- Two sources of different languages cannot have the same
886 if Source
.Language
/= Language
then
887 Error_Msg_Name_1
:= File_Name
;
890 "{ cannot be a source of several languages",
894 -- No problem if a file has already been specified as
895 -- a naming exception of this language.
897 elsif Source
.Path_Name
= Path_Id
then
899 -- Reset the naming exception flag, if this is not a
902 if not Naming_Exception
then
903 In_Tree
.Other_Sources
.Table
904 (Source_Id
).Naming_Exception
:= False;
909 -- There are several files with the same names, but the
910 -- order of the source directories is known (no /**):
911 -- only the first one encountered is kept, the other ones
914 elsif Data
.Known_Order_Of_Source_Dirs
then
917 -- But it is an error if the order of the source directories
921 Error_Msg_Name_1
:= File_Name
;
924 "{ is found in several source directories",
929 -- Two sources with different file names cannot have the same
932 elsif Source
.Object_Name
= Obj_Id
then
933 Error_Msg_Name_1
:= File_Id
;
934 Error_Msg_Name_2
:= Source
.File_Name
;
935 Error_Msg_Name_3
:= Obj_Id
;
938 "{ and { have the same object file {",
944 if Current_Verbosity
= High
then
945 Write_Str
(" found ");
946 Display_Language_Name
(Language
);
947 Write_Str
(" source """);
948 Write_Str
(Get_Name_String
(File_Name
));
950 Write_Str
(" object path = ");
951 Write_Line
(Get_Name_String
(Obj_Path_Id
));
954 -- Create the Other_Source record
957 (Language
=> Language
,
958 File_Name
=> File_Id
,
959 Path_Name
=> Path_Id
,
960 Source_TS
=> File_Stamp
(Path_Id
),
961 Object_Name
=> Obj_Id
,
962 Object_Path
=> Obj_Path_Id
,
963 Object_TS
=> File_Stamp
(Obj_Path_Id
),
965 Dep_Path
=> Dep_Path_Id
,
966 Dep_TS
=> File_Stamp
(Dep_Path_Id
),
967 Naming_Exception
=> Naming_Exception
,
968 Next
=> No_Other_Source
);
970 -- And add it to the Other_Sources table
972 Other_Source_Table
.Increment_Last
973 (In_Tree
.Other_Sources
);
974 In_Tree
.Other_Sources
.Table
975 (Other_Source_Table
.Last
(In_Tree
.Other_Sources
)) :=
978 -- There are sources of languages other than Ada in this project
980 Data
.Other_Sources_Present
:= True;
982 -- And there are sources of this language in this project
984 Set
(Language
, True, Data
, In_Tree
);
986 -- Add this source to the list of sources of languages other than
987 -- Ada of the project.
989 if Data
.First_Other_Source
= No_Other_Source
then
990 Data
.First_Other_Source
:=
991 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
994 In_Tree
.Other_Sources
.Table
(Data
.Last_Other_Source
).Next
:=
995 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
998 Data
.Last_Other_Source
:=
999 Other_Source_Table
.Last
(In_Tree
.Other_Sources
);
1002 end Check_For_Source
;
1004 -------------------------------
1005 -- Check_If_Externally_Built --
1006 -------------------------------
1008 procedure Check_If_Externally_Built
1009 (Project
: Project_Id
;
1010 In_Tree
: Project_Tree_Ref
;
1011 Data
: in out Project_Data
)
1013 Externally_Built
: constant Variable_Value
:=
1015 (Name_Externally_Built
,
1016 Data
.Decl
.Attributes
, In_Tree
);
1019 if not Externally_Built
.Default
then
1020 Get_Name_String
(Externally_Built
.Value
);
1021 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1023 if Name_Buffer
(1 .. Name_Len
) = "true" then
1024 Data
.Externally_Built
:= True;
1026 elsif Name_Buffer
(1 .. Name_Len
) /= "false" then
1027 Error_Msg
(Project
, In_Tree
,
1028 "Externally_Built may only be true or false",
1029 Externally_Built
.Location
);
1033 if Current_Verbosity
= High
then
1034 Write_Str
("Project is ");
1036 if not Data
.Externally_Built
then
1040 Write_Line
("externally built.");
1042 end Check_If_Externally_Built
;
1044 -----------------------------
1045 -- Check_Naming_Scheme --
1046 -----------------------------
1048 procedure Check_Naming_Scheme
1049 (Data
: in out Project_Data
;
1050 Project
: Project_Id
;
1051 In_Tree
: Project_Tree_Ref
)
1053 Naming_Id
: constant Package_Id
:=
1054 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
, In_Tree
);
1056 Naming
: Package_Element
;
1058 procedure Check_Unit_Names
(List
: Array_Element_Id
);
1059 -- Check that a list of unit names contains only valid names
1061 ----------------------
1062 -- Check_Unit_Names --
1063 ----------------------
1065 procedure Check_Unit_Names
(List
: Array_Element_Id
) is
1066 Current
: Array_Element_Id
:= List
;
1067 Element
: Array_Element
;
1068 Unit_Name
: Name_Id
;
1071 -- Loop through elements of the string list
1073 while Current
/= No_Array_Element
loop
1074 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1076 -- Put file name in canonical case
1078 Get_Name_String
(Element
.Value
.Value
);
1079 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1080 Element
.Value
.Value
:= Name_Find
;
1082 -- Check that it contains a valid unit name
1084 Get_Name_String
(Element
.Index
);
1085 Check_Ada_Name
(Name_Buffer
(1 .. Name_Len
), Unit_Name
);
1087 if Unit_Name
= No_Name
then
1088 Err_Vars
.Error_Msg_Name_1
:= Element
.Index
;
1091 "{ is not a valid unit name.",
1092 Element
.Value
.Location
);
1095 if Current_Verbosity
= High
then
1096 Write_Str
(" Unit (""");
1097 Write_Str
(Get_Name_String
(Unit_Name
));
1101 Element
.Index
:= Unit_Name
;
1102 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1105 Current
:= Element
.Next
;
1107 end Check_Unit_Names
;
1109 -- Start of processing for Check_Naming_Scheme
1112 -- If there is a package Naming, we will put in Data.Naming what is in
1113 -- this package Naming.
1115 if Naming_Id
/= No_Package
then
1116 Naming
:= In_Tree
.Packages
.Table
(Naming_Id
);
1118 if Current_Verbosity
= High
then
1119 Write_Line
("Checking ""Naming"" for Ada.");
1123 Bodies
: constant Array_Element_Id
:=
1124 Util
.Value_Of
(Name_Body
, Naming
.Decl
.Arrays
, In_Tree
);
1126 Specs
: constant Array_Element_Id
:=
1127 Util
.Value_Of
(Name_Spec
, Naming
.Decl
.Arrays
, In_Tree
);
1130 if Bodies
/= No_Array_Element
then
1132 -- We have elements in the array Body_Part
1134 if Current_Verbosity
= High
then
1135 Write_Line
("Found Bodies.");
1138 Data
.Naming
.Bodies
:= Bodies
;
1139 Check_Unit_Names
(Bodies
);
1142 if Current_Verbosity
= High
then
1143 Write_Line
("No Bodies.");
1147 if Specs
/= No_Array_Element
then
1149 -- We have elements in the array Specs
1151 if Current_Verbosity
= High
then
1152 Write_Line
("Found Specs.");
1155 Data
.Naming
.Specs
:= Specs
;
1156 Check_Unit_Names
(Specs
);
1159 if Current_Verbosity
= High
then
1160 Write_Line
("No Specs.");
1165 -- We are now checking if variables Dot_Replacement, Casing,
1166 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1169 -- For each variable, if it does not exist, we do nothing,
1170 -- because we already have the default.
1172 -- Check Dot_Replacement
1175 Dot_Replacement
: constant Variable_Value
:=
1177 (Name_Dot_Replacement
,
1178 Naming
.Decl
.Attributes
, In_Tree
);
1181 pragma Assert
(Dot_Replacement
.Kind
= Single
,
1182 "Dot_Replacement is not a single string");
1184 if not Dot_Replacement
.Default
then
1185 Get_Name_String
(Dot_Replacement
.Value
);
1187 if Name_Len
= 0 then
1190 "Dot_Replacement cannot be empty",
1191 Dot_Replacement
.Location
);
1194 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1195 Data
.Naming
.Dot_Replacement
:= Name_Find
;
1196 Data
.Naming
.Dot_Repl_Loc
:= Dot_Replacement
.Location
;
1201 if Current_Verbosity
= High
then
1202 Write_Str
(" Dot_Replacement = """);
1203 Write_Str
(Get_Name_String
(Data
.Naming
.Dot_Replacement
));
1211 Casing_String
: constant Variable_Value
:=
1213 (Name_Casing
, Naming
.Decl
.Attributes
, In_Tree
);
1216 pragma Assert
(Casing_String
.Kind
= Single
,
1217 "Casing is not a single string");
1219 if not Casing_String
.Default
then
1221 Casing_Image
: constant String :=
1222 Get_Name_String
(Casing_String
.Value
);
1225 Casing_Value
: constant Casing_Type
:=
1226 Value
(Casing_Image
);
1228 Data
.Naming
.Casing
:= Casing_Value
;
1232 when Constraint_Error
=>
1233 if Casing_Image
'Length = 0 then
1236 "Casing cannot be an empty string",
1237 Casing_String
.Location
);
1240 Name_Len
:= Casing_Image
'Length;
1241 Name_Buffer
(1 .. Name_Len
) := Casing_Image
;
1242 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
1245 "{ is not a correct Casing",
1246 Casing_String
.Location
);
1252 if Current_Verbosity
= High
then
1253 Write_Str
(" Casing = ");
1254 Write_Str
(Image
(Data
.Naming
.Casing
));
1259 -- Check Spec_Suffix
1262 Ada_Spec_Suffix
: constant Variable_Value
:=
1266 In_Array
=> Data
.Naming
.Spec_Suffix
,
1267 In_Tree
=> In_Tree
);
1270 if Ada_Spec_Suffix
.Kind
= Single
1271 and then Get_Name_String
(Ada_Spec_Suffix
.Value
) /= ""
1273 Get_Name_String
(Ada_Spec_Suffix
.Value
);
1274 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1275 Data
.Naming
.Ada_Spec_Suffix
:= Name_Find
;
1276 Data
.Naming
.Spec_Suffix_Loc
:= Ada_Spec_Suffix
.Location
;
1279 Data
.Naming
.Ada_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
1283 if Current_Verbosity
= High
then
1284 Write_Str
(" Spec_Suffix = """);
1285 Write_Str
(Get_Name_String
(Data
.Naming
.Ada_Spec_Suffix
));
1290 -- Check Body_Suffix
1293 Ada_Body_Suffix
: constant Variable_Value
:=
1297 In_Array
=> Data
.Naming
.Body_Suffix
,
1298 In_Tree
=> In_Tree
);
1301 if Ada_Body_Suffix
.Kind
= Single
1302 and then Get_Name_String
(Ada_Body_Suffix
.Value
) /= ""
1304 Get_Name_String
(Ada_Body_Suffix
.Value
);
1305 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1306 Data
.Naming
.Ada_Body_Suffix
:= Name_Find
;
1307 Data
.Naming
.Body_Suffix_Loc
:= Ada_Body_Suffix
.Location
;
1310 Data
.Naming
.Ada_Body_Suffix
:= Default_Ada_Body_Suffix
;
1314 if Current_Verbosity
= High
then
1315 Write_Str
(" Body_Suffix = """);
1316 Write_Str
(Get_Name_String
(Data
.Naming
.Ada_Body_Suffix
));
1321 -- Check Separate_Suffix
1324 Ada_Sep_Suffix
: constant Variable_Value
:=
1326 (Variable_Name
=> Name_Separate_Suffix
,
1327 In_Variables
=> Naming
.Decl
.Attributes
,
1328 In_Tree
=> In_Tree
);
1331 if Ada_Sep_Suffix
.Default
then
1332 Data
.Naming
.Separate_Suffix
:=
1333 Data
.Naming
.Ada_Body_Suffix
;
1336 Get_Name_String
(Ada_Sep_Suffix
.Value
);
1338 if Name_Len
= 0 then
1341 "Separate_Suffix cannot be empty",
1342 Ada_Sep_Suffix
.Location
);
1345 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1346 Data
.Naming
.Separate_Suffix
:= Name_Find
;
1347 Data
.Naming
.Sep_Suffix_Loc
:= Ada_Sep_Suffix
.Location
;
1352 if Current_Verbosity
= High
then
1353 Write_Str
(" Separate_Suffix = """);
1354 Write_Str
(Get_Name_String
(Data
.Naming
.Separate_Suffix
));
1359 -- Check if Data.Naming is valid
1361 Check_Ada_Naming_Scheme_Validity
(Project
, In_Tree
, Data
.Naming
);
1364 Data
.Naming
.Ada_Spec_Suffix
:= Default_Ada_Spec_Suffix
;
1365 Data
.Naming
.Ada_Body_Suffix
:= Default_Ada_Body_Suffix
;
1366 Data
.Naming
.Separate_Suffix
:= Default_Ada_Body_Suffix
;
1368 end Check_Naming_Scheme
;
1370 ------------------------------
1371 -- Check_Library_Attributes --
1372 ------------------------------
1374 procedure Check_Library_Attributes
1375 (Project
: Project_Id
;
1376 In_Tree
: Project_Tree_Ref
;
1377 Data
: in out Project_Data
)
1379 Attributes
: constant Prj
.Variable_Id
:= Data
.Decl
.Attributes
;
1381 Lib_Dir
: constant Prj
.Variable_Value
:=
1383 (Snames
.Name_Library_Dir
, Attributes
, In_Tree
);
1385 Lib_Name
: constant Prj
.Variable_Value
:=
1387 (Snames
.Name_Library_Name
, Attributes
, In_Tree
);
1389 Lib_Version
: constant Prj
.Variable_Value
:=
1391 (Snames
.Name_Library_Version
, Attributes
, In_Tree
);
1393 The_Lib_Kind
: constant Prj
.Variable_Value
:=
1395 (Snames
.Name_Library_Kind
, Attributes
, In_Tree
);
1398 -- Special case of extending project
1400 if Data
.Extends
/= No_Project
then
1402 Extended_Data
: constant Project_Data
:=
1403 In_Tree
.Projects
.Table
(Data
.Extends
);
1406 -- If the project extended is a library project, we inherit
1407 -- the library name, if it is not redefined; we check that
1408 -- the library directory is specified; and we reset the
1409 -- library flag for the extended project.
1411 if Extended_Data
.Library
then
1412 if Lib_Name
.Default
then
1413 Data
.Library_Name
:= Extended_Data
.Library_Name
;
1416 if Lib_Dir
.Default
then
1417 if not Data
.Virtual
then
1420 "a project extending a library project must " &
1421 "specify an attribute Library_Dir",
1426 In_Tree
.Projects
.Table
(Data
.Extends
).Library
:=
1432 pragma Assert
(Lib_Dir
.Kind
= Single
);
1434 if Lib_Dir
.Value
= Empty_String
then
1435 if Current_Verbosity
= High
then
1436 Write_Line
("No library directory");
1440 -- Find path name, check that it is a directory
1443 (Lib_Dir
.Value
, Data
.Display_Directory
,
1444 Data
.Library_Dir
, Data
.Display_Library_Dir
);
1446 if Data
.Library_Dir
= No_Name
then
1448 -- Get the absolute name of the library directory that
1449 -- does not exist, to report an error.
1452 Dir_Name
: constant String := Get_Name_String
(Lib_Dir
.Value
);
1455 if Is_Absolute_Path
(Dir_Name
) then
1456 Err_Vars
.Error_Msg_Name_1
:= Lib_Dir
.Value
;
1459 Get_Name_String
(Data
.Display_Directory
);
1461 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
1462 Name_Len
:= Name_Len
+ 1;
1463 Name_Buffer
(Name_Len
) := Directory_Separator
;
1467 (Name_Len
+ 1 .. Name_Len
+ Dir_Name
'Length) :=
1469 Name_Len
:= Name_Len
+ Dir_Name
'Length;
1470 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
1477 "library directory { does not exist",
1481 -- The library directory cannot be the same as the Object directory
1483 elsif Data
.Library_Dir
= Data
.Object_Directory
then
1486 "library directory cannot be the same " &
1487 "as object directory",
1489 Data
.Library_Dir
:= No_Name
;
1490 Data
.Display_Library_Dir
:= No_Name
;
1492 -- Display the Library directory in high verbosity
1495 if Current_Verbosity
= High
then
1496 Write_Str
("Library directory =""");
1497 Write_Str
(Get_Name_String
(Data
.Display_Library_Dir
));
1503 pragma Assert
(Lib_Name
.Kind
= Single
);
1505 if Lib_Name
.Value
= Empty_String
then
1506 if Current_Verbosity
= High
1507 and then Data
.Library_Name
= No_Name
1509 Write_Line
("No library name");
1513 -- There is no restriction on the syntax of library names
1515 Data
.Library_Name
:= Lib_Name
.Value
;
1518 if Data
.Library_Name
/= No_Name
1519 and then Current_Verbosity
= High
1521 Write_Str
("Library name = """);
1522 Write_Str
(Get_Name_String
(Data
.Library_Name
));
1527 Data
.Library_Dir
/= No_Name
1529 Data
.Library_Name
/= No_Name
;
1531 if Data
.Library
then
1532 if MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.None
then
1535 "?libraries are not supported on this platform",
1537 Data
.Library
:= False;
1540 pragma Assert
(Lib_Version
.Kind
= Single
);
1542 if Lib_Version
.Value
= Empty_String
then
1543 if Current_Verbosity
= High
then
1544 Write_Line
("No library version specified");
1548 Data
.Lib_Internal_Name
:= Lib_Version
.Value
;
1551 pragma Assert
(The_Lib_Kind
.Kind
= Single
);
1553 if The_Lib_Kind
.Value
= Empty_String
then
1554 if Current_Verbosity
= High
then
1555 Write_Line
("No library kind specified");
1559 Get_Name_String
(The_Lib_Kind
.Value
);
1562 Kind_Name
: constant String :=
1563 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1565 OK
: Boolean := True;
1568 if Kind_Name
= "static" then
1569 Data
.Library_Kind
:= Static
;
1571 elsif Kind_Name
= "dynamic" then
1572 Data
.Library_Kind
:= Dynamic
;
1574 elsif Kind_Name
= "relocatable" then
1575 Data
.Library_Kind
:= Relocatable
;
1580 "illegal value for Library_Kind",
1581 The_Lib_Kind
.Location
);
1585 if Current_Verbosity
= High
and then OK
then
1586 Write_Str
("Library kind = ");
1587 Write_Line
(Kind_Name
);
1590 if Data
.Library_Kind
/= Static
and then
1591 MLib
.Tgt
.Support_For_Libraries
= MLib
.Tgt
.Static_Only
1595 "only static libraries are supported " &
1597 The_Lib_Kind
.Location
);
1598 Data
.Library
:= False;
1603 if Data
.Library
and then Current_Verbosity
= High
then
1604 Write_Line
("This is a library project file");
1609 end Check_Library_Attributes
;
1611 --------------------------
1612 -- Check_Package_Naming --
1613 --------------------------
1615 procedure Check_Package_Naming
1616 (Project
: Project_Id
;
1617 In_Tree
: Project_Tree_Ref
;
1618 Data
: in out Project_Data
)
1620 Naming_Id
: constant Package_Id
:=
1621 Util
.Value_Of
(Name_Naming
, Data
.Decl
.Packages
, In_Tree
);
1623 Naming
: Package_Element
;
1626 -- If there is a package Naming, we will put in Data.Naming
1627 -- what is in this package Naming.
1629 if Naming_Id
/= No_Package
then
1630 Naming
:= In_Tree
.Packages
.Table
(Naming_Id
);
1632 if Current_Verbosity
= High
then
1633 Write_Line
("Checking ""Naming"".");
1636 -- Check Spec_Suffix
1639 Spec_Suffixs
: Array_Element_Id
:=
1645 Suffix
: Array_Element_Id
;
1646 Element
: Array_Element
;
1647 Suffix2
: Array_Element_Id
;
1650 -- If some suffixs have been specified, we make sure that
1651 -- for each language for which a default suffix has been
1652 -- specified, there is a suffix specified, either the one
1653 -- in the project file or if there were none, the default.
1655 if Spec_Suffixs
/= No_Array_Element
then
1656 Suffix
:= Data
.Naming
.Spec_Suffix
;
1658 while Suffix
/= No_Array_Element
loop
1660 In_Tree
.Array_Elements
.Table
(Suffix
);
1661 Suffix2
:= Spec_Suffixs
;
1663 while Suffix2
/= No_Array_Element
loop
1664 exit when In_Tree
.Array_Elements
.Table
1665 (Suffix2
).Index
= Element
.Index
;
1666 Suffix2
:= In_Tree
.Array_Elements
.Table
1670 -- There is a registered default suffix, but no
1671 -- suffix specified in the project file.
1672 -- Add the default to the array.
1674 if Suffix2
= No_Array_Element
then
1675 Array_Element_Table
.Increment_Last
1676 (In_Tree
.Array_Elements
);
1677 In_Tree
.Array_Elements
.Table
1678 (Array_Element_Table
.Last
1679 (In_Tree
.Array_Elements
)) :=
1680 (Index
=> Element
.Index
,
1681 Src_Index
=> Element
.Src_Index
,
1682 Index_Case_Sensitive
=> False,
1683 Value
=> Element
.Value
,
1684 Next
=> Spec_Suffixs
);
1685 Spec_Suffixs
:= Array_Element_Table
.Last
1686 (In_Tree
.Array_Elements
);
1689 Suffix
:= Element
.Next
;
1692 -- Put the resulting array as the specification suffixs
1694 Data
.Naming
.Spec_Suffix
:= Spec_Suffixs
;
1699 Current
: Array_Element_Id
:= Data
.Naming
.Spec_Suffix
;
1700 Element
: Array_Element
;
1703 while Current
/= No_Array_Element
loop
1704 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1705 Get_Name_String
(Element
.Value
.Value
);
1707 if Name_Len
= 0 then
1710 "Spec_Suffix cannot be empty",
1711 Element
.Value
.Location
);
1714 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1715 Current
:= Element
.Next
;
1719 -- Check Body_Suffix
1722 Impl_Suffixs
: Array_Element_Id
:=
1728 Suffix
: Array_Element_Id
;
1729 Element
: Array_Element
;
1730 Suffix2
: Array_Element_Id
;
1733 -- If some suffixes have been specified, we make sure that
1734 -- for each language for which a default suffix has been
1735 -- specified, there is a suffix specified, either the one
1736 -- in the project file or if there were noe, the default.
1738 if Impl_Suffixs
/= No_Array_Element
then
1739 Suffix
:= Data
.Naming
.Body_Suffix
;
1741 while Suffix
/= No_Array_Element
loop
1743 In_Tree
.Array_Elements
.Table
(Suffix
);
1744 Suffix2
:= Impl_Suffixs
;
1746 while Suffix2
/= No_Array_Element
loop
1747 exit when In_Tree
.Array_Elements
.Table
1748 (Suffix2
).Index
= Element
.Index
;
1749 Suffix2
:= In_Tree
.Array_Elements
.Table
1753 -- There is a registered default suffix, but no suffix was
1754 -- specified in the project file. Add the default to the
1757 if Suffix2
= No_Array_Element
then
1758 Array_Element_Table
.Increment_Last
1759 (In_Tree
.Array_Elements
);
1760 In_Tree
.Array_Elements
.Table
1761 (Array_Element_Table
.Last
1762 (In_Tree
.Array_Elements
)) :=
1763 (Index
=> Element
.Index
,
1764 Src_Index
=> Element
.Src_Index
,
1765 Index_Case_Sensitive
=> False,
1766 Value
=> Element
.Value
,
1767 Next
=> Impl_Suffixs
);
1768 Impl_Suffixs
:= Array_Element_Table
.Last
1769 (In_Tree
.Array_Elements
);
1772 Suffix
:= Element
.Next
;
1775 -- Put the resulting array as the implementation suffixs
1777 Data
.Naming
.Body_Suffix
:= Impl_Suffixs
;
1782 Current
: Array_Element_Id
:= Data
.Naming
.Body_Suffix
;
1783 Element
: Array_Element
;
1786 while Current
/= No_Array_Element
loop
1787 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
1788 Get_Name_String
(Element
.Value
.Value
);
1790 if Name_Len
= 0 then
1793 "Body_Suffix cannot be empty",
1794 Element
.Value
.Location
);
1797 In_Tree
.Array_Elements
.Table
(Current
) := Element
;
1798 Current
:= Element
.Next
;
1802 -- Get the exceptions, if any
1804 Data
.Naming
.Specification_Exceptions
:=
1806 (Name_Specification_Exceptions
,
1807 In_Arrays
=> Naming
.Decl
.Arrays
,
1808 In_Tree
=> In_Tree
);
1810 Data
.Naming
.Implementation_Exceptions
:=
1812 (Name_Implementation_Exceptions
,
1813 In_Arrays
=> Naming
.Decl
.Arrays
,
1814 In_Tree
=> In_Tree
);
1816 end Check_Package_Naming
;
1818 ---------------------------------
1819 -- Check_Programming_Languages --
1820 ---------------------------------
1822 procedure Check_Programming_Languages
1823 (In_Tree
: Project_Tree_Ref
;
1824 Data
: in out Project_Data
)
1826 Languages
: Variable_Value
:= Nil_Variable_Value
;
1830 Prj
.Util
.Value_Of
(Name_Languages
, Data
.Decl
.Attributes
, In_Tree
);
1831 Data
.Ada_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
1832 Data
.Other_Sources_Present
:= Data
.Source_Dirs
/= Nil_String
;
1834 if Data
.Source_Dirs
/= Nil_String
then
1836 -- Check if languages are specified in this project
1838 if Languages
.Default
then
1840 -- Attribute Languages is not specified. So, it defaults to
1841 -- a project of language Ada only.
1843 Data
.Languages
(Ada_Language_Index
) := True;
1845 -- No sources of languages other than Ada
1847 Data
.Other_Sources_Present
:= False;
1851 Current
: String_List_Id
:= Languages
.Values
;
1852 Element
: String_Element
;
1853 Lang_Name
: Name_Id
;
1854 Index
: Language_Index
;
1857 -- Assume that there is no language specified yet
1859 Data
.Other_Sources_Present
:= False;
1860 Data
.Ada_Sources_Present
:= False;
1862 -- Look through all the languages specified in attribute
1863 -- Languages, if any
1865 while Current
/= Nil_String
loop
1867 In_Tree
.String_Elements
.Table
(Current
);
1868 Get_Name_String
(Element
.Value
);
1869 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1870 Lang_Name
:= Name_Find
;
1871 Index
:= Language_Indexes
.Get
(Lang_Name
);
1873 if Index
= No_Language_Index
then
1874 Add_Language_Name
(Lang_Name
);
1875 Index
:= Last_Language_Index
;
1878 Set
(Index
, True, Data
, In_Tree
);
1879 Set
(Language_Processing
=> Default_Language_Processing_Data
,
1880 For_Language
=> Index
,
1882 In_Tree
=> In_Tree
);
1884 if Index
= Ada_Language_Index
then
1885 Data
.Ada_Sources_Present
:= True;
1888 Data
.Other_Sources_Present
:= True;
1891 Current
:= Element
.Next
;
1896 end Check_Programming_Languages
;
1902 function Check_Project
1904 Root_Project
: Project_Id
;
1905 In_Tree
: Project_Tree_Ref
;
1906 Extending
: Boolean) return Boolean
1909 if P
= Root_Project
then
1912 elsif Extending
then
1914 Data
: Project_Data
:= In_Tree
.Projects
.Table
(Root_Project
);
1917 while Data
.Extends
/= No_Project
loop
1918 if P
= Data
.Extends
then
1922 Data
:= In_Tree
.Projects
.Table
(Data
.Extends
);
1930 -------------------------------
1931 -- Check_Stand_Alone_Library --
1932 -------------------------------
1934 procedure Check_Stand_Alone_Library
1935 (Project
: Project_Id
;
1936 In_Tree
: Project_Tree_Ref
;
1937 Data
: in out Project_Data
;
1938 Extending
: Boolean)
1940 Lib_Interfaces
: constant Prj
.Variable_Value
:=
1942 (Snames
.Name_Library_Interface
,
1943 Data
.Decl
.Attributes
,
1946 Lib_Auto_Init
: constant Prj
.Variable_Value
:=
1948 (Snames
.Name_Library_Auto_Init
,
1949 Data
.Decl
.Attributes
,
1952 Lib_Src_Dir
: constant Prj
.Variable_Value
:=
1954 (Snames
.Name_Library_Src_Dir
,
1955 Data
.Decl
.Attributes
,
1958 Lib_Symbol_File
: constant Prj
.Variable_Value
:=
1960 (Snames
.Name_Library_Symbol_File
,
1961 Data
.Decl
.Attributes
,
1964 Lib_Symbol_Policy
: constant Prj
.Variable_Value
:=
1966 (Snames
.Name_Library_Symbol_Policy
,
1967 Data
.Decl
.Attributes
,
1970 Lib_Ref_Symbol_File
: constant Prj
.Variable_Value
:=
1972 (Snames
.Name_Library_Reference_Symbol_File
,
1973 Data
.Decl
.Attributes
,
1976 Auto_Init_Supported
: constant Boolean :=
1978 Standalone_Library_Auto_Init_Is_Supported
;
1980 OK
: Boolean := True;
1983 pragma Assert
(Lib_Interfaces
.Kind
= List
);
1985 -- It is a stand-alone library project file if attribute
1986 -- Library_Interface is defined.
1988 if not Lib_Interfaces
.Default
then
1989 SAL_Library
: declare
1990 Interfaces
: String_List_Id
:= Lib_Interfaces
.Values
;
1991 Interface_ALIs
: String_List_Id
:= Nil_String
;
1993 The_Unit_Id
: Unit_Id
;
1994 The_Unit_Data
: Unit_Data
;
1996 procedure Add_ALI_For
(Source
: Name_Id
);
1997 -- Add an ALI file name to the list of Interface ALIs
2003 procedure Add_ALI_For
(Source
: Name_Id
) is
2005 Get_Name_String
(Source
);
2008 ALI
: constant String :=
2009 ALI_File_Name
(Name_Buffer
(1 .. Name_Len
));
2010 ALI_Name_Id
: Name_Id
;
2012 Name_Len
:= ALI
'Length;
2013 Name_Buffer
(1 .. Name_Len
) := ALI
;
2014 ALI_Name_Id
:= Name_Find
;
2016 String_Element_Table
.Increment_Last
2017 (In_Tree
.String_Elements
);
2018 In_Tree
.String_Elements
.Table
2019 (String_Element_Table
.Last
2020 (In_Tree
.String_Elements
)) :=
2021 (Value
=> ALI_Name_Id
,
2023 Display_Value
=> ALI_Name_Id
,
2025 In_Tree
.String_Elements
.Table
2026 (Interfaces
).Location
,
2028 Next
=> Interface_ALIs
);
2029 Interface_ALIs
:= String_Element_Table
.Last
2030 (In_Tree
.String_Elements
);
2034 -- Start of processing for SAL_Library
2037 Data
.Standalone_Library
:= True;
2039 -- Library_Interface cannot be an empty list
2041 if Interfaces
= Nil_String
then
2044 "Library_Interface cannot be an empty list",
2045 Lib_Interfaces
.Location
);
2048 -- Process each unit name specified in the attribute
2049 -- Library_Interface.
2051 while Interfaces
/= Nil_String
loop
2053 (In_Tree
.String_Elements
.Table
2054 (Interfaces
).Value
);
2055 To_Lower
(Name_Buffer
(1 .. Name_Len
));
2057 if Name_Len
= 0 then
2060 "an interface cannot be an empty string",
2061 In_Tree
.String_Elements
.Table
2062 (Interfaces
).Location
);
2066 Error_Msg_Name_1
:= Unit
;
2068 Units_Htable
.Get
(In_Tree
.Units_HT
, Unit
);
2070 if The_Unit_Id
= No_Unit
then
2074 In_Tree
.String_Elements
.Table
2075 (Interfaces
).Location
);
2078 -- Check that the unit is part of the project
2081 In_Tree
.Units
.Table
(The_Unit_Id
);
2083 if The_Unit_Data
.File_Names
(Body_Part
).Name
/= No_Name
2084 and then The_Unit_Data
.File_Names
(Body_Part
).Path
/=
2088 (The_Unit_Data
.File_Names
(Body_Part
).Project
,
2089 Project
, In_Tree
, Extending
)
2091 -- There is a body for this unit.
2092 -- If there is no spec, we need to check
2093 -- that it is not a subunit.
2095 if The_Unit_Data
.File_Names
2096 (Specification
).Name
= No_Name
2099 Src_Ind
: Source_File_Index
;
2102 Src_Ind
:= Sinput
.P
.Load_Project_File
2104 (The_Unit_Data
.File_Names
2107 if Sinput
.P
.Source_File_Is_Subunit
2112 "{ is a subunit; " &
2113 "it cannot be an interface",
2115 String_Elements
.Table
2116 (Interfaces
).Location
);
2121 -- The unit is not a subunit, so we add
2122 -- to the Interface ALIs the ALI file
2123 -- corresponding to the body.
2126 (The_Unit_Data
.File_Names
(Body_Part
).Name
);
2131 "{ is not an unit of this project",
2132 In_Tree
.String_Elements
.Table
2133 (Interfaces
).Location
);
2136 elsif The_Unit_Data
.File_Names
2137 (Specification
).Name
/= No_Name
2138 and then The_Unit_Data
.File_Names
2139 (Specification
).Path
/= Slash
2140 and then Check_Project
2141 (The_Unit_Data
.File_Names
2142 (Specification
).Project
,
2143 Project
, In_Tree
, Extending
)
2146 -- The unit is part of the project, it has
2147 -- a spec, but no body. We add to the Interface
2148 -- ALIs the ALI file corresponding to the spec.
2151 (The_Unit_Data
.File_Names
(Specification
).Name
);
2156 "{ is not an unit of this project",
2157 In_Tree
.String_Elements
.Table
2158 (Interfaces
).Location
);
2165 In_Tree
.String_Elements
.Table
(Interfaces
).Next
;
2168 -- Put the list of Interface ALIs in the project data
2170 Data
.Lib_Interface_ALIs
:= Interface_ALIs
;
2172 -- Check value of attribute Library_Auto_Init and set
2173 -- Lib_Auto_Init accordingly.
2175 if Lib_Auto_Init
.Default
then
2177 -- If no attribute Library_Auto_Init is declared, then
2178 -- set auto init only if it is supported.
2180 Data
.Lib_Auto_Init
:= Auto_Init_Supported
;
2183 Get_Name_String
(Lib_Auto_Init
.Value
);
2184 To_Lower
(Name_Buffer
(1 .. Name_Len
));
2186 if Name_Buffer
(1 .. Name_Len
) = "false" then
2187 Data
.Lib_Auto_Init
:= False;
2189 elsif Name_Buffer
(1 .. Name_Len
) = "true" then
2190 if Auto_Init_Supported
then
2191 Data
.Lib_Auto_Init
:= True;
2194 -- Library_Auto_Init cannot be "true" if auto init
2199 "library auto init not supported " &
2201 Lib_Auto_Init
.Location
);
2207 "invalid value for attribute Library_Auto_Init",
2208 Lib_Auto_Init
.Location
);
2213 -- If attribute Library_Src_Dir is defined and not the
2214 -- empty string, check if the directory exist and is not
2215 -- the object directory or one of the source directories.
2216 -- This is the directory where copies of the interface
2217 -- sources will be copied. Note that this directory may be
2218 -- the library directory.
2220 if Lib_Src_Dir
.Value
/= Empty_String
then
2222 Dir_Id
: constant Name_Id
:= Lib_Src_Dir
.Value
;
2226 (Dir_Id
, Data
.Display_Directory
,
2227 Data
.Library_Src_Dir
,
2228 Data
.Display_Library_Src_Dir
);
2230 -- If directory does not exist, report an error
2232 if Data
.Library_Src_Dir
= No_Name
then
2234 -- Get the absolute name of the library directory
2235 -- that does not exist, to report an error.
2238 Dir_Name
: constant String :=
2239 Get_Name_String
(Dir_Id
);
2242 if Is_Absolute_Path
(Dir_Name
) then
2243 Err_Vars
.Error_Msg_Name_1
:= Dir_Id
;
2246 Get_Name_String
(Data
.Directory
);
2248 if Name_Buffer
(Name_Len
) /=
2251 Name_Len
:= Name_Len
+ 1;
2252 Name_Buffer
(Name_Len
) :=
2253 Directory_Separator
;
2258 Name_Len
+ Dir_Name
'Length) :=
2260 Name_Len
:= Name_Len
+ Dir_Name
'Length;
2261 Err_Vars
.Error_Msg_Name_1
:= Name_Find
;
2268 "Directory { does not exist",
2269 Lib_Src_Dir
.Location
);
2272 -- Report an error if it is the same as the object
2275 elsif Data
.Library_Src_Dir
= Data
.Object_Directory
then
2278 "directory to copy interfaces cannot be " &
2279 "the object directory",
2280 Lib_Src_Dir
.Location
);
2281 Data
.Library_Src_Dir
:= No_Name
;
2283 -- Check if it is same as one of the source directories
2287 Src_Dirs
: String_List_Id
:= Data
.Source_Dirs
;
2288 Src_Dir
: String_Element
;
2291 while Src_Dirs
/= Nil_String
loop
2292 Src_Dir
:= In_Tree
.String_Elements
.Table
2294 Src_Dirs
:= Src_Dir
.Next
;
2296 -- Report error if it is one of the source directories
2298 if Data
.Library_Src_Dir
= Src_Dir
.Value
then
2301 "directory to copy interfaces cannot " &
2302 "be one of the source directories",
2303 Lib_Src_Dir
.Location
);
2304 Data
.Library_Src_Dir
:= No_Name
;
2310 -- In high verbosity, if there is a valid Library_Src_Dir,
2311 -- display its path name.
2313 if Data
.Library_Src_Dir
/= No_Name
2314 and then Current_Verbosity
= High
2316 Write_Str
("Directory to copy interfaces =""");
2317 Write_Str
(Get_Name_String
(Data
.Library_Src_Dir
));
2324 -- Check the symbol related attributes
2326 -- First, the symbol policy
2328 if not Lib_Symbol_Policy
.Default
then
2330 Value
: constant String :=
2332 (Get_Name_String
(Lib_Symbol_Policy
.Value
));
2335 -- Symbol policy must hove one of a limited number of values
2337 if Value
= "autonomous" or else Value
= "default" then
2338 Data
.Symbol_Data
.Symbol_Policy
:= Autonomous
;
2340 elsif Value
= "compliant" then
2341 Data
.Symbol_Data
.Symbol_Policy
:= Compliant
;
2343 elsif Value
= "controlled" then
2344 Data
.Symbol_Data
.Symbol_Policy
:= Controlled
;
2346 elsif Value
= "restricted" then
2347 Data
.Symbol_Data
.Symbol_Policy
:= Restricted
;
2352 "illegal value for Library_Symbol_Policy",
2353 Lib_Symbol_Policy
.Location
);
2358 -- If attribute Library_Symbol_File is not specified, symbol policy
2359 -- cannot be Restricted.
2361 if Lib_Symbol_File
.Default
then
2362 if Data
.Symbol_Data
.Symbol_Policy
= Restricted
then
2365 "Library_Symbol_File needs to be defined when " &
2366 "symbol policy is Restricted",
2367 Lib_Symbol_Policy
.Location
);
2371 -- Library_Symbol_File is defined. Check that the file exists.
2373 Data
.Symbol_Data
.Symbol_File
:= Lib_Symbol_File
.Value
;
2375 Get_Name_String
(Lib_Symbol_File
.Value
);
2377 if Name_Len
= 0 then
2380 "symbol file name cannot be an empty string",
2381 Lib_Symbol_File
.Location
);
2384 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
2387 for J
in 1 .. Name_Len
loop
2388 if Name_Buffer
(J
) = '/'
2389 or else Name_Buffer
(J
) = Directory_Separator
2398 Error_Msg_Name_1
:= Lib_Symbol_File
.Value
;
2401 "symbol file name { is illegal. " &
2402 "Name canot include directory info.",
2403 Lib_Symbol_File
.Location
);
2408 -- If attribute Library_Reference_Symbol_File is not defined,
2409 -- symbol policy cannot be Compilant or Controlled.
2411 if Lib_Ref_Symbol_File
.Default
then
2412 if Data
.Symbol_Data
.Symbol_Policy
= Compliant
2413 or else Data
.Symbol_Data
.Symbol_Policy
= Controlled
2417 "a reference symbol file need to be defined",
2418 Lib_Symbol_Policy
.Location
);
2422 -- Library_Reference_Symbol_File is defined, check file exists
2424 Data
.Symbol_Data
.Reference
:= Lib_Ref_Symbol_File
.Value
;
2426 Get_Name_String
(Lib_Ref_Symbol_File
.Value
);
2428 if Name_Len
= 0 then
2431 "reference symbol file name cannot be an empty string",
2432 Lib_Symbol_File
.Location
);
2435 OK
:= not Is_Absolute_Path
(Name_Buffer
(1 .. Name_Len
));
2438 for J
in 1 .. Name_Len
loop
2439 if Name_Buffer
(J
) = '/'
2440 or else Name_Buffer
(J
) = Directory_Separator
2449 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
2452 "reference symbol file { name is illegal. " &
2453 "Name canot include directory info.",
2454 Lib_Ref_Symbol_File
.Location
);
2457 if not Is_Regular_File
2458 (Get_Name_String
(Data
.Object_Directory
) &
2459 Directory_Separator
&
2460 Get_Name_String
(Lib_Ref_Symbol_File
.Value
))
2462 Error_Msg_Name_1
:= Lib_Ref_Symbol_File
.Value
;
2465 "library reference symbol file { does not exist",
2466 Lib_Ref_Symbol_File
.Location
);
2469 -- Check that the reference symbol file and the symbol file
2470 -- are not the same file.
2472 if Data
.Symbol_Data
.Symbol_File
/= No_Name
then
2476 (Data
.Symbol_Data
.Symbol_File
);
2478 Reference
: String :=
2480 (Data
.Symbol_Data
.Reference
);
2483 Canonical_Case_File_Name
(Symbol
);
2484 Canonical_Case_File_Name
(Reference
);
2486 if Symbol
= Reference
then
2489 "reference symbol file and symbol file " &
2490 "cannot be the same file",
2491 Lib_Ref_Symbol_File
.Location
);
2498 end Check_Stand_Alone_Library
;
2500 ----------------------------
2501 -- Compute_Directory_Last --
2502 ----------------------------
2504 function Compute_Directory_Last
(Dir
: String) return Natural is
2507 and then (Dir
(Dir
'Last - 1) = Directory_Separator
2508 or else Dir
(Dir
'Last - 1) = '/')
2510 return Dir
'Last - 1;
2514 end Compute_Directory_Last
;
2516 --------------------
2517 -- Body_Suffix_Of --
2518 --------------------
2520 function Body_Suffix_Of
2521 (Language
: Language_Index
;
2522 In_Project
: Project_Data
;
2523 In_Tree
: Project_Tree_Ref
) return String
2525 Suffix_Id
: constant Name_Id
:=
2526 Suffix_Of
(Language
, In_Project
, In_Tree
);
2528 if Suffix_Id
/= No_Name
then
2529 return Get_Name_String
(Suffix_Id
);
2531 return "." & Get_Name_String
(Language_Names
.Table
(Language
));
2540 (Project
: Project_Id
;
2541 In_Tree
: Project_Tree_Ref
;
2543 Flag_Location
: Source_Ptr
)
2545 Error_Buffer
: String (1 .. 5_000
);
2546 Error_Last
: Natural := 0;
2547 Msg_Name
: Natural := 0;
2548 First
: Positive := Msg
'First;
2550 procedure Add
(C
: Character);
2551 -- Add a character to the buffer
2553 procedure Add
(S
: String);
2554 -- Add a string to the buffer
2556 procedure Add
(Id
: Name_Id
);
2557 -- Add a name to the buffer
2563 procedure Add
(C
: Character) is
2565 Error_Last
:= Error_Last
+ 1;
2566 Error_Buffer
(Error_Last
) := C
;
2569 procedure Add
(S
: String) is
2571 Error_Buffer
(Error_Last
+ 1 .. Error_Last
+ S
'Length) := S
;
2572 Error_Last
:= Error_Last
+ S
'Length;
2575 procedure Add
(Id
: Name_Id
) is
2577 Get_Name_String
(Id
);
2578 Add
(Name_Buffer
(1 .. Name_Len
));
2581 -- Start of processing for Error_Msg
2584 if Error_Report
= null then
2585 Prj
.Err
.Error_Msg
(Msg
, Flag_Location
);
2589 -- Ignore continuation character
2591 if Msg
(First
) = '\' then
2594 -- Warniung character is always the first one in this package
2596 elsif Msg
(First
) = '?' then
2601 for Index
in First
.. Msg
'Last loop
2602 if Msg
(Index
) = '{' or else Msg
(Index
) = '%' then
2604 -- Include a name between double quotes
2606 Msg_Name
:= Msg_Name
+ 1;
2610 when 1 => Add
(Err_Vars
.Error_Msg_Name_1
);
2611 when 2 => Add
(Err_Vars
.Error_Msg_Name_2
);
2612 when 3 => Add
(Err_Vars
.Error_Msg_Name_3
);
2614 when others => null;
2625 Error_Report
(Error_Buffer
(1 .. Error_Last
), Project
, In_Tree
);
2632 procedure Find_Sources
2633 (Project
: Project_Id
;
2634 In_Tree
: Project_Tree_Ref
;
2635 Data
: in out Project_Data
;
2636 For_Language
: Language_Index
;
2637 Follow_Links
: Boolean := False)
2639 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
2640 Element
: String_Element
;
2642 Current_Source
: String_List_Id
:= Nil_String
;
2643 Source_Recorded
: Boolean := False;
2646 if Current_Verbosity
= High
then
2647 Write_Line
("Looking for sources:");
2650 -- For each subdirectory
2652 while Source_Dir
/= Nil_String
loop
2654 Source_Recorded
:= False;
2655 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
2656 if Element
.Value
/= No_Name
then
2657 Get_Name_String
(Element
.Display_Value
);
2660 Source_Directory
: constant String :=
2661 Name_Buffer
(1 .. Name_Len
) & Directory_Separator
;
2662 Dir_Last
: constant Natural :=
2663 Compute_Directory_Last
(Source_Directory
);
2666 if Current_Verbosity
= High
then
2667 Write_Str
("Source_Dir = ");
2668 Write_Line
(Source_Directory
);
2671 -- We look to every entry in the source directory
2673 Open
(Dir
, Source_Directory
2674 (Source_Directory
'First .. Dir_Last
));
2677 Read
(Dir
, Name_Buffer
, Name_Len
);
2679 if Current_Verbosity
= High
then
2680 Write_Str
(" Checking ");
2681 Write_Line
(Name_Buffer
(1 .. Name_Len
));
2684 exit when Name_Len
= 0;
2687 File_Name
: constant Name_Id
:= Name_Find
;
2688 Path
: constant String :=
2690 (Name
=> Name_Buffer
(1 .. Name_Len
),
2691 Directory
=> Source_Directory
2692 (Source_Directory
'First .. Dir_Last
),
2693 Resolve_Links
=> Follow_Links
,
2694 Case_Sensitive
=> True);
2695 Path_Name
: Name_Id
;
2698 Name_Len
:= Path
'Length;
2699 Name_Buffer
(1 .. Name_Len
) := Path
;
2700 Path_Name
:= Name_Find
;
2702 if For_Language
= Ada_Language_Index
then
2704 -- We attempt to register it as a source. However,
2705 -- there is no error if the file does not contain
2706 -- a valid source. But there is an error if we have
2707 -- a duplicate unit name.
2710 (File_Name
=> File_Name
,
2711 Path_Name
=> Path_Name
,
2715 Location
=> No_Location
,
2716 Current_Source
=> Current_Source
,
2717 Source_Recorded
=> Source_Recorded
,
2718 Follow_Links
=> Follow_Links
);
2722 (File_Name
=> File_Name
,
2723 Path_Name
=> Path_Name
,
2727 Location
=> No_Location
,
2728 Language
=> For_Language
,
2730 Body_Suffix_Of
(For_Language
, Data
, In_Tree
),
2731 Naming_Exception
=> False);
2741 when Directory_Error
=>
2745 if Source_Recorded
then
2746 In_Tree
.String_Elements
.Table
(Source_Dir
).Flag
:=
2750 Source_Dir
:= Element
.Next
;
2753 if Current_Verbosity
= High
then
2754 Write_Line
("end Looking for sources.");
2757 if For_Language
= Ada_Language_Index
then
2759 -- If we have looked for sources and found none, then
2760 -- it is an error, except if it is an extending project.
2761 -- If a non extending project is not supposed to contain
2762 -- any source, then we never call Find_Sources.
2764 if Current_Source
/= Nil_String
then
2765 Data
.Ada_Sources_Present
:= True;
2767 elsif Data
.Extends
= No_Project
then
2770 "there are no Ada sources in this project",
2776 --------------------------------
2777 -- Free_Ada_Naming_Exceptions --
2778 --------------------------------
2780 procedure Free_Ada_Naming_Exceptions
is
2782 Ada_Naming_Exception_Table
.Set_Last
(0);
2783 Ada_Naming_Exceptions
.Reset
;
2784 Reverse_Ada_Naming_Exceptions
.Reset
;
2785 end Free_Ada_Naming_Exceptions
;
2787 ---------------------
2788 -- Get_Directories --
2789 ---------------------
2791 procedure Get_Directories
2792 (Project
: Project_Id
;
2793 In_Tree
: Project_Tree_Ref
;
2794 Data
: in out Project_Data
)
2796 Object_Dir
: constant Variable_Value
:=
2798 (Name_Object_Dir
, Data
.Decl
.Attributes
, In_Tree
);
2800 Exec_Dir
: constant Variable_Value
:=
2802 (Name_Exec_Dir
, Data
.Decl
.Attributes
, In_Tree
);
2804 Source_Dirs
: constant Variable_Value
:=
2806 (Name_Source_Dirs
, Data
.Decl
.Attributes
, In_Tree
);
2808 Last_Source_Dir
: String_List_Id
:= Nil_String
;
2810 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
);
2811 -- Find one or several source directories, and add them
2812 -- to the list of source directories of the project.
2814 ----------------------
2815 -- Find_Source_Dirs --
2816 ----------------------
2818 procedure Find_Source_Dirs
(From
: Name_Id
; Location
: Source_Ptr
) is
2819 Directory
: constant String := Get_Name_String
(From
);
2820 Element
: String_Element
;
2822 procedure Recursive_Find_Dirs
(Path
: Name_Id
);
2823 -- Find all the subdirectories (recursively) of Path and add them
2824 -- to the list of source directories of the project.
2826 -------------------------
2827 -- Recursive_Find_Dirs --
2828 -------------------------
2830 procedure Recursive_Find_Dirs
(Path
: Name_Id
) is
2832 Name
: String (1 .. 250);
2834 List
: String_List_Id
:= Data
.Source_Dirs
;
2835 Element
: String_Element
;
2836 Found
: Boolean := False;
2838 Non_Canonical_Path
: Name_Id
:= No_Name
;
2839 Canonical_Path
: Name_Id
:= No_Name
;
2841 The_Path
: constant String :=
2842 Normalize_Pathname
(Get_Name_String
(Path
)) &
2843 Directory_Separator
;
2845 The_Path_Last
: constant Natural :=
2846 Compute_Directory_Last
(The_Path
);
2849 Name_Len
:= The_Path_Last
- The_Path
'First + 1;
2850 Name_Buffer
(1 .. Name_Len
) :=
2851 The_Path
(The_Path
'First .. The_Path_Last
);
2852 Non_Canonical_Path
:= Name_Find
;
2853 Get_Name_String
(Non_Canonical_Path
);
2854 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2855 Canonical_Path
:= Name_Find
;
2857 -- To avoid processing the same directory several times, check
2858 -- if the directory is already in Recursive_Dirs. If it is,
2859 -- then there is nothing to do, just return. If it is not, put
2860 -- it there and continue recursive processing.
2862 if Recursive_Dirs
.Get
(Canonical_Path
) then
2866 Recursive_Dirs
.Set
(Canonical_Path
, True);
2869 -- Check if directory is already in list
2871 while List
/= Nil_String
loop
2872 Element
:= In_Tree
.String_Elements
.Table
(List
);
2874 if Element
.Value
/= No_Name
then
2875 Found
:= Element
.Value
= Canonical_Path
;
2879 List
:= Element
.Next
;
2882 -- If directory is not already in list, put it there
2885 if Current_Verbosity
= High
then
2887 Write_Line
(The_Path
(The_Path
'First .. The_Path_Last
));
2890 String_Element_Table
.Increment_Last
2891 (In_Tree
.String_Elements
);
2893 (Value
=> Canonical_Path
,
2894 Display_Value
=> Non_Canonical_Path
,
2895 Location
=> No_Location
,
2900 -- Case of first source directory
2902 if Last_Source_Dir
= Nil_String
then
2903 Data
.Source_Dirs
:= String_Element_Table
.Last
2904 (In_Tree
.String_Elements
);
2906 -- Here we already have source directories
2909 -- Link the previous last to the new one
2911 In_Tree
.String_Elements
.Table
2912 (Last_Source_Dir
).Next
:=
2913 String_Element_Table
.Last
2914 (In_Tree
.String_Elements
);
2917 -- And register this source directory as the new last
2919 Last_Source_Dir
:= String_Element_Table
.Last
2920 (In_Tree
.String_Elements
);
2921 In_Tree
.String_Elements
.Table
(Last_Source_Dir
) :=
2925 -- Now look for subdirectories. We do that even when this
2926 -- directory is already in the list, because some of its
2927 -- subdirectories may not be in the list yet.
2929 Open
(Dir
, The_Path
(The_Path
'First .. The_Path_Last
));
2932 Read
(Dir
, Name
, Last
);
2935 if Name
(1 .. Last
) /= "."
2936 and then Name
(1 .. Last
) /= ".."
2938 -- Avoid . and .. directories
2940 if Current_Verbosity
= High
then
2941 Write_Str
(" Checking ");
2942 Write_Line
(Name
(1 .. Last
));
2946 Path_Name
: constant String :=
2948 (Name
=> Name
(1 .. Last
),
2951 (The_Path
'First .. The_Path_Last
),
2952 Resolve_Links
=> False,
2953 Case_Sensitive
=> True);
2956 if Is_Directory
(Path_Name
) then
2958 -- We have found a new subdirectory, call self
2960 Name_Len
:= Path_Name
'Length;
2961 Name_Buffer
(1 .. Name_Len
) := Path_Name
;
2962 Recursive_Find_Dirs
(Name_Find
);
2971 when Directory_Error
=>
2973 end Recursive_Find_Dirs
;
2975 -- Start of processing for Find_Source_Dirs
2978 if Current_Verbosity
= High
then
2979 Write_Str
("Find_Source_Dirs (""");
2980 Write_Str
(Directory
);
2984 -- First, check if we are looking for a directory tree,
2985 -- indicated by "/**" at the end.
2987 if Directory
'Length >= 3
2988 and then Directory
(Directory
'Last - 1 .. Directory
'Last) = "**"
2989 and then (Directory
(Directory
'Last - 2) = '/'
2991 Directory
(Directory
'Last - 2) = Directory_Separator
)
2993 Data
.Known_Order_Of_Source_Dirs
:= False;
2995 Name_Len
:= Directory
'Length - 3;
2997 if Name_Len
= 0 then
2999 -- This is the case of "/**": all directories
3000 -- in the file system.
3003 Name_Buffer
(1) := Directory
(Directory
'First);
3006 Name_Buffer
(1 .. Name_Len
) :=
3007 Directory
(Directory
'First .. Directory
'Last - 3);
3010 if Current_Verbosity
= High
then
3011 Write_Str
("Looking for all subdirectories of """);
3012 Write_Str
(Name_Buffer
(1 .. Name_Len
));
3017 Base_Dir
: constant Name_Id
:= Name_Find
;
3018 Root_Dir
: constant String :=
3020 (Name
=> Get_Name_String
(Base_Dir
),
3022 Get_Name_String
(Data
.Display_Directory
),
3023 Resolve_Links
=> False,
3024 Case_Sensitive
=> True);
3027 if Root_Dir
'Length = 0 then
3028 Err_Vars
.Error_Msg_Name_1
:= Base_Dir
;
3030 if Location
= No_Location
then
3033 "{ is not a valid directory.",
3038 "{ is not a valid directory.",
3043 -- We have an existing directory, we register it and all
3044 -- of its subdirectories.
3046 if Current_Verbosity
= High
then
3047 Write_Line
("Looking for source directories:");
3050 Name_Len
:= Root_Dir
'Length;
3051 Name_Buffer
(1 .. Name_Len
) := Root_Dir
;
3052 Recursive_Find_Dirs
(Name_Find
);
3054 if Current_Verbosity
= High
then
3055 Write_Line
("End of looking for source directories.");
3060 -- We have a single directory
3064 Path_Name
: Name_Id
;
3065 Display_Path_Name
: Name_Id
;
3069 (From
, Data
.Display_Directory
, Path_Name
, Display_Path_Name
);
3071 if Path_Name
= No_Name
then
3072 Err_Vars
.Error_Msg_Name_1
:= From
;
3074 if Location
= No_Location
then
3077 "{ is not a valid directory",
3082 "{ is not a valid directory",
3087 -- As it is an existing directory, we add it to
3088 -- the list of directories.
3090 String_Element_Table
.Increment_Last
3091 (In_Tree
.String_Elements
);
3092 Element
.Value
:= Path_Name
;
3093 Element
.Display_Value
:= Display_Path_Name
;
3095 if Last_Source_Dir
= Nil_String
then
3097 -- This is the first source directory
3099 Data
.Source_Dirs
:= String_Element_Table
.Last
3100 (In_Tree
.String_Elements
);
3103 -- We already have source directories,
3104 -- link the previous last to the new one.
3106 In_Tree
.String_Elements
.Table
3107 (Last_Source_Dir
).Next
:=
3108 String_Element_Table
.Last
3109 (In_Tree
.String_Elements
);
3112 -- And register this source directory as the new last
3114 Last_Source_Dir
:= String_Element_Table
.Last
3115 (In_Tree
.String_Elements
);
3116 In_Tree
.String_Elements
.Table
3117 (Last_Source_Dir
) := Element
;
3121 end Find_Source_Dirs
;
3123 -- Start of processing for Get_Directories
3126 if Current_Verbosity
= High
then
3127 Write_Line
("Starting to look for directories");
3130 -- Check the object directory
3132 pragma Assert
(Object_Dir
.Kind
= Single
,
3133 "Object_Dir is not a single string");
3135 -- We set the object directory to its default
3137 Data
.Object_Directory
:= Data
.Directory
;
3138 Data
.Display_Object_Dir
:= Data
.Display_Directory
;
3140 if Object_Dir
.Value
/= Empty_String
then
3141 Get_Name_String
(Object_Dir
.Value
);
3143 if Name_Len
= 0 then
3146 "Object_Dir cannot be empty",
3147 Object_Dir
.Location
);
3150 -- We check that the specified object directory does exist
3153 (Object_Dir
.Value
, Data
.Display_Directory
,
3154 Data
.Object_Directory
, Data
.Display_Object_Dir
);
3156 if Data
.Object_Directory
= No_Name
then
3158 -- The object directory does not exist, report an error
3160 Err_Vars
.Error_Msg_Name_1
:= Object_Dir
.Value
;
3163 "the object directory { cannot be found",
3166 -- Do not keep a nil Object_Directory. Set it to the specified
3167 -- (relative or absolute) path. This is for the benefit of
3168 -- tools that recover from errors; for example, these tools
3169 -- could create the non existent directory.
3171 Data
.Display_Object_Dir
:= Object_Dir
.Value
;
3172 Get_Name_String
(Object_Dir
.Value
);
3173 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3174 Data
.Object_Directory
:= Name_Find
;
3179 if Current_Verbosity
= High
then
3180 if Data
.Object_Directory
= No_Name
then
3181 Write_Line
("No object directory");
3183 Write_Str
("Object directory: """);
3184 Write_Str
(Get_Name_String
(Data
.Display_Object_Dir
));
3189 -- Check the exec directory
3191 pragma Assert
(Exec_Dir
.Kind
= Single
,
3192 "Exec_Dir is not a single string");
3194 -- We set the object directory to its default
3196 Data
.Exec_Directory
:= Data
.Object_Directory
;
3197 Data
.Display_Exec_Dir
:= Data
.Display_Object_Dir
;
3199 if Exec_Dir
.Value
/= Empty_String
then
3200 Get_Name_String
(Exec_Dir
.Value
);
3202 if Name_Len
= 0 then
3205 "Exec_Dir cannot be empty",
3209 -- We check that the specified object directory
3213 (Exec_Dir
.Value
, Data
.Directory
,
3214 Data
.Exec_Directory
, Data
.Display_Exec_Dir
);
3216 if Data
.Exec_Directory
= No_Name
then
3217 Err_Vars
.Error_Msg_Name_1
:= Exec_Dir
.Value
;
3220 "the exec directory { cannot be found",
3226 if Current_Verbosity
= High
then
3227 if Data
.Exec_Directory
= No_Name
then
3228 Write_Line
("No exec directory");
3230 Write_Str
("Exec directory: """);
3231 Write_Str
(Get_Name_String
(Data
.Display_Exec_Dir
));
3236 -- Look for the source directories
3238 if Current_Verbosity
= High
then
3239 Write_Line
("Starting to look for source directories");
3242 pragma Assert
(Source_Dirs
.Kind
= List
, "Source_Dirs is not a list");
3244 if Source_Dirs
.Default
then
3246 -- No Source_Dirs specified: the single source directory
3247 -- is the one containing the project file
3249 String_Element_Table
.Increment_Last
3250 (In_Tree
.String_Elements
);
3251 Data
.Source_Dirs
:= String_Element_Table
.Last
3252 (In_Tree
.String_Elements
);
3253 In_Tree
.String_Elements
.Table
(Data
.Source_Dirs
) :=
3254 (Value
=> Data
.Directory
,
3255 Display_Value
=> Data
.Display_Directory
,
3256 Location
=> No_Location
,
3261 if Current_Verbosity
= High
then
3262 Write_Line
("Single source directory:");
3264 Write_Str
(Get_Name_String
(Data
.Display_Directory
));
3268 elsif Source_Dirs
.Values
= Nil_String
then
3270 -- If Source_Dirs is an empty string list, this means
3271 -- that this project contains no source. For projects that
3272 -- don't extend other projects, this also means that there is no
3273 -- need for an object directory, if not specified.
3275 if Data
.Extends
= No_Project
3276 and then Data
.Object_Directory
= Data
.Directory
3278 Data
.Object_Directory
:= No_Name
;
3281 Data
.Source_Dirs
:= Nil_String
;
3282 Data
.Ada_Sources_Present
:= False;
3283 Data
.Other_Sources_Present
:= False;
3287 Source_Dir
: String_List_Id
:= Source_Dirs
.Values
;
3288 Element
: String_Element
;
3291 -- We will find the source directories for each
3292 -- element of the list
3294 while Source_Dir
/= Nil_String
loop
3296 In_Tree
.String_Elements
.Table
(Source_Dir
);
3297 Find_Source_Dirs
(Element
.Value
, Element
.Location
);
3298 Source_Dir
:= Element
.Next
;
3303 if Current_Verbosity
= High
then
3304 Write_Line
("Putting source directories in canonical cases");
3308 Current
: String_List_Id
:= Data
.Source_Dirs
;
3309 Element
: String_Element
;
3312 while Current
/= Nil_String
loop
3313 Element
:= In_Tree
.String_Elements
.Table
(Current
);
3314 if Element
.Value
/= No_Name
then
3315 Get_Name_String
(Element
.Value
);
3316 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3317 Element
.Value
:= Name_Find
;
3318 In_Tree
.String_Elements
.Table
(Current
) := Element
;
3321 Current
:= Element
.Next
;
3325 end Get_Directories
;
3332 (Project
: Project_Id
;
3333 In_Tree
: Project_Tree_Ref
;
3334 Data
: in out Project_Data
) is
3335 Mains
: constant Variable_Value
:=
3336 Prj
.Util
.Value_Of
(Name_Main
, Data
.Decl
.Attributes
, In_Tree
);
3339 Data
.Mains
:= Mains
.Values
;
3341 -- If no Mains were specified, and if we are an extending
3342 -- project, inherit the Mains from the project we are extending.
3344 if Mains
.Default
then
3345 if Data
.Extends
/= No_Project
then
3347 In_Tree
.Projects
.Table
(Data
.Extends
).Mains
;
3350 -- In a library project file, Main cannot be specified
3352 elsif Data
.Library
then
3355 "a library project file cannot have Main specified",
3360 ---------------------------
3361 -- Get_Sources_From_File --
3362 ---------------------------
3364 procedure Get_Sources_From_File
3366 Location
: Source_Ptr
;
3367 Project
: Project_Id
;
3368 In_Tree
: Project_Tree_Ref
)
3370 File
: Prj
.Util
.Text_File
;
3371 Line
: String (1 .. 250);
3373 Source_Name
: Name_Id
;
3378 if Current_Verbosity
= High
then
3379 Write_Str
("Opening """);
3386 Prj
.Util
.Open
(File
, Path
);
3388 if not Prj
.Util
.Is_Valid
(File
) then
3389 Error_Msg
(Project
, In_Tree
, "file does not exist", Location
);
3391 -- Read the lines one by one
3393 while not Prj
.Util
.End_Of_File
(File
) loop
3394 Prj
.Util
.Get_Line
(File
, Line
, Last
);
3396 -- A non empty, non comment line should contain a file name
3399 and then (Last
= 1 or else Line
(1 .. 2) /= "--")
3401 -- ??? we should check that there is no directory information
3404 Name_Buffer
(1 .. Name_Len
) := Line
(1 .. Last
);
3405 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3406 Source_Name
:= Name_Find
;
3410 (Name
=> Source_Name
,
3411 Location
=> Location
,
3416 Prj
.Util
.Close
(File
);
3419 end Get_Sources_From_File
;
3426 (Canonical_File_Name
: Name_Id
;
3427 Naming
: Naming_Data
;
3428 Exception_Id
: out Ada_Naming_Exception_Id
;
3429 Unit_Name
: out Name_Id
;
3430 Unit_Kind
: out Spec_Or_Body
;
3431 Needs_Pragma
: out Boolean)
3433 Info_Id
: Ada_Naming_Exception_Id
3434 := Ada_Naming_Exceptions
.Get
(Canonical_File_Name
);
3438 if Info_Id
= No_Ada_Naming_Exception
then
3439 if Hostparm
.OpenVMS
then
3440 VMS_Name
:= Canonical_File_Name
;
3441 Get_Name_String
(VMS_Name
);
3443 if Name_Buffer
(Name_Len
) = '.' then
3444 Name_Len
:= Name_Len
- 1;
3445 VMS_Name
:= Name_Find
;
3448 Info_Id
:= Ada_Naming_Exceptions
.Get
(VMS_Name
);
3453 if Info_Id
/= No_Ada_Naming_Exception
then
3454 Exception_Id
:= Info_Id
;
3455 Unit_Name
:= No_Name
;
3456 Unit_Kind
:= Specification
;
3457 Needs_Pragma
:= True;
3461 Needs_Pragma
:= False;
3462 Exception_Id
:= No_Ada_Naming_Exception
;
3464 Get_Name_String
(Canonical_File_Name
);
3467 File
: String := Name_Buffer
(1 .. Name_Len
);
3468 First
: constant Positive := File
'First;
3469 Last
: Natural := File
'Last;
3470 Standard_GNAT
: Boolean;
3474 Naming
.Ada_Spec_Suffix
= Default_Ada_Spec_Suffix
3475 and then Naming
.Ada_Body_Suffix
= Default_Ada_Body_Suffix
;
3477 -- Check if the end of the file name is Specification_Append
3479 Get_Name_String
(Naming
.Ada_Spec_Suffix
);
3481 if File
'Length > Name_Len
3482 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3483 Name_Buffer
(1 .. Name_Len
)
3487 Unit_Kind
:= Specification
;
3488 Last
:= Last
- Name_Len
;
3490 if Current_Verbosity
= High
then
3491 Write_Str
(" Specification: ");
3492 Write_Line
(File
(First
.. Last
));
3496 Get_Name_String
(Naming
.Ada_Body_Suffix
);
3498 -- Check if the end of the file name is Body_Append
3500 if File
'Length > Name_Len
3501 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3502 Name_Buffer
(1 .. Name_Len
)
3506 Unit_Kind
:= Body_Part
;
3507 Last
:= Last
- Name_Len
;
3509 if Current_Verbosity
= High
then
3510 Write_Str
(" Body: ");
3511 Write_Line
(File
(First
.. Last
));
3514 elsif Naming
.Separate_Suffix
/= Naming
.Ada_Spec_Suffix
then
3515 Get_Name_String
(Naming
.Separate_Suffix
);
3517 -- Check if the end of the file name is Separate_Append
3519 if File
'Length > Name_Len
3520 and then File
(Last
- Name_Len
+ 1 .. Last
) =
3521 Name_Buffer
(1 .. Name_Len
)
3523 -- We have a separate (a body)
3525 Unit_Kind
:= Body_Part
;
3526 Last
:= Last
- Name_Len
;
3528 if Current_Verbosity
= High
then
3529 Write_Str
(" Separate: ");
3530 Write_Line
(File
(First
.. Last
));
3544 -- This is not a source file
3546 Unit_Name
:= No_Name
;
3547 Unit_Kind
:= Specification
;
3549 if Current_Verbosity
= High
then
3550 Write_Line
(" Not a valid file name.");
3556 Get_Name_String
(Naming
.Dot_Replacement
);
3558 Standard_GNAT
and then Name_Buffer
(1 .. Name_Len
) = "-";
3560 if Name_Buffer
(1 .. Name_Len
) /= "." then
3562 -- If Dot_Replacement is not a single dot, then there should
3563 -- not be any dot in the name.
3565 for Index
in First
.. Last
loop
3566 if File
(Index
) = '.' then
3567 if Current_Verbosity
= High
then
3569 (" Not a valid file name (some dot not replaced).");
3572 Unit_Name
:= No_Name
;
3578 -- Replace the substring Dot_Replacement with dots
3581 Index
: Positive := First
;
3584 while Index
<= Last
- Name_Len
+ 1 loop
3586 if File
(Index
.. Index
+ Name_Len
- 1) =
3587 Name_Buffer
(1 .. Name_Len
)
3589 File
(Index
) := '.';
3591 if Name_Len
> 1 and then Index
< Last
then
3592 File
(Index
+ 1 .. Last
- Name_Len
+ 1) :=
3593 File
(Index
+ Name_Len
.. Last
);
3596 Last
:= Last
- Name_Len
+ 1;
3604 -- Check if the casing is right
3607 Src
: String := File
(First
.. Last
);
3610 case Naming
.Casing
is
3611 when All_Lower_Case
=>
3614 Mapping
=> Lower_Case_Map
);
3616 when All_Upper_Case
=>
3619 Mapping
=> Upper_Case_Map
);
3621 when Mixed_Case | Unknown
=>
3625 if Src
/= File
(First
.. Last
) then
3626 if Current_Verbosity
= High
then
3627 Write_Line
(" Not a valid file name (casing).");
3630 Unit_Name
:= No_Name
;
3634 -- We put the name in lower case
3638 Mapping
=> Lower_Case_Map
);
3640 -- In the standard GNAT naming scheme, check for special cases:
3641 -- children or separates of A, G, I or S, and run time sources.
3643 if Standard_GNAT
and then Src
'Length >= 3 then
3645 S1
: constant Character := Src
(Src
'First);
3646 S2
: constant Character := Src
(Src
'First + 1);
3649 if S1
= 'a' or else S1
= 'g'
3650 or else S1
= 'i' or else S1
= 's'
3652 -- Children or separates of packages A, G, I or S
3654 if (Hostparm
.OpenVMS
and then S2
= '$')
3655 or else (not Hostparm
.OpenVMS
and then S2
= '~')
3657 Src
(Src
'First + 1) := '.';
3659 -- If it is potentially a run time source, disable
3660 -- filling of the mapping file to avoid warnings.
3663 Set_Mapping_File_Initial_State_To_Empty
;
3670 if Current_Verbosity
= High
then
3675 -- Now, we check if this name is a valid unit name
3677 Check_Ada_Name
(Name
=> Src
, Unit
=> Unit_Name
);
3687 function Hash
(Unit
: Unit_Info
) return Header_Num
is
3689 return Header_Num
(Unit
.Unit
mod 2048);
3692 -----------------------
3693 -- Is_Illegal_Suffix --
3694 -----------------------
3696 function Is_Illegal_Suffix
3698 Dot_Replacement_Is_A_Single_Dot
: Boolean) return Boolean
3701 if Suffix
'Length = 0 or else Index
(Suffix
, ".") = 0 then
3705 -- If dot replacement is a single dot, and first character of
3706 -- suffix is also a dot
3708 if Dot_Replacement_Is_A_Single_Dot
3709 and then Suffix
(Suffix
'First) = '.'
3711 for Index
in Suffix
'First + 1 .. Suffix
'Last loop
3713 -- If there is another dot
3715 if Suffix
(Index
) = '.' then
3717 -- It is illegal to have a letter following the initial dot
3719 return Is_Letter
(Suffix
(Suffix
'First + 1));
3727 end Is_Illegal_Suffix
;
3729 ----------------------
3730 -- Locate_Directory --
3731 ----------------------
3733 procedure Locate_Directory
3737 Display
: out Name_Id
)
3739 The_Name
: constant String := Get_Name_String
(Name
);
3741 The_Parent
: constant String :=
3742 Get_Name_String
(Parent
) & Directory_Separator
;
3744 The_Parent_Last
: constant Natural :=
3745 Compute_Directory_Last
(The_Parent
);
3748 if Current_Verbosity
= High
then
3749 Write_Str
("Locate_Directory (""");
3750 Write_Str
(The_Name
);
3751 Write_Str
(""", """);
3752 Write_Str
(The_Parent
);
3759 if Is_Absolute_Path
(The_Name
) then
3760 if Is_Directory
(The_Name
) then
3762 Normed
: constant String :=
3765 Resolve_Links
=> False,
3766 Case_Sensitive
=> True);
3768 Canonical_Path
: constant String :=
3771 Resolve_Links
=> True,
3772 Case_Sensitive
=> False);
3775 Name_Len
:= Normed
'Length;
3776 Name_Buffer
(1 .. Name_Len
) := Normed
;
3777 Display
:= Name_Find
;
3779 Name_Len
:= Canonical_Path
'Length;
3780 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3787 Full_Path
: constant String :=
3788 The_Parent
(The_Parent
'First .. The_Parent_Last
) &
3792 if Is_Directory
(Full_Path
) then
3794 Normed
: constant String :=
3797 Resolve_Links
=> False,
3798 Case_Sensitive
=> True);
3800 Canonical_Path
: constant String :=
3803 Resolve_Links
=> True,
3804 Case_Sensitive
=> False);
3807 Name_Len
:= Normed
'Length;
3808 Name_Buffer
(1 .. Name_Len
) := Normed
;
3809 Display
:= Name_Find
;
3811 Name_Len
:= Canonical_Path
'Length;
3812 Name_Buffer
(1 .. Name_Len
) := Canonical_Path
;
3818 end Locate_Directory
;
3820 ----------------------
3821 -- Look_For_Sources --
3822 ----------------------
3824 procedure Look_For_Sources
3825 (Project
: Project_Id
;
3826 In_Tree
: Project_Tree_Ref
;
3827 Data
: in out Project_Data
;
3828 Follow_Links
: Boolean)
3830 procedure Get_Path_Names_And_Record_Sources
(Follow_Links
: Boolean);
3831 -- Find the path names of the source files in the Source_Names table
3832 -- in the source directories and record those that are Ada sources.
3834 procedure Get_Sources_From_File
3836 Location
: Source_Ptr
);
3837 -- Get the sources of a project from a text file
3839 ---------------------------------------
3840 -- Get_Path_Names_And_Record_Sources --
3841 ---------------------------------------
3843 procedure Get_Path_Names_And_Record_Sources
(Follow_Links
: Boolean) is
3844 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
3845 Element
: String_Element
;
3850 Canonical_Name
: Name_Id
;
3851 Name_Str
: String (1 .. 1_024
);
3852 Last
: Natural := 0;
3855 Current_Source
: String_List_Id
:= Nil_String
;
3857 First_Error
: Boolean := True;
3859 Source_Recorded
: Boolean := False;
3862 -- We look in all source directories for the file names in the
3863 -- hash table Source_Names
3865 while Source_Dir
/= Nil_String
loop
3866 Source_Recorded
:= False;
3867 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
3870 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
3872 if Current_Verbosity
= High
then
3873 Write_Str
("checking directory """);
3874 Write_Str
(Dir_Path
);
3878 Open
(Dir
, Dir_Path
);
3881 Read
(Dir
, Name_Str
, Last
);
3884 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
3886 Canonical_Case_File_Name
(Name_Str
(1 .. Last
));
3888 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
3889 Canonical_Name
:= Name_Find
;
3890 NL
:= Source_Names
.Get
(Canonical_Name
);
3892 if NL
/= No_Name_Location
and then not NL
.Found
then
3894 Source_Names
.Set
(Canonical_Name
, NL
);
3895 Name_Len
:= Dir_Path
'Length;
3896 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
3898 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
3899 Add_Char_To_Name_Buffer
(Directory_Separator
);
3902 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
3905 if Current_Verbosity
= High
then
3906 Write_Str
(" found ");
3907 Write_Line
(Get_Name_String
(Name
));
3910 -- Register the source if it is an Ada compilation unit
3918 Location
=> NL
.Location
,
3919 Current_Source
=> Current_Source
,
3920 Source_Recorded
=> Source_Recorded
,
3921 Follow_Links
=> Follow_Links
);
3928 if Source_Recorded
then
3929 In_Tree
.String_Elements
.Table
(Source_Dir
).Flag
:=
3933 Source_Dir
:= Element
.Next
;
3936 -- It is an error if a source file name in a source list or
3937 -- in a source list file is not found.
3939 NL
:= Source_Names
.Get_First
;
3941 while NL
/= No_Name_Location
loop
3942 if not NL
.Found
then
3943 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
3948 "source file { cannot be found",
3950 First_Error
:= False;
3955 "\source file { cannot be found",
3960 NL
:= Source_Names
.Get_Next
;
3962 end Get_Path_Names_And_Record_Sources
;
3964 ---------------------------
3965 -- Get_Sources_From_File --
3966 ---------------------------
3968 procedure Get_Sources_From_File
3970 Location
: Source_Ptr
)
3973 -- Get the list of sources from the file and put them in hash table
3976 Get_Sources_From_File
(Path
, Location
, Project
, In_Tree
);
3978 -- Look in the source directories to find those sources
3980 Get_Path_Names_And_Record_Sources
(Follow_Links
);
3982 -- We should have found at least one source.
3983 -- If not, report an error.
3985 if Data
.Sources
= Nil_String
then
3986 Error_Msg
(Project
, In_Tree
,
3987 "there are no Ada sources in this project",
3990 end Get_Sources_From_File
;
3993 if Data
.Ada_Sources_Present
then
3995 Sources
: constant Variable_Value
:=
3998 Data
.Decl
.Attributes
,
4001 Source_List_File
: constant Variable_Value
:=
4003 (Name_Source_List_File
,
4004 Data
.Decl
.Attributes
,
4007 Locally_Removed
: constant Variable_Value
:=
4009 (Name_Locally_Removed_Files
,
4010 Data
.Decl
.Attributes
,
4015 (Sources
.Kind
= List
,
4016 "Source_Files is not a list");
4019 (Source_List_File
.Kind
= Single
,
4020 "Source_List_File is not a single string");
4022 if not Sources
.Default
then
4023 if not Source_List_File
.Default
then
4026 "?both variables source_files and " &
4027 "source_list_file are present",
4028 Source_List_File
.Location
);
4031 -- Sources is a list of file names
4034 Current
: String_List_Id
:= Sources
.Values
;
4035 Element
: String_Element
;
4036 Location
: Source_Ptr
;
4042 Data
.Ada_Sources_Present
:= Current
/= Nil_String
;
4044 while Current
/= Nil_String
loop
4046 In_Tree
.String_Elements
.Table
(Current
);
4047 Get_Name_String
(Element
.Value
);
4048 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4051 -- If the element has no location, then use the
4052 -- location of Sources to report possible errors.
4054 if Element
.Location
= No_Location
then
4055 Location
:= Sources
.Location
;
4057 Location
:= Element
.Location
;
4064 Location
=> Location
,
4067 Current
:= Element
.Next
;
4070 Get_Path_Names_And_Record_Sources
(Follow_Links
);
4073 -- No source_files specified
4075 -- We check Source_List_File has been specified
4077 elsif not Source_List_File
.Default
then
4079 -- Source_List_File is the name of the file
4080 -- that contains the source file names
4083 Source_File_Path_Name
: constant String :=
4085 (Source_List_File
.Value
,
4089 if Source_File_Path_Name
'Length = 0 then
4090 Err_Vars
.Error_Msg_Name_1
:= Source_List_File
.Value
;
4093 "file with sources { does not exist",
4094 Source_List_File
.Location
);
4097 Get_Sources_From_File
4098 (Source_File_Path_Name
,
4099 Source_List_File
.Location
);
4104 -- Neither Source_Files nor Source_List_File has been
4105 -- specified. Find all the files that satisfy the naming
4106 -- scheme in all the source directories.
4109 (Project
, In_Tree
, Data
, Ada_Language_Index
, Follow_Links
);
4112 -- If there are sources that are locally removed, mark them as
4113 -- such in the Units table.
4115 if not Locally_Removed
.Default
then
4117 -- Sources can be locally removed only in extending
4120 if Data
.Extends
= No_Project
then
4123 "Locally_Removed_Files can only be used " &
4124 "in an extending project file",
4125 Locally_Removed
.Location
);
4129 Current
: String_List_Id
:= Locally_Removed
.Values
;
4130 Element
: String_Element
;
4131 Location
: Source_Ptr
;
4135 Extended
: Project_Id
;
4138 while Current
/= Nil_String
loop
4140 In_Tree
.String_Elements
.Table
(Current
);
4141 Get_Name_String
(Element
.Value
);
4142 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4145 -- If the element has no location, then use the
4146 -- location of Locally_Removed to report
4149 if Element
.Location
= No_Location
then
4150 Location
:= Locally_Removed
.Location
;
4152 Location
:= Element
.Location
;
4157 for Index
in Unit_Table
.First
..
4158 Unit_Table
.Last
(In_Tree
.Units
)
4160 Unit
:= In_Tree
.Units
.Table
(Index
);
4162 if Unit
.File_Names
(Specification
).Name
= Name
then
4165 -- Check that this is from a project that
4166 -- the current project extends, but not the
4169 Extended
:= Unit
.File_Names
4170 (Specification
).Project
;
4172 if Extended
= Project
then
4175 "cannot remove a source " &
4176 "of the same project",
4180 Project_Extends
(Project
, Extended
, In_Tree
)
4183 (Specification
).Path
:= Slash
;
4185 (Specification
).Needs_Pragma
:= False;
4186 In_Tree
.Units
.Table
(Index
) :=
4188 Add_Forbidden_File_Name
4189 (Unit
.File_Names
(Specification
).Name
);
4195 "cannot remove a source from " &
4201 Unit
.File_Names
(Body_Part
).Name
= Name
4205 -- Check that this is from a project that
4206 -- the current project extends, but not the
4209 Extended
:= Unit
.File_Names
4210 (Body_Part
).Project
;
4212 if Extended
= Project
then
4215 "cannot remove a source " &
4216 "of the same project",
4220 Project_Extends
(Project
, Extended
, In_Tree
)
4222 Unit
.File_Names
(Body_Part
).Path
:= Slash
;
4223 Unit
.File_Names
(Body_Part
).Needs_Pragma
4225 In_Tree
.Units
.Table
(Index
) :=
4227 Add_Forbidden_File_Name
4228 (Unit
.File_Names
(Body_Part
).Name
);
4236 Err_Vars
.Error_Msg_Name_1
:= Name
;
4238 (Project
, In_Tree
, "unknown file {", Location
);
4241 Current
:= Element
.Next
;
4249 if Data
.Other_Sources_Present
then
4251 -- Set Source_Present to False. It will be set back to True
4252 -- whenever a source is found.
4254 Data
.Other_Sources_Present
:= False;
4255 for Lang
in Ada_Language_Index
+ 1 .. Last_Language_Index
loop
4257 -- For each language (other than Ada) in the project file
4259 if Is_Present
(Lang
, Data
, In_Tree
) then
4261 -- Reset the indication that there are sources of this
4262 -- language. It will be set back to True whenever we find a
4263 -- source of the language.
4265 Set
(Lang
, False, Data
, In_Tree
);
4267 -- First, get the source suffix for the language
4269 Set
(Suffix
=> Suffix_For
(Lang
, Data
.Naming
, In_Tree
),
4270 For_Language
=> Lang
,
4272 In_Tree
=> In_Tree
);
4274 -- Then, deal with the naming exceptions, if any
4279 Naming_Exceptions
: constant Variable_Value
:=
4281 (Index
=> Language_Names
.Table
(Lang
),
4283 In_Array
=> Data
.Naming
.Implementation_Exceptions
,
4284 In_Tree
=> In_Tree
);
4285 Element_Id
: String_List_Id
;
4286 Element
: String_Element
;
4288 Source_Found
: Boolean := False;
4291 -- If there are naming exceptions, look through them one
4294 if Naming_Exceptions
/= Nil_Variable_Value
then
4295 Element_Id
:= Naming_Exceptions
.Values
;
4297 while Element_Id
/= Nil_String
loop
4298 Element
:= In_Tree
.String_Elements
.Table
4300 Get_Name_String
(Element
.Value
);
4301 Canonical_Case_File_Name
4302 (Name_Buffer
(1 .. Name_Len
));
4303 File_Id
:= Name_Find
;
4305 -- Put each naming exception in the Source_Names
4306 -- hash table, but if there are repetition, don't
4307 -- bother after the first instance.
4310 Source_Names
.Get
(File_Id
) = No_Name_Location
4312 Source_Found
:= True;
4316 Location
=> Element
.Location
,
4320 Element_Id
:= Element
.Next
;
4323 -- If there is at least one naming exception, record
4324 -- those that are found in the source directories.
4326 if Source_Found
then
4327 Record_Other_Sources
4328 (Project
=> Project
,
4332 Naming_Exceptions
=> True);
4338 -- Now, check if a list of sources is declared either through
4339 -- a string list (attribute Source_Files) or a text file
4340 -- (attribute Source_List_File). If a source list is declared,
4341 -- we will consider only those naming exceptions that are
4345 Sources
: constant Variable_Value
:=
4348 Data
.Decl
.Attributes
,
4351 Source_List_File
: constant Variable_Value
:=
4353 (Name_Source_List_File
,
4354 Data
.Decl
.Attributes
,
4359 (Sources
.Kind
= List
,
4360 "Source_Files is not a list");
4363 (Source_List_File
.Kind
= Single
,
4364 "Source_List_File is not a single string");
4366 if not Sources
.Default
then
4367 if not Source_List_File
.Default
then
4370 "?both variables source_files and " &
4371 "source_list_file are present",
4372 Source_List_File
.Location
);
4375 -- Sources is a list of file names
4378 Current
: String_List_Id
:= Sources
.Values
;
4379 Element
: String_Element
;
4380 Location
: Source_Ptr
;
4386 -- Put all the sources in the Source_Names hash table
4388 while Current
/= Nil_String
loop
4390 In_Tree
.String_Elements
.Table
4392 Get_Name_String
(Element
.Value
);
4393 Canonical_Case_File_Name
4394 (Name_Buffer
(1 .. Name_Len
));
4397 -- If the element has no location, then use the
4398 -- location of Sources to report possible errors.
4400 if Element
.Location
= No_Location
then
4401 Location
:= Sources
.Location
;
4403 Location
:= Element
.Location
;
4410 Location
=> Location
,
4413 Current
:= Element
.Next
;
4416 -- And look for their directories
4418 Record_Other_Sources
4419 (Project
=> Project
,
4423 Naming_Exceptions
=> False);
4426 -- No source_files specified
4428 -- We check if Source_List_File has been specified
4430 elsif not Source_List_File
.Default
then
4432 -- Source_List_File is the name of the file
4433 -- that contains the source file names
4436 Source_File_Path_Name
: constant String :=
4438 (Source_List_File
.Value
,
4442 if Source_File_Path_Name
'Length = 0 then
4443 Err_Vars
.Error_Msg_Name_1
:=
4444 Source_List_File
.Value
;
4447 "file with sources { does not exist",
4448 Source_List_File
.Location
);
4451 -- Read the file, putting each source in the
4452 -- Source_Names hash table.
4454 Get_Sources_From_File
4455 (Source_File_Path_Name
,
4456 Source_List_File
.Location
,
4459 -- And look for their directories
4461 Record_Other_Sources
4462 (Project
=> Project
,
4466 Naming_Exceptions
=> False);
4470 -- Neither Source_Files nor Source_List_File was specified
4473 -- Find all the files that satisfy the naming scheme in
4474 -- all the source directories. All the naming exceptions
4475 -- that effectively exist are also part of the source
4476 -- of this language.
4478 Find_Sources
(Project
, In_Tree
, Data
, Lang
);
4484 end Look_For_Sources
;
4490 function Path_Name_Of
4491 (File_Name
: Name_Id
;
4492 Directory
: Name_Id
) return String
4494 Result
: String_Access
;
4496 The_Directory
: constant String := Get_Name_String
(Directory
);
4499 Get_Name_String
(File_Name
);
4500 Result
:= Locate_Regular_File
4501 (File_Name
=> Name_Buffer
(1 .. Name_Len
),
4502 Path
=> The_Directory
);
4504 if Result
= null then
4507 Canonical_Case_File_Name
(Result
.all);
4512 -------------------------------
4513 -- Prepare_Ada_Naming_Exceptions --
4514 -------------------------------
4516 procedure Prepare_Ada_Naming_Exceptions
4517 (List
: Array_Element_Id
;
4518 In_Tree
: Project_Tree_Ref
;
4519 Kind
: Spec_Or_Body
)
4521 Current
: Array_Element_Id
:= List
;
4522 Element
: Array_Element
;
4527 -- Traverse the list
4529 while Current
/= No_Array_Element
loop
4530 Element
:= In_Tree
.Array_Elements
.Table
(Current
);
4532 if Element
.Index
/= No_Name
then
4535 Unit
=> Element
.Index
,
4536 Next
=> No_Ada_Naming_Exception
);
4537 Reverse_Ada_Naming_Exceptions
.Set
4538 (Unit
, (Element
.Value
.Value
, Element
.Value
.Index
));
4539 Unit
.Next
:= Ada_Naming_Exceptions
.Get
(Element
.Value
.Value
);
4540 Ada_Naming_Exception_Table
.Increment_Last
;
4541 Ada_Naming_Exception_Table
.Table
4542 (Ada_Naming_Exception_Table
.Last
) := Unit
;
4543 Ada_Naming_Exceptions
.Set
4544 (Element
.Value
.Value
, Ada_Naming_Exception_Table
.Last
);
4547 Current
:= Element
.Next
;
4549 end Prepare_Ada_Naming_Exceptions
;
4551 ---------------------
4552 -- Project_Extends --
4553 ---------------------
4555 function Project_Extends
4556 (Extending
: Project_Id
;
4557 Extended
: Project_Id
;
4558 In_Tree
: Project_Tree_Ref
) return Boolean
4560 Current
: Project_Id
:= Extending
;
4563 if Current
= No_Project
then
4566 elsif Current
= Extended
then
4570 Current
:= In_Tree
.Projects
.Table
(Current
).Extends
;
4572 end Project_Extends
;
4574 -----------------------
4575 -- Record_Ada_Source --
4576 -----------------------
4578 procedure Record_Ada_Source
4579 (File_Name
: Name_Id
;
4580 Path_Name
: Name_Id
;
4581 Project
: Project_Id
;
4582 In_Tree
: Project_Tree_Ref
;
4583 Data
: in out Project_Data
;
4584 Location
: Source_Ptr
;
4585 Current_Source
: in out String_List_Id
;
4586 Source_Recorded
: in out Boolean;
4587 Follow_Links
: Boolean)
4589 Canonical_File_Name
: Name_Id
;
4590 Canonical_Path_Name
: Name_Id
;
4592 Exception_Id
: Ada_Naming_Exception_Id
;
4593 Unit_Name
: Name_Id
;
4594 Unit_Kind
: Spec_Or_Body
;
4595 Unit_Index
: Int
:= 0;
4597 Name_Index
: Name_And_Index
;
4598 Needs_Pragma
: Boolean;
4600 The_Location
: Source_Ptr
:= Location
;
4601 Previous_Source
: constant String_List_Id
:= Current_Source
;
4602 Except_Name
: Name_And_Index
:= No_Name_And_Index
;
4604 Unit_Prj
: Unit_Project
;
4606 File_Name_Recorded
: Boolean := False;
4609 Get_Name_String
(File_Name
);
4610 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4611 Canonical_File_Name
:= Name_Find
;
4614 Canonical_Path
: constant String :=
4616 (Get_Name_String
(Path_Name
),
4617 Resolve_Links
=> Follow_Links
,
4618 Case_Sensitive
=> False);
4621 Add_Str_To_Name_Buffer
(Canonical_Path
);
4622 Canonical_Path_Name
:= Name_Find
;
4625 -- Find out the unit name, the unit kind and if it needs
4626 -- a specific SFN pragma.
4629 (Canonical_File_Name
=> Canonical_File_Name
,
4630 Naming
=> Data
.Naming
,
4631 Exception_Id
=> Exception_Id
,
4632 Unit_Name
=> Unit_Name
,
4633 Unit_Kind
=> Unit_Kind
,
4634 Needs_Pragma
=> Needs_Pragma
);
4636 if Exception_Id
= No_Ada_Naming_Exception
and then
4639 if Current_Verbosity
= High
then
4641 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4642 Write_Line
(""" is not a valid source file name (ignored).");
4646 -- Check to see if the source has been hidden by an exception,
4647 -- but only if it is not an exception.
4649 if not Needs_Pragma
then
4651 Reverse_Ada_Naming_Exceptions
.Get
4652 ((Unit_Kind
, Unit_Name
, No_Ada_Naming_Exception
));
4654 if Except_Name
/= No_Name_And_Index
then
4655 if Current_Verbosity
= High
then
4657 Write_Str
(Get_Name_String
(Canonical_File_Name
));
4658 Write_Str
(""" contains a unit that is found in """);
4659 Write_Str
(Get_Name_String
(Except_Name
.Name
));
4660 Write_Line
(""" (ignored).");
4663 -- The file is not included in the source of the project,
4664 -- because it is hidden by the exception.
4665 -- So, there is nothing else to do.
4672 if Exception_Id
/= No_Ada_Naming_Exception
then
4673 Info
:= Ada_Naming_Exception_Table
.Table
(Exception_Id
);
4674 Exception_Id
:= Info
.Next
;
4675 Info
.Next
:= No_Ada_Naming_Exception
;
4676 Name_Index
:= Reverse_Ada_Naming_Exceptions
.Get
(Info
);
4678 Unit_Name
:= Info
.Unit
;
4679 Unit_Index
:= Name_Index
.Index
;
4680 Unit_Kind
:= Info
.Kind
;
4683 -- Put the file name in the list of sources of the project
4685 if not File_Name_Recorded
then
4686 String_Element_Table
.Increment_Last
4687 (In_Tree
.String_Elements
);
4688 In_Tree
.String_Elements
.Table
4689 (String_Element_Table
.Last
4690 (In_Tree
.String_Elements
)) :=
4691 (Value
=> Canonical_File_Name
,
4692 Display_Value
=> File_Name
,
4693 Location
=> No_Location
,
4696 Index
=> Unit_Index
);
4699 if Current_Source
= Nil_String
then
4700 Data
.Sources
:= String_Element_Table
.Last
4701 (In_Tree
.String_Elements
);
4703 In_Tree
.String_Elements
.Table
4704 (Current_Source
).Next
:=
4705 String_Element_Table
.Last
4706 (In_Tree
.String_Elements
);
4709 Current_Source
:= String_Element_Table
.Last
4710 (In_Tree
.String_Elements
);
4712 -- Put the unit in unit list
4715 The_Unit
: Unit_Id
:=
4716 Units_Htable
.Get
(In_Tree
.Units_HT
, Unit_Name
);
4717 The_Unit_Data
: Unit_Data
;
4720 if Current_Verbosity
= High
then
4721 Write_Str
("Putting ");
4722 Write_Str
(Get_Name_String
(Unit_Name
));
4723 Write_Line
(" in the unit list.");
4726 -- The unit is already in the list, but may be it is
4727 -- only the other unit kind (spec or body), or what is
4728 -- in the unit list is a unit of a project we are extending.
4730 if The_Unit
/= No_Unit
then
4731 The_Unit_Data
:= In_Tree
.Units
.Table
(The_Unit
);
4733 if The_Unit_Data
.File_Names
(Unit_Kind
).Name
= No_Name
4734 or else Project_Extends
4736 The_Unit_Data
.File_Names
(Unit_Kind
).Project
,
4739 if The_Unit_Data
.File_Names
(Unit_Kind
).Path
= Slash
then
4740 Remove_Forbidden_File_Name
4741 (The_Unit_Data
.File_Names
(Unit_Kind
).Name
);
4744 -- Record the file name in the hash table Files_Htable
4746 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4749 Canonical_File_Name
,
4752 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4753 (Name
=> Canonical_File_Name
,
4754 Index
=> Unit_Index
,
4755 Display_Name
=> File_Name
,
4756 Path
=> Canonical_Path_Name
,
4757 Display_Path
=> Path_Name
,
4759 Needs_Pragma
=> Needs_Pragma
);
4760 In_Tree
.Units
.Table
(The_Unit
) :=
4762 Source_Recorded
:= True;
4764 elsif The_Unit_Data
.File_Names
(Unit_Kind
).Project
= Project
4765 and then (Data
.Known_Order_Of_Source_Dirs
or else
4766 The_Unit_Data
.File_Names
(Unit_Kind
).Path
=
4767 Canonical_Path_Name
)
4769 if Previous_Source
= Nil_String
then
4770 Data
.Sources
:= Nil_String
;
4772 In_Tree
.String_Elements
.Table
4773 (Previous_Source
).Next
:= Nil_String
;
4774 String_Element_Table
.Decrement_Last
4775 (In_Tree
.String_Elements
);
4778 Current_Source
:= Previous_Source
;
4781 -- It is an error to have two units with the same name
4782 -- and the same kind (spec or body).
4784 if The_Location
= No_Location
then
4786 In_Tree
.Projects
.Table
4790 Err_Vars
.Error_Msg_Name_1
:= Unit_Name
;
4792 (Project
, In_Tree
, "duplicate source {", The_Location
);
4794 Err_Vars
.Error_Msg_Name_1
:=
4795 In_Tree
.Projects
.Table
4796 (The_Unit_Data
.File_Names
(Unit_Kind
).Project
).Name
;
4797 Err_Vars
.Error_Msg_Name_2
:=
4798 The_Unit_Data
.File_Names
(Unit_Kind
).Path
;
4801 "\ project file {, {", The_Location
);
4803 Err_Vars
.Error_Msg_Name_1
:=
4804 In_Tree
.Projects
.Table
(Project
).Name
;
4805 Err_Vars
.Error_Msg_Name_2
:= Canonical_Path_Name
;
4808 "\ project file {, {", The_Location
);
4811 -- It is a new unit, create a new record
4814 -- First, check if there is no other unit with this file
4815 -- name in another project. If it is, report an error.
4816 -- Of course, we do that only for the first unit in the
4819 Unit_Prj
:= Files_Htable
.Get
4820 (In_Tree
.Files_HT
, Canonical_File_Name
);
4822 if not File_Name_Recorded
and then
4823 Unit_Prj
/= No_Unit_Project
4825 Error_Msg_Name_1
:= File_Name
;
4827 In_Tree
.Projects
.Table
4828 (Unit_Prj
.Project
).Name
;
4831 "{ is already a source of project {",
4835 Unit_Table
.Increment_Last
(In_Tree
.Units
);
4836 The_Unit
:= Unit_Table
.Last
(In_Tree
.Units
);
4838 (In_Tree
.Units_HT
, Unit_Name
, The_Unit
);
4839 Unit_Prj
:= (Unit
=> The_Unit
, Project
=> Project
);
4842 Canonical_File_Name
,
4844 The_Unit_Data
.Name
:= Unit_Name
;
4845 The_Unit_Data
.File_Names
(Unit_Kind
) :=
4846 (Name
=> Canonical_File_Name
,
4847 Index
=> Unit_Index
,
4848 Display_Name
=> File_Name
,
4849 Path
=> Canonical_Path_Name
,
4850 Display_Path
=> Path_Name
,
4852 Needs_Pragma
=> Needs_Pragma
);
4853 In_Tree
.Units
.Table
(The_Unit
) :=
4855 Source_Recorded
:= True;
4860 exit when Exception_Id
= No_Ada_Naming_Exception
;
4861 File_Name_Recorded
:= True;
4864 end Record_Ada_Source
;
4866 --------------------------
4867 -- Record_Other_Sources --
4868 --------------------------
4870 procedure Record_Other_Sources
4871 (Project
: Project_Id
;
4872 In_Tree
: Project_Tree_Ref
;
4873 Data
: in out Project_Data
;
4874 Language
: Language_Index
;
4875 Naming_Exceptions
: Boolean)
4877 Source_Dir
: String_List_Id
:= Data
.Source_Dirs
;
4878 Element
: String_Element
;
4882 Canonical_Name
: Name_Id
;
4884 Name_Str
: String (1 .. 1_024
);
4885 Last
: Natural := 0;
4888 First_Error
: Boolean := True;
4890 Suffix
: constant String := Body_Suffix_Of
(Language
, Data
, In_Tree
);
4893 while Source_Dir
/= Nil_String
loop
4894 Element
:= In_Tree
.String_Elements
.Table
(Source_Dir
);
4897 Dir_Path
: constant String := Get_Name_String
(Element
.Value
);
4900 if Current_Verbosity
= High
then
4901 Write_Str
("checking directory """);
4902 Write_Str
(Dir_Path
);
4903 Write_Str
(""" for ");
4905 if Naming_Exceptions
then
4906 Write_Str
("naming exceptions");
4909 Write_Str
("sources");
4912 Write_Str
(" of Language ");
4913 Display_Language_Name
(Language
);
4916 Open
(Dir
, Dir_Path
);
4919 Read
(Dir
, Name_Str
, Last
);
4923 (Dir_Path
& Directory_Separator
& Name_Str
(1 .. Last
))
4926 Name_Buffer
(1 .. Name_Len
) := Name_Str
(1 .. Last
);
4927 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
4928 Canonical_Name
:= Name_Find
;
4929 NL
:= Source_Names
.Get
(Canonical_Name
);
4931 if NL
/= No_Name_Location
then
4933 if not Data
.Known_Order_Of_Source_Dirs
then
4934 Error_Msg_Name_1
:= Canonical_Name
;
4937 "{ is found in several source directories",
4943 Source_Names
.Set
(Canonical_Name
, NL
);
4944 Name_Len
:= Dir_Path
'Length;
4945 Name_Buffer
(1 .. Name_Len
) := Dir_Path
;
4946 Add_Char_To_Name_Buffer
(Directory_Separator
);
4947 Add_Str_To_Name_Buffer
(Name_Str
(1 .. Last
));
4951 (File_Name
=> Canonical_Name
,
4956 Location
=> NL
.Location
,
4957 Language
=> Language
,
4959 Naming_Exception
=> Naming_Exceptions
);
4968 Source_Dir
:= Element
.Next
;
4971 if not Naming_Exceptions
then
4972 NL
:= Source_Names
.Get_First
;
4974 -- It is an error if a source file name in a source list or
4975 -- in a source list file is not found.
4977 while NL
/= No_Name_Location
loop
4978 if not NL
.Found
then
4979 Err_Vars
.Error_Msg_Name_1
:= NL
.Name
;
4984 "source file { cannot be found",
4986 First_Error
:= False;
4991 "\source file { cannot be found",
4996 NL
:= Source_Names
.Get_Next
;
4999 -- Any naming exception of this language that is not in a list
5000 -- of sources must be removed.
5003 Source_Id
: Other_Source_Id
:= Data
.First_Other_Source
;
5004 Prev_Id
: Other_Source_Id
:= No_Other_Source
;
5005 Source
: Other_Source
;
5008 while Source_Id
/= No_Other_Source
loop
5009 Source
:= In_Tree
.Other_Sources
.Table
(Source_Id
);
5011 if Source
.Language
= Language
5012 and then Source
.Naming_Exception
5014 if Current_Verbosity
= High
then
5015 Write_Str
("Naming exception """);
5016 Write_Str
(Get_Name_String
(Source
.File_Name
));
5017 Write_Str
(""" is not in the list of sources,");
5018 Write_Line
(" so it is removed.");
5021 if Prev_Id
= No_Other_Source
then
5022 Data
.First_Other_Source
:= Source
.Next
;
5025 In_Tree
.Other_Sources
.Table
5026 (Prev_Id
).Next
:= Source
.Next
;
5029 Source_Id
:= Source
.Next
;
5031 if Source_Id
= No_Other_Source
then
5032 Data
.Last_Other_Source
:= Prev_Id
;
5036 Prev_Id
:= Source_Id
;
5037 Source_Id
:= Source
.Next
;
5042 end Record_Other_Sources
;
5044 ----------------------
5045 -- Show_Source_Dirs --
5046 ----------------------
5048 procedure Show_Source_Dirs
5049 (Project
: Project_Id
;
5050 In_Tree
: Project_Tree_Ref
)
5052 Current
: String_List_Id
;
5053 Element
: String_Element
;
5056 Write_Line
("Source_Dirs:");
5058 Current
:= In_Tree
.Projects
.Table
(Project
).Source_Dirs
;
5059 while Current
/= Nil_String
loop
5060 Element
:= In_Tree
.String_Elements
.Table
(Current
);
5062 Write_Line
(Get_Name_String
(Element
.Value
));
5063 Current
:= Element
.Next
;
5066 Write_Line
("end Source_Dirs.");
5067 end Show_Source_Dirs
;
5074 (Language
: Language_Index
;
5075 Naming
: Naming_Data
;
5076 In_Tree
: Project_Tree_Ref
) return Name_Id
5078 Suffix
: constant Variable_Value
:=
5080 (Index
=> Language_Names
.Table
(Language
),
5082 In_Array
=> Naming
.Body_Suffix
,
5083 In_Tree
=> In_Tree
);
5085 -- If no suffix for this language in package Naming, use the default
5087 if Suffix
= Nil_Variable_Value
then
5091 when Ada_Language_Index
=>
5092 Add_Str_To_Name_Buffer
(".adb");
5094 when C_Language_Index
=>
5095 Add_Str_To_Name_Buffer
(".c");
5097 when C_Plus_Plus_Language_Index
=>
5098 Add_Str_To_Name_Buffer
(".cc");
5104 -- Otherwise use the one specified
5107 Get_Name_String
(Suffix
.Value
);
5110 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
5114 -------------------------
5115 -- Warn_If_Not_Sources --
5116 -------------------------
5118 -- comments needed in this body ???
5120 procedure Warn_If_Not_Sources
5121 (Project
: Project_Id
;
5122 In_Tree
: Project_Tree_Ref
;
5123 Conventions
: Array_Element_Id
;
5125 Extending
: Boolean)
5127 Conv
: Array_Element_Id
:= Conventions
;
5129 The_Unit_Id
: Unit_Id
;
5130 The_Unit_Data
: Unit_Data
;
5131 Location
: Source_Ptr
;
5134 while Conv
/= No_Array_Element
loop
5135 Unit
:= In_Tree
.Array_Elements
.Table
(Conv
).Index
;
5136 Error_Msg_Name_1
:= Unit
;
5137 Get_Name_String
(Unit
);
5138 To_Lower
(Name_Buffer
(1 .. Name_Len
));
5140 The_Unit_Id
:= Units_Htable
.Get
5141 (In_Tree
.Units_HT
, Unit
);
5142 Location
:= In_Tree
.Array_Elements
.Table
5143 (Conv
).Value
.Location
;
5145 if The_Unit_Id
= No_Unit
then
5152 The_Unit_Data
:= In_Tree
.Units
.Table
(The_Unit_Id
);
5155 if not Check_Project
5156 (The_Unit_Data
.File_Names
(Specification
).Project
,
5157 Project
, In_Tree
, Extending
)
5161 "?unit{ has no spec in this project",
5166 if not Check_Project
5167 (The_Unit_Data
.File_Names
(Body_Part
).Project
,
5168 Project
, In_Tree
, Extending
)
5172 "?unit{ has no body in this project",
5178 Conv
:= In_Tree
.Array_Elements
.Table
(Conv
).Next
;
5180 end Warn_If_Not_Sources
;