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, Body_Part);
854 Prepare_Ada_Naming_Exceptions
855 (Project.Naming.Specs, In_Tree, Specification);
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_Specification_Suffix | Name_Spec_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
2981 (Name_Specification,
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_Specification_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 specification 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 (Body_Part).Name /= No_File
4546 UData.File_Names (Body_Part).Path.Name /=
4550 (UData.File_Names (Body_Part).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 (Specification).Name =
4561 Src_Ind : Source_File_Index;
4564 Src_Ind := Sinput.P.Load_Project_File
4567 (Body_Part).Path.Name));
4569 if Sinput.P.Source_File_Is_Subunit
4574 "%% is a subunit; " &
4575 "it cannot be an interface",
4577 String_Elements.Table
4578 (Interfaces).Location);
4583 -- The unit is not a subunit, so we add the
4584 -- ALI file for its body to the Interface ALIs.
4587 (UData.File_Names (Body_Part).Name);
4592 "%% is not an unit of this project",
4593 In_Tree.String_Elements.Table
4594 (Interfaces).Location);
4597 elsif UData.File_Names (Specification).Name /=
4599 and then UData.File_Names
4600 (Specification).Path.Name /= Slash
4601 and then Check_Project
4603 (Specification).Project,
4607 -- The unit is part of the project, it has a spec,
4608 -- but no body. We add the ALI for its spec to the
4612 (UData.File_Names (Specification).Name);
4617 "%% is not an unit of this project",
4618 In_Tree.String_Elements.Table
4619 (Interfaces).Location);
4624 -- Multi_Language mode
4626 Next_Proj := Project.Extends;
4628 Iter := For_Each_Source (In_Tree, Project);
4631 while Prj.Element (Iter) /= No_Source and then
4632 Prj.Element (Iter).Unit /= Unit
4637 Source := Prj.Element (Iter);
4638 exit when Source /= No_Source or else
4639 Next_Proj = No_Project;
4641 Iter := For_Each_Source (In_Tree, Next_Proj);
4642 Next_Proj := Next_Proj.Extends;
4645 if Source /= No_Source then
4646 if Source.Kind = Sep then
4647 Source := No_Source;
4649 elsif Source.Kind = Spec
4650 and then Source.Other_Part /= No_Source
4652 Source := Source.Other_Part;
4656 if Source /= No_Source then
4657 if Source.Project /= Project
4659 not Is_Extending (Project, Source.Project)
4661 Source := No_Source;
4665 if Source = No_Source then
4668 "%% is not an unit of this project",
4669 In_Tree.String_Elements.Table
4670 (Interfaces).Location);
4673 if Source.Kind = Spec and then
4674 Source.Other_Part /= No_Source
4676 Source := Source.Other_Part;
4679 String_Element_Table.Increment_Last
4680 (In_Tree.String_Elements);
4681 In_Tree.String_Elements.Table
4682 (String_Element_Table.Last
4683 (In_Tree.String_Elements)) :=
4684 (Value => Name_Id (Source.Dep_Name),
4686 Display_Value => Name_Id (Source.Dep_Name),
4688 In_Tree.String_Elements.Table
4689 (Interfaces).Location,
4691 Next => Interface_ALIs);
4692 Interface_ALIs := String_Element_Table.Last
4693 (In_Tree.String_Elements);
4701 In_Tree.String_Elements.Table (Interfaces).Next;
4704 -- Put the list of Interface ALIs in the project data
4706 Project.Lib_Interface_ALIs := Interface_ALIs;
4708 -- Check value of attribute Library_Auto_Init and set
4709 -- Lib_Auto_Init accordingly.
4711 if Lib_Auto_Init.Default then
4713 -- If no attribute Library_Auto_Init is declared, then set auto
4714 -- init only if it is supported.
4716 Project.Lib_Auto_Init := Auto_Init_Supported;
4719 Get_Name_String (Lib_Auto_Init.Value);
4720 To_Lower (Name_Buffer (1 .. Name_Len));
4722 if Name_Buffer (1 .. Name_Len) = "false" then
4723 Project.Lib_Auto_Init := False;
4725 elsif Name_Buffer (1 .. Name_Len) = "true" then
4726 if Auto_Init_Supported then
4727 Project.Lib_Auto_Init := True;
4730 -- Library_Auto_Init cannot be "true" if auto init is not
4735 "library auto init not supported " &
4737 Lib_Auto_Init.Location);
4743 "invalid value for attribute Library_Auto_Init",
4744 Lib_Auto_Init.Location);
4749 -- If attribute Library_Src_Dir is defined and not the empty string,
4750 -- check if the directory exist and is not the object directory or
4751 -- one of the source directories. This is the directory where copies
4752 -- of the interface sources will be copied. Note that this directory
4753 -- may be the library directory.
4755 if Lib_Src_Dir.Value /= Empty_String then
4757 Dir_Id : constant File_Name_Type :=
4758 File_Name_Type (Lib_Src_Dir.Value);
4759 Dir_Exists : Boolean;
4766 Path => Project.Library_Src_Dir,
4767 Dir_Exists => Dir_Exists,
4768 Must_Exist => False,
4769 Create => "library source copy",
4770 Location => Lib_Src_Dir.Location,
4771 Externally_Built => Project.Externally_Built);
4773 -- If directory does not exist, report an error
4775 if not Dir_Exists then
4776 -- Get the absolute name of the library directory that does
4777 -- not exist, to report an error.
4779 Err_Vars.Error_Msg_File_1 :=
4780 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4783 "Directory { does not exist",
4784 Lib_Src_Dir.Location);
4786 -- Report error if it is the same as the object directory
4788 elsif Project.Library_Src_Dir = Project.Object_Directory then
4791 "directory to copy interfaces cannot be " &
4792 "the object directory",
4793 Lib_Src_Dir.Location);
4794 Project.Library_Src_Dir := No_Path_Information;
4798 Src_Dirs : String_List_Id;
4799 Src_Dir : String_Element;
4803 -- Interface copy directory cannot be one of the source
4804 -- directory of the current project.
4806 Src_Dirs := Project.Source_Dirs;
4807 while Src_Dirs /= Nil_String loop
4808 Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
4810 -- Report error if it is one of the source directories
4812 if Project.Library_Src_Dir.Name =
4813 Path_Name_Type (Src_Dir.Value)
4817 "directory to copy interfaces cannot " &
4818 "be one of the source directories",
4819 Lib_Src_Dir.Location);
4820 Project.Library_Src_Dir := No_Path_Information;
4824 Src_Dirs := Src_Dir.Next;
4827 if Project.Library_Src_Dir /= No_Path_Information then
4829 -- It cannot be a source directory of any other
4832 Pid := In_Tree.Projects;
4834 exit Project_Loop when Pid = null;
4836 Src_Dirs := Pid.Project.Source_Dirs;
4837 Dir_Loop : while Src_Dirs /= Nil_String loop
4839 In_Tree.String_Elements.Table (Src_Dirs);
4841 -- Report error if it is one of the source
4844 if Project.Library_Src_Dir.Name =
4845 Path_Name_Type (Src_Dir.Value)
4848 File_Name_Type (Src_Dir.Value);
4849 Error_Msg_Name_1 := Pid.Project.Name;
4852 "directory to copy interfaces cannot " &
4853 "be the same as source directory { of " &
4855 Lib_Src_Dir.Location);
4856 Project.Library_Src_Dir :=
4857 No_Path_Information;
4861 Src_Dirs := Src_Dir.Next;
4865 end loop Project_Loop;
4869 -- In high verbosity, if there is a valid Library_Src_Dir,
4870 -- display its path name.
4872 if Project.Library_Src_Dir /= No_Path_Information
4873 and then Current_Verbosity = High
4876 ("Directory to copy interfaces",
4877 Get_Name_String (Project.Library_Src_Dir.Name));
4883 -- Check the symbol related attributes
4885 -- First, the symbol policy
4887 if not Lib_Symbol_Policy.Default then
4889 Value : constant String :=
4891 (Get_Name_String (Lib_Symbol_Policy.Value));
4894 -- Symbol policy must hove one of a limited number of values
4896 if Value = "autonomous" or else Value = "default" then
4897 Project.Symbol_Data.Symbol_Policy := Autonomous;
4899 elsif Value = "compliant" then
4900 Project.Symbol_Data.Symbol_Policy := Compliant;
4902 elsif Value = "controlled" then
4903 Project.Symbol_Data.Symbol_Policy := Controlled;
4905 elsif Value = "restricted" then
4906 Project.Symbol_Data.Symbol_Policy := Restricted;
4908 elsif Value = "direct" then
4909 Project.Symbol_Data.Symbol_Policy := Direct;
4914 "illegal value for Library_Symbol_Policy",
4915 Lib_Symbol_Policy.Location);
4920 -- If attribute Library_Symbol_File is not specified, symbol policy
4921 -- cannot be Restricted.
4923 if Lib_Symbol_File.Default then
4924 if Project.Symbol_Data.Symbol_Policy = Restricted then
4927 "Library_Symbol_File needs to be defined when " &
4928 "symbol policy is Restricted",
4929 Lib_Symbol_Policy.Location);
4933 -- Library_Symbol_File is defined
4935 Project.Symbol_Data.Symbol_File :=
4936 Path_Name_Type (Lib_Symbol_File.Value);
4938 Get_Name_String (Lib_Symbol_File.Value);
4940 if Name_Len = 0 then
4943 "symbol file name cannot be an empty string",
4944 Lib_Symbol_File.Location);
4947 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4950 for J in 1 .. Name_Len loop
4951 if Name_Buffer (J) = '/'
4952 or else Name_Buffer (J) = Directory_Separator
4961 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4964 "symbol file name { is illegal. " &
4965 "Name cannot include directory info.",
4966 Lib_Symbol_File.Location);
4971 -- If attribute Library_Reference_Symbol_File is not defined,
4972 -- symbol policy cannot be Compliant or Controlled.
4974 if Lib_Ref_Symbol_File.Default then
4975 if Project.Symbol_Data.Symbol_Policy = Compliant
4976 or else Project.Symbol_Data.Symbol_Policy = Controlled
4980 "a reference symbol file needs to be defined",
4981 Lib_Symbol_Policy.Location);
4985 -- Library_Reference_Symbol_File is defined, check file exists
4987 Project.Symbol_Data.Reference :=
4988 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4990 Get_Name_String (Lib_Ref_Symbol_File.Value);
4992 if Name_Len = 0 then
4995 "reference symbol file name cannot be an empty string",
4996 Lib_Symbol_File.Location);
4999 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
5001 Add_Str_To_Name_Buffer
5002 (Get_Name_String (Project.Directory.Name));
5003 Add_Char_To_Name_Buffer (Directory_Separator);
5004 Add_Str_To_Name_Buffer
5005 (Get_Name_String (Lib_Ref_Symbol_File.Value));
5006 Project.Symbol_Data.Reference := Name_Find;
5009 if not Is_Regular_File
5010 (Get_Name_String (Project.Symbol_Data.Reference))
5013 File_Name_Type (Lib_Ref_Symbol_File.Value);
5015 -- For controlled and direct symbol policies, it is an error
5016 -- if the reference symbol file does not exist. For other
5017 -- symbol policies, this is just a warning
5020 Project.Symbol_Data.Symbol_Policy /= Controlled
5021 and then Project.Symbol_Data.Symbol_Policy /= Direct;
5025 "<library reference symbol file { does not exist",
5026 Lib_Ref_Symbol_File.Location);
5028 -- In addition in the non-controlled case, if symbol policy
5029 -- is Compliant, it is changed to Autonomous, because there
5030 -- is no reference to check against, and we don't want to
5031 -- fail in this case.
5033 if Project.Symbol_Data.Symbol_Policy /= Controlled then
5034 if Project.Symbol_Data.Symbol_Policy = Compliant then
5035 Project.Symbol_Data.Symbol_Policy := Autonomous;
5040 -- If both the reference symbol file and the symbol file are
5041 -- defined, then check that they are not the same file.
5043 if Project.Symbol_Data.Symbol_File /= No_Path then
5044 Get_Name_String (Project.Symbol_Data.Symbol_File);
5046 if Name_Len > 0 then
5048 Symb_Path : constant String :=
5051 (Project.Object_Directory.Name) &
5052 Directory_Separator &
5053 Name_Buffer (1 .. Name_Len),
5054 Directory => Current_Dir,
5056 Opt.Follow_Links_For_Files);
5057 Ref_Path : constant String :=
5060 (Project.Symbol_Data.Reference),
5061 Directory => Current_Dir,
5063 Opt.Follow_Links_For_Files);
5065 if Symb_Path = Ref_Path then
5068 "library reference symbol file and library" &
5069 " symbol file cannot be the same file",
5070 Lib_Ref_Symbol_File.Location);
5078 end Check_Stand_Alone_Library;
5080 ----------------------------
5081 -- Compute_Directory_Last --
5082 ----------------------------
5084 function Compute_Directory_Last (Dir : String) return Natural is
5087 and then (Dir (Dir'Last - 1) = Directory_Separator
5088 or else Dir (Dir'Last - 1) = '/')
5090 return Dir'Last - 1;
5094 end Compute_Directory_Last;
5101 (Project : Project_Id;
5102 In_Tree : Project_Tree_Ref;
5104 Flag_Location : Source_Ptr)
5106 Real_Location : Source_Ptr := Flag_Location;
5107 Error_Buffer : String (1 .. 5_000);
5108 Error_Last : Natural := 0;
5109 Name_Number : Natural := 0;
5110 File_Number : Natural := 0;
5111 First : Positive := Msg'First;
5114 procedure Add (C : Character);
5115 -- Add a character to the buffer
5117 procedure Add (S : String);
5118 -- Add a string to the buffer
5121 -- Add a name to the buffer
5124 -- Add a file name to the buffer
5130 procedure Add (C : Character) is
5132 Error_Last := Error_Last + 1;
5133 Error_Buffer (Error_Last) := C;
5136 procedure Add (S : String) is
5138 Error_Buffer (Error_Last + 1 .. Error_Last + S'Length) := S;
5139 Error_Last := Error_Last + S'Length;
5146 procedure Add_File is
5147 File : File_Name_Type;
5151 File_Number := File_Number + 1;
5155 File := Err_Vars.Error_Msg_File_1;
5157 File := Err_Vars.Error_Msg_File_2;
5159 File := Err_Vars.Error_Msg_File_3;
5164 Get_Name_String (File);
5165 Add (Name_Buffer (1 .. Name_Len));
5173 procedure Add_Name is
5178 Name_Number := Name_Number + 1;
5182 Name := Err_Vars.Error_Msg_Name_1;
5184 Name := Err_Vars.Error_Msg_Name_2;
5186 Name := Err_Vars.Error_Msg_Name_3;
5191 Get_Name_String (Name);
5192 Add (Name_Buffer (1 .. Name_Len));
5196 -- Start of processing for Error_Msg
5199 -- If location of error is unknown, use the location of the project
5201 if Real_Location = No_Location then
5202 Real_Location := Project.Location;
5205 if Error_Report = null then
5206 Prj.Err.Error_Msg (Msg, Real_Location);
5210 -- Ignore continuation character
5212 if Msg (First) = '\' then
5216 -- Warning character is always the first one in this package
5217 -- this is an undocumented kludge???
5219 if Msg (First) = '?' then
5223 elsif Msg (First) = '<' then
5226 if Err_Vars.Error_Msg_Warn then
5232 while Index <= Msg'Last loop
5233 if Msg (Index) = '{' then
5236 elsif Msg (Index) = '%' then
5237 if Index < Msg'Last and then Msg (Index + 1) = '%' then
5249 Error_Report (Error_Buffer (1 .. Error_Last), Project, In_Tree);
5252 --------------------------------
5253 -- Free_Ada_Naming_Exceptions --
5254 --------------------------------
5256 procedure Free_Ada_Naming_Exceptions is
5258 Ada_Naming_Exception_Table.Set_Last (0);
5259 Ada_Naming_Exceptions.Reset;
5260 Reverse_Ada_Naming_Exceptions.Reset;
5261 end Free_Ada_Naming_Exceptions;
5263 ---------------------
5264 -- Get_Directories --
5265 ---------------------
5267 procedure Get_Directories
5268 (Project : Project_Id;
5269 In_Tree : Project_Tree_Ref;
5270 Current_Dir : String)
5272 Object_Dir : constant Variable_Value :=
5274 (Name_Object_Dir, Project.Decl.Attributes, In_Tree);
5276 Exec_Dir : constant Variable_Value :=
5278 (Name_Exec_Dir, Project.Decl.Attributes, In_Tree);
5280 Source_Dirs : constant Variable_Value :=
5282 (Name_Source_Dirs, Project.Decl.Attributes, In_Tree);
5284 Excluded_Source_Dirs : constant Variable_Value :=
5286 (Name_Excluded_Source_Dirs,
5287 Project.Decl.Attributes,
5290 Source_Files : constant Variable_Value :=
5292 (Name_Source_Files, Project.Decl.Attributes, In_Tree);
5294 Last_Source_Dir : String_List_Id := Nil_String;
5296 Languages : constant Variable_Value :=
5298 (Name_Languages, Project.Decl.Attributes, In_Tree);
5300 procedure Find_Source_Dirs
5301 (From : File_Name_Type;
5302 Location : Source_Ptr;
5303 Removed : Boolean := False);
5304 -- Find one or several source directories, and add (or remove, if
5305 -- Removed is True) them to list of source directories of the project.
5307 ----------------------
5308 -- Find_Source_Dirs --
5309 ----------------------
5311 procedure Find_Source_Dirs
5312 (From : File_Name_Type;
5313 Location : Source_Ptr;
5314 Removed : Boolean := False)
5316 Directory : constant String := Get_Name_String (From);
5317 Element : String_Element;
5319 procedure Recursive_Find_Dirs (Path : Name_Id);
5320 -- Find all the subdirectories (recursively) of Path and add them
5321 -- to the list of source directories of the project.
5323 -------------------------
5324 -- Recursive_Find_Dirs --
5325 -------------------------
5327 procedure Recursive_Find_Dirs (Path : Name_Id) is
5329 Name : String (1 .. 250);
5331 List : String_List_Id;
5332 Prev : String_List_Id;
5333 Element : String_Element;
5334 Found : Boolean := False;
5336 Non_Canonical_Path : Name_Id := No_Name;
5337 Canonical_Path : Name_Id := No_Name;
5339 The_Path : constant String :=
5341 (Get_Name_String (Path),
5342 Directory => Current_Dir,
5343 Resolve_Links => Opt.Follow_Links_For_Dirs) &
5344 Directory_Separator;
5346 The_Path_Last : constant Natural :=
5347 Compute_Directory_Last (The_Path);
5350 Name_Len := The_Path_Last - The_Path'First + 1;
5351 Name_Buffer (1 .. Name_Len) :=
5352 The_Path (The_Path'First .. The_Path_Last);
5353 Non_Canonical_Path := Name_Find;
5355 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
5357 -- To avoid processing the same directory several times, check
5358 -- if the directory is already in Recursive_Dirs. If it is, then
5359 -- there is nothing to do, just return. If it is not, put it there
5360 -- and continue recursive processing.
5363 if Recursive_Dirs.Get (Canonical_Path) then
5366 Recursive_Dirs.Set (Canonical_Path, True);
5370 -- Check if directory is already in list
5372 List := Project.Source_Dirs;
5374 while List /= Nil_String loop
5375 Element := In_Tree.String_Elements.Table (List);
5377 if Element.Value /= No_Name then
5378 Found := Element.Value = Canonical_Path;
5383 List := Element.Next;
5386 -- If directory is not already in list, put it there
5388 if (not Removed) and (not Found) then
5389 if Current_Verbosity = High then
5391 Write_Line (The_Path (The_Path'First .. The_Path_Last));
5394 String_Element_Table.Increment_Last
5395 (In_Tree.String_Elements);
5397 (Value => Canonical_Path,
5398 Display_Value => Non_Canonical_Path,
5399 Location => No_Location,
5404 -- Case of first source directory
5406 if Last_Source_Dir = Nil_String then
5407 Project.Source_Dirs := String_Element_Table.Last
5408 (In_Tree.String_Elements);
5410 -- Here we already have source directories
5413 -- Link the previous last to the new one
5415 In_Tree.String_Elements.Table
5416 (Last_Source_Dir).Next :=
5417 String_Element_Table.Last
5418 (In_Tree.String_Elements);
5421 -- And register this source directory as the new last
5423 Last_Source_Dir := String_Element_Table.Last
5424 (In_Tree.String_Elements);
5425 In_Tree.String_Elements.Table (Last_Source_Dir) :=
5428 elsif Removed and Found then
5429 if Prev = Nil_String then
5430 Project.Source_Dirs :=
5431 In_Tree.String_Elements.Table (List).Next;
5433 In_Tree.String_Elements.Table (Prev).Next :=
5434 In_Tree.String_Elements.Table (List).Next;
5438 -- Now look for subdirectories. We do that even when this
5439 -- directory is already in the list, because some of its
5440 -- subdirectories may not be in the list yet.
5442 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
5445 Read (Dir, Name, Last);
5448 if Name (1 .. Last) /= "."
5449 and then Name (1 .. Last) /= ".."
5451 -- Avoid . and .. directories
5453 if Current_Verbosity = High then
5454 Write_Str (" Checking ");
5455 Write_Line (Name (1 .. Last));
5459 Path_Name : constant String :=
5461 (Name => Name (1 .. Last),
5463 The_Path (The_Path'First .. The_Path_Last),
5464 Resolve_Links => Opt.Follow_Links_For_Dirs,
5465 Case_Sensitive => True);
5468 if Is_Directory (Path_Name) then
5469 -- We have found a new subdirectory, call self
5471 Name_Len := Path_Name'Length;
5472 Name_Buffer (1 .. Name_Len) := Path_Name;
5473 Recursive_Find_Dirs (Name_Find);
5482 when Directory_Error =>
5484 end Recursive_Find_Dirs;
5486 -- Start of processing for Find_Source_Dirs
5489 if Current_Verbosity = High and then not Removed then
5490 Write_Str ("Find_Source_Dirs (""");
5491 Write_Str (Directory);
5495 -- First, check if we are looking for a directory tree, indicated
5496 -- by "/**" at the end.
5498 if Directory'Length >= 3
5499 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
5500 and then (Directory (Directory'Last - 2) = '/'
5502 Directory (Directory'Last - 2) = Directory_Separator)
5505 Project.Known_Order_Of_Source_Dirs := False;
5508 Name_Len := Directory'Length - 3;
5510 if Name_Len = 0 then
5512 -- Case of "/**": all directories in file system
5515 Name_Buffer (1) := Directory (Directory'First);
5518 Name_Buffer (1 .. Name_Len) :=
5519 Directory (Directory'First .. Directory'Last - 3);
5522 if Current_Verbosity = High then
5523 Write_Str ("Looking for all subdirectories of """);
5524 Write_Str (Name_Buffer (1 .. Name_Len));
5529 Base_Dir : constant File_Name_Type := Name_Find;
5530 Root_Dir : constant String :=
5532 (Name => Get_Name_String (Base_Dir),
5535 (Project.Directory.Display_Name),
5536 Resolve_Links => False,
5537 Case_Sensitive => True);
5540 if Root_Dir'Length = 0 then
5541 Err_Vars.Error_Msg_File_1 := Base_Dir;
5543 if Location = No_Location then
5546 "{ is not a valid directory.",
5551 "{ is not a valid directory.",
5556 -- We have an existing directory, we register it and all of
5557 -- its subdirectories.
5559 if Current_Verbosity = High then
5560 Write_Line ("Looking for source directories:");
5563 Name_Len := Root_Dir'Length;
5564 Name_Buffer (1 .. Name_Len) := Root_Dir;
5565 Recursive_Find_Dirs (Name_Find);
5567 if Current_Verbosity = High then
5568 Write_Line ("End of looking for source directories.");
5573 -- We have a single directory
5577 Path_Name : Path_Information;
5578 List : String_List_Id;
5579 Prev : String_List_Id;
5580 Dir_Exists : Boolean;
5584 (Project => Project,
5588 Dir_Exists => Dir_Exists,
5589 Must_Exist => False);
5591 if not Dir_Exists then
5592 Err_Vars.Error_Msg_File_1 := From;
5594 if Location = No_Location then
5597 "{ is not a valid directory",
5602 "{ is not a valid directory",
5608 Path : constant String :=
5609 Get_Name_String (Path_Name.Name) &
5610 Directory_Separator;
5611 Last_Path : constant Natural :=
5612 Compute_Directory_Last (Path);
5614 Display_Path : constant String :=
5616 (Path_Name.Display_Name) &
5617 Directory_Separator;
5618 Last_Display_Path : constant Natural :=
5619 Compute_Directory_Last
5621 Display_Path_Id : Name_Id;
5625 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
5626 Path_Id := Name_Find;
5628 Add_Str_To_Name_Buffer
5630 (Display_Path'First .. Last_Display_Path));
5631 Display_Path_Id := Name_Find;
5635 -- As it is an existing directory, we add it to the
5636 -- list of directories.
5638 String_Element_Table.Increment_Last
5639 (In_Tree.String_Elements);
5643 Display_Value => Display_Path_Id,
5644 Location => No_Location,
5646 Next => Nil_String);
5648 if Last_Source_Dir = Nil_String then
5650 -- This is the first source directory
5652 Project.Source_Dirs := String_Element_Table.Last
5653 (In_Tree.String_Elements);
5656 -- We already have source directories, link the
5657 -- previous last to the new one.
5659 In_Tree.String_Elements.Table
5660 (Last_Source_Dir).Next :=
5661 String_Element_Table.Last
5662 (In_Tree.String_Elements);
5665 -- And register this source directory as the new last
5667 Last_Source_Dir := String_Element_Table.Last
5668 (In_Tree.String_Elements);
5669 In_Tree.String_Elements.Table
5670 (Last_Source_Dir) := Element;
5673 -- Remove source dir, if present
5677 -- Look for source dir in current list
5679 List := Project.Source_Dirs;
5680 while List /= Nil_String loop
5681 Element := In_Tree.String_Elements.Table (List);
5682 exit when Element.Value = Path_Id;
5684 List := Element.Next;
5687 if List /= Nil_String then
5688 -- Source dir was found, remove it from the list
5690 if Prev = Nil_String then
5691 Project.Source_Dirs :=
5692 In_Tree.String_Elements.Table (List).Next;
5695 In_Tree.String_Elements.Table (Prev).Next :=
5696 In_Tree.String_Elements.Table (List).Next;
5704 end Find_Source_Dirs;
5706 -- Start of processing for Get_Directories
5708 Dir_Exists : Boolean;
5711 if Current_Verbosity = High then
5712 Write_Line ("Starting to look for directories");
5715 -- Set the object directory to its default which may be nil, if there
5716 -- is no sources in the project.
5718 if (((not Source_Files.Default)
5719 and then Source_Files.Values = Nil_String)
5721 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5723 ((not Languages.Default) and then Languages.Values = Nil_String))
5724 and then Project.Extends = No_Project
5726 Project.Object_Directory := No_Path_Information;
5728 Project.Object_Directory := Project.Directory;
5731 -- Check the object directory
5733 if Object_Dir.Value /= Empty_String then
5734 Get_Name_String (Object_Dir.Value);
5736 if Name_Len = 0 then
5739 "Object_Dir cannot be empty",
5740 Object_Dir.Location);
5743 -- We check that the specified object directory does exist.
5744 -- However, even when it doesn't exist, we set it to a default
5745 -- value. This is for the benefit of tools that recover from
5746 -- errors; for example, these tools could create the non existent
5748 -- We always return an absolute directory name though
5753 File_Name_Type (Object_Dir.Value),
5754 Path => Project.Object_Directory,
5756 Dir_Exists => Dir_Exists,
5757 Location => Object_Dir.Location,
5758 Must_Exist => False,
5759 Externally_Built => Project.Externally_Built);
5762 and then not Project.Externally_Built
5764 -- The object directory does not exist, report an error if
5765 -- the project is not externally built.
5767 Err_Vars.Error_Msg_File_1 :=
5768 File_Name_Type (Object_Dir.Value);
5771 "object directory { not found",
5776 elsif Project.Object_Directory /= No_Path_Information
5777 and then Subdirs /= null
5780 Name_Buffer (1) := '.';
5785 Path => Project.Object_Directory,
5787 Dir_Exists => Dir_Exists,
5788 Location => Object_Dir.Location,
5789 Externally_Built => Project.Externally_Built);
5792 if Current_Verbosity = High then
5793 if Project.Object_Directory = No_Path_Information then
5794 Write_Line ("No object directory");
5797 ("Object directory",
5798 Get_Name_String (Project.Object_Directory.Display_Name));
5802 -- Check the exec directory
5804 -- We set the object directory to its default
5806 Project.Exec_Directory := Project.Object_Directory;
5808 if Exec_Dir.Value /= Empty_String then
5809 Get_Name_String (Exec_Dir.Value);
5811 if Name_Len = 0 then
5814 "Exec_Dir cannot be empty",
5818 -- We check that the specified exec directory does exist
5823 File_Name_Type (Exec_Dir.Value),
5824 Path => Project.Exec_Directory,
5825 Dir_Exists => Dir_Exists,
5827 Location => Exec_Dir.Location,
5828 Externally_Built => Project.Externally_Built);
5830 if not Dir_Exists then
5831 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5834 "exec directory { not found",
5840 if Current_Verbosity = High then
5841 if Project.Exec_Directory = No_Path_Information then
5842 Write_Line ("No exec directory");
5844 Write_Str ("Exec directory: """);
5845 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5850 -- Look for the source directories
5852 if Current_Verbosity = High then
5853 Write_Line ("Starting to look for source directories");
5856 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5858 if (not Source_Files.Default) and then
5859 Source_Files.Values = Nil_String
5861 Project.Source_Dirs := Nil_String;
5863 if Project.Qualifier = Standard then
5867 "a standard project cannot have no sources",
5868 Source_Files.Location);
5871 elsif Source_Dirs.Default then
5873 -- No Source_Dirs specified: the single source directory is the one
5874 -- containing the project file
5876 String_Element_Table.Append (In_Tree.String_Elements,
5877 (Value => Name_Id (Project.Directory.Name),
5878 Display_Value => Name_Id (Project.Directory.Display_Name),
5879 Location => No_Location,
5883 Project.Source_Dirs := String_Element_Table.Last
5884 (In_Tree.String_Elements);
5886 if Current_Verbosity = High then
5888 ("Default source directory",
5889 Get_Name_String (Project.Directory.Display_Name));
5892 elsif Source_Dirs.Values = Nil_String then
5893 if Project.Qualifier = Standard then
5897 "a standard project cannot have no source directories",
5898 Source_Dirs.Location);
5901 Project.Source_Dirs := Nil_String;
5905 Source_Dir : String_List_Id;
5906 Element : String_Element;
5909 -- Process the source directories for each element of the list
5911 Source_Dir := Source_Dirs.Values;
5912 while Source_Dir /= Nil_String loop
5913 Element := In_Tree.String_Elements.Table (Source_Dir);
5915 (File_Name_Type (Element.Value), Element.Location);
5916 Source_Dir := Element.Next;
5921 if not Excluded_Source_Dirs.Default
5922 and then Excluded_Source_Dirs.Values /= Nil_String
5925 Source_Dir : String_List_Id;
5926 Element : String_Element;
5929 -- Process the source directories for each element of the list
5931 Source_Dir := Excluded_Source_Dirs.Values;
5932 while Source_Dir /= Nil_String loop
5933 Element := In_Tree.String_Elements.Table (Source_Dir);
5935 (File_Name_Type (Element.Value),
5938 Source_Dir := Element.Next;
5943 if Current_Verbosity = High then
5944 Write_Line ("Putting source directories in canonical cases");
5948 Current : String_List_Id := Project.Source_Dirs;
5949 Element : String_Element;
5952 while Current /= Nil_String loop
5953 Element := In_Tree.String_Elements.Table (Current);
5954 if Element.Value /= No_Name then
5956 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5957 In_Tree.String_Elements.Table (Current) := Element;
5960 Current := Element.Next;
5963 end Get_Directories;
5970 (Project : Project_Id;
5971 In_Tree : Project_Tree_Ref)
5973 Mains : constant Variable_Value :=
5974 Prj.Util.Value_Of (Name_Main, Project.Decl.Attributes, In_Tree);
5975 List : String_List_Id;
5976 Elem : String_Element;
5979 Project.Mains := Mains.Values;
5981 -- If no Mains were specified, and if we are an extending project,
5982 -- inherit the Mains from the project we are extending.
5984 if Mains.Default then
5985 if not Project.Library and then Project.Extends /= No_Project then
5986 Project.Mains := Project.Extends.Mains;
5989 -- In a library project file, Main cannot be specified
5991 elsif Project.Library then
5994 "a library project file cannot have Main specified",
5998 List := Mains.Values;
5999 while List /= Nil_String loop
6000 Elem := In_Tree.String_Elements.Table (List);
6002 if Length_Of_Name (Elem.Value) = 0 then
6005 "?a main cannot have an empty name",
6015 ---------------------------
6016 -- Get_Sources_From_File --
6017 ---------------------------
6019 procedure Get_Sources_From_File
6021 Location : Source_Ptr;
6022 Project : Project_Id;
6023 In_Tree : Project_Tree_Ref)
6025 File : Prj.Util.Text_File;
6026 Line : String (1 .. 250);
6028 Source_Name : File_Name_Type;
6029 Name_Loc : Name_Location;
6032 if Get_Mode = Ada_Only then
6036 if Current_Verbosity = High then
6037 Write_Str ("Opening """);
6044 Prj.Util.Open (File, Path);
6046 if not Prj.Util.Is_Valid (File) then
6047 Error_Msg (Project, In_Tree, "file does not exist", Location);
6050 -- Read the lines one by one
6052 while not Prj.Util.End_Of_File (File) loop
6053 Prj.Util.Get_Line (File, Line, Last);
6055 -- A non empty, non comment line should contain a file name
6058 and then (Last = 1 or else Line (1 .. 2) /= "--")
6061 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6062 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6063 Source_Name := Name_Find;
6065 -- Check that there is no directory information
6067 for J in 1 .. Last loop
6068 if Line (J) = '/' or else Line (J) = Directory_Separator then
6069 Error_Msg_File_1 := Source_Name;
6073 "file name cannot include directory information ({)",
6079 Name_Loc := Source_Names.Get (Source_Name);
6081 if Name_Loc = No_Name_Location then
6083 (Name => Source_Name,
6084 Location => Location,
6085 Source => No_Source,
6090 Source_Names.Set (Source_Name, Name_Loc);
6094 Prj.Util.Close (File);
6097 end Get_Sources_From_File;
6099 -----------------------
6100 -- Compute_Unit_Name --
6101 -----------------------
6103 procedure Compute_Unit_Name
6104 (File_Name : File_Name_Type;
6105 Dot_Replacement : File_Name_Type;
6106 Separate_Suffix : File_Name_Type;
6107 Body_Suffix : File_Name_Type;
6108 Spec_Suffix : File_Name_Type;
6109 Casing : Casing_Type;
6110 Kind : out Source_Kind;
6112 In_Tree : Project_Tree_Ref)
6114 Filename : constant String := Get_Name_String (File_Name);
6115 Last : Integer := Filename'Last;
6116 Sep_Len : constant Integer :=
6117 Integer (Length_Of_Name (Separate_Suffix));
6118 Body_Len : constant Integer :=
6119 Integer (Length_Of_Name (Body_Suffix));
6120 Spec_Len : constant Integer :=
6121 Integer (Length_Of_Name (Spec_Suffix));
6123 Standard_GNAT : constant Boolean :=
6124 Spec_Suffix = Default_Ada_Spec_Suffix
6126 Body_Suffix = Default_Ada_Body_Suffix;
6128 Unit_Except : Unit_Exception;
6129 Masked : Boolean := False;
6134 if Dot_Replacement = No_File then
6135 if Current_Verbosity = High then
6136 Write_Line (" No dot_replacement specified");
6141 -- Choose the longest suffix that matches. If there are several matches,
6142 -- give priority to specs, then bodies, then separates.
6144 if Separate_Suffix /= Body_Suffix
6145 and then Suffix_Matches (Filename, Separate_Suffix)
6147 Last := Filename'Last - Sep_Len;
6151 if Filename'Last - Body_Len <= Last
6152 and then Suffix_Matches (Filename, Body_Suffix)
6154 Last := Natural'Min (Last, Filename'Last - Body_Len);
6158 if Filename'Last - Spec_Len <= Last
6159 and then Suffix_Matches (Filename, Spec_Suffix)
6161 Last := Natural'Min (Last, Filename'Last - Spec_Len);
6165 if Last = Filename'Last then
6166 if Current_Verbosity = High then
6167 Write_Line (" No matching suffix");
6172 -- Check that the casing matches
6174 if File_Names_Case_Sensitive then
6176 when All_Lower_Case =>
6177 for J in Filename'First .. Last loop
6178 if Is_Letter (Filename (J))
6179 and then not Is_Lower (Filename (J))
6181 if Current_Verbosity = High then
6182 Write_Line (" Invalid casing");
6188 when All_Upper_Case =>
6189 for J in Filename'First .. Last loop
6190 if Is_Letter (Filename (J))
6191 and then not Is_Upper (Filename (J))
6193 if Current_Verbosity = High then
6194 Write_Line (" Invalid casing");
6200 when Mixed_Case | Unknown =>
6205 -- If Dot_Replacement is not a single dot, then there should not
6206 -- be any dot in the name.
6209 Dot_Repl : constant String := Get_Name_String (Dot_Replacement);
6212 if Dot_Repl /= "." then
6213 for Index in Filename'First .. Last loop
6214 if Filename (Index) = '.' then
6215 if Current_Verbosity = High then
6216 Write_Line (" Invalid name, contains dot");
6222 Replace_Into_Name_Buffer
6223 (Filename (Filename'First .. Last), Dot_Repl, '.');
6225 Name_Len := Last - Filename'First + 1;
6226 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
6228 (Source => Name_Buffer (1 .. Name_Len),
6229 Mapping => Lower_Case_Map);
6233 -- In the standard GNAT naming scheme, check for special cases: children
6234 -- or separates of A, G, I or S, and run time sources.
6236 if Standard_GNAT and then Name_Len >= 3 then
6238 S1 : constant Character := Name_Buffer (1);
6239 S2 : constant Character := Name_Buffer (2);
6240 S3 : constant Character := Name_Buffer (3);
6248 -- Children or separates of packages A, G, I or S. These names
6249 -- are x__ ... or x~... (where x is a, g, i, or s). Both
6250 -- versions (x__... and x~...) are allowed in all platforms,
6251 -- because it is not possible to know the platform before
6252 -- processing of the project files.
6254 if S2 = '_' and then S3 = '_' then
6255 Name_Buffer (2) := '.';
6256 Name_Buffer (3 .. Name_Len - 1) :=
6257 Name_Buffer (4 .. Name_Len);
6258 Name_Len := Name_Len - 1;
6261 Name_Buffer (2) := '.';
6265 -- If it is potentially a run time source, disable filling
6266 -- of the mapping file to avoid warnings.
6268 Set_Mapping_File_Initial_State_To_Empty (In_Tree);
6274 -- Name_Buffer contains the name of the the unit in lower-cases. Check
6275 -- that this is a valid unit name
6277 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
6279 -- If there is a naming exception for the same unit, the file is not
6280 -- a source for the unit. Currently, this only applies in multi_lang
6281 -- mode, since Unit_Exceptions is no set in ada_only mode.
6283 if Unit /= No_Name then
6284 Unit_Except := Unit_Exceptions.Get (Unit);
6287 Masked := Unit_Except.Spec /= No_File
6289 Unit_Except.Spec /= File_Name;
6291 Masked := Unit_Except.Impl /= No_File
6293 Unit_Except.Impl /= File_Name;
6297 if Current_Verbosity = High then
6298 Write_Str (" """ & Filename & """ contains the ");
6301 Write_Str ("spec of a unit found in """);
6302 Write_Str (Get_Name_String (Unit_Except.Spec));
6304 Write_Str ("body of a unit found in """);
6305 Write_Str (Get_Name_String (Unit_Except.Impl));
6308 Write_Line (""" (ignored)");
6316 and then Current_Verbosity = High
6319 when Spec => Write_Str (" spec of ");
6320 when Impl => Write_Str (" body of ");
6321 when Sep => Write_Str (" sep of ");
6324 Write_Line (Get_Name_String (Unit));
6326 end Compute_Unit_Name;
6333 (In_Tree : Project_Tree_Ref;
6334 Canonical_File_Name : File_Name_Type;
6335 Naming : Naming_Data;
6336 Exception_Id : out Ada_Naming_Exception_Id;
6337 Unit_Name : out Name_Id;
6338 Unit_Kind : out Spec_Or_Body)
6340 Info_Id : Ada_Naming_Exception_Id :=
6341 Ada_Naming_Exceptions.Get (Canonical_File_Name);
6342 VMS_Name : File_Name_Type;
6346 if Info_Id = No_Ada_Naming_Exception
6347 and then Hostparm.OpenVMS
6349 VMS_Name := Canonical_File_Name;
6350 Get_Name_String (VMS_Name);
6352 if Name_Buffer (Name_Len) = '.' then
6353 Name_Len := Name_Len - 1;
6354 VMS_Name := Name_Find;
6357 Info_Id := Ada_Naming_Exceptions.Get (VMS_Name);
6360 if Info_Id /= No_Ada_Naming_Exception then
6361 Exception_Id := Info_Id;
6362 Unit_Name := No_Name;
6363 Unit_Kind := Specification;
6366 Exception_Id := No_Ada_Naming_Exception;
6368 (File_Name => Canonical_File_Name,
6369 Dot_Replacement => Naming.Dot_Replacement,
6370 Separate_Suffix => Naming.Separate_Suffix,
6371 Body_Suffix => Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6372 Spec_Suffix => Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
6373 Casing => Naming.Casing,
6376 In_Tree => In_Tree);
6379 when Spec => Unit_Kind := Specification;
6380 when Impl | Sep => Unit_Kind := Body_Part;
6389 function Hash (Unit : Unit_Info) return Header_Num is
6391 return Header_Num (Unit.Unit mod 2048);
6394 -----------------------
6395 -- Is_Illegal_Suffix --
6396 -----------------------
6398 function Is_Illegal_Suffix
6399 (Suffix : File_Name_Type;
6400 Dot_Replacement : File_Name_Type) return Boolean
6402 Suffix_Str : constant String := Get_Name_String (Suffix);
6405 if Suffix_Str'Length = 0 then
6407 elsif Index (Suffix_Str, ".") = 0 then
6411 -- Case of dot replacement is a single dot, and first character of
6412 -- suffix is also a dot.
6414 if Get_Name_String (Dot_Replacement) = "."
6415 and then Suffix_Str (Suffix_Str'First) = '.'
6417 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
6419 -- Case of following dot
6421 if Suffix_Str (Index) = '.' then
6423 -- It is illegal to have a letter following the initial dot
6425 return Is_Letter (Suffix_Str (Suffix_Str'First + 1));
6431 end Is_Illegal_Suffix;
6433 ----------------------
6434 -- Locate_Directory --
6435 ----------------------
6437 procedure Locate_Directory
6438 (Project : Project_Id;
6439 In_Tree : Project_Tree_Ref;
6440 Name : File_Name_Type;
6441 Path : out Path_Information;
6442 Dir_Exists : out Boolean;
6443 Create : String := "";
6444 Location : Source_Ptr := No_Location;
6445 Must_Exist : Boolean := True;
6446 Externally_Built : Boolean := False)
6448 Parent : constant Path_Name_Type :=
6449 Project.Directory.Display_Name;
6450 The_Parent : constant String :=
6451 Get_Name_String (Parent) & Directory_Separator;
6452 The_Parent_Last : constant Natural :=
6453 Compute_Directory_Last (The_Parent);
6454 Full_Name : File_Name_Type;
6455 The_Name : File_Name_Type;
6458 Get_Name_String (Name);
6460 -- Add Subdirs.all if it is a directory that may be created and
6461 -- Subdirs is not null;
6463 if Create /= "" and then Subdirs /= null then
6464 if Name_Buffer (Name_Len) /= Directory_Separator then
6465 Add_Char_To_Name_Buffer (Directory_Separator);
6468 Add_Str_To_Name_Buffer (Subdirs.all);
6471 -- Convert '/' to directory separator (for Windows)
6473 for J in 1 .. Name_Len loop
6474 if Name_Buffer (J) = '/' then
6475 Name_Buffer (J) := Directory_Separator;
6479 The_Name := Name_Find;
6481 if Current_Verbosity = High then
6482 Write_Str ("Locate_Directory (""");
6483 Write_Str (Get_Name_String (The_Name));
6484 Write_Str (""", """);
6485 Write_Str (The_Parent);
6489 Path := No_Path_Information;
6490 Dir_Exists := False;
6492 if Is_Absolute_Path (Get_Name_String (The_Name)) then
6493 Full_Name := The_Name;
6497 Add_Str_To_Name_Buffer
6498 (The_Parent (The_Parent'First .. The_Parent_Last));
6499 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
6500 Full_Name := Name_Find;
6504 Full_Path_Name : String_Access :=
6505 new String'(Get_Name_String (Full_Name));
6508 if (Setup_Projects or else Subdirs /= null)
6509 and then Create'Length > 0
6511 if not Is_Directory (Full_Path_Name.all) then
6513 -- If project is externally built, do not create a subdir,
6514 -- use the specified directory, without the subdir.
6516 if Externally_Built then
6517 if Is_Absolute_Path (Get_Name_String (Name)) then
6518 Get_Name_String (Name);
6522 Add_Str_To_Name_Buffer
6523 (The_Parent (The_Parent'First .. The_Parent_Last));
6524 Add_Str_To_Name_Buffer (Get_Name_String (Name));
6527 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
6531 Create_Path (Full_Path_Name.all);
6533 if not Quiet_Output then
6535 Write_Str (" directory """);
6536 Write_Str (Full_Path_Name.all);
6537 Write_Str (""" created for project ");
6538 Write_Line (Get_Name_String (Project.Name));
6545 "could not create " & Create &
6546 " directory " & Full_Path_Name.all,
6553 Dir_Exists := Is_Directory (Full_Path_Name.all);
6555 if not Must_Exist or else Dir_Exists then
6557 Normed : constant String :=
6559 (Full_Path_Name.all,
6561 The_Parent (The_Parent'First .. The_Parent_Last),
6562 Resolve_Links => False,
6563 Case_Sensitive => True);
6565 Canonical_Path : constant String :=
6570 (The_Parent'First .. The_Parent_Last),
6572 Opt.Follow_Links_For_Dirs,
6573 Case_Sensitive => False);
6576 Name_Len := Normed'Length;
6577 Name_Buffer (1 .. Name_Len) := Normed;
6578 Path.Display_Name := Name_Find;
6580 Name_Len := Canonical_Path'Length;
6581 Name_Buffer (1 .. Name_Len) := Canonical_Path;
6582 Path.Name := Name_Find;
6586 Free (Full_Path_Name);
6588 end Locate_Directory;
6590 ---------------------------
6591 -- Find_Excluded_Sources --
6592 ---------------------------
6594 procedure Find_Excluded_Sources
6595 (Project : Project_Id;
6596 In_Tree : Project_Tree_Ref)
6598 Excluded_Source_List_File : constant Variable_Value :=
6600 (Name_Excluded_Source_List_File,
6601 Project.Decl.Attributes,
6604 Excluded_Sources : Variable_Value := Util.Value_Of
6605 (Name_Excluded_Source_Files,
6606 Project.Decl.Attributes,
6609 Current : String_List_Id;
6610 Element : String_Element;
6611 Location : Source_Ptr;
6612 Name : File_Name_Type;
6613 File : Prj.Util.Text_File;
6614 Line : String (1 .. 300);
6616 Locally_Removed : Boolean := False;
6619 -- If Excluded_Source_Files is not declared, check
6620 -- Locally_Removed_Files.
6622 if Excluded_Sources.Default then
6623 Locally_Removed := True;
6626 (Name_Locally_Removed_Files, Project.Decl.Attributes, In_Tree);
6629 Excluded_Sources_Htable.Reset;
6631 -- If there are excluded sources, put them in the table
6633 if not Excluded_Sources.Default then
6634 if not Excluded_Source_List_File.Default then
6635 if Locally_Removed then
6638 "?both attributes Locally_Removed_Files and " &
6639 "Excluded_Source_List_File are present",
6640 Excluded_Source_List_File.Location);
6644 "?both attributes Excluded_Source_Files and " &
6645 "Excluded_Source_List_File are present",
6646 Excluded_Source_List_File.Location);
6650 Current := Excluded_Sources.Values;
6651 while Current /= Nil_String loop
6652 Element := In_Tree.String_Elements.Table (Current);
6653 Name := Canonical_Case_File_Name (Element.Value);
6655 -- If the element has no location, then use the location of
6656 -- Excluded_Sources to report possible errors.
6658 if Element.Location = No_Location then
6659 Location := Excluded_Sources.Location;
6661 Location := Element.Location;
6664 Excluded_Sources_Htable.Set (Name, (Name, False, Location));
6665 Current := Element.Next;
6668 elsif not Excluded_Source_List_File.Default then
6669 Location := Excluded_Source_List_File.Location;
6672 Source_File_Path_Name : constant String :=
6675 (Excluded_Source_List_File.Value),
6676 Project.Directory.Name);
6679 if Source_File_Path_Name'Length = 0 then
6680 Err_Vars.Error_Msg_File_1 :=
6681 File_Name_Type (Excluded_Source_List_File.Value);
6684 "file with excluded sources { does not exist",
6685 Excluded_Source_List_File.Location);
6690 Prj.Util.Open (File, Source_File_Path_Name);
6692 if not Prj.Util.Is_Valid (File) then
6694 (Project, In_Tree, "file does not exist", Location);
6696 -- Read the lines one by one
6698 while not Prj.Util.End_Of_File (File) loop
6699 Prj.Util.Get_Line (File, Line, Last);
6701 -- Non empty, non comment line should contain a file name
6704 and then (Last = 1 or else Line (1 .. 2) /= "--")
6707 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6708 Canonical_Case_File_Name
6709 (Name_Buffer (1 .. Name_Len));
6712 -- Check that there is no directory information
6714 for J in 1 .. Last loop
6716 or else Line (J) = Directory_Separator
6718 Error_Msg_File_1 := Name;
6722 "file name cannot include " &
6723 "directory information ({)",
6729 Excluded_Sources_Htable.Set
6730 (Name, (Name, False, Location));
6734 Prj.Util.Close (File);
6739 end Find_Excluded_Sources;
6745 procedure Find_Sources
6746 (Project : Project_Id;
6747 In_Tree : Project_Tree_Ref;
6748 Proc_Data : in out Processing_Data)
6750 Sources : constant Variable_Value :=
6753 Project.Decl.Attributes,
6755 Source_List_File : constant Variable_Value :=
6757 (Name_Source_List_File,
6758 Project.Decl.Attributes,
6760 Name_Loc : Name_Location;
6762 Has_Explicit_Sources : Boolean;
6765 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6767 (Source_List_File.Kind = Single,
6768 "Source_List_File is not a single string");
6770 -- If the user has specified a Source_Files attribute
6772 if not Sources.Default then
6773 if not Source_List_File.Default then
6776 "?both attributes source_files and " &
6777 "source_list_file are present",
6778 Source_List_File.Location);
6781 -- Sources is a list of file names
6784 Current : String_List_Id := Sources.Values;
6785 Element : String_Element;
6786 Location : Source_Ptr;
6787 Name : File_Name_Type;
6790 if Get_Mode = Multi_Language then
6791 if Current = Nil_String then
6792 Project.Languages := No_Language_Index;
6794 -- This project contains no source. For projects that don't
6795 -- extend other projects, this also means that there is no
6796 -- need for an object directory, if not specified.
6798 if Project.Extends = No_Project
6799 and then Project.Object_Directory = Project.Directory
6801 Project.Object_Directory := No_Path_Information;
6806 while Current /= Nil_String loop
6807 Element := In_Tree.String_Elements.Table (Current);
6808 Name := Canonical_Case_File_Name (Element.Value);
6809 Get_Name_String (Element.Value);
6811 -- If the element has no location, then use the location of
6812 -- Sources to report possible errors.
6814 if Element.Location = No_Location then
6815 Location := Sources.Location;
6817 Location := Element.Location;
6820 -- Check that there is no directory information
6822 for J in 1 .. Name_Len loop
6823 if Name_Buffer (J) = '/'
6824 or else Name_Buffer (J) = Directory_Separator
6826 Error_Msg_File_1 := Name;
6830 "file name cannot include directory " &
6837 -- In Multi_Language mode, check whether the file is already
6838 -- there: the same file name may be in the list. If the source
6839 -- is missing, the error will be on the first mention of the
6840 -- source file name.
6844 Name_Loc := No_Name_Location;
6845 when Multi_Language =>
6846 Name_Loc := Source_Names.Get (Name);
6849 if Name_Loc = No_Name_Location then
6852 Location => Location,
6853 Source => No_Source,
6856 Source_Names.Set (Name, Name_Loc);
6859 Current := Element.Next;
6862 Has_Explicit_Sources := True;
6865 -- If we have no Source_Files attribute, check the Source_List_File
6868 elsif not Source_List_File.Default then
6870 -- Source_List_File is the name of the file that contains the source
6874 Source_File_Path_Name : constant String :=
6876 (File_Name_Type (Source_List_File.Value),
6877 Project.Directory.Name);
6880 Has_Explicit_Sources := True;
6882 if Source_File_Path_Name'Length = 0 then
6883 Err_Vars.Error_Msg_File_1 :=
6884 File_Name_Type (Source_List_File.Value);
6887 "file with sources { does not exist",
6888 Source_List_File.Location);
6891 Get_Sources_From_File
6892 (Source_File_Path_Name, Source_List_File.Location,
6898 -- Neither Source_Files nor Source_List_File has been specified. Find
6899 -- all the files that satisfy the naming scheme in all the source
6902 Has_Explicit_Sources := False;
6905 if Get_Mode = Ada_Only then
6907 (Project, In_Tree, Explicit_Sources_Only => Has_Explicit_Sources,
6908 Proc_Data => Proc_Data);
6914 Sources.Default and then Source_List_File.Default);
6917 -- Check if all exceptions have been found. For Ada, it is an error if
6918 -- an exception is not found. For other language, the source is simply
6923 Iter : Source_Iterator;
6926 Iter := For_Each_Source (In_Tree, Project);
6928 Source := Prj.Element (Iter);
6929 exit when Source = No_Source;
6931 if Source.Naming_Exception
6932 and then Source.Path = No_Path_Information
6934 if Source.Unit /= No_Name then
6935 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6936 Error_Msg_Name_2 := Name_Id (Source.Unit);
6939 "source file %% for unit %% not found",
6943 Remove_Source (Source, No_Source);
6950 -- It is an error if a source file name in a source list or in a source
6951 -- list file is not found.
6953 if Has_Explicit_Sources then
6956 First_Error : Boolean;
6959 NL := Source_Names.Get_First;
6960 First_Error := True;
6961 while NL /= No_Name_Location loop
6962 if not NL.Found then
6963 Err_Vars.Error_Msg_File_1 := NL.Name;
6968 "source file { not found",
6970 First_Error := False;
6975 "\source file { not found",
6980 NL := Source_Names.Get_Next;
6985 if Get_Mode = Ada_Only
6986 and then Project.Extends = No_Project
6988 -- We should have found at least one source, if not report an error
6990 if not Has_Ada_Sources (Project) then
6992 (Project, "Ada", In_Tree, Source_List_File.Location);
7001 procedure Initialize (Proc_Data : in out Processing_Data) is
7003 Files_Htable.Reset (Proc_Data.Units);
7010 procedure Free (Proc_Data : in out Processing_Data) is
7012 Files_Htable.Reset (Proc_Data.Units);
7015 ----------------------
7016 -- Find_Ada_Sources --
7017 ----------------------
7019 procedure Find_Ada_Sources
7020 (Project : Project_Id;
7021 In_Tree : Project_Tree_Ref;
7022 Explicit_Sources_Only : Boolean;
7023 Proc_Data : in out Processing_Data)
7025 Source_Dir : String_List_Id;
7026 Element : String_Element;
7028 Dir_Has_Source : Boolean := False;
7030 Ada_Language : Language_Ptr;
7033 if Current_Verbosity = High then
7034 Write_Line ("Looking for Ada sources:");
7037 Ada_Language := Project.Languages;
7038 while Ada_Language /= No_Language_Index
7039 and then Ada_Language.Name /= Name_Ada
7041 Ada_Language := Ada_Language.Next;
7044 -- We look in all source directories for the file names in the hash
7045 -- table Source_Names.
7047 Source_Dir := Project.Source_Dirs;
7048 while Source_Dir /= Nil_String loop
7049 Dir_Has_Source := False;
7050 Element := In_Tree.String_Elements.Table (Source_Dir);
7053 Dir_Path : constant String :=
7054 Get_Name_String (Element.Display_Value) &
7055 Directory_Separator;
7056 Dir_Last : constant Natural := Compute_Directory_Last (Dir_Path);
7059 if Current_Verbosity = High then
7060 Write_Line ("checking directory """ & Dir_Path & """");
7063 -- Look for all files in the current source directory
7065 Open (Dir, Dir_Path (Dir_Path'First .. Dir_Last));
7068 Read (Dir, Name_Buffer, Name_Len);
7069 exit when Name_Len = 0;
7071 if Current_Verbosity = High then
7072 Write_Line (" Checking " & Name_Buffer (1 .. Name_Len));
7076 Name : constant File_Name_Type := Name_Find;
7077 Canonical_Name : File_Name_Type;
7079 -- ??? We could probably optimize the following call: we
7080 -- need to resolve links only once for the directory itself,
7081 -- and then do a single call to readlink() for each file.
7082 -- Unfortunately that would require a change in
7083 -- Normalize_Pathname so that it has the option of not
7084 -- resolving links for its Directory parameter, only for
7087 Path : constant String :=
7089 (Name => Name_Buffer (1 .. Name_Len),
7090 Directory => Dir_Path (Dir_Path'First .. Dir_Last),
7091 Resolve_Links => Opt.Follow_Links_For_Files,
7092 Case_Sensitive => True); -- no case folding
7094 Path_Name : Path_Name_Type;
7095 To_Record : Boolean := False;
7096 Location : Source_Ptr;
7099 -- If the file was listed in the explicit list of sources,
7100 -- mark it as such (since we'll need to report an error when
7101 -- an explicit source was not found)
7103 if Explicit_Sources_Only then
7105 Canonical_Case_File_Name (Name_Id (Name));
7106 NL := Source_Names.Get (Canonical_Name);
7107 To_Record := NL /= No_Name_Location and then not NL.Found;
7111 Location := NL.Location;
7112 Source_Names.Set (Canonical_Name, NL);
7117 Location := No_Location;
7121 Name_Len := Path'Length;
7122 Name_Buffer (1 .. Name_Len) := Path;
7123 Path_Name := Name_Find;
7125 if Current_Verbosity = High then
7126 Write_Line (" recording " & Get_Name_String (Name));
7129 -- Register the source if it is an Ada compilation unit
7133 Path_Name => Path_Name,
7136 Proc_Data => Proc_Data,
7137 Ada_Language => Ada_Language,
7138 Location => Location,
7139 Source_Recorded => Dir_Has_Source);
7152 if Dir_Has_Source then
7153 In_Tree.String_Elements.Table (Source_Dir).Flag := True;
7156 Source_Dir := Element.Next;
7159 if Current_Verbosity = High then
7160 Write_Line ("End looking for sources");
7162 end Find_Ada_Sources;
7164 -------------------------------
7165 -- Check_File_Naming_Schemes --
7166 -------------------------------
7168 procedure Check_File_Naming_Schemes
7169 (In_Tree : Project_Tree_Ref;
7170 Project : Project_Id;
7171 File_Name : File_Name_Type;
7172 Alternate_Languages : out Language_List;
7173 Language : out Language_Ptr;
7174 Display_Language_Name : out Name_Id;
7176 Lang_Kind : out Language_Kind;
7177 Kind : out Source_Kind)
7179 Filename : constant String := Get_Name_String (File_Name);
7180 Config : Language_Config;
7181 Tmp_Lang : Language_Ptr;
7183 Header_File : Boolean := False;
7184 -- True if we found at least one language for which the file is a header
7185 -- In such a case, we search for all possible languages where this is
7186 -- also a header (C and C++ for instance), since the file might be used
7187 -- for several such languages.
7189 procedure Check_File_Based_Lang;
7190 -- Does the naming scheme test for file-based languages. For those,
7191 -- there is no Unit. Just check if the file name has the implementation
7192 -- or, if it is specified, the template suffix of the language.
7194 -- Returns True if the file belongs to the current language and we
7195 -- should stop searching for matching languages. Not that a given header
7196 -- file could belong to several languages (C and C++ for instance). Thus
7197 -- if we found a header we'll check whether it matches other languages.
7199 ---------------------------
7200 -- Check_File_Based_Lang --
7201 ---------------------------
7203 procedure Check_File_Based_Lang is
7206 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
7210 Language := Tmp_Lang;
7212 if Current_Verbosity = High then
7213 Write_Str (" implementation of language ");
7214 Write_Line (Get_Name_String (Display_Language_Name));
7217 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
7218 if Current_Verbosity = High then
7219 Write_Str (" header of language ");
7220 Write_Line (Get_Name_String (Display_Language_Name));
7224 Alternate_Languages := new Language_List_Element'
7225 (Language => Language,
7226 Next => Alternate_Languages);
7229 Header_File := True;
7232 Language := Tmp_Lang;
7235 end Check_File_Based_Lang;
7237 -- Start of processing for Check_File_Naming_Schemes
7240 Language := No_Language_Index;
7241 Alternate_Languages := null;
7242 Display_Language_Name := No_Name;
7244 Lang_Kind := File_Based;
7247 Tmp_Lang := Project.Languages;
7248 while Tmp_Lang /= No_Language_Index loop
7249 if Current_Verbosity = High then
7251 (" Testing language "
7252 & Get_Name_String (Tmp_Lang.Name)
7253 & " Header_File=" & Header_File'Img);
7256 Display_Language_Name := Tmp_Lang.Display_Name;
7257 Config := Tmp_Lang.Config;
7258 Lang_Kind := Config.Kind;
7262 Check_File_Based_Lang;
7263 exit when Kind = Impl;
7267 -- We know it belongs to a least a file_based language, no
7268 -- need to check unit-based ones.
7270 if not Header_File then
7272 (File_Name => File_Name,
7273 Dot_Replacement => Config.Naming_Data.Dot_Replacement,
7274 Separate_Suffix => Config.Naming_Data.Separate_Suffix,
7275 Body_Suffix => Config.Naming_Data.Body_Suffix,
7276 Spec_Suffix => Config.Naming_Data.Spec_Suffix,
7277 Casing => Config.Naming_Data.Casing,
7280 In_Tree => In_Tree);
7282 if Unit /= No_Name then
7283 Language := Tmp_Lang;
7289 Tmp_Lang := Tmp_Lang.Next;
7292 if Language = No_Language_Index
7293 and then Current_Verbosity = High
7295 Write_Line (" not a source of any language");
7297 end Check_File_Naming_Schemes;
7303 procedure Check_File
7304 (Project : Project_Id;
7305 In_Tree : Project_Tree_Ref;
7306 Path : Path_Name_Type;
7307 File_Name : File_Name_Type;
7308 Display_File_Name : File_Name_Type;
7309 For_All_Sources : Boolean)
7311 Canonical_Path : constant Path_Name_Type :=
7313 (Canonical_Case_File_Name (Name_Id (Path)));
7315 Name_Loc : Name_Location := Source_Names.Get (File_Name);
7316 Check_Name : Boolean := False;
7317 Alternate_Languages : Language_List;
7318 Language : Language_Ptr;
7320 Other_Part : Source_Id;
7322 Src_Ind : Source_File_Index;
7324 Source_To_Replace : Source_Id := No_Source;
7325 Display_Language_Name : Name_Id;
7326 Lang_Kind : Language_Kind;
7327 Kind : Source_Kind := Spec;
7328 Iter : Source_Iterator;
7331 if Name_Loc = No_Name_Location then
7332 Check_Name := For_All_Sources;
7335 if Name_Loc.Found then
7337 -- Check if it is OK to have the same file name in several
7338 -- source directories.
7340 if not Project.Known_Order_Of_Source_Dirs then
7341 Error_Msg_File_1 := File_Name;
7344 "{ is found in several source directories",
7349 Name_Loc.Found := True;
7351 Source_Names.Set (File_Name, Name_Loc);
7353 if Name_Loc.Source = No_Source then
7357 Name_Loc.Source.Path := (Canonical_Path, Path);
7359 Source_Paths_Htable.Set
7360 (In_Tree.Source_Paths_HT,
7364 -- Check if this is a subunit
7366 if Name_Loc.Source.Unit /= No_Name
7367 and then Name_Loc.Source.Kind = Impl
7369 Src_Ind := Sinput.P.Load_Project_File
7370 (Get_Name_String (Canonical_Path));
7372 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7373 Name_Loc.Source.Kind := Sep;
7381 Other_Part := No_Source;
7383 Check_File_Naming_Schemes
7384 (In_Tree => In_Tree,
7386 File_Name => File_Name,
7387 Alternate_Languages => Alternate_Languages,
7388 Language => Language,
7389 Display_Language_Name => Display_Language_Name,
7391 Lang_Kind => Lang_Kind,
7394 if Language = No_Language_Index then
7396 -- A file name in a list must be a source of a language
7398 if Name_Loc.Found then
7399 Error_Msg_File_1 := File_Name;
7403 "language unknown for {",
7408 -- Check if the same file name or unit is used in the prj tree
7410 Iter := For_Each_Source (In_Tree);
7413 Source := Prj.Element (Iter);
7414 exit when Source = No_Source;
7417 and then Source.Unit = Unit
7419 ((Source.Kind = Spec and then Kind = Impl)
7421 (Source.Kind = Impl and then Kind = Spec))
7423 Other_Part := Source;
7425 elsif (Unit /= No_Name
7426 and then Source.Unit = Unit
7430 (Source.Kind = Sep and then Kind = Impl)
7432 (Source.Kind = Impl and then Kind = Sep)))
7434 (Unit = No_Name and then Source.File = File_Name)
7436 -- Duplication of file/unit in same project is only
7437 -- allowed if order of source directories is known.
7439 if Project = Source.Project then
7440 if Project.Known_Order_Of_Source_Dirs then
7443 elsif Unit /= No_Name then
7444 Error_Msg_Name_1 := Unit;
7446 (Project, In_Tree, "duplicate unit %%",
7451 Error_Msg_File_1 := File_Name;
7453 (Project, In_Tree, "duplicate source file name {",
7458 -- Do not allow the same unit name in different projects,
7459 -- except if one is extending the other.
7461 -- For a file based language, the same file name replaces
7462 -- a file in a project being extended, but it is allowed
7463 -- to have the same file name in unrelated projects.
7465 elsif Is_Extending (Project, Source.Project) then
7466 Source_To_Replace := Source;
7468 elsif Unit /= No_Name
7469 and then not Source.Locally_Removed
7471 Error_Msg_Name_1 := Unit;
7474 "unit %% cannot belong to several projects",
7477 Error_Msg_Name_1 := Project.Name;
7478 Error_Msg_Name_2 := Name_Id (Path);
7480 (Project, In_Tree, "\ project %%, %%", No_Location);
7482 Error_Msg_Name_1 := Source.Project.Name;
7483 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
7485 (Project, In_Tree, "\ project %%, %%", No_Location);
7499 Lang_Id => Language,
7500 Lang_Kind => Lang_Kind,
7502 Alternate_Languages => Alternate_Languages,
7503 File_Name => File_Name,
7504 Display_File => Display_File_Name,
7505 Other_Part => Other_Part,
7507 Path => (Canonical_Path, Path),
7508 Source_To_Replace => Source_To_Replace);
7514 ------------------------
7515 -- Search_Directories --
7516 ------------------------
7518 procedure Search_Directories
7519 (Project : Project_Id;
7520 In_Tree : Project_Tree_Ref;
7521 For_All_Sources : Boolean)
7523 Source_Dir : String_List_Id;
7524 Element : String_Element;
7526 Name : String (1 .. 1_000);
7528 File_Name : File_Name_Type;
7529 Display_File_Name : File_Name_Type;
7532 if Current_Verbosity = High then
7533 Write_Line ("Looking for sources:");
7536 -- Loop through subdirectories
7538 Source_Dir := Project.Source_Dirs;
7539 while Source_Dir /= Nil_String loop
7541 Element := In_Tree.String_Elements.Table (Source_Dir);
7542 if Element.Value /= No_Name then
7543 Get_Name_String (Element.Display_Value);
7546 Source_Directory : constant String :=
7547 Name_Buffer (1 .. Name_Len) &
7548 Directory_Separator;
7550 Dir_Last : constant Natural :=
7551 Compute_Directory_Last
7555 if Current_Verbosity = High then
7556 Write_Attr ("Source_Dir", Source_Directory);
7559 -- We look to every entry in the source directory
7561 Open (Dir, Source_Directory);
7564 Read (Dir, Name, Last);
7568 -- ??? Duplicate system call here, we just did a
7569 -- a similar one. Maybe Ada.Directories would be more
7573 (Source_Directory & Name (1 .. Last))
7575 if Current_Verbosity = High then
7576 Write_Str (" Checking ");
7577 Write_Line (Name (1 .. Last));
7581 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7582 Display_File_Name := Name_Find;
7584 if Osint.File_Names_Case_Sensitive then
7585 File_Name := Display_File_Name;
7587 Canonical_Case_File_Name
7588 (Name_Buffer (1 .. Name_Len));
7589 File_Name := Name_Find;
7593 Path_Name : constant String :=
7596 Directory => Source_Directory
7597 (Source_Directory'First .. Dir_Last),
7598 Resolve_Links => Opt.Follow_Links_For_Files,
7599 Case_Sensitive => True); -- no folding
7601 Path : Path_Name_Type;
7603 Excluded_Sources_Htable.Get (File_Name);
7606 Name_Len := Path_Name'Length;
7607 Name_Buffer (1 .. Name_Len) := Path_Name;
7610 if FF /= No_File_Found then
7611 if not FF.Found then
7613 Excluded_Sources_Htable.Set (File_Name, FF);
7615 if Current_Verbosity = High then
7616 Write_Str (" excluded source """);
7617 Write_Str (Get_Name_String (File_Name));
7624 (Project => Project,
7627 File_Name => File_Name,
7628 Display_File_Name => Display_File_Name,
7629 For_All_Sources => For_All_Sources);
7640 when Directory_Error =>
7644 Source_Dir := Element.Next;
7647 if Current_Verbosity = High then
7648 Write_Line ("end Looking for sources.");
7650 end Search_Directories;
7652 ----------------------------
7653 -- Load_Naming_Exceptions --
7654 ----------------------------
7656 procedure Load_Naming_Exceptions
7657 (Project : Project_Id;
7658 In_Tree : Project_Tree_Ref)
7661 Iter : Source_Iterator;
7664 Unit_Exceptions.Reset;
7666 Iter := For_Each_Source (In_Tree, Project);
7668 Source := Prj.Element (Iter);
7669 exit when Source = No_Source;
7671 -- An excluded file cannot also be an exception file name
7673 if Excluded_Sources_Htable.Get (Source.File) /= No_File_Found then
7674 Error_Msg_File_1 := Source.File;
7677 "{ cannot be both excluded and an exception file name",
7681 if Current_Verbosity = High then
7682 Write_Str ("Naming exception: Putting source file ");
7683 Write_Str (Get_Name_String (Source.File));
7684 Write_Line (" in Source_Names");
7690 (Name => Source.File,
7691 Location => No_Location,
7693 Except => Source.Unit /= No_Name,
7696 -- If this is an Ada exception, record in table Unit_Exceptions
7698 if Source.Unit /= No_Name then
7700 Unit_Except : Unit_Exception :=
7701 Unit_Exceptions.Get (Source.Unit);
7704 Unit_Except.Name := Source.Unit;
7706 if Source.Kind = Spec then
7707 Unit_Except.Spec := Source.File;
7709 Unit_Except.Impl := Source.File;
7712 Unit_Exceptions.Set (Source.Unit, Unit_Except);
7718 end Load_Naming_Exceptions;
7720 ----------------------
7721 -- Look_For_Sources --
7722 ----------------------
7724 procedure Look_For_Sources
7725 (Project : Project_Id;
7726 In_Tree : Project_Tree_Ref;
7727 Proc_Data : in out Processing_Data)
7729 Iter : Source_Iterator;
7731 procedure Process_Sources_In_Multi_Language_Mode;
7732 -- Find all source files when in multi language mode
7734 procedure Mark_Excluded_Sources;
7735 -- Mark as such the sources that are declared as excluded
7737 ---------------------------
7738 -- Mark_Excluded_Sources --
7739 ---------------------------
7741 procedure Mark_Excluded_Sources is
7742 Source : Source_Id := No_Source;
7745 Excluded : File_Found := Excluded_Sources_Htable.Get_First;
7748 (Extended : Project_Id;
7750 Kind : Spec_Or_Body);
7751 -- If the current file (Excluded) belongs to the current project or
7752 -- one that the current project extends, then mark this file/unit as
7753 -- excluded. It is an error to locally remove a file from another
7761 (Extended : Project_Id;
7763 Kind : Spec_Or_Body)
7766 if Extended = Project
7767 or else Is_Extending (Project, Extended)
7771 if Index /= No_Unit_Index then
7772 Unit.File_Names (Kind).Path.Name := Slash;
7773 Unit.File_Names (Kind).Needs_Pragma := False;
7774 In_Tree.Units.Table (Index) := Unit;
7777 if Source /= No_Source then
7778 Source.Locally_Removed := True;
7779 Source.In_Interfaces := False;
7782 if Current_Verbosity = High then
7783 Write_Str ("Removing file ");
7784 Write_Line (Get_Name_String (Excluded.File));
7787 Add_Forbidden_File_Name (Excluded.File);
7792 "cannot remove a source from another project",
7797 -- Start of processing for Mark_Excluded_Sources
7800 while Excluded /= No_File_Found loop
7806 -- ??? This loop could be the same as for Multi_Language if
7807 -- we were setting In_Tree.First_Source when we search for
7808 -- Ada sources (basically once we have removed the use of
7809 -- Project.Ada_Sources).
7812 for Index in Unit_Table.First ..
7813 Unit_Table.Last (In_Tree.Units)
7815 Unit := In_Tree.Units.Table (Index);
7817 for Kind in Spec_Or_Body'Range loop
7818 if Unit.File_Names (Kind).Name = Excluded.File then
7819 Exclude (Unit.File_Names (Kind).Project, Index, Kind);
7823 end loop For_Each_Unit;
7825 when Multi_Language =>
7826 Iter := For_Each_Source (In_Tree);
7828 Source := Prj.Element (Iter);
7829 exit when Source = No_Source;
7831 if Source.File = Excluded.File then
7832 Exclude (Source.Project, No_Unit_Index, Specification);
7839 OK := OK or Excluded.Found;
7843 Err_Vars.Error_Msg_File_1 := Excluded.File;
7845 (Project, In_Tree, "unknown file {", Excluded.Location);
7848 Excluded := Excluded_Sources_Htable.Get_Next;
7850 end Mark_Excluded_Sources;
7852 --------------------------------------------
7853 -- Process_Sources_In_Multi_Language_Mode --
7854 --------------------------------------------
7856 procedure Process_Sources_In_Multi_Language_Mode is
7857 Iter : Source_Iterator;
7859 -- Check that two sources of this project do not have the same object
7862 Check_Object_File_Names : declare
7864 Source_Name : File_Name_Type;
7866 procedure Check_Object (Src : Source_Id);
7867 -- Check if object file name of the current source is already in
7868 -- hash table Object_File_Names. If it is, report an error. If it
7869 -- is not, put it there with the file name of the current source.
7875 procedure Check_Object (Src : Source_Id) is
7877 Source_Name := Object_File_Names.Get (Src.Object);
7879 if Source_Name /= No_File then
7880 Error_Msg_File_1 := Src.File;
7881 Error_Msg_File_2 := Source_Name;
7885 "{ and { have the same object file name",
7889 Object_File_Names.Set (Src.Object, Src.File);
7893 -- Start of processing for Check_Object_File_Names
7896 Object_File_Names.Reset;
7897 Iter := For_Each_Source (In_Tree);
7899 Src_Id := Prj.Element (Iter);
7900 exit when Src_Id = No_Source;
7902 if Src_Id.Compiled and then Src_Id.Object_Exists
7903 and then Is_Extending (Project, Src_Id.Project)
7905 if Src_Id.Unit = No_Name then
7906 if Src_Id.Kind = Impl then
7907 Check_Object (Src_Id);
7913 if Src_Id.Other_Part = No_Source then
7914 Check_Object (Src_Id);
7921 if Src_Id.Other_Part /= No_Source then
7922 Check_Object (Src_Id);
7925 -- Check if it is a subunit
7928 Src_Ind : constant Source_File_Index :=
7929 Sinput.P.Load_Project_File
7931 (Src_Id.Path.Name));
7933 if Sinput.P.Source_File_Is_Subunit
7938 Check_Object (Src_Id);
7948 end Check_Object_File_Names;
7949 end Process_Sources_In_Multi_Language_Mode;
7951 -- Start of processing for Look_For_Sources
7955 Find_Excluded_Sources (Project, In_Tree);
7957 if (Get_Mode = Ada_Only and then Is_A_Language (Project, Name_Ada))
7958 or else (Get_Mode = Multi_Language
7959 and then Project.Languages /= No_Language_Index)
7961 if Get_Mode = Multi_Language then
7962 Load_Naming_Exceptions (Project, In_Tree);
7965 Find_Sources (Project, In_Tree, Proc_Data);
7966 Mark_Excluded_Sources;
7968 if Get_Mode = Multi_Language then
7969 Process_Sources_In_Multi_Language_Mode;
7972 end Look_For_Sources;
7978 function Path_Name_Of
7979 (File_Name : File_Name_Type;
7980 Directory : Path_Name_Type) return String
7982 Result : String_Access;
7983 The_Directory : constant String := Get_Name_String (Directory);
7986 Get_Name_String (File_Name);
7989 (File_Name => Name_Buffer (1 .. Name_Len),
7990 Path => The_Directory);
7992 if Result = null then
7996 R : String := Result.all;
7999 Canonical_Case_File_Name (R);
8005 -----------------------------------
8006 -- Prepare_Ada_Naming_Exceptions --
8007 -----------------------------------
8009 procedure Prepare_Ada_Naming_Exceptions
8010 (List : Array_Element_Id;
8011 In_Tree : Project_Tree_Ref;
8012 Kind : Spec_Or_Body)
8014 Current : Array_Element_Id;
8015 Element : Array_Element;
8019 -- Traverse the list
8022 while Current /= No_Array_Element loop
8023 Element := In_Tree.Array_Elements.Table (Current);
8025 if Element.Index /= No_Name then
8028 Unit => Element.Index,
8029 Next => No_Ada_Naming_Exception);
8030 Reverse_Ada_Naming_Exceptions.Set
8031 (Unit, (Element.Value.Value, Element.Value.Index));
8033 Ada_Naming_Exceptions.Get (File_Name_Type (Element.Value.Value));
8034 Ada_Naming_Exception_Table.Increment_Last;
8035 Ada_Naming_Exception_Table.Table
8036 (Ada_Naming_Exception_Table.Last) := Unit;
8037 Ada_Naming_Exceptions.Set
8038 (File_Name_Type (Element.Value.Value),
8039 Ada_Naming_Exception_Table.Last);
8042 Current := Element.Next;
8044 end Prepare_Ada_Naming_Exceptions;
8046 -----------------------
8047 -- Record_Ada_Source --
8048 -----------------------
8050 procedure Record_Ada_Source
8051 (File_Name : File_Name_Type;
8052 Path_Name : Path_Name_Type;
8053 Project : Project_Id;
8054 In_Tree : Project_Tree_Ref;
8055 Proc_Data : in out Processing_Data;
8056 Ada_Language : Language_Ptr;
8057 Location : Source_Ptr;
8058 Source_Recorded : in out Boolean)
8060 Canonical_File : File_Name_Type;
8061 Canonical_Path : Path_Name_Type;
8063 File_Recorded : Boolean := False;
8064 -- True when at least one file has been recorded
8066 procedure Record_Unit
8067 (Unit_Name : Name_Id;
8068 Unit_Ind : Int := 0;
8069 Unit_Kind : Spec_Or_Body;
8070 Needs_Pragma : Boolean);
8071 -- Register of the units contained in the source file (there is in
8072 -- general a single such unit except when exceptions to the naming
8073 -- scheme indicate there are several such units)
8079 procedure Record_Unit
8080 (Unit_Name : Name_Id;
8081 Unit_Ind : Int := 0;
8082 Unit_Kind : Spec_Or_Body;
8083 Needs_Pragma : Boolean)
8085 The_Unit : Unit_Index :=
8086 Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
8090 To_Record : Boolean := False;
8091 The_Location : Source_Ptr := Location;
8092 Unit_Prj : Project_Id;
8095 if Current_Verbosity = High then
8096 Write_Str (" Putting ");
8097 Write_Str (Get_Name_String (Unit_Name));
8098 Write_Line (" in the unit list.");
8101 -- The unit is already in the list, but may be it is only the other
8102 -- unit kind (spec or body), or what is in the unit list is a unit of
8103 -- a project we are extending.
8105 if The_Unit /= No_Unit_Index then
8106 UData := In_Tree.Units.Table (The_Unit);
8108 if (UData.File_Names (Unit_Kind).Name = Canonical_File
8109 and then UData.File_Names (Unit_Kind).Path.Name = Slash)
8110 or else UData.File_Names (Unit_Kind).Name = No_File
8111 or else Is_Extending
8112 (Project.Extends, UData.File_Names (Unit_Kind).Project)
8114 if UData.File_Names (Unit_Kind).Path.Name = Slash then
8115 Remove_Forbidden_File_Name
8116 (UData.File_Names (Unit_Kind).Name);
8119 -- Record the file name in the hash table Files_Htable
8121 Files_Htable.Set (Proc_Data.Units, Canonical_File, Project);
8123 UData.File_Names (Unit_Kind) :=
8124 (Name => Canonical_File,
8126 Display_Name => File_Name,
8127 Path => (Canonical_Path, Path_Name),
8129 Needs_Pragma => Needs_Pragma);
8130 In_Tree.Units.Table (The_Unit) := UData;
8132 Source_Recorded := True;
8134 -- If the same file is already in the list, do not add it again
8136 elsif UData.File_Names (Unit_Kind).Project = Project
8138 (Project.Known_Order_Of_Source_Dirs
8140 UData.File_Names (Unit_Kind).Path.Name = Canonical_Path)
8144 -- Else, same unit but not same file => It is an error to have two
8145 -- units with the same name and the same kind (spec or body).
8148 if The_Location = No_Location then
8149 The_Location := Project.Location;
8152 Err_Vars.Error_Msg_Name_1 := Unit_Name;
8154 (Project, In_Tree, "duplicate unit %%", The_Location);
8156 Err_Vars.Error_Msg_Name_1 :=
8157 UData.File_Names (Unit_Kind).Project.Name;
8158 Err_Vars.Error_Msg_File_1 :=
8159 File_Name_Type (UData.File_Names (Unit_Kind).Path.Name);
8162 "\ project file %%, {", The_Location);
8164 Err_Vars.Error_Msg_Name_1 := Project.Name;
8165 Err_Vars.Error_Msg_File_1 := File_Name_Type (Canonical_Path);
8167 (Project, In_Tree, "\ project file %%, {", The_Location);
8172 -- It is a new unit, create a new record
8175 -- First, check if there is no other unit with this file name in
8176 -- another project. If it is, report error but note we do that
8177 -- only for the first unit in the source file.
8179 Unit_Prj := Files_Htable.Get (Proc_Data.Units, Canonical_File);
8181 if not File_Recorded
8182 and then Unit_Prj /= No_Project
8184 Error_Msg_File_1 := File_Name;
8185 Error_Msg_Name_1 := Unit_Prj.Name;
8188 "{ is already a source of project %%",
8192 Unit_Table.Increment_Last (In_Tree.Units);
8193 The_Unit := Unit_Table.Last (In_Tree.Units);
8194 Units_Htable.Set (In_Tree.Units_HT, Unit_Name, The_Unit);
8196 Files_Htable.Set (Proc_Data.Units, Canonical_File, Project);
8198 UData.Name := Unit_Name;
8199 UData.File_Names (Unit_Kind) :=
8200 (Name => Canonical_File,
8202 Display_Name => File_Name,
8203 Path => (Canonical_Path, Path_Name),
8205 Needs_Pragma => Needs_Pragma);
8206 In_Tree.Units.Table (The_Unit) := UData;
8208 Source_Recorded := True;
8215 when Body_Part => Kind := Impl;
8216 when Specification => Kind := Spec;
8223 Lang_Id => Ada_Language,
8224 Lang_Kind => Unit_Based,
8225 File_Name => Canonical_File,
8226 Display_File => File_Name,
8228 Path => (Canonical_Path, Path_Name),
8230 Other_Part => No_Source); -- ??? Can we find file ?
8234 Exception_Id : Ada_Naming_Exception_Id;
8235 Unit_Name : Name_Id;
8236 Unit_Kind : Spec_Or_Body;
8237 Unit_Ind : Int := 0;
8239 Name_Index : Name_And_Index;
8240 Except_Name : Name_And_Index := No_Name_And_Index;
8241 Needs_Pragma : Boolean;
8244 Canonical_File := Canonical_Case_File_Name (Name_Id (File_Name));
8246 Path_Name_Type (Canonical_Case_File_Name (Name_Id (Path_Name)));
8248 -- Check the naming scheme to get extra file properties
8251 (In_Tree => In_Tree,
8252 Canonical_File_Name => Canonical_File,
8253 Naming => Project.Naming,
8254 Exception_Id => Exception_Id,
8255 Unit_Name => Unit_Name,
8256 Unit_Kind => Unit_Kind);
8258 Needs_Pragma := Exception_Id /= No_Ada_Naming_Exception;
8260 if Exception_Id = No_Ada_Naming_Exception
8261 and then Unit_Name = No_Name
8263 if Current_Verbosity = High then
8265 Write_Str (Get_Name_String (Canonical_File));
8266 Write_Line (""" is not a valid source file name (ignored).");
8271 -- Check to see if the source has been hidden by an exception,
8272 -- but only if it is not an exception.
8274 if not Needs_Pragma then
8276 Reverse_Ada_Naming_Exceptions.Get
8277 ((Unit_Kind, Unit_Name, No_Ada_Naming_Exception));
8279 if Except_Name /= No_Name_And_Index then
8280 if Current_Verbosity = High then
8282 Write_Str (Get_Name_String (Canonical_File));
8283 Write_Str (""" contains a unit that is found in """);
8284 Write_Str (Get_Name_String (Except_Name.Name));
8285 Write_Line (""" (ignored).");
8288 -- The file is not included in the source of the project since it
8289 -- is hidden by the exception. So, nothing else to do.
8295 -- The following loop registers the unit in the appropriate table. It
8296 -- will be executed multiple times when the file is a multi-unit file,
8297 -- in which case Exception_Id initially points to the first file and
8298 -- then to each other unit in the file.
8301 if Exception_Id /= No_Ada_Naming_Exception then
8302 Info := Ada_Naming_Exception_Table.Table (Exception_Id);
8303 Exception_Id := Info.Next;
8304 Info.Next := No_Ada_Naming_Exception;
8305 Name_Index := Reverse_Ada_Naming_Exceptions.Get (Info);
8307 Unit_Name := Info.Unit;
8308 Unit_Ind := Name_Index.Index;
8309 Unit_Kind := Info.Kind;
8312 Record_Unit (Unit_Name, Unit_Ind, Unit_Kind, Needs_Pragma);
8313 File_Recorded := True;
8315 exit when Exception_Id = No_Ada_Naming_Exception;
8317 end Record_Ada_Source;
8323 procedure Remove_Source
8325 Replaced_By : Source_Id)
8330 if Current_Verbosity = High then
8331 Write_Str ("Removing source ");
8332 Write_Line (Get_Name_String (Id.File));
8335 if Replaced_By /= No_Source then
8336 Id.Replaced_By := Replaced_By;
8337 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
8340 Source := Id.Language.First_Source;
8343 Id.Language.First_Source := Id.Next_In_Lang;
8346 while Source.Next_In_Lang /= Id loop
8347 Source := Source.Next_In_Lang;
8350 Source.Next_In_Lang := Id.Next_In_Lang;
8354 -----------------------
8355 -- Report_No_Sources --
8356 -----------------------
8358 procedure Report_No_Sources
8359 (Project : Project_Id;
8361 In_Tree : Project_Tree_Ref;
8362 Location : Source_Ptr;
8363 Continuation : Boolean := False)
8366 case When_No_Sources is
8370 when Warning | Error =>
8372 Msg : constant String :=
8375 " sources in this project";
8378 Error_Msg_Warn := When_No_Sources = Warning;
8380 if Continuation then
8381 Error_Msg (Project, In_Tree, "\" & Msg, Location);
8383 Error_Msg (Project, In_Tree, Msg, Location);
8387 end Report_No_Sources;
8389 ----------------------
8390 -- Show_Source_Dirs --
8391 ----------------------
8393 procedure Show_Source_Dirs
8394 (Project : Project_Id;
8395 In_Tree : Project_Tree_Ref)
8397 Current : String_List_Id;
8398 Element : String_Element;
8401 Write_Line ("Source_Dirs:");
8403 Current := Project.Source_Dirs;
8404 while Current /= Nil_String loop
8405 Element := In_Tree.String_Elements.Table (Current);
8407 Write_Line (Get_Name_String (Element.Value));
8408 Current := Element.Next;
8411 Write_Line ("end Source_Dirs.");
8412 end Show_Source_Dirs;
8414 -------------------------
8415 -- Warn_If_Not_Sources --
8416 -------------------------
8418 -- comments needed in this body ???
8420 procedure Warn_If_Not_Sources
8421 (Project : Project_Id;
8422 In_Tree : Project_Tree_Ref;
8423 Conventions : Array_Element_Id;
8425 Extending : Boolean)
8427 Conv : Array_Element_Id;
8429 The_Unit_Id : Unit_Index;
8430 The_Unit_Data : Unit_Data;
8431 Location : Source_Ptr;
8434 Conv := Conventions;
8435 while Conv /= No_Array_Element loop
8436 Unit := In_Tree.Array_Elements.Table (Conv).Index;
8437 Error_Msg_Name_1 := Unit;
8438 Get_Name_String (Unit);
8439 To_Lower (Name_Buffer (1 .. Name_Len));
8441 The_Unit_Id := Units_Htable.Get (In_Tree.Units_HT, Unit);
8442 Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
8444 if The_Unit_Id = No_Unit_Index then
8445 Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
8448 The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
8450 In_Tree.Array_Elements.Table (Conv).Value.Value;
8453 if not Check_Project
8454 (The_Unit_Data.File_Names (Specification).Project,
8459 "?source of spec of unit %% (%%)" &
8460 " not found in this project",
8465 if not Check_Project
8466 (The_Unit_Data.File_Names (Body_Part).Project,
8471 "?source of body of unit %% (%%)" &
8472 " not found in this project",
8478 Conv := In_Tree.Array_Elements.Table (Conv).Next;
8480 end Warn_If_Not_Sources;