1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
28 with Atree
; use Atree
;
29 with Casing
; use Casing
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Dist
; use Exp_Dist
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
46 with Sdefault
; use Sdefault
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Dist
; use Sem_Dist
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sem_Util
; use Sem_Util
;
56 with Stand
; use Stand
;
57 with Sinfo
; use Sinfo
;
58 with Sinput
; use Sinput
;
59 with Stringt
; use Stringt
;
61 with Stylesw
; use Stylesw
;
62 with Targparm
; use Targparm
;
63 with Ttypes
; use Ttypes
;
64 with Ttypef
; use Ttypef
;
65 with Tbuild
; use Tbuild
;
66 with Uintp
; use Uintp
;
67 with Urealp
; use Urealp
;
69 package body Sem_Attr
is
71 True_Value
: constant Uint
:= Uint_1
;
72 False_Value
: constant Uint
:= Uint_0
;
73 -- Synonyms to be used when these constants are used as Boolean values
75 Bad_Attribute
: exception;
76 -- Exception raised if an error is detected during attribute processing,
77 -- used so that we can abandon the processing so we don't run into
78 -- trouble with cascaded errors.
80 -- The following array is the list of attributes defined in the Ada 83 RM
81 -- that are not included in Ada 95, but still get recognized in GNAT.
83 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
89 Attribute_Constrained |
102 Attribute_Leading_Part |
104 Attribute_Machine_Emax |
105 Attribute_Machine_Emin |
106 Attribute_Machine_Mantissa |
107 Attribute_Machine_Overflows |
108 Attribute_Machine_Radix |
109 Attribute_Machine_Rounds |
115 Attribute_Safe_Emax |
116 Attribute_Safe_Large |
117 Attribute_Safe_Small |
120 Attribute_Storage_Size |
122 Attribute_Terminated |
125 Attribute_Width => True,
128 -- The following array is the list of attributes defined in the Ada 2005
129 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
130 -- but in Ada 95 they are considered to be implementation defined.
132 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
133 Attribute_Machine_Rounding |
135 Attribute_Stream_Size |
136 Attribute_Wide_Wide_Width
=> True,
139 -- The following array contains all attributes that imply a modification
140 -- of their prefixes or result in an access value. Such prefixes can be
141 -- considered as lvalues.
143 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
144 Attribute_Class_Array
'(
149 Attribute_Unchecked_Access |
150 Attribute_Unrestricted_Access => True,
153 -----------------------
154 -- Local_Subprograms --
155 -----------------------
157 procedure Eval_Attribute (N : Node_Id);
158 -- Performs compile time evaluation of attributes where possible, leaving
159 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
160 -- set, and replacing the node with a literal node if the value can be
161 -- computed at compile time. All static attribute references are folded,
162 -- as well as a number of cases of non-static attributes that can always
163 -- be computed at compile time (e.g. floating-point model attributes that
164 -- are applied to non-static subtypes). Of course in such cases, the
165 -- Is_Static_Expression flag will not be set on the resulting literal.
166 -- Note that the only required action of this procedure is to catch the
167 -- static expression cases as described in the RM. Folding of other cases
168 -- is done where convenient, but some additional non-static folding is in
169 -- N_Expand_Attribute_Reference in cases where this is more convenient.
171 function Is_Anonymous_Tagged_Base
175 -- For derived tagged types that constrain parent discriminants we build
176 -- an anonymous unconstrained base type. We need to recognize the relation
177 -- between the two when analyzing an access attribute for a constrained
178 -- component, before the full declaration for Typ has been analyzed, and
179 -- where therefore the prefix of the attribute does not match the enclosing
182 -----------------------
183 -- Analyze_Attribute --
184 -----------------------
186 procedure Analyze_Attribute (N : Node_Id) is
187 Loc : constant Source_Ptr := Sloc (N);
188 Aname : constant Name_Id := Attribute_Name (N);
189 P : constant Node_Id := Prefix (N);
190 Exprs : constant List_Id := Expressions (N);
191 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
196 -- Type of prefix after analysis
198 P_Base_Type : Entity_Id;
199 -- Base type of prefix after analysis
201 -----------------------
202 -- Local Subprograms --
203 -----------------------
205 procedure Analyze_Access_Attribute;
206 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
207 -- Internally, Id distinguishes which of the three cases is involved.
209 procedure Check_Array_Or_Scalar_Type;
210 -- Common procedure used by First, Last, Range attribute to check
211 -- that the prefix is a constrained array or scalar type, or a name
212 -- of an array object, and that an argument appears only if appropriate
213 -- (i.e. only in the array case).
215 procedure Check_Array_Type;
216 -- Common semantic checks for all array attributes. Checks that the
217 -- prefix is a constrained array type or the name of an array object.
218 -- The error message for non-arrays is specialized appropriately.
220 procedure Check_Asm_Attribute;
221 -- Common semantic checks for Asm_Input and Asm_Output attributes
223 procedure Check_Component;
224 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
225 -- Position. Checks prefix is an appropriate selected component.
227 procedure Check_Decimal_Fixed_Point_Type;
228 -- Check that prefix of attribute N is a decimal fixed-point type
230 procedure Check_Dereference;
231 -- If the prefix of attribute is an object of an access type, then
232 -- introduce an explicit deference, and adjust P_Type accordingly.
234 procedure Check_Discrete_Type;
235 -- Verify that prefix of attribute N is a discrete type
238 -- Check that no attribute arguments are present
240 procedure Check_Either_E0_Or_E1;
241 -- Check that there are zero or one attribute arguments present
244 -- Check that exactly one attribute argument is present
247 -- Check that two attribute arguments are present
249 procedure Check_Enum_Image;
250 -- If the prefix type is an enumeration type, set all its literals
251 -- as referenced, since the image function could possibly end up
252 -- referencing any of the literals indirectly.
254 procedure Check_Fixed_Point_Type;
255 -- Verify that prefix of attribute N is a fixed type
257 procedure Check_Fixed_Point_Type_0;
258 -- Verify that prefix of attribute N is a fixed type and that
259 -- no attribute expressions are present
261 procedure Check_Floating_Point_Type;
262 -- Verify that prefix of attribute N is a float type
264 procedure Check_Floating_Point_Type_0;
265 -- Verify that prefix of attribute N is a float type and that
266 -- no attribute expressions are present
268 procedure Check_Floating_Point_Type_1;
269 -- Verify that prefix of attribute N is a float type and that
270 -- exactly one attribute expression is present
272 procedure Check_Floating_Point_Type_2;
273 -- Verify that prefix of attribute N is a float type and that
274 -- two attribute expressions are present
276 procedure Legal_Formal_Attribute;
277 -- Common processing for attributes Definite, Has_Access_Values,
278 -- and Has_Discriminants
280 procedure Check_Integer_Type;
281 -- Verify that prefix of attribute N is an integer type
283 procedure Check_Library_Unit;
284 -- Verify that prefix of attribute N is a library unit
286 procedure Check_Modular_Integer_Type;
287 -- Verify that prefix of attribute N is a modular integer type
289 procedure Check_Not_Incomplete_Type;
290 -- Check that P (the prefix of the attribute) is not an incomplete
291 -- type or a private type for which no full view has been given.
293 procedure Check_Object_Reference (P : Node_Id);
294 -- Check that P (the prefix of the attribute) is an object reference
296 procedure Check_Program_Unit;
297 -- Verify that prefix of attribute N is a program unit
299 procedure Check_Real_Type;
300 -- Verify that prefix of attribute N is fixed or float type
302 procedure Check_Scalar_Type;
303 -- Verify that prefix of attribute N is a scalar type
305 procedure Check_Standard_Prefix;
306 -- Verify that prefix of attribute N is package Standard
308 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
309 -- Validity checking for stream attribute. Nam is the TSS name of the
310 -- corresponding possible defined attribute function (e.g. for the
311 -- Read attribute, Nam will be TSS_Stream_Read).
313 procedure Check_Task_Prefix;
314 -- Verify that prefix of attribute N is a task or task type
316 procedure Check_Type;
317 -- Verify that the prefix of attribute N is a type
319 procedure Check_Unit_Name (Nod : Node_Id);
320 -- Check that Nod is of the form of a library unit name, i.e that
321 -- it is an identifier, or a selected component whose prefix is
322 -- itself of the form of a library unit name. Note that this is
323 -- quite different from Check_Program_Unit, since it only checks
324 -- the syntactic form of the name, not the semantic identity. This
325 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
326 -- UET_Address) which can refer to non-visible unit.
328 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
329 pragma No_Return (Error_Attr);
330 procedure Error_Attr;
331 pragma No_Return (Error_Attr);
332 -- Posts error using Error_Msg_N at given node, sets type of attribute
333 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
334 -- semantic processing. The message typically contains a % insertion
335 -- character which is replaced by the attribute name. The call with
336 -- no arguments is used when the caller has already generated the
337 -- required error messages.
339 procedure Error_Attr_P (Msg : String);
340 pragma No_Return (Error_Attr);
341 -- Like Error_Attr, but error is posted at the start of the prefix
343 procedure Standard_Attribute (Val : Int);
344 -- Used to process attributes whose prefix is package Standard which
345 -- yield values of type Universal_Integer. The attribute reference
346 -- node is rewritten with an integer literal of the given value.
348 procedure Unexpected_Argument (En : Node_Id);
349 -- Signal unexpected attribute argument (En is the argument)
351 procedure Validate_Non_Static_Attribute_Function_Call;
352 -- Called when processing an attribute that is a function call to a
353 -- non-static function, i.e. an attribute function that either takes
354 -- non-scalar arguments or returns a non-scalar result. Verifies that
355 -- such a call does not appear in a preelaborable context.
357 ------------------------------
358 -- Analyze_Access_Attribute --
359 ------------------------------
361 procedure Analyze_Access_Attribute is
362 Acc_Type : Entity_Id;
367 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
368 -- Build an access-to-object type whose designated type is DT,
369 -- and whose Ekind is appropriate to the attribute type. The
370 -- type that is constructed is returned as the result.
372 procedure Build_Access_Subprogram_Type (P : Node_Id);
373 -- Build an access to subprogram whose designated type is
374 -- the type of the prefix. If prefix is overloaded, so it the
375 -- node itself. The result is stored in Acc_Type.
377 function OK_Self_Reference return Boolean;
378 -- An access reference whose prefix is a type can legally appear
379 -- within an aggregate, where it is obtained by expansion of
380 -- a defaulted aggregate. The enclosing aggregate that contains
381 -- the self-referenced is flagged so that the self-reference can
382 -- be expanded into a reference to the target object (see exp_aggr).
384 ------------------------------
385 -- Build_Access_Object_Type --
386 ------------------------------
388 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
389 Typ : constant Entity_Id :=
391 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
393 Set_Etype (Typ, Typ);
394 Init_Size_Align (Typ);
396 Set_Associated_Node_For_Itype (Typ, N);
397 Set_Directly_Designated_Type (Typ, DT);
399 end Build_Access_Object_Type;
401 ----------------------------------
402 -- Build_Access_Subprogram_Type --
403 ----------------------------------
405 procedure Build_Access_Subprogram_Type (P : Node_Id) is
406 Index : Interp_Index;
409 procedure Check_Local_Access (E : Entity_Id);
410 -- Deal with possible access to local subprogram. If we have such
411 -- an access, we set a flag to kill all tracked values on any call
412 -- because this access value may be passed around, and any called
413 -- code might use it to access a local procedure which clobbers a
416 function Get_Kind (E : Entity_Id) return Entity_Kind;
417 -- Distinguish between access to regular/protected subprograms
419 ------------------------
420 -- Check_Local_Access --
421 ------------------------
423 procedure Check_Local_Access (E : Entity_Id) is
425 if not Is_Library_Level_Entity (E) then
426 Set_Suppress_Value_Tracking_On_Call (Current_Scope);
428 end Check_Local_Access;
434 function Get_Kind (E : Entity_Id) return Entity_Kind is
436 if Convention (E) = Convention_Protected then
437 return E_Access_Protected_Subprogram_Type;
439 return E_Access_Subprogram_Type;
443 -- Start of processing for Build_Access_Subprogram_Type
446 -- In the case of an access to subprogram, use the name of the
447 -- subprogram itself as the designated type. Type-checking in
448 -- this case compares the signatures of the designated types.
450 Set_Etype (N, Any_Type);
452 if not Is_Overloaded (P) then
453 Check_Local_Access (Entity (P));
455 if not Is_Intrinsic_Subprogram (Entity (P)) then
458 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
459 Set_Etype (Acc_Type, Acc_Type);
460 Set_Directly_Designated_Type (Acc_Type, Entity (P));
461 Set_Etype (N, Acc_Type);
465 Get_First_Interp (P, Index, It);
466 while Present (It.Nam) loop
467 Check_Local_Access (It.Nam);
469 if not Is_Intrinsic_Subprogram (It.Nam) then
472 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
473 Set_Etype (Acc_Type, Acc_Type);
474 Set_Directly_Designated_Type (Acc_Type, It.Nam);
475 Add_One_Interp (N, Acc_Type, Acc_Type);
478 Get_Next_Interp (Index, It);
482 -- Cannot be applied to intrinsic. Looking at the tests above,
483 -- the only way Etype (N) can still be set to Any_Type is if
484 -- Is_Intrinsic_Subprogram was True for some referenced entity.
486 if Etype (N) = Any_Type then
487 Error_Attr_P ("prefix of % attribute cannot be intrinsic");
489 end Build_Access_Subprogram_Type;
491 ----------------------
492 -- OK_Self_Reference --
493 ----------------------
495 function OK_Self_Reference return Boolean is
502 (Nkind (Par) = N_Component_Association
503 or else Nkind (Par) in N_Subexpr)
505 if Nkind (Par) = N_Aggregate
506 or else Nkind (Par) = N_Extension_Aggregate
508 if Etype (Par) = Typ then
509 Set_Has_Self_Reference (Par);
517 -- No enclosing aggregate, or not a self-reference
520 end OK_Self_Reference;
522 -- Start of processing for Analyze_Access_Attribute
527 if Nkind (P) = N_Character_Literal then
529 ("prefix of % attribute cannot be enumeration literal");
532 -- Case of access to subprogram
534 if Is_Entity_Name (P)
535 and then Is_Overloadable (Entity (P))
537 if Has_Pragma_Inline_Always (Entity (P)) then
539 ("prefix of % attribute cannot be Inline_Always subprogram");
542 if Aname = Name_Unchecked_Access then
543 Error_Attr ("attribute% cannot be applied to a subprogram", P);
546 -- Build the appropriate subprogram type
548 Build_Access_Subprogram_Type (P);
550 -- For unrestricted access, kill current values, since this
551 -- attribute allows a reference to a local subprogram that
552 -- could modify local variables to be passed out of scope
554 if Aname = Name_Unrestricted_Access then
560 -- Component is an operation of a protected type
562 elsif Nkind (P) = N_Selected_Component
563 and then Is_Overloadable (Entity (Selector_Name (P)))
565 if Ekind (Entity (Selector_Name (P))) = E_Entry then
566 Error_Attr_P ("prefix of % attribute must be subprogram");
569 Build_Access_Subprogram_Type (Selector_Name (P));
573 -- Deal with incorrect reference to a type, but note that some
574 -- accesses are allowed: references to the current type instance,
575 -- or in Ada 2005 self-referential pointer in a default-initialized
578 if Is_Entity_Name (P) then
581 -- The reference may appear in an aggregate that has been expanded
582 -- into a loop. Locate scope of type definition, if any.
584 Scop := Current_Scope;
585 while Ekind (Scop) = E_Loop loop
586 Scop := Scope (Scop);
589 if Is_Type (Typ) then
591 -- OK if we are within the scope of a limited type
592 -- let's mark the component as having per object constraint
594 if Is_Anonymous_Tagged_Base (Scop, Typ) then
602 Q : Node_Id := Parent (N);
606 and then Nkind (Q) /= N_Component_Declaration
612 Set_Has_Per_Object_Constraint (
613 Defining_Identifier (Q), True);
617 if Nkind (P) = N_Expanded_Name then
619 ("current instance prefix must be a direct name", P);
622 -- If a current instance attribute appears within a
623 -- a component constraint it must appear alone; other
624 -- contexts (default expressions, within a task body)
625 -- are not subject to this restriction.
627 if not In_Default_Expression
628 and then not Has_Completion (Scop)
630 Nkind (Parent (N)) /= N_Discriminant_Association
632 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
635 ("current instance attribute must appear alone", N);
638 -- OK if we are in initialization procedure for the type
639 -- in question, in which case the reference to the type
640 -- is rewritten as a reference to the current object.
642 elsif Ekind (Scop) = E_Procedure
643 and then Is_Init_Proc (Scop)
644 and then Etype (First_Formal (Scop)) = Typ
647 Make_Attribute_Reference (Loc,
648 Prefix => Make_Identifier (Loc, Name_uInit),
649 Attribute_Name => Name_Unrestricted_Access));
653 -- OK if a task type, this test needs sharpening up ???
655 elsif Is_Task_Type (Typ) then
658 -- OK if self-reference in an aggregate in Ada 2005, and
659 -- the reference comes from a copied default expression.
661 -- Note that we check legality of self-reference even if the
662 -- expression comes from source, e.g. when a single component
663 -- association in an aggregate has a box association.
665 elsif Ada_Version >= Ada_05
666 and then OK_Self_Reference
670 -- Otherwise we have an error case
673 Error_Attr ("% attribute cannot be applied to type", P);
679 -- If we fall through, we have a normal access to object case.
680 -- Unrestricted_Access is legal wherever an allocator would be
681 -- legal, so its Etype is set to E_Allocator. The expected type
682 -- of the other attributes is a general access type, and therefore
683 -- we label them with E_Access_Attribute_Type.
685 if not Is_Overloaded (P) then
686 Acc_Type := Build_Access_Object_Type (P_Type);
687 Set_Etype (N, Acc_Type);
690 Index : Interp_Index;
693 Set_Etype (N, Any_Type);
694 Get_First_Interp (P, Index, It);
695 while Present (It.Typ) loop
696 Acc_Type := Build_Access_Object_Type (It.Typ);
697 Add_One_Interp (N, Acc_Type, Acc_Type);
698 Get_Next_Interp (Index, It);
703 -- Special cases when we can find a prefix that is an entity name
712 if Is_Entity_Name (PP) then
715 -- If we have an access to an object, and the attribute
716 -- comes from source, then set the object as potentially
717 -- source modified. We do this because the resulting access
718 -- pointer can be used to modify the variable, and we might
719 -- not detect this, leading to some junk warnings.
721 Set_Never_Set_In_Source (Ent, False);
723 -- Mark entity as address taken, and kill current values
725 Set_Address_Taken (Ent);
726 Kill_Current_Values (Ent);
729 elsif Nkind (PP) = N_Selected_Component
730 or else Nkind (PP) = N_Indexed_Component
740 -- Check for aliased view unless unrestricted case. We allow a
741 -- nonaliased prefix when within an instance because the prefix may
742 -- have been a tagged formal object, which is defined to be aliased
743 -- even when the actual might not be (other instance cases will have
744 -- been caught in the generic). Similarly, within an inlined body we
745 -- know that the attribute is legal in the original subprogram, and
746 -- therefore legal in the expansion.
748 if Aname /= Name_Unrestricted_Access
749 and then not Is_Aliased_View (P)
750 and then not In_Instance
751 and then not In_Inlined_Body
753 Error_Attr_P ("prefix of % attribute must be aliased");
755 end Analyze_Access_Attribute;
757 --------------------------------
758 -- Check_Array_Or_Scalar_Type --
759 --------------------------------
761 procedure Check_Array_Or_Scalar_Type is
765 -- Dimension number for array attributes
768 -- Case of string literal or string literal subtype. These cases
769 -- cannot arise from legal Ada code, but the expander is allowed
770 -- to generate them. They require special handling because string
771 -- literal subtypes do not have standard bounds (the whole idea
772 -- of these subtypes is to avoid having to generate the bounds)
774 if Ekind (P_Type) = E_String_Literal_Subtype then
775 Set_Etype (N, Etype (First_Index (P_Base_Type)));
780 elsif Is_Scalar_Type (P_Type) then
784 Error_Attr ("invalid argument in % attribute", E1);
786 Set_Etype (N, P_Base_Type);
790 -- The following is a special test to allow 'First to apply to
791 -- private scalar types if the attribute comes from generated
792 -- code. This occurs in the case of Normalize_Scalars code.
794 elsif Is_Private_Type
(P_Type
)
795 and then Present
(Full_View
(P_Type
))
796 and then Is_Scalar_Type
(Full_View
(P_Type
))
797 and then not Comes_From_Source
(N
)
799 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
801 -- Array types other than string literal subtypes handled above
806 -- We know prefix is an array type, or the name of an array
807 -- object, and that the expression, if present, is static
808 -- and within the range of the dimensions of the type.
810 pragma Assert
(Is_Array_Type
(P_Type
));
811 Index
:= First_Index
(P_Base_Type
);
815 -- First dimension assumed
817 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
820 D
:= UI_To_Int
(Intval
(E1
));
822 for J
in 1 .. D
- 1 loop
826 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
827 Set_Etype
(E1
, Standard_Integer
);
830 end Check_Array_Or_Scalar_Type
;
832 ----------------------
833 -- Check_Array_Type --
834 ----------------------
836 procedure Check_Array_Type
is
838 -- Dimension number for array attributes
841 -- If the type is a string literal type, then this must be generated
842 -- internally, and no further check is required on its legality.
844 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
847 -- If the type is a composite, it is an illegal aggregate, no point
850 elsif P_Type
= Any_Composite
then
854 -- Normal case of array type or subtype
856 Check_Either_E0_Or_E1
;
859 if Is_Array_Type
(P_Type
) then
860 if not Is_Constrained
(P_Type
)
861 and then Is_Entity_Name
(P
)
862 and then Is_Type
(Entity
(P
))
864 -- Note: we do not call Error_Attr here, since we prefer to
865 -- continue, using the relevant index type of the array,
866 -- even though it is unconstrained. This gives better error
867 -- recovery behavior.
869 Error_Msg_Name_1
:= Aname
;
871 ("prefix for % attribute must be constrained array", P
);
874 D
:= Number_Dimensions
(P_Type
);
877 if Is_Private_Type
(P_Type
) then
878 Error_Attr_P
("prefix for % attribute may not be private type");
880 elsif Is_Access_Type
(P_Type
)
881 and then Is_Array_Type
(Designated_Type
(P_Type
))
882 and then Is_Entity_Name
(P
)
883 and then Is_Type
(Entity
(P
))
885 Error_Attr_P
("prefix of % attribute cannot be access type");
887 elsif Attr_Id
= Attribute_First
889 Attr_Id
= Attribute_Last
891 Error_Attr
("invalid prefix for % attribute", P
);
894 Error_Attr_P
("prefix for % attribute must be array");
899 Resolve
(E1
, Any_Integer
);
900 Set_Etype
(E1
, Standard_Integer
);
902 if not Is_Static_Expression
(E1
)
903 or else Raises_Constraint_Error
(E1
)
906 ("expression for dimension must be static!", E1
);
909 elsif UI_To_Int
(Expr_Value
(E1
)) > D
910 or else UI_To_Int
(Expr_Value
(E1
)) < 1
912 Error_Attr
("invalid dimension number for array type", E1
);
916 if (Style_Check
and Style_Check_Array_Attribute_Index
)
917 and then Comes_From_Source
(N
)
919 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
921 end Check_Array_Type
;
923 -------------------------
924 -- Check_Asm_Attribute --
925 -------------------------
927 procedure Check_Asm_Attribute
is
932 -- Check first argument is static string expression
934 Analyze_And_Resolve
(E1
, Standard_String
);
936 if Etype
(E1
) = Any_Type
then
939 elsif not Is_OK_Static_Expression
(E1
) then
941 ("constraint argument must be static string expression!", E1
);
945 -- Check second argument is right type
947 Analyze_And_Resolve
(E2
, Entity
(P
));
949 -- Note: that is all we need to do, we don't need to check
950 -- that it appears in a correct context. The Ada type system
951 -- will do that for us.
953 end Check_Asm_Attribute
;
955 ---------------------
956 -- Check_Component --
957 ---------------------
959 procedure Check_Component
is
963 if Nkind
(P
) /= N_Selected_Component
965 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
967 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
969 Error_Attr_P
("prefix for % attribute must be selected component");
973 ------------------------------------
974 -- Check_Decimal_Fixed_Point_Type --
975 ------------------------------------
977 procedure Check_Decimal_Fixed_Point_Type
is
981 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
982 Error_Attr_P
("prefix of % attribute must be decimal type");
984 end Check_Decimal_Fixed_Point_Type
;
986 -----------------------
987 -- Check_Dereference --
988 -----------------------
990 procedure Check_Dereference
is
993 -- Case of a subtype mark
995 if Is_Entity_Name
(P
)
996 and then Is_Type
(Entity
(P
))
1001 -- Case of an expression
1005 if Is_Access_Type
(P_Type
) then
1007 -- If there is an implicit dereference, then we must freeze
1008 -- the designated type of the access type, since the type of
1009 -- the referenced array is this type (see AI95-00106).
1011 Freeze_Before
(N
, Designated_Type
(P_Type
));
1014 Make_Explicit_Dereference
(Sloc
(P
),
1015 Prefix
=> Relocate_Node
(P
)));
1017 Analyze_And_Resolve
(P
);
1018 P_Type
:= Etype
(P
);
1020 if P_Type
= Any_Type
then
1021 raise Bad_Attribute
;
1024 P_Base_Type
:= Base_Type
(P_Type
);
1026 end Check_Dereference
;
1028 -------------------------
1029 -- Check_Discrete_Type --
1030 -------------------------
1032 procedure Check_Discrete_Type
is
1036 if not Is_Discrete_Type
(P_Type
) then
1037 Error_Attr_P
("prefix of % attribute must be discrete type");
1039 end Check_Discrete_Type
;
1045 procedure Check_E0
is
1047 if Present
(E1
) then
1048 Unexpected_Argument
(E1
);
1056 procedure Check_E1
is
1058 Check_Either_E0_Or_E1
;
1062 -- Special-case attributes that are functions and that appear as
1063 -- the prefix of another attribute. Error is posted on parent.
1065 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1066 and then (Attribute_Name
(Parent
(N
)) = Name_Address
1068 Attribute_Name
(Parent
(N
)) = Name_Code_Address
1070 Attribute_Name
(Parent
(N
)) = Name_Access
)
1072 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1073 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1074 Set_Etype
(Parent
(N
), Any_Type
);
1075 Set_Entity
(Parent
(N
), Any_Type
);
1076 raise Bad_Attribute
;
1079 Error_Attr
("missing argument for % attribute", N
);
1088 procedure Check_E2
is
1091 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1093 Error_Attr
("missing argument for % attribute (2 required)", N
);
1097 ---------------------------
1098 -- Check_Either_E0_Or_E1 --
1099 ---------------------------
1101 procedure Check_Either_E0_Or_E1
is
1103 if Present
(E2
) then
1104 Unexpected_Argument
(E2
);
1106 end Check_Either_E0_Or_E1
;
1108 ----------------------
1109 -- Check_Enum_Image --
1110 ----------------------
1112 procedure Check_Enum_Image
is
1115 if Is_Enumeration_Type
(P_Base_Type
) then
1116 Lit
:= First_Literal
(P_Base_Type
);
1117 while Present
(Lit
) loop
1118 Set_Referenced
(Lit
);
1122 end Check_Enum_Image
;
1124 ----------------------------
1125 -- Check_Fixed_Point_Type --
1126 ----------------------------
1128 procedure Check_Fixed_Point_Type
is
1132 if not Is_Fixed_Point_Type
(P_Type
) then
1133 Error_Attr_P
("prefix of % attribute must be fixed point type");
1135 end Check_Fixed_Point_Type
;
1137 ------------------------------
1138 -- Check_Fixed_Point_Type_0 --
1139 ------------------------------
1141 procedure Check_Fixed_Point_Type_0
is
1143 Check_Fixed_Point_Type
;
1145 end Check_Fixed_Point_Type_0
;
1147 -------------------------------
1148 -- Check_Floating_Point_Type --
1149 -------------------------------
1151 procedure Check_Floating_Point_Type
is
1155 if not Is_Floating_Point_Type
(P_Type
) then
1156 Error_Attr_P
("prefix of % attribute must be float type");
1158 end Check_Floating_Point_Type
;
1160 ---------------------------------
1161 -- Check_Floating_Point_Type_0 --
1162 ---------------------------------
1164 procedure Check_Floating_Point_Type_0
is
1166 Check_Floating_Point_Type
;
1168 end Check_Floating_Point_Type_0
;
1170 ---------------------------------
1171 -- Check_Floating_Point_Type_1 --
1172 ---------------------------------
1174 procedure Check_Floating_Point_Type_1
is
1176 Check_Floating_Point_Type
;
1178 end Check_Floating_Point_Type_1
;
1180 ---------------------------------
1181 -- Check_Floating_Point_Type_2 --
1182 ---------------------------------
1184 procedure Check_Floating_Point_Type_2
is
1186 Check_Floating_Point_Type
;
1188 end Check_Floating_Point_Type_2
;
1190 ------------------------
1191 -- Check_Integer_Type --
1192 ------------------------
1194 procedure Check_Integer_Type
is
1198 if not Is_Integer_Type
(P_Type
) then
1199 Error_Attr_P
("prefix of % attribute must be integer type");
1201 end Check_Integer_Type
;
1203 ------------------------
1204 -- Check_Library_Unit --
1205 ------------------------
1207 procedure Check_Library_Unit
is
1209 if not Is_Compilation_Unit
(Entity
(P
)) then
1210 Error_Attr_P
("prefix of % attribute must be library unit");
1212 end Check_Library_Unit
;
1214 --------------------------------
1215 -- Check_Modular_Integer_Type --
1216 --------------------------------
1218 procedure Check_Modular_Integer_Type
is
1222 if not Is_Modular_Integer_Type
(P_Type
) then
1224 ("prefix of % attribute must be modular integer type");
1226 end Check_Modular_Integer_Type
;
1228 -------------------------------
1229 -- Check_Not_Incomplete_Type --
1230 -------------------------------
1232 procedure Check_Not_Incomplete_Type
is
1237 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1238 -- dereference we have to check wrong uses of incomplete types
1239 -- (other wrong uses are checked at their freezing point).
1241 -- Example 1: Limited-with
1243 -- limited with Pkg;
1245 -- type Acc is access Pkg.T;
1247 -- S : Integer := X.all'Size; -- ERROR
1250 -- Example 2: Tagged incomplete
1252 -- type T is tagged;
1253 -- type Acc is access all T;
1255 -- S : constant Integer := X.all'Size; -- ERROR
1256 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1258 if Ada_Version
>= Ada_05
1259 and then Nkind
(P
) = N_Explicit_Dereference
1262 while Nkind
(E
) = N_Explicit_Dereference
loop
1266 if From_With_Type
(Etype
(E
)) then
1268 ("prefix of % attribute cannot be an incomplete type");
1271 if Is_Access_Type
(Etype
(E
)) then
1272 Typ
:= Directly_Designated_Type
(Etype
(E
));
1277 if Ekind
(Typ
) = E_Incomplete_Type
1278 and then No
(Full_View
(Typ
))
1281 ("prefix of % attribute cannot be an incomplete type");
1286 if not Is_Entity_Name
(P
)
1287 or else not Is_Type
(Entity
(P
))
1288 or else In_Default_Expression
1292 Check_Fully_Declared
(P_Type
, P
);
1294 end Check_Not_Incomplete_Type
;
1296 ----------------------------
1297 -- Check_Object_Reference --
1298 ----------------------------
1300 procedure Check_Object_Reference
(P
: Node_Id
) is
1304 -- If we need an object, and we have a prefix that is the name of
1305 -- a function entity, convert it into a function call.
1307 if Is_Entity_Name
(P
)
1308 and then Ekind
(Entity
(P
)) = E_Function
1310 Rtyp
:= Etype
(Entity
(P
));
1313 Make_Function_Call
(Sloc
(P
),
1314 Name
=> Relocate_Node
(P
)));
1316 Analyze_And_Resolve
(P
, Rtyp
);
1318 -- Otherwise we must have an object reference
1320 elsif not Is_Object_Reference
(P
) then
1321 Error_Attr_P
("prefix of % attribute must be object");
1323 end Check_Object_Reference
;
1325 ------------------------
1326 -- Check_Program_Unit --
1327 ------------------------
1329 procedure Check_Program_Unit
is
1331 if Is_Entity_Name
(P
) then
1333 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1334 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1337 if K
in Subprogram_Kind
1338 or else K
in Task_Kind
1339 or else K
in Protected_Kind
1340 or else K
= E_Package
1341 or else K
in Generic_Unit_Kind
1342 or else (K
= E_Variable
1346 Is_Protected_Type
(T
)))
1353 Error_Attr_P
("prefix of % attribute must be program unit");
1354 end Check_Program_Unit
;
1356 ---------------------
1357 -- Check_Real_Type --
1358 ---------------------
1360 procedure Check_Real_Type
is
1364 if not Is_Real_Type
(P_Type
) then
1365 Error_Attr_P
("prefix of % attribute must be real type");
1367 end Check_Real_Type
;
1369 -----------------------
1370 -- Check_Scalar_Type --
1371 -----------------------
1373 procedure Check_Scalar_Type
is
1377 if not Is_Scalar_Type
(P_Type
) then
1378 Error_Attr_P
("prefix of % attribute must be scalar type");
1380 end Check_Scalar_Type
;
1382 ---------------------------
1383 -- Check_Standard_Prefix --
1384 ---------------------------
1386 procedure Check_Standard_Prefix
is
1390 if Nkind
(P
) /= N_Identifier
1391 or else Chars
(P
) /= Name_Standard
1393 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1395 end Check_Standard_Prefix
;
1397 ----------------------------
1398 -- Check_Stream_Attribute --
1399 ----------------------------
1401 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1406 Validate_Non_Static_Attribute_Function_Call
;
1408 -- With the exception of 'Input, Stream attributes are procedures,
1409 -- and can only appear at the position of procedure calls. We check
1410 -- for this here, before they are rewritten, to give a more precise
1413 if Nam
= TSS_Stream_Input
then
1416 elsif Is_List_Member
(N
)
1417 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1418 and then Nkind
(Parent
(N
)) /= N_Aggregate
1424 ("invalid context for attribute%, which is a procedure", N
);
1428 Btyp
:= Implementation_Base_Type
(P_Type
);
1430 -- Stream attributes not allowed on limited types unless the
1431 -- attribute reference was generated by the expander (in which
1432 -- case the underlying type will be used, as described in Sinfo),
1433 -- or the attribute was specified explicitly for the type itself
1434 -- or one of its ancestors (taking visibility rules into account if
1435 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1436 -- (with no visibility restriction).
1438 if Comes_From_Source
(N
)
1439 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1440 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1442 Error_Msg_Name_1
:= Aname
;
1444 if Is_Limited_Type
(P_Type
) then
1446 ("limited type& has no% attribute", P
, P_Type
);
1447 Explain_Limited_Type
(P_Type
, P
);
1450 ("attribute% for type& is not available", P
, P_Type
);
1454 -- Check for violation of restriction No_Stream_Attributes
1456 if Is_RTE
(P_Type
, RE_Exception_Id
)
1458 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1460 Check_Restriction
(No_Exception_Registration
, P
);
1463 -- Here we must check that the first argument is an access type
1464 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1466 Analyze_And_Resolve
(E1
);
1469 -- Note: the double call to Root_Type here is needed because the
1470 -- root type of a class-wide type is the corresponding type (e.g.
1471 -- X for X'Class, and we really want to go to the root.)
1473 if not Is_Access_Type
(Etyp
)
1474 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1475 RTE
(RE_Root_Stream_Type
)
1478 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1481 -- Check that the second argument is of the right type if there is
1482 -- one (the Input attribute has only one argument so this is skipped)
1484 if Present
(E2
) then
1487 if Nam
= TSS_Stream_Read
1488 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1491 ("second argument of % attribute must be a variable", E2
);
1494 Resolve
(E2
, P_Type
);
1496 end Check_Stream_Attribute
;
1498 -----------------------
1499 -- Check_Task_Prefix --
1500 -----------------------
1502 procedure Check_Task_Prefix
is
1506 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1507 -- task interface class-wide types.
1509 if Is_Task_Type
(Etype
(P
))
1510 or else (Is_Access_Type
(Etype
(P
))
1511 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1512 or else (Ada_Version
>= Ada_05
1513 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1514 and then Is_Interface
(Etype
(P
))
1515 and then Is_Task_Interface
(Etype
(P
)))
1520 if Ada_Version
>= Ada_05
then
1522 ("prefix of % attribute must be a task or a task " &
1523 "interface class-wide object");
1526 Error_Attr_P
("prefix of % attribute must be a task");
1529 end Check_Task_Prefix
;
1535 -- The possibilities are an entity name denoting a type, or an
1536 -- attribute reference that denotes a type (Base or Class). If
1537 -- the type is incomplete, replace it with its full view.
1539 procedure Check_Type
is
1541 if not Is_Entity_Name
(P
)
1542 or else not Is_Type
(Entity
(P
))
1544 Error_Attr_P
("prefix of % attribute must be a type");
1546 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1547 and then Present
(Full_View
(Entity
(P
)))
1549 P_Type
:= Full_View
(Entity
(P
));
1550 Set_Entity
(P
, P_Type
);
1554 ---------------------
1555 -- Check_Unit_Name --
1556 ---------------------
1558 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1560 if Nkind
(Nod
) = N_Identifier
then
1563 elsif Nkind
(Nod
) = N_Selected_Component
then
1564 Check_Unit_Name
(Prefix
(Nod
));
1566 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1571 Error_Attr
("argument for % attribute must be unit name", P
);
1572 end Check_Unit_Name
;
1578 procedure Error_Attr
is
1580 Set_Etype
(N
, Any_Type
);
1581 Set_Entity
(N
, Any_Type
);
1582 raise Bad_Attribute
;
1585 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1587 Error_Msg_Name_1
:= Aname
;
1588 Error_Msg_N
(Msg
, Error_Node
);
1596 procedure Error_Attr_P
(Msg
: String) is
1598 Error_Msg_Name_1
:= Aname
;
1599 Error_Msg_F
(Msg
, P
);
1603 ----------------------------
1604 -- Legal_Formal_Attribute --
1605 ----------------------------
1607 procedure Legal_Formal_Attribute
is
1611 if not Is_Entity_Name
(P
)
1612 or else not Is_Type
(Entity
(P
))
1614 Error_Attr_P
("prefix of % attribute must be generic type");
1616 elsif Is_Generic_Actual_Type
(Entity
(P
))
1618 or else In_Inlined_Body
1622 elsif Is_Generic_Type
(Entity
(P
)) then
1623 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1625 ("prefix of % attribute must be indefinite generic type");
1630 ("prefix of % attribute must be indefinite generic type");
1633 Set_Etype
(N
, Standard_Boolean
);
1634 end Legal_Formal_Attribute
;
1636 ------------------------
1637 -- Standard_Attribute --
1638 ------------------------
1640 procedure Standard_Attribute
(Val
: Int
) is
1642 Check_Standard_Prefix
;
1643 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1645 end Standard_Attribute
;
1647 -------------------------
1648 -- Unexpected Argument --
1649 -------------------------
1651 procedure Unexpected_Argument
(En
: Node_Id
) is
1653 Error_Attr
("unexpected argument for % attribute", En
);
1654 end Unexpected_Argument
;
1656 -------------------------------------------------
1657 -- Validate_Non_Static_Attribute_Function_Call --
1658 -------------------------------------------------
1660 -- This function should be moved to Sem_Dist ???
1662 procedure Validate_Non_Static_Attribute_Function_Call
is
1664 if In_Preelaborated_Unit
1665 and then not In_Subprogram_Or_Concurrent_Unit
1667 Flag_Non_Static_Expr
1668 ("non-static function call in preelaborated unit!", N
);
1670 end Validate_Non_Static_Attribute_Function_Call
;
1672 -----------------------------------------------
1673 -- Start of Processing for Analyze_Attribute --
1674 -----------------------------------------------
1677 -- Immediate return if unrecognized attribute (already diagnosed
1678 -- by parser, so there is nothing more that we need to do)
1680 if not Is_Attribute_Name
(Aname
) then
1681 raise Bad_Attribute
;
1684 -- Deal with Ada 83 issues
1686 if Comes_From_Source
(N
) then
1687 if not Attribute_83
(Attr_Id
) then
1688 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1689 Error_Msg_Name_1
:= Aname
;
1690 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1693 if Attribute_Impl_Def
(Attr_Id
) then
1694 Check_Restriction
(No_Implementation_Attributes
, N
);
1699 -- Deal with Ada 2005 issues
1701 if Attribute_05
(Attr_Id
) and then Ada_Version
<= Ada_95
then
1702 Check_Restriction
(No_Implementation_Attributes
, N
);
1705 -- Remote access to subprogram type access attribute reference needs
1706 -- unanalyzed copy for tree transformation. The analyzed copy is used
1707 -- for its semantic information (whether prefix is a remote subprogram
1708 -- name), the unanalyzed copy is used to construct new subtree rooted
1709 -- with N_Aggregate which represents a fat pointer aggregate.
1711 if Aname
= Name_Access
then
1712 Discard_Node
(Copy_Separate_Tree
(N
));
1715 -- Analyze prefix and exit if error in analysis. If the prefix is an
1716 -- incomplete type, use full view if available. Note that there are
1717 -- some attributes for which we do not analyze the prefix, since the
1718 -- prefix is not a normal name.
1720 if Aname
/= Name_Elab_Body
1722 Aname
/= Name_Elab_Spec
1724 Aname
/= Name_UET_Address
1726 Aname
/= Name_Enabled
1729 P_Type
:= Etype
(P
);
1731 if Is_Entity_Name
(P
)
1732 and then Present
(Entity
(P
))
1733 and then Is_Type
(Entity
(P
))
1735 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
1736 P_Type
:= Get_Full_View
(P_Type
);
1737 Set_Entity
(P
, P_Type
);
1738 Set_Etype
(P
, P_Type
);
1740 elsif Entity
(P
) = Current_Scope
1741 and then Is_Record_Type
(Entity
(P
))
1743 -- Use of current instance within the type. Verify that if the
1744 -- attribute appears within a constraint, it yields an access
1745 -- type, other uses are illegal.
1753 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
1755 Par
:= Parent
(Par
);
1759 and then Nkind
(Par
) = N_Subtype_Indication
1761 if Attr_Id
/= Attribute_Access
1762 and then Attr_Id
/= Attribute_Unchecked_Access
1763 and then Attr_Id
/= Attribute_Unrestricted_Access
1766 ("in a constraint the current instance can only"
1767 & " be used with an access attribute", N
);
1774 if P_Type
= Any_Type
then
1775 raise Bad_Attribute
;
1778 P_Base_Type
:= Base_Type
(P_Type
);
1781 -- Analyze expressions that may be present, exiting if an error occurs
1788 E1
:= First
(Exprs
);
1791 -- Check for missing/bad expression (result of previous error)
1793 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1794 raise Bad_Attribute
;
1799 if Present
(E2
) then
1802 if Etype
(E2
) = Any_Type
then
1803 raise Bad_Attribute
;
1806 if Present
(Next
(E2
)) then
1807 Unexpected_Argument
(Next
(E2
));
1812 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1813 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
1815 if Ada_Version
< Ada_05
1816 and then Is_Overloaded
(P
)
1817 and then Aname
/= Name_Access
1818 and then Aname
/= Name_Address
1819 and then Aname
/= Name_Code_Address
1820 and then Aname
/= Name_Count
1821 and then Aname
/= Name_Unchecked_Access
1823 Error_Attr
("ambiguous prefix for % attribute", P
);
1825 elsif Ada_Version
>= Ada_05
1826 and then Is_Overloaded
(P
)
1827 and then Aname
/= Name_Access
1828 and then Aname
/= Name_Address
1829 and then Aname
/= Name_Code_Address
1830 and then Aname
/= Name_Unchecked_Access
1832 -- Ada 2005 (AI-345): Since protected and task types have primitive
1833 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1836 if Aname
= Name_Count
1837 or else Aname
= Name_Caller
1838 or else Aname
= Name_AST_Entry
1841 Count
: Natural := 0;
1846 Get_First_Interp
(P
, I
, It
);
1847 while Present
(It
.Nam
) loop
1848 if Comes_From_Source
(It
.Nam
) then
1854 Get_Next_Interp
(I
, It
);
1858 Error_Attr
("ambiguous prefix for % attribute", P
);
1860 Set_Is_Overloaded
(P
, False);
1865 Error_Attr
("ambiguous prefix for % attribute", P
);
1869 -- Remaining processing depends on attribute
1877 when Attribute_Abort_Signal
=>
1878 Check_Standard_Prefix
;
1880 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1887 when Attribute_Access
=>
1888 Analyze_Access_Attribute
;
1894 when Attribute_Address
=>
1897 -- Check for some junk cases, where we have to allow the address
1898 -- attribute but it does not make much sense, so at least for now
1899 -- just replace with Null_Address.
1901 -- We also do this if the prefix is a reference to the AST_Entry
1902 -- attribute. If expansion is active, the attribute will be
1903 -- replaced by a function call, and address will work fine and
1904 -- get the proper value, but if expansion is not active, then
1905 -- the check here allows proper semantic analysis of the reference.
1907 -- An Address attribute created by expansion is legal even when it
1908 -- applies to other entity-denoting expressions.
1910 if Is_Entity_Name
(P
) then
1912 Ent
: constant Entity_Id
:= Entity
(P
);
1915 if Is_Subprogram
(Ent
) then
1916 Set_Address_Taken
(Ent
);
1917 Kill_Current_Values
(Ent
);
1919 -- An Address attribute is accepted when generated by the
1920 -- compiler for dispatching operation, and an error is
1921 -- issued once the subprogram is frozen (to avoid confusing
1922 -- errors about implicit uses of Address in the dispatch
1923 -- table initialization).
1925 if Has_Pragma_Inline_Always
(Entity
(P
))
1926 and then Comes_From_Source
(P
)
1929 ("prefix of % attribute cannot be Inline_Always" &
1933 elsif Is_Object
(Ent
)
1934 or else Ekind
(Ent
) = E_Label
1936 Set_Address_Taken
(Ent
);
1938 -- If we have an address of an object, and the attribute
1939 -- comes from source, then set the object as potentially
1940 -- source modified. We do this because the resulting address
1941 -- can potentially be used to modify the variable and we
1942 -- might not detect this, leading to some junk warnings.
1944 Set_Never_Set_In_Source
(Ent
, False);
1946 elsif (Is_Concurrent_Type
(Etype
(Ent
))
1947 and then Etype
(Ent
) = Base_Type
(Ent
))
1948 or else Ekind
(Ent
) = E_Package
1949 or else Is_Generic_Unit
(Ent
)
1952 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1955 Error_Attr
("invalid prefix for % attribute", P
);
1959 elsif Nkind
(P
) = N_Attribute_Reference
1960 and then Attribute_Name
(P
) = Name_AST_Entry
1963 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1965 elsif Is_Object_Reference
(P
) then
1968 elsif Nkind
(P
) = N_Selected_Component
1969 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1973 -- What exactly are we allowing here ??? and is this properly
1974 -- documented in the sinfo documentation for this node ???
1976 elsif not Comes_From_Source
(N
) then
1980 Error_Attr
("invalid prefix for % attribute", P
);
1983 Set_Etype
(N
, RTE
(RE_Address
));
1989 when Attribute_Address_Size
=>
1990 Standard_Attribute
(System_Address_Size
);
1996 when Attribute_Adjacent
=>
1997 Check_Floating_Point_Type_2
;
1998 Set_Etype
(N
, P_Base_Type
);
1999 Resolve
(E1
, P_Base_Type
);
2000 Resolve
(E2
, P_Base_Type
);
2006 when Attribute_Aft
=>
2007 Check_Fixed_Point_Type_0
;
2008 Set_Etype
(N
, Universal_Integer
);
2014 when Attribute_Alignment
=>
2016 -- Don't we need more checking here, cf Size ???
2019 Check_Not_Incomplete_Type
;
2020 Set_Etype
(N
, Universal_Integer
);
2026 when Attribute_Asm_Input
=>
2027 Check_Asm_Attribute
;
2028 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2034 when Attribute_Asm_Output
=>
2035 Check_Asm_Attribute
;
2037 if Etype
(E2
) = Any_Type
then
2040 elsif Aname
= Name_Asm_Output
then
2041 if not Is_Variable
(E2
) then
2043 ("second argument for Asm_Output is not variable", E2
);
2047 Note_Possible_Modification
(E2
);
2048 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2054 when Attribute_AST_Entry
=> AST_Entry
: declare
2060 -- Indicates if entry family index is present. Note the coding
2061 -- here handles the entry family case, but in fact it cannot be
2062 -- executed currently, because pragma AST_Entry does not permit
2063 -- the specification of an entry family.
2065 procedure Bad_AST_Entry
;
2066 -- Signal a bad AST_Entry pragma
2068 function OK_Entry
(E
: Entity_Id
) return Boolean;
2069 -- Checks that E is of an appropriate entity kind for an entry
2070 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2071 -- is set True for the entry family case). In the True case,
2072 -- makes sure that Is_AST_Entry is set on the entry.
2074 procedure Bad_AST_Entry
is
2076 Error_Attr_P
("prefix for % attribute must be task entry");
2079 function OK_Entry
(E
: Entity_Id
) return Boolean is
2084 Result
:= (Ekind
(E
) = E_Entry_Family
);
2086 Result
:= (Ekind
(E
) = E_Entry
);
2090 if not Is_AST_Entry
(E
) then
2091 Error_Msg_Name_2
:= Aname
;
2092 Error_Attr
("% attribute requires previous % pragma", P
);
2099 -- Start of processing for AST_Entry
2105 -- Deal with entry family case
2107 if Nkind
(P
) = N_Indexed_Component
then
2115 Ptyp
:= Etype
(Pref
);
2117 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2121 -- If the prefix is a selected component whose prefix is of an
2122 -- access type, then introduce an explicit dereference.
2123 -- ??? Could we reuse Check_Dereference here?
2125 if Nkind
(Pref
) = N_Selected_Component
2126 and then Is_Access_Type
(Ptyp
)
2129 Make_Explicit_Dereference
(Sloc
(Pref
),
2130 Relocate_Node
(Pref
)));
2131 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2134 -- Prefix can be of the form a.b, where a is a task object
2135 -- and b is one of the entries of the corresponding task type.
2137 if Nkind
(Pref
) = N_Selected_Component
2138 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2139 and then Is_Object_Reference
(Prefix
(Pref
))
2140 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2144 -- Otherwise the prefix must be an entry of a containing task,
2145 -- or of a variable of the enclosing task type.
2148 if Nkind
(Pref
) = N_Identifier
2149 or else Nkind
(Pref
) = N_Expanded_Name
2151 Ent
:= Entity
(Pref
);
2153 if not OK_Entry
(Ent
)
2154 or else not In_Open_Scopes
(Scope
(Ent
))
2164 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2171 -- Note: when the base attribute appears in the context of a subtype
2172 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2173 -- the following circuit.
2175 when Attribute_Base
=> Base
: declare
2183 if Ada_Version
>= Ada_95
2184 and then not Is_Scalar_Type
(Typ
)
2185 and then not Is_Generic_Type
(Typ
)
2187 Error_Attr_P
("prefix of Base attribute must be scalar type");
2189 elsif Sloc
(Typ
) = Standard_Location
2190 and then Base_Type
(Typ
) = Typ
2191 and then Warn_On_Redundant_Constructs
2194 ("?redudant attribute, & is its own base type", N
, Typ
);
2197 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2198 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2199 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2207 when Attribute_Bit
=> Bit
:
2211 if not Is_Object_Reference
(P
) then
2212 Error_Attr_P
("prefix for % attribute must be object");
2214 -- What about the access object cases ???
2220 Set_Etype
(N
, Universal_Integer
);
2227 when Attribute_Bit_Order
=> Bit_Order
:
2232 if not Is_Record_Type
(P_Type
) then
2233 Error_Attr_P
("prefix of % attribute must be record type");
2236 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2238 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2241 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2244 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2247 -- Reset incorrect indication of staticness
2249 Set_Is_Static_Expression
(N
, False);
2256 -- Note: in generated code, we can have a Bit_Position attribute
2257 -- applied to a (naked) record component (i.e. the prefix is an
2258 -- identifier that references an E_Component or E_Discriminant
2259 -- entity directly, and this is interpreted as expected by Gigi.
2260 -- The following code will not tolerate such usage, but when the
2261 -- expander creates this special case, it marks it as analyzed
2262 -- immediately and sets an appropriate type.
2264 when Attribute_Bit_Position
=>
2265 if Comes_From_Source
(N
) then
2269 Set_Etype
(N
, Universal_Integer
);
2275 when Attribute_Body_Version
=>
2278 Set_Etype
(N
, RTE
(RE_Version_String
));
2284 when Attribute_Callable
=>
2286 Set_Etype
(N
, Standard_Boolean
);
2293 when Attribute_Caller
=> Caller
: declare
2300 if Nkind
(P
) = N_Identifier
2301 or else Nkind
(P
) = N_Expanded_Name
2305 if not Is_Entry
(Ent
) then
2306 Error_Attr
("invalid entry name", N
);
2310 Error_Attr
("invalid entry name", N
);
2314 for J
in reverse 0 .. Scope_Stack
.Last
loop
2315 S
:= Scope_Stack
.Table
(J
).Entity
;
2317 if S
= Scope
(Ent
) then
2318 Error_Attr
("Caller must appear in matching accept or body", N
);
2324 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2331 when Attribute_Ceiling
=>
2332 Check_Floating_Point_Type_1
;
2333 Set_Etype
(N
, P_Base_Type
);
2334 Resolve
(E1
, P_Base_Type
);
2340 when Attribute_Class
=>
2341 Check_Restriction
(No_Dispatch
, N
);
2349 when Attribute_Code_Address
=>
2352 if Nkind
(P
) = N_Attribute_Reference
2353 and then (Attribute_Name
(P
) = Name_Elab_Body
2355 Attribute_Name
(P
) = Name_Elab_Spec
)
2359 elsif not Is_Entity_Name
(P
)
2360 or else (Ekind
(Entity
(P
)) /= E_Function
2362 Ekind
(Entity
(P
)) /= E_Procedure
)
2364 Error_Attr
("invalid prefix for % attribute", P
);
2365 Set_Address_Taken
(Entity
(P
));
2368 Set_Etype
(N
, RTE
(RE_Address
));
2370 --------------------
2371 -- Component_Size --
2372 --------------------
2374 when Attribute_Component_Size
=>
2376 Set_Etype
(N
, Universal_Integer
);
2378 -- Note: unlike other array attributes, unconstrained arrays are OK
2380 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2390 when Attribute_Compose
=>
2391 Check_Floating_Point_Type_2
;
2392 Set_Etype
(N
, P_Base_Type
);
2393 Resolve
(E1
, P_Base_Type
);
2394 Resolve
(E2
, Any_Integer
);
2400 when Attribute_Constrained
=>
2402 Set_Etype
(N
, Standard_Boolean
);
2404 -- Case from RM J.4(2) of constrained applied to private type
2406 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2407 Check_Restriction
(No_Obsolescent_Features
, N
);
2409 if Warn_On_Obsolescent_Feature
then
2411 ("constrained for private type is an " &
2412 "obsolescent feature (RM J.4)?", N
);
2415 -- If we are within an instance, the attribute must be legal
2416 -- because it was valid in the generic unit. Ditto if this is
2417 -- an inlining of a function declared in an instance.
2420 or else In_Inlined_Body
2424 -- For sure OK if we have a real private type itself, but must
2425 -- be completed, cannot apply Constrained to incomplete type.
2427 elsif Is_Private_Type
(Entity
(P
)) then
2429 -- Note: this is one of the Annex J features that does not
2430 -- generate a warning from -gnatwj, since in fact it seems
2431 -- very useful, and is used in the GNAT runtime.
2433 Check_Not_Incomplete_Type
;
2437 -- Normal (non-obsolescent case) of application to object of
2438 -- a discriminated type.
2441 Check_Object_Reference
(P
);
2443 -- If N does not come from source, then we allow the
2444 -- the attribute prefix to be of a private type whose
2445 -- full type has discriminants. This occurs in cases
2446 -- involving expanded calls to stream attributes.
2448 if not Comes_From_Source
(N
) then
2449 P_Type
:= Underlying_Type
(P_Type
);
2452 -- Must have discriminants or be an access type designating
2453 -- a type with discriminants. If it is a classwide type is ???
2454 -- has unknown discriminants.
2456 if Has_Discriminants
(P_Type
)
2457 or else Has_Unknown_Discriminants
(P_Type
)
2459 (Is_Access_Type
(P_Type
)
2460 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2464 -- Also allow an object of a generic type if extensions allowed
2465 -- and allow this for any type at all.
2467 elsif (Is_Generic_Type
(P_Type
)
2468 or else Is_Generic_Actual_Type
(P_Type
))
2469 and then Extensions_Allowed
2475 -- Fall through if bad prefix
2478 ("prefix of % attribute must be object of discriminated type");
2484 when Attribute_Copy_Sign
=>
2485 Check_Floating_Point_Type_2
;
2486 Set_Etype
(N
, P_Base_Type
);
2487 Resolve
(E1
, P_Base_Type
);
2488 Resolve
(E2
, P_Base_Type
);
2494 when Attribute_Count
=> Count
:
2503 if Nkind
(P
) = N_Identifier
2504 or else Nkind
(P
) = N_Expanded_Name
2508 if Ekind
(Ent
) /= E_Entry
then
2509 Error_Attr
("invalid entry name", N
);
2512 elsif Nkind
(P
) = N_Indexed_Component
then
2513 if not Is_Entity_Name
(Prefix
(P
))
2514 or else No
(Entity
(Prefix
(P
)))
2515 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2517 if Nkind
(Prefix
(P
)) = N_Selected_Component
2518 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2519 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2523 ("attribute % must apply to entry of current task", P
);
2526 Error_Attr
("invalid entry family name", P
);
2531 Ent
:= Entity
(Prefix
(P
));
2534 elsif Nkind
(P
) = N_Selected_Component
2535 and then Present
(Entity
(Selector_Name
(P
)))
2536 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2539 ("attribute % must apply to entry of current task", P
);
2542 Error_Attr
("invalid entry name", N
);
2546 for J
in reverse 0 .. Scope_Stack
.Last
loop
2547 S
:= Scope_Stack
.Table
(J
).Entity
;
2549 if S
= Scope
(Ent
) then
2550 if Nkind
(P
) = N_Expanded_Name
then
2551 Tsk
:= Entity
(Prefix
(P
));
2553 -- The prefix denotes either the task type, or else a
2554 -- single task whose task type is being analyzed.
2559 or else (not Is_Type
(Tsk
)
2560 and then Etype
(Tsk
) = S
2561 and then not (Comes_From_Source
(S
)))
2566 ("Attribute % must apply to entry of current task", N
);
2572 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2573 and then Ekind
(S
) /= E_Loop
2574 and then Ekind
(S
) /= E_Block
2575 and then Ekind
(S
) /= E_Entry
2576 and then Ekind
(S
) /= E_Entry_Family
2578 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2580 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2581 and then not Has_Completion
(Scope
(Ent
))
2583 Error_Attr
("attribute % can only be used inside body", N
);
2587 if Is_Overloaded
(P
) then
2589 Index
: Interp_Index
;
2593 Get_First_Interp
(P
, Index
, It
);
2595 while Present
(It
.Nam
) loop
2596 if It
.Nam
= Ent
then
2599 -- Ada 2005 (AI-345): Do not consider primitive entry
2600 -- wrappers generated for task or protected types.
2602 elsif Ada_Version
>= Ada_05
2603 and then not Comes_From_Source
(It
.Nam
)
2608 Error_Attr
("ambiguous entry name", N
);
2611 Get_Next_Interp
(Index
, It
);
2616 Set_Etype
(N
, Universal_Integer
);
2619 -----------------------
2620 -- Default_Bit_Order --
2621 -----------------------
2623 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2625 Check_Standard_Prefix
;
2628 if Bytes_Big_Endian
then
2630 Make_Integer_Literal
(Loc
, False_Value
));
2633 Make_Integer_Literal
(Loc
, True_Value
));
2636 Set_Etype
(N
, Universal_Integer
);
2637 Set_Is_Static_Expression
(N
);
2638 end Default_Bit_Order
;
2644 when Attribute_Definite
=>
2645 Legal_Formal_Attribute
;
2651 when Attribute_Delta
=>
2652 Check_Fixed_Point_Type_0
;
2653 Set_Etype
(N
, Universal_Real
);
2659 when Attribute_Denorm
=>
2660 Check_Floating_Point_Type_0
;
2661 Set_Etype
(N
, Standard_Boolean
);
2667 when Attribute_Digits
=>
2671 if not Is_Floating_Point_Type
(P_Type
)
2672 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2675 ("prefix of % attribute must be float or decimal type");
2678 Set_Etype
(N
, Universal_Integer
);
2684 -- Also handles processing for Elab_Spec
2686 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2688 Check_Unit_Name
(P
);
2689 Set_Etype
(N
, Standard_Void_Type
);
2691 -- We have to manually call the expander in this case to get
2692 -- the necessary expansion (normally attributes that return
2693 -- entities are not expanded).
2701 -- Shares processing with Elab_Body
2707 when Attribute_Elaborated
=>
2710 Set_Etype
(N
, Standard_Boolean
);
2716 when Attribute_Emax
=>
2717 Check_Floating_Point_Type_0
;
2718 Set_Etype
(N
, Universal_Integer
);
2724 when Attribute_Enabled
=>
2725 Check_Either_E0_Or_E1
;
2727 if Present
(E1
) then
2728 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
2729 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
2734 if Nkind
(P
) /= N_Identifier
then
2735 Error_Msg_N
("identifier expected (check name)", P
);
2737 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
2738 Error_Msg_N
("& is not a recognized check name", P
);
2741 Set_Etype
(N
, Standard_Boolean
);
2747 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2749 if Present
(E1
) then
2751 Check_Discrete_Type
;
2752 Resolve
(E1
, P_Base_Type
);
2755 if not Is_Entity_Name
(P
)
2756 or else (not Is_Object
(Entity
(P
))
2758 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2761 ("prefix of %attribute must be " &
2762 "discrete type/object or enum literal");
2766 Set_Etype
(N
, Universal_Integer
);
2773 when Attribute_Epsilon
=>
2774 Check_Floating_Point_Type_0
;
2775 Set_Etype
(N
, Universal_Real
);
2781 when Attribute_Exponent
=>
2782 Check_Floating_Point_Type_1
;
2783 Set_Etype
(N
, Universal_Integer
);
2784 Resolve
(E1
, P_Base_Type
);
2790 when Attribute_External_Tag
=>
2794 Set_Etype
(N
, Standard_String
);
2796 if not Is_Tagged_Type
(P_Type
) then
2797 Error_Attr_P
("prefix of % attribute must be tagged");
2804 when Attribute_Fast_Math
=>
2806 Check_Standard_Prefix
;
2808 if Opt
.Fast_Math
then
2809 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
2811 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
2818 when Attribute_First
=>
2819 Check_Array_Or_Scalar_Type
;
2825 when Attribute_First_Bit
=>
2827 Set_Etype
(N
, Universal_Integer
);
2833 when Attribute_Fixed_Value
=>
2835 Check_Fixed_Point_Type
;
2836 Resolve
(E1
, Any_Integer
);
2837 Set_Etype
(N
, P_Base_Type
);
2843 when Attribute_Floor
=>
2844 Check_Floating_Point_Type_1
;
2845 Set_Etype
(N
, P_Base_Type
);
2846 Resolve
(E1
, P_Base_Type
);
2852 when Attribute_Fore
=>
2853 Check_Fixed_Point_Type_0
;
2854 Set_Etype
(N
, Universal_Integer
);
2860 when Attribute_Fraction
=>
2861 Check_Floating_Point_Type_1
;
2862 Set_Etype
(N
, P_Base_Type
);
2863 Resolve
(E1
, P_Base_Type
);
2865 -----------------------
2866 -- Has_Access_Values --
2867 -----------------------
2869 when Attribute_Has_Access_Values
=>
2872 Set_Etype
(N
, Standard_Boolean
);
2874 -----------------------
2875 -- Has_Discriminants --
2876 -----------------------
2878 when Attribute_Has_Discriminants
=>
2879 Legal_Formal_Attribute
;
2885 when Attribute_Identity
=>
2889 if Etype
(P
) = Standard_Exception_Type
then
2890 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2892 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
2893 -- task interface class-wide types.
2895 elsif Is_Task_Type
(Etype
(P
))
2896 or else (Is_Access_Type
(Etype
(P
))
2897 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2898 or else (Ada_Version
>= Ada_05
2899 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2900 and then Is_Interface
(Etype
(P
))
2901 and then Is_Task_Interface
(Etype
(P
)))
2904 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2907 if Ada_Version
>= Ada_05
then
2909 ("prefix of % attribute must be an exception, a " &
2910 "task or a task interface class-wide object");
2913 ("prefix of % attribute must be a task or an exception");
2921 when Attribute_Image
=> Image
:
2923 Set_Etype
(N
, Standard_String
);
2926 if Is_Real_Type
(P_Type
) then
2927 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2928 Error_Msg_Name_1
:= Aname
;
2930 ("(Ada 83) % attribute not allowed for real types", N
);
2934 if Is_Enumeration_Type
(P_Type
) then
2935 Check_Restriction
(No_Enumeration_Maps
, N
);
2939 Resolve
(E1
, P_Base_Type
);
2941 Validate_Non_Static_Attribute_Function_Call
;
2948 when Attribute_Img
=> Img
:
2951 Set_Etype
(N
, Standard_String
);
2953 if not Is_Scalar_Type
(P_Type
)
2954 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2957 ("prefix of % attribute must be scalar object name");
2967 when Attribute_Input
=>
2969 Check_Stream_Attribute
(TSS_Stream_Input
);
2970 Set_Etype
(N
, P_Base_Type
);
2976 when Attribute_Integer_Value
=>
2979 Resolve
(E1
, Any_Fixed
);
2981 -- Signal an error if argument type is not a specific fixed-point
2982 -- subtype. An error has been signalled already if the argument
2983 -- was not of a fixed-point type.
2985 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
2986 Error_Attr
("argument of % must be of a fixed-point type", E1
);
2989 Set_Etype
(N
, P_Base_Type
);
2995 when Attribute_Large
=>
2998 Set_Etype
(N
, Universal_Real
);
3004 when Attribute_Last
=>
3005 Check_Array_Or_Scalar_Type
;
3011 when Attribute_Last_Bit
=>
3013 Set_Etype
(N
, Universal_Integer
);
3019 when Attribute_Leading_Part
=>
3020 Check_Floating_Point_Type_2
;
3021 Set_Etype
(N
, P_Base_Type
);
3022 Resolve
(E1
, P_Base_Type
);
3023 Resolve
(E2
, Any_Integer
);
3029 when Attribute_Length
=>
3031 Set_Etype
(N
, Universal_Integer
);
3037 when Attribute_Machine
=>
3038 Check_Floating_Point_Type_1
;
3039 Set_Etype
(N
, P_Base_Type
);
3040 Resolve
(E1
, P_Base_Type
);
3046 when Attribute_Machine_Emax
=>
3047 Check_Floating_Point_Type_0
;
3048 Set_Etype
(N
, Universal_Integer
);
3054 when Attribute_Machine_Emin
=>
3055 Check_Floating_Point_Type_0
;
3056 Set_Etype
(N
, Universal_Integer
);
3058 ----------------------
3059 -- Machine_Mantissa --
3060 ----------------------
3062 when Attribute_Machine_Mantissa
=>
3063 Check_Floating_Point_Type_0
;
3064 Set_Etype
(N
, Universal_Integer
);
3066 -----------------------
3067 -- Machine_Overflows --
3068 -----------------------
3070 when Attribute_Machine_Overflows
=>
3073 Set_Etype
(N
, Standard_Boolean
);
3079 when Attribute_Machine_Radix
=>
3082 Set_Etype
(N
, Universal_Integer
);
3084 ----------------------
3085 -- Machine_Rounding --
3086 ----------------------
3088 when Attribute_Machine_Rounding
=>
3089 Check_Floating_Point_Type_1
;
3090 Set_Etype
(N
, P_Base_Type
);
3091 Resolve
(E1
, P_Base_Type
);
3093 --------------------
3094 -- Machine_Rounds --
3095 --------------------
3097 when Attribute_Machine_Rounds
=>
3100 Set_Etype
(N
, Standard_Boolean
);
3106 when Attribute_Machine_Size
=>
3109 Check_Not_Incomplete_Type
;
3110 Set_Etype
(N
, Universal_Integer
);
3116 when Attribute_Mantissa
=>
3119 Set_Etype
(N
, Universal_Integer
);
3125 when Attribute_Max
=>
3128 Resolve
(E1
, P_Base_Type
);
3129 Resolve
(E2
, P_Base_Type
);
3130 Set_Etype
(N
, P_Base_Type
);
3132 ----------------------------------
3133 -- Max_Size_In_Storage_Elements --
3134 ----------------------------------
3136 when Attribute_Max_Size_In_Storage_Elements
=>
3139 Check_Not_Incomplete_Type
;
3140 Set_Etype
(N
, Universal_Integer
);
3142 -----------------------
3143 -- Maximum_Alignment --
3144 -----------------------
3146 when Attribute_Maximum_Alignment
=>
3147 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3149 --------------------
3150 -- Mechanism_Code --
3151 --------------------
3153 when Attribute_Mechanism_Code
=>
3154 if not Is_Entity_Name
(P
)
3155 or else not Is_Subprogram
(Entity
(P
))
3157 Error_Attr_P
("prefix of % attribute must be subprogram");
3160 Check_Either_E0_Or_E1
;
3162 if Present
(E1
) then
3163 Resolve
(E1
, Any_Integer
);
3164 Set_Etype
(E1
, Standard_Integer
);
3166 if not Is_Static_Expression
(E1
) then
3167 Flag_Non_Static_Expr
3168 ("expression for parameter number must be static!", E1
);
3171 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3172 or else UI_To_Int
(Intval
(E1
)) < 0
3174 Error_Attr
("invalid parameter number for %attribute", E1
);
3178 Set_Etype
(N
, Universal_Integer
);
3184 when Attribute_Min
=>
3187 Resolve
(E1
, P_Base_Type
);
3188 Resolve
(E2
, P_Base_Type
);
3189 Set_Etype
(N
, P_Base_Type
);
3195 when Attribute_Mod
=>
3197 -- Note: this attribute is only allowed in Ada 2005 mode, but
3198 -- we do not need to test that here, since Mod is only recognized
3199 -- as an attribute name in Ada 2005 mode during the parse.
3202 Check_Modular_Integer_Type
;
3203 Resolve
(E1
, Any_Integer
);
3204 Set_Etype
(N
, P_Base_Type
);
3210 when Attribute_Model
=>
3211 Check_Floating_Point_Type_1
;
3212 Set_Etype
(N
, P_Base_Type
);
3213 Resolve
(E1
, P_Base_Type
);
3219 when Attribute_Model_Emin
=>
3220 Check_Floating_Point_Type_0
;
3221 Set_Etype
(N
, Universal_Integer
);
3227 when Attribute_Model_Epsilon
=>
3228 Check_Floating_Point_Type_0
;
3229 Set_Etype
(N
, Universal_Real
);
3231 --------------------
3232 -- Model_Mantissa --
3233 --------------------
3235 when Attribute_Model_Mantissa
=>
3236 Check_Floating_Point_Type_0
;
3237 Set_Etype
(N
, Universal_Integer
);
3243 when Attribute_Model_Small
=>
3244 Check_Floating_Point_Type_0
;
3245 Set_Etype
(N
, Universal_Real
);
3251 when Attribute_Modulus
=>
3253 Check_Modular_Integer_Type
;
3254 Set_Etype
(N
, Universal_Integer
);
3256 --------------------
3257 -- Null_Parameter --
3258 --------------------
3260 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3261 Parnt
: constant Node_Id
:= Parent
(N
);
3262 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3264 procedure Bad_Null_Parameter
(Msg
: String);
3265 -- Used if bad Null parameter attribute node is found. Issues
3266 -- given error message, and also sets the type to Any_Type to
3267 -- avoid blowups later on from dealing with a junk node.
3269 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3270 -- Called to check that Proc_Ent is imported subprogram
3272 ------------------------
3273 -- Bad_Null_Parameter --
3274 ------------------------
3276 procedure Bad_Null_Parameter
(Msg
: String) is
3278 Error_Msg_N
(Msg
, N
);
3279 Set_Etype
(N
, Any_Type
);
3280 end Bad_Null_Parameter
;
3282 ----------------------
3283 -- Must_Be_Imported --
3284 ----------------------
3286 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3287 Pent
: Entity_Id
:= Proc_Ent
;
3290 while Present
(Alias
(Pent
)) loop
3291 Pent
:= Alias
(Pent
);
3294 -- Ignore check if procedure not frozen yet (we will get
3295 -- another chance when the default parameter is reanalyzed)
3297 if not Is_Frozen
(Pent
) then
3300 elsif not Is_Imported
(Pent
) then
3302 ("Null_Parameter can only be used with imported subprogram");
3307 end Must_Be_Imported
;
3309 -- Start of processing for Null_Parameter
3314 Set_Etype
(N
, P_Type
);
3316 -- Case of attribute used as default expression
3318 if Nkind
(Parnt
) = N_Parameter_Specification
then
3319 Must_Be_Imported
(Defining_Entity
(GParnt
));
3321 -- Case of attribute used as actual for subprogram (positional)
3323 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
3325 Nkind
(Parnt
) = N_Function_Call
)
3326 and then Is_Entity_Name
(Name
(Parnt
))
3328 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3330 -- Case of attribute used as actual for subprogram (named)
3332 elsif Nkind
(Parnt
) = N_Parameter_Association
3333 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
3335 Nkind
(GParnt
) = N_Function_Call
)
3336 and then Is_Entity_Name
(Name
(GParnt
))
3338 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3340 -- Not an allowed case
3344 ("Null_Parameter must be actual or default parameter");
3353 when Attribute_Object_Size
=>
3356 Check_Not_Incomplete_Type
;
3357 Set_Etype
(N
, Universal_Integer
);
3363 when Attribute_Output
=>
3365 Check_Stream_Attribute
(TSS_Stream_Output
);
3366 Set_Etype
(N
, Standard_Void_Type
);
3367 Resolve
(N
, Standard_Void_Type
);
3373 when Attribute_Partition_ID
=>
3376 if P_Type
/= Any_Type
then
3377 if not Is_Library_Level_Entity
(Entity
(P
)) then
3379 ("prefix of % attribute must be library-level entity");
3381 -- The defining entity of prefix should not be declared inside
3382 -- a Pure unit. RM E.1(8).
3383 -- The Is_Pure flag has been set during declaration.
3385 elsif Is_Entity_Name
(P
)
3386 and then Is_Pure
(Entity
(P
))
3389 ("prefix of % attribute must not be declared pure");
3393 Set_Etype
(N
, Universal_Integer
);
3395 -------------------------
3396 -- Passed_By_Reference --
3397 -------------------------
3399 when Attribute_Passed_By_Reference
=>
3402 Set_Etype
(N
, Standard_Boolean
);
3408 when Attribute_Pool_Address
=>
3410 Set_Etype
(N
, RTE
(RE_Address
));
3416 when Attribute_Pos
=>
3417 Check_Discrete_Type
;
3419 Resolve
(E1
, P_Base_Type
);
3420 Set_Etype
(N
, Universal_Integer
);
3426 when Attribute_Position
=>
3428 Set_Etype
(N
, Universal_Integer
);
3434 when Attribute_Pred
=>
3437 Resolve
(E1
, P_Base_Type
);
3438 Set_Etype
(N
, P_Base_Type
);
3440 -- Nothing to do for real type case
3442 if Is_Real_Type
(P_Type
) then
3445 -- If not modular type, test for overflow check required
3448 if not Is_Modular_Integer_Type
(P_Type
)
3449 and then not Range_Checks_Suppressed
(P_Base_Type
)
3451 Enable_Range_Check
(E1
);
3459 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3461 when Attribute_Priority
=>
3462 if Ada_Version
< Ada_05
then
3463 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
3468 -- The prefix must be a protected object (AARM D.5.2 (2/2))
3472 if Is_Protected_Type
(Etype
(P
))
3473 or else (Is_Access_Type
(Etype
(P
))
3474 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
3476 Resolve
(P
, Etype
(P
));
3478 Error_Attr_P
("prefix of % attribute must be a protected object");
3481 Set_Etype
(N
, Standard_Integer
);
3483 -- Must be called from within a protected procedure or entry of the
3484 -- protected object.
3491 while S
/= Etype
(P
)
3492 and then S
/= Standard_Standard
3497 if S
= Standard_Standard
then
3498 Error_Attr
("the attribute % is only allowed inside protected "
3503 Validate_Non_Static_Attribute_Function_Call
;
3509 when Attribute_Range
=>
3510 Check_Array_Or_Scalar_Type
;
3512 if Ada_Version
= Ada_83
3513 and then Is_Scalar_Type
(P_Type
)
3514 and then Comes_From_Source
(N
)
3517 ("(Ada 83) % attribute not allowed for scalar type", P
);
3524 when Attribute_Range_Length
=>
3525 Check_Discrete_Type
;
3526 Set_Etype
(N
, Universal_Integer
);
3532 when Attribute_Read
=>
3534 Check_Stream_Attribute
(TSS_Stream_Read
);
3535 Set_Etype
(N
, Standard_Void_Type
);
3536 Resolve
(N
, Standard_Void_Type
);
3537 Note_Possible_Modification
(E2
);
3543 when Attribute_Remainder
=>
3544 Check_Floating_Point_Type_2
;
3545 Set_Etype
(N
, P_Base_Type
);
3546 Resolve
(E1
, P_Base_Type
);
3547 Resolve
(E2
, P_Base_Type
);
3553 when Attribute_Round
=>
3555 Check_Decimal_Fixed_Point_Type
;
3556 Set_Etype
(N
, P_Base_Type
);
3558 -- Because the context is universal_real (3.5.10(12)) it is a legal
3559 -- context for a universal fixed expression. This is the only
3560 -- attribute whose functional description involves U_R.
3562 if Etype
(E1
) = Universal_Fixed
then
3564 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3565 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3566 Expression
=> Relocate_Node
(E1
));
3574 Resolve
(E1
, Any_Real
);
3580 when Attribute_Rounding
=>
3581 Check_Floating_Point_Type_1
;
3582 Set_Etype
(N
, P_Base_Type
);
3583 Resolve
(E1
, P_Base_Type
);
3589 when Attribute_Safe_Emax
=>
3590 Check_Floating_Point_Type_0
;
3591 Set_Etype
(N
, Universal_Integer
);
3597 when Attribute_Safe_First
=>
3598 Check_Floating_Point_Type_0
;
3599 Set_Etype
(N
, Universal_Real
);
3605 when Attribute_Safe_Large
=>
3608 Set_Etype
(N
, Universal_Real
);
3614 when Attribute_Safe_Last
=>
3615 Check_Floating_Point_Type_0
;
3616 Set_Etype
(N
, Universal_Real
);
3622 when Attribute_Safe_Small
=>
3625 Set_Etype
(N
, Universal_Real
);
3631 when Attribute_Scale
=>
3633 Check_Decimal_Fixed_Point_Type
;
3634 Set_Etype
(N
, Universal_Integer
);
3640 when Attribute_Scaling
=>
3641 Check_Floating_Point_Type_2
;
3642 Set_Etype
(N
, P_Base_Type
);
3643 Resolve
(E1
, P_Base_Type
);
3649 when Attribute_Signed_Zeros
=>
3650 Check_Floating_Point_Type_0
;
3651 Set_Etype
(N
, Standard_Boolean
);
3657 when Attribute_Size | Attribute_VADS_Size
=>
3660 -- If prefix is parameterless function call, rewrite and resolve
3663 if Is_Entity_Name
(P
)
3664 and then Ekind
(Entity
(P
)) = E_Function
3668 -- Similar processing for a protected function call
3670 elsif Nkind
(P
) = N_Selected_Component
3671 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
3676 if Is_Object_Reference
(P
) then
3677 Check_Object_Reference
(P
);
3679 elsif Is_Entity_Name
(P
)
3680 and then (Is_Type
(Entity
(P
))
3681 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
3685 elsif Nkind
(P
) = N_Type_Conversion
3686 and then not Comes_From_Source
(P
)
3691 Error_Attr_P
("invalid prefix for % attribute");
3694 Check_Not_Incomplete_Type
;
3695 Set_Etype
(N
, Universal_Integer
);
3701 when Attribute_Small
=>
3704 Set_Etype
(N
, Universal_Real
);
3710 when Attribute_Storage_Pool
=>
3711 if Is_Access_Type
(P_Type
) then
3714 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
3716 ("cannot use % attribute for access-to-subprogram type");
3719 -- Set appropriate entity
3721 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3722 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3724 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3727 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3729 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3730 -- Storage_Pool since this attribute is not defined for such
3731 -- types (RM E.2.3(22)).
3733 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3736 Error_Attr_P
("prefix of % attribute must be access type");
3743 when Attribute_Storage_Size
=>
3744 if Is_Task_Type
(P_Type
) then
3746 Set_Etype
(N
, Universal_Integer
);
3748 elsif Is_Access_Type
(P_Type
) then
3749 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
3751 ("cannot use % attribute for access-to-subprogram type");
3754 if Is_Entity_Name
(P
)
3755 and then Is_Type
(Entity
(P
))
3759 Set_Etype
(N
, Universal_Integer
);
3761 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3762 -- Storage_Size since this attribute is not defined for
3763 -- such types (RM E.2.3(22)).
3765 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3767 -- The prefix is allowed to be an implicit dereference
3768 -- of an access value designating a task.
3773 Set_Etype
(N
, Universal_Integer
);
3777 Error_Attr_P
("prefix of % attribute must be access or task type");
3784 when Attribute_Storage_Unit
=>
3785 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3791 when Attribute_Stream_Size
=>
3795 if Is_Entity_Name
(P
)
3796 and then Is_Elementary_Type
(Entity
(P
))
3798 Set_Etype
(N
, Universal_Integer
);
3800 Error_Attr_P
("invalid prefix for % attribute");
3807 when Attribute_Stub_Type
=>
3811 if Is_Remote_Access_To_Class_Wide_Type
(P_Type
) then
3813 New_Occurrence_Of
(Corresponding_Stub_Type
(P_Type
), Loc
));
3816 ("prefix of% attribute must be remote access to classwide");
3823 when Attribute_Succ
=>
3826 Resolve
(E1
, P_Base_Type
);
3827 Set_Etype
(N
, P_Base_Type
);
3829 -- Nothing to do for real type case
3831 if Is_Real_Type
(P_Type
) then
3834 -- If not modular type, test for overflow check required
3837 if not Is_Modular_Integer_Type
(P_Type
)
3838 and then not Range_Checks_Suppressed
(P_Base_Type
)
3840 Enable_Range_Check
(E1
);
3848 when Attribute_Tag
=>
3852 if not Is_Tagged_Type
(P_Type
) then
3853 Error_Attr_P
("prefix of % attribute must be tagged");
3855 -- Next test does not apply to generated code
3856 -- why not, and what does the illegal reference mean???
3858 elsif Is_Object_Reference
(P
)
3859 and then not Is_Class_Wide_Type
(P_Type
)
3860 and then Comes_From_Source
(N
)
3863 ("% attribute can only be applied to objects " &
3864 "of class - wide type");
3867 -- The prefix cannot be an incomplete type. However, references
3868 -- to 'Tag can be generated when expanding interface conversions,
3869 -- and this is legal.
3871 if Comes_From_Source
(N
) then
3872 Check_Not_Incomplete_Type
;
3875 -- Set appropriate type
3877 Set_Etype
(N
, RTE
(RE_Tag
));
3883 when Attribute_Target_Name
=> Target_Name
: declare
3884 TN
: constant String := Sdefault
.Target_Name
.all;
3888 Check_Standard_Prefix
;
3893 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
3898 Make_String_Literal
(Loc
,
3899 Strval
=> TN
(TN
'First .. TL
)));
3900 Analyze_And_Resolve
(N
, Standard_String
);
3907 when Attribute_Terminated
=>
3909 Set_Etype
(N
, Standard_Boolean
);
3916 when Attribute_To_Address
=>
3920 if Nkind
(P
) /= N_Identifier
3921 or else Chars
(P
) /= Name_System
3923 Error_Attr_P
("prefix of %attribute must be System");
3926 Generate_Reference
(RTE
(RE_Address
), P
);
3927 Analyze_And_Resolve
(E1
, Any_Integer
);
3928 Set_Etype
(N
, RTE
(RE_Address
));
3934 when Attribute_Truncation
=>
3935 Check_Floating_Point_Type_1
;
3936 Resolve
(E1
, P_Base_Type
);
3937 Set_Etype
(N
, P_Base_Type
);
3943 when Attribute_Type_Class
=>
3946 Check_Not_Incomplete_Type
;
3947 Set_Etype
(N
, RTE
(RE_Type_Class
));
3953 when Attribute_UET_Address
=>
3955 Check_Unit_Name
(P
);
3956 Set_Etype
(N
, RTE
(RE_Address
));
3958 -----------------------
3959 -- Unbiased_Rounding --
3960 -----------------------
3962 when Attribute_Unbiased_Rounding
=>
3963 Check_Floating_Point_Type_1
;
3964 Set_Etype
(N
, P_Base_Type
);
3965 Resolve
(E1
, P_Base_Type
);
3967 ----------------------
3968 -- Unchecked_Access --
3969 ----------------------
3971 when Attribute_Unchecked_Access
=>
3972 if Comes_From_Source
(N
) then
3973 Check_Restriction
(No_Unchecked_Access
, N
);
3976 Analyze_Access_Attribute
;
3978 -------------------------
3979 -- Unconstrained_Array --
3980 -------------------------
3982 when Attribute_Unconstrained_Array
=>
3985 Check_Not_Incomplete_Type
;
3986 Set_Etype
(N
, Standard_Boolean
);
3988 ------------------------------
3989 -- Universal_Literal_String --
3990 ------------------------------
3992 -- This is a GNAT specific attribute whose prefix must be a named
3993 -- number where the expression is either a single numeric literal,
3994 -- or a numeric literal immediately preceded by a minus sign. The
3995 -- result is equivalent to a string literal containing the text of
3996 -- the literal as it appeared in the source program with a possible
3997 -- leading minus sign.
3999 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
4003 if not Is_Entity_Name
(P
)
4004 or else Ekind
(Entity
(P
)) not in Named_Kind
4006 Error_Attr_P
("prefix for % attribute must be named number");
4013 Src
: Source_Buffer_Ptr
;
4016 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
4018 if Nkind
(Expr
) = N_Op_Minus
then
4020 Expr
:= Original_Node
(Right_Opnd
(Expr
));
4025 if Nkind
(Expr
) /= N_Integer_Literal
4026 and then Nkind
(Expr
) /= N_Real_Literal
4029 ("named number for % attribute must be simple literal", N
);
4032 -- Build string literal corresponding to source literal text
4037 Store_String_Char
(Get_Char_Code
('-'));
4041 Src
:= Source_Text
(Get_Source_File_Index
(S
));
4043 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
4044 Store_String_Char
(Get_Char_Code
(Src
(S
)));
4048 -- Now we rewrite the attribute with the string literal
4051 Make_String_Literal
(Loc
, End_String
));
4055 end Universal_Literal_String
;
4057 -------------------------
4058 -- Unrestricted_Access --
4059 -------------------------
4061 -- This is a GNAT specific attribute which is like Access except that
4062 -- all scope checks and checks for aliased views are omitted.
4064 when Attribute_Unrestricted_Access
=>
4065 if Comes_From_Source
(N
) then
4066 Check_Restriction
(No_Unchecked_Access
, N
);
4069 if Is_Entity_Name
(P
) then
4070 Set_Address_Taken
(Entity
(P
));
4073 Analyze_Access_Attribute
;
4079 when Attribute_Val
=> Val
: declare
4082 Check_Discrete_Type
;
4083 Resolve
(E1
, Any_Integer
);
4084 Set_Etype
(N
, P_Base_Type
);
4086 -- Note, we need a range check in general, but we wait for the
4087 -- Resolve call to do this, since we want to let Eval_Attribute
4088 -- have a chance to find an static illegality first!
4095 when Attribute_Valid
=>
4098 -- Ignore check for object if we have a 'Valid reference generated
4099 -- by the expanded code, since in some cases valid checks can occur
4100 -- on items that are names, but are not objects (e.g. attributes).
4102 if Comes_From_Source
(N
) then
4103 Check_Object_Reference
(P
);
4106 if not Is_Scalar_Type
(P_Type
) then
4107 Error_Attr_P
("object for % attribute must be of scalar type");
4110 Set_Etype
(N
, Standard_Boolean
);
4116 when Attribute_Value
=> Value
:
4121 -- Case of enumeration type
4123 if Is_Enumeration_Type
(P_Type
) then
4124 Check_Restriction
(No_Enumeration_Maps
, N
);
4126 -- Mark all enumeration literals as referenced, since the use of
4127 -- the Value attribute can implicitly reference any of the
4128 -- literals of the enumeration base type.
4131 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
4133 while Present
(Ent
) loop
4134 Set_Referenced
(Ent
);
4140 -- Set Etype before resolving expression because expansion of
4141 -- expression may require enclosing type. Note that the type
4142 -- returned by 'Value is the base type of the prefix type.
4144 Set_Etype
(N
, P_Base_Type
);
4145 Validate_Non_Static_Attribute_Function_Call
;
4152 when Attribute_Value_Size
=>
4155 Check_Not_Incomplete_Type
;
4156 Set_Etype
(N
, Universal_Integer
);
4162 when Attribute_Version
=>
4165 Set_Etype
(N
, RTE
(RE_Version_String
));
4171 when Attribute_Wchar_T_Size
=>
4172 Standard_Attribute
(Interfaces_Wchar_T_Size
);
4178 when Attribute_Wide_Image
=> Wide_Image
:
4181 Set_Etype
(N
, Standard_Wide_String
);
4183 Resolve
(E1
, P_Base_Type
);
4184 Validate_Non_Static_Attribute_Function_Call
;
4187 ---------------------
4188 -- Wide_Wide_Image --
4189 ---------------------
4191 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4194 Set_Etype
(N
, Standard_Wide_Wide_String
);
4196 Resolve
(E1
, P_Base_Type
);
4197 Validate_Non_Static_Attribute_Function_Call
;
4198 end Wide_Wide_Image
;
4204 when Attribute_Wide_Value
=> Wide_Value
:
4209 -- Set Etype before resolving expression because expansion
4210 -- of expression may require enclosing type.
4212 Set_Etype
(N
, P_Type
);
4213 Validate_Non_Static_Attribute_Function_Call
;
4216 ---------------------
4217 -- Wide_Wide_Value --
4218 ---------------------
4220 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4225 -- Set Etype before resolving expression because expansion
4226 -- of expression may require enclosing type.
4228 Set_Etype
(N
, P_Type
);
4229 Validate_Non_Static_Attribute_Function_Call
;
4230 end Wide_Wide_Value
;
4232 ---------------------
4233 -- Wide_Wide_Width --
4234 ---------------------
4236 when Attribute_Wide_Wide_Width
=>
4239 Set_Etype
(N
, Universal_Integer
);
4245 when Attribute_Wide_Width
=>
4248 Set_Etype
(N
, Universal_Integer
);
4254 when Attribute_Width
=>
4257 Set_Etype
(N
, Universal_Integer
);
4263 when Attribute_Word_Size
=>
4264 Standard_Attribute
(System_Word_Size
);
4270 when Attribute_Write
=>
4272 Check_Stream_Attribute
(TSS_Stream_Write
);
4273 Set_Etype
(N
, Standard_Void_Type
);
4274 Resolve
(N
, Standard_Void_Type
);
4278 -- All errors raise Bad_Attribute, so that we get out before any further
4279 -- damage occurs when an error is detected (for example, if we check for
4280 -- one attribute expression, and the check succeeds, we want to be able
4281 -- to proceed securely assuming that an expression is in fact present.
4283 -- Note: we set the attribute analyzed in this case to prevent any
4284 -- attempt at reanalysis which could generate spurious error msgs.
4287 when Bad_Attribute
=>
4289 Set_Etype
(N
, Any_Type
);
4291 end Analyze_Attribute
;
4293 --------------------
4294 -- Eval_Attribute --
4295 --------------------
4297 procedure Eval_Attribute
(N
: Node_Id
) is
4298 Loc
: constant Source_Ptr
:= Sloc
(N
);
4299 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4300 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4301 P
: constant Node_Id
:= Prefix
(N
);
4303 C_Type
: constant Entity_Id
:= Etype
(N
);
4304 -- The type imposed by the context
4307 -- First expression, or Empty if none
4310 -- Second expression, or Empty if none
4312 P_Entity
: Entity_Id
;
4313 -- Entity denoted by prefix
4316 -- The type of the prefix
4318 P_Base_Type
: Entity_Id
;
4319 -- The base type of the prefix type
4321 P_Root_Type
: Entity_Id
;
4322 -- The root type of the prefix type
4325 -- True if the result is Static. This is set by the general processing
4326 -- to true if the prefix is static, and all expressions are static. It
4327 -- can be reset as processing continues for particular attributes
4329 Lo_Bound
, Hi_Bound
: Node_Id
;
4330 -- Expressions for low and high bounds of type or array index referenced
4331 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4334 -- Constraint error node used if we have an attribute reference has
4335 -- an argument that raises a constraint error. In this case we replace
4336 -- the attribute with a raise constraint_error node. This is important
4337 -- processing, since otherwise gigi might see an attribute which it is
4338 -- unprepared to deal with.
4340 function Aft_Value
return Nat
;
4341 -- Computes Aft value for current attribute prefix (used by Aft itself
4342 -- and also by Width for computing the Width of a fixed point type).
4344 procedure Check_Expressions
;
4345 -- In case where the attribute is not foldable, the expressions, if
4346 -- any, of the attribute, are in a non-static context. This procedure
4347 -- performs the required additional checks.
4349 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4350 -- Determines if the given type has compile time known bounds. Note
4351 -- that we enter the case statement even in cases where the prefix
4352 -- type does NOT have known bounds, so it is important to guard any
4353 -- attempt to evaluate both bounds with a call to this function.
4355 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4356 -- This procedure is called when the attribute N has a non-static
4357 -- but compile time known value given by Val. It includes the
4358 -- necessary checks for out of range values.
4360 procedure Float_Attribute_Universal_Integer
4369 -- This procedure evaluates a float attribute with no arguments that
4370 -- returns a universal integer result. The parameters give the values
4371 -- for the possible floating-point root types. See ttypef for details.
4372 -- The prefix type is a float type (and is thus not a generic type).
4374 procedure Float_Attribute_Universal_Real
4375 (IEEES_Val
: String;
4382 AAMPL_Val
: String);
4383 -- This procedure evaluates a float attribute with no arguments that
4384 -- returns a universal real result. The parameters give the values
4385 -- required for the possible floating-point root types in string
4386 -- format as real literals with a possible leading minus sign.
4387 -- The prefix type is a float type (and is thus not a generic type).
4389 function Fore_Value
return Nat
;
4390 -- Computes the Fore value for the current attribute prefix, which is
4391 -- known to be a static fixed-point type. Used by Fore and Width.
4393 function Mantissa
return Uint
;
4394 -- Returns the Mantissa value for the prefix type
4396 procedure Set_Bounds
;
4397 -- Used for First, Last and Length attributes applied to an array or
4398 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4399 -- and high bound expressions for the index referenced by the attribute
4400 -- designator (i.e. the first index if no expression is present, and
4401 -- the N'th index if the value N is present as an expression). Also
4402 -- used for First and Last of scalar types. Static is reset to False
4403 -- if the type or index type is not statically constrained.
4405 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4406 -- Verify that the prefix of a potentially static array attribute
4407 -- satisfies the conditions of 4.9 (14).
4413 function Aft_Value
return Nat
is
4419 Delta_Val
:= Delta_Value
(P_Type
);
4420 while Delta_Val
< Ureal_Tenth
loop
4421 Delta_Val
:= Delta_Val
* Ureal_10
;
4422 Result
:= Result
+ 1;
4428 -----------------------
4429 -- Check_Expressions --
4430 -----------------------
4432 procedure Check_Expressions
is
4436 while Present
(E
) loop
4437 Check_Non_Static_Context
(E
);
4440 end Check_Expressions
;
4442 ----------------------------------
4443 -- Compile_Time_Known_Attribute --
4444 ----------------------------------
4446 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4447 T
: constant Entity_Id
:= Etype
(N
);
4450 Fold_Uint
(N
, Val
, False);
4452 -- Check that result is in bounds of the type if it is static
4454 if Is_In_Range
(N
, T
) then
4457 elsif Is_Out_Of_Range
(N
, T
) then
4458 Apply_Compile_Time_Constraint_Error
4459 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4461 elsif not Range_Checks_Suppressed
(T
) then
4462 Enable_Range_Check
(N
);
4465 Set_Do_Range_Check
(N
, False);
4467 end Compile_Time_Known_Attribute
;
4469 -------------------------------
4470 -- Compile_Time_Known_Bounds --
4471 -------------------------------
4473 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4476 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4478 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4479 end Compile_Time_Known_Bounds
;
4481 ---------------------------------------
4482 -- Float_Attribute_Universal_Integer --
4483 ---------------------------------------
4485 procedure Float_Attribute_Universal_Integer
4496 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4499 if Vax_Float
(P_Base_Type
) then
4500 if Digs
= VAXFF_Digits
then
4502 elsif Digs
= VAXDF_Digits
then
4504 else pragma Assert
(Digs
= VAXGF_Digits
);
4508 elsif Is_AAMP_Float
(P_Base_Type
) then
4509 if Digs
= AAMPS_Digits
then
4511 else pragma Assert
(Digs
= AAMPL_Digits
);
4516 if Digs
= IEEES_Digits
then
4518 elsif Digs
= IEEEL_Digits
then
4520 else pragma Assert
(Digs
= IEEEX_Digits
);
4525 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4526 end Float_Attribute_Universal_Integer
;
4528 ------------------------------------
4529 -- Float_Attribute_Universal_Real --
4530 ------------------------------------
4532 procedure Float_Attribute_Universal_Real
4533 (IEEES_Val
: String;
4543 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4546 if Vax_Float
(P_Base_Type
) then
4547 if Digs
= VAXFF_Digits
then
4548 Val
:= Real_Convert
(VAXFF_Val
);
4549 elsif Digs
= VAXDF_Digits
then
4550 Val
:= Real_Convert
(VAXDF_Val
);
4551 else pragma Assert
(Digs
= VAXGF_Digits
);
4552 Val
:= Real_Convert
(VAXGF_Val
);
4555 elsif Is_AAMP_Float
(P_Base_Type
) then
4556 if Digs
= AAMPS_Digits
then
4557 Val
:= Real_Convert
(AAMPS_Val
);
4558 else pragma Assert
(Digs
= AAMPL_Digits
);
4559 Val
:= Real_Convert
(AAMPL_Val
);
4563 if Digs
= IEEES_Digits
then
4564 Val
:= Real_Convert
(IEEES_Val
);
4565 elsif Digs
= IEEEL_Digits
then
4566 Val
:= Real_Convert
(IEEEL_Val
);
4567 else pragma Assert
(Digs
= IEEEX_Digits
);
4568 Val
:= Real_Convert
(IEEEX_Val
);
4572 Set_Sloc
(Val
, Loc
);
4574 Set_Is_Static_Expression
(N
, Static
);
4575 Analyze_And_Resolve
(N
, C_Type
);
4576 end Float_Attribute_Universal_Real
;
4582 -- Note that the Fore calculation is based on the actual values
4583 -- of the bounds, and does not take into account possible rounding.
4585 function Fore_Value
return Nat
is
4586 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4587 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4588 Small
: constant Ureal
:= Small_Value
(P_Type
);
4589 Lo_Real
: constant Ureal
:= Lo
* Small
;
4590 Hi_Real
: constant Ureal
:= Hi
* Small
;
4595 -- Bounds are given in terms of small units, so first compute
4596 -- proper values as reals.
4598 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4601 -- Loop to compute proper value if more than one digit required
4603 while T
>= Ureal_10
loop
4615 -- Table of mantissa values accessed by function Computed using
4618 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4620 -- where D is T'Digits (RM83 3.5.7)
4622 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4664 function Mantissa
return Uint
is
4667 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4674 procedure Set_Bounds
is
4680 -- For a string literal subtype, we have to construct the bounds.
4681 -- Valid Ada code never applies attributes to string literals, but
4682 -- it is convenient to allow the expander to generate attribute
4683 -- references of this type (e.g. First and Last applied to a string
4686 -- Note that the whole point of the E_String_Literal_Subtype is to
4687 -- avoid this construction of bounds, but the cases in which we
4688 -- have to materialize them are rare enough that we don't worry!
4690 -- The low bound is simply the low bound of the base type. The
4691 -- high bound is computed from the length of the string and this
4694 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4695 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4696 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4699 Make_Integer_Literal
(Sloc
(P
),
4701 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4703 Set_Parent
(Hi_Bound
, P
);
4704 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4707 -- For non-array case, just get bounds of scalar type
4709 elsif Is_Scalar_Type
(P_Type
) then
4712 -- For a fixed-point type, we must freeze to get the attributes
4713 -- of the fixed-point type set now so we can reference them.
4715 if Is_Fixed_Point_Type
(P_Type
)
4716 and then not Is_Frozen
(Base_Type
(P_Type
))
4717 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4718 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4720 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4723 -- For array case, get type of proper index
4729 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4732 Indx
:= First_Index
(P_Type
);
4733 for J
in 1 .. Ndim
- 1 loop
4737 -- If no index type, get out (some other error occurred, and
4738 -- we don't have enough information to complete the job!)
4746 Ityp
:= Etype
(Indx
);
4749 -- A discrete range in an index constraint is allowed to be a
4750 -- subtype indication. This is syntactically a pain, but should
4751 -- not propagate to the entity for the corresponding index subtype.
4752 -- After checking that the subtype indication is legal, the range
4753 -- of the subtype indication should be transfered to the entity.
4754 -- The attributes for the bounds should remain the simple retrievals
4755 -- that they are now.
4757 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4758 Hi_Bound
:= Type_High_Bound
(Ityp
);
4760 if not Is_Static_Subtype
(Ityp
) then
4765 -------------------------------
4766 -- Statically_Denotes_Entity --
4767 -------------------------------
4769 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
4773 if not Is_Entity_Name
(N
) then
4780 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
4781 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
4782 end Statically_Denotes_Entity
;
4784 -- Start of processing for Eval_Attribute
4787 -- Acquire first two expressions (at the moment, no attributes
4788 -- take more than two expressions in any case).
4790 if Present
(Expressions
(N
)) then
4791 E1
:= First
(Expressions
(N
));
4798 -- Special processing for Enabled attribute. This attribute has a very
4799 -- special prefix, and the easiest way to avoid lots of special checks
4800 -- to protect this special prefix from causing trouble is to deal with
4801 -- this attribute immediately and be done with it.
4803 if Id
= Attribute_Enabled
then
4805 -- Evaluate the Enabled attribute
4807 -- We skip evaluation if the expander is not active. This is not just
4808 -- an optimization. It is of key importance that we not rewrite the
4809 -- attribute in a generic template, since we want to pick up the
4810 -- setting of the check in the instance, and testing expander active
4811 -- is as easy way of doing this as any.
4813 if Expander_Active
then
4815 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
4820 if C
in Predefined_Check_Id
then
4821 R
:= Scope_Suppress
(C
);
4823 R
:= Is_Check_Suppressed
(Empty
, C
);
4827 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
4831 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
4833 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
4841 -- Special processing for cases where the prefix is an object. For
4842 -- this purpose, a string literal counts as an object (attributes
4843 -- of string literals can only appear in generated code).
4845 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
4847 -- For Component_Size, the prefix is an array object, and we apply
4848 -- the attribute to the type of the object. This is allowed for
4849 -- both unconstrained and constrained arrays, since the bounds
4850 -- have no influence on the value of this attribute.
4852 if Id
= Attribute_Component_Size
then
4853 P_Entity
:= Etype
(P
);
4855 -- For First and Last, the prefix is an array object, and we apply
4856 -- the attribute to the type of the array, but we need a constrained
4857 -- type for this, so we use the actual subtype if available.
4859 elsif Id
= Attribute_First
4863 Id
= Attribute_Length
4866 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4869 if Present
(AS
) and then Is_Constrained
(AS
) then
4872 -- If we have an unconstrained type, cannot fold
4880 -- For Size, give size of object if available, otherwise we
4881 -- cannot fold Size.
4883 elsif Id
= Attribute_Size
then
4884 if Is_Entity_Name
(P
)
4885 and then Known_Esize
(Entity
(P
))
4887 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4895 -- For Alignment, give size of object if available, otherwise we
4896 -- cannot fold Alignment.
4898 elsif Id
= Attribute_Alignment
then
4899 if Is_Entity_Name
(P
)
4900 and then Known_Alignment
(Entity
(P
))
4902 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
4910 -- No other attributes for objects are folded
4917 -- Cases where P is not an object. Cannot do anything if P is
4918 -- not the name of an entity.
4920 elsif not Is_Entity_Name
(P
) then
4924 -- Otherwise get prefix entity
4927 P_Entity
:= Entity
(P
);
4930 -- At this stage P_Entity is the entity to which the attribute
4931 -- is to be applied. This is usually simply the entity of the
4932 -- prefix, except in some cases of attributes for objects, where
4933 -- as described above, we apply the attribute to the object type.
4935 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4936 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4937 -- Note we allow non-static non-generic types at this stage as further
4940 if Is_Type
(P_Entity
)
4941 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4942 and then (not Is_Generic_Type
(P_Entity
))
4946 -- Second foldable possibility is an array object (RM 4.9(8))
4948 elsif (Ekind
(P_Entity
) = E_Variable
4950 Ekind
(P_Entity
) = E_Constant
)
4951 and then Is_Array_Type
(Etype
(P_Entity
))
4952 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4954 P_Type
:= Etype
(P_Entity
);
4956 -- If the entity is an array constant with an unconstrained nominal
4957 -- subtype then get the type from the initial value. If the value has
4958 -- been expanded into assignments, there is no expression and the
4959 -- attribute reference remains dynamic.
4960 -- We could do better here and retrieve the type ???
4962 if Ekind
(P_Entity
) = E_Constant
4963 and then not Is_Constrained
(P_Type
)
4965 if No
(Constant_Value
(P_Entity
)) then
4968 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4972 -- Definite must be folded if the prefix is not a generic type,
4973 -- that is to say if we are within an instantiation. Same processing
4974 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4975 -- and Unconstrained_Array.
4977 elsif (Id
= Attribute_Definite
4979 Id
= Attribute_Has_Access_Values
4981 Id
= Attribute_Has_Discriminants
4983 Id
= Attribute_Type_Class
4985 Id
= Attribute_Unconstrained_Array
)
4986 and then not Is_Generic_Type
(P_Entity
)
4990 -- We can fold 'Size applied to a type if the size is known
4991 -- (as happens for a size from an attribute definition clause).
4992 -- At this stage, this can happen only for types (e.g. record
4993 -- types) for which the size is always non-static. We exclude
4994 -- generic types from consideration (since they have bogus
4995 -- sizes set within templates).
4997 elsif Id
= Attribute_Size
4998 and then Is_Type
(P_Entity
)
4999 and then (not Is_Generic_Type
(P_Entity
))
5000 and then Known_Static_RM_Size
(P_Entity
)
5002 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
5005 -- We can fold 'Alignment applied to a type if the alignment is known
5006 -- (as happens for an alignment from an attribute definition clause).
5007 -- At this stage, this can happen only for types (e.g. record
5008 -- types) for which the size is always non-static. We exclude
5009 -- generic types from consideration (since they have bogus
5010 -- sizes set within templates).
5012 elsif Id
= Attribute_Alignment
5013 and then Is_Type
(P_Entity
)
5014 and then (not Is_Generic_Type
(P_Entity
))
5015 and then Known_Alignment
(P_Entity
)
5017 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
5020 -- If this is an access attribute that is known to fail accessibility
5021 -- check, rewrite accordingly.
5023 elsif Attribute_Name
(N
) = Name_Access
5024 and then Raises_Constraint_Error
(N
)
5027 Make_Raise_Program_Error
(Loc
,
5028 Reason
=> PE_Accessibility_Check_Failed
));
5029 Set_Etype
(N
, C_Type
);
5032 -- No other cases are foldable (they certainly aren't static, and at
5033 -- the moment we don't try to fold any cases other than these three).
5040 -- If either attribute or the prefix is Any_Type, then propagate
5041 -- Any_Type to the result and don't do anything else at all.
5043 if P_Type
= Any_Type
5044 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
5045 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
5047 Set_Etype
(N
, Any_Type
);
5051 -- Scalar subtype case. We have not yet enforced the static requirement
5052 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
5053 -- of non-static attribute references (e.g. S'Digits for a non-static
5054 -- floating-point type, which we can compute at compile time).
5056 -- Note: this folding of non-static attributes is not simply a case of
5057 -- optimization. For many of the attributes affected, Gigi cannot handle
5058 -- the attribute and depends on the front end having folded them away.
5060 -- Note: although we don't require staticness at this stage, we do set
5061 -- the Static variable to record the staticness, for easy reference by
5062 -- those attributes where it matters (e.g. Succ and Pred), and also to
5063 -- be used to ensure that non-static folded things are not marked as
5064 -- being static (a check that is done right at the end).
5066 P_Root_Type
:= Root_Type
(P_Type
);
5067 P_Base_Type
:= Base_Type
(P_Type
);
5069 -- If the root type or base type is generic, then we cannot fold. This
5070 -- test is needed because subtypes of generic types are not always
5071 -- marked as being generic themselves (which seems odd???)
5073 if Is_Generic_Type
(P_Root_Type
)
5074 or else Is_Generic_Type
(P_Base_Type
)
5079 if Is_Scalar_Type
(P_Type
) then
5080 Static
:= Is_OK_Static_Subtype
(P_Type
);
5082 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
5083 -- since we can't do anything with unconstrained arrays. In addition,
5084 -- only the First, Last and Length attributes are possibly static.
5086 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
5087 -- Unconstrained_Array are again exceptions, because they apply as
5088 -- well to unconstrained types.
5090 -- In addition Component_Size is an exception since it is possibly
5091 -- foldable, even though it is never static, and it does apply to
5092 -- unconstrained arrays. Furthermore, it is essential to fold this
5093 -- in the packed case, since otherwise the value will be incorrect.
5095 elsif Id
= Attribute_Definite
5097 Id
= Attribute_Has_Access_Values
5099 Id
= Attribute_Has_Discriminants
5101 Id
= Attribute_Type_Class
5103 Id
= Attribute_Unconstrained_Array
5105 Id
= Attribute_Component_Size
5110 if not Is_Constrained
(P_Type
)
5111 or else (Id
/= Attribute_First
and then
5112 Id
/= Attribute_Last
and then
5113 Id
/= Attribute_Length
)
5119 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
5120 -- scalar case, we hold off on enforcing staticness, since there are
5121 -- cases which we can fold at compile time even though they are not
5122 -- static (e.g. 'Length applied to a static index, even though other
5123 -- non-static indexes make the array type non-static). This is only
5124 -- an optimization, but it falls out essentially free, so why not.
5125 -- Again we compute the variable Static for easy reference later
5126 -- (note that no array attributes are static in Ada 83).
5128 Static
:= Ada_Version
>= Ada_95
5129 and then Statically_Denotes_Entity
(P
);
5135 N
:= First_Index
(P_Type
);
5136 while Present
(N
) loop
5137 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
5139 -- If however the index type is generic, attributes cannot
5142 if Is_Generic_Type
(Etype
(N
))
5143 and then Id
/= Attribute_Component_Size
5153 -- Check any expressions that are present. Note that these expressions,
5154 -- depending on the particular attribute type, are either part of the
5155 -- attribute designator, or they are arguments in a case where the
5156 -- attribute reference returns a function. In the latter case, the
5157 -- rule in (RM 4.9(22)) applies and in particular requires the type
5158 -- of the expressions to be scalar in order for the attribute to be
5159 -- considered to be static.
5166 while Present
(E
) loop
5168 -- If expression is not static, then the attribute reference
5169 -- result certainly cannot be static.
5171 if not Is_Static_Expression
(E
) then
5175 -- If the result is not known at compile time, or is not of
5176 -- a scalar type, then the result is definitely not static,
5177 -- so we can quit now.
5179 if not Compile_Time_Known_Value
(E
)
5180 or else not Is_Scalar_Type
(Etype
(E
))
5182 -- An odd special case, if this is a Pos attribute, this
5183 -- is where we need to apply a range check since it does
5184 -- not get done anywhere else.
5186 if Id
= Attribute_Pos
then
5187 if Is_Integer_Type
(Etype
(E
)) then
5188 Apply_Range_Check
(E
, Etype
(N
));
5195 -- If the expression raises a constraint error, then so does
5196 -- the attribute reference. We keep going in this case because
5197 -- we are still interested in whether the attribute reference
5198 -- is static even if it is not static.
5200 elsif Raises_Constraint_Error
(E
) then
5201 Set_Raises_Constraint_Error
(N
);
5207 if Raises_Constraint_Error
(Prefix
(N
)) then
5212 -- Deal with the case of a static attribute reference that raises
5213 -- constraint error. The Raises_Constraint_Error flag will already
5214 -- have been set, and the Static flag shows whether the attribute
5215 -- reference is static. In any case we certainly can't fold such an
5216 -- attribute reference.
5218 -- Note that the rewriting of the attribute node with the constraint
5219 -- error node is essential in this case, because otherwise Gigi might
5220 -- blow up on one of the attributes it never expects to see.
5222 -- The constraint_error node must have the type imposed by the context,
5223 -- to avoid spurious errors in the enclosing expression.
5225 if Raises_Constraint_Error
(N
) then
5227 Make_Raise_Constraint_Error
(Sloc
(N
),
5228 Reason
=> CE_Range_Check_Failed
);
5229 Set_Etype
(CE_Node
, Etype
(N
));
5230 Set_Raises_Constraint_Error
(CE_Node
);
5232 Rewrite
(N
, Relocate_Node
(CE_Node
));
5233 Set_Is_Static_Expression
(N
, Static
);
5237 -- At this point we have a potentially foldable attribute reference.
5238 -- If Static is set, then the attribute reference definitely obeys
5239 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5240 -- folded. If Static is not set, then the attribute may or may not
5241 -- be foldable, and the individual attribute processing routines
5242 -- test Static as required in cases where it makes a difference.
5244 -- In the case where Static is not set, we do know that all the
5245 -- expressions present are at least known at compile time (we
5246 -- assumed above that if this was not the case, then there was
5247 -- no hope of static evaluation). However, we did not require
5248 -- that the bounds of the prefix type be compile time known,
5249 -- let alone static). That's because there are many attributes
5250 -- that can be computed at compile time on non-static subtypes,
5251 -- even though such references are not static expressions.
5259 when Attribute_Adjacent
=>
5262 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5268 when Attribute_Aft
=>
5269 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5275 when Attribute_Alignment
=> Alignment_Block
: declare
5276 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5279 -- Fold if alignment is set and not otherwise
5281 if Known_Alignment
(P_TypeA
) then
5282 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5284 end Alignment_Block
;
5290 -- Can only be folded in No_Ast_Handler case
5292 when Attribute_AST_Entry
=>
5293 if not Is_AST_Entry
(P_Entity
) then
5295 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5304 -- Bit can never be folded
5306 when Attribute_Bit
=>
5313 -- Body_version can never be static
5315 when Attribute_Body_Version
=>
5322 when Attribute_Ceiling
=>
5324 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5326 --------------------
5327 -- Component_Size --
5328 --------------------
5330 when Attribute_Component_Size
=>
5331 if Known_Static_Component_Size
(P_Type
) then
5332 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5339 when Attribute_Compose
=>
5342 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5349 -- Constrained is never folded for now, there may be cases that
5350 -- could be handled at compile time. to be looked at later.
5352 when Attribute_Constrained
=>
5359 when Attribute_Copy_Sign
=>
5362 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5368 when Attribute_Delta
=>
5369 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5375 when Attribute_Definite
=>
5376 Rewrite
(N
, New_Occurrence_Of
(
5377 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5378 Analyze_And_Resolve
(N
, Standard_Boolean
);
5384 when Attribute_Denorm
=>
5386 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5392 when Attribute_Digits
=>
5393 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5399 when Attribute_Emax
=>
5401 -- Ada 83 attribute is defined as (RM83 3.5.8)
5403 -- T'Emax = 4 * T'Mantissa
5405 Fold_Uint
(N
, 4 * Mantissa
, True);
5411 when Attribute_Enum_Rep
=>
5413 -- For an enumeration type with a non-standard representation use
5414 -- the Enumeration_Rep field of the proper constant. Note that this
5415 -- will not work for types Character/Wide_[Wide-]Character, since no
5416 -- real entities are created for the enumeration literals, but that
5417 -- does not matter since these two types do not have non-standard
5418 -- representations anyway.
5420 if Is_Enumeration_Type
(P_Type
)
5421 and then Has_Non_Standard_Rep
(P_Type
)
5423 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5425 -- For enumeration types with standard representations and all
5426 -- other cases (i.e. all integer and modular types), Enum_Rep
5427 -- is equivalent to Pos.
5430 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5437 when Attribute_Epsilon
=>
5439 -- Ada 83 attribute is defined as (RM83 3.5.8)
5441 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5443 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5449 when Attribute_Exponent
=>
5451 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5457 when Attribute_First
=> First_Attr
:
5461 if Compile_Time_Known_Value
(Lo_Bound
) then
5462 if Is_Real_Type
(P_Type
) then
5463 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5465 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5474 when Attribute_Fixed_Value
=>
5481 when Attribute_Floor
=>
5483 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5489 when Attribute_Fore
=>
5490 if Compile_Time_Known_Bounds
(P_Type
) then
5491 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5498 when Attribute_Fraction
=>
5500 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5502 -----------------------
5503 -- Has_Access_Values --
5504 -----------------------
5506 when Attribute_Has_Access_Values
=>
5507 Rewrite
(N
, New_Occurrence_Of
5508 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5509 Analyze_And_Resolve
(N
, Standard_Boolean
);
5511 -----------------------
5512 -- Has_Discriminants --
5513 -----------------------
5515 when Attribute_Has_Discriminants
=>
5516 Rewrite
(N
, New_Occurrence_Of
(
5517 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5518 Analyze_And_Resolve
(N
, Standard_Boolean
);
5524 when Attribute_Identity
=>
5531 -- Image is a scalar attribute, but is never static, because it is
5532 -- not a static function (having a non-scalar argument (RM 4.9(22))
5533 -- However, we can constant-fold the image of an enumeration literal
5534 -- if names are available.
5536 when Attribute_Image
=>
5537 if Is_Entity_Name
(E1
)
5538 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
5539 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
5540 and then not Global_Discard_Names
5543 Lit
: constant Entity_Id
:= Entity
(E1
);
5547 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
5548 Set_Casing
(All_Upper_Case
);
5549 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
5551 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
5552 Analyze_And_Resolve
(N
, Standard_String
);
5553 Set_Is_Static_Expression
(N
, False);
5561 -- Img is a scalar attribute, but is never static, because it is
5562 -- not a static function (having a non-scalar argument (RM 4.9(22))
5564 when Attribute_Img
=>
5571 when Attribute_Integer_Value
=>
5578 when Attribute_Large
=>
5580 -- For fixed-point, we use the identity:
5582 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5584 if Is_Fixed_Point_Type
(P_Type
) then
5586 Make_Op_Multiply
(Loc
,
5588 Make_Op_Subtract
(Loc
,
5592 Make_Real_Literal
(Loc
, Ureal_2
),
5594 Make_Attribute_Reference
(Loc
,
5596 Attribute_Name
=> Name_Mantissa
)),
5597 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5600 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5602 Analyze_And_Resolve
(N
, C_Type
);
5604 -- Floating-point (Ada 83 compatibility)
5607 -- Ada 83 attribute is defined as (RM83 3.5.8)
5609 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5613 -- T'Emax = 4 * T'Mantissa
5616 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5624 when Attribute_Last
=> Last
:
5628 if Compile_Time_Known_Value
(Hi_Bound
) then
5629 if Is_Real_Type
(P_Type
) then
5630 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5632 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5641 when Attribute_Leading_Part
=>
5643 Eval_Fat
.Leading_Part
5644 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5650 when Attribute_Length
=> Length
: declare
5654 -- In the case of a generic index type, the bounds may
5655 -- appear static but the computation is not meaningful,
5656 -- and may generate a spurious warning.
5658 Ind
:= First_Index
(P_Type
);
5660 while Present
(Ind
) loop
5661 if Is_Generic_Type
(Etype
(Ind
)) then
5670 if Compile_Time_Known_Value
(Lo_Bound
)
5671 and then Compile_Time_Known_Value
(Hi_Bound
)
5674 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
5683 when Attribute_Machine
=>
5686 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
5693 when Attribute_Machine_Emax
=>
5694 Float_Attribute_Universal_Integer
(
5702 AAMPL_Machine_Emax
);
5708 when Attribute_Machine_Emin
=>
5709 Float_Attribute_Universal_Integer
(
5717 AAMPL_Machine_Emin
);
5719 ----------------------
5720 -- Machine_Mantissa --
5721 ----------------------
5723 when Attribute_Machine_Mantissa
=>
5724 Float_Attribute_Universal_Integer
(
5725 IEEES_Machine_Mantissa
,
5726 IEEEL_Machine_Mantissa
,
5727 IEEEX_Machine_Mantissa
,
5728 VAXFF_Machine_Mantissa
,
5729 VAXDF_Machine_Mantissa
,
5730 VAXGF_Machine_Mantissa
,
5731 AAMPS_Machine_Mantissa
,
5732 AAMPL_Machine_Mantissa
);
5734 -----------------------
5735 -- Machine_Overflows --
5736 -----------------------
5738 when Attribute_Machine_Overflows
=>
5740 -- Always true for fixed-point
5742 if Is_Fixed_Point_Type
(P_Type
) then
5743 Fold_Uint
(N
, True_Value
, True);
5745 -- Floating point case
5749 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
5757 when Attribute_Machine_Radix
=>
5758 if Is_Fixed_Point_Type
(P_Type
) then
5759 if Is_Decimal_Fixed_Point_Type
(P_Type
)
5760 and then Machine_Radix_10
(P_Type
)
5762 Fold_Uint
(N
, Uint_10
, True);
5764 Fold_Uint
(N
, Uint_2
, True);
5767 -- All floating-point type always have radix 2
5770 Fold_Uint
(N
, Uint_2
, True);
5773 ----------------------
5774 -- Machine_Rounding --
5775 ----------------------
5777 -- Note: for the folding case, it is fine to treat Machine_Rounding
5778 -- exactly the same way as Rounding, since this is one of the allowed
5779 -- behaviors, and performance is not an issue here. It might be a bit
5780 -- better to give the same result as it would give at run-time, even
5781 -- though the non-determinism is certainly permitted.
5783 when Attribute_Machine_Rounding
=>
5785 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5787 --------------------
5788 -- Machine_Rounds --
5789 --------------------
5791 when Attribute_Machine_Rounds
=>
5793 -- Always False for fixed-point
5795 if Is_Fixed_Point_Type
(P_Type
) then
5796 Fold_Uint
(N
, False_Value
, True);
5798 -- Else yield proper floating-point result
5802 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
5809 -- Note: Machine_Size is identical to Object_Size
5811 when Attribute_Machine_Size
=> Machine_Size
: declare
5812 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5815 if Known_Esize
(P_TypeA
) then
5816 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5824 when Attribute_Mantissa
=>
5826 -- Fixed-point mantissa
5828 if Is_Fixed_Point_Type
(P_Type
) then
5830 -- Compile time foldable case
5832 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5834 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5836 -- The calculation of the obsolete Ada 83 attribute Mantissa
5837 -- is annoying, because of AI00143, quoted here:
5839 -- !question 84-01-10
5841 -- Consider the model numbers for F:
5843 -- type F is delta 1.0 range -7.0 .. 8.0;
5845 -- The wording requires that F'MANTISSA be the SMALLEST
5846 -- integer number for which each bound of the specified
5847 -- range is either a model number or lies at most small
5848 -- distant from a model number. This means F'MANTISSA
5849 -- is required to be 3 since the range -7.0 .. 7.0 fits
5850 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5851 -- number, namely, 7. Is this analysis correct? Note that
5852 -- this implies the upper bound of the range is not
5853 -- represented as a model number.
5855 -- !response 84-03-17
5857 -- The analysis is correct. The upper and lower bounds for
5858 -- a fixed point type can lie outside the range of model
5869 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5870 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5871 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5872 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5874 -- If the Bound is exactly a model number, i.e. a multiple
5875 -- of Small, then we back it off by one to get the integer
5876 -- value that must be representable.
5878 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5879 Max_Man
:= Max_Man
- 1;
5882 -- Now find corresponding size = Mantissa value
5885 while 2 ** Siz
< Max_Man
loop
5889 Fold_Uint
(N
, Siz
, True);
5893 -- The case of dynamic bounds cannot be evaluated at compile
5894 -- time. Instead we use a runtime routine (see Exp_Attr).
5899 -- Floating-point Mantissa
5902 Fold_Uint
(N
, Mantissa
, True);
5909 when Attribute_Max
=> Max
:
5911 if Is_Real_Type
(P_Type
) then
5913 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5915 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5919 ----------------------------------
5920 -- Max_Size_In_Storage_Elements --
5921 ----------------------------------
5923 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5924 -- Storage_Unit boundary. We can fold any cases for which the size
5925 -- is known by the front end.
5927 when Attribute_Max_Size_In_Storage_Elements
=>
5928 if Known_Esize
(P_Type
) then
5930 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5931 System_Storage_Unit
,
5935 --------------------
5936 -- Mechanism_Code --
5937 --------------------
5939 when Attribute_Mechanism_Code
=>
5943 Mech
: Mechanism_Type
;
5947 Mech
:= Mechanism
(P_Entity
);
5950 Val
:= UI_To_Int
(Expr_Value
(E1
));
5952 Formal
:= First_Formal
(P_Entity
);
5953 for J
in 1 .. Val
- 1 loop
5954 Next_Formal
(Formal
);
5956 Mech
:= Mechanism
(Formal
);
5960 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
5968 when Attribute_Min
=> Min
:
5970 if Is_Real_Type
(P_Type
) then
5972 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5975 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5983 when Attribute_Mod
=>
5985 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
5991 when Attribute_Model
=>
5993 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5999 when Attribute_Model_Emin
=>
6000 Float_Attribute_Universal_Integer
(
6014 when Attribute_Model_Epsilon
=>
6015 Float_Attribute_Universal_Real
(
6016 IEEES_Model_Epsilon
'Universal_Literal_String,
6017 IEEEL_Model_Epsilon
'Universal_Literal_String,
6018 IEEEX_Model_Epsilon
'Universal_Literal_String,
6019 VAXFF_Model_Epsilon
'Universal_Literal_String,
6020 VAXDF_Model_Epsilon
'Universal_Literal_String,
6021 VAXGF_Model_Epsilon
'Universal_Literal_String,
6022 AAMPS_Model_Epsilon
'Universal_Literal_String,
6023 AAMPL_Model_Epsilon
'Universal_Literal_String);
6025 --------------------
6026 -- Model_Mantissa --
6027 --------------------
6029 when Attribute_Model_Mantissa
=>
6030 Float_Attribute_Universal_Integer
(
6031 IEEES_Model_Mantissa
,
6032 IEEEL_Model_Mantissa
,
6033 IEEEX_Model_Mantissa
,
6034 VAXFF_Model_Mantissa
,
6035 VAXDF_Model_Mantissa
,
6036 VAXGF_Model_Mantissa
,
6037 AAMPS_Model_Mantissa
,
6038 AAMPL_Model_Mantissa
);
6044 when Attribute_Model_Small
=>
6045 Float_Attribute_Universal_Real
(
6046 IEEES_Model_Small
'Universal_Literal_String,
6047 IEEEL_Model_Small
'Universal_Literal_String,
6048 IEEEX_Model_Small
'Universal_Literal_String,
6049 VAXFF_Model_Small
'Universal_Literal_String,
6050 VAXDF_Model_Small
'Universal_Literal_String,
6051 VAXGF_Model_Small
'Universal_Literal_String,
6052 AAMPS_Model_Small
'Universal_Literal_String,
6053 AAMPL_Model_Small
'Universal_Literal_String);
6059 when Attribute_Modulus
=>
6060 Fold_Uint
(N
, Modulus
(P_Type
), True);
6062 --------------------
6063 -- Null_Parameter --
6064 --------------------
6066 -- Cannot fold, we know the value sort of, but the whole point is
6067 -- that there is no way to talk about this imaginary value except
6068 -- by using the attribute, so we leave it the way it is.
6070 when Attribute_Null_Parameter
=>
6077 -- The Object_Size attribute for a type returns the Esize of the
6078 -- type and can be folded if this value is known.
6080 when Attribute_Object_Size
=> Object_Size
: declare
6081 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6084 if Known_Esize
(P_TypeA
) then
6085 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6089 -------------------------
6090 -- Passed_By_Reference --
6091 -------------------------
6093 -- Scalar types are never passed by reference
6095 when Attribute_Passed_By_Reference
=>
6096 Fold_Uint
(N
, False_Value
, True);
6102 when Attribute_Pos
=>
6103 Fold_Uint
(N
, Expr_Value
(E1
), True);
6109 when Attribute_Pred
=> Pred
:
6111 -- Floating-point case
6113 if Is_Floating_Point_Type
(P_Type
) then
6115 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6119 elsif Is_Fixed_Point_Type
(P_Type
) then
6121 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
6123 -- Modular integer case (wraps)
6125 elsif Is_Modular_Integer_Type
(P_Type
) then
6126 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
6128 -- Other scalar cases
6131 pragma Assert
(Is_Scalar_Type
(P_Type
));
6133 if Is_Enumeration_Type
(P_Type
)
6134 and then Expr_Value
(E1
) =
6135 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6137 Apply_Compile_Time_Constraint_Error
6138 (N
, "Pred of `&''First`",
6139 CE_Overflow_Check_Failed
,
6141 Warn
=> not Static
);
6147 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
6155 -- No processing required, because by this stage, Range has been
6156 -- replaced by First .. Last, so this branch can never be taken.
6158 when Attribute_Range
=>
6159 raise Program_Error
;
6165 when Attribute_Range_Length
=>
6168 if Compile_Time_Known_Value
(Hi_Bound
)
6169 and then Compile_Time_Known_Value
(Lo_Bound
)
6173 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
6181 when Attribute_Remainder
=> Remainder
: declare
6182 X
: constant Ureal
:= Expr_Value_R
(E1
);
6183 Y
: constant Ureal
:= Expr_Value_R
(E2
);
6186 if UR_Is_Zero
(Y
) then
6187 Apply_Compile_Time_Constraint_Error
6188 (N
, "division by zero in Remainder",
6189 CE_Overflow_Check_Failed
,
6190 Warn
=> not Static
);
6196 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
6203 when Attribute_Round
=> Round
:
6209 -- First we get the (exact result) in units of small
6211 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
6213 -- Now round that exactly to an integer
6215 Si
:= UR_To_Uint
(Sr
);
6217 -- Finally the result is obtained by converting back to real
6219 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
6226 when Attribute_Rounding
=>
6228 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6234 when Attribute_Safe_Emax
=>
6235 Float_Attribute_Universal_Integer
(
6249 when Attribute_Safe_First
=>
6250 Float_Attribute_Universal_Real
(
6251 IEEES_Safe_First
'Universal_Literal_String,
6252 IEEEL_Safe_First
'Universal_Literal_String,
6253 IEEEX_Safe_First
'Universal_Literal_String,
6254 VAXFF_Safe_First
'Universal_Literal_String,
6255 VAXDF_Safe_First
'Universal_Literal_String,
6256 VAXGF_Safe_First
'Universal_Literal_String,
6257 AAMPS_Safe_First
'Universal_Literal_String,
6258 AAMPL_Safe_First
'Universal_Literal_String);
6264 when Attribute_Safe_Large
=>
6265 if Is_Fixed_Point_Type
(P_Type
) then
6267 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
6269 Float_Attribute_Universal_Real
(
6270 IEEES_Safe_Large
'Universal_Literal_String,
6271 IEEEL_Safe_Large
'Universal_Literal_String,
6272 IEEEX_Safe_Large
'Universal_Literal_String,
6273 VAXFF_Safe_Large
'Universal_Literal_String,
6274 VAXDF_Safe_Large
'Universal_Literal_String,
6275 VAXGF_Safe_Large
'Universal_Literal_String,
6276 AAMPS_Safe_Large
'Universal_Literal_String,
6277 AAMPL_Safe_Large
'Universal_Literal_String);
6284 when Attribute_Safe_Last
=>
6285 Float_Attribute_Universal_Real
(
6286 IEEES_Safe_Last
'Universal_Literal_String,
6287 IEEEL_Safe_Last
'Universal_Literal_String,
6288 IEEEX_Safe_Last
'Universal_Literal_String,
6289 VAXFF_Safe_Last
'Universal_Literal_String,
6290 VAXDF_Safe_Last
'Universal_Literal_String,
6291 VAXGF_Safe_Last
'Universal_Literal_String,
6292 AAMPS_Safe_Last
'Universal_Literal_String,
6293 AAMPL_Safe_Last
'Universal_Literal_String);
6299 when Attribute_Safe_Small
=>
6301 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6302 -- for fixed-point, since is the same as Small, but we implement
6303 -- it for backwards compatibility.
6305 if Is_Fixed_Point_Type
(P_Type
) then
6306 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6308 -- Ada 83 Safe_Small for floating-point cases
6311 Float_Attribute_Universal_Real
(
6312 IEEES_Safe_Small
'Universal_Literal_String,
6313 IEEEL_Safe_Small
'Universal_Literal_String,
6314 IEEEX_Safe_Small
'Universal_Literal_String,
6315 VAXFF_Safe_Small
'Universal_Literal_String,
6316 VAXDF_Safe_Small
'Universal_Literal_String,
6317 VAXGF_Safe_Small
'Universal_Literal_String,
6318 AAMPS_Safe_Small
'Universal_Literal_String,
6319 AAMPL_Safe_Small
'Universal_Literal_String);
6326 when Attribute_Scale
=>
6327 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6333 when Attribute_Scaling
=>
6336 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6342 when Attribute_Signed_Zeros
=>
6344 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6350 -- Size attribute returns the RM size. All scalar types can be folded,
6351 -- as well as any types for which the size is known by the front end,
6352 -- including any type for which a size attribute is specified.
6354 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6355 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6358 if RM_Size
(P_TypeA
) /= Uint_0
then
6362 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6364 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6367 -- If a size clause applies, then use the size from it.
6368 -- This is one of the rare cases where we can use the
6369 -- Size_Clause field for a subtype when Has_Size_Clause
6370 -- is False. Consider:
6372 -- type x is range 1 .. 64;
6373 -- for x'size use 12;
6374 -- subtype y is x range 0 .. 3;
6376 -- Here y has a size clause inherited from x, but normally
6377 -- it does not apply, and y'size is 2. However, y'VADS_Size
6378 -- is indeed 12 and not 2.
6381 and then Is_OK_Static_Expression
(Expression
(S
))
6383 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6385 -- If no size is specified, then we simply use the object
6386 -- size in the VADS_Size case (e.g. Natural'Size is equal
6387 -- to Integer'Size, not one less).
6390 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6394 -- Normal case (Size) in which case we want the RM_Size
6399 Static
and then Is_Discrete_Type
(P_TypeA
));
6408 when Attribute_Small
=>
6410 -- The floating-point case is present only for Ada 83 compatability.
6411 -- Note that strictly this is an illegal addition, since we are
6412 -- extending an Ada 95 defined attribute, but we anticipate an
6413 -- ARG ruling that will permit this.
6415 if Is_Floating_Point_Type
(P_Type
) then
6417 -- Ada 83 attribute is defined as (RM83 3.5.8)
6419 -- T'Small = 2.0**(-T'Emax - 1)
6423 -- T'Emax = 4 * T'Mantissa
6425 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6427 -- Normal Ada 95 fixed-point case
6430 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6437 when Attribute_Stream_Size
=>
6444 when Attribute_Succ
=> Succ
:
6446 -- Floating-point case
6448 if Is_Floating_Point_Type
(P_Type
) then
6450 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6454 elsif Is_Fixed_Point_Type
(P_Type
) then
6456 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6458 -- Modular integer case (wraps)
6460 elsif Is_Modular_Integer_Type
(P_Type
) then
6461 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6463 -- Other scalar cases
6466 pragma Assert
(Is_Scalar_Type
(P_Type
));
6468 if Is_Enumeration_Type
(P_Type
)
6469 and then Expr_Value
(E1
) =
6470 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6472 Apply_Compile_Time_Constraint_Error
6473 (N
, "Succ of `&''Last`",
6474 CE_Overflow_Check_Failed
,
6476 Warn
=> not Static
);
6481 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6490 when Attribute_Truncation
=>
6492 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6498 when Attribute_Type_Class
=> Type_Class
: declare
6499 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6503 if Is_Descendent_Of_Address
(Typ
) then
6504 Id
:= RE_Type_Class_Address
;
6506 elsif Is_Enumeration_Type
(Typ
) then
6507 Id
:= RE_Type_Class_Enumeration
;
6509 elsif Is_Integer_Type
(Typ
) then
6510 Id
:= RE_Type_Class_Integer
;
6512 elsif Is_Fixed_Point_Type
(Typ
) then
6513 Id
:= RE_Type_Class_Fixed_Point
;
6515 elsif Is_Floating_Point_Type
(Typ
) then
6516 Id
:= RE_Type_Class_Floating_Point
;
6518 elsif Is_Array_Type
(Typ
) then
6519 Id
:= RE_Type_Class_Array
;
6521 elsif Is_Record_Type
(Typ
) then
6522 Id
:= RE_Type_Class_Record
;
6524 elsif Is_Access_Type
(Typ
) then
6525 Id
:= RE_Type_Class_Access
;
6527 elsif Is_Enumeration_Type
(Typ
) then
6528 Id
:= RE_Type_Class_Enumeration
;
6530 elsif Is_Task_Type
(Typ
) then
6531 Id
:= RE_Type_Class_Task
;
6533 -- We treat protected types like task types. It would make more
6534 -- sense to have another enumeration value, but after all the
6535 -- whole point of this feature is to be exactly DEC compatible,
6536 -- and changing the type Type_Clas would not meet this requirement.
6538 elsif Is_Protected_Type
(Typ
) then
6539 Id
:= RE_Type_Class_Task
;
6541 -- Not clear if there are any other possibilities, but if there
6542 -- are, then we will treat them as the address case.
6545 Id
:= RE_Type_Class_Address
;
6548 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6551 -----------------------
6552 -- Unbiased_Rounding --
6553 -----------------------
6555 when Attribute_Unbiased_Rounding
=>
6557 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
6560 -------------------------
6561 -- Unconstrained_Array --
6562 -------------------------
6564 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
6565 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6568 Rewrite
(N
, New_Occurrence_Of
(
6570 Is_Array_Type
(P_Type
)
6571 and then not Is_Constrained
(Typ
)), Loc
));
6573 -- Analyze and resolve as boolean, note that this attribute is
6574 -- a static attribute in GNAT.
6576 Analyze_And_Resolve
(N
, Standard_Boolean
);
6578 end Unconstrained_Array
;
6584 -- Processing is shared with Size
6590 when Attribute_Val
=> Val
:
6592 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6594 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
6596 Apply_Compile_Time_Constraint_Error
6597 (N
, "Val expression out of range",
6598 CE_Range_Check_Failed
,
6599 Warn
=> not Static
);
6605 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6613 -- The Value_Size attribute for a type returns the RM size of the
6614 -- type. This an always be folded for scalar types, and can also
6615 -- be folded for non-scalar types if the size is set.
6617 when Attribute_Value_Size
=> Value_Size
: declare
6618 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6620 if RM_Size
(P_TypeA
) /= Uint_0
then
6621 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6629 -- Version can never be static
6631 when Attribute_Version
=>
6638 -- Wide_Image is a scalar attribute, but is never static, because it
6639 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6641 when Attribute_Wide_Image
=>
6644 ---------------------
6645 -- Wide_Wide_Image --
6646 ---------------------
6648 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6649 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6651 when Attribute_Wide_Wide_Image
=>
6654 ---------------------
6655 -- Wide_Wide_Width --
6656 ---------------------
6658 -- Processing for Wide_Wide_Width is combined with Width
6664 -- Processing for Wide_Width is combined with Width
6670 -- This processing also handles the case of Wide_[Wide_]Width
6672 when Attribute_Width |
6673 Attribute_Wide_Width |
6674 Attribute_Wide_Wide_Width
=> Width
:
6676 if Compile_Time_Known_Bounds
(P_Type
) then
6678 -- Floating-point types
6680 if Is_Floating_Point_Type
(P_Type
) then
6682 -- Width is zero for a null range (RM 3.5 (38))
6684 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
6685 Expr_Value_R
(Type_Low_Bound
(P_Type
))
6687 Fold_Uint
(N
, Uint_0
, True);
6690 -- For floating-point, we have +N.dddE+nnn where length
6691 -- of ddd is determined by type'Digits - 1, but is one
6692 -- if Digits is one (RM 3.5 (33)).
6694 -- nnn is set to 2 for Short_Float and Float (32 bit
6695 -- floats), and 3 for Long_Float and Long_Long_Float.
6696 -- For machines where Long_Long_Float is the IEEE
6697 -- extended precision type, the exponent takes 4 digits.
6701 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
6704 if Esize
(P_Type
) <= 32 then
6706 elsif Esize
(P_Type
) = 64 then
6712 Fold_Uint
(N
, UI_From_Int
(Len
), True);
6716 -- Fixed-point types
6718 elsif Is_Fixed_Point_Type
(P_Type
) then
6720 -- Width is zero for a null range (RM 3.5 (38))
6722 if Expr_Value
(Type_High_Bound
(P_Type
)) <
6723 Expr_Value
(Type_Low_Bound
(P_Type
))
6725 Fold_Uint
(N
, Uint_0
, True);
6727 -- The non-null case depends on the specific real type
6730 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6733 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
6740 R
: constant Entity_Id
:= Root_Type
(P_Type
);
6741 Lo
: constant Uint
:=
6742 Expr_Value
(Type_Low_Bound
(P_Type
));
6743 Hi
: constant Uint
:=
6744 Expr_Value
(Type_High_Bound
(P_Type
));
6757 -- Width for types derived from Standard.Character
6758 -- and Standard.Wide_[Wide_]Character.
6760 elsif R
= Standard_Character
6761 or else R
= Standard_Wide_Character
6762 or else R
= Standard_Wide_Wide_Character
6766 -- Set W larger if needed
6768 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
6770 -- All wide characters look like Hex_hhhhhhhh
6776 C
:= Character'Val (J
);
6778 -- Test for all cases where Character'Image
6779 -- yields an image that is longer than three
6780 -- characters. First the cases of Reserved_xxx
6781 -- names (length = 12).
6784 when Reserved_128 | Reserved_129 |
6785 Reserved_132 | Reserved_153
6789 when BS | HT | LF | VT | FF | CR |
6790 SO | SI | EM | FS | GS | RS |
6791 US | RI | MW | ST | PM
6795 when NUL | SOH | STX | ETX | EOT |
6796 ENQ | ACK | BEL | DLE | DC1 |
6797 DC2 | DC3 | DC4 | NAK | SYN |
6798 ETB | CAN | SUB | ESC | DEL |
6799 BPH | NBH | NEL | SSA | ESA |
6800 HTS | HTJ | VTS | PLD | PLU |
6801 SS2 | SS3 | DCS | PU1 | PU2 |
6802 STS | CCH | SPA | EPA | SOS |
6803 SCI | CSI | OSC | APC
6807 when Space
.. Tilde |
6808 No_Break_Space
.. LC_Y_Diaeresis
6813 W
:= Int
'Max (W
, Wt
);
6817 -- Width for types derived from Standard.Boolean
6819 elsif R
= Standard_Boolean
then
6826 -- Width for integer types
6828 elsif Is_Integer_Type
(P_Type
) then
6829 T
:= UI_Max
(abs Lo
, abs Hi
);
6837 -- Only remaining possibility is user declared enum type
6840 pragma Assert
(Is_Enumeration_Type
(P_Type
));
6843 L
:= First_Literal
(P_Type
);
6845 while Present
(L
) loop
6847 -- Only pay attention to in range characters
6849 if Lo
<= Enumeration_Pos
(L
)
6850 and then Enumeration_Pos
(L
) <= Hi
6852 -- For Width case, use decoded name
6854 if Id
= Attribute_Width
then
6855 Get_Decoded_Name_String
(Chars
(L
));
6856 Wt
:= Nat
(Name_Len
);
6858 -- For Wide_[Wide_]Width, use encoded name, and
6859 -- then adjust for the encoding.
6862 Get_Name_String
(Chars
(L
));
6864 -- Character literals are always of length 3
6866 if Name_Buffer
(1) = 'Q' then
6869 -- Otherwise loop to adjust for upper/wide chars
6872 Wt
:= Nat
(Name_Len
);
6874 for J
in 1 .. Name_Len
loop
6875 if Name_Buffer
(J
) = 'U' then
6877 elsif Name_Buffer
(J
) = 'W' then
6884 W
:= Int
'Max (W
, Wt
);
6891 Fold_Uint
(N
, UI_From_Int
(W
), True);
6897 -- The following attributes can never be folded, and furthermore we
6898 -- should not even have entered the case statement for any of these.
6899 -- Note that in some cases, the values have already been folded as
6900 -- a result of the processing in Analyze_Attribute.
6902 when Attribute_Abort_Signal |
6905 Attribute_Address_Size |
6906 Attribute_Asm_Input |
6907 Attribute_Asm_Output |
6909 Attribute_Bit_Order |
6910 Attribute_Bit_Position |
6911 Attribute_Callable |
6914 Attribute_Code_Address |
6916 Attribute_Default_Bit_Order |
6917 Attribute_Elaborated |
6918 Attribute_Elab_Body |
6919 Attribute_Elab_Spec |
6921 Attribute_External_Tag |
6922 Attribute_Fast_Math |
6923 Attribute_First_Bit |
6925 Attribute_Last_Bit |
6926 Attribute_Maximum_Alignment |
6928 Attribute_Partition_ID |
6929 Attribute_Pool_Address |
6930 Attribute_Position |
6931 Attribute_Priority |
6933 Attribute_Storage_Pool |
6934 Attribute_Storage_Size |
6935 Attribute_Storage_Unit |
6936 Attribute_Stub_Type |
6938 Attribute_Target_Name |
6939 Attribute_Terminated |
6940 Attribute_To_Address |
6941 Attribute_UET_Address |
6942 Attribute_Unchecked_Access |
6943 Attribute_Universal_Literal_String |
6944 Attribute_Unrestricted_Access |
6947 Attribute_Wchar_T_Size |
6948 Attribute_Wide_Value |
6949 Attribute_Wide_Wide_Value |
6950 Attribute_Word_Size |
6953 raise Program_Error
;
6956 -- At the end of the case, one more check. If we did a static evaluation
6957 -- so that the result is now a literal, then set Is_Static_Expression
6958 -- in the constant only if the prefix type is a static subtype. For
6959 -- non-static subtypes, the folding is still OK, but not static.
6961 -- An exception is the GNAT attribute Constrained_Array which is
6962 -- defined to be a static attribute in all cases.
6964 if Nkind
(N
) = N_Integer_Literal
6965 or else Nkind
(N
) = N_Real_Literal
6966 or else Nkind
(N
) = N_Character_Literal
6967 or else Nkind
(N
) = N_String_Literal
6968 or else (Is_Entity_Name
(N
)
6969 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6971 Set_Is_Static_Expression
(N
, Static
);
6973 -- If this is still an attribute reference, then it has not been folded
6974 -- and that means that its expressions are in a non-static context.
6976 elsif Nkind
(N
) = N_Attribute_Reference
then
6979 -- Note: the else case not covered here are odd cases where the
6980 -- processing has transformed the attribute into something other
6981 -- than a constant. Nothing more to do in such cases.
6988 ------------------------------
6989 -- Is_Anonymous_Tagged_Base --
6990 ------------------------------
6992 function Is_Anonymous_Tagged_Base
6999 Anon
= Current_Scope
7000 and then Is_Itype
(Anon
)
7001 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
7002 end Is_Anonymous_Tagged_Base
;
7004 --------------------------------
7005 -- Name_Implies_Lvalue_Prefix --
7006 --------------------------------
7008 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
7009 pragma Assert
(Is_Attribute_Name
(Nam
));
7011 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
7012 end Name_Implies_Lvalue_Prefix
;
7014 -----------------------
7015 -- Resolve_Attribute --
7016 -----------------------
7018 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
7019 Loc
: constant Source_Ptr
:= Sloc
(N
);
7020 P
: constant Node_Id
:= Prefix
(N
);
7021 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7022 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7023 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7024 Des_Btyp
: Entity_Id
;
7025 Index
: Interp_Index
;
7027 Nom_Subt
: Entity_Id
;
7029 procedure Accessibility_Message
;
7030 -- Error, or warning within an instance, if the static accessibility
7031 -- rules of 3.10.2 are violated.
7033 ---------------------------
7034 -- Accessibility_Message --
7035 ---------------------------
7037 procedure Accessibility_Message
is
7038 Indic
: Node_Id
:= Parent
(Parent
(N
));
7041 -- In an instance, this is a runtime check, but one we
7042 -- know will fail, so generate an appropriate warning.
7044 if In_Instance_Body
then
7046 ("?non-local pointer cannot point to local object", P
);
7048 ("\?Program_Error will be raised at run time", P
);
7050 Make_Raise_Program_Error
(Loc
,
7051 Reason
=> PE_Accessibility_Check_Failed
));
7057 ("non-local pointer cannot point to local object", P
);
7059 -- Check for case where we have a missing access definition
7061 if Is_Record_Type
(Current_Scope
)
7063 (Nkind
(Parent
(N
)) = N_Discriminant_Association
7065 Nkind
(Parent
(N
)) = N_Index_Or_Discriminant_Constraint
)
7067 Indic
:= Parent
(Parent
(N
));
7068 while Present
(Indic
)
7069 and then Nkind
(Indic
) /= N_Subtype_Indication
7071 Indic
:= Parent
(Indic
);
7074 if Present
(Indic
) then
7076 ("\use an access definition for" &
7077 " the access discriminant of&",
7078 N
, Entity
(Subtype_Mark
(Indic
)));
7082 end Accessibility_Message
;
7084 -- Start of processing for Resolve_Attribute
7087 -- If error during analysis, no point in continuing, except for
7088 -- array types, where we get better recovery by using unconstrained
7089 -- indices than nothing at all (see Check_Array_Type).
7092 and then Attr_Id
/= Attribute_First
7093 and then Attr_Id
/= Attribute_Last
7094 and then Attr_Id
/= Attribute_Length
7095 and then Attr_Id
/= Attribute_Range
7100 -- If attribute was universal type, reset to actual type
7102 if Etype
(N
) = Universal_Integer
7103 or else Etype
(N
) = Universal_Real
7108 -- Remaining processing depends on attribute
7116 -- For access attributes, if the prefix denotes an entity, it is
7117 -- interpreted as a name, never as a call. It may be overloaded,
7118 -- in which case resolution uses the profile of the context type.
7119 -- Otherwise prefix must be resolved.
7121 when Attribute_Access
7122 | Attribute_Unchecked_Access
7123 | Attribute_Unrestricted_Access
=>
7125 Access_Attribute
: begin
7126 if Is_Variable
(P
) then
7127 Note_Possible_Modification
(P
);
7130 if Is_Entity_Name
(P
) then
7131 if Is_Overloaded
(P
) then
7132 Get_First_Interp
(P
, Index
, It
);
7133 while Present
(It
.Nam
) loop
7134 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
7135 Set_Entity
(P
, It
.Nam
);
7137 -- The prefix is definitely NOT overloaded anymore at
7138 -- this point, so we reset the Is_Overloaded flag to
7139 -- avoid any confusion when reanalyzing the node.
7141 Set_Is_Overloaded
(P
, False);
7142 Set_Is_Overloaded
(N
, False);
7143 Generate_Reference
(Entity
(P
), P
);
7147 Get_Next_Interp
(Index
, It
);
7150 -- If Prefix is a subprogram name, it is frozen by this
7153 -- If it is a type, there is nothing to resolve.
7154 -- If it is an object, complete its resolution.
7156 elsif Is_Overloadable
(Entity
(P
)) then
7157 if not In_Default_Expression
then
7158 Insert_Actions
(N
, Freeze_Entity
(Entity
(P
), Loc
));
7161 elsif Is_Type
(Entity
(P
)) then
7167 Error_Msg_Name_1
:= Aname
;
7169 if not Is_Entity_Name
(P
) then
7172 elsif Is_Overloadable
(Entity
(P
))
7173 and then Is_Abstract_Subprogram
(Entity
(P
))
7175 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
7176 Set_Etype
(N
, Any_Type
);
7178 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
7179 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
7181 ("prefix of % attribute cannot be enumeration literal",
7185 ("prefix of % attribute cannot be intrinsic", P
);
7188 Set_Etype
(N
, Any_Type
);
7191 -- Assignments, return statements, components of aggregates,
7192 -- generic instantiations will require convention checks if
7193 -- the type is an access to subprogram. Given that there will
7194 -- also be accessibility checks on those, this is where the
7195 -- checks can eventually be centralized ???
7197 if Ekind
(Btyp
) = E_Access_Subprogram_Type
7199 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7201 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7203 -- Deal with convention mismatch
7205 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
7207 ("subprogram & has wrong convention", P
, Entity
(P
));
7210 ("\does not match convention of access type &",
7213 if not Has_Convention_Pragma
(Btyp
) then
7215 ("\probable missing pragma Convention for &",
7220 Check_Subtype_Conformant
7221 (New_Id
=> Entity
(P
),
7222 Old_Id
=> Designated_Type
(Btyp
),
7226 if Attr_Id
= Attribute_Unchecked_Access
then
7227 Error_Msg_Name_1
:= Aname
;
7229 ("attribute% cannot be applied to a subprogram", P
);
7231 elsif Aname
= Name_Unrestricted_Access
then
7232 null; -- Nothing to check
7234 -- Check the static accessibility rule of 3.10.2(32).
7235 -- This rule also applies within the private part of an
7236 -- instantiation. This rule does not apply to anonymous
7237 -- access-to-subprogram types (Ada 2005).
7239 elsif Attr_Id
= Attribute_Access
7240 and then not In_Instance_Body
7241 and then Subprogram_Access_Level
(Entity
(P
)) >
7242 Type_Access_Level
(Btyp
)
7243 and then Ekind
(Btyp
) /=
7244 E_Anonymous_Access_Subprogram_Type
7245 and then Ekind
(Btyp
) /=
7246 E_Anonymous_Access_Protected_Subprogram_Type
7249 ("subprogram must not be deeper than access type", P
);
7251 -- Check the restriction of 3.10.2(32) that disallows the
7252 -- access attribute within a generic body when the ultimate
7253 -- ancestor of the type of the attribute is declared outside
7254 -- of the generic unit and the subprogram is declared within
7255 -- that generic unit. This includes any such attribute that
7256 -- occurs within the body of a generic unit that is a child
7257 -- of the generic unit where the subprogram is declared.
7258 -- The rule also prohibits applying the attibute when the
7259 -- access type is a generic formal access type (since the
7260 -- level of the actual type is not known). This restriction
7261 -- does not apply when the attribute type is an anonymous
7262 -- access-to-subprogram type. Note that this check was
7263 -- revised by AI-229, because the originally Ada 95 rule
7264 -- was too lax. The original rule only applied when the
7265 -- subprogram was declared within the body of the generic,
7266 -- which allowed the possibility of dangling references).
7267 -- The rule was also too strict in some case, in that it
7268 -- didn't permit the access to be declared in the generic
7269 -- spec, whereas the revised rule does (as long as it's not
7272 -- There are a couple of subtleties of the test for applying
7273 -- the check that are worth noting. First, we only apply it
7274 -- when the levels of the subprogram and access type are the
7275 -- same (the case where the subprogram is statically deeper
7276 -- was applied above, and the case where the type is deeper
7277 -- is always safe). Second, we want the check to apply
7278 -- within nested generic bodies and generic child unit
7279 -- bodies, but not to apply to an attribute that appears in
7280 -- the generic unit's specification. This is done by testing
7281 -- that the attribute's innermost enclosing generic body is
7282 -- not the same as the innermost generic body enclosing the
7283 -- generic unit where the subprogram is declared (we don't
7284 -- want the check to apply when the access attribute is in
7285 -- the spec and there's some other generic body enclosing
7286 -- generic). Finally, there's no point applying the check
7287 -- when within an instance, because any violations will have
7288 -- been caught by the compilation of the generic unit.
7290 elsif Attr_Id
= Attribute_Access
7291 and then not In_Instance
7292 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
7293 and then Present
(Enclosing_Generic_Body
(N
))
7294 and then Enclosing_Generic_Body
(N
) /=
7295 Enclosing_Generic_Body
7296 (Enclosing_Generic_Unit
(Entity
(P
)))
7297 and then Subprogram_Access_Level
(Entity
(P
)) =
7298 Type_Access_Level
(Btyp
)
7299 and then Ekind
(Btyp
) /=
7300 E_Anonymous_Access_Subprogram_Type
7301 and then Ekind
(Btyp
) /=
7302 E_Anonymous_Access_Protected_Subprogram_Type
7304 -- The attribute type's ultimate ancestor must be
7305 -- declared within the same generic unit as the
7306 -- subprogram is declared. The error message is
7307 -- specialized to say "ancestor" for the case where
7308 -- the access type is not its own ancestor, since
7309 -- saying simply "access type" would be very confusing.
7311 if Enclosing_Generic_Unit
(Entity
(P
)) /=
7312 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
7315 ("''Access attribute not allowed in generic body",
7318 if Root_Type
(Btyp
) = Btyp
then
7321 "access type & is declared outside " &
7322 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7325 ("\because ancestor of " &
7326 "access type & is declared outside " &
7327 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7331 ("\move ''Access to private part, or " &
7332 "(Ada 2005) use anonymous access type instead of &",
7335 -- If the ultimate ancestor of the attribute's type is
7336 -- a formal type, then the attribute is illegal because
7337 -- the actual type might be declared at a higher level.
7338 -- The error message is specialized to say "ancestor"
7339 -- for the case where the access type is not its own
7340 -- ancestor, since saying simply "access type" would be
7343 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
7344 if Root_Type
(Btyp
) = Btyp
then
7346 ("access type must not be a generic formal type",
7350 ("ancestor access type must not be a generic " &
7357 -- If this is a renaming, an inherited operation, or a
7358 -- subprogram instance, use the original entity. This may make
7359 -- the node type-inconsistent, so this transformation can only
7360 -- be done if the node will not be reanalyzed. In particular,
7361 -- if it is within a default expression, the transformation
7362 -- must be delayed until the default subprogram is created for
7363 -- it, when the enclosing subprogram is frozen.
7365 if Is_Entity_Name
(P
)
7366 and then Is_Overloadable
(Entity
(P
))
7367 and then Present
(Alias
(Entity
(P
)))
7368 and then Expander_Active
7371 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7374 elsif Nkind
(P
) = N_Selected_Component
7375 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
7377 -- Protected operation. If operation is overloaded, must
7378 -- disambiguate. Prefix that denotes protected object itself
7379 -- is resolved with its own type.
7381 if Attr_Id
= Attribute_Unchecked_Access
then
7382 Error_Msg_Name_1
:= Aname
;
7384 ("attribute% cannot be applied to protected operation", P
);
7387 Resolve
(Prefix
(P
));
7388 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
7390 elsif Is_Overloaded
(P
) then
7392 -- Use the designated type of the context to disambiguate
7393 -- Note that this was not strictly conformant to Ada 95,
7394 -- but was the implementation adopted by most Ada 95 compilers.
7395 -- The use of the context type to resolve an Access attribute
7396 -- reference is now mandated in AI-235 for Ada 2005.
7399 Index
: Interp_Index
;
7403 Get_First_Interp
(P
, Index
, It
);
7404 while Present
(It
.Typ
) loop
7405 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
7406 Resolve
(P
, It
.Typ
);
7410 Get_Next_Interp
(Index
, It
);
7417 -- X'Access is illegal if X denotes a constant and the access type
7418 -- is access-to-variable. Same for 'Unchecked_Access. The rule
7419 -- does not apply to 'Unrestricted_Access. If the reference is a
7420 -- default-initialized aggregate component for a self-referential
7421 -- type the reference is legal.
7423 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7424 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7425 or else (Is_Record_Type
(Btyp
)
7427 Present
(Corresponding_Remote_Type
(Btyp
)))
7428 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7429 or else Ekind
(Btyp
)
7430 = E_Anonymous_Access_Protected_Subprogram_Type
7431 or else Is_Access_Constant
(Btyp
)
7432 or else Is_Variable
(P
)
7433 or else Attr_Id
= Attribute_Unrestricted_Access
)
7435 if Is_Entity_Name
(P
)
7436 and then Is_Type
(Entity
(P
))
7438 -- Legality of a self-reference through an access
7439 -- attribute has been verified in Analyze_Access_Attribute.
7443 elsif Comes_From_Source
(N
) then
7444 Error_Msg_F
("access-to-variable designates constant", P
);
7448 Des_Btyp
:= Designated_Type
(Btyp
);
7450 if Ada_Version
>= Ada_05
7451 and then Is_Incomplete_Type
(Des_Btyp
)
7453 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
7454 -- imported entity, and the non-limited view is visible, make
7455 -- use of it. If it is an incomplete subtype, use the base type
7458 if From_With_Type
(Des_Btyp
)
7459 and then Present
(Non_Limited_View
(Des_Btyp
))
7461 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
7463 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
7464 Des_Btyp
:= Etype
(Des_Btyp
);
7468 if (Attr_Id
= Attribute_Access
7470 Attr_Id
= Attribute_Unchecked_Access
)
7471 and then (Ekind
(Btyp
) = E_General_Access_Type
7472 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7474 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7475 -- access types for stand-alone objects, record and array
7476 -- components, and return objects. For a component definition
7477 -- the level is the same of the enclosing composite type.
7479 if Ada_Version
>= Ada_05
7480 and then Is_Local_Anonymous_Access
(Btyp
)
7481 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7482 and then Attr_Id
= Attribute_Access
7484 -- In an instance, this is a runtime check, but one we
7485 -- know will fail, so generate an appropriate warning.
7487 if In_Instance_Body
then
7489 ("?non-local pointer cannot point to local object", P
);
7491 ("\?Program_Error will be raised at run time", P
);
7493 Make_Raise_Program_Error
(Loc
,
7494 Reason
=> PE_Accessibility_Check_Failed
));
7499 ("non-local pointer cannot point to local object", P
);
7503 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7505 ("illegal attribute for discriminant-dependent component",
7509 -- Check static matching rule of 3.10.2(27). Nominal subtype
7510 -- of the prefix must statically match the designated type.
7512 Nom_Subt
:= Etype
(P
);
7514 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7515 Nom_Subt
:= Base_Type
(Nom_Subt
);
7518 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7520 -- If the attribute is in the context of an access
7521 -- parameter, then the prefix is allowed to be of the
7522 -- class-wide type (by AI-127).
7524 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7525 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7526 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7532 Desig
:= Designated_Type
(Typ
);
7534 if Is_Class_Wide_Type
(Desig
) then
7535 Desig
:= Etype
(Desig
);
7538 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
7543 ("type of prefix: & not compatible",
7546 ("\with &, the expected designated type",
7547 P
, Designated_Type
(Typ
));
7552 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7554 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
7555 and then Is_Class_Wide_Type
(Nom_Subt
))
7558 ("type of prefix: & is not covered", P
, Nom_Subt
);
7560 ("\by &, the expected designated type" &
7561 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
7564 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
7565 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
7566 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
7567 and then Designated_Type
(Typ
) /= Nom_Subt
7569 Apply_Discriminant_Check
7570 (N
, Etype
(Designated_Type
(Typ
)));
7573 -- Ada 2005 (AI-363): Require static matching when designated
7574 -- type has discriminants and a constrained partial view, since
7575 -- in general objects of such types are mutable, so we can't
7576 -- allow the access value to designate a constrained object
7577 -- (because access values must be assumed to designate mutable
7578 -- objects when designated type does not impose a constraint).
7580 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
7583 elsif Has_Discriminants
(Designated_Type
(Typ
))
7584 and then not Is_Constrained
(Des_Btyp
)
7586 (Ada_Version
< Ada_05
7588 not Has_Constrained_Partial_View
7589 (Designated_Type
(Base_Type
(Typ
))))
7595 ("object subtype must statically match "
7596 & "designated subtype", P
);
7598 if Is_Entity_Name
(P
)
7599 and then Is_Array_Type
(Designated_Type
(Typ
))
7602 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
7605 Error_Msg_N
("aliased object has explicit bounds?",
7607 Error_Msg_N
("\declare without bounds"
7608 & " (and with explicit initialization)?", D
);
7609 Error_Msg_N
("\for use with unconstrained access?", D
);
7614 -- Check the static accessibility rule of 3.10.2(28).
7615 -- Note that this check is not performed for the
7616 -- case of an anonymous access type, since the access
7617 -- attribute is always legal in such a context.
7619 if Attr_Id
/= Attribute_Unchecked_Access
7620 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7621 and then Ekind
(Btyp
) = E_General_Access_Type
7623 Accessibility_Message
;
7628 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7630 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7632 if Is_Entity_Name
(P
)
7633 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
7635 Error_Msg_F
("context requires a protected subprogram", P
);
7637 -- Check accessibility of protected object against that of the
7638 -- access type, but only on user code, because the expander
7639 -- creates access references for handlers. If the context is an
7640 -- anonymous_access_to_protected, there are no accessibility
7641 -- checks either. Omit check entirely for Unrestricted_Access.
7643 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7644 and then Comes_From_Source
(N
)
7645 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7646 and then Attr_Id
/= Attribute_Unrestricted_Access
7648 Accessibility_Message
;
7652 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
7654 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
7655 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
7657 Error_Msg_F
("context requires a non-protected subprogram", P
);
7660 -- The context cannot be a pool-specific type, but this is a
7661 -- legality rule, not a resolution rule, so it must be checked
7662 -- separately, after possibly disambiguation (see AI-245).
7664 if Ekind
(Btyp
) = E_Access_Type
7665 and then Attr_Id
/= Attribute_Unrestricted_Access
7667 Wrong_Type
(N
, Typ
);
7670 -- The context may be a constrained access type (however ill-
7671 -- advised such subtypes might be) so in order to generate a
7672 -- constraint check when needed set the type of the attribute
7673 -- reference to the base type of the context.
7675 Set_Etype
(N
, Btyp
);
7677 -- Check for incorrect atomic/volatile reference (RM C.6(12))
7679 if Attr_Id
/= Attribute_Unrestricted_Access
then
7680 if Is_Atomic_Object
(P
)
7681 and then not Is_Atomic
(Designated_Type
(Typ
))
7684 ("access to atomic object cannot yield access-to-" &
7685 "non-atomic type", P
);
7687 elsif Is_Volatile_Object
(P
)
7688 and then not Is_Volatile
(Designated_Type
(Typ
))
7691 ("access to volatile object cannot yield access-to-" &
7692 "non-volatile type", P
);
7696 if Is_Entity_Name
(P
) then
7697 Set_Address_Taken
(Entity
(P
));
7699 end Access_Attribute
;
7705 -- Deal with resolving the type for Address attribute, overloading
7706 -- is not permitted here, since there is no context to resolve it.
7708 when Attribute_Address | Attribute_Code_Address
=>
7709 Address_Attribute
: begin
7711 -- To be safe, assume that if the address of a variable is taken,
7712 -- it may be modified via this address, so note modification.
7714 if Is_Variable
(P
) then
7715 Note_Possible_Modification
(P
);
7718 if Nkind
(P
) in N_Subexpr
7719 and then Is_Overloaded
(P
)
7721 Get_First_Interp
(P
, Index
, It
);
7722 Get_Next_Interp
(Index
, It
);
7724 if Present
(It
.Nam
) then
7725 Error_Msg_Name_1
:= Aname
;
7727 ("prefix of % attribute cannot be overloaded", P
);
7731 if not Is_Entity_Name
(P
)
7732 or else not Is_Overloadable
(Entity
(P
))
7734 if not Is_Task_Type
(Etype
(P
))
7735 or else Nkind
(P
) = N_Explicit_Dereference
7741 -- If this is the name of a derived subprogram, or that of a
7742 -- generic actual, the address is that of the original entity.
7744 if Is_Entity_Name
(P
)
7745 and then Is_Overloadable
(Entity
(P
))
7746 and then Present
(Alias
(Entity
(P
)))
7749 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7752 if Is_Entity_Name
(P
) then
7753 Set_Address_Taken
(Entity
(P
));
7755 end Address_Attribute
;
7761 -- Prefix of the AST_Entry attribute is an entry name which must
7762 -- not be resolved, since this is definitely not an entry call.
7764 when Attribute_AST_Entry
=>
7771 -- Prefix of Body_Version attribute can be a subprogram name which
7772 -- must not be resolved, since this is not a call.
7774 when Attribute_Body_Version
=>
7781 -- Prefix of Caller attribute is an entry name which must not
7782 -- be resolved, since this is definitely not an entry call.
7784 when Attribute_Caller
=>
7791 -- Shares processing with Address attribute
7797 -- If the prefix of the Count attribute is an entry name it must not
7798 -- be resolved, since this is definitely not an entry call. However,
7799 -- if it is an element of an entry family, the index itself may
7800 -- have to be resolved because it can be a general expression.
7802 when Attribute_Count
=>
7803 if Nkind
(P
) = N_Indexed_Component
7804 and then Is_Entity_Name
(Prefix
(P
))
7807 Indx
: constant Node_Id
:= First
(Expressions
(P
));
7808 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
7810 Resolve
(Indx
, Entry_Index_Type
(Fam
));
7811 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
7819 -- Prefix of the Elaborated attribute is a subprogram name which
7820 -- must not be resolved, since this is definitely not a call. Note
7821 -- that it is a library unit, so it cannot be overloaded here.
7823 when Attribute_Elaborated
=>
7830 -- Prefix of Enabled attribute is a check name, which must be treated
7831 -- specially and not touched by Resolve.
7833 when Attribute_Enabled
=>
7836 --------------------
7837 -- Mechanism_Code --
7838 --------------------
7840 -- Prefix of the Mechanism_Code attribute is a function name
7841 -- which must not be resolved. Should we check for overloaded ???
7843 when Attribute_Mechanism_Code
=>
7850 -- Most processing is done in sem_dist, after determining the
7851 -- context type. Node is rewritten as a conversion to a runtime call.
7853 when Attribute_Partition_ID
=>
7854 Process_Partition_Id
(N
);
7861 when Attribute_Pool_Address
=>
7868 -- We replace the Range attribute node with a range expression
7869 -- whose bounds are the 'First and 'Last attributes applied to the
7870 -- same prefix. The reason that we do this transformation here
7871 -- instead of in the expander is that it simplifies other parts of
7872 -- the semantic analysis which assume that the Range has been
7873 -- replaced; thus it must be done even when in semantic-only mode
7874 -- (note that the RM specifically mentions this equivalence, we
7875 -- take care that the prefix is only evaluated once).
7877 when Attribute_Range
=> Range_Attribute
:
7882 function Check_Discriminated_Prival
7885 -- The range of a private component constrained by a
7886 -- discriminant is rewritten to make the discriminant
7887 -- explicit. This solves some complex visibility problems
7888 -- related to the use of privals.
7890 --------------------------------
7891 -- Check_Discriminated_Prival --
7892 --------------------------------
7894 function Check_Discriminated_Prival
7899 if Is_Entity_Name
(N
)
7900 and then Ekind
(Entity
(N
)) = E_In_Parameter
7901 and then not Within_Init_Proc
7903 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
7905 return Duplicate_Subexpr
(N
);
7907 end Check_Discriminated_Prival
;
7909 -- Start of processing for Range_Attribute
7912 if not Is_Entity_Name
(P
)
7913 or else not Is_Type
(Entity
(P
))
7918 -- Check whether prefix is (renaming of) private component
7919 -- of protected type.
7921 if Is_Entity_Name
(P
)
7922 and then Comes_From_Source
(N
)
7923 and then Is_Array_Type
(Etype
(P
))
7924 and then Number_Dimensions
(Etype
(P
)) = 1
7925 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
7927 Ekind
(Scope
(Scope
(Entity
(P
)))) =
7931 Check_Discriminated_Prival
7932 (Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
7935 Check_Discriminated_Prival
7936 (Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
7940 Make_Attribute_Reference
(Loc
,
7941 Prefix
=> Duplicate_Subexpr
(P
),
7942 Attribute_Name
=> Name_Last
,
7943 Expressions
=> Expressions
(N
));
7946 Make_Attribute_Reference
(Loc
,
7948 Attribute_Name
=> Name_First
,
7949 Expressions
=> Expressions
(N
));
7952 -- If the original was marked as Must_Not_Freeze (see code
7953 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7954 -- does not freeze either.
7956 if Must_Not_Freeze
(N
) then
7957 Set_Must_Not_Freeze
(HB
);
7958 Set_Must_Not_Freeze
(LB
);
7959 Set_Must_Not_Freeze
(Prefix
(HB
));
7960 Set_Must_Not_Freeze
(Prefix
(LB
));
7963 if Raises_Constraint_Error
(Prefix
(N
)) then
7965 -- Preserve Sloc of prefix in the new bounds, so that
7966 -- the posted warning can be removed if we are within
7967 -- unreachable code.
7969 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
7970 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
7973 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
7974 Analyze_And_Resolve
(N
, Typ
);
7976 -- Normally after resolving attribute nodes, Eval_Attribute
7977 -- is called to do any possible static evaluation of the node.
7978 -- However, here since the Range attribute has just been
7979 -- transformed into a range expression it is no longer an
7980 -- attribute node and therefore the call needs to be avoided
7981 -- and is accomplished by simply returning from the procedure.
7984 end Range_Attribute
;
7990 -- Prefix must not be resolved in this case, since it is not a
7991 -- real entity reference. No action of any kind is require!
7993 when Attribute_UET_Address
=>
7996 ----------------------
7997 -- Unchecked_Access --
7998 ----------------------
8000 -- Processing is shared with Access
8002 -------------------------
8003 -- Unrestricted_Access --
8004 -------------------------
8006 -- Processing is shared with Access
8012 -- Apply range check. Note that we did not do this during the
8013 -- analysis phase, since we wanted Eval_Attribute to have a
8014 -- chance at finding an illegal out of range value.
8016 when Attribute_Val
=>
8018 -- Note that we do our own Eval_Attribute call here rather than
8019 -- use the common one, because we need to do processing after
8020 -- the call, as per above comment.
8024 -- Eval_Attribute may replace the node with a raise CE, or
8025 -- fold it to a constant. Obviously we only apply a scalar
8026 -- range check if this did not happen!
8028 if Nkind
(N
) = N_Attribute_Reference
8029 and then Attribute_Name
(N
) = Name_Val
8031 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
8040 -- Prefix of Version attribute can be a subprogram name which
8041 -- must not be resolved, since this is not a call.
8043 when Attribute_Version
=>
8046 ----------------------
8047 -- Other Attributes --
8048 ----------------------
8050 -- For other attributes, resolve prefix unless it is a type. If
8051 -- the attribute reference itself is a type name ('Base and 'Class)
8052 -- then this is only legal within a task or protected record.
8055 if not Is_Entity_Name
(P
)
8056 or else not Is_Type
(Entity
(P
))
8061 -- If the attribute reference itself is a type name ('Base,
8062 -- 'Class) then this is only legal within a task or protected
8063 -- record. What is this all about ???
8065 if Is_Entity_Name
(N
)
8066 and then Is_Type
(Entity
(N
))
8068 if Is_Concurrent_Type
(Entity
(N
))
8069 and then In_Open_Scopes
(Entity
(P
))
8074 ("invalid use of subtype name in expression or call", N
);
8078 -- For attributes whose argument may be a string, complete
8079 -- resolution of argument now. This avoids premature expansion
8080 -- (and the creation of transient scopes) before the attribute
8081 -- reference is resolved.
8084 when Attribute_Value
=>
8085 Resolve
(First
(Expressions
(N
)), Standard_String
);
8087 when Attribute_Wide_Value
=>
8088 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
8090 when Attribute_Wide_Wide_Value
=>
8091 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
8093 when others => null;
8096 -- If the prefix of the attribute is a class-wide type then it
8097 -- will be expanded into a dispatching call to a predefined
8098 -- primitive. Therefore we must check for potential violation
8099 -- of such restriction.
8101 if Is_Class_Wide_Type
(Etype
(P
)) then
8102 Check_Restriction
(No_Dispatching_Calls
, N
);
8106 -- Normally the Freezing is done by Resolve but sometimes the Prefix
8107 -- is not resolved, in which case the freezing must be done now.
8109 Freeze_Expression
(P
);
8111 -- Finally perform static evaluation on the attribute reference
8114 end Resolve_Attribute
;
8116 --------------------------------
8117 -- Stream_Attribute_Available --
8118 --------------------------------
8120 function Stream_Attribute_Available
8122 Nam
: TSS_Name_Type
;
8123 Partial_View
: Node_Id
:= Empty
) return Boolean
8125 Etyp
: Entity_Id
:= Typ
;
8127 -- Start of processing for Stream_Attribute_Available
8130 -- We need some comments in this body ???
8132 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
8136 if Is_Class_Wide_Type
(Typ
) then
8137 return not Is_Limited_Type
(Typ
)
8138 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
8141 if Nam
= TSS_Stream_Input
8142 and then Is_Abstract_Type
(Typ
)
8143 and then not Is_Class_Wide_Type
(Typ
)
8148 if not (Is_Limited_Type
(Typ
)
8149 or else (Present
(Partial_View
)
8150 and then Is_Limited_Type
(Partial_View
)))
8155 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
8157 if Nam
= TSS_Stream_Input
8158 and then Ada_Version
>= Ada_05
8159 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
8163 elsif Nam
= TSS_Stream_Output
8164 and then Ada_Version
>= Ada_05
8165 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
8170 -- Case of Read and Write: check for attribute definition clause that
8171 -- applies to an ancestor type.
8173 while Etype
(Etyp
) /= Etyp
loop
8174 Etyp
:= Etype
(Etyp
);
8176 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
8181 if Ada_Version
< Ada_05
then
8183 -- In Ada 95 mode, also consider a non-visible definition
8186 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
8189 and then Stream_Attribute_Available
8190 (Btyp
, Nam
, Partial_View
=> Typ
);
8195 end Stream_Attribute_Available
;