1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2011, 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.Env; use Prj.Env;
33 with Prj.Err; use Prj.Err;
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.HTable; use GNAT.HTable;
44 package body Prj.Part is
46 Buffer : String_Access;
47 Buffer_Last : Natural := 0;
49 Dir_Sep : Character renames GNAT.OS_Lib.Directory_Separator;
51 ------------------------------------
52 -- Local Packages and Subprograms --
53 ------------------------------------
55 type With_Id is new Nat;
56 No_With : constant With_Id := 0;
58 type With_Record is record
59 Path : Path_Name_Type;
60 Location : Source_Ptr;
61 Limited_With : Boolean;
62 Node : Project_Node_Id;
65 -- Information about an imported project, to be put in table Withs below
67 package Withs is new Table.Table
68 (Table_Component_Type => With_Record,
69 Table_Index_Type => With_Id,
72 Table_Increment => 100,
73 Table_Name => "Prj.Part.Withs");
74 -- Table used to store temporarily paths and locations of imported
75 -- projects. These imported projects will be effectively parsed later: just
76 -- before parsing the current project for the non limited withed projects,
77 -- after getting its name; after complete parsing of the current project
78 -- for the limited withed projects.
80 type Names_And_Id is record
81 Path_Name : Path_Name_Type;
82 Canonical_Path_Name : Path_Name_Type;
84 Limited_With : Boolean;
87 package Project_Stack is new Table.Table
88 (Table_Component_Type => Names_And_Id,
89 Table_Index_Type => Nat,
92 Table_Increment => 100,
93 Table_Name => "Prj.Part.Project_Stack");
94 -- This table is used to detect circular dependencies
95 -- for imported and extended projects and to get the project ids of
96 -- limited imported projects when there is a circularity with at least
97 -- one limited imported project file.
99 package Virtual_Hash is new GNAT.HTable.Simple_HTable
100 (Header_Num => Header_Num,
101 Element => Project_Node_Id,
102 No_Element => Project_Node_High_Bound,
103 Key => Project_Node_Id,
104 Hash => Prj.Tree.Hash,
106 -- Hash table to store the node ids of projects for which a virtual
107 -- extending project need to be created. The corresponding value is the
108 -- head of a list of WITH clauses corresponding to the context of the
109 -- enclosing EXTEND ALL projects. Note: Default_Element is Project_Node_
110 -- High_Bound because we want Empty_Node to be a possible value.
112 package Processed_Hash is new GNAT.HTable.Simple_HTable
113 (Header_Num => Header_Num,
116 Key => Project_Node_Id,
117 Hash => Prj.Tree.Hash,
119 -- Hash table to store the project process when looking for project that
120 -- need to have a virtual extending project, to avoid processing the same
123 function Has_Circular_Dependencies
124 (Flags : Processing_Flags;
125 Normed_Path_Name : Path_Name_Type;
126 Canonical_Path_Name : Path_Name_Type) return Boolean;
127 -- Check for a circular dependency in the loaded project.
128 -- Generates an error message in such a case.
130 procedure Read_Project_Qualifier
131 (Flags : Processing_Flags;
132 In_Tree : Project_Node_Tree_Ref;
133 Is_Config_File : Boolean;
134 Qualifier_Location : out Source_Ptr;
135 Project : Project_Node_Id);
136 -- Check if there is a qualifier before the reserved word "project"
138 -- Hash table to cache project path to avoid looking for them on the path
140 procedure Check_Extending_All_Imports
141 (Flags : Processing_Flags;
142 In_Tree : Project_Node_Tree_Ref;
143 Project : Project_Node_Id);
144 -- Check that a non extending-all project does not import an
145 -- extending-all project.
147 procedure Check_Aggregate_Imports
148 (Flags : Processing_Flags;
149 In_Tree : Project_Node_Tree_Ref;
150 Project : Project_Node_Id);
151 -- Check that an aggregate project only imports abstract projects
153 procedure Create_Virtual_Extending_Project
154 (For_Project : Project_Node_Id;
155 Main_Project : Project_Node_Id;
156 Extension_Withs : Project_Node_Id;
157 In_Tree : Project_Node_Tree_Ref);
158 -- Create a virtual extending project of For_Project. Main_Project is
159 -- the extending all project. Extension_Withs is the head of a WITH clause
160 -- list to be added to the created virtual project.
162 -- The String_Value_Of is not set for the automatically added with
163 -- clause and keeps the default value of No_Name. This enables Prj.PP
164 -- to skip these automatically added with clauses to be processed.
166 procedure Look_For_Virtual_Projects_For
167 (Proj : Project_Node_Id;
168 In_Tree : Project_Node_Tree_Ref;
169 Potentially_Virtual : Boolean);
170 -- Look for projects that need to have a virtual extending project.
171 -- This procedure is recursive. If called with Potentially_Virtual set to
172 -- True, then Proj may need an virtual extending project; otherwise it
173 -- does not (because it is already extended), but other projects that it
174 -- imports may need to be virtually extended.
176 type Extension_Origin is (None, Extending_Simple, Extending_All);
177 -- Type of parameter From_Extended for procedures Parse_Single_Project and
178 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
179 -- tree rooted at an extending all project.
181 procedure Parse_Single_Project
182 (In_Tree : Project_Node_Tree_Ref;
183 Project : out Project_Node_Id;
184 Extends_All : out Boolean;
185 Path_Name_Id : Path_Name_Type;
187 From_Extended : Extension_Origin;
188 In_Limited : Boolean;
189 Packages_To_Check : String_List_Access;
191 Current_Dir : String;
192 Is_Config_File : Boolean;
193 Env : in out Environment);
194 -- Parse a project file. This is a recursive procedure: it calls itself for
195 -- imported and extended projects. When From_Extended is not None, if the
196 -- project has already been parsed and is an extended project A, return the
197 -- ultimate (not extended) project that extends A. When In_Limited is True,
198 -- the importing path includes at least one "limited with". When parsing
199 -- configuration projects, do not allow a depth > 1.
201 -- Is_Config_File should be set to True if the project represents a config
202 -- file (.cgpr) since some specific checks apply.
204 procedure Pre_Parse_Context_Clause
205 (In_Tree : Project_Node_Tree_Ref;
206 Context_Clause : out With_Id;
207 Is_Config_File : Boolean;
208 Flags : Processing_Flags);
209 -- Parse the context clause of a project. Store the paths and locations of
210 -- the imported projects in table Withs. Does nothing if there is no
211 -- context clause (if the current token is not "with" or "limited" followed
213 -- Is_Config_File should be set to True if the project represents a config
214 -- file (.cgpr) since some specific checks apply.
216 procedure Post_Parse_Context_Clause
217 (Context_Clause : With_Id;
218 In_Tree : Project_Node_Tree_Ref;
219 Limited_Withs : Boolean;
220 Imported_Projects : in out Project_Node_Id;
221 Project_Directory : Path_Name_Type;
222 From_Extended : Extension_Origin;
223 Packages_To_Check : String_List_Access;
225 Current_Dir : String;
226 Is_Config_File : Boolean;
227 Env : in out Environment);
228 -- Parse the imported projects that have been stored in table Withs, if
229 -- any. From_Extended is used for the call to Parse_Single_Project below.
230 -- When In_Limited is True, the importing path includes at least one
231 -- "limited with". When Limited_Withs is False, only non limited withed
232 -- projects are parsed. When Limited_Withs is True, only limited withed
233 -- projects are parsed.
234 -- Is_Config_File should be set to True if the project represents a config
235 -- file (.cgpr) since some specific checks apply.
237 function Project_Name_From
239 Is_Config_File : Boolean) return Name_Id;
240 -- Returns the name of the project that corresponds to its path name.
241 -- Returns No_Name if the path name is invalid, because the corresponding
242 -- project name does not have the syntax of an ada identifier.
244 function Copy_With_Clause
245 (With_Clause : Project_Node_Id;
246 In_Tree : Project_Node_Tree_Ref;
247 Next_Clause : Project_Node_Id) return Project_Node_Id;
248 -- Return a copy of With_Clause in In_Tree, whose Next_With_Clause is the
251 ----------------------
252 -- Copy_With_Clause --
253 ----------------------
255 function Copy_With_Clause
256 (With_Clause : Project_Node_Id;
257 In_Tree : Project_Node_Tree_Ref;
258 Next_Clause : Project_Node_Id) return Project_Node_Id
260 New_With_Clause : constant Project_Node_Id :=
261 Default_Project_Node (In_Tree, N_With_Clause);
263 Set_Name_Of (New_With_Clause, In_Tree,
264 Name_Of (With_Clause, In_Tree));
265 Set_Path_Name_Of (New_With_Clause, In_Tree,
266 Path_Name_Of (With_Clause, In_Tree));
267 Set_Project_Node_Of (New_With_Clause, In_Tree,
268 Project_Node_Of (With_Clause, In_Tree));
269 Set_Next_With_Clause_Of (New_With_Clause, In_Tree, Next_Clause);
271 return New_With_Clause;
272 end Copy_With_Clause;
274 --------------------------------------
275 -- Create_Virtual_Extending_Project --
276 --------------------------------------
278 procedure Create_Virtual_Extending_Project
279 (For_Project : Project_Node_Id;
280 Main_Project : Project_Node_Id;
281 Extension_Withs : Project_Node_Id;
282 In_Tree : Project_Node_Tree_Ref)
285 Virtual_Name : constant String :=
287 Get_Name_String (Name_Of (For_Project, In_Tree));
288 -- The name of the virtual extending project
290 Virtual_Name_Id : Name_Id;
291 -- Virtual extending project name id
293 Virtual_Path_Id : Path_Name_Type;
294 -- Fake path name of the virtual extending project. The directory is
295 -- the same directory as the extending all project.
297 -- The source of the virtual extending project is something like:
299 -- project V$<project name> extends <project path> is
301 -- for Source_Dirs use ();
303 -- end V$<project name>;
305 -- The project directory cannot be specified during parsing; it will be
306 -- put directly in the virtual extending project data during processing.
308 -- Nodes that made up the virtual extending project
310 Virtual_Project : Project_Node_Id;
311 With_Clause : constant Project_Node_Id :=
313 (In_Tree, N_With_Clause);
314 Project_Declaration : Project_Node_Id;
315 Source_Dirs_Declaration : constant Project_Node_Id :=
317 (In_Tree, N_Declarative_Item);
318 Source_Dirs_Attribute : constant Project_Node_Id :=
320 (In_Tree, N_Attribute_Declaration, List);
321 Source_Dirs_Expression : constant Project_Node_Id :=
323 (In_Tree, N_Expression, List);
324 Source_Dirs_Term : constant Project_Node_Id :=
326 (In_Tree, N_Term, List);
327 Source_Dirs_List : constant Project_Node_Id :=
329 (In_Tree, N_Literal_String_List, List);
332 -- Get the virtual path name
334 Get_Name_String (Path_Name_Of (Main_Project, In_Tree));
337 and then Name_Buffer (Name_Len) /= Directory_Separator
338 and then Name_Buffer (Name_Len) /= '/'
340 Name_Len := Name_Len - 1;
343 Name_Buffer (Name_Len + 1 .. Name_Len + Virtual_Name'Length) :=
345 Name_Len := Name_Len + Virtual_Name'Length;
346 Virtual_Path_Id := Name_Find;
348 -- Get the virtual name id
350 Name_Len := Virtual_Name'Length;
351 Name_Buffer (1 .. Name_Len) := Virtual_Name;
352 Virtual_Name_Id := Name_Find;
354 Virtual_Project := Create_Project
356 Name => Virtual_Name_Id,
357 Full_Path => Virtual_Path_Id,
358 Is_Config_File => False);
360 Project_Declaration := Project_Declaration_Of (Virtual_Project, In_Tree);
362 -- Add a WITH clause to the main project to import the newly created
363 -- virtual extending project.
365 Set_Name_Of (With_Clause, In_Tree, Virtual_Name_Id);
366 Set_Path_Name_Of (With_Clause, In_Tree, Virtual_Path_Id);
367 Set_Project_Node_Of (With_Clause, In_Tree, Virtual_Project);
368 Set_Next_With_Clause_Of
369 (With_Clause, In_Tree, First_With_Clause_Of (Main_Project, In_Tree));
370 Set_First_With_Clause_Of (Main_Project, In_Tree, With_Clause);
372 -- Copy with clauses for projects imported by the extending-all project
375 Org_With_Clause : Project_Node_Id := Extension_Withs;
376 New_With_Clause : Project_Node_Id := Empty_Node;
379 while Present (Org_With_Clause) loop
381 Copy_With_Clause (Org_With_Clause, In_Tree, New_With_Clause);
383 Org_With_Clause := Next_With_Clause_Of (Org_With_Clause, In_Tree);
386 Set_First_With_Clause_Of (Virtual_Project, In_Tree, New_With_Clause);
389 -- Virtual project node
392 (Virtual_Project, In_Tree, Location_Of (Main_Project, In_Tree));
393 Set_Extended_Project_Path_Of
394 (Virtual_Project, In_Tree, Path_Name_Of (For_Project, In_Tree));
396 -- Project declaration
398 Set_First_Declarative_Item_Of
399 (Project_Declaration, In_Tree, Source_Dirs_Declaration);
400 Set_Extended_Project_Of (Project_Declaration, In_Tree, For_Project);
402 -- Source_Dirs declaration
404 Set_Current_Item_Node
405 (Source_Dirs_Declaration, In_Tree, Source_Dirs_Attribute);
407 -- Source_Dirs attribute
409 Set_Name_Of (Source_Dirs_Attribute, In_Tree, Snames.Name_Source_Dirs);
411 (Source_Dirs_Attribute, In_Tree, Source_Dirs_Expression);
413 -- Source_Dirs expression
415 Set_First_Term (Source_Dirs_Expression, In_Tree, Source_Dirs_Term);
419 Set_Current_Term (Source_Dirs_Term, In_Tree, Source_Dirs_List);
421 -- Source_Dirs empty list: nothing to do
422 end Create_Virtual_Extending_Project;
424 -----------------------------------
425 -- Look_For_Virtual_Projects_For --
426 -----------------------------------
428 Extension_Withs : Project_Node_Id;
429 -- Head of the current EXTENDS ALL imports list. When creating virtual
430 -- projects for an EXTENDS ALL, we import in each virtual project all
431 -- of the projects that appear in WITH clauses of the extending projects.
432 -- This ensures that virtual projects share a consistent environment (in
433 -- particular if a project imported by one of the extending projects
434 -- replaces some runtime units).
436 procedure Look_For_Virtual_Projects_For
437 (Proj : Project_Node_Id;
438 In_Tree : Project_Node_Tree_Ref;
439 Potentially_Virtual : Boolean)
441 Declaration : Project_Node_Id := Empty_Node;
442 -- Node for the project declaration of Proj
444 With_Clause : Project_Node_Id := Empty_Node;
445 -- Node for a with clause of Proj
447 Imported : Project_Node_Id := Empty_Node;
448 -- Node for a project imported by Proj
450 Extended : Project_Node_Id := Empty_Node;
451 -- Node for the eventual project extended by Proj
453 Extends_All : Boolean := False;
454 -- Set True if Proj is an EXTENDS ALL project
456 Saved_Extension_Withs : constant Project_Node_Id := Extension_Withs;
459 -- Nothing to do if Proj is undefined or has already been processed
461 if Present (Proj) and then not Processed_Hash.Get (Proj) then
463 -- Make sure the project will not be processed again
465 Processed_Hash.Set (Proj, True);
467 Declaration := Project_Declaration_Of (Proj, In_Tree);
469 if Present (Declaration) then
470 Extended := Extended_Project_Of (Declaration, In_Tree);
471 Extends_All := Is_Extending_All (Proj, In_Tree);
474 -- If this is a project that may need a virtual extending project
475 -- and it is not itself an extending project, put it in the list.
477 if Potentially_Virtual and then No (Extended) then
478 Virtual_Hash.Set (Proj, Extension_Withs);
481 -- Now check the projects it imports
483 With_Clause := First_With_Clause_Of (Proj, In_Tree);
484 while Present (With_Clause) loop
485 Imported := Project_Node_Of (With_Clause, In_Tree);
487 if Present (Imported) then
488 Look_For_Virtual_Projects_For
489 (Imported, In_Tree, Potentially_Virtual => True);
494 -- This is an EXTENDS ALL project: prepend each of its WITH
495 -- clauses to the currently active list of extension deps.
498 Copy_With_Clause (With_Clause, In_Tree, Extension_Withs);
501 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
504 -- Check also the eventual project extended by Proj. As this project
505 -- is already extended, call recursively with Potentially_Virtual
508 Look_For_Virtual_Projects_For
509 (Extended, In_Tree, Potentially_Virtual => False);
511 Extension_Withs := Saved_Extension_Withs;
513 end Look_For_Virtual_Projects_For;
520 (In_Tree : Project_Node_Tree_Ref;
521 Project : out Project_Node_Id;
522 Project_File_Name : String;
523 Errout_Handling : Errout_Mode := Always_Finalize;
524 Packages_To_Check : String_List_Access;
525 Store_Comments : Boolean := False;
526 Current_Directory : String := "";
527 Is_Config_File : Boolean;
528 Env : in out Prj.Tree.Environment;
529 Target_Name : String := "")
532 pragma Warnings (Off, Dummy);
534 Real_Project_File_Name : String_Access :=
535 Osint.To_Canonical_File_Spec
537 Path_Name_Id : Path_Name_Type;
540 In_Tree.Incomplete_With := False;
542 if not Is_Initialized (Env.Project_Path) then
543 Prj.Env.Initialize_Default_Project_Path
544 (Env.Project_Path, Target_Name);
547 if Real_Project_File_Name = null then
548 Real_Project_File_Name := new String'(Project_File_Name);
551 Project := Empty_Node;
553 Find_Project (Env.Project_Path,
554 Project_File_Name => Real_Project_File_Name.all,
555 Directory => Current_Directory,
556 Path => Path_Name_Id);
557 Free (Real_Project_File_Name);
559 if Errout_Handling /= Never_Finalize then
563 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
564 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
566 if Path_Name_Id = No_Path then
570 Get_Path (Env.Project_Path, Path => P);
577 Project := Empty_Node;
582 -- Parse the main project file
588 Extends_All => Dummy,
589 Path_Name_Id => Path_Name_Id,
591 From_Extended => None,
593 Packages_To_Check => Packages_To_Check,
595 Current_Dir => Current_Directory,
596 Is_Config_File => Is_Config_File,
600 when Types.Unrecoverable_Error =>
602 -- Unrecoverable_Error is raised when a line is too long.
603 -- A meaningful error message will be displayed later.
605 Project := Empty_Node;
608 -- If Project is an extending-all project, create the eventual
609 -- virtual extending projects and check that there are no illegally
610 -- imported projects.
613 and then Is_Extending_All (Project, In_Tree)
615 -- First look for projects that potentially need a virtual
616 -- extending project.
619 Processed_Hash.Reset;
621 -- Mark the extending all project as processed, to avoid checking
622 -- the imported projects in case of a "limited with" on this
623 -- extending all project.
625 Processed_Hash.Set (Project, True);
628 Declaration : constant Project_Node_Id :=
629 Project_Declaration_Of (Project, In_Tree);
631 Extension_Withs := First_With_Clause_Of (Project, In_Tree);
632 Look_For_Virtual_Projects_For
633 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
634 Potentially_Virtual => False);
637 -- Now, check the projects directly imported by the main project.
638 -- Remove from the potentially virtual any project extended by one
639 -- of these imported projects. For non extending imported projects,
640 -- check that they do not belong to the project tree of the project
641 -- being "extended-all" by the main project.
644 With_Clause : Project_Node_Id;
645 Imported : Project_Node_Id := Empty_Node;
646 Declaration : Project_Node_Id := Empty_Node;
649 With_Clause := First_With_Clause_Of (Project, In_Tree);
650 while Present (With_Clause) loop
651 Imported := Project_Node_Of (With_Clause, In_Tree);
653 if Present (Imported) then
654 Declaration := Project_Declaration_Of (Imported, In_Tree);
656 if Extended_Project_Of (Declaration, In_Tree) /=
661 Extended_Project_Of (Declaration, In_Tree);
662 exit when No (Imported);
663 Virtual_Hash.Remove (Imported);
665 Project_Declaration_Of (Imported, In_Tree);
670 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
674 -- Now create all the virtual extending projects
677 Proj : Project_Node_Id := Empty_Node;
678 Withs : Project_Node_Id;
680 Virtual_Hash.Get_First (Proj, Withs);
681 while Withs /= Project_Node_High_Bound loop
682 Create_Virtual_Extending_Project
683 (Proj, Project, Withs, In_Tree);
684 Virtual_Hash.Get_Next (Proj, Withs);
689 -- If there were any kind of error during the parsing, serious
690 -- or not, then the parsing fails.
692 if Err_Vars.Total_Errors_Detected > 0 then
693 Project := Empty_Node;
696 case Errout_Handling is
697 when Always_Finalize =>
700 -- Reinitialize to avoid duplicate warnings later on
703 when Finalize_If_Error =>
709 when Never_Finalize =>
718 Write_Line (Exception_Information (X));
719 Write_Str ("Exception ");
720 Write_Str (Exception_Name (X));
721 Write_Line (" raised, while processing project file");
722 Project := Empty_Node;
725 ------------------------------
726 -- Pre_Parse_Context_Clause --
727 ------------------------------
729 procedure Pre_Parse_Context_Clause
730 (In_Tree : Project_Node_Tree_Ref;
731 Context_Clause : out With_Id;
732 Is_Config_File : Boolean;
733 Flags : Processing_Flags)
735 Current_With_Clause : With_Id := No_With;
736 Limited_With : Boolean := False;
737 Current_With : With_Record;
738 Current_With_Node : Project_Node_Id := Empty_Node;
741 -- Assume no context clause
743 Context_Clause := No_With;
746 -- If Token is not WITH or LIMITED, there is no context clause, or we
747 -- have exhausted the with clauses.
749 while Token = Tok_With or else Token = Tok_Limited loop
751 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
752 Limited_With := Token = Tok_Limited;
754 if Is_Config_File then
757 "configuration project cannot import " &
758 "other configuration projects",
763 Scan (In_Tree); -- past LIMITED
764 Expect (Tok_With, "WITH");
765 exit With_Loop when Token /= Tok_With;
770 Scan (In_Tree); -- past WITH or ","
772 Expect (Tok_String_Literal, "literal string");
774 if Token /= Tok_String_Literal then
778 -- Store path and location in table Withs
781 (Path => Path_Name_Type (Token_Name),
782 Location => Token_Ptr,
783 Limited_With => Limited_With,
784 Node => Current_With_Node,
787 Withs.Increment_Last;
788 Withs.Table (Withs.Last) := Current_With;
790 if Current_With_Clause = No_With then
791 Context_Clause := Withs.Last;
794 Withs.Table (Current_With_Clause).Next := Withs.Last;
797 Current_With_Clause := Withs.Last;
801 if Token = Tok_Semicolon then
802 Set_End_Of_Line (Current_With_Node);
803 Set_Previous_Line_Node (Current_With_Node);
805 -- End of (possibly multiple) with clause;
807 Scan (In_Tree); -- past semicolon
810 elsif Token = Tok_Comma then
811 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
814 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
820 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
823 end Pre_Parse_Context_Clause;
825 -------------------------------
826 -- Post_Parse_Context_Clause --
827 -------------------------------
829 procedure Post_Parse_Context_Clause
830 (Context_Clause : With_Id;
831 In_Tree : Project_Node_Tree_Ref;
832 Limited_Withs : Boolean;
833 Imported_Projects : in out Project_Node_Id;
834 Project_Directory : Path_Name_Type;
835 From_Extended : Extension_Origin;
836 Packages_To_Check : String_List_Access;
838 Current_Dir : String;
839 Is_Config_File : Boolean;
840 Env : in out Environment)
842 Current_With_Clause : With_Id := Context_Clause;
844 Current_Project : Project_Node_Id := Imported_Projects;
845 Previous_Project : Project_Node_Id := Empty_Node;
846 Next_Project : Project_Node_Id := Empty_Node;
848 Project_Directory_Path : constant String :=
849 Get_Name_String (Project_Directory);
851 Current_With : With_Record;
852 Extends_All : Boolean := False;
853 Imported_Path_Name_Id : Path_Name_Type;
856 -- Set Current_Project to the last project in the current list, if the
857 -- list is not empty.
859 if Present (Current_Project) then
861 Present (Next_With_Clause_Of (Current_Project, In_Tree))
863 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
867 while Current_With_Clause /= No_With loop
868 Current_With := Withs.Table (Current_With_Clause);
869 Current_With_Clause := Current_With.Next;
871 if Limited_Withs = Current_With.Limited_With then
874 Project_File_Name => Get_Name_String (Current_With.Path),
875 Directory => Project_Directory_Path,
876 Path => Imported_Path_Name_Id);
878 if Imported_Path_Name_Id = No_Path then
879 if Env.Flags.Ignore_Missing_With then
880 In_Tree.Incomplete_With := True;
883 -- The project file cannot be found
885 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
887 (Env.Flags, "unknown project file: {",
888 Current_With.Location);
890 -- If this is not imported by the main project file, display
893 if Project_Stack.Last > 1 then
894 for Index in reverse 1 .. Project_Stack.Last loop
897 (Project_Stack.Table (Index).Path_Name);
899 (Env.Flags, "\imported by {", Current_With.Location);
908 Resolved_Path : constant String :=
910 (Get_Name_String (Imported_Path_Name_Id),
911 Directory => Current_Dir,
913 Opt.Follow_Links_For_Files,
914 Case_Sensitive => True);
916 Withed_Project : Project_Node_Id := Empty_Node;
919 Previous_Project := Current_Project;
921 if No (Current_Project) then
923 -- First with clause of the context clause
925 Current_Project := Current_With.Node;
926 Imported_Projects := Current_Project;
929 Next_Project := Current_With.Node;
930 Set_Next_With_Clause_Of
931 (Current_Project, In_Tree, Next_Project);
932 Current_Project := Next_Project;
938 Name_Id (Current_With.Path));
940 (Current_Project, In_Tree, Current_With.Location);
942 -- If it is a limited with, check if we have a circularity.
943 -- If we have one, get the project id of the limited
944 -- imported project file, and do not parse it.
946 if Limited_Withs and then Project_Stack.Last > 1 then
948 Canonical_Path_Name : Path_Name_Type;
951 Name_Len := Resolved_Path'Length;
952 Name_Buffer (1 .. Name_Len) := Resolved_Path;
953 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
954 Canonical_Path_Name := Name_Find;
956 for Index in 1 .. Project_Stack.Last loop
957 if Project_Stack.Table (Index).Canonical_Path_Name =
960 -- We have found the limited imported project,
961 -- get its project id, and do not parse it.
963 Withed_Project := Project_Stack.Table (Index).Id;
970 -- Parse the imported project, if its project id is unknown
972 if No (Withed_Project) then
975 Project => Withed_Project,
976 Extends_All => Extends_All,
977 Path_Name_Id => Imported_Path_Name_Id,
979 From_Extended => From_Extended,
980 In_Limited => Limited_Withs,
981 Packages_To_Check => Packages_To_Check,
983 Current_Dir => Current_Dir,
984 Is_Config_File => Is_Config_File,
988 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
991 if No (Withed_Project) then
993 -- If parsing unsuccessful, remove the context clause
995 Current_Project := Previous_Project;
997 if No (Current_Project) then
998 Imported_Projects := Empty_Node;
1001 Set_Next_With_Clause_Of
1002 (Current_Project, In_Tree, Empty_Node);
1005 -- If parsing was successful, record project name and
1006 -- path name in with clause
1009 (Node => Current_Project,
1011 To => Withed_Project,
1012 Limited_With => Current_With.Limited_With);
1016 Name_Of (Withed_Project, In_Tree));
1018 Name_Len := Resolved_Path'Length;
1019 Name_Buffer (1 .. Name_Len) := Resolved_Path;
1020 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
1023 Set_Is_Extending_All (Current_Project, In_Tree);
1030 end Post_Parse_Context_Clause;
1032 ---------------------------------
1033 -- Check_Extending_All_Imports --
1034 ---------------------------------
1036 procedure Check_Extending_All_Imports
1037 (Flags : Processing_Flags;
1038 In_Tree : Project_Node_Tree_Ref;
1039 Project : Project_Node_Id)
1041 With_Clause : Project_Node_Id;
1042 Imported : Project_Node_Id;
1045 if not Is_Extending_All (Project, In_Tree) then
1046 With_Clause := First_With_Clause_Of (Project, In_Tree);
1047 while Present (With_Clause) loop
1048 Imported := Project_Node_Of (With_Clause, In_Tree);
1050 if Is_Extending_All (With_Clause, In_Tree) then
1051 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
1052 Error_Msg (Flags, "cannot import extending-all project %%",
1057 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1060 end Check_Extending_All_Imports;
1062 -----------------------------
1063 -- Check_Aggregate_Imports --
1064 -----------------------------
1066 procedure Check_Aggregate_Imports
1067 (Flags : Processing_Flags;
1068 In_Tree : Project_Node_Tree_Ref;
1069 Project : Project_Node_Id)
1071 With_Clause, Imported : Project_Node_Id;
1073 if Project_Qualifier_Of (Project, In_Tree) = Aggregate then
1074 With_Clause := First_With_Clause_Of (Project, In_Tree);
1076 while Present (With_Clause) loop
1077 Imported := Project_Node_Of (With_Clause, In_Tree);
1079 if Project_Qualifier_Of (Imported, In_Tree) /= Dry then
1080 Error_Msg_Name_1 := Name_Id (Path_Name_Of (Imported, In_Tree));
1081 Error_Msg (Flags, "can only import abstract projects, not %%",
1086 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1089 end Check_Aggregate_Imports;
1091 ----------------------------
1092 -- Read_Project_Qualifier --
1093 ----------------------------
1095 procedure Read_Project_Qualifier
1096 (Flags : Processing_Flags;
1097 In_Tree : Project_Node_Tree_Ref;
1098 Is_Config_File : Boolean;
1099 Qualifier_Location : out Source_Ptr;
1100 Project : Project_Node_Id)
1102 Proj_Qualifier : Project_Qualifier := Unspecified;
1104 Qualifier_Location := Token_Ptr;
1106 if Token = Tok_Abstract then
1107 Proj_Qualifier := Dry;
1110 elsif Token = Tok_Identifier then
1112 when Snames.Name_Standard =>
1113 Proj_Qualifier := Standard;
1116 when Snames.Name_Aggregate =>
1117 Proj_Qualifier := Aggregate;
1120 if Token = Tok_Identifier
1121 and then Token_Name = Snames.Name_Library
1123 Proj_Qualifier := Aggregate_Library;
1127 when Snames.Name_Library =>
1128 Proj_Qualifier := Library;
1131 when Snames.Name_Configuration =>
1132 if not Is_Config_File then
1135 "configuration projects cannot belong to a user" &
1140 Proj_Qualifier := Configuration;
1148 if Is_Config_File and then Proj_Qualifier = Unspecified then
1150 -- Set the qualifier to Configuration, even if the token doesn't
1151 -- exist in the source file itself, so that we can differentiate
1152 -- project files and configuration files later on.
1154 Proj_Qualifier := Configuration;
1157 if Proj_Qualifier /= Unspecified then
1159 and then Proj_Qualifier /= Configuration
1162 "a configuration project cannot be qualified except " &
1163 "as configuration project",
1164 Qualifier_Location);
1167 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1169 end Read_Project_Qualifier;
1171 -------------------------------
1172 -- Has_Circular_Dependencies --
1173 -------------------------------
1175 function Has_Circular_Dependencies
1176 (Flags : Processing_Flags;
1177 Normed_Path_Name : Path_Name_Type;
1178 Canonical_Path_Name : Path_Name_Type) return Boolean is
1180 for Index in reverse 1 .. Project_Stack.Last loop
1181 exit when Project_Stack.Table (Index).Limited_With;
1183 if Canonical_Path_Name =
1184 Project_Stack.Table (Index).Canonical_Path_Name
1186 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
1187 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
1188 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
1190 for Current in reverse 1 .. Project_Stack.Last loop
1192 Name_Id (Project_Stack.Table (Current).Path_Name);
1194 if Project_Stack.Table (Current).Canonical_Path_Name /=
1198 (Flags, "\ %% which itself is imported by", Token_Ptr);
1201 Error_Msg (Flags, "\ %%", Token_Ptr);
1210 end Has_Circular_Dependencies;
1212 --------------------------
1213 -- Parse_Single_Project --
1214 --------------------------
1216 procedure Parse_Single_Project
1217 (In_Tree : Project_Node_Tree_Ref;
1218 Project : out Project_Node_Id;
1219 Extends_All : out Boolean;
1220 Path_Name_Id : Path_Name_Type;
1222 From_Extended : Extension_Origin;
1223 In_Limited : Boolean;
1224 Packages_To_Check : String_List_Access;
1226 Current_Dir : String;
1227 Is_Config_File : Boolean;
1228 Env : in out Environment)
1230 Path_Name : constant String := Get_Name_String (Path_Name_Id);
1232 Normed_Path_Name : Path_Name_Type;
1233 Canonical_Path_Name : Path_Name_Type;
1234 Project_Directory : Path_Name_Type;
1235 Project_Scan_State : Saved_Project_Scan_State;
1236 Source_Index : Source_File_Index;
1238 Extending : Boolean := False;
1240 Extended_Project : Project_Node_Id := Empty_Node;
1242 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1243 Tree_Private_Part.Projects_Htable.Get_First
1244 (In_Tree.Projects_HT);
1246 Name_From_Path : constant Name_Id :=
1247 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
1248 Name_Of_Project : Name_Id := No_Name;
1249 Display_Name_Of_Project : Name_Id := No_Name;
1251 Duplicated : Boolean := False;
1253 First_With : With_Id;
1254 Imported_Projects : Project_Node_Id := Empty_Node;
1256 use Tree_Private_Part;
1258 Project_Comment_State : Tree.Comment_State;
1260 Qualifier_Location : Source_Ptr;
1263 Extends_All := False;
1266 Normed_Path : constant String := Normalize_Pathname
1268 Directory => Current_Dir,
1269 Resolve_Links => False,
1270 Case_Sensitive => True);
1271 Canonical_Path : constant String := Normalize_Pathname
1273 Directory => Current_Dir,
1274 Resolve_Links => Opt.Follow_Links_For_Files,
1275 Case_Sensitive => False);
1277 Name_Len := Normed_Path'Length;
1278 Name_Buffer (1 .. Name_Len) := Normed_Path;
1279 Normed_Path_Name := Name_Find;
1280 Name_Len := Canonical_Path'Length;
1281 Name_Buffer (1 .. Name_Len) := Canonical_Path;
1282 Canonical_Path_Name := Name_Find;
1285 if Has_Circular_Dependencies
1286 (Env.Flags, Normed_Path_Name, Canonical_Path_Name)
1288 Project := Empty_Node;
1292 -- Put the new path name on the stack
1294 Project_Stack.Append
1295 ((Path_Name => Normed_Path_Name,
1296 Canonical_Path_Name => Canonical_Path_Name,
1298 Limited_With => In_Limited));
1300 -- Check if the project file has already been parsed
1303 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1305 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1308 if A_Project_Name_And_Node.Extended then
1309 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1312 "cannot extend the same project file several times",
1318 "cannot extend an already imported project file",
1322 elsif A_Project_Name_And_Node.Extended then
1324 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1326 -- If the imported project is an extended project A, and we are
1327 -- in an extended project, replace A with the ultimate project
1330 if From_Extended /= None then
1332 Decl : Project_Node_Id :=
1333 Project_Declaration_Of
1334 (A_Project_Name_And_Node.Node, In_Tree);
1336 Prj : Project_Node_Id :=
1337 A_Project_Name_And_Node.Node;
1340 -- Loop through extending projects to find the ultimate
1341 -- extending project, that is the one that is not
1342 -- extended. For an abstract project, as it can be
1343 -- extended several times, there is no extending project
1344 -- registered, so the loop does not execute and the
1345 -- resulting project is the abstract project.
1348 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1350 Prj := Extending_Project_Of (Decl, In_Tree);
1351 Decl := Project_Declaration_Of (Prj, In_Tree);
1354 A_Project_Name_And_Node.Node := Prj;
1359 "cannot import an already extended project file",
1364 Project := A_Project_Name_And_Node.Node;
1365 Project_Stack.Decrement_Last;
1369 A_Project_Name_And_Node :=
1370 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1373 -- We never encountered this project file. Save the scan state, load the
1374 -- project file and start to scan it.
1376 Save_Project_Scan_State (Project_Scan_State);
1377 Source_Index := Load_Project_File (Path_Name);
1378 Tree.Save (Project_Comment_State);
1380 -- If we cannot find it, we stop
1382 if Source_Index = No_Source_File then
1383 Project := Empty_Node;
1384 Project_Stack.Decrement_Last;
1388 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1392 if not Is_Config_File and then Name_From_Path = No_Name then
1394 -- The project file name is not correct (no or bad extension, or not
1395 -- following Ada identifier's syntax).
1397 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1398 Error_Msg (Env.Flags,
1399 "?{ is not a valid path name for a project file",
1403 if Current_Verbosity >= Medium then
1404 Debug_Increase_Indent ("Parsing """ & Path_Name & '"');
1407 Project_Directory :=
1408 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1410 -- Is there any imported project?
1412 Pre_Parse_Context_Clause
1413 (In_Tree => In_Tree,
1414 Is_Config_File => Is_Config_File,
1415 Context_Clause => First_With,
1416 Flags => Env.Flags);
1418 Project := Default_Project_Node
1419 (Of_Kind => N_Project, In_Tree => In_Tree);
1420 Project_Stack.Table (Project_Stack.Last).Id := Project;
1421 Set_Directory_Of (Project, In_Tree, Project_Directory);
1422 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1424 Read_Project_Qualifier
1425 (Env.Flags, In_Tree, Is_Config_File, Qualifier_Location, Project);
1427 Set_Location_Of (Project, In_Tree, Token_Ptr);
1429 Expect (Tok_Project, "PROJECT");
1431 -- Mark location of PROJECT token if present
1433 if Token = Tok_Project then
1434 Scan (In_Tree); -- past PROJECT
1435 Set_Location_Of (Project, In_Tree, Token_Ptr);
1442 Expect (Tok_Identifier, "identifier");
1444 -- If the token is not an identifier, clear the buffer before
1445 -- exiting to indicate that the name of the project is ill-formed.
1447 if Token /= Tok_Identifier then
1452 -- Add the identifier name to the buffer
1454 Get_Name_String (Token_Name);
1455 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1457 -- Scan past the identifier
1461 -- If we have a dot, add a dot to the Buffer and look for the next
1464 exit when Token /= Tok_Dot;
1465 Add_To_Buffer (".", Buffer, Buffer_Last);
1467 -- Scan past the dot
1472 -- See if this is an extending project
1474 if Token = Tok_Extends then
1476 if Is_Config_File then
1479 "extending configuration project not allowed", Token_Ptr);
1482 -- Make sure that gnatmake will use mapping files
1484 Opt.Create_Mapping_File := True;
1486 -- We are extending another project
1490 Scan (In_Tree); -- past EXTENDS
1492 if Token = Tok_All then
1493 Extends_All := True;
1494 Set_Is_Extending_All (Project, In_Tree);
1495 Scan (In_Tree); -- scan past ALL
1499 -- If the name is well formed, Buffer_Last is > 0
1501 if Buffer_Last > 0 then
1503 -- The Buffer contains the name of the project
1505 Name_Len := Buffer_Last;
1506 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1507 Name_Of_Project := Name_Find;
1508 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1510 -- To get expected name of the project file, replace dots by dashes
1512 for Index in 1 .. Name_Len loop
1513 if Name_Buffer (Index) = '.' then
1514 Name_Buffer (Index) := '-';
1518 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1521 Expected_Name : constant Name_Id := Name_Find;
1522 Extension : String_Access;
1525 -- Output a warning if the actual name is not the expected name
1527 if not Is_Config_File
1528 and then (Name_From_Path /= No_Name)
1529 and then Expected_Name /= Name_From_Path
1531 Error_Msg_Name_1 := Expected_Name;
1533 if Is_Config_File then
1534 Extension := new String'(Config_Project_File_Extension);
1537 Extension := new String'(Project_File_Extension);
1542 "?file name does not match project name, should be `%%"
1543 & Extension.all & "`",
1548 -- Read the original casing of the project name
1554 Loc := Location_Of (Project, In_Tree);
1555 for J in 1 .. Name_Len loop
1556 Name_Buffer (J) := Sinput.Source (Loc);
1560 Display_Name_Of_Project := Name_Find;
1564 From_Ext : Extension_Origin := None;
1567 -- Extending_All is always propagated
1569 if From_Extended = Extending_All or else Extends_All then
1570 From_Ext := Extending_All;
1572 -- Otherwise, From_Extended is set to Extending_Single if the
1573 -- current project is an extending project.
1576 From_Ext := Extending_Simple;
1579 Post_Parse_Context_Clause
1580 (In_Tree => In_Tree,
1581 Context_Clause => First_With,
1582 Limited_Withs => False,
1583 Imported_Projects => Imported_Projects,
1584 Project_Directory => Project_Directory,
1585 From_Extended => From_Ext,
1586 Packages_To_Check => Packages_To_Check,
1588 Current_Dir => Current_Dir,
1589 Is_Config_File => Is_Config_File,
1591 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1594 if not Is_Config_File then
1596 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1597 Tree_Private_Part.Projects_Htable.Get_First
1598 (In_Tree.Projects_HT);
1599 Project_Name : Name_Id := Name_And_Node.Name;
1602 -- Check if we already have a project with this name
1604 while Project_Name /= No_Name
1605 and then Project_Name /= Name_Of_Project
1608 Tree_Private_Part.Projects_Htable.Get_Next
1609 (In_Tree.Projects_HT);
1610 Project_Name := Name_And_Node.Name;
1613 -- Report an error if we already have a project with this name
1615 if Project_Name /= No_Name then
1617 Error_Msg_Name_1 := Project_Name;
1619 (Env.Flags, "duplicate project name %%",
1620 Location_Of (Project, In_Tree));
1622 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1625 "\already in %%", Location_Of (Project, In_Tree));
1633 Expect (Tok_String_Literal, "literal string");
1635 if Token = Tok_String_Literal then
1636 Set_Extended_Project_Path_Of
1639 Path_Name_Type (Token_Name));
1642 Original_Path_Name : constant String :=
1643 Get_Name_String (Token_Name);
1645 Extended_Project_Path_Name_Id : Path_Name_Type;
1650 Project_File_Name => Original_Path_Name,
1651 Directory => Get_Name_String (Project_Directory),
1652 Path => Extended_Project_Path_Name_Id);
1654 if Extended_Project_Path_Name_Id = No_Path then
1656 -- We could not find the project file to extend
1658 Error_Msg_Name_1 := Token_Name;
1660 Error_Msg (Env.Flags, "unknown project file: %%", Token_Ptr);
1662 -- If not in the main project file, display the import path
1664 if Project_Stack.Last > 1 then
1667 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1668 Error_Msg (Env.Flags, "\extended by %%", Token_Ptr);
1670 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1673 (Project_Stack.Table (Index).Path_Name);
1674 Error_Msg (Env.Flags, "\imported by %%", Token_Ptr);
1680 From_Ext : Extension_Origin := None;
1683 if From_Extended = Extending_All or else Extends_All then
1684 From_Ext := Extending_All;
1687 Parse_Single_Project
1688 (In_Tree => In_Tree,
1689 Project => Extended_Project,
1690 Extends_All => Extends_All,
1691 Path_Name_Id => Extended_Project_Path_Name_Id,
1693 From_Extended => From_Ext,
1694 In_Limited => In_Limited,
1695 Packages_To_Check => Packages_To_Check,
1697 Current_Dir => Current_Dir,
1698 Is_Config_File => Is_Config_File,
1702 if Present (Extended_Project) then
1704 -- A project that extends an extending-all project is
1705 -- also an extending-all project.
1707 if Is_Extending_All (Extended_Project, In_Tree) then
1708 Set_Is_Extending_All (Project, In_Tree);
1711 -- An abstract project can only extend an abstract
1712 -- project. Otherwise we may have an abstract project
1713 -- with sources if it inherits sources from the project
1716 if Project_Qualifier_Of (Project, In_Tree) = Dry and then
1717 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1720 (Env.Flags, "an abstract project can only extend " &
1721 "another abstract project",
1722 Qualifier_Location);
1728 Scan (In_Tree); -- past the extended project path
1732 Check_Extending_All_Imports (Env.Flags, In_Tree, Project);
1733 Check_Aggregate_Imports (Env.Flags, In_Tree, Project);
1735 -- Check that a project with a name including a dot either imports
1736 -- or extends the project whose name precedes the last dot.
1738 if Name_Of_Project /= No_Name then
1739 Get_Name_String (Name_Of_Project);
1745 -- Look for the last dot
1747 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1748 Name_Len := Name_Len - 1;
1751 -- If a dot was found, check if parent project is imported or extended
1753 if Name_Len > 0 then
1754 Name_Len := Name_Len - 1;
1757 Parent_Name : constant Name_Id := Name_Find;
1758 Parent_Found : Boolean := False;
1759 Parent_Node : Project_Node_Id := Empty_Node;
1760 With_Clause : Project_Node_Id :=
1761 First_With_Clause_Of (Project, In_Tree);
1762 Imp_Proj_Name : Name_Id;
1765 -- If there is an extended project, check its name
1767 if Present (Extended_Project) then
1768 Parent_Node := Extended_Project;
1770 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1773 -- If the parent project is not the extended project,
1774 -- check each imported project until we find the parent project.
1777 while not Parent_Found and then Present (With_Clause) loop
1778 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1779 Extension_Loop : while Present (Parent_Node) loop
1780 Imp_Proj_Name := Name_Of (Parent_Node, In_Tree);
1781 Parent_Found := Imp_Proj_Name = Parent_Name;
1782 exit Imported_Loop when Parent_Found;
1785 (Project_Declaration_Of (Parent_Node, In_Tree),
1787 end loop Extension_Loop;
1789 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1790 end loop Imported_Loop;
1792 if Parent_Found then
1793 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1796 -- If the parent project was not found, report an error
1798 Error_Msg_Name_1 := Name_Of_Project;
1799 Error_Msg_Name_2 := Parent_Name;
1800 Error_Msg (Env.Flags,
1801 "project %% does not import or extend project %%",
1802 Location_Of (Project, In_Tree));
1807 Expect (Tok_Is, "IS");
1808 Set_End_Of_Line (Project);
1809 Set_Previous_Line_Node (Project);
1810 Set_Next_End_Node (Project);
1813 Project_Declaration : Project_Node_Id := Empty_Node;
1816 -- No need to Scan past "is", Prj.Dect.Parse will do it
1819 (In_Tree => In_Tree,
1820 Declarations => Project_Declaration,
1821 Current_Project => Project,
1822 Extends => Extended_Project,
1823 Packages_To_Check => Packages_To_Check,
1824 Is_Config_File => Is_Config_File,
1825 Flags => Env.Flags);
1826 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1828 if Present (Extended_Project)
1829 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1831 Set_Extending_Project_Of
1832 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1837 Expect (Tok_End, "END");
1838 Remove_Next_End_Node;
1840 -- Skip "end" if present
1842 if Token = Tok_End then
1850 -- Store the name following "end" in the Buffer. The name may be made of
1851 -- several simple names.
1854 Expect (Tok_Identifier, "identifier");
1856 -- If we don't have an identifier, clear the buffer before exiting to
1857 -- avoid checking the name.
1859 if Token /= Tok_Identifier then
1864 -- Add the identifier to the Buffer
1865 Get_Name_String (Token_Name);
1866 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1868 -- Scan past the identifier
1871 exit when Token /= Tok_Dot;
1872 Add_To_Buffer (".", Buffer, Buffer_Last);
1876 -- If we have a valid name, check if it is the name of the project
1878 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1879 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1880 Get_Name_String (Name_Of (Project, In_Tree))
1882 -- Invalid name: report an error
1884 Error_Msg (Env.Flags, "expected """ &
1885 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1890 Expect (Tok_Semicolon, "`;`");
1892 -- Check that there is no more text following the end of the project
1895 if Token = Tok_Semicolon then
1896 Set_Previous_End_Node (Project);
1899 if Token /= Tok_EOF then
1902 "unexpected text following end of project", Token_Ptr);
1906 if not Duplicated and then Name_Of_Project /= No_Name then
1908 -- Add the name of the project to the hash table, so that we can
1909 -- check that no other subsequent project will have the same name.
1911 Tree_Private_Part.Projects_Htable.Set
1912 (T => In_Tree.Projects_HT,
1913 K => Name_Of_Project,
1914 E => (Name => Name_Of_Project,
1915 Display_Name => Display_Name_Of_Project,
1917 Canonical_Path => Canonical_Path_Name,
1918 Extended => Extended,
1919 Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
1923 From_Ext : Extension_Origin := None;
1926 -- Extending_All is always propagated
1928 if From_Extended = Extending_All or else Extends_All then
1929 From_Ext := Extending_All;
1931 -- Otherwise, From_Extended is set to Extending_Single if the
1932 -- current project is an extending project.
1935 From_Ext := Extending_Simple;
1938 Post_Parse_Context_Clause
1939 (In_Tree => In_Tree,
1940 Context_Clause => First_With,
1941 Limited_Withs => True,
1942 Imported_Projects => Imported_Projects,
1943 Project_Directory => Project_Directory,
1944 From_Extended => From_Ext,
1945 Packages_To_Check => Packages_To_Check,
1947 Current_Dir => Current_Dir,
1948 Is_Config_File => Is_Config_File,
1950 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1953 -- Restore the scan state, in case we are not the main project
1955 Restore_Project_Scan_State (Project_Scan_State);
1957 -- And remove the project from the project stack
1959 Project_Stack.Decrement_Last;
1961 -- Indicate if there are unkept comments
1963 Tree.Set_Project_File_Includes_Unkept_Comments
1966 To => Tree.There_Are_Unkept_Comments);
1968 -- And restore the comment state that was saved
1970 Tree.Restore_And_Free (Project_Comment_State);
1972 Debug_Decrease_Indent;
1973 end Parse_Single_Project;
1975 -----------------------
1976 -- Project_Name_From --
1977 -----------------------
1979 function Project_Name_From
1980 (Path_Name : String;
1981 Is_Config_File : Boolean) return Name_Id
1983 Canonical : String (1 .. Path_Name'Length) := Path_Name;
1984 First : Natural := Canonical'Last;
1985 Last : Natural := First;
1989 if Current_Verbosity = High then
1990 Debug_Output ("Project_Name_From (""" & Canonical & """)");
1993 -- If the path name is empty, return No_Name to indicate failure
1999 Canonical_Case_File_Name (Canonical);
2001 -- Look for the last dot in the path name
2005 Canonical (First) /= '.'
2010 -- If we have a dot, check that it is followed by the correct extension
2012 if First > 0 and then Canonical (First) = '.' then
2013 if (not Is_Config_File
2014 and then Canonical (First .. Last) = Project_File_Extension
2015 and then First /= 1)
2019 Canonical (First .. Last) = Config_Project_File_Extension
2020 and then First /= 1)
2022 -- Look for the last directory separator, if any
2027 and then Canonical (First) /= '/'
2028 and then Canonical (First) /= Dir_Sep
2034 -- Not the correct extension, return No_Name to indicate failure
2039 -- If no dot in the path name, return No_Name to indicate failure
2047 -- If the extension is the file name, return No_Name to indicate failure
2049 if First > Last then
2053 -- Put the name in lower case into Name_Buffer
2055 Name_Len := Last - First + 1;
2056 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
2060 -- Check if it is a well formed project name. Return No_Name if it is
2064 if not Is_Letter (Name_Buffer (Index)) then
2071 exit when Index >= Name_Len;
2073 if Name_Buffer (Index) = '_' then
2074 if Name_Buffer (Index + 1) = '_' then
2079 exit when Name_Buffer (Index) = '-';
2081 if Name_Buffer (Index) /= '_'
2082 and then not Is_Alphanumeric (Name_Buffer (Index))
2090 if Index >= Name_Len then
2091 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
2093 -- All checks have succeeded. Return name in Name_Buffer
2101 elsif Name_Buffer (Index) = '-' then
2105 end Project_Name_From;