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 function Hash (Unit : Unit_Info) return Header_Num;
201 type Name_And_Index is record
202 Name : Name_Id := No_Name;
205 No_Name_And_Index : constant Name_And_Index :=
206 (Name => No_Name, Index => 0);
207 -- Name of a unit, and its index inside the source file. The first unit has
208 -- index 1 (see doc for pragma Source_File_Name), but the index might be
209 -- set to 0 when the source file contains a single unit.
211 package Reverse_Ada_Naming_Exceptions is new GNAT.HTable.Simple_HTable
212 (Header_Num => Header_Num,
213 Element => Name_And_Index,
214 No_Element => No_Name_And_Index,
218 -- A table to check if a unit with an exceptional name will hide a source
219 -- with a file name following the naming convention.
221 procedure Load_Naming_Exceptions
222 (Project : Project_Id;
223 In_Tree : Project_Tree_Ref);
224 -- All source files in Data.First_Source are considered as naming
225 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
230 In_Tree : Project_Tree_Ref;
231 Project : Project_Id;
232 Lang_Id : Language_Ptr;
234 File_Name : File_Name_Type;
235 Display_File : File_Name_Type;
236 Lang_Kind : Language_Kind;
237 Naming_Exception : Boolean := False;
238 Path : Path_Information := No_Path_Information;
239 Alternate_Languages : Language_List := null;
240 Other_Part : Source_Id := No_Source;
241 Unit : Name_Id := No_Name;
243 Source_To_Replace : Source_Id := No_Source);
244 -- Add a new source to the different lists: list of all sources in the
245 -- project tree, list of source of a project and list of sources of a
248 -- If Path is specified, the file is also added to Source_Paths_HT.
249 -- If Source_To_Replace is specified, it points to the source in the
250 -- extended project that the new file is overriding.
252 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
253 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
254 -- This alters Name_Buffer
256 function Suffix_Matches
258 Suffix : File_Name_Type) return Boolean;
259 -- True if the file name ends with the given suffix. Always returns False
260 -- if Suffix is No_Name.
262 procedure Replace_Into_Name_Buffer
265 Replacement : Character);
266 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
267 -- converted to lower-case at the same time.
269 function ALI_File_Name (Source : String) return String;
270 -- Return the ALI file name corresponding to a source
272 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
273 -- Check that a name is a valid Ada unit name
275 procedure Check_Naming_Schemes
276 (Project : Project_Id;
277 In_Tree : Project_Tree_Ref;
278 Is_Config_File : Boolean);
279 -- Check the naming scheme part of Data.
280 -- Is_Config_File should be True if Project is a config file (.cgpr)
282 procedure Check_Configuration
283 (Project : Project_Id;
284 In_Tree : Project_Tree_Ref;
285 Compiler_Driver_Mandatory : Boolean);
286 -- Check the configuration attributes for the project
287 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
288 -- for each language must be defined, or we will not look for its source
291 procedure Check_If_Externally_Built
292 (Project : Project_Id;
293 In_Tree : Project_Tree_Ref);
294 -- Check attribute Externally_Built of project Project in project tree
295 -- In_Tree and modify its data Data if it has the value "true".
297 procedure Check_Interfaces
298 (Project : Project_Id;
299 In_Tree : Project_Tree_Ref);
300 -- If a list of sources is specified in attribute Interfaces, set
301 -- In_Interfaces only for the sources specified in the list.
303 procedure Check_Library_Attributes
304 (Project : Project_Id;
305 In_Tree : Project_Tree_Ref);
306 -- Check the library attributes of project Project in project tree In_Tree
307 -- and modify its data Data accordingly.
308 -- Current_Dir should represent the current directory, and is passed for
309 -- efficiency to avoid system calls to recompute it.
311 procedure Check_Package_Naming
312 (Project : Project_Id;
313 In_Tree : Project_Tree_Ref);
314 -- Check package Naming of project Project in project tree In_Tree and
315 -- modify its data Data accordingly.
317 procedure Check_Programming_Languages
318 (In_Tree : Project_Tree_Ref;
319 Project : Project_Id);
320 -- Check attribute Languages for the project with data Data in project
321 -- tree In_Tree and set the components of Data for all the programming
322 -- languages indicated in attribute Languages, if any.
324 function Check_Project
326 Root_Project : Project_Id;
327 Extending : Boolean) return Boolean;
328 -- Returns True if P is Root_Project or, if Extending is True, a project
329 -- extended by Root_Project.
331 procedure Check_Stand_Alone_Library
332 (Project : Project_Id;
333 In_Tree : Project_Tree_Ref;
334 Current_Dir : String;
335 Extending : Boolean);
336 -- Check if project Project in project tree In_Tree is a Stand-Alone
337 -- Library project, and modify its data Data accordingly if it is one.
338 -- Current_Dir should represent the current directory, and is passed for
339 -- efficiency to avoid system calls to recompute it.
341 procedure Check_And_Normalize_Unit_Names
342 (Project : Project_Id;
343 In_Tree : Project_Tree_Ref;
344 List : Array_Element_Id;
345 Debug_Name : String);
346 -- Check that a list of unit names contains only valid names. Casing
347 -- is normalized where appropriate.
348 -- Debug_Name is the name representing the list, and is used for debug
351 procedure Find_Ada_Sources
352 (Project : Project_Id;
353 In_Tree : Project_Tree_Ref;
354 Explicit_Sources_Only : Boolean;
355 Proc_Data : in out Processing_Data);
356 -- Find all Ada sources by traversing all source directories.
357 -- If Explicit_Sources_Only is True, then the sources found must belong to
358 -- the list of sources specified explicitly in the project file.
359 -- If Explicit_Sources_Only is False, then all sources matching the naming
360 -- scheme are recorded.
362 function Compute_Directory_Last (Dir : String) return Natural;
363 -- Return the index of the last significant character in Dir. This is used
364 -- to avoid duplicate '/' (slash) characters at the end of directory names.
367 (Project : Project_Id;
368 In_Tree : Project_Tree_Ref;
370 Flag_Location : Source_Ptr);
371 -- Output an error message. If Error_Report is null, simply call
372 -- Prj.Err.Error_Msg. Otherwise, disregard Flag_Location and use
375 procedure Search_Directories
376 (Project : Project_Id;
377 In_Tree : Project_Tree_Ref;
378 For_All_Sources : Boolean);
379 -- Search the source directories to find the sources.
380 -- If For_All_Sources is True, check each regular file name against the
381 -- naming schemes of the different languages. Otherwise consider only the
382 -- file names in the hash table Source_Names.
385 (Project : Project_Id;
386 In_Tree : Project_Tree_Ref;
387 Path : Path_Name_Type;
388 File_Name : File_Name_Type;
389 Display_File_Name : File_Name_Type;
390 For_All_Sources : Boolean);
391 -- Check if file File_Name is a valid source of the project. This is used
392 -- in multi-language mode only.
393 -- When the file matches one of the naming schemes, it is added to
394 -- various htables through Add_Source and to Source_Paths_Htable.
396 -- Name is the name of the candidate file. It hasn't been normalized yet
397 -- and is the direct result of readdir().
399 -- File_Name is the same as Name, but has been normalized.
400 -- Display_File_Name, however, has not been normalized.
402 -- Source_Directory is the directory in which the file
403 -- was found. It hasn't been normalized (nor has had links resolved).
404 -- It should not end with a directory separator, to avoid duplicates
407 -- If For_All_Sources is True, then all possible file names are analyzed
408 -- otherwise only those currently set in the Source_Names htable.
410 procedure Check_File_Naming_Schemes
411 (In_Tree : Project_Tree_Ref;
412 Project : Project_Id;
413 File_Name : File_Name_Type;
414 Alternate_Languages : out Language_List;
415 Language : out Language_Ptr;
416 Display_Language_Name : out Name_Id;
418 Lang_Kind : out Language_Kind;
419 Kind : out Source_Kind);
420 -- Check if the file name File_Name conforms to one of the naming
421 -- schemes of the project.
423 -- If the file does not match one of the naming schemes, set Language
424 -- to No_Language_Index.
426 -- Filename is the name of the file being investigated. It has been
427 -- normalized (case-folded). File_Name is the same value.
429 procedure Free_Ada_Naming_Exceptions;
430 -- Free the internal hash tables used for checking naming exceptions
432 procedure Get_Directories
433 (Project : Project_Id;
434 In_Tree : Project_Tree_Ref;
435 Current_Dir : String);
436 -- Get the object directory, the exec directory and the source directories
439 -- Current_Dir should represent the current directory, and is passed for
440 -- efficiency to avoid system calls to recompute it.
443 (Project : Project_Id;
444 In_Tree : Project_Tree_Ref);
445 -- Get the mains of a project from attribute Main, if it exists, and put
446 -- them in the project data.
448 procedure Get_Sources_From_File
450 Location : Source_Ptr;
451 Project : Project_Id;
452 In_Tree : Project_Tree_Ref);
453 -- Get the list of sources from a text file and put them in hash table
456 procedure Find_Sources
457 (Project : Project_Id;
458 In_Tree : Project_Tree_Ref;
459 Proc_Data : in out Processing_Data);
460 -- Process the Source_Files and Source_List_File attributes, and store
461 -- the list of source files into the Source_Names htable.
462 -- When these attributes are not defined, find all files matching the
463 -- naming schemes in the source directories.
465 procedure Compute_Unit_Name
466 (File_Name : File_Name_Type;
467 Dot_Replacement : File_Name_Type;
468 Separate_Suffix : File_Name_Type;
469 Body_Suffix : File_Name_Type;
470 Spec_Suffix : File_Name_Type;
471 Casing : Casing_Type;
472 Kind : out Source_Kind;
474 In_Tree : Project_Tree_Ref);
475 -- Check whether the file matches the naming scheme. If it does,
476 -- compute its unit name. If Unit is set to No_Name on exit, none of the
477 -- other out parameters are relevant.
480 (In_Tree : Project_Tree_Ref;
481 Canonical_File_Name : File_Name_Type;
482 Naming : Naming_Data;
483 Exception_Id : out Ada_Naming_Exception_Id;
484 Unit_Name : out Name_Id;
485 Unit_Kind : out Spec_Or_Body);
486 -- Find out, from a file name, the unit name, the unit kind and if a
487 -- specific SFN pragma is needed. If the file name corresponds to no unit,
488 -- then Unit_Name will be No_Name. If the file is a multi-unit source or an
489 -- exception to the naming scheme, then Exception_Id is set to the unit or
490 -- units that the source contains, and the other information are not set.
492 function Is_Illegal_Suffix
493 (Suffix : File_Name_Type;
494 Dot_Replacement : File_Name_Type) return Boolean;
495 -- Returns True if the string Suffix cannot be used as a spec suffix, a
496 -- body suffix or a separate suffix.
498 procedure Locate_Directory
499 (Project : Project_Id;
500 In_Tree : Project_Tree_Ref;
501 Name : File_Name_Type;
502 Path : out Path_Information;
503 Dir_Exists : out Boolean;
504 Create : String := "";
505 Location : Source_Ptr := No_Location;
506 Must_Exist : Boolean := True;
507 Externally_Built : Boolean := False);
508 -- Locate a directory. Name is the directory name.
509 -- Relative paths are resolved relative to the project's directory.
510 -- If the directory does not exist and Setup_Projects
511 -- is True and Create is a non null string, an attempt is made to create
513 -- If the directory does not exist, it is either created if Setup_Projects
514 -- is False (and then returned), or simply returned without checking for
515 -- its existence (if Must_Exist is False) or No_Path_Information is
516 -- returned. In all cases, Dir_Exists indicates whether the directory now
519 -- Create is also used for debugging traces to show which path we are
522 procedure Look_For_Sources
523 (Project : Project_Id;
524 In_Tree : Project_Tree_Ref;
525 Proc_Data : in out Processing_Data);
526 -- Find all the sources of project Project in project tree In_Tree and
527 -- update its Data accordingly. This assumes that Data.First_Source has
528 -- been initialized with the list of excluded sources and special naming
531 function Path_Name_Of
532 (File_Name : File_Name_Type;
533 Directory : Path_Name_Type) return String;
534 -- Returns the path name of a (non project) file. Returns an empty string
535 -- if file cannot be found.
537 procedure Prepare_Ada_Naming_Exceptions
538 (List : Array_Element_Id;
539 In_Tree : Project_Tree_Ref;
540 Kind : Spec_Or_Body);
541 -- Prepare the internal hash tables used for checking naming exceptions
542 -- for Ada. Insert all elements of List in the tables.
544 procedure Record_Ada_Source
545 (File_Name : File_Name_Type;
546 Path_Name : Path_Name_Type;
547 Project : Project_Id;
548 In_Tree : Project_Tree_Ref;
549 Proc_Data : in out Processing_Data;
550 Ada_Language : Language_Ptr;
551 Location : Source_Ptr;
552 Source_Recorded : in out Boolean);
553 -- Put a unit in the list of units of a project, if the file name
554 -- corresponds to a valid unit name.
555 -- Ada_Language is a pointer to the Language_Data for "Ada" in Project.
557 procedure Remove_Source
559 Replaced_By : Source_Id);
562 procedure Report_No_Sources
563 (Project : Project_Id;
565 In_Tree : Project_Tree_Ref;
566 Location : Source_Ptr;
567 Continuation : Boolean := False);
568 -- Report an error or a warning depending on the value of When_No_Sources
569 -- when there are no sources for language Lang_Name.
571 procedure Show_Source_Dirs
572 (Project : Project_Id; In_Tree : Project_Tree_Ref);
573 -- List all the source directories of a project
575 procedure Warn_If_Not_Sources
576 (Project : Project_Id;
577 In_Tree : Project_Tree_Ref;
578 Conventions : Array_Element_Id;
580 Extending : Boolean);
581 -- Check that individual naming conventions apply to immediate sources of
582 -- the project. If not, issue a warning.
584 procedure Write_Attr (Name, Value : String);
585 -- Debug print a value for a specific property. Does nothing when not in
588 ------------------------------
589 -- Replace_Into_Name_Buffer --
590 ------------------------------
592 procedure Replace_Into_Name_Buffer
595 Replacement : Character)
597 Max : constant Integer := Str'Last - Pattern'Length + 1;
604 while J <= Str'Last loop
605 Name_Len := Name_Len + 1;
608 and then Str (J .. J + Pattern'Length - 1) = Pattern
610 Name_Buffer (Name_Len) := Replacement;
611 J := J + Pattern'Length;
614 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
618 end Replace_Into_Name_Buffer;
624 function Suffix_Matches
626 Suffix : File_Name_Type) return Boolean
629 if Suffix = No_File or else Suffix = Empty_File then
634 Suf : constant String := Get_Name_String (Suffix);
636 return Filename'Length > Suf'Length
638 (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
646 procedure Write_Attr (Name, Value : String) is
648 if Current_Verbosity = High then
649 Write_Str (" " & Name & " = """);
662 In_Tree : Project_Tree_Ref;
663 Project : Project_Id;
664 Lang_Id : Language_Ptr;
666 File_Name : File_Name_Type;
667 Display_File : File_Name_Type;
668 Lang_Kind : Language_Kind;
669 Naming_Exception : Boolean := False;
670 Path : Path_Information := No_Path_Information;
671 Alternate_Languages : Language_List := null;
672 Other_Part : Source_Id := No_Source;
673 Unit : Name_Id := No_Name;
675 Source_To_Replace : Source_Id := No_Source)
677 Config : constant Language_Config := Lang_Id.Config;
680 Id := new Source_Data;
682 if Current_Verbosity = High then
683 Write_Str ("Adding source File: ");
684 Write_Str (Get_Name_String (File_Name));
686 if Lang_Kind = Unit_Based then
687 Write_Str (" Unit: ");
688 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
689 -- (see test extended_projects)
690 if Unit /= No_Name then
691 Write_Str (Get_Name_String (Unit));
693 Write_Str (" Kind: ");
694 Write_Str (Source_Kind'Image (Kind));
700 Id.Project := Project;
701 Id.Language := Lang_Id;
702 Id.Lang_Kind := Lang_Kind;
703 Id.Compiled := Lang_Id.Config.Compiler_Driver /=
706 Id.Alternate_Languages := Alternate_Languages;
707 Id.Other_Part := Other_Part;
709 Id.Object_Exists := Config.Object_Generated;
710 Id.Object_Linked := Config.Objects_Linked;
712 if Other_Part /= No_Source then
713 Other_Part.Other_Part := Id;
718 Id.File := File_Name;
719 Id.Display_File := Display_File;
720 Id.Dependency := Lang_Id.Config.Dependency_Kind;
721 Id.Dep_Name := Dependency_Name (File_Name, Id.Dependency);
722 Id.Naming_Exception := Naming_Exception;
724 if Id.Compiled and then Id.Object_Exists then
725 Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
726 Id.Switches := Switches_Name (File_Name);
729 if Path /= No_Path_Information then
731 Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path.Name, Id);
734 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
737 if Unit /= No_Name then
738 Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
741 -- Add the source to the language list
743 Id.Next_In_Lang := Lang_Id.First_Source;
744 Lang_Id.First_Source := Id;
746 if Source_To_Replace /= No_Source then
747 Remove_Source (Source_To_Replace, Id);
755 function ALI_File_Name (Source : String) return String is
757 -- If the source name has an extension, then replace it with
760 for Index in reverse Source'First + 1 .. Source'Last loop
761 if Source (Index) = '.' then
762 return Source (Source'First .. Index - 1) & ALI_Suffix;
766 -- If there is no dot, or if it is the first character, just add the
769 return Source & ALI_Suffix;
772 ------------------------------
773 -- Canonical_Case_File_Name --
774 ------------------------------
776 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
778 if Osint.File_Names_Case_Sensitive then
779 return File_Name_Type (Name);
781 Get_Name_String (Name);
782 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
785 end Canonical_Case_File_Name;
792 (Project : Project_Id;
793 In_Tree : Project_Tree_Ref;
794 Report_Error : Put_Line_Access;
795 When_No_Sources : Error_Warning;
796 Current_Dir : String;
797 Proc_Data : in out Processing_Data;
798 Is_Config_File : Boolean;
799 Compiler_Driver_Mandatory : Boolean)
801 Extending : Boolean := False;
804 Nmsc.When_No_Sources := When_No_Sources;
805 Error_Report := Report_Error;
807 Recursive_Dirs.Reset;
809 Check_If_Externally_Built (Project, In_Tree);
811 -- Object, exec and source directories
813 Get_Directories (Project, In_Tree, Current_Dir);
815 -- Get the programming languages
817 Check_Programming_Languages (In_Tree, Project);
819 if Project.Qualifier = Dry
820 and then Project.Source_Dirs /= Nil_String
824 "an abstract project needs to have no language, no sources " &
825 "or no source directories",
829 -- Check configuration in multi language mode
831 if Must_Check_Configuration then
834 Compiler_Driver_Mandatory => Compiler_Driver_Mandatory);
837 -- Library attributes
839 Check_Library_Attributes (Project, In_Tree);
841 if Current_Verbosity = High then
842 Show_Source_Dirs (Project, In_Tree);
845 Check_Package_Naming (Project, In_Tree);
847 Extending := Project.Extends /= No_Project;
849 Check_Naming_Schemes (Project, In_Tree, Is_Config_File);
851 if Get_Mode = Ada_Only then
852 Prepare_Ada_Naming_Exceptions
853 (Project.Naming.Bodies, In_Tree, Impl);
854 Prepare_Ada_Naming_Exceptions
855 (Project.Naming.Specs, In_Tree, Spec);
860 if Project.Source_Dirs /= Nil_String then
861 Look_For_Sources (Project, In_Tree, Proc_Data);
863 if Get_Mode = Ada_Only then
865 -- Check that all individual naming conventions apply to sources
866 -- of this project file.
869 (Project, In_Tree, Project.Naming.Bodies,
871 Extending => Extending);
873 (Project, In_Tree, Project.Naming.Specs,
875 Extending => Extending);
877 elsif Get_Mode = Multi_Language and then
878 (not Project.Externally_Built) and then
882 Language : Language_Ptr;
884 Alt_Lang : Language_List;
885 Continuation : Boolean := False;
886 Iter : Source_Iterator;
889 Language := Project.Languages;
890 while Language /= No_Language_Index loop
892 -- If there are no sources for this language, check whether
893 -- there are sources for which this is an alternate
896 if Language.First_Source = No_Source then
897 Iter := For_Each_Source (In_Tree => In_Tree,
900 Source := Element (Iter);
901 exit Source_Loop when Source = No_Source
902 or else Source.Language = Language;
904 Alt_Lang := Source.Alternate_Languages;
905 while Alt_Lang /= null loop
906 exit Source_Loop when Alt_Lang.Language = Language;
907 Alt_Lang := Alt_Lang.Next;
911 end loop Source_Loop;
913 if Source = No_Source then
916 Get_Name_String (Language.Display_Name),
920 Continuation := True;
924 Language := Language.Next;
930 if Get_Mode = Multi_Language then
932 -- If a list of sources is specified in attribute Interfaces, set
933 -- In_Interfaces only for the sources specified in the list.
935 Check_Interfaces (Project, In_Tree);
938 -- If it is a library project file, check if it is a standalone library
940 if Project.Library then
941 Check_Stand_Alone_Library
942 (Project, In_Tree, Current_Dir, Extending);
945 -- Put the list of Mains, if any, in the project data
947 Get_Mains (Project, In_Tree);
949 Free_Ada_Naming_Exceptions;
956 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
957 The_Name : String := Name;
959 Need_Letter : Boolean := True;
960 Last_Underscore : Boolean := False;
961 OK : Boolean := The_Name'Length > 0;
964 function Is_Reserved (Name : Name_Id) return Boolean;
965 function Is_Reserved (S : String) return Boolean;
966 -- Check that the given name is not an Ada 95 reserved word. The reason
967 -- for the Ada 95 here is that we do not want to exclude the case of an
968 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
969 -- name would be rejected anyway by the compiler. That means there is no
970 -- requirement that the project file parser reject this.
976 function Is_Reserved (S : String) return Boolean is
979 Add_Str_To_Name_Buffer (S);
980 return Is_Reserved (Name_Find);
987 function Is_Reserved (Name : Name_Id) return Boolean is
989 if Get_Name_Table_Byte (Name) /= 0
990 and then Name /= Name_Project
991 and then Name /= Name_Extends
992 and then Name /= Name_External
993 and then Name not in Ada_2005_Reserved_Words
997 if Current_Verbosity = High then
998 Write_Str (The_Name);
999 Write_Line (" is an Ada reserved word.");
1009 -- Start of processing for Check_Ada_Name
1012 To_Lower (The_Name);
1014 Name_Len := The_Name'Length;
1015 Name_Buffer (1 .. Name_Len) := The_Name;
1017 -- Special cases of children of packages A, G, I and S on VMS
1019 if OpenVMS_On_Target
1020 and then Name_Len > 3
1021 and then Name_Buffer (2 .. 3) = "__"
1023 ((Name_Buffer (1) = 'a') or else
1024 (Name_Buffer (1) = 'g') or else
1025 (Name_Buffer (1) = 'i') or else
1026 (Name_Buffer (1) = 's'))
1028 Name_Buffer (2) := '.';
1029 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1030 Name_Len := Name_Len - 1;
1033 Real_Name := Name_Find;
1035 if Is_Reserved (Real_Name) then
1039 First := The_Name'First;
1041 for Index in The_Name'Range loop
1044 -- We need a letter (at the beginning, and following a dot),
1045 -- but we don't have one.
1047 if Is_Letter (The_Name (Index)) then
1048 Need_Letter := False;
1053 if Current_Verbosity = High then
1054 Write_Int (Types.Int (Index));
1056 Write_Char (The_Name (Index));
1057 Write_Line ("' is not a letter.");
1063 elsif Last_Underscore
1064 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1066 -- Two underscores are illegal, and a dot cannot follow
1071 if Current_Verbosity = High then
1072 Write_Int (Types.Int (Index));
1074 Write_Char (The_Name (Index));
1075 Write_Line ("' is illegal here.");
1080 elsif The_Name (Index) = '.' then
1082 -- First, check if the name before the dot is not a reserved word
1083 if Is_Reserved (The_Name (First .. Index - 1)) then
1089 -- We need a letter after a dot
1091 Need_Letter := True;
1093 elsif The_Name (Index) = '_' then
1094 Last_Underscore := True;
1097 -- We need an letter or a digit
1099 Last_Underscore := False;
1101 if not Is_Alphanumeric (The_Name (Index)) then
1104 if Current_Verbosity = High then
1105 Write_Int (Types.Int (Index));
1107 Write_Char (The_Name (Index));
1108 Write_Line ("' is not alphanumeric.");
1116 -- Cannot end with an underscore or a dot
1118 OK := OK and then not Need_Letter and then not Last_Underscore;
1121 if First /= Name'First and then
1122 Is_Reserved (The_Name (First .. The_Name'Last))
1130 -- Signal a problem with No_Name
1136 -------------------------
1137 -- Check_Configuration --
1138 -------------------------
1140 procedure Check_Configuration
1141 (Project : Project_Id;
1142 In_Tree : Project_Tree_Ref;
1143 Compiler_Driver_Mandatory : Boolean)
1145 Dot_Replacement : File_Name_Type := No_File;
1146 Casing : Casing_Type := All_Lower_Case;
1147 Separate_Suffix : File_Name_Type := No_File;
1149 Lang_Index : Language_Ptr := No_Language_Index;
1150 -- The index of the language data being checked
1152 Prev_Index : Language_Ptr := No_Language_Index;
1153 -- The index of the previous language
1155 Current_Language : Name_Id := No_Name;
1156 -- The name of the language
1158 procedure Get_Language_Index_Of (Language : Name_Id);
1159 -- Get the language index of Language, if Language is one of the
1160 -- languages of the project.
1162 procedure Process_Project_Level_Simple_Attributes;
1163 -- Process the simple attributes at the project level
1165 procedure Process_Project_Level_Array_Attributes;
1166 -- Process the associate array attributes at the project level
1168 procedure Process_Packages;
1169 -- Read the packages of the project
1171 ---------------------------
1172 -- Get_Language_Index_Of --
1173 ---------------------------
1175 procedure Get_Language_Index_Of (Language : Name_Id) is
1176 Real_Language : Name_Id;
1179 Get_Name_String (Language);
1180 To_Lower (Name_Buffer (1 .. Name_Len));
1181 Real_Language := Name_Find;
1183 -- Nothing to do if the language is the same as the current language
1185 if Current_Language /= Real_Language then
1186 Lang_Index := Project.Languages;
1187 while Lang_Index /= No_Language_Index loop
1188 exit when Lang_Index.Name = Real_Language;
1189 Lang_Index := Lang_Index.Next;
1192 if Lang_Index = No_Language_Index then
1193 Current_Language := No_Name;
1195 Current_Language := Real_Language;
1198 end Get_Language_Index_Of;
1200 ----------------------
1201 -- Process_Packages --
1202 ----------------------
1204 procedure Process_Packages is
1205 Packages : Package_Id;
1206 Element : Package_Element;
1208 procedure Process_Binder (Arrays : Array_Id);
1209 -- Process the associate array attributes of package Binder
1211 procedure Process_Builder (Attributes : Variable_Id);
1212 -- Process the simple attributes of package Builder
1214 procedure Process_Compiler (Arrays : Array_Id);
1215 -- Process the associate array attributes of package Compiler
1217 procedure Process_Naming (Attributes : Variable_Id);
1218 -- Process the simple attributes of package Naming
1220 procedure Process_Naming (Arrays : Array_Id);
1221 -- Process the associate array attributes of package Naming
1223 procedure Process_Linker (Attributes : Variable_Id);
1224 -- Process the simple attributes of package Linker of a
1225 -- configuration project.
1227 --------------------
1228 -- Process_Binder --
1229 --------------------
1231 procedure Process_Binder (Arrays : Array_Id) is
1232 Current_Array_Id : Array_Id;
1233 Current_Array : Array_Data;
1234 Element_Id : Array_Element_Id;
1235 Element : Array_Element;
1238 -- Process the associative array attribute of package Binder
1240 Current_Array_Id := Arrays;
1241 while Current_Array_Id /= No_Array loop
1242 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1244 Element_Id := Current_Array.Value;
1245 while Element_Id /= No_Array_Element loop
1246 Element := In_Tree.Array_Elements.Table (Element_Id);
1248 if Element.Index /= All_Other_Names then
1250 -- Get the name of the language
1252 Get_Language_Index_Of (Element.Index);
1254 if Lang_Index /= No_Language_Index then
1255 case Current_Array.Name is
1258 -- Attribute Driver (<language>)
1260 Lang_Index.Config.Binder_Driver :=
1261 File_Name_Type (Element.Value.Value);
1263 when Name_Required_Switches =>
1265 Lang_Index.Config.Binder_Required_Switches,
1266 From_List => Element.Value.Values,
1267 In_Tree => In_Tree);
1271 -- Attribute Prefix (<language>)
1273 Lang_Index.Config.Binder_Prefix :=
1274 Element.Value.Value;
1276 when Name_Objects_Path =>
1278 -- Attribute Objects_Path (<language>)
1280 Lang_Index.Config.Objects_Path :=
1281 Element.Value.Value;
1283 when Name_Objects_Path_File =>
1285 -- Attribute Objects_Path (<language>)
1287 Lang_Index.Config.Objects_Path_File :=
1288 Element.Value.Value;
1296 Element_Id := Element.Next;
1299 Current_Array_Id := Current_Array.Next;
1303 ---------------------
1304 -- Process_Builder --
1305 ---------------------
1307 procedure Process_Builder (Attributes : Variable_Id) is
1308 Attribute_Id : Variable_Id;
1309 Attribute : Variable;
1312 -- Process non associated array attribute from package Builder
1314 Attribute_Id := Attributes;
1315 while Attribute_Id /= No_Variable loop
1317 In_Tree.Variable_Elements.Table (Attribute_Id);
1319 if not Attribute.Value.Default then
1320 if Attribute.Name = Name_Executable_Suffix then
1322 -- Attribute Executable_Suffix: the suffix of the
1325 Project.Config.Executable_Suffix :=
1326 Attribute.Value.Value;
1330 Attribute_Id := Attribute.Next;
1332 end Process_Builder;
1334 ----------------------
1335 -- Process_Compiler --
1336 ----------------------
1338 procedure Process_Compiler (Arrays : Array_Id) is
1339 Current_Array_Id : Array_Id;
1340 Current_Array : Array_Data;
1341 Element_Id : Array_Element_Id;
1342 Element : Array_Element;
1343 List : String_List_Id;
1346 -- Process the associative array attribute of package Compiler
1348 Current_Array_Id := Arrays;
1349 while Current_Array_Id /= No_Array loop
1350 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1352 Element_Id := Current_Array.Value;
1353 while Element_Id /= No_Array_Element loop
1354 Element := In_Tree.Array_Elements.Table (Element_Id);
1356 if Element.Index /= All_Other_Names then
1358 -- Get the name of the language
1360 Get_Language_Index_Of (Element.Index);
1362 if Lang_Index /= No_Language_Index then
1363 case Current_Array.Name is
1364 when Name_Dependency_Switches =>
1366 -- Attribute Dependency_Switches (<language>)
1368 if Lang_Index.Config.Dependency_Kind = None then
1369 Lang_Index.Config.Dependency_Kind := Makefile;
1372 List := Element.Value.Values;
1374 if List /= Nil_String then
1376 Lang_Index.Config.Dependency_Option,
1378 In_Tree => In_Tree);
1381 when Name_Dependency_Driver =>
1383 -- Attribute Dependency_Driver (<language>)
1385 if Lang_Index.Config.Dependency_Kind = None then
1386 Lang_Index.Config.Dependency_Kind := Makefile;
1389 List := Element.Value.Values;
1391 if List /= Nil_String then
1393 Lang_Index.Config.Compute_Dependency,
1395 In_Tree => In_Tree);
1398 when Name_Include_Switches =>
1400 -- Attribute Include_Switches (<language>)
1402 List := Element.Value.Values;
1404 if List = Nil_String then
1408 "include option cannot be null",
1409 Element.Value.Location);
1413 Lang_Index.Config.Include_Option,
1415 In_Tree => In_Tree);
1417 when Name_Include_Path =>
1419 -- Attribute Include_Path (<language>)
1421 Lang_Index.Config.Include_Path :=
1422 Element.Value.Value;
1424 when Name_Include_Path_File =>
1426 -- Attribute Include_Path_File (<language>)
1428 Lang_Index.Config.Include_Path_File :=
1429 Element.Value.Value;
1433 -- Attribute Driver (<language>)
1435 Lang_Index.Config.Compiler_Driver :=
1436 File_Name_Type (Element.Value.Value);
1438 when Name_Required_Switches |
1439 Name_Leading_Required_Switches =>
1442 Compiler_Leading_Required_Switches,
1443 From_List => Element.Value.Values,
1444 In_Tree => In_Tree);
1446 when Name_Trailing_Required_Switches =>
1449 Compiler_Trailing_Required_Switches,
1450 From_List => Element.Value.Values,
1451 In_Tree => In_Tree);
1453 when Name_Path_Syntax =>
1455 Lang_Index.Config.Path_Syntax :=
1456 Path_Syntax_Kind'Value
1457 (Get_Name_String (Element.Value.Value));
1460 when Constraint_Error =>
1464 "invalid value for Path_Syntax",
1465 Element.Value.Location);
1468 when Name_Object_File_Suffix =>
1469 if Get_Name_String (Element.Value.Value) = "" then
1472 "object file suffix cannot be empty",
1473 Element.Value.Location);
1476 Lang_Index.Config.Object_File_Suffix :=
1477 Element.Value.Value;
1480 when Name_Object_File_Switches =>
1482 Lang_Index.Config.Object_File_Switches,
1483 From_List => Element.Value.Values,
1484 In_Tree => In_Tree);
1486 when Name_Pic_Option =>
1488 -- Attribute Compiler_Pic_Option (<language>)
1490 List := Element.Value.Values;
1492 if List = Nil_String then
1496 "compiler PIC option cannot be null",
1497 Element.Value.Location);
1501 Lang_Index.Config.Compilation_PIC_Option,
1503 In_Tree => In_Tree);
1505 when Name_Mapping_File_Switches =>
1507 -- Attribute Mapping_File_Switches (<language>)
1509 List := Element.Value.Values;
1511 if List = Nil_String then
1515 "mapping file switches cannot be null",
1516 Element.Value.Location);
1520 Lang_Index.Config.Mapping_File_Switches,
1522 In_Tree => In_Tree);
1524 when Name_Mapping_Spec_Suffix =>
1526 -- Attribute Mapping_Spec_Suffix (<language>)
1528 Lang_Index.Config.Mapping_Spec_Suffix :=
1529 File_Name_Type (Element.Value.Value);
1531 when Name_Mapping_Body_Suffix =>
1533 -- Attribute Mapping_Body_Suffix (<language>)
1535 Lang_Index.Config.Mapping_Body_Suffix :=
1536 File_Name_Type (Element.Value.Value);
1538 when Name_Config_File_Switches =>
1540 -- Attribute Config_File_Switches (<language>)
1542 List := Element.Value.Values;
1544 if List = Nil_String then
1548 "config file switches cannot be null",
1549 Element.Value.Location);
1553 Lang_Index.Config.Config_File_Switches,
1555 In_Tree => In_Tree);
1557 when Name_Objects_Path =>
1559 -- Attribute Objects_Path (<language>)
1561 Lang_Index.Config.Objects_Path :=
1562 Element.Value.Value;
1564 when Name_Objects_Path_File =>
1566 -- Attribute Objects_Path_File (<language>)
1568 Lang_Index.Config.Objects_Path_File :=
1569 Element.Value.Value;
1571 when Name_Config_Body_File_Name =>
1573 -- Attribute Config_Body_File_Name (<language>)
1575 Lang_Index.Config.Config_Body :=
1576 Element.Value.Value;
1578 when Name_Config_Body_File_Name_Pattern =>
1580 -- Attribute Config_Body_File_Name_Pattern
1583 Lang_Index.Config.Config_Body_Pattern :=
1584 Element.Value.Value;
1586 when Name_Config_Spec_File_Name =>
1588 -- Attribute Config_Spec_File_Name (<language>)
1590 Lang_Index.Config.Config_Spec :=
1591 Element.Value.Value;
1593 when Name_Config_Spec_File_Name_Pattern =>
1595 -- Attribute Config_Spec_File_Name_Pattern
1598 Lang_Index.Config.Config_Spec_Pattern :=
1599 Element.Value.Value;
1601 when Name_Config_File_Unique =>
1603 -- Attribute Config_File_Unique (<language>)
1606 Lang_Index.Config.Config_File_Unique :=
1608 (Get_Name_String (Element.Value.Value));
1610 when Constraint_Error =>
1614 "illegal value for Config_File_Unique",
1615 Element.Value.Location);
1624 Element_Id := Element.Next;
1627 Current_Array_Id := Current_Array.Next;
1629 end Process_Compiler;
1631 --------------------
1632 -- Process_Naming --
1633 --------------------
1635 procedure Process_Naming (Attributes : Variable_Id) is
1636 Attribute_Id : Variable_Id;
1637 Attribute : Variable;
1640 -- Process non associated array attribute from package Naming
1642 Attribute_Id := Attributes;
1643 while Attribute_Id /= No_Variable loop
1644 Attribute := In_Tree.Variable_Elements.Table (Attribute_Id);
1646 if not Attribute.Value.Default then
1647 if Attribute.Name = Name_Separate_Suffix then
1649 -- Attribute Separate_Suffix
1651 Separate_Suffix := File_Name_Type (Attribute.Value.Value);
1653 elsif Attribute.Name = Name_Casing then
1659 Value (Get_Name_String (Attribute.Value.Value));
1662 when Constraint_Error =>
1666 "invalid value for Casing",
1667 Attribute.Value.Location);
1670 elsif Attribute.Name = Name_Dot_Replacement then
1672 -- Attribute Dot_Replacement
1674 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1679 Attribute_Id := Attribute.Next;
1683 procedure Process_Naming (Arrays : Array_Id) is
1684 Current_Array_Id : Array_Id;
1685 Current_Array : Array_Data;
1686 Element_Id : Array_Element_Id;
1687 Element : Array_Element;
1689 -- Process the associative array attribute of package Naming
1691 Current_Array_Id := Arrays;
1692 while Current_Array_Id /= No_Array loop
1693 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
1695 Element_Id := Current_Array.Value;
1696 while Element_Id /= No_Array_Element loop
1697 Element := In_Tree.Array_Elements.Table (Element_Id);
1699 -- Get the name of the language
1701 Get_Language_Index_Of (Element.Index);
1703 if Lang_Index /= No_Language_Index then
1704 case Current_Array.Name is
1705 when Name_Spec_Suffix | Name_Specification_Suffix =>
1707 -- Attribute Spec_Suffix (<language>)
1709 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1710 File_Name_Type (Element.Value.Value);
1712 when Name_Implementation_Suffix | Name_Body_Suffix =>
1714 -- Attribute Body_Suffix (<language>)
1716 Lang_Index.Config.Naming_Data.Body_Suffix :=
1717 File_Name_Type (Element.Value.Value);
1719 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1720 File_Name_Type (Element.Value.Value);
1727 Element_Id := Element.Next;
1730 Current_Array_Id := Current_Array.Next;
1734 --------------------
1735 -- Process_Linker --
1736 --------------------
1738 procedure Process_Linker (Attributes : Variable_Id) is
1739 Attribute_Id : Variable_Id;
1740 Attribute : Variable;
1743 -- Process non associated array attribute from package Linker
1745 Attribute_Id := Attributes;
1746 while Attribute_Id /= No_Variable loop
1748 In_Tree.Variable_Elements.Table (Attribute_Id);
1750 if not Attribute.Value.Default then
1751 if Attribute.Name = Name_Driver then
1753 -- Attribute Linker'Driver: the default linker to use
1755 Project.Config.Linker :=
1756 Path_Name_Type (Attribute.Value.Value);
1758 -- Linker'Driver is also used to link shared libraries
1759 -- if the obsolescent attribute Library_GCC has not been
1762 if Project.Config.Shared_Lib_Driver = No_File then
1763 Project.Config.Shared_Lib_Driver :=
1764 File_Name_Type (Attribute.Value.Value);
1767 elsif Attribute.Name = Name_Required_Switches then
1769 -- Attribute Required_Switches: the minimum
1770 -- options to use when invoking the linker
1772 Put (Into_List => Project.Config.Minimum_Linker_Options,
1773 From_List => Attribute.Value.Values,
1774 In_Tree => In_Tree);
1776 elsif Attribute.Name = Name_Map_File_Option then
1777 Project.Config.Map_File_Option := Attribute.Value.Value;
1779 elsif Attribute.Name = Name_Max_Command_Line_Length then
1781 Project.Config.Max_Command_Line_Length :=
1782 Natural'Value (Get_Name_String
1783 (Attribute.Value.Value));
1786 when Constraint_Error =>
1790 "value must be positive or equal to 0",
1791 Attribute.Value.Location);
1794 elsif Attribute.Name = Name_Response_File_Format then
1799 Get_Name_String (Attribute.Value.Value);
1800 To_Lower (Name_Buffer (1 .. Name_Len));
1803 if Name = Name_None then
1804 Project.Config.Resp_File_Format := None;
1806 elsif Name = Name_Gnu then
1807 Project.Config.Resp_File_Format := GNU;
1809 elsif Name = Name_Object_List then
1810 Project.Config.Resp_File_Format := Object_List;
1812 elsif Name = Name_Option_List then
1813 Project.Config.Resp_File_Format := Option_List;
1819 "illegal response file format",
1820 Attribute.Value.Location);
1824 elsif Attribute.Name = Name_Response_File_Switches then
1825 Put (Into_List => Project.Config.Resp_File_Options,
1826 From_List => Attribute.Value.Values,
1827 In_Tree => In_Tree);
1831 Attribute_Id := Attribute.Next;
1835 -- Start of processing for Process_Packages
1838 Packages := Project.Decl.Packages;
1839 while Packages /= No_Package loop
1840 Element := In_Tree.Packages.Table (Packages);
1842 case Element.Name is
1845 -- Process attributes of package Binder
1847 Process_Binder (Element.Decl.Arrays);
1849 when Name_Builder =>
1851 -- Process attributes of package Builder
1853 Process_Builder (Element.Decl.Attributes);
1855 when Name_Compiler =>
1857 -- Process attributes of package Compiler
1859 Process_Compiler (Element.Decl.Arrays);
1863 -- Process attributes of package Linker
1865 Process_Linker (Element.Decl.Attributes);
1869 -- Process attributes of package Naming
1871 Process_Naming (Element.Decl.Attributes);
1872 Process_Naming (Element.Decl.Arrays);
1878 Packages := Element.Next;
1880 end Process_Packages;
1882 ---------------------------------------------
1883 -- Process_Project_Level_Simple_Attributes --
1884 ---------------------------------------------
1886 procedure Process_Project_Level_Simple_Attributes is
1887 Attribute_Id : Variable_Id;
1888 Attribute : Variable;
1889 List : String_List_Id;
1892 -- Process non associated array attribute at project level
1894 Attribute_Id := Project.Decl.Attributes;
1895 while Attribute_Id /= No_Variable loop
1897 In_Tree.Variable_Elements.Table (Attribute_Id);
1899 if not Attribute.Value.Default then
1900 if Attribute.Name = Name_Target then
1902 -- Attribute Target: the target specified
1904 Project.Config.Target := Attribute.Value.Value;
1906 elsif Attribute.Name = Name_Library_Builder then
1908 -- Attribute Library_Builder: the application to invoke
1909 -- to build libraries.
1911 Project.Config.Library_Builder :=
1912 Path_Name_Type (Attribute.Value.Value);
1914 elsif Attribute.Name = Name_Archive_Builder then
1916 -- Attribute Archive_Builder: the archive builder
1917 -- (usually "ar") and its minimum options (usually "cr").
1919 List := Attribute.Value.Values;
1921 if List = Nil_String then
1925 "archive builder cannot be null",
1926 Attribute.Value.Location);
1929 Put (Into_List => Project.Config.Archive_Builder,
1931 In_Tree => In_Tree);
1933 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1935 -- Attribute Archive_Builder: the archive builder
1936 -- (usually "ar") and its minimum options (usually "cr").
1938 List := Attribute.Value.Values;
1940 if List /= Nil_String then
1943 Project.Config.Archive_Builder_Append_Option,
1945 In_Tree => In_Tree);
1948 elsif Attribute.Name = Name_Archive_Indexer then
1950 -- Attribute Archive_Indexer: the optional archive
1951 -- indexer (usually "ranlib") with its minimum options
1954 List := Attribute.Value.Values;
1956 if List = Nil_String then
1960 "archive indexer cannot be null",
1961 Attribute.Value.Location);
1964 Put (Into_List => Project.Config.Archive_Indexer,
1966 In_Tree => In_Tree);
1968 elsif Attribute.Name = Name_Library_Partial_Linker then
1970 -- Attribute Library_Partial_Linker: the optional linker
1971 -- driver with its minimum options, to partially link
1974 List := Attribute.Value.Values;
1976 if List = Nil_String then
1980 "partial linker cannot be null",
1981 Attribute.Value.Location);
1984 Put (Into_List => Project.Config.Lib_Partial_Linker,
1986 In_Tree => In_Tree);
1988 elsif Attribute.Name = Name_Library_GCC then
1989 Project.Config.Shared_Lib_Driver :=
1990 File_Name_Type (Attribute.Value.Value);
1994 "?Library_'G'C'C is an obsolescent attribute, " &
1995 "use Linker''Driver instead",
1996 Attribute.Value.Location);
1998 elsif Attribute.Name = Name_Archive_Suffix then
1999 Project.Config.Archive_Suffix :=
2000 File_Name_Type (Attribute.Value.Value);
2002 elsif Attribute.Name = Name_Linker_Executable_Option then
2004 -- Attribute Linker_Executable_Option: optional options
2005 -- to specify an executable name. Defaults to "-o".
2007 List := Attribute.Value.Values;
2009 if List = Nil_String then
2013 "linker executable option cannot be null",
2014 Attribute.Value.Location);
2017 Put (Into_List => Project.Config.Linker_Executable_Option,
2019 In_Tree => In_Tree);
2021 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2023 -- Attribute Linker_Lib_Dir_Option: optional options
2024 -- to specify a library search directory. Defaults to
2027 Get_Name_String (Attribute.Value.Value);
2029 if Name_Len = 0 then
2033 "linker library directory option cannot be empty",
2034 Attribute.Value.Location);
2037 Project.Config.Linker_Lib_Dir_Option :=
2038 Attribute.Value.Value;
2040 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2042 -- Attribute Linker_Lib_Name_Option: optional options
2043 -- to specify the name of a library to be linked in.
2044 -- Defaults to "-l".
2046 Get_Name_String (Attribute.Value.Value);
2048 if Name_Len = 0 then
2052 "linker library name option cannot be empty",
2053 Attribute.Value.Location);
2056 Project.Config.Linker_Lib_Name_Option :=
2057 Attribute.Value.Value;
2059 elsif Attribute.Name = Name_Run_Path_Option then
2061 -- Attribute Run_Path_Option: optional options to
2062 -- specify a path for libraries.
2064 List := Attribute.Value.Values;
2066 if List /= Nil_String then
2067 Put (Into_List => Project.Config.Run_Path_Option,
2069 In_Tree => In_Tree);
2072 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2074 pragma Unsuppress (All_Checks);
2076 Project.Config.Separate_Run_Path_Options :=
2077 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2079 when Constraint_Error =>
2083 "invalid value """ &
2084 Get_Name_String (Attribute.Value.Value) &
2085 """ for Separate_Run_Path_Options",
2086 Attribute.Value.Location);
2089 elsif Attribute.Name = Name_Library_Support then
2091 pragma Unsuppress (All_Checks);
2093 Project.Config.Lib_Support :=
2094 Library_Support'Value (Get_Name_String
2095 (Attribute.Value.Value));
2097 when Constraint_Error =>
2101 "invalid value """ &
2102 Get_Name_String (Attribute.Value.Value) &
2103 """ for Library_Support",
2104 Attribute.Value.Location);
2107 elsif Attribute.Name = Name_Shared_Library_Prefix then
2108 Project.Config.Shared_Lib_Prefix :=
2109 File_Name_Type (Attribute.Value.Value);
2111 elsif Attribute.Name = Name_Shared_Library_Suffix then
2112 Project.Config.Shared_Lib_Suffix :=
2113 File_Name_Type (Attribute.Value.Value);
2115 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2117 pragma Unsuppress (All_Checks);
2119 Project.Config.Symbolic_Link_Supported :=
2120 Boolean'Value (Get_Name_String
2121 (Attribute.Value.Value));
2123 when Constraint_Error =>
2128 & Get_Name_String (Attribute.Value.Value)
2129 & """ for Symbolic_Link_Supported",
2130 Attribute.Value.Location);
2134 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2137 pragma Unsuppress (All_Checks);
2139 Project.Config.Lib_Maj_Min_Id_Supported :=
2140 Boolean'Value (Get_Name_String
2141 (Attribute.Value.Value));
2143 when Constraint_Error =>
2147 "invalid value """ &
2148 Get_Name_String (Attribute.Value.Value) &
2149 """ for Library_Major_Minor_Id_Supported",
2150 Attribute.Value.Location);
2153 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2155 pragma Unsuppress (All_Checks);
2157 Project.Config.Auto_Init_Supported :=
2158 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2160 when Constraint_Error =>
2165 & Get_Name_String (Attribute.Value.Value)
2166 & """ for Library_Auto_Init_Supported",
2167 Attribute.Value.Location);
2170 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2171 List := Attribute.Value.Values;
2173 if List /= Nil_String then
2174 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2176 In_Tree => In_Tree);
2179 elsif Attribute.Name = Name_Library_Version_Switches then
2180 List := Attribute.Value.Values;
2182 if List /= Nil_String then
2183 Put (Into_List => Project.Config.Lib_Version_Options,
2185 In_Tree => In_Tree);
2190 Attribute_Id := Attribute.Next;
2192 end Process_Project_Level_Simple_Attributes;
2194 --------------------------------------------
2195 -- Process_Project_Level_Array_Attributes --
2196 --------------------------------------------
2198 procedure Process_Project_Level_Array_Attributes is
2199 Current_Array_Id : Array_Id;
2200 Current_Array : Array_Data;
2201 Element_Id : Array_Element_Id;
2202 Element : Array_Element;
2203 List : String_List_Id;
2206 -- Process the associative array attributes at project level
2208 Current_Array_Id := Project.Decl.Arrays;
2209 while Current_Array_Id /= No_Array loop
2210 Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
2212 Element_Id := Current_Array.Value;
2213 while Element_Id /= No_Array_Element loop
2214 Element := In_Tree.Array_Elements.Table (Element_Id);
2216 -- Get the name of the language
2218 Get_Language_Index_Of (Element.Index);
2220 if Lang_Index /= No_Language_Index then
2221 case Current_Array.Name is
2222 when Name_Inherit_Source_Path =>
2223 List := Element.Value.Values;
2225 if List /= Nil_String then
2228 Lang_Index.Config.Include_Compatible_Languages,
2231 Lower_Case => True);
2234 when Name_Toolchain_Description =>
2236 -- Attribute Toolchain_Description (<language>)
2238 Lang_Index.Config.Toolchain_Description :=
2239 Element.Value.Value;
2241 when Name_Toolchain_Version =>
2243 -- Attribute Toolchain_Version (<language>)
2245 Lang_Index.Config.Toolchain_Version :=
2246 Element.Value.Value;
2248 when Name_Runtime_Library_Dir =>
2250 -- Attribute Runtime_Library_Dir (<language>)
2252 Lang_Index.Config.Runtime_Library_Dir :=
2253 Element.Value.Value;
2255 when Name_Runtime_Source_Dir =>
2257 -- Attribute Runtime_Library_Dir (<language>)
2259 Lang_Index.Config.Runtime_Source_Dir :=
2260 Element.Value.Value;
2262 when Name_Object_Generated =>
2264 pragma Unsuppress (All_Checks);
2270 (Get_Name_String (Element.Value.Value));
2272 Lang_Index.Config.Object_Generated := Value;
2274 -- If no object is generated, no object may be
2278 Lang_Index.Config.Objects_Linked := False;
2282 when Constraint_Error =>
2287 & Get_Name_String (Element.Value.Value)
2288 & """ for Object_Generated",
2289 Element.Value.Location);
2292 when Name_Objects_Linked =>
2294 pragma Unsuppress (All_Checks);
2300 (Get_Name_String (Element.Value.Value));
2302 -- No change if Object_Generated is False, as this
2303 -- forces Objects_Linked to be False too.
2305 if Lang_Index.Config.Object_Generated then
2306 Lang_Index.Config.Objects_Linked := Value;
2310 when Constraint_Error =>
2315 & Get_Name_String (Element.Value.Value)
2316 & """ for Objects_Linked",
2317 Element.Value.Location);
2324 Element_Id := Element.Next;
2327 Current_Array_Id := Current_Array.Next;
2329 end Process_Project_Level_Array_Attributes;
2332 Process_Project_Level_Simple_Attributes;
2333 Process_Project_Level_Array_Attributes;
2336 -- For unit based languages, set Casing, Dot_Replacement and
2337 -- Separate_Suffix in Naming_Data.
2339 Lang_Index := Project.Languages;
2340 while Lang_Index /= No_Language_Index loop
2341 if Lang_Index.Name = Name_Ada then
2342 Lang_Index.Config.Naming_Data.Casing := Casing;
2343 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2345 if Separate_Suffix /= No_File then
2346 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2353 Lang_Index := Lang_Index.Next;
2356 -- Give empty names to various prefixes/suffixes, if they have not
2357 -- been specified in the configuration.
2359 if Project.Config.Archive_Suffix = No_File then
2360 Project.Config.Archive_Suffix := Empty_File;
2363 if Project.Config.Shared_Lib_Prefix = No_File then
2364 Project.Config.Shared_Lib_Prefix := Empty_File;
2367 if Project.Config.Shared_Lib_Suffix = No_File then
2368 Project.Config.Shared_Lib_Suffix := Empty_File;
2371 Lang_Index := Project.Languages;
2372 while Lang_Index /= No_Language_Index loop
2373 Current_Language := Lang_Index.Display_Name;
2375 -- For all languages, Compiler_Driver needs to be specified. This is
2376 -- only necessary if we do intend to compiler (not in GPS for
2379 if Compiler_Driver_Mandatory
2380 and then Lang_Index.Config.Compiler_Driver = No_File
2382 Error_Msg_Name_1 := Current_Language;
2386 "?no compiler specified for language %%" &
2387 ", ignoring all its sources",
2390 if Lang_Index = Project.Languages then
2391 Project.Languages := Lang_Index.Next;
2393 Prev_Index.Next := Lang_Index.Next;
2396 elsif Lang_Index.Name = Name_Ada then
2397 Prev_Index := Lang_Index;
2399 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2400 -- Body_Suffix need to be specified.
2402 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2406 "Dot_Replacement not specified for Ada",
2410 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2414 "Spec_Suffix not specified for Ada",
2418 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2422 "Body_Suffix not specified for Ada",
2427 Prev_Index := Lang_Index;
2429 -- For file based languages, either Spec_Suffix or Body_Suffix
2430 -- need to be specified.
2432 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File and then
2433 Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2435 Error_Msg_Name_1 := Current_Language;
2439 "no suffixes specified for %%",
2444 Lang_Index := Lang_Index.Next;
2446 end Check_Configuration;
2448 -------------------------------
2449 -- Check_If_Externally_Built --
2450 -------------------------------
2452 procedure Check_If_Externally_Built
2453 (Project : Project_Id;
2454 In_Tree : Project_Tree_Ref)
2456 Externally_Built : constant Variable_Value :=
2458 (Name_Externally_Built,
2459 Project.Decl.Attributes, In_Tree);
2462 if not Externally_Built.Default then
2463 Get_Name_String (Externally_Built.Value);
2464 To_Lower (Name_Buffer (1 .. Name_Len));
2466 if Name_Buffer (1 .. Name_Len) = "true" then
2467 Project.Externally_Built := True;
2469 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2470 Error_Msg (Project, In_Tree,
2471 "Externally_Built may only be true or false",
2472 Externally_Built.Location);
2476 -- A virtual project extending an externally built project is itself
2477 -- externally built.
2479 if Project.Virtual and then Project.Extends /= No_Project then
2480 Project.Externally_Built := Project.Extends.Externally_Built;
2483 if Current_Verbosity = High then
2484 Write_Str ("Project is ");
2486 if not Project.Externally_Built then
2490 Write_Line ("externally built.");
2492 end Check_If_Externally_Built;
2494 ----------------------
2495 -- Check_Interfaces --
2496 ----------------------
2498 procedure Check_Interfaces
2499 (Project : Project_Id;
2500 In_Tree : Project_Tree_Ref)
2502 Interfaces : constant Prj.Variable_Value :=
2504 (Snames.Name_Interfaces,
2505 Project.Decl.Attributes,
2508 List : String_List_Id;
2509 Element : String_Element;
2510 Name : File_Name_Type;
2511 Iter : Source_Iterator;
2513 Project_2 : Project_Id;
2516 if not Interfaces.Default then
2518 -- Set In_Interfaces to False for all sources. It will be set to True
2519 -- later for the sources in the Interfaces list.
2521 Project_2 := Project;
2522 while Project_2 /= No_Project loop
2523 Iter := For_Each_Source (In_Tree, Project_2);
2526 Source := Prj.Element (Iter);
2527 exit when Source = No_Source;
2528 Source.In_Interfaces := False;
2532 Project_2 := Project_2.Extends;
2535 List := Interfaces.Values;
2536 while List /= Nil_String loop
2537 Element := In_Tree.String_Elements.Table (List);
2538 Name := Canonical_Case_File_Name (Element.Value);
2540 Project_2 := Project;
2542 while Project_2 /= No_Project loop
2543 Iter := For_Each_Source (In_Tree, Project_2);
2546 Source := Prj.Element (Iter);
2547 exit when Source = No_Source;
2549 if Source.File = Name then
2550 if not Source.Locally_Removed then
2551 Source.In_Interfaces := True;
2552 Source.Declared_In_Interfaces := True;
2554 if Source.Other_Part /= No_Source then
2555 Source.Other_Part.In_Interfaces := True;
2556 Source.Other_Part.Declared_In_Interfaces := True;
2559 if Current_Verbosity = High then
2560 Write_Str (" interface: ");
2561 Write_Line (Get_Name_String (Source.Path.Name));
2571 Project_2 := Project_2.Extends;
2574 if Source = No_Source then
2575 Error_Msg_File_1 := File_Name_Type (Element.Value);
2576 Error_Msg_Name_1 := Project.Name;
2581 "{ cannot be an interface of project %% "
2582 & "as it is not one of its sources",
2586 List := Element.Next;
2589 Project.Interfaces_Defined := True;
2591 elsif Project.Extends /= No_Project then
2592 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2594 if Project.Interfaces_Defined then
2595 Iter := For_Each_Source (In_Tree, Project);
2597 Source := Prj.Element (Iter);
2598 exit when Source = No_Source;
2600 if not Source.Declared_In_Interfaces then
2601 Source.In_Interfaces := False;
2608 end Check_Interfaces;
2610 ------------------------------------
2611 -- Check_And_Normalize_Unit_Names --
2612 ------------------------------------
2614 procedure Check_And_Normalize_Unit_Names
2615 (Project : Project_Id;
2616 In_Tree : Project_Tree_Ref;
2617 List : Array_Element_Id;
2618 Debug_Name : String)
2620 Current : Array_Element_Id;
2621 Element : Array_Element;
2622 Unit_Name : Name_Id;
2625 if Current_Verbosity = High then
2626 Write_Line (" Checking unit names in " & Debug_Name);
2630 while Current /= No_Array_Element loop
2631 Element := In_Tree.Array_Elements.Table (Current);
2632 Element.Value.Value :=
2633 Name_Id (Canonical_Case_File_Name (Element.Value.Value));
2635 -- Check that it contains a valid unit name
2637 Get_Name_String (Element.Index);
2638 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit_Name);
2640 if Unit_Name = No_Name then
2641 Err_Vars.Error_Msg_Name_1 := Element.Index;
2644 "%% is not a valid unit name.",
2645 Element.Value.Location);
2648 if Current_Verbosity = High then
2649 Write_Str (" for unit: ");
2650 Write_Line (Get_Name_String (Unit_Name));
2653 Element.Index := Unit_Name;
2654 In_Tree.Array_Elements.Table (Current) := Element;
2657 Current := Element.Next;
2659 end Check_And_Normalize_Unit_Names;
2661 --------------------------
2662 -- Check_Naming_Schemes --
2663 --------------------------
2665 procedure Check_Naming_Schemes
2666 (Project : Project_Id;
2667 In_Tree : Project_Tree_Ref;
2668 Is_Config_File : Boolean)
2670 Naming_Id : constant Package_Id :=
2671 Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
2672 Naming : Package_Element;
2674 procedure Check_Naming_Ada_Only;
2675 -- Does Check_Naming_Schemes processing in Ada_Only mode.
2676 -- If there is a package Naming, puts in Data.Naming the contents of
2679 procedure Check_Naming_Multi_Lang;
2680 -- Does Check_Naming_Schemes processing for Multi_Language mode
2682 procedure Check_Common
2683 (Dot_Replacement : in out File_Name_Type;
2684 Casing : in out Casing_Type;
2685 Casing_Defined : out Boolean;
2686 Separate_Suffix : in out File_Name_Type;
2687 Sep_Suffix_Loc : out Source_Ptr);
2688 -- Check attributes common to Ada_Only and Multi_Lang modes
2690 procedure Process_Exceptions_File_Based
2691 (Lang_Id : Language_Ptr;
2692 Kind : Source_Kind);
2693 procedure Process_Exceptions_Unit_Based
2694 (Lang_Id : Language_Ptr;
2695 Kind : Source_Kind);
2696 -- In Multi_Lang mode, process the naming exceptions for the two types
2697 -- of languages we can have.
2703 procedure Check_Common
2704 (Dot_Replacement : in out File_Name_Type;
2705 Casing : in out Casing_Type;
2706 Casing_Defined : out Boolean;
2707 Separate_Suffix : in out File_Name_Type;
2708 Sep_Suffix_Loc : out Source_Ptr)
2710 Dot_Repl : constant Variable_Value :=
2712 (Name_Dot_Replacement,
2713 Naming.Decl.Attributes,
2715 Casing_String : constant Variable_Value :=
2718 Naming.Decl.Attributes,
2720 Sep_Suffix : constant Variable_Value :=
2722 (Name_Separate_Suffix,
2723 Naming.Decl.Attributes,
2725 Dot_Repl_Loc : Source_Ptr;
2728 Sep_Suffix_Loc := No_Location;
2730 if not Dot_Repl.Default then
2732 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2734 if Length_Of_Name (Dot_Repl.Value) = 0 then
2737 "Dot_Replacement cannot be empty",
2741 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2742 Dot_Repl_Loc := Dot_Repl.Location;
2745 Repl : constant String := Get_Name_String (Dot_Replacement);
2748 -- Dot_Replacement cannot
2750 -- - start or end with an alphanumeric
2751 -- - be a single '_'
2752 -- - start with an '_' followed by an alphanumeric
2753 -- - contain a '.' except if it is "."
2756 or else Is_Alphanumeric (Repl (Repl'First))
2757 or else Is_Alphanumeric (Repl (Repl'Last))
2758 or else (Repl (Repl'First) = '_'
2762 Is_Alphanumeric (Repl (Repl'First + 1))))
2763 or else (Repl'Length > 1
2765 Index (Source => Repl, Pattern => ".") /= 0)
2770 """ is illegal for Dot_Replacement.",
2776 if Dot_Replacement /= No_File then
2778 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2781 Casing_Defined := False;
2783 if not Casing_String.Default then
2785 (Casing_String.Kind = Single, "Casing is not a string");
2788 Casing_Image : constant String :=
2789 Get_Name_String (Casing_String.Value);
2791 if Casing_Image'Length = 0 then
2794 "Casing cannot be an empty string",
2795 Casing_String.Location);
2798 Casing := Value (Casing_Image);
2799 Casing_Defined := True;
2802 when Constraint_Error =>
2803 Name_Len := Casing_Image'Length;
2804 Name_Buffer (1 .. Name_Len) := Casing_Image;
2805 Err_Vars.Error_Msg_Name_1 := Name_Find;
2808 "%% is not a correct Casing",
2809 Casing_String.Location);
2813 Write_Attr ("Casing", Image (Casing));
2815 if not Sep_Suffix.Default then
2816 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2819 "Separate_Suffix cannot be empty",
2820 Sep_Suffix.Location);
2823 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2824 Sep_Suffix_Loc := Sep_Suffix.Location;
2826 if Is_Illegal_Suffix (Separate_Suffix, Dot_Replacement) then
2827 Err_Vars.Error_Msg_File_1 := Separate_Suffix;
2830 "{ is illegal for Separate_Suffix",
2831 Sep_Suffix.Location);
2836 if Separate_Suffix /= No_File then
2838 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2842 -----------------------------------
2843 -- Process_Exceptions_File_Based --
2844 -----------------------------------
2846 procedure Process_Exceptions_File_Based
2847 (Lang_Id : Language_Ptr;
2850 Lang : constant Name_Id := Lang_Id.Name;
2851 Exceptions : Array_Element_Id;
2852 Exception_List : Variable_Value;
2853 Element_Id : String_List_Id;
2854 Element : String_Element;
2855 File_Name : File_Name_Type;
2857 Iter : Source_Iterator;
2864 (Name_Implementation_Exceptions,
2865 In_Arrays => Naming.Decl.Arrays,
2866 In_Tree => In_Tree);
2871 (Name_Specification_Exceptions,
2872 In_Arrays => Naming.Decl.Arrays,
2873 In_Tree => In_Tree);
2876 Exception_List := Value_Of
2878 In_Array => Exceptions,
2879 In_Tree => In_Tree);
2881 if Exception_List /= Nil_Variable_Value then
2882 Element_Id := Exception_List.Values;
2883 while Element_Id /= Nil_String loop
2884 Element := In_Tree.String_Elements.Table (Element_Id);
2885 File_Name := Canonical_Case_File_Name (Element.Value);
2887 Iter := For_Each_Source (In_Tree, Project);
2889 Source := Prj.Element (Iter);
2890 exit when Source = No_Source or else Source.File = File_Name;
2894 if Source = No_Source then
2901 File_Name => File_Name,
2902 Display_File => File_Name_Type (Element.Value),
2903 Naming_Exception => True,
2904 Lang_Kind => File_Based);
2907 -- Check if the file name is already recorded for another
2908 -- language or another kind.
2910 if Source.Language /= Lang_Id then
2914 "the same file cannot be a source of two languages",
2917 elsif Source.Kind /= Kind then
2921 "the same file cannot be a source and a template",
2925 -- If the file is already recorded for the same
2926 -- language and the same kind, it means that the file
2927 -- name appears several times in the *_Exceptions
2928 -- attribute; so there is nothing to do.
2931 Element_Id := Element.Next;
2934 end Process_Exceptions_File_Based;
2936 -----------------------------------
2937 -- Process_Exceptions_Unit_Based --
2938 -----------------------------------
2940 procedure Process_Exceptions_Unit_Based
2941 (Lang_Id : Language_Ptr;
2944 Lang : constant Name_Id := Lang_Id.Name;
2945 Exceptions : Array_Element_Id;
2946 Element : Array_Element;
2949 File_Name : File_Name_Type;
2951 Source_To_Replace : Source_Id := No_Source;
2952 Other_Project : Project_Id;
2953 Other_Part : Source_Id := No_Source;
2954 Iter : Source_Iterator;
2959 Exceptions := Value_Of
2961 In_Arrays => Naming.Decl.Arrays,
2962 In_Tree => In_Tree);
2964 if Exceptions = No_Array_Element then
2967 (Name_Implementation,
2968 In_Arrays => Naming.Decl.Arrays,
2969 In_Tree => In_Tree);
2976 In_Arrays => Naming.Decl.Arrays,
2977 In_Tree => In_Tree);
2979 if Exceptions = No_Array_Element then
2980 Exceptions := Value_Of
2982 In_Arrays => Naming.Decl.Arrays,
2983 In_Tree => In_Tree);
2987 while Exceptions /= No_Array_Element loop
2988 Element := In_Tree.Array_Elements.Table (Exceptions);
2989 File_Name := Canonical_Case_File_Name (Element.Value.Value);
2991 Get_Name_String (Element.Index);
2992 To_Lower (Name_Buffer (1 .. Name_Len));
2994 Index := Element.Value.Index;
2996 -- For Ada, check if it is a valid unit name
2998 if Lang = Name_Ada then
2999 Get_Name_String (Element.Index);
3000 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
3002 if Unit = No_Name then
3003 Err_Vars.Error_Msg_Name_1 := Element.Index;
3006 "%% is not a valid unit name.",
3007 Element.Value.Location);
3011 if Unit /= No_Name then
3013 -- Check if the source already exists
3015 Source_To_Replace := No_Source;
3016 Iter := For_Each_Source (In_Tree);
3019 Source := Prj.Element (Iter);
3020 exit when Source = No_Source
3021 or else (Source.Unit = Unit and then Source.Index = Index);
3025 if Source /= No_Source then
3026 if Source.Kind /= Kind then
3027 Other_Part := Source;
3031 Source := Prj.Element (Iter);
3033 exit when Source = No_Source or else
3034 (Source.Unit = Unit and then Source.Index = Index);
3038 if Source /= No_Source then
3039 Other_Project := Source.Project;
3041 if Is_Extending (Project, Other_Project) then
3042 Other_Part := Source.Other_Part;
3044 -- Record the source to be removed
3046 Source_To_Replace := Source;
3047 Source := No_Source;
3050 Error_Msg_Name_1 := Unit;
3051 Error_Msg_Name_2 := Other_Project.Name;
3055 "%% is already a source of project %%",
3056 Element.Value.Location);
3061 if Source = No_Source then
3068 File_Name => File_Name,
3069 Display_File => File_Name_Type (Element.Value.Value),
3070 Lang_Kind => Unit_Based,
3071 Other_Part => Other_Part,
3074 Naming_Exception => True,
3075 Source_To_Replace => Source_To_Replace);
3079 Exceptions := Element.Next;
3081 end Process_Exceptions_Unit_Based;
3083 ---------------------------
3084 -- Check_Naming_Ada_Only --
3085 ---------------------------
3087 procedure Check_Naming_Ada_Only is
3088 Casing_Defined : Boolean;
3089 Spec_Suffix : File_Name_Type;
3090 Body_Suffix : File_Name_Type;
3091 Sep_Suffix_Loc : Source_Ptr;
3093 Ada_Spec_Suffix : constant Variable_Value :=
3097 In_Array => Project.Naming.Spec_Suffix,
3098 In_Tree => In_Tree);
3100 Ada_Body_Suffix : constant Variable_Value :=
3104 In_Array => Project.Naming.Body_Suffix,
3105 In_Tree => In_Tree);
3108 -- The default value of separate suffix should be the same as the
3109 -- body suffix, so we need to compute that first.
3111 if Ada_Body_Suffix.Kind = Single
3112 and then Length_Of_Name (Ada_Body_Suffix.Value) /= 0
3114 Body_Suffix := Canonical_Case_File_Name (Ada_Body_Suffix.Value);
3115 Project.Naming.Separate_Suffix := Body_Suffix;
3116 Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
3119 Body_Suffix := Default_Ada_Body_Suffix;
3120 Project.Naming.Separate_Suffix := Body_Suffix;
3121 Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
3124 Write_Attr ("Body_Suffix", Get_Name_String (Body_Suffix));
3126 -- We'll need the dot replacement below, so compute it now
3129 (Dot_Replacement => Project.Naming.Dot_Replacement,
3130 Casing => Project.Naming.Casing,
3131 Casing_Defined => Casing_Defined,
3132 Separate_Suffix => Project.Naming.Separate_Suffix,
3133 Sep_Suffix_Loc => Sep_Suffix_Loc);
3135 Project.Naming.Bodies :=
3136 Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
3138 if Project.Naming.Bodies /= No_Array_Element then
3139 Check_And_Normalize_Unit_Names
3140 (Project, In_Tree, Project.Naming.Bodies, "Naming.Bodies");
3143 Project.Naming.Specs :=
3144 Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
3146 if Project.Naming.Specs /= No_Array_Element then
3147 Check_And_Normalize_Unit_Names
3148 (Project, In_Tree, Project.Naming.Specs, "Naming.Specs");
3151 -- Check Spec_Suffix
3153 if Ada_Spec_Suffix.Kind = Single
3154 and then Length_Of_Name (Ada_Spec_Suffix.Value) /= 0
3156 Spec_Suffix := Canonical_Case_File_Name (Ada_Spec_Suffix.Value);
3157 Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
3159 if Is_Illegal_Suffix
3160 (Spec_Suffix, Project.Naming.Dot_Replacement)
3162 Err_Vars.Error_Msg_File_1 := Spec_Suffix;
3165 "{ is illegal for Spec_Suffix",
3166 Ada_Spec_Suffix.Location);
3170 Spec_Suffix := Default_Ada_Spec_Suffix;
3171 Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
3174 Write_Attr ("Spec_Suffix", Get_Name_String (Spec_Suffix));
3176 -- Check Body_Suffix
3178 if Is_Illegal_Suffix
3179 (Body_Suffix, Project.Naming.Dot_Replacement)
3181 Err_Vars.Error_Msg_File_1 := Body_Suffix;
3184 "{ is illegal for Body_Suffix",
3185 Ada_Body_Suffix.Location);
3188 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3189 -- since that would cause a clear ambiguity. Note that we do allow a
3190 -- Spec_Suffix to have the same termination as one of these, which
3191 -- causes a potential ambiguity, but we resolve that my matching the
3192 -- longest possible suffix.
3194 if Spec_Suffix = Body_Suffix then
3198 Get_Name_String (Body_Suffix) &
3199 """) cannot be the same as Spec_Suffix.",
3200 Ada_Body_Suffix.Location);
3203 if Body_Suffix /= Project.Naming.Separate_Suffix
3204 and then Spec_Suffix = Project.Naming.Separate_Suffix
3208 "Separate_Suffix (""" &
3209 Get_Name_String (Project.Naming.Separate_Suffix) &
3210 """) cannot be the same as Spec_Suffix.",
3213 end Check_Naming_Ada_Only;
3215 -----------------------------
3216 -- Check_Naming_Multi_Lang --
3217 -----------------------------
3219 procedure Check_Naming_Multi_Lang is
3220 Dot_Replacement : File_Name_Type := No_File;
3221 Separate_Suffix : File_Name_Type := No_File;
3222 Casing : Casing_Type := All_Lower_Case;
3223 Casing_Defined : Boolean;
3224 Lang_Id : Language_Ptr;
3225 Sep_Suffix_Loc : Source_Ptr;
3226 Suffix : Variable_Value;
3231 (Dot_Replacement => Dot_Replacement,
3233 Casing_Defined => Casing_Defined,
3234 Separate_Suffix => Separate_Suffix,
3235 Sep_Suffix_Loc => Sep_Suffix_Loc);
3237 -- For all unit based languages, if any, set the specified
3238 -- value of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3239 -- systematically overwrite, since the defaults come from the
3240 -- configuration file
3242 if Dot_Replacement /= No_File
3243 or else Casing_Defined
3244 or else Separate_Suffix /= No_File
3246 Lang_Id := Project.Languages;
3247 while Lang_Id /= No_Language_Index loop
3248 if Lang_Id.Config.Kind = Unit_Based then
3249 if Dot_Replacement /= No_File then
3250 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3254 if Casing_Defined then
3255 Lang_Id.Config.Naming_Data.Casing := Casing;
3258 if Separate_Suffix /= No_File then
3259 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3264 Lang_Id := Lang_Id.Next;
3268 -- Next, get the spec and body suffixes
3270 Lang_Id := Project.Languages;
3271 while Lang_Id /= No_Language_Index loop
3272 Lang := Lang_Id.Name;
3278 Attribute_Or_Array_Name => Name_Spec_Suffix,
3279 In_Package => Naming_Id,
3280 In_Tree => In_Tree);
3282 if Suffix = Nil_Variable_Value then
3285 Attribute_Or_Array_Name => Name_Spec_Suffix,
3286 In_Package => Naming_Id,
3287 In_Tree => In_Tree);
3290 if Suffix /= Nil_Variable_Value then
3291 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3292 File_Name_Type (Suffix.Value);
3299 Attribute_Or_Array_Name => Name_Body_Suffix,
3300 In_Package => Naming_Id,
3301 In_Tree => In_Tree);
3303 if Suffix = Nil_Variable_Value then
3306 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3307 In_Package => Naming_Id,
3308 In_Tree => In_Tree);
3311 if Suffix /= Nil_Variable_Value then
3312 Lang_Id.Config.Naming_Data.Body_Suffix :=
3313 File_Name_Type (Suffix.Value);
3316 -- ??? As opposed to what is done in Check_Naming_Ada_Only,
3317 -- we do not check whether spec_suffix=body_suffix, which
3318 -- should be illegal. Best would be to share this code into
3319 -- Check_Common, but we access the attributes from the project
3320 -- files slightly differently apparently.
3322 Lang_Id := Lang_Id.Next;
3325 -- Get the naming exceptions for all languages
3327 for Kind in Spec .. Impl loop
3328 Lang_Id := Project.Languages;
3329 while Lang_Id /= No_Language_Index loop
3330 case Lang_Id.Config.Kind is
3332 Process_Exceptions_File_Based (Lang_Id, Kind);
3335 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3338 Lang_Id := Lang_Id.Next;
3341 end Check_Naming_Multi_Lang;
3343 -- Start of processing for Check_Naming_Schemes
3346 -- No Naming package or parsing a configuration file? nothing to do
3348 if Naming_Id /= No_Package and not Is_Config_File then
3349 Naming := In_Tree.Packages.Table (Naming_Id);
3351 if Current_Verbosity = High then
3352 Write_Line ("Checking package Naming.");
3357 Check_Naming_Ada_Only;
3358 when Multi_Language =>
3359 Check_Naming_Multi_Lang;
3362 end Check_Naming_Schemes;
3364 ------------------------------
3365 -- Check_Library_Attributes --
3366 ------------------------------
3368 procedure Check_Library_Attributes
3369 (Project : Project_Id;
3370 In_Tree : Project_Tree_Ref)
3372 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3374 Lib_Dir : constant Prj.Variable_Value :=
3376 (Snames.Name_Library_Dir, Attributes, In_Tree);
3378 Lib_Name : constant Prj.Variable_Value :=
3380 (Snames.Name_Library_Name, Attributes, In_Tree);
3382 Lib_Version : constant Prj.Variable_Value :=
3384 (Snames.Name_Library_Version, Attributes, In_Tree);
3386 Lib_ALI_Dir : constant Prj.Variable_Value :=
3388 (Snames.Name_Library_Ali_Dir, Attributes, In_Tree);
3390 Lib_GCC : constant Prj.Variable_Value :=
3392 (Snames.Name_Library_GCC, Attributes, In_Tree);
3394 The_Lib_Kind : constant Prj.Variable_Value :=
3396 (Snames.Name_Library_Kind, Attributes, In_Tree);
3398 Imported_Project_List : Project_List;
3400 Continuation : String_Access := No_Continuation_String'Access;
3402 Support_For_Libraries : Library_Support;
3404 Library_Directory_Present : Boolean;
3406 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3407 -- Check if an imported or extended project if also a library project
3413 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3415 Iter : Source_Iterator;
3418 if Proj /= No_Project then
3419 if not Proj.Library then
3421 -- The only not library projects that are OK are those that
3422 -- have no sources. However, header files from non-Ada
3423 -- languages are OK, as there is nothing to compile.
3425 Iter := For_Each_Source (In_Tree, Proj);
3427 Src_Id := Prj.Element (Iter);
3428 exit when Src_Id = No_Source
3429 or else Src_Id.Lang_Kind /= File_Based
3430 or else Src_Id.Kind /= Spec;
3434 if Src_Id /= No_Source then
3435 Error_Msg_Name_1 := Project.Name;
3436 Error_Msg_Name_2 := Proj.Name;
3439 if Project.Library_Kind /= Static then
3443 "shared library project %% cannot extend " &
3444 "project %% that is not a library project",
3446 Continuation := Continuation_String'Access;
3449 elsif (not Unchecked_Shared_Lib_Imports)
3450 and then Project.Library_Kind /= Static
3455 "shared library project %% cannot import project %% " &
3456 "that is not a shared library project",
3458 Continuation := Continuation_String'Access;
3462 elsif Project.Library_Kind /= Static and then
3463 Proj.Library_Kind = Static
3465 Error_Msg_Name_1 := Project.Name;
3466 Error_Msg_Name_2 := Proj.Name;
3472 "shared library project %% cannot extend static " &
3473 "library project %%",
3475 Continuation := Continuation_String'Access;
3477 elsif not Unchecked_Shared_Lib_Imports then
3481 "shared library project %% cannot import static " &
3482 "library project %%",
3484 Continuation := Continuation_String'Access;
3491 Dir_Exists : Boolean;
3493 -- Start of processing for Check_Library_Attributes
3496 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3498 -- Special case of extending project
3500 if Project.Extends /= No_Project then
3502 -- If the project extended is a library project, we inherit the
3503 -- library name, if it is not redefined; we check that the library
3504 -- directory is specified.
3506 if Project.Extends.Library then
3507 if Project.Qualifier = Standard then
3510 "a standard project cannot extend a library project",
3514 if Lib_Name.Default then
3515 Project.Library_Name := Project.Extends.Library_Name;
3518 if Lib_Dir.Default then
3519 if not Project.Virtual then
3522 "a project extending a library project must " &
3523 "specify an attribute Library_Dir",
3527 -- For a virtual project extending a library project,
3528 -- inherit library directory.
3530 Project.Library_Dir := Project.Extends.Library_Dir;
3531 Library_Directory_Present := True;
3538 pragma Assert (Lib_Name.Kind = Single);
3540 if Lib_Name.Value = Empty_String then
3541 if Current_Verbosity = High
3542 and then Project.Library_Name = No_Name
3544 Write_Line ("No library name");
3548 -- There is no restriction on the syntax of library names
3550 Project.Library_Name := Lib_Name.Value;
3553 if Project.Library_Name /= No_Name then
3554 if Current_Verbosity = High then
3556 ("Library name", Get_Name_String (Project.Library_Name));
3559 pragma Assert (Lib_Dir.Kind = Single);
3561 if not Library_Directory_Present then
3562 if Current_Verbosity = High then
3563 Write_Line ("No library directory");
3567 -- Find path name (unless inherited), check that it is a directory
3569 if Project.Library_Dir = No_Path_Information then
3573 File_Name_Type (Lib_Dir.Value),
3574 Path => Project.Library_Dir,
3575 Dir_Exists => Dir_Exists,
3576 Create => "library",
3577 Must_Exist => False,
3578 Location => Lib_Dir.Location,
3579 Externally_Built => Project.Externally_Built);
3585 (Project.Library_Dir.Display_Name));
3588 if not Dir_Exists then
3589 -- Get the absolute name of the library directory that
3590 -- does not exist, to report an error.
3592 Err_Vars.Error_Msg_File_1 :=
3593 File_Name_Type (Project.Library_Dir.Display_Name);
3596 "library directory { does not exist",
3599 -- The library directory cannot be the same as the Object
3602 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3605 "library directory cannot be the same " &
3606 "as object directory",
3608 Project.Library_Dir := No_Path_Information;
3612 OK : Boolean := True;
3613 Dirs_Id : String_List_Id;
3614 Dir_Elem : String_Element;
3618 -- The library directory cannot be the same as a source
3619 -- directory of the current project.
3621 Dirs_Id := Project.Source_Dirs;
3622 while Dirs_Id /= Nil_String loop
3623 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3624 Dirs_Id := Dir_Elem.Next;
3626 if Project.Library_Dir.Name =
3627 Path_Name_Type (Dir_Elem.Value)
3629 Err_Vars.Error_Msg_File_1 :=
3630 File_Name_Type (Dir_Elem.Value);
3633 "library directory cannot be the same " &
3634 "as source directory {",
3643 -- The library directory cannot be the same as a source
3644 -- directory of another project either.
3646 Pid := In_Tree.Projects;
3648 exit Project_Loop when Pid = null;
3650 if Pid.Project /= Project then
3651 Dirs_Id := Pid.Project.Source_Dirs;
3653 Dir_Loop : while Dirs_Id /= Nil_String loop
3655 In_Tree.String_Elements.Table (Dirs_Id);
3656 Dirs_Id := Dir_Elem.Next;
3658 if Project.Library_Dir.Name =
3659 Path_Name_Type (Dir_Elem.Value)
3661 Err_Vars.Error_Msg_File_1 :=
3662 File_Name_Type (Dir_Elem.Value);
3663 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3667 "library directory cannot be the same " &
3668 "as source directory { of project %%",
3677 end loop Project_Loop;
3681 Project.Library_Dir := No_Path_Information;
3683 elsif Current_Verbosity = High then
3685 -- Display the Library directory in high verbosity
3688 ("Library directory",
3689 Get_Name_String (Project.Library_Dir.Display_Name));
3698 Project.Library_Dir /= No_Path_Information
3699 and then Project.Library_Name /= No_Name;
3701 if Project.Extends = No_Project then
3702 case Project.Qualifier is
3704 if Project.Library then
3707 "a standard project cannot be a library project",
3712 if not Project.Library then
3713 if Project.Library_Dir = No_Path_Information then
3716 "\attribute Library_Dir not declared",
3720 if Project.Library_Name = No_Name then
3723 "\attribute Library_Name not declared",
3734 if Project.Library then
3735 if Get_Mode = Multi_Language then
3736 Support_For_Libraries := Project.Config.Lib_Support;
3739 Support_For_Libraries := MLib.Tgt.Support_For_Libraries;
3742 if Support_For_Libraries = Prj.None then
3745 "?libraries are not supported on this platform",
3747 Project.Library := False;
3750 if Lib_ALI_Dir.Value = Empty_String then
3751 if Current_Verbosity = High then
3752 Write_Line ("No library ALI directory specified");
3755 Project.Library_ALI_Dir := Project.Library_Dir;
3758 -- Find path name, check that it is a directory
3763 File_Name_Type (Lib_ALI_Dir.Value),
3764 Path => Project.Library_ALI_Dir,
3765 Create => "library ALI",
3766 Dir_Exists => Dir_Exists,
3767 Must_Exist => False,
3768 Location => Lib_ALI_Dir.Location,
3769 Externally_Built => Project.Externally_Built);
3771 if not Dir_Exists then
3772 -- Get the absolute name of the library ALI directory that
3773 -- does not exist, to report an error.
3775 Err_Vars.Error_Msg_File_1 :=
3776 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3779 "library 'A'L'I directory { does not exist",
3780 Lib_ALI_Dir.Location);
3783 if Project.Library_ALI_Dir /= Project.Library_Dir then
3785 -- The library ALI directory cannot be the same as the
3786 -- Object directory.
3788 if Project.Library_ALI_Dir = Project.Object_Directory then
3791 "library 'A'L'I directory cannot be the same " &
3792 "as object directory",
3793 Lib_ALI_Dir.Location);
3794 Project.Library_ALI_Dir := No_Path_Information;
3798 OK : Boolean := True;
3799 Dirs_Id : String_List_Id;
3800 Dir_Elem : String_Element;
3804 -- The library ALI directory cannot be the same as
3805 -- a source directory of the current project.
3807 Dirs_Id := Project.Source_Dirs;
3808 while Dirs_Id /= Nil_String loop
3809 Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
3810 Dirs_Id := Dir_Elem.Next;
3812 if Project.Library_ALI_Dir.Name =
3813 Path_Name_Type (Dir_Elem.Value)
3815 Err_Vars.Error_Msg_File_1 :=
3816 File_Name_Type (Dir_Elem.Value);
3819 "library 'A'L'I directory cannot be " &
3820 "the same as source directory {",
3821 Lib_ALI_Dir.Location);
3829 -- The library ALI directory cannot be the same as
3830 -- a source directory of another project either.
3832 Pid := In_Tree.Projects;
3833 ALI_Project_Loop : loop
3834 exit ALI_Project_Loop when Pid = null;
3836 if Pid.Project /= Project then
3837 Dirs_Id := Pid.Project.Source_Dirs;
3840 while Dirs_Id /= Nil_String loop
3842 In_Tree.String_Elements.Table (Dirs_Id);
3843 Dirs_Id := Dir_Elem.Next;
3845 if Project.Library_ALI_Dir.Name =
3846 Path_Name_Type (Dir_Elem.Value)
3848 Err_Vars.Error_Msg_File_1 :=
3849 File_Name_Type (Dir_Elem.Value);
3850 Err_Vars.Error_Msg_Name_1 :=
3855 "library 'A'L'I directory cannot " &
3856 "be the same as source directory " &
3858 Lib_ALI_Dir.Location);
3860 exit ALI_Project_Loop;
3862 end loop ALI_Dir_Loop;
3865 end loop ALI_Project_Loop;
3869 Project.Library_ALI_Dir := No_Path_Information;
3871 elsif Current_Verbosity = High then
3873 -- Display the Library ALI directory in high
3879 (Project.Library_ALI_Dir.Display_Name));
3886 pragma Assert (Lib_Version.Kind = Single);
3888 if Lib_Version.Value = Empty_String then
3889 if Current_Verbosity = High then
3890 Write_Line ("No library version specified");
3894 Project.Lib_Internal_Name := Lib_Version.Value;
3897 pragma Assert (The_Lib_Kind.Kind = Single);
3899 if The_Lib_Kind.Value = Empty_String then
3900 if Current_Verbosity = High then
3901 Write_Line ("No library kind specified");
3905 Get_Name_String (The_Lib_Kind.Value);
3908 Kind_Name : constant String :=
3909 To_Lower (Name_Buffer (1 .. Name_Len));
3911 OK : Boolean := True;
3914 if Kind_Name = "static" then
3915 Project.Library_Kind := Static;
3917 elsif Kind_Name = "dynamic" then
3918 Project.Library_Kind := Dynamic;
3920 elsif Kind_Name = "relocatable" then
3921 Project.Library_Kind := Relocatable;
3926 "illegal value for Library_Kind",
3927 The_Lib_Kind.Location);
3931 if Current_Verbosity = High and then OK then
3932 Write_Attr ("Library kind", Kind_Name);
3935 if Project.Library_Kind /= Static then
3936 if Support_For_Libraries = Prj.Static_Only then
3939 "only static libraries are supported " &
3941 The_Lib_Kind.Location);
3942 Project.Library := False;
3945 -- Check if (obsolescent) attribute Library_GCC or
3946 -- Linker'Driver is declared.
3948 if Lib_GCC.Value /= Empty_String then
3952 "?Library_'G'C'C is an obsolescent attribute, " &
3953 "use Linker''Driver instead",
3955 Project.Config.Shared_Lib_Driver :=
3956 File_Name_Type (Lib_GCC.Value);
3960 Linker : constant Package_Id :=
3963 Project.Decl.Packages,
3965 Driver : constant Variable_Value :=
3968 Attribute_Or_Array_Name =>
3970 In_Package => Linker,
3975 if Driver /= Nil_Variable_Value
3976 and then Driver.Value /= Empty_String
3978 Project.Config.Shared_Lib_Driver :=
3979 File_Name_Type (Driver.Value);
3988 if Project.Library then
3989 if Current_Verbosity = High then
3990 Write_Line ("This is a library project file");
3993 if Get_Mode = Multi_Language then
3994 Check_Library (Project.Extends, Extends => True);
3996 Imported_Project_List := Project.Imported_Projects;
3997 while Imported_Project_List /= null loop
3999 (Imported_Project_List.Project,
4001 Imported_Project_List := Imported_Project_List.Next;
4009 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4010 -- Warn if they are declared, as it is a common error to think that
4011 -- library are "linked" with Linker switches.
4013 if Project.Library then
4015 Linker_Package_Id : constant Package_Id :=
4018 Project.Decl.Packages, In_Tree);
4019 Linker_Package : Package_Element;
4020 Switches : Array_Element_Id := No_Array_Element;
4023 if Linker_Package_Id /= No_Package then
4024 Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
4028 (Name => Name_Switches,
4029 In_Arrays => Linker_Package.Decl.Arrays,
4030 In_Tree => In_Tree);
4032 if Switches = No_Array_Element then
4035 (Name => Name_Default_Switches,
4036 In_Arrays => Linker_Package.Decl.Arrays,
4037 In_Tree => In_Tree);
4040 if Switches /= No_Array_Element then
4043 "?Linker switches not taken into account in library " &
4051 if Project.Extends /= No_Project then
4052 Project.Extends.Library := False;
4054 end Check_Library_Attributes;
4056 --------------------------
4057 -- Check_Package_Naming --
4058 --------------------------
4060 procedure Check_Package_Naming
4061 (Project : Project_Id;
4062 In_Tree : Project_Tree_Ref)
4064 Naming_Id : constant Package_Id :=
4065 Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
4067 Naming : Package_Element;
4070 -- If there is a package Naming, we will put in Data.Naming
4071 -- what is in this package Naming.
4073 if Naming_Id /= No_Package then
4074 Naming := In_Tree.Packages.Table (Naming_Id);
4076 if Current_Verbosity = High then
4077 Write_Line ("Checking ""Naming"".");
4080 -- Check Spec_Suffix
4083 Spec_Suffixs : Array_Element_Id :=
4089 Suffix : Array_Element_Id;
4090 Element : Array_Element;
4091 Suffix2 : Array_Element_Id;
4094 -- If some suffixes have been specified, we make sure that
4095 -- for each language for which a default suffix has been
4096 -- specified, there is a suffix specified, either the one
4097 -- in the project file or if there were none, the default.
4099 if Spec_Suffixs /= No_Array_Element then
4100 Suffix := Project.Naming.Spec_Suffix;
4102 while Suffix /= No_Array_Element loop
4104 In_Tree.Array_Elements.Table (Suffix);
4105 Suffix2 := Spec_Suffixs;
4107 while Suffix2 /= No_Array_Element loop
4108 exit when In_Tree.Array_Elements.Table
4109 (Suffix2).Index = Element.Index;
4110 Suffix2 := In_Tree.Array_Elements.Table
4114 -- There is a registered default suffix, but no
4115 -- suffix specified in the project file.
4116 -- Add the default to the array.
4118 if Suffix2 = No_Array_Element then
4119 Array_Element_Table.Increment_Last
4120 (In_Tree.Array_Elements);
4121 In_Tree.Array_Elements.Table
4122 (Array_Element_Table.Last
4123 (In_Tree.Array_Elements)) :=
4124 (Index => Element.Index,
4125 Src_Index => Element.Src_Index,
4126 Index_Case_Sensitive => False,
4127 Value => Element.Value,
4128 Next => Spec_Suffixs);
4129 Spec_Suffixs := Array_Element_Table.Last
4130 (In_Tree.Array_Elements);
4133 Suffix := Element.Next;
4136 -- Put the resulting array as the Spec suffixes
4138 Project.Naming.Spec_Suffix := Spec_Suffixs;
4142 -- Check Body_Suffix
4145 Impl_Suffixs : Array_Element_Id :=
4151 Suffix : Array_Element_Id;
4152 Element : Array_Element;
4153 Suffix2 : Array_Element_Id;
4156 -- If some suffixes have been specified, we make sure that
4157 -- for each language for which a default suffix has been
4158 -- specified, there is a suffix specified, either the one
4159 -- in the project file or if there were none, the default.
4161 if Impl_Suffixs /= No_Array_Element then
4162 Suffix := Project.Naming.Body_Suffix;
4163 while Suffix /= No_Array_Element loop
4165 In_Tree.Array_Elements.Table (Suffix);
4167 Suffix2 := Impl_Suffixs;
4168 while Suffix2 /= No_Array_Element loop
4169 exit when In_Tree.Array_Elements.Table
4170 (Suffix2).Index = Element.Index;
4171 Suffix2 := In_Tree.Array_Elements.Table
4175 -- There is a registered default suffix, but no suffix was
4176 -- specified in the project file. Add default to the array.
4178 if Suffix2 = No_Array_Element then
4179 Array_Element_Table.Increment_Last
4180 (In_Tree.Array_Elements);
4181 In_Tree.Array_Elements.Table
4182 (Array_Element_Table.Last
4183 (In_Tree.Array_Elements)) :=
4184 (Index => Element.Index,
4185 Src_Index => Element.Src_Index,
4186 Index_Case_Sensitive => False,
4187 Value => Element.Value,
4188 Next => Impl_Suffixs);
4189 Impl_Suffixs := Array_Element_Table.Last
4190 (In_Tree.Array_Elements);
4193 Suffix := Element.Next;
4196 -- Put the resulting array as the implementation suffixes
4198 Project.Naming.Body_Suffix := Impl_Suffixs;
4202 -- Get the exceptions, if any
4204 Project.Naming.Specification_Exceptions :=
4206 (Name_Specification_Exceptions,
4207 In_Arrays => Naming.Decl.Arrays,
4208 In_Tree => In_Tree);
4210 Project.Naming.Implementation_Exceptions :=
4212 (Name_Implementation_Exceptions,
4213 In_Arrays => Naming.Decl.Arrays,
4214 In_Tree => In_Tree);
4216 end Check_Package_Naming;
4218 ---------------------------------
4219 -- Check_Programming_Languages --
4220 ---------------------------------
4222 procedure Check_Programming_Languages
4223 (In_Tree : Project_Tree_Ref;
4224 Project : Project_Id)
4226 Languages : Variable_Value := Nil_Variable_Value;
4227 Def_Lang : Variable_Value := Nil_Variable_Value;
4228 Def_Lang_Id : Name_Id;
4231 Project.Languages := No_Language_Index;
4233 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, In_Tree);
4236 (Name_Default_Language, Project.Decl.Attributes, In_Tree);
4238 -- Shouldn't these be set to False by default, and only set to True when
4239 -- we actually find some source file???
4241 if Project.Source_Dirs /= Nil_String then
4243 -- Check if languages are specified in this project
4245 if Languages.Default then
4247 -- In Ada_Only mode, the default language is Ada
4249 if Get_Mode = Ada_Only then
4250 Def_Lang_Id := Name_Ada;
4253 -- Fail if there is no default language defined
4255 if Def_Lang.Default then
4256 if not Default_Language_Is_Ada then
4260 "no languages defined for this project",
4262 Def_Lang_Id := No_Name;
4264 Def_Lang_Id := Name_Ada;
4268 Get_Name_String (Def_Lang.Value);
4269 To_Lower (Name_Buffer (1 .. Name_Len));
4270 Def_Lang_Id := Name_Find;
4274 if Def_Lang_Id /= No_Name then
4275 Project.Languages := new Language_Data'(No_Language_Data);
4276 Project.Languages.Name := Def_Lang_Id;
4277 Get_Name_String (Def_Lang_Id);
4278 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4279 Project.Languages.Display_Name := Name_Find;
4281 if Def_Lang_Id = Name_Ada then
4282 Project.Languages.Config.Kind := Unit_Based;
4283 Project.Languages.Config.Dependency_Kind := ALI_File;
4285 Project.Languages.Config.Kind := File_Based;
4291 Current : String_List_Id := Languages.Values;
4292 Element : String_Element;
4293 Lang_Name : Name_Id;
4294 Index : Language_Ptr;
4295 NL_Id : Language_Ptr;
4298 -- If there are no languages declared, there are no sources
4300 if Current = Nil_String then
4301 Project.Source_Dirs := Nil_String;
4303 if Project.Qualifier = Standard then
4307 "a standard project must have at least one language",
4308 Languages.Location);
4312 -- Look through all the languages specified in attribute
4315 while Current /= Nil_String loop
4316 Element := In_Tree.String_Elements.Table (Current);
4317 Get_Name_String (Element.Value);
4318 To_Lower (Name_Buffer (1 .. Name_Len));
4319 Lang_Name := Name_Find;
4321 -- If the language was not already specified (duplicates
4322 -- are simply ignored).
4324 NL_Id := Project.Languages;
4325 while NL_Id /= No_Language_Index loop
4326 exit when Lang_Name = NL_Id.Name;
4327 NL_Id := NL_Id.Next;
4330 if NL_Id = No_Language_Index then
4331 Index := new Language_Data'(No_Language_Data);
4332 Index.Name := Lang_Name;
4333 Index.Display_Name := Element.Value;
4334 Index.Next := Project.Languages;
4336 if Lang_Name = Name_Ada then
4337 Index.Config.Kind := Unit_Based;
4338 Index.Config.Dependency_Kind := ALI_File;
4341 Index.Config.Kind := File_Based;
4342 Index.Config.Dependency_Kind := None;
4345 Project.Languages := Index;
4348 Current := Element.Next;
4354 end Check_Programming_Languages;
4360 function Check_Project
4362 Root_Project : Project_Id;
4363 Extending : Boolean) return Boolean
4367 if P = Root_Project then
4370 elsif Extending then
4371 Prj := Root_Project;
4372 while Prj.Extends /= No_Project loop
4373 if P = Prj.Extends then
4384 -------------------------------
4385 -- Check_Stand_Alone_Library --
4386 -------------------------------
4388 procedure Check_Stand_Alone_Library
4389 (Project : Project_Id;
4390 In_Tree : Project_Tree_Ref;
4391 Current_Dir : String;
4392 Extending : Boolean)
4394 Lib_Interfaces : constant Prj.Variable_Value :=
4396 (Snames.Name_Library_Interface,
4397 Project.Decl.Attributes,
4400 Lib_Auto_Init : constant Prj.Variable_Value :=
4402 (Snames.Name_Library_Auto_Init,
4403 Project.Decl.Attributes,
4406 Lib_Src_Dir : constant Prj.Variable_Value :=
4408 (Snames.Name_Library_Src_Dir,
4409 Project.Decl.Attributes,
4412 Lib_Symbol_File : constant Prj.Variable_Value :=
4414 (Snames.Name_Library_Symbol_File,
4415 Project.Decl.Attributes,
4418 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4420 (Snames.Name_Library_Symbol_Policy,
4421 Project.Decl.Attributes,
4424 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4426 (Snames.Name_Library_Reference_Symbol_File,
4427 Project.Decl.Attributes,
4430 Auto_Init_Supported : Boolean;
4431 OK : Boolean := True;
4433 Next_Proj : Project_Id;
4434 Iter : Source_Iterator;
4437 if Get_Mode = Multi_Language then
4438 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4440 Auto_Init_Supported :=
4441 MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported;
4444 pragma Assert (Lib_Interfaces.Kind = List);
4446 -- It is a stand-alone library project file if attribute
4447 -- Library_Interface is defined.
4449 if not Lib_Interfaces.Default then
4450 SAL_Library : declare
4451 Interfaces : String_List_Id := Lib_Interfaces.Values;
4452 Interface_ALIs : String_List_Id := Nil_String;
4454 The_Unit_Id : Unit_Index;
4457 procedure Add_ALI_For (Source : File_Name_Type);
4458 -- Add an ALI file name to the list of Interface ALIs
4464 procedure Add_ALI_For (Source : File_Name_Type) is
4466 Get_Name_String (Source);
4469 ALI : constant String :=
4470 ALI_File_Name (Name_Buffer (1 .. Name_Len));
4471 ALI_Name_Id : Name_Id;
4474 Name_Len := ALI'Length;
4475 Name_Buffer (1 .. Name_Len) := ALI;
4476 ALI_Name_Id := Name_Find;
4478 String_Element_Table.Increment_Last
4479 (In_Tree.String_Elements);
4480 In_Tree.String_Elements.Table
4481 (String_Element_Table.Last
4482 (In_Tree.String_Elements)) :=
4483 (Value => ALI_Name_Id,
4485 Display_Value => ALI_Name_Id,
4487 In_Tree.String_Elements.Table
4488 (Interfaces).Location,
4490 Next => Interface_ALIs);
4491 Interface_ALIs := String_Element_Table.Last
4492 (In_Tree.String_Elements);
4496 -- Start of processing for SAL_Library
4499 Project.Standalone_Library := True;
4501 -- Library_Interface cannot be an empty list
4503 if Interfaces = Nil_String then
4506 "Library_Interface cannot be an empty list",
4507 Lib_Interfaces.Location);
4510 -- Process each unit name specified in the attribute
4511 -- Library_Interface.
4513 while Interfaces /= Nil_String loop
4515 (In_Tree.String_Elements.Table (Interfaces).Value);
4516 To_Lower (Name_Buffer (1 .. Name_Len));
4518 if Name_Len = 0 then
4521 "an interface cannot be an empty string",
4522 In_Tree.String_Elements.Table (Interfaces).Location);
4526 Error_Msg_Name_1 := Unit;
4528 if Get_Mode = Ada_Only then
4530 Units_Htable.Get (In_Tree.Units_HT, Unit);
4532 if The_Unit_Id = No_Unit_Index then
4536 In_Tree.String_Elements.Table
4537 (Interfaces).Location);
4540 -- Check that the unit is part of the project
4542 UData := In_Tree.Units.Table (The_Unit_Id);
4544 if UData.File_Names (Impl) /= null
4546 UData.File_Names (Impl).Path.Name /=
4550 (UData.File_Names (Impl).Project,
4553 -- There is a body for this unit.
4554 -- If there is no spec, we need to check that it
4555 -- is not a subunit.
4557 if UData.File_Names (Spec) = null then
4559 Src_Ind : Source_File_Index;
4562 Src_Ind := Sinput.P.Load_Project_File
4567 if Sinput.P.Source_File_Is_Subunit
4572 "%% is a subunit; " &
4573 "it cannot be an interface",
4575 String_Elements.Table
4576 (Interfaces).Location);
4581 -- The unit is not a subunit, so we add the
4582 -- ALI file for its body to the Interface ALIs.
4585 (UData.File_Names (Impl).File);
4590 "%% is not an unit of this project",
4591 In_Tree.String_Elements.Table
4592 (Interfaces).Location);
4595 elsif UData.File_Names (Spec) /= null
4596 and then UData.File_Names
4597 (Spec).Path.Name /= Slash
4598 and then Check_Project
4604 -- The unit is part of the project, it has a spec,
4605 -- but no body. We add the ALI for its spec to the
4609 (UData.File_Names (Spec).File);
4614 "%% is not an unit of this project",
4615 In_Tree.String_Elements.Table
4616 (Interfaces).Location);
4621 -- Multi_Language mode
4623 Next_Proj := Project.Extends;
4625 Iter := For_Each_Source (In_Tree, Project);
4628 while Prj.Element (Iter) /= No_Source and then
4629 Prj.Element (Iter).Unit /= Unit
4634 Source := Prj.Element (Iter);
4635 exit when Source /= No_Source or else
4636 Next_Proj = No_Project;
4638 Iter := For_Each_Source (In_Tree, Next_Proj);
4639 Next_Proj := Next_Proj.Extends;
4642 if Source /= No_Source then
4643 if Source.Kind = Sep then
4644 Source := No_Source;
4646 elsif Source.Kind = Spec
4647 and then Source.Other_Part /= No_Source
4649 Source := Source.Other_Part;
4653 if Source /= No_Source then
4654 if Source.Project /= Project
4656 not Is_Extending (Project, Source.Project)
4658 Source := No_Source;
4662 if Source = No_Source then
4665 "%% is not an unit of this project",
4666 In_Tree.String_Elements.Table
4667 (Interfaces).Location);
4670 if Source.Kind = Spec and then
4671 Source.Other_Part /= No_Source
4673 Source := Source.Other_Part;
4676 String_Element_Table.Increment_Last
4677 (In_Tree.String_Elements);
4678 In_Tree.String_Elements.Table
4679 (String_Element_Table.Last
4680 (In_Tree.String_Elements)) :=
4681 (Value => Name_Id (Source.Dep_Name),
4683 Display_Value => Name_Id (Source.Dep_Name),
4685 In_Tree.String_Elements.Table
4686 (Interfaces).Location,
4688 Next => Interface_ALIs);
4689 Interface_ALIs := String_Element_Table.Last
4690 (In_Tree.String_Elements);
4698 In_Tree.String_Elements.Table (Interfaces).Next;
4701 -- Put the list of Interface ALIs in the project data
4703 Project.Lib_Interface_ALIs := Interface_ALIs;
4705 -- Check value of attribute Library_Auto_Init and set
4706 -- Lib_Auto_Init accordingly.
4708 if Lib_Auto_Init.Default then
4710 -- If no attribute Library_Auto_Init is declared, then set auto
4711 -- init only if it is supported.
4713 Project.Lib_Auto_Init := Auto_Init_Supported;
4716 Get_Name_String (Lib_Auto_Init.Value);
4717 To_Lower (Name_Buffer (1 .. Name_Len));
4719 if Name_Buffer (1 .. Name_Len) = "false" then
4720 Project.Lib_Auto_Init := False;
4722 elsif Name_Buffer (1 .. Name_Len) = "true" then
4723 if Auto_Init_Supported then
4724 Project.Lib_Auto_Init := True;
4727 -- Library_Auto_Init cannot be "true" if auto init is not
4732 "library auto init not supported " &
4734 Lib_Auto_Init.Location);
4740 "invalid value for attribute Library_Auto_Init",
4741 Lib_Auto_Init.Location);
4746 -- If attribute Library_Src_Dir is defined and not the empty string,
4747 -- check if the directory exist and is not the object directory or
4748 -- one of the source directories. This is the directory where copies
4749 -- of the interface sources will be copied. Note that this directory
4750 -- may be the library directory.
4752 if Lib_Src_Dir.Value /= Empty_String then
4754 Dir_Id : constant File_Name_Type :=
4755 File_Name_Type (Lib_Src_Dir.Value);
4756 Dir_Exists : Boolean;
4763 Path => Project.Library_Src_Dir,
4764 Dir_Exists => Dir_Exists,
4765 Must_Exist => False,
4766 Create => "library source copy",
4767 Location => Lib_Src_Dir.Location,
4768 Externally_Built => Project.Externally_Built);
4770 -- If directory does not exist, report an error
4772 if not Dir_Exists then
4773 -- Get the absolute name of the library directory that does
4774 -- not exist, to report an error.
4776 Err_Vars.Error_Msg_File_1 :=
4777 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4780 "Directory { does not exist",
4781 Lib_Src_Dir.Location);
4783 -- Report error if it is the same as the object directory
4785 elsif Project.Library_Src_Dir = Project.Object_Directory then
4788 "directory to copy interfaces cannot be " &
4789 "the object directory",
4790 Lib_Src_Dir.Location);
4791 Project.Library_Src_Dir := No_Path_Information;
4795 Src_Dirs : String_List_Id;
4796 Src_Dir : String_Element;
4800 -- Interface copy directory cannot be one of the source
4801 -- directory of the current project.
4803 Src_Dirs := Project.Source_Dirs;
4804 while Src_Dirs /= Nil_String loop
4805 Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
4807 -- Report error if it is one of the source directories
4809 if Project.Library_Src_Dir.Name =
4810 Path_Name_Type (Src_Dir.Value)
4814 "directory to copy interfaces cannot " &
4815 "be one of the source directories",
4816 Lib_Src_Dir.Location);
4817 Project.Library_Src_Dir := No_Path_Information;
4821 Src_Dirs := Src_Dir.Next;
4824 if Project.Library_Src_Dir /= No_Path_Information then
4826 -- It cannot be a source directory of any other
4829 Pid := In_Tree.Projects;
4831 exit Project_Loop when Pid = null;
4833 Src_Dirs := Pid.Project.Source_Dirs;
4834 Dir_Loop : while Src_Dirs /= Nil_String loop
4836 In_Tree.String_Elements.Table (Src_Dirs);
4838 -- Report error if it is one of the source
4841 if Project.Library_Src_Dir.Name =
4842 Path_Name_Type (Src_Dir.Value)
4845 File_Name_Type (Src_Dir.Value);
4846 Error_Msg_Name_1 := Pid.Project.Name;
4849 "directory to copy interfaces cannot " &
4850 "be the same as source directory { of " &
4852 Lib_Src_Dir.Location);
4853 Project.Library_Src_Dir :=
4854 No_Path_Information;
4858 Src_Dirs := Src_Dir.Next;
4862 end loop Project_Loop;
4866 -- In high verbosity, if there is a valid Library_Src_Dir,
4867 -- display its path name.
4869 if Project.Library_Src_Dir /= No_Path_Information
4870 and then Current_Verbosity = High
4873 ("Directory to copy interfaces",
4874 Get_Name_String (Project.Library_Src_Dir.Name));
4880 -- Check the symbol related attributes
4882 -- First, the symbol policy
4884 if not Lib_Symbol_Policy.Default then
4886 Value : constant String :=
4888 (Get_Name_String (Lib_Symbol_Policy.Value));
4891 -- Symbol policy must hove one of a limited number of values
4893 if Value = "autonomous" or else Value = "default" then
4894 Project.Symbol_Data.Symbol_Policy := Autonomous;
4896 elsif Value = "compliant" then
4897 Project.Symbol_Data.Symbol_Policy := Compliant;
4899 elsif Value = "controlled" then
4900 Project.Symbol_Data.Symbol_Policy := Controlled;
4902 elsif Value = "restricted" then
4903 Project.Symbol_Data.Symbol_Policy := Restricted;
4905 elsif Value = "direct" then
4906 Project.Symbol_Data.Symbol_Policy := Direct;
4911 "illegal value for Library_Symbol_Policy",
4912 Lib_Symbol_Policy.Location);
4917 -- If attribute Library_Symbol_File is not specified, symbol policy
4918 -- cannot be Restricted.
4920 if Lib_Symbol_File.Default then
4921 if Project.Symbol_Data.Symbol_Policy = Restricted then
4924 "Library_Symbol_File needs to be defined when " &
4925 "symbol policy is Restricted",
4926 Lib_Symbol_Policy.Location);
4930 -- Library_Symbol_File is defined
4932 Project.Symbol_Data.Symbol_File :=
4933 Path_Name_Type (Lib_Symbol_File.Value);
4935 Get_Name_String (Lib_Symbol_File.Value);
4937 if Name_Len = 0 then
4940 "symbol file name cannot be an empty string",
4941 Lib_Symbol_File.Location);
4944 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4947 for J in 1 .. Name_Len loop
4948 if Name_Buffer (J) = '/'
4949 or else Name_Buffer (J) = Directory_Separator
4958 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4961 "symbol file name { is illegal. " &
4962 "Name cannot include directory info.",
4963 Lib_Symbol_File.Location);
4968 -- If attribute Library_Reference_Symbol_File is not defined,
4969 -- symbol policy cannot be Compliant or Controlled.
4971 if Lib_Ref_Symbol_File.Default then
4972 if Project.Symbol_Data.Symbol_Policy = Compliant
4973 or else Project.Symbol_Data.Symbol_Policy = Controlled
4977 "a reference symbol file needs to be defined",
4978 Lib_Symbol_Policy.Location);
4982 -- Library_Reference_Symbol_File is defined, check file exists
4984 Project.Symbol_Data.Reference :=
4985 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4987 Get_Name_String (Lib_Ref_Symbol_File.Value);
4989 if Name_Len = 0 then
4992 "reference symbol file name cannot be an empty string",
4993 Lib_Symbol_File.Location);
4996 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4998 Add_Str_To_Name_Buffer
4999 (Get_Name_String (Project.Directory.Name));
5000 Add_Char_To_Name_Buffer (Directory_Separator);
5001 Add_Str_To_Name_Buffer
5002 (Get_Name_String (Lib_Ref_Symbol_File.Value));
5003 Project.Symbol_Data.Reference := Name_Find;
5006 if not Is_Regular_File
5007 (Get_Name_String (Project.Symbol_Data.Reference))
5010 File_Name_Type (Lib_Ref_Symbol_File.Value);
5012 -- For controlled and direct symbol policies, it is an error
5013 -- if the reference symbol file does not exist. For other
5014 -- symbol policies, this is just a warning
5017 Project.Symbol_Data.Symbol_Policy /= Controlled
5018 and then Project.Symbol_Data.Symbol_Policy /= Direct;
5022 "<library reference symbol file { does not exist",
5023 Lib_Ref_Symbol_File.Location);
5025 -- In addition in the non-controlled case, if symbol policy
5026 -- is Compliant, it is changed to Autonomous, because there
5027 -- is no reference to check against, and we don't want to
5028 -- fail in this case.
5030 if Project.Symbol_Data.Symbol_Policy /= Controlled then
5031 if Project.Symbol_Data.Symbol_Policy = Compliant then
5032 Project.Symbol_Data.Symbol_Policy := Autonomous;
5037 -- If both the reference symbol file and the symbol file are
5038 -- defined, then check that they are not the same file.
5040 if Project.Symbol_Data.Symbol_File /= No_Path then
5041 Get_Name_String (Project.Symbol_Data.Symbol_File);
5043 if Name_Len > 0 then
5045 Symb_Path : constant String :=
5048 (Project.Object_Directory.Name) &
5049 Directory_Separator &
5050 Name_Buffer (1 .. Name_Len),
5051 Directory => Current_Dir,
5053 Opt.Follow_Links_For_Files);
5054 Ref_Path : constant String :=
5057 (Project.Symbol_Data.Reference),
5058 Directory => Current_Dir,
5060 Opt.Follow_Links_For_Files);
5062 if Symb_Path = Ref_Path then
5065 "library reference symbol file and library" &
5066 " symbol file cannot be the same file",
5067 Lib_Ref_Symbol_File.Location);
5075 end Check_Stand_Alone_Library;
5077 ----------------------------
5078 -- Compute_Directory_Last --
5079 ----------------------------
5081 function Compute_Directory_Last (Dir : String) return Natural is
5084 and then (Dir (Dir'Last - 1) = Directory_Separator
5085 or else Dir (Dir'Last - 1) = '/')
5087 return Dir'Last - 1;
5091 end Compute_Directory_Last;
5098 (Project : Project_Id;
5099 In_Tree : Project_Tree_Ref;
5101 Flag_Location : Source_Ptr)
5103 Real_Location : Source_Ptr := Flag_Location;
5104 Error_Buffer : String (1 .. 5_000);
5105 Error_Last : Natural := 0;
5106 Name_Number : Natural := 0;
5107 File_Number : Natural := 0;
5108 First : Positive := Msg'First;
5111 procedure Add (C : Character);
5112 -- Add a character to the buffer
5114 procedure Add (S : String);
5115 -- Add a string to the buffer
5118 -- Add a name to the buffer
5121 -- Add a file name to the buffer
5127 procedure Add (C : Character) is
5129 Error_Last := Error_Last + 1;
5130 Error_Buffer (Error_Last) := C;
5133 procedure Add (S : String) is
5135 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
5136 Error_Last := Error_Last + S'Length;
5143 procedure Add_File is
5144 File : File_Name_Type;
5148 File_Number := File_Number + 1;
5152 File := Err_Vars.Error_Msg_File_1;
5154 File := Err_Vars.Error_Msg_File_2;
5156 File := Err_Vars.Error_Msg_File_3;
5161 Get_Name_String (File);
5162 Add (Name_Buffer (1 .. Name_Len));
5170 procedure Add_Name is
5175 Name_Number := Name_Number + 1;
5179 Name := Err_Vars.Error_Msg_Name_1;
5181 Name := Err_Vars.Error_Msg_Name_2;
5183 Name := Err_Vars.Error_Msg_Name_3;
5188 Get_Name_String (Name);
5189 Add (Name_Buffer (1 .. Name_Len));
5193 -- Start of processing for Error_Msg
5196 -- If location of error is unknown, use the location of the project
5198 if Real_Location = No_Location then
5199 Real_Location := Project.Location;
5202 if Error_Report = null then
5203 Prj.Err.Error_Msg (Msg, Real_Location);
5207 -- Ignore continuation character
5209 if Msg (First) = '\' then
5213 -- Warning character is always the first one in this package
5214 -- this is an undocumented kludge???
5216 if Msg (First) = '?' then
5220 elsif Msg (First) = '<' then
5223 if Err_Vars.Error_Msg_Warn then
5229 while Index <= Msg'Last loop
5230 if Msg (Index) = '{' then
5233 elsif Msg (Index) = '%' then
5234 if Index < Msg'Last and then Msg (Index + 1) = '%' then
5246 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
5249 --------------------------------
5250 -- Free_Ada_Naming_Exceptions --
5251 --------------------------------
5253 procedure Free_Ada_Naming_Exceptions is
5255 Ada_Naming_Exception_Table.Set_Last (0);
5256 Ada_Naming_Exceptions.Reset;
5257 Reverse_Ada_Naming_Exceptions.Reset;
5258 end Free_Ada_Naming_Exceptions;
5260 ---------------------
5261 -- Get_Directories --
5262 ---------------------
5264 procedure Get_Directories
5265 (Project : Project_Id;
5266 In_Tree : Project_Tree_Ref;
5267 Current_Dir : String)
5269 Object_Dir : constant Variable_Value :=
5271 (Name_Object_Dir, Project.Decl.Attributes, In_Tree);
5273 Exec_Dir : constant Variable_Value :=
5275 (Name_Exec_Dir, Project.Decl.Attributes, In_Tree);
5277 Source_Dirs : constant Variable_Value :=
5279 (Name_Source_Dirs, Project.Decl.Attributes, In_Tree);
5281 Excluded_Source_Dirs : constant Variable_Value :=
5283 (Name_Excluded_Source_Dirs,
5284 Project.Decl.Attributes,
5287 Source_Files : constant Variable_Value :=
5289 (Name_Source_Files, Project.Decl.Attributes, In_Tree);
5291 Last_Source_Dir : String_List_Id := Nil_String;
5293 Languages : constant Variable_Value :=
5295 (Name_Languages, Project.Decl.Attributes, In_Tree);
5297 procedure Find_Source_Dirs
5298 (From : File_Name_Type;
5299 Location : Source_Ptr;
5300 Removed : Boolean := False);
5301 -- Find one or several source directories, and add (or remove, if
5302 -- Removed is True) them to list of source directories of the project.
5304 ----------------------
5305 -- Find_Source_Dirs --
5306 ----------------------
5308 procedure Find_Source_Dirs
5309 (From : File_Name_Type;
5310 Location : Source_Ptr;
5311 Removed : Boolean := False)
5313 Directory : constant String := Get_Name_String (From);
5314 Element : String_Element;
5316 procedure Recursive_Find_Dirs (Path : Name_Id);
5317 -- Find all the subdirectories (recursively) of Path and add them
5318 -- to the list of source directories of the project.
5320 -------------------------
5321 -- Recursive_Find_Dirs --
5322 -------------------------
5324 procedure Recursive_Find_Dirs (Path : Name_Id) is
5326 Name : String (1 .. 250);
5328 List : String_List_Id;
5329 Prev : String_List_Id;
5330 Element : String_Element;
5331 Found : Boolean := False;
5333 Non_Canonical_Path : Name_Id := No_Name;
5334 Canonical_Path : Name_Id := No_Name;
5336 The_Path : constant String :=
5338 (Get_Name_String (Path),
5339 Directory => Current_Dir,
5340 Resolve_Links => Opt.Follow_Links_For_Dirs) &
5341 Directory_Separator;
5343 The_Path_Last : constant Natural :=
5344 Compute_Directory_Last (The_Path);
5347 Name_Len := The_Path_Last - The_Path'First + 1;
5348 Name_Buffer (1 .. Name_Len) :=
5349 The_Path (The_Path'First .. The_Path_Last);
5350 Non_Canonical_Path := Name_Find;
5352 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
5354 -- To avoid processing the same directory several times, check
5355 -- if the directory is already in Recursive_Dirs. If it is, then
5356 -- there is nothing to do, just return. If it is not, put it there
5357 -- and continue recursive processing.
5360 if Recursive_Dirs.Get (Canonical_Path) then
5363 Recursive_Dirs.Set (Canonical_Path, True);
5367 -- Check if directory is already in list
5369 List := Project.Source_Dirs;
5371 while List /= Nil_String loop
5372 Element := In_Tree.String_Elements.Table (List);
5374 if Element.Value /= No_Name then
5375 Found := Element.Value = Canonical_Path;
5380 List := Element.Next;
5383 -- If directory is not already in list, put it there
5385 if (not Removed) and (not Found) then
5386 if Current_Verbosity = High then
5388 Write_Line (The_Path (The_Path'First .. The_Path_Last));
5391 String_Element_Table.Increment_Last
5392 (In_Tree.String_Elements);
5394 (Value => Canonical_Path,
5395 Display_Value => Non_Canonical_Path,
5396 Location => No_Location,
5401 -- Case of first source directory
5403 if Last_Source_Dir = Nil_String then
5404 Project.Source_Dirs := String_Element_Table.Last
5405 (In_Tree.String_Elements);
5407 -- Here we already have source directories
5410 -- Link the previous last to the new one
5412 In_Tree.String_Elements.Table
5413 (Last_Source_Dir).Next :=
5414 String_Element_Table.Last
5415 (In_Tree.String_Elements);
5418 -- And register this source directory as the new last
5420 Last_Source_Dir := String_Element_Table.Last
5421 (In_Tree.String_Elements);
5422 In_Tree.String_Elements.Table (Last_Source_Dir) :=
5425 elsif Removed and Found then
5426 if Prev = Nil_String then
5427 Project.Source_Dirs :=
5428 In_Tree.String_Elements.Table (List).Next;
5430 In_Tree.String_Elements.Table (Prev).Next :=
5431 In_Tree.String_Elements.Table (List).Next;
5435 -- Now look for subdirectories. We do that even when this
5436 -- directory is already in the list, because some of its
5437 -- subdirectories may not be in the list yet.
5439 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
5442 Read (Dir, Name, Last);
5445 if Name (1 .. Last) /= "."
5446 and then Name (1 .. Last) /= ".."
5448 -- Avoid . and .. directories
5450 if Current_Verbosity = High then
5451 Write_Str (" Checking ");
5452 Write_Line (Name (1 .. Last));
5456 Path_Name : constant String :=
5458 (Name => Name (1 .. Last),
5460 The_Path (The_Path'First .. The_Path_Last),
5461 Resolve_Links => Opt.Follow_Links_For_Dirs,
5462 Case_Sensitive => True);
5465 if Is_Directory (Path_Name) then
5466 -- We have found a new subdirectory, call self
5468 Name_Len := Path_Name'Length;
5469 Name_Buffer (1 .. Name_Len) := Path_Name;
5470 Recursive_Find_Dirs (Name_Find);
5479 when Directory_Error =>
5481 end Recursive_Find_Dirs;
5483 -- Start of processing for Find_Source_Dirs
5486 if Current_Verbosity = High and then not Removed then
5487 Write_Str ("Find_Source_Dirs (""");
5488 Write_Str (Directory);
5492 -- First, check if we are looking for a directory tree, indicated
5493 -- by "/**" at the end.
5495 if Directory'Length >= 3
5496 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5497 and then (Directory (Directory'Last - 2) = '/'
5499 Directory (Directory'Last - 2) = Directory_Separator)
5502 Project.Known_Order_Of_Source_Dirs := False;
5505 Name_Len := Directory'Length - 3;
5507 if Name_Len = 0 then
5509 -- Case of "/**": all directories in file system
5512 Name_Buffer (1) := Directory (Directory'First);
5515 Name_Buffer (1 .. Name_Len) :=
5516 Directory (Directory'First .. Directory'Last - 3);
5519 if Current_Verbosity = High then
5520 Write_Str ("Looking for all subdirectories of """);
5521 Write_Str (Name_Buffer (1 .. Name_Len));
5526 Base_Dir : constant File_Name_Type := Name_Find;
5527 Root_Dir : constant String :=
5529 (Name => Get_Name_String (Base_Dir),
5532 (Project.Directory.Display_Name),
5533 Resolve_Links => False,
5534 Case_Sensitive => True);
5537 if Root_Dir'Length = 0 then
5538 Err_Vars.Error_Msg_File_1 := Base_Dir;
5540 if Location = No_Location then
5543 "{ is not a valid directory.",
5548 "{ is not a valid directory.",
5553 -- We have an existing directory, we register it and all of
5554 -- its subdirectories.
5556 if Current_Verbosity = High then
5557 Write_Line ("Looking for source directories:");
5560 Name_Len := Root_Dir'Length;
5561 Name_Buffer (1 .. Name_Len) := Root_Dir;
5562 Recursive_Find_Dirs (Name_Find);
5564 if Current_Verbosity = High then
5565 Write_Line ("End of looking for source directories.");
5570 -- We have a single directory
5574 Path_Name : Path_Information;
5575 List : String_List_Id;
5576 Prev : String_List_Id;
5577 Dir_Exists : Boolean;
5581 (Project => Project,
5585 Dir_Exists => Dir_Exists,
5586 Must_Exist => False);
5588 if not Dir_Exists then
5589 Err_Vars.Error_Msg_File_1 := From;
5591 if Location = No_Location then
5594 "{ is not a valid directory",
5599 "{ is not a valid directory",
5605 Path : constant String :=
5606 Get_Name_String (Path_Name.Name) &
5607 Directory_Separator;
5608 Last_Path : constant Natural :=
5609 Compute_Directory_Last (Path);
5611 Display_Path : constant String :=
5613 (Path_Name.Display_Name) &
5614 Directory_Separator;
5615 Last_Display_Path : constant Natural :=
5616 Compute_Directory_Last
5618 Display_Path_Id : Name_Id;
5622 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5623 Path_Id := Name_Find;
5625 Add_Str_To_Name_Buffer
5627 (Display_Path'First .. Last_Display_Path));
5628 Display_Path_Id := Name_Find;
5632 -- As it is an existing directory, we add it to the
5633 -- list of directories.
5635 String_Element_Table.Increment_Last
5636 (In_Tree.String_Elements);
5640 Display_Value => Display_Path_Id,
5641 Location => No_Location,
5643 Next => Nil_String);
5645 if Last_Source_Dir = Nil_String then
5647 -- This is the first source directory
5649 Project.Source_Dirs := String_Element_Table.Last
5650 (In_Tree.String_Elements);
5653 -- We already have source directories, link the
5654 -- previous last to the new one.
5656 In_Tree.String_Elements.Table
5657 (Last_Source_Dir).Next :=
5658 String_Element_Table.Last
5659 (In_Tree.String_Elements);
5662 -- And register this source directory as the new last
5664 Last_Source_Dir := String_Element_Table.Last
5665 (In_Tree.String_Elements);
5666 In_Tree.String_Elements.Table
5667 (Last_Source_Dir) := Element;
5670 -- Remove source dir, if present
5674 -- Look for source dir in current list
5676 List := Project.Source_Dirs;
5677 while List /= Nil_String loop
5678 Element := In_Tree.String_Elements.Table (List);
5679 exit when Element.Value = Path_Id;
5681 List := Element.Next;
5684 if List /= Nil_String then
5685 -- Source dir was found, remove it from the list
5687 if Prev = Nil_String then
5688 Project.Source_Dirs :=
5689 In_Tree.String_Elements.Table (List).Next;
5692 In_Tree.String_Elements.Table (Prev).Next :=
5693 In_Tree.String_Elements.Table (List).Next;
5701 end Find_Source_Dirs;
5703 -- Start of processing for Get_Directories
5705 Dir_Exists : Boolean;
5708 if Current_Verbosity = High then
5709 Write_Line ("Starting to look for directories");
5712 -- Set the object directory to its default which may be nil, if there
5713 -- is no sources in the project.
5715 if (((not Source_Files.Default)
5716 and then Source_Files.Values = Nil_String)
5718 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5720 ((not Languages.Default) and then Languages.Values = Nil_String))
5721 and then Project.Extends = No_Project
5723 Project.Object_Directory := No_Path_Information;
5725 Project.Object_Directory := Project.Directory;
5728 -- Check the object directory
5730 if Object_Dir.Value /= Empty_String then
5731 Get_Name_String (Object_Dir.Value);
5733 if Name_Len = 0 then
5736 "Object_Dir cannot be empty",
5737 Object_Dir.Location);
5740 -- We check that the specified object directory does exist.
5741 -- However, even when it doesn't exist, we set it to a default
5742 -- value. This is for the benefit of tools that recover from
5743 -- errors; for example, these tools could create the non existent
5745 -- We always return an absolute directory name though
5750 File_Name_Type (Object_Dir.Value),
5751 Path => Project.Object_Directory,
5753 Dir_Exists => Dir_Exists,
5754 Location => Object_Dir.Location,
5755 Must_Exist => False,
5756 Externally_Built => Project.Externally_Built);
5759 and then not Project.Externally_Built
5761 -- The object directory does not exist, report an error if
5762 -- the project is not externally built.
5764 Err_Vars.Error_Msg_File_1 :=
5765 File_Name_Type (Object_Dir.Value);
5768 "object directory { not found",
5773 elsif Project.Object_Directory /= No_Path_Information
5774 and then Subdirs /= null
5777 Name_Buffer (1) := '.';
5782 Path => Project.Object_Directory,
5784 Dir_Exists => Dir_Exists,
5785 Location => Object_Dir.Location,
5786 Externally_Built => Project.Externally_Built);
5789 if Current_Verbosity = High then
5790 if Project.Object_Directory = No_Path_Information then
5791 Write_Line ("No object directory");
5794 ("Object directory",
5795 Get_Name_String (Project.Object_Directory.Display_Name));
5799 -- Check the exec directory
5801 -- We set the object directory to its default
5803 Project.Exec_Directory := Project.Object_Directory;
5805 if Exec_Dir.Value /= Empty_String then
5806 Get_Name_String (Exec_Dir.Value);
5808 if Name_Len = 0 then
5811 "Exec_Dir cannot be empty",
5815 -- We check that the specified exec directory does exist
5820 File_Name_Type (Exec_Dir.Value),
5821 Path => Project.Exec_Directory,
5822 Dir_Exists => Dir_Exists,
5824 Location => Exec_Dir.Location,
5825 Externally_Built => Project.Externally_Built);
5827 if not Dir_Exists then
5828 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5831 "exec directory { not found",
5837 if Current_Verbosity = High then
5838 if Project.Exec_Directory = No_Path_Information then
5839 Write_Line ("No exec directory");
5841 Write_Str ("Exec directory: """);
5842 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5847 -- Look for the source directories
5849 if Current_Verbosity = High then
5850 Write_Line ("Starting to look for source directories");
5853 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5855 if (not Source_Files.Default) and then
5856 Source_Files.Values = Nil_String
5858 Project.Source_Dirs := Nil_String;
5860 if Project.Qualifier = Standard then
5864 "a standard project cannot have no sources",
5865 Source_Files.Location);
5868 elsif Source_Dirs.Default then
5870 -- No Source_Dirs specified: the single source directory is the one
5871 -- containing the project file
5873 String_Element_Table.Append (In_Tree.String_Elements,
5874 (Value => Name_Id (Project.Directory.Name),
5875 Display_Value => Name_Id (Project.Directory.Display_Name),
5876 Location => No_Location,
5880 Project.Source_Dirs := String_Element_Table.Last
5881 (In_Tree.String_Elements);
5883 if Current_Verbosity = High then
5885 ("Default source directory",
5886 Get_Name_String (Project.Directory.Display_Name));
5889 elsif Source_Dirs.Values = Nil_String then
5890 if Project.Qualifier = Standard then
5894 "a standard project cannot have no source directories",
5895 Source_Dirs.Location);
5898 Project.Source_Dirs := Nil_String;
5902 Source_Dir : String_List_Id;
5903 Element : String_Element;
5906 -- Process the source directories for each element of the list
5908 Source_Dir := Source_Dirs.Values;
5909 while Source_Dir /= Nil_String loop
5910 Element := In_Tree.String_Elements.Table (Source_Dir);
5912 (File_Name_Type (Element.Value), Element.Location);
5913 Source_Dir := Element.Next;
5918 if not Excluded_Source_Dirs.Default
5919 and then Excluded_Source_Dirs.Values /= Nil_String
5922 Source_Dir : String_List_Id;
5923 Element : String_Element;
5926 -- Process the source directories for each element of the list
5928 Source_Dir := Excluded_Source_Dirs.Values;
5929 while Source_Dir /= Nil_String loop
5930 Element := In_Tree.String_Elements.Table (Source_Dir);
5932 (File_Name_Type (Element.Value),
5935 Source_Dir := Element.Next;
5940 if Current_Verbosity = High then
5941 Write_Line ("Putting source directories in canonical cases");
5945 Current : String_List_Id := Project.Source_Dirs;
5946 Element : String_Element;
5949 while Current /= Nil_String loop
5950 Element := In_Tree.String_Elements.Table (Current);
5951 if Element.Value /= No_Name then
5953 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5954 In_Tree.String_Elements.Table (Current) := Element;
5957 Current := Element.Next;
5960 end Get_Directories;
5967 (Project : Project_Id;
5968 In_Tree : Project_Tree_Ref)
5970 Mains : constant Variable_Value :=
5971 Prj.Util.Value_Of (Name_Main, Project.Decl.Attributes, In_Tree);
5972 List : String_List_Id;
5973 Elem : String_Element;
5976 Project.Mains := Mains.Values;
5978 -- If no Mains were specified, and if we are an extending project,
5979 -- inherit the Mains from the project we are extending.
5981 if Mains.Default then
5982 if not Project.Library and then Project.Extends /= No_Project then
5983 Project.Mains := Project.Extends.Mains;
5986 -- In a library project file, Main cannot be specified
5988 elsif Project.Library then
5991 "a library project file cannot have Main specified",
5995 List := Mains.Values;
5996 while List /= Nil_String loop
5997 Elem := In_Tree.String_Elements.Table (List);
5999 if Length_Of_Name (Elem.Value) = 0 then
6002 "?a main cannot have an empty name",
6012 ---------------------------
6013 -- Get_Sources_From_File --
6014 ---------------------------
6016 procedure Get_Sources_From_File
6018 Location : Source_Ptr;
6019 Project : Project_Id;
6020 In_Tree : Project_Tree_Ref)
6022 File : Prj.Util.Text_File;
6023 Line : String (1 .. 250);
6025 Source_Name : File_Name_Type;
6026 Name_Loc : Name_Location;
6029 if Get_Mode = Ada_Only then
6033 if Current_Verbosity = High then
6034 Write_Str ("Opening """);
6041 Prj.Util.Open (File, Path);
6043 if not Prj.Util.Is_Valid (File) then
6044 Error_Msg (Project, In_Tree, "file does not exist", Location);
6047 -- Read the lines one by one
6049 while not Prj.Util.End_Of_File (File) loop
6050 Prj.Util.Get_Line (File, Line, Last);
6052 -- A non empty, non comment line should contain a file name
6055 and then (Last = 1 or else Line (1 .. 2) /= "--")
6058 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6059 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6060 Source_Name := Name_Find;
6062 -- Check that there is no directory information
6064 for J in 1 .. Last loop
6065 if Line (J) = '/' or else Line (J) = Directory_Separator then
6066 Error_Msg_File_1 := Source_Name;
6070 "file name cannot include directory information ({)",
6076 Name_Loc := Source_Names.Get (Source_Name);
6078 if Name_Loc = No_Name_Location then
6080 (Name => Source_Name,
6081 Location => Location,
6082 Source => No_Source,
6087 Source_Names.Set (Source_Name, Name_Loc);
6091 Prj.Util.Close (File);
6094 end Get_Sources_From_File;
6096 -----------------------
6097 -- Compute_Unit_Name --
6098 -----------------------
6100 procedure Compute_Unit_Name
6101 (File_Name : File_Name_Type;
6102 Dot_Replacement : File_Name_Type;
6103 Separate_Suffix : File_Name_Type;
6104 Body_Suffix : File_Name_Type;
6105 Spec_Suffix : File_Name_Type;
6106 Casing : Casing_Type;
6107 Kind : out Source_Kind;
6109 In_Tree : Project_Tree_Ref)
6111 Filename : constant String := Get_Name_String (File_Name);
6112 Last : Integer := Filename'Last;
6113 Sep_Len : constant Integer :=
6114 Integer (Length_Of_Name (Separate_Suffix));
6115 Body_Len : constant Integer :=
6116 Integer (Length_Of_Name (Body_Suffix));
6117 Spec_Len : constant Integer :=
6118 Integer (Length_Of_Name (Spec_Suffix));
6120 Standard_GNAT : constant Boolean :=
6121 Spec_Suffix = Default_Ada_Spec_Suffix
6123 Body_Suffix = Default_Ada_Body_Suffix;
6125 Unit_Except : Unit_Exception;
6126 Masked : Boolean := False;
6131 if Dot_Replacement = No_File then
6132 if Current_Verbosity = High then
6133 Write_Line (" No dot_replacement specified");
6138 -- Choose the longest suffix that matches. If there are several matches,
6139 -- give priority to specs, then bodies, then separates.
6141 if Separate_Suffix /= Body_Suffix
6142 and then Suffix_Matches (Filename, Separate_Suffix)
6144 Last := Filename'Last - Sep_Len;
6148 if Filename'Last - Body_Len <= Last
6149 and then Suffix_Matches (Filename, Body_Suffix)
6151 Last := Natural'Min (Last, Filename'Last - Body_Len);
6155 if Filename'Last - Spec_Len <= Last
6156 and then Suffix_Matches (Filename, Spec_Suffix)
6158 Last := Natural'Min (Last, Filename'Last - Spec_Len);
6162 if Last = Filename'Last then
6163 if Current_Verbosity = High then
6164 Write_Line (" No matching suffix");
6169 -- Check that the casing matches
6171 if File_Names_Case_Sensitive then
6173 when All_Lower_Case =>
6174 for J in Filename'First .. Last loop
6175 if Is_Letter (Filename (J))
6176 and then not Is_Lower (Filename (J))
6178 if Current_Verbosity = High then
6179 Write_Line (" Invalid casing");
6185 when All_Upper_Case =>
6186 for J in Filename'First .. Last loop
6187 if Is_Letter (Filename (J))
6188 and then not Is_Upper (Filename (J))
6190 if Current_Verbosity = High then
6191 Write_Line (" Invalid casing");
6197 when Mixed_Case | Unknown =>
6202 -- If Dot_Replacement is not a single dot, then there should not
6203 -- be any dot in the name.
6206 Dot_Repl : constant String := Get_Name_String (Dot_Replacement);
6209 if Dot_Repl /= "." then
6210 for Index in Filename'First .. Last loop
6211 if Filename (Index) = '.' then
6212 if Current_Verbosity = High then
6213 Write_Line (" Invalid name, contains dot");
6219 Replace_Into_Name_Buffer
6220 (Filename (Filename'First .. Last), Dot_Repl, '.');
6222 Name_Len := Last - Filename'First + 1;
6223 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
6225 (Source => Name_Buffer (1 .. Name_Len),
6226 Mapping => Lower_Case_Map);
6230 -- In the standard GNAT naming scheme, check for special cases: children
6231 -- or separates of A, G, I or S, and run time sources.
6233 if Standard_GNAT and then Name_Len >= 3 then
6235 S1 : constant Character := Name_Buffer (1);
6236 S2 : constant Character := Name_Buffer (2);
6237 S3 : constant Character := Name_Buffer (3);
6245 -- Children or separates of packages A, G, I or S. These names
6246 -- are x__ ... or x~... (where x is a, g, i, or s). Both
6247 -- versions (x__... and x~...) are allowed in all platforms,
6248 -- because it is not possible to know the platform before
6249 -- processing of the project files.
6251 if S2 = '_' and then S3 = '_' then
6252 Name_Buffer (2) := '.';
6253 Name_Buffer (3 .. Name_Len - 1) :=
6254 Name_Buffer (4 .. Name_Len);
6255 Name_Len := Name_Len - 1;
6258 Name_Buffer (2) := '.';
6262 -- If it is potentially a run time source, disable filling
6263 -- of the mapping file to avoid warnings.
6265 Set_Mapping_File_Initial_State_To_Empty (In_Tree);
6271 -- Name_Buffer contains the name of the the unit in lower-cases. Check
6272 -- that this is a valid unit name
6274 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
6276 -- If there is a naming exception for the same unit, the file is not
6277 -- a source for the unit. Currently, this only applies in multi_lang
6278 -- mode, since Unit_Exceptions is no set in ada_only mode.
6280 if Unit /= No_Name then
6281 Unit_Except := Unit_Exceptions.Get (Unit);
6284 Masked := Unit_Except.Spec /= No_File
6286 Unit_Except.Spec /= File_Name;
6288 Masked := Unit_Except.Impl /= No_File
6290 Unit_Except.Impl /= File_Name;
6294 if Current_Verbosity = High then
6295 Write_Str (" """ & Filename & """ contains the ");
6298 Write_Str ("spec of a unit found in """);
6299 Write_Str (Get_Name_String (Unit_Except.Spec));
6301 Write_Str ("body of a unit found in """);
6302 Write_Str (Get_Name_String (Unit_Except.Impl));
6305 Write_Line (""" (ignored)");
6313 and then Current_Verbosity = High
6316 when Spec => Write_Str (" spec of ");
6317 when Impl => Write_Str (" body of ");
6318 when Sep => Write_Str (" sep of ");
6321 Write_Line (Get_Name_String (Unit));
6323 end Compute_Unit_Name;
6330 (In_Tree : Project_Tree_Ref;
6331 Canonical_File_Name : File_Name_Type;
6332 Naming : Naming_Data;
6333 Exception_Id : out Ada_Naming_Exception_Id;
6334 Unit_Name : out Name_Id;
6335 Unit_Kind : out Spec_Or_Body)
6337 Info_Id : Ada_Naming_Exception_Id :=
6338 Ada_Naming_Exceptions.Get (Canonical_File_Name);
6339 VMS_Name : File_Name_Type;
6343 if Info_Id = No_Ada_Naming_Exception
6344 and then Hostparm.OpenVMS
6346 VMS_Name := Canonical_File_Name;
6347 Get_Name_String (VMS_Name);
6349 if Name_Buffer (Name_Len) = '.' then
6350 Name_Len := Name_Len - 1;
6351 VMS_Name := Name_Find;
6354 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
6357 if Info_Id /= No_Ada_Naming_Exception then
6358 Exception_Id := Info_Id;
6359 Unit_Name := No_Name;
6363 Exception_Id := No_Ada_Naming_Exception;
6365 (File_Name => Canonical_File_Name,
6366 Dot_Replacement => Naming.Dot_Replacement,
6367 Separate_Suffix => Naming.Separate_Suffix,
6368 Body_Suffix => Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6369 Spec_Suffix => Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6370 Casing => Naming.Casing,
6373 In_Tree => In_Tree);
6376 when Spec => Unit_Kind := Spec;
6377 when Impl | Sep => Unit_Kind := Impl;
6386 function Hash (Unit : Unit_Info) return Header_Num is
6388 return Header_Num (Unit.Unit mod 2048);
6391 -----------------------
6392 -- Is_Illegal_Suffix --
6393 -----------------------
6395 function Is_Illegal_Suffix
6396 (Suffix : File_Name_Type;
6397 Dot_Replacement : File_Name_Type) return Boolean
6399 Suffix_Str : constant String := Get_Name_String (Suffix);
6402 if Suffix_Str'Length = 0 then
6404 elsif Index (Suffix_Str, ".") = 0 then
6408 -- Case of dot replacement is a single dot, and first character of
6409 -- suffix is also a dot.
6411 if Get_Name_String (Dot_Replacement) = "."
6412 and then Suffix_Str (Suffix_Str'First) = '.'
6414 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
6416 -- Case of following dot
6418 if Suffix_Str (Index) = '.' then
6420 -- It is illegal to have a letter following the initial dot
6422 return Is_Letter (Suffix_Str (Suffix_Str'First + 1));
6428 end Is_Illegal_Suffix;
6430 ----------------------
6431 -- Locate_Directory --
6432 ----------------------
6434 procedure Locate_Directory
6435 (Project : Project_Id;
6436 In_Tree : Project_Tree_Ref;
6437 Name : File_Name_Type;
6438 Path : out Path_Information;
6439 Dir_Exists : out Boolean;
6440 Create : String := "";
6441 Location : Source_Ptr := No_Location;
6442 Must_Exist : Boolean := True;
6443 Externally_Built : Boolean := False)
6445 Parent : constant Path_Name_Type :=
6446 Project.Directory.Display_Name;
6447 The_Parent : constant String :=
6448 Get_Name_String (Parent) & Directory_Separator;
6449 The_Parent_Last : constant Natural :=
6450 Compute_Directory_Last (The_Parent);
6451 Full_Name : File_Name_Type;
6452 The_Name : File_Name_Type;
6455 Get_Name_String (Name);
6457 -- Add Subdirs.all if it is a directory that may be created and
6458 -- Subdirs is not null;
6460 if Create /= "" and then Subdirs /= null then
6461 if Name_Buffer (Name_Len) /= Directory_Separator then
6462 Add_Char_To_Name_Buffer (Directory_Separator);
6465 Add_Str_To_Name_Buffer (Subdirs.all);
6468 -- Convert '/' to directory separator (for Windows)
6470 for J in 1 .. Name_Len loop
6471 if Name_Buffer (J) = '/' then
6472 Name_Buffer (J) := Directory_Separator;
6476 The_Name := Name_Find;
6478 if Current_Verbosity = High then
6479 Write_Str ("Locate_Directory (""");
6480 Write_Str (Get_Name_String (The_Name));
6481 Write_Str (""", """);
6482 Write_Str (The_Parent);
6486 Path := No_Path_Information;
6487 Dir_Exists := False;
6489 if Is_Absolute_Path (Get_Name_String (The_Name)) then
6490 Full_Name := The_Name;
6494 Add_Str_To_Name_Buffer
6495 (The_Parent (The_Parent'First .. The_Parent_Last));
6496 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
6497 Full_Name := Name_Find;
6501 Full_Path_Name : String_Access :=
6502 new String'(Get_Name_String (Full_Name));
6505 if (Setup_Projects or else Subdirs /= null)
6506 and then Create'Length > 0
6508 if not Is_Directory (Full_Path_Name.all) then
6510 -- If project is externally built, do not create a subdir,
6511 -- use the specified directory, without the subdir.
6513 if Externally_Built then
6514 if Is_Absolute_Path (Get_Name_String (Name)) then
6515 Get_Name_String (Name);
6519 Add_Str_To_Name_Buffer
6520 (The_Parent (The_Parent'First .. The_Parent_Last));
6521 Add_Str_To_Name_Buffer (Get_Name_String (Name));
6524 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
6528 Create_Path (Full_Path_Name.all);
6530 if not Quiet_Output then
6532 Write_Str (" directory """);
6533 Write_Str (Full_Path_Name.all);
6534 Write_Str (""" created for project ");
6535 Write_Line (Get_Name_String (Project.Name));
6542 "could not create " & Create &
6543 " directory " & Full_Path_Name.all,
6550 Dir_Exists := Is_Directory (Full_Path_Name.all);
6552 if not Must_Exist or else Dir_Exists then
6554 Normed : constant String :=
6556 (Full_Path_Name.all,
6558 The_Parent (The_Parent'First .. The_Parent_Last),
6559 Resolve_Links => False,
6560 Case_Sensitive => True);
6562 Canonical_Path : constant String :=
6567 (The_Parent'First .. The_Parent_Last),
6569 Opt.Follow_Links_For_Dirs,
6570 Case_Sensitive => False);
6573 Name_Len := Normed'Length;
6574 Name_Buffer (1 .. Name_Len) := Normed;
6575 Path.Display_Name := Name_Find;
6577 Name_Len := Canonical_Path'Length;
6578 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6579 Path.Name := Name_Find;
6583 Free (Full_Path_Name);
6585 end Locate_Directory;
6587 ---------------------------
6588 -- Find_Excluded_Sources --
6589 ---------------------------
6591 procedure Find_Excluded_Sources
6592 (Project : Project_Id;
6593 In_Tree : Project_Tree_Ref)
6595 Excluded_Source_List_File : constant Variable_Value :=
6597 (Name_Excluded_Source_List_File,
6598 Project.Decl.Attributes,
6601 Excluded_Sources : Variable_Value := Util.Value_Of
6602 (Name_Excluded_Source_Files,
6603 Project.Decl.Attributes,
6606 Current : String_List_Id;
6607 Element : String_Element;
6608 Location : Source_Ptr;
6609 Name : File_Name_Type;
6610 File : Prj.Util.Text_File;
6611 Line : String (1 .. 300);
6613 Locally_Removed : Boolean := False;
6616 -- If Excluded_Source_Files is not declared, check
6617 -- Locally_Removed_Files.
6619 if Excluded_Sources.Default then
6620 Locally_Removed := True;
6623 (Name_Locally_Removed_Files, Project.Decl.Attributes, In_Tree);
6626 Excluded_Sources_Htable.Reset;
6628 -- If there are excluded sources, put them in the table
6630 if not Excluded_Sources.Default then
6631 if not Excluded_Source_List_File.Default then
6632 if Locally_Removed then
6635 "?both attributes Locally_Removed_Files and " &
6636 "Excluded_Source_List_File are present",
6637 Excluded_Source_List_File.Location);
6641 "?both attributes Excluded_Source_Files and " &
6642 "Excluded_Source_List_File are present",
6643 Excluded_Source_List_File.Location);
6647 Current := Excluded_Sources.Values;
6648 while Current /= Nil_String loop
6649 Element := In_Tree.String_Elements.Table (Current);
6650 Name := Canonical_Case_File_Name (Element.Value);
6652 -- If the element has no location, then use the location of
6653 -- Excluded_Sources to report possible errors.
6655 if Element.Location = No_Location then
6656 Location := Excluded_Sources.Location;
6658 Location := Element.Location;
6661 Excluded_Sources_Htable.Set (Name, (Name, False, Location));
6662 Current := Element.Next;
6665 elsif not Excluded_Source_List_File.Default then
6666 Location := Excluded_Source_List_File.Location;
6669 Source_File_Path_Name : constant String :=
6672 (Excluded_Source_List_File.Value),
6673 Project.Directory.Name);
6676 if Source_File_Path_Name'Length = 0 then
6677 Err_Vars.Error_Msg_File_1 :=
6678 File_Name_Type (Excluded_Source_List_File.Value);
6681 "file with excluded sources { does not exist",
6682 Excluded_Source_List_File.Location);
6687 Prj.Util.Open (File, Source_File_Path_Name);
6689 if not Prj.Util.Is_Valid (File) then
6691 (Project, In_Tree, "file does not exist", Location);
6693 -- Read the lines one by one
6695 while not Prj.Util.End_Of_File (File) loop
6696 Prj.Util.Get_Line (File, Line, Last);
6698 -- Non empty, non comment line should contain a file name
6701 and then (Last = 1 or else Line (1 .. 2) /= "--")
6704 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6705 Canonical_Case_File_Name
6706 (Name_Buffer (1 .. Name_Len));
6709 -- Check that there is no directory information
6711 for J in 1 .. Last loop
6713 or else Line (J) = Directory_Separator
6715 Error_Msg_File_1 := Name;
6719 "file name cannot include " &
6720 "directory information ({)",
6726 Excluded_Sources_Htable.Set
6727 (Name, (Name, False, Location));
6731 Prj.Util.Close (File);
6736 end Find_Excluded_Sources;
6742 procedure Find_Sources
6743 (Project : Project_Id;
6744 In_Tree : Project_Tree_Ref;
6745 Proc_Data : in out Processing_Data)
6747 Sources : constant Variable_Value :=
6750 Project.Decl.Attributes,
6752 Source_List_File : constant Variable_Value :=
6754 (Name_Source_List_File,
6755 Project.Decl.Attributes,
6757 Name_Loc : Name_Location;
6759 Has_Explicit_Sources : Boolean;
6762 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6764 (Source_List_File.Kind = Single,
6765 "Source_List_File is not a single string");
6767 -- If the user has specified a Source_Files attribute
6769 if not Sources.Default then
6770 if not Source_List_File.Default then
6773 "?both attributes source_files and " &
6774 "source_list_file are present",
6775 Source_List_File.Location);
6778 -- Sources is a list of file names
6781 Current : String_List_Id := Sources.Values;
6782 Element : String_Element;
6783 Location : Source_Ptr;
6784 Name : File_Name_Type;
6787 if Get_Mode = Multi_Language then
6788 if Current = Nil_String then
6789 Project.Languages := No_Language_Index;
6791 -- This project contains no source. For projects that don't
6792 -- extend other projects, this also means that there is no
6793 -- need for an object directory, if not specified.
6795 if Project.Extends = No_Project
6796 and then Project.Object_Directory = Project.Directory
6798 Project.Object_Directory := No_Path_Information;
6803 while Current /= Nil_String loop
6804 Element := In_Tree.String_Elements.Table (Current);
6805 Name := Canonical_Case_File_Name (Element.Value);
6806 Get_Name_String (Element.Value);
6808 -- If the element has no location, then use the location of
6809 -- Sources to report possible errors.
6811 if Element.Location = No_Location then
6812 Location := Sources.Location;
6814 Location := Element.Location;
6817 -- Check that there is no directory information
6819 for J in 1 .. Name_Len loop
6820 if Name_Buffer (J) = '/'
6821 or else Name_Buffer (J) = Directory_Separator
6823 Error_Msg_File_1 := Name;
6827 "file name cannot include directory " &
6834 -- In Multi_Language mode, check whether the file is already
6835 -- there: the same file name may be in the list. If the source
6836 -- is missing, the error will be on the first mention of the
6837 -- source file name.
6841 Name_Loc := No_Name_Location;
6842 when Multi_Language =>
6843 Name_Loc := Source_Names.Get (Name);
6846 if Name_Loc = No_Name_Location then
6849 Location => Location,
6850 Source => No_Source,
6853 Source_Names.Set (Name, Name_Loc);
6856 Current := Element.Next;
6859 Has_Explicit_Sources := True;
6862 -- If we have no Source_Files attribute, check the Source_List_File
6865 elsif not Source_List_File.Default then
6867 -- Source_List_File is the name of the file that contains the source
6871 Source_File_Path_Name : constant String :=
6873 (File_Name_Type (Source_List_File.Value),
6874 Project.Directory.Name);
6877 Has_Explicit_Sources := True;
6879 if Source_File_Path_Name'Length = 0 then
6880 Err_Vars.Error_Msg_File_1 :=
6881 File_Name_Type (Source_List_File.Value);
6884 "file with sources { does not exist",
6885 Source_List_File.Location);
6888 Get_Sources_From_File
6889 (Source_File_Path_Name, Source_List_File.Location,
6895 -- Neither Source_Files nor Source_List_File has been specified. Find
6896 -- all the files that satisfy the naming scheme in all the source
6899 Has_Explicit_Sources := False;
6902 if Get_Mode = Ada_Only then
6904 (Project, In_Tree, Explicit_Sources_Only => Has_Explicit_Sources,
6905 Proc_Data => Proc_Data);
6911 Sources.Default and then Source_List_File.Default);
6914 -- Check if all exceptions have been found. For Ada, it is an error if
6915 -- an exception is not found. For other language, the source is simply
6920 Iter : Source_Iterator;
6923 Iter := For_Each_Source (In_Tree, Project);
6925 Source := Prj.Element (Iter);
6926 exit when Source = No_Source;
6928 if Source.Naming_Exception
6929 and then Source.Path = No_Path_Information
6931 if Source.Unit /= No_Name then
6932 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6933 Error_Msg_Name_2 := Name_Id (Source.Unit);
6936 "source file %% for unit %% not found",
6940 Remove_Source (Source, No_Source);
6947 -- It is an error if a source file name in a source list or in a source
6948 -- list file is not found.
6950 if Has_Explicit_Sources then
6953 First_Error : Boolean;
6956 NL := Source_Names.Get_First;
6957 First_Error := True;
6958 while NL /= No_Name_Location loop
6959 if not NL.Found then
6960 Err_Vars.Error_Msg_File_1 := NL.Name;
6965 "source file { not found",
6967 First_Error := False;
6972 "\source file { not found",
6977 NL := Source_Names.Get_Next;
6982 if Get_Mode = Ada_Only
6983 and then Project.Extends = No_Project
6985 -- We should have found at least one source, if not report an error
6987 if not Has_Ada_Sources (Project) then
6989 (Project, "Ada", In_Tree, Source_List_File.Location);
6998 procedure Initialize (Proc_Data : in out Processing_Data) is
7000 Files_Htable.Reset (Proc_Data.Units);
7007 procedure Free (Proc_Data : in out Processing_Data) is
7009 Files_Htable.Reset (Proc_Data.Units);
7012 ----------------------
7013 -- Find_Ada_Sources --
7014 ----------------------
7016 procedure Find_Ada_Sources
7017 (Project : Project_Id;
7018 In_Tree : Project_Tree_Ref;
7019 Explicit_Sources_Only : Boolean;
7020 Proc_Data : in out Processing_Data)
7022 Source_Dir : String_List_Id;
7023 Element : String_Element;
7025 Dir_Has_Source : Boolean := False;
7027 Ada_Language : Language_Ptr;
7030 if Current_Verbosity = High then
7031 Write_Line ("Looking for Ada sources:");
7034 Ada_Language := Project.Languages;
7035 while Ada_Language /= No_Language_Index
7036 and then Ada_Language.Name /= Name_Ada
7038 Ada_Language := Ada_Language.Next;
7041 -- We look in all source directories for the file names in the hash
7042 -- table Source_Names.
7044 Source_Dir := Project.Source_Dirs;
7045 while Source_Dir /= Nil_String loop
7046 Dir_Has_Source := False;
7047 Element := In_Tree.String_Elements.Table (Source_Dir);
7050 Dir_Path : constant String :=
7051 Get_Name_String (Element.Display_Value) &
7052 Directory_Separator;
7053 Dir_Last : constant Natural := Compute_Directory_Last (Dir_Path);
7056 if Current_Verbosity = High then
7057 Write_Line ("checking directory """ & Dir_Path & """");
7060 -- Look for all files in the current source directory
7062 Open (Dir, Dir_Path (Dir_Path'First .. Dir_Last));
7065 Read (Dir, Name_Buffer, Name_Len);
7066 exit when Name_Len = 0;
7068 if Current_Verbosity = High then
7069 Write_Line (" Checking " & Name_Buffer (1 .. Name_Len));
7073 Name : constant File_Name_Type := Name_Find;
7074 Canonical_Name : File_Name_Type;
7076 -- ??? We could probably optimize the following call: we
7077 -- need to resolve links only once for the directory itself,
7078 -- and then do a single call to readlink() for each file.
7079 -- Unfortunately that would require a change in
7080 -- Normalize_Pathname so that it has the option of not
7081 -- resolving links for its Directory parameter, only for
7084 Path : constant String :=
7086 (Name => Name_Buffer (1 .. Name_Len),
7087 Directory => Dir_Path (Dir_Path'First .. Dir_Last),
7088 Resolve_Links => Opt.Follow_Links_For_Files,
7089 Case_Sensitive => True); -- no case folding
7091 Path_Name : Path_Name_Type;
7092 To_Record : Boolean := False;
7093 Location : Source_Ptr;
7096 -- If the file was listed in the explicit list of sources,
7097 -- mark it as such (since we'll need to report an error when
7098 -- an explicit source was not found)
7100 if Explicit_Sources_Only then
7102 Canonical_Case_File_Name (Name_Id (Name));
7103 NL := Source_Names.Get (Canonical_Name);
7104 To_Record := NL /= No_Name_Location and then not NL.Found;
7108 Location := NL.Location;
7109 Source_Names.Set (Canonical_Name, NL);
7114 Location := No_Location;
7118 Name_Len := Path'Length;
7119 Name_Buffer (1 .. Name_Len) := Path;
7120 Path_Name := Name_Find;
7122 if Current_Verbosity = High then
7123 Write_Line (" recording " & Get_Name_String (Name));
7126 -- Register the source if it is an Ada compilation unit
7130 Path_Name => Path_Name,
7133 Proc_Data => Proc_Data,
7134 Ada_Language => Ada_Language,
7135 Location => Location,
7136 Source_Recorded => Dir_Has_Source);
7149 if Dir_Has_Source then
7150 In_Tree.String_Elements.Table (Source_Dir).Flag := True;
7153 Source_Dir := Element.Next;
7156 if Current_Verbosity = High then
7157 Write_Line ("End looking for sources");
7159 end Find_Ada_Sources;
7161 -------------------------------
7162 -- Check_File_Naming_Schemes --
7163 -------------------------------
7165 procedure Check_File_Naming_Schemes
7166 (In_Tree : Project_Tree_Ref;
7167 Project : Project_Id;
7168 File_Name : File_Name_Type;
7169 Alternate_Languages : out Language_List;
7170 Language : out Language_Ptr;
7171 Display_Language_Name : out Name_Id;
7173 Lang_Kind : out Language_Kind;
7174 Kind : out Source_Kind)
7176 Filename : constant String := Get_Name_String (File_Name);
7177 Config : Language_Config;
7178 Tmp_Lang : Language_Ptr;
7180 Header_File : Boolean := False;
7181 -- True if we found at least one language for which the file is a header
7182 -- In such a case, we search for all possible languages where this is
7183 -- also a header (C and C++ for instance), since the file might be used
7184 -- for several such languages.
7186 procedure Check_File_Based_Lang;
7187 -- Does the naming scheme test for file-based languages. For those,
7188 -- there is no Unit. Just check if the file name has the implementation
7189 -- or, if it is specified, the template suffix of the language.
7191 -- Returns True if the file belongs to the current language and we
7192 -- should stop searching for matching languages. Not that a given header
7193 -- file could belong to several languages (C and C++ for instance). Thus
7194 -- if we found a header we'll check whether it matches other languages.
7196 ---------------------------
7197 -- Check_File_Based_Lang --
7198 ---------------------------
7200 procedure Check_File_Based_Lang is
7203 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
7207 Language := Tmp_Lang;
7209 if Current_Verbosity = High then
7210 Write_Str (" implementation of language ");
7211 Write_Line (Get_Name_String (Display_Language_Name));
7214 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
7215 if Current_Verbosity = High then
7216 Write_Str (" header of language ");
7217 Write_Line (Get_Name_String (Display_Language_Name));
7221 Alternate_Languages := new Language_List_Element'
7222 (Language => Language,
7223 Next => Alternate_Languages);
7226 Header_File := True;
7229 Language := Tmp_Lang;
7232 end Check_File_Based_Lang;
7234 -- Start of processing for Check_File_Naming_Schemes
7237 Language := No_Language_Index;
7238 Alternate_Languages := null;
7239 Display_Language_Name := No_Name;
7241 Lang_Kind := File_Based;
7244 Tmp_Lang := Project.Languages;
7245 while Tmp_Lang /= No_Language_Index loop
7246 if Current_Verbosity = High then
7248 (" Testing language "
7249 & Get_Name_String (Tmp_Lang.Name)
7250 & " Header_File=" & Header_File'Img);
7253 Display_Language_Name := Tmp_Lang.Display_Name;
7254 Config := Tmp_Lang.Config;
7255 Lang_Kind := Config.Kind;
7259 Check_File_Based_Lang;
7260 exit when Kind = Impl;
7264 -- We know it belongs to a least a file_based language, no
7265 -- need to check unit-based ones.
7267 if not Header_File then
7269 (File_Name => File_Name,
7270 Dot_Replacement => Config.Naming_Data.Dot_Replacement,
7271 Separate_Suffix => Config.Naming_Data.Separate_Suffix,
7272 Body_Suffix => Config.Naming_Data.Body_Suffix,
7273 Spec_Suffix => Config.Naming_Data.Spec_Suffix,
7274 Casing => Config.Naming_Data.Casing,
7277 In_Tree => In_Tree);
7279 if Unit /= No_Name then
7280 Language := Tmp_Lang;
7286 Tmp_Lang := Tmp_Lang.Next;
7289 if Language = No_Language_Index
7290 and then Current_Verbosity = High
7292 Write_Line (" not a source of any language");
7294 end Check_File_Naming_Schemes;
7300 procedure Check_File
7301 (Project : Project_Id;
7302 In_Tree : Project_Tree_Ref;
7303 Path : Path_Name_Type;
7304 File_Name : File_Name_Type;
7305 Display_File_Name : File_Name_Type;
7306 For_All_Sources : Boolean)
7308 Canonical_Path : constant Path_Name_Type :=
7310 (Canonical_Case_File_Name (Name_Id (Path)));
7312 Name_Loc : Name_Location := Source_Names.Get (File_Name);
7313 Check_Name : Boolean := False;
7314 Alternate_Languages : Language_List;
7315 Language : Language_Ptr;
7317 Other_Part : Source_Id;
7319 Src_Ind : Source_File_Index;
7321 Source_To_Replace : Source_Id := No_Source;
7322 Display_Language_Name : Name_Id;
7323 Lang_Kind : Language_Kind;
7324 Kind : Source_Kind := Spec;
7325 Iter : Source_Iterator;
7328 if Name_Loc = No_Name_Location then
7329 Check_Name := For_All_Sources;
7332 if Name_Loc.Found then
7334 -- Check if it is OK to have the same file name in several
7335 -- source directories.
7337 if not Project.Known_Order_Of_Source_Dirs then
7338 Error_Msg_File_1 := File_Name;
7341 "{ is found in several source directories",
7346 Name_Loc.Found := True;
7348 Source_Names.Set (File_Name, Name_Loc);
7350 if Name_Loc.Source = No_Source then
7354 Name_Loc.Source.Path := (Canonical_Path, Path);
7356 Source_Paths_Htable.Set
7357 (In_Tree.Source_Paths_HT,
7361 -- Check if this is a subunit
7363 if Name_Loc.Source.Unit /= No_Name
7364 and then Name_Loc.Source.Kind = Impl
7366 Src_Ind := Sinput.P.Load_Project_File
7367 (Get_Name_String (Canonical_Path));
7369 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7370 Name_Loc.Source.Kind := Sep;
7378 Other_Part := No_Source;
7380 Check_File_Naming_Schemes
7381 (In_Tree => In_Tree,
7383 File_Name => File_Name,
7384 Alternate_Languages => Alternate_Languages,
7385 Language => Language,
7386 Display_Language_Name => Display_Language_Name,
7388 Lang_Kind => Lang_Kind,
7391 if Language = No_Language_Index then
7393 -- A file name in a list must be a source of a language
7395 if Name_Loc.Found then
7396 Error_Msg_File_1 := File_Name;
7400 "language unknown for {",
7405 -- Check if the same file name or unit is used in the prj tree
7407 Iter := For_Each_Source (In_Tree);
7410 Source := Prj.Element (Iter);
7411 exit when Source = No_Source;
7414 and then Source.Unit = Unit
7416 ((Source.Kind = Spec and then Kind = Impl)
7418 (Source.Kind = Impl and then Kind = Spec))
7420 Other_Part := Source;
7422 elsif (Unit /= No_Name
7423 and then Source.Unit = Unit
7427 (Source.Kind = Sep and then Kind = Impl)
7429 (Source.Kind = Impl and then Kind = Sep)))
7431 (Unit = No_Name and then Source.File = File_Name)
7433 -- Duplication of file/unit in same project is only
7434 -- allowed if order of source directories is known.
7436 if Project = Source.Project then
7437 if Project.Known_Order_Of_Source_Dirs then
7440 elsif Unit /= No_Name then
7441 Error_Msg_Name_1 := Unit;
7443 (Project, In_Tree, "duplicate unit %%",
7448 Error_Msg_File_1 := File_Name;
7450 (Project, In_Tree, "duplicate source file name {",
7455 -- Do not allow the same unit name in different projects,
7456 -- except if one is extending the other.
7458 -- For a file based language, the same file name replaces
7459 -- a file in a project being extended, but it is allowed
7460 -- to have the same file name in unrelated projects.
7462 elsif Is_Extending (Project, Source.Project) then
7463 Source_To_Replace := Source;
7465 elsif Unit /= No_Name
7466 and then not Source.Locally_Removed
7468 Error_Msg_Name_1 := Unit;
7471 "unit %% cannot belong to several projects",
7474 Error_Msg_Name_1 := Project.Name;
7475 Error_Msg_Name_2 := Name_Id (Path);
7477 (Project, In_Tree, "\ project %%, %%", No_Location);
7479 Error_Msg_Name_1 := Source.Project.Name;
7480 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
7482 (Project, In_Tree, "\ project %%, %%", No_Location);
7496 Lang_Id => Language,
7497 Lang_Kind => Lang_Kind,
7499 Alternate_Languages => Alternate_Languages,
7500 File_Name => File_Name,
7501 Display_File => Display_File_Name,
7502 Other_Part => Other_Part,
7504 Path => (Canonical_Path, Path),
7505 Source_To_Replace => Source_To_Replace);
7511 ------------------------
7512 -- Search_Directories --
7513 ------------------------
7515 procedure Search_Directories
7516 (Project : Project_Id;
7517 In_Tree : Project_Tree_Ref;
7518 For_All_Sources : Boolean)
7520 Source_Dir : String_List_Id;
7521 Element : String_Element;
7523 Name : String (1 .. 1_000);
7525 File_Name : File_Name_Type;
7526 Display_File_Name : File_Name_Type;
7529 if Current_Verbosity = High then
7530 Write_Line ("Looking for sources:");
7533 -- Loop through subdirectories
7535 Source_Dir := Project.Source_Dirs;
7536 while Source_Dir /= Nil_String loop
7538 Element := In_Tree.String_Elements.Table (Source_Dir);
7539 if Element.Value /= No_Name then
7540 Get_Name_String (Element.Display_Value);
7543 Source_Directory : constant String :=
7544 Name_Buffer (1 .. Name_Len) &
7545 Directory_Separator;
7547 Dir_Last : constant Natural :=
7548 Compute_Directory_Last
7552 if Current_Verbosity = High then
7553 Write_Attr ("Source_Dir", Source_Directory);
7556 -- We look to every entry in the source directory
7558 Open (Dir, Source_Directory);
7561 Read (Dir, Name, Last);
7565 -- ??? Duplicate system call here, we just did a
7566 -- a similar one. Maybe Ada.Directories would be more
7570 (Source_Directory & Name (1 .. Last))
7572 if Current_Verbosity = High then
7573 Write_Str (" Checking ");
7574 Write_Line (Name (1 .. Last));
7578 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7579 Display_File_Name := Name_Find;
7581 if Osint.File_Names_Case_Sensitive then
7582 File_Name := Display_File_Name;
7584 Canonical_Case_File_Name
7585 (Name_Buffer (1 .. Name_Len));
7586 File_Name := Name_Find;
7590 Path_Name : constant String :=
7593 Directory => Source_Directory
7594 (Source_Directory'First .. Dir_Last),
7595 Resolve_Links => Opt.Follow_Links_For_Files,
7596 Case_Sensitive => True); -- no folding
7598 Path : Path_Name_Type;
7600 Excluded_Sources_Htable.Get (File_Name);
7603 Name_Len := Path_Name'Length;
7604 Name_Buffer (1 .. Name_Len) := Path_Name;
7607 if FF /= No_File_Found then
7608 if not FF.Found then
7610 Excluded_Sources_Htable.Set (File_Name, FF);
7612 if Current_Verbosity = High then
7613 Write_Str (" excluded source """);
7614 Write_Str (Get_Name_String (File_Name));
7621 (Project => Project,
7624 File_Name => File_Name,
7625 Display_File_Name => Display_File_Name,
7626 For_All_Sources => For_All_Sources);
7637 when Directory_Error =>
7641 Source_Dir := Element.Next;
7644 if Current_Verbosity = High then
7645 Write_Line ("end Looking for sources.");
7647 end Search_Directories;
7649 ----------------------------
7650 -- Load_Naming_Exceptions --
7651 ----------------------------
7653 procedure Load_Naming_Exceptions
7654 (Project : Project_Id;
7655 In_Tree : Project_Tree_Ref)
7658 Iter : Source_Iterator;
7661 Unit_Exceptions.Reset;
7663 Iter := For_Each_Source (In_Tree, Project);
7665 Source := Prj.Element (Iter);
7666 exit when Source = No_Source;
7668 -- An excluded file cannot also be an exception file name
7670 if Excluded_Sources_Htable.Get (Source.File) /= No_File_Found then
7671 Error_Msg_File_1 := Source.File;
7674 "{ cannot be both excluded and an exception file name",
7678 if Current_Verbosity = High then
7679 Write_Str ("Naming exception: Putting source file ");
7680 Write_Str (Get_Name_String (Source.File));
7681 Write_Line (" in Source_Names");
7687 (Name => Source.File,
7688 Location => No_Location,
7690 Except => Source.Unit /= No_Name,
7693 -- If this is an Ada exception, record in table Unit_Exceptions
7695 if Source.Unit /= No_Name then
7697 Unit_Except : Unit_Exception :=
7698 Unit_Exceptions.Get (Source.Unit);
7701 Unit_Except.Name := Source.Unit;
7703 if Source.Kind = Spec then
7704 Unit_Except.Spec := Source.File;
7706 Unit_Except.Impl := Source.File;
7709 Unit_Exceptions.Set (Source.Unit, Unit_Except);
7715 end Load_Naming_Exceptions;
7717 ----------------------
7718 -- Look_For_Sources --
7719 ----------------------
7721 procedure Look_For_Sources
7722 (Project : Project_Id;
7723 In_Tree : Project_Tree_Ref;
7724 Proc_Data : in out Processing_Data)
7726 Iter : Source_Iterator;
7728 procedure Process_Sources_In_Multi_Language_Mode;
7729 -- Find all source files when in multi language mode
7731 procedure Mark_Excluded_Sources;
7732 -- Mark as such the sources that are declared as excluded
7734 ---------------------------
7735 -- Mark_Excluded_Sources --
7736 ---------------------------
7738 procedure Mark_Excluded_Sources is
7739 Source : Source_Id := No_Source;
7742 Excluded : File_Found := Excluded_Sources_Htable.Get_First;
7745 (Extended : Project_Id;
7747 Kind : Spec_Or_Body);
7748 -- If the current file (Excluded) belongs to the current project or
7749 -- one that the current project extends, then mark this file/unit as
7750 -- excluded. It is an error to locally remove a file from another
7758 (Extended : Project_Id;
7760 Kind : Spec_Or_Body)
7763 if Extended = Project
7764 or else Is_Extending (Project, Extended)
7768 if Index /= No_Unit_Index then
7769 Unit.File_Names (Kind).Path.Name := Slash;
7770 Unit.File_Names (Kind).Naming_Exception := False;
7771 In_Tree.Units.Table (Index) := Unit;
7774 if Source /= No_Source then
7775 Source.Locally_Removed := True;
7776 Source.In_Interfaces := False;
7779 if Current_Verbosity = High then
7780 Write_Str ("Removing file ");
7781 Write_Line (Get_Name_String (Excluded.File));
7784 Add_Forbidden_File_Name (Excluded.File);
7789 "cannot remove a source from another project",
7794 -- Start of processing for Mark_Excluded_Sources
7797 while Excluded /= No_File_Found loop
7803 -- ??? This loop could be the same as for Multi_Language if
7804 -- we were setting In_Tree.First_Source when we search for
7805 -- Ada sources (basically once we have removed the use of
7806 -- Project.Ada_Sources).
7809 for Index in Unit_Table.First ..
7810 Unit_Table.Last (In_Tree.Units)
7812 Unit := In_Tree.Units.Table (Index);
7814 for Kind in Spec_Or_Body'Range loop
7815 if Unit.File_Names (Kind) /= null
7816 and then Unit.File_Names (Kind).File = Excluded.File
7818 Exclude (Unit.File_Names (Kind).Project, Index, Kind);
7822 end loop For_Each_Unit;
7824 when Multi_Language =>
7825 Iter := For_Each_Source (In_Tree);
7827 Source := Prj.Element (Iter);
7828 exit when Source = No_Source;
7830 if Source.File = Excluded.File then
7831 Exclude (Source.Project, No_Unit_Index, Spec);
7838 OK := OK or Excluded.Found;
7842 Err_Vars.Error_Msg_File_1 := Excluded.File;
7844 (Project, In_Tree, "unknown file {", Excluded.Location);
7847 Excluded := Excluded_Sources_Htable.Get_Next;
7849 end Mark_Excluded_Sources;
7851 --------------------------------------------
7852 -- Process_Sources_In_Multi_Language_Mode --
7853 --------------------------------------------
7855 procedure Process_Sources_In_Multi_Language_Mode is
7856 Iter : Source_Iterator;
7858 -- Check that two sources of this project do not have the same object
7861 Check_Object_File_Names : declare
7863 Source_Name : File_Name_Type;
7865 procedure Check_Object (Src : Source_Id);
7866 -- Check if object file name of the current source is already in
7867 -- hash table Object_File_Names. If it is, report an error. If it
7868 -- is not, put it there with the file name of the current source.
7874 procedure Check_Object (Src : Source_Id) is
7876 Source_Name := Object_File_Names.Get (Src.Object);
7878 if Source_Name /= No_File then
7879 Error_Msg_File_1 := Src.File;
7880 Error_Msg_File_2 := Source_Name;
7884 "{ and { have the same object file name",
7888 Object_File_Names.Set (Src.Object, Src.File);
7892 -- Start of processing for Check_Object_File_Names
7895 Object_File_Names.Reset;
7896 Iter := For_Each_Source (In_Tree);
7898 Src_Id := Prj.Element (Iter);
7899 exit when Src_Id = No_Source;
7901 if Src_Id.Compiled and then Src_Id.Object_Exists
7902 and then Is_Extending (Project, Src_Id.Project)
7904 if Src_Id.Unit = No_Name then
7905 if Src_Id.Kind = Impl then
7906 Check_Object (Src_Id);
7912 if Src_Id.Other_Part = No_Source then
7913 Check_Object (Src_Id);
7920 if Src_Id.Other_Part /= No_Source then
7921 Check_Object (Src_Id);
7924 -- Check if it is a subunit
7927 Src_Ind : constant Source_File_Index :=
7928 Sinput.P.Load_Project_File
7930 (Src_Id.Path.Name));
7932 if Sinput.P.Source_File_Is_Subunit
7937 Check_Object (Src_Id);
7947 end Check_Object_File_Names;
7948 end Process_Sources_In_Multi_Language_Mode;
7950 -- Start of processing for Look_For_Sources
7954 Find_Excluded_Sources (Project, In_Tree);
7956 if (Get_Mode = Ada_Only and then Is_A_Language (Project, Name_Ada))
7957 or else (Get_Mode = Multi_Language
7958 and then Project.Languages /= No_Language_Index)
7960 if Get_Mode = Multi_Language then
7961 Load_Naming_Exceptions (Project, In_Tree);
7964 Find_Sources (Project, In_Tree, Proc_Data);
7965 Mark_Excluded_Sources;
7967 if Get_Mode = Multi_Language then
7968 Process_Sources_In_Multi_Language_Mode;
7971 end Look_For_Sources;
7977 function Path_Name_Of
7978 (File_Name : File_Name_Type;
7979 Directory : Path_Name_Type) return String
7981 Result : String_Access;
7982 The_Directory : constant String := Get_Name_String (Directory);
7985 Get_Name_String (File_Name);
7988 (File_Name => Name_Buffer (1 .. Name_Len),
7989 Path => The_Directory);
7991 if Result = null then
7995 R : String := Result.all;
7998 Canonical_Case_File_Name (R);
8004 -----------------------------------
8005 -- Prepare_Ada_Naming_Exceptions --
8006 -----------------------------------
8008 procedure Prepare_Ada_Naming_Exceptions
8009 (List : Array_Element_Id;
8010 In_Tree : Project_Tree_Ref;
8011 Kind : Spec_Or_Body)
8013 Current : Array_Element_Id;
8014 Element : Array_Element;
8018 -- Traverse the list
8021 while Current /= No_Array_Element loop
8022 Element := In_Tree.Array_Elements.Table (Current);
8024 if Element.Index /= No_Name then
8027 Unit => Element.Index,
8028 Next => No_Ada_Naming_Exception);
8029 Reverse_Ada_Naming_Exceptions.Set
8030 (Unit, (Element.Value.Value, Element.Value.Index));
8032 Ada_Naming_Exceptions.Get (File_Name_Type (Element.Value.Value));
8033 Ada_Naming_Exception_Table.Increment_Last;
8034 Ada_Naming_Exception_Table.Table
8035 (Ada_Naming_Exception_Table.Last) := Unit;
8036 Ada_Naming_Exceptions.Set
8037 (File_Name_Type (Element.Value.Value),
8038 Ada_Naming_Exception_Table.Last);
8041 Current := Element.Next;
8043 end Prepare_Ada_Naming_Exceptions;
8045 -----------------------
8046 -- Record_Ada_Source --
8047 -----------------------
8049 procedure Record_Ada_Source
8050 (File_Name : File_Name_Type;
8051 Path_Name : Path_Name_Type;
8052 Project : Project_Id;
8053 In_Tree : Project_Tree_Ref;
8054 Proc_Data : in out Processing_Data;
8055 Ada_Language : Language_Ptr;
8056 Location : Source_Ptr;
8057 Source_Recorded : in out Boolean)
8059 Canonical_File : File_Name_Type;
8060 Canonical_Path : Path_Name_Type;
8062 File_Recorded : Boolean := False;
8063 -- True when at least one file has been recorded
8065 procedure Record_Unit
8066 (Unit_Name : Name_Id;
8067 Unit_Ind : Int := 0;
8068 Unit_Kind : Spec_Or_Body;
8069 Needs_Pragma : Boolean);
8070 -- Register of the units contained in the source file (there is in
8071 -- general a single such unit except when exceptions to the naming
8072 -- scheme indicate there are several such units)
8078 procedure Record_Unit
8079 (Unit_Name : Name_Id;
8080 Unit_Ind : Int := 0;
8081 Unit_Kind : Spec_Or_Body;
8082 Needs_Pragma : Boolean)
8084 The_Unit : Unit_Index :=
8085 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
8089 To_Record : Boolean := False;
8090 The_Location : Source_Ptr := Location;
8091 Unit_Prj : Project_Id;
8094 if Current_Verbosity = High then
8095 Write_Str (" Putting ");
8096 Write_Str (Get_Name_String (Unit_Name));
8097 Write_Line (" in the unit list.");
8100 -- The unit is already in the list, but may be it is only the other
8101 -- unit kind (spec or body), or what is in the unit list is a unit of
8102 -- a project we are extending.
8104 if The_Unit /= No_Unit_Index then
8105 UData := In_Tree.Units.Table (The_Unit);
8107 if UData.File_Names (Unit_Kind) = null
8109 ((UData.File_Names (Unit_Kind).File = Canonical_File
8110 and then UData.File_Names (Unit_Kind).Path.Name = Slash)
8111 or else UData.File_Names (Unit_Kind).File = No_File
8112 or else Is_Extending
8113 (Project.Extends, UData.File_Names (Unit_Kind).Project))
8115 if UData.File_Names (Unit_Kind) /= null
8116 and then UData.File_Names (Unit_Kind).Path.Name = Slash
8118 Remove_Forbidden_File_Name
8119 (UData.File_Names (Unit_Kind).File);
8123 Source_Recorded := True;
8125 -- If the same file is already in the list, do not add it again
8127 elsif UData.File_Names (Unit_Kind).Project = Project
8129 (Project.Known_Order_Of_Source_Dirs
8131 UData.File_Names (Unit_Kind).Path.Name = Canonical_Path)
8135 -- Else, same unit but not same file => It is an error to have two
8136 -- units with the same name and the same kind (spec or body).
8139 if The_Location = No_Location then
8140 The_Location := Project.Location;
8143 Err_Vars.Error_Msg_Name_1 := Unit_Name;
8145 (Project, In_Tree, "duplicate unit %%", The_Location);
8147 Err_Vars.Error_Msg_Name_1 :=
8148 UData.File_Names (Unit_Kind).Project.Name;
8149 Err_Vars.Error_Msg_File_1 :=
8150 File_Name_Type (UData.File_Names (Unit_Kind).Path.Name);
8153 "\ project file %%, {", The_Location);
8155 Err_Vars.Error_Msg_Name_1 := Project.Name;
8156 Err_Vars.Error_Msg_File_1 := File_Name_Type (Canonical_Path);
8158 (Project, In_Tree, "\ project file %%, {", The_Location);
8163 -- It is a new unit, create a new record
8166 -- First, check if there is no other unit with this file name in
8167 -- another project. If it is, report error but note we do that
8168 -- only for the first unit in the source file.
8170 Unit_Prj := Files_Htable.Get (Proc_Data.Units, Canonical_File);
8172 if not File_Recorded
8173 and then Unit_Prj /= No_Project
8175 Error_Msg_File_1 := File_Name;
8176 Error_Msg_Name_1 := Unit_Prj.Name;
8179 "{ is already a source of project %%",
8183 UData.Name := Unit_Name;
8184 Unit_Table.Increment_Last (In_Tree.Units);
8185 The_Unit := Unit_Table.Last (In_Tree.Units);
8186 Units_Htable.Set (In_Tree.Units_HT, Unit_Name, The_Unit);
8188 Source_Recorded := True;
8194 Files_Htable.Set (Proc_Data.Units, Canonical_File, Project);
8207 Lang_Id => Ada_Language,
8208 Lang_Kind => Unit_Based,
8209 File_Name => Canonical_File,
8210 Display_File => File_Name,
8212 Path => (Canonical_Path, Path_Name),
8213 Naming_Exception => Needs_Pragma,
8216 Other_Part => No_Source); -- ??? Can we find file ?
8218 UData.File_Names (Unit_Kind) := Source;
8219 In_Tree.Units.Table (The_Unit) := UData;
8223 Exception_Id : Ada_Naming_Exception_Id;
8224 Unit_Name : Name_Id;
8225 Unit_Kind : Spec_Or_Body;
8226 Unit_Ind : Int := 0;
8228 Name_Index : Name_And_Index;
8229 Except_Name : Name_And_Index := No_Name_And_Index;
8230 Needs_Pragma : Boolean;
8233 Canonical_File := Canonical_Case_File_Name (Name_Id (File_Name));
8235 Path_Name_Type (Canonical_Case_File_Name (Name_Id (Path_Name)));
8237 -- Check the naming scheme to get extra file properties
8240 (In_Tree => In_Tree,
8241 Canonical_File_Name => Canonical_File,
8242 Naming => Project.Naming,
8243 Exception_Id => Exception_Id,
8244 Unit_Name => Unit_Name,
8245 Unit_Kind => Unit_Kind);
8247 Needs_Pragma := Exception_Id /= No_Ada_Naming_Exception;
8249 if Exception_Id = No_Ada_Naming_Exception
8250 and then Unit_Name = No_Name
8252 if Current_Verbosity = High then
8254 Write_Str (Get_Name_String (Canonical_File));
8255 Write_Line (""" is not a valid source file name (ignored).");
8260 -- Check to see if the source has been hidden by an exception,
8261 -- but only if it is not an exception.
8263 if not Needs_Pragma then
8265 Reverse_Ada_Naming_Exceptions.Get
8266 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
8268 if Except_Name /= No_Name_And_Index then
8269 if Current_Verbosity = High then
8271 Write_Str (Get_Name_String (Canonical_File));
8272 Write_Str (""" contains a unit that is found in """);
8273 Write_Str (Get_Name_String (Except_Name.Name));
8274 Write_Line (""" (ignored).");
8277 -- The file is not included in the source of the project since it
8278 -- is hidden by the exception. So, nothing else to do.
8284 -- The following loop registers the unit in the appropriate table. It
8285 -- will be executed multiple times when the file is a multi-unit file,
8286 -- in which case Exception_Id initially points to the first file and
8287 -- then to each other unit in the file.
8290 if Exception_Id /= No_Ada_Naming_Exception then
8291 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
8292 Exception_Id := Info.Next;
8293 Info.Next := No_Ada_Naming_Exception;
8294 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
8296 Unit_Name := Info.Unit;
8297 Unit_Ind := Name_Index.Index;
8298 Unit_Kind := Info.Kind;
8301 Record_Unit (Unit_Name, Unit_Ind, Unit_Kind, Needs_Pragma);
8302 File_Recorded := True;
8304 exit when Exception_Id = No_Ada_Naming_Exception;
8306 end Record_Ada_Source;
8312 procedure Remove_Source
8314 Replaced_By : Source_Id)
8319 if Current_Verbosity = High then
8320 Write_Str ("Removing source ");
8321 Write_Line (Get_Name_String (Id.File));
8324 if Replaced_By /= No_Source then
8325 Id.Replaced_By := Replaced_By;
8326 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
8329 Source := Id.Language.First_Source;
8332 Id.Language.First_Source := Id.Next_In_Lang;
8335 while Source.Next_In_Lang /= Id loop
8336 Source := Source.Next_In_Lang;
8339 Source.Next_In_Lang := Id.Next_In_Lang;
8343 -----------------------
8344 -- Report_No_Sources --
8345 -----------------------
8347 procedure Report_No_Sources
8348 (Project : Project_Id;
8350 In_Tree : Project_Tree_Ref;
8351 Location : Source_Ptr;
8352 Continuation : Boolean := False)
8355 case When_No_Sources is
8359 when Warning | Error =>
8361 Msg : constant String :=
8364 " sources in this project";
8367 Error_Msg_Warn := When_No_Sources = Warning;
8369 if Continuation then
8370 Error_Msg (Project, In_Tree, "\" & Msg, Location);
8372 Error_Msg (Project, In_Tree, Msg, Location);
8376 end Report_No_Sources;
8378 ----------------------
8379 -- Show_Source_Dirs --
8380 ----------------------
8382 procedure Show_Source_Dirs
8383 (Project : Project_Id;
8384 In_Tree : Project_Tree_Ref)
8386 Current : String_List_Id;
8387 Element : String_Element;
8390 Write_Line ("Source_Dirs:");
8392 Current := Project.Source_Dirs;
8393 while Current /= Nil_String loop
8394 Element := In_Tree.String_Elements.Table (Current);
8396 Write_Line (Get_Name_String (Element.Value));
8397 Current := Element.Next;
8400 Write_Line ("end Source_Dirs.");
8401 end Show_Source_Dirs;
8403 -------------------------
8404 -- Warn_If_Not_Sources --
8405 -------------------------
8407 -- comments needed in this body ???
8409 procedure Warn_If_Not_Sources
8410 (Project : Project_Id;
8411 In_Tree : Project_Tree_Ref;
8412 Conventions : Array_Element_Id;
8414 Extending : Boolean)
8416 Conv : Array_Element_Id;
8418 The_Unit_Id : Unit_Index;
8419 The_Unit_Data : Unit_Data;
8420 Location : Source_Ptr;
8423 Conv := Conventions;
8424 while Conv /= No_Array_Element loop
8425 Unit := In_Tree.Array_Elements.Table (Conv).Index;
8426 Error_Msg_Name_1 := Unit;
8427 Get_Name_String (Unit);
8428 To_Lower (Name_Buffer (1 .. Name_Len));
8430 The_Unit_Id := Units_Htable.Get (In_Tree.Units_HT, Unit);
8431 Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
8433 if The_Unit_Id = No_Unit_Index then
8434 Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
8437 The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
8439 In_Tree.Array_Elements.Table (Conv).Value.Value;
8442 if not Check_Project
8443 (The_Unit_Data.File_Names (Spec).Project,
8448 "?source of spec of unit %% (%%)" &
8449 " not found in this project",
8454 if The_Unit_Data.File_Names (Impl) = null
8455 or else not Check_Project
8456 (The_Unit_Data.File_Names (Impl).Project,
8461 "?source of body of unit %% (%%)" &
8462 " not found in this project",
8468 Conv := In_Tree.Array_Elements.Table (Conv).Next;
8470 end Warn_If_Not_Sources;