1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 ------------------------------------------------------------------------------
29 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
31 with Atree
; use Atree
;
32 with Checks
; use Checks
;
33 with Einfo
; use Einfo
;
34 with Errout
; use Errout
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Expander
; use Expander
;
39 with Freeze
; use Freeze
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch13
; use Sem_Ch13
;
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 Snames
; use Snames
;
62 with Stringt
; use Stringt
;
63 with Targparm
; use Targparm
;
64 with Ttypes
; use Ttypes
;
65 with Ttypef
; use Ttypef
;
66 with Tbuild
; use Tbuild
;
67 with Uintp
; use Uintp
;
68 with Urealp
; use Urealp
;
69 with Widechar
; use Widechar
;
71 package body Sem_Attr
is
73 True_Value
: constant Uint
:= Uint_1
;
74 False_Value
: constant Uint
:= Uint_0
;
75 -- Synonyms to be used when these constants are used as Boolean values
77 Bad_Attribute
: exception;
78 -- Exception raised if an error is detected during attribute processing,
79 -- used so that we can abandon the processing so we don't run into
80 -- trouble with cascaded errors.
82 -- The following array is the list of attributes defined in the Ada 83 RM
84 Attribute_83
: Attribute_Class_Array
:= Attribute_Class_Array
'(
90 Attribute_Constrained |
103 Attribute_Leading_Part |
105 Attribute_Machine_Emax |
106 Attribute_Machine_Emin |
107 Attribute_Machine_Mantissa |
108 Attribute_Machine_Overflows |
109 Attribute_Machine_Radix |
110 Attribute_Machine_Rounds |
116 Attribute_Safe_Emax |
117 Attribute_Safe_Large |
118 Attribute_Safe_Small |
121 Attribute_Storage_Size |
123 Attribute_Terminated |
126 Attribute_Width => True,
129 -----------------------
130 -- Local_Subprograms --
131 -----------------------
133 procedure Eval_Attribute (N : Node_Id);
134 -- Performs compile time evaluation of attributes where possible, leaving
135 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
136 -- set, and replacing the node with a literal node if the value can be
137 -- computed at compile time. All static attribute references are folded,
138 -- as well as a number of cases of non-static attributes that can always
139 -- be computed at compile time (e.g. floating-point model attributes that
140 -- are applied to non-static subtypes). Of course in such cases, the
141 -- Is_Static_Expression flag will not be set on the resulting literal.
142 -- Note that the only required action of this procedure is to catch the
143 -- static expression cases as described in the RM. Folding of other cases
144 -- is done where convenient, but some additional non-static folding is in
145 -- N_Expand_Attribute_Reference in cases where this is more convenient.
147 function Is_Anonymous_Tagged_Base
151 -- For derived tagged types that constrain parent discriminants we build
152 -- an anonymous unconstrained base type. We need to recognize the relation
153 -- between the two when analyzing an access attribute for a constrained
154 -- component, before the full declaration for Typ has been analyzed, and
155 -- where therefore the prefix of the attribute does not match the enclosing
158 -----------------------
159 -- Analyze_Attribute --
160 -----------------------
162 procedure Analyze_Attribute (N : Node_Id) is
163 Loc : constant Source_Ptr := Sloc (N);
164 Aname : constant Name_Id := Attribute_Name (N);
165 P : constant Node_Id := Prefix (N);
166 Exprs : constant List_Id := Expressions (N);
167 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
172 -- Type of prefix after analysis
174 P_Base_Type : Entity_Id;
175 -- Base type of prefix after analysis
177 P_Root_Type : Entity_Id;
178 -- Root type of prefix after analysis
180 Unanalyzed : Node_Id;
182 -----------------------
183 -- Local Subprograms --
184 -----------------------
186 procedure Access_Attribute;
187 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
188 -- Internally, Id distinguishes which of the three cases is involved.
190 procedure Check_Array_Or_Scalar_Type;
191 -- Common procedure used by First, Last, Range attribute to check
192 -- that the prefix is a constrained array or scalar type, or a name
193 -- of an array object, and that an argument appears only if appropriate
194 -- (i.e. only in the array case).
196 procedure Check_Array_Type;
197 -- Common semantic checks for all array attributes. Checks that the
198 -- prefix is a constrained array type or the name of an array object.
199 -- The error message for non-arrays is specialized appropriately.
201 procedure Check_Asm_Attribute;
202 -- Common semantic checks for Asm_Input and Asm_Output attributes
204 procedure Check_Component;
205 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
206 -- Position. Checks prefix is an appropriate selected component.
208 procedure Check_Decimal_Fixed_Point_Type;
209 -- Check that prefix of attribute N is a decimal fixed-point type
211 procedure Check_Dereference;
212 -- If the prefix of attribute is an object of an access type, then
213 -- introduce an explicit deference, and adjust P_Type accordingly.
215 procedure Check_Discrete_Type;
216 -- Verify that prefix of attribute N is a discrete type
219 -- Check that no attribute arguments are present
221 procedure Check_Either_E0_Or_E1;
222 -- Check that there are zero or one attribute arguments present
225 -- Check that exactly one attribute argument is present
228 -- Check that two attribute arguments are present
230 procedure Check_Enum_Image;
231 -- If the prefix type is an enumeration type, set all its literals
232 -- as referenced, since the image function could possibly end up
233 -- referencing any of the literals indirectly.
235 procedure Check_Enumeration_Type;
236 -- Verify that prefix of attribute N is an enumeration type
238 procedure Check_Fixed_Point_Type;
239 -- Verify that prefix of attribute N is a fixed type
241 procedure Check_Fixed_Point_Type_0;
242 -- Verify that prefix of attribute N is a fixed type and that
243 -- no attribute expressions are present
245 procedure Check_Floating_Point_Type;
246 -- Verify that prefix of attribute N is a float type
248 procedure Check_Floating_Point_Type_0;
249 -- Verify that prefix of attribute N is a float type and that
250 -- no attribute expressions are present
252 procedure Check_Floating_Point_Type_1;
253 -- Verify that prefix of attribute N is a float type and that
254 -- exactly one attribute expression is present
256 procedure Check_Floating_Point_Type_2;
257 -- Verify that prefix of attribute N is a float type and that
258 -- two attribute expressions are present
260 procedure Legal_Formal_Attribute;
261 -- Common processing for attributes Definite, and Has_Discriminants
263 procedure Check_Integer_Type;
264 -- Verify that prefix of attribute N is an integer type
266 procedure Check_Library_Unit;
267 -- Verify that prefix of attribute N is a library unit
269 procedure Check_Not_Incomplete_Type;
270 -- Check that P (the prefix of the attribute) is not an incomplete
271 -- type or a private type for which no full view has been given.
273 procedure Check_Object_Reference (P : Node_Id);
274 -- Check that P (the prefix of the attribute) is an object reference
276 procedure Check_Program_Unit;
277 -- Verify that prefix of attribute N is a program unit
279 procedure Check_Real_Type;
280 -- Verify that prefix of attribute N is fixed or float type
282 procedure Check_Scalar_Type;
283 -- Verify that prefix of attribute N is a scalar type
285 procedure Check_Standard_Prefix;
286 -- Verify that prefix of attribute N is package Standard
288 procedure Check_Stream_Attribute (Nam : Name_Id);
289 -- Validity checking for stream attribute. Nam is the name of the
290 -- corresponding possible defined attribute function (e.g. for the
291 -- Read attribute, Nam will be Name_uRead).
293 procedure Check_Task_Prefix;
294 -- Verify that prefix of attribute N is a task or task type
296 procedure Check_Type;
297 -- Verify that the prefix of attribute N is a type
299 procedure Check_Unit_Name (Nod : Node_Id);
300 -- Check that Nod is of the form of a library unit name, i.e that
301 -- it is an identifier, or a selected component whose prefix is
302 -- itself of the form of a library unit name. Note that this is
303 -- quite different from Check_Program_Unit, since it only checks
304 -- the syntactic form of the name, not the semantic identity. This
305 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
306 -- UET_Address) which can refer to non-visible unit.
308 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
309 pragma No_Return (Error_Attr);
310 -- Posts error using Error_Msg_N at given node, sets type of attribute
311 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
312 -- semantic processing. The message typically contains a % insertion
313 -- character which is replaced by the attribute name.
315 procedure Standard_Attribute (Val : Int);
316 -- Used to process attributes whose prefix is package Standard which
317 -- yield values of type Universal_Integer. The attribute reference
318 -- node is rewritten with an integer literal of the given value.
320 procedure Unexpected_Argument (En : Node_Id);
321 -- Signal unexpected attribute argument (En is the argument)
323 procedure Validate_Non_Static_Attribute_Function_Call;
324 -- Called when processing an attribute that is a function call to a
325 -- non-static function, i.e. an attribute function that either takes
326 -- non-scalar arguments or returns a non-scalar result. Verifies that
327 -- such a call does not appear in a preelaborable context.
329 ----------------------
330 -- Access_Attribute --
331 ----------------------
333 procedure Access_Attribute is
334 Acc_Type : Entity_Id;
339 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
340 -- Build an access-to-object type whose designated type is DT,
341 -- and whose Ekind is appropriate to the attribute type. The
342 -- type that is constructed is returned as the result.
344 procedure Build_Access_Subprogram_Type (P : Node_Id);
345 -- Build an access to subprogram whose designated type is
346 -- the type of the prefix. If prefix is overloaded, so it the
347 -- node itself. The result is stored in Acc_Type.
349 ------------------------------
350 -- Build_Access_Object_Type --
351 ------------------------------
353 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
357 if Aname = Name_Unrestricted_Access then
360 (E_Allocator_Type, Current_Scope, Loc, 'A
');
364 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
367 Set_Etype (Typ, Typ);
368 Init_Size_Align (Typ);
370 Set_Associated_Node_For_Itype (Typ, N);
371 Set_Directly_Designated_Type (Typ, DT);
373 end Build_Access_Object_Type;
375 ----------------------------------
376 -- Build_Access_Subprogram_Type --
377 ----------------------------------
379 procedure Build_Access_Subprogram_Type (P : Node_Id) is
380 Index : Interp_Index;
383 function Get_Kind (E : Entity_Id) return Entity_Kind;
384 -- Distinguish between access to regular and protected
387 function Get_Kind (E : Entity_Id) return Entity_Kind is
389 if Convention (E) = Convention_Protected then
390 return E_Access_Protected_Subprogram_Type;
392 return E_Access_Subprogram_Type;
396 -- Start of processing for Build_Access_Subprogram_Type
399 if not Is_Overloaded (P) then
402 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
403 Set_Etype (Acc_Type, Acc_Type);
404 Set_Directly_Designated_Type (Acc_Type, Entity (P));
405 Set_Etype (N, Acc_Type);
408 Get_First_Interp (P, Index, It);
409 Set_Etype (N, Any_Type);
411 while Present (It.Nam) loop
413 if not Is_Intrinsic_Subprogram (It.Nam) then
416 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
417 Set_Etype (Acc_Type, Acc_Type);
418 Set_Directly_Designated_Type (Acc_Type, It.Nam);
419 Add_One_Interp (N, Acc_Type, Acc_Type);
422 Get_Next_Interp (Index, It);
425 if Etype (N) = Any_Type then
426 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
429 end Build_Access_Subprogram_Type;
431 -- Start of processing for Access_Attribute
436 if Nkind (P) = N_Character_Literal then
438 ("prefix of % attribute cannot be enumeration literal", P);
440 -- In the case of an access to subprogram, use the name of the
441 -- subprogram itself as the designated type. Type-checking in
442 -- this case compares the signatures of the designated types.
444 elsif Is_Entity_Name (P)
445 and then Is_Overloadable (Entity (P))
447 Build_Access_Subprogram_Type (P);
450 -- Component is an operation of a protected type.
452 elsif (Nkind (P) = N_Selected_Component
453 and then Is_Overloadable (Entity (Selector_Name (P))))
455 if Ekind (Entity (Selector_Name (P))) = E_Entry then
456 Error_Attr ("Prefix of % attribute must be subprogram", P);
459 Build_Access_Subprogram_Type (Selector_Name (P));
463 -- Deal with incorrect reference to a type, but note that some
464 -- accesses are allowed (references to the current type instance).
466 if Is_Entity_Name (P) then
467 Scop := Current_Scope;
470 if Is_Type (Typ) then
472 -- OK if we are within the scope of a limited type
473 -- let's mark the component as having per object constraint
475 if Is_Anonymous_Tagged_Base (Scop, Typ) then
483 Q : Node_Id := Parent (N);
487 and then Nkind (Q) /= N_Component_Declaration
492 Set_Has_Per_Object_Constraint (
493 Defining_Identifier (Q), True);
497 if Nkind (P) = N_Expanded_Name then
499 ("current instance prefix must be a direct name", P);
502 -- If a current instance attribute appears within a
503 -- a component constraint it must appear alone; other
504 -- contexts (default expressions, within a task body)
505 -- are not subject to this restriction.
507 if not In_Default_Expression
508 and then not Has_Completion (Scop)
510 Nkind (Parent (N)) /= N_Discriminant_Association
512 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
515 ("current instance attribute must appear alone", N);
518 -- OK if we are in initialization procedure for the type
519 -- in question, in which case the reference to the type
520 -- is rewritten as a reference to the current object.
522 elsif Ekind (Scop) = E_Procedure
523 and then Chars (Scop) = Name_uInit_Proc
524 and then Etype (First_Formal (Scop)) = Typ
527 Make_Attribute_Reference (Loc,
528 Prefix => Make_Identifier (Loc, Name_uInit),
529 Attribute_Name => Name_Unrestricted_Access));
533 -- OK if a task type, this test needs sharpening up ???
535 elsif Is_Task_Type (Typ) then
538 -- Otherwise we have an error case
541 Error_Attr ("% attribute cannot be applied to type", P);
547 -- If we fall through, we have a normal access to object case.
548 -- Unrestricted_Access is legal wherever an allocator would be
549 -- legal, so its Etype is set to E_Allocator. The expected type
550 -- of the other attributes is a general access type, and therefore
551 -- we label them with E_Access_Attribute_Type.
553 if not Is_Overloaded (P) then
554 Acc_Type := Build_Access_Object_Type (P_Type);
555 Set_Etype (N, Acc_Type);
558 Index : Interp_Index;
562 Set_Etype (N, Any_Type);
563 Get_First_Interp (P, Index, It);
565 while Present (It.Typ) loop
566 Acc_Type := Build_Access_Object_Type (It.Typ);
567 Add_One_Interp (N, Acc_Type, Acc_Type);
568 Get_Next_Interp (Index, It);
573 -- Check for aliased view unless unrestricted case. We allow
574 -- a nonaliased prefix when within an instance because the
575 -- prefix may have been a tagged formal object, which is
576 -- defined to be aliased even when the actual might not be
577 -- (other instance cases will have been caught in the generic).
579 if Aname /= Name_Unrestricted_Access
580 and then not Is_Aliased_View (P)
581 and then not In_Instance
583 Error_Attr ("prefix of % attribute must be aliased", P);
586 end Access_Attribute;
588 --------------------------------
589 -- Check_Array_Or_Scalar_Type --
590 --------------------------------
592 procedure Check_Array_Or_Scalar_Type is
596 -- Dimension number for array attributes.
599 -- Case of string literal or string literal subtype. These cases
600 -- cannot arise from legal Ada code, but the expander is allowed
601 -- to generate them. They require special handling because string
602 -- literal subtypes do not have standard bounds (the whole idea
603 -- of these subtypes is to avoid having to generate the bounds)
605 if Ekind (P_Type) = E_String_Literal_Subtype then
606 Set_Etype (N, Etype (First_Index (P_Base_Type)));
611 elsif Is_Scalar_Type (P_Type) then
615 Error_Attr ("invalid argument in % attribute", E1);
617 Set_Etype (N, P_Base_Type);
621 -- The following is a special test to allow 'First to apply to
622 -- private scalar types if the attribute comes from generated
623 -- code. This occurs in the case of Normalize_Scalars code.
625 elsif Is_Private_Type
(P_Type
)
626 and then Present
(Full_View
(P_Type
))
627 and then Is_Scalar_Type
(Full_View
(P_Type
))
628 and then not Comes_From_Source
(N
)
630 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
632 -- Array types other than string literal subtypes handled above
637 -- We know prefix is an array type, or the name of an array
638 -- object, and that the expression, if present, is static
639 -- and within the range of the dimensions of the type.
641 if Is_Array_Type
(P_Type
) then
642 Index
:= First_Index
(P_Base_Type
);
644 else pragma Assert
(Is_Access_Type
(P_Type
));
645 Index
:= First_Index
(Base_Type
(Designated_Type
(P_Type
)));
650 -- First dimension assumed
652 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
655 D
:= UI_To_Int
(Intval
(E1
));
657 for J
in 1 .. D
- 1 loop
661 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
662 Set_Etype
(E1
, Standard_Integer
);
665 end Check_Array_Or_Scalar_Type
;
667 ----------------------
668 -- Check_Array_Type --
669 ----------------------
671 procedure Check_Array_Type
is
673 -- Dimension number for array attributes.
676 -- If the type is a string literal type, then this must be generated
677 -- internally, and no further check is required on its legality.
679 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
682 -- If the type is a composite, it is an illegal aggregate, no point
685 elsif P_Type
= Any_Composite
then
689 -- Normal case of array type or subtype
691 Check_Either_E0_Or_E1
;
693 if Is_Array_Type
(P_Type
) then
694 if not Is_Constrained
(P_Type
)
695 and then Is_Entity_Name
(P
)
696 and then Is_Type
(Entity
(P
))
698 -- Note: we do not call Error_Attr here, since we prefer to
699 -- continue, using the relevant index type of the array,
700 -- even though it is unconstrained. This gives better error
701 -- recovery behavior.
703 Error_Msg_Name_1
:= Aname
;
705 ("prefix for % attribute must be constrained array", P
);
708 D
:= Number_Dimensions
(P_Type
);
710 elsif Is_Access_Type
(P_Type
)
711 and then Is_Array_Type
(Designated_Type
(P_Type
))
713 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
714 Error_Attr
("prefix of % attribute cannot be access type", P
);
717 D
:= Number_Dimensions
(Designated_Type
(P_Type
));
719 -- If there is an implicit dereference, then we must freeze
720 -- the designated type of the access type, since the type of
721 -- the referenced array is this type (see AI95-00106).
723 Freeze_Before
(N
, Designated_Type
(P_Type
));
726 if Is_Private_Type
(P_Type
) then
728 ("prefix for % attribute may not be private type", P
);
730 elsif Attr_Id
= Attribute_First
732 Attr_Id
= Attribute_Last
734 Error_Attr
("invalid prefix for % attribute", P
);
737 Error_Attr
("prefix for % attribute must be array", P
);
742 Resolve
(E1
, Any_Integer
);
743 Set_Etype
(E1
, Standard_Integer
);
745 if not Is_Static_Expression
(E1
)
746 or else Raises_Constraint_Error
(E1
)
748 Error_Attr
("expression for dimension must be static", E1
);
750 elsif UI_To_Int
(Expr_Value
(E1
)) > D
751 or else UI_To_Int
(Expr_Value
(E1
)) < 1
753 Error_Attr
("invalid dimension number for array type", E1
);
756 end Check_Array_Type
;
758 -------------------------
759 -- Check_Asm_Attribute --
760 -------------------------
762 procedure Check_Asm_Attribute
is
767 -- Check first argument is static string expression
769 Analyze_And_Resolve
(E1
, Standard_String
);
771 if Etype
(E1
) = Any_Type
then
774 elsif not Is_OK_Static_Expression
(E1
) then
776 ("constraint argument must be static string expression", E1
);
779 -- Check second argument is right type
781 Analyze_And_Resolve
(E2
, Entity
(P
));
783 -- Note: that is all we need to do, we don't need to check
784 -- that it appears in a correct context. The Ada type system
785 -- will do that for us.
787 end Check_Asm_Attribute
;
789 ---------------------
790 -- Check_Component --
791 ---------------------
793 procedure Check_Component
is
797 if Nkind
(P
) /= N_Selected_Component
799 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
801 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
804 ("prefix for % attribute must be selected component", P
);
808 ------------------------------------
809 -- Check_Decimal_Fixed_Point_Type --
810 ------------------------------------
812 procedure Check_Decimal_Fixed_Point_Type
is
816 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
818 ("prefix of % attribute must be decimal type", P
);
820 end Check_Decimal_Fixed_Point_Type
;
822 -----------------------
823 -- Check_Dereference --
824 -----------------------
826 procedure Check_Dereference
is
828 if Is_Object_Reference
(P
)
829 and then Is_Access_Type
(P_Type
)
832 Make_Explicit_Dereference
(Sloc
(P
),
833 Prefix
=> Relocate_Node
(P
)));
835 Analyze_And_Resolve
(P
);
838 if P_Type
= Any_Type
then
842 P_Base_Type
:= Base_Type
(P_Type
);
843 P_Root_Type
:= Root_Type
(P_Base_Type
);
845 end Check_Dereference
;
847 -------------------------
848 -- Check_Discrete_Type --
849 -------------------------
851 procedure Check_Discrete_Type
is
855 if not Is_Discrete_Type
(P_Type
) then
856 Error_Attr
("prefix of % attribute must be discrete type", P
);
858 end Check_Discrete_Type
;
864 procedure Check_E0
is
867 Unexpected_Argument
(E1
);
875 procedure Check_E1
is
877 Check_Either_E0_Or_E1
;
881 -- Special-case attributes that are functions and that appear as
882 -- the prefix of another attribute. Error is posted on parent.
884 if Nkind
(Parent
(N
)) = N_Attribute_Reference
885 and then (Attribute_Name
(Parent
(N
)) = Name_Address
887 Attribute_Name
(Parent
(N
)) = Name_Code_Address
889 Attribute_Name
(Parent
(N
)) = Name_Access
)
891 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
892 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
893 Set_Etype
(Parent
(N
), Any_Type
);
894 Set_Entity
(Parent
(N
), Any_Type
);
898 Error_Attr
("missing argument for % attribute", N
);
907 procedure Check_E2
is
910 Error_Attr
("missing arguments for % attribute (2 required)", N
);
912 Error_Attr
("missing argument for % attribute (2 required)", N
);
916 ---------------------------
917 -- Check_Either_E0_Or_E1 --
918 ---------------------------
920 procedure Check_Either_E0_Or_E1
is
923 Unexpected_Argument
(E2
);
925 end Check_Either_E0_Or_E1
;
927 ----------------------
928 -- Check_Enum_Image --
929 ----------------------
931 procedure Check_Enum_Image
is
935 if Is_Enumeration_Type
(P_Base_Type
) then
936 Lit
:= First_Literal
(P_Base_Type
);
937 while Present
(Lit
) loop
938 Set_Referenced
(Lit
);
942 end Check_Enum_Image
;
944 ----------------------------
945 -- Check_Enumeration_Type --
946 ----------------------------
948 procedure Check_Enumeration_Type
is
952 if not Is_Enumeration_Type
(P_Type
) then
953 Error_Attr
("prefix of % attribute must be enumeration type", P
);
955 end Check_Enumeration_Type
;
957 ----------------------------
958 -- Check_Fixed_Point_Type --
959 ----------------------------
961 procedure Check_Fixed_Point_Type
is
965 if not Is_Fixed_Point_Type
(P_Type
) then
966 Error_Attr
("prefix of % attribute must be fixed point type", P
);
968 end Check_Fixed_Point_Type
;
970 ------------------------------
971 -- Check_Fixed_Point_Type_0 --
972 ------------------------------
974 procedure Check_Fixed_Point_Type_0
is
976 Check_Fixed_Point_Type
;
978 end Check_Fixed_Point_Type_0
;
980 -------------------------------
981 -- Check_Floating_Point_Type --
982 -------------------------------
984 procedure Check_Floating_Point_Type
is
988 if not Is_Floating_Point_Type
(P_Type
) then
989 Error_Attr
("prefix of % attribute must be float type", P
);
991 end Check_Floating_Point_Type
;
993 ---------------------------------
994 -- Check_Floating_Point_Type_0 --
995 ---------------------------------
997 procedure Check_Floating_Point_Type_0
is
999 Check_Floating_Point_Type
;
1001 end Check_Floating_Point_Type_0
;
1003 ---------------------------------
1004 -- Check_Floating_Point_Type_1 --
1005 ---------------------------------
1007 procedure Check_Floating_Point_Type_1
is
1009 Check_Floating_Point_Type
;
1011 end Check_Floating_Point_Type_1
;
1013 ---------------------------------
1014 -- Check_Floating_Point_Type_2 --
1015 ---------------------------------
1017 procedure Check_Floating_Point_Type_2
is
1019 Check_Floating_Point_Type
;
1021 end Check_Floating_Point_Type_2
;
1023 ------------------------
1024 -- Check_Integer_Type --
1025 ------------------------
1027 procedure Check_Integer_Type
is
1031 if not Is_Integer_Type
(P_Type
) then
1032 Error_Attr
("prefix of % attribute must be integer type", P
);
1034 end Check_Integer_Type
;
1036 ------------------------
1037 -- Check_Library_Unit --
1038 ------------------------
1040 procedure Check_Library_Unit
is
1042 if not Is_Compilation_Unit
(Entity
(P
)) then
1043 Error_Attr
("prefix of % attribute must be library unit", P
);
1045 end Check_Library_Unit
;
1047 -------------------------------
1048 -- Check_Not_Incomplete_Type --
1049 -------------------------------
1051 procedure Check_Not_Incomplete_Type
is
1053 if not Is_Entity_Name
(P
)
1054 or else not Is_Type
(Entity
(P
))
1055 or else In_Default_Expression
1060 Check_Fully_Declared
(P_Type
, P
);
1062 end Check_Not_Incomplete_Type
;
1064 ----------------------------
1065 -- Check_Object_Reference --
1066 ----------------------------
1068 procedure Check_Object_Reference
(P
: Node_Id
) is
1072 -- If we need an object, and we have a prefix that is the name of
1073 -- a function entity, convert it into a function call.
1075 if Is_Entity_Name
(P
)
1076 and then Ekind
(Entity
(P
)) = E_Function
1078 Rtyp
:= Etype
(Entity
(P
));
1081 Make_Function_Call
(Sloc
(P
),
1082 Name
=> Relocate_Node
(P
)));
1084 Analyze_And_Resolve
(P
, Rtyp
);
1086 -- Otherwise we must have an object reference
1088 elsif not Is_Object_Reference
(P
) then
1089 Error_Attr
("prefix of % attribute must be object", P
);
1091 end Check_Object_Reference
;
1093 ------------------------
1094 -- Check_Program_Unit --
1095 ------------------------
1097 procedure Check_Program_Unit
is
1099 if Is_Entity_Name
(P
) then
1101 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1102 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1105 if K
in Subprogram_Kind
1106 or else K
in Task_Kind
1107 or else K
in Protected_Kind
1108 or else K
= E_Package
1109 or else K
in Generic_Unit_Kind
1110 or else (K
= E_Variable
1114 Is_Protected_Type
(T
)))
1121 Error_Attr
("prefix of % attribute must be program unit", P
);
1122 end Check_Program_Unit
;
1124 ---------------------
1125 -- Check_Real_Type --
1126 ---------------------
1128 procedure Check_Real_Type
is
1132 if not Is_Real_Type
(P_Type
) then
1133 Error_Attr
("prefix of % attribute must be real type", P
);
1135 end Check_Real_Type
;
1137 -----------------------
1138 -- Check_Scalar_Type --
1139 -----------------------
1141 procedure Check_Scalar_Type
is
1145 if not Is_Scalar_Type
(P_Type
) then
1146 Error_Attr
("prefix of % attribute must be scalar type", P
);
1148 end Check_Scalar_Type
;
1150 ---------------------------
1151 -- Check_Standard_Prefix --
1152 ---------------------------
1154 procedure Check_Standard_Prefix
is
1158 if Nkind
(P
) /= N_Identifier
1159 or else Chars
(P
) /= Name_Standard
1161 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1164 end Check_Standard_Prefix
;
1166 ----------------------------
1167 -- Check_Stream_Attribute --
1168 ----------------------------
1170 procedure Check_Stream_Attribute
(Nam
: Name_Id
) is
1175 Validate_Non_Static_Attribute_Function_Call
;
1177 -- With the exception of 'Input, Stream attributes are procedures,
1178 -- and can only appear at the position of procedure calls. We check
1179 -- for this here, before they are rewritten, to give a more precise
1182 if Nam
= Name_uInput
then
1185 elsif Is_List_Member
(N
)
1186 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1187 and then Nkind
(Parent
(N
)) /= N_Aggregate
1193 ("invalid context for attribute %, which is a procedure", N
);
1197 Btyp
:= Implementation_Base_Type
(P_Type
);
1199 -- Stream attributes not allowed on limited types unless the
1200 -- special OK_For_Stream flag is set.
1202 if Is_Limited_Type
(P_Type
)
1203 and then Comes_From_Source
(N
)
1204 and then not Present
(TSS
(Btyp
, Nam
))
1205 and then No
(Get_Rep_Pragma
(Btyp
, Name_Stream_Convert
))
1207 -- Special case the message if we are compiling the stub version
1208 -- of a remote operation. One error on the type is sufficient.
1210 if (Is_Remote_Types
(Current_Scope
)
1211 or else Is_Remote_Call_Interface
(Current_Scope
))
1212 and then not Error_Posted
(Btyp
)
1214 Error_Msg_Node_2
:= Current_Scope
;
1216 ("limited type& used in& has no stream attributes", P
, Btyp
);
1217 Set_Error_Posted
(Btyp
);
1219 elsif not Error_Posted
(Btyp
) then
1221 ("limited type& has no stream attributes", P
, Btyp
);
1225 -- Here we must check that the first argument is an access type
1226 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1228 Analyze_And_Resolve
(E1
);
1231 -- Note: the double call to Root_Type here is needed because the
1232 -- root type of a class-wide type is the corresponding type (e.g.
1233 -- X for X'Class, and we really want to go to the root.
1235 if not Is_Access_Type
(Etyp
)
1236 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1237 RTE
(RE_Root_Stream_Type
)
1240 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1243 -- Check that the second argument is of the right type if there is
1244 -- one (the Input attribute has only one argument so this is skipped)
1246 if Present
(E2
) then
1250 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1253 ("second argument of % attribute must be a variable", E2
);
1256 Resolve
(E2
, P_Type
);
1258 end Check_Stream_Attribute
;
1260 -----------------------
1261 -- Check_Task_Prefix --
1262 -----------------------
1264 procedure Check_Task_Prefix
is
1268 if Is_Task_Type
(Etype
(P
))
1269 or else (Is_Access_Type
(Etype
(P
))
1270 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1272 Resolve
(P
, Etype
(P
));
1274 Error_Attr
("prefix of % attribute must be a task", P
);
1276 end Check_Task_Prefix
;
1282 -- The possibilities are an entity name denoting a type, or an
1283 -- attribute reference that denotes a type (Base or Class). If
1284 -- the type is incomplete, replace it with its full view.
1286 procedure Check_Type
is
1288 if not Is_Entity_Name
(P
)
1289 or else not Is_Type
(Entity
(P
))
1291 Error_Attr
("prefix of % attribute must be a type", P
);
1293 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1294 and then Present
(Full_View
(Entity
(P
)))
1296 P_Type
:= Full_View
(Entity
(P
));
1297 Set_Entity
(P
, P_Type
);
1301 ---------------------
1302 -- Check_Unit_Name --
1303 ---------------------
1305 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1307 if Nkind
(Nod
) = N_Identifier
then
1310 elsif Nkind
(Nod
) = N_Selected_Component
then
1311 Check_Unit_Name
(Prefix
(Nod
));
1313 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1318 Error_Attr
("argument for % attribute must be unit name", P
);
1319 end Check_Unit_Name
;
1325 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1327 Error_Msg_Name_1
:= Aname
;
1328 Error_Msg_N
(Msg
, Error_Node
);
1329 Set_Etype
(N
, Any_Type
);
1330 Set_Entity
(N
, Any_Type
);
1331 raise Bad_Attribute
;
1334 ----------------------------
1335 -- Legal_Formal_Attribute --
1336 ----------------------------
1338 procedure Legal_Formal_Attribute
is
1342 if not Is_Entity_Name
(P
)
1343 or else not Is_Type
(Entity
(P
))
1345 Error_Attr
(" prefix of % attribute must be generic type", N
);
1347 elsif Is_Generic_Actual_Type
(Entity
(P
))
1352 elsif Is_Generic_Type
(Entity
(P
)) then
1353 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1355 (" prefix of % attribute must be indefinite generic type", N
);
1360 (" prefix of % attribute must be indefinite generic type", N
);
1363 Set_Etype
(N
, Standard_Boolean
);
1364 end Legal_Formal_Attribute
;
1366 ------------------------
1367 -- Standard_Attribute --
1368 ------------------------
1370 procedure Standard_Attribute
(Val
: Int
) is
1372 Check_Standard_Prefix
;
1374 Make_Integer_Literal
(Loc
, Val
));
1376 end Standard_Attribute
;
1378 -------------------------
1379 -- Unexpected Argument --
1380 -------------------------
1382 procedure Unexpected_Argument
(En
: Node_Id
) is
1384 Error_Attr
("unexpected argument for % attribute", En
);
1385 end Unexpected_Argument
;
1387 -------------------------------------------------
1388 -- Validate_Non_Static_Attribute_Function_Call --
1389 -------------------------------------------------
1391 -- This function should be moved to Sem_Dist ???
1393 procedure Validate_Non_Static_Attribute_Function_Call
is
1395 if In_Preelaborated_Unit
1396 and then not In_Subprogram_Or_Concurrent_Unit
1398 Error_Msg_N
("non-static function call in preelaborated unit", N
);
1400 end Validate_Non_Static_Attribute_Function_Call
;
1402 -----------------------------------------------
1403 -- Start of Processing for Analyze_Attribute --
1404 -----------------------------------------------
1407 -- Immediate return if unrecognized attribute (already diagnosed
1408 -- by parser, so there is nothing more that we need to do)
1410 if not Is_Attribute_Name
(Aname
) then
1411 raise Bad_Attribute
;
1414 -- Deal with Ada 83 and Features issues
1416 if not Attribute_83
(Attr_Id
) then
1417 if Ada_83
and then Comes_From_Source
(N
) then
1418 Error_Msg_Name_1
:= Aname
;
1419 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1422 if Attribute_Impl_Def
(Attr_Id
) then
1423 Check_Restriction
(No_Implementation_Attributes
, N
);
1427 -- Remote access to subprogram type access attribute reference needs
1428 -- unanalyzed copy for tree transformation. The analyzed copy is used
1429 -- for its semantic information (whether prefix is a remote subprogram
1430 -- name), the unanalyzed copy is used to construct new subtree rooted
1431 -- with N_aggregate which represents a fat pointer aggregate.
1433 if Aname
= Name_Access
then
1434 Unanalyzed
:= Copy_Separate_Tree
(N
);
1437 -- Analyze prefix and exit if error in analysis. If the prefix is an
1438 -- incomplete type, use full view if available. A special case is
1439 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1440 -- or UET_Address attribute.
1442 if Aname
/= Name_Elab_Body
1444 Aname
/= Name_Elab_Spec
1446 Aname
/= Name_UET_Address
1449 P_Type
:= Etype
(P
);
1451 if Is_Entity_Name
(P
)
1452 and then Present
(Entity
(P
))
1453 and then Is_Type
(Entity
(P
))
1454 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1456 P_Type
:= Get_Full_View
(P_Type
);
1457 Set_Entity
(P
, P_Type
);
1458 Set_Etype
(P
, P_Type
);
1461 if P_Type
= Any_Type
then
1462 raise Bad_Attribute
;
1465 P_Base_Type
:= Base_Type
(P_Type
);
1466 P_Root_Type
:= Root_Type
(P_Base_Type
);
1469 -- Analyze expressions that may be present, exiting if an error occurs
1476 E1
:= First
(Exprs
);
1479 -- Check for missing or bad expression (result of previous error)
1481 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1482 raise Bad_Attribute
;
1487 if Present
(E2
) then
1490 if Etype
(E2
) = Any_Type
then
1491 raise Bad_Attribute
;
1494 if Present
(Next
(E2
)) then
1495 Unexpected_Argument
(Next
(E2
));
1500 if Is_Overloaded
(P
)
1501 and then Aname
/= Name_Access
1502 and then Aname
/= Name_Address
1503 and then Aname
/= Name_Code_Address
1504 and then Aname
/= Name_Count
1505 and then Aname
/= Name_Unchecked_Access
1507 Error_Attr
("ambiguous prefix for % attribute", P
);
1510 -- Remaining processing depends on attribute
1518 when Attribute_Abort_Signal
=>
1519 Check_Standard_Prefix
;
1521 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1528 when Attribute_Access
=>
1535 when Attribute_Address
=>
1538 -- Check for some junk cases, where we have to allow the address
1539 -- attribute but it does not make much sense, so at least for now
1540 -- just replace with Null_Address.
1542 -- We also do this if the prefix is a reference to the AST_Entry
1543 -- attribute. If expansion is active, the attribute will be
1544 -- replaced by a function call, and address will work fine and
1545 -- get the proper value, but if expansion is not active, then
1546 -- the check here allows proper semantic analysis of the reference.
1548 -- An Address attribute created by expansion is legal even when it
1549 -- applies to other entity-denoting expressions.
1551 if (Is_Entity_Name
(P
)) then
1552 if Is_Subprogram
(Entity
(P
))
1553 or else Is_Object
(Entity
(P
))
1554 or else Ekind
(Entity
(P
)) = E_Label
1556 Set_Address_Taken
(Entity
(P
));
1558 elsif (Is_Concurrent_Type
(Etype
(Entity
(P
)))
1559 and then Etype
(Entity
(P
)) = Base_Type
(Entity
(P
)))
1560 or else Ekind
(Entity
(P
)) = E_Package
1561 or else Is_Generic_Unit
(Entity
(P
))
1564 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1567 Error_Attr
("invalid prefix for % attribute", P
);
1570 elsif Nkind
(P
) = N_Attribute_Reference
1571 and then Attribute_Name
(P
) = Name_AST_Entry
1574 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1576 elsif Is_Object_Reference
(P
) then
1579 elsif Nkind
(P
) = N_Selected_Component
1580 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1584 elsif not Comes_From_Source
(N
) then
1588 Error_Attr
("invalid prefix for % attribute", P
);
1591 Set_Etype
(N
, RTE
(RE_Address
));
1597 when Attribute_Address_Size
=>
1598 Standard_Attribute
(System_Address_Size
);
1604 when Attribute_Adjacent
=>
1605 Check_Floating_Point_Type_2
;
1606 Set_Etype
(N
, P_Base_Type
);
1607 Resolve
(E1
, P_Base_Type
);
1608 Resolve
(E2
, P_Base_Type
);
1614 when Attribute_Aft
=>
1615 Check_Fixed_Point_Type_0
;
1616 Set_Etype
(N
, Universal_Integer
);
1622 when Attribute_Alignment
=>
1624 -- Don't we need more checking here, cf Size ???
1627 Check_Not_Incomplete_Type
;
1628 Set_Etype
(N
, Universal_Integer
);
1634 when Attribute_Asm_Input
=>
1635 Check_Asm_Attribute
;
1636 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1642 when Attribute_Asm_Output
=>
1643 Check_Asm_Attribute
;
1645 if Etype
(E2
) = Any_Type
then
1648 elsif Aname
= Name_Asm_Output
then
1649 if not Is_Variable
(E2
) then
1651 ("second argument for Asm_Output is not variable", E2
);
1655 Note_Possible_Modification
(E2
);
1656 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1662 when Attribute_AST_Entry
=> AST_Entry
: declare
1668 -- Indicates if entry family index is present. Note the coding
1669 -- here handles the entry family case, but in fact it cannot be
1670 -- executed currently, because pragma AST_Entry does not permit
1671 -- the specification of an entry family.
1673 procedure Bad_AST_Entry
;
1674 -- Signal a bad AST_Entry pragma
1676 function OK_Entry
(E
: Entity_Id
) return Boolean;
1677 -- Checks that E is of an appropriate entity kind for an entry
1678 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1679 -- is set True for the entry family case). In the True case,
1680 -- makes sure that Is_AST_Entry is set on the entry.
1682 procedure Bad_AST_Entry
is
1684 Error_Attr
("prefix for % attribute must be task entry", P
);
1687 function OK_Entry
(E
: Entity_Id
) return Boolean is
1692 Result
:= (Ekind
(E
) = E_Entry_Family
);
1694 Result
:= (Ekind
(E
) = E_Entry
);
1698 if not Is_AST_Entry
(E
) then
1699 Error_Msg_Name_2
:= Aname
;
1701 ("% attribute requires previous % pragma", P
);
1708 -- Start of processing for AST_Entry
1714 -- Deal with entry family case
1716 if Nkind
(P
) = N_Indexed_Component
then
1724 Ptyp
:= Etype
(Pref
);
1726 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
1730 -- If the prefix is a selected component whose prefix is of an
1731 -- access type, then introduce an explicit dereference.
1733 if Nkind
(Pref
) = N_Selected_Component
1734 and then Is_Access_Type
(Ptyp
)
1737 Make_Explicit_Dereference
(Sloc
(Pref
),
1738 Relocate_Node
(Pref
)));
1739 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
1742 -- Prefix can be of the form a.b, where a is a task object
1743 -- and b is one of the entries of the corresponding task type.
1745 if Nkind
(Pref
) = N_Selected_Component
1746 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
1747 and then Is_Object_Reference
(Prefix
(Pref
))
1748 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
1752 -- Otherwise the prefix must be an entry of a containing task,
1753 -- or of a variable of the enclosing task type.
1756 if Nkind
(Pref
) = N_Identifier
1757 or else Nkind
(Pref
) = N_Expanded_Name
1759 Ent
:= Entity
(Pref
);
1761 if not OK_Entry
(Ent
)
1762 or else not In_Open_Scopes
(Scope
(Ent
))
1772 Set_Etype
(N
, RTE
(RE_AST_Handler
));
1779 when Attribute_Base
=> Base
: declare
1783 Check_Either_E0_Or_E1
;
1787 if Sloc
(Typ
) = Standard_Location
1788 and then Base_Type
(Typ
) = Typ
1789 and then Warn_On_Redundant_Constructs
1792 ("?redudant attribute, & is its own base type", N
, Typ
);
1795 Set_Etype
(N
, Base_Type
(Entity
(P
)));
1797 -- If we have an expression present, then really this is a conversion
1798 -- and the tree must be reformed. Note that this is one of the cases
1799 -- in which we do a replace rather than a rewrite, because the
1800 -- original tree is junk.
1802 if Present
(E1
) then
1804 Make_Type_Conversion
(Loc
,
1806 Make_Attribute_Reference
(Loc
,
1807 Prefix
=> Prefix
(N
),
1808 Attribute_Name
=> Name_Base
),
1809 Expression
=> Relocate_Node
(E1
)));
1811 -- E1 may be overloaded, and its interpretations preserved.
1813 Save_Interps
(E1
, Expression
(N
));
1816 -- For other cases, set the proper type as the entity of the
1817 -- attribute reference, and then rewrite the node to be an
1818 -- occurrence of the referenced base type. This way, no one
1819 -- else in the compiler has to worry about the base attribute.
1822 Set_Entity
(N
, Base_Type
(Entity
(P
)));
1824 New_Reference_To
(Entity
(N
), Loc
));
1833 when Attribute_Bit
=> Bit
:
1837 if not Is_Object_Reference
(P
) then
1838 Error_Attr
("prefix for % attribute must be object", P
);
1840 -- What about the access object cases ???
1846 Set_Etype
(N
, Universal_Integer
);
1853 when Attribute_Bit_Order
=> Bit_Order
:
1858 if not Is_Record_Type
(P_Type
) then
1859 Error_Attr
("prefix of % attribute must be record type", P
);
1862 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
1864 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
1867 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
1870 Set_Etype
(N
, RTE
(RE_Bit_Order
));
1871 Resolve
(N
, Etype
(N
));
1873 -- Reset incorrect indication of staticness
1875 Set_Is_Static_Expression
(N
, False);
1882 -- Note: in generated code, we can have a Bit_Position attribute
1883 -- applied to a (naked) record component (i.e. the prefix is an
1884 -- identifier that references an E_Component or E_Discriminant
1885 -- entity directly, and this is interpreted as expected by Gigi.
1886 -- The following code will not tolerate such usage, but when the
1887 -- expander creates this special case, it marks it as analyzed
1888 -- immediately and sets an appropriate type.
1890 when Attribute_Bit_Position
=>
1892 if Comes_From_Source
(N
) then
1896 Set_Etype
(N
, Universal_Integer
);
1902 when Attribute_Body_Version
=>
1905 Set_Etype
(N
, RTE
(RE_Version_String
));
1911 when Attribute_Callable
=>
1913 Set_Etype
(N
, Standard_Boolean
);
1920 when Attribute_Caller
=> Caller
: declare
1927 if Nkind
(P
) = N_Identifier
1928 or else Nkind
(P
) = N_Expanded_Name
1932 if not Is_Entry
(Ent
) then
1933 Error_Attr
("invalid entry name", N
);
1937 Error_Attr
("invalid entry name", N
);
1941 for J
in reverse 0 .. Scope_Stack
.Last
loop
1942 S
:= Scope_Stack
.Table
(J
).Entity
;
1944 if S
= Scope
(Ent
) then
1945 Error_Attr
("Caller must appear in matching accept or body", N
);
1951 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
1958 when Attribute_Ceiling
=>
1959 Check_Floating_Point_Type_1
;
1960 Set_Etype
(N
, P_Base_Type
);
1961 Resolve
(E1
, P_Base_Type
);
1967 when Attribute_Class
=> Class
: declare
1969 Check_Restriction
(No_Dispatch
, N
);
1970 Check_Either_E0_Or_E1
;
1972 -- If we have an expression present, then really this is a conversion
1973 -- and the tree must be reformed into a proper conversion. This is a
1974 -- Replace rather than a Rewrite, because the original tree is junk.
1975 -- If expression is overloaded, propagate interpretations to new one.
1977 if Present
(E1
) then
1979 Make_Type_Conversion
(Loc
,
1981 Make_Attribute_Reference
(Loc
,
1982 Prefix
=> Prefix
(N
),
1983 Attribute_Name
=> Name_Class
),
1984 Expression
=> Relocate_Node
(E1
)));
1986 Save_Interps
(E1
, Expression
(N
));
1989 -- Otherwise we just need to find the proper type
2001 when Attribute_Code_Address
=>
2004 if Nkind
(P
) = N_Attribute_Reference
2005 and then (Attribute_Name
(P
) = Name_Elab_Body
2007 Attribute_Name
(P
) = Name_Elab_Spec
)
2011 elsif not Is_Entity_Name
(P
)
2012 or else (Ekind
(Entity
(P
)) /= E_Function
2014 Ekind
(Entity
(P
)) /= E_Procedure
)
2016 Error_Attr
("invalid prefix for % attribute", P
);
2017 Set_Address_Taken
(Entity
(P
));
2020 Set_Etype
(N
, RTE
(RE_Address
));
2022 --------------------
2023 -- Component_Size --
2024 --------------------
2026 when Attribute_Component_Size
=>
2028 Set_Etype
(N
, Universal_Integer
);
2030 -- Note: unlike other array attributes, unconstrained arrays are OK
2032 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2042 when Attribute_Compose
=>
2043 Check_Floating_Point_Type_2
;
2044 Set_Etype
(N
, P_Base_Type
);
2045 Resolve
(E1
, P_Base_Type
);
2046 Resolve
(E2
, Any_Integer
);
2052 when Attribute_Constrained
=>
2054 Set_Etype
(N
, Standard_Boolean
);
2056 -- Case from RM J.4(2) of constrained applied to private type
2058 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2060 -- If we are within an instance, the attribute must be legal
2061 -- because it was valid in the generic unit.
2066 -- For sure OK if we have a real private type itself, but must
2067 -- be completed, cannot apply Constrained to incomplete type.
2069 elsif Is_Private_Type
(Entity
(P
)) then
2070 Check_Not_Incomplete_Type
;
2075 Check_Object_Reference
(P
);
2077 -- If N does not come from source, then we allow the
2078 -- the attribute prefix to be of a private type whose
2079 -- full type has discriminants. This occurs in cases
2080 -- involving expanded calls to stream attributes.
2082 if not Comes_From_Source
(N
) then
2083 P_Type
:= Underlying_Type
(P_Type
);
2086 -- Must have discriminants or be an access type designating
2087 -- a type with discriminants. If it is a classwide type is
2088 -- has unknown discriminants.
2090 if Has_Discriminants
(P_Type
)
2091 or else Has_Unknown_Discriminants
(P_Type
)
2093 (Is_Access_Type
(P_Type
)
2094 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2098 -- Also allow an object of a generic type if extensions allowed
2099 -- and allow this for any type at all.
2101 elsif (Is_Generic_Type
(P_Type
)
2102 or else Is_Generic_Actual_Type
(P_Type
))
2103 and then Extensions_Allowed
2109 -- Fall through if bad prefix
2112 ("prefix of % attribute must be object of discriminated type", P
);
2118 when Attribute_Copy_Sign
=>
2119 Check_Floating_Point_Type_2
;
2120 Set_Etype
(N
, P_Base_Type
);
2121 Resolve
(E1
, P_Base_Type
);
2122 Resolve
(E2
, P_Base_Type
);
2128 when Attribute_Count
=> Count
:
2137 if Nkind
(P
) = N_Identifier
2138 or else Nkind
(P
) = N_Expanded_Name
2142 if Ekind
(Ent
) /= E_Entry
then
2143 Error_Attr
("invalid entry name", N
);
2146 elsif Nkind
(P
) = N_Indexed_Component
then
2147 Ent
:= Entity
(Prefix
(P
));
2149 if Ekind
(Ent
) /= E_Entry_Family
then
2150 Error_Attr
("invalid entry family name", P
);
2155 Error_Attr
("invalid entry name", N
);
2159 for J
in reverse 0 .. Scope_Stack
.Last
loop
2160 S
:= Scope_Stack
.Table
(J
).Entity
;
2162 if S
= Scope
(Ent
) then
2163 if Nkind
(P
) = N_Expanded_Name
then
2164 Tsk
:= Entity
(Prefix
(P
));
2166 -- The prefix denotes either the task type, or else a
2167 -- single task whose task type is being analyzed.
2172 or else (not Is_Type
(Tsk
)
2173 and then Etype
(Tsk
) = S
2174 and then not (Comes_From_Source
(S
)))
2179 ("Count must apply to entry of current task", N
);
2185 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2186 and then Ekind
(S
) /= E_Loop
2187 and then Ekind
(S
) /= E_Block
2188 and then Ekind
(S
) /= E_Entry
2189 and then Ekind
(S
) /= E_Entry_Family
2191 Error_Attr
("Count cannot appear in inner unit", N
);
2193 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2194 and then not Has_Completion
(Scope
(Ent
))
2196 Error_Attr
("attribute % can only be used inside body", N
);
2200 if Is_Overloaded
(P
) then
2202 Index
: Interp_Index
;
2206 Get_First_Interp
(P
, Index
, It
);
2208 while Present
(It
.Nam
) loop
2209 if It
.Nam
= Ent
then
2212 elsif Scope
(It
.Nam
) = Scope
(Ent
) then
2213 Error_Attr
("ambiguous entry name", N
);
2216 -- For now make this into a warning. Will become an
2217 -- error after the 3.15 release.
2220 ("ambiguous name, resolved to entry?", N
);
2222 ("\(this will become an error in a later release)?", N
);
2225 Get_Next_Interp
(Index
, It
);
2230 Set_Etype
(N
, Universal_Integer
);
2233 -----------------------
2234 -- Default_Bit_Order --
2235 -----------------------
2237 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2239 Check_Standard_Prefix
;
2242 if Bytes_Big_Endian
then
2244 Make_Integer_Literal
(Loc
, False_Value
));
2247 Make_Integer_Literal
(Loc
, True_Value
));
2250 Set_Etype
(N
, Universal_Integer
);
2251 Set_Is_Static_Expression
(N
);
2252 end Default_Bit_Order
;
2258 when Attribute_Definite
=>
2259 Legal_Formal_Attribute
;
2265 when Attribute_Delta
=>
2266 Check_Fixed_Point_Type_0
;
2267 Set_Etype
(N
, Universal_Real
);
2273 when Attribute_Denorm
=>
2274 Check_Floating_Point_Type_0
;
2275 Set_Etype
(N
, Standard_Boolean
);
2281 when Attribute_Digits
=>
2285 if not Is_Floating_Point_Type
(P_Type
)
2286 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2289 ("prefix of % attribute must be float or decimal type", P
);
2292 Set_Etype
(N
, Universal_Integer
);
2298 -- Also handles processing for Elab_Spec
2300 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2302 Check_Unit_Name
(P
);
2303 Set_Etype
(N
, Standard_Void_Type
);
2305 -- We have to manually call the expander in this case to get
2306 -- the necessary expansion (normally attributes that return
2307 -- entities are not expanded).
2315 -- Shares processing with Elab_Body
2321 when Attribute_Elaborated
=>
2324 Set_Etype
(N
, Standard_Boolean
);
2330 when Attribute_Emax
=>
2331 Check_Floating_Point_Type_0
;
2332 Set_Etype
(N
, Universal_Integer
);
2338 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2340 if Present
(E1
) then
2342 Check_Discrete_Type
;
2343 Resolve
(E1
, P_Base_Type
);
2346 if not Is_Entity_Name
(P
)
2347 or else (not Is_Object
(Entity
(P
))
2349 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2352 ("prefix of %attribute must be " &
2353 "discrete type/object or enum literal", P
);
2357 Set_Etype
(N
, Universal_Integer
);
2364 when Attribute_Epsilon
=>
2365 Check_Floating_Point_Type_0
;
2366 Set_Etype
(N
, Universal_Real
);
2372 when Attribute_Exponent
=>
2373 Check_Floating_Point_Type_1
;
2374 Set_Etype
(N
, Universal_Integer
);
2375 Resolve
(E1
, P_Base_Type
);
2381 when Attribute_External_Tag
=>
2385 Set_Etype
(N
, Standard_String
);
2387 if not Is_Tagged_Type
(P_Type
) then
2388 Error_Attr
("prefix of % attribute must be tagged", P
);
2395 when Attribute_First
=>
2396 Check_Array_Or_Scalar_Type
;
2402 when Attribute_First_Bit
=>
2404 Set_Etype
(N
, Universal_Integer
);
2410 when Attribute_Fixed_Value
=>
2412 Check_Fixed_Point_Type
;
2413 Resolve
(E1
, Any_Integer
);
2414 Set_Etype
(N
, P_Base_Type
);
2420 when Attribute_Floor
=>
2421 Check_Floating_Point_Type_1
;
2422 Set_Etype
(N
, P_Base_Type
);
2423 Resolve
(E1
, P_Base_Type
);
2429 when Attribute_Fore
=>
2430 Check_Fixed_Point_Type_0
;
2431 Set_Etype
(N
, Universal_Integer
);
2437 when Attribute_Fraction
=>
2438 Check_Floating_Point_Type_1
;
2439 Set_Etype
(N
, P_Base_Type
);
2440 Resolve
(E1
, P_Base_Type
);
2442 -----------------------
2443 -- Has_Discriminants --
2444 -----------------------
2446 when Attribute_Has_Discriminants
=>
2447 Legal_Formal_Attribute
;
2453 when Attribute_Identity
=>
2457 if Etype
(P
) = Standard_Exception_Type
then
2458 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2460 elsif Is_Task_Type
(Etype
(P
))
2461 or else (Is_Access_Type
(Etype
(P
))
2462 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2464 Resolve
(P
, Etype
(P
));
2465 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
2468 Error_Attr
("prefix of % attribute must be a task or an "
2476 when Attribute_Image
=> Image
:
2478 Set_Etype
(N
, Standard_String
);
2481 if Is_Real_Type
(P_Type
) then
2482 if Ada_83
and then Comes_From_Source
(N
) then
2483 Error_Msg_Name_1
:= Aname
;
2485 ("(Ada 83) % attribute not allowed for real types", N
);
2489 if Is_Enumeration_Type
(P_Type
) then
2490 Check_Restriction
(No_Enumeration_Maps
, N
);
2494 Resolve
(E1
, P_Base_Type
);
2496 Validate_Non_Static_Attribute_Function_Call
;
2503 when Attribute_Img
=> Img
:
2505 Set_Etype
(N
, Standard_String
);
2507 if not Is_Scalar_Type
(P_Type
)
2508 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2511 ("prefix of % attribute must be scalar object name", N
);
2521 when Attribute_Input
=>
2523 Check_Stream_Attribute
(Name_uInput
);
2524 Disallow_In_No_Run_Time_Mode
(N
);
2525 Set_Etype
(N
, P_Base_Type
);
2531 when Attribute_Integer_Value
=>
2534 Resolve
(E1
, Any_Fixed
);
2535 Set_Etype
(N
, P_Base_Type
);
2541 when Attribute_Large
=>
2544 Set_Etype
(N
, Universal_Real
);
2550 when Attribute_Last
=>
2551 Check_Array_Or_Scalar_Type
;
2557 when Attribute_Last_Bit
=>
2559 Set_Etype
(N
, Universal_Integer
);
2565 when Attribute_Leading_Part
=>
2566 Check_Floating_Point_Type_2
;
2567 Set_Etype
(N
, P_Base_Type
);
2568 Resolve
(E1
, P_Base_Type
);
2569 Resolve
(E2
, Any_Integer
);
2575 when Attribute_Length
=>
2577 Set_Etype
(N
, Universal_Integer
);
2583 when Attribute_Machine
=>
2584 Check_Floating_Point_Type_1
;
2585 Set_Etype
(N
, P_Base_Type
);
2586 Resolve
(E1
, P_Base_Type
);
2592 when Attribute_Machine_Emax
=>
2593 Check_Floating_Point_Type_0
;
2594 Set_Etype
(N
, Universal_Integer
);
2600 when Attribute_Machine_Emin
=>
2601 Check_Floating_Point_Type_0
;
2602 Set_Etype
(N
, Universal_Integer
);
2604 ----------------------
2605 -- Machine_Mantissa --
2606 ----------------------
2608 when Attribute_Machine_Mantissa
=>
2609 Check_Floating_Point_Type_0
;
2610 Set_Etype
(N
, Universal_Integer
);
2612 -----------------------
2613 -- Machine_Overflows --
2614 -----------------------
2616 when Attribute_Machine_Overflows
=>
2619 Set_Etype
(N
, Standard_Boolean
);
2625 when Attribute_Machine_Radix
=>
2628 Set_Etype
(N
, Universal_Integer
);
2630 --------------------
2631 -- Machine_Rounds --
2632 --------------------
2634 when Attribute_Machine_Rounds
=>
2637 Set_Etype
(N
, Standard_Boolean
);
2643 when Attribute_Machine_Size
=>
2646 Check_Not_Incomplete_Type
;
2647 Set_Etype
(N
, Universal_Integer
);
2653 when Attribute_Mantissa
=>
2656 Set_Etype
(N
, Universal_Integer
);
2662 when Attribute_Max
=>
2665 Resolve
(E1
, P_Base_Type
);
2666 Resolve
(E2
, P_Base_Type
);
2667 Set_Etype
(N
, P_Base_Type
);
2669 ----------------------------
2670 -- Max_Interrupt_Priority --
2671 ----------------------------
2673 when Attribute_Max_Interrupt_Priority
=>
2678 (Parent
(RTE
(RE_Max_Interrupt_Priority
))))));
2684 when Attribute_Max_Priority
=>
2689 (Parent
(RTE
(RE_Max_Priority
))))));
2691 ----------------------------------
2692 -- Max_Size_In_Storage_Elements --
2693 ----------------------------------
2695 when Attribute_Max_Size_In_Storage_Elements
=>
2698 Check_Not_Incomplete_Type
;
2699 Set_Etype
(N
, Universal_Integer
);
2701 -----------------------
2702 -- Maximum_Alignment --
2703 -----------------------
2705 when Attribute_Maximum_Alignment
=>
2706 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
2708 --------------------
2709 -- Mechanism_Code --
2710 --------------------
2712 when Attribute_Mechanism_Code
=>
2714 if not Is_Entity_Name
(P
)
2715 or else not Is_Subprogram
(Entity
(P
))
2717 Error_Attr
("prefix of % attribute must be subprogram", P
);
2720 Check_Either_E0_Or_E1
;
2722 if Present
(E1
) then
2723 Resolve
(E1
, Any_Integer
);
2724 Set_Etype
(E1
, Standard_Integer
);
2726 if not Is_Static_Expression
(E1
) then
2728 ("expression for parameter number must be static", E1
);
2730 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
2731 or else UI_To_Int
(Intval
(E1
)) < 0
2733 Error_Attr
("invalid parameter number for %attribute", E1
);
2737 Set_Etype
(N
, Universal_Integer
);
2743 when Attribute_Min
=>
2746 Resolve
(E1
, P_Base_Type
);
2747 Resolve
(E2
, P_Base_Type
);
2748 Set_Etype
(N
, P_Base_Type
);
2754 when Attribute_Model
=>
2755 Check_Floating_Point_Type_1
;
2756 Set_Etype
(N
, P_Base_Type
);
2757 Resolve
(E1
, P_Base_Type
);
2763 when Attribute_Model_Emin
=>
2764 Check_Floating_Point_Type_0
;
2765 Set_Etype
(N
, Universal_Integer
);
2771 when Attribute_Model_Epsilon
=>
2772 Check_Floating_Point_Type_0
;
2773 Set_Etype
(N
, Universal_Real
);
2775 --------------------
2776 -- Model_Mantissa --
2777 --------------------
2779 when Attribute_Model_Mantissa
=>
2780 Check_Floating_Point_Type_0
;
2781 Set_Etype
(N
, Universal_Integer
);
2787 when Attribute_Model_Small
=>
2788 Check_Floating_Point_Type_0
;
2789 Set_Etype
(N
, Universal_Real
);
2795 when Attribute_Modulus
=>
2799 if not Is_Modular_Integer_Type
(P_Type
) then
2800 Error_Attr
("prefix of % attribute must be modular type", P
);
2803 Set_Etype
(N
, Universal_Integer
);
2805 --------------------
2806 -- Null_Parameter --
2807 --------------------
2809 when Attribute_Null_Parameter
=> Null_Parameter
: declare
2810 Parnt
: constant Node_Id
:= Parent
(N
);
2811 GParnt
: constant Node_Id
:= Parent
(Parnt
);
2813 procedure Bad_Null_Parameter
(Msg
: String);
2814 -- Used if bad Null parameter attribute node is found. Issues
2815 -- given error message, and also sets the type to Any_Type to
2816 -- avoid blowups later on from dealing with a junk node.
2818 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
2819 -- Called to check that Proc_Ent is imported subprogram
2821 ------------------------
2822 -- Bad_Null_Parameter --
2823 ------------------------
2825 procedure Bad_Null_Parameter
(Msg
: String) is
2827 Error_Msg_N
(Msg
, N
);
2828 Set_Etype
(N
, Any_Type
);
2829 end Bad_Null_Parameter
;
2831 ----------------------
2832 -- Must_Be_Imported --
2833 ----------------------
2835 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
2836 Pent
: Entity_Id
:= Proc_Ent
;
2839 while Present
(Alias
(Pent
)) loop
2840 Pent
:= Alias
(Pent
);
2843 -- Ignore check if procedure not frozen yet (we will get
2844 -- another chance when the default parameter is reanalyzed)
2846 if not Is_Frozen
(Pent
) then
2849 elsif not Is_Imported
(Pent
) then
2851 ("Null_Parameter can only be used with imported subprogram");
2856 end Must_Be_Imported
;
2858 -- Start of processing for Null_Parameter
2863 Set_Etype
(N
, P_Type
);
2865 -- Case of attribute used as default expression
2867 if Nkind
(Parnt
) = N_Parameter_Specification
then
2868 Must_Be_Imported
(Defining_Entity
(GParnt
));
2870 -- Case of attribute used as actual for subprogram (positional)
2872 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
2874 Nkind
(Parnt
) = N_Function_Call
)
2875 and then Is_Entity_Name
(Name
(Parnt
))
2877 Must_Be_Imported
(Entity
(Name
(Parnt
)));
2879 -- Case of attribute used as actual for subprogram (named)
2881 elsif Nkind
(Parnt
) = N_Parameter_Association
2882 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
2884 Nkind
(GParnt
) = N_Function_Call
)
2885 and then Is_Entity_Name
(Name
(GParnt
))
2887 Must_Be_Imported
(Entity
(Name
(GParnt
)));
2889 -- Not an allowed case
2893 ("Null_Parameter must be actual or default parameter");
2902 when Attribute_Object_Size
=>
2905 Check_Not_Incomplete_Type
;
2906 Set_Etype
(N
, Universal_Integer
);
2912 when Attribute_Output
=>
2914 Check_Stream_Attribute
(Name_uInput
);
2915 Set_Etype
(N
, Standard_Void_Type
);
2916 Disallow_In_No_Run_Time_Mode
(N
);
2917 Resolve
(N
, Standard_Void_Type
);
2923 when Attribute_Partition_ID
=>
2926 if P_Type
/= Any_Type
then
2927 if not Is_Library_Level_Entity
(Entity
(P
)) then
2929 ("prefix of % attribute must be library-level entity", P
);
2931 -- The defining entity of prefix should not be declared inside
2932 -- a Pure unit. RM E.1(8).
2933 -- The Is_Pure flag has been set during declaration.
2935 elsif Is_Entity_Name
(P
)
2936 and then Is_Pure
(Entity
(P
))
2939 ("prefix of % attribute must not be declared pure", P
);
2943 Set_Etype
(N
, Universal_Integer
);
2945 -------------------------
2946 -- Passed_By_Reference --
2947 -------------------------
2949 when Attribute_Passed_By_Reference
=>
2952 Set_Etype
(N
, Standard_Boolean
);
2958 when Attribute_Pos
=>
2959 Check_Discrete_Type
;
2961 Resolve
(E1
, P_Base_Type
);
2962 Set_Etype
(N
, Universal_Integer
);
2968 when Attribute_Position
=>
2970 Set_Etype
(N
, Universal_Integer
);
2976 when Attribute_Pred
=>
2979 Resolve
(E1
, P_Base_Type
);
2980 Set_Etype
(N
, P_Base_Type
);
2982 -- Nothing to do for real type case
2984 if Is_Real_Type
(P_Type
) then
2987 -- If not modular type, test for overflow check required
2990 if not Is_Modular_Integer_Type
(P_Type
)
2991 and then not Range_Checks_Suppressed
(P_Base_Type
)
2993 Enable_Range_Check
(E1
);
3001 when Attribute_Range
=>
3002 Check_Array_Or_Scalar_Type
;
3005 and then Is_Scalar_Type
(P_Type
)
3006 and then Comes_From_Source
(N
)
3009 ("(Ada 83) % attribute not allowed for scalar type", P
);
3016 when Attribute_Range_Length
=>
3017 Check_Discrete_Type
;
3018 Set_Etype
(N
, Universal_Integer
);
3024 when Attribute_Read
=>
3026 Check_Stream_Attribute
(Name_uRead
);
3027 Set_Etype
(N
, Standard_Void_Type
);
3028 Resolve
(N
, Standard_Void_Type
);
3029 Disallow_In_No_Run_Time_Mode
(N
);
3030 Note_Possible_Modification
(E2
);
3036 when Attribute_Remainder
=>
3037 Check_Floating_Point_Type_2
;
3038 Set_Etype
(N
, P_Base_Type
);
3039 Resolve
(E1
, P_Base_Type
);
3040 Resolve
(E2
, P_Base_Type
);
3046 when Attribute_Round
=>
3048 Check_Decimal_Fixed_Point_Type
;
3049 Set_Etype
(N
, P_Base_Type
);
3051 -- Because the context is universal_real (3.5.10(12)) it is a legal
3052 -- context for a universal fixed expression. This is the only
3053 -- attribute whose functional description involves U_R.
3055 if Etype
(E1
) = Universal_Fixed
then
3057 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3058 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3059 Expression
=> Relocate_Node
(E1
));
3067 Resolve
(E1
, Any_Real
);
3073 when Attribute_Rounding
=>
3074 Check_Floating_Point_Type_1
;
3075 Set_Etype
(N
, P_Base_Type
);
3076 Resolve
(E1
, P_Base_Type
);
3082 when Attribute_Safe_Emax
=>
3083 Check_Floating_Point_Type_0
;
3084 Set_Etype
(N
, Universal_Integer
);
3090 when Attribute_Safe_First
=>
3091 Check_Floating_Point_Type_0
;
3092 Set_Etype
(N
, Universal_Real
);
3098 when Attribute_Safe_Large
=>
3101 Set_Etype
(N
, Universal_Real
);
3107 when Attribute_Safe_Last
=>
3108 Check_Floating_Point_Type_0
;
3109 Set_Etype
(N
, Universal_Real
);
3115 when Attribute_Safe_Small
=>
3118 Set_Etype
(N
, Universal_Real
);
3124 when Attribute_Scale
=>
3126 Check_Decimal_Fixed_Point_Type
;
3127 Set_Etype
(N
, Universal_Integer
);
3133 when Attribute_Scaling
=>
3134 Check_Floating_Point_Type_2
;
3135 Set_Etype
(N
, P_Base_Type
);
3136 Resolve
(E1
, P_Base_Type
);
3142 when Attribute_Signed_Zeros
=>
3143 Check_Floating_Point_Type_0
;
3144 Set_Etype
(N
, Standard_Boolean
);
3150 when Attribute_Size | Attribute_VADS_Size
=>
3153 if Is_Object_Reference
(P
)
3154 or else (Is_Entity_Name
(P
)
3155 and then Ekind
(Entity
(P
)) = E_Function
)
3157 Check_Object_Reference
(P
);
3159 elsif Is_Entity_Name
(P
)
3160 and then Is_Type
(Entity
(P
))
3164 elsif Nkind
(P
) = N_Type_Conversion
3165 and then not Comes_From_Source
(P
)
3170 Error_Attr
("invalid prefix for % attribute", P
);
3173 Check_Not_Incomplete_Type
;
3174 Set_Etype
(N
, Universal_Integer
);
3180 when Attribute_Small
=>
3183 Set_Etype
(N
, Universal_Real
);
3189 when Attribute_Storage_Pool
=>
3190 if Is_Access_Type
(P_Type
) then
3193 -- Set appropriate entity
3195 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3196 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3198 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3201 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3203 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3204 -- Storage_Pool since this attribute is not defined for such
3205 -- types (RM E.2.3(22)).
3207 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3210 Error_Attr
("prefix of % attribute must be access type", P
);
3217 when Attribute_Storage_Size
=>
3219 if Is_Task_Type
(P_Type
) then
3221 Set_Etype
(N
, Universal_Integer
);
3223 elsif Is_Access_Type
(P_Type
) then
3224 if Is_Entity_Name
(P
)
3225 and then Is_Type
(Entity
(P
))
3229 Set_Etype
(N
, Universal_Integer
);
3231 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3232 -- Storage_Size since this attribute is not defined for
3233 -- such types (RM E.2.3(22)).
3235 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3237 -- The prefix is allowed to be an implicit dereference
3238 -- of an access value designating a task.
3243 Set_Etype
(N
, Universal_Integer
);
3248 ("prefix of % attribute must be access or task type", P
);
3255 when Attribute_Storage_Unit
=>
3256 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3262 when Attribute_Succ
=>
3265 Resolve
(E1
, P_Base_Type
);
3266 Set_Etype
(N
, P_Base_Type
);
3268 -- Nothing to do for real type case
3270 if Is_Real_Type
(P_Type
) then
3273 -- If not modular type, test for overflow check required.
3276 if not Is_Modular_Integer_Type
(P_Type
)
3277 and then not Range_Checks_Suppressed
(P_Base_Type
)
3279 Enable_Range_Check
(E1
);
3287 when Attribute_Tag
=>
3291 if not Is_Tagged_Type
(P_Type
) then
3292 Error_Attr
("prefix of % attribute must be tagged", P
);
3294 -- Next test does not apply to generated code
3295 -- why not, and what does the illegal reference mean???
3297 elsif Is_Object_Reference
(P
)
3298 and then not Is_Class_Wide_Type
(P_Type
)
3299 and then Comes_From_Source
(N
)
3302 ("% attribute can only be applied to objects of class-wide type",
3306 Set_Etype
(N
, RTE
(RE_Tag
));
3312 when Attribute_Terminated
=>
3314 Set_Etype
(N
, Standard_Boolean
);
3321 when Attribute_Tick
=>
3322 Check_Standard_Prefix
;
3324 Make_Real_Literal
(Loc
,
3325 UR_From_Components
(
3326 Num
=> UI_From_Int
(Ttypes
.System_Tick_Nanoseconds
),
3327 Den
=> UI_From_Int
(9),
3335 when Attribute_To_Address
=>
3339 if Nkind
(P
) /= N_Identifier
3340 or else Chars
(P
) /= Name_System
3342 Error_Attr
("prefix of %attribute must be System", P
);
3345 Generate_Reference
(RTE
(RE_Address
), P
);
3346 Analyze_And_Resolve
(E1
, Any_Integer
);
3347 Set_Etype
(N
, RTE
(RE_Address
));
3353 when Attribute_Truncation
=>
3354 Check_Floating_Point_Type_1
;
3355 Resolve
(E1
, P_Base_Type
);
3356 Set_Etype
(N
, P_Base_Type
);
3362 when Attribute_Type_Class
=>
3365 Check_Not_Incomplete_Type
;
3366 Set_Etype
(N
, RTE
(RE_Type_Class
));
3372 when Attribute_UET_Address
=>
3374 Check_Unit_Name
(P
);
3375 Set_Etype
(N
, RTE
(RE_Address
));
3377 -----------------------
3378 -- Unbiased_Rounding --
3379 -----------------------
3381 when Attribute_Unbiased_Rounding
=>
3382 Check_Floating_Point_Type_1
;
3383 Set_Etype
(N
, P_Base_Type
);
3384 Resolve
(E1
, P_Base_Type
);
3386 ----------------------
3387 -- Unchecked_Access --
3388 ----------------------
3390 when Attribute_Unchecked_Access
=>
3391 if Comes_From_Source
(N
) then
3392 Check_Restriction
(No_Unchecked_Access
, N
);
3397 ------------------------------
3398 -- Universal_Literal_String --
3399 ------------------------------
3401 -- This is a GNAT specific attribute whose prefix must be a named
3402 -- number where the expression is either a single numeric literal,
3403 -- or a numeric literal immediately preceded by a minus sign. The
3404 -- result is equivalent to a string literal containing the text of
3405 -- the literal as it appeared in the source program with a possible
3406 -- leading minus sign.
3408 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3412 if not Is_Entity_Name
(P
)
3413 or else Ekind
(Entity
(P
)) not in Named_Kind
3415 Error_Attr
("prefix for % attribute must be named number", P
);
3422 Src
: Source_Buffer_Ptr
;
3425 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3427 if Nkind
(Expr
) = N_Op_Minus
then
3429 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3434 if Nkind
(Expr
) /= N_Integer_Literal
3435 and then Nkind
(Expr
) /= N_Real_Literal
3438 ("named number for % attribute must be simple literal", N
);
3441 -- Build string literal corresponding to source literal text
3446 Store_String_Char
(Get_Char_Code
('-'));
3450 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3452 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3453 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3457 -- Now we rewrite the attribute with the string literal
3460 Make_String_Literal
(Loc
, End_String
));
3464 end Universal_Literal_String
;
3466 -------------------------
3467 -- Unrestricted_Access --
3468 -------------------------
3470 -- This is a GNAT specific attribute which is like Access except that
3471 -- all scope checks and checks for aliased views are omitted.
3473 when Attribute_Unrestricted_Access
=>
3474 if Comes_From_Source
(N
) then
3475 Check_Restriction
(No_Unchecked_Access
, N
);
3478 if Is_Entity_Name
(P
) then
3479 Set_Address_Taken
(Entity
(P
));
3488 when Attribute_Val
=> Val
: declare
3491 Check_Discrete_Type
;
3492 Resolve
(E1
, Any_Integer
);
3493 Set_Etype
(N
, P_Base_Type
);
3495 -- Note, we need a range check in general, but we wait for the
3496 -- Resolve call to do this, since we want to let Eval_Attribute
3497 -- have a chance to find an static illegality first!
3504 when Attribute_Valid
=>
3507 -- Ignore check for object if we have a 'Valid reference generated
3508 -- by the expanded code, since in some cases valid checks can occur
3509 -- on items that are names, but are not objects (e.g. attributes).
3511 if Comes_From_Source
(N
) then
3512 Check_Object_Reference
(P
);
3515 if not Is_Scalar_Type
(P_Type
) then
3516 Error_Attr
("object for % attribute must be of scalar type", P
);
3519 Set_Etype
(N
, Standard_Boolean
);
3525 when Attribute_Value
=> Value
:
3530 if Is_Enumeration_Type
(P_Type
) then
3531 Check_Restriction
(No_Enumeration_Maps
, N
);
3534 -- Set Etype before resolving expression because expansion
3535 -- of expression may require enclosing type.
3537 Set_Etype
(N
, P_Type
);
3538 Validate_Non_Static_Attribute_Function_Call
;
3545 when Attribute_Value_Size
=>
3548 Check_Not_Incomplete_Type
;
3549 Set_Etype
(N
, Universal_Integer
);
3555 when Attribute_Version
=>
3558 Set_Etype
(N
, RTE
(RE_Version_String
));
3564 when Attribute_Wchar_T_Size
=>
3565 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3571 when Attribute_Wide_Image
=> Wide_Image
:
3574 Set_Etype
(N
, Standard_Wide_String
);
3576 Resolve
(E1
, P_Base_Type
);
3577 Validate_Non_Static_Attribute_Function_Call
;
3584 when Attribute_Wide_Value
=> Wide_Value
:
3589 -- Set Etype before resolving expression because expansion
3590 -- of expression may require enclosing type.
3592 Set_Etype
(N
, P_Type
);
3593 Validate_Non_Static_Attribute_Function_Call
;
3600 when Attribute_Wide_Width
=>
3603 Set_Etype
(N
, Universal_Integer
);
3609 when Attribute_Width
=>
3612 Set_Etype
(N
, Universal_Integer
);
3618 when Attribute_Word_Size
=>
3619 Standard_Attribute
(System_Word_Size
);
3625 when Attribute_Write
=>
3627 Check_Stream_Attribute
(Name_uWrite
);
3628 Set_Etype
(N
, Standard_Void_Type
);
3629 Disallow_In_No_Run_Time_Mode
(N
);
3630 Resolve
(N
, Standard_Void_Type
);
3634 -- All errors raise Bad_Attribute, so that we get out before any further
3635 -- damage occurs when an error is detected (for example, if we check for
3636 -- one attribute expression, and the check succeeds, we want to be able
3637 -- to proceed securely assuming that an expression is in fact present.
3640 when Bad_Attribute
=>
3641 Set_Etype
(N
, Any_Type
);
3644 end Analyze_Attribute
;
3646 --------------------
3647 -- Eval_Attribute --
3648 --------------------
3650 procedure Eval_Attribute
(N
: Node_Id
) is
3651 Loc
: constant Source_Ptr
:= Sloc
(N
);
3652 Aname
: constant Name_Id
:= Attribute_Name
(N
);
3653 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
3654 P
: constant Node_Id
:= Prefix
(N
);
3656 C_Type
: constant Entity_Id
:= Etype
(N
);
3657 -- The type imposed by the context.
3660 -- First expression, or Empty if none
3663 -- Second expression, or Empty if none
3665 P_Entity
: Entity_Id
;
3666 -- Entity denoted by prefix
3669 -- The type of the prefix
3671 P_Base_Type
: Entity_Id
;
3672 -- The base type of the prefix type
3674 P_Root_Type
: Entity_Id
;
3675 -- The root type of the prefix type
3678 -- True if prefix type is static
3680 Lo_Bound
, Hi_Bound
: Node_Id
;
3681 -- Expressions for low and high bounds of type or array index referenced
3682 -- by First, Last, or Length attribute for array, set by Set_Bounds.
3685 -- Constraint error node used if we have an attribute reference has
3686 -- an argument that raises a constraint error. In this case we replace
3687 -- the attribute with a raise constraint_error node. This is important
3688 -- processing, since otherwise gigi might see an attribute which it is
3689 -- unprepared to deal with.
3691 function Aft_Value
return Nat
;
3692 -- Computes Aft value for current attribute prefix (used by Aft itself
3693 -- and also by Width for computing the Width of a fixed point type).
3695 procedure Check_Expressions
;
3696 -- In case where the attribute is not foldable, the expressions, if
3697 -- any, of the attribute, are in a non-static context. This procedure
3698 -- performs the required additional checks.
3700 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
3701 -- This procedure is called when the attribute N has a non-static
3702 -- but compile time known value given by Val. It includes the
3703 -- necessary checks for out of range values.
3705 procedure Float_Attribute_Universal_Integer
3712 -- This procedure evaluates a float attribute with no arguments that
3713 -- returns a universal integer result. The parameters give the values
3714 -- for the possible floating-point root types. See ttypef for details.
3715 -- The prefix type is a float type (and is thus not a generic type).
3717 procedure Float_Attribute_Universal_Real
3718 (IEEES_Val
: String;
3723 VAXGF_Val
: String);
3724 -- This procedure evaluates a float attribute with no arguments that
3725 -- returns a universal real result. The parameters give the values
3726 -- required for the possible floating-point root types in string
3727 -- format as real literals with a possible leading minus sign.
3728 -- The prefix type is a float type (and is thus not a generic type).
3730 function Fore_Value
return Nat
;
3731 -- Computes the Fore value for the current attribute prefix, which is
3732 -- known to be a static fixed-point type. Used by Fore and Width.
3734 function Mantissa
return Uint
;
3735 -- Returns the Mantissa value for the prefix type
3737 procedure Set_Bounds
;
3738 -- Used for First, Last and Length attributes applied to an array or
3739 -- array subtype. Sets the variables Index_Lo and Index_Hi to the low
3740 -- and high bound expressions for the index referenced by the attribute
3741 -- designator (i.e. the first index if no expression is present, and
3742 -- the N'th index if the value N is present as an expression). Also
3743 -- used for First and Last of scalar types.
3749 function Aft_Value
return Nat
is
3755 Delta_Val
:= Delta_Value
(P_Type
);
3757 while Delta_Val
< Ureal_Tenth
loop
3758 Delta_Val
:= Delta_Val
* Ureal_10
;
3759 Result
:= Result
+ 1;
3765 -----------------------
3766 -- Check_Expressions --
3767 -----------------------
3769 procedure Check_Expressions
is
3773 while Present
(E
) loop
3774 Check_Non_Static_Context
(E
);
3777 end Check_Expressions
;
3779 ----------------------------------
3780 -- Compile_Time_Known_Attribute --
3781 ----------------------------------
3783 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
3784 T
: constant Entity_Id
:= Etype
(N
);
3788 Set_Is_Static_Expression
(N
, False);
3790 -- Check that result is in bounds of the type if it is static
3792 if Is_In_Range
(N
, T
) then
3795 elsif Is_Out_Of_Range
(N
, T
) then
3796 Apply_Compile_Time_Constraint_Error
3797 (N
, "value not in range of}?");
3799 elsif not Range_Checks_Suppressed
(T
) then
3800 Enable_Range_Check
(N
);
3803 Set_Do_Range_Check
(N
, False);
3805 end Compile_Time_Known_Attribute
;
3807 ---------------------------------------
3808 -- Float_Attribute_Universal_Integer --
3809 ---------------------------------------
3811 procedure Float_Attribute_Universal_Integer
3820 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3823 if not Vax_Float
(P_Base_Type
) then
3824 if Digs
= IEEES_Digits
then
3826 elsif Digs
= IEEEL_Digits
then
3828 else pragma Assert
(Digs
= IEEEX_Digits
);
3833 if Digs
= VAXFF_Digits
then
3835 elsif Digs
= VAXDF_Digits
then
3837 else pragma Assert
(Digs
= VAXGF_Digits
);
3842 Fold_Uint
(N
, UI_From_Int
(Val
));
3843 end Float_Attribute_Universal_Integer
;
3845 ------------------------------------
3846 -- Float_Attribute_Universal_Real --
3847 ------------------------------------
3849 procedure Float_Attribute_Universal_Real
3850 (IEEES_Val
: String;
3858 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3861 if not Vax_Float
(P_Base_Type
) then
3862 if Digs
= IEEES_Digits
then
3863 Val
:= Real_Convert
(IEEES_Val
);
3864 elsif Digs
= IEEEL_Digits
then
3865 Val
:= Real_Convert
(IEEEL_Val
);
3866 else pragma Assert
(Digs
= IEEEX_Digits
);
3867 Val
:= Real_Convert
(IEEEX_Val
);
3871 if Digs
= VAXFF_Digits
then
3872 Val
:= Real_Convert
(VAXFF_Val
);
3873 elsif Digs
= VAXDF_Digits
then
3874 Val
:= Real_Convert
(VAXDF_Val
);
3875 else pragma Assert
(Digs
= VAXGF_Digits
);
3876 Val
:= Real_Convert
(VAXGF_Val
);
3880 Set_Sloc
(Val
, Loc
);
3882 Analyze_And_Resolve
(N
, C_Type
);
3883 end Float_Attribute_Universal_Real
;
3889 -- Note that the Fore calculation is based on the actual values
3890 -- of the bounds, and does not take into account possible rounding.
3892 function Fore_Value
return Nat
is
3893 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
3894 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
3895 Small
: constant Ureal
:= Small_Value
(P_Type
);
3896 Lo_Real
: constant Ureal
:= Lo
* Small
;
3897 Hi_Real
: constant Ureal
:= Hi
* Small
;
3902 -- Bounds are given in terms of small units, so first compute
3903 -- proper values as reals.
3905 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
3908 -- Loop to compute proper value if more than one digit required
3910 while T
>= Ureal_10
loop
3922 -- Table of mantissa values accessed by function Computed using
3925 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
3927 -- where D is T'Digits (RM83 3.5.7)
3929 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
3971 function Mantissa
return Uint
is
3974 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
3981 procedure Set_Bounds
is
3987 -- For a string literal subtype, we have to construct the bounds.
3988 -- Valid Ada code never applies attributes to string literals, but
3989 -- it is convenient to allow the expander to generate attribute
3990 -- references of this type (e.g. First and Last applied to a string
3993 -- Note that the whole point of the E_String_Literal_Subtype is to
3994 -- avoid this construction of bounds, but the cases in which we
3995 -- have to materialize them are rare enough that we don't worry!
3997 -- The low bound is simply the low bound of the base type. The
3998 -- high bound is computed from the length of the string and this
4001 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4003 Type_Low_Bound
(Etype
(First_Index
(Base_Type
(P_Type
))));
4006 Make_Integer_Literal
(Sloc
(P
),
4008 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4010 Set_Parent
(Hi_Bound
, P
);
4011 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4014 -- For non-array case, just get bounds of scalar type
4016 elsif Is_Scalar_Type
(P_Type
) then
4019 if Is_Fixed_Point_Type
(P_Type
)
4020 and then not Is_Frozen
(Base_Type
(P_Type
))
4021 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4022 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4024 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4027 -- For array case, get type of proper index
4033 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4036 Indx
:= First_Index
(P_Type
);
4037 for J
in 1 .. Ndim
- 1 loop
4041 -- If no index type, get out (some other error occurred, and
4042 -- we don't have enough information to complete the job!)
4050 Ityp
:= Etype
(Indx
);
4053 -- A discrete range in an index constraint is allowed to be a
4054 -- subtype indication. This is syntactically a pain, but should
4055 -- not propagate to the entity for the corresponding index subtype.
4056 -- After checking that the subtype indication is legal, the range
4057 -- of the subtype indication should be transfered to the entity.
4058 -- The attributes for the bounds should remain the simple retrievals
4059 -- that they are now.
4061 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4062 Hi_Bound
:= Type_High_Bound
(Ityp
);
4066 -- Start of processing for Eval_Attribute
4069 -- Acquire first two expressions (at the moment, no attributes
4070 -- take more than two expressions in any case).
4072 if Present
(Expressions
(N
)) then
4073 E1
:= First
(Expressions
(N
));
4080 -- Special processing for cases where the prefix is an object
4082 if Is_Object_Reference
(P
) then
4084 -- For Component_Size, the prefix is an array object, and we apply
4085 -- the attribute to the type of the object. This is allowed for
4086 -- both unconstrained and constrained arrays, since the bounds
4087 -- have no influence on the value of this attribute.
4089 if Id
= Attribute_Component_Size
then
4090 P_Entity
:= Etype
(P
);
4092 -- For First and Last, the prefix is an array object, and we apply
4093 -- the attribute to the type of the array, but we need a constrained
4094 -- type for this, so we use the actual subtype if available.
4096 elsif Id
= Attribute_First
4100 Id
= Attribute_Length
4103 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4106 if Present
(AS
) then
4109 -- If no actual subtype, cannot fold
4117 -- For Size, give size of object if available, otherwise we
4118 -- cannot fold Size.
4120 elsif Id
= Attribute_Size
then
4122 if Is_Entity_Name
(P
)
4123 and then Known_Esize
(Entity
(P
))
4125 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4133 -- For Alignment, give size of object if available, otherwise we
4134 -- cannot fold Alignment.
4136 elsif Id
= Attribute_Alignment
then
4138 if Is_Entity_Name
(P
)
4139 and then Known_Alignment
(Entity
(P
))
4141 Fold_Uint
(N
, Alignment
(Entity
(P
)));
4142 Set_Is_Static_Expression
(N
, False);
4150 -- No other attributes for objects are folded
4157 -- Cases where P is not an object. Cannot do anything if P is
4158 -- not the name of an entity.
4160 elsif not Is_Entity_Name
(P
) then
4164 -- Otherwise get prefix entity
4167 P_Entity
:= Entity
(P
);
4170 -- At this stage P_Entity is the entity to which the attribute
4171 -- is to be applied. This is usually simply the entity of the
4172 -- prefix, except in some cases of attributes for objects, where
4173 -- as described above, we apply the attribute to the object type.
4175 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4176 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4177 -- Note we allow non-static non-generic types at this stage as further
4180 if Is_Type
(P_Entity
)
4181 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4182 and then (not Is_Generic_Type
(P_Entity
))
4186 -- Second foldable possibility is an array object (RM 4.9(8))
4188 elsif (Ekind
(P_Entity
) = E_Variable
4190 Ekind
(P_Entity
) = E_Constant
)
4191 and then Is_Array_Type
(Etype
(P_Entity
))
4192 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4194 P_Type
:= Etype
(P_Entity
);
4196 -- If the entity is an array constant with an unconstrained
4197 -- nominal subtype then get the type from the initial value.
4198 -- If the value has been expanded into assignments, the expression
4199 -- is not present and the attribute reference remains dynamic.
4200 -- We could do better here and retrieve the type ???
4202 if Ekind
(P_Entity
) = E_Constant
4203 and then not Is_Constrained
(P_Type
)
4205 if No
(Constant_Value
(P_Entity
)) then
4208 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4212 -- Definite must be folded if the prefix is not a generic type,
4213 -- that is to say if we are within an instantiation. Same processing
4214 -- applies to the GNAT attributes Has_Discriminants and Type_Class
4216 elsif (Id
= Attribute_Definite
4218 Id
= Attribute_Has_Discriminants
4220 Id
= Attribute_Type_Class
)
4221 and then not Is_Generic_Type
(P_Entity
)
4225 -- We can fold 'Size applied to a type if the size is known
4226 -- (as happens for a size from an attribute definition clause).
4227 -- At this stage, this can happen only for types (e.g. record
4228 -- types) for which the size is always non-static. We exclude
4229 -- generic types from consideration (since they have bogus
4230 -- sizes set within templates).
4232 elsif Id
= Attribute_Size
4233 and then Is_Type
(P_Entity
)
4234 and then (not Is_Generic_Type
(P_Entity
))
4235 and then Known_Static_RM_Size
(P_Entity
)
4237 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4240 -- No other cases are foldable (they certainly aren't static, and at
4241 -- the moment we don't try to fold any cases other than the two above)
4248 -- If either attribute or the prefix is Any_Type, then propagate
4249 -- Any_Type to the result and don't do anything else at all.
4251 if P_Type
= Any_Type
4252 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4253 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4255 Set_Etype
(N
, Any_Type
);
4259 -- Scalar subtype case. We have not yet enforced the static requirement
4260 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4261 -- of non-static attribute references (e.g. S'Digits for a non-static
4262 -- floating-point type, which we can compute at compile time).
4264 -- Note: this folding of non-static attributes is not simply a case of
4265 -- optimization. For many of the attributes affected, Gigi cannot handle
4266 -- the attribute and depends on the front end having folded them away.
4268 -- Note: although we don't require staticness at this stage, we do set
4269 -- the Static variable to record the staticness, for easy reference by
4270 -- those attributes where it matters (e.g. Succ and Pred), and also to
4271 -- be used to ensure that non-static folded things are not marked as
4272 -- being static (a check that is done right at the end).
4274 P_Root_Type
:= Root_Type
(P_Type
);
4275 P_Base_Type
:= Base_Type
(P_Type
);
4277 -- If the root type or base type is generic, then we cannot fold. This
4278 -- test is needed because subtypes of generic types are not always
4279 -- marked as being generic themselves (which seems odd???)
4281 if Is_Generic_Type
(P_Root_Type
)
4282 or else Is_Generic_Type
(P_Base_Type
)
4287 if Is_Scalar_Type
(P_Type
) then
4288 Static
:= Is_OK_Static_Subtype
(P_Type
);
4290 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4291 -- since we can't do anything with unconstrained arrays. In addition,
4292 -- only the First, Last and Length attributes are possibly static.
4293 -- In addition Component_Size is possibly foldable, even though it
4294 -- can never be static.
4296 -- Definite, Has_Discriminants and Type_Class are again exceptions,
4297 -- because they apply as well to unconstrained types.
4299 elsif Id
= Attribute_Definite
4301 Id
= Attribute_Has_Discriminants
4303 Id
= Attribute_Type_Class
4308 if not Is_Constrained
(P_Type
)
4309 or else (Id
/= Attribute_Component_Size
and then
4310 Id
/= Attribute_First
and then
4311 Id
/= Attribute_Last
and then
4312 Id
/= Attribute_Length
)
4318 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4319 -- scalar case, we hold off on enforcing staticness, since there are
4320 -- cases which we can fold at compile time even though they are not
4321 -- static (e.g. 'Length applied to a static index, even though other
4322 -- non-static indexes make the array type non-static). This is only
4323 -- ab optimization, but it falls out essentially free, so why not.
4324 -- Again we compute the variable Static for easy reference later
4325 -- (note that no array attributes are static in Ada 83).
4333 N
:= First_Index
(P_Type
);
4334 while Present
(N
) loop
4335 Static
:= Static
and Is_Static_Subtype
(Etype
(N
));
4341 -- Check any expressions that are present. Note that these expressions,
4342 -- depending on the particular attribute type, are either part of the
4343 -- attribute designator, or they are arguments in a case where the
4344 -- attribute reference returns a function. In the latter case, the
4345 -- rule in (RM 4.9(22)) applies and in particular requires the type
4346 -- of the expressions to be scalar in order for the attribute to be
4347 -- considered to be static.
4354 while Present
(E
) loop
4356 -- If expression is not static, then the attribute reference
4357 -- certainly is neither foldable nor static, so we can quit
4358 -- after calling Apply_Range_Check for 'Pos attributes.
4360 -- We can also quit if the expression is not of a scalar type
4363 if not Is_Static_Expression
(E
)
4364 or else not Is_Scalar_Type
(Etype
(E
))
4366 if Id
= Attribute_Pos
then
4367 if Is_Integer_Type
(Etype
(E
)) then
4368 Apply_Range_Check
(E
, Etype
(N
));
4375 -- If the expression raises a constraint error, then so does
4376 -- the attribute reference. We keep going in this case because
4377 -- we are still interested in whether the attribute reference
4378 -- is static even if it is not static.
4380 elsif Raises_Constraint_Error
(E
) then
4381 Set_Raises_Constraint_Error
(N
);
4387 if Raises_Constraint_Error
(Prefix
(N
)) then
4392 -- Deal with the case of a static attribute reference that raises
4393 -- constraint error. The Raises_Constraint_Error flag will already
4394 -- have been set, and the Static flag shows whether the attribute
4395 -- reference is static. In any case we certainly can't fold such an
4396 -- attribute reference.
4398 -- Note that the rewriting of the attribute node with the constraint
4399 -- error node is essential in this case, because otherwise Gigi might
4400 -- blow up on one of the attributes it never expects to see.
4402 -- The constraint_error node must have the type imposed by the context,
4403 -- to avoid spurious errors in the enclosing expression.
4405 if Raises_Constraint_Error
(N
) then
4407 Make_Raise_Constraint_Error
(Sloc
(N
));
4408 Set_Etype
(CE_Node
, Etype
(N
));
4409 Set_Raises_Constraint_Error
(CE_Node
);
4411 Rewrite
(N
, Relocate_Node
(CE_Node
));
4412 Set_Is_Static_Expression
(N
, Static
);
4416 -- At this point we have a potentially foldable attribute reference.
4417 -- If Static is set, then the attribute reference definitely obeys
4418 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4419 -- folded. If Static is not set, then the attribute may or may not
4420 -- be foldable, and the individual attribute processing routines
4421 -- test Static as required in cases where it makes a difference.
4429 when Attribute_Adjacent
=>
4433 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4440 when Attribute_Aft
=>
4441 Fold_Uint
(N
, UI_From_Int
(Aft_Value
));
4447 when Attribute_Alignment
=> Alignment_Block
: declare
4448 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4451 -- Fold if alignment is set and not otherwise
4453 if Known_Alignment
(P_TypeA
) then
4454 Fold_Uint
(N
, Alignment
(P_TypeA
));
4456 end Alignment_Block
;
4462 -- Can only be folded in No_Ast_Handler case
4464 when Attribute_AST_Entry
=>
4465 if not Is_AST_Entry
(P_Entity
) then
4467 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
4476 -- Bit can never be folded
4478 when Attribute_Bit
=>
4485 -- Body_version can never be static
4487 when Attribute_Body_Version
=>
4494 when Attribute_Ceiling
=>
4497 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)));
4500 --------------------
4501 -- Component_Size --
4502 --------------------
4504 when Attribute_Component_Size
=>
4505 if Component_Size
(P_Type
) /= 0 then
4506 Fold_Uint
(N
, Component_Size
(P_Type
));
4513 when Attribute_Compose
=>
4517 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4524 -- Constrained is never folded for now, there may be cases that
4525 -- could be handled at compile time. to be looked at later.
4527 when Attribute_Constrained
=>
4534 when Attribute_Copy_Sign
=>
4538 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4545 when Attribute_Delta
=>
4546 Fold_Ureal
(N
, Delta_Value
(P_Type
));
4552 when Attribute_Definite
=>
4557 if Is_Indefinite_Subtype
(P_Entity
) then
4558 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4560 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4563 Rewrite
(N
, Result
);
4564 Analyze_And_Resolve
(N
, Standard_Boolean
);
4571 when Attribute_Denorm
=>
4573 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)));
4579 when Attribute_Digits
=>
4580 Fold_Uint
(N
, Digits_Value
(P_Type
));
4586 when Attribute_Emax
=>
4588 -- Ada 83 attribute is defined as (RM83 3.5.8)
4590 -- T'Emax = 4 * T'Mantissa
4592 Fold_Uint
(N
, 4 * Mantissa
);
4598 when Attribute_Enum_Rep
=>
4601 -- For an enumeration type with a non-standard representation
4602 -- use the Enumeration_Rep field of the proper constant. Note
4603 -- that this would not work for types Character/Wide_Character,
4604 -- since no real entities are created for the enumeration
4605 -- literals, but that does not matter since these two types
4606 -- do not have non-standard representations anyway.
4608 if Is_Enumeration_Type
(P_Type
)
4609 and then Has_Non_Standard_Rep
(P_Type
)
4611 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)));
4613 -- For enumeration types with standard representations and all
4614 -- other cases (i.e. all integer and modular types), Enum_Rep
4615 -- is equivalent to Pos.
4618 Fold_Uint
(N
, Expr_Value
(E1
));
4626 when Attribute_Epsilon
=>
4628 -- Ada 83 attribute is defined as (RM83 3.5.8)
4630 -- T'Epsilon = 2.0**(1 - T'Mantissa)
4632 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
));
4638 when Attribute_Exponent
=>
4641 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)));
4648 when Attribute_First
=> First_Attr
:
4652 if Compile_Time_Known_Value
(Lo_Bound
) then
4653 if Is_Real_Type
(P_Type
) then
4654 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
));
4656 Fold_Uint
(N
, Expr_Value
(Lo_Bound
));
4665 when Attribute_Fixed_Value
=>
4672 when Attribute_Floor
=>
4675 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)));
4682 when Attribute_Fore
=>
4684 Fold_Uint
(N
, UI_From_Int
(Fore_Value
));
4691 when Attribute_Fraction
=>
4694 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)));
4697 -----------------------
4698 -- Has_Discriminants --
4699 -----------------------
4701 when Attribute_Has_Discriminants
=>
4706 if Has_Discriminants
(P_Entity
) then
4707 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4709 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4712 Rewrite
(N
, Result
);
4713 Analyze_And_Resolve
(N
, Standard_Boolean
);
4720 when Attribute_Identity
=>
4727 -- Image is a scalar attribute, but is never static, because it is
4728 -- not a static function (having a non-scalar argument (RM 4.9(22))
4730 when Attribute_Image
=>
4737 -- Img is a scalar attribute, but is never static, because it is
4738 -- not a static function (having a non-scalar argument (RM 4.9(22))
4740 when Attribute_Img
=>
4747 when Attribute_Integer_Value
=>
4754 when Attribute_Large
=>
4756 -- For fixed-point, we use the identity:
4758 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
4760 if Is_Fixed_Point_Type
(P_Type
) then
4762 Make_Op_Multiply
(Loc
,
4764 Make_Op_Subtract
(Loc
,
4768 Make_Real_Literal
(Loc
, Ureal_2
),
4770 Make_Attribute_Reference
(Loc
,
4772 Attribute_Name
=> Name_Mantissa
)),
4773 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
4776 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
4778 Analyze_And_Resolve
(N
, C_Type
);
4780 -- Floating-point (Ada 83 compatibility)
4783 -- Ada 83 attribute is defined as (RM83 3.5.8)
4785 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
4789 -- T'Emax = 4 * T'Mantissa
4792 Ureal_2
** (4 * Mantissa
) *
4793 (Ureal_1
- Ureal_2
** (-Mantissa
)));
4800 when Attribute_Last
=> Last
:
4804 if Compile_Time_Known_Value
(Hi_Bound
) then
4805 if Is_Real_Type
(P_Type
) then
4806 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
));
4808 Fold_Uint
(N
, Expr_Value
(Hi_Bound
));
4817 when Attribute_Leading_Part
=>
4820 Eval_Fat
.Leading_Part
4821 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4828 when Attribute_Length
=> Length
:
4832 if Compile_Time_Known_Value
(Lo_Bound
)
4833 and then Compile_Time_Known_Value
(Hi_Bound
)
4836 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))));
4844 when Attribute_Machine
=>
4847 Eval_Fat
.Machine
(P_Root_Type
, Expr_Value_R
(E1
),
4855 when Attribute_Machine_Emax
=>
4856 Float_Attribute_Universal_Integer
(
4862 VAXGF_Machine_Emax
);
4868 when Attribute_Machine_Emin
=>
4869 Float_Attribute_Universal_Integer
(
4875 VAXGF_Machine_Emin
);
4877 ----------------------
4878 -- Machine_Mantissa --
4879 ----------------------
4881 when Attribute_Machine_Mantissa
=>
4882 Float_Attribute_Universal_Integer
(
4883 IEEES_Machine_Mantissa
,
4884 IEEEL_Machine_Mantissa
,
4885 IEEEX_Machine_Mantissa
,
4886 VAXFF_Machine_Mantissa
,
4887 VAXDF_Machine_Mantissa
,
4888 VAXGF_Machine_Mantissa
);
4890 -----------------------
4891 -- Machine_Overflows --
4892 -----------------------
4894 when Attribute_Machine_Overflows
=>
4896 -- Always true for fixed-point
4898 if Is_Fixed_Point_Type
(P_Type
) then
4899 Fold_Uint
(N
, True_Value
);
4901 -- Floating point case
4905 (N
, UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)));
4912 when Attribute_Machine_Radix
=>
4913 if Is_Fixed_Point_Type
(P_Type
) then
4914 if Is_Decimal_Fixed_Point_Type
(P_Type
)
4915 and then Machine_Radix_10
(P_Type
)
4917 Fold_Uint
(N
, Uint_10
);
4919 Fold_Uint
(N
, Uint_2
);
4922 -- All floating-point type always have radix 2
4925 Fold_Uint
(N
, Uint_2
);
4928 --------------------
4929 -- Machine_Rounds --
4930 --------------------
4932 when Attribute_Machine_Rounds
=>
4934 -- Always False for fixed-point
4936 if Is_Fixed_Point_Type
(P_Type
) then
4937 Fold_Uint
(N
, False_Value
);
4939 -- Else yield proper floating-point result
4943 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)));
4950 -- Note: Machine_Size is identical to Object_Size
4952 when Attribute_Machine_Size
=> Machine_Size
: declare
4953 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4956 if Known_Esize
(P_TypeA
) then
4957 Fold_Uint
(N
, Esize
(P_TypeA
));
4965 when Attribute_Mantissa
=>
4967 -- Fixed-point mantissa
4969 if Is_Fixed_Point_Type
(P_Type
) then
4971 -- Compile time foldable case
4973 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4975 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4977 -- The calculation of the obsolete Ada 83 attribute Mantissa
4978 -- is annoying, because of AI00143, quoted here:
4980 -- !question 84-01-10
4982 -- Consider the model numbers for F:
4984 -- type F is delta 1.0 range -7.0 .. 8.0;
4986 -- The wording requires that F'MANTISSA be the SMALLEST
4987 -- integer number for which each bound of the specified
4988 -- range is either a model number or lies at most small
4989 -- distant from a model number. This means F'MANTISSA
4990 -- is required to be 3 since the range -7.0 .. 7.0 fits
4991 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
4992 -- number, namely, 7. Is this analysis correct? Note that
4993 -- this implies the upper bound of the range is not
4994 -- represented as a model number.
4996 -- !response 84-03-17
4998 -- The analysis is correct. The upper and lower bounds for
4999 -- a fixed point type can lie outside the range of model
5010 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5011 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5012 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5013 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5015 -- If the Bound is exactly a model number, i.e. a multiple
5016 -- of Small, then we back it off by one to get the integer
5017 -- value that must be representable.
5019 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5020 Max_Man
:= Max_Man
- 1;
5023 -- Now find corresponding size = Mantissa value
5026 while 2 ** Siz
< Max_Man
loop
5034 -- The case of dynamic bounds cannot be evaluated at compile
5035 -- time. Instead we use a runtime routine (see Exp_Attr).
5040 -- Floating-point Mantissa
5043 Fold_Uint
(N
, Mantissa
);
5050 when Attribute_Max
=> Max
:
5052 if Is_Real_Type
(P_Type
) then
5053 Fold_Ureal
(N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5055 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)));
5059 ----------------------------------
5060 -- Max_Size_In_Storage_Elements --
5061 ----------------------------------
5063 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5064 -- Storage_Unit boundary. We can fold any cases for which the size
5065 -- is known by the front end.
5067 when Attribute_Max_Size_In_Storage_Elements
=>
5068 if Known_Esize
(P_Type
) then
5070 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5071 System_Storage_Unit
);
5074 --------------------
5075 -- Mechanism_Code --
5076 --------------------
5078 when Attribute_Mechanism_Code
=>
5082 Mech
: Mechanism_Type
;
5086 Mech
:= Mechanism
(P_Entity
);
5089 Val
:= UI_To_Int
(Expr_Value
(E1
));
5091 Formal
:= First_Formal
(P_Entity
);
5092 for J
in 1 .. Val
- 1 loop
5093 Next_Formal
(Formal
);
5095 Mech
:= Mechanism
(Formal
);
5099 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)));
5107 when Attribute_Min
=> Min
:
5109 if Is_Real_Type
(P_Type
) then
5110 Fold_Ureal
(N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5112 Fold_Uint
(N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)));
5120 when Attribute_Model
=>
5123 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)));
5130 when Attribute_Model_Emin
=>
5131 Float_Attribute_Universal_Integer
(
5143 when Attribute_Model_Epsilon
=>
5144 Float_Attribute_Universal_Real
(
5145 IEEES_Model_Epsilon
'Universal_Literal_String,
5146 IEEEL_Model_Epsilon
'Universal_Literal_String,
5147 IEEEX_Model_Epsilon
'Universal_Literal_String,
5148 VAXFF_Model_Epsilon
'Universal_Literal_String,
5149 VAXDF_Model_Epsilon
'Universal_Literal_String,
5150 VAXGF_Model_Epsilon
'Universal_Literal_String);
5152 --------------------
5153 -- Model_Mantissa --
5154 --------------------
5156 when Attribute_Model_Mantissa
=>
5157 Float_Attribute_Universal_Integer
(
5158 IEEES_Model_Mantissa
,
5159 IEEEL_Model_Mantissa
,
5160 IEEEX_Model_Mantissa
,
5161 VAXFF_Model_Mantissa
,
5162 VAXDF_Model_Mantissa
,
5163 VAXGF_Model_Mantissa
);
5169 when Attribute_Model_Small
=>
5170 Float_Attribute_Universal_Real
(
5171 IEEES_Model_Small
'Universal_Literal_String,
5172 IEEEL_Model_Small
'Universal_Literal_String,
5173 IEEEX_Model_Small
'Universal_Literal_String,
5174 VAXFF_Model_Small
'Universal_Literal_String,
5175 VAXDF_Model_Small
'Universal_Literal_String,
5176 VAXGF_Model_Small
'Universal_Literal_String);
5182 when Attribute_Modulus
=>
5183 Fold_Uint
(N
, Modulus
(P_Type
));
5185 --------------------
5186 -- Null_Parameter --
5187 --------------------
5189 -- Cannot fold, we know the value sort of, but the whole point is
5190 -- that there is no way to talk about this imaginary value except
5191 -- by using the attribute, so we leave it the way it is.
5193 when Attribute_Null_Parameter
=>
5200 -- The Object_Size attribute for a type returns the Esize of the
5201 -- type and can be folded if this value is known.
5203 when Attribute_Object_Size
=> Object_Size
: declare
5204 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5207 if Known_Esize
(P_TypeA
) then
5208 Fold_Uint
(N
, Esize
(P_TypeA
));
5212 -------------------------
5213 -- Passed_By_Reference --
5214 -------------------------
5216 -- Scalar types are never passed by reference
5218 when Attribute_Passed_By_Reference
=>
5219 Fold_Uint
(N
, False_Value
);
5225 when Attribute_Pos
=>
5226 Fold_Uint
(N
, Expr_Value
(E1
));
5232 when Attribute_Pred
=> Pred
:
5236 -- Floating-point case. For now, do not fold this, since we
5237 -- don't know how to do it right (see fixed bug 3512-001 ???)
5239 if Is_Floating_Point_Type
(P_Type
) then
5241 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)));
5245 elsif Is_Fixed_Point_Type
(P_Type
) then
5247 Expr_Value_R
(E1
) - Small_Value
(P_Type
));
5249 -- Modular integer case (wraps)
5251 elsif Is_Modular_Integer_Type
(P_Type
) then
5252 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
));
5254 -- Other scalar cases
5257 pragma Assert
(Is_Scalar_Type
(P_Type
));
5259 if Is_Enumeration_Type
(P_Type
)
5260 and then Expr_Value
(E1
) =
5261 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5263 Apply_Compile_Time_Constraint_Error
5264 (N
, "Pred of type''First");
5269 Fold_Uint
(N
, Expr_Value
(E1
) - 1);
5278 -- No processing required, because by this stage, Range has been
5279 -- replaced by First .. Last, so this branch can never be taken.
5281 when Attribute_Range
=>
5282 raise Program_Error
;
5288 when Attribute_Range_Length
=>
5291 if Compile_Time_Known_Value
(Hi_Bound
)
5292 and then Compile_Time_Known_Value
(Lo_Bound
)
5296 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1));
5303 when Attribute_Remainder
=>
5307 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5314 when Attribute_Round
=> Round
:
5321 -- First we get the (exact result) in units of small
5323 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5325 -- Now round that exactly to an integer
5327 Si
:= UR_To_Uint
(Sr
);
5329 -- Finally the result is obtained by converting back to real
5331 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
));
5339 when Attribute_Rounding
=>
5342 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5349 when Attribute_Safe_Emax
=>
5350 Float_Attribute_Universal_Integer
(
5362 when Attribute_Safe_First
=>
5363 Float_Attribute_Universal_Real
(
5364 IEEES_Safe_First
'Universal_Literal_String,
5365 IEEEL_Safe_First
'Universal_Literal_String,
5366 IEEEX_Safe_First
'Universal_Literal_String,
5367 VAXFF_Safe_First
'Universal_Literal_String,
5368 VAXDF_Safe_First
'Universal_Literal_String,
5369 VAXGF_Safe_First
'Universal_Literal_String);
5375 when Attribute_Safe_Large
=>
5376 if Is_Fixed_Point_Type
(P_Type
) then
5377 Fold_Ureal
(N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)));
5379 Float_Attribute_Universal_Real
(
5380 IEEES_Safe_Large
'Universal_Literal_String,
5381 IEEEL_Safe_Large
'Universal_Literal_String,
5382 IEEEX_Safe_Large
'Universal_Literal_String,
5383 VAXFF_Safe_Large
'Universal_Literal_String,
5384 VAXDF_Safe_Large
'Universal_Literal_String,
5385 VAXGF_Safe_Large
'Universal_Literal_String);
5392 when Attribute_Safe_Last
=>
5393 Float_Attribute_Universal_Real
(
5394 IEEES_Safe_Last
'Universal_Literal_String,
5395 IEEEL_Safe_Last
'Universal_Literal_String,
5396 IEEEX_Safe_Last
'Universal_Literal_String,
5397 VAXFF_Safe_Last
'Universal_Literal_String,
5398 VAXDF_Safe_Last
'Universal_Literal_String,
5399 VAXGF_Safe_Last
'Universal_Literal_String);
5405 when Attribute_Safe_Small
=>
5407 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5408 -- for fixed-point, since is the same as Small, but we implement
5409 -- it for backwards compatibility.
5411 if Is_Fixed_Point_Type
(P_Type
) then
5412 Fold_Ureal
(N
, Small_Value
(P_Type
));
5414 -- Ada 83 Safe_Small for floating-point cases
5417 Float_Attribute_Universal_Real
(
5418 IEEES_Safe_Small
'Universal_Literal_String,
5419 IEEEL_Safe_Small
'Universal_Literal_String,
5420 IEEEX_Safe_Small
'Universal_Literal_String,
5421 VAXFF_Safe_Small
'Universal_Literal_String,
5422 VAXDF_Safe_Small
'Universal_Literal_String,
5423 VAXGF_Safe_Small
'Universal_Literal_String);
5430 when Attribute_Scale
=>
5431 Fold_Uint
(N
, Scale_Value
(P_Type
));
5437 when Attribute_Scaling
=>
5441 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
5448 when Attribute_Signed_Zeros
=>
5450 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)));
5456 -- Size attribute returns the RM size. All scalar types can be folded,
5457 -- as well as any types for which the size is known by the front end,
5458 -- including any type for which a size attribute is specified.
5460 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
5461 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5464 if RM_Size
(P_TypeA
) /= Uint_0
then
5468 if (Id
= Attribute_VADS_Size
or else Use_VADS_Size
) then
5471 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
5474 -- If a size clause applies, then use the size from it.
5475 -- This is one of the rare cases where we can use the
5476 -- Size_Clause field for a subtype when Has_Size_Clause
5477 -- is False. Consider:
5479 -- type x is range 1 .. 64;
5480 -- for x'size use 12;
5481 -- subtype y is x range 0 .. 3;
5483 -- Here y has a size clause inherited from x, but normally
5484 -- it does not apply, and y'size is 2. However, y'VADS_Size
5485 -- is indeed 12 and not 2.
5488 and then Is_OK_Static_Expression
(Expression
(S
))
5490 Fold_Uint
(N
, Expr_Value
(Expression
(S
)));
5492 -- If no size is specified, then we simply use the object
5493 -- size in the VADS_Size case (e.g. Natural'Size is equal
5494 -- to Integer'Size, not one less).
5497 Fold_Uint
(N
, Esize
(P_TypeA
));
5501 -- Normal case (Size) in which case we want the RM_Size
5504 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5513 when Attribute_Small
=>
5515 -- The floating-point case is present only for Ada 83 compatibility.
5516 -- Note that strictly this is an illegal addition, since we are
5517 -- extending an Ada 95 defined attribute, but we anticipate an
5518 -- ARG ruling that will permit this.
5520 if Is_Floating_Point_Type
(P_Type
) then
5522 -- Ada 83 attribute is defined as (RM83 3.5.8)
5524 -- T'Small = 2.0**(-T'Emax - 1)
5528 -- T'Emax = 4 * T'Mantissa
5530 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1));
5532 -- Normal Ada 95 fixed-point case
5535 Fold_Ureal
(N
, Small_Value
(P_Type
));
5542 when Attribute_Succ
=> Succ
:
5546 -- Floating-point case. For now, do not fold this, since we
5547 -- don't know how to do it right (see fixed bug 3512-001 ???)
5549 if Is_Floating_Point_Type
(P_Type
) then
5551 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)));
5555 elsif Is_Fixed_Point_Type
(P_Type
) then
5557 Expr_Value_R
(E1
) + Small_Value
(P_Type
));
5559 -- Modular integer case (wraps)
5561 elsif Is_Modular_Integer_Type
(P_Type
) then
5562 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
));
5564 -- Other scalar cases
5567 pragma Assert
(Is_Scalar_Type
(P_Type
));
5569 if Is_Enumeration_Type
(P_Type
)
5570 and then Expr_Value
(E1
) =
5571 Expr_Value
(Type_High_Bound
(P_Base_Type
))
5573 Apply_Compile_Time_Constraint_Error
5574 (N
, "Succ of type''Last");
5578 Fold_Uint
(N
, Expr_Value
(E1
) + 1);
5588 when Attribute_Truncation
=>
5591 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)));
5598 when Attribute_Type_Class
=> Type_Class
: declare
5599 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
5603 if Is_RTE
(P_Root_Type
, RE_Address
) then
5604 Id
:= RE_Type_Class_Address
;
5606 elsif Is_Enumeration_Type
(Typ
) then
5607 Id
:= RE_Type_Class_Enumeration
;
5609 elsif Is_Integer_Type
(Typ
) then
5610 Id
:= RE_Type_Class_Integer
;
5612 elsif Is_Fixed_Point_Type
(Typ
) then
5613 Id
:= RE_Type_Class_Fixed_Point
;
5615 elsif Is_Floating_Point_Type
(Typ
) then
5616 Id
:= RE_Type_Class_Floating_Point
;
5618 elsif Is_Array_Type
(Typ
) then
5619 Id
:= RE_Type_Class_Array
;
5621 elsif Is_Record_Type
(Typ
) then
5622 Id
:= RE_Type_Class_Record
;
5624 elsif Is_Access_Type
(Typ
) then
5625 Id
:= RE_Type_Class_Access
;
5627 elsif Is_Enumeration_Type
(Typ
) then
5628 Id
:= RE_Type_Class_Enumeration
;
5630 elsif Is_Task_Type
(Typ
) then
5631 Id
:= RE_Type_Class_Task
;
5633 -- We treat protected types like task types. It would make more
5634 -- sense to have another enumeration value, but after all the
5635 -- whole point of this feature is to be exactly DEC compatible,
5636 -- and changing the type Type_Clas would not meet this requirement.
5638 elsif Is_Protected_Type
(Typ
) then
5639 Id
:= RE_Type_Class_Task
;
5641 -- Not clear if there are any other possibilities, but if there
5642 -- are, then we will treat them as the address case.
5645 Id
:= RE_Type_Class_Address
;
5648 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
5652 -----------------------
5653 -- Unbiased_Rounding --
5654 -----------------------
5656 when Attribute_Unbiased_Rounding
=>
5659 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5666 -- Processing is shared with Size
5672 when Attribute_Val
=> Val
:
5675 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5677 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
5679 Apply_Compile_Time_Constraint_Error
5680 (N
, "Val expression out of range");
5684 Fold_Uint
(N
, Expr_Value
(E1
));
5693 -- The Value_Size attribute for a type returns the RM size of the
5694 -- type. This an always be folded for scalar types, and can also
5695 -- be folded for non-scalar types if the size is set.
5697 when Attribute_Value_Size
=> Value_Size
: declare
5698 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5701 if RM_Size
(P_TypeA
) /= Uint_0
then
5702 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5711 -- Version can never be static
5713 when Attribute_Version
=>
5720 -- Wide_Image is a scalar attribute, but is never static, because it
5721 -- is not a static function (having a non-scalar argument (RM 4.9(22))
5723 when Attribute_Wide_Image
=>
5730 -- Processing for Wide_Width is combined with Width
5736 -- This processing also handles the case of Wide_Width
5738 when Attribute_Width | Attribute_Wide_Width
=> Width
:
5742 -- Floating-point types
5744 if Is_Floating_Point_Type
(P_Type
) then
5746 -- Width is zero for a null range (RM 3.5 (38))
5748 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
5749 Expr_Value_R
(Type_Low_Bound
(P_Type
))
5751 Fold_Uint
(N
, Uint_0
);
5754 -- For floating-point, we have +N.dddE+nnn where length
5755 -- of ddd is determined by type'Digits - 1, but is one
5756 -- if Digits is one (RM 3.5 (33)).
5758 -- nnn is set to 2 for Short_Float and Float (32 bit
5759 -- floats), and 3 for Long_Float and Long_Long_Float.
5760 -- This is not quite right, but is good enough.
5764 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
5767 if Esize
(P_Type
) <= 32 then
5773 Fold_Uint
(N
, UI_From_Int
(Len
));
5777 -- Fixed-point types
5779 elsif Is_Fixed_Point_Type
(P_Type
) then
5781 -- Width is zero for a null range (RM 3.5 (38))
5783 if Expr_Value
(Type_High_Bound
(P_Type
)) <
5784 Expr_Value
(Type_Low_Bound
(P_Type
))
5786 Fold_Uint
(N
, Uint_0
);
5788 -- The non-null case depends on the specific real type
5791 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
5793 Fold_Uint
(N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
));
5800 R
: constant Entity_Id
:= Root_Type
(P_Type
);
5801 Lo
: constant Uint
:=
5802 Expr_Value
(Type_Low_Bound
(P_Type
));
5803 Hi
: constant Uint
:=
5804 Expr_Value
(Type_High_Bound
(P_Type
));
5817 -- Width for types derived from Standard.Character
5818 -- and Standard.Wide_Character.
5820 elsif R
= Standard_Character
5821 or else R
= Standard_Wide_Character
5825 -- Set W larger if needed
5827 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
5829 -- Assume all wide-character escape sequences are
5830 -- same length, so we can quit when we reach one.
5833 if Id
= Attribute_Wide_Width
then
5834 W
:= Int
'Max (W
, 3);
5837 W
:= Int
'Max (W
, Length_Wide
);
5842 C
:= Character'Val (J
);
5844 -- Test for all cases where Character'Image
5845 -- yields an image that is longer than three
5846 -- characters. First the cases of Reserved_xxx
5847 -- names (length = 12).
5850 when Reserved_128 | Reserved_129 |
5851 Reserved_132 | Reserved_153
5855 when BS | HT | LF | VT | FF | CR |
5856 SO | SI | EM | FS | GS | RS |
5857 US | RI | MW | ST | PM
5861 when NUL | SOH | STX | ETX | EOT |
5862 ENQ | ACK | BEL | DLE | DC1 |
5863 DC2 | DC3 | DC4 | NAK | SYN |
5864 ETB | CAN | SUB | ESC | DEL |
5865 BPH | NBH | NEL | SSA | ESA |
5866 HTS | HTJ | VTS | PLD | PLU |
5867 SS2 | SS3 | DCS | PU1 | PU2 |
5868 STS | CCH | SPA | EPA | SOS |
5869 SCI | CSI | OSC | APC
5873 when Space
.. Tilde |
5874 No_Break_Space
.. LC_Y_Diaeresis
5880 W
:= Int
'Max (W
, Wt
);
5884 -- Width for types derived from Standard.Boolean
5886 elsif R
= Standard_Boolean
then
5893 -- Width for integer types
5895 elsif Is_Integer_Type
(P_Type
) then
5896 T
:= UI_Max
(abs Lo
, abs Hi
);
5904 -- Only remaining possibility is user declared enum type
5907 pragma Assert
(Is_Enumeration_Type
(P_Type
));
5910 L
:= First_Literal
(P_Type
);
5912 while Present
(L
) loop
5914 -- Only pay attention to in range characters
5916 if Lo
<= Enumeration_Pos
(L
)
5917 and then Enumeration_Pos
(L
) <= Hi
5919 -- For Width case, use decoded name
5921 if Id
= Attribute_Width
then
5922 Get_Decoded_Name_String
(Chars
(L
));
5923 Wt
:= Nat
(Name_Len
);
5925 -- For Wide_Width, use encoded name, and then
5926 -- adjust for the encoding.
5929 Get_Name_String
(Chars
(L
));
5931 -- Character literals are always of length 3
5933 if Name_Buffer
(1) = 'Q' then
5936 -- Otherwise loop to adjust for upper/wide chars
5939 Wt
:= Nat
(Name_Len
);
5941 for J
in 1 .. Name_Len
loop
5942 if Name_Buffer
(J
) = 'U' then
5944 elsif Name_Buffer
(J
) = 'W' then
5951 W
:= Int
'Max (W
, Wt
);
5958 Fold_Uint
(N
, UI_From_Int
(W
));
5964 -- The following attributes can never be folded, and furthermore we
5965 -- should not even have entered the case statement for any of these.
5966 -- Note that in some cases, the values have already been folded as
5967 -- a result of the processing in Analyze_Attribute.
5969 when Attribute_Abort_Signal |
5972 Attribute_Address_Size |
5973 Attribute_Asm_Input |
5974 Attribute_Asm_Output |
5976 Attribute_Bit_Order |
5977 Attribute_Bit_Position |
5978 Attribute_Callable |
5981 Attribute_Code_Address |
5983 Attribute_Default_Bit_Order |
5984 Attribute_Elaborated |
5985 Attribute_Elab_Body |
5986 Attribute_Elab_Spec |
5987 Attribute_External_Tag |
5988 Attribute_First_Bit |
5990 Attribute_Last_Bit |
5991 Attribute_Max_Interrupt_Priority |
5992 Attribute_Max_Priority |
5993 Attribute_Maximum_Alignment |
5995 Attribute_Partition_ID |
5996 Attribute_Position |
5998 Attribute_Storage_Pool |
5999 Attribute_Storage_Size |
6000 Attribute_Storage_Unit |
6002 Attribute_Terminated |
6004 Attribute_To_Address |
6005 Attribute_UET_Address |
6006 Attribute_Unchecked_Access |
6007 Attribute_Universal_Literal_String |
6008 Attribute_Unrestricted_Access |
6011 Attribute_Wchar_T_Size |
6012 Attribute_Wide_Value |
6013 Attribute_Word_Size |
6016 raise Program_Error
;
6020 -- At the end of the case, one more check. If we did a static evaluation
6021 -- so that the result is now a literal, then set Is_Static_Expression
6022 -- in the constant only if the prefix type is a static subtype. For
6023 -- non-static subtypes, the folding is still OK, but not static.
6025 if Nkind
(N
) = N_Integer_Literal
6026 or else Nkind
(N
) = N_Real_Literal
6027 or else Nkind
(N
) = N_Character_Literal
6028 or else Nkind
(N
) = N_String_Literal
6029 or else (Is_Entity_Name
(N
)
6030 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6032 Set_Is_Static_Expression
(N
, Static
);
6034 -- If this is still an attribute reference, then it has not been folded
6035 -- and that means that its expressions are in a non-static context.
6037 elsif Nkind
(N
) = N_Attribute_Reference
then
6040 -- Note: the else case not covered here are odd cases where the
6041 -- processing has transformed the attribute into something other
6042 -- than a constant. Nothing more to do in such cases.
6050 ------------------------------
6051 -- Is_Anonymous_Tagged_Base --
6052 ------------------------------
6054 function Is_Anonymous_Tagged_Base
6061 Anon
= Current_Scope
6062 and then Is_Itype
(Anon
)
6063 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6064 end Is_Anonymous_Tagged_Base
;
6066 -----------------------
6067 -- Resolve_Attribute --
6068 -----------------------
6070 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6071 Loc
: constant Source_Ptr
:= Sloc
(N
);
6072 P
: constant Node_Id
:= Prefix
(N
);
6073 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6074 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6075 Index
: Interp_Index
;
6077 Btyp
: Entity_Id
:= Base_Type
(Typ
);
6078 Nom_Subt
: Entity_Id
;
6081 -- If error during analysis, no point in continuing, except for
6082 -- array types, where we get better recovery by using unconstrained
6083 -- indices than nothing at all (see Check_Array_Type).
6086 and then Attr_Id
/= Attribute_First
6087 and then Attr_Id
/= Attribute_Last
6088 and then Attr_Id
/= Attribute_Length
6089 and then Attr_Id
/= Attribute_Range
6094 -- If attribute was universal type, reset to actual type
6096 if Etype
(N
) = Universal_Integer
6097 or else Etype
(N
) = Universal_Real
6102 -- Remaining processing depends on attribute
6110 -- For access attributes, if the prefix denotes an entity, it is
6111 -- interpreted as a name, never as a call. It may be overloaded,
6112 -- in which case resolution uses the profile of the context type.
6113 -- Otherwise prefix must be resolved.
6115 when Attribute_Access
6116 | Attribute_Unchecked_Access
6117 | Attribute_Unrestricted_Access
=>
6119 if Is_Variable
(P
) then
6120 Note_Possible_Modification
(P
);
6123 if Is_Entity_Name
(P
) then
6125 if Is_Overloaded
(P
) then
6126 Get_First_Interp
(P
, Index
, It
);
6128 while Present
(It
.Nam
) loop
6130 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6131 Set_Entity
(P
, It
.Nam
);
6133 -- The prefix is definitely NOT overloaded anymore
6134 -- at this point, so we reset the Is_Overloaded
6135 -- flag to avoid any confusion when reanalyzing
6138 Set_Is_Overloaded
(P
, False);
6139 Generate_Reference
(Entity
(P
), P
);
6143 Get_Next_Interp
(Index
, It
);
6146 -- If it is a subprogram name or a type, there is nothing
6149 elsif not Is_Overloadable
(Entity
(P
))
6150 and then not Is_Type
(Entity
(P
))
6152 Resolve
(P
, Etype
(P
));
6155 if not Is_Entity_Name
(P
) then
6158 elsif Is_Abstract
(Entity
(P
))
6159 and then Is_Overloadable
(Entity
(P
))
6161 Error_Msg_Name_1
:= Aname
;
6162 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6163 Set_Etype
(N
, Any_Type
);
6165 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6166 Error_Msg_Name_1
:= Aname
;
6168 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6170 ("prefix of % attribute cannot be enumeration literal",
6174 ("prefix of % attribute cannot be intrinsic", P
);
6177 Set_Etype
(N
, Any_Type
);
6180 -- Assignments, return statements, components of aggregates,
6181 -- generic instantiations will require convention checks if
6182 -- the type is an access to subprogram. Given that there will
6183 -- also be accessibility checks on those, this is where the
6184 -- checks can eventually be centralized ???
6186 if Ekind
(Btyp
) = E_Access_Subprogram_Type
then
6187 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6189 ("subprogram has invalid convention for context", P
);
6192 Check_Subtype_Conformant
6193 (New_Id
=> Entity
(P
),
6194 Old_Id
=> Designated_Type
(Btyp
),
6198 if Attr_Id
= Attribute_Unchecked_Access
then
6199 Error_Msg_Name_1
:= Aname
;
6201 ("attribute% cannot be applied to a subprogram", P
);
6203 elsif Aname
= Name_Unrestricted_Access
then
6204 null; -- Nothing to check
6206 -- Check the static accessibility rule of 3.10.2(32)
6208 elsif Attr_Id
= Attribute_Access
6209 and then Subprogram_Access_Level
(Entity
(P
))
6210 > Type_Access_Level
(Btyp
)
6212 if not In_Instance_Body
then
6214 ("subprogram must not be deeper than access type",
6217 Warn_On_Instance
:= True;
6219 ("subprogram must not be deeper than access type?",
6222 ("Constraint_Error will be raised ?", P
);
6223 Set_Raises_Constraint_Error
(N
);
6224 Warn_On_Instance
:= False;
6227 -- Check the restriction of 3.10.2(32) that disallows
6228 -- the type of the access attribute to be declared
6229 -- outside a generic body when the attribute occurs
6230 -- within that generic body.
6232 elsif Enclosing_Generic_Body
(Entity
(P
))
6233 /= Enclosing_Generic_Body
(Btyp
)
6236 ("access type must not be outside generic body", P
);
6240 -- if this is a renaming, an inherited operation, or a
6241 -- subprogram instance, use the original entity.
6243 if Is_Entity_Name
(P
)
6244 and then Is_Overloadable
(Entity
(P
))
6245 and then Present
(Alias
(Entity
(P
)))
6248 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6251 elsif Nkind
(P
) = N_Selected_Component
6252 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
6254 -- Protected operation. If operation is overloaded, must
6255 -- disambiguate. Prefix that denotes protected object itself
6256 -- is resolved with its own type.
6258 if Attr_Id
= Attribute_Unchecked_Access
then
6259 Error_Msg_Name_1
:= Aname
;
6261 ("attribute% cannot be applied to protected operation", P
);
6264 Resolve
(Prefix
(P
), Etype
(Prefix
(P
)));
6266 elsif Is_Overloaded
(P
) then
6268 -- Use the designated type of the context to disambiguate.
6270 Index
: Interp_Index
;
6273 Get_First_Interp
(P
, Index
, It
);
6275 while Present
(It
.Typ
) loop
6276 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
6277 Resolve
(P
, It
.Typ
);
6281 Get_Next_Interp
(Index
, It
);
6285 Resolve
(P
, Etype
(P
));
6288 -- X'Access is illegal if X denotes a constant and the access
6289 -- type is access-to-variable. Same for 'Unchecked_Access.
6290 -- The rule does not apply to 'Unrestricted_Access.
6292 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
6293 or else (Is_Record_Type
(Btyp
) and then
6294 Present
(Corresponding_Remote_Type
(Btyp
)))
6295 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6296 or else Is_Access_Constant
(Btyp
)
6297 or else Is_Variable
(P
)
6298 or else Attr_Id
= Attribute_Unrestricted_Access
)
6300 if Comes_From_Source
(N
) then
6301 Error_Msg_N
("access-to-variable designates constant", P
);
6305 if (Attr_Id
= Attribute_Access
6307 Attr_Id
= Attribute_Unchecked_Access
)
6308 and then (Ekind
(Btyp
) = E_General_Access_Type
6309 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
6311 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
6313 ("illegal attribute for discriminant-dependent component",
6317 -- Check the static matching rule of 3.10.2(27). The
6318 -- nominal subtype of the prefix must statically
6319 -- match the designated type.
6321 Nom_Subt
:= Etype
(P
);
6323 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
6324 Nom_Subt
:= Etype
(Nom_Subt
);
6327 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
6329 -- If the attribute is in the context of an access
6330 -- parameter, then the prefix is allowed to be of
6331 -- the class-wide type (by AI-127).
6333 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
6334 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6335 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
6341 Desig
:= Designated_Type
(Typ
);
6343 if Is_Class_Wide_Type
(Desig
) then
6344 Desig
:= Etype
(Desig
);
6347 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
6352 ("type of prefix: & not compatible",
6355 ("\with &, the expected designated type",
6356 P
, Designated_Type
(Typ
));
6361 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6363 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
6364 and then Is_Class_Wide_Type
(Nom_Subt
))
6367 ("type of prefix: & is not covered", P
, Nom_Subt
);
6369 ("\by &, the expected designated type" &
6370 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
6373 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
6374 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
6375 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
6376 and then Designated_Type
(Typ
) /= Nom_Subt
6378 Apply_Discriminant_Check
6379 (N
, Etype
(Designated_Type
(Typ
)));
6382 elsif not Subtypes_Statically_Match
6383 (Designated_Type
(Typ
), Nom_Subt
)
6385 not (Has_Discriminants
(Designated_Type
(Typ
))
6386 and then not Is_Constrained
(Designated_Type
(Typ
)))
6389 ("object subtype must statically match "
6390 & "designated subtype", P
);
6392 if Is_Entity_Name
(P
)
6393 and then Is_Array_Type
(Designated_Type
(Typ
))
6397 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
6400 Error_Msg_N
("aliased object has explicit bounds?",
6402 Error_Msg_N
("\declare without bounds"
6403 & " (and with explicit initialization)?", D
);
6404 Error_Msg_N
("\for use with unconstrained access?", D
);
6409 -- Check the static accessibility rule of 3.10.2(28).
6410 -- Note that this check is not performed for the
6411 -- case of an anonymous access type, since the access
6412 -- attribute is always legal in such a context.
6414 if Attr_Id
/= Attribute_Unchecked_Access
6415 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
6416 and then Ekind
(Btyp
) = E_General_Access_Type
6418 -- In an instance, this is a runtime check, but one we
6419 -- know will fail, so generate an appropriate warning.
6421 if In_Instance_Body
then
6423 ("?non-local pointer cannot point to local object", P
);
6425 ("?Program_Error will be raised at run time", P
);
6426 Rewrite
(N
, Make_Raise_Program_Error
(Loc
));
6432 ("non-local pointer cannot point to local object", P
);
6434 if Is_Record_Type
(Current_Scope
)
6435 and then (Nkind
(Parent
(N
)) =
6436 N_Discriminant_Association
6438 Nkind
(Parent
(N
)) =
6439 N_Index_Or_Discriminant_Constraint
)
6442 Indic
: Node_Id
:= Parent
(Parent
(N
));
6445 while Present
(Indic
)
6446 and then Nkind
(Indic
) /= N_Subtype_Indication
6448 Indic
:= Parent
(Indic
);
6451 if Present
(Indic
) then
6453 ("\use an access definition for" &
6454 " the access discriminant of&", N
,
6455 Entity
(Subtype_Mark
(Indic
)));
6463 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6464 and then Is_Entity_Name
(P
)
6465 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
6467 Error_Msg_N
("context requires a protected subprogram", P
);
6469 elsif Ekind
(Btyp
) = E_Access_Subprogram_Type
6470 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
6472 Error_Msg_N
("context requires a non-protected subprogram", P
);
6475 -- The context cannot be a pool-specific type, but this is a
6476 -- legality rule, not a resolution rule, so it must be checked
6477 -- separately, after possibly disambiguation (see AI-245).
6479 if Ekind
(Btyp
) = E_Access_Type
6480 and then Attr_Id
/= Attribute_Unrestricted_Access
6482 Wrong_Type
(N
, Typ
);
6487 -- Check for incorrect atomic/volatile reference (RM C.6(12))
6489 if Attr_Id
/= Attribute_Unrestricted_Access
then
6490 if Is_Atomic_Object
(P
)
6491 and then not Is_Atomic
(Designated_Type
(Typ
))
6494 ("access to atomic object cannot yield access-to-" &
6495 "non-atomic type", P
);
6497 elsif Is_Volatile_Object
(P
)
6498 and then not Is_Volatile
(Designated_Type
(Typ
))
6501 ("access to volatile object cannot yield access-to-" &
6502 "non-volatile type", P
);
6510 -- Deal with resolving the type for Address attribute, overloading
6511 -- is not permitted here, since there is no context to resolve it.
6513 when Attribute_Address | Attribute_Code_Address
=>
6515 -- To be safe, assume that if the address of a variable is taken,
6516 -- it may be modified via this address, so note modification.
6518 if Is_Variable
(P
) then
6519 Note_Possible_Modification
(P
);
6522 if Nkind
(P
) in N_Subexpr
6523 and then Is_Overloaded
(P
)
6525 Get_First_Interp
(P
, Index
, It
);
6526 Get_Next_Interp
(Index
, It
);
6528 if Present
(It
.Nam
) then
6529 Error_Msg_Name_1
:= Aname
;
6531 ("prefix of % attribute cannot be overloaded", N
);
6536 if not Is_Entity_Name
(P
)
6537 or else not Is_Overloadable
(Entity
(P
))
6539 if not Is_Task_Type
(Etype
(P
))
6540 or else Nkind
(P
) = N_Explicit_Dereference
6542 Resolve
(P
, Etype
(P
));
6546 -- If this is the name of a derived subprogram, or that of a
6547 -- generic actual, the address is that of the original entity.
6549 if Is_Entity_Name
(P
)
6550 and then Is_Overloadable
(Entity
(P
))
6551 and then Present
(Alias
(Entity
(P
)))
6554 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6561 -- Prefix of the AST_Entry attribute is an entry name which must
6562 -- not be resolved, since this is definitely not an entry call.
6564 when Attribute_AST_Entry
=>
6571 -- Prefix of Body_Version attribute can be a subprogram name which
6572 -- must not be resolved, since this is not a call.
6574 when Attribute_Body_Version
=>
6581 -- Prefix of Caller attribute is an entry name which must not
6582 -- be resolved, since this is definitely not an entry call.
6584 when Attribute_Caller
=>
6591 -- Shares processing with Address attribute
6597 -- Prefix of the Count attribute is an entry name which must not
6598 -- be resolved, since this is definitely not an entry call.
6600 when Attribute_Count
=>
6607 -- Prefix of the Elaborated attribute is a subprogram name which
6608 -- must not be resolved, since this is definitely not a call. Note
6609 -- that it is a library unit, so it cannot be overloaded here.
6611 when Attribute_Elaborated
=>
6614 --------------------
6615 -- Mechanism_Code --
6616 --------------------
6618 -- Prefix of the Mechanism_Code attribute is a function name
6619 -- which must not be resolved. Should we check for overloaded ???
6621 when Attribute_Mechanism_Code
=>
6628 -- Most processing is done in sem_dist, after determining the
6629 -- context type. Node is rewritten as a conversion to a runtime call.
6631 when Attribute_Partition_ID
=>
6632 Process_Partition_Id
(N
);
6639 -- We replace the Range attribute node with a range expression
6640 -- whose bounds are the 'First and 'Last attributes applied to the
6641 -- same prefix. The reason that we do this transformation here
6642 -- instead of in the expander is that it simplifies other parts of
6643 -- the semantic analysis which assume that the Range has been
6644 -- replaced; thus it must be done even when in semantic-only mode
6645 -- (note that the RM specifically mentions this equivalence, we
6646 -- take care that the prefix is only evaluated once).
6648 when Attribute_Range
=> Range_Attribute
:
6653 function Check_Discriminated_Prival
6656 -- The range of a private component constrained by a
6657 -- discriminant is rewritten to make the discriminant
6658 -- explicit. This solves some complex visibility problems
6659 -- related to the use of privals.
6661 function Check_Discriminated_Prival
6666 if Is_Entity_Name
(N
)
6667 and then Ekind
(Entity
(N
)) = E_In_Parameter
6668 and then not Within_Init_Proc
6670 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
6672 return Duplicate_Subexpr
(N
);
6674 end Check_Discriminated_Prival
;
6676 -- Start of processing for Range_Attribute
6679 if not Is_Entity_Name
(P
)
6680 or else not Is_Type
(Entity
(P
))
6682 Resolve
(P
, Etype
(P
));
6685 -- Check whether prefix is (renaming of) private component
6686 -- of protected type.
6688 if Is_Entity_Name
(P
)
6689 and then Comes_From_Source
(N
)
6690 and then Is_Array_Type
(Etype
(P
))
6691 and then Number_Dimensions
(Etype
(P
)) = 1
6692 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
6694 Ekind
(Scope
(Scope
(Entity
(P
)))) =
6697 LB
:= Check_Discriminated_Prival
(
6698 Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
6700 HB
:= Check_Discriminated_Prival
(
6701 Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
6705 Make_Attribute_Reference
(Loc
,
6706 Prefix
=> Duplicate_Subexpr
(P
),
6707 Attribute_Name
=> Name_Last
,
6708 Expressions
=> Expressions
(N
));
6711 Make_Attribute_Reference
(Loc
,
6713 Attribute_Name
=> Name_First
,
6714 Expressions
=> Expressions
(N
));
6717 -- If the original was marked as Must_Not_Freeze (see code
6718 -- in Sem_Ch3.Make_Index), then make sure the rewriting
6719 -- does not freeze either.
6721 if Must_Not_Freeze
(N
) then
6722 Set_Must_Not_Freeze
(HB
);
6723 Set_Must_Not_Freeze
(LB
);
6724 Set_Must_Not_Freeze
(Prefix
(HB
));
6725 Set_Must_Not_Freeze
(Prefix
(LB
));
6728 if Raises_Constraint_Error
(Prefix
(N
)) then
6730 -- Preserve Sloc of prefix in the new bounds, so that
6731 -- the posted warning can be removed if we are within
6732 -- unreachable code.
6734 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
6735 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
6738 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
6739 Analyze_And_Resolve
(N
, Typ
);
6741 -- Normally after resolving attribute nodes, Eval_Attribute
6742 -- is called to do any possible static evaluation of the node.
6743 -- However, here since the Range attribute has just been
6744 -- transformed into a range expression it is no longer an
6745 -- attribute node and therefore the call needs to be avoided
6746 -- and is accomplished by simply returning from the procedure.
6749 end Range_Attribute
;
6755 -- Prefix must not be resolved in this case, since it is not a
6756 -- real entity reference. No action of any kind is require!
6758 when Attribute_UET_Address
=>
6761 ----------------------
6762 -- Unchecked_Access --
6763 ----------------------
6765 -- Processing is shared with Access
6767 -------------------------
6768 -- Unrestricted_Access --
6769 -------------------------
6771 -- Processing is shared with Access
6777 -- Apply range check. Note that we did not do this during the
6778 -- analysis phase, since we wanted Eval_Attribute to have a
6779 -- chance at finding an illegal out of range value.
6781 when Attribute_Val
=>
6783 -- Note that we do our own Eval_Attribute call here rather than
6784 -- use the common one, because we need to do processing after
6785 -- the call, as per above comment.
6789 -- Eval_Attribute may replace the node with a raise CE, or
6790 -- fold it to a constant. Obviously we only apply a scalar
6791 -- range check if this did not happen!
6793 if Nkind
(N
) = N_Attribute_Reference
6794 and then Attribute_Name
(N
) = Name_Val
6796 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
6805 -- Prefix of Version attribute can be a subprogram name which
6806 -- must not be resolved, since this is not a call.
6808 when Attribute_Version
=>
6811 ----------------------
6812 -- Other Attributes --
6813 ----------------------
6815 -- For other attributes, resolve prefix unless it is a type. If
6816 -- the attribute reference itself is a type name ('Base and 'Class)
6817 -- then this is only legal within a task or protected record.
6820 if not Is_Entity_Name
(P
)
6821 or else not Is_Type
(Entity
(P
))
6823 Resolve
(P
, Etype
(P
));
6826 -- If the attribute reference itself is a type name ('Base,
6827 -- 'Class) then this is only legal within a task or protected
6828 -- record. What is this all about ???
6830 if Is_Entity_Name
(N
)
6831 and then Is_Type
(Entity
(N
))
6833 if Is_Concurrent_Type
(Entity
(N
))
6834 and then In_Open_Scopes
(Entity
(P
))
6839 ("invalid use of subtype name in expression or call", N
);
6843 -- For attributes whose argument may be a string, complete
6844 -- resolution of argument now. This avoids premature expansion
6845 -- (and the creation of transient scopes) before the attribute
6846 -- reference is resolved.
6849 when Attribute_Value
=>
6850 Resolve
(First
(Expressions
(N
)), Standard_String
);
6852 when Attribute_Wide_Value
=>
6853 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
6855 when others => null;
6859 -- Normally the Freezing is done by Resolve but sometimes the Prefix
6860 -- is not resolved, in which case the freezing must be done now.
6862 Freeze_Expression
(P
);
6864 -- Finally perform static evaluation on the attribute reference
6868 end Resolve_Attribute
;