1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-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 Err_Vars; use Err_Vars;
28 with Osint; use Osint;
29 with Output; use Output;
30 with Prj.Com; use Prj.Com;
32 with Prj.Err; use Prj.Err;
33 with Prj.Ext; use Prj.Ext;
34 with Sinput; use Sinput;
35 with Sinput.P; use Sinput.P;
39 with Ada.Characters.Handling; use Ada.Characters.Handling;
40 with Ada.Exceptions; use Ada.Exceptions;
42 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
44 with System.HTable; use System.HTable;
46 package body Prj.Part is
48 Buffer : String_Access;
49 Buffer_Last : Natural := 0;
51 Dir_Sep : Character renames GNAT.OS_Lib.Directory_Separator;
53 ------------------------------------
54 -- Local Packages and Subprograms --
55 ------------------------------------
57 type With_Id is new Nat;
58 No_With : constant With_Id := 0;
60 type With_Record is record
61 Path : Path_Name_Type;
62 Location : Source_Ptr;
63 Limited_With : Boolean;
64 Node : Project_Node_Id;
67 -- Information about an imported project, to be put in table Withs below
69 package Withs is new Table.Table
70 (Table_Component_Type => With_Record,
71 Table_Index_Type => With_Id,
74 Table_Increment => 100,
75 Table_Name => "Prj.Part.Withs");
76 -- Table used to store temporarily paths and locations of imported
77 -- projects. These imported projects will be effectively parsed later: just
78 -- before parsing the current project for the non limited withed projects,
79 -- after getting its name; after complete parsing of the current project
80 -- for the limited withed projects.
82 type Names_And_Id is record
83 Path_Name : Path_Name_Type;
84 Canonical_Path_Name : Path_Name_Type;
86 Limited_With : Boolean;
89 package Project_Stack is new Table.Table
90 (Table_Component_Type => Names_And_Id,
91 Table_Index_Type => Nat,
94 Table_Increment => 100,
95 Table_Name => "Prj.Part.Project_Stack");
96 -- This table is used to detect circular dependencies
97 -- for imported and extended projects and to get the project ids of
98 -- limited imported projects when there is a circularity with at least
99 -- one limited imported project file.
101 package Virtual_Hash is new System.HTable.Simple_HTable
102 (Header_Num => Header_Num,
103 Element => Project_Node_Id,
104 No_Element => Empty_Node,
105 Key => Project_Node_Id,
106 Hash => Prj.Tree.Hash,
108 -- Hash table to store the node id of the project for which a virtual
109 -- extending project need to be created.
111 package Processed_Hash is new System.HTable.Simple_HTable
112 (Header_Num => Header_Num,
115 Key => Project_Node_Id,
116 Hash => Prj.Tree.Hash,
118 -- Hash table to store the project process when looking for project that
119 -- need to have a virtual extending project, to avoid processing the same
122 package Projects_Paths is new System.HTable.Simple_HTable
123 (Header_Num => Header_Num,
124 Element => Path_Name_Type,
125 No_Element => No_Path,
129 -- Hash table to cache project path to avoid looking for them on the path
131 procedure Create_Virtual_Extending_Project
132 (For_Project : Project_Node_Id;
133 Main_Project : Project_Node_Id;
134 In_Tree : Project_Node_Tree_Ref);
135 -- Create a virtual extending project of For_Project. Main_Project is
136 -- the extending all project.
138 -- The String_Value_Of is not set for the automatically added with
139 -- clause and keeps the default value of No_Name. This enables Prj.PP
140 -- to skip these automatically added with clauses to be processed.
142 procedure Look_For_Virtual_Projects_For
143 (Proj : Project_Node_Id;
144 In_Tree : Project_Node_Tree_Ref;
145 Potentially_Virtual : Boolean);
146 -- Look for projects that need to have a virtual extending project.
147 -- This procedure is recursive. If called with Potentially_Virtual set to
148 -- True, then Proj may need an virtual extending project; otherwise it
149 -- does not (because it is already extended), but other projects that it
150 -- imports may need to be virtually extended.
152 type Extension_Origin is (None, Extending_Simple, Extending_All);
153 -- Type of parameter From_Extended for procedures Parse_Single_Project and
154 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
155 -- tree rooted at an extending all project.
157 procedure Parse_Single_Project
158 (In_Tree : Project_Node_Tree_Ref;
159 Project : out Project_Node_Id;
160 Extends_All : out Boolean;
163 From_Extended : Extension_Origin;
164 In_Limited : Boolean;
165 Packages_To_Check : String_List_Access;
167 Current_Dir : String;
168 Is_Config_File : Boolean;
169 Flags : Processing_Flags);
170 -- Parse a project file. This is a recursive procedure: it calls itself for
171 -- imported and extended projects. When From_Extended is not None, if the
172 -- project has already been parsed and is an extended project A, return the
173 -- ultimate (not extended) project that extends A. When In_Limited is True,
174 -- the importing path includes at least one "limited with". When parsing
175 -- configuration projects, do not allow a depth > 1.
177 -- Is_Config_File should be set to True if the project represents a config
178 -- file (.cgpr) since some specific checks apply.
180 procedure Pre_Parse_Context_Clause
181 (In_Tree : Project_Node_Tree_Ref;
182 Context_Clause : out With_Id;
183 Is_Config_File : Boolean;
184 Flags : Processing_Flags);
185 -- Parse the context clause of a project. Store the paths and locations of
186 -- the imported projects in table Withs. Does nothing if there is no
187 -- context clause (if the current token is not "with" or "limited" followed
189 -- Is_Config_File should be set to True if the project represents a config
190 -- file (.cgpr) since some specific checks apply.
192 procedure Post_Parse_Context_Clause
193 (Context_Clause : With_Id;
194 In_Tree : Project_Node_Tree_Ref;
195 Limited_Withs : Boolean;
196 Imported_Projects : in out Project_Node_Id;
197 Project_Directory : Path_Name_Type;
198 From_Extended : Extension_Origin;
199 In_Limited : Boolean;
200 Packages_To_Check : String_List_Access;
202 Current_Dir : String;
203 Is_Config_File : Boolean;
204 Flags : Processing_Flags);
205 -- Parse the imported projects that have been stored in table Withs, if
206 -- any. From_Extended is used for the call to Parse_Single_Project below.
207 -- When In_Limited is True, the importing path includes at least one
208 -- "limited with". When Limited_Withs is False, only non limited withed
209 -- projects are parsed. When Limited_Withs is True, only limited withed
210 -- projects are parsed.
211 -- Is_Config_File should be set to True if the project represents a config
212 -- file (.cgpr) since some specific checks apply.
214 function Project_Path_Name_Of
215 (Project_File_Name : String;
216 Directory : String) return String;
217 -- Returns the path name of a project file. Returns an empty string
218 -- if project file cannot be found.
220 function Project_Name_From
222 Is_Config_File : Boolean) return Name_Id;
223 -- Returns the name of the project that corresponds to its path name.
224 -- Returns No_Name if the path name is invalid, because the corresponding
225 -- project name does not have the syntax of an ada identifier.
227 --------------------------------------
228 -- Create_Virtual_Extending_Project --
229 --------------------------------------
231 procedure Create_Virtual_Extending_Project
232 (For_Project : Project_Node_Id;
233 Main_Project : Project_Node_Id;
234 In_Tree : Project_Node_Tree_Ref)
237 Virtual_Name : constant String :=
239 Get_Name_String (Name_Of (For_Project, In_Tree));
240 -- The name of the virtual extending project
242 Virtual_Name_Id : Name_Id;
243 -- Virtual extending project name id
245 Virtual_Path_Id : Path_Name_Type;
246 -- Fake path name of the virtual extending project. The directory is
247 -- the same directory as the extending all project.
249 -- The source of the virtual extending project is something like:
251 -- project V$<project name> extends <project path> is
253 -- for Source_Dirs use ();
255 -- end V$<project name>;
257 -- The project directory cannot be specified during parsing; it will be
258 -- put directly in the virtual extending project data during processing.
260 -- Nodes that made up the virtual extending project
262 Virtual_Project : Project_Node_Id;
263 With_Clause : constant Project_Node_Id :=
265 (In_Tree, N_With_Clause);
266 Project_Declaration : Project_Node_Id;
267 Source_Dirs_Declaration : constant Project_Node_Id :=
269 (In_Tree, N_Declarative_Item);
270 Source_Dirs_Attribute : constant Project_Node_Id :=
272 (In_Tree, N_Attribute_Declaration, List);
273 Source_Dirs_Expression : constant Project_Node_Id :=
275 (In_Tree, N_Expression, List);
276 Source_Dirs_Term : constant Project_Node_Id :=
278 (In_Tree, N_Term, List);
279 Source_Dirs_List : constant Project_Node_Id :=
281 (In_Tree, N_Literal_String_List, List);
284 -- Get the virtual path name
286 Get_Name_String (Path_Name_Of (Main_Project, In_Tree));
289 and then Name_Buffer (Name_Len) /= Directory_Separator
290 and then Name_Buffer (Name_Len) /= '/'
292 Name_Len := Name_Len - 1;
295 Name_Buffer (Name_Len + 1 .. Name_Len + Virtual_Name'Length) :=
297 Name_Len := Name_Len + Virtual_Name'Length;
298 Virtual_Path_Id := Name_Find;
300 -- Get the virtual name id
302 Name_Len := Virtual_Name'Length;
303 Name_Buffer (1 .. Name_Len) := Virtual_Name;
304 Virtual_Name_Id := Name_Find;
306 Virtual_Project := Create_Project
308 Name => Virtual_Name_Id,
309 Full_Path => Virtual_Path_Id,
310 Is_Config_File => False);
312 Project_Declaration := Project_Declaration_Of (Virtual_Project, In_Tree);
316 Set_Name_Of (With_Clause, In_Tree, Virtual_Name_Id);
317 Set_Path_Name_Of (With_Clause, In_Tree, Virtual_Path_Id);
318 Set_Project_Node_Of (With_Clause, In_Tree, Virtual_Project);
319 Set_Next_With_Clause_Of
320 (With_Clause, In_Tree, First_With_Clause_Of (Main_Project, In_Tree));
321 Set_First_With_Clause_Of (Main_Project, In_Tree, With_Clause);
323 -- Virtual project node
326 (Virtual_Project, In_Tree, Location_Of (Main_Project, In_Tree));
327 Set_Extended_Project_Path_Of
328 (Virtual_Project, In_Tree, Path_Name_Of (For_Project, In_Tree));
330 -- Project declaration
332 Set_First_Declarative_Item_Of
333 (Project_Declaration, In_Tree, Source_Dirs_Declaration);
334 Set_Extended_Project_Of (Project_Declaration, In_Tree, For_Project);
336 -- Source_Dirs declaration
338 Set_Current_Item_Node
339 (Source_Dirs_Declaration, In_Tree, Source_Dirs_Attribute);
341 -- Source_Dirs attribute
343 Set_Name_Of (Source_Dirs_Attribute, In_Tree, Snames.Name_Source_Dirs);
345 (Source_Dirs_Attribute, In_Tree, Source_Dirs_Expression);
347 -- Source_Dirs expression
349 Set_First_Term (Source_Dirs_Expression, In_Tree, Source_Dirs_Term);
353 Set_Current_Term (Source_Dirs_Term, In_Tree, Source_Dirs_List);
355 -- Source_Dirs empty list: nothing to do
356 end Create_Virtual_Extending_Project;
358 -----------------------------------
359 -- Look_For_Virtual_Projects_For --
360 -----------------------------------
362 procedure Look_For_Virtual_Projects_For
363 (Proj : Project_Node_Id;
364 In_Tree : Project_Node_Tree_Ref;
365 Potentially_Virtual : Boolean)
367 Declaration : Project_Node_Id := Empty_Node;
368 -- Node for the project declaration of Proj
370 With_Clause : Project_Node_Id := Empty_Node;
371 -- Node for a with clause of Proj
373 Imported : Project_Node_Id := Empty_Node;
374 -- Node for a project imported by Proj
376 Extended : Project_Node_Id := Empty_Node;
377 -- Node for the eventual project extended by Proj
380 -- Nothing to do if Proj is not defined or if it has already been
383 if Present (Proj) and then not Processed_Hash.Get (Proj) then
384 -- Make sure the project will not be processed again
386 Processed_Hash.Set (Proj, True);
388 Declaration := Project_Declaration_Of (Proj, In_Tree);
390 if Present (Declaration) then
391 Extended := Extended_Project_Of (Declaration, In_Tree);
394 -- If this is a project that may need a virtual extending project
395 -- and it is not itself an extending project, put it in the list.
397 if Potentially_Virtual and then No (Extended) then
398 Virtual_Hash.Set (Proj, Proj);
401 -- Now check the projects it imports
403 With_Clause := First_With_Clause_Of (Proj, In_Tree);
405 while Present (With_Clause) loop
406 Imported := Project_Node_Of (With_Clause, In_Tree);
408 if Present (Imported) then
409 Look_For_Virtual_Projects_For
410 (Imported, In_Tree, Potentially_Virtual => True);
413 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
416 -- Check also the eventual project extended by Proj. As this project
417 -- is already extended, call recursively with Potentially_Virtual
420 Look_For_Virtual_Projects_For
421 (Extended, In_Tree, Potentially_Virtual => False);
423 end Look_For_Virtual_Projects_For;
430 (In_Tree : Project_Node_Tree_Ref;
431 Project : out Project_Node_Id;
432 Project_File_Name : String;
433 Always_Errout_Finalize : Boolean;
434 Packages_To_Check : String_List_Access := All_Packages;
435 Store_Comments : Boolean := False;
436 Current_Directory : String := "";
437 Is_Config_File : Boolean;
438 Flags : Processing_Flags)
441 pragma Warnings (Off, Dummy);
443 Real_Project_File_Name : String_Access :=
444 Osint.To_Canonical_File_Spec
448 if Real_Project_File_Name = null then
449 Real_Project_File_Name := new String'(Project_File_Name);
452 Project := Empty_Node;
454 Projects_Paths.Reset;
456 if Current_Verbosity >= Medium then
457 Write_Str ("GPR_PROJECT_PATH=""");
458 Write_Str (Project_Path);
463 Path_Name : constant String :=
464 Project_Path_Name_Of (Real_Project_File_Name.all,
465 Directory => Current_Directory);
468 Free (Real_Project_File_Name);
471 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
472 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
474 -- Parse the main project file
476 if Path_Name = "" then
482 Project := Empty_Node;
489 Extends_All => Dummy,
490 Path_Name => Path_Name,
492 From_Extended => None,
494 Packages_To_Check => Packages_To_Check,
496 Current_Dir => Current_Directory,
497 Is_Config_File => Is_Config_File,
500 -- If Project is an extending-all project, create the eventual
501 -- virtual extending projects and check that there are no illegally
502 -- imported projects.
505 and then Is_Extending_All (Project, In_Tree)
507 -- First look for projects that potentially need a virtual
508 -- extending project.
511 Processed_Hash.Reset;
513 -- Mark the extending all project as processed, to avoid checking
514 -- the imported projects in case of a "limited with" on this
515 -- extending all project.
517 Processed_Hash.Set (Project, True);
520 Declaration : constant Project_Node_Id :=
521 Project_Declaration_Of (Project, In_Tree);
523 Look_For_Virtual_Projects_For
524 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
525 Potentially_Virtual => False);
528 -- Now, check the projects directly imported by the main project.
529 -- Remove from the potentially virtual any project extended by one
530 -- of these imported projects. For non extending imported
531 -- projects, check that they do not belong to the project tree of
532 -- the project being "extended-all" by the main project.
535 With_Clause : Project_Node_Id;
536 Imported : Project_Node_Id := Empty_Node;
537 Declaration : Project_Node_Id := Empty_Node;
540 With_Clause := First_With_Clause_Of (Project, In_Tree);
541 while Present (With_Clause) loop
542 Imported := Project_Node_Of (With_Clause, In_Tree);
544 if Present (Imported) then
545 Declaration := Project_Declaration_Of (Imported, In_Tree);
547 if Extended_Project_Of (Declaration, In_Tree) /=
552 Extended_Project_Of (Declaration, In_Tree);
553 exit when No (Imported);
554 Virtual_Hash.Remove (Imported);
556 Project_Declaration_Of (Imported, In_Tree);
561 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
565 -- Now create all the virtual extending projects
568 Proj : Project_Node_Id := Virtual_Hash.Get_First;
570 while Present (Proj) loop
571 Create_Virtual_Extending_Project (Proj, Project, In_Tree);
572 Proj := Virtual_Hash.Get_Next;
577 -- If there were any kind of error during the parsing, serious
578 -- or not, then the parsing fails.
580 if Err_Vars.Total_Errors_Detected > 0 then
581 Project := Empty_Node;
584 if No (Project) or else Always_Errout_Finalize then
594 Write_Line (Exception_Information (X));
595 Write_Str ("Exception ");
596 Write_Str (Exception_Name (X));
597 Write_Line (" raised, while processing project file");
598 Project := Empty_Node;
601 ------------------------------
602 -- Pre_Parse_Context_Clause --
603 ------------------------------
605 procedure Pre_Parse_Context_Clause
606 (In_Tree : Project_Node_Tree_Ref;
607 Context_Clause : out With_Id;
608 Is_Config_File : Boolean;
609 Flags : Processing_Flags)
611 Current_With_Clause : With_Id := No_With;
612 Limited_With : Boolean := False;
613 Current_With : With_Record;
614 Current_With_Node : Project_Node_Id := Empty_Node;
617 -- Assume no context clause
619 Context_Clause := No_With;
622 -- If Token is not WITH or LIMITED, there is no context clause, or we
623 -- have exhausted the with clauses.
625 while Token = Tok_With or else Token = Tok_Limited loop
627 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
628 Limited_With := Token = Tok_Limited;
630 if Is_Config_File then
633 "configuration project cannot import " &
634 "other configuration projects",
639 Scan (In_Tree); -- scan past LIMITED
640 Expect (Tok_With, "WITH");
641 exit With_Loop when Token /= Tok_With;
646 Scan (In_Tree); -- past WITH or ","
648 Expect (Tok_String_Literal, "literal string");
650 if Token /= Tok_String_Literal then
654 -- Store path and location in table Withs
657 (Path => Path_Name_Type (Token_Name),
658 Location => Token_Ptr,
659 Limited_With => Limited_With,
660 Node => Current_With_Node,
663 Withs.Increment_Last;
664 Withs.Table (Withs.Last) := Current_With;
666 if Current_With_Clause = No_With then
667 Context_Clause := Withs.Last;
670 Withs.Table (Current_With_Clause).Next := Withs.Last;
673 Current_With_Clause := Withs.Last;
677 if Token = Tok_Semicolon then
678 Set_End_Of_Line (Current_With_Node);
679 Set_Previous_Line_Node (Current_With_Node);
681 -- End of (possibly multiple) with clause;
683 Scan (In_Tree); -- past the semicolon
686 elsif Token = Tok_Comma then
687 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
690 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
696 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
699 end Pre_Parse_Context_Clause;
701 -------------------------------
702 -- Post_Parse_Context_Clause --
703 -------------------------------
705 procedure Post_Parse_Context_Clause
706 (Context_Clause : With_Id;
707 In_Tree : Project_Node_Tree_Ref;
708 Limited_Withs : Boolean;
709 Imported_Projects : in out Project_Node_Id;
710 Project_Directory : Path_Name_Type;
711 From_Extended : Extension_Origin;
712 In_Limited : Boolean;
713 Packages_To_Check : String_List_Access;
715 Current_Dir : String;
716 Is_Config_File : Boolean;
717 Flags : Processing_Flags)
719 Current_With_Clause : With_Id := Context_Clause;
721 Current_Project : Project_Node_Id := Imported_Projects;
722 Previous_Project : Project_Node_Id := Empty_Node;
723 Next_Project : Project_Node_Id := Empty_Node;
725 Project_Directory_Path : constant String :=
726 Get_Name_String (Project_Directory);
728 Current_With : With_Record;
729 Extends_All : Boolean := False;
732 -- Set Current_Project to the last project in the current list, if the
733 -- list is not empty.
735 if Present (Current_Project) then
737 Present (Next_With_Clause_Of (Current_Project, In_Tree))
739 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
743 while Current_With_Clause /= No_With loop
744 Current_With := Withs.Table (Current_With_Clause);
745 Current_With_Clause := Current_With.Next;
747 if Limited_Withs = Current_With.Limited_With then
749 Original_Path : constant String :=
750 Get_Name_String (Current_With.Path);
752 Imported_Path_Name : constant String :=
755 Project_Directory_Path);
757 Resolved_Path : constant String :=
760 Directory => Current_Dir,
762 Opt.Follow_Links_For_Files,
763 Case_Sensitive => True);
765 Withed_Project : Project_Node_Id := Empty_Node;
768 if Imported_Path_Name = "" then
770 -- The project file cannot be found
772 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
774 (Flags, "unknown project file: {", Current_With.Location);
776 -- If this is not imported by the main project file, display
779 if Project_Stack.Last > 1 then
780 for Index in reverse 1 .. Project_Stack.Last loop
783 (Project_Stack.Table (Index).Path_Name);
785 (Flags, "\imported by {", Current_With.Location);
792 Previous_Project := Current_Project;
794 if No (Current_Project) then
796 -- First with clause of the context clause
798 Current_Project := Current_With.Node;
799 Imported_Projects := Current_Project;
802 Next_Project := Current_With.Node;
803 Set_Next_With_Clause_Of
804 (Current_Project, In_Tree, Next_Project);
805 Current_Project := Next_Project;
811 Name_Id (Current_With.Path));
813 (Current_Project, In_Tree, Current_With.Location);
815 -- If it is a limited with, check if we have a circularity.
816 -- If we have one, get the project id of the limited
817 -- imported project file, and do not parse it.
819 if Limited_Withs and then Project_Stack.Last > 1 then
821 Canonical_Path_Name : Path_Name_Type;
824 Name_Len := Resolved_Path'Length;
825 Name_Buffer (1 .. Name_Len) := Resolved_Path;
826 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
827 Canonical_Path_Name := Name_Find;
829 for Index in 1 .. Project_Stack.Last loop
830 if Project_Stack.Table (Index).Canonical_Path_Name =
833 -- We have found the limited imported project,
834 -- get its project id, and do not parse it.
836 Withed_Project := Project_Stack.Table (Index).Id;
843 -- Parse the imported project, if its project id is unknown
845 if No (Withed_Project) then
848 Project => Withed_Project,
849 Extends_All => Extends_All,
850 Path_Name => Imported_Path_Name,
852 From_Extended => From_Extended,
853 In_Limited => Limited_Withs,
854 Packages_To_Check => Packages_To_Check,
856 Current_Dir => Current_Dir,
857 Is_Config_File => Is_Config_File,
861 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
864 if No (Withed_Project) then
866 -- If parsing unsuccessful, remove the context clause
868 Current_Project := Previous_Project;
870 if No (Current_Project) then
871 Imported_Projects := Empty_Node;
874 Set_Next_With_Clause_Of
875 (Current_Project, In_Tree, Empty_Node);
878 -- If parsing was successful, record project name and
879 -- path name in with clause
882 (Node => Current_Project,
884 To => Withed_Project,
885 Limited_With => Current_With.Limited_With);
889 Name_Of (Withed_Project, In_Tree));
891 Name_Len := Resolved_Path'Length;
892 Name_Buffer (1 .. Name_Len) := Resolved_Path;
893 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
896 Set_Is_Extending_All (Current_Project, In_Tree);
903 end Post_Parse_Context_Clause;
905 --------------------------
906 -- Parse_Single_Project --
907 --------------------------
909 procedure Parse_Single_Project
910 (In_Tree : Project_Node_Tree_Ref;
911 Project : out Project_Node_Id;
912 Extends_All : out Boolean;
915 From_Extended : Extension_Origin;
916 In_Limited : Boolean;
917 Packages_To_Check : String_List_Access;
919 Current_Dir : String;
920 Is_Config_File : Boolean;
921 Flags : Processing_Flags)
923 Normed_Path_Name : Path_Name_Type;
924 Canonical_Path_Name : Path_Name_Type;
925 Project_Directory : Path_Name_Type;
926 Project_Scan_State : Saved_Project_Scan_State;
927 Source_Index : Source_File_Index;
929 Extending : Boolean := False;
931 Extended_Project : Project_Node_Id := Empty_Node;
933 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
934 Tree_Private_Part.Projects_Htable.Get_First
935 (In_Tree.Projects_HT);
937 Name_From_Path : constant Name_Id :=
938 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
939 Name_Of_Project : Name_Id := No_Name;
941 Duplicated : Boolean := False;
943 First_With : With_Id;
944 Imported_Projects : Project_Node_Id := Empty_Node;
946 use Tree_Private_Part;
948 Project_Comment_State : Tree.Comment_State;
950 Proj_Qualifier : Project_Qualifier := Unspecified;
951 Qualifier_Location : Source_Ptr;
954 Extends_All := False;
957 Normed_Path : constant String := Normalize_Pathname
959 Directory => Current_Dir,
960 Resolve_Links => False,
961 Case_Sensitive => True);
962 Canonical_Path : constant String := Normalize_Pathname
964 Directory => Current_Dir,
965 Resolve_Links => Opt.Follow_Links_For_Files,
966 Case_Sensitive => False);
968 Name_Len := Normed_Path'Length;
969 Name_Buffer (1 .. Name_Len) := Normed_Path;
970 Normed_Path_Name := Name_Find;
971 Name_Len := Canonical_Path'Length;
972 Name_Buffer (1 .. Name_Len) := Canonical_Path;
973 Canonical_Path_Name := Name_Find;
976 -- Check for a circular dependency
978 for Index in reverse 1 .. Project_Stack.Last loop
979 exit when Project_Stack.Table (Index).Limited_With;
981 if Canonical_Path_Name =
982 Project_Stack.Table (Index).Canonical_Path_Name
984 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
985 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
986 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
988 for Current in reverse 1 .. Project_Stack.Last loop
990 Name_Id (Project_Stack.Table (Current).Path_Name);
992 if Project_Stack.Table (Current).Canonical_Path_Name /=
996 (Flags, "\ %% which itself is imported by", Token_Ptr);
999 Error_Msg (Flags, "\ %%", Token_Ptr);
1004 Project := Empty_Node;
1009 -- Put the new path name on the stack
1011 Project_Stack.Append
1012 ((Path_Name => Normed_Path_Name,
1013 Canonical_Path_Name => Canonical_Path_Name,
1015 Limited_With => In_Limited));
1017 -- Check if the project file has already been parsed
1020 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1022 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1025 if A_Project_Name_And_Node.Extended then
1026 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1029 "cannot extend the same project file several times",
1035 "cannot extend an already imported project file",
1039 elsif A_Project_Name_And_Node.Extended then
1041 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1043 -- If the imported project is an extended project A, and we are
1044 -- in an extended project, replace A with the ultimate project
1047 if From_Extended /= None then
1049 Decl : Project_Node_Id :=
1050 Project_Declaration_Of
1051 (A_Project_Name_And_Node.Node, In_Tree);
1053 Prj : Project_Node_Id :=
1054 A_Project_Name_And_Node.Node;
1057 -- Loop through extending projects to find the ultimate
1058 -- extending project, that is the one that is not
1059 -- extended. For an abstract project, as it can be
1060 -- extended several times, there is no extending project
1061 -- registered, so the loop does not execute and the
1062 -- resulting project is the abstract project.
1065 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1067 Prj := Extending_Project_Of (Decl, In_Tree);
1068 Decl := Project_Declaration_Of (Prj, In_Tree);
1071 A_Project_Name_And_Node.Node := Prj;
1076 "cannot import an already extended project file",
1081 Project := A_Project_Name_And_Node.Node;
1082 Project_Stack.Decrement_Last;
1086 A_Project_Name_And_Node :=
1087 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1090 -- We never encountered this project file. Save the scan state, load the
1091 -- project file and start to scan it.
1093 Save_Project_Scan_State (Project_Scan_State);
1094 Source_Index := Load_Project_File (Path_Name);
1095 Tree.Save (Project_Comment_State);
1097 -- If we cannot find it, we stop
1099 if Source_Index = No_Source_File then
1100 Project := Empty_Node;
1101 Project_Stack.Decrement_Last;
1105 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1109 if not Is_Config_File and then Name_From_Path = No_Name then
1111 -- The project file name is not correct (no or bad extension, or not
1112 -- following Ada identifier's syntax).
1114 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1116 "?{ is not a valid path name for a project file",
1120 if Current_Verbosity >= Medium then
1121 Write_Str ("Parsing """);
1122 Write_Str (Path_Name);
1127 Project_Directory :=
1128 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1130 -- Is there any imported project?
1132 Pre_Parse_Context_Clause
1133 (In_Tree => In_Tree,
1134 Is_Config_File => Is_Config_File,
1135 Context_Clause => First_With,
1138 Project := Default_Project_Node
1139 (Of_Kind => N_Project, In_Tree => In_Tree);
1140 Project_Stack.Table (Project_Stack.Last).Id := Project;
1141 Set_Directory_Of (Project, In_Tree, Project_Directory);
1142 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1144 -- Check if there is a qualifier before the reserved word "project"
1146 Qualifier_Location := Token_Ptr;
1148 if Token = Tok_Abstract then
1149 Proj_Qualifier := Dry;
1152 elsif Token = Tok_Identifier then
1154 when Snames.Name_Standard =>
1155 Proj_Qualifier := Standard;
1158 when Snames.Name_Aggregate =>
1159 Proj_Qualifier := Aggregate;
1162 if Token = Tok_Identifier and then
1163 Token_Name = Snames.Name_Library
1165 Proj_Qualifier := Aggregate_Library;
1169 when Snames.Name_Library =>
1170 Proj_Qualifier := Library;
1173 when Snames.Name_Configuration =>
1174 if not Is_Config_File then
1177 "configuration projects cannot belong to a user" &
1182 Proj_Qualifier := Configuration;
1190 if Is_Config_File and then Proj_Qualifier = Unspecified then
1192 -- Set the qualifier to Configuration, even if the token doesn't
1193 -- exist in the source file itself, so that we can differentiate
1194 -- project files and configuration files later on.
1196 Proj_Qualifier := Configuration;
1199 if Proj_Qualifier /= Unspecified then
1201 and then Proj_Qualifier /= Configuration
1204 "a configuration project cannot be qualified except " &
1205 "as configuration project",
1206 Qualifier_Location);
1209 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1212 Set_Location_Of (Project, In_Tree, Token_Ptr);
1214 Expect (Tok_Project, "PROJECT");
1216 -- Mark location of PROJECT token if present
1218 if Token = Tok_Project then
1219 Scan (In_Tree); -- past PROJECT
1220 Set_Location_Of (Project, In_Tree, Token_Ptr);
1227 Expect (Tok_Identifier, "identifier");
1229 -- If the token is not an identifier, clear the buffer before
1230 -- exiting to indicate that the name of the project is ill-formed.
1232 if Token /= Tok_Identifier then
1237 -- Add the identifier name to the buffer
1239 Get_Name_String (Token_Name);
1240 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1242 -- Scan past the identifier
1246 -- If we have a dot, add a dot to the Buffer and look for the next
1249 exit when Token /= Tok_Dot;
1250 Add_To_Buffer (".", Buffer, Buffer_Last);
1252 -- Scan past the dot
1257 -- See if this is an extending project
1259 if Token = Tok_Extends then
1261 if Is_Config_File then
1264 "extending configuration project not allowed", Token_Ptr);
1267 -- Make sure that gnatmake will use mapping files
1269 Create_Mapping_File := True;
1271 -- We are extending another project
1275 Scan (In_Tree); -- past EXTENDS
1277 if Token = Tok_All then
1278 Extends_All := True;
1279 Set_Is_Extending_All (Project, In_Tree);
1280 Scan (In_Tree); -- scan past ALL
1284 -- If the name is well formed, Buffer_Last is > 0
1286 if Buffer_Last > 0 then
1288 -- The Buffer contains the name of the project
1290 Name_Len := Buffer_Last;
1291 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1292 Name_Of_Project := Name_Find;
1293 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1295 -- To get expected name of the project file, replace dots by dashes
1297 Name_Len := Buffer_Last;
1298 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1300 for Index in 1 .. Name_Len loop
1301 if Name_Buffer (Index) = '.' then
1302 Name_Buffer (Index) := '-';
1306 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1309 Expected_Name : constant Name_Id := Name_Find;
1310 Extension : String_Access;
1313 -- Output a warning if the actual name is not the expected name
1315 if not Is_Config_File
1316 and then (Name_From_Path /= No_Name)
1317 and then Expected_Name /= Name_From_Path
1319 Error_Msg_Name_1 := Expected_Name;
1321 if Is_Config_File then
1322 Extension := new String'(Config_Project_File_Extension);
1325 Extension := new String'(Project_File_Extension);
1330 "?file name does not match project name, should be `%%"
1331 & Extension.all & "`",
1337 From_Ext : Extension_Origin := None;
1340 -- Extending_All is always propagated
1342 if From_Extended = Extending_All or else Extends_All then
1343 From_Ext := Extending_All;
1345 -- Otherwise, From_Extended is set to Extending_Single if the
1346 -- current project is an extending project.
1349 From_Ext := Extending_Simple;
1352 Post_Parse_Context_Clause
1353 (In_Tree => In_Tree,
1354 Context_Clause => First_With,
1355 Limited_Withs => False,
1356 Imported_Projects => Imported_Projects,
1357 Project_Directory => Project_Directory,
1358 From_Extended => From_Ext,
1359 In_Limited => In_Limited,
1360 Packages_To_Check => Packages_To_Check,
1362 Current_Dir => Current_Dir,
1363 Is_Config_File => Is_Config_File,
1365 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1368 if not Is_Config_File then
1370 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1371 Tree_Private_Part.Projects_Htable.Get_First
1372 (In_Tree.Projects_HT);
1373 Project_Name : Name_Id := Name_And_Node.Name;
1376 -- Check if we already have a project with this name
1378 while Project_Name /= No_Name
1379 and then Project_Name /= Name_Of_Project
1382 Tree_Private_Part.Projects_Htable.Get_Next
1383 (In_Tree.Projects_HT);
1384 Project_Name := Name_And_Node.Name;
1387 -- Report an error if we already have a project with this name
1389 if Project_Name /= No_Name then
1391 Error_Msg_Name_1 := Project_Name;
1393 (Flags, "duplicate project name %%",
1394 Location_Of (Project, In_Tree));
1396 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1398 (Flags, "\already in %%", Location_Of (Project, In_Tree));
1406 Expect (Tok_String_Literal, "literal string");
1408 if Token = Tok_String_Literal then
1409 Set_Extended_Project_Path_Of
1412 Path_Name_Type (Token_Name));
1415 Original_Path_Name : constant String :=
1416 Get_Name_String (Token_Name);
1418 Extended_Project_Path_Name : constant String :=
1419 Project_Path_Name_Of
1420 (Original_Path_Name,
1422 (Project_Directory));
1425 if Extended_Project_Path_Name = "" then
1427 -- We could not find the project file to extend
1429 Error_Msg_Name_1 := Token_Name;
1431 Error_Msg (Flags, "unknown project file: %%", Token_Ptr);
1433 -- If we are not in the main project file, display the
1436 if Project_Stack.Last > 1 then
1439 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1440 Error_Msg (Flags, "\extended by %%", Token_Ptr);
1442 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1445 (Project_Stack.Table (Index).Path_Name);
1446 Error_Msg (Flags, "\imported by %%", Token_Ptr);
1452 From_Ext : Extension_Origin := None;
1455 if From_Extended = Extending_All or else Extends_All then
1456 From_Ext := Extending_All;
1459 Parse_Single_Project
1460 (In_Tree => In_Tree,
1461 Project => Extended_Project,
1462 Extends_All => Extends_All,
1463 Path_Name => Extended_Project_Path_Name,
1465 From_Extended => From_Ext,
1466 In_Limited => In_Limited,
1467 Packages_To_Check => Packages_To_Check,
1469 Current_Dir => Current_Dir,
1470 Is_Config_File => Is_Config_File,
1474 if Present (Extended_Project) then
1476 -- A project that extends an extending-all project is
1477 -- also an extending-all project.
1479 if Is_Extending_All (Extended_Project, In_Tree) then
1480 Set_Is_Extending_All (Project, In_Tree);
1483 -- An abstract project can only extend an abstract
1484 -- project, otherwise we may have an abstract project
1485 -- with sources, if it inherits sources from the project
1488 if Proj_Qualifier = Dry and then
1489 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1492 (Flags, "an abstract project can only extend " &
1493 "another abstract project",
1494 Qualifier_Location);
1500 Scan (In_Tree); -- past the extended project path
1504 -- Check that a non extending-all project does not import an
1505 -- extending-all project.
1507 if not Is_Extending_All (Project, In_Tree) then
1509 With_Clause : Project_Node_Id :=
1510 First_With_Clause_Of (Project, In_Tree);
1511 Imported : Project_Node_Id := Empty_Node;
1515 while Present (With_Clause) loop
1516 Imported := Project_Node_Of (With_Clause, In_Tree);
1518 if Is_Extending_All (With_Clause, In_Tree) then
1519 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
1520 Error_Msg (Flags, "cannot import extending-all project %%",
1522 exit With_Clause_Loop;
1525 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1526 end loop With_Clause_Loop;
1530 -- Check that a project with a name including a dot either imports
1531 -- or extends the project whose name precedes the last dot.
1533 if Name_Of_Project /= No_Name then
1534 Get_Name_String (Name_Of_Project);
1540 -- Look for the last dot
1542 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1543 Name_Len := Name_Len - 1;
1546 -- If a dot was find, check if the parent project is imported
1549 if Name_Len > 0 then
1550 Name_Len := Name_Len - 1;
1553 Parent_Name : constant Name_Id := Name_Find;
1554 Parent_Found : Boolean := False;
1555 Parent_Node : Project_Node_Id := Empty_Node;
1556 With_Clause : Project_Node_Id :=
1557 First_With_Clause_Of (Project, In_Tree);
1560 -- If there is an extended project, check its name
1562 if Present (Extended_Project) then
1563 Parent_Node := Extended_Project;
1565 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1568 -- If the parent project is not the extended project,
1569 -- check each imported project until we find the parent project.
1571 while not Parent_Found and then Present (With_Clause) loop
1572 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1573 Parent_Found := Name_Of (Parent_Node, In_Tree) = Parent_Name;
1574 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1577 if Parent_Found then
1578 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1581 -- If the parent project was not found, report an error
1583 Error_Msg_Name_1 := Name_Of_Project;
1584 Error_Msg_Name_2 := Parent_Name;
1586 "project %% does not import or extend project %%",
1587 Location_Of (Project, In_Tree));
1592 Expect (Tok_Is, "IS");
1593 Set_End_Of_Line (Project);
1594 Set_Previous_Line_Node (Project);
1595 Set_Next_End_Node (Project);
1598 Project_Declaration : Project_Node_Id := Empty_Node;
1601 -- No need to Scan past "is", Prj.Dect.Parse will do it
1604 (In_Tree => In_Tree,
1605 Declarations => Project_Declaration,
1606 Current_Project => Project,
1607 Extends => Extended_Project,
1608 Packages_To_Check => Packages_To_Check,
1609 Is_Config_File => Is_Config_File,
1611 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1613 if Present (Extended_Project)
1614 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1616 Set_Extending_Project_Of
1617 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1622 Expect (Tok_End, "END");
1623 Remove_Next_End_Node;
1625 -- Skip "end" if present
1627 if Token = Tok_End then
1635 -- Store the name following "end" in the Buffer. The name may be made of
1636 -- several simple names.
1639 Expect (Tok_Identifier, "identifier");
1641 -- If we don't have an identifier, clear the buffer before exiting to
1642 -- avoid checking the name.
1644 if Token /= Tok_Identifier then
1649 -- Add the identifier to the Buffer
1650 Get_Name_String (Token_Name);
1651 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1653 -- Scan past the identifier
1656 exit when Token /= Tok_Dot;
1657 Add_To_Buffer (".", Buffer, Buffer_Last);
1661 -- If we have a valid name, check if it is the name of the project
1663 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1664 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1665 Get_Name_String (Name_Of (Project, In_Tree))
1667 -- Invalid name: report an error
1669 Error_Msg (Flags, "expected """ &
1670 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1675 Expect (Tok_Semicolon, "`;`");
1677 -- Check that there is no more text following the end of the project
1680 if Token = Tok_Semicolon then
1681 Set_Previous_End_Node (Project);
1684 if Token /= Tok_EOF then
1686 (Flags, "unexpected text following end of project", Token_Ptr);
1690 if not Duplicated and then Name_Of_Project /= No_Name then
1692 -- Add the name of the project to the hash table, so that we can
1693 -- check that no other subsequent project will have the same name.
1695 Tree_Private_Part.Projects_Htable.Set
1696 (T => In_Tree.Projects_HT,
1697 K => Name_Of_Project,
1698 E => (Name => Name_Of_Project,
1700 Canonical_Path => Canonical_Path_Name,
1701 Extended => Extended,
1702 Proj_Qualifier => Proj_Qualifier));
1706 From_Ext : Extension_Origin := None;
1709 -- Extending_All is always propagated
1711 if From_Extended = Extending_All or else Extends_All then
1712 From_Ext := Extending_All;
1714 -- Otherwise, From_Extended is set to Extending_Single if the
1715 -- current project is an extending project.
1718 From_Ext := Extending_Simple;
1721 Post_Parse_Context_Clause
1722 (In_Tree => In_Tree,
1723 Context_Clause => First_With,
1724 Limited_Withs => True,
1725 Imported_Projects => Imported_Projects,
1726 Project_Directory => Project_Directory,
1727 From_Extended => From_Ext,
1728 In_Limited => In_Limited,
1729 Packages_To_Check => Packages_To_Check,
1731 Current_Dir => Current_Dir,
1732 Is_Config_File => Is_Config_File,
1734 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1737 -- Restore the scan state, in case we are not the main project
1739 Restore_Project_Scan_State (Project_Scan_State);
1741 -- And remove the project from the project stack
1743 Project_Stack.Decrement_Last;
1745 -- Indicate if there are unkept comments
1747 Tree.Set_Project_File_Includes_Unkept_Comments
1750 To => Tree.There_Are_Unkept_Comments);
1752 -- And restore the comment state that was saved
1754 Tree.Restore_And_Free (Project_Comment_State);
1755 end Parse_Single_Project;
1757 -----------------------
1758 -- Project_Name_From --
1759 -----------------------
1761 function Project_Name_From
1762 (Path_Name : String;
1763 Is_Config_File : Boolean) return Name_Id
1765 Canonical : String (1 .. Path_Name'Length) := Path_Name;
1766 First : Natural := Canonical'Last;
1767 Last : Natural := First;
1771 if Current_Verbosity = High then
1772 Write_Str ("Project_Name_From (""");
1773 Write_Str (Canonical);
1777 -- If the path name is empty, return No_Name to indicate failure
1783 Canonical_Case_File_Name (Canonical);
1785 -- Look for the last dot in the path name
1789 Canonical (First) /= '.'
1794 -- If we have a dot, check that it is followed by the correct extension
1796 if First > 0 and then Canonical (First) = '.' then
1797 if (not Is_Config_File
1798 and then Canonical (First .. Last) = Project_File_Extension
1799 and then First /= 1)
1803 Canonical (First .. Last) = Config_Project_File_Extension
1804 and then First /= 1)
1806 -- Look for the last directory separator, if any
1811 and then Canonical (First) /= '/'
1812 and then Canonical (First) /= Dir_Sep
1818 -- Not the correct extension, return No_Name to indicate failure
1823 -- If no dot in the path name, return No_Name to indicate failure
1831 -- If the extension is the file name, return No_Name to indicate failure
1833 if First > Last then
1837 -- Put the name in lower case into Name_Buffer
1839 Name_Len := Last - First + 1;
1840 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
1844 -- Check if it is a well formed project name. Return No_Name if it is
1848 if not Is_Letter (Name_Buffer (Index)) then
1855 exit when Index >= Name_Len;
1857 if Name_Buffer (Index) = '_' then
1858 if Name_Buffer (Index + 1) = '_' then
1863 exit when Name_Buffer (Index) = '-';
1865 if Name_Buffer (Index) /= '_'
1866 and then not Is_Alphanumeric (Name_Buffer (Index))
1874 if Index >= Name_Len then
1875 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
1877 -- All checks have succeeded. Return name in Name_Buffer
1885 elsif Name_Buffer (Index) = '-' then
1889 end Project_Name_From;
1891 --------------------------
1892 -- Project_Path_Name_Of --
1893 --------------------------
1895 function Project_Path_Name_Of
1896 (Project_File_Name : String;
1897 Directory : String) return String
1900 function Try_Path_Name (Path : String) return String_Access;
1901 pragma Inline (Try_Path_Name);
1902 -- Try the specified Path
1908 function Try_Path_Name (Path : String) return String_Access is
1909 Prj_Path : constant String := Project_Path;
1912 Result : String_Access := null;
1915 if Current_Verbosity = High then
1916 Write_Str (" Trying ");
1920 if Is_Absolute_Path (Path) then
1921 if Is_Regular_File (Path) then
1922 Result := new String'(Path);
1926 -- Because we don't want to resolve symbolic links, we cannot use
1927 -- Locate_Regular_File. So, we try each possible path
1930 First := Prj_Path'First;
1931 while First <= Prj_Path'Last loop
1932 while First <= Prj_Path'Last
1933 and then Prj_Path (First) = Path_Separator
1938 exit when First > Prj_Path'Last;
1941 while Last < Prj_Path'Last
1942 and then Prj_Path (Last + 1) /= Path_Separator
1949 if not Is_Absolute_Path (Prj_Path (First .. Last)) then
1950 Add_Str_To_Name_Buffer (Get_Current_Dir);
1951 Add_Char_To_Name_Buffer (Directory_Separator);
1954 Add_Str_To_Name_Buffer (Prj_Path (First .. Last));
1955 Add_Char_To_Name_Buffer (Directory_Separator);
1956 Add_Str_To_Name_Buffer (Path);
1958 if Is_Regular_File (Name_Buffer (1 .. Name_Len)) then
1959 Result := new String'(Name_Buffer (1 .. Name_Len));
1970 -- Local Declarations
1972 Result : String_Access;
1973 Result_Id : Path_Name_Type;
1974 Has_Dot : Boolean := False;
1977 -- Start of processing for Project_Path_Name_Of
1980 if Current_Verbosity = High then
1981 Write_Str ("Project_Path_Name_Of (""");
1982 Write_Str (Project_File_Name);
1983 Write_Str (""", """);
1984 Write_Str (Directory);
1985 Write_Line (""");");
1988 -- Check the project cache
1990 Name_Len := Project_File_Name'Length;
1991 Name_Buffer (1 .. Name_Len) := Project_File_Name;
1993 Result_Id := Projects_Paths.Get (Key);
1995 if Result_Id /= No_Path then
1996 return Get_Name_String (Result_Id);
1999 -- Check if Project_File_Name contains an extension (a dot before a
2000 -- directory separator). If it is the case we do not try project file
2001 -- with an added extension as it is not possible to have multiple dots
2002 -- on a project file name.
2004 Check_Dot : for K in reverse Project_File_Name'Range loop
2005 if Project_File_Name (K) = '.' then
2010 exit Check_Dot when Project_File_Name (K) = Directory_Separator
2011 or else Project_File_Name (K) = '/';
2014 if not Is_Absolute_Path (Project_File_Name) then
2016 -- First we try <directory>/<file_name>.<extension>
2019 Result := Try_Path_Name
2020 (Directory & Directory_Separator &
2021 Project_File_Name & Project_File_Extension);
2024 -- Then we try <directory>/<file_name>
2026 if Result = null then
2027 Result := Try_Path_Name
2028 (Directory & Directory_Separator & Project_File_Name);
2032 -- Then we try <file_name>.<extension>
2034 if Result = null and then not Has_Dot then
2035 Result := Try_Path_Name (Project_File_Name & Project_File_Extension);
2038 -- Then we try <file_name>
2040 if Result = null then
2041 Result := Try_Path_Name (Project_File_Name);
2044 -- If we cannot find the project file, we return an empty string
2046 if Result = null then
2051 Final_Result : constant String :=
2052 GNAT.OS_Lib.Normalize_Pathname
2054 Directory => Directory,
2055 Resolve_Links => False,
2056 Case_Sensitive => True);
2059 Name_Len := Final_Result'Length;
2060 Name_Buffer (1 .. Name_Len) := Final_Result;
2061 Result_Id := Name_Find;
2063 Projects_Paths.Set (Key, Result_Id);
2064 return Final_Result;
2067 end Project_Path_Name_Of;