Daily bump.
[official-gcc.git] / gcc / ada / frontend.adb
blob7c56ac9789f0a950fd9fbce4097262cd37391abd
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R O N T E N D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
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- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with System.Strings; use System.Strings;
28 with Atree; use Atree;
29 with Checks;
30 with CStand;
31 with Debug; use Debug;
32 with Elists;
33 with Exp_Dbug;
34 with Fmap;
35 with Fname.UF;
36 with Inline; use Inline;
37 with Lib; use Lib;
38 with Lib.Load; use Lib.Load;
39 with Live; use Live;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Opt; use Opt;
43 with Osint;
44 with Par;
45 with Prep;
46 with Prepcomp;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Snames; use Snames;
51 with Sprint;
52 with Scn; use Scn;
53 with Sem; use Sem;
54 with Sem_Aux;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_SCIL;
57 with Sem_Elab; use Sem_Elab;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_VFpt; use Sem_VFpt;
60 with Sem_Warn; use Sem_Warn;
61 with Sinfo; use Sinfo;
62 with Sinput; use Sinput;
63 with Sinput.L; use Sinput.L;
64 with SCIL_LL; use SCIL_LL;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Types; use Types;
69 procedure Frontend is
70 Config_Pragmas : List_Id;
71 -- Gather configuration pragmas
73 begin
74 -- Carry out package initializations. These are initializations which might
75 -- logically be performed at elaboration time, were it not for the fact
76 -- that we may be doing things more than once in the big loop over files.
77 -- Like elaboration, the order in which these calls are made is in some
78 -- cases important. For example, Lib cannot be initialized before Namet,
79 -- since it uses names table entries.
81 Rtsfind.Initialize;
82 Atree.Initialize;
83 Nlists.Initialize;
84 Elists.Initialize;
85 Lib.Load.Initialize;
86 Sem_Aux.Initialize;
87 Sem_Ch8.Initialize;
88 Sem_Prag.Initialize;
89 Fname.UF.Initialize;
90 Checks.Initialize;
91 Sem_Warn.Initialize;
92 Prep.Initialize;
94 if Generate_SCIL then
95 SCIL_LL.Initialize;
96 end if;
98 -- Create package Standard
100 CStand.Create_Standard;
102 -- If the -gnatd.H flag is present, we are only interested in the Standard
103 -- package, so the frontend has done its job here.
105 if Debug_Flag_Dot_HH then
106 return;
107 end if;
109 -- Check possible symbol definitions specified by -gnateD switches
111 Prepcomp.Process_Command_Line_Symbol_Definitions;
113 -- If -gnatep= was specified, parse the preprocessing data file
115 if Preprocessing_Data_File /= null then
116 Name_Len := Preprocessing_Data_File'Length;
117 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
118 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
120 -- Otherwise, check if there were preprocessing symbols on the command
121 -- line and set preprocessing if there are.
123 else
124 Prepcomp.Check_Symbols;
125 end if;
127 -- We set Parsing_Main_Extended_Source true here to cover processing of all
128 -- the configuration pragma files, as well as the main source unit itself.
130 Parsing_Main_Extended_Source := True;
132 -- Now that the preprocessing situation is established, we are able to
133 -- load the main source (this is no longer done by Lib.Load.Initialize).
135 Lib.Load.Load_Main_Source;
137 -- Return immediately if the main source could not be found
139 if Sinput.Main_Source_File = No_Source_File then
140 return;
141 end if;
143 -- Read and process configuration pragma files if present
145 declare
146 Save_Style_Check : constant Boolean := Opt.Style_Check;
147 -- Save style check mode so it can be restored later
149 Source_Config_File : Source_File_Index;
150 -- Source reference for -gnatec configuration file
152 Prag : Node_Id;
154 begin
155 -- We always analyze config files with style checks off, since
156 -- we don't want a miscellaneous gnat.adc that is around to
157 -- discombobulate intended -gnatg or -gnaty compilations. We
158 -- also disconnect checking for maximum line length.
160 Opt.Style_Check := False;
161 Style_Check := False;
163 -- Capture current suppress options, which may get modified
165 Scope_Suppress := Opt.Suppress_Options;
167 -- First deal with gnat.adc file
169 if Opt.Config_File then
170 Name_Buffer (1 .. 8) := "gnat.adc";
171 Name_Len := 8;
172 Source_gnat_adc := Load_Config_File (Name_Enter);
174 if Source_gnat_adc /= No_Source_File then
175 Initialize_Scanner (No_Unit, Source_gnat_adc);
176 Config_Pragmas := Par (Configuration_Pragmas => True);
177 else
178 Config_Pragmas := Empty_List;
179 end if;
181 else
182 Config_Pragmas := Empty_List;
183 end if;
185 -- Check for VAX Float
187 if Targparm.VAX_Float_On_Target then
189 -- pragma Float_Representation (VAX_Float);
191 Opt.Float_Format := 'V';
193 -- pragma Long_Float (G_Float);
195 Opt.Float_Format_Long := 'G';
197 Set_Standard_Fpt_Formats;
198 end if;
200 -- Now deal with specified config pragmas files if there are any
202 if Opt.Config_File_Names /= null then
203 for Index in Opt.Config_File_Names'Range loop
204 Name_Len := Config_File_Names (Index)'Length;
205 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
206 Source_Config_File := Load_Config_File (Name_Enter);
208 if Source_Config_File = No_Source_File then
209 Osint.Fail
210 ("cannot find configuration pragmas file "
211 & Config_File_Names (Index).all);
212 end if;
214 Initialize_Scanner (No_Unit, Source_Config_File);
215 Append_List_To
216 (Config_Pragmas, Par (Configuration_Pragmas => True));
217 end loop;
218 end if;
220 -- Now analyze all pragmas except those whose analysis must be
221 -- deferred till after the main unit is analyzed.
223 if Config_Pragmas /= Error_List
224 and then Operating_Mode /= Check_Syntax
225 then
226 Prag := First (Config_Pragmas);
227 while Present (Prag) loop
228 if not Delay_Config_Pragma_Analyze (Prag) then
229 Analyze_Pragma (Prag);
230 end if;
232 Next (Prag);
233 end loop;
234 end if;
236 -- Restore style check, but if config file turned on checks, leave on!
238 Opt.Style_Check := Save_Style_Check or Style_Check;
240 -- Capture any modifications to suppress options from config pragmas
242 Opt.Suppress_Options := Scope_Suppress;
243 end;
245 -- This is where we can capture the value of the compilation unit specific
246 -- restrictions that have been set by the config pragma files (or from
247 -- Targparm), for later restoration when processing e.g. subunits.
249 Save_Config_Cunit_Boolean_Restrictions;
251 -- If there was a -gnatem switch, initialize the mappings of unit names to
252 -- file names and of file names to path names from the mapping file.
254 if Mapping_File_Name /= null then
255 Fmap.Initialize (Mapping_File_Name.all);
256 end if;
258 -- Adjust Optimize_Alignment mode from debug switches if necessary
260 if Debug_Flag_Dot_SS then
261 Optimize_Alignment := 'S';
262 elsif Debug_Flag_Dot_TT then
263 Optimize_Alignment := 'T';
264 end if;
266 -- We have now processed the command line switches, and the configuration
267 -- pragma files, so this is the point at which we want to capture the
268 -- values of the configuration switches (see Opt for further details).
270 Opt.Register_Opt_Config_Switches;
272 -- Check for file which contains No_Body pragma
274 if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
275 Change_Main_Unit_To_Spec;
276 end if;
278 -- Initialize the scanner. Note that we do this after the call to
279 -- Create_Standard, which uses the scanner in its processing of
280 -- floating-point bounds.
282 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
284 -- Here we call the parser to parse the compilation unit (or units in
285 -- the check syntax mode, but in that case we won't go on to the
286 -- semantics in any case).
288 Discard_List (Par (Configuration_Pragmas => False));
289 Parsing_Main_Extended_Source := False;
291 -- The main unit is now loaded, and subunits of it can be loaded,
292 -- without reporting spurious loading circularities.
294 Set_Loading (Main_Unit, False);
296 -- Now that the main unit is installed, we can complete the analysis
297 -- of the pragmas in gnat.adc and the configuration file, that require
298 -- a context for their semantic processing.
300 if Config_Pragmas /= Error_List
301 and then Operating_Mode /= Check_Syntax
303 -- Do not attempt to process deferred configuration pragmas if the main
304 -- unit failed to load, to avoid cascaded inconsistencies that can lead
305 -- to a compiler crash.
307 and then not Fatal_Error (Main_Unit)
308 then
309 -- Pragmas that require some semantic activity, such as
310 -- Interrupt_State, cannot be processed until the main unit
311 -- is installed, because they require a compilation unit on
312 -- which to attach with_clauses, etc. So analyze them now.
314 declare
315 Prag : Node_Id;
317 begin
318 Prag := First (Config_Pragmas);
319 while Present (Prag) loop
320 if Delay_Config_Pragma_Analyze (Prag) then
321 Analyze_Pragma (Prag);
322 end if;
324 Next (Prag);
325 end loop;
326 end;
327 end if;
329 -- If we have restriction No_Exception_Propagation, and we did not have an
330 -- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
331 -- this warning by default if we have encountered an exception handler.
333 if Restriction_Check_Required (No_Exception_Propagation)
334 and then not No_Warn_On_Non_Local_Exception
335 and then Exception_Handler_Encountered
336 then
337 Warn_On_Non_Local_Exception := True;
338 end if;
340 -- Now on to the semantics. Skip if in syntax only mode
342 if Operating_Mode /= Check_Syntax then
344 -- Install the configuration pragmas in the tree
346 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
348 -- Following steps are skipped if we had a fatal error during parsing
350 if not Fatal_Error (Main_Unit) then
352 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
353 -- actually generate code for subunits, so we suppress expansion.
354 -- This also corrects certain problems that occur if we try to
355 -- incorporate subunits at a lower level.
357 if Operating_Mode = Generate_Code
358 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
359 then
360 Operating_Mode := Check_Semantics;
361 end if;
363 -- Analyze (and possibly expand) main unit
365 Scope_Suppress := Suppress_Options;
366 Semantics (Cunit (Main_Unit));
368 -- Cleanup processing after completing main analysis
370 if Operating_Mode = Generate_Code
371 or else (Operating_Mode = Check_Semantics
372 and then ASIS_Mode)
373 then
374 Instantiate_Bodies;
375 end if;
377 if Operating_Mode = Generate_Code then
378 if Inline_Processing_Required then
379 Analyze_Inlined_Bodies;
380 end if;
382 -- Remove entities from program that do not have any
383 -- execution time references.
385 if Debug_Flag_UU then
386 Collect_Garbage_Entities;
387 end if;
389 Check_Elab_Calls;
390 end if;
392 -- List library units if requested
394 if List_Units then
395 Lib.List;
396 end if;
398 -- Output waiting warning messages
400 Sem_Warn.Output_Non_Modified_In_Out_Warnings;
401 Sem_Warn.Output_Unreferenced_Messages;
402 Sem_Warn.Check_Unused_Withs;
403 Sem_Warn.Output_Unused_Warnings_Off_Warnings;
404 end if;
405 end if;
407 -- Qualify all entity names in inner packages, package bodies, etc.,
408 -- except when compiling for the VM back-ends, which depend on having
409 -- unqualified names in certain cases and handles the generation of
410 -- qualified names when needed.
412 if VM_Target = No_VM then
413 Exp_Dbug.Qualify_All_Entity_Names;
414 end if;
416 -- SCIL backend requirement. Check that SCIL nodes associated with
417 -- dispatching calls reference subprogram calls.
419 if Generate_SCIL then
420 pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
421 null;
422 end if;
424 -- Dump the source now. Note that we do this as soon as the analysis
425 -- of the tree is complete, because it is not just a dump in the case
426 -- of -gnatD, where it rewrites all source locations in the tree.
428 Sprint.Source_Dump;
430 -- Check again for configuration pragmas that appear in the context of
431 -- the main unit. These pragmas only affect the main unit, and the
432 -- corresponding flag is reset after each call to Semantics, but they
433 -- may affect the generated ali for the unit, and therefore the flag
434 -- must be set properly after compilation. Currently we only check for
435 -- Initialize_Scalars, but others should be checked: as well???
437 declare
438 Item : Node_Id;
440 begin
441 Item := First (Context_Items (Cunit (Main_Unit)));
442 while Present (Item) loop
443 if Nkind (Item) = N_Pragma
444 and then Pragma_Name (Item) = Name_Initialize_Scalars
445 then
446 Initialize_Scalars := True;
447 end if;
449 Next (Item);
450 end loop;
451 end;
453 -- If a mapping file has been specified by a -gnatem switch, update
454 -- it if there has been some sources that were not in the mappings.
456 if Mapping_File_Name /= null then
457 Fmap.Update_Mapping_File (Mapping_File_Name.all);
458 end if;
460 return;
461 end Frontend;