annotate gcc/ada/par-load.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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 -- P A R . L O A D --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, 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 -- The Par.Load procedure loads all units that are definitely required before
kono
parents:
diff changeset
27 -- it makes any sense at all to proceed with semantic analysis, including
kono
parents:
diff changeset
28 -- with'ed units, corresponding specs for bodies, parents of child specs,
kono
parents:
diff changeset
29 -- and parents of subunits. All these units are loaded and pointers installed
kono
parents:
diff changeset
30 -- in the tree as described in the spec of package Lib.
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with Fname.UF; use Fname.UF;
kono
parents:
diff changeset
33 with Lib.Load; use Lib.Load;
kono
parents:
diff changeset
34 with Namet.Sp; use Namet.Sp;
kono
parents:
diff changeset
35 with Uname; use Uname;
kono
parents:
diff changeset
36 with Osint; use Osint;
kono
parents:
diff changeset
37 with Sinput.L; use Sinput.L;
kono
parents:
diff changeset
38 with Stylesw; use Stylesw;
kono
parents:
diff changeset
39 with Validsw; use Validsw;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 separate (Par)
kono
parents:
diff changeset
44 procedure Load is
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 File_Name : File_Name_Type;
kono
parents:
diff changeset
47 -- Name of file for current unit, derived from unit name
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 Cur_Unum : constant Unit_Number_Type := Current_Source_Unit;
kono
parents:
diff changeset
50 -- Unit number of unit that we just finished parsing. Note that we need
kono
parents:
diff changeset
51 -- to capture this, because Source_Unit will change as we parse new
kono
parents:
diff changeset
52 -- source files in the multiple main source file case.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 Curunit : constant Node_Id := Cunit (Cur_Unum);
kono
parents:
diff changeset
55 -- Compilation unit node for current compilation unit
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 Loc : Source_Ptr := Sloc (Curunit);
kono
parents:
diff changeset
58 -- Source location for compilation unit node
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 Save_Style_Check : Boolean;
kono
parents:
diff changeset
61 Save_Style_Checks : Style_Check_Options;
kono
parents:
diff changeset
62 -- Save style check so it can be restored later
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Save_Validity_Check : Boolean;
kono
parents:
diff changeset
65 Save_Validity_Checks : Validity_Check_Options;
kono
parents:
diff changeset
66 -- Save validity check so it can be restored later
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 With_Cunit : Node_Id;
kono
parents:
diff changeset
69 -- Compilation unit node for withed unit
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 Context_Node : Node_Id;
kono
parents:
diff changeset
72 -- Next node in context items list
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 With_Node : Node_Id;
kono
parents:
diff changeset
75 -- N_With_Clause node
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 Spec_Name : Unit_Name_Type;
kono
parents:
diff changeset
78 -- Unit name of required spec
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 Body_Name : Unit_Name_Type;
kono
parents:
diff changeset
81 -- Unit name of corresponding body
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 Unum : Unit_Number_Type;
kono
parents:
diff changeset
84 -- Unit number of loaded unit
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 Limited_With_Found : Boolean := False;
kono
parents:
diff changeset
87 -- We load the context items in two rounds: the first round handles normal
kono
parents:
diff changeset
88 -- withed units and the second round handles Ada 2005 limited-withed units.
kono
parents:
diff changeset
89 -- This is required to allow the low-level circuitry that detects circular
kono
parents:
diff changeset
90 -- dependencies of units the correct notification of errors (see comment
kono
parents:
diff changeset
91 -- bellow). This variable is used to indicate that the second round is
kono
parents:
diff changeset
92 -- required.
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 function Same_File_Name_Except_For_Case
kono
parents:
diff changeset
95 (Expected_File_Name : File_Name_Type;
kono
parents:
diff changeset
96 Actual_File_Name : File_Name_Type) return Boolean;
kono
parents:
diff changeset
97 -- Given an actual file name and an expected file name (the latter being
kono
parents:
diff changeset
98 -- derived from the unit name), determine if they are the same except for
kono
parents:
diff changeset
99 -- possibly different casing of letters.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 ------------------------------------
kono
parents:
diff changeset
102 -- Same_File_Name_Except_For_Case --
kono
parents:
diff changeset
103 ------------------------------------
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 function Same_File_Name_Except_For_Case
kono
parents:
diff changeset
106 (Expected_File_Name : File_Name_Type;
kono
parents:
diff changeset
107 Actual_File_Name : File_Name_Type) return Boolean
kono
parents:
diff changeset
108 is
kono
parents:
diff changeset
109 begin
kono
parents:
diff changeset
110 Get_Name_String (Actual_File_Name);
kono
parents:
diff changeset
111 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 declare
kono
parents:
diff changeset
114 Lower_Case_Actual_File_Name : String (1 .. Name_Len);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 begin
kono
parents:
diff changeset
117 Lower_Case_Actual_File_Name := Name_Buffer (1 .. Name_Len);
kono
parents:
diff changeset
118 Get_Name_String (Expected_File_Name);
kono
parents:
diff changeset
119 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
kono
parents:
diff changeset
120 return Lower_Case_Actual_File_Name = Name_Buffer (1 .. Name_Len);
kono
parents:
diff changeset
121 end;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 end Same_File_Name_Except_For_Case;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 -- Start of processing for Load
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 begin
kono
parents:
diff changeset
128 -- Don't do any loads if we already had a fatal error
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 if Fatal_Error (Cur_Unum) = Error_Detected then
kono
parents:
diff changeset
131 return;
kono
parents:
diff changeset
132 end if;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 Save_Style_Check_Options (Save_Style_Checks);
kono
parents:
diff changeset
135 Save_Style_Check := Opt.Style_Check;
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 Save_Validity_Check_Options (Save_Validity_Checks);
kono
parents:
diff changeset
138 Save_Validity_Check := Opt.Validity_Checks_On;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 -- If main unit, set Main_Unit_Entity (this will get overwritten if
kono
parents:
diff changeset
141 -- the main unit has a separate spec, that happens later on in Load)
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 if Cur_Unum = Main_Unit then
kono
parents:
diff changeset
144 Main_Unit_Entity := Cunit_Entity (Main_Unit);
kono
parents:
diff changeset
145 end if;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 -- If we have no unit name, things are seriously messed up by previous
kono
parents:
diff changeset
148 -- errors, and we should not try to continue compilation.
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 if Unit_Name (Cur_Unum) = No_Unit_Name then
kono
parents:
diff changeset
151 raise Unrecoverable_Error;
kono
parents:
diff changeset
152 end if;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 -- Next step, make sure that the unit name matches the file name
kono
parents:
diff changeset
155 -- and issue a warning message if not. We only output this for the
kono
parents:
diff changeset
156 -- main unit, since for other units it is more serious and is
kono
parents:
diff changeset
157 -- caught in a separate test below. We also inhibit the message in
kono
parents:
diff changeset
158 -- multiple unit per file mode, because in this case the relation
kono
parents:
diff changeset
159 -- between file name and unit name is broken.
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 File_Name :=
kono
parents:
diff changeset
162 Get_File_Name
kono
parents:
diff changeset
163 (Unit_Name (Cur_Unum),
kono
parents:
diff changeset
164 Subunit => Nkind (Unit (Cunit (Cur_Unum))) = N_Subunit);
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 if Cur_Unum = Main_Unit
kono
parents:
diff changeset
167 and then Multiple_Unit_Index = 0
kono
parents:
diff changeset
168 and then File_Name /= Unit_File_Name (Cur_Unum)
kono
parents:
diff changeset
169 and then (File_Names_Case_Sensitive
kono
parents:
diff changeset
170 or not Same_File_Name_Except_For_Case
kono
parents:
diff changeset
171 (File_Name, Unit_File_Name (Cur_Unum)))
kono
parents:
diff changeset
172 then
kono
parents:
diff changeset
173 Error_Msg_File_1 := File_Name;
kono
parents:
diff changeset
174 Error_Msg
kono
parents:
diff changeset
175 ("??file name does not match unit name, should be{", Sloc (Curunit));
kono
parents:
diff changeset
176 end if;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 -- For units other than the main unit, the expected unit name is set and
kono
parents:
diff changeset
179 -- must be the same as the actual unit name, or we are in big trouble, and
kono
parents:
diff changeset
180 -- abandon the compilation since there are situations where this really
kono
parents:
diff changeset
181 -- gets us into bad trouble (e.g. some subunit situations).
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 if Cur_Unum /= Main_Unit
kono
parents:
diff changeset
184 and then Expected_Unit (Cur_Unum) /= Unit_Name (Cur_Unum)
kono
parents:
diff changeset
185 then
kono
parents:
diff changeset
186 Loc := Error_Location (Cur_Unum);
kono
parents:
diff changeset
187 Error_Msg_File_1 := Unit_File_Name (Cur_Unum);
kono
parents:
diff changeset
188 Get_Name_String (Error_Msg_File_1);
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -- Check for predefined file case
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 if Name_Len > 1
kono
parents:
diff changeset
193 and then Name_Buffer (2) = '-'
kono
parents:
diff changeset
194 and then (Name_Buffer (1) = 'a'
kono
parents:
diff changeset
195 or else
kono
parents:
diff changeset
196 Name_Buffer (1) = 's'
kono
parents:
diff changeset
197 or else
kono
parents:
diff changeset
198 Name_Buffer (1) = 'i'
kono
parents:
diff changeset
199 or else
kono
parents:
diff changeset
200 Name_Buffer (1) = 'g')
kono
parents:
diff changeset
201 then
kono
parents:
diff changeset
202 declare
kono
parents:
diff changeset
203 Expect_Name : constant Unit_Name_Type := Expected_Unit (Cur_Unum);
kono
parents:
diff changeset
204 Actual_Name : constant Unit_Name_Type := Unit_Name (Cur_Unum);
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 begin
kono
parents:
diff changeset
207 Error_Msg_Unit_1 := Expect_Name;
kono
parents:
diff changeset
208 Error_Msg -- CODEFIX
kono
parents:
diff changeset
209 ("$$ is not a predefined library unit!", Loc);
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 -- In the predefined file case, we know the user did not
kono
parents:
diff changeset
212 -- construct their own package, but we got the wrong one.
kono
parents:
diff changeset
213 -- This means that the name supplied by the user crunched
kono
parents:
diff changeset
214 -- to something we recognized, but then the file did not
kono
parents:
diff changeset
215 -- contain the unit expected. Most likely this is due to
kono
parents:
diff changeset
216 -- a misspelling, e.g.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 -- with Ada.Calender;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 -- This crunches to a-calend, which indeed contains the unit
kono
parents:
diff changeset
221 -- Ada.Calendar, and we can diagnose the misspelling. This
kono
parents:
diff changeset
222 -- is a simple heuristic, but it catches many common cases
kono
parents:
diff changeset
223 -- of misspelling of predefined unit names without needing
kono
parents:
diff changeset
224 -- a full list of them.
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 -- Before actually issuing the message, we will check that the
kono
parents:
diff changeset
227 -- unit name is indeed a plausible misspelling of the one we got.
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if Is_Bad_Spelling_Of
kono
parents:
diff changeset
230 (Name_Id (Expect_Name), Name_Id (Actual_Name))
kono
parents:
diff changeset
231 then
kono
parents:
diff changeset
232 Error_Msg_Unit_1 := Actual_Name;
kono
parents:
diff changeset
233 Error_Msg -- CODEFIX
kono
parents:
diff changeset
234 ("possible misspelling of $$!", Loc);
kono
parents:
diff changeset
235 end if;
kono
parents:
diff changeset
236 end;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Non-predefined file name case. In this case we generate a message
kono
parents:
diff changeset
239 -- and then we quit, because we are in big trouble, and if we try
kono
parents:
diff changeset
240 -- to continue compilation, we get into some nasty situations
kono
parents:
diff changeset
241 -- (for example in some subunit cases).
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 else
kono
parents:
diff changeset
244 Error_Msg ("file { does not contain expected unit!", Loc);
kono
parents:
diff changeset
245 Error_Msg_Unit_1 := Expected_Unit (Cur_Unum);
kono
parents:
diff changeset
246 Error_Msg ("\\expected unit $!", Loc);
kono
parents:
diff changeset
247 Error_Msg_Unit_1 := Unit_Name (Cur_Unum);
kono
parents:
diff changeset
248 Error_Msg ("\\found unit $!", Loc);
kono
parents:
diff changeset
249 end if;
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 -- In both cases, remove the unit if it is the last unit (which it
kono
parents:
diff changeset
252 -- normally (always?) will be) so that it is out of the way later.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 Remove_Unit (Cur_Unum);
kono
parents:
diff changeset
255 end if;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 -- If current unit is a body, load its corresponding spec
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 if Nkind (Unit (Curunit)) = N_Package_Body
kono
parents:
diff changeset
260 or else Nkind (Unit (Curunit)) = N_Subprogram_Body
kono
parents:
diff changeset
261 then
kono
parents:
diff changeset
262 Spec_Name := Get_Spec_Name (Unit_Name (Cur_Unum));
kono
parents:
diff changeset
263 Unum :=
kono
parents:
diff changeset
264 Load_Unit
kono
parents:
diff changeset
265 (Load_Name => Spec_Name,
kono
parents:
diff changeset
266 Required => False,
kono
parents:
diff changeset
267 Subunit => False,
kono
parents:
diff changeset
268 Error_Node => Curunit,
kono
parents:
diff changeset
269 Corr_Body => Cur_Unum,
kono
parents:
diff changeset
270 PMES => (Cur_Unum = Main_Unit));
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 -- If we successfully load the unit, then set the spec/body pointers.
kono
parents:
diff changeset
273 -- Once again note that if the loaded unit has a fatal error, Load will
kono
parents:
diff changeset
274 -- have set our Fatal_Error flag to propagate this condition.
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 if Unum /= No_Unit then
kono
parents:
diff changeset
277 Set_Library_Unit (Curunit, Cunit (Unum));
kono
parents:
diff changeset
278 Set_Library_Unit (Cunit (Unum), Curunit);
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 -- If this is a separate spec for the main unit, then we reset
kono
parents:
diff changeset
281 -- Main_Unit_Entity to point to the entity for this separate spec
kono
parents:
diff changeset
282 -- and this is also where we generate the SCO's for this spec.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 if Cur_Unum = Main_Unit then
kono
parents:
diff changeset
285 Main_Unit_Entity := Cunit_Entity (Unum);
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 if Generate_SCO then
kono
parents:
diff changeset
288 SCO_Record_Raw (Unum);
kono
parents:
diff changeset
289 end if;
kono
parents:
diff changeset
290 end if;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 -- If we don't find the spec, then if we have a subprogram body, we
kono
parents:
diff changeset
293 -- are still OK, we just have a case of a body acting as its own spec
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 elsif Nkind (Unit (Curunit)) = N_Subprogram_Body then
kono
parents:
diff changeset
296 Set_Acts_As_Spec (Curunit, True);
kono
parents:
diff changeset
297 Set_Library_Unit (Curunit, Curunit);
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 -- Otherwise we do have an error, repeat the load request for the spec
kono
parents:
diff changeset
300 -- with Required set True to generate an appropriate error message.
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 else
kono
parents:
diff changeset
303 Unum :=
kono
parents:
diff changeset
304 Load_Unit
kono
parents:
diff changeset
305 (Load_Name => Spec_Name,
kono
parents:
diff changeset
306 Required => True,
kono
parents:
diff changeset
307 Subunit => False,
kono
parents:
diff changeset
308 Error_Node => Curunit);
kono
parents:
diff changeset
309 return;
kono
parents:
diff changeset
310 end if;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 -- If current unit is a child unit spec, load its parent. If the child unit
kono
parents:
diff changeset
313 -- is loaded through a limited with, the parent must be as well.
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 elsif Nkind (Unit (Curunit)) = N_Package_Declaration
kono
parents:
diff changeset
316 or else Nkind (Unit (Curunit)) = N_Subprogram_Declaration
kono
parents:
diff changeset
317 or else Nkind (Unit (Curunit)) in N_Generic_Declaration
kono
parents:
diff changeset
318 or else Nkind (Unit (Curunit)) in N_Generic_Instantiation
kono
parents:
diff changeset
319 or else Nkind (Unit (Curunit)) in N_Renaming_Declaration
kono
parents:
diff changeset
320 then
kono
parents:
diff changeset
321 -- Turn style and validity checks off for parent unit
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 if not GNAT_Mode then
kono
parents:
diff changeset
324 Reset_Style_Check_Options;
kono
parents:
diff changeset
325 Reset_Validity_Check_Options;
kono
parents:
diff changeset
326 end if;
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 Spec_Name := Get_Parent_Spec_Name (Unit_Name (Cur_Unum));
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 if Spec_Name /= No_Unit_Name then
kono
parents:
diff changeset
331 Unum :=
kono
parents:
diff changeset
332 Load_Unit
kono
parents:
diff changeset
333 (Load_Name => Spec_Name,
kono
parents:
diff changeset
334 Required => True,
kono
parents:
diff changeset
335 Subunit => False,
kono
parents:
diff changeset
336 Error_Node => Curunit);
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 if Unum /= No_Unit then
kono
parents:
diff changeset
339 Set_Parent_Spec (Unit (Curunit), Cunit (Unum));
kono
parents:
diff changeset
340 end if;
kono
parents:
diff changeset
341 end if;
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 -- If current unit is a subunit, then load its parent body
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 elsif Nkind (Unit (Curunit)) = N_Subunit then
kono
parents:
diff changeset
346 Body_Name := Get_Parent_Body_Name (Unit_Name (Cur_Unum));
kono
parents:
diff changeset
347 Unum :=
kono
parents:
diff changeset
348 Load_Unit
kono
parents:
diff changeset
349 (Load_Name => Body_Name,
kono
parents:
diff changeset
350 Required => True,
kono
parents:
diff changeset
351 Subunit => False,
kono
parents:
diff changeset
352 Error_Node => Name (Unit (Curunit)));
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 if Unum /= No_Unit then
kono
parents:
diff changeset
355 Set_Library_Unit (Curunit, Cunit (Unum));
kono
parents:
diff changeset
356 end if;
kono
parents:
diff changeset
357 end if;
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 -- Now we load with'ed units, with style/validity checks turned off
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 if not GNAT_Mode then
kono
parents:
diff changeset
362 Reset_Style_Check_Options;
kono
parents:
diff changeset
363 Reset_Validity_Check_Options;
kono
parents:
diff changeset
364 end if;
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 -- Load the context items in two rounds: the first round handles normal
kono
parents:
diff changeset
367 -- withed units and the second round handles Ada 2005 limited-withed units.
kono
parents:
diff changeset
368 -- This is required to allow the low-level circuitry that detects circular
kono
parents:
diff changeset
369 -- dependencies of units the correct notification of the following error:
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 -- limited with D;
kono
parents:
diff changeset
372 -- with D; with C;
kono
parents:
diff changeset
373 -- package C is ... package D is ...
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 for Round in 1 .. 2 loop
kono
parents:
diff changeset
376 Context_Node := First (Context_Items (Curunit));
kono
parents:
diff changeset
377 while Present (Context_Node) loop
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 -- During the first round we check if there is some limited-with
kono
parents:
diff changeset
380 -- context clause; otherwise the second round will be skipped
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 if Nkind (Context_Node) = N_With_Clause
kono
parents:
diff changeset
383 and then Round = 1
kono
parents:
diff changeset
384 and then Limited_Present (Context_Node)
kono
parents:
diff changeset
385 then
kono
parents:
diff changeset
386 Limited_With_Found := True;
kono
parents:
diff changeset
387 end if;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 if Nkind (Context_Node) = N_With_Clause
kono
parents:
diff changeset
390 and then ((Round = 1 and then not Limited_Present (Context_Node))
kono
parents:
diff changeset
391 or else
kono
parents:
diff changeset
392 (Round = 2 and then Limited_Present (Context_Node)))
kono
parents:
diff changeset
393 then
kono
parents:
diff changeset
394 With_Node := Context_Node;
kono
parents:
diff changeset
395 Spec_Name := Get_Unit_Name (With_Node);
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 Unum :=
kono
parents:
diff changeset
398 Load_Unit
kono
parents:
diff changeset
399 (Load_Name => Spec_Name,
kono
parents:
diff changeset
400 Required => False,
kono
parents:
diff changeset
401 Subunit => False,
kono
parents:
diff changeset
402 Error_Node => With_Node,
kono
parents:
diff changeset
403 Renamings => True,
kono
parents:
diff changeset
404 With_Node => Context_Node);
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 -- If we find the unit, then set spec pointer in the N_With_Clause
kono
parents:
diff changeset
407 -- to point to the compilation unit for the spec. Remember that
kono
parents:
diff changeset
408 -- the Load routine itself sets our Fatal_Error flag if the loaded
kono
parents:
diff changeset
409 -- unit gets a fatal error, so we don't need to worry about that.
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 if Unum /= No_Unit then
kono
parents:
diff changeset
412 Set_Library_Unit (With_Node, Cunit (Unum));
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 -- If the spec isn't found, then try finding the corresponding
kono
parents:
diff changeset
415 -- body, since it is possible that we have a subprogram body
kono
parents:
diff changeset
416 -- that is acting as a spec (since no spec is present).
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 else
kono
parents:
diff changeset
419 Body_Name := Get_Body_Name (Spec_Name);
kono
parents:
diff changeset
420 Unum :=
kono
parents:
diff changeset
421 Load_Unit
kono
parents:
diff changeset
422 (Load_Name => Body_Name,
kono
parents:
diff changeset
423 Required => False,
kono
parents:
diff changeset
424 Subunit => False,
kono
parents:
diff changeset
425 Error_Node => With_Node,
kono
parents:
diff changeset
426 Renamings => True);
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 -- If we got a subprogram body, then mark that we are using
kono
parents:
diff changeset
429 -- the body as a spec in the file table, and set the spec
kono
parents:
diff changeset
430 -- pointer in the N_With_Clause to point to the body entity.
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 if Unum /= No_Unit
kono
parents:
diff changeset
433 and then Nkind (Unit (Cunit (Unum))) = N_Subprogram_Body
kono
parents:
diff changeset
434 then
kono
parents:
diff changeset
435 With_Cunit := Cunit (Unum);
kono
parents:
diff changeset
436 Set_Library_Unit (With_Node, With_Cunit);
kono
parents:
diff changeset
437 Set_Acts_As_Spec (With_Cunit, True);
kono
parents:
diff changeset
438 Set_Library_Unit (With_Cunit, With_Cunit);
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 -- If we couldn't find the body, or if it wasn't a body spec
kono
parents:
diff changeset
441 -- then we are in trouble. We make one more call to Load to
kono
parents:
diff changeset
442 -- require the spec. We know it will fail of course, the
kono
parents:
diff changeset
443 -- purpose is to generate the required error message (we prefer
kono
parents:
diff changeset
444 -- that this message refer to the missing spec, not the body)
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 else
kono
parents:
diff changeset
447 Unum :=
kono
parents:
diff changeset
448 Load_Unit
kono
parents:
diff changeset
449 (Load_Name => Spec_Name,
kono
parents:
diff changeset
450 Required => True,
kono
parents:
diff changeset
451 Subunit => False,
kono
parents:
diff changeset
452 Error_Node => With_Node,
kono
parents:
diff changeset
453 Renamings => True);
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 -- Here we create a dummy package unit for the missing unit
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 Unum := Create_Dummy_Package_Unit (With_Node, Spec_Name);
kono
parents:
diff changeset
458 Set_Library_Unit (With_Node, Cunit (Unum));
kono
parents:
diff changeset
459 end if;
kono
parents:
diff changeset
460 end if;
kono
parents:
diff changeset
461 end if;
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 Next (Context_Node);
kono
parents:
diff changeset
464 end loop;
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 exit when not Limited_With_Found;
kono
parents:
diff changeset
467 end loop;
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 -- Restore style/validity check mode for main unit
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 Set_Style_Check_Options (Save_Style_Checks);
kono
parents:
diff changeset
472 Opt.Style_Check := Save_Style_Check;
kono
parents:
diff changeset
473 Set_Validity_Check_Options (Save_Validity_Checks);
kono
parents:
diff changeset
474 Opt.Validity_Checks_On := Save_Validity_Check;
kono
parents:
diff changeset
475 end Load;