OSDN Git Service

Delete all lines containing "$Revision:".
[pf3gnuchains/gcc-fork.git] / gcc / ada / exp_intr.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             E X P _ I N T R                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 with Atree;    use Atree;
29 with Einfo;    use Einfo;
30 with Errout;   use Errout;
31 with Exp_Ch4;  use Exp_Ch4;
32 with Exp_Ch7;  use Exp_Ch7;
33 with Exp_Ch9;  use Exp_Ch9;
34 with Exp_Ch11; use Exp_Ch11;
35 with Exp_Code; use Exp_Code;
36 with Exp_Fixd; use Exp_Fixd;
37 with Exp_Util; use Exp_Util;
38 with Itypes;   use Itypes;
39 with Namet;    use Namet;
40 with Nmake;    use Nmake;
41 with Nlists;   use Nlists;
42 with Restrict; use Restrict;
43 with Rtsfind;  use Rtsfind;
44 with Sem;      use Sem;
45 with Sem_Eval; use Sem_Eval;
46 with Sem_Res;  use Sem_Res;
47 with Sem_Util; use Sem_Util;
48 with Sinfo;    use Sinfo;
49 with Sinput;   use Sinput;
50 with Snames;   use Snames;
51 with Stand;    use Stand;
52 with Stringt;  use Stringt;
53 with Tbuild;   use Tbuild;
54 with Uintp;    use Uintp;
55 with Urealp;   use Urealp;
56
57 package body Exp_Intr is
58
59    -----------------------
60    -- Local Subprograms --
61    -----------------------
62
63    procedure Expand_Is_Negative (N : Node_Id);
64    --  Expand a call to the intrinsic Is_Negative function
65
66    procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id);
67    --  Expand a call to Exception_Information/Message/Name. The first
68    --  parameter, N, is the node for the function call, and Ent is the
69    --  entity for the corresponding routine in the Ada.Exceptions package.
70
71    procedure Expand_Import_Call (N : Node_Id);
72    --  Expand a call to Import_Address/Longest_Integer/Value. The parameter
73    --  N is the node for the function call.
74
75    procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind);
76    --  Expand an intrinsic shift operation, N and E are from the call to
77    --  Expand_Instrinsic_Call (call node and subprogram spec entity) and
78    --  K is the kind for the shift node
79
80    procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id);
81    --  Expand a call to an instantiation of Unchecked_Convertion into a node
82    --  N_Unchecked_Type_Conversion.
83
84    procedure Expand_Unc_Deallocation (N : Node_Id);
85    --  Expand a call to an instantiation of Unchecked_Deallocation into a node
86    --  N_Free_Statement and appropriate context.
87
88    procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id);
89    --  Rewrite the node by the appropriate string or positive constant.
90    --  Nam can be one of the following:
91    --    Name_File             - expand string that is the name of source file
92    --    Name_Line             - expand integer line number
93    --    Name_Source_Location  - expand string of form file:line
94    --    Name_Enclosing_Entity - expand string  with name of enclosing entity
95
96    ---------------------------
97    -- Expand_Exception_Call --
98    ---------------------------
99
100    --  If the function call is not within an exception handler, then the
101    --  call is replaced by a null string. Otherwise the appropriate routine
102    --  in Ada.Exceptions is called passing the choice parameter specification
103    --  from the enclosing handler. If the enclosing handler lacks a choice
104    --  parameter, then one is supplied.
105
106    procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id) is
107       Loc : constant Source_Ptr := Sloc (N);
108       P   : Node_Id;
109       E   : Entity_Id;
110       S   : String_Id;
111
112    begin
113       --  Climb up parents to see if we are in exception handler
114
115       P := Parent (N);
116       loop
117          --  Case of not in exception handler
118
119          if No (P) then
120             Start_String;
121             S := End_String;
122             Rewrite (N,
123               Make_String_Literal (Loc,
124                 Strval => S));
125             exit;
126
127          --  Case of in exception handler
128
129          elsif Nkind (P) = N_Exception_Handler then
130             if No (Choice_Parameter (P)) then
131
132                --  If no choice parameter present, then put one there. Note
133                --  that we do not need to put it on the entity chain, since
134                --  no one will be referencing it by normal visibility methods.
135
136                E := Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
137                Set_Choice_Parameter (P, E);
138                Set_Ekind (E, E_Variable);
139                Set_Etype (E, RTE (RE_Exception_Occurrence));
140                Set_Scope (E, Current_Scope);
141             end if;
142
143             Rewrite (N,
144               Make_Function_Call (Loc,
145                 Name => New_Occurrence_Of (RTE (Ent), Loc),
146                 Parameter_Associations => New_List (
147                   New_Occurrence_Of (Choice_Parameter (P), Loc))));
148             exit;
149
150          --  Keep climbing!
151
152          else
153             P := Parent (P);
154          end if;
155       end loop;
156
157       Analyze_And_Resolve (N, Standard_String);
158    end Expand_Exception_Call;
159
160    ------------------------
161    -- Expand_Import_Call --
162    ------------------------
163
164    --  The function call must have a static string as its argument. We create
165    --  a dummy variable which uses this string as the external name in an
166    --  Import pragma. The result is then obtained as the address of this
167    --  dummy variable, converted to the appropriate target type.
168
169    procedure Expand_Import_Call (N : Node_Id) is
170       Loc : constant Source_Ptr := Sloc (N);
171       Ent : constant Entity_Id  := Entity (Name (N));
172       Str : constant Node_Id    := First_Actual (N);
173       Dum : Entity_Id;
174
175    begin
176       Dum := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
177
178       Insert_Actions (N, New_List (
179         Make_Object_Declaration (Loc,
180           Defining_Identifier => Dum,
181           Object_Definition   =>
182             New_Occurrence_Of (Standard_Character, Loc)),
183
184         Make_Pragma (Loc,
185           Chars => Name_Import,
186           Pragma_Argument_Associations => New_List (
187             Make_Pragma_Argument_Association (Loc,
188               Expression => Make_Identifier (Loc, Name_Ada)),
189
190             Make_Pragma_Argument_Association (Loc,
191               Expression => Make_Identifier (Loc, Chars (Dum))),
192
193             Make_Pragma_Argument_Association (Loc,
194               Chars => Name_Link_Name,
195               Expression => Relocate_Node (Str))))));
196
197       Rewrite (N,
198         Unchecked_Convert_To (Etype (Ent),
199           Make_Attribute_Reference (Loc,
200             Attribute_Name => Name_Address,
201             Prefix => Make_Identifier (Loc, Chars (Dum)))));
202
203       Analyze_And_Resolve (N, Etype (Ent));
204    end Expand_Import_Call;
205
206    ---------------------------
207    -- Expand_Intrinsic_Call --
208    ---------------------------
209
210    procedure Expand_Intrinsic_Call (N : Node_Id; E : Entity_Id) is
211       Nam : Name_Id;
212
213    begin
214       --  If the intrinsic subprogram is generic, gets its original name.
215
216       if Present (Parent (E))
217         and then Present (Generic_Parent (Parent (E)))
218       then
219          Nam := Chars (Generic_Parent (Parent (E)));
220       else
221          Nam := Chars (E);
222       end if;
223
224       if Nam = Name_Asm then
225          Expand_Asm_Call (N);
226
227       elsif Nam = Name_Divide then
228          Expand_Decimal_Divide_Call (N);
229
230       elsif Nam = Name_Exception_Information then
231          Expand_Exception_Call (N, RE_Exception_Information);
232
233       elsif Nam = Name_Exception_Message then
234          Expand_Exception_Call (N, RE_Exception_Message);
235
236       elsif Nam = Name_Exception_Name then
237          Expand_Exception_Call (N, RE_Exception_Name_Simple);
238
239       elsif Nam = Name_Import_Address
240               or else
241             Nam = Name_Import_Largest_Value
242               or else
243             Nam = Name_Import_Value
244       then
245          Expand_Import_Call (N);
246
247       elsif Nam = Name_Is_Negative then
248          Expand_Is_Negative (N);
249
250       elsif Nam = Name_Rotate_Left then
251          Expand_Shift (N, E, N_Op_Rotate_Left);
252
253       elsif Nam = Name_Rotate_Right then
254          Expand_Shift (N, E, N_Op_Rotate_Right);
255
256       elsif Nam = Name_Shift_Left then
257          Expand_Shift (N, E, N_Op_Shift_Left);
258
259       elsif Nam = Name_Shift_Right then
260          Expand_Shift (N, E, N_Op_Shift_Right);
261
262       elsif Nam = Name_Shift_Right_Arithmetic then
263          Expand_Shift (N, E, N_Op_Shift_Right_Arithmetic);
264
265       elsif Nam = Name_Unchecked_Conversion then
266          Expand_Unc_Conversion (N, E);
267
268       elsif Nam = Name_Unchecked_Deallocation then
269          Expand_Unc_Deallocation (N);
270
271       elsif Nam = Name_File
272         or else Nam = Name_Line
273         or else Nam = Name_Source_Location
274         or else Nam = Name_Enclosing_Entity
275       then
276          Expand_Source_Info (N, Nam);
277
278       else
279          --  Only other possibility is a renaming, in which case we expand
280          --  the call to the original operation (which must be intrinsic).
281
282          pragma Assert (Present (Alias (E)));
283          Expand_Intrinsic_Call (N,  Alias (E));
284       end if;
285
286    end Expand_Intrinsic_Call;
287
288    ------------------------
289    -- Expand_Is_Negative --
290    ------------------------
291
292    procedure Expand_Is_Negative (N : Node_Id) is
293       Loc   : constant Source_Ptr := Sloc (N);
294       Opnd  : constant Node_Id    := Relocate_Node (First_Actual (N));
295
296    begin
297
298       --  We replace the function call by the following expression
299
300       --    if Opnd < 0.0 then
301       --       True
302       --    else
303       --       if Opnd > 0.0 then
304       --          False;
305       --       else
306       --          Float_Unsigned!(Float (Opnd)) /= 0
307       --       end if;
308       --    end if;
309
310       Rewrite (N,
311         Make_Conditional_Expression (Loc,
312           Expressions => New_List (
313             Make_Op_Lt (Loc,
314               Left_Opnd  => Duplicate_Subexpr (Opnd),
315               Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
316
317             New_Occurrence_Of (Standard_True, Loc),
318
319             Make_Conditional_Expression (Loc,
320              Expressions => New_List (
321                Make_Op_Gt (Loc,
322                  Left_Opnd  => Duplicate_Subexpr (Opnd),
323                  Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
324
325                New_Occurrence_Of (Standard_False, Loc),
326
327                 Make_Op_Ne (Loc,
328                   Left_Opnd =>
329                     Unchecked_Convert_To (RTE (RE_Float_Unsigned),
330                                           Convert_To (Standard_Float,
331                                             Duplicate_Subexpr (Opnd))),
332                   Right_Opnd =>
333                     Make_Integer_Literal (Loc, 0)))))));
334
335       Analyze_And_Resolve (N, Standard_Boolean);
336    end Expand_Is_Negative;
337
338    ------------------
339    -- Expand_Shift --
340    ------------------
341
342    --  This procedure is used to convert a call to a shift function to the
343    --  corresponding operator node. This conversion is not done by the usual
344    --  circuit for converting calls to operator functions (e.g. "+"(1,2)) to
345    --  operator nodes, because shifts are not predefined operators.
346
347    --  As a result, whenever a shift is used in the source program, it will
348    --  remain as a call until converted by this routine to the operator node
349    --  form which Gigi is expecting to see.
350
351    --  Note: it is possible for the expander to generate shift operator nodes
352    --  directly, which will be analyzed in the normal manner by calling Analyze
353    --  and Resolve. Such shift operator nodes will not be seen by Expand_Shift.
354
355    procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind) is
356       Loc   : constant Source_Ptr := Sloc (N);
357       Typ   : constant Entity_Id  := Etype (N);
358       Left  : constant Node_Id    := First_Actual (N);
359       Right : constant Node_Id    := Next_Actual (Left);
360       Ltyp  : constant Node_Id    := Etype (Left);
361       Rtyp  : constant Node_Id    := Etype (Right);
362       Snode : Node_Id;
363
364    begin
365       Snode := New_Node (K, Loc);
366       Set_Left_Opnd  (Snode, Relocate_Node (Left));
367       Set_Right_Opnd (Snode, Relocate_Node (Right));
368       Set_Chars      (Snode, Chars (E));
369       Set_Etype      (Snode, Base_Type (Typ));
370       Set_Entity     (Snode, E);
371
372       if Compile_Time_Known_Value (Type_High_Bound (Rtyp))
373         and then Expr_Value (Type_High_Bound (Rtyp)) < Esize (Ltyp)
374       then
375          Set_Shift_Count_OK (Snode, True);
376       end if;
377
378       --  Do the rewrite. Note that we don't call Analyze and Resolve on
379       --  this node, because it already got analyzed and resolved when
380       --  it was a function call!
381
382       Rewrite (N, Snode);
383       Set_Analyzed (N);
384
385    end Expand_Shift;
386
387    ------------------------
388    -- Expand_Source_Info --
389    ------------------------
390
391    procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id) is
392       Loc : constant Source_Ptr := Sloc (N);
393       Ent : Entity_Id;
394
395    begin
396       --  Integer cases
397
398       if Nam = Name_Line then
399          Rewrite (N,
400            Make_Integer_Literal (Loc,
401              Intval => UI_From_Int (Int (Get_Logical_Line_Number (Loc)))));
402          Analyze_And_Resolve (N, Standard_Positive);
403
404       --  String cases
405
406       else
407          case Nam is
408             when Name_File =>
409                Get_Decoded_Name_String
410                  (Reference_Name (Get_Source_File_Index (Loc)));
411
412             when Name_Source_Location =>
413                Build_Location_String (Loc);
414
415             when Name_Enclosing_Entity =>
416                Name_Len := 0;
417
418                Ent := Current_Scope;
419
420                --  Skip enclosing blocks to reach enclosing unit.
421
422                while Present (Ent) loop
423                   exit when Ekind (Ent) /= E_Block
424                     and then Ekind (Ent) /= E_Loop;
425                   Ent := Scope (Ent);
426                end loop;
427
428                --  Ent now points to the relevant defining entity
429
430                declare
431                   SDef : Source_Ptr := Sloc (Ent);
432                   TDef : Source_Buffer_Ptr;
433
434                begin
435                   TDef := Source_Text (Get_Source_File_Index (SDef));
436                   Name_Len := 0;
437
438                   while TDef (SDef) in '0' .. '9'
439                     or else TDef (SDef) >= 'A'
440                     or else TDef (SDef) = ASCII.ESC
441                   loop
442                      Add_Char_To_Name_Buffer (TDef (SDef));
443                      SDef := SDef + 1;
444                   end loop;
445                end;
446
447             when others =>
448                raise Program_Error;
449          end case;
450
451          Rewrite (N,
452            Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
453          Analyze_And_Resolve (N, Standard_String);
454       end if;
455
456       Set_Is_Static_Expression (N);
457    end Expand_Source_Info;
458
459    ---------------------------
460    -- Expand_Unc_Conversion --
461    ---------------------------
462
463    procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id) is
464       Func : constant Entity_Id  := Entity (Name (N));
465       Conv : Node_Id;
466       Ftyp : Entity_Id;
467
468    begin
469       --  Rewrite as unchecked conversion node. Note that we must convert
470       --  the operand to the formal type of the input parameter of the
471       --  function, so that the resulting N_Unchecked_Type_Conversion
472       --  call indicates the correct types for Gigi.
473
474       --  Right now, we only do this if a scalar type is involved. It is
475       --  not clear if it is needed in other cases. If we do attempt to
476       --  do the conversion unconditionally, it crashes 3411-018. To be
477       --  investigated further ???
478
479       Conv := Relocate_Node (First_Actual (N));
480       Ftyp := Etype (First_Formal (Func));
481
482       if Is_Scalar_Type (Ftyp) then
483          Conv := Convert_To (Ftyp, Conv);
484          Set_Parent (Conv, N);
485          Analyze_And_Resolve (Conv);
486       end if;
487
488       --  We do the analysis here, because we do not want the compiler
489       --  to try to optimize or otherwise reorganize the unchecked
490       --  conversion node.
491
492       Rewrite (N, Unchecked_Convert_To (Etype (E), Conv));
493       Set_Etype (N, Etype (E));
494       Set_Analyzed (N);
495
496       if Nkind (N) = N_Unchecked_Type_Conversion then
497          Expand_N_Unchecked_Type_Conversion (N);
498       end if;
499    end Expand_Unc_Conversion;
500
501    -----------------------------
502    -- Expand_Unc_Deallocation --
503    -----------------------------
504
505    --  Generate the following Code :
506
507    --    if Arg /= null then
508    --     <Finalize_Call> (.., T'Class(Arg.all), ..);  -- for controlled types
509    --       Free (Arg);
510    --       Arg := Null;
511    --    end if;
512
513    --  For a task, we also generate a call to Free_Task to ensure that the
514    --  task itself is freed if it is terminated, ditto for a simple protected
515    --  object, with a call to Finalize_Protection
516
517    procedure Expand_Unc_Deallocation (N : Node_Id) is
518       Loc   : constant Source_Ptr := Sloc (N);
519       Arg   : constant Node_Id    := First_Actual (N);
520       Typ   : constant Entity_Id  := Etype (Arg);
521       Stmts : constant List_Id    := New_List;
522       Pool  : constant Entity_Id  :=
523                 Associated_Storage_Pool (Underlying_Type (Root_Type (Typ)));
524
525       Desig_T   : Entity_Id  := Designated_Type (Typ);
526       Gen_Code  : Node_Id;
527       Free_Node : Node_Id;
528       Deref     : Node_Id;
529       Free_Arg  : Node_Id;
530       Free_Cod  : List_Id;
531       Blk       : Node_Id;
532
533    begin
534       if Controlled_Type (Desig_T) then
535
536          Deref := Make_Explicit_Dereference (Loc, Duplicate_Subexpr (Arg));
537
538          --  If the type is tagged, then we must force dispatching on the
539          --  finalization call because the designated type may not be the
540          --  actual type of the object
541
542          if Is_Tagged_Type (Desig_T)
543            and then not Is_Class_Wide_Type (Desig_T)
544          then
545             Deref := Unchecked_Convert_To (Class_Wide_Type (Desig_T), Deref);
546          end if;
547
548          Free_Cod :=
549            Make_Final_Call
550             (Ref         => Deref,
551              Typ         => Desig_T,
552              With_Detach => New_Reference_To (Standard_True, Loc));
553
554          if Abort_Allowed then
555             Prepend_To (Free_Cod,
556               Build_Runtime_Call (Loc, RE_Abort_Defer));
557
558             Blk :=
559               Make_Block_Statement (Loc, Handled_Statement_Sequence =>
560                 Make_Handled_Sequence_Of_Statements (Loc,
561                   Statements  => Free_Cod,
562                   At_End_Proc =>
563                     New_Occurrence_Of (RTE (RE_Abort_Undefer_Direct), Loc)));
564
565             --  We now expand the exception (at end) handler. We set a
566             --  temporary parent pointer since we have not attached Blk
567             --  to the tree yet.
568
569             Set_Parent (Blk, N);
570             Analyze (Blk);
571             Expand_At_End_Handler
572               (Handled_Statement_Sequence (Blk), Entity (Identifier (Blk)));
573             Append (Blk, Stmts);
574
575          else
576             Append_List_To (Stmts, Free_Cod);
577          end if;
578       end if;
579
580       --  For a task type, call Free_Task before freeing the ATCB.
581
582       if Is_Task_Type (Desig_T) then
583
584          declare
585             Stat : Node_Id := Prev (N);
586             Nam1 : Node_Id;
587             Nam2 : Node_Id;
588
589          begin
590             --  An Abort followed by a Free will not do what the user
591             --  expects, because the abort is not immediate. This is worth
592             --  a friendly warning.
593
594             while Present (Stat)
595               and then not Comes_From_Source (Original_Node (Stat))
596             loop
597                Prev (Stat);
598             end loop;
599
600             if Present (Stat)
601               and then Nkind (Original_Node (Stat)) = N_Abort_Statement
602             then
603                Stat := Original_Node (Stat);
604                Nam1 := First (Names (Stat));
605                Nam2 := Original_Node (First (Parameter_Associations (N)));
606
607                if Nkind (Nam1) = N_Explicit_Dereference
608                  and then Is_Entity_Name (Prefix (Nam1))
609                  and then Is_Entity_Name (Nam2)
610                  and then Entity (Prefix (Nam1)) = Entity (Nam2)
611                then
612                   Error_Msg_N ("Abort may take time to complete?", N);
613                   Error_Msg_N ("\deallocation might have no effect?", N);
614                   Error_Msg_N ("\safer to wait for termination.?", N);
615                end if;
616             end if;
617          end;
618
619          Append_To (Stmts,
620            Make_Procedure_Call_Statement (Loc,
621              Name => New_Reference_To (RTE (RE_Free_Task), Loc),
622              Parameter_Associations => New_List (
623                Concurrent_Ref (Duplicate_Subexpr (Arg)))));
624       end if;
625
626       --  For a protected type with no entries, call Finalize_Protection
627       --  before freeing the PO.
628
629       if Is_Protected_Type (Desig_T) and then not Has_Entries (Desig_T) then
630          Append_To (Stmts,
631            Make_Procedure_Call_Statement (Loc,
632              Name => New_Reference_To (RTE (RE_Finalize_Protection), Loc),
633              Parameter_Associations => New_List (
634                Concurrent_Ref (Duplicate_Subexpr (Arg)))));
635       end if;
636
637       --  Normal processing for non-controlled types
638
639       Free_Arg := Duplicate_Subexpr (Arg);
640       Free_Node := Make_Free_Statement (Loc, Empty);
641       Append_To (Stmts, Free_Node);
642       Set_Storage_Pool (Free_Node, Pool);
643
644       --  Make implicit if statement. We omit this if we are the then part
645       --  of a test of the form:
646
647       --    if not (Arg = null) then
648
649       --  i.e. if the test is explicit in the source. Arg must be a simple
650       --  identifier for the purposes of this special test. Note that the
651       --  use of /= in the source is always transformed into the above form.
652
653       declare
654          Test_Needed : Boolean := True;
655          P           : constant Node_Id := Parent (N);
656          C           : Node_Id;
657
658       begin
659          if Nkind (Arg) = N_Identifier
660            and then Nkind (P) =  N_If_Statement
661            and then First (Then_Statements (P)) = N
662          then
663             if Nkind (Condition (P)) = N_Op_Not then
664                C := Right_Opnd (Condition (P));
665
666                if Nkind (C) = N_Op_Eq
667                  and then Nkind (Left_Opnd (C)) = N_Identifier
668                  and then Chars (Arg) = Chars (Left_Opnd (C))
669                  and then Nkind (Right_Opnd (C)) = N_Null
670                then
671                   Test_Needed := False;
672                end if;
673             end if;
674          end if;
675
676          --  Generate If_Statement if needed
677
678          if Test_Needed then
679             Gen_Code :=
680               Make_Implicit_If_Statement (N,
681                 Condition =>
682                   Make_Op_Ne (Loc,
683                     Left_Opnd  => Duplicate_Subexpr (Arg),
684                     Right_Opnd => Make_Null (Loc)),
685                 Then_Statements => Stmts);
686
687          else
688             Gen_Code :=
689               Make_Block_Statement (Loc,
690                 Handled_Statement_Sequence =>
691                   Make_Handled_Sequence_Of_Statements (Loc,
692                     Statements => Stmts));
693          end if;
694       end;
695
696       --  Deal with storage pool
697
698       if Present (Pool) then
699
700          --  Freeing the secondary stack is meaningless
701
702          if Is_RTE (Pool, RE_SS_Pool) then
703             null;
704
705          else
706             Set_Procedure_To_Call (Free_Node,
707               Find_Prim_Op (Etype (Pool), Name_Deallocate));
708
709             --  If the type is class wide, we generate an implicit type
710             --  with the right dynamic size, so that the deallocate call
711             --  gets the right size parameter computed by gigi
712
713             if Is_Class_Wide_Type (Desig_T) then
714                declare
715                   Acc_Type : constant Entity_Id :=
716                                Create_Itype (E_Access_Type, N);
717                   Deref    : constant Node_Id :=
718                                Make_Explicit_Dereference (Loc,
719                                  Duplicate_Subexpr (Arg));
720
721                begin
722                   Set_Etype  (Deref, Typ);
723                   Set_Parent (Deref, Free_Node);
724
725                   Set_Etype     (Acc_Type, Acc_Type);
726                   Set_Size_Info (Acc_Type, Typ);
727                   Set_Directly_Designated_Type
728                                 (Acc_Type, Entity (Make_Subtype_From_Expr
729                                                     (Deref, Desig_T)));
730
731                   Free_Arg := Unchecked_Convert_To (Acc_Type, Free_Arg);
732                end;
733             end if;
734          end if;
735       end if;
736
737       Set_Expression (Free_Node, Free_Arg);
738
739       declare
740          Lhs : Node_Id := Duplicate_Subexpr (Arg);
741
742       begin
743          Set_Assignment_OK (Lhs);
744          Append_To (Stmts,
745            Make_Assignment_Statement (Loc,
746              Name       => Lhs,
747              Expression => Make_Null (Loc)));
748       end;
749
750       Rewrite (N, Gen_Code);
751       Analyze (N);
752    end Expand_Unc_Deallocation;
753
754 end Exp_Intr;