2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / ada / exp_attr.adb
blob2df553c4585a5a289f0981961a972adfc59303ca
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ A T T R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, 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. --
17 -- --
18 -- You should have received a copy of the GNU General Public License along --
19 -- with this program; see file COPYING3. If not see --
20 -- <http://www.gnu.org/licenses/>. --
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 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Exp_Atag; use Exp_Atag;
32 with Exp_Ch2; use Exp_Ch2;
33 with Exp_Ch3; use Exp_Ch3;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_Ch9; use Exp_Ch9;
36 with Exp_Dist; use Exp_Dist;
37 with Exp_Imgv; use Exp_Imgv;
38 with Exp_Pakd; use Exp_Pakd;
39 with Exp_Strm; use Exp_Strm;
40 with Exp_Tss; use Exp_Tss;
41 with Exp_Util; use Exp_Util;
42 with Exp_VFpt; use Exp_VFpt;
43 with Fname; use Fname;
44 with Freeze; use Freeze;
45 with Gnatvsn; use Gnatvsn;
46 with Itypes; use Itypes;
47 with Lib; use Lib;
48 with Namet; use Namet;
49 with Nmake; use Nmake;
50 with Nlists; use Nlists;
51 with Opt; use Opt;
52 with Restrict; use Restrict;
53 with Rident; use Rident;
54 with Rtsfind; use Rtsfind;
55 with Sem; use Sem;
56 with Sem_Aux; use Sem_Aux;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch7; use Sem_Ch7;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Res; use Sem_Res;
62 with Sem_Util; use Sem_Util;
63 with Sinfo; use Sinfo;
64 with Snames; use Snames;
65 with Stand; use Stand;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uintp; use Uintp;
71 with Uname; use Uname;
72 with Validsw; use Validsw;
74 package body Exp_Attr is
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
80 procedure Compile_Stream_Body_In_Scope
81 (N : Node_Id;
82 Decl : Node_Id;
83 Arr : Entity_Id;
84 Check : Boolean);
85 -- The body for a stream subprogram may be generated outside of the scope
86 -- of the type. If the type is fully private, it may depend on the full
87 -- view of other types (e.g. indices) that are currently private as well.
88 -- We install the declarations of the package in which the type is declared
89 -- before compiling the body in what is its proper environment. The Check
90 -- parameter indicates if checks are to be suppressed for the stream body.
91 -- We suppress checks for array/record reads, since the rule is that these
92 -- are like assignments, out of range values due to uninitialized storage,
93 -- or other invalid values do NOT cause a Constraint_Error to be raised.
95 procedure Expand_Access_To_Protected_Op
96 (N : Node_Id;
97 Pref : Node_Id;
98 Typ : Entity_Id);
100 -- An attribute reference to a protected subprogram is transformed into
101 -- a pair of pointers: one to the object, and one to the operations.
102 -- This expansion is performed for 'Access and for 'Unrestricted_Access.
104 procedure Expand_Fpt_Attribute
105 (N : Node_Id;
106 Pkg : RE_Id;
107 Nam : Name_Id;
108 Args : List_Id);
109 -- This procedure expands a call to a floating-point attribute function.
110 -- N is the attribute reference node, and Args is a list of arguments to
111 -- be passed to the function call. Pkg identifies the package containing
112 -- the appropriate instantiation of System.Fat_Gen. Float arguments in Args
113 -- have already been converted to the floating-point type for which Pkg was
114 -- instantiated. The Nam argument is the relevant attribute processing
115 -- routine to be called. This is the same as the attribute name, except in
116 -- the Unaligned_Valid case.
118 procedure Expand_Fpt_Attribute_R (N : Node_Id);
119 -- This procedure expands a call to a floating-point attribute function
120 -- that takes a single floating-point argument. The function to be called
121 -- is always the same as the attribute name.
123 procedure Expand_Fpt_Attribute_RI (N : Node_Id);
124 -- This procedure expands a call to a floating-point attribute function
125 -- that takes one floating-point argument and one integer argument. The
126 -- function to be called is always the same as the attribute name.
128 procedure Expand_Fpt_Attribute_RR (N : Node_Id);
129 -- This procedure expands a call to a floating-point attribute function
130 -- that takes two floating-point arguments. The function to be called
131 -- is always the same as the attribute name.
133 procedure Expand_Pred_Succ (N : Node_Id);
134 -- Handles expansion of Pred or Succ attributes for case of non-real
135 -- operand with overflow checking required.
137 function Get_Index_Subtype (N : Node_Id) return Entity_Id;
138 -- Used for Last, Last, and Length, when the prefix is an array type.
139 -- Obtains the corresponding index subtype.
141 procedure Find_Fat_Info
142 (T : Entity_Id;
143 Fat_Type : out Entity_Id;
144 Fat_Pkg : out RE_Id);
145 -- Given a floating-point type T, identifies the package containing the
146 -- attributes for this type (returned in Fat_Pkg), and the corresponding
147 -- type for which this package was instantiated from Fat_Gen. Error if T
148 -- is not a floating-point type.
150 function Find_Stream_Subprogram
151 (Typ : Entity_Id;
152 Nam : TSS_Name_Type) return Entity_Id;
153 -- Returns the stream-oriented subprogram attribute for Typ. For tagged
154 -- types, the corresponding primitive operation is looked up, else the
155 -- appropriate TSS from the type itself, or from its closest ancestor
156 -- defining it, is returned. In both cases, inheritance of representation
157 -- aspects is thus taken into account.
159 function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id;
160 -- Given a type, find a corresponding stream convert pragma that applies to
161 -- the implementation base type of this type (Typ). If found, return the
162 -- pragma node, otherwise return Empty if no pragma is found.
164 function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean;
165 -- Utility for array attributes, returns true on packed constrained
166 -- arrays, and on access to same.
168 function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean;
169 -- Returns true iff the given node refers to an attribute call that
170 -- can be expanded directly by the back end and does not need front end
171 -- expansion. Typically used for rounding and truncation attributes that
172 -- appear directly inside a conversion to integer.
174 ----------------------------------
175 -- Compile_Stream_Body_In_Scope --
176 ----------------------------------
178 procedure Compile_Stream_Body_In_Scope
179 (N : Node_Id;
180 Decl : Node_Id;
181 Arr : Entity_Id;
182 Check : Boolean)
184 Installed : Boolean := False;
185 Scop : constant Entity_Id := Scope (Arr);
186 Curr : constant Entity_Id := Current_Scope;
188 begin
189 if Is_Hidden (Arr)
190 and then not In_Open_Scopes (Scop)
191 and then Ekind (Scop) = E_Package
192 then
193 Push_Scope (Scop);
194 Install_Visible_Declarations (Scop);
195 Install_Private_Declarations (Scop);
196 Installed := True;
198 -- The entities in the package are now visible, but the generated
199 -- stream entity must appear in the current scope (usually an
200 -- enclosing stream function) so that itypes all have their proper
201 -- scopes.
203 Push_Scope (Curr);
204 end if;
206 if Check then
207 Insert_Action (N, Decl);
208 else
209 Insert_Action (N, Decl, Suppress => All_Checks);
210 end if;
212 if Installed then
214 -- Remove extra copy of current scope, and package itself
216 Pop_Scope;
217 End_Package_Scope (Scop);
218 end if;
219 end Compile_Stream_Body_In_Scope;
221 -----------------------------------
222 -- Expand_Access_To_Protected_Op --
223 -----------------------------------
225 procedure Expand_Access_To_Protected_Op
226 (N : Node_Id;
227 Pref : Node_Id;
228 Typ : Entity_Id)
230 -- The value of the attribute_reference is a record containing two
231 -- fields: an access to the protected object, and an access to the
232 -- subprogram itself. The prefix is a selected component.
234 Loc : constant Source_Ptr := Sloc (N);
235 Agg : Node_Id;
236 Btyp : constant Entity_Id := Base_Type (Typ);
237 Sub : Entity_Id;
238 E_T : constant Entity_Id := Equivalent_Type (Btyp);
239 Acc : constant Entity_Id :=
240 Etype (Next_Component (First_Component (E_T)));
241 Obj_Ref : Node_Id;
242 Curr : Entity_Id;
244 function May_Be_External_Call return Boolean;
245 -- If the 'Access is to a local operation, but appears in a context
246 -- where it may lead to a call from outside the object, we must treat
247 -- this as an external call. Clearly we cannot tell without full
248 -- flow analysis, and a subsequent call that uses this 'Access may
249 -- lead to a bounded error (trying to seize locks twice, e.g.). For
250 -- now we treat 'Access as a potential external call if it is an actual
251 -- in a call to an outside subprogram.
253 --------------------------
254 -- May_Be_External_Call --
255 --------------------------
257 function May_Be_External_Call return Boolean is
258 Subp : Entity_Id;
259 Par : Node_Id := Parent (N);
261 begin
262 -- Account for the case where the Access attribute is part of a
263 -- named parameter association.
265 if Nkind (Par) = N_Parameter_Association then
266 Par := Parent (Par);
267 end if;
269 if Nkind_In (Par, N_Procedure_Call_Statement, N_Function_Call)
270 and then Is_Entity_Name (Name (Par))
271 then
272 Subp := Entity (Name (Par));
273 return not In_Open_Scopes (Scope (Subp));
274 else
275 return False;
276 end if;
277 end May_Be_External_Call;
279 -- Start of processing for Expand_Access_To_Protected_Op
281 begin
282 -- Within the body of the protected type, the prefix
283 -- designates a local operation, and the object is the first
284 -- parameter of the corresponding protected body of the
285 -- current enclosing operation.
287 if Is_Entity_Name (Pref) then
288 if May_Be_External_Call then
289 Sub :=
290 New_Occurrence_Of
291 (External_Subprogram (Entity (Pref)), Loc);
292 else
293 Sub :=
294 New_Occurrence_Of
295 (Protected_Body_Subprogram (Entity (Pref)), Loc);
296 end if;
298 -- Don't traverse the scopes when the attribute occurs within an init
299 -- proc, because we directly use the _init formal of the init proc in
300 -- that case.
302 Curr := Current_Scope;
303 if not Is_Init_Proc (Curr) then
304 pragma Assert (In_Open_Scopes (Scope (Entity (Pref))));
306 while Scope (Curr) /= Scope (Entity (Pref)) loop
307 Curr := Scope (Curr);
308 end loop;
309 end if;
311 -- In case of protected entries the first formal of its Protected_
312 -- Body_Subprogram is the address of the object.
314 if Ekind (Curr) = E_Entry then
315 Obj_Ref :=
316 New_Occurrence_Of
317 (First_Formal
318 (Protected_Body_Subprogram (Curr)), Loc);
320 -- If the current scope is an init proc, then use the address of the
321 -- _init formal as the object reference.
323 elsif Is_Init_Proc (Curr) then
324 Obj_Ref :=
325 Make_Attribute_Reference (Loc,
326 Prefix => New_Occurrence_Of (First_Formal (Curr), Loc),
327 Attribute_Name => Name_Address);
329 -- In case of protected subprograms the first formal of its
330 -- Protected_Body_Subprogram is the object and we get its address.
332 else
333 Obj_Ref :=
334 Make_Attribute_Reference (Loc,
335 Prefix =>
336 New_Occurrence_Of
337 (First_Formal
338 (Protected_Body_Subprogram (Curr)), Loc),
339 Attribute_Name => Name_Address);
340 end if;
342 -- Case where the prefix is not an entity name. Find the
343 -- version of the protected operation to be called from
344 -- outside the protected object.
346 else
347 Sub :=
348 New_Occurrence_Of
349 (External_Subprogram
350 (Entity (Selector_Name (Pref))), Loc);
352 Obj_Ref :=
353 Make_Attribute_Reference (Loc,
354 Prefix => Relocate_Node (Prefix (Pref)),
355 Attribute_Name => Name_Address);
356 end if;
358 Agg :=
359 Make_Aggregate (Loc,
360 Expressions =>
361 New_List (
362 Obj_Ref,
363 Unchecked_Convert_To (Acc,
364 Make_Attribute_Reference (Loc,
365 Prefix => Sub,
366 Attribute_Name => Name_Address))));
368 Rewrite (N, Agg);
370 Analyze_And_Resolve (N, E_T);
372 -- For subsequent analysis, the node must retain its type.
373 -- The backend will replace it with the equivalent type where
374 -- needed.
376 Set_Etype (N, Typ);
377 end Expand_Access_To_Protected_Op;
379 --------------------------
380 -- Expand_Fpt_Attribute --
381 --------------------------
383 procedure Expand_Fpt_Attribute
384 (N : Node_Id;
385 Pkg : RE_Id;
386 Nam : Name_Id;
387 Args : List_Id)
389 Loc : constant Source_Ptr := Sloc (N);
390 Typ : constant Entity_Id := Etype (N);
391 Fnm : Node_Id;
393 begin
394 -- The function name is the selected component Attr_xxx.yyy where
395 -- Attr_xxx is the package name, and yyy is the argument Nam.
397 -- Note: it would be more usual to have separate RE entries for each
398 -- of the entities in the Fat packages, but first they have identical
399 -- names (so we would have to have lots of renaming declarations to
400 -- meet the normal RE rule of separate names for all runtime entities),
401 -- and second there would be an awful lot of them!
403 Fnm :=
404 Make_Selected_Component (Loc,
405 Prefix => New_Reference_To (RTE (Pkg), Loc),
406 Selector_Name => Make_Identifier (Loc, Nam));
408 -- The generated call is given the provided set of parameters, and then
409 -- wrapped in a conversion which converts the result to the target type
410 -- We use the base type as the target because a range check may be
411 -- required.
413 Rewrite (N,
414 Unchecked_Convert_To (Base_Type (Etype (N)),
415 Make_Function_Call (Loc,
416 Name => Fnm,
417 Parameter_Associations => Args)));
419 Analyze_And_Resolve (N, Typ);
420 end Expand_Fpt_Attribute;
422 ----------------------------
423 -- Expand_Fpt_Attribute_R --
424 ----------------------------
426 -- The single argument is converted to its root type to call the
427 -- appropriate runtime function, with the actual call being built
428 -- by Expand_Fpt_Attribute
430 procedure Expand_Fpt_Attribute_R (N : Node_Id) is
431 E1 : constant Node_Id := First (Expressions (N));
432 Ftp : Entity_Id;
433 Pkg : RE_Id;
434 begin
435 Find_Fat_Info (Etype (E1), Ftp, Pkg);
436 Expand_Fpt_Attribute
437 (N, Pkg, Attribute_Name (N),
438 New_List (Unchecked_Convert_To (Ftp, Relocate_Node (E1))));
439 end Expand_Fpt_Attribute_R;
441 -----------------------------
442 -- Expand_Fpt_Attribute_RI --
443 -----------------------------
445 -- The first argument is converted to its root type and the second
446 -- argument is converted to standard long long integer to call the
447 -- appropriate runtime function, with the actual call being built
448 -- by Expand_Fpt_Attribute
450 procedure Expand_Fpt_Attribute_RI (N : Node_Id) is
451 E1 : constant Node_Id := First (Expressions (N));
452 Ftp : Entity_Id;
453 Pkg : RE_Id;
454 E2 : constant Node_Id := Next (E1);
455 begin
456 Find_Fat_Info (Etype (E1), Ftp, Pkg);
457 Expand_Fpt_Attribute
458 (N, Pkg, Attribute_Name (N),
459 New_List (
460 Unchecked_Convert_To (Ftp, Relocate_Node (E1)),
461 Unchecked_Convert_To (Standard_Integer, Relocate_Node (E2))));
462 end Expand_Fpt_Attribute_RI;
464 -----------------------------
465 -- Expand_Fpt_Attribute_RR --
466 -----------------------------
468 -- The two arguments are converted to their root types to call the
469 -- appropriate runtime function, with the actual call being built
470 -- by Expand_Fpt_Attribute
472 procedure Expand_Fpt_Attribute_RR (N : Node_Id) is
473 E1 : constant Node_Id := First (Expressions (N));
474 Ftp : Entity_Id;
475 Pkg : RE_Id;
476 E2 : constant Node_Id := Next (E1);
477 begin
478 Find_Fat_Info (Etype (E1), Ftp, Pkg);
479 Expand_Fpt_Attribute
480 (N, Pkg, Attribute_Name (N),
481 New_List (
482 Unchecked_Convert_To (Ftp, Relocate_Node (E1)),
483 Unchecked_Convert_To (Ftp, Relocate_Node (E2))));
484 end Expand_Fpt_Attribute_RR;
486 ----------------------------------
487 -- Expand_N_Attribute_Reference --
488 ----------------------------------
490 procedure Expand_N_Attribute_Reference (N : Node_Id) is
491 Loc : constant Source_Ptr := Sloc (N);
492 Typ : constant Entity_Id := Etype (N);
493 Btyp : constant Entity_Id := Base_Type (Typ);
494 Pref : constant Node_Id := Prefix (N);
495 Ptyp : constant Entity_Id := Etype (Pref);
496 Exprs : constant List_Id := Expressions (N);
497 Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N));
499 procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id);
500 -- Rewrites a stream attribute for Read, Write or Output with the
501 -- procedure call. Pname is the entity for the procedure to call.
503 ------------------------------
504 -- Rewrite_Stream_Proc_Call --
505 ------------------------------
507 procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id) is
508 Item : constant Node_Id := Next (First (Exprs));
509 Formal : constant Entity_Id := Next_Formal (First_Formal (Pname));
510 Formal_Typ : constant Entity_Id := Etype (Formal);
511 Is_Written : constant Boolean := (Ekind (Formal) /= E_In_Parameter);
513 begin
514 -- The expansion depends on Item, the second actual, which is
515 -- the object being streamed in or out.
517 -- If the item is a component of a packed array type, and
518 -- a conversion is needed on exit, we introduce a temporary to
519 -- hold the value, because otherwise the packed reference will
520 -- not be properly expanded.
522 if Nkind (Item) = N_Indexed_Component
523 and then Is_Packed (Base_Type (Etype (Prefix (Item))))
524 and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
525 and then Is_Written
526 then
527 declare
528 Temp : constant Entity_Id :=
529 Make_Defining_Identifier
530 (Loc, New_Internal_Name ('V'));
531 Decl : Node_Id;
532 Assn : Node_Id;
534 begin
535 Decl :=
536 Make_Object_Declaration (Loc,
537 Defining_Identifier => Temp,
538 Object_Definition =>
539 New_Occurrence_Of (Formal_Typ, Loc));
540 Set_Etype (Temp, Formal_Typ);
542 Assn :=
543 Make_Assignment_Statement (Loc,
544 Name => New_Copy_Tree (Item),
545 Expression =>
546 Unchecked_Convert_To
547 (Etype (Item), New_Occurrence_Of (Temp, Loc)));
549 Rewrite (Item, New_Occurrence_Of (Temp, Loc));
550 Insert_Actions (N,
551 New_List (
552 Decl,
553 Make_Procedure_Call_Statement (Loc,
554 Name => New_Occurrence_Of (Pname, Loc),
555 Parameter_Associations => Exprs),
556 Assn));
558 Rewrite (N, Make_Null_Statement (Loc));
559 return;
560 end;
561 end if;
563 -- For the class-wide dispatching cases, and for cases in which
564 -- the base type of the second argument matches the base type of
565 -- the corresponding formal parameter (that is to say the stream
566 -- operation is not inherited), we are all set, and can use the
567 -- argument unchanged.
569 -- For all other cases we do an unchecked conversion of the second
570 -- parameter to the type of the formal of the procedure we are
571 -- calling. This deals with the private type cases, and with going
572 -- to the root type as required in elementary type case.
574 if not Is_Class_Wide_Type (Entity (Pref))
575 and then not Is_Class_Wide_Type (Etype (Item))
576 and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
577 then
578 Rewrite (Item,
579 Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item)));
581 -- For untagged derived types set Assignment_OK, to prevent
582 -- copies from being created when the unchecked conversion
583 -- is expanded (which would happen in Remove_Side_Effects
584 -- if Expand_N_Unchecked_Conversion were allowed to call
585 -- Force_Evaluation). The copy could violate Ada semantics
586 -- in cases such as an actual that is an out parameter.
587 -- Note that this approach is also used in exp_ch7 for calls
588 -- to controlled type operations to prevent problems with
589 -- actuals wrapped in unchecked conversions.
591 if Is_Untagged_Derivation (Etype (Expression (Item))) then
592 Set_Assignment_OK (Item);
593 end if;
594 end if;
596 -- The stream operation to call maybe a renaming created by
597 -- an attribute definition clause, and may not be frozen yet.
598 -- Ensure that it has the necessary extra formals.
600 if not Is_Frozen (Pname) then
601 Create_Extra_Formals (Pname);
602 end if;
604 -- And now rewrite the call
606 Rewrite (N,
607 Make_Procedure_Call_Statement (Loc,
608 Name => New_Occurrence_Of (Pname, Loc),
609 Parameter_Associations => Exprs));
611 Analyze (N);
612 end Rewrite_Stream_Proc_Call;
614 -- Start of processing for Expand_N_Attribute_Reference
616 begin
617 -- Do required validity checking, if enabled. Do not apply check to
618 -- output parameters of an Asm instruction, since the value of this
619 -- is not set till after the attribute has been elaborated, and do
620 -- not apply the check to the arguments of a 'Read or 'Input attribute
621 -- reference since the scalar argument is an OUT scalar.
623 if Validity_Checks_On and then Validity_Check_Operands
624 and then Id /= Attribute_Asm_Output
625 and then Id /= Attribute_Read
626 and then Id /= Attribute_Input
627 then
628 declare
629 Expr : Node_Id;
630 begin
631 Expr := First (Expressions (N));
632 while Present (Expr) loop
633 Ensure_Valid (Expr);
634 Next (Expr);
635 end loop;
636 end;
637 end if;
639 -- Ada 2005 (AI-318-02): If attribute prefix is a call to a build-in-
640 -- place function, then a temporary return object needs to be created
641 -- and access to it must be passed to the function. Currently we limit
642 -- such functions to those with inherently limited result subtypes, but
643 -- eventually we plan to expand the functions that are treated as
644 -- build-in-place to include other composite result types.
646 if Ada_Version >= Ada_05
647 and then Is_Build_In_Place_Function_Call (Pref)
648 then
649 Make_Build_In_Place_Call_In_Anonymous_Context (Pref);
650 end if;
652 -- If prefix is a protected type name, this is a reference to
653 -- the current instance of the type.
655 if Is_Protected_Self_Reference (Pref) then
656 Rewrite (Pref, Concurrent_Ref (Pref));
657 Analyze (Pref);
658 end if;
660 -- Remaining processing depends on specific attribute
662 case Id is
664 ------------
665 -- Access --
666 ------------
668 when Attribute_Access |
669 Attribute_Unchecked_Access |
670 Attribute_Unrestricted_Access =>
672 Access_Cases : declare
673 Ref_Object : constant Node_Id := Get_Referenced_Object (Pref);
674 Btyp_DDT : Entity_Id;
676 function Enclosing_Object (N : Node_Id) return Node_Id;
677 -- If N denotes a compound name (selected component, indexed
678 -- component, or slice), returns the name of the outermost
679 -- such enclosing object. Otherwise returns N. If the object
680 -- is a renaming, then the renamed object is returned.
682 ----------------------
683 -- Enclosing_Object --
684 ----------------------
686 function Enclosing_Object (N : Node_Id) return Node_Id is
687 Obj_Name : Node_Id;
689 begin
690 Obj_Name := N;
691 while Nkind_In (Obj_Name, N_Selected_Component,
692 N_Indexed_Component,
693 N_Slice)
694 loop
695 Obj_Name := Prefix (Obj_Name);
696 end loop;
698 return Get_Referenced_Object (Obj_Name);
699 end Enclosing_Object;
701 -- Local declarations
703 Enc_Object : constant Node_Id := Enclosing_Object (Ref_Object);
705 -- Start of processing for Access_Cases
707 begin
708 Btyp_DDT := Designated_Type (Btyp);
710 -- Handle designated types that come from the limited view
712 if Ekind (Btyp_DDT) = E_Incomplete_Type
713 and then From_With_Type (Btyp_DDT)
714 and then Present (Non_Limited_View (Btyp_DDT))
715 then
716 Btyp_DDT := Non_Limited_View (Btyp_DDT);
718 elsif Is_Class_Wide_Type (Btyp_DDT)
719 and then Ekind (Etype (Btyp_DDT)) = E_Incomplete_Type
720 and then From_With_Type (Etype (Btyp_DDT))
721 and then Present (Non_Limited_View (Etype (Btyp_DDT)))
722 and then Present (Class_Wide_Type
723 (Non_Limited_View (Etype (Btyp_DDT))))
724 then
725 Btyp_DDT :=
726 Class_Wide_Type (Non_Limited_View (Etype (Btyp_DDT)));
727 end if;
729 -- In order to improve the text of error messages, the designated
730 -- type of access-to-subprogram itypes is set by the semantics as
731 -- the associated subprogram entity (see sem_attr). Now we replace
732 -- such node with the proper E_Subprogram_Type itype.
734 if Id = Attribute_Unrestricted_Access
735 and then Is_Subprogram (Directly_Designated_Type (Typ))
736 then
737 -- The following conditions ensure that this special management
738 -- is done only for "Address!(Prim'Unrestricted_Access)" nodes.
739 -- At this stage other cases in which the designated type is
740 -- still a subprogram (instead of an E_Subprogram_Type) are
741 -- wrong because the semantics must have overridden the type of
742 -- the node with the type imposed by the context.
744 if Nkind (Parent (N)) = N_Unchecked_Type_Conversion
745 and then Etype (Parent (N)) = RTE (RE_Prim_Ptr)
746 then
747 Set_Etype (N, RTE (RE_Prim_Ptr));
749 else
750 declare
751 Subp : constant Entity_Id :=
752 Directly_Designated_Type (Typ);
753 Etyp : Entity_Id;
754 Extra : Entity_Id := Empty;
755 New_Formal : Entity_Id;
756 Old_Formal : Entity_Id := First_Formal (Subp);
757 Subp_Typ : Entity_Id;
759 begin
760 Subp_Typ := Create_Itype (E_Subprogram_Type, N);
761 Set_Etype (Subp_Typ, Etype (Subp));
762 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
764 if Present (Old_Formal) then
765 New_Formal := New_Copy (Old_Formal);
766 Set_First_Entity (Subp_Typ, New_Formal);
768 loop
769 Set_Scope (New_Formal, Subp_Typ);
770 Etyp := Etype (New_Formal);
772 -- Handle itypes. There is no need to duplicate
773 -- here the itypes associated with record types
774 -- (i.e the implicit full view of private types).
776 if Is_Itype (Etyp)
777 and then Ekind (Base_Type (Etyp)) /= E_Record_Type
778 then
779 Extra := New_Copy (Etyp);
780 Set_Parent (Extra, New_Formal);
781 Set_Etype (New_Formal, Extra);
782 Set_Scope (Extra, Subp_Typ);
783 end if;
785 Extra := New_Formal;
786 Next_Formal (Old_Formal);
787 exit when No (Old_Formal);
789 Set_Next_Entity (New_Formal,
790 New_Copy (Old_Formal));
791 Next_Entity (New_Formal);
792 end loop;
794 Set_Next_Entity (New_Formal, Empty);
795 Set_Last_Entity (Subp_Typ, Extra);
796 end if;
798 -- Now that the explicit formals have been duplicated,
799 -- any extra formals needed by the subprogram must be
800 -- created.
802 if Present (Extra) then
803 Set_Extra_Formal (Extra, Empty);
804 end if;
806 Create_Extra_Formals (Subp_Typ);
807 Set_Directly_Designated_Type (Typ, Subp_Typ);
808 end;
809 end if;
810 end if;
812 if Is_Access_Protected_Subprogram_Type (Btyp) then
813 Expand_Access_To_Protected_Op (N, Pref, Typ);
815 -- If prefix is a type name, this is a reference to the current
816 -- instance of the type, within its initialization procedure.
818 elsif Is_Entity_Name (Pref)
819 and then Is_Type (Entity (Pref))
820 then
821 declare
822 Par : Node_Id;
823 Formal : Entity_Id;
825 begin
826 -- If the current instance name denotes a task type, then
827 -- the access attribute is rewritten to be the name of the
828 -- "_task" parameter associated with the task type's task
829 -- procedure. An unchecked conversion is applied to ensure
830 -- a type match in cases of expander-generated calls (e.g.
831 -- init procs).
833 if Is_Task_Type (Entity (Pref)) then
834 Formal :=
835 First_Entity (Get_Task_Body_Procedure (Entity (Pref)));
836 while Present (Formal) loop
837 exit when Chars (Formal) = Name_uTask;
838 Next_Entity (Formal);
839 end loop;
841 pragma Assert (Present (Formal));
843 Rewrite (N,
844 Unchecked_Convert_To (Typ,
845 New_Occurrence_Of (Formal, Loc)));
846 Set_Etype (N, Typ);
848 -- The expression must appear in a default expression,
849 -- (which in the initialization procedure is the
850 -- right-hand side of an assignment), and not in a
851 -- discriminant constraint.
853 else
854 Par := Parent (N);
855 while Present (Par) loop
856 exit when Nkind (Par) = N_Assignment_Statement;
858 if Nkind (Par) = N_Component_Declaration then
859 return;
860 end if;
862 Par := Parent (Par);
863 end loop;
865 if Present (Par) then
866 Rewrite (N,
867 Make_Attribute_Reference (Loc,
868 Prefix => Make_Identifier (Loc, Name_uInit),
869 Attribute_Name => Attribute_Name (N)));
871 Analyze_And_Resolve (N, Typ);
872 end if;
873 end if;
874 end;
876 -- If the prefix of an Access attribute is a dereference of an
877 -- access parameter (or a renaming of such a dereference, or a
878 -- subcomponent of such a dereference) and the context is a
879 -- general access type (including the type of an object or
880 -- component with an access_definition, but not the anonymous
881 -- type of an access parameter or access discriminant), then
882 -- apply an accessibility check to the access parameter. We used
883 -- to rewrite the access parameter as a type conversion, but that
884 -- could only be done if the immediate prefix of the Access
885 -- attribute was the dereference, and didn't handle cases where
886 -- the attribute is applied to a subcomponent of the dereference,
887 -- since there's generally no available, appropriate access type
888 -- to convert to in that case. The attribute is passed as the
889 -- point to insert the check, because the access parameter may
890 -- come from a renaming, possibly in a different scope, and the
891 -- check must be associated with the attribute itself.
893 elsif Id = Attribute_Access
894 and then Nkind (Enc_Object) = N_Explicit_Dereference
895 and then Is_Entity_Name (Prefix (Enc_Object))
896 and then (Ekind (Btyp) = E_General_Access_Type
897 or else Is_Local_Anonymous_Access (Btyp))
898 and then Ekind (Entity (Prefix (Enc_Object))) in Formal_Kind
899 and then Ekind (Etype (Entity (Prefix (Enc_Object))))
900 = E_Anonymous_Access_Type
901 and then Present (Extra_Accessibility
902 (Entity (Prefix (Enc_Object))))
903 then
904 Apply_Accessibility_Check (Prefix (Enc_Object), Typ, N);
906 -- Ada 2005 (AI-251): If the designated type is an interface we
907 -- add an implicit conversion to force the displacement of the
908 -- pointer to reference the secondary dispatch table.
910 elsif Is_Interface (Btyp_DDT)
911 and then (Comes_From_Source (N)
912 or else Comes_From_Source (Ref_Object)
913 or else (Nkind (Ref_Object) in N_Has_Chars
914 and then Chars (Ref_Object) = Name_uInit))
915 then
916 if Nkind (Ref_Object) /= N_Explicit_Dereference then
918 -- No implicit conversion required if types match, or if
919 -- the prefix is the class_wide_type of the interface. In
920 -- either case passing an object of the interface type has
921 -- already set the pointer correctly.
923 if Btyp_DDT = Etype (Ref_Object)
924 or else (Is_Class_Wide_Type (Etype (Ref_Object))
925 and then
926 Class_Wide_Type (Btyp_DDT) = Etype (Ref_Object))
927 then
928 null;
930 else
931 Rewrite (Prefix (N),
932 Convert_To (Btyp_DDT,
933 New_Copy_Tree (Prefix (N))));
935 Analyze_And_Resolve (Prefix (N), Btyp_DDT);
936 end if;
938 -- When the object is an explicit dereference, convert the
939 -- dereference's prefix.
941 else
942 declare
943 Obj_DDT : constant Entity_Id :=
944 Base_Type
945 (Directly_Designated_Type
946 (Etype (Prefix (Ref_Object))));
947 begin
948 -- No implicit conversion required if designated types
949 -- match.
951 if Obj_DDT /= Btyp_DDT
952 and then not (Is_Class_Wide_Type (Obj_DDT)
953 and then Etype (Obj_DDT) = Btyp_DDT)
954 then
955 Rewrite (N,
956 Convert_To (Typ,
957 New_Copy_Tree (Prefix (Ref_Object))));
958 Analyze_And_Resolve (N, Typ);
959 end if;
960 end;
961 end if;
962 end if;
963 end Access_Cases;
965 --------------
966 -- Adjacent --
967 --------------
969 -- Transforms 'Adjacent into a call to the floating-point attribute
970 -- function Adjacent in Fat_xxx (where xxx is the root type)
972 when Attribute_Adjacent =>
973 Expand_Fpt_Attribute_RR (N);
975 -------------
976 -- Address --
977 -------------
979 when Attribute_Address => Address : declare
980 Task_Proc : Entity_Id;
982 begin
983 -- If the prefix is a task or a task type, the useful address is that
984 -- of the procedure for the task body, i.e. the actual program unit.
985 -- We replace the original entity with that of the procedure.
987 if Is_Entity_Name (Pref)
988 and then Is_Task_Type (Entity (Pref))
989 then
990 Task_Proc := Next_Entity (Root_Type (Ptyp));
992 while Present (Task_Proc) loop
993 exit when Ekind (Task_Proc) = E_Procedure
994 and then Etype (First_Formal (Task_Proc)) =
995 Corresponding_Record_Type (Ptyp);
996 Next_Entity (Task_Proc);
997 end loop;
999 if Present (Task_Proc) then
1000 Set_Entity (Pref, Task_Proc);
1001 Set_Etype (Pref, Etype (Task_Proc));
1002 end if;
1004 -- Similarly, the address of a protected operation is the address
1005 -- of the corresponding protected body, regardless of the protected
1006 -- object from which it is selected.
1008 elsif Nkind (Pref) = N_Selected_Component
1009 and then Is_Subprogram (Entity (Selector_Name (Pref)))
1010 and then Is_Protected_Type (Scope (Entity (Selector_Name (Pref))))
1011 then
1012 Rewrite (Pref,
1013 New_Occurrence_Of (
1014 External_Subprogram (Entity (Selector_Name (Pref))), Loc));
1016 elsif Nkind (Pref) = N_Explicit_Dereference
1017 and then Ekind (Ptyp) = E_Subprogram_Type
1018 and then Convention (Ptyp) = Convention_Protected
1019 then
1020 -- The prefix is be a dereference of an access_to_protected_
1021 -- subprogram. The desired address is the second component of
1022 -- the record that represents the access.
1024 declare
1025 Addr : constant Entity_Id := Etype (N);
1026 Ptr : constant Node_Id := Prefix (Pref);
1027 T : constant Entity_Id :=
1028 Equivalent_Type (Base_Type (Etype (Ptr)));
1030 begin
1031 Rewrite (N,
1032 Unchecked_Convert_To (Addr,
1033 Make_Selected_Component (Loc,
1034 Prefix => Unchecked_Convert_To (T, Ptr),
1035 Selector_Name => New_Occurrence_Of (
1036 Next_Entity (First_Entity (T)), Loc))));
1038 Analyze_And_Resolve (N, Addr);
1039 end;
1041 -- Ada 2005 (AI-251): Class-wide interface objects are always
1042 -- "displaced" to reference the tag associated with the interface
1043 -- type. In order to obtain the real address of such objects we
1044 -- generate a call to a run-time subprogram that returns the base
1045 -- address of the object.
1047 -- This processing is not needed in the VM case, where dispatching
1048 -- issues are taken care of by the virtual machine.
1050 elsif Is_Class_Wide_Type (Ptyp)
1051 and then Is_Interface (Ptyp)
1052 and then Tagged_Type_Expansion
1053 and then not (Nkind (Pref) in N_Has_Entity
1054 and then Is_Subprogram (Entity (Pref)))
1055 then
1056 Rewrite (N,
1057 Make_Function_Call (Loc,
1058 Name => New_Reference_To (RTE (RE_Base_Address), Loc),
1059 Parameter_Associations => New_List (
1060 Relocate_Node (N))));
1061 Analyze (N);
1062 return;
1063 end if;
1065 -- Deal with packed array reference, other cases are handled by
1066 -- the back end.
1068 if Involves_Packed_Array_Reference (Pref) then
1069 Expand_Packed_Address_Reference (N);
1070 end if;
1071 end Address;
1073 ---------------
1074 -- Alignment --
1075 ---------------
1077 when Attribute_Alignment => Alignment : declare
1078 New_Node : Node_Id;
1080 begin
1081 -- For class-wide types, X'Class'Alignment is transformed into a
1082 -- direct reference to the Alignment of the class type, so that the
1083 -- back end does not have to deal with the X'Class'Alignment
1084 -- reference.
1086 if Is_Entity_Name (Pref)
1087 and then Is_Class_Wide_Type (Entity (Pref))
1088 then
1089 Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
1090 return;
1092 -- For x'Alignment applied to an object of a class wide type,
1093 -- transform X'Alignment into a call to the predefined primitive
1094 -- operation _Alignment applied to X.
1096 elsif Is_Class_Wide_Type (Ptyp) then
1098 -- No need to do anything else compiling under restriction
1099 -- No_Dispatching_Calls. During the semantic analysis we
1100 -- already notified such violation.
1102 if Restriction_Active (No_Dispatching_Calls) then
1103 return;
1104 end if;
1106 New_Node :=
1107 Make_Function_Call (Loc,
1108 Name => New_Reference_To
1109 (Find_Prim_Op (Ptyp, Name_uAlignment), Loc),
1110 Parameter_Associations => New_List (Pref));
1112 if Typ /= Standard_Integer then
1114 -- The context is a specific integer type with which the
1115 -- original attribute was compatible. The function has a
1116 -- specific type as well, so to preserve the compatibility
1117 -- we must convert explicitly.
1119 New_Node := Convert_To (Typ, New_Node);
1120 end if;
1122 Rewrite (N, New_Node);
1123 Analyze_And_Resolve (N, Typ);
1124 return;
1126 -- For all other cases, we just have to deal with the case of
1127 -- the fact that the result can be universal.
1129 else
1130 Apply_Universal_Integer_Attribute_Checks (N);
1131 end if;
1132 end Alignment;
1134 ---------------
1135 -- AST_Entry --
1136 ---------------
1138 when Attribute_AST_Entry => AST_Entry : declare
1139 Ttyp : Entity_Id;
1140 T_Id : Node_Id;
1141 Eent : Entity_Id;
1143 Entry_Ref : Node_Id;
1144 -- The reference to the entry or entry family
1146 Index : Node_Id;
1147 -- The index expression for an entry family reference, or
1148 -- the Empty if Entry_Ref references a simple entry.
1150 begin
1151 if Nkind (Pref) = N_Indexed_Component then
1152 Entry_Ref := Prefix (Pref);
1153 Index := First (Expressions (Pref));
1154 else
1155 Entry_Ref := Pref;
1156 Index := Empty;
1157 end if;
1159 -- Get expression for Task_Id and the entry entity
1161 if Nkind (Entry_Ref) = N_Selected_Component then
1162 T_Id :=
1163 Make_Attribute_Reference (Loc,
1164 Attribute_Name => Name_Identity,
1165 Prefix => Prefix (Entry_Ref));
1167 Ttyp := Etype (Prefix (Entry_Ref));
1168 Eent := Entity (Selector_Name (Entry_Ref));
1170 else
1171 T_Id :=
1172 Make_Function_Call (Loc,
1173 Name => New_Occurrence_Of (RTE (RE_Current_Task), Loc));
1175 Eent := Entity (Entry_Ref);
1177 -- We have to find the enclosing task to get the task type
1178 -- There must be one, since we already validated this earlier
1180 Ttyp := Current_Scope;
1181 while not Is_Task_Type (Ttyp) loop
1182 Ttyp := Scope (Ttyp);
1183 end loop;
1184 end if;
1186 -- Now rewrite the attribute with a call to Create_AST_Handler
1188 Rewrite (N,
1189 Make_Function_Call (Loc,
1190 Name => New_Occurrence_Of (RTE (RE_Create_AST_Handler), Loc),
1191 Parameter_Associations => New_List (
1192 T_Id,
1193 Entry_Index_Expression (Loc, Eent, Index, Ttyp))));
1195 Analyze_And_Resolve (N, RTE (RE_AST_Handler));
1196 end AST_Entry;
1198 ------------------
1199 -- Bit_Position --
1200 ------------------
1202 -- We compute this if a component clause was present, otherwise we leave
1203 -- the computation up to the back end, since we don't know what layout
1204 -- will be chosen.
1206 -- Note that the attribute can apply to a naked record component
1207 -- in generated code (i.e. the prefix is an identifier that
1208 -- references the component or discriminant entity).
1210 when Attribute_Bit_Position => Bit_Position :
1211 declare
1212 CE : Entity_Id;
1214 begin
1215 if Nkind (Pref) = N_Identifier then
1216 CE := Entity (Pref);
1217 else
1218 CE := Entity (Selector_Name (Pref));
1219 end if;
1221 if Known_Static_Component_Bit_Offset (CE) then
1222 Rewrite (N,
1223 Make_Integer_Literal (Loc,
1224 Intval => Component_Bit_Offset (CE)));
1225 Analyze_And_Resolve (N, Typ);
1227 else
1228 Apply_Universal_Integer_Attribute_Checks (N);
1229 end if;
1230 end Bit_Position;
1232 ------------------
1233 -- Body_Version --
1234 ------------------
1236 -- A reference to P'Body_Version or P'Version is expanded to
1238 -- Vnn : Unsigned;
1239 -- pragma Import (C, Vnn, "uuuuT");
1240 -- ...
1241 -- Get_Version_String (Vnn)
1243 -- where uuuu is the unit name (dots replaced by double underscore)
1244 -- and T is B for the cases of Body_Version, or Version applied to a
1245 -- subprogram acting as its own spec, and S for Version applied to a
1246 -- subprogram spec or package. This sequence of code references the
1247 -- the unsigned constant created in the main program by the binder.
1249 -- A special exception occurs for Standard, where the string
1250 -- returned is a copy of the library string in gnatvsn.ads.
1252 when Attribute_Body_Version | Attribute_Version => Version : declare
1253 E : constant Entity_Id :=
1254 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1255 Pent : Entity_Id;
1256 S : String_Id;
1258 begin
1259 -- If not library unit, get to containing library unit
1261 Pent := Entity (Pref);
1262 while Pent /= Standard_Standard
1263 and then Scope (Pent) /= Standard_Standard
1264 and then not Is_Child_Unit (Pent)
1265 loop
1266 Pent := Scope (Pent);
1267 end loop;
1269 -- Special case Standard and Standard.ASCII
1271 if Pent = Standard_Standard or else Pent = Standard_ASCII then
1272 Rewrite (N,
1273 Make_String_Literal (Loc,
1274 Strval => Verbose_Library_Version));
1276 -- All other cases
1278 else
1279 -- Build required string constant
1281 Get_Name_String (Get_Unit_Name (Pent));
1283 Start_String;
1284 for J in 1 .. Name_Len - 2 loop
1285 if Name_Buffer (J) = '.' then
1286 Store_String_Chars ("__");
1287 else
1288 Store_String_Char (Get_Char_Code (Name_Buffer (J)));
1289 end if;
1290 end loop;
1292 -- Case of subprogram acting as its own spec, always use body
1294 if Nkind (Declaration_Node (Pent)) in N_Subprogram_Specification
1295 and then Nkind (Parent (Declaration_Node (Pent))) =
1296 N_Subprogram_Body
1297 and then Acts_As_Spec (Parent (Declaration_Node (Pent)))
1298 then
1299 Store_String_Chars ("B");
1301 -- Case of no body present, always use spec
1303 elsif not Unit_Requires_Body (Pent) then
1304 Store_String_Chars ("S");
1306 -- Otherwise use B for Body_Version, S for spec
1308 elsif Id = Attribute_Body_Version then
1309 Store_String_Chars ("B");
1310 else
1311 Store_String_Chars ("S");
1312 end if;
1314 S := End_String;
1315 Lib.Version_Referenced (S);
1317 -- Insert the object declaration
1319 Insert_Actions (N, New_List (
1320 Make_Object_Declaration (Loc,
1321 Defining_Identifier => E,
1322 Object_Definition =>
1323 New_Occurrence_Of (RTE (RE_Unsigned), Loc))));
1325 -- Set entity as imported with correct external name
1327 Set_Is_Imported (E);
1328 Set_Interface_Name (E, Make_String_Literal (Loc, S));
1330 -- Set entity as internal to ensure proper Sprint output of its
1331 -- implicit importation.
1333 Set_Is_Internal (E);
1335 -- And now rewrite original reference
1337 Rewrite (N,
1338 Make_Function_Call (Loc,
1339 Name => New_Reference_To (RTE (RE_Get_Version_String), Loc),
1340 Parameter_Associations => New_List (
1341 New_Occurrence_Of (E, Loc))));
1342 end if;
1344 Analyze_And_Resolve (N, RTE (RE_Version_String));
1345 end Version;
1347 -------------
1348 -- Ceiling --
1349 -------------
1351 -- Transforms 'Ceiling into a call to the floating-point attribute
1352 -- function Ceiling in Fat_xxx (where xxx is the root type)
1354 when Attribute_Ceiling =>
1355 Expand_Fpt_Attribute_R (N);
1357 --------------
1358 -- Callable --
1359 --------------
1361 -- Transforms 'Callable attribute into a call to the Callable function
1363 when Attribute_Callable => Callable :
1364 begin
1365 -- We have an object of a task interface class-wide type as a prefix
1366 -- to Callable. Generate:
1367 -- callable (Task_Id (Pref._disp_get_task_id));
1369 if Ada_Version >= Ada_05
1370 and then Ekind (Ptyp) = E_Class_Wide_Type
1371 and then Is_Interface (Ptyp)
1372 and then Is_Task_Interface (Ptyp)
1373 then
1374 Rewrite (N,
1375 Make_Function_Call (Loc,
1376 Name =>
1377 New_Reference_To (RTE (RE_Callable), Loc),
1378 Parameter_Associations => New_List (
1379 Make_Unchecked_Type_Conversion (Loc,
1380 Subtype_Mark =>
1381 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
1382 Expression =>
1383 Make_Selected_Component (Loc,
1384 Prefix =>
1385 New_Copy_Tree (Pref),
1386 Selector_Name =>
1387 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))))));
1389 else
1390 Rewrite (N,
1391 Build_Call_With_Task (Pref, RTE (RE_Callable)));
1392 end if;
1394 Analyze_And_Resolve (N, Standard_Boolean);
1395 end Callable;
1397 ------------
1398 -- Caller --
1399 ------------
1401 -- Transforms 'Caller attribute into a call to either the
1402 -- Task_Entry_Caller or the Protected_Entry_Caller function.
1404 when Attribute_Caller => Caller : declare
1405 Id_Kind : constant Entity_Id := RTE (RO_AT_Task_Id);
1406 Ent : constant Entity_Id := Entity (Pref);
1407 Conctype : constant Entity_Id := Scope (Ent);
1408 Nest_Depth : Integer := 0;
1409 Name : Node_Id;
1410 S : Entity_Id;
1412 begin
1413 -- Protected case
1415 if Is_Protected_Type (Conctype) then
1416 case Corresponding_Runtime_Package (Conctype) is
1417 when System_Tasking_Protected_Objects_Entries =>
1418 Name :=
1419 New_Reference_To
1420 (RTE (RE_Protected_Entry_Caller), Loc);
1422 when System_Tasking_Protected_Objects_Single_Entry =>
1423 Name :=
1424 New_Reference_To
1425 (RTE (RE_Protected_Single_Entry_Caller), Loc);
1427 when others =>
1428 raise Program_Error;
1429 end case;
1431 Rewrite (N,
1432 Unchecked_Convert_To (Id_Kind,
1433 Make_Function_Call (Loc,
1434 Name => Name,
1435 Parameter_Associations => New_List (
1436 New_Reference_To
1437 (Find_Protection_Object (Current_Scope), Loc)))));
1439 -- Task case
1441 else
1442 -- Determine the nesting depth of the E'Caller attribute, that
1443 -- is, how many accept statements are nested within the accept
1444 -- statement for E at the point of E'Caller. The runtime uses
1445 -- this depth to find the specified entry call.
1447 for J in reverse 0 .. Scope_Stack.Last loop
1448 S := Scope_Stack.Table (J).Entity;
1450 -- We should not reach the scope of the entry, as it should
1451 -- already have been checked in Sem_Attr that this attribute
1452 -- reference is within a matching accept statement.
1454 pragma Assert (S /= Conctype);
1456 if S = Ent then
1457 exit;
1459 elsif Is_Entry (S) then
1460 Nest_Depth := Nest_Depth + 1;
1461 end if;
1462 end loop;
1464 Rewrite (N,
1465 Unchecked_Convert_To (Id_Kind,
1466 Make_Function_Call (Loc,
1467 Name =>
1468 New_Reference_To (RTE (RE_Task_Entry_Caller), Loc),
1469 Parameter_Associations => New_List (
1470 Make_Integer_Literal (Loc,
1471 Intval => Int (Nest_Depth))))));
1472 end if;
1474 Analyze_And_Resolve (N, Id_Kind);
1475 end Caller;
1477 -------------
1478 -- Compose --
1479 -------------
1481 -- Transforms 'Compose into a call to the floating-point attribute
1482 -- function Compose in Fat_xxx (where xxx is the root type)
1484 -- Note: we strictly should have special code here to deal with the
1485 -- case of absurdly negative arguments (less than Integer'First)
1486 -- which will return a (signed) zero value, but it hardly seems
1487 -- worth the effort. Absurdly large positive arguments will raise
1488 -- constraint error which is fine.
1490 when Attribute_Compose =>
1491 Expand_Fpt_Attribute_RI (N);
1493 -----------------
1494 -- Constrained --
1495 -----------------
1497 when Attribute_Constrained => Constrained : declare
1498 Formal_Ent : constant Entity_Id := Param_Entity (Pref);
1500 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean;
1501 -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a
1502 -- view of an aliased object whose subtype is constrained.
1504 ---------------------------------
1505 -- Is_Constrained_Aliased_View --
1506 ---------------------------------
1508 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean is
1509 E : Entity_Id;
1511 begin
1512 if Is_Entity_Name (Obj) then
1513 E := Entity (Obj);
1515 if Present (Renamed_Object (E)) then
1516 return Is_Constrained_Aliased_View (Renamed_Object (E));
1517 else
1518 return Is_Aliased (E) and then Is_Constrained (Etype (E));
1519 end if;
1521 else
1522 return Is_Aliased_View (Obj)
1523 and then
1524 (Is_Constrained (Etype (Obj))
1525 or else (Nkind (Obj) = N_Explicit_Dereference
1526 and then
1527 not Has_Constrained_Partial_View
1528 (Base_Type (Etype (Obj)))));
1529 end if;
1530 end Is_Constrained_Aliased_View;
1532 -- Start of processing for Constrained
1534 begin
1535 -- Reference to a parameter where the value is passed as an extra
1536 -- actual, corresponding to the extra formal referenced by the
1537 -- Extra_Constrained field of the corresponding formal. If this
1538 -- is an entry in-parameter, it is replaced by a constant renaming
1539 -- for which Extra_Constrained is never created.
1541 if Present (Formal_Ent)
1542 and then Ekind (Formal_Ent) /= E_Constant
1543 and then Present (Extra_Constrained (Formal_Ent))
1544 then
1545 Rewrite (N,
1546 New_Occurrence_Of
1547 (Extra_Constrained (Formal_Ent), Sloc (N)));
1549 -- For variables with a Extra_Constrained field, we use the
1550 -- corresponding entity.
1552 elsif Nkind (Pref) = N_Identifier
1553 and then Ekind (Entity (Pref)) = E_Variable
1554 and then Present (Extra_Constrained (Entity (Pref)))
1555 then
1556 Rewrite (N,
1557 New_Occurrence_Of
1558 (Extra_Constrained (Entity (Pref)), Sloc (N)));
1560 -- For all other entity names, we can tell at compile time
1562 elsif Is_Entity_Name (Pref) then
1563 declare
1564 Ent : constant Entity_Id := Entity (Pref);
1565 Res : Boolean;
1567 begin
1568 -- (RM J.4) obsolescent cases
1570 if Is_Type (Ent) then
1572 -- Private type
1574 if Is_Private_Type (Ent) then
1575 Res := not Has_Discriminants (Ent)
1576 or else Is_Constrained (Ent);
1578 -- It not a private type, must be a generic actual type
1579 -- that corresponded to a private type. We know that this
1580 -- correspondence holds, since otherwise the reference
1581 -- within the generic template would have been illegal.
1583 else
1584 if Is_Composite_Type (Underlying_Type (Ent)) then
1585 Res := Is_Constrained (Ent);
1586 else
1587 Res := True;
1588 end if;
1589 end if;
1591 -- If the prefix is not a variable or is aliased, then
1592 -- definitely true; if it's a formal parameter without an
1593 -- associated extra formal, then treat it as constrained.
1595 -- Ada 2005 (AI-363): An aliased prefix must be known to be
1596 -- constrained in order to set the attribute to True.
1598 elsif not Is_Variable (Pref)
1599 or else Present (Formal_Ent)
1600 or else (Ada_Version < Ada_05
1601 and then Is_Aliased_View (Pref))
1602 or else (Ada_Version >= Ada_05
1603 and then Is_Constrained_Aliased_View (Pref))
1604 then
1605 Res := True;
1607 -- Variable case, look at type to see if it is constrained.
1608 -- Note that the one case where this is not accurate (the
1609 -- procedure formal case), has been handled above.
1611 -- We use the Underlying_Type here (and below) in case the
1612 -- type is private without discriminants, but the full type
1613 -- has discriminants. This case is illegal, but we generate it
1614 -- internally for passing to the Extra_Constrained parameter.
1616 else
1617 Res := Is_Constrained (Underlying_Type (Etype (Ent)));
1618 end if;
1620 Rewrite (N,
1621 New_Reference_To (Boolean_Literals (Res), Loc));
1622 end;
1624 -- Prefix is not an entity name. These are also cases where we can
1625 -- always tell at compile time by looking at the form and type of the
1626 -- prefix. If an explicit dereference of an object with constrained
1627 -- partial view, this is unconstrained (Ada 2005 AI-363).
1629 else
1630 Rewrite (N,
1631 New_Reference_To (
1632 Boolean_Literals (
1633 not Is_Variable (Pref)
1634 or else
1635 (Nkind (Pref) = N_Explicit_Dereference
1636 and then
1637 not Has_Constrained_Partial_View (Base_Type (Ptyp)))
1638 or else Is_Constrained (Underlying_Type (Ptyp))),
1639 Loc));
1640 end if;
1642 Analyze_And_Resolve (N, Standard_Boolean);
1643 end Constrained;
1645 ---------------
1646 -- Copy_Sign --
1647 ---------------
1649 -- Transforms 'Copy_Sign into a call to the floating-point attribute
1650 -- function Copy_Sign in Fat_xxx (where xxx is the root type)
1652 when Attribute_Copy_Sign =>
1653 Expand_Fpt_Attribute_RR (N);
1655 -----------
1656 -- Count --
1657 -----------
1659 -- Transforms 'Count attribute into a call to the Count function
1661 when Attribute_Count => Count : declare
1662 Call : Node_Id;
1663 Conctyp : Entity_Id;
1664 Entnam : Node_Id;
1665 Entry_Id : Entity_Id;
1666 Index : Node_Id;
1667 Name : Node_Id;
1669 begin
1670 -- If the prefix is a member of an entry family, retrieve both
1671 -- entry name and index. For a simple entry there is no index.
1673 if Nkind (Pref) = N_Indexed_Component then
1674 Entnam := Prefix (Pref);
1675 Index := First (Expressions (Pref));
1676 else
1677 Entnam := Pref;
1678 Index := Empty;
1679 end if;
1681 Entry_Id := Entity (Entnam);
1683 -- Find the concurrent type in which this attribute is referenced
1684 -- (there had better be one).
1686 Conctyp := Current_Scope;
1687 while not Is_Concurrent_Type (Conctyp) loop
1688 Conctyp := Scope (Conctyp);
1689 end loop;
1691 -- Protected case
1693 if Is_Protected_Type (Conctyp) then
1694 case Corresponding_Runtime_Package (Conctyp) is
1695 when System_Tasking_Protected_Objects_Entries =>
1696 Name := New_Reference_To (RTE (RE_Protected_Count), Loc);
1698 Call :=
1699 Make_Function_Call (Loc,
1700 Name => Name,
1701 Parameter_Associations => New_List (
1702 New_Reference_To
1703 (Find_Protection_Object (Current_Scope), Loc),
1704 Entry_Index_Expression
1705 (Loc, Entry_Id, Index, Scope (Entry_Id))));
1707 when System_Tasking_Protected_Objects_Single_Entry =>
1708 Name :=
1709 New_Reference_To (RTE (RE_Protected_Count_Entry), Loc);
1711 Call :=
1712 Make_Function_Call (Loc,
1713 Name => Name,
1714 Parameter_Associations => New_List (
1715 New_Reference_To
1716 (Find_Protection_Object (Current_Scope), Loc)));
1718 when others =>
1719 raise Program_Error;
1720 end case;
1722 -- Task case
1724 else
1725 Call :=
1726 Make_Function_Call (Loc,
1727 Name => New_Reference_To (RTE (RE_Task_Count), Loc),
1728 Parameter_Associations => New_List (
1729 Entry_Index_Expression (Loc,
1730 Entry_Id, Index, Scope (Entry_Id))));
1731 end if;
1733 -- The call returns type Natural but the context is universal integer
1734 -- so any integer type is allowed. The attribute was already resolved
1735 -- so its Etype is the required result type. If the base type of the
1736 -- context type is other than Standard.Integer we put in a conversion
1737 -- to the required type. This can be a normal typed conversion since
1738 -- both input and output types of the conversion are integer types
1740 if Base_Type (Typ) /= Base_Type (Standard_Integer) then
1741 Rewrite (N, Convert_To (Typ, Call));
1742 else
1743 Rewrite (N, Call);
1744 end if;
1746 Analyze_And_Resolve (N, Typ);
1747 end Count;
1749 ---------------
1750 -- Elab_Body --
1751 ---------------
1753 -- This processing is shared by Elab_Spec
1755 -- What we do is to insert the following declarations
1757 -- procedure tnn;
1758 -- pragma Import (C, enn, "name___elabb/s");
1760 -- and then the Elab_Body/Spec attribute is replaced by a reference
1761 -- to this defining identifier.
1763 when Attribute_Elab_Body |
1764 Attribute_Elab_Spec =>
1766 Elab_Body : declare
1767 Ent : constant Entity_Id :=
1768 Make_Defining_Identifier (Loc,
1769 New_Internal_Name ('E'));
1770 Str : String_Id;
1771 Lang : Node_Id;
1773 procedure Make_Elab_String (Nod : Node_Id);
1774 -- Given Nod, an identifier, or a selected component, put the
1775 -- image into the current string literal, with double underline
1776 -- between components.
1778 ----------------------
1779 -- Make_Elab_String --
1780 ----------------------
1782 procedure Make_Elab_String (Nod : Node_Id) is
1783 begin
1784 if Nkind (Nod) = N_Selected_Component then
1785 Make_Elab_String (Prefix (Nod));
1787 case VM_Target is
1788 when JVM_Target =>
1789 Store_String_Char ('$');
1790 when CLI_Target =>
1791 Store_String_Char ('.');
1792 when No_VM =>
1793 Store_String_Char ('_');
1794 Store_String_Char ('_');
1795 end case;
1797 Get_Name_String (Chars (Selector_Name (Nod)));
1799 else
1800 pragma Assert (Nkind (Nod) = N_Identifier);
1801 Get_Name_String (Chars (Nod));
1802 end if;
1804 Store_String_Chars (Name_Buffer (1 .. Name_Len));
1805 end Make_Elab_String;
1807 -- Start of processing for Elab_Body/Elab_Spec
1809 begin
1810 -- First we need to prepare the string literal for the name of
1811 -- the elaboration routine to be referenced.
1813 Start_String;
1814 Make_Elab_String (Pref);
1816 if VM_Target = No_VM then
1817 Store_String_Chars ("___elab");
1818 Lang := Make_Identifier (Loc, Name_C);
1819 else
1820 Store_String_Chars ("._elab");
1821 Lang := Make_Identifier (Loc, Name_Ada);
1822 end if;
1824 if Id = Attribute_Elab_Body then
1825 Store_String_Char ('b');
1826 else
1827 Store_String_Char ('s');
1828 end if;
1830 Str := End_String;
1832 Insert_Actions (N, New_List (
1833 Make_Subprogram_Declaration (Loc,
1834 Specification =>
1835 Make_Procedure_Specification (Loc,
1836 Defining_Unit_Name => Ent)),
1838 Make_Pragma (Loc,
1839 Chars => Name_Import,
1840 Pragma_Argument_Associations => New_List (
1841 Make_Pragma_Argument_Association (Loc,
1842 Expression => Lang),
1844 Make_Pragma_Argument_Association (Loc,
1845 Expression =>
1846 Make_Identifier (Loc, Chars (Ent))),
1848 Make_Pragma_Argument_Association (Loc,
1849 Expression =>
1850 Make_String_Literal (Loc, Str))))));
1852 Set_Entity (N, Ent);
1853 Rewrite (N, New_Occurrence_Of (Ent, Loc));
1854 end Elab_Body;
1856 ----------------
1857 -- Elaborated --
1858 ----------------
1860 -- Elaborated is always True for preelaborated units, predefined units,
1861 -- pure units and units which have Elaborate_Body pragmas. These units
1862 -- have no elaboration entity.
1864 -- Note: The Elaborated attribute is never passed to the back end
1866 when Attribute_Elaborated => Elaborated : declare
1867 Ent : constant Entity_Id := Entity (Pref);
1869 begin
1870 if Present (Elaboration_Entity (Ent)) then
1871 Rewrite (N,
1872 New_Occurrence_Of (Elaboration_Entity (Ent), Loc));
1873 else
1874 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
1875 end if;
1876 end Elaborated;
1878 --------------
1879 -- Enum_Rep --
1880 --------------
1882 when Attribute_Enum_Rep => Enum_Rep :
1883 begin
1884 -- X'Enum_Rep (Y) expands to
1886 -- target-type (Y)
1888 -- This is simply a direct conversion from the enumeration type to
1889 -- the target integer type, which is treated by the back end as a
1890 -- normal integer conversion, treating the enumeration type as an
1891 -- integer, which is exactly what we want! We set Conversion_OK to
1892 -- make sure that the analyzer does not complain about what otherwise
1893 -- might be an illegal conversion.
1895 if Is_Non_Empty_List (Exprs) then
1896 Rewrite (N,
1897 OK_Convert_To (Typ, Relocate_Node (First (Exprs))));
1899 -- X'Enum_Rep where X is an enumeration literal is replaced by
1900 -- the literal value.
1902 elsif Ekind (Entity (Pref)) = E_Enumeration_Literal then
1903 Rewrite (N,
1904 Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Pref))));
1906 -- If this is a renaming of a literal, recover the representation
1907 -- of the original.
1909 elsif Ekind (Entity (Pref)) = E_Constant
1910 and then Present (Renamed_Object (Entity (Pref)))
1911 and then
1912 Ekind (Entity (Renamed_Object (Entity (Pref))))
1913 = E_Enumeration_Literal
1914 then
1915 Rewrite (N,
1916 Make_Integer_Literal (Loc,
1917 Enumeration_Rep (Entity (Renamed_Object (Entity (Pref))))));
1919 -- X'Enum_Rep where X is an object does a direct unchecked conversion
1920 -- of the object value, as described for the type case above.
1922 else
1923 Rewrite (N,
1924 OK_Convert_To (Typ, Relocate_Node (Pref)));
1925 end if;
1927 Set_Etype (N, Typ);
1928 Analyze_And_Resolve (N, Typ);
1929 end Enum_Rep;
1931 --------------
1932 -- Enum_Val --
1933 --------------
1935 when Attribute_Enum_Val => Enum_Val : declare
1936 Expr : Node_Id;
1937 Btyp : constant Entity_Id := Base_Type (Ptyp);
1939 begin
1940 -- X'Enum_Val (Y) expands to
1942 -- [constraint_error when _rep_to_pos (Y, False) = -1, msg]
1943 -- X!(Y);
1945 Expr := Unchecked_Convert_To (Ptyp, First (Exprs));
1947 Insert_Action (N,
1948 Make_Raise_Constraint_Error (Loc,
1949 Condition =>
1950 Make_Op_Eq (Loc,
1951 Left_Opnd =>
1952 Make_Function_Call (Loc,
1953 Name =>
1954 New_Reference_To (TSS (Btyp, TSS_Rep_To_Pos), Loc),
1955 Parameter_Associations => New_List (
1956 Relocate_Node (Duplicate_Subexpr (Expr)),
1957 New_Occurrence_Of (Standard_False, Loc))),
1959 Right_Opnd => Make_Integer_Literal (Loc, -1)),
1960 Reason => CE_Range_Check_Failed));
1962 Rewrite (N, Expr);
1963 Analyze_And_Resolve (N, Ptyp);
1964 end Enum_Val;
1966 --------------
1967 -- Exponent --
1968 --------------
1970 -- Transforms 'Exponent into a call to the floating-point attribute
1971 -- function Exponent in Fat_xxx (where xxx is the root type)
1973 when Attribute_Exponent =>
1974 Expand_Fpt_Attribute_R (N);
1976 ------------------
1977 -- External_Tag --
1978 ------------------
1980 -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag)
1982 when Attribute_External_Tag => External_Tag :
1983 begin
1984 Rewrite (N,
1985 Make_Function_Call (Loc,
1986 Name => New_Reference_To (RTE (RE_External_Tag), Loc),
1987 Parameter_Associations => New_List (
1988 Make_Attribute_Reference (Loc,
1989 Attribute_Name => Name_Tag,
1990 Prefix => Prefix (N)))));
1992 Analyze_And_Resolve (N, Standard_String);
1993 end External_Tag;
1995 -----------
1996 -- First --
1997 -----------
1999 when Attribute_First =>
2001 -- If the prefix type is a constrained packed array type which
2002 -- already has a Packed_Array_Type representation defined, then
2003 -- replace this attribute with a direct reference to 'First of the
2004 -- appropriate index subtype (since otherwise the back end will try
2005 -- to give us the value of 'First for this implementation type).
2007 if Is_Constrained_Packed_Array (Ptyp) then
2008 Rewrite (N,
2009 Make_Attribute_Reference (Loc,
2010 Attribute_Name => Name_First,
2011 Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
2012 Analyze_And_Resolve (N, Typ);
2014 elsif Is_Access_Type (Ptyp) then
2015 Apply_Access_Check (N);
2016 end if;
2018 ---------------
2019 -- First_Bit --
2020 ---------------
2022 -- Compute this if component clause was present, otherwise we leave the
2023 -- computation to be completed in the back-end, since we don't know what
2024 -- layout will be chosen.
2026 when Attribute_First_Bit => First_Bit : declare
2027 CE : constant Entity_Id := Entity (Selector_Name (Pref));
2029 begin
2030 if Known_Static_Component_Bit_Offset (CE) then
2031 Rewrite (N,
2032 Make_Integer_Literal (Loc,
2033 Component_Bit_Offset (CE) mod System_Storage_Unit));
2035 Analyze_And_Resolve (N, Typ);
2037 else
2038 Apply_Universal_Integer_Attribute_Checks (N);
2039 end if;
2040 end First_Bit;
2042 -----------------
2043 -- Fixed_Value --
2044 -----------------
2046 -- We transform:
2048 -- fixtype'Fixed_Value (integer-value)
2050 -- into
2052 -- fixtype(integer-value)
2054 -- We do all the required analysis of the conversion here, because we do
2055 -- not want this to go through the fixed-point conversion circuits. Note
2056 -- that the back end always treats fixed-point as equivalent to the
2057 -- corresponding integer type anyway.
2059 when Attribute_Fixed_Value => Fixed_Value :
2060 begin
2061 Rewrite (N,
2062 Make_Type_Conversion (Loc,
2063 Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
2064 Expression => Relocate_Node (First (Exprs))));
2065 Set_Etype (N, Entity (Pref));
2066 Set_Analyzed (N);
2068 -- Note: it might appear that a properly analyzed unchecked conversion
2069 -- would be just fine here, but that's not the case, since the full
2070 -- range checks performed by the following call are critical!
2072 Apply_Type_Conversion_Checks (N);
2073 end Fixed_Value;
2075 -----------
2076 -- Floor --
2077 -----------
2079 -- Transforms 'Floor into a call to the floating-point attribute
2080 -- function Floor in Fat_xxx (where xxx is the root type)
2082 when Attribute_Floor =>
2083 Expand_Fpt_Attribute_R (N);
2085 ----------
2086 -- Fore --
2087 ----------
2089 -- For the fixed-point type Typ:
2091 -- Typ'Fore
2093 -- expands into
2095 -- Result_Type (System.Fore (Universal_Real (Type'First)),
2096 -- Universal_Real (Type'Last))
2098 -- Note that we know that the type is a non-static subtype, or Fore
2099 -- would have itself been computed dynamically in Eval_Attribute.
2101 when Attribute_Fore => Fore : begin
2102 Rewrite (N,
2103 Convert_To (Typ,
2104 Make_Function_Call (Loc,
2105 Name => New_Reference_To (RTE (RE_Fore), Loc),
2107 Parameter_Associations => New_List (
2108 Convert_To (Universal_Real,
2109 Make_Attribute_Reference (Loc,
2110 Prefix => New_Reference_To (Ptyp, Loc),
2111 Attribute_Name => Name_First)),
2113 Convert_To (Universal_Real,
2114 Make_Attribute_Reference (Loc,
2115 Prefix => New_Reference_To (Ptyp, Loc),
2116 Attribute_Name => Name_Last))))));
2118 Analyze_And_Resolve (N, Typ);
2119 end Fore;
2121 --------------
2122 -- Fraction --
2123 --------------
2125 -- Transforms 'Fraction into a call to the floating-point attribute
2126 -- function Fraction in Fat_xxx (where xxx is the root type)
2128 when Attribute_Fraction =>
2129 Expand_Fpt_Attribute_R (N);
2131 --------------
2132 -- From_Any --
2133 --------------
2135 when Attribute_From_Any => From_Any : declare
2136 P_Type : constant Entity_Id := Etype (Pref);
2137 Decls : constant List_Id := New_List;
2138 begin
2139 Rewrite (N,
2140 Build_From_Any_Call (P_Type,
2141 Relocate_Node (First (Exprs)),
2142 Decls));
2143 Insert_Actions (N, Decls);
2144 Analyze_And_Resolve (N, P_Type);
2145 end From_Any;
2147 --------------
2148 -- Identity --
2149 --------------
2151 -- For an exception returns a reference to the exception data:
2152 -- Exception_Id!(Prefix'Reference)
2154 -- For a task it returns a reference to the _task_id component of
2155 -- corresponding record:
2157 -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined
2159 -- in Ada.Task_Identification
2161 when Attribute_Identity => Identity : declare
2162 Id_Kind : Entity_Id;
2164 begin
2165 if Ptyp = Standard_Exception_Type then
2166 Id_Kind := RTE (RE_Exception_Id);
2168 if Present (Renamed_Object (Entity (Pref))) then
2169 Set_Entity (Pref, Renamed_Object (Entity (Pref)));
2170 end if;
2172 Rewrite (N,
2173 Unchecked_Convert_To (Id_Kind, Make_Reference (Loc, Pref)));
2174 else
2175 Id_Kind := RTE (RO_AT_Task_Id);
2177 -- If the prefix is a task interface, the Task_Id is obtained
2178 -- dynamically through a dispatching call, as for other task
2179 -- attributes applied to interfaces.
2181 if Ada_Version >= Ada_05
2182 and then Ekind (Ptyp) = E_Class_Wide_Type
2183 and then Is_Interface (Ptyp)
2184 and then Is_Task_Interface (Ptyp)
2185 then
2186 Rewrite (N,
2187 Unchecked_Convert_To (Id_Kind,
2188 Make_Selected_Component (Loc,
2189 Prefix =>
2190 New_Copy_Tree (Pref),
2191 Selector_Name =>
2192 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))));
2194 else
2195 Rewrite (N,
2196 Unchecked_Convert_To (Id_Kind, Concurrent_Ref (Pref)));
2197 end if;
2198 end if;
2200 Analyze_And_Resolve (N, Id_Kind);
2201 end Identity;
2203 -----------
2204 -- Image --
2205 -----------
2207 -- Image attribute is handled in separate unit Exp_Imgv
2209 when Attribute_Image =>
2210 Exp_Imgv.Expand_Image_Attribute (N);
2212 ---------
2213 -- Img --
2214 ---------
2216 -- X'Img is expanded to typ'Image (X), where typ is the type of X
2218 when Attribute_Img => Img :
2219 begin
2220 Rewrite (N,
2221 Make_Attribute_Reference (Loc,
2222 Prefix => New_Reference_To (Ptyp, Loc),
2223 Attribute_Name => Name_Image,
2224 Expressions => New_List (Relocate_Node (Pref))));
2226 Analyze_And_Resolve (N, Standard_String);
2227 end Img;
2229 -----------
2230 -- Input --
2231 -----------
2233 when Attribute_Input => Input : declare
2234 P_Type : constant Entity_Id := Entity (Pref);
2235 B_Type : constant Entity_Id := Base_Type (P_Type);
2236 U_Type : constant Entity_Id := Underlying_Type (P_Type);
2237 Strm : constant Node_Id := First (Exprs);
2238 Fname : Entity_Id;
2239 Decl : Node_Id;
2240 Call : Node_Id;
2241 Prag : Node_Id;
2242 Arg2 : Node_Id;
2243 Rfunc : Node_Id;
2245 Cntrl : Node_Id := Empty;
2246 -- Value for controlling argument in call. Always Empty except in
2247 -- the dispatching (class-wide type) case, where it is a reference
2248 -- to the dummy object initialized to the right internal tag.
2250 procedure Freeze_Stream_Subprogram (F : Entity_Id);
2251 -- The expansion of the attribute reference may generate a call to
2252 -- a user-defined stream subprogram that is frozen by the call. This
2253 -- can lead to access-before-elaboration problem if the reference
2254 -- appears in an object declaration and the subprogram body has not
2255 -- been seen. The freezing of the subprogram requires special code
2256 -- because it appears in an expanded context where expressions do
2257 -- not freeze their constituents.
2259 ------------------------------
2260 -- Freeze_Stream_Subprogram --
2261 ------------------------------
2263 procedure Freeze_Stream_Subprogram (F : Entity_Id) is
2264 Decl : constant Node_Id := Unit_Declaration_Node (F);
2265 Bod : Node_Id;
2267 begin
2268 -- If this is user-defined subprogram, the corresponding
2269 -- stream function appears as a renaming-as-body, and the
2270 -- user subprogram must be retrieved by tree traversal.
2272 if Present (Decl)
2273 and then Nkind (Decl) = N_Subprogram_Declaration
2274 and then Present (Corresponding_Body (Decl))
2275 then
2276 Bod := Corresponding_Body (Decl);
2278 if Nkind (Unit_Declaration_Node (Bod)) =
2279 N_Subprogram_Renaming_Declaration
2280 then
2281 Set_Is_Frozen (Entity (Name (Unit_Declaration_Node (Bod))));
2282 end if;
2283 end if;
2284 end Freeze_Stream_Subprogram;
2286 -- Start of processing for Input
2288 begin
2289 -- If no underlying type, we have an error that will be diagnosed
2290 -- elsewhere, so here we just completely ignore the expansion.
2292 if No (U_Type) then
2293 return;
2294 end if;
2296 -- If there is a TSS for Input, just call it
2298 Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input);
2300 if Present (Fname) then
2301 null;
2303 else
2304 -- If there is a Stream_Convert pragma, use it, we rewrite
2306 -- sourcetyp'Input (stream)
2308 -- as
2310 -- sourcetyp (streamread (strmtyp'Input (stream)));
2312 -- where streamread is the given Read function that converts an
2313 -- argument of type strmtyp to type sourcetyp or a type from which
2314 -- it is derived (extra conversion required for the derived case).
2316 Prag := Get_Stream_Convert_Pragma (P_Type);
2318 if Present (Prag) then
2319 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
2320 Rfunc := Entity (Expression (Arg2));
2322 Rewrite (N,
2323 Convert_To (B_Type,
2324 Make_Function_Call (Loc,
2325 Name => New_Occurrence_Of (Rfunc, Loc),
2326 Parameter_Associations => New_List (
2327 Make_Attribute_Reference (Loc,
2328 Prefix =>
2329 New_Occurrence_Of
2330 (Etype (First_Formal (Rfunc)), Loc),
2331 Attribute_Name => Name_Input,
2332 Expressions => Exprs)))));
2334 Analyze_And_Resolve (N, B_Type);
2335 return;
2337 -- Elementary types
2339 elsif Is_Elementary_Type (U_Type) then
2341 -- A special case arises if we have a defined _Read routine,
2342 -- since in this case we are required to call this routine.
2344 if Present (TSS (Base_Type (U_Type), TSS_Stream_Read)) then
2345 Build_Record_Or_Elementary_Input_Function
2346 (Loc, U_Type, Decl, Fname);
2347 Insert_Action (N, Decl);
2349 -- For normal cases, we call the I_xxx routine directly
2351 else
2352 Rewrite (N, Build_Elementary_Input_Call (N));
2353 Analyze_And_Resolve (N, P_Type);
2354 return;
2355 end if;
2357 -- Array type case
2359 elsif Is_Array_Type (U_Type) then
2360 Build_Array_Input_Function (Loc, U_Type, Decl, Fname);
2361 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
2363 -- Dispatching case with class-wide type
2365 elsif Is_Class_Wide_Type (P_Type) then
2367 -- No need to do anything else compiling under restriction
2368 -- No_Dispatching_Calls. During the semantic analysis we
2369 -- already notified such violation.
2371 if Restriction_Active (No_Dispatching_Calls) then
2372 return;
2373 end if;
2375 declare
2376 Rtyp : constant Entity_Id := Root_Type (P_Type);
2377 Dnn : Entity_Id;
2378 Decl : Node_Id;
2380 begin
2381 -- Read the internal tag (RM 13.13.2(34)) and use it to
2382 -- initialize a dummy tag object:
2384 -- Dnn : Ada.Tags.Tag
2385 -- := Descendant_Tag (String'Input (Strm), P_Type);
2387 -- This dummy object is used only to provide a controlling
2388 -- argument for the eventual _Input call. Descendant_Tag is
2389 -- called rather than Internal_Tag to ensure that we have a
2390 -- tag for a type that is descended from the prefix type and
2391 -- declared at the same accessibility level (the exception
2392 -- Tag_Error will be raised otherwise). The level check is
2393 -- required for Ada 2005 because tagged types can be
2394 -- extended in nested scopes (AI-344).
2396 Dnn :=
2397 Make_Defining_Identifier (Loc,
2398 Chars => New_Internal_Name ('D'));
2400 Decl :=
2401 Make_Object_Declaration (Loc,
2402 Defining_Identifier => Dnn,
2403 Object_Definition =>
2404 New_Occurrence_Of (RTE (RE_Tag), Loc),
2405 Expression =>
2406 Make_Function_Call (Loc,
2407 Name =>
2408 New_Occurrence_Of (RTE (RE_Descendant_Tag), Loc),
2409 Parameter_Associations => New_List (
2410 Make_Attribute_Reference (Loc,
2411 Prefix =>
2412 New_Occurrence_Of (Standard_String, Loc),
2413 Attribute_Name => Name_Input,
2414 Expressions => New_List (
2415 Relocate_Node
2416 (Duplicate_Subexpr (Strm)))),
2417 Make_Attribute_Reference (Loc,
2418 Prefix => New_Reference_To (P_Type, Loc),
2419 Attribute_Name => Name_Tag))));
2421 Insert_Action (N, Decl);
2423 -- Now we need to get the entity for the call, and construct
2424 -- a function call node, where we preset a reference to Dnn
2425 -- as the controlling argument (doing an unchecked convert
2426 -- to the class-wide tagged type to make it look like a real
2427 -- tagged object).
2429 Fname := Find_Prim_Op (Rtyp, TSS_Stream_Input);
2430 Cntrl := Unchecked_Convert_To (P_Type,
2431 New_Occurrence_Of (Dnn, Loc));
2432 Set_Etype (Cntrl, P_Type);
2433 Set_Parent (Cntrl, N);
2434 end;
2436 -- For tagged types, use the primitive Input function
2438 elsif Is_Tagged_Type (U_Type) then
2439 Fname := Find_Prim_Op (U_Type, TSS_Stream_Input);
2441 -- All other record type cases, including protected records. The
2442 -- latter only arise for expander generated code for handling
2443 -- shared passive partition access.
2445 else
2446 pragma Assert
2447 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
2449 -- Ada 2005 (AI-216): Program_Error is raised executing default
2450 -- implementation of the Input attribute of an unchecked union
2451 -- type if the type lacks default discriminant values.
2453 if Is_Unchecked_Union (Base_Type (U_Type))
2454 and then No (Discriminant_Constraint (U_Type))
2455 then
2456 Insert_Action (N,
2457 Make_Raise_Program_Error (Loc,
2458 Reason => PE_Unchecked_Union_Restriction));
2460 return;
2461 end if;
2463 Build_Record_Or_Elementary_Input_Function
2464 (Loc, Base_Type (U_Type), Decl, Fname);
2465 Insert_Action (N, Decl);
2467 if Nkind (Parent (N)) = N_Object_Declaration
2468 and then Is_Record_Type (U_Type)
2469 then
2470 -- The stream function may contain calls to user-defined
2471 -- Read procedures for individual components.
2473 declare
2474 Comp : Entity_Id;
2475 Func : Entity_Id;
2477 begin
2478 Comp := First_Component (U_Type);
2479 while Present (Comp) loop
2480 Func :=
2481 Find_Stream_Subprogram
2482 (Etype (Comp), TSS_Stream_Read);
2484 if Present (Func) then
2485 Freeze_Stream_Subprogram (Func);
2486 end if;
2488 Next_Component (Comp);
2489 end loop;
2490 end;
2491 end if;
2492 end if;
2493 end if;
2495 -- If we fall through, Fname is the function to be called. The result
2496 -- is obtained by calling the appropriate function, then converting
2497 -- the result. The conversion does a subtype check.
2499 Call :=
2500 Make_Function_Call (Loc,
2501 Name => New_Occurrence_Of (Fname, Loc),
2502 Parameter_Associations => New_List (
2503 Relocate_Node (Strm)));
2505 Set_Controlling_Argument (Call, Cntrl);
2506 Rewrite (N, Unchecked_Convert_To (P_Type, Call));
2507 Analyze_And_Resolve (N, P_Type);
2509 if Nkind (Parent (N)) = N_Object_Declaration then
2510 Freeze_Stream_Subprogram (Fname);
2511 end if;
2512 end Input;
2514 -------------------
2515 -- Integer_Value --
2516 -------------------
2518 -- We transform
2520 -- inttype'Fixed_Value (fixed-value)
2522 -- into
2524 -- inttype(integer-value))
2526 -- we do all the required analysis of the conversion here, because we do
2527 -- not want this to go through the fixed-point conversion circuits. Note
2528 -- that the back end always treats fixed-point as equivalent to the
2529 -- corresponding integer type anyway.
2531 when Attribute_Integer_Value => Integer_Value :
2532 begin
2533 Rewrite (N,
2534 Make_Type_Conversion (Loc,
2535 Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
2536 Expression => Relocate_Node (First (Exprs))));
2537 Set_Etype (N, Entity (Pref));
2538 Set_Analyzed (N);
2540 -- Note: it might appear that a properly analyzed unchecked conversion
2541 -- would be just fine here, but that's not the case, since the full
2542 -- range checks performed by the following call are critical!
2544 Apply_Type_Conversion_Checks (N);
2545 end Integer_Value;
2547 -------------------
2548 -- Invalid_Value --
2549 -------------------
2551 when Attribute_Invalid_Value =>
2552 Rewrite (N, Get_Simple_Init_Val (Ptyp, N));
2554 ----------
2555 -- Last --
2556 ----------
2558 when Attribute_Last =>
2560 -- If the prefix type is a constrained packed array type which
2561 -- already has a Packed_Array_Type representation defined, then
2562 -- replace this attribute with a direct reference to 'Last of the
2563 -- appropriate index subtype (since otherwise the back end will try
2564 -- to give us the value of 'Last for this implementation type).
2566 if Is_Constrained_Packed_Array (Ptyp) then
2567 Rewrite (N,
2568 Make_Attribute_Reference (Loc,
2569 Attribute_Name => Name_Last,
2570 Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
2571 Analyze_And_Resolve (N, Typ);
2573 elsif Is_Access_Type (Ptyp) then
2574 Apply_Access_Check (N);
2575 end if;
2577 --------------
2578 -- Last_Bit --
2579 --------------
2581 -- We compute this if a component clause was present, otherwise we leave
2582 -- the computation up to the back end, since we don't know what layout
2583 -- will be chosen.
2585 when Attribute_Last_Bit => Last_Bit : declare
2586 CE : constant Entity_Id := Entity (Selector_Name (Pref));
2588 begin
2589 if Known_Static_Component_Bit_Offset (CE)
2590 and then Known_Static_Esize (CE)
2591 then
2592 Rewrite (N,
2593 Make_Integer_Literal (Loc,
2594 Intval => (Component_Bit_Offset (CE) mod System_Storage_Unit)
2595 + Esize (CE) - 1));
2597 Analyze_And_Resolve (N, Typ);
2599 else
2600 Apply_Universal_Integer_Attribute_Checks (N);
2601 end if;
2602 end Last_Bit;
2604 ------------------
2605 -- Leading_Part --
2606 ------------------
2608 -- Transforms 'Leading_Part into a call to the floating-point attribute
2609 -- function Leading_Part in Fat_xxx (where xxx is the root type)
2611 -- Note: strictly, we should generate special case code to deal with
2612 -- absurdly large positive arguments (greater than Integer'Last), which
2613 -- result in returning the first argument unchanged, but it hardly seems
2614 -- worth the effort. We raise constraint error for absurdly negative
2615 -- arguments which is fine.
2617 when Attribute_Leading_Part =>
2618 Expand_Fpt_Attribute_RI (N);
2620 ------------
2621 -- Length --
2622 ------------
2624 when Attribute_Length => declare
2625 Ityp : Entity_Id;
2626 Xnum : Uint;
2628 begin
2629 -- Processing for packed array types
2631 if Is_Array_Type (Ptyp) and then Is_Packed (Ptyp) then
2632 Ityp := Get_Index_Subtype (N);
2634 -- If the index type, Ityp, is an enumeration type with holes,
2635 -- then we calculate X'Length explicitly using
2637 -- Typ'Max
2638 -- (0, Ityp'Pos (X'Last (N)) -
2639 -- Ityp'Pos (X'First (N)) + 1);
2641 -- Since the bounds in the template are the representation values
2642 -- and the back end would get the wrong value.
2644 if Is_Enumeration_Type (Ityp)
2645 and then Present (Enum_Pos_To_Rep (Base_Type (Ityp)))
2646 then
2647 if No (Exprs) then
2648 Xnum := Uint_1;
2649 else
2650 Xnum := Expr_Value (First (Expressions (N)));
2651 end if;
2653 Rewrite (N,
2654 Make_Attribute_Reference (Loc,
2655 Prefix => New_Occurrence_Of (Typ, Loc),
2656 Attribute_Name => Name_Max,
2657 Expressions => New_List
2658 (Make_Integer_Literal (Loc, 0),
2660 Make_Op_Add (Loc,
2661 Left_Opnd =>
2662 Make_Op_Subtract (Loc,
2663 Left_Opnd =>
2664 Make_Attribute_Reference (Loc,
2665 Prefix => New_Occurrence_Of (Ityp, Loc),
2666 Attribute_Name => Name_Pos,
2668 Expressions => New_List (
2669 Make_Attribute_Reference (Loc,
2670 Prefix => Duplicate_Subexpr (Pref),
2671 Attribute_Name => Name_Last,
2672 Expressions => New_List (
2673 Make_Integer_Literal (Loc, Xnum))))),
2675 Right_Opnd =>
2676 Make_Attribute_Reference (Loc,
2677 Prefix => New_Occurrence_Of (Ityp, Loc),
2678 Attribute_Name => Name_Pos,
2680 Expressions => New_List (
2681 Make_Attribute_Reference (Loc,
2682 Prefix =>
2683 Duplicate_Subexpr_No_Checks (Pref),
2684 Attribute_Name => Name_First,
2685 Expressions => New_List (
2686 Make_Integer_Literal (Loc, Xnum)))))),
2688 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
2690 Analyze_And_Resolve (N, Typ, Suppress => All_Checks);
2691 return;
2693 -- If the prefix type is a constrained packed array type which
2694 -- already has a Packed_Array_Type representation defined, then
2695 -- replace this attribute with a direct reference to 'Range_Length
2696 -- of the appropriate index subtype (since otherwise the back end
2697 -- will try to give us the value of 'Length for this
2698 -- implementation type).
2700 elsif Is_Constrained (Ptyp) then
2701 Rewrite (N,
2702 Make_Attribute_Reference (Loc,
2703 Attribute_Name => Name_Range_Length,
2704 Prefix => New_Reference_To (Ityp, Loc)));
2705 Analyze_And_Resolve (N, Typ);
2706 end if;
2708 -- Access type case
2710 elsif Is_Access_Type (Ptyp) then
2711 Apply_Access_Check (N);
2713 -- If the designated type is a packed array type, then we convert
2714 -- the reference to:
2716 -- typ'Max (0, 1 +
2717 -- xtyp'Pos (Pref'Last (Expr)) -
2718 -- xtyp'Pos (Pref'First (Expr)));
2720 -- This is a bit complex, but it is the easiest thing to do that
2721 -- works in all cases including enum types with holes xtyp here
2722 -- is the appropriate index type.
2724 declare
2725 Dtyp : constant Entity_Id := Designated_Type (Ptyp);
2726 Xtyp : Entity_Id;
2728 begin
2729 if Is_Array_Type (Dtyp) and then Is_Packed (Dtyp) then
2730 Xtyp := Get_Index_Subtype (N);
2732 Rewrite (N,
2733 Make_Attribute_Reference (Loc,
2734 Prefix => New_Occurrence_Of (Typ, Loc),
2735 Attribute_Name => Name_Max,
2736 Expressions => New_List (
2737 Make_Integer_Literal (Loc, 0),
2739 Make_Op_Add (Loc,
2740 Make_Integer_Literal (Loc, 1),
2741 Make_Op_Subtract (Loc,
2742 Left_Opnd =>
2743 Make_Attribute_Reference (Loc,
2744 Prefix => New_Occurrence_Of (Xtyp, Loc),
2745 Attribute_Name => Name_Pos,
2746 Expressions => New_List (
2747 Make_Attribute_Reference (Loc,
2748 Prefix => Duplicate_Subexpr (Pref),
2749 Attribute_Name => Name_Last,
2750 Expressions =>
2751 New_Copy_List (Exprs)))),
2753 Right_Opnd =>
2754 Make_Attribute_Reference (Loc,
2755 Prefix => New_Occurrence_Of (Xtyp, Loc),
2756 Attribute_Name => Name_Pos,
2757 Expressions => New_List (
2758 Make_Attribute_Reference (Loc,
2759 Prefix =>
2760 Duplicate_Subexpr_No_Checks (Pref),
2761 Attribute_Name => Name_First,
2762 Expressions =>
2763 New_Copy_List (Exprs)))))))));
2765 Analyze_And_Resolve (N, Typ);
2766 end if;
2767 end;
2769 -- Otherwise leave it to the back end
2771 else
2772 Apply_Universal_Integer_Attribute_Checks (N);
2773 end if;
2774 end;
2776 -------------
2777 -- Machine --
2778 -------------
2780 -- Transforms 'Machine into a call to the floating-point attribute
2781 -- function Machine in Fat_xxx (where xxx is the root type)
2783 when Attribute_Machine =>
2784 Expand_Fpt_Attribute_R (N);
2786 ----------------------
2787 -- Machine_Rounding --
2788 ----------------------
2790 -- Transforms 'Machine_Rounding into a call to the floating-point
2791 -- attribute function Machine_Rounding in Fat_xxx (where xxx is the root
2792 -- type). Expansion is avoided for cases the back end can handle
2793 -- directly.
2795 when Attribute_Machine_Rounding =>
2796 if not Is_Inline_Floating_Point_Attribute (N) then
2797 Expand_Fpt_Attribute_R (N);
2798 end if;
2800 ------------------
2801 -- Machine_Size --
2802 ------------------
2804 -- Machine_Size is equivalent to Object_Size, so transform it into
2805 -- Object_Size and that way the back end never sees Machine_Size.
2807 when Attribute_Machine_Size =>
2808 Rewrite (N,
2809 Make_Attribute_Reference (Loc,
2810 Prefix => Prefix (N),
2811 Attribute_Name => Name_Object_Size));
2813 Analyze_And_Resolve (N, Typ);
2815 --------------
2816 -- Mantissa --
2817 --------------
2819 -- The only case that can get this far is the dynamic case of the old
2820 -- Ada 83 Mantissa attribute for the fixed-point case. For this case,
2821 -- we expand:
2823 -- typ'Mantissa
2825 -- into
2827 -- ityp (System.Mantissa.Mantissa_Value
2828 -- (Integer'Integer_Value (typ'First),
2829 -- Integer'Integer_Value (typ'Last)));
2831 when Attribute_Mantissa => Mantissa : begin
2832 Rewrite (N,
2833 Convert_To (Typ,
2834 Make_Function_Call (Loc,
2835 Name => New_Occurrence_Of (RTE (RE_Mantissa_Value), Loc),
2837 Parameter_Associations => New_List (
2839 Make_Attribute_Reference (Loc,
2840 Prefix => New_Occurrence_Of (Standard_Integer, Loc),
2841 Attribute_Name => Name_Integer_Value,
2842 Expressions => New_List (
2844 Make_Attribute_Reference (Loc,
2845 Prefix => New_Occurrence_Of (Ptyp, Loc),
2846 Attribute_Name => Name_First))),
2848 Make_Attribute_Reference (Loc,
2849 Prefix => New_Occurrence_Of (Standard_Integer, Loc),
2850 Attribute_Name => Name_Integer_Value,
2851 Expressions => New_List (
2853 Make_Attribute_Reference (Loc,
2854 Prefix => New_Occurrence_Of (Ptyp, Loc),
2855 Attribute_Name => Name_Last)))))));
2857 Analyze_And_Resolve (N, Typ);
2858 end Mantissa;
2860 --------------------
2861 -- Mechanism_Code --
2862 --------------------
2864 when Attribute_Mechanism_Code =>
2866 -- We must replace the prefix in the renamed case
2868 if Is_Entity_Name (Pref)
2869 and then Present (Alias (Entity (Pref)))
2870 then
2871 Set_Renamed_Subprogram (Pref, Alias (Entity (Pref)));
2872 end if;
2874 ---------
2875 -- Mod --
2876 ---------
2878 when Attribute_Mod => Mod_Case : declare
2879 Arg : constant Node_Id := Relocate_Node (First (Exprs));
2880 Hi : constant Node_Id := Type_High_Bound (Etype (Arg));
2881 Modv : constant Uint := Modulus (Btyp);
2883 begin
2885 -- This is not so simple. The issue is what type to use for the
2886 -- computation of the modular value.
2888 -- The easy case is when the modulus value is within the bounds
2889 -- of the signed integer type of the argument. In this case we can
2890 -- just do the computation in that signed integer type, and then
2891 -- do an ordinary conversion to the target type.
2893 if Modv <= Expr_Value (Hi) then
2894 Rewrite (N,
2895 Convert_To (Btyp,
2896 Make_Op_Mod (Loc,
2897 Left_Opnd => Arg,
2898 Right_Opnd => Make_Integer_Literal (Loc, Modv))));
2900 -- Here we know that the modulus is larger than type'Last of the
2901 -- integer type. There are two cases to consider:
2903 -- a) The integer value is non-negative. In this case, it is
2904 -- returned as the result (since it is less than the modulus).
2906 -- b) The integer value is negative. In this case, we know that the
2907 -- result is modulus + value, where the value might be as small as
2908 -- -modulus. The trouble is what type do we use to do the subtract.
2909 -- No type will do, since modulus can be as big as 2**64, and no
2910 -- integer type accommodates this value. Let's do bit of algebra
2912 -- modulus + value
2913 -- = modulus - (-value)
2914 -- = (modulus - 1) - (-value - 1)
2916 -- Now modulus - 1 is certainly in range of the modular type.
2917 -- -value is in the range 1 .. modulus, so -value -1 is in the
2918 -- range 0 .. modulus-1 which is in range of the modular type.
2919 -- Furthermore, (-value - 1) can be expressed as -(value + 1)
2920 -- which we can compute using the integer base type.
2922 -- Once this is done we analyze the conditional expression without
2923 -- range checks, because we know everything is in range, and we
2924 -- want to prevent spurious warnings on either branch.
2926 else
2927 Rewrite (N,
2928 Make_Conditional_Expression (Loc,
2929 Expressions => New_List (
2930 Make_Op_Ge (Loc,
2931 Left_Opnd => Duplicate_Subexpr (Arg),
2932 Right_Opnd => Make_Integer_Literal (Loc, 0)),
2934 Convert_To (Btyp,
2935 Duplicate_Subexpr_No_Checks (Arg)),
2937 Make_Op_Subtract (Loc,
2938 Left_Opnd =>
2939 Make_Integer_Literal (Loc,
2940 Intval => Modv - 1),
2941 Right_Opnd =>
2942 Convert_To (Btyp,
2943 Make_Op_Minus (Loc,
2944 Right_Opnd =>
2945 Make_Op_Add (Loc,
2946 Left_Opnd => Duplicate_Subexpr_No_Checks (Arg),
2947 Right_Opnd =>
2948 Make_Integer_Literal (Loc,
2949 Intval => 1))))))));
2951 end if;
2953 Analyze_And_Resolve (N, Btyp, Suppress => All_Checks);
2954 end Mod_Case;
2956 -----------
2957 -- Model --
2958 -----------
2960 -- Transforms 'Model into a call to the floating-point attribute
2961 -- function Model in Fat_xxx (where xxx is the root type)
2963 when Attribute_Model =>
2964 Expand_Fpt_Attribute_R (N);
2966 -----------------
2967 -- Object_Size --
2968 -----------------
2970 -- The processing for Object_Size shares the processing for Size
2972 ---------
2973 -- Old --
2974 ---------
2976 when Attribute_Old => Old : declare
2977 Tnn : constant Entity_Id :=
2978 Make_Defining_Identifier (Loc,
2979 Chars => New_Internal_Name ('T'));
2980 Subp : Node_Id;
2981 Asn_Stm : Node_Id;
2983 begin
2984 -- Find the nearest subprogram body, ignoring _Preconditions
2986 Subp := N;
2987 loop
2988 Subp := Parent (Subp);
2989 exit when Nkind (Subp) = N_Subprogram_Body
2990 and then Chars (Defining_Entity (Subp)) /= Name_uPostconditions;
2991 end loop;
2993 -- Insert the assignment at the start of the declarations
2995 Asn_Stm :=
2996 Make_Object_Declaration (Loc,
2997 Defining_Identifier => Tnn,
2998 Constant_Present => True,
2999 Object_Definition => New_Occurrence_Of (Etype (N), Loc),
3000 Expression => Pref);
3002 if Is_Empty_List (Declarations (Subp)) then
3003 Set_Declarations (Subp, New_List (Asn_Stm));
3004 Analyze (Asn_Stm);
3005 else
3006 Insert_Action (First (Declarations (Subp)), Asn_Stm);
3007 end if;
3009 Rewrite (N, New_Occurrence_Of (Tnn, Loc));
3010 end Old;
3012 ------------
3013 -- Output --
3014 ------------
3016 when Attribute_Output => Output : declare
3017 P_Type : constant Entity_Id := Entity (Pref);
3018 U_Type : constant Entity_Id := Underlying_Type (P_Type);
3019 Pname : Entity_Id;
3020 Decl : Node_Id;
3021 Prag : Node_Id;
3022 Arg3 : Node_Id;
3023 Wfunc : Node_Id;
3025 begin
3026 -- If no underlying type, we have an error that will be diagnosed
3027 -- elsewhere, so here we just completely ignore the expansion.
3029 if No (U_Type) then
3030 return;
3031 end if;
3033 -- If TSS for Output is present, just call it
3035 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output);
3037 if Present (Pname) then
3038 null;
3040 else
3041 -- If there is a Stream_Convert pragma, use it, we rewrite
3043 -- sourcetyp'Output (stream, Item)
3045 -- as
3047 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
3049 -- where strmwrite is the given Write function that converts an
3050 -- argument of type sourcetyp or a type acctyp, from which it is
3051 -- derived to type strmtyp. The conversion to acttyp is required
3052 -- for the derived case.
3054 Prag := Get_Stream_Convert_Pragma (P_Type);
3056 if Present (Prag) then
3057 Arg3 :=
3058 Next (Next (First (Pragma_Argument_Associations (Prag))));
3059 Wfunc := Entity (Expression (Arg3));
3061 Rewrite (N,
3062 Make_Attribute_Reference (Loc,
3063 Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
3064 Attribute_Name => Name_Output,
3065 Expressions => New_List (
3066 Relocate_Node (First (Exprs)),
3067 Make_Function_Call (Loc,
3068 Name => New_Occurrence_Of (Wfunc, Loc),
3069 Parameter_Associations => New_List (
3070 OK_Convert_To (Etype (First_Formal (Wfunc)),
3071 Relocate_Node (Next (First (Exprs)))))))));
3073 Analyze (N);
3074 return;
3076 -- For elementary types, we call the W_xxx routine directly.
3077 -- Note that the effect of Write and Output is identical for
3078 -- the case of an elementary type, since there are no
3079 -- discriminants or bounds.
3081 elsif Is_Elementary_Type (U_Type) then
3083 -- A special case arises if we have a defined _Write routine,
3084 -- since in this case we are required to call this routine.
3086 if Present (TSS (Base_Type (U_Type), TSS_Stream_Write)) then
3087 Build_Record_Or_Elementary_Output_Procedure
3088 (Loc, U_Type, Decl, Pname);
3089 Insert_Action (N, Decl);
3091 -- For normal cases, we call the W_xxx routine directly
3093 else
3094 Rewrite (N, Build_Elementary_Write_Call (N));
3095 Analyze (N);
3096 return;
3097 end if;
3099 -- Array type case
3101 elsif Is_Array_Type (U_Type) then
3102 Build_Array_Output_Procedure (Loc, U_Type, Decl, Pname);
3103 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
3105 -- Class-wide case, first output external tag, then dispatch
3106 -- to the appropriate primitive Output function (RM 13.13.2(31)).
3108 elsif Is_Class_Wide_Type (P_Type) then
3110 -- No need to do anything else compiling under restriction
3111 -- No_Dispatching_Calls. During the semantic analysis we
3112 -- already notified such violation.
3114 if Restriction_Active (No_Dispatching_Calls) then
3115 return;
3116 end if;
3118 Tag_Write : declare
3119 Strm : constant Node_Id := First (Exprs);
3120 Item : constant Node_Id := Next (Strm);
3122 begin
3123 -- Ada 2005 (AI-344): Check that the accessibility level
3124 -- of the type of the output object is not deeper than
3125 -- that of the attribute's prefix type.
3127 -- if Get_Access_Level (Item'Tag)
3128 -- /= Get_Access_Level (P_Type'Tag)
3129 -- then
3130 -- raise Tag_Error;
3131 -- end if;
3133 -- String'Output (Strm, External_Tag (Item'Tag));
3135 -- We cannot figure out a practical way to implement this
3136 -- accessibility check on virtual machines, so we omit it.
3138 if Ada_Version >= Ada_05
3139 and then Tagged_Type_Expansion
3140 then
3141 Insert_Action (N,
3142 Make_Implicit_If_Statement (N,
3143 Condition =>
3144 Make_Op_Ne (Loc,
3145 Left_Opnd =>
3146 Build_Get_Access_Level (Loc,
3147 Make_Attribute_Reference (Loc,
3148 Prefix =>
3149 Relocate_Node (
3150 Duplicate_Subexpr (Item,
3151 Name_Req => True)),
3152 Attribute_Name => Name_Tag)),
3154 Right_Opnd =>
3155 Make_Integer_Literal (Loc,
3156 Type_Access_Level (P_Type))),
3158 Then_Statements =>
3159 New_List (Make_Raise_Statement (Loc,
3160 New_Occurrence_Of (
3161 RTE (RE_Tag_Error), Loc)))));
3162 end if;
3164 Insert_Action (N,
3165 Make_Attribute_Reference (Loc,
3166 Prefix => New_Occurrence_Of (Standard_String, Loc),
3167 Attribute_Name => Name_Output,
3168 Expressions => New_List (
3169 Relocate_Node (Duplicate_Subexpr (Strm)),
3170 Make_Function_Call (Loc,
3171 Name =>
3172 New_Occurrence_Of (RTE (RE_External_Tag), Loc),
3173 Parameter_Associations => New_List (
3174 Make_Attribute_Reference (Loc,
3175 Prefix =>
3176 Relocate_Node
3177 (Duplicate_Subexpr (Item, Name_Req => True)),
3178 Attribute_Name => Name_Tag))))));
3179 end Tag_Write;
3181 Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
3183 -- Tagged type case, use the primitive Output function
3185 elsif Is_Tagged_Type (U_Type) then
3186 Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
3188 -- All other record type cases, including protected records.
3189 -- The latter only arise for expander generated code for
3190 -- handling shared passive partition access.
3192 else
3193 pragma Assert
3194 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
3196 -- Ada 2005 (AI-216): Program_Error is raised when executing
3197 -- the default implementation of the Output attribute of an
3198 -- unchecked union type if the type lacks default discriminant
3199 -- values.
3201 if Is_Unchecked_Union (Base_Type (U_Type))
3202 and then No (Discriminant_Constraint (U_Type))
3203 then
3204 Insert_Action (N,
3205 Make_Raise_Program_Error (Loc,
3206 Reason => PE_Unchecked_Union_Restriction));
3208 return;
3209 end if;
3211 Build_Record_Or_Elementary_Output_Procedure
3212 (Loc, Base_Type (U_Type), Decl, Pname);
3213 Insert_Action (N, Decl);
3214 end if;
3215 end if;
3217 -- If we fall through, Pname is the name of the procedure to call
3219 Rewrite_Stream_Proc_Call (Pname);
3220 end Output;
3222 ---------
3223 -- Pos --
3224 ---------
3226 -- For enumeration types with a standard representation, Pos is
3227 -- handled by the back end.
3229 -- For enumeration types, with a non-standard representation we
3230 -- generate a call to the _Rep_To_Pos function created when the
3231 -- type was frozen. The call has the form
3233 -- _rep_to_pos (expr, flag)
3235 -- The parameter flag is True if range checks are enabled, causing
3236 -- Program_Error to be raised if the expression has an invalid
3237 -- representation, and False if range checks are suppressed.
3239 -- For integer types, Pos is equivalent to a simple integer
3240 -- conversion and we rewrite it as such
3242 when Attribute_Pos => Pos :
3243 declare
3244 Etyp : Entity_Id := Base_Type (Entity (Pref));
3246 begin
3247 -- Deal with zero/non-zero boolean values
3249 if Is_Boolean_Type (Etyp) then
3250 Adjust_Condition (First (Exprs));
3251 Etyp := Standard_Boolean;
3252 Set_Prefix (N, New_Occurrence_Of (Standard_Boolean, Loc));
3253 end if;
3255 -- Case of enumeration type
3257 if Is_Enumeration_Type (Etyp) then
3259 -- Non-standard enumeration type (generate call)
3261 if Present (Enum_Pos_To_Rep (Etyp)) then
3262 Append_To (Exprs, Rep_To_Pos_Flag (Etyp, Loc));
3263 Rewrite (N,
3264 Convert_To (Typ,
3265 Make_Function_Call (Loc,
3266 Name =>
3267 New_Reference_To (TSS (Etyp, TSS_Rep_To_Pos), Loc),
3268 Parameter_Associations => Exprs)));
3270 Analyze_And_Resolve (N, Typ);
3272 -- Standard enumeration type (do universal integer check)
3274 else
3275 Apply_Universal_Integer_Attribute_Checks (N);
3276 end if;
3278 -- Deal with integer types (replace by conversion)
3280 elsif Is_Integer_Type (Etyp) then
3281 Rewrite (N, Convert_To (Typ, First (Exprs)));
3282 Analyze_And_Resolve (N, Typ);
3283 end if;
3285 end Pos;
3287 --------------
3288 -- Position --
3289 --------------
3291 -- We compute this if a component clause was present, otherwise we leave
3292 -- the computation up to the back end, since we don't know what layout
3293 -- will be chosen.
3295 when Attribute_Position => Position :
3296 declare
3297 CE : constant Entity_Id := Entity (Selector_Name (Pref));
3299 begin
3300 if Present (Component_Clause (CE)) then
3301 Rewrite (N,
3302 Make_Integer_Literal (Loc,
3303 Intval => Component_Bit_Offset (CE) / System_Storage_Unit));
3304 Analyze_And_Resolve (N, Typ);
3306 else
3307 Apply_Universal_Integer_Attribute_Checks (N);
3308 end if;
3309 end Position;
3311 ----------
3312 -- Pred --
3313 ----------
3315 -- 1. Deal with enumeration types with holes
3316 -- 2. For floating-point, generate call to attribute function
3317 -- 3. For other cases, deal with constraint checking
3319 when Attribute_Pred => Pred :
3320 declare
3321 Etyp : constant Entity_Id := Base_Type (Ptyp);
3323 begin
3325 -- For enumeration types with non-standard representations, we
3326 -- expand typ'Pred (x) into
3328 -- Pos_To_Rep (Rep_To_Pos (x) - 1)
3330 -- If the representation is contiguous, we compute instead
3331 -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations.
3332 -- The conversion function Enum_Pos_To_Rep is defined on the
3333 -- base type, not the subtype, so we have to use the base type
3334 -- explicitly for this and other enumeration attributes.
3336 if Is_Enumeration_Type (Ptyp)
3337 and then Present (Enum_Pos_To_Rep (Etyp))
3338 then
3339 if Has_Contiguous_Rep (Etyp) then
3340 Rewrite (N,
3341 Unchecked_Convert_To (Ptyp,
3342 Make_Op_Add (Loc,
3343 Left_Opnd =>
3344 Make_Integer_Literal (Loc,
3345 Enumeration_Rep (First_Literal (Ptyp))),
3346 Right_Opnd =>
3347 Make_Function_Call (Loc,
3348 Name =>
3349 New_Reference_To
3350 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
3352 Parameter_Associations =>
3353 New_List (
3354 Unchecked_Convert_To (Ptyp,
3355 Make_Op_Subtract (Loc,
3356 Left_Opnd =>
3357 Unchecked_Convert_To (Standard_Integer,
3358 Relocate_Node (First (Exprs))),
3359 Right_Opnd =>
3360 Make_Integer_Literal (Loc, 1))),
3361 Rep_To_Pos_Flag (Ptyp, Loc))))));
3363 else
3364 -- Add Boolean parameter True, to request program errror if
3365 -- we have a bad representation on our hands. If checks are
3366 -- suppressed, then add False instead
3368 Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
3369 Rewrite (N,
3370 Make_Indexed_Component (Loc,
3371 Prefix =>
3372 New_Reference_To
3373 (Enum_Pos_To_Rep (Etyp), Loc),
3374 Expressions => New_List (
3375 Make_Op_Subtract (Loc,
3376 Left_Opnd =>
3377 Make_Function_Call (Loc,
3378 Name =>
3379 New_Reference_To
3380 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
3381 Parameter_Associations => Exprs),
3382 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
3383 end if;
3385 Analyze_And_Resolve (N, Typ);
3387 -- For floating-point, we transform 'Pred into a call to the Pred
3388 -- floating-point attribute function in Fat_xxx (xxx is root type)
3390 elsif Is_Floating_Point_Type (Ptyp) then
3391 Expand_Fpt_Attribute_R (N);
3392 Analyze_And_Resolve (N, Typ);
3394 -- For modular types, nothing to do (no overflow, since wraps)
3396 elsif Is_Modular_Integer_Type (Ptyp) then
3397 null;
3399 -- For other types, if argument is marked as needing a range check or
3400 -- overflow checking is enabled, we must generate a check.
3402 elsif not Overflow_Checks_Suppressed (Ptyp)
3403 or else Do_Range_Check (First (Exprs))
3404 then
3405 Set_Do_Range_Check (First (Exprs), False);
3406 Expand_Pred_Succ (N);
3407 end if;
3408 end Pred;
3410 --------------
3411 -- Priority --
3412 --------------
3414 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3416 -- We rewrite X'Priority as the following run-time call:
3418 -- Get_Ceiling (X._Object)
3420 -- Note that although X'Priority is notionally an object, it is quite
3421 -- deliberately not defined as an aliased object in the RM. This means
3422 -- that it works fine to rewrite it as a call, without having to worry
3423 -- about complications that would other arise from X'Priority'Access,
3424 -- which is illegal, because of the lack of aliasing.
3426 when Attribute_Priority =>
3427 declare
3428 Call : Node_Id;
3429 Conctyp : Entity_Id;
3430 Object_Parm : Node_Id;
3431 Subprg : Entity_Id;
3432 RT_Subprg_Name : Node_Id;
3434 begin
3435 -- Look for the enclosing concurrent type
3437 Conctyp := Current_Scope;
3438 while not Is_Concurrent_Type (Conctyp) loop
3439 Conctyp := Scope (Conctyp);
3440 end loop;
3442 pragma Assert (Is_Protected_Type (Conctyp));
3444 -- Generate the actual of the call
3446 Subprg := Current_Scope;
3447 while not Present (Protected_Body_Subprogram (Subprg)) loop
3448 Subprg := Scope (Subprg);
3449 end loop;
3451 -- Use of 'Priority inside protected entries and barriers (in
3452 -- both cases the type of the first formal of their expanded
3453 -- subprogram is Address)
3455 if Etype (First_Entity (Protected_Body_Subprogram (Subprg)))
3456 = RTE (RE_Address)
3457 then
3458 declare
3459 New_Itype : Entity_Id;
3461 begin
3462 -- In the expansion of protected entries the type of the
3463 -- first formal of the Protected_Body_Subprogram is an
3464 -- Address. In order to reference the _object component
3465 -- we generate:
3467 -- type T is access p__ptTV;
3468 -- freeze T []
3470 New_Itype := Create_Itype (E_Access_Type, N);
3471 Set_Etype (New_Itype, New_Itype);
3472 Set_Directly_Designated_Type (New_Itype,
3473 Corresponding_Record_Type (Conctyp));
3474 Freeze_Itype (New_Itype, N);
3476 -- Generate:
3477 -- T!(O)._object'unchecked_access
3479 Object_Parm :=
3480 Make_Attribute_Reference (Loc,
3481 Prefix =>
3482 Make_Selected_Component (Loc,
3483 Prefix =>
3484 Unchecked_Convert_To (New_Itype,
3485 New_Reference_To
3486 (First_Entity
3487 (Protected_Body_Subprogram (Subprg)),
3488 Loc)),
3489 Selector_Name =>
3490 Make_Identifier (Loc, Name_uObject)),
3491 Attribute_Name => Name_Unchecked_Access);
3492 end;
3494 -- Use of 'Priority inside a protected subprogram
3496 else
3497 Object_Parm :=
3498 Make_Attribute_Reference (Loc,
3499 Prefix =>
3500 Make_Selected_Component (Loc,
3501 Prefix => New_Reference_To
3502 (First_Entity
3503 (Protected_Body_Subprogram (Subprg)),
3504 Loc),
3505 Selector_Name =>
3506 Make_Identifier (Loc, Name_uObject)),
3507 Attribute_Name => Name_Unchecked_Access);
3508 end if;
3510 -- Select the appropriate run-time subprogram
3512 if Number_Entries (Conctyp) = 0 then
3513 RT_Subprg_Name :=
3514 New_Reference_To (RTE (RE_Get_Ceiling), Loc);
3515 else
3516 RT_Subprg_Name :=
3517 New_Reference_To (RTE (RO_PE_Get_Ceiling), Loc);
3518 end if;
3520 Call :=
3521 Make_Function_Call (Loc,
3522 Name => RT_Subprg_Name,
3523 Parameter_Associations => New_List (Object_Parm));
3525 Rewrite (N, Call);
3527 -- Avoid the generation of extra checks on the pointer to the
3528 -- protected object.
3530 Analyze_And_Resolve (N, Typ, Suppress => Access_Check);
3531 end;
3533 ------------------
3534 -- Range_Length --
3535 ------------------
3537 when Attribute_Range_Length => Range_Length : begin
3538 -- The only special processing required is for the case where
3539 -- Range_Length is applied to an enumeration type with holes.
3540 -- In this case we transform
3542 -- X'Range_Length
3544 -- to
3546 -- X'Pos (X'Last) - X'Pos (X'First) + 1
3548 -- So that the result reflects the proper Pos values instead
3549 -- of the underlying representations.
3551 if Is_Enumeration_Type (Ptyp)
3552 and then Has_Non_Standard_Rep (Ptyp)
3553 then
3554 Rewrite (N,
3555 Make_Op_Add (Loc,
3556 Left_Opnd =>
3557 Make_Op_Subtract (Loc,
3558 Left_Opnd =>
3559 Make_Attribute_Reference (Loc,
3560 Attribute_Name => Name_Pos,
3561 Prefix => New_Occurrence_Of (Ptyp, Loc),
3562 Expressions => New_List (
3563 Make_Attribute_Reference (Loc,
3564 Attribute_Name => Name_Last,
3565 Prefix => New_Occurrence_Of (Ptyp, Loc)))),
3567 Right_Opnd =>
3568 Make_Attribute_Reference (Loc,
3569 Attribute_Name => Name_Pos,
3570 Prefix => New_Occurrence_Of (Ptyp, Loc),
3571 Expressions => New_List (
3572 Make_Attribute_Reference (Loc,
3573 Attribute_Name => Name_First,
3574 Prefix => New_Occurrence_Of (Ptyp, Loc))))),
3576 Right_Opnd =>
3577 Make_Integer_Literal (Loc, 1)));
3579 Analyze_And_Resolve (N, Typ);
3581 -- For all other cases, the attribute is handled by the back end, but
3582 -- we need to deal with the case of the range check on a universal
3583 -- integer.
3585 else
3586 Apply_Universal_Integer_Attribute_Checks (N);
3587 end if;
3588 end Range_Length;
3590 ----------
3591 -- Read --
3592 ----------
3594 when Attribute_Read => Read : declare
3595 P_Type : constant Entity_Id := Entity (Pref);
3596 B_Type : constant Entity_Id := Base_Type (P_Type);
3597 U_Type : constant Entity_Id := Underlying_Type (P_Type);
3598 Pname : Entity_Id;
3599 Decl : Node_Id;
3600 Prag : Node_Id;
3601 Arg2 : Node_Id;
3602 Rfunc : Node_Id;
3603 Lhs : Node_Id;
3604 Rhs : Node_Id;
3606 begin
3607 -- If no underlying type, we have an error that will be diagnosed
3608 -- elsewhere, so here we just completely ignore the expansion.
3610 if No (U_Type) then
3611 return;
3612 end if;
3614 -- The simple case, if there is a TSS for Read, just call it
3616 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read);
3618 if Present (Pname) then
3619 null;
3621 else
3622 -- If there is a Stream_Convert pragma, use it, we rewrite
3624 -- sourcetyp'Read (stream, Item)
3626 -- as
3628 -- Item := sourcetyp (strmread (strmtyp'Input (Stream)));
3630 -- where strmread is the given Read function that converts an
3631 -- argument of type strmtyp to type sourcetyp or a type from which
3632 -- it is derived. The conversion to sourcetyp is required in the
3633 -- latter case.
3635 -- A special case arises if Item is a type conversion in which
3636 -- case, we have to expand to:
3638 -- Itemx := typex (strmread (strmtyp'Input (Stream)));
3640 -- where Itemx is the expression of the type conversion (i.e.
3641 -- the actual object), and typex is the type of Itemx.
3643 Prag := Get_Stream_Convert_Pragma (P_Type);
3645 if Present (Prag) then
3646 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
3647 Rfunc := Entity (Expression (Arg2));
3648 Lhs := Relocate_Node (Next (First (Exprs)));
3649 Rhs :=
3650 OK_Convert_To (B_Type,
3651 Make_Function_Call (Loc,
3652 Name => New_Occurrence_Of (Rfunc, Loc),
3653 Parameter_Associations => New_List (
3654 Make_Attribute_Reference (Loc,
3655 Prefix =>
3656 New_Occurrence_Of
3657 (Etype (First_Formal (Rfunc)), Loc),
3658 Attribute_Name => Name_Input,
3659 Expressions => New_List (
3660 Relocate_Node (First (Exprs)))))));
3662 if Nkind (Lhs) = N_Type_Conversion then
3663 Lhs := Expression (Lhs);
3664 Rhs := Convert_To (Etype (Lhs), Rhs);
3665 end if;
3667 Rewrite (N,
3668 Make_Assignment_Statement (Loc,
3669 Name => Lhs,
3670 Expression => Rhs));
3671 Set_Assignment_OK (Lhs);
3672 Analyze (N);
3673 return;
3675 -- For elementary types, we call the I_xxx routine using the first
3676 -- parameter and then assign the result into the second parameter.
3677 -- We set Assignment_OK to deal with the conversion case.
3679 elsif Is_Elementary_Type (U_Type) then
3680 declare
3681 Lhs : Node_Id;
3682 Rhs : Node_Id;
3684 begin
3685 Lhs := Relocate_Node (Next (First (Exprs)));
3686 Rhs := Build_Elementary_Input_Call (N);
3688 if Nkind (Lhs) = N_Type_Conversion then
3689 Lhs := Expression (Lhs);
3690 Rhs := Convert_To (Etype (Lhs), Rhs);
3691 end if;
3693 Set_Assignment_OK (Lhs);
3695 Rewrite (N,
3696 Make_Assignment_Statement (Loc,
3697 Name => Lhs,
3698 Expression => Rhs));
3700 Analyze (N);
3701 return;
3702 end;
3704 -- Array type case
3706 elsif Is_Array_Type (U_Type) then
3707 Build_Array_Read_Procedure (N, U_Type, Decl, Pname);
3708 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
3710 -- Tagged type case, use the primitive Read function. Note that
3711 -- this will dispatch in the class-wide case which is what we want
3713 elsif Is_Tagged_Type (U_Type) then
3714 Pname := Find_Prim_Op (U_Type, TSS_Stream_Read);
3716 -- All other record type cases, including protected records. The
3717 -- latter only arise for expander generated code for handling
3718 -- shared passive partition access.
3720 else
3721 pragma Assert
3722 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
3724 -- Ada 2005 (AI-216): Program_Error is raised when executing
3725 -- the default implementation of the Read attribute of an
3726 -- Unchecked_Union type.
3728 if Is_Unchecked_Union (Base_Type (U_Type)) then
3729 Insert_Action (N,
3730 Make_Raise_Program_Error (Loc,
3731 Reason => PE_Unchecked_Union_Restriction));
3732 end if;
3734 if Has_Discriminants (U_Type)
3735 and then Present
3736 (Discriminant_Default_Value (First_Discriminant (U_Type)))
3737 then
3738 Build_Mutable_Record_Read_Procedure
3739 (Loc, Base_Type (U_Type), Decl, Pname);
3740 else
3741 Build_Record_Read_Procedure
3742 (Loc, Base_Type (U_Type), Decl, Pname);
3743 end if;
3745 -- Suppress checks, uninitialized or otherwise invalid
3746 -- data does not cause constraint errors to be raised for
3747 -- a complete record read.
3749 Insert_Action (N, Decl, All_Checks);
3750 end if;
3751 end if;
3753 Rewrite_Stream_Proc_Call (Pname);
3754 end Read;
3756 ---------------
3757 -- Remainder --
3758 ---------------
3760 -- Transforms 'Remainder into a call to the floating-point attribute
3761 -- function Remainder in Fat_xxx (where xxx is the root type)
3763 when Attribute_Remainder =>
3764 Expand_Fpt_Attribute_RR (N);
3766 ------------
3767 -- Result --
3768 ------------
3770 -- Transform 'Result into reference to _Result formal. At the point
3771 -- where a legal 'Result attribute is expanded, we know that we are in
3772 -- the context of a _Postcondition function with a _Result parameter.
3774 when Attribute_Result =>
3775 Rewrite (N,
3776 Make_Identifier (Loc,
3777 Chars => Name_uResult));
3778 Analyze_And_Resolve (N, Typ);
3780 -----------
3781 -- Round --
3782 -----------
3784 -- The handling of the Round attribute is quite delicate. The processing
3785 -- in Sem_Attr introduced a conversion to universal real, reflecting the
3786 -- semantics of Round, but we do not want anything to do with universal
3787 -- real at runtime, since this corresponds to using floating-point
3788 -- arithmetic.
3790 -- What we have now is that the Etype of the Round attribute correctly
3791 -- indicates the final result type. The operand of the Round is the
3792 -- conversion to universal real, described above, and the operand of
3793 -- this conversion is the actual operand of Round, which may be the
3794 -- special case of a fixed point multiplication or division (Etype =
3795 -- universal fixed)
3797 -- The exapander will expand first the operand of the conversion, then
3798 -- the conversion, and finally the round attribute itself, since we
3799 -- always work inside out. But we cannot simply process naively in this
3800 -- order. In the semantic world where universal fixed and real really
3801 -- exist and have infinite precision, there is no problem, but in the
3802 -- implementation world, where universal real is a floating-point type,
3803 -- we would get the wrong result.
3805 -- So the approach is as follows. First, when expanding a multiply or
3806 -- divide whose type is universal fixed, we do nothing at all, instead
3807 -- deferring the operation till later.
3809 -- The actual processing is done in Expand_N_Type_Conversion which
3810 -- handles the special case of Round by looking at its parent to see if
3811 -- it is a Round attribute, and if it is, handling the conversion (or
3812 -- its fixed multiply/divide child) in an appropriate manner.
3814 -- This means that by the time we get to expanding the Round attribute
3815 -- itself, the Round is nothing more than a type conversion (and will
3816 -- often be a null type conversion), so we just replace it with the
3817 -- appropriate conversion operation.
3819 when Attribute_Round =>
3820 Rewrite (N,
3821 Convert_To (Etype (N), Relocate_Node (First (Exprs))));
3822 Analyze_And_Resolve (N);
3824 --------------
3825 -- Rounding --
3826 --------------
3828 -- Transforms 'Rounding into a call to the floating-point attribute
3829 -- function Rounding in Fat_xxx (where xxx is the root type)
3831 when Attribute_Rounding =>
3832 Expand_Fpt_Attribute_R (N);
3834 -------------
3835 -- Scaling --
3836 -------------
3838 -- Transforms 'Scaling into a call to the floating-point attribute
3839 -- function Scaling in Fat_xxx (where xxx is the root type)
3841 when Attribute_Scaling =>
3842 Expand_Fpt_Attribute_RI (N);
3844 ----------
3845 -- Size --
3846 ----------
3848 when Attribute_Size |
3849 Attribute_Object_Size |
3850 Attribute_Value_Size |
3851 Attribute_VADS_Size => Size :
3853 declare
3854 Siz : Uint;
3855 New_Node : Node_Id;
3857 begin
3858 -- Processing for VADS_Size case. Note that this processing removes
3859 -- all traces of VADS_Size from the tree, and completes all required
3860 -- processing for VADS_Size by translating the attribute reference
3861 -- to an appropriate Size or Object_Size reference.
3863 if Id = Attribute_VADS_Size
3864 or else (Use_VADS_Size and then Id = Attribute_Size)
3865 then
3866 -- If the size is specified, then we simply use the specified
3867 -- size. This applies to both types and objects. The size of an
3868 -- object can be specified in the following ways:
3870 -- An explicit size object is given for an object
3871 -- A component size is specified for an indexed component
3872 -- A component clause is specified for a selected component
3873 -- The object is a component of a packed composite object
3875 -- If the size is specified, then VADS_Size of an object
3877 if (Is_Entity_Name (Pref)
3878 and then Present (Size_Clause (Entity (Pref))))
3879 or else
3880 (Nkind (Pref) = N_Component_Clause
3881 and then (Present (Component_Clause
3882 (Entity (Selector_Name (Pref))))
3883 or else Is_Packed (Etype (Prefix (Pref)))))
3884 or else
3885 (Nkind (Pref) = N_Indexed_Component
3886 and then (Component_Size (Etype (Prefix (Pref))) /= 0
3887 or else Is_Packed (Etype (Prefix (Pref)))))
3888 then
3889 Set_Attribute_Name (N, Name_Size);
3891 -- Otherwise if we have an object rather than a type, then the
3892 -- VADS_Size attribute applies to the type of the object, rather
3893 -- than the object itself. This is one of the respects in which
3894 -- VADS_Size differs from Size.
3896 else
3897 if (not Is_Entity_Name (Pref)
3898 or else not Is_Type (Entity (Pref)))
3899 and then (Is_Scalar_Type (Ptyp) or else Is_Constrained (Ptyp))
3900 then
3901 Rewrite (Pref, New_Occurrence_Of (Ptyp, Loc));
3902 end if;
3904 -- For a scalar type for which no size was explicitly given,
3905 -- VADS_Size means Object_Size. This is the other respect in
3906 -- which VADS_Size differs from Size.
3908 if Is_Scalar_Type (Ptyp) and then No (Size_Clause (Ptyp)) then
3909 Set_Attribute_Name (N, Name_Object_Size);
3911 -- In all other cases, Size and VADS_Size are the sane
3913 else
3914 Set_Attribute_Name (N, Name_Size);
3915 end if;
3916 end if;
3917 end if;
3919 -- For class-wide types, X'Class'Size is transformed into a direct
3920 -- reference to the Size of the class type, so that the back end does
3921 -- not have to deal with the X'Class'Size reference.
3923 if Is_Entity_Name (Pref)
3924 and then Is_Class_Wide_Type (Entity (Pref))
3925 then
3926 Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
3927 return;
3929 -- For X'Size applied to an object of a class-wide type, transform
3930 -- X'Size into a call to the primitive operation _Size applied to X.
3932 elsif Is_Class_Wide_Type (Ptyp)
3933 or else (Id = Attribute_Size
3934 and then Is_Tagged_Type (Ptyp)
3935 and then Has_Unknown_Discriminants (Ptyp))
3936 then
3937 -- No need to do anything else compiling under restriction
3938 -- No_Dispatching_Calls. During the semantic analysis we
3939 -- already notified such violation.
3941 if Restriction_Active (No_Dispatching_Calls) then
3942 return;
3943 end if;
3945 New_Node :=
3946 Make_Function_Call (Loc,
3947 Name => New_Reference_To
3948 (Find_Prim_Op (Ptyp, Name_uSize), Loc),
3949 Parameter_Associations => New_List (Pref));
3951 if Typ /= Standard_Long_Long_Integer then
3953 -- The context is a specific integer type with which the
3954 -- original attribute was compatible. The function has a
3955 -- specific type as well, so to preserve the compatibility
3956 -- we must convert explicitly.
3958 New_Node := Convert_To (Typ, New_Node);
3959 end if;
3961 Rewrite (N, New_Node);
3962 Analyze_And_Resolve (N, Typ);
3963 return;
3965 -- Case of known RM_Size of a type
3967 elsif (Id = Attribute_Size or else Id = Attribute_Value_Size)
3968 and then Is_Entity_Name (Pref)
3969 and then Is_Type (Entity (Pref))
3970 and then Known_Static_RM_Size (Entity (Pref))
3971 then
3972 Siz := RM_Size (Entity (Pref));
3974 -- Case of known Esize of a type
3976 elsif Id = Attribute_Object_Size
3977 and then Is_Entity_Name (Pref)
3978 and then Is_Type (Entity (Pref))
3979 and then Known_Static_Esize (Entity (Pref))
3980 then
3981 Siz := Esize (Entity (Pref));
3983 -- Case of known size of object
3985 elsif Id = Attribute_Size
3986 and then Is_Entity_Name (Pref)
3987 and then Is_Object (Entity (Pref))
3988 and then Known_Esize (Entity (Pref))
3989 and then Known_Static_Esize (Entity (Pref))
3990 then
3991 Siz := Esize (Entity (Pref));
3993 -- For an array component, we can do Size in the front end
3994 -- if the component_size of the array is set.
3996 elsif Nkind (Pref) = N_Indexed_Component then
3997 Siz := Component_Size (Etype (Prefix (Pref)));
3999 -- For a record component, we can do Size in the front end if there
4000 -- is a component clause, or if the record is packed and the
4001 -- component's size is known at compile time.
4003 elsif Nkind (Pref) = N_Selected_Component then
4004 declare
4005 Rec : constant Entity_Id := Etype (Prefix (Pref));
4006 Comp : constant Entity_Id := Entity (Selector_Name (Pref));
4008 begin
4009 if Present (Component_Clause (Comp)) then
4010 Siz := Esize (Comp);
4012 elsif Is_Packed (Rec) then
4013 Siz := RM_Size (Ptyp);
4015 else
4016 Apply_Universal_Integer_Attribute_Checks (N);
4017 return;
4018 end if;
4019 end;
4021 -- All other cases are handled by the back end
4023 else
4024 Apply_Universal_Integer_Attribute_Checks (N);
4026 -- If Size is applied to a formal parameter that is of a packed
4027 -- array subtype, then apply Size to the actual subtype.
4029 if Is_Entity_Name (Pref)
4030 and then Is_Formal (Entity (Pref))
4031 and then Is_Array_Type (Ptyp)
4032 and then Is_Packed (Ptyp)
4033 then
4034 Rewrite (N,
4035 Make_Attribute_Reference (Loc,
4036 Prefix =>
4037 New_Occurrence_Of (Get_Actual_Subtype (Pref), Loc),
4038 Attribute_Name => Name_Size));
4039 Analyze_And_Resolve (N, Typ);
4040 end if;
4042 -- If Size applies to a dereference of an access to unconstrained
4043 -- packed array, the back end needs to see its unconstrained
4044 -- nominal type, but also a hint to the actual constrained type.
4046 if Nkind (Pref) = N_Explicit_Dereference
4047 and then Is_Array_Type (Ptyp)
4048 and then not Is_Constrained (Ptyp)
4049 and then Is_Packed (Ptyp)
4050 then
4051 Set_Actual_Designated_Subtype (Pref,
4052 Get_Actual_Subtype (Pref));
4053 end if;
4055 return;
4056 end if;
4058 -- Common processing for record and array component case
4060 if Siz /= No_Uint and then Siz /= 0 then
4061 declare
4062 CS : constant Boolean := Comes_From_Source (N);
4064 begin
4065 Rewrite (N, Make_Integer_Literal (Loc, Siz));
4067 -- This integer literal is not a static expression. We do not
4068 -- call Analyze_And_Resolve here, because this would activate
4069 -- the circuit for deciding that a static value was out of
4070 -- range, and we don't want that.
4072 -- So just manually set the type, mark the expression as non-
4073 -- static, and then ensure that the result is checked properly
4074 -- if the attribute comes from source (if it was internally
4075 -- generated, we never need a constraint check).
4077 Set_Etype (N, Typ);
4078 Set_Is_Static_Expression (N, False);
4080 if CS then
4081 Apply_Constraint_Check (N, Typ);
4082 end if;
4083 end;
4084 end if;
4085 end Size;
4087 ------------------
4088 -- Storage_Pool --
4089 ------------------
4091 when Attribute_Storage_Pool =>
4092 Rewrite (N,
4093 Make_Type_Conversion (Loc,
4094 Subtype_Mark => New_Reference_To (Etype (N), Loc),
4095 Expression => New_Reference_To (Entity (N), Loc)));
4096 Analyze_And_Resolve (N, Typ);
4098 ------------------
4099 -- Storage_Size --
4100 ------------------
4102 when Attribute_Storage_Size => Storage_Size : begin
4104 -- Access type case, always go to the root type
4106 -- The case of access types results in a value of zero for the case
4107 -- where no storage size attribute clause has been given. If a
4108 -- storage size has been given, then the attribute is converted
4109 -- to a reference to the variable used to hold this value.
4111 if Is_Access_Type (Ptyp) then
4112 if Present (Storage_Size_Variable (Root_Type (Ptyp))) then
4113 Rewrite (N,
4114 Make_Attribute_Reference (Loc,
4115 Prefix => New_Reference_To (Typ, Loc),
4116 Attribute_Name => Name_Max,
4117 Expressions => New_List (
4118 Make_Integer_Literal (Loc, 0),
4119 Convert_To (Typ,
4120 New_Reference_To
4121 (Storage_Size_Variable (Root_Type (Ptyp)), Loc)))));
4123 elsif Present (Associated_Storage_Pool (Root_Type (Ptyp))) then
4124 Rewrite (N,
4125 OK_Convert_To (Typ,
4126 Make_Function_Call (Loc,
4127 Name =>
4128 New_Reference_To
4129 (Find_Prim_Op
4130 (Etype (Associated_Storage_Pool (Root_Type (Ptyp))),
4131 Attribute_Name (N)),
4132 Loc),
4134 Parameter_Associations => New_List (
4135 New_Reference_To
4136 (Associated_Storage_Pool (Root_Type (Ptyp)), Loc)))));
4138 else
4139 Rewrite (N, Make_Integer_Literal (Loc, 0));
4140 end if;
4142 Analyze_And_Resolve (N, Typ);
4144 -- For tasks, we retrieve the size directly from the TCB. The
4145 -- size may depend on a discriminant of the type, and therefore
4146 -- can be a per-object expression, so type-level information is
4147 -- not sufficient in general. There are four cases to consider:
4149 -- a) If the attribute appears within a task body, the designated
4150 -- TCB is obtained by a call to Self.
4152 -- b) If the prefix of the attribute is the name of a task object,
4153 -- the designated TCB is the one stored in the corresponding record.
4155 -- c) If the prefix is a task type, the size is obtained from the
4156 -- size variable created for each task type
4158 -- d) If no storage_size was specified for the type , there is no
4159 -- size variable, and the value is a system-specific default.
4161 else
4162 if In_Open_Scopes (Ptyp) then
4164 -- Storage_Size (Self)
4166 Rewrite (N,
4167 Convert_To (Typ,
4168 Make_Function_Call (Loc,
4169 Name =>
4170 New_Occurrence_Of (RTE (RE_Storage_Size), Loc),
4171 Parameter_Associations =>
4172 New_List (
4173 Make_Function_Call (Loc,
4174 Name =>
4175 New_Reference_To (RTE (RE_Self), Loc))))));
4177 elsif not Is_Entity_Name (Pref)
4178 or else not Is_Type (Entity (Pref))
4179 then
4180 -- Storage_Size (Rec (Obj).Size)
4182 Rewrite (N,
4183 Convert_To (Typ,
4184 Make_Function_Call (Loc,
4185 Name =>
4186 New_Occurrence_Of (RTE (RE_Storage_Size), Loc),
4187 Parameter_Associations =>
4188 New_List (
4189 Make_Selected_Component (Loc,
4190 Prefix =>
4191 Unchecked_Convert_To (
4192 Corresponding_Record_Type (Ptyp),
4193 New_Copy_Tree (Pref)),
4194 Selector_Name =>
4195 Make_Identifier (Loc, Name_uTask_Id))))));
4197 elsif Present (Storage_Size_Variable (Ptyp)) then
4199 -- Static storage size pragma given for type: retrieve value
4200 -- from its allocated storage variable.
4202 Rewrite (N,
4203 Convert_To (Typ,
4204 Make_Function_Call (Loc,
4205 Name => New_Occurrence_Of (
4206 RTE (RE_Adjust_Storage_Size), Loc),
4207 Parameter_Associations =>
4208 New_List (
4209 New_Reference_To (
4210 Storage_Size_Variable (Ptyp), Loc)))));
4211 else
4212 -- Get system default
4214 Rewrite (N,
4215 Convert_To (Typ,
4216 Make_Function_Call (Loc,
4217 Name =>
4218 New_Occurrence_Of (
4219 RTE (RE_Default_Stack_Size), Loc))));
4220 end if;
4222 Analyze_And_Resolve (N, Typ);
4223 end if;
4224 end Storage_Size;
4226 -----------------
4227 -- Stream_Size --
4228 -----------------
4230 when Attribute_Stream_Size => Stream_Size : declare
4231 Size : Int;
4233 begin
4234 -- If we have a Stream_Size clause for this type use it, otherwise
4235 -- the Stream_Size if the size of the type.
4237 if Has_Stream_Size_Clause (Ptyp) then
4238 Size :=
4239 UI_To_Int
4240 (Static_Integer (Expression (Stream_Size_Clause (Ptyp))));
4241 else
4242 Size := UI_To_Int (Esize (Ptyp));
4243 end if;
4245 Rewrite (N, Make_Integer_Literal (Loc, Intval => Size));
4246 Analyze_And_Resolve (N, Typ);
4247 end Stream_Size;
4249 ----------
4250 -- Succ --
4251 ----------
4253 -- 1. Deal with enumeration types with holes
4254 -- 2. For floating-point, generate call to attribute function
4255 -- 3. For other cases, deal with constraint checking
4257 when Attribute_Succ => Succ :
4258 declare
4259 Etyp : constant Entity_Id := Base_Type (Ptyp);
4261 begin
4263 -- For enumeration types with non-standard representations, we
4264 -- expand typ'Succ (x) into
4266 -- Pos_To_Rep (Rep_To_Pos (x) + 1)
4268 -- If the representation is contiguous, we compute instead
4269 -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations.
4271 if Is_Enumeration_Type (Ptyp)
4272 and then Present (Enum_Pos_To_Rep (Etyp))
4273 then
4274 if Has_Contiguous_Rep (Etyp) then
4275 Rewrite (N,
4276 Unchecked_Convert_To (Ptyp,
4277 Make_Op_Add (Loc,
4278 Left_Opnd =>
4279 Make_Integer_Literal (Loc,
4280 Enumeration_Rep (First_Literal (Ptyp))),
4281 Right_Opnd =>
4282 Make_Function_Call (Loc,
4283 Name =>
4284 New_Reference_To
4285 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
4287 Parameter_Associations =>
4288 New_List (
4289 Unchecked_Convert_To (Ptyp,
4290 Make_Op_Add (Loc,
4291 Left_Opnd =>
4292 Unchecked_Convert_To (Standard_Integer,
4293 Relocate_Node (First (Exprs))),
4294 Right_Opnd =>
4295 Make_Integer_Literal (Loc, 1))),
4296 Rep_To_Pos_Flag (Ptyp, Loc))))));
4297 else
4298 -- Add Boolean parameter True, to request program errror if
4299 -- we have a bad representation on our hands. Add False if
4300 -- checks are suppressed.
4302 Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
4303 Rewrite (N,
4304 Make_Indexed_Component (Loc,
4305 Prefix =>
4306 New_Reference_To
4307 (Enum_Pos_To_Rep (Etyp), Loc),
4308 Expressions => New_List (
4309 Make_Op_Add (Loc,
4310 Left_Opnd =>
4311 Make_Function_Call (Loc,
4312 Name =>
4313 New_Reference_To
4314 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
4315 Parameter_Associations => Exprs),
4316 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
4317 end if;
4319 Analyze_And_Resolve (N, Typ);
4321 -- For floating-point, we transform 'Succ into a call to the Succ
4322 -- floating-point attribute function in Fat_xxx (xxx is root type)
4324 elsif Is_Floating_Point_Type (Ptyp) then
4325 Expand_Fpt_Attribute_R (N);
4326 Analyze_And_Resolve (N, Typ);
4328 -- For modular types, nothing to do (no overflow, since wraps)
4330 elsif Is_Modular_Integer_Type (Ptyp) then
4331 null;
4333 -- For other types, if argument is marked as needing a range check or
4334 -- overflow checking is enabled, we must generate a check.
4336 elsif not Overflow_Checks_Suppressed (Ptyp)
4337 or else Do_Range_Check (First (Exprs))
4338 then
4339 Set_Do_Range_Check (First (Exprs), False);
4340 Expand_Pred_Succ (N);
4341 end if;
4342 end Succ;
4344 ---------
4345 -- Tag --
4346 ---------
4348 -- Transforms X'Tag into a direct reference to the tag of X
4350 when Attribute_Tag => Tag :
4351 declare
4352 Ttyp : Entity_Id;
4353 Prefix_Is_Type : Boolean;
4355 begin
4356 if Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then
4357 Ttyp := Entity (Pref);
4358 Prefix_Is_Type := True;
4359 else
4360 Ttyp := Ptyp;
4361 Prefix_Is_Type := False;
4362 end if;
4364 if Is_Class_Wide_Type (Ttyp) then
4365 Ttyp := Root_Type (Ttyp);
4366 end if;
4368 Ttyp := Underlying_Type (Ttyp);
4370 -- Ada 2005: The type may be a synchronized tagged type, in which
4371 -- case the tag information is stored in the corresponding record.
4373 if Is_Concurrent_Type (Ttyp) then
4374 Ttyp := Corresponding_Record_Type (Ttyp);
4375 end if;
4377 if Prefix_Is_Type then
4379 -- For VMs we leave the type attribute unexpanded because
4380 -- there's not a dispatching table to reference.
4382 if Tagged_Type_Expansion then
4383 Rewrite (N,
4384 Unchecked_Convert_To (RTE (RE_Tag),
4385 New_Reference_To
4386 (Node (First_Elmt (Access_Disp_Table (Ttyp))), Loc)));
4387 Analyze_And_Resolve (N, RTE (RE_Tag));
4388 end if;
4390 -- Ada 2005 (AI-251): The use of 'Tag in the sources always
4391 -- references the primary tag of the actual object. If 'Tag is
4392 -- applied to class-wide interface objects we generate code that
4393 -- displaces "this" to reference the base of the object.
4395 elsif Comes_From_Source (N)
4396 and then Is_Class_Wide_Type (Etype (Prefix (N)))
4397 and then Is_Interface (Etype (Prefix (N)))
4398 then
4399 -- Generate:
4400 -- (To_Tag_Ptr (Prefix'Address)).all
4402 -- Note that Prefix'Address is recursively expanded into a call
4403 -- to Base_Address (Obj.Tag)
4405 -- Not needed for VM targets, since all handled by the VM
4407 if Tagged_Type_Expansion then
4408 Rewrite (N,
4409 Make_Explicit_Dereference (Loc,
4410 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4411 Make_Attribute_Reference (Loc,
4412 Prefix => Relocate_Node (Pref),
4413 Attribute_Name => Name_Address))));
4414 Analyze_And_Resolve (N, RTE (RE_Tag));
4415 end if;
4417 else
4418 Rewrite (N,
4419 Make_Selected_Component (Loc,
4420 Prefix => Relocate_Node (Pref),
4421 Selector_Name =>
4422 New_Reference_To (First_Tag_Component (Ttyp), Loc)));
4423 Analyze_And_Resolve (N, RTE (RE_Tag));
4424 end if;
4425 end Tag;
4427 ----------------
4428 -- Terminated --
4429 ----------------
4431 -- Transforms 'Terminated attribute into a call to Terminated function
4433 when Attribute_Terminated => Terminated :
4434 begin
4435 -- The prefix of Terminated is of a task interface class-wide type.
4436 -- Generate:
4437 -- terminated (Task_Id (Pref._disp_get_task_id));
4439 if Ada_Version >= Ada_05
4440 and then Ekind (Ptyp) = E_Class_Wide_Type
4441 and then Is_Interface (Ptyp)
4442 and then Is_Task_Interface (Ptyp)
4443 then
4444 Rewrite (N,
4445 Make_Function_Call (Loc,
4446 Name =>
4447 New_Reference_To (RTE (RE_Terminated), Loc),
4448 Parameter_Associations => New_List (
4449 Make_Unchecked_Type_Conversion (Loc,
4450 Subtype_Mark =>
4451 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4452 Expression =>
4453 Make_Selected_Component (Loc,
4454 Prefix =>
4455 New_Copy_Tree (Pref),
4456 Selector_Name =>
4457 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))))));
4459 elsif Restricted_Profile then
4460 Rewrite (N,
4461 Build_Call_With_Task (Pref, RTE (RE_Restricted_Terminated)));
4463 else
4464 Rewrite (N,
4465 Build_Call_With_Task (Pref, RTE (RE_Terminated)));
4466 end if;
4468 Analyze_And_Resolve (N, Standard_Boolean);
4469 end Terminated;
4471 ----------------
4472 -- To_Address --
4473 ----------------
4475 -- Transforms System'To_Address (X) into unchecked conversion
4476 -- from (integral) type of X to type address.
4478 when Attribute_To_Address =>
4479 Rewrite (N,
4480 Unchecked_Convert_To (RTE (RE_Address),
4481 Relocate_Node (First (Exprs))));
4482 Analyze_And_Resolve (N, RTE (RE_Address));
4484 ------------
4485 -- To_Any --
4486 ------------
4488 when Attribute_To_Any => To_Any : declare
4489 P_Type : constant Entity_Id := Etype (Pref);
4490 Decls : constant List_Id := New_List;
4491 begin
4492 Rewrite (N,
4493 Build_To_Any_Call
4494 (Convert_To (P_Type,
4495 Relocate_Node (First (Exprs))), Decls));
4496 Insert_Actions (N, Decls);
4497 Analyze_And_Resolve (N, RTE (RE_Any));
4498 end To_Any;
4500 ----------------
4501 -- Truncation --
4502 ----------------
4504 -- Transforms 'Truncation into a call to the floating-point attribute
4505 -- function Truncation in Fat_xxx (where xxx is the root type).
4506 -- Expansion is avoided for cases the back end can handle directly.
4508 when Attribute_Truncation =>
4509 if not Is_Inline_Floating_Point_Attribute (N) then
4510 Expand_Fpt_Attribute_R (N);
4511 end if;
4513 --------------
4514 -- TypeCode --
4515 --------------
4517 when Attribute_TypeCode => TypeCode : declare
4518 P_Type : constant Entity_Id := Etype (Pref);
4519 Decls : constant List_Id := New_List;
4520 begin
4521 Rewrite (N, Build_TypeCode_Call (Loc, P_Type, Decls));
4522 Insert_Actions (N, Decls);
4523 Analyze_And_Resolve (N, RTE (RE_TypeCode));
4524 end TypeCode;
4526 -----------------------
4527 -- Unbiased_Rounding --
4528 -----------------------
4530 -- Transforms 'Unbiased_Rounding into a call to the floating-point
4531 -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the
4532 -- root type). Expansion is avoided for cases the back end can handle
4533 -- directly.
4535 when Attribute_Unbiased_Rounding =>
4536 if not Is_Inline_Floating_Point_Attribute (N) then
4537 Expand_Fpt_Attribute_R (N);
4538 end if;
4540 -----------------
4541 -- UET_Address --
4542 -----------------
4544 when Attribute_UET_Address => UET_Address : declare
4545 Ent : constant Entity_Id :=
4546 Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
4548 begin
4549 Insert_Action (N,
4550 Make_Object_Declaration (Loc,
4551 Defining_Identifier => Ent,
4552 Aliased_Present => True,
4553 Object_Definition =>
4554 New_Occurrence_Of (RTE (RE_Address), Loc)));
4556 -- Construct name __gnat_xxx__SDP, where xxx is the unit name
4557 -- in normal external form.
4559 Get_External_Unit_Name_String (Get_Unit_Name (Pref));
4560 Name_Buffer (1 + 7 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
4561 Name_Len := Name_Len + 7;
4562 Name_Buffer (1 .. 7) := "__gnat_";
4563 Name_Buffer (Name_Len + 1 .. Name_Len + 5) := "__SDP";
4564 Name_Len := Name_Len + 5;
4566 Set_Is_Imported (Ent);
4567 Set_Interface_Name (Ent,
4568 Make_String_Literal (Loc,
4569 Strval => String_From_Name_Buffer));
4571 -- Set entity as internal to ensure proper Sprint output of its
4572 -- implicit importation.
4574 Set_Is_Internal (Ent);
4576 Rewrite (N,
4577 Make_Attribute_Reference (Loc,
4578 Prefix => New_Occurrence_Of (Ent, Loc),
4579 Attribute_Name => Name_Address));
4581 Analyze_And_Resolve (N, Typ);
4582 end UET_Address;
4584 ---------------
4585 -- VADS_Size --
4586 ---------------
4588 -- The processing for VADS_Size is shared with Size
4590 ---------
4591 -- Val --
4592 ---------
4594 -- For enumeration types with a standard representation, and for all
4595 -- other types, Val is handled by the back end. For enumeration types
4596 -- with a non-standard representation we use the _Pos_To_Rep array that
4597 -- was created when the type was frozen.
4599 when Attribute_Val => Val :
4600 declare
4601 Etyp : constant Entity_Id := Base_Type (Entity (Pref));
4603 begin
4604 if Is_Enumeration_Type (Etyp)
4605 and then Present (Enum_Pos_To_Rep (Etyp))
4606 then
4607 if Has_Contiguous_Rep (Etyp) then
4608 declare
4609 Rep_Node : constant Node_Id :=
4610 Unchecked_Convert_To (Etyp,
4611 Make_Op_Add (Loc,
4612 Left_Opnd =>
4613 Make_Integer_Literal (Loc,
4614 Enumeration_Rep (First_Literal (Etyp))),
4615 Right_Opnd =>
4616 (Convert_To (Standard_Integer,
4617 Relocate_Node (First (Exprs))))));
4619 begin
4620 Rewrite (N,
4621 Unchecked_Convert_To (Etyp,
4622 Make_Op_Add (Loc,
4623 Left_Opnd =>
4624 Make_Integer_Literal (Loc,
4625 Enumeration_Rep (First_Literal (Etyp))),
4626 Right_Opnd =>
4627 Make_Function_Call (Loc,
4628 Name =>
4629 New_Reference_To
4630 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
4631 Parameter_Associations => New_List (
4632 Rep_Node,
4633 Rep_To_Pos_Flag (Etyp, Loc))))));
4634 end;
4636 else
4637 Rewrite (N,
4638 Make_Indexed_Component (Loc,
4639 Prefix => New_Reference_To (Enum_Pos_To_Rep (Etyp), Loc),
4640 Expressions => New_List (
4641 Convert_To (Standard_Integer,
4642 Relocate_Node (First (Exprs))))));
4643 end if;
4645 Analyze_And_Resolve (N, Typ);
4647 -- If the argument is marked as requiring a range check then generate
4648 -- it here.
4650 elsif Do_Range_Check (First (Exprs)) then
4651 Set_Do_Range_Check (First (Exprs), False);
4652 Generate_Range_Check (First (Exprs), Etyp, CE_Range_Check_Failed);
4653 end if;
4654 end Val;
4656 -----------
4657 -- Valid --
4658 -----------
4660 -- The code for valid is dependent on the particular types involved.
4661 -- See separate sections below for the generated code in each case.
4663 when Attribute_Valid => Valid :
4664 declare
4665 Btyp : Entity_Id := Base_Type (Ptyp);
4666 Tst : Node_Id;
4668 Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;
4669 -- Save the validity checking mode. We always turn off validity
4670 -- checking during process of 'Valid since this is one place
4671 -- where we do not want the implicit validity checks to intefere
4672 -- with the explicit validity check that the programmer is doing.
4674 function Make_Range_Test return Node_Id;
4675 -- Build the code for a range test of the form
4676 -- Btyp!(Pref) >= Btyp!(Ptyp'First)
4677 -- and then
4678 -- Btyp!(Pref) <= Btyp!(Ptyp'Last)
4680 ---------------------
4681 -- Make_Range_Test --
4682 ---------------------
4684 function Make_Range_Test return Node_Id is
4685 begin
4686 return
4687 Make_And_Then (Loc,
4688 Left_Opnd =>
4689 Make_Op_Ge (Loc,
4690 Left_Opnd =>
4691 Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
4693 Right_Opnd =>
4694 Unchecked_Convert_To (Btyp,
4695 Make_Attribute_Reference (Loc,
4696 Prefix => New_Occurrence_Of (Ptyp, Loc),
4697 Attribute_Name => Name_First))),
4699 Right_Opnd =>
4700 Make_Op_Le (Loc,
4701 Left_Opnd =>
4702 Unchecked_Convert_To (Btyp,
4703 Duplicate_Subexpr_No_Checks (Pref)),
4705 Right_Opnd =>
4706 Unchecked_Convert_To (Btyp,
4707 Make_Attribute_Reference (Loc,
4708 Prefix => New_Occurrence_Of (Ptyp, Loc),
4709 Attribute_Name => Name_Last))));
4710 end Make_Range_Test;
4712 -- Start of processing for Attribute_Valid
4714 begin
4715 -- Turn off validity checks. We do not want any implicit validity
4716 -- checks to intefere with the explicit check from the attribute
4718 Validity_Checks_On := False;
4720 -- Floating-point case. This case is handled by the Valid attribute
4721 -- code in the floating-point attribute run-time library.
4723 if Is_Floating_Point_Type (Ptyp) then
4724 declare
4725 Pkg : RE_Id;
4726 Ftp : Entity_Id;
4728 begin
4729 -- For vax fpt types, call appropriate routine in special vax
4730 -- floating point unit. We do not have to worry about loads in
4731 -- this case, since these types have no signalling NaN's.
4733 if Vax_Float (Btyp) then
4734 Expand_Vax_Valid (N);
4736 -- The AAMP back end handles Valid for floating-point types
4738 elsif Is_AAMP_Float (Btyp) then
4739 Analyze_And_Resolve (Pref, Ptyp);
4740 Set_Etype (N, Standard_Boolean);
4741 Set_Analyzed (N);
4743 -- Non VAX float case
4745 else
4746 Find_Fat_Info (Ptyp, Ftp, Pkg);
4748 -- If the floating-point object might be unaligned, we need
4749 -- to call the special routine Unaligned_Valid, which makes
4750 -- the needed copy, being careful not to load the value into
4751 -- any floating-point register. The argument in this case is
4752 -- obj'Address (see Unaligned_Valid routine in Fat_Gen).
4754 if Is_Possibly_Unaligned_Object (Pref) then
4755 Expand_Fpt_Attribute
4756 (N, Pkg, Name_Unaligned_Valid,
4757 New_List (
4758 Make_Attribute_Reference (Loc,
4759 Prefix => Relocate_Node (Pref),
4760 Attribute_Name => Name_Address)));
4762 -- In the normal case where we are sure the object is
4763 -- aligned, we generate a call to Valid, and the argument in
4764 -- this case is obj'Unrestricted_Access (after converting
4765 -- obj to the right floating-point type).
4767 else
4768 Expand_Fpt_Attribute
4769 (N, Pkg, Name_Valid,
4770 New_List (
4771 Make_Attribute_Reference (Loc,
4772 Prefix => Unchecked_Convert_To (Ftp, Pref),
4773 Attribute_Name => Name_Unrestricted_Access)));
4774 end if;
4775 end if;
4777 -- One more task, we still need a range check. Required
4778 -- only if we have a constraint, since the Valid routine
4779 -- catches infinities properly (infinities are never valid).
4781 -- The way we do the range check is simply to create the
4782 -- expression: Valid (N) and then Base_Type(Pref) in Typ.
4784 if not Subtypes_Statically_Match (Ptyp, Btyp) then
4785 Rewrite (N,
4786 Make_And_Then (Loc,
4787 Left_Opnd => Relocate_Node (N),
4788 Right_Opnd =>
4789 Make_In (Loc,
4790 Left_Opnd => Convert_To (Btyp, Pref),
4791 Right_Opnd => New_Occurrence_Of (Ptyp, Loc))));
4792 end if;
4793 end;
4795 -- Enumeration type with holes
4797 -- For enumeration types with holes, the Pos value constructed by
4798 -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a
4799 -- second argument of False returns minus one for an invalid value,
4800 -- and the non-negative pos value for a valid value, so the
4801 -- expansion of X'Valid is simply:
4803 -- type(X)'Pos (X) >= 0
4805 -- We can't quite generate it that way because of the requirement
4806 -- for the non-standard second argument of False in the resulting
4807 -- rep_to_pos call, so we have to explicitly create:
4809 -- _rep_to_pos (X, False) >= 0
4811 -- If we have an enumeration subtype, we also check that the
4812 -- value is in range:
4814 -- _rep_to_pos (X, False) >= 0
4815 -- and then
4816 -- (X >= type(X)'First and then type(X)'Last <= X)
4818 elsif Is_Enumeration_Type (Ptyp)
4819 and then Present (Enum_Pos_To_Rep (Base_Type (Ptyp)))
4820 then
4821 Tst :=
4822 Make_Op_Ge (Loc,
4823 Left_Opnd =>
4824 Make_Function_Call (Loc,
4825 Name =>
4826 New_Reference_To
4827 (TSS (Base_Type (Ptyp), TSS_Rep_To_Pos), Loc),
4828 Parameter_Associations => New_List (
4829 Pref,
4830 New_Occurrence_Of (Standard_False, Loc))),
4831 Right_Opnd => Make_Integer_Literal (Loc, 0));
4833 if Ptyp /= Btyp
4834 and then
4835 (Type_Low_Bound (Ptyp) /= Type_Low_Bound (Btyp)
4836 or else
4837 Type_High_Bound (Ptyp) /= Type_High_Bound (Btyp))
4838 then
4839 -- The call to Make_Range_Test will create declarations
4840 -- that need a proper insertion point, but Pref is now
4841 -- attached to a node with no ancestor. Attach to tree
4842 -- even if it is to be rewritten below.
4844 Set_Parent (Tst, Parent (N));
4846 Tst :=
4847 Make_And_Then (Loc,
4848 Left_Opnd => Make_Range_Test,
4849 Right_Opnd => Tst);
4850 end if;
4852 Rewrite (N, Tst);
4854 -- Fortran convention booleans
4856 -- For the very special case of Fortran convention booleans, the
4857 -- value is always valid, since it is an integer with the semantics
4858 -- that non-zero is true, and any value is permissible.
4860 elsif Is_Boolean_Type (Ptyp)
4861 and then Convention (Ptyp) = Convention_Fortran
4862 then
4863 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4865 -- For biased representations, we will be doing an unchecked
4866 -- conversion without unbiasing the result. That means that the range
4867 -- test has to take this into account, and the proper form of the
4868 -- test is:
4870 -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length)
4872 elsif Has_Biased_Representation (Ptyp) then
4873 Btyp := RTE (RE_Unsigned_32);
4874 Rewrite (N,
4875 Make_Op_Lt (Loc,
4876 Left_Opnd =>
4877 Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
4878 Right_Opnd =>
4879 Unchecked_Convert_To (Btyp,
4880 Make_Attribute_Reference (Loc,
4881 Prefix => New_Occurrence_Of (Ptyp, Loc),
4882 Attribute_Name => Name_Range_Length))));
4884 -- For all other scalar types, what we want logically is a
4885 -- range test:
4887 -- X in type(X)'First .. type(X)'Last
4889 -- But that's precisely what won't work because of possible
4890 -- unwanted optimization (and indeed the basic motivation for
4891 -- the Valid attribute is exactly that this test does not work!)
4892 -- What will work is:
4894 -- Btyp!(X) >= Btyp!(type(X)'First)
4895 -- and then
4896 -- Btyp!(X) <= Btyp!(type(X)'Last)
4898 -- where Btyp is an integer type large enough to cover the full
4899 -- range of possible stored values (i.e. it is chosen on the basis
4900 -- of the size of the type, not the range of the values). We write
4901 -- this as two tests, rather than a range check, so that static
4902 -- evaluation will easily remove either or both of the checks if
4903 -- they can be -statically determined to be true (this happens
4904 -- when the type of X is static and the range extends to the full
4905 -- range of stored values).
4907 -- Unsigned types. Note: it is safe to consider only whether the
4908 -- subtype is unsigned, since we will in that case be doing all
4909 -- unsigned comparisons based on the subtype range. Since we use the
4910 -- actual subtype object size, this is appropriate.
4912 -- For example, if we have
4914 -- subtype x is integer range 1 .. 200;
4915 -- for x'Object_Size use 8;
4917 -- Now the base type is signed, but objects of this type are bits
4918 -- unsigned, and doing an unsigned test of the range 1 to 200 is
4919 -- correct, even though a value greater than 127 looks signed to a
4920 -- signed comparison.
4922 elsif Is_Unsigned_Type (Ptyp) then
4923 if Esize (Ptyp) <= 32 then
4924 Btyp := RTE (RE_Unsigned_32);
4925 else
4926 Btyp := RTE (RE_Unsigned_64);
4927 end if;
4929 Rewrite (N, Make_Range_Test);
4931 -- Signed types
4933 else
4934 if Esize (Ptyp) <= Esize (Standard_Integer) then
4935 Btyp := Standard_Integer;
4936 else
4937 Btyp := Universal_Integer;
4938 end if;
4940 Rewrite (N, Make_Range_Test);
4941 end if;
4943 Analyze_And_Resolve (N, Standard_Boolean);
4944 Validity_Checks_On := Save_Validity_Checks_On;
4945 end Valid;
4947 -----------
4948 -- Value --
4949 -----------
4951 -- Value attribute is handled in separate unti Exp_Imgv
4953 when Attribute_Value =>
4954 Exp_Imgv.Expand_Value_Attribute (N);
4956 -----------------
4957 -- Value_Size --
4958 -----------------
4960 -- The processing for Value_Size shares the processing for Size
4962 -------------
4963 -- Version --
4964 -------------
4966 -- The processing for Version shares the processing for Body_Version
4968 ----------------
4969 -- Wide_Image --
4970 ----------------
4972 -- Wide_Image attribute is handled in separate unit Exp_Imgv
4974 when Attribute_Wide_Image =>
4975 Exp_Imgv.Expand_Wide_Image_Attribute (N);
4977 ---------------------
4978 -- Wide_Wide_Image --
4979 ---------------------
4981 -- Wide_Wide_Image attribute is handled in separate unit Exp_Imgv
4983 when Attribute_Wide_Wide_Image =>
4984 Exp_Imgv.Expand_Wide_Wide_Image_Attribute (N);
4986 ----------------
4987 -- Wide_Value --
4988 ----------------
4990 -- We expand typ'Wide_Value (X) into
4992 -- typ'Value
4993 -- (Wide_String_To_String (X, Wide_Character_Encoding_Method))
4995 -- Wide_String_To_String is a runtime function that converts its wide
4996 -- string argument to String, converting any non-translatable characters
4997 -- into appropriate escape sequences. This preserves the required
4998 -- semantics of Wide_Value in all cases, and results in a very simple
4999 -- implementation approach.
5001 -- Note: for this approach to be fully standard compliant for the cases
5002 -- where typ is Wide_Character and Wide_Wide_Character, the encoding
5003 -- method must cover the entire character range (e.g. UTF-8). But that
5004 -- is a reasonable requirement when dealing with encoded character
5005 -- sequences. Presumably if one of the restrictive encoding mechanisms
5006 -- is in use such as Shift-JIS, then characters that cannot be
5007 -- represented using this encoding will not appear in any case.
5009 when Attribute_Wide_Value => Wide_Value :
5010 begin
5011 Rewrite (N,
5012 Make_Attribute_Reference (Loc,
5013 Prefix => Pref,
5014 Attribute_Name => Name_Value,
5016 Expressions => New_List (
5017 Make_Function_Call (Loc,
5018 Name =>
5019 New_Reference_To (RTE (RE_Wide_String_To_String), Loc),
5021 Parameter_Associations => New_List (
5022 Relocate_Node (First (Exprs)),
5023 Make_Integer_Literal (Loc,
5024 Intval => Int (Wide_Character_Encoding_Method)))))));
5026 Analyze_And_Resolve (N, Typ);
5027 end Wide_Value;
5029 ---------------------
5030 -- Wide_Wide_Value --
5031 ---------------------
5033 -- We expand typ'Wide_Value_Value (X) into
5035 -- typ'Value
5036 -- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method))
5038 -- Wide_Wide_String_To_String is a runtime function that converts its
5039 -- wide string argument to String, converting any non-translatable
5040 -- characters into appropriate escape sequences. This preserves the
5041 -- required semantics of Wide_Wide_Value in all cases, and results in a
5042 -- very simple implementation approach.
5044 -- It's not quite right where typ = Wide_Wide_Character, because the
5045 -- encoding method may not cover the whole character type ???
5047 when Attribute_Wide_Wide_Value => Wide_Wide_Value :
5048 begin
5049 Rewrite (N,
5050 Make_Attribute_Reference (Loc,
5051 Prefix => Pref,
5052 Attribute_Name => Name_Value,
5054 Expressions => New_List (
5055 Make_Function_Call (Loc,
5056 Name =>
5057 New_Reference_To (RTE (RE_Wide_Wide_String_To_String), Loc),
5059 Parameter_Associations => New_List (
5060 Relocate_Node (First (Exprs)),
5061 Make_Integer_Literal (Loc,
5062 Intval => Int (Wide_Character_Encoding_Method)))))));
5064 Analyze_And_Resolve (N, Typ);
5065 end Wide_Wide_Value;
5067 ---------------------
5068 -- Wide_Wide_Width --
5069 ---------------------
5071 -- Wide_Wide_Width attribute is handled in separate unit Exp_Imgv
5073 when Attribute_Wide_Wide_Width =>
5074 Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide);
5076 ----------------
5077 -- Wide_Width --
5078 ----------------
5080 -- Wide_Width attribute is handled in separate unit Exp_Imgv
5082 when Attribute_Wide_Width =>
5083 Exp_Imgv.Expand_Width_Attribute (N, Wide);
5085 -----------
5086 -- Width --
5087 -----------
5089 -- Width attribute is handled in separate unit Exp_Imgv
5091 when Attribute_Width =>
5092 Exp_Imgv.Expand_Width_Attribute (N, Normal);
5094 -----------
5095 -- Write --
5096 -----------
5098 when Attribute_Write => Write : declare
5099 P_Type : constant Entity_Id := Entity (Pref);
5100 U_Type : constant Entity_Id := Underlying_Type (P_Type);
5101 Pname : Entity_Id;
5102 Decl : Node_Id;
5103 Prag : Node_Id;
5104 Arg3 : Node_Id;
5105 Wfunc : Node_Id;
5107 begin
5108 -- If no underlying type, we have an error that will be diagnosed
5109 -- elsewhere, so here we just completely ignore the expansion.
5111 if No (U_Type) then
5112 return;
5113 end if;
5115 -- The simple case, if there is a TSS for Write, just call it
5117 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write);
5119 if Present (Pname) then
5120 null;
5122 else
5123 -- If there is a Stream_Convert pragma, use it, we rewrite
5125 -- sourcetyp'Output (stream, Item)
5127 -- as
5129 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
5131 -- where strmwrite is the given Write function that converts an
5132 -- argument of type sourcetyp or a type acctyp, from which it is
5133 -- derived to type strmtyp. The conversion to acttyp is required
5134 -- for the derived case.
5136 Prag := Get_Stream_Convert_Pragma (P_Type);
5138 if Present (Prag) then
5139 Arg3 :=
5140 Next (Next (First (Pragma_Argument_Associations (Prag))));
5141 Wfunc := Entity (Expression (Arg3));
5143 Rewrite (N,
5144 Make_Attribute_Reference (Loc,
5145 Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
5146 Attribute_Name => Name_Output,
5147 Expressions => New_List (
5148 Relocate_Node (First (Exprs)),
5149 Make_Function_Call (Loc,
5150 Name => New_Occurrence_Of (Wfunc, Loc),
5151 Parameter_Associations => New_List (
5152 OK_Convert_To (Etype (First_Formal (Wfunc)),
5153 Relocate_Node (Next (First (Exprs)))))))));
5155 Analyze (N);
5156 return;
5158 -- For elementary types, we call the W_xxx routine directly
5160 elsif Is_Elementary_Type (U_Type) then
5161 Rewrite (N, Build_Elementary_Write_Call (N));
5162 Analyze (N);
5163 return;
5165 -- Array type case
5167 elsif Is_Array_Type (U_Type) then
5168 Build_Array_Write_Procedure (N, U_Type, Decl, Pname);
5169 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
5171 -- Tagged type case, use the primitive Write function. Note that
5172 -- this will dispatch in the class-wide case which is what we want
5174 elsif Is_Tagged_Type (U_Type) then
5175 Pname := Find_Prim_Op (U_Type, TSS_Stream_Write);
5177 -- All other record type cases, including protected records.
5178 -- The latter only arise for expander generated code for
5179 -- handling shared passive partition access.
5181 else
5182 pragma Assert
5183 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
5185 -- Ada 2005 (AI-216): Program_Error is raised when executing
5186 -- the default implementation of the Write attribute of an
5187 -- Unchecked_Union type. However, if the 'Write reference is
5188 -- within the generated Output stream procedure, Write outputs
5189 -- the components, and the default values of the discriminant
5190 -- are streamed by the Output procedure itself.
5192 if Is_Unchecked_Union (Base_Type (U_Type))
5193 and not Is_TSS (Current_Scope, TSS_Stream_Output)
5194 then
5195 Insert_Action (N,
5196 Make_Raise_Program_Error (Loc,
5197 Reason => PE_Unchecked_Union_Restriction));
5198 end if;
5200 if Has_Discriminants (U_Type)
5201 and then Present
5202 (Discriminant_Default_Value (First_Discriminant (U_Type)))
5203 then
5204 Build_Mutable_Record_Write_Procedure
5205 (Loc, Base_Type (U_Type), Decl, Pname);
5206 else
5207 Build_Record_Write_Procedure
5208 (Loc, Base_Type (U_Type), Decl, Pname);
5209 end if;
5211 Insert_Action (N, Decl);
5212 end if;
5213 end if;
5215 -- If we fall through, Pname is the procedure to be called
5217 Rewrite_Stream_Proc_Call (Pname);
5218 end Write;
5220 -- Component_Size is handled by the back end, unless the component size
5221 -- is known at compile time, which is always true in the packed array
5222 -- case. It is important that the packed array case is handled in the
5223 -- front end (see Eval_Attribute) since the back end would otherwise get
5224 -- confused by the equivalent packed array type.
5226 when Attribute_Component_Size =>
5227 null;
5229 -- The following attributes are handled by the back end (except that
5230 -- static cases have already been evaluated during semantic processing,
5231 -- but in any case the back end should not count on this). The one bit
5232 -- of special processing required is that these attributes typically
5233 -- generate conditionals in the code, so we need to check the relevant
5234 -- restriction.
5236 when Attribute_Max |
5237 Attribute_Min =>
5238 Check_Restriction (No_Implicit_Conditionals, N);
5240 -- The following attributes are handled by the back end (except that
5241 -- static cases have already been evaluated during semantic processing,
5242 -- but in any case the back end should not count on this).
5244 -- The back end also handles the non-class-wide cases of Size
5246 when Attribute_Bit_Order |
5247 Attribute_Code_Address |
5248 Attribute_Definite |
5249 Attribute_Null_Parameter |
5250 Attribute_Passed_By_Reference |
5251 Attribute_Pool_Address =>
5252 null;
5254 -- The following attributes are also handled by the back end, but return
5255 -- a universal integer result, so may need a conversion for checking
5256 -- that the result is in range.
5258 when Attribute_Aft |
5259 Attribute_Bit |
5260 Attribute_Max_Size_In_Storage_Elements
5262 Apply_Universal_Integer_Attribute_Checks (N);
5264 -- The following attributes should not appear at this stage, since they
5265 -- have already been handled by the analyzer (and properly rewritten
5266 -- with corresponding values or entities to represent the right values)
5268 when Attribute_Abort_Signal |
5269 Attribute_Address_Size |
5270 Attribute_Base |
5271 Attribute_Class |
5272 Attribute_Compiler_Version |
5273 Attribute_Default_Bit_Order |
5274 Attribute_Delta |
5275 Attribute_Denorm |
5276 Attribute_Digits |
5277 Attribute_Emax |
5278 Attribute_Enabled |
5279 Attribute_Epsilon |
5280 Attribute_Fast_Math |
5281 Attribute_Has_Access_Values |
5282 Attribute_Has_Discriminants |
5283 Attribute_Has_Tagged_Values |
5284 Attribute_Large |
5285 Attribute_Machine_Emax |
5286 Attribute_Machine_Emin |
5287 Attribute_Machine_Mantissa |
5288 Attribute_Machine_Overflows |
5289 Attribute_Machine_Radix |
5290 Attribute_Machine_Rounds |
5291 Attribute_Maximum_Alignment |
5292 Attribute_Model_Emin |
5293 Attribute_Model_Epsilon |
5294 Attribute_Model_Mantissa |
5295 Attribute_Model_Small |
5296 Attribute_Modulus |
5297 Attribute_Partition_ID |
5298 Attribute_Range |
5299 Attribute_Safe_Emax |
5300 Attribute_Safe_First |
5301 Attribute_Safe_Large |
5302 Attribute_Safe_Last |
5303 Attribute_Safe_Small |
5304 Attribute_Scale |
5305 Attribute_Signed_Zeros |
5306 Attribute_Small |
5307 Attribute_Storage_Unit |
5308 Attribute_Stub_Type |
5309 Attribute_Target_Name |
5310 Attribute_Type_Class |
5311 Attribute_Unconstrained_Array |
5312 Attribute_Universal_Literal_String |
5313 Attribute_Wchar_T_Size |
5314 Attribute_Word_Size =>
5316 raise Program_Error;
5318 -- The Asm_Input and Asm_Output attributes are not expanded at this
5319 -- stage, but will be eliminated in the expansion of the Asm call, see
5320 -- Exp_Intr for details. So the back end will never see these either.
5322 when Attribute_Asm_Input |
5323 Attribute_Asm_Output =>
5325 null;
5327 end case;
5329 exception
5330 when RE_Not_Available =>
5331 return;
5332 end Expand_N_Attribute_Reference;
5334 ----------------------
5335 -- Expand_Pred_Succ --
5336 ----------------------
5338 -- For typ'Pred (exp), we generate the check
5340 -- [constraint_error when exp = typ'Base'First]
5342 -- Similarly, for typ'Succ (exp), we generate the check
5344 -- [constraint_error when exp = typ'Base'Last]
5346 -- These checks are not generated for modular types, since the proper
5347 -- semantics for Succ and Pred on modular types is to wrap, not raise CE.
5349 procedure Expand_Pred_Succ (N : Node_Id) is
5350 Loc : constant Source_Ptr := Sloc (N);
5351 Cnam : Name_Id;
5353 begin
5354 if Attribute_Name (N) = Name_Pred then
5355 Cnam := Name_First;
5356 else
5357 Cnam := Name_Last;
5358 end if;
5360 Insert_Action (N,
5361 Make_Raise_Constraint_Error (Loc,
5362 Condition =>
5363 Make_Op_Eq (Loc,
5364 Left_Opnd =>
5365 Duplicate_Subexpr_Move_Checks (First (Expressions (N))),
5366 Right_Opnd =>
5367 Make_Attribute_Reference (Loc,
5368 Prefix =>
5369 New_Reference_To (Base_Type (Etype (Prefix (N))), Loc),
5370 Attribute_Name => Cnam)),
5371 Reason => CE_Overflow_Check_Failed));
5372 end Expand_Pred_Succ;
5374 -------------------
5375 -- Find_Fat_Info --
5376 -------------------
5378 procedure Find_Fat_Info
5379 (T : Entity_Id;
5380 Fat_Type : out Entity_Id;
5381 Fat_Pkg : out RE_Id)
5383 Btyp : constant Entity_Id := Base_Type (T);
5384 Rtyp : constant Entity_Id := Root_Type (T);
5385 Digs : constant Nat := UI_To_Int (Digits_Value (Btyp));
5387 begin
5388 -- If the base type is VAX float, then get appropriate VAX float type
5390 if Vax_Float (Btyp) then
5391 case Digs is
5392 when 6 =>
5393 Fat_Type := RTE (RE_Fat_VAX_F);
5394 Fat_Pkg := RE_Attr_VAX_F_Float;
5396 when 9 =>
5397 Fat_Type := RTE (RE_Fat_VAX_D);
5398 Fat_Pkg := RE_Attr_VAX_D_Float;
5400 when 15 =>
5401 Fat_Type := RTE (RE_Fat_VAX_G);
5402 Fat_Pkg := RE_Attr_VAX_G_Float;
5404 when others =>
5405 raise Program_Error;
5406 end case;
5408 -- If root type is VAX float, this is the case where the library has
5409 -- been recompiled in VAX float mode, and we have an IEEE float type.
5410 -- This is when we use the special IEEE Fat packages.
5412 elsif Vax_Float (Rtyp) then
5413 case Digs is
5414 when 6 =>
5415 Fat_Type := RTE (RE_Fat_IEEE_Short);
5416 Fat_Pkg := RE_Attr_IEEE_Short;
5418 when 15 =>
5419 Fat_Type := RTE (RE_Fat_IEEE_Long);
5420 Fat_Pkg := RE_Attr_IEEE_Long;
5422 when others =>
5423 raise Program_Error;
5424 end case;
5426 -- If neither the base type nor the root type is VAX_Float then VAX
5427 -- float is out of the picture, and we can just use the root type.
5429 else
5430 Fat_Type := Rtyp;
5432 if Fat_Type = Standard_Short_Float then
5433 Fat_Pkg := RE_Attr_Short_Float;
5435 elsif Fat_Type = Standard_Float then
5436 Fat_Pkg := RE_Attr_Float;
5438 elsif Fat_Type = Standard_Long_Float then
5439 Fat_Pkg := RE_Attr_Long_Float;
5441 elsif Fat_Type = Standard_Long_Long_Float then
5442 Fat_Pkg := RE_Attr_Long_Long_Float;
5444 -- Universal real (which is its own root type) is treated as being
5445 -- equivalent to Standard.Long_Long_Float, since it is defined to
5446 -- have the same precision as the longest Float type.
5448 elsif Fat_Type = Universal_Real then
5449 Fat_Type := Standard_Long_Long_Float;
5450 Fat_Pkg := RE_Attr_Long_Long_Float;
5452 else
5453 raise Program_Error;
5454 end if;
5455 end if;
5456 end Find_Fat_Info;
5458 ----------------------------
5459 -- Find_Stream_Subprogram --
5460 ----------------------------
5462 function Find_Stream_Subprogram
5463 (Typ : Entity_Id;
5464 Nam : TSS_Name_Type) return Entity_Id
5466 Base_Typ : constant Entity_Id := Base_Type (Typ);
5467 Ent : constant Entity_Id := TSS (Typ, Nam);
5469 begin
5470 if Present (Ent) then
5471 return Ent;
5472 end if;
5474 -- Stream attributes for strings are expanded into library calls. The
5475 -- following checks are disabled when the run-time is not available or
5476 -- when compiling predefined types due to bootstrap issues. As a result,
5477 -- the compiler will generate in-place stream routines for string types
5478 -- that appear in GNAT's library, but will generate calls via rtsfind
5479 -- to library routines for user code.
5480 -- ??? For now, disable this code for JVM, since this generates a
5481 -- VerifyError exception at run-time on e.g. c330001.
5482 -- This is disabled for AAMP, to avoid making dependences on files not
5483 -- supported in the AAMP library (such as s-fileio.adb).
5485 if VM_Target /= JVM_Target
5486 and then not AAMP_On_Target
5487 and then
5488 not Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
5489 then
5490 -- String as defined in package Ada
5492 if Base_Typ = Standard_String then
5493 if Restriction_Active (No_Stream_Optimizations) then
5494 if Nam = TSS_Stream_Input then
5495 return RTE (RE_String_Input);
5497 elsif Nam = TSS_Stream_Output then
5498 return RTE (RE_String_Output);
5500 elsif Nam = TSS_Stream_Read then
5501 return RTE (RE_String_Read);
5503 else pragma Assert (Nam = TSS_Stream_Write);
5504 return RTE (RE_String_Write);
5505 end if;
5507 else
5508 if Nam = TSS_Stream_Input then
5509 return RTE (RE_String_Input_Blk_IO);
5511 elsif Nam = TSS_Stream_Output then
5512 return RTE (RE_String_Output_Blk_IO);
5514 elsif Nam = TSS_Stream_Read then
5515 return RTE (RE_String_Read_Blk_IO);
5517 else pragma Assert (Nam = TSS_Stream_Write);
5518 return RTE (RE_String_Write_Blk_IO);
5519 end if;
5520 end if;
5522 -- Wide_String as defined in package Ada
5524 elsif Base_Typ = Standard_Wide_String then
5525 if Restriction_Active (No_Stream_Optimizations) then
5526 if Nam = TSS_Stream_Input then
5527 return RTE (RE_Wide_String_Input);
5529 elsif Nam = TSS_Stream_Output then
5530 return RTE (RE_Wide_String_Output);
5532 elsif Nam = TSS_Stream_Read then
5533 return RTE (RE_Wide_String_Read);
5535 else pragma Assert (Nam = TSS_Stream_Write);
5536 return RTE (RE_Wide_String_Write);
5537 end if;
5539 else
5540 if Nam = TSS_Stream_Input then
5541 return RTE (RE_Wide_String_Input_Blk_IO);
5543 elsif Nam = TSS_Stream_Output then
5544 return RTE (RE_Wide_String_Output_Blk_IO);
5546 elsif Nam = TSS_Stream_Read then
5547 return RTE (RE_Wide_String_Read_Blk_IO);
5549 else pragma Assert (Nam = TSS_Stream_Write);
5550 return RTE (RE_Wide_String_Write_Blk_IO);
5551 end if;
5552 end if;
5554 -- Wide_Wide_String as defined in package Ada
5556 elsif Base_Typ = Standard_Wide_Wide_String then
5557 if Restriction_Active (No_Stream_Optimizations) then
5558 if Nam = TSS_Stream_Input then
5559 return RTE (RE_Wide_Wide_String_Input);
5561 elsif Nam = TSS_Stream_Output then
5562 return RTE (RE_Wide_Wide_String_Output);
5564 elsif Nam = TSS_Stream_Read then
5565 return RTE (RE_Wide_Wide_String_Read);
5567 else pragma Assert (Nam = TSS_Stream_Write);
5568 return RTE (RE_Wide_Wide_String_Write);
5569 end if;
5571 else
5572 if Nam = TSS_Stream_Input then
5573 return RTE (RE_Wide_Wide_String_Input_Blk_IO);
5575 elsif Nam = TSS_Stream_Output then
5576 return RTE (RE_Wide_Wide_String_Output_Blk_IO);
5578 elsif Nam = TSS_Stream_Read then
5579 return RTE (RE_Wide_Wide_String_Read_Blk_IO);
5581 else pragma Assert (Nam = TSS_Stream_Write);
5582 return RTE (RE_Wide_Wide_String_Write_Blk_IO);
5583 end if;
5584 end if;
5585 end if;
5586 end if;
5588 if Is_Tagged_Type (Typ)
5589 and then Is_Derived_Type (Typ)
5590 then
5591 return Find_Prim_Op (Typ, Nam);
5592 else
5593 return Find_Inherited_TSS (Typ, Nam);
5594 end if;
5595 end Find_Stream_Subprogram;
5597 -----------------------
5598 -- Get_Index_Subtype --
5599 -----------------------
5601 function Get_Index_Subtype (N : Node_Id) return Node_Id is
5602 P_Type : Entity_Id := Etype (Prefix (N));
5603 Indx : Node_Id;
5604 J : Int;
5606 begin
5607 if Is_Access_Type (P_Type) then
5608 P_Type := Designated_Type (P_Type);
5609 end if;
5611 if No (Expressions (N)) then
5612 J := 1;
5613 else
5614 J := UI_To_Int (Expr_Value (First (Expressions (N))));
5615 end if;
5617 Indx := First_Index (P_Type);
5618 while J > 1 loop
5619 Next_Index (Indx);
5620 J := J - 1;
5621 end loop;
5623 return Etype (Indx);
5624 end Get_Index_Subtype;
5626 -------------------------------
5627 -- Get_Stream_Convert_Pragma --
5628 -------------------------------
5630 function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id is
5631 Typ : Entity_Id;
5632 N : Node_Id;
5634 begin
5635 -- Note: we cannot use Get_Rep_Pragma here because of the peculiarity
5636 -- that a stream convert pragma for a tagged type is not inherited from
5637 -- its parent. Probably what is wrong here is that it is basically
5638 -- incorrect to consider a stream convert pragma to be a representation
5639 -- pragma at all ???
5641 N := First_Rep_Item (Implementation_Base_Type (T));
5642 while Present (N) loop
5643 if Nkind (N) = N_Pragma
5644 and then Pragma_Name (N) = Name_Stream_Convert
5645 then
5646 -- For tagged types this pragma is not inherited, so we
5647 -- must verify that it is defined for the given type and
5648 -- not an ancestor.
5650 Typ :=
5651 Entity (Expression (First (Pragma_Argument_Associations (N))));
5653 if not Is_Tagged_Type (T)
5654 or else T = Typ
5655 or else (Is_Private_Type (Typ) and then T = Full_View (Typ))
5656 then
5657 return N;
5658 end if;
5659 end if;
5661 Next_Rep_Item (N);
5662 end loop;
5664 return Empty;
5665 end Get_Stream_Convert_Pragma;
5667 ---------------------------------
5668 -- Is_Constrained_Packed_Array --
5669 ---------------------------------
5671 function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean is
5672 Arr : Entity_Id := Typ;
5674 begin
5675 if Is_Access_Type (Arr) then
5676 Arr := Designated_Type (Arr);
5677 end if;
5679 return Is_Array_Type (Arr)
5680 and then Is_Constrained (Arr)
5681 and then Present (Packed_Array_Type (Arr));
5682 end Is_Constrained_Packed_Array;
5684 ----------------------------------------
5685 -- Is_Inline_Floating_Point_Attribute --
5686 ----------------------------------------
5688 function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean is
5689 Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N));
5691 begin
5692 if Nkind (Parent (N)) /= N_Type_Conversion
5693 or else not Is_Integer_Type (Etype (Parent (N)))
5694 then
5695 return False;
5696 end if;
5698 -- Should also support 'Machine_Rounding and 'Unbiased_Rounding, but
5699 -- required back end support has not been implemented yet ???
5701 return Id = Attribute_Truncation;
5702 end Is_Inline_Floating_Point_Attribute;
5704 end Exp_Attr;