1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2013, 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 Atree
; use Atree
;
27 with Err_Vars
; use Err_Vars
;
29 with Osint
; use Osint
;
30 with Output
; use Output
;
31 with Prj
.Com
; use Prj
.Com
;
33 with Prj
.Env
; use Prj
.Env
;
34 with Prj
.Err
; use Prj
.Err
;
35 with Sinput
; use Sinput
;
36 with Sinput
.P
; use Sinput
.P
;
40 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
41 with Ada
.Exceptions
; use Ada
.Exceptions
;
43 with GNAT
.HTable
; use GNAT
.HTable
;
45 package body Prj
.Part
is
47 Buffer
: String_Access
;
48 Buffer_Last
: Natural := 0;
50 Dir_Sep
: Character renames GNAT
.OS_Lib
.Directory_Separator
;
52 ------------------------------------
53 -- Local Packages and Subprograms --
54 ------------------------------------
56 type With_Id
is new Nat
;
57 No_With
: constant With_Id
:= 0;
59 type With_Record
is record
60 Path
: Path_Name_Type
;
61 Location
: Source_Ptr
;
62 Limited_With
: Boolean;
63 Node
: Project_Node_Id
;
66 -- Information about an imported project, to be put in table Withs below
68 package Withs
is new Table
.Table
69 (Table_Component_Type
=> With_Record
,
70 Table_Index_Type
=> With_Id
,
73 Table_Increment
=> 100,
74 Table_Name
=> "Prj.Part.Withs");
75 -- Table used to store temporarily paths and locations of imported
76 -- projects. These imported projects will be effectively parsed later: just
77 -- before parsing the current project for the non limited withed projects,
78 -- after getting its name; after complete parsing of the current project
79 -- for the limited withed projects.
81 type Names_And_Id
is record
82 Path_Name
: Path_Name_Type
;
83 Canonical_Path_Name
: Path_Name_Type
;
85 Limited_With
: Boolean;
88 package Project_Stack
is new Table
.Table
89 (Table_Component_Type
=> Names_And_Id
,
90 Table_Index_Type
=> Nat
,
93 Table_Increment
=> 100,
94 Table_Name
=> "Prj.Part.Project_Stack");
95 -- This table is used to detect circular dependencies
96 -- for imported and extended projects and to get the project ids of
97 -- limited imported projects when there is a circularity with at least
98 -- one limited imported project file.
100 package Virtual_Hash
is new GNAT
.HTable
.Simple_HTable
101 (Header_Num
=> Header_Num
,
102 Element
=> Project_Node_Id
,
103 No_Element
=> Project_Node_High_Bound
,
104 Key
=> Project_Node_Id
,
105 Hash
=> Prj
.Tree
.Hash
,
107 -- Hash table to store the node ids of projects for which a virtual
108 -- extending project need to be created. The corresponding value is the
109 -- head of a list of WITH clauses corresponding to the context of the
110 -- enclosing EXTEND ALL projects. Note: Default_Element is Project_Node_
111 -- High_Bound because we want Empty_Node to be a possible value.
113 package Processed_Hash
is new GNAT
.HTable
.Simple_HTable
114 (Header_Num
=> Header_Num
,
117 Key
=> Project_Node_Id
,
118 Hash
=> Prj
.Tree
.Hash
,
120 -- Hash table to store the project process when looking for project that
121 -- need to have a virtual extending project, to avoid processing the same
124 function Has_Circular_Dependencies
125 (Flags
: Processing_Flags
;
126 Normed_Path_Name
: Path_Name_Type
;
127 Canonical_Path_Name
: Path_Name_Type
) return Boolean;
128 -- Check for a circular dependency in the loaded project.
129 -- Generates an error message in such a case.
131 procedure Read_Project_Qualifier
132 (Flags
: Processing_Flags
;
133 In_Tree
: Project_Node_Tree_Ref
;
134 Is_Config_File
: Boolean;
135 Qualifier_Location
: out Source_Ptr
;
136 Project
: Project_Node_Id
);
137 -- Check if there is a qualifier before the reserved word "project"
139 -- Hash table to cache project path to avoid looking for them on the path
141 procedure Check_Extending_All_Imports
142 (Flags
: Processing_Flags
;
143 In_Tree
: Project_Node_Tree_Ref
;
144 Project
: Project_Node_Id
);
145 -- Check that a non extending-all project does not import an
146 -- extending-all project.
148 procedure Check_Aggregate_Imports
149 (Flags
: Processing_Flags
;
150 In_Tree
: Project_Node_Tree_Ref
;
151 Project
: Project_Node_Id
);
152 -- Check that an aggregate project only imports abstract projects
154 procedure Create_Virtual_Extending_Project
155 (For_Project
: Project_Node_Id
;
156 Main_Project
: Project_Node_Id
;
157 Extension_Withs
: Project_Node_Id
;
158 In_Tree
: Project_Node_Tree_Ref
);
159 -- Create a virtual extending project of For_Project. Main_Project is
160 -- the extending all project. Extension_Withs is the head of a WITH clause
161 -- list to be added to the created virtual project.
163 -- The String_Value_Of is not set for the automatically added with
164 -- clause and keeps the default value of No_Name. This enables Prj.PP
165 -- to skip these automatically added with clauses to be processed.
167 procedure Look_For_Virtual_Projects_For
168 (Proj
: Project_Node_Id
;
169 In_Tree
: Project_Node_Tree_Ref
;
170 Potentially_Virtual
: Boolean);
171 -- Look for projects that need to have a virtual extending project.
172 -- This procedure is recursive. If called with Potentially_Virtual set to
173 -- True, then Proj may need an virtual extending project; otherwise it
174 -- does not (because it is already extended), but other projects that it
175 -- imports may need to be virtually extended.
177 type Extension_Origin
is (None
, Extending_Simple
, Extending_All
);
178 -- Type of parameter From_Extended for procedures Parse_Single_Project and
179 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
180 -- tree rooted at an extending all project.
182 procedure Parse_Single_Project
183 (In_Tree
: Project_Node_Tree_Ref
;
184 Project
: out Project_Node_Id
;
185 Extends_All
: out Boolean;
186 Path_Name_Id
: Path_Name_Type
;
188 From_Extended
: Extension_Origin
;
189 In_Limited
: Boolean;
190 Packages_To_Check
: String_List_Access
;
192 Current_Dir
: String;
193 Is_Config_File
: Boolean;
194 Env
: in out Environment
;
195 Implicit_Project
: Boolean := False);
196 -- Parse a project file. This is a recursive procedure: it calls itself for
197 -- imported and extended projects. When From_Extended is not None, if the
198 -- project has already been parsed and is an extended project A, return the
199 -- ultimate (not extended) project that extends A. When In_Limited is True,
200 -- the importing path includes at least one "limited with". When parsing
201 -- configuration projects, do not allow a depth > 1.
203 -- Is_Config_File should be set to True if the project represents a config
204 -- file (.cgpr) since some specific checks apply.
206 -- If Implicit_Project is True, change the Directory of the project node
207 -- to be the Current_Dir. Recursive calls to Parse_Single_Project are
208 -- always done with the default False value for Implicit_Project.
210 procedure Pre_Parse_Context_Clause
211 (In_Tree
: Project_Node_Tree_Ref
;
212 Context_Clause
: out With_Id
;
213 Is_Config_File
: Boolean;
214 Flags
: Processing_Flags
);
215 -- Parse the context clause of a project. Store the paths and locations of
216 -- the imported projects in table Withs. Does nothing if there is no
217 -- context clause (if the current token is not "with" or "limited" followed
219 -- Is_Config_File should be set to True if the project represents a config
220 -- file (.cgpr) since some specific checks apply.
222 procedure Post_Parse_Context_Clause
223 (Context_Clause
: With_Id
;
224 In_Tree
: Project_Node_Tree_Ref
;
225 In_Limited
: Boolean;
226 Limited_Withs
: Boolean;
227 Imported_Projects
: in out Project_Node_Id
;
228 Project_Directory
: Path_Name_Type
;
229 From_Extended
: Extension_Origin
;
230 Packages_To_Check
: String_List_Access
;
232 Current_Dir
: String;
233 Is_Config_File
: Boolean;
234 Env
: in out Environment
);
235 -- Parse the imported projects that have been stored in table Withs, if
236 -- any. From_Extended is used for the call to Parse_Single_Project below.
238 -- When In_Limited is True, the importing path includes at least one
239 -- "limited with". When Limited_Withs is False, only non limited withed
240 -- projects are parsed. When Limited_Withs is True, only limited withed
241 -- projects are parsed.
243 -- Is_Config_File should be set to True if the project represents a config
244 -- file (.cgpr) since some specific checks apply.
246 function Project_Name_From
248 Is_Config_File
: Boolean) return Name_Id
;
249 -- Returns the name of the project that corresponds to its path name.
250 -- Returns No_Name if the path name is invalid, because the corresponding
251 -- project name does not have the syntax of an ada identifier.
253 function Copy_With_Clause
254 (With_Clause
: Project_Node_Id
;
255 In_Tree
: Project_Node_Tree_Ref
;
256 Next_Clause
: Project_Node_Id
) return Project_Node_Id
;
257 -- Return a copy of With_Clause in In_Tree, whose Next_With_Clause is the
260 ----------------------
261 -- Copy_With_Clause --
262 ----------------------
264 function Copy_With_Clause
265 (With_Clause
: Project_Node_Id
;
266 In_Tree
: Project_Node_Tree_Ref
;
267 Next_Clause
: Project_Node_Id
) return Project_Node_Id
269 New_With_Clause
: constant Project_Node_Id
:=
270 Default_Project_Node
(In_Tree
, N_With_Clause
);
272 Set_Name_Of
(New_With_Clause
, In_Tree
,
273 Name_Of
(With_Clause
, In_Tree
));
274 Set_Path_Name_Of
(New_With_Clause
, In_Tree
,
275 Path_Name_Of
(With_Clause
, In_Tree
));
276 Set_Project_Node_Of
(New_With_Clause
, In_Tree
,
277 Project_Node_Of
(With_Clause
, In_Tree
));
278 Set_Next_With_Clause_Of
(New_With_Clause
, In_Tree
, Next_Clause
);
280 return New_With_Clause
;
281 end Copy_With_Clause
;
283 --------------------------------------
284 -- Create_Virtual_Extending_Project --
285 --------------------------------------
287 procedure Create_Virtual_Extending_Project
288 (For_Project
: Project_Node_Id
;
289 Main_Project
: Project_Node_Id
;
290 Extension_Withs
: Project_Node_Id
;
291 In_Tree
: Project_Node_Tree_Ref
)
294 Virtual_Name
: constant String :=
296 Get_Name_String
(Name_Of
(For_Project
, In_Tree
));
297 -- The name of the virtual extending project
299 Virtual_Name_Id
: Name_Id
;
300 -- Virtual extending project name id
302 Virtual_Path_Id
: Path_Name_Type
;
303 -- Fake path name of the virtual extending project. The directory is
304 -- the same directory as the extending all project.
306 -- The source of the virtual extending project is something like:
308 -- project V$<project name> extends <project path> is
310 -- for Source_Dirs use ();
312 -- end V$<project name>;
314 -- The project directory cannot be specified during parsing; it will be
315 -- put directly in the virtual extending project data during processing.
317 -- Nodes that made up the virtual extending project
319 Virtual_Project
: Project_Node_Id
;
320 With_Clause
: constant Project_Node_Id
:=
322 (In_Tree
, N_With_Clause
);
323 Project_Declaration
: Project_Node_Id
;
324 Source_Dirs_Declaration
: constant Project_Node_Id
:=
326 (In_Tree
, N_Declarative_Item
);
327 Source_Dirs_Attribute
: constant Project_Node_Id
:=
329 (In_Tree
, N_Attribute_Declaration
, List
);
330 Source_Dirs_Expression
: constant Project_Node_Id
:=
332 (In_Tree
, N_Expression
, List
);
333 Source_Dirs_Term
: constant Project_Node_Id
:=
335 (In_Tree
, N_Term
, List
);
336 Source_Dirs_List
: constant Project_Node_Id
:=
338 (In_Tree
, N_Literal_String_List
, List
);
341 -- Get the virtual path name
343 Get_Name_String
(Path_Name_Of
(Main_Project
, In_Tree
));
346 and then Name_Buffer
(Name_Len
) /= Directory_Separator
347 and then Name_Buffer
(Name_Len
) /= '/'
349 Name_Len
:= Name_Len
- 1;
352 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Virtual_Name
'Length) :=
354 Name_Len
:= Name_Len
+ Virtual_Name
'Length;
355 Virtual_Path_Id
:= Name_Find
;
357 -- Get the virtual name id
359 Name_Len
:= Virtual_Name
'Length;
360 Name_Buffer
(1 .. Name_Len
) := Virtual_Name
;
361 Virtual_Name_Id
:= Name_Find
;
363 Virtual_Project
:= Create_Project
365 Name
=> Virtual_Name_Id
,
366 Full_Path
=> Virtual_Path_Id
,
367 Is_Config_File
=> False);
369 Project_Declaration
:= Project_Declaration_Of
(Virtual_Project
, In_Tree
);
371 -- Add a WITH clause to the main project to import the newly created
372 -- virtual extending project.
374 Set_Name_Of
(With_Clause
, In_Tree
, Virtual_Name_Id
);
375 Set_Path_Name_Of
(With_Clause
, In_Tree
, Virtual_Path_Id
);
376 Set_Project_Node_Of
(With_Clause
, In_Tree
, Virtual_Project
);
377 Set_Next_With_Clause_Of
378 (With_Clause
, In_Tree
, First_With_Clause_Of
(Main_Project
, In_Tree
));
379 Set_First_With_Clause_Of
(Main_Project
, In_Tree
, With_Clause
);
381 -- Copy with clauses for projects imported by the extending-all project
384 Org_With_Clause
: Project_Node_Id
:= Extension_Withs
;
385 New_With_Clause
: Project_Node_Id
:= Empty_Node
;
388 while Present
(Org_With_Clause
) loop
390 Copy_With_Clause
(Org_With_Clause
, In_Tree
, New_With_Clause
);
392 Org_With_Clause
:= Next_With_Clause_Of
(Org_With_Clause
, In_Tree
);
395 Set_First_With_Clause_Of
(Virtual_Project
, In_Tree
, New_With_Clause
);
398 -- Virtual project node
401 (Virtual_Project
, In_Tree
, Location_Of
(Main_Project
, In_Tree
));
402 Set_Extended_Project_Path_Of
403 (Virtual_Project
, In_Tree
, Path_Name_Of
(For_Project
, In_Tree
));
405 -- Project declaration
407 Set_First_Declarative_Item_Of
408 (Project_Declaration
, In_Tree
, Source_Dirs_Declaration
);
409 Set_Extended_Project_Of
(Project_Declaration
, In_Tree
, For_Project
);
411 -- Source_Dirs declaration
413 Set_Current_Item_Node
414 (Source_Dirs_Declaration
, In_Tree
, Source_Dirs_Attribute
);
416 -- Source_Dirs attribute
418 Set_Name_Of
(Source_Dirs_Attribute
, In_Tree
, Snames
.Name_Source_Dirs
);
420 (Source_Dirs_Attribute
, In_Tree
, Source_Dirs_Expression
);
422 -- Source_Dirs expression
424 Set_First_Term
(Source_Dirs_Expression
, In_Tree
, Source_Dirs_Term
);
428 Set_Current_Term
(Source_Dirs_Term
, In_Tree
, Source_Dirs_List
);
430 -- Source_Dirs empty list: nothing to do
431 end Create_Virtual_Extending_Project
;
433 -----------------------------------
434 -- Look_For_Virtual_Projects_For --
435 -----------------------------------
437 Extension_Withs
: Project_Node_Id
;
438 -- Head of the current EXTENDS ALL imports list. When creating virtual
439 -- projects for an EXTENDS ALL, we import in each virtual project all
440 -- of the projects that appear in WITH clauses of the extending projects.
441 -- This ensures that virtual projects share a consistent environment (in
442 -- particular if a project imported by one of the extending projects
443 -- replaces some runtime units).
445 procedure Look_For_Virtual_Projects_For
446 (Proj
: Project_Node_Id
;
447 In_Tree
: Project_Node_Tree_Ref
;
448 Potentially_Virtual
: Boolean)
450 Declaration
: Project_Node_Id
:= Empty_Node
;
451 -- Node for the project declaration of Proj
453 With_Clause
: Project_Node_Id
:= Empty_Node
;
454 -- Node for a with clause of Proj
456 Imported
: Project_Node_Id
:= Empty_Node
;
457 -- Node for a project imported by Proj
459 Extended
: Project_Node_Id
:= Empty_Node
;
460 -- Node for the eventual project extended by Proj
462 Extends_All
: Boolean := False;
463 -- Set True if Proj is an EXTENDS ALL project
465 Saved_Extension_Withs
: constant Project_Node_Id
:= Extension_Withs
;
468 -- Nothing to do if Proj is undefined or has already been processed
470 if Present
(Proj
) and then not Processed_Hash
.Get
(Proj
) then
472 -- Make sure the project will not be processed again
474 Processed_Hash
.Set
(Proj
, True);
476 Declaration
:= Project_Declaration_Of
(Proj
, In_Tree
);
478 if Present
(Declaration
) then
479 Extended
:= Extended_Project_Of
(Declaration
, In_Tree
);
480 Extends_All
:= Is_Extending_All
(Proj
, In_Tree
);
483 -- If this is a project that may need a virtual extending project
484 -- and it is not itself an extending project, put it in the list.
486 if Potentially_Virtual
and then No
(Extended
) then
487 Virtual_Hash
.Set
(Proj
, Extension_Withs
);
490 -- Now check the projects it imports
492 With_Clause
:= First_With_Clause_Of
(Proj
, In_Tree
);
493 while Present
(With_Clause
) loop
494 Imported
:= Project_Node_Of
(With_Clause
, In_Tree
);
496 if Present
(Imported
) then
497 Look_For_Virtual_Projects_For
498 (Imported
, In_Tree
, Potentially_Virtual
=> True);
503 -- This is an EXTENDS ALL project: prepend each of its WITH
504 -- clauses to the currently active list of extension deps.
507 Copy_With_Clause
(With_Clause
, In_Tree
, Extension_Withs
);
510 With_Clause
:= Next_With_Clause_Of
(With_Clause
, In_Tree
);
513 -- Check also the eventual project extended by Proj. As this project
514 -- is already extended, call recursively with Potentially_Virtual
517 Look_For_Virtual_Projects_For
518 (Extended
, In_Tree
, Potentially_Virtual
=> False);
520 Extension_Withs
:= Saved_Extension_Withs
;
522 end Look_For_Virtual_Projects_For
;
529 (In_Tree
: Project_Node_Tree_Ref
;
530 Project
: out Project_Node_Id
;
531 Project_File_Name
: String;
532 Errout_Handling
: Errout_Mode
:= Always_Finalize
;
533 Packages_To_Check
: String_List_Access
;
534 Store_Comments
: Boolean := False;
535 Current_Directory
: String := "";
536 Is_Config_File
: Boolean;
537 Env
: in out Prj
.Tree
.Environment
;
538 Target_Name
: String := "";
539 Implicit_Project
: Boolean := False)
542 pragma Warnings
(Off
, Dummy
);
544 Real_Project_File_Name
: String_Access
:=
545 Osint
.To_Canonical_File_Spec
547 Path_Name_Id
: Path_Name_Type
;
550 In_Tree
.Incomplete_With
:= False;
552 if not Is_Initialized
(Env
.Project_Path
) then
553 Prj
.Env
.Initialize_Default_Project_Path
554 (Env
.Project_Path
, Target_Name
);
557 if Real_Project_File_Name
= null then
558 Real_Project_File_Name
:= new String'(Project_File_Name);
561 Project := Empty_Node;
563 Find_Project (Env.Project_Path,
564 Project_File_Name => Real_Project_File_Name.all,
565 Directory => Current_Directory,
566 Path => Path_Name_Id);
567 Free (Real_Project_File_Name);
569 if Errout_Handling /= Never_Finalize then
573 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
574 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
576 if Path_Name_Id = No_Path then
580 Get_Path (Env.Project_Path, Path => P);
587 Project := Empty_Node;
592 -- Parse the main project file
598 Extends_All => Dummy,
599 Path_Name_Id => Path_Name_Id,
601 From_Extended => None,
603 Packages_To_Check => Packages_To_Check,
605 Current_Dir => Current_Directory,
606 Is_Config_File => Is_Config_File,
608 Implicit_Project => Implicit_Project);
611 when Types.Unrecoverable_Error =>
613 -- Unrecoverable_Error is raised when a line is too long.
614 -- A meaningful error message will be displayed later.
616 Project := Empty_Node;
619 -- If Project is an extending-all project, create the eventual
620 -- virtual extending projects and check that there are no illegally
621 -- imported projects.
624 and then Is_Extending_All (Project, In_Tree)
626 -- First look for projects that potentially need a virtual
627 -- extending project.
630 Processed_Hash.Reset;
632 -- Mark the extending all project as processed, to avoid checking
633 -- the imported projects in case of a "limited with" on this
634 -- extending all project.
636 Processed_Hash.Set (Project, True);
639 Declaration : constant Project_Node_Id :=
640 Project_Declaration_Of (Project, In_Tree);
642 Extension_Withs := First_With_Clause_Of (Project, In_Tree);
643 Look_For_Virtual_Projects_For
644 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
645 Potentially_Virtual => False);
648 -- Now, check the projects directly imported by the main project.
649 -- Remove from the potentially virtual any project extended by one
650 -- of these imported projects.
653 With_Clause : Project_Node_Id;
654 Imported : Project_Node_Id := Empty_Node;
655 Declaration : Project_Node_Id := Empty_Node;
658 With_Clause := First_With_Clause_Of (Project, In_Tree);
659 while Present (With_Clause) loop
660 Imported := Project_Node_Of (With_Clause, In_Tree);
662 if Present (Imported) then
663 Declaration := Project_Declaration_Of (Imported, In_Tree);
665 if Extended_Project_Of (Declaration, In_Tree) /=
670 Extended_Project_Of (Declaration, In_Tree);
671 exit when No (Imported);
672 Virtual_Hash.Remove (Imported);
674 Project_Declaration_Of (Imported, In_Tree);
679 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
683 -- Now create all the virtual extending projects
686 Proj : Project_Node_Id := Empty_Node;
687 Withs : Project_Node_Id;
689 Virtual_Hash.Get_First (Proj, Withs);
690 while Withs /= Project_Node_High_Bound loop
691 Create_Virtual_Extending_Project
692 (Proj, Project, Withs, In_Tree);
693 Virtual_Hash.Get_Next (Proj, Withs);
698 -- If there were any kind of error during the parsing, serious
699 -- or not, then the parsing fails.
701 if Total_Errors_Detected > 0 then
702 Project := Empty_Node;
705 case Errout_Handling is
706 when Always_Finalize =>
709 -- Reinitialize to avoid duplicate warnings later on
712 when Finalize_If_Error =>
718 when Never_Finalize =>
727 Write_Line (Exception_Information (X));
728 Write_Str ("Exception ");
729 Write_Str (Exception_Name (X));
730 Write_Line (" raised, while processing project file");
731 Project := Empty_Node;
734 ------------------------------
735 -- Pre_Parse_Context_Clause --
736 ------------------------------
738 procedure Pre_Parse_Context_Clause
739 (In_Tree : Project_Node_Tree_Ref;
740 Context_Clause : out With_Id;
741 Is_Config_File : Boolean;
742 Flags : Processing_Flags)
744 Current_With_Clause : With_Id := No_With;
745 Limited_With : Boolean := False;
746 Current_With : With_Record;
747 Current_With_Node : Project_Node_Id := Empty_Node;
750 -- Assume no context clause
752 Context_Clause := No_With;
755 -- If Token is not WITH or LIMITED, there is no context clause, or we
756 -- have exhausted the with clauses.
758 while Token = Tok_With or else Token = Tok_Limited loop
760 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
761 Limited_With := Token = Tok_Limited;
763 if Is_Config_File then
766 "configuration project cannot import " &
767 "other configuration projects",
772 Scan (In_Tree); -- past LIMITED
773 Expect (Tok_With, "WITH");
774 exit With_Loop when Token /= Tok_With;
779 Scan (In_Tree); -- past WITH or ","
781 Expect (Tok_String_Literal, "literal string");
783 if Token /= Tok_String_Literal then
787 -- Store path and location in table Withs
790 (Path => Path_Name_Type (Token_Name),
791 Location => Token_Ptr,
792 Limited_With => Limited_With,
793 Node => Current_With_Node,
796 Withs.Increment_Last;
797 Withs.Table (Withs.Last) := Current_With;
799 if Current_With_Clause = No_With then
800 Context_Clause := Withs.Last;
803 Withs.Table (Current_With_Clause).Next := Withs.Last;
806 Current_With_Clause := Withs.Last;
810 if Token = Tok_Semicolon then
811 Set_End_Of_Line (Current_With_Node);
812 Set_Previous_Line_Node (Current_With_Node);
814 -- End of (possibly multiple) with clause;
816 Scan (In_Tree); -- past semicolon
819 elsif Token = Tok_Comma then
820 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
823 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
829 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
832 end Pre_Parse_Context_Clause;
834 -------------------------------
835 -- Post_Parse_Context_Clause --
836 -------------------------------
838 procedure Post_Parse_Context_Clause
839 (Context_Clause : With_Id;
840 In_Tree : Project_Node_Tree_Ref;
841 In_Limited : Boolean;
842 Limited_Withs : Boolean;
843 Imported_Projects : in out Project_Node_Id;
844 Project_Directory : Path_Name_Type;
845 From_Extended : Extension_Origin;
846 Packages_To_Check : String_List_Access;
848 Current_Dir : String;
849 Is_Config_File : Boolean;
850 Env : in out Environment)
852 Current_With_Clause : With_Id := Context_Clause;
854 Current_Project : Project_Node_Id := Imported_Projects;
855 Previous_Project : Project_Node_Id := Empty_Node;
856 Next_Project : Project_Node_Id := Empty_Node;
858 Project_Directory_Path : constant String :=
859 Get_Name_String (Project_Directory);
861 Current_With : With_Record;
862 Extends_All : Boolean := False;
863 Imported_Path_Name_Id : Path_Name_Type;
866 -- Set Current_Project to the last project in the current list, if the
867 -- list is not empty.
869 if Present (Current_Project) then
871 Present (Next_With_Clause_Of (Current_Project, In_Tree))
873 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
877 while Current_With_Clause /= No_With loop
878 Current_With := Withs.Table (Current_With_Clause);
879 Current_With_Clause := Current_With.Next;
881 if Limited_Withs = Current_With.Limited_With then
884 Project_File_Name => Get_Name_String (Current_With.Path),
885 Directory => Project_Directory_Path,
886 Path => Imported_Path_Name_Id);
888 if Imported_Path_Name_Id = No_Path then
889 if Env.Flags.Ignore_Missing_With then
890 In_Tree.Incomplete_With := True;
893 -- The project file cannot be found
895 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
897 (Env.Flags, "unknown project file: {",
898 Current_With.Location);
900 -- If this is not imported by the main project file, display
903 if Project_Stack.Last > 1 then
904 for Index in reverse 1 .. Project_Stack.Last loop
907 (Project_Stack.Table (Index).Path_Name);
909 (Env.Flags, "\imported by {", Current_With.Location);
918 Resolved_Path : constant String :=
920 (Get_Name_String (Imported_Path_Name_Id),
921 Directory => Current_Dir,
923 Opt.Follow_Links_For_Files,
924 Case_Sensitive => True);
926 Withed_Project : Project_Node_Id := Empty_Node;
929 Previous_Project := Current_Project;
931 if No (Current_Project) then
933 -- First with clause of the context clause
935 Current_Project := Current_With.Node;
936 Imported_Projects := Current_Project;
939 Next_Project := Current_With.Node;
940 Set_Next_With_Clause_Of
941 (Current_Project, In_Tree, Next_Project);
942 Current_Project := Next_Project;
948 Name_Id (Current_With.Path));
950 (Current_Project, In_Tree, Current_With.Location);
952 -- If it is a limited with, check if we have a circularity.
953 -- If we have one, get the project id of the limited
954 -- imported project file, and do not parse it.
956 if (In_Limited or Limited_Withs)
957 and then Project_Stack.Last > 1
960 Canonical_Path_Name : Path_Name_Type;
963 Name_Len := Resolved_Path'Length;
964 Name_Buffer (1 .. Name_Len) := Resolved_Path;
965 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
966 Canonical_Path_Name := Name_Find;
968 for Index in 1 .. Project_Stack.Last loop
969 if Project_Stack.Table (Index).Canonical_Path_Name =
972 -- We have found the limited imported project,
973 -- get its project id, and do not parse it.
975 Withed_Project := Project_Stack.Table (Index).Id;
982 -- Parse the imported project if its project id is unknown
984 if No (Withed_Project) then
987 Project => Withed_Project,
988 Extends_All => Extends_All,
989 Path_Name_Id => Imported_Path_Name_Id,
991 From_Extended => From_Extended,
992 In_Limited => In_Limited or Limited_Withs,
993 Packages_To_Check => Packages_To_Check,
995 Current_Dir => Current_Dir,
996 Is_Config_File => Is_Config_File,
1000 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
1003 if No (Withed_Project) then
1005 -- If parsing unsuccessful, remove the context clause
1007 Current_Project := Previous_Project;
1009 if No (Current_Project) then
1010 Imported_Projects := Empty_Node;
1013 Set_Next_With_Clause_Of
1014 (Current_Project, In_Tree, Empty_Node);
1017 -- If parsing was successful, record project name and
1018 -- path name in with clause
1021 (Node => Current_Project,
1023 To => Withed_Project,
1024 Limited_With => Current_With.Limited_With);
1028 Name_Of (Withed_Project, In_Tree));
1030 Name_Len := Resolved_Path'Length;
1031 Name_Buffer (1 .. Name_Len) := Resolved_Path;
1032 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
1035 Set_Is_Extending_All (Current_Project, In_Tree);
1042 end Post_Parse_Context_Clause;
1044 ---------------------------------
1045 -- Check_Extending_All_Imports --
1046 ---------------------------------
1048 procedure Check_Extending_All_Imports
1049 (Flags : Processing_Flags;
1050 In_Tree : Project_Node_Tree_Ref;
1051 Project : Project_Node_Id)
1053 With_Clause : Project_Node_Id;
1054 Imported : Project_Node_Id;
1057 if not Is_Extending_All (Project, In_Tree) then
1058 With_Clause := First_With_Clause_Of (Project, In_Tree);
1059 while Present (With_Clause) loop
1060 Imported := Project_Node_Of (With_Clause, In_Tree);
1062 if Is_Extending_All (With_Clause, In_Tree) then
1063 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
1064 Error_Msg (Flags, "cannot import extending-all project %%",
1069 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1072 end Check_Extending_All_Imports;
1074 -----------------------------
1075 -- Check_Aggregate_Imports --
1076 -----------------------------
1078 procedure Check_Aggregate_Imports
1079 (Flags : Processing_Flags;
1080 In_Tree : Project_Node_Tree_Ref;
1081 Project : Project_Node_Id)
1083 With_Clause, Imported : Project_Node_Id;
1085 if Project_Qualifier_Of (Project, In_Tree) = Aggregate then
1086 With_Clause := First_With_Clause_Of (Project, In_Tree);
1088 while Present (With_Clause) loop
1089 Imported := Project_Node_Of (With_Clause, In_Tree);
1091 if Project_Qualifier_Of (Imported, In_Tree) /= Dry then
1092 Error_Msg_Name_1 := Name_Id (Path_Name_Of (Imported, In_Tree));
1093 Error_Msg (Flags, "can only import abstract projects, not %%",
1098 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1101 end Check_Aggregate_Imports;
1103 ----------------------------
1104 -- Read_Project_Qualifier --
1105 ----------------------------
1107 procedure Read_Project_Qualifier
1108 (Flags : Processing_Flags;
1109 In_Tree : Project_Node_Tree_Ref;
1110 Is_Config_File : Boolean;
1111 Qualifier_Location : out Source_Ptr;
1112 Project : Project_Node_Id)
1114 Proj_Qualifier : Project_Qualifier := Unspecified;
1116 Qualifier_Location := Token_Ptr;
1118 if Token = Tok_Abstract then
1119 Proj_Qualifier := Dry;
1122 elsif Token = Tok_Identifier then
1124 when Snames.Name_Standard =>
1125 Proj_Qualifier := Standard;
1128 when Snames.Name_Aggregate =>
1129 Proj_Qualifier := Aggregate;
1132 if Token = Tok_Identifier
1133 and then Token_Name = Snames.Name_Library
1135 Proj_Qualifier := Aggregate_Library;
1139 when Snames.Name_Library =>
1140 Proj_Qualifier := Library;
1143 when Snames.Name_Configuration =>
1144 if not Is_Config_File then
1147 "configuration projects cannot belong to a user" &
1152 Proj_Qualifier := Configuration;
1160 if Is_Config_File and then Proj_Qualifier = Unspecified then
1162 -- Set the qualifier to Configuration, even if the token doesn't
1163 -- exist in the source file itself, so that we can differentiate
1164 -- project files and configuration files later on.
1166 Proj_Qualifier := Configuration;
1169 if Proj_Qualifier /= Unspecified then
1171 and then Proj_Qualifier /= Configuration
1174 "a configuration project cannot be qualified except " &
1175 "as configuration project",
1176 Qualifier_Location);
1179 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1181 end Read_Project_Qualifier;
1183 -------------------------------
1184 -- Has_Circular_Dependencies --
1185 -------------------------------
1187 function Has_Circular_Dependencies
1188 (Flags : Processing_Flags;
1189 Normed_Path_Name : Path_Name_Type;
1190 Canonical_Path_Name : Path_Name_Type) return Boolean is
1192 for Index in reverse 1 .. Project_Stack.Last loop
1193 exit when Project_Stack.Table (Index).Limited_With;
1195 if Canonical_Path_Name =
1196 Project_Stack.Table (Index).Canonical_Path_Name
1198 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
1199 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
1200 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
1202 for Current in reverse 1 .. Project_Stack.Last loop
1204 Name_Id (Project_Stack.Table (Current).Path_Name);
1206 if Project_Stack.Table (Current).Canonical_Path_Name /=
1210 (Flags, "\ %% which itself is imported by", Token_Ptr);
1213 Error_Msg (Flags, "\ %%", Token_Ptr);
1222 end Has_Circular_Dependencies;
1224 --------------------------
1225 -- Parse_Single_Project --
1226 --------------------------
1228 procedure Parse_Single_Project
1229 (In_Tree : Project_Node_Tree_Ref;
1230 Project : out Project_Node_Id;
1231 Extends_All : out Boolean;
1232 Path_Name_Id : Path_Name_Type;
1234 From_Extended : Extension_Origin;
1235 In_Limited : Boolean;
1236 Packages_To_Check : String_List_Access;
1238 Current_Dir : String;
1239 Is_Config_File : Boolean;
1240 Env : in out Environment;
1241 Implicit_Project : Boolean := False)
1243 Path_Name : constant String := Get_Name_String (Path_Name_Id);
1245 Normed_Path_Name : Path_Name_Type;
1246 Canonical_Path_Name : Path_Name_Type;
1247 Project_Directory : Path_Name_Type;
1248 Project_Scan_State : Saved_Project_Scan_State;
1249 Source_Index : Source_File_Index;
1251 Extending : Boolean := False;
1253 Extended_Project : Project_Node_Id := Empty_Node;
1255 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1256 Tree_Private_Part.Projects_Htable.Get_First
1257 (In_Tree.Projects_HT);
1259 Name_From_Path : constant Name_Id :=
1260 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
1261 Name_Of_Project : Name_Id := No_Name;
1262 Display_Name_Of_Project : Name_Id := No_Name;
1264 Duplicated : Boolean := False;
1266 First_With : With_Id;
1267 Imported_Projects : Project_Node_Id := Empty_Node;
1269 use Tree_Private_Part;
1271 Project_Comment_State : Tree.Comment_State;
1273 Qualifier_Location : Source_Ptr;
1276 Extends_All := False;
1279 Normed_Path : constant String := Normalize_Pathname
1281 Directory => Current_Dir,
1282 Resolve_Links => False,
1283 Case_Sensitive => True);
1284 Canonical_Path : constant String := Normalize_Pathname
1286 Directory => Current_Dir,
1287 Resolve_Links => Opt.Follow_Links_For_Files,
1288 Case_Sensitive => False);
1290 Name_Len := Normed_Path'Length;
1291 Name_Buffer (1 .. Name_Len) := Normed_Path;
1292 Normed_Path_Name := Name_Find;
1293 Name_Len := Canonical_Path'Length;
1294 Name_Buffer (1 .. Name_Len) := Canonical_Path;
1295 Canonical_Path_Name := Name_Find;
1298 if Has_Circular_Dependencies
1299 (Env.Flags, Normed_Path_Name, Canonical_Path_Name)
1301 Project := Empty_Node;
1305 -- Put the new path name on the stack
1307 Project_Stack.Append
1308 ((Path_Name => Normed_Path_Name,
1309 Canonical_Path_Name => Canonical_Path_Name,
1311 Limited_With => In_Limited));
1313 -- Check if the project file has already been parsed
1316 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1318 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1321 if A_Project_Name_And_Node.Extended then
1322 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1325 "cannot extend the same project file several times",
1331 "cannot extend an already imported project file",
1335 elsif A_Project_Name_And_Node.Extended then
1337 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1339 -- If the imported project is an extended project A, and we are
1340 -- in an extended project, replace A with the ultimate project
1343 if From_Extended /= None then
1345 Decl : Project_Node_Id :=
1346 Project_Declaration_Of
1347 (A_Project_Name_And_Node.Node, In_Tree);
1349 Prj : Project_Node_Id :=
1350 A_Project_Name_And_Node.Node;
1353 -- Loop through extending projects to find the ultimate
1354 -- extending project, that is the one that is not
1355 -- extended. For an abstract project, as it can be
1356 -- extended several times, there is no extending project
1357 -- registered, so the loop does not execute and the
1358 -- resulting project is the abstract project.
1361 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1363 Prj := Extending_Project_Of (Decl, In_Tree);
1364 Decl := Project_Declaration_Of (Prj, In_Tree);
1367 A_Project_Name_And_Node.Node := Prj;
1372 "cannot import an already extended project file",
1377 Project := A_Project_Name_And_Node.Node;
1378 Project_Stack.Decrement_Last;
1382 A_Project_Name_And_Node :=
1383 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1386 -- We never encountered this project file. Save the scan state, load the
1387 -- project file and start to scan it.
1389 Save_Project_Scan_State (Project_Scan_State);
1390 Source_Index := Load_Project_File (Path_Name);
1391 Tree.Save (Project_Comment_State);
1393 -- If we cannot find it, we stop
1395 if Source_Index = No_Source_File then
1396 Project := Empty_Node;
1397 Project_Stack.Decrement_Last;
1401 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1405 if not Is_Config_File
1406 and then Name_From_Path = No_Name
1407 and then not Implicit_Project
1410 -- The project file name is not correct (no or bad extension, or not
1411 -- following Ada identifier's syntax).
1413 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1414 Error_Msg (Env.Flags,
1415 "?{ is not a valid path name for a project file",
1419 if Current_Verbosity >= Medium then
1420 Debug_Increase_Indent ("Parsing """ & Path_Name & '"');
1423 Project_Directory :=
1424 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1426 -- Is there any imported project?
1428 Pre_Parse_Context_Clause
1429 (In_Tree => In_Tree,
1430 Is_Config_File => Is_Config_File,
1431 Context_Clause => First_With,
1432 Flags => Env.Flags);
1434 Project := Default_Project_Node
1435 (Of_Kind => N_Project, In_Tree => In_Tree);
1436 Project_Stack.Table (Project_Stack.Last).Id := Project;
1437 Set_Directory_Of (Project, In_Tree, Project_Directory);
1438 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1440 Read_Project_Qualifier
1441 (Env.Flags, In_Tree, Is_Config_File, Qualifier_Location, Project);
1443 Set_Location_Of (Project, In_Tree, Token_Ptr);
1445 Expect (Tok_Project, "PROJECT
");
1447 -- Mark location of PROJECT token if present
1449 if Token = Tok_Project then
1450 Scan (In_Tree); -- past PROJECT
1451 Set_Location_Of (Project, In_Tree, Token_Ptr);
1458 Expect (Tok_Identifier, "identifier
");
1460 -- If the token is not an identifier, clear the buffer before
1461 -- exiting to indicate that the name of the project is ill-formed.
1463 if Token /= Tok_Identifier then
1468 -- Add the identifier name to the buffer
1470 Get_Name_String (Token_Name);
1471 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1473 -- Scan past the identifier
1477 -- If we have a dot, add a dot to the Buffer and look for the next
1480 exit when Token /= Tok_Dot;
1481 Add_To_Buffer (".", Buffer, Buffer_Last);
1483 -- Scan past the dot
1488 -- See if this is an extending project
1490 if Token = Tok_Extends then
1492 if Is_Config_File then
1495 "extending configuration project
not allowed
", Token_Ptr);
1498 -- Make sure that gnatmake will use mapping files
1500 Opt.Create_Mapping_File := True;
1502 -- We are extending another project
1506 Scan (In_Tree); -- past EXTENDS
1508 if Token = Tok_All then
1509 Extends_All := True;
1510 Set_Is_Extending_All (Project, In_Tree);
1511 Scan (In_Tree); -- scan past ALL
1515 -- If the name is well formed, Buffer_Last is > 0
1517 if Buffer_Last > 0 then
1519 -- The Buffer contains the name of the project
1521 Name_Len := Buffer_Last;
1522 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1523 Name_Of_Project := Name_Find;
1524 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1526 -- To get expected name of the project file, replace dots by dashes
1528 for Index in 1 .. Name_Len loop
1529 if Name_Buffer (Index) = '.' then
1530 Name_Buffer (Index) := '-';
1534 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1537 Expected_Name : constant Name_Id := Name_Find;
1538 Extension : String_Access;
1541 -- Output a warning if the actual name is not the expected name
1543 if not Is_Config_File
1544 and then (Name_From_Path /= No_Name)
1545 and then Expected_Name /= Name_From_Path
1547 Error_Msg_Name_1 := Expected_Name;
1549 if Is_Config_File then
1550 Extension := new String'(Config_Project_File_Extension);
1553 Extension := new String'(Project_File_Extension);
1558 "?file name does
not match project name
, should be `
%%"
1559 & Extension.all & "`
",
1564 -- Read the original casing of the project name
1570 Loc := Location_Of (Project, In_Tree);
1571 for J in 1 .. Name_Len loop
1572 Name_Buffer (J) := Sinput.Source (Loc);
1576 Display_Name_Of_Project := Name_Find;
1580 From_Ext : Extension_Origin := None;
1583 -- Extending_All is always propagated
1585 if From_Extended = Extending_All or else Extends_All then
1586 From_Ext := Extending_All;
1588 -- Otherwise, From_Extended is set to Extending_Single if the
1589 -- current project is an extending project.
1592 From_Ext := Extending_Simple;
1595 Post_Parse_Context_Clause
1596 (In_Tree => In_Tree,
1597 Context_Clause => First_With,
1598 In_Limited => In_Limited,
1599 Limited_Withs => False,
1600 Imported_Projects => Imported_Projects,
1601 Project_Directory => Project_Directory,
1602 From_Extended => From_Ext,
1603 Packages_To_Check => Packages_To_Check,
1605 Current_Dir => Current_Dir,
1606 Is_Config_File => Is_Config_File,
1608 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1611 if not Is_Config_File then
1613 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1614 Tree_Private_Part.Projects_Htable.Get_First
1615 (In_Tree.Projects_HT);
1616 Project_Name : Name_Id := Name_And_Node.Name;
1619 -- Check if we already have a project with this name
1621 while Project_Name /= No_Name
1622 and then Project_Name /= Name_Of_Project
1625 Tree_Private_Part.Projects_Htable.Get_Next
1626 (In_Tree.Projects_HT);
1627 Project_Name := Name_And_Node.Name;
1630 -- Report an error if we already have a project with this name
1632 if Project_Name /= No_Name then
1634 Error_Msg_Name_1 := Project_Name;
1636 (Env.Flags, "duplicate project name
%%",
1637 Location_Of (Project, In_Tree));
1639 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1642 "\already
in %%", Location_Of (Project, In_Tree));
1650 Expect (Tok_String_Literal, "literal
string");
1652 if Token = Tok_String_Literal then
1653 Set_Extended_Project_Path_Of
1656 Path_Name_Type (Token_Name));
1659 Original_Path_Name : constant String :=
1660 Get_Name_String (Token_Name);
1662 Extended_Project_Path_Name_Id : Path_Name_Type;
1667 Project_File_Name => Original_Path_Name,
1668 Directory => Get_Name_String (Project_Directory),
1669 Path => Extended_Project_Path_Name_Id);
1671 if Extended_Project_Path_Name_Id = No_Path then
1673 -- We could not find the project file to extend
1675 Error_Msg_Name_1 := Token_Name;
1677 Error_Msg (Env.Flags, "unknown project file
: %%", Token_Ptr);
1679 -- If not in the main project file, display the import path
1681 if Project_Stack.Last > 1 then
1684 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1685 Error_Msg (Env.Flags, "\extended by
%%", Token_Ptr);
1687 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1690 (Project_Stack.Table (Index).Path_Name);
1691 Error_Msg (Env.Flags, "\imported by
%%", Token_Ptr);
1697 From_Ext : Extension_Origin := None;
1700 if From_Extended = Extending_All or else Extends_All then
1701 From_Ext := Extending_All;
1704 Parse_Single_Project
1705 (In_Tree => In_Tree,
1706 Project => Extended_Project,
1707 Extends_All => Extends_All,
1708 Path_Name_Id => Extended_Project_Path_Name_Id,
1710 From_Extended => From_Ext,
1711 In_Limited => In_Limited,
1712 Packages_To_Check => Packages_To_Check,
1714 Current_Dir => Current_Dir,
1715 Is_Config_File => Is_Config_File,
1719 if Present (Extended_Project) then
1721 -- A project that extends an extending-all project is
1722 -- also an extending-all project.
1724 if Is_Extending_All (Extended_Project, In_Tree) then
1725 Set_Is_Extending_All (Project, In_Tree);
1728 -- An abstract project can only extend an abstract
1729 -- project. Otherwise we may have an abstract project
1730 -- with sources if it inherits sources from the project
1733 if Project_Qualifier_Of (Project, In_Tree) = Dry and then
1734 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1737 (Env.Flags, "an
abstract project can only extend
" &
1738 "another
abstract project
",
1739 Qualifier_Location);
1745 Scan (In_Tree); -- past the extended project path
1749 Check_Extending_All_Imports (Env.Flags, In_Tree, Project);
1750 Check_Aggregate_Imports (Env.Flags, In_Tree, Project);
1752 -- Check that a project with a name including a dot either imports
1753 -- or extends the project whose name precedes the last dot.
1755 if Name_Of_Project /= No_Name then
1756 Get_Name_String (Name_Of_Project);
1762 -- Look for the last dot
1764 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1765 Name_Len := Name_Len - 1;
1768 -- If a dot was found, check if parent project is imported or extended
1770 if Name_Len > 0 then
1771 Name_Len := Name_Len - 1;
1774 Parent_Name : constant Name_Id := Name_Find;
1775 Parent_Found : Boolean := False;
1776 Parent_Node : Project_Node_Id := Empty_Node;
1777 With_Clause : Project_Node_Id :=
1778 First_With_Clause_Of (Project, In_Tree);
1779 Imp_Proj_Name : Name_Id;
1782 -- If there is an extended project, check its name
1784 if Present (Extended_Project) then
1785 Parent_Node := Extended_Project;
1787 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1790 -- If the parent project is not the extended project,
1791 -- check each imported project until we find the parent project.
1794 while not Parent_Found and then Present (With_Clause) loop
1795 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1796 Extension_Loop : while Present (Parent_Node) loop
1797 Imp_Proj_Name := Name_Of (Parent_Node, In_Tree);
1798 Parent_Found := Imp_Proj_Name = Parent_Name;
1799 exit Imported_Loop when Parent_Found;
1802 (Project_Declaration_Of (Parent_Node, In_Tree),
1804 end loop Extension_Loop;
1806 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1807 end loop Imported_Loop;
1809 if Parent_Found then
1810 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1813 -- If the parent project was not found, report an error
1815 Error_Msg_Name_1 := Name_Of_Project;
1816 Error_Msg_Name_2 := Parent_Name;
1817 Error_Msg (Env.Flags,
1818 "project
%% does
not import
or extend project
%%",
1819 Location_Of (Project, In_Tree));
1824 Expect (Tok_Is, "IS");
1825 Set_End_Of_Line (Project);
1826 Set_Previous_Line_Node (Project);
1827 Set_Next_End_Node (Project);
1830 Project_Declaration : Project_Node_Id := Empty_Node;
1833 -- No need to Scan past "is", Prj.Dect.Parse will do it
1836 (In_Tree => In_Tree,
1837 Declarations => Project_Declaration,
1838 Current_Project => Project,
1839 Extends => Extended_Project,
1840 Packages_To_Check => Packages_To_Check,
1841 Is_Config_File => Is_Config_File,
1842 Flags => Env.Flags);
1843 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1845 if Present (Extended_Project)
1846 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1848 Set_Extending_Project_Of
1849 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1854 Expect (Tok_End, "END");
1855 Remove_Next_End_Node;
1857 -- Skip "end" if present
1859 if Token = Tok_End then
1867 -- Store the name following "end" in the Buffer. The name may be made of
1868 -- several simple names.
1871 Expect (Tok_Identifier, "identifier
");
1873 -- If we don't have an identifier, clear the buffer before exiting to
1874 -- avoid checking the name.
1876 if Token /= Tok_Identifier then
1881 -- Add the identifier to the Buffer
1882 Get_Name_String (Token_Name);
1883 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1885 -- Scan past the identifier
1888 exit when Token /= Tok_Dot;
1889 Add_To_Buffer (".", Buffer, Buffer_Last);
1893 -- If we have a valid name, check if it is the name of the project
1895 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1896 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1897 Get_Name_String (Name_Of (Project, In_Tree))
1899 -- Invalid name: report an error
1901 Error_Msg (Env.Flags, "expected
""" &
1902 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1907 Expect (Tok_Semicolon, "`
;`
");
1909 -- Check that there is no more text following the end of the project
1912 if Token = Tok_Semicolon then
1913 Set_Previous_End_Node (Project);
1916 if Token /= Tok_EOF then
1919 "unexpected text following
end of project
", Token_Ptr);
1923 if not Duplicated and then Name_Of_Project /= No_Name then
1925 -- Add the name of the project to the hash table, so that we can
1926 -- check that no other subsequent project will have the same name.
1928 Tree_Private_Part.Projects_Htable.Set
1929 (T => In_Tree.Projects_HT,
1930 K => Name_Of_Project,
1931 E => (Name => Name_Of_Project,
1932 Display_Name => Display_Name_Of_Project,
1934 Canonical_Path => Canonical_Path_Name,
1935 Extended => Extended,
1936 Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
1940 From_Ext : Extension_Origin := None;
1943 -- Extending_All is always propagated
1945 if From_Extended = Extending_All or else Extends_All then
1946 From_Ext := Extending_All;
1948 -- Otherwise, From_Extended is set to Extending_Single if the
1949 -- current project is an extending project.
1952 From_Ext := Extending_Simple;
1955 Post_Parse_Context_Clause
1956 (In_Tree => In_Tree,
1957 Context_Clause => First_With,
1958 In_Limited => In_Limited,
1959 Limited_Withs => True,
1960 Imported_Projects => Imported_Projects,
1961 Project_Directory => Project_Directory,
1962 From_Extended => From_Ext,
1963 Packages_To_Check => Packages_To_Check,
1965 Current_Dir => Current_Dir,
1966 Is_Config_File => Is_Config_File,
1968 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1971 -- Restore the scan state, in case we are not the main project
1973 Restore_Project_Scan_State (Project_Scan_State);
1975 -- And remove the project from the project stack
1977 Project_Stack.Decrement_Last;
1979 -- Indicate if there are unkept comments
1981 Tree.Set_Project_File_Includes_Unkept_Comments
1984 To => Tree.There_Are_Unkept_Comments);
1986 -- And restore the comment state that was saved
1988 Tree.Restore_And_Free (Project_Comment_State);
1990 Debug_Decrease_Indent;
1992 if Project /= Empty_Node and then Implicit_Project then
1994 Add_Str_To_Name_Buffer (Current_Dir);
1995 Add_Char_To_Name_Buffer (Dir_Sep);
1996 In_Tree.Project_Nodes.Table (Project).Directory := Name_Find;
1998 end Parse_Single_Project;
2000 -----------------------
2001 -- Project_Name_From --
2002 -----------------------
2004 function Project_Name_From
2005 (Path_Name : String;
2006 Is_Config_File : Boolean) return Name_Id
2008 Canonical : String (1 .. Path_Name'Length) := Path_Name;
2009 First : Natural := Canonical'Last;
2010 Last : Natural := First;
2014 if Current_Verbosity = High then
2015 Debug_Output ("Project_Name_From
(""" & Canonical & """)");
2018 -- If the path name is empty, return No_Name to indicate failure
2024 Canonical_Case_File_Name (Canonical);
2026 -- Look for the last dot in the path name
2030 Canonical (First) /= '.'
2035 -- If we have a dot, check that it is followed by the correct extension
2037 if First > 0 and then Canonical (First) = '.' then
2038 if (not Is_Config_File
2039 and then Canonical (First .. Last) = Project_File_Extension
2040 and then First /= 1)
2044 Canonical (First .. Last) = Config_Project_File_Extension
2045 and then First /= 1)
2047 -- Look for the last directory separator, if any
2052 and then Canonical (First) /= '/'
2053 and then Canonical (First) /= Dir_Sep
2059 -- Not the correct extension, return No_Name to indicate failure
2064 -- If no dot in the path name, return No_Name to indicate failure
2072 -- If the extension is the file name, return No_Name to indicate failure
2074 if First > Last then
2078 -- Put the name in lower case into Name_Buffer
2080 Name_Len := Last - First + 1;
2081 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
2085 -- Check if it is a well formed project name. Return No_Name if it is
2089 if not Is_Letter (Name_Buffer (Index)) then
2096 exit when Index >= Name_Len;
2098 if Name_Buffer (Index) = '_' then
2099 if Name_Buffer (Index + 1) = '_' then
2104 exit when Name_Buffer (Index) = '-';
2106 if Name_Buffer (Index) /= '_'
2107 and then not Is_Alphanumeric (Name_Buffer (Index))
2115 if Index >= Name_Len then
2116 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
2118 -- All checks have succeeded. Return name in Name_Buffer
2126 elsif Name_Buffer (Index) = '-' then
2130 end Project_Name_From;