clean up and renames beginigs of a testsuite
[official-gcc.git] / gcc / ada / frontend.adb
blobfb5eb4319f1d16225001e4e39c115fd0530a6215
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-2010, 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_Warn; use Sem_Warn;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Sinput.L; use Sinput.L;
63 with SCIL_LL; use SCIL_LL;
64 with Targparm; use Targparm;
65 with Tbuild; use Tbuild;
66 with Types; use Types;
68 procedure Frontend is
69 Config_Pragmas : List_Id;
70 -- Gather configuration pragmas
72 begin
73 -- Carry out package initializations. These are initializations which might
74 -- logically be performed at elaboration time, were it not for the fact
75 -- that we may be doing things more than once in the big loop over files.
76 -- Like elaboration, the order in which these calls are made is in some
77 -- cases important. For example, Lib cannot be initialized before Namet,
78 -- since it uses names table entries.
80 Rtsfind.Initialize;
81 Atree.Initialize;
82 Nlists.Initialize;
83 Elists.Initialize;
84 Lib.Load.Initialize;
85 Sem_Aux.Initialize;
86 Sem_Ch8.Initialize;
87 Sem_Prag.Initialize;
88 Fname.UF.Initialize;
89 Checks.Initialize;
90 Sem_Warn.Initialize;
91 Prep.Initialize;
93 if Generate_SCIL then
94 SCIL_LL.Initialize;
95 end if;
97 -- Create package Standard
99 CStand.Create_Standard;
101 -- Check possible symbol definitions specified by -gnateD switches
103 Prepcomp.Process_Command_Line_Symbol_Definitions;
105 -- If -gnatep= was specified, parse the preprocessing data file
107 if Preprocessing_Data_File /= null then
108 Name_Len := Preprocessing_Data_File'Length;
109 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
110 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
112 -- Otherwise, check if there were preprocessing symbols on the command
113 -- line and set preprocessing if there are.
115 else
116 Prepcomp.Check_Symbols;
117 end if;
119 -- Now that the preprocessing situation is established, we are able to
120 -- load the main source (this is no longer done by Lib.Load.Initialize).
122 Lib.Load.Load_Main_Source;
124 -- Return immediately if the main source could not be parsed
126 if Sinput.Main_Source_File = No_Source_File then
127 return;
128 end if;
130 -- Read and process configuration pragma files if present
132 declare
133 Save_Style_Check : constant Boolean := Opt.Style_Check;
134 -- Save style check mode so it can be restored later
136 Source_Config_File : Source_File_Index;
137 -- Source reference for -gnatec configuration file
139 Prag : Node_Id;
141 begin
142 -- We always analyze config files with style checks off, since
143 -- we don't want a miscellaneous gnat.adc that is around to
144 -- discombobulate intended -gnatg or -gnaty compilations. We
145 -- also disconnect checking for maximum line length.
147 Opt.Style_Check := False;
148 Style_Check := False;
150 -- Capture current suppress options, which may get modified
152 Scope_Suppress := Opt.Suppress_Options;
154 -- First deal with gnat.adc file
156 if Opt.Config_File then
157 Name_Buffer (1 .. 8) := "gnat.adc";
158 Name_Len := 8;
159 Source_gnat_adc := Load_Config_File (Name_Enter);
161 if Source_gnat_adc /= No_Source_File then
162 Initialize_Scanner (No_Unit, Source_gnat_adc);
163 Config_Pragmas := Par (Configuration_Pragmas => True);
165 else
166 Config_Pragmas := Empty_List;
167 end if;
169 else
170 Config_Pragmas := Empty_List;
171 end if;
173 -- Now deal with specified config pragmas files if there are any
175 if Opt.Config_File_Names /= null then
176 for Index in Opt.Config_File_Names'Range loop
177 Name_Len := Config_File_Names (Index)'Length;
178 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
179 Source_Config_File := Load_Config_File (Name_Enter);
181 if Source_Config_File = No_Source_File then
182 Osint.Fail
183 ("cannot find configuration pragmas file "
184 & Config_File_Names (Index).all);
185 end if;
187 Initialize_Scanner (No_Unit, Source_Config_File);
188 Append_List_To
189 (Config_Pragmas, Par (Configuration_Pragmas => True));
190 end loop;
191 end if;
193 -- Now analyze all pragmas except those whose analysis must be
194 -- deferred till after the main unit is analyzed.
196 if Config_Pragmas /= Error_List
197 and then Operating_Mode /= Check_Syntax
198 then
199 Prag := First (Config_Pragmas);
200 while Present (Prag) loop
201 if not Delay_Config_Pragma_Analyze (Prag) then
202 Analyze_Pragma (Prag);
203 end if;
205 Next (Prag);
206 end loop;
207 end if;
209 -- Restore style check, but if config file turned on checks, leave on!
211 Opt.Style_Check := Save_Style_Check or Style_Check;
213 -- Capture any modifications to suppress options from config pragmas
215 Opt.Suppress_Options := Scope_Suppress;
216 end;
218 -- If there was a -gnatem switch, initialize the mappings of unit names to
219 -- file names and of file names to path names from the mapping file.
221 if Mapping_File_Name /= null then
222 Fmap.Initialize (Mapping_File_Name.all);
223 end if;
225 -- Adjust Optimize_Alignment mode from debug switches if necessary
227 if Debug_Flag_Dot_SS then
228 Optimize_Alignment := 'S';
229 elsif Debug_Flag_Dot_TT then
230 Optimize_Alignment := 'T';
231 end if;
233 -- We have now processed the command line switches, and the gnat.adc
234 -- file, so this is the point at which we want to capture the values
235 -- of the configuration switches (see Opt for further details).
237 Opt.Register_Opt_Config_Switches;
239 -- Check for file which contains No_Body pragma
241 if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
242 Change_Main_Unit_To_Spec;
243 end if;
245 -- Initialize the scanner. Note that we do this after the call to
246 -- Create_Standard, which uses the scanner in its processing of
247 -- floating-point bounds.
249 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
251 -- Here we call the parser to parse the compilation unit (or units in
252 -- the check syntax mode, but in that case we won't go on to the
253 -- semantics in any case).
255 Discard_List (Par (Configuration_Pragmas => False));
257 -- The main unit is now loaded, and subunits of it can be loaded,
258 -- without reporting spurious loading circularities.
260 Set_Loading (Main_Unit, False);
262 -- Now that the main unit is installed, we can complete the analysis
263 -- of the pragmas in gnat.adc and the configuration file, that require
264 -- a context for their semantic processing.
266 if Config_Pragmas /= Error_List
267 and then Operating_Mode /= Check_Syntax
268 then
269 -- Pragmas that require some semantic activity, such as
270 -- Interrupt_State, cannot be processed until the main unit
271 -- is installed, because they require a compilation unit on
272 -- which to attach with_clauses, etc. So analyze them now.
274 declare
275 Prag : Node_Id;
277 begin
278 Prag := First (Config_Pragmas);
279 while Present (Prag) loop
280 if Delay_Config_Pragma_Analyze (Prag) then
281 Analyze_Pragma (Prag);
282 end if;
284 Next (Prag);
285 end loop;
286 end;
287 end if;
289 -- If we have restriction No_Exception_Propagation, and we did not have an
290 -- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
291 -- this warning by default if we have encountered an exception handler.
293 if Restriction_Active (No_Exception_Propagation)
294 and then not No_Warn_On_Non_Local_Exception
295 and then Exception_Handler_Encountered
296 then
297 Warn_On_Non_Local_Exception := True;
298 end if;
300 -- Now on to the semantics. Skip if in syntax only mode
302 if Operating_Mode /= Check_Syntax then
304 -- Install the configuration pragmas in the tree
306 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
308 -- Following steps are skipped if we had a fatal error during parsing
310 if not Fatal_Error (Main_Unit) then
312 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
313 -- actually generate code for subunits, so we suppress expansion.
314 -- This also corrects certain problems that occur if we try to
315 -- incorporate subunits at a lower level.
317 if Operating_Mode = Generate_Code
318 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
319 then
320 Operating_Mode := Check_Semantics;
321 end if;
323 -- Analyze (and possibly expand) main unit
325 Scope_Suppress := Suppress_Options;
326 Semantics (Cunit (Main_Unit));
328 -- Cleanup processing after completing main analysis
330 if Operating_Mode = Generate_Code
331 or else (Operating_Mode = Check_Semantics
332 and then ASIS_Mode)
333 then
334 Instantiate_Bodies;
335 end if;
337 if Operating_Mode = Generate_Code then
338 if Inline_Processing_Required then
339 Analyze_Inlined_Bodies;
340 end if;
342 -- Remove entities from program that do not have any
343 -- execution time references.
345 if Debug_Flag_UU then
346 Collect_Garbage_Entities;
347 end if;
349 Check_Elab_Calls;
350 end if;
352 -- List library units if requested
354 if List_Units then
355 Lib.List;
356 end if;
358 -- Output waiting warning messages
360 Sem_Warn.Output_Non_Modified_In_Out_Warnings;
361 Sem_Warn.Output_Unreferenced_Messages;
362 Sem_Warn.Check_Unused_Withs;
363 Sem_Warn.Output_Unused_Warnings_Off_Warnings;
364 end if;
365 end if;
367 -- Qualify all entity names in inner packages, package bodies, etc.,
368 -- except when compiling for the VM back-ends, which depend on
369 -- having unqualified names in certain cases and handles the
370 -- generation of qualified names when needed.
372 if VM_Target = No_VM then
373 Exp_Dbug.Qualify_All_Entity_Names;
374 end if;
376 -- SCIL backend requirement. Check that SCIL nodes associated with
377 -- dispatching calls reference subprogram calls.
379 if Generate_SCIL then
380 pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
381 null;
382 end if;
384 -- Dump the source now. Note that we do this as soon as the analysis
385 -- of the tree is complete, because it is not just a dump in the case
386 -- of -gnatD, where it rewrites all source locations in the tree.
388 Sprint.Source_Dump;
390 -- Check again for configuration pragmas that appear in the context of
391 -- the main unit. These pragmas only affect the main unit, and the
392 -- corresponding flag is reset after each call to Semantics, but they
393 -- may affect the generated ali for the unit, and therefore the flag
394 -- must be set properly after compilation. Currently we only check for
395 -- Initialize_Scalars, but others should be checked: as well???
397 declare
398 Item : Node_Id;
400 begin
401 Item := First (Context_Items (Cunit (Main_Unit)));
402 while Present (Item) loop
403 if Nkind (Item) = N_Pragma
404 and then Pragma_Name (Item) = Name_Initialize_Scalars
405 then
406 Initialize_Scalars := True;
407 end if;
409 Next (Item);
410 end loop;
411 end;
413 -- If a mapping file has been specified by a -gnatem switch, update
414 -- it if there has been some sources that were not in the mappings.
416 if Mapping_File_Name /= null then
417 Fmap.Update_Mapping_File (Mapping_File_Name.all);
418 end if;
420 return;
421 end Frontend;