1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with GNAT.Case_Util; use GNAT.Case_Util;
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
30 with Err_Vars; use Err_Vars;
35 with Osint; use Osint;
36 with Output; use Output;
37 with Prj.Env; use Prj.Env;
39 with Prj.Util; use Prj.Util;
41 with Snames; use Snames;
42 with Table; use Table;
43 with Targparm; use Targparm;
45 with Ada.Characters.Handling; use Ada.Characters.Handling;
46 with Ada.Directories; use Ada.Directories;
47 with Ada.Strings; use Ada.Strings;
48 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
49 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
51 package body Prj.Nmsc is
53 No_Continuation_String : aliased String := "";
54 Continuation_String : aliased String := "\";
55 -- Used in Check_Library for continuation error messages at the same
58 Error_Report : Put_Line_Access := null;
59 -- Set to point to error reporting procedure
61 When_No_Sources : Error_Warning := Error;
62 -- Indicates what should be done when there is no Ada sources in a non
63 -- extending Ada project.
65 ALI_Suffix : constant String := ".ali";
66 -- File suffix for ali files
68 type Name_Location is record
69 Name : File_Name_Type;
70 Location : Source_Ptr;
71 Source : Source_Id := No_Source;
72 Except : Boolean := False;
73 Found : Boolean := False;
75 -- Information about file names found in string list attribute
76 -- Source_Files or in a source list file, stored in hash table
77 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
79 No_Name_Location : constant Name_Location :=
81 Location => No_Location,
86 package Source_Names is new GNAT.HTable.Simple_HTable
87 (Header_Num => Header_Num,
88 Element => Name_Location,
89 No_Element => No_Name_Location,
90 Key => File_Name_Type,
93 -- Hash table to store file names found in string list attribute
94 -- Source_Files or in a source list file, stored in hash table
95 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
97 -- More documentation needed on what unit exceptions are about ???
99 type Unit_Exception is record
101 Spec : File_Name_Type;
102 Impl : File_Name_Type;
105 No_Unit_Exception : constant Unit_Exception :=
110 package Unit_Exceptions is new GNAT.HTable.Simple_HTable
111 (Header_Num => Header_Num,
112 Element => Unit_Exception,
113 No_Element => No_Unit_Exception,
117 -- Hash table to store the unit exceptions
119 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
120 (Header_Num => Header_Num,
126 -- Hash table to store recursive source directories, to avoid looking
127 -- several times, and to avoid cycles that may be introduced by symbolic
130 type Ada_Naming_Exception_Id is new Nat;
131 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
133 type Unit_Info is record
136 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
140 -- Why is the following commented out ???
141 -- No_Unit : constant Unit_Info :=
142 -- (Specification, No_Name, No_Ada_Naming_Exception);
144 package Ada_Naming_Exception_Table is new Table.Table
145 (Table_Component_Type => Unit_Info,
146 Table_Index_Type => Ada_Naming_Exception_Id,
147 Table_Low_Bound => 1,
149 Table_Increment => 100,
150 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
152 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
153 (Header_Num => Header_Num,
154 Element => Ada_Naming_Exception_Id,
155 No_Element => No_Ada_Naming_Exception,
156 Key => File_Name_Type,
159 -- A hash table to store naming exceptions for Ada. For each file name
160 -- there is one or several unit in table Ada_Naming_Exception_Table.
162 package Object_File_Names is new GNAT.HTable.Simple_HTable
163 (Header_Num => Header_Num,
164 Element => File_Name_Type,
165 No_Element => No_File,
166 Key => File_Name_Type,
169 -- A hash table to store the object file names for a project, to check that
170 -- two different sources have different object file names.
172 type File_Found is record
173 File : File_Name_Type := No_File;
174 Found : Boolean := False;
175 Location : Source_Ptr := No_Location;
177 No_File_Found : constant File_Found := (No_File, False, No_Location);
178 -- Comments needed ???
180 package Excluded_Sources_Htable is new GNAT.HTable.Simple_HTable
181 (Header_Num => Header_Num,
182 Element => File_Found,
183 No_Element => No_File_Found,
184 Key => File_Name_Type,
187 -- A hash table to store the excluded files, if any. This is filled by
188 -- Find_Excluded_Sources below.
190 procedure Find_Excluded_Sources
191 (Project : Project_Id;
192 In_Tree : Project_Tree_Ref;
193 Data : Project_Data);
194 -- Find the list of files that should not be considered as source files
195 -- for this project. Sets the list in the Excluded_Sources_Htable.
197 function Hash (Unit : Unit_Info) return Header_Num;
199 type Name_And_Index is record
200 Name : Name_Id := No_Name;
203 No_Name_And_Index : constant Name_And_Index :=
204 (Name => No_Name, Index => 0);
206 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
207 (Header_Num => Header_Num,
208 Element => Name_And_Index,
209 No_Element => No_Name_And_Index,
213 -- A table to check if a unit with an exceptional name will hide a source
214 -- with a file name following the naming convention.
218 Data : in out Project_Data;
219 In_Tree : Project_Tree_Ref;
220 Project : Project_Id;
222 Lang_Id : Language_Index;
224 File_Name : File_Name_Type;
225 Display_File : File_Name_Type;
226 Lang_Kind : Language_Kind;
227 Naming_Exception : Boolean := False;
228 Path : Path_Name_Type := No_Path;
229 Display_Path : Path_Name_Type := No_Path;
230 Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
231 Other_Part : Source_Id := No_Source;
232 Unit : Name_Id := No_Name;
234 Source_To_Replace : Source_Id := No_Source);
235 -- Add a new source to the different lists: list of all sources in the
236 -- project tree, list of source of a project and list of sources of a
239 -- If Path is specified, the file is also added to Source_Paths_HT.
240 -- If Source_To_Replace is specified, it points to the source in the
241 -- extended project that the new file is overriding.
243 function ALI_File_Name (Source : String) return String;
244 -- Return the ALI file name corresponding to a source
246 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
247 -- Check that a name is a valid Ada unit name
249 procedure Check_Naming_Schemes
250 (Data : in out Project_Data;
251 Project : Project_Id;
252 In_Tree : Project_Tree_Ref);
253 -- Check the naming scheme part of Data
255 procedure Check_Ada_Naming_Scheme_Validity
256 (Project : Project_Id;
257 In_Tree : Project_Tree_Ref;
258 Naming : Naming_Data);
259 -- Check that the package Naming is correct
261 procedure Check_Configuration
262 (Project : Project_Id;
263 In_Tree : Project_Tree_Ref;
264 Data : in out Project_Data);
265 -- Check the configuration attributes for the project
267 procedure Check_If_Externally_Built
268 (Project : Project_Id;
269 In_Tree : Project_Tree_Ref;
270 Data : in out Project_Data);
271 -- Check attribute Externally_Built of project Project in project tree
272 -- In_Tree and modify its data Data if it has the value "true".
274 procedure Check_Interfaces
275 (Project : Project_Id;
276 In_Tree : Project_Tree_Ref;
277 Data : in out Project_Data);
278 -- If a list of sources is specified in attribute Interfaces, set
279 -- In_Interfaces only for the sources specified in the list.
281 procedure Check_Library_Attributes
282 (Project : Project_Id;
283 In_Tree : Project_Tree_Ref;
284 Current_Dir : String;
285 Data : in out Project_Data);
286 -- Check the library attributes of project Project in project tree In_Tree
287 -- and modify its data Data accordingly.
288 -- Current_Dir should represent the current directory, and is passed for
289 -- efficiency to avoid system calls to recompute it.
291 procedure Check_Package_Naming
292 (Project : Project_Id;
293 In_Tree : Project_Tree_Ref;
294 Data : in out Project_Data);
295 -- Check package Naming of project Project in project tree In_Tree and
296 -- modify its data Data accordingly.
298 procedure Check_Programming_Languages
299 (In_Tree : Project_Tree_Ref;
300 Project : Project_Id;
301 Data : in out Project_Data);
302 -- Check attribute Languages for the project with data Data in project
303 -- tree In_Tree and set the components of Data for all the programming
304 -- languages indicated in attribute Languages, if any.
306 function Check_Project
308 Root_Project : Project_Id;
309 In_Tree : Project_Tree_Ref;
310 Extending : Boolean) return Boolean;
311 -- Returns True if P is Root_Project or, if Extending is True, a project
312 -- extended by Root_Project.
314 procedure Check_Stand_Alone_Library
315 (Project : Project_Id;
316 In_Tree : Project_Tree_Ref;
317 Data : in out Project_Data;
318 Current_Dir : String;
319 Extending : Boolean);
320 -- Check if project Project in project tree In_Tree is a Stand-Alone
321 -- Library project, and modify its data Data accordingly if it is one.
322 -- Current_Dir should represent the current directory, and is passed for
323 -- efficiency to avoid system calls to recompute it.
325 procedure Get_Path_Names_And_Record_Ada_Sources
326 (Project : Project_Id;
327 In_Tree : Project_Tree_Ref;
328 Data : in out Project_Data;
329 Current_Dir : String);
330 -- Find the path names of the source files in the Source_Names table
331 -- in the source directories and record those that are Ada sources.
333 function Compute_Directory_Last (Dir : String) return Natural;
334 -- Return the index of the last significant character in Dir. This is used
335 -- to avoid duplicate '/' (slash) characters at the end of directory names.
338 (Project : Project_Id;
339 In_Tree : Project_Tree_Ref;
341 Flag_Location : Source_Ptr);
342 -- Output an error message. If Error_Report is null, simply call
343 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
346 procedure Find_Ada_Sources
347 (Project : Project_Id;
348 In_Tree : Project_Tree_Ref;
349 Data : in out Project_Data;
350 Current_Dir : String);
351 -- Find all the Ada sources in all of the source directories of a project
352 -- Current_Dir should represent the current directory, and is passed for
353 -- efficiency to avoid system calls to recompute it.
355 procedure Search_Directories
356 (Project : Project_Id;
357 In_Tree : Project_Tree_Ref;
358 Data : in out Project_Data;
359 For_All_Sources : Boolean);
360 -- Search the source directories to find the sources.
361 -- If For_All_Sources is True, check each regular file name against the
362 -- naming schemes of the different languages. Otherwise consider only the
363 -- file names in the hash table Source_Names.
366 (Project : Project_Id;
367 In_Tree : Project_Tree_Ref;
368 Data : in out Project_Data;
370 File_Name : File_Name_Type;
371 Display_File_Name : File_Name_Type;
372 Source_Directory : String;
373 For_All_Sources : Boolean);
374 -- Check if file File_Name is a valid source of the project. This is used
375 -- in multi-language mode only.
376 -- When the file matches one of the naming schemes, it is added to
377 -- various htables through Add_Source and to Source_Paths_Htable.
379 -- Name is the name of the candidate file. It hasn't been normalized yet
380 -- and is the direct result of readdir().
382 -- File_Name is the same as Name, but has been normalized.
383 -- Display_File_Name, however, has not been normalized.
385 -- Source_Directory is the directory in which the file
386 -- was found. It hasn't been normalized (nor has had links resolved).
387 -- It should not end with a directory separator, to avoid duplicates
390 -- If For_All_Sources is True, then all possible file names are analyzed
391 -- otherwise only those currently set in the Source_Names htable.
393 procedure Check_Naming_Schemes
394 (In_Tree : Project_Tree_Ref;
395 Data : in out Project_Data;
397 File_Name : File_Name_Type;
398 Alternate_Languages : out Alternate_Language_Id;
399 Language : out Language_Index;
400 Language_Name : out Name_Id;
401 Display_Language_Name : out Name_Id;
403 Lang_Kind : out Language_Kind;
404 Kind : out Source_Kind);
405 -- Check if the file name File_Name conforms to one of the naming
406 -- schemes of the project.
408 -- If the file does not match one of the naming schemes, set Language
409 -- to No_Language_Index.
411 -- Filename is the name of the file being investigated. It has been
412 -- normalized (case-folded). File_Name is the same value.
414 procedure Free_Ada_Naming_Exceptions;
415 -- Free the internal hash tables used for checking naming exceptions
417 procedure Get_Directories
418 (Project : Project_Id;
419 In_Tree : Project_Tree_Ref;
420 Current_Dir : String;
421 Data : in out Project_Data);
422 -- Get the object directory, the exec directory and the source directories
425 -- Current_Dir should represent the current directory, and is passed for
426 -- efficiency to avoid system calls to recompute it.
429 (Project : Project_Id;
430 In_Tree : Project_Tree_Ref;
431 Data : in out Project_Data);
432 -- Get the mains of a project from attribute Main, if it exists, and put
433 -- them in the project data.
435 procedure Get_Sources_From_File
437 Location : Source_Ptr;
438 Project : Project_Id;
439 In_Tree : Project_Tree_Ref);
440 -- Get the list of sources from a text file and put them in hash table
443 procedure Find_Explicit_Sources
444 (Current_Dir : String;
445 Project : Project_Id;
446 In_Tree : Project_Tree_Ref;
447 Data : in out Project_Data);
448 -- Process the Source_Files and Source_List_File attributes, and store
449 -- the list of source files into the Source_Names htable.
451 -- Lang indicates which language is being processed when in Ada_Only mode
452 -- (all languages are processed anyway when in Multi_Language mode).
455 (In_Tree : Project_Tree_Ref;
456 Canonical_File_Name : File_Name_Type;
457 Naming : Naming_Data;
458 Exception_Id : out Ada_Naming_Exception_Id;
459 Unit_Name : out Name_Id;
460 Unit_Kind : out Spec_Or_Body;
461 Needs_Pragma : out Boolean);
462 -- Find out, from a file name, the unit name, the unit kind and if a
463 -- specific SFN pragma is needed. If the file name corresponds to no unit,
464 -- then Unit_Name will be No_Name. If the file is a multi-unit source or an
465 -- exception to the naming scheme, then Exception_Id is set to the unit or
466 -- units that the source contains.
468 function Is_Illegal_Suffix
470 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean;
471 -- Returns True if the string Suffix cannot be used as a spec suffix, a
472 -- body suffix or a separate suffix.
474 procedure Locate_Directory
475 (Project : Project_Id;
476 In_Tree : Project_Tree_Ref;
477 Name : File_Name_Type;
478 Parent : Path_Name_Type;
479 Dir : out Path_Name_Type;
480 Display : out Path_Name_Type;
481 Create : String := "";
482 Current_Dir : String;
483 Location : Source_Ptr := No_Location);
484 -- Locate a directory. Name is the directory name. Parent is the root
485 -- directory, if Name a relative path name. Dir is set to the canonical
486 -- case path name of the directory, and Display is the directory path name
487 -- for display purposes. If the directory does not exist and Project_Setup
488 -- is True and Create is a non null string, an attempt is made to create
489 -- the directory. If the directory does not exist and Project_Setup is
490 -- false, then Dir and Display are set to No_Name.
492 -- Current_Dir should represent the current directory, and is passed for
493 -- efficiency to avoid system calls to recompute it.
495 procedure Look_For_Sources
496 (Project : Project_Id;
497 In_Tree : Project_Tree_Ref;
498 Data : in out Project_Data;
499 Current_Dir : String);
500 -- Find all the sources of project Project in project tree In_Tree and
501 -- update its Data accordingly.
503 -- Current_Dir should represent the current directory, and is passed for
504 -- efficiency to avoid system calls to recompute it.
506 function Path_Name_Of
507 (File_Name : File_Name_Type;
508 Directory : Path_Name_Type) return String;
509 -- Returns the path name of a (non project) file. Returns an empty string
510 -- if file cannot be found.
512 procedure Prepare_Ada_Naming_Exceptions
513 (List : Array_Element_Id;
514 In_Tree : Project_Tree_Ref;
515 Kind : Spec_Or_Body);
516 -- Prepare the internal hash tables used for checking naming exceptions
517 -- for Ada. Insert all elements of List in the tables.
519 function Project_Extends
520 (Extending : Project_Id;
521 Extended : Project_Id;
522 In_Tree : Project_Tree_Ref) return Boolean;
523 -- Returns True if Extending is extending Extended either directly or
526 procedure Record_Ada_Source
527 (File_Name : File_Name_Type;
528 Path_Name : Path_Name_Type;
529 Project : Project_Id;
530 In_Tree : Project_Tree_Ref;
531 Data : in out Project_Data;
532 Location : Source_Ptr;
533 Current_Source : in out String_List_Id;
534 Source_Recorded : in out Boolean;
535 Current_Dir : String);
536 -- Put a unit in the list of units of a project, if the file name
537 -- corresponds to a valid unit name.
539 -- Current_Dir should represent the current directory, and is passed for
540 -- efficiency to avoid system calls to recompute it.
542 procedure Remove_Source
544 Replaced_By : Source_Id;
545 Project : Project_Id;
546 Data : in out Project_Data;
547 In_Tree : Project_Tree_Ref);
550 procedure Report_No_Sources
551 (Project : Project_Id;
553 In_Tree : Project_Tree_Ref;
554 Location : Source_Ptr;
555 Continuation : Boolean := False);
556 -- Report an error or a warning depending on the value of When_No_Sources
557 -- when there are no sources for language Lang_Name.
559 procedure Show_Source_Dirs
560 (Data : Project_Data; In_Tree : Project_Tree_Ref);
561 -- List all the source directories of a project
563 procedure Warn_If_Not_Sources
564 (Project : Project_Id;
565 In_Tree : Project_Tree_Ref;
566 Conventions : Array_Element_Id;
568 Extending : Boolean);
569 -- Check that individual naming conventions apply to immediate sources of
570 -- the project. If not, issue a warning.
578 Data : in out Project_Data;
579 In_Tree : Project_Tree_Ref;
580 Project : Project_Id;
582 Lang_Id : Language_Index;
584 File_Name : File_Name_Type;
585 Display_File : File_Name_Type;
586 Lang_Kind : Language_Kind;
587 Naming_Exception : Boolean := False;
588 Path : Path_Name_Type := No_Path;
589 Display_Path : Path_Name_Type := No_Path;
590 Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
591 Other_Part : Source_Id := No_Source;
592 Unit : Name_Id := No_Name;
594 Source_To_Replace : Source_Id := No_Source)
596 Source : constant Source_Id := Data.Last_Source;
597 Src_Data : Source_Data := No_Source_Data;
598 Config : constant Language_Config :=
599 In_Tree.Languages_Data.Table (Lang_Id).Config;
602 -- This is a new source so create an entry for it in the Sources table
604 Source_Data_Table.Increment_Last (In_Tree.Sources);
605 Id := Source_Data_Table.Last (In_Tree.Sources);
607 if Current_Verbosity = High then
608 Write_Str ("Adding source #");
610 Write_Str (", File : ");
611 Write_Str (Get_Name_String (File_Name));
613 if Lang_Kind = Unit_Based then
614 Write_Str (", Unit : ");
615 Write_Str (Get_Name_String (Unit));
621 Src_Data.Project := Project;
622 Src_Data.Language_Name := Lang;
623 Src_Data.Language := Lang_Id;
624 Src_Data.Lang_Kind := Lang_Kind;
625 Src_Data.Compiled := In_Tree.Languages_Data.Table
626 (Lang_Id).Config.Compiler_Driver /=
628 Src_Data.Kind := Kind;
629 Src_Data.Alternate_Languages := Alternate_Languages;
630 Src_Data.Other_Part := Other_Part;
632 Src_Data.Object_Exists := Config.Object_Generated;
633 Src_Data.Object_Linked := Config.Objects_Linked;
635 if Other_Part /= No_Source then
636 In_Tree.Sources.Table (Other_Part).Other_Part := Id;
639 Src_Data.Unit := Unit;
640 Src_Data.Index := Index;
641 Src_Data.File := File_Name;
642 Src_Data.Display_File := Display_File;
643 Src_Data.Dependency := In_Tree.Languages_Data.Table
644 (Lang_Id).Config.Dependency_Kind;
645 Src_Data.Naming_Exception := Naming_Exception;
647 if Src_Data.Compiled and then Src_Data.Object_Exists then
648 Src_Data.Object := Object_Name (File_Name);
650 Dependency_Name (File_Name, Src_Data.Dependency);
651 Src_Data.Switches := Switches_Name (File_Name);
654 if Path /= No_Path then
655 Src_Data.Path := (Path, Display_Path);
656 Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path, Id);
659 -- Add the source to the global list
661 Src_Data.Next_In_Sources := In_Tree.First_Source;
662 In_Tree.First_Source := Id;
664 -- Add the source to the project list
666 if Source = No_Source then
667 Data.First_Source := Id;
669 In_Tree.Sources.Table (Source).Next_In_Project := Id;
672 Data.Last_Source := Id;
674 -- Add the source to the language list
676 Src_Data.Next_In_Lang :=
677 In_Tree.Languages_Data.Table (Lang_Id).First_Source;
678 In_Tree.Languages_Data.Table (Lang_Id).First_Source := Id;
680 In_Tree.Sources.Table (Id) := Src_Data;
682 if Source_To_Replace /= No_Source then
683 Remove_Source (Source_To_Replace, Id, Project, Data, In_Tree);
691 function ALI_File_Name (Source : String) return String is
693 -- If the source name has an extension, then replace it with
696 for Index in reverse Source'First + 1 .. Source'Last loop
697 if Source (Index) = '.' then
698 return Source (Source'First .. Index - 1) & ALI_Suffix;
702 -- If there is no dot, or if it is the first character, just add the
705 return Source & ALI_Suffix;
713 (Project : Project_Id;
714 In_Tree : Project_Tree_Ref;
715 Report_Error : Put_Line_Access;
716 When_No_Sources : Error_Warning;
717 Current_Dir : String)
719 Data : Project_Data := In_Tree.Projects.Table (Project);
720 Extending : Boolean := False;
723 Nmsc.When_No_Sources := When_No_Sources;
724 Error_Report := Report_Error;
726 Recursive_Dirs.Reset;
728 Check_If_Externally_Built (Project, In_Tree, Data);
730 -- Object, exec and source directories
732 Get_Directories (Project, In_Tree, Current_Dir, Data);
734 -- Get the programming languages
736 Check_Programming_Languages (In_Tree, Project, Data);
738 if Data.Qualifier = Dry and then Data.Source_Dirs /= Nil_String then
741 "an abstract project need to have no language, no sources or no " &
742 "source directories",
746 -- Check configuration in multi language mode
748 if Must_Check_Configuration then
749 Check_Configuration (Project, In_Tree, Data);
752 -- Library attributes
754 Check_Library_Attributes (Project, In_Tree, Current_Dir, Data);
756 if Current_Verbosity = High then
757 Show_Source_Dirs (Data, In_Tree);
760 Check_Package_Naming (Project, In_Tree, Data);
762 Extending := Data.Extends /= No_Project;
764 Check_Naming_Schemes (Data, Project, In_Tree);
766 if Get_Mode = Ada_Only then
767 Prepare_Ada_Naming_Exceptions
768 (Data.Naming.Bodies, In_Tree, Body_Part);
769 Prepare_Ada_Naming_Exceptions
770 (Data.Naming.Specs, In_Tree, Specification);
775 if Data.Source_Dirs /= Nil_String then
776 Look_For_Sources (Project, In_Tree, Data, Current_Dir);
778 if Get_Mode = Ada_Only then
780 -- Check that all individual naming conventions apply to sources
781 -- of this project file.
784 (Project, In_Tree, Data.Naming.Bodies,
786 Extending => Extending);
788 (Project, In_Tree, Data.Naming.Specs,
790 Extending => Extending);
792 elsif Get_Mode = Multi_Language and then
793 (not Data.Externally_Built) and then
797 Language : Language_Index;
799 Src_Data : Source_Data;
800 Alt_Lang : Alternate_Language_Id;
801 Alt_Lang_Data : Alternate_Language_Data;
802 Continuation : Boolean := False;
805 Language := Data.First_Language_Processing;
806 while Language /= No_Language_Index loop
807 Source := Data.First_Source;
808 Source_Loop : while Source /= No_Source loop
809 Src_Data := In_Tree.Sources.Table (Source);
811 exit Source_Loop when Src_Data.Language = Language;
813 Alt_Lang := Src_Data.Alternate_Languages;
816 while Alt_Lang /= No_Alternate_Language loop
818 In_Tree.Alt_Langs.Table (Alt_Lang);
820 when Alt_Lang_Data.Language = Language;
821 Alt_Lang := Alt_Lang_Data.Next;
822 end loop Alternate_Loop;
824 Source := Src_Data.Next_In_Project;
825 end loop Source_Loop;
827 if Source = No_Source then
831 (In_Tree.Languages_Data.Table
832 (Language).Display_Name),
836 Continuation := True;
839 Language := In_Tree.Languages_Data.Table (Language).Next;
845 if Get_Mode = Multi_Language then
847 -- If a list of sources is specified in attribute Interfaces, set
848 -- In_Interfaces only for the sources specified in the list.
850 Check_Interfaces (Project, In_Tree, Data);
853 -- If it is a library project file, check if it is a standalone library
856 Check_Stand_Alone_Library
857 (Project, In_Tree, Data, Current_Dir, Extending);
860 -- Put the list of Mains, if any, in the project data
862 Get_Mains (Project, In_Tree, Data);
864 -- Update the project data in the Projects table
866 In_Tree.Projects.Table (Project) := Data;
868 Free_Ada_Naming_Exceptions;
875 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
876 The_Name : String := Name;
878 Need_Letter : Boolean := True;
879 Last_Underscore : Boolean := False;
880 OK : Boolean := The_Name'Length > 0;
883 function Is_Reserved (Name : Name_Id) return Boolean;
884 function Is_Reserved (S : String) return Boolean;
885 -- Check that the given name is not an Ada 95 reserved word. The reason
886 -- for the Ada 95 here is that we do not want to exclude the case of an
887 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
888 -- name would be rejected anyway by the compiler. That means there is no
889 -- requirement that the project file parser reject this.
895 function Is_Reserved (S : String) return Boolean is
898 Add_Str_To_Name_Buffer (S);
899 return Is_Reserved (Name_Find);
906 function Is_Reserved (Name : Name_Id) return Boolean is
908 if Get_Name_Table_Byte (Name) /= 0
909 and then Name /= Name_Project
910 and then Name /= Name_Extends
911 and then Name /= Name_External
912 and then Name not in Ada_2005_Reserved_Words
916 if Current_Verbosity = High then
917 Write_Str (The_Name);
918 Write_Line (" is an Ada reserved word.");
928 -- Start of processing for Check_Ada_Name
933 Name_Len := The_Name'Length;
934 Name_Buffer (1 .. Name_Len) := The_Name;
936 -- Special cases of children of packages A, G, I and S on VMS
939 and then Name_Len > 3
940 and then Name_Buffer (2 .. 3) = "__"
942 ((Name_Buffer (1) = 'a') or else
943 (Name_Buffer (1) = 'g') or else
944 (Name_Buffer (1) = 'i') or else
945 (Name_Buffer (1) = 's'))
947 Name_Buffer (2) := '.';
948 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
949 Name_Len := Name_Len - 1;
952 Real_Name := Name_Find;
954 if Is_Reserved (Real_Name) then
958 First := The_Name'First;
960 for Index in The_Name'Range loop
963 -- We need a letter (at the beginning, and following a dot),
964 -- but we don't have one.
966 if Is_Letter (The_Name (Index)) then
967 Need_Letter := False;
972 if Current_Verbosity = High then
973 Write_Int (Types.Int (Index));
975 Write_Char (The_Name (Index));
976 Write_Line ("' is not a letter.");
982 elsif Last_Underscore
983 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
985 -- Two underscores are illegal, and a dot cannot follow
990 if Current_Verbosity = High then
991 Write_Int (Types.Int (Index));
993 Write_Char (The_Name (Index));
994 Write_Line ("' is illegal here.");
999 elsif The_Name (Index) = '.' then
1001 -- First, check if the name before the dot is not a reserved word
1002 if Is_Reserved (The_Name (First .. Index - 1)) then
1008 -- We need a letter after a dot
1010 Need_Letter := True;
1012 elsif The_Name (Index) = '_' then
1013 Last_Underscore := True;
1016 -- We need an letter or a digit
1018 Last_Underscore := False;
1020 if not Is_Alphanumeric (The_Name (Index)) then
1023 if Current_Verbosity = High then
1024 Write_Int (Types.Int (Index));
1026 Write_Char (The_Name (Index));
1027 Write_Line ("' is not alphanumeric.");
1035 -- Cannot end with an underscore or a dot
1037 OK := OK and then not Need_Letter and then not Last_Underscore;
1040 if First /= Name'First and then
1041 Is_Reserved (The_Name (First .. The_Name'Last))
1049 -- Signal a problem with No_Name
1055 --------------------------------------
1056 -- Check_Ada_Naming_Scheme_Validity --
1057 --------------------------------------
1059 procedure Check_Ada_Naming_Scheme_Validity
1060 (Project : Project_Id;
1061 In_Tree : Project_Tree_Ref;
1062 Naming : Naming_Data)
1065 -- Only check if we are not using the Default naming scheme
1067 if Naming /= In_Tree.Private_Part.Default_Naming then
1069 Dot_Replacement : constant String :=
1071 (Naming.Dot_Replacement);
1073 Spec_Suffix : constant String :=
1074 Spec_Suffix_Of (In_Tree, "ada", Naming);
1076 Body_Suffix : constant String :=
1077 Body_Suffix_Of (In_Tree, "ada", Naming);
1079 Separate_Suffix : constant String :=
1081 (Naming.Separate_Suffix);
1084 -- Dot_Replacement cannot
1087 -- - start or end with an alphanumeric
1088 -- - be a single '_'
1089 -- - start with an '_' followed by an alphanumeric
1090 -- - contain a '.' except if it is "."
1092 if Dot_Replacement'Length = 0
1093 or else Is_Alphanumeric
1094 (Dot_Replacement (Dot_Replacement'First))
1095 or else Is_Alphanumeric
1096 (Dot_Replacement (Dot_Replacement'Last))
1097 or else (Dot_Replacement (Dot_Replacement'First) = '_'
1099 (Dot_Replacement'Length = 1
1102 (Dot_Replacement (Dot_Replacement'First + 1))))
1103 or else (Dot_Replacement'Length > 1
1105 Index (Source => Dot_Replacement,
1106 Pattern => ".") /= 0)
1110 '"' & Dot_Replacement &
1111 """ is illegal for Dot_Replacement.",
1112 Naming.Dot_Repl_Loc);
1118 if Is_Illegal_Suffix
1119 (Spec_Suffix, Dot_Replacement = ".")
1121 Err_Vars.Error_Msg_File_1 :=
1122 Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
1125 "{ is illegal for Spec_Suffix",
1126 Naming.Ada_Spec_Suffix_Loc);
1129 if Is_Illegal_Suffix
1130 (Body_Suffix, Dot_Replacement = ".")
1132 Err_Vars.Error_Msg_File_1 :=
1133 Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
1136 "{ is illegal for Body_Suffix",
1137 Naming.Ada_Body_Suffix_Loc);
1140 if Body_Suffix /= Separate_Suffix then
1141 if Is_Illegal_Suffix
1142 (Separate_Suffix, Dot_Replacement = ".")
1144 Err_Vars.Error_Msg_File_1 := Naming.Separate_Suffix;
1147 "{ is illegal for Separate_Suffix",
1148 Naming.Sep_Suffix_Loc);
1152 -- Spec_Suffix cannot be equal to Body_Suffix Separate_Suffix,
1153 -- since that would cause a clear ambiguity. Note that we do
1154 -- allow a Spec_Suffix to have the same termination as one of
1155 -- these, which causes a potential ambiguity, but we resolve
1156 -- that my matching the longest possible suffix.
1158 if Spec_Suffix = Body_Suffix then
1163 """) cannot be the same as Spec_Suffix.",
1164 Naming.Ada_Body_Suffix_Loc);
1167 if Body_Suffix /= Separate_Suffix
1168 and then Spec_Suffix = Separate_Suffix
1172 "Separate_Suffix (""" &
1174 """) cannot be the same as Spec_Suffix.",
1175 Naming.Sep_Suffix_Loc);
1179 end Check_Ada_Naming_Scheme_Validity;
1181 -------------------------
1182 -- Check_Configuration --
1183 -------------------------
1185 procedure Check_Configuration
1186 (Project : Project_Id;
1187 In_Tree : Project_Tree_Ref;
1188 Data : in out Project_Data)
1190 Dot_Replacement : File_Name_Type := No_File;
1191 Casing : Casing_Type := All_Lower_Case;
1192 Separate_Suffix : File_Name_Type := No_File;
1194 Lang_Index : Language_Index := No_Language_Index;
1195 -- The index of the language data being checked
1197 Prev_Index : Language_Index := No_Language_Index;
1198 -- The index of the previous language
1200 Current_Language : Name_Id := No_Name;
1201 -- The name of the language
1203 Lang_Data : Language_Data;
1204 -- The data of the language being checked
1206 procedure Get_Language_Index_Of (Language : Name_Id);
1207 -- Get the language index of Language, if Language is one of the
1208 -- languages of the project.
1210 procedure Process_Project_Level_Simple_Attributes;
1211 -- Process the simple attributes at the project level
1213 procedure Process_Project_Level_Array_Attributes;
1214 -- Process the associate array attributes at the project level
1216 procedure Process_Packages;
1217 -- Read the packages of the project
1219 ---------------------------
1220 -- Get_Language_Index_Of --
1221 ---------------------------
1223 procedure Get_Language_Index_Of (Language : Name_Id) is
1224 Real_Language : Name_Id;
1227 Get_Name_String (Language);
1228 To_Lower (Name_Buffer (1 .. Name_Len));
1229 Real_Language := Name_Find;
1231 -- Nothing to do if the language is the same as the current language
1233 if Current_Language /= Real_Language then
1234 Lang_Index := Data.First_Language_Processing;
1235 while Lang_Index /= No_Language_Index loop
1236 exit when In_Tree.Languages_Data.Table (Lang_Index).Name =
1239 In_Tree.Languages_Data.Table (Lang_Index).Next;
1242 if Lang_Index = No_Language_Index then
1243 Current_Language := No_Name;
1245 Current_Language := Real_Language;
1248 end Get_Language_Index_Of;
1250 ----------------------
1251 -- Process_Packages --
1252 ----------------------
1254 procedure Process_Packages is
1255 Packages : Package_Id;
1256 Element : Package_Element;
1258 procedure Process_Binder (Arrays : Array_Id);
1259 -- Process the associate array attributes of package Binder
1261 procedure Process_Builder (Attributes : Variable_Id);
1262 -- Process the simple attributes of package Builder
1264 procedure Process_Compiler (Arrays : Array_Id);
1265 -- Process the associate array attributes of package Compiler
1267 procedure Process_Naming (Attributes : Variable_Id);
1268 -- Process the simple attributes of package Naming
1270 procedure Process_Naming (Arrays : Array_Id);
1271 -- Process the associate array attributes of package Naming
1273 procedure Process_Linker (Attributes : Variable_Id);
1274 -- Process the simple attributes of package Linker of a
1275 -- configuration project.
1277 --------------------
1278 -- Process_Binder --
1279 --------------------
1281 procedure Process_Binder (Arrays : Array_Id) is
1282 Current_Array_Id : Array_Id;
1283 Current_Array : Array_Data;
1284 Element_Id : Array_Element_Id;
1285 Element : Array_Element;
1288 -- Process the associative array attribute of package Binder
1290 Current_Array_Id := Arrays;
1291 while Current_Array_Id /= No_Array loop
1292 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1294 Element_Id := Current_Array.Value;
1295 while Element_Id /= No_Array_Element loop
1296 Element := In_Tree.Array_Elements.Table (Element_Id);
1298 -- Get the name of the language
1300 Get_Language_Index_Of (Element.Index);
1302 if Lang_Index /= No_Language_Index then
1303 case Current_Array.Name is
1306 -- Attribute Driver (<language>)
1308 In_Tree.Languages_Data.Table
1309 (Lang_Index).Config.Binder_Driver :=
1310 File_Name_Type (Element.Value.Value);
1312 when Name_Required_Switches =>
1314 In_Tree.Languages_Data.Table
1315 (Lang_Index).Config.Binder_Required_Switches,
1316 From_List => Element.Value.Values,
1317 In_Tree => In_Tree);
1321 -- Attribute Prefix (<language>)
1323 In_Tree.Languages_Data.Table
1324 (Lang_Index).Config.Binder_Prefix :=
1325 Element.Value.Value;
1327 when Name_Objects_Path =>
1329 -- Attribute Objects_Path (<language>)
1331 In_Tree.Languages_Data.Table
1332 (Lang_Index).Config.Objects_Path :=
1333 Element.Value.Value;
1335 when Name_Objects_Path_File =>
1337 -- Attribute Objects_Path (<language>)
1339 In_Tree.Languages_Data.Table
1340 (Lang_Index).Config.Objects_Path_File :=
1341 Element.Value.Value;
1348 Element_Id := Element.Next;
1351 Current_Array_Id := Current_Array.Next;
1355 ---------------------
1356 -- Process_Builder --
1357 ---------------------
1359 procedure Process_Builder (Attributes : Variable_Id) is
1360 Attribute_Id : Variable_Id;
1361 Attribute : Variable;
1364 -- Process non associated array attribute from package Builder
1366 Attribute_Id := Attributes;
1367 while Attribute_Id /= No_Variable loop
1369 In_Tree.Variable_Elements.Table (Attribute_Id);
1371 if not Attribute.Value.Default then
1372 if Attribute.Name = Name_Executable_Suffix then
1374 -- Attribute Executable_Suffix: the suffix of the
1377 Data.Config.Executable_Suffix :=
1378 Attribute.Value.Value;
1382 Attribute_Id := Attribute.Next;
1384 end Process_Builder;
1386 ----------------------
1387 -- Process_Compiler --
1388 ----------------------
1390 procedure Process_Compiler (Arrays : Array_Id) is
1391 Current_Array_Id : Array_Id;
1392 Current_Array : Array_Data;
1393 Element_Id : Array_Element_Id;
1394 Element : Array_Element;
1395 List : String_List_Id;
1398 -- Process the associative array attribute of package Compiler
1400 Current_Array_Id := Arrays;
1401 while Current_Array_Id /= No_Array loop
1402 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1404 Element_Id := Current_Array.Value;
1405 while Element_Id /= No_Array_Element loop
1406 Element := In_Tree.Array_Elements.Table (Element_Id);
1408 -- Get the name of the language
1410 Get_Language_Index_Of (Element.Index);
1412 if Lang_Index /= No_Language_Index then
1413 case Current_Array.Name is
1414 when Name_Dependency_Switches =>
1416 -- Attribute Dependency_Switches (<language>)
1418 if In_Tree.Languages_Data.Table
1419 (Lang_Index).Config.Dependency_Kind = None
1421 In_Tree.Languages_Data.Table
1422 (Lang_Index).Config.Dependency_Kind :=
1426 List := Element.Value.Values;
1428 if List /= Nil_String then
1430 In_Tree.Languages_Data.Table
1431 (Lang_Index).Config.Dependency_Option,
1433 In_Tree => In_Tree);
1436 when Name_Dependency_Driver =>
1438 -- Attribute Dependency_Driver (<language>)
1440 if In_Tree.Languages_Data.Table
1441 (Lang_Index).Config.Dependency_Kind = None
1443 In_Tree.Languages_Data.Table
1444 (Lang_Index).Config.Dependency_Kind :=
1448 List := Element.Value.Values;
1450 if List /= Nil_String then
1452 In_Tree.Languages_Data.Table
1453 (Lang_Index).Config.Compute_Dependency,
1455 In_Tree => In_Tree);
1458 when Name_Include_Switches =>
1460 -- Attribute Include_Switches (<language>)
1462 List := Element.Value.Values;
1464 if List = Nil_String then
1468 "include option cannot be null",
1469 Element.Value.Location);
1473 In_Tree.Languages_Data.Table
1474 (Lang_Index).Config.Include_Option,
1476 In_Tree => In_Tree);
1478 when Name_Include_Path =>
1480 -- Attribute Include_Path (<language>)
1482 In_Tree.Languages_Data.Table
1483 (Lang_Index).Config.Include_Path :=
1484 Element.Value.Value;
1486 when Name_Include_Path_File =>
1488 -- Attribute Include_Path_File (<language>)
1490 In_Tree.Languages_Data.Table
1491 (Lang_Index).Config.Include_Path_File :=
1492 Element.Value.Value;
1496 -- Attribute Driver (<language>)
1498 Get_Name_String (Element.Value.Value);
1500 In_Tree.Languages_Data.Table
1501 (Lang_Index).Config.Compiler_Driver :=
1502 File_Name_Type (Element.Value.Value);
1504 when Name_Required_Switches =>
1506 In_Tree.Languages_Data.Table
1507 (Lang_Index).Config.
1508 Compiler_Required_Switches,
1509 From_List => Element.Value.Values,
1510 In_Tree => In_Tree);
1512 when Name_Pic_Option =>
1514 -- Attribute Compiler_Pic_Option (<language>)
1516 List := Element.Value.Values;
1518 if List = Nil_String then
1522 "compiler PIC option cannot be null",
1523 Element.Value.Location);
1527 In_Tree.Languages_Data.Table
1528 (Lang_Index).Config.Compilation_PIC_Option,
1530 In_Tree => In_Tree);
1532 when Name_Mapping_File_Switches =>
1534 -- Attribute Mapping_File_Switches (<language>)
1536 List := Element.Value.Values;
1538 if List = Nil_String then
1542 "mapping file switches cannot be null",
1543 Element.Value.Location);
1547 In_Tree.Languages_Data.Table
1548 (Lang_Index).Config.Mapping_File_Switches,
1550 In_Tree => In_Tree);
1552 when Name_Mapping_Spec_Suffix =>
1554 -- Attribute Mapping_Spec_Suffix (<language>)
1556 In_Tree.Languages_Data.Table
1557 (Lang_Index).Config.Mapping_Spec_Suffix :=
1558 File_Name_Type (Element.Value.Value);
1560 when Name_Mapping_Body_Suffix =>
1562 -- Attribute Mapping_Body_Suffix (<language>)
1564 In_Tree.Languages_Data.Table
1565 (Lang_Index).Config.Mapping_Body_Suffix :=
1566 File_Name_Type (Element.Value.Value);
1568 when Name_Config_File_Switches =>
1570 -- Attribute Config_File_Switches (<language>)
1572 List := Element.Value.Values;
1574 if List = Nil_String then
1578 "config file switches cannot be null",
1579 Element.Value.Location);
1583 In_Tree.Languages_Data.Table
1584 (Lang_Index).Config.Config_File_Switches,
1586 In_Tree => In_Tree);
1588 when Name_Objects_Path =>
1590 -- Attribute Objects_Path (<language>)
1592 In_Tree.Languages_Data.Table
1593 (Lang_Index).Config.Objects_Path :=
1594 Element.Value.Value;
1596 when Name_Objects_Path_File =>
1598 -- Attribute Objects_Path_File (<language>)
1600 In_Tree.Languages_Data.Table
1601 (Lang_Index).Config.Objects_Path_File :=
1602 Element.Value.Value;
1604 when Name_Config_Body_File_Name =>
1606 -- Attribute Config_Body_File_Name (<language>)
1608 In_Tree.Languages_Data.Table
1609 (Lang_Index).Config.Config_Body :=
1610 Element.Value.Value;
1612 when Name_Config_Body_File_Name_Pattern =>
1614 -- Attribute Config_Body_File_Name_Pattern
1617 In_Tree.Languages_Data.Table
1618 (Lang_Index).Config.Config_Body_Pattern :=
1619 Element.Value.Value;
1621 when Name_Config_Spec_File_Name =>
1623 -- Attribute Config_Spec_File_Name (<language>)
1625 In_Tree.Languages_Data.Table
1626 (Lang_Index).Config.Config_Spec :=
1627 Element.Value.Value;
1629 when Name_Config_Spec_File_Name_Pattern =>
1631 -- Attribute Config_Spec_File_Name_Pattern
1634 In_Tree.Languages_Data.Table
1635 (Lang_Index).Config.Config_Spec_Pattern :=
1636 Element.Value.Value;
1638 when Name_Config_File_Unique =>
1640 -- Attribute Config_File_Unique (<language>)
1643 In_Tree.Languages_Data.Table
1644 (Lang_Index).Config.Config_File_Unique :=
1646 (Get_Name_String (Element.Value.Value));
1648 when Constraint_Error =>
1652 "illegal value for Config_File_Unique",
1653 Element.Value.Location);
1661 Element_Id := Element.Next;
1664 Current_Array_Id := Current_Array.Next;
1666 end Process_Compiler;
1668 --------------------
1669 -- Process_Naming --
1670 --------------------
1672 procedure Process_Naming (Attributes : Variable_Id) is
1673 Attribute_Id : Variable_Id;
1674 Attribute : Variable;
1677 -- Process non associated array attribute from package Naming
1679 Attribute_Id := Attributes;
1680 while Attribute_Id /= No_Variable loop
1682 In_Tree.Variable_Elements.Table (Attribute_Id);
1684 if not Attribute.Value.Default then
1685 if Attribute.Name = Name_Separate_Suffix then
1687 -- Attribute Separate_Suffix
1689 Separate_Suffix := File_Name_Type (Attribute.Value.Value);
1691 elsif Attribute.Name = Name_Casing then
1697 Value (Get_Name_String (Attribute.Value.Value));
1700 when Constraint_Error =>
1704 "invalid value for Casing",
1705 Attribute.Value.Location);
1708 elsif Attribute.Name = Name_Dot_Replacement then
1710 -- Attribute Dot_Replacement
1712 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1717 Attribute_Id := Attribute.Next;
1721 procedure Process_Naming (Arrays : Array_Id) is
1722 Current_Array_Id : Array_Id;
1723 Current_Array : Array_Data;
1724 Element_Id : Array_Element_Id;
1725 Element : Array_Element;
1727 -- Process the associative array attribute of package Naming
1729 Current_Array_Id := Arrays;
1730 while Current_Array_Id /= No_Array loop
1731 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1733 Element_Id := Current_Array.Value;
1734 while Element_Id /= No_Array_Element loop
1735 Element := In_Tree.Array_Elements.Table (Element_Id);
1737 -- Get the name of the language
1739 Get_Language_Index_Of (Element.Index);
1741 if Lang_Index /= No_Language_Index then
1742 case Current_Array.Name is
1743 when Name_Specification_Suffix | Name_Spec_Suffix =>
1745 -- Attribute Spec_Suffix (<language>)
1747 In_Tree.Languages_Data.Table
1748 (Lang_Index).Config.Naming_Data.Spec_Suffix :=
1749 File_Name_Type (Element.Value.Value);
1751 when Name_Implementation_Suffix | Name_Body_Suffix =>
1753 -- Attribute Body_Suffix (<language>)
1755 In_Tree.Languages_Data.Table
1756 (Lang_Index).Config.Naming_Data.Body_Suffix :=
1757 File_Name_Type (Element.Value.Value);
1759 In_Tree.Languages_Data.Table
1760 (Lang_Index).Config.Naming_Data.Separate_Suffix :=
1761 File_Name_Type (Element.Value.Value);
1768 Element_Id := Element.Next;
1771 Current_Array_Id := Current_Array.Next;
1775 --------------------
1776 -- Process_Linker --
1777 --------------------
1779 procedure Process_Linker (Attributes : Variable_Id) is
1780 Attribute_Id : Variable_Id;
1781 Attribute : Variable;
1784 -- Process non associated array attribute from package Linker
1786 Attribute_Id := Attributes;
1787 while Attribute_Id /= No_Variable loop
1789 In_Tree.Variable_Elements.Table (Attribute_Id);
1791 if not Attribute.Value.Default then
1792 if Attribute.Name = Name_Driver then
1794 -- Attribute Linker'Driver: the default linker to use
1796 Data.Config.Linker :=
1797 Path_Name_Type (Attribute.Value.Value);
1799 elsif Attribute.Name = Name_Required_Switches then
1801 -- Attribute Required_Switches: the minimum
1802 -- options to use when invoking the linker
1805 Data.Config.Minimum_Linker_Options,
1806 From_List => Attribute.Value.Values,
1807 In_Tree => In_Tree);
1809 elsif Attribute.Name = Name_Map_File_Option then
1810 Data.Config.Map_File_Option := Attribute.Value.Value;
1814 Attribute_Id := Attribute.Next;
1818 -- Start of processing for Process_Packages
1821 Packages := Data.Decl.Packages;
1822 while Packages /= No_Package loop
1823 Element := In_Tree.Packages.Table (Packages);
1825 case Element.Name is
1828 -- Process attributes of package Binder
1830 Process_Binder (Element.Decl.Arrays);
1832 when Name_Builder =>
1834 -- Process attributes of package Builder
1836 Process_Builder (Element.Decl.Attributes);
1838 when Name_Compiler =>
1840 -- Process attributes of package Compiler
1842 Process_Compiler (Element.Decl.Arrays);
1846 -- Process attributes of package Linker
1848 Process_Linker (Element.Decl.Attributes);
1852 -- Process attributes of package Naming
1854 Process_Naming (Element.Decl.Attributes);
1855 Process_Naming (Element.Decl.Arrays);
1861 Packages := Element.Next;
1863 end Process_Packages;
1865 ---------------------------------------------
1866 -- Process_Project_Level_Simple_Attributes --
1867 ---------------------------------------------
1869 procedure Process_Project_Level_Simple_Attributes is
1870 Attribute_Id : Variable_Id;
1871 Attribute : Variable;
1872 List : String_List_Id;
1875 -- Process non associated array attribute at project level
1877 Attribute_Id := Data.Decl.Attributes;
1878 while Attribute_Id /= No_Variable loop
1880 In_Tree.Variable_Elements.Table (Attribute_Id);
1882 if not Attribute.Value.Default then
1883 if Attribute.Name = Name_Library_Builder then
1885 -- Attribute Library_Builder: the application to invoke
1886 -- to build libraries.
1888 Data.Config.Library_Builder :=
1889 Path_Name_Type (Attribute.Value.Value);
1891 elsif Attribute.Name = Name_Archive_Builder then
1893 -- Attribute Archive_Builder: the archive builder
1894 -- (usually "ar") and its minimum options (usually "cr").
1896 List := Attribute.Value.Values;
1898 if List = Nil_String then
1902 "archive builder cannot be null",
1903 Attribute.Value.Location);
1906 Put (Into_List => Data.Config.Archive_Builder,
1908 In_Tree => In_Tree);
1910 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1912 -- Attribute Archive_Builder: the archive builder
1913 -- (usually "ar") and its minimum options (usually "cr").
1915 List := Attribute.Value.Values;
1917 if List /= Nil_String then
1919 (Into_List => Data.Config.Archive_Builder_Append_Option,
1921 In_Tree => In_Tree);
1924 elsif Attribute.Name = Name_Archive_Indexer then
1926 -- Attribute Archive_Indexer: the optional archive
1927 -- indexer (usually "ranlib") with its minimum options
1930 List := Attribute.Value.Values;
1932 if List = Nil_String then
1936 "archive indexer cannot be null",
1937 Attribute.Value.Location);
1940 Put (Into_List => Data.Config.Archive_Indexer,
1942 In_Tree => In_Tree);
1944 elsif Attribute.Name = Name_Library_Partial_Linker then
1946 -- Attribute Library_Partial_Linker: the optional linker
1947 -- driver with its minimum options, to partially link
1950 List := Attribute.Value.Values;
1952 if List = Nil_String then
1956 "partial linker cannot be null",
1957 Attribute.Value.Location);
1960 Put (Into_List => Data.Config.Lib_Partial_Linker,
1962 In_Tree => In_Tree);
1964 elsif Attribute.Name = Name_Library_GCC then
1965 Data.Config.Shared_Lib_Driver :=
1966 File_Name_Type (Attribute.Value.Value);
1968 elsif Attribute.Name = Name_Archive_Suffix then
1969 Data.Config.Archive_Suffix :=
1970 File_Name_Type (Attribute.Value.Value);
1972 elsif Attribute.Name = Name_Linker_Executable_Option then
1974 -- Attribute Linker_Executable_Option: optional options
1975 -- to specify an executable name. Defaults to "-o".
1977 List := Attribute.Value.Values;
1979 if List = Nil_String then
1983 "linker executable option cannot be null",
1984 Attribute.Value.Location);
1987 Put (Into_List => Data.Config.Linker_Executable_Option,
1989 In_Tree => In_Tree);
1991 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
1993 -- Attribute Linker_Lib_Dir_Option: optional options
1994 -- to specify a library search directory. Defaults to
1997 Get_Name_String (Attribute.Value.Value);
1999 if Name_Len = 0 then
2003 "linker library directory option cannot be empty",
2004 Attribute.Value.Location);
2007 Data.Config.Linker_Lib_Dir_Option := Attribute.Value.Value;
2009 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2011 -- Attribute Linker_Lib_Name_Option: optional options
2012 -- to specify the name of a library to be linked in.
2013 -- Defaults to "-l".
2015 Get_Name_String (Attribute.Value.Value);
2017 if Name_Len = 0 then
2021 "linker library name option cannot be empty",
2022 Attribute.Value.Location);
2025 Data.Config.Linker_Lib_Name_Option := Attribute.Value.Value;
2027 elsif Attribute.Name = Name_Run_Path_Option then
2029 -- Attribute Run_Path_Option: optional options to
2030 -- specify a path for libraries.
2032 List := Attribute.Value.Values;
2034 if List /= Nil_String then
2035 Put (Into_List => Data.Config.Run_Path_Option,
2037 In_Tree => In_Tree);
2040 elsif Attribute.Name = Name_Library_Support then
2042 pragma Unsuppress (All_Checks);
2044 Data.Config.Lib_Support :=
2045 Library_Support'Value (Get_Name_String
2046 (Attribute.Value.Value));
2048 when Constraint_Error =>
2052 "invalid value """ &
2053 Get_Name_String (Attribute.Value.Value) &
2054 """ for Library_Support",
2055 Attribute.Value.Location);
2058 elsif Attribute.Name = Name_Shared_Library_Prefix then
2059 Data.Config.Shared_Lib_Prefix :=
2060 File_Name_Type (Attribute.Value.Value);
2062 elsif Attribute.Name = Name_Shared_Library_Suffix then
2063 Data.Config.Shared_Lib_Suffix :=
2064 File_Name_Type (Attribute.Value.Value);
2066 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2068 pragma Unsuppress (All_Checks);
2070 Data.Config.Symbolic_Link_Supported :=
2071 Boolean'Value (Get_Name_String
2072 (Attribute.Value.Value));
2074 when Constraint_Error =>
2079 & Get_Name_String (Attribute.Value.Value)
2080 & """ for Symbolic_Link_Supported",
2081 Attribute.Value.Location);
2085 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2088 pragma Unsuppress (All_Checks);
2090 Data.Config.Lib_Maj_Min_Id_Supported :=
2091 Boolean'Value (Get_Name_String
2092 (Attribute.Value.Value));
2094 when Constraint_Error =>
2098 "invalid value """ &
2099 Get_Name_String (Attribute.Value.Value) &
2100 """ for Library_Major_Minor_Id_Supported",
2101 Attribute.Value.Location);
2104 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2106 pragma Unsuppress (All_Checks);
2108 Data.Config.Auto_Init_Supported :=
2109 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2111 when Constraint_Error =>
2116 & Get_Name_String (Attribute.Value.Value)
2117 & """ for Library_Auto_Init_Supported",
2118 Attribute.Value.Location);
2121 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2122 List := Attribute.Value.Values;
2124 if List /= Nil_String then
2125 Put (Into_List => Data.Config.Shared_Lib_Min_Options,
2127 In_Tree => In_Tree);
2130 elsif Attribute.Name = Name_Library_Version_Switches then
2131 List := Attribute.Value.Values;
2133 if List /= Nil_String then
2134 Put (Into_List => Data.Config.Lib_Version_Options,
2136 In_Tree => In_Tree);
2141 Attribute_Id := Attribute.Next;
2143 end Process_Project_Level_Simple_Attributes;
2145 --------------------------------------------
2146 -- Process_Project_Level_Array_Attributes --
2147 --------------------------------------------
2149 procedure Process_Project_Level_Array_Attributes is
2150 Current_Array_Id : Array_Id;
2151 Current_Array : Array_Data;
2152 Element_Id : Array_Element_Id;
2153 Element : Array_Element;
2154 List : String_List_Id;
2157 -- Process the associative array attributes at project level
2159 Current_Array_Id := Data.Decl.Arrays;
2160 while Current_Array_Id /= No_Array loop
2161 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
2163 Element_Id := Current_Array.Value;
2164 while Element_Id /= No_Array_Element loop
2165 Element := In_Tree.Array_Elements.Table (Element_Id);
2167 -- Get the name of the language
2169 Get_Language_Index_Of (Element.Index);
2171 if Lang_Index /= No_Language_Index then
2172 case Current_Array.Name is
2173 when Name_Inherit_Source_Path =>
2174 List := Element.Value.Values;
2176 if List /= Nil_String then
2179 In_Tree.Languages_Data.Table (Lang_Index).
2180 Config.Include_Compatible_Languages,
2183 Lower_Case => True);
2186 when Name_Toolchain_Description =>
2188 -- Attribute Toolchain_Description (<language>)
2190 In_Tree.Languages_Data.Table
2191 (Lang_Index).Config.Toolchain_Description :=
2192 Element.Value.Value;
2194 when Name_Toolchain_Version =>
2196 -- Attribute Toolchain_Version (<language>)
2198 In_Tree.Languages_Data.Table
2199 (Lang_Index).Config.Toolchain_Version :=
2200 Element.Value.Value;
2202 when Name_Runtime_Library_Dir =>
2204 -- Attribute Runtime_Library_Dir (<language>)
2206 In_Tree.Languages_Data.Table
2207 (Lang_Index).Config.Runtime_Library_Dir :=
2208 Element.Value.Value;
2210 when Name_Object_Generated =>
2212 pragma Unsuppress (All_Checks);
2218 (Get_Name_String (Element.Value.Value));
2220 In_Tree.Languages_Data.Table
2221 (Lang_Index).Config.Object_Generated := Value;
2223 -- If no object is generated, no object may be
2227 In_Tree.Languages_Data.Table
2228 (Lang_Index).Config.Objects_Linked := False;
2232 when Constraint_Error =>
2237 & Get_Name_String (Element.Value.Value)
2238 & """ for Object_Generated",
2239 Element.Value.Location);
2242 when Name_Objects_Linked =>
2244 pragma Unsuppress (All_Checks);
2250 (Get_Name_String (Element.Value.Value));
2252 -- No change if Object_Generated is False, as this
2253 -- forces Objects_Linked to be False too.
2255 if In_Tree.Languages_Data.Table
2256 (Lang_Index).Config.Object_Generated
2258 In_Tree.Languages_Data.Table
2259 (Lang_Index).Config.Objects_Linked :=
2264 when Constraint_Error =>
2269 & Get_Name_String (Element.Value.Value)
2270 & """ for Objects_Linked",
2271 Element.Value.Location);
2278 Element_Id := Element.Next;
2281 Current_Array_Id := Current_Array.Next;
2283 end Process_Project_Level_Array_Attributes;
2286 Process_Project_Level_Simple_Attributes;
2287 Process_Project_Level_Array_Attributes;
2290 -- For unit based languages, set Casing, Dot_Replacement and
2291 -- Separate_Suffix in Naming_Data.
2293 Lang_Index := Data.First_Language_Processing;
2294 while Lang_Index /= No_Language_Index loop
2295 if In_Tree.Languages_Data.Table
2296 (Lang_Index).Name = Name_Ada
2298 In_Tree.Languages_Data.Table
2299 (Lang_Index).Config.Naming_Data.Casing := Casing;
2300 In_Tree.Languages_Data.Table
2301 (Lang_Index).Config.Naming_Data.Dot_Replacement :=
2304 if Separate_Suffix /= No_File then
2305 In_Tree.Languages_Data.Table
2306 (Lang_Index).Config.Naming_Data.Separate_Suffix :=
2313 Lang_Index := In_Tree.Languages_Data.Table (Lang_Index).Next;
2316 -- Give empty names to various prefixes/suffixes, if they have not
2317 -- been specified in the configuration.
2319 if Data.Config.Archive_Suffix = No_File then
2320 Data.Config.Archive_Suffix := Empty_File;
2323 if Data.Config.Shared_Lib_Prefix = No_File then
2324 Data.Config.Shared_Lib_Prefix := Empty_File;
2327 if Data.Config.Shared_Lib_Suffix = No_File then
2328 Data.Config.Shared_Lib_Suffix := Empty_File;
2331 Lang_Index := Data.First_Language_Processing;
2332 while Lang_Index /= No_Language_Index loop
2333 Lang_Data := In_Tree.Languages_Data.Table (Lang_Index);
2335 Current_Language := Lang_Data.Display_Name;
2337 -- For all languages, Compiler_Driver needs to be specified
2339 if Lang_Data.Config.Compiler_Driver = No_File then
2340 Error_Msg_Name_1 := Current_Language;
2344 "?no compiler specified for language %%" &
2345 ", ignoring all its sources",
2348 if Lang_Index = Data.First_Language_Processing then
2349 Data.First_Language_Processing :=
2352 In_Tree.Languages_Data.Table (Prev_Index).Next :=
2356 elsif Lang_Data.Name = Name_Ada then
2357 Prev_Index := Lang_Index;
2359 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2360 -- Body_Suffix need to be specified.
2362 if Lang_Data.Config.Naming_Data.Dot_Replacement = No_File then
2366 "Dot_Replacement not specified for Ada",
2370 if Lang_Data.Config.Naming_Data.Spec_Suffix = No_File then
2374 "Spec_Suffix not specified for Ada",
2378 if Lang_Data.Config.Naming_Data.Body_Suffix = No_File then
2382 "Body_Suffix not specified for Ada",
2387 Prev_Index := Lang_Index;
2389 -- For file based languages, either Spec_Suffix or Body_Suffix
2390 -- need to be specified.
2392 if Lang_Data.Config.Naming_Data.Spec_Suffix = No_File and then
2393 Lang_Data.Config.Naming_Data.Body_Suffix = No_File
2395 Error_Msg_Name_1 := Current_Language;
2399 "no suffixes specified for %%",
2404 Lang_Index := Lang_Data.Next;
2406 end Check_Configuration;
2408 -------------------------------
2409 -- Check_If_Externally_Built --
2410 -------------------------------
2412 procedure Check_If_Externally_Built
2413 (Project : Project_Id;
2414 In_Tree : Project_Tree_Ref;
2415 Data : in out Project_Data)
2417 Externally_Built : constant Variable_Value :=
2419 (Name_Externally_Built,
2420 Data.Decl.Attributes, In_Tree);
2423 if not Externally_Built.Default then
2424 Get_Name_String (Externally_Built.Value);
2425 To_Lower (Name_Buffer (1 .. Name_Len));
2427 if Name_Buffer (1 .. Name_Len) = "true" then
2428 Data.Externally_Built := True;
2430 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2431 Error_Msg (Project, In_Tree,
2432 "Externally_Built may only be true or false",
2433 Externally_Built.Location);
2437 -- A virtual project extending an externally built project is itself
2438 -- externally built.
2440 if Data.Virtual and then Data.Extends /= No_Project then
2441 Data.Externally_Built :=
2442 In_Tree.Projects.Table (Data.Extends).Externally_Built;
2445 if Current_Verbosity = High then
2446 Write_Str ("Project is ");
2448 if not Data.Externally_Built then
2452 Write_Line ("externally built.");
2454 end Check_If_Externally_Built;
2456 ----------------------
2457 -- Check_Interfaces --
2458 ----------------------
2460 procedure Check_Interfaces
2461 (Project : Project_Id;
2462 In_Tree : Project_Tree_Ref;
2463 Data : in out Project_Data)
2465 Interfaces : constant Prj.Variable_Value :=
2467 (Snames.Name_Interfaces,
2468 Data.Decl.Attributes,
2471 List : String_List_Id;
2472 Element : String_Element;
2473 Name : File_Name_Type;
2476 Src_Data : Source_Data;
2478 Project_2 : Project_Id;
2479 Data_2 : Project_Data;
2482 if not Interfaces.Default then
2484 -- Set In_Interfaces to False for all sources. It will be set to True
2485 -- later for the sources in the Interfaces list.
2487 Project_2 := Project;
2490 Source := Data_2.First_Source;
2491 while Source /= No_Source loop
2492 Src_Data := In_Tree.Sources.Table (Source);
2493 Src_Data.In_Interfaces := False;
2494 In_Tree.Sources.Table (Source) := Src_Data;
2495 Source := Src_Data.Next_In_Project;
2498 Project_2 := Data_2.Extends;
2500 exit when Project_2 = No_Project;
2502 Data_2 := In_Tree.Projects.Table (Project_2);
2505 List := Interfaces.Values;
2506 while List /= Nil_String loop
2507 Element := In_Tree.String_Elements.Table (List);
2508 Get_Name_String (Element.Value);
2509 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2512 Project_2 := Project;
2516 Source := Data_2.First_Source;
2517 while Source /= No_Source loop
2518 Src_Data := In_Tree.Sources.Table (Source);
2519 if Src_Data.File = Name then
2520 if not Src_Data.Locally_Removed then
2521 In_Tree.Sources.Table (Source).In_Interfaces := True;
2522 In_Tree.Sources.Table
2523 (Source).Declared_In_Interfaces := True;
2525 if Src_Data.Other_Part /= No_Source then
2526 In_Tree.Sources.Table
2527 (Src_Data.Other_Part).In_Interfaces := True;
2528 In_Tree.Sources.Table
2529 (Src_Data.Other_Part).Declared_In_Interfaces :=
2533 if Current_Verbosity = High then
2534 Write_Str (" interface: ");
2535 Write_Line (Get_Name_String (Src_Data.Path.Name));
2542 Source := Src_Data.Next_In_Project;
2545 Project_2 := Data_2.Extends;
2547 exit Big_Loop when Project_2 = No_Project;
2549 Data_2 := In_Tree.Projects.Table (Project_2);
2552 if Source = No_Source then
2553 Error_Msg_File_1 := File_Name_Type (Element.Value);
2554 Error_Msg_Name_1 := Data.Name;
2559 "{ cannot be an interface of project %% " &
2560 "as it is not one of its sources",
2564 List := Element.Next;
2567 Data.Interfaces_Defined := True;
2569 elsif Data.Extends /= No_Project then
2570 Data.Interfaces_Defined :=
2571 In_Tree.Projects.Table (Data.Extends).Interfaces_Defined;
2573 if Data.Interfaces_Defined then
2574 Source := Data.First_Source;
2575 while Source /= No_Source loop
2576 Src_Data := In_Tree.Sources.Table (Source);
2578 if not Src_Data.Declared_In_Interfaces then
2579 Src_Data.In_Interfaces := False;
2580 In_Tree.Sources.Table (Source) := Src_Data;
2583 Source := Src_Data.Next_In_Project;
2587 end Check_Interfaces;
2589 --------------------------
2590 -- Check_Naming_Schemes --
2591 --------------------------
2593 procedure Check_Naming_Schemes
2594 (Data : in out Project_Data;
2595 Project : Project_Id;
2596 In_Tree : Project_Tree_Ref)
2598 Naming_Id : constant Package_Id :=
2599 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
2600 Naming : Package_Element;
2602 procedure Check_Unit_Names (List : Array_Element_Id);
2603 -- Check that a list of unit names contains only valid names
2605 procedure Get_Exceptions (Kind : Source_Kind);
2607 procedure Get_Unit_Exceptions (Kind : Source_Kind);
2609 ----------------------
2610 -- Check_Unit_Names --
2611 ----------------------
2613 procedure Check_Unit_Names (List : Array_Element_Id) is
2614 Current : Array_Element_Id;
2615 Element : Array_Element;
2616 Unit_Name : Name_Id;
2619 -- Loop through elements of the string list
2622 while Current /= No_Array_Element loop
2623 Element := In_Tree.Array_Elements.Table (Current);
2625 -- Put file name in canonical case
2627 if not Osint.File_Names_Case_Sensitive then
2628 Get_Name_String (Element.Value.Value);
2629 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2630 Element.Value.Value := Name_Find;
2633 -- Check that it contains a valid unit name
2635 Get_Name_String (Element.Index);
2636 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
2638 if Unit_Name = No_Name then
2639 Err_Vars.Error_Msg_Name_1 := Element.Index;
2642 "%% is not a valid unit name.",
2643 Element.Value.Location);
2646 if Current_Verbosity = High then
2647 Write_Str (" Unit (""");
2648 Write_Str (Get_Name_String (Unit_Name));
2652 Element.Index := Unit_Name;
2653 In_Tree.Array_Elements.Table (Current) := Element;
2656 Current := Element.Next;
2658 end Check_Unit_Names;
2660 --------------------
2661 -- Get_Exceptions --
2662 --------------------
2664 procedure Get_Exceptions (Kind : Source_Kind) is
2665 Exceptions : Array_Element_Id;
2666 Exception_List : Variable_Value;
2667 Element_Id : String_List_Id;
2668 Element : String_Element;
2669 File_Name : File_Name_Type;
2670 Lang_Id : Language_Index;
2672 Lang_Kind : Language_Kind;
2679 (Name_Implementation_Exceptions,
2680 In_Arrays => Naming.Decl.Arrays,
2681 In_Tree => In_Tree);
2686 (Name_Specification_Exceptions,
2687 In_Arrays => Naming.Decl.Arrays,
2688 In_Tree => In_Tree);
2691 Lang_Id := Data.First_Language_Processing;
2692 while Lang_Id /= No_Language_Index loop
2693 if In_Tree.Languages_Data.Table (Lang_Id).Config.Kind =
2696 Lang := In_Tree.Languages_Data.Table (Lang_Id).Name;
2698 In_Tree.Languages_Data.Table (Lang_Id).Config.Kind;
2700 Exception_List := Value_Of
2702 In_Array => Exceptions,
2703 In_Tree => In_Tree);
2705 if Exception_List /= Nil_Variable_Value then
2706 Element_Id := Exception_List.Values;
2707 while Element_Id /= Nil_String loop
2708 Element := In_Tree.String_Elements.Table (Element_Id);
2710 if Osint.File_Names_Case_Sensitive then
2711 File_Name := File_Name_Type (Element.Value);
2713 Get_Name_String (Element.Value);
2714 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2715 File_Name := Name_Find;
2718 Source := Data.First_Source;
2719 while Source /= No_Source
2721 In_Tree.Sources.Table (Source).File /= File_Name
2724 In_Tree.Sources.Table (Source).Next_In_Project;
2727 if Source = No_Source then
2736 File_Name => File_Name,
2737 Display_File => File_Name_Type (Element.Value),
2738 Naming_Exception => True,
2739 Lang_Kind => Lang_Kind);
2742 -- Check if the file name is already recorded for
2743 -- another language or another kind.
2746 In_Tree.Sources.Table (Source).Language /= Lang_Id
2751 "the same file cannot be a source " &
2755 elsif In_Tree.Sources.Table (Source).Kind /= Kind then
2759 "the same file cannot be a source " &
2764 -- If the file is already recorded for the same
2765 -- language and the same kind, it means that the file
2766 -- name appears several times in the *_Exceptions
2767 -- attribute; so there is nothing to do.
2771 Element_Id := Element.Next;
2776 Lang_Id := In_Tree.Languages_Data.Table (Lang_Id).Next;
2780 -------------------------
2781 -- Get_Unit_Exceptions --
2782 -------------------------
2784 procedure Get_Unit_Exceptions (Kind : Source_Kind) is
2785 Exceptions : Array_Element_Id;
2786 Element : Array_Element;
2789 File_Name : File_Name_Type;
2790 Lang_Id : constant Language_Index :=
2791 Data.Unit_Based_Language_Index;
2792 Lang : constant Name_Id :=
2793 Data.Unit_Based_Language_Name;
2796 Source_To_Replace : Source_Id := No_Source;
2798 Other_Project : Project_Id;
2799 Other_Part : Source_Id := No_Source;
2802 if Lang_Id = No_Language_Index or else Lang = No_Name then
2807 Exceptions := Value_Of
2809 In_Arrays => Naming.Decl.Arrays,
2810 In_Tree => In_Tree);
2812 if Exceptions = No_Array_Element then
2815 (Name_Implementation,
2816 In_Arrays => Naming.Decl.Arrays,
2817 In_Tree => In_Tree);
2824 In_Arrays => Naming.Decl.Arrays,
2825 In_Tree => In_Tree);
2827 if Exceptions = No_Array_Element then
2828 Exceptions := Value_Of
2829 (Name_Specification,
2830 In_Arrays => Naming.Decl.Arrays,
2831 In_Tree => In_Tree);
2836 while Exceptions /= No_Array_Element loop
2837 Element := In_Tree.Array_Elements.Table (Exceptions);
2839 if Osint.File_Names_Case_Sensitive then
2840 File_Name := File_Name_Type (Element.Value.Value);
2842 Get_Name_String (Element.Value.Value);
2843 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2844 File_Name := Name_Find;
2847 Get_Name_String (Element.Index);
2848 To_Lower (Name_Buffer (1 .. Name_Len));
2851 Index := Element.Value.Index;
2853 -- For Ada, check if it is a valid unit name
2855 if Lang = Name_Ada then
2856 Get_Name_String (Element.Index);
2857 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2859 if Unit = No_Name then
2860 Err_Vars.Error_Msg_Name_1 := Element.Index;
2863 "%% is not a valid unit name.",
2864 Element.Value.Location);
2868 if Unit /= No_Name then
2870 -- Check if the source already exists
2872 Source := In_Tree.First_Source;
2873 Source_To_Replace := No_Source;
2875 while Source /= No_Source and then
2876 (In_Tree.Sources.Table (Source).Unit /= Unit or else
2877 In_Tree.Sources.Table (Source).Index /= Index)
2879 Source := In_Tree.Sources.Table (Source).Next_In_Sources;
2882 if Source /= No_Source then
2883 if In_Tree.Sources.Table (Source).Kind /= Kind then
2884 Other_Part := Source;
2888 In_Tree.Sources.Table (Source).Next_In_Sources;
2890 exit when Source = No_Source or else
2891 (In_Tree.Sources.Table (Source).Unit = Unit
2893 In_Tree.Sources.Table (Source).Index = Index);
2897 if Source /= No_Source then
2898 Other_Project := In_Tree.Sources.Table (Source).Project;
2900 if Is_Extending (Project, Other_Project, In_Tree) then
2902 In_Tree.Sources.Table (Source).Other_Part;
2904 -- Record the source to be removed
2906 Source_To_Replace := Source;
2907 Source := No_Source;
2910 Error_Msg_Name_1 := Unit;
2912 In_Tree.Projects.Table (Other_Project).Name;
2916 "%% is already a source of project %%",
2917 Element.Value.Location);
2922 if Source = No_Source then
2931 File_Name => File_Name,
2932 Display_File => File_Name_Type (Element.Value.Value),
2933 Lang_Kind => Unit_Based,
2934 Other_Part => Other_Part,
2937 Naming_Exception => True,
2938 Source_To_Replace => Source_To_Replace);
2942 Exceptions := Element.Next;
2945 end Get_Unit_Exceptions;
2947 -- Start of processing for Check_Naming_Schemes
2950 if Get_Mode = Ada_Only then
2952 -- If there is a package Naming, we will put in Data.Naming what is
2953 -- in this package Naming.
2955 if Naming_Id /= No_Package then
2956 Naming := In_Tree.Packages.Table (Naming_Id);
2958 if Current_Verbosity = High then
2959 Write_Line ("Checking ""Naming"" for Ada.");
2963 Bodies : constant Array_Element_Id :=
2965 (Name_Body, Naming.Decl.Arrays, In_Tree);
2967 Specs : constant Array_Element_Id :=
2969 (Name_Spec, Naming.Decl.Arrays, In_Tree);
2972 if Bodies /= No_Array_Element then
2974 -- We have elements in the array Body_Part
2976 if Current_Verbosity = High then
2977 Write_Line ("Found Bodies.");
2980 Data.Naming.Bodies := Bodies;
2981 Check_Unit_Names (Bodies);
2984 if Current_Verbosity = High then
2985 Write_Line ("No Bodies.");
2989 if Specs /= No_Array_Element then
2991 -- We have elements in the array Specs
2993 if Current_Verbosity = High then
2994 Write_Line ("Found Specs.");
2997 Data.Naming.Specs := Specs;
2998 Check_Unit_Names (Specs);
3001 if Current_Verbosity = High then
3002 Write_Line ("No Specs.");
3007 -- We are now checking if variables Dot_Replacement, Casing,
3008 -- Spec_Suffix, Body_Suffix and/or Separate_Suffix exist.
3010 -- For each variable, if it does not exist, we do nothing,
3011 -- because we already have the default.
3013 -- Check Dot_Replacement
3016 Dot_Replacement : constant Variable_Value :=
3018 (Name_Dot_Replacement,
3019 Naming.Decl.Attributes, In_Tree);
3022 pragma Assert (Dot_Replacement.Kind = Single,
3023 "Dot_Replacement is not a single string");
3025 if not Dot_Replacement.Default then
3026 Get_Name_String (Dot_Replacement.Value);
3028 if Name_Len = 0 then
3031 "Dot_Replacement cannot be empty",
3032 Dot_Replacement.Location);
3035 if Osint.File_Names_Case_Sensitive then
3036 Data.Naming.Dot_Replacement :=
3037 File_Name_Type (Dot_Replacement.Value);
3039 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3040 Data.Naming.Dot_Replacement := Name_Find;
3042 Data.Naming.Dot_Repl_Loc := Dot_Replacement.Location;
3047 if Current_Verbosity = High then
3048 Write_Str (" Dot_Replacement = """);
3049 Write_Str (Get_Name_String (Data.Naming.Dot_Replacement));
3057 Casing_String : constant Variable_Value :=
3060 Naming.Decl.Attributes,
3064 pragma Assert (Casing_String.Kind = Single,
3065 "Casing is not a single string");
3067 if not Casing_String.Default then
3069 Casing_Image : constant String :=
3070 Get_Name_String (Casing_String.Value);
3073 Casing_Value : constant Casing_Type :=
3074 Value (Casing_Image);
3076 Data.Naming.Casing := Casing_Value;
3080 when Constraint_Error =>
3081 if Casing_Image'Length = 0 then
3084 "Casing cannot be an empty string",
3085 Casing_String.Location);
3088 Name_Len := Casing_Image'Length;
3089 Name_Buffer (1 .. Name_Len) := Casing_Image;
3090 Err_Vars.Error_Msg_Name_1 := Name_Find;
3093 "%% is not a correct Casing",
3094 Casing_String.Location);
3100 if Current_Verbosity = High then
3101 Write_Str (" Casing = ");
3102 Write_Str (Image (Data.Naming.Casing));
3107 -- Check Spec_Suffix
3110 Ada_Spec_Suffix : constant Variable_Value :=
3114 In_Array => Data.Naming.Spec_Suffix,
3115 In_Tree => In_Tree);
3118 if Ada_Spec_Suffix.Kind = Single
3119 and then Get_Name_String (Ada_Spec_Suffix.Value) /= ""
3121 Get_Name_String (Ada_Spec_Suffix.Value);
3122 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3123 Set_Spec_Suffix (In_Tree, "ada", Data.Naming, Name_Find);
3124 Data.Naming.Ada_Spec_Suffix_Loc := Ada_Spec_Suffix.Location;
3131 Default_Ada_Spec_Suffix);
3135 if Current_Verbosity = High then
3136 Write_Str (" Spec_Suffix = """);
3137 Write_Str (Spec_Suffix_Of (In_Tree, "ada", Data.Naming));
3142 -- Check Body_Suffix
3145 Ada_Body_Suffix : constant Variable_Value :=
3149 In_Array => Data.Naming.Body_Suffix,
3150 In_Tree => In_Tree);
3153 if Ada_Body_Suffix.Kind = Single
3154 and then Get_Name_String (Ada_Body_Suffix.Value) /= ""
3156 Get_Name_String (Ada_Body_Suffix.Value);
3157 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3158 Set_Body_Suffix (In_Tree, "ada", Data.Naming, Name_Find);
3159 Data.Naming.Ada_Body_Suffix_Loc := Ada_Body_Suffix.Location;
3166 Default_Ada_Body_Suffix);
3170 if Current_Verbosity = High then
3171 Write_Str (" Body_Suffix = """);
3172 Write_Str (Body_Suffix_Of (In_Tree, "ada", Data.Naming));
3177 -- Check Separate_Suffix
3180 Ada_Sep_Suffix : constant Variable_Value :=
3182 (Variable_Name => Name_Separate_Suffix,
3183 In_Variables => Naming.Decl.Attributes,
3184 In_Tree => In_Tree);
3187 if Ada_Sep_Suffix.Default then
3188 Data.Naming.Separate_Suffix :=
3189 Body_Suffix_Id_Of (In_Tree, Name_Ada, Data.Naming);
3192 Get_Name_String (Ada_Sep_Suffix.Value);
3194 if Name_Len = 0 then
3197 "Separate_Suffix cannot be empty",
3198 Ada_Sep_Suffix.Location);
3201 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3202 Data.Naming.Separate_Suffix := Name_Find;
3203 Data.Naming.Sep_Suffix_Loc := Ada_Sep_Suffix.Location;
3208 if Current_Verbosity = High then
3209 Write_Str (" Separate_Suffix = """);
3210 Write_Str (Get_Name_String (Data.Naming.Separate_Suffix));
3215 -- Check if Data.Naming is valid
3217 Check_Ada_Naming_Scheme_Validity (Project, In_Tree, Data.Naming);
3220 elsif not In_Configuration then
3222 -- Look into package Naming, if there is one
3224 if Naming_Id /= No_Package then
3225 Naming := In_Tree.Packages.Table (Naming_Id);
3227 if Current_Verbosity = High then
3228 Write_Line ("Checking package Naming.");
3231 -- We are now checking if attribute Dot_Replacement, Casing,
3232 -- and/or Separate_Suffix exist.
3234 -- For each attribute, if it does not exist, we do nothing,
3235 -- because we already have the default.
3236 -- Otherwise, for all unit-based languages, we put the declared
3237 -- value in the language config.
3240 Dot_Repl : constant Variable_Value :=
3242 (Name_Dot_Replacement,
3243 Naming.Decl.Attributes, In_Tree);
3244 Dot_Replacement : File_Name_Type := No_File;
3246 Casing_String : constant Variable_Value :=
3249 Naming.Decl.Attributes,
3251 Casing : Casing_Type;
3252 Casing_Defined : Boolean := False;
3254 Sep_Suffix : constant Variable_Value :=
3256 (Variable_Name => Name_Separate_Suffix,
3257 In_Variables => Naming.Decl.Attributes,
3258 In_Tree => In_Tree);
3259 Separate_Suffix : File_Name_Type := No_File;
3261 Lang_Id : Language_Index;
3263 -- Check attribute Dot_Replacement
3265 if not Dot_Repl.Default then
3266 Get_Name_String (Dot_Repl.Value);
3268 if Name_Len = 0 then
3271 "Dot_Replacement cannot be empty",
3275 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3276 Dot_Replacement := Name_Find;
3278 if Current_Verbosity = High then
3279 Write_Str (" Dot_Replacement = """);
3280 Write_Str (Get_Name_String (Dot_Replacement));
3287 -- Check attribute Casing
3289 if not Casing_String.Default then
3291 Casing_Image : constant String :=
3292 Get_Name_String (Casing_String.Value);
3295 Casing_Value : constant Casing_Type :=
3296 Value (Casing_Image);
3298 Casing := Casing_Value;
3299 Casing_Defined := True;
3301 if Current_Verbosity = High then
3302 Write_Str (" Casing = ");
3303 Write_Str (Image (Casing));
3310 when Constraint_Error =>
3311 if Casing_Image'Length = 0 then
3314 "Casing cannot be an empty string",
3315 Casing_String.Location);
3318 Name_Len := Casing_Image'Length;
3319 Name_Buffer (1 .. Name_Len) := Casing_Image;
3320 Err_Vars.Error_Msg_Name_1 := Name_Find;
3323 "%% is not a correct Casing",
3324 Casing_String.Location);
3329 if not Sep_Suffix.Default then
3330 Get_Name_String (Sep_Suffix.Value);
3332 if Name_Len = 0 then
3335 "Separate_Suffix cannot be empty",
3336 Sep_Suffix.Location);
3339 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
3340 Separate_Suffix := Name_Find;
3342 if Current_Verbosity = High then
3343 Write_Str (" Separate_Suffix = """);
3344 Write_Str (Get_Name_String (Separate_Suffix));
3351 -- For all unit based languages, if any, set the specified
3352 -- value of Dot_Replacement, Casing and/or Separate_Suffix.
3354 if Dot_Replacement /= No_File
3355 or else Casing_Defined
3356 or else Separate_Suffix /= No_File
3358 Lang_Id := Data.First_Language_Processing;
3359 while Lang_Id /= No_Language_Index loop
3360 if In_Tree.Languages_Data.Table
3361 (Lang_Id).Config.Kind = Unit_Based
3363 if Dot_Replacement /= No_File then
3364 In_Tree.Languages_Data.Table
3365 (Lang_Id).Config.Naming_Data.Dot_Replacement :=
3369 if Casing_Defined then
3370 In_Tree.Languages_Data.Table
3371 (Lang_Id).Config.Naming_Data.Casing := Casing;
3374 if Separate_Suffix /= No_File then
3375 In_Tree.Languages_Data.Table
3376 (Lang_Id).Config.Naming_Data.Separate_Suffix :=
3382 In_Tree.Languages_Data.Table (Lang_Id).Next;
3387 -- Next, get the spec and body suffixes
3390 Suffix : Variable_Value;
3391 Lang_Id : Language_Index;
3395 Lang_Id := Data.First_Language_Processing;
3396 while Lang_Id /= No_Language_Index loop
3397 Lang := In_Tree.Languages_Data.Table (Lang_Id).Name;
3403 Attribute_Or_Array_Name => Name_Spec_Suffix,
3404 In_Package => Naming_Id,
3405 In_Tree => In_Tree);
3407 if Suffix = Nil_Variable_Value then
3410 Attribute_Or_Array_Name => Name_Specification_Suffix,
3411 In_Package => Naming_Id,
3412 In_Tree => In_Tree);
3415 if Suffix /= Nil_Variable_Value then
3416 In_Tree.Languages_Data.Table (Lang_Id).
3417 Config.Naming_Data.Spec_Suffix :=
3418 File_Name_Type (Suffix.Value);
3425 Attribute_Or_Array_Name => Name_Body_Suffix,
3426 In_Package => Naming_Id,
3427 In_Tree => In_Tree);
3429 if Suffix = Nil_Variable_Value then
3432 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3433 In_Package => Naming_Id,
3434 In_Tree => In_Tree);
3437 if Suffix /= Nil_Variable_Value then
3438 In_Tree.Languages_Data.Table (Lang_Id).
3439 Config.Naming_Data.Body_Suffix :=
3440 File_Name_Type (Suffix.Value);
3443 Lang_Id := In_Tree.Languages_Data.Table (Lang_Id).Next;
3447 -- Get the exceptions for file based languages
3449 Get_Exceptions (Spec);
3450 Get_Exceptions (Impl);
3452 -- Get the exceptions for unit based languages
3454 Get_Unit_Exceptions (Spec);
3455 Get_Unit_Exceptions (Impl);
3459 end Check_Naming_Schemes;
3461 ------------------------------
3462 -- Check_Library_Attributes --
3463 ------------------------------
3465 procedure Check_Library_Attributes
3466 (Project : Project_Id;
3467 In_Tree : Project_Tree_Ref;
3468 Current_Dir : String;
3469 Data : in out Project_Data)
3471 Attributes : constant Prj.Variable_Id := Data.Decl.Attributes;
3473 Lib_Dir : constant Prj.Variable_Value :=
3475 (Snames.Name_Library_Dir, Attributes, In_Tree);
3477 Lib_Name : constant Prj.Variable_Value :=
3479 (Snames.Name_Library_Name, Attributes, In_Tree);
3481 Lib_Version : constant Prj.Variable_Value :=
3483 (Snames.Name_Library_Version, Attributes, In_Tree);
3485 Lib_ALI_Dir : constant Prj.Variable_Value :=
3487 (Snames.Name_Library_Ali_Dir, Attributes, In_Tree);
3489 The_Lib_Kind : constant Prj.Variable_Value :=
3491 (Snames.Name_Library_Kind, Attributes, In_Tree);
3493 Imported_Project_List : Project_List := Empty_Project_List;
3495 Continuation : String_Access := No_Continuation_String'Access;
3497 Support_For_Libraries : Library_Support;
3499 Library_Directory_Present : Boolean;
3501 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3502 -- Check if an imported or extended project if also a library project
3508 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3509 Proj_Data : Project_Data;
3514 if Proj /= No_Project then
3515 Proj_Data := In_Tree.Projects.Table (Proj);
3517 if not Proj_Data.Library then
3519 -- The only not library projects that are OK are those that
3520 -- have no sources. However, header files from non-Ada
3521 -- languages are OK, as there is nothing to compile.
3523 Src_Id := Proj_Data.First_Source;
3524 while Src_Id /= No_Source loop
3525 Src := In_Tree.Sources.Table (Src_Id);
3527 exit when Src.Lang_Kind /= File_Based
3528 or else Src.Kind /= Spec;
3530 Src_Id := Src.Next_In_Project;
3533 if Src_Id /= No_Source then
3534 Error_Msg_Name_1 := Data.Name;
3535 Error_Msg_Name_2 := Proj_Data.Name;
3538 if Data.Library_Kind /= Static then
3542 "shared library project %% cannot extend " &
3543 "project %% that is not a library project",
3545 Continuation := Continuation_String'Access;
3548 elsif Data.Library_Kind /= Static then
3552 "shared library project %% cannot import project %% " &
3553 "that is not a shared library project",
3555 Continuation := Continuation_String'Access;
3559 elsif Data.Library_Kind /= Static and then
3560 Proj_Data.Library_Kind = Static
3562 Error_Msg_Name_1 := Data.Name;
3563 Error_Msg_Name_2 := Proj_Data.Name;
3569 "shared library project %% cannot extend static " &
3570 "library project %%",
3577 "shared library project %% cannot import static " &
3578 "library project %%",
3582 Continuation := Continuation_String'Access;
3587 -- Start of processing for Check_Library_Attributes
3590 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3592 -- Special case of extending project
3594 if Data.Extends /= No_Project then
3596 Extended_Data : constant Project_Data :=
3597 In_Tree.Projects.Table (Data.Extends);
3600 -- If the project extended is a library project, we inherit the
3601 -- library name, if it is not redefined; we check that the library
3602 -- directory is specified.
3604 if Extended_Data.Library then
3605 if Data.Qualifier = Standard then
3608 "a standard project cannot extend a library project",
3612 if Lib_Name.Default then
3613 Data.Library_Name := Extended_Data.Library_Name;
3616 if Lib_Dir.Default then
3617 if not Data.Virtual then
3620 "a project extending a library project must " &
3621 "specify an attribute Library_Dir",
3625 -- For a virtual project extending a library project,
3626 -- inherit library directory.
3628 Data.Library_Dir := Extended_Data.Library_Dir;
3629 Library_Directory_Present := True;
3637 pragma Assert (Lib_Name.Kind = Single);
3639 if Lib_Name.Value = Empty_String then
3640 if Current_Verbosity = High
3641 and then Data.Library_Name = No_Name
3643 Write_Line ("No library name");
3647 -- There is no restriction on the syntax of library names
3649 Data.Library_Name := Lib_Name.Value;
3652 if Data.Library_Name /= No_Name then
3653 if Current_Verbosity = High then
3654 Write_Str ("Library name = """);
3655 Write_Str (Get_Name_String (Data.Library_Name));
3659 pragma Assert (Lib_Dir.Kind = Single);
3661 if not Library_Directory_Present then
3662 if Current_Verbosity = High then
3663 Write_Line ("No library directory");
3667 -- Find path name (unless inherited), check that it is a directory
3669 if Data.Library_Dir = No_Path_Information then
3673 File_Name_Type (Lib_Dir.Value),
3674 Data.Directory.Display_Name,
3675 Data.Library_Dir.Name,
3676 Data.Library_Dir.Display_Name,
3677 Create => "library",
3678 Current_Dir => Current_Dir,
3679 Location => Lib_Dir.Location);
3682 if Data.Library_Dir = No_Path_Information then
3684 -- Get the absolute name of the library directory that
3685 -- does not exist, to report an error.
3688 Dir_Name : constant String :=
3689 Get_Name_String (Lib_Dir.Value);
3692 if Is_Absolute_Path (Dir_Name) then
3693 Err_Vars.Error_Msg_File_1 :=
3694 File_Name_Type (Lib_Dir.Value);
3697 Get_Name_String (Data.Directory.Display_Name);
3699 if Name_Buffer (Name_Len) /= Directory_Separator then
3700 Name_Len := Name_Len + 1;
3701 Name_Buffer (Name_Len) := Directory_Separator;
3705 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3707 Name_Len := Name_Len + Dir_Name'Length;
3708 Err_Vars.Error_Msg_File_1 := Name_Find;
3715 "library directory { does not exist",
3719 -- The library directory cannot be the same as the Object
3722 elsif Data.Library_Dir.Name = Data.Object_Directory.Name then
3725 "library directory cannot be the same " &
3726 "as object directory",
3728 Data.Library_Dir := No_Path_Information;
3732 OK : Boolean := True;
3733 Dirs_Id : String_List_Id;
3734 Dir_Elem : String_Element;
3737 -- The library directory cannot be the same as a source
3738 -- directory of the current project.
3740 Dirs_Id := Data.Source_Dirs;
3741 while Dirs_Id /= Nil_String loop
3742 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3743 Dirs_Id := Dir_Elem.Next;
3746 Data.Library_Dir.Name = Path_Name_Type (Dir_Elem.Value)
3748 Err_Vars.Error_Msg_File_1 :=
3749 File_Name_Type (Dir_Elem.Value);
3752 "library directory cannot be the same " &
3753 "as source directory {",
3762 -- The library directory cannot be the same as a source
3763 -- directory of another project either.
3766 for Pid in 1 .. Project_Table.Last (In_Tree.Projects) loop
3767 if Pid /= Project then
3768 Dirs_Id := In_Tree.Projects.Table (Pid).Source_Dirs;
3770 Dir_Loop : while Dirs_Id /= Nil_String loop
3772 In_Tree.String_Elements.Table (Dirs_Id);
3773 Dirs_Id := Dir_Elem.Next;
3775 if Data.Library_Dir.Name =
3776 Path_Name_Type (Dir_Elem.Value)
3778 Err_Vars.Error_Msg_File_1 :=
3779 File_Name_Type (Dir_Elem.Value);
3780 Err_Vars.Error_Msg_Name_1 :=
3781 In_Tree.Projects.Table (Pid).Name;
3785 "library directory cannot be the same " &
3786 "as source directory { of project %%",
3793 end loop Project_Loop;
3797 Data.Library_Dir := No_Path_Information;
3799 elsif Current_Verbosity = High then
3801 -- Display the Library directory in high verbosity
3803 Write_Str ("Library directory =""");
3805 (Get_Name_String (Data.Library_Dir.Display_Name));
3815 Data.Library_Dir /= No_Path_Information
3817 Data.Library_Name /= No_Name;
3819 if Data.Extends = No_Project then
3820 case Data.Qualifier is
3822 if Data.Library then
3825 "a standard project cannot be a library project",
3830 if not Data.Library then
3833 "not a library project",
3843 if Data.Library then
3844 if Get_Mode = Multi_Language then
3845 Support_For_Libraries := Data.Config.Lib_Support;
3848 Support_For_Libraries := MLib.Tgt.Support_For_Libraries;
3851 if Support_For_Libraries = Prj.None then
3854 "?libraries are not supported on this platform",
3856 Data.Library := False;
3859 if Lib_ALI_Dir.Value = Empty_String then
3860 if Current_Verbosity = High then
3861 Write_Line ("No library ALI directory specified");
3863 Data.Library_ALI_Dir := Data.Library_Dir;
3866 -- Find path name, check that it is a directory
3871 File_Name_Type (Lib_ALI_Dir.Value),
3872 Data.Directory.Display_Name,
3873 Data.Library_ALI_Dir.Name,
3874 Data.Library_ALI_Dir.Display_Name,
3875 Create => "library ALI",
3876 Current_Dir => Current_Dir,
3877 Location => Lib_ALI_Dir.Location);
3879 if Data.Library_ALI_Dir = No_Path_Information then
3881 -- Get the absolute name of the library ALI directory that
3882 -- does not exist, to report an error.
3885 Dir_Name : constant String :=
3886 Get_Name_String (Lib_ALI_Dir.Value);
3889 if Is_Absolute_Path (Dir_Name) then
3890 Err_Vars.Error_Msg_File_1 :=
3891 File_Name_Type (Lib_Dir.Value);
3894 Get_Name_String (Data.Directory.Display_Name);
3896 if Name_Buffer (Name_Len) /= Directory_Separator then
3897 Name_Len := Name_Len + 1;
3898 Name_Buffer (Name_Len) := Directory_Separator;
3902 (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
3904 Name_Len := Name_Len + Dir_Name'Length;
3905 Err_Vars.Error_Msg_File_1 := Name_Find;
3912 "library 'A'L'I directory { does not exist",
3913 Lib_ALI_Dir.Location);
3917 if Data.Library_ALI_Dir /= Data.Library_Dir then
3919 -- The library ALI directory cannot be the same as the
3920 -- Object directory.
3922 if Data.Library_ALI_Dir = Data.Object_Directory then
3925 "library 'A'L'I directory cannot be the same " &
3926 "as object directory",
3927 Lib_ALI_Dir.Location);
3928 Data.Library_ALI_Dir := No_Path_Information;
3932 OK : Boolean := True;
3933 Dirs_Id : String_List_Id;
3934 Dir_Elem : String_Element;
3937 -- The library ALI directory cannot be the same as
3938 -- a source directory of the current project.
3940 Dirs_Id := Data.Source_Dirs;
3941 while Dirs_Id /= Nil_String loop
3942 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3943 Dirs_Id := Dir_Elem.Next;
3945 if Data.Library_ALI_Dir.Name =
3946 Path_Name_Type (Dir_Elem.Value)
3948 Err_Vars.Error_Msg_File_1 :=
3949 File_Name_Type (Dir_Elem.Value);
3952 "library 'A'L'I directory cannot be " &
3953 "the same as source directory {",
3954 Lib_ALI_Dir.Location);
3962 -- The library ALI directory cannot be the same as
3963 -- a source directory of another project either.
3967 Pid in 1 .. Project_Table.Last (In_Tree.Projects)
3969 if Pid /= Project then
3971 In_Tree.Projects.Table (Pid).Source_Dirs;
3974 while Dirs_Id /= Nil_String loop
3976 In_Tree.String_Elements.Table (Dirs_Id);
3977 Dirs_Id := Dir_Elem.Next;
3979 if Data.Library_ALI_Dir.Name =
3980 Path_Name_Type (Dir_Elem.Value)
3982 Err_Vars.Error_Msg_File_1 :=
3983 File_Name_Type (Dir_Elem.Value);
3984 Err_Vars.Error_Msg_Name_1 :=
3985 In_Tree.Projects.Table (Pid).Name;
3989 "library 'A'L'I directory cannot " &
3990 "be the same as source directory " &
3992 Lib_ALI_Dir.Location);
3994 exit ALI_Project_Loop;
3996 end loop ALI_Dir_Loop;
3998 end loop ALI_Project_Loop;
4002 Data.Library_ALI_Dir := No_Path_Information;
4004 elsif Current_Verbosity = High then
4006 -- Display the Library ALI directory in high
4009 Write_Str ("Library ALI directory =""");
4012 (Data.Library_ALI_Dir.Display_Name));
4020 pragma Assert (Lib_Version.Kind = Single);
4022 if Lib_Version.Value = Empty_String then
4023 if Current_Verbosity = High then
4024 Write_Line ("No library version specified");
4028 Data.Lib_Internal_Name := Lib_Version.Value;
4031 pragma Assert (The_Lib_Kind.Kind = Single);
4033 if The_Lib_Kind.Value = Empty_String then
4034 if Current_Verbosity = High then
4035 Write_Line ("No library kind specified");
4039 Get_Name_String (The_Lib_Kind.Value);
4042 Kind_Name : constant String :=
4043 To_Lower (Name_Buffer (1 .. Name_Len));
4045 OK : Boolean := True;
4048 if Kind_Name = "static" then
4049 Data.Library_Kind := Static;
4051 elsif Kind_Name = "dynamic" then
4052 Data.Library_Kind := Dynamic;
4054 elsif Kind_Name = "relocatable" then
4055 Data.Library_Kind := Relocatable;
4060 "illegal value for Library_Kind",
4061 The_Lib_Kind.Location);
4065 if Current_Verbosity = High and then OK then
4066 Write_Str ("Library kind = ");
4067 Write_Line (Kind_Name);
4070 if Data.Library_Kind /= Static and then
4071 Support_For_Libraries = Prj.Static_Only
4075 "only static libraries are supported " &
4077 The_Lib_Kind.Location);
4078 Data.Library := False;
4083 if Data.Library then
4084 if Current_Verbosity = High then
4085 Write_Line ("This is a library project file");
4088 if Get_Mode = Multi_Language then
4089 Check_Library (Data.Extends, Extends => True);
4091 Imported_Project_List := Data.Imported_Projects;
4092 while Imported_Project_List /= Empty_Project_List loop
4094 (In_Tree.Project_Lists.Table
4095 (Imported_Project_List).Project,
4097 Imported_Project_List :=
4098 In_Tree.Project_Lists.Table
4099 (Imported_Project_List).Next;
4107 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4108 -- Warn if they are declared, as it is a common error to think that
4109 -- library are "linked" with Linker switches.
4111 if Data.Library then
4113 Linker_Package_Id : constant Package_Id :=
4115 (Name_Linker, Data.Decl.Packages, In_Tree);
4116 Linker_Package : Package_Element;
4117 Switches : Array_Element_Id := No_Array_Element;
4120 if Linker_Package_Id /= No_Package then
4121 Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
4125 (Name => Name_Switches,
4126 In_Arrays => Linker_Package.Decl.Arrays,
4127 In_Tree => In_Tree);
4129 if Switches = No_Array_Element then
4132 (Name => Name_Default_Switches,
4133 In_Arrays => Linker_Package.Decl.Arrays,
4134 In_Tree => In_Tree);
4137 if Switches /= No_Array_Element then
4140 "?Linker switches not taken into account in library " &
4148 if Data.Extends /= No_Project then
4149 In_Tree.Projects.Table (Data.Extends).Library := False;
4151 end Check_Library_Attributes;
4153 --------------------------
4154 -- Check_Package_Naming --
4155 --------------------------
4157 procedure Check_Package_Naming
4158 (Project : Project_Id;
4159 In_Tree : Project_Tree_Ref;
4160 Data : in out Project_Data)
4162 Naming_Id : constant Package_Id :=
4163 Util.Value_Of (Name_Naming, Data.Decl.Packages, In_Tree);
4165 Naming : Package_Element;
4168 -- If there is a package Naming, we will put in Data.Naming
4169 -- what is in this package Naming.
4171 if Naming_Id /= No_Package then
4172 Naming := In_Tree.Packages.Table (Naming_Id);
4174 if Current_Verbosity = High then
4175 Write_Line ("Checking ""Naming"".");
4178 -- Check Spec_Suffix
4181 Spec_Suffixs : Array_Element_Id :=
4187 Suffix : Array_Element_Id;
4188 Element : Array_Element;
4189 Suffix2 : Array_Element_Id;
4192 -- If some suffixes have been specified, we make sure that
4193 -- for each language for which a default suffix has been
4194 -- specified, there is a suffix specified, either the one
4195 -- in the project file or if there were none, the default.
4197 if Spec_Suffixs /= No_Array_Element then
4198 Suffix := Data.Naming.Spec_Suffix;
4200 while Suffix /= No_Array_Element loop
4202 In_Tree.Array_Elements.Table (Suffix);
4203 Suffix2 := Spec_Suffixs;
4205 while Suffix2 /= No_Array_Element loop
4206 exit when In_Tree.Array_Elements.Table
4207 (Suffix2).Index = Element.Index;
4208 Suffix2 := In_Tree.Array_Elements.Table
4212 -- There is a registered default suffix, but no
4213 -- suffix specified in the project file.
4214 -- Add the default to the array.
4216 if Suffix2 = No_Array_Element then
4217 Array_Element_Table.Increment_Last
4218 (In_Tree.Array_Elements);
4219 In_Tree.Array_Elements.Table
4220 (Array_Element_Table.Last
4221 (In_Tree.Array_Elements)) :=
4222 (Index => Element.Index,
4223 Src_Index => Element.Src_Index,
4224 Index_Case_Sensitive => False,
4225 Value => Element.Value,
4226 Next => Spec_Suffixs);
4227 Spec_Suffixs := Array_Element_Table.Last
4228 (In_Tree.Array_Elements);
4231 Suffix := Element.Next;
4234 -- Put the resulting array as the specification suffixes
4236 Data.Naming.Spec_Suffix := Spec_Suffixs;
4241 Current : Array_Element_Id;
4242 Element : Array_Element;
4245 Current := Data.Naming.Spec_Suffix;
4246 while Current /= No_Array_Element loop
4247 Element := In_Tree.Array_Elements.Table (Current);
4248 Get_Name_String (Element.Value.Value);
4250 if Name_Len = 0 then
4253 "Spec_Suffix cannot be empty",
4254 Element.Value.Location);
4257 In_Tree.Array_Elements.Table (Current) := Element;
4258 Current := Element.Next;
4262 -- Check Body_Suffix
4265 Impl_Suffixs : Array_Element_Id :=
4271 Suffix : Array_Element_Id;
4272 Element : Array_Element;
4273 Suffix2 : Array_Element_Id;
4276 -- If some suffixes have been specified, we make sure that
4277 -- for each language for which a default suffix has been
4278 -- specified, there is a suffix specified, either the one
4279 -- in the project file or if there were none, the default.
4281 if Impl_Suffixs /= No_Array_Element then
4282 Suffix := Data.Naming.Body_Suffix;
4283 while Suffix /= No_Array_Element loop
4285 In_Tree.Array_Elements.Table (Suffix);
4287 Suffix2 := Impl_Suffixs;
4288 while Suffix2 /= No_Array_Element loop
4289 exit when In_Tree.Array_Elements.Table
4290 (Suffix2).Index = Element.Index;
4291 Suffix2 := In_Tree.Array_Elements.Table
4295 -- There is a registered default suffix, but no suffix was
4296 -- specified in the project file. Add default to the array.
4298 if Suffix2 = No_Array_Element then
4299 Array_Element_Table.Increment_Last
4300 (In_Tree.Array_Elements);
4301 In_Tree.Array_Elements.Table
4302 (Array_Element_Table.Last
4303 (In_Tree.Array_Elements)) :=
4304 (Index => Element.Index,
4305 Src_Index => Element.Src_Index,
4306 Index_Case_Sensitive => False,
4307 Value => Element.Value,
4308 Next => Impl_Suffixs);
4309 Impl_Suffixs := Array_Element_Table.Last
4310 (In_Tree.Array_Elements);
4313 Suffix := Element.Next;
4316 -- Put the resulting array as the implementation suffixes
4318 Data.Naming.Body_Suffix := Impl_Suffixs;
4323 Current : Array_Element_Id;
4324 Element : Array_Element;
4327 Current := Data.Naming.Body_Suffix;
4328 while Current /= No_Array_Element loop
4329 Element := In_Tree.Array_Elements.Table (Current);
4330 Get_Name_String (Element.Value.Value);
4332 if Name_Len = 0 then
4335 "Body_Suffix cannot be empty",
4336 Element.Value.Location);
4339 In_Tree.Array_Elements.Table (Current) := Element;
4340 Current := Element.Next;
4344 -- Get the exceptions, if any
4346 Data.Naming.Specification_Exceptions :=
4348 (Name_Specification_Exceptions,
4349 In_Arrays => Naming.Decl.Arrays,
4350 In_Tree => In_Tree);
4352 Data.Naming.Implementation_Exceptions :=
4354 (Name_Implementation_Exceptions,
4355 In_Arrays => Naming.Decl.Arrays,
4356 In_Tree => In_Tree);
4358 end Check_Package_Naming;
4360 ---------------------------------
4361 -- Check_Programming_Languages --
4362 ---------------------------------
4364 procedure Check_Programming_Languages
4365 (In_Tree : Project_Tree_Ref;
4366 Project : Project_Id;
4367 Data : in out Project_Data)
4369 Languages : Variable_Value := Nil_Variable_Value;
4370 Def_Lang : Variable_Value := Nil_Variable_Value;
4371 Def_Lang_Id : Name_Id;
4374 Data.First_Language_Processing := No_Language_Index;
4376 Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes, In_Tree);
4379 (Name_Default_Language, Data.Decl.Attributes, In_Tree);
4380 Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
4381 Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
4383 if Data.Source_Dirs /= Nil_String then
4385 -- Check if languages are specified in this project
4387 if Languages.Default then
4389 -- Attribute Languages is not specified. So, it defaults to
4390 -- a project of the default language only.
4392 Name_List_Table.Increment_Last (In_Tree.Name_Lists);
4393 Data.Languages := Name_List_Table.Last (In_Tree.Name_Lists);
4395 -- In Ada_Only mode, the default language is Ada
4397 if Get_Mode = Ada_Only then
4398 In_Tree.Name_Lists.Table (Data.Languages) :=
4399 (Name => Name_Ada, Next => No_Name_List);
4401 -- Attribute Languages is not specified. So, it defaults to
4402 -- a project of language Ada only. No sources of languages
4405 Data.Other_Sources_Present := False;
4408 -- Fail if there is no default language defined
4410 if Def_Lang.Default then
4411 if not Default_Language_Is_Ada then
4415 "no languages defined for this project",
4417 Def_Lang_Id := No_Name;
4419 Def_Lang_Id := Name_Ada;
4423 Get_Name_String (Def_Lang.Value);
4424 To_Lower (Name_Buffer (1 .. Name_Len));
4425 Def_Lang_Id := Name_Find;
4428 if Def_Lang_Id /= No_Name then
4429 In_Tree.Name_Lists.Table (Data.Languages) :=
4430 (Name => Def_Lang_Id, Next => No_Name_List);
4432 Language_Data_Table.Increment_Last (In_Tree.Languages_Data);
4434 Data.First_Language_Processing :=
4435 Language_Data_Table.Last (In_Tree.Languages_Data);
4436 In_Tree.Languages_Data.Table
4437 (Data.First_Language_Processing) := No_Language_Data;
4438 In_Tree.Languages_Data.Table
4439 (Data.First_Language_Processing).Name := Def_Lang_Id;
4440 Get_Name_String (Def_Lang_Id);
4441 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4442 In_Tree.Languages_Data.Table
4443 (Data.First_Language_Processing).Display_Name := Name_Find;
4445 if Def_Lang_Id = Name_Ada then
4446 In_Tree.Languages_Data.Table
4447 (Data.First_Language_Processing).Config.Kind
4449 In_Tree.Languages_Data.Table
4450 (Data.First_Language_Processing).Config.Dependency_Kind
4452 Data.Unit_Based_Language_Name := Name_Ada;
4453 Data.Unit_Based_Language_Index :=
4454 Data.First_Language_Processing;
4456 In_Tree.Languages_Data.Table
4457 (Data.First_Language_Processing).Config.Kind
4465 Current : String_List_Id := Languages.Values;
4466 Element : String_Element;
4467 Lang_Name : Name_Id;
4468 Index : Language_Index;
4469 Lang_Data : Language_Data;
4470 NL_Id : Name_List_Index := No_Name_List;
4473 -- Assume there are no language declared
4475 Data.Ada_Sources_Present := False;
4476 Data.Other_Sources_Present := False;
4478 -- If there are no languages declared, there are no sources
4480 if Current = Nil_String then
4481 Data.Source_Dirs := Nil_String;
4483 if Data.Qualifier = Standard then
4487 "a standard project cannot have no language declared",
4488 Languages.Location);
4492 -- Look through all the languages specified in attribute
4495 while Current /= Nil_String loop
4497 In_Tree.String_Elements.Table (Current);
4498 Get_Name_String (Element.Value);
4499 To_Lower (Name_Buffer (1 .. Name_Len));
4500 Lang_Name := Name_Find;
4502 NL_Id := Data.Languages;
4503 while NL_Id /= No_Name_List loop
4505 Lang_Name = In_Tree.Name_Lists.Table (NL_Id).Name;
4506 NL_Id := In_Tree.Name_Lists.Table (NL_Id).Next;
4509 if NL_Id = No_Name_List then
4510 Name_List_Table.Increment_Last (In_Tree.Name_Lists);
4512 if Data.Languages = No_Name_List then
4514 Name_List_Table.Last (In_Tree.Name_Lists);
4517 NL_Id := Data.Languages;
4518 while In_Tree.Name_Lists.Table (NL_Id).Next /=
4521 NL_Id := In_Tree.Name_Lists.Table (NL_Id).Next;
4524 In_Tree.Name_Lists.Table (NL_Id).Next :=
4525 Name_List_Table.Last (In_Tree.Name_Lists);
4528 NL_Id := Name_List_Table.Last (In_Tree.Name_Lists);
4529 In_Tree.Name_Lists.Table (NL_Id) :=
4530 (Lang_Name, No_Name_List);
4532 if Get_Mode = Ada_Only then
4533 -- Check for language Ada
4535 if Lang_Name = Name_Ada then
4536 Data.Ada_Sources_Present := True;
4539 Data.Other_Sources_Present := True;
4543 Language_Data_Table.Increment_Last
4544 (In_Tree.Languages_Data);
4546 Language_Data_Table.Last (In_Tree.Languages_Data);
4547 Lang_Data.Name := Lang_Name;
4548 Lang_Data.Display_Name := Element.Value;
4549 Lang_Data.Next := Data.First_Language_Processing;
4551 if Lang_Name = Name_Ada then
4552 Lang_Data.Config.Kind := Unit_Based;
4553 Lang_Data.Config.Dependency_Kind := ALI_File;
4554 Data.Unit_Based_Language_Name := Name_Ada;
4555 Data.Unit_Based_Language_Index := Index;
4558 Lang_Data.Config.Kind := File_Based;
4559 Lang_Data.Config.Dependency_Kind := None;
4562 In_Tree.Languages_Data.Table (Index) := Lang_Data;
4563 Data.First_Language_Processing := Index;
4567 Current := Element.Next;
4573 end Check_Programming_Languages;
4579 function Check_Project
4581 Root_Project : Project_Id;
4582 In_Tree : Project_Tree_Ref;
4583 Extending : Boolean) return Boolean
4586 if P = Root_Project then
4589 elsif Extending then
4591 Data : Project_Data := In_Tree.Projects.Table (Root_Project);
4594 while Data.Extends /= No_Project loop
4595 if P = Data.Extends then
4599 Data := In_Tree.Projects.Table (Data.Extends);
4607 -------------------------------
4608 -- Check_Stand_Alone_Library --
4609 -------------------------------
4611 procedure Check_Stand_Alone_Library
4612 (Project : Project_Id;
4613 In_Tree : Project_Tree_Ref;
4614 Data : in out Project_Data;
4615 Current_Dir : String;
4616 Extending : Boolean)
4618 Lib_Interfaces : constant Prj.Variable_Value :=
4620 (Snames.Name_Library_Interface,
4621 Data.Decl.Attributes,
4624 Lib_Auto_Init : constant Prj.Variable_Value :=
4626 (Snames.Name_Library_Auto_Init,
4627 Data.Decl.Attributes,
4630 Lib_Src_Dir : constant Prj.Variable_Value :=
4632 (Snames.Name_Library_Src_Dir,
4633 Data.Decl.Attributes,
4636 Lib_Symbol_File : constant Prj.Variable_Value :=
4638 (Snames.Name_Library_Symbol_File,
4639 Data.Decl.Attributes,
4642 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4644 (Snames.Name_Library_Symbol_Policy,
4645 Data.Decl.Attributes,
4648 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4650 (Snames.Name_Library_Reference_Symbol_File,
4651 Data.Decl.Attributes,
4654 Auto_Init_Supported : Boolean;
4655 OK : Boolean := True;
4657 Next_Proj : Project_Id;
4660 if Get_Mode = Multi_Language then
4661 Auto_Init_Supported := Data.Config.Auto_Init_Supported;
4663 Auto_Init_Supported :=
4664 MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported;
4667 pragma Assert (Lib_Interfaces.Kind = List);
4669 -- It is a stand-alone library project file if attribute
4670 -- Library_Interface is defined.
4672 if not Lib_Interfaces.Default then
4673 SAL_Library : declare
4674 Interfaces : String_List_Id := Lib_Interfaces.Values;
4675 Interface_ALIs : String_List_Id := Nil_String;
4677 The_Unit_Id : Unit_Index;
4678 The_Unit_Data : Unit_Data;
4680 procedure Add_ALI_For (Source : File_Name_Type);
4681 -- Add an ALI file name to the list of Interface ALIs
4687 procedure Add_ALI_For (Source : File_Name_Type) is
4689 Get_Name_String (Source);
4692 ALI : constant String :=
4693 ALI_File_Name (Name_Buffer (1 .. Name_Len));
4694 ALI_Name_Id : Name_Id;
4697 Name_Len := ALI'Length;
4698 Name_Buffer (1 .. Name_Len) := ALI;
4699 ALI_Name_Id := Name_Find;
4701 String_Element_Table.Increment_Last
4702 (In_Tree.String_Elements);
4703 In_Tree.String_Elements.Table
4704 (String_Element_Table.Last
4705 (In_Tree.String_Elements)) :=
4706 (Value => ALI_Name_Id,
4708 Display_Value => ALI_Name_Id,
4710 In_Tree.String_Elements.Table
4711 (Interfaces).Location,
4713 Next => Interface_ALIs);
4714 Interface_ALIs := String_Element_Table.Last
4715 (In_Tree.String_Elements);
4719 -- Start of processing for SAL_Library
4722 Data.Standalone_Library := True;
4724 -- Library_Interface cannot be an empty list
4726 if Interfaces = Nil_String then
4729 "Library_Interface cannot be an empty list",
4730 Lib_Interfaces.Location);
4733 -- Process each unit name specified in the attribute
4734 -- Library_Interface.
4736 while Interfaces /= Nil_String loop
4738 (In_Tree.String_Elements.Table (Interfaces).Value);
4739 To_Lower (Name_Buffer (1 .. Name_Len));
4741 if Name_Len = 0 then
4744 "an interface cannot be an empty string",
4745 In_Tree.String_Elements.Table (Interfaces).Location);
4749 Error_Msg_Name_1 := Unit;
4751 if Get_Mode = Ada_Only then
4753 Units_Htable.Get (In_Tree.Units_HT, Unit);
4755 if The_Unit_Id = No_Unit_Index then
4759 In_Tree.String_Elements.Table
4760 (Interfaces).Location);
4763 -- Check that the unit is part of the project
4766 In_Tree.Units.Table (The_Unit_Id);
4768 if The_Unit_Data.File_Names (Body_Part).Name /= No_File
4769 and then The_Unit_Data.File_Names
4770 (Body_Part).Path.Name /= Slash
4773 (The_Unit_Data.File_Names (Body_Part).Project,
4774 Project, In_Tree, Extending)
4776 -- There is a body for this unit.
4777 -- If there is no spec, we need to check
4778 -- that it is not a subunit.
4780 if The_Unit_Data.File_Names
4781 (Specification).Name = No_File
4784 Src_Ind : Source_File_Index;
4787 Src_Ind := Sinput.P.Load_Project_File
4789 (The_Unit_Data.File_Names
4790 (Body_Part).Path.Name));
4792 if Sinput.P.Source_File_Is_Subunit
4797 "%% is a subunit; " &
4798 "it cannot be an interface",
4800 String_Elements.Table
4801 (Interfaces).Location);
4806 -- The unit is not a subunit, so we add
4807 -- to the Interface ALIs the ALI file
4808 -- corresponding to the body.
4811 (The_Unit_Data.File_Names (Body_Part).Name);
4816 "%% is not an unit of this project",
4817 In_Tree.String_Elements.Table
4818 (Interfaces).Location);
4821 elsif The_Unit_Data.File_Names
4822 (Specification).Name /= No_File
4823 and then The_Unit_Data.File_Names
4824 (Specification).Path.Name /= Slash
4825 and then Check_Project
4826 (The_Unit_Data.File_Names
4827 (Specification).Project,
4828 Project, In_Tree, Extending)
4831 -- The unit is part of the project, it has
4832 -- a spec, but no body. We add to the Interface
4833 -- ALIs the ALI file corresponding to the spec.
4836 (The_Unit_Data.File_Names (Specification).Name);
4841 "%% is not an unit of this project",
4842 In_Tree.String_Elements.Table
4843 (Interfaces).Location);
4848 -- Multi_Language mode
4850 Next_Proj := Data.Extends;
4851 Source := Data.First_Source;
4854 while Source /= No_Source and then
4855 In_Tree.Sources.Table (Source).Unit /= Unit
4858 In_Tree.Sources.Table (Source).Next_In_Project;
4861 exit when Source /= No_Source or else
4862 Next_Proj = No_Project;
4865 In_Tree.Projects.Table (Next_Proj).First_Source;
4867 In_Tree.Projects.Table (Next_Proj).Extends;
4870 if Source /= No_Source then
4871 if In_Tree.Sources.Table (Source).Kind = Sep then
4872 Source := No_Source;
4874 elsif In_Tree.Sources.Table (Source).Kind = Spec
4876 In_Tree.Sources.Table (Source).Other_Part /=
4879 Source := In_Tree.Sources.Table (Source).Other_Part;
4883 if Source /= No_Source then
4884 if In_Tree.Sources.Table (Source).Project /= Project
4888 In_Tree.Sources.Table (Source).Project,
4891 Source := No_Source;
4895 if Source = No_Source then
4898 "%% is not an unit of this project",
4899 In_Tree.String_Elements.Table
4900 (Interfaces).Location);
4903 if In_Tree.Sources.Table (Source).Kind = Spec and then
4904 In_Tree.Sources.Table (Source).Other_Part /=
4907 Source := In_Tree.Sources.Table (Source).Other_Part;
4910 String_Element_Table.Increment_Last
4911 (In_Tree.String_Elements);
4912 In_Tree.String_Elements.Table
4913 (String_Element_Table.Last
4914 (In_Tree.String_Elements)) :=
4916 Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
4919 Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
4921 In_Tree.String_Elements.Table
4922 (Interfaces).Location,
4924 Next => Interface_ALIs);
4925 Interface_ALIs := String_Element_Table.Last
4926 (In_Tree.String_Elements);
4934 In_Tree.String_Elements.Table (Interfaces).Next;
4937 -- Put the list of Interface ALIs in the project data
4939 Data.Lib_Interface_ALIs := Interface_ALIs;
4941 -- Check value of attribute Library_Auto_Init and set
4942 -- Lib_Auto_Init accordingly.
4944 if Lib_Auto_Init.Default then
4946 -- If no attribute Library_Auto_Init is declared, then set auto
4947 -- init only if it is supported.
4949 Data.Lib_Auto_Init := Auto_Init_Supported;
4952 Get_Name_String (Lib_Auto_Init.Value);
4953 To_Lower (Name_Buffer (1 .. Name_Len));
4955 if Name_Buffer (1 .. Name_Len) = "false" then
4956 Data.Lib_Auto_Init := False;
4958 elsif Name_Buffer (1 .. Name_Len) = "true" then
4959 if Auto_Init_Supported then
4960 Data.Lib_Auto_Init := True;
4963 -- Library_Auto_Init cannot be "true" if auto init is not
4968 "library auto init not supported " &
4970 Lib_Auto_Init.Location);
4976 "invalid value for attribute Library_Auto_Init",
4977 Lib_Auto_Init.Location);
4982 -- If attribute Library_Src_Dir is defined and not the empty string,
4983 -- check if the directory exist and is not the object directory or
4984 -- one of the source directories. This is the directory where copies
4985 -- of the interface sources will be copied. Note that this directory
4986 -- may be the library directory.
4988 if Lib_Src_Dir.Value /= Empty_String then
4990 Dir_Id : constant File_Name_Type :=
4991 File_Name_Type (Lib_Src_Dir.Value);
4998 Data.Directory.Display_Name,
4999 Data.Library_Src_Dir.Name,
5000 Data.Library_Src_Dir.Display_Name,
5001 Create => "library source copy",
5002 Current_Dir => Current_Dir,
5003 Location => Lib_Src_Dir.Location);
5005 -- If directory does not exist, report an error
5007 if Data.Library_Src_Dir = No_Path_Information then
5009 -- Get the absolute name of the library directory that does
5010 -- not exist, to report an error.
5013 Dir_Name : constant String :=
5014 Get_Name_String (Dir_Id);
5017 if Is_Absolute_Path (Dir_Name) then
5018 Err_Vars.Error_Msg_File_1 := Dir_Id;
5021 Get_Name_String (Data.Directory.Name);
5023 if Name_Buffer (Name_Len) /=
5026 Name_Len := Name_Len + 1;
5027 Name_Buffer (Name_Len) :=
5028 Directory_Separator;
5033 Name_Len + Dir_Name'Length) :=
5035 Name_Len := Name_Len + Dir_Name'Length;
5036 Err_Vars.Error_Msg_Name_1 := Name_Find;
5041 Error_Msg_File_1 := Dir_Id;
5044 "Directory { does not exist",
5045 Lib_Src_Dir.Location);
5048 -- Report error if it is the same as the object directory
5050 elsif Data.Library_Src_Dir = Data.Object_Directory then
5053 "directory to copy interfaces cannot be " &
5054 "the object directory",
5055 Lib_Src_Dir.Location);
5056 Data.Library_Src_Dir := No_Path_Information;
5060 Src_Dirs : String_List_Id;
5061 Src_Dir : String_Element;
5064 -- Interface copy directory cannot be one of the source
5065 -- directory of the current project.
5067 Src_Dirs := Data.Source_Dirs;
5068 while Src_Dirs /= Nil_String loop
5069 Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
5071 -- Report error if it is one of the source directories
5073 if Data.Library_Src_Dir.Name =
5074 Path_Name_Type (Src_Dir.Value)
5078 "directory to copy interfaces cannot " &
5079 "be one of the source directories",
5080 Lib_Src_Dir.Location);
5081 Data.Library_Src_Dir := No_Path_Information;
5085 Src_Dirs := Src_Dir.Next;
5088 if Data.Library_Src_Dir /= No_Path_Information then
5090 -- It cannot be a source directory of any other
5093 Project_Loop : for Pid in 1 ..
5094 Project_Table.Last (In_Tree.Projects)
5097 In_Tree.Projects.Table (Pid).Source_Dirs;
5098 Dir_Loop : while Src_Dirs /= Nil_String loop
5100 In_Tree.String_Elements.Table (Src_Dirs);
5102 -- Report error if it is one of the source
5105 if Data.Library_Src_Dir.Name =
5106 Path_Name_Type (Src_Dir.Value)
5109 File_Name_Type (Src_Dir.Value);
5111 In_Tree.Projects.Table (Pid).Name;
5114 "directory to copy interfaces cannot " &
5115 "be the same as source directory { of " &
5117 Lib_Src_Dir.Location);
5118 Data.Library_Src_Dir := No_Path_Information;
5122 Src_Dirs := Src_Dir.Next;
5124 end loop Project_Loop;
5128 -- In high verbosity, if there is a valid Library_Src_Dir,
5129 -- display its path name.
5131 if Data.Library_Src_Dir /= No_Path_Information
5132 and then Current_Verbosity = High
5134 Write_Str ("Directory to copy interfaces =""");
5135 Write_Str (Get_Name_String (Data.Library_Src_Dir.Name));
5142 -- Check the symbol related attributes
5144 -- First, the symbol policy
5146 if not Lib_Symbol_Policy.Default then
5148 Value : constant String :=
5150 (Get_Name_String (Lib_Symbol_Policy.Value));
5153 -- Symbol policy must hove one of a limited number of values
5155 if Value = "autonomous" or else Value = "default" then
5156 Data.Symbol_Data.Symbol_Policy := Autonomous;
5158 elsif Value = "compliant" then
5159 Data.Symbol_Data.Symbol_Policy := Compliant;
5161 elsif Value = "controlled" then
5162 Data.Symbol_Data.Symbol_Policy := Controlled;
5164 elsif Value = "restricted" then
5165 Data.Symbol_Data.Symbol_Policy := Restricted;
5167 elsif Value = "direct" then
5168 Data.Symbol_Data.Symbol_Policy := Direct;
5173 "illegal value for Library_Symbol_Policy",
5174 Lib_Symbol_Policy.Location);
5179 -- If attribute Library_Symbol_File is not specified, symbol policy
5180 -- cannot be Restricted.
5182 if Lib_Symbol_File.Default then
5183 if Data.Symbol_Data.Symbol_Policy = Restricted then
5186 "Library_Symbol_File needs to be defined when " &
5187 "symbol policy is Restricted",
5188 Lib_Symbol_Policy.Location);
5192 -- Library_Symbol_File is defined
5194 Data.Symbol_Data.Symbol_File :=
5195 Path_Name_Type (Lib_Symbol_File.Value);
5197 Get_Name_String (Lib_Symbol_File.Value);
5199 if Name_Len = 0 then
5202 "symbol file name cannot be an empty string",
5203 Lib_Symbol_File.Location);
5206 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
5209 for J in 1 .. Name_Len loop
5210 if Name_Buffer (J) = '/'
5211 or else Name_Buffer (J) = Directory_Separator
5220 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
5223 "symbol file name { is illegal. " &
5224 "Name cannot include directory info.",
5225 Lib_Symbol_File.Location);
5230 -- If attribute Library_Reference_Symbol_File is not defined,
5231 -- symbol policy cannot be Compliant or Controlled.
5233 if Lib_Ref_Symbol_File.Default then
5234 if Data.Symbol_Data.Symbol_Policy = Compliant
5235 or else Data.Symbol_Data.Symbol_Policy = Controlled
5239 "a reference symbol file need to be defined",
5240 Lib_Symbol_Policy.Location);
5244 -- Library_Reference_Symbol_File is defined, check file exists
5246 Data.Symbol_Data.Reference :=
5247 Path_Name_Type (Lib_Ref_Symbol_File.Value);
5249 Get_Name_String (Lib_Ref_Symbol_File.Value);
5251 if Name_Len = 0 then
5254 "reference symbol file name cannot be an empty string",
5255 Lib_Symbol_File.Location);
5258 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
5260 Add_Str_To_Name_Buffer
5261 (Get_Name_String (Data.Directory.Name));
5262 Add_Char_To_Name_Buffer (Directory_Separator);
5263 Add_Str_To_Name_Buffer
5264 (Get_Name_String (Lib_Ref_Symbol_File.Value));
5265 Data.Symbol_Data.Reference := Name_Find;
5268 if not Is_Regular_File
5269 (Get_Name_String (Data.Symbol_Data.Reference))
5272 File_Name_Type (Lib_Ref_Symbol_File.Value);
5274 -- For controlled and direct symbol policies, it is an error
5275 -- if the reference symbol file does not exist. For other
5276 -- symbol policies, this is just a warning
5279 Data.Symbol_Data.Symbol_Policy /= Controlled
5280 and then Data.Symbol_Data.Symbol_Policy /= Direct;
5284 "<library reference symbol file { does not exist",
5285 Lib_Ref_Symbol_File.Location);
5287 -- In addition in the non-controlled case, if symbol policy
5288 -- is Compliant, it is changed to Autonomous, because there
5289 -- is no reference to check against, and we don't want to
5290 -- fail in this case.
5292 if Data.Symbol_Data.Symbol_Policy /= Controlled then
5293 if Data.Symbol_Data.Symbol_Policy = Compliant then
5294 Data.Symbol_Data.Symbol_Policy := Autonomous;
5299 -- If both the reference symbol file and the symbol file are
5300 -- defined, then check that they are not the same file.
5302 if Data.Symbol_Data.Symbol_File /= No_Path then
5303 Get_Name_String (Data.Symbol_Data.Symbol_File);
5305 if Name_Len > 0 then
5307 Symb_Path : constant String :=
5310 (Data.Object_Directory.Name) &
5311 Directory_Separator &
5312 Name_Buffer (1 .. Name_Len),
5313 Directory => Current_Dir,
5315 Opt.Follow_Links_For_Files);
5316 Ref_Path : constant String :=
5319 (Data.Symbol_Data.Reference),
5320 Directory => Current_Dir,
5322 Opt.Follow_Links_For_Files);
5324 if Symb_Path = Ref_Path then
5327 "library reference symbol file and library" &
5328 " symbol file cannot be the same file",
5329 Lib_Ref_Symbol_File.Location);
5337 end Check_Stand_Alone_Library;
5339 ----------------------------
5340 -- Compute_Directory_Last --
5341 ----------------------------
5343 function Compute_Directory_Last (Dir : String) return Natural is
5346 and then (Dir (Dir'Last - 1) = Directory_Separator
5347 or else Dir (Dir'Last - 1) = '/')
5349 return Dir'Last - 1;
5353 end Compute_Directory_Last;
5360 (Project : Project_Id;
5361 In_Tree : Project_Tree_Ref;
5363 Flag_Location : Source_Ptr)
5365 Real_Location : Source_Ptr := Flag_Location;
5366 Error_Buffer : String (1 .. 5_000);
5367 Error_Last : Natural := 0;
5368 Name_Number : Natural := 0;
5369 File_Number : Natural := 0;
5370 First : Positive := Msg'First;
5373 procedure Add (C : Character);
5374 -- Add a character to the buffer
5376 procedure Add (S : String);
5377 -- Add a string to the buffer
5380 -- Add a name to the buffer
5383 -- Add a file name to the buffer
5389 procedure Add (C : Character) is
5391 Error_Last := Error_Last + 1;
5392 Error_Buffer (Error_Last) := C;
5395 procedure Add (S : String) is
5397 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
5398 Error_Last := Error_Last + S'Length;
5405 procedure Add_File is
5406 File : File_Name_Type;
5410 File_Number := File_Number + 1;
5414 File := Err_Vars.Error_Msg_File_1;
5416 File := Err_Vars.Error_Msg_File_2;
5418 File := Err_Vars.Error_Msg_File_3;
5423 Get_Name_String (File);
5424 Add (Name_Buffer (1 .. Name_Len));
5432 procedure Add_Name is
5437 Name_Number := Name_Number + 1;
5441 Name := Err_Vars.Error_Msg_Name_1;
5443 Name := Err_Vars.Error_Msg_Name_2;
5445 Name := Err_Vars.Error_Msg_Name_3;
5450 Get_Name_String (Name);
5451 Add (Name_Buffer (1 .. Name_Len));
5455 -- Start of processing for Error_Msg
5458 -- If location of error is unknown, use the location of the project
5460 if Real_Location = No_Location then
5461 Real_Location := In_Tree.Projects.Table (Project).Location;
5464 if Error_Report = null then
5465 Prj.Err.Error_Msg (Msg, Real_Location);
5469 -- Ignore continuation character
5471 if Msg (First) = '\' then
5475 -- Warning character is always the first one in this package
5476 -- this is an undocumented kludge???
5478 if Msg (First) = '?' then
5482 elsif Msg (First) = '<' then
5485 if Err_Vars.Error_Msg_Warn then
5491 while Index <= Msg'Last loop
5492 if Msg (Index) = '{' then
5495 elsif Msg (Index) = '%' then
5496 if Index < Msg'Last and then Msg (Index + 1) = '%' then
5508 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
5511 ----------------------
5512 -- Find_Ada_Sources --
5513 ----------------------
5515 procedure Find_Ada_Sources
5516 (Project : Project_Id;
5517 In_Tree : Project_Tree_Ref;
5518 Data : in out Project_Data;
5519 Current_Dir : String)
5521 Source_Dir : String_List_Id := Data.Source_Dirs;
5522 Element : String_Element;
5524 Current_Source : String_List_Id := Nil_String;
5525 Source_Recorded : Boolean := False;
5528 if Current_Verbosity = High then
5529 Write_Line ("Looking for sources:");
5532 -- For each subdirectory
5534 while Source_Dir /= Nil_String loop
5536 Source_Recorded := False;
5537 Element := In_Tree.String_Elements.Table (Source_Dir);
5538 if Element.Value /= No_Name then
5539 Get_Name_String (Element.Display_Value);
5542 Source_Directory : constant String :=
5543 Name_Buffer (1 .. Name_Len) & Directory_Separator;
5544 Dir_Last : constant Natural :=
5545 Compute_Directory_Last (Source_Directory);
5548 if Current_Verbosity = High then
5549 Write_Str ("Source_Dir = ");
5550 Write_Line (Source_Directory);
5553 -- We look at every entry in the source directory
5556 Source_Directory (Source_Directory'First .. Dir_Last));
5559 Read (Dir, Name_Buffer, Name_Len);
5561 if Current_Verbosity = High then
5562 Write_Str (" Checking ");
5563 Write_Line (Name_Buffer (1 .. Name_Len));
5566 exit when Name_Len = 0;
5569 File_Name : constant File_Name_Type := Name_Find;
5571 -- ??? We could probably optimize the following call:
5572 -- we need to resolve links only once for the
5573 -- directory itself, and then do a single call to
5574 -- readlink() for each file. Unfortunately that would
5575 -- require a change in Normalize_Pathname so that it
5576 -- has the option of not resolving links for its
5577 -- Directory parameter, only for Name.
5579 Path : constant String :=
5581 (Name => Name_Buffer (1 .. Name_Len),
5584 (Source_Directory'First .. Dir_Last),
5586 Opt.Follow_Links_For_Files,
5587 Case_Sensitive => True);
5589 Path_Name : Path_Name_Type;
5592 Name_Len := Path'Length;
5593 Name_Buffer (1 .. Name_Len) := Path;
5594 Path_Name := Name_Find;
5596 -- We attempt to register it as a source. However,
5597 -- there is no error if the file does not contain a
5598 -- valid source. But there is an error if we have a
5599 -- duplicate unit name.
5602 (File_Name => File_Name,
5603 Path_Name => Path_Name,
5607 Location => No_Location,
5608 Current_Source => Current_Source,
5609 Source_Recorded => Source_Recorded,
5610 Current_Dir => Current_Dir);
5619 when Directory_Error =>
5623 if Source_Recorded then
5624 In_Tree.String_Elements.Table (Source_Dir).Flag :=
5628 Source_Dir := Element.Next;
5631 if Current_Verbosity = High then
5632 Write_Line ("end Looking for sources.");
5635 end Find_Ada_Sources;
5637 --------------------------------
5638 -- Free_Ada_Naming_Exceptions --
5639 --------------------------------
5641 procedure Free_Ada_Naming_Exceptions is
5643 Ada_Naming_Exception_Table.Set_Last (0);
5644 Ada_Naming_Exceptions.Reset;
5645 Reverse_Ada_Naming_Exceptions.Reset;
5646 end Free_Ada_Naming_Exceptions;
5648 ---------------------
5649 -- Get_Directories --
5650 ---------------------
5652 procedure Get_Directories
5653 (Project : Project_Id;
5654 In_Tree : Project_Tree_Ref;
5655 Current_Dir : String;
5656 Data : in out Project_Data)
5658 Object_Dir : constant Variable_Value :=
5660 (Name_Object_Dir, Data.Decl.Attributes, In_Tree);
5662 Exec_Dir : constant Variable_Value :=
5664 (Name_Exec_Dir, Data.Decl.Attributes, In_Tree);
5666 Source_Dirs : constant Variable_Value :=
5668 (Name_Source_Dirs, Data.Decl.Attributes, In_Tree);
5670 Excluded_Source_Dirs : constant Variable_Value :=
5672 (Name_Excluded_Source_Dirs,
5673 Data.Decl.Attributes,
5676 Source_Files : constant Variable_Value :=
5678 (Name_Source_Files, Data.Decl.Attributes, In_Tree);
5680 Last_Source_Dir : String_List_Id := Nil_String;
5682 procedure Find_Source_Dirs
5683 (From : File_Name_Type;
5684 Location : Source_Ptr;
5685 Removed : Boolean := False);
5686 -- Find one or several source directories, and add (or remove, if
5687 -- Removed is True) them to list of source directories of the project.
5689 ----------------------
5690 -- Find_Source_Dirs --
5691 ----------------------
5693 procedure Find_Source_Dirs
5694 (From : File_Name_Type;
5695 Location : Source_Ptr;
5696 Removed : Boolean := False)
5698 Directory : constant String := Get_Name_String (From);
5699 Element : String_Element;
5701 procedure Recursive_Find_Dirs (Path : Name_Id);
5702 -- Find all the subdirectories (recursively) of Path and add them
5703 -- to the list of source directories of the project.
5705 -------------------------
5706 -- Recursive_Find_Dirs --
5707 -------------------------
5709 procedure Recursive_Find_Dirs (Path : Name_Id) is
5711 Name : String (1 .. 250);
5713 List : String_List_Id;
5714 Prev : String_List_Id;
5715 Element : String_Element;
5716 Found : Boolean := False;
5718 Non_Canonical_Path : Name_Id := No_Name;
5719 Canonical_Path : Name_Id := No_Name;
5721 The_Path : constant String :=
5723 (Get_Name_String (Path),
5724 Directory => Current_Dir,
5725 Resolve_Links => Opt.Follow_Links_For_Dirs) &
5726 Directory_Separator;
5728 The_Path_Last : constant Natural :=
5729 Compute_Directory_Last (The_Path);
5732 Name_Len := The_Path_Last - The_Path'First + 1;
5733 Name_Buffer (1 .. Name_Len) :=
5734 The_Path (The_Path'First .. The_Path_Last);
5735 Non_Canonical_Path := Name_Find;
5737 if Osint.File_Names_Case_Sensitive then
5738 Canonical_Path := Non_Canonical_Path;
5740 Get_Name_String (Non_Canonical_Path);
5741 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5742 Canonical_Path := Name_Find;
5745 -- To avoid processing the same directory several times, check
5746 -- if the directory is already in Recursive_Dirs. If it is, then
5747 -- there is nothing to do, just return. If it is not, put it there
5748 -- and continue recursive processing.
5751 if Recursive_Dirs.Get (Canonical_Path) then
5754 Recursive_Dirs.Set (Canonical_Path, True);
5758 -- Check if directory is already in list
5760 List := Data.Source_Dirs;
5762 while List /= Nil_String loop
5763 Element := In_Tree.String_Elements.Table (List);
5765 if Element.Value /= No_Name then
5766 Found := Element.Value = Canonical_Path;
5771 List := Element.Next;
5774 -- If directory is not already in list, put it there
5776 if (not Removed) and (not Found) then
5777 if Current_Verbosity = High then
5779 Write_Line (The_Path (The_Path'First .. The_Path_Last));
5782 String_Element_Table.Increment_Last
5783 (In_Tree.String_Elements);
5785 (Value => Canonical_Path,
5786 Display_Value => Non_Canonical_Path,
5787 Location => No_Location,
5792 -- Case of first source directory
5794 if Last_Source_Dir = Nil_String then
5795 Data.Source_Dirs := String_Element_Table.Last
5796 (In_Tree.String_Elements);
5798 -- Here we already have source directories
5801 -- Link the previous last to the new one
5803 In_Tree.String_Elements.Table
5804 (Last_Source_Dir).Next :=
5805 String_Element_Table.Last
5806 (In_Tree.String_Elements);
5809 -- And register this source directory as the new last
5811 Last_Source_Dir := String_Element_Table.Last
5812 (In_Tree.String_Elements);
5813 In_Tree.String_Elements.Table (Last_Source_Dir) :=
5816 elsif Removed and Found then
5817 if Prev = Nil_String then
5819 In_Tree.String_Elements.Table (List).Next;
5821 In_Tree.String_Elements.Table (Prev).Next :=
5822 In_Tree.String_Elements.Table (List).Next;
5826 -- Now look for subdirectories. We do that even when this
5827 -- directory is already in the list, because some of its
5828 -- subdirectories may not be in the list yet.
5830 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
5833 Read (Dir, Name, Last);
5836 if Name (1 .. Last) /= "."
5837 and then Name (1 .. Last) /= ".."
5839 -- Avoid . and .. directories
5841 if Current_Verbosity = High then
5842 Write_Str (" Checking ");
5843 Write_Line (Name (1 .. Last));
5847 Path_Name : constant String :=
5849 (Name => Name (1 .. Last),
5851 The_Path (The_Path'First .. The_Path_Last),
5852 Resolve_Links => Opt.Follow_Links_For_Dirs,
5853 Case_Sensitive => True);
5856 if Is_Directory (Path_Name) then
5857 -- We have found a new subdirectory, call self
5859 Name_Len := Path_Name'Length;
5860 Name_Buffer (1 .. Name_Len) := Path_Name;
5861 Recursive_Find_Dirs (Name_Find);
5870 when Directory_Error =>
5872 end Recursive_Find_Dirs;
5874 -- Start of processing for Find_Source_Dirs
5877 if Current_Verbosity = High and then not Removed then
5878 Write_Str ("Find_Source_Dirs (""");
5879 Write_Str (Directory);
5883 -- First, check if we are looking for a directory tree, indicated
5884 -- by "/**" at the end.
5886 if Directory'Length >= 3
5887 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5888 and then (Directory (Directory'Last - 2) = '/'
5890 Directory (Directory'Last - 2) = Directory_Separator)
5893 Data.Known_Order_Of_Source_Dirs := False;
5896 Name_Len := Directory'Length - 3;
5898 if Name_Len = 0 then
5900 -- Case of "/**": all directories in file system
5903 Name_Buffer (1) := Directory (Directory'First);
5906 Name_Buffer (1 .. Name_Len) :=
5907 Directory (Directory'First .. Directory'Last - 3);
5910 if Current_Verbosity = High then
5911 Write_Str ("Looking for all subdirectories of """);
5912 Write_Str (Name_Buffer (1 .. Name_Len));
5917 Base_Dir : constant File_Name_Type := Name_Find;
5918 Root_Dir : constant String :=
5920 (Name => Get_Name_String (Base_Dir),
5922 Get_Name_String (Data.Directory.Display_Name),
5923 Resolve_Links => False,
5924 Case_Sensitive => True);
5927 if Root_Dir'Length = 0 then
5928 Err_Vars.Error_Msg_File_1 := Base_Dir;
5930 if Location = No_Location then
5933 "{ is not a valid directory.",
5938 "{ is not a valid directory.",
5943 -- We have an existing directory, we register it and all of
5944 -- its subdirectories.
5946 if Current_Verbosity = High then
5947 Write_Line ("Looking for source directories:");
5950 Name_Len := Root_Dir'Length;
5951 Name_Buffer (1 .. Name_Len) := Root_Dir;
5952 Recursive_Find_Dirs (Name_Find);
5954 if Current_Verbosity = High then
5955 Write_Line ("End of looking for source directories.");
5960 -- We have a single directory
5964 Path_Name : Path_Name_Type;
5965 Display_Path_Name : Path_Name_Type;
5966 List : String_List_Id;
5967 Prev : String_List_Id;
5971 (Project => Project,
5974 Parent => Data.Directory.Display_Name,
5976 Display => Display_Path_Name,
5977 Current_Dir => Current_Dir);
5979 if Path_Name = No_Path then
5980 Err_Vars.Error_Msg_File_1 := From;
5982 if Location = No_Location then
5985 "{ is not a valid directory",
5990 "{ is not a valid directory",
5996 Path : constant String :=
5997 Get_Name_String (Path_Name) &
5998 Directory_Separator;
5999 Last_Path : constant Natural :=
6000 Compute_Directory_Last (Path);
6002 Display_Path : constant String :=
6004 (Display_Path_Name) &
6005 Directory_Separator;
6006 Last_Display_Path : constant Natural :=
6007 Compute_Directory_Last
6009 Display_Path_Id : Name_Id;
6013 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
6014 Path_Id := Name_Find;
6016 Add_Str_To_Name_Buffer
6018 (Display_Path'First .. Last_Display_Path));
6019 Display_Path_Id := Name_Find;
6023 -- As it is an existing directory, we add it to the
6024 -- list of directories.
6026 String_Element_Table.Increment_Last
6027 (In_Tree.String_Elements);
6031 Display_Value => Display_Path_Id,
6032 Location => No_Location,
6034 Next => Nil_String);
6036 if Last_Source_Dir = Nil_String then
6038 -- This is the first source directory
6040 Data.Source_Dirs := String_Element_Table.Last
6041 (In_Tree.String_Elements);
6044 -- We already have source directories, link the
6045 -- previous last to the new one.
6047 In_Tree.String_Elements.Table
6048 (Last_Source_Dir).Next :=
6049 String_Element_Table.Last
6050 (In_Tree.String_Elements);
6053 -- And register this source directory as the new last
6055 Last_Source_Dir := String_Element_Table.Last
6056 (In_Tree.String_Elements);
6057 In_Tree.String_Elements.Table
6058 (Last_Source_Dir) := Element;
6061 -- Remove source dir, if present
6063 List := Data.Source_Dirs;
6066 -- Look for source dir in current list
6068 while List /= Nil_String loop
6069 Element := In_Tree.String_Elements.Table (List);
6070 exit when Element.Value = Path_Id;
6072 List := Element.Next;
6075 if List /= Nil_String then
6076 -- Source dir was found, remove it from the list
6078 if Prev = Nil_String then
6080 In_Tree.String_Elements.Table (List).Next;
6083 In_Tree.String_Elements.Table (Prev).Next :=
6084 In_Tree.String_Elements.Table (List).Next;
6092 end Find_Source_Dirs;
6094 -- Start of processing for Get_Directories
6097 if Current_Verbosity = High then
6098 Write_Line ("Starting to look for directories");
6101 -- Check the object directory
6103 pragma Assert (Object_Dir.Kind = Single,
6104 "Object_Dir is not a single string");
6106 -- We set the object directory to its default
6108 Data.Object_Directory := Data.Directory;
6110 if Object_Dir.Value /= Empty_String then
6111 Get_Name_String (Object_Dir.Value);
6113 if Name_Len = 0 then
6116 "Object_Dir cannot be empty",
6117 Object_Dir.Location);
6120 -- We check that the specified object directory does exist
6125 File_Name_Type (Object_Dir.Value),
6126 Data.Directory.Display_Name,
6127 Data.Object_Directory.Name,
6128 Data.Object_Directory.Display_Name,
6130 Location => Object_Dir.Location,
6131 Current_Dir => Current_Dir);
6133 if Data.Object_Directory = No_Path_Information then
6135 -- The object directory does not exist, report an error if the
6136 -- project is not externally built.
6138 if not Data.Externally_Built then
6139 Err_Vars.Error_Msg_File_1 :=
6140 File_Name_Type (Object_Dir.Value);
6143 "the object directory { cannot be found",
6147 -- Do not keep a nil Object_Directory. Set it to the specified
6148 -- (relative or absolute) path. This is for the benefit of
6149 -- tools that recover from errors; for example, these tools
6150 -- could create the non existent directory.
6152 Data.Object_Directory.Display_Name :=
6153 Path_Name_Type (Object_Dir.Value);
6155 if Osint.File_Names_Case_Sensitive then
6156 Data.Object_Directory.Name :=
6157 Path_Name_Type (Object_Dir.Value);
6159 Get_Name_String (Object_Dir.Value);
6160 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6161 Data.Object_Directory.Name := Name_Find;
6166 elsif Subdirs /= null then
6168 Name_Buffer (1) := '.';
6173 Data.Directory.Name,
6174 Data.Object_Directory.Name,
6175 Data.Object_Directory.Display_Name,
6177 Location => Object_Dir.Location,
6178 Current_Dir => Current_Dir);
6181 if Current_Verbosity = High then
6182 if Data.Object_Directory = No_Path_Information then
6183 Write_Line ("No object directory");
6185 Write_Str ("Object directory: """);
6186 Write_Str (Get_Name_String (Data.Object_Directory.Display_Name));
6191 -- Check the exec directory
6193 pragma Assert (Exec_Dir.Kind = Single,
6194 "Exec_Dir is not a single string");
6196 -- We set the object directory to its default
6198 Data.Exec_Directory := Data.Object_Directory;
6200 if Exec_Dir.Value /= Empty_String then
6201 Get_Name_String (Exec_Dir.Value);
6203 if Name_Len = 0 then
6206 "Exec_Dir cannot be empty",
6210 -- We check that the specified exec directory does exist
6215 File_Name_Type (Exec_Dir.Value),
6216 Data.Directory.Name,
6217 Data.Exec_Directory.Name,
6218 Data.Exec_Directory.Display_Name,
6220 Location => Exec_Dir.Location,
6221 Current_Dir => Current_Dir);
6223 if Data.Exec_Directory = No_Path_Information then
6224 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
6227 "the exec directory { cannot be found",
6233 if Current_Verbosity = High then
6234 if Data.Exec_Directory = No_Path_Information then
6235 Write_Line ("No exec directory");
6237 Write_Str ("Exec directory: """);
6238 Write_Str (Get_Name_String (Data.Exec_Directory.Display_Name));
6243 -- Look for the source directories
6245 if Current_Verbosity = High then
6246 Write_Line ("Starting to look for source directories");
6249 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
6251 if (not Source_Files.Default) and then
6252 Source_Files.Values = Nil_String
6254 Data.Source_Dirs := Nil_String;
6256 if Data.Qualifier = Standard then
6260 "a standard project cannot have no sources",
6261 Source_Files.Location);
6264 if Data.Extends = No_Project
6265 and then Data.Object_Directory = Data.Directory
6267 Data.Object_Directory := No_Path_Information;
6270 elsif Source_Dirs.Default then
6272 -- No Source_Dirs specified: the single source directory is the one
6273 -- containing the project file
6275 String_Element_Table.Increment_Last
6276 (In_Tree.String_Elements);
6277 Data.Source_Dirs := String_Element_Table.Last
6278 (In_Tree.String_Elements);
6279 In_Tree.String_Elements.Table (Data.Source_Dirs) :=
6280 (Value => Name_Id (Data.Directory.Name),
6281 Display_Value => Name_Id (Data.Directory.Display_Name),
6282 Location => No_Location,
6287 if Current_Verbosity = High then
6288 Write_Line ("Single source directory:");
6290 Write_Str (Get_Name_String (Data.Directory.Display_Name));
6294 elsif Source_Dirs.Values = Nil_String then
6295 if Data.Qualifier = Standard then
6299 "a standard project cannot have no source directories",
6300 Source_Dirs.Location);
6303 -- If Source_Dirs is an empty string list, this means that this
6304 -- project contains no source. For projects that don't extend other
6305 -- projects, this also means that there is no need for an object
6306 -- directory, if not specified.
6308 if Data.Extends = No_Project
6309 and then Data.Object_Directory = Data.Directory
6311 Data.Object_Directory := No_Path_Information;
6314 Data.Source_Dirs := Nil_String;
6318 Source_Dir : String_List_Id;
6319 Element : String_Element;
6322 -- Process the source directories for each element of the list
6324 Source_Dir := Source_Dirs.Values;
6325 while Source_Dir /= Nil_String loop
6327 In_Tree.String_Elements.Table (Source_Dir);
6329 (File_Name_Type (Element.Value), Element.Location);
6330 Source_Dir := Element.Next;
6335 if not Excluded_Source_Dirs.Default
6336 and then Excluded_Source_Dirs.Values /= Nil_String
6339 Source_Dir : String_List_Id;
6340 Element : String_Element;
6343 -- Process the source directories for each element of the list
6345 Source_Dir := Excluded_Source_Dirs.Values;
6346 while Source_Dir /= Nil_String loop
6348 In_Tree.String_Elements.Table (Source_Dir);
6350 (File_Name_Type (Element.Value),
6353 Source_Dir := Element.Next;
6358 if Current_Verbosity = High then
6359 Write_Line ("Putting source directories in canonical cases");
6363 Current : String_List_Id := Data.Source_Dirs;
6364 Element : String_Element;
6367 while Current /= Nil_String loop
6368 Element := In_Tree.String_Elements.Table (Current);
6369 if Element.Value /= No_Name then
6370 if not Osint.File_Names_Case_Sensitive then
6371 Get_Name_String (Element.Value);
6372 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6373 Element.Value := Name_Find;
6376 In_Tree.String_Elements.Table (Current) := Element;
6379 Current := Element.Next;
6383 end Get_Directories;
6390 (Project : Project_Id;
6391 In_Tree : Project_Tree_Ref;
6392 Data : in out Project_Data)
6394 Mains : constant Variable_Value :=
6395 Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes, In_Tree);
6398 Data.Mains := Mains.Values;
6400 -- If no Mains were specified, and if we are an extending project,
6401 -- inherit the Mains from the project we are extending.
6403 if Mains.Default then
6404 if not Data.Library and then Data.Extends /= No_Project then
6406 In_Tree.Projects.Table (Data.Extends).Mains;
6409 -- In a library project file, Main cannot be specified
6411 elsif Data.Library then
6414 "a library project file cannot have Main specified",
6419 ---------------------------
6420 -- Get_Sources_From_File --
6421 ---------------------------
6423 procedure Get_Sources_From_File
6425 Location : Source_Ptr;
6426 Project : Project_Id;
6427 In_Tree : Project_Tree_Ref)
6429 File : Prj.Util.Text_File;
6430 Line : String (1 .. 250);
6432 Source_Name : File_Name_Type;
6433 Name_Loc : Name_Location;
6436 if Get_Mode = Ada_Only then
6440 if Current_Verbosity = High then
6441 Write_Str ("Opening """);
6448 Prj.Util.Open (File, Path);
6450 if not Prj.Util.Is_Valid (File) then
6451 Error_Msg (Project, In_Tree, "file does not exist", Location);
6453 -- Read the lines one by one
6455 while not Prj.Util.End_Of_File (File) loop
6456 Prj.Util.Get_Line (File, Line, Last);
6458 -- A non empty, non comment line should contain a file name
6461 and then (Last = 1 or else Line (1 .. 2) /= "--")
6464 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6465 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6466 Source_Name := Name_Find;
6468 -- Check that there is no directory information
6470 for J in 1 .. Last loop
6471 if Line (J) = '/' or else Line (J) = Directory_Separator then
6472 Error_Msg_File_1 := Source_Name;
6476 "file name cannot include directory information ({)",
6482 Name_Loc := Source_Names.Get (Source_Name);
6484 if Name_Loc = No_Name_Location then
6486 (Name => Source_Name,
6487 Location => Location,
6488 Source => No_Source,
6493 Source_Names.Set (Source_Name, Name_Loc);
6497 Prj.Util.Close (File);
6500 end Get_Sources_From_File;
6507 (In_Tree : Project_Tree_Ref;
6508 Canonical_File_Name : File_Name_Type;
6509 Naming : Naming_Data;
6510 Exception_Id : out Ada_Naming_Exception_Id;
6511 Unit_Name : out Name_Id;
6512 Unit_Kind : out Spec_Or_Body;
6513 Needs_Pragma : out Boolean)
6515 Info_Id : Ada_Naming_Exception_Id :=
6516 Ada_Naming_Exceptions.Get (Canonical_File_Name);
6517 VMS_Name : File_Name_Type;
6520 if Info_Id = No_Ada_Naming_Exception then
6521 if Hostparm.OpenVMS then
6522 VMS_Name := Canonical_File_Name;
6523 Get_Name_String (VMS_Name);
6525 if Name_Buffer (Name_Len) = '.' then
6526 Name_Len := Name_Len - 1;
6527 VMS_Name := Name_Find;
6530 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
6535 if Info_Id /= No_Ada_Naming_Exception then
6536 Exception_Id := Info_Id;
6537 Unit_Name := No_Name;
6538 Unit_Kind := Specification;
6539 Needs_Pragma := True;
6543 Needs_Pragma := False;
6544 Exception_Id := No_Ada_Naming_Exception;
6546 Get_Name_String (Canonical_File_Name);
6548 -- How about some comments and a name for this declare block ???
6549 -- In fact the whole code below needs more comments ???
6552 File : String := Name_Buffer (1 .. Name_Len);
6553 First : constant Positive := File'First;
6554 Last : Natural := File'Last;
6555 Standard_GNAT : Boolean;
6556 Spec : constant File_Name_Type :=
6557 Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
6558 Body_Suff : constant File_Name_Type :=
6559 Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming);
6562 Standard_GNAT := Spec = Default_Ada_Spec_Suffix
6563 and then Body_Suff = Default_Ada_Body_Suffix;
6566 Spec_Suffix : constant String := Get_Name_String (Spec);
6567 Body_Suffix : constant String := Get_Name_String (Body_Suff);
6568 Sep_Suffix : constant String :=
6569 Get_Name_String (Naming.Separate_Suffix);
6571 May_Be_Spec : Boolean;
6572 May_Be_Body : Boolean;
6573 May_Be_Sep : Boolean;
6577 File'Length > Spec_Suffix'Length
6579 File (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix;
6582 File'Length > Body_Suffix'Length
6584 File (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix;
6587 File'Length > Sep_Suffix'Length
6589 File (Last - Sep_Suffix'Length + 1 .. Last) = Sep_Suffix;
6591 -- If two May_Be_ booleans are True, always choose the longer one
6594 if May_Be_Body and then
6595 Spec_Suffix'Length < Body_Suffix'Length
6597 Unit_Kind := Body_Part;
6599 if May_Be_Sep and then
6600 Body_Suffix'Length < Sep_Suffix'Length
6602 Last := Last - Sep_Suffix'Length;
6603 May_Be_Body := False;
6606 Last := Last - Body_Suffix'Length;
6607 May_Be_Sep := False;
6610 elsif May_Be_Sep and then
6611 Spec_Suffix'Length < Sep_Suffix'Length
6613 Unit_Kind := Body_Part;
6614 Last := Last - Sep_Suffix'Length;
6617 Unit_Kind := Specification;
6618 Last := Last - Spec_Suffix'Length;
6621 elsif May_Be_Body then
6622 Unit_Kind := Body_Part;
6624 if May_Be_Sep and then
6625 Body_Suffix'Length < Sep_Suffix'Length
6627 Last := Last - Sep_Suffix'Length;
6628 May_Be_Body := False;
6630 Last := Last - Body_Suffix'Length;
6631 May_Be_Sep := False;
6634 elsif May_Be_Sep then
6635 Unit_Kind := Body_Part;
6636 Last := Last - Sep_Suffix'Length;
6644 -- This is not a source file
6646 Unit_Name := No_Name;
6647 Unit_Kind := Specification;
6649 if Current_Verbosity = High then
6650 Write_Line (" Not a valid file name.");
6655 elsif Current_Verbosity = High then
6657 when Specification =>
6658 Write_Str (" Specification: ");
6659 Write_Line (File (First .. Last + Spec_Suffix'Length));
6663 Write_Str (" Body: ");
6664 Write_Line (File (First .. Last + Body_Suffix'Length));
6667 Write_Str (" Separate: ");
6668 Write_Line (File (First .. Last + Sep_Suffix'Length));
6674 Get_Name_String (Naming.Dot_Replacement);
6676 Standard_GNAT and then Name_Buffer (1 .. Name_Len) = "-";
6678 if Name_Buffer (1 .. Name_Len) /= "." then
6680 -- If Dot_Replacement is not a single dot, then there should not
6681 -- be any dot in the name.
6683 for Index in First .. Last loop
6684 if File (Index) = '.' then
6685 if Current_Verbosity = High then
6687 (" Not a valid file name (some dot not replaced).");
6690 Unit_Name := No_Name;
6696 -- Replace the substring Dot_Replacement with dots
6699 Index : Positive := First;
6702 while Index <= Last - Name_Len + 1 loop
6704 if File (Index .. Index + Name_Len - 1) =
6705 Name_Buffer (1 .. Name_Len)
6707 File (Index) := '.';
6709 if Name_Len > 1 and then Index < Last then
6710 File (Index + 1 .. Last - Name_Len + 1) :=
6711 File (Index + Name_Len .. Last);
6714 Last := Last - Name_Len + 1;
6722 -- Check if the casing is right
6725 Src : String := File (First .. Last);
6726 Src_Last : Positive := Last;
6729 case Naming.Casing is
6730 when All_Lower_Case =>
6733 Mapping => Lower_Case_Map);
6735 when All_Upper_Case =>
6738 Mapping => Upper_Case_Map);
6740 when Mixed_Case | Unknown =>
6744 if Src /= File (First .. Last) then
6745 if Current_Verbosity = High then
6746 Write_Line (" Not a valid file name (casing).");
6749 Unit_Name := No_Name;
6753 -- We put the name in lower case
6757 Mapping => Lower_Case_Map);
6759 -- In the standard GNAT naming scheme, check for special cases:
6760 -- children or separates of A, G, I or S, and run time sources.
6762 if Standard_GNAT and then Src'Length >= 3 then
6764 S1 : constant Character := Src (Src'First);
6765 S2 : constant Character := Src (Src'First + 1);
6766 S3 : constant Character := Src (Src'First + 2);
6774 -- Children or separates of packages A, G, I or S. These
6775 -- names are x__ ... or x~... (where x is a, g, i, or s).
6776 -- Both versions (x__... and x~...) are allowed in all
6777 -- platforms, because it is not possible to know the
6778 -- platform before processing of the project files.
6780 if S2 = '_' and then S3 = '_' then
6781 Src (Src'First + 1) := '.';
6782 Src_Last := Src_Last - 1;
6783 Src (Src'First + 2 .. Src_Last) :=
6784 Src (Src'First + 3 .. Src_Last + 1);
6787 Src (Src'First + 1) := '.';
6789 -- If it is potentially a run time source, disable
6790 -- filling of the mapping file to avoid warnings.
6793 Set_Mapping_File_Initial_State_To_Empty;
6799 if Current_Verbosity = High then
6801 Write_Line (Src (Src'First .. Src_Last));
6804 -- Now, we check if this name is a valid unit name
6807 (Name => Src (Src'First .. Src_Last), Unit => Unit_Name);
6817 function Hash (Unit : Unit_Info) return Header_Num is
6819 return Header_Num (Unit.Unit mod 2048);
6822 -----------------------
6823 -- Is_Illegal_Suffix --
6824 -----------------------
6826 function Is_Illegal_Suffix
6828 Dot_Replacement_Is_A_Single_Dot : Boolean) return Boolean
6831 if Suffix'Length = 0 or else Index (Suffix, ".") = 0 then
6835 -- If dot replacement is a single dot, and first character of suffix is
6838 if Dot_Replacement_Is_A_Single_Dot
6839 and then Suffix (Suffix'First) = '.'
6841 for Index in Suffix'First + 1 .. Suffix'Last loop
6843 -- If there is another dot
6845 if Suffix (Index) = '.' then
6847 -- It is illegal to have a letter following the initial dot
6849 return Is_Letter (Suffix (Suffix'First + 1));
6857 end Is_Illegal_Suffix;
6859 ----------------------
6860 -- Locate_Directory --
6861 ----------------------
6863 procedure Locate_Directory
6864 (Project : Project_Id;
6865 In_Tree : Project_Tree_Ref;
6866 Name : File_Name_Type;
6867 Parent : Path_Name_Type;
6868 Dir : out Path_Name_Type;
6869 Display : out Path_Name_Type;
6870 Create : String := "";
6871 Current_Dir : String;
6872 Location : Source_Ptr := No_Location)
6874 The_Parent : constant String :=
6875 Get_Name_String (Parent) & Directory_Separator;
6877 The_Parent_Last : constant Natural :=
6878 Compute_Directory_Last (The_Parent);
6880 Full_Name : File_Name_Type;
6882 The_Name : File_Name_Type;
6885 Get_Name_String (Name);
6887 -- Add Subdirs.all if it is a directory that may be created and
6888 -- Subdirs is not null;
6890 if Create /= "" and then Subdirs /= null then
6891 if Name_Buffer (Name_Len) /= Directory_Separator then
6892 Add_Char_To_Name_Buffer (Directory_Separator);
6895 Add_Str_To_Name_Buffer (Subdirs.all);
6898 -- Convert '/' to directory separator (for Windows)
6900 for J in 1 .. Name_Len loop
6901 if Name_Buffer (J) = '/' then
6902 Name_Buffer (J) := Directory_Separator;
6906 The_Name := Name_Find;
6908 if Current_Verbosity = High then
6909 Write_Str ("Locate_Directory (""");
6910 Write_Str (Get_Name_String (The_Name));
6911 Write_Str (""", """);
6912 Write_Str (The_Parent);
6919 if Is_Absolute_Path (Get_Name_String (The_Name)) then
6920 Full_Name := The_Name;
6924 Add_Str_To_Name_Buffer
6925 (The_Parent (The_Parent'First .. The_Parent_Last));
6926 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
6927 Full_Name := Name_Find;
6931 Full_Path_Name : constant String := Get_Name_String (Full_Name);
6934 if (Setup_Projects or else Subdirs /= null)
6935 and then Create'Length > 0
6936 and then not Is_Directory (Full_Path_Name)
6939 Create_Path (Full_Path_Name);
6941 if not Quiet_Output then
6943 Write_Str (" directory """);
6944 Write_Str (Full_Path_Name);
6945 Write_Line (""" created");
6952 "could not create " & Create &
6953 " directory " & Full_Path_Name,
6958 if Is_Directory (Full_Path_Name) then
6960 Normed : constant String :=
6963 Directory => Current_Dir,
6964 Resolve_Links => False,
6965 Case_Sensitive => True);
6967 Canonical_Path : constant String :=
6970 Directory => Current_Dir,
6972 Opt.Follow_Links_For_Dirs,
6973 Case_Sensitive => False);
6976 Name_Len := Normed'Length;
6977 Name_Buffer (1 .. Name_Len) := Normed;
6978 Display := Name_Find;
6980 Name_Len := Canonical_Path'Length;
6981 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6986 end Locate_Directory;
6988 ---------------------------
6989 -- Find_Excluded_Sources --
6990 ---------------------------
6992 procedure Find_Excluded_Sources
6993 (Project : Project_Id;
6994 In_Tree : Project_Tree_Ref;
6995 Data : Project_Data)
6997 Excluded_Sources : Variable_Value;
6999 Excluded_Source_List_File : Variable_Value;
7001 Current : String_List_Id;
7003 Element : String_Element;
7005 Location : Source_Ptr;
7007 Name : File_Name_Type;
7009 File : Prj.Util.Text_File;
7010 Line : String (1 .. 300);
7013 Locally_Removed : Boolean := False;
7015 Excluded_Source_List_File :=
7017 (Name_Excluded_Source_List_File, Data.Decl.Attributes, In_Tree);
7021 (Name_Excluded_Source_Files, Data.Decl.Attributes, In_Tree);
7023 -- If Excluded_Source_Files is not declared, check
7024 -- Locally_Removed_Files.
7026 if Excluded_Sources.Default then
7027 Locally_Removed := True;
7030 (Name_Locally_Removed_Files, Data.Decl.Attributes, In_Tree);
7033 Excluded_Sources_Htable.Reset;
7035 -- If there are excluded sources, put them in the table
7037 if not Excluded_Sources.Default then
7038 if not Excluded_Source_List_File.Default then
7039 if Locally_Removed then
7042 "?both attributes Locally_Removed_Files and " &
7043 "Excluded_Source_List_File are present",
7044 Excluded_Source_List_File.Location);
7048 "?both attributes Excluded_Source_Files and " &
7049 "Excluded_Source_List_File are present",
7050 Excluded_Source_List_File.Location);
7054 Current := Excluded_Sources.Values;
7055 while Current /= Nil_String loop
7056 Element := In_Tree.String_Elements.Table (Current);
7058 if Osint.File_Names_Case_Sensitive then
7059 Name := File_Name_Type (Element.Value);
7061 Get_Name_String (Element.Value);
7062 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7066 -- If the element has no location, then use the location
7067 -- of Excluded_Sources to report possible errors.
7069 if Element.Location = No_Location then
7070 Location := Excluded_Sources.Location;
7072 Location := Element.Location;
7075 Excluded_Sources_Htable.Set (Name, (Name, False, Location));
7076 Current := Element.Next;
7079 elsif not Excluded_Source_List_File.Default then
7080 Location := Excluded_Source_List_File.Location;
7083 Source_File_Path_Name : constant String :=
7086 (Excluded_Source_List_File.Value),
7087 Data.Directory.Name);
7090 if Source_File_Path_Name'Length = 0 then
7091 Err_Vars.Error_Msg_File_1 :=
7092 File_Name_Type (Excluded_Source_List_File.Value);
7095 "file with excluded sources { does not exist",
7096 Excluded_Source_List_File.Location);
7101 Prj.Util.Open (File, Source_File_Path_Name);
7103 if not Prj.Util.Is_Valid (File) then
7105 (Project, In_Tree, "file does not exist", Location);
7107 -- Read the lines one by one
7109 while not Prj.Util.End_Of_File (File) loop
7110 Prj.Util.Get_Line (File, Line, Last);
7112 -- A non empty, non comment line should contain a file
7116 and then (Last = 1 or else Line (1 .. 2) /= "--")
7119 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
7120 Canonical_Case_File_Name
7121 (Name_Buffer (1 .. Name_Len));
7124 -- Check that there is no directory information
7126 for J in 1 .. Last loop
7128 or else Line (J) = Directory_Separator
7130 Error_Msg_File_1 := Name;
7134 "file name cannot include " &
7135 "directory information ({)",
7141 Excluded_Sources_Htable.Set
7142 (Name, (Name, False, Location));
7146 Prj.Util.Close (File);
7151 end Find_Excluded_Sources;
7153 ---------------------------
7154 -- Find_Explicit_Sources --
7155 ---------------------------
7157 procedure Find_Explicit_Sources
7158 (Current_Dir : String;
7159 Project : Project_Id;
7160 In_Tree : Project_Tree_Ref;
7161 Data : in out Project_Data)
7163 Sources : constant Variable_Value :=
7166 Data.Decl.Attributes,
7168 Source_List_File : constant Variable_Value :=
7170 (Name_Source_List_File,
7171 Data.Decl.Attributes,
7173 Name_Loc : Name_Location;
7176 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
7178 (Source_List_File.Kind = Single,
7179 "Source_List_File is not a single string");
7181 -- If the user has specified a Sources attribute
7183 if not Sources.Default then
7184 if not Source_List_File.Default then
7187 "?both attributes source_files and " &
7188 "source_list_file are present",
7189 Source_List_File.Location);
7192 -- Sources is a list of file names
7195 Current : String_List_Id := Sources.Values;
7196 Element : String_Element;
7197 Location : Source_Ptr;
7198 Name : File_Name_Type;
7201 if Get_Mode = Ada_Only then
7202 Data.Ada_Sources_Present := Current /= Nil_String;
7205 if Get_Mode = Multi_Language then
7206 if Current = Nil_String then
7207 Data.First_Language_Processing := No_Language_Index;
7209 -- This project contains no source. For projects that
7210 -- don't extend other projects, this also means that
7211 -- there is no need for an object directory, if not
7214 if Data.Extends = No_Project
7215 and then Data.Object_Directory = Data.Directory
7217 Data.Object_Directory := No_Path_Information;
7222 while Current /= Nil_String loop
7223 Element := In_Tree.String_Elements.Table (Current);
7224 Get_Name_String (Element.Value);
7226 if Osint.File_Names_Case_Sensitive then
7227 Name := File_Name_Type (Element.Value);
7229 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7233 -- If the element has no location, then use the
7234 -- location of Sources to report possible errors.
7236 if Element.Location = No_Location then
7237 Location := Sources.Location;
7239 Location := Element.Location;
7242 -- Check that there is no directory information
7244 for J in 1 .. Name_Len loop
7245 if Name_Buffer (J) = '/'
7246 or else Name_Buffer (J) = Directory_Separator
7248 Error_Msg_File_1 := Name;
7252 "file name cannot include directory " &
7259 -- In Multi_Language mode, check whether the file is
7260 -- already there: the same file name may be in the list; if
7261 -- the source is missing, the error will be on the first
7262 -- mention of the source file name.
7266 Name_Loc := No_Name_Location;
7267 when Multi_Language =>
7268 Name_Loc := Source_Names.Get (Name);
7271 if Name_Loc = No_Name_Location then
7274 Location => Location,
7275 Source => No_Source,
7278 Source_Names.Set (Name, Name_Loc);
7281 Current := Element.Next;
7284 if Get_Mode = Ada_Only then
7285 Get_Path_Names_And_Record_Ada_Sources
7286 (Project, In_Tree, Data, Current_Dir);
7290 -- If we have no Source_Files attribute, check the Source_List_File
7293 elsif not Source_List_File.Default then
7295 -- Source_List_File is the name of the file
7296 -- that contains the source file names
7299 Source_File_Path_Name : constant String :=
7301 (File_Name_Type (Source_List_File.Value), Data.Directory.Name);
7304 if Source_File_Path_Name'Length = 0 then
7305 Err_Vars.Error_Msg_File_1 :=
7306 File_Name_Type (Source_List_File.Value);
7309 "file with sources { does not exist",
7310 Source_List_File.Location);
7313 Get_Sources_From_File
7314 (Source_File_Path_Name, Source_List_File.Location,
7317 if Get_Mode = Ada_Only then
7318 -- Look in the source directories to find those sources
7320 Get_Path_Names_And_Record_Ada_Sources
7321 (Project, In_Tree, Data, Current_Dir);
7327 -- Neither Source_Files nor Source_List_File has been
7328 -- specified. Find all the files that satisfy the naming
7329 -- scheme in all the source directories.
7331 if Get_Mode = Ada_Only then
7332 Find_Ada_Sources (Project, In_Tree, Data, Current_Dir);
7336 if Get_Mode = Multi_Language then
7338 (Project, In_Tree, Data,
7340 Sources.Default and then Source_List_File.Default);
7342 -- Check if all exceptions have been found.
7343 -- For Ada, it is an error if an exception is not found.
7344 -- For other language, the source is simply removed.
7348 Src_Data : Source_Data;
7351 Source := Data.First_Source;
7352 while Source /= No_Source loop
7353 Src_Data := In_Tree.Sources.Table (Source);
7355 if Src_Data.Naming_Exception
7356 and then Src_Data.Path = No_Path_Information
7358 if Src_Data.Unit /= No_Name then
7359 Error_Msg_Name_1 := Name_Id (Src_Data.Display_File);
7360 Error_Msg_Name_2 := Name_Id (Src_Data.Unit);
7363 "source file %% for unit %% not found",
7367 Remove_Source (Source, No_Source, Project, Data, In_Tree);
7370 Source := Src_Data.Next_In_Project;
7374 -- Check that all sources in Source_Files or the file
7375 -- Source_List_File has been found.
7378 Name_Loc : Name_Location;
7381 Name_Loc := Source_Names.Get_First;
7382 while Name_Loc /= No_Name_Location loop
7383 if (not Name_Loc.Except) and then (not Name_Loc.Found) then
7384 Error_Msg_Name_1 := Name_Id (Name_Loc.Name);
7388 "file %% not found",
7392 Name_Loc := Source_Names.Get_Next;
7397 if Get_Mode = Ada_Only
7398 and then Data.Extends = No_Project
7400 -- We should have found at least one source, if not report an error
7402 if Data.Ada_Sources = Nil_String then
7404 (Project, "Ada", In_Tree, Source_List_File.Location);
7408 end Find_Explicit_Sources;
7410 -------------------------------------------
7411 -- Get_Path_Names_And_Record_Ada_Sources --
7412 -------------------------------------------
7414 procedure Get_Path_Names_And_Record_Ada_Sources
7415 (Project : Project_Id;
7416 In_Tree : Project_Tree_Ref;
7417 Data : in out Project_Data;
7418 Current_Dir : String)
7420 Source_Dir : String_List_Id;
7421 Element : String_Element;
7422 Path : Path_Name_Type;
7424 Name : File_Name_Type;
7425 Canonical_Name : File_Name_Type;
7426 Name_Str : String (1 .. 1_024);
7427 Last : Natural := 0;
7429 Current_Source : String_List_Id := Nil_String;
7430 First_Error : Boolean := True;
7431 Source_Recorded : Boolean := False;
7434 -- We look in all source directories for the file names in the hash
7435 -- table Source_Names.
7437 Source_Dir := Data.Source_Dirs;
7438 while Source_Dir /= Nil_String loop
7439 Source_Recorded := False;
7440 Element := In_Tree.String_Elements.Table (Source_Dir);
7443 Dir_Path : constant String :=
7444 Get_Name_String (Element.Display_Value);
7446 if Current_Verbosity = High then
7447 Write_Str ("checking directory """);
7448 Write_Str (Dir_Path);
7452 Open (Dir, Dir_Path);
7455 Read (Dir, Name_Str, Last);
7459 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
7462 if Osint.File_Names_Case_Sensitive then
7463 Canonical_Name := Name;
7465 Canonical_Case_File_Name (Name_Str (1 .. Last));
7466 Name_Buffer (1 .. Name_Len) := Name_Str (1 .. Last);
7467 Canonical_Name := Name_Find;
7470 NL := Source_Names.Get (Canonical_Name);
7472 if NL /= No_Name_Location and then not NL.Found then
7474 Source_Names.Set (Canonical_Name, NL);
7475 Name_Len := Dir_Path'Length;
7476 Name_Buffer (1 .. Name_Len) := Dir_Path;
7478 if Name_Buffer (Name_Len) /= Directory_Separator then
7479 Add_Char_To_Name_Buffer (Directory_Separator);
7482 Add_Str_To_Name_Buffer (Name_Str (1 .. Last));
7485 if Current_Verbosity = High then
7486 Write_Str (" found ");
7487 Write_Line (Get_Name_String (Name));
7490 -- Register the source if it is an Ada compilation unit
7498 Location => NL.Location,
7499 Current_Source => Current_Source,
7500 Source_Recorded => Source_Recorded,
7501 Current_Dir => Current_Dir);
7508 if Source_Recorded then
7509 In_Tree.String_Elements.Table (Source_Dir).Flag :=
7513 Source_Dir := Element.Next;
7516 -- It is an error if a source file name in a source list or
7517 -- in a source list file is not found.
7519 NL := Source_Names.Get_First;
7520 while NL /= No_Name_Location loop
7521 if not NL.Found then
7522 Err_Vars.Error_Msg_File_1 := NL.Name;
7527 "source file { cannot be found",
7529 First_Error := False;
7534 "\source file { cannot be found",
7539 NL := Source_Names.Get_Next;
7541 end Get_Path_Names_And_Record_Ada_Sources;
7543 --------------------------
7544 -- Check_Naming_Schemes --
7545 --------------------------
7547 procedure Check_Naming_Schemes
7548 (In_Tree : Project_Tree_Ref;
7549 Data : in out Project_Data;
7551 File_Name : File_Name_Type;
7552 Alternate_Languages : out Alternate_Language_Id;
7553 Language : out Language_Index;
7554 Language_Name : out Name_Id;
7555 Display_Language_Name : out Name_Id;
7557 Lang_Kind : out Language_Kind;
7558 Kind : out Source_Kind)
7560 Last : Positive := Filename'Last;
7561 Config : Language_Config;
7562 Lang : Name_List_Index := Data.Languages;
7563 Header_File : Boolean := False;
7564 First_Language : Language_Index;
7567 Last_Spec : Natural;
7568 Last_Body : Natural;
7573 Alternate_Languages := No_Alternate_Language;
7575 while Lang /= No_Name_List loop
7576 Language_Name := In_Tree.Name_Lists.Table (Lang).Name;
7577 Language := Data.First_Language_Processing;
7579 if Current_Verbosity = High then
7581 (" Testing language "
7582 & Get_Name_String (Language_Name)
7583 & " Header_File=" & Header_File'Img);
7586 while Language /= No_Language_Index loop
7587 if In_Tree.Languages_Data.Table (Language).Name =
7590 Display_Language_Name :=
7591 In_Tree.Languages_Data.Table (Language).Display_Name;
7592 Config := In_Tree.Languages_Data.Table (Language).Config;
7593 Lang_Kind := Config.Kind;
7595 if Config.Kind = File_Based then
7597 -- For file based languages, there is no Unit. Just
7598 -- check if the file name has the implementation or,
7599 -- if it is specified, the template suffix of the
7605 and then Config.Naming_Data.Body_Suffix /= No_File
7608 Impl_Suffix : constant String :=
7609 Get_Name_String (Config.Naming_Data.Body_Suffix);
7612 if Filename'Length > Impl_Suffix'Length
7615 (Last - Impl_Suffix'Length + 1 .. Last) =
7620 if Current_Verbosity = High then
7621 Write_Str (" source of language ");
7623 (Get_Name_String (Display_Language_Name));
7631 if Config.Naming_Data.Spec_Suffix /= No_File then
7633 Spec_Suffix : constant String :=
7635 (Config.Naming_Data.Spec_Suffix);
7638 if Filename'Length > Spec_Suffix'Length
7641 (Last - Spec_Suffix'Length + 1 .. Last) =
7646 if Current_Verbosity = High then
7647 Write_Str (" header file of language ");
7649 (Get_Name_String (Display_Language_Name));
7653 Alternate_Language_Table.Increment_Last
7654 (In_Tree.Alt_Langs);
7655 In_Tree.Alt_Langs.Table
7656 (Alternate_Language_Table.Last
7657 (In_Tree.Alt_Langs)) :=
7658 (Language => Language,
7659 Next => Alternate_Languages);
7660 Alternate_Languages :=
7661 Alternate_Language_Table.Last
7662 (In_Tree.Alt_Langs);
7664 Header_File := True;
7665 First_Language := Language;
7671 elsif not Header_File then
7672 -- Unit based language
7674 OK := Config.Naming_Data.Dot_Replacement /= No_File;
7679 -- ??? Are we doing this once per file in the project ?
7680 -- It should be done only once per project.
7682 case Config.Naming_Data.Casing is
7683 when All_Lower_Case =>
7684 for J in Filename'Range loop
7685 if Is_Letter (Filename (J)) then
7686 if not Is_Lower (Filename (J)) then
7693 when All_Upper_Case =>
7694 for J in Filename'Range loop
7695 if Is_Letter (Filename (J)) then
7696 if not Is_Upper (Filename (J)) then
7709 Last_Spec := Natural'Last;
7710 Last_Body := Natural'Last;
7711 Last_Sep := Natural'Last;
7713 if Config.Naming_Data.Separate_Suffix /= No_File
7715 Config.Naming_Data.Separate_Suffix /=
7716 Config.Naming_Data.Body_Suffix
7719 Suffix : constant String :=
7721 (Config.Naming_Data.Separate_Suffix);
7723 if Filename'Length > Suffix'Length
7726 (Last - Suffix'Length + 1 .. Last) =
7729 Last_Sep := Last - Suffix'Length;
7734 if Config.Naming_Data.Body_Suffix /= No_File then
7736 Suffix : constant String :=
7738 (Config.Naming_Data.Body_Suffix);
7740 if Filename'Length > Suffix'Length
7743 (Last - Suffix'Length + 1 .. Last) =
7746 Last_Body := Last - Suffix'Length;
7751 if Config.Naming_Data.Spec_Suffix /= No_File then
7753 Suffix : constant String :=
7755 (Config.Naming_Data.Spec_Suffix);
7757 if Filename'Length > Suffix'Length
7760 (Last - Suffix'Length + 1 .. Last) =
7763 Last_Spec := Last - Suffix'Length;
7769 Last_Min : constant Natural :=
7770 Natural'Min (Natural'Min (Last_Spec,
7775 OK := Last_Min < Last;
7780 if Last_Min = Last_Spec then
7783 elsif Last_Min = Last_Body then
7795 -- Replace dot replacements with dots
7800 J : Positive := Filename'First;
7802 Dot_Replacement : constant String :=
7804 (Config.Naming_Data.
7807 Max : constant Positive :=
7808 Last - Dot_Replacement'Length + 1;
7812 Name_Len := Name_Len + 1;
7814 if J <= Max and then
7816 (J .. J + Dot_Replacement'Length - 1) =
7819 Name_Buffer (Name_Len) := '.';
7820 J := J + Dot_Replacement'Length;
7823 if Filename (J) = '.' then
7828 Name_Buffer (Name_Len) :=
7829 GNAT.Case_Util.To_Lower (Filename (J));
7840 -- The name buffer should contain the name of the
7841 -- the unit, if it is one.
7843 -- Check that this is a valid unit name
7845 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
7847 if Unit /= No_Name then
7849 if Current_Verbosity = High then
7851 Write_Str (" spec of ");
7853 Write_Str (" body of ");
7856 Write_Str (Get_Name_String (Unit));
7857 Write_Str (" (language ");
7859 (Get_Name_String (Display_Language_Name));
7863 -- Comments required, declare block should
7867 Unit_Except : constant Unit_Exception :=
7868 Unit_Exceptions.Get (Unit);
7870 procedure Masked_Unit (Spec : Boolean);
7871 -- Indicate that there is an exception for
7872 -- the same unit, so the file is not a
7873 -- source for the unit.
7879 procedure Masked_Unit (Spec : Boolean) is
7881 if Current_Verbosity = High then
7883 Write_Str (Filename);
7884 Write_Str (""" contains the ");
7893 (" of a unit that is found in """);
7898 (Unit_Except.Spec));
7902 (Unit_Except.Impl));
7905 Write_Line (""" (ignored)");
7908 Language := No_Language_Index;
7913 if Unit_Except.Spec /= No_File
7914 and then Unit_Except.Spec /= File_Name
7916 Masked_Unit (Spec => True);
7920 if Unit_Except.Impl /= No_File
7921 and then Unit_Except.Impl /= File_Name
7923 Masked_Unit (Spec => False);
7934 Language := In_Tree.Languages_Data.Table (Language).Next;
7937 Lang := In_Tree.Name_Lists.Table (Lang).Next;
7940 -- Comment needed here ???
7943 Language := First_Language;
7946 Language := No_Language_Index;
7948 if Current_Verbosity = High then
7949 Write_Line (" not a source of any language");
7952 end Check_Naming_Schemes;
7958 procedure Check_File
7959 (Project : Project_Id;
7960 In_Tree : Project_Tree_Ref;
7961 Data : in out Project_Data;
7963 File_Name : File_Name_Type;
7964 Display_File_Name : File_Name_Type;
7965 Source_Directory : String;
7966 For_All_Sources : Boolean)
7968 Display_Path : constant String :=
7971 Directory => Source_Directory,
7972 Resolve_Links => Opt.Follow_Links_For_Files,
7973 Case_Sensitive => True);
7975 Name_Loc : Name_Location := Source_Names.Get (File_Name);
7976 Path_Id : Path_Name_Type;
7977 Display_Path_Id : Path_Name_Type;
7978 Check_Name : Boolean := False;
7979 Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
7980 Language : Language_Index;
7982 Other_Part : Source_Id;
7984 Src_Ind : Source_File_Index;
7985 Src_Data : Source_Data;
7987 Source_To_Replace : Source_Id := No_Source;
7988 Language_Name : Name_Id;
7989 Display_Language_Name : Name_Id;
7990 Lang_Kind : Language_Kind;
7991 Kind : Source_Kind := Spec;
7994 Name_Len := Display_Path'Length;
7995 Name_Buffer (1 .. Name_Len) := Display_Path;
7996 Display_Path_Id := Name_Find;
7998 if Osint.File_Names_Case_Sensitive then
7999 Path_Id := Display_Path_Id;
8001 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
8002 Path_Id := Name_Find;
8005 if Name_Loc = No_Name_Location then
8006 Check_Name := For_All_Sources;
8009 if Name_Loc.Found then
8011 -- Check if it is OK to have the same file name in several
8012 -- source directories.
8014 if not Data.Known_Order_Of_Source_Dirs then
8015 Error_Msg_File_1 := File_Name;
8018 "{ is found in several source directories",
8023 Name_Loc.Found := True;
8025 Source_Names.Set (File_Name, Name_Loc);
8027 if Name_Loc.Source = No_Source then
8031 In_Tree.Sources.Table (Name_Loc.Source).Path :=
8032 (Path_Id, Display_Path_Id);
8034 Source_Paths_Htable.Set
8035 (In_Tree.Source_Paths_HT,
8039 -- Check if this is a subunit
8041 if In_Tree.Sources.Table (Name_Loc.Source).Unit /= No_Name
8043 In_Tree.Sources.Table (Name_Loc.Source).Kind = Impl
8045 Src_Ind := Sinput.P.Load_Project_File
8046 (Get_Name_String (Path_Id));
8048 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
8049 In_Tree.Sources.Table (Name_Loc.Source).Kind := Sep;
8057 Other_Part := No_Source;
8059 Check_Naming_Schemes
8060 (In_Tree => In_Tree,
8062 Filename => Get_Name_String (File_Name),
8063 File_Name => File_Name,
8064 Alternate_Languages => Alternate_Languages,
8065 Language => Language,
8066 Language_Name => Language_Name,
8067 Display_Language_Name => Display_Language_Name,
8069 Lang_Kind => Lang_Kind,
8072 if Language = No_Language_Index then
8074 -- A file name in a list must be a source of a language
8076 if Name_Loc.Found then
8077 Error_Msg_File_1 := File_Name;
8081 "language unknown for {",
8086 -- Check if the same file name or unit is used in the prj tree
8088 Source := In_Tree.First_Source;
8090 while Source /= No_Source loop
8091 Src_Data := In_Tree.Sources.Table (Source);
8094 and then Src_Data.Unit = Unit
8096 ((Src_Data.Kind = Spec and then Kind = Impl)
8098 (Src_Data.Kind = Impl and then Kind = Spec))
8100 Other_Part := Source;
8102 elsif (Unit /= No_Name
8103 and then Src_Data.Unit = Unit
8105 (Src_Data.Kind = Kind
8107 (Src_Data.Kind = Sep and then Kind = Impl)
8109 (Src_Data.Kind = Impl and then Kind = Sep)))
8110 or else (Unit = No_Name and then Src_Data.File = File_Name)
8112 -- Duplication of file/unit in same project is only
8113 -- allowed if order of source directories is known.
8115 if Project = Src_Data.Project then
8116 if Data.Known_Order_Of_Source_Dirs then
8119 elsif Unit /= No_Name then
8120 Error_Msg_Name_1 := Unit;
8122 (Project, In_Tree, "duplicate unit %%", No_Location);
8126 Error_Msg_File_1 := File_Name;
8128 (Project, In_Tree, "duplicate source file name {",
8133 -- Do not allow the same unit name in different
8134 -- projects, except if one is extending the other.
8136 -- For a file based language, the same file name
8137 -- replaces a file in a project being extended, but
8138 -- it is allowed to have the same file name in
8139 -- unrelated projects.
8142 (Project, Src_Data.Project, In_Tree)
8144 Source_To_Replace := Source;
8146 elsif Unit /= No_Name then
8147 Error_Msg_Name_1 := Unit;
8150 "unit %% cannot belong to several projects",
8153 Error_Msg_Name_1 := In_Tree.Projects.Table (Project).Name;
8154 Error_Msg_Name_2 := Name_Id (Display_Path_Id);
8156 (Project, In_Tree, "\ project %%, %%", No_Location);
8159 In_Tree.Projects.Table (Src_Data.Project).Name;
8160 Error_Msg_Name_2 := Name_Id (Src_Data.Path.Display_Name);
8162 (Project, In_Tree, "\ project %%, %%", No_Location);
8168 Source := Src_Data.Next_In_Sources;
8177 Lang => Language_Name,
8178 Lang_Id => Language,
8179 Lang_Kind => Lang_Kind,
8181 Alternate_Languages => Alternate_Languages,
8182 File_Name => File_Name,
8183 Display_File => Display_File_Name,
8184 Other_Part => Other_Part,
8187 Display_Path => Display_Path_Id,
8188 Source_To_Replace => Source_To_Replace);
8194 ------------------------
8195 -- Search_Directories --
8196 ------------------------
8198 procedure Search_Directories
8199 (Project : Project_Id;
8200 In_Tree : Project_Tree_Ref;
8201 Data : in out Project_Data;
8202 For_All_Sources : Boolean)
8204 Source_Dir : String_List_Id;
8205 Element : String_Element;
8207 Name : String (1 .. 1_000);
8209 File_Name : File_Name_Type;
8210 Display_File_Name : File_Name_Type;
8213 if Current_Verbosity = High then
8214 Write_Line ("Looking for sources:");
8217 -- Loop through subdirectories
8219 Source_Dir := Data.Source_Dirs;
8220 while Source_Dir /= Nil_String loop
8222 Element := In_Tree.String_Elements.Table (Source_Dir);
8223 if Element.Value /= No_Name then
8224 Get_Name_String (Element.Display_Value);
8227 Source_Directory : constant String :=
8228 Name_Buffer (1 .. Name_Len) &
8229 Directory_Separator;
8231 Dir_Last : constant Natural :=
8232 Compute_Directory_Last
8236 if Current_Verbosity = High then
8237 Write_Str ("Source_Dir = ");
8238 Write_Line (Source_Directory);
8241 -- We look to every entry in the source directory
8243 Open (Dir, Source_Directory);
8246 Read (Dir, Name, Last);
8250 -- ??? Duplicate system call here, we just did a
8251 -- a similar one. Maybe Ada.Directories would be more
8255 (Source_Directory & Name (1 .. Last))
8257 if Current_Verbosity = High then
8258 Write_Str (" Checking ");
8259 Write_Line (Name (1 .. Last));
8263 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8264 Display_File_Name := Name_Find;
8266 if Osint.File_Names_Case_Sensitive then
8267 File_Name := Display_File_Name;
8269 Canonical_Case_File_Name
8270 (Name_Buffer (1 .. Name_Len));
8271 File_Name := Name_Find;
8276 Excluded_Sources_Htable.Get (File_Name);
8279 if FF /= No_File_Found then
8280 if not FF.Found then
8282 Excluded_Sources_Htable.Set
8285 if Current_Verbosity = High then
8286 Write_Str (" excluded source """);
8287 Write_Str (Get_Name_String (File_Name));
8294 (Project => Project,
8297 Name => Name (1 .. Last),
8298 File_Name => File_Name,
8299 Display_File_Name => Display_File_Name,
8300 Source_Directory => Source_Directory
8301 (Source_Directory'First .. Dir_Last),
8302 For_All_Sources => For_All_Sources);
8313 when Directory_Error =>
8317 Source_Dir := Element.Next;
8320 if Current_Verbosity = High then
8321 Write_Line ("end Looking for sources.");
8323 end Search_Directories;
8325 ----------------------
8326 -- Look_For_Sources --
8327 ----------------------
8329 procedure Look_For_Sources
8330 (Project : Project_Id;
8331 In_Tree : Project_Tree_Ref;
8332 Data : in out Project_Data;
8333 Current_Dir : String)
8335 procedure Remove_Locally_Removed_Files_From_Units;
8336 -- Mark all locally removed sources as such in the Units table
8338 procedure Process_Sources_In_Multi_Language_Mode;
8339 -- Find all source files when in multi language mode
8341 ---------------------------------------------
8342 -- Remove_Locally_Removed_Files_From_Units --
8343 ---------------------------------------------
8345 procedure Remove_Locally_Removed_Files_From_Units is
8346 Excluded : File_Found;
8349 Extended : Project_Id;
8352 Excluded := Excluded_Sources_Htable.Get_First;
8353 while Excluded /= No_File_Found loop
8357 for Index in Unit_Table.First ..
8358 Unit_Table.Last (In_Tree.Units)
8360 Unit := In_Tree.Units.Table (Index);
8362 for Kind in Spec_Or_Body'Range loop
8363 if Unit.File_Names (Kind).Name = Excluded.File then
8366 -- Check that this is from the current project or
8367 -- that the current project extends.
8369 Extended := Unit.File_Names (Kind).Project;
8371 if Extended = Project
8372 or else Project_Extends (Project, Extended, In_Tree)
8374 Unit.File_Names (Kind).Path.Name := Slash;
8375 Unit.File_Names (Kind).Needs_Pragma := False;
8376 In_Tree.Units.Table (Index) := Unit;
8377 Add_Forbidden_File_Name
8378 (Unit.File_Names (Kind).Name);
8382 "cannot remove a source from " &
8389 end loop For_Each_Unit;
8392 Err_Vars.Error_Msg_File_1 := Excluded.File;
8394 (Project, In_Tree, "unknown file {", Excluded.Location);
8397 Excluded := Excluded_Sources_Htable.Get_Next;
8399 end Remove_Locally_Removed_Files_From_Units;
8401 --------------------------------------------
8402 -- Process_Sources_In_Multi_Language_Mode --
8403 --------------------------------------------
8405 procedure Process_Sources_In_Multi_Language_Mode is
8407 Src_Data : Source_Data;
8408 Name_Loc : Name_Location;
8413 -- First, put all naming exceptions if any, in the Source_Names table
8415 Unit_Exceptions.Reset;
8417 Source := Data.First_Source;
8418 while Source /= No_Source loop
8419 Src_Data := In_Tree.Sources.Table (Source);
8421 -- A file that is excluded cannot also be an exception file name
8423 if Excluded_Sources_Htable.Get (Src_Data.File) /=
8426 Error_Msg_File_1 := Src_Data.File;
8429 "{ cannot be both excluded and an exception file name",
8433 Name_Loc := (Name => Src_Data.File,
8434 Location => No_Location,
8436 Except => Src_Data.Unit /= No_Name,
8439 if Current_Verbosity = High then
8440 Write_Str ("Putting source #");
8441 Write_Str (Source'Img);
8442 Write_Str (", file ");
8443 Write_Str (Get_Name_String (Src_Data.File));
8444 Write_Line (" in Source_Names");
8447 Source_Names.Set (K => Src_Data.File, E => Name_Loc);
8449 -- If this is an Ada exception, record it in table Unit_Exceptions
8451 if Src_Data.Unit /= No_Name then
8453 Unit_Except : Unit_Exception :=
8454 Unit_Exceptions.Get (Src_Data.Unit);
8457 Unit_Except.Name := Src_Data.Unit;
8459 if Src_Data.Kind = Spec then
8460 Unit_Except.Spec := Src_Data.File;
8462 Unit_Except.Impl := Src_Data.File;
8465 Unit_Exceptions.Set (Src_Data.Unit, Unit_Except);
8469 Source := Src_Data.Next_In_Project;
8472 Find_Explicit_Sources
8473 (Current_Dir, Project, In_Tree, Data);
8475 -- Mark as such the sources that are declared as excluded
8477 FF := Excluded_Sources_Htable.Get_First;
8478 while FF /= No_File_Found loop
8480 Source := In_Tree.First_Source;
8482 while Source /= No_Source loop
8483 Src_Data := In_Tree.Sources.Table (Source);
8485 if Src_Data.File = FF.File then
8487 -- Check that this is from this project or a project that
8488 -- the current project extends.
8490 if Src_Data.Project = Project or else
8491 Is_Extending (Project, Src_Data.Project, In_Tree)
8493 Src_Data.Locally_Removed := True;
8494 Src_Data.In_Interfaces := False;
8495 In_Tree.Sources.Table (Source) := Src_Data;
8496 Add_Forbidden_File_Name (FF.File);
8502 Source := Src_Data.Next_In_Sources;
8505 if not FF.Found and not OK then
8506 Err_Vars.Error_Msg_File_1 := FF.File;
8507 Error_Msg (Project, In_Tree, "unknown file {", FF.Location);
8510 FF := Excluded_Sources_Htable.Get_Next;
8513 -- Check that two sources of this project do not have the same object
8516 Check_Object_File_Names : declare
8518 Src_Data : Source_Data;
8519 Source_Name : File_Name_Type;
8521 procedure Check_Object;
8522 -- Check if object file name of the current source is already in
8523 -- hash table Object_File_Names. If it is, report an error. If it
8524 -- is not, put it there with the file name of the current source.
8530 procedure Check_Object is
8532 Source_Name := Object_File_Names.Get (Src_Data.Object);
8534 if Source_Name /= No_File then
8535 Error_Msg_File_1 := Src_Data.File;
8536 Error_Msg_File_2 := Source_Name;
8540 "{ and { have the same object file name",
8544 Object_File_Names.Set (Src_Data.Object, Src_Data.File);
8548 -- Start of processing for Check_Object_File_Names
8551 Object_File_Names.Reset;
8552 Src_Id := In_Tree.First_Source;
8553 while Src_Id /= No_Source loop
8554 Src_Data := In_Tree.Sources.Table (Src_Id);
8556 if Src_Data.Compiled and then Src_Data.Object_Exists
8557 and then Project_Extends (Project, Src_Data.Project, In_Tree)
8559 if Src_Data.Unit = No_Name then
8560 if Src_Data.Kind = Impl then
8565 case Src_Data.Kind is
8567 if Src_Data.Other_Part = No_Source then
8575 if Src_Data.Other_Part /= No_Source then
8579 -- Check if it is a subunit
8582 Src_Ind : constant Source_File_Index :=
8583 Sinput.P.Load_Project_File
8585 (Src_Data.Path.Name));
8588 if Sinput.P.Source_File_Is_Subunit
8591 In_Tree.Sources.Table (Src_Id).Kind := Sep;
8601 Src_Id := Src_Data.Next_In_Sources;
8603 end Check_Object_File_Names;
8604 end Process_Sources_In_Multi_Language_Mode;
8606 -- Start of processing for Look_For_Sources
8610 Find_Excluded_Sources (Project, In_Tree, Data);
8614 if Is_A_Language (In_Tree, Data, Name_Ada) then
8615 Find_Explicit_Sources (Current_Dir, Project, In_Tree, Data);
8616 Remove_Locally_Removed_Files_From_Units;
8619 when Multi_Language =>
8620 if Data.First_Language_Processing /= No_Language_Index then
8621 Process_Sources_In_Multi_Language_Mode;
8624 end Look_For_Sources;
8630 function Path_Name_Of
8631 (File_Name : File_Name_Type;
8632 Directory : Path_Name_Type) return String
8634 Result : String_Access;
8635 The_Directory : constant String := Get_Name_String (Directory);
8638 Get_Name_String (File_Name);
8641 (File_Name => Name_Buffer (1 .. Name_Len),
8642 Path => The_Directory);
8644 if Result = null then
8647 Canonical_Case_File_Name (Result.all);
8652 -------------------------------
8653 -- Prepare_Ada_Naming_Exceptions --
8654 -------------------------------
8656 procedure Prepare_Ada_Naming_Exceptions
8657 (List : Array_Element_Id;
8658 In_Tree : Project_Tree_Ref;
8659 Kind : Spec_Or_Body)
8661 Current : Array_Element_Id;
8662 Element : Array_Element;
8666 -- Traverse the list
8669 while Current /= No_Array_Element loop
8670 Element := In_Tree.Array_Elements.Table (Current);
8672 if Element.Index /= No_Name then
8675 Unit => Element.Index,
8676 Next => No_Ada_Naming_Exception);
8677 Reverse_Ada_Naming_Exceptions.Set
8678 (Unit, (Element.Value.Value, Element.Value.Index));
8680 Ada_Naming_Exceptions.Get (File_Name_Type (Element.Value.Value));
8681 Ada_Naming_Exception_Table.Increment_Last;
8682 Ada_Naming_Exception_Table.Table
8683 (Ada_Naming_Exception_Table.Last) := Unit;
8684 Ada_Naming_Exceptions.Set
8685 (File_Name_Type (Element.Value.Value),
8686 Ada_Naming_Exception_Table.Last);
8689 Current := Element.Next;
8691 end Prepare_Ada_Naming_Exceptions;
8693 ---------------------
8694 -- Project_Extends --
8695 ---------------------
8697 function Project_Extends
8698 (Extending : Project_Id;
8699 Extended : Project_Id;
8700 In_Tree : Project_Tree_Ref) return Boolean
8702 Current : Project_Id := Extending;
8706 if Current = No_Project then
8709 elsif Current = Extended then
8713 Current := In_Tree.Projects.Table (Current).Extends;
8715 end Project_Extends;
8717 -----------------------
8718 -- Record_Ada_Source --
8719 -----------------------
8721 procedure Record_Ada_Source
8722 (File_Name : File_Name_Type;
8723 Path_Name : Path_Name_Type;
8724 Project : Project_Id;
8725 In_Tree : Project_Tree_Ref;
8726 Data : in out Project_Data;
8727 Location : Source_Ptr;
8728 Current_Source : in out String_List_Id;
8729 Source_Recorded : in out Boolean;
8730 Current_Dir : String)
8732 Canonical_File_Name : File_Name_Type;
8733 Canonical_Path_Name : Path_Name_Type;
8735 Exception_Id : Ada_Naming_Exception_Id;
8736 Unit_Name : Name_Id;
8737 Unit_Kind : Spec_Or_Body;
8738 Unit_Ind : Int := 0;
8740 Name_Index : Name_And_Index;
8741 Needs_Pragma : Boolean;
8743 The_Location : Source_Ptr := Location;
8744 Previous_Source : constant String_List_Id := Current_Source;
8745 Except_Name : Name_And_Index := No_Name_And_Index;
8747 Unit_Prj : Unit_Project;
8749 File_Name_Recorded : Boolean := False;
8752 if Osint.File_Names_Case_Sensitive then
8753 Canonical_File_Name := File_Name;
8754 Canonical_Path_Name := Path_Name;
8756 Get_Name_String (File_Name);
8757 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
8758 Canonical_File_Name := Name_Find;
8761 Canonical_Path : constant String :=
8763 (Get_Name_String (Path_Name),
8764 Directory => Current_Dir,
8765 Resolve_Links => Opt.Follow_Links_For_Files,
8766 Case_Sensitive => False);
8769 Add_Str_To_Name_Buffer (Canonical_Path);
8770 Canonical_Path_Name := Name_Find;
8774 -- Find out the unit name, the unit kind and if it needs
8775 -- a specific SFN pragma.
8778 (In_Tree => In_Tree,
8779 Canonical_File_Name => Canonical_File_Name,
8780 Naming => Data.Naming,
8781 Exception_Id => Exception_Id,
8782 Unit_Name => Unit_Name,
8783 Unit_Kind => Unit_Kind,
8784 Needs_Pragma => Needs_Pragma);
8786 if Exception_Id = No_Ada_Naming_Exception
8787 and then Unit_Name = No_Name
8789 if Current_Verbosity = High then
8791 Write_Str (Get_Name_String (Canonical_File_Name));
8792 Write_Line (""" is not a valid source file name (ignored).");
8796 -- Check to see if the source has been hidden by an exception,
8797 -- but only if it is not an exception.
8799 if not Needs_Pragma then
8801 Reverse_Ada_Naming_Exceptions.Get
8802 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
8804 if Except_Name /= No_Name_And_Index then
8805 if Current_Verbosity = High then
8807 Write_Str (Get_Name_String (Canonical_File_Name));
8808 Write_Str (""" contains a unit that is found in """);
8809 Write_Str (Get_Name_String (Except_Name.Name));
8810 Write_Line (""" (ignored).");
8813 -- The file is not included in the source of the project since
8814 -- it is hidden by the exception. So, nothing else to do.
8821 if Exception_Id /= No_Ada_Naming_Exception then
8822 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
8823 Exception_Id := Info.Next;
8824 Info.Next := No_Ada_Naming_Exception;
8825 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
8827 Unit_Name := Info.Unit;
8828 Unit_Ind := Name_Index.Index;
8829 Unit_Kind := Info.Kind;
8832 -- Put the file name in the list of sources of the project
8834 String_Element_Table.Increment_Last (In_Tree.String_Elements);
8835 In_Tree.String_Elements.Table
8836 (String_Element_Table.Last (In_Tree.String_Elements)) :=
8837 (Value => Name_Id (Canonical_File_Name),
8838 Display_Value => Name_Id (File_Name),
8839 Location => No_Location,
8844 if Current_Source = Nil_String then
8846 String_Element_Table.Last (In_Tree.String_Elements);
8848 In_Tree.String_Elements.Table (Current_Source).Next :=
8849 String_Element_Table.Last (In_Tree.String_Elements);
8853 String_Element_Table.Last (In_Tree.String_Elements);
8855 -- Put the unit in unit list
8858 The_Unit : Unit_Index :=
8859 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
8861 The_Unit_Data : Unit_Data;
8864 if Current_Verbosity = High then
8865 Write_Str ("Putting ");
8866 Write_Str (Get_Name_String (Unit_Name));
8867 Write_Line (" in the unit list.");
8870 -- The unit is already in the list, but may be it is
8871 -- only the other unit kind (spec or body), or what is
8872 -- in the unit list is a unit of a project we are extending.
8874 if The_Unit /= No_Unit_Index then
8875 The_Unit_Data := In_Tree.Units.Table (The_Unit);
8877 if (The_Unit_Data.File_Names (Unit_Kind).Name =
8880 The_Unit_Data.File_Names
8881 (Unit_Kind).Path.Name = Slash)
8882 or else The_Unit_Data.File_Names (Unit_Kind).Name = No_File
8883 or else Project_Extends
8885 The_Unit_Data.File_Names (Unit_Kind).Project,
8889 The_Unit_Data.File_Names (Unit_Kind).Path.Name = Slash
8891 Remove_Forbidden_File_Name
8892 (The_Unit_Data.File_Names (Unit_Kind).Name);
8895 -- Record the file name in the hash table Files_Htable
8897 Unit_Prj := (Unit => The_Unit, Project => Project);
8900 Canonical_File_Name,
8903 The_Unit_Data.File_Names (Unit_Kind) :=
8904 (Name => Canonical_File_Name,
8906 Display_Name => File_Name,
8907 Path => (Canonical_Path_Name, Path_Name),
8909 Needs_Pragma => Needs_Pragma);
8910 In_Tree.Units.Table (The_Unit) := The_Unit_Data;
8911 Source_Recorded := True;
8913 elsif The_Unit_Data.File_Names (Unit_Kind).Project = Project
8914 and then (Data.Known_Order_Of_Source_Dirs
8916 The_Unit_Data.File_Names
8917 (Unit_Kind).Path.Name = Canonical_Path_Name)
8919 if Previous_Source = Nil_String then
8920 Data.Ada_Sources := Nil_String;
8922 In_Tree.String_Elements.Table (Previous_Source).Next :=
8924 String_Element_Table.Decrement_Last
8925 (In_Tree.String_Elements);
8928 Current_Source := Previous_Source;
8931 -- It is an error to have two units with the same name
8932 -- and the same kind (spec or body).
8934 if The_Location = No_Location then
8936 In_Tree.Projects.Table (Project).Location;
8939 Err_Vars.Error_Msg_Name_1 := Unit_Name;
8941 (Project, In_Tree, "duplicate unit %%", The_Location);
8943 Err_Vars.Error_Msg_Name_1 :=
8944 In_Tree.Projects.Table
8945 (The_Unit_Data.File_Names (Unit_Kind).Project).Name;
8946 Err_Vars.Error_Msg_File_1 :=
8948 (The_Unit_Data.File_Names (Unit_Kind).Path.Name);
8951 "\ project file %%, {", The_Location);
8953 Err_Vars.Error_Msg_Name_1 :=
8954 In_Tree.Projects.Table (Project).Name;
8955 Err_Vars.Error_Msg_File_1 :=
8956 File_Name_Type (Canonical_Path_Name);
8959 "\ project file %%, {", The_Location);
8962 -- It is a new unit, create a new record
8965 -- First, check if there is no other unit with this file
8966 -- name in another project. If it is, report error but note
8967 -- we do that only for the first unit in the source file.
8970 Files_Htable.Get (In_Tree.Files_HT, Canonical_File_Name);
8972 if not File_Name_Recorded and then
8973 Unit_Prj /= No_Unit_Project
8975 Error_Msg_File_1 := File_Name;
8977 In_Tree.Projects.Table (Unit_Prj.Project).Name;
8980 "{ is already a source of project %%",
8984 Unit_Table.Increment_Last (In_Tree.Units);
8985 The_Unit := Unit_Table.Last (In_Tree.Units);
8987 (In_Tree.Units_HT, Unit_Name, The_Unit);
8988 Unit_Prj := (Unit => The_Unit, Project => Project);
8991 Canonical_File_Name,
8993 The_Unit_Data.Name := Unit_Name;
8994 The_Unit_Data.File_Names (Unit_Kind) :=
8995 (Name => Canonical_File_Name,
8997 Display_Name => File_Name,
8998 Path => (Canonical_Path_Name, Path_Name),
9000 Needs_Pragma => Needs_Pragma);
9001 In_Tree.Units.Table (The_Unit) := The_Unit_Data;
9002 Source_Recorded := True;
9007 exit when Exception_Id = No_Ada_Naming_Exception;
9008 File_Name_Recorded := True;
9011 end Record_Ada_Source;
9017 procedure Remove_Source
9019 Replaced_By : Source_Id;
9020 Project : Project_Id;
9021 Data : in out Project_Data;
9022 In_Tree : Project_Tree_Ref)
9024 Src_Data : constant Source_Data := In_Tree.Sources.Table (Id);
9028 if Current_Verbosity = High then
9029 Write_Str ("Removing source #");
9030 Write_Line (Id'Img);
9033 if Replaced_By /= No_Source then
9034 In_Tree.Sources.Table (Id).Replaced_By := Replaced_By;
9035 In_Tree.Sources.Table (Replaced_By).Declared_In_Interfaces :=
9036 In_Tree.Sources.Table (Id).Declared_In_Interfaces;
9039 -- Remove the source from the global source list
9041 Source := In_Tree.First_Source;
9044 In_Tree.First_Source := Src_Data.Next_In_Sources;
9047 while In_Tree.Sources.Table (Source).Next_In_Sources /= Id loop
9048 Source := In_Tree.Sources.Table (Source).Next_In_Sources;
9051 In_Tree.Sources.Table (Source).Next_In_Sources :=
9052 Src_Data.Next_In_Sources;
9055 -- Remove the source from the project list
9057 if Src_Data.Project = Project then
9058 Source := Data.First_Source;
9061 Data.First_Source := Src_Data.Next_In_Project;
9063 if Src_Data.Next_In_Project = No_Source then
9064 Data.Last_Source := No_Source;
9068 while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
9069 Source := In_Tree.Sources.Table (Source).Next_In_Project;
9072 In_Tree.Sources.Table (Source).Next_In_Project :=
9073 Src_Data.Next_In_Project;
9075 if Src_Data.Next_In_Project = No_Source then
9076 In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
9081 Source := In_Tree.Projects.Table (Src_Data.Project).First_Source;
9084 In_Tree.Projects.Table (Src_Data.Project).First_Source :=
9085 Src_Data.Next_In_Project;
9087 if Src_Data.Next_In_Project = No_Source then
9088 In_Tree.Projects.Table (Src_Data.Project).Last_Source :=
9093 while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
9094 Source := In_Tree.Sources.Table (Source).Next_In_Project;
9097 In_Tree.Sources.Table (Source).Next_In_Project :=
9098 Src_Data.Next_In_Project;
9100 if Src_Data.Next_In_Project = No_Source then
9101 In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
9106 -- Remove source from the language list
9108 Source := In_Tree.Languages_Data.Table (Src_Data.Language).First_Source;
9111 In_Tree.Languages_Data.Table (Src_Data.Language).First_Source :=
9112 Src_Data.Next_In_Lang;
9115 while In_Tree.Sources.Table (Source).Next_In_Lang /= Id loop
9116 Source := In_Tree.Sources.Table (Source).Next_In_Lang;
9119 In_Tree.Sources.Table (Source).Next_In_Lang :=
9120 Src_Data.Next_In_Lang;
9124 -----------------------
9125 -- Report_No_Sources --
9126 -----------------------
9128 procedure Report_No_Sources
9129 (Project : Project_Id;
9131 In_Tree : Project_Tree_Ref;
9132 Location : Source_Ptr;
9133 Continuation : Boolean := False)
9136 case When_No_Sources is
9140 when Warning | Error =>
9142 Msg : constant String :=
9145 " sources in this project";
9148 Error_Msg_Warn := When_No_Sources = Warning;
9150 if Continuation then
9152 (Project, In_Tree, "\" & Msg, Location);
9156 (Project, In_Tree, Msg, Location);
9160 end Report_No_Sources;
9162 ----------------------
9163 -- Show_Source_Dirs --
9164 ----------------------
9166 procedure Show_Source_Dirs
9167 (Data : Project_Data;
9168 In_Tree : Project_Tree_Ref)
9170 Current : String_List_Id;
9171 Element : String_Element;
9174 Write_Line ("Source_Dirs:");
9176 Current := Data.Source_Dirs;
9177 while Current /= Nil_String loop
9178 Element := In_Tree.String_Elements.Table (Current);
9180 Write_Line (Get_Name_String (Element.Value));
9181 Current := Element.Next;
9184 Write_Line ("end Source_Dirs.");
9185 end Show_Source_Dirs;
9187 -------------------------
9188 -- Warn_If_Not_Sources --
9189 -------------------------
9191 -- comments needed in this body ???
9193 procedure Warn_If_Not_Sources
9194 (Project : Project_Id;
9195 In_Tree : Project_Tree_Ref;
9196 Conventions : Array_Element_Id;
9198 Extending : Boolean)
9200 Conv : Array_Element_Id;
9202 The_Unit_Id : Unit_Index;
9203 The_Unit_Data : Unit_Data;
9204 Location : Source_Ptr;
9207 Conv := Conventions;
9208 while Conv /= No_Array_Element loop
9209 Unit := In_Tree.Array_Elements.Table (Conv).Index;
9210 Error_Msg_Name_1 := Unit;
9211 Get_Name_String (Unit);
9212 To_Lower (Name_Buffer (1 .. Name_Len));
9214 The_Unit_Id := Units_Htable.Get (In_Tree.Units_HT, Unit);
9215 Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
9217 if The_Unit_Id = No_Unit_Index then
9218 Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
9221 The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
9223 In_Tree.Array_Elements.Table (Conv).Value.Value;
9226 if not Check_Project
9227 (The_Unit_Data.File_Names (Specification).Project,
9228 Project, In_Tree, Extending)
9232 "?source of spec of unit %% (%%)" &
9233 " cannot be found in this project",
9238 if not Check_Project
9239 (The_Unit_Data.File_Names (Body_Part).Project,
9240 Project, In_Tree, Extending)
9244 "?source of body of unit %% (%%)" &
9245 " cannot be found in this project",
9251 Conv := In_Tree.Array_Elements.Table (Conv).Next;
9253 end Warn_If_Not_Sources;