* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / prj-nmsc.adb
blobbc7adfa375a9432c0518f352866ea229520de71b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J . N M S C --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2000-2005 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Err_Vars; use Err_Vars;
28 with Fmap; use Fmap;
29 with Hostparm;
30 with MLib.Tgt;
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;
36 with Prj.Err;
37 with Prj.Util; use Prj.Util;
38 with Sinput.P;
39 with Snames; use Snames;
40 with Table; use Table;
42 with Ada.Characters.Handling; use Ada.Characters.Handling;
43 with Ada.Strings; use Ada.Strings;
44 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
45 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
47 with GNAT.Case_Util; use GNAT.Case_Util;
48 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
49 with GNAT.HTable;
51 package body Prj.Nmsc is
53 Error_Report : Put_Line_Access := null;
54 -- Set to point to error reporting procedure
56 ALI_Suffix : constant String := ".ali";
57 -- File suffix for ali files
59 Object_Suffix : constant String := Get_Object_Suffix.all;
60 -- File suffix for object files
62 type Name_Location is record
63 Name : Name_Id;
64 Location : Source_Ptr;
65 Found : Boolean := False;
66 end record;
67 -- Information about file names found in string list attribute
68 -- Source_Files or in a source list file, stored in hash table
69 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
71 No_Name_Location : constant Name_Location :=
72 (Name => No_Name, Location => No_Location, Found => False);
74 package Source_Names is new GNAT.HTable.Simple_HTable
75 (Header_Num => Header_Num,
76 Element => Name_Location,
77 No_Element => No_Name_Location,
78 Key => Name_Id,
79 Hash => Hash,
80 Equal => "=");
81 -- Hash table to store file names found in string list attribute
82 -- Source_Files or in a source list file, stored in hash table
83 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
85 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
86 (Header_Num => Header_Num,
87 Element => Boolean,
88 No_Element => False,
89 Key => Name_Id,
90 Hash => Hash,
91 Equal => "=");
92 -- Hash table to store recursive source directories, to avoid looking
93 -- several times, and to avoid cycles that may be introduced by symbolic
94 -- links.
96 type Ada_Naming_Exception_Id is new Nat;
97 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
99 type Unit_Info is record
100 Kind : Spec_Or_Body;
101 Unit : Name_Id;
102 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
103 end record;
104 -- No_Unit : constant Unit_Info :=
105 -- (Specification, No_Name, No_Ada_Naming_Exception);
107 package Ada_Naming_Exception_Table is new Table.Table
108 (Table_Component_Type => Unit_Info,
109 Table_Index_Type => Ada_Naming_Exception_Id,
110 Table_Low_Bound => 1,
111 Table_Initial => 20,
112 Table_Increment => 100,
113 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
115 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
116 (Header_Num => Header_Num,
117 Element => Ada_Naming_Exception_Id,
118 No_Element => No_Ada_Naming_Exception,
119 Key => Name_Id,
120 Hash => Hash,
121 Equal => "=");
122 -- A hash table to store naming exceptions for Ada. For each file name
123 -- there is one or several unit in table Ada_Naming_Exception_Table.
125 function Hash (Unit : Unit_Info) return Header_Num;
127 type Name_And_Index is record
128 Name : Name_Id := No_Name;
129 Index : Int := 0;
130 end record;
131 No_Name_And_Index : constant Name_And_Index :=
132 (Name => No_Name, Index => 0);
134 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
135 (Header_Num => Header_Num,
136 Element => Name_And_Index,
137 No_Element => No_Name_And_Index,
138 Key => Unit_Info,
139 Hash => Hash,
140 Equal => "=");
141 -- A table to check if a unit with an exceptional name will hide
142 -- a source with a file name following the naming convention.
144 function ALI_File_Name (Source : String) return String;
145 -- Return the ALI file name corresponding to a source
147 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
148 -- Check that a name is a valid Ada unit name
150 procedure Check_Naming_Scheme
151 (Data : in out Project_Data;
152 Project : Project_Id;
153 In_Tree : Project_Tree_Ref);
154 -- Check the naming scheme part of Data
156 procedure Check_Ada_Naming_Scheme_Validity
157 (Project : Project_Id;
158 In_Tree : Project_Tree_Ref;
159 Naming : Naming_Data);
160 -- Check that the package Naming is correct
162 procedure Check_For_Source
163 (File_Name : Name_Id;
164 Path_Name : Name_Id;
165 Project : Project_Id;
166 In_Tree : Project_Tree_Ref;
167 Data : in out Project_Data;
168 Location : Source_Ptr;
169 Language : Language_Index;
170 Suffix : String;
171 Naming_Exception : Boolean);
172 -- Check if a file, with name File_Name and path Path_Name, in a source
173 -- directory is a source for language Language in project Project of
174 -- project tree In_Tree. ???
176 procedure Check_If_Externally_Built
177 (Project : Project_Id;
178 In_Tree : Project_Tree_Ref;
179 Data : in out Project_Data);
180 -- Check attribute Externally_Built of project Project in project tree
181 -- In_Tree and modify its data Data if it has the value "true".
183 procedure Check_Library_Attributes
184 (Project : Project_Id;
185 In_Tree : Project_Tree_Ref;
186 Data : in out Project_Data);
187 -- Check the library attributes of project Project in project tree In_Tree
188 -- and modify its data Data accordingly.
190 procedure Check_Package_Naming
191 (Project : Project_Id;
192 In_Tree : Project_Tree_Ref;
193 Data : in out Project_Data);
194 -- Check package Naming of project Project in project tree In_Tree and
195 -- modify its data Data accordingly.
197 procedure Check_Programming_Languages
198 (In_Tree : Project_Tree_Ref; Data : in out Project_Data);
199 -- Check attribute Languages for the project with data Data in project
200 -- tree In_Tree and set the components of Data for all the programming
201 -- languages indicated in attribute Languages, if any.
203 function Check_Project
204 (P : Project_Id;
205 Root_Project : Project_Id;
206 In_Tree : Project_Tree_Ref;
207 Extending : Boolean) return Boolean;
208 -- Returns True if P is Root_Project or, if Extending is True, a project
209 -- extended by Root_Project.
211 procedure Check_Stand_Alone_Library
212 (Project : Project_Id;
213 In_Tree : Project_Tree_Ref;
214 Data : in out Project_Data;
215 Extending : Boolean);
216 -- Check if project Project in project tree In_Tree is a Stand-Alone
217 -- Library project, and modify its data Data accordingly if it is one.
219 function Compute_Directory_Last (Dir : String) return Natural;
220 -- Return the index of the last significant character in Dir. This is used
221 -- to avoid duplicates '/' at the end of directory names
223 function Body_Suffix_Of
224 (Language : Language_Index;
225 In_Project : Project_Data;
226 In_Tree : Project_Tree_Ref)
227 return String;
228 -- Returns the suffix of sources of language Language in project In_Project
229 -- in project tree In_Tree.
231 procedure Error_Msg
232 (Project : Project_Id;
233 In_Tree : Project_Tree_Ref;
234 Msg : String;
235 Flag_Location : Source_Ptr);
236 -- Output an error message. If Error_Report is null, simply call
237 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
238 -- Error_Report.
240 procedure Find_Sources
241 (Project : Project_Id;
242 In_Tree : Project_Tree_Ref;
243 Data : in out Project_Data;
244 For_Language : Language_Index;
245 Follow_Links : Boolean := False);
246 -- Find all the sources in all of the source directories of a project for
247 -- a specified language.
249 procedure Free_Ada_Naming_Exceptions;
250 -- Free the internal hash tables used for checking naming exceptions
252 procedure Get_Directories
253 (Project : Project_Id;
254 In_Tree : Project_Tree_Ref;
255 Data : in out Project_Data);
256 -- Get the object directory, the exec directory and the source directories
257 -- of a project.
259 procedure Get_Mains
260 (Project : Project_Id;
261 In_Tree : Project_Tree_Ref;
262 Data : in out Project_Data);
263 -- Get the mains of a project from attribute Main, if it exists, and put
264 -- them in the project data.
266 procedure Get_Sources_From_File
267 (Path : String;
268 Location : Source_Ptr;
269 Project : Project_Id;
270 In_Tree : Project_Tree_Ref);
271 -- Get the list of sources from a text file and put them in hash table
272 -- Source_Names.
274 procedure Get_Unit
275 (Canonical_File_Name : Name_Id;
276 Naming : Naming_Data;
277 Exception_Id : out Ada_Naming_Exception_Id;
278 Unit_Name : out Name_Id;
279 Unit_Kind : out Spec_Or_Body;
280 Needs_Pragma : out Boolean);
281 -- Find out, from a file name, the unit name, the unit kind and if a
282 -- specific SFN pragma is needed. If the file name corresponds to no
283 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
284 -- or an exception to the naming scheme, then Exception_Id is set to
285 -- the unit or units that the source contains.
287 function Is_Illegal_Suffix
288 (Suffix : String;
289 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
290 -- Returns True if the string Suffix cannot be used as
291 -- a spec suffix, a body suffix or a separate suffix.
293 procedure Locate_Directory
294 (Name : Name_Id;
295 Parent : Name_Id;
296 Dir : out Name_Id;
297 Display : out Name_Id);
298 -- Locate a directory (returns No_Name for Dir and Display if directory
299 -- does not exist). Name is the directory name. Parent is the root
300 -- directory, if Name is a relative path name. Dir is the canonical case
301 -- path name of the directory, Display is the directory path name for
302 -- display purposes.
304 procedure Look_For_Sources
305 (Project : Project_Id;
306 In_Tree : Project_Tree_Ref;
307 Data : in out Project_Data;
308 Follow_Links : Boolean);
309 -- Find all the sources of a project
311 function Path_Name_Of
312 (File_Name : Name_Id;
313 Directory : Name_Id) return String;
314 -- Returns the path name of a (non project) file.
315 -- Returns an empty string if file cannot be found.
317 procedure Prepare_Ada_Naming_Exceptions
318 (List : Array_Element_Id;
319 In_Tree : Project_Tree_Ref;
320 Kind : Spec_Or_Body);
321 -- Prepare the internal hash tables used for checking naming exceptions
322 -- for Ada. Insert all elements of List in the tables.
324 function Project_Extends
325 (Extending : Project_Id;
326 Extended : Project_Id;
327 In_Tree : Project_Tree_Ref) return Boolean;
328 -- Returns True if Extending is extending Extended either directly or
329 -- indirectly.
331 procedure Record_Ada_Source
332 (File_Name : Name_Id;
333 Path_Name : Name_Id;
334 Project : Project_Id;
335 In_Tree : Project_Tree_Ref;
336 Data : in out Project_Data;
337 Location : Source_Ptr;
338 Current_Source : in out String_List_Id;
339 Source_Recorded : in out Boolean;
340 Follow_Links : Boolean);
341 -- Put a unit in the list of units of a project, if the file name
342 -- corresponds to a valid unit name.
344 procedure Record_Other_Sources
345 (Project : Project_Id;
346 In_Tree : Project_Tree_Ref;
347 Data : in out Project_Data;
348 Language : Language_Index;
349 Naming_Exceptions : Boolean);
350 -- Record the sources of a language in a project.
351 -- When Naming_Exceptions is True, mark the found sources as such, to
352 -- later remove those that are not named in a list of sources.
354 procedure Show_Source_Dirs
355 (Project : Project_Id; In_Tree : Project_Tree_Ref);
356 -- List all the source directories of a project
358 function Suffix_For
359 (Language : Language_Index;
360 Naming : Naming_Data;
361 In_Tree : Project_Tree_Ref) return Name_Id;
362 -- Get the suffix for the source of a language from a package naming.
363 -- If not specified, return the default for the language.
365 procedure Warn_If_Not_Sources
366 (Project : Project_Id;
367 In_Tree : Project_Tree_Ref;
368 Conventions : Array_Element_Id;
369 Specs : Boolean;
370 Extending : Boolean);
371 -- Check that individual naming conventions apply to immediate
372 -- sources of the project; if not, issue a warning.
374 -------------------
375 -- ALI_File_Name --
376 -------------------
378 function ALI_File_Name (Source : String) return String is
379 begin
380 -- If the source name has an extension, then replace it with
381 -- the ALI suffix.
383 for Index in reverse Source'First + 1 .. Source'Last loop
384 if Source (Index) = '.' then
385 return Source (Source'First .. Index - 1) & ALI_Suffix;
386 end if;
387 end loop;
389 -- If there is no dot, or if it is the first character, just add the
390 -- ALI suffix.
392 return Source & ALI_Suffix;
393 end ALI_File_Name;
395 -----------
396 -- Check --
397 -----------
399 procedure Check
400 (Project : Project_Id;
401 In_Tree : Project_Tree_Ref;
402 Report_Error : Put_Line_Access;
403 Follow_Links : Boolean)
405 Data : Project_Data := In_Tree.Projects.Table (Project);
406 Extending : Boolean := False;
408 begin
409 Error_Report := Report_Error;
411 Recursive_Dirs.Reset;
413 -- Object, exec and source directories
415 Get_Directories (Project, In_Tree, Data);
417 -- Get the programming languages
419 Check_Programming_Languages (In_Tree, Data);
421 -- Library attributes
423 Check_Library_Attributes (Project, In_Tree, Data);
425 Check_If_Externally_Built (Project, In_Tree, Data);
427 if Current_Verbosity = High then
428 Show_Source_Dirs (Project, In_Tree);
429 end if;
431 Check_Package_Naming (Project, In_Tree, Data);
433 Extending := Data.Extends /= No_Project;
435 Check_Naming_Scheme (Data, Project, In_Tree);
437 Prepare_Ada_Naming_Exceptions
438 (Data.Naming.Bodies, In_Tree, Body_Part);
439 Prepare_Ada_Naming_Exceptions
440 (Data.Naming.Specs, In_Tree, Specification);
442 -- Find the sources
444 if Data.Source_Dirs /= Nil_String then
445 Look_For_Sources (Project, In_Tree, Data, Follow_Links);
446 end if;
448 if Data.Ada_Sources_Present then
450 -- Check that all individual naming conventions apply to sources of
451 -- this project file.
453 Warn_If_Not_Sources
454 (Project, In_Tree, Data.Naming.Bodies,
455 Specs => False,
456 Extending => Extending);
457 Warn_If_Not_Sources
458 (Project, In_Tree, Data.Naming.Specs,
459 Specs => True,
460 Extending => Extending);
461 end if;
463 -- If it is a library project file, check if it is a standalone library
465 if Data.Library then
466 Check_Stand_Alone_Library (Project, In_Tree, Data, Extending);
467 end if;
469 -- Put the list of Mains, if any, in the project data
471 Get_Mains (Project, In_Tree, Data);
473 -- Update the project data in the Projects table
475 In_Tree.Projects.Table (Project) := Data;
477 Free_Ada_Naming_Exceptions;
478 end Check;
480 --------------------
481 -- Check_Ada_Name --
482 --------------------
484 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
485 The_Name : String := Name;
486 Real_Name : Name_Id;
487 Need_Letter : Boolean := True;
488 Last_Underscore : Boolean := False;
489 OK : Boolean := The_Name'Length > 0;
491 begin
492 To_Lower (The_Name);
494 Name_Len := The_Name'Length;
495 Name_Buffer (1 .. Name_Len) := The_Name;
496 Real_Name := Name_Find;
498 -- Check first that the given name is not an Ada reserved word
500 if Get_Name_Table_Byte (Real_Name) /= 0
501 and then Real_Name /= Name_Project
502 and then Real_Name /= Name_Extends
503 and then Real_Name /= Name_External
504 then
505 Unit := No_Name;
507 if Current_Verbosity = High then
508 Write_Str (The_Name);
509 Write_Line (" is an Ada reserved word.");
510 end if;
512 return;
513 end if;
515 for Index in The_Name'Range loop
516 if Need_Letter then
518 -- We need a letter (at the beginning, and following a dot),
519 -- but we don't have one.
521 if Is_Letter (The_Name (Index)) then
522 Need_Letter := False;
524 else
525 OK := False;
527 if Current_Verbosity = High then
528 Write_Int (Types.Int (Index));
529 Write_Str (": '");
530 Write_Char (The_Name (Index));
531 Write_Line ("' is not a letter.");
532 end if;
534 exit;
535 end if;
537 elsif Last_Underscore
538 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
539 then
540 -- Two underscores are illegal, and a dot cannot follow
541 -- an underscore.
543 OK := False;
545 if Current_Verbosity = High then
546 Write_Int (Types.Int (Index));
547 Write_Str (": '");
548 Write_Char (The_Name (Index));
549 Write_Line ("' is illegal here.");
550 end if;
552 exit;
554 elsif The_Name (Index) = '.' then
556 -- We need a letter after a dot
558 Need_Letter := True;
560 elsif The_Name (Index) = '_' then
561 Last_Underscore := True;
563 else
564 -- We need an letter or a digit
566 Last_Underscore := False;
568 if not Is_Alphanumeric (The_Name (Index)) then
569 OK := False;
571 if Current_Verbosity = High then
572 Write_Int (Types.Int (Index));
573 Write_Str (": '");
574 Write_Char (The_Name (Index));
575 Write_Line ("' is not alphanumeric.");
576 end if;
578 exit;
579 end if;
580 end if;
581 end loop;
583 -- Cannot end with an underscore or a dot
585 OK := OK and then not Need_Letter and then not Last_Underscore;
587 if OK then
588 Unit := Real_Name;
590 else
591 -- Signal a problem with No_Name
593 Unit := No_Name;
594 end if;
595 end Check_Ada_Name;
597 --------------------------------------
598 -- Check_Ada_Naming_Scheme_Validity --
599 --------------------------------------
601 procedure Check_Ada_Naming_Scheme_Validity
602 (Project : Project_Id;
603 In_Tree : Project_Tree_Ref;
604 Naming : Naming_Data)
606 begin
607 -- Only check if we are not using the Default naming scheme
609 if Naming /= In_Tree.Private_Part.Default_Naming then
610 declare
611 Dot_Replacement : constant String :=
612 Get_Name_String
613 (Naming.Dot_Replacement);
615 Spec_Suffix : constant String :=
616 Get_Name_String
617 (Naming.Ada_Spec_Suffix);
619 Body_Suffix : constant String :=
620 Get_Name_String
621 (Naming.Ada_Body_Suffix);
623 Separate_Suffix : constant String :=
624 Get_Name_String
625 (Naming.Separate_Suffix);
627 begin
628 -- Dot_Replacement cannot
629 -- - be empty
630 -- - start or end with an alphanumeric
631 -- - be a single '_'
632 -- - start with an '_' followed by an alphanumeric
633 -- - contain a '.' except if it is "."
635 if Dot_Replacement'Length = 0
636 or else Is_Alphanumeric
637 (Dot_Replacement (Dot_Replacement'First))
638 or else Is_Alphanumeric
639 (Dot_Replacement (Dot_Replacement'Last))
640 or else (Dot_Replacement (Dot_Replacement'First) = '_'
641 and then
642 (Dot_Replacement'Length = 1
643 or else
644 Is_Alphanumeric
645 (Dot_Replacement (Dot_Replacement'First + 1))))
646 or else (Dot_Replacement'Length > 1
647 and then
648 Index (Source => Dot_Replacement,
649 Pattern => ".") /= 0)
650 then
651 Error_Msg
652 (Project, In_Tree,
653 '"' & Dot_Replacement &
654 """ is illegal for Dot_Replacement.",
655 Naming.Dot_Repl_Loc);
656 end if;
658 -- Suffixes cannot
659 -- - be empty
661 if Is_Illegal_Suffix
662 (Spec_Suffix, Dot_Replacement = ".")
663 then
664 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Spec_Suffix;
665 Error_Msg
666 (Project, In_Tree,
667 "{ is illegal for Spec_Suffix",
668 Naming.Spec_Suffix_Loc);
669 end if;
671 if Is_Illegal_Suffix
672 (Body_Suffix, Dot_Replacement = ".")
673 then
674 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Body_Suffix;
675 Error_Msg
676 (Project, In_Tree,
677 "{ is illegal for Body_Suffix",
678 Naming.Body_Suffix_Loc);
679 end if;
681 if Body_Suffix /= Separate_Suffix then
682 if Is_Illegal_Suffix
683 (Separate_Suffix, Dot_Replacement = ".")
684 then
685 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
686 Error_Msg
687 (Project, In_Tree,
688 "{ is illegal for Separate_Suffix",
689 Naming.Sep_Suffix_Loc);
690 end if;
691 end if;
693 -- Spec_Suffix cannot have the same termination as
694 -- Body_Suffix or Separate_Suffix
696 if Spec_Suffix'Length <= Body_Suffix'Length
697 and then
698 Body_Suffix (Body_Suffix'Last -
699 Spec_Suffix'Length + 1 ..
700 Body_Suffix'Last) = Spec_Suffix
701 then
702 Error_Msg
703 (Project, In_Tree,
704 "Body_Suffix (""" &
705 Body_Suffix &
706 """) cannot end with" &
707 " Spec_Suffix (""" &
708 Spec_Suffix & """).",
709 Naming.Body_Suffix_Loc);
710 end if;
712 if Body_Suffix /= Separate_Suffix
713 and then Spec_Suffix'Length <= Separate_Suffix'Length
714 and then
715 Separate_Suffix
716 (Separate_Suffix'Last - Spec_Suffix'Length + 1
718 Separate_Suffix'Last) = Spec_Suffix
719 then
720 Error_Msg
721 (Project, In_Tree,
722 "Separate_Suffix (""" &
723 Separate_Suffix &
724 """) cannot end with" &
725 " Spec_Suffix (""" &
726 Spec_Suffix & """).",
727 Naming.Sep_Suffix_Loc);
728 end if;
729 end;
730 end if;
731 end Check_Ada_Naming_Scheme_Validity;
733 ----------------------
734 -- Check_For_Source --
735 ----------------------
737 procedure Check_For_Source
738 (File_Name : Name_Id;
739 Path_Name : Name_Id;
740 Project : Project_Id;
741 In_Tree : Project_Tree_Ref;
742 Data : in out Project_Data;
743 Location : Source_Ptr;
744 Language : Language_Index;
745 Suffix : String;
746 Naming_Exception : Boolean)
748 Name : String := Get_Name_String (File_Name);
749 Real_Location : Source_Ptr := Location;
751 begin
752 Canonical_Case_File_Name (Name);
754 -- A file is a source of a language if Naming_Exception is True (case
755 -- of naming exceptions) or if its file name ends with the suffix.
757 if Naming_Exception or else
758 (Name'Length > Suffix'Length and then
759 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
760 then
761 if Real_Location = No_Location then
762 Real_Location := Data.Location;
763 end if;
765 declare
766 Path : String := Get_Name_String (Path_Name);
768 Path_Id : Name_Id;
769 -- The path name id (in canonical case)
771 File_Id : Name_Id;
772 -- The file name id (in canonical case)
774 Obj_Id : Name_Id;
775 -- The object file name
777 Obj_Path_Id : Name_Id;
778 -- The object path name
780 Dep_Id : Name_Id;
781 -- The dependency file name
783 Dep_Path_Id : Name_Id;
784 -- The dependency path name
786 Dot_Pos : Natural := 0;
787 -- Position of the last dot in Name
789 Source : Other_Source;
790 Source_Id : Other_Source_Id := Data.First_Other_Source;
792 begin
793 Canonical_Case_File_Name (Path);
795 -- Get the file name id
797 Name_Len := Name'Length;
798 Name_Buffer (1 .. Name_Len) := Name;
799 File_Id := Name_Find;
801 -- Get the path name id
803 Name_Len := Path'Length;
804 Name_Buffer (1 .. Name_Len) := Path;
805 Path_Id := Name_Find;
807 -- Find the position of the last dot
809 for J in reverse Name'Range loop
810 if Name (J) = '.' then
811 Dot_Pos := J;
812 exit;
813 end if;
814 end loop;
816 if Dot_Pos <= Name'First then
817 Dot_Pos := Name'Last + 1;
818 end if;
820 -- Compute the object file name
822 Get_Name_String (File_Id);
823 Name_Len := Dot_Pos - Name'First;
825 for J in Object_Suffix'Range loop
826 Name_Len := Name_Len + 1;
827 Name_Buffer (Name_Len) := Object_Suffix (J);
828 end loop;
830 Obj_Id := Name_Find;
832 -- Compute the object path name
834 Get_Name_String (Data.Object_Directory);
836 if Name_Buffer (Name_Len) /= Directory_Separator and then
837 Name_Buffer (Name_Len) /= '/'
838 then
839 Name_Len := Name_Len + 1;
840 Name_Buffer (Name_Len) := Directory_Separator;
841 end if;
843 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
844 Obj_Path_Id := Name_Find;
846 -- Compute the dependency file name
848 Get_Name_String (File_Id);
849 Name_Len := Dot_Pos - Name'First + 1;
850 Name_Buffer (Name_Len) := '.';
851 Name_Len := Name_Len + 1;
852 Name_Buffer (Name_Len) := 'd';
853 Dep_Id := Name_Find;
855 -- Compute the dependency path name
857 Get_Name_String (Data.Object_Directory);
859 if Name_Buffer (Name_Len) /= Directory_Separator and then
860 Name_Buffer (Name_Len) /= '/'
861 then
862 Name_Len := Name_Len + 1;
863 Name_Buffer (Name_Len) := Directory_Separator;
864 end if;
866 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
867 Dep_Path_Id := Name_Find;
869 -- Check if source is already in the list of source for this
870 -- project: it may have already been specified as a naming
871 -- exception for the same language or an other language, or
872 -- they may be two identical file names in different source
873 -- directories.
875 while Source_Id /= No_Other_Source loop
876 Source := In_Tree.Other_Sources.Table (Source_Id);
878 if Source.File_Name = File_Id then
880 -- Two sources of different languages cannot have the same
881 -- file name.
883 if Source.Language /= Language then
884 Error_Msg_Name_1 := File_Name;
885 Error_Msg
886 (Project, In_Tree,
887 "{ cannot be a source of several languages",
888 Real_Location);
889 return;
891 -- No problem if a file has already been specified as
892 -- a naming exception of this language.
894 elsif Source.Path_Name = Path_Id then
896 -- Reset the naming exception flag, if this is not a
897 -- naming exception.
899 if not Naming_Exception then
900 In_Tree.Other_Sources.Table
901 (Source_Id).Naming_Exception := False;
902 end if;
904 return;
906 -- There are several files with the same names, but the
907 -- order of the source directories is known (no /**):
908 -- only the first one encountered is kept, the other ones
909 -- are ignored.
911 elsif Data.Known_Order_Of_Source_Dirs then
912 return;
914 -- But it is an error if the order of the source directories
915 -- is not known.
917 else
918 Error_Msg_Name_1 := File_Name;
919 Error_Msg
920 (Project, In_Tree,
921 "{ is found in several source directories",
922 Real_Location);
923 return;
924 end if;
926 -- Two sources with different file names cannot have the same
927 -- object file name.
929 elsif Source.Object_Name = Obj_Id then
930 Error_Msg_Name_1 := File_Id;
931 Error_Msg_Name_2 := Source.File_Name;
932 Error_Msg_Name_3 := Obj_Id;
933 Error_Msg
934 (Project, In_Tree,
935 "{ and { have the same object file {",
936 Real_Location);
937 return;
938 end if;
940 Source_Id := Source.Next;
941 end loop;
943 if Current_Verbosity = High then
944 Write_Str (" found ");
945 Display_Language_Name (Language);
946 Write_Str (" source """);
947 Write_Str (Get_Name_String (File_Name));
948 Write_Line ("""");
949 Write_Str (" object path = ");
950 Write_Line (Get_Name_String (Obj_Path_Id));
951 end if;
953 -- Create the Other_Source record
955 Source :=
956 (Language => Language,
957 File_Name => File_Id,
958 Path_Name => Path_Id,
959 Source_TS => File_Stamp (Path_Id),
960 Object_Name => Obj_Id,
961 Object_Path => Obj_Path_Id,
962 Object_TS => File_Stamp (Obj_Path_Id),
963 Dep_Name => Dep_Id,
964 Dep_Path => Dep_Path_Id,
965 Dep_TS => File_Stamp (Dep_Path_Id),
966 Naming_Exception => Naming_Exception,
967 Next => No_Other_Source);
969 -- And add it to the Other_Sources table
971 Other_Source_Table.Increment_Last
972 (In_Tree.Other_Sources);
973 In_Tree.Other_Sources.Table
974 (Other_Source_Table.Last (In_Tree.Other_Sources)) :=
975 Source;
977 -- There are sources of languages other than Ada in this project
979 Data.Other_Sources_Present := True;
981 -- And there are sources of this language in this project
983 Set (Language, True, Data, In_Tree);
985 -- Add this source to the list of sources of languages other than
986 -- Ada of the project.
988 if Data.First_Other_Source = No_Other_Source then
989 Data.First_Other_Source :=
990 Other_Source_Table.Last (In_Tree.Other_Sources);
992 else
993 In_Tree.Other_Sources.Table (Data.Last_Other_Source).Next :=
994 Other_Source_Table.Last (In_Tree.Other_Sources);
995 end if;
997 Data.Last_Other_Source :=
998 Other_Source_Table.Last (In_Tree.Other_Sources);
999 end;
1000 end if;
1001 end Check_For_Source;
1003 -------------------------------
1004 -- Check_If_Externally_Built --
1005 -------------------------------
1007 procedure Check_If_Externally_Built
1008 (Project : Project_Id;
1009 In_Tree : Project_Tree_Ref;
1010 Data : in out Project_Data)
1012 Externally_Built : constant Variable_Value :=
1013 Util.Value_Of
1014 (Name_Externally_Built,
1015 Data.Decl.Attributes, In_Tree);
1017 begin
1018 if not Externally_Built.Default then
1019 Get_Name_String (Externally_Built.Value);
1020 To_Lower (Name_Buffer (1 .. Name_Len));
1022 if Name_Buffer (1 .. Name_Len) = "true" then
1023 Data.Externally_Built := True;
1025 elsif Name_Buffer (1 .. Name_Len) /= "false" then
1026 Error_Msg (Project, In_Tree,
1027 "Externally_Built may only be true or false",
1028 Externally_Built.Location);
1029 end if;
1030 end if;
1032 if Current_Verbosity = High then
1033 Write_Str ("Project is ");
1035 if not Data.Externally_Built then
1036 Write_Str ("not ");
1037 end if;
1039 Write_Line ("externally built.");
1040 end if;
1041 end Check_If_Externally_Built;
1043 -----------------------------
1044 -- Check_Naming_Scheme --
1045 -----------------------------
1047 procedure Check_Naming_Scheme
1048 (Data : in out Project_Data;
1049 Project : Project_Id;
1050 In_Tree : Project_Tree_Ref)
1052 Naming_Id : constant Package_Id :=
1053 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
1055 Naming : Package_Element;
1057 procedure Check_Unit_Names (List : Array_Element_Id);
1058 -- Check that a list of unit names contains only valid names
1060 ----------------------
1061 -- Check_Unit_Names --
1062 ----------------------
1064 procedure Check_Unit_Names (List : Array_Element_Id) is
1065 Current : Array_Element_Id := List;
1066 Element : Array_Element;
1067 Unit_Name : Name_Id;
1069 begin
1070 -- Loop through elements of the string list
1072 while Current /= No_Array_Element loop
1073 Element := In_Tree.Array_Elements.Table (Current);
1075 -- Put file name in canonical case
1077 Get_Name_String (Element.Value.Value);
1078 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1079 Element.Value.Value := Name_Find;
1081 -- Check that it contains a valid unit name
1083 Get_Name_String (Element.Index);
1084 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1086 if Unit_Name = No_Name then
1087 Err_Vars.Error_Msg_Name_1 := Element.Index;
1088 Error_Msg
1089 (Project, In_Tree,
1090 "{ is not a valid unit name.",
1091 Element.Value.Location);
1093 else
1094 if Current_Verbosity = High then
1095 Write_Str (" Unit (""");
1096 Write_Str (Get_Name_String (Unit_Name));
1097 Write_Line (""")");
1098 end if;
1100 Element.Index := Unit_Name;
1101 In_Tree.Array_Elements.Table (Current) := Element;
1102 end if;
1104 Current := Element.Next;
1105 end loop;
1106 end Check_Unit_Names;
1108 -- Start of processing for Check_Naming_Scheme
1110 begin
1111 -- If there is a package Naming, we will put in Data.Naming what is in
1112 -- this package Naming.
1114 if Naming_Id /= No_Package then
1115 Naming := In_Tree.Packages.Table (Naming_Id);
1117 if Current_Verbosity = High then
1118 Write_Line ("Checking ""Naming"" for Ada.");
1119 end if;
1121 declare
1122 Bodies : constant Array_Element_Id :=
1123 Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
1125 Specs : constant Array_Element_Id :=
1126 Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
1128 begin
1129 if Bodies /= No_Array_Element then
1131 -- We have elements in the array Body_Part
1133 if Current_Verbosity = High then
1134 Write_Line ("Found Bodies.");
1135 end if;
1137 Data.Naming.Bodies := Bodies;
1138 Check_Unit_Names (Bodies);
1140 else
1141 if Current_Verbosity = High then
1142 Write_Line ("No Bodies.");
1143 end if;
1144 end if;
1146 if Specs /= No_Array_Element then
1148 -- We have elements in the array Specs
1150 if Current_Verbosity = High then
1151 Write_Line ("Found Specs.");
1152 end if;
1154 Data.Naming.Specs := Specs;
1155 Check_Unit_Names (Specs);
1157 else
1158 if Current_Verbosity = High then
1159 Write_Line ("No Specs.");
1160 end if;
1161 end if;
1162 end;
1164 -- We are now checking if variables Dot_Replacement, Casing,
1165 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1166 -- exist.
1168 -- For each variable, if it does not exist, we do nothing,
1169 -- because we already have the default.
1171 -- Check Dot_Replacement
1173 declare
1174 Dot_Replacement : constant Variable_Value :=
1175 Util.Value_Of
1176 (Name_Dot_Replacement,
1177 Naming.Decl.Attributes, In_Tree);
1179 begin
1180 pragma Assert (Dot_Replacement.Kind = Single,
1181 "Dot_Replacement is not a single string");
1183 if not Dot_Replacement.Default then
1184 Get_Name_String (Dot_Replacement.Value);
1186 if Name_Len = 0 then
1187 Error_Msg
1188 (Project, In_Tree,
1189 "Dot_Replacement cannot be empty",
1190 Dot_Replacement.Location);
1192 else
1193 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1194 Data.Naming.Dot_Replacement := Name_Find;
1195 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
1196 end if;
1197 end if;
1198 end;
1200 if Current_Verbosity = High then
1201 Write_Str (" Dot_Replacement = """);
1202 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
1203 Write_Char ('"');
1204 Write_Eol;
1205 end if;
1207 -- Check Casing
1209 declare
1210 Casing_String : constant Variable_Value :=
1211 Util.Value_Of
1212 (Name_Casing, Naming.Decl.Attributes, In_Tree);
1214 begin
1215 pragma Assert (Casing_String.Kind = Single,
1216 "Casing is not a single string");
1218 if not Casing_String.Default then
1219 declare
1220 Casing_Image : constant String :=
1221 Get_Name_String (Casing_String.Value);
1222 begin
1223 declare
1224 Casing_Value : constant Casing_Type :=
1225 Value (Casing_Image);
1226 begin
1227 Data.Naming.Casing := Casing_Value;
1228 end;
1230 exception
1231 when Constraint_Error =>
1232 if Casing_Image'Length = 0 then
1233 Error_Msg
1234 (Project, In_Tree,
1235 "Casing cannot be an empty string",
1236 Casing_String.Location);
1238 else
1239 Name_Len := Casing_Image'Length;
1240 Name_Buffer (1 .. Name_Len) := Casing_Image;
1241 Err_Vars.Error_Msg_Name_1 := Name_Find;
1242 Error_Msg
1243 (Project, In_Tree,
1244 "{ is not a correct Casing",
1245 Casing_String.Location);
1246 end if;
1247 end;
1248 end if;
1249 end;
1251 if Current_Verbosity = High then
1252 Write_Str (" Casing = ");
1253 Write_Str (Image (Data.Naming.Casing));
1254 Write_Char ('.');
1255 Write_Eol;
1256 end if;
1258 -- Check Spec_Suffix
1260 declare
1261 Ada_Spec_Suffix : constant Variable_Value :=
1262 Prj.Util.Value_Of
1263 (Index => Name_Ada,
1264 Src_Index => 0,
1265 In_Array => Data.Naming.Spec_Suffix,
1266 In_Tree => In_Tree);
1268 begin
1269 if Ada_Spec_Suffix.Kind = Single
1270 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
1271 then
1272 Get_Name_String (Ada_Spec_Suffix.Value);
1273 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1274 Data.Naming.Ada_Spec_Suffix := Name_Find;
1275 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
1277 else
1278 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1279 end if;
1280 end;
1282 if Current_Verbosity = High then
1283 Write_Str (" Spec_Suffix = """);
1284 Write_Str (Get_Name_String (Data.Naming.Ada_Spec_Suffix));
1285 Write_Char ('"');
1286 Write_Eol;
1287 end if;
1289 -- Check Body_Suffix
1291 declare
1292 Ada_Body_Suffix : constant Variable_Value :=
1293 Prj.Util.Value_Of
1294 (Index => Name_Ada,
1295 Src_Index => 0,
1296 In_Array => Data.Naming.Body_Suffix,
1297 In_Tree => In_Tree);
1299 begin
1300 if Ada_Body_Suffix.Kind = Single
1301 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
1302 then
1303 Get_Name_String (Ada_Body_Suffix.Value);
1304 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1305 Data.Naming.Ada_Body_Suffix := Name_Find;
1306 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
1308 else
1309 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1310 end if;
1311 end;
1313 if Current_Verbosity = High then
1314 Write_Str (" Body_Suffix = """);
1315 Write_Str (Get_Name_String (Data.Naming.Ada_Body_Suffix));
1316 Write_Char ('"');
1317 Write_Eol;
1318 end if;
1320 -- Check Separate_Suffix
1322 declare
1323 Ada_Sep_Suffix : constant Variable_Value :=
1324 Prj.Util.Value_Of
1325 (Variable_Name => Name_Separate_Suffix,
1326 In_Variables => Naming.Decl.Attributes,
1327 In_Tree => In_Tree);
1329 begin
1330 if Ada_Sep_Suffix.Default then
1331 Data.Naming.Separate_Suffix :=
1332 Data.Naming.Ada_Body_Suffix;
1334 else
1335 Get_Name_String (Ada_Sep_Suffix.Value);
1337 if Name_Len = 0 then
1338 Error_Msg
1339 (Project, In_Tree,
1340 "Separate_Suffix cannot be empty",
1341 Ada_Sep_Suffix.Location);
1343 else
1344 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1345 Data.Naming.Separate_Suffix := Name_Find;
1346 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
1347 end if;
1348 end if;
1349 end;
1351 if Current_Verbosity = High then
1352 Write_Str (" Separate_Suffix = """);
1353 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
1354 Write_Char ('"');
1355 Write_Eol;
1356 end if;
1358 -- Check if Data.Naming is valid
1360 Check_Ada_Naming_Scheme_Validity (Project, In_Tree, Data.Naming);
1362 else
1363 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1364 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1365 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
1366 end if;
1367 end Check_Naming_Scheme;
1369 ------------------------------
1370 -- Check_Library_Attributes --
1371 ------------------------------
1373 procedure Check_Library_Attributes
1374 (Project : Project_Id;
1375 In_Tree : Project_Tree_Ref;
1376 Data : in out Project_Data)
1378 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
1380 Lib_Dir : constant Prj.Variable_Value :=
1381 Prj.Util.Value_Of
1382 (Snames.Name_Library_Dir, Attributes, In_Tree);
1384 Lib_Name : constant Prj.Variable_Value :=
1385 Prj.Util.Value_Of
1386 (Snames.Name_Library_Name, Attributes, In_Tree);
1388 Lib_Version : constant Prj.Variable_Value :=
1389 Prj.Util.Value_Of
1390 (Snames.Name_Library_Version, Attributes, In_Tree);
1392 The_Lib_Kind : constant Prj.Variable_Value :=
1393 Prj.Util.Value_Of
1394 (Snames.Name_Library_Kind, Attributes, In_Tree);
1396 begin
1397 -- Special case of extending project
1399 if Data.Extends /= No_Project then
1400 declare
1401 Extended_Data : constant Project_Data :=
1402 In_Tree.Projects.Table (Data.Extends);
1404 begin
1405 -- If the project extended is a library project, we inherit
1406 -- the library name, if it is not redefined; we check that
1407 -- the library directory is specified; and we reset the
1408 -- library flag for the extended project.
1410 if Extended_Data.Library then
1411 if Lib_Name.Default then
1412 Data.Library_Name := Extended_Data.Library_Name;
1413 end if;
1415 if Lib_Dir.Default then
1416 if not Data.Virtual then
1417 Error_Msg
1418 (Project, In_Tree,
1419 "a project extending a library project must " &
1420 "specify an attribute Library_Dir",
1421 Data.Location);
1422 end if;
1423 end if;
1425 In_Tree.Projects.Table (Data.Extends).Library :=
1426 False;
1427 end if;
1428 end;
1429 end if;
1431 pragma Assert (Lib_Dir.Kind = Single);
1433 if Lib_Dir.Value = Empty_String then
1434 if Current_Verbosity = High then
1435 Write_Line ("No library directory");
1436 end if;
1438 else
1439 -- Find path name, check that it is a directory
1441 Locate_Directory
1442 (Lib_Dir.Value, Data.Display_Directory,
1443 Data.Library_Dir, Data.Display_Library_Dir);
1445 if Data.Library_Dir = No_Name then
1447 -- Get the absolute name of the library directory that
1448 -- does not exist, to report an error.
1450 declare
1451 Dir_Name : constant String := Get_Name_String (Lib_Dir.Value);
1453 begin
1454 if Is_Absolute_Path (Dir_Name) then
1455 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
1457 else
1458 Get_Name_String (Data.Display_Directory);
1460 if Name_Buffer (Name_Len) /= Directory_Separator then
1461 Name_Len := Name_Len + 1;
1462 Name_Buffer (Name_Len) := Directory_Separator;
1463 end if;
1465 Name_Buffer
1466 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
1467 Dir_Name;
1468 Name_Len := Name_Len + Dir_Name'Length;
1469 Err_Vars.Error_Msg_Name_1 := Name_Find;
1470 end if;
1472 -- Report the error
1474 Error_Msg
1475 (Project, In_Tree,
1476 "library directory { does not exist",
1477 Lib_Dir.Location);
1478 end;
1480 -- The library directory cannot be the same as the Object directory
1482 elsif Data.Library_Dir = Data.Object_Directory then
1483 Error_Msg
1484 (Project, In_Tree,
1485 "library directory cannot be the same " &
1486 "as object directory",
1487 Lib_Dir.Location);
1488 Data.Library_Dir := No_Name;
1489 Data.Display_Library_Dir := No_Name;
1491 -- Display the Library directory in high verbosity
1493 else
1494 if Current_Verbosity = High then
1495 Write_Str ("Library directory =""");
1496 Write_Str (Get_Name_String (Data.Display_Library_Dir));
1497 Write_Line ("""");
1498 end if;
1499 end if;
1500 end if;
1502 pragma Assert (Lib_Name.Kind = Single);
1504 if Lib_Name.Value = Empty_String then
1505 if Current_Verbosity = High
1506 and then Data.Library_Name = No_Name
1507 then
1508 Write_Line ("No library name");
1509 end if;
1511 else
1512 -- There is no restriction on the syntax of library names
1514 Data.Library_Name := Lib_Name.Value;
1515 end if;
1517 if Data.Library_Name /= No_Name
1518 and then Current_Verbosity = High
1519 then
1520 Write_Str ("Library name = """);
1521 Write_Str (Get_Name_String (Data.Library_Name));
1522 Write_Line ("""");
1523 end if;
1525 Data.Library :=
1526 Data.Library_Dir /= No_Name
1527 and then
1528 Data.Library_Name /= No_Name;
1530 if Data.Library then
1531 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
1532 Error_Msg
1533 (Project, In_Tree,
1534 "?libraries are not supported on this platform",
1535 Lib_Name.Location);
1536 Data.Library := False;
1538 else
1539 pragma Assert (Lib_Version.Kind = Single);
1541 if Lib_Version.Value = Empty_String then
1542 if Current_Verbosity = High then
1543 Write_Line ("No library version specified");
1544 end if;
1546 else
1547 Data.Lib_Internal_Name := Lib_Version.Value;
1548 end if;
1550 pragma Assert (The_Lib_Kind.Kind = Single);
1552 if The_Lib_Kind.Value = Empty_String then
1553 if Current_Verbosity = High then
1554 Write_Line ("No library kind specified");
1555 end if;
1557 else
1558 Get_Name_String (The_Lib_Kind.Value);
1560 declare
1561 Kind_Name : constant String :=
1562 To_Lower (Name_Buffer (1 .. Name_Len));
1564 OK : Boolean := True;
1566 begin
1567 if Kind_Name = "static" then
1568 Data.Library_Kind := Static;
1570 elsif Kind_Name = "dynamic" then
1571 Data.Library_Kind := Dynamic;
1573 elsif Kind_Name = "relocatable" then
1574 Data.Library_Kind := Relocatable;
1576 else
1577 Error_Msg
1578 (Project, In_Tree,
1579 "illegal value for Library_Kind",
1580 The_Lib_Kind.Location);
1581 OK := False;
1582 end if;
1584 if Current_Verbosity = High and then OK then
1585 Write_Str ("Library kind = ");
1586 Write_Line (Kind_Name);
1587 end if;
1589 if Data.Library_Kind /= Static and then
1590 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
1591 then
1592 Error_Msg
1593 (Project, In_Tree,
1594 "only static libraries are supported " &
1595 "on this platform",
1596 The_Lib_Kind.Location);
1597 Data.Library := False;
1598 end if;
1599 end;
1600 end if;
1602 if Data.Library and then Current_Verbosity = High then
1603 Write_Line ("This is a library project file");
1604 end if;
1606 end if;
1607 end if;
1608 end Check_Library_Attributes;
1610 --------------------------
1611 -- Check_Package_Naming --
1612 --------------------------
1614 procedure Check_Package_Naming
1615 (Project : Project_Id;
1616 In_Tree : Project_Tree_Ref;
1617 Data : in out Project_Data)
1619 Naming_Id : constant Package_Id :=
1620 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
1622 Naming : Package_Element;
1624 begin
1625 -- If there is a package Naming, we will put in Data.Naming
1626 -- what is in this package Naming.
1628 if Naming_Id /= No_Package then
1629 Naming := In_Tree.Packages.Table (Naming_Id);
1631 if Current_Verbosity = High then
1632 Write_Line ("Checking ""Naming"".");
1633 end if;
1635 -- Check Spec_Suffix
1637 declare
1638 Spec_Suffixs : Array_Element_Id :=
1639 Util.Value_Of
1640 (Name_Spec_Suffix,
1641 Naming.Decl.Arrays,
1642 In_Tree);
1644 Suffix : Array_Element_Id;
1645 Element : Array_Element;
1646 Suffix2 : Array_Element_Id;
1648 begin
1649 -- If some suffixs have been specified, we make sure that
1650 -- for each language for which a default suffix has been
1651 -- specified, there is a suffix specified, either the one
1652 -- in the project file or if there were none, the default.
1654 if Spec_Suffixs /= No_Array_Element then
1655 Suffix := Data.Naming.Spec_Suffix;
1657 while Suffix /= No_Array_Element loop
1658 Element :=
1659 In_Tree.Array_Elements.Table (Suffix);
1660 Suffix2 := Spec_Suffixs;
1662 while Suffix2 /= No_Array_Element loop
1663 exit when In_Tree.Array_Elements.Table
1664 (Suffix2).Index = Element.Index;
1665 Suffix2 := In_Tree.Array_Elements.Table
1666 (Suffix2).Next;
1667 end loop;
1669 -- There is a registered default suffix, but no
1670 -- suffix specified in the project file.
1671 -- Add the default to the array.
1673 if Suffix2 = No_Array_Element then
1674 Array_Element_Table.Increment_Last
1675 (In_Tree.Array_Elements);
1676 In_Tree.Array_Elements.Table
1677 (Array_Element_Table.Last
1678 (In_Tree.Array_Elements)) :=
1679 (Index => Element.Index,
1680 Src_Index => Element.Src_Index,
1681 Index_Case_Sensitive => False,
1682 Value => Element.Value,
1683 Next => Spec_Suffixs);
1684 Spec_Suffixs := Array_Element_Table.Last
1685 (In_Tree.Array_Elements);
1686 end if;
1688 Suffix := Element.Next;
1689 end loop;
1691 -- Put the resulting array as the specification suffixs
1693 Data.Naming.Spec_Suffix := Spec_Suffixs;
1694 end if;
1695 end;
1697 declare
1698 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
1699 Element : Array_Element;
1701 begin
1702 while Current /= No_Array_Element loop
1703 Element := In_Tree.Array_Elements.Table (Current);
1704 Get_Name_String (Element.Value.Value);
1706 if Name_Len = 0 then
1707 Error_Msg
1708 (Project, In_Tree,
1709 "Spec_Suffix cannot be empty",
1710 Element.Value.Location);
1711 end if;
1713 In_Tree.Array_Elements.Table (Current) := Element;
1714 Current := Element.Next;
1715 end loop;
1716 end;
1718 -- Check Body_Suffix
1720 declare
1721 Impl_Suffixs : Array_Element_Id :=
1722 Util.Value_Of
1723 (Name_Body_Suffix,
1724 Naming.Decl.Arrays,
1725 In_Tree);
1727 Suffix : Array_Element_Id;
1728 Element : Array_Element;
1729 Suffix2 : Array_Element_Id;
1731 begin
1732 -- If some suffixes have been specified, we make sure that
1733 -- for each language for which a default suffix has been
1734 -- specified, there is a suffix specified, either the one
1735 -- in the project file or if there were noe, the default.
1737 if Impl_Suffixs /= No_Array_Element then
1738 Suffix := Data.Naming.Body_Suffix;
1740 while Suffix /= No_Array_Element loop
1741 Element :=
1742 In_Tree.Array_Elements.Table (Suffix);
1743 Suffix2 := Impl_Suffixs;
1745 while Suffix2 /= No_Array_Element loop
1746 exit when In_Tree.Array_Elements.Table
1747 (Suffix2).Index = Element.Index;
1748 Suffix2 := In_Tree.Array_Elements.Table
1749 (Suffix2).Next;
1750 end loop;
1752 -- There is a registered default suffix, but no suffix was
1753 -- specified in the project file. Add the default to the
1754 -- array.
1756 if Suffix2 = No_Array_Element then
1757 Array_Element_Table.Increment_Last
1758 (In_Tree.Array_Elements);
1759 In_Tree.Array_Elements.Table
1760 (Array_Element_Table.Last
1761 (In_Tree.Array_Elements)) :=
1762 (Index => Element.Index,
1763 Src_Index => Element.Src_Index,
1764 Index_Case_Sensitive => False,
1765 Value => Element.Value,
1766 Next => Impl_Suffixs);
1767 Impl_Suffixs := Array_Element_Table.Last
1768 (In_Tree.Array_Elements);
1769 end if;
1771 Suffix := Element.Next;
1772 end loop;
1774 -- Put the resulting array as the implementation suffixs
1776 Data.Naming.Body_Suffix := Impl_Suffixs;
1777 end if;
1778 end;
1780 declare
1781 Current : Array_Element_Id := Data.Naming.Body_Suffix;
1782 Element : Array_Element;
1784 begin
1785 while Current /= No_Array_Element loop
1786 Element := In_Tree.Array_Elements.Table (Current);
1787 Get_Name_String (Element.Value.Value);
1789 if Name_Len = 0 then
1790 Error_Msg
1791 (Project, In_Tree,
1792 "Body_Suffix cannot be empty",
1793 Element.Value.Location);
1794 end if;
1796 In_Tree.Array_Elements.Table (Current) := Element;
1797 Current := Element.Next;
1798 end loop;
1799 end;
1801 -- Get the exceptions, if any
1803 Data.Naming.Specification_Exceptions :=
1804 Util.Value_Of
1805 (Name_Specification_Exceptions,
1806 In_Arrays => Naming.Decl.Arrays,
1807 In_Tree => In_Tree);
1809 Data.Naming.Implementation_Exceptions :=
1810 Util.Value_Of
1811 (Name_Implementation_Exceptions,
1812 In_Arrays => Naming.Decl.Arrays,
1813 In_Tree => In_Tree);
1814 end if;
1815 end Check_Package_Naming;
1817 ---------------------------------
1818 -- Check_Programming_Languages --
1819 ---------------------------------
1821 procedure Check_Programming_Languages
1822 (In_Tree : Project_Tree_Ref;
1823 Data : in out Project_Data)
1825 Languages : Variable_Value := Nil_Variable_Value;
1827 begin
1828 Languages :=
1829 Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes, In_Tree);
1830 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
1831 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
1833 if Data.Source_Dirs /= Nil_String then
1835 -- Check if languages are specified in this project
1837 if Languages.Default then
1839 -- Attribute Languages is not specified. So, it defaults to
1840 -- a project of language Ada only.
1842 Data.Languages (Ada_Language_Index) := True;
1844 -- No sources of languages other than Ada
1846 Data.Other_Sources_Present := False;
1848 else
1849 declare
1850 Current : String_List_Id := Languages.Values;
1851 Element : String_Element;
1852 Lang_Name : Name_Id;
1853 Index : Language_Index;
1855 begin
1856 -- Assume that there is no language specified yet
1858 Data.Other_Sources_Present := False;
1859 Data.Ada_Sources_Present := False;
1861 -- Look through all the languages specified in attribute
1862 -- Languages, if any
1864 while Current /= Nil_String loop
1865 Element :=
1866 In_Tree.String_Elements.Table (Current);
1867 Get_Name_String (Element.Value);
1868 To_Lower (Name_Buffer (1 .. Name_Len));
1869 Lang_Name := Name_Find;
1870 Index := Language_Indexes.Get (Lang_Name);
1872 if Index = No_Language_Index then
1873 Add_Language_Name (Lang_Name);
1874 Index := Last_Language_Index;
1875 end if;
1877 Set (Index, True, Data, In_Tree);
1878 Set (Language_Processing => Default_Language_Processing_Data,
1879 For_Language => Index,
1880 In_Project => Data,
1881 In_Tree => In_Tree);
1883 if Index = Ada_Language_Index then
1884 Data.Ada_Sources_Present := True;
1886 else
1887 Data.Other_Sources_Present := True;
1888 end if;
1890 Current := Element.Next;
1891 end loop;
1892 end;
1893 end if;
1894 end if;
1895 end Check_Programming_Languages;
1897 -------------------
1898 -- Check_Project --
1899 -------------------
1901 function Check_Project
1902 (P : Project_Id;
1903 Root_Project : Project_Id;
1904 In_Tree : Project_Tree_Ref;
1905 Extending : Boolean) return Boolean
1907 begin
1908 if P = Root_Project then
1909 return True;
1911 elsif Extending then
1912 declare
1913 Data : Project_Data := In_Tree.Projects.Table (Root_Project);
1915 begin
1916 while Data.Extends /= No_Project loop
1917 if P = Data.Extends then
1918 return True;
1919 end if;
1921 Data := In_Tree.Projects.Table (Data.Extends);
1922 end loop;
1923 end;
1924 end if;
1926 return False;
1927 end Check_Project;
1929 -------------------------------
1930 -- Check_Stand_Alone_Library --
1931 -------------------------------
1933 procedure Check_Stand_Alone_Library
1934 (Project : Project_Id;
1935 In_Tree : Project_Tree_Ref;
1936 Data : in out Project_Data;
1937 Extending : Boolean)
1939 Lib_Interfaces : constant Prj.Variable_Value :=
1940 Prj.Util.Value_Of
1941 (Snames.Name_Library_Interface,
1942 Data.Decl.Attributes,
1943 In_Tree);
1945 Lib_Auto_Init : constant Prj.Variable_Value :=
1946 Prj.Util.Value_Of
1947 (Snames.Name_Library_Auto_Init,
1948 Data.Decl.Attributes,
1949 In_Tree);
1951 Lib_Src_Dir : constant Prj.Variable_Value :=
1952 Prj.Util.Value_Of
1953 (Snames.Name_Library_Src_Dir,
1954 Data.Decl.Attributes,
1955 In_Tree);
1957 Lib_Symbol_File : constant Prj.Variable_Value :=
1958 Prj.Util.Value_Of
1959 (Snames.Name_Library_Symbol_File,
1960 Data.Decl.Attributes,
1961 In_Tree);
1963 Lib_Symbol_Policy : constant Prj.Variable_Value :=
1964 Prj.Util.Value_Of
1965 (Snames.Name_Library_Symbol_Policy,
1966 Data.Decl.Attributes,
1967 In_Tree);
1969 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
1970 Prj.Util.Value_Of
1971 (Snames.Name_Library_Reference_Symbol_File,
1972 Data.Decl.Attributes,
1973 In_Tree);
1975 Auto_Init_Supported : constant Boolean :=
1976 MLib.Tgt.
1977 Standalone_Library_Auto_Init_Is_Supported;
1979 OK : Boolean := True;
1981 begin
1982 pragma Assert (Lib_Interfaces.Kind = List);
1984 -- It is a stand-alone library project file if attribute
1985 -- Library_Interface is defined.
1987 if not Lib_Interfaces.Default then
1988 SAL_Library : declare
1989 Interfaces : String_List_Id := Lib_Interfaces.Values;
1990 Interface_ALIs : String_List_Id := Nil_String;
1991 Unit : Name_Id;
1992 The_Unit_Id : Unit_Id;
1993 The_Unit_Data : Unit_Data;
1995 procedure Add_ALI_For (Source : Name_Id);
1996 -- Add an ALI file name to the list of Interface ALIs
1998 -----------------
1999 -- Add_ALI_For --
2000 -----------------
2002 procedure Add_ALI_For (Source : Name_Id) is
2003 begin
2004 Get_Name_String (Source);
2006 declare
2007 ALI : constant String :=
2008 ALI_File_Name (Name_Buffer (1 .. Name_Len));
2009 ALI_Name_Id : Name_Id;
2010 begin
2011 Name_Len := ALI'Length;
2012 Name_Buffer (1 .. Name_Len) := ALI;
2013 ALI_Name_Id := Name_Find;
2015 String_Element_Table.Increment_Last
2016 (In_Tree.String_Elements);
2017 In_Tree.String_Elements.Table
2018 (String_Element_Table.Last
2019 (In_Tree.String_Elements)) :=
2020 (Value => ALI_Name_Id,
2021 Index => 0,
2022 Display_Value => ALI_Name_Id,
2023 Location =>
2024 In_Tree.String_Elements.Table
2025 (Interfaces).Location,
2026 Flag => False,
2027 Next => Interface_ALIs);
2028 Interface_ALIs := String_Element_Table.Last
2029 (In_Tree.String_Elements);
2030 end;
2031 end Add_ALI_For;
2033 -- Start of processing for SAL_Library
2035 begin
2036 Data.Standalone_Library := True;
2038 -- Library_Interface cannot be an empty list
2040 if Interfaces = Nil_String then
2041 Error_Msg
2042 (Project, In_Tree,
2043 "Library_Interface cannot be an empty list",
2044 Lib_Interfaces.Location);
2045 end if;
2047 -- Process each unit name specified in the attribute
2048 -- Library_Interface.
2050 while Interfaces /= Nil_String loop
2051 Get_Name_String
2052 (In_Tree.String_Elements.Table
2053 (Interfaces).Value);
2054 To_Lower (Name_Buffer (1 .. Name_Len));
2056 if Name_Len = 0 then
2057 Error_Msg
2058 (Project, In_Tree,
2059 "an interface cannot be an empty string",
2060 In_Tree.String_Elements.Table
2061 (Interfaces).Location);
2063 else
2064 Unit := Name_Find;
2065 Error_Msg_Name_1 := Unit;
2066 The_Unit_Id :=
2067 Units_Htable.Get (In_Tree.Units_HT, Unit);
2069 if The_Unit_Id = No_Unit then
2070 Error_Msg
2071 (Project, In_Tree,
2072 "unknown unit {",
2073 In_Tree.String_Elements.Table
2074 (Interfaces).Location);
2076 else
2077 -- Check that the unit is part of the project
2079 The_Unit_Data :=
2080 In_Tree.Units.Table (The_Unit_Id);
2082 if The_Unit_Data.File_Names (Body_Part).Name /= No_Name
2083 and then The_Unit_Data.File_Names (Body_Part).Path /=
2084 Slash
2085 then
2086 if Check_Project
2087 (The_Unit_Data.File_Names (Body_Part).Project,
2088 Project, In_Tree, Extending)
2089 then
2090 -- There is a body for this unit.
2091 -- If there is no spec, we need to check
2092 -- that it is not a subunit.
2094 if The_Unit_Data.File_Names
2095 (Specification).Name = No_Name
2096 then
2097 declare
2098 Src_Ind : Source_File_Index;
2100 begin
2101 Src_Ind := Sinput.P.Load_Project_File
2102 (Get_Name_String
2103 (The_Unit_Data.File_Names
2104 (Body_Part).Path));
2106 if Sinput.P.Source_File_Is_Subunit
2107 (Src_Ind)
2108 then
2109 Error_Msg
2110 (Project, In_Tree,
2111 "{ is a subunit; " &
2112 "it cannot be an interface",
2113 In_Tree.
2114 String_Elements.Table
2115 (Interfaces).Location);
2116 end if;
2117 end;
2118 end if;
2120 -- The unit is not a subunit, so we add
2121 -- to the Interface ALIs the ALI file
2122 -- corresponding to the body.
2124 Add_ALI_For
2125 (The_Unit_Data.File_Names (Body_Part).Name);
2127 else
2128 Error_Msg
2129 (Project, In_Tree,
2130 "{ is not an unit of this project",
2131 In_Tree.String_Elements.Table
2132 (Interfaces).Location);
2133 end if;
2135 elsif The_Unit_Data.File_Names
2136 (Specification).Name /= No_Name
2137 and then The_Unit_Data.File_Names
2138 (Specification).Path /= Slash
2139 and then Check_Project
2140 (The_Unit_Data.File_Names
2141 (Specification).Project,
2142 Project, In_Tree, Extending)
2144 then
2145 -- The unit is part of the project, it has
2146 -- a spec, but no body. We add to the Interface
2147 -- ALIs the ALI file corresponding to the spec.
2149 Add_ALI_For
2150 (The_Unit_Data.File_Names (Specification).Name);
2152 else
2153 Error_Msg
2154 (Project, In_Tree,
2155 "{ is not an unit of this project",
2156 In_Tree.String_Elements.Table
2157 (Interfaces).Location);
2158 end if;
2159 end if;
2161 end if;
2163 Interfaces :=
2164 In_Tree.String_Elements.Table (Interfaces).Next;
2165 end loop;
2167 -- Put the list of Interface ALIs in the project data
2169 Data.Lib_Interface_ALIs := Interface_ALIs;
2171 -- Check value of attribute Library_Auto_Init and set
2172 -- Lib_Auto_Init accordingly.
2174 if Lib_Auto_Init.Default then
2176 -- If no attribute Library_Auto_Init is declared, then
2177 -- set auto init only if it is supported.
2179 Data.Lib_Auto_Init := Auto_Init_Supported;
2181 else
2182 Get_Name_String (Lib_Auto_Init.Value);
2183 To_Lower (Name_Buffer (1 .. Name_Len));
2185 if Name_Buffer (1 .. Name_Len) = "false" then
2186 Data.Lib_Auto_Init := False;
2188 elsif Name_Buffer (1 .. Name_Len) = "true" then
2189 if Auto_Init_Supported then
2190 Data.Lib_Auto_Init := True;
2192 else
2193 -- Library_Auto_Init cannot be "true" if auto init
2194 -- is not supported
2196 Error_Msg
2197 (Project, In_Tree,
2198 "library auto init not supported " &
2199 "on this platform",
2200 Lib_Auto_Init.Location);
2201 end if;
2203 else
2204 Error_Msg
2205 (Project, In_Tree,
2206 "invalid value for attribute Library_Auto_Init",
2207 Lib_Auto_Init.Location);
2208 end if;
2209 end if;
2210 end SAL_Library;
2212 -- If attribute Library_Src_Dir is defined and not the
2213 -- empty string, check if the directory exist and is not
2214 -- the object directory or one of the source directories.
2215 -- This is the directory where copies of the interface
2216 -- sources will be copied. Note that this directory may be
2217 -- the library directory.
2219 if Lib_Src_Dir.Value /= Empty_String then
2220 declare
2221 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
2223 begin
2224 Locate_Directory
2225 (Dir_Id, Data.Display_Directory,
2226 Data.Library_Src_Dir,
2227 Data.Display_Library_Src_Dir);
2229 -- If directory does not exist, report an error
2231 if Data.Library_Src_Dir = No_Name then
2233 -- Get the absolute name of the library directory
2234 -- that does not exist, to report an error.
2236 declare
2237 Dir_Name : constant String :=
2238 Get_Name_String (Dir_Id);
2240 begin
2241 if Is_Absolute_Path (Dir_Name) then
2242 Err_Vars.Error_Msg_Name_1 := Dir_Id;
2244 else
2245 Get_Name_String (Data.Directory);
2247 if Name_Buffer (Name_Len) /=
2248 Directory_Separator
2249 then
2250 Name_Len := Name_Len + 1;
2251 Name_Buffer (Name_Len) :=
2252 Directory_Separator;
2253 end if;
2255 Name_Buffer
2256 (Name_Len + 1 ..
2257 Name_Len + Dir_Name'Length) :=
2258 Dir_Name;
2259 Name_Len := Name_Len + Dir_Name'Length;
2260 Err_Vars.Error_Msg_Name_1 := Name_Find;
2261 end if;
2263 -- Report the error
2265 Error_Msg
2266 (Project, In_Tree,
2267 "Directory { does not exist",
2268 Lib_Src_Dir.Location);
2269 end;
2271 -- Report an error if it is the same as the object
2272 -- directory.
2274 elsif Data.Library_Src_Dir = Data.Object_Directory then
2275 Error_Msg
2276 (Project, In_Tree,
2277 "directory to copy interfaces cannot be " &
2278 "the object directory",
2279 Lib_Src_Dir.Location);
2280 Data.Library_Src_Dir := No_Name;
2282 -- Check if it is same as one of the source directories
2284 else
2285 declare
2286 Src_Dirs : String_List_Id := Data.Source_Dirs;
2287 Src_Dir : String_Element;
2289 begin
2290 while Src_Dirs /= Nil_String loop
2291 Src_Dir := In_Tree.String_Elements.Table
2292 (Src_Dirs);
2293 Src_Dirs := Src_Dir.Next;
2295 -- Report error if it is one of the source directories
2297 if Data.Library_Src_Dir = Src_Dir.Value then
2298 Error_Msg
2299 (Project, In_Tree,
2300 "directory to copy interfaces cannot " &
2301 "be one of the source directories",
2302 Lib_Src_Dir.Location);
2303 Data.Library_Src_Dir := No_Name;
2304 exit;
2305 end if;
2306 end loop;
2307 end;
2309 -- In high verbosity, if there is a valid Library_Src_Dir,
2310 -- display its path name.
2312 if Data.Library_Src_Dir /= No_Name
2313 and then Current_Verbosity = High
2314 then
2315 Write_Str ("Directory to copy interfaces =""");
2316 Write_Str (Get_Name_String (Data.Library_Src_Dir));
2317 Write_Line ("""");
2318 end if;
2319 end if;
2320 end;
2321 end if;
2323 -- Check the symbol related attributes
2325 -- First, the symbol policy
2327 if not Lib_Symbol_Policy.Default then
2328 declare
2329 Value : constant String :=
2330 To_Lower
2331 (Get_Name_String (Lib_Symbol_Policy.Value));
2333 begin
2334 -- Symbol policy must hove one of a limited number of values
2336 if Value = "autonomous" or else Value = "default" then
2337 Data.Symbol_Data.Symbol_Policy := Autonomous;
2339 elsif Value = "compliant" then
2340 Data.Symbol_Data.Symbol_Policy := Compliant;
2342 elsif Value = "controlled" then
2343 Data.Symbol_Data.Symbol_Policy := Controlled;
2345 elsif Value = "restricted" then
2346 Data.Symbol_Data.Symbol_Policy := Restricted;
2348 else
2349 Error_Msg
2350 (Project, In_Tree,
2351 "illegal value for Library_Symbol_Policy",
2352 Lib_Symbol_Policy.Location);
2353 end if;
2354 end;
2355 end if;
2357 -- If attribute Library_Symbol_File is not specified, symbol policy
2358 -- cannot be Restricted.
2360 if Lib_Symbol_File.Default then
2361 if Data.Symbol_Data.Symbol_Policy = Restricted then
2362 Error_Msg
2363 (Project, In_Tree,
2364 "Library_Symbol_File needs to be defined when " &
2365 "symbol policy is Restricted",
2366 Lib_Symbol_Policy.Location);
2367 end if;
2369 else
2370 -- Library_Symbol_File is defined. Check that the file exists
2372 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
2374 Get_Name_String (Lib_Symbol_File.Value);
2376 if Name_Len = 0 then
2377 Error_Msg
2378 (Project, In_Tree,
2379 "symbol file name cannot be an empty string",
2380 Lib_Symbol_File.Location);
2382 else
2383 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2385 if OK then
2386 for J in 1 .. Name_Len loop
2387 if Name_Buffer (J) = '/'
2388 or else Name_Buffer (J) = Directory_Separator
2389 then
2390 OK := False;
2391 exit;
2392 end if;
2393 end loop;
2394 end if;
2396 if not OK then
2397 Error_Msg_Name_1 := Lib_Symbol_File.Value;
2398 Error_Msg
2399 (Project, In_Tree,
2400 "symbol file name { is illegal. " &
2401 "Name canot include directory info.",
2402 Lib_Symbol_File.Location);
2403 end if;
2404 end if;
2405 end if;
2407 -- If attribute Library_Reference_Symbol_File is not defined,
2408 -- symbol policy cannot be Compilant or Controlled.
2410 if Lib_Ref_Symbol_File.Default then
2411 if Data.Symbol_Data.Symbol_Policy = Compliant
2412 or else Data.Symbol_Data.Symbol_Policy = Controlled
2413 then
2414 Error_Msg
2415 (Project, In_Tree,
2416 "a reference symbol file need to be defined",
2417 Lib_Symbol_Policy.Location);
2418 end if;
2420 else
2421 -- Library_Reference_Symbol_File is defined, check file exists
2423 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
2425 Get_Name_String (Lib_Ref_Symbol_File.Value);
2427 if Name_Len = 0 then
2428 Error_Msg
2429 (Project, In_Tree,
2430 "reference symbol file name cannot be an empty string",
2431 Lib_Symbol_File.Location);
2433 else
2434 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2436 if OK then
2437 for J in 1 .. Name_Len loop
2438 if Name_Buffer (J) = '/'
2439 or else Name_Buffer (J) = Directory_Separator
2440 then
2441 OK := False;
2442 exit;
2443 end if;
2444 end loop;
2445 end if;
2447 if not OK then
2448 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2449 Error_Msg
2450 (Project, In_Tree,
2451 "reference symbol file { name is illegal. " &
2452 "Name canot include directory info.",
2453 Lib_Ref_Symbol_File.Location);
2454 end if;
2456 if not Is_Regular_File
2457 (Get_Name_String (Data.Object_Directory) &
2458 Directory_Separator &
2459 Get_Name_String (Lib_Ref_Symbol_File.Value))
2460 then
2461 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2463 -- For controlled symbol policy, it is an error if the
2464 -- reference symbol file does not exist. For other symbol
2465 -- policies, this is just a warning
2467 Error_Msg_Warn :=
2468 Data.Symbol_Data.Symbol_Policy /= Controlled;
2470 Error_Msg
2471 (Project, In_Tree,
2472 "<library reference symbol file { does not exist",
2473 Lib_Ref_Symbol_File.Location);
2475 -- In addition in the non-controlled case, if symbol policy
2476 -- is Compliant, it is changed to Autonomous, because there
2477 -- is no reference to check against, and we don't want to
2478 -- fail in this case.
2480 if Data.Symbol_Data.Symbol_Policy /= Controlled then
2481 if Data.Symbol_Data.Symbol_Policy = Compliant then
2482 Data.Symbol_Data.Symbol_Policy := Autonomous;
2483 end if;
2484 end if;
2485 end if;
2486 end if;
2487 end if;
2488 end if;
2489 end Check_Stand_Alone_Library;
2491 ----------------------------
2492 -- Compute_Directory_Last --
2493 ----------------------------
2495 function Compute_Directory_Last (Dir : String) return Natural is
2496 begin
2497 if Dir'Length > 1
2498 and then (Dir (Dir'Last - 1) = Directory_Separator
2499 or else Dir (Dir'Last - 1) = '/')
2500 then
2501 return Dir'Last - 1;
2502 else
2503 return Dir'Last;
2504 end if;
2505 end Compute_Directory_Last;
2507 --------------------
2508 -- Body_Suffix_Of --
2509 --------------------
2511 function Body_Suffix_Of
2512 (Language : Language_Index;
2513 In_Project : Project_Data;
2514 In_Tree : Project_Tree_Ref) return String
2516 Suffix_Id : constant Name_Id :=
2517 Suffix_Of (Language, In_Project, In_Tree);
2518 begin
2519 if Suffix_Id /= No_Name then
2520 return Get_Name_String (Suffix_Id);
2521 else
2522 return "." & Get_Name_String (Language_Names.Table (Language));
2523 end if;
2524 end Body_Suffix_Of;
2526 ---------------
2527 -- Error_Msg --
2528 ---------------
2530 procedure Error_Msg
2531 (Project : Project_Id;
2532 In_Tree : Project_Tree_Ref;
2533 Msg : String;
2534 Flag_Location : Source_Ptr)
2536 Error_Buffer : String (1 .. 5_000);
2537 Error_Last : Natural := 0;
2538 Msg_Name : Natural := 0;
2539 First : Positive := Msg'First;
2541 procedure Add (C : Character);
2542 -- Add a character to the buffer
2544 procedure Add (S : String);
2545 -- Add a string to the buffer
2547 procedure Add (Id : Name_Id);
2548 -- Add a name to the buffer
2550 ---------
2551 -- Add --
2552 ---------
2554 procedure Add (C : Character) is
2555 begin
2556 Error_Last := Error_Last + 1;
2557 Error_Buffer (Error_Last) := C;
2558 end Add;
2560 procedure Add (S : String) is
2561 begin
2562 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2563 Error_Last := Error_Last + S'Length;
2564 end Add;
2566 procedure Add (Id : Name_Id) is
2567 begin
2568 Get_Name_String (Id);
2569 Add (Name_Buffer (1 .. Name_Len));
2570 end Add;
2572 -- Start of processing for Error_Msg
2574 begin
2575 if Error_Report = null then
2576 Prj.Err.Error_Msg (Msg, Flag_Location);
2577 return;
2578 end if;
2580 -- Ignore continuation character
2582 if Msg (First) = '\' then
2583 First := First + 1;
2585 -- Warniung character is always the first one in this package
2586 -- this is an undoocumented kludge!!!
2588 elsif Msg (First) = '?' then
2589 First := First + 1;
2590 Add ("Warning: ");
2592 elsif Msg (First) = '<' then
2593 First := First + 1;
2595 if Err_Vars.Error_Msg_Warn then
2596 Add ("Warning: ");
2597 end if;
2598 end if;
2600 for Index in First .. Msg'Last loop
2601 if Msg (Index) = '{' or else Msg (Index) = '%' then
2603 -- Include a name between double quotes
2605 Msg_Name := Msg_Name + 1;
2606 Add ('"');
2608 case Msg_Name is
2609 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2610 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2611 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2613 when others => null;
2614 end case;
2616 Add ('"');
2618 else
2619 Add (Msg (Index));
2620 end if;
2622 end loop;
2624 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
2625 end Error_Msg;
2627 ------------------
2628 -- Find_Sources --
2629 ------------------
2631 procedure Find_Sources
2632 (Project : Project_Id;
2633 In_Tree : Project_Tree_Ref;
2634 Data : in out Project_Data;
2635 For_Language : Language_Index;
2636 Follow_Links : Boolean := False)
2638 Source_Dir : String_List_Id := Data.Source_Dirs;
2639 Element : String_Element;
2640 Dir : Dir_Type;
2641 Current_Source : String_List_Id := Nil_String;
2642 Source_Recorded : Boolean := False;
2644 begin
2645 if Current_Verbosity = High then
2646 Write_Line ("Looking for sources:");
2647 end if;
2649 -- For each subdirectory
2651 while Source_Dir /= Nil_String loop
2652 begin
2653 Source_Recorded := False;
2654 Element := In_Tree.String_Elements.Table (Source_Dir);
2655 if Element.Value /= No_Name then
2656 Get_Name_String (Element.Display_Value);
2658 declare
2659 Source_Directory : constant String :=
2660 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2661 Dir_Last : constant Natural :=
2662 Compute_Directory_Last (Source_Directory);
2664 begin
2665 if Current_Verbosity = High then
2666 Write_Str ("Source_Dir = ");
2667 Write_Line (Source_Directory);
2668 end if;
2670 -- We look to every entry in the source directory
2672 Open (Dir, Source_Directory
2673 (Source_Directory'First .. Dir_Last));
2675 loop
2676 Read (Dir, Name_Buffer, Name_Len);
2678 if Current_Verbosity = High then
2679 Write_Str (" Checking ");
2680 Write_Line (Name_Buffer (1 .. Name_Len));
2681 end if;
2683 exit when Name_Len = 0;
2685 declare
2686 File_Name : constant Name_Id := Name_Find;
2687 Path : constant String :=
2688 Normalize_Pathname
2689 (Name => Name_Buffer (1 .. Name_Len),
2690 Directory => Source_Directory
2691 (Source_Directory'First .. Dir_Last),
2692 Resolve_Links => Follow_Links,
2693 Case_Sensitive => True);
2694 Path_Name : Name_Id;
2696 begin
2697 Name_Len := Path'Length;
2698 Name_Buffer (1 .. Name_Len) := Path;
2699 Path_Name := Name_Find;
2701 if For_Language = Ada_Language_Index then
2703 -- We attempt to register it as a source. However,
2704 -- there is no error if the file does not contain
2705 -- a valid source. But there is an error if we have
2706 -- a duplicate unit name.
2708 Record_Ada_Source
2709 (File_Name => File_Name,
2710 Path_Name => Path_Name,
2711 Project => Project,
2712 In_Tree => In_Tree,
2713 Data => Data,
2714 Location => No_Location,
2715 Current_Source => Current_Source,
2716 Source_Recorded => Source_Recorded,
2717 Follow_Links => Follow_Links);
2719 else
2720 Check_For_Source
2721 (File_Name => File_Name,
2722 Path_Name => Path_Name,
2723 Project => Project,
2724 In_Tree => In_Tree,
2725 Data => Data,
2726 Location => No_Location,
2727 Language => For_Language,
2728 Suffix =>
2729 Body_Suffix_Of (For_Language, Data, In_Tree),
2730 Naming_Exception => False);
2731 end if;
2732 end;
2733 end loop;
2735 Close (Dir);
2736 end;
2737 end if;
2739 exception
2740 when Directory_Error =>
2741 null;
2742 end;
2744 if Source_Recorded then
2745 In_Tree.String_Elements.Table (Source_Dir).Flag :=
2746 True;
2747 end if;
2749 Source_Dir := Element.Next;
2750 end loop;
2752 if Current_Verbosity = High then
2753 Write_Line ("end Looking for sources.");
2754 end if;
2756 if For_Language = Ada_Language_Index then
2758 -- If we have looked for sources and found none, then
2759 -- it is an error, except if it is an extending project.
2760 -- If a non extending project is not supposed to contain
2761 -- any source, then we never call Find_Sources.
2763 if Current_Source /= Nil_String then
2764 Data.Ada_Sources_Present := True;
2766 elsif Data.Extends = No_Project then
2767 Error_Msg
2768 (Project, In_Tree,
2769 "there are no Ada sources in this project",
2770 Data.Location);
2771 end if;
2772 end if;
2773 end Find_Sources;
2775 --------------------------------
2776 -- Free_Ada_Naming_Exceptions --
2777 --------------------------------
2779 procedure Free_Ada_Naming_Exceptions is
2780 begin
2781 Ada_Naming_Exception_Table.Set_Last (0);
2782 Ada_Naming_Exceptions.Reset;
2783 Reverse_Ada_Naming_Exceptions.Reset;
2784 end Free_Ada_Naming_Exceptions;
2786 ---------------------
2787 -- Get_Directories --
2788 ---------------------
2790 procedure Get_Directories
2791 (Project : Project_Id;
2792 In_Tree : Project_Tree_Ref;
2793 Data : in out Project_Data)
2795 Object_Dir : constant Variable_Value :=
2796 Util.Value_Of
2797 (Name_Object_Dir, Data.Decl.Attributes, In_Tree);
2799 Exec_Dir : constant Variable_Value :=
2800 Util.Value_Of
2801 (Name_Exec_Dir, Data.Decl.Attributes, In_Tree);
2803 Source_Dirs : constant Variable_Value :=
2804 Util.Value_Of
2805 (Name_Source_Dirs, Data.Decl.Attributes, In_Tree);
2807 Last_Source_Dir : String_List_Id := Nil_String;
2809 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2810 -- Find one or several source directories, and add them
2811 -- to the list of source directories of the project.
2813 ----------------------
2814 -- Find_Source_Dirs --
2815 ----------------------
2817 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2818 Directory : constant String := Get_Name_String (From);
2819 Element : String_Element;
2821 procedure Recursive_Find_Dirs (Path : Name_Id);
2822 -- Find all the subdirectories (recursively) of Path and add them
2823 -- to the list of source directories of the project.
2825 -------------------------
2826 -- Recursive_Find_Dirs --
2827 -------------------------
2829 procedure Recursive_Find_Dirs (Path : Name_Id) is
2830 Dir : Dir_Type;
2831 Name : String (1 .. 250);
2832 Last : Natural;
2833 List : String_List_Id := Data.Source_Dirs;
2834 Element : String_Element;
2835 Found : Boolean := False;
2837 Non_Canonical_Path : Name_Id := No_Name;
2838 Canonical_Path : Name_Id := No_Name;
2840 The_Path : constant String :=
2841 Normalize_Pathname (Get_Name_String (Path)) &
2842 Directory_Separator;
2844 The_Path_Last : constant Natural :=
2845 Compute_Directory_Last (The_Path);
2847 begin
2848 Name_Len := The_Path_Last - The_Path'First + 1;
2849 Name_Buffer (1 .. Name_Len) :=
2850 The_Path (The_Path'First .. The_Path_Last);
2851 Non_Canonical_Path := Name_Find;
2852 Get_Name_String (Non_Canonical_Path);
2853 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2854 Canonical_Path := Name_Find;
2856 -- To avoid processing the same directory several times, check
2857 -- if the directory is already in Recursive_Dirs. If it is,
2858 -- then there is nothing to do, just return. If it is not, put
2859 -- it there and continue recursive processing.
2861 if Recursive_Dirs.Get (Canonical_Path) then
2862 return;
2864 else
2865 Recursive_Dirs.Set (Canonical_Path, True);
2866 end if;
2868 -- Check if directory is already in list
2870 while List /= Nil_String loop
2871 Element := In_Tree.String_Elements.Table (List);
2873 if Element.Value /= No_Name then
2874 Found := Element.Value = Canonical_Path;
2875 exit when Found;
2876 end if;
2878 List := Element.Next;
2879 end loop;
2881 -- If directory is not already in list, put it there
2883 if not Found then
2884 if Current_Verbosity = High then
2885 Write_Str (" ");
2886 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2887 end if;
2889 String_Element_Table.Increment_Last
2890 (In_Tree.String_Elements);
2891 Element :=
2892 (Value => Canonical_Path,
2893 Display_Value => Non_Canonical_Path,
2894 Location => No_Location,
2895 Flag => False,
2896 Next => Nil_String,
2897 Index => 0);
2899 -- Case of first source directory
2901 if Last_Source_Dir = Nil_String then
2902 Data.Source_Dirs := String_Element_Table.Last
2903 (In_Tree.String_Elements);
2905 -- Here we already have source directories
2907 else
2908 -- Link the previous last to the new one
2910 In_Tree.String_Elements.Table
2911 (Last_Source_Dir).Next :=
2912 String_Element_Table.Last
2913 (In_Tree.String_Elements);
2914 end if;
2916 -- And register this source directory as the new last
2918 Last_Source_Dir := String_Element_Table.Last
2919 (In_Tree.String_Elements);
2920 In_Tree.String_Elements.Table (Last_Source_Dir) :=
2921 Element;
2922 end if;
2924 -- Now look for subdirectories. We do that even when this
2925 -- directory is already in the list, because some of its
2926 -- subdirectories may not be in the list yet.
2928 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2930 loop
2931 Read (Dir, Name, Last);
2932 exit when Last = 0;
2934 if Name (1 .. Last) /= "."
2935 and then Name (1 .. Last) /= ".."
2936 then
2937 -- Avoid . and .. directories
2939 if Current_Verbosity = High then
2940 Write_Str (" Checking ");
2941 Write_Line (Name (1 .. Last));
2942 end if;
2944 declare
2945 Path_Name : constant String :=
2946 Normalize_Pathname
2947 (Name => Name (1 .. Last),
2948 Directory =>
2949 The_Path
2950 (The_Path'First .. The_Path_Last),
2951 Resolve_Links => False,
2952 Case_Sensitive => True);
2954 begin
2955 if Is_Directory (Path_Name) then
2957 -- We have found a new subdirectory, call self
2959 Name_Len := Path_Name'Length;
2960 Name_Buffer (1 .. Name_Len) := Path_Name;
2961 Recursive_Find_Dirs (Name_Find);
2962 end if;
2963 end;
2964 end if;
2965 end loop;
2967 Close (Dir);
2969 exception
2970 when Directory_Error =>
2971 null;
2972 end Recursive_Find_Dirs;
2974 -- Start of processing for Find_Source_Dirs
2976 begin
2977 if Current_Verbosity = High then
2978 Write_Str ("Find_Source_Dirs (""");
2979 Write_Str (Directory);
2980 Write_Line (""")");
2981 end if;
2983 -- First, check if we are looking for a directory tree,
2984 -- indicated by "/**" at the end.
2986 if Directory'Length >= 3
2987 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2988 and then (Directory (Directory'Last - 2) = '/'
2989 or else
2990 Directory (Directory'Last - 2) = Directory_Separator)
2991 then
2992 Data.Known_Order_Of_Source_Dirs := False;
2994 Name_Len := Directory'Length - 3;
2996 if Name_Len = 0 then
2998 -- This is the case of "/**": all directories
2999 -- in the file system.
3001 Name_Len := 1;
3002 Name_Buffer (1) := Directory (Directory'First);
3004 else
3005 Name_Buffer (1 .. Name_Len) :=
3006 Directory (Directory'First .. Directory'Last - 3);
3007 end if;
3009 if Current_Verbosity = High then
3010 Write_Str ("Looking for all subdirectories of """);
3011 Write_Str (Name_Buffer (1 .. Name_Len));
3012 Write_Line ("""");
3013 end if;
3015 declare
3016 Base_Dir : constant Name_Id := Name_Find;
3017 Root_Dir : constant String :=
3018 Normalize_Pathname
3019 (Name => Get_Name_String (Base_Dir),
3020 Directory =>
3021 Get_Name_String (Data.Display_Directory),
3022 Resolve_Links => False,
3023 Case_Sensitive => True);
3025 begin
3026 if Root_Dir'Length = 0 then
3027 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3029 if Location = No_Location then
3030 Error_Msg
3031 (Project, In_Tree,
3032 "{ is not a valid directory.",
3033 Data.Location);
3034 else
3035 Error_Msg
3036 (Project, In_Tree,
3037 "{ is not a valid directory.",
3038 Location);
3039 end if;
3041 else
3042 -- We have an existing directory, we register it and all
3043 -- of its subdirectories.
3045 if Current_Verbosity = High then
3046 Write_Line ("Looking for source directories:");
3047 end if;
3049 Name_Len := Root_Dir'Length;
3050 Name_Buffer (1 .. Name_Len) := Root_Dir;
3051 Recursive_Find_Dirs (Name_Find);
3053 if Current_Verbosity = High then
3054 Write_Line ("End of looking for source directories.");
3055 end if;
3056 end if;
3057 end;
3059 -- We have a single directory
3061 else
3062 declare
3063 Path_Name : Name_Id;
3064 Display_Path_Name : Name_Id;
3066 begin
3067 Locate_Directory
3068 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3070 if Path_Name = No_Name then
3071 Err_Vars.Error_Msg_Name_1 := From;
3073 if Location = No_Location then
3074 Error_Msg
3075 (Project, In_Tree,
3076 "{ is not a valid directory",
3077 Data.Location);
3078 else
3079 Error_Msg
3080 (Project, In_Tree,
3081 "{ is not a valid directory",
3082 Location);
3083 end if;
3085 else
3086 -- As it is an existing directory, we add it to
3087 -- the list of directories.
3089 String_Element_Table.Increment_Last
3090 (In_Tree.String_Elements);
3091 Element.Value := Path_Name;
3092 Element.Display_Value := Display_Path_Name;
3094 if Last_Source_Dir = Nil_String then
3096 -- This is the first source directory
3098 Data.Source_Dirs := String_Element_Table.Last
3099 (In_Tree.String_Elements);
3101 else
3102 -- We already have source directories,
3103 -- link the previous last to the new one.
3105 In_Tree.String_Elements.Table
3106 (Last_Source_Dir).Next :=
3107 String_Element_Table.Last
3108 (In_Tree.String_Elements);
3109 end if;
3111 -- And register this source directory as the new last
3113 Last_Source_Dir := String_Element_Table.Last
3114 (In_Tree.String_Elements);
3115 In_Tree.String_Elements.Table
3116 (Last_Source_Dir) := Element;
3117 end if;
3118 end;
3119 end if;
3120 end Find_Source_Dirs;
3122 -- Start of processing for Get_Directories
3124 begin
3125 if Current_Verbosity = High then
3126 Write_Line ("Starting to look for directories");
3127 end if;
3129 -- Check the object directory
3131 pragma Assert (Object_Dir.Kind = Single,
3132 "Object_Dir is not a single string");
3134 -- We set the object directory to its default
3136 Data.Object_Directory := Data.Directory;
3137 Data.Display_Object_Dir := Data.Display_Directory;
3139 if Object_Dir.Value /= Empty_String then
3140 Get_Name_String (Object_Dir.Value);
3142 if Name_Len = 0 then
3143 Error_Msg
3144 (Project, In_Tree,
3145 "Object_Dir cannot be empty",
3146 Object_Dir.Location);
3148 else
3149 -- We check that the specified object directory does exist
3151 Locate_Directory
3152 (Object_Dir.Value, Data.Display_Directory,
3153 Data.Object_Directory, Data.Display_Object_Dir);
3155 if Data.Object_Directory = No_Name then
3157 -- The object directory does not exist, report an error
3159 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3160 Error_Msg
3161 (Project, In_Tree,
3162 "the object directory { cannot be found",
3163 Data.Location);
3165 -- Do not keep a nil Object_Directory. Set it to the specified
3166 -- (relative or absolute) path. This is for the benefit of
3167 -- tools that recover from errors; for example, these tools
3168 -- could create the non existent directory.
3170 Data.Display_Object_Dir := Object_Dir.Value;
3171 Get_Name_String (Object_Dir.Value);
3172 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3173 Data.Object_Directory := Name_Find;
3174 end if;
3175 end if;
3176 end if;
3178 if Current_Verbosity = High then
3179 if Data.Object_Directory = No_Name then
3180 Write_Line ("No object directory");
3181 else
3182 Write_Str ("Object directory: """);
3183 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3184 Write_Line ("""");
3185 end if;
3186 end if;
3188 -- Check the exec directory
3190 pragma Assert (Exec_Dir.Kind = Single,
3191 "Exec_Dir is not a single string");
3193 -- We set the object directory to its default
3195 Data.Exec_Directory := Data.Object_Directory;
3196 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3198 if Exec_Dir.Value /= Empty_String then
3199 Get_Name_String (Exec_Dir.Value);
3201 if Name_Len = 0 then
3202 Error_Msg
3203 (Project, In_Tree,
3204 "Exec_Dir cannot be empty",
3205 Exec_Dir.Location);
3207 else
3208 -- We check that the specified object directory
3209 -- does exist.
3211 Locate_Directory
3212 (Exec_Dir.Value, Data.Directory,
3213 Data.Exec_Directory, Data.Display_Exec_Dir);
3215 if Data.Exec_Directory = No_Name then
3216 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3217 Error_Msg
3218 (Project, In_Tree,
3219 "the exec directory { cannot be found",
3220 Data.Location);
3221 end if;
3222 end if;
3223 end if;
3225 if Current_Verbosity = High then
3226 if Data.Exec_Directory = No_Name then
3227 Write_Line ("No exec directory");
3228 else
3229 Write_Str ("Exec directory: """);
3230 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3231 Write_Line ("""");
3232 end if;
3233 end if;
3235 -- Look for the source directories
3237 if Current_Verbosity = High then
3238 Write_Line ("Starting to look for source directories");
3239 end if;
3241 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
3243 if Source_Dirs.Default then
3245 -- No Source_Dirs specified: the single source directory
3246 -- is the one containing the project file
3248 String_Element_Table.Increment_Last
3249 (In_Tree.String_Elements);
3250 Data.Source_Dirs := String_Element_Table.Last
3251 (In_Tree.String_Elements);
3252 In_Tree.String_Elements.Table (Data.Source_Dirs) :=
3253 (Value => Data.Directory,
3254 Display_Value => Data.Display_Directory,
3255 Location => No_Location,
3256 Flag => False,
3257 Next => Nil_String,
3258 Index => 0);
3260 if Current_Verbosity = High then
3261 Write_Line ("Single source directory:");
3262 Write_Str (" """);
3263 Write_Str (Get_Name_String (Data.Display_Directory));
3264 Write_Line ("""");
3265 end if;
3267 elsif Source_Dirs.Values = Nil_String then
3269 -- If Source_Dirs is an empty string list, this means
3270 -- that this project contains no source. For projects that
3271 -- don't extend other projects, this also means that there is no
3272 -- need for an object directory, if not specified.
3274 if Data.Extends = No_Project
3275 and then Data.Object_Directory = Data.Directory
3276 then
3277 Data.Object_Directory := No_Name;
3278 end if;
3280 Data.Source_Dirs := Nil_String;
3281 Data.Ada_Sources_Present := False;
3282 Data.Other_Sources_Present := False;
3284 else
3285 declare
3286 Source_Dir : String_List_Id := Source_Dirs.Values;
3287 Element : String_Element;
3289 begin
3290 -- We will find the source directories for each
3291 -- element of the list
3293 while Source_Dir /= Nil_String loop
3294 Element :=
3295 In_Tree.String_Elements.Table (Source_Dir);
3296 Find_Source_Dirs (Element.Value, Element.Location);
3297 Source_Dir := Element.Next;
3298 end loop;
3299 end;
3300 end if;
3302 if Current_Verbosity = High then
3303 Write_Line ("Putting source directories in canonical cases");
3304 end if;
3306 declare
3307 Current : String_List_Id := Data.Source_Dirs;
3308 Element : String_Element;
3310 begin
3311 while Current /= Nil_String loop
3312 Element := In_Tree.String_Elements.Table (Current);
3313 if Element.Value /= No_Name then
3314 Get_Name_String (Element.Value);
3315 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3316 Element.Value := Name_Find;
3317 In_Tree.String_Elements.Table (Current) := Element;
3318 end if;
3320 Current := Element.Next;
3321 end loop;
3322 end;
3324 end Get_Directories;
3326 ---------------
3327 -- Get_Mains --
3328 ---------------
3330 procedure Get_Mains
3331 (Project : Project_Id;
3332 In_Tree : Project_Tree_Ref;
3333 Data : in out Project_Data) is
3334 Mains : constant Variable_Value :=
3335 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes, In_Tree);
3337 begin
3338 Data.Mains := Mains.Values;
3340 -- If no Mains were specified, and if we are an extending
3341 -- project, inherit the Mains from the project we are extending.
3343 if Mains.Default then
3344 if Data.Extends /= No_Project then
3345 Data.Mains :=
3346 In_Tree.Projects.Table (Data.Extends).Mains;
3347 end if;
3349 -- In a library project file, Main cannot be specified
3351 elsif Data.Library then
3352 Error_Msg
3353 (Project, In_Tree,
3354 "a library project file cannot have Main specified",
3355 Mains.Location);
3356 end if;
3357 end Get_Mains;
3359 ---------------------------
3360 -- Get_Sources_From_File --
3361 ---------------------------
3363 procedure Get_Sources_From_File
3364 (Path : String;
3365 Location : Source_Ptr;
3366 Project : Project_Id;
3367 In_Tree : Project_Tree_Ref)
3369 File : Prj.Util.Text_File;
3370 Line : String (1 .. 250);
3371 Last : Natural;
3372 Source_Name : Name_Id;
3374 begin
3375 Source_Names.Reset;
3377 if Current_Verbosity = High then
3378 Write_Str ("Opening """);
3379 Write_Str (Path);
3380 Write_Line (""".");
3381 end if;
3383 -- Open the file
3385 Prj.Util.Open (File, Path);
3387 if not Prj.Util.Is_Valid (File) then
3388 Error_Msg (Project, In_Tree, "file does not exist", Location);
3389 else
3390 -- Read the lines one by one
3392 while not Prj.Util.End_Of_File (File) loop
3393 Prj.Util.Get_Line (File, Line, Last);
3395 -- A non empty, non comment line should contain a file name
3397 if Last /= 0
3398 and then (Last = 1 or else Line (1 .. 2) /= "--")
3399 then
3400 -- ??? we should check that there is no directory information
3402 Name_Len := Last;
3403 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
3404 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3405 Source_Name := Name_Find;
3406 Source_Names.Set
3407 (K => Source_Name,
3408 E =>
3409 (Name => Source_Name,
3410 Location => Location,
3411 Found => False));
3412 end if;
3413 end loop;
3415 Prj.Util.Close (File);
3417 end if;
3418 end Get_Sources_From_File;
3420 --------------
3421 -- Get_Unit --
3422 --------------
3424 procedure Get_Unit
3425 (Canonical_File_Name : Name_Id;
3426 Naming : Naming_Data;
3427 Exception_Id : out Ada_Naming_Exception_Id;
3428 Unit_Name : out Name_Id;
3429 Unit_Kind : out Spec_Or_Body;
3430 Needs_Pragma : out Boolean)
3432 Info_Id : Ada_Naming_Exception_Id
3433 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
3434 VMS_Name : Name_Id;
3436 begin
3437 if Info_Id = No_Ada_Naming_Exception then
3438 if Hostparm.OpenVMS then
3439 VMS_Name := Canonical_File_Name;
3440 Get_Name_String (VMS_Name);
3442 if Name_Buffer (Name_Len) = '.' then
3443 Name_Len := Name_Len - 1;
3444 VMS_Name := Name_Find;
3445 end if;
3447 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
3448 end if;
3450 end if;
3452 if Info_Id /= No_Ada_Naming_Exception then
3453 Exception_Id := Info_Id;
3454 Unit_Name := No_Name;
3455 Unit_Kind := Specification;
3456 Needs_Pragma := True;
3457 return;
3458 end if;
3460 Needs_Pragma := False;
3461 Exception_Id := No_Ada_Naming_Exception;
3463 Get_Name_String (Canonical_File_Name);
3465 declare
3466 File : String := Name_Buffer (1 .. Name_Len);
3467 First : constant Positive := File'First;
3468 Last : Natural := File'Last;
3469 Standard_GNAT : Boolean;
3471 begin
3472 Standard_GNAT :=
3473 Naming.Ada_Spec_Suffix = Default_Ada_Spec_Suffix
3474 and then Naming.Ada_Body_Suffix = Default_Ada_Body_Suffix;
3476 -- Check if the end of the file name is Specification_Append
3478 Get_Name_String (Naming.Ada_Spec_Suffix);
3480 if File'Length > Name_Len
3481 and then File (Last - Name_Len + 1 .. Last) =
3482 Name_Buffer (1 .. Name_Len)
3483 then
3484 -- We have a spec
3486 Unit_Kind := Specification;
3487 Last := Last - Name_Len;
3489 if Current_Verbosity = High then
3490 Write_Str (" Specification: ");
3491 Write_Line (File (First .. Last));
3492 end if;
3494 else
3495 Get_Name_String (Naming.Ada_Body_Suffix);
3497 -- Check if the end of the file name is Body_Append
3499 if File'Length > Name_Len
3500 and then File (Last - Name_Len + 1 .. Last) =
3501 Name_Buffer (1 .. Name_Len)
3502 then
3503 -- We have a body
3505 Unit_Kind := Body_Part;
3506 Last := Last - Name_Len;
3508 if Current_Verbosity = High then
3509 Write_Str (" Body: ");
3510 Write_Line (File (First .. Last));
3511 end if;
3513 elsif Naming.Separate_Suffix /= Naming.Ada_Spec_Suffix then
3514 Get_Name_String (Naming.Separate_Suffix);
3516 -- Check if the end of the file name is Separate_Append
3518 if File'Length > Name_Len
3519 and then File (Last - Name_Len + 1 .. Last) =
3520 Name_Buffer (1 .. Name_Len)
3521 then
3522 -- We have a separate (a body)
3524 Unit_Kind := Body_Part;
3525 Last := Last - Name_Len;
3527 if Current_Verbosity = High then
3528 Write_Str (" Separate: ");
3529 Write_Line (File (First .. Last));
3530 end if;
3532 else
3533 Last := 0;
3534 end if;
3536 else
3537 Last := 0;
3538 end if;
3539 end if;
3541 if Last = 0 then
3543 -- This is not a source file
3545 Unit_Name := No_Name;
3546 Unit_Kind := Specification;
3548 if Current_Verbosity = High then
3549 Write_Line (" Not a valid file name.");
3550 end if;
3552 return;
3553 end if;
3555 Get_Name_String (Naming.Dot_Replacement);
3556 Standard_GNAT :=
3557 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
3559 if Name_Buffer (1 .. Name_Len) /= "." then
3561 -- If Dot_Replacement is not a single dot, then there should
3562 -- not be any dot in the name.
3564 for Index in First .. Last loop
3565 if File (Index) = '.' then
3566 if Current_Verbosity = High then
3567 Write_Line
3568 (" Not a valid file name (some dot not replaced).");
3569 end if;
3571 Unit_Name := No_Name;
3572 return;
3574 end if;
3575 end loop;
3577 -- Replace the substring Dot_Replacement with dots
3579 declare
3580 Index : Positive := First;
3582 begin
3583 while Index <= Last - Name_Len + 1 loop
3585 if File (Index .. Index + Name_Len - 1) =
3586 Name_Buffer (1 .. Name_Len)
3587 then
3588 File (Index) := '.';
3590 if Name_Len > 1 and then Index < Last then
3591 File (Index + 1 .. Last - Name_Len + 1) :=
3592 File (Index + Name_Len .. Last);
3593 end if;
3595 Last := Last - Name_Len + 1;
3596 end if;
3598 Index := Index + 1;
3599 end loop;
3600 end;
3601 end if;
3603 -- Check if the casing is right
3605 declare
3606 Src : String := File (First .. Last);
3608 begin
3609 case Naming.Casing is
3610 when All_Lower_Case =>
3611 Fixed.Translate
3612 (Source => Src,
3613 Mapping => Lower_Case_Map);
3615 when All_Upper_Case =>
3616 Fixed.Translate
3617 (Source => Src,
3618 Mapping => Upper_Case_Map);
3620 when Mixed_Case | Unknown =>
3621 null;
3622 end case;
3624 if Src /= File (First .. Last) then
3625 if Current_Verbosity = High then
3626 Write_Line (" Not a valid file name (casing).");
3627 end if;
3629 Unit_Name := No_Name;
3630 return;
3631 end if;
3633 -- We put the name in lower case
3635 Fixed.Translate
3636 (Source => Src,
3637 Mapping => Lower_Case_Map);
3639 -- In the standard GNAT naming scheme, check for special cases:
3640 -- children or separates of A, G, I or S, and run time sources.
3642 if Standard_GNAT and then Src'Length >= 3 then
3643 declare
3644 S1 : constant Character := Src (Src'First);
3645 S2 : constant Character := Src (Src'First + 1);
3647 begin
3648 if S1 = 'a' or else S1 = 'g'
3649 or else S1 = 'i' or else S1 = 's'
3650 then
3651 -- Children or separates of packages A, G, I or S
3653 if (Hostparm.OpenVMS and then S2 = '$')
3654 or else (not Hostparm.OpenVMS and then S2 = '~')
3655 then
3656 Src (Src'First + 1) := '.';
3658 -- If it is potentially a run time source, disable
3659 -- filling of the mapping file to avoid warnings.
3661 elsif S2 = '.' then
3662 Set_Mapping_File_Initial_State_To_Empty;
3663 end if;
3665 end if;
3666 end;
3667 end if;
3669 if Current_Verbosity = High then
3670 Write_Str (" ");
3671 Write_Line (Src);
3672 end if;
3674 -- Now, we check if this name is a valid unit name
3676 Check_Ada_Name (Name => Src, Unit => Unit_Name);
3677 end;
3679 end;
3680 end Get_Unit;
3682 ----------
3683 -- Hash --
3684 ----------
3686 function Hash (Unit : Unit_Info) return Header_Num is
3687 begin
3688 return Header_Num (Unit.Unit mod 2048);
3689 end Hash;
3691 -----------------------
3692 -- Is_Illegal_Suffix --
3693 -----------------------
3695 function Is_Illegal_Suffix
3696 (Suffix : String;
3697 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
3699 begin
3700 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
3701 return True;
3702 end if;
3704 -- If dot replacement is a single dot, and first character of
3705 -- suffix is also a dot
3707 if Dot_Replacement_Is_A_Single_Dot
3708 and then Suffix (Suffix'First) = '.'
3709 then
3710 for Index in Suffix'First + 1 .. Suffix'Last loop
3712 -- If there is another dot
3714 if Suffix (Index) = '.' then
3716 -- It is illegal to have a letter following the initial dot
3718 return Is_Letter (Suffix (Suffix'First + 1));
3719 end if;
3720 end loop;
3721 end if;
3723 -- Everything is OK
3725 return False;
3726 end Is_Illegal_Suffix;
3728 ----------------------
3729 -- Locate_Directory --
3730 ----------------------
3732 procedure Locate_Directory
3733 (Name : Name_Id;
3734 Parent : Name_Id;
3735 Dir : out Name_Id;
3736 Display : out Name_Id)
3738 The_Name : constant String := Get_Name_String (Name);
3740 The_Parent : constant String :=
3741 Get_Name_String (Parent) & Directory_Separator;
3743 The_Parent_Last : constant Natural :=
3744 Compute_Directory_Last (The_Parent);
3746 begin
3747 if Current_Verbosity = High then
3748 Write_Str ("Locate_Directory (""");
3749 Write_Str (The_Name);
3750 Write_Str (""", """);
3751 Write_Str (The_Parent);
3752 Write_Line (""")");
3753 end if;
3755 Dir := No_Name;
3756 Display := No_Name;
3758 if Is_Absolute_Path (The_Name) then
3759 if Is_Directory (The_Name) then
3760 declare
3761 Normed : constant String :=
3762 Normalize_Pathname
3763 (The_Name,
3764 Resolve_Links => False,
3765 Case_Sensitive => True);
3767 Canonical_Path : constant String :=
3768 Normalize_Pathname
3769 (Normed,
3770 Resolve_Links => True,
3771 Case_Sensitive => False);
3773 begin
3774 Name_Len := Normed'Length;
3775 Name_Buffer (1 .. Name_Len) := Normed;
3776 Display := Name_Find;
3778 Name_Len := Canonical_Path'Length;
3779 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3780 Dir := Name_Find;
3781 end;
3782 end if;
3784 else
3785 declare
3786 Full_Path : constant String :=
3787 The_Parent (The_Parent'First .. The_Parent_Last) &
3788 The_Name;
3790 begin
3791 if Is_Directory (Full_Path) then
3792 declare
3793 Normed : constant String :=
3794 Normalize_Pathname
3795 (Full_Path,
3796 Resolve_Links => False,
3797 Case_Sensitive => True);
3799 Canonical_Path : constant String :=
3800 Normalize_Pathname
3801 (Normed,
3802 Resolve_Links => True,
3803 Case_Sensitive => False);
3805 begin
3806 Name_Len := Normed'Length;
3807 Name_Buffer (1 .. Name_Len) := Normed;
3808 Display := Name_Find;
3810 Name_Len := Canonical_Path'Length;
3811 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3812 Dir := Name_Find;
3813 end;
3814 end if;
3815 end;
3816 end if;
3817 end Locate_Directory;
3819 ----------------------
3820 -- Look_For_Sources --
3821 ----------------------
3823 procedure Look_For_Sources
3824 (Project : Project_Id;
3825 In_Tree : Project_Tree_Ref;
3826 Data : in out Project_Data;
3827 Follow_Links : Boolean)
3829 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean);
3830 -- Find the path names of the source files in the Source_Names table
3831 -- in the source directories and record those that are Ada sources.
3833 procedure Get_Sources_From_File
3834 (Path : String;
3835 Location : Source_Ptr);
3836 -- Get the sources of a project from a text file
3838 ---------------------------------------
3839 -- Get_Path_Names_And_Record_Sources --
3840 ---------------------------------------
3842 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean) is
3843 Source_Dir : String_List_Id := Data.Source_Dirs;
3844 Element : String_Element;
3845 Path : Name_Id;
3847 Dir : Dir_Type;
3848 Name : Name_Id;
3849 Canonical_Name : Name_Id;
3850 Name_Str : String (1 .. 1_024);
3851 Last : Natural := 0;
3852 NL : Name_Location;
3854 Current_Source : String_List_Id := Nil_String;
3856 First_Error : Boolean := True;
3858 Source_Recorded : Boolean := False;
3860 begin
3861 -- We look in all source directories for the file names in the
3862 -- hash table Source_Names
3864 while Source_Dir /= Nil_String loop
3865 Source_Recorded := False;
3866 Element := In_Tree.String_Elements.Table (Source_Dir);
3868 declare
3869 Dir_Path : constant String := Get_Name_String (Element.Value);
3870 begin
3871 if Current_Verbosity = High then
3872 Write_Str ("checking directory """);
3873 Write_Str (Dir_Path);
3874 Write_Line ("""");
3875 end if;
3877 Open (Dir, Dir_Path);
3879 loop
3880 Read (Dir, Name_Str, Last);
3881 exit when Last = 0;
3882 Name_Len := Last;
3883 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3884 Name := Name_Find;
3885 Canonical_Case_File_Name (Name_Str (1 .. Last));
3886 Name_Len := Last;
3887 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3888 Canonical_Name := Name_Find;
3889 NL := Source_Names.Get (Canonical_Name);
3891 if NL /= No_Name_Location and then not NL.Found then
3892 NL.Found := True;
3893 Source_Names.Set (Canonical_Name, NL);
3894 Name_Len := Dir_Path'Length;
3895 Name_Buffer (1 .. Name_Len) := Dir_Path;
3897 if Name_Buffer (Name_Len) /= Directory_Separator then
3898 Add_Char_To_Name_Buffer (Directory_Separator);
3899 end if;
3901 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
3902 Path := Name_Find;
3904 if Current_Verbosity = High then
3905 Write_Str (" found ");
3906 Write_Line (Get_Name_String (Name));
3907 end if;
3909 -- Register the source if it is an Ada compilation unit
3911 Record_Ada_Source
3912 (File_Name => Name,
3913 Path_Name => Path,
3914 Project => Project,
3915 In_Tree => In_Tree,
3916 Data => Data,
3917 Location => NL.Location,
3918 Current_Source => Current_Source,
3919 Source_Recorded => Source_Recorded,
3920 Follow_Links => Follow_Links);
3921 end if;
3922 end loop;
3924 Close (Dir);
3925 end;
3927 if Source_Recorded then
3928 In_Tree.String_Elements.Table (Source_Dir).Flag :=
3929 True;
3930 end if;
3932 Source_Dir := Element.Next;
3933 end loop;
3935 -- It is an error if a source file name in a source list or
3936 -- in a source list file is not found.
3938 NL := Source_Names.Get_First;
3940 while NL /= No_Name_Location loop
3941 if not NL.Found then
3942 Err_Vars.Error_Msg_Name_1 := NL.Name;
3944 if First_Error then
3945 Error_Msg
3946 (Project, In_Tree,
3947 "source file { cannot be found",
3948 NL.Location);
3949 First_Error := False;
3951 else
3952 Error_Msg
3953 (Project, In_Tree,
3954 "\source file { cannot be found",
3955 NL.Location);
3956 end if;
3957 end if;
3959 NL := Source_Names.Get_Next;
3960 end loop;
3961 end Get_Path_Names_And_Record_Sources;
3963 ---------------------------
3964 -- Get_Sources_From_File --
3965 ---------------------------
3967 procedure Get_Sources_From_File
3968 (Path : String;
3969 Location : Source_Ptr)
3971 begin
3972 -- Get the list of sources from the file and put them in hash table
3973 -- Source_Names.
3975 Get_Sources_From_File (Path, Location, Project, In_Tree);
3977 -- Look in the source directories to find those sources
3979 Get_Path_Names_And_Record_Sources (Follow_Links);
3981 -- We should have found at least one source.
3982 -- If not, report an error.
3984 if Data.Sources = Nil_String then
3985 Error_Msg (Project, In_Tree,
3986 "there are no Ada sources in this project",
3987 Location);
3988 end if;
3989 end Get_Sources_From_File;
3991 begin
3992 if Data.Ada_Sources_Present then
3993 declare
3994 Sources : constant Variable_Value :=
3995 Util.Value_Of
3996 (Name_Source_Files,
3997 Data.Decl.Attributes,
3998 In_Tree);
4000 Source_List_File : constant Variable_Value :=
4001 Util.Value_Of
4002 (Name_Source_List_File,
4003 Data.Decl.Attributes,
4004 In_Tree);
4006 Locally_Removed : constant Variable_Value :=
4007 Util.Value_Of
4008 (Name_Locally_Removed_Files,
4009 Data.Decl.Attributes,
4010 In_Tree);
4012 begin
4013 pragma Assert
4014 (Sources.Kind = List,
4015 "Source_Files is not a list");
4017 pragma Assert
4018 (Source_List_File.Kind = Single,
4019 "Source_List_File is not a single string");
4021 if not Sources.Default then
4022 if not Source_List_File.Default then
4023 Error_Msg
4024 (Project, In_Tree,
4025 "?both variables source_files and " &
4026 "source_list_file are present",
4027 Source_List_File.Location);
4028 end if;
4030 -- Sources is a list of file names
4032 declare
4033 Current : String_List_Id := Sources.Values;
4034 Element : String_Element;
4035 Location : Source_Ptr;
4036 Name : Name_Id;
4038 begin
4039 Source_Names.Reset;
4041 Data.Ada_Sources_Present := Current /= Nil_String;
4043 while Current /= Nil_String loop
4044 Element :=
4045 In_Tree.String_Elements.Table (Current);
4046 Get_Name_String (Element.Value);
4047 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4048 Name := Name_Find;
4050 -- If the element has no location, then use the
4051 -- location of Sources to report possible errors.
4053 if Element.Location = No_Location then
4054 Location := Sources.Location;
4055 else
4056 Location := Element.Location;
4057 end if;
4059 Source_Names.Set
4060 (K => Name,
4061 E =>
4062 (Name => Name,
4063 Location => Location,
4064 Found => False));
4066 Current := Element.Next;
4067 end loop;
4069 Get_Path_Names_And_Record_Sources (Follow_Links);
4070 end;
4072 -- No source_files specified
4074 -- We check Source_List_File has been specified
4076 elsif not Source_List_File.Default then
4078 -- Source_List_File is the name of the file
4079 -- that contains the source file names
4081 declare
4082 Source_File_Path_Name : constant String :=
4083 Path_Name_Of
4084 (Source_List_File.Value,
4085 Data.Directory);
4087 begin
4088 if Source_File_Path_Name'Length = 0 then
4089 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4090 Error_Msg
4091 (Project, In_Tree,
4092 "file with sources { does not exist",
4093 Source_List_File.Location);
4095 else
4096 Get_Sources_From_File
4097 (Source_File_Path_Name,
4098 Source_List_File.Location);
4099 end if;
4100 end;
4102 else
4103 -- Neither Source_Files nor Source_List_File has been
4104 -- specified. Find all the files that satisfy the naming
4105 -- scheme in all the source directories.
4107 Find_Sources
4108 (Project, In_Tree, Data, Ada_Language_Index, Follow_Links);
4109 end if;
4111 -- If there are sources that are locally removed, mark them as
4112 -- such in the Units table.
4114 if not Locally_Removed.Default then
4116 -- Sources can be locally removed only in extending
4117 -- project files.
4119 if Data.Extends = No_Project then
4120 Error_Msg
4121 (Project, In_Tree,
4122 "Locally_Removed_Files can only be used " &
4123 "in an extending project file",
4124 Locally_Removed.Location);
4126 else
4127 declare
4128 Current : String_List_Id := Locally_Removed.Values;
4129 Element : String_Element;
4130 Location : Source_Ptr;
4131 OK : Boolean;
4132 Unit : Unit_Data;
4133 Name : Name_Id;
4134 Extended : Project_Id;
4136 begin
4137 while Current /= Nil_String loop
4138 Element :=
4139 In_Tree.String_Elements.Table (Current);
4140 Get_Name_String (Element.Value);
4141 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4142 Name := Name_Find;
4144 -- If the element has no location, then use the
4145 -- location of Locally_Removed to report
4146 -- possible errors.
4148 if Element.Location = No_Location then
4149 Location := Locally_Removed.Location;
4150 else
4151 Location := Element.Location;
4152 end if;
4154 OK := False;
4156 for Index in Unit_Table.First ..
4157 Unit_Table.Last (In_Tree.Units)
4158 loop
4159 Unit := In_Tree.Units.Table (Index);
4161 if Unit.File_Names (Specification).Name = Name then
4162 OK := True;
4164 -- Check that this is from a project that
4165 -- the current project extends, but not the
4166 -- current project.
4168 Extended := Unit.File_Names
4169 (Specification).Project;
4171 if Extended = Project then
4172 Error_Msg
4173 (Project, In_Tree,
4174 "cannot remove a source " &
4175 "of the same project",
4176 Location);
4178 elsif
4179 Project_Extends (Project, Extended, In_Tree)
4180 then
4181 Unit.File_Names
4182 (Specification).Path := Slash;
4183 Unit.File_Names
4184 (Specification).Needs_Pragma := False;
4185 In_Tree.Units.Table (Index) :=
4186 Unit;
4187 Add_Forbidden_File_Name
4188 (Unit.File_Names (Specification).Name);
4189 exit;
4191 else
4192 Error_Msg
4193 (Project, In_Tree,
4194 "cannot remove a source from " &
4195 "another project",
4196 Location);
4197 end if;
4199 elsif
4200 Unit.File_Names (Body_Part).Name = Name
4201 then
4202 OK := True;
4204 -- Check that this is from a project that
4205 -- the current project extends, but not the
4206 -- current project.
4208 Extended := Unit.File_Names
4209 (Body_Part).Project;
4211 if Extended = Project then
4212 Error_Msg
4213 (Project, In_Tree,
4214 "cannot remove a source " &
4215 "of the same project",
4216 Location);
4218 elsif
4219 Project_Extends (Project, Extended, In_Tree)
4220 then
4221 Unit.File_Names (Body_Part).Path := Slash;
4222 Unit.File_Names (Body_Part).Needs_Pragma
4223 := False;
4224 In_Tree.Units.Table (Index) :=
4225 Unit;
4226 Add_Forbidden_File_Name
4227 (Unit.File_Names (Body_Part).Name);
4228 exit;
4229 end if;
4231 end if;
4232 end loop;
4234 if not OK then
4235 Err_Vars.Error_Msg_Name_1 := Name;
4236 Error_Msg
4237 (Project, In_Tree, "unknown file {", Location);
4238 end if;
4240 Current := Element.Next;
4241 end loop;
4242 end;
4243 end if;
4244 end if;
4245 end;
4246 end if;
4248 if Data.Other_Sources_Present then
4250 -- Set Source_Present to False. It will be set back to True
4251 -- whenever a source is found.
4253 Data.Other_Sources_Present := False;
4254 for Lang in Ada_Language_Index + 1 .. Last_Language_Index loop
4256 -- For each language (other than Ada) in the project file
4258 if Is_Present (Lang, Data, In_Tree) then
4260 -- Reset the indication that there are sources of this
4261 -- language. It will be set back to True whenever we find a
4262 -- source of the language.
4264 Set (Lang, False, Data, In_Tree);
4266 -- First, get the source suffix for the language
4268 Set (Suffix => Suffix_For (Lang, Data.Naming, In_Tree),
4269 For_Language => Lang,
4270 In_Project => Data,
4271 In_Tree => In_Tree);
4273 -- Then, deal with the naming exceptions, if any
4275 Source_Names.Reset;
4277 declare
4278 Naming_Exceptions : constant Variable_Value :=
4279 Value_Of
4280 (Index => Language_Names.Table (Lang),
4281 Src_Index => 0,
4282 In_Array => Data.Naming.Implementation_Exceptions,
4283 In_Tree => In_Tree);
4284 Element_Id : String_List_Id;
4285 Element : String_Element;
4286 File_Id : Name_Id;
4287 Source_Found : Boolean := False;
4289 begin
4290 -- If there are naming exceptions, look through them one
4291 -- by one.
4293 if Naming_Exceptions /= Nil_Variable_Value then
4294 Element_Id := Naming_Exceptions.Values;
4296 while Element_Id /= Nil_String loop
4297 Element := In_Tree.String_Elements.Table
4298 (Element_Id);
4299 Get_Name_String (Element.Value);
4300 Canonical_Case_File_Name
4301 (Name_Buffer (1 .. Name_Len));
4302 File_Id := Name_Find;
4304 -- Put each naming exception in the Source_Names
4305 -- hash table, but if there are repetition, don't
4306 -- bother after the first instance.
4309 Source_Names.Get (File_Id) = No_Name_Location
4310 then
4311 Source_Found := True;
4312 Source_Names.Set
4313 (File_Id,
4314 (Name => File_Id,
4315 Location => Element.Location,
4316 Found => False));
4317 end if;
4319 Element_Id := Element.Next;
4320 end loop;
4322 -- If there is at least one naming exception, record
4323 -- those that are found in the source directories.
4325 if Source_Found then
4326 Record_Other_Sources
4327 (Project => Project,
4328 In_Tree => In_Tree,
4329 Data => Data,
4330 Language => Lang,
4331 Naming_Exceptions => True);
4332 end if;
4334 end if;
4335 end;
4337 -- Now, check if a list of sources is declared either through
4338 -- a string list (attribute Source_Files) or a text file
4339 -- (attribute Source_List_File). If a source list is declared,
4340 -- we will consider only those naming exceptions that are
4341 -- on the list.
4343 declare
4344 Sources : constant Variable_Value :=
4345 Util.Value_Of
4346 (Name_Source_Files,
4347 Data.Decl.Attributes,
4348 In_Tree);
4350 Source_List_File : constant Variable_Value :=
4351 Util.Value_Of
4352 (Name_Source_List_File,
4353 Data.Decl.Attributes,
4354 In_Tree);
4356 begin
4357 pragma Assert
4358 (Sources.Kind = List,
4359 "Source_Files is not a list");
4361 pragma Assert
4362 (Source_List_File.Kind = Single,
4363 "Source_List_File is not a single string");
4365 if not Sources.Default then
4366 if not Source_List_File.Default then
4367 Error_Msg
4368 (Project, In_Tree,
4369 "?both variables source_files and " &
4370 "source_list_file are present",
4371 Source_List_File.Location);
4372 end if;
4374 -- Sources is a list of file names
4376 declare
4377 Current : String_List_Id := Sources.Values;
4378 Element : String_Element;
4379 Location : Source_Ptr;
4380 Name : Name_Id;
4382 begin
4383 Source_Names.Reset;
4385 -- Put all the sources in the Source_Names hash table
4387 while Current /= Nil_String loop
4388 Element :=
4389 In_Tree.String_Elements.Table
4390 (Current);
4391 Get_Name_String (Element.Value);
4392 Canonical_Case_File_Name
4393 (Name_Buffer (1 .. Name_Len));
4394 Name := Name_Find;
4396 -- If the element has no location, then use the
4397 -- location of Sources to report possible errors.
4399 if Element.Location = No_Location then
4400 Location := Sources.Location;
4401 else
4402 Location := Element.Location;
4403 end if;
4405 Source_Names.Set
4406 (K => Name,
4407 E =>
4408 (Name => Name,
4409 Location => Location,
4410 Found => False));
4412 Current := Element.Next;
4413 end loop;
4415 -- And look for their directories
4417 Record_Other_Sources
4418 (Project => Project,
4419 In_Tree => In_Tree,
4420 Data => Data,
4421 Language => Lang,
4422 Naming_Exceptions => False);
4423 end;
4425 -- No source_files specified
4427 -- We check if Source_List_File has been specified
4429 elsif not Source_List_File.Default then
4431 -- Source_List_File is the name of the file
4432 -- that contains the source file names
4434 declare
4435 Source_File_Path_Name : constant String :=
4436 Path_Name_Of
4437 (Source_List_File.Value,
4438 Data.Directory);
4440 begin
4441 if Source_File_Path_Name'Length = 0 then
4442 Err_Vars.Error_Msg_Name_1 :=
4443 Source_List_File.Value;
4444 Error_Msg
4445 (Project, In_Tree,
4446 "file with sources { does not exist",
4447 Source_List_File.Location);
4449 else
4450 -- Read the file, putting each source in the
4451 -- Source_Names hash table.
4453 Get_Sources_From_File
4454 (Source_File_Path_Name,
4455 Source_List_File.Location,
4456 Project, In_Tree);
4458 -- And look for their directories
4460 Record_Other_Sources
4461 (Project => Project,
4462 In_Tree => In_Tree,
4463 Data => Data,
4464 Language => Lang,
4465 Naming_Exceptions => False);
4466 end if;
4467 end;
4469 -- Neither Source_Files nor Source_List_File was specified
4471 else
4472 -- Find all the files that satisfy the naming scheme in
4473 -- all the source directories. All the naming exceptions
4474 -- that effectively exist are also part of the source
4475 -- of this language.
4477 Find_Sources (Project, In_Tree, Data, Lang);
4478 end if;
4479 end;
4480 end if;
4481 end loop;
4482 end if;
4483 end Look_For_Sources;
4485 ------------------
4486 -- Path_Name_Of --
4487 ------------------
4489 function Path_Name_Of
4490 (File_Name : Name_Id;
4491 Directory : Name_Id) return String
4493 Result : String_Access;
4495 The_Directory : constant String := Get_Name_String (Directory);
4497 begin
4498 Get_Name_String (File_Name);
4499 Result := Locate_Regular_File
4500 (File_Name => Name_Buffer (1 .. Name_Len),
4501 Path => The_Directory);
4503 if Result = null then
4504 return "";
4505 else
4506 Canonical_Case_File_Name (Result.all);
4507 return Result.all;
4508 end if;
4509 end Path_Name_Of;
4511 -------------------------------
4512 -- Prepare_Ada_Naming_Exceptions --
4513 -------------------------------
4515 procedure Prepare_Ada_Naming_Exceptions
4516 (List : Array_Element_Id;
4517 In_Tree : Project_Tree_Ref;
4518 Kind : Spec_Or_Body)
4520 Current : Array_Element_Id := List;
4521 Element : Array_Element;
4523 Unit : Unit_Info;
4525 begin
4526 -- Traverse the list
4528 while Current /= No_Array_Element loop
4529 Element := In_Tree.Array_Elements.Table (Current);
4531 if Element.Index /= No_Name then
4532 Unit :=
4533 (Kind => Kind,
4534 Unit => Element.Index,
4535 Next => No_Ada_Naming_Exception);
4536 Reverse_Ada_Naming_Exceptions.Set
4537 (Unit, (Element.Value.Value, Element.Value.Index));
4538 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4539 Ada_Naming_Exception_Table.Increment_Last;
4540 Ada_Naming_Exception_Table.Table
4541 (Ada_Naming_Exception_Table.Last) := Unit;
4542 Ada_Naming_Exceptions.Set
4543 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4544 end if;
4546 Current := Element.Next;
4547 end loop;
4548 end Prepare_Ada_Naming_Exceptions;
4550 ---------------------
4551 -- Project_Extends --
4552 ---------------------
4554 function Project_Extends
4555 (Extending : Project_Id;
4556 Extended : Project_Id;
4557 In_Tree : Project_Tree_Ref) return Boolean
4559 Current : Project_Id := Extending;
4560 begin
4561 loop
4562 if Current = No_Project then
4563 return False;
4565 elsif Current = Extended then
4566 return True;
4567 end if;
4569 Current := In_Tree.Projects.Table (Current).Extends;
4570 end loop;
4571 end Project_Extends;
4573 -----------------------
4574 -- Record_Ada_Source --
4575 -----------------------
4577 procedure Record_Ada_Source
4578 (File_Name : Name_Id;
4579 Path_Name : Name_Id;
4580 Project : Project_Id;
4581 In_Tree : Project_Tree_Ref;
4582 Data : in out Project_Data;
4583 Location : Source_Ptr;
4584 Current_Source : in out String_List_Id;
4585 Source_Recorded : in out Boolean;
4586 Follow_Links : Boolean)
4588 Canonical_File_Name : Name_Id;
4589 Canonical_Path_Name : Name_Id;
4591 Exception_Id : Ada_Naming_Exception_Id;
4592 Unit_Name : Name_Id;
4593 Unit_Kind : Spec_Or_Body;
4594 Unit_Index : Int := 0;
4595 Info : Unit_Info;
4596 Name_Index : Name_And_Index;
4597 Needs_Pragma : Boolean;
4599 The_Location : Source_Ptr := Location;
4600 Previous_Source : constant String_List_Id := Current_Source;
4601 Except_Name : Name_And_Index := No_Name_And_Index;
4603 Unit_Prj : Unit_Project;
4605 File_Name_Recorded : Boolean := False;
4607 begin
4608 Get_Name_String (File_Name);
4609 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4610 Canonical_File_Name := Name_Find;
4612 declare
4613 Canonical_Path : constant String :=
4614 Normalize_Pathname
4615 (Get_Name_String (Path_Name),
4616 Resolve_Links => Follow_Links,
4617 Case_Sensitive => False);
4618 begin
4619 Name_Len := 0;
4620 Add_Str_To_Name_Buffer (Canonical_Path);
4621 Canonical_Path_Name := Name_Find;
4622 end;
4624 -- Find out the unit name, the unit kind and if it needs
4625 -- a specific SFN pragma.
4627 Get_Unit
4628 (Canonical_File_Name => Canonical_File_Name,
4629 Naming => Data.Naming,
4630 Exception_Id => Exception_Id,
4631 Unit_Name => Unit_Name,
4632 Unit_Kind => Unit_Kind,
4633 Needs_Pragma => Needs_Pragma);
4635 if Exception_Id = No_Ada_Naming_Exception and then
4636 Unit_Name = No_Name
4637 then
4638 if Current_Verbosity = High then
4639 Write_Str (" """);
4640 Write_Str (Get_Name_String (Canonical_File_Name));
4641 Write_Line (""" is not a valid source file name (ignored).");
4642 end if;
4644 else
4645 -- Check to see if the source has been hidden by an exception,
4646 -- but only if it is not an exception.
4648 if not Needs_Pragma then
4649 Except_Name :=
4650 Reverse_Ada_Naming_Exceptions.Get
4651 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4653 if Except_Name /= No_Name_And_Index then
4654 if Current_Verbosity = High then
4655 Write_Str (" """);
4656 Write_Str (Get_Name_String (Canonical_File_Name));
4657 Write_Str (""" contains a unit that is found in """);
4658 Write_Str (Get_Name_String (Except_Name.Name));
4659 Write_Line (""" (ignored).");
4660 end if;
4662 -- The file is not included in the source of the project,
4663 -- because it is hidden by the exception.
4664 -- So, there is nothing else to do.
4666 return;
4667 end if;
4668 end if;
4670 loop
4671 if Exception_Id /= No_Ada_Naming_Exception then
4672 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4673 Exception_Id := Info.Next;
4674 Info.Next := No_Ada_Naming_Exception;
4675 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4677 Unit_Name := Info.Unit;
4678 Unit_Index := Name_Index.Index;
4679 Unit_Kind := Info.Kind;
4680 end if;
4682 -- Put the file name in the list of sources of the project
4684 if not File_Name_Recorded then
4685 String_Element_Table.Increment_Last
4686 (In_Tree.String_Elements);
4687 In_Tree.String_Elements.Table
4688 (String_Element_Table.Last
4689 (In_Tree.String_Elements)) :=
4690 (Value => Canonical_File_Name,
4691 Display_Value => File_Name,
4692 Location => No_Location,
4693 Flag => False,
4694 Next => Nil_String,
4695 Index => Unit_Index);
4696 end if;
4698 if Current_Source = Nil_String then
4699 Data.Sources := String_Element_Table.Last
4700 (In_Tree.String_Elements);
4701 else
4702 In_Tree.String_Elements.Table
4703 (Current_Source).Next :=
4704 String_Element_Table.Last
4705 (In_Tree.String_Elements);
4706 end if;
4708 Current_Source := String_Element_Table.Last
4709 (In_Tree.String_Elements);
4711 -- Put the unit in unit list
4713 declare
4714 The_Unit : Unit_Id :=
4715 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
4716 The_Unit_Data : Unit_Data;
4718 begin
4719 if Current_Verbosity = High then
4720 Write_Str ("Putting ");
4721 Write_Str (Get_Name_String (Unit_Name));
4722 Write_Line (" in the unit list.");
4723 end if;
4725 -- The unit is already in the list, but may be it is
4726 -- only the other unit kind (spec or body), or what is
4727 -- in the unit list is a unit of a project we are extending.
4729 if The_Unit /= No_Unit then
4730 The_Unit_Data := In_Tree.Units.Table (The_Unit);
4732 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4733 or else Project_Extends
4734 (Data.Extends,
4735 The_Unit_Data.File_Names (Unit_Kind).Project,
4736 In_Tree)
4737 then
4738 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4739 Remove_Forbidden_File_Name
4740 (The_Unit_Data.File_Names (Unit_Kind).Name);
4741 end if;
4743 -- Record the file name in the hash table Files_Htable
4745 Unit_Prj := (Unit => The_Unit, Project => Project);
4746 Files_Htable.Set
4747 (In_Tree.Files_HT,
4748 Canonical_File_Name,
4749 Unit_Prj);
4751 The_Unit_Data.File_Names (Unit_Kind) :=
4752 (Name => Canonical_File_Name,
4753 Index => Unit_Index,
4754 Display_Name => File_Name,
4755 Path => Canonical_Path_Name,
4756 Display_Path => Path_Name,
4757 Project => Project,
4758 Needs_Pragma => Needs_Pragma);
4759 In_Tree.Units.Table (The_Unit) :=
4760 The_Unit_Data;
4761 Source_Recorded := True;
4763 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4764 and then (Data.Known_Order_Of_Source_Dirs or else
4765 The_Unit_Data.File_Names (Unit_Kind).Path =
4766 Canonical_Path_Name)
4767 then
4768 if Previous_Source = Nil_String then
4769 Data.Sources := Nil_String;
4770 else
4771 In_Tree.String_Elements.Table
4772 (Previous_Source).Next := Nil_String;
4773 String_Element_Table.Decrement_Last
4774 (In_Tree.String_Elements);
4775 end if;
4777 Current_Source := Previous_Source;
4779 else
4780 -- It is an error to have two units with the same name
4781 -- and the same kind (spec or body).
4783 if The_Location = No_Location then
4784 The_Location :=
4785 In_Tree.Projects.Table
4786 (Project).Location;
4787 end if;
4789 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4790 Error_Msg
4791 (Project, In_Tree, "duplicate source {", The_Location);
4793 Err_Vars.Error_Msg_Name_1 :=
4794 In_Tree.Projects.Table
4795 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4796 Err_Vars.Error_Msg_Name_2 :=
4797 The_Unit_Data.File_Names (Unit_Kind).Path;
4798 Error_Msg
4799 (Project, In_Tree,
4800 "\ project file {, {", The_Location);
4802 Err_Vars.Error_Msg_Name_1 :=
4803 In_Tree.Projects.Table (Project).Name;
4804 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4805 Error_Msg
4806 (Project, In_Tree,
4807 "\ project file {, {", The_Location);
4808 end if;
4810 -- It is a new unit, create a new record
4812 else
4813 -- First, check if there is no other unit with this file
4814 -- name in another project. If it is, report an error.
4815 -- Of course, we do that only for the first unit in the
4816 -- source file.
4818 Unit_Prj := Files_Htable.Get
4819 (In_Tree.Files_HT, Canonical_File_Name);
4821 if not File_Name_Recorded and then
4822 Unit_Prj /= No_Unit_Project
4823 then
4824 Error_Msg_Name_1 := File_Name;
4825 Error_Msg_Name_2 :=
4826 In_Tree.Projects.Table
4827 (Unit_Prj.Project).Name;
4828 Error_Msg
4829 (Project, In_Tree,
4830 "{ is already a source of project {",
4831 Location);
4833 else
4834 Unit_Table.Increment_Last (In_Tree.Units);
4835 The_Unit := Unit_Table.Last (In_Tree.Units);
4836 Units_Htable.Set
4837 (In_Tree.Units_HT, Unit_Name, The_Unit);
4838 Unit_Prj := (Unit => The_Unit, Project => Project);
4839 Files_Htable.Set
4840 (In_Tree.Files_HT,
4841 Canonical_File_Name,
4842 Unit_Prj);
4843 The_Unit_Data.Name := Unit_Name;
4844 The_Unit_Data.File_Names (Unit_Kind) :=
4845 (Name => Canonical_File_Name,
4846 Index => Unit_Index,
4847 Display_Name => File_Name,
4848 Path => Canonical_Path_Name,
4849 Display_Path => Path_Name,
4850 Project => Project,
4851 Needs_Pragma => Needs_Pragma);
4852 In_Tree.Units.Table (The_Unit) :=
4853 The_Unit_Data;
4854 Source_Recorded := True;
4855 end if;
4856 end if;
4857 end;
4859 exit when Exception_Id = No_Ada_Naming_Exception;
4860 File_Name_Recorded := True;
4861 end loop;
4862 end if;
4863 end Record_Ada_Source;
4865 --------------------------
4866 -- Record_Other_Sources --
4867 --------------------------
4869 procedure Record_Other_Sources
4870 (Project : Project_Id;
4871 In_Tree : Project_Tree_Ref;
4872 Data : in out Project_Data;
4873 Language : Language_Index;
4874 Naming_Exceptions : Boolean)
4876 Source_Dir : String_List_Id := Data.Source_Dirs;
4877 Element : String_Element;
4878 Path : Name_Id;
4880 Dir : Dir_Type;
4881 Canonical_Name : Name_Id;
4883 Name_Str : String (1 .. 1_024);
4884 Last : Natural := 0;
4885 NL : Name_Location;
4887 First_Error : Boolean := True;
4889 Suffix : constant String := Body_Suffix_Of (Language, Data, In_Tree);
4891 begin
4892 while Source_Dir /= Nil_String loop
4893 Element := In_Tree.String_Elements.Table (Source_Dir);
4895 declare
4896 Dir_Path : constant String := Get_Name_String (Element.Value);
4898 begin
4899 if Current_Verbosity = High then
4900 Write_Str ("checking directory """);
4901 Write_Str (Dir_Path);
4902 Write_Str (""" for ");
4904 if Naming_Exceptions then
4905 Write_Str ("naming exceptions");
4907 else
4908 Write_Str ("sources");
4909 end if;
4911 Write_Str (" of Language ");
4912 Display_Language_Name (Language);
4913 end if;
4915 Open (Dir, Dir_Path);
4917 loop
4918 Read (Dir, Name_Str, Last);
4919 exit when Last = 0;
4921 if Is_Regular_File
4922 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4923 then
4924 Name_Len := Last;
4925 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4926 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4927 Canonical_Name := Name_Find;
4928 NL := Source_Names.Get (Canonical_Name);
4930 if NL /= No_Name_Location then
4931 if NL.Found then
4932 if not Data.Known_Order_Of_Source_Dirs then
4933 Error_Msg_Name_1 := Canonical_Name;
4934 Error_Msg
4935 (Project, In_Tree,
4936 "{ is found in several source directories",
4937 NL.Location);
4938 end if;
4940 else
4941 NL.Found := True;
4942 Source_Names.Set (Canonical_Name, NL);
4943 Name_Len := Dir_Path'Length;
4944 Name_Buffer (1 .. Name_Len) := Dir_Path;
4945 Add_Char_To_Name_Buffer (Directory_Separator);
4946 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4947 Path := Name_Find;
4949 Check_For_Source
4950 (File_Name => Canonical_Name,
4951 Path_Name => Path,
4952 Project => Project,
4953 In_Tree => In_Tree,
4954 Data => Data,
4955 Location => NL.Location,
4956 Language => Language,
4957 Suffix => Suffix,
4958 Naming_Exception => Naming_Exceptions);
4959 end if;
4960 end if;
4961 end if;
4962 end loop;
4964 Close (Dir);
4965 end;
4967 Source_Dir := Element.Next;
4968 end loop;
4970 if not Naming_Exceptions then
4971 NL := Source_Names.Get_First;
4973 -- It is an error if a source file name in a source list or
4974 -- in a source list file is not found.
4976 while NL /= No_Name_Location loop
4977 if not NL.Found then
4978 Err_Vars.Error_Msg_Name_1 := NL.Name;
4980 if First_Error then
4981 Error_Msg
4982 (Project, In_Tree,
4983 "source file { cannot be found",
4984 NL.Location);
4985 First_Error := False;
4987 else
4988 Error_Msg
4989 (Project, In_Tree,
4990 "\source file { cannot be found",
4991 NL.Location);
4992 end if;
4993 end if;
4995 NL := Source_Names.Get_Next;
4996 end loop;
4998 -- Any naming exception of this language that is not in a list
4999 -- of sources must be removed.
5001 declare
5002 Source_Id : Other_Source_Id := Data.First_Other_Source;
5003 Prev_Id : Other_Source_Id := No_Other_Source;
5004 Source : Other_Source;
5006 begin
5007 while Source_Id /= No_Other_Source loop
5008 Source := In_Tree.Other_Sources.Table (Source_Id);
5010 if Source.Language = Language
5011 and then Source.Naming_Exception
5012 then
5013 if Current_Verbosity = High then
5014 Write_Str ("Naming exception """);
5015 Write_Str (Get_Name_String (Source.File_Name));
5016 Write_Str (""" is not in the list of sources,");
5017 Write_Line (" so it is removed.");
5018 end if;
5020 if Prev_Id = No_Other_Source then
5021 Data.First_Other_Source := Source.Next;
5023 else
5024 In_Tree.Other_Sources.Table
5025 (Prev_Id).Next := Source.Next;
5026 end if;
5028 Source_Id := Source.Next;
5030 if Source_Id = No_Other_Source then
5031 Data.Last_Other_Source := Prev_Id;
5032 end if;
5034 else
5035 Prev_Id := Source_Id;
5036 Source_Id := Source.Next;
5037 end if;
5038 end loop;
5039 end;
5040 end if;
5041 end Record_Other_Sources;
5043 ----------------------
5044 -- Show_Source_Dirs --
5045 ----------------------
5047 procedure Show_Source_Dirs
5048 (Project : Project_Id;
5049 In_Tree : Project_Tree_Ref)
5051 Current : String_List_Id;
5052 Element : String_Element;
5054 begin
5055 Write_Line ("Source_Dirs:");
5057 Current := In_Tree.Projects.Table (Project).Source_Dirs;
5058 while Current /= Nil_String loop
5059 Element := In_Tree.String_Elements.Table (Current);
5060 Write_Str (" ");
5061 Write_Line (Get_Name_String (Element.Value));
5062 Current := Element.Next;
5063 end loop;
5065 Write_Line ("end Source_Dirs.");
5066 end Show_Source_Dirs;
5068 ----------------
5069 -- Suffix_For --
5070 ----------------
5072 function Suffix_For
5073 (Language : Language_Index;
5074 Naming : Naming_Data;
5075 In_Tree : Project_Tree_Ref) return Name_Id
5077 Suffix : constant Variable_Value :=
5078 Value_Of
5079 (Index => Language_Names.Table (Language),
5080 Src_Index => 0,
5081 In_Array => Naming.Body_Suffix,
5082 In_Tree => In_Tree);
5083 begin
5084 -- If no suffix for this language in package Naming, use the default
5086 if Suffix = Nil_Variable_Value then
5087 Name_Len := 0;
5089 case Language is
5090 when Ada_Language_Index =>
5091 Add_Str_To_Name_Buffer (".adb");
5093 when C_Language_Index =>
5094 Add_Str_To_Name_Buffer (".c");
5096 when C_Plus_Plus_Language_Index =>
5097 Add_Str_To_Name_Buffer (".cpp");
5099 when others =>
5100 return No_Name;
5101 end case;
5103 -- Otherwise use the one specified
5105 else
5106 Get_Name_String (Suffix.Value);
5107 end if;
5109 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5110 return Name_Find;
5111 end Suffix_For;
5113 -------------------------
5114 -- Warn_If_Not_Sources --
5115 -------------------------
5117 -- comments needed in this body ???
5119 procedure Warn_If_Not_Sources
5120 (Project : Project_Id;
5121 In_Tree : Project_Tree_Ref;
5122 Conventions : Array_Element_Id;
5123 Specs : Boolean;
5124 Extending : Boolean)
5126 Conv : Array_Element_Id := Conventions;
5127 Unit : Name_Id;
5128 The_Unit_Id : Unit_Id;
5129 The_Unit_Data : Unit_Data;
5130 Location : Source_Ptr;
5132 begin
5133 while Conv /= No_Array_Element loop
5134 Unit := In_Tree.Array_Elements.Table (Conv).Index;
5135 Error_Msg_Name_1 := Unit;
5136 Get_Name_String (Unit);
5137 To_Lower (Name_Buffer (1 .. Name_Len));
5138 Unit := Name_Find;
5139 The_Unit_Id := Units_Htable.Get
5140 (In_Tree.Units_HT, Unit);
5141 Location := In_Tree.Array_Elements.Table
5142 (Conv).Value.Location;
5144 if The_Unit_Id = No_Unit then
5145 Error_Msg
5146 (Project, In_Tree,
5147 "?unknown unit {",
5148 Location);
5150 else
5151 The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
5153 if Specs then
5154 if not Check_Project
5155 (The_Unit_Data.File_Names (Specification).Project,
5156 Project, In_Tree, Extending)
5157 then
5158 Error_Msg
5159 (Project, In_Tree,
5160 "?unit{ has no spec in this project",
5161 Location);
5162 end if;
5164 else
5165 if not Check_Project
5166 (The_Unit_Data.File_Names (Body_Part).Project,
5167 Project, In_Tree, Extending)
5168 then
5169 Error_Msg
5170 (Project, In_Tree,
5171 "?unit{ has no body in this project",
5172 Location);
5173 end if;
5174 end if;
5175 end if;
5177 Conv := In_Tree.Array_Elements.Table (Conv).Next;
5178 end loop;
5179 end Warn_If_Not_Sources;
5181 end Prj.Nmsc;