annotate gcc/ada/lib-load.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- L I B . L O A D --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Atree; use Atree;
kono
parents:
diff changeset
27 with Debug; use Debug;
kono
parents:
diff changeset
28 with Einfo; use Einfo;
kono
parents:
diff changeset
29 with Errout; use Errout;
kono
parents:
diff changeset
30 with Fname; use Fname;
kono
parents:
diff changeset
31 with Fname.UF; use Fname.UF;
kono
parents:
diff changeset
32 with Nlists; use Nlists;
kono
parents:
diff changeset
33 with Nmake; use Nmake;
kono
parents:
diff changeset
34 with Opt; use Opt;
kono
parents:
diff changeset
35 with Osint; use Osint;
kono
parents:
diff changeset
36 with Osint.C; use Osint.C;
kono
parents:
diff changeset
37 with Output; use Output;
kono
parents:
diff changeset
38 with Par;
kono
parents:
diff changeset
39 with Restrict; use Restrict;
kono
parents:
diff changeset
40 with Scn; use Scn;
kono
parents:
diff changeset
41 with Sinfo; use Sinfo;
kono
parents:
diff changeset
42 with Sinput; use Sinput;
kono
parents:
diff changeset
43 with Sinput.L; use Sinput.L;
kono
parents:
diff changeset
44 with Stand; use Stand;
kono
parents:
diff changeset
45 with Tbuild; use Tbuild;
kono
parents:
diff changeset
46 with Uname; use Uname;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package body Lib.Load is
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -----------------------
kono
parents:
diff changeset
51 -- Local Subprograms --
kono
parents:
diff changeset
52 -----------------------
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 function From_Limited_With_Chain return Boolean;
kono
parents:
diff changeset
55 -- Check whether a possible circular dependence includes units that
kono
parents:
diff changeset
56 -- have been loaded through limited_with clauses, in which case there
kono
parents:
diff changeset
57 -- is no real circularity.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 function Spec_Is_Irrelevant
kono
parents:
diff changeset
60 (Spec_Unit : Unit_Number_Type;
kono
parents:
diff changeset
61 Body_Unit : Unit_Number_Type) return Boolean;
kono
parents:
diff changeset
62 -- The Spec_Unit and Body_Unit parameters are the unit numbers of the
kono
parents:
diff changeset
63 -- spec file that corresponds to the main unit which is a body. This
kono
parents:
diff changeset
64 -- function determines if the spec file is irrelevant and will be
kono
parents:
diff changeset
65 -- overridden by the body as described in RM 10.1.4(4). See description
kono
parents:
diff changeset
66 -- in "Special Handling of Subprogram Bodies" for further details.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 procedure Write_Dependency_Chain;
kono
parents:
diff changeset
69 -- This procedure is used to generate error message info lines that
kono
parents:
diff changeset
70 -- trace the current dependency chain when a load error occurs.
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 ------------------------------
kono
parents:
diff changeset
73 -- Change_Main_Unit_To_Spec --
kono
parents:
diff changeset
74 ------------------------------
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 procedure Change_Main_Unit_To_Spec is
kono
parents:
diff changeset
77 U : Unit_Record renames Units.Table (Main_Unit);
kono
parents:
diff changeset
78 N : File_Name_Type;
kono
parents:
diff changeset
79 X : Source_File_Index;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 begin
kono
parents:
diff changeset
82 -- Get name of unit body
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 Get_Name_String (U.Unit_File_Name);
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -- Note: for the following we should really generalize and consult the
kono
parents:
diff changeset
87 -- file name pattern data, but for now we just deal with the common
kono
parents:
diff changeset
88 -- naming cases, which is probably good enough in practice ???
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -- Change .adb to .ads
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 if Name_Len >= 5
kono
parents:
diff changeset
93 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
kono
parents:
diff changeset
94 then
kono
parents:
diff changeset
95 Name_Buffer (Name_Len) := 's';
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- Change .2.ada to .1.ada (Rational convention)
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 elsif Name_Len >= 7
kono
parents:
diff changeset
100 and then Name_Buffer (Name_Len - 5 .. Name_Len) = ".2.ada"
kono
parents:
diff changeset
101 then
kono
parents:
diff changeset
102 Name_Buffer (Name_Len - 4) := '1';
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 -- Change .ada to _.ada (DEC convention)
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 elsif Name_Len >= 5
kono
parents:
diff changeset
107 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".ada"
kono
parents:
diff changeset
108 then
kono
parents:
diff changeset
109 Name_Buffer (Name_Len - 3 .. Name_Len + 1) := "_.ada";
kono
parents:
diff changeset
110 Name_Len := Name_Len + 1;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 -- No match, don't make the change
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 else
kono
parents:
diff changeset
115 return;
kono
parents:
diff changeset
116 end if;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 -- Try loading the spec
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 N := Name_Find;
kono
parents:
diff changeset
121 X := Load_Source_File (N);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 -- No change if we did not find the spec
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 if X <= No_Source_File then
kono
parents:
diff changeset
126 return;
kono
parents:
diff changeset
127 end if;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -- Otherwise modify Main_Unit entry to point to spec
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 U.Unit_File_Name := N;
kono
parents:
diff changeset
132 U.Source_Index := X;
kono
parents:
diff changeset
133 end Change_Main_Unit_To_Spec;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -------------------------------
kono
parents:
diff changeset
136 -- Create_Dummy_Package_Unit --
kono
parents:
diff changeset
137 -------------------------------
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 function Create_Dummy_Package_Unit
kono
parents:
diff changeset
140 (With_Node : Node_Id;
kono
parents:
diff changeset
141 Spec_Name : Unit_Name_Type) return Unit_Number_Type
kono
parents:
diff changeset
142 is
kono
parents:
diff changeset
143 Unum : Unit_Number_Type;
kono
parents:
diff changeset
144 Cunit_Entity : Entity_Id;
kono
parents:
diff changeset
145 Cunit : Node_Id;
kono
parents:
diff changeset
146 Du_Name : Node_Or_Entity_Id;
kono
parents:
diff changeset
147 End_Lab : Node_Id;
kono
parents:
diff changeset
148 Fname : constant File_Name_Type :=
kono
parents:
diff changeset
149 Get_File_Name (Spec_Name, Subunit => False);
kono
parents:
diff changeset
150 Pre_Name : constant Boolean :=
kono
parents:
diff changeset
151 Is_Predefined_File_Name (Fname, Renamings_Included => False);
kono
parents:
diff changeset
152 Ren_Name : constant Boolean :=
kono
parents:
diff changeset
153 Is_Predefined_Renaming_File_Name (Fname);
kono
parents:
diff changeset
154 GNAT_Name : constant Boolean :=
kono
parents:
diff changeset
155 Is_GNAT_File_Name (Fname);
kono
parents:
diff changeset
156 Save_CS : constant Boolean := Get_Comes_From_Source_Default;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 begin
kono
parents:
diff changeset
159 -- The created dummy package unit does not come from source
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 Set_Comes_From_Source_Default (False);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- Normal package
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 if Nkind (Name (With_Node)) = N_Identifier then
kono
parents:
diff changeset
166 Cunit_Entity :=
kono
parents:
diff changeset
167 Make_Defining_Identifier (No_Location,
kono
parents:
diff changeset
168 Chars => Chars (Name (With_Node)));
kono
parents:
diff changeset
169 Du_Name := Cunit_Entity;
kono
parents:
diff changeset
170 End_Lab := New_Occurrence_Of (Cunit_Entity, No_Location);
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 -- Child package
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 else
kono
parents:
diff changeset
175 Cunit_Entity :=
kono
parents:
diff changeset
176 Make_Defining_Identifier (No_Location,
kono
parents:
diff changeset
177 Chars => Chars (Selector_Name (Name (With_Node))));
kono
parents:
diff changeset
178 Du_Name :=
kono
parents:
diff changeset
179 Make_Defining_Program_Unit_Name (No_Location,
kono
parents:
diff changeset
180 Name => Copy_Separate_Tree (Prefix (Name (With_Node))),
kono
parents:
diff changeset
181 Defining_Identifier => Cunit_Entity);
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 Set_Is_Child_Unit (Cunit_Entity);
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 End_Lab :=
kono
parents:
diff changeset
186 Make_Designator (No_Location,
kono
parents:
diff changeset
187 Name => Copy_Separate_Tree (Prefix (Name (With_Node))),
kono
parents:
diff changeset
188 Identifier => New_Occurrence_Of (Cunit_Entity, No_Location));
kono
parents:
diff changeset
189 end if;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 Set_Scope (Cunit_Entity, Standard_Standard);
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 Cunit :=
kono
parents:
diff changeset
194 Make_Compilation_Unit (No_Location,
kono
parents:
diff changeset
195 Context_Items => Empty_List,
kono
parents:
diff changeset
196 Unit =>
kono
parents:
diff changeset
197 Make_Package_Declaration (No_Location,
kono
parents:
diff changeset
198 Specification =>
kono
parents:
diff changeset
199 Make_Package_Specification (No_Location,
kono
parents:
diff changeset
200 Defining_Unit_Name => Du_Name,
kono
parents:
diff changeset
201 Visible_Declarations => Empty_List,
kono
parents:
diff changeset
202 End_Label => End_Lab)),
kono
parents:
diff changeset
203 Aux_Decls_Node =>
kono
parents:
diff changeset
204 Make_Compilation_Unit_Aux (No_Location));
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 -- Mark the dummy package as analyzed to prevent analysis of this
kono
parents:
diff changeset
207 -- (non-existent) unit in -gnatQ mode because at the moment the
kono
parents:
diff changeset
208 -- structure and attributes of this dummy package does not allow
kono
parents:
diff changeset
209 -- a normal analysis of this unit
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 Set_Analyzed (Cunit);
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 Units.Increment_Last;
kono
parents:
diff changeset
214 Unum := Units.Last;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 Units.Table (Unum) :=
kono
parents:
diff changeset
217 (Cunit => Cunit,
kono
parents:
diff changeset
218 Cunit_Entity => Cunit_Entity,
kono
parents:
diff changeset
219 Dependency_Num => 0,
kono
parents:
diff changeset
220 Dynamic_Elab => False,
kono
parents:
diff changeset
221 Error_Location => Sloc (With_Node),
kono
parents:
diff changeset
222 Expected_Unit => Spec_Name,
kono
parents:
diff changeset
223 Fatal_Error => Error_Detected,
kono
parents:
diff changeset
224 Generate_Code => False,
kono
parents:
diff changeset
225 Has_RACW => False,
kono
parents:
diff changeset
226 Filler => False,
kono
parents:
diff changeset
227 Ident_String => Empty,
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 Is_Predefined_Renaming => Ren_Name,
kono
parents:
diff changeset
230 Is_Predefined_Unit => Pre_Name or Ren_Name,
kono
parents:
diff changeset
231 Is_Internal_Unit => Pre_Name or Ren_Name or GNAT_Name,
kono
parents:
diff changeset
232 Filler2 => False,
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 Loading => False,
kono
parents:
diff changeset
235 Main_Priority => Default_Main_Priority,
kono
parents:
diff changeset
236 Main_CPU => Default_Main_CPU,
kono
parents:
diff changeset
237 Primary_Stack_Count => 0,
kono
parents:
diff changeset
238 Sec_Stack_Count => 0,
kono
parents:
diff changeset
239 Munit_Index => 0,
kono
parents:
diff changeset
240 No_Elab_Code_All => False,
kono
parents:
diff changeset
241 Serial_Number => 0,
kono
parents:
diff changeset
242 Source_Index => No_Source_File,
kono
parents:
diff changeset
243 Unit_File_Name => Fname,
kono
parents:
diff changeset
244 Unit_Name => Spec_Name,
kono
parents:
diff changeset
245 Version => 0,
kono
parents:
diff changeset
246 OA_Setting => 'O');
kono
parents:
diff changeset
247
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
248 Init_Unit_Name (Unum, Spec_Name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
249
111
kono
parents:
diff changeset
250 Set_Comes_From_Source_Default (Save_CS);
kono
parents:
diff changeset
251 Set_Error_Posted (Cunit_Entity);
kono
parents:
diff changeset
252 Set_Error_Posted (Cunit);
kono
parents:
diff changeset
253 return Unum;
kono
parents:
diff changeset
254 end Create_Dummy_Package_Unit;
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 -----------------------------
kono
parents:
diff changeset
257 -- From_Limited_With_Chain --
kono
parents:
diff changeset
258 -----------------------------
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 function From_Limited_With_Chain return Boolean is
kono
parents:
diff changeset
261 Curr_Num : constant Unit_Number_Type :=
kono
parents:
diff changeset
262 Load_Stack.Table (Load_Stack.Last).Unit_Number;
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 begin
kono
parents:
diff changeset
265 -- True if the current load operation is through a limited_with clause
kono
parents:
diff changeset
266 -- and we are not within a loop of regular with_clauses.
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 for U in reverse Load_Stack.First .. Load_Stack.Last - 1 loop
kono
parents:
diff changeset
269 if Load_Stack.Table (U).Unit_Number = Curr_Num then
kono
parents:
diff changeset
270 return False;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 elsif Present (Load_Stack.Table (U).With_Node)
kono
parents:
diff changeset
273 and then Limited_Present (Load_Stack.Table (U).With_Node)
kono
parents:
diff changeset
274 then
kono
parents:
diff changeset
275 return True;
kono
parents:
diff changeset
276 end if;
kono
parents:
diff changeset
277 end loop;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 return False;
kono
parents:
diff changeset
280 end From_Limited_With_Chain;
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 ----------------
kono
parents:
diff changeset
283 -- Initialize --
kono
parents:
diff changeset
284 ----------------
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 procedure Initialize is
kono
parents:
diff changeset
287 begin
kono
parents:
diff changeset
288 Units.Init;
kono
parents:
diff changeset
289 Load_Stack.Init;
kono
parents:
diff changeset
290 end Initialize;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 ------------------------
kono
parents:
diff changeset
293 -- Initialize_Version --
kono
parents:
diff changeset
294 ------------------------
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 procedure Initialize_Version (U : Unit_Number_Type) is
kono
parents:
diff changeset
297 begin
kono
parents:
diff changeset
298 Units.Table (U).Version := Source_Checksum (Source_Index (U));
kono
parents:
diff changeset
299 end Initialize_Version;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 ----------------------
kono
parents:
diff changeset
302 -- Load_Main_Source --
kono
parents:
diff changeset
303 ----------------------
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 procedure Load_Main_Source is
kono
parents:
diff changeset
306 Fname : constant File_Name_Type := Next_Main_Source;
kono
parents:
diff changeset
307 Pre_Name : constant Boolean :=
kono
parents:
diff changeset
308 Is_Predefined_File_Name (Fname, Renamings_Included => False);
kono
parents:
diff changeset
309 Ren_Name : constant Boolean :=
kono
parents:
diff changeset
310 Is_Predefined_Renaming_File_Name (Fname);
kono
parents:
diff changeset
311 GNAT_Name : constant Boolean :=
kono
parents:
diff changeset
312 Is_GNAT_File_Name (Fname);
kono
parents:
diff changeset
313 Version : Word := 0;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 begin
kono
parents:
diff changeset
316 Load_Stack.Increment_Last;
kono
parents:
diff changeset
317 Load_Stack.Table (Load_Stack.Last) := (Main_Unit, Empty);
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 -- Initialize unit table entry for Main_Unit. Note that we don't know
kono
parents:
diff changeset
320 -- the unit name yet, that gets filled in when the parser parses the
kono
parents:
diff changeset
321 -- main unit, at which time a check is made that it matches the main
kono
parents:
diff changeset
322 -- file name, and then the Unit_Name field is set. The Cunit and
kono
parents:
diff changeset
323 -- Cunit_Entity fields also get filled in later by the parser.
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 Units.Increment_Last;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 Units.Table (Main_Unit).Unit_File_Name := Fname;
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 if Fname /= No_File then
kono
parents:
diff changeset
330 Main_Source_File := Load_Source_File (Fname);
kono
parents:
diff changeset
331 Current_Error_Source_File := Main_Source_File;
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 if Main_Source_File > No_Source_File then
kono
parents:
diff changeset
334 Version := Source_Checksum (Main_Source_File);
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 else
kono
parents:
diff changeset
337 -- To avoid emitting a source location (since there is no file),
kono
parents:
diff changeset
338 -- we write a custom error message instead of using the machinery
kono
parents:
diff changeset
339 -- in errout.adb.
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 Set_Standard_Error;
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 if Main_Source_File = No_Access_To_Source_File then
kono
parents:
diff changeset
344 Write_Str
kono
parents:
diff changeset
345 ("no read access for file """ & Get_Name_String (Fname)
kono
parents:
diff changeset
346 & """");
kono
parents:
diff changeset
347 else
kono
parents:
diff changeset
348 Write_Str
kono
parents:
diff changeset
349 ("file """ & Get_Name_String (Fname) & """ not found");
kono
parents:
diff changeset
350 end if;
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 Write_Eol;
kono
parents:
diff changeset
353 Set_Standard_Output;
kono
parents:
diff changeset
354 end if;
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 Units.Table (Main_Unit) :=
kono
parents:
diff changeset
357 (Cunit => Empty,
kono
parents:
diff changeset
358 Cunit_Entity => Empty,
kono
parents:
diff changeset
359 Dependency_Num => 0,
kono
parents:
diff changeset
360 Dynamic_Elab => False,
kono
parents:
diff changeset
361 Error_Location => No_Location,
kono
parents:
diff changeset
362 Expected_Unit => No_Unit_Name,
kono
parents:
diff changeset
363 Fatal_Error => None,
kono
parents:
diff changeset
364 Generate_Code => False,
kono
parents:
diff changeset
365 Has_RACW => False,
kono
parents:
diff changeset
366 Filler => False,
kono
parents:
diff changeset
367 Ident_String => Empty,
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 Is_Predefined_Renaming => Ren_Name,
kono
parents:
diff changeset
370 Is_Predefined_Unit => Pre_Name or Ren_Name,
kono
parents:
diff changeset
371 Is_Internal_Unit => Pre_Name or Ren_Name or GNAT_Name,
kono
parents:
diff changeset
372 Filler2 => False,
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 Loading => True,
kono
parents:
diff changeset
375 Main_Priority => Default_Main_Priority,
kono
parents:
diff changeset
376 Main_CPU => Default_Main_CPU,
kono
parents:
diff changeset
377 Primary_Stack_Count => 0,
kono
parents:
diff changeset
378 Sec_Stack_Count => 0,
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 Munit_Index => 0,
kono
parents:
diff changeset
381 No_Elab_Code_All => False,
kono
parents:
diff changeset
382 Serial_Number => 0,
kono
parents:
diff changeset
383 Source_Index => Main_Source_File,
kono
parents:
diff changeset
384 Unit_File_Name => Fname,
kono
parents:
diff changeset
385 Unit_Name => No_Unit_Name,
kono
parents:
diff changeset
386 Version => Version,
kono
parents:
diff changeset
387 OA_Setting => 'O');
kono
parents:
diff changeset
388 end if;
kono
parents:
diff changeset
389 end Load_Main_Source;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 ---------------
kono
parents:
diff changeset
392 -- Load_Unit --
kono
parents:
diff changeset
393 ---------------
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 function Load_Unit
kono
parents:
diff changeset
396 (Load_Name : Unit_Name_Type;
kono
parents:
diff changeset
397 Required : Boolean;
kono
parents:
diff changeset
398 Error_Node : Node_Id;
kono
parents:
diff changeset
399 Subunit : Boolean;
kono
parents:
diff changeset
400 Corr_Body : Unit_Number_Type := No_Unit;
kono
parents:
diff changeset
401 Renamings : Boolean := False;
kono
parents:
diff changeset
402 With_Node : Node_Id := Empty;
kono
parents:
diff changeset
403 PMES : Boolean := False) return Unit_Number_Type
kono
parents:
diff changeset
404 is
kono
parents:
diff changeset
405 Calling_Unit : Unit_Number_Type;
kono
parents:
diff changeset
406 Uname_Actual : Unit_Name_Type;
kono
parents:
diff changeset
407 Unum : Unit_Number_Type;
kono
parents:
diff changeset
408 Unump : Unit_Number_Type;
kono
parents:
diff changeset
409 Fname : File_Name_Type;
kono
parents:
diff changeset
410 Pre_Name : Boolean;
kono
parents:
diff changeset
411 Ren_Name : Boolean;
kono
parents:
diff changeset
412 GNAT_Name : Boolean;
kono
parents:
diff changeset
413 Src_Ind : Source_File_Index;
kono
parents:
diff changeset
414 Save_PMES : constant Boolean := Parsing_Main_Extended_Source;
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 Save_Cunit_Restrictions : constant Save_Cunit_Boolean_Restrictions :=
kono
parents:
diff changeset
417 Cunit_Boolean_Restrictions_Save;
kono
parents:
diff changeset
418 -- Save current restrictions for restore at end
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 begin
kono
parents:
diff changeset
421 Parsing_Main_Extended_Source := PMES;
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 -- Initialize restrictions to config restrictions for unit to load if
kono
parents:
diff changeset
424 -- it is part of the main extended source, otherwise reset them.
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 -- Note: it's a bit odd but PMES is False for subunits, which is why
kono
parents:
diff changeset
427 -- we have the OR here. Should be investigated some time???
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 if PMES or Subunit then
kono
parents:
diff changeset
430 Restore_Config_Cunit_Boolean_Restrictions;
kono
parents:
diff changeset
431 else
kono
parents:
diff changeset
432 Reset_Cunit_Boolean_Restrictions;
kono
parents:
diff changeset
433 end if;
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 -- If renamings are allowed and we have a child unit name, then we
kono
parents:
diff changeset
436 -- must first load the parent to deal with finding the real name.
kono
parents:
diff changeset
437 -- Retain the with_clause that names the child, so that if it is
kono
parents:
diff changeset
438 -- limited, the parent is loaded under the same condition.
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 if Renamings and then Is_Child_Name (Load_Name) then
kono
parents:
diff changeset
441 Unump :=
kono
parents:
diff changeset
442 Load_Unit
kono
parents:
diff changeset
443 (Load_Name => Get_Parent_Spec_Name (Load_Name),
kono
parents:
diff changeset
444 Required => Required,
kono
parents:
diff changeset
445 Subunit => False,
kono
parents:
diff changeset
446 Renamings => True,
kono
parents:
diff changeset
447 Error_Node => Error_Node,
kono
parents:
diff changeset
448 With_Node => With_Node);
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 if Unump = No_Unit then
kono
parents:
diff changeset
451 Parsing_Main_Extended_Source := Save_PMES;
kono
parents:
diff changeset
452 return No_Unit;
kono
parents:
diff changeset
453 end if;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 -- If parent is a renaming, then we use the renamed package as
kono
parents:
diff changeset
456 -- the actual parent for the subsequent load operation.
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 if Nkind (Unit (Cunit (Unump))) = N_Package_Renaming_Declaration then
kono
parents:
diff changeset
459 Uname_Actual :=
kono
parents:
diff changeset
460 New_Child
kono
parents:
diff changeset
461 (Load_Name, Get_Unit_Name (Name (Unit (Cunit (Unump)))));
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 -- If the load is for a with_clause, for visibility purposes both
kono
parents:
diff changeset
464 -- the renamed entity and renaming one must be available in the
kono
parents:
diff changeset
465 -- current unit: the renamed one in order to retrieve the child
kono
parents:
diff changeset
466 -- unit, and the original one because it may be used as a prefix
kono
parents:
diff changeset
467 -- in the body of the current unit. We add an explicit with_clause
kono
parents:
diff changeset
468 -- for the original parent so that the renaming declaration is
kono
parents:
diff changeset
469 -- properly loaded and analyzed.
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 if Present (With_Node) then
kono
parents:
diff changeset
472 Insert_After (With_Node,
kono
parents:
diff changeset
473 Make_With_Clause (Sloc (With_Node),
kono
parents:
diff changeset
474 Name => Copy_Separate_Tree (Prefix (Name (With_Node)))));
kono
parents:
diff changeset
475 end if;
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 -- Save the renaming entity, to establish its visibility when
kono
parents:
diff changeset
478 -- installing the context. The implicit with is on this entity,
kono
parents:
diff changeset
479 -- not on the package it renames. This is somewhat redundant given
kono
parents:
diff changeset
480 -- the with_clause just created, but it simplifies subsequent
kono
parents:
diff changeset
481 -- expansion of the current with_clause. Optimizable ???
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 if Nkind (Error_Node) = N_With_Clause
kono
parents:
diff changeset
484 and then Nkind (Name (Error_Node)) = N_Selected_Component
kono
parents:
diff changeset
485 then
kono
parents:
diff changeset
486 declare
kono
parents:
diff changeset
487 Par : Node_Id := Name (Error_Node);
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 begin
kono
parents:
diff changeset
490 while Nkind (Par) = N_Selected_Component
kono
parents:
diff changeset
491 and then Chars (Selector_Name (Par)) /=
kono
parents:
diff changeset
492 Chars (Cunit_Entity (Unump))
kono
parents:
diff changeset
493 loop
kono
parents:
diff changeset
494 Par := Prefix (Par);
kono
parents:
diff changeset
495 end loop;
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 -- Case of some intermediate parent is a renaming
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 if Nkind (Par) = N_Selected_Component then
kono
parents:
diff changeset
500 Set_Entity (Selector_Name (Par), Cunit_Entity (Unump));
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 -- Case where the ultimate parent is a renaming
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 else
kono
parents:
diff changeset
505 Set_Entity (Par, Cunit_Entity (Unump));
kono
parents:
diff changeset
506 end if;
kono
parents:
diff changeset
507 end;
kono
parents:
diff changeset
508 end if;
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 -- If the parent is not a renaming, then get its name (this may
kono
parents:
diff changeset
511 -- be different from the parent spec name obtained above because
kono
parents:
diff changeset
512 -- of renamings higher up in the hierarchy).
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 else
kono
parents:
diff changeset
515 Uname_Actual := New_Child (Load_Name, Unit_Name (Unump));
kono
parents:
diff changeset
516 end if;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 -- Here if unit to be loaded is not a child unit
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 else
kono
parents:
diff changeset
521 Uname_Actual := Load_Name;
kono
parents:
diff changeset
522 end if;
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 Fname := Get_File_Name (Uname_Actual, Subunit);
kono
parents:
diff changeset
525 Pre_Name :=
kono
parents:
diff changeset
526 Is_Predefined_File_Name (Fname, Renamings_Included => False);
kono
parents:
diff changeset
527 Ren_Name := Is_Predefined_Renaming_File_Name (Fname);
kono
parents:
diff changeset
528 GNAT_Name := Is_GNAT_File_Name (Fname);
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 if Debug_Flag_L then
kono
parents:
diff changeset
531 Write_Eol;
kono
parents:
diff changeset
532 Write_Str ("*** Load request for unit: ");
kono
parents:
diff changeset
533 Write_Unit_Name (Load_Name);
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 if Required then
kono
parents:
diff changeset
536 Write_Str (" (Required = True)");
kono
parents:
diff changeset
537 else
kono
parents:
diff changeset
538 Write_Str (" (Required = False)");
kono
parents:
diff changeset
539 end if;
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 Write_Eol;
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 if Uname_Actual /= Load_Name then
kono
parents:
diff changeset
544 Write_Str ("*** Actual unit loaded: ");
kono
parents:
diff changeset
545 Write_Unit_Name (Uname_Actual);
kono
parents:
diff changeset
546 end if;
kono
parents:
diff changeset
547 end if;
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 -- Capture error location if it is for the main unit. The idea is to
kono
parents:
diff changeset
550 -- post errors on the main unit location, not the most recent unit.
kono
parents:
diff changeset
551 -- Note: Unit_Name (Main_Unit) is not set if we are parsing gnat.adc.
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 if Present (Error_Node)
kono
parents:
diff changeset
554 and then Unit_Name (Main_Unit) /= No_Unit_Name
kono
parents:
diff changeset
555 then
kono
parents:
diff changeset
556 -- It seems like In_Extended_Main_Source_Unit (Error_Node) would
kono
parents:
diff changeset
557 -- do the trick here, but that's wrong, it is much too early to
kono
parents:
diff changeset
558 -- call this routine. We are still in the parser, and the required
kono
parents:
diff changeset
559 -- semantic information is not established yet. So we base the
kono
parents:
diff changeset
560 -- judgment on unit names.
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 Get_External_Unit_Name_String (Unit_Name (Main_Unit));
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 declare
kono
parents:
diff changeset
565 Main_Unit_Name : constant String := Name_Buffer (1 .. Name_Len);
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 begin
kono
parents:
diff changeset
568 Get_External_Unit_Name_String
kono
parents:
diff changeset
569 (Unit_Name (Get_Source_Unit (Error_Node)));
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 -- If the two names are identical, then for sure we are part
kono
parents:
diff changeset
572 -- of the extended main unit
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 if Main_Unit_Name = Name_Buffer (1 .. Name_Len) then
kono
parents:
diff changeset
575 Load_Msg_Sloc := Sloc (Error_Node);
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 -- If the load is called from a with_type clause, the error
kono
parents:
diff changeset
578 -- node is correct.
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 -- Otherwise, check for the subunit case, and if so, consider
kono
parents:
diff changeset
581 -- we have a match if one name is a prefix of the other name.
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 else
kono
parents:
diff changeset
584 if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
kono
parents:
diff changeset
585 or else
kono
parents:
diff changeset
586 Nkind (Unit (Cunit (Get_Source_Unit (Error_Node)))) =
kono
parents:
diff changeset
587 N_Subunit
kono
parents:
diff changeset
588 then
kono
parents:
diff changeset
589 Name_Len := Integer'Min (Name_Len, Main_Unit_Name'Length);
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 if Name_Buffer (1 .. Name_Len)
kono
parents:
diff changeset
592 =
kono
parents:
diff changeset
593 Main_Unit_Name (1 .. Name_Len)
kono
parents:
diff changeset
594 then
kono
parents:
diff changeset
595 Load_Msg_Sloc := Sloc (Error_Node);
kono
parents:
diff changeset
596 end if;
kono
parents:
diff changeset
597 end if;
kono
parents:
diff changeset
598 end if;
kono
parents:
diff changeset
599 end;
kono
parents:
diff changeset
600 end if;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 -- If we are generating error messages, then capture calling unit
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 if Present (Error_Node) then
kono
parents:
diff changeset
605 Calling_Unit := Get_Source_Unit (Error_Node);
kono
parents:
diff changeset
606 else
kono
parents:
diff changeset
607 Calling_Unit := No_Unit;
kono
parents:
diff changeset
608 end if;
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 -- See if we already have an entry for this unit
kono
parents:
diff changeset
611
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
612 Unum := Unit_Names.Get (Uname_Actual);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
613 if Unum = No_Unit then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
614 Unum := Units.Last + 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
615 end if;
111
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 -- Whether or not the entry was found, Unum is now the right value,
kono
parents:
diff changeset
618 -- since it is one more than Units.Last (i.e. the index of the new
kono
parents:
diff changeset
619 -- entry we will create) in the not found case.
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 -- A special check is necessary in the unit not found case. If the unit
kono
parents:
diff changeset
622 -- is not found, but the file in which it lives has already been loaded,
kono
parents:
diff changeset
623 -- then we have the problem that the file does not contain the unit that
kono
parents:
diff changeset
624 -- is needed. We simply treat this as a file not found condition.
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 -- We skip this test in multiple unit per file mode since in this
kono
parents:
diff changeset
627 -- case we can have multiple units from the same source file.
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 if Unum > Units.Last and then Get_Unit_Index (Uname_Actual) = 0 then
kono
parents:
diff changeset
630 for J in Units.First .. Units.Last loop
kono
parents:
diff changeset
631 if Fname = Units.Table (J).Unit_File_Name then
kono
parents:
diff changeset
632 if Debug_Flag_L then
kono
parents:
diff changeset
633 Write_Str (" file does not contain unit, Unit_Number = ");
kono
parents:
diff changeset
634 Write_Int (Int (Unum));
kono
parents:
diff changeset
635 Write_Eol;
kono
parents:
diff changeset
636 Write_Eol;
kono
parents:
diff changeset
637 end if;
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 if Present (Error_Node) then
kono
parents:
diff changeset
640 Get_Name_String (Fname);
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 if Is_Predefined_File_Name (Fname) then
kono
parents:
diff changeset
643 Error_Msg_Unit_1 := Uname_Actual;
kono
parents:
diff changeset
644 Error_Msg
kono
parents:
diff changeset
645 ("$$ is not a language defined unit", Load_Msg_Sloc);
kono
parents:
diff changeset
646 else
kono
parents:
diff changeset
647 Error_Msg_File_1 := Fname;
kono
parents:
diff changeset
648 Error_Msg_Unit_1 := Uname_Actual;
kono
parents:
diff changeset
649 Error_Msg ("File{ does not contain unit$", Load_Msg_Sloc);
kono
parents:
diff changeset
650 end if;
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 Write_Dependency_Chain;
kono
parents:
diff changeset
653 Unum := No_Unit;
kono
parents:
diff changeset
654 goto Done;
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 else
kono
parents:
diff changeset
657 Unum := No_Unit;
kono
parents:
diff changeset
658 goto Done;
kono
parents:
diff changeset
659 end if;
kono
parents:
diff changeset
660 end if;
kono
parents:
diff changeset
661 end loop;
kono
parents:
diff changeset
662 end if;
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 -- If we are proceeding with load, then make load stack entry,
kono
parents:
diff changeset
665 -- and indicate the kind of with_clause responsible for the load.
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 Load_Stack.Increment_Last;
kono
parents:
diff changeset
668 Load_Stack.Table (Load_Stack.Last) := (Unum, With_Node);
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 -- Case of entry already in table
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 if Unum <= Units.Last then
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 -- Here is where we check for a circular dependency, which is
kono
parents:
diff changeset
675 -- an attempt to load a unit which is currently in the process
kono
parents:
diff changeset
676 -- of being loaded. We do *not* care about a circular chain that
kono
parents:
diff changeset
677 -- leads back to a body, because this kind of circular dependence
kono
parents:
diff changeset
678 -- legitimately occurs (e.g. two package bodies that contain
kono
parents:
diff changeset
679 -- inlined subprogram referenced by the other).
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 -- Ada 2005 (AI-50217): We also ignore limited_with clauses, because
kono
parents:
diff changeset
682 -- their purpose is precisely to create legal circular structures.
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 if Loading (Unum)
kono
parents:
diff changeset
685 and then (Is_Spec_Name (Units.Table (Unum).Unit_Name)
kono
parents:
diff changeset
686 or else Acts_As_Spec (Units.Table (Unum).Cunit))
kono
parents:
diff changeset
687 and then (Nkind (Error_Node) /= N_With_Clause
kono
parents:
diff changeset
688 or else not Limited_Present (Error_Node))
kono
parents:
diff changeset
689 and then not From_Limited_With_Chain
kono
parents:
diff changeset
690 then
kono
parents:
diff changeset
691 if Debug_Flag_L then
kono
parents:
diff changeset
692 Write_Str (" circular dependency encountered");
kono
parents:
diff changeset
693 Write_Eol;
kono
parents:
diff changeset
694 end if;
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 if Present (Error_Node) then
kono
parents:
diff changeset
697 Error_Msg ("circular unit dependency", Load_Msg_Sloc);
kono
parents:
diff changeset
698 Write_Dependency_Chain;
kono
parents:
diff changeset
699 else
kono
parents:
diff changeset
700 Load_Stack.Decrement_Last;
kono
parents:
diff changeset
701 end if;
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 Unum := No_Unit;
kono
parents:
diff changeset
704 goto Done;
kono
parents:
diff changeset
705 end if;
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 if Debug_Flag_L then
kono
parents:
diff changeset
708 Write_Str (" unit already in file table, Unit_Number = ");
kono
parents:
diff changeset
709 Write_Int (Int (Unum));
kono
parents:
diff changeset
710 Write_Eol;
kono
parents:
diff changeset
711 end if;
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 Load_Stack.Decrement_Last;
kono
parents:
diff changeset
714 goto Done;
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 -- Unit is not already in table, so try to open the file
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 else
kono
parents:
diff changeset
719 if Debug_Flag_L then
kono
parents:
diff changeset
720 Write_Str (" attempt unit load, Unit_Number = ");
kono
parents:
diff changeset
721 Write_Int (Int (Unum));
kono
parents:
diff changeset
722 Write_Eol;
kono
parents:
diff changeset
723 end if;
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 Src_Ind := Load_Source_File (Fname);
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 -- Make a partial entry in the file table, used even in the file not
kono
parents:
diff changeset
728 -- found case to print the dependency chain including the last entry
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 Units.Increment_Last;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
731 Init_Unit_Name (Unum, Uname_Actual);
111
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 -- File was found
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 if Src_Ind > No_Source_File then
kono
parents:
diff changeset
736 Units.Table (Unum) :=
kono
parents:
diff changeset
737 (Cunit => Empty,
kono
parents:
diff changeset
738 Cunit_Entity => Empty,
kono
parents:
diff changeset
739 Dependency_Num => 0,
kono
parents:
diff changeset
740 Dynamic_Elab => False,
kono
parents:
diff changeset
741 Error_Location => Sloc (Error_Node),
kono
parents:
diff changeset
742 Expected_Unit => Uname_Actual,
kono
parents:
diff changeset
743 Fatal_Error => None,
kono
parents:
diff changeset
744 Generate_Code => False,
kono
parents:
diff changeset
745 Has_RACW => False,
kono
parents:
diff changeset
746 Filler => False,
kono
parents:
diff changeset
747 Ident_String => Empty,
kono
parents:
diff changeset
748
kono
parents:
diff changeset
749 Is_Predefined_Renaming => Ren_Name,
kono
parents:
diff changeset
750 Is_Predefined_Unit => Pre_Name or Ren_Name,
kono
parents:
diff changeset
751 Is_Internal_Unit => Pre_Name or Ren_Name or GNAT_Name,
kono
parents:
diff changeset
752 Filler2 => False,
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 Loading => True,
kono
parents:
diff changeset
755 Main_Priority => Default_Main_Priority,
kono
parents:
diff changeset
756 Main_CPU => Default_Main_CPU,
kono
parents:
diff changeset
757 Primary_Stack_Count => 0,
kono
parents:
diff changeset
758 Sec_Stack_Count => 0,
kono
parents:
diff changeset
759 Munit_Index => 0,
kono
parents:
diff changeset
760 No_Elab_Code_All => False,
kono
parents:
diff changeset
761 Serial_Number => 0,
kono
parents:
diff changeset
762 Source_Index => Src_Ind,
kono
parents:
diff changeset
763 Unit_File_Name => Fname,
kono
parents:
diff changeset
764 Unit_Name => Uname_Actual,
kono
parents:
diff changeset
765 Version => Source_Checksum (Src_Ind),
kono
parents:
diff changeset
766 OA_Setting => 'O');
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 -- Parse the new unit
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 declare
kono
parents:
diff changeset
771 Save_Index : constant Nat := Multiple_Unit_Index;
kono
parents:
diff changeset
772 Save_PMES : constant Boolean := Parsing_Main_Extended_Source;
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 begin
kono
parents:
diff changeset
775 Multiple_Unit_Index := Get_Unit_Index (Uname_Actual);
kono
parents:
diff changeset
776 Units.Table (Unum).Munit_Index := Multiple_Unit_Index;
kono
parents:
diff changeset
777 Initialize_Scanner (Unum, Source_Index (Unum));
kono
parents:
diff changeset
778
kono
parents:
diff changeset
779 if Calling_Unit = Main_Unit and then Subunit then
kono
parents:
diff changeset
780 Parsing_Main_Extended_Source := True;
kono
parents:
diff changeset
781 end if;
kono
parents:
diff changeset
782
kono
parents:
diff changeset
783 Discard_List (Par (Configuration_Pragmas => False));
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 Parsing_Main_Extended_Source := Save_PMES;
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 Multiple_Unit_Index := Save_Index;
kono
parents:
diff changeset
788 Set_Loading (Unum, False);
kono
parents:
diff changeset
789 end;
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 -- If spec is irrelevant, then post errors and quit
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 if Corr_Body /= No_Unit
kono
parents:
diff changeset
794 and then Spec_Is_Irrelevant (Unum, Corr_Body)
kono
parents:
diff changeset
795 then
kono
parents:
diff changeset
796 Error_Msg_File_1 := Unit_File_Name (Corr_Body);
kono
parents:
diff changeset
797 Error_Msg
kono
parents:
diff changeset
798 ("cannot compile subprogram in file {!", Load_Msg_Sloc);
kono
parents:
diff changeset
799 Error_Msg_File_1 := Unit_File_Name (Unum);
kono
parents:
diff changeset
800 Error_Msg
kono
parents:
diff changeset
801 ("\incorrect spec in file { must be removed first!",
kono
parents:
diff changeset
802 Load_Msg_Sloc);
kono
parents:
diff changeset
803 Unum := No_Unit;
kono
parents:
diff changeset
804 goto Done;
kono
parents:
diff changeset
805 end if;
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 -- If loaded unit had an error, then caller inherits setting
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 if Present (Error_Node) then
kono
parents:
diff changeset
810 case Units.Table (Unum).Fatal_Error is
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 -- Nothing to do if with'ed unit had no error
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 when None =>
kono
parents:
diff changeset
815 null;
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 -- If with'ed unit had a detected fatal error, propagate it
kono
parents:
diff changeset
818
kono
parents:
diff changeset
819 when Error_Detected =>
kono
parents:
diff changeset
820 Units.Table (Calling_Unit).Fatal_Error := Error_Detected;
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 -- If with'ed unit had an ignored error, then propagate it
kono
parents:
diff changeset
823 -- but do not overide an existring setting.
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 when Error_Ignored =>
kono
parents:
diff changeset
826 if Units.Table (Calling_Unit).Fatal_Error = None then
kono
parents:
diff changeset
827 Units.Table (Calling_Unit).Fatal_Error :=
kono
parents:
diff changeset
828 Error_Ignored;
kono
parents:
diff changeset
829 end if;
kono
parents:
diff changeset
830 end case;
kono
parents:
diff changeset
831 end if;
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 -- Remove load stack entry and return the entry in the file table
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 Load_Stack.Decrement_Last;
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 -- All done, return unit number
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 goto Done;
kono
parents:
diff changeset
840
kono
parents:
diff changeset
841 -- Case of file not found
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 else
kono
parents:
diff changeset
844 if Debug_Flag_L then
kono
parents:
diff changeset
845 if Src_Ind = No_Access_To_Source_File then
kono
parents:
diff changeset
846 Write_Str (" no read access to file, load failed");
kono
parents:
diff changeset
847 else
kono
parents:
diff changeset
848 Write_Str (" file was not found, load failed");
kono
parents:
diff changeset
849 end if;
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 Write_Eol;
kono
parents:
diff changeset
852 end if;
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 -- Generate message if unit required
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 if Required then
kono
parents:
diff changeset
857 Get_Name_String (Fname);
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 if Is_Predefined_File_Name (Fname) then
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 -- This is a predefined library unit which is not present
kono
parents:
diff changeset
862 -- in the run time. If a predefined unit is not available
kono
parents:
diff changeset
863 -- it may very likely be the case that there is also pragma
kono
parents:
diff changeset
864 -- Restriction forbidding its usage. This is typically the
kono
parents:
diff changeset
865 -- case when building a configurable run time, where the
kono
parents:
diff changeset
866 -- usage of certain run-time units is restricted by means
kono
parents:
diff changeset
867 -- of both the corresponding pragma Restriction (such as
kono
parents:
diff changeset
868 -- No_Calendar), and by not including the unit. Hence, we
kono
parents:
diff changeset
869 -- check whether this predefined unit is forbidden, so that
kono
parents:
diff changeset
870 -- the message about the restriction violation is generated,
kono
parents:
diff changeset
871 -- if needed.
kono
parents:
diff changeset
872
kono
parents:
diff changeset
873 if Present (Error_Node) then
kono
parents:
diff changeset
874 Check_Restricted_Unit (Load_Name, Error_Node);
kono
parents:
diff changeset
875 end if;
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877 Error_Msg_Unit_1 := Uname_Actual;
kono
parents:
diff changeset
878 Error_Msg -- CODEFIX
kono
parents:
diff changeset
879 ("$$ is not a predefined library unit", Load_Msg_Sloc);
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 else
kono
parents:
diff changeset
882 Error_Msg_File_1 := Fname;
kono
parents:
diff changeset
883
kono
parents:
diff changeset
884 if Src_Ind = No_Access_To_Source_File then
kono
parents:
diff changeset
885 Error_Msg ("no read access to file{", Load_Msg_Sloc);
kono
parents:
diff changeset
886 else
kono
parents:
diff changeset
887 Error_Msg ("file{ not found", Load_Msg_Sloc);
kono
parents:
diff changeset
888 end if;
kono
parents:
diff changeset
889 end if;
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 Write_Dependency_Chain;
kono
parents:
diff changeset
892
kono
parents:
diff changeset
893 -- Remove unit from stack, to avoid cascaded errors on
kono
parents:
diff changeset
894 -- subsequent missing files.
kono
parents:
diff changeset
895
kono
parents:
diff changeset
896 Load_Stack.Decrement_Last;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
897 Remove_Unit (Unum);
111
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 -- If unit not required, remove load stack entry and the junk
kono
parents:
diff changeset
900 -- file table entry, and return No_Unit to indicate not found,
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 else
kono
parents:
diff changeset
903 Load_Stack.Decrement_Last;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
904 Remove_Unit (Unum);
111
kono
parents:
diff changeset
905 end if;
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907 Unum := No_Unit;
kono
parents:
diff changeset
908 goto Done;
kono
parents:
diff changeset
909 end if;
kono
parents:
diff changeset
910 end if;
kono
parents:
diff changeset
911
kono
parents:
diff changeset
912 -- Here to exit, with result in Unum
kono
parents:
diff changeset
913
kono
parents:
diff changeset
914 <<Done>>
kono
parents:
diff changeset
915 Parsing_Main_Extended_Source := Save_PMES;
kono
parents:
diff changeset
916 Cunit_Boolean_Restrictions_Restore (Save_Cunit_Restrictions);
kono
parents:
diff changeset
917 return Unum;
kono
parents:
diff changeset
918 end Load_Unit;
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 --------------------------
kono
parents:
diff changeset
921 -- Make_Child_Decl_Unit --
kono
parents:
diff changeset
922 --------------------------
kono
parents:
diff changeset
923
kono
parents:
diff changeset
924 procedure Make_Child_Decl_Unit (N : Node_Id) is
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
925 Unit_Decl : constant Node_Id := Library_Unit (N);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
926 Unit_Num : constant Unit_Number_Type := Get_Cunit_Unit_Number (N);
111
kono
parents:
diff changeset
927
kono
parents:
diff changeset
928 begin
kono
parents:
diff changeset
929 Units.Increment_Last;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
930 Units.Table (Units.Last) := Units.Table (Unit_Num);
111
kono
parents:
diff changeset
931 Units.Table (Units.Last).Cunit := Unit_Decl;
kono
parents:
diff changeset
932 Units.Table (Units.Last).Cunit_Entity :=
kono
parents:
diff changeset
933 Defining_Identifier
kono
parents:
diff changeset
934 (Defining_Unit_Name (Specification (Unit (Unit_Decl))));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
935 Init_Unit_Name (Units.Last, Get_Spec_Name (Unit_Name (Unit_Num)));
111
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 -- The library unit created for of a child subprogram unit plays no
kono
parents:
diff changeset
938 -- role in code generation and binding, so label it accordingly.
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 Units.Table (Units.Last).Generate_Code := False;
kono
parents:
diff changeset
941 Set_Has_No_Elaboration_Code (Unit_Decl);
kono
parents:
diff changeset
942 end Make_Child_Decl_Unit;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 ------------------------
kono
parents:
diff changeset
945 -- Make_Instance_Unit --
kono
parents:
diff changeset
946 ------------------------
kono
parents:
diff changeset
947
kono
parents:
diff changeset
948 -- If the unit is an instance, it appears as a package declaration, but
kono
parents:
diff changeset
949 -- contains both declaration and body of the instance. The body becomes
kono
parents:
diff changeset
950 -- the main unit of the compilation, and the declaration is inserted
kono
parents:
diff changeset
951 -- at the end of the unit table. The main unit now has the name of a
kono
parents:
diff changeset
952 -- body, which is constructed from the name of the original spec,
kono
parents:
diff changeset
953 -- and is attached to the compilation node of the original unit. The
kono
parents:
diff changeset
954 -- declaration has been attached to a new compilation unit node, and
kono
parents:
diff changeset
955 -- code will have to be generated for it.
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 procedure Make_Instance_Unit (N : Node_Id; In_Main : Boolean) is
kono
parents:
diff changeset
958 Sind : constant Source_File_Index := Source_Index (Main_Unit);
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 begin
kono
parents:
diff changeset
961 Units.Increment_Last;
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 if In_Main then
kono
parents:
diff changeset
964 Units.Table (Units.Last) := Units.Table (Main_Unit);
kono
parents:
diff changeset
965 Units.Table (Units.Last).Cunit := Library_Unit (N);
kono
parents:
diff changeset
966 Units.Table (Units.Last).Generate_Code := True;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
967 Init_Unit_Name (Units.Last, Unit_Name (Main_Unit));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
968
111
kono
parents:
diff changeset
969 Units.Table (Main_Unit).Cunit := N;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 Units.Table (Main_Unit).Version := Source_Checksum (Sind);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 Init_Unit_Name (Main_Unit,
111
kono
parents:
diff changeset
972 Get_Body_Name
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973 (Unit_Name (Get_Cunit_Unit_Number (Library_Unit (N)))));
111
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 else
kono
parents:
diff changeset
976 -- Duplicate information from instance unit, for the body. The unit
kono
parents:
diff changeset
977 -- node N has been rewritten as a body, but it was placed in the
kono
parents:
diff changeset
978 -- units table when first loaded as a declaration.
kono
parents:
diff changeset
979
kono
parents:
diff changeset
980 Units.Table (Units.Last) := Units.Table (Get_Cunit_Unit_Number (N));
kono
parents:
diff changeset
981 Units.Table (Units.Last).Cunit := Library_Unit (N);
kono
parents:
diff changeset
982 end if;
kono
parents:
diff changeset
983 end Make_Instance_Unit;
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 ------------------------
kono
parents:
diff changeset
986 -- Spec_Is_Irrelevant --
kono
parents:
diff changeset
987 ------------------------
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 function Spec_Is_Irrelevant
kono
parents:
diff changeset
990 (Spec_Unit : Unit_Number_Type;
kono
parents:
diff changeset
991 Body_Unit : Unit_Number_Type) return Boolean
kono
parents:
diff changeset
992 is
kono
parents:
diff changeset
993 Sunit : constant Node_Id := Cunit (Spec_Unit);
kono
parents:
diff changeset
994 Bunit : constant Node_Id := Cunit (Body_Unit);
kono
parents:
diff changeset
995
kono
parents:
diff changeset
996 begin
kono
parents:
diff changeset
997 -- The spec is irrelevant if the body is a subprogram body, and the spec
kono
parents:
diff changeset
998 -- is other than a subprogram spec or generic subprogram spec. Note that
kono
parents:
diff changeset
999 -- the names must be the same, we don't need to check that, because we
kono
parents:
diff changeset
1000 -- already know that from the fact that the file names are the same.
kono
parents:
diff changeset
1001
kono
parents:
diff changeset
1002 return
kono
parents:
diff changeset
1003 Nkind (Unit (Bunit)) = N_Subprogram_Body
kono
parents:
diff changeset
1004 and then Nkind (Unit (Sunit)) /= N_Subprogram_Declaration
kono
parents:
diff changeset
1005 and then Nkind (Unit (Sunit)) /= N_Generic_Subprogram_Declaration;
kono
parents:
diff changeset
1006 end Spec_Is_Irrelevant;
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 --------------------
kono
parents:
diff changeset
1009 -- Version_Update --
kono
parents:
diff changeset
1010 --------------------
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 procedure Version_Update (U : Node_Id; From : Node_Id) is
kono
parents:
diff changeset
1013 Unum : constant Unit_Number_Type := Get_Cunit_Unit_Number (U);
kono
parents:
diff changeset
1014 Fnum : constant Unit_Number_Type := Get_Cunit_Unit_Number (From);
kono
parents:
diff changeset
1015 begin
kono
parents:
diff changeset
1016 if Source_Index (Fnum) > No_Source_File then
kono
parents:
diff changeset
1017 Units.Table (Unum).Version :=
kono
parents:
diff changeset
1018 Units.Table (Unum).Version
kono
parents:
diff changeset
1019 xor
kono
parents:
diff changeset
1020 Source_Checksum (Source_Index (Fnum));
kono
parents:
diff changeset
1021 end if;
kono
parents:
diff changeset
1022 end Version_Update;
kono
parents:
diff changeset
1023
kono
parents:
diff changeset
1024 ----------------------------
kono
parents:
diff changeset
1025 -- Write_Dependency_Chain --
kono
parents:
diff changeset
1026 ----------------------------
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 procedure Write_Dependency_Chain is
kono
parents:
diff changeset
1029 begin
kono
parents:
diff changeset
1030 -- The dependency chain is only written if it is at least two entries
kono
parents:
diff changeset
1031 -- deep, otherwise it is trivial (the main unit depending on a unit
kono
parents:
diff changeset
1032 -- that it obviously directly depends on).
kono
parents:
diff changeset
1033
kono
parents:
diff changeset
1034 if Load_Stack.Last - 1 > Load_Stack.First then
kono
parents:
diff changeset
1035 for U in Load_Stack.First .. Load_Stack.Last - 1 loop
kono
parents:
diff changeset
1036 Error_Msg_Unit_1 :=
kono
parents:
diff changeset
1037 Unit_Name (Load_Stack.Table (U).Unit_Number);
kono
parents:
diff changeset
1038 Error_Msg_Unit_2 :=
kono
parents:
diff changeset
1039 Unit_Name (Load_Stack.Table (U + 1).Unit_Number);
kono
parents:
diff changeset
1040 Error_Msg ("$ depends on $!", Load_Msg_Sloc);
kono
parents:
diff changeset
1041 end loop;
kono
parents:
diff changeset
1042 end if;
kono
parents:
diff changeset
1043 end Write_Dependency_Chain;
kono
parents:
diff changeset
1044
kono
parents:
diff changeset
1045 end Lib.Load;