PR tree-optimization/19853
[official-gcc.git] / gcc / ada / prj-nmsc.adb
blobb56bdcc56784628f4a5c12975ffc17c00d1e7862
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-2004 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.Com; use Prj.Com;
36 with Prj.Env; use Prj.Env;
37 with Prj.Err;
38 with Prj.Util; use Prj.Util;
39 with Sinput.P;
40 with Snames; use Snames;
41 with Table; use Table;
42 with Types; use Types;
44 with Ada.Characters.Handling; use Ada.Characters.Handling;
45 with Ada.Strings; use Ada.Strings;
46 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
47 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
49 with GNAT.Case_Util; use GNAT.Case_Util;
50 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
51 with GNAT.OS_Lib; use GNAT.OS_Lib;
52 with GNAT.HTable;
54 package body Prj.Nmsc is
56 Error_Report : Put_Line_Access := null;
57 -- Set to point to error reporting procedure
59 ALI_Suffix : constant String := ".ali";
60 -- File suffix for ali files
62 Object_Suffix : constant String := Get_Object_Suffix.all;
63 -- File suffix for object files
65 type Name_Location is record
66 Name : Name_Id;
67 Location : Source_Ptr;
68 Found : Boolean := False;
69 end record;
70 -- Information about file names found in string list attribute
71 -- Source_Files or in a source list file, stored in hash table
72 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
74 No_Name_Location : constant Name_Location :=
75 (Name => No_Name, Location => No_Location, Found => False);
77 package Source_Names is new GNAT.HTable.Simple_HTable
78 (Header_Num => Header_Num,
79 Element => Name_Location,
80 No_Element => No_Name_Location,
81 Key => Name_Id,
82 Hash => Hash,
83 Equal => "=");
84 -- Hash table to store file names found in string list attribute
85 -- Source_Files or in a source list file, stored in hash table
86 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
88 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
89 (Header_Num => Header_Num,
90 Element => Boolean,
91 No_Element => False,
92 Key => Name_Id,
93 Hash => Hash,
94 Equal => "=");
95 -- Hash table to store recursive source directories, to avoid looking
96 -- several times, and to avoid cycles that may be introduced by symbolic
97 -- links.
99 type Ada_Naming_Exception_Id is new Nat;
100 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
102 type Unit_Info is record
103 Kind : Spec_Or_Body;
104 Unit : Name_Id;
105 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
106 end record;
107 -- No_Unit : constant Unit_Info :=
108 -- (Specification, No_Name, No_Ada_Naming_Exception);
110 package Ada_Naming_Exception_Table is new Table.Table
111 (Table_Component_Type => Unit_Info,
112 Table_Index_Type => Ada_Naming_Exception_Id,
113 Table_Low_Bound => 1,
114 Table_Initial => 20,
115 Table_Increment => 100,
116 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
118 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
119 (Header_Num => Header_Num,
120 Element => Ada_Naming_Exception_Id,
121 No_Element => No_Ada_Naming_Exception,
122 Key => Name_Id,
123 Hash => Hash,
124 Equal => "=");
125 -- A hash table to store naming exceptions for Ada. For each file name
126 -- there is one or several unit in table Ada_Naming_Exception_Table.
128 function Hash (Unit : Unit_Info) return Header_Num;
130 type Name_And_Index is record
131 Name : Name_Id := No_Name;
132 Index : Int := 0;
133 end record;
134 No_Name_And_Index : constant Name_And_Index :=
135 (Name => No_Name, Index => 0);
137 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
138 (Header_Num => Header_Num,
139 Element => Name_And_Index,
140 No_Element => No_Name_And_Index,
141 Key => Unit_Info,
142 Hash => Hash,
143 Equal => "=");
144 -- A table to check if a unit with an exceptional name will hide
145 -- a source with a file name following the naming convention.
147 function ALI_File_Name (Source : String) return String;
148 -- Return the ALI file name corresponding to a source
150 procedure Check_Ada_Name
151 (Name : String;
152 Unit : out Name_Id);
153 -- Check that a name is a valid Ada unit name
155 procedure Check_Naming_Scheme
156 (Data : in out Project_Data;
157 Project : Project_Id);
158 -- Check the naming scheme part of Data
160 procedure Check_Ada_Naming_Scheme_Validity
161 (Project : Project_Id;
162 Naming : Naming_Data);
163 -- Check that the package Naming is correct
165 procedure Check_For_Source
166 (File_Name : Name_Id;
167 Path_Name : Name_Id;
168 Project : Project_Id;
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 in a source directory is a source for a specific
175 -- language other than Ada. Comments required for parameters ???
177 procedure Check_If_Externally_Built
178 (Project : Project_Id;
179 Data : in out Project_Data);
180 -- ??? comment required
182 procedure Check_Library_Attributes
183 (Project : Project_Id;
184 Data : in out Project_Data);
185 -- ??? comment required
187 procedure Check_Package_Naming
188 (Project : Project_Id;
189 Data : in out Project_Data);
190 -- ??? comment required
192 procedure Check_Programming_Languages (Data : in out Project_Data);
193 -- ??? comment required
195 function Check_Project
196 (P : Project_Id;
197 Root_Project : Project_Id;
198 Extending : Boolean) return Boolean;
199 -- Returns True if P is Root_Project or, if Extending is True, a project
200 -- extended by Root_Project.
202 procedure Check_Stand_Alone_Library
203 (Project : Project_Id;
204 Data : in out Project_Data;
205 Extending : Boolean);
207 function Compute_Directory_Last (Dir : String) return Natural;
208 -- Return the index of the last significant character in Dir. This is used
209 -- to avoid duplicates '/' at the end of directory names
211 function Body_Suffix_Of
212 (Language : Language_Index; In_Project : Project_Data)
213 return String;
215 procedure Error_Msg
216 (Project : Project_Id;
217 Msg : String;
218 Flag_Location : Source_Ptr);
219 -- Output an error message. If Error_Report is null, simply call
220 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
221 -- Error_Report.
223 procedure Find_Sources
224 (Project : Project_Id;
225 Data : in out Project_Data;
226 For_Language : Language_Index;
227 Follow_Links : Boolean := False);
228 -- Find all the sources in all of the source directories of a project for
229 -- a specified language.
231 procedure Free_Ada_Naming_Exceptions;
232 -- Free the internal hash tables used for checking naming exceptions
234 procedure Get_Directories
235 (Project : Project_Id;
236 Data : in out Project_Data);
237 -- Get the object directory, the exec directory and the source directories
238 -- of a project.
240 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
241 -- Get the mains of a project from attribute Main, if it exists, and put
242 -- them in the project data.
244 procedure Get_Sources_From_File
245 (Path : String;
246 Location : Source_Ptr;
247 Project : Project_Id);
248 -- Get the list of sources from a text file and put them in hash table
249 -- Source_Names.
251 procedure Get_Unit
252 (Canonical_File_Name : Name_Id;
253 Naming : Naming_Data;
254 Exception_Id : out Ada_Naming_Exception_Id;
255 Unit_Name : out Name_Id;
256 Unit_Kind : out Spec_Or_Body;
257 Needs_Pragma : out Boolean);
258 -- Find out, from a file name, the unit name, the unit kind and if a
259 -- specific SFN pragma is needed. If the file name corresponds to no
260 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
261 -- or an exception to the naming scheme, then Exception_Id is set to
262 -- the unit or units that the source contains.
264 function Is_Illegal_Suffix
265 (Suffix : String;
266 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
267 -- Returns True if the string Suffix cannot be used as
268 -- a spec suffix, a body suffix or a separate suffix.
270 procedure Locate_Directory
271 (Name : Name_Id;
272 Parent : Name_Id;
273 Dir : out Name_Id;
274 Display : out Name_Id);
275 -- Locate a directory (returns No_Name for Dir and Display if directory
276 -- does not exist). Name is the directory name. Parent is the root
277 -- directory, if Name is a relative path name. Dir is the canonical case
278 -- path name of the directory, Display is the directory path name for
279 -- display purposes.
281 procedure Look_For_Sources
282 (Project : Project_Id;
283 Data : in out Project_Data;
284 Follow_Links : Boolean);
285 -- Comment required ???
287 function Path_Name_Of
288 (File_Name : Name_Id;
289 Directory : Name_Id) return String;
290 -- Returns the path name of a (non project) file.
291 -- Returns an empty string if file cannot be found.
293 procedure Prepare_Ada_Naming_Exceptions
294 (List : Array_Element_Id;
295 Kind : Spec_Or_Body);
296 -- Prepare the internal hash tables used for checking naming exceptions
297 -- for Ada. Insert all elements of List in the tables.
299 function Project_Extends
300 (Extending : Project_Id;
301 Extended : Project_Id) return Boolean;
302 -- Returns True if Extending is extending Extended either directly or
303 -- indirectly.
305 procedure Record_Ada_Source
306 (File_Name : Name_Id;
307 Path_Name : Name_Id;
308 Project : Project_Id;
309 Data : in out Project_Data;
310 Location : Source_Ptr;
311 Current_Source : in out String_List_Id;
312 Source_Recorded : in out Boolean;
313 Follow_Links : Boolean);
314 -- Put a unit in the list of units of a project, if the file name
315 -- corresponds to a valid unit name.
317 procedure Record_Other_Sources
318 (Project : Project_Id;
319 Data : in out Project_Data;
320 Language : Language_Index;
321 Naming_Exceptions : Boolean);
322 -- Record the sources of a language in a project.
323 -- When Naming_Exceptions is True, mark the found sources as such, to
324 -- later remove those that are not named in a list of sources.
326 procedure Show_Source_Dirs (Project : Project_Id);
327 -- List all the source directories of a project
329 function Suffix_For
330 (Language : Language_Index;
331 Naming : Naming_Data) return Name_Id;
332 -- Get the suffix for the source of a language from a package naming.
333 -- If not specified, return the default for the language.
335 procedure Warn_If_Not_Sources
336 (Project : Project_Id;
337 Conventions : Array_Element_Id;
338 Specs : Boolean;
339 Extending : Boolean);
340 -- Check that individual naming conventions apply to immediate
341 -- sources of the project; if not, issue a warning.
343 -------------------
344 -- ALI_File_Name --
345 -------------------
347 function ALI_File_Name (Source : String) return String is
348 begin
349 -- If the source name has an extension, then replace it with
350 -- the ALI suffix.
352 for Index in reverse Source'First + 1 .. Source'Last loop
353 if Source (Index) = '.' then
354 return Source (Source'First .. Index - 1) & ALI_Suffix;
355 end if;
356 end loop;
358 -- If there is no dot, or if it is the first character, just add the
359 -- ALI suffix.
361 return Source & ALI_Suffix;
362 end ALI_File_Name;
364 -----------
365 -- Check --
366 -----------
368 procedure Check
369 (Project : Project_Id;
370 Report_Error : Put_Line_Access;
371 Follow_Links : Boolean)
373 Data : Project_Data := Projects.Table (Project);
375 Extending : Boolean := False;
377 begin
378 Error_Report := Report_Error;
380 Recursive_Dirs.Reset;
382 -- Object, exec and source directories
384 Get_Directories (Project, Data);
386 -- Get the programming languages
388 Check_Programming_Languages (Data);
390 -- Library attributes
392 Check_Library_Attributes (Project, Data);
394 Check_If_Externally_Built (Project, Data);
396 if Current_Verbosity = High then
397 Show_Source_Dirs (Project);
398 end if;
400 Check_Package_Naming (Project, Data);
402 Extending := Data.Extends /= No_Project;
404 Check_Naming_Scheme (Data, Project);
406 Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
407 Prepare_Ada_Naming_Exceptions (Data.Naming.Specs, Specification);
409 -- Find the sources
411 if Data.Source_Dirs /= Nil_String then
412 Look_For_Sources (Project, Data, Follow_Links);
413 end if;
415 if Data.Ada_Sources_Present then
417 -- Check that all individual naming conventions apply to sources of
418 -- this project file.
420 Warn_If_Not_Sources
421 (Project, Data.Naming.Bodies,
422 Specs => False,
423 Extending => Extending);
424 Warn_If_Not_Sources
425 (Project, Data.Naming.Specs,
426 Specs => True,
427 Extending => Extending);
428 end if;
431 -- If it is a library project file, check if it is a standalone library
433 if Data.Library then
434 Check_Stand_Alone_Library (Project, Data, Extending);
435 end if;
437 -- Put the list of Mains, if any, in the project data
439 Get_Mains (Project, Data);
441 -- Update the project data in the Projects table
443 Projects.Table (Project) := Data;
445 Free_Ada_Naming_Exceptions;
446 end Check;
448 --------------------
449 -- Check_Ada_Name --
450 --------------------
452 procedure Check_Ada_Name
453 (Name : String;
454 Unit : out Name_Id)
456 The_Name : String := Name;
457 Real_Name : Name_Id;
458 Need_Letter : Boolean := True;
459 Last_Underscore : Boolean := False;
460 OK : Boolean := The_Name'Length > 0;
462 begin
463 To_Lower (The_Name);
465 Name_Len := The_Name'Length;
466 Name_Buffer (1 .. Name_Len) := The_Name;
467 Real_Name := Name_Find;
469 -- Check first that the given name is not an Ada reserved word
471 if Get_Name_Table_Byte (Real_Name) /= 0
472 and then Real_Name /= Name_Project
473 and then Real_Name /= Name_Extends
474 and then Real_Name /= Name_External
475 then
476 Unit := No_Name;
478 if Current_Verbosity = High then
479 Write_Str (The_Name);
480 Write_Line (" is an Ada reserved word.");
481 end if;
483 return;
484 end if;
486 for Index in The_Name'Range loop
487 if Need_Letter then
489 -- We need a letter (at the beginning, and following a dot),
490 -- but we don't have one.
492 if Is_Letter (The_Name (Index)) then
493 Need_Letter := False;
495 else
496 OK := False;
498 if Current_Verbosity = High then
499 Write_Int (Types.Int (Index));
500 Write_Str (": '");
501 Write_Char (The_Name (Index));
502 Write_Line ("' is not a letter.");
503 end if;
505 exit;
506 end if;
508 elsif Last_Underscore
509 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
510 then
511 -- Two underscores are illegal, and a dot cannot follow
512 -- an underscore.
514 OK := False;
516 if Current_Verbosity = High then
517 Write_Int (Types.Int (Index));
518 Write_Str (": '");
519 Write_Char (The_Name (Index));
520 Write_Line ("' is illegal here.");
521 end if;
523 exit;
525 elsif The_Name (Index) = '.' then
527 -- We need a letter after a dot
529 Need_Letter := True;
531 elsif The_Name (Index) = '_' then
532 Last_Underscore := True;
534 else
535 -- We need an letter or a digit
537 Last_Underscore := False;
539 if not Is_Alphanumeric (The_Name (Index)) then
540 OK := False;
542 if Current_Verbosity = High then
543 Write_Int (Types.Int (Index));
544 Write_Str (": '");
545 Write_Char (The_Name (Index));
546 Write_Line ("' is not alphanumeric.");
547 end if;
549 exit;
550 end if;
551 end if;
552 end loop;
554 -- Cannot end with an underscore or a dot
556 OK := OK and then not Need_Letter and then not Last_Underscore;
558 if OK then
559 Unit := Real_Name;
561 else
562 -- Signal a problem with No_Name
564 Unit := No_Name;
565 end if;
566 end Check_Ada_Name;
568 --------------------------------------
569 -- Check_Ada_Naming_Scheme_Validity --
570 --------------------------------------
572 procedure Check_Ada_Naming_Scheme_Validity
573 (Project : Project_Id;
574 Naming : Naming_Data)
576 begin
577 -- Only check if we are not using the standard naming scheme
579 if Naming /= Standard_Naming_Data then
580 declare
581 Dot_Replacement : constant String :=
582 Get_Name_String
583 (Naming.Dot_Replacement);
585 Spec_Suffix : constant String :=
586 Get_Name_String
587 (Naming.Ada_Spec_Suffix);
589 Body_Suffix : constant String :=
590 Get_Name_String
591 (Naming.Ada_Body_Suffix);
593 Separate_Suffix : constant String :=
594 Get_Name_String
595 (Naming.Separate_Suffix);
597 begin
598 -- Dot_Replacement cannot
599 -- - be empty
600 -- - start or end with an alphanumeric
601 -- - be a single '_'
602 -- - start with an '_' followed by an alphanumeric
603 -- - contain a '.' except if it is "."
605 if Dot_Replacement'Length = 0
606 or else Is_Alphanumeric
607 (Dot_Replacement (Dot_Replacement'First))
608 or else Is_Alphanumeric
609 (Dot_Replacement (Dot_Replacement'Last))
610 or else (Dot_Replacement (Dot_Replacement'First) = '_'
611 and then
612 (Dot_Replacement'Length = 1
613 or else
614 Is_Alphanumeric
615 (Dot_Replacement (Dot_Replacement'First + 1))))
616 or else (Dot_Replacement'Length > 1
617 and then
618 Index (Source => Dot_Replacement,
619 Pattern => ".") /= 0)
620 then
621 Error_Msg
622 (Project,
623 '"' & Dot_Replacement &
624 """ is illegal for Dot_Replacement.",
625 Naming.Dot_Repl_Loc);
626 end if;
628 -- Suffixes cannot
629 -- - be empty
631 if Is_Illegal_Suffix
632 (Spec_Suffix, Dot_Replacement = ".")
633 then
634 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Spec_Suffix;
635 Error_Msg
636 (Project,
637 "{ is illegal for Spec_Suffix",
638 Naming.Spec_Suffix_Loc);
639 end if;
641 if Is_Illegal_Suffix
642 (Body_Suffix, Dot_Replacement = ".")
643 then
644 Err_Vars.Error_Msg_Name_1 := Naming.Ada_Body_Suffix;
645 Error_Msg
646 (Project,
647 "{ is illegal for Body_Suffix",
648 Naming.Body_Suffix_Loc);
649 end if;
651 if Body_Suffix /= Separate_Suffix then
652 if Is_Illegal_Suffix
653 (Separate_Suffix, Dot_Replacement = ".")
654 then
655 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
656 Error_Msg
657 (Project,
658 "{ is illegal for Separate_Suffix",
659 Naming.Sep_Suffix_Loc);
660 end if;
661 end if;
663 -- Spec_Suffix cannot have the same termination as
664 -- Body_Suffix or Separate_Suffix
666 if Spec_Suffix'Length <= Body_Suffix'Length
667 and then
668 Body_Suffix (Body_Suffix'Last -
669 Spec_Suffix'Length + 1 ..
670 Body_Suffix'Last) = Spec_Suffix
671 then
672 Error_Msg
673 (Project,
674 "Body_Suffix (""" &
675 Body_Suffix &
676 """) cannot end with" &
677 " Spec_Suffix (""" &
678 Spec_Suffix & """).",
679 Naming.Body_Suffix_Loc);
680 end if;
682 if Body_Suffix /= Separate_Suffix
683 and then Spec_Suffix'Length <= Separate_Suffix'Length
684 and then
685 Separate_Suffix
686 (Separate_Suffix'Last - Spec_Suffix'Length + 1
688 Separate_Suffix'Last) = Spec_Suffix
689 then
690 Error_Msg
691 (Project,
692 "Separate_Suffix (""" &
693 Separate_Suffix &
694 """) cannot end with" &
695 " Spec_Suffix (""" &
696 Spec_Suffix & """).",
697 Naming.Sep_Suffix_Loc);
698 end if;
699 end;
700 end if;
701 end Check_Ada_Naming_Scheme_Validity;
703 ----------------------
704 -- Check_For_Source --
705 ----------------------
707 procedure Check_For_Source
708 (File_Name : Name_Id;
709 Path_Name : Name_Id;
710 Project : Project_Id;
711 Data : in out Project_Data;
712 Location : Source_Ptr;
713 Language : Language_Index;
714 Suffix : String;
715 Naming_Exception : Boolean)
717 Name : String := Get_Name_String (File_Name);
718 Real_Location : Source_Ptr := Location;
720 begin
721 Canonical_Case_File_Name (Name);
723 -- A file is a source of a language if Naming_Exception is True (case
724 -- of naming exceptions) or if its file name ends with the suffix.
726 if Naming_Exception or else
727 (Name'Length > Suffix'Length and then
728 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
729 then
730 if Real_Location = No_Location then
731 Real_Location := Data.Location;
732 end if;
734 declare
735 Path : String := Get_Name_String (Path_Name);
737 Path_Id : Name_Id;
738 -- The path name id (in canonical case)
740 File_Id : Name_Id;
741 -- The file name id (in canonical case)
743 Obj_Id : Name_Id;
744 -- The object file name
746 Obj_Path_Id : Name_Id;
747 -- The object path name
749 Dep_Id : Name_Id;
750 -- The dependency file name
752 Dep_Path_Id : Name_Id;
753 -- The dependency path name
755 Dot_Pos : Natural := 0;
756 -- Position of the last dot in Name
758 Source : Other_Source;
759 Source_Id : Other_Source_Id := Data.First_Other_Source;
761 begin
762 Canonical_Case_File_Name (Path);
764 -- Get the file name id
766 Name_Len := Name'Length;
767 Name_Buffer (1 .. Name_Len) := Name;
768 File_Id := Name_Find;
770 -- Get the path name id
772 Name_Len := Path'Length;
773 Name_Buffer (1 .. Name_Len) := Path;
774 Path_Id := Name_Find;
776 -- Find the position of the last dot
778 for J in reverse Name'Range loop
779 if Name (J) = '.' then
780 Dot_Pos := J;
781 exit;
782 end if;
783 end loop;
785 if Dot_Pos <= Name'First then
786 Dot_Pos := Name'Last + 1;
787 end if;
789 -- Compute the object file name
791 Get_Name_String (File_Id);
792 Name_Len := Dot_Pos - Name'First;
794 for J in Object_Suffix'Range loop
795 Name_Len := Name_Len + 1;
796 Name_Buffer (Name_Len) := Object_Suffix (J);
797 end loop;
799 Obj_Id := Name_Find;
801 -- Compute the object path name
803 Get_Name_String (Data.Object_Directory);
805 if Name_Buffer (Name_Len) /= Directory_Separator and then
806 Name_Buffer (Name_Len) /= '/'
807 then
808 Name_Len := Name_Len + 1;
809 Name_Buffer (Name_Len) := Directory_Separator;
810 end if;
812 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
813 Obj_Path_Id := Name_Find;
815 -- Compute the dependency file name
817 Get_Name_String (File_Id);
818 Name_Len := Dot_Pos - Name'First + 1;
819 Name_Buffer (Name_Len) := '.';
820 Name_Len := Name_Len + 1;
821 Name_Buffer (Name_Len) := 'd';
822 Dep_Id := Name_Find;
824 -- Compute the dependency path name
826 Get_Name_String (Data.Object_Directory);
828 if Name_Buffer (Name_Len) /= Directory_Separator and then
829 Name_Buffer (Name_Len) /= '/'
830 then
831 Name_Len := Name_Len + 1;
832 Name_Buffer (Name_Len) := Directory_Separator;
833 end if;
835 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
836 Dep_Path_Id := Name_Find;
838 -- Check if source is already in the list of source for this
839 -- project: it may have already been specified as a naming
840 -- exception for the same language or an other language, or
841 -- they may be two identical file names in different source
842 -- directories.
844 while Source_Id /= No_Other_Source loop
845 Source := Other_Sources.Table (Source_Id);
846 Source_Id := Source.Next;
848 if Source.File_Name = File_Id then
850 -- Two sources of different languages cannot have the same
851 -- file name.
853 if Source.Language /= Language then
854 Error_Msg_Name_1 := File_Name;
855 Error_Msg
856 (Project,
857 "{ cannot be a source of several languages",
858 Real_Location);
859 return;
861 -- No problem if a file has already been specified as
862 -- a naming exception of this language.
864 elsif Source.Path_Name = Path_Id then
866 -- Reset the naming exception flag, if this is not a
867 -- naming exception.
869 if not Naming_Exception then
870 Other_Sources.Table (Source_Id).Naming_Exception :=
871 False;
872 end if;
874 return;
876 -- There are several files with the same names, but the
877 -- order of the source directories is known (no /**):
878 -- only the first one encountered is kept, the other ones
879 -- are ignored.
881 elsif Data.Known_Order_Of_Source_Dirs then
882 return;
884 -- But it is an error if the order of the source directories
885 -- is not known.
887 else
888 Error_Msg_Name_1 := File_Name;
889 Error_Msg
890 (Project,
891 "{ is found in several source directories",
892 Real_Location);
893 return;
894 end if;
896 -- Two sources with different file names cannot have the same
897 -- object file name.
899 elsif Source.Object_Name = Obj_Id then
900 Error_Msg_Name_1 := File_Id;
901 Error_Msg_Name_2 := Source.File_Name;
902 Error_Msg_Name_3 := Obj_Id;
903 Error_Msg
904 (Project,
905 "{ and { have the same object file {",
906 Real_Location);
907 return;
908 end if;
909 end loop;
911 if Current_Verbosity = High then
912 Write_Str (" found ");
913 Display_Language_Name (Language);
914 Write_Str (" source """);
915 Write_Str (Get_Name_String (File_Name));
916 Write_Line ("""");
917 Write_Str (" object path = ");
918 Write_Line (Get_Name_String (Obj_Path_Id));
919 end if;
921 -- Create the Other_Source record
923 Source :=
924 (Language => Language,
925 File_Name => File_Id,
926 Path_Name => Path_Id,
927 Source_TS => File_Stamp (Path_Id),
928 Object_Name => Obj_Id,
929 Object_Path => Obj_Path_Id,
930 Object_TS => File_Stamp (Obj_Path_Id),
931 Dep_Name => Dep_Id,
932 Dep_Path => Dep_Path_Id,
933 Dep_TS => File_Stamp (Dep_Path_Id),
934 Naming_Exception => Naming_Exception,
935 Next => No_Other_Source);
937 -- And add it to the Other_Sources table
939 Other_Sources.Increment_Last;
940 Other_Sources.Table (Other_Sources.Last) := Source;
942 -- There are sources of languages other than Ada in this project
944 Data.Other_Sources_Present := True;
946 -- And there are sources of this language in this project
948 Set (Language, True, Data);
950 -- Add this source to the list of sources of languages other than
951 -- Ada of the project.
953 if Data.First_Other_Source = No_Other_Source then
954 Data.First_Other_Source := Other_Sources.Last;
956 else
957 Other_Sources.Table (Data.Last_Other_Source).Next :=
958 Other_Sources.Last;
959 end if;
961 Data.Last_Other_Source := Other_Sources.Last;
962 end;
963 end if;
964 end Check_For_Source;
966 -------------------------------
967 -- Check_If_Externally_Built --
968 -------------------------------
970 procedure Check_If_Externally_Built
971 (Project : Project_Id; Data : in out Project_Data)
973 Externally_Built : constant Variable_Value :=
974 Util.Value_Of
975 (Name_Externally_Built, Data.Decl.Attributes);
977 begin
978 if not Externally_Built.Default then
979 Get_Name_String (Externally_Built.Value);
980 To_Lower (Name_Buffer (1 .. Name_Len));
982 if Name_Buffer (1 .. Name_Len) = "true" then
983 Data.Externally_Built := True;
985 elsif Name_Buffer (1 .. Name_Len) /= "false" then
986 Error_Msg (Project,
987 "Externally_Built may only be true or false",
988 Externally_Built.Location);
989 end if;
990 end if;
992 if Current_Verbosity = High then
993 Write_Str ("Project is ");
995 if not Data.Externally_Built then
996 Write_Str ("not ");
997 end if;
999 Write_Line ("externally built.");
1000 end if;
1001 end Check_If_Externally_Built;
1003 -----------------------------
1004 -- Check_Naming_Scheme --
1005 -----------------------------
1007 procedure Check_Naming_Scheme
1008 (Data : in out Project_Data;
1009 Project : Project_Id)
1011 Naming_Id : constant Package_Id :=
1012 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1014 Naming : Package_Element;
1016 procedure Check_Unit_Names (List : Array_Element_Id);
1017 -- Check that a list of unit names contains only valid names
1019 ----------------------
1020 -- Check_Unit_Names --
1021 ----------------------
1023 procedure Check_Unit_Names (List : Array_Element_Id) is
1024 Current : Array_Element_Id := List;
1025 Element : Array_Element;
1026 Unit_Name : Name_Id;
1028 begin
1029 -- Loop through elements of the string list
1031 while Current /= No_Array_Element loop
1032 Element := Array_Elements.Table (Current);
1034 -- Put file name in canonical case
1036 Get_Name_String (Element.Value.Value);
1037 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1038 Element.Value.Value := Name_Find;
1040 -- Check that it contains a valid unit name
1042 Get_Name_String (Element.Index);
1043 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1045 if Unit_Name = No_Name then
1046 Err_Vars.Error_Msg_Name_1 := Element.Index;
1047 Error_Msg
1048 (Project,
1049 "{ is not a valid unit name.",
1050 Element.Value.Location);
1052 else
1053 if Current_Verbosity = High then
1054 Write_Str (" Unit (""");
1055 Write_Str (Get_Name_String (Unit_Name));
1056 Write_Line (""")");
1057 end if;
1059 Element.Index := Unit_Name;
1060 Array_Elements.Table (Current) := Element;
1061 end if;
1063 Current := Element.Next;
1064 end loop;
1065 end Check_Unit_Names;
1067 -- Start of processing for Check_Naming_Scheme
1069 begin
1070 -- If there is a package Naming, we will put in Data.Naming what is in
1071 -- this package Naming.
1073 if Naming_Id /= No_Package then
1074 Naming := Packages.Table (Naming_Id);
1076 if Current_Verbosity = High then
1077 Write_Line ("Checking ""Naming"" for Ada.");
1078 end if;
1080 declare
1081 Bodies : constant Array_Element_Id :=
1082 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
1084 Specs : constant Array_Element_Id :=
1085 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
1087 begin
1088 if Bodies /= No_Array_Element then
1090 -- We have elements in the array Body_Part
1092 if Current_Verbosity = High then
1093 Write_Line ("Found Bodies.");
1094 end if;
1096 Data.Naming.Bodies := Bodies;
1097 Check_Unit_Names (Bodies);
1099 else
1100 if Current_Verbosity = High then
1101 Write_Line ("No Bodies.");
1102 end if;
1103 end if;
1105 if Specs /= No_Array_Element then
1107 -- We have elements in the array Specs
1109 if Current_Verbosity = High then
1110 Write_Line ("Found Specs.");
1111 end if;
1113 Data.Naming.Specs := Specs;
1114 Check_Unit_Names (Specs);
1116 else
1117 if Current_Verbosity = High then
1118 Write_Line ("No Specs.");
1119 end if;
1120 end if;
1121 end;
1123 -- We are now checking if variables Dot_Replacement, Casing,
1124 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
1125 -- exist.
1127 -- For each variable, if it does not exist, we do nothing,
1128 -- because we already have the default.
1130 -- Check Dot_Replacement
1132 declare
1133 Dot_Replacement : constant Variable_Value :=
1134 Util.Value_Of
1135 (Name_Dot_Replacement,
1136 Naming.Decl.Attributes);
1138 begin
1139 pragma Assert (Dot_Replacement.Kind = Single,
1140 "Dot_Replacement is not a single string");
1142 if not Dot_Replacement.Default then
1143 Get_Name_String (Dot_Replacement.Value);
1145 if Name_Len = 0 then
1146 Error_Msg
1147 (Project,
1148 "Dot_Replacement cannot be empty",
1149 Dot_Replacement.Location);
1151 else
1152 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1153 Data.Naming.Dot_Replacement := Name_Find;
1154 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
1155 end if;
1156 end if;
1157 end;
1159 if Current_Verbosity = High then
1160 Write_Str (" Dot_Replacement = """);
1161 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
1162 Write_Char ('"');
1163 Write_Eol;
1164 end if;
1166 -- Check Casing
1168 declare
1169 Casing_String : constant Variable_Value :=
1170 Util.Value_Of
1171 (Name_Casing, Naming.Decl.Attributes);
1173 begin
1174 pragma Assert (Casing_String.Kind = Single,
1175 "Casing is not a single string");
1177 if not Casing_String.Default then
1178 declare
1179 Casing_Image : constant String :=
1180 Get_Name_String (Casing_String.Value);
1181 begin
1182 declare
1183 Casing_Value : constant Casing_Type :=
1184 Value (Casing_Image);
1185 begin
1186 -- Ignore Casing on platforms where file names are
1187 -- case-insensitive.
1189 if not File_Names_Case_Sensitive then
1190 Data.Naming.Casing := All_Lower_Case;
1192 else
1193 Data.Naming.Casing := Casing_Value;
1194 end if;
1195 end;
1197 exception
1198 when Constraint_Error =>
1199 if Casing_Image'Length = 0 then
1200 Error_Msg
1201 (Project,
1202 "Casing cannot be an empty string",
1203 Casing_String.Location);
1205 else
1206 Name_Len := Casing_Image'Length;
1207 Name_Buffer (1 .. Name_Len) := Casing_Image;
1208 Err_Vars.Error_Msg_Name_1 := Name_Find;
1209 Error_Msg
1210 (Project,
1211 "{ is not a correct Casing",
1212 Casing_String.Location);
1213 end if;
1214 end;
1215 end if;
1216 end;
1218 if Current_Verbosity = High then
1219 Write_Str (" Casing = ");
1220 Write_Str (Image (Data.Naming.Casing));
1221 Write_Char ('.');
1222 Write_Eol;
1223 end if;
1225 -- Check Spec_Suffix
1227 declare
1228 Ada_Spec_Suffix : constant Variable_Value :=
1229 Prj.Util.Value_Of
1230 (Index => Name_Ada,
1231 Src_Index => 0,
1232 In_Array => Data.Naming.Spec_Suffix);
1234 begin
1235 if Ada_Spec_Suffix.Kind = Single
1236 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
1237 then
1238 Get_Name_String (Ada_Spec_Suffix.Value);
1239 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1240 Data.Naming.Ada_Spec_Suffix := Name_Find;
1241 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
1243 else
1244 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1245 end if;
1246 end;
1248 if Current_Verbosity = High then
1249 Write_Str (" Spec_Suffix = """);
1250 Write_Str (Get_Name_String (Data.Naming.Ada_Spec_Suffix));
1251 Write_Char ('"');
1252 Write_Eol;
1253 end if;
1255 -- Check Body_Suffix
1257 declare
1258 Ada_Body_Suffix : constant Variable_Value :=
1259 Prj.Util.Value_Of
1260 (Index => Name_Ada,
1261 Src_Index => 0,
1262 In_Array => Data.Naming.Body_Suffix);
1264 begin
1265 if Ada_Body_Suffix.Kind = Single
1266 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
1267 then
1268 Get_Name_String (Ada_Body_Suffix.Value);
1269 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1270 Data.Naming.Ada_Body_Suffix := Name_Find;
1271 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
1273 else
1274 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1275 end if;
1276 end;
1278 if Current_Verbosity = High then
1279 Write_Str (" Body_Suffix = """);
1280 Write_Str (Get_Name_String (Data.Naming.Ada_Body_Suffix));
1281 Write_Char ('"');
1282 Write_Eol;
1283 end if;
1285 -- Check Separate_Suffix
1287 declare
1288 Ada_Sep_Suffix : constant Variable_Value :=
1289 Prj.Util.Value_Of
1290 (Variable_Name => Name_Separate_Suffix,
1291 In_Variables => Naming.Decl.Attributes);
1293 begin
1294 if Ada_Sep_Suffix.Default then
1295 Data.Naming.Separate_Suffix :=
1296 Data.Naming.Ada_Body_Suffix;
1298 else
1299 Get_Name_String (Ada_Sep_Suffix.Value);
1301 if Name_Len = 0 then
1302 Error_Msg
1303 (Project,
1304 "Separate_Suffix cannot be empty",
1305 Ada_Sep_Suffix.Location);
1307 else
1308 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1309 Data.Naming.Separate_Suffix := Name_Find;
1310 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
1311 end if;
1312 end if;
1313 end;
1315 if Current_Verbosity = High then
1316 Write_Str (" Separate_Suffix = """);
1317 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
1318 Write_Char ('"');
1319 Write_Eol;
1320 end if;
1322 -- Check if Data.Naming is valid
1324 Check_Ada_Naming_Scheme_Validity (Project, Data.Naming);
1326 else
1327 Data.Naming.Ada_Spec_Suffix := Default_Ada_Spec_Suffix;
1328 Data.Naming.Ada_Body_Suffix := Default_Ada_Body_Suffix;
1329 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
1330 end if;
1331 end Check_Naming_Scheme;
1333 ------------------------------
1334 -- Check_Library_Attributes --
1335 ------------------------------
1337 procedure Check_Library_Attributes
1338 (Project : Project_Id; Data : in out Project_Data)
1340 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
1342 Lib_Dir : constant Prj.Variable_Value :=
1343 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
1345 Lib_Name : constant Prj.Variable_Value :=
1346 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
1348 Lib_Version : constant Prj.Variable_Value :=
1349 Prj.Util.Value_Of
1350 (Snames.Name_Library_Version, Attributes);
1352 The_Lib_Kind : constant Prj.Variable_Value :=
1353 Prj.Util.Value_Of
1354 (Snames.Name_Library_Kind, Attributes);
1356 begin
1357 -- Special case of extending project
1359 if Data.Extends /= No_Project then
1360 declare
1361 Extended_Data : constant Project_Data :=
1362 Projects.Table (Data.Extends);
1364 begin
1365 -- If the project extended is a library project, we inherit
1366 -- the library name, if it is not redefined; we check that
1367 -- the library directory is specified; and we reset the
1368 -- library flag for the extended project.
1370 if Extended_Data.Library then
1371 if Lib_Name.Default then
1372 Data.Library_Name := Extended_Data.Library_Name;
1373 end if;
1375 if Lib_Dir.Default then
1376 if not Data.Virtual then
1377 Error_Msg
1378 (Project,
1379 "a project extending a library project must " &
1380 "specify an attribute Library_Dir",
1381 Data.Location);
1382 end if;
1383 end if;
1385 Projects.Table (Data.Extends).Library := False;
1386 end if;
1387 end;
1388 end if;
1390 pragma Assert (Lib_Dir.Kind = Single);
1392 if Lib_Dir.Value = Empty_String then
1393 if Current_Verbosity = High then
1394 Write_Line ("No library directory");
1395 end if;
1397 else
1398 -- Find path name, check that it is a directory
1400 Locate_Directory
1401 (Lib_Dir.Value, Data.Display_Directory,
1402 Data.Library_Dir, Data.Display_Library_Dir);
1404 if Data.Library_Dir = No_Name then
1406 -- Get the absolute name of the library directory that
1407 -- does not exist, to report an error.
1409 declare
1410 Dir_Name : constant String := Get_Name_String (Lib_Dir.Value);
1412 begin
1413 if Is_Absolute_Path (Dir_Name) then
1414 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
1416 else
1417 Get_Name_String (Data.Display_Directory);
1419 if Name_Buffer (Name_Len) /= Directory_Separator then
1420 Name_Len := Name_Len + 1;
1421 Name_Buffer (Name_Len) := Directory_Separator;
1422 end if;
1424 Name_Buffer
1425 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
1426 Dir_Name;
1427 Name_Len := Name_Len + Dir_Name'Length;
1428 Err_Vars.Error_Msg_Name_1 := Name_Find;
1429 end if;
1431 -- Report the error
1433 Error_Msg
1434 (Project,
1435 "library directory { does not exist",
1436 Lib_Dir.Location);
1437 end;
1439 -- comment ???
1441 elsif Data.Library_Dir = Data.Object_Directory then
1442 Error_Msg
1443 (Project,
1444 "library directory cannot be the same " &
1445 "as object directory",
1446 Lib_Dir.Location);
1447 Data.Library_Dir := No_Name;
1448 Data.Display_Library_Dir := No_Name;
1450 -- comment ???
1452 else
1453 if Current_Verbosity = High then
1454 Write_Str ("Library directory =""");
1455 Write_Str (Get_Name_String (Data.Display_Library_Dir));
1456 Write_Line ("""");
1457 end if;
1458 end if;
1459 end if;
1461 pragma Assert (Lib_Name.Kind = Single);
1463 if Lib_Name.Value = Empty_String then
1464 if Current_Verbosity = High
1465 and then Data.Library_Name = No_Name
1466 then
1467 Write_Line ("No library name");
1468 end if;
1470 else
1471 -- There is no restriction on the syntax of library names
1473 Data.Library_Name := Lib_Name.Value;
1474 end if;
1476 if Data.Library_Name /= No_Name
1477 and then Current_Verbosity = High
1478 then
1479 Write_Str ("Library name = """);
1480 Write_Str (Get_Name_String (Data.Library_Name));
1481 Write_Line ("""");
1482 end if;
1484 Data.Library :=
1485 Data.Library_Dir /= No_Name
1486 and then
1487 Data.Library_Name /= No_Name;
1489 if Data.Library then
1490 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
1491 Error_Msg
1492 (Project,
1493 "?libraries are not supported on this platform",
1494 Lib_Name.Location);
1495 Data.Library := False;
1497 else
1498 pragma Assert (Lib_Version.Kind = Single);
1500 if Lib_Version.Value = Empty_String then
1501 if Current_Verbosity = High then
1502 Write_Line ("No library version specified");
1503 end if;
1505 else
1506 Data.Lib_Internal_Name := Lib_Version.Value;
1507 end if;
1509 pragma Assert (The_Lib_Kind.Kind = Single);
1511 if The_Lib_Kind.Value = Empty_String then
1512 if Current_Verbosity = High then
1513 Write_Line ("No library kind specified");
1514 end if;
1516 else
1517 Get_Name_String (The_Lib_Kind.Value);
1519 declare
1520 Kind_Name : constant String :=
1521 To_Lower (Name_Buffer (1 .. Name_Len));
1523 OK : Boolean := True;
1525 begin
1526 if Kind_Name = "static" then
1527 Data.Library_Kind := Static;
1529 elsif Kind_Name = "dynamic" then
1530 Data.Library_Kind := Dynamic;
1532 elsif Kind_Name = "relocatable" then
1533 Data.Library_Kind := Relocatable;
1535 else
1536 Error_Msg
1537 (Project,
1538 "illegal value for Library_Kind",
1539 The_Lib_Kind.Location);
1540 OK := False;
1541 end if;
1543 if Current_Verbosity = High and then OK then
1544 Write_Str ("Library kind = ");
1545 Write_Line (Kind_Name);
1546 end if;
1548 if Data.Library_Kind /= Static and then
1549 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
1550 then
1551 Error_Msg
1552 (Project,
1553 "only static libraries are supported " &
1554 "on this platform",
1555 The_Lib_Kind.Location);
1556 Data.Library := False;
1557 end if;
1558 end;
1559 end if;
1561 if Data.Library and then Current_Verbosity = High then
1562 Write_Line ("This is a library project file");
1563 end if;
1565 end if;
1566 end if;
1567 end Check_Library_Attributes;
1569 --------------------------
1570 -- Check_Package_Naming --
1571 --------------------------
1573 procedure Check_Package_Naming
1574 (Project : Project_Id; Data : in out Project_Data)
1576 Naming_Id : constant Package_Id :=
1577 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1579 Naming : Package_Element;
1581 begin
1582 -- If there is a package Naming, we will put in Data.Naming
1583 -- what is in this package Naming.
1585 if Naming_Id /= No_Package then
1586 Naming := Packages.Table (Naming_Id);
1588 if Current_Verbosity = High then
1589 Write_Line ("Checking ""Naming"".");
1590 end if;
1592 -- Check Spec_Suffix
1594 declare
1595 Spec_Suffixs : Array_Element_Id :=
1596 Util.Value_Of
1597 (Name_Spec_Suffix,
1598 Naming.Decl.Arrays);
1600 Suffix : Array_Element_Id;
1601 Element : Array_Element;
1602 Suffix2 : Array_Element_Id;
1604 begin
1605 -- If some suffixs have been specified, we make sure that
1606 -- for each language for which a default suffix has been
1607 -- specified, there is a suffix specified, either the one
1608 -- in the project file or if there were none, the default.
1610 if Spec_Suffixs /= No_Array_Element then
1611 Suffix := Data.Naming.Spec_Suffix;
1613 while Suffix /= No_Array_Element loop
1614 Element := Array_Elements.Table (Suffix);
1615 Suffix2 := Spec_Suffixs;
1617 while Suffix2 /= No_Array_Element loop
1618 exit when Array_Elements.Table (Suffix2).Index =
1619 Element.Index;
1620 Suffix2 := Array_Elements.Table (Suffix2).Next;
1621 end loop;
1623 -- There is a registered default suffix, but no
1624 -- suffix specified in the project file.
1625 -- Add the default to the array.
1627 if Suffix2 = No_Array_Element then
1628 Array_Elements.Increment_Last;
1629 Array_Elements.Table (Array_Elements.Last) :=
1630 (Index => Element.Index,
1631 Src_Index => Element.Src_Index,
1632 Index_Case_Sensitive => False,
1633 Value => Element.Value,
1634 Next => Spec_Suffixs);
1635 Spec_Suffixs := Array_Elements.Last;
1636 end if;
1638 Suffix := Element.Next;
1639 end loop;
1641 -- Put the resulting array as the specification suffixs
1643 Data.Naming.Spec_Suffix := Spec_Suffixs;
1644 end if;
1645 end;
1647 declare
1648 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
1649 Element : Array_Element;
1651 begin
1652 while Current /= No_Array_Element loop
1653 Element := Array_Elements.Table (Current);
1654 Get_Name_String (Element.Value.Value);
1656 if Name_Len = 0 then
1657 Error_Msg
1658 (Project,
1659 "Spec_Suffix cannot be empty",
1660 Element.Value.Location);
1661 end if;
1663 Array_Elements.Table (Current) := Element;
1664 Current := Element.Next;
1665 end loop;
1666 end;
1668 -- Check Body_Suffix
1670 declare
1671 Impl_Suffixs : Array_Element_Id :=
1672 Util.Value_Of
1673 (Name_Body_Suffix,
1674 Naming.Decl.Arrays);
1676 Suffix : Array_Element_Id;
1677 Element : Array_Element;
1678 Suffix2 : Array_Element_Id;
1680 begin
1681 -- If some suffixes have been specified, we make sure that
1682 -- for each language for which a default suffix has been
1683 -- specified, there is a suffix specified, either the one
1684 -- in the project file or if there were noe, the default.
1686 if Impl_Suffixs /= No_Array_Element then
1687 Suffix := Data.Naming.Body_Suffix;
1689 while Suffix /= No_Array_Element loop
1690 Element := Array_Elements.Table (Suffix);
1691 Suffix2 := Impl_Suffixs;
1693 while Suffix2 /= No_Array_Element loop
1694 exit when Array_Elements.Table (Suffix2).Index =
1695 Element.Index;
1696 Suffix2 := Array_Elements.Table (Suffix2).Next;
1697 end loop;
1699 -- There is a registered default suffix, but no suffix was
1700 -- specified in the project file. Add the default to the
1701 -- array.
1703 if Suffix2 = No_Array_Element then
1704 Array_Elements.Increment_Last;
1705 Array_Elements.Table (Array_Elements.Last) :=
1706 (Index => Element.Index,
1707 Src_Index => Element.Src_Index,
1708 Index_Case_Sensitive => False,
1709 Value => Element.Value,
1710 Next => Impl_Suffixs);
1711 Impl_Suffixs := Array_Elements.Last;
1712 end if;
1714 Suffix := Element.Next;
1715 end loop;
1717 -- Put the resulting array as the implementation suffixs
1719 Data.Naming.Body_Suffix := Impl_Suffixs;
1720 end if;
1721 end;
1723 declare
1724 Current : Array_Element_Id := Data.Naming.Body_Suffix;
1725 Element : Array_Element;
1727 begin
1728 while Current /= No_Array_Element loop
1729 Element := Array_Elements.Table (Current);
1730 Get_Name_String (Element.Value.Value);
1732 if Name_Len = 0 then
1733 Error_Msg
1734 (Project,
1735 "Body_Suffix cannot be empty",
1736 Element.Value.Location);
1737 end if;
1739 Array_Elements.Table (Current) := Element;
1740 Current := Element.Next;
1741 end loop;
1742 end;
1744 -- Get the exceptions, if any
1746 Data.Naming.Specification_Exceptions :=
1747 Util.Value_Of
1748 (Name_Specification_Exceptions,
1749 In_Arrays => Naming.Decl.Arrays);
1751 Data.Naming.Implementation_Exceptions :=
1752 Util.Value_Of
1753 (Name_Implementation_Exceptions,
1754 In_Arrays => Naming.Decl.Arrays);
1755 end if;
1756 end Check_Package_Naming;
1758 ---------------------------------
1759 -- Check_Programming_Languages --
1760 ---------------------------------
1762 procedure Check_Programming_Languages (Data : in out Project_Data) is
1763 Languages : Variable_Value := Nil_Variable_Value;
1765 begin
1766 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
1767 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
1768 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
1770 if Data.Source_Dirs /= Nil_String then
1772 -- Check if languages are specified in this project
1774 if Languages.Default then
1776 -- Attribute Languages is not specified. So, it defaults to
1777 -- a project of language Ada only.
1779 Data.Languages (Ada_Language_Index) := True;
1781 -- No sources of languages other than Ada
1783 Data.Other_Sources_Present := False;
1785 else
1786 declare
1787 Current : String_List_Id := Languages.Values;
1788 Element : String_Element;
1789 Lang_Name : Name_Id;
1790 Index : Language_Index;
1792 begin
1793 -- Assume that there is no language specified yet
1795 Data.Other_Sources_Present := False;
1796 Data.Ada_Sources_Present := False;
1798 -- Look through all the languages specified in attribute
1799 -- Languages, if any
1801 while Current /= Nil_String loop
1802 Element := String_Elements.Table (Current);
1803 Get_Name_String (Element.Value);
1804 To_Lower (Name_Buffer (1 .. Name_Len));
1805 Lang_Name := Name_Find;
1806 Index := Language_Indexes.Get (Lang_Name);
1808 if Index = No_Language_Index then
1809 Add_Language_Name (Lang_Name);
1810 Index := Last_Language_Index;
1811 end if;
1813 Set (Index, True, Data);
1814 Set (Language_Processing => Default_Language_Processing_Data,
1815 For_Language => Index,
1816 In_Project => Data);
1818 if Index = Ada_Language_Index then
1819 Data.Ada_Sources_Present := True;
1821 else
1822 Data.Other_Sources_Present := True;
1823 end if;
1825 Current := Element.Next;
1826 end loop;
1827 end;
1828 end if;
1829 end if;
1830 end Check_Programming_Languages;
1832 -------------------
1833 -- Check_Project --
1834 -------------------
1836 function Check_Project
1837 (P : Project_Id;
1838 Root_Project : Project_Id;
1839 Extending : Boolean) return Boolean
1841 begin
1842 if P = Root_Project then
1843 return True;
1845 elsif Extending then
1846 declare
1847 Data : Project_Data := Projects.Table (Root_Project);
1849 begin
1850 while Data.Extends /= No_Project loop
1851 if P = Data.Extends then
1852 return True;
1853 end if;
1855 Data := Projects.Table (Data.Extends);
1856 end loop;
1857 end;
1858 end if;
1860 return False;
1861 end Check_Project;
1863 -------------------------------
1864 -- Check_Stand_Alone_Library --
1865 -------------------------------
1867 procedure Check_Stand_Alone_Library
1868 (Project : Project_Id;
1869 Data : in out Project_Data;
1870 Extending : Boolean)
1872 Lib_Interfaces : constant Prj.Variable_Value :=
1873 Prj.Util.Value_Of
1874 (Snames.Name_Library_Interface,
1875 Data.Decl.Attributes);
1877 Lib_Auto_Init : constant Prj.Variable_Value :=
1878 Prj.Util.Value_Of
1879 (Snames.Name_Library_Auto_Init,
1880 Data.Decl.Attributes);
1882 Lib_Src_Dir : constant Prj.Variable_Value :=
1883 Prj.Util.Value_Of
1884 (Snames.Name_Library_Src_Dir,
1885 Data.Decl.Attributes);
1887 Lib_Symbol_File : constant Prj.Variable_Value :=
1888 Prj.Util.Value_Of
1889 (Snames.Name_Library_Symbol_File,
1890 Data.Decl.Attributes);
1892 Lib_Symbol_Policy : constant Prj.Variable_Value :=
1893 Prj.Util.Value_Of
1894 (Snames.Name_Library_Symbol_Policy,
1895 Data.Decl.Attributes);
1897 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
1898 Prj.Util.Value_Of
1899 (Snames.Name_Library_Reference_Symbol_File,
1900 Data.Decl.Attributes);
1902 Auto_Init_Supported : constant Boolean :=
1903 MLib.Tgt.
1904 Standalone_Library_Auto_Init_Is_Supported;
1906 OK : Boolean := True;
1908 begin
1909 pragma Assert (Lib_Interfaces.Kind = List);
1911 -- It is a stand-alone library project file if attribute
1912 -- Library_Interface is defined.
1914 if not Lib_Interfaces.Default then
1915 SAL_Library : declare
1916 Interfaces : String_List_Id := Lib_Interfaces.Values;
1917 Interface_ALIs : String_List_Id := Nil_String;
1918 Unit : Name_Id;
1919 The_Unit_Id : Unit_Id;
1920 The_Unit_Data : Unit_Data;
1922 procedure Add_ALI_For (Source : Name_Id);
1923 -- Add an ALI file name to the list of Interface ALIs
1925 -----------------
1926 -- Add_ALI_For --
1927 -----------------
1929 procedure Add_ALI_For (Source : Name_Id) is
1930 begin
1931 Get_Name_String (Source);
1933 declare
1934 ALI : constant String :=
1935 ALI_File_Name (Name_Buffer (1 .. Name_Len));
1936 ALI_Name_Id : Name_Id;
1937 begin
1938 Name_Len := ALI'Length;
1939 Name_Buffer (1 .. Name_Len) := ALI;
1940 ALI_Name_Id := Name_Find;
1942 String_Elements.Increment_Last;
1943 String_Elements.Table (String_Elements.Last) :=
1944 (Value => ALI_Name_Id,
1945 Index => 0,
1946 Display_Value => ALI_Name_Id,
1947 Location => String_Elements.Table
1948 (Interfaces).Location,
1949 Flag => False,
1950 Next => Interface_ALIs);
1951 Interface_ALIs := String_Elements.Last;
1952 end;
1953 end Add_ALI_For;
1955 -- Start of processing for SAL_Library
1957 begin
1958 Data.Standalone_Library := True;
1960 -- Library_Interface cannot be an empty list
1962 if Interfaces = Nil_String then
1963 Error_Msg
1964 (Project,
1965 "Library_Interface cannot be an empty list",
1966 Lib_Interfaces.Location);
1967 end if;
1969 -- Process each unit name specified in the attribute
1970 -- Library_Interface.
1972 while Interfaces /= Nil_String loop
1973 Get_Name_String
1974 (String_Elements.Table (Interfaces).Value);
1975 To_Lower (Name_Buffer (1 .. Name_Len));
1977 if Name_Len = 0 then
1978 Error_Msg
1979 (Project,
1980 "an interface cannot be an empty string",
1981 String_Elements.Table (Interfaces).Location);
1983 else
1984 Unit := Name_Find;
1985 Error_Msg_Name_1 := Unit;
1986 The_Unit_Id := Units_Htable.Get (Unit);
1988 if The_Unit_Id = Prj.Com.No_Unit then
1989 Error_Msg
1990 (Project,
1991 "unknown unit {",
1992 String_Elements.Table (Interfaces).Location);
1994 else
1995 -- Check that the unit is part of the project
1997 The_Unit_Data := Units.Table (The_Unit_Id);
1999 if The_Unit_Data.File_Names
2000 (Com.Body_Part).Name /= No_Name
2001 and then The_Unit_Data.File_Names
2002 (Com.Body_Part).Path /= Slash
2003 then
2004 if Check_Project
2005 (The_Unit_Data.File_Names (Body_Part).Project,
2006 Project, Extending)
2007 then
2008 -- There is a body for this unit.
2009 -- If there is no spec, we need to check
2010 -- that it is not a subunit.
2012 if The_Unit_Data.File_Names
2013 (Specification).Name = No_Name
2014 then
2015 declare
2016 Src_Ind : Source_File_Index;
2018 begin
2019 Src_Ind := Sinput.P.Load_Project_File
2020 (Get_Name_String
2021 (The_Unit_Data.File_Names
2022 (Body_Part).Path));
2024 if Sinput.P.Source_File_Is_Subunit
2025 (Src_Ind)
2026 then
2027 Error_Msg
2028 (Project,
2029 "{ is a subunit; " &
2030 "it cannot be an interface",
2031 String_Elements.Table
2032 (Interfaces).Location);
2033 end if;
2034 end;
2035 end if;
2037 -- The unit is not a subunit, so we add
2038 -- to the Interface ALIs the ALI file
2039 -- corresponding to the body.
2041 Add_ALI_For
2042 (The_Unit_Data.File_Names (Body_Part).Name);
2044 else
2045 Error_Msg
2046 (Project,
2047 "{ is not an unit of this project",
2048 String_Elements.Table
2049 (Interfaces).Location);
2050 end if;
2052 elsif The_Unit_Data.File_Names
2053 (Com.Specification).Name /= No_Name
2054 and then The_Unit_Data.File_Names
2055 (Com.Specification).Path /= Slash
2056 and then Check_Project
2057 (The_Unit_Data.File_Names
2058 (Specification).Project,
2059 Project, Extending)
2061 then
2062 -- The unit is part of the project, it has
2063 -- a spec, but no body. We add to the Interface
2064 -- ALIs the ALI file corresponding to the spec.
2066 Add_ALI_For
2067 (The_Unit_Data.File_Names (Specification).Name);
2069 else
2070 Error_Msg
2071 (Project,
2072 "{ is not an unit of this project",
2073 String_Elements.Table (Interfaces).Location);
2074 end if;
2075 end if;
2077 end if;
2079 Interfaces := String_Elements.Table (Interfaces).Next;
2080 end loop;
2082 -- Put the list of Interface ALIs in the project data
2084 Data.Lib_Interface_ALIs := Interface_ALIs;
2086 -- Check value of attribute Library_Auto_Init and set
2087 -- Lib_Auto_Init accordingly.
2089 if Lib_Auto_Init.Default then
2091 -- If no attribute Library_Auto_Init is declared, then
2092 -- set auto init only if it is supported.
2094 Data.Lib_Auto_Init := Auto_Init_Supported;
2096 else
2097 Get_Name_String (Lib_Auto_Init.Value);
2098 To_Lower (Name_Buffer (1 .. Name_Len));
2100 if Name_Buffer (1 .. Name_Len) = "false" then
2101 Data.Lib_Auto_Init := False;
2103 elsif Name_Buffer (1 .. Name_Len) = "true" then
2104 if Auto_Init_Supported then
2105 Data.Lib_Auto_Init := True;
2107 else
2108 -- Library_Auto_Init cannot be "true" if auto init
2109 -- is not supported
2111 Error_Msg
2112 (Project,
2113 "library auto init not supported " &
2114 "on this platform",
2115 Lib_Auto_Init.Location);
2116 end if;
2118 else
2119 Error_Msg
2120 (Project,
2121 "invalid value for attribute Library_Auto_Init",
2122 Lib_Auto_Init.Location);
2123 end if;
2124 end if;
2125 end SAL_Library;
2127 -- If attribute Library_Src_Dir is defined and not the
2128 -- empty string, check if the directory exist and is not
2129 -- the object directory or one of the source directories.
2130 -- This is the directory where copies of the interface
2131 -- sources will be copied. Note that this directory may be
2132 -- the library directory.
2134 if Lib_Src_Dir.Value /= Empty_String then
2135 declare
2136 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
2138 begin
2139 Locate_Directory
2140 (Dir_Id, Data.Display_Directory,
2141 Data.Library_Src_Dir,
2142 Data.Display_Library_Src_Dir);
2144 -- If directory does not exist, report an error
2146 if Data.Library_Src_Dir = No_Name then
2148 -- Get the absolute name of the library directory
2149 -- that does not exist, to report an error.
2151 declare
2152 Dir_Name : constant String :=
2153 Get_Name_String (Dir_Id);
2155 begin
2156 if Is_Absolute_Path (Dir_Name) then
2157 Err_Vars.Error_Msg_Name_1 := Dir_Id;
2159 else
2160 Get_Name_String (Data.Directory);
2162 if Name_Buffer (Name_Len) /=
2163 Directory_Separator
2164 then
2165 Name_Len := Name_Len + 1;
2166 Name_Buffer (Name_Len) :=
2167 Directory_Separator;
2168 end if;
2170 Name_Buffer
2171 (Name_Len + 1 ..
2172 Name_Len + Dir_Name'Length) :=
2173 Dir_Name;
2174 Name_Len := Name_Len + Dir_Name'Length;
2175 Err_Vars.Error_Msg_Name_1 := Name_Find;
2176 end if;
2178 -- Report the error
2180 Error_Msg
2181 (Project,
2182 "Directory { does not exist",
2183 Lib_Src_Dir.Location);
2184 end;
2186 -- Report an error if it is the same as the object
2187 -- directory.
2189 elsif Data.Library_Src_Dir = Data.Object_Directory then
2190 Error_Msg
2191 (Project,
2192 "directory to copy interfaces cannot be " &
2193 "the object directory",
2194 Lib_Src_Dir.Location);
2195 Data.Library_Src_Dir := No_Name;
2197 -- Check if it is same as one of the source directories
2199 else
2200 declare
2201 Src_Dirs : String_List_Id := Data.Source_Dirs;
2202 Src_Dir : String_Element;
2204 begin
2205 while Src_Dirs /= Nil_String loop
2206 Src_Dir := String_Elements.Table (Src_Dirs);
2207 Src_Dirs := Src_Dir.Next;
2209 -- Report error if it is one of the source directories
2211 if Data.Library_Src_Dir = Src_Dir.Value then
2212 Error_Msg
2213 (Project,
2214 "directory to copy interfaces cannot " &
2215 "be one of the source directories",
2216 Lib_Src_Dir.Location);
2217 Data.Library_Src_Dir := No_Name;
2218 exit;
2219 end if;
2220 end loop;
2221 end;
2223 -- pages of code follow here with no comments at all ???
2225 if Data.Library_Src_Dir /= No_Name
2226 and then Current_Verbosity = High
2227 then
2228 Write_Str ("Directory to copy interfaces =""");
2229 Write_Str (Get_Name_String (Data.Library_Dir));
2230 Write_Line ("""");
2231 end if;
2232 end if;
2233 end;
2234 end if;
2236 if not Lib_Symbol_Policy.Default then
2237 declare
2238 Value : constant String :=
2239 To_Lower
2240 (Get_Name_String (Lib_Symbol_Policy.Value));
2242 begin
2243 if Value = "autonomous" or else Value = "default" then
2244 Data.Symbol_Data.Symbol_Policy := Autonomous;
2246 elsif Value = "compliant" then
2247 Data.Symbol_Data.Symbol_Policy := Compliant;
2249 elsif Value = "controlled" then
2250 Data.Symbol_Data.Symbol_Policy := Controlled;
2252 elsif Value = "restricted" then
2253 Data.Symbol_Data.Symbol_Policy := Restricted;
2255 else
2256 Error_Msg
2257 (Project,
2258 "illegal value for Library_Symbol_Policy",
2259 Lib_Symbol_Policy.Location);
2260 end if;
2261 end;
2262 end if;
2264 if Lib_Symbol_File.Default then
2265 if Data.Symbol_Data.Symbol_Policy = Restricted then
2266 Error_Msg
2267 (Project,
2268 "Library_Symbol_File needs to be defined when " &
2269 "symbol policy is Restricted",
2270 Lib_Symbol_Policy.Location);
2271 end if;
2273 else
2274 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
2276 Get_Name_String (Lib_Symbol_File.Value);
2278 if Name_Len = 0 then
2279 Error_Msg
2280 (Project,
2281 "symbol file name cannot be an empty string",
2282 Lib_Symbol_File.Location);
2284 else
2285 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2287 if OK then
2288 for J in 1 .. Name_Len loop
2289 if Name_Buffer (J) = '/'
2290 or else Name_Buffer (J) = Directory_Separator
2291 then
2292 OK := False;
2293 exit;
2294 end if;
2295 end loop;
2296 end if;
2298 if not OK then
2299 Error_Msg_Name_1 := Lib_Symbol_File.Value;
2300 Error_Msg
2301 (Project,
2302 "symbol file name { is illegal. " &
2303 "Name canot include directory info.",
2304 Lib_Symbol_File.Location);
2305 end if;
2306 end if;
2307 end if;
2309 if Lib_Ref_Symbol_File.Default then
2310 if Data.Symbol_Data.Symbol_Policy = Compliant
2311 or else Data.Symbol_Data.Symbol_Policy = Controlled
2312 then
2313 Error_Msg
2314 (Project,
2315 "a reference symbol file need to be defined",
2316 Lib_Symbol_Policy.Location);
2317 end if;
2319 else
2320 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
2322 Get_Name_String (Lib_Ref_Symbol_File.Value);
2324 if Name_Len = 0 then
2325 Error_Msg
2326 (Project,
2327 "reference symbol file name cannot be an empty string",
2328 Lib_Symbol_File.Location);
2330 else
2331 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
2333 if OK then
2334 for J in 1 .. Name_Len loop
2335 if Name_Buffer (J) = '/'
2336 or else Name_Buffer (J) = Directory_Separator
2337 then
2338 OK := False;
2339 exit;
2340 end if;
2341 end loop;
2342 end if;
2344 if not OK then
2345 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2346 Error_Msg
2347 (Project,
2348 "reference symbol file { name is illegal. " &
2349 "Name canot include directory info.",
2350 Lib_Ref_Symbol_File.Location);
2351 end if;
2353 if not Is_Regular_File
2354 (Get_Name_String (Data.Object_Directory) &
2355 Directory_Separator &
2356 Get_Name_String (Lib_Ref_Symbol_File.Value))
2357 then
2358 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
2359 Error_Msg
2360 (Project,
2361 "library reference symbol file { does not exist",
2362 Lib_Ref_Symbol_File.Location);
2363 end if;
2365 if Data.Symbol_Data.Symbol_File /= No_Name then
2366 declare
2367 Symbol : String :=
2368 Get_Name_String
2369 (Data.Symbol_Data.Symbol_File);
2371 Reference : String :=
2372 Get_Name_String
2373 (Data.Symbol_Data.Reference);
2375 begin
2376 Canonical_Case_File_Name (Symbol);
2377 Canonical_Case_File_Name (Reference);
2379 if Symbol = Reference then
2380 Error_Msg
2381 (Project,
2382 "reference symbol file and symbol file " &
2383 "cannot be the same file",
2384 Lib_Ref_Symbol_File.Location);
2385 end if;
2386 end;
2387 end if;
2388 end if;
2389 end if;
2390 end if;
2391 end Check_Stand_Alone_Library;
2393 ----------------------------
2394 -- Compute_Directory_Last --
2395 ----------------------------
2397 function Compute_Directory_Last (Dir : String) return Natural is
2398 begin
2399 if Dir'Length > 1
2400 and then (Dir (Dir'Last - 1) = Directory_Separator
2401 or else Dir (Dir'Last - 1) = '/')
2402 then
2403 return Dir'Last - 1;
2404 else
2405 return Dir'Last;
2406 end if;
2407 end Compute_Directory_Last;
2409 --------------------
2410 -- Body_Suffix_Of --
2411 --------------------
2413 function Body_Suffix_Of
2414 (Language : Language_Index;
2415 In_Project : Project_Data) return String
2417 Suffix_Id : constant Name_Id := Suffix_Of (Language, In_Project);
2418 begin
2419 if Suffix_Id /= No_Name then
2420 return Get_Name_String (Suffix_Id);
2421 else
2422 return "." & Get_Name_String (Language_Names.Table (Language));
2423 end if;
2424 end Body_Suffix_Of;
2426 ---------------
2427 -- Error_Msg --
2428 ---------------
2430 procedure Error_Msg
2431 (Project : Project_Id;
2432 Msg : String;
2433 Flag_Location : Source_Ptr)
2435 Error_Buffer : String (1 .. 5_000);
2436 Error_Last : Natural := 0;
2437 Msg_Name : Natural := 0;
2438 First : Positive := Msg'First;
2440 procedure Add (C : Character);
2441 -- Add a character to the buffer
2443 procedure Add (S : String);
2444 -- Add a string to the buffer
2446 procedure Add (Id : Name_Id);
2447 -- Add a name to the buffer
2449 ---------
2450 -- Add --
2451 ---------
2453 procedure Add (C : Character) is
2454 begin
2455 Error_Last := Error_Last + 1;
2456 Error_Buffer (Error_Last) := C;
2457 end Add;
2459 procedure Add (S : String) is
2460 begin
2461 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2462 Error_Last := Error_Last + S'Length;
2463 end Add;
2465 procedure Add (Id : Name_Id) is
2466 begin
2467 Get_Name_String (Id);
2468 Add (Name_Buffer (1 .. Name_Len));
2469 end Add;
2471 -- Start of processing for Error_Msg
2473 begin
2474 if Error_Report = null then
2475 Prj.Err.Error_Msg (Msg, Flag_Location);
2476 return;
2477 end if;
2479 -- Ignore continuation character
2481 if Msg (First) = '\' then
2482 First := First + 1;
2484 -- Warniung character is always the first one in this package
2486 elsif Msg (First) = '?' then
2487 First := First + 1;
2488 Add ("Warning: ");
2489 end if;
2491 for Index in First .. Msg'Last loop
2492 if Msg (Index) = '{' or else Msg (Index) = '%' then
2494 -- Include a name between double quotes
2496 Msg_Name := Msg_Name + 1;
2497 Add ('"');
2499 case Msg_Name is
2500 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2501 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2502 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2504 when others => null;
2505 end case;
2507 Add ('"');
2509 else
2510 Add (Msg (Index));
2511 end if;
2513 end loop;
2515 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2516 end Error_Msg;
2518 ------------------
2519 -- Find_Sources --
2520 ------------------
2522 procedure Find_Sources
2523 (Project : Project_Id;
2524 Data : in out Project_Data;
2525 For_Language : Language_Index;
2526 Follow_Links : Boolean := False)
2528 Source_Dir : String_List_Id := Data.Source_Dirs;
2529 Element : String_Element;
2530 Dir : Dir_Type;
2531 Current_Source : String_List_Id := Nil_String;
2532 Source_Recorded : Boolean := False;
2534 begin
2535 if Current_Verbosity = High then
2536 Write_Line ("Looking for sources:");
2537 end if;
2539 -- For each subdirectory
2541 while Source_Dir /= Nil_String loop
2542 begin
2543 Source_Recorded := False;
2544 Element := String_Elements.Table (Source_Dir);
2545 if Element.Value /= No_Name then
2546 Get_Name_String (Element.Display_Value);
2548 declare
2549 Source_Directory : constant String :=
2550 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2551 Dir_Last : constant Natural :=
2552 Compute_Directory_Last (Source_Directory);
2554 begin
2555 if Current_Verbosity = High then
2556 Write_Str ("Source_Dir = ");
2557 Write_Line (Source_Directory);
2558 end if;
2560 -- We look to every entry in the source directory
2562 Open (Dir, Source_Directory
2563 (Source_Directory'First .. Dir_Last));
2565 loop
2566 Read (Dir, Name_Buffer, Name_Len);
2568 if Current_Verbosity = High then
2569 Write_Str (" Checking ");
2570 Write_Line (Name_Buffer (1 .. Name_Len));
2571 end if;
2573 exit when Name_Len = 0;
2575 declare
2576 File_Name : constant Name_Id := Name_Find;
2577 Path : constant String :=
2578 Normalize_Pathname
2579 (Name => Name_Buffer (1 .. Name_Len),
2580 Directory => Source_Directory
2581 (Source_Directory'First .. Dir_Last),
2582 Resolve_Links => Follow_Links,
2583 Case_Sensitive => True);
2584 Path_Name : Name_Id;
2586 begin
2587 Name_Len := Path'Length;
2588 Name_Buffer (1 .. Name_Len) := Path;
2589 Path_Name := Name_Find;
2591 if For_Language = Ada_Language_Index then
2593 -- We attempt to register it as a source. However,
2594 -- there is no error if the file does not contain
2595 -- a valid source. But there is an error if we have
2596 -- a duplicate unit name.
2598 Record_Ada_Source
2599 (File_Name => File_Name,
2600 Path_Name => Path_Name,
2601 Project => Project,
2602 Data => Data,
2603 Location => No_Location,
2604 Current_Source => Current_Source,
2605 Source_Recorded => Source_Recorded,
2606 Follow_Links => Follow_Links);
2608 else
2609 Check_For_Source
2610 (File_Name => File_Name,
2611 Path_Name => Path_Name,
2612 Project => Project,
2613 Data => Data,
2614 Location => No_Location,
2615 Language => For_Language,
2616 Suffix =>
2617 Body_Suffix_Of (For_Language, Data),
2618 Naming_Exception => False);
2619 end if;
2620 end;
2621 end loop;
2623 Close (Dir);
2624 end;
2625 end if;
2627 exception
2628 when Directory_Error =>
2629 null;
2630 end;
2632 if Source_Recorded then
2633 String_Elements.Table (Source_Dir).Flag := True;
2634 end if;
2636 Source_Dir := Element.Next;
2637 end loop;
2639 if Current_Verbosity = High then
2640 Write_Line ("end Looking for sources.");
2641 end if;
2643 if For_Language = Ada_Language_Index then
2645 -- If we have looked for sources and found none, then
2646 -- it is an error, except if it is an extending project.
2647 -- If a non extending project is not supposed to contain
2648 -- any source, then we never call Find_Sources.
2650 if Current_Source /= Nil_String then
2651 Data.Ada_Sources_Present := True;
2653 elsif Data.Extends = No_Project then
2654 Error_Msg
2655 (Project,
2656 "there are no Ada sources in this project",
2657 Data.Location);
2658 end if;
2659 end if;
2660 end Find_Sources;
2662 --------------------------------
2663 -- Free_Ada_Naming_Exceptions --
2664 --------------------------------
2666 procedure Free_Ada_Naming_Exceptions is
2667 begin
2668 Ada_Naming_Exception_Table.Set_Last (0);
2669 Ada_Naming_Exceptions.Reset;
2670 Reverse_Ada_Naming_Exceptions.Reset;
2671 end Free_Ada_Naming_Exceptions;
2673 ---------------------
2674 -- Get_Directories --
2675 ---------------------
2677 procedure Get_Directories
2678 (Project : Project_Id;
2679 Data : in out Project_Data)
2681 Object_Dir : constant Variable_Value :=
2682 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
2684 Exec_Dir : constant Variable_Value :=
2685 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
2687 Source_Dirs : constant Variable_Value :=
2688 Util.Value_Of
2689 (Name_Source_Dirs, Data.Decl.Attributes);
2691 Last_Source_Dir : String_List_Id := Nil_String;
2693 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2694 -- Find one or several source directories, and add them
2695 -- to the list of source directories of the project.
2697 ----------------------
2698 -- Find_Source_Dirs --
2699 ----------------------
2701 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2702 Directory : constant String := Get_Name_String (From);
2703 Element : String_Element;
2705 procedure Recursive_Find_Dirs (Path : Name_Id);
2706 -- Find all the subdirectories (recursively) of Path and add them
2707 -- to the list of source directories of the project.
2709 -------------------------
2710 -- Recursive_Find_Dirs --
2711 -------------------------
2713 procedure Recursive_Find_Dirs (Path : Name_Id) is
2714 Dir : Dir_Type;
2715 Name : String (1 .. 250);
2716 Last : Natural;
2717 List : String_List_Id := Data.Source_Dirs;
2718 Element : String_Element;
2719 Found : Boolean := False;
2721 Non_Canonical_Path : Name_Id := No_Name;
2722 Canonical_Path : Name_Id := No_Name;
2724 The_Path : constant String :=
2725 Normalize_Pathname (Get_Name_String (Path)) &
2726 Directory_Separator;
2728 The_Path_Last : constant Natural :=
2729 Compute_Directory_Last (The_Path);
2731 begin
2732 Name_Len := The_Path_Last - The_Path'First + 1;
2733 Name_Buffer (1 .. Name_Len) :=
2734 The_Path (The_Path'First .. The_Path_Last);
2735 Non_Canonical_Path := Name_Find;
2736 Get_Name_String (Non_Canonical_Path);
2737 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2738 Canonical_Path := Name_Find;
2740 -- To avoid processing the same directory several times, check
2741 -- if the directory is already in Recursive_Dirs. If it is,
2742 -- then there is nothing to do, just return. If it is not, put
2743 -- it there and continue recursive processing.
2745 if Recursive_Dirs.Get (Canonical_Path) then
2746 return;
2748 else
2749 Recursive_Dirs.Set (Canonical_Path, True);
2750 end if;
2752 -- Check if directory is already in list
2754 while List /= Nil_String loop
2755 Element := String_Elements.Table (List);
2757 if Element.Value /= No_Name then
2758 Found := Element.Value = Canonical_Path;
2759 exit when Found;
2760 end if;
2762 List := Element.Next;
2763 end loop;
2765 -- If directory is not already in list, put it there
2767 if not Found then
2768 if Current_Verbosity = High then
2769 Write_Str (" ");
2770 Write_Line (The_Path (The_Path'First .. The_Path_Last));
2771 end if;
2773 String_Elements.Increment_Last;
2774 Element :=
2775 (Value => Canonical_Path,
2776 Display_Value => Non_Canonical_Path,
2777 Location => No_Location,
2778 Flag => False,
2779 Next => Nil_String,
2780 Index => 0);
2782 -- Case of first source directory
2784 if Last_Source_Dir = Nil_String then
2785 Data.Source_Dirs := String_Elements.Last;
2787 -- Here we already have source directories
2789 else
2790 -- Link the previous last to the new one
2792 String_Elements.Table (Last_Source_Dir).Next :=
2793 String_Elements.Last;
2794 end if;
2796 -- And register this source directory as the new last
2798 Last_Source_Dir := String_Elements.Last;
2799 String_Elements.Table (Last_Source_Dir) := Element;
2800 end if;
2802 -- Now look for subdirectories. We do that even when this
2803 -- directory is already in the list, because some of its
2804 -- subdirectories may not be in the list yet.
2806 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
2808 loop
2809 Read (Dir, Name, Last);
2810 exit when Last = 0;
2812 if Name (1 .. Last) /= "."
2813 and then Name (1 .. Last) /= ".."
2814 then
2815 -- Avoid . and .. directories
2817 if Current_Verbosity = High then
2818 Write_Str (" Checking ");
2819 Write_Line (Name (1 .. Last));
2820 end if;
2822 declare
2823 Path_Name : constant String :=
2824 Normalize_Pathname
2825 (Name => Name (1 .. Last),
2826 Directory =>
2827 The_Path
2828 (The_Path'First .. The_Path_Last),
2829 Resolve_Links => False,
2830 Case_Sensitive => True);
2832 begin
2833 if Is_Directory (Path_Name) then
2835 -- We have found a new subdirectory, call self
2837 Name_Len := Path_Name'Length;
2838 Name_Buffer (1 .. Name_Len) := Path_Name;
2839 Recursive_Find_Dirs (Name_Find);
2840 end if;
2841 end;
2842 end if;
2843 end loop;
2845 Close (Dir);
2847 exception
2848 when Directory_Error =>
2849 null;
2850 end Recursive_Find_Dirs;
2852 -- Start of processing for Find_Source_Dirs
2854 begin
2855 if Current_Verbosity = High then
2856 Write_Str ("Find_Source_Dirs (""");
2857 Write_Str (Directory);
2858 Write_Line (""")");
2859 end if;
2861 -- First, check if we are looking for a directory tree,
2862 -- indicated by "/**" at the end.
2864 if Directory'Length >= 3
2865 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
2866 and then (Directory (Directory'Last - 2) = '/'
2867 or else
2868 Directory (Directory'Last - 2) = Directory_Separator)
2869 then
2870 Data.Known_Order_Of_Source_Dirs := False;
2872 Name_Len := Directory'Length - 3;
2874 if Name_Len = 0 then
2876 -- This is the case of "/**": all directories
2877 -- in the file system.
2879 Name_Len := 1;
2880 Name_Buffer (1) := Directory (Directory'First);
2882 else
2883 Name_Buffer (1 .. Name_Len) :=
2884 Directory (Directory'First .. Directory'Last - 3);
2885 end if;
2887 if Current_Verbosity = High then
2888 Write_Str ("Looking for all subdirectories of """);
2889 Write_Str (Name_Buffer (1 .. Name_Len));
2890 Write_Line ("""");
2891 end if;
2893 declare
2894 Base_Dir : constant Name_Id := Name_Find;
2895 Root_Dir : constant String :=
2896 Normalize_Pathname
2897 (Name => Get_Name_String (Base_Dir),
2898 Directory =>
2899 Get_Name_String (Data.Display_Directory),
2900 Resolve_Links => False,
2901 Case_Sensitive => True);
2903 begin
2904 if Root_Dir'Length = 0 then
2905 Err_Vars.Error_Msg_Name_1 := Base_Dir;
2907 if Location = No_Location then
2908 Error_Msg
2909 (Project,
2910 "{ is not a valid directory.",
2911 Data.Location);
2912 else
2913 Error_Msg
2914 (Project,
2915 "{ is not a valid directory.",
2916 Location);
2917 end if;
2919 else
2920 -- We have an existing directory, we register it and all
2921 -- of its subdirectories.
2923 if Current_Verbosity = High then
2924 Write_Line ("Looking for source directories:");
2925 end if;
2927 Name_Len := Root_Dir'Length;
2928 Name_Buffer (1 .. Name_Len) := Root_Dir;
2929 Recursive_Find_Dirs (Name_Find);
2931 if Current_Verbosity = High then
2932 Write_Line ("End of looking for source directories.");
2933 end if;
2934 end if;
2935 end;
2937 -- We have a single directory
2939 else
2940 declare
2941 Path_Name : Name_Id;
2942 Display_Path_Name : Name_Id;
2944 begin
2945 Locate_Directory
2946 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
2948 if Path_Name = No_Name then
2949 Err_Vars.Error_Msg_Name_1 := From;
2951 if Location = No_Location then
2952 Error_Msg
2953 (Project,
2954 "{ is not a valid directory",
2955 Data.Location);
2956 else
2957 Error_Msg
2958 (Project,
2959 "{ is not a valid directory",
2960 Location);
2961 end if;
2963 else
2964 -- As it is an existing directory, we add it to
2965 -- the list of directories.
2967 String_Elements.Increment_Last;
2968 Element.Value := Path_Name;
2969 Element.Display_Value := Display_Path_Name;
2971 if Last_Source_Dir = Nil_String then
2973 -- This is the first source directory
2975 Data.Source_Dirs := String_Elements.Last;
2977 else
2978 -- We already have source directories,
2979 -- link the previous last to the new one.
2981 String_Elements.Table (Last_Source_Dir).Next :=
2982 String_Elements.Last;
2983 end if;
2985 -- And register this source directory as the new last
2987 Last_Source_Dir := String_Elements.Last;
2988 String_Elements.Table (Last_Source_Dir) := Element;
2989 end if;
2990 end;
2991 end if;
2992 end Find_Source_Dirs;
2994 -- Start of processing for Get_Directories
2996 begin
2997 if Current_Verbosity = High then
2998 Write_Line ("Starting to look for directories");
2999 end if;
3001 -- Check the object directory
3003 pragma Assert (Object_Dir.Kind = Single,
3004 "Object_Dir is not a single string");
3006 -- We set the object directory to its default
3008 Data.Object_Directory := Data.Directory;
3009 Data.Display_Object_Dir := Data.Display_Directory;
3011 if Object_Dir.Value /= Empty_String then
3012 Get_Name_String (Object_Dir.Value);
3014 if Name_Len = 0 then
3015 Error_Msg
3016 (Project,
3017 "Object_Dir cannot be empty",
3018 Object_Dir.Location);
3020 else
3021 -- We check that the specified object directory does exist
3023 Locate_Directory
3024 (Object_Dir.Value, Data.Display_Directory,
3025 Data.Object_Directory, Data.Display_Object_Dir);
3027 if Data.Object_Directory = No_Name then
3029 -- The object directory does not exist, report an error
3031 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3032 Error_Msg
3033 (Project,
3034 "the object directory { cannot be found",
3035 Data.Location);
3037 -- Do not keep a nil Object_Directory. Set it to the specified
3038 -- (relative or absolute) path. This is for the benefit of
3039 -- tools that recover from errors; for example, these tools
3040 -- could create the non existent directory.
3042 Data.Display_Object_Dir := Object_Dir.Value;
3043 Get_Name_String (Object_Dir.Value);
3044 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3045 Data.Object_Directory := Name_Find;
3046 end if;
3047 end if;
3048 end if;
3050 if Current_Verbosity = High then
3051 if Data.Object_Directory = No_Name then
3052 Write_Line ("No object directory");
3053 else
3054 Write_Str ("Object directory: """);
3055 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3056 Write_Line ("""");
3057 end if;
3058 end if;
3060 -- Check the exec directory
3062 pragma Assert (Exec_Dir.Kind = Single,
3063 "Exec_Dir is not a single string");
3065 -- We set the object directory to its default
3067 Data.Exec_Directory := Data.Object_Directory;
3068 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3070 if Exec_Dir.Value /= Empty_String then
3071 Get_Name_String (Exec_Dir.Value);
3073 if Name_Len = 0 then
3074 Error_Msg
3075 (Project,
3076 "Exec_Dir cannot be empty",
3077 Exec_Dir.Location);
3079 else
3080 -- We check that the specified object directory
3081 -- does exist.
3083 Locate_Directory
3084 (Exec_Dir.Value, Data.Directory,
3085 Data.Exec_Directory, Data.Display_Exec_Dir);
3087 if Data.Exec_Directory = No_Name then
3088 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3089 Error_Msg
3090 (Project,
3091 "the exec directory { cannot be found",
3092 Data.Location);
3093 end if;
3094 end if;
3095 end if;
3097 if Current_Verbosity = High then
3098 if Data.Exec_Directory = No_Name then
3099 Write_Line ("No exec directory");
3100 else
3101 Write_Str ("Exec directory: """);
3102 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3103 Write_Line ("""");
3104 end if;
3105 end if;
3107 -- Look for the source directories
3109 if Current_Verbosity = High then
3110 Write_Line ("Starting to look for source directories");
3111 end if;
3113 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
3115 if Source_Dirs.Default then
3117 -- No Source_Dirs specified: the single source directory
3118 -- is the one containing the project file
3120 String_Elements.Increment_Last;
3121 Data.Source_Dirs := String_Elements.Last;
3122 String_Elements.Table (Data.Source_Dirs) :=
3123 (Value => Data.Directory,
3124 Display_Value => Data.Display_Directory,
3125 Location => No_Location,
3126 Flag => False,
3127 Next => Nil_String,
3128 Index => 0);
3130 if Current_Verbosity = High then
3131 Write_Line ("Single source directory:");
3132 Write_Str (" """);
3133 Write_Str (Get_Name_String (Data.Display_Directory));
3134 Write_Line ("""");
3135 end if;
3137 elsif Source_Dirs.Values = Nil_String then
3139 -- If Source_Dirs is an empty string list, this means
3140 -- that this project contains no source. For projects that
3141 -- don't extend other projects, this also means that there is no
3142 -- need for an object directory, if not specified.
3144 if Data.Extends = No_Project
3145 and then Data.Object_Directory = Data.Directory
3146 then
3147 Data.Object_Directory := No_Name;
3148 end if;
3150 Data.Source_Dirs := Nil_String;
3151 Data.Ada_Sources_Present := False;
3152 Data.Other_Sources_Present := False;
3154 else
3155 declare
3156 Source_Dir : String_List_Id := Source_Dirs.Values;
3157 Element : String_Element;
3159 begin
3160 -- We will find the source directories for each
3161 -- element of the list
3163 while Source_Dir /= Nil_String loop
3164 Element := String_Elements.Table (Source_Dir);
3165 Find_Source_Dirs (Element.Value, Element.Location);
3166 Source_Dir := Element.Next;
3167 end loop;
3168 end;
3169 end if;
3171 if Current_Verbosity = High then
3172 Write_Line ("Putting source directories in canonical cases");
3173 end if;
3175 declare
3176 Current : String_List_Id := Data.Source_Dirs;
3177 Element : String_Element;
3179 begin
3180 while Current /= Nil_String loop
3181 Element := String_Elements.Table (Current);
3182 if Element.Value /= No_Name then
3183 Get_Name_String (Element.Value);
3184 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3185 Element.Value := Name_Find;
3186 String_Elements.Table (Current) := Element;
3187 end if;
3189 Current := Element.Next;
3190 end loop;
3191 end;
3193 end Get_Directories;
3195 ---------------
3196 -- Get_Mains --
3197 ---------------
3199 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
3200 Mains : constant Variable_Value :=
3201 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
3203 begin
3204 Data.Mains := Mains.Values;
3206 -- If no Mains were specified, and if we are an extending
3207 -- project, inherit the Mains from the project we are extending.
3209 if Mains.Default then
3210 if Data.Extends /= No_Project then
3211 Data.Mains := Projects.Table (Data.Extends).Mains;
3212 end if;
3214 -- In a library project file, Main cannot be specified
3216 elsif Data.Library then
3217 Error_Msg
3218 (Project,
3219 "a library project file cannot have Main specified",
3220 Mains.Location);
3221 end if;
3222 end Get_Mains;
3224 ---------------------------
3225 -- Get_Sources_From_File --
3226 ---------------------------
3228 procedure Get_Sources_From_File
3229 (Path : String;
3230 Location : Source_Ptr;
3231 Project : Project_Id)
3233 File : Prj.Util.Text_File;
3234 Line : String (1 .. 250);
3235 Last : Natural;
3236 Source_Name : Name_Id;
3238 begin
3239 Source_Names.Reset;
3241 if Current_Verbosity = High then
3242 Write_Str ("Opening """);
3243 Write_Str (Path);
3244 Write_Line (""".");
3245 end if;
3247 -- Open the file
3249 Prj.Util.Open (File, Path);
3251 if not Prj.Util.Is_Valid (File) then
3252 Error_Msg (Project, "file does not exist", Location);
3253 else
3254 -- Read the lines one by one
3256 while not Prj.Util.End_Of_File (File) loop
3257 Prj.Util.Get_Line (File, Line, Last);
3259 -- A non empty, non comment line should contain a file name
3261 if Last /= 0
3262 and then (Last = 1 or else Line (1 .. 2) /= "--")
3263 then
3264 -- ??? we should check that there is no directory information
3266 Name_Len := Last;
3267 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
3268 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3269 Source_Name := Name_Find;
3270 Source_Names.Set
3271 (K => Source_Name,
3272 E =>
3273 (Name => Source_Name,
3274 Location => Location,
3275 Found => False));
3276 end if;
3277 end loop;
3279 Prj.Util.Close (File);
3281 end if;
3282 end Get_Sources_From_File;
3284 --------------
3285 -- Get_Unit --
3286 --------------
3288 procedure Get_Unit
3289 (Canonical_File_Name : Name_Id;
3290 Naming : Naming_Data;
3291 Exception_Id : out Ada_Naming_Exception_Id;
3292 Unit_Name : out Name_Id;
3293 Unit_Kind : out Spec_Or_Body;
3294 Needs_Pragma : out Boolean)
3296 Info_Id : Ada_Naming_Exception_Id
3297 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
3298 VMS_Name : Name_Id;
3300 begin
3301 if Info_Id = No_Ada_Naming_Exception then
3302 if Hostparm.OpenVMS then
3303 VMS_Name := Canonical_File_Name;
3304 Get_Name_String (VMS_Name);
3306 if Name_Buffer (Name_Len) = '.' then
3307 Name_Len := Name_Len - 1;
3308 VMS_Name := Name_Find;
3309 end if;
3311 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
3312 end if;
3314 end if;
3316 if Info_Id /= No_Ada_Naming_Exception then
3317 Exception_Id := Info_Id;
3318 Unit_Name := No_Name;
3319 Unit_Kind := Specification;
3320 Needs_Pragma := True;
3321 return;
3322 end if;
3324 Needs_Pragma := False;
3325 Exception_Id := No_Ada_Naming_Exception;
3327 Get_Name_String (Canonical_File_Name);
3329 declare
3330 File : String := Name_Buffer (1 .. Name_Len);
3331 First : constant Positive := File'First;
3332 Last : Natural := File'Last;
3333 Standard_GNAT : Boolean;
3335 begin
3336 Standard_GNAT :=
3337 Naming.Ada_Spec_Suffix = Default_Ada_Spec_Suffix
3338 and then Naming.Ada_Body_Suffix = Default_Ada_Body_Suffix;
3340 -- Check if the end of the file name is Specification_Append
3342 Get_Name_String (Naming.Ada_Spec_Suffix);
3344 if File'Length > Name_Len
3345 and then File (Last - Name_Len + 1 .. Last) =
3346 Name_Buffer (1 .. Name_Len)
3347 then
3348 -- We have a spec
3350 Unit_Kind := Specification;
3351 Last := Last - Name_Len;
3353 if Current_Verbosity = High then
3354 Write_Str (" Specification: ");
3355 Write_Line (File (First .. Last));
3356 end if;
3358 else
3359 Get_Name_String (Naming.Ada_Body_Suffix);
3361 -- Check if the end of the file name is Body_Append
3363 if File'Length > Name_Len
3364 and then File (Last - Name_Len + 1 .. Last) =
3365 Name_Buffer (1 .. Name_Len)
3366 then
3367 -- We have a body
3369 Unit_Kind := Body_Part;
3370 Last := Last - Name_Len;
3372 if Current_Verbosity = High then
3373 Write_Str (" Body: ");
3374 Write_Line (File (First .. Last));
3375 end if;
3377 elsif Naming.Separate_Suffix /= Naming.Ada_Spec_Suffix then
3378 Get_Name_String (Naming.Separate_Suffix);
3380 -- Check if the end of the file name is Separate_Append
3382 if File'Length > Name_Len
3383 and then File (Last - Name_Len + 1 .. Last) =
3384 Name_Buffer (1 .. Name_Len)
3385 then
3386 -- We have a separate (a body)
3388 Unit_Kind := Body_Part;
3389 Last := Last - Name_Len;
3391 if Current_Verbosity = High then
3392 Write_Str (" Separate: ");
3393 Write_Line (File (First .. Last));
3394 end if;
3396 else
3397 Last := 0;
3398 end if;
3400 else
3401 Last := 0;
3402 end if;
3403 end if;
3405 if Last = 0 then
3407 -- This is not a source file
3409 Unit_Name := No_Name;
3410 Unit_Kind := Specification;
3412 if Current_Verbosity = High then
3413 Write_Line (" Not a valid file name.");
3414 end if;
3416 return;
3417 end if;
3419 Get_Name_String (Naming.Dot_Replacement);
3420 Standard_GNAT :=
3421 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
3423 if Name_Buffer (1 .. Name_Len) /= "." then
3425 -- If Dot_Replacement is not a single dot, then there should
3426 -- not be any dot in the name.
3428 for Index in First .. Last loop
3429 if File (Index) = '.' then
3430 if Current_Verbosity = High then
3431 Write_Line
3432 (" Not a valid file name (some dot not replaced).");
3433 end if;
3435 Unit_Name := No_Name;
3436 return;
3438 end if;
3439 end loop;
3441 -- Replace the substring Dot_Replacement with dots
3443 declare
3444 Index : Positive := First;
3446 begin
3447 while Index <= Last - Name_Len + 1 loop
3449 if File (Index .. Index + Name_Len - 1) =
3450 Name_Buffer (1 .. Name_Len)
3451 then
3452 File (Index) := '.';
3454 if Name_Len > 1 and then Index < Last then
3455 File (Index + 1 .. Last - Name_Len + 1) :=
3456 File (Index + Name_Len .. Last);
3457 end if;
3459 Last := Last - Name_Len + 1;
3460 end if;
3462 Index := Index + 1;
3463 end loop;
3464 end;
3465 end if;
3467 -- Check if the casing is right
3469 declare
3470 Src : String := File (First .. Last);
3472 begin
3473 case Naming.Casing is
3474 when All_Lower_Case =>
3475 Fixed.Translate
3476 (Source => Src,
3477 Mapping => Lower_Case_Map);
3479 when All_Upper_Case =>
3480 Fixed.Translate
3481 (Source => Src,
3482 Mapping => Upper_Case_Map);
3484 when Mixed_Case | Unknown =>
3485 null;
3486 end case;
3488 if Src /= File (First .. Last) then
3489 if Current_Verbosity = High then
3490 Write_Line (" Not a valid file name (casing).");
3491 end if;
3493 Unit_Name := No_Name;
3494 return;
3495 end if;
3497 -- We put the name in lower case
3499 Fixed.Translate
3500 (Source => Src,
3501 Mapping => Lower_Case_Map);
3503 -- In the standard GNAT naming scheme, check for special cases:
3504 -- children or separates of A, G, I or S, and run time sources.
3506 if Standard_GNAT and then Src'Length >= 3 then
3507 declare
3508 S1 : constant Character := Src (Src'First);
3509 S2 : constant Character := Src (Src'First + 1);
3511 begin
3512 if S1 = 'a' or else S1 = 'g'
3513 or else S1 = 'i' or else S1 = 's'
3514 then
3515 -- Children or separates of packages A, G, I or S
3517 if (Hostparm.OpenVMS and then S2 = '$')
3518 or else (not Hostparm.OpenVMS and then S2 = '~')
3519 then
3520 Src (Src'First + 1) := '.';
3522 -- If it is potentially a run time source, disable
3523 -- filling of the mapping file to avoid warnings.
3525 elsif S2 = '.' then
3526 Set_Mapping_File_Initial_State_To_Empty;
3527 end if;
3529 end if;
3530 end;
3531 end if;
3533 if Current_Verbosity = High then
3534 Write_Str (" ");
3535 Write_Line (Src);
3536 end if;
3538 -- Now, we check if this name is a valid unit name
3540 Check_Ada_Name (Name => Src, Unit => Unit_Name);
3541 end;
3543 end;
3544 end Get_Unit;
3546 ----------
3547 -- Hash --
3548 ----------
3550 function Hash (Unit : Unit_Info) return Header_Num is
3551 begin
3552 return Header_Num (Unit.Unit mod 2048);
3553 end Hash;
3555 -----------------------
3556 -- Is_Illegal_Suffix --
3557 -----------------------
3559 function Is_Illegal_Suffix
3560 (Suffix : String;
3561 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
3563 begin
3564 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
3565 return True;
3566 end if;
3568 -- If dot replacement is a single dot, and first character of
3569 -- suffix is also a dot
3571 if Dot_Replacement_Is_A_Single_Dot
3572 and then Suffix (Suffix'First) = '.'
3573 then
3574 for Index in Suffix'First + 1 .. Suffix'Last loop
3576 -- If there is another dot
3578 if Suffix (Index) = '.' then
3580 -- It is illegal to have a letter following the initial dot
3582 return Is_Letter (Suffix (Suffix'First + 1));
3583 end if;
3584 end loop;
3585 end if;
3587 -- Everything is OK
3589 return False;
3590 end Is_Illegal_Suffix;
3592 ----------------------
3593 -- Locate_Directory --
3594 ----------------------
3596 procedure Locate_Directory
3597 (Name : Name_Id;
3598 Parent : Name_Id;
3599 Dir : out Name_Id;
3600 Display : out Name_Id)
3602 The_Name : constant String := Get_Name_String (Name);
3604 The_Parent : constant String :=
3605 Get_Name_String (Parent) & Directory_Separator;
3607 The_Parent_Last : constant Natural :=
3608 Compute_Directory_Last (The_Parent);
3610 begin
3611 if Current_Verbosity = High then
3612 Write_Str ("Locate_Directory (""");
3613 Write_Str (The_Name);
3614 Write_Str (""", """);
3615 Write_Str (The_Parent);
3616 Write_Line (""")");
3617 end if;
3619 Dir := No_Name;
3620 Display := No_Name;
3622 if Is_Absolute_Path (The_Name) then
3623 if Is_Directory (The_Name) then
3624 declare
3625 Normed : constant String :=
3626 Normalize_Pathname
3627 (The_Name,
3628 Resolve_Links => False,
3629 Case_Sensitive => True);
3631 Canonical_Path : constant String :=
3632 Normalize_Pathname
3633 (Normed,
3634 Resolve_Links => True,
3635 Case_Sensitive => False);
3637 begin
3638 Name_Len := Normed'Length;
3639 Name_Buffer (1 .. Name_Len) := Normed;
3640 Display := Name_Find;
3642 Name_Len := Canonical_Path'Length;
3643 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3644 Dir := Name_Find;
3645 end;
3646 end if;
3648 else
3649 declare
3650 Full_Path : constant String :=
3651 The_Parent (The_Parent'First .. The_Parent_Last) &
3652 The_Name;
3654 begin
3655 if Is_Directory (Full_Path) then
3656 declare
3657 Normed : constant String :=
3658 Normalize_Pathname
3659 (Full_Path,
3660 Resolve_Links => False,
3661 Case_Sensitive => True);
3663 Canonical_Path : constant String :=
3664 Normalize_Pathname
3665 (Normed,
3666 Resolve_Links => True,
3667 Case_Sensitive => False);
3669 begin
3670 Name_Len := Normed'Length;
3671 Name_Buffer (1 .. Name_Len) := Normed;
3672 Display := Name_Find;
3674 Name_Len := Canonical_Path'Length;
3675 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3676 Dir := Name_Find;
3677 end;
3678 end if;
3679 end;
3680 end if;
3681 end Locate_Directory;
3683 ----------------------
3684 -- Look_For_Sources --
3685 ----------------------
3687 procedure Look_For_Sources
3688 (Project : Project_Id;
3689 Data : in out Project_Data;
3690 Follow_Links : Boolean)
3692 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean);
3693 -- Find the path names of the source files in the Source_Names table
3694 -- in the source directories and record those that are Ada sources.
3696 procedure Get_Sources_From_File
3697 (Path : String;
3698 Location : Source_Ptr);
3699 -- Get the sources of a project from a text file
3701 ---------------------------------------
3702 -- Get_Path_Names_And_Record_Sources --
3703 ---------------------------------------
3705 procedure Get_Path_Names_And_Record_Sources (Follow_Links : Boolean) is
3706 Source_Dir : String_List_Id := Data.Source_Dirs;
3707 Element : String_Element;
3708 Path : Name_Id;
3710 Dir : Dir_Type;
3711 Name : Name_Id;
3712 Canonical_Name : Name_Id;
3713 Name_Str : String (1 .. 1_024);
3714 Last : Natural := 0;
3715 NL : Name_Location;
3717 Current_Source : String_List_Id := Nil_String;
3719 First_Error : Boolean := True;
3721 Source_Recorded : Boolean := False;
3723 begin
3724 -- We look in all source directories for the file names in the
3725 -- hash table Source_Names
3727 while Source_Dir /= Nil_String loop
3728 Source_Recorded := False;
3729 Element := String_Elements.Table (Source_Dir);
3731 declare
3732 Dir_Path : constant String := Get_Name_String (Element.Value);
3733 begin
3734 if Current_Verbosity = High then
3735 Write_Str ("checking directory """);
3736 Write_Str (Dir_Path);
3737 Write_Line ("""");
3738 end if;
3740 Open (Dir, Dir_Path);
3742 loop
3743 Read (Dir, Name_Str, Last);
3744 exit when Last = 0;
3745 Name_Len := Last;
3746 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3747 Name := Name_Find;
3748 Canonical_Case_File_Name (Name_Str (1 .. Last));
3749 Name_Len := Last;
3750 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
3751 Canonical_Name := Name_Find;
3752 NL := Source_Names.Get (Canonical_Name);
3754 if NL /= No_Name_Location and then not NL.Found then
3755 NL.Found := True;
3756 Source_Names.Set (Canonical_Name, NL);
3757 Name_Len := Dir_Path'Length;
3758 Name_Buffer (1 .. Name_Len) := Dir_Path;
3760 if Name_Buffer (Name_Len) /= Directory_Separator then
3761 Add_Char_To_Name_Buffer (Directory_Separator);
3762 end if;
3764 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
3765 Path := Name_Find;
3767 if Current_Verbosity = High then
3768 Write_Str (" found ");
3769 Write_Line (Get_Name_String (Name));
3770 end if;
3772 -- Register the source if it is an Ada compilation unit
3774 Record_Ada_Source
3775 (File_Name => Name,
3776 Path_Name => Path,
3777 Project => Project,
3778 Data => Data,
3779 Location => NL.Location,
3780 Current_Source => Current_Source,
3781 Source_Recorded => Source_Recorded,
3782 Follow_Links => Follow_Links);
3783 end if;
3784 end loop;
3786 Close (Dir);
3787 end;
3789 if Source_Recorded then
3790 String_Elements.Table (Source_Dir).Flag := True;
3791 end if;
3793 Source_Dir := Element.Next;
3794 end loop;
3796 -- It is an error if a source file name in a source list or
3797 -- in a source list file is not found.
3799 NL := Source_Names.Get_First;
3801 while NL /= No_Name_Location loop
3802 if not NL.Found then
3803 Err_Vars.Error_Msg_Name_1 := NL.Name;
3805 if First_Error then
3806 Error_Msg
3807 (Project,
3808 "source file { cannot be found",
3809 NL.Location);
3810 First_Error := False;
3812 else
3813 Error_Msg
3814 (Project,
3815 "\source file { cannot be found",
3816 NL.Location);
3817 end if;
3818 end if;
3820 NL := Source_Names.Get_Next;
3821 end loop;
3822 end Get_Path_Names_And_Record_Sources;
3824 ---------------------------
3825 -- Get_Sources_From_File --
3826 ---------------------------
3828 procedure Get_Sources_From_File
3829 (Path : String;
3830 Location : Source_Ptr)
3832 begin
3833 -- Get the list of sources from the file and put them in hash table
3834 -- Source_Names.
3836 Get_Sources_From_File (Path, Location, Project);
3838 -- Look in the source directories to find those sources
3840 Get_Path_Names_And_Record_Sources (Follow_Links);
3842 -- We should have found at least one source.
3843 -- If not, report an error.
3845 if Data.Sources = Nil_String then
3846 Error_Msg (Project,
3847 "there are no Ada sources in this project",
3848 Location);
3849 end if;
3850 end Get_Sources_From_File;
3852 begin
3853 if Data.Ada_Sources_Present then
3854 declare
3855 Sources : constant Variable_Value :=
3856 Util.Value_Of
3857 (Name_Source_Files,
3858 Data.Decl.Attributes);
3860 Source_List_File : constant Variable_Value :=
3861 Util.Value_Of
3862 (Name_Source_List_File,
3863 Data.Decl.Attributes);
3865 Locally_Removed : constant Variable_Value :=
3866 Util.Value_Of
3867 (Name_Locally_Removed_Files,
3868 Data.Decl.Attributes);
3870 begin
3871 pragma Assert
3872 (Sources.Kind = List,
3873 "Source_Files is not a list");
3875 pragma Assert
3876 (Source_List_File.Kind = Single,
3877 "Source_List_File is not a single string");
3879 if not Sources.Default then
3880 if not Source_List_File.Default then
3881 Error_Msg
3882 (Project,
3883 "?both variables source_files and " &
3884 "source_list_file are present",
3885 Source_List_File.Location);
3886 end if;
3888 -- Sources is a list of file names
3890 declare
3891 Current : String_List_Id := Sources.Values;
3892 Element : String_Element;
3893 Location : Source_Ptr;
3894 Name : Name_Id;
3896 begin
3897 Source_Names.Reset;
3899 Data.Ada_Sources_Present := Current /= Nil_String;
3901 while Current /= Nil_String loop
3902 Element := String_Elements.Table (Current);
3903 Get_Name_String (Element.Value);
3904 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3905 Name := Name_Find;
3907 -- If the element has no location, then use the
3908 -- location of Sources to report possible errors.
3910 if Element.Location = No_Location then
3911 Location := Sources.Location;
3912 else
3913 Location := Element.Location;
3914 end if;
3916 Source_Names.Set
3917 (K => Name,
3918 E =>
3919 (Name => Name,
3920 Location => Location,
3921 Found => False));
3923 Current := Element.Next;
3924 end loop;
3926 Get_Path_Names_And_Record_Sources (Follow_Links);
3927 end;
3929 -- No source_files specified
3931 -- We check Source_List_File has been specified
3933 elsif not Source_List_File.Default then
3935 -- Source_List_File is the name of the file
3936 -- that contains the source file names
3938 declare
3939 Source_File_Path_Name : constant String :=
3940 Path_Name_Of
3941 (Source_List_File.Value,
3942 Data.Directory);
3944 begin
3945 if Source_File_Path_Name'Length = 0 then
3946 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
3947 Error_Msg
3948 (Project,
3949 "file with sources { does not exist",
3950 Source_List_File.Location);
3952 else
3953 Get_Sources_From_File
3954 (Source_File_Path_Name,
3955 Source_List_File.Location);
3956 end if;
3957 end;
3959 else
3960 -- Neither Source_Files nor Source_List_File has been
3961 -- specified. Find all the files that satisfy the naming
3962 -- scheme in all the source directories.
3964 Find_Sources
3965 (Project, Data, Ada_Language_Index, Follow_Links);
3966 end if;
3968 -- If there are sources that are locally removed, mark them as
3969 -- such in the Units table.
3971 if not Locally_Removed.Default then
3973 -- Sources can be locally removed only in extending
3974 -- project files.
3976 if Data.Extends = No_Project then
3977 Error_Msg
3978 (Project,
3979 "Locally_Removed_Files can only be used " &
3980 "in an extending project file",
3981 Locally_Removed.Location);
3983 else
3984 declare
3985 Current : String_List_Id := Locally_Removed.Values;
3986 Element : String_Element;
3987 Location : Source_Ptr;
3988 OK : Boolean;
3989 Unit : Unit_Data;
3990 Name : Name_Id;
3991 Extended : Project_Id;
3993 begin
3994 while Current /= Nil_String loop
3995 Element := String_Elements.Table (Current);
3996 Get_Name_String (Element.Value);
3997 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3998 Name := Name_Find;
4000 -- If the element has no location, then use the
4001 -- location of Locally_Removed to report
4002 -- possible errors.
4004 if Element.Location = No_Location then
4005 Location := Locally_Removed.Location;
4006 else
4007 Location := Element.Location;
4008 end if;
4010 OK := False;
4012 for Index in 1 .. Units.Last loop
4013 Unit := Units.Table (Index);
4015 if Unit.File_Names (Specification).Name = Name then
4016 OK := True;
4018 -- Check that this is from a project that
4019 -- the current project extends, but not the
4020 -- current project.
4022 Extended := Unit.File_Names
4023 (Specification).Project;
4025 if Extended = Project then
4026 Error_Msg
4027 (Project,
4028 "cannot remove a source " &
4029 "of the same project",
4030 Location);
4032 elsif
4033 Project_Extends (Project, Extended)
4034 then
4035 Unit.File_Names
4036 (Specification).Path := Slash;
4037 Unit.File_Names
4038 (Specification).Needs_Pragma := False;
4039 Units.Table (Index) := Unit;
4040 Add_Forbidden_File_Name
4041 (Unit.File_Names (Specification).Name);
4042 exit;
4044 else
4045 Error_Msg
4046 (Project,
4047 "cannot remove a source from " &
4048 "another project",
4049 Location);
4050 end if;
4052 elsif
4053 Unit.File_Names (Body_Part).Name = Name
4054 then
4055 OK := True;
4057 -- Check that this is from a project that
4058 -- the current project extends, but not the
4059 -- current project.
4061 Extended := Unit.File_Names
4062 (Body_Part).Project;
4064 if Extended = Project then
4065 Error_Msg
4066 (Project,
4067 "cannot remove a source " &
4068 "of the same project",
4069 Location);
4071 elsif
4072 Project_Extends (Project, Extended)
4073 then
4074 Unit.File_Names (Body_Part).Path := Slash;
4075 Unit.File_Names (Body_Part).Needs_Pragma
4076 := False;
4077 Units.Table (Index) := Unit;
4078 Add_Forbidden_File_Name
4079 (Unit.File_Names (Body_Part).Name);
4080 exit;
4081 end if;
4083 end if;
4084 end loop;
4086 if not OK then
4087 Err_Vars.Error_Msg_Name_1 := Name;
4088 Error_Msg (Project, "unknown file {", Location);
4089 end if;
4091 Current := Element.Next;
4092 end loop;
4093 end;
4094 end if;
4095 end if;
4096 end;
4097 end if;
4099 if Data.Other_Sources_Present then
4101 -- Set Source_Present to False. It will be set back to True
4102 -- whenever a source is found.
4104 Data.Other_Sources_Present := False;
4105 for Lang in Ada_Language_Index + 1 .. Last_Language_Index loop
4107 -- For each language (other than Ada) in the project file
4109 if Is_Present (Lang, Data) then
4111 -- Reset the indication that there are sources of this
4112 -- language. It will be set back to True whenever we find a
4113 -- source of the language.
4115 Set (Lang, False, Data);
4117 -- First, get the source suffix for the language
4119 Set (Suffix => Suffix_For (Lang, Data.Naming),
4120 For_Language => Lang,
4121 In_Project => Data);
4123 -- Then, deal with the naming exceptions, if any
4125 Source_Names.Reset;
4127 declare
4128 Naming_Exceptions : constant Variable_Value :=
4129 Value_Of
4130 (Index => Language_Names.Table (Lang),
4131 Src_Index => 0,
4132 In_Array => Data.Naming.Implementation_Exceptions);
4133 Element_Id : String_List_Id;
4134 Element : String_Element;
4135 File_Id : Name_Id;
4136 Source_Found : Boolean := False;
4138 begin
4139 -- If there are naming exceptions, look through them one
4140 -- by one.
4142 if Naming_Exceptions /= Nil_Variable_Value then
4143 Element_Id := Naming_Exceptions.Values;
4145 while Element_Id /= Nil_String loop
4146 Element := String_Elements.Table (Element_Id);
4147 Get_Name_String (Element.Value);
4148 Canonical_Case_File_Name
4149 (Name_Buffer (1 .. Name_Len));
4150 File_Id := Name_Find;
4152 -- Put each naming exception in the Source_Names
4153 -- hash table, but if there are repetition, don't
4154 -- bother after the first instance.
4157 Source_Names.Get (File_Id) = No_Name_Location
4158 then
4159 Source_Found := True;
4160 Source_Names.Set
4161 (File_Id,
4162 (Name => File_Id,
4163 Location => Element.Location,
4164 Found => False));
4165 end if;
4167 Element_Id := Element.Next;
4168 end loop;
4170 -- If there is at least one naming exception, record
4171 -- those that are found in the source directories.
4173 if Source_Found then
4174 Record_Other_Sources
4175 (Project => Project,
4176 Data => Data,
4177 Language => Lang,
4178 Naming_Exceptions => True);
4179 end if;
4181 end if;
4182 end;
4184 -- Now, check if a list of sources is declared either through
4185 -- a string list (attribute Source_Files) or a text file
4186 -- (attribute Source_List_File). If a source list is declared,
4187 -- we will consider only those naming exceptions that are
4188 -- on the list.
4190 declare
4191 Sources : constant Variable_Value :=
4192 Util.Value_Of
4193 (Name_Source_Files,
4194 Data.Decl.Attributes);
4196 Source_List_File : constant Variable_Value :=
4197 Util.Value_Of
4198 (Name_Source_List_File,
4199 Data.Decl.Attributes);
4201 begin
4202 pragma Assert
4203 (Sources.Kind = List,
4204 "Source_Files is not a list");
4206 pragma Assert
4207 (Source_List_File.Kind = Single,
4208 "Source_List_File is not a single string");
4210 if not Sources.Default then
4211 if not Source_List_File.Default then
4212 Error_Msg
4213 (Project,
4214 "?both variables source_files and " &
4215 "source_list_file are present",
4216 Source_List_File.Location);
4217 end if;
4219 -- Sources is a list of file names
4221 declare
4222 Current : String_List_Id := Sources.Values;
4223 Element : String_Element;
4224 Location : Source_Ptr;
4225 Name : Name_Id;
4227 begin
4228 Source_Names.Reset;
4230 -- Put all the sources in the Source_Names hash table
4232 while Current /= Nil_String loop
4233 Element := String_Elements.Table (Current);
4234 Get_Name_String (Element.Value);
4235 Canonical_Case_File_Name
4236 (Name_Buffer (1 .. Name_Len));
4237 Name := Name_Find;
4239 -- If the element has no location, then use the
4240 -- location of Sources to report possible errors.
4242 if Element.Location = No_Location then
4243 Location := Sources.Location;
4244 else
4245 Location := Element.Location;
4246 end if;
4248 Source_Names.Set
4249 (K => Name,
4250 E =>
4251 (Name => Name,
4252 Location => Location,
4253 Found => False));
4255 Current := Element.Next;
4256 end loop;
4258 -- And look for their directories
4260 Record_Other_Sources
4261 (Project => Project,
4262 Data => Data,
4263 Language => Lang,
4264 Naming_Exceptions => False);
4265 end;
4267 -- No source_files specified
4269 -- We check if Source_List_File has been specified
4271 elsif not Source_List_File.Default then
4273 -- Source_List_File is the name of the file
4274 -- that contains the source file names
4276 declare
4277 Source_File_Path_Name : constant String :=
4278 Path_Name_Of
4279 (Source_List_File.Value,
4280 Data.Directory);
4282 begin
4283 if Source_File_Path_Name'Length = 0 then
4284 Err_Vars.Error_Msg_Name_1 :=
4285 Source_List_File.Value;
4286 Error_Msg
4287 (Project,
4288 "file with sources { does not exist",
4289 Source_List_File.Location);
4291 else
4292 -- Read the file, putting each source in the
4293 -- Source_Names hash table.
4295 Get_Sources_From_File
4296 (Source_File_Path_Name,
4297 Source_List_File.Location,
4298 Project);
4300 -- And look for their directories
4302 Record_Other_Sources
4303 (Project => Project,
4304 Data => Data,
4305 Language => Lang,
4306 Naming_Exceptions => False);
4307 end if;
4308 end;
4310 -- Neither Source_Files nor Source_List_File was specified
4312 else
4313 -- Find all the files that satisfy the naming scheme in
4314 -- all the source directories. All the naming exceptions
4315 -- that effectively exist are also part of the source
4316 -- of this language.
4318 Find_Sources (Project, Data, Lang);
4319 end if;
4320 end;
4321 end if;
4322 end loop;
4323 end if;
4324 end Look_For_Sources;
4326 ------------------
4327 -- Path_Name_Of --
4328 ------------------
4330 function Path_Name_Of
4331 (File_Name : Name_Id;
4332 Directory : Name_Id) return String
4334 Result : String_Access;
4336 The_Directory : constant String := Get_Name_String (Directory);
4338 begin
4339 Get_Name_String (File_Name);
4340 Result := Locate_Regular_File
4341 (File_Name => Name_Buffer (1 .. Name_Len),
4342 Path => The_Directory);
4344 if Result = null then
4345 return "";
4346 else
4347 Canonical_Case_File_Name (Result.all);
4348 return Result.all;
4349 end if;
4350 end Path_Name_Of;
4352 -------------------------------
4353 -- Prepare_Ada_Naming_Exceptions --
4354 -------------------------------
4356 procedure Prepare_Ada_Naming_Exceptions
4357 (List : Array_Element_Id;
4358 Kind : Spec_Or_Body)
4360 Current : Array_Element_Id := List;
4361 Element : Array_Element;
4363 Unit : Unit_Info;
4365 begin
4366 -- Traverse the list
4368 while Current /= No_Array_Element loop
4369 Element := Array_Elements.Table (Current);
4371 if Element.Index /= No_Name then
4372 Unit :=
4373 (Kind => Kind,
4374 Unit => Element.Index,
4375 Next => No_Ada_Naming_Exception);
4376 Reverse_Ada_Naming_Exceptions.Set
4377 (Unit, (Element.Value.Value, Element.Value.Index));
4378 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4379 Ada_Naming_Exception_Table.Increment_Last;
4380 Ada_Naming_Exception_Table.Table
4381 (Ada_Naming_Exception_Table.Last) := Unit;
4382 Ada_Naming_Exceptions.Set
4383 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4384 end if;
4386 Current := Element.Next;
4387 end loop;
4388 end Prepare_Ada_Naming_Exceptions;
4390 ---------------------
4391 -- Project_Extends --
4392 ---------------------
4394 function Project_Extends
4395 (Extending : Project_Id;
4396 Extended : Project_Id) return Boolean
4398 Current : Project_Id := Extending;
4399 begin
4400 loop
4401 if Current = No_Project then
4402 return False;
4404 elsif Current = Extended then
4405 return True;
4406 end if;
4408 Current := Projects.Table (Current).Extends;
4409 end loop;
4410 end Project_Extends;
4412 -----------------------
4413 -- Record_Ada_Source --
4414 -----------------------
4416 procedure Record_Ada_Source
4417 (File_Name : Name_Id;
4418 Path_Name : Name_Id;
4419 Project : Project_Id;
4420 Data : in out Project_Data;
4421 Location : Source_Ptr;
4422 Current_Source : in out String_List_Id;
4423 Source_Recorded : in out Boolean;
4424 Follow_Links : Boolean)
4426 Canonical_File_Name : Name_Id;
4427 Canonical_Path_Name : Name_Id;
4429 Exception_Id : Ada_Naming_Exception_Id;
4430 Unit_Name : Name_Id;
4431 Unit_Kind : Spec_Or_Body;
4432 Unit_Index : Int := 0;
4433 Info : Unit_Info;
4434 Name_Index : Name_And_Index;
4435 Needs_Pragma : Boolean;
4437 The_Location : Source_Ptr := Location;
4438 Previous_Source : constant String_List_Id := Current_Source;
4439 Except_Name : Name_And_Index := No_Name_And_Index;
4441 Unit_Prj : Unit_Project;
4443 File_Name_Recorded : Boolean := False;
4445 begin
4446 Get_Name_String (File_Name);
4447 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4448 Canonical_File_Name := Name_Find;
4450 declare
4451 Canonical_Path : constant String :=
4452 Normalize_Pathname
4453 (Get_Name_String (Path_Name),
4454 Resolve_Links => Follow_Links,
4455 Case_Sensitive => False);
4456 begin
4457 Name_Len := 0;
4458 Add_Str_To_Name_Buffer (Canonical_Path);
4459 Canonical_Path_Name := Name_Find;
4460 end;
4462 -- Find out the unit name, the unit kind and if it needs
4463 -- a specific SFN pragma.
4465 Get_Unit
4466 (Canonical_File_Name => Canonical_File_Name,
4467 Naming => Data.Naming,
4468 Exception_Id => Exception_Id,
4469 Unit_Name => Unit_Name,
4470 Unit_Kind => Unit_Kind,
4471 Needs_Pragma => Needs_Pragma);
4473 if Exception_Id = No_Ada_Naming_Exception and then
4474 Unit_Name = No_Name
4475 then
4476 if Current_Verbosity = High then
4477 Write_Str (" """);
4478 Write_Str (Get_Name_String (Canonical_File_Name));
4479 Write_Line (""" is not a valid source file name (ignored).");
4480 end if;
4482 else
4483 -- Check to see if the source has been hidden by an exception,
4484 -- but only if it is not an exception.
4486 if not Needs_Pragma then
4487 Except_Name :=
4488 Reverse_Ada_Naming_Exceptions.Get
4489 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4491 if Except_Name /= No_Name_And_Index then
4492 if Current_Verbosity = High then
4493 Write_Str (" """);
4494 Write_Str (Get_Name_String (Canonical_File_Name));
4495 Write_Str (""" contains a unit that is found in """);
4496 Write_Str (Get_Name_String (Except_Name.Name));
4497 Write_Line (""" (ignored).");
4498 end if;
4500 -- The file is not included in the source of the project,
4501 -- because it is hidden by the exception.
4502 -- So, there is nothing else to do.
4504 return;
4505 end if;
4506 end if;
4508 loop
4509 if Exception_Id /= No_Ada_Naming_Exception then
4510 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4511 Exception_Id := Info.Next;
4512 Info.Next := No_Ada_Naming_Exception;
4513 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4515 Unit_Name := Info.Unit;
4516 Unit_Index := Name_Index.Index;
4517 Unit_Kind := Info.Kind;
4518 end if;
4520 -- Put the file name in the list of sources of the project
4522 if not File_Name_Recorded then
4523 String_Elements.Increment_Last;
4524 String_Elements.Table (String_Elements.Last) :=
4525 (Value => Canonical_File_Name,
4526 Display_Value => File_Name,
4527 Location => No_Location,
4528 Flag => False,
4529 Next => Nil_String,
4530 Index => Unit_Index);
4531 end if;
4533 if Current_Source = Nil_String then
4534 Data.Sources := String_Elements.Last;
4535 else
4536 String_Elements.Table (Current_Source).Next :=
4537 String_Elements.Last;
4538 end if;
4540 Current_Source := String_Elements.Last;
4542 -- Put the unit in unit list
4544 declare
4545 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4546 The_Unit_Data : Unit_Data;
4548 begin
4549 if Current_Verbosity = High then
4550 Write_Str ("Putting ");
4551 Write_Str (Get_Name_String (Unit_Name));
4552 Write_Line (" in the unit list.");
4553 end if;
4555 -- The unit is already in the list, but may be it is
4556 -- only the other unit kind (spec or body), or what is
4557 -- in the unit list is a unit of a project we are extending.
4559 if The_Unit /= Prj.Com.No_Unit then
4560 The_Unit_Data := Units.Table (The_Unit);
4562 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4563 or else Project_Extends
4564 (Data.Extends,
4565 The_Unit_Data.File_Names (Unit_Kind).Project)
4566 then
4567 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4568 Remove_Forbidden_File_Name
4569 (The_Unit_Data.File_Names (Unit_Kind).Name);
4570 end if;
4572 -- Record the file name in the hash table Files_Htable
4574 Unit_Prj := (Unit => The_Unit, Project => Project);
4575 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4577 The_Unit_Data.File_Names (Unit_Kind) :=
4578 (Name => Canonical_File_Name,
4579 Index => Unit_Index,
4580 Display_Name => File_Name,
4581 Path => Canonical_Path_Name,
4582 Display_Path => Path_Name,
4583 Project => Project,
4584 Needs_Pragma => Needs_Pragma);
4585 Units.Table (The_Unit) := The_Unit_Data;
4586 Source_Recorded := True;
4588 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4589 and then (Data.Known_Order_Of_Source_Dirs or else
4590 The_Unit_Data.File_Names (Unit_Kind).Path =
4591 Canonical_Path_Name)
4592 then
4593 if Previous_Source = Nil_String then
4594 Data.Sources := Nil_String;
4595 else
4596 String_Elements.Table (Previous_Source).Next :=
4597 Nil_String;
4598 String_Elements.Decrement_Last;
4599 end if;
4601 Current_Source := Previous_Source;
4603 else
4604 -- It is an error to have two units with the same name
4605 -- and the same kind (spec or body).
4607 if The_Location = No_Location then
4608 The_Location := Projects.Table (Project).Location;
4609 end if;
4611 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4612 Error_Msg (Project, "duplicate source {", The_Location);
4614 Err_Vars.Error_Msg_Name_1 :=
4615 Projects.Table
4616 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4617 Err_Vars.Error_Msg_Name_2 :=
4618 The_Unit_Data.File_Names (Unit_Kind).Path;
4619 Error_Msg
4620 (Project, "\ project file {, {", The_Location);
4622 Err_Vars.Error_Msg_Name_1 :=
4623 Projects.Table (Project).Name;
4624 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4625 Error_Msg
4626 (Project, "\ project file {, {", The_Location);
4627 end if;
4629 -- It is a new unit, create a new record
4631 else
4632 -- First, check if there is no other unit with this file
4633 -- name in another project. If it is, report an error.
4634 -- Of course, we do that only for the first unit in the
4635 -- source file.
4637 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4639 if not File_Name_Recorded and then
4640 Unit_Prj /= No_Unit_Project
4641 then
4642 Error_Msg_Name_1 := File_Name;
4643 Error_Msg_Name_2 :=
4644 Projects.Table (Unit_Prj.Project).Name;
4645 Error_Msg
4646 (Project,
4647 "{ is already a source of project {",
4648 Location);
4650 else
4651 Units.Increment_Last;
4652 The_Unit := Units.Last;
4653 Units_Htable.Set (Unit_Name, The_Unit);
4654 Unit_Prj := (Unit => The_Unit, Project => Project);
4655 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4656 The_Unit_Data.Name := Unit_Name;
4657 The_Unit_Data.File_Names (Unit_Kind) :=
4658 (Name => Canonical_File_Name,
4659 Index => Unit_Index,
4660 Display_Name => File_Name,
4661 Path => Canonical_Path_Name,
4662 Display_Path => Path_Name,
4663 Project => Project,
4664 Needs_Pragma => Needs_Pragma);
4665 Units.Table (The_Unit) := The_Unit_Data;
4666 Source_Recorded := True;
4667 end if;
4668 end if;
4669 end;
4671 exit when Exception_Id = No_Ada_Naming_Exception;
4672 File_Name_Recorded := True;
4673 end loop;
4674 end if;
4675 end Record_Ada_Source;
4677 --------------------------
4678 -- Record_Other_Sources --
4679 --------------------------
4681 procedure Record_Other_Sources
4682 (Project : Project_Id;
4683 Data : in out Project_Data;
4684 Language : Language_Index;
4685 Naming_Exceptions : Boolean)
4687 Source_Dir : String_List_Id := Data.Source_Dirs;
4688 Element : String_Element;
4689 Path : Name_Id;
4691 Dir : Dir_Type;
4692 Canonical_Name : Name_Id;
4694 Name_Str : String (1 .. 1_024);
4695 Last : Natural := 0;
4696 NL : Name_Location;
4698 First_Error : Boolean := True;
4700 Suffix : constant String := Body_Suffix_Of (Language, Data);
4702 begin
4703 while Source_Dir /= Nil_String loop
4704 Element := String_Elements.Table (Source_Dir);
4706 declare
4707 Dir_Path : constant String := Get_Name_String (Element.Value);
4709 begin
4710 if Current_Verbosity = High then
4711 Write_Str ("checking directory """);
4712 Write_Str (Dir_Path);
4713 Write_Str (""" for ");
4715 if Naming_Exceptions then
4716 Write_Str ("naming exceptions");
4718 else
4719 Write_Str ("sources");
4720 end if;
4722 Write_Str (" of Language ");
4723 Display_Language_Name (Language);
4724 end if;
4726 Open (Dir, Dir_Path);
4728 loop
4729 Read (Dir, Name_Str, Last);
4730 exit when Last = 0;
4732 if Is_Regular_File
4733 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4734 then
4735 Name_Len := Last;
4736 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4737 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4738 Canonical_Name := Name_Find;
4739 NL := Source_Names.Get (Canonical_Name);
4741 if NL /= No_Name_Location then
4742 if NL.Found then
4743 if not Data.Known_Order_Of_Source_Dirs then
4744 Error_Msg_Name_1 := Canonical_Name;
4745 Error_Msg
4746 (Project,
4747 "{ is found in several source directories",
4748 NL.Location);
4749 end if;
4751 else
4752 NL.Found := True;
4753 Source_Names.Set (Canonical_Name, NL);
4754 Name_Len := Dir_Path'Length;
4755 Name_Buffer (1 .. Name_Len) := Dir_Path;
4756 Add_Char_To_Name_Buffer (Directory_Separator);
4757 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4758 Path := Name_Find;
4760 Check_For_Source
4761 (File_Name => Canonical_Name,
4762 Path_Name => Path,
4763 Project => Project,
4764 Data => Data,
4765 Location => NL.Location,
4766 Language => Language,
4767 Suffix => Suffix,
4768 Naming_Exception => Naming_Exceptions);
4769 end if;
4770 end if;
4771 end if;
4772 end loop;
4774 Close (Dir);
4775 end;
4777 Source_Dir := Element.Next;
4778 end loop;
4780 if not Naming_Exceptions then
4781 NL := Source_Names.Get_First;
4783 -- It is an error if a source file name in a source list or
4784 -- in a source list file is not found.
4786 while NL /= No_Name_Location loop
4787 if not NL.Found then
4788 Err_Vars.Error_Msg_Name_1 := NL.Name;
4790 if First_Error then
4791 Error_Msg
4792 (Project,
4793 "source file { cannot be found",
4794 NL.Location);
4795 First_Error := False;
4797 else
4798 Error_Msg
4799 (Project,
4800 "\source file { cannot be found",
4801 NL.Location);
4802 end if;
4803 end if;
4805 NL := Source_Names.Get_Next;
4806 end loop;
4808 -- Any naming exception of this language that is not in a list
4809 -- of sources must be removed.
4811 declare
4812 Source_Id : Other_Source_Id := Data.First_Other_Source;
4813 Prev_Id : Other_Source_Id := No_Other_Source;
4814 Source : Other_Source;
4816 begin
4817 while Source_Id /= No_Other_Source loop
4818 Source := Other_Sources.Table (Source_Id);
4820 if Source.Language = Language
4821 and then Source.Naming_Exception
4822 then
4823 if Current_Verbosity = High then
4824 Write_Str ("Naming exception """);
4825 Write_Str (Get_Name_String (Source.File_Name));
4826 Write_Str (""" is not in the list of sources,");
4827 Write_Line (" so it is removed.");
4828 end if;
4830 if Prev_Id = No_Other_Source then
4831 Data.First_Other_Source := Source.Next;
4833 else
4834 Other_Sources.Table (Prev_Id).Next := Source.Next;
4835 end if;
4837 Source_Id := Source.Next;
4839 if Source_Id = No_Other_Source then
4840 Data.Last_Other_Source := Prev_Id;
4841 end if;
4843 else
4844 Prev_Id := Source_Id;
4845 Source_Id := Source.Next;
4846 end if;
4847 end loop;
4848 end;
4849 end if;
4850 end Record_Other_Sources;
4852 ----------------------
4853 -- Show_Source_Dirs --
4854 ----------------------
4856 procedure Show_Source_Dirs (Project : Project_Id) is
4857 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4858 Element : String_Element;
4860 begin
4861 Write_Line ("Source_Dirs:");
4863 while Current /= Nil_String loop
4864 Element := String_Elements.Table (Current);
4865 Write_Str (" ");
4866 Write_Line (Get_Name_String (Element.Value));
4867 Current := Element.Next;
4868 end loop;
4870 Write_Line ("end Source_Dirs.");
4871 end Show_Source_Dirs;
4873 ----------------
4874 -- Suffix_For --
4875 ----------------
4877 function Suffix_For
4878 (Language : Language_Index;
4879 Naming : Naming_Data) return Name_Id
4881 Suffix : constant Variable_Value :=
4882 Value_Of
4883 (Index => Language_Names.Table (Language),
4884 Src_Index => 0,
4885 In_Array => Naming.Body_Suffix);
4886 begin
4887 -- If no suffix for this language in package Naming, use the default
4889 if Suffix = Nil_Variable_Value then
4890 Name_Len := 0;
4892 case Language is
4893 when Ada_Language_Index =>
4894 Add_Str_To_Name_Buffer (".adb");
4896 when C_Language_Index =>
4897 Add_Str_To_Name_Buffer (".c");
4899 when C_Plus_Plus_Language_Index =>
4900 Add_Str_To_Name_Buffer (".cc");
4902 when others =>
4903 return No_Name;
4904 end case;
4906 -- Otherwise use the one specified
4908 else
4909 Get_Name_String (Suffix.Value);
4910 end if;
4912 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4913 return Name_Find;
4914 end Suffix_For;
4916 -------------------------
4917 -- Warn_If_Not_Sources --
4918 -------------------------
4920 -- comments needed in this body ???
4922 procedure Warn_If_Not_Sources
4923 (Project : Project_Id;
4924 Conventions : Array_Element_Id;
4925 Specs : Boolean;
4926 Extending : Boolean)
4928 Conv : Array_Element_Id := Conventions;
4929 Unit : Name_Id;
4930 The_Unit_Id : Unit_Id;
4931 The_Unit_Data : Unit_Data;
4932 Location : Source_Ptr;
4934 begin
4935 while Conv /= No_Array_Element loop
4936 Unit := Array_Elements.Table (Conv).Index;
4937 Error_Msg_Name_1 := Unit;
4938 Get_Name_String (Unit);
4939 To_Lower (Name_Buffer (1 .. Name_Len));
4940 Unit := Name_Find;
4941 The_Unit_Id := Units_Htable.Get (Unit);
4942 Location := Array_Elements.Table (Conv).Value.Location;
4944 if The_Unit_Id = Prj.Com.No_Unit then
4945 Error_Msg
4946 (Project,
4947 "?unknown unit {",
4948 Location);
4950 else
4951 The_Unit_Data := Units.Table (The_Unit_Id);
4953 if Specs then
4954 if not Check_Project
4955 (The_Unit_Data.File_Names (Specification).Project,
4956 Project, Extending)
4957 then
4958 Error_Msg
4959 (Project,
4960 "?unit{ has no spec in this project",
4961 Location);
4962 end if;
4964 else
4965 if not Check_Project
4966 (The_Unit_Data.File_Names (Com.Body_Part).Project,
4967 Project, Extending)
4968 then
4969 Error_Msg
4970 (Project,
4971 "?unit{ has no body in this project",
4972 Location);
4973 end if;
4974 end if;
4975 end if;
4977 Conv := Array_Elements.Table (Conv).Next;
4978 end loop;
4979 end Warn_If_Not_Sources;
4981 end Prj.Nmsc;