PR target/16201
[official-gcc.git] / gcc / ada / frontend.adb
blob35645bd0812dbcbab76f97a80c45b94f5413c701
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-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with GNAT.Strings; use GNAT.Strings;
29 with Atree; use Atree;
30 with Checks;
31 with CStand;
32 with Debug; use Debug;
33 with Elists;
34 with Exp_Ch11;
35 with Exp_Dbug;
36 with Fmap;
37 with Fname.UF;
38 with Hostparm; use Hostparm;
39 with Inline; use Inline;
40 with Lib; use Lib;
41 with Lib.Load; use Lib.Load;
42 with Live; use Live;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Opt; use Opt;
46 with Osint;
47 with Output; use Output;
48 with Par;
49 with Prepcomp;
50 with Rtsfind;
51 with Sprint;
52 with Scn; use Scn;
53 with Sem; use Sem;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Warn; use Sem_Warn;
58 with Sinfo; use Sinfo;
59 with Sinput; use Sinput;
60 with Sinput.L; use Sinput.L;
61 with Tbuild; use Tbuild;
62 with Types; use Types;
64 procedure Frontend is
65 Config_Pragmas : List_Id;
66 -- Gather configuration pragmas
68 begin
69 -- Carry out package initializations. These are initializations which
70 -- might logically be performed at elaboration time, were it not for
71 -- the fact that we may be doing things more than once in the big loop
72 -- over files. Like elaboration, the order in which these calls are
73 -- made is in some cases important. For example, Lib cannot be
74 -- initialized until Namet, since it uses names table entries.
76 Rtsfind.Initialize;
77 Atree.Initialize;
78 Nlists.Initialize;
79 Elists.Initialize;
80 Lib.Load.Initialize;
81 Sem_Ch8.Initialize;
82 Fname.UF.Initialize;
83 Exp_Ch11.Initialize;
84 Checks.Initialize;
86 -- Create package Standard
88 CStand.Create_Standard;
90 -- Check possible symbol definitions specified by -gnateD switches
92 Prepcomp.Process_Command_Line_Symbol_Definitions;
94 -- If -gnatep= was specified, parse the preprocessing data file
96 if Preprocessing_Data_File /= null then
97 Name_Len := Preprocessing_Data_File'Length;
98 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
99 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
101 -- Otherwise, check if there were preprocessing symbols on the command
102 -- line and set preprocessing if there are.
104 else
105 Prepcomp.Check_Symbols;
106 end if;
108 -- Now that the preprocessing situation is established, we are able to
109 -- load the main source (this is no longer done by Lib.Load.Initalize).
111 Lib.Load.Load_Main_Source;
113 -- Read and process configuration pragma files if present
115 declare
116 Save_Style_Check : constant Boolean := Opt.Style_Check;
117 -- Save style check mode so it can be restored later
119 Source_Config_File : Source_File_Index;
120 -- Source reference for -gnatec configuration file
122 Prag : Node_Id;
124 begin
125 -- We always analyze config files with style checks off, since
126 -- we don't want a miscellaneous gnat.adc that is around to
127 -- discombobulate intended -gnatg or -gnaty compilations. We
128 -- also disconnect checking for maximum line length.
130 Opt.Style_Check := False;
131 Style_Check := False;
132 Opt.Max_Line_Length := Int (Column_Number'Last);
134 -- Capture current suppress options, which may get modified
136 Scope_Suppress := Opt.Suppress_Options;
138 -- First deal with gnat.adc file
140 if Opt.Config_File then
141 Name_Buffer (1 .. 8) := "gnat.adc";
142 Name_Len := 8;
143 Source_gnat_adc := Load_Config_File (Name_Enter);
145 if Source_gnat_adc /= No_Source_File then
146 Initialize_Scanner (No_Unit, Source_gnat_adc);
147 Config_Pragmas := Par (Configuration_Pragmas => True);
149 else
150 Config_Pragmas := Empty_List;
151 end if;
153 else
154 Config_Pragmas := Empty_List;
155 end if;
157 -- Now deal with specified config pragmas files if there are any
159 if Opt.Config_File_Names /= null then
160 for Index in Opt.Config_File_Names'Range loop
161 Name_Len := Config_File_Names (Index)'Length;
162 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
163 Source_Config_File := Load_Config_File (Name_Enter);
165 if Source_Config_File = No_Source_File then
166 Osint.Fail
167 ("cannot find configuration pragmas file ",
168 Config_File_Names (Index).all);
169 end if;
171 Initialize_Scanner (No_Unit, Source_Config_File);
172 Append_List_To
173 (Config_Pragmas, Par (Configuration_Pragmas => True));
174 end loop;
175 end if;
177 -- Now analyze all pragmas except those whose analysis must be
178 -- deferred till after the main unit is analyzed.
180 if Config_Pragmas /= Error_List
181 and then Operating_Mode /= Check_Syntax
182 then
183 Prag := First (Config_Pragmas);
184 while Present (Prag) loop
185 if not Delay_Config_Pragma_Analyze (Prag) then
186 Analyze_Pragma (Prag);
187 end if;
189 Next (Prag);
190 end loop;
191 end if;
193 -- Restore style check, but if config file turned on checks, leave on!
195 Opt.Style_Check := Save_Style_Check or Style_Check;
196 Opt.Max_Line_Length := Hostparm.Max_Line_Length;
198 -- Capture any modifications to suppress options from config pragmas
200 Opt.Suppress_Options := Scope_Suppress;
201 end;
203 -- If there was a -gnatem switch, initialize the mappings of unit names to
204 -- file names and of file names to path names from the mapping file.
206 if Mapping_File_Name /= null then
207 Fmap.Initialize (Mapping_File_Name.all);
208 end if;
210 -- We have now processed the command line switches, and the gnat.adc
211 -- file, so this is the point at which we want to capture the values
212 -- of the configuration switches (see Opt for further details).
214 Opt.Register_Opt_Config_Switches;
216 -- Initialize the scanner. Note that we do this after the call to
217 -- Create_Standard, which uses the scanner in its processing of
218 -- floating-point bounds.
220 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
222 -- Output header if in verbose mode or full list mode
224 if Verbose_Mode or Full_List then
225 Write_Eol;
227 if Operating_Mode = Generate_Code then
228 Write_Str ("Compiling: ");
229 else
230 Write_Str ("Checking: ");
231 end if;
233 Write_Name (Full_File_Name (Current_Source_File));
235 if not Debug_Flag_7 then
236 Write_Str (" (source file time stamp: ");
237 Write_Time_Stamp (Current_Source_File);
238 Write_Char (')');
239 end if;
241 Write_Eol;
242 end if;
244 -- Here we call the parser to parse the compilation unit (or units in
245 -- the check syntax mode, but in that case we won't go on to the
246 -- semantics in any case).
248 Discard_List (Par (Configuration_Pragmas => False));
250 -- The main unit is now loaded, and subunits of it can be loaded,
251 -- without reporting spurious loading circularities.
253 Set_Loading (Main_Unit, False);
255 -- Now that the main unit is installed, we can complete the analysis
256 -- of the pragmas in gnat.adc and the configuration file, that require
257 -- a context for their semantic processing.
259 if Config_Pragmas /= Error_List
260 and then Operating_Mode /= Check_Syntax
261 then
262 -- Pragmas that require some semantic activity, such as
263 -- Interrupt_State, cannot be processed until the main unit
264 -- is installed, because they require a compilation unit on
265 -- which to attach with_clauses, etc. So analyze them now.
267 declare
268 Prag : Node_Id;
270 begin
271 Prag := First (Config_Pragmas);
272 while Present (Prag) loop
273 if Delay_Config_Pragma_Analyze (Prag) then
274 Analyze_Pragma (Prag);
275 end if;
277 Next (Prag);
278 end loop;
279 end;
280 end if;
282 -- Now on to the semantics. Skip if in syntax only mode
284 if Operating_Mode /= Check_Syntax then
286 -- Install the configuration pragmas in the tree
288 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
290 -- Following steps are skipped if we had a fatal error during parsing
292 if not Fatal_Error (Main_Unit) then
294 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
295 -- actually generate code for subunits, so we suppress expansion.
296 -- This also corrects certain problems that occur if we try to
297 -- incorporate subunits at a lower level.
299 if Operating_Mode = Generate_Code
300 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
301 then
302 Operating_Mode := Check_Semantics;
303 end if;
305 -- Analyze (and possibly expand) main unit
307 Scope_Suppress := Suppress_Options;
308 Semantics (Cunit (Main_Unit));
310 -- Cleanup processing after completing main analysis
312 if Operating_Mode = Generate_Code
313 or else (Operating_Mode = Check_Semantics
314 and then ASIS_Mode)
315 then
316 Instantiate_Bodies;
317 end if;
319 if Operating_Mode = Generate_Code then
320 if Inline_Processing_Required then
321 Analyze_Inlined_Bodies;
322 end if;
324 -- Remove entities from program that do not have any
325 -- execution time references.
327 if Debug_Flag_UU then
328 Collect_Garbage_Entities;
329 end if;
331 Check_Elab_Calls;
333 -- Build unit exception table. We leave this up to the end to
334 -- make sure that all the necessary information is at hand.
336 Exp_Ch11.Generate_Unit_Exception_Table;
337 end if;
339 -- List library units if requested
341 if List_Units then
342 Lib.List;
343 end if;
345 -- Output any messages for unreferenced entities
347 Output_Unreferenced_Messages;
348 Sem_Warn.Check_Unused_Withs;
349 end if;
350 end if;
352 -- Qualify all entity names in inner packages, package bodies, etc.,
353 -- except when compiling for the JVM back end, which depends on
354 -- having unqualified names in certain cases and handles the
355 -- generation of qualified names when needed.
357 if not Java_VM then
358 Exp_Dbug.Qualify_All_Entity_Names;
359 end if;
361 -- Dump the source now. Note that we do this as soon as the analysis
362 -- of the tree is complete, because it is not just a dump in the case
363 -- of -gnatD, where it rewrites all source locations in the tree.
365 Sprint.Source_Dump;
367 -- If a mapping file has been specified by a -gnatem switch, update
368 -- it if there has been some sourcs that were not in the mappings.
370 if Mapping_File_Name /= null then
371 Fmap.Update_Mapping_File (Mapping_File_Name.all);
372 end if;
374 return;
375 end Frontend;