OSDN Git Service

* Make-lang.in (gnat_ug_unx.info): Add dependency on stmp-docobjdir.
[pf3gnuchains/gcc-fork.git] / gcc / ada / expander.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             E X P A N D E R                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2001 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 Atree;     use Atree;
28 with Debug_A;   use Debug_A;
29 with Errout;    use Errout;
30 with Exp_Aggr;  use Exp_Aggr;
31 with Exp_Attr;  use Exp_Attr;
32 with Exp_Ch2;   use Exp_Ch2;
33 with Exp_Ch3;   use Exp_Ch3;
34 with Exp_Ch4;   use Exp_Ch4;
35 with Exp_Ch5;   use Exp_Ch5;
36 with Exp_Ch6;   use Exp_Ch6;
37 with Exp_Ch7;   use Exp_Ch7;
38 with Exp_Ch8;   use Exp_Ch8;
39 with Exp_Ch9;   use Exp_Ch9;
40 with Exp_Ch11;  use Exp_Ch11;
41 with Exp_Ch12;  use Exp_Ch12;
42 with Exp_Ch13;  use Exp_Ch13;
43 with Exp_Prag;  use Exp_Prag;
44 with Opt;       use Opt;
45 with Sem;       use Sem;
46 with Sem_Ch8;   use Sem_Ch8;
47 with Sem_Util;  use Sem_Util;
48 with Sinfo;     use Sinfo;
49 with Table;
50
51 package body Expander is
52
53    ----------------
54    -- Local Data --
55    ----------------
56
57    --  The following table is used to save values of the Expander_Active
58    --  flag when they are saved by Expander_Mode_Save_And_Set. We use an
59    --  extendible table (which is a bit of overkill) because it is easier
60    --  than figuring out a maximum value or bothering with range checks!
61
62    package Expander_Flags is new Table.Table (
63      Table_Component_Type => Boolean,
64      Table_Index_Type     => Int,
65      Table_Low_Bound      => 0,
66      Table_Initial        => 32,
67      Table_Increment      => 200,
68      Table_Name           => "Expander_Flags");
69
70    ------------
71    -- Expand --
72    ------------
73
74    procedure Expand (N : Node_Id) is
75    begin
76       --  If we were analyzing a default expression the Full_Analysis flag
77       --  must have be off. If we are in expansion mode then we must be
78       --  performing a full analysis. If we are analyzing a generic then
79       --  Expansion must be off.
80
81       pragma Assert
82         (not (Full_Analysis and then In_Default_Expression)
83          and then (Full_Analysis or else not Expander_Active)
84          and then not (Inside_A_Generic and then Expander_Active));
85
86       --  There are three reasons for the Expander_Active flag to be false.
87       --
88       --  The first is when are not generating code. In this mode the
89       --  Full_Analysis flag indicates whether we are performing a complete
90       --  analysis, in which case Full_Analysis = True or a pre-analysis in
91       --  which case Full_Analysis = False. See the spec of Sem for more
92       --  info on this.
93       --
94       --  The second reason for the Expander_Active flag to be False is that
95       --  we are performing a pre-analysis. During pre-analysis all
96       --  expansion activity is turned off to make sure nodes are
97       --  semantically decorated but no extra nodes are generated.  This is
98       --  for instance needed for the first pass of aggregate semantic
99       --  processing. Note that in this case the Full_Analysis flag is set
100       --  to False because the node will subsequently be re-analyzed with
101       --  expansion on (see the spec of sem).
102
103       --  Finally, expansion is turned off in a regular compilation if there
104       --  are serious errors. In that case there will be no further expansion,
105       --  but one cleanup action may be required: if a transient scope was
106       --  created (e.g. for a function that returns an unconstrained type)
107       --  the scope may still be on the stack, and must be removed explicitly,
108       --  given that the expansion actions that would normally process it will
109       --  not take place. This prevents cascaded errors due to stack mismatch.
110
111       if not Expander_Active then
112          Set_Analyzed (N, Full_Analysis);
113
114          if Serious_Errors_Detected > 0
115            and then Scope_Is_Transient
116          then
117             Scope_Stack.Table
118              (Scope_Stack.Last).Actions_To_Be_Wrapped_Before := No_List;
119             Scope_Stack.Table
120              (Scope_Stack.Last).Actions_To_Be_Wrapped_After  := No_List;
121
122             Pop_Scope;
123          end if;
124
125          return;
126
127       else
128          Debug_A_Entry ("expanding  ", N);
129
130          --  Processing depends on node kind. For full details on the expansion
131          --  activity required in each case, see bodies of corresponding
132          --  expand routines
133
134          case Nkind (N) is
135
136             when N_Abort_Statement =>
137                Expand_N_Abort_Statement (N);
138
139             when N_Accept_Statement =>
140                Expand_N_Accept_Statement (N);
141
142             when N_Aggregate =>
143                Expand_N_Aggregate (N);
144
145             when N_Allocator =>
146                Expand_N_Allocator (N);
147
148             when N_And_Then =>
149                Expand_N_And_Then (N);
150
151             when N_Assignment_Statement =>
152                Expand_N_Assignment_Statement (N);
153
154             when N_Asynchronous_Select =>
155                Expand_N_Asynchronous_Select (N);
156
157             when N_Attribute_Definition_Clause =>
158                Expand_N_Attribute_Definition_Clause (N);
159
160             when N_Attribute_Reference =>
161                Expand_N_Attribute_Reference (N);
162
163             when N_Block_Statement =>
164                Expand_N_Block_Statement (N);
165
166             when N_Case_Statement =>
167                Expand_N_Case_Statement (N);
168
169             when N_Conditional_Entry_Call =>
170                Expand_N_Conditional_Entry_Call (N);
171
172             when N_Conditional_Expression =>
173                Expand_N_Conditional_Expression (N);
174
175             when N_Delay_Relative_Statement =>
176                Expand_N_Delay_Relative_Statement (N);
177
178             when N_Delay_Until_Statement =>
179                Expand_N_Delay_Until_Statement (N);
180
181             when N_Entry_Body =>
182                Expand_N_Entry_Body (N);
183
184             when N_Entry_Call_Statement =>
185                Expand_N_Entry_Call_Statement (N);
186
187             when N_Entry_Declaration =>
188                Expand_N_Entry_Declaration (N);
189
190             when N_Exception_Declaration =>
191                Expand_N_Exception_Declaration (N);
192
193             when N_Exception_Renaming_Declaration =>
194                Expand_N_Exception_Renaming_Declaration (N);
195
196             when N_Exit_Statement =>
197                Expand_N_Exit_Statement (N);
198
199             when N_Expanded_Name =>
200                Expand_N_Expanded_Name (N);
201
202             when N_Explicit_Dereference =>
203                Expand_N_Explicit_Dereference (N);
204
205             when N_Extension_Aggregate =>
206                Expand_N_Extension_Aggregate (N);
207
208             when N_Freeze_Entity =>
209                Expand_N_Freeze_Entity (N);
210
211             when N_Full_Type_Declaration =>
212                Expand_N_Full_Type_Declaration (N);
213
214             when N_Function_Call =>
215                Expand_N_Function_Call (N);
216
217             when N_Generic_Instantiation =>
218                Expand_N_Generic_Instantiation (N);
219
220             when N_Goto_Statement =>
221                Expand_N_Goto_Statement (N);
222
223             when N_Handled_Sequence_Of_Statements =>
224                Expand_N_Handled_Sequence_Of_Statements (N);
225
226             when N_Identifier =>
227                Expand_N_Identifier (N);
228
229             when N_Indexed_Component =>
230                Expand_N_Indexed_Component (N);
231
232             when N_If_Statement =>
233                Expand_N_If_Statement (N);
234
235             when N_In =>
236                Expand_N_In (N);
237
238             when N_Loop_Statement =>
239                Expand_N_Loop_Statement (N);
240
241             when N_Not_In =>
242                Expand_N_Not_In (N);
243
244             when N_Null =>
245                Expand_N_Null (N);
246
247             when N_Object_Declaration =>
248                Expand_N_Object_Declaration (N);
249
250             when N_Object_Renaming_Declaration =>
251                Expand_N_Object_Renaming_Declaration (N);
252
253             when N_Op_Add =>
254                Expand_N_Op_Add (N);
255
256             when N_Op_Abs =>
257                Expand_N_Op_Abs (N);
258
259             when N_Op_And =>
260                Expand_N_Op_And (N);
261
262             when N_Op_Concat =>
263                Expand_N_Op_Concat (N);
264
265             when N_Op_Divide =>
266                Expand_N_Op_Divide (N);
267
268             when N_Op_Eq =>
269                Expand_N_Op_Eq (N);
270
271             when N_Op_Expon =>
272                Expand_N_Op_Expon (N);
273
274             when N_Op_Ge =>
275                Expand_N_Op_Ge (N);
276
277             when N_Op_Gt =>
278                Expand_N_Op_Gt (N);
279
280             when N_Op_Le =>
281                Expand_N_Op_Le (N);
282
283             when N_Op_Lt =>
284                Expand_N_Op_Lt (N);
285
286             when N_Op_Minus =>
287                Expand_N_Op_Minus (N);
288
289             when N_Op_Mod =>
290                Expand_N_Op_Mod (N);
291
292             when N_Op_Multiply =>
293                Expand_N_Op_Multiply (N);
294
295             when N_Op_Ne =>
296                Expand_N_Op_Ne (N);
297
298             when N_Op_Not =>
299                Expand_N_Op_Not (N);
300
301             when N_Op_Or =>
302                Expand_N_Op_Or (N);
303
304             when N_Op_Plus =>
305                Expand_N_Op_Plus (N);
306
307             when N_Op_Rem =>
308                Expand_N_Op_Rem (N);
309
310             when N_Op_Rotate_Left =>
311                Expand_N_Op_Rotate_Left (N);
312
313             when N_Op_Rotate_Right =>
314                Expand_N_Op_Rotate_Right (N);
315
316             when N_Op_Shift_Left =>
317                Expand_N_Op_Shift_Left (N);
318
319             when N_Op_Shift_Right =>
320                Expand_N_Op_Shift_Right (N);
321
322             when N_Op_Shift_Right_Arithmetic =>
323                Expand_N_Op_Shift_Right_Arithmetic (N);
324
325             when N_Op_Subtract =>
326                Expand_N_Op_Subtract (N);
327
328             when N_Op_Xor =>
329                Expand_N_Op_Xor (N);
330
331             when N_Or_Else =>
332                Expand_N_Or_Else (N);
333
334             when N_Package_Body =>
335                Expand_N_Package_Body (N);
336
337             when N_Package_Declaration =>
338                Expand_N_Package_Declaration (N);
339
340             when N_Package_Renaming_Declaration =>
341                Expand_N_Package_Renaming_Declaration (N);
342
343             when N_Pragma =>
344                Expand_N_Pragma (N);
345
346             when N_Procedure_Call_Statement =>
347                Expand_N_Procedure_Call_Statement (N);
348
349             when N_Protected_Type_Declaration =>
350                Expand_N_Protected_Type_Declaration (N);
351
352             when N_Protected_Body =>
353                Expand_N_Protected_Body (N);
354
355             when N_Qualified_Expression =>
356                Expand_N_Qualified_Expression (N);
357
358             when N_Raise_Statement =>
359                Expand_N_Raise_Statement (N);
360
361             when N_Raise_Constraint_Error =>
362                Expand_N_Raise_Constraint_Error (N);
363
364             when N_Raise_Program_Error =>
365                Expand_N_Raise_Program_Error (N);
366
367             when N_Raise_Storage_Error =>
368                Expand_N_Raise_Storage_Error (N);
369
370             when N_Real_Literal =>
371                Expand_N_Real_Literal (N);
372
373             when N_Record_Representation_Clause =>
374                Expand_N_Record_Representation_Clause (N);
375
376             when N_Requeue_Statement =>
377                Expand_N_Requeue_Statement (N);
378
379             when N_Return_Statement =>
380                Expand_N_Return_Statement (N);
381
382             when N_Selected_Component =>
383                Expand_N_Selected_Component (N);
384
385             when N_Selective_Accept =>
386                Expand_N_Selective_Accept (N);
387
388             when N_Single_Task_Declaration =>
389                Expand_N_Single_Task_Declaration (N);
390
391             when N_Slice =>
392                Expand_N_Slice (N);
393
394             when N_Subtype_Indication =>
395                Expand_N_Subtype_Indication (N);
396
397             when N_Subprogram_Body =>
398                Expand_N_Subprogram_Body (N);
399
400             when N_Subprogram_Body_Stub =>
401                Expand_N_Subprogram_Body_Stub (N);
402
403             when N_Subprogram_Declaration =>
404                Expand_N_Subprogram_Declaration (N);
405
406             when N_Subprogram_Info =>
407                Expand_N_Subprogram_Info (N);
408
409             when N_Task_Body =>
410                Expand_N_Task_Body (N);
411
412             when N_Task_Type_Declaration =>
413                Expand_N_Task_Type_Declaration (N);
414
415             when N_Timed_Entry_Call =>
416                Expand_N_Timed_Entry_Call (N);
417
418             when N_Type_Conversion =>
419                Expand_N_Type_Conversion (N);
420
421             when N_Unchecked_Expression =>
422                Expand_N_Unchecked_Expression (N);
423
424             when N_Unchecked_Type_Conversion =>
425                Expand_N_Unchecked_Type_Conversion (N);
426
427             when N_Variant_Part =>
428                Expand_N_Variant_Part (N);
429
430             --  For all other node kinds, no expansion activity is required
431
432             when others => null;
433
434          end case;
435
436          --  Set result as analyzed and then do a possible transient wrap. The
437          --  transient wrap must be done after the Analyzed flag is set on, so
438          --  that we do not get a recursive attempt to expand the node N.
439
440          Set_Analyzed (N);
441
442          --  Deal with transient scopes
443
444          if Scope_Is_Transient and then N = Node_To_Be_Wrapped then
445
446             case Nkind (N) is
447                when N_Statement_Other_Than_Procedure_Call |
448                     N_Procedure_Call_Statement            =>
449                   Wrap_Transient_Statement (N);
450
451                when N_Object_Declaration          |
452                     N_Object_Renaming_Declaration |
453                     N_Subtype_Declaration         =>
454                   Wrap_Transient_Declaration (N);
455
456                when others => Wrap_Transient_Expression (N);
457             end case;
458          end if;
459
460          Debug_A_Exit ("expanding  ", N, "  (done)");
461       end if;
462    end Expand;
463
464    ---------------------------
465    -- Expander_Mode_Restore --
466    ---------------------------
467
468    procedure Expander_Mode_Restore is
469    begin
470       Expander_Active := Expander_Flags.Table (Expander_Flags.Last);
471       Expander_Flags.Decrement_Last;
472
473       if Serious_Errors_Detected /= 0 then
474          Expander_Active := False;
475       end if;
476    end Expander_Mode_Restore;
477
478    --------------------------------
479    -- Expander_Mode_Save_And_Set --
480    --------------------------------
481
482    procedure Expander_Mode_Save_And_Set (Status : Boolean) is
483    begin
484       Expander_Flags.Increment_Last;
485       Expander_Flags.Table (Expander_Flags.Last) := Expander_Active;
486       Expander_Active := Status;
487    end Expander_Mode_Save_And_Set;
488
489 end Expander;