2014-12-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / exp_intr.adb
blobe8efe03348cb45baafddeb5d2a6bc75091269ec0
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ I N T R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Expander; use Expander;
32 with Exp_Atag; use Exp_Atag;
33 with Exp_Ch4; use Exp_Ch4;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Code; use Exp_Code;
37 with Exp_Fixd; use Exp_Fixd;
38 with Exp_Util; use Exp_Util;
39 with Freeze; use Freeze;
40 with Nmake; use Nmake;
41 with Nlists; use Nlists;
42 with Opt; use Opt;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
46 with Sem; use Sem;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sem_Util; use Sem_Util;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Stringt; use Stringt;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Uintp; use Uintp;
60 with Urealp; use Urealp;
62 package body Exp_Intr is
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 procedure Expand_Binary_Operator_Call (N : Node_Id);
69 -- Expand a call to an intrinsic arithmetic operator when the operand
70 -- types or sizes are not identical.
72 procedure Expand_Is_Negative (N : Node_Id);
73 -- Expand a call to the intrinsic Is_Negative function
75 procedure Expand_Dispatching_Constructor_Call (N : Node_Id);
76 -- Expand a call to an instantiation of Generic_Dispatching_Constructor
77 -- into a dispatching call to the actual subprogram associated with the
78 -- Constructor formal subprogram, passing it the Parameters actual of
79 -- the call to the instantiation and dispatching based on call's Tag
80 -- parameter.
82 procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id);
83 -- Expand a call to Exception_Information/Message/Name. The first
84 -- parameter, N, is the node for the function call, and Ent is the
85 -- entity for the corresponding routine in the Ada.Exceptions package.
87 procedure Expand_Import_Call (N : Node_Id);
88 -- Expand a call to Import_Address/Longest_Integer/Value. The parameter
89 -- N is the node for the function call.
91 procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind);
92 -- Expand an intrinsic shift operation, N and E are from the call to
93 -- Expand_Intrinsic_Call (call node and subprogram spec entity) and
94 -- K is the kind for the shift node
96 procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id);
97 -- Expand a call to an instantiation of Unchecked_Conversion into a node
98 -- N_Unchecked_Type_Conversion.
100 procedure Expand_Unc_Deallocation (N : Node_Id);
101 -- Expand a call to an instantiation of Unchecked_Deallocation into a node
102 -- N_Free_Statement and appropriate context.
104 procedure Expand_To_Address (N : Node_Id);
105 procedure Expand_To_Pointer (N : Node_Id);
106 -- Expand a call to corresponding function, declared in an instance of
107 -- System.Address_To_Access_Conversions.
109 procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id);
110 -- Rewrite the node by the appropriate string or positive constant.
111 -- Nam can be one of the following:
112 -- Name_File - expand string name of source file
113 -- Name_Line - expand integer line number
114 -- Name_Source_Location - expand string of form file:line
115 -- Name_Enclosing_Entity - expand string name of enclosing entity
116 -- Name_Compilation_Date - expand string with compilation date
117 -- Name_Compilation_Time - expand string with compilation time
119 procedure Write_Entity_Name (E : Entity_Id);
120 -- Recursive procedure to construct string for qualified name of enclosing
121 -- program unit. The qualification stops at an enclosing scope has no
122 -- source name (block or loop). If entity is a subprogram instance, skip
123 -- enclosing wrapper package. The name is appended to the current contents
124 -- of Name_Buffer, incrementing Name_Len.
126 ---------------------
127 -- Add_Source_Info --
128 ---------------------
130 procedure Add_Source_Info (Loc : Source_Ptr; Nam : Name_Id) is
131 Ent : Entity_Id;
133 Save_NB : constant String := Name_Buffer (1 .. Name_Len);
134 Save_NL : constant Natural := Name_Len;
135 -- Save current Name_Buffer contents
137 begin
138 Name_Len := 0;
140 -- Line
142 case Nam is
144 when Name_Line =>
145 Add_Nat_To_Name_Buffer (Nat (Get_Logical_Line_Number (Loc)));
147 when Name_File =>
148 Get_Decoded_Name_String
149 (Reference_Name (Get_Source_File_Index (Loc)));
151 when Name_Source_Location =>
152 Build_Location_String (Loc);
154 when Name_Enclosing_Entity =>
156 -- Skip enclosing blocks to reach enclosing unit
158 Ent := Current_Scope;
159 while Present (Ent) loop
160 exit when not Ekind_In (Ent, E_Block, E_Loop);
161 Ent := Scope (Ent);
162 end loop;
164 -- Ent now points to the relevant defining entity
166 Write_Entity_Name (Ent);
168 when Name_Compilation_Date =>
169 declare
170 subtype S13 is String (1 .. 3);
171 Months : constant array (1 .. 12) of S13 :=
172 ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
173 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
175 M1 : constant Character := Opt.Compilation_Time (6);
176 M2 : constant Character := Opt.Compilation_Time (7);
178 MM : constant Natural range 1 .. 12 :=
179 (Character'Pos (M1) - Character'Pos ('0')) * 10 +
180 (Character'Pos (M2) - Character'Pos ('0'));
182 begin
183 -- Reformat ISO date into MMM DD YYYY (__DATE__) format
185 Name_Buffer (1 .. 3) := Months (MM);
186 Name_Buffer (4) := ' ';
187 Name_Buffer (5 .. 6) := Opt.Compilation_Time (9 .. 10);
188 Name_Buffer (7) := ' ';
189 Name_Buffer (8 .. 11) := Opt.Compilation_Time (1 .. 4);
190 Name_Len := 11;
191 end;
193 when Name_Compilation_Time =>
194 Name_Buffer (1 .. 8) := Opt.Compilation_Time (12 .. 19);
195 Name_Len := 8;
197 when others =>
198 raise Program_Error;
199 end case;
201 -- Prepend original Name_Buffer contents
203 Name_Buffer (Save_NL + 1 .. Save_NL + Name_Len) :=
204 Name_Buffer (1 .. Name_Len);
205 Name_Buffer (1 .. Save_NL) := Save_NB;
206 Name_Len := Name_Len + Save_NL;
207 end Add_Source_Info;
209 ---------------------------------
210 -- Expand_Binary_Operator_Call --
211 ---------------------------------
213 procedure Expand_Binary_Operator_Call (N : Node_Id) is
214 T1 : constant Entity_Id := Underlying_Type (Etype (Left_Opnd (N)));
215 T2 : constant Entity_Id := Underlying_Type (Etype (Right_Opnd (N)));
216 TR : constant Entity_Id := Etype (N);
217 T3 : Entity_Id;
218 Res : Node_Id;
220 Siz : constant Uint := UI_Max (RM_Size (T1), RM_Size (T2));
221 -- Maximum of operand sizes
223 begin
224 -- Nothing to do if the operands have the same modular type
226 if Base_Type (T1) = Base_Type (T2)
227 and then Is_Modular_Integer_Type (T1)
228 then
229 return;
230 end if;
232 -- Use Unsigned_32 for sizes of 32 or below, else Unsigned_64
234 if Siz > 32 then
235 T3 := RTE (RE_Unsigned_64);
236 else
237 T3 := RTE (RE_Unsigned_32);
238 end if;
240 -- Copy operator node, and reset type and entity fields, for
241 -- subsequent reanalysis.
243 Res := New_Copy (N);
244 Set_Etype (Res, T3);
246 case Nkind (N) is
247 when N_Op_And =>
248 Set_Entity (Res, Standard_Op_And);
249 when N_Op_Or =>
250 Set_Entity (Res, Standard_Op_Or);
251 when N_Op_Xor =>
252 Set_Entity (Res, Standard_Op_Xor);
253 when others =>
254 raise Program_Error;
255 end case;
257 -- Convert operands to large enough intermediate type
259 Set_Left_Opnd (Res,
260 Unchecked_Convert_To (T3, Relocate_Node (Left_Opnd (N))));
261 Set_Right_Opnd (Res,
262 Unchecked_Convert_To (T3, Relocate_Node (Right_Opnd (N))));
264 -- Analyze and resolve result formed by conversion to target type
266 Rewrite (N, Unchecked_Convert_To (TR, Res));
267 Analyze_And_Resolve (N, TR);
268 end Expand_Binary_Operator_Call;
270 -----------------------------------------
271 -- Expand_Dispatching_Constructor_Call --
272 -----------------------------------------
274 -- Transform a call to an instantiation of Generic_Dispatching_Constructor
275 -- of the form:
277 -- GDC_Instance (The_Tag, Parameters'Access)
279 -- to a class-wide conversion of a dispatching call to the actual
280 -- associated with the formal subprogram Construct, designating The_Tag
281 -- as the controlling tag of the call:
283 -- T'Class (Construct'Actual (Params)) -- Controlling tag is The_Tag
285 -- which will eventually be expanded to the following:
287 -- T'Class (The_Tag.all (Construct'Actual'Index).all (Params))
289 -- A class-wide membership test is also generated, preceding the call, to
290 -- ensure that the controlling tag denotes a type in T'Class.
292 procedure Expand_Dispatching_Constructor_Call (N : Node_Id) is
293 Loc : constant Source_Ptr := Sloc (N);
294 Tag_Arg : constant Node_Id := First_Actual (N);
295 Param_Arg : constant Node_Id := Next_Actual (Tag_Arg);
296 Subp_Decl : constant Node_Id := Parent (Parent (Entity (Name (N))));
297 Inst_Pkg : constant Node_Id := Parent (Subp_Decl);
298 Act_Rename : Node_Id;
299 Act_Constr : Entity_Id;
300 Iface_Tag : Node_Id := Empty;
301 Cnstr_Call : Node_Id;
302 Result_Typ : Entity_Id;
304 begin
305 -- Remove side effects from tag argument early, before rewriting
306 -- the dispatching constructor call, as Remove_Side_Effects relies
307 -- on Tag_Arg's Parent link properly attached to the tree (once the
308 -- call is rewritten, the Parent is inconsistent as it points to the
309 -- rewritten node, which is not the syntactic parent of the Tag_Arg
310 -- anymore).
312 Remove_Side_Effects (Tag_Arg);
314 -- The subprogram is the third actual in the instantiation, and is
315 -- retrieved from the corresponding renaming declaration. However,
316 -- freeze nodes may appear before, so we retrieve the declaration
317 -- with an explicit loop.
319 Act_Rename := First (Visible_Declarations (Inst_Pkg));
320 while Nkind (Act_Rename) /= N_Subprogram_Renaming_Declaration loop
321 Next (Act_Rename);
322 end loop;
324 Act_Constr := Entity (Name (Act_Rename));
325 Result_Typ := Class_Wide_Type (Etype (Act_Constr));
327 if Is_Interface (Etype (Act_Constr)) then
329 -- If the result type is not known to be a parent of Tag_Arg then we
330 -- need to locate the tag of the secondary dispatch table.
332 if not Is_Ancestor (Etype (Result_Typ), Etype (Tag_Arg),
333 Use_Full_View => True)
334 and then Tagged_Type_Expansion
335 then
336 -- Obtain the reference to the Ada.Tags service before generating
337 -- the Object_Declaration node to ensure that if this service is
338 -- not available in the runtime then we generate a clear error.
340 declare
341 Fname : constant Node_Id :=
342 New_Occurrence_Of (RTE (RE_Secondary_Tag), Loc);
344 begin
345 pragma Assert (not Is_Interface (Etype (Tag_Arg)));
347 Iface_Tag :=
348 Make_Object_Declaration (Loc,
349 Defining_Identifier => Make_Temporary (Loc, 'V'),
350 Object_Definition =>
351 New_Occurrence_Of (RTE (RE_Tag), Loc),
352 Expression =>
353 Make_Function_Call (Loc,
354 Name => Fname,
355 Parameter_Associations => New_List (
356 Relocate_Node (Tag_Arg),
357 New_Occurrence_Of
358 (Node (First_Elmt (Access_Disp_Table
359 (Etype (Etype (Act_Constr))))),
360 Loc))));
361 Insert_Action (N, Iface_Tag);
362 end;
363 end if;
364 end if;
366 -- Create the call to the actual Constructor function
368 Cnstr_Call :=
369 Make_Function_Call (Loc,
370 Name => New_Occurrence_Of (Act_Constr, Loc),
371 Parameter_Associations => New_List (Relocate_Node (Param_Arg)));
373 -- Establish its controlling tag from the tag passed to the instance
374 -- The tag may be given by a function call, in which case a temporary
375 -- should be generated now, to prevent out-of-order insertions during
376 -- the expansion of that call when stack-checking is enabled.
378 if Present (Iface_Tag) then
379 Set_Controlling_Argument (Cnstr_Call,
380 New_Occurrence_Of (Defining_Identifier (Iface_Tag), Loc));
381 else
382 Set_Controlling_Argument (Cnstr_Call,
383 Relocate_Node (Tag_Arg));
384 end if;
386 -- Rewrite and analyze the call to the instance as a class-wide
387 -- conversion of the call to the actual constructor.
389 Rewrite (N, Convert_To (Result_Typ, Cnstr_Call));
390 Analyze_And_Resolve (N, Etype (Act_Constr));
392 -- Do not generate a run-time check on the built object if tag
393 -- checks are suppressed for the result type or VM_Target /= No_VM
395 if Tag_Checks_Suppressed (Etype (Result_Typ))
396 or else not Tagged_Type_Expansion
397 then
398 null;
400 -- Generate a class-wide membership test to ensure that the call's tag
401 -- argument denotes a type within the class. We must keep separate the
402 -- case in which the Result_Type of the constructor function is a tagged
403 -- type from the case in which it is an abstract interface because the
404 -- run-time subprogram required to check these cases differ (and have
405 -- one difference in their parameters profile).
407 -- Call CW_Membership if the Result_Type is a tagged type to look for
408 -- the tag in the table of ancestor tags.
410 elsif not Is_Interface (Result_Typ) then
411 declare
412 Obj_Tag_Node : Node_Id := New_Copy_Tree (Tag_Arg);
413 CW_Test_Node : Node_Id;
415 begin
416 Build_CW_Membership (Loc,
417 Obj_Tag_Node => Obj_Tag_Node,
418 Typ_Tag_Node =>
419 New_Occurrence_Of (
420 Node (First_Elmt (Access_Disp_Table (
421 Root_Type (Result_Typ)))), Loc),
422 Related_Nod => N,
423 New_Node => CW_Test_Node);
425 Insert_Action (N,
426 Make_Implicit_If_Statement (N,
427 Condition =>
428 Make_Op_Not (Loc, CW_Test_Node),
429 Then_Statements =>
430 New_List (Make_Raise_Statement (Loc,
431 New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
432 end;
434 -- Call IW_Membership test if the Result_Type is an abstract interface
435 -- to look for the tag in the table of interface tags.
437 else
438 Insert_Action (N,
439 Make_Implicit_If_Statement (N,
440 Condition =>
441 Make_Op_Not (Loc,
442 Make_Function_Call (Loc,
443 Name => New_Occurrence_Of (RTE (RE_IW_Membership), Loc),
444 Parameter_Associations => New_List (
445 Make_Attribute_Reference (Loc,
446 Prefix => New_Copy_Tree (Tag_Arg),
447 Attribute_Name => Name_Address),
449 New_Occurrence_Of (
450 Node (First_Elmt (Access_Disp_Table (
451 Root_Type (Result_Typ)))), Loc)))),
452 Then_Statements =>
453 New_List (
454 Make_Raise_Statement (Loc,
455 Name => New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
456 end if;
457 end Expand_Dispatching_Constructor_Call;
459 ---------------------------
460 -- Expand_Exception_Call --
461 ---------------------------
463 -- If the function call is not within an exception handler, then the call
464 -- is replaced by a null string. Otherwise the appropriate routine in
465 -- Ada.Exceptions is called passing the choice parameter specification
466 -- from the enclosing handler. If the enclosing handler lacks a choice
467 -- parameter, then one is supplied.
469 procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id) is
470 Loc : constant Source_Ptr := Sloc (N);
471 P : Node_Id;
472 E : Entity_Id;
474 begin
475 -- Climb up parents to see if we are in exception handler
477 P := Parent (N);
478 loop
479 -- Case of not in exception handler, replace by null string
481 if No (P) then
482 Rewrite (N,
483 Make_String_Literal (Loc,
484 Strval => ""));
485 exit;
487 -- Case of in exception handler
489 elsif Nkind (P) = N_Exception_Handler then
491 -- Handler cannot be used for a local raise, and furthermore, this
492 -- is a violation of the No_Exception_Propagation restriction.
494 Set_Local_Raise_Not_OK (P);
495 Check_Restriction (No_Exception_Propagation, N);
497 -- If no choice parameter present, then put one there. Note that
498 -- we do not need to put it on the entity chain, since no one will
499 -- be referencing it by normal visibility methods.
501 if No (Choice_Parameter (P)) then
502 E := Make_Temporary (Loc, 'E');
503 Set_Choice_Parameter (P, E);
504 Set_Ekind (E, E_Variable);
505 Set_Etype (E, RTE (RE_Exception_Occurrence));
506 Set_Scope (E, Current_Scope);
507 end if;
509 Rewrite (N,
510 Make_Function_Call (Loc,
511 Name => New_Occurrence_Of (RTE (Ent), Loc),
512 Parameter_Associations => New_List (
513 New_Occurrence_Of (Choice_Parameter (P), Loc))));
514 exit;
516 -- Keep climbing
518 else
519 P := Parent (P);
520 end if;
521 end loop;
523 Analyze_And_Resolve (N, Standard_String);
524 end Expand_Exception_Call;
526 ------------------------
527 -- Expand_Import_Call --
528 ------------------------
530 -- The function call must have a static string as its argument. We create
531 -- a dummy variable which uses this string as the external name in an
532 -- Import pragma. The result is then obtained as the address of this
533 -- dummy variable, converted to the appropriate target type.
535 procedure Expand_Import_Call (N : Node_Id) is
536 Loc : constant Source_Ptr := Sloc (N);
537 Ent : constant Entity_Id := Entity (Name (N));
538 Str : constant Node_Id := First_Actual (N);
539 Dum : constant Entity_Id := Make_Temporary (Loc, 'D');
541 begin
542 Insert_Actions (N, New_List (
543 Make_Object_Declaration (Loc,
544 Defining_Identifier => Dum,
545 Object_Definition =>
546 New_Occurrence_Of (Standard_Character, Loc)),
548 Make_Pragma (Loc,
549 Chars => Name_Import,
550 Pragma_Argument_Associations => New_List (
551 Make_Pragma_Argument_Association (Loc,
552 Expression => Make_Identifier (Loc, Name_Ada)),
554 Make_Pragma_Argument_Association (Loc,
555 Expression => Make_Identifier (Loc, Chars (Dum))),
557 Make_Pragma_Argument_Association (Loc,
558 Chars => Name_Link_Name,
559 Expression => Relocate_Node (Str))))));
561 Rewrite (N,
562 Unchecked_Convert_To (Etype (Ent),
563 Make_Attribute_Reference (Loc,
564 Prefix => Make_Identifier (Loc, Chars (Dum)),
565 Attribute_Name => Name_Address)));
567 Analyze_And_Resolve (N, Etype (Ent));
568 end Expand_Import_Call;
570 ---------------------------
571 -- Expand_Intrinsic_Call --
572 ---------------------------
574 procedure Expand_Intrinsic_Call (N : Node_Id; E : Entity_Id) is
575 Nam : Name_Id;
577 begin
578 -- If an external name is specified for the intrinsic, it is handled
579 -- by the back-end: leave the call node unchanged for now.
581 if Present (Interface_Name (E)) then
582 return;
583 end if;
585 -- If the intrinsic subprogram is generic, gets its original name
587 if Present (Parent (E))
588 and then Present (Generic_Parent (Parent (E)))
589 then
590 Nam := Chars (Generic_Parent (Parent (E)));
591 else
592 Nam := Chars (E);
593 end if;
595 if Nam = Name_Asm then
596 Expand_Asm_Call (N);
598 elsif Nam = Name_Divide then
599 Expand_Decimal_Divide_Call (N);
601 elsif Nam = Name_Exception_Information then
602 Expand_Exception_Call (N, RE_Exception_Information);
604 elsif Nam = Name_Exception_Message then
605 Expand_Exception_Call (N, RE_Exception_Message);
607 elsif Nam = Name_Exception_Name then
608 Expand_Exception_Call (N, RE_Exception_Name_Simple);
610 elsif Nam = Name_Generic_Dispatching_Constructor then
611 Expand_Dispatching_Constructor_Call (N);
613 elsif Nam_In (Nam, Name_Import_Address,
614 Name_Import_Largest_Value,
615 Name_Import_Value)
616 then
617 Expand_Import_Call (N);
619 elsif Nam = Name_Is_Negative then
620 Expand_Is_Negative (N);
622 elsif Nam = Name_Rotate_Left then
623 Expand_Shift (N, E, N_Op_Rotate_Left);
625 elsif Nam = Name_Rotate_Right then
626 Expand_Shift (N, E, N_Op_Rotate_Right);
628 elsif Nam = Name_Shift_Left then
629 Expand_Shift (N, E, N_Op_Shift_Left);
631 elsif Nam = Name_Shift_Right then
632 Expand_Shift (N, E, N_Op_Shift_Right);
634 elsif Nam = Name_Shift_Right_Arithmetic then
635 Expand_Shift (N, E, N_Op_Shift_Right_Arithmetic);
637 elsif Nam = Name_Unchecked_Conversion then
638 Expand_Unc_Conversion (N, E);
640 elsif Nam = Name_Unchecked_Deallocation then
641 Expand_Unc_Deallocation (N);
643 elsif Nam = Name_To_Address then
644 Expand_To_Address (N);
646 elsif Nam = Name_To_Pointer then
647 Expand_To_Pointer (N);
649 elsif Nam_In (Nam, Name_File,
650 Name_Line,
651 Name_Source_Location,
652 Name_Enclosing_Entity,
653 Name_Compilation_Date,
654 Name_Compilation_Time)
655 then
656 Expand_Source_Info (N, Nam);
658 -- If we have a renaming, expand the call to the original operation,
659 -- which must itself be intrinsic, since renaming requires matching
660 -- conventions and this has already been checked.
662 elsif Present (Alias (E)) then
663 Expand_Intrinsic_Call (N, Alias (E));
665 elsif Nkind (N) in N_Binary_Op then
666 Expand_Binary_Operator_Call (N);
668 -- The only other case is where an external name was specified, since
669 -- this is the only way that an otherwise unrecognized name could
670 -- escape the checking in Sem_Prag. Nothing needs to be done in such
671 -- a case, since we pass such a call to the back end unchanged.
673 else
674 null;
675 end if;
676 end Expand_Intrinsic_Call;
678 ------------------------
679 -- Expand_Is_Negative --
680 ------------------------
682 procedure Expand_Is_Negative (N : Node_Id) is
683 Loc : constant Source_Ptr := Sloc (N);
684 Opnd : constant Node_Id := Relocate_Node (First_Actual (N));
686 begin
688 -- We replace the function call by the following expression
690 -- if Opnd < 0.0 then
691 -- True
692 -- else
693 -- if Opnd > 0.0 then
694 -- False;
695 -- else
696 -- Float_Unsigned!(Float (Opnd)) /= 0
697 -- end if;
698 -- end if;
700 Rewrite (N,
701 Make_If_Expression (Loc,
702 Expressions => New_List (
703 Make_Op_Lt (Loc,
704 Left_Opnd => Duplicate_Subexpr (Opnd),
705 Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
707 New_Occurrence_Of (Standard_True, Loc),
709 Make_If_Expression (Loc,
710 Expressions => New_List (
711 Make_Op_Gt (Loc,
712 Left_Opnd => Duplicate_Subexpr_No_Checks (Opnd),
713 Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
715 New_Occurrence_Of (Standard_False, Loc),
717 Make_Op_Ne (Loc,
718 Left_Opnd =>
719 Unchecked_Convert_To
720 (RTE (RE_Float_Unsigned),
721 Convert_To
722 (Standard_Float,
723 Duplicate_Subexpr_No_Checks (Opnd))),
724 Right_Opnd =>
725 Make_Integer_Literal (Loc, 0)))))));
727 Analyze_And_Resolve (N, Standard_Boolean);
728 end Expand_Is_Negative;
730 ------------------
731 -- Expand_Shift --
732 ------------------
734 -- This procedure is used to convert a call to a shift function to the
735 -- corresponding operator node. This conversion is not done by the usual
736 -- circuit for converting calls to operator functions (e.g. "+"(1,2)) to
737 -- operator nodes, because shifts are not predefined operators.
739 -- As a result, whenever a shift is used in the source program, it will
740 -- remain as a call until converted by this routine to the operator node
741 -- form which the back end is expecting to see.
743 -- Note: it is possible for the expander to generate shift operator nodes
744 -- directly, which will be analyzed in the normal manner by calling Analyze
745 -- and Resolve. Such shift operator nodes will not be seen by Expand_Shift.
747 procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind) is
748 Entyp : constant Entity_Id := Etype (E);
749 Left : constant Node_Id := First_Actual (N);
750 Loc : constant Source_Ptr := Sloc (N);
751 Right : constant Node_Id := Next_Actual (Left);
752 Ltyp : constant Node_Id := Etype (Left);
753 Rtyp : constant Node_Id := Etype (Right);
754 Typ : constant Entity_Id := Etype (N);
755 Snode : Node_Id;
757 begin
758 Snode := New_Node (K, Loc);
759 Set_Right_Opnd (Snode, Relocate_Node (Right));
760 Set_Chars (Snode, Chars (E));
761 Set_Etype (Snode, Base_Type (Entyp));
762 Set_Entity (Snode, E);
764 if Compile_Time_Known_Value (Type_High_Bound (Rtyp))
765 and then Expr_Value (Type_High_Bound (Rtyp)) < Esize (Ltyp)
766 then
767 Set_Shift_Count_OK (Snode, True);
768 end if;
770 if Typ = Entyp then
772 -- Note that we don't call Analyze and Resolve on this node, because
773 -- it already got analyzed and resolved when it was a function call.
775 Set_Left_Opnd (Snode, Relocate_Node (Left));
776 Rewrite (N, Snode);
777 Set_Analyzed (N);
779 -- However, we do call the expander, so that the expansion for
780 -- rotates and shift_right_arithmetic happens if Modify_Tree_For_C
781 -- is set.
783 if Expander_Active then
784 Expand (N);
785 end if;
787 else
788 -- If the context type is not the type of the operator, it is an
789 -- inherited operator for a derived type. Wrap the node in a
790 -- conversion so that it is type-consistent for possible further
791 -- expansion (e.g. within a lock-free protected type).
793 Set_Left_Opnd (Snode,
794 Unchecked_Convert_To (Base_Type (Entyp), Relocate_Node (Left)));
795 Rewrite (N, Unchecked_Convert_To (Typ, Snode));
797 -- Analyze and resolve result formed by conversion to target type
799 Analyze_And_Resolve (N, Typ);
800 end if;
801 end Expand_Shift;
803 ------------------------
804 -- Expand_Source_Info --
805 ------------------------
807 procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id) is
808 Loc : constant Source_Ptr := Sloc (N);
809 Ent : Entity_Id;
811 begin
812 -- Integer cases
814 if Nam = Name_Line then
815 Rewrite (N,
816 Make_Integer_Literal (Loc,
817 Intval => UI_From_Int (Int (Get_Logical_Line_Number (Loc)))));
818 Analyze_And_Resolve (N, Standard_Positive);
820 -- String cases
822 else
823 Name_Len := 0;
825 case Nam is
826 when Name_File =>
827 Get_Decoded_Name_String
828 (Reference_Name (Get_Source_File_Index (Loc)));
830 when Name_Source_Location =>
831 Build_Location_String (Loc);
833 when Name_Enclosing_Entity =>
835 -- Skip enclosing blocks to reach enclosing unit
837 Ent := Current_Scope;
838 while Present (Ent) loop
839 exit when Ekind (Ent) /= E_Block
840 and then Ekind (Ent) /= E_Loop;
841 Ent := Scope (Ent);
842 end loop;
844 -- Ent now points to the relevant defining entity
846 Write_Entity_Name (Ent);
848 when Name_Compilation_Date =>
849 declare
850 subtype S13 is String (1 .. 3);
851 Months : constant array (1 .. 12) of S13 :=
852 ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
853 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
855 M1 : constant Character := Opt.Compilation_Time (6);
856 M2 : constant Character := Opt.Compilation_Time (7);
858 MM : constant Natural range 1 .. 12 :=
859 (Character'Pos (M1) - Character'Pos ('0')) * 10 +
860 (Character'Pos (M2) - Character'Pos ('0'));
862 begin
863 -- Reformat ISO date into MMM DD YYYY (__DATE__) format
865 Name_Buffer (1 .. 3) := Months (MM);
866 Name_Buffer (4) := ' ';
867 Name_Buffer (5 .. 6) := Opt.Compilation_Time (9 .. 10);
868 Name_Buffer (7) := ' ';
869 Name_Buffer (8 .. 11) := Opt.Compilation_Time (1 .. 4);
870 Name_Len := 11;
871 end;
873 when Name_Compilation_Time =>
874 Name_Buffer (1 .. 8) := Opt.Compilation_Time (12 .. 19);
875 Name_Len := 8;
877 when others =>
878 raise Program_Error;
879 end case;
881 Rewrite (N,
882 Make_String_Literal (Loc,
883 Strval => String_From_Name_Buffer));
884 Analyze_And_Resolve (N, Standard_String);
885 end if;
887 Set_Is_Static_Expression (N);
888 end Expand_Source_Info;
890 ---------------------------
891 -- Expand_Unc_Conversion --
892 ---------------------------
894 procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id) is
895 Func : constant Entity_Id := Entity (Name (N));
896 Conv : Node_Id;
897 Ftyp : Entity_Id;
898 Ttyp : Entity_Id;
900 begin
901 -- Rewrite as unchecked conversion node. Note that we must convert
902 -- the operand to the formal type of the input parameter of the
903 -- function, so that the resulting N_Unchecked_Type_Conversion
904 -- call indicates the correct types for Gigi.
906 -- Right now, we only do this if a scalar type is involved. It is
907 -- not clear if it is needed in other cases. If we do attempt to
908 -- do the conversion unconditionally, it crashes 3411-018. To be
909 -- investigated further ???
911 Conv := Relocate_Node (First_Actual (N));
912 Ftyp := Etype (First_Formal (Func));
914 if Is_Scalar_Type (Ftyp) then
915 Conv := Convert_To (Ftyp, Conv);
916 Set_Parent (Conv, N);
917 Analyze_And_Resolve (Conv);
918 end if;
920 -- The instantiation of Unchecked_Conversion creates a wrapper package,
921 -- and the target type is declared as a subtype of the actual. Recover
922 -- the actual, which is the subtype indic. in the subtype declaration
923 -- for the target type. This is semantically correct, and avoids
924 -- anomalies with access subtypes. For entities, leave type as is.
926 -- We do the analysis here, because we do not want the compiler
927 -- to try to optimize or otherwise reorganize the unchecked
928 -- conversion node.
930 Ttyp := Etype (E);
932 if Is_Entity_Name (Conv) then
933 null;
935 elsif Nkind (Parent (Ttyp)) = N_Subtype_Declaration then
936 Ttyp := Entity (Subtype_Indication (Parent (Etype (E))));
938 elsif Is_Itype (Ttyp) then
939 Ttyp :=
940 Entity (Subtype_Indication (Associated_Node_For_Itype (Ttyp)));
941 else
942 raise Program_Error;
943 end if;
945 Rewrite (N, Unchecked_Convert_To (Ttyp, Conv));
946 Set_Etype (N, Ttyp);
947 Set_Analyzed (N);
949 if Nkind (N) = N_Unchecked_Type_Conversion then
950 Expand_N_Unchecked_Type_Conversion (N);
951 end if;
952 end Expand_Unc_Conversion;
954 -----------------------------
955 -- Expand_Unc_Deallocation --
956 -----------------------------
958 -- Generate the following Code :
960 -- if Arg /= null then
961 -- <Finalize_Call> (.., T'Class(Arg.all), ..); -- for controlled types
962 -- Free (Arg);
963 -- Arg := Null;
964 -- end if;
966 -- For a task, we also generate a call to Free_Task to ensure that the
967 -- task itself is freed if it is terminated, ditto for a simple protected
968 -- object, with a call to Finalize_Protection. For composite types that
969 -- have tasks or simple protected objects as components, we traverse the
970 -- structures to find and terminate those components.
972 procedure Expand_Unc_Deallocation (N : Node_Id) is
973 Arg : constant Node_Id := First_Actual (N);
974 Loc : constant Source_Ptr := Sloc (N);
975 Typ : constant Entity_Id := Etype (Arg);
976 Desig_T : constant Entity_Id := Designated_Type (Typ);
977 Rtyp : constant Entity_Id := Underlying_Type (Root_Type (Typ));
978 Pool : constant Entity_Id := Associated_Storage_Pool (Rtyp);
979 Stmts : constant List_Id := New_List;
980 Needs_Fin : constant Boolean := Needs_Finalization (Desig_T);
982 Finalizer_Data : Finalization_Exception_Data;
984 Blk : Node_Id := Empty;
985 Blk_Id : Entity_Id;
986 Deref : Node_Id;
987 Final_Code : List_Id;
988 Free_Arg : Node_Id;
989 Free_Node : Node_Id;
990 Gen_Code : Node_Id;
992 Arg_Known_Non_Null : constant Boolean := Known_Non_Null (N);
993 -- This captures whether we know the argument to be non-null so that
994 -- we can avoid the test. The reason that we need to capture this is
995 -- that we analyze some generated statements before properly attaching
996 -- them to the tree, and that can disturb current value settings.
998 Dummy : Entity_Id;
999 -- This variable captures an unused dummy internal entity, see the
1000 -- comment associated with its use.
1002 begin
1003 -- Nothing to do if we know the argument is null
1005 if Known_Null (N) then
1006 return;
1007 end if;
1009 -- Processing for pointer to controlled type
1011 if Needs_Fin then
1012 Deref :=
1013 Make_Explicit_Dereference (Loc,
1014 Prefix => Duplicate_Subexpr_No_Checks (Arg));
1016 -- If the type is tagged, then we must force dispatching on the
1017 -- finalization call because the designated type may not be the
1018 -- actual type of the object.
1020 if Is_Tagged_Type (Desig_T)
1021 and then not Is_Class_Wide_Type (Desig_T)
1022 then
1023 Deref := Unchecked_Convert_To (Class_Wide_Type (Desig_T), Deref);
1025 elsif not Is_Tagged_Type (Desig_T) then
1027 -- Set type of result, to force a conversion when needed (see
1028 -- exp_ch7, Convert_View), given that Deep_Finalize may be
1029 -- inherited from the parent type, and we need the type of the
1030 -- expression to see whether the conversion is in fact needed.
1032 Set_Etype (Deref, Desig_T);
1033 end if;
1035 -- The finalization call is expanded wrapped in a block to catch any
1036 -- possible exception. If an exception does occur, then Program_Error
1037 -- must be raised following the freeing of the object and its removal
1038 -- from the finalization collection's list. We set a flag to record
1039 -- that an exception was raised, and save its occurrence for use in
1040 -- the later raise.
1042 -- Generate:
1043 -- Abort : constant Boolean :=
1044 -- Exception_Occurrence (Get_Current_Excep.all.all) =
1045 -- Standard'Abort_Signal'Identity;
1046 -- <or>
1047 -- Abort : constant Boolean := False; -- no abort
1049 -- E : Exception_Occurrence;
1050 -- Raised : Boolean := False;
1052 -- begin
1053 -- [Deep_]Finalize (Obj);
1054 -- exception
1055 -- when others =>
1056 -- Raised := True;
1057 -- Save_Occurrence (E, Get_Current_Excep.all.all);
1058 -- end;
1060 Build_Object_Declarations (Finalizer_Data, Stmts, Loc);
1062 Final_Code := New_List (
1063 Make_Block_Statement (Loc,
1064 Handled_Statement_Sequence =>
1065 Make_Handled_Sequence_Of_Statements (Loc,
1066 Statements => New_List (
1067 Make_Final_Call (Obj_Ref => Deref, Typ => Desig_T)),
1068 Exception_Handlers => New_List (
1069 Build_Exception_Handler (Finalizer_Data)))));
1071 -- For .NET/JVM, detach the object from the containing finalization
1072 -- collection before finalizing it.
1074 if VM_Target /= No_VM and then Is_Controlled (Desig_T) then
1075 Prepend_To (Final_Code,
1076 Make_Detach_Call (New_Copy_Tree (Arg)));
1077 end if;
1079 -- If aborts are allowed, then the finalization code must be
1080 -- protected by an abort defer/undefer pair.
1082 if Abort_Allowed then
1083 Prepend_To (Final_Code, Build_Runtime_Call (Loc, RE_Abort_Defer));
1085 Blk :=
1086 Make_Block_Statement (Loc, Handled_Statement_Sequence =>
1087 Make_Handled_Sequence_Of_Statements (Loc,
1088 Statements => Final_Code,
1089 At_End_Proc =>
1090 New_Occurrence_Of (RTE (RE_Abort_Undefer_Direct), Loc)));
1091 Add_Block_Identifier (Blk, Blk_Id);
1093 Append (Blk, Stmts);
1095 else
1096 -- Generate a dummy entity to ensure that the internal symbols are
1097 -- in sync when a unit is compiled with and without aborts.
1099 Dummy := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
1100 Append_List_To (Stmts, Final_Code);
1101 end if;
1102 end if;
1104 -- For a task type, call Free_Task before freeing the ATCB
1106 if Is_Task_Type (Desig_T) then
1108 -- We used to detect the case of Abort followed by a Free here,
1109 -- because the Free wouldn't actually free if it happens before
1110 -- the aborted task actually terminates. The warning was removed,
1111 -- because Free now works properly (the task will be freed once
1112 -- it terminates).
1114 Append_To
1115 (Stmts, Cleanup_Task (N, Duplicate_Subexpr_No_Checks (Arg)));
1117 -- For composite types that contain tasks, recurse over the structure
1118 -- to build the selectors for the task subcomponents.
1120 elsif Has_Task (Desig_T) then
1121 if Is_Record_Type (Desig_T) then
1122 Append_List_To (Stmts, Cleanup_Record (N, Arg, Desig_T));
1124 elsif Is_Array_Type (Desig_T) then
1125 Append_List_To (Stmts, Cleanup_Array (N, Arg, Desig_T));
1126 end if;
1127 end if;
1129 -- Same for simple protected types. Eventually call Finalize_Protection
1130 -- before freeing the PO for each protected component.
1132 if Is_Simple_Protected_Type (Desig_T) then
1133 Append_To (Stmts,
1134 Cleanup_Protected_Object (N, Duplicate_Subexpr_No_Checks (Arg)));
1136 elsif Has_Simple_Protected_Object (Desig_T) then
1137 if Is_Record_Type (Desig_T) then
1138 Append_List_To (Stmts, Cleanup_Record (N, Arg, Desig_T));
1139 elsif Is_Array_Type (Desig_T) then
1140 Append_List_To (Stmts, Cleanup_Array (N, Arg, Desig_T));
1141 end if;
1142 end if;
1144 -- Normal processing for non-controlled types. The argument to free is
1145 -- a renaming rather than a constant to ensure that the original context
1146 -- is always set to null after the deallocation takes place.
1148 Free_Arg := Duplicate_Subexpr_No_Checks (Arg, Renaming_Req => True);
1149 Free_Node := Make_Free_Statement (Loc, Empty);
1150 Append_To (Stmts, Free_Node);
1151 Set_Storage_Pool (Free_Node, Pool);
1153 -- Attach to tree before analysis of generated subtypes below
1155 Set_Parent (Stmts, Parent (N));
1157 -- Deal with storage pool
1159 if Present (Pool) then
1161 -- Freeing the secondary stack is meaningless
1163 if Is_RTE (Pool, RE_SS_Pool) then
1164 null;
1166 -- If the pool object is of a simple storage pool type, then attempt
1167 -- to locate the type's Deallocate procedure, if any, and set the
1168 -- free operation's procedure to call. If the type doesn't have a
1169 -- Deallocate (which is allowed), then the actual will simply be set
1170 -- to null.
1172 elsif Present (Get_Rep_Pragma
1173 (Etype (Pool), Name_Simple_Storage_Pool_Type))
1174 then
1175 declare
1176 Pool_Type : constant Entity_Id := Base_Type (Etype (Pool));
1177 Dealloc_Op : Entity_Id;
1178 begin
1179 Dealloc_Op := Get_Name_Entity_Id (Name_Deallocate);
1180 while Present (Dealloc_Op) loop
1181 if Scope (Dealloc_Op) = Scope (Pool_Type)
1182 and then Present (First_Formal (Dealloc_Op))
1183 and then Etype (First_Formal (Dealloc_Op)) = Pool_Type
1184 then
1185 Set_Procedure_To_Call (Free_Node, Dealloc_Op);
1186 exit;
1187 else
1188 Dealloc_Op := Homonym (Dealloc_Op);
1189 end if;
1190 end loop;
1191 end;
1193 -- Case of a class-wide pool type: make a dispatching call to
1194 -- Deallocate through the class-wide Deallocate_Any.
1196 elsif Is_Class_Wide_Type (Etype (Pool)) then
1197 Set_Procedure_To_Call (Free_Node, RTE (RE_Deallocate_Any));
1199 -- Case of a specific pool type: make a statically bound call
1201 else
1202 Set_Procedure_To_Call (Free_Node,
1203 Find_Prim_Op (Etype (Pool), Name_Deallocate));
1204 end if;
1205 end if;
1207 if Present (Procedure_To_Call (Free_Node)) then
1209 -- For all cases of a Deallocate call, the back-end needs to be able
1210 -- to compute the size of the object being freed. This may require
1211 -- some adjustments for objects of dynamic size.
1213 -- If the type is class wide, we generate an implicit type with the
1214 -- right dynamic size, so that the deallocate call gets the right
1215 -- size parameter computed by GIGI. Same for an access to
1216 -- unconstrained packed array.
1218 if Is_Class_Wide_Type (Desig_T)
1219 or else
1220 (Is_Array_Type (Desig_T)
1221 and then not Is_Constrained (Desig_T)
1222 and then Is_Packed (Desig_T))
1223 then
1224 declare
1225 Deref : constant Node_Id :=
1226 Make_Explicit_Dereference (Loc,
1227 Duplicate_Subexpr_No_Checks (Arg));
1228 D_Subtyp : Node_Id;
1229 D_Type : Entity_Id;
1231 begin
1232 -- Perform minor decoration as it is needed by the side effect
1233 -- removal mechanism.
1235 Set_Etype (Deref, Desig_T);
1236 Set_Parent (Deref, Free_Node);
1237 D_Subtyp := Make_Subtype_From_Expr (Deref, Desig_T);
1239 if Nkind (D_Subtyp) in N_Has_Entity then
1240 D_Type := Entity (D_Subtyp);
1242 else
1243 D_Type := Make_Temporary (Loc, 'A');
1244 Insert_Action (Deref,
1245 Make_Subtype_Declaration (Loc,
1246 Defining_Identifier => D_Type,
1247 Subtype_Indication => D_Subtyp));
1248 end if;
1250 -- Force freezing at the point of the dereference. For the
1251 -- class wide case, this avoids having the subtype frozen
1252 -- before the equivalent type.
1254 Freeze_Itype (D_Type, Deref);
1256 Set_Actual_Designated_Subtype (Free_Node, D_Type);
1257 end;
1259 end if;
1260 end if;
1262 -- Ada 2005 (AI-251): In case of abstract interface type we must
1263 -- displace the pointer to reference the base of the object to
1264 -- deallocate its memory, unless we're targetting a VM, in which case
1265 -- no special processing is required.
1267 -- Generate:
1268 -- free (Base_Address (Obj_Ptr))
1270 if Is_Interface (Directly_Designated_Type (Typ))
1271 and then Tagged_Type_Expansion
1272 then
1273 Set_Expression (Free_Node,
1274 Unchecked_Convert_To (Typ,
1275 Make_Function_Call (Loc,
1276 Name => New_Occurrence_Of (RTE (RE_Base_Address), Loc),
1277 Parameter_Associations => New_List (
1278 Unchecked_Convert_To (RTE (RE_Address), Free_Arg)))));
1280 -- Generate:
1281 -- free (Obj_Ptr)
1283 else
1284 Set_Expression (Free_Node, Free_Arg);
1285 end if;
1287 -- Only remaining step is to set result to null, or generate a raise of
1288 -- Constraint_Error if the target object is "not null".
1290 if Can_Never_Be_Null (Etype (Arg)) then
1291 Append_To (Stmts,
1292 Make_Raise_Constraint_Error (Loc,
1293 Reason => CE_Access_Check_Failed));
1295 else
1296 declare
1297 Lhs : constant Node_Id := Duplicate_Subexpr_No_Checks (Arg);
1298 begin
1299 Set_Assignment_OK (Lhs);
1300 Append_To (Stmts,
1301 Make_Assignment_Statement (Loc,
1302 Name => Lhs,
1303 Expression => Make_Null (Loc)));
1304 end;
1305 end if;
1307 -- Generate a test of whether any earlier finalization raised an
1308 -- exception, and in that case raise Program_Error with the previous
1309 -- exception occurrence.
1311 -- Generate:
1312 -- if Raised and then not Abort then
1313 -- raise Program_Error; -- for .NET and
1314 -- -- restricted RTS
1315 -- <or>
1316 -- Raise_From_Controlled_Operation (E); -- all other cases
1317 -- end if;
1319 if Needs_Fin then
1320 Append_To (Stmts, Build_Raise_Statement (Finalizer_Data));
1321 end if;
1323 -- If we know the argument is non-null, then make a block statement
1324 -- that contains the required statements, no need for a test.
1326 if Arg_Known_Non_Null then
1327 Gen_Code :=
1328 Make_Block_Statement (Loc,
1329 Handled_Statement_Sequence =>
1330 Make_Handled_Sequence_Of_Statements (Loc,
1331 Statements => Stmts));
1333 -- If the argument may be null, wrap the statements inside an IF that
1334 -- does an explicit test to exclude the null case.
1336 else
1337 Gen_Code :=
1338 Make_Implicit_If_Statement (N,
1339 Condition =>
1340 Make_Op_Ne (Loc,
1341 Left_Opnd => Duplicate_Subexpr (Arg),
1342 Right_Opnd => Make_Null (Loc)),
1343 Then_Statements => Stmts);
1344 end if;
1346 -- Rewrite the call
1348 Rewrite (N, Gen_Code);
1349 Analyze (N);
1351 -- If we generated a block with an At_End_Proc, expand the exception
1352 -- handler. We need to wait until after everything else is analyzed.
1354 if Present (Blk) then
1355 Expand_At_End_Handler
1356 (Handled_Statement_Sequence (Blk), Entity (Identifier (Blk)));
1357 end if;
1358 end Expand_Unc_Deallocation;
1360 -----------------------
1361 -- Expand_To_Address --
1362 -----------------------
1364 procedure Expand_To_Address (N : Node_Id) is
1365 Loc : constant Source_Ptr := Sloc (N);
1366 Arg : constant Node_Id := First_Actual (N);
1367 Obj : Node_Id;
1369 begin
1370 Remove_Side_Effects (Arg);
1372 Obj := Make_Explicit_Dereference (Loc, Relocate_Node (Arg));
1374 Rewrite (N,
1375 Make_If_Expression (Loc,
1376 Expressions => New_List (
1377 Make_Op_Eq (Loc,
1378 Left_Opnd => New_Copy_Tree (Arg),
1379 Right_Opnd => Make_Null (Loc)),
1380 New_Occurrence_Of (RTE (RE_Null_Address), Loc),
1381 Make_Attribute_Reference (Loc,
1382 Prefix => Obj,
1383 Attribute_Name => Name_Address))));
1385 Analyze_And_Resolve (N, RTE (RE_Address));
1386 end Expand_To_Address;
1388 -----------------------
1389 -- Expand_To_Pointer --
1390 -----------------------
1392 procedure Expand_To_Pointer (N : Node_Id) is
1393 Arg : constant Node_Id := First_Actual (N);
1395 begin
1396 Rewrite (N, Unchecked_Convert_To (Etype (N), Arg));
1397 Analyze (N);
1398 end Expand_To_Pointer;
1400 -----------------------
1401 -- Write_Entity_Name --
1402 -----------------------
1404 procedure Write_Entity_Name (E : Entity_Id) is
1406 procedure Write_Entity_Name_Inner (E : Entity_Id);
1407 -- Inner recursive routine, keep outer routine non-recursive to ease
1408 -- debugging when we get strange results from this routine.
1410 -----------------------------
1411 -- Write_Entity_Name_Inner --
1412 -----------------------------
1414 procedure Write_Entity_Name_Inner (E : Entity_Id) is
1415 begin
1416 -- If entity has an internal name, skip by it, and print its scope.
1417 -- Note that Is_Internal_Name destroys Name_Buffer, hence the save
1418 -- and restore since we depend on its current contents. Note that
1419 -- we strip a final R from the name before the test, this is needed
1420 -- for some cases of instantiations.
1422 declare
1423 Save_NB : constant String := Name_Buffer (1 .. Name_Len);
1424 Save_NL : constant Natural := Name_Len;
1425 Iname : Boolean;
1427 begin
1428 Get_Name_String (Chars (E));
1430 if Name_Buffer (Name_Len) = 'R' then
1431 Name_Len := Name_Len - 1;
1432 end if;
1434 Iname := Is_Internal_Name;
1436 Name_Buffer (1 .. Save_NL) := Save_NB;
1437 Name_Len := Save_NL;
1439 if Iname then
1440 Write_Entity_Name_Inner (Scope (E));
1441 return;
1442 end if;
1443 end;
1445 -- Just print entity name if its scope is at the outer level
1447 if Scope (E) = Standard_Standard then
1448 null;
1450 -- If scope comes from source, write scope and entity
1452 elsif Comes_From_Source (Scope (E)) then
1453 Write_Entity_Name (Scope (E));
1454 Add_Char_To_Name_Buffer ('.');
1456 -- If in wrapper package skip past it
1458 elsif Is_Wrapper_Package (Scope (E)) then
1459 Write_Entity_Name (Scope (Scope (E)));
1460 Add_Char_To_Name_Buffer ('.');
1462 -- Otherwise nothing to output (happens in unnamed block statements)
1464 else
1465 null;
1466 end if;
1468 -- Output the name
1470 declare
1471 Save_NB : constant String := Name_Buffer (1 .. Name_Len);
1472 Save_NL : constant Natural := Name_Len;
1474 begin
1475 Get_Unqualified_Decoded_Name_String (Chars (E));
1477 -- Remove trailing upper case letters from the name (useful for
1478 -- dealing with some cases of internal names generated in the case
1479 -- of references from within a generic.
1481 while Name_Len > 1
1482 and then Name_Buffer (Name_Len) in 'A' .. 'Z'
1483 loop
1484 Name_Len := Name_Len - 1;
1485 end loop;
1487 -- Adjust casing appropriately (gets name from source if possible)
1489 Adjust_Name_Case (Sloc (E));
1491 -- Append to original entry value of Name_Buffer
1493 Name_Buffer (Save_NL + 1 .. Save_NL + Name_Len) :=
1494 Name_Buffer (1 .. Name_Len);
1495 Name_Buffer (1 .. Save_NL) := Save_NB;
1496 Name_Len := Save_NL + Name_Len;
1497 end;
1498 end Write_Entity_Name_Inner;
1500 -- Start of processing for Write_Entity_Name
1502 begin
1503 Write_Entity_Name_Inner (E);
1504 end Write_Entity_Name;
1505 end Exp_Intr;