1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with System
.Strings
; use System
.Strings
;
28 with Atree
; use Atree
;
31 with Debug
; use Debug
;
36 with Inline
; use Inline
;
38 with Lib
.Load
; use Lib
.Load
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
50 with Snames
; use Snames
;
55 with Sem_Ch8
; use Sem_Ch8
;
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
;
69 Config_Pragmas
: List_Id
;
70 -- Gather configuration pragmas
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.
97 -- Create package Standard
99 CStand
.Create_Standard
;
101 -- If the -gnatd.H flag is present, we are only interested in the Standard
102 -- package, so the frontend has done its job here.
104 if Debug_Flag_Dot_HH
then
108 -- Check possible symbol definitions specified by -gnateD switches
110 Prepcomp
.Process_Command_Line_Symbol_Definitions
;
112 -- If -gnatep= was specified, parse the preprocessing data file
114 if Preprocessing_Data_File
/= null then
115 Name_Len
:= Preprocessing_Data_File
'Length;
116 Name_Buffer
(1 .. Name_Len
) := Preprocessing_Data_File
.all;
117 Prepcomp
.Parse_Preprocessing_Data_File
(Name_Find
);
119 -- Otherwise, check if there were preprocessing symbols on the command
120 -- line and set preprocessing if there are.
123 Prepcomp
.Check_Symbols
;
126 -- We set Parsing_Main_Extended_Source true here to cover processing of all
127 -- the configuration pragma files, as well as the main source unit itself.
129 Parsing_Main_Extended_Source
:= True;
131 -- Now that the preprocessing situation is established, we are able to
132 -- load the main source (this is no longer done by Lib.Load.Initialize).
134 Lib
.Load
.Load_Main_Source
;
136 -- Return immediately if the main source could not be found
138 if Sinput
.Main_Source_File
= No_Source_File
then
142 -- Read and process configuration pragma files if present
145 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
146 -- Save style check mode so it can be restored later
148 Source_Config_File
: Source_File_Index
;
149 -- Source reference for -gnatec configuration file
154 -- We always analyze config files with style checks off, since
155 -- we don't want a miscellaneous gnat.adc that is around to
156 -- discombobulate intended -gnatg or -gnaty compilations. We
157 -- also disconnect checking for maximum line length.
159 Opt
.Style_Check
:= False;
160 Style_Check
:= False;
162 -- Capture current suppress options, which may get modified
164 Scope_Suppress
:= Opt
.Suppress_Options
;
166 -- First deal with gnat.adc file
168 if Opt
.Config_File
then
169 Name_Buffer
(1 .. 8) := "gnat.adc";
171 Source_gnat_adc
:= Load_Config_File
(Name_Enter
);
173 if Source_gnat_adc
/= No_Source_File
then
174 Initialize_Scanner
(No_Unit
, Source_gnat_adc
);
175 Config_Pragmas
:= Par
(Configuration_Pragmas
=> True);
177 Config_Pragmas
:= Empty_List
;
181 Config_Pragmas
:= Empty_List
;
184 -- Now deal with specified config pragmas files if there are any
186 if Opt
.Config_File_Names
/= null then
187 for Index
in Opt
.Config_File_Names
'Range loop
188 Name_Len
:= Config_File_Names
(Index
)'Length;
189 Name_Buffer
(1 .. Name_Len
) := Config_File_Names
(Index
).all;
190 Source_Config_File
:= Load_Config_File
(Name_Enter
);
192 if Source_Config_File
= No_Source_File
then
194 ("cannot find configuration pragmas file "
195 & Config_File_Names
(Index
).all);
198 Initialize_Scanner
(No_Unit
, Source_Config_File
);
200 (Config_Pragmas
, Par
(Configuration_Pragmas
=> True));
204 -- Now analyze all pragmas except those whose analysis must be
205 -- deferred till after the main unit is analyzed.
207 if Config_Pragmas
/= Error_List
208 and then Operating_Mode
/= Check_Syntax
210 Prag
:= First
(Config_Pragmas
);
211 while Present
(Prag
) loop
212 if not Delay_Config_Pragma_Analyze
(Prag
) then
213 Analyze_Pragma
(Prag
);
220 -- Restore style check, but if config file turned on checks, leave on!
222 Opt
.Style_Check
:= Save_Style_Check
or Style_Check
;
224 -- Capture any modifications to suppress options from config pragmas
226 Opt
.Suppress_Options
:= Scope_Suppress
;
229 -- This is where we can capture the value of the compilation unit specific
230 -- restrictions that have been set by the config pragma files (or from
231 -- Targparm), for later restoration when processing e.g. subunits.
233 Save_Config_Cunit_Boolean_Restrictions
;
235 -- If there was a -gnatem switch, initialize the mappings of unit names to
236 -- file names and of file names to path names from the mapping file.
238 if Mapping_File_Name
/= null then
239 Fmap
.Initialize
(Mapping_File_Name
.all);
242 -- Adjust Optimize_Alignment mode from debug switches if necessary
244 if Debug_Flag_Dot_SS
then
245 Optimize_Alignment
:= 'S';
246 elsif Debug_Flag_Dot_TT
then
247 Optimize_Alignment
:= 'T';
250 -- We have now processed the command line switches, and the configuration
251 -- pragma files, so this is the point at which we want to capture the
252 -- values of the configuration switches (see Opt for further details).
254 Opt
.Register_Opt_Config_Switches
;
256 -- Check for file which contains No_Body pragma
258 if Source_File_Is_No_Body
(Source_Index
(Main_Unit
)) then
259 Change_Main_Unit_To_Spec
;
262 -- Initialize the scanner. Note that we do this after the call to
263 -- Create_Standard, which uses the scanner in its processing of
264 -- floating-point bounds.
266 Initialize_Scanner
(Main_Unit
, Source_Index
(Main_Unit
));
268 -- Here we call the parser to parse the compilation unit (or units in
269 -- the check syntax mode, but in that case we won't go on to the
270 -- semantics in any case).
272 Discard_List
(Par
(Configuration_Pragmas
=> False));
273 Parsing_Main_Extended_Source
:= False;
275 -- The main unit is now loaded, and subunits of it can be loaded,
276 -- without reporting spurious loading circularities.
278 Set_Loading
(Main_Unit
, False);
280 -- Now that the main unit is installed, we can complete the analysis
281 -- of the pragmas in gnat.adc and the configuration file, that require
282 -- a context for their semantic processing.
284 if Config_Pragmas
/= Error_List
285 and then Operating_Mode
/= Check_Syntax
287 -- Pragmas that require some semantic activity, such as
288 -- Interrupt_State, cannot be processed until the main unit
289 -- is installed, because they require a compilation unit on
290 -- which to attach with_clauses, etc. So analyze them now.
296 Prag
:= First
(Config_Pragmas
);
297 while Present
(Prag
) loop
298 if Delay_Config_Pragma_Analyze
(Prag
) then
299 Analyze_Pragma
(Prag
);
307 -- If we have restriction No_Exception_Propagation, and we did not have an
308 -- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
309 -- this warning by default if we have encountered an exception handler.
311 if Restriction_Check_Required
(No_Exception_Propagation
)
312 and then not No_Warn_On_Non_Local_Exception
313 and then Exception_Handler_Encountered
315 Warn_On_Non_Local_Exception
:= True;
318 -- Now on to the semantics. Skip if in syntax only mode
320 if Operating_Mode
/= Check_Syntax
then
322 -- Install the configuration pragmas in the tree
324 Set_Config_Pragmas
(Aux_Decls_Node
(Cunit
(Main_Unit
)), Config_Pragmas
);
326 -- Following steps are skipped if we had a fatal error during parsing
328 if not Fatal_Error
(Main_Unit
) then
330 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
331 -- actually generate code for subunits, so we suppress expansion.
332 -- This also corrects certain problems that occur if we try to
333 -- incorporate subunits at a lower level.
335 if Operating_Mode
= Generate_Code
336 and then Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
338 Operating_Mode
:= Check_Semantics
;
341 -- Analyze (and possibly expand) main unit
343 Scope_Suppress
:= Suppress_Options
;
344 Semantics
(Cunit
(Main_Unit
));
346 -- Cleanup processing after completing main analysis
348 if Operating_Mode
= Generate_Code
349 or else (Operating_Mode
= Check_Semantics
355 if Operating_Mode
= Generate_Code
then
356 if Inline_Processing_Required
then
357 Analyze_Inlined_Bodies
;
360 -- Remove entities from program that do not have any
361 -- execution time references.
363 if Debug_Flag_UU
then
364 Collect_Garbage_Entities
;
370 -- List library units if requested
376 -- Output waiting warning messages
378 Sem_Warn
.Output_Non_Modified_In_Out_Warnings
;
379 Sem_Warn
.Output_Unreferenced_Messages
;
380 Sem_Warn
.Check_Unused_Withs
;
381 Sem_Warn
.Output_Unused_Warnings_Off_Warnings
;
385 -- Qualify all entity names in inner packages, package bodies, etc.,
386 -- except when compiling for the VM back-ends, which depend on having
387 -- unqualified names in certain cases and handles the generation of
388 -- qualified names when needed.
390 if VM_Target
= No_VM
then
391 Exp_Dbug
.Qualify_All_Entity_Names
;
394 -- SCIL backend requirement. Check that SCIL nodes associated with
395 -- dispatching calls reference subprogram calls.
397 if Generate_SCIL
then
398 pragma Debug
(Sem_SCIL
.Check_SCIL_Nodes
(Cunit
(Main_Unit
)));
402 -- Dump the source now. Note that we do this as soon as the analysis
403 -- of the tree is complete, because it is not just a dump in the case
404 -- of -gnatD, where it rewrites all source locations in the tree.
408 -- Check again for configuration pragmas that appear in the context of
409 -- the main unit. These pragmas only affect the main unit, and the
410 -- corresponding flag is reset after each call to Semantics, but they
411 -- may affect the generated ali for the unit, and therefore the flag
412 -- must be set properly after compilation. Currently we only check for
413 -- Initialize_Scalars, but others should be checked: as well???
419 Item
:= First
(Context_Items
(Cunit
(Main_Unit
)));
420 while Present
(Item
) loop
421 if Nkind
(Item
) = N_Pragma
422 and then Pragma_Name
(Item
) = Name_Initialize_Scalars
424 Initialize_Scalars
:= True;
431 -- If a mapping file has been specified by a -gnatem switch, update
432 -- it if there has been some sources that were not in the mappings.
434 if Mapping_File_Name
/= null then
435 Fmap
.Update_Mapping_File
(Mapping_File_Name
.all);