1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
28 with Atree
; use Atree
;
29 with Casing
; use Casing
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Dist
; use Exp_Dist
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
47 with Sdefault
; use Sdefault
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dist
; use Sem_Dist
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Res
; use Sem_Res
;
55 with Sem_Type
; use Sem_Type
;
56 with Sem_Util
; use Sem_Util
;
57 with Stand
; use Stand
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with Stringt
; use Stringt
;
62 with Stylesw
; use Stylesw
;
63 with Targparm
; use Targparm
;
64 with Ttypes
; use Ttypes
;
65 with Ttypef
; use Ttypef
;
66 with Tbuild
; use Tbuild
;
67 with Uintp
; use Uintp
;
68 with Urealp
; use Urealp
;
70 package body Sem_Attr
is
72 True_Value
: constant Uint
:= Uint_1
;
73 False_Value
: constant Uint
:= Uint_0
;
74 -- Synonyms to be used when these constants are used as Boolean values
76 Bad_Attribute
: exception;
77 -- Exception raised if an error is detected during attribute processing,
78 -- used so that we can abandon the processing so we don't run into
79 -- trouble with cascaded errors.
81 -- The following array is the list of attributes defined in the Ada 83 RM
82 -- that are not included in Ada 95, but still get recognized in GNAT.
84 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
90 Attribute_Constrained |
103 Attribute_Leading_Part |
105 Attribute_Machine_Emax |
106 Attribute_Machine_Emin |
107 Attribute_Machine_Mantissa |
108 Attribute_Machine_Overflows |
109 Attribute_Machine_Radix |
110 Attribute_Machine_Rounds |
116 Attribute_Safe_Emax |
117 Attribute_Safe_Large |
118 Attribute_Safe_Small |
121 Attribute_Storage_Size |
123 Attribute_Terminated |
126 Attribute_Width => True,
129 -- The following array is the list of attributes defined in the Ada 2005
130 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
131 -- but in Ada 95 they are considered to be implementation defined.
133 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
134 Attribute_Machine_Rounding |
136 Attribute_Stream_Size |
137 Attribute_Wide_Wide_Width
=> True,
140 -- The following array contains all attributes that imply a modification
141 -- of their prefixes or result in an access value. Such prefixes can be
142 -- considered as lvalues.
144 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
145 Attribute_Class_Array
'(
150 Attribute_Unchecked_Access |
151 Attribute_Unrestricted_Access => True,
154 -----------------------
155 -- Local_Subprograms --
156 -----------------------
158 procedure Eval_Attribute (N : Node_Id);
159 -- Performs compile time evaluation of attributes where possible, leaving
160 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
161 -- set, and replacing the node with a literal node if the value can be
162 -- computed at compile time. All static attribute references are folded,
163 -- as well as a number of cases of non-static attributes that can always
164 -- be computed at compile time (e.g. floating-point model attributes that
165 -- are applied to non-static subtypes). Of course in such cases, the
166 -- Is_Static_Expression flag will not be set on the resulting literal.
167 -- Note that the only required action of this procedure is to catch the
168 -- static expression cases as described in the RM. Folding of other cases
169 -- is done where convenient, but some additional non-static folding is in
170 -- N_Expand_Attribute_Reference in cases where this is more convenient.
172 function Is_Anonymous_Tagged_Base
176 -- For derived tagged types that constrain parent discriminants we build
177 -- an anonymous unconstrained base type. We need to recognize the relation
178 -- between the two when analyzing an access attribute for a constrained
179 -- component, before the full declaration for Typ has been analyzed, and
180 -- where therefore the prefix of the attribute does not match the enclosing
183 -----------------------
184 -- Analyze_Attribute --
185 -----------------------
187 procedure Analyze_Attribute (N : Node_Id) is
188 Loc : constant Source_Ptr := Sloc (N);
189 Aname : constant Name_Id := Attribute_Name (N);
190 P : constant Node_Id := Prefix (N);
191 Exprs : constant List_Id := Expressions (N);
192 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
197 -- Type of prefix after analysis
199 P_Base_Type : Entity_Id;
200 -- Base type of prefix after analysis
202 -----------------------
203 -- Local Subprograms --
204 -----------------------
206 procedure Analyze_Access_Attribute;
207 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
208 -- Internally, Id distinguishes which of the three cases is involved.
210 procedure Check_Array_Or_Scalar_Type;
211 -- Common procedure used by First, Last, Range attribute to check
212 -- that the prefix is a constrained array or scalar type, or a name
213 -- of an array object, and that an argument appears only if appropriate
214 -- (i.e. only in the array case).
216 procedure Check_Array_Type;
217 -- Common semantic checks for all array attributes. Checks that the
218 -- prefix is a constrained array type or the name of an array object.
219 -- The error message for non-arrays is specialized appropriately.
221 procedure Check_Asm_Attribute;
222 -- Common semantic checks for Asm_Input and Asm_Output attributes
224 procedure Check_Component;
225 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
226 -- Position. Checks prefix is an appropriate selected component.
228 procedure Check_Decimal_Fixed_Point_Type;
229 -- Check that prefix of attribute N is a decimal fixed-point type
231 procedure Check_Dereference;
232 -- If the prefix of attribute is an object of an access type, then
233 -- introduce an explicit deference, and adjust P_Type accordingly.
235 procedure Check_Discrete_Type;
236 -- Verify that prefix of attribute N is a discrete type
239 -- Check that no attribute arguments are present
241 procedure Check_Either_E0_Or_E1;
242 -- Check that there are zero or one attribute arguments present
245 -- Check that exactly one attribute argument is present
248 -- Check that two attribute arguments are present
250 procedure Check_Enum_Image;
251 -- If the prefix type is an enumeration type, set all its literals
252 -- as referenced, since the image function could possibly end up
253 -- referencing any of the literals indirectly. Same for Enum_Val.
255 procedure Check_Fixed_Point_Type;
256 -- Verify that prefix of attribute N is a fixed type
258 procedure Check_Fixed_Point_Type_0;
259 -- Verify that prefix of attribute N is a fixed type and that
260 -- no attribute expressions are present
262 procedure Check_Floating_Point_Type;
263 -- Verify that prefix of attribute N is a float type
265 procedure Check_Floating_Point_Type_0;
266 -- Verify that prefix of attribute N is a float type and that
267 -- no attribute expressions are present
269 procedure Check_Floating_Point_Type_1;
270 -- Verify that prefix of attribute N is a float type and that
271 -- exactly one attribute expression is present
273 procedure Check_Floating_Point_Type_2;
274 -- Verify that prefix of attribute N is a float type and that
275 -- two attribute expressions are present
277 procedure Legal_Formal_Attribute;
278 -- Common processing for attributes Definite and Has_Discriminants.
279 -- Checks that prefix is generic indefinite formal type.
281 procedure Check_Integer_Type;
282 -- Verify that prefix of attribute N is an integer type
284 procedure Check_Library_Unit;
285 -- Verify that prefix of attribute N is a library unit
287 procedure Check_Modular_Integer_Type;
288 -- Verify that prefix of attribute N is a modular integer type
290 procedure Check_Not_CPP_Type;
291 -- Check that P (the prefix of the attribute) is not an CPP type
292 -- for which no Ada predefined primitive is available.
294 procedure Check_Not_Incomplete_Type;
295 -- Check that P (the prefix of the attribute) is not an incomplete
296 -- type or a private type for which no full view has been given.
298 procedure Check_Object_Reference (P : Node_Id);
299 -- Check that P (the prefix of the attribute) is an object reference
301 procedure Check_Program_Unit;
302 -- Verify that prefix of attribute N is a program unit
304 procedure Check_Real_Type;
305 -- Verify that prefix of attribute N is fixed or float type
307 procedure Check_Scalar_Type;
308 -- Verify that prefix of attribute N is a scalar type
310 procedure Check_Standard_Prefix;
311 -- Verify that prefix of attribute N is package Standard
313 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
314 -- Validity checking for stream attribute. Nam is the TSS name of the
315 -- corresponding possible defined attribute function (e.g. for the
316 -- Read attribute, Nam will be TSS_Stream_Read).
318 procedure Check_PolyORB_Attribute;
319 -- Validity checking for PolyORB/DSA attribute
321 procedure Check_Task_Prefix;
322 -- Verify that prefix of attribute N is a task or task type
324 procedure Check_Type;
325 -- Verify that the prefix of attribute N is a type
327 procedure Check_Unit_Name (Nod : Node_Id);
328 -- Check that Nod is of the form of a library unit name, i.e that
329 -- it is an identifier, or a selected component whose prefix is
330 -- itself of the form of a library unit name. Note that this is
331 -- quite different from Check_Program_Unit, since it only checks
332 -- the syntactic form of the name, not the semantic identity. This
333 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
334 -- UET_Address) which can refer to non-visible unit.
336 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
337 pragma No_Return (Error_Attr);
338 procedure Error_Attr;
339 pragma No_Return (Error_Attr);
340 -- Posts error using Error_Msg_N at given node, sets type of attribute
341 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
342 -- semantic processing. The message typically contains a % insertion
343 -- character which is replaced by the attribute name. The call with
344 -- no arguments is used when the caller has already generated the
345 -- required error messages.
347 procedure Error_Attr_P (Msg : String);
348 pragma No_Return (Error_Attr);
349 -- Like Error_Attr, but error is posted at the start of the prefix
351 procedure Standard_Attribute (Val : Int);
352 -- Used to process attributes whose prefix is package Standard which
353 -- yield values of type Universal_Integer. The attribute reference
354 -- node is rewritten with an integer literal of the given value.
356 procedure Unexpected_Argument (En : Node_Id);
357 -- Signal unexpected attribute argument (En is the argument)
359 procedure Validate_Non_Static_Attribute_Function_Call;
360 -- Called when processing an attribute that is a function call to a
361 -- non-static function, i.e. an attribute function that either takes
362 -- non-scalar arguments or returns a non-scalar result. Verifies that
363 -- such a call does not appear in a preelaborable context.
365 ------------------------------
366 -- Analyze_Access_Attribute --
367 ------------------------------
369 procedure Analyze_Access_Attribute is
370 Acc_Type : Entity_Id;
375 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
376 -- Build an access-to-object type whose designated type is DT,
377 -- and whose Ekind is appropriate to the attribute type. The
378 -- type that is constructed is returned as the result.
380 procedure Build_Access_Subprogram_Type (P : Node_Id);
381 -- Build an access to subprogram whose designated type is the type of
382 -- the prefix. If prefix is overloaded, so is the node itself. The
383 -- result is stored in Acc_Type.
385 function OK_Self_Reference return Boolean;
386 -- An access reference whose prefix is a type can legally appear
387 -- within an aggregate, where it is obtained by expansion of
388 -- a defaulted aggregate. The enclosing aggregate that contains
389 -- the self-referenced is flagged so that the self-reference can
390 -- be expanded into a reference to the target object (see exp_aggr).
392 ------------------------------
393 -- Build_Access_Object_Type --
394 ------------------------------
396 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
397 Typ : constant Entity_Id :=
399 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
401 Set_Etype (Typ, Typ);
403 Set_Associated_Node_For_Itype (Typ, N);
404 Set_Directly_Designated_Type (Typ, DT);
406 end Build_Access_Object_Type;
408 ----------------------------------
409 -- Build_Access_Subprogram_Type --
410 ----------------------------------
412 procedure Build_Access_Subprogram_Type (P : Node_Id) is
413 Index : Interp_Index;
416 procedure Check_Local_Access (E : Entity_Id);
417 -- Deal with possible access to local subprogram. If we have such
418 -- an access, we set a flag to kill all tracked values on any call
419 -- because this access value may be passed around, and any called
420 -- code might use it to access a local procedure which clobbers a
423 function Get_Kind (E : Entity_Id) return Entity_Kind;
424 -- Distinguish between access to regular/protected subprograms
426 ------------------------
427 -- Check_Local_Access --
428 ------------------------
430 procedure Check_Local_Access (E : Entity_Id) is
432 if not Is_Library_Level_Entity (E) then
433 Set_Suppress_Value_Tracking_On_Call (Current_Scope);
435 end Check_Local_Access;
441 function Get_Kind (E : Entity_Id) return Entity_Kind is
443 if Convention (E) = Convention_Protected then
444 return E_Access_Protected_Subprogram_Type;
446 return E_Access_Subprogram_Type;
450 -- Start of processing for Build_Access_Subprogram_Type
453 -- In the case of an access to subprogram, use the name of the
454 -- subprogram itself as the designated type. Type-checking in
455 -- this case compares the signatures of the designated types.
457 -- Note: This fragment of the tree is temporarily malformed
458 -- because the correct tree requires an E_Subprogram_Type entity
459 -- as the designated type. In most cases this designated type is
460 -- later overridden by the semantics with the type imposed by the
461 -- context during the resolution phase. In the specific case of
462 -- the expression Address!(Prim'Unrestricted_Access), used to
463 -- initialize slots of dispatch tables, this work will be done by
464 -- the expander (see Exp_Aggr).
466 -- The reason to temporarily add this kind of node to the tree
467 -- instead of a proper E_Subprogram_Type itype, is the following:
468 -- in case of errors found in the source file we report better
469 -- error messages. For example, instead of generating the
472 -- "expected access to subprogram with profile
473 -- defined at line X"
475 -- we currently generate:
477 -- "expected access to function Z defined at line X"
479 Set_Etype (N, Any_Type);
481 if not Is_Overloaded (P) then
482 Check_Local_Access (Entity (P));
484 if not Is_Intrinsic_Subprogram (Entity (P)) then
485 Acc_Type := Create_Itype (Get_Kind (Entity (P)), N);
486 Set_Is_Public (Acc_Type, False);
487 Set_Etype (Acc_Type, Acc_Type);
488 Set_Convention (Acc_Type, Convention (Entity (P)));
489 Set_Directly_Designated_Type (Acc_Type, Entity (P));
490 Set_Etype (N, Acc_Type);
491 Freeze_Before (N, Acc_Type);
495 Get_First_Interp (P, Index, It);
496 while Present (It.Nam) loop
497 Check_Local_Access (It.Nam);
499 if not Is_Intrinsic_Subprogram (It.Nam) then
500 Acc_Type := Create_Itype (Get_Kind (It.Nam), N);
501 Set_Is_Public (Acc_Type, False);
502 Set_Etype (Acc_Type, Acc_Type);
503 Set_Convention (Acc_Type, Convention (It.Nam));
504 Set_Directly_Designated_Type (Acc_Type, It.Nam);
505 Add_One_Interp (N, Acc_Type, Acc_Type);
506 Freeze_Before (N, Acc_Type);
509 Get_Next_Interp (Index, It);
513 -- Cannot be applied to intrinsic. Looking at the tests above,
514 -- the only way Etype (N) can still be set to Any_Type is if
515 -- Is_Intrinsic_Subprogram was True for some referenced entity.
517 if Etype (N) = Any_Type then
518 Error_Attr_P ("prefix of % attribute cannot be intrinsic");
520 end Build_Access_Subprogram_Type;
522 ----------------------
523 -- OK_Self_Reference --
524 ----------------------
526 function OK_Self_Reference return Boolean is
533 (Nkind (Par) = N_Component_Association
534 or else Nkind (Par) in N_Subexpr)
536 if Nkind_In (Par, N_Aggregate, N_Extension_Aggregate) then
537 if Etype (Par) = Typ then
538 Set_Has_Self_Reference (Par);
546 -- No enclosing aggregate, or not a self-reference
549 end OK_Self_Reference;
551 -- Start of processing for Analyze_Access_Attribute
556 if Nkind (P) = N_Character_Literal then
558 ("prefix of % attribute cannot be enumeration literal");
561 -- Case of access to subprogram
563 if Is_Entity_Name (P)
564 and then Is_Overloadable (Entity (P))
566 if Has_Pragma_Inline_Always (Entity (P)) then
568 ("prefix of % attribute cannot be Inline_Always subprogram");
571 if Aname = Name_Unchecked_Access then
572 Error_Attr ("attribute% cannot be applied to a subprogram", P);
575 -- Build the appropriate subprogram type
577 Build_Access_Subprogram_Type (P);
579 -- For unrestricted access, kill current values, since this
580 -- attribute allows a reference to a local subprogram that
581 -- could modify local variables to be passed out of scope
583 if Aname = Name_Unrestricted_Access then
585 -- Do not kill values on nodes initializing dispatch tables
586 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
587 -- is currently generated by the expander only for this
588 -- purpose. Done to keep the quality of warnings currently
589 -- generated by the compiler (otherwise any declaration of
590 -- a tagged type cleans constant indications from its scope).
592 if Nkind (Parent (N)) = N_Unchecked_Type_Conversion
593 and then (Etype (Parent (N)) = RTE (RE_Prim_Ptr)
595 Etype (Parent (N)) = RTE (RE_Size_Ptr))
596 and then Is_Dispatching_Operation
597 (Directly_Designated_Type (Etype (N)))
607 -- Component is an operation of a protected type
609 elsif Nkind (P) = N_Selected_Component
610 and then Is_Overloadable (Entity (Selector_Name (P)))
612 if Ekind (Entity (Selector_Name (P))) = E_Entry then
613 Error_Attr_P ("prefix of % attribute must be subprogram");
616 Build_Access_Subprogram_Type (Selector_Name (P));
620 -- Deal with incorrect reference to a type, but note that some
621 -- accesses are allowed: references to the current type instance,
622 -- or in Ada 2005 self-referential pointer in a default-initialized
625 if Is_Entity_Name (P) then
628 -- The reference may appear in an aggregate that has been expanded
629 -- into a loop. Locate scope of type definition, if any.
631 Scop := Current_Scope;
632 while Ekind (Scop) = E_Loop loop
633 Scop := Scope (Scop);
636 if Is_Type (Typ) then
638 -- OK if we are within the scope of a limited type
639 -- let's mark the component as having per object constraint
641 if Is_Anonymous_Tagged_Base (Scop, Typ) then
649 Q : Node_Id := Parent (N);
653 and then Nkind (Q) /= N_Component_Declaration
659 Set_Has_Per_Object_Constraint (
660 Defining_Identifier (Q), True);
664 if Nkind (P) = N_Expanded_Name then
666 ("current instance prefix must be a direct name", P);
669 -- If a current instance attribute appears in a component
670 -- constraint it must appear alone; other contexts (spec-
671 -- expressions, within a task body) are not subject to this
674 if not In_Spec_Expression
675 and then not Has_Completion (Scop)
677 Nkind_In (Parent (N), N_Discriminant_Association,
678 N_Index_Or_Discriminant_Constraint)
681 ("current instance attribute must appear alone", N);
684 -- OK if we are in initialization procedure for the type
685 -- in question, in which case the reference to the type
686 -- is rewritten as a reference to the current object.
688 elsif Ekind (Scop) = E_Procedure
689 and then Is_Init_Proc (Scop)
690 and then Etype (First_Formal (Scop)) = Typ
693 Make_Attribute_Reference (Loc,
694 Prefix => Make_Identifier (Loc, Name_uInit),
695 Attribute_Name => Name_Unrestricted_Access));
699 -- OK if a task type, this test needs sharpening up ???
701 elsif Is_Task_Type (Typ) then
704 -- OK if self-reference in an aggregate in Ada 2005, and
705 -- the reference comes from a copied default expression.
707 -- Note that we check legality of self-reference even if the
708 -- expression comes from source, e.g. when a single component
709 -- association in an aggregate has a box association.
711 elsif Ada_Version >= Ada_05
712 and then OK_Self_Reference
716 -- OK if reference to the current instance of a protected
719 elsif Is_Protected_Self_Reference (P) then
722 -- Otherwise we have an error case
725 Error_Attr ("% attribute cannot be applied to type", P);
731 -- If we fall through, we have a normal access to object case.
732 -- Unrestricted_Access is legal wherever an allocator would be
733 -- legal, so its Etype is set to E_Allocator. The expected type
734 -- of the other attributes is a general access type, and therefore
735 -- we label them with E_Access_Attribute_Type.
737 if not Is_Overloaded (P) then
738 Acc_Type := Build_Access_Object_Type (P_Type);
739 Set_Etype (N, Acc_Type);
742 Index : Interp_Index;
745 Set_Etype (N, Any_Type);
746 Get_First_Interp (P, Index, It);
747 while Present (It.Typ) loop
748 Acc_Type := Build_Access_Object_Type (It.Typ);
749 Add_One_Interp (N, Acc_Type, Acc_Type);
750 Get_Next_Interp (Index, It);
755 -- Special cases when we can find a prefix that is an entity name
764 if Is_Entity_Name (PP) then
767 -- If we have an access to an object, and the attribute
768 -- comes from source, then set the object as potentially
769 -- source modified. We do this because the resulting access
770 -- pointer can be used to modify the variable, and we might
771 -- not detect this, leading to some junk warnings.
773 Set_Never_Set_In_Source (Ent, False);
775 -- Mark entity as address taken, and kill current values
777 Set_Address_Taken (Ent);
778 Kill_Current_Values (Ent);
781 elsif Nkind_In (PP, N_Selected_Component,
792 -- Check for aliased view unless unrestricted case. We allow a
793 -- nonaliased prefix when within an instance because the prefix may
794 -- have been a tagged formal object, which is defined to be aliased
795 -- even when the actual might not be (other instance cases will have
796 -- been caught in the generic). Similarly, within an inlined body we
797 -- know that the attribute is legal in the original subprogram, and
798 -- therefore legal in the expansion.
800 if Aname /= Name_Unrestricted_Access
801 and then not Is_Aliased_View (P)
802 and then not In_Instance
803 and then not In_Inlined_Body
805 Error_Attr_P ("prefix of % attribute must be aliased");
807 end Analyze_Access_Attribute;
809 --------------------------------
810 -- Check_Array_Or_Scalar_Type --
811 --------------------------------
813 procedure Check_Array_Or_Scalar_Type is
817 -- Dimension number for array attributes
820 -- Case of string literal or string literal subtype. These cases
821 -- cannot arise from legal Ada code, but the expander is allowed
822 -- to generate them. They require special handling because string
823 -- literal subtypes do not have standard bounds (the whole idea
824 -- of these subtypes is to avoid having to generate the bounds)
826 if Ekind (P_Type) = E_String_Literal_Subtype then
827 Set_Etype (N, Etype (First_Index (P_Base_Type)));
832 elsif Is_Scalar_Type (P_Type) then
836 Error_Attr ("invalid argument in % attribute", E1);
838 Set_Etype (N, P_Base_Type);
842 -- The following is a special test to allow 'First to apply to
843 -- private scalar types if the attribute comes from generated
844 -- code. This occurs in the case of Normalize_Scalars code.
846 elsif Is_Private_Type
(P_Type
)
847 and then Present
(Full_View
(P_Type
))
848 and then Is_Scalar_Type
(Full_View
(P_Type
))
849 and then not Comes_From_Source
(N
)
851 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
853 -- Array types other than string literal subtypes handled above
858 -- We know prefix is an array type, or the name of an array
859 -- object, and that the expression, if present, is static
860 -- and within the range of the dimensions of the type.
862 pragma Assert
(Is_Array_Type
(P_Type
));
863 Index
:= First_Index
(P_Base_Type
);
867 -- First dimension assumed
869 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
872 D
:= UI_To_Int
(Intval
(E1
));
874 for J
in 1 .. D
- 1 loop
878 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
879 Set_Etype
(E1
, Standard_Integer
);
882 end Check_Array_Or_Scalar_Type
;
884 ----------------------
885 -- Check_Array_Type --
886 ----------------------
888 procedure Check_Array_Type
is
890 -- Dimension number for array attributes
893 -- If the type is a string literal type, then this must be generated
894 -- internally, and no further check is required on its legality.
896 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
899 -- If the type is a composite, it is an illegal aggregate, no point
902 elsif P_Type
= Any_Composite
then
906 -- Normal case of array type or subtype
908 Check_Either_E0_Or_E1
;
911 if Is_Array_Type
(P_Type
) then
912 if not Is_Constrained
(P_Type
)
913 and then Is_Entity_Name
(P
)
914 and then Is_Type
(Entity
(P
))
916 -- Note: we do not call Error_Attr here, since we prefer to
917 -- continue, using the relevant index type of the array,
918 -- even though it is unconstrained. This gives better error
919 -- recovery behavior.
921 Error_Msg_Name_1
:= Aname
;
923 ("prefix for % attribute must be constrained array", P
);
926 D
:= Number_Dimensions
(P_Type
);
929 if Is_Private_Type
(P_Type
) then
930 Error_Attr_P
("prefix for % attribute may not be private type");
932 elsif Is_Access_Type
(P_Type
)
933 and then Is_Array_Type
(Designated_Type
(P_Type
))
934 and then Is_Entity_Name
(P
)
935 and then Is_Type
(Entity
(P
))
937 Error_Attr_P
("prefix of % attribute cannot be access type");
939 elsif Attr_Id
= Attribute_First
941 Attr_Id
= Attribute_Last
943 Error_Attr
("invalid prefix for % attribute", P
);
946 Error_Attr_P
("prefix for % attribute must be array");
951 Resolve
(E1
, Any_Integer
);
952 Set_Etype
(E1
, Standard_Integer
);
954 if not Is_Static_Expression
(E1
)
955 or else Raises_Constraint_Error
(E1
)
958 ("expression for dimension must be static!", E1
);
961 elsif UI_To_Int
(Expr_Value
(E1
)) > D
962 or else UI_To_Int
(Expr_Value
(E1
)) < 1
964 Error_Attr
("invalid dimension number for array type", E1
);
968 if (Style_Check
and Style_Check_Array_Attribute_Index
)
969 and then Comes_From_Source
(N
)
971 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
973 end Check_Array_Type
;
975 -------------------------
976 -- Check_Asm_Attribute --
977 -------------------------
979 procedure Check_Asm_Attribute
is
984 -- Check first argument is static string expression
986 Analyze_And_Resolve
(E1
, Standard_String
);
988 if Etype
(E1
) = Any_Type
then
991 elsif not Is_OK_Static_Expression
(E1
) then
993 ("constraint argument must be static string expression!", E1
);
997 -- Check second argument is right type
999 Analyze_And_Resolve
(E2
, Entity
(P
));
1001 -- Note: that is all we need to do, we don't need to check
1002 -- that it appears in a correct context. The Ada type system
1003 -- will do that for us.
1005 end Check_Asm_Attribute
;
1007 ---------------------
1008 -- Check_Component --
1009 ---------------------
1011 procedure Check_Component
is
1015 if Nkind
(P
) /= N_Selected_Component
1017 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1019 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1021 Error_Attr_P
("prefix for % attribute must be selected component");
1023 end Check_Component
;
1025 ------------------------------------
1026 -- Check_Decimal_Fixed_Point_Type --
1027 ------------------------------------
1029 procedure Check_Decimal_Fixed_Point_Type
is
1033 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1034 Error_Attr_P
("prefix of % attribute must be decimal type");
1036 end Check_Decimal_Fixed_Point_Type
;
1038 -----------------------
1039 -- Check_Dereference --
1040 -----------------------
1042 procedure Check_Dereference
is
1045 -- Case of a subtype mark
1047 if Is_Entity_Name
(P
)
1048 and then Is_Type
(Entity
(P
))
1053 -- Case of an expression
1057 if Is_Access_Type
(P_Type
) then
1059 -- If there is an implicit dereference, then we must freeze
1060 -- the designated type of the access type, since the type of
1061 -- the referenced array is this type (see AI95-00106).
1063 Freeze_Before
(N
, Designated_Type
(P_Type
));
1066 Make_Explicit_Dereference
(Sloc
(P
),
1067 Prefix
=> Relocate_Node
(P
)));
1069 Analyze_And_Resolve
(P
);
1070 P_Type
:= Etype
(P
);
1072 if P_Type
= Any_Type
then
1073 raise Bad_Attribute
;
1076 P_Base_Type
:= Base_Type
(P_Type
);
1078 end Check_Dereference
;
1080 -------------------------
1081 -- Check_Discrete_Type --
1082 -------------------------
1084 procedure Check_Discrete_Type
is
1088 if not Is_Discrete_Type
(P_Type
) then
1089 Error_Attr_P
("prefix of % attribute must be discrete type");
1091 end Check_Discrete_Type
;
1097 procedure Check_E0
is
1099 if Present
(E1
) then
1100 Unexpected_Argument
(E1
);
1108 procedure Check_E1
is
1110 Check_Either_E0_Or_E1
;
1114 -- Special-case attributes that are functions and that appear as
1115 -- the prefix of another attribute. Error is posted on parent.
1117 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1118 and then (Attribute_Name
(Parent
(N
)) = Name_Address
1120 Attribute_Name
(Parent
(N
)) = Name_Code_Address
1122 Attribute_Name
(Parent
(N
)) = Name_Access
)
1124 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1125 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1126 Set_Etype
(Parent
(N
), Any_Type
);
1127 Set_Entity
(Parent
(N
), Any_Type
);
1128 raise Bad_Attribute
;
1131 Error_Attr
("missing argument for % attribute", N
);
1140 procedure Check_E2
is
1143 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1145 Error_Attr
("missing argument for % attribute (2 required)", N
);
1149 ---------------------------
1150 -- Check_Either_E0_Or_E1 --
1151 ---------------------------
1153 procedure Check_Either_E0_Or_E1
is
1155 if Present
(E2
) then
1156 Unexpected_Argument
(E2
);
1158 end Check_Either_E0_Or_E1
;
1160 ----------------------
1161 -- Check_Enum_Image --
1162 ----------------------
1164 procedure Check_Enum_Image
is
1167 if Is_Enumeration_Type
(P_Base_Type
) then
1168 Lit
:= First_Literal
(P_Base_Type
);
1169 while Present
(Lit
) loop
1170 Set_Referenced
(Lit
);
1174 end Check_Enum_Image
;
1176 ----------------------------
1177 -- Check_Fixed_Point_Type --
1178 ----------------------------
1180 procedure Check_Fixed_Point_Type
is
1184 if not Is_Fixed_Point_Type
(P_Type
) then
1185 Error_Attr_P
("prefix of % attribute must be fixed point type");
1187 end Check_Fixed_Point_Type
;
1189 ------------------------------
1190 -- Check_Fixed_Point_Type_0 --
1191 ------------------------------
1193 procedure Check_Fixed_Point_Type_0
is
1195 Check_Fixed_Point_Type
;
1197 end Check_Fixed_Point_Type_0
;
1199 -------------------------------
1200 -- Check_Floating_Point_Type --
1201 -------------------------------
1203 procedure Check_Floating_Point_Type
is
1207 if not Is_Floating_Point_Type
(P_Type
) then
1208 Error_Attr_P
("prefix of % attribute must be float type");
1210 end Check_Floating_Point_Type
;
1212 ---------------------------------
1213 -- Check_Floating_Point_Type_0 --
1214 ---------------------------------
1216 procedure Check_Floating_Point_Type_0
is
1218 Check_Floating_Point_Type
;
1220 end Check_Floating_Point_Type_0
;
1222 ---------------------------------
1223 -- Check_Floating_Point_Type_1 --
1224 ---------------------------------
1226 procedure Check_Floating_Point_Type_1
is
1228 Check_Floating_Point_Type
;
1230 end Check_Floating_Point_Type_1
;
1232 ---------------------------------
1233 -- Check_Floating_Point_Type_2 --
1234 ---------------------------------
1236 procedure Check_Floating_Point_Type_2
is
1238 Check_Floating_Point_Type
;
1240 end Check_Floating_Point_Type_2
;
1242 ------------------------
1243 -- Check_Integer_Type --
1244 ------------------------
1246 procedure Check_Integer_Type
is
1250 if not Is_Integer_Type
(P_Type
) then
1251 Error_Attr_P
("prefix of % attribute must be integer type");
1253 end Check_Integer_Type
;
1255 ------------------------
1256 -- Check_Library_Unit --
1257 ------------------------
1259 procedure Check_Library_Unit
is
1261 if not Is_Compilation_Unit
(Entity
(P
)) then
1262 Error_Attr_P
("prefix of % attribute must be library unit");
1264 end Check_Library_Unit
;
1266 --------------------------------
1267 -- Check_Modular_Integer_Type --
1268 --------------------------------
1270 procedure Check_Modular_Integer_Type
is
1274 if not Is_Modular_Integer_Type
(P_Type
) then
1276 ("prefix of % attribute must be modular integer type");
1278 end Check_Modular_Integer_Type
;
1280 ------------------------
1281 -- Check_Not_CPP_Type --
1282 ------------------------
1284 procedure Check_Not_CPP_Type
is
1286 if Is_Tagged_Type
(Etype
(P
))
1287 and then Convention
(Etype
(P
)) = Convention_CPP
1288 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1291 ("invalid use of % attribute with 'C'P'P tagged type");
1293 end Check_Not_CPP_Type
;
1295 -------------------------------
1296 -- Check_Not_Incomplete_Type --
1297 -------------------------------
1299 procedure Check_Not_Incomplete_Type
is
1304 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1305 -- dereference we have to check wrong uses of incomplete types
1306 -- (other wrong uses are checked at their freezing point).
1308 -- Example 1: Limited-with
1310 -- limited with Pkg;
1312 -- type Acc is access Pkg.T;
1314 -- S : Integer := X.all'Size; -- ERROR
1317 -- Example 2: Tagged incomplete
1319 -- type T is tagged;
1320 -- type Acc is access all T;
1322 -- S : constant Integer := X.all'Size; -- ERROR
1323 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1325 if Ada_Version
>= Ada_05
1326 and then Nkind
(P
) = N_Explicit_Dereference
1329 while Nkind
(E
) = N_Explicit_Dereference
loop
1333 if From_With_Type
(Etype
(E
)) then
1335 ("prefix of % attribute cannot be an incomplete type");
1338 if Is_Access_Type
(Etype
(E
)) then
1339 Typ
:= Directly_Designated_Type
(Etype
(E
));
1344 if Ekind
(Typ
) = E_Incomplete_Type
1345 and then No
(Full_View
(Typ
))
1348 ("prefix of % attribute cannot be an incomplete type");
1353 if not Is_Entity_Name
(P
)
1354 or else not Is_Type
(Entity
(P
))
1355 or else In_Spec_Expression
1359 Check_Fully_Declared
(P_Type
, P
);
1361 end Check_Not_Incomplete_Type
;
1363 ----------------------------
1364 -- Check_Object_Reference --
1365 ----------------------------
1367 procedure Check_Object_Reference
(P
: Node_Id
) is
1371 -- If we need an object, and we have a prefix that is the name of
1372 -- a function entity, convert it into a function call.
1374 if Is_Entity_Name
(P
)
1375 and then Ekind
(Entity
(P
)) = E_Function
1377 Rtyp
:= Etype
(Entity
(P
));
1380 Make_Function_Call
(Sloc
(P
),
1381 Name
=> Relocate_Node
(P
)));
1383 Analyze_And_Resolve
(P
, Rtyp
);
1385 -- Otherwise we must have an object reference
1387 elsif not Is_Object_Reference
(P
) then
1388 Error_Attr_P
("prefix of % attribute must be object");
1390 end Check_Object_Reference
;
1392 ----------------------------
1393 -- Check_PolyORB_Attribute --
1394 ----------------------------
1396 procedure Check_PolyORB_Attribute
is
1398 Validate_Non_Static_Attribute_Function_Call
;
1403 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1405 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1407 end Check_PolyORB_Attribute
;
1409 ------------------------
1410 -- Check_Program_Unit --
1411 ------------------------
1413 procedure Check_Program_Unit
is
1415 if Is_Entity_Name
(P
) then
1417 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1418 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1421 if K
in Subprogram_Kind
1422 or else K
in Task_Kind
1423 or else K
in Protected_Kind
1424 or else K
= E_Package
1425 or else K
in Generic_Unit_Kind
1426 or else (K
= E_Variable
1430 Is_Protected_Type
(T
)))
1437 Error_Attr_P
("prefix of % attribute must be program unit");
1438 end Check_Program_Unit
;
1440 ---------------------
1441 -- Check_Real_Type --
1442 ---------------------
1444 procedure Check_Real_Type
is
1448 if not Is_Real_Type
(P_Type
) then
1449 Error_Attr_P
("prefix of % attribute must be real type");
1451 end Check_Real_Type
;
1453 -----------------------
1454 -- Check_Scalar_Type --
1455 -----------------------
1457 procedure Check_Scalar_Type
is
1461 if not Is_Scalar_Type
(P_Type
) then
1462 Error_Attr_P
("prefix of % attribute must be scalar type");
1464 end Check_Scalar_Type
;
1466 ---------------------------
1467 -- Check_Standard_Prefix --
1468 ---------------------------
1470 procedure Check_Standard_Prefix
is
1474 if Nkind
(P
) /= N_Identifier
1475 or else Chars
(P
) /= Name_Standard
1477 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1479 end Check_Standard_Prefix
;
1481 ----------------------------
1482 -- Check_Stream_Attribute --
1483 ----------------------------
1485 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1489 In_Shared_Var_Procs
: Boolean;
1490 -- True when compiling the body of System.Shared_Storage.
1491 -- Shared_Var_Procs. For this runtime package (always compiled in
1492 -- GNAT mode), we allow stream attributes references for limited
1493 -- types for the case where shared passive objects are implemented
1494 -- using stream attributes, which is the default in GNAT's persistent
1495 -- storage implementation.
1498 Validate_Non_Static_Attribute_Function_Call
;
1500 -- With the exception of 'Input, Stream attributes are procedures,
1501 -- and can only appear at the position of procedure calls. We check
1502 -- for this here, before they are rewritten, to give a more precise
1505 if Nam
= TSS_Stream_Input
then
1508 elsif Is_List_Member
(N
)
1509 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1516 ("invalid context for attribute%, which is a procedure", N
);
1520 Btyp
:= Implementation_Base_Type
(P_Type
);
1522 -- Stream attributes not allowed on limited types unless the
1523 -- attribute reference was generated by the expander (in which
1524 -- case the underlying type will be used, as described in Sinfo),
1525 -- or the attribute was specified explicitly for the type itself
1526 -- or one of its ancestors (taking visibility rules into account if
1527 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1528 -- (with no visibility restriction).
1531 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1533 if Present
(Gen_Body
) then
1534 In_Shared_Var_Procs
:=
1535 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1537 In_Shared_Var_Procs
:= False;
1541 if (Comes_From_Source
(N
)
1542 and then not (In_Shared_Var_Procs
or In_Instance
))
1543 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1544 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1546 Error_Msg_Name_1
:= Aname
;
1548 if Is_Limited_Type
(P_Type
) then
1550 ("limited type& has no% attribute", P
, P_Type
);
1551 Explain_Limited_Type
(P_Type
, P
);
1554 ("attribute% for type& is not available", P
, P_Type
);
1558 -- Check for violation of restriction No_Stream_Attributes
1560 if Is_RTE
(P_Type
, RE_Exception_Id
)
1562 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1564 Check_Restriction
(No_Exception_Registration
, P
);
1567 -- Here we must check that the first argument is an access type
1568 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1570 Analyze_And_Resolve
(E1
);
1573 -- Note: the double call to Root_Type here is needed because the
1574 -- root type of a class-wide type is the corresponding type (e.g.
1575 -- X for X'Class, and we really want to go to the root.)
1577 if not Is_Access_Type
(Etyp
)
1578 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1579 RTE
(RE_Root_Stream_Type
)
1582 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1585 -- Check that the second argument is of the right type if there is
1586 -- one (the Input attribute has only one argument so this is skipped)
1588 if Present
(E2
) then
1591 if Nam
= TSS_Stream_Read
1592 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1595 ("second argument of % attribute must be a variable", E2
);
1598 Resolve
(E2
, P_Type
);
1602 end Check_Stream_Attribute
;
1604 -----------------------
1605 -- Check_Task_Prefix --
1606 -----------------------
1608 procedure Check_Task_Prefix
is
1612 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1613 -- task interface class-wide types.
1615 if Is_Task_Type
(Etype
(P
))
1616 or else (Is_Access_Type
(Etype
(P
))
1617 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1618 or else (Ada_Version
>= Ada_05
1619 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1620 and then Is_Interface
(Etype
(P
))
1621 and then Is_Task_Interface
(Etype
(P
)))
1626 if Ada_Version
>= Ada_05
then
1628 ("prefix of % attribute must be a task or a task " &
1629 "interface class-wide object");
1632 Error_Attr_P
("prefix of % attribute must be a task");
1635 end Check_Task_Prefix
;
1641 -- The possibilities are an entity name denoting a type, or an
1642 -- attribute reference that denotes a type (Base or Class). If
1643 -- the type is incomplete, replace it with its full view.
1645 procedure Check_Type
is
1647 if not Is_Entity_Name
(P
)
1648 or else not Is_Type
(Entity
(P
))
1650 Error_Attr_P
("prefix of % attribute must be a type");
1652 elsif Is_Protected_Self_Reference
(P
) then
1654 ("prefix of % attribute denotes current instance " &
1657 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1658 and then Present
(Full_View
(Entity
(P
)))
1660 P_Type
:= Full_View
(Entity
(P
));
1661 Set_Entity
(P
, P_Type
);
1665 ---------------------
1666 -- Check_Unit_Name --
1667 ---------------------
1669 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1671 if Nkind
(Nod
) = N_Identifier
then
1674 elsif Nkind
(Nod
) = N_Selected_Component
then
1675 Check_Unit_Name
(Prefix
(Nod
));
1677 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1682 Error_Attr
("argument for % attribute must be unit name", P
);
1683 end Check_Unit_Name
;
1689 procedure Error_Attr
is
1691 Set_Etype
(N
, Any_Type
);
1692 Set_Entity
(N
, Any_Type
);
1693 raise Bad_Attribute
;
1696 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1698 Error_Msg_Name_1
:= Aname
;
1699 Error_Msg_N
(Msg
, Error_Node
);
1707 procedure Error_Attr_P
(Msg
: String) is
1709 Error_Msg_Name_1
:= Aname
;
1710 Error_Msg_F
(Msg
, P
);
1714 ----------------------------
1715 -- Legal_Formal_Attribute --
1716 ----------------------------
1718 procedure Legal_Formal_Attribute
is
1722 if not Is_Entity_Name
(P
)
1723 or else not Is_Type
(Entity
(P
))
1725 Error_Attr_P
("prefix of % attribute must be generic type");
1727 elsif Is_Generic_Actual_Type
(Entity
(P
))
1729 or else In_Inlined_Body
1733 elsif Is_Generic_Type
(Entity
(P
)) then
1734 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1736 ("prefix of % attribute must be indefinite generic type");
1741 ("prefix of % attribute must be indefinite generic type");
1744 Set_Etype
(N
, Standard_Boolean
);
1745 end Legal_Formal_Attribute
;
1747 ------------------------
1748 -- Standard_Attribute --
1749 ------------------------
1751 procedure Standard_Attribute
(Val
: Int
) is
1753 Check_Standard_Prefix
;
1754 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1756 end Standard_Attribute
;
1758 -------------------------
1759 -- Unexpected Argument --
1760 -------------------------
1762 procedure Unexpected_Argument
(En
: Node_Id
) is
1764 Error_Attr
("unexpected argument for % attribute", En
);
1765 end Unexpected_Argument
;
1767 -------------------------------------------------
1768 -- Validate_Non_Static_Attribute_Function_Call --
1769 -------------------------------------------------
1771 -- This function should be moved to Sem_Dist ???
1773 procedure Validate_Non_Static_Attribute_Function_Call
is
1775 if In_Preelaborated_Unit
1776 and then not In_Subprogram_Or_Concurrent_Unit
1778 Flag_Non_Static_Expr
1779 ("non-static function call in preelaborated unit!", N
);
1781 end Validate_Non_Static_Attribute_Function_Call
;
1783 -----------------------------------------------
1784 -- Start of Processing for Analyze_Attribute --
1785 -----------------------------------------------
1788 -- Immediate return if unrecognized attribute (already diagnosed
1789 -- by parser, so there is nothing more that we need to do)
1791 if not Is_Attribute_Name
(Aname
) then
1792 raise Bad_Attribute
;
1795 -- Deal with Ada 83 issues
1797 if Comes_From_Source
(N
) then
1798 if not Attribute_83
(Attr_Id
) then
1799 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1800 Error_Msg_Name_1
:= Aname
;
1801 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1804 if Attribute_Impl_Def
(Attr_Id
) then
1805 Check_Restriction
(No_Implementation_Attributes
, N
);
1810 -- Deal with Ada 2005 issues
1812 if Attribute_05
(Attr_Id
) and then Ada_Version
<= Ada_95
then
1813 Check_Restriction
(No_Implementation_Attributes
, N
);
1816 -- Remote access to subprogram type access attribute reference needs
1817 -- unanalyzed copy for tree transformation. The analyzed copy is used
1818 -- for its semantic information (whether prefix is a remote subprogram
1819 -- name), the unanalyzed copy is used to construct new subtree rooted
1820 -- with N_Aggregate which represents a fat pointer aggregate.
1822 if Aname
= Name_Access
then
1823 Discard_Node
(Copy_Separate_Tree
(N
));
1826 -- Analyze prefix and exit if error in analysis. If the prefix is an
1827 -- incomplete type, use full view if available. Note that there are
1828 -- some attributes for which we do not analyze the prefix, since the
1829 -- prefix is not a normal name.
1831 if Aname
/= Name_Elab_Body
1833 Aname
/= Name_Elab_Spec
1835 Aname
/= Name_UET_Address
1837 Aname
/= Name_Enabled
1840 P_Type
:= Etype
(P
);
1842 if Is_Entity_Name
(P
)
1843 and then Present
(Entity
(P
))
1844 and then Is_Type
(Entity
(P
))
1846 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
1847 P_Type
:= Get_Full_View
(P_Type
);
1848 Set_Entity
(P
, P_Type
);
1849 Set_Etype
(P
, P_Type
);
1851 elsif Entity
(P
) = Current_Scope
1852 and then Is_Record_Type
(Entity
(P
))
1854 -- Use of current instance within the type. Verify that if the
1855 -- attribute appears within a constraint, it yields an access
1856 -- type, other uses are illegal.
1864 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
1866 Par
:= Parent
(Par
);
1870 and then Nkind
(Par
) = N_Subtype_Indication
1872 if Attr_Id
/= Attribute_Access
1873 and then Attr_Id
/= Attribute_Unchecked_Access
1874 and then Attr_Id
/= Attribute_Unrestricted_Access
1877 ("in a constraint the current instance can only"
1878 & " be used with an access attribute", N
);
1885 if P_Type
= Any_Type
then
1886 raise Bad_Attribute
;
1889 P_Base_Type
:= Base_Type
(P_Type
);
1892 -- Analyze expressions that may be present, exiting if an error occurs
1899 E1
:= First
(Exprs
);
1902 -- Check for missing/bad expression (result of previous error)
1904 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1905 raise Bad_Attribute
;
1910 if Present
(E2
) then
1913 if Etype
(E2
) = Any_Type
then
1914 raise Bad_Attribute
;
1917 if Present
(Next
(E2
)) then
1918 Unexpected_Argument
(Next
(E2
));
1923 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1924 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
1926 if Ada_Version
< Ada_05
1927 and then Is_Overloaded
(P
)
1928 and then Aname
/= Name_Access
1929 and then Aname
/= Name_Address
1930 and then Aname
/= Name_Code_Address
1931 and then Aname
/= Name_Count
1932 and then Aname
/= Name_Result
1933 and then Aname
/= Name_Unchecked_Access
1935 Error_Attr
("ambiguous prefix for % attribute", P
);
1937 elsif Ada_Version
>= Ada_05
1938 and then Is_Overloaded
(P
)
1939 and then Aname
/= Name_Access
1940 and then Aname
/= Name_Address
1941 and then Aname
/= Name_Code_Address
1942 and then Aname
/= Name_Result
1943 and then Aname
/= Name_Unchecked_Access
1945 -- Ada 2005 (AI-345): Since protected and task types have primitive
1946 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1949 if Aname
= Name_Count
1950 or else Aname
= Name_Caller
1951 or else Aname
= Name_AST_Entry
1954 Count
: Natural := 0;
1959 Get_First_Interp
(P
, I
, It
);
1960 while Present
(It
.Nam
) loop
1961 if Comes_From_Source
(It
.Nam
) then
1967 Get_Next_Interp
(I
, It
);
1971 Error_Attr
("ambiguous prefix for % attribute", P
);
1973 Set_Is_Overloaded
(P
, False);
1978 Error_Attr
("ambiguous prefix for % attribute", P
);
1982 -- Remaining processing depends on attribute
1990 when Attribute_Abort_Signal
=>
1991 Check_Standard_Prefix
;
1993 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
2000 when Attribute_Access
=>
2001 Analyze_Access_Attribute
;
2007 when Attribute_Address
=>
2010 -- Check for some junk cases, where we have to allow the address
2011 -- attribute but it does not make much sense, so at least for now
2012 -- just replace with Null_Address.
2014 -- We also do this if the prefix is a reference to the AST_Entry
2015 -- attribute. If expansion is active, the attribute will be
2016 -- replaced by a function call, and address will work fine and
2017 -- get the proper value, but if expansion is not active, then
2018 -- the check here allows proper semantic analysis of the reference.
2020 -- An Address attribute created by expansion is legal even when it
2021 -- applies to other entity-denoting expressions.
2023 if Is_Protected_Self_Reference
(P
) then
2024 -- An Address attribute on a protected object self reference
2029 elsif Is_Entity_Name
(P
) then
2031 Ent
: constant Entity_Id
:= Entity
(P
);
2034 if Is_Subprogram
(Ent
) then
2035 Set_Address_Taken
(Ent
);
2036 Kill_Current_Values
(Ent
);
2038 -- An Address attribute is accepted when generated by the
2039 -- compiler for dispatching operation, and an error is
2040 -- issued once the subprogram is frozen (to avoid confusing
2041 -- errors about implicit uses of Address in the dispatch
2042 -- table initialization).
2044 if Has_Pragma_Inline_Always
(Entity
(P
))
2045 and then Comes_From_Source
(P
)
2048 ("prefix of % attribute cannot be Inline_Always" &
2052 elsif Is_Object
(Ent
)
2053 or else Ekind
(Ent
) = E_Label
2055 Set_Address_Taken
(Ent
);
2057 -- If we have an address of an object, and the attribute
2058 -- comes from source, then set the object as potentially
2059 -- source modified. We do this because the resulting address
2060 -- can potentially be used to modify the variable and we
2061 -- might not detect this, leading to some junk warnings.
2063 Set_Never_Set_In_Source
(Ent
, False);
2065 elsif (Is_Concurrent_Type
(Etype
(Ent
))
2066 and then Etype
(Ent
) = Base_Type
(Ent
))
2067 or else Ekind
(Ent
) = E_Package
2068 or else Is_Generic_Unit
(Ent
)
2071 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2074 Error_Attr
("invalid prefix for % attribute", P
);
2078 elsif Nkind
(P
) = N_Attribute_Reference
2079 and then Attribute_Name
(P
) = Name_AST_Entry
2082 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2084 elsif Is_Object_Reference
(P
) then
2087 elsif Nkind
(P
) = N_Selected_Component
2088 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
2092 -- What exactly are we allowing here ??? and is this properly
2093 -- documented in the sinfo documentation for this node ???
2095 elsif not Comes_From_Source
(N
) then
2099 Error_Attr
("invalid prefix for % attribute", P
);
2102 Set_Etype
(N
, RTE
(RE_Address
));
2108 when Attribute_Address_Size
=>
2109 Standard_Attribute
(System_Address_Size
);
2115 when Attribute_Adjacent
=>
2116 Check_Floating_Point_Type_2
;
2117 Set_Etype
(N
, P_Base_Type
);
2118 Resolve
(E1
, P_Base_Type
);
2119 Resolve
(E2
, P_Base_Type
);
2125 when Attribute_Aft
=>
2126 Check_Fixed_Point_Type_0
;
2127 Set_Etype
(N
, Universal_Integer
);
2133 when Attribute_Alignment
=>
2135 -- Don't we need more checking here, cf Size ???
2138 Check_Not_Incomplete_Type
;
2140 Set_Etype
(N
, Universal_Integer
);
2146 when Attribute_Asm_Input
=>
2147 Check_Asm_Attribute
;
2148 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2154 when Attribute_Asm_Output
=>
2155 Check_Asm_Attribute
;
2157 if Etype
(E2
) = Any_Type
then
2160 elsif Aname
= Name_Asm_Output
then
2161 if not Is_Variable
(E2
) then
2163 ("second argument for Asm_Output is not variable", E2
);
2167 Note_Possible_Modification
(E2
, Sure
=> True);
2168 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2174 when Attribute_AST_Entry
=> AST_Entry
: declare
2180 -- Indicates if entry family index is present. Note the coding
2181 -- here handles the entry family case, but in fact it cannot be
2182 -- executed currently, because pragma AST_Entry does not permit
2183 -- the specification of an entry family.
2185 procedure Bad_AST_Entry
;
2186 -- Signal a bad AST_Entry pragma
2188 function OK_Entry
(E
: Entity_Id
) return Boolean;
2189 -- Checks that E is of an appropriate entity kind for an entry
2190 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2191 -- is set True for the entry family case). In the True case,
2192 -- makes sure that Is_AST_Entry is set on the entry.
2198 procedure Bad_AST_Entry
is
2200 Error_Attr_P
("prefix for % attribute must be task entry");
2207 function OK_Entry
(E
: Entity_Id
) return Boolean is
2212 Result
:= (Ekind
(E
) = E_Entry_Family
);
2214 Result
:= (Ekind
(E
) = E_Entry
);
2218 if not Is_AST_Entry
(E
) then
2219 Error_Msg_Name_2
:= Aname
;
2220 Error_Attr
("% attribute requires previous % pragma", P
);
2227 -- Start of processing for AST_Entry
2233 -- Deal with entry family case
2235 if Nkind
(P
) = N_Indexed_Component
then
2243 Ptyp
:= Etype
(Pref
);
2245 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2249 -- If the prefix is a selected component whose prefix is of an
2250 -- access type, then introduce an explicit dereference.
2251 -- ??? Could we reuse Check_Dereference here?
2253 if Nkind
(Pref
) = N_Selected_Component
2254 and then Is_Access_Type
(Ptyp
)
2257 Make_Explicit_Dereference
(Sloc
(Pref
),
2258 Relocate_Node
(Pref
)));
2259 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2262 -- Prefix can be of the form a.b, where a is a task object
2263 -- and b is one of the entries of the corresponding task type.
2265 if Nkind
(Pref
) = N_Selected_Component
2266 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2267 and then Is_Object_Reference
(Prefix
(Pref
))
2268 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2272 -- Otherwise the prefix must be an entry of a containing task,
2273 -- or of a variable of the enclosing task type.
2276 if Nkind_In
(Pref
, N_Identifier
, N_Expanded_Name
) then
2277 Ent
:= Entity
(Pref
);
2279 if not OK_Entry
(Ent
)
2280 or else not In_Open_Scopes
(Scope
(Ent
))
2290 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2297 -- Note: when the base attribute appears in the context of a subtype
2298 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2299 -- the following circuit.
2301 when Attribute_Base
=> Base
: declare
2309 if Ada_Version
>= Ada_95
2310 and then not Is_Scalar_Type
(Typ
)
2311 and then not Is_Generic_Type
(Typ
)
2313 Error_Attr_P
("prefix of Base attribute must be scalar type");
2315 elsif Sloc
(Typ
) = Standard_Location
2316 and then Base_Type
(Typ
) = Typ
2317 and then Warn_On_Redundant_Constructs
2320 ("?redundant attribute, & is its own base type", N
, Typ
);
2323 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2324 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2325 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2333 when Attribute_Bit
=> Bit
:
2337 if not Is_Object_Reference
(P
) then
2338 Error_Attr_P
("prefix for % attribute must be object");
2340 -- What about the access object cases ???
2346 Set_Etype
(N
, Universal_Integer
);
2353 when Attribute_Bit_Order
=> Bit_Order
:
2358 if not Is_Record_Type
(P_Type
) then
2359 Error_Attr_P
("prefix of % attribute must be record type");
2362 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2364 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2367 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2370 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2373 -- Reset incorrect indication of staticness
2375 Set_Is_Static_Expression
(N
, False);
2382 -- Note: in generated code, we can have a Bit_Position attribute
2383 -- applied to a (naked) record component (i.e. the prefix is an
2384 -- identifier that references an E_Component or E_Discriminant
2385 -- entity directly, and this is interpreted as expected by Gigi.
2386 -- The following code will not tolerate such usage, but when the
2387 -- expander creates this special case, it marks it as analyzed
2388 -- immediately and sets an appropriate type.
2390 when Attribute_Bit_Position
=>
2391 if Comes_From_Source
(N
) then
2395 Set_Etype
(N
, Universal_Integer
);
2401 when Attribute_Body_Version
=>
2404 Set_Etype
(N
, RTE
(RE_Version_String
));
2410 when Attribute_Callable
=>
2412 Set_Etype
(N
, Standard_Boolean
);
2419 when Attribute_Caller
=> Caller
: declare
2426 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2429 if not Is_Entry
(Ent
) then
2430 Error_Attr
("invalid entry name", N
);
2434 Error_Attr
("invalid entry name", N
);
2438 for J
in reverse 0 .. Scope_Stack
.Last
loop
2439 S
:= Scope_Stack
.Table
(J
).Entity
;
2441 if S
= Scope
(Ent
) then
2442 Error_Attr
("Caller must appear in matching accept or body", N
);
2448 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2455 when Attribute_Ceiling
=>
2456 Check_Floating_Point_Type_1
;
2457 Set_Etype
(N
, P_Base_Type
);
2458 Resolve
(E1
, P_Base_Type
);
2464 when Attribute_Class
=>
2465 Check_Restriction
(No_Dispatch
, N
);
2473 when Attribute_Code_Address
=>
2476 if Nkind
(P
) = N_Attribute_Reference
2477 and then (Attribute_Name
(P
) = Name_Elab_Body
2479 Attribute_Name
(P
) = Name_Elab_Spec
)
2483 elsif not Is_Entity_Name
(P
)
2484 or else (Ekind
(Entity
(P
)) /= E_Function
2486 Ekind
(Entity
(P
)) /= E_Procedure
)
2488 Error_Attr
("invalid prefix for % attribute", P
);
2489 Set_Address_Taken
(Entity
(P
));
2492 Set_Etype
(N
, RTE
(RE_Address
));
2494 --------------------
2495 -- Component_Size --
2496 --------------------
2498 when Attribute_Component_Size
=>
2500 Set_Etype
(N
, Universal_Integer
);
2502 -- Note: unlike other array attributes, unconstrained arrays are OK
2504 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2514 when Attribute_Compose
=>
2515 Check_Floating_Point_Type_2
;
2516 Set_Etype
(N
, P_Base_Type
);
2517 Resolve
(E1
, P_Base_Type
);
2518 Resolve
(E2
, Any_Integer
);
2524 when Attribute_Constrained
=>
2526 Set_Etype
(N
, Standard_Boolean
);
2528 -- Case from RM J.4(2) of constrained applied to private type
2530 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2531 Check_Restriction
(No_Obsolescent_Features
, N
);
2533 if Warn_On_Obsolescent_Feature
then
2535 ("constrained for private type is an " &
2536 "obsolescent feature (RM J.4)?", N
);
2539 -- If we are within an instance, the attribute must be legal
2540 -- because it was valid in the generic unit. Ditto if this is
2541 -- an inlining of a function declared in an instance.
2544 or else In_Inlined_Body
2548 -- For sure OK if we have a real private type itself, but must
2549 -- be completed, cannot apply Constrained to incomplete type.
2551 elsif Is_Private_Type
(Entity
(P
)) then
2553 -- Note: this is one of the Annex J features that does not
2554 -- generate a warning from -gnatwj, since in fact it seems
2555 -- very useful, and is used in the GNAT runtime.
2557 Check_Not_Incomplete_Type
;
2561 -- Normal (non-obsolescent case) of application to object of
2562 -- a discriminated type.
2565 Check_Object_Reference
(P
);
2567 -- If N does not come from source, then we allow the
2568 -- the attribute prefix to be of a private type whose
2569 -- full type has discriminants. This occurs in cases
2570 -- involving expanded calls to stream attributes.
2572 if not Comes_From_Source
(N
) then
2573 P_Type
:= Underlying_Type
(P_Type
);
2576 -- Must have discriminants or be an access type designating
2577 -- a type with discriminants. If it is a classwide type is ???
2578 -- has unknown discriminants.
2580 if Has_Discriminants
(P_Type
)
2581 or else Has_Unknown_Discriminants
(P_Type
)
2583 (Is_Access_Type
(P_Type
)
2584 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2588 -- Also allow an object of a generic type if extensions allowed
2589 -- and allow this for any type at all.
2591 elsif (Is_Generic_Type
(P_Type
)
2592 or else Is_Generic_Actual_Type
(P_Type
))
2593 and then Extensions_Allowed
2599 -- Fall through if bad prefix
2602 ("prefix of % attribute must be object of discriminated type");
2608 when Attribute_Copy_Sign
=>
2609 Check_Floating_Point_Type_2
;
2610 Set_Etype
(N
, P_Base_Type
);
2611 Resolve
(E1
, P_Base_Type
);
2612 Resolve
(E2
, P_Base_Type
);
2618 when Attribute_Count
=> Count
:
2627 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2630 if Ekind
(Ent
) /= E_Entry
then
2631 Error_Attr
("invalid entry name", N
);
2634 elsif Nkind
(P
) = N_Indexed_Component
then
2635 if not Is_Entity_Name
(Prefix
(P
))
2636 or else No
(Entity
(Prefix
(P
)))
2637 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2639 if Nkind
(Prefix
(P
)) = N_Selected_Component
2640 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2641 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2645 ("attribute % must apply to entry of current task", P
);
2648 Error_Attr
("invalid entry family name", P
);
2653 Ent
:= Entity
(Prefix
(P
));
2656 elsif Nkind
(P
) = N_Selected_Component
2657 and then Present
(Entity
(Selector_Name
(P
)))
2658 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2661 ("attribute % must apply to entry of current task", P
);
2664 Error_Attr
("invalid entry name", N
);
2668 for J
in reverse 0 .. Scope_Stack
.Last
loop
2669 S
:= Scope_Stack
.Table
(J
).Entity
;
2671 if S
= Scope
(Ent
) then
2672 if Nkind
(P
) = N_Expanded_Name
then
2673 Tsk
:= Entity
(Prefix
(P
));
2675 -- The prefix denotes either the task type, or else a
2676 -- single task whose task type is being analyzed.
2681 or else (not Is_Type
(Tsk
)
2682 and then Etype
(Tsk
) = S
2683 and then not (Comes_From_Source
(S
)))
2688 ("Attribute % must apply to entry of current task", N
);
2694 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2695 and then Ekind
(S
) /= E_Loop
2696 and then Ekind
(S
) /= E_Block
2697 and then Ekind
(S
) /= E_Entry
2698 and then Ekind
(S
) /= E_Entry_Family
2700 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2702 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2703 and then not Has_Completion
(Scope
(Ent
))
2705 Error_Attr
("attribute % can only be used inside body", N
);
2709 if Is_Overloaded
(P
) then
2711 Index
: Interp_Index
;
2715 Get_First_Interp
(P
, Index
, It
);
2717 while Present
(It
.Nam
) loop
2718 if It
.Nam
= Ent
then
2721 -- Ada 2005 (AI-345): Do not consider primitive entry
2722 -- wrappers generated for task or protected types.
2724 elsif Ada_Version
>= Ada_05
2725 and then not Comes_From_Source
(It
.Nam
)
2730 Error_Attr
("ambiguous entry name", N
);
2733 Get_Next_Interp
(Index
, It
);
2738 Set_Etype
(N
, Universal_Integer
);
2741 -----------------------
2742 -- Default_Bit_Order --
2743 -----------------------
2745 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2747 Check_Standard_Prefix
;
2749 if Bytes_Big_Endian
then
2751 Make_Integer_Literal
(Loc
, False_Value
));
2754 Make_Integer_Literal
(Loc
, True_Value
));
2757 Set_Etype
(N
, Universal_Integer
);
2758 Set_Is_Static_Expression
(N
);
2759 end Default_Bit_Order
;
2765 when Attribute_Definite
=>
2766 Legal_Formal_Attribute
;
2772 when Attribute_Delta
=>
2773 Check_Fixed_Point_Type_0
;
2774 Set_Etype
(N
, Universal_Real
);
2780 when Attribute_Denorm
=>
2781 Check_Floating_Point_Type_0
;
2782 Set_Etype
(N
, Standard_Boolean
);
2788 when Attribute_Digits
=>
2792 if not Is_Floating_Point_Type
(P_Type
)
2793 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2796 ("prefix of % attribute must be float or decimal type");
2799 Set_Etype
(N
, Universal_Integer
);
2805 -- Also handles processing for Elab_Spec
2807 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2809 Check_Unit_Name
(P
);
2810 Set_Etype
(N
, Standard_Void_Type
);
2812 -- We have to manually call the expander in this case to get
2813 -- the necessary expansion (normally attributes that return
2814 -- entities are not expanded).
2822 -- Shares processing with Elab_Body
2828 when Attribute_Elaborated
=>
2831 Set_Etype
(N
, Standard_Boolean
);
2837 when Attribute_Emax
=>
2838 Check_Floating_Point_Type_0
;
2839 Set_Etype
(N
, Universal_Integer
);
2845 when Attribute_Enabled
=>
2846 Check_Either_E0_Or_E1
;
2848 if Present
(E1
) then
2849 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
2850 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
2855 if Nkind
(P
) /= N_Identifier
then
2856 Error_Msg_N
("identifier expected (check name)", P
);
2857 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
2858 Error_Msg_N
("& is not a recognized check name", P
);
2861 Set_Etype
(N
, Standard_Boolean
);
2867 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2869 if Present
(E1
) then
2871 Check_Discrete_Type
;
2872 Resolve
(E1
, P_Base_Type
);
2875 if not Is_Entity_Name
(P
)
2876 or else (not Is_Object
(Entity
(P
))
2878 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2881 ("prefix of %attribute must be " &
2882 "discrete type/object or enum literal");
2886 Set_Etype
(N
, Universal_Integer
);
2893 when Attribute_Enum_Val
=> Enum_Val
: begin
2897 if not Is_Enumeration_Type
(P_Type
) then
2898 Error_Attr_P
("prefix of % attribute must be enumeration type");
2901 -- If the enumeration type has a standard representation, the effect
2902 -- is the same as 'Val, so rewrite the attribute as a 'Val.
2904 if not Has_Non_Standard_Rep
(P_Base_Type
) then
2906 Make_Attribute_Reference
(Loc
,
2907 Prefix
=> Relocate_Node
(Prefix
(N
)),
2908 Attribute_Name
=> Name_Val
,
2909 Expressions
=> New_List
(Relocate_Node
(E1
))));
2910 Analyze_And_Resolve
(N
, P_Base_Type
);
2912 -- Non-standard representation case (enumeration with holes)
2916 Resolve
(E1
, Any_Integer
);
2917 Set_Etype
(N
, P_Base_Type
);
2925 when Attribute_Epsilon
=>
2926 Check_Floating_Point_Type_0
;
2927 Set_Etype
(N
, Universal_Real
);
2933 when Attribute_Exponent
=>
2934 Check_Floating_Point_Type_1
;
2935 Set_Etype
(N
, Universal_Integer
);
2936 Resolve
(E1
, P_Base_Type
);
2942 when Attribute_External_Tag
=>
2946 Set_Etype
(N
, Standard_String
);
2948 if not Is_Tagged_Type
(P_Type
) then
2949 Error_Attr_P
("prefix of % attribute must be tagged");
2956 when Attribute_Fast_Math
=>
2957 Check_Standard_Prefix
;
2959 if Opt
.Fast_Math
then
2960 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
2962 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
2969 when Attribute_First
=>
2970 Check_Array_Or_Scalar_Type
;
2976 when Attribute_First_Bit
=>
2978 Set_Etype
(N
, Universal_Integer
);
2984 when Attribute_Fixed_Value
=>
2986 Check_Fixed_Point_Type
;
2987 Resolve
(E1
, Any_Integer
);
2988 Set_Etype
(N
, P_Base_Type
);
2994 when Attribute_Floor
=>
2995 Check_Floating_Point_Type_1
;
2996 Set_Etype
(N
, P_Base_Type
);
2997 Resolve
(E1
, P_Base_Type
);
3003 when Attribute_Fore
=>
3004 Check_Fixed_Point_Type_0
;
3005 Set_Etype
(N
, Universal_Integer
);
3011 when Attribute_Fraction
=>
3012 Check_Floating_Point_Type_1
;
3013 Set_Etype
(N
, P_Base_Type
);
3014 Resolve
(E1
, P_Base_Type
);
3020 when Attribute_From_Any
=>
3022 Check_PolyORB_Attribute
;
3023 Set_Etype
(N
, P_Base_Type
);
3025 -----------------------
3026 -- Has_Access_Values --
3027 -----------------------
3029 when Attribute_Has_Access_Values
=>
3032 Set_Etype
(N
, Standard_Boolean
);
3034 -----------------------
3035 -- Has_Tagged_Values --
3036 -----------------------
3038 when Attribute_Has_Tagged_Values
=>
3041 Set_Etype
(N
, Standard_Boolean
);
3043 -----------------------
3044 -- Has_Discriminants --
3045 -----------------------
3047 when Attribute_Has_Discriminants
=>
3048 Legal_Formal_Attribute
;
3054 when Attribute_Identity
=>
3058 if Etype
(P
) = Standard_Exception_Type
then
3059 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3061 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3062 -- task interface class-wide types.
3064 elsif Is_Task_Type
(Etype
(P
))
3065 or else (Is_Access_Type
(Etype
(P
))
3066 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3067 or else (Ada_Version
>= Ada_05
3068 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3069 and then Is_Interface
(Etype
(P
))
3070 and then Is_Task_Interface
(Etype
(P
)))
3073 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3076 if Ada_Version
>= Ada_05
then
3078 ("prefix of % attribute must be an exception, a " &
3079 "task or a task interface class-wide object");
3082 ("prefix of % attribute must be a task or an exception");
3090 when Attribute_Image
=> Image
:
3092 Set_Etype
(N
, Standard_String
);
3095 if Is_Real_Type
(P_Type
) then
3096 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3097 Error_Msg_Name_1
:= Aname
;
3099 ("(Ada 83) % attribute not allowed for real types", N
);
3103 if Is_Enumeration_Type
(P_Type
) then
3104 Check_Restriction
(No_Enumeration_Maps
, N
);
3108 Resolve
(E1
, P_Base_Type
);
3110 Validate_Non_Static_Attribute_Function_Call
;
3117 when Attribute_Img
=> Img
:
3120 Set_Etype
(N
, Standard_String
);
3122 if not Is_Scalar_Type
(P_Type
)
3123 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3126 ("prefix of % attribute must be scalar object name");
3136 when Attribute_Input
=>
3138 Check_Stream_Attribute
(TSS_Stream_Input
);
3139 Set_Etype
(N
, P_Base_Type
);
3145 when Attribute_Integer_Value
=>
3148 Resolve
(E1
, Any_Fixed
);
3150 -- Signal an error if argument type is not a specific fixed-point
3151 -- subtype. An error has been signalled already if the argument
3152 -- was not of a fixed-point type.
3154 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3155 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3158 Set_Etype
(N
, P_Base_Type
);
3164 when Attribute_Invalid_Value
=>
3167 Set_Etype
(N
, P_Base_Type
);
3168 Invalid_Value_Used
:= True;
3174 when Attribute_Large
=>
3177 Set_Etype
(N
, Universal_Real
);
3183 when Attribute_Last
=>
3184 Check_Array_Or_Scalar_Type
;
3190 when Attribute_Last_Bit
=>
3192 Set_Etype
(N
, Universal_Integer
);
3198 when Attribute_Leading_Part
=>
3199 Check_Floating_Point_Type_2
;
3200 Set_Etype
(N
, P_Base_Type
);
3201 Resolve
(E1
, P_Base_Type
);
3202 Resolve
(E2
, Any_Integer
);
3208 when Attribute_Length
=>
3210 Set_Etype
(N
, Universal_Integer
);
3216 when Attribute_Machine
=>
3217 Check_Floating_Point_Type_1
;
3218 Set_Etype
(N
, P_Base_Type
);
3219 Resolve
(E1
, P_Base_Type
);
3225 when Attribute_Machine_Emax
=>
3226 Check_Floating_Point_Type_0
;
3227 Set_Etype
(N
, Universal_Integer
);
3233 when Attribute_Machine_Emin
=>
3234 Check_Floating_Point_Type_0
;
3235 Set_Etype
(N
, Universal_Integer
);
3237 ----------------------
3238 -- Machine_Mantissa --
3239 ----------------------
3241 when Attribute_Machine_Mantissa
=>
3242 Check_Floating_Point_Type_0
;
3243 Set_Etype
(N
, Universal_Integer
);
3245 -----------------------
3246 -- Machine_Overflows --
3247 -----------------------
3249 when Attribute_Machine_Overflows
=>
3252 Set_Etype
(N
, Standard_Boolean
);
3258 when Attribute_Machine_Radix
=>
3261 Set_Etype
(N
, Universal_Integer
);
3263 ----------------------
3264 -- Machine_Rounding --
3265 ----------------------
3267 when Attribute_Machine_Rounding
=>
3268 Check_Floating_Point_Type_1
;
3269 Set_Etype
(N
, P_Base_Type
);
3270 Resolve
(E1
, P_Base_Type
);
3272 --------------------
3273 -- Machine_Rounds --
3274 --------------------
3276 when Attribute_Machine_Rounds
=>
3279 Set_Etype
(N
, Standard_Boolean
);
3285 when Attribute_Machine_Size
=>
3288 Check_Not_Incomplete_Type
;
3289 Set_Etype
(N
, Universal_Integer
);
3295 when Attribute_Mantissa
=>
3298 Set_Etype
(N
, Universal_Integer
);
3304 when Attribute_Max
=>
3307 Resolve
(E1
, P_Base_Type
);
3308 Resolve
(E2
, P_Base_Type
);
3309 Set_Etype
(N
, P_Base_Type
);
3311 ----------------------------------
3312 -- Max_Size_In_Storage_Elements --
3313 ----------------------------------
3315 when Attribute_Max_Size_In_Storage_Elements
=>
3318 Check_Not_Incomplete_Type
;
3319 Set_Etype
(N
, Universal_Integer
);
3321 -----------------------
3322 -- Maximum_Alignment --
3323 -----------------------
3325 when Attribute_Maximum_Alignment
=>
3326 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3328 --------------------
3329 -- Mechanism_Code --
3330 --------------------
3332 when Attribute_Mechanism_Code
=>
3333 if not Is_Entity_Name
(P
)
3334 or else not Is_Subprogram
(Entity
(P
))
3336 Error_Attr_P
("prefix of % attribute must be subprogram");
3339 Check_Either_E0_Or_E1
;
3341 if Present
(E1
) then
3342 Resolve
(E1
, Any_Integer
);
3343 Set_Etype
(E1
, Standard_Integer
);
3345 if not Is_Static_Expression
(E1
) then
3346 Flag_Non_Static_Expr
3347 ("expression for parameter number must be static!", E1
);
3350 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3351 or else UI_To_Int
(Intval
(E1
)) < 0
3353 Error_Attr
("invalid parameter number for %attribute", E1
);
3357 Set_Etype
(N
, Universal_Integer
);
3363 when Attribute_Min
=>
3366 Resolve
(E1
, P_Base_Type
);
3367 Resolve
(E2
, P_Base_Type
);
3368 Set_Etype
(N
, P_Base_Type
);
3374 when Attribute_Mod
=>
3376 -- Note: this attribute is only allowed in Ada 2005 mode, but
3377 -- we do not need to test that here, since Mod is only recognized
3378 -- as an attribute name in Ada 2005 mode during the parse.
3381 Check_Modular_Integer_Type
;
3382 Resolve
(E1
, Any_Integer
);
3383 Set_Etype
(N
, P_Base_Type
);
3389 when Attribute_Model
=>
3390 Check_Floating_Point_Type_1
;
3391 Set_Etype
(N
, P_Base_Type
);
3392 Resolve
(E1
, P_Base_Type
);
3398 when Attribute_Model_Emin
=>
3399 Check_Floating_Point_Type_0
;
3400 Set_Etype
(N
, Universal_Integer
);
3406 when Attribute_Model_Epsilon
=>
3407 Check_Floating_Point_Type_0
;
3408 Set_Etype
(N
, Universal_Real
);
3410 --------------------
3411 -- Model_Mantissa --
3412 --------------------
3414 when Attribute_Model_Mantissa
=>
3415 Check_Floating_Point_Type_0
;
3416 Set_Etype
(N
, Universal_Integer
);
3422 when Attribute_Model_Small
=>
3423 Check_Floating_Point_Type_0
;
3424 Set_Etype
(N
, Universal_Real
);
3430 when Attribute_Modulus
=>
3432 Check_Modular_Integer_Type
;
3433 Set_Etype
(N
, Universal_Integer
);
3435 --------------------
3436 -- Null_Parameter --
3437 --------------------
3439 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3440 Parnt
: constant Node_Id
:= Parent
(N
);
3441 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3443 procedure Bad_Null_Parameter
(Msg
: String);
3444 -- Used if bad Null parameter attribute node is found. Issues
3445 -- given error message, and also sets the type to Any_Type to
3446 -- avoid blowups later on from dealing with a junk node.
3448 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3449 -- Called to check that Proc_Ent is imported subprogram
3451 ------------------------
3452 -- Bad_Null_Parameter --
3453 ------------------------
3455 procedure Bad_Null_Parameter
(Msg
: String) is
3457 Error_Msg_N
(Msg
, N
);
3458 Set_Etype
(N
, Any_Type
);
3459 end Bad_Null_Parameter
;
3461 ----------------------
3462 -- Must_Be_Imported --
3463 ----------------------
3465 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3466 Pent
: Entity_Id
:= Proc_Ent
;
3469 while Present
(Alias
(Pent
)) loop
3470 Pent
:= Alias
(Pent
);
3473 -- Ignore check if procedure not frozen yet (we will get
3474 -- another chance when the default parameter is reanalyzed)
3476 if not Is_Frozen
(Pent
) then
3479 elsif not Is_Imported
(Pent
) then
3481 ("Null_Parameter can only be used with imported subprogram");
3486 end Must_Be_Imported
;
3488 -- Start of processing for Null_Parameter
3493 Set_Etype
(N
, P_Type
);
3495 -- Case of attribute used as default expression
3497 if Nkind
(Parnt
) = N_Parameter_Specification
then
3498 Must_Be_Imported
(Defining_Entity
(GParnt
));
3500 -- Case of attribute used as actual for subprogram (positional)
3502 elsif Nkind_In
(Parnt
, N_Procedure_Call_Statement
,
3504 and then Is_Entity_Name
(Name
(Parnt
))
3506 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3508 -- Case of attribute used as actual for subprogram (named)
3510 elsif Nkind
(Parnt
) = N_Parameter_Association
3511 and then Nkind_In
(GParnt
, N_Procedure_Call_Statement
,
3513 and then Is_Entity_Name
(Name
(GParnt
))
3515 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3517 -- Not an allowed case
3521 ("Null_Parameter must be actual or default parameter");
3529 when Attribute_Object_Size
=>
3532 Check_Not_Incomplete_Type
;
3533 Set_Etype
(N
, Universal_Integer
);
3539 when Attribute_Old
=>
3541 Set_Etype
(N
, P_Type
);
3543 if No
(Current_Subprogram
) then
3544 Error_Attr
("attribute % can only appear within subprogram", N
);
3547 if Is_Limited_Type
(P_Type
) then
3548 Error_Attr
("attribute % cannot apply to limited objects", P
);
3551 if Is_Entity_Name
(P
)
3552 and then Is_Constant_Object
(Entity
(P
))
3555 ("?attribute Old applied to constant has no effect", P
);
3558 -- Check that the expression does not refer to local entities
3560 Check_Local
: declare
3561 Subp
: Entity_Id
:= Current_Subprogram
;
3563 function Process
(N
: Node_Id
) return Traverse_Result
;
3564 -- Check that N does not contain references to local variables
3565 -- or other local entities of Subp.
3571 function Process
(N
: Node_Id
) return Traverse_Result
is
3573 if Is_Entity_Name
(N
)
3574 and then not Is_Formal
(Entity
(N
))
3575 and then Enclosing_Subprogram
(Entity
(N
)) = Subp
3577 Error_Msg_Node_1
:= Entity
(N
);
3579 ("attribute % cannot refer to local variable&", N
);
3585 procedure Check_No_Local
is new Traverse_Proc
;
3587 -- Start of processing for Check_Local
3592 if In_Parameter_Specification
(P
) then
3594 -- We have additional restrictions on using 'Old in parameter
3597 if Present
(Enclosing_Subprogram
(Current_Subprogram
)) then
3599 -- Check that there is no reference to the enclosing
3600 -- subprogram local variables. Otherwise, we might end
3601 -- up being called from the enclosing subprogram and thus
3602 -- using 'Old on a local variable which is not defined
3605 Subp
:= Enclosing_Subprogram
(Current_Subprogram
);
3609 -- We must prevent default expression of library-level
3610 -- subprogram from using 'Old, as the subprogram may be
3611 -- used in elaboration code for which there is no enclosing
3615 ("attribute % can only appear within subprogram", N
);
3624 when Attribute_Output
=>
3626 Check_Stream_Attribute
(TSS_Stream_Output
);
3627 Set_Etype
(N
, Standard_Void_Type
);
3628 Resolve
(N
, Standard_Void_Type
);
3634 when Attribute_Partition_ID
=> Partition_Id
:
3638 if P_Type
/= Any_Type
then
3639 if not Is_Library_Level_Entity
(Entity
(P
)) then
3641 ("prefix of % attribute must be library-level entity");
3643 -- The defining entity of prefix should not be declared inside a
3644 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
3646 elsif Is_Entity_Name
(P
)
3647 and then Is_Pure
(Entity
(P
))
3650 ("prefix of % attribute must not be declared pure");
3654 Set_Etype
(N
, Universal_Integer
);
3657 -------------------------
3658 -- Passed_By_Reference --
3659 -------------------------
3661 when Attribute_Passed_By_Reference
=>
3664 Set_Etype
(N
, Standard_Boolean
);
3670 when Attribute_Pool_Address
=>
3672 Set_Etype
(N
, RTE
(RE_Address
));
3678 when Attribute_Pos
=>
3679 Check_Discrete_Type
;
3681 Resolve
(E1
, P_Base_Type
);
3682 Set_Etype
(N
, Universal_Integer
);
3688 when Attribute_Position
=>
3690 Set_Etype
(N
, Universal_Integer
);
3696 when Attribute_Pred
=>
3699 Resolve
(E1
, P_Base_Type
);
3700 Set_Etype
(N
, P_Base_Type
);
3702 -- Nothing to do for real type case
3704 if Is_Real_Type
(P_Type
) then
3707 -- If not modular type, test for overflow check required
3710 if not Is_Modular_Integer_Type
(P_Type
)
3711 and then not Range_Checks_Suppressed
(P_Base_Type
)
3713 Enable_Range_Check
(E1
);
3721 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3723 when Attribute_Priority
=>
3724 if Ada_Version
< Ada_05
then
3725 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
3730 -- The prefix must be a protected object (AARM D.5.2 (2/2))
3734 if Is_Protected_Type
(Etype
(P
))
3735 or else (Is_Access_Type
(Etype
(P
))
3736 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
3738 Resolve
(P
, Etype
(P
));
3740 Error_Attr_P
("prefix of % attribute must be a protected object");
3743 Set_Etype
(N
, Standard_Integer
);
3745 -- Must be called from within a protected procedure or entry of the
3746 -- protected object.
3753 while S
/= Etype
(P
)
3754 and then S
/= Standard_Standard
3759 if S
= Standard_Standard
then
3760 Error_Attr
("the attribute % is only allowed inside protected "
3765 Validate_Non_Static_Attribute_Function_Call
;
3771 when Attribute_Range
=>
3772 Check_Array_Or_Scalar_Type
;
3774 if Ada_Version
= Ada_83
3775 and then Is_Scalar_Type
(P_Type
)
3776 and then Comes_From_Source
(N
)
3779 ("(Ada 83) % attribute not allowed for scalar type", P
);
3786 when Attribute_Result
=> Result
: declare
3787 CS
: Entity_Id
:= Current_Scope
;
3788 PS
: Entity_Id
:= Scope
(CS
);
3791 -- If the enclosing subprogram is always inlined, the enclosing
3792 -- postcondition will not be propagated to the expanded call.
3794 if Has_Pragma_Inline_Always
(PS
)
3795 and then Warn_On_Redundant_Constructs
3798 ("postconditions on inlined functions not enforced?", N
);
3801 -- If we are in the scope of a function and in Spec_Expression mode,
3802 -- this is likely the prescan of the postcondition pragma, and we
3803 -- just set the proper type. If there is an error it will be caught
3804 -- when the real Analyze call is done.
3806 if Ekind
(CS
) = E_Function
3807 and then In_Spec_Expression
3811 if Chars
(CS
) /= Chars
(P
) then
3813 ("incorrect prefix for % attribute, expected &", P
, CS
);
3817 Set_Etype
(N
, Etype
(CS
));
3819 -- If several functions with that name are visible,
3820 -- the intended one is the current scope.
3822 if Is_Overloaded
(P
) then
3824 Set_Is_Overloaded
(P
, False);
3827 -- Body case, where we must be inside a generated _Postcondition
3828 -- procedure, and the prefix must be on the scope stack, or else
3829 -- the attribute use is definitely misplaced. The condition itself
3830 -- may have generated transient scopes, and is not necessarily the
3835 and then CS
/= Standard_Standard
3837 if Chars
(CS
) = Name_uPostconditions
then
3846 if Chars
(CS
) = Name_uPostconditions
3847 and then Ekind
(PS
) = E_Function
3851 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
3852 and then Chars
(P
) = Chars
(PS
)
3856 -- Within an instance, the prefix designates the local renaming
3857 -- of the original generic.
3859 elsif Is_Entity_Name
(P
)
3860 and then Ekind
(Entity
(P
)) = E_Function
3861 and then Present
(Alias
(Entity
(P
)))
3862 and then Chars
(Alias
(Entity
(P
))) = Chars
(PS
)
3868 ("incorrect prefix for % attribute, expected &", P
, PS
);
3873 Make_Identifier
(Sloc
(N
),
3874 Chars
=> Name_uResult
));
3875 Analyze_And_Resolve
(N
, Etype
(PS
));
3879 ("% attribute can only appear" &
3880 " in function Postcondition pragma", P
);
3889 when Attribute_Range_Length
=>
3891 Check_Discrete_Type
;
3892 Set_Etype
(N
, Universal_Integer
);
3898 when Attribute_Read
=>
3900 Check_Stream_Attribute
(TSS_Stream_Read
);
3901 Set_Etype
(N
, Standard_Void_Type
);
3902 Resolve
(N
, Standard_Void_Type
);
3903 Note_Possible_Modification
(E2
, Sure
=> True);
3909 when Attribute_Remainder
=>
3910 Check_Floating_Point_Type_2
;
3911 Set_Etype
(N
, P_Base_Type
);
3912 Resolve
(E1
, P_Base_Type
);
3913 Resolve
(E2
, P_Base_Type
);
3919 when Attribute_Round
=>
3921 Check_Decimal_Fixed_Point_Type
;
3922 Set_Etype
(N
, P_Base_Type
);
3924 -- Because the context is universal_real (3.5.10(12)) it is a legal
3925 -- context for a universal fixed expression. This is the only
3926 -- attribute whose functional description involves U_R.
3928 if Etype
(E1
) = Universal_Fixed
then
3930 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3931 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3932 Expression
=> Relocate_Node
(E1
));
3940 Resolve
(E1
, Any_Real
);
3946 when Attribute_Rounding
=>
3947 Check_Floating_Point_Type_1
;
3948 Set_Etype
(N
, P_Base_Type
);
3949 Resolve
(E1
, P_Base_Type
);
3955 when Attribute_Safe_Emax
=>
3956 Check_Floating_Point_Type_0
;
3957 Set_Etype
(N
, Universal_Integer
);
3963 when Attribute_Safe_First
=>
3964 Check_Floating_Point_Type_0
;
3965 Set_Etype
(N
, Universal_Real
);
3971 when Attribute_Safe_Large
=>
3974 Set_Etype
(N
, Universal_Real
);
3980 when Attribute_Safe_Last
=>
3981 Check_Floating_Point_Type_0
;
3982 Set_Etype
(N
, Universal_Real
);
3988 when Attribute_Safe_Small
=>
3991 Set_Etype
(N
, Universal_Real
);
3997 when Attribute_Scale
=>
3999 Check_Decimal_Fixed_Point_Type
;
4000 Set_Etype
(N
, Universal_Integer
);
4006 when Attribute_Scaling
=>
4007 Check_Floating_Point_Type_2
;
4008 Set_Etype
(N
, P_Base_Type
);
4009 Resolve
(E1
, P_Base_Type
);
4015 when Attribute_Signed_Zeros
=>
4016 Check_Floating_Point_Type_0
;
4017 Set_Etype
(N
, Standard_Boolean
);
4023 when Attribute_Size | Attribute_VADS_Size
=> Size
:
4027 -- If prefix is parameterless function call, rewrite and resolve
4030 if Is_Entity_Name
(P
)
4031 and then Ekind
(Entity
(P
)) = E_Function
4035 -- Similar processing for a protected function call
4037 elsif Nkind
(P
) = N_Selected_Component
4038 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
4043 if Is_Object_Reference
(P
) then
4044 Check_Object_Reference
(P
);
4046 elsif Is_Entity_Name
(P
)
4047 and then (Is_Type
(Entity
(P
))
4048 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
4052 elsif Nkind
(P
) = N_Type_Conversion
4053 and then not Comes_From_Source
(P
)
4058 Error_Attr_P
("invalid prefix for % attribute");
4061 Check_Not_Incomplete_Type
;
4063 Set_Etype
(N
, Universal_Integer
);
4070 when Attribute_Small
=>
4073 Set_Etype
(N
, Universal_Real
);
4079 when Attribute_Storage_Pool
=> Storage_Pool
:
4083 if Is_Access_Type
(P_Type
) then
4084 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
4086 ("cannot use % attribute for access-to-subprogram type");
4089 -- Set appropriate entity
4091 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
4092 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
4094 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
4097 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
4099 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4100 -- Storage_Pool since this attribute is not defined for such
4101 -- types (RM E.2.3(22)).
4103 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4106 Error_Attr_P
("prefix of % attribute must be access type");
4114 when Attribute_Storage_Size
=> Storage_Size
:
4118 if Is_Task_Type
(P_Type
) then
4119 Set_Etype
(N
, Universal_Integer
);
4121 elsif Is_Access_Type
(P_Type
) then
4122 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
4124 ("cannot use % attribute for access-to-subprogram type");
4127 if Is_Entity_Name
(P
)
4128 and then Is_Type
(Entity
(P
))
4131 Set_Etype
(N
, Universal_Integer
);
4133 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4134 -- Storage_Size since this attribute is not defined for
4135 -- such types (RM E.2.3(22)).
4137 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4139 -- The prefix is allowed to be an implicit dereference
4140 -- of an access value designating a task.
4144 Set_Etype
(N
, Universal_Integer
);
4148 Error_Attr_P
("prefix of % attribute must be access or task type");
4156 when Attribute_Storage_Unit
=>
4157 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
4163 when Attribute_Stream_Size
=>
4167 if Is_Entity_Name
(P
)
4168 and then Is_Elementary_Type
(Entity
(P
))
4170 Set_Etype
(N
, Universal_Integer
);
4172 Error_Attr_P
("invalid prefix for % attribute");
4179 when Attribute_Stub_Type
=>
4183 if Is_Remote_Access_To_Class_Wide_Type
(P_Type
) then
4185 New_Occurrence_Of
(Corresponding_Stub_Type
(P_Type
), Loc
));
4188 ("prefix of% attribute must be remote access to classwide");
4195 when Attribute_Succ
=>
4198 Resolve
(E1
, P_Base_Type
);
4199 Set_Etype
(N
, P_Base_Type
);
4201 -- Nothing to do for real type case
4203 if Is_Real_Type
(P_Type
) then
4206 -- If not modular type, test for overflow check required
4209 if not Is_Modular_Integer_Type
(P_Type
)
4210 and then not Range_Checks_Suppressed
(P_Base_Type
)
4212 Enable_Range_Check
(E1
);
4220 when Attribute_Tag
=> Tag
:
4225 if not Is_Tagged_Type
(P_Type
) then
4226 Error_Attr_P
("prefix of % attribute must be tagged");
4228 -- Next test does not apply to generated code
4229 -- why not, and what does the illegal reference mean???
4231 elsif Is_Object_Reference
(P
)
4232 and then not Is_Class_Wide_Type
(P_Type
)
4233 and then Comes_From_Source
(N
)
4236 ("% attribute can only be applied to objects " &
4237 "of class - wide type");
4240 -- The prefix cannot be an incomplete type. However, references
4241 -- to 'Tag can be generated when expanding interface conversions,
4242 -- and this is legal.
4244 if Comes_From_Source
(N
) then
4245 Check_Not_Incomplete_Type
;
4248 -- Set appropriate type
4250 Set_Etype
(N
, RTE
(RE_Tag
));
4257 when Attribute_Target_Name
=> Target_Name
: declare
4258 TN
: constant String := Sdefault
.Target_Name
.all;
4262 Check_Standard_Prefix
;
4266 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
4271 Make_String_Literal
(Loc
,
4272 Strval
=> TN
(TN
'First .. TL
)));
4273 Analyze_And_Resolve
(N
, Standard_String
);
4280 when Attribute_Terminated
=>
4282 Set_Etype
(N
, Standard_Boolean
);
4289 when Attribute_To_Address
=>
4293 if Nkind
(P
) /= N_Identifier
4294 or else Chars
(P
) /= Name_System
4296 Error_Attr_P
("prefix of %attribute must be System");
4299 Generate_Reference
(RTE
(RE_Address
), P
);
4300 Analyze_And_Resolve
(E1
, Any_Integer
);
4301 Set_Etype
(N
, RTE
(RE_Address
));
4307 when Attribute_To_Any
=>
4309 Check_PolyORB_Attribute
;
4310 Set_Etype
(N
, RTE
(RE_Any
));
4316 when Attribute_Truncation
=>
4317 Check_Floating_Point_Type_1
;
4318 Resolve
(E1
, P_Base_Type
);
4319 Set_Etype
(N
, P_Base_Type
);
4325 when Attribute_Type_Class
=>
4328 Check_Not_Incomplete_Type
;
4329 Set_Etype
(N
, RTE
(RE_Type_Class
));
4335 when Attribute_TypeCode
=>
4337 Check_PolyORB_Attribute
;
4338 Set_Etype
(N
, RTE
(RE_TypeCode
));
4344 when Attribute_UET_Address
=>
4346 Check_Unit_Name
(P
);
4347 Set_Etype
(N
, RTE
(RE_Address
));
4349 -----------------------
4350 -- Unbiased_Rounding --
4351 -----------------------
4353 when Attribute_Unbiased_Rounding
=>
4354 Check_Floating_Point_Type_1
;
4355 Set_Etype
(N
, P_Base_Type
);
4356 Resolve
(E1
, P_Base_Type
);
4358 ----------------------
4359 -- Unchecked_Access --
4360 ----------------------
4362 when Attribute_Unchecked_Access
=>
4363 if Comes_From_Source
(N
) then
4364 Check_Restriction
(No_Unchecked_Access
, N
);
4367 Analyze_Access_Attribute
;
4369 -------------------------
4370 -- Unconstrained_Array --
4371 -------------------------
4373 when Attribute_Unconstrained_Array
=>
4376 Check_Not_Incomplete_Type
;
4377 Set_Etype
(N
, Standard_Boolean
);
4379 ------------------------------
4380 -- Universal_Literal_String --
4381 ------------------------------
4383 -- This is a GNAT specific attribute whose prefix must be a named
4384 -- number where the expression is either a single numeric literal,
4385 -- or a numeric literal immediately preceded by a minus sign. The
4386 -- result is equivalent to a string literal containing the text of
4387 -- the literal as it appeared in the source program with a possible
4388 -- leading minus sign.
4390 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
4394 if not Is_Entity_Name
(P
)
4395 or else Ekind
(Entity
(P
)) not in Named_Kind
4397 Error_Attr_P
("prefix for % attribute must be named number");
4404 Src
: Source_Buffer_Ptr
;
4407 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
4409 if Nkind
(Expr
) = N_Op_Minus
then
4411 Expr
:= Original_Node
(Right_Opnd
(Expr
));
4416 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
4418 ("named number for % attribute must be simple literal", N
);
4421 -- Build string literal corresponding to source literal text
4426 Store_String_Char
(Get_Char_Code
('-'));
4430 Src
:= Source_Text
(Get_Source_File_Index
(S
));
4432 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
4433 Store_String_Char
(Get_Char_Code
(Src
(S
)));
4437 -- Now we rewrite the attribute with the string literal
4440 Make_String_Literal
(Loc
, End_String
));
4444 end Universal_Literal_String
;
4446 -------------------------
4447 -- Unrestricted_Access --
4448 -------------------------
4450 -- This is a GNAT specific attribute which is like Access except that
4451 -- all scope checks and checks for aliased views are omitted.
4453 when Attribute_Unrestricted_Access
=>
4454 if Comes_From_Source
(N
) then
4455 Check_Restriction
(No_Unchecked_Access
, N
);
4458 if Is_Entity_Name
(P
) then
4459 Set_Address_Taken
(Entity
(P
));
4462 Analyze_Access_Attribute
;
4468 when Attribute_Val
=> Val
: declare
4471 Check_Discrete_Type
;
4472 Resolve
(E1
, Any_Integer
);
4473 Set_Etype
(N
, P_Base_Type
);
4475 -- Note, we need a range check in general, but we wait for the
4476 -- Resolve call to do this, since we want to let Eval_Attribute
4477 -- have a chance to find an static illegality first!
4484 when Attribute_Valid
=>
4487 -- Ignore check for object if we have a 'Valid reference generated
4488 -- by the expanded code, since in some cases valid checks can occur
4489 -- on items that are names, but are not objects (e.g. attributes).
4491 if Comes_From_Source
(N
) then
4492 Check_Object_Reference
(P
);
4495 if not Is_Scalar_Type
(P_Type
) then
4496 Error_Attr_P
("object for % attribute must be of scalar type");
4499 Set_Etype
(N
, Standard_Boolean
);
4505 when Attribute_Value
=> Value
:
4510 -- Case of enumeration type
4512 if Is_Enumeration_Type
(P_Type
) then
4513 Check_Restriction
(No_Enumeration_Maps
, N
);
4515 -- Mark all enumeration literals as referenced, since the use of
4516 -- the Value attribute can implicitly reference any of the
4517 -- literals of the enumeration base type.
4520 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
4522 while Present
(Ent
) loop
4523 Set_Referenced
(Ent
);
4529 -- Set Etype before resolving expression because expansion of
4530 -- expression may require enclosing type. Note that the type
4531 -- returned by 'Value is the base type of the prefix type.
4533 Set_Etype
(N
, P_Base_Type
);
4534 Validate_Non_Static_Attribute_Function_Call
;
4541 when Attribute_Value_Size
=>
4544 Check_Not_Incomplete_Type
;
4545 Set_Etype
(N
, Universal_Integer
);
4551 when Attribute_Version
=>
4554 Set_Etype
(N
, RTE
(RE_Version_String
));
4560 when Attribute_Wchar_T_Size
=>
4561 Standard_Attribute
(Interfaces_Wchar_T_Size
);
4567 when Attribute_Wide_Image
=> Wide_Image
:
4570 Set_Etype
(N
, Standard_Wide_String
);
4572 Resolve
(E1
, P_Base_Type
);
4573 Validate_Non_Static_Attribute_Function_Call
;
4576 ---------------------
4577 -- Wide_Wide_Image --
4578 ---------------------
4580 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4583 Set_Etype
(N
, Standard_Wide_Wide_String
);
4585 Resolve
(E1
, P_Base_Type
);
4586 Validate_Non_Static_Attribute_Function_Call
;
4587 end Wide_Wide_Image
;
4593 when Attribute_Wide_Value
=> Wide_Value
:
4598 -- Set Etype before resolving expression because expansion
4599 -- of expression may require enclosing type.
4601 Set_Etype
(N
, P_Type
);
4602 Validate_Non_Static_Attribute_Function_Call
;
4605 ---------------------
4606 -- Wide_Wide_Value --
4607 ---------------------
4609 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4614 -- Set Etype before resolving expression because expansion
4615 -- of expression may require enclosing type.
4617 Set_Etype
(N
, P_Type
);
4618 Validate_Non_Static_Attribute_Function_Call
;
4619 end Wide_Wide_Value
;
4621 ---------------------
4622 -- Wide_Wide_Width --
4623 ---------------------
4625 when Attribute_Wide_Wide_Width
=>
4628 Set_Etype
(N
, Universal_Integer
);
4634 when Attribute_Wide_Width
=>
4637 Set_Etype
(N
, Universal_Integer
);
4643 when Attribute_Width
=>
4646 Set_Etype
(N
, Universal_Integer
);
4652 when Attribute_Word_Size
=>
4653 Standard_Attribute
(System_Word_Size
);
4659 when Attribute_Write
=>
4661 Check_Stream_Attribute
(TSS_Stream_Write
);
4662 Set_Etype
(N
, Standard_Void_Type
);
4663 Resolve
(N
, Standard_Void_Type
);
4667 -- All errors raise Bad_Attribute, so that we get out before any further
4668 -- damage occurs when an error is detected (for example, if we check for
4669 -- one attribute expression, and the check succeeds, we want to be able
4670 -- to proceed securely assuming that an expression is in fact present.
4672 -- Note: we set the attribute analyzed in this case to prevent any
4673 -- attempt at reanalysis which could generate spurious error msgs.
4676 when Bad_Attribute
=>
4678 Set_Etype
(N
, Any_Type
);
4680 end Analyze_Attribute
;
4682 --------------------
4683 -- Eval_Attribute --
4684 --------------------
4686 procedure Eval_Attribute
(N
: Node_Id
) is
4687 Loc
: constant Source_Ptr
:= Sloc
(N
);
4688 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4689 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4690 P
: constant Node_Id
:= Prefix
(N
);
4692 C_Type
: constant Entity_Id
:= Etype
(N
);
4693 -- The type imposed by the context
4696 -- First expression, or Empty if none
4699 -- Second expression, or Empty if none
4701 P_Entity
: Entity_Id
;
4702 -- Entity denoted by prefix
4705 -- The type of the prefix
4707 P_Base_Type
: Entity_Id
;
4708 -- The base type of the prefix type
4710 P_Root_Type
: Entity_Id
;
4711 -- The root type of the prefix type
4714 -- True if the result is Static. This is set by the general processing
4715 -- to true if the prefix is static, and all expressions are static. It
4716 -- can be reset as processing continues for particular attributes
4718 Lo_Bound
, Hi_Bound
: Node_Id
;
4719 -- Expressions for low and high bounds of type or array index referenced
4720 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4723 -- Constraint error node used if we have an attribute reference has
4724 -- an argument that raises a constraint error. In this case we replace
4725 -- the attribute with a raise constraint_error node. This is important
4726 -- processing, since otherwise gigi might see an attribute which it is
4727 -- unprepared to deal with.
4729 function Aft_Value
return Nat
;
4730 -- Computes Aft value for current attribute prefix (used by Aft itself
4731 -- and also by Width for computing the Width of a fixed point type).
4733 procedure Check_Expressions
;
4734 -- In case where the attribute is not foldable, the expressions, if
4735 -- any, of the attribute, are in a non-static context. This procedure
4736 -- performs the required additional checks.
4738 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4739 -- Determines if the given type has compile time known bounds. Note
4740 -- that we enter the case statement even in cases where the prefix
4741 -- type does NOT have known bounds, so it is important to guard any
4742 -- attempt to evaluate both bounds with a call to this function.
4744 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4745 -- This procedure is called when the attribute N has a non-static
4746 -- but compile time known value given by Val. It includes the
4747 -- necessary checks for out of range values.
4749 procedure Float_Attribute_Universal_Integer
4758 -- This procedure evaluates a float attribute with no arguments that
4759 -- returns a universal integer result. The parameters give the values
4760 -- for the possible floating-point root types. See ttypef for details.
4761 -- The prefix type is a float type (and is thus not a generic type).
4763 procedure Float_Attribute_Universal_Real
4764 (IEEES_Val
: String;
4771 AAMPL_Val
: String);
4772 -- This procedure evaluates a float attribute with no arguments that
4773 -- returns a universal real result. The parameters give the values
4774 -- required for the possible floating-point root types in string
4775 -- format as real literals with a possible leading minus sign.
4776 -- The prefix type is a float type (and is thus not a generic type).
4778 function Fore_Value
return Nat
;
4779 -- Computes the Fore value for the current attribute prefix, which is
4780 -- known to be a static fixed-point type. Used by Fore and Width.
4782 function Mantissa
return Uint
;
4783 -- Returns the Mantissa value for the prefix type
4785 procedure Set_Bounds
;
4786 -- Used for First, Last and Length attributes applied to an array or
4787 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4788 -- and high bound expressions for the index referenced by the attribute
4789 -- designator (i.e. the first index if no expression is present, and
4790 -- the N'th index if the value N is present as an expression). Also
4791 -- used for First and Last of scalar types. Static is reset to False
4792 -- if the type or index type is not statically constrained.
4794 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4795 -- Verify that the prefix of a potentially static array attribute
4796 -- satisfies the conditions of 4.9 (14).
4802 function Aft_Value
return Nat
is
4808 Delta_Val
:= Delta_Value
(P_Type
);
4809 while Delta_Val
< Ureal_Tenth
loop
4810 Delta_Val
:= Delta_Val
* Ureal_10
;
4811 Result
:= Result
+ 1;
4817 -----------------------
4818 -- Check_Expressions --
4819 -----------------------
4821 procedure Check_Expressions
is
4825 while Present
(E
) loop
4826 Check_Non_Static_Context
(E
);
4829 end Check_Expressions
;
4831 ----------------------------------
4832 -- Compile_Time_Known_Attribute --
4833 ----------------------------------
4835 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4836 T
: constant Entity_Id
:= Etype
(N
);
4839 Fold_Uint
(N
, Val
, False);
4841 -- Check that result is in bounds of the type if it is static
4843 if Is_In_Range
(N
, T
) then
4846 elsif Is_Out_Of_Range
(N
, T
) then
4847 Apply_Compile_Time_Constraint_Error
4848 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4850 elsif not Range_Checks_Suppressed
(T
) then
4851 Enable_Range_Check
(N
);
4854 Set_Do_Range_Check
(N
, False);
4856 end Compile_Time_Known_Attribute
;
4858 -------------------------------
4859 -- Compile_Time_Known_Bounds --
4860 -------------------------------
4862 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4865 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4867 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4868 end Compile_Time_Known_Bounds
;
4870 ---------------------------------------
4871 -- Float_Attribute_Universal_Integer --
4872 ---------------------------------------
4874 procedure Float_Attribute_Universal_Integer
4885 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4888 if Vax_Float
(P_Base_Type
) then
4889 if Digs
= VAXFF_Digits
then
4891 elsif Digs
= VAXDF_Digits
then
4893 else pragma Assert
(Digs
= VAXGF_Digits
);
4897 elsif Is_AAMP_Float
(P_Base_Type
) then
4898 if Digs
= AAMPS_Digits
then
4900 else pragma Assert
(Digs
= AAMPL_Digits
);
4905 if Digs
= IEEES_Digits
then
4907 elsif Digs
= IEEEL_Digits
then
4909 else pragma Assert
(Digs
= IEEEX_Digits
);
4914 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4915 end Float_Attribute_Universal_Integer
;
4917 ------------------------------------
4918 -- Float_Attribute_Universal_Real --
4919 ------------------------------------
4921 procedure Float_Attribute_Universal_Real
4922 (IEEES_Val
: String;
4932 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4935 if Vax_Float
(P_Base_Type
) then
4936 if Digs
= VAXFF_Digits
then
4937 Val
:= Real_Convert
(VAXFF_Val
);
4938 elsif Digs
= VAXDF_Digits
then
4939 Val
:= Real_Convert
(VAXDF_Val
);
4940 else pragma Assert
(Digs
= VAXGF_Digits
);
4941 Val
:= Real_Convert
(VAXGF_Val
);
4944 elsif Is_AAMP_Float
(P_Base_Type
) then
4945 if Digs
= AAMPS_Digits
then
4946 Val
:= Real_Convert
(AAMPS_Val
);
4947 else pragma Assert
(Digs
= AAMPL_Digits
);
4948 Val
:= Real_Convert
(AAMPL_Val
);
4952 if Digs
= IEEES_Digits
then
4953 Val
:= Real_Convert
(IEEES_Val
);
4954 elsif Digs
= IEEEL_Digits
then
4955 Val
:= Real_Convert
(IEEEL_Val
);
4956 else pragma Assert
(Digs
= IEEEX_Digits
);
4957 Val
:= Real_Convert
(IEEEX_Val
);
4961 Set_Sloc
(Val
, Loc
);
4963 Set_Is_Static_Expression
(N
, Static
);
4964 Analyze_And_Resolve
(N
, C_Type
);
4965 end Float_Attribute_Universal_Real
;
4971 -- Note that the Fore calculation is based on the actual values
4972 -- of the bounds, and does not take into account possible rounding.
4974 function Fore_Value
return Nat
is
4975 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4976 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4977 Small
: constant Ureal
:= Small_Value
(P_Type
);
4978 Lo_Real
: constant Ureal
:= Lo
* Small
;
4979 Hi_Real
: constant Ureal
:= Hi
* Small
;
4984 -- Bounds are given in terms of small units, so first compute
4985 -- proper values as reals.
4987 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4990 -- Loop to compute proper value if more than one digit required
4992 while T
>= Ureal_10
loop
5004 -- Table of mantissa values accessed by function Computed using
5007 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
5009 -- where D is T'Digits (RM83 3.5.7)
5011 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
5053 function Mantissa
return Uint
is
5056 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
5063 procedure Set_Bounds
is
5069 -- For a string literal subtype, we have to construct the bounds.
5070 -- Valid Ada code never applies attributes to string literals, but
5071 -- it is convenient to allow the expander to generate attribute
5072 -- references of this type (e.g. First and Last applied to a string
5075 -- Note that the whole point of the E_String_Literal_Subtype is to
5076 -- avoid this construction of bounds, but the cases in which we
5077 -- have to materialize them are rare enough that we don't worry!
5079 -- The low bound is simply the low bound of the base type. The
5080 -- high bound is computed from the length of the string and this
5083 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
5084 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
5085 Lo_Bound
:= Type_Low_Bound
(Ityp
);
5088 Make_Integer_Literal
(Sloc
(P
),
5090 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
5092 Set_Parent
(Hi_Bound
, P
);
5093 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
5096 -- For non-array case, just get bounds of scalar type
5098 elsif Is_Scalar_Type
(P_Type
) then
5101 -- For a fixed-point type, we must freeze to get the attributes
5102 -- of the fixed-point type set now so we can reference them.
5104 if Is_Fixed_Point_Type
(P_Type
)
5105 and then not Is_Frozen
(Base_Type
(P_Type
))
5106 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5107 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5109 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
5112 -- For array case, get type of proper index
5118 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
5121 Indx
:= First_Index
(P_Type
);
5122 for J
in 1 .. Ndim
- 1 loop
5126 -- If no index type, get out (some other error occurred, and
5127 -- we don't have enough information to complete the job!)
5135 Ityp
:= Etype
(Indx
);
5138 -- A discrete range in an index constraint is allowed to be a
5139 -- subtype indication. This is syntactically a pain, but should
5140 -- not propagate to the entity for the corresponding index subtype.
5141 -- After checking that the subtype indication is legal, the range
5142 -- of the subtype indication should be transfered to the entity.
5143 -- The attributes for the bounds should remain the simple retrievals
5144 -- that they are now.
5146 Lo_Bound
:= Type_Low_Bound
(Ityp
);
5147 Hi_Bound
:= Type_High_Bound
(Ityp
);
5149 if not Is_Static_Subtype
(Ityp
) then
5154 -------------------------------
5155 -- Statically_Denotes_Entity --
5156 -------------------------------
5158 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
5162 if not Is_Entity_Name
(N
) then
5169 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
5170 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
5171 end Statically_Denotes_Entity
;
5173 -- Start of processing for Eval_Attribute
5176 -- Acquire first two expressions (at the moment, no attributes
5177 -- take more than two expressions in any case).
5179 if Present
(Expressions
(N
)) then
5180 E1
:= First
(Expressions
(N
));
5187 -- Special processing for Enabled attribute. This attribute has a very
5188 -- special prefix, and the easiest way to avoid lots of special checks
5189 -- to protect this special prefix from causing trouble is to deal with
5190 -- this attribute immediately and be done with it.
5192 if Id
= Attribute_Enabled
then
5194 -- Evaluate the Enabled attribute
5196 -- We skip evaluation if the expander is not active. This is not just
5197 -- an optimization. It is of key importance that we not rewrite the
5198 -- attribute in a generic template, since we want to pick up the
5199 -- setting of the check in the instance, and testing expander active
5200 -- is as easy way of doing this as any.
5202 if Expander_Active
then
5204 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
5209 if C
in Predefined_Check_Id
then
5210 R
:= Scope_Suppress
(C
);
5212 R
:= Is_Check_Suppressed
(Empty
, C
);
5216 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
5220 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
5222 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
5230 -- Special processing for cases where the prefix is an object. For
5231 -- this purpose, a string literal counts as an object (attributes
5232 -- of string literals can only appear in generated code).
5234 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
5236 -- For Component_Size, the prefix is an array object, and we apply
5237 -- the attribute to the type of the object. This is allowed for
5238 -- both unconstrained and constrained arrays, since the bounds
5239 -- have no influence on the value of this attribute.
5241 if Id
= Attribute_Component_Size
then
5242 P_Entity
:= Etype
(P
);
5244 -- For First and Last, the prefix is an array object, and we apply
5245 -- the attribute to the type of the array, but we need a constrained
5246 -- type for this, so we use the actual subtype if available.
5248 elsif Id
= Attribute_First
5252 Id
= Attribute_Length
5255 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
5258 if Present
(AS
) and then Is_Constrained
(AS
) then
5261 -- If we have an unconstrained type, cannot fold
5269 -- For Size, give size of object if available, otherwise we
5270 -- cannot fold Size.
5272 elsif Id
= Attribute_Size
then
5273 if Is_Entity_Name
(P
)
5274 and then Known_Esize
(Entity
(P
))
5276 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
5284 -- For Alignment, give size of object if available, otherwise we
5285 -- cannot fold Alignment.
5287 elsif Id
= Attribute_Alignment
then
5288 if Is_Entity_Name
(P
)
5289 and then Known_Alignment
(Entity
(P
))
5291 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
5299 -- No other attributes for objects are folded
5306 -- Cases where P is not an object. Cannot do anything if P is
5307 -- not the name of an entity.
5309 elsif not Is_Entity_Name
(P
) then
5313 -- Otherwise get prefix entity
5316 P_Entity
:= Entity
(P
);
5319 -- At this stage P_Entity is the entity to which the attribute
5320 -- is to be applied. This is usually simply the entity of the
5321 -- prefix, except in some cases of attributes for objects, where
5322 -- as described above, we apply the attribute to the object type.
5324 -- First foldable possibility is a scalar or array type (RM 4.9(7))
5325 -- that is not generic (generic types are eliminated by RM 4.9(25)).
5326 -- Note we allow non-static non-generic types at this stage as further
5329 if Is_Type
(P_Entity
)
5330 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
5331 and then (not Is_Generic_Type
(P_Entity
))
5335 -- Second foldable possibility is an array object (RM 4.9(8))
5337 elsif (Ekind
(P_Entity
) = E_Variable
5339 Ekind
(P_Entity
) = E_Constant
)
5340 and then Is_Array_Type
(Etype
(P_Entity
))
5341 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
5343 P_Type
:= Etype
(P_Entity
);
5345 -- If the entity is an array constant with an unconstrained nominal
5346 -- subtype then get the type from the initial value. If the value has
5347 -- been expanded into assignments, there is no expression and the
5348 -- attribute reference remains dynamic.
5350 -- We could do better here and retrieve the type ???
5352 if Ekind
(P_Entity
) = E_Constant
5353 and then not Is_Constrained
(P_Type
)
5355 if No
(Constant_Value
(P_Entity
)) then
5358 P_Type
:= Etype
(Constant_Value
(P_Entity
));
5362 -- Definite must be folded if the prefix is not a generic type,
5363 -- that is to say if we are within an instantiation. Same processing
5364 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
5365 -- Has_Tagged_Value, and Unconstrained_Array.
5367 elsif (Id
= Attribute_Definite
5369 Id
= Attribute_Has_Access_Values
5371 Id
= Attribute_Has_Discriminants
5373 Id
= Attribute_Has_Tagged_Values
5375 Id
= Attribute_Type_Class
5377 Id
= Attribute_Unconstrained_Array
)
5378 and then not Is_Generic_Type
(P_Entity
)
5382 -- We can fold 'Size applied to a type if the size is known (as happens
5383 -- for a size from an attribute definition clause). At this stage, this
5384 -- can happen only for types (e.g. record types) for which the size is
5385 -- always non-static. We exclude generic types from consideration (since
5386 -- they have bogus sizes set within templates).
5388 elsif Id
= Attribute_Size
5389 and then Is_Type
(P_Entity
)
5390 and then (not Is_Generic_Type
(P_Entity
))
5391 and then Known_Static_RM_Size
(P_Entity
)
5393 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
5396 -- We can fold 'Alignment applied to a type if the alignment is known
5397 -- (as happens for an alignment from an attribute definition clause).
5398 -- At this stage, this can happen only for types (e.g. record
5399 -- types) for which the size is always non-static. We exclude
5400 -- generic types from consideration (since they have bogus
5401 -- sizes set within templates).
5403 elsif Id
= Attribute_Alignment
5404 and then Is_Type
(P_Entity
)
5405 and then (not Is_Generic_Type
(P_Entity
))
5406 and then Known_Alignment
(P_Entity
)
5408 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
5411 -- If this is an access attribute that is known to fail accessibility
5412 -- check, rewrite accordingly.
5414 elsif Attribute_Name
(N
) = Name_Access
5415 and then Raises_Constraint_Error
(N
)
5418 Make_Raise_Program_Error
(Loc
,
5419 Reason
=> PE_Accessibility_Check_Failed
));
5420 Set_Etype
(N
, C_Type
);
5423 -- No other cases are foldable (they certainly aren't static, and at
5424 -- the moment we don't try to fold any cases other than these three).
5431 -- If either attribute or the prefix is Any_Type, then propagate
5432 -- Any_Type to the result and don't do anything else at all.
5434 if P_Type
= Any_Type
5435 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
5436 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
5438 Set_Etype
(N
, Any_Type
);
5442 -- Scalar subtype case. We have not yet enforced the static requirement
5443 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
5444 -- of non-static attribute references (e.g. S'Digits for a non-static
5445 -- floating-point type, which we can compute at compile time).
5447 -- Note: this folding of non-static attributes is not simply a case of
5448 -- optimization. For many of the attributes affected, Gigi cannot handle
5449 -- the attribute and depends on the front end having folded them away.
5451 -- Note: although we don't require staticness at this stage, we do set
5452 -- the Static variable to record the staticness, for easy reference by
5453 -- those attributes where it matters (e.g. Succ and Pred), and also to
5454 -- be used to ensure that non-static folded things are not marked as
5455 -- being static (a check that is done right at the end).
5457 P_Root_Type
:= Root_Type
(P_Type
);
5458 P_Base_Type
:= Base_Type
(P_Type
);
5460 -- If the root type or base type is generic, then we cannot fold. This
5461 -- test is needed because subtypes of generic types are not always
5462 -- marked as being generic themselves (which seems odd???)
5464 if Is_Generic_Type
(P_Root_Type
)
5465 or else Is_Generic_Type
(P_Base_Type
)
5470 if Is_Scalar_Type
(P_Type
) then
5471 Static
:= Is_OK_Static_Subtype
(P_Type
);
5473 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
5474 -- since we can't do anything with unconstrained arrays. In addition,
5475 -- only the First, Last and Length attributes are possibly static.
5477 -- Definite, Has_Access_Values, Has_Discriminants, Has_Tagged_Values,
5478 -- Type_Class, and Unconstrained_Array are again exceptions, because
5479 -- they apply as well to unconstrained types.
5481 -- In addition Component_Size is an exception since it is possibly
5482 -- foldable, even though it is never static, and it does apply to
5483 -- unconstrained arrays. Furthermore, it is essential to fold this
5484 -- in the packed case, since otherwise the value will be incorrect.
5486 elsif Id
= Attribute_Definite
5488 Id
= Attribute_Has_Access_Values
5490 Id
= Attribute_Has_Discriminants
5492 Id
= Attribute_Has_Tagged_Values
5494 Id
= Attribute_Type_Class
5496 Id
= Attribute_Unconstrained_Array
5498 Id
= Attribute_Component_Size
5503 if not Is_Constrained
(P_Type
)
5504 or else (Id
/= Attribute_First
and then
5505 Id
/= Attribute_Last
and then
5506 Id
/= Attribute_Length
)
5512 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
5513 -- scalar case, we hold off on enforcing staticness, since there are
5514 -- cases which we can fold at compile time even though they are not
5515 -- static (e.g. 'Length applied to a static index, even though other
5516 -- non-static indexes make the array type non-static). This is only
5517 -- an optimization, but it falls out essentially free, so why not.
5518 -- Again we compute the variable Static for easy reference later
5519 -- (note that no array attributes are static in Ada 83).
5521 Static
:= Ada_Version
>= Ada_95
5522 and then Statically_Denotes_Entity
(P
);
5528 N
:= First_Index
(P_Type
);
5529 while Present
(N
) loop
5530 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
5532 -- If however the index type is generic, attributes cannot
5535 if Is_Generic_Type
(Etype
(N
))
5536 and then Id
/= Attribute_Component_Size
5546 -- Check any expressions that are present. Note that these expressions,
5547 -- depending on the particular attribute type, are either part of the
5548 -- attribute designator, or they are arguments in a case where the
5549 -- attribute reference returns a function. In the latter case, the
5550 -- rule in (RM 4.9(22)) applies and in particular requires the type
5551 -- of the expressions to be scalar in order for the attribute to be
5552 -- considered to be static.
5559 while Present
(E
) loop
5561 -- If expression is not static, then the attribute reference
5562 -- result certainly cannot be static.
5564 if not Is_Static_Expression
(E
) then
5568 -- If the result is not known at compile time, or is not of
5569 -- a scalar type, then the result is definitely not static,
5570 -- so we can quit now.
5572 if not Compile_Time_Known_Value
(E
)
5573 or else not Is_Scalar_Type
(Etype
(E
))
5575 -- An odd special case, if this is a Pos attribute, this
5576 -- is where we need to apply a range check since it does
5577 -- not get done anywhere else.
5579 if Id
= Attribute_Pos
then
5580 if Is_Integer_Type
(Etype
(E
)) then
5581 Apply_Range_Check
(E
, Etype
(N
));
5588 -- If the expression raises a constraint error, then so does
5589 -- the attribute reference. We keep going in this case because
5590 -- we are still interested in whether the attribute reference
5591 -- is static even if it is not static.
5593 elsif Raises_Constraint_Error
(E
) then
5594 Set_Raises_Constraint_Error
(N
);
5600 if Raises_Constraint_Error
(Prefix
(N
)) then
5605 -- Deal with the case of a static attribute reference that raises
5606 -- constraint error. The Raises_Constraint_Error flag will already
5607 -- have been set, and the Static flag shows whether the attribute
5608 -- reference is static. In any case we certainly can't fold such an
5609 -- attribute reference.
5611 -- Note that the rewriting of the attribute node with the constraint
5612 -- error node is essential in this case, because otherwise Gigi might
5613 -- blow up on one of the attributes it never expects to see.
5615 -- The constraint_error node must have the type imposed by the context,
5616 -- to avoid spurious errors in the enclosing expression.
5618 if Raises_Constraint_Error
(N
) then
5620 Make_Raise_Constraint_Error
(Sloc
(N
),
5621 Reason
=> CE_Range_Check_Failed
);
5622 Set_Etype
(CE_Node
, Etype
(N
));
5623 Set_Raises_Constraint_Error
(CE_Node
);
5625 Rewrite
(N
, Relocate_Node
(CE_Node
));
5626 Set_Is_Static_Expression
(N
, Static
);
5630 -- At this point we have a potentially foldable attribute reference.
5631 -- If Static is set, then the attribute reference definitely obeys
5632 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5633 -- folded. If Static is not set, then the attribute may or may not
5634 -- be foldable, and the individual attribute processing routines
5635 -- test Static as required in cases where it makes a difference.
5637 -- In the case where Static is not set, we do know that all the
5638 -- expressions present are at least known at compile time (we
5639 -- assumed above that if this was not the case, then there was
5640 -- no hope of static evaluation). However, we did not require
5641 -- that the bounds of the prefix type be compile time known,
5642 -- let alone static). That's because there are many attributes
5643 -- that can be computed at compile time on non-static subtypes,
5644 -- even though such references are not static expressions.
5652 when Attribute_Adjacent
=>
5655 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5661 when Attribute_Aft
=>
5662 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5668 when Attribute_Alignment
=> Alignment_Block
: declare
5669 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5672 -- Fold if alignment is set and not otherwise
5674 if Known_Alignment
(P_TypeA
) then
5675 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5677 end Alignment_Block
;
5683 -- Can only be folded in No_Ast_Handler case
5685 when Attribute_AST_Entry
=>
5686 if not Is_AST_Entry
(P_Entity
) then
5688 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5697 -- Bit can never be folded
5699 when Attribute_Bit
=>
5706 -- Body_version can never be static
5708 when Attribute_Body_Version
=>
5715 when Attribute_Ceiling
=>
5717 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5719 --------------------
5720 -- Component_Size --
5721 --------------------
5723 when Attribute_Component_Size
=>
5724 if Known_Static_Component_Size
(P_Type
) then
5725 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5732 when Attribute_Compose
=>
5735 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5742 -- Constrained is never folded for now, there may be cases that
5743 -- could be handled at compile time. To be looked at later.
5745 when Attribute_Constrained
=>
5752 when Attribute_Copy_Sign
=>
5755 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5761 when Attribute_Delta
=>
5762 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5768 when Attribute_Definite
=>
5769 Rewrite
(N
, New_Occurrence_Of
(
5770 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5771 Analyze_And_Resolve
(N
, Standard_Boolean
);
5777 when Attribute_Denorm
=>
5779 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5785 when Attribute_Digits
=>
5786 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5792 when Attribute_Emax
=>
5794 -- Ada 83 attribute is defined as (RM83 3.5.8)
5796 -- T'Emax = 4 * T'Mantissa
5798 Fold_Uint
(N
, 4 * Mantissa
, True);
5804 when Attribute_Enum_Rep
=>
5806 -- For an enumeration type with a non-standard representation use
5807 -- the Enumeration_Rep field of the proper constant. Note that this
5808 -- will not work for types Character/Wide_[Wide-]Character, since no
5809 -- real entities are created for the enumeration literals, but that
5810 -- does not matter since these two types do not have non-standard
5811 -- representations anyway.
5813 if Is_Enumeration_Type
(P_Type
)
5814 and then Has_Non_Standard_Rep
(P_Type
)
5816 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5818 -- For enumeration types with standard representations and all
5819 -- other cases (i.e. all integer and modular types), Enum_Rep
5820 -- is equivalent to Pos.
5823 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5830 when Attribute_Enum_Val
=> Enum_Val
: declare
5834 -- We have something like Enum_Type'Enum_Val (23), so search for a
5835 -- corresponding value in the list of Enum_Rep values for the type.
5837 Lit
:= First_Literal
(P_Base_Type
);
5839 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
5840 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
5847 Apply_Compile_Time_Constraint_Error
5848 (N
, "no representation value matches",
5849 CE_Range_Check_Failed
,
5850 Warn
=> not Static
);
5860 when Attribute_Epsilon
=>
5862 -- Ada 83 attribute is defined as (RM83 3.5.8)
5864 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5866 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5872 when Attribute_Exponent
=>
5874 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5880 when Attribute_First
=> First_Attr
:
5884 if Compile_Time_Known_Value
(Lo_Bound
) then
5885 if Is_Real_Type
(P_Type
) then
5886 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5888 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5897 when Attribute_Fixed_Value
=>
5904 when Attribute_Floor
=>
5906 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5912 when Attribute_Fore
=>
5913 if Compile_Time_Known_Bounds
(P_Type
) then
5914 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5921 when Attribute_Fraction
=>
5923 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5925 -----------------------
5926 -- Has_Access_Values --
5927 -----------------------
5929 when Attribute_Has_Access_Values
=>
5930 Rewrite
(N
, New_Occurrence_Of
5931 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5932 Analyze_And_Resolve
(N
, Standard_Boolean
);
5934 -----------------------
5935 -- Has_Discriminants --
5936 -----------------------
5938 when Attribute_Has_Discriminants
=>
5939 Rewrite
(N
, New_Occurrence_Of
(
5940 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5941 Analyze_And_Resolve
(N
, Standard_Boolean
);
5943 -----------------------
5944 -- Has_Tagged_Values --
5945 -----------------------
5947 when Attribute_Has_Tagged_Values
=>
5948 Rewrite
(N
, New_Occurrence_Of
5949 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
5950 Analyze_And_Resolve
(N
, Standard_Boolean
);
5956 when Attribute_Identity
=>
5963 -- Image is a scalar attribute, but is never static, because it is
5964 -- not a static function (having a non-scalar argument (RM 4.9(22))
5965 -- However, we can constant-fold the image of an enumeration literal
5966 -- if names are available.
5968 when Attribute_Image
=>
5969 if Is_Entity_Name
(E1
)
5970 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
5971 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
5972 and then not Global_Discard_Names
5975 Lit
: constant Entity_Id
:= Entity
(E1
);
5979 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
5980 Set_Casing
(All_Upper_Case
);
5981 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
5983 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
5984 Analyze_And_Resolve
(N
, Standard_String
);
5985 Set_Is_Static_Expression
(N
, False);
5993 -- Img is a scalar attribute, but is never static, because it is
5994 -- not a static function (having a non-scalar argument (RM 4.9(22))
5996 when Attribute_Img
=>
6003 -- We never try to fold Integer_Value (though perhaps we could???)
6005 when Attribute_Integer_Value
=>
6012 -- Invalid_Value is a scalar attribute that is never static, because
6013 -- the value is by design out of range.
6015 when Attribute_Invalid_Value
=>
6022 when Attribute_Large
=>
6024 -- For fixed-point, we use the identity:
6026 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
6028 if Is_Fixed_Point_Type
(P_Type
) then
6030 Make_Op_Multiply
(Loc
,
6032 Make_Op_Subtract
(Loc
,
6036 Make_Real_Literal
(Loc
, Ureal_2
),
6038 Make_Attribute_Reference
(Loc
,
6040 Attribute_Name
=> Name_Mantissa
)),
6041 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
6044 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
6046 Analyze_And_Resolve
(N
, C_Type
);
6048 -- Floating-point (Ada 83 compatibility)
6051 -- Ada 83 attribute is defined as (RM83 3.5.8)
6053 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
6057 -- T'Emax = 4 * T'Mantissa
6060 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
6068 when Attribute_Last
=> Last
:
6072 if Compile_Time_Known_Value
(Hi_Bound
) then
6073 if Is_Real_Type
(P_Type
) then
6074 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
6076 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
6085 when Attribute_Leading_Part
=>
6087 Eval_Fat
.Leading_Part
6088 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6094 when Attribute_Length
=> Length
: declare
6098 -- In the case of a generic index type, the bounds may
6099 -- appear static but the computation is not meaningful,
6100 -- and may generate a spurious warning.
6102 Ind
:= First_Index
(P_Type
);
6104 while Present
(Ind
) loop
6105 if Is_Generic_Type
(Etype
(Ind
)) then
6114 if Compile_Time_Known_Value
(Lo_Bound
)
6115 and then Compile_Time_Known_Value
(Hi_Bound
)
6118 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
6127 when Attribute_Machine
=>
6130 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
6137 when Attribute_Machine_Emax
=>
6138 Float_Attribute_Universal_Integer
(
6146 AAMPL_Machine_Emax
);
6152 when Attribute_Machine_Emin
=>
6153 Float_Attribute_Universal_Integer
(
6161 AAMPL_Machine_Emin
);
6163 ----------------------
6164 -- Machine_Mantissa --
6165 ----------------------
6167 when Attribute_Machine_Mantissa
=>
6168 Float_Attribute_Universal_Integer
(
6169 IEEES_Machine_Mantissa
,
6170 IEEEL_Machine_Mantissa
,
6171 IEEEX_Machine_Mantissa
,
6172 VAXFF_Machine_Mantissa
,
6173 VAXDF_Machine_Mantissa
,
6174 VAXGF_Machine_Mantissa
,
6175 AAMPS_Machine_Mantissa
,
6176 AAMPL_Machine_Mantissa
);
6178 -----------------------
6179 -- Machine_Overflows --
6180 -----------------------
6182 when Attribute_Machine_Overflows
=>
6184 -- Always true for fixed-point
6186 if Is_Fixed_Point_Type
(P_Type
) then
6187 Fold_Uint
(N
, True_Value
, True);
6189 -- Floating point case
6193 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
6201 when Attribute_Machine_Radix
=>
6202 if Is_Fixed_Point_Type
(P_Type
) then
6203 if Is_Decimal_Fixed_Point_Type
(P_Type
)
6204 and then Machine_Radix_10
(P_Type
)
6206 Fold_Uint
(N
, Uint_10
, True);
6208 Fold_Uint
(N
, Uint_2
, True);
6211 -- All floating-point type always have radix 2
6214 Fold_Uint
(N
, Uint_2
, True);
6217 ----------------------
6218 -- Machine_Rounding --
6219 ----------------------
6221 -- Note: for the folding case, it is fine to treat Machine_Rounding
6222 -- exactly the same way as Rounding, since this is one of the allowed
6223 -- behaviors, and performance is not an issue here. It might be a bit
6224 -- better to give the same result as it would give at run-time, even
6225 -- though the non-determinism is certainly permitted.
6227 when Attribute_Machine_Rounding
=>
6229 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6231 --------------------
6232 -- Machine_Rounds --
6233 --------------------
6235 when Attribute_Machine_Rounds
=>
6237 -- Always False for fixed-point
6239 if Is_Fixed_Point_Type
(P_Type
) then
6240 Fold_Uint
(N
, False_Value
, True);
6242 -- Else yield proper floating-point result
6246 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
6253 -- Note: Machine_Size is identical to Object_Size
6255 when Attribute_Machine_Size
=> Machine_Size
: declare
6256 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6259 if Known_Esize
(P_TypeA
) then
6260 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6268 when Attribute_Mantissa
=>
6270 -- Fixed-point mantissa
6272 if Is_Fixed_Point_Type
(P_Type
) then
6274 -- Compile time foldable case
6276 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
6278 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
6280 -- The calculation of the obsolete Ada 83 attribute Mantissa
6281 -- is annoying, because of AI00143, quoted here:
6283 -- !question 84-01-10
6285 -- Consider the model numbers for F:
6287 -- type F is delta 1.0 range -7.0 .. 8.0;
6289 -- The wording requires that F'MANTISSA be the SMALLEST
6290 -- integer number for which each bound of the specified
6291 -- range is either a model number or lies at most small
6292 -- distant from a model number. This means F'MANTISSA
6293 -- is required to be 3 since the range -7.0 .. 7.0 fits
6294 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
6295 -- number, namely, 7. Is this analysis correct? Note that
6296 -- this implies the upper bound of the range is not
6297 -- represented as a model number.
6299 -- !response 84-03-17
6301 -- The analysis is correct. The upper and lower bounds for
6302 -- a fixed point type can lie outside the range of model
6313 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
6314 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
6315 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
6316 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
6318 -- If the Bound is exactly a model number, i.e. a multiple
6319 -- of Small, then we back it off by one to get the integer
6320 -- value that must be representable.
6322 if Small_Value
(P_Type
) * Max_Man
= Bound
then
6323 Max_Man
:= Max_Man
- 1;
6326 -- Now find corresponding size = Mantissa value
6329 while 2 ** Siz
< Max_Man
loop
6333 Fold_Uint
(N
, Siz
, True);
6337 -- The case of dynamic bounds cannot be evaluated at compile
6338 -- time. Instead we use a runtime routine (see Exp_Attr).
6343 -- Floating-point Mantissa
6346 Fold_Uint
(N
, Mantissa
, True);
6353 when Attribute_Max
=> Max
:
6355 if Is_Real_Type
(P_Type
) then
6357 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6359 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
6363 ----------------------------------
6364 -- Max_Size_In_Storage_Elements --
6365 ----------------------------------
6367 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
6368 -- Storage_Unit boundary. We can fold any cases for which the size
6369 -- is known by the front end.
6371 when Attribute_Max_Size_In_Storage_Elements
=>
6372 if Known_Esize
(P_Type
) then
6374 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
6375 System_Storage_Unit
,
6379 --------------------
6380 -- Mechanism_Code --
6381 --------------------
6383 when Attribute_Mechanism_Code
=>
6387 Mech
: Mechanism_Type
;
6391 Mech
:= Mechanism
(P_Entity
);
6394 Val
:= UI_To_Int
(Expr_Value
(E1
));
6396 Formal
:= First_Formal
(P_Entity
);
6397 for J
in 1 .. Val
- 1 loop
6398 Next_Formal
(Formal
);
6400 Mech
:= Mechanism
(Formal
);
6404 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
6412 when Attribute_Min
=> Min
:
6414 if Is_Real_Type
(P_Type
) then
6416 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6419 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
6427 when Attribute_Mod
=>
6429 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
6435 when Attribute_Model
=>
6437 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6443 when Attribute_Model_Emin
=>
6444 Float_Attribute_Universal_Integer
(
6458 when Attribute_Model_Epsilon
=>
6459 Float_Attribute_Universal_Real
(
6460 IEEES_Model_Epsilon
'Universal_Literal_String,
6461 IEEEL_Model_Epsilon
'Universal_Literal_String,
6462 IEEEX_Model_Epsilon
'Universal_Literal_String,
6463 VAXFF_Model_Epsilon
'Universal_Literal_String,
6464 VAXDF_Model_Epsilon
'Universal_Literal_String,
6465 VAXGF_Model_Epsilon
'Universal_Literal_String,
6466 AAMPS_Model_Epsilon
'Universal_Literal_String,
6467 AAMPL_Model_Epsilon
'Universal_Literal_String);
6469 --------------------
6470 -- Model_Mantissa --
6471 --------------------
6473 when Attribute_Model_Mantissa
=>
6474 Float_Attribute_Universal_Integer
(
6475 IEEES_Model_Mantissa
,
6476 IEEEL_Model_Mantissa
,
6477 IEEEX_Model_Mantissa
,
6478 VAXFF_Model_Mantissa
,
6479 VAXDF_Model_Mantissa
,
6480 VAXGF_Model_Mantissa
,
6481 AAMPS_Model_Mantissa
,
6482 AAMPL_Model_Mantissa
);
6488 when Attribute_Model_Small
=>
6489 Float_Attribute_Universal_Real
(
6490 IEEES_Model_Small
'Universal_Literal_String,
6491 IEEEL_Model_Small
'Universal_Literal_String,
6492 IEEEX_Model_Small
'Universal_Literal_String,
6493 VAXFF_Model_Small
'Universal_Literal_String,
6494 VAXDF_Model_Small
'Universal_Literal_String,
6495 VAXGF_Model_Small
'Universal_Literal_String,
6496 AAMPS_Model_Small
'Universal_Literal_String,
6497 AAMPL_Model_Small
'Universal_Literal_String);
6503 when Attribute_Modulus
=>
6504 Fold_Uint
(N
, Modulus
(P_Type
), True);
6506 --------------------
6507 -- Null_Parameter --
6508 --------------------
6510 -- Cannot fold, we know the value sort of, but the whole point is
6511 -- that there is no way to talk about this imaginary value except
6512 -- by using the attribute, so we leave it the way it is.
6514 when Attribute_Null_Parameter
=>
6521 -- The Object_Size attribute for a type returns the Esize of the
6522 -- type and can be folded if this value is known.
6524 when Attribute_Object_Size
=> Object_Size
: declare
6525 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6528 if Known_Esize
(P_TypeA
) then
6529 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6533 -------------------------
6534 -- Passed_By_Reference --
6535 -------------------------
6537 -- Scalar types are never passed by reference
6539 when Attribute_Passed_By_Reference
=>
6540 Fold_Uint
(N
, False_Value
, True);
6546 when Attribute_Pos
=>
6547 Fold_Uint
(N
, Expr_Value
(E1
), True);
6553 when Attribute_Pred
=> Pred
:
6555 -- Floating-point case
6557 if Is_Floating_Point_Type
(P_Type
) then
6559 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6563 elsif Is_Fixed_Point_Type
(P_Type
) then
6565 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
6567 -- Modular integer case (wraps)
6569 elsif Is_Modular_Integer_Type
(P_Type
) then
6570 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
6572 -- Other scalar cases
6575 pragma Assert
(Is_Scalar_Type
(P_Type
));
6577 if Is_Enumeration_Type
(P_Type
)
6578 and then Expr_Value
(E1
) =
6579 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6581 Apply_Compile_Time_Constraint_Error
6582 (N
, "Pred of `&''First`",
6583 CE_Overflow_Check_Failed
,
6585 Warn
=> not Static
);
6591 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
6599 -- No processing required, because by this stage, Range has been
6600 -- replaced by First .. Last, so this branch can never be taken.
6602 when Attribute_Range
=>
6603 raise Program_Error
;
6609 when Attribute_Range_Length
=>
6612 if Compile_Time_Known_Value
(Hi_Bound
)
6613 and then Compile_Time_Known_Value
(Lo_Bound
)
6617 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
6625 when Attribute_Remainder
=> Remainder
: declare
6626 X
: constant Ureal
:= Expr_Value_R
(E1
);
6627 Y
: constant Ureal
:= Expr_Value_R
(E2
);
6630 if UR_Is_Zero
(Y
) then
6631 Apply_Compile_Time_Constraint_Error
6632 (N
, "division by zero in Remainder",
6633 CE_Overflow_Check_Failed
,
6634 Warn
=> not Static
);
6640 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
6647 when Attribute_Round
=> Round
:
6653 -- First we get the (exact result) in units of small
6655 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
6657 -- Now round that exactly to an integer
6659 Si
:= UR_To_Uint
(Sr
);
6661 -- Finally the result is obtained by converting back to real
6663 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
6670 when Attribute_Rounding
=>
6672 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6678 when Attribute_Safe_Emax
=>
6679 Float_Attribute_Universal_Integer
(
6693 when Attribute_Safe_First
=>
6694 Float_Attribute_Universal_Real
(
6695 IEEES_Safe_First
'Universal_Literal_String,
6696 IEEEL_Safe_First
'Universal_Literal_String,
6697 IEEEX_Safe_First
'Universal_Literal_String,
6698 VAXFF_Safe_First
'Universal_Literal_String,
6699 VAXDF_Safe_First
'Universal_Literal_String,
6700 VAXGF_Safe_First
'Universal_Literal_String,
6701 AAMPS_Safe_First
'Universal_Literal_String,
6702 AAMPL_Safe_First
'Universal_Literal_String);
6708 when Attribute_Safe_Large
=>
6709 if Is_Fixed_Point_Type
(P_Type
) then
6711 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
6713 Float_Attribute_Universal_Real
(
6714 IEEES_Safe_Large
'Universal_Literal_String,
6715 IEEEL_Safe_Large
'Universal_Literal_String,
6716 IEEEX_Safe_Large
'Universal_Literal_String,
6717 VAXFF_Safe_Large
'Universal_Literal_String,
6718 VAXDF_Safe_Large
'Universal_Literal_String,
6719 VAXGF_Safe_Large
'Universal_Literal_String,
6720 AAMPS_Safe_Large
'Universal_Literal_String,
6721 AAMPL_Safe_Large
'Universal_Literal_String);
6728 when Attribute_Safe_Last
=>
6729 Float_Attribute_Universal_Real
(
6730 IEEES_Safe_Last
'Universal_Literal_String,
6731 IEEEL_Safe_Last
'Universal_Literal_String,
6732 IEEEX_Safe_Last
'Universal_Literal_String,
6733 VAXFF_Safe_Last
'Universal_Literal_String,
6734 VAXDF_Safe_Last
'Universal_Literal_String,
6735 VAXGF_Safe_Last
'Universal_Literal_String,
6736 AAMPS_Safe_Last
'Universal_Literal_String,
6737 AAMPL_Safe_Last
'Universal_Literal_String);
6743 when Attribute_Safe_Small
=>
6745 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6746 -- for fixed-point, since is the same as Small, but we implement
6747 -- it for backwards compatibility.
6749 if Is_Fixed_Point_Type
(P_Type
) then
6750 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6752 -- Ada 83 Safe_Small for floating-point cases
6755 Float_Attribute_Universal_Real
(
6756 IEEES_Safe_Small
'Universal_Literal_String,
6757 IEEEL_Safe_Small
'Universal_Literal_String,
6758 IEEEX_Safe_Small
'Universal_Literal_String,
6759 VAXFF_Safe_Small
'Universal_Literal_String,
6760 VAXDF_Safe_Small
'Universal_Literal_String,
6761 VAXGF_Safe_Small
'Universal_Literal_String,
6762 AAMPS_Safe_Small
'Universal_Literal_String,
6763 AAMPL_Safe_Small
'Universal_Literal_String);
6770 when Attribute_Scale
=>
6771 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6777 when Attribute_Scaling
=>
6780 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6786 when Attribute_Signed_Zeros
=>
6788 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6794 -- Size attribute returns the RM size. All scalar types can be folded,
6795 -- as well as any types for which the size is known by the front end,
6796 -- including any type for which a size attribute is specified.
6798 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6799 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6802 if RM_Size
(P_TypeA
) /= Uint_0
then
6806 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6808 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6811 -- If a size clause applies, then use the size from it.
6812 -- This is one of the rare cases where we can use the
6813 -- Size_Clause field for a subtype when Has_Size_Clause
6814 -- is False. Consider:
6816 -- type x is range 1 .. 64;
6817 -- for x'size use 12;
6818 -- subtype y is x range 0 .. 3;
6820 -- Here y has a size clause inherited from x, but normally
6821 -- it does not apply, and y'size is 2. However, y'VADS_Size
6822 -- is indeed 12 and not 2.
6825 and then Is_OK_Static_Expression
(Expression
(S
))
6827 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6829 -- If no size is specified, then we simply use the object
6830 -- size in the VADS_Size case (e.g. Natural'Size is equal
6831 -- to Integer'Size, not one less).
6834 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6838 -- Normal case (Size) in which case we want the RM_Size
6843 Static
and then Is_Discrete_Type
(P_TypeA
));
6852 when Attribute_Small
=>
6854 -- The floating-point case is present only for Ada 83 compatibility.
6855 -- Note that strictly this is an illegal addition, since we are
6856 -- extending an Ada 95 defined attribute, but we anticipate an
6857 -- ARG ruling that will permit this.
6859 if Is_Floating_Point_Type
(P_Type
) then
6861 -- Ada 83 attribute is defined as (RM83 3.5.8)
6863 -- T'Small = 2.0**(-T'Emax - 1)
6867 -- T'Emax = 4 * T'Mantissa
6869 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6871 -- Normal Ada 95 fixed-point case
6874 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6881 when Attribute_Stream_Size
=>
6888 when Attribute_Succ
=> Succ
:
6890 -- Floating-point case
6892 if Is_Floating_Point_Type
(P_Type
) then
6894 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6898 elsif Is_Fixed_Point_Type
(P_Type
) then
6900 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6902 -- Modular integer case (wraps)
6904 elsif Is_Modular_Integer_Type
(P_Type
) then
6905 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6907 -- Other scalar cases
6910 pragma Assert
(Is_Scalar_Type
(P_Type
));
6912 if Is_Enumeration_Type
(P_Type
)
6913 and then Expr_Value
(E1
) =
6914 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6916 Apply_Compile_Time_Constraint_Error
6917 (N
, "Succ of `&''Last`",
6918 CE_Overflow_Check_Failed
,
6920 Warn
=> not Static
);
6925 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6934 when Attribute_Truncation
=>
6936 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6942 when Attribute_Type_Class
=> Type_Class
: declare
6943 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6947 if Is_Descendent_Of_Address
(Typ
) then
6948 Id
:= RE_Type_Class_Address
;
6950 elsif Is_Enumeration_Type
(Typ
) then
6951 Id
:= RE_Type_Class_Enumeration
;
6953 elsif Is_Integer_Type
(Typ
) then
6954 Id
:= RE_Type_Class_Integer
;
6956 elsif Is_Fixed_Point_Type
(Typ
) then
6957 Id
:= RE_Type_Class_Fixed_Point
;
6959 elsif Is_Floating_Point_Type
(Typ
) then
6960 Id
:= RE_Type_Class_Floating_Point
;
6962 elsif Is_Array_Type
(Typ
) then
6963 Id
:= RE_Type_Class_Array
;
6965 elsif Is_Record_Type
(Typ
) then
6966 Id
:= RE_Type_Class_Record
;
6968 elsif Is_Access_Type
(Typ
) then
6969 Id
:= RE_Type_Class_Access
;
6971 elsif Is_Enumeration_Type
(Typ
) then
6972 Id
:= RE_Type_Class_Enumeration
;
6974 elsif Is_Task_Type
(Typ
) then
6975 Id
:= RE_Type_Class_Task
;
6977 -- We treat protected types like task types. It would make more
6978 -- sense to have another enumeration value, but after all the
6979 -- whole point of this feature is to be exactly DEC compatible,
6980 -- and changing the type Type_Class would not meet this requirement.
6982 elsif Is_Protected_Type
(Typ
) then
6983 Id
:= RE_Type_Class_Task
;
6985 -- Not clear if there are any other possibilities, but if there
6986 -- are, then we will treat them as the address case.
6989 Id
:= RE_Type_Class_Address
;
6992 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6995 -----------------------
6996 -- Unbiased_Rounding --
6997 -----------------------
6999 when Attribute_Unbiased_Rounding
=>
7001 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
7004 -------------------------
7005 -- Unconstrained_Array --
7006 -------------------------
7008 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
7009 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7012 Rewrite
(N
, New_Occurrence_Of
(
7014 Is_Array_Type
(P_Type
)
7015 and then not Is_Constrained
(Typ
)), Loc
));
7017 -- Analyze and resolve as boolean, note that this attribute is
7018 -- a static attribute in GNAT.
7020 Analyze_And_Resolve
(N
, Standard_Boolean
);
7022 end Unconstrained_Array
;
7028 -- Processing is shared with Size
7034 when Attribute_Val
=> Val
:
7036 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
7038 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
7040 Apply_Compile_Time_Constraint_Error
7041 (N
, "Val expression out of range",
7042 CE_Range_Check_Failed
,
7043 Warn
=> not Static
);
7049 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7057 -- The Value_Size attribute for a type returns the RM size of the
7058 -- type. This an always be folded for scalar types, and can also
7059 -- be folded for non-scalar types if the size is set.
7061 when Attribute_Value_Size
=> Value_Size
: declare
7062 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7064 if RM_Size
(P_TypeA
) /= Uint_0
then
7065 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
7073 -- Version can never be static
7075 when Attribute_Version
=>
7082 -- Wide_Image is a scalar attribute, but is never static, because it
7083 -- is not a static function (having a non-scalar argument (RM 4.9(22))
7085 when Attribute_Wide_Image
=>
7088 ---------------------
7089 -- Wide_Wide_Image --
7090 ---------------------
7092 -- Wide_Wide_Image is a scalar attribute but is never static, because it
7093 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
7095 when Attribute_Wide_Wide_Image
=>
7098 ---------------------
7099 -- Wide_Wide_Width --
7100 ---------------------
7102 -- Processing for Wide_Wide_Width is combined with Width
7108 -- Processing for Wide_Width is combined with Width
7114 -- This processing also handles the case of Wide_[Wide_]Width
7116 when Attribute_Width |
7117 Attribute_Wide_Width |
7118 Attribute_Wide_Wide_Width
=> Width
:
7120 if Compile_Time_Known_Bounds
(P_Type
) then
7122 -- Floating-point types
7124 if Is_Floating_Point_Type
(P_Type
) then
7126 -- Width is zero for a null range (RM 3.5 (38))
7128 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
7129 Expr_Value_R
(Type_Low_Bound
(P_Type
))
7131 Fold_Uint
(N
, Uint_0
, True);
7134 -- For floating-point, we have +N.dddE+nnn where length
7135 -- of ddd is determined by type'Digits - 1, but is one
7136 -- if Digits is one (RM 3.5 (33)).
7138 -- nnn is set to 2 for Short_Float and Float (32 bit
7139 -- floats), and 3 for Long_Float and Long_Long_Float.
7140 -- For machines where Long_Long_Float is the IEEE
7141 -- extended precision type, the exponent takes 4 digits.
7145 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
7148 if Esize
(P_Type
) <= 32 then
7150 elsif Esize
(P_Type
) = 64 then
7156 Fold_Uint
(N
, UI_From_Int
(Len
), True);
7160 -- Fixed-point types
7162 elsif Is_Fixed_Point_Type
(P_Type
) then
7164 -- Width is zero for a null range (RM 3.5 (38))
7166 if Expr_Value
(Type_High_Bound
(P_Type
)) <
7167 Expr_Value
(Type_Low_Bound
(P_Type
))
7169 Fold_Uint
(N
, Uint_0
, True);
7171 -- The non-null case depends on the specific real type
7174 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
7177 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
7184 R
: constant Entity_Id
:= Root_Type
(P_Type
);
7185 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7186 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7199 -- Width for types derived from Standard.Character
7200 -- and Standard.Wide_[Wide_]Character.
7202 elsif Is_Standard_Character_Type
(P_Type
) then
7205 -- Set W larger if needed
7207 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
7209 -- All wide characters look like Hex_hhhhhhhh
7215 C
:= Character'Val (J
);
7217 -- Test for all cases where Character'Image
7218 -- yields an image that is longer than three
7219 -- characters. First the cases of Reserved_xxx
7220 -- names (length = 12).
7223 when Reserved_128 | Reserved_129 |
7224 Reserved_132 | Reserved_153
7228 when BS | HT | LF | VT | FF | CR |
7229 SO | SI | EM | FS | GS | RS |
7230 US | RI | MW | ST | PM
7234 when NUL | SOH | STX | ETX | EOT |
7235 ENQ | ACK | BEL | DLE | DC1 |
7236 DC2 | DC3 | DC4 | NAK | SYN |
7237 ETB | CAN | SUB | ESC | DEL |
7238 BPH | NBH | NEL | SSA | ESA |
7239 HTS | HTJ | VTS | PLD | PLU |
7240 SS2 | SS3 | DCS | PU1 | PU2 |
7241 STS | CCH | SPA | EPA | SOS |
7242 SCI | CSI | OSC | APC
7246 when Space
.. Tilde |
7247 No_Break_Space
.. LC_Y_Diaeresis
7252 W
:= Int
'Max (W
, Wt
);
7256 -- Width for types derived from Standard.Boolean
7258 elsif R
= Standard_Boolean
then
7265 -- Width for integer types
7267 elsif Is_Integer_Type
(P_Type
) then
7268 T
:= UI_Max
(abs Lo
, abs Hi
);
7276 -- Only remaining possibility is user declared enum type
7279 pragma Assert
(Is_Enumeration_Type
(P_Type
));
7282 L
:= First_Literal
(P_Type
);
7284 while Present
(L
) loop
7286 -- Only pay attention to in range characters
7288 if Lo
<= Enumeration_Pos
(L
)
7289 and then Enumeration_Pos
(L
) <= Hi
7291 -- For Width case, use decoded name
7293 if Id
= Attribute_Width
then
7294 Get_Decoded_Name_String
(Chars
(L
));
7295 Wt
:= Nat
(Name_Len
);
7297 -- For Wide_[Wide_]Width, use encoded name, and
7298 -- then adjust for the encoding.
7301 Get_Name_String
(Chars
(L
));
7303 -- Character literals are always of length 3
7305 if Name_Buffer
(1) = 'Q' then
7308 -- Otherwise loop to adjust for upper/wide chars
7311 Wt
:= Nat
(Name_Len
);
7313 for J
in 1 .. Name_Len
loop
7314 if Name_Buffer
(J
) = 'U' then
7316 elsif Name_Buffer
(J
) = 'W' then
7323 W
:= Int
'Max (W
, Wt
);
7330 Fold_Uint
(N
, UI_From_Int
(W
), True);
7336 -- The following attributes denote function that cannot be folded
7338 when Attribute_From_Any |
7340 Attribute_TypeCode
=>
7343 -- The following attributes can never be folded, and furthermore we
7344 -- should not even have entered the case statement for any of these.
7345 -- Note that in some cases, the values have already been folded as
7346 -- a result of the processing in Analyze_Attribute.
7348 when Attribute_Abort_Signal |
7351 Attribute_Address_Size |
7352 Attribute_Asm_Input |
7353 Attribute_Asm_Output |
7355 Attribute_Bit_Order |
7356 Attribute_Bit_Position |
7357 Attribute_Callable |
7360 Attribute_Code_Address |
7362 Attribute_Default_Bit_Order |
7363 Attribute_Elaborated |
7364 Attribute_Elab_Body |
7365 Attribute_Elab_Spec |
7367 Attribute_External_Tag |
7368 Attribute_Fast_Math |
7369 Attribute_First_Bit |
7371 Attribute_Last_Bit |
7372 Attribute_Maximum_Alignment |
7375 Attribute_Partition_ID |
7376 Attribute_Pool_Address |
7377 Attribute_Position |
7378 Attribute_Priority |
7381 Attribute_Storage_Pool |
7382 Attribute_Storage_Size |
7383 Attribute_Storage_Unit |
7384 Attribute_Stub_Type |
7386 Attribute_Target_Name |
7387 Attribute_Terminated |
7388 Attribute_To_Address |
7389 Attribute_UET_Address |
7390 Attribute_Unchecked_Access |
7391 Attribute_Universal_Literal_String |
7392 Attribute_Unrestricted_Access |
7395 Attribute_Wchar_T_Size |
7396 Attribute_Wide_Value |
7397 Attribute_Wide_Wide_Value |
7398 Attribute_Word_Size |
7401 raise Program_Error
;
7404 -- At the end of the case, one more check. If we did a static evaluation
7405 -- so that the result is now a literal, then set Is_Static_Expression
7406 -- in the constant only if the prefix type is a static subtype. For
7407 -- non-static subtypes, the folding is still OK, but not static.
7409 -- An exception is the GNAT attribute Constrained_Array which is
7410 -- defined to be a static attribute in all cases.
7412 if Nkind_In
(N
, N_Integer_Literal
,
7414 N_Character_Literal
,
7416 or else (Is_Entity_Name
(N
)
7417 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
7419 Set_Is_Static_Expression
(N
, Static
);
7421 -- If this is still an attribute reference, then it has not been folded
7422 -- and that means that its expressions are in a non-static context.
7424 elsif Nkind
(N
) = N_Attribute_Reference
then
7427 -- Note: the else case not covered here are odd cases where the
7428 -- processing has transformed the attribute into something other
7429 -- than a constant. Nothing more to do in such cases.
7436 ------------------------------
7437 -- Is_Anonymous_Tagged_Base --
7438 ------------------------------
7440 function Is_Anonymous_Tagged_Base
7447 Anon
= Current_Scope
7448 and then Is_Itype
(Anon
)
7449 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
7450 end Is_Anonymous_Tagged_Base
;
7452 --------------------------------
7453 -- Name_Implies_Lvalue_Prefix --
7454 --------------------------------
7456 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
7457 pragma Assert
(Is_Attribute_Name
(Nam
));
7459 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
7460 end Name_Implies_Lvalue_Prefix
;
7462 -----------------------
7463 -- Resolve_Attribute --
7464 -----------------------
7466 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
7467 Loc
: constant Source_Ptr
:= Sloc
(N
);
7468 P
: constant Node_Id
:= Prefix
(N
);
7469 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7470 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7471 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7472 Des_Btyp
: Entity_Id
;
7473 Index
: Interp_Index
;
7475 Nom_Subt
: Entity_Id
;
7477 procedure Accessibility_Message
;
7478 -- Error, or warning within an instance, if the static accessibility
7479 -- rules of 3.10.2 are violated.
7481 ---------------------------
7482 -- Accessibility_Message --
7483 ---------------------------
7485 procedure Accessibility_Message
is
7486 Indic
: Node_Id
:= Parent
(Parent
(N
));
7489 -- In an instance, this is a runtime check, but one we
7490 -- know will fail, so generate an appropriate warning.
7492 if In_Instance_Body
then
7494 ("?non-local pointer cannot point to local object", P
);
7496 ("\?Program_Error will be raised at run time", P
);
7498 Make_Raise_Program_Error
(Loc
,
7499 Reason
=> PE_Accessibility_Check_Failed
));
7505 ("non-local pointer cannot point to local object", P
);
7507 -- Check for case where we have a missing access definition
7509 if Is_Record_Type
(Current_Scope
)
7511 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
7512 N_Index_Or_Discriminant_Constraint
)
7514 Indic
:= Parent
(Parent
(N
));
7515 while Present
(Indic
)
7516 and then Nkind
(Indic
) /= N_Subtype_Indication
7518 Indic
:= Parent
(Indic
);
7521 if Present
(Indic
) then
7523 ("\use an access definition for" &
7524 " the access discriminant of&",
7525 N
, Entity
(Subtype_Mark
(Indic
)));
7529 end Accessibility_Message
;
7531 -- Start of processing for Resolve_Attribute
7534 -- If error during analysis, no point in continuing, except for
7535 -- array types, where we get better recovery by using unconstrained
7536 -- indices than nothing at all (see Check_Array_Type).
7539 and then Attr_Id
/= Attribute_First
7540 and then Attr_Id
/= Attribute_Last
7541 and then Attr_Id
/= Attribute_Length
7542 and then Attr_Id
/= Attribute_Range
7547 -- If attribute was universal type, reset to actual type
7549 if Etype
(N
) = Universal_Integer
7550 or else Etype
(N
) = Universal_Real
7555 -- Remaining processing depends on attribute
7563 -- For access attributes, if the prefix denotes an entity, it is
7564 -- interpreted as a name, never as a call. It may be overloaded,
7565 -- in which case resolution uses the profile of the context type.
7566 -- Otherwise prefix must be resolved.
7568 when Attribute_Access
7569 | Attribute_Unchecked_Access
7570 | Attribute_Unrestricted_Access
=>
7574 if Is_Variable
(P
) then
7575 Note_Possible_Modification
(P
, Sure
=> False);
7578 -- The following comes from a query by Adam Beneschan, concerning
7579 -- improper use of universal_access in equality tests involving
7580 -- anonymous access types. Another good reason for 'Ref, but
7581 -- for now disable the test, which breaks several filed tests.
7583 if Ekind
(Typ
) = E_Anonymous_Access_Type
7584 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
7587 Error_Msg_N
("need unique type to resolve 'Access", N
);
7588 Error_Msg_N
("\qualify attribute with some access type", N
);
7591 if Is_Entity_Name
(P
) then
7592 if Is_Overloaded
(P
) then
7593 Get_First_Interp
(P
, Index
, It
);
7594 while Present
(It
.Nam
) loop
7595 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
7596 Set_Entity
(P
, It
.Nam
);
7598 -- The prefix is definitely NOT overloaded anymore at
7599 -- this point, so we reset the Is_Overloaded flag to
7600 -- avoid any confusion when reanalyzing the node.
7602 Set_Is_Overloaded
(P
, False);
7603 Set_Is_Overloaded
(N
, False);
7604 Generate_Reference
(Entity
(P
), P
);
7608 Get_Next_Interp
(Index
, It
);
7611 -- If Prefix is a subprogram name, it is frozen by this
7614 -- If it is a type, there is nothing to resolve.
7615 -- If it is an object, complete its resolution.
7617 elsif Is_Overloadable
(Entity
(P
)) then
7619 -- Avoid insertion of freeze actions in spec expression mode
7621 if not In_Spec_Expression
then
7622 Insert_Actions
(N
, Freeze_Entity
(Entity
(P
), Loc
));
7625 elsif Is_Type
(Entity
(P
)) then
7631 Error_Msg_Name_1
:= Aname
;
7633 if not Is_Entity_Name
(P
) then
7636 elsif Is_Overloadable
(Entity
(P
))
7637 and then Is_Abstract_Subprogram
(Entity
(P
))
7639 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
7640 Set_Etype
(N
, Any_Type
);
7642 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
7643 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
7645 ("prefix of % attribute cannot be enumeration literal",
7649 ("prefix of % attribute cannot be intrinsic", P
);
7652 Set_Etype
(N
, Any_Type
);
7655 -- Assignments, return statements, components of aggregates,
7656 -- generic instantiations will require convention checks if
7657 -- the type is an access to subprogram. Given that there will
7658 -- also be accessibility checks on those, this is where the
7659 -- checks can eventually be centralized ???
7661 if Ekind
(Btyp
) = E_Access_Subprogram_Type
7663 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7665 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7667 -- Deal with convention mismatch
7669 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
7671 ("subprogram & has wrong convention", P
, Entity
(P
));
7674 ("\does not match convention of access type &",
7677 if not Has_Convention_Pragma
(Btyp
) then
7679 ("\probable missing pragma Convention for &",
7684 Check_Subtype_Conformant
7685 (New_Id
=> Entity
(P
),
7686 Old_Id
=> Designated_Type
(Btyp
),
7690 if Attr_Id
= Attribute_Unchecked_Access
then
7691 Error_Msg_Name_1
:= Aname
;
7693 ("attribute% cannot be applied to a subprogram", P
);
7695 elsif Aname
= Name_Unrestricted_Access
then
7696 null; -- Nothing to check
7698 -- Check the static accessibility rule of 3.10.2(32).
7699 -- This rule also applies within the private part of an
7700 -- instantiation. This rule does not apply to anonymous
7701 -- access-to-subprogram types (Ada 2005).
7703 elsif Attr_Id
= Attribute_Access
7704 and then not In_Instance_Body
7705 and then Subprogram_Access_Level
(Entity
(P
)) >
7706 Type_Access_Level
(Btyp
)
7707 and then Ekind
(Btyp
) /=
7708 E_Anonymous_Access_Subprogram_Type
7709 and then Ekind
(Btyp
) /=
7710 E_Anonymous_Access_Protected_Subprogram_Type
7713 ("subprogram must not be deeper than access type", P
);
7715 -- Check the restriction of 3.10.2(32) that disallows the
7716 -- access attribute within a generic body when the ultimate
7717 -- ancestor of the type of the attribute is declared outside
7718 -- of the generic unit and the subprogram is declared within
7719 -- that generic unit. This includes any such attribute that
7720 -- occurs within the body of a generic unit that is a child
7721 -- of the generic unit where the subprogram is declared.
7722 -- The rule also prohibits applying the attribute when the
7723 -- access type is a generic formal access type (since the
7724 -- level of the actual type is not known). This restriction
7725 -- does not apply when the attribute type is an anonymous
7726 -- access-to-subprogram type. Note that this check was
7727 -- revised by AI-229, because the originally Ada 95 rule
7728 -- was too lax. The original rule only applied when the
7729 -- subprogram was declared within the body of the generic,
7730 -- which allowed the possibility of dangling references).
7731 -- The rule was also too strict in some case, in that it
7732 -- didn't permit the access to be declared in the generic
7733 -- spec, whereas the revised rule does (as long as it's not
7736 -- There are a couple of subtleties of the test for applying
7737 -- the check that are worth noting. First, we only apply it
7738 -- when the levels of the subprogram and access type are the
7739 -- same (the case where the subprogram is statically deeper
7740 -- was applied above, and the case where the type is deeper
7741 -- is always safe). Second, we want the check to apply
7742 -- within nested generic bodies and generic child unit
7743 -- bodies, but not to apply to an attribute that appears in
7744 -- the generic unit's specification. This is done by testing
7745 -- that the attribute's innermost enclosing generic body is
7746 -- not the same as the innermost generic body enclosing the
7747 -- generic unit where the subprogram is declared (we don't
7748 -- want the check to apply when the access attribute is in
7749 -- the spec and there's some other generic body enclosing
7750 -- generic). Finally, there's no point applying the check
7751 -- when within an instance, because any violations will have
7752 -- been caught by the compilation of the generic unit.
7754 elsif Attr_Id
= Attribute_Access
7755 and then not In_Instance
7756 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
7757 and then Present
(Enclosing_Generic_Body
(N
))
7758 and then Enclosing_Generic_Body
(N
) /=
7759 Enclosing_Generic_Body
7760 (Enclosing_Generic_Unit
(Entity
(P
)))
7761 and then Subprogram_Access_Level
(Entity
(P
)) =
7762 Type_Access_Level
(Btyp
)
7763 and then Ekind
(Btyp
) /=
7764 E_Anonymous_Access_Subprogram_Type
7765 and then Ekind
(Btyp
) /=
7766 E_Anonymous_Access_Protected_Subprogram_Type
7768 -- The attribute type's ultimate ancestor must be
7769 -- declared within the same generic unit as the
7770 -- subprogram is declared. The error message is
7771 -- specialized to say "ancestor" for the case where
7772 -- the access type is not its own ancestor, since
7773 -- saying simply "access type" would be very confusing.
7775 if Enclosing_Generic_Unit
(Entity
(P
)) /=
7776 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
7779 ("''Access attribute not allowed in generic body",
7782 if Root_Type
(Btyp
) = Btyp
then
7785 "access type & is declared outside " &
7786 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7789 ("\because ancestor of " &
7790 "access type & is declared outside " &
7791 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7795 ("\move ''Access to private part, or " &
7796 "(Ada 2005) use anonymous access type instead of &",
7799 -- If the ultimate ancestor of the attribute's type is
7800 -- a formal type, then the attribute is illegal because
7801 -- the actual type might be declared at a higher level.
7802 -- The error message is specialized to say "ancestor"
7803 -- for the case where the access type is not its own
7804 -- ancestor, since saying simply "access type" would be
7807 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
7808 if Root_Type
(Btyp
) = Btyp
then
7810 ("access type must not be a generic formal type",
7814 ("ancestor access type must not be a generic " &
7821 -- If this is a renaming, an inherited operation, or a
7822 -- subprogram instance, use the original entity. This may make
7823 -- the node type-inconsistent, so this transformation can only
7824 -- be done if the node will not be reanalyzed. In particular,
7825 -- if it is within a default expression, the transformation
7826 -- must be delayed until the default subprogram is created for
7827 -- it, when the enclosing subprogram is frozen.
7829 if Is_Entity_Name
(P
)
7830 and then Is_Overloadable
(Entity
(P
))
7831 and then Present
(Alias
(Entity
(P
)))
7832 and then Expander_Active
7835 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7838 elsif Nkind
(P
) = N_Selected_Component
7839 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
7841 -- Protected operation. If operation is overloaded, must
7842 -- disambiguate. Prefix that denotes protected object itself
7843 -- is resolved with its own type.
7845 if Attr_Id
= Attribute_Unchecked_Access
then
7846 Error_Msg_Name_1
:= Aname
;
7848 ("attribute% cannot be applied to protected operation", P
);
7851 Resolve
(Prefix
(P
));
7852 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
7854 elsif Is_Overloaded
(P
) then
7856 -- Use the designated type of the context to disambiguate
7857 -- Note that this was not strictly conformant to Ada 95,
7858 -- but was the implementation adopted by most Ada 95 compilers.
7859 -- The use of the context type to resolve an Access attribute
7860 -- reference is now mandated in AI-235 for Ada 2005.
7863 Index
: Interp_Index
;
7867 Get_First_Interp
(P
, Index
, It
);
7868 while Present
(It
.Typ
) loop
7869 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
7870 Resolve
(P
, It
.Typ
);
7874 Get_Next_Interp
(Index
, It
);
7881 -- X'Access is illegal if X denotes a constant and the access type
7882 -- is access-to-variable. Same for 'Unchecked_Access. The rule
7883 -- does not apply to 'Unrestricted_Access. If the reference is a
7884 -- default-initialized aggregate component for a self-referential
7885 -- type the reference is legal.
7887 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7888 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7889 or else (Is_Record_Type
(Btyp
)
7891 Present
(Corresponding_Remote_Type
(Btyp
)))
7892 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7893 or else Ekind
(Btyp
)
7894 = E_Anonymous_Access_Protected_Subprogram_Type
7895 or else Is_Access_Constant
(Btyp
)
7896 or else Is_Variable
(P
)
7897 or else Attr_Id
= Attribute_Unrestricted_Access
)
7899 if Is_Entity_Name
(P
)
7900 and then Is_Type
(Entity
(P
))
7902 -- Legality of a self-reference through an access
7903 -- attribute has been verified in Analyze_Access_Attribute.
7907 elsif Comes_From_Source
(N
) then
7908 Error_Msg_F
("access-to-variable designates constant", P
);
7912 Des_Btyp
:= Designated_Type
(Btyp
);
7914 if Ada_Version
>= Ada_05
7915 and then Is_Incomplete_Type
(Des_Btyp
)
7917 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
7918 -- imported entity, and the non-limited view is visible, make
7919 -- use of it. If it is an incomplete subtype, use the base type
7922 if From_With_Type
(Des_Btyp
)
7923 and then Present
(Non_Limited_View
(Des_Btyp
))
7925 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
7927 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
7928 Des_Btyp
:= Etype
(Des_Btyp
);
7932 if (Attr_Id
= Attribute_Access
7934 Attr_Id
= Attribute_Unchecked_Access
)
7935 and then (Ekind
(Btyp
) = E_General_Access_Type
7936 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7938 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7939 -- access types for stand-alone objects, record and array
7940 -- components, and return objects. For a component definition
7941 -- the level is the same of the enclosing composite type.
7943 if Ada_Version
>= Ada_05
7944 and then Is_Local_Anonymous_Access
(Btyp
)
7945 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7946 and then Attr_Id
= Attribute_Access
7948 -- In an instance, this is a runtime check, but one we
7949 -- know will fail, so generate an appropriate warning.
7951 if In_Instance_Body
then
7953 ("?non-local pointer cannot point to local object", P
);
7955 ("\?Program_Error will be raised at run time", P
);
7957 Make_Raise_Program_Error
(Loc
,
7958 Reason
=> PE_Accessibility_Check_Failed
));
7963 ("non-local pointer cannot point to local object", P
);
7967 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7969 ("illegal attribute for discriminant-dependent component",
7973 -- Check static matching rule of 3.10.2(27). Nominal subtype
7974 -- of the prefix must statically match the designated type.
7976 Nom_Subt
:= Etype
(P
);
7978 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7979 Nom_Subt
:= Base_Type
(Nom_Subt
);
7982 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7984 -- If the attribute is in the context of an access
7985 -- parameter, then the prefix is allowed to be of the
7986 -- class-wide type (by AI-127).
7988 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7989 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7990 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7996 Desig
:= Designated_Type
(Typ
);
7998 if Is_Class_Wide_Type
(Desig
) then
7999 Desig
:= Etype
(Desig
);
8002 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
8007 ("type of prefix: & not compatible",
8010 ("\with &, the expected designated type",
8011 P
, Designated_Type
(Typ
));
8016 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
8018 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
8019 and then Is_Class_Wide_Type
(Nom_Subt
))
8022 ("type of prefix: & is not covered", P
, Nom_Subt
);
8024 ("\by &, the expected designated type" &
8025 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
8028 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
8029 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
8030 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
8031 and then Designated_Type
(Typ
) /= Nom_Subt
8033 Apply_Discriminant_Check
8034 (N
, Etype
(Designated_Type
(Typ
)));
8037 -- Ada 2005 (AI-363): Require static matching when designated
8038 -- type has discriminants and a constrained partial view, since
8039 -- in general objects of such types are mutable, so we can't
8040 -- allow the access value to designate a constrained object
8041 -- (because access values must be assumed to designate mutable
8042 -- objects when designated type does not impose a constraint).
8044 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
8047 elsif Has_Discriminants
(Designated_Type
(Typ
))
8048 and then not Is_Constrained
(Des_Btyp
)
8050 (Ada_Version
< Ada_05
8052 not Has_Constrained_Partial_View
8053 (Designated_Type
(Base_Type
(Typ
))))
8059 ("object subtype must statically match "
8060 & "designated subtype", P
);
8062 if Is_Entity_Name
(P
)
8063 and then Is_Array_Type
(Designated_Type
(Typ
))
8066 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
8069 Error_Msg_N
("aliased object has explicit bounds?",
8071 Error_Msg_N
("\declare without bounds"
8072 & " (and with explicit initialization)?", D
);
8073 Error_Msg_N
("\for use with unconstrained access?", D
);
8078 -- Check the static accessibility rule of 3.10.2(28).
8079 -- Note that this check is not performed for the
8080 -- case of an anonymous access type, since the access
8081 -- attribute is always legal in such a context.
8083 if Attr_Id
/= Attribute_Unchecked_Access
8084 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
8085 and then Ekind
(Btyp
) = E_General_Access_Type
8087 Accessibility_Message
;
8092 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
8094 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
8096 if Is_Entity_Name
(P
)
8097 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
8099 Error_Msg_F
("context requires a protected subprogram", P
);
8101 -- Check accessibility of protected object against that of the
8102 -- access type, but only on user code, because the expander
8103 -- creates access references for handlers. If the context is an
8104 -- anonymous_access_to_protected, there are no accessibility
8105 -- checks either. Omit check entirely for Unrestricted_Access.
8107 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
8108 and then Comes_From_Source
(N
)
8109 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
8110 and then Attr_Id
/= Attribute_Unrestricted_Access
8112 Accessibility_Message
;
8116 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
8118 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
8119 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
8121 Error_Msg_F
("context requires a non-protected subprogram", P
);
8124 -- The context cannot be a pool-specific type, but this is a
8125 -- legality rule, not a resolution rule, so it must be checked
8126 -- separately, after possibly disambiguation (see AI-245).
8128 if Ekind
(Btyp
) = E_Access_Type
8129 and then Attr_Id
/= Attribute_Unrestricted_Access
8131 Wrong_Type
(N
, Typ
);
8134 -- The context may be a constrained access type (however ill-
8135 -- advised such subtypes might be) so in order to generate a
8136 -- constraint check when needed set the type of the attribute
8137 -- reference to the base type of the context.
8139 Set_Etype
(N
, Btyp
);
8141 -- Check for incorrect atomic/volatile reference (RM C.6(12))
8143 if Attr_Id
/= Attribute_Unrestricted_Access
then
8144 if Is_Atomic_Object
(P
)
8145 and then not Is_Atomic
(Designated_Type
(Typ
))
8148 ("access to atomic object cannot yield access-to-" &
8149 "non-atomic type", P
);
8151 elsif Is_Volatile_Object
(P
)
8152 and then not Is_Volatile
(Designated_Type
(Typ
))
8155 ("access to volatile object cannot yield access-to-" &
8156 "non-volatile type", P
);
8160 if Is_Entity_Name
(P
) then
8161 Set_Address_Taken
(Entity
(P
));
8163 end Access_Attribute
;
8169 -- Deal with resolving the type for Address attribute, overloading
8170 -- is not permitted here, since there is no context to resolve it.
8172 when Attribute_Address | Attribute_Code_Address
=>
8173 Address_Attribute
: begin
8175 -- To be safe, assume that if the address of a variable is taken,
8176 -- it may be modified via this address, so note modification.
8178 if Is_Variable
(P
) then
8179 Note_Possible_Modification
(P
, Sure
=> False);
8182 if Nkind
(P
) in N_Subexpr
8183 and then Is_Overloaded
(P
)
8185 Get_First_Interp
(P
, Index
, It
);
8186 Get_Next_Interp
(Index
, It
);
8188 if Present
(It
.Nam
) then
8189 Error_Msg_Name_1
:= Aname
;
8191 ("prefix of % attribute cannot be overloaded", P
);
8195 if not Is_Entity_Name
(P
)
8196 or else not Is_Overloadable
(Entity
(P
))
8198 if not Is_Task_Type
(Etype
(P
))
8199 or else Nkind
(P
) = N_Explicit_Dereference
8205 -- If this is the name of a derived subprogram, or that of a
8206 -- generic actual, the address is that of the original entity.
8208 if Is_Entity_Name
(P
)
8209 and then Is_Overloadable
(Entity
(P
))
8210 and then Present
(Alias
(Entity
(P
)))
8213 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
8216 if Is_Entity_Name
(P
) then
8217 Set_Address_Taken
(Entity
(P
));
8220 if Nkind
(P
) = N_Slice
then
8222 -- Arr (X .. Y)'address is identical to Arr (X)'address,
8223 -- even if the array is packed and the slice itself is not
8224 -- addressable. Transform the prefix into an indexed component.
8226 -- Note that the transformation is safe only if we know that
8227 -- the slice is non-null. That is because a null slice can have
8228 -- an out of bounds index value.
8230 -- Right now, gigi blows up if given 'Address on a slice as a
8231 -- result of some incorrect freeze nodes generated by the front
8232 -- end, and this covers up that bug in one case, but the bug is
8233 -- likely still there in the cases not handled by this code ???
8235 -- It's not clear what 'Address *should* return for a null
8236 -- slice with out of bounds indexes, this might be worth an ARG
8239 -- One approach would be to do a length check unconditionally,
8240 -- and then do the transformation below unconditionally, but
8241 -- analyze with checks off, avoiding the problem of the out of
8242 -- bounds index. This approach would interpret the address of
8243 -- an out of bounds null slice as being the address where the
8244 -- array element would be if there was one, which is probably
8245 -- as reasonable an interpretation as any ???
8248 Loc
: constant Source_Ptr
:= Sloc
(P
);
8249 D
: constant Node_Id
:= Discrete_Range
(P
);
8253 if Is_Entity_Name
(D
)
8256 (Type_Low_Bound
(Entity
(D
)),
8257 Type_High_Bound
(Entity
(D
)))
8260 Make_Attribute_Reference
(Loc
,
8261 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
8262 Attribute_Name
=> Name_First
);
8264 elsif Nkind
(D
) = N_Range
8265 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
8267 Lo
:= Low_Bound
(D
);
8273 if Present
(Lo
) then
8275 Make_Indexed_Component
(Loc
,
8276 Prefix
=> Relocate_Node
(Prefix
(P
)),
8277 Expressions
=> New_List
(Lo
)));
8279 Analyze_And_Resolve
(P
);
8283 end Address_Attribute
;
8289 -- Prefix of the AST_Entry attribute is an entry name which must
8290 -- not be resolved, since this is definitely not an entry call.
8292 when Attribute_AST_Entry
=>
8299 -- Prefix of Body_Version attribute can be a subprogram name which
8300 -- must not be resolved, since this is not a call.
8302 when Attribute_Body_Version
=>
8309 -- Prefix of Caller attribute is an entry name which must not
8310 -- be resolved, since this is definitely not an entry call.
8312 when Attribute_Caller
=>
8319 -- Shares processing with Address attribute
8325 -- If the prefix of the Count attribute is an entry name it must not
8326 -- be resolved, since this is definitely not an entry call. However,
8327 -- if it is an element of an entry family, the index itself may
8328 -- have to be resolved because it can be a general expression.
8330 when Attribute_Count
=>
8331 if Nkind
(P
) = N_Indexed_Component
8332 and then Is_Entity_Name
(Prefix
(P
))
8335 Indx
: constant Node_Id
:= First
(Expressions
(P
));
8336 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
8338 Resolve
(Indx
, Entry_Index_Type
(Fam
));
8339 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
8347 -- Prefix of the Elaborated attribute is a subprogram name which
8348 -- must not be resolved, since this is definitely not a call. Note
8349 -- that it is a library unit, so it cannot be overloaded here.
8351 when Attribute_Elaborated
=>
8358 -- Prefix of Enabled attribute is a check name, which must be treated
8359 -- specially and not touched by Resolve.
8361 when Attribute_Enabled
=>
8364 --------------------
8365 -- Mechanism_Code --
8366 --------------------
8368 -- Prefix of the Mechanism_Code attribute is a function name
8369 -- which must not be resolved. Should we check for overloaded ???
8371 when Attribute_Mechanism_Code
=>
8378 -- Most processing is done in sem_dist, after determining the
8379 -- context type. Node is rewritten as a conversion to a runtime call.
8381 when Attribute_Partition_ID
=>
8382 Process_Partition_Id
(N
);
8389 when Attribute_Pool_Address
=>
8396 -- We replace the Range attribute node with a range expression
8397 -- whose bounds are the 'First and 'Last attributes applied to the
8398 -- same prefix. The reason that we do this transformation here
8399 -- instead of in the expander is that it simplifies other parts of
8400 -- the semantic analysis which assume that the Range has been
8401 -- replaced; thus it must be done even when in semantic-only mode
8402 -- (note that the RM specifically mentions this equivalence, we
8403 -- take care that the prefix is only evaluated once).
8405 when Attribute_Range
=> Range_Attribute
:
8411 if not Is_Entity_Name
(P
)
8412 or else not Is_Type
(Entity
(P
))
8418 Make_Attribute_Reference
(Loc
,
8420 Duplicate_Subexpr
(P
, Name_Req
=> True),
8421 Attribute_Name
=> Name_Last
,
8422 Expressions
=> Expressions
(N
));
8425 Make_Attribute_Reference
(Loc
,
8427 Attribute_Name
=> Name_First
,
8428 Expressions
=> Expressions
(N
));
8430 -- If the original was marked as Must_Not_Freeze (see code
8431 -- in Sem_Ch3.Make_Index), then make sure the rewriting
8432 -- does not freeze either.
8434 if Must_Not_Freeze
(N
) then
8435 Set_Must_Not_Freeze
(HB
);
8436 Set_Must_Not_Freeze
(LB
);
8437 Set_Must_Not_Freeze
(Prefix
(HB
));
8438 Set_Must_Not_Freeze
(Prefix
(LB
));
8441 if Raises_Constraint_Error
(Prefix
(N
)) then
8443 -- Preserve Sloc of prefix in the new bounds, so that
8444 -- the posted warning can be removed if we are within
8445 -- unreachable code.
8447 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
8448 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
8451 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
8452 Analyze_And_Resolve
(N
, Typ
);
8454 -- Normally after resolving attribute nodes, Eval_Attribute
8455 -- is called to do any possible static evaluation of the node.
8456 -- However, here since the Range attribute has just been
8457 -- transformed into a range expression it is no longer an
8458 -- attribute node and therefore the call needs to be avoided
8459 -- and is accomplished by simply returning from the procedure.
8462 end Range_Attribute
;
8468 -- We will only come here during the prescan of a spec expression
8469 -- containing a Result attribute. In that case the proper Etype has
8470 -- already been set, and nothing more needs to be done here.
8472 when Attribute_Result
=>
8479 -- Prefix must not be resolved in this case, since it is not a
8480 -- real entity reference. No action of any kind is require!
8482 when Attribute_UET_Address
=>
8485 ----------------------
8486 -- Unchecked_Access --
8487 ----------------------
8489 -- Processing is shared with Access
8491 -------------------------
8492 -- Unrestricted_Access --
8493 -------------------------
8495 -- Processing is shared with Access
8501 -- Apply range check. Note that we did not do this during the
8502 -- analysis phase, since we wanted Eval_Attribute to have a
8503 -- chance at finding an illegal out of range value.
8505 when Attribute_Val
=>
8507 -- Note that we do our own Eval_Attribute call here rather than
8508 -- use the common one, because we need to do processing after
8509 -- the call, as per above comment.
8513 -- Eval_Attribute may replace the node with a raise CE, or
8514 -- fold it to a constant. Obviously we only apply a scalar
8515 -- range check if this did not happen!
8517 if Nkind
(N
) = N_Attribute_Reference
8518 and then Attribute_Name
(N
) = Name_Val
8520 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
8529 -- Prefix of Version attribute can be a subprogram name which
8530 -- must not be resolved, since this is not a call.
8532 when Attribute_Version
=>
8535 ----------------------
8536 -- Other Attributes --
8537 ----------------------
8539 -- For other attributes, resolve prefix unless it is a type. If
8540 -- the attribute reference itself is a type name ('Base and 'Class)
8541 -- then this is only legal within a task or protected record.
8544 if not Is_Entity_Name
(P
)
8545 or else not Is_Type
(Entity
(P
))
8550 -- If the attribute reference itself is a type name ('Base,
8551 -- 'Class) then this is only legal within a task or protected
8552 -- record. What is this all about ???
8554 if Is_Entity_Name
(N
)
8555 and then Is_Type
(Entity
(N
))
8557 if Is_Concurrent_Type
(Entity
(N
))
8558 and then In_Open_Scopes
(Entity
(P
))
8563 ("invalid use of subtype name in expression or call", N
);
8567 -- For attributes whose argument may be a string, complete
8568 -- resolution of argument now. This avoids premature expansion
8569 -- (and the creation of transient scopes) before the attribute
8570 -- reference is resolved.
8573 when Attribute_Value
=>
8574 Resolve
(First
(Expressions
(N
)), Standard_String
);
8576 when Attribute_Wide_Value
=>
8577 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
8579 when Attribute_Wide_Wide_Value
=>
8580 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
8582 when others => null;
8585 -- If the prefix of the attribute is a class-wide type then it
8586 -- will be expanded into a dispatching call to a predefined
8587 -- primitive. Therefore we must check for potential violation
8588 -- of such restriction.
8590 if Is_Class_Wide_Type
(Etype
(P
)) then
8591 Check_Restriction
(No_Dispatching_Calls
, N
);
8595 -- Normally the Freezing is done by Resolve but sometimes the Prefix
8596 -- is not resolved, in which case the freezing must be done now.
8598 Freeze_Expression
(P
);
8600 -- Finally perform static evaluation on the attribute reference
8603 end Resolve_Attribute
;
8605 --------------------------------
8606 -- Stream_Attribute_Available --
8607 --------------------------------
8609 function Stream_Attribute_Available
8611 Nam
: TSS_Name_Type
;
8612 Partial_View
: Node_Id
:= Empty
) return Boolean
8614 Etyp
: Entity_Id
:= Typ
;
8616 -- Start of processing for Stream_Attribute_Available
8619 -- We need some comments in this body ???
8621 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
8625 if Is_Class_Wide_Type
(Typ
) then
8626 return not Is_Limited_Type
(Typ
)
8627 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
8630 if Nam
= TSS_Stream_Input
8631 and then Is_Abstract_Type
(Typ
)
8632 and then not Is_Class_Wide_Type
(Typ
)
8637 if not (Is_Limited_Type
(Typ
)
8638 or else (Present
(Partial_View
)
8639 and then Is_Limited_Type
(Partial_View
)))
8644 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
8646 if Nam
= TSS_Stream_Input
8647 and then Ada_Version
>= Ada_05
8648 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
8652 elsif Nam
= TSS_Stream_Output
8653 and then Ada_Version
>= Ada_05
8654 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
8659 -- Case of Read and Write: check for attribute definition clause that
8660 -- applies to an ancestor type.
8662 while Etype
(Etyp
) /= Etyp
loop
8663 Etyp
:= Etype
(Etyp
);
8665 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
8670 if Ada_Version
< Ada_05
then
8672 -- In Ada 95 mode, also consider a non-visible definition
8675 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
8678 and then Stream_Attribute_Available
8679 (Btyp
, Nam
, Partial_View
=> Typ
);
8684 end Stream_Attribute_Available
;