PR middle-end/20263
[official-gcc.git] / gcc / ada / prj-nmsc.adb
blob6c814a990fd50c936ce416a9c9fd8c48a2562587
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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;
41 with Types; use Types;
43 with Ada.Characters.Handling; use Ada.Characters.Handling;
44 with Ada.Strings; use Ada.Strings;
45 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
46 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
48 with GNAT.Case_Util; use GNAT.Case_Util;
49 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
50 with GNAT.OS_Lib; use GNAT.OS_Lib;
51 with GNAT.HTable;
53 package body Prj.Nmsc is
55 Error_Report : Put_Line_Access := null;
56 -- Set to point to error reporting procedure
58 ALI_Suffix : constant String := ".ali";
59 -- File suffix for ali files
61 Object_Suffix : constant String := Get_Object_Suffix.all;
62 -- File suffix for object files
64 type Name_Location is record
65 Name : Name_Id;
66 Location : Source_Ptr;
67 Found : Boolean := False;
68 end record;
69 -- Information about file names found in string list attribute
70 -- Source_Files or in a source list file, stored in hash table
71 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
73 No_Name_Location : constant Name_Location :=
74 (Name => No_Name, Location => No_Location, Found => False);
76 package Source_Names is new GNAT.HTable.Simple_HTable
77 (Header_Num => Header_Num,
78 Element => Name_Location,
79 No_Element => No_Name_Location,
80 Key => Name_Id,
81 Hash => Hash,
82 Equal => "=");
83 -- Hash table to store file names found in string list attribute
84 -- Source_Files or in a source list file, stored in hash table
85 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
87 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
88 (Header_Num => Header_Num,
89 Element => Boolean,
90 No_Element => False,
91 Key => Name_Id,
92 Hash => Hash,
93 Equal => "=");
94 -- Hash table to store recursive source directories, to avoid looking
95 -- several times, and to avoid cycles that may be introduced by symbolic
96 -- links.
98 type Ada_Naming_Exception_Id is new Nat;
99 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
101 type Unit_Info is record
102 Kind : Spec_Or_Body;
103 Unit : Name_Id;
104 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
105 end record;
106 -- No_Unit : constant Unit_Info :=
107 -- (Specification, No_Name, No_Ada_Naming_Exception);
109 package Ada_Naming_Exception_Table is new Table.Table
110 (Table_Component_Type => Unit_Info,
111 Table_Index_Type => Ada_Naming_Exception_Id,
112 Table_Low_Bound => 1,
113 Table_Initial => 20,
114 Table_Increment => 100,
115 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
117 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
118 (Header_Num => Header_Num,
119 Element => Ada_Naming_Exception_Id,
120 No_Element => No_Ada_Naming_Exception,
121 Key => Name_Id,
122 Hash => Hash,
123 Equal => "=");
124 -- A hash table to store naming exceptions for Ada. For each file name
125 -- there is one or several unit in table Ada_Naming_Exception_Table.
127 function Hash (Unit : Unit_Info) return Header_Num;
129 type Name_And_Index is record
130 Name : Name_Id := No_Name;
131 Index : Int := 0;
132 end record;
133 No_Name_And_Index : constant Name_And_Index :=
134 (Name => No_Name, Index => 0);
136 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
137 (Header_Num => Header_Num,
138 Element => Name_And_Index,
139 No_Element => No_Name_And_Index,
140 Key => Unit_Info,
141 Hash => Hash,
142 Equal => "=");
143 -- A table to check if a unit with an exceptional name will hide
144 -- a source with a file name following the naming convention.
146 function ALI_File_Name (Source : String) return String;
147 -- Return the ALI file name corresponding to a source
149 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
150 -- Check that a name is a valid Ada unit name
152 procedure Check_Naming_Scheme
153 (Data : in out Project_Data;
154 Project : Project_Id;
155 In_Tree : Project_Tree_Ref);
156 -- Check the naming scheme part of Data
158 procedure Check_Ada_Naming_Scheme_Validity
159 (Project : Project_Id;
160 In_Tree : Project_Tree_Ref;
161 Naming : Naming_Data);
162 -- Check that the package Naming is correct
164 procedure Check_For_Source
165 (File_Name : Name_Id;
166 Path_Name : Name_Id;
167 Project : Project_Id;
168 In_Tree : Project_Tree_Ref;
169 Data : in out Project_Data;
170 Location : Source_Ptr;
171 Language : Language_Index;
172 Suffix : String;
173 Naming_Exception : Boolean);
174 -- Check if a file, with name File_Name and path Path_Name, in a source
175 -- directory is a source for language Language in project Project of
176 -- project tree In_Tree. ???
178 procedure Check_If_Externally_Built
179 (Project : Project_Id;
180 In_Tree : Project_Tree_Ref;
181 Data : in out Project_Data);
182 -- Check attribute Externally_Built of project Project in project tree
183 -- In_Tree and modify its data Data if it has the value "true".
185 procedure Check_Library_Attributes
186 (Project : Project_Id;
187 In_Tree : Project_Tree_Ref;
188 Data : in out Project_Data);
189 -- Check the library attributes of project Project in project tree In_Tree
190 -- and modify its data Data accordingly.
192 procedure Check_Package_Naming
193 (Project : Project_Id;
194 In_Tree : Project_Tree_Ref;
195 Data : in out Project_Data);
196 -- Check package Naming of project Project in project tree In_Tree and
197 -- modify its data Data accordingly.
199 procedure Check_Programming_Languages
200 (In_Tree : Project_Tree_Ref; Data : in out Project_Data);
201 -- Check attribute Languages for the project with data Data in project
202 -- tree In_Tree and set the components of Data for all the programming
203 -- languages indicated in attribute Languages, if any.
205 function Check_Project
206 (P : Project_Id;
207 Root_Project : Project_Id;
208 In_Tree : Project_Tree_Ref;
209 Extending : Boolean) return Boolean;
210 -- Returns True if P is Root_Project or, if Extending is True, a project
211 -- extended by Root_Project.
213 procedure Check_Stand_Alone_Library
214 (Project : Project_Id;
215 In_Tree : Project_Tree_Ref;
216 Data : in out Project_Data;
217 Extending : Boolean);
218 -- Check if project Project in project tree In_Tree is a Stand-Alone
219 -- Library project, and modify its data Data accordingly if it is one.
221 function Compute_Directory_Last (Dir : String) return Natural;
222 -- Return the index of the last significant character in Dir. This is used
223 -- to avoid duplicates '/' at the end of directory names
225 function Body_Suffix_Of
226 (Language : Language_Index;
227 In_Project : Project_Data;
228 In_Tree : Project_Tree_Ref)
229 return String;
230 -- Returns the suffix of sources of language Language in project In_Project
231 -- in project tree In_Tree.
233 procedure Error_Msg
234 (Project : Project_Id;
235 In_Tree : Project_Tree_Ref;
236 Msg : String;
237 Flag_Location : Source_Ptr);
238 -- Output an error message. If Error_Report is null, simply call
239 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
240 -- Error_Report.
242 procedure Find_Sources
243 (Project : Project_Id;
244 In_Tree : Project_Tree_Ref;
245 Data : in out Project_Data;
246 For_Language : Language_Index;
247 Follow_Links : Boolean := False);
248 -- Find all the sources in all of the source directories of a project for
249 -- a specified language.
251 procedure Free_Ada_Naming_Exceptions;
252 -- Free the internal hash tables used for checking naming exceptions
254 procedure Get_Directories
255 (Project : Project_Id;
256 In_Tree : Project_Tree_Ref;
257 Data : in out Project_Data);
258 -- Get the object directory, the exec directory and the source directories
259 -- of a project.
261 procedure Get_Mains
262 (Project : Project_Id;
263 In_Tree : Project_Tree_Ref;
264 Data : in out Project_Data);
265 -- Get the mains of a project from attribute Main, if it exists, and put
266 -- them in the project data.
268 procedure Get_Sources_From_File
269 (Path : String;
270 Location : Source_Ptr;
271 Project : Project_Id;
272 In_Tree : Project_Tree_Ref);
273 -- Get the list of sources from a text file and put them in hash table
274 -- Source_Names.
276 procedure Get_Unit
277 (Canonical_File_Name : Name_Id;
278 Naming : Naming_Data;
279 Exception_Id : out Ada_Naming_Exception_Id;
280 Unit_Name : out Name_Id;
281 Unit_Kind : out Spec_Or_Body;
282 Needs_Pragma : out Boolean);
283 -- Find out, from a file name, the unit name, the unit kind and if a
284 -- specific SFN pragma is needed. If the file name corresponds to no
285 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
286 -- or an exception to the naming scheme, then Exception_Id is set to
287 -- the unit or units that the source contains.
289 function Is_Illegal_Suffix
290 (Suffix : String;
291 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
292 -- Returns True if the string Suffix cannot be used as
293 -- a spec suffix, a body suffix or a separate suffix.
295 procedure Locate_Directory
296 (Name : Name_Id;
297 Parent : Name_Id;
298 Dir : out Name_Id;
299 Display : out Name_Id);
300 -- Locate a directory (returns No_Name for Dir and Display if directory
301 -- does not exist). Name is the directory name. Parent is the root
302 -- directory, if Name is a relative path name. Dir is the canonical case
303 -- path name of the directory, Display is the directory path name for
304 -- display purposes.
306 procedure Look_For_Sources
307 (Project : Project_Id;
308 In_Tree : Project_Tree_Ref;
309 Data : in out Project_Data;
310 Follow_Links : Boolean);
311 -- Find all the sources of a project
313 function Path_Name_Of
314 (File_Name : Name_Id;
315 Directory : Name_Id) return String;
316 -- Returns the path name of a (non project) file.
317 -- Returns an empty string if file cannot be found.
319 procedure Prepare_Ada_Naming_Exceptions
320 (List : Array_Element_Id;
321 In_Tree : Project_Tree_Ref;
322 Kind : Spec_Or_Body);
323 -- Prepare the internal hash tables used for checking naming exceptions
324 -- for Ada. Insert all elements of List in the tables.
326 function Project_Extends
327 (Extending : Project_Id;
328 Extended : Project_Id;
329 In_Tree : Project_Tree_Ref) return Boolean;
330 -- Returns True if Extending is extending Extended either directly or
331 -- indirectly.
333 procedure Record_Ada_Source
334 (File_Name : Name_Id;
335 Path_Name : Name_Id;
336 Project : Project_Id;
337 In_Tree : Project_Tree_Ref;
338 Data : in out Project_Data;
339 Location : Source_Ptr;
340 Current_Source : in out String_List_Id;
341 Source_Recorded : in out Boolean;
342 Follow_Links : Boolean);
343 -- Put a unit in the list of units of a project, if the file name
344 -- corresponds to a valid unit name.
346 procedure Record_Other_Sources
347 (Project : Project_Id;
348 In_Tree : Project_Tree_Ref;
349 Data : in out Project_Data;
350 Language : Language_Index;
351 Naming_Exceptions : Boolean);
352 -- Record the sources of a language in a project.
353 -- When Naming_Exceptions is True, mark the found sources as such, to
354 -- later remove those that are not named in a list of sources.
356 procedure Show_Source_Dirs
357 (Project : Project_Id; In_Tree : Project_Tree_Ref);
358 -- List all the source directories of a project
360 function Suffix_For
361 (Language : Language_Index;
362 Naming : Naming_Data;
363 In_Tree : Project_Tree_Ref) return Name_Id;
364 -- Get the suffix for the source of a language from a package naming.
365 -- If not specified, return the default for the language.
367 procedure Warn_If_Not_Sources
368 (Project : Project_Id;
369 In_Tree : Project_Tree_Ref;
370 Conventions : Array_Element_Id;
371 Specs : Boolean;
372 Extending : Boolean);
373 -- Check that individual naming conventions apply to immediate
374 -- sources of the project; if not, issue a warning.
376 -------------------
377 -- ALI_File_Name --
378 -------------------
380 function ALI_File_Name (Source : String) return String is
381 begin
382 -- If the source name has an extension, then replace it with
383 -- the ALI suffix.
385 for Index in reverse Source'First + 1 .. Source'Last loop
386 if Source (Index) = '.' then
387 return Source (Source'First .. Index - 1) & ALI_Suffix;
388 end if;
389 end loop;
391 -- If there is no dot, or if it is the first character, just add the
392 -- ALI suffix.
394 return Source & ALI_Suffix;
395 end ALI_File_Name;
397 -----------
398 -- Check --
399 -----------
401 procedure Check
402 (Project : Project_Id;
403 In_Tree : Project_Tree_Ref;
404 Report_Error : Put_Line_Access;
405 Follow_Links : Boolean)
407 Data : Project_Data := In_Tree.Projects.Table (Project);
408 Extending : Boolean := False;
410 begin
411 Error_Report := Report_Error;
413 Recursive_Dirs.Reset;
415 -- Object, exec and source directories
417 Get_Directories (Project, In_Tree, Data);
419 -- Get the programming languages
421 Check_Programming_Languages (In_Tree, Data);
423 -- Library attributes
425 Check_Library_Attributes (Project, In_Tree, Data);
427 Check_If_Externally_Built (Project, In_Tree, Data);
429 if Current_Verbosity = High then
430 Show_Source_Dirs (Project, In_Tree);
431 end if;
433 Check_Package_Naming (Project, In_Tree, Data);
435 Extending := Data.Extends /= No_Project;
437 Check_Naming_Scheme (Data, Project, In_Tree);
439 Prepare_Ada_Naming_Exceptions
440 (Data.Naming.Bodies, In_Tree, Body_Part);
441 Prepare_Ada_Naming_Exceptions
442 (Data.Naming.Specs, In_Tree, Specification);
444 -- Find the sources
446 if Data.Source_Dirs /= Nil_String then
447 Look_For_Sources (Project, In_Tree, Data, Follow_Links);
448 end if;
450 if Data.Ada_Sources_Present then
452 -- Check that all individual naming conventions apply to sources of
453 -- this project file.
455 Warn_If_Not_Sources
456 (Project, In_Tree, Data.Naming.Bodies,
457 Specs => False,
458 Extending => Extending);
459 Warn_If_Not_Sources
460 (Project, In_Tree, Data.Naming.Specs,
461 Specs => True,
462 Extending => Extending);
463 end if;
465 -- If it is a library project file, check if it is a standalone library
467 if Data.Library then
468 Check_Stand_Alone_Library (Project, In_Tree, Data, Extending);
469 end if;
471 -- Put the list of Mains, if any, in the project data
473 Get_Mains (Project, In_Tree, Data);
475 -- Update the project data in the Projects table
477 In_Tree.Projects.Table (Project) := Data;
479 Free_Ada_Naming_Exceptions;
480 end Check;
482 --------------------
483 -- Check_Ada_Name --
484 --------------------
486 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
487 The_Name : String := Name;
488 Real_Name : Name_Id;
489 Need_Letter : Boolean := True;
490 Last_Underscore : Boolean := False;
491 OK : Boolean := The_Name'Length > 0;
493 begin
494 To_Lower (The_Name);
496 Name_Len := The_Name'Length;
497 Name_Buffer (1 .. Name_Len) := The_Name;
498 Real_Name := Name_Find;
500 -- Check first that the given name is not an Ada reserved word
502 if Get_Name_Table_Byte (Real_Name) /= 0
503 and then Real_Name /= Name_Project
504 and then Real_Name /= Name_Extends
505 and then Real_Name /= Name_External
506 then
507 Unit := No_Name;
509 if Current_Verbosity = High then
510 Write_Str (The_Name);
511 Write_Line (" is an Ada reserved word.");
512 end if;
514 return;
515 end if;
517 for Index in The_Name'Range loop
518 if Need_Letter then
520 -- We need a letter (at the beginning, and following a dot),
521 -- but we don't have one.
523 if Is_Letter (The_Name (Index)) then
524 Need_Letter := False;
526 else
527 OK := False;
529 if Current_Verbosity = High then
530 Write_Int (Types.Int (Index));
531 Write_Str (": '");
532 Write_Char (The_Name (Index));
533 Write_Line ("' is not a letter.");
534 end if;
536 exit;
537 end if;
539 elsif Last_Underscore
540 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
541 then
542 -- Two underscores are illegal, and a dot cannot follow
543 -- an underscore.
545 OK := False;
547 if Current_Verbosity = High then
548 Write_Int (Types.Int (Index));
549 Write_Str (": '");
550 Write_Char (The_Name (Index));
551 Write_Line ("' is illegal here.");
552 end if;
554 exit;
556 elsif The_Name (Index) = '.' then
558 -- We need a letter after a dot
560 Need_Letter := True;
562 elsif The_Name (Index) = '_' then
563 Last_Underscore := True;
565 else
566 -- We need an letter or a digit
568 Last_Underscore := False;
570 if not Is_Alphanumeric (The_Name (Index)) then
571 OK := False;
573 if Current_Verbosity = High then
574 Write_Int (Types.Int (Index));
575 Write_Str (": '");
576 Write_Char (The_Name (Index));
577 Write_Line ("' is not alphanumeric.");
578 end if;
580 exit;
581 end if;
582 end if;
583 end loop;
585 -- Cannot end with an underscore or a dot
587 OK := OK and then not Need_Letter and then not Last_Underscore;
589 if OK then
590 Unit := Real_Name;
592 else
593 -- Signal a problem with No_Name
595 Unit := No_Name;
596 end if;
597 end Check_Ada_Name;
599 --------------------------------------
600 -- Check_Ada_Naming_Scheme_Validity --
601 --------------------------------------
603 procedure Check_Ada_Naming_Scheme_Validity
604 (Project : Project_Id;
605 In_Tree : Project_Tree_Ref;
606 Naming : Naming_Data)
608 begin
609 -- Only check if we are not using the Default naming scheme
611 if Naming /= In_Tree.Private_Part.Default_Naming then
612 declare
613 Dot_Replacement : constant String :=
614 Get_Name_String
615 (Naming.Dot_Replacement);
617 Spec_Suffix : constant String :=
618 Get_Name_String
619 (Naming.Ada_Spec_Suffix);
621 Body_Suffix : constant String :=
622 Get_Name_String
623 (Naming.Ada_Body_Suffix);
625 Separate_Suffix : constant String :=
626 Get_Name_String
627 (Naming.Separate_Suffix);
629 begin
630 -- Dot_Replacement cannot
631 -- - be empty
632 -- - start or end with an alphanumeric
633 -- - be a single '_'
634 -- - start with an '_' followed by an alphanumeric
635 -- - contain a '.' except if it is "."
637 if Dot_Replacement'Length = 0
638 or else Is_Alphanumeric
639 (Dot_Replacement (Dot_Replacement'First))
640 or else Is_Alphanumeric
641 (Dot_Replacement (Dot_Replacement'Last))
642 or else (Dot_Replacement (Dot_Replacement'First) = '_'
643 and then
644 (Dot_Replacement'Length = 1
645 or else
646 Is_Alphanumeric
647 (Dot_Replacement (Dot_Replacement'First + 1))))
648 or else (Dot_Replacement'Length > 1
649 and then
650 Index (Source => Dot_Replacement,
651 Pattern => ".") /= 0)
652 then
653 Error_Msg
654 (Project, In_Tree,
655 '"' & Dot_Replacement &
656 """ is illegal for Dot_Replacement.",
657 Naming.Dot_Repl_Loc);
658 end if;
660 -- Suffixes cannot
661 -- - be empty
663 if Is_Illegal_Suffix
664 (Spec_Suffix, Dot_Replacement = ".")
665 then
666 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Spec_Suffix;
667 Error_Msg
668 (Project, In_Tree,
669 "{ is illegal for Spec_Suffix",
670 Naming.Spec_Suffix_Loc);
671 end if;
673 if Is_Illegal_Suffix
674 (Body_Suffix, Dot_Replacement = ".")
675 then
676 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Body_Suffix;
677 Error_Msg
678 (Project, In_Tree,
679 "{ is illegal for Body_Suffix",
680 Naming.Body_Suffix_Loc);
681 end if;
683 if Body_Suffix /= Separate_Suffix then
684 if Is_Illegal_Suffix
685 (Separate_Suffix, Dot_Replacement = ".")
686 then
687 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
688 Error_Msg
689 (Project, In_Tree,
690 "{ is illegal for Separate_Suffix",
691 Naming.Sep_Suffix_Loc);
692 end if;
693 end if;
695 -- Spec_Suffix cannot have the same termination as
696 -- Body_Suffix or Separate_Suffix
698 if Spec_Suffix'Length <= Body_Suffix'Length
699 and then
700 Body_Suffix (Body_Suffix'Last -
701 Spec_Suffix'Length + 1 ..
702 Body_Suffix'Last) = Spec_Suffix
703 then
704 Error_Msg
705 (Project, In_Tree,
706 "Body_Suffix (""" &
707 Body_Suffix &
708 """) cannot end with" &
709 " Spec_Suffix (""" &
710 Spec_Suffix & """).",
711 Naming.Body_Suffix_Loc);
712 end if;
714 if Body_Suffix /= Separate_Suffix
715 and then Spec_Suffix'Length <= Separate_Suffix'Length
716 and then
717 Separate_Suffix
718 (Separate_Suffix'Last - Spec_Suffix'Length + 1
720 Separate_Suffix'Last) = Spec_Suffix
721 then
722 Error_Msg
723 (Project, In_Tree,
724 "Separate_Suffix (""" &
725 Separate_Suffix &
726 """) cannot end with" &
727 " Spec_Suffix (""" &
728 Spec_Suffix & """).",
729 Naming.Sep_Suffix_Loc);
730 end if;
731 end;
732 end if;
733 end Check_Ada_Naming_Scheme_Validity;
735 ----------------------
736 -- Check_For_Source --
737 ----------------------
739 procedure Check_For_Source
740 (File_Name : Name_Id;
741 Path_Name : Name_Id;
742 Project : Project_Id;
743 In_Tree : Project_Tree_Ref;
744 Data : in out Project_Data;
745 Location : Source_Ptr;
746 Language : Language_Index;
747 Suffix : String;
748 Naming_Exception : Boolean)
750 Name : String := Get_Name_String (File_Name);
751 Real_Location : Source_Ptr := Location;
753 begin
754 Canonical_Case_File_Name (Name);
756 -- A file is a source of a language if Naming_Exception is True (case
757 -- of naming exceptions) or if its file name ends with the suffix.
759 if Naming_Exception or else
760 (Name'Length > Suffix'Length and then
761 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
762 then
763 if Real_Location = No_Location then
764 Real_Location := Data.Location;
765 end if;
767 declare
768 Path : String := Get_Name_String (Path_Name);
770 Path_Id : Name_Id;
771 -- The path name id (in canonical case)
773 File_Id : Name_Id;
774 -- The file name id (in canonical case)
776 Obj_Id : Name_Id;
777 -- The object file name
779 Obj_Path_Id : Name_Id;
780 -- The object path name
782 Dep_Id : Name_Id;
783 -- The dependency file name
785 Dep_Path_Id : Name_Id;
786 -- The dependency path name
788 Dot_Pos : Natural := 0;
789 -- Position of the last dot in Name
791 Source : Other_Source;
792 Source_Id : Other_Source_Id := Data.First_Other_Source;
794 begin
795 Canonical_Case_File_Name (Path);
797 -- Get the file name id
799 Name_Len := Name'Length;
800 Name_Buffer (1 .. Name_Len) := Name;
801 File_Id := Name_Find;
803 -- Get the path name id
805 Name_Len := Path'Length;
806 Name_Buffer (1 .. Name_Len) := Path;
807 Path_Id := Name_Find;
809 -- Find the position of the last dot
811 for J in reverse Name'Range loop
812 if Name (J) = '.' then
813 Dot_Pos := J;
814 exit;
815 end if;
816 end loop;
818 if Dot_Pos <= Name'First then
819 Dot_Pos := Name'Last + 1;
820 end if;
822 -- Compute the object file name
824 Get_Name_String (File_Id);
825 Name_Len := Dot_Pos - Name'First;
827 for J in Object_Suffix'Range loop
828 Name_Len := Name_Len + 1;
829 Name_Buffer (Name_Len) := Object_Suffix (J);
830 end loop;
832 Obj_Id := Name_Find;
834 -- Compute the object path name
836 Get_Name_String (Data.Object_Directory);
838 if Name_Buffer (Name_Len) /= Directory_Separator and then
839 Name_Buffer (Name_Len) /= '/'
840 then
841 Name_Len := Name_Len + 1;
842 Name_Buffer (Name_Len) := Directory_Separator;
843 end if;
845 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
846 Obj_Path_Id := Name_Find;
848 -- Compute the dependency file name
850 Get_Name_String (File_Id);
851 Name_Len := Dot_Pos - Name'First + 1;
852 Name_Buffer (Name_Len) := '.';
853 Name_Len := Name_Len + 1;
854 Name_Buffer (Name_Len) := 'd';
855 Dep_Id := Name_Find;
857 -- Compute the dependency path name
859 Get_Name_String (Data.Object_Directory);
861 if Name_Buffer (Name_Len) /= Directory_Separator and then
862 Name_Buffer (Name_Len) /= '/'
863 then
864 Name_Len := Name_Len + 1;
865 Name_Buffer (Name_Len) := Directory_Separator;
866 end if;
868 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
869 Dep_Path_Id := Name_Find;
871 -- Check if source is already in the list of source for this
872 -- project: it may have already been specified as a naming
873 -- exception for the same language or an other language, or
874 -- they may be two identical file names in different source
875 -- directories.
877 while Source_Id /= No_Other_Source loop
878 Source := In_Tree.Other_Sources.Table (Source_Id);
879 Source_Id := Source.Next;
881 if Source.File_Name = File_Id then
883 -- Two sources of different languages cannot have the same
884 -- file name.
886 if Source.Language /= Language then
887 Error_Msg_Name_1 := File_Name;
888 Error_Msg
889 (Project, In_Tree,
890 "{ cannot be a source of several languages",
891 Real_Location);
892 return;
894 -- No problem if a file has already been specified as
895 -- a naming exception of this language.
897 elsif Source.Path_Name = Path_Id then
899 -- Reset the naming exception flag, if this is not a
900 -- naming exception.
902 if not Naming_Exception then
903 In_Tree.Other_Sources.Table
904 (Source_Id).Naming_Exception := False;
905 end if;
907 return;
909 -- There are several files with the same names, but the
910 -- order of the source directories is known (no /**):
911 -- only the first one encountered is kept, the other ones
912 -- are ignored.
914 elsif Data.Known_Order_Of_Source_Dirs then
915 return;
917 -- But it is an error if the order of the source directories
918 -- is not known.
920 else
921 Error_Msg_Name_1 := File_Name;
922 Error_Msg
923 (Project, In_Tree,
924 "{ is found in several source directories",
925 Real_Location);
926 return;
927 end if;
929 -- Two sources with different file names cannot have the same
930 -- object file name.
932 elsif Source.Object_Name = Obj_Id then
933 Error_Msg_Name_1 := File_Id;
934 Error_Msg_Name_2 := Source.File_Name;
935 Error_Msg_Name_3 := Obj_Id;
936 Error_Msg
937 (Project, In_Tree,
938 "{ and { have the same object file {",
939 Real_Location);
940 return;
941 end if;
942 end loop;
944 if Current_Verbosity = High then
945 Write_Str (" found ");
946 Display_Language_Name (Language);
947 Write_Str (" source """);
948 Write_Str (Get_Name_String (File_Name));
949 Write_Line ("""");
950 Write_Str (" object path = ");
951 Write_Line (Get_Name_String (Obj_Path_Id));
952 end if;
954 -- Create the Other_Source record
956 Source :=
957 (Language => Language,
958 File_Name => File_Id,
959 Path_Name => Path_Id,
960 Source_TS => File_Stamp (Path_Id),
961 Object_Name => Obj_Id,
962 Object_Path => Obj_Path_Id,
963 Object_TS => File_Stamp (Obj_Path_Id),
964 Dep_Name => Dep_Id,
965 Dep_Path => Dep_Path_Id,
966 Dep_TS => File_Stamp (Dep_Path_Id),
967 Naming_Exception => Naming_Exception,
968 Next => No_Other_Source);
970 -- And add it to the Other_Sources table
972 Other_Source_Table.Increment_Last
973 (In_Tree.Other_Sources);
974 In_Tree.Other_Sources.Table
975 (Other_Source_Table.Last (In_Tree.Other_Sources)) :=
976 Source;
978 -- There are sources of languages other than Ada in this project
980 Data.Other_Sources_Present := True;
982 -- And there are sources of this language in this project
984 Set (Language, True, Data, In_Tree);
986 -- Add this source to the list of sources of languages other than
987 -- Ada of the project.
989 if Data.First_Other_Source = No_Other_Source then
990 Data.First_Other_Source :=
991 Other_Source_Table.Last (In_Tree.Other_Sources);
993 else
994 In_Tree.Other_Sources.Table (Data.Last_Other_Source).Next :=
995 Other_Source_Table.Last (In_Tree.Other_Sources);
996 end if;
998 Data.Last_Other_Source :=
999 Other_Source_Table.Last (In_Tree.Other_Sources);
1000 end;
1001 end if;
1002 end Check_For_Source;
1004 -------------------------------
1005 -- Check_If_Externally_Built --
1006 -------------------------------
1008 procedure Check_If_Externally_Built
1009 (Project : Project_Id;
1010 In_Tree : Project_Tree_Ref;
1011 Data : in out Project_Data)
1013 Externally_Built : constant Variable_Value :=
1014 Util.Value_Of
1015 (Name_Externally_Built,
1016 Data.Decl.Attributes, In_Tree);
1018 begin
1019 if not Externally_Built.Default then
1020 Get_Name_String (Externally_Built.Value);
1021 To_Lower (Name_Buffer (1 .. Name_Len));
1023 if Name_Buffer (1 .. Name_Len) = "true" then
1024 Data.Externally_Built := True;
1026 elsif Name_Buffer (1 .. Name_Len) /= "false" then
1027 Error_Msg (Project, In_Tree,
1028 "Externally_Built may only be true or false",
1029 Externally_Built.Location);
1030 end if;
1031 end if;
1033 if Current_Verbosity = High then
1034 Write_Str ("Project is ");
1036 if not Data.Externally_Built then
1037 Write_Str ("not ");
1038 end if;
1040 Write_Line ("externally built.");
1041 end if;
1042 end Check_If_Externally_Built;
1044 -----------------------------
1045 -- Check_Naming_Scheme --
1046 -----------------------------
1048 procedure Check_Naming_Scheme
1049 (Data : in out Project_Data;
1050 Project : Project_Id;
1051 In_Tree : Project_Tree_Ref)
1053 Naming_Id : constant Package_Id :=
1054 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
1056 Naming : Package_Element;
1058 procedure Check_Unit_Names (List : Array_Element_Id);
1059 -- Check that a list of unit names contains only valid names
1061 ----------------------
1062 -- Check_Unit_Names --
1063 ----------------------
1065 procedure Check_Unit_Names (List : Array_Element_Id) is
1066 Current : Array_Element_Id := List;
1067 Element : Array_Element;
1068 Unit_Name : Name_Id;
1070 begin
1071 -- Loop through elements of the string list
1073 while Current /= No_Array_Element loop
1074 Element := In_Tree.Array_Elements.Table (Current);
1076 -- Put file name in canonical case
1078 Get_Name_String (Element.Value.Value);
1079 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1080 Element.Value.Value := Name_Find;
1082 -- Check that it contains a valid unit name
1084 Get_Name_String (Element.Index);
1085 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1087 if Unit_Name = No_Name then
1088 Err_Vars.Error_Msg_Name_1 := Element.Index;
1089 Error_Msg
1090 (Project, In_Tree,
1091 "{ is not a valid unit name.",
1092 Element.Value.Location);
1094 else
1095 if Current_Verbosity = High then
1096 Write_Str (" Unit (""");
1097 Write_Str (Get_Name_String (Unit_Name));
1098 Write_Line (""")");
1099 end if;
1101 Element.Index := Unit_Name;
1102 In_Tree.Array_Elements.Table (Current) := Element;
1103 end if;
1105 Current := Element.Next;
1106 end loop;
1107 end Check_Unit_Names;
1109 -- Start of processing for Check_Naming_Scheme
1111 begin
1112 -- If there is a package Naming, we will put in Data.Naming what is in
1113 -- this package Naming.
1115 if Naming_Id /= No_Package then
1116 Naming := In_Tree.Packages.Table (Naming_Id);
1118 if Current_Verbosity = High then
1119 Write_Line ("Checking ""Naming"" for Ada.");
1120 end if;
1122 declare
1123 Bodies : constant Array_Element_Id :=
1124 Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
1126 Specs : constant Array_Element_Id :=
1127 Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
1129 begin
1130 if Bodies /= No_Array_Element then
1132 -- We have elements in the array Body_Part
1134 if Current_Verbosity = High then
1135 Write_Line ("Found Bodies.");
1136 end if;
1138 Data.Naming.Bodies := Bodies;
1139 Check_Unit_Names (Bodies);
1141 else
1142 if Current_Verbosity = High then
1143 Write_Line ("No Bodies.");
1144 end if;
1145 end if;
1147 if Specs /= No_Array_Element then
1149 -- We have elements in the array Specs
1151 if Current_Verbosity = High then
1152 Write_Line ("Found Specs.");
1153 end if;
1155 Data.Naming.Specs := Specs;
1156 Check_Unit_Names (Specs);
1158 else
1159 if Current_Verbosity = High then
1160 Write_Line ("No Specs.");
1161 end if;
1162 end if;
1163 end;
1165 -- We are now checking if variables Dot_Replacement, Casing,
1166 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1167 -- exist.
1169 -- For each variable, if it does not exist, we do nothing,
1170 -- because we already have the default.
1172 -- Check Dot_Replacement
1174 declare
1175 Dot_Replacement : constant Variable_Value :=
1176 Util.Value_Of
1177 (Name_Dot_Replacement,
1178 Naming.Decl.Attributes, In_Tree);
1180 begin
1181 pragma Assert (Dot_Replacement.Kind = Single,
1182 "Dot_Replacement is not a single string");
1184 if not Dot_Replacement.Default then
1185 Get_Name_String (Dot_Replacement.Value);
1187 if Name_Len = 0 then
1188 Error_Msg
1189 (Project, In_Tree,
1190 "Dot_Replacement cannot be empty",
1191 Dot_Replacement.Location);
1193 else
1194 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1195 Data.Naming.Dot_Replacement := Name_Find;
1196 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
1197 end if;
1198 end if;
1199 end;
1201 if Current_Verbosity = High then
1202 Write_Str (" Dot_Replacement = """);
1203 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
1204 Write_Char ('"');
1205 Write_Eol;
1206 end if;
1208 -- Check Casing
1210 declare
1211 Casing_String : constant Variable_Value :=
1212 Util.Value_Of
1213 (Name_Casing, Naming.Decl.Attributes, In_Tree);
1215 begin
1216 pragma Assert (Casing_String.Kind = Single,
1217 "Casing is not a single string");
1219 if not Casing_String.Default then
1220 declare
1221 Casing_Image : constant String :=
1222 Get_Name_String (Casing_String.Value);
1223 begin
1224 declare
1225 Casing_Value : constant Casing_Type :=
1226 Value (Casing_Image);
1227 begin
1228 Data.Naming.Casing := Casing_Value;
1229 end;
1231 exception
1232 when Constraint_Error =>
1233 if Casing_Image'Length = 0 then
1234 Error_Msg
1235 (Project, In_Tree,
1236 "Casing cannot be an empty string",
1237 Casing_String.Location);
1239 else
1240 Name_Len := Casing_Image'Length;
1241 Name_Buffer (1 .. Name_Len) := Casing_Image;
1242 Err_Vars.Error_Msg_Name_1 := Name_Find;
1243 Error_Msg
1244 (Project, In_Tree,
1245 "{ is not a correct Casing",
1246 Casing_String.Location);
1247 end if;
1248 end;
1249 end if;
1250 end;
1252 if Current_Verbosity = High then
1253 Write_Str (" Casing = ");
1254 Write_Str (Image (Data.Naming.Casing));
1255 Write_Char ('.');
1256 Write_Eol;
1257 end if;
1259 -- Check Spec_Suffix
1261 declare
1262 Ada_Spec_Suffix : constant Variable_Value :=
1263 Prj.Util.Value_Of
1264 (Index => Name_Ada,
1265 Src_Index => 0,
1266 In_Array => Data.Naming.Spec_Suffix,
1267 In_Tree => In_Tree);
1269 begin
1270 if Ada_Spec_Suffix.Kind = Single
1271 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
1272 then
1273 Get_Name_String (Ada_Spec_Suffix.Value);
1274 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1275 Data.Naming.Ada_Spec_Suffix := Name_Find;
1276 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
1278 else
1279 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1280 end if;
1281 end;
1283 if Current_Verbosity = High then
1284 Write_Str (" Spec_Suffix = """);
1285 Write_Str (Get_Name_String (Data.Naming.Ada_Spec_Suffix));
1286 Write_Char ('"');
1287 Write_Eol;
1288 end if;
1290 -- Check Body_Suffix
1292 declare
1293 Ada_Body_Suffix : constant Variable_Value :=
1294 Prj.Util.Value_Of
1295 (Index => Name_Ada,
1296 Src_Index => 0,
1297 In_Array => Data.Naming.Body_Suffix,
1298 In_Tree => In_Tree);
1300 begin
1301 if Ada_Body_Suffix.Kind = Single
1302 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
1303 then
1304 Get_Name_String (Ada_Body_Suffix.Value);
1305 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1306 Data.Naming.Ada_Body_Suffix := Name_Find;
1307 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
1309 else
1310 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1311 end if;
1312 end;
1314 if Current_Verbosity = High then
1315 Write_Str (" Body_Suffix = """);
1316 Write_Str (Get_Name_String (Data.Naming.Ada_Body_Suffix));
1317 Write_Char ('"');
1318 Write_Eol;
1319 end if;
1321 -- Check Separate_Suffix
1323 declare
1324 Ada_Sep_Suffix : constant Variable_Value :=
1325 Prj.Util.Value_Of
1326 (Variable_Name => Name_Separate_Suffix,
1327 In_Variables => Naming.Decl.Attributes,
1328 In_Tree => In_Tree);
1330 begin
1331 if Ada_Sep_Suffix.Default then
1332 Data.Naming.Separate_Suffix :=
1333 Data.Naming.Ada_Body_Suffix;
1335 else
1336 Get_Name_String (Ada_Sep_Suffix.Value);
1338 if Name_Len = 0 then
1339 Error_Msg
1340 (Project, In_Tree,
1341 "Separate_Suffix cannot be empty",
1342 Ada_Sep_Suffix.Location);
1344 else
1345 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1346 Data.Naming.Separate_Suffix := Name_Find;
1347 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
1348 end if;
1349 end if;
1350 end;
1352 if Current_Verbosity = High then
1353 Write_Str (" Separate_Suffix = """);
1354 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
1355 Write_Char ('"');
1356 Write_Eol;
1357 end if;
1359 -- Check if Data.Naming is valid
1361 Check_Ada_Naming_Scheme_Validity (Project, In_Tree, Data.Naming);
1363 else
1364 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1365 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1366 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
1367 end if;
1368 end Check_Naming_Scheme;
1370 ------------------------------
1371 -- Check_Library_Attributes --
1372 ------------------------------
1374 procedure Check_Library_Attributes
1375 (Project : Project_Id;
1376 In_Tree : Project_Tree_Ref;
1377 Data : in out Project_Data)
1379 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
1381 Lib_Dir : constant Prj.Variable_Value :=
1382 Prj.Util.Value_Of
1383 (Snames.Name_Library_Dir, Attributes, In_Tree);
1385 Lib_Name : constant Prj.Variable_Value :=
1386 Prj.Util.Value_Of
1387 (Snames.Name_Library_Name, Attributes, In_Tree);
1389 Lib_Version : constant Prj.Variable_Value :=
1390 Prj.Util.Value_Of
1391 (Snames.Name_Library_Version, Attributes, In_Tree);
1393 The_Lib_Kind : constant Prj.Variable_Value :=
1394 Prj.Util.Value_Of
1395 (Snames.Name_Library_Kind, Attributes, In_Tree);
1397 begin
1398 -- Special case of extending project
1400 if Data.Extends /= No_Project then
1401 declare
1402 Extended_Data : constant Project_Data :=
1403 In_Tree.Projects.Table (Data.Extends);
1405 begin
1406 -- If the project extended is a library project, we inherit
1407 -- the library name, if it is not redefined; we check that
1408 -- the library directory is specified; and we reset the
1409 -- library flag for the extended project.
1411 if Extended_Data.Library then
1412 if Lib_Name.Default then
1413 Data.Library_Name := Extended_Data.Library_Name;
1414 end if;
1416 if Lib_Dir.Default then
1417 if not Data.Virtual then
1418 Error_Msg
1419 (Project, In_Tree,
1420 "a project extending a library project must " &
1421 "specify an attribute Library_Dir",
1422 Data.Location);
1423 end if;
1424 end if;
1426 In_Tree.Projects.Table (Data.Extends).Library :=
1427 False;
1428 end if;
1429 end;
1430 end if;
1432 pragma Assert (Lib_Dir.Kind = Single);
1434 if Lib_Dir.Value = Empty_String then
1435 if Current_Verbosity = High then
1436 Write_Line ("No library directory");
1437 end if;
1439 else
1440 -- Find path name, check that it is a directory
1442 Locate_Directory
1443 (Lib_Dir.Value, Data.Display_Directory,
1444 Data.Library_Dir, Data.Display_Library_Dir);
1446 if Data.Library_Dir = No_Name then
1448 -- Get the absolute name of the library directory that
1449 -- does not exist, to report an error.
1451 declare
1452 Dir_Name : constant String := Get_Name_String (Lib_Dir.Value);
1454 begin
1455 if Is_Absolute_Path (Dir_Name) then
1456 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
1458 else
1459 Get_Name_String (Data.Display_Directory);
1461 if Name_Buffer (Name_Len) /= Directory_Separator then
1462 Name_Len := Name_Len + 1;
1463 Name_Buffer (Name_Len) := Directory_Separator;
1464 end if;
1466 Name_Buffer
1467 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
1468 Dir_Name;
1469 Name_Len := Name_Len + Dir_Name'Length;
1470 Err_Vars.Error_Msg_Name_1 := Name_Find;
1471 end if;
1473 -- Report the error
1475 Error_Msg
1476 (Project, In_Tree,
1477 "library directory { does not exist",
1478 Lib_Dir.Location);
1479 end;
1481 -- The library directory cannot be the same as the Object directory
1483 elsif Data.Library_Dir = Data.Object_Directory then
1484 Error_Msg
1485 (Project, In_Tree,
1486 "library directory cannot be the same " &
1487 "as object directory",
1488 Lib_Dir.Location);
1489 Data.Library_Dir := No_Name;
1490 Data.Display_Library_Dir := No_Name;
1492 -- Display the Library directory in high verbosity
1494 else
1495 if Current_Verbosity = High then
1496 Write_Str ("Library directory =""");
1497 Write_Str (Get_Name_String (Data.Display_Library_Dir));
1498 Write_Line ("""");
1499 end if;
1500 end if;
1501 end if;
1503 pragma Assert (Lib_Name.Kind = Single);
1505 if Lib_Name.Value = Empty_String then
1506 if Current_Verbosity = High
1507 and then Data.Library_Name = No_Name
1508 then
1509 Write_Line ("No library name");
1510 end if;
1512 else
1513 -- There is no restriction on the syntax of library names
1515 Data.Library_Name := Lib_Name.Value;
1516 end if;
1518 if Data.Library_Name /= No_Name
1519 and then Current_Verbosity = High
1520 then
1521 Write_Str ("Library name = """);
1522 Write_Str (Get_Name_String (Data.Library_Name));
1523 Write_Line ("""");
1524 end if;
1526 Data.Library :=
1527 Data.Library_Dir /= No_Name
1528 and then
1529 Data.Library_Name /= No_Name;
1531 if Data.Library then
1532 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
1533 Error_Msg
1534 (Project, In_Tree,
1535 "?libraries are not supported on this platform",
1536 Lib_Name.Location);
1537 Data.Library := False;
1539 else
1540 pragma Assert (Lib_Version.Kind = Single);
1542 if Lib_Version.Value = Empty_String then
1543 if Current_Verbosity = High then
1544 Write_Line ("No library version specified");
1545 end if;
1547 else
1548 Data.Lib_Internal_Name := Lib_Version.Value;
1549 end if;
1551 pragma Assert (The_Lib_Kind.Kind = Single);
1553 if The_Lib_Kind.Value = Empty_String then
1554 if Current_Verbosity = High then
1555 Write_Line ("No library kind specified");
1556 end if;
1558 else
1559 Get_Name_String (The_Lib_Kind.Value);
1561 declare
1562 Kind_Name : constant String :=
1563 To_Lower (Name_Buffer (1 .. Name_Len));
1565 OK : Boolean := True;
1567 begin
1568 if Kind_Name = "static" then
1569 Data.Library_Kind := Static;
1571 elsif Kind_Name = "dynamic" then
1572 Data.Library_Kind := Dynamic;
1574 elsif Kind_Name = "relocatable" then
1575 Data.Library_Kind := Relocatable;
1577 else
1578 Error_Msg
1579 (Project, In_Tree,
1580 "illegal value for Library_Kind",
1581 The_Lib_Kind.Location);
1582 OK := False;
1583 end if;
1585 if Current_Verbosity = High and then OK then
1586 Write_Str ("Library kind = ");
1587 Write_Line (Kind_Name);
1588 end if;
1590 if Data.Library_Kind /= Static and then
1591 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
1592 then
1593 Error_Msg
1594 (Project, In_Tree,
1595 "only static libraries are supported " &
1596 "on this platform",
1597 The_Lib_Kind.Location);
1598 Data.Library := False;
1599 end if;
1600 end;
1601 end if;
1603 if Data.Library and then Current_Verbosity = High then
1604 Write_Line ("This is a library project file");
1605 end if;
1607 end if;
1608 end if;
1609 end Check_Library_Attributes;
1611 --------------------------
1612 -- Check_Package_Naming --
1613 --------------------------
1615 procedure Check_Package_Naming
1616 (Project : Project_Id;
1617 In_Tree : Project_Tree_Ref;
1618 Data : in out Project_Data)
1620 Naming_Id : constant Package_Id :=
1621 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
1623 Naming : Package_Element;
1625 begin
1626 -- If there is a package Naming, we will put in Data.Naming
1627 -- what is in this package Naming.
1629 if Naming_Id /= No_Package then
1630 Naming := In_Tree.Packages.Table (Naming_Id);
1632 if Current_Verbosity = High then
1633 Write_Line ("Checking ""Naming"".");
1634 end if;
1636 -- Check Spec_Suffix
1638 declare
1639 Spec_Suffixs : Array_Element_Id :=
1640 Util.Value_Of
1641 (Name_Spec_Suffix,
1642 Naming.Decl.Arrays,
1643 In_Tree);
1645 Suffix : Array_Element_Id;
1646 Element : Array_Element;
1647 Suffix2 : Array_Element_Id;
1649 begin
1650 -- If some suffixs have been specified, we make sure that
1651 -- for each language for which a default suffix has been
1652 -- specified, there is a suffix specified, either the one
1653 -- in the project file or if there were none, the default.
1655 if Spec_Suffixs /= No_Array_Element then
1656 Suffix := Data.Naming.Spec_Suffix;
1658 while Suffix /= No_Array_Element loop
1659 Element :=
1660 In_Tree.Array_Elements.Table (Suffix);
1661 Suffix2 := Spec_Suffixs;
1663 while Suffix2 /= No_Array_Element loop
1664 exit when In_Tree.Array_Elements.Table
1665 (Suffix2).Index = Element.Index;
1666 Suffix2 := In_Tree.Array_Elements.Table
1667 (Suffix2).Next;
1668 end loop;
1670 -- There is a registered default suffix, but no
1671 -- suffix specified in the project file.
1672 -- Add the default to the array.
1674 if Suffix2 = No_Array_Element then
1675 Array_Element_Table.Increment_Last
1676 (In_Tree.Array_Elements);
1677 In_Tree.Array_Elements.Table
1678 (Array_Element_Table.Last
1679 (In_Tree.Array_Elements)) :=
1680 (Index => Element.Index,
1681 Src_Index => Element.Src_Index,
1682 Index_Case_Sensitive => False,
1683 Value => Element.Value,
1684 Next => Spec_Suffixs);
1685 Spec_Suffixs := Array_Element_Table.Last
1686 (In_Tree.Array_Elements);
1687 end if;
1689 Suffix := Element.Next;
1690 end loop;
1692 -- Put the resulting array as the specification suffixs
1694 Data.Naming.Spec_Suffix := Spec_Suffixs;
1695 end if;
1696 end;
1698 declare
1699 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
1700 Element : Array_Element;
1702 begin
1703 while Current /= No_Array_Element loop
1704 Element := In_Tree.Array_Elements.Table (Current);
1705 Get_Name_String (Element.Value.Value);
1707 if Name_Len = 0 then
1708 Error_Msg
1709 (Project, In_Tree,
1710 "Spec_Suffix cannot be empty",
1711 Element.Value.Location);
1712 end if;
1714 In_Tree.Array_Elements.Table (Current) := Element;
1715 Current := Element.Next;
1716 end loop;
1717 end;
1719 -- Check Body_Suffix
1721 declare
1722 Impl_Suffixs : Array_Element_Id :=
1723 Util.Value_Of
1724 (Name_Body_Suffix,
1725 Naming.Decl.Arrays,
1726 In_Tree);
1728 Suffix : Array_Element_Id;
1729 Element : Array_Element;
1730 Suffix2 : Array_Element_Id;
1732 begin
1733 -- If some suffixes have been specified, we make sure that
1734 -- for each language for which a default suffix has been
1735 -- specified, there is a suffix specified, either the one
1736 -- in the project file or if there were noe, the default.
1738 if Impl_Suffixs /= No_Array_Element then
1739 Suffix := Data.Naming.Body_Suffix;
1741 while Suffix /= No_Array_Element loop
1742 Element :=
1743 In_Tree.Array_Elements.Table (Suffix);
1744 Suffix2 := Impl_Suffixs;
1746 while Suffix2 /= No_Array_Element loop
1747 exit when In_Tree.Array_Elements.Table
1748 (Suffix2).Index = Element.Index;
1749 Suffix2 := In_Tree.Array_Elements.Table
1750 (Suffix2).Next;
1751 end loop;
1753 -- There is a registered default suffix, but no suffix was
1754 -- specified in the project file. Add the default to the
1755 -- array.
1757 if Suffix2 = No_Array_Element then
1758 Array_Element_Table.Increment_Last
1759 (In_Tree.Array_Elements);
1760 In_Tree.Array_Elements.Table
1761 (Array_Element_Table.Last
1762 (In_Tree.Array_Elements)) :=
1763 (Index => Element.Index,
1764 Src_Index => Element.Src_Index,
1765 Index_Case_Sensitive => False,
1766 Value => Element.Value,
1767 Next => Impl_Suffixs);
1768 Impl_Suffixs := Array_Element_Table.Last
1769 (In_Tree.Array_Elements);
1770 end if;
1772 Suffix := Element.Next;
1773 end loop;
1775 -- Put the resulting array as the implementation suffixs
1777 Data.Naming.Body_Suffix := Impl_Suffixs;
1778 end if;
1779 end;
1781 declare
1782 Current : Array_Element_Id := Data.Naming.Body_Suffix;
1783 Element : Array_Element;
1785 begin
1786 while Current /= No_Array_Element loop
1787 Element := In_Tree.Array_Elements.Table (Current);
1788 Get_Name_String (Element.Value.Value);
1790 if Name_Len = 0 then
1791 Error_Msg
1792 (Project, In_Tree,
1793 "Body_Suffix cannot be empty",
1794 Element.Value.Location);
1795 end if;
1797 In_Tree.Array_Elements.Table (Current) := Element;
1798 Current := Element.Next;
1799 end loop;
1800 end;
1802 -- Get the exceptions, if any
1804 Data.Naming.Specification_Exceptions :=
1805 Util.Value_Of
1806 (Name_Specification_Exceptions,
1807 In_Arrays => Naming.Decl.Arrays,
1808 In_Tree => In_Tree);
1810 Data.Naming.Implementation_Exceptions :=
1811 Util.Value_Of
1812 (Name_Implementation_Exceptions,
1813 In_Arrays => Naming.Decl.Arrays,
1814 In_Tree => In_Tree);
1815 end if;
1816 end Check_Package_Naming;
1818 ---------------------------------
1819 -- Check_Programming_Languages --
1820 ---------------------------------
1822 procedure Check_Programming_Languages
1823 (In_Tree : Project_Tree_Ref;
1824 Data : in out Project_Data)
1826 Languages : Variable_Value := Nil_Variable_Value;
1828 begin
1829 Languages :=
1830 Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes, In_Tree);
1831 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
1832 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
1834 if Data.Source_Dirs /= Nil_String then
1836 -- Check if languages are specified in this project
1838 if Languages.Default then
1840 -- Attribute Languages is not specified. So, it defaults to
1841 -- a project of language Ada only.
1843 Data.Languages (Ada_Language_Index) := True;
1845 -- No sources of languages other than Ada
1847 Data.Other_Sources_Present := False;
1849 else
1850 declare
1851 Current : String_List_Id := Languages.Values;
1852 Element : String_Element;
1853 Lang_Name : Name_Id;
1854 Index : Language_Index;
1856 begin
1857 -- Assume that there is no language specified yet
1859 Data.Other_Sources_Present := False;
1860 Data.Ada_Sources_Present := False;
1862 -- Look through all the languages specified in attribute
1863 -- Languages, if any
1865 while Current /= Nil_String loop
1866 Element :=
1867 In_Tree.String_Elements.Table (Current);
1868 Get_Name_String (Element.Value);
1869 To_Lower (Name_Buffer (1 .. Name_Len));
1870 Lang_Name := Name_Find;
1871 Index := Language_Indexes.Get (Lang_Name);
1873 if Index = No_Language_Index then
1874 Add_Language_Name (Lang_Name);
1875 Index := Last_Language_Index;
1876 end if;
1878 Set (Index, True, Data, In_Tree);
1879 Set (Language_Processing => Default_Language_Processing_Data,
1880 For_Language => Index,
1881 In_Project => Data,
1882 In_Tree => In_Tree);
1884 if Index = Ada_Language_Index then
1885 Data.Ada_Sources_Present := True;
1887 else
1888 Data.Other_Sources_Present := True;
1889 end if;
1891 Current := Element.Next;
1892 end loop;
1893 end;
1894 end if;
1895 end if;
1896 end Check_Programming_Languages;
1898 -------------------
1899 -- Check_Project --
1900 -------------------
1902 function Check_Project
1903 (P : Project_Id;
1904 Root_Project : Project_Id;
1905 In_Tree : Project_Tree_Ref;
1906 Extending : Boolean) return Boolean
1908 begin
1909 if P = Root_Project then
1910 return True;
1912 elsif Extending then
1913 declare
1914 Data : Project_Data := In_Tree.Projects.Table (Root_Project);
1916 begin
1917 while Data.Extends /= No_Project loop
1918 if P = Data.Extends then
1919 return True;
1920 end if;
1922 Data := In_Tree.Projects.Table (Data.Extends);
1923 end loop;
1924 end;
1925 end if;
1927 return False;
1928 end Check_Project;
1930 -------------------------------
1931 -- Check_Stand_Alone_Library --
1932 -------------------------------
1934 procedure Check_Stand_Alone_Library
1935 (Project : Project_Id;
1936 In_Tree : Project_Tree_Ref;
1937 Data : in out Project_Data;
1938 Extending : Boolean)
1940 Lib_Interfaces : constant Prj.Variable_Value :=
1941 Prj.Util.Value_Of
1942 (Snames.Name_Library_Interface,
1943 Data.Decl.Attributes,
1944 In_Tree);
1946 Lib_Auto_Init : constant Prj.Variable_Value :=
1947 Prj.Util.Value_Of
1948 (Snames.Name_Library_Auto_Init,
1949 Data.Decl.Attributes,
1950 In_Tree);
1952 Lib_Src_Dir : constant Prj.Variable_Value :=
1953 Prj.Util.Value_Of
1954 (Snames.Name_Library_Src_Dir,
1955 Data.Decl.Attributes,
1956 In_Tree);
1958 Lib_Symbol_File : constant Prj.Variable_Value :=
1959 Prj.Util.Value_Of
1960 (Snames.Name_Library_Symbol_File,
1961 Data.Decl.Attributes,
1962 In_Tree);
1964 Lib_Symbol_Policy : constant Prj.Variable_Value :=
1965 Prj.Util.Value_Of
1966 (Snames.Name_Library_Symbol_Policy,
1967 Data.Decl.Attributes,
1968 In_Tree);
1970 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
1971 Prj.Util.Value_Of
1972 (Snames.Name_Library_Reference_Symbol_File,
1973 Data.Decl.Attributes,
1974 In_Tree);
1976 Auto_Init_Supported : constant Boolean :=
1977 MLib.Tgt.
1978 Standalone_Library_Auto_Init_Is_Supported;
1980 OK : Boolean := True;
1982 begin
1983 pragma Assert (Lib_Interfaces.Kind = List);
1985 -- It is a stand-alone library project file if attribute
1986 -- Library_Interface is defined.
1988 if not Lib_Interfaces.Default then
1989 SAL_Library : declare
1990 Interfaces : String_List_Id := Lib_Interfaces.Values;
1991 Interface_ALIs : String_List_Id := Nil_String;
1992 Unit : Name_Id;
1993 The_Unit_Id : Unit_Id;
1994 The_Unit_Data : Unit_Data;
1996 procedure Add_ALI_For (Source : Name_Id);
1997 -- Add an ALI file name to the list of Interface ALIs
1999 -----------------
2000 -- Add_ALI_For --
2001 -----------------
2003 procedure Add_ALI_For (Source : Name_Id) is
2004 begin
2005 Get_Name_String (Source);
2007 declare
2008 ALI : constant String :=
2009 ALI_File_Name (Name_Buffer (1 .. Name_Len));
2010 ALI_Name_Id : Name_Id;
2011 begin
2012 Name_Len := ALI'Length;
2013 Name_Buffer (1 .. Name_Len) := ALI;
2014 ALI_Name_Id := Name_Find;
2016 String_Element_Table.Increment_Last
2017 (In_Tree.String_Elements);
2018 In_Tree.String_Elements.Table
2019 (String_Element_Table.Last
2020 (In_Tree.String_Elements)) :=
2021 (Value => ALI_Name_Id,
2022 Index => 0,
2023 Display_Value => ALI_Name_Id,
2024 Location =>
2025 In_Tree.String_Elements.Table
2026 (Interfaces).Location,
2027 Flag => False,
2028 Next => Interface_ALIs);
2029 Interface_ALIs := String_Element_Table.Last
2030 (In_Tree.String_Elements);
2031 end;
2032 end Add_ALI_For;
2034 -- Start of processing for SAL_Library
2036 begin
2037 Data.Standalone_Library := True;
2039 -- Library_Interface cannot be an empty list
2041 if Interfaces = Nil_String then
2042 Error_Msg
2043 (Project, In_Tree,
2044 "Library_Interface cannot be an empty list",
2045 Lib_Interfaces.Location);
2046 end if;
2048 -- Process each unit name specified in the attribute
2049 -- Library_Interface.
2051 while Interfaces /= Nil_String loop
2052 Get_Name_String
2053 (In_Tree.String_Elements.Table
2054 (Interfaces).Value);
2055 To_Lower (Name_Buffer (1 .. Name_Len));
2057 if Name_Len = 0 then
2058 Error_Msg
2059 (Project, In_Tree,
2060 "an interface cannot be an empty string",
2061 In_Tree.String_Elements.Table
2062 (Interfaces).Location);
2064 else
2065 Unit := Name_Find;
2066 Error_Msg_Name_1 := Unit;
2067 The_Unit_Id :=
2068 Units_Htable.Get (In_Tree.Units_HT, Unit);
2070 if The_Unit_Id = No_Unit then
2071 Error_Msg
2072 (Project, In_Tree,
2073 "unknown unit {",
2074 In_Tree.String_Elements.Table
2075 (Interfaces).Location);
2077 else
2078 -- Check that the unit is part of the project
2080 The_Unit_Data :=
2081 In_Tree.Units.Table (The_Unit_Id);
2083 if The_Unit_Data.File_Names (Body_Part).Name /= No_Name
2084 and then The_Unit_Data.File_Names (Body_Part).Path /=
2085 Slash
2086 then
2087 if Check_Project
2088 (The_Unit_Data.File_Names (Body_Part).Project,
2089 Project, In_Tree, Extending)
2090 then
2091 -- There is a body for this unit.
2092 -- If there is no spec, we need to check
2093 -- that it is not a subunit.
2095 if The_Unit_Data.File_Names
2096 (Specification).Name = No_Name
2097 then
2098 declare
2099 Src_Ind : Source_File_Index;
2101 begin
2102 Src_Ind := Sinput.P.Load_Project_File
2103 (Get_Name_String
2104 (The_Unit_Data.File_Names
2105 (Body_Part).Path));
2107 if Sinput.P.Source_File_Is_Subunit
2108 (Src_Ind)
2109 then
2110 Error_Msg
2111 (Project, In_Tree,
2112 "{ is a subunit; " &
2113 "it cannot be an interface",
2114 In_Tree.
2115 String_Elements.Table
2116 (Interfaces).Location);
2117 end if;
2118 end;
2119 end if;
2121 -- The unit is not a subunit, so we add
2122 -- to the Interface ALIs the ALI file
2123 -- corresponding to the body.
2125 Add_ALI_For
2126 (The_Unit_Data.File_Names (Body_Part).Name);
2128 else
2129 Error_Msg
2130 (Project, In_Tree,
2131 "{ is not an unit of this project",
2132 In_Tree.String_Elements.Table
2133 (Interfaces).Location);
2134 end if;
2136 elsif The_Unit_Data.File_Names
2137 (Specification).Name /= No_Name
2138 and then The_Unit_Data.File_Names
2139 (Specification).Path /= Slash
2140 and then Check_Project
2141 (The_Unit_Data.File_Names
2142 (Specification).Project,
2143 Project, In_Tree, Extending)
2145 then
2146 -- The unit is part of the project, it has
2147 -- a spec, but no body. We add to the Interface
2148 -- ALIs the ALI file corresponding to the spec.
2150 Add_ALI_For
2151 (The_Unit_Data.File_Names (Specification).Name);
2153 else
2154 Error_Msg
2155 (Project, In_Tree,
2156 "{ is not an unit of this project",
2157 In_Tree.String_Elements.Table
2158 (Interfaces).Location);
2159 end if;
2160 end if;
2162 end if;
2164 Interfaces :=
2165 In_Tree.String_Elements.Table (Interfaces).Next;
2166 end loop;
2168 -- Put the list of Interface ALIs in the project data
2170 Data.Lib_Interface_ALIs := Interface_ALIs;
2172 -- Check value of attribute Library_Auto_Init and set
2173 -- Lib_Auto_Init accordingly.
2175 if Lib_Auto_Init.Default then
2177 -- If no attribute Library_Auto_Init is declared, then
2178 -- set auto init only if it is supported.
2180 Data.Lib_Auto_Init := Auto_Init_Supported;
2182 else
2183 Get_Name_String (Lib_Auto_Init.Value);
2184 To_Lower (Name_Buffer (1 .. Name_Len));
2186 if Name_Buffer (1 .. Name_Len) = "false" then
2187 Data.Lib_Auto_Init := False;
2189 elsif Name_Buffer (1 .. Name_Len) = "true" then
2190 if Auto_Init_Supported then
2191 Data.Lib_Auto_Init := True;
2193 else
2194 -- Library_Auto_Init cannot be "true" if auto init
2195 -- is not supported
2197 Error_Msg
2198 (Project, In_Tree,
2199 "library auto init not supported " &
2200 "on this platform",
2201 Lib_Auto_Init.Location);
2202 end if;
2204 else
2205 Error_Msg
2206 (Project, In_Tree,
2207 "invalid value for attribute Library_Auto_Init",
2208 Lib_Auto_Init.Location);
2209 end if;
2210 end if;
2211 end SAL_Library;
2213 -- If attribute Library_Src_Dir is defined and not the
2214 -- empty string, check if the directory exist and is not
2215 -- the object directory or one of the source directories.
2216 -- This is the directory where copies of the interface
2217 -- sources will be copied. Note that this directory may be
2218 -- the library directory.
2220 if Lib_Src_Dir.Value /= Empty_String then
2221 declare
2222 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
2224 begin
2225 Locate_Directory
2226 (Dir_Id, Data.Display_Directory,
2227 Data.Library_Src_Dir,
2228 Data.Display_Library_Src_Dir);
2230 -- If directory does not exist, report an error
2232 if Data.Library_Src_Dir = No_Name then
2234 -- Get the absolute name of the library directory
2235 -- that does not exist, to report an error.
2237 declare
2238 Dir_Name : constant String :=
2239 Get_Name_String (Dir_Id);
2241 begin
2242 if Is_Absolute_Path (Dir_Name) then
2243 Err_Vars.Error_Msg_Name_1 := Dir_Id;
2245 else
2246 Get_Name_String (Data.Directory);
2248 if Name_Buffer (Name_Len) /=
2249 Directory_Separator
2250 then
2251 Name_Len := Name_Len + 1;
2252 Name_Buffer (Name_Len) :=
2253 Directory_Separator;
2254 end if;
2256 Name_Buffer
2257 (Name_Len + 1 ..
2258 Name_Len + Dir_Name'Length) :=
2259 Dir_Name;
2260 Name_Len := Name_Len + Dir_Name'Length;
2261 Err_Vars.Error_Msg_Name_1 := Name_Find;
2262 end if;
2264 -- Report the error
2266 Error_Msg
2267 (Project, In_Tree,
2268 "Directory { does not exist",
2269 Lib_Src_Dir.Location);
2270 end;
2272 -- Report an error if it is the same as the object
2273 -- directory.
2275 elsif Data.Library_Src_Dir = Data.Object_Directory then
2276 Error_Msg
2277 (Project, In_Tree,
2278 "directory to copy interfaces cannot be " &
2279 "the object directory",
2280 Lib_Src_Dir.Location);
2281 Data.Library_Src_Dir := No_Name;
2283 -- Check if it is same as one of the source directories
2285 else
2286 declare
2287 Src_Dirs : String_List_Id := Data.Source_Dirs;
2288 Src_Dir : String_Element;
2290 begin
2291 while Src_Dirs /= Nil_String loop
2292 Src_Dir := In_Tree.String_Elements.Table
2293 (Src_Dirs);
2294 Src_Dirs := Src_Dir.Next;
2296 -- Report error if it is one of the source directories
2298 if Data.Library_Src_Dir = Src_Dir.Value then
2299 Error_Msg
2300 (Project, In_Tree,
2301 "directory to copy interfaces cannot " &
2302 "be one of the source directories",
2303 Lib_Src_Dir.Location);
2304 Data.Library_Src_Dir := No_Name;
2305 exit;
2306 end if;
2307 end loop;
2308 end;
2310 -- In high verbosity, if there is a valid Library_Src_Dir,
2311 -- display its path name.
2313 if Data.Library_Src_Dir /= No_Name
2314 and then Current_Verbosity = High
2315 then
2316 Write_Str ("Directory to copy interfaces =""");
2317 Write_Str (Get_Name_String (Data.Library_Src_Dir));
2318 Write_Line ("""");
2319 end if;
2320 end if;
2321 end;
2322 end if;
2324 -- Check the symbol related attributes
2326 -- First, the symbol policy
2328 if not Lib_Symbol_Policy.Default then
2329 declare
2330 Value : constant String :=
2331 To_Lower
2332 (Get_Name_String (Lib_Symbol_Policy.Value));
2334 begin
2335 -- Symbol policy must hove one of a limited number of values
2337 if Value = "autonomous" or else Value = "default" then
2338 Data.Symbol_Data.Symbol_Policy := Autonomous;
2340 elsif Value = "compliant" then
2341 Data.Symbol_Data.Symbol_Policy := Compliant;
2343 elsif Value = "controlled" then
2344 Data.Symbol_Data.Symbol_Policy := Controlled;
2346 elsif Value = "restricted" then
2347 Data.Symbol_Data.Symbol_Policy := Restricted;
2349 else
2350 Error_Msg
2351 (Project, In_Tree,
2352 "illegal value for Library_Symbol_Policy",
2353 Lib_Symbol_Policy.Location);
2354 end if;
2355 end;
2356 end if;
2358 -- If attribute Library_Symbol_File is not specified, symbol policy
2359 -- cannot be Restricted.
2361 if Lib_Symbol_File.Default then
2362 if Data.Symbol_Data.Symbol_Policy = Restricted then
2363 Error_Msg
2364 (Project, In_Tree,
2365 "Library_Symbol_File needs to be defined when " &
2366 "symbol policy is Restricted",
2367 Lib_Symbol_Policy.Location);
2368 end if;
2370 else
2371 -- Library_Symbol_File is defined. Check that the file exists.
2373 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
2375 Get_Name_String (Lib_Symbol_File.Value);
2377 if Name_Len = 0 then
2378 Error_Msg
2379 (Project, In_Tree,
2380 "symbol file name cannot be an empty string",
2381 Lib_Symbol_File.Location);
2383 else
2384 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2386 if OK then
2387 for J in 1 .. Name_Len loop
2388 if Name_Buffer (J) = '/'
2389 or else Name_Buffer (J) = Directory_Separator
2390 then
2391 OK := False;
2392 exit;
2393 end if;
2394 end loop;
2395 end if;
2397 if not OK then
2398 Error_Msg_Name_1 := Lib_Symbol_File.Value;
2399 Error_Msg
2400 (Project, In_Tree,
2401 "symbol file name { is illegal. " &
2402 "Name canot include directory info.",
2403 Lib_Symbol_File.Location);
2404 end if;
2405 end if;
2406 end if;
2408 -- If attribute Library_Reference_Symbol_File is not defined,
2409 -- symbol policy cannot be Compilant or Controlled.
2411 if Lib_Ref_Symbol_File.Default then
2412 if Data.Symbol_Data.Symbol_Policy = Compliant
2413 or else Data.Symbol_Data.Symbol_Policy = Controlled
2414 then
2415 Error_Msg
2416 (Project, In_Tree,
2417 "a reference symbol file need to be defined",
2418 Lib_Symbol_Policy.Location);
2419 end if;
2421 else
2422 -- Library_Reference_Symbol_File is defined, check file exists
2424 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
2426 Get_Name_String (Lib_Ref_Symbol_File.Value);
2428 if Name_Len = 0 then
2429 Error_Msg
2430 (Project, In_Tree,
2431 "reference symbol file name cannot be an empty string",
2432 Lib_Symbol_File.Location);
2434 else
2435 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2437 if OK then
2438 for J in 1 .. Name_Len loop
2439 if Name_Buffer (J) = '/'
2440 or else Name_Buffer (J) = Directory_Separator
2441 then
2442 OK := False;
2443 exit;
2444 end if;
2445 end loop;
2446 end if;
2448 if not OK then
2449 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2450 Error_Msg
2451 (Project, In_Tree,
2452 "reference symbol file { name is illegal. " &
2453 "Name canot include directory info.",
2454 Lib_Ref_Symbol_File.Location);
2455 end if;
2457 if not Is_Regular_File
2458 (Get_Name_String (Data.Object_Directory) &
2459 Directory_Separator &
2460 Get_Name_String (Lib_Ref_Symbol_File.Value))
2461 then
2462 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2463 Error_Msg
2464 (Project, In_Tree,
2465 "library reference symbol file { does not exist",
2466 Lib_Ref_Symbol_File.Location);
2467 end if;
2469 -- Check that the reference symbol file and the symbol file
2470 -- are not the same file.
2472 if Data.Symbol_Data.Symbol_File /= No_Name then
2473 declare
2474 Symbol : String :=
2475 Get_Name_String
2476 (Data.Symbol_Data.Symbol_File);
2478 Reference : String :=
2479 Get_Name_String
2480 (Data.Symbol_Data.Reference);
2482 begin
2483 Canonical_Case_File_Name (Symbol);
2484 Canonical_Case_File_Name (Reference);
2486 if Symbol = Reference then
2487 Error_Msg
2488 (Project, In_Tree,
2489 "reference symbol file and symbol file " &
2490 "cannot be the same file",
2491 Lib_Ref_Symbol_File.Location);
2492 end if;
2493 end;
2494 end if;
2495 end if;
2496 end if;
2497 end if;
2498 end Check_Stand_Alone_Library;
2500 ----------------------------
2501 -- Compute_Directory_Last --
2502 ----------------------------
2504 function Compute_Directory_Last (Dir : String) return Natural is
2505 begin
2506 if Dir'Length > 1
2507 and then (Dir (Dir'Last - 1) = Directory_Separator
2508 or else Dir (Dir'Last - 1) = '/')
2509 then
2510 return Dir'Last - 1;
2511 else
2512 return Dir'Last;
2513 end if;
2514 end Compute_Directory_Last;
2516 --------------------
2517 -- Body_Suffix_Of --
2518 --------------------
2520 function Body_Suffix_Of
2521 (Language : Language_Index;
2522 In_Project : Project_Data;
2523 In_Tree : Project_Tree_Ref) return String
2525 Suffix_Id : constant Name_Id :=
2526 Suffix_Of (Language, In_Project, In_Tree);
2527 begin
2528 if Suffix_Id /= No_Name then
2529 return Get_Name_String (Suffix_Id);
2530 else
2531 return "." & Get_Name_String (Language_Names.Table (Language));
2532 end if;
2533 end Body_Suffix_Of;
2535 ---------------
2536 -- Error_Msg --
2537 ---------------
2539 procedure Error_Msg
2540 (Project : Project_Id;
2541 In_Tree : Project_Tree_Ref;
2542 Msg : String;
2543 Flag_Location : Source_Ptr)
2545 Error_Buffer : String (1 .. 5_000);
2546 Error_Last : Natural := 0;
2547 Msg_Name : Natural := 0;
2548 First : Positive := Msg'First;
2550 procedure Add (C : Character);
2551 -- Add a character to the buffer
2553 procedure Add (S : String);
2554 -- Add a string to the buffer
2556 procedure Add (Id : Name_Id);
2557 -- Add a name to the buffer
2559 ---------
2560 -- Add --
2561 ---------
2563 procedure Add (C : Character) is
2564 begin
2565 Error_Last := Error_Last + 1;
2566 Error_Buffer (Error_Last) := C;
2567 end Add;
2569 procedure Add (S : String) is
2570 begin
2571 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2572 Error_Last := Error_Last + S'Length;
2573 end Add;
2575 procedure Add (Id : Name_Id) is
2576 begin
2577 Get_Name_String (Id);
2578 Add (Name_Buffer (1 .. Name_Len));
2579 end Add;
2581 -- Start of processing for Error_Msg
2583 begin
2584 if Error_Report = null then
2585 Prj.Err.Error_Msg (Msg, Flag_Location);
2586 return;
2587 end if;
2589 -- Ignore continuation character
2591 if Msg (First) = '\' then
2592 First := First + 1;
2594 -- Warniung character is always the first one in this package
2596 elsif Msg (First) = '?' then
2597 First := First + 1;
2598 Add ("Warning: ");
2599 end if;
2601 for Index in First .. Msg'Last loop
2602 if Msg (Index) = '{' or else Msg (Index) = '%' then
2604 -- Include a name between double quotes
2606 Msg_Name := Msg_Name + 1;
2607 Add ('"');
2609 case Msg_Name is
2610 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2611 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2612 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2614 when others => null;
2615 end case;
2617 Add ('"');
2619 else
2620 Add (Msg (Index));
2621 end if;
2623 end loop;
2625 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
2626 end Error_Msg;
2628 ------------------
2629 -- Find_Sources --
2630 ------------------
2632 procedure Find_Sources
2633 (Project : Project_Id;
2634 In_Tree : Project_Tree_Ref;
2635 Data : in out Project_Data;
2636 For_Language : Language_Index;
2637 Follow_Links : Boolean := False)
2639 Source_Dir : String_List_Id := Data.Source_Dirs;
2640 Element : String_Element;
2641 Dir : Dir_Type;
2642 Current_Source : String_List_Id := Nil_String;
2643 Source_Recorded : Boolean := False;
2645 begin
2646 if Current_Verbosity = High then
2647 Write_Line ("Looking for sources:");
2648 end if;
2650 -- For each subdirectory
2652 while Source_Dir /= Nil_String loop
2653 begin
2654 Source_Recorded := False;
2655 Element := In_Tree.String_Elements.Table (Source_Dir);
2656 if Element.Value /= No_Name then
2657 Get_Name_String (Element.Display_Value);
2659 declare
2660 Source_Directory : constant String :=
2661 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2662 Dir_Last : constant Natural :=
2663 Compute_Directory_Last (Source_Directory);
2665 begin
2666 if Current_Verbosity = High then
2667 Write_Str ("Source_Dir = ");
2668 Write_Line (Source_Directory);
2669 end if;
2671 -- We look to every entry in the source directory
2673 Open (Dir, Source_Directory
2674 (Source_Directory'First .. Dir_Last));
2676 loop
2677 Read (Dir, Name_Buffer, Name_Len);
2679 if Current_Verbosity = High then
2680 Write_Str (" Checking ");
2681 Write_Line (Name_Buffer (1 .. Name_Len));
2682 end if;
2684 exit when Name_Len = 0;
2686 declare
2687 File_Name : constant Name_Id := Name_Find;
2688 Path : constant String :=
2689 Normalize_Pathname
2690 (Name => Name_Buffer (1 .. Name_Len),
2691 Directory => Source_Directory
2692 (Source_Directory'First .. Dir_Last),
2693 Resolve_Links => Follow_Links,
2694 Case_Sensitive => True);
2695 Path_Name : Name_Id;
2697 begin
2698 Name_Len := Path'Length;
2699 Name_Buffer (1 .. Name_Len) := Path;
2700 Path_Name := Name_Find;
2702 if For_Language = Ada_Language_Index then
2704 -- We attempt to register it as a source. However,
2705 -- there is no error if the file does not contain
2706 -- a valid source. But there is an error if we have
2707 -- a duplicate unit name.
2709 Record_Ada_Source
2710 (File_Name => File_Name,
2711 Path_Name => Path_Name,
2712 Project => Project,
2713 In_Tree => In_Tree,
2714 Data => Data,
2715 Location => No_Location,
2716 Current_Source => Current_Source,
2717 Source_Recorded => Source_Recorded,
2718 Follow_Links => Follow_Links);
2720 else
2721 Check_For_Source
2722 (File_Name => File_Name,
2723 Path_Name => Path_Name,
2724 Project => Project,
2725 In_Tree => In_Tree,
2726 Data => Data,
2727 Location => No_Location,
2728 Language => For_Language,
2729 Suffix =>
2730 Body_Suffix_Of (For_Language, Data, In_Tree),
2731 Naming_Exception => False);
2732 end if;
2733 end;
2734 end loop;
2736 Close (Dir);
2737 end;
2738 end if;
2740 exception
2741 when Directory_Error =>
2742 null;
2743 end;
2745 if Source_Recorded then
2746 In_Tree.String_Elements.Table (Source_Dir).Flag :=
2747 True;
2748 end if;
2750 Source_Dir := Element.Next;
2751 end loop;
2753 if Current_Verbosity = High then
2754 Write_Line ("end Looking for sources.");
2755 end if;
2757 if For_Language = Ada_Language_Index then
2759 -- If we have looked for sources and found none, then
2760 -- it is an error, except if it is an extending project.
2761 -- If a non extending project is not supposed to contain
2762 -- any source, then we never call Find_Sources.
2764 if Current_Source /= Nil_String then
2765 Data.Ada_Sources_Present := True;
2767 elsif Data.Extends = No_Project then
2768 Error_Msg
2769 (Project, In_Tree,
2770 "there are no Ada sources in this project",
2771 Data.Location);
2772 end if;
2773 end if;
2774 end Find_Sources;
2776 --------------------------------
2777 -- Free_Ada_Naming_Exceptions --
2778 --------------------------------
2780 procedure Free_Ada_Naming_Exceptions is
2781 begin
2782 Ada_Naming_Exception_Table.Set_Last (0);
2783 Ada_Naming_Exceptions.Reset;
2784 Reverse_Ada_Naming_Exceptions.Reset;
2785 end Free_Ada_Naming_Exceptions;
2787 ---------------------
2788 -- Get_Directories --
2789 ---------------------
2791 procedure Get_Directories
2792 (Project : Project_Id;
2793 In_Tree : Project_Tree_Ref;
2794 Data : in out Project_Data)
2796 Object_Dir : constant Variable_Value :=
2797 Util.Value_Of
2798 (Name_Object_Dir, Data.Decl.Attributes, In_Tree);
2800 Exec_Dir : constant Variable_Value :=
2801 Util.Value_Of
2802 (Name_Exec_Dir, Data.Decl.Attributes, In_Tree);
2804 Source_Dirs : constant Variable_Value :=
2805 Util.Value_Of
2806 (Name_Source_Dirs, Data.Decl.Attributes, In_Tree);
2808 Last_Source_Dir : String_List_Id := Nil_String;
2810 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2811 -- Find one or several source directories, and add them
2812 -- to the list of source directories of the project.
2814 ----------------------
2815 -- Find_Source_Dirs --
2816 ----------------------
2818 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2819 Directory : constant String := Get_Name_String (From);
2820 Element : String_Element;
2822 procedure Recursive_Find_Dirs (Path : Name_Id);
2823 -- Find all the subdirectories (recursively) of Path and add them
2824 -- to the list of source directories of the project.
2826 -------------------------
2827 -- Recursive_Find_Dirs --
2828 -------------------------
2830 procedure Recursive_Find_Dirs (Path : Name_Id) is
2831 Dir : Dir_Type;
2832 Name : String (1 .. 250);
2833 Last : Natural;
2834 List : String_List_Id := Data.Source_Dirs;
2835 Element : String_Element;
2836 Found : Boolean := False;
2838 Non_Canonical_Path : Name_Id := No_Name;
2839 Canonical_Path : Name_Id := No_Name;
2841 The_Path : constant String :=
2842 Normalize_Pathname (Get_Name_String (Path)) &
2843 Directory_Separator;
2845 The_Path_Last : constant Natural :=
2846 Compute_Directory_Last (The_Path);
2848 begin
2849 Name_Len := The_Path_Last - The_Path'First + 1;
2850 Name_Buffer (1 .. Name_Len) :=
2851 The_Path (The_Path'First .. The_Path_Last);
2852 Non_Canonical_Path := Name_Find;
2853 Get_Name_String (Non_Canonical_Path);
2854 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2855 Canonical_Path := Name_Find;
2857 -- To avoid processing the same directory several times, check
2858 -- if the directory is already in Recursive_Dirs. If it is,
2859 -- then there is nothing to do, just return. If it is not, put
2860 -- it there and continue recursive processing.
2862 if Recursive_Dirs.Get (Canonical_Path) then
2863 return;
2865 else
2866 Recursive_Dirs.Set (Canonical_Path, True);
2867 end if;
2869 -- Check if directory is already in list
2871 while List /= Nil_String loop
2872 Element := In_Tree.String_Elements.Table (List);
2874 if Element.Value /= No_Name then
2875 Found := Element.Value = Canonical_Path;
2876 exit when Found;
2877 end if;
2879 List := Element.Next;
2880 end loop;
2882 -- If directory is not already in list, put it there
2884 if not Found then
2885 if Current_Verbosity = High then
2886 Write_Str (" ");
2887 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2888 end if;
2890 String_Element_Table.Increment_Last
2891 (In_Tree.String_Elements);
2892 Element :=
2893 (Value => Canonical_Path,
2894 Display_Value => Non_Canonical_Path,
2895 Location => No_Location,
2896 Flag => False,
2897 Next => Nil_String,
2898 Index => 0);
2900 -- Case of first source directory
2902 if Last_Source_Dir = Nil_String then
2903 Data.Source_Dirs := String_Element_Table.Last
2904 (In_Tree.String_Elements);
2906 -- Here we already have source directories
2908 else
2909 -- Link the previous last to the new one
2911 In_Tree.String_Elements.Table
2912 (Last_Source_Dir).Next :=
2913 String_Element_Table.Last
2914 (In_Tree.String_Elements);
2915 end if;
2917 -- And register this source directory as the new last
2919 Last_Source_Dir := String_Element_Table.Last
2920 (In_Tree.String_Elements);
2921 In_Tree.String_Elements.Table (Last_Source_Dir) :=
2922 Element;
2923 end if;
2925 -- Now look for subdirectories. We do that even when this
2926 -- directory is already in the list, because some of its
2927 -- subdirectories may not be in the list yet.
2929 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2931 loop
2932 Read (Dir, Name, Last);
2933 exit when Last = 0;
2935 if Name (1 .. Last) /= "."
2936 and then Name (1 .. Last) /= ".."
2937 then
2938 -- Avoid . and .. directories
2940 if Current_Verbosity = High then
2941 Write_Str (" Checking ");
2942 Write_Line (Name (1 .. Last));
2943 end if;
2945 declare
2946 Path_Name : constant String :=
2947 Normalize_Pathname
2948 (Name => Name (1 .. Last),
2949 Directory =>
2950 The_Path
2951 (The_Path'First .. The_Path_Last),
2952 Resolve_Links => False,
2953 Case_Sensitive => True);
2955 begin
2956 if Is_Directory (Path_Name) then
2958 -- We have found a new subdirectory, call self
2960 Name_Len := Path_Name'Length;
2961 Name_Buffer (1 .. Name_Len) := Path_Name;
2962 Recursive_Find_Dirs (Name_Find);
2963 end if;
2964 end;
2965 end if;
2966 end loop;
2968 Close (Dir);
2970 exception
2971 when Directory_Error =>
2972 null;
2973 end Recursive_Find_Dirs;
2975 -- Start of processing for Find_Source_Dirs
2977 begin
2978 if Current_Verbosity = High then
2979 Write_Str ("Find_Source_Dirs (""");
2980 Write_Str (Directory);
2981 Write_Line (""")");
2982 end if;
2984 -- First, check if we are looking for a directory tree,
2985 -- indicated by "/**" at the end.
2987 if Directory'Length >= 3
2988 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2989 and then (Directory (Directory'Last - 2) = '/'
2990 or else
2991 Directory (Directory'Last - 2) = Directory_Separator)
2992 then
2993 Data.Known_Order_Of_Source_Dirs := False;
2995 Name_Len := Directory'Length - 3;
2997 if Name_Len = 0 then
2999 -- This is the case of "/**": all directories
3000 -- in the file system.
3002 Name_Len := 1;
3003 Name_Buffer (1) := Directory (Directory'First);
3005 else
3006 Name_Buffer (1 .. Name_Len) :=
3007 Directory (Directory'First .. Directory'Last - 3);
3008 end if;
3010 if Current_Verbosity = High then
3011 Write_Str ("Looking for all subdirectories of """);
3012 Write_Str (Name_Buffer (1 .. Name_Len));
3013 Write_Line ("""");
3014 end if;
3016 declare
3017 Base_Dir : constant Name_Id := Name_Find;
3018 Root_Dir : constant String :=
3019 Normalize_Pathname
3020 (Name => Get_Name_String (Base_Dir),
3021 Directory =>
3022 Get_Name_String (Data.Display_Directory),
3023 Resolve_Links => False,
3024 Case_Sensitive => True);
3026 begin
3027 if Root_Dir'Length = 0 then
3028 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3030 if Location = No_Location then
3031 Error_Msg
3032 (Project, In_Tree,
3033 "{ is not a valid directory.",
3034 Data.Location);
3035 else
3036 Error_Msg
3037 (Project, In_Tree,
3038 "{ is not a valid directory.",
3039 Location);
3040 end if;
3042 else
3043 -- We have an existing directory, we register it and all
3044 -- of its subdirectories.
3046 if Current_Verbosity = High then
3047 Write_Line ("Looking for source directories:");
3048 end if;
3050 Name_Len := Root_Dir'Length;
3051 Name_Buffer (1 .. Name_Len) := Root_Dir;
3052 Recursive_Find_Dirs (Name_Find);
3054 if Current_Verbosity = High then
3055 Write_Line ("End of looking for source directories.");
3056 end if;
3057 end if;
3058 end;
3060 -- We have a single directory
3062 else
3063 declare
3064 Path_Name : Name_Id;
3065 Display_Path_Name : Name_Id;
3067 begin
3068 Locate_Directory
3069 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3071 if Path_Name = No_Name then
3072 Err_Vars.Error_Msg_Name_1 := From;
3074 if Location = No_Location then
3075 Error_Msg
3076 (Project, In_Tree,
3077 "{ is not a valid directory",
3078 Data.Location);
3079 else
3080 Error_Msg
3081 (Project, In_Tree,
3082 "{ is not a valid directory",
3083 Location);
3084 end if;
3086 else
3087 -- As it is an existing directory, we add it to
3088 -- the list of directories.
3090 String_Element_Table.Increment_Last
3091 (In_Tree.String_Elements);
3092 Element.Value := Path_Name;
3093 Element.Display_Value := Display_Path_Name;
3095 if Last_Source_Dir = Nil_String then
3097 -- This is the first source directory
3099 Data.Source_Dirs := String_Element_Table.Last
3100 (In_Tree.String_Elements);
3102 else
3103 -- We already have source directories,
3104 -- link the previous last to the new one.
3106 In_Tree.String_Elements.Table
3107 (Last_Source_Dir).Next :=
3108 String_Element_Table.Last
3109 (In_Tree.String_Elements);
3110 end if;
3112 -- And register this source directory as the new last
3114 Last_Source_Dir := String_Element_Table.Last
3115 (In_Tree.String_Elements);
3116 In_Tree.String_Elements.Table
3117 (Last_Source_Dir) := Element;
3118 end if;
3119 end;
3120 end if;
3121 end Find_Source_Dirs;
3123 -- Start of processing for Get_Directories
3125 begin
3126 if Current_Verbosity = High then
3127 Write_Line ("Starting to look for directories");
3128 end if;
3130 -- Check the object directory
3132 pragma Assert (Object_Dir.Kind = Single,
3133 "Object_Dir is not a single string");
3135 -- We set the object directory to its default
3137 Data.Object_Directory := Data.Directory;
3138 Data.Display_Object_Dir := Data.Display_Directory;
3140 if Object_Dir.Value /= Empty_String then
3141 Get_Name_String (Object_Dir.Value);
3143 if Name_Len = 0 then
3144 Error_Msg
3145 (Project, In_Tree,
3146 "Object_Dir cannot be empty",
3147 Object_Dir.Location);
3149 else
3150 -- We check that the specified object directory does exist
3152 Locate_Directory
3153 (Object_Dir.Value, Data.Display_Directory,
3154 Data.Object_Directory, Data.Display_Object_Dir);
3156 if Data.Object_Directory = No_Name then
3158 -- The object directory does not exist, report an error
3160 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3161 Error_Msg
3162 (Project, In_Tree,
3163 "the object directory { cannot be found",
3164 Data.Location);
3166 -- Do not keep a nil Object_Directory. Set it to the specified
3167 -- (relative or absolute) path. This is for the benefit of
3168 -- tools that recover from errors; for example, these tools
3169 -- could create the non existent directory.
3171 Data.Display_Object_Dir := Object_Dir.Value;
3172 Get_Name_String (Object_Dir.Value);
3173 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3174 Data.Object_Directory := Name_Find;
3175 end if;
3176 end if;
3177 end if;
3179 if Current_Verbosity = High then
3180 if Data.Object_Directory = No_Name then
3181 Write_Line ("No object directory");
3182 else
3183 Write_Str ("Object directory: """);
3184 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3185 Write_Line ("""");
3186 end if;
3187 end if;
3189 -- Check the exec directory
3191 pragma Assert (Exec_Dir.Kind = Single,
3192 "Exec_Dir is not a single string");
3194 -- We set the object directory to its default
3196 Data.Exec_Directory := Data.Object_Directory;
3197 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3199 if Exec_Dir.Value /= Empty_String then
3200 Get_Name_String (Exec_Dir.Value);
3202 if Name_Len = 0 then
3203 Error_Msg
3204 (Project, In_Tree,
3205 "Exec_Dir cannot be empty",
3206 Exec_Dir.Location);
3208 else
3209 -- We check that the specified object directory
3210 -- does exist.
3212 Locate_Directory
3213 (Exec_Dir.Value, Data.Directory,
3214 Data.Exec_Directory, Data.Display_Exec_Dir);
3216 if Data.Exec_Directory = No_Name then
3217 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3218 Error_Msg
3219 (Project, In_Tree,
3220 "the exec directory { cannot be found",
3221 Data.Location);
3222 end if;
3223 end if;
3224 end if;
3226 if Current_Verbosity = High then
3227 if Data.Exec_Directory = No_Name then
3228 Write_Line ("No exec directory");
3229 else
3230 Write_Str ("Exec directory: """);
3231 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3232 Write_Line ("""");
3233 end if;
3234 end if;
3236 -- Look for the source directories
3238 if Current_Verbosity = High then
3239 Write_Line ("Starting to look for source directories");
3240 end if;
3242 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
3244 if Source_Dirs.Default then
3246 -- No Source_Dirs specified: the single source directory
3247 -- is the one containing the project file
3249 String_Element_Table.Increment_Last
3250 (In_Tree.String_Elements);
3251 Data.Source_Dirs := String_Element_Table.Last
3252 (In_Tree.String_Elements);
3253 In_Tree.String_Elements.Table (Data.Source_Dirs) :=
3254 (Value => Data.Directory,
3255 Display_Value => Data.Display_Directory,
3256 Location => No_Location,
3257 Flag => False,
3258 Next => Nil_String,
3259 Index => 0);
3261 if Current_Verbosity = High then
3262 Write_Line ("Single source directory:");
3263 Write_Str (" """);
3264 Write_Str (Get_Name_String (Data.Display_Directory));
3265 Write_Line ("""");
3266 end if;
3268 elsif Source_Dirs.Values = Nil_String then
3270 -- If Source_Dirs is an empty string list, this means
3271 -- that this project contains no source. For projects that
3272 -- don't extend other projects, this also means that there is no
3273 -- need for an object directory, if not specified.
3275 if Data.Extends = No_Project
3276 and then Data.Object_Directory = Data.Directory
3277 then
3278 Data.Object_Directory := No_Name;
3279 end if;
3281 Data.Source_Dirs := Nil_String;
3282 Data.Ada_Sources_Present := False;
3283 Data.Other_Sources_Present := False;
3285 else
3286 declare
3287 Source_Dir : String_List_Id := Source_Dirs.Values;
3288 Element : String_Element;
3290 begin
3291 -- We will find the source directories for each
3292 -- element of the list
3294 while Source_Dir /= Nil_String loop
3295 Element :=
3296 In_Tree.String_Elements.Table (Source_Dir);
3297 Find_Source_Dirs (Element.Value, Element.Location);
3298 Source_Dir := Element.Next;
3299 end loop;
3300 end;
3301 end if;
3303 if Current_Verbosity = High then
3304 Write_Line ("Putting source directories in canonical cases");
3305 end if;
3307 declare
3308 Current : String_List_Id := Data.Source_Dirs;
3309 Element : String_Element;
3311 begin
3312 while Current /= Nil_String loop
3313 Element := In_Tree.String_Elements.Table (Current);
3314 if Element.Value /= No_Name then
3315 Get_Name_String (Element.Value);
3316 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3317 Element.Value := Name_Find;
3318 In_Tree.String_Elements.Table (Current) := Element;
3319 end if;
3321 Current := Element.Next;
3322 end loop;
3323 end;
3325 end Get_Directories;
3327 ---------------
3328 -- Get_Mains --
3329 ---------------
3331 procedure Get_Mains
3332 (Project : Project_Id;
3333 In_Tree : Project_Tree_Ref;
3334 Data : in out Project_Data) is
3335 Mains : constant Variable_Value :=
3336 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes, In_Tree);
3338 begin
3339 Data.Mains := Mains.Values;
3341 -- If no Mains were specified, and if we are an extending
3342 -- project, inherit the Mains from the project we are extending.
3344 if Mains.Default then
3345 if Data.Extends /= No_Project then
3346 Data.Mains :=
3347 In_Tree.Projects.Table (Data.Extends).Mains;
3348 end if;
3350 -- In a library project file, Main cannot be specified
3352 elsif Data.Library then
3353 Error_Msg
3354 (Project, In_Tree,
3355 "a library project file cannot have Main specified",
3356 Mains.Location);
3357 end if;
3358 end Get_Mains;
3360 ---------------------------
3361 -- Get_Sources_From_File --
3362 ---------------------------
3364 procedure Get_Sources_From_File
3365 (Path : String;
3366 Location : Source_Ptr;
3367 Project : Project_Id;
3368 In_Tree : Project_Tree_Ref)
3370 File : Prj.Util.Text_File;
3371 Line : String (1 .. 250);
3372 Last : Natural;
3373 Source_Name : Name_Id;
3375 begin
3376 Source_Names.Reset;
3378 if Current_Verbosity = High then
3379 Write_Str ("Opening """);
3380 Write_Str (Path);
3381 Write_Line (""".");
3382 end if;
3384 -- Open the file
3386 Prj.Util.Open (File, Path);
3388 if not Prj.Util.Is_Valid (File) then
3389 Error_Msg (Project, In_Tree, "file does not exist", Location);
3390 else
3391 -- Read the lines one by one
3393 while not Prj.Util.End_Of_File (File) loop
3394 Prj.Util.Get_Line (File, Line, Last);
3396 -- A non empty, non comment line should contain a file name
3398 if Last /= 0
3399 and then (Last = 1 or else Line (1 .. 2) /= "--")
3400 then
3401 -- ??? we should check that there is no directory information
3403 Name_Len := Last;
3404 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
3405 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3406 Source_Name := Name_Find;
3407 Source_Names.Set
3408 (K => Source_Name,
3409 E =>
3410 (Name => Source_Name,
3411 Location => Location,
3412 Found => False));
3413 end if;
3414 end loop;
3416 Prj.Util.Close (File);
3418 end if;
3419 end Get_Sources_From_File;
3421 --------------
3422 -- Get_Unit --
3423 --------------
3425 procedure Get_Unit
3426 (Canonical_File_Name : Name_Id;
3427 Naming : Naming_Data;
3428 Exception_Id : out Ada_Naming_Exception_Id;
3429 Unit_Name : out Name_Id;
3430 Unit_Kind : out Spec_Or_Body;
3431 Needs_Pragma : out Boolean)
3433 Info_Id : Ada_Naming_Exception_Id
3434 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
3435 VMS_Name : Name_Id;
3437 begin
3438 if Info_Id = No_Ada_Naming_Exception then
3439 if Hostparm.OpenVMS then
3440 VMS_Name := Canonical_File_Name;
3441 Get_Name_String (VMS_Name);
3443 if Name_Buffer (Name_Len) = '.' then
3444 Name_Len := Name_Len - 1;
3445 VMS_Name := Name_Find;
3446 end if;
3448 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
3449 end if;
3451 end if;
3453 if Info_Id /= No_Ada_Naming_Exception then
3454 Exception_Id := Info_Id;
3455 Unit_Name := No_Name;
3456 Unit_Kind := Specification;
3457 Needs_Pragma := True;
3458 return;
3459 end if;
3461 Needs_Pragma := False;
3462 Exception_Id := No_Ada_Naming_Exception;
3464 Get_Name_String (Canonical_File_Name);
3466 declare
3467 File : String := Name_Buffer (1 .. Name_Len);
3468 First : constant Positive := File'First;
3469 Last : Natural := File'Last;
3470 Standard_GNAT : Boolean;
3472 begin
3473 Standard_GNAT :=
3474 Naming.Ada_Spec_Suffix = Default_Ada_Spec_Suffix
3475 and then Naming.Ada_Body_Suffix = Default_Ada_Body_Suffix;
3477 -- Check if the end of the file name is Specification_Append
3479 Get_Name_String (Naming.Ada_Spec_Suffix);
3481 if File'Length > Name_Len
3482 and then File (Last - Name_Len + 1 .. Last) =
3483 Name_Buffer (1 .. Name_Len)
3484 then
3485 -- We have a spec
3487 Unit_Kind := Specification;
3488 Last := Last - Name_Len;
3490 if Current_Verbosity = High then
3491 Write_Str (" Specification: ");
3492 Write_Line (File (First .. Last));
3493 end if;
3495 else
3496 Get_Name_String (Naming.Ada_Body_Suffix);
3498 -- Check if the end of the file name is Body_Append
3500 if File'Length > Name_Len
3501 and then File (Last - Name_Len + 1 .. Last) =
3502 Name_Buffer (1 .. Name_Len)
3503 then
3504 -- We have a body
3506 Unit_Kind := Body_Part;
3507 Last := Last - Name_Len;
3509 if Current_Verbosity = High then
3510 Write_Str (" Body: ");
3511 Write_Line (File (First .. Last));
3512 end if;
3514 elsif Naming.Separate_Suffix /= Naming.Ada_Spec_Suffix then
3515 Get_Name_String (Naming.Separate_Suffix);
3517 -- Check if the end of the file name is Separate_Append
3519 if File'Length > Name_Len
3520 and then File (Last - Name_Len + 1 .. Last) =
3521 Name_Buffer (1 .. Name_Len)
3522 then
3523 -- We have a separate (a body)
3525 Unit_Kind := Body_Part;
3526 Last := Last - Name_Len;
3528 if Current_Verbosity = High then
3529 Write_Str (" Separate: ");
3530 Write_Line (File (First .. Last));
3531 end if;
3533 else
3534 Last := 0;
3535 end if;
3537 else
3538 Last := 0;
3539 end if;
3540 end if;
3542 if Last = 0 then
3544 -- This is not a source file
3546 Unit_Name := No_Name;
3547 Unit_Kind := Specification;
3549 if Current_Verbosity = High then
3550 Write_Line (" Not a valid file name.");
3551 end if;
3553 return;
3554 end if;
3556 Get_Name_String (Naming.Dot_Replacement);
3557 Standard_GNAT :=
3558 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
3560 if Name_Buffer (1 .. Name_Len) /= "." then
3562 -- If Dot_Replacement is not a single dot, then there should
3563 -- not be any dot in the name.
3565 for Index in First .. Last loop
3566 if File (Index) = '.' then
3567 if Current_Verbosity = High then
3568 Write_Line
3569 (" Not a valid file name (some dot not replaced).");
3570 end if;
3572 Unit_Name := No_Name;
3573 return;
3575 end if;
3576 end loop;
3578 -- Replace the substring Dot_Replacement with dots
3580 declare
3581 Index : Positive := First;
3583 begin
3584 while Index <= Last - Name_Len + 1 loop
3586 if File (Index .. Index + Name_Len - 1) =
3587 Name_Buffer (1 .. Name_Len)
3588 then
3589 File (Index) := '.';
3591 if Name_Len > 1 and then Index < Last then
3592 File (Index + 1 .. Last - Name_Len + 1) :=
3593 File (Index + Name_Len .. Last);
3594 end if;
3596 Last := Last - Name_Len + 1;
3597 end if;
3599 Index := Index + 1;
3600 end loop;
3601 end;
3602 end if;
3604 -- Check if the casing is right
3606 declare
3607 Src : String := File (First .. Last);
3609 begin
3610 case Naming.Casing is
3611 when All_Lower_Case =>
3612 Fixed.Translate
3613 (Source => Src,
3614 Mapping => Lower_Case_Map);
3616 when All_Upper_Case =>
3617 Fixed.Translate
3618 (Source => Src,
3619 Mapping => Upper_Case_Map);
3621 when Mixed_Case | Unknown =>
3622 null;
3623 end case;
3625 if Src /= File (First .. Last) then
3626 if Current_Verbosity = High then
3627 Write_Line (" Not a valid file name (casing).");
3628 end if;
3630 Unit_Name := No_Name;
3631 return;
3632 end if;
3634 -- We put the name in lower case
3636 Fixed.Translate
3637 (Source => Src,
3638 Mapping => Lower_Case_Map);
3640 -- In the standard GNAT naming scheme, check for special cases:
3641 -- children or separates of A, G, I or S, and run time sources.
3643 if Standard_GNAT and then Src'Length >= 3 then
3644 declare
3645 S1 : constant Character := Src (Src'First);
3646 S2 : constant Character := Src (Src'First + 1);
3648 begin
3649 if S1 = 'a' or else S1 = 'g'
3650 or else S1 = 'i' or else S1 = 's'
3651 then
3652 -- Children or separates of packages A, G, I or S
3654 if (Hostparm.OpenVMS and then S2 = '$')
3655 or else (not Hostparm.OpenVMS and then S2 = '~')
3656 then
3657 Src (Src'First + 1) := '.';
3659 -- If it is potentially a run time source, disable
3660 -- filling of the mapping file to avoid warnings.
3662 elsif S2 = '.' then
3663 Set_Mapping_File_Initial_State_To_Empty;
3664 end if;
3666 end if;
3667 end;
3668 end if;
3670 if Current_Verbosity = High then
3671 Write_Str (" ");
3672 Write_Line (Src);
3673 end if;
3675 -- Now, we check if this name is a valid unit name
3677 Check_Ada_Name (Name => Src, Unit => Unit_Name);
3678 end;
3680 end;
3681 end Get_Unit;
3683 ----------
3684 -- Hash --
3685 ----------
3687 function Hash (Unit : Unit_Info) return Header_Num is
3688 begin
3689 return Header_Num (Unit.Unit mod 2048);
3690 end Hash;
3692 -----------------------
3693 -- Is_Illegal_Suffix --
3694 -----------------------
3696 function Is_Illegal_Suffix
3697 (Suffix : String;
3698 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
3700 begin
3701 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
3702 return True;
3703 end if;
3705 -- If dot replacement is a single dot, and first character of
3706 -- suffix is also a dot
3708 if Dot_Replacement_Is_A_Single_Dot
3709 and then Suffix (Suffix'First) = '.'
3710 then
3711 for Index in Suffix'First + 1 .. Suffix'Last loop
3713 -- If there is another dot
3715 if Suffix (Index) = '.' then
3717 -- It is illegal to have a letter following the initial dot
3719 return Is_Letter (Suffix (Suffix'First + 1));
3720 end if;
3721 end loop;
3722 end if;
3724 -- Everything is OK
3726 return False;
3727 end Is_Illegal_Suffix;
3729 ----------------------
3730 -- Locate_Directory --
3731 ----------------------
3733 procedure Locate_Directory
3734 (Name : Name_Id;
3735 Parent : Name_Id;
3736 Dir : out Name_Id;
3737 Display : out Name_Id)
3739 The_Name : constant String := Get_Name_String (Name);
3741 The_Parent : constant String :=
3742 Get_Name_String (Parent) & Directory_Separator;
3744 The_Parent_Last : constant Natural :=
3745 Compute_Directory_Last (The_Parent);
3747 begin
3748 if Current_Verbosity = High then
3749 Write_Str ("Locate_Directory (""");
3750 Write_Str (The_Name);
3751 Write_Str (""", """);
3752 Write_Str (The_Parent);
3753 Write_Line (""")");
3754 end if;
3756 Dir := No_Name;
3757 Display := No_Name;
3759 if Is_Absolute_Path (The_Name) then
3760 if Is_Directory (The_Name) then
3761 declare
3762 Normed : constant String :=
3763 Normalize_Pathname
3764 (The_Name,
3765 Resolve_Links => False,
3766 Case_Sensitive => True);
3768 Canonical_Path : constant String :=
3769 Normalize_Pathname
3770 (Normed,
3771 Resolve_Links => True,
3772 Case_Sensitive => False);
3774 begin
3775 Name_Len := Normed'Length;
3776 Name_Buffer (1 .. Name_Len) := Normed;
3777 Display := Name_Find;
3779 Name_Len := Canonical_Path'Length;
3780 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3781 Dir := Name_Find;
3782 end;
3783 end if;
3785 else
3786 declare
3787 Full_Path : constant String :=
3788 The_Parent (The_Parent'First .. The_Parent_Last) &
3789 The_Name;
3791 begin
3792 if Is_Directory (Full_Path) then
3793 declare
3794 Normed : constant String :=
3795 Normalize_Pathname
3796 (Full_Path,
3797 Resolve_Links => False,
3798 Case_Sensitive => True);
3800 Canonical_Path : constant String :=
3801 Normalize_Pathname
3802 (Normed,
3803 Resolve_Links => True,
3804 Case_Sensitive => False);
3806 begin
3807 Name_Len := Normed'Length;
3808 Name_Buffer (1 .. Name_Len) := Normed;
3809 Display := Name_Find;
3811 Name_Len := Canonical_Path'Length;
3812 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3813 Dir := Name_Find;
3814 end;
3815 end if;
3816 end;
3817 end if;
3818 end Locate_Directory;
3820 ----------------------
3821 -- Look_For_Sources --
3822 ----------------------
3824 procedure Look_For_Sources
3825 (Project : Project_Id;
3826 In_Tree : Project_Tree_Ref;
3827 Data : in out Project_Data;
3828 Follow_Links : Boolean)
3830 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean);
3831 -- Find the path names of the source files in the Source_Names table
3832 -- in the source directories and record those that are Ada sources.
3834 procedure Get_Sources_From_File
3835 (Path : String;
3836 Location : Source_Ptr);
3837 -- Get the sources of a project from a text file
3839 ---------------------------------------
3840 -- Get_Path_Names_And_Record_Sources --
3841 ---------------------------------------
3843 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean) is
3844 Source_Dir : String_List_Id := Data.Source_Dirs;
3845 Element : String_Element;
3846 Path : Name_Id;
3848 Dir : Dir_Type;
3849 Name : Name_Id;
3850 Canonical_Name : Name_Id;
3851 Name_Str : String (1 .. 1_024);
3852 Last : Natural := 0;
3853 NL : Name_Location;
3855 Current_Source : String_List_Id := Nil_String;
3857 First_Error : Boolean := True;
3859 Source_Recorded : Boolean := False;
3861 begin
3862 -- We look in all source directories for the file names in the
3863 -- hash table Source_Names
3865 while Source_Dir /= Nil_String loop
3866 Source_Recorded := False;
3867 Element := In_Tree.String_Elements.Table (Source_Dir);
3869 declare
3870 Dir_Path : constant String := Get_Name_String (Element.Value);
3871 begin
3872 if Current_Verbosity = High then
3873 Write_Str ("checking directory """);
3874 Write_Str (Dir_Path);
3875 Write_Line ("""");
3876 end if;
3878 Open (Dir, Dir_Path);
3880 loop
3881 Read (Dir, Name_Str, Last);
3882 exit when Last = 0;
3883 Name_Len := Last;
3884 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3885 Name := Name_Find;
3886 Canonical_Case_File_Name (Name_Str (1 .. Last));
3887 Name_Len := Last;
3888 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3889 Canonical_Name := Name_Find;
3890 NL := Source_Names.Get (Canonical_Name);
3892 if NL /= No_Name_Location and then not NL.Found then
3893 NL.Found := True;
3894 Source_Names.Set (Canonical_Name, NL);
3895 Name_Len := Dir_Path'Length;
3896 Name_Buffer (1 .. Name_Len) := Dir_Path;
3898 if Name_Buffer (Name_Len) /= Directory_Separator then
3899 Add_Char_To_Name_Buffer (Directory_Separator);
3900 end if;
3902 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
3903 Path := Name_Find;
3905 if Current_Verbosity = High then
3906 Write_Str (" found ");
3907 Write_Line (Get_Name_String (Name));
3908 end if;
3910 -- Register the source if it is an Ada compilation unit
3912 Record_Ada_Source
3913 (File_Name => Name,
3914 Path_Name => Path,
3915 Project => Project,
3916 In_Tree => In_Tree,
3917 Data => Data,
3918 Location => NL.Location,
3919 Current_Source => Current_Source,
3920 Source_Recorded => Source_Recorded,
3921 Follow_Links => Follow_Links);
3922 end if;
3923 end loop;
3925 Close (Dir);
3926 end;
3928 if Source_Recorded then
3929 In_Tree.String_Elements.Table (Source_Dir).Flag :=
3930 True;
3931 end if;
3933 Source_Dir := Element.Next;
3934 end loop;
3936 -- It is an error if a source file name in a source list or
3937 -- in a source list file is not found.
3939 NL := Source_Names.Get_First;
3941 while NL /= No_Name_Location loop
3942 if not NL.Found then
3943 Err_Vars.Error_Msg_Name_1 := NL.Name;
3945 if First_Error then
3946 Error_Msg
3947 (Project, In_Tree,
3948 "source file { cannot be found",
3949 NL.Location);
3950 First_Error := False;
3952 else
3953 Error_Msg
3954 (Project, In_Tree,
3955 "\source file { cannot be found",
3956 NL.Location);
3957 end if;
3958 end if;
3960 NL := Source_Names.Get_Next;
3961 end loop;
3962 end Get_Path_Names_And_Record_Sources;
3964 ---------------------------
3965 -- Get_Sources_From_File --
3966 ---------------------------
3968 procedure Get_Sources_From_File
3969 (Path : String;
3970 Location : Source_Ptr)
3972 begin
3973 -- Get the list of sources from the file and put them in hash table
3974 -- Source_Names.
3976 Get_Sources_From_File (Path, Location, Project, In_Tree);
3978 -- Look in the source directories to find those sources
3980 Get_Path_Names_And_Record_Sources (Follow_Links);
3982 -- We should have found at least one source.
3983 -- If not, report an error.
3985 if Data.Sources = Nil_String then
3986 Error_Msg (Project, In_Tree,
3987 "there are no Ada sources in this project",
3988 Location);
3989 end if;
3990 end Get_Sources_From_File;
3992 begin
3993 if Data.Ada_Sources_Present then
3994 declare
3995 Sources : constant Variable_Value :=
3996 Util.Value_Of
3997 (Name_Source_Files,
3998 Data.Decl.Attributes,
3999 In_Tree);
4001 Source_List_File : constant Variable_Value :=
4002 Util.Value_Of
4003 (Name_Source_List_File,
4004 Data.Decl.Attributes,
4005 In_Tree);
4007 Locally_Removed : constant Variable_Value :=
4008 Util.Value_Of
4009 (Name_Locally_Removed_Files,
4010 Data.Decl.Attributes,
4011 In_Tree);
4013 begin
4014 pragma Assert
4015 (Sources.Kind = List,
4016 "Source_Files is not a list");
4018 pragma Assert
4019 (Source_List_File.Kind = Single,
4020 "Source_List_File is not a single string");
4022 if not Sources.Default then
4023 if not Source_List_File.Default then
4024 Error_Msg
4025 (Project, In_Tree,
4026 "?both variables source_files and " &
4027 "source_list_file are present",
4028 Source_List_File.Location);
4029 end if;
4031 -- Sources is a list of file names
4033 declare
4034 Current : String_List_Id := Sources.Values;
4035 Element : String_Element;
4036 Location : Source_Ptr;
4037 Name : Name_Id;
4039 begin
4040 Source_Names.Reset;
4042 Data.Ada_Sources_Present := Current /= Nil_String;
4044 while Current /= Nil_String loop
4045 Element :=
4046 In_Tree.String_Elements.Table (Current);
4047 Get_Name_String (Element.Value);
4048 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4049 Name := Name_Find;
4051 -- If the element has no location, then use the
4052 -- location of Sources to report possible errors.
4054 if Element.Location = No_Location then
4055 Location := Sources.Location;
4056 else
4057 Location := Element.Location;
4058 end if;
4060 Source_Names.Set
4061 (K => Name,
4062 E =>
4063 (Name => Name,
4064 Location => Location,
4065 Found => False));
4067 Current := Element.Next;
4068 end loop;
4070 Get_Path_Names_And_Record_Sources (Follow_Links);
4071 end;
4073 -- No source_files specified
4075 -- We check Source_List_File has been specified
4077 elsif not Source_List_File.Default then
4079 -- Source_List_File is the name of the file
4080 -- that contains the source file names
4082 declare
4083 Source_File_Path_Name : constant String :=
4084 Path_Name_Of
4085 (Source_List_File.Value,
4086 Data.Directory);
4088 begin
4089 if Source_File_Path_Name'Length = 0 then
4090 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4091 Error_Msg
4092 (Project, In_Tree,
4093 "file with sources { does not exist",
4094 Source_List_File.Location);
4096 else
4097 Get_Sources_From_File
4098 (Source_File_Path_Name,
4099 Source_List_File.Location);
4100 end if;
4101 end;
4103 else
4104 -- Neither Source_Files nor Source_List_File has been
4105 -- specified. Find all the files that satisfy the naming
4106 -- scheme in all the source directories.
4108 Find_Sources
4109 (Project, In_Tree, Data, Ada_Language_Index, Follow_Links);
4110 end if;
4112 -- If there are sources that are locally removed, mark them as
4113 -- such in the Units table.
4115 if not Locally_Removed.Default then
4117 -- Sources can be locally removed only in extending
4118 -- project files.
4120 if Data.Extends = No_Project then
4121 Error_Msg
4122 (Project, In_Tree,
4123 "Locally_Removed_Files can only be used " &
4124 "in an extending project file",
4125 Locally_Removed.Location);
4127 else
4128 declare
4129 Current : String_List_Id := Locally_Removed.Values;
4130 Element : String_Element;
4131 Location : Source_Ptr;
4132 OK : Boolean;
4133 Unit : Unit_Data;
4134 Name : Name_Id;
4135 Extended : Project_Id;
4137 begin
4138 while Current /= Nil_String loop
4139 Element :=
4140 In_Tree.String_Elements.Table (Current);
4141 Get_Name_String (Element.Value);
4142 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4143 Name := Name_Find;
4145 -- If the element has no location, then use the
4146 -- location of Locally_Removed to report
4147 -- possible errors.
4149 if Element.Location = No_Location then
4150 Location := Locally_Removed.Location;
4151 else
4152 Location := Element.Location;
4153 end if;
4155 OK := False;
4157 for Index in Unit_Table.First ..
4158 Unit_Table.Last (In_Tree.Units)
4159 loop
4160 Unit := In_Tree.Units.Table (Index);
4162 if Unit.File_Names (Specification).Name = Name then
4163 OK := True;
4165 -- Check that this is from a project that
4166 -- the current project extends, but not the
4167 -- current project.
4169 Extended := Unit.File_Names
4170 (Specification).Project;
4172 if Extended = Project then
4173 Error_Msg
4174 (Project, In_Tree,
4175 "cannot remove a source " &
4176 "of the same project",
4177 Location);
4179 elsif
4180 Project_Extends (Project, Extended, In_Tree)
4181 then
4182 Unit.File_Names
4183 (Specification).Path := Slash;
4184 Unit.File_Names
4185 (Specification).Needs_Pragma := False;
4186 In_Tree.Units.Table (Index) :=
4187 Unit;
4188 Add_Forbidden_File_Name
4189 (Unit.File_Names (Specification).Name);
4190 exit;
4192 else
4193 Error_Msg
4194 (Project, In_Tree,
4195 "cannot remove a source from " &
4196 "another project",
4197 Location);
4198 end if;
4200 elsif
4201 Unit.File_Names (Body_Part).Name = Name
4202 then
4203 OK := True;
4205 -- Check that this is from a project that
4206 -- the current project extends, but not the
4207 -- current project.
4209 Extended := Unit.File_Names
4210 (Body_Part).Project;
4212 if Extended = Project then
4213 Error_Msg
4214 (Project, In_Tree,
4215 "cannot remove a source " &
4216 "of the same project",
4217 Location);
4219 elsif
4220 Project_Extends (Project, Extended, In_Tree)
4221 then
4222 Unit.File_Names (Body_Part).Path := Slash;
4223 Unit.File_Names (Body_Part).Needs_Pragma
4224 := False;
4225 In_Tree.Units.Table (Index) :=
4226 Unit;
4227 Add_Forbidden_File_Name
4228 (Unit.File_Names (Body_Part).Name);
4229 exit;
4230 end if;
4232 end if;
4233 end loop;
4235 if not OK then
4236 Err_Vars.Error_Msg_Name_1 := Name;
4237 Error_Msg
4238 (Project, In_Tree, "unknown file {", Location);
4239 end if;
4241 Current := Element.Next;
4242 end loop;
4243 end;
4244 end if;
4245 end if;
4246 end;
4247 end if;
4249 if Data.Other_Sources_Present then
4251 -- Set Source_Present to False. It will be set back to True
4252 -- whenever a source is found.
4254 Data.Other_Sources_Present := False;
4255 for Lang in Ada_Language_Index + 1 .. Last_Language_Index loop
4257 -- For each language (other than Ada) in the project file
4259 if Is_Present (Lang, Data, In_Tree) then
4261 -- Reset the indication that there are sources of this
4262 -- language. It will be set back to True whenever we find a
4263 -- source of the language.
4265 Set (Lang, False, Data, In_Tree);
4267 -- First, get the source suffix for the language
4269 Set (Suffix => Suffix_For (Lang, Data.Naming, In_Tree),
4270 For_Language => Lang,
4271 In_Project => Data,
4272 In_Tree => In_Tree);
4274 -- Then, deal with the naming exceptions, if any
4276 Source_Names.Reset;
4278 declare
4279 Naming_Exceptions : constant Variable_Value :=
4280 Value_Of
4281 (Index => Language_Names.Table (Lang),
4282 Src_Index => 0,
4283 In_Array => Data.Naming.Implementation_Exceptions,
4284 In_Tree => In_Tree);
4285 Element_Id : String_List_Id;
4286 Element : String_Element;
4287 File_Id : Name_Id;
4288 Source_Found : Boolean := False;
4290 begin
4291 -- If there are naming exceptions, look through them one
4292 -- by one.
4294 if Naming_Exceptions /= Nil_Variable_Value then
4295 Element_Id := Naming_Exceptions.Values;
4297 while Element_Id /= Nil_String loop
4298 Element := In_Tree.String_Elements.Table
4299 (Element_Id);
4300 Get_Name_String (Element.Value);
4301 Canonical_Case_File_Name
4302 (Name_Buffer (1 .. Name_Len));
4303 File_Id := Name_Find;
4305 -- Put each naming exception in the Source_Names
4306 -- hash table, but if there are repetition, don't
4307 -- bother after the first instance.
4310 Source_Names.Get (File_Id) = No_Name_Location
4311 then
4312 Source_Found := True;
4313 Source_Names.Set
4314 (File_Id,
4315 (Name => File_Id,
4316 Location => Element.Location,
4317 Found => False));
4318 end if;
4320 Element_Id := Element.Next;
4321 end loop;
4323 -- If there is at least one naming exception, record
4324 -- those that are found in the source directories.
4326 if Source_Found then
4327 Record_Other_Sources
4328 (Project => Project,
4329 In_Tree => In_Tree,
4330 Data => Data,
4331 Language => Lang,
4332 Naming_Exceptions => True);
4333 end if;
4335 end if;
4336 end;
4338 -- Now, check if a list of sources is declared either through
4339 -- a string list (attribute Source_Files) or a text file
4340 -- (attribute Source_List_File). If a source list is declared,
4341 -- we will consider only those naming exceptions that are
4342 -- on the list.
4344 declare
4345 Sources : constant Variable_Value :=
4346 Util.Value_Of
4347 (Name_Source_Files,
4348 Data.Decl.Attributes,
4349 In_Tree);
4351 Source_List_File : constant Variable_Value :=
4352 Util.Value_Of
4353 (Name_Source_List_File,
4354 Data.Decl.Attributes,
4355 In_Tree);
4357 begin
4358 pragma Assert
4359 (Sources.Kind = List,
4360 "Source_Files is not a list");
4362 pragma Assert
4363 (Source_List_File.Kind = Single,
4364 "Source_List_File is not a single string");
4366 if not Sources.Default then
4367 if not Source_List_File.Default then
4368 Error_Msg
4369 (Project, In_Tree,
4370 "?both variables source_files and " &
4371 "source_list_file are present",
4372 Source_List_File.Location);
4373 end if;
4375 -- Sources is a list of file names
4377 declare
4378 Current : String_List_Id := Sources.Values;
4379 Element : String_Element;
4380 Location : Source_Ptr;
4381 Name : Name_Id;
4383 begin
4384 Source_Names.Reset;
4386 -- Put all the sources in the Source_Names hash table
4388 while Current /= Nil_String loop
4389 Element :=
4390 In_Tree.String_Elements.Table
4391 (Current);
4392 Get_Name_String (Element.Value);
4393 Canonical_Case_File_Name
4394 (Name_Buffer (1 .. Name_Len));
4395 Name := Name_Find;
4397 -- If the element has no location, then use the
4398 -- location of Sources to report possible errors.
4400 if Element.Location = No_Location then
4401 Location := Sources.Location;
4402 else
4403 Location := Element.Location;
4404 end if;
4406 Source_Names.Set
4407 (K => Name,
4408 E =>
4409 (Name => Name,
4410 Location => Location,
4411 Found => False));
4413 Current := Element.Next;
4414 end loop;
4416 -- And look for their directories
4418 Record_Other_Sources
4419 (Project => Project,
4420 In_Tree => In_Tree,
4421 Data => Data,
4422 Language => Lang,
4423 Naming_Exceptions => False);
4424 end;
4426 -- No source_files specified
4428 -- We check if Source_List_File has been specified
4430 elsif not Source_List_File.Default then
4432 -- Source_List_File is the name of the file
4433 -- that contains the source file names
4435 declare
4436 Source_File_Path_Name : constant String :=
4437 Path_Name_Of
4438 (Source_List_File.Value,
4439 Data.Directory);
4441 begin
4442 if Source_File_Path_Name'Length = 0 then
4443 Err_Vars.Error_Msg_Name_1 :=
4444 Source_List_File.Value;
4445 Error_Msg
4446 (Project, In_Tree,
4447 "file with sources { does not exist",
4448 Source_List_File.Location);
4450 else
4451 -- Read the file, putting each source in the
4452 -- Source_Names hash table.
4454 Get_Sources_From_File
4455 (Source_File_Path_Name,
4456 Source_List_File.Location,
4457 Project, In_Tree);
4459 -- And look for their directories
4461 Record_Other_Sources
4462 (Project => Project,
4463 In_Tree => In_Tree,
4464 Data => Data,
4465 Language => Lang,
4466 Naming_Exceptions => False);
4467 end if;
4468 end;
4470 -- Neither Source_Files nor Source_List_File was specified
4472 else
4473 -- Find all the files that satisfy the naming scheme in
4474 -- all the source directories. All the naming exceptions
4475 -- that effectively exist are also part of the source
4476 -- of this language.
4478 Find_Sources (Project, In_Tree, Data, Lang);
4479 end if;
4480 end;
4481 end if;
4482 end loop;
4483 end if;
4484 end Look_For_Sources;
4486 ------------------
4487 -- Path_Name_Of --
4488 ------------------
4490 function Path_Name_Of
4491 (File_Name : Name_Id;
4492 Directory : Name_Id) return String
4494 Result : String_Access;
4496 The_Directory : constant String := Get_Name_String (Directory);
4498 begin
4499 Get_Name_String (File_Name);
4500 Result := Locate_Regular_File
4501 (File_Name => Name_Buffer (1 .. Name_Len),
4502 Path => The_Directory);
4504 if Result = null then
4505 return "";
4506 else
4507 Canonical_Case_File_Name (Result.all);
4508 return Result.all;
4509 end if;
4510 end Path_Name_Of;
4512 -------------------------------
4513 -- Prepare_Ada_Naming_Exceptions --
4514 -------------------------------
4516 procedure Prepare_Ada_Naming_Exceptions
4517 (List : Array_Element_Id;
4518 In_Tree : Project_Tree_Ref;
4519 Kind : Spec_Or_Body)
4521 Current : Array_Element_Id := List;
4522 Element : Array_Element;
4524 Unit : Unit_Info;
4526 begin
4527 -- Traverse the list
4529 while Current /= No_Array_Element loop
4530 Element := In_Tree.Array_Elements.Table (Current);
4532 if Element.Index /= No_Name then
4533 Unit :=
4534 (Kind => Kind,
4535 Unit => Element.Index,
4536 Next => No_Ada_Naming_Exception);
4537 Reverse_Ada_Naming_Exceptions.Set
4538 (Unit, (Element.Value.Value, Element.Value.Index));
4539 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4540 Ada_Naming_Exception_Table.Increment_Last;
4541 Ada_Naming_Exception_Table.Table
4542 (Ada_Naming_Exception_Table.Last) := Unit;
4543 Ada_Naming_Exceptions.Set
4544 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4545 end if;
4547 Current := Element.Next;
4548 end loop;
4549 end Prepare_Ada_Naming_Exceptions;
4551 ---------------------
4552 -- Project_Extends --
4553 ---------------------
4555 function Project_Extends
4556 (Extending : Project_Id;
4557 Extended : Project_Id;
4558 In_Tree : Project_Tree_Ref) return Boolean
4560 Current : Project_Id := Extending;
4561 begin
4562 loop
4563 if Current = No_Project then
4564 return False;
4566 elsif Current = Extended then
4567 return True;
4568 end if;
4570 Current := In_Tree.Projects.Table (Current).Extends;
4571 end loop;
4572 end Project_Extends;
4574 -----------------------
4575 -- Record_Ada_Source --
4576 -----------------------
4578 procedure Record_Ada_Source
4579 (File_Name : Name_Id;
4580 Path_Name : Name_Id;
4581 Project : Project_Id;
4582 In_Tree : Project_Tree_Ref;
4583 Data : in out Project_Data;
4584 Location : Source_Ptr;
4585 Current_Source : in out String_List_Id;
4586 Source_Recorded : in out Boolean;
4587 Follow_Links : Boolean)
4589 Canonical_File_Name : Name_Id;
4590 Canonical_Path_Name : Name_Id;
4592 Exception_Id : Ada_Naming_Exception_Id;
4593 Unit_Name : Name_Id;
4594 Unit_Kind : Spec_Or_Body;
4595 Unit_Index : Int := 0;
4596 Info : Unit_Info;
4597 Name_Index : Name_And_Index;
4598 Needs_Pragma : Boolean;
4600 The_Location : Source_Ptr := Location;
4601 Previous_Source : constant String_List_Id := Current_Source;
4602 Except_Name : Name_And_Index := No_Name_And_Index;
4604 Unit_Prj : Unit_Project;
4606 File_Name_Recorded : Boolean := False;
4608 begin
4609 Get_Name_String (File_Name);
4610 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4611 Canonical_File_Name := Name_Find;
4613 declare
4614 Canonical_Path : constant String :=
4615 Normalize_Pathname
4616 (Get_Name_String (Path_Name),
4617 Resolve_Links => Follow_Links,
4618 Case_Sensitive => False);
4619 begin
4620 Name_Len := 0;
4621 Add_Str_To_Name_Buffer (Canonical_Path);
4622 Canonical_Path_Name := Name_Find;
4623 end;
4625 -- Find out the unit name, the unit kind and if it needs
4626 -- a specific SFN pragma.
4628 Get_Unit
4629 (Canonical_File_Name => Canonical_File_Name,
4630 Naming => Data.Naming,
4631 Exception_Id => Exception_Id,
4632 Unit_Name => Unit_Name,
4633 Unit_Kind => Unit_Kind,
4634 Needs_Pragma => Needs_Pragma);
4636 if Exception_Id = No_Ada_Naming_Exception and then
4637 Unit_Name = No_Name
4638 then
4639 if Current_Verbosity = High then
4640 Write_Str (" """);
4641 Write_Str (Get_Name_String (Canonical_File_Name));
4642 Write_Line (""" is not a valid source file name (ignored).");
4643 end if;
4645 else
4646 -- Check to see if the source has been hidden by an exception,
4647 -- but only if it is not an exception.
4649 if not Needs_Pragma then
4650 Except_Name :=
4651 Reverse_Ada_Naming_Exceptions.Get
4652 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4654 if Except_Name /= No_Name_And_Index then
4655 if Current_Verbosity = High then
4656 Write_Str (" """);
4657 Write_Str (Get_Name_String (Canonical_File_Name));
4658 Write_Str (""" contains a unit that is found in """);
4659 Write_Str (Get_Name_String (Except_Name.Name));
4660 Write_Line (""" (ignored).");
4661 end if;
4663 -- The file is not included in the source of the project,
4664 -- because it is hidden by the exception.
4665 -- So, there is nothing else to do.
4667 return;
4668 end if;
4669 end if;
4671 loop
4672 if Exception_Id /= No_Ada_Naming_Exception then
4673 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4674 Exception_Id := Info.Next;
4675 Info.Next := No_Ada_Naming_Exception;
4676 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4678 Unit_Name := Info.Unit;
4679 Unit_Index := Name_Index.Index;
4680 Unit_Kind := Info.Kind;
4681 end if;
4683 -- Put the file name in the list of sources of the project
4685 if not File_Name_Recorded then
4686 String_Element_Table.Increment_Last
4687 (In_Tree.String_Elements);
4688 In_Tree.String_Elements.Table
4689 (String_Element_Table.Last
4690 (In_Tree.String_Elements)) :=
4691 (Value => Canonical_File_Name,
4692 Display_Value => File_Name,
4693 Location => No_Location,
4694 Flag => False,
4695 Next => Nil_String,
4696 Index => Unit_Index);
4697 end if;
4699 if Current_Source = Nil_String then
4700 Data.Sources := String_Element_Table.Last
4701 (In_Tree.String_Elements);
4702 else
4703 In_Tree.String_Elements.Table
4704 (Current_Source).Next :=
4705 String_Element_Table.Last
4706 (In_Tree.String_Elements);
4707 end if;
4709 Current_Source := String_Element_Table.Last
4710 (In_Tree.String_Elements);
4712 -- Put the unit in unit list
4714 declare
4715 The_Unit : Unit_Id :=
4716 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
4717 The_Unit_Data : Unit_Data;
4719 begin
4720 if Current_Verbosity = High then
4721 Write_Str ("Putting ");
4722 Write_Str (Get_Name_String (Unit_Name));
4723 Write_Line (" in the unit list.");
4724 end if;
4726 -- The unit is already in the list, but may be it is
4727 -- only the other unit kind (spec or body), or what is
4728 -- in the unit list is a unit of a project we are extending.
4730 if The_Unit /= No_Unit then
4731 The_Unit_Data := In_Tree.Units.Table (The_Unit);
4733 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4734 or else Project_Extends
4735 (Data.Extends,
4736 The_Unit_Data.File_Names (Unit_Kind).Project,
4737 In_Tree)
4738 then
4739 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4740 Remove_Forbidden_File_Name
4741 (The_Unit_Data.File_Names (Unit_Kind).Name);
4742 end if;
4744 -- Record the file name in the hash table Files_Htable
4746 Unit_Prj := (Unit => The_Unit, Project => Project);
4747 Files_Htable.Set
4748 (In_Tree.Files_HT,
4749 Canonical_File_Name,
4750 Unit_Prj);
4752 The_Unit_Data.File_Names (Unit_Kind) :=
4753 (Name => Canonical_File_Name,
4754 Index => Unit_Index,
4755 Display_Name => File_Name,
4756 Path => Canonical_Path_Name,
4757 Display_Path => Path_Name,
4758 Project => Project,
4759 Needs_Pragma => Needs_Pragma);
4760 In_Tree.Units.Table (The_Unit) :=
4761 The_Unit_Data;
4762 Source_Recorded := True;
4764 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4765 and then (Data.Known_Order_Of_Source_Dirs or else
4766 The_Unit_Data.File_Names (Unit_Kind).Path =
4767 Canonical_Path_Name)
4768 then
4769 if Previous_Source = Nil_String then
4770 Data.Sources := Nil_String;
4771 else
4772 In_Tree.String_Elements.Table
4773 (Previous_Source).Next := Nil_String;
4774 String_Element_Table.Decrement_Last
4775 (In_Tree.String_Elements);
4776 end if;
4778 Current_Source := Previous_Source;
4780 else
4781 -- It is an error to have two units with the same name
4782 -- and the same kind (spec or body).
4784 if The_Location = No_Location then
4785 The_Location :=
4786 In_Tree.Projects.Table
4787 (Project).Location;
4788 end if;
4790 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4791 Error_Msg
4792 (Project, In_Tree, "duplicate source {", The_Location);
4794 Err_Vars.Error_Msg_Name_1 :=
4795 In_Tree.Projects.Table
4796 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4797 Err_Vars.Error_Msg_Name_2 :=
4798 The_Unit_Data.File_Names (Unit_Kind).Path;
4799 Error_Msg
4800 (Project, In_Tree,
4801 "\ project file {, {", The_Location);
4803 Err_Vars.Error_Msg_Name_1 :=
4804 In_Tree.Projects.Table (Project).Name;
4805 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4806 Error_Msg
4807 (Project, In_Tree,
4808 "\ project file {, {", The_Location);
4809 end if;
4811 -- It is a new unit, create a new record
4813 else
4814 -- First, check if there is no other unit with this file
4815 -- name in another project. If it is, report an error.
4816 -- Of course, we do that only for the first unit in the
4817 -- source file.
4819 Unit_Prj := Files_Htable.Get
4820 (In_Tree.Files_HT, Canonical_File_Name);
4822 if not File_Name_Recorded and then
4823 Unit_Prj /= No_Unit_Project
4824 then
4825 Error_Msg_Name_1 := File_Name;
4826 Error_Msg_Name_2 :=
4827 In_Tree.Projects.Table
4828 (Unit_Prj.Project).Name;
4829 Error_Msg
4830 (Project, In_Tree,
4831 "{ is already a source of project {",
4832 Location);
4834 else
4835 Unit_Table.Increment_Last (In_Tree.Units);
4836 The_Unit := Unit_Table.Last (In_Tree.Units);
4837 Units_Htable.Set
4838 (In_Tree.Units_HT, Unit_Name, The_Unit);
4839 Unit_Prj := (Unit => The_Unit, Project => Project);
4840 Files_Htable.Set
4841 (In_Tree.Files_HT,
4842 Canonical_File_Name,
4843 Unit_Prj);
4844 The_Unit_Data.Name := Unit_Name;
4845 The_Unit_Data.File_Names (Unit_Kind) :=
4846 (Name => Canonical_File_Name,
4847 Index => Unit_Index,
4848 Display_Name => File_Name,
4849 Path => Canonical_Path_Name,
4850 Display_Path => Path_Name,
4851 Project => Project,
4852 Needs_Pragma => Needs_Pragma);
4853 In_Tree.Units.Table (The_Unit) :=
4854 The_Unit_Data;
4855 Source_Recorded := True;
4856 end if;
4857 end if;
4858 end;
4860 exit when Exception_Id = No_Ada_Naming_Exception;
4861 File_Name_Recorded := True;
4862 end loop;
4863 end if;
4864 end Record_Ada_Source;
4866 --------------------------
4867 -- Record_Other_Sources --
4868 --------------------------
4870 procedure Record_Other_Sources
4871 (Project : Project_Id;
4872 In_Tree : Project_Tree_Ref;
4873 Data : in out Project_Data;
4874 Language : Language_Index;
4875 Naming_Exceptions : Boolean)
4877 Source_Dir : String_List_Id := Data.Source_Dirs;
4878 Element : String_Element;
4879 Path : Name_Id;
4881 Dir : Dir_Type;
4882 Canonical_Name : Name_Id;
4884 Name_Str : String (1 .. 1_024);
4885 Last : Natural := 0;
4886 NL : Name_Location;
4888 First_Error : Boolean := True;
4890 Suffix : constant String := Body_Suffix_Of (Language, Data, In_Tree);
4892 begin
4893 while Source_Dir /= Nil_String loop
4894 Element := In_Tree.String_Elements.Table (Source_Dir);
4896 declare
4897 Dir_Path : constant String := Get_Name_String (Element.Value);
4899 begin
4900 if Current_Verbosity = High then
4901 Write_Str ("checking directory """);
4902 Write_Str (Dir_Path);
4903 Write_Str (""" for ");
4905 if Naming_Exceptions then
4906 Write_Str ("naming exceptions");
4908 else
4909 Write_Str ("sources");
4910 end if;
4912 Write_Str (" of Language ");
4913 Display_Language_Name (Language);
4914 end if;
4916 Open (Dir, Dir_Path);
4918 loop
4919 Read (Dir, Name_Str, Last);
4920 exit when Last = 0;
4922 if Is_Regular_File
4923 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4924 then
4925 Name_Len := Last;
4926 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4927 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4928 Canonical_Name := Name_Find;
4929 NL := Source_Names.Get (Canonical_Name);
4931 if NL /= No_Name_Location then
4932 if NL.Found then
4933 if not Data.Known_Order_Of_Source_Dirs then
4934 Error_Msg_Name_1 := Canonical_Name;
4935 Error_Msg
4936 (Project, In_Tree,
4937 "{ is found in several source directories",
4938 NL.Location);
4939 end if;
4941 else
4942 NL.Found := True;
4943 Source_Names.Set (Canonical_Name, NL);
4944 Name_Len := Dir_Path'Length;
4945 Name_Buffer (1 .. Name_Len) := Dir_Path;
4946 Add_Char_To_Name_Buffer (Directory_Separator);
4947 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4948 Path := Name_Find;
4950 Check_For_Source
4951 (File_Name => Canonical_Name,
4952 Path_Name => Path,
4953 Project => Project,
4954 In_Tree => In_Tree,
4955 Data => Data,
4956 Location => NL.Location,
4957 Language => Language,
4958 Suffix => Suffix,
4959 Naming_Exception => Naming_Exceptions);
4960 end if;
4961 end if;
4962 end if;
4963 end loop;
4965 Close (Dir);
4966 end;
4968 Source_Dir := Element.Next;
4969 end loop;
4971 if not Naming_Exceptions then
4972 NL := Source_Names.Get_First;
4974 -- It is an error if a source file name in a source list or
4975 -- in a source list file is not found.
4977 while NL /= No_Name_Location loop
4978 if not NL.Found then
4979 Err_Vars.Error_Msg_Name_1 := NL.Name;
4981 if First_Error then
4982 Error_Msg
4983 (Project, In_Tree,
4984 "source file { cannot be found",
4985 NL.Location);
4986 First_Error := False;
4988 else
4989 Error_Msg
4990 (Project, In_Tree,
4991 "\source file { cannot be found",
4992 NL.Location);
4993 end if;
4994 end if;
4996 NL := Source_Names.Get_Next;
4997 end loop;
4999 -- Any naming exception of this language that is not in a list
5000 -- of sources must be removed.
5002 declare
5003 Source_Id : Other_Source_Id := Data.First_Other_Source;
5004 Prev_Id : Other_Source_Id := No_Other_Source;
5005 Source : Other_Source;
5007 begin
5008 while Source_Id /= No_Other_Source loop
5009 Source := In_Tree.Other_Sources.Table (Source_Id);
5011 if Source.Language = Language
5012 and then Source.Naming_Exception
5013 then
5014 if Current_Verbosity = High then
5015 Write_Str ("Naming exception """);
5016 Write_Str (Get_Name_String (Source.File_Name));
5017 Write_Str (""" is not in the list of sources,");
5018 Write_Line (" so it is removed.");
5019 end if;
5021 if Prev_Id = No_Other_Source then
5022 Data.First_Other_Source := Source.Next;
5024 else
5025 In_Tree.Other_Sources.Table
5026 (Prev_Id).Next := Source.Next;
5027 end if;
5029 Source_Id := Source.Next;
5031 if Source_Id = No_Other_Source then
5032 Data.Last_Other_Source := Prev_Id;
5033 end if;
5035 else
5036 Prev_Id := Source_Id;
5037 Source_Id := Source.Next;
5038 end if;
5039 end loop;
5040 end;
5041 end if;
5042 end Record_Other_Sources;
5044 ----------------------
5045 -- Show_Source_Dirs --
5046 ----------------------
5048 procedure Show_Source_Dirs
5049 (Project : Project_Id;
5050 In_Tree : Project_Tree_Ref)
5052 Current : String_List_Id;
5053 Element : String_Element;
5055 begin
5056 Write_Line ("Source_Dirs:");
5058 Current := In_Tree.Projects.Table (Project).Source_Dirs;
5059 while Current /= Nil_String loop
5060 Element := In_Tree.String_Elements.Table (Current);
5061 Write_Str (" ");
5062 Write_Line (Get_Name_String (Element.Value));
5063 Current := Element.Next;
5064 end loop;
5066 Write_Line ("end Source_Dirs.");
5067 end Show_Source_Dirs;
5069 ----------------
5070 -- Suffix_For --
5071 ----------------
5073 function Suffix_For
5074 (Language : Language_Index;
5075 Naming : Naming_Data;
5076 In_Tree : Project_Tree_Ref) return Name_Id
5078 Suffix : constant Variable_Value :=
5079 Value_Of
5080 (Index => Language_Names.Table (Language),
5081 Src_Index => 0,
5082 In_Array => Naming.Body_Suffix,
5083 In_Tree => In_Tree);
5084 begin
5085 -- If no suffix for this language in package Naming, use the default
5087 if Suffix = Nil_Variable_Value then
5088 Name_Len := 0;
5090 case Language is
5091 when Ada_Language_Index =>
5092 Add_Str_To_Name_Buffer (".adb");
5094 when C_Language_Index =>
5095 Add_Str_To_Name_Buffer (".c");
5097 when C_Plus_Plus_Language_Index =>
5098 Add_Str_To_Name_Buffer (".cc");
5100 when others =>
5101 return No_Name;
5102 end case;
5104 -- Otherwise use the one specified
5106 else
5107 Get_Name_String (Suffix.Value);
5108 end if;
5110 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5111 return Name_Find;
5112 end Suffix_For;
5114 -------------------------
5115 -- Warn_If_Not_Sources --
5116 -------------------------
5118 -- comments needed in this body ???
5120 procedure Warn_If_Not_Sources
5121 (Project : Project_Id;
5122 In_Tree : Project_Tree_Ref;
5123 Conventions : Array_Element_Id;
5124 Specs : Boolean;
5125 Extending : Boolean)
5127 Conv : Array_Element_Id := Conventions;
5128 Unit : Name_Id;
5129 The_Unit_Id : Unit_Id;
5130 The_Unit_Data : Unit_Data;
5131 Location : Source_Ptr;
5133 begin
5134 while Conv /= No_Array_Element loop
5135 Unit := In_Tree.Array_Elements.Table (Conv).Index;
5136 Error_Msg_Name_1 := Unit;
5137 Get_Name_String (Unit);
5138 To_Lower (Name_Buffer (1 .. Name_Len));
5139 Unit := Name_Find;
5140 The_Unit_Id := Units_Htable.Get
5141 (In_Tree.Units_HT, Unit);
5142 Location := In_Tree.Array_Elements.Table
5143 (Conv).Value.Location;
5145 if The_Unit_Id = No_Unit then
5146 Error_Msg
5147 (Project, In_Tree,
5148 "?unknown unit {",
5149 Location);
5151 else
5152 The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
5154 if Specs then
5155 if not Check_Project
5156 (The_Unit_Data.File_Names (Specification).Project,
5157 Project, In_Tree, Extending)
5158 then
5159 Error_Msg
5160 (Project, In_Tree,
5161 "?unit{ has no spec in this project",
5162 Location);
5163 end if;
5165 else
5166 if not Check_Project
5167 (The_Unit_Data.File_Names (Body_Part).Project,
5168 Project, In_Tree, Extending)
5169 then
5170 Error_Msg
5171 (Project, In_Tree,
5172 "?unit{ has no body in this project",
5173 Location);
5174 end if;
5175 end if;
5176 end if;
5178 Conv := In_Tree.Array_Elements.Table (Conv).Next;
5179 end loop;
5180 end Warn_If_Not_Sources;
5182 end Prj.Nmsc;