1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Elists
; use Elists
;
34 with Errout
; use Errout
;
36 with Exp_Dist
; use Exp_Dist
;
37 with Exp_Util
; use Exp_Util
;
38 with Expander
; use Expander
;
39 with Freeze
; use Freeze
;
40 with Gnatvsn
; use Gnatvsn
;
41 with Itypes
; use Itypes
;
43 with Lib
.Xref
; use Lib
.Xref
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
50 with Sdefault
; use Sdefault
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Cat
; use Sem_Cat
;
54 with Sem_Ch6
; use Sem_Ch6
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch10
; use Sem_Ch10
;
57 with Sem_Dim
; use Sem_Dim
;
58 with Sem_Dist
; use Sem_Dist
;
59 with Sem_Elab
; use Sem_Elab
;
60 with Sem_Elim
; use Sem_Elim
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Res
; use Sem_Res
;
63 with Sem_Type
; use Sem_Type
;
64 with Sem_Util
; use Sem_Util
;
65 with Stand
; use Stand
;
66 with Sinfo
; use Sinfo
;
67 with Sinput
; use Sinput
;
68 with Stringt
; use Stringt
;
70 with Stylesw
; use Stylesw
;
71 with Targparm
; use Targparm
;
72 with Ttypes
; use Ttypes
;
73 with Tbuild
; use Tbuild
;
74 with Uintp
; use Uintp
;
75 with Uname
; use Uname
;
76 with Urealp
; use Urealp
;
78 package body Sem_Attr
is
80 True_Value
: constant Uint
:= Uint_1
;
81 False_Value
: constant Uint
:= Uint_0
;
82 -- Synonyms to be used when these constants are used as Boolean values
84 Bad_Attribute
: exception;
85 -- Exception raised if an error is detected during attribute processing,
86 -- used so that we can abandon the processing so we don't run into
87 -- trouble with cascaded errors.
89 -- The following array is the list of attributes defined in the Ada 83 RM
90 -- that are not included in Ada 95, but still get recognized in GNAT.
92 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
98 Attribute_Constrained |
105 Attribute_First_Bit |
111 Attribute_Leading_Part |
113 Attribute_Machine_Emax |
114 Attribute_Machine_Emin |
115 Attribute_Machine_Mantissa |
116 Attribute_Machine_Overflows |
117 Attribute_Machine_Radix |
118 Attribute_Machine_Rounds |
124 Attribute_Safe_Emax |
125 Attribute_Safe_Large |
126 Attribute_Safe_Small |
129 Attribute_Storage_Size |
131 Attribute_Terminated |
134 Attribute_Width => True,
137 -- The following array is the list of attributes defined in the Ada 2005
138 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
139 -- but in Ada 95 they are considered to be implementation defined.
141 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
142 Attribute_Machine_Rounding |
145 Attribute_Stream_Size |
146 Attribute_Wide_Wide_Width
=> True,
149 -- The following array contains all attributes that imply a modification
150 -- of their prefixes or result in an access value. Such prefixes can be
151 -- considered as lvalues.
153 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
154 Attribute_Class_Array
'(
159 Attribute_Unchecked_Access |
160 Attribute_Unrestricted_Access => True,
163 -----------------------
164 -- Local_Subprograms --
165 -----------------------
167 procedure Eval_Attribute (N : Node_Id);
168 -- Performs compile time evaluation of attributes where possible, leaving
169 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
170 -- set, and replacing the node with a literal node if the value can be
171 -- computed at compile time. All static attribute references are folded,
172 -- as well as a number of cases of non-static attributes that can always
173 -- be computed at compile time (e.g. floating-point model attributes that
174 -- are applied to non-static subtypes). Of course in such cases, the
175 -- Is_Static_Expression flag will not be set on the resulting literal.
176 -- Note that the only required action of this procedure is to catch the
177 -- static expression cases as described in the RM. Folding of other cases
178 -- is done where convenient, but some additional non-static folding is in
179 -- Expand_N_Attribute_Reference in cases where this is more convenient.
181 function Is_Anonymous_Tagged_Base
185 -- For derived tagged types that constrain parent discriminants we build
186 -- an anonymous unconstrained base type. We need to recognize the relation
187 -- between the two when analyzing an access attribute for a constrained
188 -- component, before the full declaration for Typ has been analyzed, and
189 -- where therefore the prefix of the attribute does not match the enclosing
192 -----------------------
193 -- Analyze_Attribute --
194 -----------------------
196 procedure Analyze_Attribute (N : Node_Id) is
197 Loc : constant Source_Ptr := Sloc (N);
198 Aname : constant Name_Id := Attribute_Name (N);
199 P : constant Node_Id := Prefix (N);
200 Exprs : constant List_Id := Expressions (N);
201 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
206 -- Type of prefix after analysis
208 P_Base_Type : Entity_Id;
209 -- Base type of prefix after analysis
211 -----------------------
212 -- Local Subprograms --
213 -----------------------
215 procedure Analyze_Access_Attribute;
216 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
217 -- Internally, Id distinguishes which of the three cases is involved.
219 procedure Bad_Attribute_For_Predicate;
220 -- Output error message for use of a predicate (First, Last, Range) not
221 -- allowed with a type that has predicates. If the type is a generic
222 -- actual, then the message is a warning, and we generate code to raise
223 -- program error with an appropriate reason. No error message is given
224 -- for internally generated uses of the attributes. This legality rule
225 -- only applies to scalar types.
227 procedure Check_Ada_2012_Attribute;
228 -- Check that we are in Ada 2012 mode for an Ada 2012 attribute, and
229 -- issue appropriate messages if not (and return to caller even in
232 procedure Check_Array_Or_Scalar_Type;
233 -- Common procedure used by First, Last, Range attribute to check
234 -- that the prefix is a constrained array or scalar type, or a name
235 -- of an array object, and that an argument appears only if appropriate
236 -- (i.e. only in the array case).
238 procedure Check_Array_Type;
239 -- Common semantic checks for all array attributes. Checks that the
240 -- prefix is a constrained array type or the name of an array object.
241 -- The error message for non-arrays is specialized appropriately.
243 procedure Check_Asm_Attribute;
244 -- Common semantic checks for Asm_Input and Asm_Output attributes
246 procedure Check_Component;
247 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
248 -- Position. Checks prefix is an appropriate selected component.
250 procedure Check_Decimal_Fixed_Point_Type;
251 -- Check that prefix of attribute N is a decimal fixed-point type
253 procedure Check_Dereference;
254 -- If the prefix of attribute is an object of an access type, then
255 -- introduce an explicit dereference, and adjust P_Type accordingly.
257 procedure Check_Discrete_Type;
258 -- Verify that prefix of attribute N is a discrete type
261 -- Check that no attribute arguments are present
263 procedure Check_Either_E0_Or_E1;
264 -- Check that there are zero or one attribute arguments present
267 -- Check that exactly one attribute argument is present
270 -- Check that two attribute arguments are present
272 procedure Check_Enum_Image;
273 -- If the prefix type is an enumeration type, set all its literals
274 -- as referenced, since the image function could possibly end up
275 -- referencing any of the literals indirectly. Same for Enum_Val.
276 -- Set the flag only if the reference is in the main code unit. Same
277 -- restriction when resolving 'Value
; otherwise an improperly set
278 -- reference when analyzing an inlined body will lose a proper warning
279 -- on a useless with_clause.
281 procedure Check_First_Last_Valid
;
282 -- Perform all checks for First_Valid and Last_Valid attributes
284 procedure Check_Fixed_Point_Type
;
285 -- Verify that prefix of attribute N is a fixed type
287 procedure Check_Fixed_Point_Type_0
;
288 -- Verify that prefix of attribute N is a fixed type and that
289 -- no attribute expressions are present
291 procedure Check_Floating_Point_Type
;
292 -- Verify that prefix of attribute N is a float type
294 procedure Check_Floating_Point_Type_0
;
295 -- Verify that prefix of attribute N is a float type and that
296 -- no attribute expressions are present
298 procedure Check_Floating_Point_Type_1
;
299 -- Verify that prefix of attribute N is a float type and that
300 -- exactly one attribute expression is present
302 procedure Check_Floating_Point_Type_2
;
303 -- Verify that prefix of attribute N is a float type and that
304 -- two attribute expressions are present
306 procedure Legal_Formal_Attribute
;
307 -- Common processing for attributes Definite and Has_Discriminants.
308 -- Checks that prefix is generic indefinite formal type.
310 procedure Check_SPARK_Restriction_On_Attribute
;
311 -- Issue an error in formal mode because attribute N is allowed
313 procedure Check_Integer_Type
;
314 -- Verify that prefix of attribute N is an integer type
316 procedure Check_Modular_Integer_Type
;
317 -- Verify that prefix of attribute N is a modular integer type
319 procedure Check_Not_CPP_Type
;
320 -- Check that P (the prefix of the attribute) is not an CPP type
321 -- for which no Ada predefined primitive is available.
323 procedure Check_Not_Incomplete_Type
;
324 -- Check that P (the prefix of the attribute) is not an incomplete
325 -- type or a private type for which no full view has been given.
327 procedure Check_Object_Reference
(P
: Node_Id
);
328 -- Check that P is an object reference
330 procedure Check_Program_Unit
;
331 -- Verify that prefix of attribute N is a program unit
333 procedure Check_Real_Type
;
334 -- Verify that prefix of attribute N is fixed or float type
336 procedure Check_Scalar_Type
;
337 -- Verify that prefix of attribute N is a scalar type
339 procedure Check_Standard_Prefix
;
340 -- Verify that prefix of attribute N is package Standard
342 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
343 -- Validity checking for stream attribute. Nam is the TSS name of the
344 -- corresponding possible defined attribute function (e.g. for the
345 -- Read attribute, Nam will be TSS_Stream_Read).
347 procedure Check_PolyORB_Attribute
;
348 -- Validity checking for PolyORB/DSA attribute
350 procedure Check_Task_Prefix
;
351 -- Verify that prefix of attribute N is a task or task type
353 procedure Check_Type
;
354 -- Verify that the prefix of attribute N is a type
356 procedure Check_Unit_Name
(Nod
: Node_Id
);
357 -- Check that Nod is of the form of a library unit name, i.e that
358 -- it is an identifier, or a selected component whose prefix is
359 -- itself of the form of a library unit name. Note that this is
360 -- quite different from Check_Program_Unit, since it only checks
361 -- the syntactic form of the name, not the semantic identity. This
362 -- is because it is used with attributes (Elab_Body, Elab_Spec,
363 -- UET_Address and Elaborated) which can refer to non-visible unit.
365 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
366 pragma No_Return
(Error_Attr
);
367 procedure Error_Attr
;
368 pragma No_Return
(Error_Attr
);
369 -- Posts error using Error_Msg_N at given node, sets type of attribute
370 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
371 -- semantic processing. The message typically contains a % insertion
372 -- character which is replaced by the attribute name. The call with
373 -- no arguments is used when the caller has already generated the
374 -- required error messages.
376 procedure Error_Attr_P
(Msg
: String);
377 pragma No_Return
(Error_Attr
);
378 -- Like Error_Attr, but error is posted at the start of the prefix
380 procedure Standard_Attribute
(Val
: Int
);
381 -- Used to process attributes whose prefix is package Standard which
382 -- yield values of type Universal_Integer. The attribute reference
383 -- node is rewritten with an integer literal of the given value.
385 procedure Unexpected_Argument
(En
: Node_Id
);
386 -- Signal unexpected attribute argument (En is the argument)
388 procedure Validate_Non_Static_Attribute_Function_Call
;
389 -- Called when processing an attribute that is a function call to a
390 -- non-static function, i.e. an attribute function that either takes
391 -- non-scalar arguments or returns a non-scalar result. Verifies that
392 -- such a call does not appear in a preelaborable context.
394 ------------------------------
395 -- Analyze_Access_Attribute --
396 ------------------------------
398 procedure Analyze_Access_Attribute
is
399 Acc_Type
: Entity_Id
;
404 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
405 -- Build an access-to-object type whose designated type is DT,
406 -- and whose Ekind is appropriate to the attribute type. The
407 -- type that is constructed is returned as the result.
409 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
410 -- Build an access to subprogram whose designated type is the type of
411 -- the prefix. If prefix is overloaded, so is the node itself. The
412 -- result is stored in Acc_Type.
414 function OK_Self_Reference
return Boolean;
415 -- An access reference whose prefix is a type can legally appear
416 -- within an aggregate, where it is obtained by expansion of
417 -- a defaulted aggregate. The enclosing aggregate that contains
418 -- the self-referenced is flagged so that the self-reference can
419 -- be expanded into a reference to the target object (see exp_aggr).
421 ------------------------------
422 -- Build_Access_Object_Type --
423 ------------------------------
425 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
426 Typ
: constant Entity_Id
:=
428 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
430 Set_Etype
(Typ
, Typ
);
432 Set_Associated_Node_For_Itype
(Typ
, N
);
433 Set_Directly_Designated_Type
(Typ
, DT
);
435 end Build_Access_Object_Type
;
437 ----------------------------------
438 -- Build_Access_Subprogram_Type --
439 ----------------------------------
441 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
442 Index
: Interp_Index
;
445 procedure Check_Local_Access
(E
: Entity_Id
);
446 -- Deal with possible access to local subprogram. If we have such
447 -- an access, we set a flag to kill all tracked values on any call
448 -- because this access value may be passed around, and any called
449 -- code might use it to access a local procedure which clobbers a
450 -- tracked value. If the scope is a loop or block, indicate that
451 -- value tracking is disabled for the enclosing subprogram.
453 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
454 -- Distinguish between access to regular/protected subprograms
456 ------------------------
457 -- Check_Local_Access --
458 ------------------------
460 procedure Check_Local_Access
(E
: Entity_Id
) is
462 if not Is_Library_Level_Entity
(E
) then
463 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
464 Set_Suppress_Value_Tracking_On_Call
465 (Nearest_Dynamic_Scope
(Current_Scope
));
467 end Check_Local_Access
;
473 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
475 if Convention
(E
) = Convention_Protected
then
476 return E_Access_Protected_Subprogram_Type
;
478 return E_Access_Subprogram_Type
;
482 -- Start of processing for Build_Access_Subprogram_Type
485 -- In the case of an access to subprogram, use the name of the
486 -- subprogram itself as the designated type. Type-checking in
487 -- this case compares the signatures of the designated types.
489 -- Note: This fragment of the tree is temporarily malformed
490 -- because the correct tree requires an E_Subprogram_Type entity
491 -- as the designated type. In most cases this designated type is
492 -- later overridden by the semantics with the type imposed by the
493 -- context during the resolution phase. In the specific case of
494 -- the expression Address!(Prim'Unrestricted_Access), used to
495 -- initialize slots of dispatch tables, this work will be done by
496 -- the expander (see Exp_Aggr).
498 -- The reason to temporarily add this kind of node to the tree
499 -- instead of a proper E_Subprogram_Type itype, is the following:
500 -- in case of errors found in the source file we report better
501 -- error messages. For example, instead of generating the
504 -- "expected access to subprogram with profile
505 -- defined at line X"
507 -- we currently generate:
509 -- "expected access to function Z defined at line X"
511 Set_Etype
(N
, Any_Type
);
513 if not Is_Overloaded
(P
) then
514 Check_Local_Access
(Entity
(P
));
516 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
517 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
518 Set_Is_Public
(Acc_Type
, False);
519 Set_Etype
(Acc_Type
, Acc_Type
);
520 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
521 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
522 Set_Etype
(N
, Acc_Type
);
523 Freeze_Before
(N
, Acc_Type
);
527 Get_First_Interp
(P
, Index
, It
);
528 while Present
(It
.Nam
) loop
529 Check_Local_Access
(It
.Nam
);
531 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
532 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
533 Set_Is_Public
(Acc_Type
, False);
534 Set_Etype
(Acc_Type
, Acc_Type
);
535 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
536 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
537 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
538 Freeze_Before
(N
, Acc_Type
);
541 Get_Next_Interp
(Index
, It
);
545 -- Cannot be applied to intrinsic. Looking at the tests above,
546 -- the only way Etype (N) can still be set to Any_Type is if
547 -- Is_Intrinsic_Subprogram was True for some referenced entity.
549 if Etype
(N
) = Any_Type
then
550 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
552 end Build_Access_Subprogram_Type
;
554 ----------------------
555 -- OK_Self_Reference --
556 ----------------------
558 function OK_Self_Reference
return Boolean is
565 (Nkind
(Par
) = N_Component_Association
566 or else Nkind
(Par
) in N_Subexpr
)
568 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
569 if Etype
(Par
) = Typ
then
570 Set_Has_Self_Reference
(Par
);
578 -- No enclosing aggregate, or not a self-reference
581 end OK_Self_Reference
;
583 -- Start of processing for Analyze_Access_Attribute
586 Check_SPARK_Restriction_On_Attribute
;
589 if Nkind
(P
) = N_Character_Literal
then
591 ("prefix of % attribute cannot be enumeration literal");
594 -- Case of access to subprogram
596 if Is_Entity_Name
(P
)
597 and then Is_Overloadable
(Entity
(P
))
599 if Has_Pragma_Inline_Always
(Entity
(P
)) then
601 ("prefix of % attribute cannot be Inline_Always subprogram");
603 elsif Aname
= Name_Unchecked_Access
then
604 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
606 elsif Is_Ghost_Subprogram
(Entity
(P
)) then
608 ("prefix of % attribute cannot be a ghost subprogram");
611 -- Issue an error if the prefix denotes an eliminated subprogram
613 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
615 -- Check for obsolescent subprogram reference
617 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
619 -- Build the appropriate subprogram type
621 Build_Access_Subprogram_Type
(P
);
623 -- For P'Access or P'Unrestricted_Access, where P is a nested
624 -- subprogram, we might be passing P to another subprogram (but we
625 -- don't check that here), which might call P. P could modify
626 -- local variables, so we need to kill current values. It is
627 -- important not to do this for library-level subprograms, because
628 -- Kill_Current_Values is very inefficient in the case of library
629 -- level packages with lots of tagged types.
631 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
634 -- Do not kill values on nodes initializing dispatch tables
635 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
636 -- is currently generated by the expander only for this
637 -- purpose. Done to keep the quality of warnings currently
638 -- generated by the compiler (otherwise any declaration of
639 -- a tagged type cleans constant indications from its scope).
641 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
642 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
644 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
645 and then Is_Dispatching_Operation
646 (Directly_Designated_Type
(Etype
(N
)))
654 -- In the static elaboration model, treat the attribute reference
655 -- as a call for elaboration purposes. Suppress this treatment
656 -- under debug flag. In any case, we are all done.
658 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
664 -- Component is an operation of a protected type
666 elsif Nkind
(P
) = N_Selected_Component
667 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
669 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
670 Error_Attr_P
("prefix of % attribute must be subprogram");
673 Build_Access_Subprogram_Type
(Selector_Name
(P
));
677 -- Deal with incorrect reference to a type, but note that some
678 -- accesses are allowed: references to the current type instance,
679 -- or in Ada 2005 self-referential pointer in a default-initialized
682 if Is_Entity_Name
(P
) then
685 -- The reference may appear in an aggregate that has been expanded
686 -- into a loop. Locate scope of type definition, if any.
688 Scop
:= Current_Scope
;
689 while Ekind
(Scop
) = E_Loop
loop
690 Scop
:= Scope
(Scop
);
693 if Is_Type
(Typ
) then
695 -- OK if we are within the scope of a limited type
696 -- let's mark the component as having per object constraint
698 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
706 Q
: Node_Id
:= Parent
(N
);
710 and then Nkind
(Q
) /= N_Component_Declaration
716 Set_Has_Per_Object_Constraint
717 (Defining_Identifier
(Q
), True);
721 if Nkind
(P
) = N_Expanded_Name
then
723 ("current instance prefix must be a direct name", P
);
726 -- If a current instance attribute appears in a component
727 -- constraint it must appear alone; other contexts (spec-
728 -- expressions, within a task body) are not subject to this
731 if not In_Spec_Expression
732 and then not Has_Completion
(Scop
)
734 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
735 N_Index_Or_Discriminant_Constraint
)
738 ("current instance attribute must appear alone", N
);
741 if Is_CPP_Class
(Root_Type
(Typ
)) then
743 ("??current instance unsupported for derivations of "
744 & "'C'P'P types", N
);
747 -- OK if we are in initialization procedure for the type
748 -- in question, in which case the reference to the type
749 -- is rewritten as a reference to the current object.
751 elsif Ekind
(Scop
) = E_Procedure
752 and then Is_Init_Proc
(Scop
)
753 and then Etype
(First_Formal
(Scop
)) = Typ
756 Make_Attribute_Reference
(Loc
,
757 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
758 Attribute_Name
=> Name_Unrestricted_Access
));
762 -- OK if a task type, this test needs sharpening up ???
764 elsif Is_Task_Type
(Typ
) then
767 -- OK if self-reference in an aggregate in Ada 2005, and
768 -- the reference comes from a copied default expression.
770 -- Note that we check legality of self-reference even if the
771 -- expression comes from source, e.g. when a single component
772 -- association in an aggregate has a box association.
774 elsif Ada_Version
>= Ada_2005
775 and then OK_Self_Reference
779 -- OK if reference to current instance of a protected object
781 elsif Is_Protected_Self_Reference
(P
) then
784 -- Otherwise we have an error case
787 Error_Attr
("% attribute cannot be applied to type", P
);
793 -- If we fall through, we have a normal access to object case.
794 -- Unrestricted_Access is legal wherever an allocator would be
795 -- legal, so its Etype is set to E_Allocator. The expected type
796 -- of the other attributes is a general access type, and therefore
797 -- we label them with E_Access_Attribute_Type.
799 if not Is_Overloaded
(P
) then
800 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
801 Set_Etype
(N
, Acc_Type
);
804 Index
: Interp_Index
;
807 Set_Etype
(N
, Any_Type
);
808 Get_First_Interp
(P
, Index
, It
);
809 while Present
(It
.Typ
) loop
810 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
811 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
812 Get_Next_Interp
(Index
, It
);
817 -- Special cases when we can find a prefix that is an entity name
826 if Is_Entity_Name
(PP
) then
829 -- If we have an access to an object, and the attribute
830 -- comes from source, then set the object as potentially
831 -- source modified. We do this because the resulting access
832 -- pointer can be used to modify the variable, and we might
833 -- not detect this, leading to some junk warnings.
835 Set_Never_Set_In_Source
(Ent
, False);
837 -- Mark entity as address taken, and kill current values
839 Set_Address_Taken
(Ent
);
840 Kill_Current_Values
(Ent
);
843 elsif Nkind_In
(PP
, N_Selected_Component
,
854 -- Check for aliased view unless unrestricted case. We allow a
855 -- nonaliased prefix when within an instance because the prefix may
856 -- have been a tagged formal object, which is defined to be aliased
857 -- even when the actual might not be (other instance cases will have
858 -- been caught in the generic). Similarly, within an inlined body we
859 -- know that the attribute is legal in the original subprogram, and
860 -- therefore legal in the expansion.
862 if Aname
/= Name_Unrestricted_Access
863 and then not Is_Aliased_View
(P
)
864 and then not In_Instance
865 and then not In_Inlined_Body
867 Error_Attr_P
("prefix of % attribute must be aliased");
868 Check_No_Implicit_Aliasing
(P
);
870 end Analyze_Access_Attribute
;
872 ---------------------------------
873 -- Bad_Attribute_For_Predicate --
874 ---------------------------------
876 procedure Bad_Attribute_For_Predicate
is
878 if Is_Scalar_Type
(P_Type
)
879 and then Comes_From_Source
(N
)
881 Error_Msg_Name_1
:= Aname
;
882 Bad_Predicated_Subtype_Use
883 ("type& has predicates, attribute % not allowed", N
, P_Type
);
885 end Bad_Attribute_For_Predicate
;
887 ------------------------------
888 -- Check_Ada_2012_Attribute --
889 ------------------------------
891 procedure Check_Ada_2012_Attribute
is
893 if Ada_Version
< Ada_2012
then
894 Error_Msg_Name_1
:= Aname
;
896 ("attribute % is an Ada 2012 feature", N
);
898 ("\unit must be compiled with -gnat2012 switch", N
);
900 end Check_Ada_2012_Attribute
;
902 --------------------------------
903 -- Check_Array_Or_Scalar_Type --
904 --------------------------------
906 procedure Check_Array_Or_Scalar_Type
is
910 -- Dimension number for array attributes
913 -- Case of string literal or string literal subtype. These cases
914 -- cannot arise from legal Ada code, but the expander is allowed
915 -- to generate them. They require special handling because string
916 -- literal subtypes do not have standard bounds (the whole idea
917 -- of these subtypes is to avoid having to generate the bounds)
919 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
920 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
925 elsif Is_Scalar_Type
(P_Type
) then
929 Error_Attr
("invalid argument in % attribute", E1
);
931 Set_Etype
(N
, P_Base_Type
);
935 -- The following is a special test to allow 'First to apply to
936 -- private scalar types if the attribute comes from generated
937 -- code. This occurs in the case of Normalize_Scalars code.
939 elsif Is_Private_Type
(P_Type
)
940 and then Present
(Full_View
(P_Type
))
941 and then Is_Scalar_Type
(Full_View
(P_Type
))
942 and then not Comes_From_Source
(N
)
944 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
946 -- Array types other than string literal subtypes handled above
951 -- We know prefix is an array type, or the name of an array
952 -- object, and that the expression, if present, is static
953 -- and within the range of the dimensions of the type.
955 pragma Assert
(Is_Array_Type
(P_Type
));
956 Index
:= First_Index
(P_Base_Type
);
960 -- First dimension assumed
962 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
965 D
:= UI_To_Int
(Intval
(E1
));
967 for J
in 1 .. D
- 1 loop
971 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
972 Set_Etype
(E1
, Standard_Integer
);
975 end Check_Array_Or_Scalar_Type
;
977 ----------------------
978 -- Check_Array_Type --
979 ----------------------
981 procedure Check_Array_Type
is
983 -- Dimension number for array attributes
986 -- If the type is a string literal type, then this must be generated
987 -- internally, and no further check is required on its legality.
989 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
992 -- If the type is a composite, it is an illegal aggregate, no point
995 elsif P_Type
= Any_Composite
then
999 -- Normal case of array type or subtype
1001 Check_Either_E0_Or_E1
;
1004 if Is_Array_Type
(P_Type
) then
1005 if not Is_Constrained
(P_Type
)
1006 and then Is_Entity_Name
(P
)
1007 and then Is_Type
(Entity
(P
))
1009 -- Note: we do not call Error_Attr here, since we prefer to
1010 -- continue, using the relevant index type of the array,
1011 -- even though it is unconstrained. This gives better error
1012 -- recovery behavior.
1014 Error_Msg_Name_1
:= Aname
;
1016 ("prefix for % attribute must be constrained array", P
);
1019 -- The attribute reference freezes the type, and thus the
1020 -- component type, even if the attribute may not depend on the
1021 -- component. Diagnose arrays with incomplete components now.
1022 -- If the prefix is an access to array, this does not freeze
1023 -- the designated type.
1025 if Nkind
(P
) /= N_Explicit_Dereference
then
1026 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1029 D
:= Number_Dimensions
(P_Type
);
1032 if Is_Private_Type
(P_Type
) then
1033 Error_Attr_P
("prefix for % attribute may not be private type");
1035 elsif Is_Access_Type
(P_Type
)
1036 and then Is_Array_Type
(Designated_Type
(P_Type
))
1037 and then Is_Entity_Name
(P
)
1038 and then Is_Type
(Entity
(P
))
1040 Error_Attr_P
("prefix of % attribute cannot be access type");
1042 elsif Attr_Id
= Attribute_First
1044 Attr_Id
= Attribute_Last
1046 Error_Attr
("invalid prefix for % attribute", P
);
1049 Error_Attr_P
("prefix for % attribute must be array");
1053 if Present
(E1
) then
1054 Resolve
(E1
, Any_Integer
);
1055 Set_Etype
(E1
, Standard_Integer
);
1057 if not Is_Static_Expression
(E1
)
1058 or else Raises_Constraint_Error
(E1
)
1060 Flag_Non_Static_Expr
1061 ("expression for dimension must be static!", E1
);
1064 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1065 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1067 Error_Attr
("invalid dimension number for array type", E1
);
1071 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1072 and then Comes_From_Source
(N
)
1074 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1076 end Check_Array_Type
;
1078 -------------------------
1079 -- Check_Asm_Attribute --
1080 -------------------------
1082 procedure Check_Asm_Attribute
is
1087 -- Check first argument is static string expression
1089 Analyze_And_Resolve
(E1
, Standard_String
);
1091 if Etype
(E1
) = Any_Type
then
1094 elsif not Is_OK_Static_Expression
(E1
) then
1095 Flag_Non_Static_Expr
1096 ("constraint argument must be static string expression!", E1
);
1100 -- Check second argument is right type
1102 Analyze_And_Resolve
(E2
, Entity
(P
));
1104 -- Note: that is all we need to do, we don't need to check
1105 -- that it appears in a correct context. The Ada type system
1106 -- will do that for us.
1108 end Check_Asm_Attribute
;
1110 ---------------------
1111 -- Check_Component --
1112 ---------------------
1114 procedure Check_Component
is
1118 if Nkind
(P
) /= N_Selected_Component
1120 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1122 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1124 Error_Attr_P
("prefix for % attribute must be selected component");
1126 end Check_Component
;
1128 ------------------------------------
1129 -- Check_Decimal_Fixed_Point_Type --
1130 ------------------------------------
1132 procedure Check_Decimal_Fixed_Point_Type
is
1136 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1137 Error_Attr_P
("prefix of % attribute must be decimal type");
1139 end Check_Decimal_Fixed_Point_Type
;
1141 -----------------------
1142 -- Check_Dereference --
1143 -----------------------
1145 procedure Check_Dereference
is
1148 -- Case of a subtype mark
1150 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1154 -- Case of an expression
1158 if Is_Access_Type
(P_Type
) then
1160 -- If there is an implicit dereference, then we must freeze the
1161 -- designated type of the access type, since the type of the
1162 -- referenced array is this type (see AI95-00106).
1164 -- As done elsewhere, freezing must not happen when pre-analyzing
1165 -- a pre- or postcondition or a default value for an object or for
1166 -- a formal parameter.
1168 if not In_Spec_Expression
then
1169 Freeze_Before
(N
, Designated_Type
(P_Type
));
1173 Make_Explicit_Dereference
(Sloc
(P
),
1174 Prefix
=> Relocate_Node
(P
)));
1176 Analyze_And_Resolve
(P
);
1177 P_Type
:= Etype
(P
);
1179 if P_Type
= Any_Type
then
1180 raise Bad_Attribute
;
1183 P_Base_Type
:= Base_Type
(P_Type
);
1185 end Check_Dereference
;
1187 -------------------------
1188 -- Check_Discrete_Type --
1189 -------------------------
1191 procedure Check_Discrete_Type
is
1195 if not Is_Discrete_Type
(P_Type
) then
1196 Error_Attr_P
("prefix of % attribute must be discrete type");
1198 end Check_Discrete_Type
;
1204 procedure Check_E0
is
1206 if Present
(E1
) then
1207 Unexpected_Argument
(E1
);
1215 procedure Check_E1
is
1217 Check_Either_E0_Or_E1
;
1221 -- Special-case attributes that are functions and that appear as
1222 -- the prefix of another attribute. Error is posted on parent.
1224 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1225 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1229 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1230 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1231 Set_Etype
(Parent
(N
), Any_Type
);
1232 Set_Entity
(Parent
(N
), Any_Type
);
1233 raise Bad_Attribute
;
1236 Error_Attr
("missing argument for % attribute", N
);
1245 procedure Check_E2
is
1248 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1250 Error_Attr
("missing argument for % attribute (2 required)", N
);
1254 ---------------------------
1255 -- Check_Either_E0_Or_E1 --
1256 ---------------------------
1258 procedure Check_Either_E0_Or_E1
is
1260 if Present
(E2
) then
1261 Unexpected_Argument
(E2
);
1263 end Check_Either_E0_Or_E1
;
1265 ----------------------
1266 -- Check_Enum_Image --
1267 ----------------------
1269 procedure Check_Enum_Image
is
1273 -- When an enumeration type appears in an attribute reference, all
1274 -- literals of the type are marked as referenced. This must only be
1275 -- done if the attribute reference appears in the current source.
1276 -- Otherwise the information on references may differ between a
1277 -- normal compilation and one that performs inlining.
1279 if Is_Enumeration_Type
(P_Base_Type
)
1280 and then In_Extended_Main_Code_Unit
(N
)
1282 Lit
:= First_Literal
(P_Base_Type
);
1283 while Present
(Lit
) loop
1284 Set_Referenced
(Lit
);
1288 end Check_Enum_Image
;
1290 ----------------------------
1291 -- Check_First_Last_Valid --
1292 ----------------------------
1294 procedure Check_First_Last_Valid
is
1296 Check_Ada_2012_Attribute
;
1297 Check_Discrete_Type
;
1299 -- Freeze the subtype now, so that the following test for predicates
1300 -- works (we set the predicates stuff up at freeze time)
1302 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1304 -- Now test for dynamic predicate
1306 if Has_Predicates
(P_Type
)
1307 and then No
(Static_Predicate
(P_Type
))
1310 ("prefix of % attribute may not have dynamic predicate");
1313 -- Check non-static subtype
1315 if not Is_Static_Subtype
(P_Type
) then
1316 Error_Attr_P
("prefix of % attribute must be a static subtype");
1319 -- Test case for no values
1321 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1322 Expr_Value
(Type_High_Bound
(P_Type
))
1323 or else (Has_Predicates
(P_Type
)
1324 and then Is_Empty_List
(Static_Predicate
(P_Type
)))
1327 ("prefix of % attribute must be subtype with "
1328 & "at least one value");
1330 end Check_First_Last_Valid
;
1332 ----------------------------
1333 -- Check_Fixed_Point_Type --
1334 ----------------------------
1336 procedure Check_Fixed_Point_Type
is
1340 if not Is_Fixed_Point_Type
(P_Type
) then
1341 Error_Attr_P
("prefix of % attribute must be fixed point type");
1343 end Check_Fixed_Point_Type
;
1345 ------------------------------
1346 -- Check_Fixed_Point_Type_0 --
1347 ------------------------------
1349 procedure Check_Fixed_Point_Type_0
is
1351 Check_Fixed_Point_Type
;
1353 end Check_Fixed_Point_Type_0
;
1355 -------------------------------
1356 -- Check_Floating_Point_Type --
1357 -------------------------------
1359 procedure Check_Floating_Point_Type
is
1363 if not Is_Floating_Point_Type
(P_Type
) then
1364 Error_Attr_P
("prefix of % attribute must be float type");
1366 end Check_Floating_Point_Type
;
1368 ---------------------------------
1369 -- Check_Floating_Point_Type_0 --
1370 ---------------------------------
1372 procedure Check_Floating_Point_Type_0
is
1374 Check_Floating_Point_Type
;
1376 end Check_Floating_Point_Type_0
;
1378 ---------------------------------
1379 -- Check_Floating_Point_Type_1 --
1380 ---------------------------------
1382 procedure Check_Floating_Point_Type_1
is
1384 Check_Floating_Point_Type
;
1386 end Check_Floating_Point_Type_1
;
1388 ---------------------------------
1389 -- Check_Floating_Point_Type_2 --
1390 ---------------------------------
1392 procedure Check_Floating_Point_Type_2
is
1394 Check_Floating_Point_Type
;
1396 end Check_Floating_Point_Type_2
;
1398 ------------------------
1399 -- Check_Integer_Type --
1400 ------------------------
1402 procedure Check_Integer_Type
is
1406 if not Is_Integer_Type
(P_Type
) then
1407 Error_Attr_P
("prefix of % attribute must be integer type");
1409 end Check_Integer_Type
;
1411 --------------------------------
1412 -- Check_Modular_Integer_Type --
1413 --------------------------------
1415 procedure Check_Modular_Integer_Type
is
1419 if not Is_Modular_Integer_Type
(P_Type
) then
1421 ("prefix of % attribute must be modular integer type");
1423 end Check_Modular_Integer_Type
;
1425 ------------------------
1426 -- Check_Not_CPP_Type --
1427 ------------------------
1429 procedure Check_Not_CPP_Type
is
1431 if Is_Tagged_Type
(Etype
(P
))
1432 and then Convention
(Etype
(P
)) = Convention_CPP
1433 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1436 ("invalid use of % attribute with 'C'P'P tagged type");
1438 end Check_Not_CPP_Type
;
1440 -------------------------------
1441 -- Check_Not_Incomplete_Type --
1442 -------------------------------
1444 procedure Check_Not_Incomplete_Type
is
1449 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1450 -- dereference we have to check wrong uses of incomplete types
1451 -- (other wrong uses are checked at their freezing point).
1453 -- Example 1: Limited-with
1455 -- limited with Pkg;
1457 -- type Acc is access Pkg.T;
1459 -- S : Integer := X.all'Size; -- ERROR
1462 -- Example 2: Tagged incomplete
1464 -- type T is tagged;
1465 -- type Acc is access all T;
1467 -- S : constant Integer := X.all'Size; -- ERROR
1468 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1470 if Ada_Version
>= Ada_2005
1471 and then Nkind
(P
) = N_Explicit_Dereference
1474 while Nkind
(E
) = N_Explicit_Dereference
loop
1480 if From_With_Type
(Typ
) then
1482 ("prefix of % attribute cannot be an incomplete type");
1485 if Is_Access_Type
(Typ
) then
1486 Typ
:= Directly_Designated_Type
(Typ
);
1489 if Is_Class_Wide_Type
(Typ
) then
1490 Typ
:= Root_Type
(Typ
);
1493 -- A legal use of a shadow entity occurs only when the unit
1494 -- where the non-limited view resides is imported via a regular
1495 -- with clause in the current body. Such references to shadow
1496 -- entities may occur in subprogram formals.
1498 if Is_Incomplete_Type
(Typ
)
1499 and then From_With_Type
(Typ
)
1500 and then Present
(Non_Limited_View
(Typ
))
1501 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1503 Typ
:= Non_Limited_View
(Typ
);
1506 if Ekind
(Typ
) = E_Incomplete_Type
1507 and then No
(Full_View
(Typ
))
1510 ("prefix of % attribute cannot be an incomplete type");
1515 if not Is_Entity_Name
(P
)
1516 or else not Is_Type
(Entity
(P
))
1517 or else In_Spec_Expression
1521 Check_Fully_Declared
(P_Type
, P
);
1523 end Check_Not_Incomplete_Type
;
1525 ----------------------------
1526 -- Check_Object_Reference --
1527 ----------------------------
1529 procedure Check_Object_Reference
(P
: Node_Id
) is
1533 -- If we need an object, and we have a prefix that is the name of
1534 -- a function entity, convert it into a function call.
1536 if Is_Entity_Name
(P
)
1537 and then Ekind
(Entity
(P
)) = E_Function
1539 Rtyp
:= Etype
(Entity
(P
));
1542 Make_Function_Call
(Sloc
(P
),
1543 Name
=> Relocate_Node
(P
)));
1545 Analyze_And_Resolve
(P
, Rtyp
);
1547 -- Otherwise we must have an object reference
1549 elsif not Is_Object_Reference
(P
) then
1550 Error_Attr_P
("prefix of % attribute must be object");
1552 end Check_Object_Reference
;
1554 ----------------------------
1555 -- Check_PolyORB_Attribute --
1556 ----------------------------
1558 procedure Check_PolyORB_Attribute
is
1560 Validate_Non_Static_Attribute_Function_Call
;
1565 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1567 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1569 end Check_PolyORB_Attribute
;
1571 ------------------------
1572 -- Check_Program_Unit --
1573 ------------------------
1575 procedure Check_Program_Unit
is
1577 if Is_Entity_Name
(P
) then
1579 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1580 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1583 if K
in Subprogram_Kind
1584 or else K
in Task_Kind
1585 or else K
in Protected_Kind
1586 or else K
= E_Package
1587 or else K
in Generic_Unit_Kind
1588 or else (K
= E_Variable
1592 Is_Protected_Type
(T
)))
1599 Error_Attr_P
("prefix of % attribute must be program unit");
1600 end Check_Program_Unit
;
1602 ---------------------
1603 -- Check_Real_Type --
1604 ---------------------
1606 procedure Check_Real_Type
is
1610 if not Is_Real_Type
(P_Type
) then
1611 Error_Attr_P
("prefix of % attribute must be real type");
1613 end Check_Real_Type
;
1615 -----------------------
1616 -- Check_Scalar_Type --
1617 -----------------------
1619 procedure Check_Scalar_Type
is
1623 if not Is_Scalar_Type
(P_Type
) then
1624 Error_Attr_P
("prefix of % attribute must be scalar type");
1626 end Check_Scalar_Type
;
1628 ------------------------------------------
1629 -- Check_SPARK_Restriction_On_Attribute --
1630 ------------------------------------------
1632 procedure Check_SPARK_Restriction_On_Attribute
is
1634 Error_Msg_Name_1
:= Aname
;
1635 Check_SPARK_Restriction
("attribute % is not allowed", P
);
1636 end Check_SPARK_Restriction_On_Attribute
;
1638 ---------------------------
1639 -- Check_Standard_Prefix --
1640 ---------------------------
1642 procedure Check_Standard_Prefix
is
1646 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
1647 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1649 end Check_Standard_Prefix
;
1651 ----------------------------
1652 -- Check_Stream_Attribute --
1653 ----------------------------
1655 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1659 In_Shared_Var_Procs
: Boolean;
1660 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1661 -- For this runtime package (always compiled in GNAT mode), we allow
1662 -- stream attributes references for limited types for the case where
1663 -- shared passive objects are implemented using stream attributes,
1664 -- which is the default in GNAT's persistent storage implementation.
1667 Validate_Non_Static_Attribute_Function_Call
;
1669 -- With the exception of 'Input, Stream attributes are procedures,
1670 -- and can only appear at the position of procedure calls. We check
1671 -- for this here, before they are rewritten, to give a more precise
1674 if Nam
= TSS_Stream_Input
then
1677 elsif Is_List_Member
(N
)
1678 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1685 ("invalid context for attribute%, which is a procedure", N
);
1689 Btyp
:= Implementation_Base_Type
(P_Type
);
1691 -- Stream attributes not allowed on limited types unless the
1692 -- attribute reference was generated by the expander (in which
1693 -- case the underlying type will be used, as described in Sinfo),
1694 -- or the attribute was specified explicitly for the type itself
1695 -- or one of its ancestors (taking visibility rules into account if
1696 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1697 -- (with no visibility restriction).
1700 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1702 if Present
(Gen_Body
) then
1703 In_Shared_Var_Procs
:=
1704 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1706 In_Shared_Var_Procs
:= False;
1710 if (Comes_From_Source
(N
)
1711 and then not (In_Shared_Var_Procs
or In_Instance
))
1712 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1713 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1715 Error_Msg_Name_1
:= Aname
;
1717 if Is_Limited_Type
(P_Type
) then
1719 ("limited type& has no% attribute", P
, P_Type
);
1720 Explain_Limited_Type
(P_Type
, P
);
1723 ("attribute% for type& is not available", P
, P_Type
);
1727 -- Check restriction violations
1729 -- First check the No_Streams restriction, which prohibits the use
1730 -- of explicit stream attributes in the source program. We do not
1731 -- prevent the occurrence of stream attributes in generated code,
1732 -- for instance those generated implicitly for dispatching purposes.
1734 if Comes_From_Source
(N
) then
1735 Check_Restriction
(No_Streams
, P
);
1738 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1739 -- it is illegal to use a predefined elementary type stream attribute
1740 -- either by itself, or more importantly as part of the attribute
1741 -- subprogram for a composite type. However, if the broader
1742 -- restriction No_Streams is active, stream operations are not
1743 -- generated, and there is no error.
1745 if Restriction_Active
(No_Default_Stream_Attributes
)
1746 and then not Restriction_Active
(No_Streams
)
1752 if Nam
= TSS_Stream_Input
1754 Nam
= TSS_Stream_Read
1757 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1760 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1764 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1767 ("missing user-defined Stream Read or Write for type&",
1769 if not Is_Elementary_Type
(P_Type
) then
1771 ("\which is a component of type&", N
, P_Type
);
1777 -- Check special case of Exception_Id and Exception_Occurrence which
1778 -- are not allowed for restriction No_Exception_Registration.
1780 if Restriction_Check_Required
(No_Exception_Registration
)
1781 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1783 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1785 Check_Restriction
(No_Exception_Registration
, P
);
1788 -- Here we must check that the first argument is an access type
1789 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1791 Analyze_And_Resolve
(E1
);
1794 -- Note: the double call to Root_Type here is needed because the
1795 -- root type of a class-wide type is the corresponding type (e.g.
1796 -- X for X'Class, and we really want to go to the root.)
1798 if not Is_Access_Type
(Etyp
)
1799 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1800 RTE
(RE_Root_Stream_Type
)
1803 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1806 -- Check that the second argument is of the right type if there is
1807 -- one (the Input attribute has only one argument so this is skipped)
1809 if Present
(E2
) then
1812 if Nam
= TSS_Stream_Read
1813 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1816 ("second argument of % attribute must be a variable", E2
);
1819 Resolve
(E2
, P_Type
);
1823 end Check_Stream_Attribute
;
1825 -----------------------
1826 -- Check_Task_Prefix --
1827 -----------------------
1829 procedure Check_Task_Prefix
is
1833 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1834 -- task interface class-wide types.
1836 if Is_Task_Type
(Etype
(P
))
1837 or else (Is_Access_Type
(Etype
(P
))
1838 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1839 or else (Ada_Version
>= Ada_2005
1840 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1841 and then Is_Interface
(Etype
(P
))
1842 and then Is_Task_Interface
(Etype
(P
)))
1847 if Ada_Version
>= Ada_2005
then
1849 ("prefix of % attribute must be a task or a task " &
1850 "interface class-wide object");
1853 Error_Attr_P
("prefix of % attribute must be a task");
1856 end Check_Task_Prefix
;
1862 -- The possibilities are an entity name denoting a type, or an
1863 -- attribute reference that denotes a type (Base or Class). If
1864 -- the type is incomplete, replace it with its full view.
1866 procedure Check_Type
is
1868 if not Is_Entity_Name
(P
)
1869 or else not Is_Type
(Entity
(P
))
1871 Error_Attr_P
("prefix of % attribute must be a type");
1873 elsif Is_Protected_Self_Reference
(P
) then
1875 ("prefix of % attribute denotes current instance "
1876 & "(RM 9.4(21/2))");
1878 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1879 and then Present
(Full_View
(Entity
(P
)))
1881 P_Type
:= Full_View
(Entity
(P
));
1882 Set_Entity
(P
, P_Type
);
1886 ---------------------
1887 -- Check_Unit_Name --
1888 ---------------------
1890 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1892 if Nkind
(Nod
) = N_Identifier
then
1895 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
1896 Check_Unit_Name
(Prefix
(Nod
));
1898 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1903 Error_Attr
("argument for % attribute must be unit name", P
);
1904 end Check_Unit_Name
;
1910 procedure Error_Attr
is
1912 Set_Etype
(N
, Any_Type
);
1913 Set_Entity
(N
, Any_Type
);
1914 raise Bad_Attribute
;
1917 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1919 Error_Msg_Name_1
:= Aname
;
1920 Error_Msg_N
(Msg
, Error_Node
);
1928 procedure Error_Attr_P
(Msg
: String) is
1930 Error_Msg_Name_1
:= Aname
;
1931 Error_Msg_F
(Msg
, P
);
1935 ----------------------------
1936 -- Legal_Formal_Attribute --
1937 ----------------------------
1939 procedure Legal_Formal_Attribute
is
1943 if not Is_Entity_Name
(P
)
1944 or else not Is_Type
(Entity
(P
))
1946 Error_Attr_P
("prefix of % attribute must be generic type");
1948 elsif Is_Generic_Actual_Type
(Entity
(P
))
1950 or else In_Inlined_Body
1954 elsif Is_Generic_Type
(Entity
(P
)) then
1955 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1957 ("prefix of % attribute must be indefinite generic type");
1962 ("prefix of % attribute must be indefinite generic type");
1965 Set_Etype
(N
, Standard_Boolean
);
1966 end Legal_Formal_Attribute
;
1968 ------------------------
1969 -- Standard_Attribute --
1970 ------------------------
1972 procedure Standard_Attribute
(Val
: Int
) is
1974 Check_Standard_Prefix
;
1975 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1977 end Standard_Attribute
;
1979 -------------------------
1980 -- Unexpected Argument --
1981 -------------------------
1983 procedure Unexpected_Argument
(En
: Node_Id
) is
1985 Error_Attr
("unexpected argument for % attribute", En
);
1986 end Unexpected_Argument
;
1988 -------------------------------------------------
1989 -- Validate_Non_Static_Attribute_Function_Call --
1990 -------------------------------------------------
1992 -- This function should be moved to Sem_Dist ???
1994 procedure Validate_Non_Static_Attribute_Function_Call
is
1996 if In_Preelaborated_Unit
1997 and then not In_Subprogram_Or_Concurrent_Unit
1999 Flag_Non_Static_Expr
2000 ("non-static function call in preelaborated unit!", N
);
2002 end Validate_Non_Static_Attribute_Function_Call
;
2004 -- Start of processing for Analyze_Attribute
2007 -- Immediate return if unrecognized attribute (already diagnosed
2008 -- by parser, so there is nothing more that we need to do)
2010 if not Is_Attribute_Name
(Aname
) then
2011 raise Bad_Attribute
;
2014 -- Deal with Ada 83 issues
2016 if Comes_From_Source
(N
) then
2017 if not Attribute_83
(Attr_Id
) then
2018 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2019 Error_Msg_Name_1
:= Aname
;
2020 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2023 if Attribute_Impl_Def
(Attr_Id
) then
2024 Check_Restriction
(No_Implementation_Attributes
, N
);
2029 -- Deal with Ada 2005 attributes that are
2031 if Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
then
2032 Check_Restriction
(No_Implementation_Attributes
, N
);
2035 -- Remote access to subprogram type access attribute reference needs
2036 -- unanalyzed copy for tree transformation. The analyzed copy is used
2037 -- for its semantic information (whether prefix is a remote subprogram
2038 -- name), the unanalyzed copy is used to construct new subtree rooted
2039 -- with N_Aggregate which represents a fat pointer aggregate.
2041 if Aname
= Name_Access
then
2042 Discard_Node
(Copy_Separate_Tree
(N
));
2045 -- Analyze prefix and exit if error in analysis. If the prefix is an
2046 -- incomplete type, use full view if available. Note that there are
2047 -- some attributes for which we do not analyze the prefix, since the
2048 -- prefix is not a normal name, or else needs special handling.
2050 if Aname
/= Name_Elab_Body
and then
2051 Aname
/= Name_Elab_Spec
and then
2052 Aname
/= Name_Elab_Subp_Body
and then
2053 Aname
/= Name_UET_Address
and then
2054 Aname
/= Name_Enabled
and then
2058 P_Type
:= Etype
(P
);
2060 if Is_Entity_Name
(P
)
2061 and then Present
(Entity
(P
))
2062 and then Is_Type
(Entity
(P
))
2064 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2065 P_Type
:= Get_Full_View
(P_Type
);
2066 Set_Entity
(P
, P_Type
);
2067 Set_Etype
(P
, P_Type
);
2069 elsif Entity
(P
) = Current_Scope
2070 and then Is_Record_Type
(Entity
(P
))
2072 -- Use of current instance within the type. Verify that if the
2073 -- attribute appears within a constraint, it yields an access
2074 -- type, other uses are illegal.
2082 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2084 Par
:= Parent
(Par
);
2088 and then Nkind
(Par
) = N_Subtype_Indication
2090 if Attr_Id
/= Attribute_Access
2091 and then Attr_Id
/= Attribute_Unchecked_Access
2092 and then Attr_Id
/= Attribute_Unrestricted_Access
2095 ("in a constraint the current instance can only"
2096 & " be used with an access attribute", N
);
2103 if P_Type
= Any_Type
then
2104 raise Bad_Attribute
;
2107 P_Base_Type
:= Base_Type
(P_Type
);
2110 -- Analyze expressions that may be present, exiting if an error occurs
2117 E1
:= First
(Exprs
);
2119 -- Skip analysis for case of Restriction_Set, we do not expect
2120 -- the argument to be analyzed in this case.
2122 if Aname
/= Name_Restriction_Set
then
2125 -- Check for missing/bad expression (result of previous error)
2127 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2128 raise Bad_Attribute
;
2134 if Present
(E2
) then
2137 if Etype
(E2
) = Any_Type
then
2138 raise Bad_Attribute
;
2141 if Present
(Next
(E2
)) then
2142 Unexpected_Argument
(Next
(E2
));
2147 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
2148 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
2150 if Ada_Version
< Ada_2005
2151 and then Is_Overloaded
(P
)
2152 and then Aname
/= Name_Access
2153 and then Aname
/= Name_Address
2154 and then Aname
/= Name_Code_Address
2155 and then Aname
/= Name_Count
2156 and then Aname
/= Name_Result
2157 and then Aname
/= Name_Unchecked_Access
2159 Error_Attr
("ambiguous prefix for % attribute", P
);
2161 elsif Ada_Version
>= Ada_2005
2162 and then Is_Overloaded
(P
)
2163 and then Aname
/= Name_Access
2164 and then Aname
/= Name_Address
2165 and then Aname
/= Name_Code_Address
2166 and then Aname
/= Name_Result
2167 and then Aname
/= Name_Unchecked_Access
2169 -- Ada 2005 (AI-345): Since protected and task types have primitive
2170 -- entry wrappers, the attributes Count, Caller and AST_Entry require
2173 if Ada_Version
>= Ada_2005
2174 and then Nam_In
(Aname
, Name_Count
, Name_Caller
, Name_AST_Entry
)
2177 Count
: Natural := 0;
2182 Get_First_Interp
(P
, I
, It
);
2183 while Present
(It
.Nam
) loop
2184 if Comes_From_Source
(It
.Nam
) then
2190 Get_Next_Interp
(I
, It
);
2194 Error_Attr
("ambiguous prefix for % attribute", P
);
2196 Set_Is_Overloaded
(P
, False);
2201 Error_Attr
("ambiguous prefix for % attribute", P
);
2205 -- In SPARK, attributes of private types are only allowed if the full
2206 -- type declaration is visible.
2208 if Is_Entity_Name
(P
)
2209 and then Present
(Entity
(P
)) -- needed in some cases
2210 and then Is_Type
(Entity
(P
))
2211 and then Is_Private_Type
(P_Type
)
2212 and then not In_Open_Scopes
(Scope
(P_Type
))
2213 and then not In_Spec_Expression
2215 Check_SPARK_Restriction
("invisible attribute of type", N
);
2218 -- Remaining processing depends on attribute
2222 -- Attributes related to Ada 2012 iterators. Attribute specifications
2223 -- exist for these, but they cannot be queried.
2225 when Attribute_Constant_Indexing |
2226 Attribute_Default_Iterator |
2227 Attribute_Implicit_Dereference |
2228 Attribute_Iterator_Element |
2229 Attribute_Variable_Indexing
=>
2230 Error_Msg_N
("illegal attribute", N
);
2232 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2233 -- were already rejected by the parser. Thus they shouldn't appear here.
2235 when Internal_Attribute_Id
=>
2236 raise Program_Error
;
2242 when Attribute_Abort_Signal
=>
2243 Check_Standard_Prefix
;
2244 Rewrite
(N
, New_Reference_To
(Stand
.Abort_Signal
, Loc
));
2251 when Attribute_Access
=>
2252 Analyze_Access_Attribute
;
2258 when Attribute_Address
=>
2261 -- Check for some junk cases, where we have to allow the address
2262 -- attribute but it does not make much sense, so at least for now
2263 -- just replace with Null_Address.
2265 -- We also do this if the prefix is a reference to the AST_Entry
2266 -- attribute. If expansion is active, the attribute will be
2267 -- replaced by a function call, and address will work fine and
2268 -- get the proper value, but if expansion is not active, then
2269 -- the check here allows proper semantic analysis of the reference.
2271 -- An Address attribute created by expansion is legal even when it
2272 -- applies to other entity-denoting expressions.
2274 if Is_Protected_Self_Reference
(P
) then
2276 -- Address attribute on a protected object self reference is legal
2280 elsif Is_Entity_Name
(P
) then
2282 Ent
: constant Entity_Id
:= Entity
(P
);
2285 if Is_Subprogram
(Ent
) then
2286 Set_Address_Taken
(Ent
);
2287 Kill_Current_Values
(Ent
);
2289 -- An Address attribute is accepted when generated by the
2290 -- compiler for dispatching operation, and an error is
2291 -- issued once the subprogram is frozen (to avoid confusing
2292 -- errors about implicit uses of Address in the dispatch
2293 -- table initialization).
2295 if Has_Pragma_Inline_Always
(Entity
(P
))
2296 and then Comes_From_Source
(P
)
2299 ("prefix of % attribute cannot be Inline_Always" &
2302 -- It is illegal to apply 'Address to an intrinsic
2303 -- subprogram. This is now formalized in AI05-0095.
2304 -- In an instance, an attempt to obtain 'Address of an
2305 -- intrinsic subprogram (e.g the renaming of a predefined
2306 -- operator that is an actual) raises Program_Error.
2308 elsif Convention
(Ent
) = Convention_Intrinsic
then
2311 Make_Raise_Program_Error
(Loc
,
2312 Reason
=> PE_Address_Of_Intrinsic
));
2316 ("cannot take Address of intrinsic subprogram", N
);
2319 -- Issue an error if prefix denotes an eliminated subprogram
2322 Check_For_Eliminated_Subprogram
(P
, Ent
);
2325 elsif Is_Object
(Ent
)
2326 or else Ekind
(Ent
) = E_Label
2328 Set_Address_Taken
(Ent
);
2330 -- Deal with No_Implicit_Aliasing restriction
2332 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
2333 if not Is_Aliased_View
(P
) then
2334 Check_Restriction
(No_Implicit_Aliasing
, P
);
2336 Check_No_Implicit_Aliasing
(P
);
2340 -- If we have an address of an object, and the attribute
2341 -- comes from source, then set the object as potentially
2342 -- source modified. We do this because the resulting address
2343 -- can potentially be used to modify the variable and we
2344 -- might not detect this, leading to some junk warnings.
2346 Set_Never_Set_In_Source
(Ent
, False);
2348 elsif (Is_Concurrent_Type
(Etype
(Ent
))
2349 and then Etype
(Ent
) = Base_Type
(Ent
))
2350 or else Ekind
(Ent
) = E_Package
2351 or else Is_Generic_Unit
(Ent
)
2354 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2357 Error_Attr
("invalid prefix for % attribute", P
);
2361 elsif Nkind
(P
) = N_Attribute_Reference
2362 and then Attribute_Name
(P
) = Name_AST_Entry
2365 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2367 elsif Is_Object_Reference
(P
) then
2370 elsif Nkind
(P
) = N_Selected_Component
2371 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
2375 -- What exactly are we allowing here ??? and is this properly
2376 -- documented in the sinfo documentation for this node ???
2378 elsif not Comes_From_Source
(N
) then
2381 elsif Relaxed_RM_Semantics
2382 and then Nkind
(P
) = N_Attribute_Reference
2387 Error_Attr
("invalid prefix for % attribute", P
);
2390 Set_Etype
(N
, RTE
(RE_Address
));
2396 when Attribute_Address_Size
=>
2397 Standard_Attribute
(System_Address_Size
);
2403 when Attribute_Adjacent
=>
2404 Check_Floating_Point_Type_2
;
2405 Set_Etype
(N
, P_Base_Type
);
2406 Resolve
(E1
, P_Base_Type
);
2407 Resolve
(E2
, P_Base_Type
);
2413 when Attribute_Aft
=>
2414 Check_Fixed_Point_Type_0
;
2415 Set_Etype
(N
, Universal_Integer
);
2421 when Attribute_Alignment
=>
2423 -- Don't we need more checking here, cf Size ???
2426 Check_Not_Incomplete_Type
;
2428 Set_Etype
(N
, Universal_Integer
);
2434 when Attribute_Asm_Input
=>
2435 Check_Asm_Attribute
;
2437 -- The back-end may need to take the address of E2
2439 if Is_Entity_Name
(E2
) then
2440 Set_Address_Taken
(Entity
(E2
));
2443 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2449 when Attribute_Asm_Output
=>
2450 Check_Asm_Attribute
;
2452 if Etype
(E2
) = Any_Type
then
2455 elsif Aname
= Name_Asm_Output
then
2456 if not Is_Variable
(E2
) then
2458 ("second argument for Asm_Output is not variable", E2
);
2462 Note_Possible_Modification
(E2
, Sure
=> True);
2464 -- The back-end may need to take the address of E2
2466 if Is_Entity_Name
(E2
) then
2467 Set_Address_Taken
(Entity
(E2
));
2470 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2476 when Attribute_AST_Entry
=> AST_Entry
: declare
2482 -- Indicates if entry family index is present. Note the coding
2483 -- here handles the entry family case, but in fact it cannot be
2484 -- executed currently, because pragma AST_Entry does not permit
2485 -- the specification of an entry family.
2487 procedure Bad_AST_Entry
;
2488 -- Signal a bad AST_Entry pragma
2490 function OK_Entry
(E
: Entity_Id
) return Boolean;
2491 -- Checks that E is of an appropriate entity kind for an entry
2492 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2493 -- is set True for the entry family case). In the True case,
2494 -- makes sure that Is_AST_Entry is set on the entry.
2500 procedure Bad_AST_Entry
is
2502 Error_Attr_P
("prefix for % attribute must be task entry");
2509 function OK_Entry
(E
: Entity_Id
) return Boolean is
2514 Result
:= (Ekind
(E
) = E_Entry_Family
);
2516 Result
:= (Ekind
(E
) = E_Entry
);
2520 if not Is_AST_Entry
(E
) then
2521 Error_Msg_Name_2
:= Aname
;
2522 Error_Attr
("% attribute requires previous % pragma", P
);
2529 -- Start of processing for AST_Entry
2535 -- Deal with entry family case
2537 if Nkind
(P
) = N_Indexed_Component
then
2545 Ptyp
:= Etype
(Pref
);
2547 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2551 -- If the prefix is a selected component whose prefix is of an
2552 -- access type, then introduce an explicit dereference.
2553 -- ??? Could we reuse Check_Dereference here?
2555 if Nkind
(Pref
) = N_Selected_Component
2556 and then Is_Access_Type
(Ptyp
)
2559 Make_Explicit_Dereference
(Sloc
(Pref
),
2560 Relocate_Node
(Pref
)));
2561 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2564 -- Prefix can be of the form a.b, where a is a task object
2565 -- and b is one of the entries of the corresponding task type.
2567 if Nkind
(Pref
) = N_Selected_Component
2568 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2569 and then Is_Object_Reference
(Prefix
(Pref
))
2570 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2574 -- Otherwise the prefix must be an entry of a containing task,
2575 -- or of a variable of the enclosing task type.
2578 if Nkind_In
(Pref
, N_Identifier
, N_Expanded_Name
) then
2579 Ent
:= Entity
(Pref
);
2581 if not OK_Entry
(Ent
)
2582 or else not In_Open_Scopes
(Scope
(Ent
))
2592 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2595 -----------------------------
2596 -- Atomic_Always_Lock_Free --
2597 -----------------------------
2599 when Attribute_Atomic_Always_Lock_Free
=>
2602 Set_Etype
(N
, Standard_Boolean
);
2608 -- Note: when the base attribute appears in the context of a subtype
2609 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2610 -- the following circuit.
2612 when Attribute_Base
=> Base
: declare
2620 if Ada_Version
>= Ada_95
2621 and then not Is_Scalar_Type
(Typ
)
2622 and then not Is_Generic_Type
(Typ
)
2624 Error_Attr_P
("prefix of Base attribute must be scalar type");
2626 elsif Sloc
(Typ
) = Standard_Location
2627 and then Base_Type
(Typ
) = Typ
2628 and then Warn_On_Redundant_Constructs
2630 Error_Msg_NE
-- CODEFIX
2631 ("?r?redundant attribute, & is its own base type", N
, Typ
);
2634 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2635 Error_Msg_Name_1
:= Aname
;
2636 Check_SPARK_Restriction
2637 ("attribute% is only allowed as prefix of another attribute", P
);
2640 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2641 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2642 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2650 when Attribute_Bit
=> Bit
:
2654 if not Is_Object_Reference
(P
) then
2655 Error_Attr_P
("prefix for % attribute must be object");
2657 -- What about the access object cases ???
2663 Set_Etype
(N
, Universal_Integer
);
2670 when Attribute_Bit_Order
=> Bit_Order
:
2675 if not Is_Record_Type
(P_Type
) then
2676 Error_Attr_P
("prefix of % attribute must be record type");
2679 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2681 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2684 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2687 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2690 -- Reset incorrect indication of staticness
2692 Set_Is_Static_Expression
(N
, False);
2699 -- Note: in generated code, we can have a Bit_Position attribute
2700 -- applied to a (naked) record component (i.e. the prefix is an
2701 -- identifier that references an E_Component or E_Discriminant
2702 -- entity directly, and this is interpreted as expected by Gigi.
2703 -- The following code will not tolerate such usage, but when the
2704 -- expander creates this special case, it marks it as analyzed
2705 -- immediately and sets an appropriate type.
2707 when Attribute_Bit_Position
=>
2708 if Comes_From_Source
(N
) then
2712 Set_Etype
(N
, Universal_Integer
);
2718 when Attribute_Body_Version
=>
2721 Set_Etype
(N
, RTE
(RE_Version_String
));
2727 when Attribute_Callable
=>
2729 Set_Etype
(N
, Standard_Boolean
);
2736 when Attribute_Caller
=> Caller
: declare
2743 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2746 if not Is_Entry
(Ent
) then
2747 Error_Attr
("invalid entry name", N
);
2751 Error_Attr
("invalid entry name", N
);
2755 for J
in reverse 0 .. Scope_Stack
.Last
loop
2756 S
:= Scope_Stack
.Table
(J
).Entity
;
2758 if S
= Scope
(Ent
) then
2759 Error_Attr
("Caller must appear in matching accept or body", N
);
2765 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2772 when Attribute_Ceiling
=>
2773 Check_Floating_Point_Type_1
;
2774 Set_Etype
(N
, P_Base_Type
);
2775 Resolve
(E1
, P_Base_Type
);
2781 when Attribute_Class
=>
2782 Check_Restriction
(No_Dispatch
, N
);
2786 -- Applying Class to untagged incomplete type is obsolescent in Ada
2787 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2788 -- this flag gets set by Find_Type in this situation.
2790 if Restriction_Check_Required
(No_Obsolescent_Features
)
2791 and then Ada_Version
>= Ada_2005
2792 and then Ekind
(P_Type
) = E_Incomplete_Type
2795 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2797 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2798 and then not Tagged_Present
(DN
)
2800 Check_Restriction
(No_Obsolescent_Features
, P
);
2809 when Attribute_Code_Address
=>
2812 if Nkind
(P
) = N_Attribute_Reference
2813 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
2817 elsif not Is_Entity_Name
(P
)
2818 or else (Ekind
(Entity
(P
)) /= E_Function
2820 Ekind
(Entity
(P
)) /= E_Procedure
)
2822 Error_Attr
("invalid prefix for % attribute", P
);
2823 Set_Address_Taken
(Entity
(P
));
2825 -- Issue an error if the prefix denotes an eliminated subprogram
2828 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2831 Set_Etype
(N
, RTE
(RE_Address
));
2833 ----------------------
2834 -- Compiler_Version --
2835 ----------------------
2837 when Attribute_Compiler_Version
=>
2839 Check_Standard_Prefix
;
2840 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2841 Analyze_And_Resolve
(N
, Standard_String
);
2843 --------------------
2844 -- Component_Size --
2845 --------------------
2847 when Attribute_Component_Size
=>
2849 Set_Etype
(N
, Universal_Integer
);
2851 -- Note: unlike other array attributes, unconstrained arrays are OK
2853 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2863 when Attribute_Compose
=>
2864 Check_Floating_Point_Type_2
;
2865 Set_Etype
(N
, P_Base_Type
);
2866 Resolve
(E1
, P_Base_Type
);
2867 Resolve
(E2
, Any_Integer
);
2873 when Attribute_Constrained
=>
2875 Set_Etype
(N
, Standard_Boolean
);
2877 -- Case from RM J.4(2) of constrained applied to private type
2879 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2880 Check_Restriction
(No_Obsolescent_Features
, P
);
2882 if Warn_On_Obsolescent_Feature
then
2884 ("constrained for private type is an " &
2885 "obsolescent feature (RM J.4)?j?", N
);
2888 -- If we are within an instance, the attribute must be legal
2889 -- because it was valid in the generic unit. Ditto if this is
2890 -- an inlining of a function declared in an instance.
2893 or else In_Inlined_Body
2897 -- For sure OK if we have a real private type itself, but must
2898 -- be completed, cannot apply Constrained to incomplete type.
2900 elsif Is_Private_Type
(Entity
(P
)) then
2902 -- Note: this is one of the Annex J features that does not
2903 -- generate a warning from -gnatwj, since in fact it seems
2904 -- very useful, and is used in the GNAT runtime.
2906 Check_Not_Incomplete_Type
;
2910 -- Normal (non-obsolescent case) of application to object of
2911 -- a discriminated type.
2914 Check_Object_Reference
(P
);
2916 -- If N does not come from source, then we allow the
2917 -- the attribute prefix to be of a private type whose
2918 -- full type has discriminants. This occurs in cases
2919 -- involving expanded calls to stream attributes.
2921 if not Comes_From_Source
(N
) then
2922 P_Type
:= Underlying_Type
(P_Type
);
2925 -- Must have discriminants or be an access type designating
2926 -- a type with discriminants. If it is a classwide type is ???
2927 -- has unknown discriminants.
2929 if Has_Discriminants
(P_Type
)
2930 or else Has_Unknown_Discriminants
(P_Type
)
2932 (Is_Access_Type
(P_Type
)
2933 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2937 -- Also allow an object of a generic type if extensions allowed
2938 -- and allow this for any type at all.
2940 elsif (Is_Generic_Type
(P_Type
)
2941 or else Is_Generic_Actual_Type
(P_Type
))
2942 and then Extensions_Allowed
2948 -- Fall through if bad prefix
2951 ("prefix of % attribute must be object of discriminated type");
2957 when Attribute_Copy_Sign
=>
2958 Check_Floating_Point_Type_2
;
2959 Set_Etype
(N
, P_Base_Type
);
2960 Resolve
(E1
, P_Base_Type
);
2961 Resolve
(E2
, P_Base_Type
);
2967 when Attribute_Count
=> Count
:
2976 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2979 if Ekind
(Ent
) /= E_Entry
then
2980 Error_Attr
("invalid entry name", N
);
2983 elsif Nkind
(P
) = N_Indexed_Component
then
2984 if not Is_Entity_Name
(Prefix
(P
))
2985 or else No
(Entity
(Prefix
(P
)))
2986 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2988 if Nkind
(Prefix
(P
)) = N_Selected_Component
2989 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2990 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2994 ("attribute % must apply to entry of current task", P
);
2997 Error_Attr
("invalid entry family name", P
);
3002 Ent
:= Entity
(Prefix
(P
));
3005 elsif Nkind
(P
) = N_Selected_Component
3006 and then Present
(Entity
(Selector_Name
(P
)))
3007 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3010 ("attribute % must apply to entry of current task", P
);
3013 Error_Attr
("invalid entry name", N
);
3017 for J
in reverse 0 .. Scope_Stack
.Last
loop
3018 S
:= Scope_Stack
.Table
(J
).Entity
;
3020 if S
= Scope
(Ent
) then
3021 if Nkind
(P
) = N_Expanded_Name
then
3022 Tsk
:= Entity
(Prefix
(P
));
3024 -- The prefix denotes either the task type, or else a
3025 -- single task whose task type is being analyzed.
3030 or else (not Is_Type
(Tsk
)
3031 and then Etype
(Tsk
) = S
3032 and then not (Comes_From_Source
(S
)))
3037 ("Attribute % must apply to entry of current task", N
);
3043 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3045 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3047 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3049 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3050 and then not Has_Completion
(Scope
(Ent
))
3052 Error_Attr
("attribute % can only be used inside body", N
);
3056 if Is_Overloaded
(P
) then
3058 Index
: Interp_Index
;
3062 Get_First_Interp
(P
, Index
, It
);
3064 while Present
(It
.Nam
) loop
3065 if It
.Nam
= Ent
then
3068 -- Ada 2005 (AI-345): Do not consider primitive entry
3069 -- wrappers generated for task or protected types.
3071 elsif Ada_Version
>= Ada_2005
3072 and then not Comes_From_Source
(It
.Nam
)
3077 Error_Attr
("ambiguous entry name", N
);
3080 Get_Next_Interp
(Index
, It
);
3085 Set_Etype
(N
, Universal_Integer
);
3088 -----------------------
3089 -- Default_Bit_Order --
3090 -----------------------
3092 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
3094 Check_Standard_Prefix
;
3096 if Bytes_Big_Endian
then
3098 Make_Integer_Literal
(Loc
, False_Value
));
3101 Make_Integer_Literal
(Loc
, True_Value
));
3104 Set_Etype
(N
, Universal_Integer
);
3105 Set_Is_Static_Expression
(N
);
3106 end Default_Bit_Order
;
3112 when Attribute_Definite
=>
3113 Legal_Formal_Attribute
;
3119 when Attribute_Delta
=>
3120 Check_Fixed_Point_Type_0
;
3121 Set_Etype
(N
, Universal_Real
);
3127 when Attribute_Denorm
=>
3128 Check_Floating_Point_Type_0
;
3129 Set_Etype
(N
, Standard_Boolean
);
3131 ---------------------
3132 -- Descriptor_Size --
3133 ---------------------
3135 when Attribute_Descriptor_Size
=>
3138 if not Is_Entity_Name
(P
)
3139 or else not Is_Type
(Entity
(P
))
3141 Error_Attr_P
("prefix of attribute % must denote a type");
3144 Set_Etype
(N
, Universal_Integer
);
3150 when Attribute_Digits
=>
3154 if not Is_Floating_Point_Type
(P_Type
)
3155 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3158 ("prefix of % attribute must be float or decimal type");
3161 Set_Etype
(N
, Universal_Integer
);
3167 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3169 when Attribute_Elab_Body |
3170 Attribute_Elab_Spec |
3171 Attribute_Elab_Subp_Body
=>
3174 Check_Unit_Name
(P
);
3175 Set_Etype
(N
, Standard_Void_Type
);
3177 -- We have to manually call the expander in this case to get
3178 -- the necessary expansion (normally attributes that return
3179 -- entities are not expanded).
3187 -- Shares processing with Elab_Body
3193 when Attribute_Elaborated
=>
3195 Check_Unit_Name
(P
);
3196 Set_Etype
(N
, Standard_Boolean
);
3202 when Attribute_Emax
=>
3203 Check_Floating_Point_Type_0
;
3204 Set_Etype
(N
, Universal_Integer
);
3210 when Attribute_Enabled
=>
3211 Check_Either_E0_Or_E1
;
3213 if Present
(E1
) then
3214 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3215 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3220 if Nkind
(P
) /= N_Identifier
then
3221 Error_Msg_N
("identifier expected (check name)", P
);
3222 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3223 Error_Msg_N
("& is not a recognized check name", P
);
3226 Set_Etype
(N
, Standard_Boolean
);
3232 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3234 if Present
(E1
) then
3236 Check_Discrete_Type
;
3237 Resolve
(E1
, P_Base_Type
);
3240 if not Is_Entity_Name
(P
)
3241 or else (not Is_Object
(Entity
(P
))
3243 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3246 ("prefix of % attribute must be " &
3247 "discrete type/object or enum literal");
3251 Set_Etype
(N
, Universal_Integer
);
3258 when Attribute_Enum_Val
=> Enum_Val
: begin
3262 if not Is_Enumeration_Type
(P_Type
) then
3263 Error_Attr_P
("prefix of % attribute must be enumeration type");
3266 -- If the enumeration type has a standard representation, the effect
3267 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3269 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3271 Make_Attribute_Reference
(Loc
,
3272 Prefix
=> Relocate_Node
(Prefix
(N
)),
3273 Attribute_Name
=> Name_Val
,
3274 Expressions
=> New_List
(Relocate_Node
(E1
))));
3275 Analyze_And_Resolve
(N
, P_Base_Type
);
3277 -- Non-standard representation case (enumeration with holes)
3281 Resolve
(E1
, Any_Integer
);
3282 Set_Etype
(N
, P_Base_Type
);
3290 when Attribute_Epsilon
=>
3291 Check_Floating_Point_Type_0
;
3292 Set_Etype
(N
, Universal_Real
);
3298 when Attribute_Exponent
=>
3299 Check_Floating_Point_Type_1
;
3300 Set_Etype
(N
, Universal_Integer
);
3301 Resolve
(E1
, P_Base_Type
);
3307 when Attribute_External_Tag
=>
3311 Set_Etype
(N
, Standard_String
);
3313 if not Is_Tagged_Type
(P_Type
) then
3314 Error_Attr_P
("prefix of % attribute must be tagged");
3321 when Attribute_Fast_Math
=>
3322 Check_Standard_Prefix
;
3323 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3329 when Attribute_First
=>
3330 Check_Array_Or_Scalar_Type
;
3331 Bad_Attribute_For_Predicate
;
3337 when Attribute_First_Bit
=>
3339 Set_Etype
(N
, Universal_Integer
);
3345 when Attribute_First_Valid
=>
3346 Check_First_Last_Valid
;
3347 Set_Etype
(N
, P_Type
);
3353 when Attribute_Fixed_Value
=>
3355 Check_Fixed_Point_Type
;
3356 Resolve
(E1
, Any_Integer
);
3357 Set_Etype
(N
, P_Base_Type
);
3363 when Attribute_Floor
=>
3364 Check_Floating_Point_Type_1
;
3365 Set_Etype
(N
, P_Base_Type
);
3366 Resolve
(E1
, P_Base_Type
);
3372 when Attribute_Fore
=>
3373 Check_Fixed_Point_Type_0
;
3374 Set_Etype
(N
, Universal_Integer
);
3380 when Attribute_Fraction
=>
3381 Check_Floating_Point_Type_1
;
3382 Set_Etype
(N
, P_Base_Type
);
3383 Resolve
(E1
, P_Base_Type
);
3389 when Attribute_From_Any
=>
3391 Check_PolyORB_Attribute
;
3392 Set_Etype
(N
, P_Base_Type
);
3394 -----------------------
3395 -- Has_Access_Values --
3396 -----------------------
3398 when Attribute_Has_Access_Values
=>
3401 Set_Etype
(N
, Standard_Boolean
);
3403 -----------------------
3404 -- Has_Tagged_Values --
3405 -----------------------
3407 when Attribute_Has_Tagged_Values
=>
3410 Set_Etype
(N
, Standard_Boolean
);
3412 -----------------------
3413 -- Has_Discriminants --
3414 -----------------------
3416 when Attribute_Has_Discriminants
=>
3417 Legal_Formal_Attribute
;
3423 when Attribute_Identity
=>
3427 if Etype
(P
) = Standard_Exception_Type
then
3428 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3430 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3431 -- task interface class-wide types.
3433 elsif Is_Task_Type
(Etype
(P
))
3434 or else (Is_Access_Type
(Etype
(P
))
3435 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3436 or else (Ada_Version
>= Ada_2005
3437 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3438 and then Is_Interface
(Etype
(P
))
3439 and then Is_Task_Interface
(Etype
(P
)))
3442 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3445 if Ada_Version
>= Ada_2005
then
3447 ("prefix of % attribute must be an exception, a " &
3448 "task or a task interface class-wide object");
3451 ("prefix of % attribute must be a task or an exception");
3459 when Attribute_Image
=> Image
:
3461 Check_SPARK_Restriction_On_Attribute
;
3463 Set_Etype
(N
, Standard_String
);
3465 if Is_Real_Type
(P_Type
) then
3466 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3467 Error_Msg_Name_1
:= Aname
;
3469 ("(Ada 83) % attribute not allowed for real types", N
);
3473 if Is_Enumeration_Type
(P_Type
) then
3474 Check_Restriction
(No_Enumeration_Maps
, N
);
3478 Resolve
(E1
, P_Base_Type
);
3480 Validate_Non_Static_Attribute_Function_Call
;
3487 when Attribute_Img
=> Img
:
3490 Set_Etype
(N
, Standard_String
);
3492 if not Is_Scalar_Type
(P_Type
)
3493 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3496 ("prefix of % attribute must be scalar object name");
3506 when Attribute_Input
=>
3508 Check_Stream_Attribute
(TSS_Stream_Input
);
3509 Set_Etype
(N
, P_Base_Type
);
3515 when Attribute_Integer_Value
=>
3518 Resolve
(E1
, Any_Fixed
);
3520 -- Signal an error if argument type is not a specific fixed-point
3521 -- subtype. An error has been signalled already if the argument
3522 -- was not of a fixed-point type.
3524 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3525 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3528 Set_Etype
(N
, P_Base_Type
);
3534 when Attribute_Invalid_Value
=>
3537 Set_Etype
(N
, P_Base_Type
);
3538 Invalid_Value_Used
:= True;
3544 when Attribute_Large
=>
3547 Set_Etype
(N
, Universal_Real
);
3553 when Attribute_Last
=>
3554 Check_Array_Or_Scalar_Type
;
3555 Bad_Attribute_For_Predicate
;
3561 when Attribute_Last_Bit
=>
3563 Set_Etype
(N
, Universal_Integer
);
3569 when Attribute_Last_Valid
=>
3570 Check_First_Last_Valid
;
3571 Set_Etype
(N
, P_Type
);
3577 when Attribute_Leading_Part
=>
3578 Check_Floating_Point_Type_2
;
3579 Set_Etype
(N
, P_Base_Type
);
3580 Resolve
(E1
, P_Base_Type
);
3581 Resolve
(E2
, Any_Integer
);
3587 when Attribute_Length
=>
3589 Set_Etype
(N
, Universal_Integer
);
3595 when Attribute_Lock_Free
=>
3597 Set_Etype
(N
, Standard_Boolean
);
3599 if not Is_Protected_Type
(P_Type
) then
3601 ("prefix of % attribute must be a protected object");
3608 when Attribute_Loop_Entry
=> Loop_Entry
: declare
3609 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
3610 -- Inspect the prefix for any uses of entities declared within the
3611 -- related loop. Loop_Id denotes the loop identifier.
3613 --------------------------------
3614 -- Check_References_In_Prefix --
3615 --------------------------------
3617 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
3618 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
3620 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
3621 -- Determine whether a reference mentions an entity declared
3622 -- within the related loop.
3624 function Declared_Within
(Nod
: Node_Id
) return Boolean;
3625 -- Determine whether Nod appears in the subtree of Loop_Decl
3627 ---------------------
3628 -- Check_Reference --
3629 ---------------------
3631 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
3633 if Nkind
(Nod
) = N_Identifier
3634 and then Present
(Entity
(Nod
))
3635 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
3638 ("prefix of attribute % cannot reference local entities",
3644 end Check_Reference
;
3646 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
3648 ---------------------
3649 -- Declared_Within --
3650 ---------------------
3652 function Declared_Within
(Nod
: Node_Id
) return Boolean is
3657 while Present
(Stmt
) loop
3658 if Stmt
= Loop_Decl
then
3661 -- Prevent the search from going too far
3663 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3667 Stmt
:= Parent
(Stmt
);
3671 end Declared_Within
;
3673 -- Start of processing for Check_Prefix_For_Local_References
3676 Check_References
(P
);
3677 end Check_References_In_Prefix
;
3681 Context
: constant Node_Id
:= Parent
(N
);
3683 Enclosing_Loop
: Node_Id
;
3684 In_Loop_Assertion
: Boolean := False;
3685 Loop_Id
: Entity_Id
:= Empty
;
3689 -- Start of processing for Loop_Entry
3694 -- Set the type of the attribute now to ensure the successfull
3695 -- continuation of analysis even if the attribute is misplaced.
3697 Set_Etype
(Attr
, P_Type
);
3699 -- Attribute 'Loop_Entry may appear in several flavors:
3701 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3702 -- nearest enclosing loop.
3704 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3705 -- attribute may be related to a loop denoted by label Expr or
3706 -- the prefix may denote an array object and Expr may act as an
3707 -- indexed component.
3709 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3710 -- to the nearest enclosing loop, all expressions are part of
3711 -- an indexed component.
3713 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3714 -- denotes, the attribute may be related to a loop denoted by
3715 -- label Expr or the prefix may denote a multidimensional array
3716 -- array object and Expr along with the rest of the expressions
3717 -- may act as indexed components.
3719 -- Regardless of variations, the attribute reference does not have an
3720 -- expression list. Instead, all available expressions are stored as
3721 -- indexed components.
3723 -- When the attribute is part of an indexed component, find the first
3724 -- expression as it will determine the semantics of 'Loop_Entry.
3726 if Nkind
(Context
) = N_Indexed_Component
then
3727 E1
:= First
(Expressions
(Context
));
3730 -- The attribute reference appears in the following form:
3732 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3734 -- In this case, the loop name is omitted and no rewriting is
3737 if Present
(E2
) then
3740 -- The form of the attribute is:
3742 -- Prefix'Loop_Entry (Expr) [(...)]
3744 -- If Expr denotes a loop entry, the whole attribute and indexed
3745 -- component will have to be rewritten to reflect this relation.
3748 pragma Assert
(Present
(E1
));
3750 -- Do not expand the expression as it may have side effects.
3751 -- Simply preanalyze to determine whether it is a loop name or
3754 Preanalyze_And_Resolve
(E1
);
3756 if Is_Entity_Name
(E1
)
3757 and then Present
(Entity
(E1
))
3758 and then Ekind
(Entity
(E1
)) = E_Loop
3760 Loop_Id
:= Entity
(E1
);
3762 -- Transform the attribute and enclosing indexed component
3764 Set_Expressions
(N
, Expressions
(Context
));
3765 Rewrite
(Context
, N
);
3766 Set_Etype
(Context
, P_Type
);
3773 -- The prefix must denote an object
3775 if not Is_Object_Reference
(P
) then
3776 Error_Attr_P
("prefix of attribute % must denote an object");
3779 -- The prefix cannot be of a limited type because the expansion of
3780 -- Loop_Entry must create a constant initialized by the evaluated
3783 if Is_Immutably_Limited_Type
(Etype
(P
)) then
3784 Error_Attr_P
("prefix of attribute % cannot be limited");
3787 -- Climb the parent chain to verify the location of the attribute and
3788 -- find the enclosing loop.
3791 while Present
(Stmt
) loop
3793 -- Locate the enclosing Loop_Invariant / Loop_Variant pragma
3795 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
3797 Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
3798 Name_Loop_Invariant
,
3801 In_Loop_Assertion
:= True;
3803 -- Locate the enclosing loop (if any). Note that Ada 2012 array
3804 -- iteration may be expanded into several nested loops, we are
3805 -- interested in the outermost one which has the loop identifier.
3807 elsif Nkind
(Stmt
) = N_Loop_Statement
3808 and then Present
(Identifier
(Stmt
))
3810 Enclosing_Loop
:= Stmt
;
3812 -- The original attribute reference may lack a loop name. Use
3813 -- the name of the enclosing loop because it is the related
3816 if No
(Loop_Id
) then
3817 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
3822 -- Prevent the search from going too far
3824 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3828 Stmt
:= Parent
(Stmt
);
3831 -- Loop_Entry must appear within a Loop_Assertion pragma
3833 if not In_Loop_Assertion
then
3835 ("attribute % must appear within pragma Loop_Variant or " &
3836 "Loop_Invariant", N
);
3839 -- A Loop_Entry that applies to a given loop statement shall not
3840 -- appear within a body of accept statement, if this construct is
3841 -- itself enclosed by the given loop statement.
3843 for Index
in reverse 0 .. Scope_Stack
.Last
loop
3844 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
3846 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
3849 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
3854 ("attribute % cannot appear in body or accept statement", N
);
3859 -- The prefix cannot mention entities declared within the related
3860 -- loop because they will not be visible once the prefix is moved
3861 -- outside the loop.
3863 Check_References_In_Prefix
(Loop_Id
);
3865 -- The prefix must denote a static entity if the pragma does not
3866 -- apply to the innermost enclosing loop statement.
3868 if Present
(Enclosing_Loop
)
3869 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
3870 and then not Is_Entity_Name
(P
)
3872 Error_Attr_P
("prefix of attribute % must denote an entity");
3880 when Attribute_Machine
=>
3881 Check_Floating_Point_Type_1
;
3882 Set_Etype
(N
, P_Base_Type
);
3883 Resolve
(E1
, P_Base_Type
);
3889 when Attribute_Machine_Emax
=>
3890 Check_Floating_Point_Type_0
;
3891 Set_Etype
(N
, Universal_Integer
);
3897 when Attribute_Machine_Emin
=>
3898 Check_Floating_Point_Type_0
;
3899 Set_Etype
(N
, Universal_Integer
);
3901 ----------------------
3902 -- Machine_Mantissa --
3903 ----------------------
3905 when Attribute_Machine_Mantissa
=>
3906 Check_Floating_Point_Type_0
;
3907 Set_Etype
(N
, Universal_Integer
);
3909 -----------------------
3910 -- Machine_Overflows --
3911 -----------------------
3913 when Attribute_Machine_Overflows
=>
3916 Set_Etype
(N
, Standard_Boolean
);
3922 when Attribute_Machine_Radix
=>
3925 Set_Etype
(N
, Universal_Integer
);
3927 ----------------------
3928 -- Machine_Rounding --
3929 ----------------------
3931 when Attribute_Machine_Rounding
=>
3932 Check_Floating_Point_Type_1
;
3933 Set_Etype
(N
, P_Base_Type
);
3934 Resolve
(E1
, P_Base_Type
);
3936 --------------------
3937 -- Machine_Rounds --
3938 --------------------
3940 when Attribute_Machine_Rounds
=>
3943 Set_Etype
(N
, Standard_Boolean
);
3949 when Attribute_Machine_Size
=>
3952 Check_Not_Incomplete_Type
;
3953 Set_Etype
(N
, Universal_Integer
);
3959 when Attribute_Mantissa
=>
3962 Set_Etype
(N
, Universal_Integer
);
3968 when Attribute_Max
=>
3971 Resolve
(E1
, P_Base_Type
);
3972 Resolve
(E2
, P_Base_Type
);
3973 Set_Etype
(N
, P_Base_Type
);
3975 ----------------------------------
3976 -- Max_Alignment_For_Allocation --
3977 -- Max_Size_In_Storage_Elements --
3978 ----------------------------------
3980 when Attribute_Max_Alignment_For_Allocation |
3981 Attribute_Max_Size_In_Storage_Elements
=>
3984 Check_Not_Incomplete_Type
;
3985 Set_Etype
(N
, Universal_Integer
);
3987 -----------------------
3988 -- Maximum_Alignment --
3989 -----------------------
3991 when Attribute_Maximum_Alignment
=>
3992 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3994 --------------------
3995 -- Mechanism_Code --
3996 --------------------
3998 when Attribute_Mechanism_Code
=>
3999 if not Is_Entity_Name
(P
)
4000 or else not Is_Subprogram
(Entity
(P
))
4002 Error_Attr_P
("prefix of % attribute must be subprogram");
4005 Check_Either_E0_Or_E1
;
4007 if Present
(E1
) then
4008 Resolve
(E1
, Any_Integer
);
4009 Set_Etype
(E1
, Standard_Integer
);
4011 if not Is_Static_Expression
(E1
) then
4012 Flag_Non_Static_Expr
4013 ("expression for parameter number must be static!", E1
);
4016 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4017 or else UI_To_Int
(Intval
(E1
)) < 0
4019 Error_Attr
("invalid parameter number for % attribute", E1
);
4023 Set_Etype
(N
, Universal_Integer
);
4029 when Attribute_Min
=>
4032 Resolve
(E1
, P_Base_Type
);
4033 Resolve
(E2
, P_Base_Type
);
4034 Set_Etype
(N
, P_Base_Type
);
4040 when Attribute_Mod
=>
4042 -- Note: this attribute is only allowed in Ada 2005 mode, but
4043 -- we do not need to test that here, since Mod is only recognized
4044 -- as an attribute name in Ada 2005 mode during the parse.
4047 Check_Modular_Integer_Type
;
4048 Resolve
(E1
, Any_Integer
);
4049 Set_Etype
(N
, P_Base_Type
);
4055 when Attribute_Model
=>
4056 Check_Floating_Point_Type_1
;
4057 Set_Etype
(N
, P_Base_Type
);
4058 Resolve
(E1
, P_Base_Type
);
4064 when Attribute_Model_Emin
=>
4065 Check_Floating_Point_Type_0
;
4066 Set_Etype
(N
, Universal_Integer
);
4072 when Attribute_Model_Epsilon
=>
4073 Check_Floating_Point_Type_0
;
4074 Set_Etype
(N
, Universal_Real
);
4076 --------------------
4077 -- Model_Mantissa --
4078 --------------------
4080 when Attribute_Model_Mantissa
=>
4081 Check_Floating_Point_Type_0
;
4082 Set_Etype
(N
, Universal_Integer
);
4088 when Attribute_Model_Small
=>
4089 Check_Floating_Point_Type_0
;
4090 Set_Etype
(N
, Universal_Real
);
4096 when Attribute_Modulus
=>
4098 Check_Modular_Integer_Type
;
4099 Set_Etype
(N
, Universal_Integer
);
4101 --------------------
4102 -- Null_Parameter --
4103 --------------------
4105 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4106 Parnt
: constant Node_Id
:= Parent
(N
);
4107 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4109 procedure Bad_Null_Parameter
(Msg
: String);
4110 -- Used if bad Null parameter attribute node is found. Issues
4111 -- given error message, and also sets the type to Any_Type to
4112 -- avoid blowups later on from dealing with a junk node.
4114 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4115 -- Called to check that Proc_Ent is imported subprogram
4117 ------------------------
4118 -- Bad_Null_Parameter --
4119 ------------------------
4121 procedure Bad_Null_Parameter
(Msg
: String) is
4123 Error_Msg_N
(Msg
, N
);
4124 Set_Etype
(N
, Any_Type
);
4125 end Bad_Null_Parameter
;
4127 ----------------------
4128 -- Must_Be_Imported --
4129 ----------------------
4131 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4132 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4135 -- Ignore check if procedure not frozen yet (we will get
4136 -- another chance when the default parameter is reanalyzed)
4138 if not Is_Frozen
(Pent
) then
4141 elsif not Is_Imported
(Pent
) then
4143 ("Null_Parameter can only be used with imported subprogram");
4148 end Must_Be_Imported
;
4150 -- Start of processing for Null_Parameter
4155 Set_Etype
(N
, P_Type
);
4157 -- Case of attribute used as default expression
4159 if Nkind
(Parnt
) = N_Parameter_Specification
then
4160 Must_Be_Imported
(Defining_Entity
(GParnt
));
4162 -- Case of attribute used as actual for subprogram (positional)
4164 elsif Nkind
(Parnt
) in N_Subprogram_Call
4165 and then Is_Entity_Name
(Name
(Parnt
))
4167 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4169 -- Case of attribute used as actual for subprogram (named)
4171 elsif Nkind
(Parnt
) = N_Parameter_Association
4172 and then Nkind
(GParnt
) in N_Subprogram_Call
4173 and then Is_Entity_Name
(Name
(GParnt
))
4175 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4177 -- Not an allowed case
4181 ("Null_Parameter must be actual or default parameter");
4189 when Attribute_Object_Size
=>
4192 Check_Not_Incomplete_Type
;
4193 Set_Etype
(N
, Universal_Integer
);
4199 when Attribute_Old
=> Old
: declare
4201 -- The enclosing scope, excluding loops for quantified expressions.
4202 -- During analysis, it is the postcondition subprogram. During
4203 -- pre-analysis, it is the scope of the subprogram declaration.
4206 -- During pre-analysis, Prag is the enclosing pragma node if any
4209 -- Find enclosing scopes, excluding loops
4211 CS
:= Current_Scope
;
4212 while Ekind
(CS
) = E_Loop
loop
4216 -- If we are in Spec_Expression mode, this should be the prescan of
4217 -- the postcondition (or contract case, or test case) pragma.
4219 if In_Spec_Expression
then
4221 -- Check in postcondition, Test_Case or Contract_Cases
4224 while Present
(Prag
)
4225 and then not Nkind_In
(Prag
, N_Pragma
,
4226 N_Function_Specification
,
4227 N_Procedure_Specification
,
4228 N_Aspect_Specification
,
4231 Prag
:= Parent
(Prag
);
4234 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4235 -- corresponding pragma. Do not issue errors when analyzing the
4238 if Nkind
(Prag
) = N_Aspect_Specification
then
4241 elsif Nkind
(Prag
) /= N_Pragma
then
4242 Error_Attr
("% attribute can only appear in postcondition", P
);
4244 elsif Get_Pragma_Id
(Prag
) = Pragma_Test_Case
then
4246 Arg_Ens
: constant Node_Id
:=
4247 Get_Ensures_From_CTC_Pragma
(Prag
);
4252 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
4253 Arg
:= Parent
(Arg
);
4256 if Arg
/= Arg_Ens
then
4257 Error_Attr
("% attribute misplaced inside test case", P
);
4261 elsif Get_Pragma_Id
(Prag
) = Pragma_Contract_Cases
then
4263 Aggr
: constant Node_Id
:=
4264 Expression
(First
(Pragma_Argument_Associations
(Prag
)));
4269 while Arg
/= Prag
and then Parent
(Parent
(Arg
)) /= Aggr
loop
4270 Arg
:= Parent
(Arg
);
4273 -- At this point, Parent (Arg) should be a component
4274 -- association. Attribute Result is only allowed in
4275 -- the expression part of this association.
4277 if Nkind
(Parent
(Arg
)) /= N_Component_Association
4278 or else Arg
/= Expression
(Parent
(Arg
))
4281 ("% attribute misplaced inside contract cases", P
);
4285 elsif Get_Pragma_Id
(Prag
) /= Pragma_Postcondition
then
4286 Error_Attr
("% attribute can only appear in postcondition", P
);
4289 -- Body case, where we must be inside a generated _Postcondition
4290 -- procedure, or else the attribute use is definitely misplaced. The
4291 -- postcondition itself may have generated transient scopes, and is
4292 -- not necessarily the current one.
4295 while Present
(CS
) and then CS
/= Standard_Standard
loop
4296 if Chars
(CS
) = Name_uPostconditions
then
4303 if Chars
(CS
) /= Name_uPostconditions
then
4304 Error_Attr
("% attribute can only appear in postcondition", P
);
4308 -- If the attribute reference is generated for a Requires clause,
4309 -- then no expressions follow. Otherwise it is a primary, in which
4310 -- case, if expressions follow, the attribute reference must be
4311 -- an indexable object, so rewrite the node accordingly.
4313 if Present
(E1
) then
4315 Make_Indexed_Component
(Loc
,
4317 Make_Attribute_Reference
(Loc
,
4318 Prefix
=> Relocate_Node
(Prefix
(N
)),
4319 Attribute_Name
=> Name_Old
),
4320 Expressions
=> Expressions
(N
)));
4328 -- Prefix has not been analyzed yet, and its full analysis will
4329 -- take place during expansion (see below).
4331 Preanalyze_And_Resolve
(P
);
4332 P_Type
:= Etype
(P
);
4333 Set_Etype
(N
, P_Type
);
4335 if Is_Limited_Type
(P_Type
) then
4336 Error_Attr
("attribute % cannot apply to limited objects", P
);
4339 if Is_Entity_Name
(P
)
4340 and then Is_Constant_Object
(Entity
(P
))
4343 ("??attribute Old applied to constant has no effect", P
);
4346 -- The attribute appears within a pre/postcondition, but refers to
4347 -- an entity in the enclosing subprogram. If it is a component of
4348 -- a formal its expansion might generate actual subtypes that may
4349 -- be referenced in an inner context, and which must be elaborated
4350 -- within the subprogram itself. If the prefix includes a function
4351 -- call it may involve finalization actions that should only be
4352 -- inserted when the attribute has been rewritten as a declarations.
4353 -- As a result, if the prefix is not a simple name we create
4354 -- a declaration for it now, and insert it at the start of the
4355 -- enclosing subprogram. This is properly an expansion activity
4356 -- but it has to be performed now to prevent out-of-order issues.
4358 -- This expansion is both harmful and not needed in SPARK mode, since
4359 -- the formal verification backend relies on the types of nodes
4360 -- (hence is not robust w.r.t. a change to base type here), and does
4361 -- not suffer from the out-of-order issue described above. Thus, this
4362 -- expansion is skipped in SPARK mode.
4364 if not Is_Entity_Name
(P
) and then not SPARK_Mode
then
4365 P_Type
:= Base_Type
(P_Type
);
4366 Set_Etype
(N
, P_Type
);
4367 Set_Etype
(P
, P_Type
);
4368 Analyze_Dimension
(N
);
4373 ----------------------
4374 -- Overlaps_Storage --
4375 ----------------------
4377 when Attribute_Overlaps_Storage
=>
4380 -- Both arguments must be objects of any type
4382 Analyze_And_Resolve
(P
);
4383 Analyze_And_Resolve
(E1
);
4384 Check_Object_Reference
(P
);
4385 Check_Object_Reference
(E1
);
4386 Set_Etype
(N
, Standard_Boolean
);
4392 when Attribute_Output
=>
4394 Check_Stream_Attribute
(TSS_Stream_Output
);
4395 Set_Etype
(N
, Standard_Void_Type
);
4396 Resolve
(N
, Standard_Void_Type
);
4402 when Attribute_Partition_ID
=> Partition_Id
:
4406 if P_Type
/= Any_Type
then
4407 if not Is_Library_Level_Entity
(Entity
(P
)) then
4409 ("prefix of % attribute must be library-level entity");
4411 -- The defining entity of prefix should not be declared inside a
4412 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4414 elsif Is_Entity_Name
(P
)
4415 and then Is_Pure
(Entity
(P
))
4417 Error_Attr_P
("prefix of% attribute must not be declared pure");
4421 Set_Etype
(N
, Universal_Integer
);
4424 -------------------------
4425 -- Passed_By_Reference --
4426 -------------------------
4428 when Attribute_Passed_By_Reference
=>
4431 Set_Etype
(N
, Standard_Boolean
);
4437 when Attribute_Pool_Address
=>
4439 Set_Etype
(N
, RTE
(RE_Address
));
4445 when Attribute_Pos
=>
4446 Check_Discrete_Type
;
4449 if Is_Boolean_Type
(P_Type
) then
4450 Error_Msg_Name_1
:= Aname
;
4451 Error_Msg_Name_2
:= Chars
(P_Type
);
4452 Check_SPARK_Restriction
4453 ("attribute% is not allowed for type%", P
);
4456 Resolve
(E1
, P_Base_Type
);
4457 Set_Etype
(N
, Universal_Integer
);
4463 when Attribute_Position
=>
4465 Set_Etype
(N
, Universal_Integer
);
4471 when Attribute_Pred
=>
4475 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4476 Error_Msg_Name_1
:= Aname
;
4477 Error_Msg_Name_2
:= Chars
(P_Type
);
4478 Check_SPARK_Restriction
4479 ("attribute% is not allowed for type%", P
);
4482 Resolve
(E1
, P_Base_Type
);
4483 Set_Etype
(N
, P_Base_Type
);
4485 -- Nothing to do for real type case
4487 if Is_Real_Type
(P_Type
) then
4490 -- If not modular type, test for overflow check required
4493 if not Is_Modular_Integer_Type
(P_Type
)
4494 and then not Range_Checks_Suppressed
(P_Base_Type
)
4496 Enable_Range_Check
(E1
);
4504 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4506 when Attribute_Priority
=>
4507 if Ada_Version
< Ada_2005
then
4508 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4513 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4517 if Is_Protected_Type
(Etype
(P
))
4518 or else (Is_Access_Type
(Etype
(P
))
4519 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4521 Resolve
(P
, Etype
(P
));
4523 Error_Attr_P
("prefix of % attribute must be a protected object");
4526 Set_Etype
(N
, Standard_Integer
);
4528 -- Must be called from within a protected procedure or entry of the
4529 -- protected object.
4536 while S
/= Etype
(P
)
4537 and then S
/= Standard_Standard
4542 if S
= Standard_Standard
then
4543 Error_Attr
("the attribute % is only allowed inside protected "
4548 Validate_Non_Static_Attribute_Function_Call
;
4554 when Attribute_Range
=>
4555 Check_Array_Or_Scalar_Type
;
4556 Bad_Attribute_For_Predicate
;
4558 if Ada_Version
= Ada_83
4559 and then Is_Scalar_Type
(P_Type
)
4560 and then Comes_From_Source
(N
)
4563 ("(Ada 83) % attribute not allowed for scalar type", P
);
4570 when Attribute_Result
=> Result
: declare
4572 -- The enclosing scope, excluding loops for quantified expressions
4575 -- During analysis, CS is the postcondition subprogram and PS the
4576 -- source subprogram to which the postcondition applies. During
4577 -- pre-analysis, CS is the scope of the subprogram declaration.
4580 -- During pre-analysis, Prag is the enclosing pragma node if any
4583 -- Find the proper enclosing scope
4585 CS
:= Current_Scope
;
4586 while Present
(CS
) loop
4588 -- Skip generated loops
4590 if Ekind
(CS
) = E_Loop
then
4593 -- Skip the special _Parent scope generated to capture references
4594 -- to formals during the process of subprogram inlining.
4596 elsif Ekind
(CS
) = E_Function
4597 and then Chars
(CS
) = Name_uParent
4607 -- If the enclosing subprogram is always inlined, the enclosing
4608 -- postcondition will not be propagated to the expanded call.
4610 if not In_Spec_Expression
4611 and then Has_Pragma_Inline_Always
(PS
)
4612 and then Warn_On_Redundant_Constructs
4615 ("postconditions on inlined functions not enforced?r?", N
);
4618 -- If we are in the scope of a function and in Spec_Expression mode,
4619 -- this is likely the prescan of the postcondition (or contract case,
4620 -- or test case) pragma, and we just set the proper type. If there is
4621 -- an error it will be caught when the real Analyze call is done.
4623 if Ekind
(CS
) = E_Function
4624 and then In_Spec_Expression
4628 if Chars
(CS
) /= Chars
(P
) then
4629 Error_Msg_Name_1
:= Name_Result
;
4632 ("incorrect prefix for % attribute, expected &", P
, CS
);
4636 -- Check in postcondition, Test_Case or Contract_Cases of function
4639 while Present
(Prag
)
4640 and then not Nkind_In
(Prag
, N_Pragma
,
4641 N_Function_Specification
,
4642 N_Aspect_Specification
,
4645 Prag
:= Parent
(Prag
);
4648 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4649 -- corresponding pragma. Do not issue errors when analyzing the
4652 if Nkind
(Prag
) = N_Aspect_Specification
then
4655 elsif Nkind
(Prag
) /= N_Pragma
then
4657 ("% attribute can only appear in postcondition of function",
4660 elsif Get_Pragma_Id
(Prag
) = Pragma_Test_Case
then
4662 Arg_Ens
: constant Node_Id
:=
4663 Get_Ensures_From_CTC_Pragma
(Prag
);
4668 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
4669 Arg
:= Parent
(Arg
);
4672 if Arg
/= Arg_Ens
then
4673 Error_Attr
("% attribute misplaced inside test case", P
);
4677 elsif Get_Pragma_Id
(Prag
) = Pragma_Contract_Cases
then
4679 Aggr
: constant Node_Id
:=
4680 Expression
(First
(Pragma_Argument_Associations
(Prag
)));
4685 while Arg
/= Prag
and then Parent
(Parent
(Arg
)) /= Aggr
loop
4686 Arg
:= Parent
(Arg
);
4689 -- At this point, Parent (Arg) should be a component
4690 -- association. Attribute Result is only allowed in
4691 -- the expression part of this association.
4693 if Nkind
(Parent
(Arg
)) /= N_Component_Association
4694 or else Arg
/= Expression
(Parent
(Arg
))
4697 ("% attribute misplaced inside contract cases", P
);
4701 elsif Get_Pragma_Id
(Prag
) /= Pragma_Postcondition
then
4703 ("% attribute can only appear in postcondition of function",
4707 -- The attribute reference is a primary. If expressions follow,
4708 -- the attribute reference is really an indexable object, so
4709 -- rewrite and analyze as an indexed component.
4711 if Present
(E1
) then
4713 Make_Indexed_Component
(Loc
,
4715 Make_Attribute_Reference
(Loc
,
4716 Prefix
=> Relocate_Node
(Prefix
(N
)),
4717 Attribute_Name
=> Name_Result
),
4718 Expressions
=> Expressions
(N
)));
4723 Set_Etype
(N
, Etype
(CS
));
4725 -- If several functions with that name are visible,
4726 -- the intended one is the current scope.
4728 if Is_Overloaded
(P
) then
4730 Set_Is_Overloaded
(P
, False);
4733 -- Body case, where we must be inside a generated _Postcondition
4734 -- procedure, and the prefix must be on the scope stack, or else the
4735 -- attribute use is definitely misplaced. The postcondition itself
4736 -- may have generated transient scopes, and is not necessarily the
4740 while Present
(CS
) and then CS
/= Standard_Standard
loop
4741 if Chars
(CS
) = Name_uPostconditions
then
4750 if Chars
(CS
) = Name_uPostconditions
4751 and then Ekind
(PS
) = E_Function
4755 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
4756 and then Chars
(P
) = Chars
(PS
)
4760 -- Within an instance, the prefix designates the local renaming
4761 -- of the original generic.
4763 elsif Is_Entity_Name
(P
)
4764 and then Ekind
(Entity
(P
)) = E_Function
4765 and then Present
(Alias
(Entity
(P
)))
4766 and then Chars
(Alias
(Entity
(P
))) = Chars
(PS
)
4772 ("incorrect prefix for % attribute, expected &", P
, PS
);
4776 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
4777 Analyze_And_Resolve
(N
, Etype
(PS
));
4781 ("% attribute can only appear in postcondition of function",
4791 when Attribute_Range_Length
=>
4793 Check_Discrete_Type
;
4794 Set_Etype
(N
, Universal_Integer
);
4800 when Attribute_Read
=>
4802 Check_Stream_Attribute
(TSS_Stream_Read
);
4803 Set_Etype
(N
, Standard_Void_Type
);
4804 Resolve
(N
, Standard_Void_Type
);
4805 Note_Possible_Modification
(E2
, Sure
=> True);
4811 when Attribute_Ref
=>
4815 if Nkind
(P
) /= N_Expanded_Name
4816 or else not Is_RTE
(P_Type
, RE_Address
)
4818 Error_Attr_P
("prefix of % attribute must be System.Address");
4821 Analyze_And_Resolve
(E1
, Any_Integer
);
4822 Set_Etype
(N
, RTE
(RE_Address
));
4828 when Attribute_Remainder
=>
4829 Check_Floating_Point_Type_2
;
4830 Set_Etype
(N
, P_Base_Type
);
4831 Resolve
(E1
, P_Base_Type
);
4832 Resolve
(E2
, P_Base_Type
);
4834 ---------------------
4835 -- Restriction_Set --
4836 ---------------------
4838 when Attribute_Restriction_Set
=> Restriction_Set
: declare
4841 Unam
: Unit_Name_Type
;
4843 procedure Set_Result
(B
: Boolean);
4844 -- Replace restriction node by static constant False or True,
4845 -- depending on the value of B.
4851 procedure Set_Result
(B
: Boolean) is
4854 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
4856 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
4859 Set_Is_Static_Expression
(N
);
4862 -- Start of processing for Restriction_Set
4868 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
4870 Error_Attr_P
("prefix of % attribute must be System");
4873 -- No_Dependence case
4875 if Nkind
(E1
) = N_Parameter_Association
then
4876 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
4877 U
:= Explicit_Actual_Parameter
(E1
);
4879 if not OK_No_Dependence_Unit_Name
(U
) then
4884 -- See if there is an entry already in the table. That's the
4885 -- case in which we can return True.
4887 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
4888 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
4889 and then No_Dependences
.Table
(J
).Warn
= False
4896 -- If not in the No_Dependence table, result is False
4900 -- In this case, we must ensure that the binder will reject any
4901 -- other unit in the partition that sets No_Dependence for this
4902 -- unit. We do that by making an entry in the special table kept
4903 -- for this purpose (if the entry is not there already).
4905 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
4907 for J
in Restriction_Set_Dependences
.First
..
4908 Restriction_Set_Dependences
.Last
4910 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
4915 Restriction_Set_Dependences
.Append
(Unam
);
4917 -- Normal restriction case
4920 if Nkind
(E1
) /= N_Identifier
then
4922 Error_Attr
("attribute % requires restriction identifier", E1
);
4925 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
4927 if R
= Not_A_Restriction_Id
then
4929 Error_Msg_Node_1
:= E1
;
4930 Error_Attr
("invalid restriction identifier &", E1
);
4932 elsif R
not in Partition_Boolean_Restrictions
then
4934 Error_Msg_Node_1
:= E1
;
4936 ("& is not a boolean partition-wide restriction", E1
);
4939 if Restriction_Active
(R
) then
4942 Check_Restriction
(R
, N
);
4947 end Restriction_Set
;
4953 when Attribute_Round
=>
4955 Check_Decimal_Fixed_Point_Type
;
4956 Set_Etype
(N
, P_Base_Type
);
4958 -- Because the context is universal_real (3.5.10(12)) it is a
4959 -- legal context for a universal fixed expression. This is the
4960 -- only attribute whose functional description involves U_R.
4962 if Etype
(E1
) = Universal_Fixed
then
4964 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
4965 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
4966 Expression
=> Relocate_Node
(E1
));
4974 Resolve
(E1
, Any_Real
);
4980 when Attribute_Rounding
=>
4981 Check_Floating_Point_Type_1
;
4982 Set_Etype
(N
, P_Base_Type
);
4983 Resolve
(E1
, P_Base_Type
);
4989 when Attribute_Safe_Emax
=>
4990 Check_Floating_Point_Type_0
;
4991 Set_Etype
(N
, Universal_Integer
);
4997 when Attribute_Safe_First
=>
4998 Check_Floating_Point_Type_0
;
4999 Set_Etype
(N
, Universal_Real
);
5005 when Attribute_Safe_Large
=>
5008 Set_Etype
(N
, Universal_Real
);
5014 when Attribute_Safe_Last
=>
5015 Check_Floating_Point_Type_0
;
5016 Set_Etype
(N
, Universal_Real
);
5022 when Attribute_Safe_Small
=>
5025 Set_Etype
(N
, Universal_Real
);
5031 when Attribute_Same_Storage
=>
5032 Check_Ada_2012_Attribute
;
5035 -- The arguments must be objects of any type
5037 Analyze_And_Resolve
(P
);
5038 Analyze_And_Resolve
(E1
);
5039 Check_Object_Reference
(P
);
5040 Check_Object_Reference
(E1
);
5041 Set_Etype
(N
, Standard_Boolean
);
5043 --------------------------
5044 -- Scalar_Storage_Order --
5045 --------------------------
5047 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5052 if not Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
) then
5054 ("prefix of % attribute must be record or array type");
5057 if Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5059 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
5062 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
5065 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5068 -- Reset incorrect indication of staticness
5070 Set_Is_Static_Expression
(N
, False);
5071 end Scalar_Storage_Order
;
5077 when Attribute_Scale
=>
5079 Check_Decimal_Fixed_Point_Type
;
5080 Set_Etype
(N
, Universal_Integer
);
5086 when Attribute_Scaling
=>
5087 Check_Floating_Point_Type_2
;
5088 Set_Etype
(N
, P_Base_Type
);
5089 Resolve
(E1
, P_Base_Type
);
5095 when Attribute_Signed_Zeros
=>
5096 Check_Floating_Point_Type_0
;
5097 Set_Etype
(N
, Standard_Boolean
);
5103 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5107 -- If prefix is parameterless function call, rewrite and resolve
5110 if Is_Entity_Name
(P
)
5111 and then Ekind
(Entity
(P
)) = E_Function
5115 -- Similar processing for a protected function call
5117 elsif Nkind
(P
) = N_Selected_Component
5118 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5123 if Is_Object_Reference
(P
) then
5124 Check_Object_Reference
(P
);
5126 elsif Is_Entity_Name
(P
)
5127 and then (Is_Type
(Entity
(P
))
5128 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5132 elsif Nkind
(P
) = N_Type_Conversion
5133 and then not Comes_From_Source
(P
)
5137 -- Some other compilers allow dubious use of X'???'Size
5139 elsif Relaxed_RM_Semantics
5140 and then Nkind
(P
) = N_Attribute_Reference
5145 Error_Attr_P
("invalid prefix for % attribute");
5148 Check_Not_Incomplete_Type
;
5150 Set_Etype
(N
, Universal_Integer
);
5157 when Attribute_Small
=>
5160 Set_Etype
(N
, Universal_Real
);
5166 when Attribute_Storage_Pool |
5167 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5171 if Is_Access_Type
(P_Type
) then
5172 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5174 ("cannot use % attribute for access-to-subprogram type");
5177 -- Set appropriate entity
5179 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5180 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5182 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5185 if Attr_Id
= Attribute_Storage_Pool
then
5186 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5187 Name_Simple_Storage_Pool_Type
))
5189 Error_Msg_Name_1
:= Aname
;
5190 Error_Msg_N
("cannot use % attribute for type with simple "
5191 & "storage pool??", N
);
5193 ("\Program_Error will be raised at run time??", N
);
5196 (N
, Make_Raise_Program_Error
5197 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5200 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5202 -- In the Simple_Storage_Pool case, verify that the pool entity is
5203 -- actually of a simple storage pool type, and set the attribute's
5204 -- type to the pool object's type.
5207 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5208 Name_Simple_Storage_Pool_Type
))
5211 ("cannot use % attribute for type without simple " &
5215 Set_Etype
(N
, Etype
(Entity
(N
)));
5218 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5219 -- Storage_Pool since this attribute is not defined for such
5220 -- types (RM E.2.3(22)).
5222 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5225 Error_Attr_P
("prefix of % attribute must be access type");
5233 when Attribute_Storage_Size
=> Storage_Size
:
5237 if Is_Task_Type
(P_Type
) then
5238 Set_Etype
(N
, Universal_Integer
);
5240 -- Use with tasks is an obsolescent feature
5242 Check_Restriction
(No_Obsolescent_Features
, P
);
5244 elsif Is_Access_Type
(P_Type
) then
5245 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5247 ("cannot use % attribute for access-to-subprogram type");
5250 if Is_Entity_Name
(P
)
5251 and then Is_Type
(Entity
(P
))
5254 Set_Etype
(N
, Universal_Integer
);
5256 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5257 -- Storage_Size since this attribute is not defined for
5258 -- such types (RM E.2.3(22)).
5260 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5262 -- The prefix is allowed to be an implicit dereference of an
5263 -- access value designating a task.
5267 Set_Etype
(N
, Universal_Integer
);
5271 Error_Attr_P
("prefix of % attribute must be access or task type");
5279 when Attribute_Storage_Unit
=>
5280 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5286 when Attribute_Stream_Size
=>
5290 if Is_Entity_Name
(P
)
5291 and then Is_Elementary_Type
(Entity
(P
))
5293 Set_Etype
(N
, Universal_Integer
);
5295 Error_Attr_P
("invalid prefix for % attribute");
5302 when Attribute_Stub_Type
=>
5306 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5308 -- For a real RACW [sub]type, use corresponding stub type
5310 if not Is_Generic_Type
(P_Type
) then
5313 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5315 -- For a generic type (that has been marked as an RACW using the
5316 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5317 -- type. Note that if the actual is not a remote access type, the
5318 -- instantiation will fail.
5321 -- Note: we go to the underlying type here because the view
5322 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5326 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5331 ("prefix of% attribute must be remote access to classwide");
5338 when Attribute_Succ
=>
5342 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5343 Error_Msg_Name_1
:= Aname
;
5344 Error_Msg_Name_2
:= Chars
(P_Type
);
5345 Check_SPARK_Restriction
5346 ("attribute% is not allowed for type%", P
);
5349 Resolve
(E1
, P_Base_Type
);
5350 Set_Etype
(N
, P_Base_Type
);
5352 -- Nothing to do for real type case
5354 if Is_Real_Type
(P_Type
) then
5357 -- If not modular type, test for overflow check required
5360 if not Is_Modular_Integer_Type
(P_Type
)
5361 and then not Range_Checks_Suppressed
(P_Base_Type
)
5363 Enable_Range_Check
(E1
);
5367 --------------------------------
5368 -- System_Allocator_Alignment --
5369 --------------------------------
5371 when Attribute_System_Allocator_Alignment
=>
5372 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5378 when Attribute_Tag
=> Tag
:
5383 if not Is_Tagged_Type
(P_Type
) then
5384 Error_Attr_P
("prefix of % attribute must be tagged");
5386 -- Next test does not apply to generated code why not, and what does
5387 -- the illegal reference mean???
5389 elsif Is_Object_Reference
(P
)
5390 and then not Is_Class_Wide_Type
(P_Type
)
5391 and then Comes_From_Source
(N
)
5394 ("% attribute can only be applied to objects " &
5395 "of class - wide type");
5398 -- The prefix cannot be an incomplete type. However, references to
5399 -- 'Tag can be generated when expanding interface conversions, and
5402 if Comes_From_Source
(N
) then
5403 Check_Not_Incomplete_Type
;
5406 -- Set appropriate type
5408 Set_Etype
(N
, RTE
(RE_Tag
));
5415 when Attribute_Target_Name
=> Target_Name
: declare
5416 TN
: constant String := Sdefault
.Target_Name
.all;
5420 Check_Standard_Prefix
;
5424 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
5429 Make_String_Literal
(Loc
,
5430 Strval
=> TN
(TN
'First .. TL
)));
5431 Analyze_And_Resolve
(N
, Standard_String
);
5438 when Attribute_Terminated
=>
5440 Set_Etype
(N
, Standard_Boolean
);
5447 when Attribute_To_Address
=>
5451 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
5452 Error_Attr_P
("prefix of % attribute must be System");
5455 Generate_Reference
(RTE
(RE_Address
), P
);
5456 Analyze_And_Resolve
(E1
, Any_Integer
);
5457 Set_Etype
(N
, RTE
(RE_Address
));
5463 when Attribute_To_Any
=>
5465 Check_PolyORB_Attribute
;
5466 Set_Etype
(N
, RTE
(RE_Any
));
5472 when Attribute_Truncation
=>
5473 Check_Floating_Point_Type_1
;
5474 Resolve
(E1
, P_Base_Type
);
5475 Set_Etype
(N
, P_Base_Type
);
5481 when Attribute_Type_Class
=>
5484 Check_Not_Incomplete_Type
;
5485 Set_Etype
(N
, RTE
(RE_Type_Class
));
5491 when Attribute_TypeCode
=>
5493 Check_PolyORB_Attribute
;
5494 Set_Etype
(N
, RTE
(RE_TypeCode
));
5500 when Attribute_Type_Key
=>
5504 -- This processing belongs in Eval_Attribute ???
5507 function Type_Key
return String_Id
;
5508 -- A very preliminary implementation. For now, a signature
5509 -- consists of only the type name. This is clearly incomplete
5510 -- (e.g., adding a new field to a record type should change the
5511 -- type's Type_Key attribute).
5517 function Type_Key
return String_Id
is
5518 Full_Name
: constant String_Id
:=
5519 Fully_Qualified_Name_String
(Entity
(P
));
5522 -- Copy all characters in Full_Name but the trailing NUL
5525 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5526 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5529 Store_String_Chars
("'Type_Key");
5534 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5537 Analyze_And_Resolve
(N
, Standard_String
);
5543 when Attribute_UET_Address
=>
5545 Check_Unit_Name
(P
);
5546 Set_Etype
(N
, RTE
(RE_Address
));
5548 -----------------------
5549 -- Unbiased_Rounding --
5550 -----------------------
5552 when Attribute_Unbiased_Rounding
=>
5553 Check_Floating_Point_Type_1
;
5554 Set_Etype
(N
, P_Base_Type
);
5555 Resolve
(E1
, P_Base_Type
);
5557 ----------------------
5558 -- Unchecked_Access --
5559 ----------------------
5561 when Attribute_Unchecked_Access
=>
5562 if Comes_From_Source
(N
) then
5563 Check_Restriction
(No_Unchecked_Access
, N
);
5566 Analyze_Access_Attribute
;
5568 -------------------------
5569 -- Unconstrained_Array --
5570 -------------------------
5572 when Attribute_Unconstrained_Array
=>
5575 Check_Not_Incomplete_Type
;
5576 Set_Etype
(N
, Standard_Boolean
);
5578 ------------------------------
5579 -- Universal_Literal_String --
5580 ------------------------------
5582 -- This is a GNAT specific attribute whose prefix must be a named
5583 -- number where the expression is either a single numeric literal,
5584 -- or a numeric literal immediately preceded by a minus sign. The
5585 -- result is equivalent to a string literal containing the text of
5586 -- the literal as it appeared in the source program with a possible
5587 -- leading minus sign.
5589 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
5593 if not Is_Entity_Name
(P
)
5594 or else Ekind
(Entity
(P
)) not in Named_Kind
5596 Error_Attr_P
("prefix for % attribute must be named number");
5603 Src
: Source_Buffer_Ptr
;
5606 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
5608 if Nkind
(Expr
) = N_Op_Minus
then
5610 Expr
:= Original_Node
(Right_Opnd
(Expr
));
5615 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
5617 ("named number for % attribute must be simple literal", N
);
5620 -- Build string literal corresponding to source literal text
5625 Store_String_Char
(Get_Char_Code
('-'));
5629 Src
:= Source_Text
(Get_Source_File_Index
(S
));
5631 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
5632 Store_String_Char
(Get_Char_Code
(Src
(S
)));
5636 -- Now we rewrite the attribute with the string literal
5639 Make_String_Literal
(Loc
, End_String
));
5643 end Universal_Literal_String
;
5645 -------------------------
5646 -- Unrestricted_Access --
5647 -------------------------
5649 -- This is a GNAT specific attribute which is like Access except that
5650 -- all scope checks and checks for aliased views are omitted.
5652 when Attribute_Unrestricted_Access
=>
5654 -- If from source, deal with relevant restrictions
5656 if Comes_From_Source
(N
) then
5657 Check_Restriction
(No_Unchecked_Access
, N
);
5659 if Nkind
(P
) in N_Has_Entity
5660 and then Present
(Entity
(P
))
5661 and then Is_Object
(Entity
(P
))
5663 Check_Restriction
(No_Implicit_Aliasing
, N
);
5667 if Is_Entity_Name
(P
) then
5668 Set_Address_Taken
(Entity
(P
));
5671 Analyze_Access_Attribute
;
5677 when Attribute_Update
=> Update
: declare
5678 Comps
: Elist_Id
:= No_Elist
;
5680 procedure Check_Component_Reference
5683 -- Comp is a record component (possibly a discriminant) and Typ is a
5684 -- record type. Determine whether Comp is a legal component of Typ.
5685 -- Emit an error if Comp mentions a discriminant or is not a unique
5686 -- component reference in the update aggregate.
5688 -------------------------------
5689 -- Check_Component_Reference --
5690 -------------------------------
5692 procedure Check_Component_Reference
5696 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
5698 function Is_Duplicate_Component
return Boolean;
5699 -- Determine whether component Comp already appears in list Comps
5701 ----------------------------
5702 -- Is_Duplicate_Component --
5703 ----------------------------
5705 function Is_Duplicate_Component
return Boolean is
5706 Comp_Elmt
: Elmt_Id
;
5709 if Present
(Comps
) then
5710 Comp_Elmt
:= First_Elmt
(Comps
);
5711 while Present
(Comp_Elmt
) loop
5712 if Chars
(Node
(Comp_Elmt
)) = Comp_Name
then
5716 Next_Elmt
(Comp_Elmt
);
5721 end Is_Duplicate_Component
;
5725 Comp_Or_Discr
: Entity_Id
;
5727 -- Start of processing for Check_Component_Reference
5730 -- Find the discriminant or component whose name corresponds to
5731 -- Comp. A simple character comparison is sufficient because all
5732 -- visible names within a record type are unique.
5734 Comp_Or_Discr
:= First_Entity
(Typ
);
5735 while Present
(Comp_Or_Discr
) loop
5736 if Chars
(Comp_Or_Discr
) = Comp_Name
then
5740 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
5743 -- Diagnose possible erroneous references
5745 if Present
(Comp_Or_Discr
) then
5746 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
5748 ("attribute % may not modify record discriminants", Comp
);
5750 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
5751 if Is_Duplicate_Component
then
5752 Error_Msg_NE
("component & already updated", Comp
, Comp
);
5754 -- Mark this component as processed
5758 Comps
:= New_Elmt_List
;
5761 Append_Elmt
(Comp
, Comps
);
5765 -- The update aggregate mentions an entity that does not belong to
5770 ("& is not a component of aggregate subtype", Comp
, Comp
);
5772 end Check_Component_Reference
;
5779 -- Start of processing for Update
5784 if not Is_Object_Reference
(P
) then
5785 Error_Attr_P
("prefix of attribute % must denote an object");
5787 elsif not Is_Array_Type
(P_Type
)
5788 and then not Is_Record_Type
(P_Type
)
5790 Error_Attr_P
("prefix of attribute % must be a record or array");
5792 elsif Is_Immutably_Limited_Type
(P_Type
) then
5793 Error_Attr
("prefix of attribute % cannot be limited", N
);
5795 elsif Nkind
(E1
) /= N_Aggregate
then
5796 Error_Attr
("attribute % requires component association list", N
);
5799 -- Inspect the update aggregate, looking at all the associations and
5800 -- choices. Perform the following checks:
5802 -- 1) Legality of "others" in all cases
5803 -- 2) Component legality for records
5805 -- The remaining checks are performed on the expanded attribute
5807 Assoc
:= First
(Component_Associations
(E1
));
5808 while Present
(Assoc
) loop
5809 Comp
:= First
(Choices
(Assoc
));
5810 while Present
(Comp
) loop
5811 if Nkind
(Comp
) = N_Others_Choice
then
5813 ("others choice not allowed in attribute %", Comp
);
5815 elsif Is_Record_Type
(P_Type
) then
5816 Check_Component_Reference
(Comp
, P_Type
);
5825 -- The type of attribute Update is that of the prefix
5827 Set_Etype
(N
, P_Type
);
5834 when Attribute_Val
=> Val
: declare
5837 Check_Discrete_Type
;
5839 if Is_Boolean_Type
(P_Type
) then
5840 Error_Msg_Name_1
:= Aname
;
5841 Error_Msg_Name_2
:= Chars
(P_Type
);
5842 Check_SPARK_Restriction
5843 ("attribute% is not allowed for type%", P
);
5846 Resolve
(E1
, Any_Integer
);
5847 Set_Etype
(N
, P_Base_Type
);
5849 -- Note, we need a range check in general, but we wait for the
5850 -- Resolve call to do this, since we want to let Eval_Attribute
5851 -- have a chance to find an static illegality first!
5858 when Attribute_Valid
=>
5861 -- Ignore check for object if we have a 'Valid reference generated
5862 -- by the expanded code, since in some cases valid checks can occur
5863 -- on items that are names, but are not objects (e.g. attributes).
5865 if Comes_From_Source
(N
) then
5866 Check_Object_Reference
(P
);
5869 if not Is_Scalar_Type
(P_Type
) then
5870 Error_Attr_P
("object for % attribute must be of scalar type");
5873 -- If the attribute appears within the subtype's own predicate
5874 -- function, then issue a warning that this will cause infinite
5878 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
5881 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
5883 ("attribute Valid requires a predicate check??", N
);
5884 Error_Msg_N
("\and will result in infinite recursion??", N
);
5888 Set_Etype
(N
, Standard_Boolean
);
5894 when Attribute_Valid_Scalars
=>
5896 Check_Object_Reference
(P
);
5898 if No_Scalar_Parts
(P_Type
) then
5899 Error_Attr_P
("??attribute % always True, no scalars to check");
5902 Set_Etype
(N
, Standard_Boolean
);
5908 when Attribute_Value
=> Value
:
5910 Check_SPARK_Restriction_On_Attribute
;
5914 -- Case of enumeration type
5916 -- When an enumeration type appears in an attribute reference, all
5917 -- literals of the type are marked as referenced. This must only be
5918 -- done if the attribute reference appears in the current source.
5919 -- Otherwise the information on references may differ between a
5920 -- normal compilation and one that performs inlining.
5922 if Is_Enumeration_Type
(P_Type
)
5923 and then In_Extended_Main_Code_Unit
(N
)
5925 Check_Restriction
(No_Enumeration_Maps
, N
);
5927 -- Mark all enumeration literals as referenced, since the use of
5928 -- the Value attribute can implicitly reference any of the
5929 -- literals of the enumeration base type.
5932 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
5934 while Present
(Ent
) loop
5935 Set_Referenced
(Ent
);
5941 -- Set Etype before resolving expression because expansion of
5942 -- expression may require enclosing type. Note that the type
5943 -- returned by 'Value is the base type of the prefix type.
5945 Set_Etype
(N
, P_Base_Type
);
5946 Validate_Non_Static_Attribute_Function_Call
;
5953 when Attribute_Value_Size
=>
5956 Check_Not_Incomplete_Type
;
5957 Set_Etype
(N
, Universal_Integer
);
5963 when Attribute_Version
=>
5966 Set_Etype
(N
, RTE
(RE_Version_String
));
5972 when Attribute_Wchar_T_Size
=>
5973 Standard_Attribute
(Interfaces_Wchar_T_Size
);
5979 when Attribute_Wide_Image
=> Wide_Image
:
5981 Check_SPARK_Restriction_On_Attribute
;
5983 Set_Etype
(N
, Standard_Wide_String
);
5985 Resolve
(E1
, P_Base_Type
);
5986 Validate_Non_Static_Attribute_Function_Call
;
5989 ---------------------
5990 -- Wide_Wide_Image --
5991 ---------------------
5993 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
5996 Set_Etype
(N
, Standard_Wide_Wide_String
);
5998 Resolve
(E1
, P_Base_Type
);
5999 Validate_Non_Static_Attribute_Function_Call
;
6000 end Wide_Wide_Image
;
6006 when Attribute_Wide_Value
=> Wide_Value
:
6008 Check_SPARK_Restriction_On_Attribute
;
6012 -- Set Etype before resolving expression because expansion
6013 -- of expression may require enclosing type.
6015 Set_Etype
(N
, P_Type
);
6016 Validate_Non_Static_Attribute_Function_Call
;
6019 ---------------------
6020 -- Wide_Wide_Value --
6021 ---------------------
6023 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6028 -- Set Etype before resolving expression because expansion
6029 -- of expression may require enclosing type.
6031 Set_Etype
(N
, P_Type
);
6032 Validate_Non_Static_Attribute_Function_Call
;
6033 end Wide_Wide_Value
;
6035 ---------------------
6036 -- Wide_Wide_Width --
6037 ---------------------
6039 when Attribute_Wide_Wide_Width
=>
6042 Set_Etype
(N
, Universal_Integer
);
6048 when Attribute_Wide_Width
=>
6049 Check_SPARK_Restriction_On_Attribute
;
6052 Set_Etype
(N
, Universal_Integer
);
6058 when Attribute_Width
=>
6059 Check_SPARK_Restriction_On_Attribute
;
6062 Set_Etype
(N
, Universal_Integer
);
6068 when Attribute_Word_Size
=>
6069 Standard_Attribute
(System_Word_Size
);
6075 when Attribute_Write
=>
6077 Check_Stream_Attribute
(TSS_Stream_Write
);
6078 Set_Etype
(N
, Standard_Void_Type
);
6079 Resolve
(N
, Standard_Void_Type
);
6083 -- All errors raise Bad_Attribute, so that we get out before any further
6084 -- damage occurs when an error is detected (for example, if we check for
6085 -- one attribute expression, and the check succeeds, we want to be able
6086 -- to proceed securely assuming that an expression is in fact present.
6088 -- Note: we set the attribute analyzed in this case to prevent any
6089 -- attempt at reanalysis which could generate spurious error msgs.
6092 when Bad_Attribute
=>
6094 Set_Etype
(N
, Any_Type
);
6096 end Analyze_Attribute
;
6098 --------------------
6099 -- Eval_Attribute --
6100 --------------------
6102 procedure Eval_Attribute
(N
: Node_Id
) is
6103 Loc
: constant Source_Ptr
:= Sloc
(N
);
6104 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6105 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6106 P
: constant Node_Id
:= Prefix
(N
);
6108 C_Type
: constant Entity_Id
:= Etype
(N
);
6109 -- The type imposed by the context
6112 -- First expression, or Empty if none
6115 -- Second expression, or Empty if none
6117 P_Entity
: Entity_Id
;
6118 -- Entity denoted by prefix
6121 -- The type of the prefix
6123 P_Base_Type
: Entity_Id
;
6124 -- The base type of the prefix type
6126 P_Root_Type
: Entity_Id
;
6127 -- The root type of the prefix type
6130 -- True if the result is Static. This is set by the general processing
6131 -- to true if the prefix is static, and all expressions are static. It
6132 -- can be reset as processing continues for particular attributes
6134 Lo_Bound
, Hi_Bound
: Node_Id
;
6135 -- Expressions for low and high bounds of type or array index referenced
6136 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6139 -- Constraint error node used if we have an attribute reference has
6140 -- an argument that raises a constraint error. In this case we replace
6141 -- the attribute with a raise constraint_error node. This is important
6142 -- processing, since otherwise gigi might see an attribute which it is
6143 -- unprepared to deal with.
6145 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
6146 -- If Bound is a reference to a discriminant of a task or protected type
6147 -- occurring within the object's body, rewrite attribute reference into
6148 -- a reference to the corresponding discriminal. Use for the expansion
6149 -- of checks against bounds of entry family index subtypes.
6151 procedure Check_Expressions
;
6152 -- In case where the attribute is not foldable, the expressions, if
6153 -- any, of the attribute, are in a non-static context. This procedure
6154 -- performs the required additional checks.
6156 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
6157 -- Determines if the given type has compile time known bounds. Note
6158 -- that we enter the case statement even in cases where the prefix
6159 -- type does NOT have known bounds, so it is important to guard any
6160 -- attempt to evaluate both bounds with a call to this function.
6162 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
6163 -- This procedure is called when the attribute N has a non-static
6164 -- but compile time known value given by Val. It includes the
6165 -- necessary checks for out of range values.
6167 function Fore_Value
return Nat
;
6168 -- Computes the Fore value for the current attribute prefix, which is
6169 -- known to be a static fixed-point type. Used by Fore and Width.
6171 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean;
6172 -- Determine whether Typ denotes a VAX floating point type
6174 function Mantissa
return Uint
;
6175 -- Returns the Mantissa value for the prefix type
6177 procedure Set_Bounds
;
6178 -- Used for First, Last and Length attributes applied to an array or
6179 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6180 -- and high bound expressions for the index referenced by the attribute
6181 -- designator (i.e. the first index if no expression is present, and the
6182 -- N'th index if the value N is present as an expression). Also used for
6183 -- First and Last of scalar types and for First_Valid and Last_Valid.
6184 -- Static is reset to False if the type or index type is not statically
6187 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
6188 -- Verify that the prefix of a potentially static array attribute
6189 -- satisfies the conditions of 4.9 (14).
6191 -----------------------------------
6192 -- Check_Concurrent_Discriminant --
6193 -----------------------------------
6195 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
6197 -- The concurrent (task or protected) type
6200 if Nkind
(Bound
) = N_Identifier
6201 and then Ekind
(Entity
(Bound
)) = E_Discriminant
6202 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
6204 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
6206 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
6208 -- Find discriminant of original concurrent type, and use
6209 -- its current discriminal, which is the renaming within
6210 -- the task/protected body.
6214 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
6217 end Check_Concurrent_Discriminant
;
6219 -----------------------
6220 -- Check_Expressions --
6221 -----------------------
6223 procedure Check_Expressions
is
6227 while Present
(E
) loop
6228 Check_Non_Static_Context
(E
);
6231 end Check_Expressions
;
6233 ----------------------------------
6234 -- Compile_Time_Known_Attribute --
6235 ----------------------------------
6237 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
6238 T
: constant Entity_Id
:= Etype
(N
);
6241 Fold_Uint
(N
, Val
, False);
6243 -- Check that result is in bounds of the type if it is static
6245 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
6248 elsif Is_Out_Of_Range
(N
, T
) then
6249 Apply_Compile_Time_Constraint_Error
6250 (N
, "value not in range of}??", CE_Range_Check_Failed
);
6252 elsif not Range_Checks_Suppressed
(T
) then
6253 Enable_Range_Check
(N
);
6256 Set_Do_Range_Check
(N
, False);
6258 end Compile_Time_Known_Attribute
;
6260 -------------------------------
6261 -- Compile_Time_Known_Bounds --
6262 -------------------------------
6264 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
6267 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
6269 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
6270 end Compile_Time_Known_Bounds
;
6276 -- Note that the Fore calculation is based on the actual values
6277 -- of the bounds, and does not take into account possible rounding.
6279 function Fore_Value
return Nat
is
6280 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
6281 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
6282 Small
: constant Ureal
:= Small_Value
(P_Type
);
6283 Lo_Real
: constant Ureal
:= Lo
* Small
;
6284 Hi_Real
: constant Ureal
:= Hi
* Small
;
6289 -- Bounds are given in terms of small units, so first compute
6290 -- proper values as reals.
6292 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
6295 -- Loop to compute proper value if more than one digit required
6297 while T
>= Ureal_10
loop
6309 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean is
6312 Is_Floating_Point_Type
(Typ
)
6314 (Float_Format
= 'V' or else Float_Rep
(Typ
) = VAX_Native
);
6321 -- Table of mantissa values accessed by function Computed using
6324 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6326 -- where D is T'Digits (RM83 3.5.7)
6328 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
6370 function Mantissa
return Uint
is
6373 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
6380 procedure Set_Bounds
is
6386 -- For a string literal subtype, we have to construct the bounds.
6387 -- Valid Ada code never applies attributes to string literals, but
6388 -- it is convenient to allow the expander to generate attribute
6389 -- references of this type (e.g. First and Last applied to a string
6392 -- Note that the whole point of the E_String_Literal_Subtype is to
6393 -- avoid this construction of bounds, but the cases in which we
6394 -- have to materialize them are rare enough that we don't worry!
6396 -- The low bound is simply the low bound of the base type. The
6397 -- high bound is computed from the length of the string and this
6400 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
6401 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
6402 Lo_Bound
:= Type_Low_Bound
(Ityp
);
6405 Make_Integer_Literal
(Sloc
(P
),
6407 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
6409 Set_Parent
(Hi_Bound
, P
);
6410 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
6413 -- For non-array case, just get bounds of scalar type
6415 elsif Is_Scalar_Type
(P_Type
) then
6418 -- For a fixed-point type, we must freeze to get the attributes
6419 -- of the fixed-point type set now so we can reference them.
6421 if Is_Fixed_Point_Type
(P_Type
)
6422 and then not Is_Frozen
(Base_Type
(P_Type
))
6423 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
6424 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
6426 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
6429 -- For array case, get type of proper index
6435 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
6438 Indx
:= First_Index
(P_Type
);
6439 for J
in 1 .. Ndim
- 1 loop
6443 -- If no index type, get out (some other error occurred, and
6444 -- we don't have enough information to complete the job!)
6452 Ityp
:= Etype
(Indx
);
6455 -- A discrete range in an index constraint is allowed to be a
6456 -- subtype indication. This is syntactically a pain, but should
6457 -- not propagate to the entity for the corresponding index subtype.
6458 -- After checking that the subtype indication is legal, the range
6459 -- of the subtype indication should be transfered to the entity.
6460 -- The attributes for the bounds should remain the simple retrievals
6461 -- that they are now.
6463 Lo_Bound
:= Type_Low_Bound
(Ityp
);
6464 Hi_Bound
:= Type_High_Bound
(Ityp
);
6466 if not Is_Static_Subtype
(Ityp
) then
6471 -------------------------------
6472 -- Statically_Denotes_Entity --
6473 -------------------------------
6475 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
6479 if not Is_Entity_Name
(N
) then
6486 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
6487 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
6488 end Statically_Denotes_Entity
;
6490 -- Start of processing for Eval_Attribute
6493 -- Acquire first two expressions (at the moment, no attributes take more
6494 -- than two expressions in any case).
6496 if Present
(Expressions
(N
)) then
6497 E1
:= First
(Expressions
(N
));
6504 -- Special processing for Enabled attribute. This attribute has a very
6505 -- special prefix, and the easiest way to avoid lots of special checks
6506 -- to protect this special prefix from causing trouble is to deal with
6507 -- this attribute immediately and be done with it.
6509 if Id
= Attribute_Enabled
then
6511 -- We skip evaluation if the expander is not active. This is not just
6512 -- an optimization. It is of key importance that we not rewrite the
6513 -- attribute in a generic template, since we want to pick up the
6514 -- setting of the check in the instance, and testing expander active
6515 -- is as easy way of doing this as any.
6517 if Expander_Active
then
6519 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
6524 if C
in Predefined_Check_Id
then
6525 R
:= Scope_Suppress
.Suppress
(C
);
6527 R
:= Is_Check_Suppressed
(Empty
, C
);
6531 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
6534 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
6541 -- Special processing for cases where the prefix is an object. For
6542 -- this purpose, a string literal counts as an object (attributes
6543 -- of string literals can only appear in generated code).
6545 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
6547 -- For Component_Size, the prefix is an array object, and we apply
6548 -- the attribute to the type of the object. This is allowed for
6549 -- both unconstrained and constrained arrays, since the bounds
6550 -- have no influence on the value of this attribute.
6552 if Id
= Attribute_Component_Size
then
6553 P_Entity
:= Etype
(P
);
6555 -- For First and Last, the prefix is an array object, and we apply
6556 -- the attribute to the type of the array, but we need a constrained
6557 -- type for this, so we use the actual subtype if available.
6559 elsif Id
= Attribute_First
6563 Id
= Attribute_Length
6566 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
6569 if Present
(AS
) and then Is_Constrained
(AS
) then
6572 -- If we have an unconstrained type we cannot fold
6580 -- For Size, give size of object if available, otherwise we
6581 -- cannot fold Size.
6583 elsif Id
= Attribute_Size
then
6584 if Is_Entity_Name
(P
)
6585 and then Known_Esize
(Entity
(P
))
6587 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
6595 -- For Alignment, give size of object if available, otherwise we
6596 -- cannot fold Alignment.
6598 elsif Id
= Attribute_Alignment
then
6599 if Is_Entity_Name
(P
)
6600 and then Known_Alignment
(Entity
(P
))
6602 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
6610 -- For Lock_Free, we apply the attribute to the type of the object.
6611 -- This is allowed since we have already verified that the type is a
6614 elsif Id
= Attribute_Lock_Free
then
6615 P_Entity
:= Etype
(P
);
6617 -- No other attributes for objects are folded
6624 -- Cases where P is not an object. Cannot do anything if P is
6625 -- not the name of an entity.
6627 elsif not Is_Entity_Name
(P
) then
6631 -- Otherwise get prefix entity
6634 P_Entity
:= Entity
(P
);
6637 -- At this stage P_Entity is the entity to which the attribute
6638 -- is to be applied. This is usually simply the entity of the
6639 -- prefix, except in some cases of attributes for objects, where
6640 -- as described above, we apply the attribute to the object type.
6642 -- First foldable possibility is a scalar or array type (RM 4.9(7))
6643 -- that is not generic (generic types are eliminated by RM 4.9(25)).
6644 -- Note we allow non-static non-generic types at this stage as further
6647 if Is_Type
(P_Entity
)
6648 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
6649 and then (not Is_Generic_Type
(P_Entity
))
6653 -- Second foldable possibility is an array object (RM 4.9(8))
6655 elsif (Ekind
(P_Entity
) = E_Variable
6657 Ekind
(P_Entity
) = E_Constant
)
6658 and then Is_Array_Type
(Etype
(P_Entity
))
6659 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
6661 P_Type
:= Etype
(P_Entity
);
6663 -- If the entity is an array constant with an unconstrained nominal
6664 -- subtype then get the type from the initial value. If the value has
6665 -- been expanded into assignments, there is no expression and the
6666 -- attribute reference remains dynamic.
6668 -- We could do better here and retrieve the type ???
6670 if Ekind
(P_Entity
) = E_Constant
6671 and then not Is_Constrained
(P_Type
)
6673 if No
(Constant_Value
(P_Entity
)) then
6676 P_Type
:= Etype
(Constant_Value
(P_Entity
));
6680 -- Definite must be folded if the prefix is not a generic type,
6681 -- that is to say if we are within an instantiation. Same processing
6682 -- applies to the GNAT attributes Atomic_Always_Lock_Free,
6683 -- Has_Discriminants, Lock_Free, Type_Class, Has_Tagged_Value, and
6684 -- Unconstrained_Array.
6686 elsif (Id
= Attribute_Atomic_Always_Lock_Free
6688 Id
= Attribute_Definite
6690 Id
= Attribute_Has_Access_Values
6692 Id
= Attribute_Has_Discriminants
6694 Id
= Attribute_Has_Tagged_Values
6696 Id
= Attribute_Lock_Free
6698 Id
= Attribute_Type_Class
6700 Id
= Attribute_Unconstrained_Array
6702 Id
= Attribute_Max_Alignment_For_Allocation
)
6703 and then not Is_Generic_Type
(P_Entity
)
6707 -- We can fold 'Size applied to a type if the size is known (as happens
6708 -- for a size from an attribute definition clause). At this stage, this
6709 -- can happen only for types (e.g. record types) for which the size is
6710 -- always non-static. We exclude generic types from consideration (since
6711 -- they have bogus sizes set within templates).
6713 elsif Id
= Attribute_Size
6714 and then Is_Type
(P_Entity
)
6715 and then (not Is_Generic_Type
(P_Entity
))
6716 and then Known_Static_RM_Size
(P_Entity
)
6718 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
6721 -- We can fold 'Alignment applied to a type if the alignment is known
6722 -- (as happens for an alignment from an attribute definition clause).
6723 -- At this stage, this can happen only for types (e.g. record
6724 -- types) for which the size is always non-static. We exclude
6725 -- generic types from consideration (since they have bogus
6726 -- sizes set within templates).
6728 elsif Id
= Attribute_Alignment
6729 and then Is_Type
(P_Entity
)
6730 and then (not Is_Generic_Type
(P_Entity
))
6731 and then Known_Alignment
(P_Entity
)
6733 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
6736 -- If this is an access attribute that is known to fail accessibility
6737 -- check, rewrite accordingly.
6739 elsif Attribute_Name
(N
) = Name_Access
6740 and then Raises_Constraint_Error
(N
)
6743 Make_Raise_Program_Error
(Loc
,
6744 Reason
=> PE_Accessibility_Check_Failed
));
6745 Set_Etype
(N
, C_Type
);
6748 -- No other cases are foldable (they certainly aren't static, and at
6749 -- the moment we don't try to fold any cases other than the ones above).
6756 -- If either attribute or the prefix is Any_Type, then propagate
6757 -- Any_Type to the result and don't do anything else at all.
6759 if P_Type
= Any_Type
6760 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
6761 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
6763 Set_Etype
(N
, Any_Type
);
6767 -- Scalar subtype case. We have not yet enforced the static requirement
6768 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
6769 -- of non-static attribute references (e.g. S'Digits for a non-static
6770 -- floating-point type, which we can compute at compile time).
6772 -- Note: this folding of non-static attributes is not simply a case of
6773 -- optimization. For many of the attributes affected, Gigi cannot handle
6774 -- the attribute and depends on the front end having folded them away.
6776 -- Note: although we don't require staticness at this stage, we do set
6777 -- the Static variable to record the staticness, for easy reference by
6778 -- those attributes where it matters (e.g. Succ and Pred), and also to
6779 -- be used to ensure that non-static folded things are not marked as
6780 -- being static (a check that is done right at the end).
6782 P_Root_Type
:= Root_Type
(P_Type
);
6783 P_Base_Type
:= Base_Type
(P_Type
);
6785 -- If the root type or base type is generic, then we cannot fold. This
6786 -- test is needed because subtypes of generic types are not always
6787 -- marked as being generic themselves (which seems odd???)
6789 if Is_Generic_Type
(P_Root_Type
)
6790 or else Is_Generic_Type
(P_Base_Type
)
6795 if Is_Scalar_Type
(P_Type
) then
6796 Static
:= Is_OK_Static_Subtype
(P_Type
);
6798 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
6799 -- since we can't do anything with unconstrained arrays. In addition,
6800 -- only the First, Last and Length attributes are possibly static.
6802 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
6803 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
6804 -- Unconstrained_Array are again exceptions, because they apply as well
6805 -- to unconstrained types.
6807 -- In addition Component_Size is an exception since it is possibly
6808 -- foldable, even though it is never static, and it does apply to
6809 -- unconstrained arrays. Furthermore, it is essential to fold this
6810 -- in the packed case, since otherwise the value will be incorrect.
6812 elsif Id
= Attribute_Atomic_Always_Lock_Free
6814 Id
= Attribute_Definite
6816 Id
= Attribute_Has_Access_Values
6818 Id
= Attribute_Has_Discriminants
6820 Id
= Attribute_Has_Tagged_Values
6822 Id
= Attribute_Lock_Free
6824 Id
= Attribute_Type_Class
6826 Id
= Attribute_Unconstrained_Array
6828 Id
= Attribute_Component_Size
6832 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
6833 if not Is_Constrained
(P_Type
)
6834 or else (Id
/= Attribute_First
and then
6835 Id
/= Attribute_Last
and then
6836 Id
/= Attribute_Length
)
6842 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
6843 -- scalar case, we hold off on enforcing staticness, since there are
6844 -- cases which we can fold at compile time even though they are not
6845 -- static (e.g. 'Length applied to a static index, even though other
6846 -- non-static indexes make the array type non-static). This is only
6847 -- an optimization, but it falls out essentially free, so why not.
6848 -- Again we compute the variable Static for easy reference later
6849 -- (note that no array attributes are static in Ada 83).
6851 -- We also need to set Static properly for subsequent legality checks
6852 -- which might otherwise accept non-static constants in contexts
6853 -- where they are not legal.
6855 Static
:= Ada_Version
>= Ada_95
6856 and then Statically_Denotes_Entity
(P
);
6862 N
:= First_Index
(P_Type
);
6864 -- The expression is static if the array type is constrained
6865 -- by given bounds, and not by an initial expression. Constant
6866 -- strings are static in any case.
6868 if Root_Type
(P_Type
) /= Standard_String
then
6870 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
6873 while Present
(N
) loop
6874 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
6876 -- If however the index type is generic, or derived from
6877 -- one, attributes cannot be folded.
6879 if Is_Generic_Type
(Root_Type
(Etype
(N
)))
6880 and then Id
/= Attribute_Component_Size
6890 -- Check any expressions that are present. Note that these expressions,
6891 -- depending on the particular attribute type, are either part of the
6892 -- attribute designator, or they are arguments in a case where the
6893 -- attribute reference returns a function. In the latter case, the
6894 -- rule in (RM 4.9(22)) applies and in particular requires the type
6895 -- of the expressions to be scalar in order for the attribute to be
6896 -- considered to be static.
6903 while Present
(E
) loop
6905 -- If expression is not static, then the attribute reference
6906 -- result certainly cannot be static.
6908 if not Is_Static_Expression
(E
) then
6912 -- If the result is not known at compile time, or is not of
6913 -- a scalar type, then the result is definitely not static,
6914 -- so we can quit now.
6916 if not Compile_Time_Known_Value
(E
)
6917 or else not Is_Scalar_Type
(Etype
(E
))
6919 -- An odd special case, if this is a Pos attribute, this
6920 -- is where we need to apply a range check since it does
6921 -- not get done anywhere else.
6923 if Id
= Attribute_Pos
then
6924 if Is_Integer_Type
(Etype
(E
)) then
6925 Apply_Range_Check
(E
, Etype
(N
));
6932 -- If the expression raises a constraint error, then so does
6933 -- the attribute reference. We keep going in this case because
6934 -- we are still interested in whether the attribute reference
6935 -- is static even if it is not static.
6937 elsif Raises_Constraint_Error
(E
) then
6938 Set_Raises_Constraint_Error
(N
);
6944 if Raises_Constraint_Error
(Prefix
(N
)) then
6949 -- Deal with the case of a static attribute reference that raises
6950 -- constraint error. The Raises_Constraint_Error flag will already
6951 -- have been set, and the Static flag shows whether the attribute
6952 -- reference is static. In any case we certainly can't fold such an
6953 -- attribute reference.
6955 -- Note that the rewriting of the attribute node with the constraint
6956 -- error node is essential in this case, because otherwise Gigi might
6957 -- blow up on one of the attributes it never expects to see.
6959 -- The constraint_error node must have the type imposed by the context,
6960 -- to avoid spurious errors in the enclosing expression.
6962 if Raises_Constraint_Error
(N
) then
6964 Make_Raise_Constraint_Error
(Sloc
(N
),
6965 Reason
=> CE_Range_Check_Failed
);
6966 Set_Etype
(CE_Node
, Etype
(N
));
6967 Set_Raises_Constraint_Error
(CE_Node
);
6969 Rewrite
(N
, Relocate_Node
(CE_Node
));
6970 Set_Is_Static_Expression
(N
, Static
);
6974 -- At this point we have a potentially foldable attribute reference.
6975 -- If Static is set, then the attribute reference definitely obeys
6976 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
6977 -- folded. If Static is not set, then the attribute may or may not
6978 -- be foldable, and the individual attribute processing routines
6979 -- test Static as required in cases where it makes a difference.
6981 -- In the case where Static is not set, we do know that all the
6982 -- expressions present are at least known at compile time (we assumed
6983 -- above that if this was not the case, then there was no hope of static
6984 -- evaluation). However, we did not require that the bounds of the
6985 -- prefix type be compile time known, let alone static). That's because
6986 -- there are many attributes that can be computed at compile time on
6987 -- non-static subtypes, even though such references are not static
6990 -- For VAX float, the root type is an IEEE type. So make sure to use the
6991 -- base type instead of the root-type for floating point attributes.
6995 -- Attributes related to Ada 2012 iterators (placeholder ???)
6997 when Attribute_Constant_Indexing |
6998 Attribute_Default_Iterator |
6999 Attribute_Implicit_Dereference |
7000 Attribute_Iterator_Element |
7001 Attribute_Variable_Indexing
=> null;
7003 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7004 -- These were already rejected by the parser. Thus they shouldn't
7007 when Internal_Attribute_Id
=>
7008 raise Program_Error
;
7014 when Attribute_Adjacent
=>
7018 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7025 when Attribute_Aft
=>
7026 Fold_Uint
(N
, Aft_Value
(P_Type
), True);
7032 when Attribute_Alignment
=> Alignment_Block
: declare
7033 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7036 -- Fold if alignment is set and not otherwise
7038 if Known_Alignment
(P_TypeA
) then
7039 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
7041 end Alignment_Block
;
7047 -- Can only be folded in No_Ast_Handler case
7049 when Attribute_AST_Entry
=>
7050 if not Is_AST_Entry
(P_Entity
) then
7052 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
7057 -----------------------------
7058 -- Atomic_Always_Lock_Free --
7059 -----------------------------
7061 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7064 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
7066 V
: constant Entity_Id
:=
7068 (Support_Atomic_Primitives_On_Target
7069 and then Support_Atomic_Primitives
(P_Type
));
7072 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7074 -- Analyze and resolve as boolean. Note that this attribute is a
7075 -- static attribute in GNAT.
7077 Analyze_And_Resolve
(N
, Standard_Boolean
);
7079 end Atomic_Always_Lock_Free
;
7085 -- Bit can never be folded
7087 when Attribute_Bit
=>
7094 -- Body_version can never be static
7096 when Attribute_Body_Version
=>
7103 when Attribute_Ceiling
=>
7105 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7107 --------------------
7108 -- Component_Size --
7109 --------------------
7111 when Attribute_Component_Size
=>
7112 if Known_Static_Component_Size
(P_Type
) then
7113 Fold_Uint
(N
, Component_Size
(P_Type
), False);
7120 when Attribute_Compose
=>
7123 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7130 -- Constrained is never folded for now, there may be cases that
7131 -- could be handled at compile time. To be looked at later.
7133 when Attribute_Constrained
=>
7140 when Attribute_Copy_Sign
=>
7144 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7151 when Attribute_Definite
=>
7152 Rewrite
(N
, New_Occurrence_Of
(
7153 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
7154 Analyze_And_Resolve
(N
, Standard_Boolean
);
7160 when Attribute_Delta
=>
7161 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
7167 when Attribute_Denorm
=>
7169 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), True);
7171 ---------------------
7172 -- Descriptor_Size --
7173 ---------------------
7175 when Attribute_Descriptor_Size
=>
7182 when Attribute_Digits
=>
7183 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
7189 when Attribute_Emax
=>
7191 -- Ada 83 attribute is defined as (RM83 3.5.8)
7193 -- T'Emax = 4 * T'Mantissa
7195 Fold_Uint
(N
, 4 * Mantissa
, True);
7201 when Attribute_Enum_Rep
=>
7203 -- For an enumeration type with a non-standard representation use
7204 -- the Enumeration_Rep field of the proper constant. Note that this
7205 -- will not work for types Character/Wide_[Wide-]Character, since no
7206 -- real entities are created for the enumeration literals, but that
7207 -- does not matter since these two types do not have non-standard
7208 -- representations anyway.
7210 if Is_Enumeration_Type
(P_Type
)
7211 and then Has_Non_Standard_Rep
(P_Type
)
7213 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
7215 -- For enumeration types with standard representations and all
7216 -- other cases (i.e. all integer and modular types), Enum_Rep
7217 -- is equivalent to Pos.
7220 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7227 when Attribute_Enum_Val
=> Enum_Val
: declare
7231 -- We have something like Enum_Type'Enum_Val (23), so search for a
7232 -- corresponding value in the list of Enum_Rep values for the type.
7234 Lit
:= First_Literal
(P_Base_Type
);
7236 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
7237 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
7244 Apply_Compile_Time_Constraint_Error
7245 (N
, "no representation value matches",
7246 CE_Range_Check_Failed
,
7247 Warn
=> not Static
);
7257 when Attribute_Epsilon
=>
7259 -- Ada 83 attribute is defined as (RM83 3.5.8)
7261 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7263 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
7269 when Attribute_Exponent
=>
7271 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7277 when Attribute_First
=> First_Attr
:
7281 if Compile_Time_Known_Value
(Lo_Bound
) then
7282 if Is_Real_Type
(P_Type
) then
7283 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
7285 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7288 -- Replace VAX Float_Type'First with a reference to the temporary
7289 -- which represents the low bound of the type. This transformation
7290 -- is needed since the back end cannot evaluate 'First on VAX.
7292 elsif Is_VAX_Float
(P_Type
)
7293 and then Nkind
(Lo_Bound
) = N_Identifier
7295 Rewrite
(N
, New_Reference_To
(Entity
(Lo_Bound
), Sloc
(N
)));
7299 Check_Concurrent_Discriminant
(Lo_Bound
);
7307 when Attribute_First_Valid
=> First_Valid
:
7309 if Has_Predicates
(P_Type
)
7310 and then Present
(Static_Predicate
(P_Type
))
7313 FirstN
: constant Node_Id
:= First
(Static_Predicate
(P_Type
));
7315 if Nkind
(FirstN
) = N_Range
then
7316 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
7318 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
7324 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7332 when Attribute_Fixed_Value
=>
7339 when Attribute_Floor
=>
7341 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7347 when Attribute_Fore
=>
7348 if Compile_Time_Known_Bounds
(P_Type
) then
7349 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
7356 when Attribute_Fraction
=>
7358 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7360 -----------------------
7361 -- Has_Access_Values --
7362 -----------------------
7364 when Attribute_Has_Access_Values
=>
7365 Rewrite
(N
, New_Occurrence_Of
7366 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
7367 Analyze_And_Resolve
(N
, Standard_Boolean
);
7369 -----------------------
7370 -- Has_Discriminants --
7371 -----------------------
7373 when Attribute_Has_Discriminants
=>
7374 Rewrite
(N
, New_Occurrence_Of
(
7375 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
7376 Analyze_And_Resolve
(N
, Standard_Boolean
);
7378 -----------------------
7379 -- Has_Tagged_Values --
7380 -----------------------
7382 when Attribute_Has_Tagged_Values
=>
7383 Rewrite
(N
, New_Occurrence_Of
7384 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
7385 Analyze_And_Resolve
(N
, Standard_Boolean
);
7391 when Attribute_Identity
=>
7398 -- Image is a scalar attribute, but is never static, because it is
7399 -- not a static function (having a non-scalar argument (RM 4.9(22))
7400 -- However, we can constant-fold the image of an enumeration literal
7401 -- if names are available.
7403 when Attribute_Image
=>
7404 if Is_Entity_Name
(E1
)
7405 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
7406 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
7407 and then not Global_Discard_Names
7410 Lit
: constant Entity_Id
:= Entity
(E1
);
7414 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
7415 Set_Casing
(All_Upper_Case
);
7416 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
7418 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
7419 Analyze_And_Resolve
(N
, Standard_String
);
7420 Set_Is_Static_Expression
(N
, False);
7428 -- Img is a scalar attribute, but is never static, because it is
7429 -- not a static function (having a non-scalar argument (RM 4.9(22))
7431 when Attribute_Img
=>
7438 -- We never try to fold Integer_Value (though perhaps we could???)
7440 when Attribute_Integer_Value
=>
7447 -- Invalid_Value is a scalar attribute that is never static, because
7448 -- the value is by design out of range.
7450 when Attribute_Invalid_Value
=>
7457 when Attribute_Large
=>
7459 -- For fixed-point, we use the identity:
7461 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
7463 if Is_Fixed_Point_Type
(P_Type
) then
7465 Make_Op_Multiply
(Loc
,
7467 Make_Op_Subtract
(Loc
,
7471 Make_Real_Literal
(Loc
, Ureal_2
),
7473 Make_Attribute_Reference
(Loc
,
7475 Attribute_Name
=> Name_Mantissa
)),
7476 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
7479 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
7481 Analyze_And_Resolve
(N
, C_Type
);
7483 -- Floating-point (Ada 83 compatibility)
7486 -- Ada 83 attribute is defined as (RM83 3.5.8)
7488 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
7492 -- T'Emax = 4 * T'Mantissa
7496 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
7504 when Attribute_Lock_Free
=> Lock_Free
: declare
7505 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
7508 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7510 -- Analyze and resolve as boolean. Note that this attribute is a
7511 -- static attribute in GNAT.
7513 Analyze_And_Resolve
(N
, Standard_Boolean
);
7521 when Attribute_Last
=> Last_Attr
:
7525 if Compile_Time_Known_Value
(Hi_Bound
) then
7526 if Is_Real_Type
(P_Type
) then
7527 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
7529 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
7532 -- Replace VAX Float_Type'Last with a reference to the temporary
7533 -- which represents the high bound of the type. This transformation
7534 -- is needed since the back end cannot evaluate 'Last on VAX.
7536 elsif Is_VAX_Float
(P_Type
)
7537 and then Nkind
(Hi_Bound
) = N_Identifier
7539 Rewrite
(N
, New_Reference_To
(Entity
(Hi_Bound
), Sloc
(N
)));
7543 Check_Concurrent_Discriminant
(Hi_Bound
);
7551 when Attribute_Last_Valid
=> Last_Valid
:
7553 if Has_Predicates
(P_Type
)
7554 and then Present
(Static_Predicate
(P_Type
))
7557 LastN
: constant Node_Id
:= Last
(Static_Predicate
(P_Type
));
7559 if Nkind
(LastN
) = N_Range
then
7560 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
7562 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
7568 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
7576 when Attribute_Leading_Part
=>
7579 Eval_Fat
.Leading_Part
7580 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7587 when Attribute_Length
=> Length
: declare
7591 -- If any index type is a formal type, or derived from one, the
7592 -- bounds are not static. Treating them as static can produce
7593 -- spurious warnings or improper constant folding.
7595 Ind
:= First_Index
(P_Type
);
7596 while Present
(Ind
) loop
7597 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
7606 -- For two compile time values, we can compute length
7608 if Compile_Time_Known_Value
(Lo_Bound
)
7609 and then Compile_Time_Known_Value
(Hi_Bound
)
7612 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
7616 -- One more case is where Hi_Bound and Lo_Bound are compile-time
7617 -- comparable, and we can figure out the difference between them.
7620 Diff
: aliased Uint
;
7624 Compile_Time_Compare
7625 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
7628 Fold_Uint
(N
, Uint_1
, False);
7631 Fold_Uint
(N
, Uint_0
, False);
7634 if Diff
/= No_Uint
then
7635 Fold_Uint
(N
, Diff
+ 1, False);
7648 -- Loop_Entry acts as an alias of a constant initialized to the prefix
7649 -- of the said attribute at the point of entry into the related loop. As
7650 -- such, the attribute reference does not need to be evaluated because
7651 -- the prefix is the one that is evaluted.
7653 when Attribute_Loop_Entry
=>
7660 when Attribute_Machine
=>
7664 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
7671 when Attribute_Machine_Emax
=>
7672 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
7678 when Attribute_Machine_Emin
=>
7679 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
7681 ----------------------
7682 -- Machine_Mantissa --
7683 ----------------------
7685 when Attribute_Machine_Mantissa
=>
7686 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
7688 -----------------------
7689 -- Machine_Overflows --
7690 -----------------------
7692 when Attribute_Machine_Overflows
=>
7694 -- Always true for fixed-point
7696 if Is_Fixed_Point_Type
(P_Type
) then
7697 Fold_Uint
(N
, True_Value
, True);
7699 -- Floating point case
7703 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
7711 when Attribute_Machine_Radix
=>
7712 if Is_Fixed_Point_Type
(P_Type
) then
7713 if Is_Decimal_Fixed_Point_Type
(P_Type
)
7714 and then Machine_Radix_10
(P_Type
)
7716 Fold_Uint
(N
, Uint_10
, True);
7718 Fold_Uint
(N
, Uint_2
, True);
7721 -- All floating-point type always have radix 2
7724 Fold_Uint
(N
, Uint_2
, True);
7727 ----------------------
7728 -- Machine_Rounding --
7729 ----------------------
7731 -- Note: for the folding case, it is fine to treat Machine_Rounding
7732 -- exactly the same way as Rounding, since this is one of the allowed
7733 -- behaviors, and performance is not an issue here. It might be a bit
7734 -- better to give the same result as it would give at run time, even
7735 -- though the non-determinism is certainly permitted.
7737 when Attribute_Machine_Rounding
=>
7739 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7741 --------------------
7742 -- Machine_Rounds --
7743 --------------------
7745 when Attribute_Machine_Rounds
=>
7747 -- Always False for fixed-point
7749 if Is_Fixed_Point_Type
(P_Type
) then
7750 Fold_Uint
(N
, False_Value
, True);
7752 -- Else yield proper floating-point result
7756 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
7763 -- Note: Machine_Size is identical to Object_Size
7765 when Attribute_Machine_Size
=> Machine_Size
: declare
7766 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7769 if Known_Esize
(P_TypeA
) then
7770 Fold_Uint
(N
, Esize
(P_TypeA
), True);
7778 when Attribute_Mantissa
=>
7780 -- Fixed-point mantissa
7782 if Is_Fixed_Point_Type
(P_Type
) then
7784 -- Compile time foldable case
7786 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7788 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7790 -- The calculation of the obsolete Ada 83 attribute Mantissa
7791 -- is annoying, because of AI00143, quoted here:
7793 -- !question 84-01-10
7795 -- Consider the model numbers for F:
7797 -- type F is delta 1.0 range -7.0 .. 8.0;
7799 -- The wording requires that F'MANTISSA be the SMALLEST
7800 -- integer number for which each bound of the specified
7801 -- range is either a model number or lies at most small
7802 -- distant from a model number. This means F'MANTISSA
7803 -- is required to be 3 since the range -7.0 .. 7.0 fits
7804 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
7805 -- number, namely, 7. Is this analysis correct? Note that
7806 -- this implies the upper bound of the range is not
7807 -- represented as a model number.
7809 -- !response 84-03-17
7811 -- The analysis is correct. The upper and lower bounds for
7812 -- a fixed point type can lie outside the range of model
7823 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
7824 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
7825 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
7826 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
7828 -- If the Bound is exactly a model number, i.e. a multiple
7829 -- of Small, then we back it off by one to get the integer
7830 -- value that must be representable.
7832 if Small_Value
(P_Type
) * Max_Man
= Bound
then
7833 Max_Man
:= Max_Man
- 1;
7836 -- Now find corresponding size = Mantissa value
7839 while 2 ** Siz
< Max_Man
loop
7843 Fold_Uint
(N
, Siz
, True);
7847 -- The case of dynamic bounds cannot be evaluated at compile
7848 -- time. Instead we use a runtime routine (see Exp_Attr).
7853 -- Floating-point Mantissa
7856 Fold_Uint
(N
, Mantissa
, True);
7863 when Attribute_Max
=> Max
:
7865 if Is_Real_Type
(P_Type
) then
7867 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
7869 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
7873 ----------------------------------
7874 -- Max_Alignment_For_Allocation --
7875 ----------------------------------
7877 -- Max_Alignment_For_Allocation is usually the Alignment. However,
7878 -- arrays are allocated with dope, so we need to take into account both
7879 -- the alignment of the array, which comes from the component alignment,
7880 -- and the alignment of the dope. Also, if the alignment is unknown, we
7881 -- use the max (it's OK to be pessimistic).
7883 when Attribute_Max_Alignment_For_Allocation
=>
7885 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
7887 if Known_Alignment
(P_Type
) and then
7888 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
7890 A
:= Alignment
(P_Type
);
7893 Fold_Uint
(N
, A
, Static
);
7896 ----------------------------------
7897 -- Max_Size_In_Storage_Elements --
7898 ----------------------------------
7900 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
7901 -- Storage_Unit boundary. We can fold any cases for which the size
7902 -- is known by the front end.
7904 when Attribute_Max_Size_In_Storage_Elements
=>
7905 if Known_Esize
(P_Type
) then
7907 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
7908 System_Storage_Unit
,
7912 --------------------
7913 -- Mechanism_Code --
7914 --------------------
7916 when Attribute_Mechanism_Code
=>
7920 Mech
: Mechanism_Type
;
7924 Mech
:= Mechanism
(P_Entity
);
7927 Val
:= UI_To_Int
(Expr_Value
(E1
));
7929 Formal
:= First_Formal
(P_Entity
);
7930 for J
in 1 .. Val
- 1 loop
7931 Next_Formal
(Formal
);
7933 Mech
:= Mechanism
(Formal
);
7937 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
7945 when Attribute_Min
=> Min
:
7947 if Is_Real_Type
(P_Type
) then
7949 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
7952 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
7960 when Attribute_Mod
=>
7962 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
7968 when Attribute_Model
=>
7970 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7976 when Attribute_Model_Emin
=>
7977 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
7983 when Attribute_Model_Epsilon
=>
7984 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
7986 --------------------
7987 -- Model_Mantissa --
7988 --------------------
7990 when Attribute_Model_Mantissa
=>
7991 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
7997 when Attribute_Model_Small
=>
7998 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
8004 when Attribute_Modulus
=>
8005 Fold_Uint
(N
, Modulus
(P_Type
), True);
8007 --------------------
8008 -- Null_Parameter --
8009 --------------------
8011 -- Cannot fold, we know the value sort of, but the whole point is
8012 -- that there is no way to talk about this imaginary value except
8013 -- by using the attribute, so we leave it the way it is.
8015 when Attribute_Null_Parameter
=>
8022 -- The Object_Size attribute for a type returns the Esize of the
8023 -- type and can be folded if this value is known.
8025 when Attribute_Object_Size
=> Object_Size
: declare
8026 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8029 if Known_Esize
(P_TypeA
) then
8030 Fold_Uint
(N
, Esize
(P_TypeA
), True);
8034 ----------------------
8035 -- Overlaps_Storage --
8036 ----------------------
8038 when Attribute_Overlaps_Storage
=>
8041 -------------------------
8042 -- Passed_By_Reference --
8043 -------------------------
8045 -- Scalar types are never passed by reference
8047 when Attribute_Passed_By_Reference
=>
8048 Fold_Uint
(N
, False_Value
, True);
8054 when Attribute_Pos
=>
8055 Fold_Uint
(N
, Expr_Value
(E1
), True);
8061 when Attribute_Pred
=> Pred
:
8063 -- Floating-point case
8065 if Is_Floating_Point_Type
(P_Type
) then
8067 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8071 elsif Is_Fixed_Point_Type
(P_Type
) then
8073 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
8075 -- Modular integer case (wraps)
8077 elsif Is_Modular_Integer_Type
(P_Type
) then
8078 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
8080 -- Other scalar cases
8083 pragma Assert
(Is_Scalar_Type
(P_Type
));
8085 if Is_Enumeration_Type
(P_Type
)
8086 and then Expr_Value
(E1
) =
8087 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8089 Apply_Compile_Time_Constraint_Error
8090 (N
, "Pred of `&''First`",
8091 CE_Overflow_Check_Failed
,
8093 Warn
=> not Static
);
8099 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
8107 -- No processing required, because by this stage, Range has been
8108 -- replaced by First .. Last, so this branch can never be taken.
8110 when Attribute_Range
=>
8111 raise Program_Error
;
8117 when Attribute_Range_Length
=>
8120 -- Can fold if both bounds are compile time known
8122 if Compile_Time_Known_Value
(Hi_Bound
)
8123 and then Compile_Time_Known_Value
(Lo_Bound
)
8127 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
8131 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8132 -- comparable, and we can figure out the difference between them.
8135 Diff
: aliased Uint
;
8139 Compile_Time_Compare
8140 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8143 Fold_Uint
(N
, Uint_1
, False);
8146 Fold_Uint
(N
, Uint_0
, False);
8149 if Diff
/= No_Uint
then
8150 Fold_Uint
(N
, Diff
+ 1, False);
8162 when Attribute_Ref
=>
8163 Fold_Uint
(N
, Expr_Value
(E1
), True);
8169 when Attribute_Remainder
=> Remainder
: declare
8170 X
: constant Ureal
:= Expr_Value_R
(E1
);
8171 Y
: constant Ureal
:= Expr_Value_R
(E2
);
8174 if UR_Is_Zero
(Y
) then
8175 Apply_Compile_Time_Constraint_Error
8176 (N
, "division by zero in Remainder",
8177 CE_Overflow_Check_Failed
,
8178 Warn
=> not Static
);
8184 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
8191 when Attribute_Restriction_Set
=> Restriction_Set
: declare
8193 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
8194 Set_Is_Static_Expression
(N
);
8195 end Restriction_Set
;
8201 when Attribute_Round
=> Round
:
8207 -- First we get the (exact result) in units of small
8209 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
8211 -- Now round that exactly to an integer
8213 Si
:= UR_To_Uint
(Sr
);
8215 -- Finally the result is obtained by converting back to real
8217 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
8224 when Attribute_Rounding
=>
8226 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8232 when Attribute_Safe_Emax
=>
8233 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
8239 when Attribute_Safe_First
=>
8240 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
8246 when Attribute_Safe_Large
=>
8247 if Is_Fixed_Point_Type
(P_Type
) then
8249 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
8251 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8258 when Attribute_Safe_Last
=>
8259 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8265 when Attribute_Safe_Small
=>
8267 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8268 -- for fixed-point, since is the same as Small, but we implement
8269 -- it for backwards compatibility.
8271 if Is_Fixed_Point_Type
(P_Type
) then
8272 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
8274 -- Ada 83 Safe_Small for floating-point cases
8277 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
8284 when Attribute_Same_Storage
=>
8291 when Attribute_Scale
=>
8292 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
8298 when Attribute_Scaling
=>
8302 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8309 when Attribute_Signed_Zeros
=>
8311 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
8317 -- Size attribute returns the RM size. All scalar types can be folded,
8318 -- as well as any types for which the size is known by the front end,
8319 -- including any type for which a size attribute is specified.
8321 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
8322 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8325 if RM_Size
(P_TypeA
) /= Uint_0
then
8329 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
8331 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
8334 -- If a size clause applies, then use the size from it.
8335 -- This is one of the rare cases where we can use the
8336 -- Size_Clause field for a subtype when Has_Size_Clause
8337 -- is False. Consider:
8339 -- type x is range 1 .. 64;
8340 -- for x'size use 12;
8341 -- subtype y is x range 0 .. 3;
8343 -- Here y has a size clause inherited from x, but normally
8344 -- it does not apply, and y'size is 2. However, y'VADS_Size
8345 -- is indeed 12 and not 2.
8348 and then Is_OK_Static_Expression
(Expression
(S
))
8350 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
8352 -- If no size is specified, then we simply use the object
8353 -- size in the VADS_Size case (e.g. Natural'Size is equal
8354 -- to Integer'Size, not one less).
8357 Fold_Uint
(N
, Esize
(P_TypeA
), True);
8361 -- Normal case (Size) in which case we want the RM_Size
8366 Static
and then Is_Discrete_Type
(P_TypeA
));
8375 when Attribute_Small
=>
8377 -- The floating-point case is present only for Ada 83 compatibility.
8378 -- Note that strictly this is an illegal addition, since we are
8379 -- extending an Ada 95 defined attribute, but we anticipate an
8380 -- ARG ruling that will permit this.
8382 if Is_Floating_Point_Type
(P_Type
) then
8384 -- Ada 83 attribute is defined as (RM83 3.5.8)
8386 -- T'Small = 2.0**(-T'Emax - 1)
8390 -- T'Emax = 4 * T'Mantissa
8392 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
8394 -- Normal Ada 95 fixed-point case
8397 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
8404 when Attribute_Stream_Size
=>
8411 when Attribute_Succ
=> Succ
:
8413 -- Floating-point case
8415 if Is_Floating_Point_Type
(P_Type
) then
8417 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8421 elsif Is_Fixed_Point_Type
(P_Type
) then
8422 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
8424 -- Modular integer case (wraps)
8426 elsif Is_Modular_Integer_Type
(P_Type
) then
8427 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
8429 -- Other scalar cases
8432 pragma Assert
(Is_Scalar_Type
(P_Type
));
8434 if Is_Enumeration_Type
(P_Type
)
8435 and then Expr_Value
(E1
) =
8436 Expr_Value
(Type_High_Bound
(P_Base_Type
))
8438 Apply_Compile_Time_Constraint_Error
8439 (N
, "Succ of `&''Last`",
8440 CE_Overflow_Check_Failed
,
8442 Warn
=> not Static
);
8447 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
8456 when Attribute_Truncation
=>
8459 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
8466 when Attribute_Type_Class
=> Type_Class
: declare
8467 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
8471 if Is_Descendent_Of_Address
(Typ
) then
8472 Id
:= RE_Type_Class_Address
;
8474 elsif Is_Enumeration_Type
(Typ
) then
8475 Id
:= RE_Type_Class_Enumeration
;
8477 elsif Is_Integer_Type
(Typ
) then
8478 Id
:= RE_Type_Class_Integer
;
8480 elsif Is_Fixed_Point_Type
(Typ
) then
8481 Id
:= RE_Type_Class_Fixed_Point
;
8483 elsif Is_Floating_Point_Type
(Typ
) then
8484 Id
:= RE_Type_Class_Floating_Point
;
8486 elsif Is_Array_Type
(Typ
) then
8487 Id
:= RE_Type_Class_Array
;
8489 elsif Is_Record_Type
(Typ
) then
8490 Id
:= RE_Type_Class_Record
;
8492 elsif Is_Access_Type
(Typ
) then
8493 Id
:= RE_Type_Class_Access
;
8495 elsif Is_Enumeration_Type
(Typ
) then
8496 Id
:= RE_Type_Class_Enumeration
;
8498 elsif Is_Task_Type
(Typ
) then
8499 Id
:= RE_Type_Class_Task
;
8501 -- We treat protected types like task types. It would make more
8502 -- sense to have another enumeration value, but after all the
8503 -- whole point of this feature is to be exactly DEC compatible,
8504 -- and changing the type Type_Class would not meet this requirement.
8506 elsif Is_Protected_Type
(Typ
) then
8507 Id
:= RE_Type_Class_Task
;
8509 -- Not clear if there are any other possibilities, but if there
8510 -- are, then we will treat them as the address case.
8513 Id
:= RE_Type_Class_Address
;
8516 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
8519 -----------------------
8520 -- Unbiased_Rounding --
8521 -----------------------
8523 when Attribute_Unbiased_Rounding
=>
8526 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
8529 -------------------------
8530 -- Unconstrained_Array --
8531 -------------------------
8533 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
8534 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8537 Rewrite
(N
, New_Occurrence_Of
(
8539 Is_Array_Type
(P_Type
)
8540 and then not Is_Constrained
(Typ
)), Loc
));
8542 -- Analyze and resolve as boolean, note that this attribute is
8543 -- a static attribute in GNAT.
8545 Analyze_And_Resolve
(N
, Standard_Boolean
);
8547 end Unconstrained_Array
;
8549 -- Attribute Update is never static
8555 when Attribute_Update
=>
8562 -- Processing is shared with Size
8568 when Attribute_Val
=> Val
:
8570 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8572 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
8574 Apply_Compile_Time_Constraint_Error
8575 (N
, "Val expression out of range",
8576 CE_Range_Check_Failed
,
8577 Warn
=> not Static
);
8583 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8591 -- The Value_Size attribute for a type returns the RM size of the
8592 -- type. This an always be folded for scalar types, and can also
8593 -- be folded for non-scalar types if the size is set.
8595 when Attribute_Value_Size
=> Value_Size
: declare
8596 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8598 if RM_Size
(P_TypeA
) /= Uint_0
then
8599 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
8607 -- Version can never be static
8609 when Attribute_Version
=>
8616 -- Wide_Image is a scalar attribute, but is never static, because it
8617 -- is not a static function (having a non-scalar argument (RM 4.9(22))
8619 when Attribute_Wide_Image
=>
8622 ---------------------
8623 -- Wide_Wide_Image --
8624 ---------------------
8626 -- Wide_Wide_Image is a scalar attribute but is never static, because it
8627 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
8629 when Attribute_Wide_Wide_Image
=>
8632 ---------------------
8633 -- Wide_Wide_Width --
8634 ---------------------
8636 -- Processing for Wide_Wide_Width is combined with Width
8642 -- Processing for Wide_Width is combined with Width
8648 -- This processing also handles the case of Wide_[Wide_]Width
8650 when Attribute_Width |
8651 Attribute_Wide_Width |
8652 Attribute_Wide_Wide_Width
=> Width
:
8654 if Compile_Time_Known_Bounds
(P_Type
) then
8656 -- Floating-point types
8658 if Is_Floating_Point_Type
(P_Type
) then
8660 -- Width is zero for a null range (RM 3.5 (38))
8662 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
8663 Expr_Value_R
(Type_Low_Bound
(P_Type
))
8665 Fold_Uint
(N
, Uint_0
, True);
8668 -- For floating-point, we have +N.dddE+nnn where length
8669 -- of ddd is determined by type'Digits - 1, but is one
8670 -- if Digits is one (RM 3.5 (33)).
8672 -- nnn is set to 2 for Short_Float and Float (32 bit
8673 -- floats), and 3 for Long_Float and Long_Long_Float.
8674 -- For machines where Long_Long_Float is the IEEE
8675 -- extended precision type, the exponent takes 4 digits.
8679 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
8682 if Esize
(P_Type
) <= 32 then
8684 elsif Esize
(P_Type
) = 64 then
8690 Fold_Uint
(N
, UI_From_Int
(Len
), True);
8694 -- Fixed-point types
8696 elsif Is_Fixed_Point_Type
(P_Type
) then
8698 -- Width is zero for a null range (RM 3.5 (38))
8700 if Expr_Value
(Type_High_Bound
(P_Type
)) <
8701 Expr_Value
(Type_Low_Bound
(P_Type
))
8703 Fold_Uint
(N
, Uint_0
, True);
8705 -- The non-null case depends on the specific real type
8708 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
8711 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
8719 R
: constant Entity_Id
:= Root_Type
(P_Type
);
8720 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
8721 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
8734 -- Width for types derived from Standard.Character
8735 -- and Standard.Wide_[Wide_]Character.
8737 elsif Is_Standard_Character_Type
(P_Type
) then
8740 -- Set W larger if needed
8742 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
8744 -- All wide characters look like Hex_hhhhhhhh
8748 -- No need to compute this more than once!
8753 C
:= Character'Val (J
);
8755 -- Test for all cases where Character'Image
8756 -- yields an image that is longer than three
8757 -- characters. First the cases of Reserved_xxx
8758 -- names (length = 12).
8761 when Reserved_128 | Reserved_129 |
8762 Reserved_132 | Reserved_153
8765 when BS | HT | LF | VT | FF | CR |
8766 SO | SI | EM | FS | GS | RS |
8767 US | RI | MW | ST | PM
8770 when NUL | SOH | STX | ETX | EOT |
8771 ENQ | ACK | BEL | DLE | DC1 |
8772 DC2 | DC3 | DC4 | NAK | SYN |
8773 ETB | CAN | SUB | ESC | DEL |
8774 BPH | NBH | NEL | SSA | ESA |
8775 HTS | HTJ | VTS | PLD | PLU |
8776 SS2 | SS3 | DCS | PU1 | PU2 |
8777 STS | CCH | SPA | EPA | SOS |
8778 SCI | CSI | OSC | APC
8781 when Space
.. Tilde |
8782 No_Break_Space
.. LC_Y_Diaeresis
8784 -- Special case of soft hyphen in Ada 2005
8786 if C
= Character'Val (16#AD#
)
8787 and then Ada_Version
>= Ada_2005
8795 W
:= Int
'Max (W
, Wt
);
8799 -- Width for types derived from Standard.Boolean
8801 elsif R
= Standard_Boolean
then
8808 -- Width for integer types
8810 elsif Is_Integer_Type
(P_Type
) then
8811 T
:= UI_Max
(abs Lo
, abs Hi
);
8819 -- User declared enum type with discard names
8821 elsif Discard_Names
(R
) then
8823 -- If range is null, result is zero, that has already
8824 -- been dealt with, so what we need is the power of ten
8825 -- that accomodates the Pos of the largest value, which
8826 -- is the high bound of the range + one for the space.
8835 -- Only remaining possibility is user declared enum type
8836 -- with normal case of Discard_Names not active.
8839 pragma Assert
(Is_Enumeration_Type
(P_Type
));
8842 L
:= First_Literal
(P_Type
);
8843 while Present
(L
) loop
8845 -- Only pay attention to in range characters
8847 if Lo
<= Enumeration_Pos
(L
)
8848 and then Enumeration_Pos
(L
) <= Hi
8850 -- For Width case, use decoded name
8852 if Id
= Attribute_Width
then
8853 Get_Decoded_Name_String
(Chars
(L
));
8854 Wt
:= Nat
(Name_Len
);
8856 -- For Wide_[Wide_]Width, use encoded name, and
8857 -- then adjust for the encoding.
8860 Get_Name_String
(Chars
(L
));
8862 -- Character literals are always of length 3
8864 if Name_Buffer
(1) = 'Q' then
8867 -- Otherwise loop to adjust for upper/wide chars
8870 Wt
:= Nat
(Name_Len
);
8872 for J
in 1 .. Name_Len
loop
8873 if Name_Buffer
(J
) = 'U' then
8875 elsif Name_Buffer
(J
) = 'W' then
8882 W
:= Int
'Max (W
, Wt
);
8889 Fold_Uint
(N
, UI_From_Int
(W
), True);
8895 -- The following attributes denote functions that cannot be folded
8897 when Attribute_From_Any |
8899 Attribute_TypeCode
=>
8902 -- The following attributes can never be folded, and furthermore we
8903 -- should not even have entered the case statement for any of these.
8904 -- Note that in some cases, the values have already been folded as
8905 -- a result of the processing in Analyze_Attribute.
8907 when Attribute_Abort_Signal |
8910 Attribute_Address_Size |
8911 Attribute_Asm_Input |
8912 Attribute_Asm_Output |
8914 Attribute_Bit_Order |
8915 Attribute_Bit_Position |
8916 Attribute_Callable |
8919 Attribute_Code_Address |
8920 Attribute_Compiler_Version |
8922 Attribute_Default_Bit_Order |
8923 Attribute_Elaborated |
8924 Attribute_Elab_Body |
8925 Attribute_Elab_Spec |
8926 Attribute_Elab_Subp_Body |
8928 Attribute_External_Tag |
8929 Attribute_Fast_Math |
8930 Attribute_First_Bit |
8932 Attribute_Last_Bit |
8933 Attribute_Maximum_Alignment |
8936 Attribute_Partition_ID |
8937 Attribute_Pool_Address |
8938 Attribute_Position |
8939 Attribute_Priority |
8942 Attribute_Scalar_Storage_Order |
8943 Attribute_Simple_Storage_Pool |
8944 Attribute_Storage_Pool |
8945 Attribute_Storage_Size |
8946 Attribute_Storage_Unit |
8947 Attribute_Stub_Type |
8948 Attribute_System_Allocator_Alignment |
8950 Attribute_Target_Name |
8951 Attribute_Terminated |
8952 Attribute_To_Address |
8953 Attribute_Type_Key |
8954 Attribute_UET_Address |
8955 Attribute_Unchecked_Access |
8956 Attribute_Universal_Literal_String |
8957 Attribute_Unrestricted_Access |
8959 Attribute_Valid_Scalars |
8961 Attribute_Wchar_T_Size |
8962 Attribute_Wide_Value |
8963 Attribute_Wide_Wide_Value |
8964 Attribute_Word_Size |
8967 raise Program_Error
;
8970 -- At the end of the case, one more check. If we did a static evaluation
8971 -- so that the result is now a literal, then set Is_Static_Expression
8972 -- in the constant only if the prefix type is a static subtype. For
8973 -- non-static subtypes, the folding is still OK, but not static.
8975 -- An exception is the GNAT attribute Constrained_Array which is
8976 -- defined to be a static attribute in all cases.
8978 if Nkind_In
(N
, N_Integer_Literal
,
8980 N_Character_Literal
,
8982 or else (Is_Entity_Name
(N
)
8983 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
8985 Set_Is_Static_Expression
(N
, Static
);
8987 -- If this is still an attribute reference, then it has not been folded
8988 -- and that means that its expressions are in a non-static context.
8990 elsif Nkind
(N
) = N_Attribute_Reference
then
8993 -- Note: the else case not covered here are odd cases where the
8994 -- processing has transformed the attribute into something other
8995 -- than a constant. Nothing more to do in such cases.
9002 ------------------------------
9003 -- Is_Anonymous_Tagged_Base --
9004 ------------------------------
9006 function Is_Anonymous_Tagged_Base
9013 Anon
= Current_Scope
9014 and then Is_Itype
(Anon
)
9015 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
9016 end Is_Anonymous_Tagged_Base
;
9018 --------------------------------
9019 -- Name_Implies_Lvalue_Prefix --
9020 --------------------------------
9022 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
9023 pragma Assert
(Is_Attribute_Name
(Nam
));
9025 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
9026 end Name_Implies_Lvalue_Prefix
;
9028 -----------------------
9029 -- Resolve_Attribute --
9030 -----------------------
9032 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
9033 Loc
: constant Source_Ptr
:= Sloc
(N
);
9034 P
: constant Node_Id
:= Prefix
(N
);
9035 Aname
: constant Name_Id
:= Attribute_Name
(N
);
9036 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
9037 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9038 Des_Btyp
: Entity_Id
;
9039 Index
: Interp_Index
;
9041 Nom_Subt
: Entity_Id
;
9043 procedure Accessibility_Message
;
9044 -- Error, or warning within an instance, if the static accessibility
9045 -- rules of 3.10.2 are violated.
9047 ---------------------------
9048 -- Accessibility_Message --
9049 ---------------------------
9051 procedure Accessibility_Message
is
9052 Indic
: Node_Id
:= Parent
(Parent
(N
));
9055 -- In an instance, this is a runtime check, but one we
9056 -- know will fail, so generate an appropriate warning.
9058 if In_Instance_Body
then
9060 ("??non-local pointer cannot point to local object", P
);
9062 ("\??Program_Error will be raised at run time", P
);
9064 Make_Raise_Program_Error
(Loc
,
9065 Reason
=> PE_Accessibility_Check_Failed
));
9070 Error_Msg_F
("non-local pointer cannot point to local object", P
);
9072 -- Check for case where we have a missing access definition
9074 if Is_Record_Type
(Current_Scope
)
9076 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
9077 N_Index_Or_Discriminant_Constraint
)
9079 Indic
:= Parent
(Parent
(N
));
9080 while Present
(Indic
)
9081 and then Nkind
(Indic
) /= N_Subtype_Indication
9083 Indic
:= Parent
(Indic
);
9086 if Present
(Indic
) then
9088 ("\use an access definition for" &
9089 " the access discriminant of&",
9090 N
, Entity
(Subtype_Mark
(Indic
)));
9094 end Accessibility_Message
;
9096 -- Start of processing for Resolve_Attribute
9099 -- If error during analysis, no point in continuing, except for array
9100 -- types, where we get better recovery by using unconstrained indexes
9101 -- than nothing at all (see Check_Array_Type).
9104 and then Attr_Id
/= Attribute_First
9105 and then Attr_Id
/= Attribute_Last
9106 and then Attr_Id
/= Attribute_Length
9107 and then Attr_Id
/= Attribute_Range
9112 -- If attribute was universal type, reset to actual type
9114 if Etype
(N
) = Universal_Integer
9115 or else Etype
(N
) = Universal_Real
9120 -- Remaining processing depends on attribute
9128 -- For access attributes, if the prefix denotes an entity, it is
9129 -- interpreted as a name, never as a call. It may be overloaded,
9130 -- in which case resolution uses the profile of the context type.
9131 -- Otherwise prefix must be resolved.
9133 when Attribute_Access
9134 | Attribute_Unchecked_Access
9135 | Attribute_Unrestricted_Access
=>
9139 if Is_Variable
(P
) then
9140 Note_Possible_Modification
(P
, Sure
=> False);
9143 -- The following comes from a query by Adam Beneschan, concerning
9144 -- improper use of universal_access in equality tests involving
9145 -- anonymous access types. Another good reason for 'Ref, but
9146 -- for now disable the test, which breaks several filed tests.
9148 if Ekind
(Typ
) = E_Anonymous_Access_Type
9149 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
9152 Error_Msg_N
("need unique type to resolve 'Access", N
);
9153 Error_Msg_N
("\qualify attribute with some access type", N
);
9156 if Is_Entity_Name
(P
) then
9157 if Is_Overloaded
(P
) then
9158 Get_First_Interp
(P
, Index
, It
);
9159 while Present
(It
.Nam
) loop
9160 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
9161 Set_Entity
(P
, It
.Nam
);
9163 -- The prefix is definitely NOT overloaded anymore at
9164 -- this point, so we reset the Is_Overloaded flag to
9165 -- avoid any confusion when reanalyzing the node.
9167 Set_Is_Overloaded
(P
, False);
9168 Set_Is_Overloaded
(N
, False);
9169 Generate_Reference
(Entity
(P
), P
);
9173 Get_Next_Interp
(Index
, It
);
9176 -- If Prefix is a subprogram name, it is frozen by this
9179 -- If it is a type, there is nothing to resolve.
9180 -- If it is an object, complete its resolution.
9182 elsif Is_Overloadable
(Entity
(P
)) then
9184 -- Avoid insertion of freeze actions in spec expression mode
9186 if not In_Spec_Expression
then
9187 Freeze_Before
(N
, Entity
(P
));
9190 elsif Is_Type
(Entity
(P
)) then
9196 Error_Msg_Name_1
:= Aname
;
9198 if not Is_Entity_Name
(P
) then
9201 elsif Is_Overloadable
(Entity
(P
))
9202 and then Is_Abstract_Subprogram
(Entity
(P
))
9204 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
9205 Set_Etype
(N
, Any_Type
);
9207 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
9208 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
9210 ("prefix of % attribute cannot be enumeration literal",
9214 ("prefix of % attribute cannot be intrinsic", P
);
9217 Set_Etype
(N
, Any_Type
);
9220 -- Assignments, return statements, components of aggregates,
9221 -- generic instantiations will require convention checks if
9222 -- the type is an access to subprogram. Given that there will
9223 -- also be accessibility checks on those, this is where the
9224 -- checks can eventually be centralized ???
9226 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9227 E_Anonymous_Access_Subprogram_Type
,
9228 E_Access_Protected_Subprogram_Type
,
9229 E_Anonymous_Access_Protected_Subprogram_Type
)
9231 -- Deal with convention mismatch
9233 if Convention
(Designated_Type
(Btyp
)) /=
9234 Convention
(Entity
(P
))
9237 ("subprogram & has wrong convention", P
, Entity
(P
));
9239 ("\does not match convention of access type &",
9242 if not Has_Convention_Pragma
(Btyp
) then
9244 ("\probable missing pragma Convention for &",
9249 Check_Subtype_Conformant
9250 (New_Id
=> Entity
(P
),
9251 Old_Id
=> Designated_Type
(Btyp
),
9255 if Attr_Id
= Attribute_Unchecked_Access
then
9256 Error_Msg_Name_1
:= Aname
;
9258 ("attribute% cannot be applied to a subprogram", P
);
9260 elsif Aname
= Name_Unrestricted_Access
then
9261 null; -- Nothing to check
9263 -- Check the static accessibility rule of 3.10.2(32).
9264 -- This rule also applies within the private part of an
9265 -- instantiation. This rule does not apply to anonymous
9266 -- access-to-subprogram types in access parameters.
9268 elsif Attr_Id
= Attribute_Access
9269 and then not In_Instance_Body
9271 (Ekind
(Btyp
) = E_Access_Subprogram_Type
9272 or else Is_Local_Anonymous_Access
(Btyp
))
9273 and then Subprogram_Access_Level
(Entity
(P
)) >
9274 Type_Access_Level
(Btyp
)
9277 ("subprogram must not be deeper than access type", P
);
9279 -- Check the restriction of 3.10.2(32) that disallows the
9280 -- access attribute within a generic body when the ultimate
9281 -- ancestor of the type of the attribute is declared outside
9282 -- of the generic unit and the subprogram is declared within
9283 -- that generic unit. This includes any such attribute that
9284 -- occurs within the body of a generic unit that is a child
9285 -- of the generic unit where the subprogram is declared.
9287 -- The rule also prohibits applying the attribute when the
9288 -- access type is a generic formal access type (since the
9289 -- level of the actual type is not known). This restriction
9290 -- does not apply when the attribute type is an anonymous
9291 -- access-to-subprogram type. Note that this check was
9292 -- revised by AI-229, because the originally Ada 95 rule
9293 -- was too lax. The original rule only applied when the
9294 -- subprogram was declared within the body of the generic,
9295 -- which allowed the possibility of dangling references).
9296 -- The rule was also too strict in some case, in that it
9297 -- didn't permit the access to be declared in the generic
9298 -- spec, whereas the revised rule does (as long as it's not
9301 -- There are a couple of subtleties of the test for applying
9302 -- the check that are worth noting. First, we only apply it
9303 -- when the levels of the subprogram and access type are the
9304 -- same (the case where the subprogram is statically deeper
9305 -- was applied above, and the case where the type is deeper
9306 -- is always safe). Second, we want the check to apply
9307 -- within nested generic bodies and generic child unit
9308 -- bodies, but not to apply to an attribute that appears in
9309 -- the generic unit's specification. This is done by testing
9310 -- that the attribute's innermost enclosing generic body is
9311 -- not the same as the innermost generic body enclosing the
9312 -- generic unit where the subprogram is declared (we don't
9313 -- want the check to apply when the access attribute is in
9314 -- the spec and there's some other generic body enclosing
9315 -- generic). Finally, there's no point applying the check
9316 -- when within an instance, because any violations will have
9317 -- been caught by the compilation of the generic unit.
9319 -- We relax this check in Relaxed_RM_Semantics mode for
9320 -- compatibility with legacy code for use by Ada source
9321 -- code analyzers (e.g. CodePeer).
9323 elsif Attr_Id
= Attribute_Access
9324 and then not Relaxed_RM_Semantics
9325 and then not In_Instance
9326 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
9327 and then Present
(Enclosing_Generic_Body
(N
))
9328 and then Enclosing_Generic_Body
(N
) /=
9329 Enclosing_Generic_Body
9330 (Enclosing_Generic_Unit
(Entity
(P
)))
9331 and then Subprogram_Access_Level
(Entity
(P
)) =
9332 Type_Access_Level
(Btyp
)
9333 and then Ekind
(Btyp
) /=
9334 E_Anonymous_Access_Subprogram_Type
9335 and then Ekind
(Btyp
) /=
9336 E_Anonymous_Access_Protected_Subprogram_Type
9338 -- The attribute type's ultimate ancestor must be
9339 -- declared within the same generic unit as the
9340 -- subprogram is declared. The error message is
9341 -- specialized to say "ancestor" for the case where the
9342 -- access type is not its own ancestor, since saying
9343 -- simply "access type" would be very confusing.
9345 if Enclosing_Generic_Unit
(Entity
(P
)) /=
9346 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
9349 ("''Access attribute not allowed in generic body",
9352 if Root_Type
(Btyp
) = Btyp
then
9355 "access type & is declared outside " &
9356 "generic unit (RM 3.10.2(32))", N
, Btyp
);
9359 ("\because ancestor of " &
9360 "access type & is declared outside " &
9361 "generic unit (RM 3.10.2(32))", N
, Btyp
);
9365 ("\move ''Access to private part, or " &
9366 "(Ada 2005) use anonymous access type instead of &",
9369 -- If the ultimate ancestor of the attribute's type is
9370 -- a formal type, then the attribute is illegal because
9371 -- the actual type might be declared at a higher level.
9372 -- The error message is specialized to say "ancestor"
9373 -- for the case where the access type is not its own
9374 -- ancestor, since saying simply "access type" would be
9377 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
9378 if Root_Type
(Btyp
) = Btyp
then
9380 ("access type must not be a generic formal type",
9384 ("ancestor access type must not be a generic " &
9391 -- If this is a renaming, an inherited operation, or a
9392 -- subprogram instance, use the original entity. This may make
9393 -- the node type-inconsistent, so this transformation can only
9394 -- be done if the node will not be reanalyzed. In particular,
9395 -- if it is within a default expression, the transformation
9396 -- must be delayed until the default subprogram is created for
9397 -- it, when the enclosing subprogram is frozen.
9399 if Is_Entity_Name
(P
)
9400 and then Is_Overloadable
(Entity
(P
))
9401 and then Present
(Alias
(Entity
(P
)))
9402 and then Expander_Active
9405 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
9408 elsif Nkind
(P
) = N_Selected_Component
9409 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
9411 -- Protected operation. If operation is overloaded, must
9412 -- disambiguate. Prefix that denotes protected object itself
9413 -- is resolved with its own type.
9415 if Attr_Id
= Attribute_Unchecked_Access
then
9416 Error_Msg_Name_1
:= Aname
;
9418 ("attribute% cannot be applied to protected operation", P
);
9421 Resolve
(Prefix
(P
));
9422 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
9424 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
9425 -- statically illegal if F is an anonymous access to subprogram.
9427 elsif Nkind
(P
) = N_Explicit_Dereference
9428 and then Is_Entity_Name
(Prefix
(P
))
9429 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
9430 E_Anonymous_Access_Subprogram_Type
9432 Error_Msg_N
("anonymous access to subprogram "
9433 & "has deeper accessibility than any master", P
);
9435 elsif Is_Overloaded
(P
) then
9437 -- Use the designated type of the context to disambiguate
9438 -- Note that this was not strictly conformant to Ada 95,
9439 -- but was the implementation adopted by most Ada 95 compilers.
9440 -- The use of the context type to resolve an Access attribute
9441 -- reference is now mandated in AI-235 for Ada 2005.
9444 Index
: Interp_Index
;
9448 Get_First_Interp
(P
, Index
, It
);
9449 while Present
(It
.Typ
) loop
9450 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
9451 Resolve
(P
, It
.Typ
);
9455 Get_Next_Interp
(Index
, It
);
9462 -- X'Access is illegal if X denotes a constant and the access type
9463 -- is access-to-variable. Same for 'Unchecked_Access. The rule
9464 -- does not apply to 'Unrestricted_Access. If the reference is a
9465 -- default-initialized aggregate component for a self-referential
9466 -- type the reference is legal.
9468 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
9469 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
9470 or else (Is_Record_Type
(Btyp
)
9472 Present
(Corresponding_Remote_Type
(Btyp
)))
9473 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
9474 or else Ekind
(Btyp
)
9475 = E_Anonymous_Access_Protected_Subprogram_Type
9476 or else Is_Access_Constant
(Btyp
)
9477 or else Is_Variable
(P
)
9478 or else Attr_Id
= Attribute_Unrestricted_Access
)
9480 if Is_Entity_Name
(P
)
9481 and then Is_Type
(Entity
(P
))
9483 -- Legality of a self-reference through an access
9484 -- attribute has been verified in Analyze_Access_Attribute.
9488 elsif Comes_From_Source
(N
) then
9489 Error_Msg_F
("access-to-variable designates constant", P
);
9493 Des_Btyp
:= Designated_Type
(Btyp
);
9495 if Ada_Version
>= Ada_2005
9496 and then Is_Incomplete_Type
(Des_Btyp
)
9498 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
9499 -- imported entity, and the non-limited view is visible, make
9500 -- use of it. If it is an incomplete subtype, use the base type
9503 if From_With_Type
(Des_Btyp
)
9504 and then Present
(Non_Limited_View
(Des_Btyp
))
9506 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
9508 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
9509 Des_Btyp
:= Etype
(Des_Btyp
);
9513 if (Attr_Id
= Attribute_Access
9515 Attr_Id
= Attribute_Unchecked_Access
)
9516 and then (Ekind
(Btyp
) = E_General_Access_Type
9517 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
9519 -- Ada 2005 (AI-230): Check the accessibility of anonymous
9520 -- access types for stand-alone objects, record and array
9521 -- components, and return objects. For a component definition
9522 -- the level is the same of the enclosing composite type.
9524 if Ada_Version
>= Ada_2005
9525 and then (Is_Local_Anonymous_Access
(Btyp
)
9527 -- Handle cases where Btyp is the anonymous access
9528 -- type of an Ada 2012 stand-alone object.
9530 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9531 N_Object_Declaration
)
9533 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
9534 and then Attr_Id
= Attribute_Access
9536 -- In an instance, this is a runtime check, but one we
9537 -- know will fail, so generate an appropriate warning.
9539 if In_Instance_Body
then
9541 ("??non-local pointer cannot point to local object", P
);
9543 ("\??Program_Error will be raised at run time", P
);
9545 Make_Raise_Program_Error
(Loc
,
9546 Reason
=> PE_Accessibility_Check_Failed
));
9551 ("non-local pointer cannot point to local object", P
);
9555 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
9557 ("illegal attribute for discriminant-dependent component",
9561 -- Check static matching rule of 3.10.2(27). Nominal subtype
9562 -- of the prefix must statically match the designated type.
9564 Nom_Subt
:= Etype
(P
);
9566 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
9567 Nom_Subt
:= Base_Type
(Nom_Subt
);
9570 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
9572 -- If the attribute is in the context of an access
9573 -- parameter, then the prefix is allowed to be of the
9574 -- class-wide type (by AI-127).
9576 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
9577 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
9578 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
9584 Desig
:= Designated_Type
(Typ
);
9586 if Is_Class_Wide_Type
(Desig
) then
9587 Desig
:= Etype
(Desig
);
9590 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
9595 ("type of prefix: & not compatible",
9598 ("\with &, the expected designated type",
9599 P
, Designated_Type
(Typ
));
9604 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
9606 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
9607 and then Is_Class_Wide_Type
(Nom_Subt
))
9610 ("type of prefix: & is not covered", P
, Nom_Subt
);
9612 ("\by &, the expected designated type" &
9613 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
9616 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
9617 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
9618 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
9619 and then Designated_Type
(Typ
) /= Nom_Subt
9621 Apply_Discriminant_Check
9622 (N
, Etype
(Designated_Type
(Typ
)));
9625 -- Ada 2005 (AI-363): Require static matching when designated
9626 -- type has discriminants and a constrained partial view, since
9627 -- in general objects of such types are mutable, so we can't
9628 -- allow the access value to designate a constrained object
9629 -- (because access values must be assumed to designate mutable
9630 -- objects when designated type does not impose a constraint).
9632 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
9635 elsif Has_Discriminants
(Designated_Type
(Typ
))
9636 and then not Is_Constrained
(Des_Btyp
)
9638 (Ada_Version
< Ada_2005
9640 not Object_Type_Has_Constrained_Partial_View
9641 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
9642 Scop
=> Current_Scope
))
9648 ("object subtype must statically match "
9649 & "designated subtype", P
);
9651 if Is_Entity_Name
(P
)
9652 and then Is_Array_Type
(Designated_Type
(Typ
))
9655 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
9658 ("aliased object has explicit bounds??", D
);
9660 ("\declare without bounds (and with explicit "
9661 & "initialization)??", D
);
9663 ("\for use with unconstrained access??", D
);
9668 -- Check the static accessibility rule of 3.10.2(28). Note that
9669 -- this check is not performed for the case of an anonymous
9670 -- access type, since the access attribute is always legal
9671 -- in such a context.
9673 if Attr_Id
/= Attribute_Unchecked_Access
9674 and then Ekind
(Btyp
) = E_General_Access_Type
9676 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
9678 Accessibility_Message
;
9683 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
9684 E_Anonymous_Access_Protected_Subprogram_Type
)
9686 if Is_Entity_Name
(P
)
9687 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
9689 Error_Msg_F
("context requires a protected subprogram", P
);
9691 -- Check accessibility of protected object against that of the
9692 -- access type, but only on user code, because the expander
9693 -- creates access references for handlers. If the context is an
9694 -- anonymous_access_to_protected, there are no accessibility
9695 -- checks either. Omit check entirely for Unrestricted_Access.
9697 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
9698 and then Comes_From_Source
(N
)
9699 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
9700 and then Attr_Id
/= Attribute_Unrestricted_Access
9702 Accessibility_Message
;
9705 -- AI05-0225: If the context is not an access to protected
9706 -- function, the prefix must be a variable, given that it may
9707 -- be used subsequently in a protected call.
9709 elsif Nkind
(P
) = N_Selected_Component
9710 and then not Is_Variable
(Prefix
(P
))
9711 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
9714 ("target object of access to protected procedure "
9715 & "must be variable", N
);
9717 elsif Is_Entity_Name
(P
) then
9718 Check_Internal_Protected_Use
(N
, Entity
(P
));
9721 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9722 E_Anonymous_Access_Subprogram_Type
)
9723 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
9725 Error_Msg_F
("context requires a non-protected subprogram", P
);
9728 -- The context cannot be a pool-specific type, but this is a
9729 -- legality rule, not a resolution rule, so it must be checked
9730 -- separately, after possibly disambiguation (see AI-245).
9732 if Ekind
(Btyp
) = E_Access_Type
9733 and then Attr_Id
/= Attribute_Unrestricted_Access
9735 Wrong_Type
(N
, Typ
);
9738 -- The context may be a constrained access type (however ill-
9739 -- advised such subtypes might be) so in order to generate a
9740 -- constraint check when needed set the type of the attribute
9741 -- reference to the base type of the context.
9743 Set_Etype
(N
, Btyp
);
9745 -- Check for incorrect atomic/volatile reference (RM C.6(12))
9747 if Attr_Id
/= Attribute_Unrestricted_Access
then
9748 if Is_Atomic_Object
(P
)
9749 and then not Is_Atomic
(Designated_Type
(Typ
))
9752 ("access to atomic object cannot yield access-to-" &
9753 "non-atomic type", P
);
9755 elsif Is_Volatile_Object
(P
)
9756 and then not Is_Volatile
(Designated_Type
(Typ
))
9759 ("access to volatile object cannot yield access-to-" &
9760 "non-volatile type", P
);
9764 if Is_Entity_Name
(P
) then
9765 Set_Address_Taken
(Entity
(P
));
9767 end Access_Attribute
;
9773 -- Deal with resolving the type for Address attribute, overloading
9774 -- is not permitted here, since there is no context to resolve it.
9776 when Attribute_Address | Attribute_Code_Address
=>
9777 Address_Attribute
: begin
9779 -- To be safe, assume that if the address of a variable is taken,
9780 -- it may be modified via this address, so note modification.
9782 if Is_Variable
(P
) then
9783 Note_Possible_Modification
(P
, Sure
=> False);
9786 if Nkind
(P
) in N_Subexpr
9787 and then Is_Overloaded
(P
)
9789 Get_First_Interp
(P
, Index
, It
);
9790 Get_Next_Interp
(Index
, It
);
9792 if Present
(It
.Nam
) then
9793 Error_Msg_Name_1
:= Aname
;
9795 ("prefix of % attribute cannot be overloaded", P
);
9799 if not Is_Entity_Name
(P
)
9800 or else not Is_Overloadable
(Entity
(P
))
9802 if not Is_Task_Type
(Etype
(P
))
9803 or else Nkind
(P
) = N_Explicit_Dereference
9809 -- If this is the name of a derived subprogram, or that of a
9810 -- generic actual, the address is that of the original entity.
9812 if Is_Entity_Name
(P
)
9813 and then Is_Overloadable
(Entity
(P
))
9814 and then Present
(Alias
(Entity
(P
)))
9817 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
9820 if Is_Entity_Name
(P
) then
9821 Set_Address_Taken
(Entity
(P
));
9824 if Nkind
(P
) = N_Slice
then
9826 -- Arr (X .. Y)'address is identical to Arr (X)'address,
9827 -- even if the array is packed and the slice itself is not
9828 -- addressable. Transform the prefix into an indexed component.
9830 -- Note that the transformation is safe only if we know that
9831 -- the slice is non-null. That is because a null slice can have
9832 -- an out of bounds index value.
9834 -- Right now, gigi blows up if given 'Address on a slice as a
9835 -- result of some incorrect freeze nodes generated by the front
9836 -- end, and this covers up that bug in one case, but the bug is
9837 -- likely still there in the cases not handled by this code ???
9839 -- It's not clear what 'Address *should* return for a null
9840 -- slice with out of bounds indexes, this might be worth an ARG
9843 -- One approach would be to do a length check unconditionally,
9844 -- and then do the transformation below unconditionally, but
9845 -- analyze with checks off, avoiding the problem of the out of
9846 -- bounds index. This approach would interpret the address of
9847 -- an out of bounds null slice as being the address where the
9848 -- array element would be if there was one, which is probably
9849 -- as reasonable an interpretation as any ???
9852 Loc
: constant Source_Ptr
:= Sloc
(P
);
9853 D
: constant Node_Id
:= Discrete_Range
(P
);
9857 if Is_Entity_Name
(D
)
9860 (Type_Low_Bound
(Entity
(D
)),
9861 Type_High_Bound
(Entity
(D
)))
9864 Make_Attribute_Reference
(Loc
,
9865 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
9866 Attribute_Name
=> Name_First
);
9868 elsif Nkind
(D
) = N_Range
9869 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
9871 Lo
:= Low_Bound
(D
);
9877 if Present
(Lo
) then
9879 Make_Indexed_Component
(Loc
,
9880 Prefix
=> Relocate_Node
(Prefix
(P
)),
9881 Expressions
=> New_List
(Lo
)));
9883 Analyze_And_Resolve
(P
);
9887 end Address_Attribute
;
9893 -- Prefix of the AST_Entry attribute is an entry name which must
9894 -- not be resolved, since this is definitely not an entry call.
9896 when Attribute_AST_Entry
=>
9903 -- Prefix of Body_Version attribute can be a subprogram name which
9904 -- must not be resolved, since this is not a call.
9906 when Attribute_Body_Version
=>
9913 -- Prefix of Caller attribute is an entry name which must not
9914 -- be resolved, since this is definitely not an entry call.
9916 when Attribute_Caller
=>
9923 -- Shares processing with Address attribute
9929 -- If the prefix of the Count attribute is an entry name it must not
9930 -- be resolved, since this is definitely not an entry call. However,
9931 -- if it is an element of an entry family, the index itself may
9932 -- have to be resolved because it can be a general expression.
9934 when Attribute_Count
=>
9935 if Nkind
(P
) = N_Indexed_Component
9936 and then Is_Entity_Name
(Prefix
(P
))
9939 Indx
: constant Node_Id
:= First
(Expressions
(P
));
9940 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
9942 Resolve
(Indx
, Entry_Index_Type
(Fam
));
9943 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
9951 -- Prefix of the Elaborated attribute is a subprogram name which
9952 -- must not be resolved, since this is definitely not a call. Note
9953 -- that it is a library unit, so it cannot be overloaded here.
9955 when Attribute_Elaborated
=>
9962 -- Prefix of Enabled attribute is a check name, which must be treated
9963 -- specially and not touched by Resolve.
9965 when Attribute_Enabled
=>
9972 -- Do not resolve the prefix of Loop_Entry, instead wait until the
9973 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
9974 -- The delay ensures that any generated checks or temporaries are
9975 -- inserted before the relocated prefix.
9977 when Attribute_Loop_Entry
=>
9980 --------------------
9981 -- Mechanism_Code --
9982 --------------------
9984 -- Prefix of the Mechanism_Code attribute is a function name
9985 -- which must not be resolved. Should we check for overloaded ???
9987 when Attribute_Mechanism_Code
=>
9994 -- Most processing is done in sem_dist, after determining the
9995 -- context type. Node is rewritten as a conversion to a runtime call.
9997 when Attribute_Partition_ID
=>
9998 Process_Partition_Id
(N
);
10005 when Attribute_Pool_Address
=>
10012 -- We replace the Range attribute node with a range expression whose
10013 -- bounds are the 'First and 'Last attributes applied to the same
10014 -- prefix. The reason that we do this transformation here instead of
10015 -- in the expander is that it simplifies other parts of the semantic
10016 -- analysis which assume that the Range has been replaced; thus it
10017 -- must be done even when in semantic-only mode (note that the RM
10018 -- specifically mentions this equivalence, we take care that the
10019 -- prefix is only evaluated once).
10021 when Attribute_Range
=> Range_Attribute
:
10028 if not Is_Entity_Name
(P
)
10029 or else not Is_Type
(Entity
(P
))
10034 Dims
:= Expressions
(N
);
10037 Make_Attribute_Reference
(Loc
,
10039 Duplicate_Subexpr
(P
, Name_Req
=> True),
10040 Attribute_Name
=> Name_Last
,
10041 Expressions
=> Dims
);
10044 Make_Attribute_Reference
(Loc
,
10046 Attribute_Name
=> Name_First
,
10047 Expressions
=> (Dims
));
10049 -- Do not share the dimension indicator, if present. Even
10050 -- though it is a static constant, its source location
10051 -- may be modified when printing expanded code and node
10052 -- sharing will lead to chaos in Sprint.
10054 if Present
(Dims
) then
10055 Set_Expressions
(LB
,
10056 New_List
(New_Copy_Tree
(First
(Dims
))));
10059 -- If the original was marked as Must_Not_Freeze (see code
10060 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10061 -- does not freeze either.
10063 if Must_Not_Freeze
(N
) then
10064 Set_Must_Not_Freeze
(HB
);
10065 Set_Must_Not_Freeze
(LB
);
10066 Set_Must_Not_Freeze
(Prefix
(HB
));
10067 Set_Must_Not_Freeze
(Prefix
(LB
));
10070 if Raises_Constraint_Error
(Prefix
(N
)) then
10072 -- Preserve Sloc of prefix in the new bounds, so that
10073 -- the posted warning can be removed if we are within
10074 -- unreachable code.
10076 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
10077 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
10080 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
10081 Analyze_And_Resolve
(N
, Typ
);
10083 -- Ensure that the expanded range does not have side effects
10085 Force_Evaluation
(LB
);
10086 Force_Evaluation
(HB
);
10088 -- Normally after resolving attribute nodes, Eval_Attribute
10089 -- is called to do any possible static evaluation of the node.
10090 -- However, here since the Range attribute has just been
10091 -- transformed into a range expression it is no longer an
10092 -- attribute node and therefore the call needs to be avoided
10093 -- and is accomplished by simply returning from the procedure.
10096 end Range_Attribute
;
10102 -- We will only come here during the prescan of a spec expression
10103 -- containing a Result attribute. In that case the proper Etype has
10104 -- already been set, and nothing more needs to be done here.
10106 when Attribute_Result
=>
10113 -- Prefix must not be resolved in this case, since it is not a
10114 -- real entity reference. No action of any kind is require!
10116 when Attribute_UET_Address
=>
10119 ----------------------
10120 -- Unchecked_Access --
10121 ----------------------
10123 -- Processing is shared with Access
10125 -------------------------
10126 -- Unrestricted_Access --
10127 -------------------------
10129 -- Processing is shared with Access
10135 -- Apply range check. Note that we did not do this during the
10136 -- analysis phase, since we wanted Eval_Attribute to have a
10137 -- chance at finding an illegal out of range value.
10139 when Attribute_Val
=>
10141 -- Note that we do our own Eval_Attribute call here rather than
10142 -- use the common one, because we need to do processing after
10143 -- the call, as per above comment.
10145 Eval_Attribute
(N
);
10147 -- Eval_Attribute may replace the node with a raise CE, or
10148 -- fold it to a constant. Obviously we only apply a scalar
10149 -- range check if this did not happen!
10151 if Nkind
(N
) = N_Attribute_Reference
10152 and then Attribute_Name
(N
) = Name_Val
10154 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
10163 -- Prefix of Version attribute can be a subprogram name which
10164 -- must not be resolved, since this is not a call.
10166 when Attribute_Version
=>
10169 ----------------------
10170 -- Other Attributes --
10171 ----------------------
10173 -- For other attributes, resolve prefix unless it is a type. If
10174 -- the attribute reference itself is a type name ('Base and 'Class)
10175 -- then this is only legal within a task or protected record.
10178 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
10182 -- If the attribute reference itself is a type name ('Base,
10183 -- 'Class) then this is only legal within a task or protected
10184 -- record. What is this all about ???
10186 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
10187 if Is_Concurrent_Type
(Entity
(N
))
10188 and then In_Open_Scopes
(Entity
(P
))
10193 ("invalid use of subtype name in expression or call", N
);
10197 -- For attributes whose argument may be a string, complete
10198 -- resolution of argument now. This avoids premature expansion
10199 -- (and the creation of transient scopes) before the attribute
10200 -- reference is resolved.
10203 when Attribute_Value
=>
10204 Resolve
(First
(Expressions
(N
)), Standard_String
);
10206 when Attribute_Wide_Value
=>
10207 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
10209 when Attribute_Wide_Wide_Value
=>
10210 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
10212 when others => null;
10215 -- If the prefix of the attribute is a class-wide type then it
10216 -- will be expanded into a dispatching call to a predefined
10217 -- primitive. Therefore we must check for potential violation
10218 -- of such restriction.
10220 if Is_Class_Wide_Type
(Etype
(P
)) then
10221 Check_Restriction
(No_Dispatching_Calls
, N
);
10225 -- Normally the Freezing is done by Resolve but sometimes the Prefix
10226 -- is not resolved, in which case the freezing must be done now.
10228 Freeze_Expression
(P
);
10230 -- Finally perform static evaluation on the attribute reference
10232 Analyze_Dimension
(N
);
10233 Eval_Attribute
(N
);
10234 end Resolve_Attribute
;
10236 --------------------------------
10237 -- Stream_Attribute_Available --
10238 --------------------------------
10240 function Stream_Attribute_Available
10242 Nam
: TSS_Name_Type
;
10243 Partial_View
: Node_Id
:= Empty
) return Boolean
10245 Etyp
: Entity_Id
:= Typ
;
10247 -- Start of processing for Stream_Attribute_Available
10250 -- We need some comments in this body ???
10252 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
10256 if Is_Class_Wide_Type
(Typ
) then
10257 return not Is_Limited_Type
(Typ
)
10258 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
10261 if Nam
= TSS_Stream_Input
10262 and then Is_Abstract_Type
(Typ
)
10263 and then not Is_Class_Wide_Type
(Typ
)
10268 if not (Is_Limited_Type
(Typ
)
10269 or else (Present
(Partial_View
)
10270 and then Is_Limited_Type
(Partial_View
)))
10275 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
10277 if Nam
= TSS_Stream_Input
10278 and then Ada_Version
>= Ada_2005
10279 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
10283 elsif Nam
= TSS_Stream_Output
10284 and then Ada_Version
>= Ada_2005
10285 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
10290 -- Case of Read and Write: check for attribute definition clause that
10291 -- applies to an ancestor type.
10293 while Etype
(Etyp
) /= Etyp
loop
10294 Etyp
:= Etype
(Etyp
);
10296 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
10301 if Ada_Version
< Ada_2005
then
10303 -- In Ada 95 mode, also consider a non-visible definition
10306 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
10309 and then Stream_Attribute_Available
10310 (Btyp
, Nam
, Partial_View
=> Typ
);
10315 end Stream_Attribute_Available
;