1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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_Dist
; use Exp_Dist
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
47 with Sdefault
; use Sdefault
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dist
; use Sem_Dist
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Res
; use Sem_Res
;
55 with Sem_Type
; use Sem_Type
;
56 with Sem_Util
; use Sem_Util
;
57 with Stand
; use Stand
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with Stringt
; use Stringt
;
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 function OK_Self_Reference return Boolean;
347 -- An access reference whose prefix is a type can legally appear
348 -- within an aggregate, where it is obtained by expansion of
349 -- a defaulted aggregate;
351 ------------------------------
352 -- Build_Access_Object_Type --
353 ------------------------------
355 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
359 if Aname = Name_Unrestricted_Access then
362 (E_Allocator_Type, Current_Scope, Loc, 'A
');
366 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
369 Set_Etype (Typ, Typ);
370 Init_Size_Align (Typ);
372 Set_Associated_Node_For_Itype (Typ, N);
373 Set_Directly_Designated_Type (Typ, DT);
375 end Build_Access_Object_Type;
377 ----------------------------------
378 -- Build_Access_Subprogram_Type --
379 ----------------------------------
381 procedure Build_Access_Subprogram_Type (P : Node_Id) is
382 Index : Interp_Index;
385 function Get_Kind (E : Entity_Id) return Entity_Kind;
386 -- Distinguish between access to regular/protected subprograms
392 function Get_Kind (E : Entity_Id) return Entity_Kind is
394 if Convention (E) = Convention_Protected then
395 return E_Access_Protected_Subprogram_Type;
397 return E_Access_Subprogram_Type;
401 -- Start of processing for Build_Access_Subprogram_Type
404 -- In the case of an access to subprogram, use the name of the
405 -- subprogram itself as the designated type. Type-checking in
406 -- this case compares the signatures of the designated types.
408 Set_Etype (N, Any_Type);
410 if not Is_Overloaded (P) then
411 if not Is_Intrinsic_Subprogram (Entity (P)) then
414 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
415 Set_Etype (Acc_Type, Acc_Type);
416 Set_Directly_Designated_Type (Acc_Type, Entity (P));
417 Set_Etype (N, Acc_Type);
421 Get_First_Interp (P, Index, It);
422 while Present (It.Nam) loop
423 if not Is_Intrinsic_Subprogram (It.Nam) then
426 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
427 Set_Etype (Acc_Type, Acc_Type);
428 Set_Directly_Designated_Type (Acc_Type, It.Nam);
429 Add_One_Interp (N, Acc_Type, Acc_Type);
432 Get_Next_Interp (Index, It);
436 if Etype (N) = Any_Type then
437 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
439 end Build_Access_Subprogram_Type;
441 ----------------------
442 -- OK_Self_Reference --
443 ----------------------
445 function OK_Self_Reference return Boolean is
451 and then Nkind (Par) in N_Subexpr
453 exit when Nkind (Par) = N_Aggregate
454 or else Nkind (Par) = N_Extension_Aggregate;
460 (Nkind (Par) = N_Aggregate
461 or else Nkind (Par) = N_Extension_Aggregate)
462 and then Etype (Par) = Typ
464 Set_Has_Self_Reference (Par);
469 end OK_Self_Reference;
471 -- Start of processing for Analyze_Access_Attribute
476 if Nkind (P) = N_Character_Literal then
478 ("prefix of % attribute cannot be enumeration literal", P);
481 -- Case of access to subprogram
483 if Is_Entity_Name (P)
484 and then Is_Overloadable (Entity (P))
486 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
487 -- restriction set (since in general a trampoline is required).
489 if not Is_Library_Level_Entity (Entity (P)) then
490 Check_Restriction (No_Implicit_Dynamic_Code, P);
493 if Is_Always_Inlined (Entity (P)) then
495 ("prefix of % attribute cannot be Inline_Always subprogram",
499 if Aname = Name_Unchecked_Access then
500 Error_Attr ("attribute% cannot be applied to a subprogram", P);
503 -- Build the appropriate subprogram type
505 Build_Access_Subprogram_Type (P);
507 -- For unrestricted access, kill current values, since this
508 -- attribute allows a reference to a local subprogram that
509 -- could modify local variables to be passed out of scope
511 if Aname = Name_Unrestricted_Access then
517 -- Component is an operation of a protected type
519 elsif Nkind (P) = N_Selected_Component
520 and then Is_Overloadable (Entity (Selector_Name (P)))
522 if Ekind (Entity (Selector_Name (P))) = E_Entry then
523 Error_Attr ("prefix of % attribute must be subprogram", P);
526 Build_Access_Subprogram_Type (Selector_Name (P));
530 -- Deal with incorrect reference to a type, but note that some
531 -- accesses are allowed: references to the current type instance,
532 -- or in Ada 2005 self-referential pointer in a default-initialized
535 if Is_Entity_Name (P) then
538 -- The reference may appear in an aggregate that has been expanded
539 -- into a loop. Locate scope of type definition, if any.
541 Scop := Current_Scope;
542 while Ekind (Scop) = E_Loop loop
543 Scop := Scope (Scop);
546 if Is_Type (Typ) then
548 -- OK if we are within the scope of a limited type
549 -- let's mark the component as having per object constraint
551 if Is_Anonymous_Tagged_Base (Scop, Typ) then
559 Q : Node_Id := Parent (N);
563 and then Nkind (Q) /= N_Component_Declaration
569 Set_Has_Per_Object_Constraint (
570 Defining_Identifier (Q), True);
574 if Nkind (P) = N_Expanded_Name then
576 ("current instance prefix must be a direct name", P);
579 -- If a current instance attribute appears within a
580 -- a component constraint it must appear alone; other
581 -- contexts (default expressions, within a task body)
582 -- are not subject to this restriction.
584 if not In_Default_Expression
585 and then not Has_Completion (Scop)
587 Nkind (Parent (N)) /= N_Discriminant_Association
589 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
592 ("current instance attribute must appear alone", N);
595 -- OK if we are in initialization procedure for the type
596 -- in question, in which case the reference to the type
597 -- is rewritten as a reference to the current object.
599 elsif Ekind (Scop) = E_Procedure
600 and then Is_Init_Proc (Scop)
601 and then Etype (First_Formal (Scop)) = Typ
604 Make_Attribute_Reference (Loc,
605 Prefix => Make_Identifier (Loc, Name_uInit),
606 Attribute_Name => Name_Unrestricted_Access));
610 -- OK if a task type, this test needs sharpening up ???
612 elsif Is_Task_Type (Typ) then
615 -- OK if self-reference in an aggregate in Ada 2005, and
616 -- the reference comes from a copied default expression.
618 elsif Ada_Version >= Ada_05
619 and then not Comes_From_Source (N)
620 and then OK_Self_Reference
624 -- Otherwise we have an error case
627 Error_Attr ("% attribute cannot be applied to type", P);
633 -- If we fall through, we have a normal access to object case.
634 -- Unrestricted_Access is legal wherever an allocator would be
635 -- legal, so its Etype is set to E_Allocator. The expected type
636 -- of the other attributes is a general access type, and therefore
637 -- we label them with E_Access_Attribute_Type.
639 if not Is_Overloaded (P) then
640 Acc_Type := Build_Access_Object_Type (P_Type);
641 Set_Etype (N, Acc_Type);
644 Index : Interp_Index;
647 Set_Etype (N, Any_Type);
648 Get_First_Interp (P, Index, It);
649 while Present (It.Typ) loop
650 Acc_Type := Build_Access_Object_Type (It.Typ);
651 Add_One_Interp (N, Acc_Type, Acc_Type);
652 Get_Next_Interp (Index, It);
657 -- If we have an access to an object, and the attribute comes
658 -- from source, then set the object as potentially source modified.
659 -- We do this because the resulting access pointer can be used to
660 -- modify the variable, and we might not detect this, leading to
661 -- some junk warnings.
663 if Is_Entity_Name (P) then
664 Set_Never_Set_In_Source (Entity (P), False);
667 -- Check for aliased view unless unrestricted case. We allow
668 -- a nonaliased prefix when within an instance because the
669 -- prefix may have been a tagged formal object, which is
670 -- defined to be aliased even when the actual might not be
671 -- (other instance cases will have been caught in the generic).
672 -- Similarly, within an inlined body we know that the attribute
673 -- is legal in the original subprogram, and therefore legal in
676 if Aname /= Name_Unrestricted_Access
677 and then not Is_Aliased_View (P)
678 and then not In_Instance
679 and then not In_Inlined_Body
681 Error_Attr ("prefix of % attribute must be aliased", P);
683 end Analyze_Access_Attribute;
685 --------------------------------
686 -- Check_Array_Or_Scalar_Type --
687 --------------------------------
689 procedure Check_Array_Or_Scalar_Type is
693 -- Dimension number for array attributes
696 -- Case of string literal or string literal subtype. These cases
697 -- cannot arise from legal Ada code, but the expander is allowed
698 -- to generate them. They require special handling because string
699 -- literal subtypes do not have standard bounds (the whole idea
700 -- of these subtypes is to avoid having to generate the bounds)
702 if Ekind (P_Type) = E_String_Literal_Subtype then
703 Set_Etype (N, Etype (First_Index (P_Base_Type)));
708 elsif Is_Scalar_Type (P_Type) then
712 Error_Attr ("invalid argument in % attribute", E1);
714 Set_Etype (N, P_Base_Type);
718 -- The following is a special test to allow 'First to apply to
719 -- private scalar types if the attribute comes from generated
720 -- code. This occurs in the case of Normalize_Scalars code.
722 elsif Is_Private_Type
(P_Type
)
723 and then Present
(Full_View
(P_Type
))
724 and then Is_Scalar_Type
(Full_View
(P_Type
))
725 and then not Comes_From_Source
(N
)
727 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
729 -- Array types other than string literal subtypes handled above
734 -- We know prefix is an array type, or the name of an array
735 -- object, and that the expression, if present, is static
736 -- and within the range of the dimensions of the type.
738 pragma Assert
(Is_Array_Type
(P_Type
));
739 Index
:= First_Index
(P_Base_Type
);
743 -- First dimension assumed
745 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
748 D
:= UI_To_Int
(Intval
(E1
));
750 for J
in 1 .. D
- 1 loop
754 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
755 Set_Etype
(E1
, Standard_Integer
);
758 end Check_Array_Or_Scalar_Type
;
760 ----------------------
761 -- Check_Array_Type --
762 ----------------------
764 procedure Check_Array_Type
is
766 -- Dimension number for array attributes
769 -- If the type is a string literal type, then this must be generated
770 -- internally, and no further check is required on its legality.
772 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
775 -- If the type is a composite, it is an illegal aggregate, no point
778 elsif P_Type
= Any_Composite
then
782 -- Normal case of array type or subtype
784 Check_Either_E0_Or_E1
;
787 if Is_Array_Type
(P_Type
) then
788 if not Is_Constrained
(P_Type
)
789 and then Is_Entity_Name
(P
)
790 and then Is_Type
(Entity
(P
))
792 -- Note: we do not call Error_Attr here, since we prefer to
793 -- continue, using the relevant index type of the array,
794 -- even though it is unconstrained. This gives better error
795 -- recovery behavior.
797 Error_Msg_Name_1
:= Aname
;
799 ("prefix for % attribute must be constrained array", P
);
802 D
:= Number_Dimensions
(P_Type
);
805 if Is_Private_Type
(P_Type
) then
807 ("prefix for % attribute may not be private type", P
);
809 elsif Is_Access_Type
(P_Type
)
810 and then Is_Array_Type
(Designated_Type
(P_Type
))
811 and then Is_Entity_Name
(P
)
812 and then Is_Type
(Entity
(P
))
814 Error_Attr
("prefix of % attribute cannot be access type", P
);
816 elsif Attr_Id
= Attribute_First
818 Attr_Id
= Attribute_Last
820 Error_Attr
("invalid prefix for % attribute", P
);
823 Error_Attr
("prefix for % attribute must be array", P
);
828 Resolve
(E1
, Any_Integer
);
829 Set_Etype
(E1
, Standard_Integer
);
831 if not Is_Static_Expression
(E1
)
832 or else Raises_Constraint_Error
(E1
)
835 ("expression for dimension must be static!", E1
);
838 elsif UI_To_Int
(Expr_Value
(E1
)) > D
839 or else UI_To_Int
(Expr_Value
(E1
)) < 1
841 Error_Attr
("invalid dimension number for array type", E1
);
844 end Check_Array_Type
;
846 -------------------------
847 -- Check_Asm_Attribute --
848 -------------------------
850 procedure Check_Asm_Attribute
is
855 -- Check first argument is static string expression
857 Analyze_And_Resolve
(E1
, Standard_String
);
859 if Etype
(E1
) = Any_Type
then
862 elsif not Is_OK_Static_Expression
(E1
) then
864 ("constraint argument must be static string expression!", E1
);
868 -- Check second argument is right type
870 Analyze_And_Resolve
(E2
, Entity
(P
));
872 -- Note: that is all we need to do, we don't need to check
873 -- that it appears in a correct context. The Ada type system
874 -- will do that for us.
876 end Check_Asm_Attribute
;
878 ---------------------
879 -- Check_Component --
880 ---------------------
882 procedure Check_Component
is
886 if Nkind
(P
) /= N_Selected_Component
888 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
890 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
893 ("prefix for % attribute must be selected component", P
);
897 ------------------------------------
898 -- Check_Decimal_Fixed_Point_Type --
899 ------------------------------------
901 procedure Check_Decimal_Fixed_Point_Type
is
905 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
907 ("prefix of % attribute must be decimal type", P
);
909 end Check_Decimal_Fixed_Point_Type
;
911 -----------------------
912 -- Check_Dereference --
913 -----------------------
915 procedure Check_Dereference
is
918 -- Case of a subtype mark
920 if Is_Entity_Name
(P
)
921 and then Is_Type
(Entity
(P
))
926 -- Case of an expression
930 if Is_Access_Type
(P_Type
) then
932 -- If there is an implicit dereference, then we must freeze
933 -- the designated type of the access type, since the type of
934 -- the referenced array is this type (see AI95-00106).
936 Freeze_Before
(N
, Designated_Type
(P_Type
));
939 Make_Explicit_Dereference
(Sloc
(P
),
940 Prefix
=> Relocate_Node
(P
)));
942 Analyze_And_Resolve
(P
);
945 if P_Type
= Any_Type
then
949 P_Base_Type
:= Base_Type
(P_Type
);
951 end Check_Dereference
;
953 -------------------------
954 -- Check_Discrete_Type --
955 -------------------------
957 procedure Check_Discrete_Type
is
961 if not Is_Discrete_Type
(P_Type
) then
962 Error_Attr
("prefix of % attribute must be discrete type", P
);
964 end Check_Discrete_Type
;
970 procedure Check_E0
is
973 Unexpected_Argument
(E1
);
981 procedure Check_E1
is
983 Check_Either_E0_Or_E1
;
987 -- Special-case attributes that are functions and that appear as
988 -- the prefix of another attribute. Error is posted on parent.
990 if Nkind
(Parent
(N
)) = N_Attribute_Reference
991 and then (Attribute_Name
(Parent
(N
)) = Name_Address
993 Attribute_Name
(Parent
(N
)) = Name_Code_Address
995 Attribute_Name
(Parent
(N
)) = Name_Access
)
997 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
998 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
999 Set_Etype
(Parent
(N
), Any_Type
);
1000 Set_Entity
(Parent
(N
), Any_Type
);
1001 raise Bad_Attribute
;
1004 Error_Attr
("missing argument for % attribute", N
);
1013 procedure Check_E2
is
1016 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1018 Error_Attr
("missing argument for % attribute (2 required)", N
);
1022 ---------------------------
1023 -- Check_Either_E0_Or_E1 --
1024 ---------------------------
1026 procedure Check_Either_E0_Or_E1
is
1028 if Present
(E2
) then
1029 Unexpected_Argument
(E2
);
1031 end Check_Either_E0_Or_E1
;
1033 ----------------------
1034 -- Check_Enum_Image --
1035 ----------------------
1037 procedure Check_Enum_Image
is
1040 if Is_Enumeration_Type
(P_Base_Type
) then
1041 Lit
:= First_Literal
(P_Base_Type
);
1042 while Present
(Lit
) loop
1043 Set_Referenced
(Lit
);
1047 end Check_Enum_Image
;
1049 ----------------------------
1050 -- Check_Fixed_Point_Type --
1051 ----------------------------
1053 procedure Check_Fixed_Point_Type
is
1057 if not Is_Fixed_Point_Type
(P_Type
) then
1058 Error_Attr
("prefix of % attribute must be fixed point type", P
);
1060 end Check_Fixed_Point_Type
;
1062 ------------------------------
1063 -- Check_Fixed_Point_Type_0 --
1064 ------------------------------
1066 procedure Check_Fixed_Point_Type_0
is
1068 Check_Fixed_Point_Type
;
1070 end Check_Fixed_Point_Type_0
;
1072 -------------------------------
1073 -- Check_Floating_Point_Type --
1074 -------------------------------
1076 procedure Check_Floating_Point_Type
is
1080 if not Is_Floating_Point_Type
(P_Type
) then
1081 Error_Attr
("prefix of % attribute must be float type", P
);
1083 end Check_Floating_Point_Type
;
1085 ---------------------------------
1086 -- Check_Floating_Point_Type_0 --
1087 ---------------------------------
1089 procedure Check_Floating_Point_Type_0
is
1091 Check_Floating_Point_Type
;
1093 end Check_Floating_Point_Type_0
;
1095 ---------------------------------
1096 -- Check_Floating_Point_Type_1 --
1097 ---------------------------------
1099 procedure Check_Floating_Point_Type_1
is
1101 Check_Floating_Point_Type
;
1103 end Check_Floating_Point_Type_1
;
1105 ---------------------------------
1106 -- Check_Floating_Point_Type_2 --
1107 ---------------------------------
1109 procedure Check_Floating_Point_Type_2
is
1111 Check_Floating_Point_Type
;
1113 end Check_Floating_Point_Type_2
;
1115 ------------------------
1116 -- Check_Integer_Type --
1117 ------------------------
1119 procedure Check_Integer_Type
is
1123 if not Is_Integer_Type
(P_Type
) then
1124 Error_Attr
("prefix of % attribute must be integer type", P
);
1126 end Check_Integer_Type
;
1128 ------------------------
1129 -- Check_Library_Unit --
1130 ------------------------
1132 procedure Check_Library_Unit
is
1134 if not Is_Compilation_Unit
(Entity
(P
)) then
1135 Error_Attr
("prefix of % attribute must be library unit", P
);
1137 end Check_Library_Unit
;
1139 --------------------------------
1140 -- Check_Modular_Integer_Type --
1141 --------------------------------
1143 procedure Check_Modular_Integer_Type
is
1147 if not Is_Modular_Integer_Type
(P_Type
) then
1149 ("prefix of % attribute must be modular integer type", P
);
1151 end Check_Modular_Integer_Type
;
1153 -------------------------------
1154 -- Check_Not_Incomplete_Type --
1155 -------------------------------
1157 procedure Check_Not_Incomplete_Type
is
1162 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1163 -- dereference we have to check wrong uses of incomplete types
1164 -- (other wrong uses are checked at their freezing point).
1166 -- Example 1: Limited-with
1168 -- limited with Pkg;
1170 -- type Acc is access Pkg.T;
1172 -- S : Integer := X.all'Size; -- ERROR
1175 -- Example 2: Tagged incomplete
1177 -- type T is tagged;
1178 -- type Acc is access all T;
1180 -- S : constant Integer := X.all'Size; -- ERROR
1181 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1183 if Ada_Version
>= Ada_05
1184 and then Nkind
(P
) = N_Explicit_Dereference
1187 while Nkind
(E
) = N_Explicit_Dereference
loop
1191 if From_With_Type
(Etype
(E
)) then
1193 ("prefix of % attribute cannot be an incomplete type", P
);
1196 if Is_Access_Type
(Etype
(E
)) then
1197 Typ
:= Directly_Designated_Type
(Etype
(E
));
1202 if Ekind
(Typ
) = E_Incomplete_Type
1203 and then No
(Full_View
(Typ
))
1206 ("prefix of % attribute cannot be an incomplete type", P
);
1211 if not Is_Entity_Name
(P
)
1212 or else not Is_Type
(Entity
(P
))
1213 or else In_Default_Expression
1217 Check_Fully_Declared
(P_Type
, P
);
1219 end Check_Not_Incomplete_Type
;
1221 ----------------------------
1222 -- Check_Object_Reference --
1223 ----------------------------
1225 procedure Check_Object_Reference
(P
: Node_Id
) is
1229 -- If we need an object, and we have a prefix that is the name of
1230 -- a function entity, convert it into a function call.
1232 if Is_Entity_Name
(P
)
1233 and then Ekind
(Entity
(P
)) = E_Function
1235 Rtyp
:= Etype
(Entity
(P
));
1238 Make_Function_Call
(Sloc
(P
),
1239 Name
=> Relocate_Node
(P
)));
1241 Analyze_And_Resolve
(P
, Rtyp
);
1243 -- Otherwise we must have an object reference
1245 elsif not Is_Object_Reference
(P
) then
1246 Error_Attr
("prefix of % attribute must be object", P
);
1248 end Check_Object_Reference
;
1250 ------------------------
1251 -- Check_Program_Unit --
1252 ------------------------
1254 procedure Check_Program_Unit
is
1256 if Is_Entity_Name
(P
) then
1258 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1259 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1262 if K
in Subprogram_Kind
1263 or else K
in Task_Kind
1264 or else K
in Protected_Kind
1265 or else K
= E_Package
1266 or else K
in Generic_Unit_Kind
1267 or else (K
= E_Variable
1271 Is_Protected_Type
(T
)))
1278 Error_Attr
("prefix of % attribute must be program unit", P
);
1279 end Check_Program_Unit
;
1281 ---------------------
1282 -- Check_Real_Type --
1283 ---------------------
1285 procedure Check_Real_Type
is
1289 if not Is_Real_Type
(P_Type
) then
1290 Error_Attr
("prefix of % attribute must be real type", P
);
1292 end Check_Real_Type
;
1294 -----------------------
1295 -- Check_Scalar_Type --
1296 -----------------------
1298 procedure Check_Scalar_Type
is
1302 if not Is_Scalar_Type
(P_Type
) then
1303 Error_Attr
("prefix of % attribute must be scalar type", P
);
1305 end Check_Scalar_Type
;
1307 ---------------------------
1308 -- Check_Standard_Prefix --
1309 ---------------------------
1311 procedure Check_Standard_Prefix
is
1315 if Nkind
(P
) /= N_Identifier
1316 or else Chars
(P
) /= Name_Standard
1318 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1321 end Check_Standard_Prefix
;
1323 ----------------------------
1324 -- Check_Stream_Attribute --
1325 ----------------------------
1327 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1332 Validate_Non_Static_Attribute_Function_Call
;
1334 -- With the exception of 'Input, Stream attributes are procedures,
1335 -- and can only appear at the position of procedure calls. We check
1336 -- for this here, before they are rewritten, to give a more precise
1339 if Nam
= TSS_Stream_Input
then
1342 elsif Is_List_Member
(N
)
1343 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1344 and then Nkind
(Parent
(N
)) /= N_Aggregate
1350 ("invalid context for attribute%, which is a procedure", N
);
1354 Btyp
:= Implementation_Base_Type
(P_Type
);
1356 -- Stream attributes not allowed on limited types unless the
1357 -- attribute reference was generated by the expander (in which
1358 -- case the underlying type will be used, as described in Sinfo),
1359 -- or the attribute was specified explicitly for the type itself
1360 -- or one of its ancestors (taking visibility rules into account if
1361 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1362 -- (with no visibility restriction).
1364 if Comes_From_Source
(N
)
1365 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1366 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1368 Error_Msg_Name_1
:= Aname
;
1370 if Is_Limited_Type
(P_Type
) then
1372 ("limited type& has no% attribute", P
, P_Type
);
1373 Explain_Limited_Type
(P_Type
, P
);
1376 ("attribute% for type& is not available", P
, P_Type
);
1380 -- Check for violation of restriction No_Stream_Attributes
1382 if Is_RTE
(P_Type
, RE_Exception_Id
)
1384 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1386 Check_Restriction
(No_Exception_Registration
, P
);
1389 -- Here we must check that the first argument is an access type
1390 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1392 Analyze_And_Resolve
(E1
);
1395 -- Note: the double call to Root_Type here is needed because the
1396 -- root type of a class-wide type is the corresponding type (e.g.
1397 -- X for X'Class, and we really want to go to the root.
1399 if not Is_Access_Type
(Etyp
)
1400 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1401 RTE
(RE_Root_Stream_Type
)
1404 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1407 -- Check that the second argument is of the right type if there is
1408 -- one (the Input attribute has only one argument so this is skipped)
1410 if Present
(E2
) then
1413 if Nam
= TSS_Stream_Read
1414 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1417 ("second argument of % attribute must be a variable", E2
);
1420 Resolve
(E2
, P_Type
);
1422 end Check_Stream_Attribute
;
1424 -----------------------
1425 -- Check_Task_Prefix --
1426 -----------------------
1428 procedure Check_Task_Prefix
is
1432 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1433 -- task interface class-wide types.
1435 if Is_Task_Type
(Etype
(P
))
1436 or else (Is_Access_Type
(Etype
(P
))
1437 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1438 or else (Ada_Version
>= Ada_05
1439 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1440 and then Is_Interface
(Etype
(P
))
1441 and then Is_Task_Interface
(Etype
(P
)))
1446 if Ada_Version
>= Ada_05
then
1447 Error_Attr
("prefix of % attribute must be a task or a task "
1448 & "interface class-wide object", P
);
1451 Error_Attr
("prefix of % attribute must be a task", P
);
1454 end Check_Task_Prefix
;
1460 -- The possibilities are an entity name denoting a type, or an
1461 -- attribute reference that denotes a type (Base or Class). If
1462 -- the type is incomplete, replace it with its full view.
1464 procedure Check_Type
is
1466 if not Is_Entity_Name
(P
)
1467 or else not Is_Type
(Entity
(P
))
1469 Error_Attr
("prefix of % attribute must be a type", P
);
1471 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1472 and then Present
(Full_View
(Entity
(P
)))
1474 P_Type
:= Full_View
(Entity
(P
));
1475 Set_Entity
(P
, P_Type
);
1479 ---------------------
1480 -- Check_Unit_Name --
1481 ---------------------
1483 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1485 if Nkind
(Nod
) = N_Identifier
then
1488 elsif Nkind
(Nod
) = N_Selected_Component
then
1489 Check_Unit_Name
(Prefix
(Nod
));
1491 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1496 Error_Attr
("argument for % attribute must be unit name", P
);
1497 end Check_Unit_Name
;
1503 procedure Error_Attr
is
1505 Set_Etype
(N
, Any_Type
);
1506 Set_Entity
(N
, Any_Type
);
1507 raise Bad_Attribute
;
1510 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1512 Error_Msg_Name_1
:= Aname
;
1513 Error_Msg_N
(Msg
, Error_Node
);
1517 ----------------------------
1518 -- Legal_Formal_Attribute --
1519 ----------------------------
1521 procedure Legal_Formal_Attribute
is
1525 if not Is_Entity_Name
(P
)
1526 or else not Is_Type
(Entity
(P
))
1528 Error_Attr
("prefix of % attribute must be generic type", N
);
1530 elsif Is_Generic_Actual_Type
(Entity
(P
))
1532 or else In_Inlined_Body
1536 elsif Is_Generic_Type
(Entity
(P
)) then
1537 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1539 ("prefix of % attribute must be indefinite generic type", N
);
1544 ("prefix of % attribute must be indefinite generic type", N
);
1547 Set_Etype
(N
, Standard_Boolean
);
1548 end Legal_Formal_Attribute
;
1550 ------------------------
1551 -- Standard_Attribute --
1552 ------------------------
1554 procedure Standard_Attribute
(Val
: Int
) is
1556 Check_Standard_Prefix
;
1558 -- First a special check (more like a kludge really). For GNAT5
1559 -- on Windows, the alignments in GCC are severely mixed up. In
1560 -- particular, we have a situation where the maximum alignment
1561 -- that GCC thinks is possible is greater than the guaranteed
1562 -- alignment at run-time. That causes many problems. As a partial
1563 -- cure for this situation, we force a value of 4 for the maximum
1564 -- alignment attribute on this target. This still does not solve
1565 -- all problems, but it helps.
1567 -- A further (even more horrible) dimension to this kludge is now
1568 -- installed. There are two uses for Maximum_Alignment, one is to
1569 -- determine the maximum guaranteed alignment, that's the one we
1570 -- want the kludge to yield as 4. The other use is to maximally
1571 -- align objects, we can't use 4 here, since for example, long
1572 -- long integer has an alignment of 8, so we will get errors.
1574 -- It is of course impossible to determine which use the programmer
1575 -- has in mind, but an approximation for now is to disconnect the
1576 -- kludge if the attribute appears in an alignment clause.
1578 -- To be removed if GCC ever gets its act together here ???
1580 Alignment_Kludge
: declare
1583 function On_X86
return Boolean;
1584 -- Determine if target is x86 (ia32), return True if so
1590 function On_X86
return Boolean is
1591 T
: constant String := Sdefault
.Target_Name
.all;
1594 -- There is no clean way to check this. That's not surprising,
1595 -- the front end should not be doing this kind of test ???. The
1596 -- way we do it is test for either "86" or "pentium" being in
1597 -- the string for the target name. However, we need to exclude
1598 -- x86_64 for this check.
1600 for J
in T
'First .. T
'Last - 1 loop
1601 if (T
(J
.. J
+ 1) = "86"
1604 or else T
(J
+ 2 .. J
+ 4) /= "_64"))
1605 or else (J
<= T
'Last - 6
1606 and then T
(J
.. J
+ 6) = "pentium")
1615 -- Start of processing for Alignment_Kludge
1618 if Aname
= Name_Maximum_Alignment
and then On_X86
then
1621 while Nkind
(P
) in N_Subexpr
loop
1625 if Nkind
(P
) /= N_Attribute_Definition_Clause
1626 or else Chars
(P
) /= Name_Alignment
1628 Rewrite
(N
, Make_Integer_Literal
(Loc
, 4));
1633 end Alignment_Kludge
;
1635 -- Normally we get the value from gcc ???
1637 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1639 end Standard_Attribute
;
1641 -------------------------
1642 -- Unexpected Argument --
1643 -------------------------
1645 procedure Unexpected_Argument
(En
: Node_Id
) is
1647 Error_Attr
("unexpected argument for % attribute", En
);
1648 end Unexpected_Argument
;
1650 -------------------------------------------------
1651 -- Validate_Non_Static_Attribute_Function_Call --
1652 -------------------------------------------------
1654 -- This function should be moved to Sem_Dist ???
1656 procedure Validate_Non_Static_Attribute_Function_Call
is
1658 if In_Preelaborated_Unit
1659 and then not In_Subprogram_Or_Concurrent_Unit
1661 Flag_Non_Static_Expr
1662 ("non-static function call in preelaborated unit!", N
);
1664 end Validate_Non_Static_Attribute_Function_Call
;
1666 -----------------------------------------------
1667 -- Start of Processing for Analyze_Attribute --
1668 -----------------------------------------------
1671 -- Immediate return if unrecognized attribute (already diagnosed
1672 -- by parser, so there is nothing more that we need to do)
1674 if not Is_Attribute_Name
(Aname
) then
1675 raise Bad_Attribute
;
1678 -- Deal with Ada 83 and Features issues
1680 if Comes_From_Source
(N
) then
1681 if not Attribute_83
(Attr_Id
) then
1682 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1683 Error_Msg_Name_1
:= Aname
;
1684 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1687 if Attribute_Impl_Def
(Attr_Id
) then
1688 Check_Restriction
(No_Implementation_Attributes
, N
);
1693 -- Remote access to subprogram type access attribute reference needs
1694 -- unanalyzed copy for tree transformation. The analyzed copy is used
1695 -- for its semantic information (whether prefix is a remote subprogram
1696 -- name), the unanalyzed copy is used to construct new subtree rooted
1697 -- with N_Aggregate which represents a fat pointer aggregate.
1699 if Aname
= Name_Access
then
1700 Discard_Node
(Copy_Separate_Tree
(N
));
1703 -- Analyze prefix and exit if error in analysis. If the prefix is an
1704 -- incomplete type, use full view if available. A special case is
1705 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1706 -- or UET_Address attribute.
1708 if Aname
/= Name_Elab_Body
1710 Aname
/= Name_Elab_Spec
1712 Aname
/= Name_UET_Address
1715 P_Type
:= Etype
(P
);
1717 if Is_Entity_Name
(P
)
1718 and then Present
(Entity
(P
))
1719 and then Is_Type
(Entity
(P
))
1721 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
1722 P_Type
:= Get_Full_View
(P_Type
);
1723 Set_Entity
(P
, P_Type
);
1724 Set_Etype
(P
, P_Type
);
1726 elsif Entity
(P
) = Current_Scope
1727 and then Is_Record_Type
(Entity
(P
))
1729 -- Use of current instance within the type. Verify that if the
1730 -- attribute appears within a constraint, it yields an access
1731 -- type, other uses are illegal.
1739 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
1741 Par
:= Parent
(Par
);
1745 and then Nkind
(Par
) = N_Subtype_Indication
1747 if Attr_Id
/= Attribute_Access
1748 and then Attr_Id
/= Attribute_Unchecked_Access
1749 and then Attr_Id
/= Attribute_Unrestricted_Access
1752 ("in a constraint the current instance can only"
1753 & " be used with an access attribute", N
);
1760 if P_Type
= Any_Type
then
1761 raise Bad_Attribute
;
1764 P_Base_Type
:= Base_Type
(P_Type
);
1767 -- Analyze expressions that may be present, exiting if an error occurs
1774 E1
:= First
(Exprs
);
1777 -- Check for missing or bad expression (result of previous error)
1779 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1780 raise Bad_Attribute
;
1785 if Present
(E2
) then
1788 if Etype
(E2
) = Any_Type
then
1789 raise Bad_Attribute
;
1792 if Present
(Next
(E2
)) then
1793 Unexpected_Argument
(Next
(E2
));
1798 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1799 -- output compiling in Ada 95 mode
1801 if Ada_Version
< Ada_05
1802 and then Is_Overloaded
(P
)
1803 and then Aname
/= Name_Access
1804 and then Aname
/= Name_Address
1805 and then Aname
/= Name_Code_Address
1806 and then Aname
/= Name_Count
1807 and then Aname
/= Name_Unchecked_Access
1809 Error_Attr
("ambiguous prefix for % attribute", P
);
1811 elsif Ada_Version
>= Ada_05
1812 and then Is_Overloaded
(P
)
1813 and then Aname
/= Name_Access
1814 and then Aname
/= Name_Address
1815 and then Aname
/= Name_Code_Address
1816 and then Aname
/= Name_Unchecked_Access
1818 -- Ada 2005 (AI-345): Since protected and task types have primitive
1819 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1822 if Ada_Version
>= Ada_05
1823 and then (Aname
= Name_Count
1824 or else Aname
= Name_Caller
1825 or else Aname
= Name_AST_Entry
)
1828 Count
: Natural := 0;
1833 Get_First_Interp
(P
, I
, It
);
1834 while Present
(It
.Nam
) loop
1835 if Comes_From_Source
(It
.Nam
) then
1841 Get_Next_Interp
(I
, It
);
1845 Error_Attr
("ambiguous prefix for % attribute", P
);
1847 Set_Is_Overloaded
(P
, False);
1852 Error_Attr
("ambiguous prefix for % attribute", P
);
1856 -- Remaining processing depends on attribute
1864 when Attribute_Abort_Signal
=>
1865 Check_Standard_Prefix
;
1867 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1874 when Attribute_Access
=>
1875 Analyze_Access_Attribute
;
1881 when Attribute_Address
=>
1884 -- Check for some junk cases, where we have to allow the address
1885 -- attribute but it does not make much sense, so at least for now
1886 -- just replace with Null_Address.
1888 -- We also do this if the prefix is a reference to the AST_Entry
1889 -- attribute. If expansion is active, the attribute will be
1890 -- replaced by a function call, and address will work fine and
1891 -- get the proper value, but if expansion is not active, then
1892 -- the check here allows proper semantic analysis of the reference.
1894 -- An Address attribute created by expansion is legal even when it
1895 -- applies to other entity-denoting expressions.
1897 if Is_Entity_Name
(P
) then
1899 Ent
: constant Entity_Id
:= Entity
(P
);
1902 if Is_Subprogram
(Ent
) then
1903 if not Is_Library_Level_Entity
(Ent
) then
1904 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1907 Set_Address_Taken
(Ent
);
1909 -- An Address attribute is accepted when generated by
1910 -- the compiler for dispatching operation, and an error
1911 -- is issued once the subprogram is frozen (to avoid
1912 -- confusing errors about implicit uses of Address in
1913 -- the dispatch table initialization).
1915 if Is_Always_Inlined
(Entity
(P
))
1916 and then Comes_From_Source
(P
)
1919 ("prefix of % attribute cannot be Inline_Always" &
1923 elsif Is_Object
(Ent
)
1924 or else Ekind
(Ent
) = E_Label
1926 Set_Address_Taken
(Ent
);
1928 -- If we have an address of an object, and the attribute
1929 -- comes from source, then set the object as potentially
1930 -- source modified. We do this because the resulting address
1931 -- can potentially be used to modify the variable and we
1932 -- might not detect this, leading to some junk warnings.
1934 Set_Never_Set_In_Source
(Ent
, False);
1936 elsif (Is_Concurrent_Type
(Etype
(Ent
))
1937 and then Etype
(Ent
) = Base_Type
(Ent
))
1938 or else Ekind
(Ent
) = E_Package
1939 or else Is_Generic_Unit
(Ent
)
1942 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1945 Error_Attr
("invalid prefix for % attribute", P
);
1949 elsif Nkind
(P
) = N_Attribute_Reference
1950 and then Attribute_Name
(P
) = Name_AST_Entry
1953 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1955 elsif Is_Object_Reference
(P
) then
1958 elsif Nkind
(P
) = N_Selected_Component
1959 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1963 -- What exactly are we allowing here ??? and is this properly
1964 -- documented in the sinfo documentation for this node ???
1966 elsif not Comes_From_Source
(N
) then
1970 Error_Attr
("invalid prefix for % attribute", P
);
1973 Set_Etype
(N
, RTE
(RE_Address
));
1979 when Attribute_Address_Size
=>
1980 Standard_Attribute
(System_Address_Size
);
1986 when Attribute_Adjacent
=>
1987 Check_Floating_Point_Type_2
;
1988 Set_Etype
(N
, P_Base_Type
);
1989 Resolve
(E1
, P_Base_Type
);
1990 Resolve
(E2
, P_Base_Type
);
1996 when Attribute_Aft
=>
1997 Check_Fixed_Point_Type_0
;
1998 Set_Etype
(N
, Universal_Integer
);
2004 when Attribute_Alignment
=>
2006 -- Don't we need more checking here, cf Size ???
2009 Check_Not_Incomplete_Type
;
2010 Set_Etype
(N
, Universal_Integer
);
2016 when Attribute_Asm_Input
=>
2017 Check_Asm_Attribute
;
2018 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2024 when Attribute_Asm_Output
=>
2025 Check_Asm_Attribute
;
2027 if Etype
(E2
) = Any_Type
then
2030 elsif Aname
= Name_Asm_Output
then
2031 if not Is_Variable
(E2
) then
2033 ("second argument for Asm_Output is not variable", E2
);
2037 Note_Possible_Modification
(E2
);
2038 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2044 when Attribute_AST_Entry
=> AST_Entry
: declare
2050 -- Indicates if entry family index is present. Note the coding
2051 -- here handles the entry family case, but in fact it cannot be
2052 -- executed currently, because pragma AST_Entry does not permit
2053 -- the specification of an entry family.
2055 procedure Bad_AST_Entry
;
2056 -- Signal a bad AST_Entry pragma
2058 function OK_Entry
(E
: Entity_Id
) return Boolean;
2059 -- Checks that E is of an appropriate entity kind for an entry
2060 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2061 -- is set True for the entry family case). In the True case,
2062 -- makes sure that Is_AST_Entry is set on the entry.
2064 procedure Bad_AST_Entry
is
2066 Error_Attr
("prefix for % attribute must be task entry", P
);
2069 function OK_Entry
(E
: Entity_Id
) return Boolean is
2074 Result
:= (Ekind
(E
) = E_Entry_Family
);
2076 Result
:= (Ekind
(E
) = E_Entry
);
2080 if not Is_AST_Entry
(E
) then
2081 Error_Msg_Name_2
:= Aname
;
2083 ("% attribute requires previous % pragma", P
);
2090 -- Start of processing for AST_Entry
2096 -- Deal with entry family case
2098 if Nkind
(P
) = N_Indexed_Component
then
2106 Ptyp
:= Etype
(Pref
);
2108 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2112 -- If the prefix is a selected component whose prefix is of an
2113 -- access type, then introduce an explicit dereference.
2114 -- ??? Could we reuse Check_Dereference here?
2116 if Nkind
(Pref
) = N_Selected_Component
2117 and then Is_Access_Type
(Ptyp
)
2120 Make_Explicit_Dereference
(Sloc
(Pref
),
2121 Relocate_Node
(Pref
)));
2122 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2125 -- Prefix can be of the form a.b, where a is a task object
2126 -- and b is one of the entries of the corresponding task type.
2128 if Nkind
(Pref
) = N_Selected_Component
2129 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2130 and then Is_Object_Reference
(Prefix
(Pref
))
2131 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2135 -- Otherwise the prefix must be an entry of a containing task,
2136 -- or of a variable of the enclosing task type.
2139 if Nkind
(Pref
) = N_Identifier
2140 or else Nkind
(Pref
) = N_Expanded_Name
2142 Ent
:= Entity
(Pref
);
2144 if not OK_Entry
(Ent
)
2145 or else not In_Open_Scopes
(Scope
(Ent
))
2155 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2162 -- Note: when the base attribute appears in the context of a subtype
2163 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2164 -- the following circuit.
2166 when Attribute_Base
=> Base
: declare
2170 Check_Either_E0_Or_E1
;
2174 if Ada_Version
>= Ada_95
2175 and then not Is_Scalar_Type
(Typ
)
2176 and then not Is_Generic_Type
(Typ
)
2178 Error_Msg_N
("prefix of Base attribute must be scalar type", N
);
2180 elsif Sloc
(Typ
) = Standard_Location
2181 and then Base_Type
(Typ
) = Typ
2182 and then Warn_On_Redundant_Constructs
2185 ("?redudant attribute, & is its own base type", N
, Typ
);
2188 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2190 -- If we have an expression present, then really this is a conversion
2191 -- and the tree must be reformed. Note that this is one of the cases
2192 -- in which we do a replace rather than a rewrite, because the
2193 -- original tree is junk.
2195 if Present
(E1
) then
2197 Make_Type_Conversion
(Loc
,
2199 Make_Attribute_Reference
(Loc
,
2200 Prefix
=> Prefix
(N
),
2201 Attribute_Name
=> Name_Base
),
2202 Expression
=> Relocate_Node
(E1
)));
2204 -- E1 may be overloaded, and its interpretations preserved
2206 Save_Interps
(E1
, Expression
(N
));
2209 -- For other cases, set the proper type as the entity of the
2210 -- attribute reference, and then rewrite the node to be an
2211 -- occurrence of the referenced base type. This way, no one
2212 -- else in the compiler has to worry about the base attribute.
2215 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2217 New_Reference_To
(Entity
(N
), Loc
));
2226 when Attribute_Bit
=> Bit
:
2230 if not Is_Object_Reference
(P
) then
2231 Error_Attr
("prefix for % attribute must be object", P
);
2233 -- What about the access object cases ???
2239 Set_Etype
(N
, Universal_Integer
);
2246 when Attribute_Bit_Order
=> Bit_Order
:
2251 if not Is_Record_Type
(P_Type
) then
2252 Error_Attr
("prefix of % attribute must be record type", P
);
2255 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2257 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2260 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2263 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2266 -- Reset incorrect indication of staticness
2268 Set_Is_Static_Expression
(N
, False);
2275 -- Note: in generated code, we can have a Bit_Position attribute
2276 -- applied to a (naked) record component (i.e. the prefix is an
2277 -- identifier that references an E_Component or E_Discriminant
2278 -- entity directly, and this is interpreted as expected by Gigi.
2279 -- The following code will not tolerate such usage, but when the
2280 -- expander creates this special case, it marks it as analyzed
2281 -- immediately and sets an appropriate type.
2283 when Attribute_Bit_Position
=>
2285 if Comes_From_Source
(N
) then
2289 Set_Etype
(N
, Universal_Integer
);
2295 when Attribute_Body_Version
=>
2298 Set_Etype
(N
, RTE
(RE_Version_String
));
2304 when Attribute_Callable
=>
2306 Set_Etype
(N
, Standard_Boolean
);
2313 when Attribute_Caller
=> Caller
: declare
2320 if Nkind
(P
) = N_Identifier
2321 or else Nkind
(P
) = N_Expanded_Name
2325 if not Is_Entry
(Ent
) then
2326 Error_Attr
("invalid entry name", N
);
2330 Error_Attr
("invalid entry name", N
);
2334 for J
in reverse 0 .. Scope_Stack
.Last
loop
2335 S
:= Scope_Stack
.Table
(J
).Entity
;
2337 if S
= Scope
(Ent
) then
2338 Error_Attr
("Caller must appear in matching accept or body", N
);
2344 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2351 when Attribute_Ceiling
=>
2352 Check_Floating_Point_Type_1
;
2353 Set_Etype
(N
, P_Base_Type
);
2354 Resolve
(E1
, P_Base_Type
);
2360 when Attribute_Class
=> Class
: declare
2361 P
: constant Entity_Id
:= Prefix
(N
);
2364 Check_Restriction
(No_Dispatch
, N
);
2365 Check_Either_E0_Or_E1
;
2367 -- If we have an expression present, then really this is a conversion
2368 -- and the tree must be reformed into a proper conversion. This is a
2369 -- Replace rather than a Rewrite, because the original tree is junk.
2370 -- If expression is overloaded, propagate interpretations to new one.
2372 if Present
(E1
) then
2374 Make_Type_Conversion
(Loc
,
2376 Make_Attribute_Reference
(Loc
,
2378 Attribute_Name
=> Name_Class
),
2379 Expression
=> Relocate_Node
(E1
)));
2381 Save_Interps
(E1
, Expression
(N
));
2383 -- Ada 2005 (AI-251): In case of abstract interfaces we have to
2384 -- analyze and resolve the type conversion to generate the code
2385 -- that displaces the reference to the base of the object.
2387 if Is_Interface
(Etype
(P
))
2388 or else Is_Interface
(Etype
(E1
))
2390 Analyze_And_Resolve
(N
, Etype
(P
));
2395 -- Otherwise we just need to find the proper type
2407 when Attribute_Code_Address
=>
2410 if Nkind
(P
) = N_Attribute_Reference
2411 and then (Attribute_Name
(P
) = Name_Elab_Body
2413 Attribute_Name
(P
) = Name_Elab_Spec
)
2417 elsif not Is_Entity_Name
(P
)
2418 or else (Ekind
(Entity
(P
)) /= E_Function
2420 Ekind
(Entity
(P
)) /= E_Procedure
)
2422 Error_Attr
("invalid prefix for % attribute", P
);
2423 Set_Address_Taken
(Entity
(P
));
2426 Set_Etype
(N
, RTE
(RE_Address
));
2428 --------------------
2429 -- Component_Size --
2430 --------------------
2432 when Attribute_Component_Size
=>
2434 Set_Etype
(N
, Universal_Integer
);
2436 -- Note: unlike other array attributes, unconstrained arrays are OK
2438 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2448 when Attribute_Compose
=>
2449 Check_Floating_Point_Type_2
;
2450 Set_Etype
(N
, P_Base_Type
);
2451 Resolve
(E1
, P_Base_Type
);
2452 Resolve
(E2
, Any_Integer
);
2458 when Attribute_Constrained
=>
2460 Set_Etype
(N
, Standard_Boolean
);
2462 -- Case from RM J.4(2) of constrained applied to private type
2464 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2465 Check_Restriction
(No_Obsolescent_Features
, N
);
2467 if Warn_On_Obsolescent_Feature
then
2469 ("constrained for private type is an " &
2470 "obsolescent feature ('R'M 'J.4)?", N
);
2473 -- If we are within an instance, the attribute must be legal
2474 -- because it was valid in the generic unit. Ditto if this is
2475 -- an inlining of a function declared in an instance.
2478 or else In_Inlined_Body
2482 -- For sure OK if we have a real private type itself, but must
2483 -- be completed, cannot apply Constrained to incomplete type.
2485 elsif Is_Private_Type
(Entity
(P
)) then
2487 -- Note: this is one of the Annex J features that does not
2488 -- generate a warning from -gnatwj, since in fact it seems
2489 -- very useful, and is used in the GNAT runtime.
2491 Check_Not_Incomplete_Type
;
2495 -- Normal (non-obsolescent case) of application to object of
2496 -- a discriminated type.
2499 Check_Object_Reference
(P
);
2501 -- If N does not come from source, then we allow the
2502 -- the attribute prefix to be of a private type whose
2503 -- full type has discriminants. This occurs in cases
2504 -- involving expanded calls to stream attributes.
2506 if not Comes_From_Source
(N
) then
2507 P_Type
:= Underlying_Type
(P_Type
);
2510 -- Must have discriminants or be an access type designating
2511 -- a type with discriminants. If it is a classwide type is
2512 -- has unknown discriminants.
2514 if Has_Discriminants
(P_Type
)
2515 or else Has_Unknown_Discriminants
(P_Type
)
2517 (Is_Access_Type
(P_Type
)
2518 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2522 -- Also allow an object of a generic type if extensions allowed
2523 -- and allow this for any type at all.
2525 elsif (Is_Generic_Type
(P_Type
)
2526 or else Is_Generic_Actual_Type
(P_Type
))
2527 and then Extensions_Allowed
2533 -- Fall through if bad prefix
2536 ("prefix of % attribute must be object of discriminated type", P
);
2542 when Attribute_Copy_Sign
=>
2543 Check_Floating_Point_Type_2
;
2544 Set_Etype
(N
, P_Base_Type
);
2545 Resolve
(E1
, P_Base_Type
);
2546 Resolve
(E2
, P_Base_Type
);
2552 when Attribute_Count
=> Count
:
2561 if Nkind
(P
) = N_Identifier
2562 or else Nkind
(P
) = N_Expanded_Name
2566 if Ekind
(Ent
) /= E_Entry
then
2567 Error_Attr
("invalid entry name", N
);
2570 elsif Nkind
(P
) = N_Indexed_Component
then
2571 if not Is_Entity_Name
(Prefix
(P
))
2572 or else No
(Entity
(Prefix
(P
)))
2573 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2575 if Nkind
(Prefix
(P
)) = N_Selected_Component
2576 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2577 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2581 ("attribute % must apply to entry of current task", P
);
2584 Error_Attr
("invalid entry family name", P
);
2589 Ent
:= Entity
(Prefix
(P
));
2592 elsif Nkind
(P
) = N_Selected_Component
2593 and then Present
(Entity
(Selector_Name
(P
)))
2594 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2597 ("attribute % must apply to entry of current task", P
);
2600 Error_Attr
("invalid entry name", N
);
2604 for J
in reverse 0 .. Scope_Stack
.Last
loop
2605 S
:= Scope_Stack
.Table
(J
).Entity
;
2607 if S
= Scope
(Ent
) then
2608 if Nkind
(P
) = N_Expanded_Name
then
2609 Tsk
:= Entity
(Prefix
(P
));
2611 -- The prefix denotes either the task type, or else a
2612 -- single task whose task type is being analyzed.
2617 or else (not Is_Type
(Tsk
)
2618 and then Etype
(Tsk
) = S
2619 and then not (Comes_From_Source
(S
)))
2624 ("Attribute % must apply to entry of current task", N
);
2630 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2631 and then Ekind
(S
) /= E_Loop
2632 and then Ekind
(S
) /= E_Block
2633 and then Ekind
(S
) /= E_Entry
2634 and then Ekind
(S
) /= E_Entry_Family
2636 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2638 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2639 and then not Has_Completion
(Scope
(Ent
))
2641 Error_Attr
("attribute % can only be used inside body", N
);
2645 if Is_Overloaded
(P
) then
2647 Index
: Interp_Index
;
2651 Get_First_Interp
(P
, Index
, It
);
2653 while Present
(It
.Nam
) loop
2654 if It
.Nam
= Ent
then
2657 -- Ada 2005 (AI-345): Do not consider primitive entry
2658 -- wrappers generated for task or protected types.
2660 elsif Ada_Version
>= Ada_05
2661 and then not Comes_From_Source
(It
.Nam
)
2666 Error_Attr
("ambiguous entry name", N
);
2669 Get_Next_Interp
(Index
, It
);
2674 Set_Etype
(N
, Universal_Integer
);
2677 -----------------------
2678 -- Default_Bit_Order --
2679 -----------------------
2681 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2683 Check_Standard_Prefix
;
2686 if Bytes_Big_Endian
then
2688 Make_Integer_Literal
(Loc
, False_Value
));
2691 Make_Integer_Literal
(Loc
, True_Value
));
2694 Set_Etype
(N
, Universal_Integer
);
2695 Set_Is_Static_Expression
(N
);
2696 end Default_Bit_Order
;
2702 when Attribute_Definite
=>
2703 Legal_Formal_Attribute
;
2709 when Attribute_Delta
=>
2710 Check_Fixed_Point_Type_0
;
2711 Set_Etype
(N
, Universal_Real
);
2717 when Attribute_Denorm
=>
2718 Check_Floating_Point_Type_0
;
2719 Set_Etype
(N
, Standard_Boolean
);
2725 when Attribute_Digits
=>
2729 if not Is_Floating_Point_Type
(P_Type
)
2730 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2733 ("prefix of % attribute must be float or decimal type", P
);
2736 Set_Etype
(N
, Universal_Integer
);
2742 -- Also handles processing for Elab_Spec
2744 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2746 Check_Unit_Name
(P
);
2747 Set_Etype
(N
, Standard_Void_Type
);
2749 -- We have to manually call the expander in this case to get
2750 -- the necessary expansion (normally attributes that return
2751 -- entities are not expanded).
2759 -- Shares processing with Elab_Body
2765 when Attribute_Elaborated
=>
2768 Set_Etype
(N
, Standard_Boolean
);
2774 when Attribute_Emax
=>
2775 Check_Floating_Point_Type_0
;
2776 Set_Etype
(N
, Universal_Integer
);
2782 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2784 if Present
(E1
) then
2786 Check_Discrete_Type
;
2787 Resolve
(E1
, P_Base_Type
);
2790 if not Is_Entity_Name
(P
)
2791 or else (not Is_Object
(Entity
(P
))
2793 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2796 ("prefix of %attribute must be " &
2797 "discrete type/object or enum literal", P
);
2801 Set_Etype
(N
, Universal_Integer
);
2808 when Attribute_Epsilon
=>
2809 Check_Floating_Point_Type_0
;
2810 Set_Etype
(N
, Universal_Real
);
2816 when Attribute_Exponent
=>
2817 Check_Floating_Point_Type_1
;
2818 Set_Etype
(N
, Universal_Integer
);
2819 Resolve
(E1
, P_Base_Type
);
2825 when Attribute_External_Tag
=>
2829 Set_Etype
(N
, Standard_String
);
2831 if not Is_Tagged_Type
(P_Type
) then
2832 Error_Attr
("prefix of % attribute must be tagged", P
);
2839 when Attribute_First
=>
2840 Check_Array_Or_Scalar_Type
;
2846 when Attribute_First_Bit
=>
2848 Set_Etype
(N
, Universal_Integer
);
2854 when Attribute_Fixed_Value
=>
2856 Check_Fixed_Point_Type
;
2857 Resolve
(E1
, Any_Integer
);
2858 Set_Etype
(N
, P_Base_Type
);
2864 when Attribute_Floor
=>
2865 Check_Floating_Point_Type_1
;
2866 Set_Etype
(N
, P_Base_Type
);
2867 Resolve
(E1
, P_Base_Type
);
2873 when Attribute_Fore
=>
2874 Check_Fixed_Point_Type_0
;
2875 Set_Etype
(N
, Universal_Integer
);
2881 when Attribute_Fraction
=>
2882 Check_Floating_Point_Type_1
;
2883 Set_Etype
(N
, P_Base_Type
);
2884 Resolve
(E1
, P_Base_Type
);
2886 -----------------------
2887 -- Has_Access_Values --
2888 -----------------------
2890 when Attribute_Has_Access_Values
=>
2893 Set_Etype
(N
, Standard_Boolean
);
2895 -----------------------
2896 -- Has_Discriminants --
2897 -----------------------
2899 when Attribute_Has_Discriminants
=>
2900 Legal_Formal_Attribute
;
2906 when Attribute_Identity
=>
2910 if Etype
(P
) = Standard_Exception_Type
then
2911 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2913 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
2914 -- task interface class-wide types.
2916 elsif Is_Task_Type
(Etype
(P
))
2917 or else (Is_Access_Type
(Etype
(P
))
2918 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2919 or else (Ada_Version
>= Ada_05
2920 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2921 and then Is_Interface
(Etype
(P
))
2922 and then Is_Task_Interface
(Etype
(P
)))
2925 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2928 if Ada_Version
>= Ada_05
then
2929 Error_Attr
("prefix of % attribute must be an exception, a "
2930 & "task or a task interface class-wide object", P
);
2932 Error_Attr
("prefix of % attribute must be a task or an "
2941 when Attribute_Image
=> Image
:
2943 Set_Etype
(N
, Standard_String
);
2946 if Is_Real_Type
(P_Type
) then
2947 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2948 Error_Msg_Name_1
:= Aname
;
2950 ("(Ada 83) % attribute not allowed for real types", N
);
2954 if Is_Enumeration_Type
(P_Type
) then
2955 Check_Restriction
(No_Enumeration_Maps
, N
);
2959 Resolve
(E1
, P_Base_Type
);
2961 Validate_Non_Static_Attribute_Function_Call
;
2968 when Attribute_Img
=> Img
:
2970 Set_Etype
(N
, Standard_String
);
2972 if not Is_Scalar_Type
(P_Type
)
2973 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2976 ("prefix of % attribute must be scalar object name", N
);
2986 when Attribute_Input
=>
2988 Check_Stream_Attribute
(TSS_Stream_Input
);
2989 Set_Etype
(N
, P_Base_Type
);
2995 when Attribute_Integer_Value
=>
2998 Resolve
(E1
, Any_Fixed
);
2999 Set_Etype
(N
, P_Base_Type
);
3005 when Attribute_Large
=>
3008 Set_Etype
(N
, Universal_Real
);
3014 when Attribute_Last
=>
3015 Check_Array_Or_Scalar_Type
;
3021 when Attribute_Last_Bit
=>
3023 Set_Etype
(N
, Universal_Integer
);
3029 when Attribute_Leading_Part
=>
3030 Check_Floating_Point_Type_2
;
3031 Set_Etype
(N
, P_Base_Type
);
3032 Resolve
(E1
, P_Base_Type
);
3033 Resolve
(E2
, Any_Integer
);
3039 when Attribute_Length
=>
3041 Set_Etype
(N
, Universal_Integer
);
3047 when Attribute_Machine
=>
3048 Check_Floating_Point_Type_1
;
3049 Set_Etype
(N
, P_Base_Type
);
3050 Resolve
(E1
, P_Base_Type
);
3056 when Attribute_Machine_Emax
=>
3057 Check_Floating_Point_Type_0
;
3058 Set_Etype
(N
, Universal_Integer
);
3064 when Attribute_Machine_Emin
=>
3065 Check_Floating_Point_Type_0
;
3066 Set_Etype
(N
, Universal_Integer
);
3068 ----------------------
3069 -- Machine_Mantissa --
3070 ----------------------
3072 when Attribute_Machine_Mantissa
=>
3073 Check_Floating_Point_Type_0
;
3074 Set_Etype
(N
, Universal_Integer
);
3076 -----------------------
3077 -- Machine_Overflows --
3078 -----------------------
3080 when Attribute_Machine_Overflows
=>
3083 Set_Etype
(N
, Standard_Boolean
);
3089 when Attribute_Machine_Radix
=>
3092 Set_Etype
(N
, Universal_Integer
);
3094 ----------------------
3095 -- Machine_Rounding --
3096 ----------------------
3098 when Attribute_Machine_Rounding
=>
3099 Check_Floating_Point_Type_1
;
3100 Set_Etype
(N
, P_Base_Type
);
3101 Resolve
(E1
, P_Base_Type
);
3103 --------------------
3104 -- Machine_Rounds --
3105 --------------------
3107 when Attribute_Machine_Rounds
=>
3110 Set_Etype
(N
, Standard_Boolean
);
3116 when Attribute_Machine_Size
=>
3119 Check_Not_Incomplete_Type
;
3120 Set_Etype
(N
, Universal_Integer
);
3126 when Attribute_Mantissa
=>
3129 Set_Etype
(N
, Universal_Integer
);
3135 when Attribute_Max
=>
3138 Resolve
(E1
, P_Base_Type
);
3139 Resolve
(E2
, P_Base_Type
);
3140 Set_Etype
(N
, P_Base_Type
);
3142 ----------------------------------
3143 -- Max_Size_In_Storage_Elements --
3144 ----------------------------------
3146 when Attribute_Max_Size_In_Storage_Elements
=>
3149 Check_Not_Incomplete_Type
;
3150 Set_Etype
(N
, Universal_Integer
);
3152 -----------------------
3153 -- Maximum_Alignment --
3154 -----------------------
3156 when Attribute_Maximum_Alignment
=>
3157 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3159 --------------------
3160 -- Mechanism_Code --
3161 --------------------
3163 when Attribute_Mechanism_Code
=>
3164 if not Is_Entity_Name
(P
)
3165 or else not Is_Subprogram
(Entity
(P
))
3167 Error_Attr
("prefix of % attribute must be subprogram", P
);
3170 Check_Either_E0_Or_E1
;
3172 if Present
(E1
) then
3173 Resolve
(E1
, Any_Integer
);
3174 Set_Etype
(E1
, Standard_Integer
);
3176 if not Is_Static_Expression
(E1
) then
3177 Flag_Non_Static_Expr
3178 ("expression for parameter number must be static!", E1
);
3181 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3182 or else UI_To_Int
(Intval
(E1
)) < 0
3184 Error_Attr
("invalid parameter number for %attribute", E1
);
3188 Set_Etype
(N
, Universal_Integer
);
3194 when Attribute_Min
=>
3197 Resolve
(E1
, P_Base_Type
);
3198 Resolve
(E2
, P_Base_Type
);
3199 Set_Etype
(N
, P_Base_Type
);
3205 when Attribute_Mod
=>
3207 -- Note: this attribute is only allowed in Ada 2005 mode, but
3208 -- we do not need to test that here, since Mod is only recognized
3209 -- as an attribute name in Ada 2005 mode during the parse.
3212 Check_Modular_Integer_Type
;
3213 Resolve
(E1
, Any_Integer
);
3214 Set_Etype
(N
, P_Base_Type
);
3220 when Attribute_Model
=>
3221 Check_Floating_Point_Type_1
;
3222 Set_Etype
(N
, P_Base_Type
);
3223 Resolve
(E1
, P_Base_Type
);
3229 when Attribute_Model_Emin
=>
3230 Check_Floating_Point_Type_0
;
3231 Set_Etype
(N
, Universal_Integer
);
3237 when Attribute_Model_Epsilon
=>
3238 Check_Floating_Point_Type_0
;
3239 Set_Etype
(N
, Universal_Real
);
3241 --------------------
3242 -- Model_Mantissa --
3243 --------------------
3245 when Attribute_Model_Mantissa
=>
3246 Check_Floating_Point_Type_0
;
3247 Set_Etype
(N
, Universal_Integer
);
3253 when Attribute_Model_Small
=>
3254 Check_Floating_Point_Type_0
;
3255 Set_Etype
(N
, Universal_Real
);
3261 when Attribute_Modulus
=>
3263 Check_Modular_Integer_Type
;
3264 Set_Etype
(N
, Universal_Integer
);
3266 --------------------
3267 -- Null_Parameter --
3268 --------------------
3270 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3271 Parnt
: constant Node_Id
:= Parent
(N
);
3272 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3274 procedure Bad_Null_Parameter
(Msg
: String);
3275 -- Used if bad Null parameter attribute node is found. Issues
3276 -- given error message, and also sets the type to Any_Type to
3277 -- avoid blowups later on from dealing with a junk node.
3279 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3280 -- Called to check that Proc_Ent is imported subprogram
3282 ------------------------
3283 -- Bad_Null_Parameter --
3284 ------------------------
3286 procedure Bad_Null_Parameter
(Msg
: String) is
3288 Error_Msg_N
(Msg
, N
);
3289 Set_Etype
(N
, Any_Type
);
3290 end Bad_Null_Parameter
;
3292 ----------------------
3293 -- Must_Be_Imported --
3294 ----------------------
3296 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3297 Pent
: Entity_Id
:= Proc_Ent
;
3300 while Present
(Alias
(Pent
)) loop
3301 Pent
:= Alias
(Pent
);
3304 -- Ignore check if procedure not frozen yet (we will get
3305 -- another chance when the default parameter is reanalyzed)
3307 if not Is_Frozen
(Pent
) then
3310 elsif not Is_Imported
(Pent
) then
3312 ("Null_Parameter can only be used with imported subprogram");
3317 end Must_Be_Imported
;
3319 -- Start of processing for Null_Parameter
3324 Set_Etype
(N
, P_Type
);
3326 -- Case of attribute used as default expression
3328 if Nkind
(Parnt
) = N_Parameter_Specification
then
3329 Must_Be_Imported
(Defining_Entity
(GParnt
));
3331 -- Case of attribute used as actual for subprogram (positional)
3333 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
3335 Nkind
(Parnt
) = N_Function_Call
)
3336 and then Is_Entity_Name
(Name
(Parnt
))
3338 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3340 -- Case of attribute used as actual for subprogram (named)
3342 elsif Nkind
(Parnt
) = N_Parameter_Association
3343 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
3345 Nkind
(GParnt
) = N_Function_Call
)
3346 and then Is_Entity_Name
(Name
(GParnt
))
3348 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3350 -- Not an allowed case
3354 ("Null_Parameter must be actual or default parameter");
3363 when Attribute_Object_Size
=>
3366 Check_Not_Incomplete_Type
;
3367 Set_Etype
(N
, Universal_Integer
);
3373 when Attribute_Output
=>
3375 Check_Stream_Attribute
(TSS_Stream_Output
);
3376 Set_Etype
(N
, Standard_Void_Type
);
3377 Resolve
(N
, Standard_Void_Type
);
3383 when Attribute_Partition_ID
=>
3386 if P_Type
/= Any_Type
then
3387 if not Is_Library_Level_Entity
(Entity
(P
)) then
3389 ("prefix of % attribute must be library-level entity", P
);
3391 -- The defining entity of prefix should not be declared inside
3392 -- a Pure unit. RM E.1(8).
3393 -- The Is_Pure flag has been set during declaration.
3395 elsif Is_Entity_Name
(P
)
3396 and then Is_Pure
(Entity
(P
))
3399 ("prefix of % attribute must not be declared pure", P
);
3403 Set_Etype
(N
, Universal_Integer
);
3405 -------------------------
3406 -- Passed_By_Reference --
3407 -------------------------
3409 when Attribute_Passed_By_Reference
=>
3412 Set_Etype
(N
, Standard_Boolean
);
3418 when Attribute_Pool_Address
=>
3420 Set_Etype
(N
, RTE
(RE_Address
));
3426 when Attribute_Pos
=>
3427 Check_Discrete_Type
;
3429 Resolve
(E1
, P_Base_Type
);
3430 Set_Etype
(N
, Universal_Integer
);
3436 when Attribute_Position
=>
3438 Set_Etype
(N
, Universal_Integer
);
3444 when Attribute_Pred
=>
3447 Resolve
(E1
, P_Base_Type
);
3448 Set_Etype
(N
, P_Base_Type
);
3450 -- Nothing to do for real type case
3452 if Is_Real_Type
(P_Type
) then
3455 -- If not modular type, test for overflow check required
3458 if not Is_Modular_Integer_Type
(P_Type
)
3459 and then not Range_Checks_Suppressed
(P_Base_Type
)
3461 Enable_Range_Check
(E1
);
3469 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3471 when Attribute_Priority
=>
3472 if Ada_Version
< Ada_05
then
3473 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
3478 -- The prefix must be a protected object (AARM D.5.2 (2/2))
3482 if Is_Protected_Type
(Etype
(P
))
3483 or else (Is_Access_Type
(Etype
(P
))
3484 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
3486 Resolve
(P
, Etype
(P
));
3488 Error_Attr
("prefix of % attribute must be a protected object", P
);
3491 Set_Etype
(N
, Standard_Integer
);
3493 -- Must be called from within a protected procedure or entry of the
3494 -- protected object.
3501 while S
/= Etype
(P
)
3502 and then S
/= Standard_Standard
3507 if S
= Standard_Standard
then
3508 Error_Attr
("the attribute % is only allowed inside protected "
3513 Validate_Non_Static_Attribute_Function_Call
;
3519 when Attribute_Range
=>
3520 Check_Array_Or_Scalar_Type
;
3522 if Ada_Version
= Ada_83
3523 and then Is_Scalar_Type
(P_Type
)
3524 and then Comes_From_Source
(N
)
3527 ("(Ada 83) % attribute not allowed for scalar type", P
);
3534 when Attribute_Range_Length
=>
3535 Check_Discrete_Type
;
3536 Set_Etype
(N
, Universal_Integer
);
3542 when Attribute_Read
=>
3544 Check_Stream_Attribute
(TSS_Stream_Read
);
3545 Set_Etype
(N
, Standard_Void_Type
);
3546 Resolve
(N
, Standard_Void_Type
);
3547 Note_Possible_Modification
(E2
);
3553 when Attribute_Remainder
=>
3554 Check_Floating_Point_Type_2
;
3555 Set_Etype
(N
, P_Base_Type
);
3556 Resolve
(E1
, P_Base_Type
);
3557 Resolve
(E2
, P_Base_Type
);
3563 when Attribute_Round
=>
3565 Check_Decimal_Fixed_Point_Type
;
3566 Set_Etype
(N
, P_Base_Type
);
3568 -- Because the context is universal_real (3.5.10(12)) it is a legal
3569 -- context for a universal fixed expression. This is the only
3570 -- attribute whose functional description involves U_R.
3572 if Etype
(E1
) = Universal_Fixed
then
3574 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3575 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3576 Expression
=> Relocate_Node
(E1
));
3584 Resolve
(E1
, Any_Real
);
3590 when Attribute_Rounding
=>
3591 Check_Floating_Point_Type_1
;
3592 Set_Etype
(N
, P_Base_Type
);
3593 Resolve
(E1
, P_Base_Type
);
3599 when Attribute_Safe_Emax
=>
3600 Check_Floating_Point_Type_0
;
3601 Set_Etype
(N
, Universal_Integer
);
3607 when Attribute_Safe_First
=>
3608 Check_Floating_Point_Type_0
;
3609 Set_Etype
(N
, Universal_Real
);
3615 when Attribute_Safe_Large
=>
3618 Set_Etype
(N
, Universal_Real
);
3624 when Attribute_Safe_Last
=>
3625 Check_Floating_Point_Type_0
;
3626 Set_Etype
(N
, Universal_Real
);
3632 when Attribute_Safe_Small
=>
3635 Set_Etype
(N
, Universal_Real
);
3641 when Attribute_Scale
=>
3643 Check_Decimal_Fixed_Point_Type
;
3644 Set_Etype
(N
, Universal_Integer
);
3650 when Attribute_Scaling
=>
3651 Check_Floating_Point_Type_2
;
3652 Set_Etype
(N
, P_Base_Type
);
3653 Resolve
(E1
, P_Base_Type
);
3659 when Attribute_Signed_Zeros
=>
3660 Check_Floating_Point_Type_0
;
3661 Set_Etype
(N
, Standard_Boolean
);
3667 when Attribute_Size | Attribute_VADS_Size
=>
3670 -- If prefix is parameterless function call, rewrite and resolve
3673 if Is_Entity_Name
(P
)
3674 and then Ekind
(Entity
(P
)) = E_Function
3678 -- Similar processing for a protected function call
3680 elsif Nkind
(P
) = N_Selected_Component
3681 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
3686 if Is_Object_Reference
(P
) then
3687 Check_Object_Reference
(P
);
3689 elsif Is_Entity_Name
(P
)
3690 and then (Is_Type
(Entity
(P
))
3691 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
3695 elsif Nkind
(P
) = N_Type_Conversion
3696 and then not Comes_From_Source
(P
)
3701 Error_Attr
("invalid prefix for % attribute", P
);
3704 Check_Not_Incomplete_Type
;
3705 Set_Etype
(N
, Universal_Integer
);
3711 when Attribute_Small
=>
3714 Set_Etype
(N
, Universal_Real
);
3720 when Attribute_Storage_Pool
=>
3721 if Is_Access_Type
(P_Type
) then
3724 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
3726 ("cannot use % attribute for access-to-subprogram type", P
);
3729 -- Set appropriate entity
3731 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3732 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3734 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3737 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3739 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3740 -- Storage_Pool since this attribute is not defined for such
3741 -- types (RM E.2.3(22)).
3743 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3746 Error_Attr
("prefix of % attribute must be access type", P
);
3753 when Attribute_Storage_Size
=>
3754 if Is_Task_Type
(P_Type
) then
3756 Set_Etype
(N
, Universal_Integer
);
3758 elsif Is_Access_Type
(P_Type
) then
3759 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
3761 ("cannot use % attribute for access-to-subprogram type", P
);
3764 if Is_Entity_Name
(P
)
3765 and then Is_Type
(Entity
(P
))
3769 Set_Etype
(N
, Universal_Integer
);
3771 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3772 -- Storage_Size since this attribute is not defined for
3773 -- such types (RM E.2.3(22)).
3775 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3777 -- The prefix is allowed to be an implicit dereference
3778 -- of an access value designating a task.
3783 Set_Etype
(N
, Universal_Integer
);
3788 ("prefix of % attribute must be access or task type", P
);
3795 when Attribute_Storage_Unit
=>
3796 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3802 when Attribute_Stream_Size
=>
3806 if Is_Entity_Name
(P
)
3807 and then Is_Elementary_Type
(Entity
(P
))
3809 Set_Etype
(N
, Universal_Integer
);
3811 Error_Attr
("invalid prefix for % attribute", P
);
3818 when Attribute_Stub_Type
=>
3822 if Is_Remote_Access_To_Class_Wide_Type
(P_Type
) then
3824 New_Occurrence_Of
(Corresponding_Stub_Type
(P_Type
), Loc
));
3827 ("prefix of% attribute must be remote access to classwide", P
);
3834 when Attribute_Succ
=>
3837 Resolve
(E1
, P_Base_Type
);
3838 Set_Etype
(N
, P_Base_Type
);
3840 -- Nothing to do for real type case
3842 if Is_Real_Type
(P_Type
) then
3845 -- If not modular type, test for overflow check required
3848 if not Is_Modular_Integer_Type
(P_Type
)
3849 and then not Range_Checks_Suppressed
(P_Base_Type
)
3851 Enable_Range_Check
(E1
);
3859 when Attribute_Tag
=>
3863 if not Is_Tagged_Type
(P_Type
) then
3864 Error_Attr
("prefix of % attribute must be tagged", P
);
3866 -- Next test does not apply to generated code
3867 -- why not, and what does the illegal reference mean???
3869 elsif Is_Object_Reference
(P
)
3870 and then not Is_Class_Wide_Type
(P_Type
)
3871 and then Comes_From_Source
(N
)
3874 ("% attribute can only be applied to objects of class-wide type",
3878 Set_Etype
(N
, RTE
(RE_Tag
));
3884 when Attribute_Target_Name
=> Target_Name
: declare
3885 TN
: constant String := Sdefault
.Target_Name
.all;
3889 Check_Standard_Prefix
;
3894 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
3899 Make_String_Literal
(Loc
,
3900 Strval
=> TN
(TN
'First .. TL
)));
3901 Analyze_And_Resolve
(N
, Standard_String
);
3908 when Attribute_Terminated
=>
3910 Set_Etype
(N
, Standard_Boolean
);
3917 when Attribute_To_Address
=>
3921 if Nkind
(P
) /= N_Identifier
3922 or else Chars
(P
) /= Name_System
3924 Error_Attr
("prefix of %attribute must be System", P
);
3927 Generate_Reference
(RTE
(RE_Address
), P
);
3928 Analyze_And_Resolve
(E1
, Any_Integer
);
3929 Set_Etype
(N
, RTE
(RE_Address
));
3935 when Attribute_Truncation
=>
3936 Check_Floating_Point_Type_1
;
3937 Resolve
(E1
, P_Base_Type
);
3938 Set_Etype
(N
, P_Base_Type
);
3944 when Attribute_Type_Class
=>
3947 Check_Not_Incomplete_Type
;
3948 Set_Etype
(N
, RTE
(RE_Type_Class
));
3954 when Attribute_UET_Address
=>
3956 Check_Unit_Name
(P
);
3957 Set_Etype
(N
, RTE
(RE_Address
));
3959 -----------------------
3960 -- Unbiased_Rounding --
3961 -----------------------
3963 when Attribute_Unbiased_Rounding
=>
3964 Check_Floating_Point_Type_1
;
3965 Set_Etype
(N
, P_Base_Type
);
3966 Resolve
(E1
, P_Base_Type
);
3968 ----------------------
3969 -- Unchecked_Access --
3970 ----------------------
3972 when Attribute_Unchecked_Access
=>
3973 if Comes_From_Source
(N
) then
3974 Check_Restriction
(No_Unchecked_Access
, N
);
3977 Analyze_Access_Attribute
;
3979 -------------------------
3980 -- Unconstrained_Array --
3981 -------------------------
3983 when Attribute_Unconstrained_Array
=>
3986 Check_Not_Incomplete_Type
;
3987 Set_Etype
(N
, Standard_Boolean
);
3989 ------------------------------
3990 -- Universal_Literal_String --
3991 ------------------------------
3993 -- This is a GNAT specific attribute whose prefix must be a named
3994 -- number where the expression is either a single numeric literal,
3995 -- or a numeric literal immediately preceded by a minus sign. The
3996 -- result is equivalent to a string literal containing the text of
3997 -- the literal as it appeared in the source program with a possible
3998 -- leading minus sign.
4000 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
4004 if not Is_Entity_Name
(P
)
4005 or else Ekind
(Entity
(P
)) not in Named_Kind
4007 Error_Attr
("prefix for % attribute must be named number", P
);
4014 Src
: Source_Buffer_Ptr
;
4017 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
4019 if Nkind
(Expr
) = N_Op_Minus
then
4021 Expr
:= Original_Node
(Right_Opnd
(Expr
));
4026 if Nkind
(Expr
) /= N_Integer_Literal
4027 and then Nkind
(Expr
) /= N_Real_Literal
4030 ("named number for % attribute must be simple literal", N
);
4033 -- Build string literal corresponding to source literal text
4038 Store_String_Char
(Get_Char_Code
('-'));
4042 Src
:= Source_Text
(Get_Source_File_Index
(S
));
4044 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
4045 Store_String_Char
(Get_Char_Code
(Src
(S
)));
4049 -- Now we rewrite the attribute with the string literal
4052 Make_String_Literal
(Loc
, End_String
));
4056 end Universal_Literal_String
;
4058 -------------------------
4059 -- Unrestricted_Access --
4060 -------------------------
4062 -- This is a GNAT specific attribute which is like Access except that
4063 -- all scope checks and checks for aliased views are omitted.
4065 when Attribute_Unrestricted_Access
=>
4066 if Comes_From_Source
(N
) then
4067 Check_Restriction
(No_Unchecked_Access
, N
);
4070 if Is_Entity_Name
(P
) then
4071 Set_Address_Taken
(Entity
(P
));
4074 Analyze_Access_Attribute
;
4080 when Attribute_Val
=> Val
: declare
4083 Check_Discrete_Type
;
4084 Resolve
(E1
, Any_Integer
);
4085 Set_Etype
(N
, P_Base_Type
);
4087 -- Note, we need a range check in general, but we wait for the
4088 -- Resolve call to do this, since we want to let Eval_Attribute
4089 -- have a chance to find an static illegality first!
4096 when Attribute_Valid
=>
4099 -- Ignore check for object if we have a 'Valid reference generated
4100 -- by the expanded code, since in some cases valid checks can occur
4101 -- on items that are names, but are not objects (e.g. attributes).
4103 if Comes_From_Source
(N
) then
4104 Check_Object_Reference
(P
);
4107 if not Is_Scalar_Type
(P_Type
) then
4108 Error_Attr
("object for % attribute must be of scalar type", P
);
4111 Set_Etype
(N
, Standard_Boolean
);
4117 when Attribute_Value
=> Value
:
4122 if Is_Enumeration_Type
(P_Type
) then
4123 Check_Restriction
(No_Enumeration_Maps
, N
);
4126 -- Set Etype before resolving expression because expansion of
4127 -- expression may require enclosing type. Note that the type
4128 -- returned by 'Value is the base type of the prefix type.
4130 Set_Etype
(N
, P_Base_Type
);
4131 Validate_Non_Static_Attribute_Function_Call
;
4138 when Attribute_Value_Size
=>
4141 Check_Not_Incomplete_Type
;
4142 Set_Etype
(N
, Universal_Integer
);
4148 when Attribute_Version
=>
4151 Set_Etype
(N
, RTE
(RE_Version_String
));
4157 when Attribute_Wchar_T_Size
=>
4158 Standard_Attribute
(Interfaces_Wchar_T_Size
);
4164 when Attribute_Wide_Image
=> Wide_Image
:
4167 Set_Etype
(N
, Standard_Wide_String
);
4169 Resolve
(E1
, P_Base_Type
);
4170 Validate_Non_Static_Attribute_Function_Call
;
4173 ---------------------
4174 -- Wide_Wide_Image --
4175 ---------------------
4177 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4180 Set_Etype
(N
, Standard_Wide_Wide_String
);
4182 Resolve
(E1
, P_Base_Type
);
4183 Validate_Non_Static_Attribute_Function_Call
;
4184 end Wide_Wide_Image
;
4190 when Attribute_Wide_Value
=> Wide_Value
:
4195 -- Set Etype before resolving expression because expansion
4196 -- of expression may require enclosing type.
4198 Set_Etype
(N
, P_Type
);
4199 Validate_Non_Static_Attribute_Function_Call
;
4202 ---------------------
4203 -- Wide_Wide_Value --
4204 ---------------------
4206 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4211 -- Set Etype before resolving expression because expansion
4212 -- of expression may require enclosing type.
4214 Set_Etype
(N
, P_Type
);
4215 Validate_Non_Static_Attribute_Function_Call
;
4216 end Wide_Wide_Value
;
4218 ---------------------
4219 -- Wide_Wide_Width --
4220 ---------------------
4222 when Attribute_Wide_Wide_Width
=>
4225 Set_Etype
(N
, Universal_Integer
);
4231 when Attribute_Wide_Width
=>
4234 Set_Etype
(N
, Universal_Integer
);
4240 when Attribute_Width
=>
4243 Set_Etype
(N
, Universal_Integer
);
4249 when Attribute_Word_Size
=>
4250 Standard_Attribute
(System_Word_Size
);
4256 when Attribute_Write
=>
4258 Check_Stream_Attribute
(TSS_Stream_Write
);
4259 Set_Etype
(N
, Standard_Void_Type
);
4260 Resolve
(N
, Standard_Void_Type
);
4264 -- All errors raise Bad_Attribute, so that we get out before any further
4265 -- damage occurs when an error is detected (for example, if we check for
4266 -- one attribute expression, and the check succeeds, we want to be able
4267 -- to proceed securely assuming that an expression is in fact present.
4269 -- Note: we set the attribute analyzed in this case to prevent any
4270 -- attempt at reanalysis which could generate spurious error msgs.
4273 when Bad_Attribute
=>
4275 Set_Etype
(N
, Any_Type
);
4277 end Analyze_Attribute
;
4279 --------------------
4280 -- Eval_Attribute --
4281 --------------------
4283 procedure Eval_Attribute
(N
: Node_Id
) is
4284 Loc
: constant Source_Ptr
:= Sloc
(N
);
4285 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4286 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4287 P
: constant Node_Id
:= Prefix
(N
);
4289 C_Type
: constant Entity_Id
:= Etype
(N
);
4290 -- The type imposed by the context
4293 -- First expression, or Empty if none
4296 -- Second expression, or Empty if none
4298 P_Entity
: Entity_Id
;
4299 -- Entity denoted by prefix
4302 -- The type of the prefix
4304 P_Base_Type
: Entity_Id
;
4305 -- The base type of the prefix type
4307 P_Root_Type
: Entity_Id
;
4308 -- The root type of the prefix type
4311 -- True if the result is Static. This is set by the general processing
4312 -- to true if the prefix is static, and all expressions are static. It
4313 -- can be reset as processing continues for particular attributes
4315 Lo_Bound
, Hi_Bound
: Node_Id
;
4316 -- Expressions for low and high bounds of type or array index referenced
4317 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4320 -- Constraint error node used if we have an attribute reference has
4321 -- an argument that raises a constraint error. In this case we replace
4322 -- the attribute with a raise constraint_error node. This is important
4323 -- processing, since otherwise gigi might see an attribute which it is
4324 -- unprepared to deal with.
4326 function Aft_Value
return Nat
;
4327 -- Computes Aft value for current attribute prefix (used by Aft itself
4328 -- and also by Width for computing the Width of a fixed point type).
4330 procedure Check_Expressions
;
4331 -- In case where the attribute is not foldable, the expressions, if
4332 -- any, of the attribute, are in a non-static context. This procedure
4333 -- performs the required additional checks.
4335 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4336 -- Determines if the given type has compile time known bounds. Note
4337 -- that we enter the case statement even in cases where the prefix
4338 -- type does NOT have known bounds, so it is important to guard any
4339 -- attempt to evaluate both bounds with a call to this function.
4341 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4342 -- This procedure is called when the attribute N has a non-static
4343 -- but compile time known value given by Val. It includes the
4344 -- necessary checks for out of range values.
4346 procedure Float_Attribute_Universal_Integer
4355 -- This procedure evaluates a float attribute with no arguments that
4356 -- returns a universal integer result. The parameters give the values
4357 -- for the possible floating-point root types. See ttypef for details.
4358 -- The prefix type is a float type (and is thus not a generic type).
4360 procedure Float_Attribute_Universal_Real
4361 (IEEES_Val
: String;
4368 AAMPL_Val
: String);
4369 -- This procedure evaluates a float attribute with no arguments that
4370 -- returns a universal real result. The parameters give the values
4371 -- required for the possible floating-point root types in string
4372 -- format as real literals with a possible leading minus sign.
4373 -- The prefix type is a float type (and is thus not a generic type).
4375 function Fore_Value
return Nat
;
4376 -- Computes the Fore value for the current attribute prefix, which is
4377 -- known to be a static fixed-point type. Used by Fore and Width.
4379 function Mantissa
return Uint
;
4380 -- Returns the Mantissa value for the prefix type
4382 procedure Set_Bounds
;
4383 -- Used for First, Last and Length attributes applied to an array or
4384 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4385 -- and high bound expressions for the index referenced by the attribute
4386 -- designator (i.e. the first index if no expression is present, and
4387 -- the N'th index if the value N is present as an expression). Also
4388 -- used for First and Last of scalar types. Static is reset to False
4389 -- if the type or index type is not statically constrained.
4391 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4392 -- Verify that the prefix of a potentially static array attribute
4393 -- satisfies the conditions of 4.9 (14).
4399 function Aft_Value
return Nat
is
4405 Delta_Val
:= Delta_Value
(P_Type
);
4407 while Delta_Val
< Ureal_Tenth
loop
4408 Delta_Val
:= Delta_Val
* Ureal_10
;
4409 Result
:= Result
+ 1;
4415 -----------------------
4416 -- Check_Expressions --
4417 -----------------------
4419 procedure Check_Expressions
is
4423 while Present
(E
) loop
4424 Check_Non_Static_Context
(E
);
4427 end Check_Expressions
;
4429 ----------------------------------
4430 -- Compile_Time_Known_Attribute --
4431 ----------------------------------
4433 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4434 T
: constant Entity_Id
:= Etype
(N
);
4437 Fold_Uint
(N
, Val
, False);
4439 -- Check that result is in bounds of the type if it is static
4441 if Is_In_Range
(N
, T
) then
4444 elsif Is_Out_Of_Range
(N
, T
) then
4445 Apply_Compile_Time_Constraint_Error
4446 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4448 elsif not Range_Checks_Suppressed
(T
) then
4449 Enable_Range_Check
(N
);
4452 Set_Do_Range_Check
(N
, False);
4454 end Compile_Time_Known_Attribute
;
4456 -------------------------------
4457 -- Compile_Time_Known_Bounds --
4458 -------------------------------
4460 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4463 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4465 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4466 end Compile_Time_Known_Bounds
;
4468 ---------------------------------------
4469 -- Float_Attribute_Universal_Integer --
4470 ---------------------------------------
4472 procedure Float_Attribute_Universal_Integer
4483 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4486 if Vax_Float
(P_Base_Type
) then
4487 if Digs
= VAXFF_Digits
then
4489 elsif Digs
= VAXDF_Digits
then
4491 else pragma Assert
(Digs
= VAXGF_Digits
);
4495 elsif Is_AAMP_Float
(P_Base_Type
) then
4496 if Digs
= AAMPS_Digits
then
4498 else pragma Assert
(Digs
= AAMPL_Digits
);
4503 if Digs
= IEEES_Digits
then
4505 elsif Digs
= IEEEL_Digits
then
4507 else pragma Assert
(Digs
= IEEEX_Digits
);
4512 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4513 end Float_Attribute_Universal_Integer
;
4515 ------------------------------------
4516 -- Float_Attribute_Universal_Real --
4517 ------------------------------------
4519 procedure Float_Attribute_Universal_Real
4520 (IEEES_Val
: String;
4530 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4533 if Vax_Float
(P_Base_Type
) then
4534 if Digs
= VAXFF_Digits
then
4535 Val
:= Real_Convert
(VAXFF_Val
);
4536 elsif Digs
= VAXDF_Digits
then
4537 Val
:= Real_Convert
(VAXDF_Val
);
4538 else pragma Assert
(Digs
= VAXGF_Digits
);
4539 Val
:= Real_Convert
(VAXGF_Val
);
4542 elsif Is_AAMP_Float
(P_Base_Type
) then
4543 if Digs
= AAMPS_Digits
then
4544 Val
:= Real_Convert
(AAMPS_Val
);
4545 else pragma Assert
(Digs
= AAMPL_Digits
);
4546 Val
:= Real_Convert
(AAMPL_Val
);
4550 if Digs
= IEEES_Digits
then
4551 Val
:= Real_Convert
(IEEES_Val
);
4552 elsif Digs
= IEEEL_Digits
then
4553 Val
:= Real_Convert
(IEEEL_Val
);
4554 else pragma Assert
(Digs
= IEEEX_Digits
);
4555 Val
:= Real_Convert
(IEEEX_Val
);
4559 Set_Sloc
(Val
, Loc
);
4561 Set_Is_Static_Expression
(N
, Static
);
4562 Analyze_And_Resolve
(N
, C_Type
);
4563 end Float_Attribute_Universal_Real
;
4569 -- Note that the Fore calculation is based on the actual values
4570 -- of the bounds, and does not take into account possible rounding.
4572 function Fore_Value
return Nat
is
4573 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4574 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4575 Small
: constant Ureal
:= Small_Value
(P_Type
);
4576 Lo_Real
: constant Ureal
:= Lo
* Small
;
4577 Hi_Real
: constant Ureal
:= Hi
* Small
;
4582 -- Bounds are given in terms of small units, so first compute
4583 -- proper values as reals.
4585 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4588 -- Loop to compute proper value if more than one digit required
4590 while T
>= Ureal_10
loop
4602 -- Table of mantissa values accessed by function Computed using
4605 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4607 -- where D is T'Digits (RM83 3.5.7)
4609 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4651 function Mantissa
return Uint
is
4654 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4661 procedure Set_Bounds
is
4667 -- For a string literal subtype, we have to construct the bounds.
4668 -- Valid Ada code never applies attributes to string literals, but
4669 -- it is convenient to allow the expander to generate attribute
4670 -- references of this type (e.g. First and Last applied to a string
4673 -- Note that the whole point of the E_String_Literal_Subtype is to
4674 -- avoid this construction of bounds, but the cases in which we
4675 -- have to materialize them are rare enough that we don't worry!
4677 -- The low bound is simply the low bound of the base type. The
4678 -- high bound is computed from the length of the string and this
4681 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4682 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4683 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4686 Make_Integer_Literal
(Sloc
(P
),
4688 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4690 Set_Parent
(Hi_Bound
, P
);
4691 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4694 -- For non-array case, just get bounds of scalar type
4696 elsif Is_Scalar_Type
(P_Type
) then
4699 -- For a fixed-point type, we must freeze to get the attributes
4700 -- of the fixed-point type set now so we can reference them.
4702 if Is_Fixed_Point_Type
(P_Type
)
4703 and then not Is_Frozen
(Base_Type
(P_Type
))
4704 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4705 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4707 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4710 -- For array case, get type of proper index
4716 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4719 Indx
:= First_Index
(P_Type
);
4720 for J
in 1 .. Ndim
- 1 loop
4724 -- If no index type, get out (some other error occurred, and
4725 -- we don't have enough information to complete the job!)
4733 Ityp
:= Etype
(Indx
);
4736 -- A discrete range in an index constraint is allowed to be a
4737 -- subtype indication. This is syntactically a pain, but should
4738 -- not propagate to the entity for the corresponding index subtype.
4739 -- After checking that the subtype indication is legal, the range
4740 -- of the subtype indication should be transfered to the entity.
4741 -- The attributes for the bounds should remain the simple retrievals
4742 -- that they are now.
4744 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4745 Hi_Bound
:= Type_High_Bound
(Ityp
);
4747 if not Is_Static_Subtype
(Ityp
) then
4752 -------------------------------
4753 -- Statically_Denotes_Entity --
4754 -------------------------------
4756 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
4760 if not Is_Entity_Name
(N
) then
4767 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
4768 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
4769 end Statically_Denotes_Entity
;
4771 -- Start of processing for Eval_Attribute
4774 -- Acquire first two expressions (at the moment, no attributes
4775 -- take more than two expressions in any case).
4777 if Present
(Expressions
(N
)) then
4778 E1
:= First
(Expressions
(N
));
4785 -- Special processing for cases where the prefix is an object. For
4786 -- this purpose, a string literal counts as an object (attributes
4787 -- of string literals can only appear in generated code).
4789 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
4791 -- For Component_Size, the prefix is an array object, and we apply
4792 -- the attribute to the type of the object. This is allowed for
4793 -- both unconstrained and constrained arrays, since the bounds
4794 -- have no influence on the value of this attribute.
4796 if Id
= Attribute_Component_Size
then
4797 P_Entity
:= Etype
(P
);
4799 -- For First and Last, the prefix is an array object, and we apply
4800 -- the attribute to the type of the array, but we need a constrained
4801 -- type for this, so we use the actual subtype if available.
4803 elsif Id
= Attribute_First
4807 Id
= Attribute_Length
4810 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4813 if Present
(AS
) and then Is_Constrained
(AS
) then
4816 -- If we have an unconstrained type, cannot fold
4824 -- For Size, give size of object if available, otherwise we
4825 -- cannot fold Size.
4827 elsif Id
= Attribute_Size
then
4828 if Is_Entity_Name
(P
)
4829 and then Known_Esize
(Entity
(P
))
4831 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4839 -- For Alignment, give size of object if available, otherwise we
4840 -- cannot fold Alignment.
4842 elsif Id
= Attribute_Alignment
then
4843 if Is_Entity_Name
(P
)
4844 and then Known_Alignment
(Entity
(P
))
4846 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
4854 -- No other attributes for objects are folded
4861 -- Cases where P is not an object. Cannot do anything if P is
4862 -- not the name of an entity.
4864 elsif not Is_Entity_Name
(P
) then
4868 -- Otherwise get prefix entity
4871 P_Entity
:= Entity
(P
);
4874 -- At this stage P_Entity is the entity to which the attribute
4875 -- is to be applied. This is usually simply the entity of the
4876 -- prefix, except in some cases of attributes for objects, where
4877 -- as described above, we apply the attribute to the object type.
4879 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4880 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4881 -- Note we allow non-static non-generic types at this stage as further
4884 if Is_Type
(P_Entity
)
4885 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4886 and then (not Is_Generic_Type
(P_Entity
))
4890 -- Second foldable possibility is an array object (RM 4.9(8))
4892 elsif (Ekind
(P_Entity
) = E_Variable
4894 Ekind
(P_Entity
) = E_Constant
)
4895 and then Is_Array_Type
(Etype
(P_Entity
))
4896 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4898 P_Type
:= Etype
(P_Entity
);
4900 -- If the entity is an array constant with an unconstrained nominal
4901 -- subtype then get the type from the initial value. If the value has
4902 -- been expanded into assignments, there is no expression and the
4903 -- attribute reference remains dynamic.
4904 -- We could do better here and retrieve the type ???
4906 if Ekind
(P_Entity
) = E_Constant
4907 and then not Is_Constrained
(P_Type
)
4909 if No
(Constant_Value
(P_Entity
)) then
4912 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4916 -- Definite must be folded if the prefix is not a generic type,
4917 -- that is to say if we are within an instantiation. Same processing
4918 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4919 -- and Unconstrained_Array.
4921 elsif (Id
= Attribute_Definite
4923 Id
= Attribute_Has_Access_Values
4925 Id
= Attribute_Has_Discriminants
4927 Id
= Attribute_Type_Class
4929 Id
= Attribute_Unconstrained_Array
)
4930 and then not Is_Generic_Type
(P_Entity
)
4934 -- We can fold 'Size applied to a type if the size is known
4935 -- (as happens for a size from an attribute definition clause).
4936 -- At this stage, this can happen only for types (e.g. record
4937 -- types) for which the size is always non-static. We exclude
4938 -- generic types from consideration (since they have bogus
4939 -- sizes set within templates).
4941 elsif Id
= Attribute_Size
4942 and then Is_Type
(P_Entity
)
4943 and then (not Is_Generic_Type
(P_Entity
))
4944 and then Known_Static_RM_Size
(P_Entity
)
4946 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4949 -- We can fold 'Alignment applied to a type if the alignment is known
4950 -- (as happens for an alignment from an attribute definition clause).
4951 -- At this stage, this can happen only for types (e.g. record
4952 -- types) for which the size is always non-static. We exclude
4953 -- generic types from consideration (since they have bogus
4954 -- sizes set within templates).
4956 elsif Id
= Attribute_Alignment
4957 and then Is_Type
(P_Entity
)
4958 and then (not Is_Generic_Type
(P_Entity
))
4959 and then Known_Alignment
(P_Entity
)
4961 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
4964 -- If this is an access attribute that is known to fail accessibility
4965 -- check, rewrite accordingly.
4967 elsif Attribute_Name
(N
) = Name_Access
4968 and then Raises_Constraint_Error
(N
)
4971 Make_Raise_Program_Error
(Loc
,
4972 Reason
=> PE_Accessibility_Check_Failed
));
4973 Set_Etype
(N
, C_Type
);
4976 -- No other cases are foldable (they certainly aren't static, and at
4977 -- the moment we don't try to fold any cases other than these three).
4984 -- If either attribute or the prefix is Any_Type, then propagate
4985 -- Any_Type to the result and don't do anything else at all.
4987 if P_Type
= Any_Type
4988 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4989 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4991 Set_Etype
(N
, Any_Type
);
4995 -- Scalar subtype case. We have not yet enforced the static requirement
4996 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4997 -- of non-static attribute references (e.g. S'Digits for a non-static
4998 -- floating-point type, which we can compute at compile time).
5000 -- Note: this folding of non-static attributes is not simply a case of
5001 -- optimization. For many of the attributes affected, Gigi cannot handle
5002 -- the attribute and depends on the front end having folded them away.
5004 -- Note: although we don't require staticness at this stage, we do set
5005 -- the Static variable to record the staticness, for easy reference by
5006 -- those attributes where it matters (e.g. Succ and Pred), and also to
5007 -- be used to ensure that non-static folded things are not marked as
5008 -- being static (a check that is done right at the end).
5010 P_Root_Type
:= Root_Type
(P_Type
);
5011 P_Base_Type
:= Base_Type
(P_Type
);
5013 -- If the root type or base type is generic, then we cannot fold. This
5014 -- test is needed because subtypes of generic types are not always
5015 -- marked as being generic themselves (which seems odd???)
5017 if Is_Generic_Type
(P_Root_Type
)
5018 or else Is_Generic_Type
(P_Base_Type
)
5023 if Is_Scalar_Type
(P_Type
) then
5024 Static
:= Is_OK_Static_Subtype
(P_Type
);
5026 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
5027 -- since we can't do anything with unconstrained arrays. In addition,
5028 -- only the First, Last and Length attributes are possibly static.
5030 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
5031 -- Unconstrained_Array are again exceptions, because they apply as
5032 -- well to unconstrained types.
5034 -- In addition Component_Size is an exception since it is possibly
5035 -- foldable, even though it is never static, and it does apply to
5036 -- unconstrained arrays. Furthermore, it is essential to fold this
5037 -- in the packed case, since otherwise the value will be incorrect.
5039 elsif Id
= Attribute_Definite
5041 Id
= Attribute_Has_Access_Values
5043 Id
= Attribute_Has_Discriminants
5045 Id
= Attribute_Type_Class
5047 Id
= Attribute_Unconstrained_Array
5049 Id
= Attribute_Component_Size
5054 if not Is_Constrained
(P_Type
)
5055 or else (Id
/= Attribute_First
and then
5056 Id
/= Attribute_Last
and then
5057 Id
/= Attribute_Length
)
5063 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
5064 -- scalar case, we hold off on enforcing staticness, since there are
5065 -- cases which we can fold at compile time even though they are not
5066 -- static (e.g. 'Length applied to a static index, even though other
5067 -- non-static indexes make the array type non-static). This is only
5068 -- an optimization, but it falls out essentially free, so why not.
5069 -- Again we compute the variable Static for easy reference later
5070 -- (note that no array attributes are static in Ada 83).
5072 Static
:= Ada_Version
>= Ada_95
5073 and then Statically_Denotes_Entity
(P
);
5079 N
:= First_Index
(P_Type
);
5080 while Present
(N
) loop
5081 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
5083 -- If however the index type is generic, attributes cannot
5086 if Is_Generic_Type
(Etype
(N
))
5087 and then Id
/= Attribute_Component_Size
5097 -- Check any expressions that are present. Note that these expressions,
5098 -- depending on the particular attribute type, are either part of the
5099 -- attribute designator, or they are arguments in a case where the
5100 -- attribute reference returns a function. In the latter case, the
5101 -- rule in (RM 4.9(22)) applies and in particular requires the type
5102 -- of the expressions to be scalar in order for the attribute to be
5103 -- considered to be static.
5110 while Present
(E
) loop
5112 -- If expression is not static, then the attribute reference
5113 -- result certainly cannot be static.
5115 if not Is_Static_Expression
(E
) then
5119 -- If the result is not known at compile time, or is not of
5120 -- a scalar type, then the result is definitely not static,
5121 -- so we can quit now.
5123 if not Compile_Time_Known_Value
(E
)
5124 or else not Is_Scalar_Type
(Etype
(E
))
5126 -- An odd special case, if this is a Pos attribute, this
5127 -- is where we need to apply a range check since it does
5128 -- not get done anywhere else.
5130 if Id
= Attribute_Pos
then
5131 if Is_Integer_Type
(Etype
(E
)) then
5132 Apply_Range_Check
(E
, Etype
(N
));
5139 -- If the expression raises a constraint error, then so does
5140 -- the attribute reference. We keep going in this case because
5141 -- we are still interested in whether the attribute reference
5142 -- is static even if it is not static.
5144 elsif Raises_Constraint_Error
(E
) then
5145 Set_Raises_Constraint_Error
(N
);
5151 if Raises_Constraint_Error
(Prefix
(N
)) then
5156 -- Deal with the case of a static attribute reference that raises
5157 -- constraint error. The Raises_Constraint_Error flag will already
5158 -- have been set, and the Static flag shows whether the attribute
5159 -- reference is static. In any case we certainly can't fold such an
5160 -- attribute reference.
5162 -- Note that the rewriting of the attribute node with the constraint
5163 -- error node is essential in this case, because otherwise Gigi might
5164 -- blow up on one of the attributes it never expects to see.
5166 -- The constraint_error node must have the type imposed by the context,
5167 -- to avoid spurious errors in the enclosing expression.
5169 if Raises_Constraint_Error
(N
) then
5171 Make_Raise_Constraint_Error
(Sloc
(N
),
5172 Reason
=> CE_Range_Check_Failed
);
5173 Set_Etype
(CE_Node
, Etype
(N
));
5174 Set_Raises_Constraint_Error
(CE_Node
);
5176 Rewrite
(N
, Relocate_Node
(CE_Node
));
5177 Set_Is_Static_Expression
(N
, Static
);
5181 -- At this point we have a potentially foldable attribute reference.
5182 -- If Static is set, then the attribute reference definitely obeys
5183 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5184 -- folded. If Static is not set, then the attribute may or may not
5185 -- be foldable, and the individual attribute processing routines
5186 -- test Static as required in cases where it makes a difference.
5188 -- In the case where Static is not set, we do know that all the
5189 -- expressions present are at least known at compile time (we
5190 -- assumed above that if this was not the case, then there was
5191 -- no hope of static evaluation). However, we did not require
5192 -- that the bounds of the prefix type be compile time known,
5193 -- let alone static). That's because there are many attributes
5194 -- that can be computed at compile time on non-static subtypes,
5195 -- even though such references are not static expressions.
5203 when Attribute_Adjacent
=>
5206 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5212 when Attribute_Aft
=>
5213 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5219 when Attribute_Alignment
=> Alignment_Block
: declare
5220 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5223 -- Fold if alignment is set and not otherwise
5225 if Known_Alignment
(P_TypeA
) then
5226 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5228 end Alignment_Block
;
5234 -- Can only be folded in No_Ast_Handler case
5236 when Attribute_AST_Entry
=>
5237 if not Is_AST_Entry
(P_Entity
) then
5239 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5248 -- Bit can never be folded
5250 when Attribute_Bit
=>
5257 -- Body_version can never be static
5259 when Attribute_Body_Version
=>
5266 when Attribute_Ceiling
=>
5268 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5270 --------------------
5271 -- Component_Size --
5272 --------------------
5274 when Attribute_Component_Size
=>
5275 if Known_Static_Component_Size
(P_Type
) then
5276 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5283 when Attribute_Compose
=>
5286 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5293 -- Constrained is never folded for now, there may be cases that
5294 -- could be handled at compile time. to be looked at later.
5296 when Attribute_Constrained
=>
5303 when Attribute_Copy_Sign
=>
5306 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5312 when Attribute_Delta
=>
5313 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5319 when Attribute_Definite
=>
5320 Rewrite
(N
, New_Occurrence_Of
(
5321 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5322 Analyze_And_Resolve
(N
, Standard_Boolean
);
5328 when Attribute_Denorm
=>
5330 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5336 when Attribute_Digits
=>
5337 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5343 when Attribute_Emax
=>
5345 -- Ada 83 attribute is defined as (RM83 3.5.8)
5347 -- T'Emax = 4 * T'Mantissa
5349 Fold_Uint
(N
, 4 * Mantissa
, True);
5355 when Attribute_Enum_Rep
=>
5357 -- For an enumeration type with a non-standard representation use
5358 -- the Enumeration_Rep field of the proper constant. Note that this
5359 -- will not work for types Character/Wide_[Wide-]Character, since no
5360 -- real entities are created for the enumeration literals, but that
5361 -- does not matter since these two types do not have non-standard
5362 -- representations anyway.
5364 if Is_Enumeration_Type
(P_Type
)
5365 and then Has_Non_Standard_Rep
(P_Type
)
5367 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5369 -- For enumeration types with standard representations and all
5370 -- other cases (i.e. all integer and modular types), Enum_Rep
5371 -- is equivalent to Pos.
5374 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5381 when Attribute_Epsilon
=>
5383 -- Ada 83 attribute is defined as (RM83 3.5.8)
5385 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5387 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5393 when Attribute_Exponent
=>
5395 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5401 when Attribute_First
=> First_Attr
:
5405 if Compile_Time_Known_Value
(Lo_Bound
) then
5406 if Is_Real_Type
(P_Type
) then
5407 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5409 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5418 when Attribute_Fixed_Value
=>
5425 when Attribute_Floor
=>
5427 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5433 when Attribute_Fore
=>
5434 if Compile_Time_Known_Bounds
(P_Type
) then
5435 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5442 when Attribute_Fraction
=>
5444 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5446 -----------------------
5447 -- Has_Access_Values --
5448 -----------------------
5450 when Attribute_Has_Access_Values
=>
5451 Rewrite
(N
, New_Occurrence_Of
5452 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5453 Analyze_And_Resolve
(N
, Standard_Boolean
);
5455 -----------------------
5456 -- Has_Discriminants --
5457 -----------------------
5459 when Attribute_Has_Discriminants
=>
5460 Rewrite
(N
, New_Occurrence_Of
(
5461 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5462 Analyze_And_Resolve
(N
, Standard_Boolean
);
5468 when Attribute_Identity
=>
5475 -- Image is a scalar attribute, but is never static, because it is
5476 -- not a static function (having a non-scalar argument (RM 4.9(22))
5478 when Attribute_Image
=>
5485 -- Img is a scalar attribute, but is never static, because it is
5486 -- not a static function (having a non-scalar argument (RM 4.9(22))
5488 when Attribute_Img
=>
5495 when Attribute_Integer_Value
=>
5502 when Attribute_Large
=>
5504 -- For fixed-point, we use the identity:
5506 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5508 if Is_Fixed_Point_Type
(P_Type
) then
5510 Make_Op_Multiply
(Loc
,
5512 Make_Op_Subtract
(Loc
,
5516 Make_Real_Literal
(Loc
, Ureal_2
),
5518 Make_Attribute_Reference
(Loc
,
5520 Attribute_Name
=> Name_Mantissa
)),
5521 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5524 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5526 Analyze_And_Resolve
(N
, C_Type
);
5528 -- Floating-point (Ada 83 compatibility)
5531 -- Ada 83 attribute is defined as (RM83 3.5.8)
5533 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5537 -- T'Emax = 4 * T'Mantissa
5540 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5548 when Attribute_Last
=> Last
:
5552 if Compile_Time_Known_Value
(Hi_Bound
) then
5553 if Is_Real_Type
(P_Type
) then
5554 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5556 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5565 when Attribute_Leading_Part
=>
5567 Eval_Fat
.Leading_Part
5568 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5574 when Attribute_Length
=> Length
: declare
5578 -- In the case of a generic index type, the bounds may
5579 -- appear static but the computation is not meaningful,
5580 -- and may generate a spurious warning.
5582 Ind
:= First_Index
(P_Type
);
5584 while Present
(Ind
) loop
5585 if Is_Generic_Type
(Etype
(Ind
)) then
5594 if Compile_Time_Known_Value
(Lo_Bound
)
5595 and then Compile_Time_Known_Value
(Hi_Bound
)
5598 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
5607 when Attribute_Machine
=>
5610 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
5617 when Attribute_Machine_Emax
=>
5618 Float_Attribute_Universal_Integer
(
5626 AAMPL_Machine_Emax
);
5632 when Attribute_Machine_Emin
=>
5633 Float_Attribute_Universal_Integer
(
5641 AAMPL_Machine_Emin
);
5643 ----------------------
5644 -- Machine_Mantissa --
5645 ----------------------
5647 when Attribute_Machine_Mantissa
=>
5648 Float_Attribute_Universal_Integer
(
5649 IEEES_Machine_Mantissa
,
5650 IEEEL_Machine_Mantissa
,
5651 IEEEX_Machine_Mantissa
,
5652 VAXFF_Machine_Mantissa
,
5653 VAXDF_Machine_Mantissa
,
5654 VAXGF_Machine_Mantissa
,
5655 AAMPS_Machine_Mantissa
,
5656 AAMPL_Machine_Mantissa
);
5658 -----------------------
5659 -- Machine_Overflows --
5660 -----------------------
5662 when Attribute_Machine_Overflows
=>
5664 -- Always true for fixed-point
5666 if Is_Fixed_Point_Type
(P_Type
) then
5667 Fold_Uint
(N
, True_Value
, True);
5669 -- Floating point case
5673 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
5681 when Attribute_Machine_Radix
=>
5682 if Is_Fixed_Point_Type
(P_Type
) then
5683 if Is_Decimal_Fixed_Point_Type
(P_Type
)
5684 and then Machine_Radix_10
(P_Type
)
5686 Fold_Uint
(N
, Uint_10
, True);
5688 Fold_Uint
(N
, Uint_2
, True);
5691 -- All floating-point type always have radix 2
5694 Fold_Uint
(N
, Uint_2
, True);
5697 ----------------------
5698 -- Machine_Rounding --
5699 ----------------------
5701 -- Note: for the folding case, it is fine to treat Machine_Rounding
5702 -- exactly the same way as Rounding, since this is one of the allowed
5703 -- behaviors, and performance is not an issue here. It might be a bit
5704 -- better to give the same result as it would give at run-time, even
5705 -- though the non-determinism is certainly permitted.
5707 when Attribute_Machine_Rounding
=>
5709 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5711 --------------------
5712 -- Machine_Rounds --
5713 --------------------
5715 when Attribute_Machine_Rounds
=>
5717 -- Always False for fixed-point
5719 if Is_Fixed_Point_Type
(P_Type
) then
5720 Fold_Uint
(N
, False_Value
, True);
5722 -- Else yield proper floating-point result
5726 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
5733 -- Note: Machine_Size is identical to Object_Size
5735 when Attribute_Machine_Size
=> Machine_Size
: declare
5736 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5739 if Known_Esize
(P_TypeA
) then
5740 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5748 when Attribute_Mantissa
=>
5750 -- Fixed-point mantissa
5752 if Is_Fixed_Point_Type
(P_Type
) then
5754 -- Compile time foldable case
5756 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5758 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5760 -- The calculation of the obsolete Ada 83 attribute Mantissa
5761 -- is annoying, because of AI00143, quoted here:
5763 -- !question 84-01-10
5765 -- Consider the model numbers for F:
5767 -- type F is delta 1.0 range -7.0 .. 8.0;
5769 -- The wording requires that F'MANTISSA be the SMALLEST
5770 -- integer number for which each bound of the specified
5771 -- range is either a model number or lies at most small
5772 -- distant from a model number. This means F'MANTISSA
5773 -- is required to be 3 since the range -7.0 .. 7.0 fits
5774 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5775 -- number, namely, 7. Is this analysis correct? Note that
5776 -- this implies the upper bound of the range is not
5777 -- represented as a model number.
5779 -- !response 84-03-17
5781 -- The analysis is correct. The upper and lower bounds for
5782 -- a fixed point type can lie outside the range of model
5793 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5794 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5795 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5796 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5798 -- If the Bound is exactly a model number, i.e. a multiple
5799 -- of Small, then we back it off by one to get the integer
5800 -- value that must be representable.
5802 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5803 Max_Man
:= Max_Man
- 1;
5806 -- Now find corresponding size = Mantissa value
5809 while 2 ** Siz
< Max_Man
loop
5813 Fold_Uint
(N
, Siz
, True);
5817 -- The case of dynamic bounds cannot be evaluated at compile
5818 -- time. Instead we use a runtime routine (see Exp_Attr).
5823 -- Floating-point Mantissa
5826 Fold_Uint
(N
, Mantissa
, True);
5833 when Attribute_Max
=> Max
:
5835 if Is_Real_Type
(P_Type
) then
5837 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5839 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5843 ----------------------------------
5844 -- Max_Size_In_Storage_Elements --
5845 ----------------------------------
5847 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5848 -- Storage_Unit boundary. We can fold any cases for which the size
5849 -- is known by the front end.
5851 when Attribute_Max_Size_In_Storage_Elements
=>
5852 if Known_Esize
(P_Type
) then
5854 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5855 System_Storage_Unit
,
5859 --------------------
5860 -- Mechanism_Code --
5861 --------------------
5863 when Attribute_Mechanism_Code
=>
5867 Mech
: Mechanism_Type
;
5871 Mech
:= Mechanism
(P_Entity
);
5874 Val
:= UI_To_Int
(Expr_Value
(E1
));
5876 Formal
:= First_Formal
(P_Entity
);
5877 for J
in 1 .. Val
- 1 loop
5878 Next_Formal
(Formal
);
5880 Mech
:= Mechanism
(Formal
);
5884 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
5892 when Attribute_Min
=> Min
:
5894 if Is_Real_Type
(P_Type
) then
5896 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5899 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5907 when Attribute_Mod
=>
5909 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
5915 when Attribute_Model
=>
5917 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5923 when Attribute_Model_Emin
=>
5924 Float_Attribute_Universal_Integer
(
5938 when Attribute_Model_Epsilon
=>
5939 Float_Attribute_Universal_Real
(
5940 IEEES_Model_Epsilon
'Universal_Literal_String,
5941 IEEEL_Model_Epsilon
'Universal_Literal_String,
5942 IEEEX_Model_Epsilon
'Universal_Literal_String,
5943 VAXFF_Model_Epsilon
'Universal_Literal_String,
5944 VAXDF_Model_Epsilon
'Universal_Literal_String,
5945 VAXGF_Model_Epsilon
'Universal_Literal_String,
5946 AAMPS_Model_Epsilon
'Universal_Literal_String,
5947 AAMPL_Model_Epsilon
'Universal_Literal_String);
5949 --------------------
5950 -- Model_Mantissa --
5951 --------------------
5953 when Attribute_Model_Mantissa
=>
5954 Float_Attribute_Universal_Integer
(
5955 IEEES_Model_Mantissa
,
5956 IEEEL_Model_Mantissa
,
5957 IEEEX_Model_Mantissa
,
5958 VAXFF_Model_Mantissa
,
5959 VAXDF_Model_Mantissa
,
5960 VAXGF_Model_Mantissa
,
5961 AAMPS_Model_Mantissa
,
5962 AAMPL_Model_Mantissa
);
5968 when Attribute_Model_Small
=>
5969 Float_Attribute_Universal_Real
(
5970 IEEES_Model_Small
'Universal_Literal_String,
5971 IEEEL_Model_Small
'Universal_Literal_String,
5972 IEEEX_Model_Small
'Universal_Literal_String,
5973 VAXFF_Model_Small
'Universal_Literal_String,
5974 VAXDF_Model_Small
'Universal_Literal_String,
5975 VAXGF_Model_Small
'Universal_Literal_String,
5976 AAMPS_Model_Small
'Universal_Literal_String,
5977 AAMPL_Model_Small
'Universal_Literal_String);
5983 when Attribute_Modulus
=>
5984 Fold_Uint
(N
, Modulus
(P_Type
), True);
5986 --------------------
5987 -- Null_Parameter --
5988 --------------------
5990 -- Cannot fold, we know the value sort of, but the whole point is
5991 -- that there is no way to talk about this imaginary value except
5992 -- by using the attribute, so we leave it the way it is.
5994 when Attribute_Null_Parameter
=>
6001 -- The Object_Size attribute for a type returns the Esize of the
6002 -- type and can be folded if this value is known.
6004 when Attribute_Object_Size
=> Object_Size
: declare
6005 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6008 if Known_Esize
(P_TypeA
) then
6009 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6013 -------------------------
6014 -- Passed_By_Reference --
6015 -------------------------
6017 -- Scalar types are never passed by reference
6019 when Attribute_Passed_By_Reference
=>
6020 Fold_Uint
(N
, False_Value
, True);
6026 when Attribute_Pos
=>
6027 Fold_Uint
(N
, Expr_Value
(E1
), True);
6033 when Attribute_Pred
=> Pred
:
6035 -- Floating-point case
6037 if Is_Floating_Point_Type
(P_Type
) then
6039 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6043 elsif Is_Fixed_Point_Type
(P_Type
) then
6045 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
6047 -- Modular integer case (wraps)
6049 elsif Is_Modular_Integer_Type
(P_Type
) then
6050 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
6052 -- Other scalar cases
6055 pragma Assert
(Is_Scalar_Type
(P_Type
));
6057 if Is_Enumeration_Type
(P_Type
)
6058 and then Expr_Value
(E1
) =
6059 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6061 Apply_Compile_Time_Constraint_Error
6062 (N
, "Pred of `&''First`",
6063 CE_Overflow_Check_Failed
,
6065 Warn
=> not Static
);
6071 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
6079 -- No processing required, because by this stage, Range has been
6080 -- replaced by First .. Last, so this branch can never be taken.
6082 when Attribute_Range
=>
6083 raise Program_Error
;
6089 when Attribute_Range_Length
=>
6092 if Compile_Time_Known_Value
(Hi_Bound
)
6093 and then Compile_Time_Known_Value
(Lo_Bound
)
6097 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
6105 when Attribute_Remainder
=> Remainder
: declare
6106 X
: constant Ureal
:= Expr_Value_R
(E1
);
6107 Y
: constant Ureal
:= Expr_Value_R
(E2
);
6110 if UR_Is_Zero
(Y
) then
6111 Apply_Compile_Time_Constraint_Error
6112 (N
, "division by zero in Remainder",
6113 CE_Overflow_Check_Failed
,
6114 Warn
=> not Static
);
6120 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
6127 when Attribute_Round
=> Round
:
6133 -- First we get the (exact result) in units of small
6135 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
6137 -- Now round that exactly to an integer
6139 Si
:= UR_To_Uint
(Sr
);
6141 -- Finally the result is obtained by converting back to real
6143 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
6150 when Attribute_Rounding
=>
6152 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6158 when Attribute_Safe_Emax
=>
6159 Float_Attribute_Universal_Integer
(
6173 when Attribute_Safe_First
=>
6174 Float_Attribute_Universal_Real
(
6175 IEEES_Safe_First
'Universal_Literal_String,
6176 IEEEL_Safe_First
'Universal_Literal_String,
6177 IEEEX_Safe_First
'Universal_Literal_String,
6178 VAXFF_Safe_First
'Universal_Literal_String,
6179 VAXDF_Safe_First
'Universal_Literal_String,
6180 VAXGF_Safe_First
'Universal_Literal_String,
6181 AAMPS_Safe_First
'Universal_Literal_String,
6182 AAMPL_Safe_First
'Universal_Literal_String);
6188 when Attribute_Safe_Large
=>
6189 if Is_Fixed_Point_Type
(P_Type
) then
6191 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
6193 Float_Attribute_Universal_Real
(
6194 IEEES_Safe_Large
'Universal_Literal_String,
6195 IEEEL_Safe_Large
'Universal_Literal_String,
6196 IEEEX_Safe_Large
'Universal_Literal_String,
6197 VAXFF_Safe_Large
'Universal_Literal_String,
6198 VAXDF_Safe_Large
'Universal_Literal_String,
6199 VAXGF_Safe_Large
'Universal_Literal_String,
6200 AAMPS_Safe_Large
'Universal_Literal_String,
6201 AAMPL_Safe_Large
'Universal_Literal_String);
6208 when Attribute_Safe_Last
=>
6209 Float_Attribute_Universal_Real
(
6210 IEEES_Safe_Last
'Universal_Literal_String,
6211 IEEEL_Safe_Last
'Universal_Literal_String,
6212 IEEEX_Safe_Last
'Universal_Literal_String,
6213 VAXFF_Safe_Last
'Universal_Literal_String,
6214 VAXDF_Safe_Last
'Universal_Literal_String,
6215 VAXGF_Safe_Last
'Universal_Literal_String,
6216 AAMPS_Safe_Last
'Universal_Literal_String,
6217 AAMPL_Safe_Last
'Universal_Literal_String);
6223 when Attribute_Safe_Small
=>
6225 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6226 -- for fixed-point, since is the same as Small, but we implement
6227 -- it for backwards compatibility.
6229 if Is_Fixed_Point_Type
(P_Type
) then
6230 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6232 -- Ada 83 Safe_Small for floating-point cases
6235 Float_Attribute_Universal_Real
(
6236 IEEES_Safe_Small
'Universal_Literal_String,
6237 IEEEL_Safe_Small
'Universal_Literal_String,
6238 IEEEX_Safe_Small
'Universal_Literal_String,
6239 VAXFF_Safe_Small
'Universal_Literal_String,
6240 VAXDF_Safe_Small
'Universal_Literal_String,
6241 VAXGF_Safe_Small
'Universal_Literal_String,
6242 AAMPS_Safe_Small
'Universal_Literal_String,
6243 AAMPL_Safe_Small
'Universal_Literal_String);
6250 when Attribute_Scale
=>
6251 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6257 when Attribute_Scaling
=>
6260 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6266 when Attribute_Signed_Zeros
=>
6268 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6274 -- Size attribute returns the RM size. All scalar types can be folded,
6275 -- as well as any types for which the size is known by the front end,
6276 -- including any type for which a size attribute is specified.
6278 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6279 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6282 if RM_Size
(P_TypeA
) /= Uint_0
then
6286 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6288 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6291 -- If a size clause applies, then use the size from it.
6292 -- This is one of the rare cases where we can use the
6293 -- Size_Clause field for a subtype when Has_Size_Clause
6294 -- is False. Consider:
6296 -- type x is range 1 .. 64;
6297 -- for x'size use 12;
6298 -- subtype y is x range 0 .. 3;
6300 -- Here y has a size clause inherited from x, but normally
6301 -- it does not apply, and y'size is 2. However, y'VADS_Size
6302 -- is indeed 12 and not 2.
6305 and then Is_OK_Static_Expression
(Expression
(S
))
6307 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6309 -- If no size is specified, then we simply use the object
6310 -- size in the VADS_Size case (e.g. Natural'Size is equal
6311 -- to Integer'Size, not one less).
6314 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6318 -- Normal case (Size) in which case we want the RM_Size
6323 Static
and then Is_Discrete_Type
(P_TypeA
));
6332 when Attribute_Small
=>
6334 -- The floating-point case is present only for Ada 83 compatability.
6335 -- Note that strictly this is an illegal addition, since we are
6336 -- extending an Ada 95 defined attribute, but we anticipate an
6337 -- ARG ruling that will permit this.
6339 if Is_Floating_Point_Type
(P_Type
) then
6341 -- Ada 83 attribute is defined as (RM83 3.5.8)
6343 -- T'Small = 2.0**(-T'Emax - 1)
6347 -- T'Emax = 4 * T'Mantissa
6349 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6351 -- Normal Ada 95 fixed-point case
6354 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6361 when Attribute_Stream_Size
=>
6368 when Attribute_Succ
=> Succ
:
6370 -- Floating-point case
6372 if Is_Floating_Point_Type
(P_Type
) then
6374 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6378 elsif Is_Fixed_Point_Type
(P_Type
) then
6380 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6382 -- Modular integer case (wraps)
6384 elsif Is_Modular_Integer_Type
(P_Type
) then
6385 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6387 -- Other scalar cases
6390 pragma Assert
(Is_Scalar_Type
(P_Type
));
6392 if Is_Enumeration_Type
(P_Type
)
6393 and then Expr_Value
(E1
) =
6394 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6396 Apply_Compile_Time_Constraint_Error
6397 (N
, "Succ of `&''Last`",
6398 CE_Overflow_Check_Failed
,
6400 Warn
=> not Static
);
6405 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6414 when Attribute_Truncation
=>
6416 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6422 when Attribute_Type_Class
=> Type_Class
: declare
6423 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6427 if Is_Descendent_Of_Address
(Typ
) then
6428 Id
:= RE_Type_Class_Address
;
6430 elsif Is_Enumeration_Type
(Typ
) then
6431 Id
:= RE_Type_Class_Enumeration
;
6433 elsif Is_Integer_Type
(Typ
) then
6434 Id
:= RE_Type_Class_Integer
;
6436 elsif Is_Fixed_Point_Type
(Typ
) then
6437 Id
:= RE_Type_Class_Fixed_Point
;
6439 elsif Is_Floating_Point_Type
(Typ
) then
6440 Id
:= RE_Type_Class_Floating_Point
;
6442 elsif Is_Array_Type
(Typ
) then
6443 Id
:= RE_Type_Class_Array
;
6445 elsif Is_Record_Type
(Typ
) then
6446 Id
:= RE_Type_Class_Record
;
6448 elsif Is_Access_Type
(Typ
) then
6449 Id
:= RE_Type_Class_Access
;
6451 elsif Is_Enumeration_Type
(Typ
) then
6452 Id
:= RE_Type_Class_Enumeration
;
6454 elsif Is_Task_Type
(Typ
) then
6455 Id
:= RE_Type_Class_Task
;
6457 -- We treat protected types like task types. It would make more
6458 -- sense to have another enumeration value, but after all the
6459 -- whole point of this feature is to be exactly DEC compatible,
6460 -- and changing the type Type_Clas would not meet this requirement.
6462 elsif Is_Protected_Type
(Typ
) then
6463 Id
:= RE_Type_Class_Task
;
6465 -- Not clear if there are any other possibilities, but if there
6466 -- are, then we will treat them as the address case.
6469 Id
:= RE_Type_Class_Address
;
6472 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6475 -----------------------
6476 -- Unbiased_Rounding --
6477 -----------------------
6479 when Attribute_Unbiased_Rounding
=>
6481 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
6484 -------------------------
6485 -- Unconstrained_Array --
6486 -------------------------
6488 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
6489 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6492 Rewrite
(N
, New_Occurrence_Of
(
6494 Is_Array_Type
(P_Type
)
6495 and then not Is_Constrained
(Typ
)), Loc
));
6497 -- Analyze and resolve as boolean, note that this attribute is
6498 -- a static attribute in GNAT.
6500 Analyze_And_Resolve
(N
, Standard_Boolean
);
6502 end Unconstrained_Array
;
6508 -- Processing is shared with Size
6514 when Attribute_Val
=> Val
:
6516 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6518 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
6520 Apply_Compile_Time_Constraint_Error
6521 (N
, "Val expression out of range",
6522 CE_Range_Check_Failed
,
6523 Warn
=> not Static
);
6529 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6537 -- The Value_Size attribute for a type returns the RM size of the
6538 -- type. This an always be folded for scalar types, and can also
6539 -- be folded for non-scalar types if the size is set.
6541 when Attribute_Value_Size
=> Value_Size
: declare
6542 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6545 if RM_Size
(P_TypeA
) /= Uint_0
then
6546 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6555 -- Version can never be static
6557 when Attribute_Version
=>
6564 -- Wide_Image is a scalar attribute, but is never static, because it
6565 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6567 when Attribute_Wide_Image
=>
6570 ---------------------
6571 -- Wide_Wide_Image --
6572 ---------------------
6574 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6575 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6577 when Attribute_Wide_Wide_Image
=>
6580 ---------------------
6581 -- Wide_Wide_Width --
6582 ---------------------
6584 -- Processing for Wide_Wide_Width is combined with Width
6590 -- Processing for Wide_Width is combined with Width
6596 -- This processing also handles the case of Wide_[Wide_]Width
6598 when Attribute_Width |
6599 Attribute_Wide_Width |
6600 Attribute_Wide_Wide_Width
=> Width
:
6602 if Compile_Time_Known_Bounds
(P_Type
) then
6604 -- Floating-point types
6606 if Is_Floating_Point_Type
(P_Type
) then
6608 -- Width is zero for a null range (RM 3.5 (38))
6610 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
6611 Expr_Value_R
(Type_Low_Bound
(P_Type
))
6613 Fold_Uint
(N
, Uint_0
, True);
6616 -- For floating-point, we have +N.dddE+nnn where length
6617 -- of ddd is determined by type'Digits - 1, but is one
6618 -- if Digits is one (RM 3.5 (33)).
6620 -- nnn is set to 2 for Short_Float and Float (32 bit
6621 -- floats), and 3 for Long_Float and Long_Long_Float.
6622 -- For machines where Long_Long_Float is the IEEE
6623 -- extended precision type, the exponent takes 4 digits.
6627 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
6630 if Esize
(P_Type
) <= 32 then
6632 elsif Esize
(P_Type
) = 64 then
6638 Fold_Uint
(N
, UI_From_Int
(Len
), True);
6642 -- Fixed-point types
6644 elsif Is_Fixed_Point_Type
(P_Type
) then
6646 -- Width is zero for a null range (RM 3.5 (38))
6648 if Expr_Value
(Type_High_Bound
(P_Type
)) <
6649 Expr_Value
(Type_Low_Bound
(P_Type
))
6651 Fold_Uint
(N
, Uint_0
, True);
6653 -- The non-null case depends on the specific real type
6656 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6659 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
6666 R
: constant Entity_Id
:= Root_Type
(P_Type
);
6667 Lo
: constant Uint
:=
6668 Expr_Value
(Type_Low_Bound
(P_Type
));
6669 Hi
: constant Uint
:=
6670 Expr_Value
(Type_High_Bound
(P_Type
));
6683 -- Width for types derived from Standard.Character
6684 -- and Standard.Wide_[Wide_]Character.
6686 elsif R
= Standard_Character
6687 or else R
= Standard_Wide_Character
6688 or else R
= Standard_Wide_Wide_Character
6692 -- Set W larger if needed
6694 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
6696 -- All wide characters look like Hex_hhhhhhhh
6702 C
:= Character'Val (J
);
6704 -- Test for all cases where Character'Image
6705 -- yields an image that is longer than three
6706 -- characters. First the cases of Reserved_xxx
6707 -- names (length = 12).
6710 when Reserved_128 | Reserved_129 |
6711 Reserved_132 | Reserved_153
6715 when BS | HT | LF | VT | FF | CR |
6716 SO | SI | EM | FS | GS | RS |
6717 US | RI | MW | ST | PM
6721 when NUL | SOH | STX | ETX | EOT |
6722 ENQ | ACK | BEL | DLE | DC1 |
6723 DC2 | DC3 | DC4 | NAK | SYN |
6724 ETB | CAN | SUB | ESC | DEL |
6725 BPH | NBH | NEL | SSA | ESA |
6726 HTS | HTJ | VTS | PLD | PLU |
6727 SS2 | SS3 | DCS | PU1 | PU2 |
6728 STS | CCH | SPA | EPA | SOS |
6729 SCI | CSI | OSC | APC
6733 when Space
.. Tilde |
6734 No_Break_Space
.. LC_Y_Diaeresis
6739 W
:= Int
'Max (W
, Wt
);
6743 -- Width for types derived from Standard.Boolean
6745 elsif R
= Standard_Boolean
then
6752 -- Width for integer types
6754 elsif Is_Integer_Type
(P_Type
) then
6755 T
:= UI_Max
(abs Lo
, abs Hi
);
6763 -- Only remaining possibility is user declared enum type
6766 pragma Assert
(Is_Enumeration_Type
(P_Type
));
6769 L
:= First_Literal
(P_Type
);
6771 while Present
(L
) loop
6773 -- Only pay attention to in range characters
6775 if Lo
<= Enumeration_Pos
(L
)
6776 and then Enumeration_Pos
(L
) <= Hi
6778 -- For Width case, use decoded name
6780 if Id
= Attribute_Width
then
6781 Get_Decoded_Name_String
(Chars
(L
));
6782 Wt
:= Nat
(Name_Len
);
6784 -- For Wide_[Wide_]Width, use encoded name, and
6785 -- then adjust for the encoding.
6788 Get_Name_String
(Chars
(L
));
6790 -- Character literals are always of length 3
6792 if Name_Buffer
(1) = 'Q' then
6795 -- Otherwise loop to adjust for upper/wide chars
6798 Wt
:= Nat
(Name_Len
);
6800 for J
in 1 .. Name_Len
loop
6801 if Name_Buffer
(J
) = 'U' then
6803 elsif Name_Buffer
(J
) = 'W' then
6810 W
:= Int
'Max (W
, Wt
);
6817 Fold_Uint
(N
, UI_From_Int
(W
), True);
6823 -- The following attributes can never be folded, and furthermore we
6824 -- should not even have entered the case statement for any of these.
6825 -- Note that in some cases, the values have already been folded as
6826 -- a result of the processing in Analyze_Attribute.
6828 when Attribute_Abort_Signal |
6831 Attribute_Address_Size |
6832 Attribute_Asm_Input |
6833 Attribute_Asm_Output |
6835 Attribute_Bit_Order |
6836 Attribute_Bit_Position |
6837 Attribute_Callable |
6840 Attribute_Code_Address |
6842 Attribute_Default_Bit_Order |
6843 Attribute_Elaborated |
6844 Attribute_Elab_Body |
6845 Attribute_Elab_Spec |
6846 Attribute_External_Tag |
6847 Attribute_First_Bit |
6849 Attribute_Last_Bit |
6850 Attribute_Maximum_Alignment |
6852 Attribute_Partition_ID |
6853 Attribute_Pool_Address |
6854 Attribute_Position |
6855 Attribute_Priority |
6857 Attribute_Storage_Pool |
6858 Attribute_Storage_Size |
6859 Attribute_Storage_Unit |
6860 Attribute_Stub_Type |
6862 Attribute_Target_Name |
6863 Attribute_Terminated |
6864 Attribute_To_Address |
6865 Attribute_UET_Address |
6866 Attribute_Unchecked_Access |
6867 Attribute_Universal_Literal_String |
6868 Attribute_Unrestricted_Access |
6871 Attribute_Wchar_T_Size |
6872 Attribute_Wide_Value |
6873 Attribute_Wide_Wide_Value |
6874 Attribute_Word_Size |
6877 raise Program_Error
;
6880 -- At the end of the case, one more check. If we did a static evaluation
6881 -- so that the result is now a literal, then set Is_Static_Expression
6882 -- in the constant only if the prefix type is a static subtype. For
6883 -- non-static subtypes, the folding is still OK, but not static.
6885 -- An exception is the GNAT attribute Constrained_Array which is
6886 -- defined to be a static attribute in all cases.
6888 if Nkind
(N
) = N_Integer_Literal
6889 or else Nkind
(N
) = N_Real_Literal
6890 or else Nkind
(N
) = N_Character_Literal
6891 or else Nkind
(N
) = N_String_Literal
6892 or else (Is_Entity_Name
(N
)
6893 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6895 Set_Is_Static_Expression
(N
, Static
);
6897 -- If this is still an attribute reference, then it has not been folded
6898 -- and that means that its expressions are in a non-static context.
6900 elsif Nkind
(N
) = N_Attribute_Reference
then
6903 -- Note: the else case not covered here are odd cases where the
6904 -- processing has transformed the attribute into something other
6905 -- than a constant. Nothing more to do in such cases.
6913 ------------------------------
6914 -- Is_Anonymous_Tagged_Base --
6915 ------------------------------
6917 function Is_Anonymous_Tagged_Base
6924 Anon
= Current_Scope
6925 and then Is_Itype
(Anon
)
6926 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6927 end Is_Anonymous_Tagged_Base
;
6929 -----------------------
6930 -- Resolve_Attribute --
6931 -----------------------
6933 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6934 Loc
: constant Source_Ptr
:= Sloc
(N
);
6935 P
: constant Node_Id
:= Prefix
(N
);
6936 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6937 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6938 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6939 Des_Btyp
: Entity_Id
;
6940 Index
: Interp_Index
;
6942 Nom_Subt
: Entity_Id
;
6944 procedure Accessibility_Message
;
6945 -- Error, or warning within an instance, if the static accessibility
6946 -- rules of 3.10.2 are violated.
6948 ---------------------------
6949 -- Accessibility_Message --
6950 ---------------------------
6952 procedure Accessibility_Message
is
6953 Indic
: Node_Id
:= Parent
(Parent
(N
));
6956 -- In an instance, this is a runtime check, but one we
6957 -- know will fail, so generate an appropriate warning.
6959 if In_Instance_Body
then
6961 ("?non-local pointer cannot point to local object", P
);
6963 ("\?Program_Error will be raised at run time", P
);
6965 Make_Raise_Program_Error
(Loc
,
6966 Reason
=> PE_Accessibility_Check_Failed
));
6972 ("non-local pointer cannot point to local object", P
);
6974 -- Check for case where we have a missing access definition
6976 if Is_Record_Type
(Current_Scope
)
6978 (Nkind
(Parent
(N
)) = N_Discriminant_Association
6980 Nkind
(Parent
(N
)) = N_Index_Or_Discriminant_Constraint
)
6982 Indic
:= Parent
(Parent
(N
));
6983 while Present
(Indic
)
6984 and then Nkind
(Indic
) /= N_Subtype_Indication
6986 Indic
:= Parent
(Indic
);
6989 if Present
(Indic
) then
6991 ("\use an access definition for" &
6992 " the access discriminant of&", N
,
6993 Entity
(Subtype_Mark
(Indic
)));
6997 end Accessibility_Message
;
6999 -- Start of processing for Resolve_Attribute
7002 -- If error during analysis, no point in continuing, except for
7003 -- array types, where we get better recovery by using unconstrained
7004 -- indices than nothing at all (see Check_Array_Type).
7007 and then Attr_Id
/= Attribute_First
7008 and then Attr_Id
/= Attribute_Last
7009 and then Attr_Id
/= Attribute_Length
7010 and then Attr_Id
/= Attribute_Range
7015 -- If attribute was universal type, reset to actual type
7017 if Etype
(N
) = Universal_Integer
7018 or else Etype
(N
) = Universal_Real
7023 -- Remaining processing depends on attribute
7031 -- For access attributes, if the prefix denotes an entity, it is
7032 -- interpreted as a name, never as a call. It may be overloaded,
7033 -- in which case resolution uses the profile of the context type.
7034 -- Otherwise prefix must be resolved.
7036 when Attribute_Access
7037 | Attribute_Unchecked_Access
7038 | Attribute_Unrestricted_Access
=>
7040 if Is_Variable
(P
) then
7041 Note_Possible_Modification
(P
);
7044 if Is_Entity_Name
(P
) then
7045 if Is_Overloaded
(P
) then
7046 Get_First_Interp
(P
, Index
, It
);
7048 while Present
(It
.Nam
) loop
7050 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
7051 Set_Entity
(P
, It
.Nam
);
7053 -- The prefix is definitely NOT overloaded anymore
7054 -- at this point, so we reset the Is_Overloaded
7055 -- flag to avoid any confusion when reanalyzing
7058 Set_Is_Overloaded
(P
, False);
7059 Generate_Reference
(Entity
(P
), P
);
7063 Get_Next_Interp
(Index
, It
);
7066 -- If it is a subprogram name or a type, there is nothing
7069 elsif not Is_Overloadable
(Entity
(P
))
7070 and then not Is_Type
(Entity
(P
))
7075 Error_Msg_Name_1
:= Aname
;
7077 if not Is_Entity_Name
(P
) then
7080 elsif Is_Abstract
(Entity
(P
))
7081 and then Is_Overloadable
(Entity
(P
))
7083 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
7084 Set_Etype
(N
, Any_Type
);
7086 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
7087 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
7089 ("prefix of % attribute cannot be enumeration literal",
7093 ("prefix of % attribute cannot be intrinsic", P
);
7096 Set_Etype
(N
, Any_Type
);
7098 elsif Is_Thread_Body
(Entity
(P
)) then
7100 ("prefix of % attribute cannot be a thread body", P
);
7103 -- Assignments, return statements, components of aggregates,
7104 -- generic instantiations will require convention checks if
7105 -- the type is an access to subprogram. Given that there will
7106 -- also be accessibility checks on those, this is where the
7107 -- checks can eventually be centralized ???
7109 if Ekind
(Btyp
) = E_Access_Subprogram_Type
7111 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7113 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7115 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
7117 ("subprogram has invalid convention for context", P
);
7120 Check_Subtype_Conformant
7121 (New_Id
=> Entity
(P
),
7122 Old_Id
=> Designated_Type
(Btyp
),
7126 if Attr_Id
= Attribute_Unchecked_Access
then
7127 Error_Msg_Name_1
:= Aname
;
7129 ("attribute% cannot be applied to a subprogram", P
);
7131 elsif Aname
= Name_Unrestricted_Access
then
7132 null; -- Nothing to check
7134 -- Check the static accessibility rule of 3.10.2(32).
7135 -- This rule also applies within the private part of an
7136 -- instantiation. This rule does not apply to anonymous
7137 -- access-to-subprogram types (Ada 2005).
7139 elsif Attr_Id
= Attribute_Access
7140 and then not In_Instance_Body
7141 and then Subprogram_Access_Level
(Entity
(P
)) >
7142 Type_Access_Level
(Btyp
)
7143 and then Ekind
(Btyp
) /=
7144 E_Anonymous_Access_Subprogram_Type
7145 and then Ekind
(Btyp
) /=
7146 E_Anonymous_Access_Protected_Subprogram_Type
7149 ("subprogram must not be deeper than access type", P
);
7151 -- Check the restriction of 3.10.2(32) that disallows the
7152 -- access attribute within a generic body when the ultimate
7153 -- ancestor of the type of the attribute is declared outside
7154 -- of the generic unit and the subprogram is declared within
7155 -- that generic unit. This includes any such attribute that
7156 -- occurs within the body of a generic unit that is a child
7157 -- of the generic unit where the subprogram is declared.
7158 -- The rule also prohibits applying the attibute when the
7159 -- access type is a generic formal access type (since the
7160 -- level of the actual type is not known). This restriction
7161 -- does not apply when the attribute type is an anonymous
7162 -- access-to-subprogram type. Note that this check was
7163 -- revised by AI-229, because the originally Ada 95 rule
7164 -- was too lax. The original rule only applied when the
7165 -- subprogram was declared within the body of the generic,
7166 -- which allowed the possibility of dangling references).
7167 -- The rule was also too strict in some case, in that it
7168 -- didn't permit the access to be declared in the generic
7169 -- spec, whereas the revised rule does (as long as it's not
7172 -- There are a couple of subtleties of the test for applying
7173 -- the check that are worth noting. First, we only apply it
7174 -- when the levels of the subprogram and access type are the
7175 -- same (the case where the subprogram is statically deeper
7176 -- was applied above, and the case where the type is deeper
7177 -- is always safe). Second, we want the check to apply
7178 -- within nested generic bodies and generic child unit
7179 -- bodies, but not to apply to an attribute that appears in
7180 -- the generic unit's specification. This is done by testing
7181 -- that the attribute's innermost enclosing generic body is
7182 -- not the same as the innermost generic body enclosing the
7183 -- generic unit where the subprogram is declared (we don't
7184 -- want the check to apply when the access attribute is in
7185 -- the spec and there's some other generic body enclosing
7186 -- generic). Finally, there's no point applying the check
7187 -- when within an instance, because any violations will
7188 -- have been caught by the compilation of the generic unit.
7190 elsif Attr_Id
= Attribute_Access
7191 and then not In_Instance
7192 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
7193 and then Present
(Enclosing_Generic_Body
(N
))
7194 and then Enclosing_Generic_Body
(N
) /=
7195 Enclosing_Generic_Body
7196 (Enclosing_Generic_Unit
(Entity
(P
)))
7197 and then Subprogram_Access_Level
(Entity
(P
)) =
7198 Type_Access_Level
(Btyp
)
7199 and then Ekind
(Btyp
) /=
7200 E_Anonymous_Access_Subprogram_Type
7201 and then Ekind
(Btyp
) /=
7202 E_Anonymous_Access_Protected_Subprogram_Type
7204 -- The attribute type's ultimate ancestor must be
7205 -- declared within the same generic unit as the
7206 -- subprogram is declared. The error message is
7207 -- specialized to say "ancestor" for the case where
7208 -- the access type is not its own ancestor, since
7209 -- saying simply "access type" would be very confusing.
7211 if Enclosing_Generic_Unit
(Entity
(P
)) /=
7212 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
7214 if Root_Type
(Btyp
) = Btyp
then
7216 ("access type must not be outside generic unit",
7220 ("ancestor access type must not be outside " &
7224 -- If the ultimate ancestor of the attribute's type is
7225 -- a formal type, then the attribute is illegal because
7226 -- the actual type might be declared at a higher level.
7227 -- The error message is specialized to say "ancestor"
7228 -- for the case where the access type is not its own
7229 -- ancestor, since saying simply "access type" would be
7232 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
7233 if Root_Type
(Btyp
) = Btyp
then
7235 ("access type must not be a generic formal type",
7239 ("ancestor access type must not be a generic " &
7246 -- If this is a renaming, an inherited operation, or a
7247 -- subprogram instance, use the original entity.
7249 if Is_Entity_Name
(P
)
7250 and then Is_Overloadable
(Entity
(P
))
7251 and then Present
(Alias
(Entity
(P
)))
7254 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7257 elsif Nkind
(P
) = N_Selected_Component
7258 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
7260 -- Protected operation. If operation is overloaded, must
7261 -- disambiguate. Prefix that denotes protected object itself
7262 -- is resolved with its own type.
7264 if Attr_Id
= Attribute_Unchecked_Access
then
7265 Error_Msg_Name_1
:= Aname
;
7267 ("attribute% cannot be applied to protected operation", P
);
7270 Resolve
(Prefix
(P
));
7271 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
7273 elsif Is_Overloaded
(P
) then
7275 -- Use the designated type of the context to disambiguate
7276 -- Note that this was not strictly conformant to Ada 95,
7277 -- but was the implementation adopted by most Ada 95 compilers.
7278 -- The use of the context type to resolve an Access attribute
7279 -- reference is now mandated in AI-235 for Ada 2005.
7282 Index
: Interp_Index
;
7286 Get_First_Interp
(P
, Index
, It
);
7287 while Present
(It
.Typ
) loop
7288 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
7289 Resolve
(P
, It
.Typ
);
7293 Get_Next_Interp
(Index
, It
);
7300 -- X'Access is illegal if X denotes a constant and the access
7301 -- type is access-to-variable. Same for 'Unchecked_Access.
7302 -- The rule does not apply to 'Unrestricted_Access.
7303 -- If the reference is a default-initialized aggregate component
7304 -- for a self-referential type the reference is legal.
7306 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7307 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7308 or else (Is_Record_Type
(Btyp
) and then
7309 Present
(Corresponding_Remote_Type
(Btyp
)))
7310 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7311 or else Ekind
(Btyp
)
7312 = E_Anonymous_Access_Protected_Subprogram_Type
7313 or else Is_Access_Constant
(Btyp
)
7314 or else Is_Variable
(P
)
7315 or else Attr_Id
= Attribute_Unrestricted_Access
)
7317 if Is_Entity_Name
(P
)
7318 and then Is_Type
(Entity
(P
))
7320 -- Legality of a self-reference through an access
7321 -- attribute has been verified in Analyze_Access_Attribute.
7325 elsif Comes_From_Source
(N
) then
7326 Error_Msg_N
("access-to-variable designates constant", P
);
7330 if (Attr_Id
= Attribute_Access
7332 Attr_Id
= Attribute_Unchecked_Access
)
7333 and then (Ekind
(Btyp
) = E_General_Access_Type
7334 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7336 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7337 -- access types in record and array components. For a
7338 -- component definition the level is the same of the
7339 -- enclosing composite type.
7341 if Ada_Version
>= Ada_05
7343 (Is_Local_Anonymous_Access
(Btyp
)
7344 or else Ekind
(Scope
(Btyp
)) = E_Return_Statement
)
7345 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7346 and then Attr_Id
= Attribute_Access
7348 -- In an instance, this is a runtime check, but one we
7349 -- know will fail, so generate an appropriate warning.
7351 if In_Instance_Body
then
7353 ("?non-local pointer cannot point to local object", P
);
7355 ("\?Program_Error will be raised at run time", P
);
7357 Make_Raise_Program_Error
(Loc
,
7358 Reason
=> PE_Accessibility_Check_Failed
));
7362 ("non-local pointer cannot point to local object", P
);
7366 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7368 ("illegal attribute for discriminant-dependent component",
7372 -- Check the static matching rule of 3.10.2(27). The
7373 -- nominal subtype of the prefix must statically
7374 -- match the designated type.
7376 Nom_Subt
:= Etype
(P
);
7378 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7379 Nom_Subt
:= Etype
(Nom_Subt
);
7382 Des_Btyp
:= Designated_Type
(Btyp
);
7384 if Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
7386 -- Ada 2005 (AI-412): Subtypes of incomplete types visible
7387 -- through a limited with clause or regular incomplete
7390 if From_With_Type
(Des_Btyp
)
7391 and then Present
(Non_Limited_View
(Des_Btyp
))
7393 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
7395 Des_Btyp
:= Etype
(Des_Btyp
);
7399 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7401 -- If the attribute is in the context of an access
7402 -- parameter, then the prefix is allowed to be of
7403 -- the class-wide type (by AI-127).
7405 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7406 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7407 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7413 Desig
:= Designated_Type
(Typ
);
7415 if Is_Class_Wide_Type
(Desig
) then
7416 Desig
:= Etype
(Desig
);
7419 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
7424 ("type of prefix: & not compatible",
7427 ("\with &, the expected designated type",
7428 P
, Designated_Type
(Typ
));
7433 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7435 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
7436 and then Is_Class_Wide_Type
(Nom_Subt
))
7439 ("type of prefix: & is not covered", P
, Nom_Subt
);
7441 ("\by &, the expected designated type" &
7442 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
7445 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
7446 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
7447 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
7448 and then Designated_Type
(Typ
) /= Nom_Subt
7450 Apply_Discriminant_Check
7451 (N
, Etype
(Designated_Type
(Typ
)));
7454 -- Ada 2005 (AI-363): Require static matching when designated
7455 -- type has discriminants and a constrained partial view, since
7456 -- in general objects of such types are mutable, so we can't
7457 -- allow the access value to designate a constrained object
7458 -- (because access values must be assumed to designate mutable
7459 -- objects when designated type does not impose a constraint).
7461 elsif not Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
)
7463 not (Has_Discriminants
(Designated_Type
(Typ
))
7464 and then not Is_Constrained
(Des_Btyp
)
7466 (Ada_Version
< Ada_05
7468 not Has_Constrained_Partial_View
7469 (Designated_Type
(Base_Type
(Typ
)))))
7472 ("object subtype must statically match "
7473 & "designated subtype", P
);
7475 if Is_Entity_Name
(P
)
7476 and then Is_Array_Type
(Designated_Type
(Typ
))
7479 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
7482 Error_Msg_N
("aliased object has explicit bounds?",
7484 Error_Msg_N
("\declare without bounds"
7485 & " (and with explicit initialization)?", D
);
7486 Error_Msg_N
("\for use with unconstrained access?", D
);
7491 -- Check the static accessibility rule of 3.10.2(28).
7492 -- Note that this check is not performed for the
7493 -- case of an anonymous access type, since the access
7494 -- attribute is always legal in such a context.
7496 if Attr_Id
/= Attribute_Unchecked_Access
7497 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7498 and then Ekind
(Btyp
) = E_General_Access_Type
7500 Accessibility_Message
;
7505 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7507 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7509 if Is_Entity_Name
(P
)
7510 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
7512 Error_Msg_N
("context requires a protected subprogram", P
);
7514 -- Check accessibility of protected object against that
7515 -- of the access type, but only on user code, because
7516 -- the expander creates access references for handlers.
7517 -- If the context is an anonymous_access_to_protected,
7518 -- there are no accessibility checks either.
7520 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7521 and then Comes_From_Source
(N
)
7522 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7523 and then No
(Original_Access_Type
(Typ
))
7525 Accessibility_Message
;
7529 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
7531 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
7532 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
7534 Error_Msg_N
("context requires a non-protected subprogram", P
);
7537 -- The context cannot be a pool-specific type, but this is a
7538 -- legality rule, not a resolution rule, so it must be checked
7539 -- separately, after possibly disambiguation (see AI-245).
7541 if Ekind
(Btyp
) = E_Access_Type
7542 and then Attr_Id
/= Attribute_Unrestricted_Access
7544 Wrong_Type
(N
, Typ
);
7549 -- Check for incorrect atomic/volatile reference (RM C.6(12))
7551 if Attr_Id
/= Attribute_Unrestricted_Access
then
7552 if Is_Atomic_Object
(P
)
7553 and then not Is_Atomic
(Designated_Type
(Typ
))
7556 ("access to atomic object cannot yield access-to-" &
7557 "non-atomic type", P
);
7559 elsif Is_Volatile_Object
(P
)
7560 and then not Is_Volatile
(Designated_Type
(Typ
))
7563 ("access to volatile object cannot yield access-to-" &
7564 "non-volatile type", P
);
7572 -- Deal with resolving the type for Address attribute, overloading
7573 -- is not permitted here, since there is no context to resolve it.
7575 when Attribute_Address | Attribute_Code_Address
=>
7577 -- To be safe, assume that if the address of a variable is taken,
7578 -- it may be modified via this address, so note modification.
7580 if Is_Variable
(P
) then
7581 Note_Possible_Modification
(P
);
7584 if Nkind
(P
) in N_Subexpr
7585 and then Is_Overloaded
(P
)
7587 Get_First_Interp
(P
, Index
, It
);
7588 Get_Next_Interp
(Index
, It
);
7590 if Present
(It
.Nam
) then
7591 Error_Msg_Name_1
:= Aname
;
7593 ("prefix of % attribute cannot be overloaded", P
);
7598 if not Is_Entity_Name
(P
)
7599 or else not Is_Overloadable
(Entity
(P
))
7601 if not Is_Task_Type
(Etype
(P
))
7602 or else Nkind
(P
) = N_Explicit_Dereference
7608 -- If this is the name of a derived subprogram, or that of a
7609 -- generic actual, the address is that of the original entity.
7611 if Is_Entity_Name
(P
)
7612 and then Is_Overloadable
(Entity
(P
))
7613 and then Present
(Alias
(Entity
(P
)))
7616 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7623 -- Prefix of the AST_Entry attribute is an entry name which must
7624 -- not be resolved, since this is definitely not an entry call.
7626 when Attribute_AST_Entry
=>
7633 -- Prefix of Body_Version attribute can be a subprogram name which
7634 -- must not be resolved, since this is not a call.
7636 when Attribute_Body_Version
=>
7643 -- Prefix of Caller attribute is an entry name which must not
7644 -- be resolved, since this is definitely not an entry call.
7646 when Attribute_Caller
=>
7653 -- Shares processing with Address attribute
7659 -- If the prefix of the Count attribute is an entry name it must not
7660 -- be resolved, since this is definitely not an entry call. However,
7661 -- if it is an element of an entry family, the index itself may
7662 -- have to be resolved because it can be a general expression.
7664 when Attribute_Count
=>
7665 if Nkind
(P
) = N_Indexed_Component
7666 and then Is_Entity_Name
(Prefix
(P
))
7669 Indx
: constant Node_Id
:= First
(Expressions
(P
));
7670 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
7672 Resolve
(Indx
, Entry_Index_Type
(Fam
));
7673 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
7681 -- Prefix of the Elaborated attribute is a subprogram name which
7682 -- must not be resolved, since this is definitely not a call. Note
7683 -- that it is a library unit, so it cannot be overloaded here.
7685 when Attribute_Elaborated
=>
7688 --------------------
7689 -- Mechanism_Code --
7690 --------------------
7692 -- Prefix of the Mechanism_Code attribute is a function name
7693 -- which must not be resolved. Should we check for overloaded ???
7695 when Attribute_Mechanism_Code
=>
7702 -- Most processing is done in sem_dist, after determining the
7703 -- context type. Node is rewritten as a conversion to a runtime call.
7705 when Attribute_Partition_ID
=>
7706 Process_Partition_Id
(N
);
7709 when Attribute_Pool_Address
=>
7716 -- We replace the Range attribute node with a range expression
7717 -- whose bounds are the 'First and 'Last attributes applied to the
7718 -- same prefix. The reason that we do this transformation here
7719 -- instead of in the expander is that it simplifies other parts of
7720 -- the semantic analysis which assume that the Range has been
7721 -- replaced; thus it must be done even when in semantic-only mode
7722 -- (note that the RM specifically mentions this equivalence, we
7723 -- take care that the prefix is only evaluated once).
7725 when Attribute_Range
=> Range_Attribute
:
7730 function Check_Discriminated_Prival
7733 -- The range of a private component constrained by a
7734 -- discriminant is rewritten to make the discriminant
7735 -- explicit. This solves some complex visibility problems
7736 -- related to the use of privals.
7738 --------------------------------
7739 -- Check_Discriminated_Prival --
7740 --------------------------------
7742 function Check_Discriminated_Prival
7747 if Is_Entity_Name
(N
)
7748 and then Ekind
(Entity
(N
)) = E_In_Parameter
7749 and then not Within_Init_Proc
7751 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
7753 return Duplicate_Subexpr
(N
);
7755 end Check_Discriminated_Prival
;
7757 -- Start of processing for Range_Attribute
7760 if not Is_Entity_Name
(P
)
7761 or else not Is_Type
(Entity
(P
))
7766 -- Check whether prefix is (renaming of) private component
7767 -- of protected type.
7769 if Is_Entity_Name
(P
)
7770 and then Comes_From_Source
(N
)
7771 and then Is_Array_Type
(Etype
(P
))
7772 and then Number_Dimensions
(Etype
(P
)) = 1
7773 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
7775 Ekind
(Scope
(Scope
(Entity
(P
)))) =
7779 Check_Discriminated_Prival
7780 (Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
7783 Check_Discriminated_Prival
7784 (Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
7788 Make_Attribute_Reference
(Loc
,
7789 Prefix
=> Duplicate_Subexpr
(P
),
7790 Attribute_Name
=> Name_Last
,
7791 Expressions
=> Expressions
(N
));
7794 Make_Attribute_Reference
(Loc
,
7796 Attribute_Name
=> Name_First
,
7797 Expressions
=> Expressions
(N
));
7800 -- If the original was marked as Must_Not_Freeze (see code
7801 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7802 -- does not freeze either.
7804 if Must_Not_Freeze
(N
) then
7805 Set_Must_Not_Freeze
(HB
);
7806 Set_Must_Not_Freeze
(LB
);
7807 Set_Must_Not_Freeze
(Prefix
(HB
));
7808 Set_Must_Not_Freeze
(Prefix
(LB
));
7811 if Raises_Constraint_Error
(Prefix
(N
)) then
7813 -- Preserve Sloc of prefix in the new bounds, so that
7814 -- the posted warning can be removed if we are within
7815 -- unreachable code.
7817 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
7818 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
7821 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
7822 Analyze_And_Resolve
(N
, Typ
);
7824 -- Normally after resolving attribute nodes, Eval_Attribute
7825 -- is called to do any possible static evaluation of the node.
7826 -- However, here since the Range attribute has just been
7827 -- transformed into a range expression it is no longer an
7828 -- attribute node and therefore the call needs to be avoided
7829 -- and is accomplished by simply returning from the procedure.
7832 end Range_Attribute
;
7838 -- Prefix must not be resolved in this case, since it is not a
7839 -- real entity reference. No action of any kind is require!
7841 when Attribute_UET_Address
=>
7844 ----------------------
7845 -- Unchecked_Access --
7846 ----------------------
7848 -- Processing is shared with Access
7850 -------------------------
7851 -- Unrestricted_Access --
7852 -------------------------
7854 -- Processing is shared with Access
7860 -- Apply range check. Note that we did not do this during the
7861 -- analysis phase, since we wanted Eval_Attribute to have a
7862 -- chance at finding an illegal out of range value.
7864 when Attribute_Val
=>
7866 -- Note that we do our own Eval_Attribute call here rather than
7867 -- use the common one, because we need to do processing after
7868 -- the call, as per above comment.
7872 -- Eval_Attribute may replace the node with a raise CE, or
7873 -- fold it to a constant. Obviously we only apply a scalar
7874 -- range check if this did not happen!
7876 if Nkind
(N
) = N_Attribute_Reference
7877 and then Attribute_Name
(N
) = Name_Val
7879 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
7888 -- Prefix of Version attribute can be a subprogram name which
7889 -- must not be resolved, since this is not a call.
7891 when Attribute_Version
=>
7894 ----------------------
7895 -- Other Attributes --
7896 ----------------------
7898 -- For other attributes, resolve prefix unless it is a type. If
7899 -- the attribute reference itself is a type name ('Base and 'Class)
7900 -- then this is only legal within a task or protected record.
7903 if not Is_Entity_Name
(P
)
7904 or else not Is_Type
(Entity
(P
))
7909 -- If the attribute reference itself is a type name ('Base,
7910 -- 'Class) then this is only legal within a task or protected
7911 -- record. What is this all about ???
7913 if Is_Entity_Name
(N
)
7914 and then Is_Type
(Entity
(N
))
7916 if Is_Concurrent_Type
(Entity
(N
))
7917 and then In_Open_Scopes
(Entity
(P
))
7922 ("invalid use of subtype name in expression or call", N
);
7926 -- For attributes whose argument may be a string, complete
7927 -- resolution of argument now. This avoids premature expansion
7928 -- (and the creation of transient scopes) before the attribute
7929 -- reference is resolved.
7932 when Attribute_Value
=>
7933 Resolve
(First
(Expressions
(N
)), Standard_String
);
7935 when Attribute_Wide_Value
=>
7936 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
7938 when Attribute_Wide_Wide_Value
=>
7939 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
7941 when others => null;
7945 -- Normally the Freezing is done by Resolve but sometimes the Prefix
7946 -- is not resolved, in which case the freezing must be done now.
7948 Freeze_Expression
(P
);
7950 -- Finally perform static evaluation on the attribute reference
7953 end Resolve_Attribute
;
7955 --------------------------------
7956 -- Stream_Attribute_Available --
7957 --------------------------------
7959 function Stream_Attribute_Available
7961 Nam
: TSS_Name_Type
;
7962 Partial_View
: Node_Id
:= Empty
) return Boolean
7964 Etyp
: Entity_Id
:= Typ
;
7966 -- Start of processing for Stream_Attribute_Available
7969 -- We need some comments in this body ???
7971 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
7975 if Is_Class_Wide_Type
(Typ
) then
7976 return not Is_Limited_Type
(Typ
)
7977 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
7980 if Nam
= TSS_Stream_Input
7981 and then Is_Abstract
(Typ
)
7982 and then not Is_Class_Wide_Type
(Typ
)
7987 if not (Is_Limited_Type
(Typ
)
7988 or else (Present
(Partial_View
)
7989 and then Is_Limited_Type
(Partial_View
)))
7994 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
7996 if Nam
= TSS_Stream_Input
7997 and then Ada_Version
>= Ada_05
7998 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
8002 elsif Nam
= TSS_Stream_Output
8003 and then Ada_Version
>= Ada_05
8004 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
8009 -- Case of Read and Write: check for attribute definition clause that
8010 -- applies to an ancestor type.
8012 while Etype
(Etyp
) /= Etyp
loop
8013 Etyp
:= Etype
(Etyp
);
8015 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
8020 if Ada_Version
< Ada_05
then
8022 -- In Ada 95 mode, also consider a non-visible definition
8025 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
8028 and then Stream_Attribute_Available
8029 (Btyp
, Nam
, Partial_View
=> Typ
);
8034 end Stream_Attribute_Available
;