2003-05-31 Bud Davis <bdavis9659@comcast.net>
[official-gcc.git] / gcc / ada / frontend.adb
blob758513eb180ef99ccdeed48d2c02c5844a5fbe08
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-2002 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 Atree; use Atree;
28 with Checks;
29 with CStand;
30 with Debug; use Debug;
31 with Elists;
32 with Exp_Ch11;
33 with Exp_Dbug;
34 with Fmap;
35 with Fname.UF;
36 with Hostparm; use Hostparm;
37 with Inline; use Inline;
38 with Lib; use Lib;
39 with Lib.Load; use Lib.Load;
40 with Live; use Live;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Opt; use Opt;
44 with Osint;
45 with Output; use Output;
46 with Par;
47 with Rtsfind;
48 with Sprint;
49 with Scn; use Scn;
50 with Sem; use Sem;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Elab; use Sem_Elab;
53 with Sem_Prag; use Sem_Prag;
54 with Sem_Warn; use Sem_Warn;
55 with Sinfo; use Sinfo;
56 with Sinput; use Sinput;
57 with Sinput.L; use Sinput.L;
58 with Types; use Types;
60 procedure Frontend is
61 Pragmas : List_Id;
62 Prag : Node_Id;
64 Save_Style_Check : constant Boolean := Opt.Style_Check;
65 -- Save style check mode so it can be restored later
67 begin
68 -- Carry out package initializations. These are initializations which
69 -- might logically be performed at elaboration time, were it not for
70 -- the fact that we may be doing things more than once in the big loop
71 -- over files. Like elaboration, the order in which these calls are
72 -- made is in some cases important. For example, Lib cannot be
73 -- initialized until Namet, since it uses names table entries.
75 Rtsfind.Initialize;
76 Atree.Initialize;
77 Nlists.Initialize;
78 Elists.Initialize;
79 Lib.Load.Initialize;
80 Sem_Ch8.Initialize;
81 Fname.UF.Initialize;
82 Exp_Ch11.Initialize;
83 Checks.Initialize;
85 -- Create package Standard
87 CStand.Create_Standard;
89 -- Read and process gnat.adc file if one is present
91 if Opt.Config_File then
93 -- We always analyze the gnat.adc file with style checks off,
94 -- since we don't want a miscellaneous gnat.adc that is around
95 -- to discombobulate intended -gnatg compilations.
97 Opt.Style_Check := False;
99 -- Capture current suppress options, which may get modified
101 Scope_Suppress := Opt.Suppress_Options;
103 Name_Buffer (1 .. 8) := "gnat.adc";
104 Name_Len := 8;
105 Source_gnat_adc := Load_Config_File (Name_Enter);
107 if Source_gnat_adc /= No_Source_File then
108 Initialize_Scanner (No_Unit, Source_gnat_adc);
109 Pragmas := Par (Configuration_Pragmas => True);
111 if Pragmas /= Error_List
112 and then Operating_Mode /= Check_Syntax
113 then
114 Prag := First (Pragmas);
115 while Present (Prag) loop
116 Analyze_Pragma (Prag);
117 Next (Prag);
118 end loop;
119 end if;
120 end if;
122 -- Restore style check, but if gnat.adc turned on checks, leave on!
124 Opt.Style_Check := Save_Style_Check or Style_Check;
126 -- Capture any modifications to suppress options from config pragmas
128 Opt.Suppress_Options := Scope_Suppress;
129 end if;
131 -- Read and process the configuration pragmas file if one is present
133 if Config_File_Name /= null then
135 declare
136 New_Pragmas : List_Id;
137 Style_Check_Saved : constant Boolean := Opt.Style_Check;
138 Source_Config_File : Source_File_Index := No_Source_File;
140 begin
141 -- We always analyze the config pragmas file with style checks off,
142 -- since we don't want it to discombobulate intended
143 -- -gnatg compilations.
145 Opt.Style_Check := False;
147 -- Capture current suppress options, which may get modified
149 Scope_Suppress := Opt.Suppress_Options;
151 Name_Buffer (1 .. Config_File_Name'Length) := Config_File_Name.all;
152 Name_Len := Config_File_Name'Length;
153 Source_Config_File := Load_Config_File (Name_Enter);
155 if Source_Config_File = No_Source_File then
156 Osint.Fail
157 ("cannot find configuration pragmas file ",
158 Config_File_Name.all);
159 end if;
161 Initialize_Scanner (No_Unit, Source_Config_File);
162 New_Pragmas := Par (Configuration_Pragmas => True);
164 if New_Pragmas /= Error_List
165 and then Operating_Mode /= Check_Syntax
166 then
167 Prag := First (New_Pragmas);
168 while Present (Prag) loop
169 Analyze_Pragma (Prag);
170 Next (Prag);
171 end loop;
172 end if;
174 -- Restore style check, but if the config pragmas file
175 -- turned on checks, leave on!
177 Opt.Style_Check := Style_Check_Saved or Style_Check;
179 -- Capture any modifications to suppress options from config pragmas
181 Opt.Suppress_Options := Scope_Suppress;
182 end;
184 end if;
186 -- If there was a -gnatem switch, initialize the mappings of unit names to
187 -- file names and of file names to path names from the mapping file.
189 if Mapping_File_Name /= null then
190 Fmap.Initialize (Mapping_File_Name.all);
191 end if;
193 -- We have now processed the command line switches, and the gnat.adc
194 -- file, so this is the point at which we want to capture the values
195 -- of the configuration switches (see Opt for further details).
197 Opt.Register_Opt_Config_Switches;
199 -- Initialize the scanner. Note that we do this after the call to
200 -- Create_Standard, which uses the scanner in its processing of
201 -- floating-point bounds.
203 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
205 -- Output header if in verbose mode or full list mode
207 if Verbose_Mode or Full_List then
208 Write_Eol;
210 if Operating_Mode = Generate_Code then
211 Write_Str ("Compiling: ");
212 else
213 Write_Str ("Checking: ");
214 end if;
216 Write_Name (Full_File_Name (Current_Source_File));
218 if not Debug_Flag_7 then
219 Write_Str (" (source file time stamp: ");
220 Write_Time_Stamp (Current_Source_File);
221 Write_Char (')');
222 end if;
224 Write_Eol;
225 end if;
227 -- Here we call the parser to parse the compilation unit (or units in
228 -- the check syntax mode, but in that case we won't go on to the
229 -- semantics in any case).
231 declare
232 Discard : List_Id;
234 begin
235 Discard := Par (Configuration_Pragmas => False);
236 end;
238 -- The main unit is now loaded, and subunits of it can be loaded,
239 -- without reporting spurious loading circularities.
241 Set_Loading (Main_Unit, False);
243 -- Now on to the semantics. We skip the semantics if we are in syntax
244 -- only mode, or if we encountered a fatal error during the parsing.
246 if Operating_Mode /= Check_Syntax
247 and then not Fatal_Error (Main_Unit)
248 then
249 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
250 -- actually generate code for subunits, so we suppress expansion.
251 -- This also corrects certain problems that occur if we try to
252 -- incorporate subunits at a lower level.
254 if Operating_Mode = Generate_Code
255 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
256 then
257 Operating_Mode := Check_Semantics;
258 end if;
260 -- Analyze (and possibly expand) main unit
262 Scope_Suppress := Suppress_Options;
263 Semantics (Cunit (Main_Unit));
265 -- Cleanup processing after completing main analysis
267 if Operating_Mode = Generate_Code
268 or else (Operating_Mode = Check_Semantics
269 and then Tree_Output)
270 then
271 Instantiate_Bodies;
272 end if;
274 if Operating_Mode = Generate_Code then
276 if Inline_Processing_Required then
277 Analyze_Inlined_Bodies;
278 end if;
280 -- Remove entities from program that do not have any
281 -- execution time references.
283 if Debug_Flag_UU then
284 Collect_Garbage_Entities;
285 end if;
287 Check_Elab_Calls;
289 -- Build unit exception table. We leave this up to the end to
290 -- make sure that all the necessary information is at hand.
292 Exp_Ch11.Generate_Unit_Exception_Table;
293 end if;
295 -- List library units if requested
297 if List_Units then
298 Lib.List;
299 end if;
301 -- Output any messages for unreferenced entities
303 Output_Unreferenced_Messages;
304 Sem_Warn.Check_Unused_Withs;
305 end if;
307 -- Qualify all entity names in inner packages, package bodies, etc.,
308 -- except when compiling for the JVM back end, which depends on
309 -- having unqualified names in certain cases and handles the generation
310 -- of qualified names when needed.
312 if not Java_VM then
313 Exp_Dbug.Qualify_All_Entity_Names;
314 Exp_Dbug.Generate_Auxiliary_Types;
315 end if;
317 -- Dump the source now. Note that we do this as soon as the analysis
318 -- of the tree is complete, because it is not just a dump in the case
319 -- of -gnatD, where it rewrites all source locations in the tree.
321 Sprint.Source_Dump;
323 -- If a mapping file has been specified by a -gnatem switch,
324 -- update it if there has been some sourcs that were not in the mappings.
326 if Mapping_File_Name /= null then
327 Fmap.Update_Mapping_File (Mapping_File_Name.all);
328 end if;
330 end Frontend;