1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars
; use Err_Vars
;
28 with Osint
; use Osint
;
29 with Output
; use Output
;
30 with Prj
.Com
; use Prj
.Com
;
32 with Prj
.Env
; use Prj
.Env
;
33 with Prj
.Err
; use Prj
.Err
;
34 with Sinput
; use Sinput
;
35 with Sinput
.P
; use Sinput
.P
;
39 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
40 with Ada
.Exceptions
; use Ada
.Exceptions
;
42 with GNAT
.HTable
; use GNAT
.HTable
;
44 package body Prj
.Part
is
46 Buffer
: String_Access
;
47 Buffer_Last
: Natural := 0;
49 Dir_Sep
: Character renames GNAT
.OS_Lib
.Directory_Separator
;
51 ------------------------------------
52 -- Local Packages and Subprograms --
53 ------------------------------------
55 type With_Id
is new Nat
;
56 No_With
: constant With_Id
:= 0;
58 type With_Record
is record
59 Path
: Path_Name_Type
;
60 Location
: Source_Ptr
;
61 Limited_With
: Boolean;
62 Node
: Project_Node_Id
;
65 -- Information about an imported project, to be put in table Withs below
67 package Withs
is new Table
.Table
68 (Table_Component_Type
=> With_Record
,
69 Table_Index_Type
=> With_Id
,
72 Table_Increment
=> 100,
73 Table_Name
=> "Prj.Part.Withs");
74 -- Table used to store temporarily paths and locations of imported
75 -- projects. These imported projects will be effectively parsed later: just
76 -- before parsing the current project for the non limited withed projects,
77 -- after getting its name; after complete parsing of the current project
78 -- for the limited withed projects.
80 type Names_And_Id
is record
81 Path_Name
: Path_Name_Type
;
82 Canonical_Path_Name
: Path_Name_Type
;
84 Limited_With
: Boolean;
87 package Project_Stack
is new Table
.Table
88 (Table_Component_Type
=> Names_And_Id
,
89 Table_Index_Type
=> Nat
,
92 Table_Increment
=> 100,
93 Table_Name
=> "Prj.Part.Project_Stack");
94 -- This table is used to detect circular dependencies
95 -- for imported and extended projects and to get the project ids of
96 -- limited imported projects when there is a circularity with at least
97 -- one limited imported project file.
99 package Virtual_Hash
is new GNAT
.HTable
.Simple_HTable
100 (Header_Num
=> Header_Num
,
101 Element
=> Project_Node_Id
,
102 No_Element
=> Project_Node_High_Bound
,
103 Key
=> Project_Node_Id
,
104 Hash
=> Prj
.Tree
.Hash
,
106 -- Hash table to store the node ids of projects for which a virtual
107 -- extending project need to be created. The corresponding value is the
108 -- head of a list of WITH clauses corresponding to the context of the
109 -- enclosing EXTEND ALL projects. Note: Default_Element is Project_Node_
110 -- High_Bound because we want Empty_Node to be a possible value.
112 package Processed_Hash
is new GNAT
.HTable
.Simple_HTable
113 (Header_Num
=> Header_Num
,
116 Key
=> Project_Node_Id
,
117 Hash
=> Prj
.Tree
.Hash
,
119 -- Hash table to store the project process when looking for project that
120 -- need to have a virtual extending project, to avoid processing the same
123 function Has_Circular_Dependencies
124 (Flags
: Processing_Flags
;
125 Normed_Path_Name
: Path_Name_Type
;
126 Canonical_Path_Name
: Path_Name_Type
) return Boolean;
127 -- Check for a circular dependency in the loaded project.
128 -- Generates an error message in such a case.
130 procedure Read_Project_Qualifier
131 (Flags
: Processing_Flags
;
132 In_Tree
: Project_Node_Tree_Ref
;
133 Is_Config_File
: Boolean;
134 Qualifier_Location
: out Source_Ptr
;
135 Project
: Project_Node_Id
);
136 -- Check if there is a qualifier before the reserved word "project"
138 -- Hash table to cache project path to avoid looking for them on the path
140 procedure Check_Extending_All_Imports
141 (Flags
: Processing_Flags
;
142 In_Tree
: Project_Node_Tree_Ref
;
143 Project
: Project_Node_Id
);
144 -- Check that a non extending-all project does not import an
145 -- extending-all project.
147 procedure Check_Aggregate_Imports
148 (Flags
: Processing_Flags
;
149 In_Tree
: Project_Node_Tree_Ref
;
150 Project
: Project_Node_Id
);
151 -- Check that an aggregate project only imports abstract projects
153 procedure Create_Virtual_Extending_Project
154 (For_Project
: Project_Node_Id
;
155 Main_Project
: Project_Node_Id
;
156 Extension_Withs
: Project_Node_Id
;
157 In_Tree
: Project_Node_Tree_Ref
);
158 -- Create a virtual extending project of For_Project. Main_Project is
159 -- the extending all project. Extension_Withs is the head of a WITH clause
160 -- list to be added to the created virtual project.
162 -- The String_Value_Of is not set for the automatically added with
163 -- clause and keeps the default value of No_Name. This enables Prj.PP
164 -- to skip these automatically added with clauses to be processed.
166 procedure Look_For_Virtual_Projects_For
167 (Proj
: Project_Node_Id
;
168 In_Tree
: Project_Node_Tree_Ref
;
169 Potentially_Virtual
: Boolean);
170 -- Look for projects that need to have a virtual extending project.
171 -- This procedure is recursive. If called with Potentially_Virtual set to
172 -- True, then Proj may need an virtual extending project; otherwise it
173 -- does not (because it is already extended), but other projects that it
174 -- imports may need to be virtually extended.
176 type Extension_Origin
is (None
, Extending_Simple
, Extending_All
);
177 -- Type of parameter From_Extended for procedures Parse_Single_Project and
178 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
179 -- tree rooted at an extending all project.
181 procedure Parse_Single_Project
182 (In_Tree
: Project_Node_Tree_Ref
;
183 Project
: out Project_Node_Id
;
184 Extends_All
: out Boolean;
185 Path_Name_Id
: Path_Name_Type
;
187 From_Extended
: Extension_Origin
;
188 In_Limited
: Boolean;
189 Packages_To_Check
: String_List_Access
;
191 Current_Dir
: String;
192 Is_Config_File
: Boolean;
193 Env
: in out Environment
);
194 -- Parse a project file. This is a recursive procedure: it calls itself for
195 -- imported and extended projects. When From_Extended is not None, if the
196 -- project has already been parsed and is an extended project A, return the
197 -- ultimate (not extended) project that extends A. When In_Limited is True,
198 -- the importing path includes at least one "limited with". When parsing
199 -- configuration projects, do not allow a depth > 1.
201 -- Is_Config_File should be set to True if the project represents a config
202 -- file (.cgpr) since some specific checks apply.
204 procedure Pre_Parse_Context_Clause
205 (In_Tree
: Project_Node_Tree_Ref
;
206 Context_Clause
: out With_Id
;
207 Is_Config_File
: Boolean;
208 Flags
: Processing_Flags
);
209 -- Parse the context clause of a project. Store the paths and locations of
210 -- the imported projects in table Withs. Does nothing if there is no
211 -- context clause (if the current token is not "with" or "limited" followed
213 -- Is_Config_File should be set to True if the project represents a config
214 -- file (.cgpr) since some specific checks apply.
216 procedure Post_Parse_Context_Clause
217 (Context_Clause
: With_Id
;
218 In_Tree
: Project_Node_Tree_Ref
;
219 In_Limited
: Boolean;
220 Limited_Withs
: Boolean;
221 Imported_Projects
: in out Project_Node_Id
;
222 Project_Directory
: Path_Name_Type
;
223 From_Extended
: Extension_Origin
;
224 Packages_To_Check
: String_List_Access
;
226 Current_Dir
: String;
227 Is_Config_File
: Boolean;
228 Env
: in out Environment
);
229 -- Parse the imported projects that have been stored in table Withs, if
230 -- any. From_Extended is used for the call to Parse_Single_Project below.
232 -- When In_Limited is True, the importing path includes at least one
233 -- "limited with". When Limited_Withs is False, only non limited withed
234 -- projects are parsed. When Limited_Withs is True, only limited withed
235 -- projects are parsed.
237 -- Is_Config_File should be set to True if the project represents a config
238 -- file (.cgpr) since some specific checks apply.
240 function Project_Name_From
242 Is_Config_File
: Boolean) return Name_Id
;
243 -- Returns the name of the project that corresponds to its path name.
244 -- Returns No_Name if the path name is invalid, because the corresponding
245 -- project name does not have the syntax of an ada identifier.
247 function Copy_With_Clause
248 (With_Clause
: Project_Node_Id
;
249 In_Tree
: Project_Node_Tree_Ref
;
250 Next_Clause
: Project_Node_Id
) return Project_Node_Id
;
251 -- Return a copy of With_Clause in In_Tree, whose Next_With_Clause is the
254 ----------------------
255 -- Copy_With_Clause --
256 ----------------------
258 function Copy_With_Clause
259 (With_Clause
: Project_Node_Id
;
260 In_Tree
: Project_Node_Tree_Ref
;
261 Next_Clause
: Project_Node_Id
) return Project_Node_Id
263 New_With_Clause
: constant Project_Node_Id
:=
264 Default_Project_Node
(In_Tree
, N_With_Clause
);
266 Set_Name_Of
(New_With_Clause
, In_Tree
,
267 Name_Of
(With_Clause
, In_Tree
));
268 Set_Path_Name_Of
(New_With_Clause
, In_Tree
,
269 Path_Name_Of
(With_Clause
, In_Tree
));
270 Set_Project_Node_Of
(New_With_Clause
, In_Tree
,
271 Project_Node_Of
(With_Clause
, In_Tree
));
272 Set_Next_With_Clause_Of
(New_With_Clause
, In_Tree
, Next_Clause
);
274 return New_With_Clause
;
275 end Copy_With_Clause
;
277 --------------------------------------
278 -- Create_Virtual_Extending_Project --
279 --------------------------------------
281 procedure Create_Virtual_Extending_Project
282 (For_Project
: Project_Node_Id
;
283 Main_Project
: Project_Node_Id
;
284 Extension_Withs
: Project_Node_Id
;
285 In_Tree
: Project_Node_Tree_Ref
)
288 Virtual_Name
: constant String :=
290 Get_Name_String
(Name_Of
(For_Project
, In_Tree
));
291 -- The name of the virtual extending project
293 Virtual_Name_Id
: Name_Id
;
294 -- Virtual extending project name id
296 Virtual_Path_Id
: Path_Name_Type
;
297 -- Fake path name of the virtual extending project. The directory is
298 -- the same directory as the extending all project.
300 -- The source of the virtual extending project is something like:
302 -- project V$<project name> extends <project path> is
304 -- for Source_Dirs use ();
306 -- end V$<project name>;
308 -- The project directory cannot be specified during parsing; it will be
309 -- put directly in the virtual extending project data during processing.
311 -- Nodes that made up the virtual extending project
313 Virtual_Project
: Project_Node_Id
;
314 With_Clause
: constant Project_Node_Id
:=
316 (In_Tree
, N_With_Clause
);
317 Project_Declaration
: Project_Node_Id
;
318 Source_Dirs_Declaration
: constant Project_Node_Id
:=
320 (In_Tree
, N_Declarative_Item
);
321 Source_Dirs_Attribute
: constant Project_Node_Id
:=
323 (In_Tree
, N_Attribute_Declaration
, List
);
324 Source_Dirs_Expression
: constant Project_Node_Id
:=
326 (In_Tree
, N_Expression
, List
);
327 Source_Dirs_Term
: constant Project_Node_Id
:=
329 (In_Tree
, N_Term
, List
);
330 Source_Dirs_List
: constant Project_Node_Id
:=
332 (In_Tree
, N_Literal_String_List
, List
);
335 -- Get the virtual path name
337 Get_Name_String
(Path_Name_Of
(Main_Project
, In_Tree
));
340 and then Name_Buffer
(Name_Len
) /= Directory_Separator
341 and then Name_Buffer
(Name_Len
) /= '/'
343 Name_Len
:= Name_Len
- 1;
346 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Virtual_Name
'Length) :=
348 Name_Len
:= Name_Len
+ Virtual_Name
'Length;
349 Virtual_Path_Id
:= Name_Find
;
351 -- Get the virtual name id
353 Name_Len
:= Virtual_Name
'Length;
354 Name_Buffer
(1 .. Name_Len
) := Virtual_Name
;
355 Virtual_Name_Id
:= Name_Find
;
357 Virtual_Project
:= Create_Project
359 Name
=> Virtual_Name_Id
,
360 Full_Path
=> Virtual_Path_Id
,
361 Is_Config_File
=> False);
363 Project_Declaration
:= Project_Declaration_Of
(Virtual_Project
, In_Tree
);
365 -- Add a WITH clause to the main project to import the newly created
366 -- virtual extending project.
368 Set_Name_Of
(With_Clause
, In_Tree
, Virtual_Name_Id
);
369 Set_Path_Name_Of
(With_Clause
, In_Tree
, Virtual_Path_Id
);
370 Set_Project_Node_Of
(With_Clause
, In_Tree
, Virtual_Project
);
371 Set_Next_With_Clause_Of
372 (With_Clause
, In_Tree
, First_With_Clause_Of
(Main_Project
, In_Tree
));
373 Set_First_With_Clause_Of
(Main_Project
, In_Tree
, With_Clause
);
375 -- Copy with clauses for projects imported by the extending-all project
378 Org_With_Clause
: Project_Node_Id
:= Extension_Withs
;
379 New_With_Clause
: Project_Node_Id
:= Empty_Node
;
382 while Present
(Org_With_Clause
) loop
384 Copy_With_Clause
(Org_With_Clause
, In_Tree
, New_With_Clause
);
386 Org_With_Clause
:= Next_With_Clause_Of
(Org_With_Clause
, In_Tree
);
389 Set_First_With_Clause_Of
(Virtual_Project
, In_Tree
, New_With_Clause
);
392 -- Virtual project node
395 (Virtual_Project
, In_Tree
, Location_Of
(Main_Project
, In_Tree
));
396 Set_Extended_Project_Path_Of
397 (Virtual_Project
, In_Tree
, Path_Name_Of
(For_Project
, In_Tree
));
399 -- Project declaration
401 Set_First_Declarative_Item_Of
402 (Project_Declaration
, In_Tree
, Source_Dirs_Declaration
);
403 Set_Extended_Project_Of
(Project_Declaration
, In_Tree
, For_Project
);
405 -- Source_Dirs declaration
407 Set_Current_Item_Node
408 (Source_Dirs_Declaration
, In_Tree
, Source_Dirs_Attribute
);
410 -- Source_Dirs attribute
412 Set_Name_Of
(Source_Dirs_Attribute
, In_Tree
, Snames
.Name_Source_Dirs
);
414 (Source_Dirs_Attribute
, In_Tree
, Source_Dirs_Expression
);
416 -- Source_Dirs expression
418 Set_First_Term
(Source_Dirs_Expression
, In_Tree
, Source_Dirs_Term
);
422 Set_Current_Term
(Source_Dirs_Term
, In_Tree
, Source_Dirs_List
);
424 -- Source_Dirs empty list: nothing to do
425 end Create_Virtual_Extending_Project
;
427 -----------------------------------
428 -- Look_For_Virtual_Projects_For --
429 -----------------------------------
431 Extension_Withs
: Project_Node_Id
;
432 -- Head of the current EXTENDS ALL imports list. When creating virtual
433 -- projects for an EXTENDS ALL, we import in each virtual project all
434 -- of the projects that appear in WITH clauses of the extending projects.
435 -- This ensures that virtual projects share a consistent environment (in
436 -- particular if a project imported by one of the extending projects
437 -- replaces some runtime units).
439 procedure Look_For_Virtual_Projects_For
440 (Proj
: Project_Node_Id
;
441 In_Tree
: Project_Node_Tree_Ref
;
442 Potentially_Virtual
: Boolean)
444 Declaration
: Project_Node_Id
:= Empty_Node
;
445 -- Node for the project declaration of Proj
447 With_Clause
: Project_Node_Id
:= Empty_Node
;
448 -- Node for a with clause of Proj
450 Imported
: Project_Node_Id
:= Empty_Node
;
451 -- Node for a project imported by Proj
453 Extended
: Project_Node_Id
:= Empty_Node
;
454 -- Node for the eventual project extended by Proj
456 Extends_All
: Boolean := False;
457 -- Set True if Proj is an EXTENDS ALL project
459 Saved_Extension_Withs
: constant Project_Node_Id
:= Extension_Withs
;
462 -- Nothing to do if Proj is undefined or has already been processed
464 if Present
(Proj
) and then not Processed_Hash
.Get
(Proj
) then
466 -- Make sure the project will not be processed again
468 Processed_Hash
.Set
(Proj
, True);
470 Declaration
:= Project_Declaration_Of
(Proj
, In_Tree
);
472 if Present
(Declaration
) then
473 Extended
:= Extended_Project_Of
(Declaration
, In_Tree
);
474 Extends_All
:= Is_Extending_All
(Proj
, In_Tree
);
477 -- If this is a project that may need a virtual extending project
478 -- and it is not itself an extending project, put it in the list.
480 if Potentially_Virtual
and then No
(Extended
) then
481 Virtual_Hash
.Set
(Proj
, Extension_Withs
);
484 -- Now check the projects it imports
486 With_Clause
:= First_With_Clause_Of
(Proj
, In_Tree
);
487 while Present
(With_Clause
) loop
488 Imported
:= Project_Node_Of
(With_Clause
, In_Tree
);
490 if Present
(Imported
) then
491 Look_For_Virtual_Projects_For
492 (Imported
, In_Tree
, Potentially_Virtual
=> True);
497 -- This is an EXTENDS ALL project: prepend each of its WITH
498 -- clauses to the currently active list of extension deps.
501 Copy_With_Clause
(With_Clause
, In_Tree
, Extension_Withs
);
504 With_Clause
:= Next_With_Clause_Of
(With_Clause
, In_Tree
);
507 -- Check also the eventual project extended by Proj. As this project
508 -- is already extended, call recursively with Potentially_Virtual
511 Look_For_Virtual_Projects_For
512 (Extended
, In_Tree
, Potentially_Virtual
=> False);
514 Extension_Withs
:= Saved_Extension_Withs
;
516 end Look_For_Virtual_Projects_For
;
523 (In_Tree
: Project_Node_Tree_Ref
;
524 Project
: out Project_Node_Id
;
525 Project_File_Name
: String;
526 Errout_Handling
: Errout_Mode
:= Always_Finalize
;
527 Packages_To_Check
: String_List_Access
;
528 Store_Comments
: Boolean := False;
529 Current_Directory
: String := "";
530 Is_Config_File
: Boolean;
531 Env
: in out Prj
.Tree
.Environment
;
532 Target_Name
: String := "")
535 pragma Warnings
(Off
, Dummy
);
537 Real_Project_File_Name
: String_Access
:=
538 Osint
.To_Canonical_File_Spec
540 Path_Name_Id
: Path_Name_Type
;
543 In_Tree
.Incomplete_With
:= False;
545 if not Is_Initialized
(Env
.Project_Path
) then
546 Prj
.Env
.Initialize_Default_Project_Path
547 (Env
.Project_Path
, Target_Name
);
550 if Real_Project_File_Name
= null then
551 Real_Project_File_Name
:= new String'(Project_File_Name);
554 Project := Empty_Node;
556 Find_Project (Env.Project_Path,
557 Project_File_Name => Real_Project_File_Name.all,
558 Directory => Current_Directory,
559 Path => Path_Name_Id);
560 Free (Real_Project_File_Name);
562 if Errout_Handling /= Never_Finalize then
566 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
567 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
569 if Path_Name_Id = No_Path then
573 Get_Path (Env.Project_Path, Path => P);
580 Project := Empty_Node;
585 -- Parse the main project file
591 Extends_All => Dummy,
592 Path_Name_Id => Path_Name_Id,
594 From_Extended => None,
596 Packages_To_Check => Packages_To_Check,
598 Current_Dir => Current_Directory,
599 Is_Config_File => Is_Config_File,
603 when Types.Unrecoverable_Error =>
605 -- Unrecoverable_Error is raised when a line is too long.
606 -- A meaningful error message will be displayed later.
608 Project := Empty_Node;
611 -- If Project is an extending-all project, create the eventual
612 -- virtual extending projects and check that there are no illegally
613 -- imported projects.
616 and then Is_Extending_All (Project, In_Tree)
618 -- First look for projects that potentially need a virtual
619 -- extending project.
622 Processed_Hash.Reset;
624 -- Mark the extending all project as processed, to avoid checking
625 -- the imported projects in case of a "limited with" on this
626 -- extending all project.
628 Processed_Hash.Set (Project, True);
631 Declaration : constant Project_Node_Id :=
632 Project_Declaration_Of (Project, In_Tree);
634 Extension_Withs := First_With_Clause_Of (Project, In_Tree);
635 Look_For_Virtual_Projects_For
636 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
637 Potentially_Virtual => False);
640 -- Now, check the projects directly imported by the main project.
641 -- Remove from the potentially virtual any project extended by one
642 -- of these imported projects.
645 With_Clause : Project_Node_Id;
646 Imported : Project_Node_Id := Empty_Node;
647 Declaration : Project_Node_Id := Empty_Node;
650 With_Clause := First_With_Clause_Of (Project, In_Tree);
651 while Present (With_Clause) loop
652 Imported := Project_Node_Of (With_Clause, In_Tree);
654 if Present (Imported) then
655 Declaration := Project_Declaration_Of (Imported, In_Tree);
657 if Extended_Project_Of (Declaration, In_Tree) /=
662 Extended_Project_Of (Declaration, In_Tree);
663 exit when No (Imported);
664 Virtual_Hash.Remove (Imported);
666 Project_Declaration_Of (Imported, In_Tree);
671 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
675 -- Now create all the virtual extending projects
678 Proj : Project_Node_Id := Empty_Node;
679 Withs : Project_Node_Id;
681 Virtual_Hash.Get_First (Proj, Withs);
682 while Withs /= Project_Node_High_Bound loop
683 Create_Virtual_Extending_Project
684 (Proj, Project, Withs, In_Tree);
685 Virtual_Hash.Get_Next (Proj, Withs);
690 -- If there were any kind of error during the parsing, serious
691 -- or not, then the parsing fails.
693 if Err_Vars.Total_Errors_Detected > 0 then
694 Project := Empty_Node;
697 case Errout_Handling is
698 when Always_Finalize =>
701 -- Reinitialize to avoid duplicate warnings later on
704 when Finalize_If_Error =>
710 when Never_Finalize =>
719 Write_Line (Exception_Information (X));
720 Write_Str ("Exception ");
721 Write_Str (Exception_Name (X));
722 Write_Line (" raised, while processing project file");
723 Project := Empty_Node;
726 ------------------------------
727 -- Pre_Parse_Context_Clause --
728 ------------------------------
730 procedure Pre_Parse_Context_Clause
731 (In_Tree : Project_Node_Tree_Ref;
732 Context_Clause : out With_Id;
733 Is_Config_File : Boolean;
734 Flags : Processing_Flags)
736 Current_With_Clause : With_Id := No_With;
737 Limited_With : Boolean := False;
738 Current_With : With_Record;
739 Current_With_Node : Project_Node_Id := Empty_Node;
742 -- Assume no context clause
744 Context_Clause := No_With;
747 -- If Token is not WITH or LIMITED, there is no context clause, or we
748 -- have exhausted the with clauses.
750 while Token = Tok_With or else Token = Tok_Limited loop
752 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
753 Limited_With := Token = Tok_Limited;
755 if Is_Config_File then
758 "configuration project cannot import " &
759 "other configuration projects",
764 Scan (In_Tree); -- past LIMITED
765 Expect (Tok_With, "WITH");
766 exit With_Loop when Token /= Tok_With;
771 Scan (In_Tree); -- past WITH or ","
773 Expect (Tok_String_Literal, "literal string");
775 if Token /= Tok_String_Literal then
779 -- Store path and location in table Withs
782 (Path => Path_Name_Type (Token_Name),
783 Location => Token_Ptr,
784 Limited_With => Limited_With,
785 Node => Current_With_Node,
788 Withs.Increment_Last;
789 Withs.Table (Withs.Last) := Current_With;
791 if Current_With_Clause = No_With then
792 Context_Clause := Withs.Last;
795 Withs.Table (Current_With_Clause).Next := Withs.Last;
798 Current_With_Clause := Withs.Last;
802 if Token = Tok_Semicolon then
803 Set_End_Of_Line (Current_With_Node);
804 Set_Previous_Line_Node (Current_With_Node);
806 -- End of (possibly multiple) with clause;
808 Scan (In_Tree); -- past semicolon
811 elsif Token = Tok_Comma then
812 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
815 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
821 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
824 end Pre_Parse_Context_Clause;
826 -------------------------------
827 -- Post_Parse_Context_Clause --
828 -------------------------------
830 procedure Post_Parse_Context_Clause
831 (Context_Clause : With_Id;
832 In_Tree : Project_Node_Tree_Ref;
833 In_Limited : Boolean;
834 Limited_Withs : Boolean;
835 Imported_Projects : in out Project_Node_Id;
836 Project_Directory : Path_Name_Type;
837 From_Extended : Extension_Origin;
838 Packages_To_Check : String_List_Access;
840 Current_Dir : String;
841 Is_Config_File : Boolean;
842 Env : in out Environment)
844 Current_With_Clause : With_Id := Context_Clause;
846 Current_Project : Project_Node_Id := Imported_Projects;
847 Previous_Project : Project_Node_Id := Empty_Node;
848 Next_Project : Project_Node_Id := Empty_Node;
850 Project_Directory_Path : constant String :=
851 Get_Name_String (Project_Directory);
853 Current_With : With_Record;
854 Extends_All : Boolean := False;
855 Imported_Path_Name_Id : Path_Name_Type;
858 -- Set Current_Project to the last project in the current list, if the
859 -- list is not empty.
861 if Present (Current_Project) then
863 Present (Next_With_Clause_Of (Current_Project, In_Tree))
865 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
869 while Current_With_Clause /= No_With loop
870 Current_With := Withs.Table (Current_With_Clause);
871 Current_With_Clause := Current_With.Next;
873 if Limited_Withs = Current_With.Limited_With then
876 Project_File_Name => Get_Name_String (Current_With.Path),
877 Directory => Project_Directory_Path,
878 Path => Imported_Path_Name_Id);
880 if Imported_Path_Name_Id = No_Path then
881 if Env.Flags.Ignore_Missing_With then
882 In_Tree.Incomplete_With := True;
885 -- The project file cannot be found
887 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
889 (Env.Flags, "unknown project file: {",
890 Current_With.Location);
892 -- If this is not imported by the main project file, display
895 if Project_Stack.Last > 1 then
896 for Index in reverse 1 .. Project_Stack.Last loop
899 (Project_Stack.Table (Index).Path_Name);
901 (Env.Flags, "\imported by {", Current_With.Location);
910 Resolved_Path : constant String :=
912 (Get_Name_String (Imported_Path_Name_Id),
913 Directory => Current_Dir,
915 Opt.Follow_Links_For_Files,
916 Case_Sensitive => True);
918 Withed_Project : Project_Node_Id := Empty_Node;
921 Previous_Project := Current_Project;
923 if No (Current_Project) then
925 -- First with clause of the context clause
927 Current_Project := Current_With.Node;
928 Imported_Projects := Current_Project;
931 Next_Project := Current_With.Node;
932 Set_Next_With_Clause_Of
933 (Current_Project, In_Tree, Next_Project);
934 Current_Project := Next_Project;
940 Name_Id (Current_With.Path));
942 (Current_Project, In_Tree, Current_With.Location);
944 -- If it is a limited with, check if we have a circularity.
945 -- If we have one, get the project id of the limited
946 -- imported project file, and do not parse it.
948 if (In_Limited or Limited_Withs)
949 and then Project_Stack.Last > 1
952 Canonical_Path_Name : Path_Name_Type;
955 Name_Len := Resolved_Path'Length;
956 Name_Buffer (1 .. Name_Len) := Resolved_Path;
957 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
958 Canonical_Path_Name := Name_Find;
960 for Index in 1 .. Project_Stack.Last loop
961 if Project_Stack.Table (Index).Canonical_Path_Name =
964 -- We have found the limited imported project,
965 -- get its project id, and do not parse it.
967 Withed_Project := Project_Stack.Table (Index).Id;
974 -- Parse the imported project if its project id is unknown
976 if No (Withed_Project) then
979 Project => Withed_Project,
980 Extends_All => Extends_All,
981 Path_Name_Id => Imported_Path_Name_Id,
983 From_Extended => From_Extended,
984 In_Limited => In_Limited or Limited_Withs,
985 Packages_To_Check => Packages_To_Check,
987 Current_Dir => Current_Dir,
988 Is_Config_File => Is_Config_File,
992 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
995 if No (Withed_Project) then
997 -- If parsing unsuccessful, remove the context clause
999 Current_Project := Previous_Project;
1001 if No (Current_Project) then
1002 Imported_Projects := Empty_Node;
1005 Set_Next_With_Clause_Of
1006 (Current_Project, In_Tree, Empty_Node);
1009 -- If parsing was successful, record project name and
1010 -- path name in with clause
1013 (Node => Current_Project,
1015 To => Withed_Project,
1016 Limited_With => Current_With.Limited_With);
1020 Name_Of (Withed_Project, In_Tree));
1022 Name_Len := Resolved_Path'Length;
1023 Name_Buffer (1 .. Name_Len) := Resolved_Path;
1024 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
1027 Set_Is_Extending_All (Current_Project, In_Tree);
1034 end Post_Parse_Context_Clause;
1036 ---------------------------------
1037 -- Check_Extending_All_Imports --
1038 ---------------------------------
1040 procedure Check_Extending_All_Imports
1041 (Flags : Processing_Flags;
1042 In_Tree : Project_Node_Tree_Ref;
1043 Project : Project_Node_Id)
1045 With_Clause : Project_Node_Id;
1046 Imported : Project_Node_Id;
1049 if not Is_Extending_All (Project, In_Tree) then
1050 With_Clause := First_With_Clause_Of (Project, In_Tree);
1051 while Present (With_Clause) loop
1052 Imported := Project_Node_Of (With_Clause, In_Tree);
1054 if Is_Extending_All (With_Clause, In_Tree) then
1055 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
1056 Error_Msg (Flags, "cannot import extending-all project %%",
1061 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1064 end Check_Extending_All_Imports;
1066 -----------------------------
1067 -- Check_Aggregate_Imports --
1068 -----------------------------
1070 procedure Check_Aggregate_Imports
1071 (Flags : Processing_Flags;
1072 In_Tree : Project_Node_Tree_Ref;
1073 Project : Project_Node_Id)
1075 With_Clause, Imported : Project_Node_Id;
1077 if Project_Qualifier_Of (Project, In_Tree) = Aggregate then
1078 With_Clause := First_With_Clause_Of (Project, In_Tree);
1080 while Present (With_Clause) loop
1081 Imported := Project_Node_Of (With_Clause, In_Tree);
1083 if Project_Qualifier_Of (Imported, In_Tree) /= Dry then
1084 Error_Msg_Name_1 := Name_Id (Path_Name_Of (Imported, In_Tree));
1085 Error_Msg (Flags, "can only import abstract projects, not %%",
1090 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1093 end Check_Aggregate_Imports;
1095 ----------------------------
1096 -- Read_Project_Qualifier --
1097 ----------------------------
1099 procedure Read_Project_Qualifier
1100 (Flags : Processing_Flags;
1101 In_Tree : Project_Node_Tree_Ref;
1102 Is_Config_File : Boolean;
1103 Qualifier_Location : out Source_Ptr;
1104 Project : Project_Node_Id)
1106 Proj_Qualifier : Project_Qualifier := Unspecified;
1108 Qualifier_Location := Token_Ptr;
1110 if Token = Tok_Abstract then
1111 Proj_Qualifier := Dry;
1114 elsif Token = Tok_Identifier then
1116 when Snames.Name_Standard =>
1117 Proj_Qualifier := Standard;
1120 when Snames.Name_Aggregate =>
1121 Proj_Qualifier := Aggregate;
1124 if Token = Tok_Identifier
1125 and then Token_Name = Snames.Name_Library
1127 Proj_Qualifier := Aggregate_Library;
1131 when Snames.Name_Library =>
1132 Proj_Qualifier := Library;
1135 when Snames.Name_Configuration =>
1136 if not Is_Config_File then
1139 "configuration projects cannot belong to a user" &
1144 Proj_Qualifier := Configuration;
1152 if Is_Config_File and then Proj_Qualifier = Unspecified then
1154 -- Set the qualifier to Configuration, even if the token doesn't
1155 -- exist in the source file itself, so that we can differentiate
1156 -- project files and configuration files later on.
1158 Proj_Qualifier := Configuration;
1161 if Proj_Qualifier /= Unspecified then
1163 and then Proj_Qualifier /= Configuration
1166 "a configuration project cannot be qualified except " &
1167 "as configuration project",
1168 Qualifier_Location);
1171 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1173 end Read_Project_Qualifier;
1175 -------------------------------
1176 -- Has_Circular_Dependencies --
1177 -------------------------------
1179 function Has_Circular_Dependencies
1180 (Flags : Processing_Flags;
1181 Normed_Path_Name : Path_Name_Type;
1182 Canonical_Path_Name : Path_Name_Type) return Boolean is
1184 for Index in reverse 1 .. Project_Stack.Last loop
1185 exit when Project_Stack.Table (Index).Limited_With;
1187 if Canonical_Path_Name =
1188 Project_Stack.Table (Index).Canonical_Path_Name
1190 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
1191 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
1192 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
1194 for Current in reverse 1 .. Project_Stack.Last loop
1196 Name_Id (Project_Stack.Table (Current).Path_Name);
1198 if Project_Stack.Table (Current).Canonical_Path_Name /=
1202 (Flags, "\ %% which itself is imported by", Token_Ptr);
1205 Error_Msg (Flags, "\ %%", Token_Ptr);
1214 end Has_Circular_Dependencies;
1216 --------------------------
1217 -- Parse_Single_Project --
1218 --------------------------
1220 procedure Parse_Single_Project
1221 (In_Tree : Project_Node_Tree_Ref;
1222 Project : out Project_Node_Id;
1223 Extends_All : out Boolean;
1224 Path_Name_Id : Path_Name_Type;
1226 From_Extended : Extension_Origin;
1227 In_Limited : Boolean;
1228 Packages_To_Check : String_List_Access;
1230 Current_Dir : String;
1231 Is_Config_File : Boolean;
1232 Env : in out Environment)
1234 Path_Name : constant String := Get_Name_String (Path_Name_Id);
1236 Normed_Path_Name : Path_Name_Type;
1237 Canonical_Path_Name : Path_Name_Type;
1238 Project_Directory : Path_Name_Type;
1239 Project_Scan_State : Saved_Project_Scan_State;
1240 Source_Index : Source_File_Index;
1242 Extending : Boolean := False;
1244 Extended_Project : Project_Node_Id := Empty_Node;
1246 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1247 Tree_Private_Part.Projects_Htable.Get_First
1248 (In_Tree.Projects_HT);
1250 Name_From_Path : constant Name_Id :=
1251 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
1252 Name_Of_Project : Name_Id := No_Name;
1253 Display_Name_Of_Project : Name_Id := No_Name;
1255 Duplicated : Boolean := False;
1257 First_With : With_Id;
1258 Imported_Projects : Project_Node_Id := Empty_Node;
1260 use Tree_Private_Part;
1262 Project_Comment_State : Tree.Comment_State;
1264 Qualifier_Location : Source_Ptr;
1267 Extends_All := False;
1270 Normed_Path : constant String := Normalize_Pathname
1272 Directory => Current_Dir,
1273 Resolve_Links => False,
1274 Case_Sensitive => True);
1275 Canonical_Path : constant String := Normalize_Pathname
1277 Directory => Current_Dir,
1278 Resolve_Links => Opt.Follow_Links_For_Files,
1279 Case_Sensitive => False);
1281 Name_Len := Normed_Path'Length;
1282 Name_Buffer (1 .. Name_Len) := Normed_Path;
1283 Normed_Path_Name := Name_Find;
1284 Name_Len := Canonical_Path'Length;
1285 Name_Buffer (1 .. Name_Len) := Canonical_Path;
1286 Canonical_Path_Name := Name_Find;
1289 if Has_Circular_Dependencies
1290 (Env.Flags, Normed_Path_Name, Canonical_Path_Name)
1292 Project := Empty_Node;
1296 -- Put the new path name on the stack
1298 Project_Stack.Append
1299 ((Path_Name => Normed_Path_Name,
1300 Canonical_Path_Name => Canonical_Path_Name,
1302 Limited_With => In_Limited));
1304 -- Check if the project file has already been parsed
1307 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1309 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1312 if A_Project_Name_And_Node.Extended then
1313 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1316 "cannot extend the same project file several times",
1322 "cannot extend an already imported project file",
1326 elsif A_Project_Name_And_Node.Extended then
1328 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1330 -- If the imported project is an extended project A, and we are
1331 -- in an extended project, replace A with the ultimate project
1334 if From_Extended /= None then
1336 Decl : Project_Node_Id :=
1337 Project_Declaration_Of
1338 (A_Project_Name_And_Node.Node, In_Tree);
1340 Prj : Project_Node_Id :=
1341 A_Project_Name_And_Node.Node;
1344 -- Loop through extending projects to find the ultimate
1345 -- extending project, that is the one that is not
1346 -- extended. For an abstract project, as it can be
1347 -- extended several times, there is no extending project
1348 -- registered, so the loop does not execute and the
1349 -- resulting project is the abstract project.
1352 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1354 Prj := Extending_Project_Of (Decl, In_Tree);
1355 Decl := Project_Declaration_Of (Prj, In_Tree);
1358 A_Project_Name_And_Node.Node := Prj;
1363 "cannot import an already extended project file",
1368 Project := A_Project_Name_And_Node.Node;
1369 Project_Stack.Decrement_Last;
1373 A_Project_Name_And_Node :=
1374 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1377 -- We never encountered this project file. Save the scan state, load the
1378 -- project file and start to scan it.
1380 Save_Project_Scan_State (Project_Scan_State);
1381 Source_Index := Load_Project_File (Path_Name);
1382 Tree.Save (Project_Comment_State);
1384 -- If we cannot find it, we stop
1386 if Source_Index = No_Source_File then
1387 Project := Empty_Node;
1388 Project_Stack.Decrement_Last;
1392 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1396 if not Is_Config_File and then Name_From_Path = No_Name then
1398 -- The project file name is not correct (no or bad extension, or not
1399 -- following Ada identifier's syntax).
1401 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1402 Error_Msg (Env.Flags,
1403 "?{ is not a valid path name for a project file",
1407 if Current_Verbosity >= Medium then
1408 Debug_Increase_Indent ("Parsing """ & Path_Name & '"');
1411 Project_Directory :=
1412 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1414 -- Is there any imported project?
1416 Pre_Parse_Context_Clause
1417 (In_Tree => In_Tree,
1418 Is_Config_File => Is_Config_File,
1419 Context_Clause => First_With,
1420 Flags => Env.Flags);
1422 Project := Default_Project_Node
1423 (Of_Kind => N_Project, In_Tree => In_Tree);
1424 Project_Stack.Table (Project_Stack.Last).Id := Project;
1425 Set_Directory_Of (Project, In_Tree, Project_Directory);
1426 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1428 Read_Project_Qualifier
1429 (Env.Flags, In_Tree, Is_Config_File, Qualifier_Location, Project);
1431 Set_Location_Of (Project, In_Tree, Token_Ptr);
1433 Expect (Tok_Project, "PROJECT
");
1435 -- Mark location of PROJECT token if present
1437 if Token = Tok_Project then
1438 Scan (In_Tree); -- past PROJECT
1439 Set_Location_Of (Project, In_Tree, Token_Ptr);
1446 Expect (Tok_Identifier, "identifier
");
1448 -- If the token is not an identifier, clear the buffer before
1449 -- exiting to indicate that the name of the project is ill-formed.
1451 if Token /= Tok_Identifier then
1456 -- Add the identifier name to the buffer
1458 Get_Name_String (Token_Name);
1459 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1461 -- Scan past the identifier
1465 -- If we have a dot, add a dot to the Buffer and look for the next
1468 exit when Token /= Tok_Dot;
1469 Add_To_Buffer (".", Buffer, Buffer_Last);
1471 -- Scan past the dot
1476 -- See if this is an extending project
1478 if Token = Tok_Extends then
1480 if Is_Config_File then
1483 "extending configuration project
not allowed
", Token_Ptr);
1486 -- Make sure that gnatmake will use mapping files
1488 Opt.Create_Mapping_File := True;
1490 -- We are extending another project
1494 Scan (In_Tree); -- past EXTENDS
1496 if Token = Tok_All then
1497 Extends_All := True;
1498 Set_Is_Extending_All (Project, In_Tree);
1499 Scan (In_Tree); -- scan past ALL
1503 -- If the name is well formed, Buffer_Last is > 0
1505 if Buffer_Last > 0 then
1507 -- The Buffer contains the name of the project
1509 Name_Len := Buffer_Last;
1510 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1511 Name_Of_Project := Name_Find;
1512 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1514 -- To get expected name of the project file, replace dots by dashes
1516 for Index in 1 .. Name_Len loop
1517 if Name_Buffer (Index) = '.' then
1518 Name_Buffer (Index) := '-';
1522 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1525 Expected_Name : constant Name_Id := Name_Find;
1526 Extension : String_Access;
1529 -- Output a warning if the actual name is not the expected name
1531 if not Is_Config_File
1532 and then (Name_From_Path /= No_Name)
1533 and then Expected_Name /= Name_From_Path
1535 Error_Msg_Name_1 := Expected_Name;
1537 if Is_Config_File then
1538 Extension := new String'(Config_Project_File_Extension);
1541 Extension := new String'(Project_File_Extension);
1546 "?file name does
not match project name
, should be `
%%"
1547 & Extension.all & "`
",
1552 -- Read the original casing of the project name
1558 Loc := Location_Of (Project, In_Tree);
1559 for J in 1 .. Name_Len loop
1560 Name_Buffer (J) := Sinput.Source (Loc);
1564 Display_Name_Of_Project := Name_Find;
1568 From_Ext : Extension_Origin := None;
1571 -- Extending_All is always propagated
1573 if From_Extended = Extending_All or else Extends_All then
1574 From_Ext := Extending_All;
1576 -- Otherwise, From_Extended is set to Extending_Single if the
1577 -- current project is an extending project.
1580 From_Ext := Extending_Simple;
1583 Post_Parse_Context_Clause
1584 (In_Tree => In_Tree,
1585 Context_Clause => First_With,
1586 In_Limited => In_Limited,
1587 Limited_Withs => False,
1588 Imported_Projects => Imported_Projects,
1589 Project_Directory => Project_Directory,
1590 From_Extended => From_Ext,
1591 Packages_To_Check => Packages_To_Check,
1593 Current_Dir => Current_Dir,
1594 Is_Config_File => Is_Config_File,
1596 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1599 if not Is_Config_File then
1601 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1602 Tree_Private_Part.Projects_Htable.Get_First
1603 (In_Tree.Projects_HT);
1604 Project_Name : Name_Id := Name_And_Node.Name;
1607 -- Check if we already have a project with this name
1609 while Project_Name /= No_Name
1610 and then Project_Name /= Name_Of_Project
1613 Tree_Private_Part.Projects_Htable.Get_Next
1614 (In_Tree.Projects_HT);
1615 Project_Name := Name_And_Node.Name;
1618 -- Report an error if we already have a project with this name
1620 if Project_Name /= No_Name then
1622 Error_Msg_Name_1 := Project_Name;
1624 (Env.Flags, "duplicate project name
%%",
1625 Location_Of (Project, In_Tree));
1627 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1630 "\already
in %%", Location_Of (Project, In_Tree));
1638 Expect (Tok_String_Literal, "literal
string");
1640 if Token = Tok_String_Literal then
1641 Set_Extended_Project_Path_Of
1644 Path_Name_Type (Token_Name));
1647 Original_Path_Name : constant String :=
1648 Get_Name_String (Token_Name);
1650 Extended_Project_Path_Name_Id : Path_Name_Type;
1655 Project_File_Name => Original_Path_Name,
1656 Directory => Get_Name_String (Project_Directory),
1657 Path => Extended_Project_Path_Name_Id);
1659 if Extended_Project_Path_Name_Id = No_Path then
1661 -- We could not find the project file to extend
1663 Error_Msg_Name_1 := Token_Name;
1665 Error_Msg (Env.Flags, "unknown project file
: %%", Token_Ptr);
1667 -- If not in the main project file, display the import path
1669 if Project_Stack.Last > 1 then
1672 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1673 Error_Msg (Env.Flags, "\extended by
%%", Token_Ptr);
1675 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1678 (Project_Stack.Table (Index).Path_Name);
1679 Error_Msg (Env.Flags, "\imported by
%%", Token_Ptr);
1685 From_Ext : Extension_Origin := None;
1688 if From_Extended = Extending_All or else Extends_All then
1689 From_Ext := Extending_All;
1692 Parse_Single_Project
1693 (In_Tree => In_Tree,
1694 Project => Extended_Project,
1695 Extends_All => Extends_All,
1696 Path_Name_Id => Extended_Project_Path_Name_Id,
1698 From_Extended => From_Ext,
1699 In_Limited => In_Limited,
1700 Packages_To_Check => Packages_To_Check,
1702 Current_Dir => Current_Dir,
1703 Is_Config_File => Is_Config_File,
1707 if Present (Extended_Project) then
1709 -- A project that extends an extending-all project is
1710 -- also an extending-all project.
1712 if Is_Extending_All (Extended_Project, In_Tree) then
1713 Set_Is_Extending_All (Project, In_Tree);
1716 -- An abstract project can only extend an abstract
1717 -- project. Otherwise we may have an abstract project
1718 -- with sources if it inherits sources from the project
1721 if Project_Qualifier_Of (Project, In_Tree) = Dry and then
1722 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1725 (Env.Flags, "an
abstract project can only extend
" &
1726 "another
abstract project
",
1727 Qualifier_Location);
1733 Scan (In_Tree); -- past the extended project path
1737 Check_Extending_All_Imports (Env.Flags, In_Tree, Project);
1738 Check_Aggregate_Imports (Env.Flags, In_Tree, Project);
1740 -- Check that a project with a name including a dot either imports
1741 -- or extends the project whose name precedes the last dot.
1743 if Name_Of_Project /= No_Name then
1744 Get_Name_String (Name_Of_Project);
1750 -- Look for the last dot
1752 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1753 Name_Len := Name_Len - 1;
1756 -- If a dot was found, check if parent project is imported or extended
1758 if Name_Len > 0 then
1759 Name_Len := Name_Len - 1;
1762 Parent_Name : constant Name_Id := Name_Find;
1763 Parent_Found : Boolean := False;
1764 Parent_Node : Project_Node_Id := Empty_Node;
1765 With_Clause : Project_Node_Id :=
1766 First_With_Clause_Of (Project, In_Tree);
1767 Imp_Proj_Name : Name_Id;
1770 -- If there is an extended project, check its name
1772 if Present (Extended_Project) then
1773 Parent_Node := Extended_Project;
1775 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1778 -- If the parent project is not the extended project,
1779 -- check each imported project until we find the parent project.
1782 while not Parent_Found and then Present (With_Clause) loop
1783 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1784 Extension_Loop : while Present (Parent_Node) loop
1785 Imp_Proj_Name := Name_Of (Parent_Node, In_Tree);
1786 Parent_Found := Imp_Proj_Name = Parent_Name;
1787 exit Imported_Loop when Parent_Found;
1790 (Project_Declaration_Of (Parent_Node, In_Tree),
1792 end loop Extension_Loop;
1794 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1795 end loop Imported_Loop;
1797 if Parent_Found then
1798 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1801 -- If the parent project was not found, report an error
1803 Error_Msg_Name_1 := Name_Of_Project;
1804 Error_Msg_Name_2 := Parent_Name;
1805 Error_Msg (Env.Flags,
1806 "project
%% does
not import
or extend project
%%",
1807 Location_Of (Project, In_Tree));
1812 Expect (Tok_Is, "IS");
1813 Set_End_Of_Line (Project);
1814 Set_Previous_Line_Node (Project);
1815 Set_Next_End_Node (Project);
1818 Project_Declaration : Project_Node_Id := Empty_Node;
1821 -- No need to Scan past "is", Prj.Dect.Parse will do it
1824 (In_Tree => In_Tree,
1825 Declarations => Project_Declaration,
1826 Current_Project => Project,
1827 Extends => Extended_Project,
1828 Packages_To_Check => Packages_To_Check,
1829 Is_Config_File => Is_Config_File,
1830 Flags => Env.Flags);
1831 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1833 if Present (Extended_Project)
1834 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1836 Set_Extending_Project_Of
1837 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1842 Expect (Tok_End, "END");
1843 Remove_Next_End_Node;
1845 -- Skip "end" if present
1847 if Token = Tok_End then
1855 -- Store the name following "end" in the Buffer. The name may be made of
1856 -- several simple names.
1859 Expect (Tok_Identifier, "identifier
");
1861 -- If we don't have an identifier, clear the buffer before exiting to
1862 -- avoid checking the name.
1864 if Token /= Tok_Identifier then
1869 -- Add the identifier to the Buffer
1870 Get_Name_String (Token_Name);
1871 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1873 -- Scan past the identifier
1876 exit when Token /= Tok_Dot;
1877 Add_To_Buffer (".", Buffer, Buffer_Last);
1881 -- If we have a valid name, check if it is the name of the project
1883 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1884 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1885 Get_Name_String (Name_Of (Project, In_Tree))
1887 -- Invalid name: report an error
1889 Error_Msg (Env.Flags, "expected
""" &
1890 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1895 Expect (Tok_Semicolon, "`
;`
");
1897 -- Check that there is no more text following the end of the project
1900 if Token = Tok_Semicolon then
1901 Set_Previous_End_Node (Project);
1904 if Token /= Tok_EOF then
1907 "unexpected text following
end of project
", Token_Ptr);
1911 if not Duplicated and then Name_Of_Project /= No_Name then
1913 -- Add the name of the project to the hash table, so that we can
1914 -- check that no other subsequent project will have the same name.
1916 Tree_Private_Part.Projects_Htable.Set
1917 (T => In_Tree.Projects_HT,
1918 K => Name_Of_Project,
1919 E => (Name => Name_Of_Project,
1920 Display_Name => Display_Name_Of_Project,
1922 Canonical_Path => Canonical_Path_Name,
1923 Extended => Extended,
1924 Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
1928 From_Ext : Extension_Origin := None;
1931 -- Extending_All is always propagated
1933 if From_Extended = Extending_All or else Extends_All then
1934 From_Ext := Extending_All;
1936 -- Otherwise, From_Extended is set to Extending_Single if the
1937 -- current project is an extending project.
1940 From_Ext := Extending_Simple;
1943 Post_Parse_Context_Clause
1944 (In_Tree => In_Tree,
1945 Context_Clause => First_With,
1946 In_Limited => In_Limited,
1947 Limited_Withs => True,
1948 Imported_Projects => Imported_Projects,
1949 Project_Directory => Project_Directory,
1950 From_Extended => From_Ext,
1951 Packages_To_Check => Packages_To_Check,
1953 Current_Dir => Current_Dir,
1954 Is_Config_File => Is_Config_File,
1956 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1959 -- Restore the scan state, in case we are not the main project
1961 Restore_Project_Scan_State (Project_Scan_State);
1963 -- And remove the project from the project stack
1965 Project_Stack.Decrement_Last;
1967 -- Indicate if there are unkept comments
1969 Tree.Set_Project_File_Includes_Unkept_Comments
1972 To => Tree.There_Are_Unkept_Comments);
1974 -- And restore the comment state that was saved
1976 Tree.Restore_And_Free (Project_Comment_State);
1978 Debug_Decrease_Indent;
1979 end Parse_Single_Project;
1981 -----------------------
1982 -- Project_Name_From --
1983 -----------------------
1985 function Project_Name_From
1986 (Path_Name : String;
1987 Is_Config_File : Boolean) return Name_Id
1989 Canonical : String (1 .. Path_Name'Length) := Path_Name;
1990 First : Natural := Canonical'Last;
1991 Last : Natural := First;
1995 if Current_Verbosity = High then
1996 Debug_Output ("Project_Name_From
(""" & Canonical & """)");
1999 -- If the path name is empty, return No_Name to indicate failure
2005 Canonical_Case_File_Name (Canonical);
2007 -- Look for the last dot in the path name
2011 Canonical (First) /= '.'
2016 -- If we have a dot, check that it is followed by the correct extension
2018 if First > 0 and then Canonical (First) = '.' then
2019 if (not Is_Config_File
2020 and then Canonical (First .. Last) = Project_File_Extension
2021 and then First /= 1)
2025 Canonical (First .. Last) = Config_Project_File_Extension
2026 and then First /= 1)
2028 -- Look for the last directory separator, if any
2033 and then Canonical (First) /= '/'
2034 and then Canonical (First) /= Dir_Sep
2040 -- Not the correct extension, return No_Name to indicate failure
2045 -- If no dot in the path name, return No_Name to indicate failure
2053 -- If the extension is the file name, return No_Name to indicate failure
2055 if First > Last then
2059 -- Put the name in lower case into Name_Buffer
2061 Name_Len := Last - First + 1;
2062 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
2066 -- Check if it is a well formed project name. Return No_Name if it is
2070 if not Is_Letter (Name_Buffer (Index)) then
2077 exit when Index >= Name_Len;
2079 if Name_Buffer (Index) = '_' then
2080 if Name_Buffer (Index + 1) = '_' then
2085 exit when Name_Buffer (Index) = '-';
2087 if Name_Buffer (Index) /= '_'
2088 and then not Is_Alphanumeric (Name_Buffer (Index))
2096 if Index >= Name_Len then
2097 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
2099 -- All checks have succeeded. Return name in Name_Buffer
2107 elsif Name_Buffer (Index) = '-' then
2111 end Project_Name_From;