OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [expander.adb] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.