1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Debug
; use Debug
;
32 with Einfo
; use Einfo
;
33 with Errout
; use Errout
;
35 with Exp_Dist
; use Exp_Dist
;
36 with Exp_Util
; use Exp_Util
;
37 with Expander
; use Expander
;
38 with Freeze
; use Freeze
;
39 with Gnatvsn
; use Gnatvsn
;
40 with Itypes
; use Itypes
;
42 with Lib
.Xref
; use Lib
.Xref
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
49 with Sdefault
; use Sdefault
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Cat
; use Sem_Cat
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch10
; use Sem_Ch10
;
56 with Sem_Dim
; use Sem_Dim
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Elab
; use Sem_Elab
;
59 with Sem_Elim
; use Sem_Elim
;
60 with Sem_Eval
; use Sem_Eval
;
61 with Sem_Res
; use Sem_Res
;
62 with Sem_Type
; use Sem_Type
;
63 with Sem_Util
; use Sem_Util
;
64 with Stand
; use Stand
;
65 with Sinfo
; use Sinfo
;
66 with Sinput
; use Sinput
;
67 with Stringt
; use Stringt
;
69 with Stylesw
; use Stylesw
;
70 with Targparm
; use Targparm
;
71 with Ttypes
; use Ttypes
;
72 with Tbuild
; use Tbuild
;
73 with Uintp
; use Uintp
;
74 with Urealp
; use Urealp
;
76 package body Sem_Attr
is
78 True_Value
: constant Uint
:= Uint_1
;
79 False_Value
: constant Uint
:= Uint_0
;
80 -- Synonyms to be used when these constants are used as Boolean values
82 Bad_Attribute
: exception;
83 -- Exception raised if an error is detected during attribute processing,
84 -- used so that we can abandon the processing so we don't run into
85 -- trouble with cascaded errors.
87 -- The following array is the list of attributes defined in the Ada 83 RM
88 -- that are not included in Ada 95, but still get recognized in GNAT.
90 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
96 Attribute_Constrained |
103 Attribute_First_Bit |
109 Attribute_Leading_Part |
111 Attribute_Machine_Emax |
112 Attribute_Machine_Emin |
113 Attribute_Machine_Mantissa |
114 Attribute_Machine_Overflows |
115 Attribute_Machine_Radix |
116 Attribute_Machine_Rounds |
122 Attribute_Safe_Emax |
123 Attribute_Safe_Large |
124 Attribute_Safe_Small |
127 Attribute_Storage_Size |
129 Attribute_Terminated |
132 Attribute_Width => True,
135 -- The following array is the list of attributes defined in the Ada 2005
136 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
137 -- but in Ada 95 they are considered to be implementation defined.
139 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
140 Attribute_Machine_Rounding |
143 Attribute_Stream_Size |
144 Attribute_Wide_Wide_Width
=> True,
147 -- The following array contains all attributes that imply a modification
148 -- of their prefixes or result in an access value. Such prefixes can be
149 -- considered as lvalues.
151 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
152 Attribute_Class_Array
'(
157 Attribute_Unchecked_Access |
158 Attribute_Unrestricted_Access => True,
161 -----------------------
162 -- Local_Subprograms --
163 -----------------------
165 procedure Eval_Attribute (N : Node_Id);
166 -- Performs compile time evaluation of attributes where possible, leaving
167 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
168 -- set, and replacing the node with a literal node if the value can be
169 -- computed at compile time. All static attribute references are folded,
170 -- as well as a number of cases of non-static attributes that can always
171 -- be computed at compile time (e.g. floating-point model attributes that
172 -- are applied to non-static subtypes). Of course in such cases, the
173 -- Is_Static_Expression flag will not be set on the resulting literal.
174 -- Note that the only required action of this procedure is to catch the
175 -- static expression cases as described in the RM. Folding of other cases
176 -- is done where convenient, but some additional non-static folding is in
177 -- N_Expand_Attribute_Reference in cases where this is more convenient.
179 function Is_Anonymous_Tagged_Base
183 -- For derived tagged types that constrain parent discriminants we build
184 -- an anonymous unconstrained base type. We need to recognize the relation
185 -- between the two when analyzing an access attribute for a constrained
186 -- component, before the full declaration for Typ has been analyzed, and
187 -- where therefore the prefix of the attribute does not match the enclosing
190 -----------------------
191 -- Analyze_Attribute --
192 -----------------------
194 procedure Analyze_Attribute (N : Node_Id) is
195 Loc : constant Source_Ptr := Sloc (N);
196 Aname : constant Name_Id := Attribute_Name (N);
197 P : constant Node_Id := Prefix (N);
198 Exprs : constant List_Id := Expressions (N);
199 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
204 -- Type of prefix after analysis
206 P_Base_Type : Entity_Id;
207 -- Base type of prefix after analysis
209 -----------------------
210 -- Local Subprograms --
211 -----------------------
213 procedure Analyze_Access_Attribute;
214 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
215 -- Internally, Id distinguishes which of the three cases is involved.
217 procedure Bad_Attribute_For_Predicate;
218 -- Output error message for use of a predicate (First, Last, Range) not
219 -- allowed with a type that has predicates. If the type is a generic
220 -- actual, then the message is a warning, and we generate code to raise
221 -- program error with an appropriate reason. No error message is given
222 -- for internally generated uses of the attributes. This legality rule
223 -- only applies to scalar types.
225 procedure Check_Ada_2012_Attribute;
226 -- Check that we are in Ada 2012 mode for an Ada 2012 attribute, and
227 -- issue appropriate messages if not (and return to caller even in
230 procedure Check_Array_Or_Scalar_Type;
231 -- Common procedure used by First, Last, Range attribute to check
232 -- that the prefix is a constrained array or scalar type, or a name
233 -- of an array object, and that an argument appears only if appropriate
234 -- (i.e. only in the array case).
236 procedure Check_Array_Type;
237 -- Common semantic checks for all array attributes. Checks that the
238 -- prefix is a constrained array type or the name of an array object.
239 -- The error message for non-arrays is specialized appropriately.
241 procedure Check_Asm_Attribute;
242 -- Common semantic checks for Asm_Input and Asm_Output attributes
244 procedure Check_Component;
245 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
246 -- Position. Checks prefix is an appropriate selected component.
248 procedure Check_Decimal_Fixed_Point_Type;
249 -- Check that prefix of attribute N is a decimal fixed-point type
251 procedure Check_Dereference;
252 -- If the prefix of attribute is an object of an access type, then
253 -- introduce an explicit dereference, and adjust P_Type accordingly.
255 procedure Check_Discrete_Type;
256 -- Verify that prefix of attribute N is a discrete type
259 -- Check that no attribute arguments are present
261 procedure Check_Either_E0_Or_E1;
262 -- Check that there are zero or one attribute arguments present
265 -- Check that exactly one attribute argument is present
268 -- Check that two attribute arguments are present
270 procedure Check_Enum_Image;
271 -- If the prefix type is an enumeration type, set all its literals
272 -- as referenced, since the image function could possibly end up
273 -- referencing any of the literals indirectly. Same for Enum_Val.
274 -- Set the flag only if the reference is in the main code unit. Same
275 -- restriction when resolving 'Value
; otherwise an improperly set
276 -- reference when analyzing an inlined body will lose a proper warning
277 -- on a useless with_clause.
279 procedure Check_First_Last_Valid
;
280 -- Perform all checks for First_Valid and Last_Valid attributes
282 procedure Check_Fixed_Point_Type
;
283 -- Verify that prefix of attribute N is a fixed type
285 procedure Check_Fixed_Point_Type_0
;
286 -- Verify that prefix of attribute N is a fixed type and that
287 -- no attribute expressions are present
289 procedure Check_Floating_Point_Type
;
290 -- Verify that prefix of attribute N is a float type
292 procedure Check_Floating_Point_Type_0
;
293 -- Verify that prefix of attribute N is a float type and that
294 -- no attribute expressions are present
296 procedure Check_Floating_Point_Type_1
;
297 -- Verify that prefix of attribute N is a float type and that
298 -- exactly one attribute expression is present
300 procedure Check_Floating_Point_Type_2
;
301 -- Verify that prefix of attribute N is a float type and that
302 -- two attribute expressions are present
304 procedure Legal_Formal_Attribute
;
305 -- Common processing for attributes Definite and Has_Discriminants.
306 -- Checks that prefix is generic indefinite formal type.
308 procedure Check_SPARK_Restriction_On_Attribute
;
309 -- Issue an error in formal mode because attribute N is allowed
311 procedure Check_Integer_Type
;
312 -- Verify that prefix of attribute N is an integer type
314 procedure Check_Modular_Integer_Type
;
315 -- Verify that prefix of attribute N is a modular integer type
317 procedure Check_Not_CPP_Type
;
318 -- Check that P (the prefix of the attribute) is not an CPP type
319 -- for which no Ada predefined primitive is available.
321 procedure Check_Not_Incomplete_Type
;
322 -- Check that P (the prefix of the attribute) is not an incomplete
323 -- type or a private type for which no full view has been given.
325 procedure Check_Object_Reference
(P
: Node_Id
);
326 -- Check that P is an object reference
328 procedure Check_Program_Unit
;
329 -- Verify that prefix of attribute N is a program unit
331 procedure Check_Real_Type
;
332 -- Verify that prefix of attribute N is fixed or float type
334 procedure Check_Scalar_Type
;
335 -- Verify that prefix of attribute N is a scalar type
337 procedure Check_Standard_Prefix
;
338 -- Verify that prefix of attribute N is package Standard
340 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
341 -- Validity checking for stream attribute. Nam is the TSS name of the
342 -- corresponding possible defined attribute function (e.g. for the
343 -- Read attribute, Nam will be TSS_Stream_Read).
345 procedure Check_PolyORB_Attribute
;
346 -- Validity checking for PolyORB/DSA attribute
348 procedure Check_Task_Prefix
;
349 -- Verify that prefix of attribute N is a task or task type
351 procedure Check_Type
;
352 -- Verify that the prefix of attribute N is a type
354 procedure Check_Unit_Name
(Nod
: Node_Id
);
355 -- Check that Nod is of the form of a library unit name, i.e that
356 -- it is an identifier, or a selected component whose prefix is
357 -- itself of the form of a library unit name. Note that this is
358 -- quite different from Check_Program_Unit, since it only checks
359 -- the syntactic form of the name, not the semantic identity. This
360 -- is because it is used with attributes (Elab_Body, Elab_Spec,
361 -- UET_Address and Elaborated) which can refer to non-visible unit.
363 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
364 pragma No_Return
(Error_Attr
);
365 procedure Error_Attr
;
366 pragma No_Return
(Error_Attr
);
367 -- Posts error using Error_Msg_N at given node, sets type of attribute
368 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
369 -- semantic processing. The message typically contains a % insertion
370 -- character which is replaced by the attribute name. The call with
371 -- no arguments is used when the caller has already generated the
372 -- required error messages.
374 procedure Error_Attr_P
(Msg
: String);
375 pragma No_Return
(Error_Attr
);
376 -- Like Error_Attr, but error is posted at the start of the prefix
378 procedure Standard_Attribute
(Val
: Int
);
379 -- Used to process attributes whose prefix is package Standard which
380 -- yield values of type Universal_Integer. The attribute reference
381 -- node is rewritten with an integer literal of the given value.
383 procedure Unexpected_Argument
(En
: Node_Id
);
384 -- Signal unexpected attribute argument (En is the argument)
386 procedure Validate_Non_Static_Attribute_Function_Call
;
387 -- Called when processing an attribute that is a function call to a
388 -- non-static function, i.e. an attribute function that either takes
389 -- non-scalar arguments or returns a non-scalar result. Verifies that
390 -- such a call does not appear in a preelaborable context.
392 ------------------------------
393 -- Analyze_Access_Attribute --
394 ------------------------------
396 procedure Analyze_Access_Attribute
is
397 Acc_Type
: Entity_Id
;
402 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
403 -- Build an access-to-object type whose designated type is DT,
404 -- and whose Ekind is appropriate to the attribute type. The
405 -- type that is constructed is returned as the result.
407 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
408 -- Build an access to subprogram whose designated type is the type of
409 -- the prefix. If prefix is overloaded, so is the node itself. The
410 -- result is stored in Acc_Type.
412 function OK_Self_Reference
return Boolean;
413 -- An access reference whose prefix is a type can legally appear
414 -- within an aggregate, where it is obtained by expansion of
415 -- a defaulted aggregate. The enclosing aggregate that contains
416 -- the self-referenced is flagged so that the self-reference can
417 -- be expanded into a reference to the target object (see exp_aggr).
419 ------------------------------
420 -- Build_Access_Object_Type --
421 ------------------------------
423 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
424 Typ
: constant Entity_Id
:=
426 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
428 Set_Etype
(Typ
, Typ
);
430 Set_Associated_Node_For_Itype
(Typ
, N
);
431 Set_Directly_Designated_Type
(Typ
, DT
);
433 end Build_Access_Object_Type
;
435 ----------------------------------
436 -- Build_Access_Subprogram_Type --
437 ----------------------------------
439 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
440 Index
: Interp_Index
;
443 procedure Check_Local_Access
(E
: Entity_Id
);
444 -- Deal with possible access to local subprogram. If we have such
445 -- an access, we set a flag to kill all tracked values on any call
446 -- because this access value may be passed around, and any called
447 -- code might use it to access a local procedure which clobbers a
448 -- tracked value. If the scope is a loop or block, indicate that
449 -- value tracking is disabled for the enclosing subprogram.
451 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
452 -- Distinguish between access to regular/protected subprograms
454 ------------------------
455 -- Check_Local_Access --
456 ------------------------
458 procedure Check_Local_Access
(E
: Entity_Id
) is
460 if not Is_Library_Level_Entity
(E
) then
461 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
462 Set_Suppress_Value_Tracking_On_Call
463 (Nearest_Dynamic_Scope
(Current_Scope
));
465 end Check_Local_Access
;
471 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
473 if Convention
(E
) = Convention_Protected
then
474 return E_Access_Protected_Subprogram_Type
;
476 return E_Access_Subprogram_Type
;
480 -- Start of processing for Build_Access_Subprogram_Type
483 -- In the case of an access to subprogram, use the name of the
484 -- subprogram itself as the designated type. Type-checking in
485 -- this case compares the signatures of the designated types.
487 -- Note: This fragment of the tree is temporarily malformed
488 -- because the correct tree requires an E_Subprogram_Type entity
489 -- as the designated type. In most cases this designated type is
490 -- later overridden by the semantics with the type imposed by the
491 -- context during the resolution phase. In the specific case of
492 -- the expression Address!(Prim'Unrestricted_Access), used to
493 -- initialize slots of dispatch tables, this work will be done by
494 -- the expander (see Exp_Aggr).
496 -- The reason to temporarily add this kind of node to the tree
497 -- instead of a proper E_Subprogram_Type itype, is the following:
498 -- in case of errors found in the source file we report better
499 -- error messages. For example, instead of generating the
502 -- "expected access to subprogram with profile
503 -- defined at line X"
505 -- we currently generate:
507 -- "expected access to function Z defined at line X"
509 Set_Etype
(N
, Any_Type
);
511 if not Is_Overloaded
(P
) then
512 Check_Local_Access
(Entity
(P
));
514 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
515 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
516 Set_Is_Public
(Acc_Type
, False);
517 Set_Etype
(Acc_Type
, Acc_Type
);
518 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
519 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
520 Set_Etype
(N
, Acc_Type
);
521 Freeze_Before
(N
, Acc_Type
);
525 Get_First_Interp
(P
, Index
, It
);
526 while Present
(It
.Nam
) loop
527 Check_Local_Access
(It
.Nam
);
529 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
530 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
531 Set_Is_Public
(Acc_Type
, False);
532 Set_Etype
(Acc_Type
, Acc_Type
);
533 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
534 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
535 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
536 Freeze_Before
(N
, Acc_Type
);
539 Get_Next_Interp
(Index
, It
);
543 -- Cannot be applied to intrinsic. Looking at the tests above,
544 -- the only way Etype (N) can still be set to Any_Type is if
545 -- Is_Intrinsic_Subprogram was True for some referenced entity.
547 if Etype
(N
) = Any_Type
then
548 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
550 end Build_Access_Subprogram_Type
;
552 ----------------------
553 -- OK_Self_Reference --
554 ----------------------
556 function OK_Self_Reference
return Boolean is
563 (Nkind
(Par
) = N_Component_Association
564 or else Nkind
(Par
) in N_Subexpr
)
566 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
567 if Etype
(Par
) = Typ
then
568 Set_Has_Self_Reference
(Par
);
576 -- No enclosing aggregate, or not a self-reference
579 end OK_Self_Reference
;
581 -- Start of processing for Analyze_Access_Attribute
584 Check_SPARK_Restriction_On_Attribute
;
587 if Nkind
(P
) = N_Character_Literal
then
589 ("prefix of % attribute cannot be enumeration literal");
592 -- Case of access to subprogram
594 if Is_Entity_Name
(P
)
595 and then Is_Overloadable
(Entity
(P
))
597 if Has_Pragma_Inline_Always
(Entity
(P
)) then
599 ("prefix of % attribute cannot be Inline_Always subprogram");
602 if Aname
= Name_Unchecked_Access
then
603 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
606 -- Issue an error if the prefix denotes an eliminated subprogram
608 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
610 -- Check for obsolescent subprogram reference
612 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
614 -- Build the appropriate subprogram type
616 Build_Access_Subprogram_Type
(P
);
618 -- For P'Access or P'Unrestricted_Access, where P is a nested
619 -- subprogram, we might be passing P to another subprogram (but we
620 -- don't check that here), which might call P. P could modify
621 -- local variables, so we need to kill current values. It is
622 -- important not to do this for library-level subprograms, because
623 -- Kill_Current_Values is very inefficient in the case of library
624 -- level packages with lots of tagged types.
626 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
629 -- Do not kill values on nodes initializing dispatch tables
630 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
631 -- is currently generated by the expander only for this
632 -- purpose. Done to keep the quality of warnings currently
633 -- generated by the compiler (otherwise any declaration of
634 -- a tagged type cleans constant indications from its scope).
636 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
637 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
639 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
640 and then Is_Dispatching_Operation
641 (Directly_Designated_Type
(Etype
(N
)))
649 -- Treat as call for elaboration purposes and we are all
650 -- done. Suppress this treatment under debug flag.
652 if not Debug_Flag_Dot_UU
then
658 -- Component is an operation of a protected type
660 elsif Nkind
(P
) = N_Selected_Component
661 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
663 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
664 Error_Attr_P
("prefix of % attribute must be subprogram");
667 Build_Access_Subprogram_Type
(Selector_Name
(P
));
671 -- Deal with incorrect reference to a type, but note that some
672 -- accesses are allowed: references to the current type instance,
673 -- or in Ada 2005 self-referential pointer in a default-initialized
676 if Is_Entity_Name
(P
) then
679 -- The reference may appear in an aggregate that has been expanded
680 -- into a loop. Locate scope of type definition, if any.
682 Scop
:= Current_Scope
;
683 while Ekind
(Scop
) = E_Loop
loop
684 Scop
:= Scope
(Scop
);
687 if Is_Type
(Typ
) then
689 -- OK if we are within the scope of a limited type
690 -- let's mark the component as having per object constraint
692 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
700 Q
: Node_Id
:= Parent
(N
);
704 and then Nkind
(Q
) /= N_Component_Declaration
710 Set_Has_Per_Object_Constraint
711 (Defining_Identifier
(Q
), True);
715 if Nkind
(P
) = N_Expanded_Name
then
717 ("current instance prefix must be a direct name", P
);
720 -- If a current instance attribute appears in a component
721 -- constraint it must appear alone; other contexts (spec-
722 -- expressions, within a task body) are not subject to this
725 if not In_Spec_Expression
726 and then not Has_Completion
(Scop
)
728 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
729 N_Index_Or_Discriminant_Constraint
)
732 ("current instance attribute must appear alone", N
);
735 if Is_CPP_Class
(Root_Type
(Typ
)) then
737 ("?current instance unsupported for derivations of "
738 & "'C'P'P types", N
);
741 -- OK if we are in initialization procedure for the type
742 -- in question, in which case the reference to the type
743 -- is rewritten as a reference to the current object.
745 elsif Ekind
(Scop
) = E_Procedure
746 and then Is_Init_Proc
(Scop
)
747 and then Etype
(First_Formal
(Scop
)) = Typ
750 Make_Attribute_Reference
(Loc
,
751 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
752 Attribute_Name
=> Name_Unrestricted_Access
));
756 -- OK if a task type, this test needs sharpening up ???
758 elsif Is_Task_Type
(Typ
) then
761 -- OK if self-reference in an aggregate in Ada 2005, and
762 -- the reference comes from a copied default expression.
764 -- Note that we check legality of self-reference even if the
765 -- expression comes from source, e.g. when a single component
766 -- association in an aggregate has a box association.
768 elsif Ada_Version
>= Ada_2005
769 and then OK_Self_Reference
773 -- OK if reference to current instance of a protected object
775 elsif Is_Protected_Self_Reference
(P
) then
778 -- Otherwise we have an error case
781 Error_Attr
("% attribute cannot be applied to type", P
);
787 -- If we fall through, we have a normal access to object case.
788 -- Unrestricted_Access is legal wherever an allocator would be
789 -- legal, so its Etype is set to E_Allocator. The expected type
790 -- of the other attributes is a general access type, and therefore
791 -- we label them with E_Access_Attribute_Type.
793 if not Is_Overloaded
(P
) then
794 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
795 Set_Etype
(N
, Acc_Type
);
798 Index
: Interp_Index
;
801 Set_Etype
(N
, Any_Type
);
802 Get_First_Interp
(P
, Index
, It
);
803 while Present
(It
.Typ
) loop
804 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
805 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
806 Get_Next_Interp
(Index
, It
);
811 -- Special cases when we can find a prefix that is an entity name
820 if Is_Entity_Name
(PP
) then
823 -- If we have an access to an object, and the attribute
824 -- comes from source, then set the object as potentially
825 -- source modified. We do this because the resulting access
826 -- pointer can be used to modify the variable, and we might
827 -- not detect this, leading to some junk warnings.
829 Set_Never_Set_In_Source
(Ent
, False);
831 -- Mark entity as address taken, and kill current values
833 Set_Address_Taken
(Ent
);
834 Kill_Current_Values
(Ent
);
837 elsif Nkind_In
(PP
, N_Selected_Component
,
848 -- Check for aliased view unless unrestricted case. We allow a
849 -- nonaliased prefix when within an instance because the prefix may
850 -- have been a tagged formal object, which is defined to be aliased
851 -- even when the actual might not be (other instance cases will have
852 -- been caught in the generic). Similarly, within an inlined body we
853 -- know that the attribute is legal in the original subprogram, and
854 -- therefore legal in the expansion.
856 if Aname
/= Name_Unrestricted_Access
857 and then not Is_Aliased_View
(P
)
858 and then not In_Instance
859 and then not In_Inlined_Body
861 Error_Attr_P
("prefix of % attribute must be aliased");
862 Check_No_Implicit_Aliasing
(P
);
864 end Analyze_Access_Attribute
;
866 ---------------------------------
867 -- Bad_Attribute_For_Predicate --
868 ---------------------------------
870 procedure Bad_Attribute_For_Predicate
is
872 if Is_Scalar_Type
(P_Type
)
873 and then Comes_From_Source
(N
)
875 Error_Msg_Name_1
:= Aname
;
876 Bad_Predicated_Subtype_Use
877 ("type& has predicates, attribute % not allowed", N
, P_Type
);
879 end Bad_Attribute_For_Predicate
;
881 ------------------------------
882 -- Check_Ada_2012_Attribute --
883 ------------------------------
885 procedure Check_Ada_2012_Attribute
is
887 if Ada_Version
< Ada_2012
then
888 Error_Msg_Name_1
:= Aname
;
890 ("attribute % is an Ada 2012 feature", N
);
892 ("\unit must be compiled with -gnat2012 switch", N
);
894 end Check_Ada_2012_Attribute
;
896 --------------------------------
897 -- Check_Array_Or_Scalar_Type --
898 --------------------------------
900 procedure Check_Array_Or_Scalar_Type
is
904 -- Dimension number for array attributes
907 -- Case of string literal or string literal subtype. These cases
908 -- cannot arise from legal Ada code, but the expander is allowed
909 -- to generate them. They require special handling because string
910 -- literal subtypes do not have standard bounds (the whole idea
911 -- of these subtypes is to avoid having to generate the bounds)
913 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
914 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
919 elsif Is_Scalar_Type
(P_Type
) then
923 Error_Attr
("invalid argument in % attribute", E1
);
925 Set_Etype
(N
, P_Base_Type
);
929 -- The following is a special test to allow 'First to apply to
930 -- private scalar types if the attribute comes from generated
931 -- code. This occurs in the case of Normalize_Scalars code.
933 elsif Is_Private_Type
(P_Type
)
934 and then Present
(Full_View
(P_Type
))
935 and then Is_Scalar_Type
(Full_View
(P_Type
))
936 and then not Comes_From_Source
(N
)
938 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
940 -- Array types other than string literal subtypes handled above
945 -- We know prefix is an array type, or the name of an array
946 -- object, and that the expression, if present, is static
947 -- and within the range of the dimensions of the type.
949 pragma Assert
(Is_Array_Type
(P_Type
));
950 Index
:= First_Index
(P_Base_Type
);
954 -- First dimension assumed
956 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
959 D
:= UI_To_Int
(Intval
(E1
));
961 for J
in 1 .. D
- 1 loop
965 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
966 Set_Etype
(E1
, Standard_Integer
);
969 end Check_Array_Or_Scalar_Type
;
971 ----------------------
972 -- Check_Array_Type --
973 ----------------------
975 procedure Check_Array_Type
is
977 -- Dimension number for array attributes
980 -- If the type is a string literal type, then this must be generated
981 -- internally, and no further check is required on its legality.
983 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
986 -- If the type is a composite, it is an illegal aggregate, no point
989 elsif P_Type
= Any_Composite
then
993 -- Normal case of array type or subtype
995 Check_Either_E0_Or_E1
;
998 if Is_Array_Type
(P_Type
) then
999 if not Is_Constrained
(P_Type
)
1000 and then Is_Entity_Name
(P
)
1001 and then Is_Type
(Entity
(P
))
1003 -- Note: we do not call Error_Attr here, since we prefer to
1004 -- continue, using the relevant index type of the array,
1005 -- even though it is unconstrained. This gives better error
1006 -- recovery behavior.
1008 Error_Msg_Name_1
:= Aname
;
1010 ("prefix for % attribute must be constrained array", P
);
1013 D
:= Number_Dimensions
(P_Type
);
1016 if Is_Private_Type
(P_Type
) then
1017 Error_Attr_P
("prefix for % attribute may not be private type");
1019 elsif Is_Access_Type
(P_Type
)
1020 and then Is_Array_Type
(Designated_Type
(P_Type
))
1021 and then Is_Entity_Name
(P
)
1022 and then Is_Type
(Entity
(P
))
1024 Error_Attr_P
("prefix of % attribute cannot be access type");
1026 elsif Attr_Id
= Attribute_First
1028 Attr_Id
= Attribute_Last
1030 Error_Attr
("invalid prefix for % attribute", P
);
1033 Error_Attr_P
("prefix for % attribute must be array");
1037 if Present
(E1
) then
1038 Resolve
(E1
, Any_Integer
);
1039 Set_Etype
(E1
, Standard_Integer
);
1041 if not Is_Static_Expression
(E1
)
1042 or else Raises_Constraint_Error
(E1
)
1044 Flag_Non_Static_Expr
1045 ("expression for dimension must be static!", E1
);
1048 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1049 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1051 Error_Attr
("invalid dimension number for array type", E1
);
1055 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1056 and then Comes_From_Source
(N
)
1058 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1060 end Check_Array_Type
;
1062 -------------------------
1063 -- Check_Asm_Attribute --
1064 -------------------------
1066 procedure Check_Asm_Attribute
is
1071 -- Check first argument is static string expression
1073 Analyze_And_Resolve
(E1
, Standard_String
);
1075 if Etype
(E1
) = Any_Type
then
1078 elsif not Is_OK_Static_Expression
(E1
) then
1079 Flag_Non_Static_Expr
1080 ("constraint argument must be static string expression!", E1
);
1084 -- Check second argument is right type
1086 Analyze_And_Resolve
(E2
, Entity
(P
));
1088 -- Note: that is all we need to do, we don't need to check
1089 -- that it appears in a correct context. The Ada type system
1090 -- will do that for us.
1092 end Check_Asm_Attribute
;
1094 ---------------------
1095 -- Check_Component --
1096 ---------------------
1098 procedure Check_Component
is
1102 if Nkind
(P
) /= N_Selected_Component
1104 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1106 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1108 Error_Attr_P
("prefix for % attribute must be selected component");
1110 end Check_Component
;
1112 ------------------------------------
1113 -- Check_Decimal_Fixed_Point_Type --
1114 ------------------------------------
1116 procedure Check_Decimal_Fixed_Point_Type
is
1120 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1121 Error_Attr_P
("prefix of % attribute must be decimal type");
1123 end Check_Decimal_Fixed_Point_Type
;
1125 -----------------------
1126 -- Check_Dereference --
1127 -----------------------
1129 procedure Check_Dereference
is
1132 -- Case of a subtype mark
1134 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1138 -- Case of an expression
1142 if Is_Access_Type
(P_Type
) then
1144 -- If there is an implicit dereference, then we must freeze the
1145 -- designated type of the access type, since the type of the
1146 -- referenced array is this type (see AI95-00106).
1148 -- As done elsewhere, freezing must not happen when pre-analyzing
1149 -- a pre- or postcondition or a default value for an object or for
1150 -- a formal parameter.
1152 if not In_Spec_Expression
then
1153 Freeze_Before
(N
, Designated_Type
(P_Type
));
1157 Make_Explicit_Dereference
(Sloc
(P
),
1158 Prefix
=> Relocate_Node
(P
)));
1160 Analyze_And_Resolve
(P
);
1161 P_Type
:= Etype
(P
);
1163 if P_Type
= Any_Type
then
1164 raise Bad_Attribute
;
1167 P_Base_Type
:= Base_Type
(P_Type
);
1169 end Check_Dereference
;
1171 -------------------------
1172 -- Check_Discrete_Type --
1173 -------------------------
1175 procedure Check_Discrete_Type
is
1179 if not Is_Discrete_Type
(P_Type
) then
1180 Error_Attr_P
("prefix of % attribute must be discrete type");
1182 end Check_Discrete_Type
;
1188 procedure Check_E0
is
1190 if Present
(E1
) then
1191 Unexpected_Argument
(E1
);
1199 procedure Check_E1
is
1201 Check_Either_E0_Or_E1
;
1205 -- Special-case attributes that are functions and that appear as
1206 -- the prefix of another attribute. Error is posted on parent.
1208 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1209 and then (Attribute_Name
(Parent
(N
)) = Name_Address
1211 Attribute_Name
(Parent
(N
)) = Name_Code_Address
1213 Attribute_Name
(Parent
(N
)) = Name_Access
)
1215 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1216 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1217 Set_Etype
(Parent
(N
), Any_Type
);
1218 Set_Entity
(Parent
(N
), Any_Type
);
1219 raise Bad_Attribute
;
1222 Error_Attr
("missing argument for % attribute", N
);
1231 procedure Check_E2
is
1234 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1236 Error_Attr
("missing argument for % attribute (2 required)", N
);
1240 ---------------------------
1241 -- Check_Either_E0_Or_E1 --
1242 ---------------------------
1244 procedure Check_Either_E0_Or_E1
is
1246 if Present
(E2
) then
1247 Unexpected_Argument
(E2
);
1249 end Check_Either_E0_Or_E1
;
1251 ----------------------
1252 -- Check_Enum_Image --
1253 ----------------------
1255 procedure Check_Enum_Image
is
1259 -- When an enumeration type appears in an attribute reference, all
1260 -- literals of the type are marked as referenced. This must only be
1261 -- done if the attribute reference appears in the current source.
1262 -- Otherwise the information on references may differ between a
1263 -- normal compilation and one that performs inlining.
1265 if Is_Enumeration_Type
(P_Base_Type
)
1266 and then In_Extended_Main_Code_Unit
(N
)
1268 Lit
:= First_Literal
(P_Base_Type
);
1269 while Present
(Lit
) loop
1270 Set_Referenced
(Lit
);
1274 end Check_Enum_Image
;
1276 ----------------------------
1277 -- Check_First_Last_Valid --
1278 ----------------------------
1280 procedure Check_First_Last_Valid
is
1282 Check_Ada_2012_Attribute
;
1283 Check_Discrete_Type
;
1285 -- Freeze the subtype now, so that the following test for predicates
1286 -- works (we set the predicates stuff up at freeze time)
1288 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1290 -- Now test for dynamic predicate
1292 if Has_Predicates
(P_Type
)
1293 and then No
(Static_Predicate
(P_Type
))
1296 ("prefix of % attribute may not have dynamic predicate");
1299 -- Check non-static subtype
1301 if not Is_Static_Subtype
(P_Type
) then
1302 Error_Attr_P
("prefix of % attribute must be a static subtype");
1305 -- Test case for no values
1307 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1308 Expr_Value
(Type_High_Bound
(P_Type
))
1309 or else (Has_Predicates
(P_Type
)
1310 and then Is_Empty_List
(Static_Predicate
(P_Type
)))
1313 ("prefix of % attribute must be subtype with "
1314 & "at least one value");
1316 end Check_First_Last_Valid
;
1318 ----------------------------
1319 -- Check_Fixed_Point_Type --
1320 ----------------------------
1322 procedure Check_Fixed_Point_Type
is
1326 if not Is_Fixed_Point_Type
(P_Type
) then
1327 Error_Attr_P
("prefix of % attribute must be fixed point type");
1329 end Check_Fixed_Point_Type
;
1331 ------------------------------
1332 -- Check_Fixed_Point_Type_0 --
1333 ------------------------------
1335 procedure Check_Fixed_Point_Type_0
is
1337 Check_Fixed_Point_Type
;
1339 end Check_Fixed_Point_Type_0
;
1341 -------------------------------
1342 -- Check_Floating_Point_Type --
1343 -------------------------------
1345 procedure Check_Floating_Point_Type
is
1349 if not Is_Floating_Point_Type
(P_Type
) then
1350 Error_Attr_P
("prefix of % attribute must be float type");
1352 end Check_Floating_Point_Type
;
1354 ---------------------------------
1355 -- Check_Floating_Point_Type_0 --
1356 ---------------------------------
1358 procedure Check_Floating_Point_Type_0
is
1360 Check_Floating_Point_Type
;
1362 end Check_Floating_Point_Type_0
;
1364 ---------------------------------
1365 -- Check_Floating_Point_Type_1 --
1366 ---------------------------------
1368 procedure Check_Floating_Point_Type_1
is
1370 Check_Floating_Point_Type
;
1372 end Check_Floating_Point_Type_1
;
1374 ---------------------------------
1375 -- Check_Floating_Point_Type_2 --
1376 ---------------------------------
1378 procedure Check_Floating_Point_Type_2
is
1380 Check_Floating_Point_Type
;
1382 end Check_Floating_Point_Type_2
;
1384 ------------------------
1385 -- Check_Integer_Type --
1386 ------------------------
1388 procedure Check_Integer_Type
is
1392 if not Is_Integer_Type
(P_Type
) then
1393 Error_Attr_P
("prefix of % attribute must be integer type");
1395 end Check_Integer_Type
;
1397 --------------------------------
1398 -- Check_Modular_Integer_Type --
1399 --------------------------------
1401 procedure Check_Modular_Integer_Type
is
1405 if not Is_Modular_Integer_Type
(P_Type
) then
1407 ("prefix of % attribute must be modular integer type");
1409 end Check_Modular_Integer_Type
;
1411 ------------------------
1412 -- Check_Not_CPP_Type --
1413 ------------------------
1415 procedure Check_Not_CPP_Type
is
1417 if Is_Tagged_Type
(Etype
(P
))
1418 and then Convention
(Etype
(P
)) = Convention_CPP
1419 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1422 ("invalid use of % attribute with 'C'P'P tagged type");
1424 end Check_Not_CPP_Type
;
1426 -------------------------------
1427 -- Check_Not_Incomplete_Type --
1428 -------------------------------
1430 procedure Check_Not_Incomplete_Type
is
1435 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1436 -- dereference we have to check wrong uses of incomplete types
1437 -- (other wrong uses are checked at their freezing point).
1439 -- Example 1: Limited-with
1441 -- limited with Pkg;
1443 -- type Acc is access Pkg.T;
1445 -- S : Integer := X.all'Size; -- ERROR
1448 -- Example 2: Tagged incomplete
1450 -- type T is tagged;
1451 -- type Acc is access all T;
1453 -- S : constant Integer := X.all'Size; -- ERROR
1454 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1456 if Ada_Version
>= Ada_2005
1457 and then Nkind
(P
) = N_Explicit_Dereference
1460 while Nkind
(E
) = N_Explicit_Dereference
loop
1466 if From_With_Type
(Typ
) then
1468 ("prefix of % attribute cannot be an incomplete type");
1471 if Is_Access_Type
(Typ
) then
1472 Typ
:= Directly_Designated_Type
(Typ
);
1475 if Is_Class_Wide_Type
(Typ
) then
1476 Typ
:= Root_Type
(Typ
);
1479 -- A legal use of a shadow entity occurs only when the unit
1480 -- where the non-limited view resides is imported via a regular
1481 -- with clause in the current body. Such references to shadow
1482 -- entities may occur in subprogram formals.
1484 if Is_Incomplete_Type
(Typ
)
1485 and then From_With_Type
(Typ
)
1486 and then Present
(Non_Limited_View
(Typ
))
1487 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1489 Typ
:= Non_Limited_View
(Typ
);
1492 if Ekind
(Typ
) = E_Incomplete_Type
1493 and then No
(Full_View
(Typ
))
1496 ("prefix of % attribute cannot be an incomplete type");
1501 if not Is_Entity_Name
(P
)
1502 or else not Is_Type
(Entity
(P
))
1503 or else In_Spec_Expression
1507 Check_Fully_Declared
(P_Type
, P
);
1509 end Check_Not_Incomplete_Type
;
1511 ----------------------------
1512 -- Check_Object_Reference --
1513 ----------------------------
1515 procedure Check_Object_Reference
(P
: Node_Id
) is
1519 -- If we need an object, and we have a prefix that is the name of
1520 -- a function entity, convert it into a function call.
1522 if Is_Entity_Name
(P
)
1523 and then Ekind
(Entity
(P
)) = E_Function
1525 Rtyp
:= Etype
(Entity
(P
));
1528 Make_Function_Call
(Sloc
(P
),
1529 Name
=> Relocate_Node
(P
)));
1531 Analyze_And_Resolve
(P
, Rtyp
);
1533 -- Otherwise we must have an object reference
1535 elsif not Is_Object_Reference
(P
) then
1536 Error_Attr_P
("prefix of % attribute must be object");
1538 end Check_Object_Reference
;
1540 ----------------------------
1541 -- Check_PolyORB_Attribute --
1542 ----------------------------
1544 procedure Check_PolyORB_Attribute
is
1546 Validate_Non_Static_Attribute_Function_Call
;
1551 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1553 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1555 end Check_PolyORB_Attribute
;
1557 ------------------------
1558 -- Check_Program_Unit --
1559 ------------------------
1561 procedure Check_Program_Unit
is
1563 if Is_Entity_Name
(P
) then
1565 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1566 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1569 if K
in Subprogram_Kind
1570 or else K
in Task_Kind
1571 or else K
in Protected_Kind
1572 or else K
= E_Package
1573 or else K
in Generic_Unit_Kind
1574 or else (K
= E_Variable
1578 Is_Protected_Type
(T
)))
1585 Error_Attr_P
("prefix of % attribute must be program unit");
1586 end Check_Program_Unit
;
1588 ---------------------
1589 -- Check_Real_Type --
1590 ---------------------
1592 procedure Check_Real_Type
is
1596 if not Is_Real_Type
(P_Type
) then
1597 Error_Attr_P
("prefix of % attribute must be real type");
1599 end Check_Real_Type
;
1601 -----------------------
1602 -- Check_Scalar_Type --
1603 -----------------------
1605 procedure Check_Scalar_Type
is
1609 if not Is_Scalar_Type
(P_Type
) then
1610 Error_Attr_P
("prefix of % attribute must be scalar type");
1612 end Check_Scalar_Type
;
1614 ------------------------------------------
1615 -- Check_SPARK_Restriction_On_Attribute --
1616 ------------------------------------------
1618 procedure Check_SPARK_Restriction_On_Attribute
is
1620 Error_Msg_Name_1
:= Aname
;
1621 Check_SPARK_Restriction
("attribute % is not allowed", P
);
1622 end Check_SPARK_Restriction_On_Attribute
;
1624 ---------------------------
1625 -- Check_Standard_Prefix --
1626 ---------------------------
1628 procedure Check_Standard_Prefix
is
1632 if Nkind
(P
) /= N_Identifier
1633 or else Chars
(P
) /= Name_Standard
1635 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1637 end Check_Standard_Prefix
;
1639 ----------------------------
1640 -- Check_Stream_Attribute --
1641 ----------------------------
1643 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1647 In_Shared_Var_Procs
: Boolean;
1648 -- True when compiling the body of System.Shared_Storage.
1649 -- Shared_Var_Procs. For this runtime package (always compiled in
1650 -- GNAT mode), we allow stream attributes references for limited
1651 -- types for the case where shared passive objects are implemented
1652 -- using stream attributes, which is the default in GNAT's persistent
1653 -- storage implementation.
1656 Validate_Non_Static_Attribute_Function_Call
;
1658 -- With the exception of 'Input, Stream attributes are procedures,
1659 -- and can only appear at the position of procedure calls. We check
1660 -- for this here, before they are rewritten, to give a more precise
1663 if Nam
= TSS_Stream_Input
then
1666 elsif Is_List_Member
(N
)
1667 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1674 ("invalid context for attribute%, which is a procedure", N
);
1678 Btyp
:= Implementation_Base_Type
(P_Type
);
1680 -- Stream attributes not allowed on limited types unless the
1681 -- attribute reference was generated by the expander (in which
1682 -- case the underlying type will be used, as described in Sinfo),
1683 -- or the attribute was specified explicitly for the type itself
1684 -- or one of its ancestors (taking visibility rules into account if
1685 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1686 -- (with no visibility restriction).
1689 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1691 if Present
(Gen_Body
) then
1692 In_Shared_Var_Procs
:=
1693 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1695 In_Shared_Var_Procs
:= False;
1699 if (Comes_From_Source
(N
)
1700 and then not (In_Shared_Var_Procs
or In_Instance
))
1701 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1702 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1704 Error_Msg_Name_1
:= Aname
;
1706 if Is_Limited_Type
(P_Type
) then
1708 ("limited type& has no% attribute", P
, P_Type
);
1709 Explain_Limited_Type
(P_Type
, P
);
1712 ("attribute% for type& is not available", P
, P_Type
);
1716 -- Check restriction violations
1718 -- First check the No_Streams restriction, which prohibits the use
1719 -- of explicit stream attributes in the source program. We do not
1720 -- prevent the occurrence of stream attributes in generated code,
1721 -- for instance those generated implicitly for dispatching purposes.
1723 if Comes_From_Source
(N
) then
1724 Check_Restriction
(No_Streams
, P
);
1727 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1728 -- it is illegal to use a predefined elementary type stream attribute
1729 -- either by itself, or more importantly as part of the attribute
1730 -- subprogram for a composite type.
1732 if Restriction_Active
(No_Default_Stream_Attributes
) then
1737 if Nam
= TSS_Stream_Input
1739 Nam
= TSS_Stream_Read
1742 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1745 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1749 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1752 ("missing user-defined Stream Read or Write for type&",
1754 if not Is_Elementary_Type
(P_Type
) then
1756 ("\which is a component of type&", N
, P_Type
);
1762 -- Check special case of Exception_Id and Exception_Occurrence which
1763 -- are not allowed for restriction No_Exception_Registration.
1765 if Restriction_Check_Required
(No_Exception_Registration
)
1766 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1768 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1770 Check_Restriction
(No_Exception_Registration
, P
);
1773 -- Here we must check that the first argument is an access type
1774 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1776 Analyze_And_Resolve
(E1
);
1779 -- Note: the double call to Root_Type here is needed because the
1780 -- root type of a class-wide type is the corresponding type (e.g.
1781 -- X for X'Class, and we really want to go to the root.)
1783 if not Is_Access_Type
(Etyp
)
1784 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1785 RTE
(RE_Root_Stream_Type
)
1788 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1791 -- Check that the second argument is of the right type if there is
1792 -- one (the Input attribute has only one argument so this is skipped)
1794 if Present
(E2
) then
1797 if Nam
= TSS_Stream_Read
1798 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1801 ("second argument of % attribute must be a variable", E2
);
1804 Resolve
(E2
, P_Type
);
1808 end Check_Stream_Attribute
;
1810 -----------------------
1811 -- Check_Task_Prefix --
1812 -----------------------
1814 procedure Check_Task_Prefix
is
1818 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1819 -- task interface class-wide types.
1821 if Is_Task_Type
(Etype
(P
))
1822 or else (Is_Access_Type
(Etype
(P
))
1823 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1824 or else (Ada_Version
>= Ada_2005
1825 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1826 and then Is_Interface
(Etype
(P
))
1827 and then Is_Task_Interface
(Etype
(P
)))
1832 if Ada_Version
>= Ada_2005
then
1834 ("prefix of % attribute must be a task or a task " &
1835 "interface class-wide object");
1838 Error_Attr_P
("prefix of % attribute must be a task");
1841 end Check_Task_Prefix
;
1847 -- The possibilities are an entity name denoting a type, or an
1848 -- attribute reference that denotes a type (Base or Class). If
1849 -- the type is incomplete, replace it with its full view.
1851 procedure Check_Type
is
1853 if not Is_Entity_Name
(P
)
1854 or else not Is_Type
(Entity
(P
))
1856 Error_Attr_P
("prefix of % attribute must be a type");
1858 elsif Is_Protected_Self_Reference
(P
) then
1860 ("prefix of % attribute denotes current instance "
1861 & "(RM 9.4(21/2))");
1863 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1864 and then Present
(Full_View
(Entity
(P
)))
1866 P_Type
:= Full_View
(Entity
(P
));
1867 Set_Entity
(P
, P_Type
);
1871 ---------------------
1872 -- Check_Unit_Name --
1873 ---------------------
1875 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1877 if Nkind
(Nod
) = N_Identifier
then
1880 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
1881 Check_Unit_Name
(Prefix
(Nod
));
1883 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1888 Error_Attr
("argument for % attribute must be unit name", P
);
1889 end Check_Unit_Name
;
1895 procedure Error_Attr
is
1897 Set_Etype
(N
, Any_Type
);
1898 Set_Entity
(N
, Any_Type
);
1899 raise Bad_Attribute
;
1902 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1904 Error_Msg_Name_1
:= Aname
;
1905 Error_Msg_N
(Msg
, Error_Node
);
1913 procedure Error_Attr_P
(Msg
: String) is
1915 Error_Msg_Name_1
:= Aname
;
1916 Error_Msg_F
(Msg
, P
);
1920 ----------------------------
1921 -- Legal_Formal_Attribute --
1922 ----------------------------
1924 procedure Legal_Formal_Attribute
is
1928 if not Is_Entity_Name
(P
)
1929 or else not Is_Type
(Entity
(P
))
1931 Error_Attr_P
("prefix of % attribute must be generic type");
1933 elsif Is_Generic_Actual_Type
(Entity
(P
))
1935 or else In_Inlined_Body
1939 elsif Is_Generic_Type
(Entity
(P
)) then
1940 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1942 ("prefix of % attribute must be indefinite generic type");
1947 ("prefix of % attribute must be indefinite generic type");
1950 Set_Etype
(N
, Standard_Boolean
);
1951 end Legal_Formal_Attribute
;
1953 ------------------------
1954 -- Standard_Attribute --
1955 ------------------------
1957 procedure Standard_Attribute
(Val
: Int
) is
1959 Check_Standard_Prefix
;
1960 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1962 end Standard_Attribute
;
1964 -------------------------
1965 -- Unexpected Argument --
1966 -------------------------
1968 procedure Unexpected_Argument
(En
: Node_Id
) is
1970 Error_Attr
("unexpected argument for % attribute", En
);
1971 end Unexpected_Argument
;
1973 -------------------------------------------------
1974 -- Validate_Non_Static_Attribute_Function_Call --
1975 -------------------------------------------------
1977 -- This function should be moved to Sem_Dist ???
1979 procedure Validate_Non_Static_Attribute_Function_Call
is
1981 if In_Preelaborated_Unit
1982 and then not In_Subprogram_Or_Concurrent_Unit
1984 Flag_Non_Static_Expr
1985 ("non-static function call in preelaborated unit!", N
);
1987 end Validate_Non_Static_Attribute_Function_Call
;
1989 -- Start of processing for Analyze_Attribute
1992 -- Immediate return if unrecognized attribute (already diagnosed
1993 -- by parser, so there is nothing more that we need to do)
1995 if not Is_Attribute_Name
(Aname
) then
1996 raise Bad_Attribute
;
1999 -- Deal with Ada 83 issues
2001 if Comes_From_Source
(N
) then
2002 if not Attribute_83
(Attr_Id
) then
2003 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2004 Error_Msg_Name_1
:= Aname
;
2005 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
2008 if Attribute_Impl_Def
(Attr_Id
) then
2009 Check_Restriction
(No_Implementation_Attributes
, N
);
2014 -- Deal with Ada 2005 attributes that are
2016 if Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
then
2017 Check_Restriction
(No_Implementation_Attributes
, N
);
2020 -- Remote access to subprogram type access attribute reference needs
2021 -- unanalyzed copy for tree transformation. The analyzed copy is used
2022 -- for its semantic information (whether prefix is a remote subprogram
2023 -- name), the unanalyzed copy is used to construct new subtree rooted
2024 -- with N_Aggregate which represents a fat pointer aggregate.
2026 if Aname
= Name_Access
then
2027 Discard_Node
(Copy_Separate_Tree
(N
));
2030 -- Analyze prefix and exit if error in analysis. If the prefix is an
2031 -- incomplete type, use full view if available. Note that there are
2032 -- some attributes for which we do not analyze the prefix, since the
2033 -- prefix is not a normal name, or else needs special handling.
2035 if Aname
/= Name_Elab_Body
2037 Aname
/= Name_Elab_Spec
2039 Aname
/= Name_Elab_Subp_Body
2041 Aname
/= Name_UET_Address
2043 Aname
/= Name_Enabled
2048 P_Type
:= Etype
(P
);
2050 if Is_Entity_Name
(P
)
2051 and then Present
(Entity
(P
))
2052 and then Is_Type
(Entity
(P
))
2054 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2055 P_Type
:= Get_Full_View
(P_Type
);
2056 Set_Entity
(P
, P_Type
);
2057 Set_Etype
(P
, P_Type
);
2059 elsif Entity
(P
) = Current_Scope
2060 and then Is_Record_Type
(Entity
(P
))
2062 -- Use of current instance within the type. Verify that if the
2063 -- attribute appears within a constraint, it yields an access
2064 -- type, other uses are illegal.
2072 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2074 Par
:= Parent
(Par
);
2078 and then Nkind
(Par
) = N_Subtype_Indication
2080 if Attr_Id
/= Attribute_Access
2081 and then Attr_Id
/= Attribute_Unchecked_Access
2082 and then Attr_Id
/= Attribute_Unrestricted_Access
2085 ("in a constraint the current instance can only"
2086 & " be used with an access attribute", N
);
2093 if P_Type
= Any_Type
then
2094 raise Bad_Attribute
;
2097 P_Base_Type
:= Base_Type
(P_Type
);
2100 -- Analyze expressions that may be present, exiting if an error occurs
2107 E1
:= First
(Exprs
);
2110 -- Check for missing/bad expression (result of previous error)
2112 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2113 raise Bad_Attribute
;
2118 if Present
(E2
) then
2121 if Etype
(E2
) = Any_Type
then
2122 raise Bad_Attribute
;
2125 if Present
(Next
(E2
)) then
2126 Unexpected_Argument
(Next
(E2
));
2131 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
2132 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
2134 if Ada_Version
< Ada_2005
2135 and then Is_Overloaded
(P
)
2136 and then Aname
/= Name_Access
2137 and then Aname
/= Name_Address
2138 and then Aname
/= Name_Code_Address
2139 and then Aname
/= Name_Count
2140 and then Aname
/= Name_Result
2141 and then Aname
/= Name_Unchecked_Access
2143 Error_Attr
("ambiguous prefix for % attribute", P
);
2145 elsif Ada_Version
>= Ada_2005
2146 and then Is_Overloaded
(P
)
2147 and then Aname
/= Name_Access
2148 and then Aname
/= Name_Address
2149 and then Aname
/= Name_Code_Address
2150 and then Aname
/= Name_Result
2151 and then Aname
/= Name_Unchecked_Access
2153 -- Ada 2005 (AI-345): Since protected and task types have primitive
2154 -- entry wrappers, the attributes Count, Caller and AST_Entry require
2157 if Ada_Version
>= Ada_2005
2158 and then (Aname
= Name_Count
2159 or else Aname
= Name_Caller
2160 or else Aname
= Name_AST_Entry
)
2163 Count
: Natural := 0;
2168 Get_First_Interp
(P
, I
, It
);
2169 while Present
(It
.Nam
) loop
2170 if Comes_From_Source
(It
.Nam
) then
2176 Get_Next_Interp
(I
, It
);
2180 Error_Attr
("ambiguous prefix for % attribute", P
);
2182 Set_Is_Overloaded
(P
, False);
2187 Error_Attr
("ambiguous prefix for % attribute", P
);
2191 -- In SPARK, attributes of private types are only allowed if the full
2192 -- type declaration is visible.
2194 if Is_Entity_Name
(P
)
2195 and then Present
(Entity
(P
)) -- needed in some cases
2196 and then Is_Type
(Entity
(P
))
2197 and then Is_Private_Type
(P_Type
)
2198 and then not In_Open_Scopes
(Scope
(P_Type
))
2199 and then not In_Spec_Expression
2201 Check_SPARK_Restriction
("invisible attribute of type", N
);
2204 -- Remaining processing depends on attribute
2208 -- Attributes related to Ada 2012 iterators. Attribute specifications
2209 -- exist for these, but they cannot be queried.
2211 when Attribute_Constant_Indexing |
2212 Attribute_Default_Iterator |
2213 Attribute_Implicit_Dereference |
2214 Attribute_Iterator_Element |
2215 Attribute_Variable_Indexing
=>
2216 Error_Msg_N
("illegal attribute", N
);
2218 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2219 -- were already rejected by the parser. Thus they shouldn't appear here.
2221 when Internal_Attribute_Id
=>
2222 raise Program_Error
;
2228 when Attribute_Abort_Signal
=>
2229 Check_Standard_Prefix
;
2230 Rewrite
(N
, New_Reference_To
(Stand
.Abort_Signal
, Loc
));
2237 when Attribute_Access
=>
2238 Analyze_Access_Attribute
;
2244 when Attribute_Address
=>
2247 -- Check for some junk cases, where we have to allow the address
2248 -- attribute but it does not make much sense, so at least for now
2249 -- just replace with Null_Address.
2251 -- We also do this if the prefix is a reference to the AST_Entry
2252 -- attribute. If expansion is active, the attribute will be
2253 -- replaced by a function call, and address will work fine and
2254 -- get the proper value, but if expansion is not active, then
2255 -- the check here allows proper semantic analysis of the reference.
2257 -- An Address attribute created by expansion is legal even when it
2258 -- applies to other entity-denoting expressions.
2260 if Is_Protected_Self_Reference
(P
) then
2262 -- Address attribute on a protected object self reference is legal
2266 elsif Is_Entity_Name
(P
) then
2268 Ent
: constant Entity_Id
:= Entity
(P
);
2271 if Is_Subprogram
(Ent
) then
2272 Set_Address_Taken
(Ent
);
2273 Kill_Current_Values
(Ent
);
2275 -- An Address attribute is accepted when generated by the
2276 -- compiler for dispatching operation, and an error is
2277 -- issued once the subprogram is frozen (to avoid confusing
2278 -- errors about implicit uses of Address in the dispatch
2279 -- table initialization).
2281 if Has_Pragma_Inline_Always
(Entity
(P
))
2282 and then Comes_From_Source
(P
)
2285 ("prefix of % attribute cannot be Inline_Always" &
2288 -- It is illegal to apply 'Address to an intrinsic
2289 -- subprogram. This is now formalized in AI05-0095.
2290 -- In an instance, an attempt to obtain 'Address of an
2291 -- intrinsic subprogram (e.g the renaming of a predefined
2292 -- operator that is an actual) raises Program_Error.
2294 elsif Convention
(Ent
) = Convention_Intrinsic
then
2297 Make_Raise_Program_Error
(Loc
,
2298 Reason
=> PE_Address_Of_Intrinsic
));
2302 ("cannot take Address of intrinsic subprogram", N
);
2305 -- Issue an error if prefix denotes an eliminated subprogram
2308 Check_For_Eliminated_Subprogram
(P
, Ent
);
2311 elsif Is_Object
(Ent
)
2312 or else Ekind
(Ent
) = E_Label
2314 Set_Address_Taken
(Ent
);
2316 -- Deal with No_Implicit_Aliasing restriction
2318 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
2319 if not Is_Aliased_View
(P
) then
2320 Check_Restriction
(No_Implicit_Aliasing
, P
);
2322 Check_No_Implicit_Aliasing
(P
);
2326 -- If we have an address of an object, and the attribute
2327 -- comes from source, then set the object as potentially
2328 -- source modified. We do this because the resulting address
2329 -- can potentially be used to modify the variable and we
2330 -- might not detect this, leading to some junk warnings.
2332 Set_Never_Set_In_Source
(Ent
, False);
2334 elsif (Is_Concurrent_Type
(Etype
(Ent
))
2335 and then Etype
(Ent
) = Base_Type
(Ent
))
2336 or else Ekind
(Ent
) = E_Package
2337 or else Is_Generic_Unit
(Ent
)
2340 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2343 Error_Attr
("invalid prefix for % attribute", P
);
2347 elsif Nkind
(P
) = N_Attribute_Reference
2348 and then Attribute_Name
(P
) = Name_AST_Entry
2351 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2353 elsif Is_Object_Reference
(P
) then
2356 elsif Nkind
(P
) = N_Selected_Component
2357 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
2361 -- What exactly are we allowing here ??? and is this properly
2362 -- documented in the sinfo documentation for this node ???
2364 elsif not Comes_From_Source
(N
) then
2368 Error_Attr
("invalid prefix for % attribute", P
);
2371 Set_Etype
(N
, RTE
(RE_Address
));
2377 when Attribute_Address_Size
=>
2378 Standard_Attribute
(System_Address_Size
);
2384 when Attribute_Adjacent
=>
2385 Check_Floating_Point_Type_2
;
2386 Set_Etype
(N
, P_Base_Type
);
2387 Resolve
(E1
, P_Base_Type
);
2388 Resolve
(E2
, P_Base_Type
);
2394 when Attribute_Aft
=>
2395 Check_Fixed_Point_Type_0
;
2396 Set_Etype
(N
, Universal_Integer
);
2402 when Attribute_Alignment
=>
2404 -- Don't we need more checking here, cf Size ???
2407 Check_Not_Incomplete_Type
;
2409 Set_Etype
(N
, Universal_Integer
);
2415 when Attribute_Asm_Input
=>
2416 Check_Asm_Attribute
;
2418 -- The back-end may need to take the address of E2
2420 if Is_Entity_Name
(E2
) then
2421 Set_Address_Taken
(Entity
(E2
));
2424 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2430 when Attribute_Asm_Output
=>
2431 Check_Asm_Attribute
;
2433 if Etype
(E2
) = Any_Type
then
2436 elsif Aname
= Name_Asm_Output
then
2437 if not Is_Variable
(E2
) then
2439 ("second argument for Asm_Output is not variable", E2
);
2443 Note_Possible_Modification
(E2
, Sure
=> True);
2445 -- The back-end may need to take the address of E2
2447 if Is_Entity_Name
(E2
) then
2448 Set_Address_Taken
(Entity
(E2
));
2451 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2457 when Attribute_AST_Entry
=> AST_Entry
: declare
2463 -- Indicates if entry family index is present. Note the coding
2464 -- here handles the entry family case, but in fact it cannot be
2465 -- executed currently, because pragma AST_Entry does not permit
2466 -- the specification of an entry family.
2468 procedure Bad_AST_Entry
;
2469 -- Signal a bad AST_Entry pragma
2471 function OK_Entry
(E
: Entity_Id
) return Boolean;
2472 -- Checks that E is of an appropriate entity kind for an entry
2473 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2474 -- is set True for the entry family case). In the True case,
2475 -- makes sure that Is_AST_Entry is set on the entry.
2481 procedure Bad_AST_Entry
is
2483 Error_Attr_P
("prefix for % attribute must be task entry");
2490 function OK_Entry
(E
: Entity_Id
) return Boolean is
2495 Result
:= (Ekind
(E
) = E_Entry_Family
);
2497 Result
:= (Ekind
(E
) = E_Entry
);
2501 if not Is_AST_Entry
(E
) then
2502 Error_Msg_Name_2
:= Aname
;
2503 Error_Attr
("% attribute requires previous % pragma", P
);
2510 -- Start of processing for AST_Entry
2516 -- Deal with entry family case
2518 if Nkind
(P
) = N_Indexed_Component
then
2526 Ptyp
:= Etype
(Pref
);
2528 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2532 -- If the prefix is a selected component whose prefix is of an
2533 -- access type, then introduce an explicit dereference.
2534 -- ??? Could we reuse Check_Dereference here?
2536 if Nkind
(Pref
) = N_Selected_Component
2537 and then Is_Access_Type
(Ptyp
)
2540 Make_Explicit_Dereference
(Sloc
(Pref
),
2541 Relocate_Node
(Pref
)));
2542 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2545 -- Prefix can be of the form a.b, where a is a task object
2546 -- and b is one of the entries of the corresponding task type.
2548 if Nkind
(Pref
) = N_Selected_Component
2549 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2550 and then Is_Object_Reference
(Prefix
(Pref
))
2551 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2555 -- Otherwise the prefix must be an entry of a containing task,
2556 -- or of a variable of the enclosing task type.
2559 if Nkind_In
(Pref
, N_Identifier
, N_Expanded_Name
) then
2560 Ent
:= Entity
(Pref
);
2562 if not OK_Entry
(Ent
)
2563 or else not In_Open_Scopes
(Scope
(Ent
))
2573 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2576 -----------------------------
2577 -- Atomic_Always_Lock_Free --
2578 -----------------------------
2580 when Attribute_Atomic_Always_Lock_Free
=>
2583 Set_Etype
(N
, Standard_Boolean
);
2589 -- Note: when the base attribute appears in the context of a subtype
2590 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2591 -- the following circuit.
2593 when Attribute_Base
=> Base
: declare
2601 if Ada_Version
>= Ada_95
2602 and then not Is_Scalar_Type
(Typ
)
2603 and then not Is_Generic_Type
(Typ
)
2605 Error_Attr_P
("prefix of Base attribute must be scalar type");
2607 elsif Sloc
(Typ
) = Standard_Location
2608 and then Base_Type
(Typ
) = Typ
2609 and then Warn_On_Redundant_Constructs
2611 Error_Msg_NE
-- CODEFIX
2612 ("?redundant attribute, & is its own base type", N
, Typ
);
2615 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2616 Error_Msg_Name_1
:= Aname
;
2617 Check_SPARK_Restriction
2618 ("attribute% is only allowed as prefix of another attribute", P
);
2621 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2622 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2623 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2631 when Attribute_Bit
=> Bit
:
2635 if not Is_Object_Reference
(P
) then
2636 Error_Attr_P
("prefix for % attribute must be object");
2638 -- What about the access object cases ???
2644 Set_Etype
(N
, Universal_Integer
);
2651 when Attribute_Bit_Order
=> Bit_Order
:
2656 if not Is_Record_Type
(P_Type
) then
2657 Error_Attr_P
("prefix of % attribute must be record type");
2660 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2662 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2665 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2668 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2671 -- Reset incorrect indication of staticness
2673 Set_Is_Static_Expression
(N
, False);
2680 -- Note: in generated code, we can have a Bit_Position attribute
2681 -- applied to a (naked) record component (i.e. the prefix is an
2682 -- identifier that references an E_Component or E_Discriminant
2683 -- entity directly, and this is interpreted as expected by Gigi.
2684 -- The following code will not tolerate such usage, but when the
2685 -- expander creates this special case, it marks it as analyzed
2686 -- immediately and sets an appropriate type.
2688 when Attribute_Bit_Position
=>
2689 if Comes_From_Source
(N
) then
2693 Set_Etype
(N
, Universal_Integer
);
2699 when Attribute_Body_Version
=>
2702 Set_Etype
(N
, RTE
(RE_Version_String
));
2708 when Attribute_Callable
=>
2710 Set_Etype
(N
, Standard_Boolean
);
2717 when Attribute_Caller
=> Caller
: declare
2724 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2727 if not Is_Entry
(Ent
) then
2728 Error_Attr
("invalid entry name", N
);
2732 Error_Attr
("invalid entry name", N
);
2736 for J
in reverse 0 .. Scope_Stack
.Last
loop
2737 S
:= Scope_Stack
.Table
(J
).Entity
;
2739 if S
= Scope
(Ent
) then
2740 Error_Attr
("Caller must appear in matching accept or body", N
);
2746 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2753 when Attribute_Ceiling
=>
2754 Check_Floating_Point_Type_1
;
2755 Set_Etype
(N
, P_Base_Type
);
2756 Resolve
(E1
, P_Base_Type
);
2762 when Attribute_Class
=>
2763 Check_Restriction
(No_Dispatch
, N
);
2767 -- Applying Class to untagged incomplete type is obsolescent in Ada
2768 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2769 -- this flag gets set by Find_Type in this situation.
2771 if Restriction_Check_Required
(No_Obsolescent_Features
)
2772 and then Ada_Version
>= Ada_2005
2773 and then Ekind
(P_Type
) = E_Incomplete_Type
2776 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2778 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2779 and then not Tagged_Present
(DN
)
2781 Check_Restriction
(No_Obsolescent_Features
, P
);
2790 when Attribute_Code_Address
=>
2793 if Nkind
(P
) = N_Attribute_Reference
2794 and then (Attribute_Name
(P
) = Name_Elab_Body
2796 Attribute_Name
(P
) = Name_Elab_Spec
)
2800 elsif not Is_Entity_Name
(P
)
2801 or else (Ekind
(Entity
(P
)) /= E_Function
2803 Ekind
(Entity
(P
)) /= E_Procedure
)
2805 Error_Attr
("invalid prefix for % attribute", P
);
2806 Set_Address_Taken
(Entity
(P
));
2808 -- Issue an error if the prefix denotes an eliminated subprogram
2811 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2814 Set_Etype
(N
, RTE
(RE_Address
));
2816 ----------------------
2817 -- Compiler_Version --
2818 ----------------------
2820 when Attribute_Compiler_Version
=>
2822 Check_Standard_Prefix
;
2823 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2824 Analyze_And_Resolve
(N
, Standard_String
);
2826 --------------------
2827 -- Component_Size --
2828 --------------------
2830 when Attribute_Component_Size
=>
2832 Set_Etype
(N
, Universal_Integer
);
2834 -- Note: unlike other array attributes, unconstrained arrays are OK
2836 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2846 when Attribute_Compose
=>
2847 Check_Floating_Point_Type_2
;
2848 Set_Etype
(N
, P_Base_Type
);
2849 Resolve
(E1
, P_Base_Type
);
2850 Resolve
(E2
, Any_Integer
);
2856 when Attribute_Constrained
=>
2858 Set_Etype
(N
, Standard_Boolean
);
2860 -- Case from RM J.4(2) of constrained applied to private type
2862 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2863 Check_Restriction
(No_Obsolescent_Features
, P
);
2865 if Warn_On_Obsolescent_Feature
then
2867 ("constrained for private type is an " &
2868 "obsolescent feature (RM J.4)?", N
);
2871 -- If we are within an instance, the attribute must be legal
2872 -- because it was valid in the generic unit. Ditto if this is
2873 -- an inlining of a function declared in an instance.
2876 or else In_Inlined_Body
2880 -- For sure OK if we have a real private type itself, but must
2881 -- be completed, cannot apply Constrained to incomplete type.
2883 elsif Is_Private_Type
(Entity
(P
)) then
2885 -- Note: this is one of the Annex J features that does not
2886 -- generate a warning from -gnatwj, since in fact it seems
2887 -- very useful, and is used in the GNAT runtime.
2889 Check_Not_Incomplete_Type
;
2893 -- Normal (non-obsolescent case) of application to object of
2894 -- a discriminated type.
2897 Check_Object_Reference
(P
);
2899 -- If N does not come from source, then we allow the
2900 -- the attribute prefix to be of a private type whose
2901 -- full type has discriminants. This occurs in cases
2902 -- involving expanded calls to stream attributes.
2904 if not Comes_From_Source
(N
) then
2905 P_Type
:= Underlying_Type
(P_Type
);
2908 -- Must have discriminants or be an access type designating
2909 -- a type with discriminants. If it is a classwide type is ???
2910 -- has unknown discriminants.
2912 if Has_Discriminants
(P_Type
)
2913 or else Has_Unknown_Discriminants
(P_Type
)
2915 (Is_Access_Type
(P_Type
)
2916 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2920 -- Also allow an object of a generic type if extensions allowed
2921 -- and allow this for any type at all.
2923 elsif (Is_Generic_Type
(P_Type
)
2924 or else Is_Generic_Actual_Type
(P_Type
))
2925 and then Extensions_Allowed
2931 -- Fall through if bad prefix
2934 ("prefix of % attribute must be object of discriminated type");
2940 when Attribute_Copy_Sign
=>
2941 Check_Floating_Point_Type_2
;
2942 Set_Etype
(N
, P_Base_Type
);
2943 Resolve
(E1
, P_Base_Type
);
2944 Resolve
(E2
, P_Base_Type
);
2950 when Attribute_Count
=> Count
:
2959 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2962 if Ekind
(Ent
) /= E_Entry
then
2963 Error_Attr
("invalid entry name", N
);
2966 elsif Nkind
(P
) = N_Indexed_Component
then
2967 if not Is_Entity_Name
(Prefix
(P
))
2968 or else No
(Entity
(Prefix
(P
)))
2969 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2971 if Nkind
(Prefix
(P
)) = N_Selected_Component
2972 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2973 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2977 ("attribute % must apply to entry of current task", P
);
2980 Error_Attr
("invalid entry family name", P
);
2985 Ent
:= Entity
(Prefix
(P
));
2988 elsif Nkind
(P
) = N_Selected_Component
2989 and then Present
(Entity
(Selector_Name
(P
)))
2990 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2993 ("attribute % must apply to entry of current task", P
);
2996 Error_Attr
("invalid entry name", N
);
3000 for J
in reverse 0 .. Scope_Stack
.Last
loop
3001 S
:= Scope_Stack
.Table
(J
).Entity
;
3003 if S
= Scope
(Ent
) then
3004 if Nkind
(P
) = N_Expanded_Name
then
3005 Tsk
:= Entity
(Prefix
(P
));
3007 -- The prefix denotes either the task type, or else a
3008 -- single task whose task type is being analyzed.
3013 or else (not Is_Type
(Tsk
)
3014 and then Etype
(Tsk
) = S
3015 and then not (Comes_From_Source
(S
)))
3020 ("Attribute % must apply to entry of current task", N
);
3026 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3028 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3030 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3032 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3033 and then not Has_Completion
(Scope
(Ent
))
3035 Error_Attr
("attribute % can only be used inside body", N
);
3039 if Is_Overloaded
(P
) then
3041 Index
: Interp_Index
;
3045 Get_First_Interp
(P
, Index
, It
);
3047 while Present
(It
.Nam
) loop
3048 if It
.Nam
= Ent
then
3051 -- Ada 2005 (AI-345): Do not consider primitive entry
3052 -- wrappers generated for task or protected types.
3054 elsif Ada_Version
>= Ada_2005
3055 and then not Comes_From_Source
(It
.Nam
)
3060 Error_Attr
("ambiguous entry name", N
);
3063 Get_Next_Interp
(Index
, It
);
3068 Set_Etype
(N
, Universal_Integer
);
3071 -----------------------
3072 -- Default_Bit_Order --
3073 -----------------------
3075 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
3077 Check_Standard_Prefix
;
3079 if Bytes_Big_Endian
then
3081 Make_Integer_Literal
(Loc
, False_Value
));
3084 Make_Integer_Literal
(Loc
, True_Value
));
3087 Set_Etype
(N
, Universal_Integer
);
3088 Set_Is_Static_Expression
(N
);
3089 end Default_Bit_Order
;
3095 when Attribute_Definite
=>
3096 Legal_Formal_Attribute
;
3102 when Attribute_Delta
=>
3103 Check_Fixed_Point_Type_0
;
3104 Set_Etype
(N
, Universal_Real
);
3110 when Attribute_Denorm
=>
3111 Check_Floating_Point_Type_0
;
3112 Set_Etype
(N
, Standard_Boolean
);
3114 ---------------------
3115 -- Descriptor_Size --
3116 ---------------------
3118 when Attribute_Descriptor_Size
=>
3121 if not Is_Entity_Name
(P
)
3122 or else not Is_Type
(Entity
(P
))
3124 Error_Attr_P
("prefix of attribute % must denote a type");
3127 Set_Etype
(N
, Universal_Integer
);
3133 when Attribute_Digits
=>
3137 if not Is_Floating_Point_Type
(P_Type
)
3138 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3141 ("prefix of % attribute must be float or decimal type");
3144 Set_Etype
(N
, Universal_Integer
);
3150 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3152 when Attribute_Elab_Body |
3153 Attribute_Elab_Spec |
3154 Attribute_Elab_Subp_Body
=>
3157 Check_Unit_Name
(P
);
3158 Set_Etype
(N
, Standard_Void_Type
);
3160 -- We have to manually call the expander in this case to get
3161 -- the necessary expansion (normally attributes that return
3162 -- entities are not expanded).
3170 -- Shares processing with Elab_Body
3176 when Attribute_Elaborated
=>
3178 Check_Unit_Name
(P
);
3179 Set_Etype
(N
, Standard_Boolean
);
3185 when Attribute_Emax
=>
3186 Check_Floating_Point_Type_0
;
3187 Set_Etype
(N
, Universal_Integer
);
3193 when Attribute_Enabled
=>
3194 Check_Either_E0_Or_E1
;
3196 if Present
(E1
) then
3197 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3198 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3203 if Nkind
(P
) /= N_Identifier
then
3204 Error_Msg_N
("identifier expected (check name)", P
);
3205 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3206 Error_Msg_N
("& is not a recognized check name", P
);
3209 Set_Etype
(N
, Standard_Boolean
);
3215 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3217 if Present
(E1
) then
3219 Check_Discrete_Type
;
3220 Resolve
(E1
, P_Base_Type
);
3223 if not Is_Entity_Name
(P
)
3224 or else (not Is_Object
(Entity
(P
))
3226 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3229 ("prefix of % attribute must be " &
3230 "discrete type/object or enum literal");
3234 Set_Etype
(N
, Universal_Integer
);
3241 when Attribute_Enum_Val
=> Enum_Val
: begin
3245 if not Is_Enumeration_Type
(P_Type
) then
3246 Error_Attr_P
("prefix of % attribute must be enumeration type");
3249 -- If the enumeration type has a standard representation, the effect
3250 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3252 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3254 Make_Attribute_Reference
(Loc
,
3255 Prefix
=> Relocate_Node
(Prefix
(N
)),
3256 Attribute_Name
=> Name_Val
,
3257 Expressions
=> New_List
(Relocate_Node
(E1
))));
3258 Analyze_And_Resolve
(N
, P_Base_Type
);
3260 -- Non-standard representation case (enumeration with holes)
3264 Resolve
(E1
, Any_Integer
);
3265 Set_Etype
(N
, P_Base_Type
);
3273 when Attribute_Epsilon
=>
3274 Check_Floating_Point_Type_0
;
3275 Set_Etype
(N
, Universal_Real
);
3281 when Attribute_Exponent
=>
3282 Check_Floating_Point_Type_1
;
3283 Set_Etype
(N
, Universal_Integer
);
3284 Resolve
(E1
, P_Base_Type
);
3290 when Attribute_External_Tag
=>
3294 Set_Etype
(N
, Standard_String
);
3296 if not Is_Tagged_Type
(P_Type
) then
3297 Error_Attr_P
("prefix of % attribute must be tagged");
3304 when Attribute_Fast_Math
=>
3305 Check_Standard_Prefix
;
3306 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3312 when Attribute_First
=>
3313 Check_Array_Or_Scalar_Type
;
3314 Bad_Attribute_For_Predicate
;
3320 when Attribute_First_Bit
=>
3322 Set_Etype
(N
, Universal_Integer
);
3328 when Attribute_First_Valid
=>
3329 Check_First_Last_Valid
;
3330 Set_Etype
(N
, P_Type
);
3336 when Attribute_Fixed_Value
=>
3338 Check_Fixed_Point_Type
;
3339 Resolve
(E1
, Any_Integer
);
3340 Set_Etype
(N
, P_Base_Type
);
3346 when Attribute_Floor
=>
3347 Check_Floating_Point_Type_1
;
3348 Set_Etype
(N
, P_Base_Type
);
3349 Resolve
(E1
, P_Base_Type
);
3355 when Attribute_Fore
=>
3356 Check_Fixed_Point_Type_0
;
3357 Set_Etype
(N
, Universal_Integer
);
3363 when Attribute_Fraction
=>
3364 Check_Floating_Point_Type_1
;
3365 Set_Etype
(N
, P_Base_Type
);
3366 Resolve
(E1
, P_Base_Type
);
3372 when Attribute_From_Any
=>
3374 Check_PolyORB_Attribute
;
3375 Set_Etype
(N
, P_Base_Type
);
3377 -----------------------
3378 -- Has_Access_Values --
3379 -----------------------
3381 when Attribute_Has_Access_Values
=>
3384 Set_Etype
(N
, Standard_Boolean
);
3386 -----------------------
3387 -- Has_Tagged_Values --
3388 -----------------------
3390 when Attribute_Has_Tagged_Values
=>
3393 Set_Etype
(N
, Standard_Boolean
);
3395 -----------------------
3396 -- Has_Discriminants --
3397 -----------------------
3399 when Attribute_Has_Discriminants
=>
3400 Legal_Formal_Attribute
;
3406 when Attribute_Identity
=>
3410 if Etype
(P
) = Standard_Exception_Type
then
3411 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3413 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3414 -- task interface class-wide types.
3416 elsif Is_Task_Type
(Etype
(P
))
3417 or else (Is_Access_Type
(Etype
(P
))
3418 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3419 or else (Ada_Version
>= Ada_2005
3420 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3421 and then Is_Interface
(Etype
(P
))
3422 and then Is_Task_Interface
(Etype
(P
)))
3425 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3428 if Ada_Version
>= Ada_2005
then
3430 ("prefix of % attribute must be an exception, a " &
3431 "task or a task interface class-wide object");
3434 ("prefix of % attribute must be a task or an exception");
3442 when Attribute_Image
=> Image
:
3444 Check_SPARK_Restriction_On_Attribute
;
3446 Set_Etype
(N
, Standard_String
);
3448 if Is_Real_Type
(P_Type
) then
3449 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3450 Error_Msg_Name_1
:= Aname
;
3452 ("(Ada 83) % attribute not allowed for real types", N
);
3456 if Is_Enumeration_Type
(P_Type
) then
3457 Check_Restriction
(No_Enumeration_Maps
, N
);
3461 Resolve
(E1
, P_Base_Type
);
3463 Validate_Non_Static_Attribute_Function_Call
;
3470 when Attribute_Img
=> Img
:
3473 Set_Etype
(N
, Standard_String
);
3475 if not Is_Scalar_Type
(P_Type
)
3476 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3479 ("prefix of % attribute must be scalar object name");
3489 when Attribute_Input
=>
3491 Check_Stream_Attribute
(TSS_Stream_Input
);
3492 Set_Etype
(N
, P_Base_Type
);
3498 when Attribute_Integer_Value
=>
3501 Resolve
(E1
, Any_Fixed
);
3503 -- Signal an error if argument type is not a specific fixed-point
3504 -- subtype. An error has been signalled already if the argument
3505 -- was not of a fixed-point type.
3507 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3508 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3511 Set_Etype
(N
, P_Base_Type
);
3517 when Attribute_Invalid_Value
=>
3520 Set_Etype
(N
, P_Base_Type
);
3521 Invalid_Value_Used
:= True;
3527 when Attribute_Large
=>
3530 Set_Etype
(N
, Universal_Real
);
3536 when Attribute_Last
=>
3537 Check_Array_Or_Scalar_Type
;
3538 Bad_Attribute_For_Predicate
;
3544 when Attribute_Last_Bit
=>
3546 Set_Etype
(N
, Universal_Integer
);
3552 when Attribute_Last_Valid
=>
3553 Check_First_Last_Valid
;
3554 Set_Etype
(N
, P_Type
);
3560 when Attribute_Leading_Part
=>
3561 Check_Floating_Point_Type_2
;
3562 Set_Etype
(N
, P_Base_Type
);
3563 Resolve
(E1
, P_Base_Type
);
3564 Resolve
(E2
, Any_Integer
);
3570 when Attribute_Length
=>
3572 Set_Etype
(N
, Universal_Integer
);
3578 when Attribute_Lock_Free
=>
3580 Set_Etype
(N
, Standard_Boolean
);
3582 if not Is_Protected_Type
(P_Type
) then
3584 ("prefix of % attribute must be a protected object");
3591 when Attribute_Machine
=>
3592 Check_Floating_Point_Type_1
;
3593 Set_Etype
(N
, P_Base_Type
);
3594 Resolve
(E1
, P_Base_Type
);
3600 when Attribute_Machine_Emax
=>
3601 Check_Floating_Point_Type_0
;
3602 Set_Etype
(N
, Universal_Integer
);
3608 when Attribute_Machine_Emin
=>
3609 Check_Floating_Point_Type_0
;
3610 Set_Etype
(N
, Universal_Integer
);
3612 ----------------------
3613 -- Machine_Mantissa --
3614 ----------------------
3616 when Attribute_Machine_Mantissa
=>
3617 Check_Floating_Point_Type_0
;
3618 Set_Etype
(N
, Universal_Integer
);
3620 -----------------------
3621 -- Machine_Overflows --
3622 -----------------------
3624 when Attribute_Machine_Overflows
=>
3627 Set_Etype
(N
, Standard_Boolean
);
3633 when Attribute_Machine_Radix
=>
3636 Set_Etype
(N
, Universal_Integer
);
3638 ----------------------
3639 -- Machine_Rounding --
3640 ----------------------
3642 when Attribute_Machine_Rounding
=>
3643 Check_Floating_Point_Type_1
;
3644 Set_Etype
(N
, P_Base_Type
);
3645 Resolve
(E1
, P_Base_Type
);
3647 --------------------
3648 -- Machine_Rounds --
3649 --------------------
3651 when Attribute_Machine_Rounds
=>
3654 Set_Etype
(N
, Standard_Boolean
);
3660 when Attribute_Machine_Size
=>
3663 Check_Not_Incomplete_Type
;
3664 Set_Etype
(N
, Universal_Integer
);
3670 when Attribute_Mantissa
=>
3673 Set_Etype
(N
, Universal_Integer
);
3679 when Attribute_Max
=>
3682 Resolve
(E1
, P_Base_Type
);
3683 Resolve
(E2
, P_Base_Type
);
3684 Set_Etype
(N
, P_Base_Type
);
3686 ----------------------------------
3687 -- Max_Alignment_For_Allocation --
3688 -- Max_Size_In_Storage_Elements --
3689 ----------------------------------
3691 when Attribute_Max_Alignment_For_Allocation |
3692 Attribute_Max_Size_In_Storage_Elements
=>
3695 Check_Not_Incomplete_Type
;
3696 Set_Etype
(N
, Universal_Integer
);
3698 -----------------------
3699 -- Maximum_Alignment --
3700 -----------------------
3702 when Attribute_Maximum_Alignment
=>
3703 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3705 --------------------
3706 -- Mechanism_Code --
3707 --------------------
3709 when Attribute_Mechanism_Code
=>
3710 if not Is_Entity_Name
(P
)
3711 or else not Is_Subprogram
(Entity
(P
))
3713 Error_Attr_P
("prefix of % attribute must be subprogram");
3716 Check_Either_E0_Or_E1
;
3718 if Present
(E1
) then
3719 Resolve
(E1
, Any_Integer
);
3720 Set_Etype
(E1
, Standard_Integer
);
3722 if not Is_Static_Expression
(E1
) then
3723 Flag_Non_Static_Expr
3724 ("expression for parameter number must be static!", E1
);
3727 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3728 or else UI_To_Int
(Intval
(E1
)) < 0
3730 Error_Attr
("invalid parameter number for % attribute", E1
);
3734 Set_Etype
(N
, Universal_Integer
);
3740 when Attribute_Min
=>
3743 Resolve
(E1
, P_Base_Type
);
3744 Resolve
(E2
, P_Base_Type
);
3745 Set_Etype
(N
, P_Base_Type
);
3751 when Attribute_Mod
=>
3753 -- Note: this attribute is only allowed in Ada 2005 mode, but
3754 -- we do not need to test that here, since Mod is only recognized
3755 -- as an attribute name in Ada 2005 mode during the parse.
3758 Check_Modular_Integer_Type
;
3759 Resolve
(E1
, Any_Integer
);
3760 Set_Etype
(N
, P_Base_Type
);
3766 when Attribute_Model
=>
3767 Check_Floating_Point_Type_1
;
3768 Set_Etype
(N
, P_Base_Type
);
3769 Resolve
(E1
, P_Base_Type
);
3775 when Attribute_Model_Emin
=>
3776 Check_Floating_Point_Type_0
;
3777 Set_Etype
(N
, Universal_Integer
);
3783 when Attribute_Model_Epsilon
=>
3784 Check_Floating_Point_Type_0
;
3785 Set_Etype
(N
, Universal_Real
);
3787 --------------------
3788 -- Model_Mantissa --
3789 --------------------
3791 when Attribute_Model_Mantissa
=>
3792 Check_Floating_Point_Type_0
;
3793 Set_Etype
(N
, Universal_Integer
);
3799 when Attribute_Model_Small
=>
3800 Check_Floating_Point_Type_0
;
3801 Set_Etype
(N
, Universal_Real
);
3807 when Attribute_Modulus
=>
3809 Check_Modular_Integer_Type
;
3810 Set_Etype
(N
, Universal_Integer
);
3812 --------------------
3813 -- Null_Parameter --
3814 --------------------
3816 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3817 Parnt
: constant Node_Id
:= Parent
(N
);
3818 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3820 procedure Bad_Null_Parameter
(Msg
: String);
3821 -- Used if bad Null parameter attribute node is found. Issues
3822 -- given error message, and also sets the type to Any_Type to
3823 -- avoid blowups later on from dealing with a junk node.
3825 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3826 -- Called to check that Proc_Ent is imported subprogram
3828 ------------------------
3829 -- Bad_Null_Parameter --
3830 ------------------------
3832 procedure Bad_Null_Parameter
(Msg
: String) is
3834 Error_Msg_N
(Msg
, N
);
3835 Set_Etype
(N
, Any_Type
);
3836 end Bad_Null_Parameter
;
3838 ----------------------
3839 -- Must_Be_Imported --
3840 ----------------------
3842 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3843 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
3846 -- Ignore check if procedure not frozen yet (we will get
3847 -- another chance when the default parameter is reanalyzed)
3849 if not Is_Frozen
(Pent
) then
3852 elsif not Is_Imported
(Pent
) then
3854 ("Null_Parameter can only be used with imported subprogram");
3859 end Must_Be_Imported
;
3861 -- Start of processing for Null_Parameter
3866 Set_Etype
(N
, P_Type
);
3868 -- Case of attribute used as default expression
3870 if Nkind
(Parnt
) = N_Parameter_Specification
then
3871 Must_Be_Imported
(Defining_Entity
(GParnt
));
3873 -- Case of attribute used as actual for subprogram (positional)
3875 elsif Nkind
(Parnt
) in N_Subprogram_Call
3876 and then Is_Entity_Name
(Name
(Parnt
))
3878 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3880 -- Case of attribute used as actual for subprogram (named)
3882 elsif Nkind
(Parnt
) = N_Parameter_Association
3883 and then Nkind
(GParnt
) in N_Subprogram_Call
3884 and then Is_Entity_Name
(Name
(GParnt
))
3886 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3888 -- Not an allowed case
3892 ("Null_Parameter must be actual or default parameter");
3900 when Attribute_Object_Size
=>
3903 Check_Not_Incomplete_Type
;
3904 Set_Etype
(N
, Universal_Integer
);
3910 when Attribute_Old
=> Old
: declare
3912 -- The enclosing scope, excluding loops for quantified expressions.
3913 -- During analysis, it is the postcondition subprogram. During
3914 -- pre-analysis, it is the scope of the subprogram declaration.
3917 -- During pre-analysis, Prag is the enclosing pragma node if any
3920 -- Find enclosing scopes, excluding loops
3922 CS
:= Current_Scope
;
3923 while Ekind
(CS
) = E_Loop
loop
3927 -- If we are in Spec_Expression mode, this should be the prescan of
3928 -- the postcondition (or contract case, or test case) pragma.
3930 if In_Spec_Expression
then
3932 -- Check in postcondition or Ensures clause
3935 while not Nkind_In
(Prag
, N_Pragma
,
3936 N_Function_Specification
,
3937 N_Procedure_Specification
,
3940 Prag
:= Parent
(Prag
);
3943 if Nkind
(Prag
) /= N_Pragma
then
3944 Error_Attr
("% attribute can only appear in postcondition", P
);
3946 elsif Get_Pragma_Id
(Prag
) = Pragma_Contract_Case
3948 Get_Pragma_Id
(Prag
) = Pragma_Test_Case
3951 Arg_Ens
: constant Node_Id
:=
3952 Get_Ensures_From_CTC_Pragma
(Prag
);
3957 while Arg
/= Prag
and Arg
/= Arg_Ens
loop
3958 Arg
:= Parent
(Arg
);
3961 if Arg
/= Arg_Ens
then
3962 if Get_Pragma_Id
(Prag
) = Pragma_Contract_Case
then
3964 ("% attribute misplaced inside contract case", P
);
3967 ("% attribute misplaced inside test case", P
);
3972 elsif Get_Pragma_Id
(Prag
) /= Pragma_Postcondition
then
3973 Error_Attr
("% attribute can only appear in postcondition", P
);
3976 -- Body case, where we must be inside a generated _Postcondition
3977 -- procedure, or else the attribute use is definitely misplaced. The
3978 -- postcondition itself may have generated transient scopes, and is
3979 -- not necessarily the current one.
3982 while Present
(CS
) and then CS
/= Standard_Standard
loop
3983 if Chars
(CS
) = Name_uPostconditions
then
3990 if Chars
(CS
) /= Name_uPostconditions
then
3991 Error_Attr
("% attribute can only appear in postcondition", P
);
3995 -- Either the attribute reference is generated for a Requires
3996 -- clause, in which case no expressions follow, or it is a
3997 -- primary. In that case, if expressions follow, the attribute
3998 -- reference is an indexable object, so rewrite the node
4001 if Present
(E1
) then
4003 Make_Indexed_Component
(Loc
,
4005 Make_Attribute_Reference
(Loc
,
4006 Prefix
=> Relocate_Node
(Prefix
(N
)),
4007 Attribute_Name
=> Name_Old
),
4008 Expressions
=> Expressions
(N
)));
4016 -- Prefix has not been analyzed yet, and its full analysis will
4017 -- take place during expansion (see below).
4019 Preanalyze_And_Resolve
(P
);
4020 P_Type
:= Etype
(P
);
4021 Set_Etype
(N
, P_Type
);
4023 if Is_Limited_Type
(P_Type
) then
4024 Error_Attr
("attribute % cannot apply to limited objects", P
);
4027 if Is_Entity_Name
(P
)
4028 and then Is_Constant_Object
(Entity
(P
))
4031 ("?attribute Old applied to constant has no effect", P
);
4034 -- The attribute appears within a pre/postcondition, but refers to
4035 -- an entity in the enclosing subprogram. If it is a component of
4036 -- a formal its expansion might generate actual subtypes that may
4037 -- be referenced in an inner context, and which must be elaborated
4038 -- within the subprogram itself. If the prefix includes a function
4039 -- call it may involve finalization actions that should only be
4040 -- inserted when the attribute has been rewritten as a declarations.
4041 -- As a result, if the prefix is not a simple name we create
4042 -- a declaration for it now, and insert it at the start of the
4043 -- enclosing subprogram. This is properly an expansion activity
4044 -- but it has to be performed now to prevent out-of-order issues.
4046 -- This expansion is both harmful and not needed in Alfa mode, since
4047 -- the formal verification backend relies on the types of nodes
4048 -- (hence is not robust w.r.t. a change to base type here), and does
4049 -- not suffer from the out-of-order issue described above. Thus, this
4050 -- expansion is skipped in Alfa mode.
4052 if not Is_Entity_Name
(P
) and then not Alfa_Mode
then
4053 P_Type
:= Base_Type
(P_Type
);
4054 Set_Etype
(N
, P_Type
);
4055 Set_Etype
(P
, P_Type
);
4060 ----------------------
4061 -- Overlaps_Storage --
4062 ----------------------
4064 when Attribute_Overlaps_Storage
=>
4065 Check_Ada_2012_Attribute
;
4068 -- Both arguments must be objects of any type
4070 Analyze_And_Resolve
(P
);
4071 Analyze_And_Resolve
(E1
);
4072 Check_Object_Reference
(P
);
4073 Check_Object_Reference
(E1
);
4074 Set_Etype
(N
, Standard_Boolean
);
4080 when Attribute_Output
=>
4082 Check_Stream_Attribute
(TSS_Stream_Output
);
4083 Set_Etype
(N
, Standard_Void_Type
);
4084 Resolve
(N
, Standard_Void_Type
);
4090 when Attribute_Partition_ID
=> Partition_Id
:
4094 if P_Type
/= Any_Type
then
4095 if not Is_Library_Level_Entity
(Entity
(P
)) then
4097 ("prefix of % attribute must be library-level entity");
4099 -- The defining entity of prefix should not be declared inside a
4100 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4102 elsif Is_Entity_Name
(P
)
4103 and then Is_Pure
(Entity
(P
))
4105 Error_Attr_P
("prefix of% attribute must not be declared pure");
4109 Set_Etype
(N
, Universal_Integer
);
4112 -------------------------
4113 -- Passed_By_Reference --
4114 -------------------------
4116 when Attribute_Passed_By_Reference
=>
4119 Set_Etype
(N
, Standard_Boolean
);
4125 when Attribute_Pool_Address
=>
4127 Set_Etype
(N
, RTE
(RE_Address
));
4133 when Attribute_Pos
=>
4134 Check_Discrete_Type
;
4137 if Is_Boolean_Type
(P_Type
) then
4138 Error_Msg_Name_1
:= Aname
;
4139 Error_Msg_Name_2
:= Chars
(P_Type
);
4140 Check_SPARK_Restriction
4141 ("attribute% is not allowed for type%", P
);
4144 Resolve
(E1
, P_Base_Type
);
4145 Set_Etype
(N
, Universal_Integer
);
4151 when Attribute_Position
=>
4153 Set_Etype
(N
, Universal_Integer
);
4159 when Attribute_Pred
=>
4163 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4164 Error_Msg_Name_1
:= Aname
;
4165 Error_Msg_Name_2
:= Chars
(P_Type
);
4166 Check_SPARK_Restriction
4167 ("attribute% is not allowed for type%", P
);
4170 Resolve
(E1
, P_Base_Type
);
4171 Set_Etype
(N
, P_Base_Type
);
4173 -- Nothing to do for real type case
4175 if Is_Real_Type
(P_Type
) then
4178 -- If not modular type, test for overflow check required
4181 if not Is_Modular_Integer_Type
(P_Type
)
4182 and then not Range_Checks_Suppressed
(P_Base_Type
)
4184 Enable_Range_Check
(E1
);
4192 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4194 when Attribute_Priority
=>
4195 if Ada_Version
< Ada_2005
then
4196 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4201 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4205 if Is_Protected_Type
(Etype
(P
))
4206 or else (Is_Access_Type
(Etype
(P
))
4207 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4209 Resolve
(P
, Etype
(P
));
4211 Error_Attr_P
("prefix of % attribute must be a protected object");
4214 Set_Etype
(N
, Standard_Integer
);
4216 -- Must be called from within a protected procedure or entry of the
4217 -- protected object.
4224 while S
/= Etype
(P
)
4225 and then S
/= Standard_Standard
4230 if S
= Standard_Standard
then
4231 Error_Attr
("the attribute % is only allowed inside protected "
4236 Validate_Non_Static_Attribute_Function_Call
;
4242 when Attribute_Range
=>
4243 Check_Array_Or_Scalar_Type
;
4244 Bad_Attribute_For_Predicate
;
4246 if Ada_Version
= Ada_83
4247 and then Is_Scalar_Type
(P_Type
)
4248 and then Comes_From_Source
(N
)
4251 ("(Ada 83) % attribute not allowed for scalar type", P
);
4258 when Attribute_Result
=> Result
: declare
4260 -- The enclosing scope, excluding loops for quantified expressions
4263 -- During analysis, CS is the postcondition subprogram and PS the
4264 -- source subprogram to which the postcondition applies. During
4265 -- pre-analysis, CS is the scope of the subprogram declaration.
4268 -- During pre-analysis, Prag is the enclosing pragma node if any
4271 -- Find enclosing scopes, excluding loops
4273 CS
:= Current_Scope
;
4274 while Ekind
(CS
) = E_Loop
loop
4280 -- If the enclosing subprogram is always inlined, the enclosing
4281 -- postcondition will not be propagated to the expanded call.
4283 if not In_Spec_Expression
4284 and then Has_Pragma_Inline_Always
(PS
)
4285 and then Warn_On_Redundant_Constructs
4288 ("postconditions on inlined functions not enforced?", N
);
4291 -- If we are in the scope of a function and in Spec_Expression mode,
4292 -- this is likely the prescan of the postcondition (or contract case,
4293 -- or test case) pragma, and we just set the proper type. If there is
4294 -- an error it will be caught when the real Analyze call is done.
4296 if Ekind
(CS
) = E_Function
4297 and then In_Spec_Expression
4301 if Chars
(CS
) /= Chars
(P
) then
4302 Error_Msg_Name_1
:= Name_Result
;
4305 ("incorrect prefix for % attribute, expected &", P
, CS
);
4309 -- Check in postcondition or Ensures clause of function
4312 while not Nkind_In
(Prag
, N_Pragma
,
4313 N_Function_Specification
,
4316 Prag
:= Parent
(Prag
);
4319 if Nkind
(Prag
) /= N_Pragma
then
4321 ("% attribute can only appear in postcondition of function",
4324 elsif Get_Pragma_Id
(Prag
) = Pragma_Contract_Case
4326 Get_Pragma_Id
(Prag
) = Pragma_Test_Case
4329 Arg_Ens
: constant Node_Id
:=
4330 Get_Ensures_From_CTC_Pragma
(Prag
);
4335 while Arg
/= Prag
and Arg
/= Arg_Ens
loop
4336 Arg
:= Parent
(Arg
);
4339 if Arg
/= Arg_Ens
then
4340 if Get_Pragma_Id
(Prag
) = Pragma_Contract_Case
then
4342 ("% attribute misplaced inside contract case", P
);
4345 ("% attribute misplaced inside test case", P
);
4350 elsif Get_Pragma_Id
(Prag
) /= Pragma_Postcondition
then
4352 ("% attribute can only appear in postcondition of function",
4356 -- The attribute reference is a primary. If expressions follow,
4357 -- the attribute reference is really an indexable object, so
4358 -- rewrite and analyze as an indexed component.
4360 if Present
(E1
) then
4362 Make_Indexed_Component
(Loc
,
4364 Make_Attribute_Reference
(Loc
,
4365 Prefix
=> Relocate_Node
(Prefix
(N
)),
4366 Attribute_Name
=> Name_Result
),
4367 Expressions
=> Expressions
(N
)));
4372 Set_Etype
(N
, Etype
(CS
));
4374 -- If several functions with that name are visible,
4375 -- the intended one is the current scope.
4377 if Is_Overloaded
(P
) then
4379 Set_Is_Overloaded
(P
, False);
4382 -- Body case, where we must be inside a generated _Postcondition
4383 -- procedure, and the prefix must be on the scope stack, or else the
4384 -- attribute use is definitely misplaced. The postcondition itself
4385 -- may have generated transient scopes, and is not necessarily the
4389 while Present
(CS
) and then CS
/= Standard_Standard
loop
4390 if Chars
(CS
) = Name_uPostconditions
then
4399 if Chars
(CS
) = Name_uPostconditions
4400 and then Ekind
(PS
) = E_Function
4404 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
4405 and then Chars
(P
) = Chars
(PS
)
4409 -- Within an instance, the prefix designates the local renaming
4410 -- of the original generic.
4412 elsif Is_Entity_Name
(P
)
4413 and then Ekind
(Entity
(P
)) = E_Function
4414 and then Present
(Alias
(Entity
(P
)))
4415 and then Chars
(Alias
(Entity
(P
))) = Chars
(PS
)
4421 ("incorrect prefix for % attribute, expected &", P
, PS
);
4425 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
4426 Analyze_And_Resolve
(N
, Etype
(PS
));
4430 ("% attribute can only appear in postcondition of function",
4440 when Attribute_Range_Length
=>
4442 Check_Discrete_Type
;
4443 Set_Etype
(N
, Universal_Integer
);
4449 when Attribute_Read
=>
4451 Check_Stream_Attribute
(TSS_Stream_Read
);
4452 Set_Etype
(N
, Standard_Void_Type
);
4453 Resolve
(N
, Standard_Void_Type
);
4454 Note_Possible_Modification
(E2
, Sure
=> True);
4460 when Attribute_Ref
=>
4464 if Nkind
(P
) /= N_Expanded_Name
4465 or else not Is_RTE
(P_Type
, RE_Address
)
4467 Error_Attr_P
("prefix of % attribute must be System.Address");
4470 Analyze_And_Resolve
(E1
, Any_Integer
);
4471 Set_Etype
(N
, RTE
(RE_Address
));
4477 when Attribute_Remainder
=>
4478 Check_Floating_Point_Type_2
;
4479 Set_Etype
(N
, P_Base_Type
);
4480 Resolve
(E1
, P_Base_Type
);
4481 Resolve
(E2
, P_Base_Type
);
4487 when Attribute_Round
=>
4489 Check_Decimal_Fixed_Point_Type
;
4490 Set_Etype
(N
, P_Base_Type
);
4492 -- Because the context is universal_real (3.5.10(12)) it is a
4493 -- legal context for a universal fixed expression. This is the
4494 -- only attribute whose functional description involves U_R.
4496 if Etype
(E1
) = Universal_Fixed
then
4498 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
4499 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
4500 Expression
=> Relocate_Node
(E1
));
4508 Resolve
(E1
, Any_Real
);
4514 when Attribute_Rounding
=>
4515 Check_Floating_Point_Type_1
;
4516 Set_Etype
(N
, P_Base_Type
);
4517 Resolve
(E1
, P_Base_Type
);
4523 when Attribute_Safe_Emax
=>
4524 Check_Floating_Point_Type_0
;
4525 Set_Etype
(N
, Universal_Integer
);
4531 when Attribute_Safe_First
=>
4532 Check_Floating_Point_Type_0
;
4533 Set_Etype
(N
, Universal_Real
);
4539 when Attribute_Safe_Large
=>
4542 Set_Etype
(N
, Universal_Real
);
4548 when Attribute_Safe_Last
=>
4549 Check_Floating_Point_Type_0
;
4550 Set_Etype
(N
, Universal_Real
);
4556 when Attribute_Safe_Small
=>
4559 Set_Etype
(N
, Universal_Real
);
4565 when Attribute_Same_Storage
=>
4566 Check_Ada_2012_Attribute
;
4569 -- The arguments must be objects of any type
4571 Analyze_And_Resolve
(P
);
4572 Analyze_And_Resolve
(E1
);
4573 Check_Object_Reference
(P
);
4574 Check_Object_Reference
(E1
);
4575 Set_Etype
(N
, Standard_Boolean
);
4577 --------------------------
4578 -- Scalar_Storage_Order --
4579 --------------------------
4581 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
4586 if not Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
) then
4588 ("prefix of % attribute must be record or array type");
4591 if Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
4593 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
4596 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
4599 Set_Etype
(N
, RTE
(RE_Bit_Order
));
4602 -- Reset incorrect indication of staticness
4604 Set_Is_Static_Expression
(N
, False);
4605 end Scalar_Storage_Order
;
4611 when Attribute_Scale
=>
4613 Check_Decimal_Fixed_Point_Type
;
4614 Set_Etype
(N
, Universal_Integer
);
4620 when Attribute_Scaling
=>
4621 Check_Floating_Point_Type_2
;
4622 Set_Etype
(N
, P_Base_Type
);
4623 Resolve
(E1
, P_Base_Type
);
4629 when Attribute_Signed_Zeros
=>
4630 Check_Floating_Point_Type_0
;
4631 Set_Etype
(N
, Standard_Boolean
);
4637 when Attribute_Size | Attribute_VADS_Size
=> Size
:
4641 -- If prefix is parameterless function call, rewrite and resolve
4644 if Is_Entity_Name
(P
)
4645 and then Ekind
(Entity
(P
)) = E_Function
4649 -- Similar processing for a protected function call
4651 elsif Nkind
(P
) = N_Selected_Component
4652 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
4657 if Is_Object_Reference
(P
) then
4658 Check_Object_Reference
(P
);
4660 elsif Is_Entity_Name
(P
)
4661 and then (Is_Type
(Entity
(P
))
4662 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
4666 elsif Nkind
(P
) = N_Type_Conversion
4667 and then not Comes_From_Source
(P
)
4672 Error_Attr_P
("invalid prefix for % attribute");
4675 Check_Not_Incomplete_Type
;
4677 Set_Etype
(N
, Universal_Integer
);
4684 when Attribute_Small
=>
4687 Set_Etype
(N
, Universal_Real
);
4693 when Attribute_Storage_Pool |
4694 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
4698 if Is_Access_Type
(P_Type
) then
4699 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
4701 ("cannot use % attribute for access-to-subprogram type");
4704 -- Set appropriate entity
4706 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
4707 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
4709 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
4712 if Attr_Id
= Attribute_Storage_Pool
then
4713 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
4714 Name_Simple_Storage_Pool_Type
))
4716 Error_Msg_Name_1
:= Aname
;
4717 Error_Msg_N
("cannot use % attribute for type with simple " &
4718 "storage pool?", N
);
4720 ("\Program_Error will be raised at run time?", N
);
4723 (N
, Make_Raise_Program_Error
4724 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
4727 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
4729 -- In the Simple_Storage_Pool case, verify that the pool entity is
4730 -- actually of a simple storage pool type, and set the attribute's
4731 -- type to the pool object's type.
4734 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
4735 Name_Simple_Storage_Pool_Type
))
4738 ("cannot use % attribute for type without simple " &
4742 Set_Etype
(N
, Etype
(Entity
(N
)));
4745 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4746 -- Storage_Pool since this attribute is not defined for such
4747 -- types (RM E.2.3(22)).
4749 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4752 Error_Attr_P
("prefix of % attribute must be access type");
4760 when Attribute_Storage_Size
=> Storage_Size
:
4764 if Is_Task_Type
(P_Type
) then
4765 Set_Etype
(N
, Universal_Integer
);
4767 -- Use with tasks is an obsolescent feature
4769 Check_Restriction
(No_Obsolescent_Features
, P
);
4771 elsif Is_Access_Type
(P_Type
) then
4772 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
4774 ("cannot use % attribute for access-to-subprogram type");
4777 if Is_Entity_Name
(P
)
4778 and then Is_Type
(Entity
(P
))
4781 Set_Etype
(N
, Universal_Integer
);
4783 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4784 -- Storage_Size since this attribute is not defined for
4785 -- such types (RM E.2.3(22)).
4787 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4789 -- The prefix is allowed to be an implicit dereference of an
4790 -- access value designating a task.
4794 Set_Etype
(N
, Universal_Integer
);
4798 Error_Attr_P
("prefix of % attribute must be access or task type");
4806 when Attribute_Storage_Unit
=>
4807 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
4813 when Attribute_Stream_Size
=>
4817 if Is_Entity_Name
(P
)
4818 and then Is_Elementary_Type
(Entity
(P
))
4820 Set_Etype
(N
, Universal_Integer
);
4822 Error_Attr_P
("invalid prefix for % attribute");
4829 when Attribute_Stub_Type
=>
4833 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
4835 -- For a real RACW [sub]type, use corresponding stub type
4837 if not Is_Generic_Type
(P_Type
) then
4840 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
4842 -- For a generic type (that has been marked as an RACW using the
4843 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
4844 -- type. Note that if the actual is not a remote access type, the
4845 -- instantiation will fail.
4848 -- Note: we go to the underlying type here because the view
4849 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
4853 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
4858 ("prefix of% attribute must be remote access to classwide");
4865 when Attribute_Succ
=>
4869 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4870 Error_Msg_Name_1
:= Aname
;
4871 Error_Msg_Name_2
:= Chars
(P_Type
);
4872 Check_SPARK_Restriction
4873 ("attribute% is not allowed for type%", P
);
4876 Resolve
(E1
, P_Base_Type
);
4877 Set_Etype
(N
, P_Base_Type
);
4879 -- Nothing to do for real type case
4881 if Is_Real_Type
(P_Type
) then
4884 -- If not modular type, test for overflow check required
4887 if not Is_Modular_Integer_Type
(P_Type
)
4888 and then not Range_Checks_Suppressed
(P_Base_Type
)
4890 Enable_Range_Check
(E1
);
4894 --------------------------------
4895 -- System_Allocator_Alignment --
4896 --------------------------------
4898 when Attribute_System_Allocator_Alignment
=>
4899 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
4905 when Attribute_Tag
=> Tag
:
4910 if not Is_Tagged_Type
(P_Type
) then
4911 Error_Attr_P
("prefix of % attribute must be tagged");
4913 -- Next test does not apply to generated code
4914 -- why not, and what does the illegal reference mean???
4916 elsif Is_Object_Reference
(P
)
4917 and then not Is_Class_Wide_Type
(P_Type
)
4918 and then Comes_From_Source
(N
)
4921 ("% attribute can only be applied to objects " &
4922 "of class - wide type");
4925 -- The prefix cannot be an incomplete type. However, references
4926 -- to 'Tag can be generated when expanding interface conversions,
4927 -- and this is legal.
4929 if Comes_From_Source
(N
) then
4930 Check_Not_Incomplete_Type
;
4933 -- Set appropriate type
4935 Set_Etype
(N
, RTE
(RE_Tag
));
4942 when Attribute_Target_Name
=> Target_Name
: declare
4943 TN
: constant String := Sdefault
.Target_Name
.all;
4947 Check_Standard_Prefix
;
4951 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
4956 Make_String_Literal
(Loc
,
4957 Strval
=> TN
(TN
'First .. TL
)));
4958 Analyze_And_Resolve
(N
, Standard_String
);
4965 when Attribute_Terminated
=>
4967 Set_Etype
(N
, Standard_Boolean
);
4974 when Attribute_To_Address
=>
4978 if Nkind
(P
) /= N_Identifier
4979 or else Chars
(P
) /= Name_System
4981 Error_Attr_P
("prefix of % attribute must be System");
4984 Generate_Reference
(RTE
(RE_Address
), P
);
4985 Analyze_And_Resolve
(E1
, Any_Integer
);
4986 Set_Etype
(N
, RTE
(RE_Address
));
4992 when Attribute_To_Any
=>
4994 Check_PolyORB_Attribute
;
4995 Set_Etype
(N
, RTE
(RE_Any
));
5001 when Attribute_Truncation
=>
5002 Check_Floating_Point_Type_1
;
5003 Resolve
(E1
, P_Base_Type
);
5004 Set_Etype
(N
, P_Base_Type
);
5010 when Attribute_Type_Class
=>
5013 Check_Not_Incomplete_Type
;
5014 Set_Etype
(N
, RTE
(RE_Type_Class
));
5020 when Attribute_TypeCode
=>
5022 Check_PolyORB_Attribute
;
5023 Set_Etype
(N
, RTE
(RE_TypeCode
));
5029 when Attribute_Type_Key
=>
5033 -- This processing belongs in Eval_Attribute ???
5036 function Type_Key
return String_Id
;
5037 -- A very preliminary implementation. For now, a signature
5038 -- consists of only the type name. This is clearly incomplete
5039 -- (e.g., adding a new field to a record type should change the
5040 -- type's Type_Key attribute).
5046 function Type_Key
return String_Id
is
5047 Full_Name
: constant String_Id
:=
5048 Fully_Qualified_Name_String
(Entity
(P
));
5051 -- Copy all characters in Full_Name but the trailing NUL
5054 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5055 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5058 Store_String_Chars
("'Type_Key");
5063 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5066 Analyze_And_Resolve
(N
, Standard_String
);
5072 when Attribute_UET_Address
=>
5074 Check_Unit_Name
(P
);
5075 Set_Etype
(N
, RTE
(RE_Address
));
5077 -----------------------
5078 -- Unbiased_Rounding --
5079 -----------------------
5081 when Attribute_Unbiased_Rounding
=>
5082 Check_Floating_Point_Type_1
;
5083 Set_Etype
(N
, P_Base_Type
);
5084 Resolve
(E1
, P_Base_Type
);
5086 ----------------------
5087 -- Unchecked_Access --
5088 ----------------------
5090 when Attribute_Unchecked_Access
=>
5091 if Comes_From_Source
(N
) then
5092 Check_Restriction
(No_Unchecked_Access
, N
);
5095 Analyze_Access_Attribute
;
5097 -------------------------
5098 -- Unconstrained_Array --
5099 -------------------------
5101 when Attribute_Unconstrained_Array
=>
5104 Check_Not_Incomplete_Type
;
5105 Set_Etype
(N
, Standard_Boolean
);
5107 ------------------------------
5108 -- Universal_Literal_String --
5109 ------------------------------
5111 -- This is a GNAT specific attribute whose prefix must be a named
5112 -- number where the expression is either a single numeric literal,
5113 -- or a numeric literal immediately preceded by a minus sign. The
5114 -- result is equivalent to a string literal containing the text of
5115 -- the literal as it appeared in the source program with a possible
5116 -- leading minus sign.
5118 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
5122 if not Is_Entity_Name
(P
)
5123 or else Ekind
(Entity
(P
)) not in Named_Kind
5125 Error_Attr_P
("prefix for % attribute must be named number");
5132 Src
: Source_Buffer_Ptr
;
5135 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
5137 if Nkind
(Expr
) = N_Op_Minus
then
5139 Expr
:= Original_Node
(Right_Opnd
(Expr
));
5144 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
5146 ("named number for % attribute must be simple literal", N
);
5149 -- Build string literal corresponding to source literal text
5154 Store_String_Char
(Get_Char_Code
('-'));
5158 Src
:= Source_Text
(Get_Source_File_Index
(S
));
5160 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
5161 Store_String_Char
(Get_Char_Code
(Src
(S
)));
5165 -- Now we rewrite the attribute with the string literal
5168 Make_String_Literal
(Loc
, End_String
));
5172 end Universal_Literal_String
;
5174 -------------------------
5175 -- Unrestricted_Access --
5176 -------------------------
5178 -- This is a GNAT specific attribute which is like Access except that
5179 -- all scope checks and checks for aliased views are omitted.
5181 when Attribute_Unrestricted_Access
=>
5183 -- If from source, deal with relevant restrictions
5185 if Comes_From_Source
(N
) then
5186 Check_Restriction
(No_Unchecked_Access
, N
);
5188 if Nkind
(P
) in N_Has_Entity
5189 and then Present
(Entity
(P
))
5190 and then Is_Object
(Entity
(P
))
5192 Check_Restriction
(No_Implicit_Aliasing
, N
);
5196 if Is_Entity_Name
(P
) then
5197 Set_Address_Taken
(Entity
(P
));
5200 Analyze_Access_Attribute
;
5206 when Attribute_Val
=> Val
: declare
5209 Check_Discrete_Type
;
5211 if Is_Boolean_Type
(P_Type
) then
5212 Error_Msg_Name_1
:= Aname
;
5213 Error_Msg_Name_2
:= Chars
(P_Type
);
5214 Check_SPARK_Restriction
5215 ("attribute% is not allowed for type%", P
);
5218 Resolve
(E1
, Any_Integer
);
5219 Set_Etype
(N
, P_Base_Type
);
5221 -- Note, we need a range check in general, but we wait for the
5222 -- Resolve call to do this, since we want to let Eval_Attribute
5223 -- have a chance to find an static illegality first!
5230 when Attribute_Valid
=>
5233 -- Ignore check for object if we have a 'Valid reference generated
5234 -- by the expanded code, since in some cases valid checks can occur
5235 -- on items that are names, but are not objects (e.g. attributes).
5237 if Comes_From_Source
(N
) then
5238 Check_Object_Reference
(P
);
5241 if not Is_Scalar_Type
(P_Type
) then
5242 Error_Attr_P
("object for % attribute must be of scalar type");
5245 Set_Etype
(N
, Standard_Boolean
);
5251 when Attribute_Valid_Scalars
=>
5253 Check_Object_Reference
(P
);
5255 if No_Scalar_Parts
(P_Type
) then
5256 Error_Attr_P
("?attribute % always True, no scalars to check");
5259 Set_Etype
(N
, Standard_Boolean
);
5265 when Attribute_Value
=> Value
:
5267 Check_SPARK_Restriction_On_Attribute
;
5271 -- Case of enumeration type
5273 -- When an enumeration type appears in an attribute reference, all
5274 -- literals of the type are marked as referenced. This must only be
5275 -- done if the attribute reference appears in the current source.
5276 -- Otherwise the information on references may differ between a
5277 -- normal compilation and one that performs inlining.
5279 if Is_Enumeration_Type
(P_Type
)
5280 and then In_Extended_Main_Code_Unit
(N
)
5282 Check_Restriction
(No_Enumeration_Maps
, N
);
5284 -- Mark all enumeration literals as referenced, since the use of
5285 -- the Value attribute can implicitly reference any of the
5286 -- literals of the enumeration base type.
5289 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
5291 while Present
(Ent
) loop
5292 Set_Referenced
(Ent
);
5298 -- Set Etype before resolving expression because expansion of
5299 -- expression may require enclosing type. Note that the type
5300 -- returned by 'Value is the base type of the prefix type.
5302 Set_Etype
(N
, P_Base_Type
);
5303 Validate_Non_Static_Attribute_Function_Call
;
5310 when Attribute_Value_Size
=>
5313 Check_Not_Incomplete_Type
;
5314 Set_Etype
(N
, Universal_Integer
);
5320 when Attribute_Version
=>
5323 Set_Etype
(N
, RTE
(RE_Version_String
));
5329 when Attribute_Wchar_T_Size
=>
5330 Standard_Attribute
(Interfaces_Wchar_T_Size
);
5336 when Attribute_Wide_Image
=> Wide_Image
:
5338 Check_SPARK_Restriction_On_Attribute
;
5340 Set_Etype
(N
, Standard_Wide_String
);
5342 Resolve
(E1
, P_Base_Type
);
5343 Validate_Non_Static_Attribute_Function_Call
;
5346 ---------------------
5347 -- Wide_Wide_Image --
5348 ---------------------
5350 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
5353 Set_Etype
(N
, Standard_Wide_Wide_String
);
5355 Resolve
(E1
, P_Base_Type
);
5356 Validate_Non_Static_Attribute_Function_Call
;
5357 end Wide_Wide_Image
;
5363 when Attribute_Wide_Value
=> Wide_Value
:
5365 Check_SPARK_Restriction_On_Attribute
;
5369 -- Set Etype before resolving expression because expansion
5370 -- of expression may require enclosing type.
5372 Set_Etype
(N
, P_Type
);
5373 Validate_Non_Static_Attribute_Function_Call
;
5376 ---------------------
5377 -- Wide_Wide_Value --
5378 ---------------------
5380 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
5385 -- Set Etype before resolving expression because expansion
5386 -- of expression may require enclosing type.
5388 Set_Etype
(N
, P_Type
);
5389 Validate_Non_Static_Attribute_Function_Call
;
5390 end Wide_Wide_Value
;
5392 ---------------------
5393 -- Wide_Wide_Width --
5394 ---------------------
5396 when Attribute_Wide_Wide_Width
=>
5399 Set_Etype
(N
, Universal_Integer
);
5405 when Attribute_Wide_Width
=>
5406 Check_SPARK_Restriction_On_Attribute
;
5409 Set_Etype
(N
, Universal_Integer
);
5415 when Attribute_Width
=>
5416 Check_SPARK_Restriction_On_Attribute
;
5419 Set_Etype
(N
, Universal_Integer
);
5425 when Attribute_Word_Size
=>
5426 Standard_Attribute
(System_Word_Size
);
5432 when Attribute_Write
=>
5434 Check_Stream_Attribute
(TSS_Stream_Write
);
5435 Set_Etype
(N
, Standard_Void_Type
);
5436 Resolve
(N
, Standard_Void_Type
);
5440 -- All errors raise Bad_Attribute, so that we get out before any further
5441 -- damage occurs when an error is detected (for example, if we check for
5442 -- one attribute expression, and the check succeeds, we want to be able
5443 -- to proceed securely assuming that an expression is in fact present.
5445 -- Note: we set the attribute analyzed in this case to prevent any
5446 -- attempt at reanalysis which could generate spurious error msgs.
5449 when Bad_Attribute
=>
5451 Set_Etype
(N
, Any_Type
);
5453 end Analyze_Attribute
;
5455 --------------------
5456 -- Eval_Attribute --
5457 --------------------
5459 procedure Eval_Attribute
(N
: Node_Id
) is
5460 Loc
: constant Source_Ptr
:= Sloc
(N
);
5461 Aname
: constant Name_Id
:= Attribute_Name
(N
);
5462 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
5463 P
: constant Node_Id
:= Prefix
(N
);
5465 C_Type
: constant Entity_Id
:= Etype
(N
);
5466 -- The type imposed by the context
5469 -- First expression, or Empty if none
5472 -- Second expression, or Empty if none
5474 P_Entity
: Entity_Id
;
5475 -- Entity denoted by prefix
5478 -- The type of the prefix
5480 P_Base_Type
: Entity_Id
;
5481 -- The base type of the prefix type
5483 P_Root_Type
: Entity_Id
;
5484 -- The root type of the prefix type
5487 -- True if the result is Static. This is set by the general processing
5488 -- to true if the prefix is static, and all expressions are static. It
5489 -- can be reset as processing continues for particular attributes
5491 Lo_Bound
, Hi_Bound
: Node_Id
;
5492 -- Expressions for low and high bounds of type or array index referenced
5493 -- by First, Last, or Length attribute for array, set by Set_Bounds.
5496 -- Constraint error node used if we have an attribute reference has
5497 -- an argument that raises a constraint error. In this case we replace
5498 -- the attribute with a raise constraint_error node. This is important
5499 -- processing, since otherwise gigi might see an attribute which it is
5500 -- unprepared to deal with.
5502 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
5503 -- If Bound is a reference to a discriminant of a task or protected type
5504 -- occurring within the object's body, rewrite attribute reference into
5505 -- a reference to the corresponding discriminal. Use for the expansion
5506 -- of checks against bounds of entry family index subtypes.
5508 procedure Check_Expressions
;
5509 -- In case where the attribute is not foldable, the expressions, if
5510 -- any, of the attribute, are in a non-static context. This procedure
5511 -- performs the required additional checks.
5513 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
5514 -- Determines if the given type has compile time known bounds. Note
5515 -- that we enter the case statement even in cases where the prefix
5516 -- type does NOT have known bounds, so it is important to guard any
5517 -- attempt to evaluate both bounds with a call to this function.
5519 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
5520 -- This procedure is called when the attribute N has a non-static
5521 -- but compile time known value given by Val. It includes the
5522 -- necessary checks for out of range values.
5524 function Fore_Value
return Nat
;
5525 -- Computes the Fore value for the current attribute prefix, which is
5526 -- known to be a static fixed-point type. Used by Fore and Width.
5528 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean;
5529 -- Determine whether Typ denotes a VAX floating point type
5531 function Mantissa
return Uint
;
5532 -- Returns the Mantissa value for the prefix type
5534 procedure Set_Bounds
;
5535 -- Used for First, Last and Length attributes applied to an array or
5536 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
5537 -- and high bound expressions for the index referenced by the attribute
5538 -- designator (i.e. the first index if no expression is present, and the
5539 -- N'th index if the value N is present as an expression). Also used for
5540 -- First and Last of scalar types and for First_Valid and Last_Valid.
5541 -- Static is reset to False if the type or index type is not statically
5544 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
5545 -- Verify that the prefix of a potentially static array attribute
5546 -- satisfies the conditions of 4.9 (14).
5548 -----------------------------------
5549 -- Check_Concurrent_Discriminant --
5550 -----------------------------------
5552 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
5554 -- The concurrent (task or protected) type
5557 if Nkind
(Bound
) = N_Identifier
5558 and then Ekind
(Entity
(Bound
)) = E_Discriminant
5559 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
5561 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
5563 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
5565 -- Find discriminant of original concurrent type, and use
5566 -- its current discriminal, which is the renaming within
5567 -- the task/protected body.
5571 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
5574 end Check_Concurrent_Discriminant
;
5576 -----------------------
5577 -- Check_Expressions --
5578 -----------------------
5580 procedure Check_Expressions
is
5584 while Present
(E
) loop
5585 Check_Non_Static_Context
(E
);
5588 end Check_Expressions
;
5590 ----------------------------------
5591 -- Compile_Time_Known_Attribute --
5592 ----------------------------------
5594 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
5595 T
: constant Entity_Id
:= Etype
(N
);
5598 Fold_Uint
(N
, Val
, False);
5600 -- Check that result is in bounds of the type if it is static
5602 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
5605 elsif Is_Out_Of_Range
(N
, T
) then
5606 Apply_Compile_Time_Constraint_Error
5607 (N
, "value not in range of}?", CE_Range_Check_Failed
);
5609 elsif not Range_Checks_Suppressed
(T
) then
5610 Enable_Range_Check
(N
);
5613 Set_Do_Range_Check
(N
, False);
5615 end Compile_Time_Known_Attribute
;
5617 -------------------------------
5618 -- Compile_Time_Known_Bounds --
5619 -------------------------------
5621 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
5624 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
5626 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
5627 end Compile_Time_Known_Bounds
;
5633 -- Note that the Fore calculation is based on the actual values
5634 -- of the bounds, and does not take into account possible rounding.
5636 function Fore_Value
return Nat
is
5637 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
5638 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
5639 Small
: constant Ureal
:= Small_Value
(P_Type
);
5640 Lo_Real
: constant Ureal
:= Lo
* Small
;
5641 Hi_Real
: constant Ureal
:= Hi
* Small
;
5646 -- Bounds are given in terms of small units, so first compute
5647 -- proper values as reals.
5649 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
5652 -- Loop to compute proper value if more than one digit required
5654 while T
>= Ureal_10
loop
5666 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean is
5669 Is_Floating_Point_Type
(Typ
)
5672 or else Float_Rep
(Typ
) = VAX_Native
);
5679 -- Table of mantissa values accessed by function Computed using
5682 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
5684 -- where D is T'Digits (RM83 3.5.7)
5686 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
5728 function Mantissa
return Uint
is
5731 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
5738 procedure Set_Bounds
is
5744 -- For a string literal subtype, we have to construct the bounds.
5745 -- Valid Ada code never applies attributes to string literals, but
5746 -- it is convenient to allow the expander to generate attribute
5747 -- references of this type (e.g. First and Last applied to a string
5750 -- Note that the whole point of the E_String_Literal_Subtype is to
5751 -- avoid this construction of bounds, but the cases in which we
5752 -- have to materialize them are rare enough that we don't worry!
5754 -- The low bound is simply the low bound of the base type. The
5755 -- high bound is computed from the length of the string and this
5758 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
5759 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
5760 Lo_Bound
:= Type_Low_Bound
(Ityp
);
5763 Make_Integer_Literal
(Sloc
(P
),
5765 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
5767 Set_Parent
(Hi_Bound
, P
);
5768 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
5771 -- For non-array case, just get bounds of scalar type
5773 elsif Is_Scalar_Type
(P_Type
) then
5776 -- For a fixed-point type, we must freeze to get the attributes
5777 -- of the fixed-point type set now so we can reference them.
5779 if Is_Fixed_Point_Type
(P_Type
)
5780 and then not Is_Frozen
(Base_Type
(P_Type
))
5781 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5782 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5784 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
5787 -- For array case, get type of proper index
5793 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
5796 Indx
:= First_Index
(P_Type
);
5797 for J
in 1 .. Ndim
- 1 loop
5801 -- If no index type, get out (some other error occurred, and
5802 -- we don't have enough information to complete the job!)
5810 Ityp
:= Etype
(Indx
);
5813 -- A discrete range in an index constraint is allowed to be a
5814 -- subtype indication. This is syntactically a pain, but should
5815 -- not propagate to the entity for the corresponding index subtype.
5816 -- After checking that the subtype indication is legal, the range
5817 -- of the subtype indication should be transfered to the entity.
5818 -- The attributes for the bounds should remain the simple retrievals
5819 -- that they are now.
5821 Lo_Bound
:= Type_Low_Bound
(Ityp
);
5822 Hi_Bound
:= Type_High_Bound
(Ityp
);
5824 if not Is_Static_Subtype
(Ityp
) then
5829 -------------------------------
5830 -- Statically_Denotes_Entity --
5831 -------------------------------
5833 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
5837 if not Is_Entity_Name
(N
) then
5844 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
5845 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
5846 end Statically_Denotes_Entity
;
5848 -- Start of processing for Eval_Attribute
5851 -- Acquire first two expressions (at the moment, no attributes take more
5852 -- than two expressions in any case).
5854 if Present
(Expressions
(N
)) then
5855 E1
:= First
(Expressions
(N
));
5862 -- Special processing for Enabled attribute. This attribute has a very
5863 -- special prefix, and the easiest way to avoid lots of special checks
5864 -- to protect this special prefix from causing trouble is to deal with
5865 -- this attribute immediately and be done with it.
5867 if Id
= Attribute_Enabled
then
5869 -- We skip evaluation if the expander is not active. This is not just
5870 -- an optimization. It is of key importance that we not rewrite the
5871 -- attribute in a generic template, since we want to pick up the
5872 -- setting of the check in the instance, and testing expander active
5873 -- is as easy way of doing this as any.
5875 if Expander_Active
then
5877 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
5882 if C
in Predefined_Check_Id
then
5883 R
:= Scope_Suppress
.Suppress
(C
);
5885 R
:= Is_Check_Suppressed
(Empty
, C
);
5889 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
5892 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
5899 -- Special processing for cases where the prefix is an object. For
5900 -- this purpose, a string literal counts as an object (attributes
5901 -- of string literals can only appear in generated code).
5903 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
5905 -- For Component_Size, the prefix is an array object, and we apply
5906 -- the attribute to the type of the object. This is allowed for
5907 -- both unconstrained and constrained arrays, since the bounds
5908 -- have no influence on the value of this attribute.
5910 if Id
= Attribute_Component_Size
then
5911 P_Entity
:= Etype
(P
);
5913 -- For First and Last, the prefix is an array object, and we apply
5914 -- the attribute to the type of the array, but we need a constrained
5915 -- type for this, so we use the actual subtype if available.
5917 elsif Id
= Attribute_First
5921 Id
= Attribute_Length
5924 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
5927 if Present
(AS
) and then Is_Constrained
(AS
) then
5930 -- If we have an unconstrained type we cannot fold
5938 -- For Size, give size of object if available, otherwise we
5939 -- cannot fold Size.
5941 elsif Id
= Attribute_Size
then
5942 if Is_Entity_Name
(P
)
5943 and then Known_Esize
(Entity
(P
))
5945 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
5953 -- For Alignment, give size of object if available, otherwise we
5954 -- cannot fold Alignment.
5956 elsif Id
= Attribute_Alignment
then
5957 if Is_Entity_Name
(P
)
5958 and then Known_Alignment
(Entity
(P
))
5960 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
5968 -- For Lock_Free, we apply the attribute to the type of the object.
5969 -- This is allowed since we have already verified that the type is a
5972 elsif Id
= Attribute_Lock_Free
then
5973 P_Entity
:= Etype
(P
);
5975 -- No other attributes for objects are folded
5982 -- Cases where P is not an object. Cannot do anything if P is
5983 -- not the name of an entity.
5985 elsif not Is_Entity_Name
(P
) then
5989 -- Otherwise get prefix entity
5992 P_Entity
:= Entity
(P
);
5995 -- At this stage P_Entity is the entity to which the attribute
5996 -- is to be applied. This is usually simply the entity of the
5997 -- prefix, except in some cases of attributes for objects, where
5998 -- as described above, we apply the attribute to the object type.
6000 -- First foldable possibility is a scalar or array type (RM 4.9(7))
6001 -- that is not generic (generic types are eliminated by RM 4.9(25)).
6002 -- Note we allow non-static non-generic types at this stage as further
6005 if Is_Type
(P_Entity
)
6006 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
6007 and then (not Is_Generic_Type
(P_Entity
))
6011 -- Second foldable possibility is an array object (RM 4.9(8))
6013 elsif (Ekind
(P_Entity
) = E_Variable
6015 Ekind
(P_Entity
) = E_Constant
)
6016 and then Is_Array_Type
(Etype
(P_Entity
))
6017 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
6019 P_Type
:= Etype
(P_Entity
);
6021 -- If the entity is an array constant with an unconstrained nominal
6022 -- subtype then get the type from the initial value. If the value has
6023 -- been expanded into assignments, there is no expression and the
6024 -- attribute reference remains dynamic.
6026 -- We could do better here and retrieve the type ???
6028 if Ekind
(P_Entity
) = E_Constant
6029 and then not Is_Constrained
(P_Type
)
6031 if No
(Constant_Value
(P_Entity
)) then
6034 P_Type
:= Etype
(Constant_Value
(P_Entity
));
6038 -- Definite must be folded if the prefix is not a generic type,
6039 -- that is to say if we are within an instantiation. Same processing
6040 -- applies to the GNAT attributes Atomic_Always_Lock_Free,
6041 -- Has_Discriminants, Lock_Free, Type_Class, Has_Tagged_Value, and
6042 -- Unconstrained_Array.
6044 elsif (Id
= Attribute_Atomic_Always_Lock_Free
6046 Id
= Attribute_Definite
6048 Id
= Attribute_Has_Access_Values
6050 Id
= Attribute_Has_Discriminants
6052 Id
= Attribute_Has_Tagged_Values
6054 Id
= Attribute_Lock_Free
6056 Id
= Attribute_Type_Class
6058 Id
= Attribute_Unconstrained_Array
6060 Id
= Attribute_Max_Alignment_For_Allocation
)
6061 and then not Is_Generic_Type
(P_Entity
)
6065 -- We can fold 'Size applied to a type if the size is known (as happens
6066 -- for a size from an attribute definition clause). At this stage, this
6067 -- can happen only for types (e.g. record types) for which the size is
6068 -- always non-static. We exclude generic types from consideration (since
6069 -- they have bogus sizes set within templates).
6071 elsif Id
= Attribute_Size
6072 and then Is_Type
(P_Entity
)
6073 and then (not Is_Generic_Type
(P_Entity
))
6074 and then Known_Static_RM_Size
(P_Entity
)
6076 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
6079 -- We can fold 'Alignment applied to a type if the alignment is known
6080 -- (as happens for an alignment from an attribute definition clause).
6081 -- At this stage, this can happen only for types (e.g. record
6082 -- types) for which the size is always non-static. We exclude
6083 -- generic types from consideration (since they have bogus
6084 -- sizes set within templates).
6086 elsif Id
= Attribute_Alignment
6087 and then Is_Type
(P_Entity
)
6088 and then (not Is_Generic_Type
(P_Entity
))
6089 and then Known_Alignment
(P_Entity
)
6091 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
6094 -- If this is an access attribute that is known to fail accessibility
6095 -- check, rewrite accordingly.
6097 elsif Attribute_Name
(N
) = Name_Access
6098 and then Raises_Constraint_Error
(N
)
6101 Make_Raise_Program_Error
(Loc
,
6102 Reason
=> PE_Accessibility_Check_Failed
));
6103 Set_Etype
(N
, C_Type
);
6106 -- No other cases are foldable (they certainly aren't static, and at
6107 -- the moment we don't try to fold any cases other than the ones above).
6114 -- If either attribute or the prefix is Any_Type, then propagate
6115 -- Any_Type to the result and don't do anything else at all.
6117 if P_Type
= Any_Type
6118 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
6119 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
6121 Set_Etype
(N
, Any_Type
);
6125 -- Scalar subtype case. We have not yet enforced the static requirement
6126 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
6127 -- of non-static attribute references (e.g. S'Digits for a non-static
6128 -- floating-point type, which we can compute at compile time).
6130 -- Note: this folding of non-static attributes is not simply a case of
6131 -- optimization. For many of the attributes affected, Gigi cannot handle
6132 -- the attribute and depends on the front end having folded them away.
6134 -- Note: although we don't require staticness at this stage, we do set
6135 -- the Static variable to record the staticness, for easy reference by
6136 -- those attributes where it matters (e.g. Succ and Pred), and also to
6137 -- be used to ensure that non-static folded things are not marked as
6138 -- being static (a check that is done right at the end).
6140 P_Root_Type
:= Root_Type
(P_Type
);
6141 P_Base_Type
:= Base_Type
(P_Type
);
6143 -- If the root type or base type is generic, then we cannot fold. This
6144 -- test is needed because subtypes of generic types are not always
6145 -- marked as being generic themselves (which seems odd???)
6147 if Is_Generic_Type
(P_Root_Type
)
6148 or else Is_Generic_Type
(P_Base_Type
)
6153 if Is_Scalar_Type
(P_Type
) then
6154 Static
:= Is_OK_Static_Subtype
(P_Type
);
6156 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
6157 -- since we can't do anything with unconstrained arrays. In addition,
6158 -- only the First, Last and Length attributes are possibly static.
6160 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
6161 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
6162 -- Unconstrained_Array are again exceptions, because they apply as well
6163 -- to unconstrained types.
6165 -- In addition Component_Size is an exception since it is possibly
6166 -- foldable, even though it is never static, and it does apply to
6167 -- unconstrained arrays. Furthermore, it is essential to fold this
6168 -- in the packed case, since otherwise the value will be incorrect.
6170 elsif Id
= Attribute_Atomic_Always_Lock_Free
6172 Id
= Attribute_Definite
6174 Id
= Attribute_Has_Access_Values
6176 Id
= Attribute_Has_Discriminants
6178 Id
= Attribute_Has_Tagged_Values
6180 Id
= Attribute_Lock_Free
6182 Id
= Attribute_Type_Class
6184 Id
= Attribute_Unconstrained_Array
6186 Id
= Attribute_Component_Size
6190 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
6191 if not Is_Constrained
(P_Type
)
6192 or else (Id
/= Attribute_First
and then
6193 Id
/= Attribute_Last
and then
6194 Id
/= Attribute_Length
)
6200 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
6201 -- scalar case, we hold off on enforcing staticness, since there are
6202 -- cases which we can fold at compile time even though they are not
6203 -- static (e.g. 'Length applied to a static index, even though other
6204 -- non-static indexes make the array type non-static). This is only
6205 -- an optimization, but it falls out essentially free, so why not.
6206 -- Again we compute the variable Static for easy reference later
6207 -- (note that no array attributes are static in Ada 83).
6209 -- We also need to set Static properly for subsequent legality checks
6210 -- which might otherwise accept non-static constants in contexts
6211 -- where they are not legal.
6213 Static
:= Ada_Version
>= Ada_95
6214 and then Statically_Denotes_Entity
(P
);
6220 N
:= First_Index
(P_Type
);
6222 -- The expression is static if the array type is constrained
6223 -- by given bounds, and not by an initial expression. Constant
6224 -- strings are static in any case.
6226 if Root_Type
(P_Type
) /= Standard_String
then
6228 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
6231 while Present
(N
) loop
6232 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
6234 -- If however the index type is generic, or derived from
6235 -- one, attributes cannot be folded.
6237 if Is_Generic_Type
(Root_Type
(Etype
(N
)))
6238 and then Id
/= Attribute_Component_Size
6248 -- Check any expressions that are present. Note that these expressions,
6249 -- depending on the particular attribute type, are either part of the
6250 -- attribute designator, or they are arguments in a case where the
6251 -- attribute reference returns a function. In the latter case, the
6252 -- rule in (RM 4.9(22)) applies and in particular requires the type
6253 -- of the expressions to be scalar in order for the attribute to be
6254 -- considered to be static.
6261 while Present
(E
) loop
6263 -- If expression is not static, then the attribute reference
6264 -- result certainly cannot be static.
6266 if not Is_Static_Expression
(E
) then
6270 -- If the result is not known at compile time, or is not of
6271 -- a scalar type, then the result is definitely not static,
6272 -- so we can quit now.
6274 if not Compile_Time_Known_Value
(E
)
6275 or else not Is_Scalar_Type
(Etype
(E
))
6277 -- An odd special case, if this is a Pos attribute, this
6278 -- is where we need to apply a range check since it does
6279 -- not get done anywhere else.
6281 if Id
= Attribute_Pos
then
6282 if Is_Integer_Type
(Etype
(E
)) then
6283 Apply_Range_Check
(E
, Etype
(N
));
6290 -- If the expression raises a constraint error, then so does
6291 -- the attribute reference. We keep going in this case because
6292 -- we are still interested in whether the attribute reference
6293 -- is static even if it is not static.
6295 elsif Raises_Constraint_Error
(E
) then
6296 Set_Raises_Constraint_Error
(N
);
6302 if Raises_Constraint_Error
(Prefix
(N
)) then
6307 -- Deal with the case of a static attribute reference that raises
6308 -- constraint error. The Raises_Constraint_Error flag will already
6309 -- have been set, and the Static flag shows whether the attribute
6310 -- reference is static. In any case we certainly can't fold such an
6311 -- attribute reference.
6313 -- Note that the rewriting of the attribute node with the constraint
6314 -- error node is essential in this case, because otherwise Gigi might
6315 -- blow up on one of the attributes it never expects to see.
6317 -- The constraint_error node must have the type imposed by the context,
6318 -- to avoid spurious errors in the enclosing expression.
6320 if Raises_Constraint_Error
(N
) then
6322 Make_Raise_Constraint_Error
(Sloc
(N
),
6323 Reason
=> CE_Range_Check_Failed
);
6324 Set_Etype
(CE_Node
, Etype
(N
));
6325 Set_Raises_Constraint_Error
(CE_Node
);
6327 Rewrite
(N
, Relocate_Node
(CE_Node
));
6328 Set_Is_Static_Expression
(N
, Static
);
6332 -- At this point we have a potentially foldable attribute reference.
6333 -- If Static is set, then the attribute reference definitely obeys
6334 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
6335 -- folded. If Static is not set, then the attribute may or may not
6336 -- be foldable, and the individual attribute processing routines
6337 -- test Static as required in cases where it makes a difference.
6339 -- In the case where Static is not set, we do know that all the
6340 -- expressions present are at least known at compile time (we assumed
6341 -- above that if this was not the case, then there was no hope of static
6342 -- evaluation). However, we did not require that the bounds of the
6343 -- prefix type be compile time known, let alone static). That's because
6344 -- there are many attributes that can be computed at compile time on
6345 -- non-static subtypes, even though such references are not static
6350 -- Attributes related to Ada 2012 iterators (placeholder ???)
6352 when Attribute_Constant_Indexing |
6353 Attribute_Default_Iterator |
6354 Attribute_Implicit_Dereference |
6355 Attribute_Iterator_Element |
6356 Attribute_Variable_Indexing
=> null;
6358 -- Internal attributes used to deal with Ada 2012 delayed aspects.
6359 -- These were already rejected by the parser. Thus they shouldn't
6362 when Internal_Attribute_Id
=>
6363 raise Program_Error
;
6369 when Attribute_Adjacent
=>
6372 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6378 when Attribute_Aft
=>
6379 Fold_Uint
(N
, Aft_Value
(P_Type
), True);
6385 when Attribute_Alignment
=> Alignment_Block
: declare
6386 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6389 -- Fold if alignment is set and not otherwise
6391 if Known_Alignment
(P_TypeA
) then
6392 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
6394 end Alignment_Block
;
6400 -- Can only be folded in No_Ast_Handler case
6402 when Attribute_AST_Entry
=>
6403 if not Is_AST_Entry
(P_Entity
) then
6405 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
6410 -----------------------------
6411 -- Atomic_Always_Lock_Free --
6412 -----------------------------
6414 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
6417 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
6419 V
: constant Entity_Id
:=
6421 (Support_Atomic_Primitives_On_Target
6422 and then Support_Atomic_Primitives
(P_Type
));
6425 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
6427 -- Analyze and resolve as boolean. Note that this attribute is a
6428 -- static attribute in GNAT.
6430 Analyze_And_Resolve
(N
, Standard_Boolean
);
6432 end Atomic_Always_Lock_Free
;
6438 -- Bit can never be folded
6440 when Attribute_Bit
=>
6447 -- Body_version can never be static
6449 when Attribute_Body_Version
=>
6456 when Attribute_Ceiling
=>
6458 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6460 --------------------
6461 -- Component_Size --
6462 --------------------
6464 when Attribute_Component_Size
=>
6465 if Known_Static_Component_Size
(P_Type
) then
6466 Fold_Uint
(N
, Component_Size
(P_Type
), False);
6473 when Attribute_Compose
=>
6476 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
6483 -- Constrained is never folded for now, there may be cases that
6484 -- could be handled at compile time. To be looked at later.
6486 when Attribute_Constrained
=>
6493 when Attribute_Copy_Sign
=>
6496 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6502 when Attribute_Definite
=>
6503 Rewrite
(N
, New_Occurrence_Of
(
6504 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
6505 Analyze_And_Resolve
(N
, Standard_Boolean
);
6511 when Attribute_Delta
=>
6512 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
6518 when Attribute_Denorm
=>
6520 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
6522 ---------------------
6523 -- Descriptor_Size --
6524 ---------------------
6526 when Attribute_Descriptor_Size
=>
6533 when Attribute_Digits
=>
6534 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
6540 when Attribute_Emax
=>
6542 -- Ada 83 attribute is defined as (RM83 3.5.8)
6544 -- T'Emax = 4 * T'Mantissa
6546 Fold_Uint
(N
, 4 * Mantissa
, True);
6552 when Attribute_Enum_Rep
=>
6554 -- For an enumeration type with a non-standard representation use
6555 -- the Enumeration_Rep field of the proper constant. Note that this
6556 -- will not work for types Character/Wide_[Wide-]Character, since no
6557 -- real entities are created for the enumeration literals, but that
6558 -- does not matter since these two types do not have non-standard
6559 -- representations anyway.
6561 if Is_Enumeration_Type
(P_Type
)
6562 and then Has_Non_Standard_Rep
(P_Type
)
6564 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
6566 -- For enumeration types with standard representations and all
6567 -- other cases (i.e. all integer and modular types), Enum_Rep
6568 -- is equivalent to Pos.
6571 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6578 when Attribute_Enum_Val
=> Enum_Val
: declare
6582 -- We have something like Enum_Type'Enum_Val (23), so search for a
6583 -- corresponding value in the list of Enum_Rep values for the type.
6585 Lit
:= First_Literal
(P_Base_Type
);
6587 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
6588 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
6595 Apply_Compile_Time_Constraint_Error
6596 (N
, "no representation value matches",
6597 CE_Range_Check_Failed
,
6598 Warn
=> not Static
);
6608 when Attribute_Epsilon
=>
6610 -- Ada 83 attribute is defined as (RM83 3.5.8)
6612 -- T'Epsilon = 2.0**(1 - T'Mantissa)
6614 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
6620 when Attribute_Exponent
=>
6622 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6628 when Attribute_First
=> First_Attr
:
6632 if Compile_Time_Known_Value
(Lo_Bound
) then
6633 if Is_Real_Type
(P_Type
) then
6634 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
6636 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
6639 -- Replace VAX Float_Type'First with a reference to the temporary
6640 -- which represents the low bound of the type. This transformation
6641 -- is needed since the back end cannot evaluate 'First on VAX.
6643 elsif Is_VAX_Float
(P_Type
)
6644 and then Nkind
(Lo_Bound
) = N_Identifier
6646 Rewrite
(N
, New_Reference_To
(Entity
(Lo_Bound
), Sloc
(N
)));
6650 Check_Concurrent_Discriminant
(Lo_Bound
);
6658 when Attribute_First_Valid
=> First_Valid
:
6660 if Has_Predicates
(P_Type
)
6661 and then Present
(Static_Predicate
(P_Type
))
6664 FirstN
: constant Node_Id
:= First
(Static_Predicate
(P_Type
));
6666 if Nkind
(FirstN
) = N_Range
then
6667 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
6669 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
6675 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
6683 when Attribute_Fixed_Value
=>
6690 when Attribute_Floor
=>
6692 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6698 when Attribute_Fore
=>
6699 if Compile_Time_Known_Bounds
(P_Type
) then
6700 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
6707 when Attribute_Fraction
=>
6709 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6711 -----------------------
6712 -- Has_Access_Values --
6713 -----------------------
6715 when Attribute_Has_Access_Values
=>
6716 Rewrite
(N
, New_Occurrence_Of
6717 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
6718 Analyze_And_Resolve
(N
, Standard_Boolean
);
6720 -----------------------
6721 -- Has_Discriminants --
6722 -----------------------
6724 when Attribute_Has_Discriminants
=>
6725 Rewrite
(N
, New_Occurrence_Of
(
6726 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
6727 Analyze_And_Resolve
(N
, Standard_Boolean
);
6729 -----------------------
6730 -- Has_Tagged_Values --
6731 -----------------------
6733 when Attribute_Has_Tagged_Values
=>
6734 Rewrite
(N
, New_Occurrence_Of
6735 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
6736 Analyze_And_Resolve
(N
, Standard_Boolean
);
6742 when Attribute_Identity
=>
6749 -- Image is a scalar attribute, but is never static, because it is
6750 -- not a static function (having a non-scalar argument (RM 4.9(22))
6751 -- However, we can constant-fold the image of an enumeration literal
6752 -- if names are available.
6754 when Attribute_Image
=>
6755 if Is_Entity_Name
(E1
)
6756 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
6757 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
6758 and then not Global_Discard_Names
6761 Lit
: constant Entity_Id
:= Entity
(E1
);
6765 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
6766 Set_Casing
(All_Upper_Case
);
6767 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
6769 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
6770 Analyze_And_Resolve
(N
, Standard_String
);
6771 Set_Is_Static_Expression
(N
, False);
6779 -- Img is a scalar attribute, but is never static, because it is
6780 -- not a static function (having a non-scalar argument (RM 4.9(22))
6782 when Attribute_Img
=>
6789 -- We never try to fold Integer_Value (though perhaps we could???)
6791 when Attribute_Integer_Value
=>
6798 -- Invalid_Value is a scalar attribute that is never static, because
6799 -- the value is by design out of range.
6801 when Attribute_Invalid_Value
=>
6808 when Attribute_Large
=>
6810 -- For fixed-point, we use the identity:
6812 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
6814 if Is_Fixed_Point_Type
(P_Type
) then
6816 Make_Op_Multiply
(Loc
,
6818 Make_Op_Subtract
(Loc
,
6822 Make_Real_Literal
(Loc
, Ureal_2
),
6824 Make_Attribute_Reference
(Loc
,
6826 Attribute_Name
=> Name_Mantissa
)),
6827 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
6830 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
6832 Analyze_And_Resolve
(N
, C_Type
);
6834 -- Floating-point (Ada 83 compatibility)
6837 -- Ada 83 attribute is defined as (RM83 3.5.8)
6839 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
6843 -- T'Emax = 4 * T'Mantissa
6846 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
6854 when Attribute_Lock_Free
=> Lock_Free
: declare
6855 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
6858 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
6860 -- Analyze and resolve as boolean. Note that this attribute is a
6861 -- static attribute in GNAT.
6863 Analyze_And_Resolve
(N
, Standard_Boolean
);
6871 when Attribute_Last
=> Last_Attr
:
6875 if Compile_Time_Known_Value
(Hi_Bound
) then
6876 if Is_Real_Type
(P_Type
) then
6877 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
6879 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
6882 -- Replace VAX Float_Type'Last with a reference to the temporary
6883 -- which represents the high bound of the type. This transformation
6884 -- is needed since the back end cannot evaluate 'Last on VAX.
6886 elsif Is_VAX_Float
(P_Type
)
6887 and then Nkind
(Hi_Bound
) = N_Identifier
6889 Rewrite
(N
, New_Reference_To
(Entity
(Hi_Bound
), Sloc
(N
)));
6893 Check_Concurrent_Discriminant
(Hi_Bound
);
6901 when Attribute_Last_Valid
=> Last_Valid
:
6903 if Has_Predicates
(P_Type
)
6904 and then Present
(Static_Predicate
(P_Type
))
6907 LastN
: constant Node_Id
:= Last
(Static_Predicate
(P_Type
));
6909 if Nkind
(LastN
) = N_Range
then
6910 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
6912 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
6918 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
6926 when Attribute_Leading_Part
=>
6928 Eval_Fat
.Leading_Part
6929 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6935 when Attribute_Length
=> Length
: declare
6939 -- If any index type is a formal type, or derived from one, the
6940 -- bounds are not static. Treating them as static can produce
6941 -- spurious warnings or improper constant folding.
6943 Ind
:= First_Index
(P_Type
);
6944 while Present
(Ind
) loop
6945 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
6954 -- For two compile time values, we can compute length
6956 if Compile_Time_Known_Value
(Lo_Bound
)
6957 and then Compile_Time_Known_Value
(Hi_Bound
)
6960 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
6964 -- One more case is where Hi_Bound and Lo_Bound are compile-time
6965 -- comparable, and we can figure out the difference between them.
6968 Diff
: aliased Uint
;
6972 Compile_Time_Compare
6973 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
6976 Fold_Uint
(N
, Uint_1
, False);
6979 Fold_Uint
(N
, Uint_0
, False);
6982 if Diff
/= No_Uint
then
6983 Fold_Uint
(N
, Diff
+ 1, False);
6996 when Attribute_Machine
=>
6999 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
7006 when Attribute_Machine_Emax
=>
7007 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
7013 when Attribute_Machine_Emin
=>
7014 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
7016 ----------------------
7017 -- Machine_Mantissa --
7018 ----------------------
7020 when Attribute_Machine_Mantissa
=>
7021 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
7023 -----------------------
7024 -- Machine_Overflows --
7025 -----------------------
7027 when Attribute_Machine_Overflows
=>
7029 -- Always true for fixed-point
7031 if Is_Fixed_Point_Type
(P_Type
) then
7032 Fold_Uint
(N
, True_Value
, True);
7034 -- Floating point case
7038 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
7046 when Attribute_Machine_Radix
=>
7047 if Is_Fixed_Point_Type
(P_Type
) then
7048 if Is_Decimal_Fixed_Point_Type
(P_Type
)
7049 and then Machine_Radix_10
(P_Type
)
7051 Fold_Uint
(N
, Uint_10
, True);
7053 Fold_Uint
(N
, Uint_2
, True);
7056 -- All floating-point type always have radix 2
7059 Fold_Uint
(N
, Uint_2
, True);
7062 ----------------------
7063 -- Machine_Rounding --
7064 ----------------------
7066 -- Note: for the folding case, it is fine to treat Machine_Rounding
7067 -- exactly the same way as Rounding, since this is one of the allowed
7068 -- behaviors, and performance is not an issue here. It might be a bit
7069 -- better to give the same result as it would give at run time, even
7070 -- though the non-determinism is certainly permitted.
7072 when Attribute_Machine_Rounding
=>
7074 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7076 --------------------
7077 -- Machine_Rounds --
7078 --------------------
7080 when Attribute_Machine_Rounds
=>
7082 -- Always False for fixed-point
7084 if Is_Fixed_Point_Type
(P_Type
) then
7085 Fold_Uint
(N
, False_Value
, True);
7087 -- Else yield proper floating-point result
7091 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
7098 -- Note: Machine_Size is identical to Object_Size
7100 when Attribute_Machine_Size
=> Machine_Size
: declare
7101 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7104 if Known_Esize
(P_TypeA
) then
7105 Fold_Uint
(N
, Esize
(P_TypeA
), True);
7113 when Attribute_Mantissa
=>
7115 -- Fixed-point mantissa
7117 if Is_Fixed_Point_Type
(P_Type
) then
7119 -- Compile time foldable case
7121 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7123 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7125 -- The calculation of the obsolete Ada 83 attribute Mantissa
7126 -- is annoying, because of AI00143, quoted here:
7128 -- !question 84-01-10
7130 -- Consider the model numbers for F:
7132 -- type F is delta 1.0 range -7.0 .. 8.0;
7134 -- The wording requires that F'MANTISSA be the SMALLEST
7135 -- integer number for which each bound of the specified
7136 -- range is either a model number or lies at most small
7137 -- distant from a model number. This means F'MANTISSA
7138 -- is required to be 3 since the range -7.0 .. 7.0 fits
7139 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
7140 -- number, namely, 7. Is this analysis correct? Note that
7141 -- this implies the upper bound of the range is not
7142 -- represented as a model number.
7144 -- !response 84-03-17
7146 -- The analysis is correct. The upper and lower bounds for
7147 -- a fixed point type can lie outside the range of model
7158 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
7159 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
7160 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
7161 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
7163 -- If the Bound is exactly a model number, i.e. a multiple
7164 -- of Small, then we back it off by one to get the integer
7165 -- value that must be representable.
7167 if Small_Value
(P_Type
) * Max_Man
= Bound
then
7168 Max_Man
:= Max_Man
- 1;
7171 -- Now find corresponding size = Mantissa value
7174 while 2 ** Siz
< Max_Man
loop
7178 Fold_Uint
(N
, Siz
, True);
7182 -- The case of dynamic bounds cannot be evaluated at compile
7183 -- time. Instead we use a runtime routine (see Exp_Attr).
7188 -- Floating-point Mantissa
7191 Fold_Uint
(N
, Mantissa
, True);
7198 when Attribute_Max
=> Max
:
7200 if Is_Real_Type
(P_Type
) then
7202 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
7204 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
7208 ----------------------------------
7209 -- Max_Alignment_For_Allocation --
7210 ----------------------------------
7212 -- Max_Alignment_For_Allocation is usually the Alignment. However,
7213 -- arrays are allocated with dope, so we need to take into account both
7214 -- the alignment of the array, which comes from the component alignment,
7215 -- and the alignment of the dope. Also, if the alignment is unknown, we
7216 -- use the max (it's OK to be pessimistic).
7218 when Attribute_Max_Alignment_For_Allocation
=>
7220 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
7222 if Known_Alignment
(P_Type
) and then
7223 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
7225 A
:= Alignment
(P_Type
);
7228 Fold_Uint
(N
, A
, Static
);
7231 ----------------------------------
7232 -- Max_Size_In_Storage_Elements --
7233 ----------------------------------
7235 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
7236 -- Storage_Unit boundary. We can fold any cases for which the size
7237 -- is known by the front end.
7239 when Attribute_Max_Size_In_Storage_Elements
=>
7240 if Known_Esize
(P_Type
) then
7242 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
7243 System_Storage_Unit
,
7247 --------------------
7248 -- Mechanism_Code --
7249 --------------------
7251 when Attribute_Mechanism_Code
=>
7255 Mech
: Mechanism_Type
;
7259 Mech
:= Mechanism
(P_Entity
);
7262 Val
:= UI_To_Int
(Expr_Value
(E1
));
7264 Formal
:= First_Formal
(P_Entity
);
7265 for J
in 1 .. Val
- 1 loop
7266 Next_Formal
(Formal
);
7268 Mech
:= Mechanism
(Formal
);
7272 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
7280 when Attribute_Min
=> Min
:
7282 if Is_Real_Type
(P_Type
) then
7284 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
7287 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
7295 when Attribute_Mod
=>
7297 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
7303 when Attribute_Model
=>
7305 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7311 when Attribute_Model_Emin
=>
7312 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
7318 when Attribute_Model_Epsilon
=>
7319 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
7321 --------------------
7322 -- Model_Mantissa --
7323 --------------------
7325 when Attribute_Model_Mantissa
=>
7326 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
7332 when Attribute_Model_Small
=>
7333 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
7339 when Attribute_Modulus
=>
7340 Fold_Uint
(N
, Modulus
(P_Type
), True);
7342 --------------------
7343 -- Null_Parameter --
7344 --------------------
7346 -- Cannot fold, we know the value sort of, but the whole point is
7347 -- that there is no way to talk about this imaginary value except
7348 -- by using the attribute, so we leave it the way it is.
7350 when Attribute_Null_Parameter
=>
7357 -- The Object_Size attribute for a type returns the Esize of the
7358 -- type and can be folded if this value is known.
7360 when Attribute_Object_Size
=> Object_Size
: declare
7361 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7364 if Known_Esize
(P_TypeA
) then
7365 Fold_Uint
(N
, Esize
(P_TypeA
), True);
7369 ----------------------
7370 -- Overlaps_Storage --
7371 ----------------------
7373 when Attribute_Overlaps_Storage
=>
7376 -------------------------
7377 -- Passed_By_Reference --
7378 -------------------------
7380 -- Scalar types are never passed by reference
7382 when Attribute_Passed_By_Reference
=>
7383 Fold_Uint
(N
, False_Value
, True);
7389 when Attribute_Pos
=>
7390 Fold_Uint
(N
, Expr_Value
(E1
), True);
7396 when Attribute_Pred
=> Pred
:
7398 -- Floating-point case
7400 if Is_Floating_Point_Type
(P_Type
) then
7402 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7406 elsif Is_Fixed_Point_Type
(P_Type
) then
7408 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
7410 -- Modular integer case (wraps)
7412 elsif Is_Modular_Integer_Type
(P_Type
) then
7413 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
7415 -- Other scalar cases
7418 pragma Assert
(Is_Scalar_Type
(P_Type
));
7420 if Is_Enumeration_Type
(P_Type
)
7421 and then Expr_Value
(E1
) =
7422 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
7424 Apply_Compile_Time_Constraint_Error
7425 (N
, "Pred of `&''First`",
7426 CE_Overflow_Check_Failed
,
7428 Warn
=> not Static
);
7434 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
7442 -- No processing required, because by this stage, Range has been
7443 -- replaced by First .. Last, so this branch can never be taken.
7445 when Attribute_Range
=>
7446 raise Program_Error
;
7452 when Attribute_Range_Length
=>
7455 -- Can fold if both bounds are compile time known
7457 if Compile_Time_Known_Value
(Hi_Bound
)
7458 and then Compile_Time_Known_Value
(Lo_Bound
)
7462 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
7466 -- One more case is where Hi_Bound and Lo_Bound are compile-time
7467 -- comparable, and we can figure out the difference between them.
7470 Diff
: aliased Uint
;
7474 Compile_Time_Compare
7475 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
7478 Fold_Uint
(N
, Uint_1
, False);
7481 Fold_Uint
(N
, Uint_0
, False);
7484 if Diff
/= No_Uint
then
7485 Fold_Uint
(N
, Diff
+ 1, False);
7497 when Attribute_Ref
=>
7498 Fold_Uint
(N
, Expr_Value
(E1
), True);
7504 when Attribute_Remainder
=> Remainder
: declare
7505 X
: constant Ureal
:= Expr_Value_R
(E1
);
7506 Y
: constant Ureal
:= Expr_Value_R
(E2
);
7509 if UR_Is_Zero
(Y
) then
7510 Apply_Compile_Time_Constraint_Error
7511 (N
, "division by zero in Remainder",
7512 CE_Overflow_Check_Failed
,
7513 Warn
=> not Static
);
7519 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
7526 when Attribute_Round
=> Round
:
7532 -- First we get the (exact result) in units of small
7534 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
7536 -- Now round that exactly to an integer
7538 Si
:= UR_To_Uint
(Sr
);
7540 -- Finally the result is obtained by converting back to real
7542 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
7549 when Attribute_Rounding
=>
7551 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7557 when Attribute_Safe_Emax
=>
7558 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
7564 when Attribute_Safe_First
=>
7565 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
7571 when Attribute_Safe_Large
=>
7572 if Is_Fixed_Point_Type
(P_Type
) then
7574 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
7576 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
7583 when Attribute_Safe_Last
=>
7584 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
7590 when Attribute_Safe_Small
=>
7592 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
7593 -- for fixed-point, since is the same as Small, but we implement
7594 -- it for backwards compatibility.
7596 if Is_Fixed_Point_Type
(P_Type
) then
7597 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
7599 -- Ada 83 Safe_Small for floating-point cases
7602 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
7609 when Attribute_Same_Storage
=>
7616 when Attribute_Scale
=>
7617 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
7623 when Attribute_Scaling
=>
7626 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
7632 when Attribute_Signed_Zeros
=>
7634 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
7640 -- Size attribute returns the RM size. All scalar types can be folded,
7641 -- as well as any types for which the size is known by the front end,
7642 -- including any type for which a size attribute is specified.
7644 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
7645 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7648 if RM_Size
(P_TypeA
) /= Uint_0
then
7652 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
7654 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
7657 -- If a size clause applies, then use the size from it.
7658 -- This is one of the rare cases where we can use the
7659 -- Size_Clause field for a subtype when Has_Size_Clause
7660 -- is False. Consider:
7662 -- type x is range 1 .. 64;
7663 -- for x'size use 12;
7664 -- subtype y is x range 0 .. 3;
7666 -- Here y has a size clause inherited from x, but normally
7667 -- it does not apply, and y'size is 2. However, y'VADS_Size
7668 -- is indeed 12 and not 2.
7671 and then Is_OK_Static_Expression
(Expression
(S
))
7673 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
7675 -- If no size is specified, then we simply use the object
7676 -- size in the VADS_Size case (e.g. Natural'Size is equal
7677 -- to Integer'Size, not one less).
7680 Fold_Uint
(N
, Esize
(P_TypeA
), True);
7684 -- Normal case (Size) in which case we want the RM_Size
7689 Static
and then Is_Discrete_Type
(P_TypeA
));
7698 when Attribute_Small
=>
7700 -- The floating-point case is present only for Ada 83 compatibility.
7701 -- Note that strictly this is an illegal addition, since we are
7702 -- extending an Ada 95 defined attribute, but we anticipate an
7703 -- ARG ruling that will permit this.
7705 if Is_Floating_Point_Type
(P_Type
) then
7707 -- Ada 83 attribute is defined as (RM83 3.5.8)
7709 -- T'Small = 2.0**(-T'Emax - 1)
7713 -- T'Emax = 4 * T'Mantissa
7715 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
7717 -- Normal Ada 95 fixed-point case
7720 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
7727 when Attribute_Stream_Size
=>
7734 when Attribute_Succ
=> Succ
:
7736 -- Floating-point case
7738 if Is_Floating_Point_Type
(P_Type
) then
7740 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7744 elsif Is_Fixed_Point_Type
(P_Type
) then
7746 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
7748 -- Modular integer case (wraps)
7750 elsif Is_Modular_Integer_Type
(P_Type
) then
7751 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
7753 -- Other scalar cases
7756 pragma Assert
(Is_Scalar_Type
(P_Type
));
7758 if Is_Enumeration_Type
(P_Type
)
7759 and then Expr_Value
(E1
) =
7760 Expr_Value
(Type_High_Bound
(P_Base_Type
))
7762 Apply_Compile_Time_Constraint_Error
7763 (N
, "Succ of `&''Last`",
7764 CE_Overflow_Check_Failed
,
7766 Warn
=> not Static
);
7771 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
7780 when Attribute_Truncation
=>
7782 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
7788 when Attribute_Type_Class
=> Type_Class
: declare
7789 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
7793 if Is_Descendent_Of_Address
(Typ
) then
7794 Id
:= RE_Type_Class_Address
;
7796 elsif Is_Enumeration_Type
(Typ
) then
7797 Id
:= RE_Type_Class_Enumeration
;
7799 elsif Is_Integer_Type
(Typ
) then
7800 Id
:= RE_Type_Class_Integer
;
7802 elsif Is_Fixed_Point_Type
(Typ
) then
7803 Id
:= RE_Type_Class_Fixed_Point
;
7805 elsif Is_Floating_Point_Type
(Typ
) then
7806 Id
:= RE_Type_Class_Floating_Point
;
7808 elsif Is_Array_Type
(Typ
) then
7809 Id
:= RE_Type_Class_Array
;
7811 elsif Is_Record_Type
(Typ
) then
7812 Id
:= RE_Type_Class_Record
;
7814 elsif Is_Access_Type
(Typ
) then
7815 Id
:= RE_Type_Class_Access
;
7817 elsif Is_Enumeration_Type
(Typ
) then
7818 Id
:= RE_Type_Class_Enumeration
;
7820 elsif Is_Task_Type
(Typ
) then
7821 Id
:= RE_Type_Class_Task
;
7823 -- We treat protected types like task types. It would make more
7824 -- sense to have another enumeration value, but after all the
7825 -- whole point of this feature is to be exactly DEC compatible,
7826 -- and changing the type Type_Class would not meet this requirement.
7828 elsif Is_Protected_Type
(Typ
) then
7829 Id
:= RE_Type_Class_Task
;
7831 -- Not clear if there are any other possibilities, but if there
7832 -- are, then we will treat them as the address case.
7835 Id
:= RE_Type_Class_Address
;
7838 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
7841 -----------------------
7842 -- Unbiased_Rounding --
7843 -----------------------
7845 when Attribute_Unbiased_Rounding
=>
7847 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
7850 -------------------------
7851 -- Unconstrained_Array --
7852 -------------------------
7854 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
7855 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7858 Rewrite
(N
, New_Occurrence_Of
(
7860 Is_Array_Type
(P_Type
)
7861 and then not Is_Constrained
(Typ
)), Loc
));
7863 -- Analyze and resolve as boolean, note that this attribute is
7864 -- a static attribute in GNAT.
7866 Analyze_And_Resolve
(N
, Standard_Boolean
);
7868 end Unconstrained_Array
;
7874 -- Processing is shared with Size
7880 when Attribute_Val
=> Val
:
7882 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
7884 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
7886 Apply_Compile_Time_Constraint_Error
7887 (N
, "Val expression out of range",
7888 CE_Range_Check_Failed
,
7889 Warn
=> not Static
);
7895 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7903 -- The Value_Size attribute for a type returns the RM size of the
7904 -- type. This an always be folded for scalar types, and can also
7905 -- be folded for non-scalar types if the size is set.
7907 when Attribute_Value_Size
=> Value_Size
: declare
7908 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7910 if RM_Size
(P_TypeA
) /= Uint_0
then
7911 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
7919 -- Version can never be static
7921 when Attribute_Version
=>
7928 -- Wide_Image is a scalar attribute, but is never static, because it
7929 -- is not a static function (having a non-scalar argument (RM 4.9(22))
7931 when Attribute_Wide_Image
=>
7934 ---------------------
7935 -- Wide_Wide_Image --
7936 ---------------------
7938 -- Wide_Wide_Image is a scalar attribute but is never static, because it
7939 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
7941 when Attribute_Wide_Wide_Image
=>
7944 ---------------------
7945 -- Wide_Wide_Width --
7946 ---------------------
7948 -- Processing for Wide_Wide_Width is combined with Width
7954 -- Processing for Wide_Width is combined with Width
7960 -- This processing also handles the case of Wide_[Wide_]Width
7962 when Attribute_Width |
7963 Attribute_Wide_Width |
7964 Attribute_Wide_Wide_Width
=> Width
:
7966 if Compile_Time_Known_Bounds
(P_Type
) then
7968 -- Floating-point types
7970 if Is_Floating_Point_Type
(P_Type
) then
7972 -- Width is zero for a null range (RM 3.5 (38))
7974 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
7975 Expr_Value_R
(Type_Low_Bound
(P_Type
))
7977 Fold_Uint
(N
, Uint_0
, True);
7980 -- For floating-point, we have +N.dddE+nnn where length
7981 -- of ddd is determined by type'Digits - 1, but is one
7982 -- if Digits is one (RM 3.5 (33)).
7984 -- nnn is set to 2 for Short_Float and Float (32 bit
7985 -- floats), and 3 for Long_Float and Long_Long_Float.
7986 -- For machines where Long_Long_Float is the IEEE
7987 -- extended precision type, the exponent takes 4 digits.
7991 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
7994 if Esize
(P_Type
) <= 32 then
7996 elsif Esize
(P_Type
) = 64 then
8002 Fold_Uint
(N
, UI_From_Int
(Len
), True);
8006 -- Fixed-point types
8008 elsif Is_Fixed_Point_Type
(P_Type
) then
8010 -- Width is zero for a null range (RM 3.5 (38))
8012 if Expr_Value
(Type_High_Bound
(P_Type
)) <
8013 Expr_Value
(Type_Low_Bound
(P_Type
))
8015 Fold_Uint
(N
, Uint_0
, True);
8017 -- The non-null case depends on the specific real type
8020 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
8023 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
8031 R
: constant Entity_Id
:= Root_Type
(P_Type
);
8032 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
8033 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
8046 -- Width for types derived from Standard.Character
8047 -- and Standard.Wide_[Wide_]Character.
8049 elsif Is_Standard_Character_Type
(P_Type
) then
8052 -- Set W larger if needed
8054 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
8056 -- All wide characters look like Hex_hhhhhhhh
8060 -- No need to compute this more than once!
8065 C
:= Character'Val (J
);
8067 -- Test for all cases where Character'Image
8068 -- yields an image that is longer than three
8069 -- characters. First the cases of Reserved_xxx
8070 -- names (length = 12).
8073 when Reserved_128 | Reserved_129 |
8074 Reserved_132 | Reserved_153
8077 when BS | HT | LF | VT | FF | CR |
8078 SO | SI | EM | FS | GS | RS |
8079 US | RI | MW | ST | PM
8082 when NUL | SOH | STX | ETX | EOT |
8083 ENQ | ACK | BEL | DLE | DC1 |
8084 DC2 | DC3 | DC4 | NAK | SYN |
8085 ETB | CAN | SUB | ESC | DEL |
8086 BPH | NBH | NEL | SSA | ESA |
8087 HTS | HTJ | VTS | PLD | PLU |
8088 SS2 | SS3 | DCS | PU1 | PU2 |
8089 STS | CCH | SPA | EPA | SOS |
8090 SCI | CSI | OSC | APC
8093 when Space
.. Tilde |
8094 No_Break_Space
.. LC_Y_Diaeresis
8096 -- Special case of soft hyphen in Ada 2005
8098 if C
= Character'Val (16#AD#
)
8099 and then Ada_Version
>= Ada_2005
8107 W
:= Int
'Max (W
, Wt
);
8111 -- Width for types derived from Standard.Boolean
8113 elsif R
= Standard_Boolean
then
8120 -- Width for integer types
8122 elsif Is_Integer_Type
(P_Type
) then
8123 T
:= UI_Max
(abs Lo
, abs Hi
);
8131 -- User declared enum type with discard names
8133 elsif Discard_Names
(R
) then
8135 -- If range is null, result is zero, that has already
8136 -- been dealt with, so what we need is the power of ten
8137 -- that accomodates the Pos of the largest value, which
8138 -- is the high bound of the range + one for the space.
8147 -- Only remaining possibility is user declared enum type
8148 -- with normal case of Discard_Names not active.
8151 pragma Assert
(Is_Enumeration_Type
(P_Type
));
8154 L
:= First_Literal
(P_Type
);
8155 while Present
(L
) loop
8157 -- Only pay attention to in range characters
8159 if Lo
<= Enumeration_Pos
(L
)
8160 and then Enumeration_Pos
(L
) <= Hi
8162 -- For Width case, use decoded name
8164 if Id
= Attribute_Width
then
8165 Get_Decoded_Name_String
(Chars
(L
));
8166 Wt
:= Nat
(Name_Len
);
8168 -- For Wide_[Wide_]Width, use encoded name, and
8169 -- then adjust for the encoding.
8172 Get_Name_String
(Chars
(L
));
8174 -- Character literals are always of length 3
8176 if Name_Buffer
(1) = 'Q' then
8179 -- Otherwise loop to adjust for upper/wide chars
8182 Wt
:= Nat
(Name_Len
);
8184 for J
in 1 .. Name_Len
loop
8185 if Name_Buffer
(J
) = 'U' then
8187 elsif Name_Buffer
(J
) = 'W' then
8194 W
:= Int
'Max (W
, Wt
);
8201 Fold_Uint
(N
, UI_From_Int
(W
), True);
8207 -- The following attributes denote functions that cannot be folded
8209 when Attribute_From_Any |
8211 Attribute_TypeCode
=>
8214 -- The following attributes can never be folded, and furthermore we
8215 -- should not even have entered the case statement for any of these.
8216 -- Note that in some cases, the values have already been folded as
8217 -- a result of the processing in Analyze_Attribute.
8219 when Attribute_Abort_Signal |
8222 Attribute_Address_Size |
8223 Attribute_Asm_Input |
8224 Attribute_Asm_Output |
8226 Attribute_Bit_Order |
8227 Attribute_Bit_Position |
8228 Attribute_Callable |
8231 Attribute_Code_Address |
8232 Attribute_Compiler_Version |
8234 Attribute_Default_Bit_Order |
8235 Attribute_Elaborated |
8236 Attribute_Elab_Body |
8237 Attribute_Elab_Spec |
8238 Attribute_Elab_Subp_Body |
8240 Attribute_External_Tag |
8241 Attribute_Fast_Math |
8242 Attribute_First_Bit |
8244 Attribute_Last_Bit |
8245 Attribute_Maximum_Alignment |
8248 Attribute_Partition_ID |
8249 Attribute_Pool_Address |
8250 Attribute_Position |
8251 Attribute_Priority |
8254 Attribute_Scalar_Storage_Order |
8255 Attribute_Simple_Storage_Pool |
8256 Attribute_Storage_Pool |
8257 Attribute_Storage_Size |
8258 Attribute_Storage_Unit |
8259 Attribute_Stub_Type |
8260 Attribute_System_Allocator_Alignment |
8262 Attribute_Target_Name |
8263 Attribute_Terminated |
8264 Attribute_To_Address |
8265 Attribute_Type_Key |
8266 Attribute_UET_Address |
8267 Attribute_Unchecked_Access |
8268 Attribute_Universal_Literal_String |
8269 Attribute_Unrestricted_Access |
8271 Attribute_Valid_Scalars |
8273 Attribute_Wchar_T_Size |
8274 Attribute_Wide_Value |
8275 Attribute_Wide_Wide_Value |
8276 Attribute_Word_Size |
8279 raise Program_Error
;
8282 -- At the end of the case, one more check. If we did a static evaluation
8283 -- so that the result is now a literal, then set Is_Static_Expression
8284 -- in the constant only if the prefix type is a static subtype. For
8285 -- non-static subtypes, the folding is still OK, but not static.
8287 -- An exception is the GNAT attribute Constrained_Array which is
8288 -- defined to be a static attribute in all cases.
8290 if Nkind_In
(N
, N_Integer_Literal
,
8292 N_Character_Literal
,
8294 or else (Is_Entity_Name
(N
)
8295 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
8297 Set_Is_Static_Expression
(N
, Static
);
8299 -- If this is still an attribute reference, then it has not been folded
8300 -- and that means that its expressions are in a non-static context.
8302 elsif Nkind
(N
) = N_Attribute_Reference
then
8305 -- Note: the else case not covered here are odd cases where the
8306 -- processing has transformed the attribute into something other
8307 -- than a constant. Nothing more to do in such cases.
8314 ------------------------------
8315 -- Is_Anonymous_Tagged_Base --
8316 ------------------------------
8318 function Is_Anonymous_Tagged_Base
8325 Anon
= Current_Scope
8326 and then Is_Itype
(Anon
)
8327 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
8328 end Is_Anonymous_Tagged_Base
;
8330 --------------------------------
8331 -- Name_Implies_Lvalue_Prefix --
8332 --------------------------------
8334 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
8335 pragma Assert
(Is_Attribute_Name
(Nam
));
8337 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
8338 end Name_Implies_Lvalue_Prefix
;
8340 -----------------------
8341 -- Resolve_Attribute --
8342 -----------------------
8344 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
8345 Loc
: constant Source_Ptr
:= Sloc
(N
);
8346 P
: constant Node_Id
:= Prefix
(N
);
8347 Aname
: constant Name_Id
:= Attribute_Name
(N
);
8348 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
8349 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8350 Des_Btyp
: Entity_Id
;
8351 Index
: Interp_Index
;
8353 Nom_Subt
: Entity_Id
;
8355 procedure Accessibility_Message
;
8356 -- Error, or warning within an instance, if the static accessibility
8357 -- rules of 3.10.2 are violated.
8359 ---------------------------
8360 -- Accessibility_Message --
8361 ---------------------------
8363 procedure Accessibility_Message
is
8364 Indic
: Node_Id
:= Parent
(Parent
(N
));
8367 -- In an instance, this is a runtime check, but one we
8368 -- know will fail, so generate an appropriate warning.
8370 if In_Instance_Body
then
8371 Error_Msg_F
("?non-local pointer cannot point to local object", P
);
8373 ("\?Program_Error will be raised at run time", P
);
8375 Make_Raise_Program_Error
(Loc
,
8376 Reason
=> PE_Accessibility_Check_Failed
));
8381 Error_Msg_F
("non-local pointer cannot point to local object", P
);
8383 -- Check for case where we have a missing access definition
8385 if Is_Record_Type
(Current_Scope
)
8387 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
8388 N_Index_Or_Discriminant_Constraint
)
8390 Indic
:= Parent
(Parent
(N
));
8391 while Present
(Indic
)
8392 and then Nkind
(Indic
) /= N_Subtype_Indication
8394 Indic
:= Parent
(Indic
);
8397 if Present
(Indic
) then
8399 ("\use an access definition for" &
8400 " the access discriminant of&",
8401 N
, Entity
(Subtype_Mark
(Indic
)));
8405 end Accessibility_Message
;
8407 -- Start of processing for Resolve_Attribute
8410 -- If error during analysis, no point in continuing, except for array
8411 -- types, where we get better recovery by using unconstrained indexes
8412 -- than nothing at all (see Check_Array_Type).
8415 and then Attr_Id
/= Attribute_First
8416 and then Attr_Id
/= Attribute_Last
8417 and then Attr_Id
/= Attribute_Length
8418 and then Attr_Id
/= Attribute_Range
8423 -- If attribute was universal type, reset to actual type
8425 if Etype
(N
) = Universal_Integer
8426 or else Etype
(N
) = Universal_Real
8431 -- Remaining processing depends on attribute
8439 -- For access attributes, if the prefix denotes an entity, it is
8440 -- interpreted as a name, never as a call. It may be overloaded,
8441 -- in which case resolution uses the profile of the context type.
8442 -- Otherwise prefix must be resolved.
8444 when Attribute_Access
8445 | Attribute_Unchecked_Access
8446 | Attribute_Unrestricted_Access
=>
8450 if Is_Variable
(P
) then
8451 Note_Possible_Modification
(P
, Sure
=> False);
8454 -- The following comes from a query by Adam Beneschan, concerning
8455 -- improper use of universal_access in equality tests involving
8456 -- anonymous access types. Another good reason for 'Ref, but
8457 -- for now disable the test, which breaks several filed tests.
8459 if Ekind
(Typ
) = E_Anonymous_Access_Type
8460 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
8463 Error_Msg_N
("need unique type to resolve 'Access", N
);
8464 Error_Msg_N
("\qualify attribute with some access type", N
);
8467 if Is_Entity_Name
(P
) then
8468 if Is_Overloaded
(P
) then
8469 Get_First_Interp
(P
, Index
, It
);
8470 while Present
(It
.Nam
) loop
8471 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
8472 Set_Entity
(P
, It
.Nam
);
8474 -- The prefix is definitely NOT overloaded anymore at
8475 -- this point, so we reset the Is_Overloaded flag to
8476 -- avoid any confusion when reanalyzing the node.
8478 Set_Is_Overloaded
(P
, False);
8479 Set_Is_Overloaded
(N
, False);
8480 Generate_Reference
(Entity
(P
), P
);
8484 Get_Next_Interp
(Index
, It
);
8487 -- If Prefix is a subprogram name, it is frozen by this
8490 -- If it is a type, there is nothing to resolve.
8491 -- If it is an object, complete its resolution.
8493 elsif Is_Overloadable
(Entity
(P
)) then
8495 -- Avoid insertion of freeze actions in spec expression mode
8497 if not In_Spec_Expression
then
8498 Freeze_Before
(N
, Entity
(P
));
8501 elsif Is_Type
(Entity
(P
)) then
8507 Error_Msg_Name_1
:= Aname
;
8509 if not Is_Entity_Name
(P
) then
8512 elsif Is_Overloadable
(Entity
(P
))
8513 and then Is_Abstract_Subprogram
(Entity
(P
))
8515 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
8516 Set_Etype
(N
, Any_Type
);
8518 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
8519 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
8521 ("prefix of % attribute cannot be enumeration literal",
8525 ("prefix of % attribute cannot be intrinsic", P
);
8528 Set_Etype
(N
, Any_Type
);
8531 -- Assignments, return statements, components of aggregates,
8532 -- generic instantiations will require convention checks if
8533 -- the type is an access to subprogram. Given that there will
8534 -- also be accessibility checks on those, this is where the
8535 -- checks can eventually be centralized ???
8537 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
8538 E_Anonymous_Access_Subprogram_Type
,
8539 E_Access_Protected_Subprogram_Type
,
8540 E_Anonymous_Access_Protected_Subprogram_Type
)
8542 -- Deal with convention mismatch
8544 if Convention
(Designated_Type
(Btyp
)) /=
8545 Convention
(Entity
(P
))
8548 ("subprogram & has wrong convention", P
, Entity
(P
));
8550 ("\does not match convention of access type &",
8553 if not Has_Convention_Pragma
(Btyp
) then
8555 ("\probable missing pragma Convention for &",
8560 Check_Subtype_Conformant
8561 (New_Id
=> Entity
(P
),
8562 Old_Id
=> Designated_Type
(Btyp
),
8566 if Attr_Id
= Attribute_Unchecked_Access
then
8567 Error_Msg_Name_1
:= Aname
;
8569 ("attribute% cannot be applied to a subprogram", P
);
8571 elsif Aname
= Name_Unrestricted_Access
then
8572 null; -- Nothing to check
8574 -- Check the static accessibility rule of 3.10.2(32).
8575 -- This rule also applies within the private part of an
8576 -- instantiation. This rule does not apply to anonymous
8577 -- access-to-subprogram types in access parameters.
8579 elsif Attr_Id
= Attribute_Access
8580 and then not In_Instance_Body
8582 (Ekind
(Btyp
) = E_Access_Subprogram_Type
8583 or else Is_Local_Anonymous_Access
(Btyp
))
8585 and then Subprogram_Access_Level
(Entity
(P
)) >
8586 Type_Access_Level
(Btyp
)
8589 ("subprogram must not be deeper than access type", P
);
8591 -- Check the restriction of 3.10.2(32) that disallows the
8592 -- access attribute within a generic body when the ultimate
8593 -- ancestor of the type of the attribute is declared outside
8594 -- of the generic unit and the subprogram is declared within
8595 -- that generic unit. This includes any such attribute that
8596 -- occurs within the body of a generic unit that is a child
8597 -- of the generic unit where the subprogram is declared.
8599 -- The rule also prohibits applying the attribute when the
8600 -- access type is a generic formal access type (since the
8601 -- level of the actual type is not known). This restriction
8602 -- does not apply when the attribute type is an anonymous
8603 -- access-to-subprogram type. Note that this check was
8604 -- revised by AI-229, because the originally Ada 95 rule
8605 -- was too lax. The original rule only applied when the
8606 -- subprogram was declared within the body of the generic,
8607 -- which allowed the possibility of dangling references).
8608 -- The rule was also too strict in some case, in that it
8609 -- didn't permit the access to be declared in the generic
8610 -- spec, whereas the revised rule does (as long as it's not
8613 -- There are a couple of subtleties of the test for applying
8614 -- the check that are worth noting. First, we only apply it
8615 -- when the levels of the subprogram and access type are the
8616 -- same (the case where the subprogram is statically deeper
8617 -- was applied above, and the case where the type is deeper
8618 -- is always safe). Second, we want the check to apply
8619 -- within nested generic bodies and generic child unit
8620 -- bodies, but not to apply to an attribute that appears in
8621 -- the generic unit's specification. This is done by testing
8622 -- that the attribute's innermost enclosing generic body is
8623 -- not the same as the innermost generic body enclosing the
8624 -- generic unit where the subprogram is declared (we don't
8625 -- want the check to apply when the access attribute is in
8626 -- the spec and there's some other generic body enclosing
8627 -- generic). Finally, there's no point applying the check
8628 -- when within an instance, because any violations will have
8629 -- been caught by the compilation of the generic unit.
8631 -- Note that we relax this check in CodePeer mode for
8632 -- compatibility with legacy code, since CodePeer is an
8633 -- Ada source code analyzer, not a strict compiler.
8634 -- ??? Note that a better approach would be to have a
8635 -- separate switch to relax this rule, and enable this
8636 -- switch in CodePeer mode.
8638 elsif Attr_Id
= Attribute_Access
8639 and then not CodePeer_Mode
8640 and then not In_Instance
8641 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
8642 and then Present
(Enclosing_Generic_Body
(N
))
8643 and then Enclosing_Generic_Body
(N
) /=
8644 Enclosing_Generic_Body
8645 (Enclosing_Generic_Unit
(Entity
(P
)))
8646 and then Subprogram_Access_Level
(Entity
(P
)) =
8647 Type_Access_Level
(Btyp
)
8648 and then Ekind
(Btyp
) /=
8649 E_Anonymous_Access_Subprogram_Type
8650 and then Ekind
(Btyp
) /=
8651 E_Anonymous_Access_Protected_Subprogram_Type
8653 -- The attribute type's ultimate ancestor must be
8654 -- declared within the same generic unit as the
8655 -- subprogram is declared. The error message is
8656 -- specialized to say "ancestor" for the case where the
8657 -- access type is not its own ancestor, since saying
8658 -- simply "access type" would be very confusing.
8660 if Enclosing_Generic_Unit
(Entity
(P
)) /=
8661 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
8664 ("''Access attribute not allowed in generic body",
8667 if Root_Type
(Btyp
) = Btyp
then
8670 "access type & is declared outside " &
8671 "generic unit (RM 3.10.2(32))", N
, Btyp
);
8674 ("\because ancestor of " &
8675 "access type & is declared outside " &
8676 "generic unit (RM 3.10.2(32))", N
, Btyp
);
8680 ("\move ''Access to private part, or " &
8681 "(Ada 2005) use anonymous access type instead of &",
8684 -- If the ultimate ancestor of the attribute's type is
8685 -- a formal type, then the attribute is illegal because
8686 -- the actual type might be declared at a higher level.
8687 -- The error message is specialized to say "ancestor"
8688 -- for the case where the access type is not its own
8689 -- ancestor, since saying simply "access type" would be
8692 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
8693 if Root_Type
(Btyp
) = Btyp
then
8695 ("access type must not be a generic formal type",
8699 ("ancestor access type must not be a generic " &
8706 -- If this is a renaming, an inherited operation, or a
8707 -- subprogram instance, use the original entity. This may make
8708 -- the node type-inconsistent, so this transformation can only
8709 -- be done if the node will not be reanalyzed. In particular,
8710 -- if it is within a default expression, the transformation
8711 -- must be delayed until the default subprogram is created for
8712 -- it, when the enclosing subprogram is frozen.
8714 if Is_Entity_Name
(P
)
8715 and then Is_Overloadable
(Entity
(P
))
8716 and then Present
(Alias
(Entity
(P
)))
8717 and then Expander_Active
8720 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
8723 elsif Nkind
(P
) = N_Selected_Component
8724 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
8726 -- Protected operation. If operation is overloaded, must
8727 -- disambiguate. Prefix that denotes protected object itself
8728 -- is resolved with its own type.
8730 if Attr_Id
= Attribute_Unchecked_Access
then
8731 Error_Msg_Name_1
:= Aname
;
8733 ("attribute% cannot be applied to protected operation", P
);
8736 Resolve
(Prefix
(P
));
8737 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
8739 elsif Is_Overloaded
(P
) then
8741 -- Use the designated type of the context to disambiguate
8742 -- Note that this was not strictly conformant to Ada 95,
8743 -- but was the implementation adopted by most Ada 95 compilers.
8744 -- The use of the context type to resolve an Access attribute
8745 -- reference is now mandated in AI-235 for Ada 2005.
8748 Index
: Interp_Index
;
8752 Get_First_Interp
(P
, Index
, It
);
8753 while Present
(It
.Typ
) loop
8754 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
8755 Resolve
(P
, It
.Typ
);
8759 Get_Next_Interp
(Index
, It
);
8766 -- X'Access is illegal if X denotes a constant and the access type
8767 -- is access-to-variable. Same for 'Unchecked_Access. The rule
8768 -- does not apply to 'Unrestricted_Access. If the reference is a
8769 -- default-initialized aggregate component for a self-referential
8770 -- type the reference is legal.
8772 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
8773 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
8774 or else (Is_Record_Type
(Btyp
)
8776 Present
(Corresponding_Remote_Type
(Btyp
)))
8777 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
8778 or else Ekind
(Btyp
)
8779 = E_Anonymous_Access_Protected_Subprogram_Type
8780 or else Is_Access_Constant
(Btyp
)
8781 or else Is_Variable
(P
)
8782 or else Attr_Id
= Attribute_Unrestricted_Access
)
8784 if Is_Entity_Name
(P
)
8785 and then Is_Type
(Entity
(P
))
8787 -- Legality of a self-reference through an access
8788 -- attribute has been verified in Analyze_Access_Attribute.
8792 elsif Comes_From_Source
(N
) then
8793 Error_Msg_F
("access-to-variable designates constant", P
);
8797 Des_Btyp
:= Designated_Type
(Btyp
);
8799 if Ada_Version
>= Ada_2005
8800 and then Is_Incomplete_Type
(Des_Btyp
)
8802 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
8803 -- imported entity, and the non-limited view is visible, make
8804 -- use of it. If it is an incomplete subtype, use the base type
8807 if From_With_Type
(Des_Btyp
)
8808 and then Present
(Non_Limited_View
(Des_Btyp
))
8810 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
8812 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
8813 Des_Btyp
:= Etype
(Des_Btyp
);
8817 if (Attr_Id
= Attribute_Access
8819 Attr_Id
= Attribute_Unchecked_Access
)
8820 and then (Ekind
(Btyp
) = E_General_Access_Type
8821 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
8823 -- Ada 2005 (AI-230): Check the accessibility of anonymous
8824 -- access types for stand-alone objects, record and array
8825 -- components, and return objects. For a component definition
8826 -- the level is the same of the enclosing composite type.
8828 if Ada_Version
>= Ada_2005
8829 and then (Is_Local_Anonymous_Access
(Btyp
)
8831 -- Handle cases where Btyp is the anonymous access
8832 -- type of an Ada 2012 stand-alone object.
8834 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
8835 N_Object_Declaration
)
8837 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
8838 and then Attr_Id
= Attribute_Access
8840 -- In an instance, this is a runtime check, but one we
8841 -- know will fail, so generate an appropriate warning.
8843 if In_Instance_Body
then
8845 ("?non-local pointer cannot point to local object", P
);
8847 ("\?Program_Error will be raised at run time", P
);
8849 Make_Raise_Program_Error
(Loc
,
8850 Reason
=> PE_Accessibility_Check_Failed
));
8855 ("non-local pointer cannot point to local object", P
);
8859 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
8861 ("illegal attribute for discriminant-dependent component",
8865 -- Check static matching rule of 3.10.2(27). Nominal subtype
8866 -- of the prefix must statically match the designated type.
8868 Nom_Subt
:= Etype
(P
);
8870 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
8871 Nom_Subt
:= Base_Type
(Nom_Subt
);
8874 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
8876 -- If the attribute is in the context of an access
8877 -- parameter, then the prefix is allowed to be of the
8878 -- class-wide type (by AI-127).
8880 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
8881 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
8882 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
8888 Desig
:= Designated_Type
(Typ
);
8890 if Is_Class_Wide_Type
(Desig
) then
8891 Desig
:= Etype
(Desig
);
8894 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
8899 ("type of prefix: & not compatible",
8902 ("\with &, the expected designated type",
8903 P
, Designated_Type
(Typ
));
8908 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
8910 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
8911 and then Is_Class_Wide_Type
(Nom_Subt
))
8914 ("type of prefix: & is not covered", P
, Nom_Subt
);
8916 ("\by &, the expected designated type" &
8917 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
8920 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
8921 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
8922 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
8923 and then Designated_Type
(Typ
) /= Nom_Subt
8925 Apply_Discriminant_Check
8926 (N
, Etype
(Designated_Type
(Typ
)));
8929 -- Ada 2005 (AI-363): Require static matching when designated
8930 -- type has discriminants and a constrained partial view, since
8931 -- in general objects of such types are mutable, so we can't
8932 -- allow the access value to designate a constrained object
8933 -- (because access values must be assumed to designate mutable
8934 -- objects when designated type does not impose a constraint).
8936 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
8939 elsif Has_Discriminants
(Designated_Type
(Typ
))
8940 and then not Is_Constrained
(Des_Btyp
)
8942 (Ada_Version
< Ada_2005
8944 not Effectively_Has_Constrained_Partial_View
8945 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
8946 Scop
=> Current_Scope
))
8952 ("object subtype must statically match "
8953 & "designated subtype", P
);
8955 if Is_Entity_Name
(P
)
8956 and then Is_Array_Type
(Designated_Type
(Typ
))
8959 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
8961 Error_Msg_N
("aliased object has explicit bounds?",
8963 Error_Msg_N
("\declare without bounds"
8964 & " (and with explicit initialization)?", D
);
8965 Error_Msg_N
("\for use with unconstrained access?", D
);
8970 -- Check the static accessibility rule of 3.10.2(28). Note that
8971 -- this check is not performed for the case of an anonymous
8972 -- access type, since the access attribute is always legal
8973 -- in such a context.
8975 if Attr_Id
/= Attribute_Unchecked_Access
8977 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
8978 and then Ekind
(Btyp
) = E_General_Access_Type
8980 Accessibility_Message
;
8985 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
8986 E_Anonymous_Access_Protected_Subprogram_Type
)
8988 if Is_Entity_Name
(P
)
8989 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
8991 Error_Msg_F
("context requires a protected subprogram", P
);
8993 -- Check accessibility of protected object against that of the
8994 -- access type, but only on user code, because the expander
8995 -- creates access references for handlers. If the context is an
8996 -- anonymous_access_to_protected, there are no accessibility
8997 -- checks either. Omit check entirely for Unrestricted_Access.
8999 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
9000 and then Comes_From_Source
(N
)
9001 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
9002 and then Attr_Id
/= Attribute_Unrestricted_Access
9004 Accessibility_Message
;
9008 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9009 E_Anonymous_Access_Subprogram_Type
)
9010 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
9012 Error_Msg_F
("context requires a non-protected subprogram", P
);
9015 -- The context cannot be a pool-specific type, but this is a
9016 -- legality rule, not a resolution rule, so it must be checked
9017 -- separately, after possibly disambiguation (see AI-245).
9019 if Ekind
(Btyp
) = E_Access_Type
9020 and then Attr_Id
/= Attribute_Unrestricted_Access
9022 Wrong_Type
(N
, Typ
);
9025 -- The context may be a constrained access type (however ill-
9026 -- advised such subtypes might be) so in order to generate a
9027 -- constraint check when needed set the type of the attribute
9028 -- reference to the base type of the context.
9030 Set_Etype
(N
, Btyp
);
9032 -- Check for incorrect atomic/volatile reference (RM C.6(12))
9034 if Attr_Id
/= Attribute_Unrestricted_Access
then
9035 if Is_Atomic_Object
(P
)
9036 and then not Is_Atomic
(Designated_Type
(Typ
))
9039 ("access to atomic object cannot yield access-to-" &
9040 "non-atomic type", P
);
9042 elsif Is_Volatile_Object
(P
)
9043 and then not Is_Volatile
(Designated_Type
(Typ
))
9046 ("access to volatile object cannot yield access-to-" &
9047 "non-volatile type", P
);
9051 if Is_Entity_Name
(P
) then
9052 Set_Address_Taken
(Entity
(P
));
9054 end Access_Attribute
;
9060 -- Deal with resolving the type for Address attribute, overloading
9061 -- is not permitted here, since there is no context to resolve it.
9063 when Attribute_Address | Attribute_Code_Address
=>
9064 Address_Attribute
: begin
9066 -- To be safe, assume that if the address of a variable is taken,
9067 -- it may be modified via this address, so note modification.
9069 if Is_Variable
(P
) then
9070 Note_Possible_Modification
(P
, Sure
=> False);
9073 if Nkind
(P
) in N_Subexpr
9074 and then Is_Overloaded
(P
)
9076 Get_First_Interp
(P
, Index
, It
);
9077 Get_Next_Interp
(Index
, It
);
9079 if Present
(It
.Nam
) then
9080 Error_Msg_Name_1
:= Aname
;
9082 ("prefix of % attribute cannot be overloaded", P
);
9086 if not Is_Entity_Name
(P
)
9087 or else not Is_Overloadable
(Entity
(P
))
9089 if not Is_Task_Type
(Etype
(P
))
9090 or else Nkind
(P
) = N_Explicit_Dereference
9096 -- If this is the name of a derived subprogram, or that of a
9097 -- generic actual, the address is that of the original entity.
9099 if Is_Entity_Name
(P
)
9100 and then Is_Overloadable
(Entity
(P
))
9101 and then Present
(Alias
(Entity
(P
)))
9104 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
9107 if Is_Entity_Name
(P
) then
9108 Set_Address_Taken
(Entity
(P
));
9111 if Nkind
(P
) = N_Slice
then
9113 -- Arr (X .. Y)'address is identical to Arr (X)'address,
9114 -- even if the array is packed and the slice itself is not
9115 -- addressable. Transform the prefix into an indexed component.
9117 -- Note that the transformation is safe only if we know that
9118 -- the slice is non-null. That is because a null slice can have
9119 -- an out of bounds index value.
9121 -- Right now, gigi blows up if given 'Address on a slice as a
9122 -- result of some incorrect freeze nodes generated by the front
9123 -- end, and this covers up that bug in one case, but the bug is
9124 -- likely still there in the cases not handled by this code ???
9126 -- It's not clear what 'Address *should* return for a null
9127 -- slice with out of bounds indexes, this might be worth an ARG
9130 -- One approach would be to do a length check unconditionally,
9131 -- and then do the transformation below unconditionally, but
9132 -- analyze with checks off, avoiding the problem of the out of
9133 -- bounds index. This approach would interpret the address of
9134 -- an out of bounds null slice as being the address where the
9135 -- array element would be if there was one, which is probably
9136 -- as reasonable an interpretation as any ???
9139 Loc
: constant Source_Ptr
:= Sloc
(P
);
9140 D
: constant Node_Id
:= Discrete_Range
(P
);
9144 if Is_Entity_Name
(D
)
9147 (Type_Low_Bound
(Entity
(D
)),
9148 Type_High_Bound
(Entity
(D
)))
9151 Make_Attribute_Reference
(Loc
,
9152 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
9153 Attribute_Name
=> Name_First
);
9155 elsif Nkind
(D
) = N_Range
9156 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
9158 Lo
:= Low_Bound
(D
);
9164 if Present
(Lo
) then
9166 Make_Indexed_Component
(Loc
,
9167 Prefix
=> Relocate_Node
(Prefix
(P
)),
9168 Expressions
=> New_List
(Lo
)));
9170 Analyze_And_Resolve
(P
);
9174 end Address_Attribute
;
9180 -- Prefix of the AST_Entry attribute is an entry name which must
9181 -- not be resolved, since this is definitely not an entry call.
9183 when Attribute_AST_Entry
=>
9190 -- Prefix of Body_Version attribute can be a subprogram name which
9191 -- must not be resolved, since this is not a call.
9193 when Attribute_Body_Version
=>
9200 -- Prefix of Caller attribute is an entry name which must not
9201 -- be resolved, since this is definitely not an entry call.
9203 when Attribute_Caller
=>
9210 -- Shares processing with Address attribute
9216 -- If the prefix of the Count attribute is an entry name it must not
9217 -- be resolved, since this is definitely not an entry call. However,
9218 -- if it is an element of an entry family, the index itself may
9219 -- have to be resolved because it can be a general expression.
9221 when Attribute_Count
=>
9222 if Nkind
(P
) = N_Indexed_Component
9223 and then Is_Entity_Name
(Prefix
(P
))
9226 Indx
: constant Node_Id
:= First
(Expressions
(P
));
9227 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
9229 Resolve
(Indx
, Entry_Index_Type
(Fam
));
9230 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
9238 -- Prefix of the Elaborated attribute is a subprogram name which
9239 -- must not be resolved, since this is definitely not a call. Note
9240 -- that it is a library unit, so it cannot be overloaded here.
9242 when Attribute_Elaborated
=>
9249 -- Prefix of Enabled attribute is a check name, which must be treated
9250 -- specially and not touched by Resolve.
9252 when Attribute_Enabled
=>
9255 --------------------
9256 -- Mechanism_Code --
9257 --------------------
9259 -- Prefix of the Mechanism_Code attribute is a function name
9260 -- which must not be resolved. Should we check for overloaded ???
9262 when Attribute_Mechanism_Code
=>
9269 -- Most processing is done in sem_dist, after determining the
9270 -- context type. Node is rewritten as a conversion to a runtime call.
9272 when Attribute_Partition_ID
=>
9273 Process_Partition_Id
(N
);
9280 when Attribute_Pool_Address
=>
9287 -- We replace the Range attribute node with a range expression whose
9288 -- bounds are the 'First and 'Last attributes applied to the same
9289 -- prefix. The reason that we do this transformation here instead of
9290 -- in the expander is that it simplifies other parts of the semantic
9291 -- analysis which assume that the Range has been replaced; thus it
9292 -- must be done even when in semantic-only mode (note that the RM
9293 -- specifically mentions this equivalence, we take care that the
9294 -- prefix is only evaluated once).
9296 when Attribute_Range
=> Range_Attribute
:
9303 if not Is_Entity_Name
(P
)
9304 or else not Is_Type
(Entity
(P
))
9309 Dims
:= Expressions
(N
);
9312 Make_Attribute_Reference
(Loc
,
9314 Duplicate_Subexpr
(P
, Name_Req
=> True),
9315 Attribute_Name
=> Name_Last
,
9316 Expressions
=> Dims
);
9319 Make_Attribute_Reference
(Loc
,
9321 Attribute_Name
=> Name_First
,
9322 Expressions
=> (Dims
));
9324 -- Do not share the dimension indicator, if present. Even
9325 -- though it is a static constant, its source location
9326 -- may be modified when printing expanded code and node
9327 -- sharing will lead to chaos in Sprint.
9329 if Present
(Dims
) then
9330 Set_Expressions
(LB
,
9331 New_List
(New_Copy_Tree
(First
(Dims
))));
9334 -- If the original was marked as Must_Not_Freeze (see code
9335 -- in Sem_Ch3.Make_Index), then make sure the rewriting
9336 -- does not freeze either.
9338 if Must_Not_Freeze
(N
) then
9339 Set_Must_Not_Freeze
(HB
);
9340 Set_Must_Not_Freeze
(LB
);
9341 Set_Must_Not_Freeze
(Prefix
(HB
));
9342 Set_Must_Not_Freeze
(Prefix
(LB
));
9345 if Raises_Constraint_Error
(Prefix
(N
)) then
9347 -- Preserve Sloc of prefix in the new bounds, so that
9348 -- the posted warning can be removed if we are within
9349 -- unreachable code.
9351 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
9352 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
9355 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
9356 Analyze_And_Resolve
(N
, Typ
);
9358 -- Ensure that the expanded range does not have side effects
9360 Force_Evaluation
(LB
);
9361 Force_Evaluation
(HB
);
9363 -- Normally after resolving attribute nodes, Eval_Attribute
9364 -- is called to do any possible static evaluation of the node.
9365 -- However, here since the Range attribute has just been
9366 -- transformed into a range expression it is no longer an
9367 -- attribute node and therefore the call needs to be avoided
9368 -- and is accomplished by simply returning from the procedure.
9371 end Range_Attribute
;
9377 -- We will only come here during the prescan of a spec expression
9378 -- containing a Result attribute. In that case the proper Etype has
9379 -- already been set, and nothing more needs to be done here.
9381 when Attribute_Result
=>
9388 -- Prefix must not be resolved in this case, since it is not a
9389 -- real entity reference. No action of any kind is require!
9391 when Attribute_UET_Address
=>
9394 ----------------------
9395 -- Unchecked_Access --
9396 ----------------------
9398 -- Processing is shared with Access
9400 -------------------------
9401 -- Unrestricted_Access --
9402 -------------------------
9404 -- Processing is shared with Access
9410 -- Apply range check. Note that we did not do this during the
9411 -- analysis phase, since we wanted Eval_Attribute to have a
9412 -- chance at finding an illegal out of range value.
9414 when Attribute_Val
=>
9416 -- Note that we do our own Eval_Attribute call here rather than
9417 -- use the common one, because we need to do processing after
9418 -- the call, as per above comment.
9422 -- Eval_Attribute may replace the node with a raise CE, or
9423 -- fold it to a constant. Obviously we only apply a scalar
9424 -- range check if this did not happen!
9426 if Nkind
(N
) = N_Attribute_Reference
9427 and then Attribute_Name
(N
) = Name_Val
9429 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
9438 -- Prefix of Version attribute can be a subprogram name which
9439 -- must not be resolved, since this is not a call.
9441 when Attribute_Version
=>
9444 ----------------------
9445 -- Other Attributes --
9446 ----------------------
9448 -- For other attributes, resolve prefix unless it is a type. If
9449 -- the attribute reference itself is a type name ('Base and 'Class)
9450 -- then this is only legal within a task or protected record.
9453 if not Is_Entity_Name
(P
)
9454 or else not Is_Type
(Entity
(P
))
9459 -- If the attribute reference itself is a type name ('Base,
9460 -- 'Class) then this is only legal within a task or protected
9461 -- record. What is this all about ???
9463 if Is_Entity_Name
(N
)
9464 and then Is_Type
(Entity
(N
))
9466 if Is_Concurrent_Type
(Entity
(N
))
9467 and then In_Open_Scopes
(Entity
(P
))
9472 ("invalid use of subtype name in expression or call", N
);
9476 -- For attributes whose argument may be a string, complete
9477 -- resolution of argument now. This avoids premature expansion
9478 -- (and the creation of transient scopes) before the attribute
9479 -- reference is resolved.
9482 when Attribute_Value
=>
9483 Resolve
(First
(Expressions
(N
)), Standard_String
);
9485 when Attribute_Wide_Value
=>
9486 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
9488 when Attribute_Wide_Wide_Value
=>
9489 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
9491 when others => null;
9494 -- If the prefix of the attribute is a class-wide type then it
9495 -- will be expanded into a dispatching call to a predefined
9496 -- primitive. Therefore we must check for potential violation
9497 -- of such restriction.
9499 if Is_Class_Wide_Type
(Etype
(P
)) then
9500 Check_Restriction
(No_Dispatching_Calls
, N
);
9504 -- Normally the Freezing is done by Resolve but sometimes the Prefix
9505 -- is not resolved, in which case the freezing must be done now.
9507 Freeze_Expression
(P
);
9509 -- Finally perform static evaluation on the attribute reference
9511 Analyze_Dimension
(N
);
9513 end Resolve_Attribute
;
9515 --------------------------------
9516 -- Stream_Attribute_Available --
9517 --------------------------------
9519 function Stream_Attribute_Available
9521 Nam
: TSS_Name_Type
;
9522 Partial_View
: Node_Id
:= Empty
) return Boolean
9524 Etyp
: Entity_Id
:= Typ
;
9526 -- Start of processing for Stream_Attribute_Available
9529 -- We need some comments in this body ???
9531 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
9535 if Is_Class_Wide_Type
(Typ
) then
9536 return not Is_Limited_Type
(Typ
)
9537 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
9540 if Nam
= TSS_Stream_Input
9541 and then Is_Abstract_Type
(Typ
)
9542 and then not Is_Class_Wide_Type
(Typ
)
9547 if not (Is_Limited_Type
(Typ
)
9548 or else (Present
(Partial_View
)
9549 and then Is_Limited_Type
(Partial_View
)))
9554 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
9556 if Nam
= TSS_Stream_Input
9557 and then Ada_Version
>= Ada_2005
9558 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
9562 elsif Nam
= TSS_Stream_Output
9563 and then Ada_Version
>= Ada_2005
9564 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
9569 -- Case of Read and Write: check for attribute definition clause that
9570 -- applies to an ancestor type.
9572 while Etype
(Etyp
) /= Etyp
loop
9573 Etyp
:= Etype
(Etyp
);
9575 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
9580 if Ada_Version
< Ada_2005
then
9582 -- In Ada 95 mode, also consider a non-visible definition
9585 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
9588 and then Stream_Attribute_Available
9589 (Btyp
, Nam
, Partial_View
=> Typ
);
9594 end Stream_Attribute_Available
;