* configure.ac: Don't test for [build] __cxa_atexit when building a
[official-gcc.git] / gcc / ada / prj-nmsc.adb
blob8bca19c660a3c18bba4021508524241948567052
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
73 -- Ada_Check.Get_Path_Names_And_Record_Sources.
75 No_Name_Location : constant Name_Location :=
76 (Name => No_Name, Location => No_Location, Found => False);
78 package Source_Names is new GNAT.HTable.Simple_HTable
79 (Header_Num => Header_Num,
80 Element => Name_Location,
81 No_Element => No_Name_Location,
82 Key => Name_Id,
83 Hash => Hash,
84 Equal => "=");
85 -- Hash table to store file names found in string list attribute
86 -- Source_Files or in a source list file, stored in hash table
87 -- Source_Names, used by procedure
88 -- Ada_Check.Get_Path_Names_And_Record_Sources.
90 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
91 (Header_Num => Header_Num,
92 Element => Boolean,
93 No_Element => False,
94 Key => Name_Id,
95 Hash => Hash,
96 Equal => "=");
97 -- Hash table to store recursive source directories, to avoid looking
98 -- several times, and to avoid cycles that may be introduced by symbolic
99 -- links.
101 type Ada_Naming_Exception_Id is new Nat;
102 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
104 type Unit_Info is record
105 Kind : Spec_Or_Body;
106 Unit : Name_Id;
107 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
108 end record;
109 -- No_Unit : constant Unit_Info :=
110 -- (Specification, No_Name, No_Ada_Naming_Exception);
112 package Ada_Naming_Exception_Table is new Table.Table
113 (Table_Component_Type => Unit_Info,
114 Table_Index_Type => Ada_Naming_Exception_Id,
115 Table_Low_Bound => 1,
116 Table_Initial => 20,
117 Table_Increment => 100,
118 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
120 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
121 (Header_Num => Header_Num,
122 Element => Ada_Naming_Exception_Id,
123 No_Element => No_Ada_Naming_Exception,
124 Key => Name_Id,
125 Hash => Hash,
126 Equal => "=");
127 -- A hash table to store naming exceptions for Ada. For each file name
128 -- there is one or several unit in table Ada_Naming_Exception_Table.
130 function Hash (Unit : Unit_Info) return Header_Num;
132 type Name_And_Index is record
133 Name : Name_Id := No_Name;
134 Index : Int := 0;
135 end record;
136 No_Name_And_Index : constant Name_And_Index :=
137 (Name => No_Name, Index => 0);
139 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
140 (Header_Num => Header_Num,
141 Element => Name_And_Index,
142 No_Element => No_Name_And_Index,
143 Key => Unit_Info,
144 Hash => Hash,
145 Equal => "=");
146 -- A table to check if a unit with an exceptional name will hide
147 -- a source with a file name following the naming convention.
149 function ALI_File_Name (Source : String) return String;
150 -- Return the ALI file name corresponding to a source.
152 procedure Check_Ada_Name
153 (Name : String;
154 Unit : out Name_Id);
155 -- Check that a name is a valid Ada unit name.
157 procedure Check_Ada_Naming_Scheme
158 (Data : in out Project_Data;
159 Project : Project_Id);
160 -- Check the naming scheme part of Data
162 procedure Check_Ada_Naming_Scheme_Validity
163 (Project : Project_Id;
164 Naming : Naming_Data);
165 -- Check that the package Naming is correct.
167 procedure Check_For_Source
168 (File_Name : Name_Id;
169 Path_Name : Name_Id;
170 Project : Project_Id;
171 Data : in out Project_Data;
172 Location : Source_Ptr;
173 Language : Other_Programming_Language;
174 Suffix : String;
175 Naming_Exception : Boolean);
176 -- Check if a file in a source directory is a source for a specific
177 -- language other than Ada.
179 function Check_Project
180 (P : Project_Id;
181 Root_Project : Project_Id;
182 Extending : Boolean) return Boolean;
183 -- Returns True if P is Root_Project or, if Extending is True, a project
184 -- extended by Root_Project.
186 function Compute_Directory_Last (Dir : String) return Natural;
187 -- Return the index of the last significant character in Dir. This is used
188 -- to avoid duplicates '/' at the end of directory names
190 procedure Error_Msg
191 (Project : Project_Id;
192 Msg : String;
193 Flag_Location : Source_Ptr);
194 -- Output an error message. If Error_Report is null, simply call
195 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
196 -- Error_Report.
198 procedure Find_Sources
199 (Project : Project_Id;
200 Data : in out Project_Data;
201 For_Language : Programming_Language;
202 Follow_Links : Boolean := False);
203 -- Find all the sources in all of the source directories of a project for
204 -- a specified language.
206 procedure Free_Ada_Naming_Exceptions;
207 -- Free the internal hash tables used for checking naming exceptions
209 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data);
210 -- Get the mains of a project from attribute Main, if it exists, and put
211 -- them in the project data.
213 procedure Get_Sources_From_File
214 (Path : String;
215 Location : Source_Ptr;
216 Project : Project_Id);
217 -- Get the list of sources from a text file and put them in hash table
218 -- Source_Names.
220 procedure Get_Unit
221 (Canonical_File_Name : Name_Id;
222 Naming : Naming_Data;
223 Exception_Id : out Ada_Naming_Exception_Id;
224 Unit_Name : out Name_Id;
225 Unit_Kind : out Spec_Or_Body;
226 Needs_Pragma : out Boolean);
227 -- Find out, from a file name, the unit name, the unit kind and if a
228 -- specific SFN pragma is needed. If the file name corresponds to no
229 -- unit, then Unit_Name will be No_Name. If the file is a multi-unit source
230 -- or an exception to the naming scheme, then Exception_Id is set to
231 -- the unit or units that the source contains.
233 function Is_Illegal_Suffix
234 (Suffix : String;
235 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
236 -- Returns True if the string Suffix cannot be used as
237 -- a spec suffix, a body suffix or a separate suffix.
239 procedure Locate_Directory
240 (Name : Name_Id;
241 Parent : Name_Id;
242 Dir : out Name_Id;
243 Display : out Name_Id);
244 -- Locate a directory (returns No_Name for Dir and Display if directory
245 -- does not exist). Name is the directory name. Parent is the root
246 -- directory, if Name is a relative path name. Dir is the canonical case
247 -- path name of the directory, Display is the directory path name for
248 -- display purposes.
250 function Path_Name_Of
251 (File_Name : Name_Id;
252 Directory : Name_Id) return String;
253 -- Returns the path name of a (non project) file.
254 -- Returns an empty string if file cannot be found.
256 procedure Prepare_Ada_Naming_Exceptions
257 (List : Array_Element_Id;
258 Kind : Spec_Or_Body);
259 -- Prepare the internal hash tables used for checking naming exceptions
260 -- for Ada. Insert all elements of List in the tables.
262 function Project_Extends
263 (Extending : Project_Id;
264 Extended : Project_Id) return Boolean;
265 -- Returns True if Extending is extending directly or indirectly Extended.
267 procedure Record_Ada_Source
268 (File_Name : Name_Id;
269 Path_Name : Name_Id;
270 Project : Project_Id;
271 Data : in out Project_Data;
272 Location : Source_Ptr;
273 Current_Source : in out String_List_Id;
274 Source_Recorded : in out Boolean;
275 Follow_Links : Boolean);
276 -- Put a unit in the list of units of a project, if the file name
277 -- corresponds to a valid unit name.
279 procedure Record_Other_Sources
280 (Project : Project_Id;
281 Data : in out Project_Data;
282 Language : Programming_Language;
283 Naming_Exceptions : Boolean);
284 -- Record the sources of a language in a project.
285 -- When Naming_Exceptions is True, mark the found sources as such, to
286 -- later remove those that are not named in a list of sources.
288 procedure Show_Source_Dirs (Project : Project_Id);
289 -- List all the source directories of a project.
291 function Suffix_For
292 (Language : Programming_Language;
293 Naming : Naming_Data) return Name_Id;
294 -- Get the suffix for the source of a language from a package naming.
295 -- If not specified, return the default for the language.
297 ---------------
298 -- Ada_Check --
299 ---------------
301 procedure Ada_Check
302 (Project : Project_Id;
303 Report_Error : Put_Line_Access;
304 Follow_Links : Boolean)
306 Data : Project_Data;
307 Languages : Variable_Value := Nil_Variable_Value;
309 Extending : Boolean := False;
311 procedure Get_Path_Names_And_Record_Sources;
312 -- Find the path names of the source files in the Source_Names table
313 -- in the source directories and record those that are Ada sources.
315 procedure Get_Sources_From_File
316 (Path : String;
317 Location : Source_Ptr);
318 -- Get the sources of a project from a text file
320 procedure Warn_If_Not_Sources
321 (Conventions : Array_Element_Id;
322 Specs : Boolean);
323 -- Check that individual naming conventions apply to immediate
324 -- sources of the project; if not, issue a warning.
326 ---------------------------------------
327 -- Get_Path_Names_And_Record_Sources --
328 ---------------------------------------
330 procedure Get_Path_Names_And_Record_Sources is
331 Source_Dir : String_List_Id := Data.Source_Dirs;
332 Element : String_Element;
333 Path : Name_Id;
335 Dir : Dir_Type;
336 Name : Name_Id;
337 Canonical_Name : Name_Id;
338 Name_Str : String (1 .. 1_024);
339 Last : Natural := 0;
340 NL : Name_Location;
342 Current_Source : String_List_Id := Nil_String;
344 First_Error : Boolean := True;
346 Source_Recorded : Boolean := False;
348 begin
349 -- We look in all source directories for the file names in the
350 -- hash table Source_Names
352 while Source_Dir /= Nil_String loop
353 Source_Recorded := False;
354 Element := String_Elements.Table (Source_Dir);
356 declare
357 Dir_Path : constant String := Get_Name_String (Element.Value);
358 begin
359 if Current_Verbosity = High then
360 Write_Str ("checking directory """);
361 Write_Str (Dir_Path);
362 Write_Line ("""");
363 end if;
365 Open (Dir, Dir_Path);
367 loop
368 Read (Dir, Name_Str, Last);
369 exit when Last = 0;
370 Name_Len := Last;
371 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
372 Name := Name_Find;
373 Canonical_Case_File_Name (Name_Str (1 .. Last));
374 Name_Len := Last;
375 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
376 Canonical_Name := Name_Find;
377 NL := Source_Names.Get (Canonical_Name);
379 if NL /= No_Name_Location and then not NL.Found then
380 NL.Found := True;
381 Source_Names.Set (Canonical_Name, NL);
382 Name_Len := Dir_Path'Length;
383 Name_Buffer (1 .. Name_Len) := Dir_Path;
385 if Name_Buffer (Name_Len) /= Directory_Separator then
386 Add_Char_To_Name_Buffer (Directory_Separator);
387 end if;
389 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
390 Path := Name_Find;
392 if Current_Verbosity = High then
393 Write_Str (" found ");
394 Write_Line (Get_Name_String (Name));
395 end if;
397 -- Register the source if it is an Ada compilation unit.
399 Record_Ada_Source
400 (File_Name => Name,
401 Path_Name => Path,
402 Project => Project,
403 Data => Data,
404 Location => NL.Location,
405 Current_Source => Current_Source,
406 Source_Recorded => Source_Recorded,
407 Follow_Links => Follow_Links);
408 end if;
409 end loop;
411 Close (Dir);
412 end;
414 if Source_Recorded then
415 String_Elements.Table (Source_Dir).Flag := True;
416 end if;
418 Source_Dir := Element.Next;
419 end loop;
421 -- It is an error if a source file name in a source list or
422 -- in a source list file is not found.
424 NL := Source_Names.Get_First;
426 while NL /= No_Name_Location loop
427 if not NL.Found then
428 Err_Vars.Error_Msg_Name_1 := NL.Name;
430 if First_Error then
431 Error_Msg
432 (Project,
433 "source file { cannot be found",
434 NL.Location);
435 First_Error := False;
437 else
438 Error_Msg
439 (Project,
440 "\source file { cannot be found",
441 NL.Location);
442 end if;
443 end if;
445 NL := Source_Names.Get_Next;
446 end loop;
447 end Get_Path_Names_And_Record_Sources;
449 ---------------------------
450 -- Get_Sources_From_File --
451 ---------------------------
453 procedure Get_Sources_From_File
454 (Path : String;
455 Location : Source_Ptr)
457 begin
458 -- Get the list of sources from the file and put them in hash table
459 -- Source_Names.
461 Get_Sources_From_File (Path, Location, Project);
463 -- Look in the source directories to find those sources
465 Get_Path_Names_And_Record_Sources;
467 -- We should have found at least one source.
468 -- If not, report an error.
470 if Data.Sources = Nil_String then
471 Error_Msg (Project,
472 "there are no Ada sources in this project",
473 Location);
474 end if;
475 end Get_Sources_From_File;
477 -------------------------
478 -- Warn_If_Not_Sources --
479 -------------------------
481 procedure Warn_If_Not_Sources
482 (Conventions : Array_Element_Id;
483 Specs : Boolean)
485 Conv : Array_Element_Id := Conventions;
486 Unit : Name_Id;
487 The_Unit_Id : Unit_Id;
488 The_Unit_Data : Unit_Data;
489 Location : Source_Ptr;
491 begin
492 while Conv /= No_Array_Element loop
493 Unit := Array_Elements.Table (Conv).Index;
494 Error_Msg_Name_1 := Unit;
495 Get_Name_String (Unit);
496 To_Lower (Name_Buffer (1 .. Name_Len));
497 Unit := Name_Find;
498 The_Unit_Id := Units_Htable.Get (Unit);
499 Location := Array_Elements.Table (Conv).Value.Location;
501 if The_Unit_Id = Prj.Com.No_Unit then
502 Error_Msg
503 (Project,
504 "?unknown unit {",
505 Location);
507 else
508 The_Unit_Data := Units.Table (The_Unit_Id);
510 if Specs then
511 if not Check_Project
512 (The_Unit_Data.File_Names (Specification).Project,
513 Project, Extending)
514 then
515 Error_Msg
516 (Project,
517 "?unit{ has no spec in this project",
518 Location);
519 end if;
521 else
522 if not Check_Project
523 (The_Unit_Data.File_Names (Com.Body_Part).Project,
524 Project, Extending)
525 then
526 Error_Msg
527 (Project,
528 "?unit{ has no body in this project",
529 Location);
530 end if;
531 end if;
532 end if;
534 Conv := Array_Elements.Table (Conv).Next;
535 end loop;
536 end Warn_If_Not_Sources;
538 -- Start of processing for Ada_Check
540 begin
541 Language_Independent_Check (Project, Report_Error);
543 Error_Report := Report_Error;
545 Data := Projects.Table (Project);
546 Extending := Data.Extends /= No_Project;
547 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
549 Data.Naming.Current_Language := Name_Ada;
550 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
552 if not Languages.Default then
553 declare
554 Current : String_List_Id := Languages.Values;
555 Element : String_Element;
556 Ada_Found : Boolean := False;
558 begin
559 Look_For_Ada : while Current /= Nil_String loop
560 Element := String_Elements.Table (Current);
561 Get_Name_String (Element.Value);
562 To_Lower (Name_Buffer (1 .. Name_Len));
564 if Name_Buffer (1 .. Name_Len) = "ada" then
565 Ada_Found := True;
566 exit Look_For_Ada;
567 end if;
569 Current := Element.Next;
570 end loop Look_For_Ada;
572 if not Ada_Found then
574 -- Mark the project file as having no sources for Ada
576 Data.Ada_Sources_Present := False;
577 end if;
578 end;
579 end if;
581 Check_Ada_Naming_Scheme (Data, Project);
583 Prepare_Ada_Naming_Exceptions (Data.Naming.Bodies, Body_Part);
584 Prepare_Ada_Naming_Exceptions (Data.Naming.Specs, Specification);
586 -- If we have source directories, then find the sources
588 if Data.Ada_Sources_Present then
589 if Data.Source_Dirs = Nil_String then
590 Data.Ada_Sources_Present := False;
592 else
593 declare
594 Sources : constant Variable_Value :=
595 Util.Value_Of
596 (Name_Source_Files,
597 Data.Decl.Attributes);
599 Source_List_File : constant Variable_Value :=
600 Util.Value_Of
601 (Name_Source_List_File,
602 Data.Decl.Attributes);
604 Locally_Removed : constant Variable_Value :=
605 Util.Value_Of
606 (Name_Locally_Removed_Files,
607 Data.Decl.Attributes);
609 begin
610 pragma Assert
611 (Sources.Kind = List,
612 "Source_Files is not a list");
614 pragma Assert
615 (Source_List_File.Kind = Single,
616 "Source_List_File is not a single string");
618 if not Sources.Default then
619 if not Source_List_File.Default then
620 Error_Msg
621 (Project,
622 "?both variables source_files and " &
623 "source_list_file are present",
624 Source_List_File.Location);
625 end if;
627 -- Sources is a list of file names
629 declare
630 Current : String_List_Id := Sources.Values;
631 Element : String_Element;
632 Location : Source_Ptr;
633 Name : Name_Id;
635 begin
636 Source_Names.Reset;
638 Data.Ada_Sources_Present := Current /= Nil_String;
640 while Current /= Nil_String loop
641 Element := String_Elements.Table (Current);
642 Get_Name_String (Element.Value);
643 Canonical_Case_File_Name
644 (Name_Buffer (1 .. Name_Len));
645 Name := Name_Find;
647 -- If the element has no location, then use the
648 -- location of Sources to report possible errors.
650 if Element.Location = No_Location then
651 Location := Sources.Location;
653 else
654 Location := Element.Location;
655 end if;
657 Source_Names.Set
658 (K => Name,
659 E =>
660 (Name => Name,
661 Location => Location,
662 Found => False));
664 Current := Element.Next;
665 end loop;
667 Get_Path_Names_And_Record_Sources;
668 end;
670 -- No source_files specified
672 -- We check Source_List_File has been specified.
674 elsif not Source_List_File.Default then
676 -- Source_List_File is the name of the file
677 -- that contains the source file names
679 declare
680 Source_File_Path_Name : constant String :=
681 Path_Name_Of
682 (Source_List_File.Value,
683 Data.Directory);
685 begin
686 if Source_File_Path_Name'Length = 0 then
687 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
688 Error_Msg
689 (Project,
690 "file with sources { does not exist",
691 Source_List_File.Location);
693 else
694 Get_Sources_From_File
695 (Source_File_Path_Name,
696 Source_List_File.Location);
697 end if;
698 end;
700 else
701 -- Neither Source_Files nor Source_List_File has been
702 -- specified. Find all the files that satisfy the naming
703 -- scheme in all the source directories.
705 Find_Sources (Project, Data, Lang_Ada, Follow_Links);
706 end if;
708 -- If there are sources that are locally removed, mark them as
709 -- such in the Units table.
711 if not Locally_Removed.Default then
713 -- Sources can be locally removed only in extending
714 -- project files.
716 if Data.Extends = No_Project then
717 Error_Msg
718 (Project,
719 "Locally_Removed_Files can only be used " &
720 "in an extending project file",
721 Locally_Removed.Location);
723 else
724 declare
725 Current : String_List_Id :=
726 Locally_Removed.Values;
727 Element : String_Element;
728 Location : Source_Ptr;
729 OK : Boolean;
730 Unit : Unit_Data;
731 Name : Name_Id;
732 Extended : Project_Id;
734 begin
735 while Current /= Nil_String loop
736 Element := String_Elements.Table (Current);
737 Get_Name_String (Element.Value);
738 Canonical_Case_File_Name
739 (Name_Buffer (1 .. Name_Len));
740 Name := Name_Find;
742 -- If the element has no location, then use the
743 -- location of Locally_Removed to report
744 -- possible errors.
746 if Element.Location = No_Location then
747 Location := Locally_Removed.Location;
749 else
750 Location := Element.Location;
751 end if;
753 OK := False;
755 for Index in 1 .. Units.Last loop
756 Unit := Units.Table (Index);
759 Unit.File_Names (Specification).Name = Name
760 then
761 OK := True;
763 -- Check that this is from a project that
764 -- the current project extends, but not the
765 -- current project.
767 Extended := Unit.File_Names
768 (Specification).Project;
770 if Extended = Project then
771 Error_Msg
772 (Project,
773 "cannot remove a source " &
774 "of the same project",
775 Location);
777 elsif
778 Project_Extends (Project, Extended)
779 then
780 Unit.File_Names
781 (Specification).Path := Slash;
782 Unit.File_Names
783 (Specification).Needs_Pragma := False;
784 Units.Table (Index) := Unit;
785 Add_Forbidden_File_Name
786 (Unit.File_Names (Specification).Name);
787 exit;
789 else
790 Error_Msg
791 (Project,
792 "cannot remove a source from " &
793 "another project",
794 Location);
795 end if;
797 elsif
798 Unit.File_Names (Body_Part).Name = Name
799 then
800 OK := True;
802 -- Check that this is from a project that
803 -- the current project extends, but not the
804 -- current project.
806 Extended := Unit.File_Names
807 (Body_Part).Project;
809 if Extended = Project then
810 Error_Msg
811 (Project,
812 "cannot remove a source " &
813 "of the same project",
814 Location);
816 elsif
817 Project_Extends (Project, Extended)
818 then
819 Unit.File_Names (Body_Part).Path := Slash;
820 Unit.File_Names (Body_Part).Needs_Pragma
821 := False;
822 Units.Table (Index) := Unit;
823 Add_Forbidden_File_Name
824 (Unit.File_Names (Body_Part).Name);
825 exit;
826 end if;
828 end if;
829 end loop;
831 if not OK then
832 Err_Vars.Error_Msg_Name_1 := Name;
833 Error_Msg (Project, "unknown file {", Location);
834 end if;
836 Current := Element.Next;
837 end loop;
838 end;
839 end if;
840 end if;
841 end;
842 end if;
843 end if;
845 if Data.Ada_Sources_Present then
847 -- Check that all individual naming conventions apply to
848 -- sources of this project file.
850 Warn_If_Not_Sources (Data.Naming.Bodies, Specs => False);
851 Warn_If_Not_Sources (Data.Naming.Specs, Specs => True);
852 end if;
854 -- If it is a library project file, check if it is a standalone library
856 if Data.Library then
857 Standalone_Library : declare
858 Lib_Interfaces : constant Prj.Variable_Value :=
859 Prj.Util.Value_Of
860 (Snames.Name_Library_Interface,
861 Data.Decl.Attributes);
862 Lib_Auto_Init : constant Prj.Variable_Value :=
863 Prj.Util.Value_Of
864 (Snames.Name_Library_Auto_Init,
865 Data.Decl.Attributes);
867 Lib_Src_Dir : constant Prj.Variable_Value :=
868 Prj.Util.Value_Of
869 (Snames.Name_Library_Src_Dir,
870 Data.Decl.Attributes);
872 Lib_Symbol_File : constant Prj.Variable_Value :=
873 Prj.Util.Value_Of
874 (Snames.Name_Library_Symbol_File,
875 Data.Decl.Attributes);
877 Lib_Symbol_Policy : constant Prj.Variable_Value :=
878 Prj.Util.Value_Of
879 (Snames.Name_Library_Symbol_Policy,
880 Data.Decl.Attributes);
882 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
883 Prj.Util.Value_Of
884 (Snames.Name_Library_Reference_Symbol_File,
885 Data.Decl.Attributes);
887 Auto_Init_Supported : constant Boolean :=
888 MLib.Tgt.
889 Standalone_Library_Auto_Init_Is_Supported;
891 OK : Boolean := True;
893 begin
894 pragma Assert (Lib_Interfaces.Kind = List);
896 -- It is a stand-alone library project file if attribute
897 -- Library_Interface is defined.
899 if not Lib_Interfaces.Default then
900 declare
901 Interfaces : String_List_Id := Lib_Interfaces.Values;
902 Interface_ALIs : String_List_Id := Nil_String;
903 Unit : Name_Id;
904 The_Unit_Id : Unit_Id;
905 The_Unit_Data : Unit_Data;
907 procedure Add_ALI_For (Source : Name_Id);
908 -- Add an ALI file name to the list of Interface ALIs
910 -----------------
911 -- Add_ALI_For --
912 -----------------
914 procedure Add_ALI_For (Source : Name_Id) is
915 begin
916 Get_Name_String (Source);
918 declare
919 ALI : constant String :=
920 ALI_File_Name (Name_Buffer (1 .. Name_Len));
921 ALI_Name_Id : Name_Id;
922 begin
923 Name_Len := ALI'Length;
924 Name_Buffer (1 .. Name_Len) := ALI;
925 ALI_Name_Id := Name_Find;
927 String_Elements.Increment_Last;
928 String_Elements.Table (String_Elements.Last) :=
929 (Value => ALI_Name_Id,
930 Index => 0,
931 Display_Value => ALI_Name_Id,
932 Location => String_Elements.Table
933 (Interfaces).Location,
934 Flag => False,
935 Next => Interface_ALIs);
936 Interface_ALIs := String_Elements.Last;
937 end;
938 end Add_ALI_For;
940 begin
941 Data.Standalone_Library := True;
943 -- Library_Interface cannot be an empty list
945 if Interfaces = Nil_String then
946 Error_Msg
947 (Project,
948 "Library_Interface cannot be an empty list",
949 Lib_Interfaces.Location);
950 end if;
952 -- Process each unit name specified in the attribute
953 -- Library_Interface.
955 while Interfaces /= Nil_String loop
956 Get_Name_String
957 (String_Elements.Table (Interfaces).Value);
958 To_Lower (Name_Buffer (1 .. Name_Len));
960 if Name_Len = 0 then
961 Error_Msg
962 (Project,
963 "an interface cannot be an empty string",
964 String_Elements.Table (Interfaces).Location);
966 else
967 Unit := Name_Find;
968 Error_Msg_Name_1 := Unit;
969 The_Unit_Id := Units_Htable.Get (Unit);
971 if The_Unit_Id = Prj.Com.No_Unit then
972 Error_Msg
973 (Project,
974 "unknown unit {",
975 String_Elements.Table (Interfaces).Location);
977 else
978 -- Check that the unit is part of the project
980 The_Unit_Data := Units.Table (The_Unit_Id);
982 if The_Unit_Data.File_Names
983 (Com.Body_Part).Name /= No_Name
984 and then The_Unit_Data.File_Names
985 (Com.Body_Part).Path /= Slash
986 then
987 if Check_Project
988 (The_Unit_Data.File_Names (Body_Part).Project,
989 Project, Extending)
990 then
991 -- There is a body for this unit.
992 -- If there is no spec, we need to check
993 -- that it is not a subunit.
995 if The_Unit_Data.File_Names
996 (Specification).Name = No_Name
997 then
998 declare
999 Src_Ind : Source_File_Index;
1001 begin
1002 Src_Ind := Sinput.P.Load_Project_File
1003 (Get_Name_String
1004 (The_Unit_Data.File_Names
1005 (Body_Part).Path));
1007 if Sinput.P.Source_File_Is_Subunit
1008 (Src_Ind)
1009 then
1010 Error_Msg
1011 (Project,
1012 "{ is a subunit; " &
1013 "it cannot be an interface",
1014 String_Elements.Table
1015 (Interfaces).Location);
1016 end if;
1017 end;
1018 end if;
1020 -- The unit is not a subunit, so we add
1021 -- to the Interface ALIs the ALI file
1022 -- corresponding to the body.
1024 Add_ALI_For
1025 (The_Unit_Data.File_Names (Body_Part).Name);
1027 else
1028 Error_Msg
1029 (Project,
1030 "{ is not an unit of this project",
1031 String_Elements.Table
1032 (Interfaces).Location);
1033 end if;
1035 elsif The_Unit_Data.File_Names
1036 (Com.Specification).Name /= No_Name
1037 and then The_Unit_Data.File_Names
1038 (Com.Specification).Path /= Slash
1039 and then Check_Project
1040 (The_Unit_Data.File_Names
1041 (Specification).Project,
1042 Project, Extending)
1044 then
1045 -- The unit is part of the project, it has
1046 -- a spec, but no body. We add to the Interface
1047 -- ALIs the ALI file corresponding to the spec.
1049 Add_ALI_For
1050 (The_Unit_Data.File_Names (Specification).Name);
1052 else
1053 Error_Msg
1054 (Project,
1055 "{ is not an unit of this project",
1056 String_Elements.Table (Interfaces).Location);
1057 end if;
1058 end if;
1060 end if;
1062 Interfaces := String_Elements.Table (Interfaces).Next;
1063 end loop;
1065 -- Put the list of Interface ALIs in the project data
1067 Data.Lib_Interface_ALIs := Interface_ALIs;
1069 -- Check value of attribute Library_Auto_Init and set
1070 -- Lib_Auto_Init accordingly.
1072 if Lib_Auto_Init.Default then
1074 -- If no attribute Library_Auto_Init is declared, then
1075 -- set auto init only if it is supported.
1077 Data.Lib_Auto_Init := Auto_Init_Supported;
1079 else
1080 Get_Name_String (Lib_Auto_Init.Value);
1081 To_Lower (Name_Buffer (1 .. Name_Len));
1083 if Name_Buffer (1 .. Name_Len) = "false" then
1084 Data.Lib_Auto_Init := False;
1086 elsif Name_Buffer (1 .. Name_Len) = "true" then
1087 if Auto_Init_Supported then
1088 Data.Lib_Auto_Init := True;
1090 else
1091 -- Library_Auto_Init cannot be "true" if auto init
1092 -- is not supported
1094 Error_Msg
1095 (Project,
1096 "library auto init not supported " &
1097 "on this platform",
1098 Lib_Auto_Init.Location);
1099 end if;
1101 else
1102 Error_Msg
1103 (Project,
1104 "invalid value for attribute Library_Auto_Init",
1105 Lib_Auto_Init.Location);
1106 end if;
1107 end if;
1108 end;
1110 -- If attribute Library_Src_Dir is defined and not the
1111 -- empty string, check if the directory exist and is not
1112 -- the object directory or one of the source directories.
1113 -- This is the directory where copies of the interface
1114 -- sources will be copied. Note that this directory may be
1115 -- the library directory.
1117 if Lib_Src_Dir.Value /= Empty_String then
1118 declare
1119 Dir_Id : constant Name_Id := Lib_Src_Dir.Value;
1121 begin
1122 Locate_Directory
1123 (Dir_Id, Data.Display_Directory,
1124 Data.Library_Src_Dir,
1125 Data.Display_Library_Src_Dir);
1127 -- If directory does not exist, report an error
1129 if Data.Library_Src_Dir = No_Name then
1131 -- Get the absolute name of the library directory
1132 -- that does not exist, to report an error.
1134 declare
1135 Dir_Name : constant String :=
1136 Get_Name_String (Dir_Id);
1138 begin
1139 if Is_Absolute_Path (Dir_Name) then
1140 Err_Vars.Error_Msg_Name_1 := Dir_Id;
1142 else
1143 Get_Name_String (Data.Directory);
1145 if Name_Buffer (Name_Len) /=
1146 Directory_Separator
1147 then
1148 Name_Len := Name_Len + 1;
1149 Name_Buffer (Name_Len) :=
1150 Directory_Separator;
1151 end if;
1153 Name_Buffer
1154 (Name_Len + 1 ..
1155 Name_Len + Dir_Name'Length) :=
1156 Dir_Name;
1157 Name_Len := Name_Len + Dir_Name'Length;
1158 Err_Vars.Error_Msg_Name_1 := Name_Find;
1159 end if;
1161 -- Report the error
1163 Error_Msg
1164 (Project,
1165 "Directory { does not exist",
1166 Lib_Src_Dir.Location);
1167 end;
1169 -- Report an error if it is the same as the object
1170 -- directory.
1172 elsif Data.Library_Src_Dir = Data.Object_Directory then
1173 Error_Msg
1174 (Project,
1175 "directory to copy interfaces cannot be " &
1176 "the object directory",
1177 Lib_Src_Dir.Location);
1178 Data.Library_Src_Dir := No_Name;
1180 -- Check if it is the same as one of the source
1181 -- directories.
1183 else
1184 declare
1185 Src_Dirs : String_List_Id := Data.Source_Dirs;
1186 Src_Dir : String_Element;
1188 begin
1189 while Src_Dirs /= Nil_String loop
1190 Src_Dir := String_Elements.Table (Src_Dirs);
1191 Src_Dirs := Src_Dir.Next;
1193 -- Report an error if it is one of the
1194 -- source directories.
1196 if Data.Library_Src_Dir = Src_Dir.Value then
1197 Error_Msg
1198 (Project,
1199 "directory to copy interfaces cannot " &
1200 "be one of the source directories",
1201 Lib_Src_Dir.Location);
1202 Data.Library_Src_Dir := No_Name;
1203 exit;
1204 end if;
1205 end loop;
1206 end;
1208 if Data.Library_Src_Dir /= No_Name
1209 and then Current_Verbosity = High
1210 then
1211 Write_Str ("Directory to copy interfaces =""");
1212 Write_Str (Get_Name_String (Data.Library_Dir));
1213 Write_Line ("""");
1214 end if;
1215 end if;
1216 end;
1217 end if;
1219 if not Lib_Symbol_Policy.Default then
1220 declare
1221 Value : constant String :=
1222 To_Lower
1223 (Get_Name_String (Lib_Symbol_Policy.Value));
1225 begin
1226 if Value = "autonomous" or else Value = "default" then
1227 Data.Symbol_Data.Symbol_Policy := Autonomous;
1229 elsif Value = "compliant" then
1230 Data.Symbol_Data.Symbol_Policy := Compliant;
1232 elsif Value = "controlled" then
1233 Data.Symbol_Data.Symbol_Policy := Controlled;
1235 elsif Value = "restricted" then
1236 Data.Symbol_Data.Symbol_Policy := Restricted;
1238 else
1239 Error_Msg
1240 (Project,
1241 "illegal value for Library_Symbol_Policy",
1242 Lib_Symbol_Policy.Location);
1243 end if;
1244 end;
1245 end if;
1247 if Lib_Symbol_File.Default then
1248 if Data.Symbol_Data.Symbol_Policy = Restricted then
1249 Error_Msg
1250 (Project,
1251 "Library_Symbol_File needs to be defined when " &
1252 "symbol policy is Restricted",
1253 Lib_Symbol_Policy.Location);
1254 end if;
1256 else
1257 Data.Symbol_Data.Symbol_File := Lib_Symbol_File.Value;
1259 Get_Name_String (Lib_Symbol_File.Value);
1261 if Name_Len = 0 then
1262 Error_Msg
1263 (Project,
1264 "symbol file name cannot be an empty string",
1265 Lib_Symbol_File.Location);
1267 else
1268 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1270 if OK then
1271 for J in 1 .. Name_Len loop
1272 if Name_Buffer (J) = '/'
1273 or else Name_Buffer (J) = Directory_Separator
1274 then
1275 OK := False;
1276 exit;
1277 end if;
1278 end loop;
1279 end if;
1281 if not OK then
1282 Error_Msg_Name_1 := Lib_Symbol_File.Value;
1283 Error_Msg
1284 (Project,
1285 "symbol file name { is illegal. " &
1286 "Name canot include directory info.",
1287 Lib_Symbol_File.Location);
1288 end if;
1289 end if;
1290 end if;
1292 if Lib_Ref_Symbol_File.Default then
1293 if Data.Symbol_Data.Symbol_Policy = Compliant
1294 or else Data.Symbol_Data.Symbol_Policy = Controlled
1295 then
1296 Error_Msg
1297 (Project,
1298 "a reference symbol file need to be defined",
1299 Lib_Symbol_Policy.Location);
1300 end if;
1302 else
1303 Data.Symbol_Data.Reference := Lib_Ref_Symbol_File.Value;
1305 Get_Name_String (Lib_Ref_Symbol_File.Value);
1307 if Name_Len = 0 then
1308 Error_Msg
1309 (Project,
1310 "reference symbol file name cannot be an empty string",
1311 Lib_Symbol_File.Location);
1313 else
1314 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
1316 if OK then
1317 for J in 1 .. Name_Len loop
1318 if Name_Buffer (J) = '/'
1319 or else Name_Buffer (J) = Directory_Separator
1320 then
1321 OK := False;
1322 exit;
1323 end if;
1324 end loop;
1325 end if;
1327 if not OK then
1328 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1329 Error_Msg
1330 (Project,
1331 "reference symbol file { name is illegal. " &
1332 "Name canot include directory info.",
1333 Lib_Ref_Symbol_File.Location);
1334 end if;
1336 if not Is_Regular_File
1337 (Get_Name_String (Data.Object_Directory) &
1338 Directory_Separator &
1339 Get_Name_String (Lib_Ref_Symbol_File.Value))
1340 then
1341 Error_Msg_Name_1 := Lib_Ref_Symbol_File.Value;
1342 Error_Msg
1343 (Project,
1344 "library reference symbol file { does not exist",
1345 Lib_Ref_Symbol_File.Location);
1346 end if;
1348 if Data.Symbol_Data.Symbol_File /= No_Name then
1349 declare
1350 Symbol : String :=
1351 Get_Name_String
1352 (Data.Symbol_Data.Symbol_File);
1354 Reference : String :=
1355 Get_Name_String
1356 (Data.Symbol_Data.Reference);
1358 begin
1359 Canonical_Case_File_Name (Symbol);
1360 Canonical_Case_File_Name (Reference);
1362 if Symbol = Reference then
1363 Error_Msg
1364 (Project,
1365 "reference symbol file and symbol file " &
1366 "cannot be the same file",
1367 Lib_Ref_Symbol_File.Location);
1368 end if;
1369 end;
1370 end if;
1371 end if;
1372 end if;
1373 end if;
1374 end Standalone_Library;
1375 end if;
1377 -- Put the list of Mains, if any, in the project data
1379 Get_Mains (Project, Data);
1381 Projects.Table (Project) := Data;
1383 Free_Ada_Naming_Exceptions;
1384 end Ada_Check;
1386 -------------------
1387 -- ALI_File_Name --
1388 -------------------
1390 function ALI_File_Name (Source : String) return String is
1391 begin
1392 -- If the source name has an extension, then replace it with
1393 -- the ALI suffix.
1395 for Index in reverse Source'First + 1 .. Source'Last loop
1396 if Source (Index) = '.' then
1397 return Source (Source'First .. Index - 1) & ALI_Suffix;
1398 end if;
1399 end loop;
1401 -- If there is no dot, or if it is the first character, just add the
1402 -- ALI suffix.
1404 return Source & ALI_Suffix;
1405 end ALI_File_Name;
1407 --------------------
1408 -- Check_Ada_Name --
1409 --------------------
1411 procedure Check_Ada_Name
1412 (Name : String;
1413 Unit : out Name_Id)
1415 The_Name : String := Name;
1416 Real_Name : Name_Id;
1417 Need_Letter : Boolean := True;
1418 Last_Underscore : Boolean := False;
1419 OK : Boolean := The_Name'Length > 0;
1421 begin
1422 To_Lower (The_Name);
1424 Name_Len := The_Name'Length;
1425 Name_Buffer (1 .. Name_Len) := The_Name;
1426 Real_Name := Name_Find;
1428 -- Check first that the given name is not an Ada reserved word
1430 if Get_Name_Table_Byte (Real_Name) /= 0
1431 and then Real_Name /= Name_Project
1432 and then Real_Name /= Name_Extends
1433 and then Real_Name /= Name_External
1434 then
1435 Unit := No_Name;
1437 if Current_Verbosity = High then
1438 Write_Str (The_Name);
1439 Write_Line (" is an Ada reserved word.");
1440 end if;
1442 return;
1443 end if;
1445 for Index in The_Name'Range loop
1446 if Need_Letter then
1448 -- We need a letter (at the beginning, and following a dot),
1449 -- but we don't have one.
1451 if Is_Letter (The_Name (Index)) then
1452 Need_Letter := False;
1454 else
1455 OK := False;
1457 if Current_Verbosity = High then
1458 Write_Int (Types.Int (Index));
1459 Write_Str (": '");
1460 Write_Char (The_Name (Index));
1461 Write_Line ("' is not a letter.");
1462 end if;
1464 exit;
1465 end if;
1467 elsif Last_Underscore
1468 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1469 then
1470 -- Two underscores are illegal, and a dot cannot follow
1471 -- an underscore.
1473 OK := False;
1475 if Current_Verbosity = High then
1476 Write_Int (Types.Int (Index));
1477 Write_Str (": '");
1478 Write_Char (The_Name (Index));
1479 Write_Line ("' is illegal here.");
1480 end if;
1482 exit;
1484 elsif The_Name (Index) = '.' then
1486 -- We need a letter after a dot
1488 Need_Letter := True;
1490 elsif The_Name (Index) = '_' then
1491 Last_Underscore := True;
1493 else
1494 -- We need an letter or a digit
1496 Last_Underscore := False;
1498 if not Is_Alphanumeric (The_Name (Index)) then
1499 OK := False;
1501 if Current_Verbosity = High then
1502 Write_Int (Types.Int (Index));
1503 Write_Str (": '");
1504 Write_Char (The_Name (Index));
1505 Write_Line ("' is not alphanumeric.");
1506 end if;
1508 exit;
1509 end if;
1510 end if;
1511 end loop;
1513 -- Cannot end with an underscore or a dot
1515 OK := OK and then not Need_Letter and then not Last_Underscore;
1517 if OK then
1518 Unit := Real_Name;
1520 else
1521 -- Signal a problem with No_Name
1523 Unit := No_Name;
1524 end if;
1525 end Check_Ada_Name;
1527 ----------------------
1528 -- Check_For_Source --
1529 ----------------------
1531 procedure Check_For_Source
1532 (File_Name : Name_Id;
1533 Path_Name : Name_Id;
1534 Project : Project_Id;
1535 Data : in out Project_Data;
1536 Location : Source_Ptr;
1537 Language : Other_Programming_Language;
1538 Suffix : String;
1539 Naming_Exception : Boolean)
1541 Name : String := Get_Name_String (File_Name);
1542 Real_Location : Source_Ptr := Location;
1544 begin
1545 Canonical_Case_File_Name (Name);
1547 -- A file is a source of a language if Naming_Exception is True (case
1548 -- of naming exceptions) or if its file name ends with the suffix.
1550 if Naming_Exception or else
1551 (Name'Length > Suffix'Length and then
1552 Name (Name'Last - Suffix'Length + 1 .. Name'Last) = Suffix)
1553 then
1554 if Real_Location = No_Location then
1555 Real_Location := Data.Location;
1556 end if;
1558 declare
1559 Path : String := Get_Name_String (Path_Name);
1561 Path_Id : Name_Id;
1562 -- The path name id (in canonical case)
1564 File_Id : Name_Id;
1565 -- The file name id (in canonical case)
1567 Obj_Id : Name_Id;
1568 -- The object file name
1570 Obj_Path_Id : Name_Id;
1571 -- The object path name
1573 Dep_Id : Name_Id;
1574 -- The dependency file name
1576 Dep_Path_Id : Name_Id;
1577 -- The dependency path name
1579 Dot_Pos : Natural := 0;
1580 -- Position of the last dot in Name
1582 Source : Other_Source;
1583 Source_Id : Other_Source_Id := Data.First_Other_Source;
1585 begin
1586 Canonical_Case_File_Name (Path);
1588 -- Get the file name id
1590 Name_Len := Name'Length;
1591 Name_Buffer (1 .. Name_Len) := Name;
1592 File_Id := Name_Find;
1594 -- Get the path name id
1596 Name_Len := Path'Length;
1597 Name_Buffer (1 .. Name_Len) := Path;
1598 Path_Id := Name_Find;
1600 -- Find the position of the last dot
1602 for J in reverse Name'Range loop
1603 if Name (J) = '.' then
1604 Dot_Pos := J;
1605 exit;
1606 end if;
1607 end loop;
1609 if Dot_Pos <= Name'First then
1610 Dot_Pos := Name'Last + 1;
1611 end if;
1613 -- Compute the object file name
1615 Get_Name_String (File_Id);
1616 Name_Len := Dot_Pos - Name'First;
1618 for J in Object_Suffix'Range loop
1619 Name_Len := Name_Len + 1;
1620 Name_Buffer (Name_Len) := Object_Suffix (J);
1621 end loop;
1623 Obj_Id := Name_Find;
1625 -- Compute the object path name
1627 Get_Name_String (Data.Object_Directory);
1629 if Name_Buffer (Name_Len) /= Directory_Separator and then
1630 Name_Buffer (Name_Len) /= '/'
1631 then
1632 Name_Len := Name_Len + 1;
1633 Name_Buffer (Name_Len) := Directory_Separator;
1634 end if;
1636 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Id));
1637 Obj_Path_Id := Name_Find;
1639 -- Compute the dependency file name
1641 Get_Name_String (File_Id);
1642 Name_Len := Dot_Pos - Name'First + 1;
1643 Name_Buffer (Name_Len) := '.';
1644 Name_Len := Name_Len + 1;
1645 Name_Buffer (Name_Len) := 'd';
1646 Dep_Id := Name_Find;
1648 -- Compute the dependency path name
1650 Get_Name_String (Data.Object_Directory);
1652 if Name_Buffer (Name_Len) /= Directory_Separator and then
1653 Name_Buffer (Name_Len) /= '/'
1654 then
1655 Name_Len := Name_Len + 1;
1656 Name_Buffer (Name_Len) := Directory_Separator;
1657 end if;
1659 Add_Str_To_Name_Buffer (Get_Name_String (Dep_Id));
1660 Dep_Path_Id := Name_Find;
1662 -- Check if source is already in the list of source for this
1663 -- project: it may have already been specified as a naming
1664 -- exception for the same language or an other language, or they
1665 -- may be two identical file names in different source
1666 -- directories.
1668 while Source_Id /= No_Other_Source loop
1669 Source := Other_Sources.Table (Source_Id);
1670 Source_Id := Source.Next;
1672 if Source.File_Name = File_Id then
1673 -- Two sources of different languages cannot have the same
1674 -- file name.
1676 if Source.Language /= Language then
1677 Error_Msg_Name_1 := File_Name;
1678 Error_Msg
1679 (Project,
1680 "{ cannot be a source of several languages",
1681 Real_Location);
1682 return;
1684 -- No problem if a file has already been specified as
1685 -- a naming exception of this language.
1687 elsif Source.Path_Name = Path_Id then
1688 -- Reset the naming exception flag, if this is not a
1689 -- naming exception.
1691 if not Naming_Exception then
1692 Other_Sources.Table (Source_Id).Naming_Exception :=
1693 False;
1694 end if;
1696 return;
1698 -- There are several files with the same names, but the
1699 -- order of the source directories is known (no /**):
1700 -- only the first one encountered is kept, the other ones
1701 -- are ignored.
1703 elsif Data.Known_Order_Of_Source_Dirs then
1704 return;
1706 -- But it is an error if the order of the source directories
1707 -- is not known.
1709 else
1710 Error_Msg_Name_1 := File_Name;
1711 Error_Msg
1712 (Project,
1713 "{ is found in several source directories",
1714 Real_Location);
1715 return;
1716 end if;
1718 -- Two sources with different file names cannot have the same
1719 -- object file name.
1721 elsif Source.Object_Name = Obj_Id then
1722 Error_Msg_Name_1 := File_Id;
1723 Error_Msg_Name_2 := Source.File_Name;
1724 Error_Msg_Name_3 := Obj_Id;
1725 Error_Msg
1726 (Project,
1727 "{ and { have the same object file {",
1728 Real_Location);
1729 return;
1730 end if;
1731 end loop;
1733 if Current_Verbosity = High then
1734 Write_Str (" found ");
1735 Write_Str (Lang_Display_Names (Language).all);
1736 Write_Str (" source """);
1737 Write_Str (Get_Name_String (File_Name));
1738 Write_Line ("""");
1739 Write_Str (" object path = ");
1740 Write_Line (Get_Name_String (Obj_Path_Id));
1741 end if;
1743 -- Create the Other_Source record
1744 Source :=
1745 (Language => Language,
1746 File_Name => File_Id,
1747 Path_Name => Path_Id,
1748 Source_TS => File_Stamp (Path_Id),
1749 Object_Name => Obj_Id,
1750 Object_Path => Obj_Path_Id,
1751 Object_TS => File_Stamp (Obj_Path_Id),
1752 Dep_Name => Dep_Id,
1753 Dep_Path => Dep_Path_Id,
1754 Dep_TS => File_Stamp (Dep_Path_Id),
1755 Naming_Exception => Naming_Exception,
1756 Next => No_Other_Source);
1758 -- And add it to the Other_Sources table
1760 Other_Sources.Increment_Last;
1761 Other_Sources.Table (Other_Sources.Last) := Source;
1763 -- There are sources of languages other than Ada in this project
1765 Data.Other_Sources_Present := True;
1767 -- And there are sources of this language in this project
1769 Data.Languages (Language) := True;
1771 -- Add this source to the list of sources of languages other than
1772 -- Ada of the project.
1774 if Data.First_Other_Source = No_Other_Source then
1775 Data.First_Other_Source := Other_Sources.Last;
1777 else
1778 Other_Sources.Table (Data.Last_Other_Source).Next :=
1779 Other_Sources.Last;
1780 end if;
1782 Data.Last_Other_Source := Other_Sources.Last;
1783 end;
1784 end if;
1785 end Check_For_Source;
1787 --------------------------------------
1788 -- Check_Ada_Naming_Scheme_Validity --
1789 --------------------------------------
1791 procedure Check_Ada_Naming_Scheme_Validity
1792 (Project : Project_Id;
1793 Naming : Naming_Data)
1795 begin
1796 -- Only check if we are not using the standard naming scheme
1798 if Naming /= Standard_Naming_Data then
1799 declare
1800 Dot_Replacement : constant String :=
1801 Get_Name_String
1802 (Naming.Dot_Replacement);
1804 Spec_Suffix : constant String :=
1805 Get_Name_String
1806 (Naming.Current_Spec_Suffix);
1808 Body_Suffix : constant String :=
1809 Get_Name_String
1810 (Naming.Current_Body_Suffix);
1812 Separate_Suffix : constant String :=
1813 Get_Name_String
1814 (Naming.Separate_Suffix);
1816 begin
1817 -- Dot_Replacement cannot
1818 -- - be empty
1819 -- - start or end with an alphanumeric
1820 -- - be a single '_'
1821 -- - start with an '_' followed by an alphanumeric
1822 -- - contain a '.' except if it is "."
1824 if Dot_Replacement'Length = 0
1825 or else Is_Alphanumeric
1826 (Dot_Replacement (Dot_Replacement'First))
1827 or else Is_Alphanumeric
1828 (Dot_Replacement (Dot_Replacement'Last))
1829 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1830 and then
1831 (Dot_Replacement'Length = 1
1832 or else
1833 Is_Alphanumeric
1834 (Dot_Replacement (Dot_Replacement'First + 1))))
1835 or else (Dot_Replacement'Length > 1
1836 and then
1837 Index (Source => Dot_Replacement,
1838 Pattern => ".") /= 0)
1839 then
1840 Error_Msg
1841 (Project,
1842 '"' & Dot_Replacement &
1843 """ is illegal for Dot_Replacement.",
1844 Naming.Dot_Repl_Loc);
1845 end if;
1847 -- Suffixes cannot
1848 -- - be empty
1850 if Is_Illegal_Suffix
1851 (Spec_Suffix, Dot_Replacement = ".")
1852 then
1853 Err_Vars.Error_Msg_Name_1 := Naming.Current_Spec_Suffix;
1854 Error_Msg
1855 (Project,
1856 "{ is illegal for Spec_Suffix",
1857 Naming.Spec_Suffix_Loc);
1858 end if;
1860 if Is_Illegal_Suffix
1861 (Body_Suffix, Dot_Replacement = ".")
1862 then
1863 Err_Vars.Error_Msg_Name_1 := Naming.Current_Body_Suffix;
1864 Error_Msg
1865 (Project,
1866 "{ is illegal for Body_Suffix",
1867 Naming.Body_Suffix_Loc);
1868 end if;
1870 if Body_Suffix /= Separate_Suffix then
1871 if Is_Illegal_Suffix
1872 (Separate_Suffix, Dot_Replacement = ".")
1873 then
1874 Err_Vars.Error_Msg_Name_1 := Naming.Separate_Suffix;
1875 Error_Msg
1876 (Project,
1877 "{ is illegal for Separate_Suffix",
1878 Naming.Sep_Suffix_Loc);
1879 end if;
1880 end if;
1882 -- Spec_Suffix cannot have the same termination as
1883 -- Body_Suffix or Separate_Suffix
1885 if Spec_Suffix'Length <= Body_Suffix'Length
1886 and then
1887 Body_Suffix (Body_Suffix'Last -
1888 Spec_Suffix'Length + 1 ..
1889 Body_Suffix'Last) = Spec_Suffix
1890 then
1891 Error_Msg
1892 (Project,
1893 "Body_Suffix (""" &
1894 Body_Suffix &
1895 """) cannot end with" &
1896 " Spec_Suffix (""" &
1897 Spec_Suffix & """).",
1898 Naming.Body_Suffix_Loc);
1899 end if;
1901 if Body_Suffix /= Separate_Suffix
1902 and then Spec_Suffix'Length <= Separate_Suffix'Length
1903 and then
1904 Separate_Suffix
1905 (Separate_Suffix'Last - Spec_Suffix'Length + 1
1907 Separate_Suffix'Last) = Spec_Suffix
1908 then
1909 Error_Msg
1910 (Project,
1911 "Separate_Suffix (""" &
1912 Separate_Suffix &
1913 """) cannot end with" &
1914 " Spec_Suffix (""" &
1915 Spec_Suffix & """).",
1916 Naming.Sep_Suffix_Loc);
1917 end if;
1918 end;
1919 end if;
1920 end Check_Ada_Naming_Scheme_Validity;
1922 -----------------------------
1923 -- Check_Ada_Naming_Scheme --
1924 -----------------------------
1926 procedure Check_Ada_Naming_Scheme
1927 (Data : in out Project_Data;
1928 Project : Project_Id)
1930 Naming_Id : constant Package_Id :=
1931 Util.Value_Of (Name_Naming, Data.Decl.Packages);
1933 Naming : Package_Element;
1935 procedure Check_Unit_Names (List : Array_Element_Id);
1936 -- Check that a list of unit names contains only valid names.
1938 ----------------------
1939 -- Check_Unit_Names --
1940 ----------------------
1942 procedure Check_Unit_Names (List : Array_Element_Id) is
1943 Current : Array_Element_Id := List;
1944 Element : Array_Element;
1945 Unit_Name : Name_Id;
1947 begin
1948 -- Loop through elements of the string list
1950 while Current /= No_Array_Element loop
1951 Element := Array_Elements.Table (Current);
1953 -- Put file name in canonical case
1955 Get_Name_String (Element.Value.Value);
1956 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1957 Element.Value.Value := Name_Find;
1959 -- Check that it contains a valid unit name
1961 Get_Name_String (Element.Index);
1962 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
1964 if Unit_Name = No_Name then
1965 Err_Vars.Error_Msg_Name_1 := Element.Index;
1966 Error_Msg
1967 (Project,
1968 "{ is not a valid unit name.",
1969 Element.Value.Location);
1971 else
1972 if Current_Verbosity = High then
1973 Write_Str (" Unit (""");
1974 Write_Str (Get_Name_String (Unit_Name));
1975 Write_Line (""")");
1976 end if;
1978 Element.Index := Unit_Name;
1979 Array_Elements.Table (Current) := Element;
1980 end if;
1982 Current := Element.Next;
1983 end loop;
1984 end Check_Unit_Names;
1986 -- Start of processing for Check_Ada_Naming_Scheme
1988 begin
1989 -- If there is a package Naming, we will put in Data.Naming what is in
1990 -- this package Naming.
1992 if Naming_Id /= No_Package then
1993 Naming := Packages.Table (Naming_Id);
1995 if Current_Verbosity = High then
1996 Write_Line ("Checking ""Naming"" for Ada.");
1997 end if;
1999 declare
2000 Bodies : constant Array_Element_Id :=
2001 Util.Value_Of (Name_Body, Naming.Decl.Arrays);
2003 Specs : constant Array_Element_Id :=
2004 Util.Value_Of (Name_Spec, Naming.Decl.Arrays);
2006 begin
2007 if Bodies /= No_Array_Element then
2009 -- We have elements in the array Body_Part
2011 if Current_Verbosity = High then
2012 Write_Line ("Found Bodies.");
2013 end if;
2015 Data.Naming.Bodies := Bodies;
2016 Check_Unit_Names (Bodies);
2018 else
2019 if Current_Verbosity = High then
2020 Write_Line ("No Bodies.");
2021 end if;
2022 end if;
2024 if Specs /= No_Array_Element then
2026 -- We have elements in the array Specs
2028 if Current_Verbosity = High then
2029 Write_Line ("Found Specs.");
2030 end if;
2032 Data.Naming.Specs := Specs;
2033 Check_Unit_Names (Specs);
2035 else
2036 if Current_Verbosity = High then
2037 Write_Line ("No Specs.");
2038 end if;
2039 end if;
2040 end;
2042 -- We are now checking if variables Dot_Replacement, Casing,
2043 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix
2044 -- exist.
2046 -- For each variable, if it does not exist, we do nothing,
2047 -- because we already have the default.
2049 -- Check Dot_Replacement
2051 declare
2052 Dot_Replacement : constant Variable_Value :=
2053 Util.Value_Of
2054 (Name_Dot_Replacement,
2055 Naming.Decl.Attributes);
2057 begin
2058 pragma Assert (Dot_Replacement.Kind = Single,
2059 "Dot_Replacement is not a single string");
2061 if not Dot_Replacement.Default then
2062 Get_Name_String (Dot_Replacement.Value);
2064 if Name_Len = 0 then
2065 Error_Msg
2066 (Project,
2067 "Dot_Replacement cannot be empty",
2068 Dot_Replacement.Location);
2070 else
2071 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2072 Data.Naming.Dot_Replacement := Name_Find;
2073 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
2074 end if;
2075 end if;
2076 end;
2078 if Current_Verbosity = High then
2079 Write_Str (" Dot_Replacement = """);
2080 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
2081 Write_Char ('"');
2082 Write_Eol;
2083 end if;
2085 -- Check Casing
2087 declare
2088 Casing_String : constant Variable_Value :=
2089 Util.Value_Of
2090 (Name_Casing, Naming.Decl.Attributes);
2092 begin
2093 pragma Assert (Casing_String.Kind = Single,
2094 "Casing is not a single string");
2096 if not Casing_String.Default then
2097 declare
2098 Casing_Image : constant String :=
2099 Get_Name_String (Casing_String.Value);
2100 begin
2101 declare
2102 Casing_Value : constant Casing_Type :=
2103 Value (Casing_Image);
2104 begin
2105 -- Ignore Casing on platforms where file names are
2106 -- case-insensitive.
2108 if not File_Names_Case_Sensitive then
2109 Data.Naming.Casing := All_Lower_Case;
2111 else
2112 Data.Naming.Casing := Casing_Value;
2113 end if;
2114 end;
2116 exception
2117 when Constraint_Error =>
2118 if Casing_Image'Length = 0 then
2119 Error_Msg
2120 (Project,
2121 "Casing cannot be an empty string",
2122 Casing_String.Location);
2124 else
2125 Name_Len := Casing_Image'Length;
2126 Name_Buffer (1 .. Name_Len) := Casing_Image;
2127 Err_Vars.Error_Msg_Name_1 := Name_Find;
2128 Error_Msg
2129 (Project,
2130 "{ is not a correct Casing",
2131 Casing_String.Location);
2132 end if;
2133 end;
2134 end if;
2135 end;
2137 if Current_Verbosity = High then
2138 Write_Str (" Casing = ");
2139 Write_Str (Image (Data.Naming.Casing));
2140 Write_Char ('.');
2141 Write_Eol;
2142 end if;
2144 -- Check Spec_Suffix
2146 declare
2147 Ada_Spec_Suffix : constant Variable_Value :=
2148 Prj.Util.Value_Of
2149 (Index => Name_Ada,
2150 Src_Index => 0,
2151 In_Array => Data.Naming.Spec_Suffix);
2153 begin
2154 if Ada_Spec_Suffix.Kind = Single
2155 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
2156 then
2157 Get_Name_String (Ada_Spec_Suffix.Value);
2158 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2159 Data.Naming.Current_Spec_Suffix := Name_Find;
2160 Data.Naming.Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
2162 else
2163 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2164 end if;
2165 end;
2167 if Current_Verbosity = High then
2168 Write_Str (" Spec_Suffix = """);
2169 Write_Str (Get_Name_String (Data.Naming.Current_Spec_Suffix));
2170 Write_Char ('"');
2171 Write_Eol;
2172 end if;
2174 -- Check Body_Suffix
2176 declare
2177 Ada_Body_Suffix : constant Variable_Value :=
2178 Prj.Util.Value_Of
2179 (Index => Name_Ada,
2180 Src_Index => 0,
2181 In_Array => Data.Naming.Body_Suffix);
2183 begin
2184 if Ada_Body_Suffix.Kind = Single
2185 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
2186 then
2187 Get_Name_String (Ada_Body_Suffix.Value);
2188 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2189 Data.Naming.Current_Body_Suffix := Name_Find;
2190 Data.Naming.Body_Suffix_Loc := Ada_Body_Suffix.Location;
2192 else
2193 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2194 end if;
2195 end;
2197 if Current_Verbosity = High then
2198 Write_Str (" Body_Suffix = """);
2199 Write_Str (Get_Name_String (Data.Naming.Current_Body_Suffix));
2200 Write_Char ('"');
2201 Write_Eol;
2202 end if;
2204 -- Check Separate_Suffix
2206 declare
2207 Ada_Sep_Suffix : constant Variable_Value :=
2208 Prj.Util.Value_Of
2209 (Variable_Name => Name_Separate_Suffix,
2210 In_Variables => Naming.Decl.Attributes);
2212 begin
2213 if Ada_Sep_Suffix.Default then
2214 Data.Naming.Separate_Suffix :=
2215 Data.Naming.Current_Body_Suffix;
2217 else
2218 Get_Name_String (Ada_Sep_Suffix.Value);
2220 if Name_Len = 0 then
2221 Error_Msg
2222 (Project,
2223 "Separate_Suffix cannot be empty",
2224 Ada_Sep_Suffix.Location);
2226 else
2227 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2228 Data.Naming.Separate_Suffix := Name_Find;
2229 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
2230 end if;
2231 end if;
2232 end;
2234 if Current_Verbosity = High then
2235 Write_Str (" Separate_Suffix = """);
2236 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
2237 Write_Char ('"');
2238 Write_Eol;
2239 end if;
2241 -- Check if Data.Naming is valid
2243 Check_Ada_Naming_Scheme_Validity (Project, Data.Naming);
2245 else
2246 Data.Naming.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
2247 Data.Naming.Current_Body_Suffix := Default_Ada_Body_Suffix;
2248 Data.Naming.Separate_Suffix := Default_Ada_Body_Suffix;
2249 end if;
2250 end Check_Ada_Naming_Scheme;
2252 -------------------
2253 -- Check_Project --
2254 -------------------
2256 function Check_Project
2257 (P : Project_Id;
2258 Root_Project : Project_Id;
2259 Extending : Boolean) return Boolean
2261 begin
2262 if P = Root_Project then
2263 return True;
2265 elsif Extending then
2266 declare
2267 Data : Project_Data := Projects.Table (Root_Project);
2269 begin
2270 while Data.Extends /= No_Project loop
2271 if P = Data.Extends then
2272 return True;
2273 end if;
2275 Data := Projects.Table (Data.Extends);
2276 end loop;
2277 end;
2278 end if;
2280 return False;
2281 end Check_Project;
2283 ----------------------------
2284 -- Compute_Directory_Last --
2285 ----------------------------
2287 function Compute_Directory_Last (Dir : String) return Natural is
2288 begin
2289 if Dir'Length > 1
2290 and then (Dir (Dir'Last - 1) = Directory_Separator
2291 or else Dir (Dir'Last - 1) = '/')
2292 then
2293 return Dir'Last - 1;
2294 else
2295 return Dir'Last;
2296 end if;
2297 end Compute_Directory_Last;
2299 ---------------
2300 -- Error_Msg --
2301 ---------------
2303 procedure Error_Msg
2304 (Project : Project_Id;
2305 Msg : String;
2306 Flag_Location : Source_Ptr)
2308 Error_Buffer : String (1 .. 5_000);
2309 Error_Last : Natural := 0;
2310 Msg_Name : Natural := 0;
2311 First : Positive := Msg'First;
2313 procedure Add (C : Character);
2314 -- Add a character to the buffer
2316 procedure Add (S : String);
2317 -- Add a string to the buffer
2319 procedure Add (Id : Name_Id);
2320 -- Add a name to the buffer
2322 ---------
2323 -- Add --
2324 ---------
2326 procedure Add (C : Character) is
2327 begin
2328 Error_Last := Error_Last + 1;
2329 Error_Buffer (Error_Last) := C;
2330 end Add;
2332 procedure Add (S : String) is
2333 begin
2334 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
2335 Error_Last := Error_Last + S'Length;
2336 end Add;
2338 procedure Add (Id : Name_Id) is
2339 begin
2340 Get_Name_String (Id);
2341 Add (Name_Buffer (1 .. Name_Len));
2342 end Add;
2344 -- Start of processing for Error_Msg
2346 begin
2347 if Error_Report = null then
2348 Prj.Err.Error_Msg (Msg, Flag_Location);
2349 return;
2350 end if;
2352 if Msg (First) = '\' then
2354 -- Continuation character, ignore.
2356 First := First + 1;
2358 elsif Msg (First) = '?' then
2360 -- Warning character. It is always the first one in this package
2362 First := First + 1;
2363 Add ("Warning: ");
2364 end if;
2366 for Index in First .. Msg'Last loop
2367 if Msg (Index) = '{' or else Msg (Index) = '%' then
2369 -- Include a name between double quotes.
2371 Msg_Name := Msg_Name + 1;
2372 Add ('"');
2374 case Msg_Name is
2375 when 1 => Add (Err_Vars.Error_Msg_Name_1);
2376 when 2 => Add (Err_Vars.Error_Msg_Name_2);
2377 when 3 => Add (Err_Vars.Error_Msg_Name_3);
2379 when others => null;
2380 end case;
2382 Add ('"');
2384 else
2385 Add (Msg (Index));
2386 end if;
2388 end loop;
2390 Error_Report (Error_Buffer (1 .. Error_Last), Project);
2391 end Error_Msg;
2393 ------------------
2394 -- Find_Sources --
2395 ------------------
2397 procedure Find_Sources
2398 (Project : Project_Id;
2399 Data : in out Project_Data;
2400 For_Language : Programming_Language;
2401 Follow_Links : Boolean := False)
2403 Source_Dir : String_List_Id := Data.Source_Dirs;
2404 Element : String_Element;
2405 Dir : Dir_Type;
2406 Current_Source : String_List_Id := Nil_String;
2407 Source_Recorded : Boolean := False;
2409 begin
2410 if Current_Verbosity = High then
2411 Write_Line ("Looking for sources:");
2412 end if;
2414 -- For each subdirectory
2416 while Source_Dir /= Nil_String loop
2417 begin
2418 Source_Recorded := False;
2419 Element := String_Elements.Table (Source_Dir);
2420 if Element.Value /= No_Name then
2421 Get_Name_String (Element.Display_Value);
2423 declare
2424 Source_Directory : constant String :=
2425 Name_Buffer (1 .. Name_Len) & Directory_Separator;
2426 Dir_Last : constant Natural :=
2427 Compute_Directory_Last (Source_Directory);
2429 begin
2430 if Current_Verbosity = High then
2431 Write_Str ("Source_Dir = ");
2432 Write_Line (Source_Directory);
2433 end if;
2435 -- We look to every entry in the source directory
2437 Open (Dir, Source_Directory
2438 (Source_Directory'First .. Dir_Last));
2440 loop
2441 Read (Dir, Name_Buffer, Name_Len);
2443 if Current_Verbosity = High then
2444 Write_Str (" Checking ");
2445 Write_Line (Name_Buffer (1 .. Name_Len));
2446 end if;
2448 exit when Name_Len = 0;
2450 declare
2451 File_Name : constant Name_Id := Name_Find;
2452 Path : constant String :=
2453 Normalize_Pathname
2454 (Name => Name_Buffer (1 .. Name_Len),
2455 Directory => Source_Directory
2456 (Source_Directory'First .. Dir_Last),
2457 Resolve_Links => Follow_Links,
2458 Case_Sensitive => True);
2459 Path_Name : Name_Id;
2461 begin
2462 Name_Len := Path'Length;
2463 Name_Buffer (1 .. Name_Len) := Path;
2464 Path_Name := Name_Find;
2466 if For_Language = Lang_Ada then
2467 -- We attempt to register it as a source.
2468 -- However, there is no error if the file
2469 -- does not contain a valid source.
2470 -- But there is an error if we have a
2471 -- duplicate unit name.
2473 Record_Ada_Source
2474 (File_Name => File_Name,
2475 Path_Name => Path_Name,
2476 Project => Project,
2477 Data => Data,
2478 Location => No_Location,
2479 Current_Source => Current_Source,
2480 Source_Recorded => Source_Recorded,
2481 Follow_Links => Follow_Links);
2483 else
2484 Check_For_Source
2485 (File_Name => File_Name,
2486 Path_Name => Path_Name,
2487 Project => Project,
2488 Data => Data,
2489 Location => No_Location,
2490 Language => For_Language,
2491 Suffix =>
2492 Get_Name_String
2493 (Data.Impl_Suffixes (For_Language)),
2494 Naming_Exception => False);
2495 end if;
2496 end;
2497 end loop;
2499 Close (Dir);
2500 end;
2501 end if;
2503 exception
2504 when Directory_Error =>
2505 null;
2506 end;
2508 if Source_Recorded then
2509 String_Elements.Table (Source_Dir).Flag := True;
2510 end if;
2512 Source_Dir := Element.Next;
2513 end loop;
2515 if Current_Verbosity = High then
2516 Write_Line ("end Looking for sources.");
2517 end if;
2519 if For_Language = Lang_Ada then
2520 -- If we have looked for sources and found none, then
2521 -- it is an error, except if it is an extending project.
2522 -- If a non extending project is not supposed to contain
2523 -- any source, then we never call Find_Sources.
2525 if Current_Source /= Nil_String then
2526 Data.Ada_Sources_Present := True;
2528 elsif Data.Extends = No_Project then
2529 Error_Msg
2530 (Project,
2531 "there are no Ada sources in this project",
2532 Data.Location);
2533 end if;
2534 end if;
2535 end Find_Sources;
2537 --------------------------------
2538 -- Free_Ada_Naming_Exceptions --
2539 --------------------------------
2541 procedure Free_Ada_Naming_Exceptions is
2542 begin
2543 Ada_Naming_Exception_Table.Set_Last (0);
2544 Ada_Naming_Exceptions.Reset;
2545 Reverse_Ada_Naming_Exceptions.Reset;
2546 end Free_Ada_Naming_Exceptions;
2548 ---------------
2549 -- Get_Mains --
2550 ---------------
2552 procedure Get_Mains (Project : Project_Id; Data : in out Project_Data) is
2553 Mains : constant Variable_Value :=
2554 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes);
2556 begin
2557 Data.Mains := Mains.Values;
2559 -- If no Mains were specified, and if we are an extending
2560 -- project, inherit the Mains from the project we are extending.
2562 if Mains.Default then
2563 if Data.Extends /= No_Project then
2564 Data.Mains := Projects.Table (Data.Extends).Mains;
2565 end if;
2567 -- In a library project file, Main cannot be specified
2569 elsif Data.Library then
2570 Error_Msg
2571 (Project,
2572 "a library project file cannot have Main specified",
2573 Mains.Location);
2574 end if;
2575 end Get_Mains;
2577 ---------------------------
2578 -- Get_Sources_From_File --
2579 ---------------------------
2581 procedure Get_Sources_From_File
2582 (Path : String;
2583 Location : Source_Ptr;
2584 Project : Project_Id)
2586 File : Prj.Util.Text_File;
2587 Line : String (1 .. 250);
2588 Last : Natural;
2589 Source_Name : Name_Id;
2591 begin
2592 Source_Names.Reset;
2594 if Current_Verbosity = High then
2595 Write_Str ("Opening """);
2596 Write_Str (Path);
2597 Write_Line (""".");
2598 end if;
2600 -- Open the file
2602 Prj.Util.Open (File, Path);
2604 if not Prj.Util.Is_Valid (File) then
2605 Error_Msg (Project, "file does not exist", Location);
2606 else
2607 -- Read the lines one by one
2609 while not Prj.Util.End_Of_File (File) loop
2610 Prj.Util.Get_Line (File, Line, Last);
2612 -- A non empty, non comment line should contain a file name
2614 if Last /= 0
2615 and then (Last = 1 or else Line (1 .. 2) /= "--")
2616 then
2617 -- ??? we should check that there is no directory information
2619 Name_Len := Last;
2620 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
2621 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2622 Source_Name := Name_Find;
2623 Source_Names.Set
2624 (K => Source_Name,
2625 E =>
2626 (Name => Source_Name,
2627 Location => Location,
2628 Found => False));
2629 end if;
2630 end loop;
2632 Prj.Util.Close (File);
2634 end if;
2635 end Get_Sources_From_File;
2637 --------------
2638 -- Get_Unit --
2639 --------------
2641 procedure Get_Unit
2642 (Canonical_File_Name : Name_Id;
2643 Naming : Naming_Data;
2644 Exception_Id : out Ada_Naming_Exception_Id;
2645 Unit_Name : out Name_Id;
2646 Unit_Kind : out Spec_Or_Body;
2647 Needs_Pragma : out Boolean)
2649 Info_Id : Ada_Naming_Exception_Id
2650 := Ada_Naming_Exceptions.Get (Canonical_File_Name);
2651 VMS_Name : Name_Id;
2653 begin
2654 if Info_Id = No_Ada_Naming_Exception then
2655 if Hostparm.OpenVMS then
2656 VMS_Name := Canonical_File_Name;
2657 Get_Name_String (VMS_Name);
2659 if Name_Buffer (Name_Len) = '.' then
2660 Name_Len := Name_Len - 1;
2661 VMS_Name := Name_Find;
2662 end if;
2664 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
2665 end if;
2667 end if;
2669 if Info_Id /= No_Ada_Naming_Exception then
2670 Exception_Id := Info_Id;
2671 Unit_Name := No_Name;
2672 Unit_Kind := Specification;
2673 Needs_Pragma := True;
2674 return;
2675 end if;
2677 Needs_Pragma := False;
2678 Exception_Id := No_Ada_Naming_Exception;
2680 Get_Name_String (Canonical_File_Name);
2682 declare
2683 File : String := Name_Buffer (1 .. Name_Len);
2684 First : constant Positive := File'First;
2685 Last : Natural := File'Last;
2686 Standard_GNAT : Boolean;
2688 begin
2689 Standard_GNAT :=
2690 Naming.Current_Spec_Suffix = Default_Ada_Spec_Suffix
2691 and then Naming.Current_Body_Suffix = Default_Ada_Body_Suffix;
2693 -- Check if the end of the file name is Specification_Append
2695 Get_Name_String (Naming.Current_Spec_Suffix);
2697 if File'Length > Name_Len
2698 and then File (Last - Name_Len + 1 .. Last) =
2699 Name_Buffer (1 .. Name_Len)
2700 then
2701 -- We have a spec
2703 Unit_Kind := Specification;
2704 Last := Last - Name_Len;
2706 if Current_Verbosity = High then
2707 Write_Str (" Specification: ");
2708 Write_Line (File (First .. Last));
2709 end if;
2711 else
2712 Get_Name_String (Naming.Current_Body_Suffix);
2714 -- Check if the end of the file name is Body_Append
2716 if File'Length > Name_Len
2717 and then File (Last - Name_Len + 1 .. Last) =
2718 Name_Buffer (1 .. Name_Len)
2719 then
2720 -- We have a body
2722 Unit_Kind := Body_Part;
2723 Last := Last - Name_Len;
2725 if Current_Verbosity = High then
2726 Write_Str (" Body: ");
2727 Write_Line (File (First .. Last));
2728 end if;
2730 elsif Naming.Separate_Suffix /= Naming.Current_Spec_Suffix then
2731 Get_Name_String (Naming.Separate_Suffix);
2733 -- Check if the end of the file name is Separate_Append
2735 if File'Length > Name_Len
2736 and then File (Last - Name_Len + 1 .. Last) =
2737 Name_Buffer (1 .. Name_Len)
2738 then
2739 -- We have a separate (a body)
2741 Unit_Kind := Body_Part;
2742 Last := Last - Name_Len;
2744 if Current_Verbosity = High then
2745 Write_Str (" Separate: ");
2746 Write_Line (File (First .. Last));
2747 end if;
2749 else
2750 Last := 0;
2751 end if;
2753 else
2754 Last := 0;
2755 end if;
2756 end if;
2758 if Last = 0 then
2760 -- This is not a source file
2762 Unit_Name := No_Name;
2763 Unit_Kind := Specification;
2765 if Current_Verbosity = High then
2766 Write_Line (" Not a valid file name.");
2767 end if;
2769 return;
2770 end if;
2772 Get_Name_String (Naming.Dot_Replacement);
2773 Standard_GNAT :=
2774 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
2776 if Name_Buffer (1 .. Name_Len) /= "." then
2778 -- If Dot_Replacement is not a single dot,
2779 -- then there should not be any dot in the name.
2781 for Index in First .. Last loop
2782 if File (Index) = '.' then
2783 if Current_Verbosity = High then
2784 Write_Line
2785 (" Not a valid file name (some dot not replaced).");
2786 end if;
2788 Unit_Name := No_Name;
2789 return;
2791 end if;
2792 end loop;
2794 -- Replace the substring Dot_Replacement with dots
2796 declare
2797 Index : Positive := First;
2799 begin
2800 while Index <= Last - Name_Len + 1 loop
2802 if File (Index .. Index + Name_Len - 1) =
2803 Name_Buffer (1 .. Name_Len)
2804 then
2805 File (Index) := '.';
2807 if Name_Len > 1 and then Index < Last then
2808 File (Index + 1 .. Last - Name_Len + 1) :=
2809 File (Index + Name_Len .. Last);
2810 end if;
2812 Last := Last - Name_Len + 1;
2813 end if;
2815 Index := Index + 1;
2816 end loop;
2817 end;
2818 end if;
2820 -- Check if the casing is right
2822 declare
2823 Src : String := File (First .. Last);
2825 begin
2826 case Naming.Casing is
2827 when All_Lower_Case =>
2828 Fixed.Translate
2829 (Source => Src,
2830 Mapping => Lower_Case_Map);
2832 when All_Upper_Case =>
2833 Fixed.Translate
2834 (Source => Src,
2835 Mapping => Upper_Case_Map);
2837 when Mixed_Case | Unknown =>
2838 null;
2839 end case;
2841 if Src /= File (First .. Last) then
2842 if Current_Verbosity = High then
2843 Write_Line (" Not a valid file name (casing).");
2844 end if;
2846 Unit_Name := No_Name;
2847 return;
2848 end if;
2850 -- We put the name in lower case
2852 Fixed.Translate
2853 (Source => Src,
2854 Mapping => Lower_Case_Map);
2856 -- In the standard GNAT naming scheme, check for special cases:
2857 -- children or separates of A, G, I or S, and run time sources.
2859 if Standard_GNAT and then Src'Length >= 3 then
2860 declare
2861 S1 : constant Character := Src (Src'First);
2862 S2 : constant Character := Src (Src'First + 1);
2864 begin
2865 if S1 = 'a' or else S1 = 'g'
2866 or else S1 = 'i' or else S1 = 's'
2867 then
2868 -- Children or separates of packages A, G, I or S
2870 if (Hostparm.OpenVMS and then S2 = '$')
2871 or else (not Hostparm.OpenVMS and then S2 = '~')
2872 then
2873 Src (Src'First + 1) := '.';
2875 -- If it is potentially a run time source, disable
2876 -- filling of the mapping file to avoid warnings.
2878 elsif S2 = '.' then
2879 Set_Mapping_File_Initial_State_To_Empty;
2880 end if;
2882 end if;
2883 end;
2884 end if;
2886 if Current_Verbosity = High then
2887 Write_Str (" ");
2888 Write_Line (Src);
2889 end if;
2891 -- Now, we check if this name is a valid unit name
2893 Check_Ada_Name (Name => Src, Unit => Unit_Name);
2894 end;
2896 end;
2897 end Get_Unit;
2899 ----------
2900 -- Hash --
2901 ----------
2903 function Hash (Unit : Unit_Info) return Header_Num is
2904 begin
2905 return Header_Num (Unit.Unit mod 2048);
2906 end Hash;
2908 -----------------------
2909 -- Is_Illegal_Suffix --
2910 -----------------------
2912 function Is_Illegal_Suffix
2913 (Suffix : String;
2914 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
2916 begin
2917 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
2918 return True;
2919 end if;
2921 -- If dot replacement is a single dot, and first character of
2922 -- suffix is also a dot
2924 if Dot_Replacement_Is_A_Single_Dot
2925 and then Suffix (Suffix'First) = '.'
2926 then
2927 for Index in Suffix'First + 1 .. Suffix'Last loop
2929 -- If there is another dot
2931 if Suffix (Index) = '.' then
2933 -- It is illegal to have a letter following the initial dot
2935 return Is_Letter (Suffix (Suffix'First + 1));
2936 end if;
2937 end loop;
2938 end if;
2940 -- Everything is OK
2942 return False;
2943 end Is_Illegal_Suffix;
2945 --------------------------------
2946 -- Language_Independent_Check --
2947 --------------------------------
2949 procedure Language_Independent_Check
2950 (Project : Project_Id;
2951 Report_Error : Put_Line_Access)
2953 Last_Source_Dir : String_List_Id := Nil_String;
2954 Data : Project_Data := Projects.Table (Project);
2956 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr);
2957 -- Find one or several source directories, and add them
2958 -- to the list of source directories of the project.
2960 ----------------------
2961 -- Find_Source_Dirs --
2962 ----------------------
2964 procedure Find_Source_Dirs (From : Name_Id; Location : Source_Ptr) is
2965 Directory : constant String := Get_Name_String (From);
2966 Element : String_Element;
2968 procedure Recursive_Find_Dirs (Path : Name_Id);
2969 -- Find all the subdirectories (recursively) of Path and add them
2970 -- to the list of source directories of the project.
2972 -------------------------
2973 -- Recursive_Find_Dirs --
2974 -------------------------
2976 procedure Recursive_Find_Dirs (Path : Name_Id) is
2977 Dir : Dir_Type;
2978 Name : String (1 .. 250);
2979 Last : Natural;
2980 List : String_List_Id := Data.Source_Dirs;
2981 Element : String_Element;
2982 Found : Boolean := False;
2984 Non_Canonical_Path : Name_Id := No_Name;
2985 Canonical_Path : Name_Id := No_Name;
2987 The_Path : constant String :=
2988 Normalize_Pathname (Get_Name_String (Path)) &
2989 Directory_Separator;
2991 The_Path_Last : constant Natural :=
2992 Compute_Directory_Last (The_Path);
2994 begin
2995 Name_Len := The_Path_Last - The_Path'First + 1;
2996 Name_Buffer (1 .. Name_Len) :=
2997 The_Path (The_Path'First .. The_Path_Last);
2998 Non_Canonical_Path := Name_Find;
2999 Get_Name_String (Non_Canonical_Path);
3000 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3001 Canonical_Path := Name_Find;
3003 -- To avoid processing the same directory several times, check
3004 -- if the directory is already in Recursive_Dirs. If it is,
3005 -- then there is nothing to do, just return. If it is not, put
3006 -- it there and continue recursive processing.
3008 if Recursive_Dirs.Get (Canonical_Path) then
3009 return;
3011 else
3012 Recursive_Dirs.Set (Canonical_Path, True);
3013 end if;
3015 -- Check if directory is already in list
3017 while List /= Nil_String loop
3018 Element := String_Elements.Table (List);
3020 if Element.Value /= No_Name then
3021 Found := Element.Value = Canonical_Path;
3022 exit when Found;
3023 end if;
3025 List := Element.Next;
3026 end loop;
3028 -- If directory is not already in list, put it there
3030 if not Found then
3031 if Current_Verbosity = High then
3032 Write_Str (" ");
3033 Write_Line (The_Path (The_Path'First .. The_Path_Last));
3034 end if;
3036 String_Elements.Increment_Last;
3037 Element :=
3038 (Value => Canonical_Path,
3039 Display_Value => Non_Canonical_Path,
3040 Location => No_Location,
3041 Flag => False,
3042 Next => Nil_String,
3043 Index => 0);
3045 -- Case of first source directory
3047 if Last_Source_Dir = Nil_String then
3048 Data.Source_Dirs := String_Elements.Last;
3050 -- Here we already have source directories.
3052 else
3053 -- Link the previous last to the new one
3055 String_Elements.Table (Last_Source_Dir).Next :=
3056 String_Elements.Last;
3057 end if;
3059 -- And register this source directory as the new last
3061 Last_Source_Dir := String_Elements.Last;
3062 String_Elements.Table (Last_Source_Dir) := Element;
3063 end if;
3065 -- Now look for subdirectories. We do that even when this
3066 -- directory is already in the list, because some of its
3067 -- subdirectories may not be in the list yet.
3069 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
3071 loop
3072 Read (Dir, Name, Last);
3073 exit when Last = 0;
3075 if Name (1 .. Last) /= "."
3076 and then Name (1 .. Last) /= ".."
3077 then
3078 -- Avoid . and ..
3080 if Current_Verbosity = High then
3081 Write_Str (" Checking ");
3082 Write_Line (Name (1 .. Last));
3083 end if;
3085 declare
3086 Path_Name : constant String :=
3087 Normalize_Pathname
3088 (Name => Name (1 .. Last),
3089 Directory =>
3090 The_Path
3091 (The_Path'First .. The_Path_Last),
3092 Resolve_Links => False,
3093 Case_Sensitive => True);
3095 begin
3096 if Is_Directory (Path_Name) then
3098 -- We have found a new subdirectory, call self
3100 Name_Len := Path_Name'Length;
3101 Name_Buffer (1 .. Name_Len) := Path_Name;
3102 Recursive_Find_Dirs (Name_Find);
3103 end if;
3104 end;
3105 end if;
3106 end loop;
3108 Close (Dir);
3110 exception
3111 when Directory_Error =>
3112 null;
3113 end Recursive_Find_Dirs;
3115 -- Start of processing for Find_Source_Dirs
3117 begin
3118 if Current_Verbosity = High then
3119 Write_Str ("Find_Source_Dirs (""");
3120 Write_Str (Directory);
3121 Write_Line (""")");
3122 end if;
3124 -- First, check if we are looking for a directory tree,
3125 -- indicated by "/**" at the end.
3127 if Directory'Length >= 3
3128 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
3129 and then (Directory (Directory'Last - 2) = '/'
3130 or else
3131 Directory (Directory'Last - 2) = Directory_Separator)
3132 then
3133 Data.Known_Order_Of_Source_Dirs := False;
3135 Name_Len := Directory'Length - 3;
3137 if Name_Len = 0 then
3139 -- This is the case of "/**": all directories
3140 -- in the file system.
3142 Name_Len := 1;
3143 Name_Buffer (1) := Directory (Directory'First);
3145 else
3146 Name_Buffer (1 .. Name_Len) :=
3147 Directory (Directory'First .. Directory'Last - 3);
3148 end if;
3150 if Current_Verbosity = High then
3151 Write_Str ("Looking for all subdirectories of """);
3152 Write_Str (Name_Buffer (1 .. Name_Len));
3153 Write_Line ("""");
3154 end if;
3156 declare
3157 Base_Dir : constant Name_Id := Name_Find;
3158 Root_Dir : constant String :=
3159 Normalize_Pathname
3160 (Name => Get_Name_String (Base_Dir),
3161 Directory =>
3162 Get_Name_String (Data.Display_Directory),
3163 Resolve_Links => False,
3164 Case_Sensitive => True);
3166 begin
3167 if Root_Dir'Length = 0 then
3168 Err_Vars.Error_Msg_Name_1 := Base_Dir;
3170 if Location = No_Location then
3171 Error_Msg
3172 (Project,
3173 "{ is not a valid directory.",
3174 Data.Location);
3175 else
3176 Error_Msg
3177 (Project,
3178 "{ is not a valid directory.",
3179 Location);
3180 end if;
3182 else
3183 -- We have an existing directory,
3184 -- we register it and all of its subdirectories.
3186 if Current_Verbosity = High then
3187 Write_Line ("Looking for source directories:");
3188 end if;
3190 Name_Len := Root_Dir'Length;
3191 Name_Buffer (1 .. Name_Len) := Root_Dir;
3192 Recursive_Find_Dirs (Name_Find);
3194 if Current_Verbosity = High then
3195 Write_Line ("End of looking for source directories.");
3196 end if;
3197 end if;
3198 end;
3200 -- We have a single directory
3202 else
3203 declare
3204 Path_Name : Name_Id;
3205 Display_Path_Name : Name_Id;
3206 begin
3207 Locate_Directory
3208 (From, Data.Display_Directory, Path_Name, Display_Path_Name);
3209 if Path_Name = No_Name then
3210 Err_Vars.Error_Msg_Name_1 := From;
3212 if Location = No_Location then
3213 Error_Msg
3214 (Project,
3215 "{ is not a valid directory",
3216 Data.Location);
3217 else
3218 Error_Msg
3219 (Project,
3220 "{ is not a valid directory",
3221 Location);
3222 end if;
3223 else
3225 -- As it is an existing directory, we add it to
3226 -- the list of directories.
3228 String_Elements.Increment_Last;
3229 Element.Value := Path_Name;
3230 Element.Display_Value := Display_Path_Name;
3232 if Last_Source_Dir = Nil_String then
3234 -- This is the first source directory
3236 Data.Source_Dirs := String_Elements.Last;
3238 else
3239 -- We already have source directories,
3240 -- link the previous last to the new one.
3242 String_Elements.Table (Last_Source_Dir).Next :=
3243 String_Elements.Last;
3244 end if;
3246 -- And register this source directory as the new last
3248 Last_Source_Dir := String_Elements.Last;
3249 String_Elements.Table (Last_Source_Dir) := Element;
3250 end if;
3251 end;
3252 end if;
3253 end Find_Source_Dirs;
3255 -- Start of processing for Language_Independent_Check
3257 begin
3258 if Data.Language_Independent_Checked then
3259 return;
3260 end if;
3262 Data.Language_Independent_Checked := True;
3264 Error_Report := Report_Error;
3266 Recursive_Dirs.Reset;
3268 if Current_Verbosity = High then
3269 Write_Line ("Starting to look for directories");
3270 end if;
3272 -- Check the object directory
3274 declare
3275 Object_Dir : constant Variable_Value :=
3276 Util.Value_Of (Name_Object_Dir, Data.Decl.Attributes);
3278 begin
3279 pragma Assert (Object_Dir.Kind = Single,
3280 "Object_Dir is not a single string");
3282 -- We set the object directory to its default
3284 Data.Object_Directory := Data.Directory;
3285 Data.Display_Object_Dir := Data.Display_Directory;
3287 if Object_Dir.Value /= Empty_String then
3289 Get_Name_String (Object_Dir.Value);
3291 if Name_Len = 0 then
3292 Error_Msg
3293 (Project,
3294 "Object_Dir cannot be empty",
3295 Object_Dir.Location);
3297 else
3298 -- We check that the specified object directory
3299 -- does exist.
3301 Locate_Directory
3302 (Object_Dir.Value, Data.Display_Directory,
3303 Data.Object_Directory, Data.Display_Object_Dir);
3305 if Data.Object_Directory = No_Name then
3306 -- The object directory does not exist, report an error
3307 Err_Vars.Error_Msg_Name_1 := Object_Dir.Value;
3308 Error_Msg
3309 (Project,
3310 "the object directory { cannot be found",
3311 Data.Location);
3313 -- Do not keep a nil Object_Directory. Set it to the
3314 -- specified (relative or absolute) path.
3315 -- This is for the benefit of tools that recover from
3316 -- errors; for example, these tools could create the
3317 -- non existent directory.
3319 Data.Display_Object_Dir := Object_Dir.Value;
3320 Get_Name_String (Object_Dir.Value);
3321 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3322 Data.Object_Directory := Name_Find;
3323 end if;
3324 end if;
3325 end if;
3326 end;
3328 if Current_Verbosity = High then
3329 if Data.Object_Directory = No_Name then
3330 Write_Line ("No object directory");
3331 else
3332 Write_Str ("Object directory: """);
3333 Write_Str (Get_Name_String (Data.Display_Object_Dir));
3334 Write_Line ("""");
3335 end if;
3336 end if;
3338 -- Check the exec directory
3340 declare
3341 Exec_Dir : constant Variable_Value :=
3342 Util.Value_Of (Name_Exec_Dir, Data.Decl.Attributes);
3344 begin
3345 pragma Assert (Exec_Dir.Kind = Single,
3346 "Exec_Dir is not a single string");
3348 -- We set the object directory to its default
3350 Data.Exec_Directory := Data.Object_Directory;
3351 Data.Display_Exec_Dir := Data.Display_Object_Dir;
3353 if Exec_Dir.Value /= Empty_String then
3355 Get_Name_String (Exec_Dir.Value);
3357 if Name_Len = 0 then
3358 Error_Msg
3359 (Project,
3360 "Exec_Dir cannot be empty",
3361 Exec_Dir.Location);
3363 else
3364 -- We check that the specified object directory
3365 -- does exist.
3367 Locate_Directory
3368 (Exec_Dir.Value, Data.Directory,
3369 Data.Exec_Directory, Data.Display_Exec_Dir);
3371 if Data.Exec_Directory = No_Name then
3372 Err_Vars.Error_Msg_Name_1 := Exec_Dir.Value;
3373 Error_Msg
3374 (Project,
3375 "the exec directory { cannot be found",
3376 Data.Location);
3377 end if;
3378 end if;
3379 end if;
3380 end;
3382 if Current_Verbosity = High then
3383 if Data.Exec_Directory = No_Name then
3384 Write_Line ("No exec directory");
3385 else
3386 Write_Str ("Exec directory: """);
3387 Write_Str (Get_Name_String (Data.Display_Exec_Dir));
3388 Write_Line ("""");
3389 end if;
3390 end if;
3392 -- Look for the source directories
3394 declare
3395 Source_Dirs : constant Variable_Value :=
3396 Util.Value_Of
3397 (Name_Source_Dirs, Data.Decl.Attributes);
3399 begin
3400 if Current_Verbosity = High then
3401 Write_Line ("Starting to look for source directories");
3402 end if;
3404 pragma Assert (Source_Dirs.Kind = List,
3405 "Source_Dirs is not a list");
3407 if Source_Dirs.Default then
3409 -- No Source_Dirs specified: the single source directory
3410 -- is the one containing the project file
3412 String_Elements.Increment_Last;
3413 Data.Source_Dirs := String_Elements.Last;
3414 String_Elements.Table (Data.Source_Dirs) :=
3415 (Value => Data.Directory,
3416 Display_Value => Data.Display_Directory,
3417 Location => No_Location,
3418 Flag => False,
3419 Next => Nil_String,
3420 Index => 0);
3422 if Current_Verbosity = High then
3423 Write_Line ("Single source directory:");
3424 Write_Str (" """);
3425 Write_Str (Get_Name_String (Data.Display_Directory));
3426 Write_Line ("""");
3427 end if;
3429 elsif Source_Dirs.Values = Nil_String then
3431 -- If Source_Dirs is an empty string list, this means
3432 -- that this project contains no source. For projects that
3433 -- don't extend other projects, this also means that there is no
3434 -- need for an object directory, if not specified.
3436 if Data.Extends = No_Project
3437 and then Data.Object_Directory = Data.Directory
3438 then
3439 Data.Object_Directory := No_Name;
3440 end if;
3442 Data.Source_Dirs := Nil_String;
3443 Data.Ada_Sources_Present := False;
3444 Data.Other_Sources_Present := False;
3446 else
3447 declare
3448 Source_Dir : String_List_Id := Source_Dirs.Values;
3449 Element : String_Element;
3451 begin
3452 -- We will find the source directories for each
3453 -- element of the list
3455 while Source_Dir /= Nil_String loop
3456 Element := String_Elements.Table (Source_Dir);
3457 Find_Source_Dirs (Element.Value, Element.Location);
3458 Source_Dir := Element.Next;
3459 end loop;
3460 end;
3461 end if;
3463 if Current_Verbosity = High then
3464 Write_Line ("Putting source directories in canonical cases");
3465 end if;
3467 declare
3468 Current : String_List_Id := Data.Source_Dirs;
3469 Element : String_Element;
3471 begin
3472 while Current /= Nil_String loop
3473 Element := String_Elements.Table (Current);
3474 if Element.Value /= No_Name then
3475 Get_Name_String (Element.Value);
3476 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3477 Element.Value := Name_Find;
3478 String_Elements.Table (Current) := Element;
3479 end if;
3481 Current := Element.Next;
3482 end loop;
3483 end;
3484 end;
3486 -- Library attributes
3488 declare
3489 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3491 Lib_Dir : constant Prj.Variable_Value :=
3492 Prj.Util.Value_Of (Snames.Name_Library_Dir, Attributes);
3494 Lib_Name : constant Prj.Variable_Value :=
3495 Prj.Util.Value_Of (Snames.Name_Library_Name, Attributes);
3497 Lib_Version : constant Prj.Variable_Value :=
3498 Prj.Util.Value_Of
3499 (Snames.Name_Library_Version, Attributes);
3501 The_Lib_Kind : constant Prj.Variable_Value :=
3502 Prj.Util.Value_Of
3503 (Snames.Name_Library_Kind, Attributes);
3505 begin
3506 -- Special case of extending project
3508 if Data.Extends /= No_Project then
3509 declare
3510 Extended_Data : constant Project_Data :=
3511 Projects.Table (Data.Extends);
3513 begin
3514 -- If the project extended is a library project, we inherit
3515 -- the library name, if it is not redefined; we check that
3516 -- the library directory is specified; and we reset the
3517 -- library flag for the extended project.
3519 if Extended_Data.Library then
3520 if Lib_Name.Default then
3521 Data.Library_Name := Extended_Data.Library_Name;
3522 end if;
3524 if Lib_Dir.Default then
3525 if not Data.Virtual then
3526 Error_Msg
3527 (Project,
3528 "a project extending a library project must " &
3529 "specify an attribute Library_Dir",
3530 Data.Location);
3531 end if;
3532 end if;
3534 Projects.Table (Data.Extends).Library := False;
3535 end if;
3536 end;
3537 end if;
3539 pragma Assert (Lib_Dir.Kind = Single);
3541 if Lib_Dir.Value = Empty_String then
3543 if Current_Verbosity = High then
3544 Write_Line ("No library directory");
3545 end if;
3547 else
3548 -- Find path name, check that it is a directory
3550 Locate_Directory
3551 (Lib_Dir.Value, Data.Display_Directory,
3552 Data.Library_Dir, Data.Display_Library_Dir);
3554 if Data.Library_Dir = No_Name then
3556 -- Get the absolute name of the library directory that
3557 -- does not exist, to report an error.
3559 declare
3560 Dir_Name : constant String :=
3561 Get_Name_String (Lib_Dir.Value);
3562 begin
3563 if Is_Absolute_Path (Dir_Name) then
3564 Err_Vars.Error_Msg_Name_1 := Lib_Dir.Value;
3566 else
3567 Get_Name_String (Data.Display_Directory);
3569 if Name_Buffer (Name_Len) /= Directory_Separator then
3570 Name_Len := Name_Len + 1;
3571 Name_Buffer (Name_Len) := Directory_Separator;
3572 end if;
3574 Name_Buffer
3575 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3576 Dir_Name;
3577 Name_Len := Name_Len + Dir_Name'Length;
3578 Err_Vars.Error_Msg_Name_1 := Name_Find;
3579 end if;
3581 -- Report the error
3583 Error_Msg
3584 (Project,
3585 "library directory { does not exist",
3586 Lib_Dir.Location);
3587 end;
3589 elsif Data.Library_Dir = Data.Object_Directory then
3590 Error_Msg
3591 (Project,
3592 "library directory cannot be the same " &
3593 "as object directory",
3594 Lib_Dir.Location);
3595 Data.Library_Dir := No_Name;
3596 Data.Display_Library_Dir := No_Name;
3598 else
3599 if Current_Verbosity = High then
3600 Write_Str ("Library directory =""");
3601 Write_Str (Get_Name_String (Data.Display_Library_Dir));
3602 Write_Line ("""");
3603 end if;
3604 end if;
3605 end if;
3607 pragma Assert (Lib_Name.Kind = Single);
3609 if Lib_Name.Value = Empty_String then
3610 if Current_Verbosity = High
3611 and then Data.Library_Name = No_Name
3612 then
3613 Write_Line ("No library name");
3614 end if;
3616 else
3617 -- There is no restriction on the syntax of library names
3619 Data.Library_Name := Lib_Name.Value;
3620 end if;
3622 if Data.Library_Name /= No_Name
3623 and then Current_Verbosity = High
3624 then
3625 Write_Str ("Library name = """);
3626 Write_Str (Get_Name_String (Data.Library_Name));
3627 Write_Line ("""");
3628 end if;
3630 Data.Library :=
3631 Data.Library_Dir /= No_Name
3632 and then
3633 Data.Library_Name /= No_Name;
3635 if Data.Library then
3636 if MLib.Tgt.Support_For_Libraries = MLib.Tgt.None then
3637 Error_Msg
3638 (Project,
3639 "?libraries are not supported on this platform",
3640 Lib_Name.Location);
3641 Data.Library := False;
3643 else
3644 pragma Assert (Lib_Version.Kind = Single);
3646 if Lib_Version.Value = Empty_String then
3647 if Current_Verbosity = High then
3648 Write_Line ("No library version specified");
3649 end if;
3651 else
3652 Data.Lib_Internal_Name := Lib_Version.Value;
3653 end if;
3655 pragma Assert (The_Lib_Kind.Kind = Single);
3657 if The_Lib_Kind.Value = Empty_String then
3658 if Current_Verbosity = High then
3659 Write_Line ("No library kind specified");
3660 end if;
3662 else
3663 Get_Name_String (The_Lib_Kind.Value);
3665 declare
3666 Kind_Name : constant String :=
3667 To_Lower (Name_Buffer (1 .. Name_Len));
3669 OK : Boolean := True;
3671 begin
3672 if Kind_Name = "static" then
3673 Data.Library_Kind := Static;
3675 elsif Kind_Name = "dynamic" then
3676 Data.Library_Kind := Dynamic;
3678 elsif Kind_Name = "relocatable" then
3679 Data.Library_Kind := Relocatable;
3681 else
3682 Error_Msg
3683 (Project,
3684 "illegal value for Library_Kind",
3685 The_Lib_Kind.Location);
3686 OK := False;
3687 end if;
3689 if Current_Verbosity = High and then OK then
3690 Write_Str ("Library kind = ");
3691 Write_Line (Kind_Name);
3692 end if;
3694 if Data.Library_Kind /= Static and then
3695 MLib.Tgt.Support_For_Libraries = MLib.Tgt.Static_Only
3696 then
3697 Error_Msg
3698 (Project,
3699 "only static libraries are supported " &
3700 "on this platform",
3701 The_Lib_Kind.Location);
3702 Data.Library := False;
3703 end if;
3704 end;
3705 end if;
3707 if Data.Library and then Current_Verbosity = High then
3708 Write_Line ("This is a library project file");
3709 end if;
3711 end if;
3712 end if;
3713 end;
3715 if Current_Verbosity = High then
3716 Show_Source_Dirs (Project);
3717 end if;
3719 declare
3720 Naming_Id : constant Package_Id :=
3721 Util.Value_Of (Name_Naming, Data.Decl.Packages);
3723 Naming : Package_Element;
3725 begin
3726 -- If there is a package Naming, we will put in Data.Naming
3727 -- what is in this package Naming.
3729 if Naming_Id /= No_Package then
3730 Naming := Packages.Table (Naming_Id);
3732 if Current_Verbosity = High then
3733 Write_Line ("Checking ""Naming"".");
3734 end if;
3736 -- Check Spec_Suffix
3738 declare
3739 Spec_Suffixs : Array_Element_Id :=
3740 Util.Value_Of
3741 (Name_Spec_Suffix,
3742 Naming.Decl.Arrays);
3743 Suffix : Array_Element_Id;
3744 Element : Array_Element;
3745 Suffix2 : Array_Element_Id;
3747 begin
3748 -- If some suffixs have been specified, we make sure that
3749 -- for each language for which a default suffix has been
3750 -- specified, there is a suffix specified, either the one
3751 -- in the project file or if there were none, the default.
3753 if Spec_Suffixs /= No_Array_Element then
3754 Suffix := Data.Naming.Spec_Suffix;
3756 while Suffix /= No_Array_Element loop
3757 Element := Array_Elements.Table (Suffix);
3758 Suffix2 := Spec_Suffixs;
3760 while Suffix2 /= No_Array_Element loop
3761 exit when Array_Elements.Table (Suffix2).Index =
3762 Element.Index;
3763 Suffix2 := Array_Elements.Table (Suffix2).Next;
3764 end loop;
3766 -- There is a registered default suffix, but no
3767 -- suffix specified in the project file.
3768 -- Add the default to the array.
3770 if Suffix2 = No_Array_Element then
3771 Array_Elements.Increment_Last;
3772 Array_Elements.Table (Array_Elements.Last) :=
3773 (Index => Element.Index,
3774 Src_Index => Element.Src_Index,
3775 Index_Case_Sensitive => False,
3776 Value => Element.Value,
3777 Next => Spec_Suffixs);
3778 Spec_Suffixs := Array_Elements.Last;
3779 end if;
3781 Suffix := Element.Next;
3782 end loop;
3784 -- Put the resulting array as the specification suffixs
3786 Data.Naming.Spec_Suffix := Spec_Suffixs;
3787 end if;
3788 end;
3790 declare
3791 Current : Array_Element_Id := Data.Naming.Spec_Suffix;
3792 Element : Array_Element;
3794 begin
3795 while Current /= No_Array_Element loop
3796 Element := Array_Elements.Table (Current);
3797 Get_Name_String (Element.Value.Value);
3799 if Name_Len = 0 then
3800 Error_Msg
3801 (Project,
3802 "Spec_Suffix cannot be empty",
3803 Element.Value.Location);
3804 end if;
3806 Array_Elements.Table (Current) := Element;
3807 Current := Element.Next;
3808 end loop;
3809 end;
3811 -- Check Body_Suffix
3813 declare
3814 Impl_Suffixs : Array_Element_Id :=
3815 Util.Value_Of
3816 (Name_Body_Suffix,
3817 Naming.Decl.Arrays);
3819 Suffix : Array_Element_Id;
3820 Element : Array_Element;
3821 Suffix2 : Array_Element_Id;
3823 begin
3824 -- If some suffixs have been specified, we make sure that
3825 -- for each language for which a default suffix has been
3826 -- specified, there is a suffix specified, either the one
3827 -- in the project file or if there were noe, the default.
3829 if Impl_Suffixs /= No_Array_Element then
3830 Suffix := Data.Naming.Body_Suffix;
3832 while Suffix /= No_Array_Element loop
3833 Element := Array_Elements.Table (Suffix);
3834 Suffix2 := Impl_Suffixs;
3836 while Suffix2 /= No_Array_Element loop
3837 exit when Array_Elements.Table (Suffix2).Index =
3838 Element.Index;
3839 Suffix2 := Array_Elements.Table (Suffix2).Next;
3840 end loop;
3842 -- There is a registered default suffix, but no
3843 -- suffix specified in the project file.
3844 -- Add the default to the array.
3846 if Suffix2 = No_Array_Element then
3847 Array_Elements.Increment_Last;
3848 Array_Elements.Table (Array_Elements.Last) :=
3849 (Index => Element.Index,
3850 Src_Index => Element.Src_Index,
3851 Index_Case_Sensitive => False,
3852 Value => Element.Value,
3853 Next => Impl_Suffixs);
3854 Impl_Suffixs := Array_Elements.Last;
3855 end if;
3857 Suffix := Element.Next;
3858 end loop;
3860 -- Put the resulting array as the implementation suffixs
3862 Data.Naming.Body_Suffix := Impl_Suffixs;
3863 end if;
3864 end;
3866 declare
3867 Current : Array_Element_Id := Data.Naming.Body_Suffix;
3868 Element : Array_Element;
3870 begin
3871 while Current /= No_Array_Element loop
3872 Element := Array_Elements.Table (Current);
3873 Get_Name_String (Element.Value.Value);
3875 if Name_Len = 0 then
3876 Error_Msg
3877 (Project,
3878 "Body_Suffix cannot be empty",
3879 Element.Value.Location);
3880 end if;
3882 Array_Elements.Table (Current) := Element;
3883 Current := Element.Next;
3884 end loop;
3885 end;
3887 -- Get the exceptions, if any
3889 Data.Naming.Specification_Exceptions :=
3890 Util.Value_Of
3891 (Name_Specification_Exceptions,
3892 In_Arrays => Naming.Decl.Arrays);
3894 Data.Naming.Implementation_Exceptions :=
3895 Util.Value_Of
3896 (Name_Implementation_Exceptions,
3897 In_Arrays => Naming.Decl.Arrays);
3898 end if;
3899 end;
3901 Projects.Table (Project) := Data;
3902 end Language_Independent_Check;
3904 ----------------------
3905 -- Locate_Directory --
3906 ----------------------
3908 procedure Locate_Directory
3909 (Name : Name_Id;
3910 Parent : Name_Id;
3911 Dir : out Name_Id;
3912 Display : out Name_Id)
3914 The_Name : constant String := Get_Name_String (Name);
3915 The_Parent : constant String :=
3916 Get_Name_String (Parent) & Directory_Separator;
3917 The_Parent_Last : constant Natural :=
3918 Compute_Directory_Last (The_Parent);
3920 begin
3921 if Current_Verbosity = High then
3922 Write_Str ("Locate_Directory (""");
3923 Write_Str (The_Name);
3924 Write_Str (""", """);
3925 Write_Str (The_Parent);
3926 Write_Line (""")");
3927 end if;
3929 Dir := No_Name;
3930 Display := No_Name;
3932 if Is_Absolute_Path (The_Name) then
3933 if Is_Directory (The_Name) then
3934 declare
3935 Normed : constant String :=
3936 Normalize_Pathname
3937 (The_Name,
3938 Resolve_Links => False,
3939 Case_Sensitive => True);
3941 Canonical_Path : constant String :=
3942 Normalize_Pathname
3943 (Normed,
3944 Resolve_Links => True,
3945 Case_Sensitive => False);
3947 begin
3948 Name_Len := Normed'Length;
3949 Name_Buffer (1 .. Name_Len) := Normed;
3950 Display := Name_Find;
3952 Name_Len := Canonical_Path'Length;
3953 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3954 Dir := Name_Find;
3955 end;
3956 end if;
3958 else
3959 declare
3960 Full_Path : constant String :=
3961 The_Parent (The_Parent'First .. The_Parent_Last) &
3962 The_Name;
3964 begin
3965 if Is_Directory (Full_Path) then
3966 declare
3967 Normed : constant String :=
3968 Normalize_Pathname
3969 (Full_Path,
3970 Resolve_Links => False,
3971 Case_Sensitive => True);
3973 Canonical_Path : constant String :=
3974 Normalize_Pathname
3975 (Normed,
3976 Resolve_Links => True,
3977 Case_Sensitive => False);
3979 begin
3980 Name_Len := Normed'Length;
3981 Name_Buffer (1 .. Name_Len) := Normed;
3982 Display := Name_Find;
3984 Name_Len := Canonical_Path'Length;
3985 Name_Buffer (1 .. Name_Len) := Canonical_Path;
3986 Dir := Name_Find;
3987 end;
3988 end if;
3989 end;
3990 end if;
3991 end Locate_Directory;
3993 ---------------------------
3994 -- Other_Languages_Check --
3995 ---------------------------
3997 procedure Other_Languages_Check
3998 (Project : Project_Id;
3999 Report_Error : Put_Line_Access) is
4001 Data : Project_Data;
4003 Languages : Variable_Value := Nil_Variable_Value;
4005 begin
4006 Language_Independent_Check (Project, Report_Error);
4008 Error_Report := Report_Error;
4010 Data := Projects.Table (Project);
4011 Languages := Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes);
4013 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4015 if Data.Other_Sources_Present then
4016 -- Check if languages other than Ada are specified in this project
4018 if Languages.Default then
4019 -- Attribute Languages is not specified. So, it defaults to
4020 -- a project of language Ada only.
4022 Data.Languages (Lang_Ada) := True;
4024 -- No sources of languages other than Ada
4026 Data.Other_Sources_Present := False;
4028 else
4029 declare
4030 Current : String_List_Id := Languages.Values;
4031 Element : String_Element;
4032 OK : Boolean := False;
4033 begin
4034 -- Assumethat there is no language other than Ada specified.
4035 -- If in fact there is at least one, we will set back
4036 -- Other_Sources_Present to True.
4038 Data.Other_Sources_Present := False;
4040 -- Look through all the languages specified in attribute
4041 -- Languages, if any
4043 while Current /= Nil_String loop
4044 Element := String_Elements.Table (Current);
4045 Get_Name_String (Element.Value);
4046 To_Lower (Name_Buffer (1 .. Name_Len));
4047 OK := False;
4049 -- Check if it is a known language
4051 Lang_Loop : for Lang in Programming_Language loop
4053 Name_Buffer (1 .. Name_Len) = Lang_Names (Lang).all
4054 then
4055 -- Yes, this is a known language
4057 OK := True;
4059 -- Indicate the presence of this language
4060 Data.Languages (Lang) := True;
4062 -- If it is a language other than Ada, indicate that
4063 -- there should be some sources of a language other
4064 -- than Ada.
4066 if Lang /= Lang_Ada then
4067 Data.Other_Sources_Present := True;
4068 end if;
4070 exit Lang_Loop;
4071 end if;
4072 end loop Lang_Loop;
4074 -- We don't support this language: report an error
4076 if not OK then
4077 Error_Msg_Name_1 := Element.Value;
4078 Error_Msg
4079 (Project,
4080 "unknown programming language {",
4081 Element.Location);
4082 end if;
4084 Current := Element.Next;
4085 end loop;
4086 end;
4087 end if;
4088 end if;
4090 -- If there may be some sources, look for them
4092 if Data.Other_Sources_Present then
4093 -- Set Source_Present to False. It will be set back to True whenever
4094 -- a source is found.
4096 Data.Other_Sources_Present := False;
4098 for Lang in Other_Programming_Language loop
4099 -- For each language (other than Ada) in the project file
4101 if Data.Languages (Lang) then
4102 -- Reset the indication that there are sources of this
4103 -- language. It will be set back to True whenever we find a
4104 -- source of the language.
4106 Data.Languages (Lang) := False;
4108 -- First, get the source suffix for the language
4110 Data.Impl_Suffixes (Lang) := Suffix_For (Lang, Data.Naming);
4112 -- Then, deal with the naming exceptions, if any
4114 Source_Names.Reset;
4116 declare
4117 Naming_Exceptions : constant Variable_Value :=
4118 Value_Of
4119 (Index => Lang_Name_Ids (Lang),
4120 Src_Index => 0,
4121 In_Array => Data.Naming.Implementation_Exceptions);
4122 Element_Id : String_List_Id;
4123 Element : String_Element;
4124 File_Id : Name_Id;
4125 Source_Found : Boolean := False;
4126 begin
4127 -- If there are naming exceptions, look through them one
4128 -- by one.
4130 if Naming_Exceptions /= Nil_Variable_Value then
4131 Element_Id := Naming_Exceptions.Values;
4133 while Element_Id /= Nil_String loop
4134 Element := String_Elements.Table (Element_Id);
4135 Get_Name_String (Element.Value);
4136 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4137 File_Id := Name_Find;
4139 -- Put each naming exception in the Source_Names
4140 -- hash table, but if there are repetition, don't
4141 -- bother after the first instance.
4143 if Source_Names.Get (File_Id) = No_Name_Location then
4144 Source_Found := True;
4145 Source_Names.Set
4146 (File_Id,
4147 (Name => File_Id,
4148 Location => Element.Location,
4149 Found => False));
4150 end if;
4152 Element_Id := Element.Next;
4153 end loop;
4155 -- If there is at least one naming exception, record
4156 -- those that are found in the source directories.
4158 if Source_Found then
4159 Record_Other_Sources
4160 (Project => Project,
4161 Data => Data,
4162 Language => Lang,
4163 Naming_Exceptions => True);
4164 end if;
4166 end if;
4167 end;
4169 -- Now, check if a list of sources is declared either through
4170 -- a string list (attribute Source_Files) or a text file
4171 -- (attribute Source_List_File).
4172 -- If a source list is declared, we will consider only those
4173 -- naming exceptions that are on the list.
4175 declare
4176 Sources : constant Variable_Value :=
4177 Util.Value_Of
4178 (Name_Source_Files,
4179 Data.Decl.Attributes);
4181 Source_List_File : constant Variable_Value :=
4182 Util.Value_Of
4183 (Name_Source_List_File,
4184 Data.Decl.Attributes);
4186 begin
4187 pragma Assert
4188 (Sources.Kind = List,
4189 "Source_Files is not a list");
4191 pragma Assert
4192 (Source_List_File.Kind = Single,
4193 "Source_List_File is not a single string");
4195 if not Sources.Default then
4196 if not Source_List_File.Default then
4197 Error_Msg
4198 (Project,
4199 "?both variables source_files and " &
4200 "source_list_file are present",
4201 Source_List_File.Location);
4202 end if;
4204 -- Sources is a list of file names
4206 declare
4207 Current : String_List_Id := Sources.Values;
4208 Element : String_Element;
4209 Location : Source_Ptr;
4210 Name : Name_Id;
4212 begin
4213 Source_Names.Reset;
4215 -- Put all the sources in the Source_Names hash
4216 -- table.
4218 while Current /= Nil_String loop
4219 Element := String_Elements.Table (Current);
4220 Get_Name_String (Element.Value);
4221 Canonical_Case_File_Name
4222 (Name_Buffer (1 .. Name_Len));
4223 Name := Name_Find;
4225 -- If the element has no location, then use the
4226 -- location of Sources to report possible errors.
4228 if Element.Location = No_Location then
4229 Location := Sources.Location;
4231 else
4232 Location := Element.Location;
4233 end if;
4235 Source_Names.Set
4236 (K => Name,
4237 E =>
4238 (Name => Name,
4239 Location => Location,
4240 Found => False));
4242 Current := Element.Next;
4243 end loop;
4245 -- And look for their directories
4247 Record_Other_Sources
4248 (Project => Project,
4249 Data => Data,
4250 Language => Lang,
4251 Naming_Exceptions => False);
4252 end;
4254 -- No source_files specified.
4255 -- We check if Source_List_File has been specified.
4257 elsif not Source_List_File.Default then
4259 -- Source_List_File is the name of the file
4260 -- that contains the source file names
4262 declare
4263 Source_File_Path_Name : constant String :=
4264 Path_Name_Of
4265 (Source_List_File.Value,
4266 Data.Directory);
4268 begin
4269 if Source_File_Path_Name'Length = 0 then
4270 Err_Vars.Error_Msg_Name_1 := Source_List_File.Value;
4271 Error_Msg
4272 (Project,
4273 "file with sources { does not exist",
4274 Source_List_File.Location);
4276 else
4277 -- Read the file, putting each source in the
4278 -- Source_Names hash table.
4280 Get_Sources_From_File
4281 (Source_File_Path_Name,
4282 Source_List_File.Location,
4283 Project);
4285 -- And look for their directories.
4287 Record_Other_Sources
4288 (Project => Project,
4289 Data => Data,
4290 Language => Lang,
4291 Naming_Exceptions => False);
4292 end if;
4293 end;
4295 else
4296 -- Neither Source_Files nor Source_List_File has been
4297 -- specified. Find all the files that satisfy
4298 -- the naming scheme in all the source directories.
4299 -- All the naming exceptions that effectively exist are
4300 -- also part of the source of this language.
4302 Find_Sources (Project, Data, Lang);
4303 end if;
4305 end;
4306 end if;
4307 end loop;
4308 end if;
4310 -- Finally, get the mains, if any
4312 Get_Mains (Project, Data);
4314 Projects.Table (Project) := Data;
4316 end Other_Languages_Check;
4318 ------------------
4319 -- Path_Name_Of --
4320 ------------------
4322 function Path_Name_Of
4323 (File_Name : Name_Id;
4324 Directory : Name_Id) return String
4326 Result : String_Access;
4327 The_Directory : constant String := Get_Name_String (Directory);
4329 begin
4330 Get_Name_String (File_Name);
4331 Result := Locate_Regular_File
4332 (File_Name => Name_Buffer (1 .. Name_Len),
4333 Path => The_Directory);
4335 if Result = null then
4336 return "";
4337 else
4338 Canonical_Case_File_Name (Result.all);
4339 return Result.all;
4340 end if;
4341 end Path_Name_Of;
4343 -------------------------------
4344 -- Prepare_Ada_Naming_Exceptions --
4345 -------------------------------
4347 procedure Prepare_Ada_Naming_Exceptions
4348 (List : Array_Element_Id;
4349 Kind : Spec_Or_Body)
4351 Current : Array_Element_Id := List;
4352 Element : Array_Element;
4354 Unit : Unit_Info;
4356 begin
4357 -- Traverse the list
4359 while Current /= No_Array_Element loop
4360 Element := Array_Elements.Table (Current);
4362 if Element.Index /= No_Name then
4363 Unit :=
4364 (Kind => Kind,
4365 Unit => Element.Index,
4366 Next => No_Ada_Naming_Exception);
4367 Reverse_Ada_Naming_Exceptions.Set
4368 (Unit, (Element.Value.Value, Element.Value.Index));
4369 Unit.Next := Ada_Naming_Exceptions.Get (Element.Value.Value);
4370 Ada_Naming_Exception_Table.Increment_Last;
4371 Ada_Naming_Exception_Table.Table
4372 (Ada_Naming_Exception_Table.Last) := Unit;
4373 Ada_Naming_Exceptions.Set
4374 (Element.Value.Value, Ada_Naming_Exception_Table.Last);
4375 end if;
4377 Current := Element.Next;
4378 end loop;
4379 end Prepare_Ada_Naming_Exceptions;
4381 ---------------------
4382 -- Project_Extends --
4383 ---------------------
4385 function Project_Extends
4386 (Extending : Project_Id;
4387 Extended : Project_Id) return Boolean
4389 Current : Project_Id := Extending;
4390 begin
4391 loop
4392 if Current = No_Project then
4393 return False;
4395 elsif Current = Extended then
4396 return True;
4397 end if;
4399 Current := Projects.Table (Current).Extends;
4400 end loop;
4401 end Project_Extends;
4403 -----------------------
4404 -- Record_Ada_Source --
4405 -----------------------
4407 procedure Record_Ada_Source
4408 (File_Name : Name_Id;
4409 Path_Name : Name_Id;
4410 Project : Project_Id;
4411 Data : in out Project_Data;
4412 Location : Source_Ptr;
4413 Current_Source : in out String_List_Id;
4414 Source_Recorded : in out Boolean;
4415 Follow_Links : Boolean)
4417 Canonical_File_Name : Name_Id;
4418 Canonical_Path_Name : Name_Id;
4419 Exception_Id : Ada_Naming_Exception_Id;
4420 Unit_Name : Name_Id;
4421 Unit_Kind : Spec_Or_Body;
4422 Unit_Index : Int := 0;
4423 Info : Unit_Info;
4424 Name_Index : Name_And_Index;
4425 Needs_Pragma : Boolean;
4427 The_Location : Source_Ptr := Location;
4428 Previous_Source : constant String_List_Id := Current_Source;
4429 Except_Name : Name_And_Index := No_Name_And_Index;
4431 Unit_Prj : Unit_Project;
4433 File_Name_Recorded : Boolean := False;
4435 begin
4436 Get_Name_String (File_Name);
4437 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4438 Canonical_File_Name := Name_Find;
4440 declare
4441 Canonical_Path : constant String :=
4442 Normalize_Pathname
4443 (Get_Name_String (Path_Name),
4444 Resolve_Links => Follow_Links,
4445 Case_Sensitive => False);
4446 begin
4447 Name_Len := 0;
4448 Add_Str_To_Name_Buffer (Canonical_Path);
4449 Canonical_Path_Name := Name_Find;
4450 end;
4452 -- Find out the unit name, the unit kind and if it needs
4453 -- a specific SFN pragma.
4455 Get_Unit
4456 (Canonical_File_Name => Canonical_File_Name,
4457 Naming => Data.Naming,
4458 Exception_Id => Exception_Id,
4459 Unit_Name => Unit_Name,
4460 Unit_Kind => Unit_Kind,
4461 Needs_Pragma => Needs_Pragma);
4463 if Exception_Id = No_Ada_Naming_Exception and then
4464 Unit_Name = No_Name
4465 then
4466 if Current_Verbosity = High then
4467 Write_Str (" """);
4468 Write_Str (Get_Name_String (Canonical_File_Name));
4469 Write_Line (""" is not a valid source file name (ignored).");
4470 end if;
4472 else
4474 -- Check to see if the source has been hidden by an exception,
4475 -- but only if it is not an exception.
4477 if not Needs_Pragma then
4478 Except_Name :=
4479 Reverse_Ada_Naming_Exceptions.Get
4480 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
4482 if Except_Name /= No_Name_And_Index then
4483 if Current_Verbosity = High then
4484 Write_Str (" """);
4485 Write_Str (Get_Name_String (Canonical_File_Name));
4486 Write_Str (""" contains a unit that is found in """);
4487 Write_Str (Get_Name_String (Except_Name.Name));
4488 Write_Line (""" (ignored).");
4489 end if;
4491 -- The file is not included in the source of the project,
4492 -- because it is hidden by the exception.
4493 -- So, there is nothing else to do.
4495 return;
4496 end if;
4497 end if;
4499 loop
4500 if Exception_Id /= No_Ada_Naming_Exception then
4501 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
4502 Exception_Id := Info.Next;
4503 Info.Next := No_Ada_Naming_Exception;
4504 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
4506 Unit_Name := Info.Unit;
4507 Unit_Index := Name_Index.Index;
4508 Unit_Kind := Info.Kind;
4509 end if;
4510 -- Put the file name in the list of sources of the project
4512 if not File_Name_Recorded then
4513 String_Elements.Increment_Last;
4514 String_Elements.Table (String_Elements.Last) :=
4515 (Value => Canonical_File_Name,
4516 Display_Value => File_Name,
4517 Location => No_Location,
4518 Flag => False,
4519 Next => Nil_String,
4520 Index => Unit_Index);
4521 end if;
4523 if Current_Source = Nil_String then
4524 Data.Sources := String_Elements.Last;
4526 else
4527 String_Elements.Table (Current_Source).Next :=
4528 String_Elements.Last;
4529 end if;
4531 Current_Source := String_Elements.Last;
4533 -- Put the unit in unit list
4535 declare
4536 The_Unit : Unit_Id := Units_Htable.Get (Unit_Name);
4537 The_Unit_Data : Unit_Data;
4539 begin
4540 if Current_Verbosity = High then
4541 Write_Str ("Putting ");
4542 Write_Str (Get_Name_String (Unit_Name));
4543 Write_Line (" in the unit list.");
4544 end if;
4546 -- The unit is already in the list, but may be it is
4547 -- only the other unit kind (spec or body), or what is
4548 -- in the unit list is a unit of a project we are extending.
4550 if The_Unit /= Prj.Com.No_Unit then
4551 The_Unit_Data := Units.Table (The_Unit);
4553 if The_Unit_Data.File_Names (Unit_Kind).Name = No_Name
4554 or else Project_Extends
4555 (Data.Extends,
4556 The_Unit_Data.File_Names (Unit_Kind).Project)
4557 then
4558 if The_Unit_Data.File_Names (Unit_Kind).Path = Slash then
4559 Remove_Forbidden_File_Name
4560 (The_Unit_Data.File_Names (Unit_Kind).Name);
4561 end if;
4563 -- Record the file name in the hash table Files_Htable
4565 Unit_Prj := (Unit => The_Unit, Project => Project);
4566 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4568 The_Unit_Data.File_Names (Unit_Kind) :=
4569 (Name => Canonical_File_Name,
4570 Index => Unit_Index,
4571 Display_Name => File_Name,
4572 Path => Canonical_Path_Name,
4573 Display_Path => Path_Name,
4574 Project => Project,
4575 Needs_Pragma => Needs_Pragma);
4576 Units.Table (The_Unit) := The_Unit_Data;
4577 Source_Recorded := True;
4579 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
4580 and then (Data.Known_Order_Of_Source_Dirs or else
4581 The_Unit_Data.File_Names (Unit_Kind).Path =
4582 Canonical_Path_Name)
4583 then
4584 if Previous_Source = Nil_String then
4585 Data.Sources := Nil_String;
4586 else
4587 String_Elements.Table (Previous_Source).Next :=
4588 Nil_String;
4589 String_Elements.Decrement_Last;
4590 end if;
4592 Current_Source := Previous_Source;
4594 else
4595 -- It is an error to have two units with the same name
4596 -- and the same kind (spec or body).
4598 if The_Location = No_Location then
4599 The_Location := Projects.Table (Project).Location;
4600 end if;
4602 Err_Vars.Error_Msg_Name_1 := Unit_Name;
4603 Error_Msg (Project, "duplicate source {", The_Location);
4605 Err_Vars.Error_Msg_Name_1 :=
4606 Projects.Table
4607 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
4608 Err_Vars.Error_Msg_Name_2 :=
4609 The_Unit_Data.File_Names (Unit_Kind).Path;
4610 Error_Msg
4611 (Project, "\ project file {, {", The_Location);
4613 Err_Vars.Error_Msg_Name_1 :=
4614 Projects.Table (Project).Name;
4615 Err_Vars.Error_Msg_Name_2 := Canonical_Path_Name;
4616 Error_Msg
4617 (Project, "\ project file {, {", The_Location);
4619 end if;
4621 -- It is a new unit, create a new record
4623 else
4624 -- First, check if there is no other unit with this file
4625 -- name in another project. If it is, report an error.
4626 -- Of course, we do that only for the first unit in the
4627 -- source file.
4629 Unit_Prj := Files_Htable.Get (Canonical_File_Name);
4631 if not File_Name_Recorded and then
4632 Unit_Prj /= No_Unit_Project
4633 then
4634 Error_Msg_Name_1 := File_Name;
4635 Error_Msg_Name_2 :=
4636 Projects.Table (Unit_Prj.Project).Name;
4637 Error_Msg
4638 (Project,
4639 "{ is already a source of project {",
4640 Location);
4642 else
4643 Units.Increment_Last;
4644 The_Unit := Units.Last;
4645 Units_Htable.Set (Unit_Name, The_Unit);
4646 Unit_Prj := (Unit => The_Unit, Project => Project);
4647 Files_Htable.Set (Canonical_File_Name, Unit_Prj);
4648 The_Unit_Data.Name := Unit_Name;
4649 The_Unit_Data.File_Names (Unit_Kind) :=
4650 (Name => Canonical_File_Name,
4651 Index => Unit_Index,
4652 Display_Name => File_Name,
4653 Path => Canonical_Path_Name,
4654 Display_Path => Path_Name,
4655 Project => Project,
4656 Needs_Pragma => Needs_Pragma);
4657 Units.Table (The_Unit) := The_Unit_Data;
4658 Source_Recorded := True;
4659 end if;
4660 end if;
4661 end;
4663 exit when Exception_Id = No_Ada_Naming_Exception;
4664 File_Name_Recorded := True;
4665 end loop;
4666 end if;
4667 end Record_Ada_Source;
4669 --------------------------
4670 -- Record_Other_Sources --
4671 --------------------------
4673 procedure Record_Other_Sources
4674 (Project : Project_Id;
4675 Data : in out Project_Data;
4676 Language : Programming_Language;
4677 Naming_Exceptions : Boolean)
4679 Source_Dir : String_List_Id := Data.Source_Dirs;
4680 Element : String_Element;
4681 Path : Name_Id;
4683 Dir : Dir_Type;
4684 Canonical_Name : Name_Id;
4685 Name_Str : String (1 .. 1_024);
4686 Last : Natural := 0;
4687 NL : Name_Location;
4689 First_Error : Boolean := True;
4691 Suffix : constant String :=
4692 Get_Name_String (Data.Impl_Suffixes (Language));
4694 begin
4695 while Source_Dir /= Nil_String loop
4696 Element := String_Elements.Table (Source_Dir);
4698 declare
4699 Dir_Path : constant String := Get_Name_String (Element.Value);
4700 begin
4701 if Current_Verbosity = High then
4702 Write_Str ("checking directory """);
4703 Write_Str (Dir_Path);
4704 Write_Str (""" for ");
4706 if Naming_Exceptions then
4707 Write_Str ("naming exceptions");
4709 else
4710 Write_Str ("sources");
4711 end if;
4713 Write_Str (" of Language ");
4714 Write_Line (Lang_Display_Names (Language).all);
4715 end if;
4717 Open (Dir, Dir_Path);
4719 loop
4720 Read (Dir, Name_Str, Last);
4721 exit when Last = 0;
4723 if Is_Regular_File
4724 (Dir_Path & Directory_Separator & Name_Str (1 .. Last))
4725 then
4726 Name_Len := Last;
4727 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
4728 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4729 Canonical_Name := Name_Find;
4730 NL := Source_Names.Get (Canonical_Name);
4732 if NL /= No_Name_Location then
4733 if NL.Found then
4734 if not Data.Known_Order_Of_Source_Dirs then
4735 Error_Msg_Name_1 := Canonical_Name;
4736 Error_Msg
4737 (Project,
4738 "{ is found in several source directories",
4739 NL.Location);
4740 end if;
4742 else
4743 NL.Found := True;
4744 Source_Names.Set (Canonical_Name, NL);
4745 Name_Len := Dir_Path'Length;
4746 Name_Buffer (1 .. Name_Len) := Dir_Path;
4747 Add_Char_To_Name_Buffer (Directory_Separator);
4748 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
4749 Path := Name_Find;
4751 Check_For_Source
4752 (File_Name => Canonical_Name,
4753 Path_Name => Path,
4754 Project => Project,
4755 Data => Data,
4756 Location => NL.Location,
4757 Language => Language,
4758 Suffix => Suffix,
4759 Naming_Exception => Naming_Exceptions);
4760 end if;
4761 end if;
4762 end if;
4763 end loop;
4765 Close (Dir);
4766 end;
4768 Source_Dir := Element.Next;
4769 end loop;
4771 if not Naming_Exceptions then
4773 NL := Source_Names.Get_First;
4775 -- It is an error if a source file name in a source list or
4776 -- in a source list file is not found.
4778 while NL /= No_Name_Location loop
4779 if not NL.Found then
4780 Err_Vars.Error_Msg_Name_1 := NL.Name;
4782 if First_Error then
4783 Error_Msg
4784 (Project,
4785 "source file { cannot be found",
4786 NL.Location);
4787 First_Error := False;
4789 else
4790 Error_Msg
4791 (Project,
4792 "\source file { cannot be found",
4793 NL.Location);
4794 end if;
4795 end if;
4797 NL := Source_Names.Get_Next;
4798 end loop;
4800 -- Any naming exception of this language that is not in a list
4801 -- of sources must be removed.
4803 declare
4804 Source_Id : Other_Source_Id := Data.First_Other_Source;
4805 Prev_Id : Other_Source_Id := No_Other_Source;
4806 Source : Other_Source;
4807 begin
4808 while Source_Id /= No_Other_Source loop
4809 Source := Other_Sources.Table (Source_Id);
4811 if Source.Language = Language
4812 and then Source.Naming_Exception
4813 then
4814 if Current_Verbosity = High then
4815 Write_Str ("Naming exception """);
4816 Write_Str (Get_Name_String (Source.File_Name));
4817 Write_Str (""" is not in the list of sources,");
4818 Write_Line (" so it is removed.");
4819 end if;
4821 if Prev_Id = No_Other_Source then
4822 Data.First_Other_Source := Source.Next;
4824 else
4825 Other_Sources.Table (Prev_Id).Next := Source.Next;
4826 end if;
4828 Source_Id := Source.Next;
4830 if Source_Id = No_Other_Source then
4831 Data.Last_Other_Source := Prev_Id;
4832 end if;
4834 else
4835 Prev_Id := Source_Id;
4836 Source_Id := Source.Next;
4837 end if;
4838 end loop;
4839 end;
4840 end if;
4841 end Record_Other_Sources;
4843 ----------------------
4844 -- Show_Source_Dirs --
4845 ----------------------
4847 procedure Show_Source_Dirs (Project : Project_Id) is
4848 Current : String_List_Id := Projects.Table (Project).Source_Dirs;
4849 Element : String_Element;
4851 begin
4852 Write_Line ("Source_Dirs:");
4854 while Current /= Nil_String loop
4855 Element := String_Elements.Table (Current);
4856 Write_Str (" ");
4857 Write_Line (Get_Name_String (Element.Value));
4858 Current := Element.Next;
4859 end loop;
4861 Write_Line ("end Source_Dirs.");
4862 end Show_Source_Dirs;
4864 ----------------
4865 -- Suffix_For --
4866 ----------------
4868 function Suffix_For
4869 (Language : Programming_Language;
4870 Naming : Naming_Data) return Name_Id
4872 Suffix : constant Variable_Value :=
4873 Value_Of
4874 (Index => Lang_Name_Ids (Language),
4875 Src_Index => 0,
4876 In_Array => Naming.Body_Suffix);
4877 begin
4878 -- If no suffix for this language is found in package Naming, use the
4879 -- default.
4881 if Suffix = Nil_Variable_Value then
4882 Name_Len := 0;
4883 Add_Str_To_Name_Buffer (Lang_Suffixes (Language).all);
4885 -- Otherwise use the one specified
4887 else
4888 Get_Name_String (Suffix.Value);
4889 end if;
4891 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
4892 return Name_Find;
4893 end Suffix_For;
4895 end Prj.Nmsc;