1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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
;
46 with Output
; use Output
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Elab
; use Sem_Elab
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Warn
; use Sem_Warn
;
57 with Sinfo
; use Sinfo
;
58 with Sinput
; use Sinput
;
59 with Sinput
.L
; use Sinput
.L
;
60 with Tbuild
; use Tbuild
;
61 with Types
; use Types
;
64 Config_Pragmas
: List_Id
;
65 -- Gather configuration pragmas
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.
84 -- Create package Standard
86 CStand
.Create_Standard
;
88 -- Check possible symbol definitions specified by -gnateD switches
90 Prepcomp
.Process_Command_Line_Symbol_Definitions
;
92 -- If -gnatep= was specified, parse the preprocessing data file
94 if Preprocessing_Data_File
/= null then
95 Name_Len
:= Preprocessing_Data_File
'Length;
96 Name_Buffer
(1 .. Name_Len
) := Preprocessing_Data_File
.all;
97 Prepcomp
.Parse_Preprocessing_Data_File
(Name_Find
);
99 -- Otherwise, check if there were preprocessing symbols on the command
100 -- line and set preprocessing if there are.
103 Prepcomp
.Check_Symbols
;
106 -- Now that the preprocessing situation is established, we are able to
107 -- load the main source (this is no longer done by Lib.Load.Initalize).
109 Lib
.Load
.Load_Main_Source
;
111 -- Read and process configuration pragma files if present
114 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
115 -- Save style check mode so it can be restored later
117 Source_Config_File
: Source_File_Index
;
118 -- Source reference for -gnatec configuration file
123 -- We always analyze config files with style checks off, since
124 -- we don't want a miscellaneous gnat.adc that is around to
125 -- discombobulate intended -gnatg or -gnaty compilations. We
126 -- also disconnect checking for maximum line length.
128 Opt
.Style_Check
:= False;
129 Style_Check
:= False;
131 -- Capture current suppress options, which may get modified
133 Scope_Suppress
:= Opt
.Suppress_Options
;
135 -- First deal with gnat.adc file
137 if Opt
.Config_File
then
138 Name_Buffer
(1 .. 8) := "gnat.adc";
140 Source_gnat_adc
:= Load_Config_File
(Name_Enter
);
142 if Source_gnat_adc
/= No_Source_File
then
143 Initialize_Scanner
(No_Unit
, Source_gnat_adc
);
144 Config_Pragmas
:= Par
(Configuration_Pragmas
=> True);
147 Config_Pragmas
:= Empty_List
;
151 Config_Pragmas
:= Empty_List
;
154 -- Now deal with specified config pragmas files if there are any
156 if Opt
.Config_File_Names
/= null then
157 for Index
in Opt
.Config_File_Names
'Range loop
158 Name_Len
:= Config_File_Names
(Index
)'Length;
159 Name_Buffer
(1 .. Name_Len
) := Config_File_Names
(Index
).all;
160 Source_Config_File
:= Load_Config_File
(Name_Enter
);
162 if Source_Config_File
= No_Source_File
then
164 ("cannot find configuration pragmas file ",
165 Config_File_Names
(Index
).all);
168 Initialize_Scanner
(No_Unit
, Source_Config_File
);
170 (Config_Pragmas
, Par
(Configuration_Pragmas
=> True));
174 -- Now analyze all pragmas except those whose analysis must be
175 -- deferred till after the main unit is analyzed.
177 if Config_Pragmas
/= Error_List
178 and then Operating_Mode
/= Check_Syntax
180 Prag
:= First
(Config_Pragmas
);
181 while Present
(Prag
) loop
182 if not Delay_Config_Pragma_Analyze
(Prag
) then
183 Analyze_Pragma
(Prag
);
190 -- Restore style check, but if config file turned on checks, leave on!
192 Opt
.Style_Check
:= Save_Style_Check
or Style_Check
;
194 -- Capture any modifications to suppress options from config pragmas
196 Opt
.Suppress_Options
:= Scope_Suppress
;
199 -- If there was a -gnatem switch, initialize the mappings of unit names to
200 -- file names and of file names to path names from the mapping file.
202 if Mapping_File_Name
/= null then
203 Fmap
.Initialize
(Mapping_File_Name
.all);
206 -- We have now processed the command line switches, and the gnat.adc
207 -- file, so this is the point at which we want to capture the values
208 -- of the configuration switches (see Opt for further details).
210 Opt
.Register_Opt_Config_Switches
;
212 -- Initialize the scanner. Note that we do this after the call to
213 -- Create_Standard, which uses the scanner in its processing of
214 -- floating-point bounds.
216 Initialize_Scanner
(Main_Unit
, Source_Index
(Main_Unit
));
218 -- Output header if in verbose mode or full list mode
220 if Verbose_Mode
or Full_List
then
223 if Operating_Mode
= Generate_Code
then
224 Write_Str
("Compiling: ");
226 Write_Str
("Checking: ");
229 Write_Name
(Full_File_Name
(Current_Source_File
));
231 if not Debug_Flag_7
then
232 Write_Str
(" (source file time stamp: ");
233 Write_Time_Stamp
(Current_Source_File
);
240 -- Here we call the parser to parse the compilation unit (or units in
241 -- the check syntax mode, but in that case we won't go on to the
242 -- semantics in any case).
244 Discard_List
(Par
(Configuration_Pragmas
=> False));
246 -- The main unit is now loaded, and subunits of it can be loaded,
247 -- without reporting spurious loading circularities.
249 Set_Loading
(Main_Unit
, False);
251 -- Now that the main unit is installed, we can complete the analysis
252 -- of the pragmas in gnat.adc and the configuration file, that require
253 -- a context for their semantic processing.
255 if Config_Pragmas
/= Error_List
256 and then Operating_Mode
/= Check_Syntax
258 -- Pragmas that require some semantic activity, such as
259 -- Interrupt_State, cannot be processed until the main unit
260 -- is installed, because they require a compilation unit on
261 -- which to attach with_clauses, etc. So analyze them now.
267 Prag
:= First
(Config_Pragmas
);
268 while Present
(Prag
) loop
269 if Delay_Config_Pragma_Analyze
(Prag
) then
270 Analyze_Pragma
(Prag
);
278 -- Now on to the semantics. Skip if in syntax only mode
280 if Operating_Mode
/= Check_Syntax
then
282 -- Install the configuration pragmas in the tree
284 Set_Config_Pragmas
(Aux_Decls_Node
(Cunit
(Main_Unit
)), Config_Pragmas
);
286 -- Following steps are skipped if we had a fatal error during parsing
288 if not Fatal_Error
(Main_Unit
) then
290 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
291 -- actually generate code for subunits, so we suppress expansion.
292 -- This also corrects certain problems that occur if we try to
293 -- incorporate subunits at a lower level.
295 if Operating_Mode
= Generate_Code
296 and then Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
298 Operating_Mode
:= Check_Semantics
;
301 -- Analyze (and possibly expand) main unit
303 Scope_Suppress
:= Suppress_Options
;
304 Semantics
(Cunit
(Main_Unit
));
306 -- Cleanup processing after completing main analysis
308 if Operating_Mode
= Generate_Code
309 or else (Operating_Mode
= Check_Semantics
315 if Operating_Mode
= Generate_Code
then
316 if Inline_Processing_Required
then
317 Analyze_Inlined_Bodies
;
320 -- Remove entities from program that do not have any
321 -- execution time references.
323 if Debug_Flag_UU
then
324 Collect_Garbage_Entities
;
330 -- List library units if requested
336 -- Output any messages for unreferenced entities
338 Output_Unreferenced_Messages
;
339 Sem_Warn
.Check_Unused_Withs
;
343 -- Qualify all entity names in inner packages, package bodies, etc.,
344 -- except when compiling for the JVM back end, which depends on
345 -- having unqualified names in certain cases and handles the
346 -- generation of qualified names when needed.
349 Exp_Dbug
.Qualify_All_Entity_Names
;
352 -- Dump the source now. Note that we do this as soon as the analysis
353 -- of the tree is complete, because it is not just a dump in the case
354 -- of -gnatD, where it rewrites all source locations in the tree.
358 -- If a mapping file has been specified by a -gnatem switch, update
359 -- it if there has been some sourcs that were not in the mappings.
361 if Mapping_File_Name
/= null then
362 Fmap
.Update_Mapping_File
(Mapping_File_Name
.all);