1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with GNAT.Strings; use GNAT.Strings;
29 with Atree; use Atree;
32 with Debug; use Debug;
37 with Hostparm; use Hostparm;
38 with Inline; use Inline;
40 with Lib.Load; use Lib.Load;
42 with Namet; use Namet;
43 with Nlists; use Nlists;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Elab; use Sem_Elab;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Warn; use Sem_Warn;
56 with Sinfo; use Sinfo;
57 with Sinput; use Sinput;
58 with Sinput.L; use Sinput.L;
59 with Tbuild; use Tbuild;
60 with Types; use Types;
63 Config_Pragmas : List_Id;
64 -- Gather configuration pragmas
67 -- Carry out package initializations. These are initializations which
68 -- might logically be performed at elaboration time, were it not for
69 -- the fact that we may be doing things more than once in the big loop
70 -- over files. Like elaboration, the order in which these calls are
71 -- made is in some cases important. For example, Lib cannot be
72 -- initialized until Namet, since it uses names table entries.
83 -- Create package Standard
85 CStand.Create_Standard;
87 -- Check possible symbol definitions specified by -gnateD switches
89 Prepcomp.Process_Command_Line_Symbol_Definitions;
91 -- If -gnatep= was specified, parse the preprocessing data file
93 if Preprocessing_Data_File /= null then
94 Name_Len := Preprocessing_Data_File'Length;
95 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
96 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
98 -- Otherwise, check if there were preprocessing symbols on the command
99 -- line and set preprocessing if there are.
102 Prepcomp.Check_Symbols;
105 -- Now that the preprocessing situation is established, we are able to
106 -- load the main source (this is no longer done by Lib.Load.Initalize).
108 Lib.Load.Load_Main_Source;
110 -- Read and process configuration pragma files if present
113 Save_Style_Check : constant Boolean := Opt.Style_Check;
114 -- Save style check mode so it can be restored later
116 Source_Config_File : Source_File_Index;
117 -- Source reference for -gnatec configuration file
122 -- We always analyze config files with style checks off, since
123 -- we don't want a miscellaneous gnat.adc that is around to
124 -- discombobulate intended -gnatg or -gnaty compilations. We
125 -- also disconnect checking for maximum line length.
127 Opt.Style_Check := False;
128 Style_Check := False;
130 -- Capture current suppress options, which may get modified
132 Scope_Suppress := Opt.Suppress_Options;
134 -- First deal with gnat.adc file
136 if Opt.Config_File then
137 Name_Buffer (1 .. 8) := "gnat.adc";
139 Source_gnat_adc := Load_Config_File (Name_Enter);
141 if Source_gnat_adc /= No_Source_File then
142 Initialize_Scanner (No_Unit, Source_gnat_adc);
143 Config_Pragmas := Par (Configuration_Pragmas => True);
146 Config_Pragmas := Empty_List;
150 Config_Pragmas := Empty_List;
153 -- Now deal with specified config pragmas files if there are any
155 if Opt.Config_File_Names /= null then
156 for Index in Opt.Config_File_Names'Range loop
157 Name_Len := Config_File_Names (Index)'Length;
158 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
159 Source_Config_File := Load_Config_File (Name_Enter);
161 if Source_Config_File = No_Source_File then
163 ("cannot find configuration pragmas file ",
164 Config_File_Names (Index).all);
167 Initialize_Scanner (No_Unit, Source_Config_File);
169 (Config_Pragmas, Par (Configuration_Pragmas => True));
173 -- Now analyze all pragmas except those whose analysis must be
174 -- deferred till after the main unit is analyzed.
176 if Config_Pragmas /= Error_List
177 and then Operating_Mode /= Check_Syntax
179 Prag := First (Config_Pragmas);
180 while Present (Prag) loop
181 if not Delay_Config_Pragma_Analyze (Prag) then
182 Analyze_Pragma (Prag);
189 -- Restore style check, but if config file turned on checks, leave on!
191 Opt.Style_Check := Save_Style_Check or Style_Check;
193 -- Capture any modifications to suppress options from config pragmas
195 Opt.Suppress_Options := Scope_Suppress;
198 -- If there was a -gnatem switch, initialize the mappings of unit names to
199 -- file names and of file names to path names from the mapping file.
201 if Mapping_File_Name /= null then
202 Fmap.Initialize (Mapping_File_Name.all);
205 -- We have now processed the command line switches, and the gnat.adc
206 -- file, so this is the point at which we want to capture the values
207 -- of the configuration switches (see Opt for further details).
209 Opt.Register_Opt_Config_Switches;
211 -- Initialize the scanner. Note that we do this after the call to
212 -- Create_Standard, which uses the scanner in its processing of
213 -- floating-point bounds.
215 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
217 -- Here we call the parser to parse the compilation unit (or units in
218 -- the check syntax mode, but in that case we won't go on to the
219 -- semantics in any case).
221 Discard_List (Par (Configuration_Pragmas => False));
223 -- The main unit is now loaded, and subunits of it can be loaded,
224 -- without reporting spurious loading circularities.
226 Set_Loading (Main_Unit, False);
228 -- Now that the main unit is installed, we can complete the analysis
229 -- of the pragmas in gnat.adc and the configuration file, that require
230 -- a context for their semantic processing.
232 if Config_Pragmas /= Error_List
233 and then Operating_Mode /= Check_Syntax
235 -- Pragmas that require some semantic activity, such as
236 -- Interrupt_State, cannot be processed until the main unit
237 -- is installed, because they require a compilation unit on
238 -- which to attach with_clauses, etc. So analyze them now.
244 Prag := First (Config_Pragmas);
245 while Present (Prag) loop
246 if Delay_Config_Pragma_Analyze (Prag) then
247 Analyze_Pragma (Prag);
255 -- Now on to the semantics. Skip if in syntax only mode
257 if Operating_Mode /= Check_Syntax then
259 -- Install the configuration pragmas in the tree
261 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
263 -- Following steps are skipped if we had a fatal error during parsing
265 if not Fatal_Error (Main_Unit) then
267 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
268 -- actually generate code for subunits, so we suppress expansion.
269 -- This also corrects certain problems that occur if we try to
270 -- incorporate subunits at a lower level.
272 if Operating_Mode = Generate_Code
273 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
275 Operating_Mode := Check_Semantics;
278 -- Analyze (and possibly expand) main unit
280 Scope_Suppress := Suppress_Options;
281 Semantics (Cunit (Main_Unit));
283 -- Cleanup processing after completing main analysis
285 if Operating_Mode = Generate_Code
286 or else (Operating_Mode = Check_Semantics
292 if Operating_Mode = Generate_Code then
293 if Inline_Processing_Required then
294 Analyze_Inlined_Bodies;
297 -- Remove entities from program that do not have any
298 -- execution time references.
300 if Debug_Flag_UU then
301 Collect_Garbage_Entities;
307 -- List library units if requested
313 -- Output any messages for unreferenced entities
315 Output_Unreferenced_Messages;
316 Sem_Warn.Check_Unused_Withs;
320 -- Qualify all entity names in inner packages, package bodies, etc.,
321 -- except when compiling for the JVM back end, which depends on
322 -- having unqualified names in certain cases and handles the
323 -- generation of qualified names when needed.
326 Exp_Dbug.Qualify_All_Entity_Names;
329 -- Dump the source now. Note that we do this as soon as the analysis
330 -- of the tree is complete, because it is not just a dump in the case
331 -- of -gnatD, where it rewrites all source locations in the tree.
335 -- If a mapping file has been specified by a -gnatem switch, update
336 -- it if there has been some sourcs that were not in the mappings.
338 if Mapping_File_Name /= null then
339 Fmap.Update_Mapping_File (Mapping_File_Name.all);