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 => Empty_Node,
103 Key => Project_Node_Id,
104 Hash => Prj.Tree.Hash,
106 -- Hash table to store the node id of the project for which a virtual
107 -- extending project need to be created.
109 package Processed_Hash is new GNAT.HTable.Simple_HTable
110 (Header_Num => Header_Num,
113 Key => Project_Node_Id,
114 Hash => Prj.Tree.Hash,
116 -- Hash table to store the project process when looking for project that
117 -- need to have a virtual extending project, to avoid processing the same
120 function Has_Circular_Dependencies
121 (Flags : Processing_Flags;
122 Normed_Path_Name : Path_Name_Type;
123 Canonical_Path_Name : Path_Name_Type) return Boolean;
124 -- Check for a circular dependency in the loaded project.
125 -- Generates an error message in such a case.
127 procedure Read_Project_Qualifier
128 (Flags : Processing_Flags;
129 In_Tree : Project_Node_Tree_Ref;
130 Is_Config_File : Boolean;
131 Qualifier_Location : out Source_Ptr;
132 Project : Project_Node_Id);
133 -- Check if there is a qualifier before the reserved word "project"
135 -- Hash table to cache project path to avoid looking for them on the path
137 procedure Check_Extending_All_Imports
138 (Flags : Processing_Flags;
139 In_Tree : Project_Node_Tree_Ref;
140 Project : Project_Node_Id);
141 -- Check that a non extending-all project does not import an
142 -- extending-all project.
144 procedure Check_Aggregate_Imports
145 (Flags : Processing_Flags;
146 In_Tree : Project_Node_Tree_Ref;
147 Project : Project_Node_Id);
148 -- Check that an aggregate project only imports abstract projects
150 procedure Create_Virtual_Extending_Project
151 (For_Project : Project_Node_Id;
152 Main_Project : Project_Node_Id;
153 In_Tree : Project_Node_Tree_Ref);
154 -- Create a virtual extending project of For_Project. Main_Project is
155 -- the extending all project.
157 -- The String_Value_Of is not set for the automatically added with
158 -- clause and keeps the default value of No_Name. This enables Prj.PP
159 -- to skip these automatically added with clauses to be processed.
161 procedure Look_For_Virtual_Projects_For
162 (Proj : Project_Node_Id;
163 In_Tree : Project_Node_Tree_Ref;
164 Potentially_Virtual : Boolean);
165 -- Look for projects that need to have a virtual extending project.
166 -- This procedure is recursive. If called with Potentially_Virtual set to
167 -- True, then Proj may need an virtual extending project; otherwise it
168 -- does not (because it is already extended), but other projects that it
169 -- imports may need to be virtually extended.
171 type Extension_Origin is (None, Extending_Simple, Extending_All);
172 -- Type of parameter From_Extended for procedures Parse_Single_Project and
173 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
174 -- tree rooted at an extending all project.
176 procedure Parse_Single_Project
177 (In_Tree : Project_Node_Tree_Ref;
178 Project : out Project_Node_Id;
179 Extends_All : out Boolean;
180 Path_Name_Id : Path_Name_Type;
182 From_Extended : Extension_Origin;
183 In_Limited : Boolean;
184 Packages_To_Check : String_List_Access;
186 Current_Dir : String;
187 Is_Config_File : Boolean;
188 Env : in out Environment);
189 -- Parse a project file. This is a recursive procedure: it calls itself for
190 -- imported and extended projects. When From_Extended is not None, if the
191 -- project has already been parsed and is an extended project A, return the
192 -- ultimate (not extended) project that extends A. When In_Limited is True,
193 -- the importing path includes at least one "limited with". When parsing
194 -- configuration projects, do not allow a depth > 1.
196 -- Is_Config_File should be set to True if the project represents a config
197 -- file (.cgpr) since some specific checks apply.
199 procedure Pre_Parse_Context_Clause
200 (In_Tree : Project_Node_Tree_Ref;
201 Context_Clause : out With_Id;
202 Is_Config_File : Boolean;
203 Flags : Processing_Flags);
204 -- Parse the context clause of a project. Store the paths and locations of
205 -- the imported projects in table Withs. Does nothing if there is no
206 -- context clause (if the current token is not "with" or "limited" followed
208 -- Is_Config_File should be set to True if the project represents a config
209 -- file (.cgpr) since some specific checks apply.
211 procedure Post_Parse_Context_Clause
212 (Context_Clause : With_Id;
213 In_Tree : Project_Node_Tree_Ref;
214 Limited_Withs : Boolean;
215 Imported_Projects : in out Project_Node_Id;
216 Project_Directory : Path_Name_Type;
217 From_Extended : Extension_Origin;
218 In_Limited : Boolean;
219 Packages_To_Check : String_List_Access;
221 Current_Dir : String;
222 Is_Config_File : Boolean;
223 Env : in out Environment);
224 -- Parse the imported projects that have been stored in table Withs, if
225 -- any. From_Extended is used for the call to Parse_Single_Project below.
226 -- When In_Limited is True, the importing path includes at least one
227 -- "limited with". When Limited_Withs is False, only non limited withed
228 -- projects are parsed. When Limited_Withs is True, only limited withed
229 -- projects are parsed.
230 -- Is_Config_File should be set to True if the project represents a config
231 -- file (.cgpr) since some specific checks apply.
233 function Project_Name_From
235 Is_Config_File : Boolean) return Name_Id;
236 -- Returns the name of the project that corresponds to its path name.
237 -- Returns No_Name if the path name is invalid, because the corresponding
238 -- project name does not have the syntax of an ada identifier.
240 --------------------------------------
241 -- Create_Virtual_Extending_Project --
242 --------------------------------------
244 procedure Create_Virtual_Extending_Project
245 (For_Project : Project_Node_Id;
246 Main_Project : Project_Node_Id;
247 In_Tree : Project_Node_Tree_Ref)
250 Virtual_Name : constant String :=
252 Get_Name_String (Name_Of (For_Project, In_Tree));
253 -- The name of the virtual extending project
255 Virtual_Name_Id : Name_Id;
256 -- Virtual extending project name id
258 Virtual_Path_Id : Path_Name_Type;
259 -- Fake path name of the virtual extending project. The directory is
260 -- the same directory as the extending all project.
262 -- The source of the virtual extending project is something like:
264 -- project V$<project name> extends <project path> is
266 -- for Source_Dirs use ();
268 -- end V$<project name>;
270 -- The project directory cannot be specified during parsing; it will be
271 -- put directly in the virtual extending project data during processing.
273 -- Nodes that made up the virtual extending project
275 Virtual_Project : Project_Node_Id;
276 With_Clause : constant Project_Node_Id :=
278 (In_Tree, N_With_Clause);
279 Project_Declaration : Project_Node_Id;
280 Source_Dirs_Declaration : constant Project_Node_Id :=
282 (In_Tree, N_Declarative_Item);
283 Source_Dirs_Attribute : constant Project_Node_Id :=
285 (In_Tree, N_Attribute_Declaration, List);
286 Source_Dirs_Expression : constant Project_Node_Id :=
288 (In_Tree, N_Expression, List);
289 Source_Dirs_Term : constant Project_Node_Id :=
291 (In_Tree, N_Term, List);
292 Source_Dirs_List : constant Project_Node_Id :=
294 (In_Tree, N_Literal_String_List, List);
297 -- Get the virtual path name
299 Get_Name_String (Path_Name_Of (Main_Project, In_Tree));
302 and then Name_Buffer (Name_Len) /= Directory_Separator
303 and then Name_Buffer (Name_Len) /= '/'
305 Name_Len := Name_Len - 1;
308 Name_Buffer (Name_Len + 1 .. Name_Len + Virtual_Name'Length) :=
310 Name_Len := Name_Len + Virtual_Name'Length;
311 Virtual_Path_Id := Name_Find;
313 -- Get the virtual name id
315 Name_Len := Virtual_Name'Length;
316 Name_Buffer (1 .. Name_Len) := Virtual_Name;
317 Virtual_Name_Id := Name_Find;
319 Virtual_Project := Create_Project
321 Name => Virtual_Name_Id,
322 Full_Path => Virtual_Path_Id,
323 Is_Config_File => False);
325 Project_Declaration := Project_Declaration_Of (Virtual_Project, In_Tree);
329 Set_Name_Of (With_Clause, In_Tree, Virtual_Name_Id);
330 Set_Path_Name_Of (With_Clause, In_Tree, Virtual_Path_Id);
331 Set_Project_Node_Of (With_Clause, In_Tree, Virtual_Project);
332 Set_Next_With_Clause_Of
333 (With_Clause, In_Tree, First_With_Clause_Of (Main_Project, In_Tree));
334 Set_First_With_Clause_Of (Main_Project, In_Tree, With_Clause);
336 -- Virtual project node
339 (Virtual_Project, In_Tree, Location_Of (Main_Project, In_Tree));
340 Set_Extended_Project_Path_Of
341 (Virtual_Project, In_Tree, Path_Name_Of (For_Project, In_Tree));
343 -- Project declaration
345 Set_First_Declarative_Item_Of
346 (Project_Declaration, In_Tree, Source_Dirs_Declaration);
347 Set_Extended_Project_Of (Project_Declaration, In_Tree, For_Project);
349 -- Source_Dirs declaration
351 Set_Current_Item_Node
352 (Source_Dirs_Declaration, In_Tree, Source_Dirs_Attribute);
354 -- Source_Dirs attribute
356 Set_Name_Of (Source_Dirs_Attribute, In_Tree, Snames.Name_Source_Dirs);
358 (Source_Dirs_Attribute, In_Tree, Source_Dirs_Expression);
360 -- Source_Dirs expression
362 Set_First_Term (Source_Dirs_Expression, In_Tree, Source_Dirs_Term);
366 Set_Current_Term (Source_Dirs_Term, In_Tree, Source_Dirs_List);
368 -- Source_Dirs empty list: nothing to do
369 end Create_Virtual_Extending_Project;
371 -----------------------------------
372 -- Look_For_Virtual_Projects_For --
373 -----------------------------------
375 procedure Look_For_Virtual_Projects_For
376 (Proj : Project_Node_Id;
377 In_Tree : Project_Node_Tree_Ref;
378 Potentially_Virtual : Boolean)
380 Declaration : Project_Node_Id := Empty_Node;
381 -- Node for the project declaration of Proj
383 With_Clause : Project_Node_Id := Empty_Node;
384 -- Node for a with clause of Proj
386 Imported : Project_Node_Id := Empty_Node;
387 -- Node for a project imported by Proj
389 Extended : Project_Node_Id := Empty_Node;
390 -- Node for the eventual project extended by Proj
393 -- Nothing to do if Proj is not defined or if it has already been
396 if Present (Proj) and then not Processed_Hash.Get (Proj) then
397 -- Make sure the project will not be processed again
399 Processed_Hash.Set (Proj, True);
401 Declaration := Project_Declaration_Of (Proj, In_Tree);
403 if Present (Declaration) then
404 Extended := Extended_Project_Of (Declaration, In_Tree);
407 -- If this is a project that may need a virtual extending project
408 -- and it is not itself an extending project, put it in the list.
410 if Potentially_Virtual and then No (Extended) then
411 Virtual_Hash.Set (Proj, Proj);
414 -- Now check the projects it imports
416 With_Clause := First_With_Clause_Of (Proj, In_Tree);
418 while Present (With_Clause) loop
419 Imported := Project_Node_Of (With_Clause, In_Tree);
421 if Present (Imported) then
422 Look_For_Virtual_Projects_For
423 (Imported, In_Tree, Potentially_Virtual => True);
426 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
429 -- Check also the eventual project extended by Proj. As this project
430 -- is already extended, call recursively with Potentially_Virtual
433 Look_For_Virtual_Projects_For
434 (Extended, In_Tree, Potentially_Virtual => False);
436 end Look_For_Virtual_Projects_For;
443 (In_Tree : Project_Node_Tree_Ref;
444 Project : out Project_Node_Id;
445 Project_File_Name : String;
446 Errout_Handling : Errout_Mode := Always_Finalize;
447 Packages_To_Check : String_List_Access := All_Packages;
448 Store_Comments : Boolean := False;
449 Current_Directory : String := "";
450 Is_Config_File : Boolean;
451 Env : in out Prj.Tree.Environment;
452 Target_Name : String := "")
455 pragma Warnings (Off, Dummy);
457 Real_Project_File_Name : String_Access :=
458 Osint.To_Canonical_File_Spec
460 Path_Name_Id : Path_Name_Type;
463 In_Tree.Incomplete_With := False;
465 if not Is_Initialized (Env.Project_Path) then
466 Prj.Env.Initialize_Default_Project_Path
467 (Env.Project_Path, Target_Name);
470 if Real_Project_File_Name = null then
471 Real_Project_File_Name := new String'(Project_File_Name);
474 Project := Empty_Node;
476 Find_Project (Env.Project_Path,
477 Project_File_Name => Real_Project_File_Name.all,
478 Directory => Current_Directory,
479 Path => Path_Name_Id);
480 Free (Real_Project_File_Name);
482 if Errout_Handling /= Never_Finalize then
486 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
487 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
489 if Path_Name_Id = No_Path then
493 Get_Path (Env.Project_Path, Path => P);
500 Project := Empty_Node;
505 -- Parse the main project file
511 Extends_All => Dummy,
512 Path_Name_Id => Path_Name_Id,
514 From_Extended => None,
516 Packages_To_Check => Packages_To_Check,
518 Current_Dir => Current_Directory,
519 Is_Config_File => Is_Config_File,
523 when Types.Unrecoverable_Error =>
525 -- Unrecoverable_Error is raised when a line is too long.
526 -- A meaningful error message will be displayed later.
528 Project := Empty_Node;
531 -- If Project is an extending-all project, create the eventual
532 -- virtual extending projects and check that there are no illegally
533 -- imported projects.
536 and then Is_Extending_All (Project, In_Tree)
538 -- First look for projects that potentially need a virtual
539 -- extending project.
542 Processed_Hash.Reset;
544 -- Mark the extending all project as processed, to avoid checking
545 -- the imported projects in case of a "limited with" on this
546 -- extending all project.
548 Processed_Hash.Set (Project, True);
551 Declaration : constant Project_Node_Id :=
552 Project_Declaration_Of (Project, In_Tree);
554 Look_For_Virtual_Projects_For
555 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
556 Potentially_Virtual => False);
559 -- Now, check the projects directly imported by the main project.
560 -- Remove from the potentially virtual any project extended by one
561 -- of these imported projects. For non extending imported projects,
562 -- check that they do not belong to the project tree of the project
563 -- being "extended-all" by the main project.
566 With_Clause : Project_Node_Id;
567 Imported : Project_Node_Id := Empty_Node;
568 Declaration : Project_Node_Id := Empty_Node;
571 With_Clause := First_With_Clause_Of (Project, In_Tree);
572 while Present (With_Clause) loop
573 Imported := Project_Node_Of (With_Clause, In_Tree);
575 if Present (Imported) then
576 Declaration := Project_Declaration_Of (Imported, In_Tree);
578 if Extended_Project_Of (Declaration, In_Tree) /=
583 Extended_Project_Of (Declaration, In_Tree);
584 exit when No (Imported);
585 Virtual_Hash.Remove (Imported);
587 Project_Declaration_Of (Imported, In_Tree);
592 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
596 -- Now create all the virtual extending projects
599 Proj : Project_Node_Id := Virtual_Hash.Get_First;
601 while Present (Proj) loop
602 Create_Virtual_Extending_Project (Proj, Project, In_Tree);
603 Proj := Virtual_Hash.Get_Next;
608 -- If there were any kind of error during the parsing, serious
609 -- or not, then the parsing fails.
611 if Err_Vars.Total_Errors_Detected > 0 then
612 Project := Empty_Node;
615 case Errout_Handling is
616 when Always_Finalize =>
619 -- Reinitialize to avoid duplicate warnings later on
622 when Finalize_If_Error =>
628 when Never_Finalize =>
637 Write_Line (Exception_Information (X));
638 Write_Str ("Exception ");
639 Write_Str (Exception_Name (X));
640 Write_Line (" raised, while processing project file");
641 Project := Empty_Node;
644 ------------------------------
645 -- Pre_Parse_Context_Clause --
646 ------------------------------
648 procedure Pre_Parse_Context_Clause
649 (In_Tree : Project_Node_Tree_Ref;
650 Context_Clause : out With_Id;
651 Is_Config_File : Boolean;
652 Flags : Processing_Flags)
654 Current_With_Clause : With_Id := No_With;
655 Limited_With : Boolean := False;
656 Current_With : With_Record;
657 Current_With_Node : Project_Node_Id := Empty_Node;
660 -- Assume no context clause
662 Context_Clause := No_With;
665 -- If Token is not WITH or LIMITED, there is no context clause, or we
666 -- have exhausted the with clauses.
668 while Token = Tok_With or else Token = Tok_Limited loop
670 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
671 Limited_With := Token = Tok_Limited;
673 if Is_Config_File then
676 "configuration project cannot import " &
677 "other configuration projects",
682 Scan (In_Tree); -- scan past LIMITED
683 Expect (Tok_With, "WITH");
684 exit With_Loop when Token /= Tok_With;
689 Scan (In_Tree); -- past WITH or ","
691 Expect (Tok_String_Literal, "literal string");
693 if Token /= Tok_String_Literal then
697 -- Store path and location in table Withs
700 (Path => Path_Name_Type (Token_Name),
701 Location => Token_Ptr,
702 Limited_With => Limited_With,
703 Node => Current_With_Node,
706 Withs.Increment_Last;
707 Withs.Table (Withs.Last) := Current_With;
709 if Current_With_Clause = No_With then
710 Context_Clause := Withs.Last;
713 Withs.Table (Current_With_Clause).Next := Withs.Last;
716 Current_With_Clause := Withs.Last;
720 if Token = Tok_Semicolon then
721 Set_End_Of_Line (Current_With_Node);
722 Set_Previous_Line_Node (Current_With_Node);
724 -- End of (possibly multiple) with clause;
726 Scan (In_Tree); -- past the semicolon
729 elsif Token = Tok_Comma then
730 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
733 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
739 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
742 end Pre_Parse_Context_Clause;
744 -------------------------------
745 -- Post_Parse_Context_Clause --
746 -------------------------------
748 procedure Post_Parse_Context_Clause
749 (Context_Clause : With_Id;
750 In_Tree : Project_Node_Tree_Ref;
751 Limited_Withs : Boolean;
752 Imported_Projects : in out Project_Node_Id;
753 Project_Directory : Path_Name_Type;
754 From_Extended : Extension_Origin;
755 In_Limited : Boolean;
756 Packages_To_Check : String_List_Access;
758 Current_Dir : String;
759 Is_Config_File : Boolean;
760 Env : in out Environment)
762 Current_With_Clause : With_Id := Context_Clause;
764 Current_Project : Project_Node_Id := Imported_Projects;
765 Previous_Project : Project_Node_Id := Empty_Node;
766 Next_Project : Project_Node_Id := Empty_Node;
768 Project_Directory_Path : constant String :=
769 Get_Name_String (Project_Directory);
771 Current_With : With_Record;
772 Extends_All : Boolean := False;
773 Imported_Path_Name_Id : Path_Name_Type;
776 -- Set Current_Project to the last project in the current list, if the
777 -- list is not empty.
779 if Present (Current_Project) then
781 Present (Next_With_Clause_Of (Current_Project, In_Tree))
783 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
787 while Current_With_Clause /= No_With loop
788 Current_With := Withs.Table (Current_With_Clause);
789 Current_With_Clause := Current_With.Next;
791 if Limited_Withs = Current_With.Limited_With then
794 Project_File_Name => Get_Name_String (Current_With.Path),
795 Directory => Project_Directory_Path,
796 Path => Imported_Path_Name_Id);
798 if Imported_Path_Name_Id = No_Path then
799 if Env.Flags.Ignore_Missing_With then
800 In_Tree.Incomplete_With := True;
803 -- The project file cannot be found
805 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
807 (Env.Flags, "unknown project file: {",
808 Current_With.Location);
810 -- If this is not imported by the main project file, display
813 if Project_Stack.Last > 1 then
814 for Index in reverse 1 .. Project_Stack.Last loop
817 (Project_Stack.Table (Index).Path_Name);
819 (Env.Flags, "\imported by {", Current_With.Location);
828 Resolved_Path : constant String :=
830 (Get_Name_String (Imported_Path_Name_Id),
831 Directory => Current_Dir,
833 Opt.Follow_Links_For_Files,
834 Case_Sensitive => True);
836 Withed_Project : Project_Node_Id := Empty_Node;
839 Previous_Project := Current_Project;
841 if No (Current_Project) then
843 -- First with clause of the context clause
845 Current_Project := Current_With.Node;
846 Imported_Projects := Current_Project;
849 Next_Project := Current_With.Node;
850 Set_Next_With_Clause_Of
851 (Current_Project, In_Tree, Next_Project);
852 Current_Project := Next_Project;
858 Name_Id (Current_With.Path));
860 (Current_Project, In_Tree, Current_With.Location);
862 -- If it is a limited with, check if we have a circularity.
863 -- If we have one, get the project id of the limited
864 -- imported project file, and do not parse it.
866 if Limited_Withs and then Project_Stack.Last > 1 then
868 Canonical_Path_Name : Path_Name_Type;
871 Name_Len := Resolved_Path'Length;
872 Name_Buffer (1 .. Name_Len) := Resolved_Path;
873 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
874 Canonical_Path_Name := Name_Find;
876 for Index in 1 .. Project_Stack.Last loop
877 if Project_Stack.Table (Index).Canonical_Path_Name =
880 -- We have found the limited imported project,
881 -- get its project id, and do not parse it.
883 Withed_Project := Project_Stack.Table (Index).Id;
890 -- Parse the imported project, if its project id is unknown
892 if No (Withed_Project) then
895 Project => Withed_Project,
896 Extends_All => Extends_All,
897 Path_Name_Id => Imported_Path_Name_Id,
899 From_Extended => From_Extended,
900 In_Limited => Limited_Withs,
901 Packages_To_Check => Packages_To_Check,
903 Current_Dir => Current_Dir,
904 Is_Config_File => Is_Config_File,
908 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
911 if No (Withed_Project) then
913 -- If parsing unsuccessful, remove the context clause
915 Current_Project := Previous_Project;
917 if No (Current_Project) then
918 Imported_Projects := Empty_Node;
921 Set_Next_With_Clause_Of
922 (Current_Project, In_Tree, Empty_Node);
925 -- If parsing was successful, record project name and
926 -- path name in with clause
929 (Node => Current_Project,
931 To => Withed_Project,
932 Limited_With => Current_With.Limited_With);
936 Name_Of (Withed_Project, In_Tree));
938 Name_Len := Resolved_Path'Length;
939 Name_Buffer (1 .. Name_Len) := Resolved_Path;
940 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
943 Set_Is_Extending_All (Current_Project, In_Tree);
950 end Post_Parse_Context_Clause;
952 ---------------------------------
953 -- Check_Extending_All_Imports --
954 ---------------------------------
956 procedure Check_Extending_All_Imports
957 (Flags : Processing_Flags;
958 In_Tree : Project_Node_Tree_Ref;
959 Project : Project_Node_Id)
961 With_Clause : Project_Node_Id;
962 Imported : Project_Node_Id;
965 if not Is_Extending_All (Project, In_Tree) then
966 With_Clause := First_With_Clause_Of (Project, In_Tree);
967 while Present (With_Clause) loop
968 Imported := Project_Node_Of (With_Clause, In_Tree);
970 if Is_Extending_All (With_Clause, In_Tree) then
971 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
972 Error_Msg (Flags, "cannot import extending-all project %%",
977 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
980 end Check_Extending_All_Imports;
982 -----------------------------
983 -- Check_Aggregate_Imports --
984 -----------------------------
986 procedure Check_Aggregate_Imports
987 (Flags : Processing_Flags;
988 In_Tree : Project_Node_Tree_Ref;
989 Project : Project_Node_Id)
991 With_Clause, Imported : Project_Node_Id;
993 if Project_Qualifier_Of (Project, In_Tree) = Aggregate then
994 With_Clause := First_With_Clause_Of (Project, In_Tree);
996 while Present (With_Clause) loop
997 Imported := Project_Node_Of (With_Clause, In_Tree);
999 if Project_Qualifier_Of (Imported, In_Tree) /= Dry then
1000 Error_Msg_Name_1 := Name_Id (Path_Name_Of (Imported, In_Tree));
1001 Error_Msg (Flags, "can only import abstract projects, not %%",
1006 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1009 end Check_Aggregate_Imports;
1011 ----------------------------
1012 -- Read_Project_Qualifier --
1013 ----------------------------
1015 procedure Read_Project_Qualifier
1016 (Flags : Processing_Flags;
1017 In_Tree : Project_Node_Tree_Ref;
1018 Is_Config_File : Boolean;
1019 Qualifier_Location : out Source_Ptr;
1020 Project : Project_Node_Id)
1022 Proj_Qualifier : Project_Qualifier := Unspecified;
1024 Qualifier_Location := Token_Ptr;
1026 if Token = Tok_Abstract then
1027 Proj_Qualifier := Dry;
1030 elsif Token = Tok_Identifier then
1032 when Snames.Name_Standard =>
1033 Proj_Qualifier := Standard;
1036 when Snames.Name_Aggregate =>
1037 Proj_Qualifier := Aggregate;
1040 if Token = Tok_Identifier and then
1041 Token_Name = Snames.Name_Library
1043 Proj_Qualifier := Aggregate_Library;
1047 when Snames.Name_Library =>
1048 Proj_Qualifier := Library;
1051 when Snames.Name_Configuration =>
1052 if not Is_Config_File then
1055 "configuration projects cannot belong to a user" &
1060 Proj_Qualifier := Configuration;
1068 if Is_Config_File and then Proj_Qualifier = Unspecified then
1070 -- Set the qualifier to Configuration, even if the token doesn't
1071 -- exist in the source file itself, so that we can differentiate
1072 -- project files and configuration files later on.
1074 Proj_Qualifier := Configuration;
1077 if Proj_Qualifier /= Unspecified then
1079 and then Proj_Qualifier /= Configuration
1082 "a configuration project cannot be qualified except " &
1083 "as configuration project",
1084 Qualifier_Location);
1087 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1089 end Read_Project_Qualifier;
1091 -------------------------------
1092 -- Has_Circular_Dependencies --
1093 -------------------------------
1095 function Has_Circular_Dependencies
1096 (Flags : Processing_Flags;
1097 Normed_Path_Name : Path_Name_Type;
1098 Canonical_Path_Name : Path_Name_Type) return Boolean is
1100 for Index in reverse 1 .. Project_Stack.Last loop
1101 exit when Project_Stack.Table (Index).Limited_With;
1103 if Canonical_Path_Name =
1104 Project_Stack.Table (Index).Canonical_Path_Name
1106 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
1107 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
1108 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
1110 for Current in reverse 1 .. Project_Stack.Last loop
1112 Name_Id (Project_Stack.Table (Current).Path_Name);
1114 if Project_Stack.Table (Current).Canonical_Path_Name /=
1118 (Flags, "\ %% which itself is imported by", Token_Ptr);
1121 Error_Msg (Flags, "\ %%", Token_Ptr);
1130 end Has_Circular_Dependencies;
1132 --------------------------
1133 -- Parse_Single_Project --
1134 --------------------------
1136 procedure Parse_Single_Project
1137 (In_Tree : Project_Node_Tree_Ref;
1138 Project : out Project_Node_Id;
1139 Extends_All : out Boolean;
1140 Path_Name_Id : Path_Name_Type;
1142 From_Extended : Extension_Origin;
1143 In_Limited : Boolean;
1144 Packages_To_Check : String_List_Access;
1146 Current_Dir : String;
1147 Is_Config_File : Boolean;
1148 Env : in out Environment)
1150 Path_Name : constant String := Get_Name_String (Path_Name_Id);
1152 Normed_Path_Name : Path_Name_Type;
1153 Canonical_Path_Name : Path_Name_Type;
1154 Project_Directory : Path_Name_Type;
1155 Project_Scan_State : Saved_Project_Scan_State;
1156 Source_Index : Source_File_Index;
1158 Extending : Boolean := False;
1160 Extended_Project : Project_Node_Id := Empty_Node;
1162 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1163 Tree_Private_Part.Projects_Htable.Get_First
1164 (In_Tree.Projects_HT);
1166 Name_From_Path : constant Name_Id :=
1167 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
1168 Name_Of_Project : Name_Id := No_Name;
1169 Display_Name_Of_Project : Name_Id := No_Name;
1171 Duplicated : Boolean := False;
1173 First_With : With_Id;
1174 Imported_Projects : Project_Node_Id := Empty_Node;
1176 use Tree_Private_Part;
1178 Project_Comment_State : Tree.Comment_State;
1180 Qualifier_Location : Source_Ptr;
1183 Extends_All := False;
1186 Normed_Path : constant String := Normalize_Pathname
1188 Directory => Current_Dir,
1189 Resolve_Links => False,
1190 Case_Sensitive => True);
1191 Canonical_Path : constant String := Normalize_Pathname
1193 Directory => Current_Dir,
1194 Resolve_Links => Opt.Follow_Links_For_Files,
1195 Case_Sensitive => False);
1197 Name_Len := Normed_Path'Length;
1198 Name_Buffer (1 .. Name_Len) := Normed_Path;
1199 Normed_Path_Name := Name_Find;
1200 Name_Len := Canonical_Path'Length;
1201 Name_Buffer (1 .. Name_Len) := Canonical_Path;
1202 Canonical_Path_Name := Name_Find;
1205 if Has_Circular_Dependencies
1206 (Env.Flags, Normed_Path_Name, Canonical_Path_Name)
1208 Project := Empty_Node;
1212 -- Put the new path name on the stack
1214 Project_Stack.Append
1215 ((Path_Name => Normed_Path_Name,
1216 Canonical_Path_Name => Canonical_Path_Name,
1218 Limited_With => In_Limited));
1220 -- Check if the project file has already been parsed
1223 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1225 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1228 if A_Project_Name_And_Node.Extended then
1229 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1232 "cannot extend the same project file several times",
1238 "cannot extend an already imported project file",
1242 elsif A_Project_Name_And_Node.Extended then
1244 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1246 -- If the imported project is an extended project A, and we are
1247 -- in an extended project, replace A with the ultimate project
1250 if From_Extended /= None then
1252 Decl : Project_Node_Id :=
1253 Project_Declaration_Of
1254 (A_Project_Name_And_Node.Node, In_Tree);
1256 Prj : Project_Node_Id :=
1257 A_Project_Name_And_Node.Node;
1260 -- Loop through extending projects to find the ultimate
1261 -- extending project, that is the one that is not
1262 -- extended. For an abstract project, as it can be
1263 -- extended several times, there is no extending project
1264 -- registered, so the loop does not execute and the
1265 -- resulting project is the abstract project.
1268 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1270 Prj := Extending_Project_Of (Decl, In_Tree);
1271 Decl := Project_Declaration_Of (Prj, In_Tree);
1274 A_Project_Name_And_Node.Node := Prj;
1279 "cannot import an already extended project file",
1284 Project := A_Project_Name_And_Node.Node;
1285 Project_Stack.Decrement_Last;
1289 A_Project_Name_And_Node :=
1290 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1293 -- We never encountered this project file. Save the scan state, load the
1294 -- project file and start to scan it.
1296 Save_Project_Scan_State (Project_Scan_State);
1297 Source_Index := Load_Project_File (Path_Name);
1298 Tree.Save (Project_Comment_State);
1300 -- If we cannot find it, we stop
1302 if Source_Index = No_Source_File then
1303 Project := Empty_Node;
1304 Project_Stack.Decrement_Last;
1308 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1312 if not Is_Config_File and then Name_From_Path = No_Name then
1314 -- The project file name is not correct (no or bad extension, or not
1315 -- following Ada identifier's syntax).
1317 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1318 Error_Msg (Env.Flags,
1319 "?{ is not a valid path name for a project file",
1323 if Current_Verbosity >= Medium then
1324 Debug_Increase_Indent ("Parsing """ & Path_Name & '"');
1327 Project_Directory :=
1328 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1330 -- Is there any imported project?
1332 Pre_Parse_Context_Clause
1333 (In_Tree => In_Tree,
1334 Is_Config_File => Is_Config_File,
1335 Context_Clause => First_With,
1336 Flags => Env.Flags);
1338 Project := Default_Project_Node
1339 (Of_Kind => N_Project, In_Tree => In_Tree);
1340 Project_Stack.Table (Project_Stack.Last).Id := Project;
1341 Set_Directory_Of (Project, In_Tree, Project_Directory);
1342 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1344 Read_Project_Qualifier
1345 (Env.Flags, In_Tree, Is_Config_File, Qualifier_Location, Project);
1347 Set_Location_Of (Project, In_Tree, Token_Ptr);
1349 Expect (Tok_Project, "PROJECT");
1351 -- Mark location of PROJECT token if present
1353 if Token = Tok_Project then
1354 Scan (In_Tree); -- past PROJECT
1355 Set_Location_Of (Project, In_Tree, Token_Ptr);
1362 Expect (Tok_Identifier, "identifier");
1364 -- If the token is not an identifier, clear the buffer before
1365 -- exiting to indicate that the name of the project is ill-formed.
1367 if Token /= Tok_Identifier then
1372 -- Add the identifier name to the buffer
1374 Get_Name_String (Token_Name);
1375 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1377 -- Scan past the identifier
1381 -- If we have a dot, add a dot to the Buffer and look for the next
1384 exit when Token /= Tok_Dot;
1385 Add_To_Buffer (".", Buffer, Buffer_Last);
1387 -- Scan past the dot
1392 -- See if this is an extending project
1394 if Token = Tok_Extends then
1396 if Is_Config_File then
1399 "extending configuration project not allowed", Token_Ptr);
1402 -- Make sure that gnatmake will use mapping files
1404 Opt.Create_Mapping_File := True;
1406 -- We are extending another project
1410 Scan (In_Tree); -- past EXTENDS
1412 if Token = Tok_All then
1413 Extends_All := True;
1414 Set_Is_Extending_All (Project, In_Tree);
1415 Scan (In_Tree); -- scan past ALL
1419 -- If the name is well formed, Buffer_Last is > 0
1421 if Buffer_Last > 0 then
1423 -- The Buffer contains the name of the project
1425 Name_Len := Buffer_Last;
1426 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1427 Name_Of_Project := Name_Find;
1428 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1430 -- To get expected name of the project file, replace dots by dashes
1432 for Index in 1 .. Name_Len loop
1433 if Name_Buffer (Index) = '.' then
1434 Name_Buffer (Index) := '-';
1438 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1441 Expected_Name : constant Name_Id := Name_Find;
1442 Extension : String_Access;
1445 -- Output a warning if the actual name is not the expected name
1447 if not Is_Config_File
1448 and then (Name_From_Path /= No_Name)
1449 and then Expected_Name /= Name_From_Path
1451 Error_Msg_Name_1 := Expected_Name;
1453 if Is_Config_File then
1454 Extension := new String'(Config_Project_File_Extension);
1457 Extension := new String'(Project_File_Extension);
1462 "?file name does not match project name, should be `%%"
1463 & Extension.all & "`",
1468 -- Read the original casing of the project name
1474 Loc := Location_Of (Project, In_Tree);
1475 for J in 1 .. Name_Len loop
1476 Name_Buffer (J) := Sinput.Source (Loc);
1480 Display_Name_Of_Project := Name_Find;
1484 From_Ext : Extension_Origin := None;
1487 -- Extending_All is always propagated
1489 if From_Extended = Extending_All or else Extends_All then
1490 From_Ext := Extending_All;
1492 -- Otherwise, From_Extended is set to Extending_Single if the
1493 -- current project is an extending project.
1496 From_Ext := Extending_Simple;
1499 Post_Parse_Context_Clause
1500 (In_Tree => In_Tree,
1501 Context_Clause => First_With,
1502 Limited_Withs => False,
1503 Imported_Projects => Imported_Projects,
1504 Project_Directory => Project_Directory,
1505 From_Extended => From_Ext,
1506 In_Limited => In_Limited,
1507 Packages_To_Check => Packages_To_Check,
1509 Current_Dir => Current_Dir,
1510 Is_Config_File => Is_Config_File,
1512 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1515 if not Is_Config_File then
1517 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1518 Tree_Private_Part.Projects_Htable.Get_First
1519 (In_Tree.Projects_HT);
1520 Project_Name : Name_Id := Name_And_Node.Name;
1523 -- Check if we already have a project with this name
1525 while Project_Name /= No_Name
1526 and then Project_Name /= Name_Of_Project
1529 Tree_Private_Part.Projects_Htable.Get_Next
1530 (In_Tree.Projects_HT);
1531 Project_Name := Name_And_Node.Name;
1534 -- Report an error if we already have a project with this name
1536 if Project_Name /= No_Name then
1538 Error_Msg_Name_1 := Project_Name;
1540 (Env.Flags, "duplicate project name %%",
1541 Location_Of (Project, In_Tree));
1543 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1546 "\already in %%", Location_Of (Project, In_Tree));
1554 Expect (Tok_String_Literal, "literal string");
1556 if Token = Tok_String_Literal then
1557 Set_Extended_Project_Path_Of
1560 Path_Name_Type (Token_Name));
1563 Original_Path_Name : constant String :=
1564 Get_Name_String (Token_Name);
1566 Extended_Project_Path_Name_Id : Path_Name_Type;
1571 Project_File_Name => Original_Path_Name,
1572 Directory => Get_Name_String (Project_Directory),
1573 Path => Extended_Project_Path_Name_Id);
1575 if Extended_Project_Path_Name_Id = No_Path then
1577 -- We could not find the project file to extend
1579 Error_Msg_Name_1 := Token_Name;
1581 Error_Msg (Env.Flags, "unknown project file: %%", Token_Ptr);
1583 -- If not in the main project file, display the import path
1585 if Project_Stack.Last > 1 then
1588 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1589 Error_Msg (Env.Flags, "\extended by %%", Token_Ptr);
1591 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1594 (Project_Stack.Table (Index).Path_Name);
1595 Error_Msg (Env.Flags, "\imported by %%", Token_Ptr);
1601 From_Ext : Extension_Origin := None;
1604 if From_Extended = Extending_All or else Extends_All then
1605 From_Ext := Extending_All;
1608 Parse_Single_Project
1609 (In_Tree => In_Tree,
1610 Project => Extended_Project,
1611 Extends_All => Extends_All,
1612 Path_Name_Id => Extended_Project_Path_Name_Id,
1614 From_Extended => From_Ext,
1615 In_Limited => In_Limited,
1616 Packages_To_Check => Packages_To_Check,
1618 Current_Dir => Current_Dir,
1619 Is_Config_File => Is_Config_File,
1623 if Present (Extended_Project) then
1625 -- A project that extends an extending-all project is
1626 -- also an extending-all project.
1628 if Is_Extending_All (Extended_Project, In_Tree) then
1629 Set_Is_Extending_All (Project, In_Tree);
1632 -- An abstract project can only extend an abstract
1633 -- project. Otherwise we may have an abstract project
1634 -- with sources if it inherits sources from the project
1637 if Project_Qualifier_Of (Project, In_Tree) = Dry and then
1638 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1641 (Env.Flags, "an abstract project can only extend " &
1642 "another abstract project",
1643 Qualifier_Location);
1649 Scan (In_Tree); -- past the extended project path
1653 Check_Extending_All_Imports (Env.Flags, In_Tree, Project);
1654 Check_Aggregate_Imports (Env.Flags, In_Tree, Project);
1656 -- Check that a project with a name including a dot either imports
1657 -- or extends the project whose name precedes the last dot.
1659 if Name_Of_Project /= No_Name then
1660 Get_Name_String (Name_Of_Project);
1666 -- Look for the last dot
1668 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1669 Name_Len := Name_Len - 1;
1672 -- If a dot was found, check if parent project is imported or extended
1674 if Name_Len > 0 then
1675 Name_Len := Name_Len - 1;
1678 Parent_Name : constant Name_Id := Name_Find;
1679 Parent_Found : Boolean := False;
1680 Parent_Node : Project_Node_Id := Empty_Node;
1681 With_Clause : Project_Node_Id :=
1682 First_With_Clause_Of (Project, In_Tree);
1683 Imp_Proj_Name : Name_Id;
1686 -- If there is an extended project, check its name
1688 if Present (Extended_Project) then
1689 Parent_Node := Extended_Project;
1691 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1694 -- If the parent project is not the extended project,
1695 -- check each imported project until we find the parent project.
1698 while not Parent_Found and then Present (With_Clause) loop
1699 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1700 Extension_Loop : while Present (Parent_Node) loop
1701 Imp_Proj_Name := Name_Of (Parent_Node, In_Tree);
1702 Parent_Found := Imp_Proj_Name = Parent_Name;
1703 exit Imported_Loop when Parent_Found;
1706 (Project_Declaration_Of (Parent_Node, In_Tree),
1708 end loop Extension_Loop;
1710 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1711 end loop Imported_Loop;
1713 if Parent_Found then
1714 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1717 -- If the parent project was not found, report an error
1719 Error_Msg_Name_1 := Name_Of_Project;
1720 Error_Msg_Name_2 := Parent_Name;
1721 Error_Msg (Env.Flags,
1722 "project %% does not import or extend project %%",
1723 Location_Of (Project, In_Tree));
1728 Expect (Tok_Is, "IS");
1729 Set_End_Of_Line (Project);
1730 Set_Previous_Line_Node (Project);
1731 Set_Next_End_Node (Project);
1734 Project_Declaration : Project_Node_Id := Empty_Node;
1737 -- No need to Scan past "is", Prj.Dect.Parse will do it
1740 (In_Tree => In_Tree,
1741 Declarations => Project_Declaration,
1742 Current_Project => Project,
1743 Extends => Extended_Project,
1744 Packages_To_Check => Packages_To_Check,
1745 Is_Config_File => Is_Config_File,
1746 Flags => Env.Flags);
1747 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1749 if Present (Extended_Project)
1750 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1752 Set_Extending_Project_Of
1753 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1758 Expect (Tok_End, "END");
1759 Remove_Next_End_Node;
1761 -- Skip "end" if present
1763 if Token = Tok_End then
1771 -- Store the name following "end" in the Buffer. The name may be made of
1772 -- several simple names.
1775 Expect (Tok_Identifier, "identifier");
1777 -- If we don't have an identifier, clear the buffer before exiting to
1778 -- avoid checking the name.
1780 if Token /= Tok_Identifier then
1785 -- Add the identifier to the Buffer
1786 Get_Name_String (Token_Name);
1787 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1789 -- Scan past the identifier
1792 exit when Token /= Tok_Dot;
1793 Add_To_Buffer (".", Buffer, Buffer_Last);
1797 -- If we have a valid name, check if it is the name of the project
1799 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1800 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1801 Get_Name_String (Name_Of (Project, In_Tree))
1803 -- Invalid name: report an error
1805 Error_Msg (Env.Flags, "expected """ &
1806 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1811 Expect (Tok_Semicolon, "`;`");
1813 -- Check that there is no more text following the end of the project
1816 if Token = Tok_Semicolon then
1817 Set_Previous_End_Node (Project);
1820 if Token /= Tok_EOF then
1823 "unexpected text following end of project", Token_Ptr);
1827 if not Duplicated and then Name_Of_Project /= No_Name then
1829 -- Add the name of the project to the hash table, so that we can
1830 -- check that no other subsequent project will have the same name.
1832 Tree_Private_Part.Projects_Htable.Set
1833 (T => In_Tree.Projects_HT,
1834 K => Name_Of_Project,
1835 E => (Name => Name_Of_Project,
1836 Display_Name => Display_Name_Of_Project,
1838 Canonical_Path => Canonical_Path_Name,
1839 Extended => Extended,
1840 Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
1844 From_Ext : Extension_Origin := None;
1847 -- Extending_All is always propagated
1849 if From_Extended = Extending_All or else Extends_All then
1850 From_Ext := Extending_All;
1852 -- Otherwise, From_Extended is set to Extending_Single if the
1853 -- current project is an extending project.
1856 From_Ext := Extending_Simple;
1859 Post_Parse_Context_Clause
1860 (In_Tree => In_Tree,
1861 Context_Clause => First_With,
1862 Limited_Withs => True,
1863 Imported_Projects => Imported_Projects,
1864 Project_Directory => Project_Directory,
1865 From_Extended => From_Ext,
1866 In_Limited => In_Limited,
1867 Packages_To_Check => Packages_To_Check,
1869 Current_Dir => Current_Dir,
1870 Is_Config_File => Is_Config_File,
1872 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1875 -- Restore the scan state, in case we are not the main project
1877 Restore_Project_Scan_State (Project_Scan_State);
1879 -- And remove the project from the project stack
1881 Project_Stack.Decrement_Last;
1883 -- Indicate if there are unkept comments
1885 Tree.Set_Project_File_Includes_Unkept_Comments
1888 To => Tree.There_Are_Unkept_Comments);
1890 -- And restore the comment state that was saved
1892 Tree.Restore_And_Free (Project_Comment_State);
1894 Debug_Decrease_Indent;
1895 end Parse_Single_Project;
1897 -----------------------
1898 -- Project_Name_From --
1899 -----------------------
1901 function Project_Name_From
1902 (Path_Name : String;
1903 Is_Config_File : Boolean) return Name_Id
1905 Canonical : String (1 .. Path_Name'Length) := Path_Name;
1906 First : Natural := Canonical'Last;
1907 Last : Natural := First;
1911 if Current_Verbosity = High then
1912 Debug_Output ("Project_Name_From (""" & Canonical & """)");
1915 -- If the path name is empty, return No_Name to indicate failure
1921 Canonical_Case_File_Name (Canonical);
1923 -- Look for the last dot in the path name
1927 Canonical (First) /= '.'
1932 -- If we have a dot, check that it is followed by the correct extension
1934 if First > 0 and then Canonical (First) = '.' then
1935 if (not Is_Config_File
1936 and then Canonical (First .. Last) = Project_File_Extension
1937 and then First /= 1)
1941 Canonical (First .. Last) = Config_Project_File_Extension
1942 and then First /= 1)
1944 -- Look for the last directory separator, if any
1949 and then Canonical (First) /= '/'
1950 and then Canonical (First) /= Dir_Sep
1956 -- Not the correct extension, return No_Name to indicate failure
1961 -- If no dot in the path name, return No_Name to indicate failure
1969 -- If the extension is the file name, return No_Name to indicate failure
1971 if First > Last then
1975 -- Put the name in lower case into Name_Buffer
1977 Name_Len := Last - First + 1;
1978 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
1982 -- Check if it is a well formed project name. Return No_Name if it is
1986 if not Is_Letter (Name_Buffer (Index)) then
1993 exit when Index >= Name_Len;
1995 if Name_Buffer (Index) = '_' then
1996 if Name_Buffer (Index + 1) = '_' then
2001 exit when Name_Buffer (Index) = '-';
2003 if Name_Buffer (Index) /= '_'
2004 and then not Is_Alphanumeric (Name_Buffer (Index))
2012 if Index >= Name_Len then
2013 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
2015 -- All checks have succeeded. Return name in Name_Buffer
2023 elsif Name_Buffer (Index) = '-' then
2027 end Project_Name_From;