OSDN Git Service

* gcc.dg/attr-weakref-1.c: Add exit (0) to avoid spurious
[pf3gnuchains/gcc-fork.git] / gcc / ada / frontend.adb
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-2005 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
26
27 with GNAT.Strings; use GNAT.Strings;
28
29 with Atree;    use Atree;
30 with Checks;
31 with CStand;
32 with Debug;    use Debug;
33 with Elists;
34 with Exp_Dbug;
35 with Fmap;
36 with Fname.UF;
37 with Hostparm; use Hostparm;
38 with Inline;   use Inline;
39 with Lib;      use Lib;
40 with Lib.Load; use Lib.Load;
41 with Live;     use Live;
42 with Namet;    use Namet;
43 with Nlists;   use Nlists;
44 with Opt;      use Opt;
45 with Osint;
46 with Output;   use Output;
47 with Par;
48 with Prepcomp;
49 with Rtsfind;
50 with Sprint;
51 with Scn;      use Scn;
52 with Sem;      use Sem;
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;
62
63 procedure Frontend is
64       Config_Pragmas : List_Id;
65       --  Gather configuration pragmas
66
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.
74
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    Checks.Initialize;
83
84    --  Create package Standard
85
86    CStand.Create_Standard;
87
88    --  Check possible symbol definitions specified by -gnateD switches
89
90    Prepcomp.Process_Command_Line_Symbol_Definitions;
91
92    --  If -gnatep= was specified, parse the preprocessing data file
93
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);
98
99    --  Otherwise, check if there were preprocessing symbols on the command
100    --  line and set preprocessing if there are.
101
102    else
103       Prepcomp.Check_Symbols;
104    end if;
105
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).
108
109    Lib.Load.Load_Main_Source;
110
111    --  Read and process configuration pragma files if present
112
113    declare
114       Save_Style_Check : constant Boolean := Opt.Style_Check;
115       --  Save style check mode so it can be restored later
116
117       Source_Config_File : Source_File_Index;
118       --  Source reference for -gnatec configuration file
119
120       Prag : Node_Id;
121
122    begin
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.
127
128       Opt.Style_Check := False;
129       Style_Check := False;
130       Opt.Max_Line_Length := Int (Column_Number'Last);
131
132       --  Capture current suppress options, which may get modified
133
134       Scope_Suppress := Opt.Suppress_Options;
135
136       --  First deal with gnat.adc file
137
138       if Opt.Config_File then
139          Name_Buffer (1 .. 8) := "gnat.adc";
140          Name_Len := 8;
141          Source_gnat_adc := Load_Config_File (Name_Enter);
142
143          if Source_gnat_adc /= No_Source_File then
144             Initialize_Scanner (No_Unit, Source_gnat_adc);
145             Config_Pragmas := Par (Configuration_Pragmas => True);
146
147          else
148             Config_Pragmas := Empty_List;
149          end if;
150
151       else
152          Config_Pragmas := Empty_List;
153       end if;
154
155       --  Now deal with specified config pragmas files if there are any
156
157       if Opt.Config_File_Names /= null then
158          for Index in Opt.Config_File_Names'Range loop
159             Name_Len := Config_File_Names (Index)'Length;
160             Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
161             Source_Config_File := Load_Config_File (Name_Enter);
162
163             if Source_Config_File = No_Source_File then
164                Osint.Fail
165                  ("cannot find configuration pragmas file ",
166                   Config_File_Names (Index).all);
167             end if;
168
169             Initialize_Scanner (No_Unit, Source_Config_File);
170             Append_List_To
171               (Config_Pragmas, Par (Configuration_Pragmas => True));
172          end loop;
173       end if;
174
175       --  Now analyze all pragmas except those whose analysis must be
176       --  deferred till after the main unit is analyzed.
177
178       if Config_Pragmas /= Error_List
179         and then Operating_Mode /= Check_Syntax
180       then
181          Prag := First (Config_Pragmas);
182          while Present (Prag) loop
183             if not Delay_Config_Pragma_Analyze (Prag) then
184                Analyze_Pragma (Prag);
185             end if;
186
187             Next (Prag);
188          end loop;
189       end if;
190
191       --  Restore style check, but if config file turned on checks, leave on!
192
193       Opt.Style_Check := Save_Style_Check or Style_Check;
194       Opt.Max_Line_Length := Hostparm.Max_Line_Length;
195
196       --  Capture any modifications to suppress options from config pragmas
197
198       Opt.Suppress_Options := Scope_Suppress;
199    end;
200
201    --  If there was a -gnatem switch, initialize the mappings of unit names to
202    --  file names and of file names to path names from the mapping file.
203
204    if Mapping_File_Name /= null then
205       Fmap.Initialize (Mapping_File_Name.all);
206    end if;
207
208    --  We have now processed the command line switches, and the gnat.adc
209    --  file, so this is the point at which we want to capture the values
210    --  of the configuration switches (see Opt for further details).
211
212    Opt.Register_Opt_Config_Switches;
213
214    --  Initialize the scanner. Note that we do this after the call to
215    --  Create_Standard, which uses the scanner in its processing of
216    --  floating-point bounds.
217
218    Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
219
220    --  Output header if in verbose mode or full list mode
221
222    if Verbose_Mode or Full_List then
223       Write_Eol;
224
225       if Operating_Mode = Generate_Code then
226          Write_Str ("Compiling: ");
227       else
228          Write_Str ("Checking: ");
229       end if;
230
231       Write_Name (Full_File_Name (Current_Source_File));
232
233       if not Debug_Flag_7 then
234          Write_Str (" (source file time stamp: ");
235          Write_Time_Stamp (Current_Source_File);
236          Write_Char (')');
237       end if;
238
239       Write_Eol;
240    end if;
241
242    --  Here we call the parser to parse the compilation unit (or units in
243    --  the check syntax mode, but in that case we won't go on to the
244    --  semantics in any case).
245
246    Discard_List (Par (Configuration_Pragmas => False));
247
248    --  The main unit is now loaded, and subunits of it can be loaded,
249    --  without reporting spurious loading circularities.
250
251    Set_Loading (Main_Unit, False);
252
253    --  Now that the main unit is installed, we can complete the analysis
254    --  of the pragmas in gnat.adc and the configuration file, that require
255    --  a context for their semantic processing.
256
257    if Config_Pragmas /= Error_List
258      and then Operating_Mode /= Check_Syntax
259    then
260       --  Pragmas that require some semantic activity, such as
261       --  Interrupt_State, cannot be processed until the main unit
262       --  is installed, because they require a compilation unit on
263       --  which to attach with_clauses, etc. So analyze them now.
264
265       declare
266          Prag : Node_Id;
267
268       begin
269          Prag := First (Config_Pragmas);
270          while Present (Prag) loop
271             if Delay_Config_Pragma_Analyze (Prag) then
272                Analyze_Pragma (Prag);
273             end if;
274
275             Next (Prag);
276          end loop;
277       end;
278    end if;
279
280    --  Now on to the semantics. Skip if in syntax only mode
281
282    if Operating_Mode /= Check_Syntax then
283
284       --  Install the configuration pragmas in the tree
285
286       Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
287
288       --  Following steps are skipped if we had a fatal error during parsing
289
290       if not Fatal_Error (Main_Unit) then
291
292          --  Reset Operating_Mode to Check_Semantics for subunits. We cannot
293          --  actually generate code for subunits, so we suppress expansion.
294          --  This also corrects certain problems that occur if we try to
295          --  incorporate subunits at a lower level.
296
297          if Operating_Mode = Generate_Code
298             and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
299          then
300             Operating_Mode := Check_Semantics;
301          end if;
302
303          --  Analyze (and possibly expand) main unit
304
305          Scope_Suppress := Suppress_Options;
306          Semantics (Cunit (Main_Unit));
307
308          --  Cleanup processing after completing main analysis
309
310          if Operating_Mode = Generate_Code
311             or else (Operating_Mode = Check_Semantics
312                       and then ASIS_Mode)
313          then
314             Instantiate_Bodies;
315          end if;
316
317          if Operating_Mode = Generate_Code then
318             if Inline_Processing_Required then
319                Analyze_Inlined_Bodies;
320             end if;
321
322             --  Remove entities from program that do not have any
323             --  execution time references.
324
325             if Debug_Flag_UU then
326                Collect_Garbage_Entities;
327             end if;
328
329             Check_Elab_Calls;
330          end if;
331
332          --  List library units if requested
333
334          if List_Units then
335             Lib.List;
336          end if;
337
338          --  Output any messages for unreferenced entities
339
340          Output_Unreferenced_Messages;
341          Sem_Warn.Check_Unused_Withs;
342       end if;
343    end if;
344
345    --  Qualify all entity names in inner packages, package bodies, etc.,
346    --  except when compiling for the JVM back end, which depends on
347    --  having unqualified names in certain cases and handles the
348    --  generation of qualified names when needed.
349
350    if not Java_VM then
351       Exp_Dbug.Qualify_All_Entity_Names;
352    end if;
353
354    --  Dump the source now. Note that we do this as soon as the analysis
355    --  of the tree is complete, because it is not just a dump in the case
356    --  of -gnatD, where it rewrites all source locations in the tree.
357
358    Sprint.Source_Dump;
359
360    --  If a mapping file has been specified by a -gnatem switch, update
361    --  it if there has been some sourcs that were not in the mappings.
362
363    if Mapping_File_Name /= null then
364       Fmap.Update_Mapping_File (Mapping_File_Name.all);
365    end if;
366
367    return;
368 end Frontend;