1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
29 with Atree
; use Atree
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
47 with Sdefault
; use Sdefault
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dist
; use Sem_Dist
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Res
; use Sem_Res
;
55 with Sem_Type
; use Sem_Type
;
56 with Sem_Util
; use Sem_Util
;
57 with Stand
; use Stand
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with 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
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
90 Attribute_Constrained |
103 Attribute_Leading_Part |
105 Attribute_Machine_Emax |
106 Attribute_Machine_Emin |
107 Attribute_Machine_Mantissa |
108 Attribute_Machine_Overflows |
109 Attribute_Machine_Radix |
110 Attribute_Machine_Rounds |
116 Attribute_Safe_Emax |
117 Attribute_Safe_Large |
118 Attribute_Safe_Small |
121 Attribute_Storage_Size |
123 Attribute_Terminated |
126 Attribute_Width => True,
129 -----------------------
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 -----------------------
178 -- Local Subprograms --
179 -----------------------
181 procedure Analyze_Access_Attribute;
182 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
183 -- Internally, Id distinguishes which of the three cases is involved.
185 procedure Check_Array_Or_Scalar_Type;
186 -- Common procedure used by First, Last, Range attribute to check
187 -- that the prefix is a constrained array or scalar type, or a name
188 -- of an array object, and that an argument appears only if appropriate
189 -- (i.e. only in the array case).
191 procedure Check_Array_Type;
192 -- Common semantic checks for all array attributes. Checks that the
193 -- prefix is a constrained array type or the name of an array object.
194 -- The error message for non-arrays is specialized appropriately.
196 procedure Check_Asm_Attribute;
197 -- Common semantic checks for Asm_Input and Asm_Output attributes
199 procedure Check_Component;
200 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
201 -- Position. Checks prefix is an appropriate selected component.
203 procedure Check_Decimal_Fixed_Point_Type;
204 -- Check that prefix of attribute N is a decimal fixed-point type
206 procedure Check_Dereference;
207 -- If the prefix of attribute is an object of an access type, then
208 -- introduce an explicit deference, and adjust P_Type accordingly.
210 procedure Check_Discrete_Type;
211 -- Verify that prefix of attribute N is a discrete type
214 -- Check that no attribute arguments are present
216 procedure Check_Either_E0_Or_E1;
217 -- Check that there are zero or one attribute arguments present
220 -- Check that exactly one attribute argument is present
223 -- Check that two attribute arguments are present
225 procedure Check_Enum_Image;
226 -- If the prefix type is an enumeration type, set all its literals
227 -- as referenced, since the image function could possibly end up
228 -- referencing any of the literals indirectly.
230 procedure Check_Fixed_Point_Type;
231 -- Verify that prefix of attribute N is a fixed type
233 procedure Check_Fixed_Point_Type_0;
234 -- Verify that prefix of attribute N is a fixed type and that
235 -- no attribute expressions are present
237 procedure Check_Floating_Point_Type;
238 -- Verify that prefix of attribute N is a float type
240 procedure Check_Floating_Point_Type_0;
241 -- Verify that prefix of attribute N is a float type and that
242 -- no attribute expressions are present
244 procedure Check_Floating_Point_Type_1;
245 -- Verify that prefix of attribute N is a float type and that
246 -- exactly one attribute expression is present
248 procedure Check_Floating_Point_Type_2;
249 -- Verify that prefix of attribute N is a float type and that
250 -- two attribute expressions are present
252 procedure Legal_Formal_Attribute;
253 -- Common processing for attributes Definite, and Has_Discriminants
255 procedure Check_Integer_Type;
256 -- Verify that prefix of attribute N is an integer type
258 procedure Check_Library_Unit;
259 -- Verify that prefix of attribute N is a library unit
261 procedure Check_Not_Incomplete_Type;
262 -- Check that P (the prefix of the attribute) is not an incomplete
263 -- type or a private type for which no full view has been given.
265 procedure Check_Object_Reference (P : Node_Id);
266 -- Check that P (the prefix of the attribute) is an object reference
268 procedure Check_Program_Unit;
269 -- Verify that prefix of attribute N is a program unit
271 procedure Check_Real_Type;
272 -- Verify that prefix of attribute N is fixed or float type
274 procedure Check_Scalar_Type;
275 -- Verify that prefix of attribute N is a scalar type
277 procedure Check_Standard_Prefix;
278 -- Verify that prefix of attribute N is package Standard
280 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
281 -- Validity checking for stream attribute. Nam is the TSS name of the
282 -- corresponding possible defined attribute function (e.g. for the
283 -- Read attribute, Nam will be TSS_Stream_Read).
285 procedure Check_Task_Prefix;
286 -- Verify that prefix of attribute N is a task or task type
288 procedure Check_Type;
289 -- Verify that the prefix of attribute N is a type
291 procedure Check_Unit_Name (Nod : Node_Id);
292 -- Check that Nod is of the form of a library unit name, i.e that
293 -- it is an identifier, or a selected component whose prefix is
294 -- itself of the form of a library unit name. Note that this is
295 -- quite different from Check_Program_Unit, since it only checks
296 -- the syntactic form of the name, not the semantic identity. This
297 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
298 -- UET_Address) which can refer to non-visible unit.
300 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
301 pragma No_Return (Error_Attr);
302 procedure Error_Attr;
303 pragma No_Return (Error_Attr);
304 -- Posts error using Error_Msg_N at given node, sets type of attribute
305 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
306 -- semantic processing. The message typically contains a % insertion
307 -- character which is replaced by the attribute name. The call with
308 -- no arguments is used when the caller has already generated the
309 -- required error messages.
311 procedure Standard_Attribute (Val : Int);
312 -- Used to process attributes whose prefix is package Standard which
313 -- yield values of type Universal_Integer. The attribute reference
314 -- node is rewritten with an integer literal of the given value.
316 procedure Unexpected_Argument (En : Node_Id);
317 -- Signal unexpected attribute argument (En is the argument)
319 procedure Validate_Non_Static_Attribute_Function_Call;
320 -- Called when processing an attribute that is a function call to a
321 -- non-static function, i.e. an attribute function that either takes
322 -- non-scalar arguments or returns a non-scalar result. Verifies that
323 -- such a call does not appear in a preelaborable context.
325 ------------------------------
326 -- Analyze_Access_Attribute --
327 ------------------------------
329 procedure Analyze_Access_Attribute is
330 Acc_Type : Entity_Id;
335 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
336 -- Build an access-to-object type whose designated type is DT,
337 -- and whose Ekind is appropriate to the attribute type. The
338 -- type that is constructed is returned as the result.
340 procedure Build_Access_Subprogram_Type (P : Node_Id);
341 -- Build an access to subprogram whose designated type is
342 -- the type of the prefix. If prefix is overloaded, so it the
343 -- node itself. The result is stored in Acc_Type.
345 ------------------------------
346 -- Build_Access_Object_Type --
347 ------------------------------
349 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
353 if Aname = Name_Unrestricted_Access then
356 (E_Allocator_Type, Current_Scope, Loc, 'A
');
360 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
363 Set_Etype (Typ, Typ);
364 Init_Size_Align (Typ);
366 Set_Associated_Node_For_Itype (Typ, N);
367 Set_Directly_Designated_Type (Typ, DT);
369 end Build_Access_Object_Type;
371 ----------------------------------
372 -- Build_Access_Subprogram_Type --
373 ----------------------------------
375 procedure Build_Access_Subprogram_Type (P : Node_Id) is
376 Index : Interp_Index;
379 function Get_Kind (E : Entity_Id) return Entity_Kind;
380 -- 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 -- In the case of an access to subprogram, use the name of the
400 -- subprogram itself as the designated type. Type-checking in
401 -- this case compares the signatures of the designated types.
403 if not Is_Overloaded (P) then
406 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
407 Set_Etype (Acc_Type, Acc_Type);
408 Set_Directly_Designated_Type (Acc_Type, Entity (P));
409 Set_Etype (N, Acc_Type);
412 Get_First_Interp (P, Index, It);
413 Set_Etype (N, Any_Type);
415 while Present (It.Nam) loop
416 if not Is_Intrinsic_Subprogram (It.Nam) then
419 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
420 Set_Etype (Acc_Type, Acc_Type);
421 Set_Directly_Designated_Type (Acc_Type, It.Nam);
422 Add_One_Interp (N, Acc_Type, Acc_Type);
425 Get_Next_Interp (Index, It);
428 if Etype (N) = Any_Type then
429 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
432 end Build_Access_Subprogram_Type;
434 -- Start of processing for Analyze_Access_Attribute
439 if Nkind (P) = N_Character_Literal then
441 ("prefix of % attribute cannot be enumeration literal", P);
444 -- Case of access to subprogram
446 if Is_Entity_Name (P)
447 and then Is_Overloadable (Entity (P))
449 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
450 -- restriction set (since in general a trampoline is required).
452 if not Is_Library_Level_Entity (Entity (P)) then
453 Check_Restriction (No_Implicit_Dynamic_Code, P);
456 -- Build the appropriate subprogram type
458 Build_Access_Subprogram_Type (P);
460 -- For unrestricted access, kill current values, since this
461 -- attribute allows a reference to a local subprogram that
462 -- could modify local variables to be passed out of scope
464 if Aname = Name_Unrestricted_Access then
470 -- Component is an operation of a protected type
472 elsif Nkind (P) = N_Selected_Component
473 and then Is_Overloadable (Entity (Selector_Name (P)))
475 if Ekind (Entity (Selector_Name (P))) = E_Entry then
476 Error_Attr ("prefix of % attribute must be subprogram", P);
479 Build_Access_Subprogram_Type (Selector_Name (P));
483 -- Deal with incorrect reference to a type, but note that some
484 -- accesses are allowed (references to the current type instance).
486 if Is_Entity_Name (P) then
487 Scop := Current_Scope;
490 if Is_Type (Typ) then
492 -- OK if we are within the scope of a limited type
493 -- let's mark the component as having per object constraint
495 if Is_Anonymous_Tagged_Base (Scop, Typ) then
503 Q : Node_Id := Parent (N);
507 and then Nkind (Q) /= N_Component_Declaration
512 Set_Has_Per_Object_Constraint (
513 Defining_Identifier (Q), True);
517 if Nkind (P) = N_Expanded_Name then
519 ("current instance prefix must be a direct name", P);
522 -- If a current instance attribute appears within a
523 -- a component constraint it must appear alone; other
524 -- contexts (default expressions, within a task body)
525 -- are not subject to this restriction.
527 if not In_Default_Expression
528 and then not Has_Completion (Scop)
530 Nkind (Parent (N)) /= N_Discriminant_Association
532 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
535 ("current instance attribute must appear alone", N);
538 -- OK if we are in initialization procedure for the type
539 -- in question, in which case the reference to the type
540 -- is rewritten as a reference to the current object.
542 elsif Ekind (Scop) = E_Procedure
543 and then Is_Init_Proc (Scop)
544 and then Etype (First_Formal (Scop)) = Typ
547 Make_Attribute_Reference (Loc,
548 Prefix => Make_Identifier (Loc, Name_uInit),
549 Attribute_Name => Name_Unrestricted_Access));
553 -- OK if a task type, this test needs sharpening up ???
555 elsif Is_Task_Type (Typ) then
558 -- Otherwise we have an error case
561 Error_Attr ("% attribute cannot be applied to type", P);
567 -- If we fall through, we have a normal access to object case.
568 -- Unrestricted_Access is legal wherever an allocator would be
569 -- legal, so its Etype is set to E_Allocator. The expected type
570 -- of the other attributes is a general access type, and therefore
571 -- we label them with E_Access_Attribute_Type.
573 if not Is_Overloaded (P) then
574 Acc_Type := Build_Access_Object_Type (P_Type);
575 Set_Etype (N, Acc_Type);
578 Index : Interp_Index;
582 Set_Etype (N, Any_Type);
583 Get_First_Interp (P, Index, It);
585 while Present (It.Typ) loop
586 Acc_Type := Build_Access_Object_Type (It.Typ);
587 Add_One_Interp (N, Acc_Type, Acc_Type);
588 Get_Next_Interp (Index, It);
593 -- If we have an access to an object, and the attribute comes
594 -- from source, then set the object as potentially source modified.
595 -- We do this because the resulting access pointer can be used to
596 -- modify the variable, and we might not detect this, leading to
597 -- some junk warnings.
599 if Is_Entity_Name (P) then
600 Set_Never_Set_In_Source (Entity (P), False);
603 -- Check for aliased view unless unrestricted case. We allow
604 -- a nonaliased prefix when within an instance because the
605 -- prefix may have been a tagged formal object, which is
606 -- defined to be aliased even when the actual might not be
607 -- (other instance cases will have been caught in the generic).
608 -- Similarly, within an inlined body we know that the attribute
609 -- is legal in the original subprogram, and therefore legal in
612 if Aname /= Name_Unrestricted_Access
613 and then not Is_Aliased_View (P)
614 and then not In_Instance
615 and then not In_Inlined_Body
617 Error_Attr ("prefix of % attribute must be aliased", P);
619 end Analyze_Access_Attribute;
621 --------------------------------
622 -- Check_Array_Or_Scalar_Type --
623 --------------------------------
625 procedure Check_Array_Or_Scalar_Type is
629 -- Dimension number for array attributes.
632 -- Case of string literal or string literal subtype. These cases
633 -- cannot arise from legal Ada code, but the expander is allowed
634 -- to generate them. They require special handling because string
635 -- literal subtypes do not have standard bounds (the whole idea
636 -- of these subtypes is to avoid having to generate the bounds)
638 if Ekind (P_Type) = E_String_Literal_Subtype then
639 Set_Etype (N, Etype (First_Index (P_Base_Type)));
644 elsif Is_Scalar_Type (P_Type) then
648 Error_Attr ("invalid argument in % attribute", E1);
650 Set_Etype (N, P_Base_Type);
654 -- The following is a special test to allow 'First to apply to
655 -- private scalar types if the attribute comes from generated
656 -- code. This occurs in the case of Normalize_Scalars code.
658 elsif Is_Private_Type
(P_Type
)
659 and then Present
(Full_View
(P_Type
))
660 and then Is_Scalar_Type
(Full_View
(P_Type
))
661 and then not Comes_From_Source
(N
)
663 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
665 -- Array types other than string literal subtypes handled above
670 -- We know prefix is an array type, or the name of an array
671 -- object, and that the expression, if present, is static
672 -- and within the range of the dimensions of the type.
674 if Is_Array_Type
(P_Type
) then
675 Index
:= First_Index
(P_Base_Type
);
677 else pragma Assert
(Is_Access_Type
(P_Type
));
678 Index
:= First_Index
(Base_Type
(Designated_Type
(P_Type
)));
683 -- First dimension assumed
685 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
688 D
:= UI_To_Int
(Intval
(E1
));
690 for J
in 1 .. D
- 1 loop
694 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
695 Set_Etype
(E1
, Standard_Integer
);
698 end Check_Array_Or_Scalar_Type
;
700 ----------------------
701 -- Check_Array_Type --
702 ----------------------
704 procedure Check_Array_Type
is
706 -- Dimension number for array attributes.
709 -- If the type is a string literal type, then this must be generated
710 -- internally, and no further check is required on its legality.
712 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
715 -- If the type is a composite, it is an illegal aggregate, no point
718 elsif P_Type
= Any_Composite
then
722 -- Normal case of array type or subtype
724 Check_Either_E0_Or_E1
;
726 if Is_Array_Type
(P_Type
) then
727 if not Is_Constrained
(P_Type
)
728 and then Is_Entity_Name
(P
)
729 and then Is_Type
(Entity
(P
))
731 -- Note: we do not call Error_Attr here, since we prefer to
732 -- continue, using the relevant index type of the array,
733 -- even though it is unconstrained. This gives better error
734 -- recovery behavior.
736 Error_Msg_Name_1
:= Aname
;
738 ("prefix for % attribute must be constrained array", P
);
741 D
:= Number_Dimensions
(P_Type
);
743 elsif Is_Access_Type
(P_Type
)
744 and then Is_Array_Type
(Designated_Type
(P_Type
))
746 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
747 Error_Attr
("prefix of % attribute cannot be access type", P
);
750 D
:= Number_Dimensions
(Designated_Type
(P_Type
));
752 -- If there is an implicit dereference, then we must freeze
753 -- the designated type of the access type, since the type of
754 -- the referenced array is this type (see AI95-00106).
756 Freeze_Before
(N
, Designated_Type
(P_Type
));
759 if Is_Private_Type
(P_Type
) then
761 ("prefix for % attribute may not be private type", P
);
763 elsif Attr_Id
= Attribute_First
765 Attr_Id
= Attribute_Last
767 Error_Attr
("invalid prefix for % attribute", P
);
770 Error_Attr
("prefix for % attribute must be array", P
);
775 Resolve
(E1
, Any_Integer
);
776 Set_Etype
(E1
, Standard_Integer
);
778 if not Is_Static_Expression
(E1
)
779 or else Raises_Constraint_Error
(E1
)
782 ("expression for dimension must be static!", E1
);
785 elsif UI_To_Int
(Expr_Value
(E1
)) > D
786 or else UI_To_Int
(Expr_Value
(E1
)) < 1
788 Error_Attr
("invalid dimension number for array type", E1
);
791 end Check_Array_Type
;
793 -------------------------
794 -- Check_Asm_Attribute --
795 -------------------------
797 procedure Check_Asm_Attribute
is
802 -- Check first argument is static string expression
804 Analyze_And_Resolve
(E1
, Standard_String
);
806 if Etype
(E1
) = Any_Type
then
809 elsif not Is_OK_Static_Expression
(E1
) then
811 ("constraint argument must be static string expression!", E1
);
815 -- Check second argument is right type
817 Analyze_And_Resolve
(E2
, Entity
(P
));
819 -- Note: that is all we need to do, we don't need to check
820 -- that it appears in a correct context. The Ada type system
821 -- will do that for us.
823 end Check_Asm_Attribute
;
825 ---------------------
826 -- Check_Component --
827 ---------------------
829 procedure Check_Component
is
833 if Nkind
(P
) /= N_Selected_Component
835 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
837 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
840 ("prefix for % attribute must be selected component", P
);
844 ------------------------------------
845 -- Check_Decimal_Fixed_Point_Type --
846 ------------------------------------
848 procedure Check_Decimal_Fixed_Point_Type
is
852 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
854 ("prefix of % attribute must be decimal type", P
);
856 end Check_Decimal_Fixed_Point_Type
;
858 -----------------------
859 -- Check_Dereference --
860 -----------------------
862 procedure Check_Dereference
is
865 -- Case of a subtype mark
867 if Is_Entity_Name
(P
)
868 and then Is_Type
(Entity
(P
))
873 -- Case of an expression
876 if Is_Access_Type
(P_Type
) then
878 Make_Explicit_Dereference
(Sloc
(P
),
879 Prefix
=> Relocate_Node
(P
)));
881 Analyze_And_Resolve
(P
);
884 if P_Type
= Any_Type
then
888 P_Base_Type
:= Base_Type
(P_Type
);
890 end Check_Dereference
;
892 -------------------------
893 -- Check_Discrete_Type --
894 -------------------------
896 procedure Check_Discrete_Type
is
900 if not Is_Discrete_Type
(P_Type
) then
901 Error_Attr
("prefix of % attribute must be discrete type", P
);
903 end Check_Discrete_Type
;
909 procedure Check_E0
is
912 Unexpected_Argument
(E1
);
920 procedure Check_E1
is
922 Check_Either_E0_Or_E1
;
926 -- Special-case attributes that are functions and that appear as
927 -- the prefix of another attribute. Error is posted on parent.
929 if Nkind
(Parent
(N
)) = N_Attribute_Reference
930 and then (Attribute_Name
(Parent
(N
)) = Name_Address
932 Attribute_Name
(Parent
(N
)) = Name_Code_Address
934 Attribute_Name
(Parent
(N
)) = Name_Access
)
936 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
937 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
938 Set_Etype
(Parent
(N
), Any_Type
);
939 Set_Entity
(Parent
(N
), Any_Type
);
943 Error_Attr
("missing argument for % attribute", N
);
952 procedure Check_E2
is
955 Error_Attr
("missing arguments for % attribute (2 required)", N
);
957 Error_Attr
("missing argument for % attribute (2 required)", N
);
961 ---------------------------
962 -- Check_Either_E0_Or_E1 --
963 ---------------------------
965 procedure Check_Either_E0_Or_E1
is
968 Unexpected_Argument
(E2
);
970 end Check_Either_E0_Or_E1
;
972 ----------------------
973 -- Check_Enum_Image --
974 ----------------------
976 procedure Check_Enum_Image
is
980 if Is_Enumeration_Type
(P_Base_Type
) then
981 Lit
:= First_Literal
(P_Base_Type
);
982 while Present
(Lit
) loop
983 Set_Referenced
(Lit
);
987 end Check_Enum_Image
;
989 ----------------------------
990 -- Check_Fixed_Point_Type --
991 ----------------------------
993 procedure Check_Fixed_Point_Type
is
997 if not Is_Fixed_Point_Type
(P_Type
) then
998 Error_Attr
("prefix of % attribute must be fixed point type", P
);
1000 end Check_Fixed_Point_Type
;
1002 ------------------------------
1003 -- Check_Fixed_Point_Type_0 --
1004 ------------------------------
1006 procedure Check_Fixed_Point_Type_0
is
1008 Check_Fixed_Point_Type
;
1010 end Check_Fixed_Point_Type_0
;
1012 -------------------------------
1013 -- Check_Floating_Point_Type --
1014 -------------------------------
1016 procedure Check_Floating_Point_Type
is
1020 if not Is_Floating_Point_Type
(P_Type
) then
1021 Error_Attr
("prefix of % attribute must be float type", P
);
1023 end Check_Floating_Point_Type
;
1025 ---------------------------------
1026 -- Check_Floating_Point_Type_0 --
1027 ---------------------------------
1029 procedure Check_Floating_Point_Type_0
is
1031 Check_Floating_Point_Type
;
1033 end Check_Floating_Point_Type_0
;
1035 ---------------------------------
1036 -- Check_Floating_Point_Type_1 --
1037 ---------------------------------
1039 procedure Check_Floating_Point_Type_1
is
1041 Check_Floating_Point_Type
;
1043 end Check_Floating_Point_Type_1
;
1045 ---------------------------------
1046 -- Check_Floating_Point_Type_2 --
1047 ---------------------------------
1049 procedure Check_Floating_Point_Type_2
is
1051 Check_Floating_Point_Type
;
1053 end Check_Floating_Point_Type_2
;
1055 ------------------------
1056 -- Check_Integer_Type --
1057 ------------------------
1059 procedure Check_Integer_Type
is
1063 if not Is_Integer_Type
(P_Type
) then
1064 Error_Attr
("prefix of % attribute must be integer type", P
);
1066 end Check_Integer_Type
;
1068 ------------------------
1069 -- Check_Library_Unit --
1070 ------------------------
1072 procedure Check_Library_Unit
is
1074 if not Is_Compilation_Unit
(Entity
(P
)) then
1075 Error_Attr
("prefix of % attribute must be library unit", P
);
1077 end Check_Library_Unit
;
1079 -------------------------------
1080 -- Check_Not_Incomplete_Type --
1081 -------------------------------
1083 procedure Check_Not_Incomplete_Type
is
1085 if not Is_Entity_Name
(P
)
1086 or else not Is_Type
(Entity
(P
))
1087 or else In_Default_Expression
1092 Check_Fully_Declared
(P_Type
, P
);
1094 end Check_Not_Incomplete_Type
;
1096 ----------------------------
1097 -- Check_Object_Reference --
1098 ----------------------------
1100 procedure Check_Object_Reference
(P
: Node_Id
) is
1104 -- If we need an object, and we have a prefix that is the name of
1105 -- a function entity, convert it into a function call.
1107 if Is_Entity_Name
(P
)
1108 and then Ekind
(Entity
(P
)) = E_Function
1110 Rtyp
:= Etype
(Entity
(P
));
1113 Make_Function_Call
(Sloc
(P
),
1114 Name
=> Relocate_Node
(P
)));
1116 Analyze_And_Resolve
(P
, Rtyp
);
1118 -- Otherwise we must have an object reference
1120 elsif not Is_Object_Reference
(P
) then
1121 Error_Attr
("prefix of % attribute must be object", P
);
1123 end Check_Object_Reference
;
1125 ------------------------
1126 -- Check_Program_Unit --
1127 ------------------------
1129 procedure Check_Program_Unit
is
1131 if Is_Entity_Name
(P
) then
1133 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1134 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1137 if K
in Subprogram_Kind
1138 or else K
in Task_Kind
1139 or else K
in Protected_Kind
1140 or else K
= E_Package
1141 or else K
in Generic_Unit_Kind
1142 or else (K
= E_Variable
1146 Is_Protected_Type
(T
)))
1153 Error_Attr
("prefix of % attribute must be program unit", P
);
1154 end Check_Program_Unit
;
1156 ---------------------
1157 -- Check_Real_Type --
1158 ---------------------
1160 procedure Check_Real_Type
is
1164 if not Is_Real_Type
(P_Type
) then
1165 Error_Attr
("prefix of % attribute must be real type", P
);
1167 end Check_Real_Type
;
1169 -----------------------
1170 -- Check_Scalar_Type --
1171 -----------------------
1173 procedure Check_Scalar_Type
is
1177 if not Is_Scalar_Type
(P_Type
) then
1178 Error_Attr
("prefix of % attribute must be scalar type", P
);
1180 end Check_Scalar_Type
;
1182 ---------------------------
1183 -- Check_Standard_Prefix --
1184 ---------------------------
1186 procedure Check_Standard_Prefix
is
1190 if Nkind
(P
) /= N_Identifier
1191 or else Chars
(P
) /= Name_Standard
1193 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1196 end Check_Standard_Prefix
;
1198 ----------------------------
1199 -- Check_Stream_Attribute --
1200 ----------------------------
1202 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1207 Validate_Non_Static_Attribute_Function_Call
;
1209 -- With the exception of 'Input, Stream attributes are procedures,
1210 -- and can only appear at the position of procedure calls. We check
1211 -- for this here, before they are rewritten, to give a more precise
1214 if Nam
= TSS_Stream_Input
then
1217 elsif Is_List_Member
(N
)
1218 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1219 and then Nkind
(Parent
(N
)) /= N_Aggregate
1225 ("invalid context for attribute%, which is a procedure", N
);
1229 Btyp
:= Implementation_Base_Type
(P_Type
);
1231 -- Stream attributes not allowed on limited types unless the
1232 -- special OK_For_Stream flag is set.
1234 if Is_Limited_Type
(P_Type
)
1235 and then Comes_From_Source
(N
)
1236 and then not Present
(TSS
(Btyp
, Nam
))
1237 and then No
(Get_Rep_Pragma
(Btyp
, Name_Stream_Convert
))
1239 Error_Msg_Name_1
:= Aname
;
1241 ("limited type& has no% attribute", P
, Btyp
);
1242 Explain_Limited_Type
(P_Type
, P
);
1245 -- Check for violation of restriction No_Stream_Attributes
1247 if Is_RTE
(P_Type
, RE_Exception_Id
)
1249 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1251 Check_Restriction
(No_Exception_Registration
, P
);
1254 -- Here we must check that the first argument is an access type
1255 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1257 Analyze_And_Resolve
(E1
);
1260 -- Note: the double call to Root_Type here is needed because the
1261 -- root type of a class-wide type is the corresponding type (e.g.
1262 -- X for X'Class, and we really want to go to the root.
1264 if not Is_Access_Type
(Etyp
)
1265 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1266 RTE
(RE_Root_Stream_Type
)
1269 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1272 -- Check that the second argument is of the right type if there is
1273 -- one (the Input attribute has only one argument so this is skipped)
1275 if Present
(E2
) then
1278 if Nam
= TSS_Stream_Read
1279 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1282 ("second argument of % attribute must be a variable", E2
);
1285 Resolve
(E2
, P_Type
);
1287 end Check_Stream_Attribute
;
1289 -----------------------
1290 -- Check_Task_Prefix --
1291 -----------------------
1293 procedure Check_Task_Prefix
is
1297 if Is_Task_Type
(Etype
(P
))
1298 or else (Is_Access_Type
(Etype
(P
))
1299 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1303 Error_Attr
("prefix of % attribute must be a task", P
);
1305 end Check_Task_Prefix
;
1311 -- The possibilities are an entity name denoting a type, or an
1312 -- attribute reference that denotes a type (Base or Class). If
1313 -- the type is incomplete, replace it with its full view.
1315 procedure Check_Type
is
1317 if not Is_Entity_Name
(P
)
1318 or else not Is_Type
(Entity
(P
))
1320 Error_Attr
("prefix of % attribute must be a type", P
);
1322 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1323 and then Present
(Full_View
(Entity
(P
)))
1325 P_Type
:= Full_View
(Entity
(P
));
1326 Set_Entity
(P
, P_Type
);
1330 ---------------------
1331 -- Check_Unit_Name --
1332 ---------------------
1334 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1336 if Nkind
(Nod
) = N_Identifier
then
1339 elsif Nkind
(Nod
) = N_Selected_Component
then
1340 Check_Unit_Name
(Prefix
(Nod
));
1342 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1347 Error_Attr
("argument for % attribute must be unit name", P
);
1348 end Check_Unit_Name
;
1354 procedure Error_Attr
is
1356 Set_Etype
(N
, Any_Type
);
1357 Set_Entity
(N
, Any_Type
);
1358 raise Bad_Attribute
;
1361 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1363 Error_Msg_Name_1
:= Aname
;
1364 Error_Msg_N
(Msg
, Error_Node
);
1368 ----------------------------
1369 -- Legal_Formal_Attribute --
1370 ----------------------------
1372 procedure Legal_Formal_Attribute
is
1376 if not Is_Entity_Name
(P
)
1377 or else not Is_Type
(Entity
(P
))
1379 Error_Attr
("prefix of % attribute must be generic type", N
);
1381 elsif Is_Generic_Actual_Type
(Entity
(P
))
1383 or else In_Inlined_Body
1387 elsif Is_Generic_Type
(Entity
(P
)) then
1388 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1390 ("prefix of % attribute must be indefinite generic type", N
);
1395 ("prefix of % attribute must be indefinite generic type", N
);
1398 Set_Etype
(N
, Standard_Boolean
);
1399 end Legal_Formal_Attribute
;
1401 ------------------------
1402 -- Standard_Attribute --
1403 ------------------------
1405 procedure Standard_Attribute
(Val
: Int
) is
1407 Check_Standard_Prefix
;
1409 -- First a special check (more like a kludge really). For GNAT5
1410 -- on Windows, the alignments in GCC are severely mixed up. In
1411 -- particular, we have a situation where the maximum alignment
1412 -- that GCC thinks is possible is greater than the guaranteed
1413 -- alignment at run-time. That causes many problems. As a partial
1414 -- cure for this situation, we force a value of 4 for the maximum
1415 -- alignment attribute on this target. This still does not solve
1416 -- all problems, but it helps.
1418 -- A further (even more horrible) dimension to this kludge is now
1419 -- installed. There are two uses for Maximum_Alignment, one is to
1420 -- determine the maximum guaranteed alignment, that's the one we
1421 -- want the kludge to yield as 4. The other use is to maximally
1422 -- align objects, we can't use 4 here, since for example, long
1423 -- long integer has an alignment of 8, so we will get errors.
1425 -- It is of course impossible to determine which use the programmer
1426 -- has in mind, but an approximation for now is to disconnect the
1427 -- kludge if the attribute appears in an alignment clause.
1429 -- To be removed if GCC ever gets its act together here ???
1431 Alignment_Kludge
: declare
1434 function On_X86
return Boolean;
1435 -- Determine if target is x86 (ia32), return True if so
1441 function On_X86
return Boolean is
1442 T
: constant String := Sdefault
.Target_Name
.all;
1445 -- There is no clean way to check this. That's not surprising,
1446 -- the front end should not be doing this kind of test ???. The
1447 -- way we do it is test for either "86" or "pentium" being in
1448 -- the string for the target name.
1450 for J
in T
'First .. T
'Last - 1 loop
1451 if T
(J
.. J
+ 1) = "86"
1452 or else (J
<= T
'Last - 6
1453 and then T
(J
.. J
+ 6) = "pentium")
1463 if Aname
= Name_Maximum_Alignment
and then On_X86
then
1466 while Nkind
(P
) in N_Subexpr
loop
1470 if Nkind
(P
) /= N_Attribute_Definition_Clause
1471 or else Chars
(P
) /= Name_Alignment
1473 Rewrite
(N
, Make_Integer_Literal
(Loc
, 4));
1478 end Alignment_Kludge
;
1480 -- Normally we get the value from gcc ???
1482 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1484 end Standard_Attribute
;
1486 -------------------------
1487 -- Unexpected Argument --
1488 -------------------------
1490 procedure Unexpected_Argument
(En
: Node_Id
) is
1492 Error_Attr
("unexpected argument for % attribute", En
);
1493 end Unexpected_Argument
;
1495 -------------------------------------------------
1496 -- Validate_Non_Static_Attribute_Function_Call --
1497 -------------------------------------------------
1499 -- This function should be moved to Sem_Dist ???
1501 procedure Validate_Non_Static_Attribute_Function_Call
is
1503 if In_Preelaborated_Unit
1504 and then not In_Subprogram_Or_Concurrent_Unit
1506 Flag_Non_Static_Expr
1507 ("non-static function call in preelaborated unit!", N
);
1509 end Validate_Non_Static_Attribute_Function_Call
;
1511 -----------------------------------------------
1512 -- Start of Processing for Analyze_Attribute --
1513 -----------------------------------------------
1516 -- Immediate return if unrecognized attribute (already diagnosed
1517 -- by parser, so there is nothing more that we need to do)
1519 if not Is_Attribute_Name
(Aname
) then
1520 raise Bad_Attribute
;
1523 -- Deal with Ada 83 and Features issues
1525 if Comes_From_Source
(N
) then
1526 if not Attribute_83
(Attr_Id
) then
1527 if Ada_83
and then Comes_From_Source
(N
) then
1528 Error_Msg_Name_1
:= Aname
;
1529 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1532 if Attribute_Impl_Def
(Attr_Id
) then
1533 Check_Restriction
(No_Implementation_Attributes
, N
);
1538 -- Remote access to subprogram type access attribute reference needs
1539 -- unanalyzed copy for tree transformation. The analyzed copy is used
1540 -- for its semantic information (whether prefix is a remote subprogram
1541 -- name), the unanalyzed copy is used to construct new subtree rooted
1542 -- with N_aggregate which represents a fat pointer aggregate.
1544 if Aname
= Name_Access
then
1545 Discard_Node
(Copy_Separate_Tree
(N
));
1548 -- Analyze prefix and exit if error in analysis. If the prefix is an
1549 -- incomplete type, use full view if available. A special case is
1550 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1551 -- or UET_Address attribute.
1553 if Aname
/= Name_Elab_Body
1555 Aname
/= Name_Elab_Spec
1557 Aname
/= Name_UET_Address
1560 P_Type
:= Etype
(P
);
1562 if Is_Entity_Name
(P
)
1563 and then Present
(Entity
(P
))
1564 and then Is_Type
(Entity
(P
))
1565 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1567 P_Type
:= Get_Full_View
(P_Type
);
1568 Set_Entity
(P
, P_Type
);
1569 Set_Etype
(P
, P_Type
);
1572 if P_Type
= Any_Type
then
1573 raise Bad_Attribute
;
1576 P_Base_Type
:= Base_Type
(P_Type
);
1579 -- Analyze expressions that may be present, exiting if an error occurs
1586 E1
:= First
(Exprs
);
1589 -- Check for missing or bad expression (result of previous error)
1591 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1592 raise Bad_Attribute
;
1597 if Present
(E2
) then
1600 if Etype
(E2
) = Any_Type
then
1601 raise Bad_Attribute
;
1604 if Present
(Next
(E2
)) then
1605 Unexpected_Argument
(Next
(E2
));
1610 if Is_Overloaded
(P
)
1611 and then Aname
/= Name_Access
1612 and then Aname
/= Name_Address
1613 and then Aname
/= Name_Code_Address
1614 and then Aname
/= Name_Count
1615 and then Aname
/= Name_Unchecked_Access
1617 Error_Attr
("ambiguous prefix for % attribute", P
);
1620 -- Remaining processing depends on attribute
1628 when Attribute_Abort_Signal
=>
1629 Check_Standard_Prefix
;
1631 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1638 when Attribute_Access
=>
1639 Analyze_Access_Attribute
;
1645 when Attribute_Address
=>
1648 -- Check for some junk cases, where we have to allow the address
1649 -- attribute but it does not make much sense, so at least for now
1650 -- just replace with Null_Address.
1652 -- We also do this if the prefix is a reference to the AST_Entry
1653 -- attribute. If expansion is active, the attribute will be
1654 -- replaced by a function call, and address will work fine and
1655 -- get the proper value, but if expansion is not active, then
1656 -- the check here allows proper semantic analysis of the reference.
1658 -- An Address attribute created by expansion is legal even when it
1659 -- applies to other entity-denoting expressions.
1661 if Is_Entity_Name
(P
) then
1663 Ent
: constant Entity_Id
:= Entity
(P
);
1666 if Is_Subprogram
(Ent
) then
1667 if not Is_Library_Level_Entity
(Ent
) then
1668 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1671 Set_Address_Taken
(Ent
);
1673 elsif Is_Object
(Ent
)
1674 or else Ekind
(Ent
) = E_Label
1676 Set_Address_Taken
(Ent
);
1678 -- If we have an address of an object, and the attribute
1679 -- comes from source, then set the object as potentially
1680 -- source modified. We do this because the resulting address
1681 -- can potentially be used to modify the variable and we
1682 -- might not detect this, leading to some junk warnings.
1684 Set_Never_Set_In_Source
(Ent
, False);
1686 elsif (Is_Concurrent_Type
(Etype
(Ent
))
1687 and then Etype
(Ent
) = Base_Type
(Ent
))
1688 or else Ekind
(Ent
) = E_Package
1689 or else Is_Generic_Unit
(Ent
)
1692 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1695 Error_Attr
("invalid prefix for % attribute", P
);
1699 elsif Nkind
(P
) = N_Attribute_Reference
1700 and then Attribute_Name
(P
) = Name_AST_Entry
1703 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1705 elsif Is_Object_Reference
(P
) then
1708 elsif Nkind
(P
) = N_Selected_Component
1709 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1713 -- What exactly are we allowing here ??? and is this properly
1714 -- documented in the sinfo documentation for this node ???
1716 elsif not Comes_From_Source
(N
) then
1720 Error_Attr
("invalid prefix for % attribute", P
);
1723 Set_Etype
(N
, RTE
(RE_Address
));
1729 when Attribute_Address_Size
=>
1730 Standard_Attribute
(System_Address_Size
);
1736 when Attribute_Adjacent
=>
1737 Check_Floating_Point_Type_2
;
1738 Set_Etype
(N
, P_Base_Type
);
1739 Resolve
(E1
, P_Base_Type
);
1740 Resolve
(E2
, P_Base_Type
);
1746 when Attribute_Aft
=>
1747 Check_Fixed_Point_Type_0
;
1748 Set_Etype
(N
, Universal_Integer
);
1754 when Attribute_Alignment
=>
1756 -- Don't we need more checking here, cf Size ???
1759 Check_Not_Incomplete_Type
;
1760 Set_Etype
(N
, Universal_Integer
);
1766 when Attribute_Asm_Input
=>
1767 Check_Asm_Attribute
;
1768 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1774 when Attribute_Asm_Output
=>
1775 Check_Asm_Attribute
;
1777 if Etype
(E2
) = Any_Type
then
1780 elsif Aname
= Name_Asm_Output
then
1781 if not Is_Variable
(E2
) then
1783 ("second argument for Asm_Output is not variable", E2
);
1787 Note_Possible_Modification
(E2
);
1788 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1794 when Attribute_AST_Entry
=> AST_Entry
: declare
1800 -- Indicates if entry family index is present. Note the coding
1801 -- here handles the entry family case, but in fact it cannot be
1802 -- executed currently, because pragma AST_Entry does not permit
1803 -- the specification of an entry family.
1805 procedure Bad_AST_Entry
;
1806 -- Signal a bad AST_Entry pragma
1808 function OK_Entry
(E
: Entity_Id
) return Boolean;
1809 -- Checks that E is of an appropriate entity kind for an entry
1810 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1811 -- is set True for the entry family case). In the True case,
1812 -- makes sure that Is_AST_Entry is set on the entry.
1814 procedure Bad_AST_Entry
is
1816 Error_Attr
("prefix for % attribute must be task entry", P
);
1819 function OK_Entry
(E
: Entity_Id
) return Boolean is
1824 Result
:= (Ekind
(E
) = E_Entry_Family
);
1826 Result
:= (Ekind
(E
) = E_Entry
);
1830 if not Is_AST_Entry
(E
) then
1831 Error_Msg_Name_2
:= Aname
;
1833 ("% attribute requires previous % pragma", P
);
1840 -- Start of processing for AST_Entry
1846 -- Deal with entry family case
1848 if Nkind
(P
) = N_Indexed_Component
then
1856 Ptyp
:= Etype
(Pref
);
1858 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
1862 -- If the prefix is a selected component whose prefix is of an
1863 -- access type, then introduce an explicit dereference.
1865 if Nkind
(Pref
) = N_Selected_Component
1866 and then Is_Access_Type
(Ptyp
)
1869 Make_Explicit_Dereference
(Sloc
(Pref
),
1870 Relocate_Node
(Pref
)));
1871 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
1874 -- Prefix can be of the form a.b, where a is a task object
1875 -- and b is one of the entries of the corresponding task type.
1877 if Nkind
(Pref
) = N_Selected_Component
1878 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
1879 and then Is_Object_Reference
(Prefix
(Pref
))
1880 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
1884 -- Otherwise the prefix must be an entry of a containing task,
1885 -- or of a variable of the enclosing task type.
1888 if Nkind
(Pref
) = N_Identifier
1889 or else Nkind
(Pref
) = N_Expanded_Name
1891 Ent
:= Entity
(Pref
);
1893 if not OK_Entry
(Ent
)
1894 or else not In_Open_Scopes
(Scope
(Ent
))
1904 Set_Etype
(N
, RTE
(RE_AST_Handler
));
1911 -- Note: when the base attribute appears in the context of a subtype
1912 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
1913 -- the following circuit.
1915 when Attribute_Base
=> Base
: declare
1919 Check_Either_E0_Or_E1
;
1924 and then not Is_Scalar_Type
(Typ
)
1925 and then not Is_Generic_Type
(Typ
)
1927 Error_Msg_N
("prefix of Base attribute must be scalar type", N
);
1929 elsif Sloc
(Typ
) = Standard_Location
1930 and then Base_Type
(Typ
) = Typ
1931 and then Warn_On_Redundant_Constructs
1934 ("?redudant attribute, & is its own base type", N
, Typ
);
1937 Set_Etype
(N
, Base_Type
(Entity
(P
)));
1939 -- If we have an expression present, then really this is a conversion
1940 -- and the tree must be reformed. Note that this is one of the cases
1941 -- in which we do a replace rather than a rewrite, because the
1942 -- original tree is junk.
1944 if Present
(E1
) then
1946 Make_Type_Conversion
(Loc
,
1948 Make_Attribute_Reference
(Loc
,
1949 Prefix
=> Prefix
(N
),
1950 Attribute_Name
=> Name_Base
),
1951 Expression
=> Relocate_Node
(E1
)));
1953 -- E1 may be overloaded, and its interpretations preserved.
1955 Save_Interps
(E1
, Expression
(N
));
1958 -- For other cases, set the proper type as the entity of the
1959 -- attribute reference, and then rewrite the node to be an
1960 -- occurrence of the referenced base type. This way, no one
1961 -- else in the compiler has to worry about the base attribute.
1964 Set_Entity
(N
, Base_Type
(Entity
(P
)));
1966 New_Reference_To
(Entity
(N
), Loc
));
1975 when Attribute_Bit
=> Bit
:
1979 if not Is_Object_Reference
(P
) then
1980 Error_Attr
("prefix for % attribute must be object", P
);
1982 -- What about the access object cases ???
1988 Set_Etype
(N
, Universal_Integer
);
1995 when Attribute_Bit_Order
=> Bit_Order
:
2000 if not Is_Record_Type
(P_Type
) then
2001 Error_Attr
("prefix of % attribute must be record type", P
);
2004 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2006 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2009 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2012 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2015 -- Reset incorrect indication of staticness
2017 Set_Is_Static_Expression
(N
, False);
2024 -- Note: in generated code, we can have a Bit_Position attribute
2025 -- applied to a (naked) record component (i.e. the prefix is an
2026 -- identifier that references an E_Component or E_Discriminant
2027 -- entity directly, and this is interpreted as expected by Gigi.
2028 -- The following code will not tolerate such usage, but when the
2029 -- expander creates this special case, it marks it as analyzed
2030 -- immediately and sets an appropriate type.
2032 when Attribute_Bit_Position
=>
2034 if Comes_From_Source
(N
) then
2038 Set_Etype
(N
, Universal_Integer
);
2044 when Attribute_Body_Version
=>
2047 Set_Etype
(N
, RTE
(RE_Version_String
));
2053 when Attribute_Callable
=>
2055 Set_Etype
(N
, Standard_Boolean
);
2062 when Attribute_Caller
=> Caller
: declare
2069 if Nkind
(P
) = N_Identifier
2070 or else Nkind
(P
) = N_Expanded_Name
2074 if not Is_Entry
(Ent
) then
2075 Error_Attr
("invalid entry name", N
);
2079 Error_Attr
("invalid entry name", N
);
2083 for J
in reverse 0 .. Scope_Stack
.Last
loop
2084 S
:= Scope_Stack
.Table
(J
).Entity
;
2086 if S
= Scope
(Ent
) then
2087 Error_Attr
("Caller must appear in matching accept or body", N
);
2093 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2100 when Attribute_Ceiling
=>
2101 Check_Floating_Point_Type_1
;
2102 Set_Etype
(N
, P_Base_Type
);
2103 Resolve
(E1
, P_Base_Type
);
2109 when Attribute_Class
=> Class
: declare
2111 Check_Restriction
(No_Dispatch
, N
);
2112 Check_Either_E0_Or_E1
;
2114 -- If we have an expression present, then really this is a conversion
2115 -- and the tree must be reformed into a proper conversion. This is a
2116 -- Replace rather than a Rewrite, because the original tree is junk.
2117 -- If expression is overloaded, propagate interpretations to new one.
2119 if Present
(E1
) then
2121 Make_Type_Conversion
(Loc
,
2123 Make_Attribute_Reference
(Loc
,
2124 Prefix
=> Prefix
(N
),
2125 Attribute_Name
=> Name_Class
),
2126 Expression
=> Relocate_Node
(E1
)));
2128 Save_Interps
(E1
, Expression
(N
));
2131 -- Otherwise we just need to find the proper type
2143 when Attribute_Code_Address
=>
2146 if Nkind
(P
) = N_Attribute_Reference
2147 and then (Attribute_Name
(P
) = Name_Elab_Body
2149 Attribute_Name
(P
) = Name_Elab_Spec
)
2153 elsif not Is_Entity_Name
(P
)
2154 or else (Ekind
(Entity
(P
)) /= E_Function
2156 Ekind
(Entity
(P
)) /= E_Procedure
)
2158 Error_Attr
("invalid prefix for % attribute", P
);
2159 Set_Address_Taken
(Entity
(P
));
2162 Set_Etype
(N
, RTE
(RE_Address
));
2164 --------------------
2165 -- Component_Size --
2166 --------------------
2168 when Attribute_Component_Size
=>
2170 Set_Etype
(N
, Universal_Integer
);
2172 -- Note: unlike other array attributes, unconstrained arrays are OK
2174 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2184 when Attribute_Compose
=>
2185 Check_Floating_Point_Type_2
;
2186 Set_Etype
(N
, P_Base_Type
);
2187 Resolve
(E1
, P_Base_Type
);
2188 Resolve
(E2
, Any_Integer
);
2194 when Attribute_Constrained
=>
2196 Set_Etype
(N
, Standard_Boolean
);
2198 -- Case from RM J.4(2) of constrained applied to private type
2200 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2202 -- If we are within an instance, the attribute must be legal
2203 -- because it was valid in the generic unit. Ditto if this is
2204 -- an inlining of a function declared in an instance.
2207 or else In_Inlined_Body
2211 -- For sure OK if we have a real private type itself, but must
2212 -- be completed, cannot apply Constrained to incomplete type.
2214 elsif Is_Private_Type
(Entity
(P
)) then
2216 -- Note: this is one of the Annex J features that does not
2217 -- generate a warning from -gnatwj, since in fact it seems
2218 -- very useful, and is used in the GNAT runtime.
2220 Check_Not_Incomplete_Type
;
2224 -- Normal (non-obsolescent case) of application to object of
2225 -- a discriminated type.
2228 Check_Object_Reference
(P
);
2230 -- If N does not come from source, then we allow the
2231 -- the attribute prefix to be of a private type whose
2232 -- full type has discriminants. This occurs in cases
2233 -- involving expanded calls to stream attributes.
2235 if not Comes_From_Source
(N
) then
2236 P_Type
:= Underlying_Type
(P_Type
);
2239 -- Must have discriminants or be an access type designating
2240 -- a type with discriminants. If it is a classwide type is
2241 -- has unknown discriminants.
2243 if Has_Discriminants
(P_Type
)
2244 or else Has_Unknown_Discriminants
(P_Type
)
2246 (Is_Access_Type
(P_Type
)
2247 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2251 -- Also allow an object of a generic type if extensions allowed
2252 -- and allow this for any type at all.
2254 elsif (Is_Generic_Type
(P_Type
)
2255 or else Is_Generic_Actual_Type
(P_Type
))
2256 and then Extensions_Allowed
2262 -- Fall through if bad prefix
2265 ("prefix of % attribute must be object of discriminated type", P
);
2271 when Attribute_Copy_Sign
=>
2272 Check_Floating_Point_Type_2
;
2273 Set_Etype
(N
, P_Base_Type
);
2274 Resolve
(E1
, P_Base_Type
);
2275 Resolve
(E2
, P_Base_Type
);
2281 when Attribute_Count
=> Count
:
2290 if Nkind
(P
) = N_Identifier
2291 or else Nkind
(P
) = N_Expanded_Name
2295 if Ekind
(Ent
) /= E_Entry
then
2296 Error_Attr
("invalid entry name", N
);
2299 elsif Nkind
(P
) = N_Indexed_Component
then
2300 if not Is_Entity_Name
(Prefix
(P
))
2301 or else No
(Entity
(Prefix
(P
)))
2302 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2304 if Nkind
(Prefix
(P
)) = N_Selected_Component
2305 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2306 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2310 ("attribute % must apply to entry of current task", P
);
2313 Error_Attr
("invalid entry family name", P
);
2318 Ent
:= Entity
(Prefix
(P
));
2321 elsif Nkind
(P
) = N_Selected_Component
2322 and then Present
(Entity
(Selector_Name
(P
)))
2323 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2326 ("attribute % must apply to entry of current task", P
);
2329 Error_Attr
("invalid entry name", N
);
2333 for J
in reverse 0 .. Scope_Stack
.Last
loop
2334 S
:= Scope_Stack
.Table
(J
).Entity
;
2336 if S
= Scope
(Ent
) then
2337 if Nkind
(P
) = N_Expanded_Name
then
2338 Tsk
:= Entity
(Prefix
(P
));
2340 -- The prefix denotes either the task type, or else a
2341 -- single task whose task type is being analyzed.
2346 or else (not Is_Type
(Tsk
)
2347 and then Etype
(Tsk
) = S
2348 and then not (Comes_From_Source
(S
)))
2353 ("Attribute % must apply to entry of current task", N
);
2359 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2360 and then Ekind
(S
) /= E_Loop
2361 and then Ekind
(S
) /= E_Block
2362 and then Ekind
(S
) /= E_Entry
2363 and then Ekind
(S
) /= E_Entry_Family
2365 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2367 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2368 and then not Has_Completion
(Scope
(Ent
))
2370 Error_Attr
("attribute % can only be used inside body", N
);
2374 if Is_Overloaded
(P
) then
2376 Index
: Interp_Index
;
2380 Get_First_Interp
(P
, Index
, It
);
2382 while Present
(It
.Nam
) loop
2383 if It
.Nam
= Ent
then
2387 Error_Attr
("ambiguous entry name", N
);
2390 Get_Next_Interp
(Index
, It
);
2395 Set_Etype
(N
, Universal_Integer
);
2398 -----------------------
2399 -- Default_Bit_Order --
2400 -----------------------
2402 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2404 Check_Standard_Prefix
;
2407 if Bytes_Big_Endian
then
2409 Make_Integer_Literal
(Loc
, False_Value
));
2412 Make_Integer_Literal
(Loc
, True_Value
));
2415 Set_Etype
(N
, Universal_Integer
);
2416 Set_Is_Static_Expression
(N
);
2417 end Default_Bit_Order
;
2423 when Attribute_Definite
=>
2424 Legal_Formal_Attribute
;
2430 when Attribute_Delta
=>
2431 Check_Fixed_Point_Type_0
;
2432 Set_Etype
(N
, Universal_Real
);
2438 when Attribute_Denorm
=>
2439 Check_Floating_Point_Type_0
;
2440 Set_Etype
(N
, Standard_Boolean
);
2446 when Attribute_Digits
=>
2450 if not Is_Floating_Point_Type
(P_Type
)
2451 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2454 ("prefix of % attribute must be float or decimal type", P
);
2457 Set_Etype
(N
, Universal_Integer
);
2463 -- Also handles processing for Elab_Spec
2465 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2467 Check_Unit_Name
(P
);
2468 Set_Etype
(N
, Standard_Void_Type
);
2470 -- We have to manually call the expander in this case to get
2471 -- the necessary expansion (normally attributes that return
2472 -- entities are not expanded).
2480 -- Shares processing with Elab_Body
2486 when Attribute_Elaborated
=>
2489 Set_Etype
(N
, Standard_Boolean
);
2495 when Attribute_Emax
=>
2496 Check_Floating_Point_Type_0
;
2497 Set_Etype
(N
, Universal_Integer
);
2503 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2505 if Present
(E1
) then
2507 Check_Discrete_Type
;
2508 Resolve
(E1
, P_Base_Type
);
2511 if not Is_Entity_Name
(P
)
2512 or else (not Is_Object
(Entity
(P
))
2514 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2517 ("prefix of %attribute must be " &
2518 "discrete type/object or enum literal", P
);
2522 Set_Etype
(N
, Universal_Integer
);
2529 when Attribute_Epsilon
=>
2530 Check_Floating_Point_Type_0
;
2531 Set_Etype
(N
, Universal_Real
);
2537 when Attribute_Exponent
=>
2538 Check_Floating_Point_Type_1
;
2539 Set_Etype
(N
, Universal_Integer
);
2540 Resolve
(E1
, P_Base_Type
);
2546 when Attribute_External_Tag
=>
2550 Set_Etype
(N
, Standard_String
);
2552 if not Is_Tagged_Type
(P_Type
) then
2553 Error_Attr
("prefix of % attribute must be tagged", P
);
2560 when Attribute_First
=>
2561 Check_Array_Or_Scalar_Type
;
2567 when Attribute_First_Bit
=>
2569 Set_Etype
(N
, Universal_Integer
);
2575 when Attribute_Fixed_Value
=>
2577 Check_Fixed_Point_Type
;
2578 Resolve
(E1
, Any_Integer
);
2579 Set_Etype
(N
, P_Base_Type
);
2585 when Attribute_Floor
=>
2586 Check_Floating_Point_Type_1
;
2587 Set_Etype
(N
, P_Base_Type
);
2588 Resolve
(E1
, P_Base_Type
);
2594 when Attribute_Fore
=>
2595 Check_Fixed_Point_Type_0
;
2596 Set_Etype
(N
, Universal_Integer
);
2602 when Attribute_Fraction
=>
2603 Check_Floating_Point_Type_1
;
2604 Set_Etype
(N
, P_Base_Type
);
2605 Resolve
(E1
, P_Base_Type
);
2607 -----------------------
2608 -- Has_Discriminants --
2609 -----------------------
2611 when Attribute_Has_Discriminants
=>
2612 Legal_Formal_Attribute
;
2618 when Attribute_Identity
=>
2622 if Etype
(P
) = Standard_Exception_Type
then
2623 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2625 elsif Is_Task_Type
(Etype
(P
))
2626 or else (Is_Access_Type
(Etype
(P
))
2627 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2630 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2633 Error_Attr
("prefix of % attribute must be a task or an "
2641 when Attribute_Image
=> Image
:
2643 Set_Etype
(N
, Standard_String
);
2646 if Is_Real_Type
(P_Type
) then
2647 if Ada_83
and then Comes_From_Source
(N
) then
2648 Error_Msg_Name_1
:= Aname
;
2650 ("(Ada 83) % attribute not allowed for real types", N
);
2654 if Is_Enumeration_Type
(P_Type
) then
2655 Check_Restriction
(No_Enumeration_Maps
, N
);
2659 Resolve
(E1
, P_Base_Type
);
2661 Validate_Non_Static_Attribute_Function_Call
;
2668 when Attribute_Img
=> Img
:
2670 Set_Etype
(N
, Standard_String
);
2672 if not Is_Scalar_Type
(P_Type
)
2673 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2676 ("prefix of % attribute must be scalar object name", N
);
2686 when Attribute_Input
=>
2688 Check_Stream_Attribute
(TSS_Stream_Input
);
2689 Set_Etype
(N
, P_Base_Type
);
2695 when Attribute_Integer_Value
=>
2698 Resolve
(E1
, Any_Fixed
);
2699 Set_Etype
(N
, P_Base_Type
);
2705 when Attribute_Large
=>
2708 Set_Etype
(N
, Universal_Real
);
2714 when Attribute_Last
=>
2715 Check_Array_Or_Scalar_Type
;
2721 when Attribute_Last_Bit
=>
2723 Set_Etype
(N
, Universal_Integer
);
2729 when Attribute_Leading_Part
=>
2730 Check_Floating_Point_Type_2
;
2731 Set_Etype
(N
, P_Base_Type
);
2732 Resolve
(E1
, P_Base_Type
);
2733 Resolve
(E2
, Any_Integer
);
2739 when Attribute_Length
=>
2741 Set_Etype
(N
, Universal_Integer
);
2747 when Attribute_Machine
=>
2748 Check_Floating_Point_Type_1
;
2749 Set_Etype
(N
, P_Base_Type
);
2750 Resolve
(E1
, P_Base_Type
);
2756 when Attribute_Machine_Emax
=>
2757 Check_Floating_Point_Type_0
;
2758 Set_Etype
(N
, Universal_Integer
);
2764 when Attribute_Machine_Emin
=>
2765 Check_Floating_Point_Type_0
;
2766 Set_Etype
(N
, Universal_Integer
);
2768 ----------------------
2769 -- Machine_Mantissa --
2770 ----------------------
2772 when Attribute_Machine_Mantissa
=>
2773 Check_Floating_Point_Type_0
;
2774 Set_Etype
(N
, Universal_Integer
);
2776 -----------------------
2777 -- Machine_Overflows --
2778 -----------------------
2780 when Attribute_Machine_Overflows
=>
2783 Set_Etype
(N
, Standard_Boolean
);
2789 when Attribute_Machine_Radix
=>
2792 Set_Etype
(N
, Universal_Integer
);
2794 --------------------
2795 -- Machine_Rounds --
2796 --------------------
2798 when Attribute_Machine_Rounds
=>
2801 Set_Etype
(N
, Standard_Boolean
);
2807 when Attribute_Machine_Size
=>
2810 Check_Not_Incomplete_Type
;
2811 Set_Etype
(N
, Universal_Integer
);
2817 when Attribute_Mantissa
=>
2820 Set_Etype
(N
, Universal_Integer
);
2826 when Attribute_Max
=>
2829 Resolve
(E1
, P_Base_Type
);
2830 Resolve
(E2
, P_Base_Type
);
2831 Set_Etype
(N
, P_Base_Type
);
2833 ----------------------------------
2834 -- Max_Size_In_Storage_Elements --
2835 ----------------------------------
2837 when Attribute_Max_Size_In_Storage_Elements
=>
2840 Check_Not_Incomplete_Type
;
2841 Set_Etype
(N
, Universal_Integer
);
2843 -----------------------
2844 -- Maximum_Alignment --
2845 -----------------------
2847 when Attribute_Maximum_Alignment
=>
2848 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
2850 --------------------
2851 -- Mechanism_Code --
2852 --------------------
2854 when Attribute_Mechanism_Code
=>
2855 if not Is_Entity_Name
(P
)
2856 or else not Is_Subprogram
(Entity
(P
))
2858 Error_Attr
("prefix of % attribute must be subprogram", P
);
2861 Check_Either_E0_Or_E1
;
2863 if Present
(E1
) then
2864 Resolve
(E1
, Any_Integer
);
2865 Set_Etype
(E1
, Standard_Integer
);
2867 if not Is_Static_Expression
(E1
) then
2868 Flag_Non_Static_Expr
2869 ("expression for parameter number must be static!", E1
);
2872 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
2873 or else UI_To_Int
(Intval
(E1
)) < 0
2875 Error_Attr
("invalid parameter number for %attribute", E1
);
2879 Set_Etype
(N
, Universal_Integer
);
2885 when Attribute_Min
=>
2888 Resolve
(E1
, P_Base_Type
);
2889 Resolve
(E2
, P_Base_Type
);
2890 Set_Etype
(N
, P_Base_Type
);
2896 when Attribute_Model
=>
2897 Check_Floating_Point_Type_1
;
2898 Set_Etype
(N
, P_Base_Type
);
2899 Resolve
(E1
, P_Base_Type
);
2905 when Attribute_Model_Emin
=>
2906 Check_Floating_Point_Type_0
;
2907 Set_Etype
(N
, Universal_Integer
);
2913 when Attribute_Model_Epsilon
=>
2914 Check_Floating_Point_Type_0
;
2915 Set_Etype
(N
, Universal_Real
);
2917 --------------------
2918 -- Model_Mantissa --
2919 --------------------
2921 when Attribute_Model_Mantissa
=>
2922 Check_Floating_Point_Type_0
;
2923 Set_Etype
(N
, Universal_Integer
);
2929 when Attribute_Model_Small
=>
2930 Check_Floating_Point_Type_0
;
2931 Set_Etype
(N
, Universal_Real
);
2937 when Attribute_Modulus
=>
2941 if not Is_Modular_Integer_Type
(P_Type
) then
2942 Error_Attr
("prefix of % attribute must be modular type", P
);
2945 Set_Etype
(N
, Universal_Integer
);
2947 --------------------
2948 -- Null_Parameter --
2949 --------------------
2951 when Attribute_Null_Parameter
=> Null_Parameter
: declare
2952 Parnt
: constant Node_Id
:= Parent
(N
);
2953 GParnt
: constant Node_Id
:= Parent
(Parnt
);
2955 procedure Bad_Null_Parameter
(Msg
: String);
2956 -- Used if bad Null parameter attribute node is found. Issues
2957 -- given error message, and also sets the type to Any_Type to
2958 -- avoid blowups later on from dealing with a junk node.
2960 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
2961 -- Called to check that Proc_Ent is imported subprogram
2963 ------------------------
2964 -- Bad_Null_Parameter --
2965 ------------------------
2967 procedure Bad_Null_Parameter
(Msg
: String) is
2969 Error_Msg_N
(Msg
, N
);
2970 Set_Etype
(N
, Any_Type
);
2971 end Bad_Null_Parameter
;
2973 ----------------------
2974 -- Must_Be_Imported --
2975 ----------------------
2977 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
2978 Pent
: Entity_Id
:= Proc_Ent
;
2981 while Present
(Alias
(Pent
)) loop
2982 Pent
:= Alias
(Pent
);
2985 -- Ignore check if procedure not frozen yet (we will get
2986 -- another chance when the default parameter is reanalyzed)
2988 if not Is_Frozen
(Pent
) then
2991 elsif not Is_Imported
(Pent
) then
2993 ("Null_Parameter can only be used with imported subprogram");
2998 end Must_Be_Imported
;
3000 -- Start of processing for Null_Parameter
3005 Set_Etype
(N
, P_Type
);
3007 -- Case of attribute used as default expression
3009 if Nkind
(Parnt
) = N_Parameter_Specification
then
3010 Must_Be_Imported
(Defining_Entity
(GParnt
));
3012 -- Case of attribute used as actual for subprogram (positional)
3014 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
3016 Nkind
(Parnt
) = N_Function_Call
)
3017 and then Is_Entity_Name
(Name
(Parnt
))
3019 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3021 -- Case of attribute used as actual for subprogram (named)
3023 elsif Nkind
(Parnt
) = N_Parameter_Association
3024 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
3026 Nkind
(GParnt
) = N_Function_Call
)
3027 and then Is_Entity_Name
(Name
(GParnt
))
3029 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3031 -- Not an allowed case
3035 ("Null_Parameter must be actual or default parameter");
3044 when Attribute_Object_Size
=>
3047 Check_Not_Incomplete_Type
;
3048 Set_Etype
(N
, Universal_Integer
);
3054 when Attribute_Output
=>
3056 Check_Stream_Attribute
(TSS_Stream_Output
);
3057 Set_Etype
(N
, Standard_Void_Type
);
3058 Resolve
(N
, Standard_Void_Type
);
3064 when Attribute_Partition_ID
=>
3067 if P_Type
/= Any_Type
then
3068 if not Is_Library_Level_Entity
(Entity
(P
)) then
3070 ("prefix of % attribute must be library-level entity", P
);
3072 -- The defining entity of prefix should not be declared inside
3073 -- a Pure unit. RM E.1(8).
3074 -- The Is_Pure flag has been set during declaration.
3076 elsif Is_Entity_Name
(P
)
3077 and then Is_Pure
(Entity
(P
))
3080 ("prefix of % attribute must not be declared pure", P
);
3084 Set_Etype
(N
, Universal_Integer
);
3086 -------------------------
3087 -- Passed_By_Reference --
3088 -------------------------
3090 when Attribute_Passed_By_Reference
=>
3093 Set_Etype
(N
, Standard_Boolean
);
3099 when Attribute_Pool_Address
=>
3101 Set_Etype
(N
, RTE
(RE_Address
));
3107 when Attribute_Pos
=>
3108 Check_Discrete_Type
;
3110 Resolve
(E1
, P_Base_Type
);
3111 Set_Etype
(N
, Universal_Integer
);
3117 when Attribute_Position
=>
3119 Set_Etype
(N
, Universal_Integer
);
3125 when Attribute_Pred
=>
3128 Resolve
(E1
, P_Base_Type
);
3129 Set_Etype
(N
, P_Base_Type
);
3131 -- Nothing to do for real type case
3133 if Is_Real_Type
(P_Type
) then
3136 -- If not modular type, test for overflow check required
3139 if not Is_Modular_Integer_Type
(P_Type
)
3140 and then not Range_Checks_Suppressed
(P_Base_Type
)
3142 Enable_Range_Check
(E1
);
3150 when Attribute_Range
=>
3151 Check_Array_Or_Scalar_Type
;
3154 and then Is_Scalar_Type
(P_Type
)
3155 and then Comes_From_Source
(N
)
3158 ("(Ada 83) % attribute not allowed for scalar type", P
);
3165 when Attribute_Range_Length
=>
3166 Check_Discrete_Type
;
3167 Set_Etype
(N
, Universal_Integer
);
3173 when Attribute_Read
=>
3175 Check_Stream_Attribute
(TSS_Stream_Read
);
3176 Set_Etype
(N
, Standard_Void_Type
);
3177 Resolve
(N
, Standard_Void_Type
);
3178 Note_Possible_Modification
(E2
);
3184 when Attribute_Remainder
=>
3185 Check_Floating_Point_Type_2
;
3186 Set_Etype
(N
, P_Base_Type
);
3187 Resolve
(E1
, P_Base_Type
);
3188 Resolve
(E2
, P_Base_Type
);
3194 when Attribute_Round
=>
3196 Check_Decimal_Fixed_Point_Type
;
3197 Set_Etype
(N
, P_Base_Type
);
3199 -- Because the context is universal_real (3.5.10(12)) it is a legal
3200 -- context for a universal fixed expression. This is the only
3201 -- attribute whose functional description involves U_R.
3203 if Etype
(E1
) = Universal_Fixed
then
3205 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3206 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3207 Expression
=> Relocate_Node
(E1
));
3215 Resolve
(E1
, Any_Real
);
3221 when Attribute_Rounding
=>
3222 Check_Floating_Point_Type_1
;
3223 Set_Etype
(N
, P_Base_Type
);
3224 Resolve
(E1
, P_Base_Type
);
3230 when Attribute_Safe_Emax
=>
3231 Check_Floating_Point_Type_0
;
3232 Set_Etype
(N
, Universal_Integer
);
3238 when Attribute_Safe_First
=>
3239 Check_Floating_Point_Type_0
;
3240 Set_Etype
(N
, Universal_Real
);
3246 when Attribute_Safe_Large
=>
3249 Set_Etype
(N
, Universal_Real
);
3255 when Attribute_Safe_Last
=>
3256 Check_Floating_Point_Type_0
;
3257 Set_Etype
(N
, Universal_Real
);
3263 when Attribute_Safe_Small
=>
3266 Set_Etype
(N
, Universal_Real
);
3272 when Attribute_Scale
=>
3274 Check_Decimal_Fixed_Point_Type
;
3275 Set_Etype
(N
, Universal_Integer
);
3281 when Attribute_Scaling
=>
3282 Check_Floating_Point_Type_2
;
3283 Set_Etype
(N
, P_Base_Type
);
3284 Resolve
(E1
, P_Base_Type
);
3290 when Attribute_Signed_Zeros
=>
3291 Check_Floating_Point_Type_0
;
3292 Set_Etype
(N
, Standard_Boolean
);
3298 when Attribute_Size | Attribute_VADS_Size
=>
3301 if Is_Object_Reference
(P
)
3302 or else (Is_Entity_Name
(P
)
3303 and then Ekind
(Entity
(P
)) = E_Function
)
3305 Check_Object_Reference
(P
);
3307 elsif Is_Entity_Name
(P
)
3308 and then Is_Type
(Entity
(P
))
3312 elsif Nkind
(P
) = N_Type_Conversion
3313 and then not Comes_From_Source
(P
)
3318 Error_Attr
("invalid prefix for % attribute", P
);
3321 Check_Not_Incomplete_Type
;
3322 Set_Etype
(N
, Universal_Integer
);
3328 when Attribute_Small
=>
3331 Set_Etype
(N
, Universal_Real
);
3337 when Attribute_Storage_Pool
=>
3338 if Is_Access_Type
(P_Type
) then
3341 -- Set appropriate entity
3343 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3344 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3346 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3349 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3351 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3352 -- Storage_Pool since this attribute is not defined for such
3353 -- types (RM E.2.3(22)).
3355 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3358 Error_Attr
("prefix of % attribute must be access type", P
);
3365 when Attribute_Storage_Size
=>
3367 if Is_Task_Type
(P_Type
) then
3369 Set_Etype
(N
, Universal_Integer
);
3371 elsif Is_Access_Type
(P_Type
) then
3372 if Is_Entity_Name
(P
)
3373 and then Is_Type
(Entity
(P
))
3377 Set_Etype
(N
, Universal_Integer
);
3379 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3380 -- Storage_Size since this attribute is not defined for
3381 -- such types (RM E.2.3(22)).
3383 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3385 -- The prefix is allowed to be an implicit dereference
3386 -- of an access value designating a task.
3391 Set_Etype
(N
, Universal_Integer
);
3396 ("prefix of % attribute must be access or task type", P
);
3403 when Attribute_Storage_Unit
=>
3404 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3410 when Attribute_Succ
=>
3413 Resolve
(E1
, P_Base_Type
);
3414 Set_Etype
(N
, P_Base_Type
);
3416 -- Nothing to do for real type case
3418 if Is_Real_Type
(P_Type
) then
3421 -- If not modular type, test for overflow check required.
3424 if not Is_Modular_Integer_Type
(P_Type
)
3425 and then not Range_Checks_Suppressed
(P_Base_Type
)
3427 Enable_Range_Check
(E1
);
3435 when Attribute_Tag
=>
3439 if not Is_Tagged_Type
(P_Type
) then
3440 Error_Attr
("prefix of % attribute must be tagged", P
);
3442 -- Next test does not apply to generated code
3443 -- why not, and what does the illegal reference mean???
3445 elsif Is_Object_Reference
(P
)
3446 and then not Is_Class_Wide_Type
(P_Type
)
3447 and then Comes_From_Source
(N
)
3450 ("% attribute can only be applied to objects of class-wide type",
3454 Set_Etype
(N
, RTE
(RE_Tag
));
3460 when Attribute_Target_Name
=> Target_Name
: declare
3461 TN
: constant String := Sdefault
.Target_Name
.all;
3462 TL
: Integer := TN
'Last;
3465 Check_Standard_Prefix
;
3469 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
3473 Store_String_Chars
(TN
(TN
'First .. TL
));
3476 Make_String_Literal
(Loc
,
3477 Strval
=> End_String
));
3478 Analyze_And_Resolve
(N
, Standard_String
);
3485 when Attribute_Terminated
=>
3487 Set_Etype
(N
, Standard_Boolean
);
3494 when Attribute_To_Address
=>
3498 if Nkind
(P
) /= N_Identifier
3499 or else Chars
(P
) /= Name_System
3501 Error_Attr
("prefix of %attribute must be System", P
);
3504 Generate_Reference
(RTE
(RE_Address
), P
);
3505 Analyze_And_Resolve
(E1
, Any_Integer
);
3506 Set_Etype
(N
, RTE
(RE_Address
));
3512 when Attribute_Truncation
=>
3513 Check_Floating_Point_Type_1
;
3514 Resolve
(E1
, P_Base_Type
);
3515 Set_Etype
(N
, P_Base_Type
);
3521 when Attribute_Type_Class
=>
3524 Check_Not_Incomplete_Type
;
3525 Set_Etype
(N
, RTE
(RE_Type_Class
));
3531 when Attribute_UET_Address
=>
3533 Check_Unit_Name
(P
);
3534 Set_Etype
(N
, RTE
(RE_Address
));
3536 -----------------------
3537 -- Unbiased_Rounding --
3538 -----------------------
3540 when Attribute_Unbiased_Rounding
=>
3541 Check_Floating_Point_Type_1
;
3542 Set_Etype
(N
, P_Base_Type
);
3543 Resolve
(E1
, P_Base_Type
);
3545 ----------------------
3546 -- Unchecked_Access --
3547 ----------------------
3549 when Attribute_Unchecked_Access
=>
3550 if Comes_From_Source
(N
) then
3551 Check_Restriction
(No_Unchecked_Access
, N
);
3554 Analyze_Access_Attribute
;
3556 -------------------------
3557 -- Unconstrained_Array --
3558 -------------------------
3560 when Attribute_Unconstrained_Array
=>
3563 Check_Not_Incomplete_Type
;
3564 Set_Etype
(N
, Standard_Boolean
);
3566 ------------------------------
3567 -- Universal_Literal_String --
3568 ------------------------------
3570 -- This is a GNAT specific attribute whose prefix must be a named
3571 -- number where the expression is either a single numeric literal,
3572 -- or a numeric literal immediately preceded by a minus sign. The
3573 -- result is equivalent to a string literal containing the text of
3574 -- the literal as it appeared in the source program with a possible
3575 -- leading minus sign.
3577 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3581 if not Is_Entity_Name
(P
)
3582 or else Ekind
(Entity
(P
)) not in Named_Kind
3584 Error_Attr
("prefix for % attribute must be named number", P
);
3591 Src
: Source_Buffer_Ptr
;
3594 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3596 if Nkind
(Expr
) = N_Op_Minus
then
3598 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3603 if Nkind
(Expr
) /= N_Integer_Literal
3604 and then Nkind
(Expr
) /= N_Real_Literal
3607 ("named number for % attribute must be simple literal", N
);
3610 -- Build string literal corresponding to source literal text
3615 Store_String_Char
(Get_Char_Code
('-'));
3619 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3621 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3622 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3626 -- Now we rewrite the attribute with the string literal
3629 Make_String_Literal
(Loc
, End_String
));
3633 end Universal_Literal_String
;
3635 -------------------------
3636 -- Unrestricted_Access --
3637 -------------------------
3639 -- This is a GNAT specific attribute which is like Access except that
3640 -- all scope checks and checks for aliased views are omitted.
3642 when Attribute_Unrestricted_Access
=>
3643 if Comes_From_Source
(N
) then
3644 Check_Restriction
(No_Unchecked_Access
, N
);
3647 if Is_Entity_Name
(P
) then
3648 Set_Address_Taken
(Entity
(P
));
3651 Analyze_Access_Attribute
;
3657 when Attribute_Val
=> Val
: declare
3660 Check_Discrete_Type
;
3661 Resolve
(E1
, Any_Integer
);
3662 Set_Etype
(N
, P_Base_Type
);
3664 -- Note, we need a range check in general, but we wait for the
3665 -- Resolve call to do this, since we want to let Eval_Attribute
3666 -- have a chance to find an static illegality first!
3673 when Attribute_Valid
=>
3676 -- Ignore check for object if we have a 'Valid reference generated
3677 -- by the expanded code, since in some cases valid checks can occur
3678 -- on items that are names, but are not objects (e.g. attributes).
3680 if Comes_From_Source
(N
) then
3681 Check_Object_Reference
(P
);
3684 if not Is_Scalar_Type
(P_Type
) then
3685 Error_Attr
("object for % attribute must be of scalar type", P
);
3688 Set_Etype
(N
, Standard_Boolean
);
3694 when Attribute_Value
=> Value
:
3699 if Is_Enumeration_Type
(P_Type
) then
3700 Check_Restriction
(No_Enumeration_Maps
, N
);
3703 -- Set Etype before resolving expression because expansion of
3704 -- expression may require enclosing type. Note that the type
3705 -- returned by 'Value is the base type of the prefix type.
3707 Set_Etype
(N
, P_Base_Type
);
3708 Validate_Non_Static_Attribute_Function_Call
;
3715 when Attribute_Value_Size
=>
3718 Check_Not_Incomplete_Type
;
3719 Set_Etype
(N
, Universal_Integer
);
3725 when Attribute_Version
=>
3728 Set_Etype
(N
, RTE
(RE_Version_String
));
3734 when Attribute_Wchar_T_Size
=>
3735 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3741 when Attribute_Wide_Image
=> Wide_Image
:
3744 Set_Etype
(N
, Standard_Wide_String
);
3746 Resolve
(E1
, P_Base_Type
);
3747 Validate_Non_Static_Attribute_Function_Call
;
3754 when Attribute_Wide_Value
=> Wide_Value
:
3759 -- Set Etype before resolving expression because expansion
3760 -- of expression may require enclosing type.
3762 Set_Etype
(N
, P_Type
);
3763 Validate_Non_Static_Attribute_Function_Call
;
3770 when Attribute_Wide_Width
=>
3773 Set_Etype
(N
, Universal_Integer
);
3779 when Attribute_Width
=>
3782 Set_Etype
(N
, Universal_Integer
);
3788 when Attribute_Word_Size
=>
3789 Standard_Attribute
(System_Word_Size
);
3795 when Attribute_Write
=>
3797 Check_Stream_Attribute
(TSS_Stream_Write
);
3798 Set_Etype
(N
, Standard_Void_Type
);
3799 Resolve
(N
, Standard_Void_Type
);
3803 -- All errors raise Bad_Attribute, so that we get out before any further
3804 -- damage occurs when an error is detected (for example, if we check for
3805 -- one attribute expression, and the check succeeds, we want to be able
3806 -- to proceed securely assuming that an expression is in fact present.
3809 when Bad_Attribute
=>
3810 Set_Etype
(N
, Any_Type
);
3813 end Analyze_Attribute
;
3815 --------------------
3816 -- Eval_Attribute --
3817 --------------------
3819 procedure Eval_Attribute
(N
: Node_Id
) is
3820 Loc
: constant Source_Ptr
:= Sloc
(N
);
3821 Aname
: constant Name_Id
:= Attribute_Name
(N
);
3822 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
3823 P
: constant Node_Id
:= Prefix
(N
);
3825 C_Type
: constant Entity_Id
:= Etype
(N
);
3826 -- The type imposed by the context.
3829 -- First expression, or Empty if none
3832 -- Second expression, or Empty if none
3834 P_Entity
: Entity_Id
;
3835 -- Entity denoted by prefix
3838 -- The type of the prefix
3840 P_Base_Type
: Entity_Id
;
3841 -- The base type of the prefix type
3843 P_Root_Type
: Entity_Id
;
3844 -- The root type of the prefix type
3847 -- True if the result is Static. This is set by the general processing
3848 -- to true if the prefix is static, and all expressions are static. It
3849 -- can be reset as processing continues for particular attributes
3851 Lo_Bound
, Hi_Bound
: Node_Id
;
3852 -- Expressions for low and high bounds of type or array index referenced
3853 -- by First, Last, or Length attribute for array, set by Set_Bounds.
3856 -- Constraint error node used if we have an attribute reference has
3857 -- an argument that raises a constraint error. In this case we replace
3858 -- the attribute with a raise constraint_error node. This is important
3859 -- processing, since otherwise gigi might see an attribute which it is
3860 -- unprepared to deal with.
3862 function Aft_Value
return Nat
;
3863 -- Computes Aft value for current attribute prefix (used by Aft itself
3864 -- and also by Width for computing the Width of a fixed point type).
3866 procedure Check_Expressions
;
3867 -- In case where the attribute is not foldable, the expressions, if
3868 -- any, of the attribute, are in a non-static context. This procedure
3869 -- performs the required additional checks.
3871 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
3872 -- Determines if the given type has compile time known bounds. Note
3873 -- that we enter the case statement even in cases where the prefix
3874 -- type does NOT have known bounds, so it is important to guard any
3875 -- attempt to evaluate both bounds with a call to this function.
3877 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
3878 -- This procedure is called when the attribute N has a non-static
3879 -- but compile time known value given by Val. It includes the
3880 -- necessary checks for out of range values.
3882 procedure Float_Attribute_Universal_Integer
3891 -- This procedure evaluates a float attribute with no arguments that
3892 -- returns a universal integer result. The parameters give the values
3893 -- for the possible floating-point root types. See ttypef for details.
3894 -- The prefix type is a float type (and is thus not a generic type).
3896 procedure Float_Attribute_Universal_Real
3897 (IEEES_Val
: String;
3904 AAMPL_Val
: String);
3905 -- This procedure evaluates a float attribute with no arguments that
3906 -- returns a universal real result. The parameters give the values
3907 -- required for the possible floating-point root types in string
3908 -- format as real literals with a possible leading minus sign.
3909 -- The prefix type is a float type (and is thus not a generic type).
3911 function Fore_Value
return Nat
;
3912 -- Computes the Fore value for the current attribute prefix, which is
3913 -- known to be a static fixed-point type. Used by Fore and Width.
3915 function Mantissa
return Uint
;
3916 -- Returns the Mantissa value for the prefix type
3918 procedure Set_Bounds
;
3919 -- Used for First, Last and Length attributes applied to an array or
3920 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
3921 -- and high bound expressions for the index referenced by the attribute
3922 -- designator (i.e. the first index if no expression is present, and
3923 -- the N'th index if the value N is present as an expression). Also
3924 -- used for First and Last of scalar types. Static is reset to False
3925 -- if the type or index type is not statically constrained.
3931 function Aft_Value
return Nat
is
3937 Delta_Val
:= Delta_Value
(P_Type
);
3939 while Delta_Val
< Ureal_Tenth
loop
3940 Delta_Val
:= Delta_Val
* Ureal_10
;
3941 Result
:= Result
+ 1;
3947 -----------------------
3948 -- Check_Expressions --
3949 -----------------------
3951 procedure Check_Expressions
is
3955 while Present
(E
) loop
3956 Check_Non_Static_Context
(E
);
3959 end Check_Expressions
;
3961 ----------------------------------
3962 -- Compile_Time_Known_Attribute --
3963 ----------------------------------
3965 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
3966 T
: constant Entity_Id
:= Etype
(N
);
3969 Fold_Uint
(N
, Val
, False);
3971 -- Check that result is in bounds of the type if it is static
3973 if Is_In_Range
(N
, T
) then
3976 elsif Is_Out_Of_Range
(N
, T
) then
3977 Apply_Compile_Time_Constraint_Error
3978 (N
, "value not in range of}?", CE_Range_Check_Failed
);
3980 elsif not Range_Checks_Suppressed
(T
) then
3981 Enable_Range_Check
(N
);
3984 Set_Do_Range_Check
(N
, False);
3986 end Compile_Time_Known_Attribute
;
3988 -------------------------------
3989 -- Compile_Time_Known_Bounds --
3990 -------------------------------
3992 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
3995 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
3997 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
3998 end Compile_Time_Known_Bounds
;
4000 ---------------------------------------
4001 -- Float_Attribute_Universal_Integer --
4002 ---------------------------------------
4004 procedure Float_Attribute_Universal_Integer
4015 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4018 if Vax_Float
(P_Base_Type
) then
4019 if Digs
= VAXFF_Digits
then
4021 elsif Digs
= VAXDF_Digits
then
4023 else pragma Assert
(Digs
= VAXGF_Digits
);
4027 elsif Is_AAMP_Float
(P_Base_Type
) then
4028 if Digs
= AAMPS_Digits
then
4030 else pragma Assert
(Digs
= AAMPL_Digits
);
4035 if Digs
= IEEES_Digits
then
4037 elsif Digs
= IEEEL_Digits
then
4039 else pragma Assert
(Digs
= IEEEX_Digits
);
4044 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4045 end Float_Attribute_Universal_Integer
;
4047 ------------------------------------
4048 -- Float_Attribute_Universal_Real --
4049 ------------------------------------
4051 procedure Float_Attribute_Universal_Real
4052 (IEEES_Val
: String;
4062 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4065 if Vax_Float
(P_Base_Type
) then
4066 if Digs
= VAXFF_Digits
then
4067 Val
:= Real_Convert
(VAXFF_Val
);
4068 elsif Digs
= VAXDF_Digits
then
4069 Val
:= Real_Convert
(VAXDF_Val
);
4070 else pragma Assert
(Digs
= VAXGF_Digits
);
4071 Val
:= Real_Convert
(VAXGF_Val
);
4074 elsif Is_AAMP_Float
(P_Base_Type
) then
4075 if Digs
= AAMPS_Digits
then
4076 Val
:= Real_Convert
(AAMPS_Val
);
4077 else pragma Assert
(Digs
= AAMPL_Digits
);
4078 Val
:= Real_Convert
(AAMPL_Val
);
4082 if Digs
= IEEES_Digits
then
4083 Val
:= Real_Convert
(IEEES_Val
);
4084 elsif Digs
= IEEEL_Digits
then
4085 Val
:= Real_Convert
(IEEEL_Val
);
4086 else pragma Assert
(Digs
= IEEEX_Digits
);
4087 Val
:= Real_Convert
(IEEEX_Val
);
4091 Set_Sloc
(Val
, Loc
);
4093 Set_Is_Static_Expression
(N
, Static
);
4094 Analyze_And_Resolve
(N
, C_Type
);
4095 end Float_Attribute_Universal_Real
;
4101 -- Note that the Fore calculation is based on the actual values
4102 -- of the bounds, and does not take into account possible rounding.
4104 function Fore_Value
return Nat
is
4105 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4106 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4107 Small
: constant Ureal
:= Small_Value
(P_Type
);
4108 Lo_Real
: constant Ureal
:= Lo
* Small
;
4109 Hi_Real
: constant Ureal
:= Hi
* Small
;
4114 -- Bounds are given in terms of small units, so first compute
4115 -- proper values as reals.
4117 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4120 -- Loop to compute proper value if more than one digit required
4122 while T
>= Ureal_10
loop
4134 -- Table of mantissa values accessed by function Computed using
4137 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4139 -- where D is T'Digits (RM83 3.5.7)
4141 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4183 function Mantissa
return Uint
is
4186 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4193 procedure Set_Bounds
is
4199 -- For a string literal subtype, we have to construct the bounds.
4200 -- Valid Ada code never applies attributes to string literals, but
4201 -- it is convenient to allow the expander to generate attribute
4202 -- references of this type (e.g. First and Last applied to a string
4205 -- Note that the whole point of the E_String_Literal_Subtype is to
4206 -- avoid this construction of bounds, but the cases in which we
4207 -- have to materialize them are rare enough that we don't worry!
4209 -- The low bound is simply the low bound of the base type. The
4210 -- high bound is computed from the length of the string and this
4213 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4214 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4215 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4218 Make_Integer_Literal
(Sloc
(P
),
4220 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4222 Set_Parent
(Hi_Bound
, P
);
4223 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4226 -- For non-array case, just get bounds of scalar type
4228 elsif Is_Scalar_Type
(P_Type
) then
4231 -- For a fixed-point type, we must freeze to get the attributes
4232 -- of the fixed-point type set now so we can reference them.
4234 if Is_Fixed_Point_Type
(P_Type
)
4235 and then not Is_Frozen
(Base_Type
(P_Type
))
4236 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4237 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4239 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4242 -- For array case, get type of proper index
4248 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4251 Indx
:= First_Index
(P_Type
);
4252 for J
in 1 .. Ndim
- 1 loop
4256 -- If no index type, get out (some other error occurred, and
4257 -- we don't have enough information to complete the job!)
4265 Ityp
:= Etype
(Indx
);
4268 -- A discrete range in an index constraint is allowed to be a
4269 -- subtype indication. This is syntactically a pain, but should
4270 -- not propagate to the entity for the corresponding index subtype.
4271 -- After checking that the subtype indication is legal, the range
4272 -- of the subtype indication should be transfered to the entity.
4273 -- The attributes for the bounds should remain the simple retrievals
4274 -- that they are now.
4276 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4277 Hi_Bound
:= Type_High_Bound
(Ityp
);
4279 if not Is_Static_Subtype
(Ityp
) then
4284 -- Start of processing for Eval_Attribute
4287 -- Acquire first two expressions (at the moment, no attributes
4288 -- take more than two expressions in any case).
4290 if Present
(Expressions
(N
)) then
4291 E1
:= First
(Expressions
(N
));
4298 -- Special processing for cases where the prefix is an object. For
4299 -- this purpose, a string literal counts as an object (attributes
4300 -- of string literals can only appear in generated code).
4302 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
4304 -- For Component_Size, the prefix is an array object, and we apply
4305 -- the attribute to the type of the object. This is allowed for
4306 -- both unconstrained and constrained arrays, since the bounds
4307 -- have no influence on the value of this attribute.
4309 if Id
= Attribute_Component_Size
then
4310 P_Entity
:= Etype
(P
);
4312 -- For First and Last, the prefix is an array object, and we apply
4313 -- the attribute to the type of the array, but we need a constrained
4314 -- type for this, so we use the actual subtype if available.
4316 elsif Id
= Attribute_First
4320 Id
= Attribute_Length
4323 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4326 if Present
(AS
) and then Is_Constrained
(AS
) then
4329 -- If we have an unconstrained type, cannot fold
4337 -- For Size, give size of object if available, otherwise we
4338 -- cannot fold Size.
4340 elsif Id
= Attribute_Size
then
4341 if Is_Entity_Name
(P
)
4342 and then Known_Esize
(Entity
(P
))
4344 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4352 -- For Alignment, give size of object if available, otherwise we
4353 -- cannot fold Alignment.
4355 elsif Id
= Attribute_Alignment
then
4356 if Is_Entity_Name
(P
)
4357 and then Known_Alignment
(Entity
(P
))
4359 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
4367 -- No other attributes for objects are folded
4374 -- Cases where P is not an object. Cannot do anything if P is
4375 -- not the name of an entity.
4377 elsif not Is_Entity_Name
(P
) then
4381 -- Otherwise get prefix entity
4384 P_Entity
:= Entity
(P
);
4387 -- At this stage P_Entity is the entity to which the attribute
4388 -- is to be applied. This is usually simply the entity of the
4389 -- prefix, except in some cases of attributes for objects, where
4390 -- as described above, we apply the attribute to the object type.
4392 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4393 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4394 -- Note we allow non-static non-generic types at this stage as further
4397 if Is_Type
(P_Entity
)
4398 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4399 and then (not Is_Generic_Type
(P_Entity
))
4403 -- Second foldable possibility is an array object (RM 4.9(8))
4405 elsif (Ekind
(P_Entity
) = E_Variable
4407 Ekind
(P_Entity
) = E_Constant
)
4408 and then Is_Array_Type
(Etype
(P_Entity
))
4409 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4411 P_Type
:= Etype
(P_Entity
);
4413 -- If the entity is an array constant with an unconstrained
4414 -- nominal subtype then get the type from the initial value.
4415 -- If the value has been expanded into assignments, the expression
4416 -- is not present and the attribute reference remains dynamic.
4417 -- We could do better here and retrieve the type ???
4419 if Ekind
(P_Entity
) = E_Constant
4420 and then not Is_Constrained
(P_Type
)
4422 if No
(Constant_Value
(P_Entity
)) then
4425 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4429 -- Definite must be folded if the prefix is not a generic type,
4430 -- that is to say if we are within an instantiation. Same processing
4431 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4432 -- and Unconstrained_Array.
4434 elsif (Id
= Attribute_Definite
4436 Id
= Attribute_Has_Discriminants
4438 Id
= Attribute_Type_Class
4440 Id
= Attribute_Unconstrained_Array
)
4441 and then not Is_Generic_Type
(P_Entity
)
4445 -- We can fold 'Size applied to a type if the size is known
4446 -- (as happens for a size from an attribute definition clause).
4447 -- At this stage, this can happen only for types (e.g. record
4448 -- types) for which the size is always non-static. We exclude
4449 -- generic types from consideration (since they have bogus
4450 -- sizes set within templates).
4452 elsif Id
= Attribute_Size
4453 and then Is_Type
(P_Entity
)
4454 and then (not Is_Generic_Type
(P_Entity
))
4455 and then Known_Static_RM_Size
(P_Entity
)
4457 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4460 -- We can fold 'Alignment applied to a type if the alignment is known
4461 -- (as happens for an alignment from an attribute definition clause).
4462 -- At this stage, this can happen only for types (e.g. record
4463 -- types) for which the size is always non-static. We exclude
4464 -- generic types from consideration (since they have bogus
4465 -- sizes set within templates).
4467 elsif Id
= Attribute_Alignment
4468 and then Is_Type
(P_Entity
)
4469 and then (not Is_Generic_Type
(P_Entity
))
4470 and then Known_Alignment
(P_Entity
)
4472 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
4475 -- If this is an access attribute that is known to fail accessibility
4476 -- check, rewrite accordingly.
4478 elsif Attribute_Name
(N
) = Name_Access
4479 and then Raises_Constraint_Error
(N
)
4482 Make_Raise_Program_Error
(Loc
,
4483 Reason
=> PE_Accessibility_Check_Failed
));
4484 Set_Etype
(N
, C_Type
);
4487 -- No other cases are foldable (they certainly aren't static, and at
4488 -- the moment we don't try to fold any cases other than these three).
4495 -- If either attribute or the prefix is Any_Type, then propagate
4496 -- Any_Type to the result and don't do anything else at all.
4498 if P_Type
= Any_Type
4499 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4500 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4502 Set_Etype
(N
, Any_Type
);
4506 -- Scalar subtype case. We have not yet enforced the static requirement
4507 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4508 -- of non-static attribute references (e.g. S'Digits for a non-static
4509 -- floating-point type, which we can compute at compile time).
4511 -- Note: this folding of non-static attributes is not simply a case of
4512 -- optimization. For many of the attributes affected, Gigi cannot handle
4513 -- the attribute and depends on the front end having folded them away.
4515 -- Note: although we don't require staticness at this stage, we do set
4516 -- the Static variable to record the staticness, for easy reference by
4517 -- those attributes where it matters (e.g. Succ and Pred), and also to
4518 -- be used to ensure that non-static folded things are not marked as
4519 -- being static (a check that is done right at the end).
4521 P_Root_Type
:= Root_Type
(P_Type
);
4522 P_Base_Type
:= Base_Type
(P_Type
);
4524 -- If the root type or base type is generic, then we cannot fold. This
4525 -- test is needed because subtypes of generic types are not always
4526 -- marked as being generic themselves (which seems odd???)
4528 if Is_Generic_Type
(P_Root_Type
)
4529 or else Is_Generic_Type
(P_Base_Type
)
4534 if Is_Scalar_Type
(P_Type
) then
4535 Static
:= Is_OK_Static_Subtype
(P_Type
);
4537 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4538 -- since we can't do anything with unconstrained arrays. In addition,
4539 -- only the First, Last and Length attributes are possibly static.
4540 -- In addition Component_Size is possibly foldable, even though it
4541 -- can never be static.
4543 -- Definite, Has_Discriminants, Type_Class and Unconstrained_Array are
4544 -- again exceptions, because they apply as well to unconstrained types.
4546 elsif Id
= Attribute_Definite
4548 Id
= Attribute_Has_Discriminants
4550 Id
= Attribute_Type_Class
4552 Id
= Attribute_Unconstrained_Array
4557 if not Is_Constrained
(P_Type
)
4558 or else (Id
/= Attribute_Component_Size
and then
4559 Id
/= Attribute_First
and then
4560 Id
/= Attribute_Last
and then
4561 Id
/= Attribute_Length
)
4567 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4568 -- scalar case, we hold off on enforcing staticness, since there are
4569 -- cases which we can fold at compile time even though they are not
4570 -- static (e.g. 'Length applied to a static index, even though other
4571 -- non-static indexes make the array type non-static). This is only
4572 -- an optimization, but it falls out essentially free, so why not.
4573 -- Again we compute the variable Static for easy reference later
4574 -- (note that no array attributes are static in Ada 83).
4582 N
:= First_Index
(P_Type
);
4583 while Present
(N
) loop
4584 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
4586 -- If however the index type is generic, attributes cannot
4589 if Is_Generic_Type
(Etype
(N
))
4590 and then Id
/= Attribute_Component_Size
4600 -- Check any expressions that are present. Note that these expressions,
4601 -- depending on the particular attribute type, are either part of the
4602 -- attribute designator, or they are arguments in a case where the
4603 -- attribute reference returns a function. In the latter case, the
4604 -- rule in (RM 4.9(22)) applies and in particular requires the type
4605 -- of the expressions to be scalar in order for the attribute to be
4606 -- considered to be static.
4613 while Present
(E
) loop
4615 -- If expression is not static, then the attribute reference
4616 -- result certainly cannot be static.
4618 if not Is_Static_Expression
(E
) then
4622 -- If the result is not known at compile time, or is not of
4623 -- a scalar type, then the result is definitely not static,
4624 -- so we can quit now.
4626 if not Compile_Time_Known_Value
(E
)
4627 or else not Is_Scalar_Type
(Etype
(E
))
4629 -- An odd special case, if this is a Pos attribute, this
4630 -- is where we need to apply a range check since it does
4631 -- not get done anywhere else.
4633 if Id
= Attribute_Pos
then
4634 if Is_Integer_Type
(Etype
(E
)) then
4635 Apply_Range_Check
(E
, Etype
(N
));
4642 -- If the expression raises a constraint error, then so does
4643 -- the attribute reference. We keep going in this case because
4644 -- we are still interested in whether the attribute reference
4645 -- is static even if it is not static.
4647 elsif Raises_Constraint_Error
(E
) then
4648 Set_Raises_Constraint_Error
(N
);
4654 if Raises_Constraint_Error
(Prefix
(N
)) then
4659 -- Deal with the case of a static attribute reference that raises
4660 -- constraint error. The Raises_Constraint_Error flag will already
4661 -- have been set, and the Static flag shows whether the attribute
4662 -- reference is static. In any case we certainly can't fold such an
4663 -- attribute reference.
4665 -- Note that the rewriting of the attribute node with the constraint
4666 -- error node is essential in this case, because otherwise Gigi might
4667 -- blow up on one of the attributes it never expects to see.
4669 -- The constraint_error node must have the type imposed by the context,
4670 -- to avoid spurious errors in the enclosing expression.
4672 if Raises_Constraint_Error
(N
) then
4674 Make_Raise_Constraint_Error
(Sloc
(N
),
4675 Reason
=> CE_Range_Check_Failed
);
4676 Set_Etype
(CE_Node
, Etype
(N
));
4677 Set_Raises_Constraint_Error
(CE_Node
);
4679 Rewrite
(N
, Relocate_Node
(CE_Node
));
4680 Set_Is_Static_Expression
(N
, Static
);
4684 -- At this point we have a potentially foldable attribute reference.
4685 -- If Static is set, then the attribute reference definitely obeys
4686 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4687 -- folded. If Static is not set, then the attribute may or may not
4688 -- be foldable, and the individual attribute processing routines
4689 -- test Static as required in cases where it makes a difference.
4691 -- In the case where Static is not set, we do know that all the
4692 -- expressions present are at least known at compile time (we
4693 -- assumed above that if this was not the case, then there was
4694 -- no hope of static evaluation). However, we did not require
4695 -- that the bounds of the prefix type be compile time known,
4696 -- let alone static). That's because there are many attributes
4697 -- that can be computed at compile time on non-static subtypes,
4698 -- even though such references are not static expressions.
4706 when Attribute_Adjacent
=>
4709 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
4715 when Attribute_Aft
=>
4716 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
4722 when Attribute_Alignment
=> Alignment_Block
: declare
4723 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4726 -- Fold if alignment is set and not otherwise
4728 if Known_Alignment
(P_TypeA
) then
4729 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
4731 end Alignment_Block
;
4737 -- Can only be folded in No_Ast_Handler case
4739 when Attribute_AST_Entry
=>
4740 if not Is_AST_Entry
(P_Entity
) then
4742 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
4751 -- Bit can never be folded
4753 when Attribute_Bit
=>
4760 -- Body_version can never be static
4762 when Attribute_Body_Version
=>
4769 when Attribute_Ceiling
=>
4771 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
4773 --------------------
4774 -- Component_Size --
4775 --------------------
4777 when Attribute_Component_Size
=>
4778 if Known_Static_Component_Size
(P_Type
) then
4779 Fold_Uint
(N
, Component_Size
(P_Type
), False);
4786 when Attribute_Compose
=>
4789 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
4796 -- Constrained is never folded for now, there may be cases that
4797 -- could be handled at compile time. to be looked at later.
4799 when Attribute_Constrained
=>
4806 when Attribute_Copy_Sign
=>
4809 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
4815 when Attribute_Delta
=>
4816 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
4822 when Attribute_Definite
=>
4823 Rewrite
(N
, New_Occurrence_Of
(
4824 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
4825 Analyze_And_Resolve
(N
, Standard_Boolean
);
4831 when Attribute_Denorm
=>
4833 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
4839 when Attribute_Digits
=>
4840 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
4846 when Attribute_Emax
=>
4848 -- Ada 83 attribute is defined as (RM83 3.5.8)
4850 -- T'Emax = 4 * T'Mantissa
4852 Fold_Uint
(N
, 4 * Mantissa
, True);
4858 when Attribute_Enum_Rep
=>
4860 -- For an enumeration type with a non-standard representation
4861 -- use the Enumeration_Rep field of the proper constant. Note
4862 -- that this would not work for types Character/Wide_Character,
4863 -- since no real entities are created for the enumeration
4864 -- literals, but that does not matter since these two types
4865 -- do not have non-standard representations anyway.
4867 if Is_Enumeration_Type
(P_Type
)
4868 and then Has_Non_Standard_Rep
(P_Type
)
4870 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
4872 -- For enumeration types with standard representations and all
4873 -- other cases (i.e. all integer and modular types), Enum_Rep
4874 -- is equivalent to Pos.
4877 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
4884 when Attribute_Epsilon
=>
4886 -- Ada 83 attribute is defined as (RM83 3.5.8)
4888 -- T'Epsilon = 2.0**(1 - T'Mantissa)
4890 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
4896 when Attribute_Exponent
=>
4898 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
4904 when Attribute_First
=> First_Attr
:
4908 if Compile_Time_Known_Value
(Lo_Bound
) then
4909 if Is_Real_Type
(P_Type
) then
4910 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
4912 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
4921 when Attribute_Fixed_Value
=>
4928 when Attribute_Floor
=>
4930 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
4936 when Attribute_Fore
=>
4937 if Compile_Time_Known_Bounds
(P_Type
) then
4938 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
4945 when Attribute_Fraction
=>
4947 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
4949 -----------------------
4950 -- Has_Discriminants --
4951 -----------------------
4953 when Attribute_Has_Discriminants
=>
4954 Rewrite
(N
, New_Occurrence_Of
(
4955 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
4956 Analyze_And_Resolve
(N
, Standard_Boolean
);
4962 when Attribute_Identity
=>
4969 -- Image is a scalar attribute, but is never static, because it is
4970 -- not a static function (having a non-scalar argument (RM 4.9(22))
4972 when Attribute_Image
=>
4979 -- Img is a scalar attribute, but is never static, because it is
4980 -- not a static function (having a non-scalar argument (RM 4.9(22))
4982 when Attribute_Img
=>
4989 when Attribute_Integer_Value
=>
4996 when Attribute_Large
=>
4998 -- For fixed-point, we use the identity:
5000 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5002 if Is_Fixed_Point_Type
(P_Type
) then
5004 Make_Op_Multiply
(Loc
,
5006 Make_Op_Subtract
(Loc
,
5010 Make_Real_Literal
(Loc
, Ureal_2
),
5012 Make_Attribute_Reference
(Loc
,
5014 Attribute_Name
=> Name_Mantissa
)),
5015 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5018 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5020 Analyze_And_Resolve
(N
, C_Type
);
5022 -- Floating-point (Ada 83 compatibility)
5025 -- Ada 83 attribute is defined as (RM83 3.5.8)
5027 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5031 -- T'Emax = 4 * T'Mantissa
5034 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5042 when Attribute_Last
=> Last
:
5046 if Compile_Time_Known_Value
(Hi_Bound
) then
5047 if Is_Real_Type
(P_Type
) then
5048 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5050 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5059 when Attribute_Leading_Part
=>
5061 Eval_Fat
.Leading_Part
5062 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5068 when Attribute_Length
=> Length
: declare
5072 -- In the case of a generic index type, the bounds may
5073 -- appear static but the computation is not meaningful,
5074 -- and may generate a spurious warning.
5076 Ind
:= First_Index
(P_Type
);
5078 while Present
(Ind
) loop
5079 if Is_Generic_Type
(Etype
(Ind
)) then
5088 if Compile_Time_Known_Value
(Lo_Bound
)
5089 and then Compile_Time_Known_Value
(Hi_Bound
)
5092 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
5101 when Attribute_Machine
=>
5104 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
5111 when Attribute_Machine_Emax
=>
5112 Float_Attribute_Universal_Integer
(
5120 AAMPL_Machine_Emax
);
5126 when Attribute_Machine_Emin
=>
5127 Float_Attribute_Universal_Integer
(
5135 AAMPL_Machine_Emin
);
5137 ----------------------
5138 -- Machine_Mantissa --
5139 ----------------------
5141 when Attribute_Machine_Mantissa
=>
5142 Float_Attribute_Universal_Integer
(
5143 IEEES_Machine_Mantissa
,
5144 IEEEL_Machine_Mantissa
,
5145 IEEEX_Machine_Mantissa
,
5146 VAXFF_Machine_Mantissa
,
5147 VAXDF_Machine_Mantissa
,
5148 VAXGF_Machine_Mantissa
,
5149 AAMPS_Machine_Mantissa
,
5150 AAMPL_Machine_Mantissa
);
5152 -----------------------
5153 -- Machine_Overflows --
5154 -----------------------
5156 when Attribute_Machine_Overflows
=>
5158 -- Always true for fixed-point
5160 if Is_Fixed_Point_Type
(P_Type
) then
5161 Fold_Uint
(N
, True_Value
, True);
5163 -- Floating point case
5167 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
5175 when Attribute_Machine_Radix
=>
5176 if Is_Fixed_Point_Type
(P_Type
) then
5177 if Is_Decimal_Fixed_Point_Type
(P_Type
)
5178 and then Machine_Radix_10
(P_Type
)
5180 Fold_Uint
(N
, Uint_10
, True);
5182 Fold_Uint
(N
, Uint_2
, True);
5185 -- All floating-point type always have radix 2
5188 Fold_Uint
(N
, Uint_2
, True);
5191 --------------------
5192 -- Machine_Rounds --
5193 --------------------
5195 when Attribute_Machine_Rounds
=>
5197 -- Always False for fixed-point
5199 if Is_Fixed_Point_Type
(P_Type
) then
5200 Fold_Uint
(N
, False_Value
, True);
5202 -- Else yield proper floating-point result
5206 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
5213 -- Note: Machine_Size is identical to Object_Size
5215 when Attribute_Machine_Size
=> Machine_Size
: declare
5216 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5219 if Known_Esize
(P_TypeA
) then
5220 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5228 when Attribute_Mantissa
=>
5230 -- Fixed-point mantissa
5232 if Is_Fixed_Point_Type
(P_Type
) then
5234 -- Compile time foldable case
5236 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5238 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5240 -- The calculation of the obsolete Ada 83 attribute Mantissa
5241 -- is annoying, because of AI00143, quoted here:
5243 -- !question 84-01-10
5245 -- Consider the model numbers for F:
5247 -- type F is delta 1.0 range -7.0 .. 8.0;
5249 -- The wording requires that F'MANTISSA be the SMALLEST
5250 -- integer number for which each bound of the specified
5251 -- range is either a model number or lies at most small
5252 -- distant from a model number. This means F'MANTISSA
5253 -- is required to be 3 since the range -7.0 .. 7.0 fits
5254 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5255 -- number, namely, 7. Is this analysis correct? Note that
5256 -- this implies the upper bound of the range is not
5257 -- represented as a model number.
5259 -- !response 84-03-17
5261 -- The analysis is correct. The upper and lower bounds for
5262 -- a fixed point type can lie outside the range of model
5273 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5274 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5275 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5276 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5278 -- If the Bound is exactly a model number, i.e. a multiple
5279 -- of Small, then we back it off by one to get the integer
5280 -- value that must be representable.
5282 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5283 Max_Man
:= Max_Man
- 1;
5286 -- Now find corresponding size = Mantissa value
5289 while 2 ** Siz
< Max_Man
loop
5293 Fold_Uint
(N
, Siz
, True);
5297 -- The case of dynamic bounds cannot be evaluated at compile
5298 -- time. Instead we use a runtime routine (see Exp_Attr).
5303 -- Floating-point Mantissa
5306 Fold_Uint
(N
, Mantissa
, True);
5313 when Attribute_Max
=> Max
:
5315 if Is_Real_Type
(P_Type
) then
5317 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5319 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5323 ----------------------------------
5324 -- Max_Size_In_Storage_Elements --
5325 ----------------------------------
5327 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5328 -- Storage_Unit boundary. We can fold any cases for which the size
5329 -- is known by the front end.
5331 when Attribute_Max_Size_In_Storage_Elements
=>
5332 if Known_Esize
(P_Type
) then
5334 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5335 System_Storage_Unit
,
5339 --------------------
5340 -- Mechanism_Code --
5341 --------------------
5343 when Attribute_Mechanism_Code
=>
5347 Mech
: Mechanism_Type
;
5351 Mech
:= Mechanism
(P_Entity
);
5354 Val
:= UI_To_Int
(Expr_Value
(E1
));
5356 Formal
:= First_Formal
(P_Entity
);
5357 for J
in 1 .. Val
- 1 loop
5358 Next_Formal
(Formal
);
5360 Mech
:= Mechanism
(Formal
);
5364 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
5372 when Attribute_Min
=> Min
:
5374 if Is_Real_Type
(P_Type
) then
5376 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5378 Fold_Uint
(N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5386 when Attribute_Model
=>
5388 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5394 when Attribute_Model_Emin
=>
5395 Float_Attribute_Universal_Integer
(
5409 when Attribute_Model_Epsilon
=>
5410 Float_Attribute_Universal_Real
(
5411 IEEES_Model_Epsilon
'Universal_Literal_String,
5412 IEEEL_Model_Epsilon
'Universal_Literal_String,
5413 IEEEX_Model_Epsilon
'Universal_Literal_String,
5414 VAXFF_Model_Epsilon
'Universal_Literal_String,
5415 VAXDF_Model_Epsilon
'Universal_Literal_String,
5416 VAXGF_Model_Epsilon
'Universal_Literal_String,
5417 AAMPS_Model_Epsilon
'Universal_Literal_String,
5418 AAMPL_Model_Epsilon
'Universal_Literal_String);
5420 --------------------
5421 -- Model_Mantissa --
5422 --------------------
5424 when Attribute_Model_Mantissa
=>
5425 Float_Attribute_Universal_Integer
(
5426 IEEES_Model_Mantissa
,
5427 IEEEL_Model_Mantissa
,
5428 IEEEX_Model_Mantissa
,
5429 VAXFF_Model_Mantissa
,
5430 VAXDF_Model_Mantissa
,
5431 VAXGF_Model_Mantissa
,
5432 AAMPS_Model_Mantissa
,
5433 AAMPL_Model_Mantissa
);
5439 when Attribute_Model_Small
=>
5440 Float_Attribute_Universal_Real
(
5441 IEEES_Model_Small
'Universal_Literal_String,
5442 IEEEL_Model_Small
'Universal_Literal_String,
5443 IEEEX_Model_Small
'Universal_Literal_String,
5444 VAXFF_Model_Small
'Universal_Literal_String,
5445 VAXDF_Model_Small
'Universal_Literal_String,
5446 VAXGF_Model_Small
'Universal_Literal_String,
5447 AAMPS_Model_Small
'Universal_Literal_String,
5448 AAMPL_Model_Small
'Universal_Literal_String);
5454 when Attribute_Modulus
=>
5455 Fold_Uint
(N
, Modulus
(P_Type
), True);
5457 --------------------
5458 -- Null_Parameter --
5459 --------------------
5461 -- Cannot fold, we know the value sort of, but the whole point is
5462 -- that there is no way to talk about this imaginary value except
5463 -- by using the attribute, so we leave it the way it is.
5465 when Attribute_Null_Parameter
=>
5472 -- The Object_Size attribute for a type returns the Esize of the
5473 -- type and can be folded if this value is known.
5475 when Attribute_Object_Size
=> Object_Size
: declare
5476 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5479 if Known_Esize
(P_TypeA
) then
5480 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5484 -------------------------
5485 -- Passed_By_Reference --
5486 -------------------------
5488 -- Scalar types are never passed by reference
5490 when Attribute_Passed_By_Reference
=>
5491 Fold_Uint
(N
, False_Value
, True);
5497 when Attribute_Pos
=>
5498 Fold_Uint
(N
, Expr_Value
(E1
), True);
5504 when Attribute_Pred
=> Pred
:
5506 -- Floating-point case
5508 if Is_Floating_Point_Type
(P_Type
) then
5510 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5514 elsif Is_Fixed_Point_Type
(P_Type
) then
5516 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
5518 -- Modular integer case (wraps)
5520 elsif Is_Modular_Integer_Type
(P_Type
) then
5521 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
5523 -- Other scalar cases
5526 pragma Assert
(Is_Scalar_Type
(P_Type
));
5528 if Is_Enumeration_Type
(P_Type
)
5529 and then Expr_Value
(E1
) =
5530 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5532 Apply_Compile_Time_Constraint_Error
5533 (N
, "Pred of `&''First`",
5534 CE_Overflow_Check_Failed
,
5536 Warn
=> not Static
);
5542 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
5550 -- No processing required, because by this stage, Range has been
5551 -- replaced by First .. Last, so this branch can never be taken.
5553 when Attribute_Range
=>
5554 raise Program_Error
;
5560 when Attribute_Range_Length
=>
5563 if Compile_Time_Known_Value
(Hi_Bound
)
5564 and then Compile_Time_Known_Value
(Lo_Bound
)
5568 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
5576 when Attribute_Remainder
=>
5579 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
5586 when Attribute_Round
=> Round
:
5592 -- First we get the (exact result) in units of small
5594 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5596 -- Now round that exactly to an integer
5598 Si
:= UR_To_Uint
(Sr
);
5600 -- Finally the result is obtained by converting back to real
5602 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
5609 when Attribute_Rounding
=>
5611 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5617 when Attribute_Safe_Emax
=>
5618 Float_Attribute_Universal_Integer
(
5632 when Attribute_Safe_First
=>
5633 Float_Attribute_Universal_Real
(
5634 IEEES_Safe_First
'Universal_Literal_String,
5635 IEEEL_Safe_First
'Universal_Literal_String,
5636 IEEEX_Safe_First
'Universal_Literal_String,
5637 VAXFF_Safe_First
'Universal_Literal_String,
5638 VAXDF_Safe_First
'Universal_Literal_String,
5639 VAXGF_Safe_First
'Universal_Literal_String,
5640 AAMPS_Safe_First
'Universal_Literal_String,
5641 AAMPL_Safe_First
'Universal_Literal_String);
5647 when Attribute_Safe_Large
=>
5648 if Is_Fixed_Point_Type
(P_Type
) then
5650 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
5652 Float_Attribute_Universal_Real
(
5653 IEEES_Safe_Large
'Universal_Literal_String,
5654 IEEEL_Safe_Large
'Universal_Literal_String,
5655 IEEEX_Safe_Large
'Universal_Literal_String,
5656 VAXFF_Safe_Large
'Universal_Literal_String,
5657 VAXDF_Safe_Large
'Universal_Literal_String,
5658 VAXGF_Safe_Large
'Universal_Literal_String,
5659 AAMPS_Safe_Large
'Universal_Literal_String,
5660 AAMPL_Safe_Large
'Universal_Literal_String);
5667 when Attribute_Safe_Last
=>
5668 Float_Attribute_Universal_Real
(
5669 IEEES_Safe_Last
'Universal_Literal_String,
5670 IEEEL_Safe_Last
'Universal_Literal_String,
5671 IEEEX_Safe_Last
'Universal_Literal_String,
5672 VAXFF_Safe_Last
'Universal_Literal_String,
5673 VAXDF_Safe_Last
'Universal_Literal_String,
5674 VAXGF_Safe_Last
'Universal_Literal_String,
5675 AAMPS_Safe_Last
'Universal_Literal_String,
5676 AAMPL_Safe_Last
'Universal_Literal_String);
5682 when Attribute_Safe_Small
=>
5684 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5685 -- for fixed-point, since is the same as Small, but we implement
5686 -- it for backwards compatibility.
5688 if Is_Fixed_Point_Type
(P_Type
) then
5689 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
5691 -- Ada 83 Safe_Small for floating-point cases
5694 Float_Attribute_Universal_Real
(
5695 IEEES_Safe_Small
'Universal_Literal_String,
5696 IEEEL_Safe_Small
'Universal_Literal_String,
5697 IEEEX_Safe_Small
'Universal_Literal_String,
5698 VAXFF_Safe_Small
'Universal_Literal_String,
5699 VAXDF_Safe_Small
'Universal_Literal_String,
5700 VAXGF_Safe_Small
'Universal_Literal_String,
5701 AAMPS_Safe_Small
'Universal_Literal_String,
5702 AAMPL_Safe_Small
'Universal_Literal_String);
5709 when Attribute_Scale
=>
5710 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
5716 when Attribute_Scaling
=>
5719 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5725 when Attribute_Signed_Zeros
=>
5727 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
5733 -- Size attribute returns the RM size. All scalar types can be folded,
5734 -- as well as any types for which the size is known by the front end,
5735 -- including any type for which a size attribute is specified.
5737 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
5738 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5741 if RM_Size
(P_TypeA
) /= Uint_0
then
5745 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
5747 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
5750 -- If a size clause applies, then use the size from it.
5751 -- This is one of the rare cases where we can use the
5752 -- Size_Clause field for a subtype when Has_Size_Clause
5753 -- is False. Consider:
5755 -- type x is range 1 .. 64; g
5756 -- for x'size use 12;
5757 -- subtype y is x range 0 .. 3;
5759 -- Here y has a size clause inherited from x, but normally
5760 -- it does not apply, and y'size is 2. However, y'VADS_Size
5761 -- is indeed 12 and not 2.
5764 and then Is_OK_Static_Expression
(Expression
(S
))
5766 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
5768 -- If no size is specified, then we simply use the object
5769 -- size in the VADS_Size case (e.g. Natural'Size is equal
5770 -- to Integer'Size, not one less).
5773 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5777 -- Normal case (Size) in which case we want the RM_Size
5782 Static
and then Is_Discrete_Type
(P_TypeA
));
5791 when Attribute_Small
=>
5793 -- The floating-point case is present only for Ada 83 compatability.
5794 -- Note that strictly this is an illegal addition, since we are
5795 -- extending an Ada 95 defined attribute, but we anticipate an
5796 -- ARG ruling that will permit this.
5798 if Is_Floating_Point_Type
(P_Type
) then
5800 -- Ada 83 attribute is defined as (RM83 3.5.8)
5802 -- T'Small = 2.0**(-T'Emax - 1)
5806 -- T'Emax = 4 * T'Mantissa
5808 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
5810 -- Normal Ada 95 fixed-point case
5813 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
5820 when Attribute_Succ
=> Succ
:
5822 -- Floating-point case
5824 if Is_Floating_Point_Type
(P_Type
) then
5826 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5830 elsif Is_Fixed_Point_Type
(P_Type
) then
5832 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
5834 -- Modular integer case (wraps)
5836 elsif Is_Modular_Integer_Type
(P_Type
) then
5837 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
5839 -- Other scalar cases
5842 pragma Assert
(Is_Scalar_Type
(P_Type
));
5844 if Is_Enumeration_Type
(P_Type
)
5845 and then Expr_Value
(E1
) =
5846 Expr_Value
(Type_High_Bound
(P_Base_Type
))
5848 Apply_Compile_Time_Constraint_Error
5849 (N
, "Succ of `&''Last`",
5850 CE_Overflow_Check_Failed
,
5852 Warn
=> not Static
);
5857 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
5866 when Attribute_Truncation
=>
5868 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5874 when Attribute_Type_Class
=> Type_Class
: declare
5875 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
5879 if Is_Descendent_Of_Address
(Typ
) then
5880 Id
:= RE_Type_Class_Address
;
5882 elsif Is_Enumeration_Type
(Typ
) then
5883 Id
:= RE_Type_Class_Enumeration
;
5885 elsif Is_Integer_Type
(Typ
) then
5886 Id
:= RE_Type_Class_Integer
;
5888 elsif Is_Fixed_Point_Type
(Typ
) then
5889 Id
:= RE_Type_Class_Fixed_Point
;
5891 elsif Is_Floating_Point_Type
(Typ
) then
5892 Id
:= RE_Type_Class_Floating_Point
;
5894 elsif Is_Array_Type
(Typ
) then
5895 Id
:= RE_Type_Class_Array
;
5897 elsif Is_Record_Type
(Typ
) then
5898 Id
:= RE_Type_Class_Record
;
5900 elsif Is_Access_Type
(Typ
) then
5901 Id
:= RE_Type_Class_Access
;
5903 elsif Is_Enumeration_Type
(Typ
) then
5904 Id
:= RE_Type_Class_Enumeration
;
5906 elsif Is_Task_Type
(Typ
) then
5907 Id
:= RE_Type_Class_Task
;
5909 -- We treat protected types like task types. It would make more
5910 -- sense to have another enumeration value, but after all the
5911 -- whole point of this feature is to be exactly DEC compatible,
5912 -- and changing the type Type_Clas would not meet this requirement.
5914 elsif Is_Protected_Type
(Typ
) then
5915 Id
:= RE_Type_Class_Task
;
5917 -- Not clear if there are any other possibilities, but if there
5918 -- are, then we will treat them as the address case.
5921 Id
:= RE_Type_Class_Address
;
5924 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
5928 -----------------------
5929 -- Unbiased_Rounding --
5930 -----------------------
5932 when Attribute_Unbiased_Rounding
=>
5934 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
5937 -------------------------
5938 -- Unconstrained_Array --
5939 -------------------------
5941 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
5942 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5945 Rewrite
(N
, New_Occurrence_Of
(
5947 Is_Array_Type
(P_Type
)
5948 and then not Is_Constrained
(Typ
)), Loc
));
5950 -- Analyze and resolve as boolean, note that this attribute is
5951 -- a static attribute in GNAT.
5953 Analyze_And_Resolve
(N
, Standard_Boolean
);
5955 end Unconstrained_Array
;
5961 -- Processing is shared with Size
5967 when Attribute_Val
=> Val
:
5969 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5971 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
5973 Apply_Compile_Time_Constraint_Error
5974 (N
, "Val expression out of range",
5975 CE_Range_Check_Failed
,
5976 Warn
=> not Static
);
5982 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5990 -- The Value_Size attribute for a type returns the RM size of the
5991 -- type. This an always be folded for scalar types, and can also
5992 -- be folded for non-scalar types if the size is set.
5994 when Attribute_Value_Size
=> Value_Size
: declare
5995 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5998 if RM_Size
(P_TypeA
) /= Uint_0
then
5999 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6008 -- Version can never be static
6010 when Attribute_Version
=>
6017 -- Wide_Image is a scalar attribute, but is never static, because it
6018 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6020 when Attribute_Wide_Image
=>
6027 -- Processing for Wide_Width is combined with Width
6033 -- This processing also handles the case of Wide_Width
6035 when Attribute_Width | Attribute_Wide_Width
=> Width
:
6037 if Compile_Time_Known_Bounds
(P_Type
) then
6039 -- Floating-point types
6041 if Is_Floating_Point_Type
(P_Type
) then
6043 -- Width is zero for a null range (RM 3.5 (38))
6045 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
6046 Expr_Value_R
(Type_Low_Bound
(P_Type
))
6048 Fold_Uint
(N
, Uint_0
, True);
6051 -- For floating-point, we have +N.dddE+nnn where length
6052 -- of ddd is determined by type'Digits - 1, but is one
6053 -- if Digits is one (RM 3.5 (33)).
6055 -- nnn is set to 2 for Short_Float and Float (32 bit
6056 -- floats), and 3 for Long_Float and Long_Long_Float.
6057 -- This is not quite right, but is good enough.
6061 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
6064 if Esize
(P_Type
) <= 32 then
6070 Fold_Uint
(N
, UI_From_Int
(Len
), True);
6074 -- Fixed-point types
6076 elsif Is_Fixed_Point_Type
(P_Type
) then
6078 -- Width is zero for a null range (RM 3.5 (38))
6080 if Expr_Value
(Type_High_Bound
(P_Type
)) <
6081 Expr_Value
(Type_Low_Bound
(P_Type
))
6083 Fold_Uint
(N
, Uint_0
, True);
6085 -- The non-null case depends on the specific real type
6088 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6091 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
6098 R
: constant Entity_Id
:= Root_Type
(P_Type
);
6099 Lo
: constant Uint
:=
6100 Expr_Value
(Type_Low_Bound
(P_Type
));
6101 Hi
: constant Uint
:=
6102 Expr_Value
(Type_High_Bound
(P_Type
));
6115 -- Width for types derived from Standard.Character
6116 -- and Standard.Wide_Character.
6118 elsif R
= Standard_Character
6119 or else R
= Standard_Wide_Character
6123 -- Set W larger if needed
6125 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
6127 -- Assume all wide-character escape sequences are
6128 -- same length, so we can quit when we reach one.
6131 if Id
= Attribute_Wide_Width
then
6132 W
:= Int
'Max (W
, 3);
6135 W
:= Int
'Max (W
, Length_Wide
);
6140 C
:= Character'Val (J
);
6142 -- Test for all cases where Character'Image
6143 -- yields an image that is longer than three
6144 -- characters. First the cases of Reserved_xxx
6145 -- names (length = 12).
6148 when Reserved_128 | Reserved_129 |
6149 Reserved_132 | Reserved_153
6153 when BS | HT | LF | VT | FF | CR |
6154 SO | SI | EM | FS | GS | RS |
6155 US | RI | MW | ST | PM
6159 when NUL | SOH | STX | ETX | EOT |
6160 ENQ | ACK | BEL | DLE | DC1 |
6161 DC2 | DC3 | DC4 | NAK | SYN |
6162 ETB | CAN | SUB | ESC | DEL |
6163 BPH | NBH | NEL | SSA | ESA |
6164 HTS | HTJ | VTS | PLD | PLU |
6165 SS2 | SS3 | DCS | PU1 | PU2 |
6166 STS | CCH | SPA | EPA | SOS |
6167 SCI | CSI | OSC | APC
6171 when Space
.. Tilde |
6172 No_Break_Space
.. LC_Y_Diaeresis
6177 W
:= Int
'Max (W
, Wt
);
6181 -- Width for types derived from Standard.Boolean
6183 elsif R
= Standard_Boolean
then
6190 -- Width for integer types
6192 elsif Is_Integer_Type
(P_Type
) then
6193 T
:= UI_Max
(abs Lo
, abs Hi
);
6201 -- Only remaining possibility is user declared enum type
6204 pragma Assert
(Is_Enumeration_Type
(P_Type
));
6207 L
:= First_Literal
(P_Type
);
6209 while Present
(L
) loop
6211 -- Only pay attention to in range characters
6213 if Lo
<= Enumeration_Pos
(L
)
6214 and then Enumeration_Pos
(L
) <= Hi
6216 -- For Width case, use decoded name
6218 if Id
= Attribute_Width
then
6219 Get_Decoded_Name_String
(Chars
(L
));
6220 Wt
:= Nat
(Name_Len
);
6222 -- For Wide_Width, use encoded name, and then
6223 -- adjust for the encoding.
6226 Get_Name_String
(Chars
(L
));
6228 -- Character literals are always of length 3
6230 if Name_Buffer
(1) = 'Q' then
6233 -- Otherwise loop to adjust for upper/wide chars
6236 Wt
:= Nat
(Name_Len
);
6238 for J
in 1 .. Name_Len
loop
6239 if Name_Buffer
(J
) = 'U' then
6241 elsif Name_Buffer
(J
) = 'W' then
6248 W
:= Int
'Max (W
, Wt
);
6255 Fold_Uint
(N
, UI_From_Int
(W
), True);
6261 -- The following attributes can never be folded, and furthermore we
6262 -- should not even have entered the case statement for any of these.
6263 -- Note that in some cases, the values have already been folded as
6264 -- a result of the processing in Analyze_Attribute.
6266 when Attribute_Abort_Signal |
6269 Attribute_Address_Size |
6270 Attribute_Asm_Input |
6271 Attribute_Asm_Output |
6273 Attribute_Bit_Order |
6274 Attribute_Bit_Position |
6275 Attribute_Callable |
6278 Attribute_Code_Address |
6280 Attribute_Default_Bit_Order |
6281 Attribute_Elaborated |
6282 Attribute_Elab_Body |
6283 Attribute_Elab_Spec |
6284 Attribute_External_Tag |
6285 Attribute_First_Bit |
6287 Attribute_Last_Bit |
6288 Attribute_Maximum_Alignment |
6290 Attribute_Partition_ID |
6291 Attribute_Pool_Address |
6292 Attribute_Position |
6294 Attribute_Storage_Pool |
6295 Attribute_Storage_Size |
6296 Attribute_Storage_Unit |
6298 Attribute_Target_Name |
6299 Attribute_Terminated |
6300 Attribute_To_Address |
6301 Attribute_UET_Address |
6302 Attribute_Unchecked_Access |
6303 Attribute_Universal_Literal_String |
6304 Attribute_Unrestricted_Access |
6307 Attribute_Wchar_T_Size |
6308 Attribute_Wide_Value |
6309 Attribute_Word_Size |
6312 raise Program_Error
;
6316 -- At the end of the case, one more check. If we did a static evaluation
6317 -- so that the result is now a literal, then set Is_Static_Expression
6318 -- in the constant only if the prefix type is a static subtype. For
6319 -- non-static subtypes, the folding is still OK, but not static.
6321 -- An exception is the GNAT attribute Constrained_Array which is
6322 -- defined to be a static attribute in all cases.
6324 if Nkind
(N
) = N_Integer_Literal
6325 or else Nkind
(N
) = N_Real_Literal
6326 or else Nkind
(N
) = N_Character_Literal
6327 or else Nkind
(N
) = N_String_Literal
6328 or else (Is_Entity_Name
(N
)
6329 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6331 Set_Is_Static_Expression
(N
, Static
);
6333 -- If this is still an attribute reference, then it has not been folded
6334 -- and that means that its expressions are in a non-static context.
6336 elsif Nkind
(N
) = N_Attribute_Reference
then
6339 -- Note: the else case not covered here are odd cases where the
6340 -- processing has transformed the attribute into something other
6341 -- than a constant. Nothing more to do in such cases.
6349 ------------------------------
6350 -- Is_Anonymous_Tagged_Base --
6351 ------------------------------
6353 function Is_Anonymous_Tagged_Base
6360 Anon
= Current_Scope
6361 and then Is_Itype
(Anon
)
6362 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6363 end Is_Anonymous_Tagged_Base
;
6365 -----------------------
6366 -- Resolve_Attribute --
6367 -----------------------
6369 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6370 Loc
: constant Source_Ptr
:= Sloc
(N
);
6371 P
: constant Node_Id
:= Prefix
(N
);
6372 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6373 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6374 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6375 Index
: Interp_Index
;
6377 Nom_Subt
: Entity_Id
;
6380 -- If error during analysis, no point in continuing, except for
6381 -- array types, where we get better recovery by using unconstrained
6382 -- indices than nothing at all (see Check_Array_Type).
6385 and then Attr_Id
/= Attribute_First
6386 and then Attr_Id
/= Attribute_Last
6387 and then Attr_Id
/= Attribute_Length
6388 and then Attr_Id
/= Attribute_Range
6393 -- If attribute was universal type, reset to actual type
6395 if Etype
(N
) = Universal_Integer
6396 or else Etype
(N
) = Universal_Real
6401 -- Remaining processing depends on attribute
6409 -- For access attributes, if the prefix denotes an entity, it is
6410 -- interpreted as a name, never as a call. It may be overloaded,
6411 -- in which case resolution uses the profile of the context type.
6412 -- Otherwise prefix must be resolved.
6414 when Attribute_Access
6415 | Attribute_Unchecked_Access
6416 | Attribute_Unrestricted_Access
=>
6418 if Is_Variable
(P
) then
6419 Note_Possible_Modification
(P
);
6422 if Is_Entity_Name
(P
) then
6423 if Is_Overloaded
(P
) then
6424 Get_First_Interp
(P
, Index
, It
);
6426 while Present
(It
.Nam
) loop
6428 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6429 Set_Entity
(P
, It
.Nam
);
6431 -- The prefix is definitely NOT overloaded anymore
6432 -- at this point, so we reset the Is_Overloaded
6433 -- flag to avoid any confusion when reanalyzing
6436 Set_Is_Overloaded
(P
, False);
6437 Generate_Reference
(Entity
(P
), P
);
6441 Get_Next_Interp
(Index
, It
);
6444 -- If it is a subprogram name or a type, there is nothing
6447 elsif not Is_Overloadable
(Entity
(P
))
6448 and then not Is_Type
(Entity
(P
))
6453 Error_Msg_Name_1
:= Aname
;
6455 if not Is_Entity_Name
(P
) then
6458 elsif Is_Abstract
(Entity
(P
))
6459 and then Is_Overloadable
(Entity
(P
))
6461 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6462 Set_Etype
(N
, Any_Type
);
6464 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6465 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6467 ("prefix of % attribute cannot be enumeration literal",
6471 ("prefix of % attribute cannot be intrinsic", P
);
6474 Set_Etype
(N
, Any_Type
);
6476 elsif Is_Thread_Body
(Entity
(P
)) then
6478 ("prefix of % attribute cannot be a thread body", P
);
6481 -- Assignments, return statements, components of aggregates,
6482 -- generic instantiations will require convention checks if
6483 -- the type is an access to subprogram. Given that there will
6484 -- also be accessibility checks on those, this is where the
6485 -- checks can eventually be centralized ???
6487 if Ekind
(Btyp
) = E_Access_Subprogram_Type
6489 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
6491 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
6493 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6495 ("subprogram has invalid convention for context", P
);
6498 Check_Subtype_Conformant
6499 (New_Id
=> Entity
(P
),
6500 Old_Id
=> Designated_Type
(Btyp
),
6504 if Attr_Id
= Attribute_Unchecked_Access
then
6505 Error_Msg_Name_1
:= Aname
;
6507 ("attribute% cannot be applied to a subprogram", P
);
6509 elsif Aname
= Name_Unrestricted_Access
then
6510 null; -- Nothing to check
6512 -- Check the static accessibility rule of 3.10.2(32)
6513 -- In an instance body, if subprogram and type are both
6514 -- local, other rules prevent dangling references, and no
6515 -- warning is needed.
6517 elsif Attr_Id
= Attribute_Access
6518 and then Subprogram_Access_Level
(Entity
(P
)) >
6519 Type_Access_Level
(Btyp
)
6520 and then Ekind
(Btyp
) /=
6521 E_Anonymous_Access_Subprogram_Type
6522 and then Ekind
(Btyp
) /=
6523 E_Anonymous_Access_Protected_Subprogram_Type
6525 if not In_Instance_Body
then
6527 ("subprogram must not be deeper than access type",
6530 elsif Scope
(Entity
(P
)) /= Scope
(Btyp
) then
6532 ("subprogram must not be deeper than access type?",
6535 ("Constraint_Error will be raised ?", P
);
6536 Set_Raises_Constraint_Error
(N
);
6539 -- Check the restriction of 3.10.2(32) that disallows
6540 -- the type of the access attribute to be declared
6541 -- outside a generic body when the subprogram is declared
6542 -- within that generic body.
6544 elsif Enclosing_Generic_Body
(Entity
(P
))
6545 /= Enclosing_Generic_Body
(Btyp
)
6548 ("access type must not be outside generic body", P
);
6552 -- if this is a renaming, an inherited operation, or a
6553 -- subprogram instance, use the original entity.
6555 if Is_Entity_Name
(P
)
6556 and then Is_Overloadable
(Entity
(P
))
6557 and then Present
(Alias
(Entity
(P
)))
6560 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6563 elsif Nkind
(P
) = N_Selected_Component
6564 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
6566 -- Protected operation. If operation is overloaded, must
6567 -- disambiguate. Prefix that denotes protected object itself
6568 -- is resolved with its own type.
6570 if Attr_Id
= Attribute_Unchecked_Access
then
6571 Error_Msg_Name_1
:= Aname
;
6573 ("attribute% cannot be applied to protected operation", P
);
6576 Resolve
(Prefix
(P
));
6577 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
6579 elsif Is_Overloaded
(P
) then
6581 -- Use the designated type of the context to disambiguate.
6583 Index
: Interp_Index
;
6586 Get_First_Interp
(P
, Index
, It
);
6588 while Present
(It
.Typ
) loop
6589 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
6590 Resolve
(P
, It
.Typ
);
6594 Get_Next_Interp
(Index
, It
);
6601 -- X'Access is illegal if X denotes a constant and the access
6602 -- type is access-to-variable. Same for 'Unchecked_Access.
6603 -- The rule does not apply to 'Unrestricted_Access.
6605 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
6606 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
6607 or else (Is_Record_Type
(Btyp
) and then
6608 Present
(Corresponding_Remote_Type
(Btyp
)))
6609 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6610 or else Ekind
(Btyp
)
6611 = E_Anonymous_Access_Protected_Subprogram_Type
6612 or else Is_Access_Constant
(Btyp
)
6613 or else Is_Variable
(P
)
6614 or else Attr_Id
= Attribute_Unrestricted_Access
)
6616 if Comes_From_Source
(N
) then
6617 Error_Msg_N
("access-to-variable designates constant", P
);
6621 if (Attr_Id
= Attribute_Access
6623 Attr_Id
= Attribute_Unchecked_Access
)
6624 and then (Ekind
(Btyp
) = E_General_Access_Type
6625 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
6627 -- Ada 0Y (AI-230): Check the accessibility of anonymous access
6628 -- types in record and array components. For a component defini
6629 -- tion the level is the same of the enclosing composite type.
6631 if Extensions_Allowed
6632 and then Ekind
(Btyp
) = E_Anonymous_Access_Type
6633 and then (Is_Array_Type
(Scope
(Btyp
))
6634 or else Ekind
(Scope
(Btyp
)) = E_Record_Type
)
6635 and then Object_Access_Level
(P
)
6636 > Type_Access_Level
(Btyp
)
6638 -- In an instance, this is a runtime check, but one we
6639 -- know will fail, so generate an appropriate warning.
6641 if In_Instance_Body
then
6643 ("?non-local pointer cannot point to local object", P
);
6645 ("?Program_Error will be raised at run time", P
);
6647 Make_Raise_Program_Error
(Loc
,
6648 Reason
=> PE_Accessibility_Check_Failed
));
6652 ("non-local pointer cannot point to local object", P
);
6656 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
6658 ("illegal attribute for discriminant-dependent component",
6662 -- Check the static matching rule of 3.10.2(27). The
6663 -- nominal subtype of the prefix must statically
6664 -- match the designated type.
6666 Nom_Subt
:= Etype
(P
);
6668 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
6669 Nom_Subt
:= Etype
(Nom_Subt
);
6672 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
6674 -- If the attribute is in the context of an access
6675 -- parameter, then the prefix is allowed to be of
6676 -- the class-wide type (by AI-127).
6678 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
6679 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6680 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
6686 Desig
:= Designated_Type
(Typ
);
6688 if Is_Class_Wide_Type
(Desig
) then
6689 Desig
:= Etype
(Desig
);
6692 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
6697 ("type of prefix: & not compatible",
6700 ("\with &, the expected designated type",
6701 P
, Designated_Type
(Typ
));
6706 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6708 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
6709 and then Is_Class_Wide_Type
(Nom_Subt
))
6712 ("type of prefix: & is not covered", P
, Nom_Subt
);
6714 ("\by &, the expected designated type" &
6715 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
6718 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
6719 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
6720 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
6721 and then Designated_Type
(Typ
) /= Nom_Subt
6723 Apply_Discriminant_Check
6724 (N
, Etype
(Designated_Type
(Typ
)));
6727 elsif not Subtypes_Statically_Match
6728 (Designated_Type
(Base_Type
(Typ
)), Nom_Subt
)
6730 not (Has_Discriminants
(Designated_Type
(Typ
))
6733 (Designated_Type
(Base_Type
(Typ
))))
6736 ("object subtype must statically match "
6737 & "designated subtype", P
);
6739 if Is_Entity_Name
(P
)
6740 and then Is_Array_Type
(Designated_Type
(Typ
))
6744 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
6747 Error_Msg_N
("aliased object has explicit bounds?",
6749 Error_Msg_N
("\declare without bounds"
6750 & " (and with explicit initialization)?", D
);
6751 Error_Msg_N
("\for use with unconstrained access?", D
);
6756 -- Check the static accessibility rule of 3.10.2(28).
6757 -- Note that this check is not performed for the
6758 -- case of an anonymous access type, since the access
6759 -- attribute is always legal in such a context.
6761 if Attr_Id
/= Attribute_Unchecked_Access
6762 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
6763 and then Ekind
(Btyp
) = E_General_Access_Type
6765 -- In an instance, this is a runtime check, but one we
6766 -- know will fail, so generate an appropriate warning.
6768 if In_Instance_Body
then
6770 ("?non-local pointer cannot point to local object", P
);
6772 ("?Program_Error will be raised at run time", P
);
6774 Make_Raise_Program_Error
(Loc
,
6775 Reason
=> PE_Accessibility_Check_Failed
));
6781 ("non-local pointer cannot point to local object", P
);
6783 if Is_Record_Type
(Current_Scope
)
6784 and then (Nkind
(Parent
(N
)) =
6785 N_Discriminant_Association
6787 Nkind
(Parent
(N
)) =
6788 N_Index_Or_Discriminant_Constraint
)
6791 Indic
: Node_Id
:= Parent
(Parent
(N
));
6794 while Present
(Indic
)
6795 and then Nkind
(Indic
) /= N_Subtype_Indication
6797 Indic
:= Parent
(Indic
);
6800 if Present
(Indic
) then
6802 ("\use an access definition for" &
6803 " the access discriminant of&", N
,
6804 Entity
(Subtype_Mark
(Indic
)));
6812 if (Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6814 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
)
6815 and then Is_Entity_Name
(P
)
6816 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
6818 Error_Msg_N
("context requires a protected subprogram", P
);
6820 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
6822 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
6823 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
6825 Error_Msg_N
("context requires a non-protected subprogram", P
);
6828 -- The context cannot be a pool-specific type, but this is a
6829 -- legality rule, not a resolution rule, so it must be checked
6830 -- separately, after possibly disambiguation (see AI-245).
6832 if Ekind
(Btyp
) = E_Access_Type
6833 and then Attr_Id
/= Attribute_Unrestricted_Access
6835 Wrong_Type
(N
, Typ
);
6840 -- Check for incorrect atomic/volatile reference (RM C.6(12))
6842 if Attr_Id
/= Attribute_Unrestricted_Access
then
6843 if Is_Atomic_Object
(P
)
6844 and then not Is_Atomic
(Designated_Type
(Typ
))
6847 ("access to atomic object cannot yield access-to-" &
6848 "non-atomic type", P
);
6850 elsif Is_Volatile_Object
(P
)
6851 and then not Is_Volatile
(Designated_Type
(Typ
))
6854 ("access to volatile object cannot yield access-to-" &
6855 "non-volatile type", P
);
6863 -- Deal with resolving the type for Address attribute, overloading
6864 -- is not permitted here, since there is no context to resolve it.
6866 when Attribute_Address | Attribute_Code_Address
=>
6868 -- To be safe, assume that if the address of a variable is taken,
6869 -- it may be modified via this address, so note modification.
6871 if Is_Variable
(P
) then
6872 Note_Possible_Modification
(P
);
6875 if Nkind
(P
) in N_Subexpr
6876 and then Is_Overloaded
(P
)
6878 Get_First_Interp
(P
, Index
, It
);
6879 Get_Next_Interp
(Index
, It
);
6881 if Present
(It
.Nam
) then
6882 Error_Msg_Name_1
:= Aname
;
6884 ("prefix of % attribute cannot be overloaded", N
);
6889 if not Is_Entity_Name
(P
)
6890 or else not Is_Overloadable
(Entity
(P
))
6892 if not Is_Task_Type
(Etype
(P
))
6893 or else Nkind
(P
) = N_Explicit_Dereference
6899 -- If this is the name of a derived subprogram, or that of a
6900 -- generic actual, the address is that of the original entity.
6902 if Is_Entity_Name
(P
)
6903 and then Is_Overloadable
(Entity
(P
))
6904 and then Present
(Alias
(Entity
(P
)))
6907 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6914 -- Prefix of the AST_Entry attribute is an entry name which must
6915 -- not be resolved, since this is definitely not an entry call.
6917 when Attribute_AST_Entry
=>
6924 -- Prefix of Body_Version attribute can be a subprogram name which
6925 -- must not be resolved, since this is not a call.
6927 when Attribute_Body_Version
=>
6934 -- Prefix of Caller attribute is an entry name which must not
6935 -- be resolved, since this is definitely not an entry call.
6937 when Attribute_Caller
=>
6944 -- Shares processing with Address attribute
6950 -- If the prefix of the Count attribute is an entry name it must not
6951 -- be resolved, since this is definitely not an entry call. However,
6952 -- if it is an element of an entry family, the index itself may
6953 -- have to be resolved because it can be a general expression.
6955 when Attribute_Count
=>
6956 if Nkind
(P
) = N_Indexed_Component
6957 and then Is_Entity_Name
(Prefix
(P
))
6960 Indx
: constant Node_Id
:= First
(Expressions
(P
));
6961 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
6963 Resolve
(Indx
, Entry_Index_Type
(Fam
));
6964 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
6972 -- Prefix of the Elaborated attribute is a subprogram name which
6973 -- must not be resolved, since this is definitely not a call. Note
6974 -- that it is a library unit, so it cannot be overloaded here.
6976 when Attribute_Elaborated
=>
6979 --------------------
6980 -- Mechanism_Code --
6981 --------------------
6983 -- Prefix of the Mechanism_Code attribute is a function name
6984 -- which must not be resolved. Should we check for overloaded ???
6986 when Attribute_Mechanism_Code
=>
6993 -- Most processing is done in sem_dist, after determining the
6994 -- context type. Node is rewritten as a conversion to a runtime call.
6996 when Attribute_Partition_ID
=>
6997 Process_Partition_Id
(N
);
7000 when Attribute_Pool_Address
=>
7007 -- We replace the Range attribute node with a range expression
7008 -- whose bounds are the 'First and 'Last attributes applied to the
7009 -- same prefix. The reason that we do this transformation here
7010 -- instead of in the expander is that it simplifies other parts of
7011 -- the semantic analysis which assume that the Range has been
7012 -- replaced; thus it must be done even when in semantic-only mode
7013 -- (note that the RM specifically mentions this equivalence, we
7014 -- take care that the prefix is only evaluated once).
7016 when Attribute_Range
=> Range_Attribute
:
7021 function Check_Discriminated_Prival
7024 -- The range of a private component constrained by a
7025 -- discriminant is rewritten to make the discriminant
7026 -- explicit. This solves some complex visibility problems
7027 -- related to the use of privals.
7029 --------------------------------
7030 -- Check_Discriminated_Prival --
7031 --------------------------------
7033 function Check_Discriminated_Prival
7038 if Is_Entity_Name
(N
)
7039 and then Ekind
(Entity
(N
)) = E_In_Parameter
7040 and then not Within_Init_Proc
7042 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
7044 return Duplicate_Subexpr
(N
);
7046 end Check_Discriminated_Prival
;
7048 -- Start of processing for Range_Attribute
7051 if not Is_Entity_Name
(P
)
7052 or else not Is_Type
(Entity
(P
))
7057 -- Check whether prefix is (renaming of) private component
7058 -- of protected type.
7060 if Is_Entity_Name
(P
)
7061 and then Comes_From_Source
(N
)
7062 and then Is_Array_Type
(Etype
(P
))
7063 and then Number_Dimensions
(Etype
(P
)) = 1
7064 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
7066 Ekind
(Scope
(Scope
(Entity
(P
)))) =
7070 Check_Discriminated_Prival
7071 (Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
7074 Check_Discriminated_Prival
7075 (Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
7079 Make_Attribute_Reference
(Loc
,
7080 Prefix
=> Duplicate_Subexpr
(P
),
7081 Attribute_Name
=> Name_Last
,
7082 Expressions
=> Expressions
(N
));
7085 Make_Attribute_Reference
(Loc
,
7087 Attribute_Name
=> Name_First
,
7088 Expressions
=> Expressions
(N
));
7091 -- If the original was marked as Must_Not_Freeze (see code
7092 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7093 -- does not freeze either.
7095 if Must_Not_Freeze
(N
) then
7096 Set_Must_Not_Freeze
(HB
);
7097 Set_Must_Not_Freeze
(LB
);
7098 Set_Must_Not_Freeze
(Prefix
(HB
));
7099 Set_Must_Not_Freeze
(Prefix
(LB
));
7102 if Raises_Constraint_Error
(Prefix
(N
)) then
7104 -- Preserve Sloc of prefix in the new bounds, so that
7105 -- the posted warning can be removed if we are within
7106 -- unreachable code.
7108 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
7109 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
7112 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
7113 Analyze_And_Resolve
(N
, Typ
);
7115 -- Normally after resolving attribute nodes, Eval_Attribute
7116 -- is called to do any possible static evaluation of the node.
7117 -- However, here since the Range attribute has just been
7118 -- transformed into a range expression it is no longer an
7119 -- attribute node and therefore the call needs to be avoided
7120 -- and is accomplished by simply returning from the procedure.
7123 end Range_Attribute
;
7129 -- Prefix must not be resolved in this case, since it is not a
7130 -- real entity reference. No action of any kind is require!
7132 when Attribute_UET_Address
=>
7135 ----------------------
7136 -- Unchecked_Access --
7137 ----------------------
7139 -- Processing is shared with Access
7141 -------------------------
7142 -- Unrestricted_Access --
7143 -------------------------
7145 -- Processing is shared with Access
7151 -- Apply range check. Note that we did not do this during the
7152 -- analysis phase, since we wanted Eval_Attribute to have a
7153 -- chance at finding an illegal out of range value.
7155 when Attribute_Val
=>
7157 -- Note that we do our own Eval_Attribute call here rather than
7158 -- use the common one, because we need to do processing after
7159 -- the call, as per above comment.
7163 -- Eval_Attribute may replace the node with a raise CE, or
7164 -- fold it to a constant. Obviously we only apply a scalar
7165 -- range check if this did not happen!
7167 if Nkind
(N
) = N_Attribute_Reference
7168 and then Attribute_Name
(N
) = Name_Val
7170 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
7179 -- Prefix of Version attribute can be a subprogram name which
7180 -- must not be resolved, since this is not a call.
7182 when Attribute_Version
=>
7185 ----------------------
7186 -- Other Attributes --
7187 ----------------------
7189 -- For other attributes, resolve prefix unless it is a type. If
7190 -- the attribute reference itself is a type name ('Base and 'Class)
7191 -- then this is only legal within a task or protected record.
7194 if not Is_Entity_Name
(P
)
7195 or else not Is_Type
(Entity
(P
))
7200 -- If the attribute reference itself is a type name ('Base,
7201 -- 'Class) then this is only legal within a task or protected
7202 -- record. What is this all about ???
7204 if Is_Entity_Name
(N
)
7205 and then Is_Type
(Entity
(N
))
7207 if Is_Concurrent_Type
(Entity
(N
))
7208 and then In_Open_Scopes
(Entity
(P
))
7213 ("invalid use of subtype name in expression or call", N
);
7217 -- For attributes whose argument may be a string, complete
7218 -- resolution of argument now. This avoids premature expansion
7219 -- (and the creation of transient scopes) before the attribute
7220 -- reference is resolved.
7223 when Attribute_Value
=>
7224 Resolve
(First
(Expressions
(N
)), Standard_String
);
7226 when Attribute_Wide_Value
=>
7227 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
7229 when others => null;
7233 -- Normally the Freezing is done by Resolve but sometimes the Prefix
7234 -- is not resolved, in which case the freezing must be done now.
7236 Freeze_Expression
(P
);
7238 -- Finally perform static evaluation on the attribute reference
7242 end Resolve_Attribute
;