OSDN Git Service

* misc.c (insert_default_attributes): Add dummy version.
[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 --                            $Revision: 1.84 $
10 --                                                                          --
11 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 with Atree;    use Atree;
30 with Checks;
31 with CStand;
32 with Debug;    use Debug;
33 with Elists;
34 with Exp_Ch11;
35 with Exp_Dbug;
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 Rtsfind;
49 with Sprint;
50 with Scn;      use Scn;
51 with Sem;      use Sem;
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 Types;    use Types;
60
61 procedure Frontend is
62       Pragmas : List_Id;
63       Prag    : Node_Id;
64
65       Save_Style_Check : constant Boolean := Opt.Style_Check;
66       --  Save style check mode so it can be restored later
67
68 begin
69    --  Carry out package initializations. These are initializations which
70    --  might logically be performed at elaboration time, were it not for
71    --  the fact that we may be doing things more than once in the big loop
72    --  over files. Like elaboration, the order in which these calls are
73    --  made is in some cases important. For example, Lib cannot be
74    --  initialized until Namet, since it uses names table entries.
75
76    Rtsfind.Initialize;
77    Atree.Initialize;
78    Nlists.Initialize;
79    Elists.Initialize;
80    Lib.Load.Initialize;
81    Sem_Ch8.Initialize;
82    Fname.UF.Initialize;
83    Exp_Ch11.Initialize;
84    Checks.Initialize;
85
86    --  Create package Standard
87
88    CStand.Create_Standard;
89
90    --  Read and process gnat.adc file if one is present
91
92    if Opt.Config_File then
93
94       --  We always analyze the gnat.adc file with style checks off,
95       --  since we don't want a miscellaneous gnat.adc that is around
96       --  to discombobulate intended -gnatg compilations.
97
98       Opt.Style_Check := False;
99
100       --  Capture current suppress options, which may get modified
101
102       Scope_Suppress := Opt.Suppress_Options;
103
104       Name_Buffer (1 .. 8) := "gnat.adc";
105       Name_Len := 8;
106       Source_gnat_adc := Load_Config_File (Name_Enter);
107
108       if Source_gnat_adc /= No_Source_File then
109          Initialize_Scanner (No_Unit, Source_gnat_adc);
110          Pragmas := Par (Configuration_Pragmas => True);
111
112          if Pragmas /= Error_List
113            and then Operating_Mode /= Check_Syntax
114          then
115             Prag := First (Pragmas);
116             while Present (Prag) loop
117                Analyze_Pragma (Prag);
118                Next (Prag);
119             end loop;
120          end if;
121       end if;
122
123       --  Restore style check, but if gnat.adc turned on checks, leave on!
124
125       Opt.Style_Check := Save_Style_Check or Style_Check;
126
127       --  Capture any modifications to suppress options from config pragmas
128
129       Opt.Suppress_Options := Scope_Suppress;
130    end if;
131
132    --  Read and process the configuration pragmas file if one is present
133
134    if Config_File_Name /= null then
135
136       declare
137          New_Pragmas        : List_Id;
138          Style_Check_Saved  : constant Boolean  := Opt.Style_Check;
139          Source_Config_File : Source_File_Index := No_Source_File;
140
141       begin
142          --  We always analyze the config pragmas file with style checks off,
143          --  since we don't want it to discombobulate intended
144          --  -gnatg compilations.
145
146          Opt.Style_Check := False;
147
148          --  Capture current suppress options, which may get modified
149
150          Scope_Suppress := Opt.Suppress_Options;
151
152          Name_Buffer (1 .. Config_File_Name'Length) := Config_File_Name.all;
153          Name_Len := Config_File_Name'Length;
154          Source_Config_File := Load_Config_File (Name_Enter);
155
156          if Source_Config_File = No_Source_File then
157             Osint.Fail
158               ("cannot find configuration pragmas file ",
159                Config_File_Name.all);
160          end if;
161
162          Initialize_Scanner (No_Unit, Source_Config_File);
163          New_Pragmas := Par (Configuration_Pragmas => True);
164
165          if New_Pragmas /= Error_List
166            and then Operating_Mode /= Check_Syntax
167          then
168             Prag := First (New_Pragmas);
169             while Present (Prag) loop
170                Analyze_Pragma (Prag);
171                Next (Prag);
172             end loop;
173          end if;
174
175          --  Restore style check, but if the config pragmas file
176          --  turned on checks, leave on!
177
178          Opt.Style_Check := Style_Check_Saved or Style_Check;
179
180          --  Capture any modifications to suppress options from config pragmas
181
182          Opt.Suppress_Options := Scope_Suppress;
183       end;
184
185    end if;
186
187    --  We have now processed the command line switches, and the gnat.adc
188    --  file, so this is the point at which we want to capture the values
189    --  of the configuration switches (see Opt for further details).
190
191    Opt.Register_Opt_Config_Switches;
192
193    --  Initialize the scanner. Note that we do this after the call to
194    --  Create_Standard, which uses the scanner in its processing of
195    --  floating-point bounds.
196
197    Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
198
199    --  Output header if in verbose mode or full list mode
200
201    if Verbose_Mode or Full_List then
202       Write_Eol;
203
204       if Operating_Mode = Generate_Code then
205          Write_Str ("Compiling: ");
206       else
207          Write_Str ("Checking: ");
208       end if;
209
210       Write_Name (Full_File_Name (Current_Source_File));
211
212       if not Debug_Flag_7 then
213          Write_Str (" (source file time stamp: ");
214          Write_Time_Stamp (Current_Source_File);
215          Write_Char (')');
216       end if;
217
218       Write_Eol;
219    end if;
220
221    --  Here we call the parser to parse the compilation unit (or units in
222    --  the check syntax mode, but in that case we won't go on to the
223    --  semantics in any case).
224
225    declare
226       Discard : List_Id;
227
228    begin
229       Discard := Par (Configuration_Pragmas => False);
230    end;
231
232    --  The main unit is now loaded, and subunits of it can be loaded,
233    --  without reporting spurious loading circularities.
234
235    Set_Loading (Main_Unit, False);
236
237    --  Now on to the semantics. We skip the semantics if we are in syntax
238    --  only mode, or if we encountered a fatal error during the parsing.
239
240    if Operating_Mode /= Check_Syntax
241      and then not Fatal_Error (Main_Unit)
242    then
243       --  Reset Operating_Mode to Check_Semantics for subunits. We cannot
244       --  actually generate code for subunits, so we suppress expansion.
245       --  This also corrects certain problems that occur if we try to
246       --  incorporate subunits at a lower level.
247
248       if Operating_Mode = Generate_Code
249          and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
250       then
251          Operating_Mode := Check_Semantics;
252       end if;
253
254       --  Analyze (and possibly expand) main unit
255
256       Scope_Suppress := Suppress_Options;
257       Semantics (Cunit (Main_Unit));
258
259       --  Cleanup processing after completing main analysis
260
261       if Operating_Mode = Generate_Code
262          or else (Operating_Mode = Check_Semantics
263                    and then Tree_Output)
264       then
265          Instantiate_Bodies;
266       end if;
267
268       if Operating_Mode = Generate_Code then
269
270          if Inline_Processing_Required then
271             Analyze_Inlined_Bodies;
272          end if;
273
274          --  Remove entities from program that do not have any
275          --  execution time references.
276
277          if Debug_Flag_UU then
278             Collect_Garbage_Entities;
279          end if;
280
281          Check_Elab_Calls;
282
283          --  Build unit exception table. We leave this up to the end to
284          --  make sure that all the necessary information is at hand.
285
286          Exp_Ch11.Generate_Unit_Exception_Table;
287
288          --  Save the unit name and list of packages named in Use_Package
289          --  clauses for subsequent use in generating a special symbol for
290          --  the debugger for certain targets that require this.
291
292          Exp_Dbug.Save_Unitname_And_Use_List
293            (Cunit (Main_Unit), Nkind (Unit (Cunit (Main_Unit))));
294       end if;
295
296       --  List library units if requested
297
298       if List_Units then
299          Lib.List;
300       end if;
301
302       --  Output any messages for unreferenced entities
303
304       Output_Unreferenced_Messages;
305    end if;
306
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.
311
312    if not Java_VM then
313       Exp_Dbug.Qualify_All_Entity_Names;
314       Exp_Dbug.Generate_Auxiliary_Types;
315    end if;
316
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.
320
321    Sprint.Source_Dump;
322 end Frontend;