1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
29 with Atree
; use Atree
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Util
; use Exp_Util
;
35 with Expander
; use Expander
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
46 with Sdefault
; use Sdefault
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Dist
; use Sem_Dist
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sem_Util
; use Sem_Util
;
56 with Stand
; use Stand
;
57 with Sinfo
; use Sinfo
;
58 with Sinput
; use Sinput
;
60 with Stringt
; use Stringt
;
61 with Targparm
; use Targparm
;
62 with Ttypes
; use Ttypes
;
63 with Ttypef
; use Ttypef
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
66 with Urealp
; use Urealp
;
68 package body Sem_Attr
is
70 True_Value
: constant Uint
:= Uint_1
;
71 False_Value
: constant Uint
:= Uint_0
;
72 -- Synonyms to be used when these constants are used as Boolean values
74 Bad_Attribute
: exception;
75 -- Exception raised if an error is detected during attribute processing,
76 -- used so that we can abandon the processing so we don't run into
77 -- trouble with cascaded errors.
79 -- The following array is the list of attributes defined in the Ada 83 RM
81 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
87 Attribute_Constrained |
100 Attribute_Leading_Part |
102 Attribute_Machine_Emax |
103 Attribute_Machine_Emin |
104 Attribute_Machine_Mantissa |
105 Attribute_Machine_Overflows |
106 Attribute_Machine_Radix |
107 Attribute_Machine_Rounds |
113 Attribute_Safe_Emax |
114 Attribute_Safe_Large |
115 Attribute_Safe_Small |
118 Attribute_Storage_Size |
120 Attribute_Terminated |
123 Attribute_Width => True,
126 -----------------------
127 -- Local_Subprograms --
128 -----------------------
130 procedure Eval_Attribute (N : Node_Id);
131 -- Performs compile time evaluation of attributes where possible, leaving
132 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
133 -- set, and replacing the node with a literal node if the value can be
134 -- computed at compile time. All static attribute references are folded,
135 -- as well as a number of cases of non-static attributes that can always
136 -- be computed at compile time (e.g. floating-point model attributes that
137 -- are applied to non-static subtypes). Of course in such cases, the
138 -- Is_Static_Expression flag will not be set on the resulting literal.
139 -- Note that the only required action of this procedure is to catch the
140 -- static expression cases as described in the RM. Folding of other cases
141 -- is done where convenient, but some additional non-static folding is in
142 -- N_Expand_Attribute_Reference in cases where this is more convenient.
144 function Is_Anonymous_Tagged_Base
148 -- For derived tagged types that constrain parent discriminants we build
149 -- an anonymous unconstrained base type. We need to recognize the relation
150 -- between the two when analyzing an access attribute for a constrained
151 -- component, before the full declaration for Typ has been analyzed, and
152 -- where therefore the prefix of the attribute does not match the enclosing
155 -----------------------
156 -- Analyze_Attribute --
157 -----------------------
159 procedure Analyze_Attribute (N : Node_Id) is
160 Loc : constant Source_Ptr := Sloc (N);
161 Aname : constant Name_Id := Attribute_Name (N);
162 P : constant Node_Id := Prefix (N);
163 Exprs : constant List_Id := Expressions (N);
164 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
169 -- Type of prefix after analysis
171 P_Base_Type : Entity_Id;
172 -- Base type of prefix after analysis
174 -----------------------
175 -- Local Subprograms --
176 -----------------------
178 procedure Analyze_Access_Attribute;
179 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
180 -- Internally, Id distinguishes which of the three cases is involved.
182 procedure Check_Array_Or_Scalar_Type;
183 -- Common procedure used by First, Last, Range attribute to check
184 -- that the prefix is a constrained array or scalar type, or a name
185 -- of an array object, and that an argument appears only if appropriate
186 -- (i.e. only in the array case).
188 procedure Check_Array_Type;
189 -- Common semantic checks for all array attributes. Checks that the
190 -- prefix is a constrained array type or the name of an array object.
191 -- The error message for non-arrays is specialized appropriately.
193 procedure Check_Asm_Attribute;
194 -- Common semantic checks for Asm_Input and Asm_Output attributes
196 procedure Check_Component;
197 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
198 -- Position. Checks prefix is an appropriate selected component.
200 procedure Check_Decimal_Fixed_Point_Type;
201 -- Check that prefix of attribute N is a decimal fixed-point type
203 procedure Check_Dereference;
204 -- If the prefix of attribute is an object of an access type, then
205 -- introduce an explicit deference, and adjust P_Type accordingly.
207 procedure Check_Discrete_Type;
208 -- Verify that prefix of attribute N is a discrete type
211 -- Check that no attribute arguments are present
213 procedure Check_Either_E0_Or_E1;
214 -- Check that there are zero or one attribute arguments present
217 -- Check that exactly one attribute argument is present
220 -- Check that two attribute arguments are present
222 procedure Check_Enum_Image;
223 -- If the prefix type is an enumeration type, set all its literals
224 -- as referenced, since the image function could possibly end up
225 -- referencing any of the literals indirectly.
227 procedure Check_Fixed_Point_Type;
228 -- Verify that prefix of attribute N is a fixed type
230 procedure Check_Fixed_Point_Type_0;
231 -- Verify that prefix of attribute N is a fixed type and that
232 -- no attribute expressions are present
234 procedure Check_Floating_Point_Type;
235 -- Verify that prefix of attribute N is a float type
237 procedure Check_Floating_Point_Type_0;
238 -- Verify that prefix of attribute N is a float type and that
239 -- no attribute expressions are present
241 procedure Check_Floating_Point_Type_1;
242 -- Verify that prefix of attribute N is a float type and that
243 -- exactly one attribute expression is present
245 procedure Check_Floating_Point_Type_2;
246 -- Verify that prefix of attribute N is a float type and that
247 -- two attribute expressions are present
249 procedure Legal_Formal_Attribute;
250 -- Common processing for attributes Definite, Has_Access_Values,
251 -- and Has_Discriminants
253 procedure Check_Integer_Type;
254 -- Verify that prefix of attribute N is an integer type
256 procedure Check_Library_Unit;
257 -- Verify that prefix of attribute N is a library unit
259 procedure Check_Modular_Integer_Type;
260 -- Verify that prefix of attribute N is a modular integer type
262 procedure Check_Not_Incomplete_Type;
263 -- Check that P (the prefix of the attribute) is not an incomplete
264 -- type or a private type for which no full view has been given.
266 procedure Check_Object_Reference (P : Node_Id);
267 -- Check that P (the prefix of the attribute) is an object reference
269 procedure Check_Program_Unit;
270 -- Verify that prefix of attribute N is a program unit
272 procedure Check_Real_Type;
273 -- Verify that prefix of attribute N is fixed or float type
275 procedure Check_Scalar_Type;
276 -- Verify that prefix of attribute N is a scalar type
278 procedure Check_Standard_Prefix;
279 -- Verify that prefix of attribute N is package Standard
281 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
282 -- Validity checking for stream attribute. Nam is the TSS name of the
283 -- corresponding possible defined attribute function (e.g. for the
284 -- Read attribute, Nam will be TSS_Stream_Read).
286 procedure Check_Task_Prefix;
287 -- Verify that prefix of attribute N is a task or task type
289 procedure Check_Type;
290 -- Verify that the prefix of attribute N is a type
292 procedure Check_Unit_Name (Nod : Node_Id);
293 -- Check that Nod is of the form of a library unit name, i.e that
294 -- it is an identifier, or a selected component whose prefix is
295 -- itself of the form of a library unit name. Note that this is
296 -- quite different from Check_Program_Unit, since it only checks
297 -- the syntactic form of the name, not the semantic identity. This
298 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
299 -- UET_Address) which can refer to non-visible unit.
301 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
302 pragma No_Return (Error_Attr);
303 procedure Error_Attr;
304 pragma No_Return (Error_Attr);
305 -- Posts error using Error_Msg_N at given node, sets type of attribute
306 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
307 -- semantic processing. The message typically contains a % insertion
308 -- character which is replaced by the attribute name. The call with
309 -- no arguments is used when the caller has already generated the
310 -- required error messages.
312 procedure Standard_Attribute (Val : Int);
313 -- Used to process attributes whose prefix is package Standard which
314 -- yield values of type Universal_Integer. The attribute reference
315 -- node is rewritten with an integer literal of the given value.
317 procedure Unexpected_Argument (En : Node_Id);
318 -- Signal unexpected attribute argument (En is the argument)
320 procedure Validate_Non_Static_Attribute_Function_Call;
321 -- Called when processing an attribute that is a function call to a
322 -- non-static function, i.e. an attribute function that either takes
323 -- non-scalar arguments or returns a non-scalar result. Verifies that
324 -- such a call does not appear in a preelaborable context.
326 ------------------------------
327 -- Analyze_Access_Attribute --
328 ------------------------------
330 procedure Analyze_Access_Attribute is
331 Acc_Type : Entity_Id;
336 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
337 -- Build an access-to-object type whose designated type is DT,
338 -- and whose Ekind is appropriate to the attribute type. The
339 -- type that is constructed is returned as the result.
341 procedure Build_Access_Subprogram_Type (P : Node_Id);
342 -- Build an access to subprogram whose designated type is
343 -- the type of the prefix. If prefix is overloaded, so it the
344 -- node itself. The result is stored in Acc_Type.
346 ------------------------------
347 -- Build_Access_Object_Type --
348 ------------------------------
350 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
354 if Aname = Name_Unrestricted_Access then
357 (E_Allocator_Type, Current_Scope, Loc, 'A
');
361 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
364 Set_Etype (Typ, Typ);
365 Init_Size_Align (Typ);
367 Set_Associated_Node_For_Itype (Typ, N);
368 Set_Directly_Designated_Type (Typ, DT);
370 end Build_Access_Object_Type;
372 ----------------------------------
373 -- Build_Access_Subprogram_Type --
374 ----------------------------------
376 procedure Build_Access_Subprogram_Type (P : Node_Id) is
377 Index : Interp_Index;
380 function Get_Kind (E : Entity_Id) return Entity_Kind;
381 -- Distinguish between access to regular/protected subprograms
387 function Get_Kind (E : Entity_Id) return Entity_Kind is
389 if Convention (E) = Convention_Protected then
390 return E_Access_Protected_Subprogram_Type;
392 return E_Access_Subprogram_Type;
396 -- Start of processing for Build_Access_Subprogram_Type
399 -- In the case of an access to subprogram, use the name of the
400 -- subprogram itself as the designated type. Type-checking in
401 -- this case compares the signatures of the designated types.
403 Set_Etype (N, Any_Type);
405 if not Is_Overloaded (P) then
406 if not Is_Intrinsic_Subprogram (Entity (P)) then
409 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
410 Set_Etype (Acc_Type, Acc_Type);
411 Set_Directly_Designated_Type (Acc_Type, Entity (P));
412 Set_Etype (N, Acc_Type);
416 Get_First_Interp (P, Index, It);
417 while Present (It.Nam) loop
418 if not Is_Intrinsic_Subprogram (It.Nam) then
421 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
422 Set_Etype (Acc_Type, Acc_Type);
423 Set_Directly_Designated_Type (Acc_Type, It.Nam);
424 Add_One_Interp (N, Acc_Type, Acc_Type);
427 Get_Next_Interp (Index, It);
431 if Etype (N) = Any_Type then
432 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
434 end Build_Access_Subprogram_Type;
436 -- Start of processing for Analyze_Access_Attribute
441 if Nkind (P) = N_Character_Literal then
443 ("prefix of % attribute cannot be enumeration literal", P);
446 -- Case of access to subprogram
448 if Is_Entity_Name (P)
449 and then Is_Overloadable (Entity (P))
451 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
452 -- restriction set (since in general a trampoline is required).
454 if not Is_Library_Level_Entity (Entity (P)) then
455 Check_Restriction (No_Implicit_Dynamic_Code, P);
458 if Is_Always_Inlined (Entity (P)) then
460 ("prefix of % attribute cannot be Inline_Always subprogram",
464 -- Build the appropriate subprogram type
466 Build_Access_Subprogram_Type (P);
468 -- For unrestricted access, kill current values, since this
469 -- attribute allows a reference to a local subprogram that
470 -- could modify local variables to be passed out of scope
472 if Aname = Name_Unrestricted_Access then
478 -- Component is an operation of a protected type
480 elsif Nkind (P) = N_Selected_Component
481 and then Is_Overloadable (Entity (Selector_Name (P)))
483 if Ekind (Entity (Selector_Name (P))) = E_Entry then
484 Error_Attr ("prefix of % attribute must be subprogram", P);
487 Build_Access_Subprogram_Type (Selector_Name (P));
491 -- Deal with incorrect reference to a type, but note that some
492 -- accesses are allowed (references to the current type instance).
494 if Is_Entity_Name (P) then
497 -- The reference may appear in an aggregate that has been expanded
498 -- into a loop. Locate scope of type definition, if any.
500 Scop := Current_Scope;
501 while Ekind (Scop) = E_Loop loop
502 Scop := Scope (Scop);
505 if Is_Type (Typ) then
507 -- OK if we are within the scope of a limited type
508 -- let's mark the component as having per object constraint
510 if Is_Anonymous_Tagged_Base (Scop, Typ) then
518 Q : Node_Id := Parent (N);
522 and then Nkind (Q) /= N_Component_Declaration
528 Set_Has_Per_Object_Constraint (
529 Defining_Identifier (Q), True);
533 if Nkind (P) = N_Expanded_Name then
535 ("current instance prefix must be a direct name", P);
538 -- If a current instance attribute appears within a
539 -- a component constraint it must appear alone; other
540 -- contexts (default expressions, within a task body)
541 -- are not subject to this restriction.
543 if not In_Default_Expression
544 and then not Has_Completion (Scop)
546 Nkind (Parent (N)) /= N_Discriminant_Association
548 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
551 ("current instance attribute must appear alone", N);
554 -- OK if we are in initialization procedure for the type
555 -- in question, in which case the reference to the type
556 -- is rewritten as a reference to the current object.
558 elsif Ekind (Scop) = E_Procedure
559 and then Is_Init_Proc (Scop)
560 and then Etype (First_Formal (Scop)) = Typ
563 Make_Attribute_Reference (Loc,
564 Prefix => Make_Identifier (Loc, Name_uInit),
565 Attribute_Name => Name_Unrestricted_Access));
569 -- OK if a task type, this test needs sharpening up ???
571 elsif Is_Task_Type (Typ) then
574 -- Otherwise we have an error case
577 Error_Attr ("% attribute cannot be applied to type", P);
583 -- If we fall through, we have a normal access to object case.
584 -- Unrestricted_Access is legal wherever an allocator would be
585 -- legal, so its Etype is set to E_Allocator. The expected type
586 -- of the other attributes is a general access type, and therefore
587 -- we label them with E_Access_Attribute_Type.
589 if not Is_Overloaded (P) then
590 Acc_Type := Build_Access_Object_Type (P_Type);
591 Set_Etype (N, Acc_Type);
594 Index : Interp_Index;
597 Set_Etype (N, Any_Type);
598 Get_First_Interp (P, Index, It);
599 while Present (It.Typ) loop
600 Acc_Type := Build_Access_Object_Type (It.Typ);
601 Add_One_Interp (N, Acc_Type, Acc_Type);
602 Get_Next_Interp (Index, It);
607 -- If we have an access to an object, and the attribute comes
608 -- from source, then set the object as potentially source modified.
609 -- We do this because the resulting access pointer can be used to
610 -- modify the variable, and we might not detect this, leading to
611 -- some junk warnings.
613 if Is_Entity_Name (P) then
614 Set_Never_Set_In_Source (Entity (P), False);
617 -- Check for aliased view unless unrestricted case. We allow
618 -- a nonaliased prefix when within an instance because the
619 -- prefix may have been a tagged formal object, which is
620 -- defined to be aliased even when the actual might not be
621 -- (other instance cases will have been caught in the generic).
622 -- Similarly, within an inlined body we know that the attribute
623 -- is legal in the original subprogram, and therefore legal in
626 if Aname /= Name_Unrestricted_Access
627 and then not Is_Aliased_View (P)
628 and then not In_Instance
629 and then not In_Inlined_Body
631 Error_Attr ("prefix of % attribute must be aliased", P);
633 end Analyze_Access_Attribute;
635 --------------------------------
636 -- Check_Array_Or_Scalar_Type --
637 --------------------------------
639 procedure Check_Array_Or_Scalar_Type is
643 -- Dimension number for array attributes
646 -- Case of string literal or string literal subtype. These cases
647 -- cannot arise from legal Ada code, but the expander is allowed
648 -- to generate them. They require special handling because string
649 -- literal subtypes do not have standard bounds (the whole idea
650 -- of these subtypes is to avoid having to generate the bounds)
652 if Ekind (P_Type) = E_String_Literal_Subtype then
653 Set_Etype (N, Etype (First_Index (P_Base_Type)));
658 elsif Is_Scalar_Type (P_Type) then
662 Error_Attr ("invalid argument in % attribute", E1);
664 Set_Etype (N, P_Base_Type);
668 -- The following is a special test to allow 'First to apply to
669 -- private scalar types if the attribute comes from generated
670 -- code. This occurs in the case of Normalize_Scalars code.
672 elsif Is_Private_Type
(P_Type
)
673 and then Present
(Full_View
(P_Type
))
674 and then Is_Scalar_Type
(Full_View
(P_Type
))
675 and then not Comes_From_Source
(N
)
677 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
679 -- Array types other than string literal subtypes handled above
684 -- We know prefix is an array type, or the name of an array
685 -- object, and that the expression, if present, is static
686 -- and within the range of the dimensions of the type.
688 pragma Assert
(Is_Array_Type
(P_Type
));
689 Index
:= First_Index
(P_Base_Type
);
693 -- First dimension assumed
695 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
698 D
:= UI_To_Int
(Intval
(E1
));
700 for J
in 1 .. D
- 1 loop
704 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
705 Set_Etype
(E1
, Standard_Integer
);
708 end Check_Array_Or_Scalar_Type
;
710 ----------------------
711 -- Check_Array_Type --
712 ----------------------
714 procedure Check_Array_Type
is
716 -- Dimension number for array attributes
719 -- If the type is a string literal type, then this must be generated
720 -- internally, and no further check is required on its legality.
722 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
725 -- If the type is a composite, it is an illegal aggregate, no point
728 elsif P_Type
= Any_Composite
then
732 -- Normal case of array type or subtype
734 Check_Either_E0_Or_E1
;
737 if Is_Array_Type
(P_Type
) then
738 if not Is_Constrained
(P_Type
)
739 and then Is_Entity_Name
(P
)
740 and then Is_Type
(Entity
(P
))
742 -- Note: we do not call Error_Attr here, since we prefer to
743 -- continue, using the relevant index type of the array,
744 -- even though it is unconstrained. This gives better error
745 -- recovery behavior.
747 Error_Msg_Name_1
:= Aname
;
749 ("prefix for % attribute must be constrained array", P
);
752 D
:= Number_Dimensions
(P_Type
);
755 if Is_Private_Type
(P_Type
) then
757 ("prefix for % attribute may not be private type", P
);
759 elsif Is_Access_Type
(P_Type
)
760 and then Is_Array_Type
(Designated_Type
(P_Type
))
761 and then Is_Entity_Name
(P
)
762 and then Is_Type
(Entity
(P
))
764 Error_Attr
("prefix of % attribute cannot be access type", P
);
766 elsif Attr_Id
= Attribute_First
768 Attr_Id
= Attribute_Last
770 Error_Attr
("invalid prefix for % attribute", P
);
773 Error_Attr
("prefix for % attribute must be array", P
);
778 Resolve
(E1
, Any_Integer
);
779 Set_Etype
(E1
, Standard_Integer
);
781 if not Is_Static_Expression
(E1
)
782 or else Raises_Constraint_Error
(E1
)
785 ("expression for dimension must be static!", E1
);
788 elsif UI_To_Int
(Expr_Value
(E1
)) > D
789 or else UI_To_Int
(Expr_Value
(E1
)) < 1
791 Error_Attr
("invalid dimension number for array type", E1
);
794 end Check_Array_Type
;
796 -------------------------
797 -- Check_Asm_Attribute --
798 -------------------------
800 procedure Check_Asm_Attribute
is
805 -- Check first argument is static string expression
807 Analyze_And_Resolve
(E1
, Standard_String
);
809 if Etype
(E1
) = Any_Type
then
812 elsif not Is_OK_Static_Expression
(E1
) then
814 ("constraint argument must be static string expression!", E1
);
818 -- Check second argument is right type
820 Analyze_And_Resolve
(E2
, Entity
(P
));
822 -- Note: that is all we need to do, we don't need to check
823 -- that it appears in a correct context. The Ada type system
824 -- will do that for us.
826 end Check_Asm_Attribute
;
828 ---------------------
829 -- Check_Component --
830 ---------------------
832 procedure Check_Component
is
836 if Nkind
(P
) /= N_Selected_Component
838 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
840 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
843 ("prefix for % attribute must be selected component", P
);
847 ------------------------------------
848 -- Check_Decimal_Fixed_Point_Type --
849 ------------------------------------
851 procedure Check_Decimal_Fixed_Point_Type
is
855 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
857 ("prefix of % attribute must be decimal type", P
);
859 end Check_Decimal_Fixed_Point_Type
;
861 -----------------------
862 -- Check_Dereference --
863 -----------------------
865 procedure Check_Dereference
is
868 -- Case of a subtype mark
870 if Is_Entity_Name
(P
)
871 and then Is_Type
(Entity
(P
))
876 -- Case of an expression
880 if Is_Access_Type
(P_Type
) then
882 -- If there is an implicit dereference, then we must freeze
883 -- the designated type of the access type, since the type of
884 -- the referenced array is this type (see AI95-00106).
886 Freeze_Before
(N
, Designated_Type
(P_Type
));
889 Make_Explicit_Dereference
(Sloc
(P
),
890 Prefix
=> Relocate_Node
(P
)));
892 Analyze_And_Resolve
(P
);
895 if P_Type
= Any_Type
then
899 P_Base_Type
:= Base_Type
(P_Type
);
901 end Check_Dereference
;
903 -------------------------
904 -- Check_Discrete_Type --
905 -------------------------
907 procedure Check_Discrete_Type
is
911 if not Is_Discrete_Type
(P_Type
) then
912 Error_Attr
("prefix of % attribute must be discrete type", P
);
914 end Check_Discrete_Type
;
920 procedure Check_E0
is
923 Unexpected_Argument
(E1
);
931 procedure Check_E1
is
933 Check_Either_E0_Or_E1
;
937 -- Special-case attributes that are functions and that appear as
938 -- the prefix of another attribute. Error is posted on parent.
940 if Nkind
(Parent
(N
)) = N_Attribute_Reference
941 and then (Attribute_Name
(Parent
(N
)) = Name_Address
943 Attribute_Name
(Parent
(N
)) = Name_Code_Address
945 Attribute_Name
(Parent
(N
)) = Name_Access
)
947 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
948 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
949 Set_Etype
(Parent
(N
), Any_Type
);
950 Set_Entity
(Parent
(N
), Any_Type
);
954 Error_Attr
("missing argument for % attribute", N
);
963 procedure Check_E2
is
966 Error_Attr
("missing arguments for % attribute (2 required)", N
);
968 Error_Attr
("missing argument for % attribute (2 required)", N
);
972 ---------------------------
973 -- Check_Either_E0_Or_E1 --
974 ---------------------------
976 procedure Check_Either_E0_Or_E1
is
979 Unexpected_Argument
(E2
);
981 end Check_Either_E0_Or_E1
;
983 ----------------------
984 -- Check_Enum_Image --
985 ----------------------
987 procedure Check_Enum_Image
is
991 if Is_Enumeration_Type
(P_Base_Type
) then
992 Lit
:= First_Literal
(P_Base_Type
);
993 while Present
(Lit
) loop
994 Set_Referenced
(Lit
);
998 end Check_Enum_Image
;
1000 ----------------------------
1001 -- Check_Fixed_Point_Type --
1002 ----------------------------
1004 procedure Check_Fixed_Point_Type
is
1008 if not Is_Fixed_Point_Type
(P_Type
) then
1009 Error_Attr
("prefix of % attribute must be fixed point type", P
);
1011 end Check_Fixed_Point_Type
;
1013 ------------------------------
1014 -- Check_Fixed_Point_Type_0 --
1015 ------------------------------
1017 procedure Check_Fixed_Point_Type_0
is
1019 Check_Fixed_Point_Type
;
1021 end Check_Fixed_Point_Type_0
;
1023 -------------------------------
1024 -- Check_Floating_Point_Type --
1025 -------------------------------
1027 procedure Check_Floating_Point_Type
is
1031 if not Is_Floating_Point_Type
(P_Type
) then
1032 Error_Attr
("prefix of % attribute must be float type", P
);
1034 end Check_Floating_Point_Type
;
1036 ---------------------------------
1037 -- Check_Floating_Point_Type_0 --
1038 ---------------------------------
1040 procedure Check_Floating_Point_Type_0
is
1042 Check_Floating_Point_Type
;
1044 end Check_Floating_Point_Type_0
;
1046 ---------------------------------
1047 -- Check_Floating_Point_Type_1 --
1048 ---------------------------------
1050 procedure Check_Floating_Point_Type_1
is
1052 Check_Floating_Point_Type
;
1054 end Check_Floating_Point_Type_1
;
1056 ---------------------------------
1057 -- Check_Floating_Point_Type_2 --
1058 ---------------------------------
1060 procedure Check_Floating_Point_Type_2
is
1062 Check_Floating_Point_Type
;
1064 end Check_Floating_Point_Type_2
;
1066 ------------------------
1067 -- Check_Integer_Type --
1068 ------------------------
1070 procedure Check_Integer_Type
is
1074 if not Is_Integer_Type
(P_Type
) then
1075 Error_Attr
("prefix of % attribute must be integer type", P
);
1077 end Check_Integer_Type
;
1079 ------------------------
1080 -- Check_Library_Unit --
1081 ------------------------
1083 procedure Check_Library_Unit
is
1085 if not Is_Compilation_Unit
(Entity
(P
)) then
1086 Error_Attr
("prefix of % attribute must be library unit", P
);
1088 end Check_Library_Unit
;
1090 --------------------------------
1091 -- Check_Modular_Integer_Type --
1092 --------------------------------
1094 procedure Check_Modular_Integer_Type
is
1098 if not Is_Modular_Integer_Type
(P_Type
) then
1100 ("prefix of % attribute must be modular integer type", P
);
1102 end Check_Modular_Integer_Type
;
1104 -------------------------------
1105 -- Check_Not_Incomplete_Type --
1106 -------------------------------
1108 procedure Check_Not_Incomplete_Type
is
1113 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1114 -- dereference we have to check wrong uses of incomplete types
1115 -- (other wrong uses are checked at their freezing point).
1117 -- Example 1: Limited-with
1119 -- limited with Pkg;
1121 -- type Acc is access Pkg.T;
1123 -- S : Integer := X.all'Size; -- ERROR
1126 -- Example 2: Tagged incomplete
1128 -- type T is tagged;
1129 -- type Acc is access all T;
1131 -- S : constant Integer := X.all'Size; -- ERROR
1132 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1134 if Ada_Version
>= Ada_05
1135 and then Nkind
(P
) = N_Explicit_Dereference
1138 while Nkind
(E
) = N_Explicit_Dereference
loop
1142 if From_With_Type
(Etype
(E
)) then
1144 ("prefix of % attribute cannot be an incomplete type", P
);
1147 if Is_Access_Type
(Etype
(E
)) then
1148 Typ
:= Directly_Designated_Type
(Etype
(E
));
1153 if Ekind
(Typ
) = E_Incomplete_Type
1154 and then not Present
(Full_View
(Typ
))
1157 ("prefix of % attribute cannot be an incomplete type", P
);
1162 if not Is_Entity_Name
(P
)
1163 or else not Is_Type
(Entity
(P
))
1164 or else In_Default_Expression
1168 Check_Fully_Declared
(P_Type
, P
);
1170 end Check_Not_Incomplete_Type
;
1172 ----------------------------
1173 -- Check_Object_Reference --
1174 ----------------------------
1176 procedure Check_Object_Reference
(P
: Node_Id
) is
1180 -- If we need an object, and we have a prefix that is the name of
1181 -- a function entity, convert it into a function call.
1183 if Is_Entity_Name
(P
)
1184 and then Ekind
(Entity
(P
)) = E_Function
1186 Rtyp
:= Etype
(Entity
(P
));
1189 Make_Function_Call
(Sloc
(P
),
1190 Name
=> Relocate_Node
(P
)));
1192 Analyze_And_Resolve
(P
, Rtyp
);
1194 -- Otherwise we must have an object reference
1196 elsif not Is_Object_Reference
(P
) then
1197 Error_Attr
("prefix of % attribute must be object", P
);
1199 end Check_Object_Reference
;
1201 ------------------------
1202 -- Check_Program_Unit --
1203 ------------------------
1205 procedure Check_Program_Unit
is
1207 if Is_Entity_Name
(P
) then
1209 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1210 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1213 if K
in Subprogram_Kind
1214 or else K
in Task_Kind
1215 or else K
in Protected_Kind
1216 or else K
= E_Package
1217 or else K
in Generic_Unit_Kind
1218 or else (K
= E_Variable
1222 Is_Protected_Type
(T
)))
1229 Error_Attr
("prefix of % attribute must be program unit", P
);
1230 end Check_Program_Unit
;
1232 ---------------------
1233 -- Check_Real_Type --
1234 ---------------------
1236 procedure Check_Real_Type
is
1240 if not Is_Real_Type
(P_Type
) then
1241 Error_Attr
("prefix of % attribute must be real type", P
);
1243 end Check_Real_Type
;
1245 -----------------------
1246 -- Check_Scalar_Type --
1247 -----------------------
1249 procedure Check_Scalar_Type
is
1253 if not Is_Scalar_Type
(P_Type
) then
1254 Error_Attr
("prefix of % attribute must be scalar type", P
);
1256 end Check_Scalar_Type
;
1258 ---------------------------
1259 -- Check_Standard_Prefix --
1260 ---------------------------
1262 procedure Check_Standard_Prefix
is
1266 if Nkind
(P
) /= N_Identifier
1267 or else Chars
(P
) /= Name_Standard
1269 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1272 end Check_Standard_Prefix
;
1274 ----------------------------
1275 -- Check_Stream_Attribute --
1276 ----------------------------
1278 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1282 Validate_Non_Static_Attribute_Function_Call
;
1284 -- With the exception of 'Input, Stream attributes are procedures,
1285 -- and can only appear at the position of procedure calls. We check
1286 -- for this here, before they are rewritten, to give a more precise
1289 if Nam
= TSS_Stream_Input
then
1292 elsif Is_List_Member
(N
)
1293 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1294 and then Nkind
(Parent
(N
)) /= N_Aggregate
1300 ("invalid context for attribute%, which is a procedure", N
);
1304 Btyp
:= Implementation_Base_Type
(P_Type
);
1306 -- Stream attributes not allowed on limited types unless the
1307 -- attribute reference was generated by the expander (in which
1308 -- case the underlying type will be used, as described in Sinfo),
1309 -- or the attribute was specified explicitly for the type itself
1310 -- or one of its ancestors (taking visibility rules into account if
1311 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1312 -- (with no visibility restriction).
1314 if Comes_From_Source
(N
)
1315 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1316 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1318 Error_Msg_Name_1
:= Aname
;
1320 if Is_Limited_Type
(P_Type
) then
1322 ("limited type& has no% attribute", P
, P_Type
);
1323 Explain_Limited_Type
(P_Type
, P
);
1326 ("attribute% for type& is not available", P
, P_Type
);
1330 -- Check for violation of restriction No_Stream_Attributes
1332 if Is_RTE
(P_Type
, RE_Exception_Id
)
1334 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1336 Check_Restriction
(No_Exception_Registration
, P
);
1339 -- Here we must check that the first argument is an access type
1340 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1342 Analyze_And_Resolve
(E1
);
1345 -- Note: the double call to Root_Type here is needed because the
1346 -- root type of a class-wide type is the corresponding type (e.g.
1347 -- X for X'Class, and we really want to go to the root.
1349 if not Is_Access_Type
(Etyp
)
1350 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1351 RTE
(RE_Root_Stream_Type
)
1354 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1357 -- Check that the second argument is of the right type if there is
1358 -- one (the Input attribute has only one argument so this is skipped)
1360 if Present
(E2
) then
1363 if Nam
= TSS_Stream_Read
1364 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1367 ("second argument of % attribute must be a variable", E2
);
1370 Resolve
(E2
, P_Type
);
1372 end Check_Stream_Attribute
;
1374 -----------------------
1375 -- Check_Task_Prefix --
1376 -----------------------
1378 procedure Check_Task_Prefix
is
1382 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1383 -- task interface class-wide types.
1385 if Is_Task_Type
(Etype
(P
))
1386 or else (Is_Access_Type
(Etype
(P
))
1387 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1388 or else (Ada_Version
>= Ada_05
1389 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1390 and then Is_Interface
(Etype
(P
))
1391 and then Is_Task_Interface
(Etype
(P
)))
1396 if Ada_Version
>= Ada_05
then
1397 Error_Attr
("prefix of % attribute must be a task or a task "
1398 & "interface class-wide object", P
);
1401 Error_Attr
("prefix of % attribute must be a task", P
);
1404 end Check_Task_Prefix
;
1410 -- The possibilities are an entity name denoting a type, or an
1411 -- attribute reference that denotes a type (Base or Class). If
1412 -- the type is incomplete, replace it with its full view.
1414 procedure Check_Type
is
1416 if not Is_Entity_Name
(P
)
1417 or else not Is_Type
(Entity
(P
))
1419 Error_Attr
("prefix of % attribute must be a type", P
);
1421 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1422 and then Present
(Full_View
(Entity
(P
)))
1424 P_Type
:= Full_View
(Entity
(P
));
1425 Set_Entity
(P
, P_Type
);
1429 ---------------------
1430 -- Check_Unit_Name --
1431 ---------------------
1433 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1435 if Nkind
(Nod
) = N_Identifier
then
1438 elsif Nkind
(Nod
) = N_Selected_Component
then
1439 Check_Unit_Name
(Prefix
(Nod
));
1441 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1446 Error_Attr
("argument for % attribute must be unit name", P
);
1447 end Check_Unit_Name
;
1453 procedure Error_Attr
is
1455 Set_Etype
(N
, Any_Type
);
1456 Set_Entity
(N
, Any_Type
);
1457 raise Bad_Attribute
;
1460 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1462 Error_Msg_Name_1
:= Aname
;
1463 Error_Msg_N
(Msg
, Error_Node
);
1467 ----------------------------
1468 -- Legal_Formal_Attribute --
1469 ----------------------------
1471 procedure Legal_Formal_Attribute
is
1475 if not Is_Entity_Name
(P
)
1476 or else not Is_Type
(Entity
(P
))
1478 Error_Attr
("prefix of % attribute must be generic type", N
);
1480 elsif Is_Generic_Actual_Type
(Entity
(P
))
1482 or else In_Inlined_Body
1486 elsif Is_Generic_Type
(Entity
(P
)) then
1487 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1489 ("prefix of % attribute must be indefinite generic type", N
);
1494 ("prefix of % attribute must be indefinite generic type", N
);
1497 Set_Etype
(N
, Standard_Boolean
);
1498 end Legal_Formal_Attribute
;
1500 ------------------------
1501 -- Standard_Attribute --
1502 ------------------------
1504 procedure Standard_Attribute
(Val
: Int
) is
1506 Check_Standard_Prefix
;
1508 -- First a special check (more like a kludge really). For GNAT5
1509 -- on Windows, the alignments in GCC are severely mixed up. In
1510 -- particular, we have a situation where the maximum alignment
1511 -- that GCC thinks is possible is greater than the guaranteed
1512 -- alignment at run-time. That causes many problems. As a partial
1513 -- cure for this situation, we force a value of 4 for the maximum
1514 -- alignment attribute on this target. This still does not solve
1515 -- all problems, but it helps.
1517 -- A further (even more horrible) dimension to this kludge is now
1518 -- installed. There are two uses for Maximum_Alignment, one is to
1519 -- determine the maximum guaranteed alignment, that's the one we
1520 -- want the kludge to yield as 4. The other use is to maximally
1521 -- align objects, we can't use 4 here, since for example, long
1522 -- long integer has an alignment of 8, so we will get errors.
1524 -- It is of course impossible to determine which use the programmer
1525 -- has in mind, but an approximation for now is to disconnect the
1526 -- kludge if the attribute appears in an alignment clause.
1528 -- To be removed if GCC ever gets its act together here ???
1530 Alignment_Kludge
: declare
1533 function On_X86
return Boolean;
1534 -- Determine if target is x86 (ia32), return True if so
1540 function On_X86
return Boolean is
1541 T
: constant String := Sdefault
.Target_Name
.all;
1544 -- There is no clean way to check this. That's not surprising,
1545 -- the front end should not be doing this kind of test ???. The
1546 -- way we do it is test for either "86" or "pentium" being in
1547 -- the string for the target name. However, we need to exclude
1548 -- x86_64 for this check.
1550 for J
in T
'First .. T
'Last - 1 loop
1551 if (T
(J
.. J
+ 1) = "86"
1554 or else T
(J
+ 2 .. J
+ 4) /= "_64"))
1555 or else (J
<= T
'Last - 6
1556 and then T
(J
.. J
+ 6) = "pentium")
1566 if Aname
= Name_Maximum_Alignment
and then On_X86
then
1569 while Nkind
(P
) in N_Subexpr
loop
1573 if Nkind
(P
) /= N_Attribute_Definition_Clause
1574 or else Chars
(P
) /= Name_Alignment
1576 Rewrite
(N
, Make_Integer_Literal
(Loc
, 4));
1581 end Alignment_Kludge
;
1583 -- Normally we get the value from gcc ???
1585 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1587 end Standard_Attribute
;
1589 -------------------------
1590 -- Unexpected Argument --
1591 -------------------------
1593 procedure Unexpected_Argument
(En
: Node_Id
) is
1595 Error_Attr
("unexpected argument for % attribute", En
);
1596 end Unexpected_Argument
;
1598 -------------------------------------------------
1599 -- Validate_Non_Static_Attribute_Function_Call --
1600 -------------------------------------------------
1602 -- This function should be moved to Sem_Dist ???
1604 procedure Validate_Non_Static_Attribute_Function_Call
is
1606 if In_Preelaborated_Unit
1607 and then not In_Subprogram_Or_Concurrent_Unit
1609 Flag_Non_Static_Expr
1610 ("non-static function call in preelaborated unit!", N
);
1612 end Validate_Non_Static_Attribute_Function_Call
;
1614 -----------------------------------------------
1615 -- Start of Processing for Analyze_Attribute --
1616 -----------------------------------------------
1619 -- Immediate return if unrecognized attribute (already diagnosed
1620 -- by parser, so there is nothing more that we need to do)
1622 if not Is_Attribute_Name
(Aname
) then
1623 raise Bad_Attribute
;
1626 -- Deal with Ada 83 and Features issues
1628 if Comes_From_Source
(N
) then
1629 if not Attribute_83
(Attr_Id
) then
1630 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1631 Error_Msg_Name_1
:= Aname
;
1632 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1635 if Attribute_Impl_Def
(Attr_Id
) then
1636 Check_Restriction
(No_Implementation_Attributes
, N
);
1641 -- Remote access to subprogram type access attribute reference needs
1642 -- unanalyzed copy for tree transformation. The analyzed copy is used
1643 -- for its semantic information (whether prefix is a remote subprogram
1644 -- name), the unanalyzed copy is used to construct new subtree rooted
1645 -- with N_Aggregate which represents a fat pointer aggregate.
1647 if Aname
= Name_Access
then
1648 Discard_Node
(Copy_Separate_Tree
(N
));
1651 -- Analyze prefix and exit if error in analysis. If the prefix is an
1652 -- incomplete type, use full view if available. A special case is
1653 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1654 -- or UET_Address attribute.
1656 if Aname
/= Name_Elab_Body
1658 Aname
/= Name_Elab_Spec
1660 Aname
/= Name_UET_Address
1663 P_Type
:= Etype
(P
);
1665 if Is_Entity_Name
(P
)
1666 and then Present
(Entity
(P
))
1667 and then Is_Type
(Entity
(P
))
1668 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1670 P_Type
:= Get_Full_View
(P_Type
);
1671 Set_Entity
(P
, P_Type
);
1672 Set_Etype
(P
, P_Type
);
1675 if P_Type
= Any_Type
then
1676 raise Bad_Attribute
;
1679 P_Base_Type
:= Base_Type
(P_Type
);
1682 -- Analyze expressions that may be present, exiting if an error occurs
1689 E1
:= First
(Exprs
);
1692 -- Check for missing or bad expression (result of previous error)
1694 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1695 raise Bad_Attribute
;
1700 if Present
(E2
) then
1703 if Etype
(E2
) = Any_Type
then
1704 raise Bad_Attribute
;
1707 if Present
(Next
(E2
)) then
1708 Unexpected_Argument
(Next
(E2
));
1713 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1714 -- output compiling in Ada 95 mode
1716 if Ada_Version
< Ada_05
1717 and then Is_Overloaded
(P
)
1718 and then Aname
/= Name_Access
1719 and then Aname
/= Name_Address
1720 and then Aname
/= Name_Code_Address
1721 and then Aname
/= Name_Count
1722 and then Aname
/= Name_Unchecked_Access
1724 Error_Attr
("ambiguous prefix for % attribute", P
);
1726 elsif Ada_Version
>= Ada_05
1727 and then Is_Overloaded
(P
)
1728 and then Aname
/= Name_Access
1729 and then Aname
/= Name_Address
1730 and then Aname
/= Name_Code_Address
1731 and then Aname
/= Name_Unchecked_Access
1733 -- Ada 2005 (AI-345): Since protected and task types have primitive
1734 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1737 if Ada_Version
>= Ada_05
1738 and then (Aname
= Name_Count
1739 or else Aname
= Name_Caller
1740 or else Aname
= Name_AST_Entry
)
1743 Count
: Natural := 0;
1748 Get_First_Interp
(P
, I
, It
);
1750 while Present
(It
.Nam
) loop
1751 if Comes_From_Source
(It
.Nam
) then
1757 Get_Next_Interp
(I
, It
);
1761 Error_Attr
("ambiguous prefix for % attribute", P
);
1763 Set_Is_Overloaded
(P
, False);
1768 Error_Attr
("ambiguous prefix for % attribute", P
);
1772 -- Remaining processing depends on attribute
1780 when Attribute_Abort_Signal
=>
1781 Check_Standard_Prefix
;
1783 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1790 when Attribute_Access
=>
1791 Analyze_Access_Attribute
;
1797 when Attribute_Address
=>
1800 -- Check for some junk cases, where we have to allow the address
1801 -- attribute but it does not make much sense, so at least for now
1802 -- just replace with Null_Address.
1804 -- We also do this if the prefix is a reference to the AST_Entry
1805 -- attribute. If expansion is active, the attribute will be
1806 -- replaced by a function call, and address will work fine and
1807 -- get the proper value, but if expansion is not active, then
1808 -- the check here allows proper semantic analysis of the reference.
1810 -- An Address attribute created by expansion is legal even when it
1811 -- applies to other entity-denoting expressions.
1813 if Is_Entity_Name
(P
) then
1815 Ent
: constant Entity_Id
:= Entity
(P
);
1818 if Is_Subprogram
(Ent
) then
1819 if not Is_Library_Level_Entity
(Ent
) then
1820 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1823 Set_Address_Taken
(Ent
);
1825 -- An Address attribute is accepted when generated by
1826 -- the compiler for dispatching operation, and an error
1827 -- is issued once the subprogram is frozen (to avoid
1828 -- confusing errors about implicit uses of Address in
1829 -- the dispatch table initialization).
1831 if Is_Always_Inlined
(Entity
(P
))
1832 and then Comes_From_Source
(P
)
1835 ("prefix of % attribute cannot be Inline_Always" &
1839 elsif Is_Object
(Ent
)
1840 or else Ekind
(Ent
) = E_Label
1842 Set_Address_Taken
(Ent
);
1844 -- If we have an address of an object, and the attribute
1845 -- comes from source, then set the object as potentially
1846 -- source modified. We do this because the resulting address
1847 -- can potentially be used to modify the variable and we
1848 -- might not detect this, leading to some junk warnings.
1850 Set_Never_Set_In_Source
(Ent
, False);
1852 elsif (Is_Concurrent_Type
(Etype
(Ent
))
1853 and then Etype
(Ent
) = Base_Type
(Ent
))
1854 or else Ekind
(Ent
) = E_Package
1855 or else Is_Generic_Unit
(Ent
)
1858 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1861 Error_Attr
("invalid prefix for % attribute", P
);
1865 elsif Nkind
(P
) = N_Attribute_Reference
1866 and then Attribute_Name
(P
) = Name_AST_Entry
1869 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1871 elsif Is_Object_Reference
(P
) then
1874 elsif Nkind
(P
) = N_Selected_Component
1875 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1879 -- What exactly are we allowing here ??? and is this properly
1880 -- documented in the sinfo documentation for this node ???
1882 elsif not Comes_From_Source
(N
) then
1886 Error_Attr
("invalid prefix for % attribute", P
);
1889 Set_Etype
(N
, RTE
(RE_Address
));
1895 when Attribute_Address_Size
=>
1896 Standard_Attribute
(System_Address_Size
);
1902 when Attribute_Adjacent
=>
1903 Check_Floating_Point_Type_2
;
1904 Set_Etype
(N
, P_Base_Type
);
1905 Resolve
(E1
, P_Base_Type
);
1906 Resolve
(E2
, P_Base_Type
);
1912 when Attribute_Aft
=>
1913 Check_Fixed_Point_Type_0
;
1914 Set_Etype
(N
, Universal_Integer
);
1920 when Attribute_Alignment
=>
1922 -- Don't we need more checking here, cf Size ???
1925 Check_Not_Incomplete_Type
;
1926 Set_Etype
(N
, Universal_Integer
);
1932 when Attribute_Asm_Input
=>
1933 Check_Asm_Attribute
;
1934 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1940 when Attribute_Asm_Output
=>
1941 Check_Asm_Attribute
;
1943 if Etype
(E2
) = Any_Type
then
1946 elsif Aname
= Name_Asm_Output
then
1947 if not Is_Variable
(E2
) then
1949 ("second argument for Asm_Output is not variable", E2
);
1953 Note_Possible_Modification
(E2
);
1954 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1960 when Attribute_AST_Entry
=> AST_Entry
: declare
1966 -- Indicates if entry family index is present. Note the coding
1967 -- here handles the entry family case, but in fact it cannot be
1968 -- executed currently, because pragma AST_Entry does not permit
1969 -- the specification of an entry family.
1971 procedure Bad_AST_Entry
;
1972 -- Signal a bad AST_Entry pragma
1974 function OK_Entry
(E
: Entity_Id
) return Boolean;
1975 -- Checks that E is of an appropriate entity kind for an entry
1976 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1977 -- is set True for the entry family case). In the True case,
1978 -- makes sure that Is_AST_Entry is set on the entry.
1980 procedure Bad_AST_Entry
is
1982 Error_Attr
("prefix for % attribute must be task entry", P
);
1985 function OK_Entry
(E
: Entity_Id
) return Boolean is
1990 Result
:= (Ekind
(E
) = E_Entry_Family
);
1992 Result
:= (Ekind
(E
) = E_Entry
);
1996 if not Is_AST_Entry
(E
) then
1997 Error_Msg_Name_2
:= Aname
;
1999 ("% attribute requires previous % pragma", P
);
2006 -- Start of processing for AST_Entry
2012 -- Deal with entry family case
2014 if Nkind
(P
) = N_Indexed_Component
then
2022 Ptyp
:= Etype
(Pref
);
2024 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2028 -- If the prefix is a selected component whose prefix is of an
2029 -- access type, then introduce an explicit dereference.
2030 -- ??? Could we reuse Check_Dereference here?
2032 if Nkind
(Pref
) = N_Selected_Component
2033 and then Is_Access_Type
(Ptyp
)
2036 Make_Explicit_Dereference
(Sloc
(Pref
),
2037 Relocate_Node
(Pref
)));
2038 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2041 -- Prefix can be of the form a.b, where a is a task object
2042 -- and b is one of the entries of the corresponding task type.
2044 if Nkind
(Pref
) = N_Selected_Component
2045 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2046 and then Is_Object_Reference
(Prefix
(Pref
))
2047 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2051 -- Otherwise the prefix must be an entry of a containing task,
2052 -- or of a variable of the enclosing task type.
2055 if Nkind
(Pref
) = N_Identifier
2056 or else Nkind
(Pref
) = N_Expanded_Name
2058 Ent
:= Entity
(Pref
);
2060 if not OK_Entry
(Ent
)
2061 or else not In_Open_Scopes
(Scope
(Ent
))
2071 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2078 -- Note: when the base attribute appears in the context of a subtype
2079 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2080 -- the following circuit.
2082 when Attribute_Base
=> Base
: declare
2086 Check_Either_E0_Or_E1
;
2090 if Ada_Version
>= Ada_95
2091 and then not Is_Scalar_Type
(Typ
)
2092 and then not Is_Generic_Type
(Typ
)
2094 Error_Msg_N
("prefix of Base attribute must be scalar type", N
);
2096 elsif Sloc
(Typ
) = Standard_Location
2097 and then Base_Type
(Typ
) = Typ
2098 and then Warn_On_Redundant_Constructs
2101 ("?redudant attribute, & is its own base type", N
, Typ
);
2104 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2106 -- If we have an expression present, then really this is a conversion
2107 -- and the tree must be reformed. Note that this is one of the cases
2108 -- in which we do a replace rather than a rewrite, because the
2109 -- original tree is junk.
2111 if Present
(E1
) then
2113 Make_Type_Conversion
(Loc
,
2115 Make_Attribute_Reference
(Loc
,
2116 Prefix
=> Prefix
(N
),
2117 Attribute_Name
=> Name_Base
),
2118 Expression
=> Relocate_Node
(E1
)));
2120 -- E1 may be overloaded, and its interpretations preserved
2122 Save_Interps
(E1
, Expression
(N
));
2125 -- For other cases, set the proper type as the entity of the
2126 -- attribute reference, and then rewrite the node to be an
2127 -- occurrence of the referenced base type. This way, no one
2128 -- else in the compiler has to worry about the base attribute.
2131 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2133 New_Reference_To
(Entity
(N
), Loc
));
2142 when Attribute_Bit
=> Bit
:
2146 if not Is_Object_Reference
(P
) then
2147 Error_Attr
("prefix for % attribute must be object", P
);
2149 -- What about the access object cases ???
2155 Set_Etype
(N
, Universal_Integer
);
2162 when Attribute_Bit_Order
=> Bit_Order
:
2167 if not Is_Record_Type
(P_Type
) then
2168 Error_Attr
("prefix of % attribute must be record type", P
);
2171 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2173 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2176 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2179 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2182 -- Reset incorrect indication of staticness
2184 Set_Is_Static_Expression
(N
, False);
2191 -- Note: in generated code, we can have a Bit_Position attribute
2192 -- applied to a (naked) record component (i.e. the prefix is an
2193 -- identifier that references an E_Component or E_Discriminant
2194 -- entity directly, and this is interpreted as expected by Gigi.
2195 -- The following code will not tolerate such usage, but when the
2196 -- expander creates this special case, it marks it as analyzed
2197 -- immediately and sets an appropriate type.
2199 when Attribute_Bit_Position
=>
2201 if Comes_From_Source
(N
) then
2205 Set_Etype
(N
, Universal_Integer
);
2211 when Attribute_Body_Version
=>
2214 Set_Etype
(N
, RTE
(RE_Version_String
));
2220 when Attribute_Callable
=>
2222 Set_Etype
(N
, Standard_Boolean
);
2229 when Attribute_Caller
=> Caller
: declare
2236 if Nkind
(P
) = N_Identifier
2237 or else Nkind
(P
) = N_Expanded_Name
2241 if not Is_Entry
(Ent
) then
2242 Error_Attr
("invalid entry name", N
);
2246 Error_Attr
("invalid entry name", N
);
2250 for J
in reverse 0 .. Scope_Stack
.Last
loop
2251 S
:= Scope_Stack
.Table
(J
).Entity
;
2253 if S
= Scope
(Ent
) then
2254 Error_Attr
("Caller must appear in matching accept or body", N
);
2260 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2267 when Attribute_Ceiling
=>
2268 Check_Floating_Point_Type_1
;
2269 Set_Etype
(N
, P_Base_Type
);
2270 Resolve
(E1
, P_Base_Type
);
2276 when Attribute_Class
=> Class
: declare
2278 Check_Restriction
(No_Dispatch
, N
);
2279 Check_Either_E0_Or_E1
;
2281 -- If we have an expression present, then really this is a conversion
2282 -- and the tree must be reformed into a proper conversion. This is a
2283 -- Replace rather than a Rewrite, because the original tree is junk.
2284 -- If expression is overloaded, propagate interpretations to new one.
2286 if Present
(E1
) then
2288 Make_Type_Conversion
(Loc
,
2290 Make_Attribute_Reference
(Loc
,
2291 Prefix
=> Prefix
(N
),
2292 Attribute_Name
=> Name_Class
),
2293 Expression
=> Relocate_Node
(E1
)));
2295 Save_Interps
(E1
, Expression
(N
));
2298 -- Otherwise we just need to find the proper type
2310 when Attribute_Code_Address
=>
2313 if Nkind
(P
) = N_Attribute_Reference
2314 and then (Attribute_Name
(P
) = Name_Elab_Body
2316 Attribute_Name
(P
) = Name_Elab_Spec
)
2320 elsif not Is_Entity_Name
(P
)
2321 or else (Ekind
(Entity
(P
)) /= E_Function
2323 Ekind
(Entity
(P
)) /= E_Procedure
)
2325 Error_Attr
("invalid prefix for % attribute", P
);
2326 Set_Address_Taken
(Entity
(P
));
2329 Set_Etype
(N
, RTE
(RE_Address
));
2331 --------------------
2332 -- Component_Size --
2333 --------------------
2335 when Attribute_Component_Size
=>
2337 Set_Etype
(N
, Universal_Integer
);
2339 -- Note: unlike other array attributes, unconstrained arrays are OK
2341 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2351 when Attribute_Compose
=>
2352 Check_Floating_Point_Type_2
;
2353 Set_Etype
(N
, P_Base_Type
);
2354 Resolve
(E1
, P_Base_Type
);
2355 Resolve
(E2
, Any_Integer
);
2361 when Attribute_Constrained
=>
2363 Set_Etype
(N
, Standard_Boolean
);
2365 -- Case from RM J.4(2) of constrained applied to private type
2367 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2368 Check_Restriction
(No_Obsolescent_Features
, N
);
2370 if Warn_On_Obsolescent_Feature
then
2372 ("constrained for private type is an " &
2373 "obsolescent feature ('R'M 'J.4)?", N
);
2376 -- If we are within an instance, the attribute must be legal
2377 -- because it was valid in the generic unit. Ditto if this is
2378 -- an inlining of a function declared in an instance.
2381 or else In_Inlined_Body
2385 -- For sure OK if we have a real private type itself, but must
2386 -- be completed, cannot apply Constrained to incomplete type.
2388 elsif Is_Private_Type
(Entity
(P
)) then
2390 -- Note: this is one of the Annex J features that does not
2391 -- generate a warning from -gnatwj, since in fact it seems
2392 -- very useful, and is used in the GNAT runtime.
2394 Check_Not_Incomplete_Type
;
2398 -- Normal (non-obsolescent case) of application to object of
2399 -- a discriminated type.
2402 Check_Object_Reference
(P
);
2404 -- If N does not come from source, then we allow the
2405 -- the attribute prefix to be of a private type whose
2406 -- full type has discriminants. This occurs in cases
2407 -- involving expanded calls to stream attributes.
2409 if not Comes_From_Source
(N
) then
2410 P_Type
:= Underlying_Type
(P_Type
);
2413 -- Must have discriminants or be an access type designating
2414 -- a type with discriminants. If it is a classwide type is
2415 -- has unknown discriminants.
2417 if Has_Discriminants
(P_Type
)
2418 or else Has_Unknown_Discriminants
(P_Type
)
2420 (Is_Access_Type
(P_Type
)
2421 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2425 -- Also allow an object of a generic type if extensions allowed
2426 -- and allow this for any type at all.
2428 elsif (Is_Generic_Type
(P_Type
)
2429 or else Is_Generic_Actual_Type
(P_Type
))
2430 and then Extensions_Allowed
2436 -- Fall through if bad prefix
2439 ("prefix of % attribute must be object of discriminated type", P
);
2445 when Attribute_Copy_Sign
=>
2446 Check_Floating_Point_Type_2
;
2447 Set_Etype
(N
, P_Base_Type
);
2448 Resolve
(E1
, P_Base_Type
);
2449 Resolve
(E2
, P_Base_Type
);
2455 when Attribute_Count
=> Count
:
2464 if Nkind
(P
) = N_Identifier
2465 or else Nkind
(P
) = N_Expanded_Name
2469 if Ekind
(Ent
) /= E_Entry
then
2470 Error_Attr
("invalid entry name", N
);
2473 elsif Nkind
(P
) = N_Indexed_Component
then
2474 if not Is_Entity_Name
(Prefix
(P
))
2475 or else No
(Entity
(Prefix
(P
)))
2476 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2478 if Nkind
(Prefix
(P
)) = N_Selected_Component
2479 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2480 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2484 ("attribute % must apply to entry of current task", P
);
2487 Error_Attr
("invalid entry family name", P
);
2492 Ent
:= Entity
(Prefix
(P
));
2495 elsif Nkind
(P
) = N_Selected_Component
2496 and then Present
(Entity
(Selector_Name
(P
)))
2497 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2500 ("attribute % must apply to entry of current task", P
);
2503 Error_Attr
("invalid entry name", N
);
2507 for J
in reverse 0 .. Scope_Stack
.Last
loop
2508 S
:= Scope_Stack
.Table
(J
).Entity
;
2510 if S
= Scope
(Ent
) then
2511 if Nkind
(P
) = N_Expanded_Name
then
2512 Tsk
:= Entity
(Prefix
(P
));
2514 -- The prefix denotes either the task type, or else a
2515 -- single task whose task type is being analyzed.
2520 or else (not Is_Type
(Tsk
)
2521 and then Etype
(Tsk
) = S
2522 and then not (Comes_From_Source
(S
)))
2527 ("Attribute % must apply to entry of current task", N
);
2533 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2534 and then Ekind
(S
) /= E_Loop
2535 and then Ekind
(S
) /= E_Block
2536 and then Ekind
(S
) /= E_Entry
2537 and then Ekind
(S
) /= E_Entry_Family
2539 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2541 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2542 and then not Has_Completion
(Scope
(Ent
))
2544 Error_Attr
("attribute % can only be used inside body", N
);
2548 if Is_Overloaded
(P
) then
2550 Index
: Interp_Index
;
2554 Get_First_Interp
(P
, Index
, It
);
2556 while Present
(It
.Nam
) loop
2557 if It
.Nam
= Ent
then
2560 -- Ada 2005 (AI-345): Do not consider primitive entry
2561 -- wrappers generated for task or protected types.
2563 elsif Ada_Version
>= Ada_05
2564 and then not Comes_From_Source
(It
.Nam
)
2569 Error_Attr
("ambiguous entry name", N
);
2572 Get_Next_Interp
(Index
, It
);
2577 Set_Etype
(N
, Universal_Integer
);
2580 -----------------------
2581 -- Default_Bit_Order --
2582 -----------------------
2584 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2586 Check_Standard_Prefix
;
2589 if Bytes_Big_Endian
then
2591 Make_Integer_Literal
(Loc
, False_Value
));
2594 Make_Integer_Literal
(Loc
, True_Value
));
2597 Set_Etype
(N
, Universal_Integer
);
2598 Set_Is_Static_Expression
(N
);
2599 end Default_Bit_Order
;
2605 when Attribute_Definite
=>
2606 Legal_Formal_Attribute
;
2612 when Attribute_Delta
=>
2613 Check_Fixed_Point_Type_0
;
2614 Set_Etype
(N
, Universal_Real
);
2620 when Attribute_Denorm
=>
2621 Check_Floating_Point_Type_0
;
2622 Set_Etype
(N
, Standard_Boolean
);
2628 when Attribute_Digits
=>
2632 if not Is_Floating_Point_Type
(P_Type
)
2633 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2636 ("prefix of % attribute must be float or decimal type", P
);
2639 Set_Etype
(N
, Universal_Integer
);
2645 -- Also handles processing for Elab_Spec
2647 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2649 Check_Unit_Name
(P
);
2650 Set_Etype
(N
, Standard_Void_Type
);
2652 -- We have to manually call the expander in this case to get
2653 -- the necessary expansion (normally attributes that return
2654 -- entities are not expanded).
2662 -- Shares processing with Elab_Body
2668 when Attribute_Elaborated
=>
2671 Set_Etype
(N
, Standard_Boolean
);
2677 when Attribute_Emax
=>
2678 Check_Floating_Point_Type_0
;
2679 Set_Etype
(N
, Universal_Integer
);
2685 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2687 if Present
(E1
) then
2689 Check_Discrete_Type
;
2690 Resolve
(E1
, P_Base_Type
);
2693 if not Is_Entity_Name
(P
)
2694 or else (not Is_Object
(Entity
(P
))
2696 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2699 ("prefix of %attribute must be " &
2700 "discrete type/object or enum literal", P
);
2704 Set_Etype
(N
, Universal_Integer
);
2711 when Attribute_Epsilon
=>
2712 Check_Floating_Point_Type_0
;
2713 Set_Etype
(N
, Universal_Real
);
2719 when Attribute_Exponent
=>
2720 Check_Floating_Point_Type_1
;
2721 Set_Etype
(N
, Universal_Integer
);
2722 Resolve
(E1
, P_Base_Type
);
2728 when Attribute_External_Tag
=>
2732 Set_Etype
(N
, Standard_String
);
2734 if not Is_Tagged_Type
(P_Type
) then
2735 Error_Attr
("prefix of % attribute must be tagged", P
);
2742 when Attribute_First
=>
2743 Check_Array_Or_Scalar_Type
;
2749 when Attribute_First_Bit
=>
2751 Set_Etype
(N
, Universal_Integer
);
2757 when Attribute_Fixed_Value
=>
2759 Check_Fixed_Point_Type
;
2760 Resolve
(E1
, Any_Integer
);
2761 Set_Etype
(N
, P_Base_Type
);
2767 when Attribute_Floor
=>
2768 Check_Floating_Point_Type_1
;
2769 Set_Etype
(N
, P_Base_Type
);
2770 Resolve
(E1
, P_Base_Type
);
2776 when Attribute_Fore
=>
2777 Check_Fixed_Point_Type_0
;
2778 Set_Etype
(N
, Universal_Integer
);
2784 when Attribute_Fraction
=>
2785 Check_Floating_Point_Type_1
;
2786 Set_Etype
(N
, P_Base_Type
);
2787 Resolve
(E1
, P_Base_Type
);
2789 -----------------------
2790 -- Has_Access_Values --
2791 -----------------------
2793 when Attribute_Has_Access_Values
=>
2796 Set_Etype
(N
, Standard_Boolean
);
2798 -----------------------
2799 -- Has_Discriminants --
2800 -----------------------
2802 when Attribute_Has_Discriminants
=>
2803 Legal_Formal_Attribute
;
2809 when Attribute_Identity
=>
2813 if Etype
(P
) = Standard_Exception_Type
then
2814 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2816 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
2817 -- task interface class-wide types.
2819 elsif Is_Task_Type
(Etype
(P
))
2820 or else (Is_Access_Type
(Etype
(P
))
2821 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2822 or else (Ada_Version
>= Ada_05
2823 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2824 and then Is_Interface
(Etype
(P
))
2825 and then Is_Task_Interface
(Etype
(P
)))
2828 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2831 if Ada_Version
>= Ada_05
then
2832 Error_Attr
("prefix of % attribute must be an exception, a "
2833 & "task or a task interface class-wide object", P
);
2835 Error_Attr
("prefix of % attribute must be a task or an "
2844 when Attribute_Image
=> Image
:
2846 Set_Etype
(N
, Standard_String
);
2849 if Is_Real_Type
(P_Type
) then
2850 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2851 Error_Msg_Name_1
:= Aname
;
2853 ("(Ada 83) % attribute not allowed for real types", N
);
2857 if Is_Enumeration_Type
(P_Type
) then
2858 Check_Restriction
(No_Enumeration_Maps
, N
);
2862 Resolve
(E1
, P_Base_Type
);
2864 Validate_Non_Static_Attribute_Function_Call
;
2871 when Attribute_Img
=> Img
:
2873 Set_Etype
(N
, Standard_String
);
2875 if not Is_Scalar_Type
(P_Type
)
2876 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2879 ("prefix of % attribute must be scalar object name", N
);
2889 when Attribute_Input
=>
2891 Check_Stream_Attribute
(TSS_Stream_Input
);
2892 Set_Etype
(N
, P_Base_Type
);
2898 when Attribute_Integer_Value
=>
2901 Resolve
(E1
, Any_Fixed
);
2902 Set_Etype
(N
, P_Base_Type
);
2908 when Attribute_Large
=>
2911 Set_Etype
(N
, Universal_Real
);
2917 when Attribute_Last
=>
2918 Check_Array_Or_Scalar_Type
;
2924 when Attribute_Last_Bit
=>
2926 Set_Etype
(N
, Universal_Integer
);
2932 when Attribute_Leading_Part
=>
2933 Check_Floating_Point_Type_2
;
2934 Set_Etype
(N
, P_Base_Type
);
2935 Resolve
(E1
, P_Base_Type
);
2936 Resolve
(E2
, Any_Integer
);
2942 when Attribute_Length
=>
2944 Set_Etype
(N
, Universal_Integer
);
2950 when Attribute_Machine
=>
2951 Check_Floating_Point_Type_1
;
2952 Set_Etype
(N
, P_Base_Type
);
2953 Resolve
(E1
, P_Base_Type
);
2959 when Attribute_Machine_Emax
=>
2960 Check_Floating_Point_Type_0
;
2961 Set_Etype
(N
, Universal_Integer
);
2967 when Attribute_Machine_Emin
=>
2968 Check_Floating_Point_Type_0
;
2969 Set_Etype
(N
, Universal_Integer
);
2971 ----------------------
2972 -- Machine_Mantissa --
2973 ----------------------
2975 when Attribute_Machine_Mantissa
=>
2976 Check_Floating_Point_Type_0
;
2977 Set_Etype
(N
, Universal_Integer
);
2979 -----------------------
2980 -- Machine_Overflows --
2981 -----------------------
2983 when Attribute_Machine_Overflows
=>
2986 Set_Etype
(N
, Standard_Boolean
);
2992 when Attribute_Machine_Radix
=>
2995 Set_Etype
(N
, Universal_Integer
);
2997 ----------------------
2998 -- Machine_Rounding --
2999 ----------------------
3001 when Attribute_Machine_Rounding
=>
3002 Check_Floating_Point_Type_1
;
3003 Set_Etype
(N
, P_Base_Type
);
3004 Resolve
(E1
, P_Base_Type
);
3006 --------------------
3007 -- Machine_Rounds --
3008 --------------------
3010 when Attribute_Machine_Rounds
=>
3013 Set_Etype
(N
, Standard_Boolean
);
3019 when Attribute_Machine_Size
=>
3022 Check_Not_Incomplete_Type
;
3023 Set_Etype
(N
, Universal_Integer
);
3029 when Attribute_Mantissa
=>
3032 Set_Etype
(N
, Universal_Integer
);
3038 when Attribute_Max
=>
3041 Resolve
(E1
, P_Base_Type
);
3042 Resolve
(E2
, P_Base_Type
);
3043 Set_Etype
(N
, P_Base_Type
);
3045 ----------------------------------
3046 -- Max_Size_In_Storage_Elements --
3047 ----------------------------------
3049 when Attribute_Max_Size_In_Storage_Elements
=>
3052 Check_Not_Incomplete_Type
;
3053 Set_Etype
(N
, Universal_Integer
);
3055 -----------------------
3056 -- Maximum_Alignment --
3057 -----------------------
3059 when Attribute_Maximum_Alignment
=>
3060 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3062 --------------------
3063 -- Mechanism_Code --
3064 --------------------
3066 when Attribute_Mechanism_Code
=>
3067 if not Is_Entity_Name
(P
)
3068 or else not Is_Subprogram
(Entity
(P
))
3070 Error_Attr
("prefix of % attribute must be subprogram", P
);
3073 Check_Either_E0_Or_E1
;
3075 if Present
(E1
) then
3076 Resolve
(E1
, Any_Integer
);
3077 Set_Etype
(E1
, Standard_Integer
);
3079 if not Is_Static_Expression
(E1
) then
3080 Flag_Non_Static_Expr
3081 ("expression for parameter number must be static!", E1
);
3084 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3085 or else UI_To_Int
(Intval
(E1
)) < 0
3087 Error_Attr
("invalid parameter number for %attribute", E1
);
3091 Set_Etype
(N
, Universal_Integer
);
3097 when Attribute_Min
=>
3100 Resolve
(E1
, P_Base_Type
);
3101 Resolve
(E2
, P_Base_Type
);
3102 Set_Etype
(N
, P_Base_Type
);
3108 when Attribute_Mod
=>
3110 -- Note: this attribute is only allowed in Ada 2005 mode, but
3111 -- we do not need to test that here, since Mod is only recognized
3112 -- as an attribute name in Ada 2005 mode during the parse.
3115 Check_Modular_Integer_Type
;
3116 Resolve
(E1
, Any_Integer
);
3117 Set_Etype
(N
, P_Base_Type
);
3123 when Attribute_Model
=>
3124 Check_Floating_Point_Type_1
;
3125 Set_Etype
(N
, P_Base_Type
);
3126 Resolve
(E1
, P_Base_Type
);
3132 when Attribute_Model_Emin
=>
3133 Check_Floating_Point_Type_0
;
3134 Set_Etype
(N
, Universal_Integer
);
3140 when Attribute_Model_Epsilon
=>
3141 Check_Floating_Point_Type_0
;
3142 Set_Etype
(N
, Universal_Real
);
3144 --------------------
3145 -- Model_Mantissa --
3146 --------------------
3148 when Attribute_Model_Mantissa
=>
3149 Check_Floating_Point_Type_0
;
3150 Set_Etype
(N
, Universal_Integer
);
3156 when Attribute_Model_Small
=>
3157 Check_Floating_Point_Type_0
;
3158 Set_Etype
(N
, Universal_Real
);
3164 when Attribute_Modulus
=>
3166 Check_Modular_Integer_Type
;
3167 Set_Etype
(N
, Universal_Integer
);
3169 --------------------
3170 -- Null_Parameter --
3171 --------------------
3173 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3174 Parnt
: constant Node_Id
:= Parent
(N
);
3175 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3177 procedure Bad_Null_Parameter
(Msg
: String);
3178 -- Used if bad Null parameter attribute node is found. Issues
3179 -- given error message, and also sets the type to Any_Type to
3180 -- avoid blowups later on from dealing with a junk node.
3182 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3183 -- Called to check that Proc_Ent is imported subprogram
3185 ------------------------
3186 -- Bad_Null_Parameter --
3187 ------------------------
3189 procedure Bad_Null_Parameter
(Msg
: String) is
3191 Error_Msg_N
(Msg
, N
);
3192 Set_Etype
(N
, Any_Type
);
3193 end Bad_Null_Parameter
;
3195 ----------------------
3196 -- Must_Be_Imported --
3197 ----------------------
3199 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3200 Pent
: Entity_Id
:= Proc_Ent
;
3203 while Present
(Alias
(Pent
)) loop
3204 Pent
:= Alias
(Pent
);
3207 -- Ignore check if procedure not frozen yet (we will get
3208 -- another chance when the default parameter is reanalyzed)
3210 if not Is_Frozen
(Pent
) then
3213 elsif not Is_Imported
(Pent
) then
3215 ("Null_Parameter can only be used with imported subprogram");
3220 end Must_Be_Imported
;
3222 -- Start of processing for Null_Parameter
3227 Set_Etype
(N
, P_Type
);
3229 -- Case of attribute used as default expression
3231 if Nkind
(Parnt
) = N_Parameter_Specification
then
3232 Must_Be_Imported
(Defining_Entity
(GParnt
));
3234 -- Case of attribute used as actual for subprogram (positional)
3236 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
3238 Nkind
(Parnt
) = N_Function_Call
)
3239 and then Is_Entity_Name
(Name
(Parnt
))
3241 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3243 -- Case of attribute used as actual for subprogram (named)
3245 elsif Nkind
(Parnt
) = N_Parameter_Association
3246 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
3248 Nkind
(GParnt
) = N_Function_Call
)
3249 and then Is_Entity_Name
(Name
(GParnt
))
3251 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3253 -- Not an allowed case
3257 ("Null_Parameter must be actual or default parameter");
3266 when Attribute_Object_Size
=>
3269 Check_Not_Incomplete_Type
;
3270 Set_Etype
(N
, Universal_Integer
);
3276 when Attribute_Output
=>
3278 Check_Stream_Attribute
(TSS_Stream_Output
);
3279 Set_Etype
(N
, Standard_Void_Type
);
3280 Resolve
(N
, Standard_Void_Type
);
3286 when Attribute_Partition_ID
=>
3289 if P_Type
/= Any_Type
then
3290 if not Is_Library_Level_Entity
(Entity
(P
)) then
3292 ("prefix of % attribute must be library-level entity", P
);
3294 -- The defining entity of prefix should not be declared inside
3295 -- a Pure unit. RM E.1(8).
3296 -- The Is_Pure flag has been set during declaration.
3298 elsif Is_Entity_Name
(P
)
3299 and then Is_Pure
(Entity
(P
))
3302 ("prefix of % attribute must not be declared pure", P
);
3306 Set_Etype
(N
, Universal_Integer
);
3308 -------------------------
3309 -- Passed_By_Reference --
3310 -------------------------
3312 when Attribute_Passed_By_Reference
=>
3315 Set_Etype
(N
, Standard_Boolean
);
3321 when Attribute_Pool_Address
=>
3323 Set_Etype
(N
, RTE
(RE_Address
));
3329 when Attribute_Pos
=>
3330 Check_Discrete_Type
;
3332 Resolve
(E1
, P_Base_Type
);
3333 Set_Etype
(N
, Universal_Integer
);
3339 when Attribute_Position
=>
3341 Set_Etype
(N
, Universal_Integer
);
3347 when Attribute_Pred
=>
3350 Resolve
(E1
, P_Base_Type
);
3351 Set_Etype
(N
, P_Base_Type
);
3353 -- Nothing to do for real type case
3355 if Is_Real_Type
(P_Type
) then
3358 -- If not modular type, test for overflow check required
3361 if not Is_Modular_Integer_Type
(P_Type
)
3362 and then not Range_Checks_Suppressed
(P_Base_Type
)
3364 Enable_Range_Check
(E1
);
3372 when Attribute_Range
=>
3373 Check_Array_Or_Scalar_Type
;
3375 if Ada_Version
= Ada_83
3376 and then Is_Scalar_Type
(P_Type
)
3377 and then Comes_From_Source
(N
)
3380 ("(Ada 83) % attribute not allowed for scalar type", P
);
3387 when Attribute_Range_Length
=>
3388 Check_Discrete_Type
;
3389 Set_Etype
(N
, Universal_Integer
);
3395 when Attribute_Read
=>
3397 Check_Stream_Attribute
(TSS_Stream_Read
);
3398 Set_Etype
(N
, Standard_Void_Type
);
3399 Resolve
(N
, Standard_Void_Type
);
3400 Note_Possible_Modification
(E2
);
3406 when Attribute_Remainder
=>
3407 Check_Floating_Point_Type_2
;
3408 Set_Etype
(N
, P_Base_Type
);
3409 Resolve
(E1
, P_Base_Type
);
3410 Resolve
(E2
, P_Base_Type
);
3416 when Attribute_Round
=>
3418 Check_Decimal_Fixed_Point_Type
;
3419 Set_Etype
(N
, P_Base_Type
);
3421 -- Because the context is universal_real (3.5.10(12)) it is a legal
3422 -- context for a universal fixed expression. This is the only
3423 -- attribute whose functional description involves U_R.
3425 if Etype
(E1
) = Universal_Fixed
then
3427 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3428 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3429 Expression
=> Relocate_Node
(E1
));
3437 Resolve
(E1
, Any_Real
);
3443 when Attribute_Rounding
=>
3444 Check_Floating_Point_Type_1
;
3445 Set_Etype
(N
, P_Base_Type
);
3446 Resolve
(E1
, P_Base_Type
);
3452 when Attribute_Safe_Emax
=>
3453 Check_Floating_Point_Type_0
;
3454 Set_Etype
(N
, Universal_Integer
);
3460 when Attribute_Safe_First
=>
3461 Check_Floating_Point_Type_0
;
3462 Set_Etype
(N
, Universal_Real
);
3468 when Attribute_Safe_Large
=>
3471 Set_Etype
(N
, Universal_Real
);
3477 when Attribute_Safe_Last
=>
3478 Check_Floating_Point_Type_0
;
3479 Set_Etype
(N
, Universal_Real
);
3485 when Attribute_Safe_Small
=>
3488 Set_Etype
(N
, Universal_Real
);
3494 when Attribute_Scale
=>
3496 Check_Decimal_Fixed_Point_Type
;
3497 Set_Etype
(N
, Universal_Integer
);
3503 when Attribute_Scaling
=>
3504 Check_Floating_Point_Type_2
;
3505 Set_Etype
(N
, P_Base_Type
);
3506 Resolve
(E1
, P_Base_Type
);
3512 when Attribute_Signed_Zeros
=>
3513 Check_Floating_Point_Type_0
;
3514 Set_Etype
(N
, Standard_Boolean
);
3520 when Attribute_Size | Attribute_VADS_Size
=>
3523 -- If prefix is parameterless function call, rewrite and resolve
3526 if Is_Entity_Name
(P
)
3527 and then Ekind
(Entity
(P
)) = E_Function
3531 -- Similar processing for a protected function call
3533 elsif Nkind
(P
) = N_Selected_Component
3534 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
3539 if Is_Object_Reference
(P
) then
3540 Check_Object_Reference
(P
);
3542 elsif Is_Entity_Name
(P
)
3543 and then (Is_Type
(Entity
(P
))
3544 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
3548 elsif Nkind
(P
) = N_Type_Conversion
3549 and then not Comes_From_Source
(P
)
3554 Error_Attr
("invalid prefix for % attribute", P
);
3557 Check_Not_Incomplete_Type
;
3558 Set_Etype
(N
, Universal_Integer
);
3564 when Attribute_Small
=>
3567 Set_Etype
(N
, Universal_Real
);
3573 when Attribute_Storage_Pool
=>
3574 if Is_Access_Type
(P_Type
) then
3577 -- Set appropriate entity
3579 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3580 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3582 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3585 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3587 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3588 -- Storage_Pool since this attribute is not defined for such
3589 -- types (RM E.2.3(22)).
3591 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3594 Error_Attr
("prefix of % attribute must be access type", P
);
3601 when Attribute_Storage_Size
=>
3603 if Is_Task_Type
(P_Type
) then
3605 Set_Etype
(N
, Universal_Integer
);
3607 elsif Is_Access_Type
(P_Type
) then
3608 if Is_Entity_Name
(P
)
3609 and then Is_Type
(Entity
(P
))
3613 Set_Etype
(N
, Universal_Integer
);
3615 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3616 -- Storage_Size since this attribute is not defined for
3617 -- such types (RM E.2.3(22)).
3619 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3621 -- The prefix is allowed to be an implicit dereference
3622 -- of an access value designating a task.
3627 Set_Etype
(N
, Universal_Integer
);
3632 ("prefix of % attribute must be access or task type", P
);
3639 when Attribute_Storage_Unit
=>
3640 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3646 when Attribute_Stream_Size
=>
3650 if Is_Entity_Name
(P
)
3651 and then Is_Elementary_Type
(Entity
(P
))
3653 Set_Etype
(N
, Universal_Integer
);
3655 Error_Attr
("invalid prefix for % attribute", P
);
3662 when Attribute_Succ
=>
3665 Resolve
(E1
, P_Base_Type
);
3666 Set_Etype
(N
, P_Base_Type
);
3668 -- Nothing to do for real type case
3670 if Is_Real_Type
(P_Type
) then
3673 -- If not modular type, test for overflow check required
3676 if not Is_Modular_Integer_Type
(P_Type
)
3677 and then not Range_Checks_Suppressed
(P_Base_Type
)
3679 Enable_Range_Check
(E1
);
3687 when Attribute_Tag
=>
3691 if not Is_Tagged_Type
(P_Type
) then
3692 Error_Attr
("prefix of % attribute must be tagged", P
);
3694 -- Next test does not apply to generated code
3695 -- why not, and what does the illegal reference mean???
3697 elsif Is_Object_Reference
(P
)
3698 and then not Is_Class_Wide_Type
(P_Type
)
3699 and then Comes_From_Source
(N
)
3702 ("% attribute can only be applied to objects of class-wide type",
3706 Set_Etype
(N
, RTE
(RE_Tag
));
3712 when Attribute_Target_Name
=> Target_Name
: declare
3713 TN
: constant String := Sdefault
.Target_Name
.all;
3717 Check_Standard_Prefix
;
3722 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
3727 Make_String_Literal
(Loc
,
3728 Strval
=> TN
(TN
'First .. TL
)));
3729 Analyze_And_Resolve
(N
, Standard_String
);
3736 when Attribute_Terminated
=>
3738 Set_Etype
(N
, Standard_Boolean
);
3745 when Attribute_To_Address
=>
3749 if Nkind
(P
) /= N_Identifier
3750 or else Chars
(P
) /= Name_System
3752 Error_Attr
("prefix of %attribute must be System", P
);
3755 Generate_Reference
(RTE
(RE_Address
), P
);
3756 Analyze_And_Resolve
(E1
, Any_Integer
);
3757 Set_Etype
(N
, RTE
(RE_Address
));
3763 when Attribute_Truncation
=>
3764 Check_Floating_Point_Type_1
;
3765 Resolve
(E1
, P_Base_Type
);
3766 Set_Etype
(N
, P_Base_Type
);
3772 when Attribute_Type_Class
=>
3775 Check_Not_Incomplete_Type
;
3776 Set_Etype
(N
, RTE
(RE_Type_Class
));
3782 when Attribute_UET_Address
=>
3784 Check_Unit_Name
(P
);
3785 Set_Etype
(N
, RTE
(RE_Address
));
3787 -----------------------
3788 -- Unbiased_Rounding --
3789 -----------------------
3791 when Attribute_Unbiased_Rounding
=>
3792 Check_Floating_Point_Type_1
;
3793 Set_Etype
(N
, P_Base_Type
);
3794 Resolve
(E1
, P_Base_Type
);
3796 ----------------------
3797 -- Unchecked_Access --
3798 ----------------------
3800 when Attribute_Unchecked_Access
=>
3801 if Comes_From_Source
(N
) then
3802 Check_Restriction
(No_Unchecked_Access
, N
);
3805 Analyze_Access_Attribute
;
3807 -------------------------
3808 -- Unconstrained_Array --
3809 -------------------------
3811 when Attribute_Unconstrained_Array
=>
3814 Check_Not_Incomplete_Type
;
3815 Set_Etype
(N
, Standard_Boolean
);
3817 ------------------------------
3818 -- Universal_Literal_String --
3819 ------------------------------
3821 -- This is a GNAT specific attribute whose prefix must be a named
3822 -- number where the expression is either a single numeric literal,
3823 -- or a numeric literal immediately preceded by a minus sign. The
3824 -- result is equivalent to a string literal containing the text of
3825 -- the literal as it appeared in the source program with a possible
3826 -- leading minus sign.
3828 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3832 if not Is_Entity_Name
(P
)
3833 or else Ekind
(Entity
(P
)) not in Named_Kind
3835 Error_Attr
("prefix for % attribute must be named number", P
);
3842 Src
: Source_Buffer_Ptr
;
3845 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3847 if Nkind
(Expr
) = N_Op_Minus
then
3849 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3854 if Nkind
(Expr
) /= N_Integer_Literal
3855 and then Nkind
(Expr
) /= N_Real_Literal
3858 ("named number for % attribute must be simple literal", N
);
3861 -- Build string literal corresponding to source literal text
3866 Store_String_Char
(Get_Char_Code
('-'));
3870 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3872 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3873 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3877 -- Now we rewrite the attribute with the string literal
3880 Make_String_Literal
(Loc
, End_String
));
3884 end Universal_Literal_String
;
3886 -------------------------
3887 -- Unrestricted_Access --
3888 -------------------------
3890 -- This is a GNAT specific attribute which is like Access except that
3891 -- all scope checks and checks for aliased views are omitted.
3893 when Attribute_Unrestricted_Access
=>
3894 if Comes_From_Source
(N
) then
3895 Check_Restriction
(No_Unchecked_Access
, N
);
3898 if Is_Entity_Name
(P
) then
3899 Set_Address_Taken
(Entity
(P
));
3902 Analyze_Access_Attribute
;
3908 when Attribute_Val
=> Val
: declare
3911 Check_Discrete_Type
;
3912 Resolve
(E1
, Any_Integer
);
3913 Set_Etype
(N
, P_Base_Type
);
3915 -- Note, we need a range check in general, but we wait for the
3916 -- Resolve call to do this, since we want to let Eval_Attribute
3917 -- have a chance to find an static illegality first!
3924 when Attribute_Valid
=>
3927 -- Ignore check for object if we have a 'Valid reference generated
3928 -- by the expanded code, since in some cases valid checks can occur
3929 -- on items that are names, but are not objects (e.g. attributes).
3931 if Comes_From_Source
(N
) then
3932 Check_Object_Reference
(P
);
3935 if not Is_Scalar_Type
(P_Type
) then
3936 Error_Attr
("object for % attribute must be of scalar type", P
);
3939 Set_Etype
(N
, Standard_Boolean
);
3945 when Attribute_Value
=> Value
:
3950 if Is_Enumeration_Type
(P_Type
) then
3951 Check_Restriction
(No_Enumeration_Maps
, N
);
3954 -- Set Etype before resolving expression because expansion of
3955 -- expression may require enclosing type. Note that the type
3956 -- returned by 'Value is the base type of the prefix type.
3958 Set_Etype
(N
, P_Base_Type
);
3959 Validate_Non_Static_Attribute_Function_Call
;
3966 when Attribute_Value_Size
=>
3969 Check_Not_Incomplete_Type
;
3970 Set_Etype
(N
, Universal_Integer
);
3976 when Attribute_Version
=>
3979 Set_Etype
(N
, RTE
(RE_Version_String
));
3985 when Attribute_Wchar_T_Size
=>
3986 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3992 when Attribute_Wide_Image
=> Wide_Image
:
3995 Set_Etype
(N
, Standard_Wide_String
);
3997 Resolve
(E1
, P_Base_Type
);
3998 Validate_Non_Static_Attribute_Function_Call
;
4001 ---------------------
4002 -- Wide_Wide_Image --
4003 ---------------------
4005 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4008 Set_Etype
(N
, Standard_Wide_Wide_String
);
4010 Resolve
(E1
, P_Base_Type
);
4011 Validate_Non_Static_Attribute_Function_Call
;
4012 end Wide_Wide_Image
;
4018 when Attribute_Wide_Value
=> Wide_Value
:
4023 -- Set Etype before resolving expression because expansion
4024 -- of expression may require enclosing type.
4026 Set_Etype
(N
, P_Type
);
4027 Validate_Non_Static_Attribute_Function_Call
;
4030 ---------------------
4031 -- Wide_Wide_Value --
4032 ---------------------
4034 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4039 -- Set Etype before resolving expression because expansion
4040 -- of expression may require enclosing type.
4042 Set_Etype
(N
, P_Type
);
4043 Validate_Non_Static_Attribute_Function_Call
;
4044 end Wide_Wide_Value
;
4046 ---------------------
4047 -- Wide_Wide_Width --
4048 ---------------------
4050 when Attribute_Wide_Wide_Width
=>
4053 Set_Etype
(N
, Universal_Integer
);
4059 when Attribute_Wide_Width
=>
4062 Set_Etype
(N
, Universal_Integer
);
4068 when Attribute_Width
=>
4071 Set_Etype
(N
, Universal_Integer
);
4077 when Attribute_Word_Size
=>
4078 Standard_Attribute
(System_Word_Size
);
4084 when Attribute_Write
=>
4086 Check_Stream_Attribute
(TSS_Stream_Write
);
4087 Set_Etype
(N
, Standard_Void_Type
);
4088 Resolve
(N
, Standard_Void_Type
);
4092 -- All errors raise Bad_Attribute, so that we get out before any further
4093 -- damage occurs when an error is detected (for example, if we check for
4094 -- one attribute expression, and the check succeeds, we want to be able
4095 -- to proceed securely assuming that an expression is in fact present.
4097 -- Note: we set the attribute analyzed in this case to prevent any
4098 -- attempt at reanalysis which could generate spurious error msgs.
4101 when Bad_Attribute
=>
4103 Set_Etype
(N
, Any_Type
);
4105 end Analyze_Attribute
;
4107 --------------------
4108 -- Eval_Attribute --
4109 --------------------
4111 procedure Eval_Attribute
(N
: Node_Id
) is
4112 Loc
: constant Source_Ptr
:= Sloc
(N
);
4113 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4114 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4115 P
: constant Node_Id
:= Prefix
(N
);
4117 C_Type
: constant Entity_Id
:= Etype
(N
);
4118 -- The type imposed by the context
4121 -- First expression, or Empty if none
4124 -- Second expression, or Empty if none
4126 P_Entity
: Entity_Id
;
4127 -- Entity denoted by prefix
4130 -- The type of the prefix
4132 P_Base_Type
: Entity_Id
;
4133 -- The base type of the prefix type
4135 P_Root_Type
: Entity_Id
;
4136 -- The root type of the prefix type
4139 -- True if the result is Static. This is set by the general processing
4140 -- to true if the prefix is static, and all expressions are static. It
4141 -- can be reset as processing continues for particular attributes
4143 Lo_Bound
, Hi_Bound
: Node_Id
;
4144 -- Expressions for low and high bounds of type or array index referenced
4145 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4148 -- Constraint error node used if we have an attribute reference has
4149 -- an argument that raises a constraint error. In this case we replace
4150 -- the attribute with a raise constraint_error node. This is important
4151 -- processing, since otherwise gigi might see an attribute which it is
4152 -- unprepared to deal with.
4154 function Aft_Value
return Nat
;
4155 -- Computes Aft value for current attribute prefix (used by Aft itself
4156 -- and also by Width for computing the Width of a fixed point type).
4158 procedure Check_Expressions
;
4159 -- In case where the attribute is not foldable, the expressions, if
4160 -- any, of the attribute, are in a non-static context. This procedure
4161 -- performs the required additional checks.
4163 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4164 -- Determines if the given type has compile time known bounds. Note
4165 -- that we enter the case statement even in cases where the prefix
4166 -- type does NOT have known bounds, so it is important to guard any
4167 -- attempt to evaluate both bounds with a call to this function.
4169 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4170 -- This procedure is called when the attribute N has a non-static
4171 -- but compile time known value given by Val. It includes the
4172 -- necessary checks for out of range values.
4174 procedure Float_Attribute_Universal_Integer
4183 -- This procedure evaluates a float attribute with no arguments that
4184 -- returns a universal integer result. The parameters give the values
4185 -- for the possible floating-point root types. See ttypef for details.
4186 -- The prefix type is a float type (and is thus not a generic type).
4188 procedure Float_Attribute_Universal_Real
4189 (IEEES_Val
: String;
4196 AAMPL_Val
: String);
4197 -- This procedure evaluates a float attribute with no arguments that
4198 -- returns a universal real result. The parameters give the values
4199 -- required for the possible floating-point root types in string
4200 -- format as real literals with a possible leading minus sign.
4201 -- The prefix type is a float type (and is thus not a generic type).
4203 function Fore_Value
return Nat
;
4204 -- Computes the Fore value for the current attribute prefix, which is
4205 -- known to be a static fixed-point type. Used by Fore and Width.
4207 function Mantissa
return Uint
;
4208 -- Returns the Mantissa value for the prefix type
4210 procedure Set_Bounds
;
4211 -- Used for First, Last and Length attributes applied to an array or
4212 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4213 -- and high bound expressions for the index referenced by the attribute
4214 -- designator (i.e. the first index if no expression is present, and
4215 -- the N'th index if the value N is present as an expression). Also
4216 -- used for First and Last of scalar types. Static is reset to False
4217 -- if the type or index type is not statically constrained.
4219 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4220 -- Verify that the prefix of a potentially static array attribute
4221 -- satisfies the conditions of 4.9 (14).
4227 function Aft_Value
return Nat
is
4233 Delta_Val
:= Delta_Value
(P_Type
);
4235 while Delta_Val
< Ureal_Tenth
loop
4236 Delta_Val
:= Delta_Val
* Ureal_10
;
4237 Result
:= Result
+ 1;
4243 -----------------------
4244 -- Check_Expressions --
4245 -----------------------
4247 procedure Check_Expressions
is
4251 while Present
(E
) loop
4252 Check_Non_Static_Context
(E
);
4255 end Check_Expressions
;
4257 ----------------------------------
4258 -- Compile_Time_Known_Attribute --
4259 ----------------------------------
4261 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4262 T
: constant Entity_Id
:= Etype
(N
);
4265 Fold_Uint
(N
, Val
, False);
4267 -- Check that result is in bounds of the type if it is static
4269 if Is_In_Range
(N
, T
) then
4272 elsif Is_Out_Of_Range
(N
, T
) then
4273 Apply_Compile_Time_Constraint_Error
4274 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4276 elsif not Range_Checks_Suppressed
(T
) then
4277 Enable_Range_Check
(N
);
4280 Set_Do_Range_Check
(N
, False);
4282 end Compile_Time_Known_Attribute
;
4284 -------------------------------
4285 -- Compile_Time_Known_Bounds --
4286 -------------------------------
4288 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4291 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4293 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4294 end Compile_Time_Known_Bounds
;
4296 ---------------------------------------
4297 -- Float_Attribute_Universal_Integer --
4298 ---------------------------------------
4300 procedure Float_Attribute_Universal_Integer
4311 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4314 if Vax_Float
(P_Base_Type
) then
4315 if Digs
= VAXFF_Digits
then
4317 elsif Digs
= VAXDF_Digits
then
4319 else pragma Assert
(Digs
= VAXGF_Digits
);
4323 elsif Is_AAMP_Float
(P_Base_Type
) then
4324 if Digs
= AAMPS_Digits
then
4326 else pragma Assert
(Digs
= AAMPL_Digits
);
4331 if Digs
= IEEES_Digits
then
4333 elsif Digs
= IEEEL_Digits
then
4335 else pragma Assert
(Digs
= IEEEX_Digits
);
4340 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4341 end Float_Attribute_Universal_Integer
;
4343 ------------------------------------
4344 -- Float_Attribute_Universal_Real --
4345 ------------------------------------
4347 procedure Float_Attribute_Universal_Real
4348 (IEEES_Val
: String;
4358 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4361 if Vax_Float
(P_Base_Type
) then
4362 if Digs
= VAXFF_Digits
then
4363 Val
:= Real_Convert
(VAXFF_Val
);
4364 elsif Digs
= VAXDF_Digits
then
4365 Val
:= Real_Convert
(VAXDF_Val
);
4366 else pragma Assert
(Digs
= VAXGF_Digits
);
4367 Val
:= Real_Convert
(VAXGF_Val
);
4370 elsif Is_AAMP_Float
(P_Base_Type
) then
4371 if Digs
= AAMPS_Digits
then
4372 Val
:= Real_Convert
(AAMPS_Val
);
4373 else pragma Assert
(Digs
= AAMPL_Digits
);
4374 Val
:= Real_Convert
(AAMPL_Val
);
4378 if Digs
= IEEES_Digits
then
4379 Val
:= Real_Convert
(IEEES_Val
);
4380 elsif Digs
= IEEEL_Digits
then
4381 Val
:= Real_Convert
(IEEEL_Val
);
4382 else pragma Assert
(Digs
= IEEEX_Digits
);
4383 Val
:= Real_Convert
(IEEEX_Val
);
4387 Set_Sloc
(Val
, Loc
);
4389 Set_Is_Static_Expression
(N
, Static
);
4390 Analyze_And_Resolve
(N
, C_Type
);
4391 end Float_Attribute_Universal_Real
;
4397 -- Note that the Fore calculation is based on the actual values
4398 -- of the bounds, and does not take into account possible rounding.
4400 function Fore_Value
return Nat
is
4401 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4402 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4403 Small
: constant Ureal
:= Small_Value
(P_Type
);
4404 Lo_Real
: constant Ureal
:= Lo
* Small
;
4405 Hi_Real
: constant Ureal
:= Hi
* Small
;
4410 -- Bounds are given in terms of small units, so first compute
4411 -- proper values as reals.
4413 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4416 -- Loop to compute proper value if more than one digit required
4418 while T
>= Ureal_10
loop
4430 -- Table of mantissa values accessed by function Computed using
4433 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4435 -- where D is T'Digits (RM83 3.5.7)
4437 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4479 function Mantissa
return Uint
is
4482 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4489 procedure Set_Bounds
is
4495 -- For a string literal subtype, we have to construct the bounds.
4496 -- Valid Ada code never applies attributes to string literals, but
4497 -- it is convenient to allow the expander to generate attribute
4498 -- references of this type (e.g. First and Last applied to a string
4501 -- Note that the whole point of the E_String_Literal_Subtype is to
4502 -- avoid this construction of bounds, but the cases in which we
4503 -- have to materialize them are rare enough that we don't worry!
4505 -- The low bound is simply the low bound of the base type. The
4506 -- high bound is computed from the length of the string and this
4509 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4510 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4511 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4514 Make_Integer_Literal
(Sloc
(P
),
4516 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4518 Set_Parent
(Hi_Bound
, P
);
4519 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4522 -- For non-array case, just get bounds of scalar type
4524 elsif Is_Scalar_Type
(P_Type
) then
4527 -- For a fixed-point type, we must freeze to get the attributes
4528 -- of the fixed-point type set now so we can reference them.
4530 if Is_Fixed_Point_Type
(P_Type
)
4531 and then not Is_Frozen
(Base_Type
(P_Type
))
4532 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4533 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4535 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4538 -- For array case, get type of proper index
4544 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4547 Indx
:= First_Index
(P_Type
);
4548 for J
in 1 .. Ndim
- 1 loop
4552 -- If no index type, get out (some other error occurred, and
4553 -- we don't have enough information to complete the job!)
4561 Ityp
:= Etype
(Indx
);
4564 -- A discrete range in an index constraint is allowed to be a
4565 -- subtype indication. This is syntactically a pain, but should
4566 -- not propagate to the entity for the corresponding index subtype.
4567 -- After checking that the subtype indication is legal, the range
4568 -- of the subtype indication should be transfered to the entity.
4569 -- The attributes for the bounds should remain the simple retrievals
4570 -- that they are now.
4572 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4573 Hi_Bound
:= Type_High_Bound
(Ityp
);
4575 if not Is_Static_Subtype
(Ityp
) then
4580 -------------------------------
4581 -- Statically_Denotes_Entity --
4582 -------------------------------
4584 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
4588 if not Is_Entity_Name
(N
) then
4595 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
4596 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
4597 end Statically_Denotes_Entity
;
4599 -- Start of processing for Eval_Attribute
4602 -- Acquire first two expressions (at the moment, no attributes
4603 -- take more than two expressions in any case).
4605 if Present
(Expressions
(N
)) then
4606 E1
:= First
(Expressions
(N
));
4613 -- Special processing for cases where the prefix is an object. For
4614 -- this purpose, a string literal counts as an object (attributes
4615 -- of string literals can only appear in generated code).
4617 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
4619 -- For Component_Size, the prefix is an array object, and we apply
4620 -- the attribute to the type of the object. This is allowed for
4621 -- both unconstrained and constrained arrays, since the bounds
4622 -- have no influence on the value of this attribute.
4624 if Id
= Attribute_Component_Size
then
4625 P_Entity
:= Etype
(P
);
4627 -- For First and Last, the prefix is an array object, and we apply
4628 -- the attribute to the type of the array, but we need a constrained
4629 -- type for this, so we use the actual subtype if available.
4631 elsif Id
= Attribute_First
4635 Id
= Attribute_Length
4638 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4641 if Present
(AS
) and then Is_Constrained
(AS
) then
4644 -- If we have an unconstrained type, cannot fold
4652 -- For Size, give size of object if available, otherwise we
4653 -- cannot fold Size.
4655 elsif Id
= Attribute_Size
then
4656 if Is_Entity_Name
(P
)
4657 and then Known_Esize
(Entity
(P
))
4659 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4667 -- For Alignment, give size of object if available, otherwise we
4668 -- cannot fold Alignment.
4670 elsif Id
= Attribute_Alignment
then
4671 if Is_Entity_Name
(P
)
4672 and then Known_Alignment
(Entity
(P
))
4674 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
4682 -- No other attributes for objects are folded
4689 -- Cases where P is not an object. Cannot do anything if P is
4690 -- not the name of an entity.
4692 elsif not Is_Entity_Name
(P
) then
4696 -- Otherwise get prefix entity
4699 P_Entity
:= Entity
(P
);
4702 -- At this stage P_Entity is the entity to which the attribute
4703 -- is to be applied. This is usually simply the entity of the
4704 -- prefix, except in some cases of attributes for objects, where
4705 -- as described above, we apply the attribute to the object type.
4707 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4708 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4709 -- Note we allow non-static non-generic types at this stage as further
4712 if Is_Type
(P_Entity
)
4713 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4714 and then (not Is_Generic_Type
(P_Entity
))
4718 -- Second foldable possibility is an array object (RM 4.9(8))
4720 elsif (Ekind
(P_Entity
) = E_Variable
4722 Ekind
(P_Entity
) = E_Constant
)
4723 and then Is_Array_Type
(Etype
(P_Entity
))
4724 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4726 P_Type
:= Etype
(P_Entity
);
4728 -- If the entity is an array constant with an unconstrained
4729 -- nominal subtype then get the type from the initial value.
4730 -- If the value has been expanded into assignments, the expression
4731 -- is not present and the attribute reference remains dynamic.
4732 -- We could do better here and retrieve the type ???
4734 if Ekind
(P_Entity
) = E_Constant
4735 and then not Is_Constrained
(P_Type
)
4737 if No
(Constant_Value
(P_Entity
)) then
4740 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4744 -- Definite must be folded if the prefix is not a generic type,
4745 -- that is to say if we are within an instantiation. Same processing
4746 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4747 -- and Unconstrained_Array.
4749 elsif (Id
= Attribute_Definite
4751 Id
= Attribute_Has_Access_Values
4753 Id
= Attribute_Has_Discriminants
4755 Id
= Attribute_Type_Class
4757 Id
= Attribute_Unconstrained_Array
)
4758 and then not Is_Generic_Type
(P_Entity
)
4762 -- We can fold 'Size applied to a type if the size is known
4763 -- (as happens for a size from an attribute definition clause).
4764 -- At this stage, this can happen only for types (e.g. record
4765 -- types) for which the size is always non-static. We exclude
4766 -- generic types from consideration (since they have bogus
4767 -- sizes set within templates).
4769 elsif Id
= Attribute_Size
4770 and then Is_Type
(P_Entity
)
4771 and then (not Is_Generic_Type
(P_Entity
))
4772 and then Known_Static_RM_Size
(P_Entity
)
4774 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4777 -- We can fold 'Alignment applied to a type if the alignment is known
4778 -- (as happens for an alignment from an attribute definition clause).
4779 -- At this stage, this can happen only for types (e.g. record
4780 -- types) for which the size is always non-static. We exclude
4781 -- generic types from consideration (since they have bogus
4782 -- sizes set within templates).
4784 elsif Id
= Attribute_Alignment
4785 and then Is_Type
(P_Entity
)
4786 and then (not Is_Generic_Type
(P_Entity
))
4787 and then Known_Alignment
(P_Entity
)
4789 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
4792 -- If this is an access attribute that is known to fail accessibility
4793 -- check, rewrite accordingly.
4795 elsif Attribute_Name
(N
) = Name_Access
4796 and then Raises_Constraint_Error
(N
)
4799 Make_Raise_Program_Error
(Loc
,
4800 Reason
=> PE_Accessibility_Check_Failed
));
4801 Set_Etype
(N
, C_Type
);
4804 -- No other cases are foldable (they certainly aren't static, and at
4805 -- the moment we don't try to fold any cases other than these three).
4812 -- If either attribute or the prefix is Any_Type, then propagate
4813 -- Any_Type to the result and don't do anything else at all.
4815 if P_Type
= Any_Type
4816 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4817 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4819 Set_Etype
(N
, Any_Type
);
4823 -- Scalar subtype case. We have not yet enforced the static requirement
4824 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4825 -- of non-static attribute references (e.g. S'Digits for a non-static
4826 -- floating-point type, which we can compute at compile time).
4828 -- Note: this folding of non-static attributes is not simply a case of
4829 -- optimization. For many of the attributes affected, Gigi cannot handle
4830 -- the attribute and depends on the front end having folded them away.
4832 -- Note: although we don't require staticness at this stage, we do set
4833 -- the Static variable to record the staticness, for easy reference by
4834 -- those attributes where it matters (e.g. Succ and Pred), and also to
4835 -- be used to ensure that non-static folded things are not marked as
4836 -- being static (a check that is done right at the end).
4838 P_Root_Type
:= Root_Type
(P_Type
);
4839 P_Base_Type
:= Base_Type
(P_Type
);
4841 -- If the root type or base type is generic, then we cannot fold. This
4842 -- test is needed because subtypes of generic types are not always
4843 -- marked as being generic themselves (which seems odd???)
4845 if Is_Generic_Type
(P_Root_Type
)
4846 or else Is_Generic_Type
(P_Base_Type
)
4851 if Is_Scalar_Type
(P_Type
) then
4852 Static
:= Is_OK_Static_Subtype
(P_Type
);
4854 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4855 -- since we can't do anything with unconstrained arrays. In addition,
4856 -- only the First, Last and Length attributes are possibly static.
4858 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
4859 -- Unconstrained_Array are again exceptions, because they apply as
4860 -- well to unconstrained types.
4862 -- In addition Component_Size is an exception since it is possibly
4863 -- foldable, even though it is never static, and it does apply to
4864 -- unconstrained arrays. Furthermore, it is essential to fold this
4865 -- in the packed case, since otherwise the value will be incorrect.
4867 elsif Id
= Attribute_Definite
4869 Id
= Attribute_Has_Access_Values
4871 Id
= Attribute_Has_Discriminants
4873 Id
= Attribute_Type_Class
4875 Id
= Attribute_Unconstrained_Array
4877 Id
= Attribute_Component_Size
4882 if not Is_Constrained
(P_Type
)
4883 or else (Id
/= Attribute_First
and then
4884 Id
/= Attribute_Last
and then
4885 Id
/= Attribute_Length
)
4891 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4892 -- scalar case, we hold off on enforcing staticness, since there are
4893 -- cases which we can fold at compile time even though they are not
4894 -- static (e.g. 'Length applied to a static index, even though other
4895 -- non-static indexes make the array type non-static). This is only
4896 -- an optimization, but it falls out essentially free, so why not.
4897 -- Again we compute the variable Static for easy reference later
4898 -- (note that no array attributes are static in Ada 83).
4900 Static
:= Ada_Version
>= Ada_95
4901 and then Statically_Denotes_Entity
(P
);
4907 N
:= First_Index
(P_Type
);
4908 while Present
(N
) loop
4909 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
4911 -- If however the index type is generic, attributes cannot
4914 if Is_Generic_Type
(Etype
(N
))
4915 and then Id
/= Attribute_Component_Size
4925 -- Check any expressions that are present. Note that these expressions,
4926 -- depending on the particular attribute type, are either part of the
4927 -- attribute designator, or they are arguments in a case where the
4928 -- attribute reference returns a function. In the latter case, the
4929 -- rule in (RM 4.9(22)) applies and in particular requires the type
4930 -- of the expressions to be scalar in order for the attribute to be
4931 -- considered to be static.
4938 while Present
(E
) loop
4940 -- If expression is not static, then the attribute reference
4941 -- result certainly cannot be static.
4943 if not Is_Static_Expression
(E
) then
4947 -- If the result is not known at compile time, or is not of
4948 -- a scalar type, then the result is definitely not static,
4949 -- so we can quit now.
4951 if not Compile_Time_Known_Value
(E
)
4952 or else not Is_Scalar_Type
(Etype
(E
))
4954 -- An odd special case, if this is a Pos attribute, this
4955 -- is where we need to apply a range check since it does
4956 -- not get done anywhere else.
4958 if Id
= Attribute_Pos
then
4959 if Is_Integer_Type
(Etype
(E
)) then
4960 Apply_Range_Check
(E
, Etype
(N
));
4967 -- If the expression raises a constraint error, then so does
4968 -- the attribute reference. We keep going in this case because
4969 -- we are still interested in whether the attribute reference
4970 -- is static even if it is not static.
4972 elsif Raises_Constraint_Error
(E
) then
4973 Set_Raises_Constraint_Error
(N
);
4979 if Raises_Constraint_Error
(Prefix
(N
)) then
4984 -- Deal with the case of a static attribute reference that raises
4985 -- constraint error. The Raises_Constraint_Error flag will already
4986 -- have been set, and the Static flag shows whether the attribute
4987 -- reference is static. In any case we certainly can't fold such an
4988 -- attribute reference.
4990 -- Note that the rewriting of the attribute node with the constraint
4991 -- error node is essential in this case, because otherwise Gigi might
4992 -- blow up on one of the attributes it never expects to see.
4994 -- The constraint_error node must have the type imposed by the context,
4995 -- to avoid spurious errors in the enclosing expression.
4997 if Raises_Constraint_Error
(N
) then
4999 Make_Raise_Constraint_Error
(Sloc
(N
),
5000 Reason
=> CE_Range_Check_Failed
);
5001 Set_Etype
(CE_Node
, Etype
(N
));
5002 Set_Raises_Constraint_Error
(CE_Node
);
5004 Rewrite
(N
, Relocate_Node
(CE_Node
));
5005 Set_Is_Static_Expression
(N
, Static
);
5009 -- At this point we have a potentially foldable attribute reference.
5010 -- If Static is set, then the attribute reference definitely obeys
5011 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5012 -- folded. If Static is not set, then the attribute may or may not
5013 -- be foldable, and the individual attribute processing routines
5014 -- test Static as required in cases where it makes a difference.
5016 -- In the case where Static is not set, we do know that all the
5017 -- expressions present are at least known at compile time (we
5018 -- assumed above that if this was not the case, then there was
5019 -- no hope of static evaluation). However, we did not require
5020 -- that the bounds of the prefix type be compile time known,
5021 -- let alone static). That's because there are many attributes
5022 -- that can be computed at compile time on non-static subtypes,
5023 -- even though such references are not static expressions.
5031 when Attribute_Adjacent
=>
5034 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5040 when Attribute_Aft
=>
5041 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5047 when Attribute_Alignment
=> Alignment_Block
: declare
5048 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5051 -- Fold if alignment is set and not otherwise
5053 if Known_Alignment
(P_TypeA
) then
5054 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5056 end Alignment_Block
;
5062 -- Can only be folded in No_Ast_Handler case
5064 when Attribute_AST_Entry
=>
5065 if not Is_AST_Entry
(P_Entity
) then
5067 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5076 -- Bit can never be folded
5078 when Attribute_Bit
=>
5085 -- Body_version can never be static
5087 when Attribute_Body_Version
=>
5094 when Attribute_Ceiling
=>
5096 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5098 --------------------
5099 -- Component_Size --
5100 --------------------
5102 when Attribute_Component_Size
=>
5103 if Known_Static_Component_Size
(P_Type
) then
5104 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5111 when Attribute_Compose
=>
5114 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5121 -- Constrained is never folded for now, there may be cases that
5122 -- could be handled at compile time. to be looked at later.
5124 when Attribute_Constrained
=>
5131 when Attribute_Copy_Sign
=>
5134 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5140 when Attribute_Delta
=>
5141 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5147 when Attribute_Definite
=>
5148 Rewrite
(N
, New_Occurrence_Of
(
5149 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5150 Analyze_And_Resolve
(N
, Standard_Boolean
);
5156 when Attribute_Denorm
=>
5158 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5164 when Attribute_Digits
=>
5165 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5171 when Attribute_Emax
=>
5173 -- Ada 83 attribute is defined as (RM83 3.5.8)
5175 -- T'Emax = 4 * T'Mantissa
5177 Fold_Uint
(N
, 4 * Mantissa
, True);
5183 when Attribute_Enum_Rep
=>
5185 -- For an enumeration type with a non-standard representation use
5186 -- the Enumeration_Rep field of the proper constant. Note that this
5187 -- will not work for types Character/Wide_[Wide-]Character, since no
5188 -- real entities are created for the enumeration literals, but that
5189 -- does not matter since these two types do not have non-standard
5190 -- representations anyway.
5192 if Is_Enumeration_Type
(P_Type
)
5193 and then Has_Non_Standard_Rep
(P_Type
)
5195 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5197 -- For enumeration types with standard representations and all
5198 -- other cases (i.e. all integer and modular types), Enum_Rep
5199 -- is equivalent to Pos.
5202 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5209 when Attribute_Epsilon
=>
5211 -- Ada 83 attribute is defined as (RM83 3.5.8)
5213 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5215 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5221 when Attribute_Exponent
=>
5223 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5229 when Attribute_First
=> First_Attr
:
5233 if Compile_Time_Known_Value
(Lo_Bound
) then
5234 if Is_Real_Type
(P_Type
) then
5235 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5237 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5246 when Attribute_Fixed_Value
=>
5253 when Attribute_Floor
=>
5255 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5261 when Attribute_Fore
=>
5262 if Compile_Time_Known_Bounds
(P_Type
) then
5263 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5270 when Attribute_Fraction
=>
5272 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5274 -----------------------
5275 -- Has_Access_Values --
5276 -----------------------
5278 when Attribute_Has_Access_Values
=>
5279 Rewrite
(N
, New_Occurrence_Of
5280 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5281 Analyze_And_Resolve
(N
, Standard_Boolean
);
5283 -----------------------
5284 -- Has_Discriminants --
5285 -----------------------
5287 when Attribute_Has_Discriminants
=>
5288 Rewrite
(N
, New_Occurrence_Of
(
5289 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5290 Analyze_And_Resolve
(N
, Standard_Boolean
);
5296 when Attribute_Identity
=>
5303 -- Image is a scalar attribute, but is never static, because it is
5304 -- not a static function (having a non-scalar argument (RM 4.9(22))
5306 when Attribute_Image
=>
5313 -- Img is a scalar attribute, but is never static, because it is
5314 -- not a static function (having a non-scalar argument (RM 4.9(22))
5316 when Attribute_Img
=>
5323 when Attribute_Integer_Value
=>
5330 when Attribute_Large
=>
5332 -- For fixed-point, we use the identity:
5334 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5336 if Is_Fixed_Point_Type
(P_Type
) then
5338 Make_Op_Multiply
(Loc
,
5340 Make_Op_Subtract
(Loc
,
5344 Make_Real_Literal
(Loc
, Ureal_2
),
5346 Make_Attribute_Reference
(Loc
,
5348 Attribute_Name
=> Name_Mantissa
)),
5349 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5352 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5354 Analyze_And_Resolve
(N
, C_Type
);
5356 -- Floating-point (Ada 83 compatibility)
5359 -- Ada 83 attribute is defined as (RM83 3.5.8)
5361 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5365 -- T'Emax = 4 * T'Mantissa
5368 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5376 when Attribute_Last
=> Last
:
5380 if Compile_Time_Known_Value
(Hi_Bound
) then
5381 if Is_Real_Type
(P_Type
) then
5382 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5384 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5393 when Attribute_Leading_Part
=>
5395 Eval_Fat
.Leading_Part
5396 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5402 when Attribute_Length
=> Length
: declare
5406 -- In the case of a generic index type, the bounds may
5407 -- appear static but the computation is not meaningful,
5408 -- and may generate a spurious warning.
5410 Ind
:= First_Index
(P_Type
);
5412 while Present
(Ind
) loop
5413 if Is_Generic_Type
(Etype
(Ind
)) then
5422 if Compile_Time_Known_Value
(Lo_Bound
)
5423 and then Compile_Time_Known_Value
(Hi_Bound
)
5426 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
5435 when Attribute_Machine
=>
5438 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
5445 when Attribute_Machine_Emax
=>
5446 Float_Attribute_Universal_Integer
(
5454 AAMPL_Machine_Emax
);
5460 when Attribute_Machine_Emin
=>
5461 Float_Attribute_Universal_Integer
(
5469 AAMPL_Machine_Emin
);
5471 ----------------------
5472 -- Machine_Mantissa --
5473 ----------------------
5475 when Attribute_Machine_Mantissa
=>
5476 Float_Attribute_Universal_Integer
(
5477 IEEES_Machine_Mantissa
,
5478 IEEEL_Machine_Mantissa
,
5479 IEEEX_Machine_Mantissa
,
5480 VAXFF_Machine_Mantissa
,
5481 VAXDF_Machine_Mantissa
,
5482 VAXGF_Machine_Mantissa
,
5483 AAMPS_Machine_Mantissa
,
5484 AAMPL_Machine_Mantissa
);
5486 -----------------------
5487 -- Machine_Overflows --
5488 -----------------------
5490 when Attribute_Machine_Overflows
=>
5492 -- Always true for fixed-point
5494 if Is_Fixed_Point_Type
(P_Type
) then
5495 Fold_Uint
(N
, True_Value
, True);
5497 -- Floating point case
5501 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
5509 when Attribute_Machine_Radix
=>
5510 if Is_Fixed_Point_Type
(P_Type
) then
5511 if Is_Decimal_Fixed_Point_Type
(P_Type
)
5512 and then Machine_Radix_10
(P_Type
)
5514 Fold_Uint
(N
, Uint_10
, True);
5516 Fold_Uint
(N
, Uint_2
, True);
5519 -- All floating-point type always have radix 2
5522 Fold_Uint
(N
, Uint_2
, True);
5525 ----------------------
5526 -- Machine_Rounding --
5527 ----------------------
5529 -- Note: for the folding case, it is fine to treat Machine_Rounding
5530 -- exactly the same way as Rounding, since this is one of the allowed
5531 -- behaviors, and performance is not an issue here. It might be a bit
5532 -- better to give the same result as it would give at run-time, even
5533 -- though the non-determinism is certainly permitted.
5535 when Attribute_Machine_Rounding
=>
5537 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5539 --------------------
5540 -- Machine_Rounds --
5541 --------------------
5543 when Attribute_Machine_Rounds
=>
5545 -- Always False for fixed-point
5547 if Is_Fixed_Point_Type
(P_Type
) then
5548 Fold_Uint
(N
, False_Value
, True);
5550 -- Else yield proper floating-point result
5554 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
5561 -- Note: Machine_Size is identical to Object_Size
5563 when Attribute_Machine_Size
=> Machine_Size
: declare
5564 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5567 if Known_Esize
(P_TypeA
) then
5568 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5576 when Attribute_Mantissa
=>
5578 -- Fixed-point mantissa
5580 if Is_Fixed_Point_Type
(P_Type
) then
5582 -- Compile time foldable case
5584 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5586 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5588 -- The calculation of the obsolete Ada 83 attribute Mantissa
5589 -- is annoying, because of AI00143, quoted here:
5591 -- !question 84-01-10
5593 -- Consider the model numbers for F:
5595 -- type F is delta 1.0 range -7.0 .. 8.0;
5597 -- The wording requires that F'MANTISSA be the SMALLEST
5598 -- integer number for which each bound of the specified
5599 -- range is either a model number or lies at most small
5600 -- distant from a model number. This means F'MANTISSA
5601 -- is required to be 3 since the range -7.0 .. 7.0 fits
5602 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5603 -- number, namely, 7. Is this analysis correct? Note that
5604 -- this implies the upper bound of the range is not
5605 -- represented as a model number.
5607 -- !response 84-03-17
5609 -- The analysis is correct. The upper and lower bounds for
5610 -- a fixed point type can lie outside the range of model
5621 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5622 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5623 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5624 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5626 -- If the Bound is exactly a model number, i.e. a multiple
5627 -- of Small, then we back it off by one to get the integer
5628 -- value that must be representable.
5630 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5631 Max_Man
:= Max_Man
- 1;
5634 -- Now find corresponding size = Mantissa value
5637 while 2 ** Siz
< Max_Man
loop
5641 Fold_Uint
(N
, Siz
, True);
5645 -- The case of dynamic bounds cannot be evaluated at compile
5646 -- time. Instead we use a runtime routine (see Exp_Attr).
5651 -- Floating-point Mantissa
5654 Fold_Uint
(N
, Mantissa
, True);
5661 when Attribute_Max
=> Max
:
5663 if Is_Real_Type
(P_Type
) then
5665 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5667 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5671 ----------------------------------
5672 -- Max_Size_In_Storage_Elements --
5673 ----------------------------------
5675 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5676 -- Storage_Unit boundary. We can fold any cases for which the size
5677 -- is known by the front end.
5679 when Attribute_Max_Size_In_Storage_Elements
=>
5680 if Known_Esize
(P_Type
) then
5682 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5683 System_Storage_Unit
,
5687 --------------------
5688 -- Mechanism_Code --
5689 --------------------
5691 when Attribute_Mechanism_Code
=>
5695 Mech
: Mechanism_Type
;
5699 Mech
:= Mechanism
(P_Entity
);
5702 Val
:= UI_To_Int
(Expr_Value
(E1
));
5704 Formal
:= First_Formal
(P_Entity
);
5705 for J
in 1 .. Val
- 1 loop
5706 Next_Formal
(Formal
);
5708 Mech
:= Mechanism
(Formal
);
5712 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
5720 when Attribute_Min
=> Min
:
5722 if Is_Real_Type
(P_Type
) then
5724 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5727 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5735 when Attribute_Mod
=>
5737 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
5743 when Attribute_Model
=>
5745 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5751 when Attribute_Model_Emin
=>
5752 Float_Attribute_Universal_Integer
(
5766 when Attribute_Model_Epsilon
=>
5767 Float_Attribute_Universal_Real
(
5768 IEEES_Model_Epsilon
'Universal_Literal_String,
5769 IEEEL_Model_Epsilon
'Universal_Literal_String,
5770 IEEEX_Model_Epsilon
'Universal_Literal_String,
5771 VAXFF_Model_Epsilon
'Universal_Literal_String,
5772 VAXDF_Model_Epsilon
'Universal_Literal_String,
5773 VAXGF_Model_Epsilon
'Universal_Literal_String,
5774 AAMPS_Model_Epsilon
'Universal_Literal_String,
5775 AAMPL_Model_Epsilon
'Universal_Literal_String);
5777 --------------------
5778 -- Model_Mantissa --
5779 --------------------
5781 when Attribute_Model_Mantissa
=>
5782 Float_Attribute_Universal_Integer
(
5783 IEEES_Model_Mantissa
,
5784 IEEEL_Model_Mantissa
,
5785 IEEEX_Model_Mantissa
,
5786 VAXFF_Model_Mantissa
,
5787 VAXDF_Model_Mantissa
,
5788 VAXGF_Model_Mantissa
,
5789 AAMPS_Model_Mantissa
,
5790 AAMPL_Model_Mantissa
);
5796 when Attribute_Model_Small
=>
5797 Float_Attribute_Universal_Real
(
5798 IEEES_Model_Small
'Universal_Literal_String,
5799 IEEEL_Model_Small
'Universal_Literal_String,
5800 IEEEX_Model_Small
'Universal_Literal_String,
5801 VAXFF_Model_Small
'Universal_Literal_String,
5802 VAXDF_Model_Small
'Universal_Literal_String,
5803 VAXGF_Model_Small
'Universal_Literal_String,
5804 AAMPS_Model_Small
'Universal_Literal_String,
5805 AAMPL_Model_Small
'Universal_Literal_String);
5811 when Attribute_Modulus
=>
5812 Fold_Uint
(N
, Modulus
(P_Type
), True);
5814 --------------------
5815 -- Null_Parameter --
5816 --------------------
5818 -- Cannot fold, we know the value sort of, but the whole point is
5819 -- that there is no way to talk about this imaginary value except
5820 -- by using the attribute, so we leave it the way it is.
5822 when Attribute_Null_Parameter
=>
5829 -- The Object_Size attribute for a type returns the Esize of the
5830 -- type and can be folded if this value is known.
5832 when Attribute_Object_Size
=> Object_Size
: declare
5833 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5836 if Known_Esize
(P_TypeA
) then
5837 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5841 -------------------------
5842 -- Passed_By_Reference --
5843 -------------------------
5845 -- Scalar types are never passed by reference
5847 when Attribute_Passed_By_Reference
=>
5848 Fold_Uint
(N
, False_Value
, True);
5854 when Attribute_Pos
=>
5855 Fold_Uint
(N
, Expr_Value
(E1
), True);
5861 when Attribute_Pred
=> Pred
:
5863 -- Floating-point case
5865 if Is_Floating_Point_Type
(P_Type
) then
5867 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5871 elsif Is_Fixed_Point_Type
(P_Type
) then
5873 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
5875 -- Modular integer case (wraps)
5877 elsif Is_Modular_Integer_Type
(P_Type
) then
5878 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
5880 -- Other scalar cases
5883 pragma Assert
(Is_Scalar_Type
(P_Type
));
5885 if Is_Enumeration_Type
(P_Type
)
5886 and then Expr_Value
(E1
) =
5887 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5889 Apply_Compile_Time_Constraint_Error
5890 (N
, "Pred of `&''First`",
5891 CE_Overflow_Check_Failed
,
5893 Warn
=> not Static
);
5899 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
5907 -- No processing required, because by this stage, Range has been
5908 -- replaced by First .. Last, so this branch can never be taken.
5910 when Attribute_Range
=>
5911 raise Program_Error
;
5917 when Attribute_Range_Length
=>
5920 if Compile_Time_Known_Value
(Hi_Bound
)
5921 and then Compile_Time_Known_Value
(Lo_Bound
)
5925 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
5933 when Attribute_Remainder
=> Remainder
: declare
5934 X
: constant Ureal
:= Expr_Value_R
(E1
);
5935 Y
: constant Ureal
:= Expr_Value_R
(E2
);
5938 if UR_Is_Zero
(Y
) then
5939 Apply_Compile_Time_Constraint_Error
5940 (N
, "division by zero in Remainder",
5941 CE_Overflow_Check_Failed
,
5942 Warn
=> not Static
);
5948 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
5955 when Attribute_Round
=> Round
:
5961 -- First we get the (exact result) in units of small
5963 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5965 -- Now round that exactly to an integer
5967 Si
:= UR_To_Uint
(Sr
);
5969 -- Finally the result is obtained by converting back to real
5971 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
5978 when Attribute_Rounding
=>
5980 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5986 when Attribute_Safe_Emax
=>
5987 Float_Attribute_Universal_Integer
(
6001 when Attribute_Safe_First
=>
6002 Float_Attribute_Universal_Real
(
6003 IEEES_Safe_First
'Universal_Literal_String,
6004 IEEEL_Safe_First
'Universal_Literal_String,
6005 IEEEX_Safe_First
'Universal_Literal_String,
6006 VAXFF_Safe_First
'Universal_Literal_String,
6007 VAXDF_Safe_First
'Universal_Literal_String,
6008 VAXGF_Safe_First
'Universal_Literal_String,
6009 AAMPS_Safe_First
'Universal_Literal_String,
6010 AAMPL_Safe_First
'Universal_Literal_String);
6016 when Attribute_Safe_Large
=>
6017 if Is_Fixed_Point_Type
(P_Type
) then
6019 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
6021 Float_Attribute_Universal_Real
(
6022 IEEES_Safe_Large
'Universal_Literal_String,
6023 IEEEL_Safe_Large
'Universal_Literal_String,
6024 IEEEX_Safe_Large
'Universal_Literal_String,
6025 VAXFF_Safe_Large
'Universal_Literal_String,
6026 VAXDF_Safe_Large
'Universal_Literal_String,
6027 VAXGF_Safe_Large
'Universal_Literal_String,
6028 AAMPS_Safe_Large
'Universal_Literal_String,
6029 AAMPL_Safe_Large
'Universal_Literal_String);
6036 when Attribute_Safe_Last
=>
6037 Float_Attribute_Universal_Real
(
6038 IEEES_Safe_Last
'Universal_Literal_String,
6039 IEEEL_Safe_Last
'Universal_Literal_String,
6040 IEEEX_Safe_Last
'Universal_Literal_String,
6041 VAXFF_Safe_Last
'Universal_Literal_String,
6042 VAXDF_Safe_Last
'Universal_Literal_String,
6043 VAXGF_Safe_Last
'Universal_Literal_String,
6044 AAMPS_Safe_Last
'Universal_Literal_String,
6045 AAMPL_Safe_Last
'Universal_Literal_String);
6051 when Attribute_Safe_Small
=>
6053 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6054 -- for fixed-point, since is the same as Small, but we implement
6055 -- it for backwards compatibility.
6057 if Is_Fixed_Point_Type
(P_Type
) then
6058 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6060 -- Ada 83 Safe_Small for floating-point cases
6063 Float_Attribute_Universal_Real
(
6064 IEEES_Safe_Small
'Universal_Literal_String,
6065 IEEEL_Safe_Small
'Universal_Literal_String,
6066 IEEEX_Safe_Small
'Universal_Literal_String,
6067 VAXFF_Safe_Small
'Universal_Literal_String,
6068 VAXDF_Safe_Small
'Universal_Literal_String,
6069 VAXGF_Safe_Small
'Universal_Literal_String,
6070 AAMPS_Safe_Small
'Universal_Literal_String,
6071 AAMPL_Safe_Small
'Universal_Literal_String);
6078 when Attribute_Scale
=>
6079 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6085 when Attribute_Scaling
=>
6088 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6094 when Attribute_Signed_Zeros
=>
6096 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6102 -- Size attribute returns the RM size. All scalar types can be folded,
6103 -- as well as any types for which the size is known by the front end,
6104 -- including any type for which a size attribute is specified.
6106 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6107 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6110 if RM_Size
(P_TypeA
) /= Uint_0
then
6114 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6116 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6119 -- If a size clause applies, then use the size from it.
6120 -- This is one of the rare cases where we can use the
6121 -- Size_Clause field for a subtype when Has_Size_Clause
6122 -- is False. Consider:
6124 -- type x is range 1 .. 64;
6125 -- for x'size use 12;
6126 -- subtype y is x range 0 .. 3;
6128 -- Here y has a size clause inherited from x, but normally
6129 -- it does not apply, and y'size is 2. However, y'VADS_Size
6130 -- is indeed 12 and not 2.
6133 and then Is_OK_Static_Expression
(Expression
(S
))
6135 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6137 -- If no size is specified, then we simply use the object
6138 -- size in the VADS_Size case (e.g. Natural'Size is equal
6139 -- to Integer'Size, not one less).
6142 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6146 -- Normal case (Size) in which case we want the RM_Size
6151 Static
and then Is_Discrete_Type
(P_TypeA
));
6160 when Attribute_Small
=>
6162 -- The floating-point case is present only for Ada 83 compatability.
6163 -- Note that strictly this is an illegal addition, since we are
6164 -- extending an Ada 95 defined attribute, but we anticipate an
6165 -- ARG ruling that will permit this.
6167 if Is_Floating_Point_Type
(P_Type
) then
6169 -- Ada 83 attribute is defined as (RM83 3.5.8)
6171 -- T'Small = 2.0**(-T'Emax - 1)
6175 -- T'Emax = 4 * T'Mantissa
6177 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6179 -- Normal Ada 95 fixed-point case
6182 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6189 when Attribute_Stream_Size
=>
6196 when Attribute_Succ
=> Succ
:
6198 -- Floating-point case
6200 if Is_Floating_Point_Type
(P_Type
) then
6202 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6206 elsif Is_Fixed_Point_Type
(P_Type
) then
6208 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6210 -- Modular integer case (wraps)
6212 elsif Is_Modular_Integer_Type
(P_Type
) then
6213 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6215 -- Other scalar cases
6218 pragma Assert
(Is_Scalar_Type
(P_Type
));
6220 if Is_Enumeration_Type
(P_Type
)
6221 and then Expr_Value
(E1
) =
6222 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6224 Apply_Compile_Time_Constraint_Error
6225 (N
, "Succ of `&''Last`",
6226 CE_Overflow_Check_Failed
,
6228 Warn
=> not Static
);
6233 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6242 when Attribute_Truncation
=>
6244 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6250 when Attribute_Type_Class
=> Type_Class
: declare
6251 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6255 if Is_Descendent_Of_Address
(Typ
) then
6256 Id
:= RE_Type_Class_Address
;
6258 elsif Is_Enumeration_Type
(Typ
) then
6259 Id
:= RE_Type_Class_Enumeration
;
6261 elsif Is_Integer_Type
(Typ
) then
6262 Id
:= RE_Type_Class_Integer
;
6264 elsif Is_Fixed_Point_Type
(Typ
) then
6265 Id
:= RE_Type_Class_Fixed_Point
;
6267 elsif Is_Floating_Point_Type
(Typ
) then
6268 Id
:= RE_Type_Class_Floating_Point
;
6270 elsif Is_Array_Type
(Typ
) then
6271 Id
:= RE_Type_Class_Array
;
6273 elsif Is_Record_Type
(Typ
) then
6274 Id
:= RE_Type_Class_Record
;
6276 elsif Is_Access_Type
(Typ
) then
6277 Id
:= RE_Type_Class_Access
;
6279 elsif Is_Enumeration_Type
(Typ
) then
6280 Id
:= RE_Type_Class_Enumeration
;
6282 elsif Is_Task_Type
(Typ
) then
6283 Id
:= RE_Type_Class_Task
;
6285 -- We treat protected types like task types. It would make more
6286 -- sense to have another enumeration value, but after all the
6287 -- whole point of this feature is to be exactly DEC compatible,
6288 -- and changing the type Type_Clas would not meet this requirement.
6290 elsif Is_Protected_Type
(Typ
) then
6291 Id
:= RE_Type_Class_Task
;
6293 -- Not clear if there are any other possibilities, but if there
6294 -- are, then we will treat them as the address case.
6297 Id
:= RE_Type_Class_Address
;
6300 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6303 -----------------------
6304 -- Unbiased_Rounding --
6305 -----------------------
6307 when Attribute_Unbiased_Rounding
=>
6309 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
6312 -------------------------
6313 -- Unconstrained_Array --
6314 -------------------------
6316 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
6317 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6320 Rewrite
(N
, New_Occurrence_Of
(
6322 Is_Array_Type
(P_Type
)
6323 and then not Is_Constrained
(Typ
)), Loc
));
6325 -- Analyze and resolve as boolean, note that this attribute is
6326 -- a static attribute in GNAT.
6328 Analyze_And_Resolve
(N
, Standard_Boolean
);
6330 end Unconstrained_Array
;
6336 -- Processing is shared with Size
6342 when Attribute_Val
=> Val
:
6344 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6346 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
6348 Apply_Compile_Time_Constraint_Error
6349 (N
, "Val expression out of range",
6350 CE_Range_Check_Failed
,
6351 Warn
=> not Static
);
6357 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6365 -- The Value_Size attribute for a type returns the RM size of the
6366 -- type. This an always be folded for scalar types, and can also
6367 -- be folded for non-scalar types if the size is set.
6369 when Attribute_Value_Size
=> Value_Size
: declare
6370 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6373 if RM_Size
(P_TypeA
) /= Uint_0
then
6374 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6383 -- Version can never be static
6385 when Attribute_Version
=>
6392 -- Wide_Image is a scalar attribute, but is never static, because it
6393 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6395 when Attribute_Wide_Image
=>
6398 ---------------------
6399 -- Wide_Wide_Image --
6400 ---------------------
6402 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6403 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6405 when Attribute_Wide_Wide_Image
=>
6408 ---------------------
6409 -- Wide_Wide_Width --
6410 ---------------------
6412 -- Processing for Wide_Wide_Width is combined with Width
6418 -- Processing for Wide_Width is combined with Width
6424 -- This processing also handles the case of Wide_[Wide_]Width
6426 when Attribute_Width |
6427 Attribute_Wide_Width |
6428 Attribute_Wide_Wide_Width
=> Width
:
6430 if Compile_Time_Known_Bounds
(P_Type
) then
6432 -- Floating-point types
6434 if Is_Floating_Point_Type
(P_Type
) then
6436 -- Width is zero for a null range (RM 3.5 (38))
6438 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
6439 Expr_Value_R
(Type_Low_Bound
(P_Type
))
6441 Fold_Uint
(N
, Uint_0
, True);
6444 -- For floating-point, we have +N.dddE+nnn where length
6445 -- of ddd is determined by type'Digits - 1, but is one
6446 -- if Digits is one (RM 3.5 (33)).
6448 -- nnn is set to 2 for Short_Float and Float (32 bit
6449 -- floats), and 3 for Long_Float and Long_Long_Float.
6450 -- This is not quite right, but is good enough.
6454 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
6457 if Esize
(P_Type
) <= 32 then
6463 Fold_Uint
(N
, UI_From_Int
(Len
), True);
6467 -- Fixed-point types
6469 elsif Is_Fixed_Point_Type
(P_Type
) then
6471 -- Width is zero for a null range (RM 3.5 (38))
6473 if Expr_Value
(Type_High_Bound
(P_Type
)) <
6474 Expr_Value
(Type_Low_Bound
(P_Type
))
6476 Fold_Uint
(N
, Uint_0
, True);
6478 -- The non-null case depends on the specific real type
6481 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6484 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
6491 R
: constant Entity_Id
:= Root_Type
(P_Type
);
6492 Lo
: constant Uint
:=
6493 Expr_Value
(Type_Low_Bound
(P_Type
));
6494 Hi
: constant Uint
:=
6495 Expr_Value
(Type_High_Bound
(P_Type
));
6508 -- Width for types derived from Standard.Character
6509 -- and Standard.Wide_[Wide_]Character.
6511 elsif R
= Standard_Character
6512 or else R
= Standard_Wide_Character
6513 or else R
= Standard_Wide_Wide_Character
6517 -- Set W larger if needed
6519 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
6521 -- All wide characters look like Hex_hhhhhhhh
6527 C
:= Character'Val (J
);
6529 -- Test for all cases where Character'Image
6530 -- yields an image that is longer than three
6531 -- characters. First the cases of Reserved_xxx
6532 -- names (length = 12).
6535 when Reserved_128 | Reserved_129 |
6536 Reserved_132 | Reserved_153
6540 when BS | HT | LF | VT | FF | CR |
6541 SO | SI | EM | FS | GS | RS |
6542 US | RI | MW | ST | PM
6546 when NUL | SOH | STX | ETX | EOT |
6547 ENQ | ACK | BEL | DLE | DC1 |
6548 DC2 | DC3 | DC4 | NAK | SYN |
6549 ETB | CAN | SUB | ESC | DEL |
6550 BPH | NBH | NEL | SSA | ESA |
6551 HTS | HTJ | VTS | PLD | PLU |
6552 SS2 | SS3 | DCS | PU1 | PU2 |
6553 STS | CCH | SPA | EPA | SOS |
6554 SCI | CSI | OSC | APC
6558 when Space
.. Tilde |
6559 No_Break_Space
.. LC_Y_Diaeresis
6564 W
:= Int
'Max (W
, Wt
);
6568 -- Width for types derived from Standard.Boolean
6570 elsif R
= Standard_Boolean
then
6577 -- Width for integer types
6579 elsif Is_Integer_Type
(P_Type
) then
6580 T
:= UI_Max
(abs Lo
, abs Hi
);
6588 -- Only remaining possibility is user declared enum type
6591 pragma Assert
(Is_Enumeration_Type
(P_Type
));
6594 L
:= First_Literal
(P_Type
);
6596 while Present
(L
) loop
6598 -- Only pay attention to in range characters
6600 if Lo
<= Enumeration_Pos
(L
)
6601 and then Enumeration_Pos
(L
) <= Hi
6603 -- For Width case, use decoded name
6605 if Id
= Attribute_Width
then
6606 Get_Decoded_Name_String
(Chars
(L
));
6607 Wt
:= Nat
(Name_Len
);
6609 -- For Wide_[Wide_]Width, use encoded name, and
6610 -- then adjust for the encoding.
6613 Get_Name_String
(Chars
(L
));
6615 -- Character literals are always of length 3
6617 if Name_Buffer
(1) = 'Q' then
6620 -- Otherwise loop to adjust for upper/wide chars
6623 Wt
:= Nat
(Name_Len
);
6625 for J
in 1 .. Name_Len
loop
6626 if Name_Buffer
(J
) = 'U' then
6628 elsif Name_Buffer
(J
) = 'W' then
6635 W
:= Int
'Max (W
, Wt
);
6642 Fold_Uint
(N
, UI_From_Int
(W
), True);
6648 -- The following attributes can never be folded, and furthermore we
6649 -- should not even have entered the case statement for any of these.
6650 -- Note that in some cases, the values have already been folded as
6651 -- a result of the processing in Analyze_Attribute.
6653 when Attribute_Abort_Signal |
6656 Attribute_Address_Size |
6657 Attribute_Asm_Input |
6658 Attribute_Asm_Output |
6660 Attribute_Bit_Order |
6661 Attribute_Bit_Position |
6662 Attribute_Callable |
6665 Attribute_Code_Address |
6667 Attribute_Default_Bit_Order |
6668 Attribute_Elaborated |
6669 Attribute_Elab_Body |
6670 Attribute_Elab_Spec |
6671 Attribute_External_Tag |
6672 Attribute_First_Bit |
6674 Attribute_Last_Bit |
6675 Attribute_Maximum_Alignment |
6677 Attribute_Partition_ID |
6678 Attribute_Pool_Address |
6679 Attribute_Position |
6681 Attribute_Storage_Pool |
6682 Attribute_Storage_Size |
6683 Attribute_Storage_Unit |
6685 Attribute_Target_Name |
6686 Attribute_Terminated |
6687 Attribute_To_Address |
6688 Attribute_UET_Address |
6689 Attribute_Unchecked_Access |
6690 Attribute_Universal_Literal_String |
6691 Attribute_Unrestricted_Access |
6694 Attribute_Wchar_T_Size |
6695 Attribute_Wide_Value |
6696 Attribute_Wide_Wide_Value |
6697 Attribute_Word_Size |
6700 raise Program_Error
;
6703 -- At the end of the case, one more check. If we did a static evaluation
6704 -- so that the result is now a literal, then set Is_Static_Expression
6705 -- in the constant only if the prefix type is a static subtype. For
6706 -- non-static subtypes, the folding is still OK, but not static.
6708 -- An exception is the GNAT attribute Constrained_Array which is
6709 -- defined to be a static attribute in all cases.
6711 if Nkind
(N
) = N_Integer_Literal
6712 or else Nkind
(N
) = N_Real_Literal
6713 or else Nkind
(N
) = N_Character_Literal
6714 or else Nkind
(N
) = N_String_Literal
6715 or else (Is_Entity_Name
(N
)
6716 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6718 Set_Is_Static_Expression
(N
, Static
);
6720 -- If this is still an attribute reference, then it has not been folded
6721 -- and that means that its expressions are in a non-static context.
6723 elsif Nkind
(N
) = N_Attribute_Reference
then
6726 -- Note: the else case not covered here are odd cases where the
6727 -- processing has transformed the attribute into something other
6728 -- than a constant. Nothing more to do in such cases.
6736 ------------------------------
6737 -- Is_Anonymous_Tagged_Base --
6738 ------------------------------
6740 function Is_Anonymous_Tagged_Base
6747 Anon
= Current_Scope
6748 and then Is_Itype
(Anon
)
6749 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6750 end Is_Anonymous_Tagged_Base
;
6752 -----------------------
6753 -- Resolve_Attribute --
6754 -----------------------
6756 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6757 Loc
: constant Source_Ptr
:= Sloc
(N
);
6758 P
: constant Node_Id
:= Prefix
(N
);
6759 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6760 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6761 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6762 Index
: Interp_Index
;
6764 Nom_Subt
: Entity_Id
;
6766 procedure Accessibility_Message
;
6767 -- Error, or warning within an instance, if the static accessibility
6768 -- rules of 3.10.2 are violated.
6770 ---------------------------
6771 -- Accessibility_Message --
6772 ---------------------------
6774 procedure Accessibility_Message
is
6775 Indic
: Node_Id
:= Parent
(Parent
(N
));
6778 -- In an instance, this is a runtime check, but one we
6779 -- know will fail, so generate an appropriate warning.
6781 if In_Instance_Body
then
6783 ("?non-local pointer cannot point to local object", P
);
6785 ("?Program_Error will be raised at run time", P
);
6787 Make_Raise_Program_Error
(Loc
,
6788 Reason
=> PE_Accessibility_Check_Failed
));
6794 ("non-local pointer cannot point to local object", P
);
6796 -- Check for case where we have a missing access definition
6798 if Is_Record_Type
(Current_Scope
)
6800 (Nkind
(Parent
(N
)) = N_Discriminant_Association
6802 Nkind
(Parent
(N
)) = N_Index_Or_Discriminant_Constraint
)
6804 Indic
:= Parent
(Parent
(N
));
6805 while Present
(Indic
)
6806 and then Nkind
(Indic
) /= N_Subtype_Indication
6808 Indic
:= Parent
(Indic
);
6811 if Present
(Indic
) then
6813 ("\use an access definition for" &
6814 " the access discriminant of&", N
,
6815 Entity
(Subtype_Mark
(Indic
)));
6819 end Accessibility_Message
;
6821 -- Start of processing for Resolve_Attribute
6824 -- If error during analysis, no point in continuing, except for
6825 -- array types, where we get better recovery by using unconstrained
6826 -- indices than nothing at all (see Check_Array_Type).
6829 and then Attr_Id
/= Attribute_First
6830 and then Attr_Id
/= Attribute_Last
6831 and then Attr_Id
/= Attribute_Length
6832 and then Attr_Id
/= Attribute_Range
6837 -- If attribute was universal type, reset to actual type
6839 if Etype
(N
) = Universal_Integer
6840 or else Etype
(N
) = Universal_Real
6845 -- Remaining processing depends on attribute
6853 -- For access attributes, if the prefix denotes an entity, it is
6854 -- interpreted as a name, never as a call. It may be overloaded,
6855 -- in which case resolution uses the profile of the context type.
6856 -- Otherwise prefix must be resolved.
6858 when Attribute_Access
6859 | Attribute_Unchecked_Access
6860 | Attribute_Unrestricted_Access
=>
6862 if Is_Variable
(P
) then
6863 Note_Possible_Modification
(P
);
6866 if Is_Entity_Name
(P
) then
6867 if Is_Overloaded
(P
) then
6868 Get_First_Interp
(P
, Index
, It
);
6870 while Present
(It
.Nam
) loop
6872 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6873 Set_Entity
(P
, It
.Nam
);
6875 -- The prefix is definitely NOT overloaded anymore
6876 -- at this point, so we reset the Is_Overloaded
6877 -- flag to avoid any confusion when reanalyzing
6880 Set_Is_Overloaded
(P
, False);
6881 Generate_Reference
(Entity
(P
), P
);
6885 Get_Next_Interp
(Index
, It
);
6888 -- If it is a subprogram name or a type, there is nothing
6891 elsif not Is_Overloadable
(Entity
(P
))
6892 and then not Is_Type
(Entity
(P
))
6897 Error_Msg_Name_1
:= Aname
;
6899 if not Is_Entity_Name
(P
) then
6902 elsif Is_Abstract
(Entity
(P
))
6903 and then Is_Overloadable
(Entity
(P
))
6905 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6906 Set_Etype
(N
, Any_Type
);
6908 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6909 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6911 ("prefix of % attribute cannot be enumeration literal",
6915 ("prefix of % attribute cannot be intrinsic", P
);
6918 Set_Etype
(N
, Any_Type
);
6920 elsif Is_Thread_Body
(Entity
(P
)) then
6922 ("prefix of % attribute cannot be a thread body", P
);
6925 -- Assignments, return statements, components of aggregates,
6926 -- generic instantiations will require convention checks if
6927 -- the type is an access to subprogram. Given that there will
6928 -- also be accessibility checks on those, this is where the
6929 -- checks can eventually be centralized ???
6931 if Ekind
(Btyp
) = E_Access_Subprogram_Type
6933 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
6935 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
6937 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6939 ("subprogram has invalid convention for context", P
);
6942 Check_Subtype_Conformant
6943 (New_Id
=> Entity
(P
),
6944 Old_Id
=> Designated_Type
(Btyp
),
6948 if Attr_Id
= Attribute_Unchecked_Access
then
6949 Error_Msg_Name_1
:= Aname
;
6951 ("attribute% cannot be applied to a subprogram", P
);
6953 elsif Aname
= Name_Unrestricted_Access
then
6954 null; -- Nothing to check
6956 -- Check the static accessibility rule of 3.10.2(32)
6957 -- In an instance body, if subprogram and type are both
6958 -- local, other rules prevent dangling references, and no
6959 -- warning is needed.
6961 elsif Attr_Id
= Attribute_Access
6962 and then Subprogram_Access_Level
(Entity
(P
)) >
6963 Type_Access_Level
(Btyp
)
6964 and then Ekind
(Btyp
) /=
6965 E_Anonymous_Access_Subprogram_Type
6966 and then Ekind
(Btyp
) /=
6967 E_Anonymous_Access_Protected_Subprogram_Type
6969 if not In_Instance_Body
then
6971 ("subprogram must not be deeper than access type",
6974 elsif Scope
(Entity
(P
)) /= Scope
(Btyp
) then
6976 ("subprogram must not be deeper than access type?",
6979 ("Constraint_Error will be raised ?", P
);
6980 Set_Raises_Constraint_Error
(N
);
6983 -- Check the restriction of 3.10.2(32) that disallows
6984 -- the type of the access attribute to be declared
6985 -- outside a generic body when the subprogram is declared
6986 -- within that generic body.
6988 -- Ada2005: If the expected type is for an access
6989 -- parameter, this clause does not apply.
6991 elsif Present
(Enclosing_Generic_Body
(Entity
(P
)))
6992 and then Enclosing_Generic_Body
(Entity
(P
)) /=
6993 Enclosing_Generic_Body
(Btyp
)
6995 Ekind
(Btyp
) /= E_Anonymous_Access_Subprogram_Type
6998 ("access type must not be outside generic body", P
);
7002 -- If this is a renaming, an inherited operation, or a
7003 -- subprogram instance, use the original entity.
7005 if Is_Entity_Name
(P
)
7006 and then Is_Overloadable
(Entity
(P
))
7007 and then Present
(Alias
(Entity
(P
)))
7010 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7013 elsif Nkind
(P
) = N_Selected_Component
7014 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
7016 -- Protected operation. If operation is overloaded, must
7017 -- disambiguate. Prefix that denotes protected object itself
7018 -- is resolved with its own type.
7020 if Attr_Id
= Attribute_Unchecked_Access
then
7021 Error_Msg_Name_1
:= Aname
;
7023 ("attribute% cannot be applied to protected operation", P
);
7026 Resolve
(Prefix
(P
));
7027 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
7029 elsif Is_Overloaded
(P
) then
7031 -- Use the designated type of the context to disambiguate
7032 -- Note that this was not strictly conformant to Ada 95,
7033 -- but was the implementation adopted by most Ada 95 compilers.
7034 -- The use of the context type to resolve an Access attribute
7035 -- reference is now mandated in AI-235 for Ada 2005.
7038 Index
: Interp_Index
;
7042 Get_First_Interp
(P
, Index
, It
);
7043 while Present
(It
.Typ
) loop
7044 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
7045 Resolve
(P
, It
.Typ
);
7049 Get_Next_Interp
(Index
, It
);
7056 -- X'Access is illegal if X denotes a constant and the access
7057 -- type is access-to-variable. Same for 'Unchecked_Access.
7058 -- The rule does not apply to 'Unrestricted_Access.
7060 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7061 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7062 or else (Is_Record_Type
(Btyp
) and then
7063 Present
(Corresponding_Remote_Type
(Btyp
)))
7064 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7065 or else Ekind
(Btyp
)
7066 = E_Anonymous_Access_Protected_Subprogram_Type
7067 or else Is_Access_Constant
(Btyp
)
7068 or else Is_Variable
(P
)
7069 or else Attr_Id
= Attribute_Unrestricted_Access
)
7071 if Comes_From_Source
(N
) then
7072 Error_Msg_N
("access-to-variable designates constant", P
);
7076 if (Attr_Id
= Attribute_Access
7078 Attr_Id
= Attribute_Unchecked_Access
)
7079 and then (Ekind
(Btyp
) = E_General_Access_Type
7080 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7082 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7083 -- access types in record and array components. For a
7084 -- component definition the level is the same of the
7085 -- enclosing composite type.
7087 if Ada_Version
>= Ada_05
7088 and then Is_Local_Anonymous_Access
(Btyp
)
7089 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7091 -- In an instance, this is a runtime check, but one we
7092 -- know will fail, so generate an appropriate warning.
7094 if In_Instance_Body
then
7096 ("?non-local pointer cannot point to local object", P
);
7098 ("?Program_Error will be raised at run time", P
);
7100 Make_Raise_Program_Error
(Loc
,
7101 Reason
=> PE_Accessibility_Check_Failed
));
7105 ("non-local pointer cannot point to local object", P
);
7109 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7111 ("illegal attribute for discriminant-dependent component",
7115 -- Check the static matching rule of 3.10.2(27). The
7116 -- nominal subtype of the prefix must statically
7117 -- match the designated type.
7119 Nom_Subt
:= Etype
(P
);
7121 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7122 Nom_Subt
:= Etype
(Nom_Subt
);
7125 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7127 -- If the attribute is in the context of an access
7128 -- parameter, then the prefix is allowed to be of
7129 -- the class-wide type (by AI-127).
7131 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7132 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7133 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7139 Desig
:= Designated_Type
(Typ
);
7141 if Is_Class_Wide_Type
(Desig
) then
7142 Desig
:= Etype
(Desig
);
7145 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
7150 ("type of prefix: & not compatible",
7153 ("\with &, the expected designated type",
7154 P
, Designated_Type
(Typ
));
7159 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7161 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
7162 and then Is_Class_Wide_Type
(Nom_Subt
))
7165 ("type of prefix: & is not covered", P
, Nom_Subt
);
7167 ("\by &, the expected designated type" &
7168 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
7171 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
7172 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
7173 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
7174 and then Designated_Type
(Typ
) /= Nom_Subt
7176 Apply_Discriminant_Check
7177 (N
, Etype
(Designated_Type
(Typ
)));
7180 elsif not Subtypes_Statically_Match
7181 (Designated_Type
(Base_Type
(Typ
)), Nom_Subt
)
7183 not (Has_Discriminants
(Designated_Type
(Typ
))
7186 (Designated_Type
(Base_Type
(Typ
))))
7189 ("object subtype must statically match "
7190 & "designated subtype", P
);
7192 if Is_Entity_Name
(P
)
7193 and then Is_Array_Type
(Designated_Type
(Typ
))
7197 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
7200 Error_Msg_N
("aliased object has explicit bounds?",
7202 Error_Msg_N
("\declare without bounds"
7203 & " (and with explicit initialization)?", D
);
7204 Error_Msg_N
("\for use with unconstrained access?", D
);
7209 -- Check the static accessibility rule of 3.10.2(28).
7210 -- Note that this check is not performed for the
7211 -- case of an anonymous access type, since the access
7212 -- attribute is always legal in such a context.
7214 if Attr_Id
/= Attribute_Unchecked_Access
7215 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7216 and then Ekind
(Btyp
) = E_General_Access_Type
7218 Accessibility_Message
;
7223 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7225 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7227 if Is_Entity_Name
(P
)
7228 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
7230 Error_Msg_N
("context requires a protected subprogram", P
);
7232 -- Check accessibility of protected object against that
7233 -- of the access type, but only on user code, because
7234 -- the expander creates access references for handlers.
7235 -- If the context is an anonymous_access_to_protected,
7236 -- there are no accessibility checks either.
7238 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7239 and then Comes_From_Source
(N
)
7240 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7241 and then No
(Original_Access_Type
(Typ
))
7243 Accessibility_Message
;
7247 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
7249 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
7250 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
7252 Error_Msg_N
("context requires a non-protected subprogram", P
);
7255 -- The context cannot be a pool-specific type, but this is a
7256 -- legality rule, not a resolution rule, so it must be checked
7257 -- separately, after possibly disambiguation (see AI-245).
7259 if Ekind
(Btyp
) = E_Access_Type
7260 and then Attr_Id
/= Attribute_Unrestricted_Access
7262 Wrong_Type
(N
, Typ
);
7267 -- Check for incorrect atomic/volatile reference (RM C.6(12))
7269 if Attr_Id
/= Attribute_Unrestricted_Access
then
7270 if Is_Atomic_Object
(P
)
7271 and then not Is_Atomic
(Designated_Type
(Typ
))
7274 ("access to atomic object cannot yield access-to-" &
7275 "non-atomic type", P
);
7277 elsif Is_Volatile_Object
(P
)
7278 and then not Is_Volatile
(Designated_Type
(Typ
))
7281 ("access to volatile object cannot yield access-to-" &
7282 "non-volatile type", P
);
7290 -- Deal with resolving the type for Address attribute, overloading
7291 -- is not permitted here, since there is no context to resolve it.
7293 when Attribute_Address | Attribute_Code_Address
=>
7295 -- To be safe, assume that if the address of a variable is taken,
7296 -- it may be modified via this address, so note modification.
7298 if Is_Variable
(P
) then
7299 Note_Possible_Modification
(P
);
7302 if Nkind
(P
) in N_Subexpr
7303 and then Is_Overloaded
(P
)
7305 Get_First_Interp
(P
, Index
, It
);
7306 Get_Next_Interp
(Index
, It
);
7308 if Present
(It
.Nam
) then
7309 Error_Msg_Name_1
:= Aname
;
7311 ("prefix of % attribute cannot be overloaded", P
);
7316 if not Is_Entity_Name
(P
)
7317 or else not Is_Overloadable
(Entity
(P
))
7319 if not Is_Task_Type
(Etype
(P
))
7320 or else Nkind
(P
) = N_Explicit_Dereference
7326 -- If this is the name of a derived subprogram, or that of a
7327 -- generic actual, the address is that of the original entity.
7329 if Is_Entity_Name
(P
)
7330 and then Is_Overloadable
(Entity
(P
))
7331 and then Present
(Alias
(Entity
(P
)))
7334 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7341 -- Prefix of the AST_Entry attribute is an entry name which must
7342 -- not be resolved, since this is definitely not an entry call.
7344 when Attribute_AST_Entry
=>
7351 -- Prefix of Body_Version attribute can be a subprogram name which
7352 -- must not be resolved, since this is not a call.
7354 when Attribute_Body_Version
=>
7361 -- Prefix of Caller attribute is an entry name which must not
7362 -- be resolved, since this is definitely not an entry call.
7364 when Attribute_Caller
=>
7371 -- Shares processing with Address attribute
7377 -- If the prefix of the Count attribute is an entry name it must not
7378 -- be resolved, since this is definitely not an entry call. However,
7379 -- if it is an element of an entry family, the index itself may
7380 -- have to be resolved because it can be a general expression.
7382 when Attribute_Count
=>
7383 if Nkind
(P
) = N_Indexed_Component
7384 and then Is_Entity_Name
(Prefix
(P
))
7387 Indx
: constant Node_Id
:= First
(Expressions
(P
));
7388 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
7390 Resolve
(Indx
, Entry_Index_Type
(Fam
));
7391 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
7399 -- Prefix of the Elaborated attribute is a subprogram name which
7400 -- must not be resolved, since this is definitely not a call. Note
7401 -- that it is a library unit, so it cannot be overloaded here.
7403 when Attribute_Elaborated
=>
7406 --------------------
7407 -- Mechanism_Code --
7408 --------------------
7410 -- Prefix of the Mechanism_Code attribute is a function name
7411 -- which must not be resolved. Should we check for overloaded ???
7413 when Attribute_Mechanism_Code
=>
7420 -- Most processing is done in sem_dist, after determining the
7421 -- context type. Node is rewritten as a conversion to a runtime call.
7423 when Attribute_Partition_ID
=>
7424 Process_Partition_Id
(N
);
7427 when Attribute_Pool_Address
=>
7434 -- We replace the Range attribute node with a range expression
7435 -- whose bounds are the 'First and 'Last attributes applied to the
7436 -- same prefix. The reason that we do this transformation here
7437 -- instead of in the expander is that it simplifies other parts of
7438 -- the semantic analysis which assume that the Range has been
7439 -- replaced; thus it must be done even when in semantic-only mode
7440 -- (note that the RM specifically mentions this equivalence, we
7441 -- take care that the prefix is only evaluated once).
7443 when Attribute_Range
=> Range_Attribute
:
7448 function Check_Discriminated_Prival
7451 -- The range of a private component constrained by a
7452 -- discriminant is rewritten to make the discriminant
7453 -- explicit. This solves some complex visibility problems
7454 -- related to the use of privals.
7456 --------------------------------
7457 -- Check_Discriminated_Prival --
7458 --------------------------------
7460 function Check_Discriminated_Prival
7465 if Is_Entity_Name
(N
)
7466 and then Ekind
(Entity
(N
)) = E_In_Parameter
7467 and then not Within_Init_Proc
7469 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
7471 return Duplicate_Subexpr
(N
);
7473 end Check_Discriminated_Prival
;
7475 -- Start of processing for Range_Attribute
7478 if not Is_Entity_Name
(P
)
7479 or else not Is_Type
(Entity
(P
))
7484 -- Check whether prefix is (renaming of) private component
7485 -- of protected type.
7487 if Is_Entity_Name
(P
)
7488 and then Comes_From_Source
(N
)
7489 and then Is_Array_Type
(Etype
(P
))
7490 and then Number_Dimensions
(Etype
(P
)) = 1
7491 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
7493 Ekind
(Scope
(Scope
(Entity
(P
)))) =
7497 Check_Discriminated_Prival
7498 (Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
7501 Check_Discriminated_Prival
7502 (Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
7506 Make_Attribute_Reference
(Loc
,
7507 Prefix
=> Duplicate_Subexpr
(P
),
7508 Attribute_Name
=> Name_Last
,
7509 Expressions
=> Expressions
(N
));
7512 Make_Attribute_Reference
(Loc
,
7514 Attribute_Name
=> Name_First
,
7515 Expressions
=> Expressions
(N
));
7518 -- If the original was marked as Must_Not_Freeze (see code
7519 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7520 -- does not freeze either.
7522 if Must_Not_Freeze
(N
) then
7523 Set_Must_Not_Freeze
(HB
);
7524 Set_Must_Not_Freeze
(LB
);
7525 Set_Must_Not_Freeze
(Prefix
(HB
));
7526 Set_Must_Not_Freeze
(Prefix
(LB
));
7529 if Raises_Constraint_Error
(Prefix
(N
)) then
7531 -- Preserve Sloc of prefix in the new bounds, so that
7532 -- the posted warning can be removed if we are within
7533 -- unreachable code.
7535 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
7536 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
7539 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
7540 Analyze_And_Resolve
(N
, Typ
);
7542 -- Normally after resolving attribute nodes, Eval_Attribute
7543 -- is called to do any possible static evaluation of the node.
7544 -- However, here since the Range attribute has just been
7545 -- transformed into a range expression it is no longer an
7546 -- attribute node and therefore the call needs to be avoided
7547 -- and is accomplished by simply returning from the procedure.
7550 end Range_Attribute
;
7556 -- Prefix must not be resolved in this case, since it is not a
7557 -- real entity reference. No action of any kind is require!
7559 when Attribute_UET_Address
=>
7562 ----------------------
7563 -- Unchecked_Access --
7564 ----------------------
7566 -- Processing is shared with Access
7568 -------------------------
7569 -- Unrestricted_Access --
7570 -------------------------
7572 -- Processing is shared with Access
7578 -- Apply range check. Note that we did not do this during the
7579 -- analysis phase, since we wanted Eval_Attribute to have a
7580 -- chance at finding an illegal out of range value.
7582 when Attribute_Val
=>
7584 -- Note that we do our own Eval_Attribute call here rather than
7585 -- use the common one, because we need to do processing after
7586 -- the call, as per above comment.
7590 -- Eval_Attribute may replace the node with a raise CE, or
7591 -- fold it to a constant. Obviously we only apply a scalar
7592 -- range check if this did not happen!
7594 if Nkind
(N
) = N_Attribute_Reference
7595 and then Attribute_Name
(N
) = Name_Val
7597 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
7606 -- Prefix of Version attribute can be a subprogram name which
7607 -- must not be resolved, since this is not a call.
7609 when Attribute_Version
=>
7612 ----------------------
7613 -- Other Attributes --
7614 ----------------------
7616 -- For other attributes, resolve prefix unless it is a type. If
7617 -- the attribute reference itself is a type name ('Base and 'Class)
7618 -- then this is only legal within a task or protected record.
7621 if not Is_Entity_Name
(P
)
7622 or else not Is_Type
(Entity
(P
))
7627 -- If the attribute reference itself is a type name ('Base,
7628 -- 'Class) then this is only legal within a task or protected
7629 -- record. What is this all about ???
7631 if Is_Entity_Name
(N
)
7632 and then Is_Type
(Entity
(N
))
7634 if Is_Concurrent_Type
(Entity
(N
))
7635 and then In_Open_Scopes
(Entity
(P
))
7640 ("invalid use of subtype name in expression or call", N
);
7644 -- For attributes whose argument may be a string, complete
7645 -- resolution of argument now. This avoids premature expansion
7646 -- (and the creation of transient scopes) before the attribute
7647 -- reference is resolved.
7650 when Attribute_Value
=>
7651 Resolve
(First
(Expressions
(N
)), Standard_String
);
7653 when Attribute_Wide_Value
=>
7654 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
7656 when Attribute_Wide_Wide_Value
=>
7657 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
7659 when others => null;
7663 -- Normally the Freezing is done by Resolve but sometimes the Prefix
7664 -- is not resolved, in which case the freezing must be done now.
7666 Freeze_Expression
(P
);
7668 -- Finally perform static evaluation on the attribute reference
7671 end Resolve_Attribute
;
7673 --------------------------------
7674 -- Stream_Attribute_Available --
7675 --------------------------------
7677 function Stream_Attribute_Available
7679 Nam
: TSS_Name_Type
;
7680 Partial_View
: Node_Id
:= Empty
) return Boolean
7682 Etyp
: Entity_Id
:= Typ
;
7684 function Has_Specified_Stream_Attribute
7686 Nam
: TSS_Name_Type
) return Boolean;
7687 -- True iff there is a visible attribute definition clause specifying
7688 -- attribute Nam for Typ.
7690 ------------------------------------
7691 -- Has_Specified_Stream_Attribute --
7692 ------------------------------------
7694 function Has_Specified_Stream_Attribute
7696 Nam
: TSS_Name_Type
) return Boolean
7701 (Nam
= TSS_Stream_Input
7702 and then Has_Specified_Stream_Input
(Typ
))
7704 (Nam
= TSS_Stream_Output
7705 and then Has_Specified_Stream_Output
(Typ
))
7707 (Nam
= TSS_Stream_Read
7708 and then Has_Specified_Stream_Read
(Typ
))
7710 (Nam
= TSS_Stream_Write
7711 and then Has_Specified_Stream_Write
(Typ
));
7712 end Has_Specified_Stream_Attribute
;
7714 -- Start of processing for Stream_Attribute_Available
7717 -- We need some comments in this body ???
7719 if Has_Specified_Stream_Attribute
(Typ
, Nam
) then
7723 if Is_Class_Wide_Type
(Typ
) then
7724 return not Is_Limited_Type
(Typ
)
7725 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
7728 if Nam
= TSS_Stream_Input
7729 and then Is_Abstract
(Typ
)
7730 and then not Is_Class_Wide_Type
(Typ
)
7735 if not (Is_Limited_Type
(Typ
)
7736 or else (Present
(Partial_View
)
7737 and then Is_Limited_Type
(Partial_View
)))
7742 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
7744 if Nam
= TSS_Stream_Input
7745 and then Ada_Version
>= Ada_05
7746 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
7750 elsif Nam
= TSS_Stream_Output
7751 and then Ada_Version
>= Ada_05
7752 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
7757 -- Case of Read and Write: check for attribute definition clause that
7758 -- applies to an ancestor type.
7760 while Etype
(Etyp
) /= Etyp
loop
7761 Etyp
:= Etype
(Etyp
);
7763 if Has_Specified_Stream_Attribute
(Etyp
, Nam
) then
7768 if Ada_Version
< Ada_05
then
7770 -- In Ada 95 mode, also consider a non-visible definition
7773 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
7776 and then Stream_Attribute_Available
7777 (Btyp
, Nam
, Partial_View
=> Typ
);
7782 end Stream_Attribute_Available
;