1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars
; use Err_Vars
;
28 with Osint
; use Osint
;
29 with Output
; use Output
;
30 with Prj
.Com
; use Prj
.Com
;
32 with Prj
.Env
; use Prj
.Env
;
33 with Prj
.Err
; use Prj
.Err
;
34 with Sinput
; use Sinput
;
35 with Sinput
.P
; use Sinput
.P
;
39 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
40 with Ada
.Exceptions
; use Ada
.Exceptions
;
42 with GNAT
.HTable
; use GNAT
.HTable
;
44 package body Prj
.Part
is
46 Buffer
: String_Access
;
47 Buffer_Last
: Natural := 0;
49 Dir_Sep
: Character renames GNAT
.OS_Lib
.Directory_Separator
;
51 ------------------------------------
52 -- Local Packages and Subprograms --
53 ------------------------------------
55 type With_Id
is new Nat
;
56 No_With
: constant With_Id
:= 0;
58 type With_Record
is record
59 Path
: Path_Name_Type
;
60 Location
: Source_Ptr
;
61 Limited_With
: Boolean;
62 Node
: Project_Node_Id
;
65 -- Information about an imported project, to be put in table Withs below
67 package Withs
is new Table
.Table
68 (Table_Component_Type
=> With_Record
,
69 Table_Index_Type
=> With_Id
,
72 Table_Increment
=> 100,
73 Table_Name
=> "Prj.Part.Withs");
74 -- Table used to store temporarily paths and locations of imported
75 -- projects. These imported projects will be effectively parsed later: just
76 -- before parsing the current project for the non limited withed projects,
77 -- after getting its name; after complete parsing of the current project
78 -- for the limited withed projects.
80 type Names_And_Id
is record
81 Path_Name
: Path_Name_Type
;
82 Canonical_Path_Name
: Path_Name_Type
;
84 Limited_With
: Boolean;
87 package Project_Stack
is new Table
.Table
88 (Table_Component_Type
=> Names_And_Id
,
89 Table_Index_Type
=> Nat
,
92 Table_Increment
=> 100,
93 Table_Name
=> "Prj.Part.Project_Stack");
94 -- This table is used to detect circular dependencies
95 -- for imported and extended projects and to get the project ids of
96 -- limited imported projects when there is a circularity with at least
97 -- one limited imported project file.
99 package Virtual_Hash
is new GNAT
.HTable
.Simple_HTable
100 (Header_Num
=> Header_Num
,
101 Element
=> Project_Node_Id
,
102 No_Element
=> Empty_Node
,
103 Key
=> Project_Node_Id
,
104 Hash
=> Prj
.Tree
.Hash
,
106 -- Hash table to store the node id of the project for which a virtual
107 -- extending project need to be created.
109 package Processed_Hash
is new GNAT
.HTable
.Simple_HTable
110 (Header_Num
=> Header_Num
,
113 Key
=> Project_Node_Id
,
114 Hash
=> Prj
.Tree
.Hash
,
116 -- Hash table to store the project process when looking for project that
117 -- need to have a virtual extending project, to avoid processing the same
120 function Has_Circular_Dependencies
121 (Flags
: Processing_Flags
;
122 Normed_Path_Name
: Path_Name_Type
;
123 Canonical_Path_Name
: Path_Name_Type
) return Boolean;
124 -- Check for a circular dependency in the loaded project.
125 -- Generates an error message in such a case.
127 procedure Read_Project_Qualifier
128 (Flags
: Processing_Flags
;
129 In_Tree
: Project_Node_Tree_Ref
;
130 Is_Config_File
: Boolean;
131 Qualifier_Location
: out Source_Ptr
;
132 Project
: Project_Node_Id
);
133 -- Check if there is a qualifier before the reserved word "project"
135 -- Hash table to cache project path to avoid looking for them on the path
137 procedure Check_Extending_All_Imports
138 (Flags
: Processing_Flags
;
139 In_Tree
: Project_Node_Tree_Ref
;
140 Project
: Project_Node_Id
);
141 -- Check that a non extending-all project does not import an
142 -- extending-all project.
144 procedure Check_Aggregate_Imports
145 (Flags
: Processing_Flags
;
146 In_Tree
: Project_Node_Tree_Ref
;
147 Project
: Project_Node_Id
);
148 -- Check that an aggregate project only imports abstract projects
150 procedure Create_Virtual_Extending_Project
151 (For_Project
: Project_Node_Id
;
152 Main_Project
: Project_Node_Id
;
153 In_Tree
: Project_Node_Tree_Ref
);
154 -- Create a virtual extending project of For_Project. Main_Project is
155 -- the extending all project.
157 -- The String_Value_Of is not set for the automatically added with
158 -- clause and keeps the default value of No_Name. This enables Prj.PP
159 -- to skip these automatically added with clauses to be processed.
161 procedure Look_For_Virtual_Projects_For
162 (Proj
: Project_Node_Id
;
163 In_Tree
: Project_Node_Tree_Ref
;
164 Potentially_Virtual
: Boolean);
165 -- Look for projects that need to have a virtual extending project.
166 -- This procedure is recursive. If called with Potentially_Virtual set to
167 -- True, then Proj may need an virtual extending project; otherwise it
168 -- does not (because it is already extended), but other projects that it
169 -- imports may need to be virtually extended.
171 type Extension_Origin
is (None
, Extending_Simple
, Extending_All
);
172 -- Type of parameter From_Extended for procedures Parse_Single_Project and
173 -- Post_Parse_Context_Clause. Extending_All means that we are parsing the
174 -- tree rooted at an extending all project.
176 procedure Parse_Single_Project
177 (In_Tree
: Project_Node_Tree_Ref
;
178 Project
: out Project_Node_Id
;
179 Extends_All
: out Boolean;
180 Path_Name_Id
: Path_Name_Type
;
182 From_Extended
: Extension_Origin
;
183 In_Limited
: Boolean;
184 Packages_To_Check
: String_List_Access
;
186 Current_Dir
: String;
187 Is_Config_File
: Boolean;
188 Flags
: Processing_Flags
);
189 -- Parse a project file. This is a recursive procedure: it calls itself for
190 -- imported and extended projects. When From_Extended is not None, if the
191 -- project has already been parsed and is an extended project A, return the
192 -- ultimate (not extended) project that extends A. When In_Limited is True,
193 -- the importing path includes at least one "limited with". When parsing
194 -- configuration projects, do not allow a depth > 1.
196 -- Is_Config_File should be set to True if the project represents a config
197 -- file (.cgpr) since some specific checks apply.
199 procedure Pre_Parse_Context_Clause
200 (In_Tree
: Project_Node_Tree_Ref
;
201 Context_Clause
: out With_Id
;
202 Is_Config_File
: Boolean;
203 Flags
: Processing_Flags
);
204 -- Parse the context clause of a project. Store the paths and locations of
205 -- the imported projects in table Withs. Does nothing if there is no
206 -- context clause (if the current token is not "with" or "limited" followed
208 -- Is_Config_File should be set to True if the project represents a config
209 -- file (.cgpr) since some specific checks apply.
211 procedure Post_Parse_Context_Clause
212 (Context_Clause
: With_Id
;
213 In_Tree
: Project_Node_Tree_Ref
;
214 Limited_Withs
: Boolean;
215 Imported_Projects
: in out Project_Node_Id
;
216 Project_Directory
: Path_Name_Type
;
217 From_Extended
: Extension_Origin
;
218 In_Limited
: Boolean;
219 Packages_To_Check
: String_List_Access
;
221 Current_Dir
: String;
222 Is_Config_File
: Boolean;
223 Flags
: Processing_Flags
);
224 -- Parse the imported projects that have been stored in table Withs, if
225 -- any. From_Extended is used for the call to Parse_Single_Project below.
226 -- When In_Limited is True, the importing path includes at least one
227 -- "limited with". When Limited_Withs is False, only non limited withed
228 -- projects are parsed. When Limited_Withs is True, only limited withed
229 -- projects are parsed.
230 -- Is_Config_File should be set to True if the project represents a config
231 -- file (.cgpr) since some specific checks apply.
233 function Project_Name_From
235 Is_Config_File
: Boolean) return Name_Id
;
236 -- Returns the name of the project that corresponds to its path name.
237 -- Returns No_Name if the path name is invalid, because the corresponding
238 -- project name does not have the syntax of an ada identifier.
240 --------------------------------------
241 -- Create_Virtual_Extending_Project --
242 --------------------------------------
244 procedure Create_Virtual_Extending_Project
245 (For_Project
: Project_Node_Id
;
246 Main_Project
: Project_Node_Id
;
247 In_Tree
: Project_Node_Tree_Ref
)
250 Virtual_Name
: constant String :=
252 Get_Name_String
(Name_Of
(For_Project
, In_Tree
));
253 -- The name of the virtual extending project
255 Virtual_Name_Id
: Name_Id
;
256 -- Virtual extending project name id
258 Virtual_Path_Id
: Path_Name_Type
;
259 -- Fake path name of the virtual extending project. The directory is
260 -- the same directory as the extending all project.
262 -- The source of the virtual extending project is something like:
264 -- project V$<project name> extends <project path> is
266 -- for Source_Dirs use ();
268 -- end V$<project name>;
270 -- The project directory cannot be specified during parsing; it will be
271 -- put directly in the virtual extending project data during processing.
273 -- Nodes that made up the virtual extending project
275 Virtual_Project
: Project_Node_Id
;
276 With_Clause
: constant Project_Node_Id
:=
278 (In_Tree
, N_With_Clause
);
279 Project_Declaration
: Project_Node_Id
;
280 Source_Dirs_Declaration
: constant Project_Node_Id
:=
282 (In_Tree
, N_Declarative_Item
);
283 Source_Dirs_Attribute
: constant Project_Node_Id
:=
285 (In_Tree
, N_Attribute_Declaration
, List
);
286 Source_Dirs_Expression
: constant Project_Node_Id
:=
288 (In_Tree
, N_Expression
, List
);
289 Source_Dirs_Term
: constant Project_Node_Id
:=
291 (In_Tree
, N_Term
, List
);
292 Source_Dirs_List
: constant Project_Node_Id
:=
294 (In_Tree
, N_Literal_String_List
, List
);
297 -- Get the virtual path name
299 Get_Name_String
(Path_Name_Of
(Main_Project
, In_Tree
));
302 and then Name_Buffer
(Name_Len
) /= Directory_Separator
303 and then Name_Buffer
(Name_Len
) /= '/'
305 Name_Len
:= Name_Len
- 1;
308 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Virtual_Name
'Length) :=
310 Name_Len
:= Name_Len
+ Virtual_Name
'Length;
311 Virtual_Path_Id
:= Name_Find
;
313 -- Get the virtual name id
315 Name_Len
:= Virtual_Name
'Length;
316 Name_Buffer
(1 .. Name_Len
) := Virtual_Name
;
317 Virtual_Name_Id
:= Name_Find
;
319 Virtual_Project
:= Create_Project
321 Name
=> Virtual_Name_Id
,
322 Full_Path
=> Virtual_Path_Id
,
323 Is_Config_File
=> False);
325 Project_Declaration
:= Project_Declaration_Of
(Virtual_Project
, In_Tree
);
329 Set_Name_Of
(With_Clause
, In_Tree
, Virtual_Name_Id
);
330 Set_Path_Name_Of
(With_Clause
, In_Tree
, Virtual_Path_Id
);
331 Set_Project_Node_Of
(With_Clause
, In_Tree
, Virtual_Project
);
332 Set_Next_With_Clause_Of
333 (With_Clause
, In_Tree
, First_With_Clause_Of
(Main_Project
, In_Tree
));
334 Set_First_With_Clause_Of
(Main_Project
, In_Tree
, With_Clause
);
336 -- Virtual project node
339 (Virtual_Project
, In_Tree
, Location_Of
(Main_Project
, In_Tree
));
340 Set_Extended_Project_Path_Of
341 (Virtual_Project
, In_Tree
, Path_Name_Of
(For_Project
, In_Tree
));
343 -- Project declaration
345 Set_First_Declarative_Item_Of
346 (Project_Declaration
, In_Tree
, Source_Dirs_Declaration
);
347 Set_Extended_Project_Of
(Project_Declaration
, In_Tree
, For_Project
);
349 -- Source_Dirs declaration
351 Set_Current_Item_Node
352 (Source_Dirs_Declaration
, In_Tree
, Source_Dirs_Attribute
);
354 -- Source_Dirs attribute
356 Set_Name_Of
(Source_Dirs_Attribute
, In_Tree
, Snames
.Name_Source_Dirs
);
358 (Source_Dirs_Attribute
, In_Tree
, Source_Dirs_Expression
);
360 -- Source_Dirs expression
362 Set_First_Term
(Source_Dirs_Expression
, In_Tree
, Source_Dirs_Term
);
366 Set_Current_Term
(Source_Dirs_Term
, In_Tree
, Source_Dirs_List
);
368 -- Source_Dirs empty list: nothing to do
369 end Create_Virtual_Extending_Project
;
371 -----------------------------------
372 -- Look_For_Virtual_Projects_For --
373 -----------------------------------
375 procedure Look_For_Virtual_Projects_For
376 (Proj
: Project_Node_Id
;
377 In_Tree
: Project_Node_Tree_Ref
;
378 Potentially_Virtual
: Boolean)
380 Declaration
: Project_Node_Id
:= Empty_Node
;
381 -- Node for the project declaration of Proj
383 With_Clause
: Project_Node_Id
:= Empty_Node
;
384 -- Node for a with clause of Proj
386 Imported
: Project_Node_Id
:= Empty_Node
;
387 -- Node for a project imported by Proj
389 Extended
: Project_Node_Id
:= Empty_Node
;
390 -- Node for the eventual project extended by Proj
393 -- Nothing to do if Proj is not defined or if it has already been
396 if Present
(Proj
) and then not Processed_Hash
.Get
(Proj
) then
397 -- Make sure the project will not be processed again
399 Processed_Hash
.Set
(Proj
, True);
401 Declaration
:= Project_Declaration_Of
(Proj
, In_Tree
);
403 if Present
(Declaration
) then
404 Extended
:= Extended_Project_Of
(Declaration
, In_Tree
);
407 -- If this is a project that may need a virtual extending project
408 -- and it is not itself an extending project, put it in the list.
410 if Potentially_Virtual
and then No
(Extended
) then
411 Virtual_Hash
.Set
(Proj
, Proj
);
414 -- Now check the projects it imports
416 With_Clause
:= First_With_Clause_Of
(Proj
, In_Tree
);
418 while Present
(With_Clause
) loop
419 Imported
:= Project_Node_Of
(With_Clause
, In_Tree
);
421 if Present
(Imported
) then
422 Look_For_Virtual_Projects_For
423 (Imported
, In_Tree
, Potentially_Virtual
=> True);
426 With_Clause
:= Next_With_Clause_Of
(With_Clause
, In_Tree
);
429 -- Check also the eventual project extended by Proj. As this project
430 -- is already extended, call recursively with Potentially_Virtual
433 Look_For_Virtual_Projects_For
434 (Extended
, In_Tree
, Potentially_Virtual
=> False);
436 end Look_For_Virtual_Projects_For
;
443 (In_Tree
: Project_Node_Tree_Ref
;
444 Project
: out Project_Node_Id
;
445 Project_File_Name
: String;
446 Always_Errout_Finalize
: Boolean;
447 Packages_To_Check
: String_List_Access
:= All_Packages
;
448 Store_Comments
: Boolean := False;
449 Current_Directory
: String := "";
450 Is_Config_File
: Boolean;
451 Flags
: Processing_Flags
)
454 pragma Warnings
(Off
, Dummy
);
456 Real_Project_File_Name
: String_Access
:=
457 Osint
.To_Canonical_File_Spec
459 Path_Name_Id
: Path_Name_Type
;
462 if Real_Project_File_Name
= null then
463 Real_Project_File_Name
:= new String'(Project_File_Name);
466 Project := Empty_Node;
468 Find_Project (In_Tree.Project_Path,
469 Project_File_Name => Real_Project_File_Name.all,
470 Directory => Current_Directory,
471 Path => Path_Name_Id);
472 Free (Real_Project_File_Name);
475 Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
476 Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
478 if Path_Name_Id = No_Path then
482 Get_Path (In_Tree.Project_Path, Path => P);
488 Project := Empty_Node;
493 -- Parse the main project file
499 Extends_All => Dummy,
500 Path_Name_Id => Path_Name_Id,
502 From_Extended => None,
504 Packages_To_Check => Packages_To_Check,
506 Current_Dir => Current_Directory,
507 Is_Config_File => Is_Config_File,
511 when Types.Unrecoverable_Error =>
513 -- Unrecoverable_Error is raised when a line is too long.
514 -- A meaningful error message will be displayed later.
516 Project := Empty_Node;
519 -- If Project is an extending-all project, create the eventual
520 -- virtual extending projects and check that there are no illegally
521 -- imported projects.
524 and then Is_Extending_All (Project, In_Tree)
526 -- First look for projects that potentially need a virtual
527 -- extending project.
530 Processed_Hash.Reset;
532 -- Mark the extending all project as processed, to avoid checking
533 -- the imported projects in case of a "limited with" on this
534 -- extending all project.
536 Processed_Hash.Set (Project, True);
539 Declaration : constant Project_Node_Id :=
540 Project_Declaration_Of (Project, In_Tree);
542 Look_For_Virtual_Projects_For
543 (Extended_Project_Of (Declaration, In_Tree), In_Tree,
544 Potentially_Virtual => False);
547 -- Now, check the projects directly imported by the main project.
548 -- Remove from the potentially virtual any project extended by one
549 -- of these imported projects. For non extending imported projects,
550 -- check that they do not belong to the project tree of the project
551 -- being "extended-all" by the main project.
554 With_Clause : Project_Node_Id;
555 Imported : Project_Node_Id := Empty_Node;
556 Declaration : Project_Node_Id := Empty_Node;
559 With_Clause := First_With_Clause_Of (Project, In_Tree);
560 while Present (With_Clause) loop
561 Imported := Project_Node_Of (With_Clause, In_Tree);
563 if Present (Imported) then
564 Declaration := Project_Declaration_Of (Imported, In_Tree);
566 if Extended_Project_Of (Declaration, In_Tree) /=
571 Extended_Project_Of (Declaration, In_Tree);
572 exit when No (Imported);
573 Virtual_Hash.Remove (Imported);
575 Project_Declaration_Of (Imported, In_Tree);
580 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
584 -- Now create all the virtual extending projects
587 Proj : Project_Node_Id := Virtual_Hash.Get_First;
589 while Present (Proj) loop
590 Create_Virtual_Extending_Project (Proj, Project, In_Tree);
591 Proj := Virtual_Hash.Get_Next;
596 -- If there were any kind of error during the parsing, serious
597 -- or not, then the parsing fails.
599 if Err_Vars.Total_Errors_Detected > 0 then
600 Project := Empty_Node;
603 if No (Project) or else Always_Errout_Finalize then
606 -- Reinitialize to avoid duplicate warnings later on
616 Write_Line (Exception_Information (X));
617 Write_Str ("Exception ");
618 Write_Str (Exception_Name (X));
619 Write_Line (" raised, while processing project file");
620 Project := Empty_Node;
623 ------------------------------
624 -- Pre_Parse_Context_Clause --
625 ------------------------------
627 procedure Pre_Parse_Context_Clause
628 (In_Tree : Project_Node_Tree_Ref;
629 Context_Clause : out With_Id;
630 Is_Config_File : Boolean;
631 Flags : Processing_Flags)
633 Current_With_Clause : With_Id := No_With;
634 Limited_With : Boolean := False;
635 Current_With : With_Record;
636 Current_With_Node : Project_Node_Id := Empty_Node;
639 -- Assume no context clause
641 Context_Clause := No_With;
644 -- If Token is not WITH or LIMITED, there is no context clause, or we
645 -- have exhausted the with clauses.
647 while Token = Tok_With or else Token = Tok_Limited loop
649 Default_Project_Node (Of_Kind => N_With_Clause, In_Tree => In_Tree);
650 Limited_With := Token = Tok_Limited;
652 if Is_Config_File then
655 "configuration project cannot import " &
656 "other configuration projects",
661 Scan (In_Tree); -- scan past LIMITED
662 Expect (Tok_With, "WITH");
663 exit With_Loop when Token /= Tok_With;
668 Scan (In_Tree); -- past WITH or ","
670 Expect (Tok_String_Literal, "literal string");
672 if Token /= Tok_String_Literal then
676 -- Store path and location in table Withs
679 (Path => Path_Name_Type (Token_Name),
680 Location => Token_Ptr,
681 Limited_With => Limited_With,
682 Node => Current_With_Node,
685 Withs.Increment_Last;
686 Withs.Table (Withs.Last) := Current_With;
688 if Current_With_Clause = No_With then
689 Context_Clause := Withs.Last;
692 Withs.Table (Current_With_Clause).Next := Withs.Last;
695 Current_With_Clause := Withs.Last;
699 if Token = Tok_Semicolon then
700 Set_End_Of_Line (Current_With_Node);
701 Set_Previous_Line_Node (Current_With_Node);
703 -- End of (possibly multiple) with clause;
705 Scan (In_Tree); -- past the semicolon
708 elsif Token = Tok_Comma then
709 Set_Is_Not_Last_In_List (Current_With_Node, In_Tree);
712 Error_Msg (Flags, "expected comma or semi colon", Token_Ptr);
718 (Of_Kind => N_With_Clause, In_Tree => In_Tree);
721 end Pre_Parse_Context_Clause;
723 -------------------------------
724 -- Post_Parse_Context_Clause --
725 -------------------------------
727 procedure Post_Parse_Context_Clause
728 (Context_Clause : With_Id;
729 In_Tree : Project_Node_Tree_Ref;
730 Limited_Withs : Boolean;
731 Imported_Projects : in out Project_Node_Id;
732 Project_Directory : Path_Name_Type;
733 From_Extended : Extension_Origin;
734 In_Limited : Boolean;
735 Packages_To_Check : String_List_Access;
737 Current_Dir : String;
738 Is_Config_File : Boolean;
739 Flags : Processing_Flags)
741 Current_With_Clause : With_Id := Context_Clause;
743 Current_Project : Project_Node_Id := Imported_Projects;
744 Previous_Project : Project_Node_Id := Empty_Node;
745 Next_Project : Project_Node_Id := Empty_Node;
747 Project_Directory_Path : constant String :=
748 Get_Name_String (Project_Directory);
750 Current_With : With_Record;
751 Extends_All : Boolean := False;
752 Imported_Path_Name_Id : Path_Name_Type;
755 -- Set Current_Project to the last project in the current list, if the
756 -- list is not empty.
758 if Present (Current_Project) then
760 Present (Next_With_Clause_Of (Current_Project, In_Tree))
762 Current_Project := Next_With_Clause_Of (Current_Project, In_Tree);
766 while Current_With_Clause /= No_With loop
767 Current_With := Withs.Table (Current_With_Clause);
768 Current_With_Clause := Current_With.Next;
770 if Limited_Withs = Current_With.Limited_With then
772 (In_Tree.Project_Path,
773 Project_File_Name => Get_Name_String (Current_With.Path),
774 Directory => Project_Directory_Path,
775 Path => Imported_Path_Name_Id);
777 if Imported_Path_Name_Id = No_Path then
779 -- The project file cannot be found
781 Error_Msg_File_1 := File_Name_Type (Current_With.Path);
783 (Flags, "unknown project file: {", Current_With.Location);
785 -- If this is not imported by the main project file, display
788 if Project_Stack.Last > 1 then
789 for Index in reverse 1 .. Project_Stack.Last loop
792 (Project_Stack.Table (Index).Path_Name);
794 (Flags, "\imported by {", Current_With.Location);
802 Resolved_Path : constant String :=
804 (Get_Name_String (Imported_Path_Name_Id),
805 Directory => Current_Dir,
807 Opt.Follow_Links_For_Files,
808 Case_Sensitive => True);
810 Withed_Project : Project_Node_Id := Empty_Node;
813 Previous_Project := Current_Project;
815 if No (Current_Project) then
817 -- First with clause of the context clause
819 Current_Project := Current_With.Node;
820 Imported_Projects := Current_Project;
823 Next_Project := Current_With.Node;
824 Set_Next_With_Clause_Of
825 (Current_Project, In_Tree, Next_Project);
826 Current_Project := Next_Project;
832 Name_Id (Current_With.Path));
834 (Current_Project, In_Tree, Current_With.Location);
836 -- If it is a limited with, check if we have a circularity.
837 -- If we have one, get the project id of the limited
838 -- imported project file, and do not parse it.
840 if Limited_Withs and then Project_Stack.Last > 1 then
842 Canonical_Path_Name : Path_Name_Type;
845 Name_Len := Resolved_Path'Length;
846 Name_Buffer (1 .. Name_Len) := Resolved_Path;
847 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
848 Canonical_Path_Name := Name_Find;
850 for Index in 1 .. Project_Stack.Last loop
851 if Project_Stack.Table (Index).Canonical_Path_Name =
854 -- We have found the limited imported project,
855 -- get its project id, and do not parse it.
857 Withed_Project := Project_Stack.Table (Index).Id;
864 -- Parse the imported project, if its project id is unknown
866 if No (Withed_Project) then
869 Project => Withed_Project,
870 Extends_All => Extends_All,
871 Path_Name_Id => Imported_Path_Name_Id,
873 From_Extended => From_Extended,
874 In_Limited => Limited_Withs,
875 Packages_To_Check => Packages_To_Check,
877 Current_Dir => Current_Dir,
878 Is_Config_File => Is_Config_File,
882 Extends_All := Is_Extending_All (Withed_Project, In_Tree);
885 if No (Withed_Project) then
887 -- If parsing unsuccessful, remove the context clause
889 Current_Project := Previous_Project;
891 if No (Current_Project) then
892 Imported_Projects := Empty_Node;
895 Set_Next_With_Clause_Of
896 (Current_Project, In_Tree, Empty_Node);
899 -- If parsing was successful, record project name and
900 -- path name in with clause
903 (Node => Current_Project,
905 To => Withed_Project,
906 Limited_With => Current_With.Limited_With);
910 Name_Of (Withed_Project, In_Tree));
912 Name_Len := Resolved_Path'Length;
913 Name_Buffer (1 .. Name_Len) := Resolved_Path;
914 Set_Path_Name_Of (Current_Project, In_Tree, Name_Find);
917 Set_Is_Extending_All (Current_Project, In_Tree);
924 end Post_Parse_Context_Clause;
926 ---------------------------------
927 -- Check_Extending_All_Imports --
928 ---------------------------------
930 procedure Check_Extending_All_Imports
931 (Flags : Processing_Flags;
932 In_Tree : Project_Node_Tree_Ref;
933 Project : Project_Node_Id)
935 With_Clause : Project_Node_Id;
936 Imported : Project_Node_Id;
939 if not Is_Extending_All (Project, In_Tree) then
940 With_Clause := First_With_Clause_Of (Project, In_Tree);
941 while Present (With_Clause) loop
942 Imported := Project_Node_Of (With_Clause, In_Tree);
944 if Is_Extending_All (With_Clause, In_Tree) then
945 Error_Msg_Name_1 := Name_Of (Imported, In_Tree);
946 Error_Msg (Flags, "cannot import extending-all project %%",
951 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
954 end Check_Extending_All_Imports;
956 -----------------------------
957 -- Check_Aggregate_Imports --
958 -----------------------------
960 procedure Check_Aggregate_Imports
961 (Flags : Processing_Flags;
962 In_Tree : Project_Node_Tree_Ref;
963 Project : Project_Node_Id)
965 With_Clause, Imported : Project_Node_Id;
967 if Project_Qualifier_Of (Project, In_Tree) = Aggregate then
968 With_Clause := First_With_Clause_Of (Project, In_Tree);
970 while Present (With_Clause) loop
971 Imported := Project_Node_Of (With_Clause, In_Tree);
973 if Project_Qualifier_Of (Imported, In_Tree) /= Dry then
974 Error_Msg_Name_1 := Name_Id (Path_Name_Of (Imported, In_Tree));
975 Error_Msg (Flags, "can only import abstract projects, not %%",
980 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
983 end Check_Aggregate_Imports;
985 ----------------------------
986 -- Read_Project_Qualifier --
987 ----------------------------
989 procedure Read_Project_Qualifier
990 (Flags : Processing_Flags;
991 In_Tree : Project_Node_Tree_Ref;
992 Is_Config_File : Boolean;
993 Qualifier_Location : out Source_Ptr;
994 Project : Project_Node_Id)
996 Proj_Qualifier : Project_Qualifier := Unspecified;
998 Qualifier_Location := Token_Ptr;
1000 if Token = Tok_Abstract then
1001 Proj_Qualifier := Dry;
1004 elsif Token = Tok_Identifier then
1006 when Snames.Name_Standard =>
1007 Proj_Qualifier := Standard;
1010 when Snames.Name_Aggregate =>
1011 Proj_Qualifier := Aggregate;
1014 if Token = Tok_Identifier and then
1015 Token_Name = Snames.Name_Library
1017 Proj_Qualifier := Aggregate_Library;
1021 when Snames.Name_Library =>
1022 Proj_Qualifier := Library;
1025 when Snames.Name_Configuration =>
1026 if not Is_Config_File then
1029 "configuration projects cannot belong to a user" &
1034 Proj_Qualifier := Configuration;
1042 if Is_Config_File and then Proj_Qualifier = Unspecified then
1044 -- Set the qualifier to Configuration, even if the token doesn't
1045 -- exist in the source file itself, so that we can differentiate
1046 -- project files and configuration files later on.
1048 Proj_Qualifier := Configuration;
1051 if Proj_Qualifier /= Unspecified then
1053 and then Proj_Qualifier /= Configuration
1056 "a configuration project cannot be qualified except " &
1057 "as configuration project",
1058 Qualifier_Location);
1061 Set_Project_Qualifier_Of (Project, In_Tree, Proj_Qualifier);
1063 end Read_Project_Qualifier;
1065 -------------------------------
1066 -- Has_Circular_Dependencies --
1067 -------------------------------
1069 function Has_Circular_Dependencies
1070 (Flags : Processing_Flags;
1071 Normed_Path_Name : Path_Name_Type;
1072 Canonical_Path_Name : Path_Name_Type) return Boolean is
1074 for Index in reverse 1 .. Project_Stack.Last loop
1075 exit when Project_Stack.Table (Index).Limited_With;
1077 if Canonical_Path_Name =
1078 Project_Stack.Table (Index).Canonical_Path_Name
1080 Error_Msg (Flags, "circular dependency detected", Token_Ptr);
1081 Error_Msg_Name_1 := Name_Id (Normed_Path_Name);
1082 Error_Msg (Flags, "\ %% is imported by", Token_Ptr);
1084 for Current in reverse 1 .. Project_Stack.Last loop
1086 Name_Id (Project_Stack.Table (Current).Path_Name);
1088 if Project_Stack.Table (Current).Canonical_Path_Name /=
1092 (Flags, "\ %% which itself is imported by", Token_Ptr);
1095 Error_Msg (Flags, "\ %%", Token_Ptr);
1104 end Has_Circular_Dependencies;
1106 --------------------------
1107 -- Parse_Single_Project --
1108 --------------------------
1110 procedure Parse_Single_Project
1111 (In_Tree : Project_Node_Tree_Ref;
1112 Project : out Project_Node_Id;
1113 Extends_All : out Boolean;
1114 Path_Name_Id : Path_Name_Type;
1116 From_Extended : Extension_Origin;
1117 In_Limited : Boolean;
1118 Packages_To_Check : String_List_Access;
1120 Current_Dir : String;
1121 Is_Config_File : Boolean;
1122 Flags : Processing_Flags)
1124 Path_Name : constant String := Get_Name_String (Path_Name_Id);
1126 Normed_Path_Name : Path_Name_Type;
1127 Canonical_Path_Name : Path_Name_Type;
1128 Project_Directory : Path_Name_Type;
1129 Project_Scan_State : Saved_Project_Scan_State;
1130 Source_Index : Source_File_Index;
1132 Extending : Boolean := False;
1134 Extended_Project : Project_Node_Id := Empty_Node;
1136 A_Project_Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1137 Tree_Private_Part.Projects_Htable.Get_First
1138 (In_Tree.Projects_HT);
1140 Name_From_Path : constant Name_Id :=
1141 Project_Name_From (Path_Name, Is_Config_File => Is_Config_File);
1142 Name_Of_Project : Name_Id := No_Name;
1143 Display_Name_Of_Project : Name_Id := No_Name;
1145 Duplicated : Boolean := False;
1147 First_With : With_Id;
1148 Imported_Projects : Project_Node_Id := Empty_Node;
1150 use Tree_Private_Part;
1152 Project_Comment_State : Tree.Comment_State;
1154 Qualifier_Location : Source_Ptr;
1157 Extends_All := False;
1160 Normed_Path : constant String := Normalize_Pathname
1162 Directory => Current_Dir,
1163 Resolve_Links => False,
1164 Case_Sensitive => True);
1165 Canonical_Path : constant String := Normalize_Pathname
1167 Directory => Current_Dir,
1168 Resolve_Links => Opt.Follow_Links_For_Files,
1169 Case_Sensitive => False);
1171 Name_Len := Normed_Path'Length;
1172 Name_Buffer (1 .. Name_Len) := Normed_Path;
1173 Normed_Path_Name := Name_Find;
1174 Name_Len := Canonical_Path'Length;
1175 Name_Buffer (1 .. Name_Len) := Canonical_Path;
1176 Canonical_Path_Name := Name_Find;
1179 if Has_Circular_Dependencies
1180 (Flags, Normed_Path_Name, Canonical_Path_Name)
1182 Project := Empty_Node;
1186 -- Put the new path name on the stack
1188 Project_Stack.Append
1189 ((Path_Name => Normed_Path_Name,
1190 Canonical_Path_Name => Canonical_Path_Name,
1192 Limited_With => In_Limited));
1194 -- Check if the project file has already been parsed
1197 A_Project_Name_And_Node /= Tree_Private_Part.No_Project_Name_And_Node
1199 if A_Project_Name_And_Node.Canonical_Path = Canonical_Path_Name then
1202 if A_Project_Name_And_Node.Extended then
1203 if A_Project_Name_And_Node.Proj_Qualifier /= Dry then
1206 "cannot extend the same project file several times",
1212 "cannot extend an already imported project file",
1216 elsif A_Project_Name_And_Node.Extended then
1218 Is_Extending_All (A_Project_Name_And_Node.Node, In_Tree);
1220 -- If the imported project is an extended project A, and we are
1221 -- in an extended project, replace A with the ultimate project
1224 if From_Extended /= None then
1226 Decl : Project_Node_Id :=
1227 Project_Declaration_Of
1228 (A_Project_Name_And_Node.Node, In_Tree);
1230 Prj : Project_Node_Id :=
1231 A_Project_Name_And_Node.Node;
1234 -- Loop through extending projects to find the ultimate
1235 -- extending project, that is the one that is not
1236 -- extended. For an abstract project, as it can be
1237 -- extended several times, there is no extending project
1238 -- registered, so the loop does not execute and the
1239 -- resulting project is the abstract project.
1242 Extending_Project_Of (Decl, In_Tree) /= Empty_Node
1244 Prj := Extending_Project_Of (Decl, In_Tree);
1245 Decl := Project_Declaration_Of (Prj, In_Tree);
1248 A_Project_Name_And_Node.Node := Prj;
1253 "cannot import an already extended project file",
1258 Project := A_Project_Name_And_Node.Node;
1259 Project_Stack.Decrement_Last;
1263 A_Project_Name_And_Node :=
1264 Tree_Private_Part.Projects_Htable.Get_Next (In_Tree.Projects_HT);
1267 -- We never encountered this project file. Save the scan state, load the
1268 -- project file and start to scan it.
1270 Save_Project_Scan_State (Project_Scan_State);
1271 Source_Index := Load_Project_File (Path_Name);
1272 Tree.Save (Project_Comment_State);
1274 -- If we cannot find it, we stop
1276 if Source_Index = No_Source_File then
1277 Project := Empty_Node;
1278 Project_Stack.Decrement_Last;
1282 Prj.Err.Scanner.Initialize_Scanner (Source_Index);
1286 if not Is_Config_File and then Name_From_Path = No_Name then
1288 -- The project file name is not correct (no or bad extension, or not
1289 -- following Ada identifier's syntax).
1291 Error_Msg_File_1 := File_Name_Type (Canonical_Path_Name);
1293 "?{ is not a valid path name for a project file",
1297 if Current_Verbosity >= Medium then
1298 Write_Str ("Parsing """);
1299 Write_Str (Path_Name);
1304 Project_Directory :=
1305 Path_Name_Type (Get_Directory (File_Name_Type (Normed_Path_Name)));
1307 -- Is there any imported project?
1309 Pre_Parse_Context_Clause
1310 (In_Tree => In_Tree,
1311 Is_Config_File => Is_Config_File,
1312 Context_Clause => First_With,
1315 Project := Default_Project_Node
1316 (Of_Kind => N_Project, In_Tree => In_Tree);
1317 Project_Stack.Table (Project_Stack.Last).Id := Project;
1318 Set_Directory_Of (Project, In_Tree, Project_Directory);
1319 Set_Path_Name_Of (Project, In_Tree, Normed_Path_Name);
1321 Read_Project_Qualifier
1322 (Flags, In_Tree, Is_Config_File, Qualifier_Location, Project);
1324 Set_Location_Of (Project, In_Tree, Token_Ptr);
1326 Expect (Tok_Project, "PROJECT
");
1328 -- Mark location of PROJECT token if present
1330 if Token = Tok_Project then
1331 Scan (In_Tree); -- past PROJECT
1332 Set_Location_Of (Project, In_Tree, Token_Ptr);
1339 Expect (Tok_Identifier, "identifier
");
1341 -- If the token is not an identifier, clear the buffer before
1342 -- exiting to indicate that the name of the project is ill-formed.
1344 if Token /= Tok_Identifier then
1349 -- Add the identifier name to the buffer
1351 Get_Name_String (Token_Name);
1352 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1354 -- Scan past the identifier
1358 -- If we have a dot, add a dot to the Buffer and look for the next
1361 exit when Token /= Tok_Dot;
1362 Add_To_Buffer (".", Buffer, Buffer_Last);
1364 -- Scan past the dot
1369 -- See if this is an extending project
1371 if Token = Tok_Extends then
1373 if Is_Config_File then
1376 "extending configuration project
not allowed
", Token_Ptr);
1379 -- Make sure that gnatmake will use mapping files
1381 Opt.Create_Mapping_File := True;
1383 -- We are extending another project
1387 Scan (In_Tree); -- past EXTENDS
1389 if Token = Tok_All then
1390 Extends_All := True;
1391 Set_Is_Extending_All (Project, In_Tree);
1392 Scan (In_Tree); -- scan past ALL
1396 -- If the name is well formed, Buffer_Last is > 0
1398 if Buffer_Last > 0 then
1400 -- The Buffer contains the name of the project
1402 Name_Len := Buffer_Last;
1403 Name_Buffer (1 .. Name_Len) := Buffer (1 .. Buffer_Last);
1404 Name_Of_Project := Name_Find;
1405 Set_Name_Of (Project, In_Tree, Name_Of_Project);
1407 -- To get expected name of the project file, replace dots by dashes
1409 for Index in 1 .. Name_Len loop
1410 if Name_Buffer (Index) = '.' then
1411 Name_Buffer (Index) := '-';
1415 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1418 Expected_Name : constant Name_Id := Name_Find;
1419 Extension : String_Access;
1422 -- Output a warning if the actual name is not the expected name
1424 if not Is_Config_File
1425 and then (Name_From_Path /= No_Name)
1426 and then Expected_Name /= Name_From_Path
1428 Error_Msg_Name_1 := Expected_Name;
1430 if Is_Config_File then
1431 Extension := new String'(Config_Project_File_Extension);
1434 Extension := new String'(Project_File_Extension);
1439 "?file name does
not match project name
, should be `
%%"
1440 & Extension.all & "`
",
1445 -- Read the original casing of the project name
1451 Loc := Location_Of (Project, In_Tree);
1452 for J in 1 .. Name_Len loop
1453 Name_Buffer (J) := Sinput.Source (Loc);
1457 Display_Name_Of_Project := Name_Find;
1461 From_Ext : Extension_Origin := None;
1464 -- Extending_All is always propagated
1466 if From_Extended = Extending_All or else Extends_All then
1467 From_Ext := Extending_All;
1469 -- Otherwise, From_Extended is set to Extending_Single if the
1470 -- current project is an extending project.
1473 From_Ext := Extending_Simple;
1476 Post_Parse_Context_Clause
1477 (In_Tree => In_Tree,
1478 Context_Clause => First_With,
1479 Limited_Withs => False,
1480 Imported_Projects => Imported_Projects,
1481 Project_Directory => Project_Directory,
1482 From_Extended => From_Ext,
1483 In_Limited => In_Limited,
1484 Packages_To_Check => Packages_To_Check,
1486 Current_Dir => Current_Dir,
1487 Is_Config_File => Is_Config_File,
1489 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1492 if not Is_Config_File then
1494 Name_And_Node : Tree_Private_Part.Project_Name_And_Node :=
1495 Tree_Private_Part.Projects_Htable.Get_First
1496 (In_Tree.Projects_HT);
1497 Project_Name : Name_Id := Name_And_Node.Name;
1500 -- Check if we already have a project with this name
1502 while Project_Name /= No_Name
1503 and then Project_Name /= Name_Of_Project
1506 Tree_Private_Part.Projects_Htable.Get_Next
1507 (In_Tree.Projects_HT);
1508 Project_Name := Name_And_Node.Name;
1511 -- Report an error if we already have a project with this name
1513 if Project_Name /= No_Name then
1515 Error_Msg_Name_1 := Project_Name;
1517 (Flags, "duplicate project name
%%",
1518 Location_Of (Project, In_Tree));
1520 Name_Id (Path_Name_Of (Name_And_Node.Node, In_Tree));
1522 (Flags, "\already
in %%", Location_Of (Project, In_Tree));
1530 Expect (Tok_String_Literal, "literal
string");
1532 if Token = Tok_String_Literal then
1533 Set_Extended_Project_Path_Of
1536 Path_Name_Type (Token_Name));
1539 Original_Path_Name : constant String :=
1540 Get_Name_String (Token_Name);
1541 Extended_Project_Path_Name_Id : Path_Name_Type;
1544 (In_Tree.Project_Path,
1545 Project_File_Name => Original_Path_Name,
1546 Directory => Get_Name_String (Project_Directory),
1547 Path => Extended_Project_Path_Name_Id);
1549 if Extended_Project_Path_Name_Id = No_Path then
1551 -- We could not find the project file to extend
1553 Error_Msg_Name_1 := Token_Name;
1555 Error_Msg (Flags, "unknown project file
: %%", Token_Ptr);
1557 -- If we are not in the main project file, display the
1560 if Project_Stack.Last > 1 then
1563 (Project_Stack.Table (Project_Stack.Last).Path_Name);
1564 Error_Msg (Flags, "\extended by
%%", Token_Ptr);
1566 for Index in reverse 1 .. Project_Stack.Last - 1 loop
1569 (Project_Stack.Table (Index).Path_Name);
1570 Error_Msg (Flags, "\imported by
%%", Token_Ptr);
1576 From_Ext : Extension_Origin := None;
1579 if From_Extended = Extending_All or else Extends_All then
1580 From_Ext := Extending_All;
1583 Parse_Single_Project
1584 (In_Tree => In_Tree,
1585 Project => Extended_Project,
1586 Extends_All => Extends_All,
1587 Path_Name_Id => Extended_Project_Path_Name_Id,
1589 From_Extended => From_Ext,
1590 In_Limited => In_Limited,
1591 Packages_To_Check => Packages_To_Check,
1593 Current_Dir => Current_Dir,
1594 Is_Config_File => Is_Config_File,
1598 if Present (Extended_Project) then
1600 -- A project that extends an extending-all project is
1601 -- also an extending-all project.
1603 if Is_Extending_All (Extended_Project, In_Tree) then
1604 Set_Is_Extending_All (Project, In_Tree);
1607 -- An abstract project can only extend an abstract
1608 -- project, otherwise we may have an abstract project
1609 -- with sources, if it inherits sources from the project
1612 if Project_Qualifier_Of (Project, In_Tree) = Dry and then
1613 Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1616 (Flags, "an
abstract project can only extend
" &
1617 "another
abstract project
",
1618 Qualifier_Location);
1624 Scan (In_Tree); -- past the extended project path
1628 Check_Extending_All_Imports (Flags, In_Tree, Project);
1629 Check_Aggregate_Imports (Flags, In_Tree, Project);
1631 -- Check that a project with a name including a dot either imports
1632 -- or extends the project whose name precedes the last dot.
1634 if Name_Of_Project /= No_Name then
1635 Get_Name_String (Name_Of_Project);
1641 -- Look for the last dot
1643 while Name_Len > 0 and then Name_Buffer (Name_Len) /= '.' loop
1644 Name_Len := Name_Len - 1;
1647 -- If a dot was found, check if parent project is imported or extended
1649 if Name_Len > 0 then
1650 Name_Len := Name_Len - 1;
1653 Parent_Name : constant Name_Id := Name_Find;
1654 Parent_Found : Boolean := False;
1655 Parent_Node : Project_Node_Id := Empty_Node;
1656 With_Clause : Project_Node_Id :=
1657 First_With_Clause_Of (Project, In_Tree);
1658 Imp_Proj_Name : Name_Id;
1661 -- If there is an extended project, check its name
1663 if Present (Extended_Project) then
1664 Parent_Node := Extended_Project;
1666 Name_Of (Extended_Project, In_Tree) = Parent_Name;
1669 -- If the parent project is not the extended project,
1670 -- check each imported project until we find the parent project.
1673 while not Parent_Found and then Present (With_Clause) loop
1674 Parent_Node := Project_Node_Of (With_Clause, In_Tree);
1675 Extension_Loop : while Present (Parent_Node) loop
1676 Imp_Proj_Name := Name_Of (Parent_Node, In_Tree);
1677 Parent_Found := Imp_Proj_Name = Parent_Name;
1678 exit Imported_Loop when Parent_Found;
1681 (Project_Declaration_Of (Parent_Node, In_Tree),
1683 end loop Extension_Loop;
1685 With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1686 end loop Imported_Loop;
1688 if Parent_Found then
1689 Set_Parent_Project_Of (Project, In_Tree, To => Parent_Node);
1692 -- If the parent project was not found, report an error
1694 Error_Msg_Name_1 := Name_Of_Project;
1695 Error_Msg_Name_2 := Parent_Name;
1697 "project
%% does
not import
or extend project
%%",
1698 Location_Of (Project, In_Tree));
1703 Expect (Tok_Is, "IS");
1704 Set_End_Of_Line (Project);
1705 Set_Previous_Line_Node (Project);
1706 Set_Next_End_Node (Project);
1709 Project_Declaration : Project_Node_Id := Empty_Node;
1712 -- No need to Scan past "is", Prj.Dect.Parse will do it
1715 (In_Tree => In_Tree,
1716 Declarations => Project_Declaration,
1717 Current_Project => Project,
1718 Extends => Extended_Project,
1719 Packages_To_Check => Packages_To_Check,
1720 Is_Config_File => Is_Config_File,
1722 Set_Project_Declaration_Of (Project, In_Tree, Project_Declaration);
1724 if Present (Extended_Project)
1725 and then Project_Qualifier_Of (Extended_Project, In_Tree) /= Dry
1727 Set_Extending_Project_Of
1728 (Project_Declaration_Of (Extended_Project, In_Tree), In_Tree,
1733 Expect (Tok_End, "END");
1734 Remove_Next_End_Node;
1736 -- Skip "end" if present
1738 if Token = Tok_End then
1746 -- Store the name following "end" in the Buffer. The name may be made of
1747 -- several simple names.
1750 Expect (Tok_Identifier, "identifier
");
1752 -- If we don't have an identifier, clear the buffer before exiting to
1753 -- avoid checking the name.
1755 if Token /= Tok_Identifier then
1760 -- Add the identifier to the Buffer
1761 Get_Name_String (Token_Name);
1762 Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
1764 -- Scan past the identifier
1767 exit when Token /= Tok_Dot;
1768 Add_To_Buffer (".", Buffer, Buffer_Last);
1772 -- If we have a valid name, check if it is the name of the project
1774 if Name_Of_Project /= No_Name and then Buffer_Last > 0 then
1775 if To_Lower (Buffer (1 .. Buffer_Last)) /=
1776 Get_Name_String (Name_Of (Project, In_Tree))
1778 -- Invalid name: report an error
1780 Error_Msg (Flags, "expected
""" &
1781 Get_Name_String (Name_Of (Project, In_Tree)) & """",
1786 Expect (Tok_Semicolon, "`
;`
");
1788 -- Check that there is no more text following the end of the project
1791 if Token = Tok_Semicolon then
1792 Set_Previous_End_Node (Project);
1795 if Token /= Tok_EOF then
1797 (Flags, "unexpected text following
end of project
", Token_Ptr);
1801 if not Duplicated and then Name_Of_Project /= No_Name then
1803 -- Add the name of the project to the hash table, so that we can
1804 -- check that no other subsequent project will have the same name.
1806 Tree_Private_Part.Projects_Htable.Set
1807 (T => In_Tree.Projects_HT,
1808 K => Name_Of_Project,
1809 E => (Name => Name_Of_Project,
1810 Display_Name => Display_Name_Of_Project,
1812 Canonical_Path => Canonical_Path_Name,
1813 Extended => Extended,
1814 Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
1818 From_Ext : Extension_Origin := None;
1821 -- Extending_All is always propagated
1823 if From_Extended = Extending_All or else Extends_All then
1824 From_Ext := Extending_All;
1826 -- Otherwise, From_Extended is set to Extending_Single if the
1827 -- current project is an extending project.
1830 From_Ext := Extending_Simple;
1833 Post_Parse_Context_Clause
1834 (In_Tree => In_Tree,
1835 Context_Clause => First_With,
1836 Limited_Withs => True,
1837 Imported_Projects => Imported_Projects,
1838 Project_Directory => Project_Directory,
1839 From_Extended => From_Ext,
1840 In_Limited => In_Limited,
1841 Packages_To_Check => Packages_To_Check,
1843 Current_Dir => Current_Dir,
1844 Is_Config_File => Is_Config_File,
1846 Set_First_With_Clause_Of (Project, In_Tree, Imported_Projects);
1849 -- Restore the scan state, in case we are not the main project
1851 Restore_Project_Scan_State (Project_Scan_State);
1853 -- And remove the project from the project stack
1855 Project_Stack.Decrement_Last;
1857 -- Indicate if there are unkept comments
1859 Tree.Set_Project_File_Includes_Unkept_Comments
1862 To => Tree.There_Are_Unkept_Comments);
1864 -- And restore the comment state that was saved
1866 Tree.Restore_And_Free (Project_Comment_State);
1867 end Parse_Single_Project;
1869 -----------------------
1870 -- Project_Name_From --
1871 -----------------------
1873 function Project_Name_From
1874 (Path_Name : String;
1875 Is_Config_File : Boolean) return Name_Id
1877 Canonical : String (1 .. Path_Name'Length) := Path_Name;
1878 First : Natural := Canonical'Last;
1879 Last : Natural := First;
1883 if Current_Verbosity = High then
1884 Write_Str ("Project_Name_From
(""");
1885 Write_Str (Canonical);
1889 -- If the path name is empty, return No_Name to indicate failure
1895 Canonical_Case_File_Name (Canonical);
1897 -- Look for the last dot in the path name
1901 Canonical (First) /= '.'
1906 -- If we have a dot, check that it is followed by the correct extension
1908 if First > 0 and then Canonical (First) = '.' then
1909 if (not Is_Config_File
1910 and then Canonical (First .. Last) = Project_File_Extension
1911 and then First /= 1)
1915 Canonical (First .. Last) = Config_Project_File_Extension
1916 and then First /= 1)
1918 -- Look for the last directory separator, if any
1923 and then Canonical (First) /= '/'
1924 and then Canonical (First) /= Dir_Sep
1930 -- Not the correct extension, return No_Name to indicate failure
1935 -- If no dot in the path name, return No_Name to indicate failure
1943 -- If the extension is the file name, return No_Name to indicate failure
1945 if First > Last then
1949 -- Put the name in lower case into Name_Buffer
1951 Name_Len := Last - First + 1;
1952 Name_Buffer (1 .. Name_Len) := To_Lower (Canonical (First .. Last));
1956 -- Check if it is a well formed project name. Return No_Name if it is
1960 if not Is_Letter (Name_Buffer (Index)) then
1967 exit when Index >= Name_Len;
1969 if Name_Buffer (Index) = '_' then
1970 if Name_Buffer (Index + 1) = '_' then
1975 exit when Name_Buffer (Index) = '-';
1977 if Name_Buffer (Index) /= '_'
1978 and then not Is_Alphanumeric (Name_Buffer (Index))
1986 if Index >= Name_Len then
1987 if Is_Alphanumeric (Name_Buffer (Name_Len)) then
1989 -- All checks have succeeded. Return name in Name_Buffer
1997 elsif Name_Buffer (Index) = '-' then
2001 end Project_Name_From;