]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/frontend.adb
c++: Handle multiple aggregate overloads [PR95319].
[thirdparty/gcc.git] / gcc / ada / frontend.adb
CommitLineData
70482933
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- F R O N T E N D --
6-- --
7-- B o d y --
8-- --
1d005acc 9-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
70482933
RK
10-- --
11-- GNAT is free software; you can redistribute it and/or modify it under --
12-- terms of the GNU General Public License as published by the Free Soft- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
70482933
RK
14-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17-- for more details. You should have received a copy of the GNU General --
b5c84c3c
RD
18-- Public License distributed with GNAT; see file COPYING3. If not, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license. --
70482933
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
70482933
RK
23-- --
24------------------------------------------------------------------------------
25
804f7040 26with System.Strings; use System.Strings;
fbf5a39b 27
70482933
RK
28with Atree; use Atree;
29with Checks;
30with CStand;
31with Debug; use Debug;
32with Elists;
70482933 33with Exp_Dbug;
29a56f61 34with Exp_Unst;
6510f4c9 35with Fmap;
70482933 36with Fname.UF;
8636f52f 37with Ghost; use Ghost;
70482933
RK
38with Inline; use Inline;
39with Lib; use Lib;
40with Lib.Load; use Lib.Load;
851e9f19 41with Lib.Xref;
70482933
RK
42with Live; use Live;
43with Namet; use Namet;
44with Nlists; use Nlists;
45with Opt; use Opt;
46with Osint;
70482933 47with Par;
4e0079cc 48with Prep;
fbf5a39b 49with Prepcomp;
1f6821b4
AC
50with Restrict; use Restrict;
51with Rident; use Rident;
851e9f19 52with Rtsfind;
82878151 53with Snames; use Snames;
70482933
RK
54with Sprint;
55with Scn; use Scn;
56with Sem; use Sem;
21d27997 57with Sem_Aux;
851e9f19 58with Sem_Ch8;
d06b3b1d 59with Sem_SCIL;
70482933
RK
60with Sem_Elab; use Sem_Elab;
61with Sem_Prag; use Sem_Prag;
851e9f19 62with Sem_Warn;
70482933
RK
63with Sinfo; use Sinfo;
64with Sinput; use Sinput;
65with Sinput.L; use Sinput.L;
851e9f19 66with SCIL_LL;
fbf5a39b 67with Tbuild; use Tbuild;
70482933
RK
68with Types; use Types;
69
70procedure Frontend is
70482933 71begin
1f6821b4
AC
72 -- Carry out package initializations. These are initializations which might
73 -- logically be performed at elaboration time, were it not for the fact
74 -- that we may be doing things more than once in the big loop over files.
75 -- Like elaboration, the order in which these calls are made is in some
c3b36d48 76 -- cases important. For example, Lib cannot be initialized before Namet,
1f6821b4 77 -- since it uses names table entries.
70482933
RK
78
79 Rtsfind.Initialize;
70482933
RK
80 Nlists.Initialize;
81 Elists.Initialize;
82 Lib.Load.Initialize;
21d27997 83 Sem_Aux.Initialize;
70482933 84 Sem_Ch8.Initialize;
21d27997 85 Sem_Prag.Initialize;
70482933 86 Fname.UF.Initialize;
70482933 87 Checks.Initialize;
1b24ada5 88 Sem_Warn.Initialize;
4e0079cc 89 Prep.Initialize;
90e491a7 90 Sem_Elab.Initialize;
70482933 91
7665e4bd
AC
92 if Generate_SCIL then
93 SCIL_LL.Initialize;
94 end if;
95
70482933
RK
96 -- Create package Standard
97
98 CStand.Create_Standard;
99
fbf5a39b 100 -- Check possible symbol definitions specified by -gnateD switches
70482933 101
fbf5a39b 102 Prepcomp.Process_Command_Line_Symbol_Definitions;
70482933 103
fbf5a39b 104 -- If -gnatep= was specified, parse the preprocessing data file
70482933 105
fbf5a39b
AC
106 if Preprocessing_Data_File /= null then
107 Name_Len := Preprocessing_Data_File'Length;
108 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
109 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
70482933 110
fbf5a39b
AC
111 -- Otherwise, check if there were preprocessing symbols on the command
112 -- line and set preprocessing if there are.
70482933 113
fbf5a39b
AC
114 else
115 Prepcomp.Check_Symbols;
116 end if;
70482933 117
ea4ce0f7
VC
118 -- We set Parsing_Main_Extended_Source true here to cover processing of all
119 -- the configuration pragma files, as well as the main source unit itself.
120
121 Parsing_Main_Extended_Source := True;
122
fbf5a39b 123 -- Now that the preprocessing situation is established, we are able to
e14c931f 124 -- load the main source (this is no longer done by Lib.Load.Initialize).
70482933 125
fbf5a39b 126 Lib.Load.Load_Main_Source;
70482933 127
e1d9659d 128 -- Return immediately if the main source could not be found
804f7040 129
cd644ae2 130 if Sinput.Main_Source_File <= No_Source_File then
804f7040
VC
131 return;
132 end if;
133
fbf5a39b 134 -- Read and process configuration pragma files if present
70482933 135
fbf5a39b 136 declare
9caf55e3 137 Dot_Gnat_Adc : constant File_Name_Type := Name_Find ("./gnat.adc");
7ec25b2b 138 Gnat_Adc : constant File_Name_Type := Name_Find ("gnat.adc");
9caf55e3 139
fbf5a39b
AC
140 Save_Style_Check : constant Boolean := Opt.Style_Check;
141 -- Save style check mode so it can be restored later
70482933 142
7ec25b2b
AC
143 Config_Pragmas : List_Id := Empty_List;
144 -- Gather configuration pragmas
145
fbf5a39b
AC
146 Source_Config_File : Source_File_Index;
147 -- Source reference for -gnatec configuration file
70482933 148
fbf5a39b 149 Prag : Node_Id;
70482933 150
fbf5a39b 151 begin
9d2a2071
AC
152 -- We always analyze config files with style checks off, since we
153 -- don't want a miscellaneous gnat.adc that is around to discombobulate
154 -- intended -gnatg or -gnaty compilations. We also disconnect checking
155 -- for maximum line length.
70482933 156
fbf5a39b
AC
157 Opt.Style_Check := False;
158 Style_Check := False;
70482933 159
fbf5a39b 160 -- Capture current suppress options, which may get modified
70482933 161
fbf5a39b 162 Scope_Suppress := Opt.Suppress_Options;
70482933 163
fbf5a39b
AC
164 -- First deal with gnat.adc file
165
166 if Opt.Config_File then
9caf55e3 167 Source_gnat_adc := Load_Config_File (Gnat_Adc);
fbf5a39b 168
fc27e20e
RD
169 -- Case of gnat.adc file present
170
cd644ae2 171 if Source_gnat_adc > No_Source_File then
7f5e671b 172
fc27e20e
RD
173 -- Parse the gnat.adc file for configuration pragmas
174
fbf5a39b
AC
175 Initialize_Scanner (No_Unit, Source_gnat_adc);
176 Config_Pragmas := Par (Configuration_Pragmas => True);
fc27e20e 177
9caf55e3
BD
178 -- We add a compilation dependency for gnat.adc so that if it
179 -- changes, we force a recompilation.
fc27e20e 180
5ae24312 181 Prepcomp.Add_Dependency (Source_gnat_adc);
fbf5a39b 182 end if;
fbf5a39b 183 end if;
70482933 184
fbf5a39b 185 -- Now deal with specified config pragmas files if there are any
70482933 186
fbf5a39b 187 if Opt.Config_File_Names /= null then
fc27e20e
RD
188
189 -- Loop through config pragmas files
190
fbf5a39b 191 for Index in Opt.Config_File_Names'Range loop
9caf55e3
BD
192 declare
193 Len : constant Natural := Config_File_Names (Index)'Length;
194 Str : constant String (1 .. Len) :=
7ec25b2b
AC
195 Config_File_Names (Index).all;
196
9caf55e3 197 Config_Name : constant File_Name_Type := Name_Find (Str);
7ec25b2b
AC
198 Temp_File : constant Boolean :=
199 Len > 4
200 and then
201 (Str (Len - 3 .. Len) = ".TMP"
202 or else
203 Str (Len - 3 .. Len) = ".tmp");
9caf55e3 204 -- Extension indicating a temporary config file?
fccaf220 205
9caf55e3
BD
206 begin
207 -- Skip it if it's the default name, already loaded above.
7ec25b2b
AC
208 -- Otherwise, we get confusing warning messages about seeing
209 -- the same thing twice.
5ae24312 210
9caf55e3
BD
211 if Config_Name /= Gnat_Adc
212 and then Config_Name /= Dot_Gnat_Adc
213 then
214 -- Load the file, error if we did not find it
70482933 215
9caf55e3 216 Source_Config_File := Load_Config_File (Config_Name);
5ae24312 217
cd644ae2 218 if Source_Config_File <= No_Source_File then
9caf55e3
BD
219 Osint.Fail
220 ("cannot find configuration pragmas file "
221 & Config_File_Names (Index).all);
fc27e20e 222
9caf55e3
BD
223 -- If we did find the file, and it is not a temporary file,
224 -- then we add a compilation dependency for it so that if it
225 -- changes, we force a recompilation.
70482933 226
9caf55e3
BD
227 elsif not Temp_File then
228 Prepcomp.Add_Dependency (Source_Config_File);
229 end if;
fccaf220 230
9caf55e3
BD
231 -- Parse the config pragmas file, and accumulate results
232
233 Initialize_Scanner (No_Unit, Source_Config_File);
234 Append_List_To
235 (Config_Pragmas, Par (Configuration_Pragmas => True));
236 end if;
237 end;
fbf5a39b
AC
238 end loop;
239 end if;
70482933 240
fbf5a39b
AC
241 -- Now analyze all pragmas except those whose analysis must be
242 -- deferred till after the main unit is analyzed.
70482933 243
fbf5a39b
AC
244 if Config_Pragmas /= Error_List
245 and then Operating_Mode /= Check_Syntax
246 then
247 Prag := First (Config_Pragmas);
248 while Present (Prag) loop
249 if not Delay_Config_Pragma_Analyze (Prag) then
70482933 250 Analyze_Pragma (Prag);
fbf5a39b 251 end if;
70482933 252
fbf5a39b
AC
253 Next (Prag);
254 end loop;
255 end if;
70482933 256
a90bd866 257 -- Restore style check, but if config file turned on checks, leave on
70482933 258
fbf5a39b 259 Opt.Style_Check := Save_Style_Check or Style_Check;
70482933 260
fbf5a39b 261 -- Capture any modifications to suppress options from config pragmas
70482933 262
fbf5a39b 263 Opt.Suppress_Options := Scope_Suppress;
094cf333 264
9caf55e3
BD
265 -- If a target dependency info file has been read through switch
266 -- -gnateT=, add it to the dependencies.
267
268 if Target_Dependent_Info_Read_Name /= null then
269 declare
270 Index : Source_File_Index;
271 begin
272 Name_Len := 0;
273 Add_Str_To_Name_Buffer (Target_Dependent_Info_Read_Name.all);
274 Index := Load_Config_File (Name_Enter);
275 Prepcomp.Add_Dependency (Index);
276 end;
277 end if;
51fb9b73 278
9caf55e3
BD
279 -- This is where we can capture the value of the compilation unit
280 -- specific restrictions that have been set by the config pragma
281 -- files (or from Targparm), for later restoration when processing
282 -- e.g. subunits.
51fb9b73 283
9caf55e3 284 Save_Config_Cunit_Boolean_Restrictions;
6510f4c9 285
9caf55e3
BD
286 -- If there was a -gnatem switch, initialize the mappings of unit names
287 -- to file names and of file names to path names from the mapping file.
6510f4c9 288
9caf55e3
BD
289 if Mapping_File_Name /= null then
290 Fmap.Initialize (Mapping_File_Name.all);
291 end if;
1b24ada5 292
9caf55e3 293 -- Adjust Optimize_Alignment mode from debug switches if necessary
1b24ada5 294
9caf55e3
BD
295 if Debug_Flag_Dot_SS then
296 Optimize_Alignment := 'S';
297 elsif Debug_Flag_Dot_TT then
298 Optimize_Alignment := 'T';
299 end if;
70482933 300
9caf55e3
BD
301 -- We have now processed the command line switches, and the
302 -- configuration pragma files, so this is the point at which we want to
303 -- capture the values of the configuration switches (see Opt for further
304 -- details).
70482933 305
9cc97ad5 306 Register_Config_Switches;
804f7040 307
9caf55e3 308 -- Check for file which contains No_Body pragma
804f7040 309
9caf55e3
BD
310 if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
311 Change_Main_Unit_To_Spec;
312 end if;
70482933 313
9caf55e3
BD
314 -- Initialize the scanner. Note that we do this after the call to
315 -- Create_Standard, which uses the scanner in its processing of
316 -- floating-point bounds.
70482933 317
9caf55e3 318 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
70482933 319
9caf55e3
BD
320 -- Here we call the parser to parse the compilation unit (or units in
321 -- the check syntax mode, but in that case we won't go on to the
322 -- semantics in any case).
70482933 323
9caf55e3
BD
324 Discard_List (Par (Configuration_Pragmas => False));
325 Parsing_Main_Extended_Source := False;
70482933 326
9caf55e3
BD
327 -- The main unit is now loaded, and subunits of it can be loaded,
328 -- without reporting spurious loading circularities.
70482933 329
9caf55e3 330 Set_Loading (Main_Unit, False);
a39a553e 331
9caf55e3
BD
332 -- Now that the main unit is installed, we can complete the analysis
333 -- of the pragmas in gnat.adc and the configuration file, that require
334 -- a context for their semantic processing.
a39a553e 335
9caf55e3
BD
336 if Config_Pragmas /= Error_List
337 and then Operating_Mode /= Check_Syntax
70482933 338
9caf55e3
BD
339 -- Do not attempt to process deferred configuration pragmas if the
340 -- main unit failed to load, to avoid cascaded inconsistencies that
341 -- can lead to a compiler crash.
70482933 342
9caf55e3
BD
343 and then Fatal_Error (Main_Unit) /= Error_Detected
344 then
345 -- Pragmas that require some semantic activity, such as
346 -- Interrupt_State, cannot be processed until the main unit is
347 -- installed, because they require a compilation unit on which to
348 -- attach with_clauses, etc. So analyze them now.
349
350 declare
351 Prag : Node_Id;
352
353 begin
354 Prag := First (Config_Pragmas);
355 while Present (Prag) loop
356
357 -- Guard against the case where a configuration pragma may be
358 -- split into multiple pragmas and the original rewritten as a
359 -- null statement.
360
361 if Nkind (Prag) = N_Pragma
362 and then Delay_Config_Pragma_Analyze (Prag)
363 then
364 Analyze_Pragma (Prag);
365 end if;
366
367 Next (Prag);
368 end loop;
369 end;
370 end if;
de4ac038 371
9caf55e3
BD
372 -- If we have restriction No_Exception_Propagation, and we did not have
373 -- an explicit switch turning off Warn_On_Non_Local_Exception, then turn
374 -- on this warning by default if we have encountered an exception
375 -- handler.
de4ac038 376
9caf55e3
BD
377 if Restriction_Check_Required (No_Exception_Propagation)
378 and then not No_Warn_On_Non_Local_Exception
379 and then Exception_Handler_Encountered
380 then
381 Warn_On_Non_Local_Exception := True;
382 end if;
70482933 383
9caf55e3 384 -- Now on to the semantics. Skip if in syntax only mode
70482933 385
9caf55e3 386 if Operating_Mode /= Check_Syntax then
1f6821b4 387
9caf55e3 388 -- Install the configuration pragmas in the tree
1f6821b4 389
9caf55e3
BD
390 Set_Config_Pragmas
391 (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
70482933 392
9caf55e3 393 -- Following steps are skipped if we had a fatal error during parsing
70482933 394
9caf55e3 395 if Fatal_Error (Main_Unit) /= Error_Detected then
fbf5a39b 396
9caf55e3
BD
397 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
398 -- actually generate code for subunits, so we suppress expansion.
399 -- This also corrects certain problems that occur if we try to
400 -- incorporate subunits at a lower level.
fbf5a39b 401
9caf55e3
BD
402 if Operating_Mode = Generate_Code
403 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
404 then
405 Operating_Mode := Check_Semantics;
406 end if;
fbf5a39b 407
9caf55e3 408 -- Analyze (and possibly expand) main unit
70482933 409
9caf55e3
BD
410 Scope_Suppress := Suppress_Options;
411 Semantics (Cunit (Main_Unit));
fbf5a39b 412
9caf55e3 413 -- Cleanup processing after completing main analysis
70482933 414
9caf55e3 415 -- Comment needed for ASIS mode test and GNATprove mode test???
fbf5a39b 416
9caf55e3
BD
417 pragma Assert
418 (Operating_Mode = Generate_Code
419 or else Operating_Mode = Check_Semantics);
fbf5a39b 420
9caf55e3
BD
421 if Operating_Mode = Generate_Code
422 or else (ASIS_Mode or GNATprove_Mode)
423 then
424 Instantiate_Bodies;
425 end if;
70482933 426
90e491a7
PMR
427 -- Analyze all inlined bodies, check access-before-elaboration
428 -- rules, and remove ignored Ghost code when generating code or
429 -- compiling for GNATprove.
4a28b181 430
9caf55e3
BD
431 if Operating_Mode = Generate_Code or else GNATprove_Mode then
432 if Inline_Processing_Required then
433 Analyze_Inlined_Bodies;
434 end if;
e49de265 435
9caf55e3
BD
436 -- Remove entities from program that do not have any execution
437 -- time references.
70482933 438
9caf55e3
BD
439 if Debug_Flag_UU then
440 Collect_Garbage_Entities;
441 end if;
54740d7d 442
967947ed
PMR
443 if Legacy_Elaboration_Checks then
444 Check_Elab_Calls;
445 end if;
446
90e491a7 447 -- Examine all top level scenarios collected during analysis
967947ed
PMR
448 -- and resolution. Diagnose conditional ABEs, install run-time
449 -- checks to catch conditional ABEs, and guarantee the prior
450 -- elaboration of external units.
90e491a7
PMR
451
452 Check_Elaboration_Scenarios;
70482933 453
967947ed
PMR
454 -- Examine all top level scenarios collected during analysis and
455 -- resolution in order to diagnose conditional ABEs, even in the
456 -- presence of serious errors.
90e491a7
PMR
457
458 else
459 Check_Elaboration_Scenarios;
fbf5a39b 460 end if;
70482933 461
9caf55e3 462 -- At this stage we can unnest subprogram bodies if required
8636f52f 463
4af4c79a
AC
464 if Total_Errors_Detected = 0 then
465 Exp_Unst.Unnest_Subprograms (Cunit (Main_Unit));
466 end if;
70482933 467
9caf55e3 468 -- List library units if requested
f8dae9bb 469
9caf55e3
BD
470 if List_Units then
471 Lib.List;
472 end if;
f8dae9bb 473
9caf55e3 474 -- Output waiting warning messages
70482933 475
9caf55e3
BD
476 Lib.Xref.Process_Deferred_References;
477 Sem_Warn.Output_Non_Modified_In_Out_Warnings;
478 Sem_Warn.Output_Unreferenced_Messages;
479 Sem_Warn.Check_Unused_Withs;
480 Sem_Warn.Output_Unused_Warnings_Off_Warnings;
7ffb58af
HK
481
482 -- Remove any ignored Ghost code as it must not appear in the
483 -- executable. This action must be performed last because it
484 -- heavily alters the tree.
485
486 if Operating_Mode = Generate_Code or else GNATprove_Mode then
487 Remove_Ignored_Ghost_Code;
488 end if;
fbf5a39b 489 end if;
fbf5a39b 490 end if;
9caf55e3 491 end;
70482933 492
e4d04166 493 -- Qualify all entity names in inner packages, package bodies, etc
70482933 494
d05586dc
YM
495 if not GNATprove_Mode then
496 Exp_Dbug.Qualify_All_Entity_Names;
497 end if;
70482933 498
327503f1
JM
499 -- SCIL backend requirement. Check that SCIL nodes associated with
500 -- dispatching calls reference subprogram calls.
501
502 if Generate_SCIL then
d06b3b1d 503 pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
e657b693 504 null;
327503f1
JM
505 end if;
506
70482933
RK
507 -- Dump the source now. Note that we do this as soon as the analysis
508 -- of the tree is complete, because it is not just a dump in the case
509 -- of -gnatD, where it rewrites all source locations in the tree.
510
511 Sprint.Source_Dump;
07fc65c4 512
ed05b790
RD
513 -- Check again for configuration pragmas that appear in the context
514 -- of the main unit. These pragmas only affect the main unit, and the
82878151
AC
515 -- corresponding flag is reset after each call to Semantics, but they
516 -- may affect the generated ali for the unit, and therefore the flag
517 -- must be set properly after compilation. Currently we only check for
518 -- Initialize_Scalars, but others should be checked: as well???
519
520 declare
521 Item : Node_Id;
522
523 begin
524 Item := First (Context_Items (Cunit (Main_Unit)));
525 while Present (Item) loop
526 if Nkind (Item) = N_Pragma
6e759c2a 527 and then Pragma_Name (Item) = Name_Initialize_Scalars
82878151
AC
528 then
529 Initialize_Scalars := True;
530 end if;
43ccd04b 531
82878151
AC
532 Next (Item);
533 end loop;
534 end;
535
fbf5a39b 536 -- If a mapping file has been specified by a -gnatem switch, update
e14c931f 537 -- it if there has been some sources that were not in the mappings.
07fc65c4
GB
538
539 if Mapping_File_Name /= null then
540 Fmap.Update_Mapping_File (Mapping_File_Name.all);
541 end if;
542
fbf5a39b 543 return;
70482933 544end Frontend;