1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2009, 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.
78 -- Except is set to True if source is a naming exception in the project.
80 No_Name_Location : constant Name_Location :=
82 Location => No_Location,
87 package Source_Names is new GNAT.HTable.Simple_HTable
88 (Header_Num => Header_Num,
89 Element => Name_Location,
90 No_Element => No_Name_Location,
91 Key => File_Name_Type,
94 -- Hash table to store file names found in string list attribute
95 -- Source_Files or in a source list file, stored in hash table
96 -- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
98 -- More documentation needed on what unit exceptions are about ???
100 type Unit_Exception is record
102 Spec : File_Name_Type;
103 Impl : File_Name_Type;
105 -- Record special naming schemes for Ada units (name of spec file and name
106 -- of implementation file).
108 No_Unit_Exception : constant Unit_Exception :=
113 package Unit_Exceptions is new GNAT.HTable.Simple_HTable
114 (Header_Num => Header_Num,
115 Element => Unit_Exception,
116 No_Element => No_Unit_Exception,
120 -- Hash table to store the unit exceptions.
121 -- ??? Seems to be used only by the multi_lang mode
122 -- ??? Should not be a global array, but stored in the project_data
124 package Recursive_Dirs is new GNAT.HTable.Simple_HTable
125 (Header_Num => Header_Num,
131 -- Hash table to store recursive source directories, to avoid looking
132 -- several times, and to avoid cycles that may be introduced by symbolic
135 type Ada_Naming_Exception_Id is new Nat;
136 No_Ada_Naming_Exception : constant Ada_Naming_Exception_Id := 0;
138 type Unit_Info is record
141 Next : Ada_Naming_Exception_Id := No_Ada_Naming_Exception;
145 package Ada_Naming_Exception_Table is new Table.Table
146 (Table_Component_Type => Unit_Info,
147 Table_Index_Type => Ada_Naming_Exception_Id,
148 Table_Low_Bound => 1,
150 Table_Increment => 100,
151 Table_Name => "Prj.Nmsc.Ada_Naming_Exception_Table");
153 package Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
154 (Header_Num => Header_Num,
155 Element => Ada_Naming_Exception_Id,
156 No_Element => No_Ada_Naming_Exception,
157 Key => File_Name_Type,
160 -- A hash table to store naming exceptions for Ada. For each file name
161 -- there is one or several unit in table Ada_Naming_Exception_Table.
162 -- ??? This is for ada_only mode, we should be able to merge with
163 -- Unit_Exceptions table, used by multi_lang mode.
165 package Object_File_Names is new GNAT.HTable.Simple_HTable
166 (Header_Num => Header_Num,
167 Element => File_Name_Type,
168 No_Element => No_File,
169 Key => File_Name_Type,
172 -- A hash table to store the object file names for a project, to check that
173 -- two different sources have different object file names.
175 type File_Found is record
176 File : File_Name_Type := No_File;
177 Found : Boolean := False;
178 Location : Source_Ptr := No_Location;
180 No_File_Found : constant File_Found := (No_File, False, No_Location);
181 -- Comments needed ???
183 package Excluded_Sources_Htable is new GNAT.HTable.Simple_HTable
184 (Header_Num => Header_Num,
185 Element => File_Found,
186 No_Element => No_File_Found,
187 Key => File_Name_Type,
190 -- A hash table to store the excluded files, if any. This is filled by
191 -- Find_Excluded_Sources below.
193 procedure Find_Excluded_Sources
194 (Project : Project_Id;
195 In_Tree : Project_Tree_Ref);
196 -- Find the list of files that should not be considered as source files
197 -- for this project. Sets the list in the Excluded_Sources_Htable.
199 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
200 -- Override the reference kind for a source file. This properly updates
201 -- the unit data if necessary.
203 function Hash (Unit : Unit_Info) return Header_Num;
205 type Name_And_Index is record
206 Name : Name_Id := No_Name;
209 No_Name_And_Index : constant Name_And_Index :=
210 (Name => No_Name, Index => 0);
211 -- Name of a unit, and its index inside the source file. The first unit has
212 -- index 1 (see doc for pragma Source_File_Name), but the index might be
213 -- set to 0 when the source file contains a single unit.
215 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
216 (Header_Num => Header_Num,
217 Element => Name_And_Index,
218 No_Element => No_Name_And_Index,
222 -- A table to check if a unit with an exceptional name will hide a source
223 -- with a file name following the naming convention.
225 procedure Load_Naming_Exceptions
226 (Project : Project_Id;
227 In_Tree : Project_Tree_Ref);
228 -- All source files in Data.First_Source are considered as naming
229 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
234 In_Tree : Project_Tree_Ref;
235 Project : Project_Id;
236 Lang_Id : Language_Ptr;
238 File_Name : File_Name_Type;
239 Display_File : File_Name_Type;
240 Naming_Exception : Boolean := False;
241 Path : Path_Information := No_Path_Information;
242 Alternate_Languages : Language_List := null;
243 Other_Part : Source_Id := No_Source;
244 Unit : Name_Id := No_Name;
246 Source_To_Replace : Source_Id := No_Source);
247 -- Add a new source to the different lists: list of all sources in the
248 -- project tree, list of source of a project and list of sources of a
251 -- If Path is specified, the file is also added to Source_Paths_HT.
252 -- If Source_To_Replace is specified, it points to the source in the
253 -- extended project that the new file is overriding.
255 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
256 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
257 -- This alters Name_Buffer
259 function Suffix_Matches
261 Suffix : File_Name_Type) return Boolean;
262 -- True if the file name ends with the given suffix. Always returns False
263 -- if Suffix is No_Name.
265 procedure Replace_Into_Name_Buffer
268 Replacement : Character);
269 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
270 -- converted to lower-case at the same time.
272 function ALI_File_Name (Source : String) return String;
273 -- Return the ALI file name corresponding to a source
275 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
276 -- Check that a name is a valid Ada unit name
278 procedure Check_Naming_Schemes
279 (Project : Project_Id;
280 In_Tree : Project_Tree_Ref;
281 Is_Config_File : Boolean);
282 -- Check the naming scheme part of Data.
283 -- Is_Config_File should be True if Project is a config file (.cgpr)
285 procedure Check_Configuration
286 (Project : Project_Id;
287 In_Tree : Project_Tree_Ref;
288 Compiler_Driver_Mandatory : Boolean);
289 -- Check the configuration attributes for the project
290 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
291 -- for each language must be defined, or we will not look for its source
294 procedure Check_If_Externally_Built
295 (Project : Project_Id;
296 In_Tree : Project_Tree_Ref);
297 -- Check attribute Externally_Built of project Project in project tree
298 -- In_Tree and modify its data Data if it has the value "true".
300 procedure Check_Interfaces
301 (Project : Project_Id;
302 In_Tree : Project_Tree_Ref);
303 -- If a list of sources is specified in attribute Interfaces, set
304 -- In_Interfaces only for the sources specified in the list.
306 procedure Check_Library_Attributes
307 (Project : Project_Id;
308 In_Tree : Project_Tree_Ref);
309 -- Check the library attributes of project Project in project tree In_Tree
310 -- and modify its data Data accordingly.
311 -- Current_Dir should represent the current directory, and is passed for
312 -- efficiency to avoid system calls to recompute it.
314 procedure Check_Package_Naming
315 (Project : Project_Id;
316 In_Tree : Project_Tree_Ref);
317 -- Check package Naming of project Project in project tree In_Tree and
318 -- modify its data Data accordingly.
320 procedure Check_Programming_Languages
321 (In_Tree : Project_Tree_Ref;
322 Project : Project_Id);
323 -- Check attribute Languages for the project with data Data in project
324 -- tree In_Tree and set the components of Data for all the programming
325 -- languages indicated in attribute Languages, if any.
327 function Check_Project
329 Root_Project : Project_Id;
330 Extending : Boolean) return Boolean;
331 -- Returns True if P is Root_Project or, if Extending is True, a project
332 -- extended by Root_Project.
334 procedure Check_Stand_Alone_Library
335 (Project : Project_Id;
336 In_Tree : Project_Tree_Ref;
337 Current_Dir : String;
338 Extending : Boolean);
339 -- Check if project Project in project tree In_Tree is a Stand-Alone
340 -- Library project, and modify its data Data accordingly if it is one.
341 -- Current_Dir should represent the current directory, and is passed for
342 -- efficiency to avoid system calls to recompute it.
344 procedure Check_And_Normalize_Unit_Names
345 (Project : Project_Id;
346 In_Tree : Project_Tree_Ref;
347 List : Array_Element_Id;
348 Debug_Name : String);
349 -- Check that a list of unit names contains only valid names. Casing
350 -- is normalized where appropriate.
351 -- Debug_Name is the name representing the list, and is used for debug
354 procedure Find_Ada_Sources
355 (Project : Project_Id;
356 In_Tree : Project_Tree_Ref;
357 Explicit_Sources_Only : Boolean;
358 Proc_Data : in out Processing_Data);
359 -- Find all Ada sources by traversing all source directories.
360 -- If Explicit_Sources_Only is True, then the sources found must belong to
361 -- the list of sources specified explicitly in the project file.
362 -- If Explicit_Sources_Only is False, then all sources matching the naming
363 -- scheme are recorded.
365 function Compute_Directory_Last (Dir : String) return Natural;
366 -- Return the index of the last significant character in Dir. This is used
367 -- to avoid duplicate '/' (slash) characters at the end of directory names.
370 (Project : Project_Id;
371 In_Tree : Project_Tree_Ref;
373 Flag_Location : Source_Ptr);
374 -- Output an error message. If Error_Report is null, simply call
375 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
378 procedure Search_Directories
379 (Project : Project_Id;
380 In_Tree : Project_Tree_Ref;
381 For_All_Sources : Boolean);
382 -- Search the source directories to find the sources.
383 -- If For_All_Sources is True, check each regular file name against the
384 -- naming schemes of the different languages. Otherwise consider only the
385 -- file names in the hash table Source_Names.
388 (Project : Project_Id;
389 In_Tree : Project_Tree_Ref;
390 Path : Path_Name_Type;
391 File_Name : File_Name_Type;
392 Display_File_Name : File_Name_Type;
393 For_All_Sources : Boolean);
394 -- Check if file File_Name is a valid source of the project. This is used
395 -- in multi-language mode only.
396 -- When the file matches one of the naming schemes, it is added to
397 -- various htables through Add_Source and to Source_Paths_Htable.
399 -- Name is the name of the candidate file. It hasn't been normalized yet
400 -- and is the direct result of readdir().
402 -- File_Name is the same as Name, but has been normalized.
403 -- Display_File_Name, however, has not been normalized.
405 -- Source_Directory is the directory in which the file
406 -- was found. It hasn't been normalized (nor has had links resolved).
407 -- It should not end with a directory separator, to avoid duplicates
410 -- If For_All_Sources is True, then all possible file names are analyzed
411 -- otherwise only those currently set in the Source_Names htable.
413 procedure Check_File_Naming_Schemes
414 (In_Tree : Project_Tree_Ref;
415 Project : Project_Id;
416 File_Name : File_Name_Type;
417 Alternate_Languages : out Language_List;
418 Language : out Language_Ptr;
419 Display_Language_Name : out Name_Id;
421 Lang_Kind : out Language_Kind;
422 Kind : out Source_Kind);
423 -- Check if the file name File_Name conforms to one of the naming
424 -- schemes of the project.
426 -- If the file does not match one of the naming schemes, set Language
427 -- to No_Language_Index.
429 -- Filename is the name of the file being investigated. It has been
430 -- normalized (case-folded). File_Name is the same value.
432 procedure Free_Ada_Naming_Exceptions;
433 -- Free the internal hash tables used for checking naming exceptions
435 procedure Get_Directories
436 (Project : Project_Id;
437 In_Tree : Project_Tree_Ref;
438 Current_Dir : String);
439 -- Get the object directory, the exec directory and the source directories
442 -- Current_Dir should represent the current directory, and is passed for
443 -- efficiency to avoid system calls to recompute it.
446 (Project : Project_Id;
447 In_Tree : Project_Tree_Ref);
448 -- Get the mains of a project from attribute Main, if it exists, and put
449 -- them in the project data.
451 procedure Get_Sources_From_File
453 Location : Source_Ptr;
454 Project : Project_Id;
455 In_Tree : Project_Tree_Ref);
456 -- Get the list of sources from a text file and put them in hash table
459 procedure Find_Sources
460 (Project : Project_Id;
461 In_Tree : Project_Tree_Ref;
462 Proc_Data : in out Processing_Data);
463 -- Process the Source_Files and Source_List_File attributes, and store
464 -- the list of source files into the Source_Names htable.
465 -- When these attributes are not defined, find all files matching the
466 -- naming schemes in the source directories.
468 procedure Compute_Unit_Name
469 (File_Name : File_Name_Type;
470 Dot_Replacement : File_Name_Type;
471 Separate_Suffix : File_Name_Type;
472 Body_Suffix : File_Name_Type;
473 Spec_Suffix : File_Name_Type;
474 Casing : Casing_Type;
475 Kind : out Source_Kind;
477 In_Tree : Project_Tree_Ref);
478 -- Check whether the file matches the naming scheme. If it does,
479 -- compute its unit name. If Unit is set to No_Name on exit, none of the
480 -- other out parameters are relevant.
483 (In_Tree : Project_Tree_Ref;
484 Canonical_File_Name : File_Name_Type;
485 Naming : Naming_Data;
486 Exception_Id : out Ada_Naming_Exception_Id;
487 Unit_Name : out Name_Id;
488 Unit_Kind : out Spec_Or_Body);
489 -- Find out, from a file name, the unit name, the unit kind and if a
490 -- specific SFN pragma is needed. If the file name corresponds to no unit,
491 -- then Unit_Name will be No_Name. If the file is a multi-unit source or an
492 -- exception to the naming scheme, then Exception_Id is set to the unit or
493 -- units that the source contains, and the other information are not set.
495 function Is_Illegal_Suffix
496 (Suffix : File_Name_Type;
497 Dot_Replacement : File_Name_Type) return Boolean;
498 -- Returns True if the string Suffix cannot be used as a spec suffix, a
499 -- body suffix or a separate suffix.
501 procedure Locate_Directory
502 (Project : Project_Id;
503 In_Tree : Project_Tree_Ref;
504 Name : File_Name_Type;
505 Path : out Path_Information;
506 Dir_Exists : out Boolean;
507 Create : String := "";
508 Location : Source_Ptr := No_Location;
509 Must_Exist : Boolean := True;
510 Externally_Built : Boolean := False);
511 -- Locate a directory. Name is the directory name.
512 -- Relative paths are resolved relative to the project's directory.
513 -- If the directory does not exist and Setup_Projects
514 -- is True and Create is a non null string, an attempt is made to create
516 -- If the directory does not exist, it is either created if Setup_Projects
517 -- is False (and then returned), or simply returned without checking for
518 -- its existence (if Must_Exist is False) or No_Path_Information is
519 -- returned. In all cases, Dir_Exists indicates whether the directory now
522 -- Create is also used for debugging traces to show which path we are
525 procedure Look_For_Sources
526 (Project : Project_Id;
527 In_Tree : Project_Tree_Ref;
528 Proc_Data : in out Processing_Data);
529 -- Find all the sources of project Project in project tree In_Tree and
530 -- update its Data accordingly. This assumes that Data.First_Source has
531 -- been initialized with the list of excluded sources and special naming
534 function Path_Name_Of
535 (File_Name : File_Name_Type;
536 Directory : Path_Name_Type) return String;
537 -- Returns the path name of a (non project) file. Returns an empty string
538 -- if file cannot be found.
540 procedure Prepare_Ada_Naming_Exceptions
541 (List : Array_Element_Id;
542 In_Tree : Project_Tree_Ref;
543 Kind : Spec_Or_Body);
544 -- Prepare the internal hash tables used for checking naming exceptions
545 -- for Ada. Insert all elements of List in the tables.
547 procedure Record_Ada_Source
548 (File_Name : File_Name_Type;
549 Path_Name : Path_Name_Type;
550 Project : Project_Id;
551 In_Tree : Project_Tree_Ref;
552 Proc_Data : in out Processing_Data;
553 Ada_Language : Language_Ptr;
554 Location : Source_Ptr;
555 Source_Recorded : in out Boolean);
556 -- Put a unit in the list of units of a project, if the file name
557 -- corresponds to a valid unit name.
558 -- Ada_Language is a pointer to the Language_Data for "Ada" in Project.
560 procedure Remove_Source
562 Replaced_By : Source_Id);
565 procedure Report_No_Sources
566 (Project : Project_Id;
568 In_Tree : Project_Tree_Ref;
569 Location : Source_Ptr;
570 Continuation : Boolean := False);
571 -- Report an error or a warning depending on the value of When_No_Sources
572 -- when there are no sources for language Lang_Name.
574 procedure Show_Source_Dirs
575 (Project : Project_Id; In_Tree : Project_Tree_Ref);
576 -- List all the source directories of a project
578 procedure Warn_If_Not_Sources
579 (Project : Project_Id;
580 In_Tree : Project_Tree_Ref;
581 Conventions : Array_Element_Id;
583 Extending : Boolean);
584 -- Check that individual naming conventions apply to immediate sources of
585 -- the project. If not, issue a warning.
587 procedure Write_Attr (Name, Value : String);
588 -- Debug print a value for a specific property. Does nothing when not in
591 ------------------------------
592 -- Replace_Into_Name_Buffer --
593 ------------------------------
595 procedure Replace_Into_Name_Buffer
598 Replacement : Character)
600 Max : constant Integer := Str'Last - Pattern'Length + 1;
607 while J <= Str'Last loop
608 Name_Len := Name_Len + 1;
611 and then Str (J .. J + Pattern'Length - 1) = Pattern
613 Name_Buffer (Name_Len) := Replacement;
614 J := J + Pattern'Length;
617 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
621 end Replace_Into_Name_Buffer;
627 function Suffix_Matches
629 Suffix : File_Name_Type) return Boolean
632 if Suffix = No_File or else Suffix = Empty_File then
637 Suf : constant String := Get_Name_String (Suffix);
639 return Filename'Length > Suf'Length
641 (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
649 procedure Write_Attr (Name, Value : String) is
651 if Current_Verbosity = High then
652 Write_Str (" " & Name & " = """);
665 In_Tree : Project_Tree_Ref;
666 Project : Project_Id;
667 Lang_Id : Language_Ptr;
669 File_Name : File_Name_Type;
670 Display_File : File_Name_Type;
671 Naming_Exception : Boolean := False;
672 Path : Path_Information := No_Path_Information;
673 Alternate_Languages : Language_List := null;
674 Other_Part : Source_Id := No_Source;
675 Unit : Name_Id := No_Name;
677 Source_To_Replace : Source_Id := No_Source)
679 Config : constant Language_Config := Lang_Id.Config;
683 Id := new Source_Data;
685 if Current_Verbosity = High then
686 Write_Str ("Adding source File: ");
687 Write_Str (Get_Name_String (File_Name));
689 if Lang_Id.Config.Kind = Unit_Based then
690 Write_Str (" Unit: ");
691 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
692 -- (see test extended_projects)
693 if Unit /= No_Name then
694 Write_Str (Get_Name_String (Unit));
696 Write_Str (" Kind: ");
697 Write_Str (Source_Kind'Image (Kind));
703 Id.Project := Project;
704 Id.Language := Lang_Id;
706 Id.Alternate_Languages := Alternate_Languages;
707 Id.Other_Part := Other_Part;
709 if Other_Part /= No_Source then
710 Other_Part.Other_Part := Id;
713 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
716 if Unit /= No_Name then
717 Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
719 -- ??? Record_Unit has already fetched that earlier, so this isn't
720 -- the most efficient way. But we can't really pass a parameter since
721 -- Process_Exceptions_Unit_Based and Check_File haven't looked it up.
723 UData := Units_Htable.Get (In_Tree.Units_HT, Unit);
725 if UData = No_Unit_Index then
726 UData := new Unit_Data;
728 Units_Htable.Set (In_Tree.Units_HT, Unit, UData);
733 -- Note that this updates Unit information as well
735 Override_Kind (Id, Kind);
739 Id.File := File_Name;
740 Id.Display_File := Display_File;
741 Id.Dep_Name := Dependency_Name
742 (File_Name, Lang_Id.Config.Dependency_Kind);
743 Id.Naming_Exception := Naming_Exception;
745 if Is_Compilable (Id) and then Config.Object_Generated then
746 Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
747 Id.Switches := Switches_Name (File_Name);
750 if Path /= No_Path_Information then
752 Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path.Name, Id);
755 -- Add the source to the language list
757 Id.Next_In_Lang := Lang_Id.First_Source;
758 Lang_Id.First_Source := Id;
760 if Source_To_Replace /= No_Source then
761 Remove_Source (Source_To_Replace, Id);
769 function ALI_File_Name (Source : String) return String is
771 -- If the source name has extension, replace it with the ALI suffix
773 for Index in reverse Source'First + 1 .. Source'Last loop
774 if Source (Index) = '.' then
775 return Source (Source'First .. Index - 1) & ALI_Suffix;
779 -- If no dot, or if it is the first character, just add the ALI suffix
781 return Source & ALI_Suffix;
784 ------------------------------
785 -- Canonical_Case_File_Name --
786 ------------------------------
788 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
790 if Osint.File_Names_Case_Sensitive then
791 return File_Name_Type (Name);
793 Get_Name_String (Name);
794 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
797 end Canonical_Case_File_Name;
804 (Project : Project_Id;
805 In_Tree : Project_Tree_Ref;
806 Report_Error : Put_Line_Access;
807 When_No_Sources : Error_Warning;
808 Current_Dir : String;
809 Proc_Data : in out Processing_Data;
810 Is_Config_File : Boolean;
811 Compiler_Driver_Mandatory : Boolean)
813 Extending : Boolean := False;
816 Nmsc.When_No_Sources := When_No_Sources;
817 Error_Report := Report_Error;
819 Recursive_Dirs.Reset;
821 Check_If_Externally_Built (Project, In_Tree);
823 -- Object, exec and source directories
825 Get_Directories (Project, In_Tree, Current_Dir);
827 -- Get the programming languages
829 Check_Programming_Languages (In_Tree, Project);
831 if Project.Qualifier = Dry
832 and then Project.Source_Dirs /= Nil_String
835 Source_Dirs : constant Variable_Value :=
838 Project.Decl.Attributes, In_Tree);
839 Source_Files : constant Variable_Value :=
842 Project.Decl.Attributes, In_Tree);
843 Source_List_File : constant Variable_Value :=
845 (Name_Source_List_File,
846 Project.Decl.Attributes, In_Tree);
847 Languages : constant Variable_Value :=
850 Project.Decl.Attributes, In_Tree);
853 if Source_Dirs.Values = Nil_String
854 and then Source_Files.Values = Nil_String
855 and then Languages.Values = Nil_String
856 and then Source_List_File.Default
858 Project.Source_Dirs := Nil_String;
863 "an abstract project needs to have no language, " &
864 "no sources or no source directories",
870 -- Check configuration in multi language mode
872 if Must_Check_Configuration then
875 Compiler_Driver_Mandatory => Compiler_Driver_Mandatory);
878 -- Library attributes
880 Check_Library_Attributes (Project, In_Tree);
882 if Current_Verbosity = High then
883 Show_Source_Dirs (Project, In_Tree);
886 Check_Package_Naming (Project, In_Tree);
888 Extending := Project.Extends /= No_Project;
890 Check_Naming_Schemes (Project, In_Tree, Is_Config_File);
892 if Get_Mode = Ada_Only then
893 Prepare_Ada_Naming_Exceptions
894 (Project.Naming.Bodies, In_Tree, Impl);
895 Prepare_Ada_Naming_Exceptions
896 (Project.Naming.Specs, In_Tree, Spec);
901 if Project.Source_Dirs /= Nil_String then
902 Look_For_Sources (Project, In_Tree, Proc_Data);
904 if Get_Mode = Ada_Only then
906 -- Check that all individual naming conventions apply to sources
907 -- of this project file.
910 (Project, In_Tree, Project.Naming.Bodies,
912 Extending => Extending);
914 (Project, In_Tree, Project.Naming.Specs,
916 Extending => Extending);
918 elsif Get_Mode = Multi_Language and then
919 (not Project.Externally_Built) and then
923 Language : Language_Ptr;
925 Alt_Lang : Language_List;
926 Continuation : Boolean := False;
927 Iter : Source_Iterator;
930 Language := Project.Languages;
931 while Language /= No_Language_Index loop
933 -- If there are no sources for this language, check whether
934 -- there are sources for which this is an alternate
937 if Language.First_Source = No_Source then
938 Iter := For_Each_Source (In_Tree => In_Tree,
941 Source := Element (Iter);
942 exit Source_Loop when Source = No_Source
943 or else Source.Language = Language;
945 Alt_Lang := Source.Alternate_Languages;
946 while Alt_Lang /= null loop
947 exit Source_Loop when Alt_Lang.Language = Language;
948 Alt_Lang := Alt_Lang.Next;
952 end loop Source_Loop;
954 if Source = No_Source then
957 Get_Name_String (Language.Display_Name),
961 Continuation := True;
965 Language := Language.Next;
971 if Get_Mode = Multi_Language then
973 -- If a list of sources is specified in attribute Interfaces, set
974 -- In_Interfaces only for the sources specified in the list.
976 Check_Interfaces (Project, In_Tree);
979 -- If it is a library project file, check if it is a standalone library
981 if Project.Library then
982 Check_Stand_Alone_Library
983 (Project, In_Tree, Current_Dir, Extending);
986 -- Put the list of Mains, if any, in the project data
988 Get_Mains (Project, In_Tree);
990 Free_Ada_Naming_Exceptions;
997 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
998 The_Name : String := Name;
1000 Need_Letter : Boolean := True;
1001 Last_Underscore : Boolean := False;
1002 OK : Boolean := The_Name'Length > 0;
1005 function Is_Reserved (Name : Name_Id) return Boolean;
1006 function Is_Reserved (S : String) return Boolean;
1007 -- Check that the given name is not an Ada 95 reserved word. The reason
1008 -- for the Ada 95 here is that we do not want to exclude the case of an
1009 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
1010 -- name would be rejected anyway by the compiler. That means there is no
1011 -- requirement that the project file parser reject this.
1017 function Is_Reserved (S : String) return Boolean is
1020 Add_Str_To_Name_Buffer (S);
1021 return Is_Reserved (Name_Find);
1028 function Is_Reserved (Name : Name_Id) return Boolean is
1030 if Get_Name_Table_Byte (Name) /= 0
1031 and then Name /= Name_Project
1032 and then Name /= Name_Extends
1033 and then Name /= Name_External
1034 and then Name not in Ada_2005_Reserved_Words
1038 if Current_Verbosity = High then
1039 Write_Str (The_Name);
1040 Write_Line (" is an Ada reserved word.");
1050 -- Start of processing for Check_Ada_Name
1053 To_Lower (The_Name);
1055 Name_Len := The_Name'Length;
1056 Name_Buffer (1 .. Name_Len) := The_Name;
1058 -- Special cases of children of packages A, G, I and S on VMS
1060 if OpenVMS_On_Target
1061 and then Name_Len > 3
1062 and then Name_Buffer (2 .. 3) = "__"
1064 ((Name_Buffer (1) = 'a') or else
1065 (Name_Buffer (1) = 'g') or else
1066 (Name_Buffer (1) = 'i') or else
1067 (Name_Buffer (1) = 's'))
1069 Name_Buffer (2) := '.';
1070 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1071 Name_Len := Name_Len - 1;
1074 Real_Name := Name_Find;
1076 if Is_Reserved (Real_Name) then
1080 First := The_Name'First;
1082 for Index in The_Name'Range loop
1085 -- We need a letter (at the beginning, and following a dot),
1086 -- but we don't have one.
1088 if Is_Letter (The_Name (Index)) then
1089 Need_Letter := False;
1094 if Current_Verbosity = High then
1095 Write_Int (Types.Int (Index));
1097 Write_Char (The_Name (Index));
1098 Write_Line ("' is not a letter.");
1104 elsif Last_Underscore
1105 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1107 -- Two underscores are illegal, and a dot cannot follow
1112 if Current_Verbosity = High then
1113 Write_Int (Types.Int (Index));
1115 Write_Char (The_Name (Index));
1116 Write_Line ("' is illegal here.");
1121 elsif The_Name (Index) = '.' then
1123 -- First, check if the name before the dot is not a reserved word
1124 if Is_Reserved (The_Name (First .. Index - 1)) then
1130 -- We need a letter after a dot
1132 Need_Letter := True;
1134 elsif The_Name (Index) = '_' then
1135 Last_Underscore := True;
1138 -- We need an letter or a digit
1140 Last_Underscore := False;
1142 if not Is_Alphanumeric (The_Name (Index)) then
1145 if Current_Verbosity = High then
1146 Write_Int (Types.Int (Index));
1148 Write_Char (The_Name (Index));
1149 Write_Line ("' is not alphanumeric.");
1157 -- Cannot end with an underscore or a dot
1159 OK := OK and then not Need_Letter and then not Last_Underscore;
1162 if First /= Name'First and then
1163 Is_Reserved (The_Name (First .. The_Name'Last))
1171 -- Signal a problem with No_Name
1177 -------------------------
1178 -- Check_Configuration --
1179 -------------------------
1181 procedure Check_Configuration
1182 (Project : Project_Id;
1183 In_Tree : Project_Tree_Ref;
1184 Compiler_Driver_Mandatory : Boolean)
1186 Dot_Replacement : File_Name_Type := No_File;
1187 Casing : Casing_Type := All_Lower_Case;
1188 Separate_Suffix : File_Name_Type := No_File;
1190 Lang_Index : Language_Ptr := No_Language_Index;
1191 -- The index of the language data being checked
1193 Prev_Index : Language_Ptr := No_Language_Index;
1194 -- The index of the previous language
1196 procedure Process_Project_Level_Simple_Attributes;
1197 -- Process the simple attributes at the project level
1199 procedure Process_Project_Level_Array_Attributes;
1200 -- Process the associate array attributes at the project level
1202 procedure Process_Packages;
1203 -- Read the packages of the project
1205 ----------------------
1206 -- Process_Packages --
1207 ----------------------
1209 procedure Process_Packages is
1210 Packages : Package_Id;
1211 Element : Package_Element;
1213 procedure Process_Binder (Arrays : Array_Id);
1214 -- Process the associate array attributes of package Binder
1216 procedure Process_Builder (Attributes : Variable_Id);
1217 -- Process the simple attributes of package Builder
1219 procedure Process_Compiler (Arrays : Array_Id);
1220 -- Process the associate array attributes of package Compiler
1222 procedure Process_Naming (Attributes : Variable_Id);
1223 -- Process the simple attributes of package Naming
1225 procedure Process_Naming (Arrays : Array_Id);
1226 -- Process the associate array attributes of package Naming
1228 procedure Process_Linker (Attributes : Variable_Id);
1229 -- Process the simple attributes of package Linker of a
1230 -- configuration project.
1232 --------------------
1233 -- Process_Binder --
1234 --------------------
1236 procedure Process_Binder (Arrays : Array_Id) is
1237 Current_Array_Id : Array_Id;
1238 Current_Array : Array_Data;
1239 Element_Id : Array_Element_Id;
1240 Element : Array_Element;
1243 -- Process the associative array attribute of package Binder
1245 Current_Array_Id := Arrays;
1246 while Current_Array_Id /= No_Array loop
1247 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1249 Element_Id := Current_Array.Value;
1250 while Element_Id /= No_Array_Element loop
1251 Element := In_Tree.Array_Elements.Table (Element_Id);
1253 if Element.Index /= All_Other_Names then
1255 -- Get the name of the language
1258 Get_Language_From_Name
1259 (Project, Get_Name_String (Element.Index));
1261 if Lang_Index /= No_Language_Index then
1262 case Current_Array.Name is
1265 -- Attribute Driver (<language>)
1267 Lang_Index.Config.Binder_Driver :=
1268 File_Name_Type (Element.Value.Value);
1270 when Name_Required_Switches =>
1273 Lang_Index.Config.Binder_Required_Switches,
1274 From_List => Element.Value.Values,
1275 In_Tree => In_Tree);
1279 -- Attribute Prefix (<language>)
1281 Lang_Index.Config.Binder_Prefix :=
1282 Element.Value.Value;
1284 when Name_Objects_Path =>
1286 -- Attribute Objects_Path (<language>)
1288 Lang_Index.Config.Objects_Path :=
1289 Element.Value.Value;
1291 when Name_Objects_Path_File =>
1293 -- Attribute Objects_Path (<language>)
1295 Lang_Index.Config.Objects_Path_File :=
1296 Element.Value.Value;
1304 Element_Id := Element.Next;
1307 Current_Array_Id := Current_Array.Next;
1311 ---------------------
1312 -- Process_Builder --
1313 ---------------------
1315 procedure Process_Builder (Attributes : Variable_Id) is
1316 Attribute_Id : Variable_Id;
1317 Attribute : Variable;
1320 -- Process non associated array attribute from package Builder
1322 Attribute_Id := Attributes;
1323 while Attribute_Id /= No_Variable loop
1325 In_Tree.Variable_Elements.Table (Attribute_Id);
1327 if not Attribute.Value.Default then
1328 if Attribute.Name = Name_Executable_Suffix then
1330 -- Attribute Executable_Suffix: the suffix of the
1333 Project.Config.Executable_Suffix :=
1334 Attribute.Value.Value;
1338 Attribute_Id := Attribute.Next;
1340 end Process_Builder;
1342 ----------------------
1343 -- Process_Compiler --
1344 ----------------------
1346 procedure Process_Compiler (Arrays : Array_Id) is
1347 Current_Array_Id : Array_Id;
1348 Current_Array : Array_Data;
1349 Element_Id : Array_Element_Id;
1350 Element : Array_Element;
1351 List : String_List_Id;
1354 -- Process the associative array attribute of package Compiler
1356 Current_Array_Id := Arrays;
1357 while Current_Array_Id /= No_Array loop
1358 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1360 Element_Id := Current_Array.Value;
1361 while Element_Id /= No_Array_Element loop
1362 Element := In_Tree.Array_Elements.Table (Element_Id);
1364 if Element.Index /= All_Other_Names then
1366 -- Get the name of the language
1368 Lang_Index := Get_Language_From_Name
1369 (Project, Get_Name_String (Element.Index));
1371 if Lang_Index /= No_Language_Index then
1372 case Current_Array.Name is
1373 when Name_Dependency_Switches =>
1375 -- Attribute Dependency_Switches (<language>)
1377 if Lang_Index.Config.Dependency_Kind = None then
1378 Lang_Index.Config.Dependency_Kind := Makefile;
1381 List := Element.Value.Values;
1383 if List /= Nil_String then
1385 Lang_Index.Config.Dependency_Option,
1387 In_Tree => In_Tree);
1390 when Name_Dependency_Driver =>
1392 -- Attribute Dependency_Driver (<language>)
1394 if Lang_Index.Config.Dependency_Kind = None then
1395 Lang_Index.Config.Dependency_Kind := Makefile;
1398 List := Element.Value.Values;
1400 if List /= Nil_String then
1402 Lang_Index.Config.Compute_Dependency,
1404 In_Tree => In_Tree);
1407 when Name_Include_Switches =>
1409 -- Attribute Include_Switches (<language>)
1411 List := Element.Value.Values;
1413 if List = Nil_String then
1417 "include option cannot be null",
1418 Element.Value.Location);
1422 Lang_Index.Config.Include_Option,
1424 In_Tree => In_Tree);
1426 when Name_Include_Path =>
1428 -- Attribute Include_Path (<language>)
1430 Lang_Index.Config.Include_Path :=
1431 Element.Value.Value;
1433 when Name_Include_Path_File =>
1435 -- Attribute Include_Path_File (<language>)
1437 Lang_Index.Config.Include_Path_File :=
1438 Element.Value.Value;
1442 -- Attribute Driver (<language>)
1444 Lang_Index.Config.Compiler_Driver :=
1445 File_Name_Type (Element.Value.Value);
1447 when Name_Required_Switches |
1448 Name_Leading_Required_Switches =>
1451 Compiler_Leading_Required_Switches,
1452 From_List => Element.Value.Values,
1453 In_Tree => In_Tree);
1455 when Name_Trailing_Required_Switches =>
1458 Compiler_Trailing_Required_Switches,
1459 From_List => Element.Value.Values,
1460 In_Tree => In_Tree);
1462 when Name_Path_Syntax =>
1464 Lang_Index.Config.Path_Syntax :=
1465 Path_Syntax_Kind'Value
1466 (Get_Name_String (Element.Value.Value));
1469 when Constraint_Error =>
1473 "invalid value for Path_Syntax",
1474 Element.Value.Location);
1477 when Name_Object_File_Suffix =>
1478 if Get_Name_String (Element.Value.Value) = "" then
1481 "object file suffix cannot be empty",
1482 Element.Value.Location);
1485 Lang_Index.Config.Object_File_Suffix :=
1486 Element.Value.Value;
1489 when Name_Object_File_Switches =>
1491 Lang_Index.Config.Object_File_Switches,
1492 From_List => Element.Value.Values,
1493 In_Tree => In_Tree);
1495 when Name_Pic_Option =>
1497 -- Attribute Compiler_Pic_Option (<language>)
1499 List := Element.Value.Values;
1501 if List = Nil_String then
1505 "compiler PIC option cannot be null",
1506 Element.Value.Location);
1510 Lang_Index.Config.Compilation_PIC_Option,
1512 In_Tree => In_Tree);
1514 when Name_Mapping_File_Switches =>
1516 -- Attribute Mapping_File_Switches (<language>)
1518 List := Element.Value.Values;
1520 if List = Nil_String then
1524 "mapping file switches cannot be null",
1525 Element.Value.Location);
1529 Lang_Index.Config.Mapping_File_Switches,
1531 In_Tree => In_Tree);
1533 when Name_Mapping_Spec_Suffix =>
1535 -- Attribute Mapping_Spec_Suffix (<language>)
1537 Lang_Index.Config.Mapping_Spec_Suffix :=
1538 File_Name_Type (Element.Value.Value);
1540 when Name_Mapping_Body_Suffix =>
1542 -- Attribute Mapping_Body_Suffix (<language>)
1544 Lang_Index.Config.Mapping_Body_Suffix :=
1545 File_Name_Type (Element.Value.Value);
1547 when Name_Config_File_Switches =>
1549 -- Attribute Config_File_Switches (<language>)
1551 List := Element.Value.Values;
1553 if List = Nil_String then
1557 "config file switches cannot be null",
1558 Element.Value.Location);
1562 Lang_Index.Config.Config_File_Switches,
1564 In_Tree => In_Tree);
1566 when Name_Objects_Path =>
1568 -- Attribute Objects_Path (<language>)
1570 Lang_Index.Config.Objects_Path :=
1571 Element.Value.Value;
1573 when Name_Objects_Path_File =>
1575 -- Attribute Objects_Path_File (<language>)
1577 Lang_Index.Config.Objects_Path_File :=
1578 Element.Value.Value;
1580 when Name_Config_Body_File_Name =>
1582 -- Attribute Config_Body_File_Name (<language>)
1584 Lang_Index.Config.Config_Body :=
1585 Element.Value.Value;
1587 when Name_Config_Body_File_Name_Pattern =>
1589 -- Attribute Config_Body_File_Name_Pattern
1592 Lang_Index.Config.Config_Body_Pattern :=
1593 Element.Value.Value;
1595 when Name_Config_Spec_File_Name =>
1597 -- Attribute Config_Spec_File_Name (<language>)
1599 Lang_Index.Config.Config_Spec :=
1600 Element.Value.Value;
1602 when Name_Config_Spec_File_Name_Pattern =>
1604 -- Attribute Config_Spec_File_Name_Pattern
1607 Lang_Index.Config.Config_Spec_Pattern :=
1608 Element.Value.Value;
1610 when Name_Config_File_Unique =>
1612 -- Attribute Config_File_Unique (<language>)
1615 Lang_Index.Config.Config_File_Unique :=
1617 (Get_Name_String (Element.Value.Value));
1619 when Constraint_Error =>
1623 "illegal value for Config_File_Unique",
1624 Element.Value.Location);
1633 Element_Id := Element.Next;
1636 Current_Array_Id := Current_Array.Next;
1638 end Process_Compiler;
1640 --------------------
1641 -- Process_Naming --
1642 --------------------
1644 procedure Process_Naming (Attributes : Variable_Id) is
1645 Attribute_Id : Variable_Id;
1646 Attribute : Variable;
1649 -- Process non associated array attribute from package Naming
1651 Attribute_Id := Attributes;
1652 while Attribute_Id /= No_Variable loop
1653 Attribute := In_Tree.Variable_Elements.Table (Attribute_Id);
1655 if not Attribute.Value.Default then
1656 if Attribute.Name = Name_Separate_Suffix then
1658 -- Attribute Separate_Suffix
1660 Separate_Suffix := File_Name_Type (Attribute.Value.Value);
1662 elsif Attribute.Name = Name_Casing then
1668 Value (Get_Name_String (Attribute.Value.Value));
1671 when Constraint_Error =>
1675 "invalid value for Casing",
1676 Attribute.Value.Location);
1679 elsif Attribute.Name = Name_Dot_Replacement then
1681 -- Attribute Dot_Replacement
1683 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1688 Attribute_Id := Attribute.Next;
1692 procedure Process_Naming (Arrays : Array_Id) is
1693 Current_Array_Id : Array_Id;
1694 Current_Array : Array_Data;
1695 Element_Id : Array_Element_Id;
1696 Element : Array_Element;
1698 -- Process the associative array attribute of package Naming
1700 Current_Array_Id := Arrays;
1701 while Current_Array_Id /= No_Array loop
1702 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1704 Element_Id := Current_Array.Value;
1705 while Element_Id /= No_Array_Element loop
1706 Element := In_Tree.Array_Elements.Table (Element_Id);
1708 -- Get the name of the language
1710 Lang_Index := Get_Language_From_Name
1711 (Project, Get_Name_String (Element.Index));
1713 if Lang_Index /= No_Language_Index then
1714 case Current_Array.Name is
1715 when Name_Spec_Suffix | Name_Specification_Suffix =>
1717 -- Attribute Spec_Suffix (<language>)
1719 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1720 File_Name_Type (Element.Value.Value);
1722 when Name_Implementation_Suffix | Name_Body_Suffix =>
1724 -- Attribute Body_Suffix (<language>)
1726 Lang_Index.Config.Naming_Data.Body_Suffix :=
1727 File_Name_Type (Element.Value.Value);
1729 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1730 File_Name_Type (Element.Value.Value);
1737 Element_Id := Element.Next;
1740 Current_Array_Id := Current_Array.Next;
1744 --------------------
1745 -- Process_Linker --
1746 --------------------
1748 procedure Process_Linker (Attributes : Variable_Id) is
1749 Attribute_Id : Variable_Id;
1750 Attribute : Variable;
1753 -- Process non associated array attribute from package Linker
1755 Attribute_Id := Attributes;
1756 while Attribute_Id /= No_Variable loop
1758 In_Tree.Variable_Elements.Table (Attribute_Id);
1760 if not Attribute.Value.Default then
1761 if Attribute.Name = Name_Driver then
1763 -- Attribute Linker'Driver: the default linker to use
1765 Project.Config.Linker :=
1766 Path_Name_Type (Attribute.Value.Value);
1768 -- Linker'Driver is also used to link shared libraries
1769 -- if the obsolescent attribute Library_GCC has not been
1772 if Project.Config.Shared_Lib_Driver = No_File then
1773 Project.Config.Shared_Lib_Driver :=
1774 File_Name_Type (Attribute.Value.Value);
1777 elsif Attribute.Name = Name_Required_Switches then
1779 -- Attribute Required_Switches: the minimum
1780 -- options to use when invoking the linker
1782 Put (Into_List => Project.Config.Minimum_Linker_Options,
1783 From_List => Attribute.Value.Values,
1784 In_Tree => In_Tree);
1786 elsif Attribute.Name = Name_Map_File_Option then
1787 Project.Config.Map_File_Option := Attribute.Value.Value;
1789 elsif Attribute.Name = Name_Max_Command_Line_Length then
1791 Project.Config.Max_Command_Line_Length :=
1792 Natural'Value (Get_Name_String
1793 (Attribute.Value.Value));
1796 when Constraint_Error =>
1800 "value must be positive or equal to 0",
1801 Attribute.Value.Location);
1804 elsif Attribute.Name = Name_Response_File_Format then
1809 Get_Name_String (Attribute.Value.Value);
1810 To_Lower (Name_Buffer (1 .. Name_Len));
1813 if Name = Name_None then
1814 Project.Config.Resp_File_Format := None;
1816 elsif Name = Name_Gnu then
1817 Project.Config.Resp_File_Format := GNU;
1819 elsif Name = Name_Object_List then
1820 Project.Config.Resp_File_Format := Object_List;
1822 elsif Name = Name_Option_List then
1823 Project.Config.Resp_File_Format := Option_List;
1829 "illegal response file format",
1830 Attribute.Value.Location);
1834 elsif Attribute.Name = Name_Response_File_Switches then
1835 Put (Into_List => Project.Config.Resp_File_Options,
1836 From_List => Attribute.Value.Values,
1837 In_Tree => In_Tree);
1841 Attribute_Id := Attribute.Next;
1845 -- Start of processing for Process_Packages
1848 Packages := Project.Decl.Packages;
1849 while Packages /= No_Package loop
1850 Element := In_Tree.Packages.Table (Packages);
1852 case Element.Name is
1855 -- Process attributes of package Binder
1857 Process_Binder (Element.Decl.Arrays);
1859 when Name_Builder =>
1861 -- Process attributes of package Builder
1863 Process_Builder (Element.Decl.Attributes);
1865 when Name_Compiler =>
1867 -- Process attributes of package Compiler
1869 Process_Compiler (Element.Decl.Arrays);
1873 -- Process attributes of package Linker
1875 Process_Linker (Element.Decl.Attributes);
1879 -- Process attributes of package Naming
1881 Process_Naming (Element.Decl.Attributes);
1882 Process_Naming (Element.Decl.Arrays);
1888 Packages := Element.Next;
1890 end Process_Packages;
1892 ---------------------------------------------
1893 -- Process_Project_Level_Simple_Attributes --
1894 ---------------------------------------------
1896 procedure Process_Project_Level_Simple_Attributes is
1897 Attribute_Id : Variable_Id;
1898 Attribute : Variable;
1899 List : String_List_Id;
1902 -- Process non associated array attribute at project level
1904 Attribute_Id := Project.Decl.Attributes;
1905 while Attribute_Id /= No_Variable loop
1907 In_Tree.Variable_Elements.Table (Attribute_Id);
1909 if not Attribute.Value.Default then
1910 if Attribute.Name = Name_Target then
1912 -- Attribute Target: the target specified
1914 Project.Config.Target := Attribute.Value.Value;
1916 elsif Attribute.Name = Name_Library_Builder then
1918 -- Attribute Library_Builder: the application to invoke
1919 -- to build libraries.
1921 Project.Config.Library_Builder :=
1922 Path_Name_Type (Attribute.Value.Value);
1924 elsif Attribute.Name = Name_Archive_Builder then
1926 -- Attribute Archive_Builder: the archive builder
1927 -- (usually "ar") and its minimum options (usually "cr").
1929 List := Attribute.Value.Values;
1931 if List = Nil_String then
1935 "archive builder cannot be null",
1936 Attribute.Value.Location);
1939 Put (Into_List => Project.Config.Archive_Builder,
1941 In_Tree => In_Tree);
1943 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1945 -- Attribute Archive_Builder: the archive builder
1946 -- (usually "ar") and its minimum options (usually "cr").
1948 List := Attribute.Value.Values;
1950 if List /= Nil_String then
1953 Project.Config.Archive_Builder_Append_Option,
1955 In_Tree => In_Tree);
1958 elsif Attribute.Name = Name_Archive_Indexer then
1960 -- Attribute Archive_Indexer: the optional archive
1961 -- indexer (usually "ranlib") with its minimum options
1964 List := Attribute.Value.Values;
1966 if List = Nil_String then
1970 "archive indexer cannot be null",
1971 Attribute.Value.Location);
1974 Put (Into_List => Project.Config.Archive_Indexer,
1976 In_Tree => In_Tree);
1978 elsif Attribute.Name = Name_Library_Partial_Linker then
1980 -- Attribute Library_Partial_Linker: the optional linker
1981 -- driver with its minimum options, to partially link
1984 List := Attribute.Value.Values;
1986 if List = Nil_String then
1990 "partial linker cannot be null",
1991 Attribute.Value.Location);
1994 Put (Into_List => Project.Config.Lib_Partial_Linker,
1996 In_Tree => In_Tree);
1998 elsif Attribute.Name = Name_Library_GCC then
1999 Project.Config.Shared_Lib_Driver :=
2000 File_Name_Type (Attribute.Value.Value);
2004 "?Library_'G'C'C is an obsolescent attribute, " &
2005 "use Linker''Driver instead",
2006 Attribute.Value.Location);
2008 elsif Attribute.Name = Name_Archive_Suffix then
2009 Project.Config.Archive_Suffix :=
2010 File_Name_Type (Attribute.Value.Value);
2012 elsif Attribute.Name = Name_Linker_Executable_Option then
2014 -- Attribute Linker_Executable_Option: optional options
2015 -- to specify an executable name. Defaults to "-o".
2017 List := Attribute.Value.Values;
2019 if List = Nil_String then
2023 "linker executable option cannot be null",
2024 Attribute.Value.Location);
2027 Put (Into_List => Project.Config.Linker_Executable_Option,
2029 In_Tree => In_Tree);
2031 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2033 -- Attribute Linker_Lib_Dir_Option: optional options
2034 -- to specify a library search directory. Defaults to
2037 Get_Name_String (Attribute.Value.Value);
2039 if Name_Len = 0 then
2043 "linker library directory option cannot be empty",
2044 Attribute.Value.Location);
2047 Project.Config.Linker_Lib_Dir_Option :=
2048 Attribute.Value.Value;
2050 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2052 -- Attribute Linker_Lib_Name_Option: optional options
2053 -- to specify the name of a library to be linked in.
2054 -- Defaults to "-l".
2056 Get_Name_String (Attribute.Value.Value);
2058 if Name_Len = 0 then
2062 "linker library name option cannot be empty",
2063 Attribute.Value.Location);
2066 Project.Config.Linker_Lib_Name_Option :=
2067 Attribute.Value.Value;
2069 elsif Attribute.Name = Name_Run_Path_Option then
2071 -- Attribute Run_Path_Option: optional options to
2072 -- specify a path for libraries.
2074 List := Attribute.Value.Values;
2076 if List /= Nil_String then
2077 Put (Into_List => Project.Config.Run_Path_Option,
2079 In_Tree => In_Tree);
2082 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2084 pragma Unsuppress (All_Checks);
2086 Project.Config.Separate_Run_Path_Options :=
2087 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2089 when Constraint_Error =>
2093 "invalid value """ &
2094 Get_Name_String (Attribute.Value.Value) &
2095 """ for Separate_Run_Path_Options",
2096 Attribute.Value.Location);
2099 elsif Attribute.Name = Name_Library_Support then
2101 pragma Unsuppress (All_Checks);
2103 Project.Config.Lib_Support :=
2104 Library_Support'Value (Get_Name_String
2105 (Attribute.Value.Value));
2107 when Constraint_Error =>
2111 "invalid value """ &
2112 Get_Name_String (Attribute.Value.Value) &
2113 """ for Library_Support",
2114 Attribute.Value.Location);
2117 elsif Attribute.Name = Name_Shared_Library_Prefix then
2118 Project.Config.Shared_Lib_Prefix :=
2119 File_Name_Type (Attribute.Value.Value);
2121 elsif Attribute.Name = Name_Shared_Library_Suffix then
2122 Project.Config.Shared_Lib_Suffix :=
2123 File_Name_Type (Attribute.Value.Value);
2125 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2127 pragma Unsuppress (All_Checks);
2129 Project.Config.Symbolic_Link_Supported :=
2130 Boolean'Value (Get_Name_String
2131 (Attribute.Value.Value));
2133 when Constraint_Error =>
2138 & Get_Name_String (Attribute.Value.Value)
2139 & """ for Symbolic_Link_Supported",
2140 Attribute.Value.Location);
2144 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2147 pragma Unsuppress (All_Checks);
2149 Project.Config.Lib_Maj_Min_Id_Supported :=
2150 Boolean'Value (Get_Name_String
2151 (Attribute.Value.Value));
2153 when Constraint_Error =>
2157 "invalid value """ &
2158 Get_Name_String (Attribute.Value.Value) &
2159 """ for Library_Major_Minor_Id_Supported",
2160 Attribute.Value.Location);
2163 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2165 pragma Unsuppress (All_Checks);
2167 Project.Config.Auto_Init_Supported :=
2168 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2170 when Constraint_Error =>
2175 & Get_Name_String (Attribute.Value.Value)
2176 & """ for Library_Auto_Init_Supported",
2177 Attribute.Value.Location);
2180 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2181 List := Attribute.Value.Values;
2183 if List /= Nil_String then
2184 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2186 In_Tree => In_Tree);
2189 elsif Attribute.Name = Name_Library_Version_Switches then
2190 List := Attribute.Value.Values;
2192 if List /= Nil_String then
2193 Put (Into_List => Project.Config.Lib_Version_Options,
2195 In_Tree => In_Tree);
2200 Attribute_Id := Attribute.Next;
2202 end Process_Project_Level_Simple_Attributes;
2204 --------------------------------------------
2205 -- Process_Project_Level_Array_Attributes --
2206 --------------------------------------------
2208 procedure Process_Project_Level_Array_Attributes is
2209 Current_Array_Id : Array_Id;
2210 Current_Array : Array_Data;
2211 Element_Id : Array_Element_Id;
2212 Element : Array_Element;
2213 List : String_List_Id;
2216 -- Process the associative array attributes at project level
2218 Current_Array_Id := Project.Decl.Arrays;
2219 while Current_Array_Id /= No_Array loop
2220 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
2222 Element_Id := Current_Array.Value;
2223 while Element_Id /= No_Array_Element loop
2224 Element := In_Tree.Array_Elements.Table (Element_Id);
2226 -- Get the name of the language
2229 Get_Language_From_Name
2230 (Project, Get_Name_String (Element.Index));
2232 if Lang_Index /= No_Language_Index then
2233 case Current_Array.Name is
2234 when Name_Inherit_Source_Path =>
2235 List := Element.Value.Values;
2237 if List /= Nil_String then
2240 Lang_Index.Config.Include_Compatible_Languages,
2243 Lower_Case => True);
2246 when Name_Toolchain_Description =>
2248 -- Attribute Toolchain_Description (<language>)
2250 Lang_Index.Config.Toolchain_Description :=
2251 Element.Value.Value;
2253 when Name_Toolchain_Version =>
2255 -- Attribute Toolchain_Version (<language>)
2257 Lang_Index.Config.Toolchain_Version :=
2258 Element.Value.Value;
2260 when Name_Runtime_Library_Dir =>
2262 -- Attribute Runtime_Library_Dir (<language>)
2264 Lang_Index.Config.Runtime_Library_Dir :=
2265 Element.Value.Value;
2267 when Name_Runtime_Source_Dir =>
2269 -- Attribute Runtime_Library_Dir (<language>)
2271 Lang_Index.Config.Runtime_Source_Dir :=
2272 Element.Value.Value;
2274 when Name_Object_Generated =>
2276 pragma Unsuppress (All_Checks);
2282 (Get_Name_String (Element.Value.Value));
2284 Lang_Index.Config.Object_Generated := Value;
2286 -- If no object is generated, no object may be
2290 Lang_Index.Config.Objects_Linked := False;
2294 when Constraint_Error =>
2299 & Get_Name_String (Element.Value.Value)
2300 & """ for Object_Generated",
2301 Element.Value.Location);
2304 when Name_Objects_Linked =>
2306 pragma Unsuppress (All_Checks);
2312 (Get_Name_String (Element.Value.Value));
2314 -- No change if Object_Generated is False, as this
2315 -- forces Objects_Linked to be False too.
2317 if Lang_Index.Config.Object_Generated then
2318 Lang_Index.Config.Objects_Linked := Value;
2322 when Constraint_Error =>
2327 & Get_Name_String (Element.Value.Value)
2328 & """ for Objects_Linked",
2329 Element.Value.Location);
2336 Element_Id := Element.Next;
2339 Current_Array_Id := Current_Array.Next;
2341 end Process_Project_Level_Array_Attributes;
2344 Process_Project_Level_Simple_Attributes;
2345 Process_Project_Level_Array_Attributes;
2348 -- For unit based languages, set Casing, Dot_Replacement and
2349 -- Separate_Suffix in Naming_Data.
2351 Lang_Index := Project.Languages;
2352 while Lang_Index /= No_Language_Index loop
2353 if Lang_Index.Name = Name_Ada then
2354 Lang_Index.Config.Naming_Data.Casing := Casing;
2355 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2357 if Separate_Suffix /= No_File then
2358 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2365 Lang_Index := Lang_Index.Next;
2368 -- Give empty names to various prefixes/suffixes, if they have not
2369 -- been specified in the configuration.
2371 if Project.Config.Archive_Suffix = No_File then
2372 Project.Config.Archive_Suffix := Empty_File;
2375 if Project.Config.Shared_Lib_Prefix = No_File then
2376 Project.Config.Shared_Lib_Prefix := Empty_File;
2379 if Project.Config.Shared_Lib_Suffix = No_File then
2380 Project.Config.Shared_Lib_Suffix := Empty_File;
2383 Lang_Index := Project.Languages;
2384 while Lang_Index /= No_Language_Index loop
2385 -- For all languages, Compiler_Driver needs to be specified. This is
2386 -- only necessary if we do intend to compiler (not in GPS for
2389 if Compiler_Driver_Mandatory
2390 and then Lang_Index.Config.Compiler_Driver = No_File
2392 Error_Msg_Name_1 := Lang_Index.Display_Name;
2396 "?no compiler specified for language %%" &
2397 ", ignoring all its sources",
2400 if Lang_Index = Project.Languages then
2401 Project.Languages := Lang_Index.Next;
2403 Prev_Index.Next := Lang_Index.Next;
2406 elsif Lang_Index.Name = Name_Ada then
2407 Prev_Index := Lang_Index;
2409 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2410 -- Body_Suffix need to be specified.
2412 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2416 "Dot_Replacement not specified for Ada",
2420 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2424 "Spec_Suffix not specified for Ada",
2428 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2432 "Body_Suffix not specified for Ada",
2437 Prev_Index := Lang_Index;
2439 -- For file based languages, either Spec_Suffix or Body_Suffix
2440 -- need to be specified.
2442 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File and then
2443 Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2445 Error_Msg_Name_1 := Lang_Index.Display_Name;
2449 "no suffixes specified for %%",
2454 Lang_Index := Lang_Index.Next;
2456 end Check_Configuration;
2458 -------------------------------
2459 -- Check_If_Externally_Built --
2460 -------------------------------
2462 procedure Check_If_Externally_Built
2463 (Project : Project_Id;
2464 In_Tree : Project_Tree_Ref)
2466 Externally_Built : constant Variable_Value :=
2468 (Name_Externally_Built,
2469 Project.Decl.Attributes, In_Tree);
2472 if not Externally_Built.Default then
2473 Get_Name_String (Externally_Built.Value);
2474 To_Lower (Name_Buffer (1 .. Name_Len));
2476 if Name_Buffer (1 .. Name_Len) = "true" then
2477 Project.Externally_Built := True;
2479 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2480 Error_Msg (Project, In_Tree,
2481 "Externally_Built may only be true or false",
2482 Externally_Built.Location);
2486 -- A virtual project extending an externally built project is itself
2487 -- externally built.
2489 if Project.Virtual and then Project.Extends /= No_Project then
2490 Project.Externally_Built := Project.Extends.Externally_Built;
2493 if Current_Verbosity = High then
2494 Write_Str ("Project is ");
2496 if not Project.Externally_Built then
2500 Write_Line ("externally built.");
2502 end Check_If_Externally_Built;
2504 ----------------------
2505 -- Check_Interfaces --
2506 ----------------------
2508 procedure Check_Interfaces
2509 (Project : Project_Id;
2510 In_Tree : Project_Tree_Ref)
2512 Interfaces : constant Prj.Variable_Value :=
2514 (Snames.Name_Interfaces,
2515 Project.Decl.Attributes,
2518 List : String_List_Id;
2519 Element : String_Element;
2520 Name : File_Name_Type;
2521 Iter : Source_Iterator;
2523 Project_2 : Project_Id;
2526 if not Interfaces.Default then
2528 -- Set In_Interfaces to False for all sources. It will be set to True
2529 -- later for the sources in the Interfaces list.
2531 Project_2 := Project;
2532 while Project_2 /= No_Project loop
2533 Iter := For_Each_Source (In_Tree, Project_2);
2536 Source := Prj.Element (Iter);
2537 exit when Source = No_Source;
2538 Source.In_Interfaces := False;
2542 Project_2 := Project_2.Extends;
2545 List := Interfaces.Values;
2546 while List /= Nil_String loop
2547 Element := In_Tree.String_Elements.Table (List);
2548 Name := Canonical_Case_File_Name (Element.Value);
2550 Project_2 := Project;
2552 while Project_2 /= No_Project loop
2553 Iter := For_Each_Source (In_Tree, Project_2);
2556 Source := Prj.Element (Iter);
2557 exit when Source = No_Source;
2559 if Source.File = Name then
2560 if not Source.Locally_Removed then
2561 Source.In_Interfaces := True;
2562 Source.Declared_In_Interfaces := True;
2564 if Source.Other_Part /= No_Source then
2565 Source.Other_Part.In_Interfaces := True;
2566 Source.Other_Part.Declared_In_Interfaces := True;
2569 if Current_Verbosity = High then
2570 Write_Str (" interface: ");
2571 Write_Line (Get_Name_String (Source.Path.Name));
2581 Project_2 := Project_2.Extends;
2584 if Source = No_Source then
2585 Error_Msg_File_1 := File_Name_Type (Element.Value);
2586 Error_Msg_Name_1 := Project.Name;
2591 "{ cannot be an interface of project %% "
2592 & "as it is not one of its sources",
2596 List := Element.Next;
2599 Project.Interfaces_Defined := True;
2601 elsif Project.Extends /= No_Project then
2602 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2604 if Project.Interfaces_Defined then
2605 Iter := For_Each_Source (In_Tree, Project);
2607 Source := Prj.Element (Iter);
2608 exit when Source = No_Source;
2610 if not Source.Declared_In_Interfaces then
2611 Source.In_Interfaces := False;
2618 end Check_Interfaces;
2620 ------------------------------------
2621 -- Check_And_Normalize_Unit_Names --
2622 ------------------------------------
2624 procedure Check_And_Normalize_Unit_Names
2625 (Project : Project_Id;
2626 In_Tree : Project_Tree_Ref;
2627 List : Array_Element_Id;
2628 Debug_Name : String)
2630 Current : Array_Element_Id;
2631 Element : Array_Element;
2632 Unit_Name : Name_Id;
2635 if Current_Verbosity = High then
2636 Write_Line (" Checking unit names in " & Debug_Name);
2640 while Current /= No_Array_Element loop
2641 Element := In_Tree.Array_Elements.Table (Current);
2642 Element.Value.Value :=
2643 Name_Id (Canonical_Case_File_Name (Element.Value.Value));
2645 -- Check that it contains a valid unit name
2647 Get_Name_String (Element.Index);
2648 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
2650 if Unit_Name = No_Name then
2651 Err_Vars.Error_Msg_Name_1 := Element.Index;
2654 "%% is not a valid unit name.",
2655 Element.Value.Location);
2658 if Current_Verbosity = High then
2659 Write_Str (" for unit: ");
2660 Write_Line (Get_Name_String (Unit_Name));
2663 Element.Index := Unit_Name;
2664 In_Tree.Array_Elements.Table (Current) := Element;
2667 Current := Element.Next;
2669 end Check_And_Normalize_Unit_Names;
2671 --------------------------
2672 -- Check_Naming_Schemes --
2673 --------------------------
2675 procedure Check_Naming_Schemes
2676 (Project : Project_Id;
2677 In_Tree : Project_Tree_Ref;
2678 Is_Config_File : Boolean)
2680 Naming_Id : constant Package_Id :=
2681 Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
2682 Naming : Package_Element;
2684 procedure Check_Naming_Ada_Only;
2685 -- Does Check_Naming_Schemes processing in Ada_Only mode.
2686 -- If there is a package Naming, puts in Data.Naming the contents of
2689 procedure Check_Naming_Multi_Lang;
2690 -- Does Check_Naming_Schemes processing for Multi_Language mode
2692 procedure Check_Common
2693 (Dot_Replacement : in out File_Name_Type;
2694 Casing : in out Casing_Type;
2695 Casing_Defined : out Boolean;
2696 Separate_Suffix : in out File_Name_Type;
2697 Sep_Suffix_Loc : out Source_Ptr);
2698 -- Check attributes common to Ada_Only and Multi_Lang modes
2700 procedure Process_Exceptions_File_Based
2701 (Lang_Id : Language_Ptr;
2702 Kind : Source_Kind);
2703 procedure Process_Exceptions_Unit_Based
2704 (Lang_Id : Language_Ptr;
2705 Kind : Source_Kind);
2706 -- In Multi_Lang mode, process the naming exceptions for the two types
2707 -- of languages we can have.
2713 procedure Check_Common
2714 (Dot_Replacement : in out File_Name_Type;
2715 Casing : in out Casing_Type;
2716 Casing_Defined : out Boolean;
2717 Separate_Suffix : in out File_Name_Type;
2718 Sep_Suffix_Loc : out Source_Ptr)
2720 Dot_Repl : constant Variable_Value :=
2722 (Name_Dot_Replacement,
2723 Naming.Decl.Attributes,
2725 Casing_String : constant Variable_Value :=
2728 Naming.Decl.Attributes,
2730 Sep_Suffix : constant Variable_Value :=
2732 (Name_Separate_Suffix,
2733 Naming.Decl.Attributes,
2735 Dot_Repl_Loc : Source_Ptr;
2738 Sep_Suffix_Loc := No_Location;
2740 if not Dot_Repl.Default then
2742 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2744 if Length_Of_Name (Dot_Repl.Value) = 0 then
2747 "Dot_Replacement cannot be empty",
2751 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2752 Dot_Repl_Loc := Dot_Repl.Location;
2755 Repl : constant String := Get_Name_String (Dot_Replacement);
2758 -- Dot_Replacement cannot
2760 -- - start or end with an alphanumeric
2761 -- - be a single '_'
2762 -- - start with an '_' followed by an alphanumeric
2763 -- - contain a '.' except if it is "."
2766 or else Is_Alphanumeric (Repl (Repl'First))
2767 or else Is_Alphanumeric (Repl (Repl'Last))
2768 or else (Repl (Repl'First) = '_'
2772 Is_Alphanumeric (Repl (Repl'First + 1))))
2773 or else (Repl'Length > 1
2775 Index (Source => Repl, Pattern => ".") /= 0)
2780 """ is illegal for Dot_Replacement.",
2786 if Dot_Replacement /= No_File then
2788 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2791 Casing_Defined := False;
2793 if not Casing_String.Default then
2795 (Casing_String.Kind = Single, "Casing is not a string");
2798 Casing_Image : constant String :=
2799 Get_Name_String (Casing_String.Value);
2801 if Casing_Image'Length = 0 then
2804 "Casing cannot be an empty string",
2805 Casing_String.Location);
2808 Casing := Value (Casing_Image);
2809 Casing_Defined := True;
2812 when Constraint_Error =>
2813 Name_Len := Casing_Image'Length;
2814 Name_Buffer (1 .. Name_Len) := Casing_Image;
2815 Err_Vars.Error_Msg_Name_1 := Name_Find;
2818 "%% is not a correct Casing",
2819 Casing_String.Location);
2823 Write_Attr ("Casing", Image (Casing));
2825 if not Sep_Suffix.Default then
2826 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2829 "Separate_Suffix cannot be empty",
2830 Sep_Suffix.Location);
2833 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2834 Sep_Suffix_Loc := Sep_Suffix.Location;
2836 if Is_Illegal_Suffix (Separate_Suffix, Dot_Replacement) then
2837 Err_Vars.Error_Msg_File_1 := Separate_Suffix;
2840 "{ is illegal for Separate_Suffix",
2841 Sep_Suffix.Location);
2846 if Separate_Suffix /= No_File then
2848 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2852 -----------------------------------
2853 -- Process_Exceptions_File_Based --
2854 -----------------------------------
2856 procedure Process_Exceptions_File_Based
2857 (Lang_Id : Language_Ptr;
2860 Lang : constant Name_Id := Lang_Id.Name;
2861 Exceptions : Array_Element_Id;
2862 Exception_List : Variable_Value;
2863 Element_Id : String_List_Id;
2864 Element : String_Element;
2865 File_Name : File_Name_Type;
2867 Iter : Source_Iterator;
2874 (Name_Implementation_Exceptions,
2875 In_Arrays => Naming.Decl.Arrays,
2876 In_Tree => In_Tree);
2881 (Name_Specification_Exceptions,
2882 In_Arrays => Naming.Decl.Arrays,
2883 In_Tree => In_Tree);
2886 Exception_List := Value_Of
2888 In_Array => Exceptions,
2889 In_Tree => In_Tree);
2891 if Exception_List /= Nil_Variable_Value then
2892 Element_Id := Exception_List.Values;
2893 while Element_Id /= Nil_String loop
2894 Element := In_Tree.String_Elements.Table (Element_Id);
2895 File_Name := Canonical_Case_File_Name (Element.Value);
2897 Iter := For_Each_Source (In_Tree, Project);
2899 Source := Prj.Element (Iter);
2900 exit when Source = No_Source or else Source.File = File_Name;
2904 if Source = No_Source then
2911 File_Name => File_Name,
2912 Display_File => File_Name_Type (Element.Value),
2913 Naming_Exception => True);
2916 -- Check if the file name is already recorded for another
2917 -- language or another kind.
2919 if Source.Language /= Lang_Id then
2923 "the same file cannot be a source of two languages",
2926 elsif Source.Kind /= Kind then
2930 "the same file cannot be a source and a template",
2934 -- If the file is already recorded for the same
2935 -- language and the same kind, it means that the file
2936 -- name appears several times in the *_Exceptions
2937 -- attribute; so there is nothing to do.
2940 Element_Id := Element.Next;
2943 end Process_Exceptions_File_Based;
2945 -----------------------------------
2946 -- Process_Exceptions_Unit_Based --
2947 -----------------------------------
2949 procedure Process_Exceptions_Unit_Based
2950 (Lang_Id : Language_Ptr;
2953 Lang : constant Name_Id := Lang_Id.Name;
2954 Exceptions : Array_Element_Id;
2955 Element : Array_Element;
2958 File_Name : File_Name_Type;
2960 Source_To_Replace : Source_Id := No_Source;
2961 Other_Project : Project_Id;
2962 Other_Part : Source_Id := No_Source;
2963 Iter : Source_Iterator;
2968 Exceptions := Value_Of
2970 In_Arrays => Naming.Decl.Arrays,
2971 In_Tree => In_Tree);
2973 if Exceptions = No_Array_Element then
2976 (Name_Implementation,
2977 In_Arrays => Naming.Decl.Arrays,
2978 In_Tree => In_Tree);
2985 In_Arrays => Naming.Decl.Arrays,
2986 In_Tree => In_Tree);
2988 if Exceptions = No_Array_Element then
2989 Exceptions := Value_Of
2991 In_Arrays => Naming.Decl.Arrays,
2992 In_Tree => In_Tree);
2996 while Exceptions /= No_Array_Element loop
2997 Element := In_Tree.Array_Elements.Table (Exceptions);
2998 File_Name := Canonical_Case_File_Name (Element.Value.Value);
3000 Get_Name_String (Element.Index);
3001 To_Lower (Name_Buffer (1 .. Name_Len));
3003 Index := Element.Value.Index;
3005 -- For Ada, check if it is a valid unit name
3007 if Lang = Name_Ada then
3008 Get_Name_String (Element.Index);
3009 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
3011 if Unit = No_Name then
3012 Err_Vars.Error_Msg_Name_1 := Element.Index;
3015 "%% is not a valid unit name.",
3016 Element.Value.Location);
3020 if Unit /= No_Name then
3022 -- Check if the source already exists
3023 -- ??? In Ada_Only mode (Record_Unit), we use a htable for
3026 Source_To_Replace := No_Source;
3027 Iter := For_Each_Source (In_Tree);
3030 Source := Prj.Element (Iter);
3031 exit when Source = No_Source
3032 or else (Source.Unit /= null
3033 and then Source.Unit.Name = Unit
3034 and then Source.Index = Index);
3038 if Source /= No_Source then
3039 if Source.Kind /= Kind then
3040 Other_Part := Source;
3044 Source := Prj.Element (Iter);
3046 exit when Source = No_Source
3047 or else (Source.Unit /= null
3048 and then Source.Unit.Name = Unit
3049 and then Source.Index = Index);
3053 if Source /= No_Source then
3054 Other_Project := Source.Project;
3056 if Is_Extending (Project, Other_Project) then
3057 Other_Part := Source.Other_Part;
3059 -- Record the source to be removed
3061 Source_To_Replace := Source;
3062 Source := No_Source;
3065 Error_Msg_Name_1 := Unit;
3066 Error_Msg_Name_2 := Other_Project.Name;
3070 "%% is already a source of project %%",
3071 Element.Value.Location);
3076 if Source = No_Source then
3083 File_Name => File_Name,
3084 Display_File => File_Name_Type (Element.Value.Value),
3085 Other_Part => Other_Part,
3088 Naming_Exception => True,
3089 Source_To_Replace => Source_To_Replace);
3093 Exceptions := Element.Next;
3095 end Process_Exceptions_Unit_Based;
3097 ---------------------------
3098 -- Check_Naming_Ada_Only --
3099 ---------------------------
3101 procedure Check_Naming_Ada_Only is
3102 Casing_Defined : Boolean;
3103 Spec_Suffix : File_Name_Type;
3104 Body_Suffix : File_Name_Type;
3105 Sep_Suffix_Loc : Source_Ptr;
3107 Ada_Spec_Suffix : constant Variable_Value :=
3111 In_Array => Project.Naming.Spec_Suffix,
3112 In_Tree => In_Tree);
3114 Ada_Body_Suffix : constant Variable_Value :=
3118 In_Array => Project.Naming.Body_Suffix,
3119 In_Tree => In_Tree);
3122 -- The default value of separate suffix should be the same as the
3123 -- body suffix, so we need to compute that first.
3125 if Ada_Body_Suffix.Kind = Single
3126 and then Length_Of_Name (Ada_Body_Suffix.Value) /= 0
3128 Body_Suffix := Canonical_Case_File_Name (Ada_Body_Suffix.Value);
3129 Project.Naming.Separate_Suffix := Body_Suffix;
3130 Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
3133 Body_Suffix := Default_Ada_Body_Suffix;
3134 Project.Naming.Separate_Suffix := Body_Suffix;
3135 Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
3138 Write_Attr ("Body_Suffix", Get_Name_String (Body_Suffix));
3140 -- We'll need the dot replacement below, so compute it now
3143 (Dot_Replacement => Project.Naming.Dot_Replacement,
3144 Casing => Project.Naming.Casing,
3145 Casing_Defined => Casing_Defined,
3146 Separate_Suffix => Project.Naming.Separate_Suffix,
3147 Sep_Suffix_Loc => Sep_Suffix_Loc);
3149 Project.Naming.Bodies :=
3150 Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
3152 if Project.Naming.Bodies /= No_Array_Element then
3153 Check_And_Normalize_Unit_Names
3154 (Project, In_Tree, Project.Naming.Bodies, "Naming.Bodies");
3157 Project.Naming.Specs :=
3158 Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
3160 if Project.Naming.Specs /= No_Array_Element then
3161 Check_And_Normalize_Unit_Names
3162 (Project, In_Tree, Project.Naming.Specs, "Naming.Specs");
3165 -- Check Spec_Suffix
3167 if Ada_Spec_Suffix.Kind = Single
3168 and then Length_Of_Name (Ada_Spec_Suffix.Value) /= 0
3170 Spec_Suffix := Canonical_Case_File_Name (Ada_Spec_Suffix.Value);
3171 Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
3173 if Is_Illegal_Suffix
3174 (Spec_Suffix, Project.Naming.Dot_Replacement)
3176 Err_Vars.Error_Msg_File_1 := Spec_Suffix;
3179 "{ is illegal for Spec_Suffix",
3180 Ada_Spec_Suffix.Location);
3184 Spec_Suffix := Default_Ada_Spec_Suffix;
3185 Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
3188 Write_Attr ("Spec_Suffix", Get_Name_String (Spec_Suffix));
3190 -- Check Body_Suffix
3192 if Is_Illegal_Suffix
3193 (Body_Suffix, Project.Naming.Dot_Replacement)
3195 Err_Vars.Error_Msg_File_1 := Body_Suffix;
3198 "{ is illegal for Body_Suffix",
3199 Ada_Body_Suffix.Location);
3202 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3203 -- since that would cause a clear ambiguity. Note that we do allow a
3204 -- Spec_Suffix to have the same termination as one of these, which
3205 -- causes a potential ambiguity, but we resolve that my matching the
3206 -- longest possible suffix.
3208 if Spec_Suffix = Body_Suffix then
3212 Get_Name_String (Body_Suffix) &
3213 """) cannot be the same as Spec_Suffix.",
3214 Ada_Body_Suffix.Location);
3217 if Body_Suffix /= Project.Naming.Separate_Suffix
3218 and then Spec_Suffix = Project.Naming.Separate_Suffix
3222 "Separate_Suffix (""" &
3223 Get_Name_String (Project.Naming.Separate_Suffix) &
3224 """) cannot be the same as Spec_Suffix.",
3227 end Check_Naming_Ada_Only;
3229 -----------------------------
3230 -- Check_Naming_Multi_Lang --
3231 -----------------------------
3233 procedure Check_Naming_Multi_Lang is
3234 Dot_Replacement : File_Name_Type := No_File;
3235 Separate_Suffix : File_Name_Type := No_File;
3236 Casing : Casing_Type := All_Lower_Case;
3237 Casing_Defined : Boolean;
3238 Lang_Id : Language_Ptr;
3239 Sep_Suffix_Loc : Source_Ptr;
3240 Suffix : Variable_Value;
3245 (Dot_Replacement => Dot_Replacement,
3247 Casing_Defined => Casing_Defined,
3248 Separate_Suffix => Separate_Suffix,
3249 Sep_Suffix_Loc => Sep_Suffix_Loc);
3251 -- For all unit based languages, if any, set the specified
3252 -- value of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3253 -- systematically overwrite, since the defaults come from the
3254 -- configuration file
3256 if Dot_Replacement /= No_File
3257 or else Casing_Defined
3258 or else Separate_Suffix /= No_File
3260 Lang_Id := Project.Languages;
3261 while Lang_Id /= No_Language_Index loop
3262 if Lang_Id.Config.Kind = Unit_Based then
3263 if Dot_Replacement /= No_File then
3264 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3268 if Casing_Defined then
3269 Lang_Id.Config.Naming_Data.Casing := Casing;
3272 if Separate_Suffix /= No_File then
3273 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3278 Lang_Id := Lang_Id.Next;
3282 -- Next, get the spec and body suffixes
3284 Lang_Id := Project.Languages;
3285 while Lang_Id /= No_Language_Index loop
3286 Lang := Lang_Id.Name;
3292 Attribute_Or_Array_Name => Name_Spec_Suffix,
3293 In_Package => Naming_Id,
3294 In_Tree => In_Tree);
3296 if Suffix = Nil_Variable_Value then
3299 Attribute_Or_Array_Name => Name_Spec_Suffix,
3300 In_Package => Naming_Id,
3301 In_Tree => In_Tree);
3304 if Suffix /= Nil_Variable_Value then
3305 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3306 File_Name_Type (Suffix.Value);
3313 Attribute_Or_Array_Name => Name_Body_Suffix,
3314 In_Package => Naming_Id,
3315 In_Tree => In_Tree);
3317 if Suffix = Nil_Variable_Value then
3320 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3321 In_Package => Naming_Id,
3322 In_Tree => In_Tree);
3325 if Suffix /= Nil_Variable_Value then
3326 Lang_Id.Config.Naming_Data.Body_Suffix :=
3327 File_Name_Type (Suffix.Value);
3330 -- ??? As opposed to what is done in Check_Naming_Ada_Only,
3331 -- we do not check whether spec_suffix=body_suffix, which
3332 -- should be illegal. Best would be to share this code into
3333 -- Check_Common, but we access the attributes from the project
3334 -- files slightly differently apparently.
3336 Lang_Id := Lang_Id.Next;
3339 -- Get the naming exceptions for all languages
3341 for Kind in Spec .. Impl loop
3342 Lang_Id := Project.Languages;
3343 while Lang_Id /= No_Language_Index loop
3344 case Lang_Id.Config.Kind is
3346 Process_Exceptions_File_Based (Lang_Id, Kind);
3349 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3352 Lang_Id := Lang_Id.Next;
3355 end Check_Naming_Multi_Lang;
3357 -- Start of processing for Check_Naming_Schemes
3360 -- No Naming package or parsing a configuration file? nothing to do
3362 if Naming_Id /= No_Package and not Is_Config_File then
3363 Naming := In_Tree.Packages.Table (Naming_Id);
3365 if Current_Verbosity = High then
3366 Write_Line ("Checking package Naming.");
3371 Check_Naming_Ada_Only;
3372 when Multi_Language =>
3373 Check_Naming_Multi_Lang;
3376 end Check_Naming_Schemes;
3378 ------------------------------
3379 -- Check_Library_Attributes --
3380 ------------------------------
3382 procedure Check_Library_Attributes
3383 (Project : Project_Id;
3384 In_Tree : Project_Tree_Ref)
3386 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3388 Lib_Dir : constant Prj.Variable_Value :=
3390 (Snames.Name_Library_Dir, Attributes, In_Tree);
3392 Lib_Name : constant Prj.Variable_Value :=
3394 (Snames.Name_Library_Name, Attributes, In_Tree);
3396 Lib_Version : constant Prj.Variable_Value :=
3398 (Snames.Name_Library_Version, Attributes, In_Tree);
3400 Lib_ALI_Dir : constant Prj.Variable_Value :=
3402 (Snames.Name_Library_Ali_Dir, Attributes, In_Tree);
3404 Lib_GCC : constant Prj.Variable_Value :=
3406 (Snames.Name_Library_GCC, Attributes, In_Tree);
3408 The_Lib_Kind : constant Prj.Variable_Value :=
3410 (Snames.Name_Library_Kind, Attributes, In_Tree);
3412 Imported_Project_List : Project_List;
3414 Continuation : String_Access := No_Continuation_String'Access;
3416 Support_For_Libraries : Library_Support;
3418 Library_Directory_Present : Boolean;
3420 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3421 -- Check if an imported or extended project if also a library project
3427 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3429 Iter : Source_Iterator;
3432 if Proj /= No_Project then
3433 if not Proj.Library then
3435 -- The only not library projects that are OK are those that
3436 -- have no sources. However, header files from non-Ada
3437 -- languages are OK, as there is nothing to compile.
3439 Iter := For_Each_Source (In_Tree, Proj);
3441 Src_Id := Prj.Element (Iter);
3442 exit when Src_Id = No_Source
3443 or else Src_Id.Language.Config.Kind /= File_Based
3444 or else Src_Id.Kind /= Spec;
3448 if Src_Id /= No_Source then
3449 Error_Msg_Name_1 := Project.Name;
3450 Error_Msg_Name_2 := Proj.Name;
3453 if Project.Library_Kind /= Static then
3457 "shared library project %% cannot extend " &
3458 "project %% that is not a library project",
3460 Continuation := Continuation_String'Access;
3463 elsif (not Unchecked_Shared_Lib_Imports)
3464 and then Project.Library_Kind /= Static
3469 "shared library project %% cannot import project %% " &
3470 "that is not a shared library project",
3472 Continuation := Continuation_String'Access;
3476 elsif Project.Library_Kind /= Static and then
3477 Proj.Library_Kind = Static
3479 Error_Msg_Name_1 := Project.Name;
3480 Error_Msg_Name_2 := Proj.Name;
3486 "shared library project %% cannot extend static " &
3487 "library project %%",
3489 Continuation := Continuation_String'Access;
3491 elsif not Unchecked_Shared_Lib_Imports then
3495 "shared library project %% cannot import static " &
3496 "library project %%",
3498 Continuation := Continuation_String'Access;
3505 Dir_Exists : Boolean;
3507 -- Start of processing for Check_Library_Attributes
3510 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3512 -- Special case of extending project
3514 if Project.Extends /= No_Project then
3516 -- If the project extended is a library project, we inherit the
3517 -- library name, if it is not redefined; we check that the library
3518 -- directory is specified.
3520 if Project.Extends.Library then
3521 if Project.Qualifier = Standard then
3524 "a standard project cannot extend a library project",
3528 if Lib_Name.Default then
3529 Project.Library_Name := Project.Extends.Library_Name;
3532 if Lib_Dir.Default then
3533 if not Project.Virtual then
3536 "a project extending a library project must " &
3537 "specify an attribute Library_Dir",
3541 -- For a virtual project extending a library project,
3542 -- inherit library directory.
3544 Project.Library_Dir := Project.Extends.Library_Dir;
3545 Library_Directory_Present := True;
3552 pragma Assert (Lib_Name.Kind = Single);
3554 if Lib_Name.Value = Empty_String then
3555 if Current_Verbosity = High
3556 and then Project.Library_Name = No_Name
3558 Write_Line ("No library name");
3562 -- There is no restriction on the syntax of library names
3564 Project.Library_Name := Lib_Name.Value;
3567 if Project.Library_Name /= No_Name then
3568 if Current_Verbosity = High then
3570 ("Library name", Get_Name_String (Project.Library_Name));
3573 pragma Assert (Lib_Dir.Kind = Single);
3575 if not Library_Directory_Present then
3576 if Current_Verbosity = High then
3577 Write_Line ("No library directory");
3581 -- Find path name (unless inherited), check that it is a directory
3583 if Project.Library_Dir = No_Path_Information then
3587 File_Name_Type (Lib_Dir.Value),
3588 Path => Project.Library_Dir,
3589 Dir_Exists => Dir_Exists,
3590 Create => "library",
3591 Must_Exist => False,
3592 Location => Lib_Dir.Location,
3593 Externally_Built => Project.Externally_Built);
3599 (Project.Library_Dir.Display_Name));
3602 if not Dir_Exists then
3603 -- Get the absolute name of the library directory that
3604 -- does not exist, to report an error.
3606 Err_Vars.Error_Msg_File_1 :=
3607 File_Name_Type (Project.Library_Dir.Display_Name);
3610 "library directory { does not exist",
3613 -- The library directory cannot be the same as the Object
3616 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3619 "library directory cannot be the same " &
3620 "as object directory",
3622 Project.Library_Dir := No_Path_Information;
3626 OK : Boolean := True;
3627 Dirs_Id : String_List_Id;
3628 Dir_Elem : String_Element;
3632 -- The library directory cannot be the same as a source
3633 -- directory of the current project.
3635 Dirs_Id := Project.Source_Dirs;
3636 while Dirs_Id /= Nil_String loop
3637 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3638 Dirs_Id := Dir_Elem.Next;
3640 if Project.Library_Dir.Name =
3641 Path_Name_Type (Dir_Elem.Value)
3643 Err_Vars.Error_Msg_File_1 :=
3644 File_Name_Type (Dir_Elem.Value);
3647 "library directory cannot be the same " &
3648 "as source directory {",
3657 -- The library directory cannot be the same as a source
3658 -- directory of another project either.
3660 Pid := In_Tree.Projects;
3662 exit Project_Loop when Pid = null;
3664 if Pid.Project /= Project then
3665 Dirs_Id := Pid.Project.Source_Dirs;
3667 Dir_Loop : while Dirs_Id /= Nil_String loop
3669 In_Tree.String_Elements.Table (Dirs_Id);
3670 Dirs_Id := Dir_Elem.Next;
3672 if Project.Library_Dir.Name =
3673 Path_Name_Type (Dir_Elem.Value)
3675 Err_Vars.Error_Msg_File_1 :=
3676 File_Name_Type (Dir_Elem.Value);
3677 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3681 "library directory cannot be the same " &
3682 "as source directory { of project %%",
3691 end loop Project_Loop;
3695 Project.Library_Dir := No_Path_Information;
3697 elsif Current_Verbosity = High then
3699 -- Display the Library directory in high verbosity
3702 ("Library directory",
3703 Get_Name_String (Project.Library_Dir.Display_Name));
3712 Project.Library_Dir /= No_Path_Information
3713 and then Project.Library_Name /= No_Name;
3715 if Project.Extends = No_Project then
3716 case Project.Qualifier is
3718 if Project.Library then
3721 "a standard project cannot be a library project",
3726 if not Project.Library then
3727 if Project.Library_Dir = No_Path_Information then
3730 "\attribute Library_Dir not declared",
3734 if Project.Library_Name = No_Name then
3737 "\attribute Library_Name not declared",
3748 if Project.Library then
3749 if Get_Mode = Multi_Language then
3750 Support_For_Libraries := Project.Config.Lib_Support;
3753 Support_For_Libraries := MLib.Tgt.Support_For_Libraries;
3756 if Support_For_Libraries = Prj.None then
3759 "?libraries are not supported on this platform",
3761 Project.Library := False;
3764 if Lib_ALI_Dir.Value = Empty_String then
3765 if Current_Verbosity = High then
3766 Write_Line ("No library ALI directory specified");
3769 Project.Library_ALI_Dir := Project.Library_Dir;
3772 -- Find path name, check that it is a directory
3777 File_Name_Type (Lib_ALI_Dir.Value),
3778 Path => Project.Library_ALI_Dir,
3779 Create => "library ALI",
3780 Dir_Exists => Dir_Exists,
3781 Must_Exist => False,
3782 Location => Lib_ALI_Dir.Location,
3783 Externally_Built => Project.Externally_Built);
3785 if not Dir_Exists then
3786 -- Get the absolute name of the library ALI directory that
3787 -- does not exist, to report an error.
3789 Err_Vars.Error_Msg_File_1 :=
3790 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3793 "library 'A'L'I directory { does not exist",
3794 Lib_ALI_Dir.Location);
3797 if Project.Library_ALI_Dir /= Project.Library_Dir then
3799 -- The library ALI directory cannot be the same as the
3800 -- Object directory.
3802 if Project.Library_ALI_Dir = Project.Object_Directory then
3805 "library 'A'L'I directory cannot be the same " &
3806 "as object directory",
3807 Lib_ALI_Dir.Location);
3808 Project.Library_ALI_Dir := No_Path_Information;
3812 OK : Boolean := True;
3813 Dirs_Id : String_List_Id;
3814 Dir_Elem : String_Element;
3818 -- The library ALI directory cannot be the same as
3819 -- a source directory of the current project.
3821 Dirs_Id := Project.Source_Dirs;
3822 while Dirs_Id /= Nil_String loop
3823 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3824 Dirs_Id := Dir_Elem.Next;
3826 if Project.Library_ALI_Dir.Name =
3827 Path_Name_Type (Dir_Elem.Value)
3829 Err_Vars.Error_Msg_File_1 :=
3830 File_Name_Type (Dir_Elem.Value);
3833 "library 'A'L'I directory cannot be " &
3834 "the same as source directory {",
3835 Lib_ALI_Dir.Location);
3843 -- The library ALI directory cannot be the same as
3844 -- a source directory of another project either.
3846 Pid := In_Tree.Projects;
3847 ALI_Project_Loop : loop
3848 exit ALI_Project_Loop when Pid = null;
3850 if Pid.Project /= Project then
3851 Dirs_Id := Pid.Project.Source_Dirs;
3854 while Dirs_Id /= Nil_String loop
3856 In_Tree.String_Elements.Table (Dirs_Id);
3857 Dirs_Id := Dir_Elem.Next;
3859 if Project.Library_ALI_Dir.Name =
3860 Path_Name_Type (Dir_Elem.Value)
3862 Err_Vars.Error_Msg_File_1 :=
3863 File_Name_Type (Dir_Elem.Value);
3864 Err_Vars.Error_Msg_Name_1 :=
3869 "library 'A'L'I directory cannot " &
3870 "be the same as source directory " &
3872 Lib_ALI_Dir.Location);
3874 exit ALI_Project_Loop;
3876 end loop ALI_Dir_Loop;
3879 end loop ALI_Project_Loop;
3883 Project.Library_ALI_Dir := No_Path_Information;
3885 elsif Current_Verbosity = High then
3887 -- Display the Library ALI directory in high
3893 (Project.Library_ALI_Dir.Display_Name));
3900 pragma Assert (Lib_Version.Kind = Single);
3902 if Lib_Version.Value = Empty_String then
3903 if Current_Verbosity = High then
3904 Write_Line ("No library version specified");
3908 Project.Lib_Internal_Name := Lib_Version.Value;
3911 pragma Assert (The_Lib_Kind.Kind = Single);
3913 if The_Lib_Kind.Value = Empty_String then
3914 if Current_Verbosity = High then
3915 Write_Line ("No library kind specified");
3919 Get_Name_String (The_Lib_Kind.Value);
3922 Kind_Name : constant String :=
3923 To_Lower (Name_Buffer (1 .. Name_Len));
3925 OK : Boolean := True;
3928 if Kind_Name = "static" then
3929 Project.Library_Kind := Static;
3931 elsif Kind_Name = "dynamic" then
3932 Project.Library_Kind := Dynamic;
3934 elsif Kind_Name = "relocatable" then
3935 Project.Library_Kind := Relocatable;
3940 "illegal value for Library_Kind",
3941 The_Lib_Kind.Location);
3945 if Current_Verbosity = High and then OK then
3946 Write_Attr ("Library kind", Kind_Name);
3949 if Project.Library_Kind /= Static then
3950 if Support_For_Libraries = Prj.Static_Only then
3953 "only static libraries are supported " &
3955 The_Lib_Kind.Location);
3956 Project.Library := False;
3959 -- Check if (obsolescent) attribute Library_GCC or
3960 -- Linker'Driver is declared.
3962 if Lib_GCC.Value /= Empty_String then
3966 "?Library_'G'C'C is an obsolescent attribute, " &
3967 "use Linker''Driver instead",
3969 Project.Config.Shared_Lib_Driver :=
3970 File_Name_Type (Lib_GCC.Value);
3974 Linker : constant Package_Id :=
3977 Project.Decl.Packages,
3979 Driver : constant Variable_Value :=
3982 Attribute_Or_Array_Name =>
3984 In_Package => Linker,
3989 if Driver /= Nil_Variable_Value
3990 and then Driver.Value /= Empty_String
3992 Project.Config.Shared_Lib_Driver :=
3993 File_Name_Type (Driver.Value);
4002 if Project.Library then
4003 if Current_Verbosity = High then
4004 Write_Line ("This is a library project file");
4007 if Get_Mode = Multi_Language then
4008 Check_Library (Project.Extends, Extends => True);
4010 Imported_Project_List := Project.Imported_Projects;
4011 while Imported_Project_List /= null loop
4013 (Imported_Project_List.Project,
4015 Imported_Project_List := Imported_Project_List.Next;
4023 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4024 -- Warn if they are declared, as it is a common error to think that
4025 -- library are "linked" with Linker switches.
4027 if Project.Library then
4029 Linker_Package_Id : constant Package_Id :=
4032 Project.Decl.Packages, In_Tree);
4033 Linker_Package : Package_Element;
4034 Switches : Array_Element_Id := No_Array_Element;
4037 if Linker_Package_Id /= No_Package then
4038 Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
4042 (Name => Name_Switches,
4043 In_Arrays => Linker_Package.Decl.Arrays,
4044 In_Tree => In_Tree);
4046 if Switches = No_Array_Element then
4049 (Name => Name_Default_Switches,
4050 In_Arrays => Linker_Package.Decl.Arrays,
4051 In_Tree => In_Tree);
4054 if Switches /= No_Array_Element then
4057 "?Linker switches not taken into account in library " &
4065 if Project.Extends /= No_Project then
4066 Project.Extends.Library := False;
4068 end Check_Library_Attributes;
4070 --------------------------
4071 -- Check_Package_Naming --
4072 --------------------------
4074 procedure Check_Package_Naming
4075 (Project : Project_Id;
4076 In_Tree : Project_Tree_Ref)
4078 Naming_Id : constant Package_Id :=
4079 Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
4081 Naming : Package_Element;
4084 -- If there is a package Naming, we will put in Data.Naming
4085 -- what is in this package Naming.
4087 if Naming_Id /= No_Package then
4088 Naming := In_Tree.Packages.Table (Naming_Id);
4090 if Current_Verbosity = High then
4091 Write_Line ("Checking ""Naming"".");
4094 -- Check Spec_Suffix
4097 Spec_Suffixs : Array_Element_Id :=
4103 Suffix : Array_Element_Id;
4104 Element : Array_Element;
4105 Suffix2 : Array_Element_Id;
4108 -- If some suffixes have been specified, we make sure that
4109 -- for each language for which a default suffix has been
4110 -- specified, there is a suffix specified, either the one
4111 -- in the project file or if there were none, the default.
4113 if Spec_Suffixs /= No_Array_Element then
4114 Suffix := Project.Naming.Spec_Suffix;
4116 while Suffix /= No_Array_Element loop
4118 In_Tree.Array_Elements.Table (Suffix);
4119 Suffix2 := Spec_Suffixs;
4121 while Suffix2 /= No_Array_Element loop
4122 exit when In_Tree.Array_Elements.Table
4123 (Suffix2).Index = Element.Index;
4124 Suffix2 := In_Tree.Array_Elements.Table
4128 -- There is a registered default suffix, but no
4129 -- suffix specified in the project file.
4130 -- Add the default to the array.
4132 if Suffix2 = No_Array_Element then
4133 Array_Element_Table.Increment_Last
4134 (In_Tree.Array_Elements);
4135 In_Tree.Array_Elements.Table
4136 (Array_Element_Table.Last
4137 (In_Tree.Array_Elements)) :=
4138 (Index => Element.Index,
4139 Src_Index => Element.Src_Index,
4140 Index_Case_Sensitive => False,
4141 Value => Element.Value,
4142 Next => Spec_Suffixs);
4143 Spec_Suffixs := Array_Element_Table.Last
4144 (In_Tree.Array_Elements);
4147 Suffix := Element.Next;
4150 -- Put the resulting array as the Spec suffixes
4152 Project.Naming.Spec_Suffix := Spec_Suffixs;
4156 -- Check Body_Suffix
4159 Impl_Suffixs : Array_Element_Id :=
4165 Suffix : Array_Element_Id;
4166 Element : Array_Element;
4167 Suffix2 : Array_Element_Id;
4170 -- If some suffixes have been specified, we make sure that
4171 -- for each language for which a default suffix has been
4172 -- specified, there is a suffix specified, either the one
4173 -- in the project file or if there were none, the default.
4175 if Impl_Suffixs /= No_Array_Element then
4176 Suffix := Project.Naming.Body_Suffix;
4177 while Suffix /= No_Array_Element loop
4179 In_Tree.Array_Elements.Table (Suffix);
4181 Suffix2 := Impl_Suffixs;
4182 while Suffix2 /= No_Array_Element loop
4183 exit when In_Tree.Array_Elements.Table
4184 (Suffix2).Index = Element.Index;
4185 Suffix2 := In_Tree.Array_Elements.Table
4189 -- There is a registered default suffix, but no suffix was
4190 -- specified in the project file. Add default to the array.
4192 if Suffix2 = No_Array_Element then
4193 Array_Element_Table.Increment_Last
4194 (In_Tree.Array_Elements);
4195 In_Tree.Array_Elements.Table
4196 (Array_Element_Table.Last
4197 (In_Tree.Array_Elements)) :=
4198 (Index => Element.Index,
4199 Src_Index => Element.Src_Index,
4200 Index_Case_Sensitive => False,
4201 Value => Element.Value,
4202 Next => Impl_Suffixs);
4203 Impl_Suffixs := Array_Element_Table.Last
4204 (In_Tree.Array_Elements);
4207 Suffix := Element.Next;
4210 -- Put the resulting array as the implementation suffixes
4212 Project.Naming.Body_Suffix := Impl_Suffixs;
4216 -- Get the exceptions, if any
4218 Project.Naming.Specification_Exceptions :=
4220 (Name_Specification_Exceptions,
4221 In_Arrays => Naming.Decl.Arrays,
4222 In_Tree => In_Tree);
4224 Project.Naming.Implementation_Exceptions :=
4226 (Name_Implementation_Exceptions,
4227 In_Arrays => Naming.Decl.Arrays,
4228 In_Tree => In_Tree);
4230 end Check_Package_Naming;
4232 ---------------------------------
4233 -- Check_Programming_Languages --
4234 ---------------------------------
4236 procedure Check_Programming_Languages
4237 (In_Tree : Project_Tree_Ref;
4238 Project : Project_Id)
4240 Languages : Variable_Value := Nil_Variable_Value;
4241 Def_Lang : Variable_Value := Nil_Variable_Value;
4242 Def_Lang_Id : Name_Id;
4245 Project.Languages := No_Language_Index;
4247 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, In_Tree);
4250 (Name_Default_Language, Project.Decl.Attributes, In_Tree);
4252 -- Shouldn't these be set to False by default, and only set to True when
4253 -- we actually find some source file???
4255 if Project.Source_Dirs /= Nil_String then
4257 -- Check if languages are specified in this project
4259 if Languages.Default then
4261 -- In Ada_Only mode, the default language is Ada
4263 if Get_Mode = Ada_Only then
4264 Def_Lang_Id := Name_Ada;
4267 -- Fail if there is no default language defined
4269 if Def_Lang.Default then
4270 if not Default_Language_Is_Ada then
4274 "no languages defined for this project",
4276 Def_Lang_Id := No_Name;
4278 Def_Lang_Id := Name_Ada;
4282 Get_Name_String (Def_Lang.Value);
4283 To_Lower (Name_Buffer (1 .. Name_Len));
4284 Def_Lang_Id := Name_Find;
4288 if Def_Lang_Id /= No_Name then
4289 Project.Languages := new Language_Data'(No_Language_Data);
4290 Project.Languages.Name := Def_Lang_Id;
4291 Get_Name_String (Def_Lang_Id);
4292 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4293 Project.Languages.Display_Name := Name_Find;
4295 if Def_Lang_Id = Name_Ada then
4296 Project.Languages.Config.Kind := Unit_Based;
4297 Project.Languages.Config.Dependency_Kind := ALI_File;
4299 Project.Languages.Config.Kind := File_Based;
4305 Current : String_List_Id := Languages.Values;
4306 Element : String_Element;
4307 Lang_Name : Name_Id;
4308 Index : Language_Ptr;
4309 NL_Id : Language_Ptr;
4312 -- If there are no languages declared, there are no sources
4314 if Current = Nil_String then
4315 Project.Source_Dirs := Nil_String;
4317 if Project.Qualifier = Standard then
4321 "a standard project must have at least one language",
4322 Languages.Location);
4326 -- Look through all the languages specified in attribute
4329 while Current /= Nil_String loop
4330 Element := In_Tree.String_Elements.Table (Current);
4331 Get_Name_String (Element.Value);
4332 To_Lower (Name_Buffer (1 .. Name_Len));
4333 Lang_Name := Name_Find;
4335 -- If the language was not already specified (duplicates
4336 -- are simply ignored).
4338 NL_Id := Project.Languages;
4339 while NL_Id /= No_Language_Index loop
4340 exit when Lang_Name = NL_Id.Name;
4341 NL_Id := NL_Id.Next;
4344 if NL_Id = No_Language_Index then
4345 Index := new Language_Data'(No_Language_Data);
4346 Index.Name := Lang_Name;
4347 Index.Display_Name := Element.Value;
4348 Index.Next := Project.Languages;
4350 if Lang_Name = Name_Ada then
4351 Index.Config.Kind := Unit_Based;
4352 Index.Config.Dependency_Kind := ALI_File;
4355 Index.Config.Kind := File_Based;
4356 Index.Config.Dependency_Kind := None;
4359 Project.Languages := Index;
4362 Current := Element.Next;
4368 end Check_Programming_Languages;
4374 function Check_Project
4376 Root_Project : Project_Id;
4377 Extending : Boolean) return Boolean
4381 if P = Root_Project then
4384 elsif Extending then
4385 Prj := Root_Project;
4386 while Prj.Extends /= No_Project loop
4387 if P = Prj.Extends then
4398 -------------------------------
4399 -- Check_Stand_Alone_Library --
4400 -------------------------------
4402 procedure Check_Stand_Alone_Library
4403 (Project : Project_Id;
4404 In_Tree : Project_Tree_Ref;
4405 Current_Dir : String;
4406 Extending : Boolean)
4408 Lib_Interfaces : constant Prj.Variable_Value :=
4410 (Snames.Name_Library_Interface,
4411 Project.Decl.Attributes,
4414 Lib_Auto_Init : constant Prj.Variable_Value :=
4416 (Snames.Name_Library_Auto_Init,
4417 Project.Decl.Attributes,
4420 Lib_Src_Dir : constant Prj.Variable_Value :=
4422 (Snames.Name_Library_Src_Dir,
4423 Project.Decl.Attributes,
4426 Lib_Symbol_File : constant Prj.Variable_Value :=
4428 (Snames.Name_Library_Symbol_File,
4429 Project.Decl.Attributes,
4432 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4434 (Snames.Name_Library_Symbol_Policy,
4435 Project.Decl.Attributes,
4438 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4440 (Snames.Name_Library_Reference_Symbol_File,
4441 Project.Decl.Attributes,
4444 Auto_Init_Supported : Boolean;
4445 OK : Boolean := True;
4447 Next_Proj : Project_Id;
4448 Iter : Source_Iterator;
4451 if Get_Mode = Multi_Language then
4452 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4454 Auto_Init_Supported :=
4455 MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported;
4458 pragma Assert (Lib_Interfaces.Kind = List);
4460 -- It is a stand-alone library project file if attribute
4461 -- Library_Interface is defined.
4463 if not Lib_Interfaces.Default then
4464 SAL_Library : declare
4465 Interfaces : String_List_Id := Lib_Interfaces.Values;
4466 Interface_ALIs : String_List_Id := Nil_String;
4470 procedure Add_ALI_For (Source : File_Name_Type);
4471 -- Add an ALI file name to the list of Interface ALIs
4477 procedure Add_ALI_For (Source : File_Name_Type) is
4479 Get_Name_String (Source);
4482 ALI : constant String :=
4483 ALI_File_Name (Name_Buffer (1 .. Name_Len));
4484 ALI_Name_Id : Name_Id;
4487 Name_Len := ALI'Length;
4488 Name_Buffer (1 .. Name_Len) := ALI;
4489 ALI_Name_Id := Name_Find;
4491 String_Element_Table.Increment_Last
4492 (In_Tree.String_Elements);
4493 In_Tree.String_Elements.Table
4494 (String_Element_Table.Last
4495 (In_Tree.String_Elements)) :=
4496 (Value => ALI_Name_Id,
4498 Display_Value => ALI_Name_Id,
4500 In_Tree.String_Elements.Table
4501 (Interfaces).Location,
4503 Next => Interface_ALIs);
4504 Interface_ALIs := String_Element_Table.Last
4505 (In_Tree.String_Elements);
4509 -- Start of processing for SAL_Library
4512 Project.Standalone_Library := True;
4514 -- Library_Interface cannot be an empty list
4516 if Interfaces = Nil_String then
4519 "Library_Interface cannot be an empty list",
4520 Lib_Interfaces.Location);
4523 -- Process each unit name specified in the attribute
4524 -- Library_Interface.
4526 while Interfaces /= Nil_String loop
4528 (In_Tree.String_Elements.Table (Interfaces).Value);
4529 To_Lower (Name_Buffer (1 .. Name_Len));
4531 if Name_Len = 0 then
4534 "an interface cannot be an empty string",
4535 In_Tree.String_Elements.Table (Interfaces).Location);
4539 Error_Msg_Name_1 := Unit;
4541 if Get_Mode = Ada_Only then
4542 UData := Units_Htable.Get (In_Tree.Units_HT, Unit);
4544 if UData = No_Unit_Index then
4548 In_Tree.String_Elements.Table
4549 (Interfaces).Location);
4552 -- Check that the unit is part of the project
4554 if UData.File_Names (Impl) /= null
4555 and then UData.File_Names (Impl).Path.Name /= Slash
4558 (UData.File_Names (Impl).Project,
4561 -- There is a body for this unit.
4562 -- If there is no spec, we need to check that it
4563 -- is not a subunit.
4565 if UData.File_Names (Spec) = null then
4567 Src_Ind : Source_File_Index;
4571 Sinput.P.Load_Project_File
4572 (Get_Name_String (UData.File_Names
4575 if Sinput.P.Source_File_Is_Subunit
4580 "%% is a subunit; " &
4581 "it cannot be an interface",
4583 String_Elements.Table
4584 (Interfaces).Location);
4589 -- The unit is not a subunit, so we add the
4590 -- ALI file for its body to the Interface ALIs.
4593 (UData.File_Names (Impl).File);
4598 "%% is not an unit of this project",
4599 In_Tree.String_Elements.Table
4600 (Interfaces).Location);
4603 elsif UData.File_Names (Spec) /= null
4604 and then UData.File_Names (Spec).Path.Name /= Slash
4605 and then Check_Project
4606 (UData.File_Names (Spec).Project,
4610 -- The unit is part of the project, it has a spec,
4611 -- but no body. We add the ALI for its spec to the
4615 (UData.File_Names (Spec).File);
4620 "%% is not an unit of this project",
4621 In_Tree.String_Elements.Table
4622 (Interfaces).Location);
4627 -- Multi_Language mode
4629 Next_Proj := Project.Extends;
4630 Iter := For_Each_Source (In_Tree, Project);
4632 while Prj.Element (Iter) /= No_Source
4634 (Prj.Element (Iter).Unit = null
4635 or else Prj.Element (Iter).Unit.Name /= Unit)
4640 Source := Prj.Element (Iter);
4641 exit when Source /= No_Source
4642 or else Next_Proj = No_Project;
4644 Iter := For_Each_Source (In_Tree, Next_Proj);
4645 Next_Proj := Next_Proj.Extends;
4648 if Source /= No_Source then
4649 if Source.Kind = Sep then
4650 Source := No_Source;
4651 elsif Source.Kind = Spec
4652 and then Source.Other_Part /= No_Source
4654 Source := Source.Other_Part;
4658 if Source /= No_Source then
4659 if Source.Project /= Project
4660 and then not Is_Extending (Project, Source.Project)
4662 Source := No_Source;
4666 if Source = No_Source then
4669 "%% is not an unit of this project",
4670 In_Tree.String_Elements.Table
4671 (Interfaces).Location);
4674 if Source.Kind = Spec and then
4675 Source.Other_Part /= No_Source
4677 Source := Source.Other_Part;
4680 String_Element_Table.Increment_Last
4681 (In_Tree.String_Elements);
4683 In_Tree.String_Elements.Table
4684 (String_Element_Table.Last
4685 (In_Tree.String_Elements)) :=
4686 (Value => Name_Id (Source.Dep_Name),
4688 Display_Value => Name_Id (Source.Dep_Name),
4690 In_Tree.String_Elements.Table
4691 (Interfaces).Location,
4693 Next => Interface_ALIs);
4696 String_Element_Table.Last (In_Tree.String_Elements);
4704 In_Tree.String_Elements.Table (Interfaces).Next;
4707 -- Put the list of Interface ALIs in the project data
4709 Project.Lib_Interface_ALIs := Interface_ALIs;
4711 -- Check value of attribute Library_Auto_Init and set
4712 -- Lib_Auto_Init accordingly.
4714 if Lib_Auto_Init.Default then
4716 -- If no attribute Library_Auto_Init is declared, then set auto
4717 -- init only if it is supported.
4719 Project.Lib_Auto_Init := Auto_Init_Supported;
4722 Get_Name_String (Lib_Auto_Init.Value);
4723 To_Lower (Name_Buffer (1 .. Name_Len));
4725 if Name_Buffer (1 .. Name_Len) = "false" then
4726 Project.Lib_Auto_Init := False;
4728 elsif Name_Buffer (1 .. Name_Len) = "true" then
4729 if Auto_Init_Supported then
4730 Project.Lib_Auto_Init := True;
4733 -- Library_Auto_Init cannot be "true" if auto init is not
4738 "library auto init not supported " &
4740 Lib_Auto_Init.Location);
4746 "invalid value for attribute Library_Auto_Init",
4747 Lib_Auto_Init.Location);
4752 -- If attribute Library_Src_Dir is defined and not the empty string,
4753 -- check if the directory exist and is not the object directory or
4754 -- one of the source directories. This is the directory where copies
4755 -- of the interface sources will be copied. Note that this directory
4756 -- may be the library directory.
4758 if Lib_Src_Dir.Value /= Empty_String then
4760 Dir_Id : constant File_Name_Type :=
4761 File_Name_Type (Lib_Src_Dir.Value);
4762 Dir_Exists : Boolean;
4769 Path => Project.Library_Src_Dir,
4770 Dir_Exists => Dir_Exists,
4771 Must_Exist => False,
4772 Create => "library source copy",
4773 Location => Lib_Src_Dir.Location,
4774 Externally_Built => Project.Externally_Built);
4776 -- If directory does not exist, report an error
4778 if not Dir_Exists then
4779 -- Get the absolute name of the library directory that does
4780 -- not exist, to report an error.
4782 Err_Vars.Error_Msg_File_1 :=
4783 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4786 "Directory { does not exist",
4787 Lib_Src_Dir.Location);
4789 -- Report error if it is the same as the object directory
4791 elsif Project.Library_Src_Dir = Project.Object_Directory then
4794 "directory to copy interfaces cannot be " &
4795 "the object directory",
4796 Lib_Src_Dir.Location);
4797 Project.Library_Src_Dir := No_Path_Information;
4801 Src_Dirs : String_List_Id;
4802 Src_Dir : String_Element;
4806 -- Interface copy directory cannot be one of the source
4807 -- directory of the current project.
4809 Src_Dirs := Project.Source_Dirs;
4810 while Src_Dirs /= Nil_String loop
4811 Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
4813 -- Report error if it is one of the source directories
4815 if Project.Library_Src_Dir.Name =
4816 Path_Name_Type (Src_Dir.Value)
4820 "directory to copy interfaces cannot " &
4821 "be one of the source directories",
4822 Lib_Src_Dir.Location);
4823 Project.Library_Src_Dir := No_Path_Information;
4827 Src_Dirs := Src_Dir.Next;
4830 if Project.Library_Src_Dir /= No_Path_Information then
4832 -- It cannot be a source directory of any other
4835 Pid := In_Tree.Projects;
4837 exit Project_Loop when Pid = null;
4839 Src_Dirs := Pid.Project.Source_Dirs;
4840 Dir_Loop : while Src_Dirs /= Nil_String loop
4842 In_Tree.String_Elements.Table (Src_Dirs);
4844 -- Report error if it is one of the source
4847 if Project.Library_Src_Dir.Name =
4848 Path_Name_Type (Src_Dir.Value)
4851 File_Name_Type (Src_Dir.Value);
4852 Error_Msg_Name_1 := Pid.Project.Name;
4855 "directory to copy interfaces cannot " &
4856 "be the same as source directory { of " &
4858 Lib_Src_Dir.Location);
4859 Project.Library_Src_Dir :=
4860 No_Path_Information;
4864 Src_Dirs := Src_Dir.Next;
4868 end loop Project_Loop;
4872 -- In high verbosity, if there is a valid Library_Src_Dir,
4873 -- display its path name.
4875 if Project.Library_Src_Dir /= No_Path_Information
4876 and then Current_Verbosity = High
4879 ("Directory to copy interfaces",
4880 Get_Name_String (Project.Library_Src_Dir.Name));
4886 -- Check the symbol related attributes
4888 -- First, the symbol policy
4890 if not Lib_Symbol_Policy.Default then
4892 Value : constant String :=
4894 (Get_Name_String (Lib_Symbol_Policy.Value));
4897 -- Symbol policy must hove one of a limited number of values
4899 if Value = "autonomous" or else Value = "default" then
4900 Project.Symbol_Data.Symbol_Policy := Autonomous;
4902 elsif Value = "compliant" then
4903 Project.Symbol_Data.Symbol_Policy := Compliant;
4905 elsif Value = "controlled" then
4906 Project.Symbol_Data.Symbol_Policy := Controlled;
4908 elsif Value = "restricted" then
4909 Project.Symbol_Data.Symbol_Policy := Restricted;
4911 elsif Value = "direct" then
4912 Project.Symbol_Data.Symbol_Policy := Direct;
4917 "illegal value for Library_Symbol_Policy",
4918 Lib_Symbol_Policy.Location);
4923 -- If attribute Library_Symbol_File is not specified, symbol policy
4924 -- cannot be Restricted.
4926 if Lib_Symbol_File.Default then
4927 if Project.Symbol_Data.Symbol_Policy = Restricted then
4930 "Library_Symbol_File needs to be defined when " &
4931 "symbol policy is Restricted",
4932 Lib_Symbol_Policy.Location);
4936 -- Library_Symbol_File is defined
4938 Project.Symbol_Data.Symbol_File :=
4939 Path_Name_Type (Lib_Symbol_File.Value);
4941 Get_Name_String (Lib_Symbol_File.Value);
4943 if Name_Len = 0 then
4946 "symbol file name cannot be an empty string",
4947 Lib_Symbol_File.Location);
4950 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4953 for J in 1 .. Name_Len loop
4954 if Name_Buffer (J) = '/'
4955 or else Name_Buffer (J) = Directory_Separator
4964 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4967 "symbol file name { is illegal. " &
4968 "Name cannot include directory info.",
4969 Lib_Symbol_File.Location);
4974 -- If attribute Library_Reference_Symbol_File is not defined,
4975 -- symbol policy cannot be Compliant or Controlled.
4977 if Lib_Ref_Symbol_File.Default then
4978 if Project.Symbol_Data.Symbol_Policy = Compliant
4979 or else Project.Symbol_Data.Symbol_Policy = Controlled
4983 "a reference symbol file needs to be defined",
4984 Lib_Symbol_Policy.Location);
4988 -- Library_Reference_Symbol_File is defined, check file exists
4990 Project.Symbol_Data.Reference :=
4991 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4993 Get_Name_String (Lib_Ref_Symbol_File.Value);
4995 if Name_Len = 0 then
4998 "reference symbol file name cannot be an empty string",
4999 Lib_Symbol_File.Location);
5002 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
5004 Add_Str_To_Name_Buffer
5005 (Get_Name_String (Project.Directory.Name));
5006 Add_Char_To_Name_Buffer (Directory_Separator);
5007 Add_Str_To_Name_Buffer
5008 (Get_Name_String (Lib_Ref_Symbol_File.Value));
5009 Project.Symbol_Data.Reference := Name_Find;
5012 if not Is_Regular_File
5013 (Get_Name_String (Project.Symbol_Data.Reference))
5016 File_Name_Type (Lib_Ref_Symbol_File.Value);
5018 -- For controlled and direct symbol policies, it is an error
5019 -- if the reference symbol file does not exist. For other
5020 -- symbol policies, this is just a warning
5023 Project.Symbol_Data.Symbol_Policy /= Controlled
5024 and then Project.Symbol_Data.Symbol_Policy /= Direct;
5028 "<library reference symbol file { does not exist",
5029 Lib_Ref_Symbol_File.Location);
5031 -- In addition in the non-controlled case, if symbol policy
5032 -- is Compliant, it is changed to Autonomous, because there
5033 -- is no reference to check against, and we don't want to
5034 -- fail in this case.
5036 if Project.Symbol_Data.Symbol_Policy /= Controlled then
5037 if Project.Symbol_Data.Symbol_Policy = Compliant then
5038 Project.Symbol_Data.Symbol_Policy := Autonomous;
5043 -- If both the reference symbol file and the symbol file are
5044 -- defined, then check that they are not the same file.
5046 if Project.Symbol_Data.Symbol_File /= No_Path then
5047 Get_Name_String (Project.Symbol_Data.Symbol_File);
5049 if Name_Len > 0 then
5051 Symb_Path : constant String :=
5054 (Project.Object_Directory.Name) &
5055 Directory_Separator &
5056 Name_Buffer (1 .. Name_Len),
5057 Directory => Current_Dir,
5059 Opt.Follow_Links_For_Files);
5060 Ref_Path : constant String :=
5063 (Project.Symbol_Data.Reference),
5064 Directory => Current_Dir,
5066 Opt.Follow_Links_For_Files);
5068 if Symb_Path = Ref_Path then
5071 "library reference symbol file and library" &
5072 " symbol file cannot be the same file",
5073 Lib_Ref_Symbol_File.Location);
5081 end Check_Stand_Alone_Library;
5083 ----------------------------
5084 -- Compute_Directory_Last --
5085 ----------------------------
5087 function Compute_Directory_Last (Dir : String) return Natural is
5090 and then (Dir (Dir'Last - 1) = Directory_Separator
5091 or else Dir (Dir'Last - 1) = '/')
5093 return Dir'Last - 1;
5097 end Compute_Directory_Last;
5104 (Project : Project_Id;
5105 In_Tree : Project_Tree_Ref;
5107 Flag_Location : Source_Ptr)
5109 Real_Location : Source_Ptr := Flag_Location;
5110 Error_Buffer : String (1 .. 5_000);
5111 Error_Last : Natural := 0;
5112 Name_Number : Natural := 0;
5113 File_Number : Natural := 0;
5114 First : Positive := Msg'First;
5117 procedure Add (C : Character);
5118 -- Add a character to the buffer
5120 procedure Add (S : String);
5121 -- Add a string to the buffer
5124 -- Add a name to the buffer
5127 -- Add a file name to the buffer
5133 procedure Add (C : Character) is
5135 Error_Last := Error_Last + 1;
5136 Error_Buffer (Error_Last) := C;
5139 procedure Add (S : String) is
5141 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
5142 Error_Last := Error_Last + S'Length;
5149 procedure Add_File is
5150 File : File_Name_Type;
5154 File_Number := File_Number + 1;
5158 File := Err_Vars.Error_Msg_File_1;
5160 File := Err_Vars.Error_Msg_File_2;
5162 File := Err_Vars.Error_Msg_File_3;
5167 Get_Name_String (File);
5168 Add (Name_Buffer (1 .. Name_Len));
5176 procedure Add_Name is
5181 Name_Number := Name_Number + 1;
5185 Name := Err_Vars.Error_Msg_Name_1;
5187 Name := Err_Vars.Error_Msg_Name_2;
5189 Name := Err_Vars.Error_Msg_Name_3;
5194 Get_Name_String (Name);
5195 Add (Name_Buffer (1 .. Name_Len));
5199 -- Start of processing for Error_Msg
5202 -- If location of error is unknown, use the location of the project
5204 if Real_Location = No_Location then
5205 Real_Location := Project.Location;
5208 if Error_Report = null then
5209 Prj.Err.Error_Msg (Msg, Real_Location);
5213 -- Ignore continuation character
5215 if Msg (First) = '\' then
5219 -- Warning character is always the first one in this package
5220 -- this is an undocumented kludge???
5222 if Msg (First) = '?' then
5226 elsif Msg (First) = '<' then
5229 if Err_Vars.Error_Msg_Warn then
5235 while Index <= Msg'Last loop
5236 if Msg (Index) = '{' then
5239 elsif Msg (Index) = '%' then
5240 if Index < Msg'Last and then Msg (Index + 1) = '%' then
5252 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
5255 --------------------------------
5256 -- Free_Ada_Naming_Exceptions --
5257 --------------------------------
5259 procedure Free_Ada_Naming_Exceptions is
5261 Ada_Naming_Exception_Table.Set_Last (0);
5262 Ada_Naming_Exceptions.Reset;
5263 Reverse_Ada_Naming_Exceptions.Reset;
5264 end Free_Ada_Naming_Exceptions;
5266 ---------------------
5267 -- Get_Directories --
5268 ---------------------
5270 procedure Get_Directories
5271 (Project : Project_Id;
5272 In_Tree : Project_Tree_Ref;
5273 Current_Dir : String)
5275 Object_Dir : constant Variable_Value :=
5277 (Name_Object_Dir, Project.Decl.Attributes, In_Tree);
5279 Exec_Dir : constant Variable_Value :=
5281 (Name_Exec_Dir, Project.Decl.Attributes, In_Tree);
5283 Source_Dirs : constant Variable_Value :=
5285 (Name_Source_Dirs, Project.Decl.Attributes, In_Tree);
5287 Excluded_Source_Dirs : constant Variable_Value :=
5289 (Name_Excluded_Source_Dirs,
5290 Project.Decl.Attributes,
5293 Source_Files : constant Variable_Value :=
5295 (Name_Source_Files, Project.Decl.Attributes, In_Tree);
5297 Last_Source_Dir : String_List_Id := Nil_String;
5299 Languages : constant Variable_Value :=
5301 (Name_Languages, Project.Decl.Attributes, In_Tree);
5303 procedure Find_Source_Dirs
5304 (From : File_Name_Type;
5305 Location : Source_Ptr;
5306 Removed : Boolean := False);
5307 -- Find one or several source directories, and add (or remove, if
5308 -- Removed is True) them to list of source directories of the project.
5310 ----------------------
5311 -- Find_Source_Dirs --
5312 ----------------------
5314 procedure Find_Source_Dirs
5315 (From : File_Name_Type;
5316 Location : Source_Ptr;
5317 Removed : Boolean := False)
5319 Directory : constant String := Get_Name_String (From);
5320 Element : String_Element;
5322 procedure Recursive_Find_Dirs (Path : Name_Id);
5323 -- Find all the subdirectories (recursively) of Path and add them
5324 -- to the list of source directories of the project.
5326 -------------------------
5327 -- Recursive_Find_Dirs --
5328 -------------------------
5330 procedure Recursive_Find_Dirs (Path : Name_Id) is
5332 Name : String (1 .. 250);
5334 List : String_List_Id;
5335 Prev : String_List_Id;
5336 Element : String_Element;
5337 Found : Boolean := False;
5339 Non_Canonical_Path : Name_Id := No_Name;
5340 Canonical_Path : Name_Id := No_Name;
5342 The_Path : constant String :=
5344 (Get_Name_String (Path),
5345 Directory => Current_Dir,
5346 Resolve_Links => Opt.Follow_Links_For_Dirs) &
5347 Directory_Separator;
5349 The_Path_Last : constant Natural :=
5350 Compute_Directory_Last (The_Path);
5353 Name_Len := The_Path_Last - The_Path'First + 1;
5354 Name_Buffer (1 .. Name_Len) :=
5355 The_Path (The_Path'First .. The_Path_Last);
5356 Non_Canonical_Path := Name_Find;
5358 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
5360 -- To avoid processing the same directory several times, check
5361 -- if the directory is already in Recursive_Dirs. If it is, then
5362 -- there is nothing to do, just return. If it is not, put it there
5363 -- and continue recursive processing.
5366 if Recursive_Dirs.Get (Canonical_Path) then
5369 Recursive_Dirs.Set (Canonical_Path, True);
5373 -- Check if directory is already in list
5375 List := Project.Source_Dirs;
5377 while List /= Nil_String loop
5378 Element := In_Tree.String_Elements.Table (List);
5380 if Element.Value /= No_Name then
5381 Found := Element.Value = Canonical_Path;
5386 List := Element.Next;
5389 -- If directory is not already in list, put it there
5391 if (not Removed) and (not Found) then
5392 if Current_Verbosity = High then
5394 Write_Line (The_Path (The_Path'First .. The_Path_Last));
5397 String_Element_Table.Increment_Last
5398 (In_Tree.String_Elements);
5400 (Value => Canonical_Path,
5401 Display_Value => Non_Canonical_Path,
5402 Location => No_Location,
5407 -- Case of first source directory
5409 if Last_Source_Dir = Nil_String then
5410 Project.Source_Dirs := String_Element_Table.Last
5411 (In_Tree.String_Elements);
5413 -- Here we already have source directories
5416 -- Link the previous last to the new one
5418 In_Tree.String_Elements.Table
5419 (Last_Source_Dir).Next :=
5420 String_Element_Table.Last
5421 (In_Tree.String_Elements);
5424 -- And register this source directory as the new last
5426 Last_Source_Dir := String_Element_Table.Last
5427 (In_Tree.String_Elements);
5428 In_Tree.String_Elements.Table (Last_Source_Dir) :=
5431 elsif Removed and Found then
5432 if Prev = Nil_String then
5433 Project.Source_Dirs :=
5434 In_Tree.String_Elements.Table (List).Next;
5436 In_Tree.String_Elements.Table (Prev).Next :=
5437 In_Tree.String_Elements.Table (List).Next;
5441 -- Now look for subdirectories. We do that even when this
5442 -- directory is already in the list, because some of its
5443 -- subdirectories may not be in the list yet.
5445 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
5448 Read (Dir, Name, Last);
5451 if Name (1 .. Last) /= "."
5452 and then Name (1 .. Last) /= ".."
5454 -- Avoid . and .. directories
5456 if Current_Verbosity = High then
5457 Write_Str (" Checking ");
5458 Write_Line (Name (1 .. Last));
5462 Path_Name : constant String :=
5464 (Name => Name (1 .. Last),
5466 The_Path (The_Path'First .. The_Path_Last),
5467 Resolve_Links => Opt.Follow_Links_For_Dirs,
5468 Case_Sensitive => True);
5471 if Is_Directory (Path_Name) then
5472 -- We have found a new subdirectory, call self
5474 Name_Len := Path_Name'Length;
5475 Name_Buffer (1 .. Name_Len) := Path_Name;
5476 Recursive_Find_Dirs (Name_Find);
5485 when Directory_Error =>
5487 end Recursive_Find_Dirs;
5489 -- Start of processing for Find_Source_Dirs
5492 if Current_Verbosity = High and then not Removed then
5493 Write_Str ("Find_Source_Dirs (""");
5494 Write_Str (Directory);
5498 -- First, check if we are looking for a directory tree, indicated
5499 -- by "/**" at the end.
5501 if Directory'Length >= 3
5502 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5503 and then (Directory (Directory'Last - 2) = '/'
5505 Directory (Directory'Last - 2) = Directory_Separator)
5508 Project.Known_Order_Of_Source_Dirs := False;
5511 Name_Len := Directory'Length - 3;
5513 if Name_Len = 0 then
5515 -- Case of "/**": all directories in file system
5518 Name_Buffer (1) := Directory (Directory'First);
5521 Name_Buffer (1 .. Name_Len) :=
5522 Directory (Directory'First .. Directory'Last - 3);
5525 if Current_Verbosity = High then
5526 Write_Str ("Looking for all subdirectories of """);
5527 Write_Str (Name_Buffer (1 .. Name_Len));
5532 Base_Dir : constant File_Name_Type := Name_Find;
5533 Root_Dir : constant String :=
5535 (Name => Get_Name_String (Base_Dir),
5538 (Project.Directory.Display_Name),
5539 Resolve_Links => False,
5540 Case_Sensitive => True);
5543 if Root_Dir'Length = 0 then
5544 Err_Vars.Error_Msg_File_1 := Base_Dir;
5546 if Location = No_Location then
5549 "{ is not a valid directory.",
5554 "{ is not a valid directory.",
5559 -- We have an existing directory, we register it and all of
5560 -- its subdirectories.
5562 if Current_Verbosity = High then
5563 Write_Line ("Looking for source directories:");
5566 Name_Len := Root_Dir'Length;
5567 Name_Buffer (1 .. Name_Len) := Root_Dir;
5568 Recursive_Find_Dirs (Name_Find);
5570 if Current_Verbosity = High then
5571 Write_Line ("End of looking for source directories.");
5576 -- We have a single directory
5580 Path_Name : Path_Information;
5581 List : String_List_Id;
5582 Prev : String_List_Id;
5583 Dir_Exists : Boolean;
5587 (Project => Project,
5591 Dir_Exists => Dir_Exists,
5592 Must_Exist => False);
5594 if not Dir_Exists then
5595 Err_Vars.Error_Msg_File_1 := From;
5597 if Location = No_Location then
5600 "{ is not a valid directory",
5605 "{ is not a valid directory",
5611 Path : constant String :=
5612 Get_Name_String (Path_Name.Name) &
5613 Directory_Separator;
5614 Last_Path : constant Natural :=
5615 Compute_Directory_Last (Path);
5617 Display_Path : constant String :=
5619 (Path_Name.Display_Name) &
5620 Directory_Separator;
5621 Last_Display_Path : constant Natural :=
5622 Compute_Directory_Last
5624 Display_Path_Id : Name_Id;
5628 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5629 Path_Id := Name_Find;
5631 Add_Str_To_Name_Buffer
5633 (Display_Path'First .. Last_Display_Path));
5634 Display_Path_Id := Name_Find;
5638 -- As it is an existing directory, we add it to the
5639 -- list of directories.
5641 String_Element_Table.Increment_Last
5642 (In_Tree.String_Elements);
5646 Display_Value => Display_Path_Id,
5647 Location => No_Location,
5649 Next => Nil_String);
5651 if Last_Source_Dir = Nil_String then
5653 -- This is the first source directory
5655 Project.Source_Dirs := String_Element_Table.Last
5656 (In_Tree.String_Elements);
5659 -- We already have source directories, link the
5660 -- previous last to the new one.
5662 In_Tree.String_Elements.Table
5663 (Last_Source_Dir).Next :=
5664 String_Element_Table.Last
5665 (In_Tree.String_Elements);
5668 -- And register this source directory as the new last
5670 Last_Source_Dir := String_Element_Table.Last
5671 (In_Tree.String_Elements);
5672 In_Tree.String_Elements.Table
5673 (Last_Source_Dir) := Element;
5676 -- Remove source dir, if present
5680 -- Look for source dir in current list
5682 List := Project.Source_Dirs;
5683 while List /= Nil_String loop
5684 Element := In_Tree.String_Elements.Table (List);
5685 exit when Element.Value = Path_Id;
5687 List := Element.Next;
5690 if List /= Nil_String then
5691 -- Source dir was found, remove it from the list
5693 if Prev = Nil_String then
5694 Project.Source_Dirs :=
5695 In_Tree.String_Elements.Table (List).Next;
5698 In_Tree.String_Elements.Table (Prev).Next :=
5699 In_Tree.String_Elements.Table (List).Next;
5707 end Find_Source_Dirs;
5709 -- Start of processing for Get_Directories
5711 Dir_Exists : Boolean;
5714 if Current_Verbosity = High then
5715 Write_Line ("Starting to look for directories");
5718 -- Set the object directory to its default which may be nil, if there
5719 -- is no sources in the project.
5721 if (((not Source_Files.Default)
5722 and then Source_Files.Values = Nil_String)
5724 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5726 ((not Languages.Default) and then Languages.Values = Nil_String))
5727 and then Project.Extends = No_Project
5729 Project.Object_Directory := No_Path_Information;
5731 Project.Object_Directory := Project.Directory;
5734 -- Check the object directory
5736 if Object_Dir.Value /= Empty_String then
5737 Get_Name_String (Object_Dir.Value);
5739 if Name_Len = 0 then
5742 "Object_Dir cannot be empty",
5743 Object_Dir.Location);
5746 -- We check that the specified object directory does exist.
5747 -- However, even when it doesn't exist, we set it to a default
5748 -- value. This is for the benefit of tools that recover from
5749 -- errors; for example, these tools could create the non existent
5751 -- We always return an absolute directory name though
5756 File_Name_Type (Object_Dir.Value),
5757 Path => Project.Object_Directory,
5759 Dir_Exists => Dir_Exists,
5760 Location => Object_Dir.Location,
5761 Must_Exist => False,
5762 Externally_Built => Project.Externally_Built);
5765 and then not Project.Externally_Built
5767 -- The object directory does not exist, report an error if
5768 -- the project is not externally built.
5770 Err_Vars.Error_Msg_File_1 :=
5771 File_Name_Type (Object_Dir.Value);
5774 "object directory { not found",
5779 elsif Project.Object_Directory /= No_Path_Information
5780 and then Subdirs /= null
5783 Name_Buffer (1) := '.';
5788 Path => Project.Object_Directory,
5790 Dir_Exists => Dir_Exists,
5791 Location => Object_Dir.Location,
5792 Externally_Built => Project.Externally_Built);
5795 if Current_Verbosity = High then
5796 if Project.Object_Directory = No_Path_Information then
5797 Write_Line ("No object directory");
5800 ("Object directory",
5801 Get_Name_String (Project.Object_Directory.Display_Name));
5805 -- Check the exec directory
5807 -- We set the object directory to its default
5809 Project.Exec_Directory := Project.Object_Directory;
5811 if Exec_Dir.Value /= Empty_String then
5812 Get_Name_String (Exec_Dir.Value);
5814 if Name_Len = 0 then
5817 "Exec_Dir cannot be empty",
5821 -- We check that the specified exec directory does exist
5826 File_Name_Type (Exec_Dir.Value),
5827 Path => Project.Exec_Directory,
5828 Dir_Exists => Dir_Exists,
5830 Location => Exec_Dir.Location,
5831 Externally_Built => Project.Externally_Built);
5833 if not Dir_Exists then
5834 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5837 "exec directory { not found",
5843 if Current_Verbosity = High then
5844 if Project.Exec_Directory = No_Path_Information then
5845 Write_Line ("No exec directory");
5847 Write_Str ("Exec directory: """);
5848 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5853 -- Look for the source directories
5855 if Current_Verbosity = High then
5856 Write_Line ("Starting to look for source directories");
5859 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5861 if (not Source_Files.Default) and then
5862 Source_Files.Values = Nil_String
5864 Project.Source_Dirs := Nil_String;
5866 if Project.Qualifier = Standard then
5870 "a standard project cannot have no sources",
5871 Source_Files.Location);
5874 elsif Source_Dirs.Default then
5876 -- No Source_Dirs specified: the single source directory is the one
5877 -- containing the project file
5879 String_Element_Table.Append (In_Tree.String_Elements,
5880 (Value => Name_Id (Project.Directory.Name),
5881 Display_Value => Name_Id (Project.Directory.Display_Name),
5882 Location => No_Location,
5886 Project.Source_Dirs := String_Element_Table.Last
5887 (In_Tree.String_Elements);
5889 if Current_Verbosity = High then
5891 ("Default source directory",
5892 Get_Name_String (Project.Directory.Display_Name));
5895 elsif Source_Dirs.Values = Nil_String then
5896 if Project.Qualifier = Standard then
5900 "a standard project cannot have no source directories",
5901 Source_Dirs.Location);
5904 Project.Source_Dirs := Nil_String;
5908 Source_Dir : String_List_Id;
5909 Element : String_Element;
5912 -- Process the source directories for each element of the list
5914 Source_Dir := Source_Dirs.Values;
5915 while Source_Dir /= Nil_String loop
5916 Element := In_Tree.String_Elements.Table (Source_Dir);
5918 (File_Name_Type (Element.Value), Element.Location);
5919 Source_Dir := Element.Next;
5924 if not Excluded_Source_Dirs.Default
5925 and then Excluded_Source_Dirs.Values /= Nil_String
5928 Source_Dir : String_List_Id;
5929 Element : String_Element;
5932 -- Process the source directories for each element of the list
5934 Source_Dir := Excluded_Source_Dirs.Values;
5935 while Source_Dir /= Nil_String loop
5936 Element := In_Tree.String_Elements.Table (Source_Dir);
5938 (File_Name_Type (Element.Value),
5941 Source_Dir := Element.Next;
5946 if Current_Verbosity = High then
5947 Write_Line ("Putting source directories in canonical cases");
5951 Current : String_List_Id := Project.Source_Dirs;
5952 Element : String_Element;
5955 while Current /= Nil_String loop
5956 Element := In_Tree.String_Elements.Table (Current);
5957 if Element.Value /= No_Name then
5959 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5960 In_Tree.String_Elements.Table (Current) := Element;
5963 Current := Element.Next;
5966 end Get_Directories;
5973 (Project : Project_Id;
5974 In_Tree : Project_Tree_Ref)
5976 Mains : constant Variable_Value :=
5977 Prj.Util.Value_Of (Name_Main, Project.Decl.Attributes, In_Tree);
5978 List : String_List_Id;
5979 Elem : String_Element;
5982 Project.Mains := Mains.Values;
5984 -- If no Mains were specified, and if we are an extending project,
5985 -- inherit the Mains from the project we are extending.
5987 if Mains.Default then
5988 if not Project.Library and then Project.Extends /= No_Project then
5989 Project.Mains := Project.Extends.Mains;
5992 -- In a library project file, Main cannot be specified
5994 elsif Project.Library then
5997 "a library project file cannot have Main specified",
6001 List := Mains.Values;
6002 while List /= Nil_String loop
6003 Elem := In_Tree.String_Elements.Table (List);
6005 if Length_Of_Name (Elem.Value) = 0 then
6008 "?a main cannot have an empty name",
6018 ---------------------------
6019 -- Get_Sources_From_File --
6020 ---------------------------
6022 procedure Get_Sources_From_File
6024 Location : Source_Ptr;
6025 Project : Project_Id;
6026 In_Tree : Project_Tree_Ref)
6028 File : Prj.Util.Text_File;
6029 Line : String (1 .. 250);
6031 Source_Name : File_Name_Type;
6032 Name_Loc : Name_Location;
6035 if Get_Mode = Ada_Only then
6039 if Current_Verbosity = High then
6040 Write_Str ("Opening """);
6047 Prj.Util.Open (File, Path);
6049 if not Prj.Util.Is_Valid (File) then
6050 Error_Msg (Project, In_Tree, "file does not exist", Location);
6053 -- Read the lines one by one
6055 while not Prj.Util.End_Of_File (File) loop
6056 Prj.Util.Get_Line (File, Line, Last);
6058 -- A non empty, non comment line should contain a file name
6061 and then (Last = 1 or else Line (1 .. 2) /= "--")
6064 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6065 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6066 Source_Name := Name_Find;
6068 -- Check that there is no directory information
6070 for J in 1 .. Last loop
6071 if Line (J) = '/' or else Line (J) = Directory_Separator then
6072 Error_Msg_File_1 := Source_Name;
6076 "file name cannot include directory information ({)",
6082 Name_Loc := Source_Names.Get (Source_Name);
6084 if Name_Loc = No_Name_Location then
6086 (Name => Source_Name,
6087 Location => Location,
6088 Source => No_Source,
6093 Source_Names.Set (Source_Name, Name_Loc);
6097 Prj.Util.Close (File);
6100 end Get_Sources_From_File;
6102 -----------------------
6103 -- Compute_Unit_Name --
6104 -----------------------
6106 procedure Compute_Unit_Name
6107 (File_Name : File_Name_Type;
6108 Dot_Replacement : File_Name_Type;
6109 Separate_Suffix : File_Name_Type;
6110 Body_Suffix : File_Name_Type;
6111 Spec_Suffix : File_Name_Type;
6112 Casing : Casing_Type;
6113 Kind : out Source_Kind;
6115 In_Tree : Project_Tree_Ref)
6117 Filename : constant String := Get_Name_String (File_Name);
6118 Last : Integer := Filename'Last;
6119 Sep_Len : constant Integer :=
6120 Integer (Length_Of_Name (Separate_Suffix));
6121 Body_Len : constant Integer :=
6122 Integer (Length_Of_Name (Body_Suffix));
6123 Spec_Len : constant Integer :=
6124 Integer (Length_Of_Name (Spec_Suffix));
6126 Standard_GNAT : constant Boolean :=
6127 Spec_Suffix = Default_Ada_Spec_Suffix
6129 Body_Suffix = Default_Ada_Body_Suffix;
6131 Unit_Except : Unit_Exception;
6132 Masked : Boolean := False;
6137 if Dot_Replacement = No_File then
6138 if Current_Verbosity = High then
6139 Write_Line (" No dot_replacement specified");
6144 -- Choose the longest suffix that matches. If there are several matches,
6145 -- give priority to specs, then bodies, then separates.
6147 if Separate_Suffix /= Body_Suffix
6148 and then Suffix_Matches (Filename, Separate_Suffix)
6150 Last := Filename'Last - Sep_Len;
6154 if Filename'Last - Body_Len <= Last
6155 and then Suffix_Matches (Filename, Body_Suffix)
6157 Last := Natural'Min (Last, Filename'Last - Body_Len);
6161 if Filename'Last - Spec_Len <= Last
6162 and then Suffix_Matches (Filename, Spec_Suffix)
6164 Last := Natural'Min (Last, Filename'Last - Spec_Len);
6168 if Last = Filename'Last then
6169 if Current_Verbosity = High then
6170 Write_Line (" No matching suffix");
6175 -- Check that the casing matches
6177 if File_Names_Case_Sensitive then
6179 when All_Lower_Case =>
6180 for J in Filename'First .. Last loop
6181 if Is_Letter (Filename (J))
6182 and then not Is_Lower (Filename (J))
6184 if Current_Verbosity = High then
6185 Write_Line (" Invalid casing");
6191 when All_Upper_Case =>
6192 for J in Filename'First .. Last loop
6193 if Is_Letter (Filename (J))
6194 and then not Is_Upper (Filename (J))
6196 if Current_Verbosity = High then
6197 Write_Line (" Invalid casing");
6203 when Mixed_Case | Unknown =>
6208 -- If Dot_Replacement is not a single dot, then there should not
6209 -- be any dot in the name.
6212 Dot_Repl : constant String := Get_Name_String (Dot_Replacement);
6215 if Dot_Repl /= "." then
6216 for Index in Filename'First .. Last loop
6217 if Filename (Index) = '.' then
6218 if Current_Verbosity = High then
6219 Write_Line (" Invalid name, contains dot");
6225 Replace_Into_Name_Buffer
6226 (Filename (Filename'First .. Last), Dot_Repl, '.');
6228 Name_Len := Last - Filename'First + 1;
6229 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
6231 (Source => Name_Buffer (1 .. Name_Len),
6232 Mapping => Lower_Case_Map);
6236 -- In the standard GNAT naming scheme, check for special cases: children
6237 -- or separates of A, G, I or S, and run time sources.
6239 if Standard_GNAT and then Name_Len >= 3 then
6241 S1 : constant Character := Name_Buffer (1);
6242 S2 : constant Character := Name_Buffer (2);
6243 S3 : constant Character := Name_Buffer (3);
6251 -- Children or separates of packages A, G, I or S. These names
6252 -- are x__ ... or x~... (where x is a, g, i, or s). Both
6253 -- versions (x__... and x~...) are allowed in all platforms,
6254 -- because it is not possible to know the platform before
6255 -- processing of the project files.
6257 if S2 = '_' and then S3 = '_' then
6258 Name_Buffer (2) := '.';
6259 Name_Buffer (3 .. Name_Len - 1) :=
6260 Name_Buffer (4 .. Name_Len);
6261 Name_Len := Name_Len - 1;
6264 Name_Buffer (2) := '.';
6268 -- If it is potentially a run time source, disable filling
6269 -- of the mapping file to avoid warnings.
6271 Set_Mapping_File_Initial_State_To_Empty (In_Tree);
6277 -- Name_Buffer contains the name of the the unit in lower-cases. Check
6278 -- that this is a valid unit name
6280 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
6282 -- If there is a naming exception for the same unit, the file is not
6283 -- a source for the unit. Currently, this only applies in multi_lang
6284 -- mode, since Unit_Exceptions is no set in ada_only mode.
6286 if Unit /= No_Name then
6287 Unit_Except := Unit_Exceptions.Get (Unit);
6290 Masked := Unit_Except.Spec /= No_File
6292 Unit_Except.Spec /= File_Name;
6294 Masked := Unit_Except.Impl /= No_File
6296 Unit_Except.Impl /= File_Name;
6300 if Current_Verbosity = High then
6301 Write_Str (" """ & Filename & """ contains the ");
6304 Write_Str ("spec of a unit found in """);
6305 Write_Str (Get_Name_String (Unit_Except.Spec));
6307 Write_Str ("body of a unit found in """);
6308 Write_Str (Get_Name_String (Unit_Except.Impl));
6311 Write_Line (""" (ignored)");
6319 and then Current_Verbosity = High
6322 when Spec => Write_Str (" spec of ");
6323 when Impl => Write_Str (" body of ");
6324 when Sep => Write_Str (" sep of ");
6327 Write_Line (Get_Name_String (Unit));
6329 end Compute_Unit_Name;
6336 (In_Tree : Project_Tree_Ref;
6337 Canonical_File_Name : File_Name_Type;
6338 Naming : Naming_Data;
6339 Exception_Id : out Ada_Naming_Exception_Id;
6340 Unit_Name : out Name_Id;
6341 Unit_Kind : out Spec_Or_Body)
6343 Info_Id : Ada_Naming_Exception_Id :=
6344 Ada_Naming_Exceptions.Get (Canonical_File_Name);
6345 VMS_Name : File_Name_Type;
6349 if Info_Id = No_Ada_Naming_Exception
6350 and then Hostparm.OpenVMS
6352 VMS_Name := Canonical_File_Name;
6353 Get_Name_String (VMS_Name);
6355 if Name_Buffer (Name_Len) = '.' then
6356 Name_Len := Name_Len - 1;
6357 VMS_Name := Name_Find;
6360 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
6363 if Info_Id /= No_Ada_Naming_Exception then
6364 Exception_Id := Info_Id;
6365 Unit_Name := No_Name;
6369 Exception_Id := No_Ada_Naming_Exception;
6371 (File_Name => Canonical_File_Name,
6372 Dot_Replacement => Naming.Dot_Replacement,
6373 Separate_Suffix => Naming.Separate_Suffix,
6374 Body_Suffix => Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6375 Spec_Suffix => Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6376 Casing => Naming.Casing,
6379 In_Tree => In_Tree);
6382 when Spec => Unit_Kind := Spec;
6383 when Impl | Sep => Unit_Kind := Impl;
6392 function Hash (Unit : Unit_Info) return Header_Num is
6394 return Header_Num (Unit.Unit mod 2048);
6397 -----------------------
6398 -- Is_Illegal_Suffix --
6399 -----------------------
6401 function Is_Illegal_Suffix
6402 (Suffix : File_Name_Type;
6403 Dot_Replacement : File_Name_Type) return Boolean
6405 Suffix_Str : constant String := Get_Name_String (Suffix);
6408 if Suffix_Str'Length = 0 then
6410 elsif Index (Suffix_Str, ".") = 0 then
6414 -- Case of dot replacement is a single dot, and first character of
6415 -- suffix is also a dot.
6417 if Get_Name_String (Dot_Replacement) = "."
6418 and then Suffix_Str (Suffix_Str'First) = '.'
6420 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
6422 -- Case of following dot
6424 if Suffix_Str (Index) = '.' then
6426 -- It is illegal to have a letter following the initial dot
6428 return Is_Letter (Suffix_Str (Suffix_Str'First + 1));
6434 end Is_Illegal_Suffix;
6436 ----------------------
6437 -- Locate_Directory --
6438 ----------------------
6440 procedure Locate_Directory
6441 (Project : Project_Id;
6442 In_Tree : Project_Tree_Ref;
6443 Name : File_Name_Type;
6444 Path : out Path_Information;
6445 Dir_Exists : out Boolean;
6446 Create : String := "";
6447 Location : Source_Ptr := No_Location;
6448 Must_Exist : Boolean := True;
6449 Externally_Built : Boolean := False)
6451 Parent : constant Path_Name_Type :=
6452 Project.Directory.Display_Name;
6453 The_Parent : constant String :=
6454 Get_Name_String (Parent) & Directory_Separator;
6455 The_Parent_Last : constant Natural :=
6456 Compute_Directory_Last (The_Parent);
6457 Full_Name : File_Name_Type;
6458 The_Name : File_Name_Type;
6461 Get_Name_String (Name);
6463 -- Add Subdirs.all if it is a directory that may be created and
6464 -- Subdirs is not null;
6466 if Create /= "" and then Subdirs /= null then
6467 if Name_Buffer (Name_Len) /= Directory_Separator then
6468 Add_Char_To_Name_Buffer (Directory_Separator);
6471 Add_Str_To_Name_Buffer (Subdirs.all);
6474 -- Convert '/' to directory separator (for Windows)
6476 for J in 1 .. Name_Len loop
6477 if Name_Buffer (J) = '/' then
6478 Name_Buffer (J) := Directory_Separator;
6482 The_Name := Name_Find;
6484 if Current_Verbosity = High then
6485 Write_Str ("Locate_Directory (""");
6486 Write_Str (Get_Name_String (The_Name));
6487 Write_Str (""", """);
6488 Write_Str (The_Parent);
6492 Path := No_Path_Information;
6493 Dir_Exists := False;
6495 if Is_Absolute_Path (Get_Name_String (The_Name)) then
6496 Full_Name := The_Name;
6500 Add_Str_To_Name_Buffer
6501 (The_Parent (The_Parent'First .. The_Parent_Last));
6502 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
6503 Full_Name := Name_Find;
6507 Full_Path_Name : String_Access :=
6508 new String'(Get_Name_String (Full_Name));
6511 if (Setup_Projects or else Subdirs /= null)
6512 and then Create'Length > 0
6514 if not Is_Directory (Full_Path_Name.all) then
6516 -- If project is externally built, do not create a subdir,
6517 -- use the specified directory, without the subdir.
6519 if Externally_Built then
6520 if Is_Absolute_Path (Get_Name_String (Name)) then
6521 Get_Name_String (Name);
6525 Add_Str_To_Name_Buffer
6526 (The_Parent (The_Parent'First .. The_Parent_Last));
6527 Add_Str_To_Name_Buffer (Get_Name_String (Name));
6530 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
6534 Create_Path (Full_Path_Name.all);
6536 if not Quiet_Output then
6538 Write_Str (" directory """);
6539 Write_Str (Full_Path_Name.all);
6540 Write_Str (""" created for project ");
6541 Write_Line (Get_Name_String (Project.Name));
6548 "could not create " & Create &
6549 " directory " & Full_Path_Name.all,
6556 Dir_Exists := Is_Directory (Full_Path_Name.all);
6558 if not Must_Exist or else Dir_Exists then
6560 Normed : constant String :=
6562 (Full_Path_Name.all,
6564 The_Parent (The_Parent'First .. The_Parent_Last),
6565 Resolve_Links => False,
6566 Case_Sensitive => True);
6568 Canonical_Path : constant String :=
6573 (The_Parent'First .. The_Parent_Last),
6575 Opt.Follow_Links_For_Dirs,
6576 Case_Sensitive => False);
6579 Name_Len := Normed'Length;
6580 Name_Buffer (1 .. Name_Len) := Normed;
6581 Path.Display_Name := Name_Find;
6583 Name_Len := Canonical_Path'Length;
6584 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6585 Path.Name := Name_Find;
6589 Free (Full_Path_Name);
6591 end Locate_Directory;
6593 ---------------------------
6594 -- Find_Excluded_Sources --
6595 ---------------------------
6597 procedure Find_Excluded_Sources
6598 (Project : Project_Id;
6599 In_Tree : Project_Tree_Ref)
6601 Excluded_Source_List_File : constant Variable_Value :=
6603 (Name_Excluded_Source_List_File,
6604 Project.Decl.Attributes,
6607 Excluded_Sources : Variable_Value := Util.Value_Of
6608 (Name_Excluded_Source_Files,
6609 Project.Decl.Attributes,
6612 Current : String_List_Id;
6613 Element : String_Element;
6614 Location : Source_Ptr;
6615 Name : File_Name_Type;
6616 File : Prj.Util.Text_File;
6617 Line : String (1 .. 300);
6619 Locally_Removed : Boolean := False;
6622 -- If Excluded_Source_Files is not declared, check
6623 -- Locally_Removed_Files.
6625 if Excluded_Sources.Default then
6626 Locally_Removed := True;
6629 (Name_Locally_Removed_Files, Project.Decl.Attributes, In_Tree);
6632 Excluded_Sources_Htable.Reset;
6634 -- If there are excluded sources, put them in the table
6636 if not Excluded_Sources.Default then
6637 if not Excluded_Source_List_File.Default then
6638 if Locally_Removed then
6641 "?both attributes Locally_Removed_Files and " &
6642 "Excluded_Source_List_File are present",
6643 Excluded_Source_List_File.Location);
6647 "?both attributes Excluded_Source_Files and " &
6648 "Excluded_Source_List_File are present",
6649 Excluded_Source_List_File.Location);
6653 Current := Excluded_Sources.Values;
6654 while Current /= Nil_String loop
6655 Element := In_Tree.String_Elements.Table (Current);
6656 Name := Canonical_Case_File_Name (Element.Value);
6658 -- If the element has no location, then use the location of
6659 -- Excluded_Sources to report possible errors.
6661 if Element.Location = No_Location then
6662 Location := Excluded_Sources.Location;
6664 Location := Element.Location;
6667 Excluded_Sources_Htable.Set (Name, (Name, False, Location));
6668 Current := Element.Next;
6671 elsif not Excluded_Source_List_File.Default then
6672 Location := Excluded_Source_List_File.Location;
6675 Source_File_Path_Name : constant String :=
6678 (Excluded_Source_List_File.Value),
6679 Project.Directory.Name);
6682 if Source_File_Path_Name'Length = 0 then
6683 Err_Vars.Error_Msg_File_1 :=
6684 File_Name_Type (Excluded_Source_List_File.Value);
6687 "file with excluded sources { does not exist",
6688 Excluded_Source_List_File.Location);
6693 Prj.Util.Open (File, Source_File_Path_Name);
6695 if not Prj.Util.Is_Valid (File) then
6697 (Project, In_Tree, "file does not exist", Location);
6699 -- Read the lines one by one
6701 while not Prj.Util.End_Of_File (File) loop
6702 Prj.Util.Get_Line (File, Line, Last);
6704 -- Non empty, non comment line should contain a file name
6707 and then (Last = 1 or else Line (1 .. 2) /= "--")
6710 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6711 Canonical_Case_File_Name
6712 (Name_Buffer (1 .. Name_Len));
6715 -- Check that there is no directory information
6717 for J in 1 .. Last loop
6719 or else Line (J) = Directory_Separator
6721 Error_Msg_File_1 := Name;
6725 "file name cannot include " &
6726 "directory information ({)",
6732 Excluded_Sources_Htable.Set
6733 (Name, (Name, False, Location));
6737 Prj.Util.Close (File);
6742 end Find_Excluded_Sources;
6748 procedure Find_Sources
6749 (Project : Project_Id;
6750 In_Tree : Project_Tree_Ref;
6751 Proc_Data : in out Processing_Data)
6753 Sources : constant Variable_Value :=
6756 Project.Decl.Attributes,
6758 Source_List_File : constant Variable_Value :=
6760 (Name_Source_List_File,
6761 Project.Decl.Attributes,
6763 Name_Loc : Name_Location;
6765 Has_Explicit_Sources : Boolean;
6768 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6770 (Source_List_File.Kind = Single,
6771 "Source_List_File is not a single string");
6773 -- If the user has specified a Source_Files attribute
6775 if not Sources.Default then
6776 if not Source_List_File.Default then
6779 "?both attributes source_files and " &
6780 "source_list_file are present",
6781 Source_List_File.Location);
6784 -- Sources is a list of file names
6787 Current : String_List_Id := Sources.Values;
6788 Element : String_Element;
6789 Location : Source_Ptr;
6790 Name : File_Name_Type;
6793 if Get_Mode = Multi_Language then
6794 if Current = Nil_String then
6795 Project.Languages := No_Language_Index;
6797 -- This project contains no source. For projects that don't
6798 -- extend other projects, this also means that there is no
6799 -- need for an object directory, if not specified.
6801 if Project.Extends = No_Project
6802 and then Project.Object_Directory = Project.Directory
6804 Project.Object_Directory := No_Path_Information;
6809 while Current /= Nil_String loop
6810 Element := In_Tree.String_Elements.Table (Current);
6811 Name := Canonical_Case_File_Name (Element.Value);
6812 Get_Name_String (Element.Value);
6814 -- If the element has no location, then use the location of
6815 -- Sources to report possible errors.
6817 if Element.Location = No_Location then
6818 Location := Sources.Location;
6820 Location := Element.Location;
6823 -- Check that there is no directory information
6825 for J in 1 .. Name_Len loop
6826 if Name_Buffer (J) = '/'
6827 or else Name_Buffer (J) = Directory_Separator
6829 Error_Msg_File_1 := Name;
6833 "file name cannot include directory " &
6840 -- In Multi_Language mode, check whether the file is already
6841 -- there: the same file name may be in the list. If the source
6842 -- is missing, the error will be on the first mention of the
6843 -- source file name.
6847 Name_Loc := No_Name_Location;
6848 when Multi_Language =>
6849 Name_Loc := Source_Names.Get (Name);
6852 if Name_Loc = No_Name_Location then
6855 Location => Location,
6856 Source => No_Source,
6859 Source_Names.Set (Name, Name_Loc);
6862 Current := Element.Next;
6865 Has_Explicit_Sources := True;
6868 -- If we have no Source_Files attribute, check the Source_List_File
6871 elsif not Source_List_File.Default then
6873 -- Source_List_File is the name of the file that contains the source
6877 Source_File_Path_Name : constant String :=
6879 (File_Name_Type (Source_List_File.Value),
6880 Project.Directory.Name);
6883 Has_Explicit_Sources := True;
6885 if Source_File_Path_Name'Length = 0 then
6886 Err_Vars.Error_Msg_File_1 :=
6887 File_Name_Type (Source_List_File.Value);
6890 "file with sources { does not exist",
6891 Source_List_File.Location);
6894 Get_Sources_From_File
6895 (Source_File_Path_Name, Source_List_File.Location,
6901 -- Neither Source_Files nor Source_List_File has been specified. Find
6902 -- all the files that satisfy the naming scheme in all the source
6905 Has_Explicit_Sources := False;
6908 if Get_Mode = Ada_Only then
6910 (Project, In_Tree, Explicit_Sources_Only => Has_Explicit_Sources,
6911 Proc_Data => Proc_Data);
6917 Sources.Default and then Source_List_File.Default);
6920 -- Check if all exceptions have been found. For Ada, it is an error if
6921 -- an exception is not found. For other language, the source is simply
6926 Iter : Source_Iterator;
6929 Iter := For_Each_Source (In_Tree, Project);
6931 Source := Prj.Element (Iter);
6932 exit when Source = No_Source;
6934 if Source.Naming_Exception
6935 and then Source.Path = No_Path_Information
6937 if Source.Unit /= No_Unit_Index then
6938 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6939 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6942 "source file %% for unit %% not found",
6946 Remove_Source (Source, No_Source);
6953 -- It is an error if a source file name in a source list or in a source
6954 -- list file is not found.
6956 if Has_Explicit_Sources then
6959 First_Error : Boolean;
6962 NL := Source_Names.Get_First;
6963 First_Error := True;
6964 while NL /= No_Name_Location loop
6965 if not NL.Found then
6966 Err_Vars.Error_Msg_File_1 := NL.Name;
6971 "source file { not found",
6973 First_Error := False;
6978 "\source file { not found",
6983 NL := Source_Names.Get_Next;
6988 if Get_Mode = Ada_Only
6989 and then Project.Extends = No_Project
6991 -- We should have found at least one source, if not report an error
6993 if not Has_Ada_Sources (Project) then
6995 (Project, "Ada", In_Tree, Source_List_File.Location);
7004 procedure Initialize (Proc_Data : in out Processing_Data) is
7006 Files_Htable.Reset (Proc_Data.Units);
7013 procedure Free (Proc_Data : in out Processing_Data) is
7015 Files_Htable.Reset (Proc_Data.Units);
7018 ----------------------
7019 -- Find_Ada_Sources --
7020 ----------------------
7022 procedure Find_Ada_Sources
7023 (Project : Project_Id;
7024 In_Tree : Project_Tree_Ref;
7025 Explicit_Sources_Only : Boolean;
7026 Proc_Data : in out Processing_Data)
7028 Source_Dir : String_List_Id;
7029 Element : String_Element;
7031 Dir_Has_Source : Boolean := False;
7033 Ada_Language : Language_Ptr;
7036 if Current_Verbosity = High then
7037 Write_Line ("Looking for Ada sources:");
7040 Ada_Language := Project.Languages;
7041 while Ada_Language /= No_Language_Index
7042 and then Ada_Language.Name /= Name_Ada
7044 Ada_Language := Ada_Language.Next;
7047 -- We look in all source directories for the file names in the hash
7048 -- table Source_Names.
7050 Source_Dir := Project.Source_Dirs;
7051 while Source_Dir /= Nil_String loop
7052 Dir_Has_Source := False;
7053 Element := In_Tree.String_Elements.Table (Source_Dir);
7056 Dir_Path : constant String :=
7057 Get_Name_String (Element.Display_Value) &
7058 Directory_Separator;
7059 Dir_Last : constant Natural := Compute_Directory_Last (Dir_Path);
7062 if Current_Verbosity = High then
7063 Write_Line ("checking directory """ & Dir_Path & """");
7066 -- Look for all files in the current source directory
7068 Open (Dir, Dir_Path (Dir_Path'First .. Dir_Last));
7071 Read (Dir, Name_Buffer, Name_Len);
7072 exit when Name_Len = 0;
7074 if Current_Verbosity = High then
7075 Write_Line (" Checking " & Name_Buffer (1 .. Name_Len));
7079 Name : constant File_Name_Type := Name_Find;
7080 Canonical_Name : File_Name_Type;
7082 -- ??? We could probably optimize the following call: we
7083 -- need to resolve links only once for the directory itself,
7084 -- and then do a single call to readlink() for each file.
7085 -- Unfortunately that would require a change in
7086 -- Normalize_Pathname so that it has the option of not
7087 -- resolving links for its Directory parameter, only for
7090 Path : constant String :=
7092 (Name => Name_Buffer (1 .. Name_Len),
7093 Directory => Dir_Path (Dir_Path'First .. Dir_Last),
7094 Resolve_Links => Opt.Follow_Links_For_Files,
7095 Case_Sensitive => True); -- no case folding
7097 Path_Name : Path_Name_Type;
7098 To_Record : Boolean := False;
7099 Location : Source_Ptr;
7102 -- If the file was listed in the explicit list of sources,
7103 -- mark it as such (since we'll need to report an error when
7104 -- an explicit source was not found)
7106 if Explicit_Sources_Only then
7108 Canonical_Case_File_Name (Name_Id (Name));
7109 NL := Source_Names.Get (Canonical_Name);
7110 To_Record := NL /= No_Name_Location and then not NL.Found;
7114 Location := NL.Location;
7115 Source_Names.Set (Canonical_Name, NL);
7120 Location := No_Location;
7124 Name_Len := Path'Length;
7125 Name_Buffer (1 .. Name_Len) := Path;
7126 Path_Name := Name_Find;
7128 if Current_Verbosity = High then
7129 Write_Line (" recording " & Get_Name_String (Name));
7132 -- Register the source if it is an Ada compilation unit
7136 Path_Name => Path_Name,
7139 Proc_Data => Proc_Data,
7140 Ada_Language => Ada_Language,
7141 Location => Location,
7142 Source_Recorded => Dir_Has_Source);
7155 if Dir_Has_Source then
7156 In_Tree.String_Elements.Table (Source_Dir).Flag := True;
7159 Source_Dir := Element.Next;
7162 if Current_Verbosity = High then
7163 Write_Line ("End looking for sources");
7165 end Find_Ada_Sources;
7167 -------------------------------
7168 -- Check_File_Naming_Schemes --
7169 -------------------------------
7171 procedure Check_File_Naming_Schemes
7172 (In_Tree : Project_Tree_Ref;
7173 Project : Project_Id;
7174 File_Name : File_Name_Type;
7175 Alternate_Languages : out Language_List;
7176 Language : out Language_Ptr;
7177 Display_Language_Name : out Name_Id;
7179 Lang_Kind : out Language_Kind;
7180 Kind : out Source_Kind)
7182 Filename : constant String := Get_Name_String (File_Name);
7183 Config : Language_Config;
7184 Tmp_Lang : Language_Ptr;
7186 Header_File : Boolean := False;
7187 -- True if we found at least one language for which the file is a header
7188 -- In such a case, we search for all possible languages where this is
7189 -- also a header (C and C++ for instance), since the file might be used
7190 -- for several such languages.
7192 procedure Check_File_Based_Lang;
7193 -- Does the naming scheme test for file-based languages. For those,
7194 -- there is no Unit. Just check if the file name has the implementation
7195 -- or, if it is specified, the template suffix of the language.
7197 -- Returns True if the file belongs to the current language and we
7198 -- should stop searching for matching languages. Not that a given header
7199 -- file could belong to several languages (C and C++ for instance). Thus
7200 -- if we found a header we'll check whether it matches other languages.
7202 ---------------------------
7203 -- Check_File_Based_Lang --
7204 ---------------------------
7206 procedure Check_File_Based_Lang is
7209 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
7213 Language := Tmp_Lang;
7215 if Current_Verbosity = High then
7216 Write_Str (" implementation of language ");
7217 Write_Line (Get_Name_String (Display_Language_Name));
7220 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
7221 if Current_Verbosity = High then
7222 Write_Str (" header of language ");
7223 Write_Line (Get_Name_String (Display_Language_Name));
7227 Alternate_Languages := new Language_List_Element'
7228 (Language => Language,
7229 Next => Alternate_Languages);
7232 Header_File := True;
7235 Language := Tmp_Lang;
7238 end Check_File_Based_Lang;
7240 -- Start of processing for Check_File_Naming_Schemes
7243 Language := No_Language_Index;
7244 Alternate_Languages := null;
7245 Display_Language_Name := No_Name;
7247 Lang_Kind := File_Based;
7250 Tmp_Lang := Project.Languages;
7251 while Tmp_Lang /= No_Language_Index loop
7252 if Current_Verbosity = High then
7254 (" Testing language "
7255 & Get_Name_String (Tmp_Lang.Name)
7256 & " Header_File=" & Header_File'Img);
7259 Display_Language_Name := Tmp_Lang.Display_Name;
7260 Config := Tmp_Lang.Config;
7261 Lang_Kind := Config.Kind;
7265 Check_File_Based_Lang;
7266 exit when Kind = Impl;
7270 -- We know it belongs to a least a file_based language, no
7271 -- need to check unit-based ones.
7273 if not Header_File then
7275 (File_Name => File_Name,
7276 Dot_Replacement => Config.Naming_Data.Dot_Replacement,
7277 Separate_Suffix => Config.Naming_Data.Separate_Suffix,
7278 Body_Suffix => Config.Naming_Data.Body_Suffix,
7279 Spec_Suffix => Config.Naming_Data.Spec_Suffix,
7280 Casing => Config.Naming_Data.Casing,
7283 In_Tree => In_Tree);
7285 if Unit /= No_Name then
7286 Language := Tmp_Lang;
7292 Tmp_Lang := Tmp_Lang.Next;
7295 if Language = No_Language_Index
7296 and then Current_Verbosity = High
7298 Write_Line (" not a source of any language");
7300 end Check_File_Naming_Schemes;
7306 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
7308 -- Remove reference in the unit, if necessary
7310 if Source.Unit /= null
7311 and then Source.Kind in Spec_Or_Body
7313 Source.Unit.File_Names (Source.Kind) := null;
7316 Source.Kind := Kind;
7318 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
7319 Source.Unit.File_Names (Source.Kind) := Source;
7327 procedure Check_File
7328 (Project : Project_Id;
7329 In_Tree : Project_Tree_Ref;
7330 Path : Path_Name_Type;
7331 File_Name : File_Name_Type;
7332 Display_File_Name : File_Name_Type;
7333 For_All_Sources : Boolean)
7335 Canonical_Path : constant Path_Name_Type :=
7337 (Canonical_Case_File_Name (Name_Id (Path)));
7339 Name_Loc : Name_Location := Source_Names.Get (File_Name);
7340 Check_Name : Boolean := False;
7341 Alternate_Languages : Language_List;
7342 Language : Language_Ptr;
7344 Other_Part : Source_Id;
7346 Src_Ind : Source_File_Index;
7348 Source_To_Replace : Source_Id := No_Source;
7349 Display_Language_Name : Name_Id;
7350 Lang_Kind : Language_Kind;
7351 Kind : Source_Kind := Spec;
7352 Iter : Source_Iterator;
7355 if Name_Loc = No_Name_Location then
7356 Check_Name := For_All_Sources;
7359 if Name_Loc.Found then
7361 -- Check if it is OK to have the same file name in several
7362 -- source directories.
7364 if not Project.Known_Order_Of_Source_Dirs then
7365 Error_Msg_File_1 := File_Name;
7368 "{ is found in several source directories",
7373 Name_Loc.Found := True;
7375 Source_Names.Set (File_Name, Name_Loc);
7377 if Name_Loc.Source = No_Source then
7381 Name_Loc.Source.Path := (Canonical_Path, Path);
7383 Source_Paths_Htable.Set
7384 (In_Tree.Source_Paths_HT,
7388 -- Check if this is a subunit
7390 if Name_Loc.Source.Unit /= No_Unit_Index
7391 and then Name_Loc.Source.Kind = Impl
7393 Src_Ind := Sinput.P.Load_Project_File
7394 (Get_Name_String (Canonical_Path));
7396 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7397 Override_Kind (Name_Loc.Source, Sep);
7405 Other_Part := No_Source;
7407 Check_File_Naming_Schemes
7408 (In_Tree => In_Tree,
7410 File_Name => File_Name,
7411 Alternate_Languages => Alternate_Languages,
7412 Language => Language,
7413 Display_Language_Name => Display_Language_Name,
7415 Lang_Kind => Lang_Kind,
7418 if Language = No_Language_Index then
7420 -- A file name in a list must be a source of a language
7422 if Name_Loc.Found then
7423 Error_Msg_File_1 := File_Name;
7427 "language unknown for {",
7432 -- Check if the same file name or unit is used in the prj tree
7434 Iter := For_Each_Source (In_Tree);
7437 Source := Prj.Element (Iter);
7438 exit when Source = No_Source;
7441 and then Source.Unit /= No_Unit_Index
7442 and then Source.Unit.Name = Unit
7444 ((Source.Kind = Spec and then Kind = Impl)
7446 (Source.Kind = Impl and then Kind = Spec))
7448 Other_Part := Source;
7450 elsif (Unit /= No_Name
7451 and then Source.Unit /= No_Unit_Index
7452 and then Source.Unit.Name = Unit
7456 (Source.Kind = Sep and then Kind = Impl)
7458 (Source.Kind = Impl and then Kind = Sep)))
7460 (Unit = No_Name and then Source.File = File_Name)
7462 -- Duplication of file/unit in same project is only
7463 -- allowed if order of source directories is known.
7465 if Project = Source.Project then
7466 if Project.Known_Order_Of_Source_Dirs then
7469 elsif Unit /= No_Name then
7470 Error_Msg_Name_1 := Unit;
7472 (Project, In_Tree, "duplicate unit %%",
7477 Error_Msg_File_1 := File_Name;
7479 (Project, In_Tree, "duplicate source file name {",
7484 -- Do not allow the same unit name in different projects,
7485 -- except if one is extending the other.
7487 -- For a file based language, the same file name replaces
7488 -- a file in a project being extended, but it is allowed
7489 -- to have the same file name in unrelated projects.
7491 elsif Is_Extending (Project, Source.Project) then
7492 Source_To_Replace := Source;
7494 elsif Unit /= No_Name
7495 and then not Source.Locally_Removed
7497 Error_Msg_Name_1 := Unit;
7500 "unit %% cannot belong to several projects",
7503 Error_Msg_Name_1 := Project.Name;
7504 Error_Msg_Name_2 := Name_Id (Path);
7506 (Project, In_Tree, "\ project %%, %%", No_Location);
7508 Error_Msg_Name_1 := Source.Project.Name;
7509 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
7511 (Project, In_Tree, "\ project %%, %%", No_Location);
7525 Lang_Id => Language,
7527 Alternate_Languages => Alternate_Languages,
7528 File_Name => File_Name,
7529 Display_File => Display_File_Name,
7530 Other_Part => Other_Part,
7532 Path => (Canonical_Path, Path),
7533 Source_To_Replace => Source_To_Replace);
7539 ------------------------
7540 -- Search_Directories --
7541 ------------------------
7543 procedure Search_Directories
7544 (Project : Project_Id;
7545 In_Tree : Project_Tree_Ref;
7546 For_All_Sources : Boolean)
7548 Source_Dir : String_List_Id;
7549 Element : String_Element;
7551 Name : String (1 .. 1_000);
7553 File_Name : File_Name_Type;
7554 Display_File_Name : File_Name_Type;
7557 if Current_Verbosity = High then
7558 Write_Line ("Looking for sources:");
7561 -- Loop through subdirectories
7563 Source_Dir := Project.Source_Dirs;
7564 while Source_Dir /= Nil_String loop
7566 Element := In_Tree.String_Elements.Table (Source_Dir);
7567 if Element.Value /= No_Name then
7568 Get_Name_String (Element.Display_Value);
7571 Source_Directory : constant String :=
7572 Name_Buffer (1 .. Name_Len) &
7573 Directory_Separator;
7575 Dir_Last : constant Natural :=
7576 Compute_Directory_Last
7580 if Current_Verbosity = High then
7581 Write_Attr ("Source_Dir", Source_Directory);
7584 -- We look to every entry in the source directory
7586 Open (Dir, Source_Directory);
7589 Read (Dir, Name, Last);
7593 -- ??? Duplicate system call here, we just did a
7594 -- a similar one. Maybe Ada.Directories would be more
7598 (Source_Directory & Name (1 .. Last))
7600 if Current_Verbosity = High then
7601 Write_Str (" Checking ");
7602 Write_Line (Name (1 .. Last));
7606 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7607 Display_File_Name := Name_Find;
7609 if Osint.File_Names_Case_Sensitive then
7610 File_Name := Display_File_Name;
7612 Canonical_Case_File_Name
7613 (Name_Buffer (1 .. Name_Len));
7614 File_Name := Name_Find;
7618 Path_Name : constant String :=
7621 Directory => Source_Directory
7622 (Source_Directory'First .. Dir_Last),
7623 Resolve_Links => Opt.Follow_Links_For_Files,
7624 Case_Sensitive => True); -- no folding
7626 Path : Path_Name_Type;
7628 Excluded_Sources_Htable.Get (File_Name);
7631 Name_Len := Path_Name'Length;
7632 Name_Buffer (1 .. Name_Len) := Path_Name;
7635 if FF /= No_File_Found then
7636 if not FF.Found then
7638 Excluded_Sources_Htable.Set (File_Name, FF);
7640 if Current_Verbosity = High then
7641 Write_Str (" excluded source """);
7642 Write_Str (Get_Name_String (File_Name));
7649 (Project => Project,
7652 File_Name => File_Name,
7653 Display_File_Name => Display_File_Name,
7654 For_All_Sources => For_All_Sources);
7665 when Directory_Error =>
7669 Source_Dir := Element.Next;
7672 if Current_Verbosity = High then
7673 Write_Line ("end Looking for sources.");
7675 end Search_Directories;
7677 ----------------------------
7678 -- Load_Naming_Exceptions --
7679 ----------------------------
7681 procedure Load_Naming_Exceptions
7682 (Project : Project_Id;
7683 In_Tree : Project_Tree_Ref)
7686 Iter : Source_Iterator;
7689 Unit_Exceptions.Reset;
7691 Iter := For_Each_Source (In_Tree, Project);
7693 Source := Prj.Element (Iter);
7694 exit when Source = No_Source;
7696 -- An excluded file cannot also be an exception file name
7698 if Excluded_Sources_Htable.Get (Source.File) /= No_File_Found then
7699 Error_Msg_File_1 := Source.File;
7702 "{ cannot be both excluded and an exception file name",
7706 if Current_Verbosity = High then
7707 Write_Str ("Naming exception: Putting source file ");
7708 Write_Str (Get_Name_String (Source.File));
7709 Write_Line (" in Source_Names");
7715 (Name => Source.File,
7716 Location => No_Location,
7718 Except => Source.Unit /= No_Unit_Index,
7721 -- If this is an Ada exception, record in table Unit_Exceptions
7723 if Source.Unit /= No_Unit_Index then
7725 Unit_Except : Unit_Exception :=
7726 Unit_Exceptions.Get (Source.Unit.Name);
7729 Unit_Except.Name := Source.Unit.Name;
7731 if Source.Kind = Spec then
7732 Unit_Except.Spec := Source.File;
7734 Unit_Except.Impl := Source.File;
7737 Unit_Exceptions.Set (Source.Unit.Name, Unit_Except);
7743 end Load_Naming_Exceptions;
7745 ----------------------
7746 -- Look_For_Sources --
7747 ----------------------
7749 procedure Look_For_Sources
7750 (Project : Project_Id;
7751 In_Tree : Project_Tree_Ref;
7752 Proc_Data : in out Processing_Data)
7754 Iter : Source_Iterator;
7756 procedure Process_Sources_In_Multi_Language_Mode;
7757 -- Find all source files when in multi language mode
7759 procedure Mark_Excluded_Sources;
7760 -- Mark as such the sources that are declared as excluded
7762 ---------------------------
7763 -- Mark_Excluded_Sources --
7764 ---------------------------
7766 procedure Mark_Excluded_Sources is
7767 Source : Source_Id := No_Source;
7769 Excluded : File_Found;
7773 Excluded := Excluded_Sources_Htable.Get_First;
7774 while Excluded /= No_File_Found loop
7777 -- ??? Don't we have a hash table to map files to Source_Id?
7779 Iter := For_Each_Source (In_Tree);
7781 Source := Prj.Element (Iter);
7782 exit when Source = No_Source;
7784 if Source.File = Excluded.File then
7785 if Source.Project = Project
7786 or else Is_Extending (Project, Source.Project)
7790 if Source.Unit /= No_Unit_Index then
7793 (In_Tree.Units_HT, Source.Unit.Name);
7794 if Index.File_Names (Source.Kind) /= null then
7795 Index.File_Names (Source.Kind).Path.Name := Slash;
7796 Index.File_Names (Source.Kind).Naming_Exception :=
7799 -- ??? Should we simply set (can be done from the
7801 -- Index.File_Names (Source.Kind) := null;
7806 if Source /= No_Source then
7807 Source.Locally_Removed := True;
7808 Source.In_Interfaces := False;
7811 if Current_Verbosity = High then
7812 Write_Str ("Removing file ");
7813 Write_Line (Get_Name_String (Excluded.File));
7816 Add_Forbidden_File_Name (Excluded.File);
7821 "cannot remove a source from another project",
7831 OK := OK or Excluded.Found;
7834 Err_Vars.Error_Msg_File_1 := Excluded.File;
7836 (Project, In_Tree, "unknown file {", Excluded.Location);
7839 Excluded := Excluded_Sources_Htable.Get_Next;
7841 end Mark_Excluded_Sources;
7843 --------------------------------------------
7844 -- Process_Sources_In_Multi_Language_Mode --
7845 --------------------------------------------
7847 procedure Process_Sources_In_Multi_Language_Mode is
7848 Iter : Source_Iterator;
7850 -- Check that two sources of this project do not have the same object
7853 Check_Object_File_Names : declare
7855 Source_Name : File_Name_Type;
7857 procedure Check_Object (Src : Source_Id);
7858 -- Check if object file name of the current source is already in
7859 -- hash table Object_File_Names. If it is, report an error. If it
7860 -- is not, put it there with the file name of the current source.
7866 procedure Check_Object (Src : Source_Id) is
7868 Source_Name := Object_File_Names.Get (Src.Object);
7870 if Source_Name /= No_File then
7871 Error_Msg_File_1 := Src.File;
7872 Error_Msg_File_2 := Source_Name;
7876 "{ and { have the same object file name",
7880 Object_File_Names.Set (Src.Object, Src.File);
7884 -- Start of processing for Check_Object_File_Names
7887 Object_File_Names.Reset;
7888 Iter := For_Each_Source (In_Tree);
7890 Src_Id := Prj.Element (Iter);
7891 exit when Src_Id = No_Source;
7893 if Is_Compilable (Src_Id)
7894 and then Src_Id.Language.Config.Object_Generated
7895 and then Is_Extending (Project, Src_Id.Project)
7897 if Src_Id.Unit = No_Unit_Index then
7898 if Src_Id.Kind = Impl then
7899 Check_Object (Src_Id);
7905 if Src_Id.Other_Part = No_Source then
7906 Check_Object (Src_Id);
7913 if Src_Id.Other_Part /= No_Source then
7914 Check_Object (Src_Id);
7917 -- Check if it is a subunit
7920 Src_Ind : constant Source_File_Index :=
7921 Sinput.P.Load_Project_File
7923 (Src_Id.Path.Name));
7925 if Sinput.P.Source_File_Is_Subunit
7928 Override_Kind (Src_Id, Sep);
7930 Check_Object (Src_Id);
7940 end Check_Object_File_Names;
7941 end Process_Sources_In_Multi_Language_Mode;
7943 -- Start of processing for Look_For_Sources
7947 Find_Excluded_Sources (Project, In_Tree);
7949 if (Get_Mode = Ada_Only and then Is_A_Language (Project, Name_Ada))
7950 or else (Get_Mode = Multi_Language
7951 and then Project.Languages /= No_Language_Index)
7953 if Get_Mode = Multi_Language then
7954 Load_Naming_Exceptions (Project, In_Tree);
7957 Find_Sources (Project, In_Tree, Proc_Data);
7958 Mark_Excluded_Sources;
7960 if Get_Mode = Multi_Language then
7961 Process_Sources_In_Multi_Language_Mode;
7964 end Look_For_Sources;
7970 function Path_Name_Of
7971 (File_Name : File_Name_Type;
7972 Directory : Path_Name_Type) return String
7974 Result : String_Access;
7975 The_Directory : constant String := Get_Name_String (Directory);
7978 Get_Name_String (File_Name);
7981 (File_Name => Name_Buffer (1 .. Name_Len),
7982 Path => The_Directory);
7984 if Result = null then
7988 R : String := Result.all;
7991 Canonical_Case_File_Name (R);
7997 -----------------------------------
7998 -- Prepare_Ada_Naming_Exceptions --
7999 -----------------------------------
8001 procedure Prepare_Ada_Naming_Exceptions
8002 (List : Array_Element_Id;
8003 In_Tree : Project_Tree_Ref;
8004 Kind : Spec_Or_Body)
8006 Current : Array_Element_Id;
8007 Element : Array_Element;
8011 -- Traverse the list
8014 while Current /= No_Array_Element loop
8015 Element := In_Tree.Array_Elements.Table (Current);
8017 if Element.Index /= No_Name then
8020 Unit => Element.Index,
8021 Next => No_Ada_Naming_Exception);
8022 Reverse_Ada_Naming_Exceptions.Set
8023 (Unit, (Element.Value.Value, Element.Value.Index));
8025 Ada_Naming_Exceptions.Get (File_Name_Type (Element.Value.Value));
8026 Ada_Naming_Exception_Table.Increment_Last;
8027 Ada_Naming_Exception_Table.Table
8028 (Ada_Naming_Exception_Table.Last) := Unit;
8029 Ada_Naming_Exceptions.Set
8030 (File_Name_Type (Element.Value.Value),
8031 Ada_Naming_Exception_Table.Last);
8034 Current := Element.Next;
8036 end Prepare_Ada_Naming_Exceptions;
8038 -----------------------
8039 -- Record_Ada_Source --
8040 -----------------------
8042 procedure Record_Ada_Source
8043 (File_Name : File_Name_Type;
8044 Path_Name : Path_Name_Type;
8045 Project : Project_Id;
8046 In_Tree : Project_Tree_Ref;
8047 Proc_Data : in out Processing_Data;
8048 Ada_Language : Language_Ptr;
8049 Location : Source_Ptr;
8050 Source_Recorded : in out Boolean)
8052 Canonical_File : File_Name_Type;
8053 Canonical_Path : Path_Name_Type;
8055 File_Recorded : Boolean := False;
8056 -- True when at least one file has been recorded
8058 procedure Record_Unit
8059 (Unit_Name : Name_Id;
8060 Unit_Ind : Int := 0;
8061 Unit_Kind : Spec_Or_Body;
8062 Needs_Pragma : Boolean);
8063 -- Register of the units contained in the source file (there is in
8064 -- general a single such unit except when exceptions to the naming
8065 -- scheme indicate there are several such units)
8071 procedure Record_Unit
8072 (Unit_Name : Name_Id;
8073 Unit_Ind : Int := 0;
8074 Unit_Kind : Spec_Or_Body;
8075 Needs_Pragma : Boolean)
8077 UData : constant Unit_Index :=
8078 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
8079 -- ??? Add_Source will look it up again, can we do that only once ?
8082 To_Record : Boolean := False;
8083 The_Location : Source_Ptr := Location;
8084 Unit_Prj : Project_Id;
8087 if Current_Verbosity = High then
8088 Write_Str (" Putting ");
8089 Write_Str (Get_Name_String (Unit_Name));
8090 Write_Line (" in the unit list.");
8093 -- The unit is already in the list, but may be it is only the other
8094 -- unit kind (spec or body), or what is in the unit list is a unit of
8095 -- a project we are extending.
8097 if UData /= No_Unit_Index then
8098 if UData.File_Names (Unit_Kind) = null
8100 (UData.File_Names (Unit_Kind).File = Canonical_File
8101 and then UData.File_Names (Unit_Kind).Path.Name = Slash)
8102 or else Is_Extending
8103 (Project.Extends, UData.File_Names (Unit_Kind).Project)
8105 if UData.File_Names (Unit_Kind) /= null
8106 and then UData.File_Names (Unit_Kind).Path.Name = Slash
8108 Remove_Forbidden_File_Name
8109 (UData.File_Names (Unit_Kind).File);
8114 -- If the same file is already in the list, do not add it again
8116 elsif UData.File_Names (Unit_Kind).Project = Project
8118 (Project.Known_Order_Of_Source_Dirs
8120 UData.File_Names (Unit_Kind).Path.Name = Canonical_Path)
8124 -- Else, same unit but not same file => It is an error to have two
8125 -- units with the same name and the same kind (spec or body).
8128 if The_Location = No_Location then
8129 The_Location := Project.Location;
8132 Err_Vars.Error_Msg_Name_1 := Unit_Name;
8134 (Project, In_Tree, "duplicate unit %%", The_Location);
8136 Err_Vars.Error_Msg_Name_1 :=
8137 UData.File_Names (Unit_Kind).Project.Name;
8138 Err_Vars.Error_Msg_File_1 :=
8139 File_Name_Type (UData.File_Names (Unit_Kind).Path.Name);
8142 "\ project file %%, {", The_Location);
8144 Err_Vars.Error_Msg_Name_1 := Project.Name;
8145 Err_Vars.Error_Msg_File_1 := File_Name_Type (Canonical_Path);
8147 (Project, In_Tree, "\ project file %%, {", The_Location);
8152 -- It is a new unit, create a new record
8155 -- First, check if there is no other unit with this file name in
8156 -- another project. If it is, report error but note we do that
8157 -- only for the first unit in the source file.
8159 Unit_Prj := Files_Htable.Get (Proc_Data.Units, Canonical_File);
8161 if not File_Recorded
8162 and then Unit_Prj /= No_Project
8164 Error_Msg_File_1 := File_Name;
8165 Error_Msg_Name_1 := Unit_Prj.Name;
8168 "{ is already a source of project %%",
8177 Files_Htable.Set (Proc_Data.Units, Canonical_File, Project);
8182 Lang_Id => Ada_Language,
8183 File_Name => Canonical_File,
8184 Display_File => File_Name,
8186 Path => (Canonical_Path, Path_Name),
8187 Naming_Exception => Needs_Pragma,
8190 Other_Part => No_Source); -- ??? Can we find file ?
8191 Source_Recorded := True;
8195 Exception_Id : Ada_Naming_Exception_Id;
8196 Unit_Name : Name_Id;
8197 Unit_Kind : Spec_Or_Body;
8198 Unit_Ind : Int := 0;
8200 Name_Index : Name_And_Index;
8201 Except_Name : Name_And_Index := No_Name_And_Index;
8202 Needs_Pragma : Boolean;
8205 Canonical_File := Canonical_Case_File_Name (Name_Id (File_Name));
8207 Path_Name_Type (Canonical_Case_File_Name (Name_Id (Path_Name)));
8209 -- Check the naming scheme to get extra file properties
8212 (In_Tree => In_Tree,
8213 Canonical_File_Name => Canonical_File,
8214 Naming => Project.Naming,
8215 Exception_Id => Exception_Id,
8216 Unit_Name => Unit_Name,
8217 Unit_Kind => Unit_Kind);
8219 Needs_Pragma := Exception_Id /= No_Ada_Naming_Exception;
8221 if Exception_Id = No_Ada_Naming_Exception
8222 and then Unit_Name = No_Name
8224 if Current_Verbosity = High then
8226 Write_Str (Get_Name_String (Canonical_File));
8227 Write_Line (""" is not a valid source file name (ignored).");
8232 -- Check to see if the source has been hidden by an exception,
8233 -- but only if it is not an exception.
8235 if not Needs_Pragma then
8237 Reverse_Ada_Naming_Exceptions.Get
8238 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
8240 if Except_Name /= No_Name_And_Index then
8241 if Current_Verbosity = High then
8243 Write_Str (Get_Name_String (Canonical_File));
8244 Write_Str (""" contains a unit that is found in """);
8245 Write_Str (Get_Name_String (Except_Name.Name));
8246 Write_Line (""" (ignored).");
8249 -- The file is not included in the source of the project since it
8250 -- is hidden by the exception. So, nothing else to do.
8256 -- The following loop registers the unit in the appropriate table. It
8257 -- will be executed multiple times when the file is a multi-unit file,
8258 -- in which case Exception_Id initially points to the first file and
8259 -- then to each other unit in the file.
8262 if Exception_Id /= No_Ada_Naming_Exception then
8263 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
8264 Exception_Id := Info.Next;
8265 Info.Next := No_Ada_Naming_Exception;
8266 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
8268 Unit_Name := Info.Unit;
8269 Unit_Ind := Name_Index.Index;
8270 Unit_Kind := Info.Kind;
8273 Record_Unit (Unit_Name, Unit_Ind, Unit_Kind, Needs_Pragma);
8274 File_Recorded := True;
8276 exit when Exception_Id = No_Ada_Naming_Exception;
8278 end Record_Ada_Source;
8284 procedure Remove_Source
8286 Replaced_By : Source_Id)
8291 if Current_Verbosity = High then
8292 Write_Str ("Removing source ");
8293 Write_Line (Get_Name_String (Id.File));
8296 if Replaced_By /= No_Source then
8297 Id.Replaced_By := Replaced_By;
8298 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
8301 Source := Id.Language.First_Source;
8304 Id.Language.First_Source := Id.Next_In_Lang;
8307 while Source.Next_In_Lang /= Id loop
8308 Source := Source.Next_In_Lang;
8311 Source.Next_In_Lang := Id.Next_In_Lang;
8315 -----------------------
8316 -- Report_No_Sources --
8317 -----------------------
8319 procedure Report_No_Sources
8320 (Project : Project_Id;
8322 In_Tree : Project_Tree_Ref;
8323 Location : Source_Ptr;
8324 Continuation : Boolean := False)
8327 case When_No_Sources is
8331 when Warning | Error =>
8333 Msg : constant String :=
8336 " sources in this project";
8339 Error_Msg_Warn := When_No_Sources = Warning;
8341 if Continuation then
8342 Error_Msg (Project, In_Tree, "\" & Msg, Location);
8344 Error_Msg (Project, In_Tree, Msg, Location);
8348 end Report_No_Sources;
8350 ----------------------
8351 -- Show_Source_Dirs --
8352 ----------------------
8354 procedure Show_Source_Dirs
8355 (Project : Project_Id;
8356 In_Tree : Project_Tree_Ref)
8358 Current : String_List_Id;
8359 Element : String_Element;
8362 Write_Line ("Source_Dirs:");
8364 Current := Project.Source_Dirs;
8365 while Current /= Nil_String loop
8366 Element := In_Tree.String_Elements.Table (Current);
8368 Write_Line (Get_Name_String (Element.Value));
8369 Current := Element.Next;
8372 Write_Line ("end Source_Dirs.");
8373 end Show_Source_Dirs;
8375 -------------------------
8376 -- Warn_If_Not_Sources --
8377 -------------------------
8379 -- comments needed in this body ???
8381 procedure Warn_If_Not_Sources
8382 (Project : Project_Id;
8383 In_Tree : Project_Tree_Ref;
8384 Conventions : Array_Element_Id;
8386 Extending : Boolean)
8388 Conv : Array_Element_Id;
8390 The_Unit_Data : Unit_Index;
8391 Location : Source_Ptr;
8394 Conv := Conventions;
8395 while Conv /= No_Array_Element loop
8396 Unit := In_Tree.Array_Elements.Table (Conv).Index;
8397 Error_Msg_Name_1 := Unit;
8398 Get_Name_String (Unit);
8399 To_Lower (Name_Buffer (1 .. Name_Len));
8401 The_Unit_Data := Units_Htable.Get (In_Tree.Units_HT, Unit);
8402 Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
8404 if The_Unit_Data = No_Unit_Index then
8405 Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
8409 In_Tree.Array_Elements.Table (Conv).Value.Value;
8412 if not Check_Project
8413 (The_Unit_Data.File_Names (Spec).Project,
8418 "?source of spec of unit %% (%%)" &
8419 " not found in this project",
8424 if The_Unit_Data.File_Names (Impl) = null
8425 or else not Check_Project
8426 (The_Unit_Data.File_Names (Impl).Project,
8431 "?source of body of unit %% (%%)" &
8432 " not found in this project",
8438 Conv := In_Tree.Array_Elements.Table (Conv).Next;
8440 end Warn_If_Not_Sources;