1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
29 with Aspects
; use Aspects
;
30 with Atree
; use Atree
;
31 with Casing
; use Casing
;
32 with Checks
; use Checks
;
33 with Debug
; use Debug
;
34 with Einfo
; use Einfo
;
35 with Einfo
.Entities
; use Einfo
.Entities
;
36 with Einfo
.Utils
; use Einfo
.Utils
;
37 with Elists
; use Elists
;
38 with Errout
; use Errout
;
40 with Exp_Dist
; use Exp_Dist
;
41 with Exp_Util
; use Exp_Util
;
42 with Expander
; use Expander
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
45 with Gnatvsn
; use Gnatvsn
;
46 with Itypes
; use Itypes
;
48 with Lib
.Xref
; use Lib
.Xref
;
49 with Nlists
; use Nlists
;
50 with Nmake
; use Nmake
;
52 with Restrict
; use Restrict
;
53 with Rident
; use Rident
;
54 with Rtsfind
; use Rtsfind
;
57 with Sem_Aggr
; use Sem_Aggr
;
58 with Sem_Aux
; use Sem_Aux
;
59 with Sem_Cat
; use Sem_Cat
;
60 with Sem_Ch6
; use Sem_Ch6
;
61 with Sem_Ch8
; use Sem_Ch8
;
62 with Sem_Ch10
; use Sem_Ch10
;
63 with Sem_Dim
; use Sem_Dim
;
64 with Sem_Dist
; use Sem_Dist
;
65 with Sem_Elab
; use Sem_Elab
;
66 with Sem_Elim
; use Sem_Elim
;
67 with Sem_Eval
; use Sem_Eval
;
68 with Sem_Prag
; use Sem_Prag
;
69 with Sem_Res
; use Sem_Res
;
70 with Sem_Type
; use Sem_Type
;
71 with Sem_Util
; use Sem_Util
;
73 with Stand
; use Stand
;
74 with Sinfo
; use Sinfo
;
75 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
76 with Sinfo
.Utils
; use Sinfo
.Utils
;
77 with Sinput
; use Sinput
;
79 with Stringt
; use Stringt
;
80 with Strub
; use Strub
;
82 with Stylesw
; use Stylesw
;
83 with Targparm
; use Targparm
;
84 with Ttypes
; use Ttypes
;
85 with Tbuild
; use Tbuild
;
86 with Uintp
; use Uintp
;
87 with Uname
; use Uname
;
88 with Urealp
; use Urealp
;
89 with Warnsw
; use Warnsw
;
91 with System
.CRC32
; use System
.CRC32
;
93 package body Sem_Attr
is
95 True_Value
: constant Uint
:= Uint_1
;
96 False_Value
: constant Uint
:= Uint_0
;
97 -- Synonyms to be used when these constants are used as Boolean values
99 Bad_Attribute
: exception;
100 -- Exception raised if an error is detected during attribute processing,
101 -- used so that we can abandon the processing so we don't run into
102 -- trouble with cascaded errors.
104 -- The following array is the list of attributes defined in the Ada 83 RM.
105 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
106 -- modes all these attributes are recognized, even if removed in Ada 95.
108 Attribute_83
: constant Attribute_Set
:=
111 Attribute_Alignment |
114 Attribute_Constrained |
121 Attribute_First_Bit |
127 Attribute_Leading_Part |
129 Attribute_Machine_Emax |
130 Attribute_Machine_Emin |
131 Attribute_Machine_Mantissa |
132 Attribute_Machine_Overflows |
133 Attribute_Machine_Radix |
134 Attribute_Machine_Rounds |
140 Attribute_Safe_Emax |
141 Attribute_Safe_Large |
142 Attribute_Safe_Small |
145 Attribute_Storage_Size |
147 Attribute_Terminated |
150 Attribute_Width
=> True,
153 -- The following array is the list of attributes defined in the Ada 2005
154 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
155 -- but in Ada 95 they are considered to be implementation defined.
157 Attribute_05
: constant Attribute_Set
:=
158 (Attribute_Machine_Rounding |
161 Attribute_Stream_Size |
162 Attribute_Wide_Wide_Width
=> True,
165 -- The following array is the list of attributes defined in the Ada 2012
166 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
167 -- and Ada 2005 modes, but are considered to be implementation defined.
169 Attribute_12
: constant Attribute_Set
:=
170 (Attribute_First_Valid |
171 Attribute_Has_Same_Storage |
172 Attribute_Last_Valid |
173 Attribute_Max_Alignment_For_Allocation
=> True,
176 -- The following array is the list of attributes defined in the Ada 2022
177 -- RM which are not defined in Ada 2012. These are recognized in Ada
178 -- 95/2005/2012 modes, but are considered to be implementation defined.
180 Attribute_22
: constant Attribute_Set
:=
181 (Attribute_Enum_Rep |
184 Attribute_Preelaborable_Initialization
=> True,
187 -- The following array contains all attributes that imply a modification
188 -- of their prefixes or result in an access value. Such prefixes can be
189 -- considered as lvalues.
191 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Set
:=
196 Attribute_Unchecked_Access |
197 Attribute_Unrestricted_Access
=> True,
200 -----------------------
201 -- Local_Subprograms --
202 -----------------------
204 procedure Eval_Attribute
(N
: Node_Id
);
205 -- Performs compile time evaluation of attributes where possible, leaving
206 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
207 -- set, and replacing the node with a literal node if the value can be
208 -- computed at compile time. All static attribute references are folded,
209 -- as well as a number of cases of non-static attributes that can always
210 -- be computed at compile time (e.g. floating-point model attributes that
211 -- are applied to non-static subtypes). Of course in such cases, the
212 -- Is_Static_Expression flag will not be set on the resulting literal.
213 -- Note that the only required action of this procedure is to catch the
214 -- static expression cases as described in the RM. Folding of other cases
215 -- is done where convenient, but some additional non-static folding is in
216 -- Expand_N_Attribute_Reference in cases where this is more convenient.
218 function Is_Anonymous_Tagged_Base
220 Typ
: Entity_Id
) return Boolean;
221 -- For derived tagged types that constrain parent discriminants we build
222 -- an anonymous unconstrained base type. We need to recognize the relation
223 -- between the two when analyzing an access attribute for a constrained
224 -- component, before the full declaration for Typ has been analyzed, and
225 -- where therefore the prefix of the attribute does not match the enclosing
228 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean);
229 -- Rewrites node N with an occurrence of either Standard_False or
230 -- Standard_True, depending on the value of the parameter B. The
231 -- result is marked as a static expression.
233 -----------------------
234 -- Analyze_Attribute --
235 -----------------------
237 procedure Analyze_Attribute
(N
: Node_Id
) is
238 Loc
: constant Source_Ptr
:= Sloc
(N
);
239 Aname
: constant Name_Id
:= Attribute_Name
(N
);
240 Exprs
: constant List_Id
:= Expressions
(N
);
241 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
242 P_Old
: constant Node_Id
:= Prefix
(N
);
244 P
: Node_Id
:= P_Old
;
248 P_Type
: Entity_Id
:= Empty
;
249 -- Type of prefix after analysis
251 P_Base_Type
: Entity_Id
:= Empty
;
252 -- Base type of prefix after analysis
254 -----------------------
255 -- Local Subprograms --
256 -----------------------
258 procedure Address_Checks
;
259 -- Semantic checks for valid use of Address attribute. This was made
260 -- a separate routine with the idea of using it for unrestricted access
261 -- which seems like it should follow the same rules, but that turned
262 -- out to be impractical. So now this is only used for Address.
264 procedure Analyze_Access_Attribute
;
265 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
266 -- Internally, Id distinguishes which of the three cases is involved.
268 procedure Analyze_Attribute_Old_Result
269 (Legal
: out Boolean;
270 Spec_Id
: out Entity_Id
);
271 -- Common processing for attributes 'Old and 'Result. The routine checks
272 -- that the attribute appears in a postcondition-like aspect or pragma
273 -- associated with a suitable subprogram or a body. Flag Legal is set
274 -- when the above criteria are met. Spec_Id denotes the entity of the
275 -- subprogram [body] or Empty if the attribute is illegal.
277 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
);
278 -- Common processing for attributes 'Img, 'Image, 'Wide_Image, and
279 -- 'Wide_Wide_Image. The routine checks that the prefix is valid and
280 -- sets the type of the attribute to the one specified by Str_Typ (e.g.
281 -- Standard_String for 'Image and Standard_Wide_String for 'Wide_Image).
283 procedure Analyze_Index_Attribute
284 (Legal
: out Boolean;
285 Spec_Id
: out Entity_Id
);
286 -- Processing for attribute 'Index. It checks that the attribute appears
287 -- in a pre/postcondition-like aspect or pragma associated with an entry
288 -- family. Flag Legal is set when the above criteria are met. Spec_Id
289 -- denotes the entity of the wrapper of the entry family or Empty if
290 -- the attribute is illegal.
292 procedure Bad_Attribute_For_Predicate
;
293 -- Output error message for use of a predicate (First, Last, Range) not
294 -- allowed with a type that has predicates. If the type is a generic
295 -- actual, then the message is a warning, and we generate code to raise
296 -- program error with an appropriate reason. No error message is given
297 -- for internally generated uses of the attributes. This legality rule
298 -- only applies to scalar types.
300 procedure Check_Array_Or_Scalar_Type
;
301 -- Common procedure used by First, Last, Range attribute to check
302 -- that the prefix is a constrained array or scalar type, or a name
303 -- of an array object, and that an argument appears only if appropriate
304 -- (i.e. only in the array case).
306 procedure Check_Array_Type
;
307 -- Common semantic checks for all array attributes. Checks that the
308 -- prefix is a constrained array type or the name of an array object.
309 -- The error message for non-arrays is specialized appropriately.
311 procedure Check_Asm_Attribute
;
312 -- Common semantic checks for Asm_Input and Asm_Output attributes
314 procedure Check_Component
;
315 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
316 -- Position. Checks prefix is an appropriate selected component.
318 procedure Check_Decimal_Fixed_Point_Type
;
319 -- Check that prefix of attribute N is a decimal fixed-point type
321 procedure Check_Dereference
;
322 -- If the prefix of attribute is an object of an access type, then
323 -- introduce an explicit dereference, and adjust P_Type accordingly.
325 procedure Check_Discrete_Type
;
326 -- Verify that prefix of attribute N is a discrete type
329 -- Check that no attribute arguments are present
331 procedure Check_Either_E0_Or_E1
;
332 -- Check that there are zero or one attribute arguments present
335 -- Check that exactly one attribute argument is present
338 -- Check that two attribute arguments are present
340 procedure Check_Enum_Image
(Check_Enumeration_Maps
: Boolean := False);
341 -- Common processing for the Image and Value family of attributes,
342 -- including their Wide and Wide_Wide versions, Enum_Val, Img,
345 -- If the prefix type of an attribute is an enumeration type, set all
346 -- its literals as referenced, since the attribute function can
347 -- indirectly reference any of the literals. Set the referenced flag
348 -- only if the attribute is in the main code unit; otherwise an
349 -- improperly set reference when analyzing an inlined body will lose a
350 -- proper warning on a useless with_clause.
352 -- If Check_Enumeration_Maps is True, then the attribute expansion
353 -- requires enumeration maps, so check whether restriction
354 -- No_Enumeration_Maps is active.
356 procedure Check_First_Last_Valid
;
357 -- Perform all checks for First_Valid and Last_Valid attributes
359 procedure Check_Fixed_Point_Type
;
360 -- Verify that prefix of attribute N is a fixed type
362 procedure Check_Fixed_Point_Type_0
;
363 -- Verify that prefix of attribute N is a fixed type and that
364 -- no attribute expressions are present.
366 procedure Check_Floating_Point_Type
;
367 -- Verify that prefix of attribute N is a float type
369 procedure Check_Floating_Point_Type_0
;
370 -- Verify that prefix of attribute N is a float type and that
371 -- no attribute expressions are present.
373 procedure Check_Floating_Point_Type_1
;
374 -- Verify that prefix of attribute N is a float type and that
375 -- exactly one attribute expression is present.
377 procedure Check_Floating_Point_Type_2
;
378 -- Verify that prefix of attribute N is a float type and that
379 -- two attribute expressions are present.
381 procedure Check_Integer_Type
;
382 -- Verify that prefix of attribute N is an integer type
384 procedure Check_Modular_Integer_Type
;
385 -- Verify that prefix of attribute N is a modular integer type
387 procedure Check_Not_CPP_Type
;
388 -- Check that P (the prefix of the attribute) is not an CPP type
389 -- for which no Ada predefined primitive is available.
391 procedure Check_Not_Incomplete_Type
;
392 -- Check that P (the prefix of the attribute) is not an incomplete
393 -- type or a private type for which no full view has been given.
395 procedure Check_Object_Reference
(P
: Node_Id
);
396 -- Check that P is an object reference
398 procedure Check_PolyORB_Attribute
;
399 -- Validity checking for PolyORB/DSA attribute
401 procedure Check_Program_Unit
;
402 -- Verify that prefix of attribute N is a program unit
404 procedure Check_Real_Type
;
405 -- Verify that prefix of attribute N is fixed or float type
407 procedure Check_Enumeration_Type
;
408 -- Verify that prefix of attribute N is an enumeration type
410 procedure Check_Scalar_Type
;
411 -- Verify that prefix of attribute N is a scalar type
413 procedure Check_Standard_Prefix
;
414 -- Verify that prefix of attribute N is package Standard. Also checks
415 -- that there are no arguments.
417 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
418 -- Validity checking for stream attribute. Nam is the TSS name of the
419 -- corresponding possible defined attribute function (e.g. for the
420 -- Read attribute, Nam will be TSS_Stream_Read).
422 procedure Check_Put_Image_Attribute
;
423 -- Validity checking for Put_Image attribute
425 procedure Check_System_Prefix
;
426 -- Verify that prefix of attribute N is package System
428 procedure Check_Task_Prefix
;
429 -- Verify that prefix of attribute N is a task or task type
431 procedure Check_Type
;
432 -- Verify that the prefix of attribute N is a type
434 procedure Check_Unit_Name
(Nod
: Node_Id
);
435 -- Check that Nod is of the form of a library unit name, i.e that
436 -- it is an identifier, or a selected component whose prefix is
437 -- itself of the form of a library unit name. Note that this is
438 -- quite different from Check_Program_Unit, since it only checks
439 -- the syntactic form of the name, not the semantic identity. This
440 -- is because it is used with attributes (Elab_Body, Elab_Spec and
441 -- Elaborated) which can refer to non-visible unit.
443 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
444 pragma No_Return
(Error_Attr
);
445 procedure Error_Attr
;
446 pragma No_Return
(Error_Attr
);
447 -- Posts error using Error_Msg_N at given node, sets type of attribute
448 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
449 -- semantic processing. The message typically contains a % insertion
450 -- character which is replaced by the attribute name. The call with
451 -- no arguments is used when the caller has already generated the
452 -- required error messages.
454 procedure Error_Attr_P
(Msg
: String; Msg_Cont
: String := "");
455 pragma No_Return
(Error_Attr_P
);
456 -- Like Error_Attr, but error is posted at the start of the prefix. The
457 -- second message Msg_Cont is useful to issue a continuation message
458 -- before raising Bad_Attribute.
460 procedure Legal_Formal_Attribute
;
461 -- Common processing for attributes Definite and Has_Discriminants.
462 -- Checks that prefix is generic indefinite formal type.
464 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
465 -- Common processing for attributes Max_Alignment_For_Allocation and
466 -- Max_Size_In_Storage_Elements.
469 -- Common processing for attributes Max and Min
471 procedure Standard_Attribute
(Val
: Int
);
472 -- Used to process attributes whose prefix is package Standard which
473 -- yield values of type Universal_Integer. The attribute reference
474 -- node is rewritten with an integer literal of the given value which
475 -- is marked as static.
477 procedure Uneval_Old_Msg
;
478 -- Called when Loop_Entry or Old is used in a potentially unevaluated
479 -- expression. Generates appropriate message or warning depending on
480 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
481 -- node in the aspect case).
483 procedure Unexpected_Argument
(En
: Node_Id
);
484 pragma No_Return
(Unexpected_Argument
);
485 -- Signal unexpected attribute argument (En is the argument), and then
486 -- raises Bad_Attribute to avoid any further semantic processing.
488 procedure Validate_Non_Static_Attribute_Function_Call
;
489 -- Called when processing an attribute that is a function call to a
490 -- non-static function, i.e. an attribute function that either takes
491 -- non-scalar arguments or returns a non-scalar result. Verifies that
492 -- such a call does not appear in a preelaborable context.
498 procedure Address_Checks
is
500 -- An Address attribute created by expansion is legal even when it
501 -- applies to other entity-denoting expressions.
503 if not Comes_From_Source
(N
) then
506 -- Address attribute on a protected object self reference is legal
508 elsif Is_Protected_Self_Reference
(P
) then
511 -- Address applied to an entity
513 elsif Is_Entity_Name
(P
) then
515 Ent
: constant Entity_Id
:= Entity
(P
);
518 if Is_Subprogram
(Ent
) then
519 Set_Address_Taken
(Ent
);
521 -- An Address attribute is accepted when generated by the
522 -- compiler for dispatching operation, and an error is
523 -- issued once the subprogram is frozen (to avoid confusing
524 -- errors about implicit uses of Address in the dispatch
525 -- table initialization).
527 if Has_Pragma_Inline_Always
(Entity
(P
))
528 and then Comes_From_Source
(P
)
531 ("prefix of % attribute cannot be Inline_Always "
534 -- It is illegal to apply 'Address to an intrinsic
535 -- subprogram. This is now formalized in AI05-0095.
536 -- In an instance, an attempt to obtain 'Address of an
537 -- intrinsic subprogram (e.g the renaming of a predefined
538 -- operator that is an actual) raises Program_Error.
540 elsif Convention
(Ent
) = Convention_Intrinsic
then
543 Make_Raise_Program_Error
(Loc
,
544 Reason
=> PE_Address_Of_Intrinsic
));
547 Error_Msg_Name_1
:= Aname
;
549 ("cannot take % of intrinsic subprogram", N
);
552 -- Issue an error if prefix denotes an eliminated subprogram
555 Check_For_Eliminated_Subprogram
(P
, Ent
);
558 -- Object or label reference
560 elsif Is_Object_Reference
(P
) or else Ekind
(Ent
) = E_Label
then
561 Set_Address_Taken
(Ent
);
563 -- Deal with No_Implicit_Aliasing restriction
565 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
566 if not Is_Aliased_View
(P
) then
567 Check_Restriction
(No_Implicit_Aliasing
, P
);
569 Check_No_Implicit_Aliasing
(P
);
573 -- If we have an address of an object, and the attribute
574 -- comes from source, then set the object as potentially
575 -- source modified. We do this because the resulting address
576 -- can potentially be used to modify the variable and we
577 -- might not detect this, leading to some junk warnings.
579 Set_Never_Set_In_Source
(Ent
, False);
581 -- Allow Address to be applied to task or protected type,
582 -- returning null address (what is that about???)
584 elsif (Is_Concurrent_Type
(Etype
(Ent
))
585 and then Etype
(Ent
) = Base_Type
(Ent
))
586 or else Ekind
(Ent
) = E_Package
587 or else Is_Generic_Unit
(Ent
)
590 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
592 -- Anything else is illegal
595 Error_Attr
("invalid prefix for % attribute", P
);
601 elsif Is_Object_Reference
(P
) then
604 -- Subprogram called using dot notation
606 elsif Nkind
(P
) = N_Selected_Component
607 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
611 -- What exactly are we allowing here ??? and is this properly
612 -- documented in the sinfo documentation for this node ???
614 elsif Relaxed_RM_Semantics
615 and then Nkind
(P
) = N_Attribute_Reference
619 -- All other non-entity name cases are illegal
622 Error_Attr
("invalid prefix for % attribute", P
);
626 ------------------------------
627 -- Analyze_Access_Attribute --
628 ------------------------------
630 procedure Analyze_Access_Attribute
is
631 Acc_Type
: Entity_Id
;
636 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
637 -- Build an access-to-object type whose designated type is DT,
638 -- and whose Ekind is appropriate to the attribute type. The
639 -- type that is constructed is returned as the result.
641 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
642 -- Build an access to subprogram whose designated type is the type of
643 -- the prefix. If prefix is overloaded, so is the node itself. The
644 -- result is stored in Acc_Type.
646 function OK_Self_Reference
return Boolean;
647 -- An access reference whose prefix is a type can legally appear
648 -- within an aggregate, where it is obtained by expansion of
649 -- a defaulted aggregate. The enclosing aggregate that contains
650 -- the self-referenced is flagged so that the self-reference can
651 -- be expanded into a reference to the target object (see exp_aggr).
653 ------------------------------
654 -- Build_Access_Object_Type --
655 ------------------------------
657 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
658 Typ
: constant Entity_Id
:=
660 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
662 Set_Etype
(Typ
, Typ
);
664 Set_Associated_Node_For_Itype
(Typ
, N
);
665 Set_Directly_Designated_Type
(Typ
, DT
);
667 end Build_Access_Object_Type
;
669 ----------------------------------
670 -- Build_Access_Subprogram_Type --
671 ----------------------------------
673 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
674 Index
: Interp_Index
;
677 procedure Check_Local_Access
(E
: Entity_Id
);
678 -- Deal with possible access to local subprogram. If we have such
679 -- an access, we set a flag to kill all tracked values on any call
680 -- because this access value may be passed around, and any called
681 -- code might use it to access a local procedure which clobbers a
682 -- tracked value. If the scope is a loop or block, indicate that
683 -- value tracking is disabled for the enclosing subprogram.
685 function Get_Convention
(E
: Entity_Id
) return Convention_Id
;
686 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
687 -- Distinguish between access to regular/protected subprograms
689 ------------------------
690 -- Check_Local_Access --
691 ------------------------
693 procedure Check_Local_Access
(E
: Entity_Id
) is
695 if not Is_Library_Level_Entity
(E
) then
696 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
697 Set_Suppress_Value_Tracking_On_Call
698 (Nearest_Dynamic_Scope
(Current_Scope
));
700 end Check_Local_Access
;
706 function Get_Convention
(E
: Entity_Id
) return Convention_Id
is
708 -- Restrict handling by_protected_procedure access subprograms
709 -- to source entities; required to avoid building access to
710 -- subprogram types with convention protected when building
713 if Comes_From_Source
(P
)
714 and then Is_By_Protected_Procedure
(E
)
716 return Convention_Protected
;
718 return Convention
(E
);
726 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
728 if Get_Convention
(E
) = Convention_Protected
then
729 return E_Access_Protected_Subprogram_Type
;
731 return E_Access_Subprogram_Type
;
735 -- Start of processing for Build_Access_Subprogram_Type
738 -- In the case of an access to subprogram, use the name of the
739 -- subprogram itself as the designated type. Type-checking in
740 -- this case compares the signatures of the designated types.
742 -- Note: This fragment of the tree is temporarily malformed
743 -- because the correct tree requires an E_Subprogram_Type entity
744 -- as the designated type. In most cases this designated type is
745 -- later overridden by the semantics with the type imposed by the
746 -- context during the resolution phase. In the specific case of
747 -- the expression Address!(Prim'Unrestricted_Access), used to
748 -- initialize slots of dispatch tables, this work will be done by
749 -- the expander (see Exp_Aggr).
751 -- The reason to temporarily add this kind of node to the tree
752 -- instead of a proper E_Subprogram_Type itype, is the following:
753 -- in case of errors found in the source file we report better
754 -- error messages. For example, instead of generating the
757 -- "expected access to subprogram with profile
758 -- defined at line X"
760 -- we currently generate:
762 -- "expected access to function Z defined at line X"
764 Set_Etype
(N
, Any_Type
);
766 if not Is_Overloaded
(P
) then
767 Check_Local_Access
(Entity
(P
));
769 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
770 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
771 Set_Is_Public
(Acc_Type
, False);
772 Set_Etype
(Acc_Type
, Acc_Type
);
773 Set_Convention
(Acc_Type
, Get_Convention
(Entity
(P
)));
774 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
775 Set_Etype
(N
, Acc_Type
);
776 Freeze_Before
(N
, Acc_Type
);
780 Get_First_Interp
(P
, Index
, It
);
781 while Present
(It
.Nam
) loop
782 Check_Local_Access
(It
.Nam
);
784 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
785 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
786 Set_Is_Public
(Acc_Type
, False);
787 Set_Etype
(Acc_Type
, Acc_Type
);
788 Set_Convention
(Acc_Type
, Get_Convention
(It
.Nam
));
789 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
790 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
791 Freeze_Before
(N
, Acc_Type
);
794 Get_Next_Interp
(Index
, It
);
798 -- Cannot be applied to intrinsic. Looking at the tests above,
799 -- the only way Etype (N) can still be set to Any_Type is if
800 -- Is_Intrinsic_Subprogram was True for some referenced entity.
802 if Etype
(N
) = Any_Type
then
803 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
805 end Build_Access_Subprogram_Type
;
807 ----------------------
808 -- OK_Self_Reference --
809 ----------------------
811 function OK_Self_Reference
return Boolean is
815 -- If N does not come from source, the reference is assumed to be
818 if not Comes_From_Source
(N
) then
825 (Nkind
(Par
) = N_Component_Association
826 or else Nkind
(Par
) in N_Subexpr
)
828 if Nkind
(Par
) in N_Aggregate | N_Extension_Aggregate
then
829 if Etype
(Par
) = Typ
then
830 Set_Has_Self_Reference
(Par
);
832 -- Check the context: the aggregate must be part of the
833 -- initialization of a type or component, or it is the
834 -- resulting expansion in an initialization procedure.
836 if Is_Init_Proc
(Current_Scope
) then
840 while Present
(Par
) loop
841 if Nkind
(Par
) = N_Full_Type_Declaration
then
856 -- No enclosing aggregate, or not a self-reference
859 end OK_Self_Reference
;
861 -- Start of processing for Analyze_Access_Attribute
864 -- Access and Unchecked_Access are illegal in declare_expressions,
865 -- according to the RM. We also make the GNAT Unrestricted_Access
866 -- attribute illegal if it comes from source.
868 if In_Declare_Expr
> 0
869 and then (Attr_Id
/= Attribute_Unrestricted_Access
870 or else Comes_From_Source
(N
))
872 Error_Attr
("% attribute cannot occur in a declare_expression", N
);
877 if Nkind
(P
) = N_Character_Literal
then
879 ("prefix of % attribute cannot be enumeration literal");
882 -- Preserve relevant elaboration-related attributes of the context
883 -- which are no longer available or very expensive to recompute once
884 -- analysis, resolution, and expansion are over.
886 Mark_Elaboration_Attributes
892 -- Save the scenario for later examination by the ABE Processing
895 Record_Elaboration_Scenario
(N
);
897 -- Case of access to subprogram
899 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
900 if Has_Pragma_Inline_Always
(Entity
(P
)) then
902 ("prefix of % attribute cannot be Inline_Always subprogram");
904 elsif Aname
= Name_Unchecked_Access
then
905 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
908 -- Issue an error if the prefix denotes an eliminated subprogram
910 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
912 -- Check for obsolescent subprogram reference
914 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
916 -- Build the appropriate subprogram type
918 Build_Access_Subprogram_Type
(P
);
920 -- For P'Access or P'Unrestricted_Access, where P is a nested
921 -- subprogram, we might be passing P to another subprogram (but we
922 -- don't check that here), which might call P. P could modify
923 -- local variables, so we need to kill current values. It is
924 -- important not to do this for library-level subprograms, because
925 -- Kill_Current_Values is very inefficient in the case of library
926 -- level packages with lots of tagged types.
928 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
931 -- Do not kill values on nodes initializing dispatch tables
932 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
933 -- is currently generated by the expander only for this
934 -- purpose. Done to keep the quality of warnings currently
935 -- generated by the compiler (otherwise any declaration of
936 -- a tagged type cleans constant indications from its scope).
938 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
939 and then (Is_RTE
(Etype
(Parent
(N
)), RE_Prim_Ptr
)
941 Is_RTE
(Etype
(Parent
(N
)), RE_Size_Ptr
))
942 and then Is_Dispatching_Operation
943 (Directly_Designated_Type
(Etype
(N
)))
951 -- In the static elaboration model, treat the attribute reference
952 -- as a subprogram call for elaboration purposes. Suppress this
953 -- treatment under debug flag. In any case, we are all done.
955 if Legacy_Elaboration_Checks
956 and not Dynamic_Elaboration_Checks
957 and not Debug_Flag_Dot_UU
964 -- Component is an operation of a protected type
966 elsif Nkind
(P
) = N_Selected_Component
967 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
969 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
970 Error_Attr_P
("prefix of % attribute must be subprogram");
973 Build_Access_Subprogram_Type
(Selector_Name
(P
));
977 -- Deal with incorrect reference to a type, but note that some
978 -- accesses are allowed: references to the current type instance,
979 -- or in Ada 2005 self-referential pointer in a default-initialized
982 if Is_Entity_Name
(P
) then
985 -- The reference may appear in an aggregate that has been expanded
986 -- into a loop. Locate scope of type definition, if any.
988 Scop
:= Current_Scope
;
989 while Ekind
(Scop
) = E_Loop
loop
990 Scop
:= Scope
(Scop
);
993 if Is_Type
(Typ
) then
995 -- OK if we are within the scope of a limited type
996 -- let's mark the component as having per object constraint
998 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
1000 Set_Entity
(P
, Typ
);
1004 -- A current instance typically appears immediately within
1005 -- the type declaration, but may be nested within an internally
1006 -- generated temporary scope - as for an aggregate of a
1007 -- discriminated component.
1010 or else (In_Open_Scopes
(Typ
)
1011 and then not Comes_From_Source
(Scop
))
1014 Q
: Node_Id
:= Parent
(N
);
1018 and then Nkind
(Q
) /= N_Component_Declaration
1024 Set_Has_Per_Object_Constraint
1025 (Defining_Identifier
(Q
), True);
1029 if Nkind
(P
) = N_Expanded_Name
then
1031 ("current instance prefix must be a direct name", P
);
1034 -- If a current instance attribute appears in a component
1035 -- constraint it must appear alone; other contexts (spec-
1036 -- expressions, within a task body) are not subject to this
1039 if not In_Spec_Expression
1040 and then not Has_Completion
(Scop
)
1042 Nkind
(Parent
(N
)) not in
1043 N_Discriminant_Association |
1044 N_Index_Or_Discriminant_Constraint
1047 ("current instance attribute must appear alone", N
);
1050 if Is_CPP_Class
(Root_Type
(Typ
)) then
1052 ("??current instance unsupported for derivations of "
1053 & "'C'P'P types", N
);
1056 -- OK if we are in initialization procedure for the type
1057 -- in question, in which case the reference to the type
1058 -- is rewritten as a reference to the current object.
1060 elsif Ekind
(Scop
) = E_Procedure
1061 and then Is_Init_Proc
(Scop
)
1062 and then Etype
(First_Formal
(Scop
)) = Typ
1065 Make_Attribute_Reference
(Loc
,
1066 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1067 Attribute_Name
=> Name_Unrestricted_Access
));
1071 -- OK if current task.
1073 elsif Is_Task_Type
(Typ
)
1074 and then In_Open_Scopes
(Typ
)
1078 -- OK if self-reference in an aggregate in Ada 2005, and
1079 -- the reference comes from a copied default expression.
1081 -- Note that we check legality of self-reference even if the
1082 -- expression comes from source, e.g. when a single component
1083 -- association in an aggregate has a box association.
1085 elsif Ada_Version
>= Ada_2005
and then OK_Self_Reference
then
1088 -- OK if reference to current instance of a protected object
1090 elsif Is_Protected_Self_Reference
(P
) then
1093 -- Otherwise we have an error case
1096 Error_Attr
("% attribute cannot be applied to type", P
);
1101 -- If we fall through, we have a normal access to object case
1103 -- Unrestricted_Access is (for now) legal wherever an allocator would
1104 -- be legal, so its Etype is set to E_Allocator. The expected type
1105 -- of the other attributes is a general access type, and therefore
1106 -- we label them with E_Access_Attribute_Type.
1108 if not Is_Overloaded
(P
) then
1109 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
1110 Set_Etype
(N
, Acc_Type
);
1114 Index
: Interp_Index
;
1117 Set_Etype
(N
, Any_Type
);
1118 Get_First_Interp
(P
, Index
, It
);
1119 while Present
(It
.Typ
) loop
1120 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1121 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1122 Get_Next_Interp
(Index
, It
);
1127 -- Special cases when we can find a prefix that is an entity name
1136 if Is_Entity_Name
(PP
) then
1139 -- If we have an access to an object, and the attribute
1140 -- comes from source, then set the object as potentially
1141 -- source modified. We do this because the resulting access
1142 -- pointer can be used to modify the variable, and we might
1143 -- not detect this, leading to some junk warnings.
1145 -- We do this only for source references, since otherwise
1146 -- we can suppress warnings, e.g. from the unrestricted
1147 -- access generated for validity checks in -gnatVa mode.
1149 if Comes_From_Source
(N
) then
1150 Set_Never_Set_In_Source
(Ent
, False);
1153 -- Mark entity as address taken in the case of
1154 -- 'Unrestricted_Access or subprograms, and kill current
1157 if Aname
= Name_Unrestricted_Access
1158 or else Is_Subprogram
(Ent
)
1160 Set_Address_Taken
(Ent
);
1163 Kill_Current_Values
(Ent
);
1166 elsif Nkind
(PP
) in N_Selected_Component | N_Indexed_Component
1175 end Analyze_Access_Attribute
;
1177 ----------------------------------
1178 -- Analyze_Attribute_Old_Result --
1179 ----------------------------------
1181 procedure Analyze_Attribute_Old_Result
1182 (Legal
: out Boolean;
1183 Spec_Id
: out Entity_Id
)
1185 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1186 -- Verify that the attribute appears within pragma Check that mimics
1189 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1190 -- Verify that the attribute appears within a consequence of aspect
1191 -- or pragma Contract_Cases denoted by Prag.
1193 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1194 -- Verify that the attribute appears within the "Ensures" argument of
1195 -- aspect or pragma Test_Case denoted by Prag.
1199 Encl_Nod
: Node_Id
) return Boolean;
1200 -- Subsidiary to Check_Placement_In_XXX. Determine whether arbitrary
1201 -- node Nod is within enclosing node Encl_Nod.
1203 procedure Placement_Error
;
1204 pragma No_Return
(Placement_Error
);
1205 -- Emit a general error when the attributes does not appear in a
1206 -- postcondition-like aspect or pragma, and then raises Bad_Attribute
1207 -- to avoid any further semantic processing.
1209 ------------------------------
1210 -- Check_Placement_In_Check --
1211 ------------------------------
1213 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1214 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1215 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1218 -- The "Name" argument of pragma Check denotes a postcondition
1222 | Name_Postcondition
1227 -- Otherwise the placement of the attribute is illegal
1232 end Check_Placement_In_Check
;
1234 ---------------------------------------
1235 -- Check_Placement_In_Contract_Cases --
1236 ---------------------------------------
1238 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1244 -- Obtain the argument of the aspect or pragma
1246 if Nkind
(Prag
) = N_Aspect_Specification
then
1249 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1252 Cases
:= Expression
(Arg
);
1254 if Present
(Component_Associations
(Cases
)) then
1255 CCase
:= First
(Component_Associations
(Cases
));
1256 while Present
(CCase
) loop
1258 -- Detect whether the attribute appears within the
1259 -- consequence of the current contract case.
1261 if Nkind
(CCase
) = N_Component_Association
1262 and then Is_Within
(N
, Expression
(CCase
))
1271 -- Otherwise aspect or pragma Contract_Cases is either malformed
1272 -- or the attribute does not appear within a consequence.
1275 ("attribute % must appear in the consequence of a contract case",
1277 end Check_Placement_In_Contract_Cases
;
1279 ----------------------------------
1280 -- Check_Placement_In_Test_Case --
1281 ----------------------------------
1283 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1284 Arg
: constant Node_Id
:=
1287 Arg_Nam
=> Name_Ensures
,
1288 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1291 -- Detect whether the attribute appears within the "Ensures"
1292 -- expression of aspect or pragma Test_Case.
1294 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1299 ("attribute % must appear in the ensures expression of a "
1302 end Check_Placement_In_Test_Case
;
1310 Encl_Nod
: Node_Id
) return Boolean
1316 while Present
(Par
) loop
1317 if Par
= Encl_Nod
then
1320 -- Prevent the search from going too far
1322 elsif Is_Body_Or_Package_Declaration
(Par
) then
1326 Par
:= Parent
(Par
);
1332 ---------------------
1333 -- Placement_Error --
1334 ---------------------
1336 procedure Placement_Error
is
1338 if Aname
= Name_Old
then
1339 Error_Attr
("attribute % can only appear in postcondition", P
);
1341 -- Specialize the error message for attribute 'Result
1345 ("attribute % can only appear in postcondition of function",
1348 end Placement_Error
;
1354 Subp_Decl
: Node_Id
;
1356 -- Start of processing for Analyze_Attribute_Old_Result
1359 -- Assume that the attribute is illegal
1364 -- Skip processing during preanalysis of class-wide preconditions and
1365 -- postconditions since at this stage the expression is not installed
1366 -- yet on its definite context.
1368 if Inside_Class_Condition_Preanalysis
then
1371 -- Search for the subprogram that has this class-wide condition;
1372 -- required to avoid reporting spurious errors since the current
1373 -- scope may not be appropriate because the attribute may be
1374 -- referenced from the inner scope of, for example, quantified
1377 -- Although the expression is not installed on its definite
1378 -- context, we know that the subprogram has been placed in the
1379 -- scope stack by Preanalyze_Condition; we also know that it is
1380 -- not a generic subprogram since class-wide pre/postconditions
1381 -- can only be applied for primitive operations of tagged types.
1383 if Is_Subprogram
(Current_Scope
) then
1384 Spec_Id
:= Current_Scope
;
1386 Spec_Id
:= Enclosing_Subprogram
(Current_Scope
);
1389 pragma Assert
(Is_Dispatching_Operation
(Spec_Id
));
1393 -- Traverse the parent chain to find the aspect or pragma where the
1394 -- attribute resides.
1397 while Present
(Prag
) loop
1398 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1401 -- Prevent the search from going too far
1403 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1407 Prag
:= Parent
(Prag
);
1410 -- The attribute is allowed to appear only in postcondition-like
1411 -- aspects or pragmas.
1413 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1414 if Nkind
(Prag
) = N_Aspect_Specification
then
1415 Prag_Nam
:= Chars
(Identifier
(Prag
));
1417 Prag_Nam
:= Pragma_Name
(Prag
);
1420 if Prag_Nam
= Name_Check
then
1421 Check_Placement_In_Check
(Prag
);
1423 elsif Prag_Nam
= Name_Contract_Cases
then
1424 Check_Placement_In_Contract_Cases
(Prag
);
1426 -- Attributes 'Old and 'Result are allowed to appear in
1427 -- consequence of aspect or pragma Exceptional_Cases. We already
1428 -- examined the exception_choice part of contract syntax, so we
1429 -- can accept all remaining occurrences within the pragma.
1431 elsif Prag_Nam
= Name_Exceptional_Cases
then
1434 -- Attribute 'Result is allowed to appear in aspect or pragma
1435 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1437 elsif Prag_Nam
in Name_Depends | Name_Refined_Depends
1438 and then Aname
= Name_Result
1442 -- Attribute 'Result is allowed to appear in aspect
1443 -- Relaxed_Initialization (SPARK RM 6.10).
1445 elsif Prag_Nam
= Name_Relaxed_Initialization
1446 and then Aname
= Name_Result
1450 elsif Prag_Nam
in Name_Post
1452 | Name_Postcondition
1457 elsif Prag_Nam
= Name_Test_Case
then
1458 Check_Placement_In_Test_Case
(Prag
);
1464 -- 'Old attribute reference ok in a _Wrapped_Statements procedure
1466 elsif Nkind
(Prag
) = N_Subprogram_Body
1467 and then Ekind
(Defining_Entity
(Prag
)) in Subprogram_Kind
1468 and then Present
(Wrapped_Statements
(Defining_Entity
(Prag
)))
1472 -- Otherwise the placement of the attribute is illegal
1478 -- Find the related subprogram subject to the aspect or pragma
1480 if Nkind
(Prag
) = N_Aspect_Specification
then
1481 Subp_Decl
:= Parent
(Prag
);
1482 elsif Nkind
(Prag
) = N_Subprogram_Body
then
1485 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1488 -- 'Old objects appear in block and extended return statements as
1489 -- part of the expansion of contract wrappers.
1491 if Nkind
(Subp_Decl
) in N_Block_Statement
1492 | N_Extended_Return_Statement
1494 Subp_Decl
:= Parent
(Parent
(Subp_Decl
));
1497 -- The aspect or pragma where the attribute resides should be
1498 -- associated with a subprogram declaration or a body. If this is not
1499 -- the case, then the aspect or pragma is illegal. Return as analysis
1500 -- cannot be carried out. Note that it is legal to have the aspect
1501 -- appear on a subprogram renaming, when the renamed entity is an
1502 -- attribute reference.
1504 -- Generating C code the internally built nested _postcondition
1505 -- subprograms are inlined; after expanded, inlined aspects are
1506 -- located in the internal block generated by the frontend.
1508 if Nkind
(Subp_Decl
) = N_Block_Statement
1509 and then Modify_Tree_For_C
1510 and then In_Inlined_Body
1514 elsif Nkind
(Subp_Decl
) not in N_Abstract_Subprogram_Declaration
1515 | N_Entry_Declaration
1516 | N_Expression_Function
1517 | N_Full_Type_Declaration
1518 | N_Generic_Subprogram_Declaration
1520 | N_Subprogram_Body_Stub
1521 | N_Subprogram_Declaration
1522 | N_Subprogram_Renaming_Declaration
1527 -- If we get here, then the attribute is legal
1530 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1532 -- When generating C code, nested _postcondition subprograms are
1533 -- inlined by the front end to avoid problems (when unnested) with
1534 -- referenced itypes. Handle that here, since as part of inlining the
1535 -- expander nests subprogram within a dummy procedure named _parent
1536 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1537 -- Hence, in this context, the spec_id of _postconditions is the
1540 if Modify_Tree_For_C
1541 and then Chars
(Spec_Id
) = Name_uParent
1542 and then Chars
(Scope
(Spec_Id
)) = Name_uWrapped_Statements
1544 -- This situation occurs only when analyzing the body-to-inline
1546 pragma Assert
(Inside_A_Generic
);
1548 Spec_Id
:= Scope
(Spec_Id
);
1549 pragma Assert
(Is_Inlined
(Spec_Id
));
1551 end Analyze_Attribute_Old_Result
;
1553 -----------------------------
1554 -- Analyze_Image_Attribute --
1555 -----------------------------
1557 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
) is
1558 procedure Check_Image_Type
(Image_Type
: Entity_Id
);
1559 -- Check that Image_Type is legal as the type of a prefix of 'Image.
1560 -- Legality depends on the Ada language version.
1562 ----------------------
1563 -- Check_Image_Type --
1564 ----------------------
1566 procedure Check_Image_Type
(Image_Type
: Entity_Id
) is
1568 -- Image_Type may be empty in case of another error detected,
1569 -- or if an N_Raise_xxx_Error node is a parent of N.
1571 if Ada_Version
< Ada_2022
1572 and then Present
(Image_Type
)
1573 and then not Is_Scalar_Type
(Image_Type
)
1575 Error_Msg_Ada_2022_Feature
("nonscalar ''Image", Sloc
(P
));
1578 end Check_Image_Type
;
1580 -- Start of processing for Analyze_Image_Attribute
1583 -- AI12-0124: The ARG has adopted the GNAT semantics of 'Img for
1584 -- scalar types, so that the prefix can be an object, a named value,
1585 -- or a type. If the prefix is an object, there is no argument.
1587 if Is_Object_Image
(P
) then
1589 Set_Etype
(N
, Str_Typ
);
1590 Check_Image_Type
(Etype
(P
));
1592 if Attr_Id
/= Attribute_Img
then
1593 Error_Msg_Ada_2012_Feature
("|Object''Image", Sloc
(P
));
1597 Set_Etype
(N
, Str_Typ
);
1599 pragma Assert
(Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)));
1601 if Ekind
(Entity
(P
)) = E_Incomplete_Type
1602 and then Present
(Full_View
(Entity
(P
)))
1604 P_Type
:= Full_View
(Entity
(P
));
1605 P_Base_Type
:= Base_Type
(P_Type
);
1606 Set_Entity
(P
, P_Type
);
1609 Check_Image_Type
(P_Type
);
1610 Resolve
(E1
, P_Base_Type
);
1611 Validate_Non_Static_Attribute_Function_Call
;
1614 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
1616 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
1617 -- to avoid giving a duplicate message for when Image attributes
1618 -- applied to object references get expanded into type-based Image
1621 if Restriction_Check_Required
(No_Fixed_IO
)
1622 and then Comes_From_Source
(N
)
1623 and then Is_Fixed_Point_Type
(P_Type
)
1625 Check_Restriction
(No_Fixed_IO
, P
);
1627 end Analyze_Image_Attribute
;
1629 -----------------------------
1630 -- Analyze_Index_Attribute --
1631 -----------------------------
1633 procedure Analyze_Index_Attribute
1634 (Legal
: out Boolean;
1635 Spec_Id
: out Entity_Id
)
1637 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1638 -- Verify that the attribute appears within pragma Check that mimics
1641 procedure Placement_Error
;
1642 pragma No_Return
(Placement_Error
);
1643 -- Emit a general error when the attributes does not appear in a
1644 -- precondition or postcondition aspect or pragma, and then raises
1645 -- Bad_Attribute to avoid any further semantic processing.
1647 ------------------------------
1648 -- Check_Placement_In_Check --
1649 ------------------------------
1651 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1652 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1653 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1656 -- The "Name" argument of pragma Check denotes a precondition or
1660 | Name_Postcondition
1667 -- Otherwise the placement of the attribute is illegal
1672 end Check_Placement_In_Check
;
1674 ---------------------
1675 -- Placement_Error --
1676 ---------------------
1678 procedure Placement_Error
is
1681 ("attribute % can only appear in pre- or postcondition", P
);
1682 end Placement_Error
;
1688 Subp_Decl
: Node_Id
;
1690 -- Start of processing for Analyze_Index_Attribute
1693 -- Assume that the attribute is illegal
1698 -- Skip processing during preanalysis of class-wide preconditions and
1699 -- postconditions since at this stage the expression is not installed
1700 -- yet on its definite context.
1702 if Inside_Class_Condition_Preanalysis
then
1704 Spec_Id
:= Current_Scope
;
1708 -- Traverse the parent chain to find the aspect or pragma where the
1709 -- attribute resides.
1712 while Present
(Prag
) loop
1713 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1716 -- Prevent the search from going too far
1718 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1722 Prag
:= Parent
(Prag
);
1725 -- The attribute is allowed to appear only in precondition and
1726 -- postcondition-like aspects or pragmas.
1728 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1729 if Nkind
(Prag
) = N_Aspect_Specification
then
1730 Prag_Nam
:= Chars
(Identifier
(Prag
));
1732 Prag_Nam
:= Pragma_Name
(Prag
);
1735 if Prag_Nam
= Name_Check
then
1736 Check_Placement_In_Check
(Prag
);
1738 elsif Prag_Nam
in Name_Post
1739 | Name_Postcondition
1750 -- Otherwise the placement of the attribute is illegal
1756 -- Find the related subprogram subject to the aspect or pragma
1758 if Nkind
(Prag
) = N_Aspect_Specification
then
1759 Subp_Decl
:= Parent
(Prag
);
1761 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1764 -- The aspect or pragma where the attribute resides should be
1765 -- associated with a subprogram declaration or a body since the
1766 -- analysis of pre-/postconditions of entry and entry families is
1767 -- performed in their wrapper subprogram. If this is not the case,
1768 -- then the aspect or pragma is illegal and no further analysis is
1771 if Nkind
(Subp_Decl
) not in N_Subprogram_Body
1772 | N_Subprogram_Declaration
1777 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1779 -- If we get here and Spec_Id denotes the entity of the entry wrapper
1780 -- (or the postcondition procedure of the entry wrapper) then the
1781 -- attribute is legal.
1783 if Is_Entry_Wrapper
(Spec_Id
) then
1786 elsif Chars
(Spec_Id
) = Name_uWrapped_Statements
1787 and then Is_Entry_Wrapper
(Scope
(Spec_Id
))
1789 Spec_Id
:= Scope
(Spec_Id
);
1792 -- Otherwise the attribute is illegal and we return Empty
1797 end Analyze_Index_Attribute
;
1799 ---------------------------------
1800 -- Bad_Attribute_For_Predicate --
1801 ---------------------------------
1803 procedure Bad_Attribute_For_Predicate
is
1805 if Is_Scalar_Type
(P_Type
)
1806 and then Comes_From_Source
(N
)
1808 Error_Msg_Name_1
:= Aname
;
1809 Bad_Predicated_Subtype_Use
1810 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1812 end Bad_Attribute_For_Predicate
;
1814 --------------------------------
1815 -- Check_Array_Or_Scalar_Type --
1816 --------------------------------
1818 procedure Check_Array_Or_Scalar_Type
is
1819 function In_Aspect_Specification
return Boolean;
1820 -- A current instance of a type in an aspect specification is an
1821 -- object and not a type, and therefore cannot be of a scalar type
1822 -- in the prefix of one of the array attributes if the attribute
1823 -- reference is part of an aspect expression.
1825 -----------------------------
1826 -- In_Aspect_Specification --
1827 -----------------------------
1829 function In_Aspect_Specification
return Boolean is
1834 while Present
(P
) loop
1835 if Nkind
(P
) = N_Aspect_Specification
then
1836 return P_Type
= Entity
(P
);
1838 elsif Nkind
(P
) in N_Declaration
then
1846 end In_Aspect_Specification
;
1852 -- Start of processing for Check_Array_Or_Scalar_Type
1855 -- Case of string literal or string literal subtype. These cases
1856 -- cannot arise from legal Ada code, but the expander is allowed
1857 -- to generate them. They require special handling because string
1858 -- literal subtypes do not have standard bounds (the whole idea
1859 -- of these subtypes is to avoid having to generate the bounds)
1861 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1862 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1867 elsif Is_Scalar_Type
(P_Type
) then
1870 if Present
(E1
) then
1871 Error_Attr
("invalid argument in % attribute", E1
);
1873 elsif In_Aspect_Specification
then
1875 ("prefix of % attribute cannot be the current instance of a "
1876 & "scalar type", P
);
1879 Set_Etype
(N
, P_Base_Type
);
1883 -- The following is a special test to allow 'First to apply to
1884 -- private scalar types if the attribute comes from generated
1885 -- code. This occurs in the case of Normalize_Scalars code.
1887 elsif Is_Private_Type
(P_Type
)
1888 and then Present
(Full_View
(P_Type
))
1889 and then Is_Scalar_Type
(Full_View
(P_Type
))
1890 and then not Comes_From_Source
(N
)
1892 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1894 -- Array types other than string literal subtypes handled above
1899 -- We know prefix is an array type, or the name of an array
1900 -- object, and that the expression, if present, is static
1901 -- and within the range of the dimensions of the type.
1903 pragma Assert
(Is_Array_Type
(P_Type
));
1904 Index
:= First_Index
(P_Base_Type
);
1908 -- First dimension assumed
1910 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1914 Udims
: constant Uint
:= Expr_Value
(E1
);
1915 Dims
: constant Int
:= UI_To_Int
(Udims
);
1917 for J
in 1 .. Dims
- 1 loop
1922 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1925 end Check_Array_Or_Scalar_Type
;
1927 ----------------------
1928 -- Check_Array_Type --
1929 ----------------------
1931 procedure Check_Array_Type
is
1933 -- Dimension number for array attributes
1936 -- If the type is a string literal type, then this must be generated
1937 -- internally, and no further check is required on its legality.
1939 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1942 -- If the type is a composite, it is an illegal aggregate, no point
1945 elsif P_Type
= Any_Composite
then
1946 raise Bad_Attribute
;
1949 -- Normal case of array type or subtype. Note that if the
1950 -- prefix is a current instance of a type declaration it
1951 -- appears within an aspect specification and is legal.
1953 Check_Either_E0_Or_E1
;
1956 if Is_Array_Type
(P_Type
) then
1957 if not Is_Constrained
(P_Type
)
1958 and then Is_Entity_Name
(P
)
1959 and then Is_Type
(Entity
(P
))
1960 and then not Is_Current_Instance
(P
)
1962 -- Note: we do not call Error_Attr here, since we prefer to
1963 -- continue, using the relevant index type of the array,
1964 -- even though it is unconstrained. This gives better error
1965 -- recovery behavior.
1967 Error_Msg_Name_1
:= Aname
;
1969 ("prefix for % attribute must be constrained array", P
);
1972 -- The attribute reference freezes the type, and thus the
1973 -- component type, even if the attribute may not depend on the
1974 -- component. Diagnose arrays with incomplete components now.
1975 -- If the prefix is an access to array, this does not freeze
1976 -- the designated type.
1978 if Nkind
(P
) /= N_Explicit_Dereference
then
1979 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1982 D
:= Number_Dimensions
(P_Type
);
1985 if Is_Private_Type
(P_Type
) then
1986 Error_Attr_P
("prefix for % attribute may not be private type");
1988 elsif Is_Access_Type
(P_Type
)
1989 and then Is_Array_Type
(Designated_Type
(P_Type
))
1990 and then Is_Entity_Name
(P
)
1991 and then Is_Type
(Entity
(P
))
1993 Error_Attr_P
("prefix of % attribute cannot be access type");
1995 elsif Attr_Id
= Attribute_First
1997 Attr_Id
= Attribute_Last
1999 Error_Attr
("invalid prefix for % attribute", P
);
2002 Error_Attr_P
("prefix for % attribute must be array");
2006 if Present
(E1
) then
2007 Resolve
(E1
, Any_Integer
);
2008 Set_Etype
(E1
, Standard_Integer
);
2010 if not Is_OK_Static_Expression
(E1
)
2011 or else Raises_Constraint_Error
(E1
)
2013 Flag_Non_Static_Expr
2014 ("expression for dimension must be static!", E1
);
2019 Value
: constant Uint
:= Expr_Value
(E1
);
2022 if Value
> D
or else Value
< 1 then
2023 Error_Attr
("invalid dimension number for array type", E1
);
2026 -- Replace the static value to simplify the tree for gigi
2027 Fold_Uint
(E1
, Value
, True);
2032 if (Style_Check
and Style_Check_Array_Attribute_Index
)
2033 and then Comes_From_Source
(N
)
2035 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
2037 end Check_Array_Type
;
2039 -------------------------
2040 -- Check_Asm_Attribute --
2041 -------------------------
2043 procedure Check_Asm_Attribute
is
2048 -- Check first argument is static string expression
2050 Analyze_And_Resolve
(E1
, Standard_String
);
2052 if Etype
(E1
) = Any_Type
then
2055 elsif not Is_OK_Static_Expression
(E1
) then
2056 Flag_Non_Static_Expr
2057 ("constraint argument must be static string expression!", E1
);
2061 -- Check second argument is right type
2063 Analyze_And_Resolve
(E2
, Entity
(P
));
2065 -- Note: that is all we need to do, we don't need to check
2066 -- that it appears in a correct context. The Ada type system
2067 -- will do that for us.
2069 end Check_Asm_Attribute
;
2071 ---------------------
2072 -- Check_Component --
2073 ---------------------
2075 procedure Check_Component
is
2079 if Nkind
(P
) /= N_Selected_Component
2081 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
2083 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
2085 Error_Attr_P
("prefix for % attribute must be selected component");
2087 end Check_Component
;
2089 ------------------------------------
2090 -- Check_Decimal_Fixed_Point_Type --
2091 ------------------------------------
2093 procedure Check_Decimal_Fixed_Point_Type
is
2097 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
2098 Error_Attr_P
("prefix of % attribute must be decimal type");
2100 end Check_Decimal_Fixed_Point_Type
;
2102 -----------------------
2103 -- Check_Dereference --
2104 -----------------------
2106 procedure Check_Dereference
is
2109 -- Case of a subtype mark
2111 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2115 -- Case of an expression
2119 if Is_Access_Type
(P_Type
) then
2121 -- If there is an implicit dereference, then we must freeze the
2122 -- designated type of the access type, since the type of the
2123 -- referenced array is this type (see AI95-00106).
2125 -- As done elsewhere, freezing must not happen when preanalyzing
2126 -- a pre- or postcondition or a default value for an object or for
2127 -- a formal parameter.
2129 if not In_Spec_Expression
then
2130 Freeze_Before
(N
, Designated_Type
(P_Type
));
2134 Make_Explicit_Dereference
(Sloc
(P_Old
),
2135 Prefix
=> Relocate_Node
(P_Old
)));
2137 Analyze_And_Resolve
(P_Old
);
2138 P_Type
:= Etype
(P_Old
);
2140 if P_Type
= Any_Type
then
2141 raise Bad_Attribute
;
2144 P_Base_Type
:= Base_Type
(P_Type
);
2146 end Check_Dereference
;
2148 -------------------------
2149 -- Check_Discrete_Type --
2150 -------------------------
2152 procedure Check_Discrete_Type
is
2156 if not Is_Discrete_Type
(P_Type
) then
2157 Error_Attr_P
("prefix of % attribute must be discrete type");
2159 end Check_Discrete_Type
;
2165 procedure Check_E0
is
2167 if Present
(E1
) then
2168 Unexpected_Argument
(E1
);
2176 procedure Check_E1
is
2178 Check_Either_E0_Or_E1
;
2182 -- Special-case attributes that are functions and that appear as
2183 -- the prefix of another attribute. Error is posted on parent.
2185 if Nkind
(Parent
(N
)) = N_Attribute_Reference
2186 and then Attribute_Name
(Parent
(N
)) in Name_Address
2190 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
2191 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
2192 Set_Etype
(Parent
(N
), Any_Type
);
2193 Set_Entity
(Parent
(N
), Any_Type
);
2194 raise Bad_Attribute
;
2197 Error_Attr
("missing argument for % attribute", N
);
2206 procedure Check_E2
is
2209 Error_Attr
("missing arguments for % attribute (2 required)", N
);
2211 Error_Attr
("missing argument for % attribute (2 required)", N
);
2215 ---------------------------
2216 -- Check_Either_E0_Or_E1 --
2217 ---------------------------
2219 procedure Check_Either_E0_Or_E1
is
2221 if Present
(E2
) then
2222 Unexpected_Argument
(E2
);
2224 end Check_Either_E0_Or_E1
;
2226 ----------------------
2227 -- Check_Enum_Image --
2228 ----------------------
2230 procedure Check_Enum_Image
(Check_Enumeration_Maps
: Boolean := False) is
2234 -- Ensure that Check_Enumeration_Maps parameter is set precisely for
2235 -- attributes whose implementation requires enumeration maps.
2238 (Check_Enumeration_Maps
= (Attr_Id
in Attribute_Image
2240 | Attribute_Valid_Value
2242 | Attribute_Wide_Image
2243 | Attribute_Wide_Value
2244 | Attribute_Wide_Wide_Image
2245 | Attribute_Wide_Wide_Value
));
2247 -- When an enumeration type appears in an attribute reference, all
2248 -- literals of the type are marked as referenced. This must only be
2249 -- done if the attribute reference appears in the current source.
2250 -- Otherwise the information on references may differ between a
2251 -- normal compilation and one that performs inlining.
2253 if Is_Enumeration_Type
(P_Base_Type
)
2254 and then In_Extended_Main_Code_Unit
(N
)
2256 if Check_Enumeration_Maps
then
2257 Check_Restriction
(No_Enumeration_Maps
, N
);
2260 Lit
:= First_Literal
(P_Base_Type
);
2261 while Present
(Lit
) loop
2262 Set_Referenced
(Lit
);
2266 end Check_Enum_Image
;
2268 ----------------------------
2269 -- Check_First_Last_Valid --
2270 ----------------------------
2272 procedure Check_First_Last_Valid
is
2274 Check_Discrete_Type
;
2276 -- Freeze the subtype now, so that the following test for predicates
2277 -- works (we set the predicates stuff up at freeze time)
2279 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
2281 -- Now test for dynamic predicate
2283 if Has_Predicates
(P_Type
)
2284 and then not (Has_Static_Predicate
(P_Type
))
2287 ("prefix of % attribute may not have dynamic predicate");
2290 -- Check non-static subtype
2292 if not Is_OK_Static_Subtype
(P_Type
) then
2293 Error_Attr_P
("prefix of % attribute must be a static subtype");
2296 -- Test case for no values
2298 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
2299 Expr_Value
(Type_High_Bound
(P_Type
))
2300 or else (Has_Predicates
(P_Type
)
2302 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
2305 ("prefix of % attribute must be subtype with at least one "
2308 end Check_First_Last_Valid
;
2310 ----------------------------
2311 -- Check_Fixed_Point_Type --
2312 ----------------------------
2314 procedure Check_Fixed_Point_Type
is
2318 if not Is_Fixed_Point_Type
(P_Type
) then
2319 Error_Attr_P
("prefix of % attribute must be fixed point type");
2321 end Check_Fixed_Point_Type
;
2323 ------------------------------
2324 -- Check_Fixed_Point_Type_0 --
2325 ------------------------------
2327 procedure Check_Fixed_Point_Type_0
is
2329 Check_Fixed_Point_Type
;
2331 end Check_Fixed_Point_Type_0
;
2333 -------------------------------
2334 -- Check_Floating_Point_Type --
2335 -------------------------------
2337 procedure Check_Floating_Point_Type
is
2341 if not Is_Floating_Point_Type
(P_Type
) then
2342 Error_Attr_P
("prefix of % attribute must be float type");
2344 end Check_Floating_Point_Type
;
2346 ---------------------------------
2347 -- Check_Floating_Point_Type_0 --
2348 ---------------------------------
2350 procedure Check_Floating_Point_Type_0
is
2352 Check_Floating_Point_Type
;
2354 end Check_Floating_Point_Type_0
;
2356 ---------------------------------
2357 -- Check_Floating_Point_Type_1 --
2358 ---------------------------------
2360 procedure Check_Floating_Point_Type_1
is
2362 Check_Floating_Point_Type
;
2364 end Check_Floating_Point_Type_1
;
2366 ---------------------------------
2367 -- Check_Floating_Point_Type_2 --
2368 ---------------------------------
2370 procedure Check_Floating_Point_Type_2
is
2372 Check_Floating_Point_Type
;
2374 end Check_Floating_Point_Type_2
;
2376 ------------------------
2377 -- Check_Integer_Type --
2378 ------------------------
2380 procedure Check_Integer_Type
is
2384 if not Is_Integer_Type
(P_Type
) then
2385 Error_Attr_P
("prefix of % attribute must be integer type");
2387 end Check_Integer_Type
;
2389 --------------------------------
2390 -- Check_Modular_Integer_Type --
2391 --------------------------------
2393 procedure Check_Modular_Integer_Type
is
2397 if not Is_Modular_Integer_Type
(P_Type
) then
2399 ("prefix of % attribute must be modular integer type");
2401 end Check_Modular_Integer_Type
;
2403 ------------------------
2404 -- Check_Not_CPP_Type --
2405 ------------------------
2407 procedure Check_Not_CPP_Type
is
2409 if Is_Tagged_Type
(Etype
(P
))
2410 and then Convention
(Etype
(P
)) = Convention_CPP
2411 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
2414 ("invalid use of % attribute with 'C'P'P tagged type");
2416 end Check_Not_CPP_Type
;
2418 -------------------------------
2419 -- Check_Not_Incomplete_Type --
2420 -------------------------------
2422 procedure Check_Not_Incomplete_Type
is
2427 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2428 -- dereference we have to check wrong uses of incomplete types
2429 -- (other wrong uses are checked at their freezing point).
2431 -- In Ada 2012, incomplete types can appear in subprogram
2432 -- profiles, but formals with incomplete types cannot be the
2433 -- prefix of attributes.
2435 -- Example 1: Limited-with
2437 -- limited with Pkg;
2439 -- type Acc is access Pkg.T;
2441 -- S : Integer := X.all'Size; -- ERROR
2444 -- Example 2: Tagged incomplete
2446 -- type T is tagged;
2447 -- type Acc is access all T;
2449 -- S : constant Integer := X.all'Size; -- ERROR
2450 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2452 if Ada_Version
>= Ada_2005
2453 and then Nkind
(P
) = N_Explicit_Dereference
2456 while Nkind
(E
) = N_Explicit_Dereference
loop
2462 if From_Limited_With
(Typ
) then
2464 ("prefix of % attribute cannot be an incomplete type");
2466 -- If the prefix is an access type check the designated type
2468 elsif Is_Access_Type
(Typ
)
2469 and then Nkind
(P
) = N_Explicit_Dereference
2471 Typ
:= Directly_Designated_Type
(Typ
);
2474 if Is_Class_Wide_Type
(Typ
) then
2475 Typ
:= Root_Type
(Typ
);
2478 -- A legal use of a shadow entity occurs only when the unit where
2479 -- the non-limited view resides is imported via a regular with
2480 -- clause in the current body. Such references to shadow entities
2481 -- may occur in subprogram formals.
2483 if Is_Incomplete_Type
(Typ
)
2484 and then From_Limited_With
(Typ
)
2485 and then Present
(Non_Limited_View
(Typ
))
2486 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2488 Typ
:= Non_Limited_View
(Typ
);
2491 -- If still incomplete, it can be a local incomplete type, or a
2492 -- limited view whose scope is also a limited view.
2494 if Ekind
(Typ
) = E_Incomplete_Type
then
2495 if not From_Limited_With
(Typ
)
2496 and then No
(Full_View
(Typ
))
2499 ("prefix of % attribute cannot be an incomplete type");
2501 -- The limited view may be available indirectly through
2502 -- an intermediate unit. If the non-limited view is available
2503 -- the attribute reference is legal.
2505 elsif From_Limited_With
(Typ
)
2507 (No
(Non_Limited_View
(Typ
))
2508 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2511 ("prefix of % attribute cannot be an incomplete type");
2515 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2518 elsif Is_Entity_Name
(P
)
2519 and then Is_Formal
(Entity
(P
))
2520 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2523 ("prefix of % attribute cannot be an incomplete type");
2526 if not Is_Entity_Name
(P
)
2527 or else not Is_Type
(Entity
(P
))
2528 or else In_Spec_Expression
2531 elsif not Is_Current_Instance
(P
) then
2532 Check_Fully_Declared
(P_Type
, P
);
2534 end Check_Not_Incomplete_Type
;
2536 ----------------------------
2537 -- Check_Object_Reference --
2538 ----------------------------
2540 procedure Check_Object_Reference
(P
: Node_Id
) is
2544 -- If we need an object, and we have a prefix that is the name of a
2545 -- function entity, convert it into a function call.
2547 if Is_Entity_Name
(P
)
2548 and then Ekind
(Entity
(P
)) = E_Function
2550 Rtyp
:= Etype
(Entity
(P
));
2553 Make_Function_Call
(Sloc
(P
),
2554 Name
=> Relocate_Node
(P
)));
2556 Analyze_And_Resolve
(P
, Rtyp
);
2558 -- Otherwise we must have an object reference
2560 elsif not Is_Object_Reference
(P
) then
2561 Error_Attr_P
("prefix of % attribute must be object");
2563 end Check_Object_Reference
;
2565 ----------------------------
2566 -- Check_PolyORB_Attribute --
2567 ----------------------------
2569 procedure Check_PolyORB_Attribute
is
2571 Validate_Non_Static_Attribute_Function_Call
;
2576 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2578 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2580 end Check_PolyORB_Attribute
;
2582 ------------------------
2583 -- Check_Program_Unit --
2584 ------------------------
2586 procedure Check_Program_Unit
is
2588 if Is_Entity_Name
(P
) then
2590 E
: constant Entity_Id
:= Entity
(P
);
2592 if Ekind
(E
) in E_Protected_Type
2598 or else Is_Single_Concurrent_Object
(E
)
2605 Error_Attr_P
("prefix of % attribute must be program unit");
2606 end Check_Program_Unit
;
2608 ---------------------
2609 -- Check_Real_Type --
2610 ---------------------
2612 procedure Check_Real_Type
is
2616 if not Is_Real_Type
(P_Type
) then
2617 Error_Attr_P
("prefix of % attribute must be real type");
2619 end Check_Real_Type
;
2621 ----------------------------
2622 -- Check_Enumeration_Type --
2623 ----------------------------
2625 procedure Check_Enumeration_Type
is
2629 if not Is_Enumeration_Type
(P_Type
) then
2630 Error_Attr_P
("prefix of % attribute must be enumeration type");
2632 end Check_Enumeration_Type
;
2634 -----------------------
2635 -- Check_Scalar_Type --
2636 -----------------------
2638 procedure Check_Scalar_Type
is
2642 if not Is_Scalar_Type
(P_Type
) then
2643 Error_Attr_P
("prefix of % attribute must be scalar type");
2645 end Check_Scalar_Type
;
2647 ---------------------------
2648 -- Check_Standard_Prefix --
2649 ---------------------------
2651 procedure Check_Standard_Prefix
is
2655 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2656 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2658 end Check_Standard_Prefix
;
2660 -------------------------------
2661 -- Check_Put_Image_Attribute --
2662 -------------------------------
2664 procedure Check_Put_Image_Attribute
is
2666 -- Put_Image is a procedure, and can only appear at the position of a
2667 -- procedure call. If it's a list member and it's parent is a
2668 -- procedure call or aggregate, then this is appearing as an actual
2669 -- parameter or component association, which is wrong.
2671 if Is_List_Member
(N
)
2672 and then Nkind
(Parent
(N
)) not in
2673 N_Procedure_Call_Statement | N_Aggregate
2678 ("invalid context for attribute%, which is a procedure", N
);
2682 Analyze_And_Resolve
(E1
);
2684 -- Check that the first argument is
2685 -- Ada.Strings.Text_Buffers.Root_Buffer_Type'Class.
2687 -- Note: the double call to Root_Type here is needed because the
2688 -- root type of a class-wide type is the corresponding type (e.g.
2689 -- X for X'Class, and we really want to go to the root.)
2691 if not Is_RTE
(Root_Type
(Root_Type
(Etype
(E1
))),
2692 RE_Root_Buffer_Type
)
2695 ("expected Ada.Strings.Text_Buffers.Root_Buffer_Type''Class",
2699 -- Check that the second argument is of the right type
2702 Resolve
(E2
, P_Type
);
2703 end Check_Put_Image_Attribute
;
2705 ----------------------------
2706 -- Check_Stream_Attribute --
2707 ----------------------------
2709 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2713 In_Shared_Var_Procs
: Boolean;
2714 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2715 -- For this runtime package (always compiled in GNAT mode), we allow
2716 -- stream attributes references for limited types for the case where
2717 -- shared passive objects are implemented using stream attributes,
2718 -- which is the default in GNAT's persistent storage implementation.
2721 Validate_Non_Static_Attribute_Function_Call
;
2723 -- With the exception of 'Input, Stream attributes are procedures,
2724 -- and can only appear at the position of procedure calls. We check
2725 -- for this here, before they are rewritten, to give a more precise
2728 if Nam
= TSS_Stream_Input
then
2731 elsif Is_List_Member
(N
)
2732 and then Nkind
(Parent
(N
)) not in
2733 N_Procedure_Call_Statement | N_Aggregate
2739 ("invalid context for attribute%, which is a procedure", N
);
2743 Btyp
:= Implementation_Base_Type
(P_Type
);
2745 -- Stream attributes not allowed on limited types unless the
2746 -- attribute reference was generated by the expander (in which
2747 -- case the underlying type will be used, as described in Sinfo),
2748 -- or the attribute was specified explicitly for the type itself
2749 -- or one of its ancestors (taking visibility rules into account if
2750 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2751 -- (with no visibility restriction).
2754 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2756 if Present
(Gen_Body
) then
2757 In_Shared_Var_Procs
:=
2758 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2760 In_Shared_Var_Procs
:= False;
2764 if (Comes_From_Source
(N
)
2765 and then not (In_Shared_Var_Procs
or In_Instance
))
2766 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2767 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2769 Error_Msg_Name_1
:= Aname
;
2771 if Is_Limited_Type
(P_Type
) then
2773 ("limited type& has no% attribute", P
, P_Type
);
2774 Explain_Limited_Type
(P_Type
, P
);
2777 ("attribute% for type& is not available", P
, P_Type
);
2781 -- Check for no stream operations allowed from No_Tagged_Streams
2783 if Is_Tagged_Type
(P_Type
)
2784 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2786 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2788 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2792 -- Check restriction violations
2794 -- First check the No_Streams restriction, which prohibits the use
2795 -- of explicit stream attributes in the source program. We do not
2796 -- prevent the occurrence of stream attributes in generated code,
2797 -- for instance those generated implicitly for dispatching purposes.
2799 if Comes_From_Source
(N
) then
2800 Check_Restriction
(No_Streams
, P
);
2803 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2804 -- it is illegal to use a predefined elementary type stream attribute
2805 -- either by itself, or more importantly as part of the attribute
2806 -- subprogram for a composite type. However, if the broader
2807 -- restriction No_Streams is active, stream operations are not
2808 -- generated, and there is no error.
2810 if Restriction_Active
(No_Default_Stream_Attributes
)
2811 and then not Restriction_Active
(No_Streams
)
2817 if Nam
= TSS_Stream_Input
2819 Nam
= TSS_Stream_Read
2822 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2825 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2829 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2832 ("missing user-defined Stream Read or Write for type&",
2834 if not Is_Elementary_Type
(P_Type
) then
2836 ("\which is a component of type&", N
, P_Type
);
2842 -- Check special case of Exception_Id and Exception_Occurrence which
2843 -- are not allowed for restriction No_Exception_Registration.
2845 if Restriction_Check_Required
(No_Exception_Registration
)
2846 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2848 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2850 Check_Restriction
(No_Exception_Registration
, P
);
2853 -- If the No_Tagged_Type_Registration restriction is active, then
2854 -- class-wide streaming attributes are not allowed.
2856 if Restriction_Check_Required
(No_Tagged_Type_Registration
)
2857 and then Is_Class_Wide_Type
(P_Type
)
2859 Check_Restriction
(No_Tagged_Type_Registration
, P
);
2862 -- Here we must check that the first argument is an access type
2863 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2865 Analyze_And_Resolve
(E1
);
2868 -- Note: the double call to Root_Type here is needed because the
2869 -- root type of a class-wide type is the corresponding type (e.g.
2870 -- X for X'Class, and we really want to go to the root.)
2872 if not Is_Access_Type
(Etyp
)
2873 or else not Is_RTE
(Root_Type
(Root_Type
(Designated_Type
(Etyp
))),
2874 RE_Root_Stream_Type
)
2877 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2880 -- Check that the second argument is of the right type if there is
2881 -- one (the Input attribute has only one argument so this is skipped)
2883 if Present
(E2
) then
2886 if Nam
= TSS_Stream_Read
2887 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2890 ("second argument of % attribute must be a variable", E2
);
2893 Resolve
(E2
, P_Type
);
2897 end Check_Stream_Attribute
;
2899 -------------------------
2900 -- Check_System_Prefix --
2901 -------------------------
2903 procedure Check_System_Prefix
is
2905 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2906 Error_Attr
("only allowed prefix for % attribute is System", P
);
2908 end Check_System_Prefix
;
2910 -----------------------
2911 -- Check_Task_Prefix --
2912 -----------------------
2914 procedure Check_Task_Prefix
is
2916 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2917 -- task interface class-wide types.
2919 if Is_Task_Type
(Etype
(P
))
2920 or else (Is_Access_Type
(Etype
(P
))
2921 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2922 or else (Ada_Version
>= Ada_2005
2923 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2924 and then Is_Interface
(Etype
(P
))
2925 and then Is_Task_Interface
(Etype
(P
)))
2930 if Ada_Version
>= Ada_2005
then
2932 ("prefix of % attribute must be a task or a task " &
2933 "interface class-wide object");
2936 Error_Attr_P
("prefix of % attribute must be a task");
2939 end Check_Task_Prefix
;
2945 -- The possibilities are an entity name denoting a type, or an
2946 -- attribute reference that denotes a type (Base or Class). If
2947 -- the type is incomplete, replace it with its full view.
2949 procedure Check_Type
is
2951 if not Is_Entity_Name
(P
)
2952 or else not Is_Type
(Entity
(P
))
2954 Error_Attr_P
("prefix of % attribute must be a type");
2956 elsif Is_Protected_Self_Reference
(P
) then
2958 ("prefix of % attribute denotes current instance "
2959 & "(RM 9.4(21/2))");
2961 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2962 and then Present
(Full_View
(Entity
(P
)))
2964 P_Type
:= Full_View
(Entity
(P
));
2965 Set_Entity
(P
, P_Type
);
2969 ---------------------
2970 -- Check_Unit_Name --
2971 ---------------------
2973 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2975 if Nkind
(Nod
) = N_Identifier
then
2978 elsif Nkind
(Nod
) in N_Selected_Component | N_Expanded_Name
then
2979 Check_Unit_Name
(Prefix
(Nod
));
2981 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2986 Error_Attr
("argument for % attribute must be unit name", P
);
2987 end Check_Unit_Name
;
2993 procedure Error_Attr
is
2995 Set_Etype
(N
, Any_Type
);
2996 Set_Entity
(N
, Any_Type
);
2997 raise Bad_Attribute
;
3000 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
3002 Error_Msg_Name_1
:= Aname
;
3003 Error_Msg_N
(Msg
, Error_Node
);
3011 procedure Error_Attr_P
(Msg
: String; Msg_Cont
: String := "") is
3013 Error_Msg_Name_1
:= Aname
;
3014 Error_Msg_F
(Msg
, P
);
3015 if Msg_Cont
/= "" then
3016 Error_Msg_F
(Msg_Cont
, P
);
3021 ----------------------------
3022 -- Legal_Formal_Attribute --
3023 ----------------------------
3025 procedure Legal_Formal_Attribute
is
3029 if not Is_Entity_Name
(P
)
3030 or else not Is_Type
(Entity
(P
))
3032 Error_Attr_P
("prefix of % attribute must be generic type");
3034 elsif Is_Generic_Actual_Type
(Entity
(P
))
3036 or else In_Inlined_Body
3040 elsif Is_Generic_Type
(Entity
(P
)) then
3041 if Is_Definite_Subtype
(Entity
(P
)) then
3043 ("prefix of % attribute must be indefinite generic type");
3048 ("prefix of % attribute must be indefinite generic type");
3051 Set_Etype
(N
, Standard_Boolean
);
3052 end Legal_Formal_Attribute
;
3054 ---------------------------------------------------------------
3055 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
3056 ---------------------------------------------------------------
3058 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
3062 Check_Not_Incomplete_Type
;
3063 Set_Etype
(N
, Universal_Integer
);
3064 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
3070 procedure Min_Max
is
3072 -- Attribute can appear as function name in a reduction.
3073 -- Semantic checks are performed later.
3075 if Nkind
(Parent
(N
)) = N_Attribute_Reference
3076 and then Attribute_Name
(Parent
(N
)) = Name_Reduce
3078 Set_Etype
(N
, P_Base_Type
);
3084 Resolve
(E1
, P_Base_Type
);
3085 Resolve
(E2
, P_Base_Type
);
3086 Set_Etype
(N
, P_Base_Type
);
3088 -- Check for comparison on unordered enumeration type
3090 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
3091 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
3093 ("comparison on unordered enumeration type& declared#?.u?",
3098 ------------------------
3099 -- Standard_Attribute --
3100 ------------------------
3102 procedure Standard_Attribute
(Val
: Int
) is
3104 Check_Standard_Prefix
;
3105 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
3107 Set_Is_Static_Expression
(N
, True);
3108 end Standard_Attribute
;
3110 --------------------
3111 -- Uneval_Old_Msg --
3112 --------------------
3114 procedure Uneval_Old_Msg
is
3115 Uneval_Old_Setting
: Character;
3119 -- If from aspect, then Uneval_Old_Setting comes from flags in the
3120 -- N_Aspect_Specification node that corresponds to the attribute.
3122 -- First find the pragma in which we appear (note that at this stage,
3123 -- even if we appeared originally within an aspect specification, we
3124 -- are now within the corresponding pragma).
3128 Prag
:= Parent
(Prag
);
3129 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
3132 if Present
(Prag
) then
3133 if Uneval_Old_Accept
(Prag
) then
3134 Uneval_Old_Setting
:= 'A';
3135 elsif Uneval_Old_Warn
(Prag
) then
3136 Uneval_Old_Setting
:= 'W';
3138 Uneval_Old_Setting
:= 'E';
3141 -- If we did not find the pragma, that's odd, just use the setting
3142 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
3145 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
3148 -- Processing depends on the setting of Uneval_Old
3150 case Uneval_Old_Setting
is
3152 -- ??? In the case where Ada_Version is < Ada_2022 and
3153 -- an illegal 'Old prefix would be legal in Ada_2022,
3154 -- we'd like to call Error_Msg_Ada_2022_Feature.
3155 -- Identifying that case involves some work.
3158 ("prefix of attribute % that is potentially "
3159 & "unevaluated must statically name an entity"
3161 -- further text needed for accuracy if Ada_2022
3162 & (if Ada_Version
>= Ada_2022
3163 and then Attr_Id
= Attribute_Old
3164 then " or be eligible for conditional evaluation"
3165 & " (RM 6.1.1 (27))"
3168 "\using pragma Unevaluated_Use_Of_Old (Allow) will make "
3172 Error_Msg_Name_1
:= Aname
;
3174 ("??prefix of attribute % appears in potentially "
3175 & "unevaluated context, exception may be raised", P
);
3181 raise Program_Error
;
3185 -------------------------
3186 -- Unexpected Argument --
3187 -------------------------
3189 procedure Unexpected_Argument
(En
: Node_Id
) is
3191 Error_Attr
("unexpected argument for % attribute", En
);
3192 end Unexpected_Argument
;
3194 -------------------------------------------------
3195 -- Validate_Non_Static_Attribute_Function_Call --
3196 -------------------------------------------------
3198 -- This function should be moved to Sem_Dist ???
3200 procedure Validate_Non_Static_Attribute_Function_Call
is
3202 if In_Preelaborated_Unit
3203 and then not In_Subprogram_Or_Concurrent_Unit
3205 Flag_Non_Static_Expr
3206 ("non-static function call in preelaborated unit!", N
);
3208 end Validate_Non_Static_Attribute_Function_Call
;
3210 -- Start of processing for Analyze_Attribute
3213 -- Immediate return if unrecognized attribute (already diagnosed by
3214 -- parser, so there is nothing more that we need to do).
3216 if not Is_Attribute_Name
(Aname
) then
3217 raise Bad_Attribute
;
3220 Check_Restriction_No_Use_Of_Attribute
(N
);
3222 -- Deal with Ada 83 issues
3224 if Comes_From_Source
(N
) then
3225 if not Attribute_83
(Attr_Id
) then
3226 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3227 Error_Msg_Name_1
:= Aname
;
3228 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
3231 if Attribute_Impl_Def
(Attr_Id
) then
3232 Check_Restriction
(No_Implementation_Attributes
, N
);
3237 -- Deal with Ada 2005 attributes that are implementation attributes
3238 -- because they appear in a version of Ada before Ada 2005, ditto for
3239 -- Ada 2012 and Ada 2022 attributes appearing in an earlier version.
3241 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
3243 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
3245 (Attribute_22
(Attr_Id
) and then Ada_Version
< Ada_2022
)
3247 Check_Restriction
(No_Implementation_Attributes
, N
);
3250 -- Remote access to subprogram type access attribute reference needs
3251 -- unanalyzed copy for tree transformation. The analyzed copy is used
3252 -- for its semantic information (whether prefix is a remote subprogram
3253 -- name), the unanalyzed copy is used to construct new subtree rooted
3254 -- with N_Aggregate which represents a fat pointer aggregate.
3256 if Aname
= Name_Access
then
3257 Discard_Node
(Copy_Separate_Tree
(N
));
3260 -- Analyze prefix and exit if error in analysis. If the prefix is an
3261 -- incomplete type, use full view if available. Note that there are
3262 -- some attributes for which we do not analyze the prefix, since the
3263 -- prefix is not a normal name, or else needs special handling.
3265 if Aname
/= Name_Elab_Body
and then
3266 Aname
/= Name_Elab_Spec
and then
3267 Aname
/= Name_Elab_Subp_Body
and then
3268 Aname
/= Name_Enabled
and then
3272 P_Type
:= Etype
(P
);
3274 if Is_Entity_Name
(P
)
3275 and then Present
(Entity
(P
))
3276 and then Is_Type
(Entity
(P
))
3278 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
3279 P_Type
:= Get_Full_View
(P_Type
);
3280 Set_Entity
(P
, P_Type
);
3281 Set_Etype
(P
, P_Type
);
3283 elsif Entity
(P
) = Current_Scope
3284 and then Is_Record_Type
(Entity
(P
))
3286 -- Use of current instance within the type. Verify that if the
3287 -- attribute appears within a constraint, it yields an access
3288 -- type, other uses are illegal.
3296 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
3298 Par
:= Parent
(Par
);
3302 and then Nkind
(Par
) = N_Subtype_Indication
3304 if Attr_Id
/= Attribute_Access
3305 and then Attr_Id
/= Attribute_Unchecked_Access
3306 and then Attr_Id
/= Attribute_Unrestricted_Access
3309 ("in a constraint the current instance can only "
3310 & "be used with an access attribute", N
);
3317 if P_Type
= Any_Type
then
3318 raise Bad_Attribute
;
3321 P_Base_Type
:= Base_Type
(P_Type
);
3324 -- Analyze expressions that may be present, exiting if an error occurs
3331 E1
:= First
(Exprs
);
3333 -- Skip analysis for case of Restriction_Set, we do not expect
3334 -- the argument to be analyzed in this case.
3336 if Aname
/= Name_Restriction_Set
then
3339 -- Check for missing/bad expression (result of previous error)
3342 or else (Etype
(E1
) = Any_Type
and then Full_Analysis
)
3344 Check_Error_Detected
;
3345 raise Bad_Attribute
;
3351 if Present
(E2
) then
3354 if Etype
(E2
) = Any_Type
then
3355 raise Bad_Attribute
;
3358 if Present
(Next
(E2
)) then
3359 Unexpected_Argument
(Next
(E2
));
3364 -- Cases where prefix must be resolvable by itself
3366 if Is_Overloaded
(P
)
3367 and then Aname
/= Name_Access
3368 and then Aname
/= Name_Address
3369 and then Aname
/= Name_Code_Address
3370 and then Aname
/= Name_Result
3371 and then Aname
/= Name_Unchecked_Access
3373 -- The prefix must be resolvable by itself, without reference to the
3374 -- attribute. One case that requires special handling is a prefix
3375 -- that is a function name, where one interpretation may be a
3376 -- parameterless call. Entry attributes are handled specially below.
3378 if Is_Entity_Name
(P
)
3379 and then Aname
not in Name_Count | Name_Caller
3381 Check_Parameterless_Call
(P
);
3384 if Is_Overloaded
(P
) then
3386 -- Ada 2005 (AI-345): Since protected and task types have
3387 -- primitive entry wrappers, the attributes Count, and Caller
3388 -- require a context check
3390 if Aname
in Name_Count | Name_Caller
then
3392 Count
: Natural := 0;
3397 Get_First_Interp
(P
, I
, It
);
3398 while Present
(It
.Nam
) loop
3399 if Comes_From_Source
(It
.Nam
) then
3405 Get_Next_Interp
(I
, It
);
3409 Error_Attr
("ambiguous prefix for % attribute", P
);
3411 Set_Is_Overloaded
(P
, False);
3416 Error_Attr
("ambiguous prefix for % attribute", P
);
3421 -- If the prefix was rewritten as a raise node, then rewrite N as a
3422 -- raise node, to avoid creating inconsistent trees. We still need to
3423 -- perform legality checks on the original tree.
3425 if Nkind
(P
) in N_Raise_xxx_Error
then
3426 Rewrite
(N
, Relocate_Node
(P
));
3427 P
:= Original_Node
(P_Old
);
3430 -- Remaining processing depends on attribute
3434 -- Attributes related to Ada 2012 iterators. Attribute specifications
3435 -- exist for these, but they cannot be queried.
3437 when Attribute_Constant_Indexing
3438 | Attribute_Default_Iterator
3439 | Attribute_Implicit_Dereference
3440 | Attribute_Iterator_Element
3441 | Attribute_Iterable
3442 | Attribute_Variable_Indexing
3444 Error_Msg_N
("illegal attribute", N
);
3446 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
3447 -- were already rejected by the parser. Thus they shouldn't appear here.
3449 when Internal_Attribute_Id
=>
3450 raise Program_Error
;
3456 when Attribute_Abort_Signal
=>
3457 Check_Standard_Prefix
;
3458 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
3465 when Attribute_Access
=>
3466 Analyze_Access_Attribute
;
3467 Check_Not_Incomplete_Type
;
3473 when Attribute_Address
=>
3476 Check_Not_Incomplete_Type
;
3478 -- If the prefix is a dereference of a value whose associated access
3479 -- type has been specified with aspect Designated_Storage_Model, then
3480 -- use the associated Storage_Model_Type's address type as the type
3481 -- of the attribute. Otherwise we use System.Address as usual. This
3482 -- isn't normally legit for a predefined attribute, but this is for
3483 -- our own extension to addressing and currently requires extensions
3484 -- to be enabled (such as with -gnatX0).
3487 Prefix_Obj
: constant Node_Id
:= Get_Referenced_Object
(P
);
3488 Addr_Type
: Entity_Id
:= RTE
(RE_Address
);
3490 if Nkind
(Prefix_Obj
) = N_Explicit_Dereference
then
3492 P_Type
: constant Entity_Id
:= Etype
(Prefix
(Prefix_Obj
));
3494 use Storage_Model_Support
;
3496 if Has_Designated_Storage_Model_Aspect
(P_Type
) then
3497 Addr_Type
:= Storage_Model_Address_Type
3498 (Storage_Model_Object
(P_Type
));
3503 Set_Etype
(N
, Addr_Type
);
3510 when Attribute_Address_Size
=>
3511 Standard_Attribute
(System_Address_Size
);
3517 when Attribute_Adjacent
3518 | Attribute_Copy_Sign
3519 | Attribute_Remainder
3521 Check_Floating_Point_Type_2
;
3522 Set_Etype
(N
, P_Base_Type
);
3523 Resolve
(E1
, P_Base_Type
);
3524 Resolve
(E2
, P_Base_Type
);
3530 when Attribute_Aft
=>
3531 Check_Fixed_Point_Type_0
;
3532 Set_Etype
(N
, Universal_Integer
);
3538 when Attribute_Alignment
=>
3540 -- Don't we need more checking here, cf Size ???
3543 Check_Not_Incomplete_Type
;
3545 Set_Etype
(N
, Universal_Integer
);
3551 when Attribute_Asm_Input
=>
3552 Check_Asm_Attribute
;
3554 -- The back end may need to take the address of E2
3556 if Is_Entity_Name
(E2
) then
3557 Set_Address_Taken
(Entity
(E2
));
3560 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3566 when Attribute_Asm_Output
=>
3567 Check_Asm_Attribute
;
3569 if Etype
(E2
) = Any_Type
then
3572 elsif Aname
= Name_Asm_Output
then
3573 if not Is_Variable
(E2
) then
3575 ("second argument for Asm_Output is not variable", E2
);
3579 Note_Possible_Modification
(E2
, Sure
=> True);
3581 -- The back end may need to take the address of E2
3583 if Is_Entity_Name
(E2
) then
3584 Set_Address_Taken
(Entity
(E2
));
3587 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3589 -----------------------------
3590 -- Atomic_Always_Lock_Free --
3591 -----------------------------
3593 when Attribute_Atomic_Always_Lock_Free
=>
3596 Set_Etype
(N
, Standard_Boolean
);
3602 -- Note: when the base attribute appears in the context of a subtype
3603 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3604 -- the following circuit.
3606 when Attribute_Base
=> Base
: declare
3614 if Ada_Version
>= Ada_95
3615 and then not Is_Scalar_Type
(Typ
)
3616 and then not Is_Generic_Type
(Typ
)
3618 Error_Attr_P
("prefix of Base attribute must be scalar type");
3620 elsif Sloc
(Typ
) = Standard_Location
3621 and then Base_Type
(Typ
) = Typ
3622 and then Warn_On_Redundant_Constructs
3624 Error_Msg_NE
-- CODEFIX
3625 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3628 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3629 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3630 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3638 when Attribute_Bit
=>
3641 if not Is_Object_Reference
(P
) then
3642 Error_Attr_P
("prefix of % attribute must be object");
3644 -- What about the access object cases ???
3650 Set_Etype
(N
, Universal_Integer
);
3656 when Attribute_Bit_Order
=>
3660 if not Is_Record_Type
(P_Type
) then
3661 Error_Attr_P
("prefix of % attribute must be record type");
3664 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3666 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3669 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3674 -- Reset incorrect indication of staticness
3676 Set_Is_Static_Expression
(N
, False);
3682 -- Note: in generated code, we can have a Bit_Position attribute
3683 -- applied to a (naked) record component (i.e. the prefix is an
3684 -- identifier that references an E_Component or E_Discriminant
3685 -- entity directly, and this is interpreted as expected by Gigi.
3686 -- The following code will not tolerate such usage, but when the
3687 -- expander creates this special case, it marks it as analyzed
3688 -- immediately and sets an appropriate type.
3690 when Attribute_Bit_Position
=>
3691 if Comes_From_Source
(N
) then
3695 Set_Etype
(N
, Universal_Integer
);
3701 when Attribute_Body_Version
=>
3704 Set_Etype
(N
, RTE
(RE_Version_String
));
3710 when Attribute_Callable
3711 | Attribute_Terminated
3714 Set_Etype
(N
, Standard_Boolean
);
3721 when Attribute_Caller
=> Caller
: declare
3728 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3731 if not Is_Entry
(Ent
) then
3732 Error_Attr
("invalid entry name", N
);
3736 Error_Attr
("invalid entry name", N
);
3739 for J
in reverse 0 .. Scope_Stack
.Last
loop
3740 S
:= Scope_Stack
.Table
(J
).Entity
;
3742 if S
= Scope
(Ent
) then
3743 Error_Attr
("Caller must appear in matching accept or body", N
);
3749 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3756 when Attribute_Ceiling
3758 | Attribute_Fraction
3760 | Attribute_Machine_Rounding
3762 | Attribute_Rounding
3763 | Attribute_Truncation
3764 | Attribute_Unbiased_Rounding
3766 Check_Floating_Point_Type_1
;
3767 Set_Etype
(N
, P_Base_Type
);
3768 Resolve
(E1
, P_Base_Type
);
3774 when Attribute_Class
=>
3775 Check_Restriction
(No_Dispatch
, N
);
3779 -- Applying Class to untagged incomplete type is obsolescent in Ada
3780 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3781 -- this flag gets set by Find_Type in this situation.
3783 if Restriction_Check_Required
(No_Obsolescent_Features
)
3784 and then Ada_Version
>= Ada_2005
3785 and then Ekind
(P_Type
) = E_Incomplete_Type
3788 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3790 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3791 and then not Tagged_Present
(DN
)
3793 Check_Restriction
(No_Obsolescent_Features
, P
);
3802 when Attribute_Code_Address
=>
3805 if Nkind
(P
) = N_Attribute_Reference
3806 and then Attribute_Name
(P
) in Name_Elab_Body | Name_Elab_Spec
3810 elsif not Is_Entity_Name
(P
)
3811 or else (Ekind
(Entity
(P
)) /= E_Function
3813 Ekind
(Entity
(P
)) /= E_Procedure
)
3815 Error_Attr
("invalid prefix for % attribute", P
);
3817 -- Issue an error if the prefix denotes an eliminated subprogram
3820 Set_Address_Taken
(Entity
(P
));
3821 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3824 Set_Etype
(N
, RTE
(RE_Address
));
3826 ----------------------
3827 -- Compiler_Version --
3828 ----------------------
3830 when Attribute_Compiler_Version
=>
3832 Check_Standard_Prefix
;
3833 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3834 Analyze_And_Resolve
(N
, Standard_String
);
3835 Set_Is_Static_Expression
(N
, True);
3837 --------------------
3838 -- Component_Size --
3839 --------------------
3841 when Attribute_Component_Size
=>
3843 Set_Etype
(N
, Universal_Integer
);
3845 -- Note: unlike other array attributes, unconstrained arrays are OK
3847 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3857 when Attribute_Compose
3858 | Attribute_Leading_Part
3861 Check_Floating_Point_Type_2
;
3862 Set_Etype
(N
, P_Base_Type
);
3863 Resolve
(E1
, P_Base_Type
);
3864 Resolve
(E2
, Any_Integer
);
3870 when Attribute_Constrained
=>
3872 Set_Etype
(N
, Standard_Boolean
);
3874 -- Case from RM J.4(2) of constrained applied to private type
3876 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3877 Check_Restriction
(No_Obsolescent_Features
, P
);
3879 if Warn_On_Obsolescent_Feature
then
3881 ("constrained for private type is an obsolescent feature "
3882 & "(RM J.4)?j?", N
);
3885 -- If we are within an instance, the attribute must be legal
3886 -- because it was valid in the generic unit. Ditto if this is
3887 -- an inlining of a function declared in an instance.
3889 if In_Instance
or else In_Inlined_Body
then
3892 -- For sure OK if we have a real private type itself, but must
3893 -- be completed, cannot apply Constrained to incomplete type.
3895 elsif Is_Private_Type
(Entity
(P
)) then
3897 -- Note: this is one of the Annex J features that does not
3898 -- generate a warning from -gnatwj, since in fact it seems
3899 -- very useful, and is used in the GNAT runtime.
3901 Check_Not_Incomplete_Type
;
3905 -- Normal (non-obsolescent case) of application to object or value of
3906 -- a discriminated type.
3909 -- AI12-0068: In a type or subtype aspect, a prefix denoting the
3910 -- current instance of the (sub)type is defined to be a value,
3911 -- not an object, so the Constrained attribute is always True
3912 -- (see RM 8.6(18/5) and RM 3.7.2(3/5)). We issue a warning about
3913 -- this unintuitive result, to help avoid confusion.
3915 if Is_Current_Instance_Reference_In_Type_Aspect
(P
) then
3916 Error_Msg_Name_1
:= Aname
;
3918 ("current instance attribute % in subtype aspect always " &
3922 Check_Object_Reference
(P
);
3925 -- If N does not come from source, then we allow the
3926 -- the attribute prefix to be of a private type whose
3927 -- full type has discriminants. This occurs in cases
3928 -- involving expanded calls to stream attributes.
3930 if not Comes_From_Source
(N
) then
3931 P_Type
:= Underlying_Type
(P_Type
);
3934 -- Must have discriminants or be an access type designating a type
3935 -- with discriminants. If it is a class-wide type it has unknown
3938 if Has_Discriminants
(P_Type
)
3939 or else Has_Unknown_Discriminants
(P_Type
)
3941 (Is_Access_Type
(P_Type
)
3942 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3946 -- The rule given in 3.7.2 is part of static semantics, but the
3947 -- intent is clearly that it be treated as a legality rule, and
3948 -- rechecked in the visible part of an instance. Nevertheless
3949 -- the intent also seems to be it should legally apply to the
3950 -- actual of a formal with unknown discriminants, regardless of
3951 -- whether the actual has discriminants, in which case the value
3952 -- of the attribute is determined using the J.4 rules. This choice
3953 -- seems the most useful, and is compatible with existing tests.
3955 elsif In_Instance
then
3958 -- Also allow an object of a generic type if extensions allowed
3959 -- and allow this for any type at all.
3961 elsif (Is_Generic_Type
(P_Type
)
3962 or else Is_Generic_Actual_Type
(P_Type
))
3963 and then All_Extensions_Allowed
3969 -- Fall through if bad prefix
3972 ("prefix of % attribute must be object of discriminated type");
3978 -- Shares processing with Adjacent attribute
3984 when Attribute_Count
=> Count
: declare
3992 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3995 if Ekind
(Ent
) /= E_Entry
then
3996 Error_Attr
("invalid entry name", N
);
3999 elsif Nkind
(P
) = N_Indexed_Component
then
4000 if not Is_Entity_Name
(Prefix
(P
))
4001 or else No
(Entity
(Prefix
(P
)))
4002 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
4004 if Nkind
(Prefix
(P
)) = N_Selected_Component
4005 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
4006 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
4010 ("attribute % must apply to entry of current task", P
);
4013 Error_Attr
("invalid entry family name", P
);
4017 Ent
:= Entity
(Prefix
(P
));
4020 elsif Nkind
(P
) = N_Selected_Component
4021 and then Present
(Entity
(Selector_Name
(P
)))
4022 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
4025 ("attribute % must apply to entry of current task", P
);
4028 Error_Attr
("invalid entry name", N
);
4031 for J
in reverse 0 .. Scope_Stack
.Last
loop
4032 S
:= Scope_Stack
.Table
(J
).Entity
;
4034 if S
= Scope
(Ent
) then
4035 if Nkind
(P
) = N_Expanded_Name
then
4036 Tsk
:= Entity
(Prefix
(P
));
4038 -- The prefix denotes either the task type, or else a
4039 -- single task whose task type is being analyzed.
4041 if (Is_Type
(Tsk
) and then Tsk
= S
)
4042 or else (not Is_Type
(Tsk
)
4043 and then Etype
(Tsk
) = S
4044 and then not (Comes_From_Source
(S
)))
4049 ("attribute % must apply to entry of current task", N
);
4055 elsif Ekind
(Scope
(Ent
)) in Task_Kind
4056 and then Ekind
(S
) not in E_Block
4061 Error_Attr
("attribute % cannot appear in inner unit", N
);
4063 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
4064 and then not Has_Completion
(Scope
(Ent
))
4066 Error_Attr
("attribute % can only be used inside body", N
);
4070 if Is_Overloaded
(P
) then
4072 Index
: Interp_Index
;
4076 Get_First_Interp
(P
, Index
, It
);
4077 while Present
(It
.Nam
) loop
4078 if It
.Nam
= Ent
then
4081 -- Ada 2005 (AI-345): Do not consider primitive entry
4082 -- wrappers generated for task or protected types.
4084 elsif Ada_Version
>= Ada_2005
4085 and then not Comes_From_Source
(It
.Nam
)
4090 Error_Attr
("ambiguous entry name", N
);
4093 Get_Next_Interp
(Index
, It
);
4098 Set_Etype
(N
, Universal_Integer
);
4101 -----------------------
4102 -- Default_Bit_Order --
4103 -----------------------
4105 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
4106 Target_Default_Bit_Order
: System
.Bit_Order
;
4109 Check_Standard_Prefix
;
4111 if Bytes_Big_Endian
then
4112 Target_Default_Bit_Order
:= System
.High_Order_First
;
4114 Target_Default_Bit_Order
:= System
.Low_Order_First
;
4118 Make_Integer_Literal
(Loc
,
4119 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
4121 Set_Etype
(N
, Universal_Integer
);
4122 Set_Is_Static_Expression
(N
);
4123 end Default_Bit_Order
;
4125 ----------------------------------
4126 -- Default_Scalar_Storage_Order --
4127 ----------------------------------
4129 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
4130 RE_Default_SSO
: RE_Id
;
4133 Check_Standard_Prefix
;
4135 case Opt
.Default_SSO
is
4137 if Bytes_Big_Endian
then
4138 RE_Default_SSO
:= RE_High_Order_First
;
4140 RE_Default_SSO
:= RE_Low_Order_First
;
4144 RE_Default_SSO
:= RE_High_Order_First
;
4147 RE_Default_SSO
:= RE_Low_Order_First
;
4150 raise Program_Error
;
4153 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
4160 when Attribute_Definite
=>
4161 Legal_Formal_Attribute
;
4167 when Attribute_Delta
=>
4168 Check_Fixed_Point_Type_0
;
4169 Set_Etype
(N
, Universal_Real
);
4175 when Attribute_Denorm
4176 | Attribute_Signed_Zeros
4178 Check_Floating_Point_Type_0
;
4179 Set_Etype
(N
, Standard_Boolean
);
4185 when Attribute_Deref
=>
4188 Resolve
(E1
, RTE
(RE_Address
));
4189 Set_Etype
(N
, P_Type
);
4191 ---------------------
4192 -- Descriptor_Size --
4193 ---------------------
4195 when Attribute_Descriptor_Size
=>
4198 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
4199 Error_Attr_P
("prefix of attribute % must denote a type");
4202 Set_Etype
(N
, Universal_Integer
);
4208 when Attribute_Digits
=>
4212 if not Is_Floating_Point_Type
(P_Type
)
4213 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
4216 ("prefix of % attribute must be float or decimal type");
4219 Set_Etype
(N
, Universal_Integer
);
4225 -- Also handles processing for Elab_Spec and Elab_Subp_Body
4227 when Attribute_Elab_Body
4228 | Attribute_Elab_Spec
4229 | Attribute_Elab_Subp_Body
4232 Check_Unit_Name
(P
);
4233 Set_Etype
(N
, Standard_Void_Type
);
4235 -- We have to manually call the expander in this case to get
4236 -- the necessary expansion (normally attributes that return
4237 -- entities are not expanded).
4245 -- Shares processing with Elab_Body attribute
4251 when Attribute_Elaborated
=>
4253 Check_Unit_Name
(P
);
4254 Set_Etype
(N
, Standard_Boolean
);
4261 | Attribute_Machine_Emax
4262 | Attribute_Machine_Emin
4263 | Attribute_Machine_Mantissa
4264 | Attribute_Model_Emin
4265 | Attribute_Model_Mantissa
4266 | Attribute_Safe_Emax
4268 Check_Floating_Point_Type_0
;
4269 Set_Etype
(N
, Universal_Integer
);
4275 when Attribute_Enabled
=>
4276 Check_Either_E0_Or_E1
;
4278 if Present
(E1
) then
4279 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
4280 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
4285 if Nkind
(P
) /= N_Identifier
then
4286 Error_Msg_N
("identifier expected (check name)", P
);
4287 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
4288 Error_Msg_N
("& is not a recognized check name", P
);
4291 Set_Etype
(N
, Standard_Boolean
);
4297 when Attribute_Enum_Rep
=>
4299 -- T'Enum_Rep (X) case
4301 if Present
(E1
) then
4303 Check_Discrete_Type
;
4304 Resolve
(E1
, P_Base_Type
);
4306 -- X'Enum_Rep case. X must be an object or enumeration literal
4307 -- (including an attribute reference), and it must be of a
4311 ((Is_Object_Reference
(P
)
4314 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
4315 or else Nkind
(P
) = N_Attribute_Reference
)
4316 and then Is_Discrete_Type
(Etype
(P
)))
4318 Error_Attr_P
("prefix of % attribute must be discrete object");
4321 Set_Etype
(N
, Universal_Integer
);
4327 when Attribute_Enum_Val
=>
4331 if not Is_Enumeration_Type
(P_Type
) then
4332 Error_Attr_P
("prefix of % attribute must be enumeration type");
4335 -- If the enumeration type has a standard representation, the effect
4336 -- is the same as 'Val, so rewrite the attribute as a 'Val.
4338 if not Has_Non_Standard_Rep
(P_Base_Type
) then
4340 Make_Attribute_Reference
(Loc
,
4341 Prefix
=> Relocate_Node
(Prefix
(N
)),
4342 Attribute_Name
=> Name_Val
,
4343 Expressions
=> New_List
(Relocate_Node
(E1
))));
4344 Analyze_And_Resolve
(N
, P_Base_Type
);
4346 -- Non-standard representation case (enumeration with holes)
4350 Resolve
(E1
, Any_Integer
);
4351 Set_Etype
(N
, P_Base_Type
);
4358 when Attribute_Epsilon
4359 | Attribute_Model_Epsilon
4360 | Attribute_Model_Small
4361 | Attribute_Safe_First
4362 | Attribute_Safe_Last
4364 Check_Floating_Point_Type_0
;
4365 Set_Etype
(N
, Universal_Real
);
4371 when Attribute_Exponent
=>
4372 Check_Floating_Point_Type_1
;
4373 Set_Etype
(N
, Universal_Integer
);
4374 Resolve
(E1
, P_Base_Type
);
4380 when Attribute_External_Tag
=>
4384 Set_Etype
(N
, Standard_String
);
4386 if not Is_Tagged_Type
(P_Type
) then
4387 Error_Attr_P
("prefix of % attribute must be tagged");
4394 when Attribute_Fast_Math
=>
4395 Check_Standard_Prefix
;
4396 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
4398 -----------------------
4399 -- Finalization_Size --
4400 -----------------------
4402 when Attribute_Finalization_Size
=>
4405 -- The prefix denotes an object
4407 if Is_Object_Reference
(P
) then
4408 Check_Object_Reference
(P
);
4410 -- The prefix denotes a type
4412 elsif Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
4414 Check_Not_Incomplete_Type
;
4416 -- Attribute 'Finalization_Size is not defined for class-wide
4417 -- types because it is not possible to know statically whether
4418 -- a definite type will have controlled components or not.
4420 if Is_Class_Wide_Type
(Etype
(P
)) then
4422 ("prefix of % attribute cannot denote a class-wide type");
4425 -- The prefix denotes an illegal construct
4429 ("prefix of % attribute must be a definite type or an object");
4432 Set_Etype
(N
, Universal_Integer
);
4438 when Attribute_First
4441 Check_Array_Or_Scalar_Type
;
4442 Bad_Attribute_For_Predicate
;
4448 when Attribute_First_Bit
4449 | Attribute_Last_Bit
4450 | Attribute_Position
4453 Set_Etype
(N
, Universal_Integer
);
4459 when Attribute_First_Valid
4460 | Attribute_Last_Valid
4462 Check_First_Last_Valid
;
4463 Set_Etype
(N
, P_Type
);
4469 when Attribute_Fixed_Value
=>
4470 Check_Fixed_Point_Type
;
4472 Resolve
(E1
, Any_Integer
);
4473 Set_Etype
(N
, P_Base_Type
);
4479 -- Shares processing with Ceiling attribute
4485 when Attribute_Fore
=>
4486 Check_Fixed_Point_Type_0
;
4487 Set_Etype
(N
, Universal_Integer
);
4493 -- Shares processing with Ceiling attribute
4499 when Attribute_From_Any
=>
4501 Check_PolyORB_Attribute
;
4502 Set_Etype
(N
, P_Base_Type
);
4504 -----------------------
4505 -- Has_Access_Values --
4506 -----------------------
4508 when Attribute_Has_Access_Values
4509 | Attribute_Has_Tagged_Values
4513 Set_Etype
(N
, Standard_Boolean
);
4515 ----------------------
4516 -- Has_Same_Storage --
4517 ----------------------
4519 when Attribute_Has_Same_Storage
4520 | Attribute_Overlaps_Storage
4524 -- The arguments must be objects of any type
4526 Analyze_And_Resolve
(P
);
4527 Analyze_And_Resolve
(E1
);
4528 Check_Object_Reference
(P
);
4529 Check_Object_Reference
(E1
);
4530 Set_Etype
(N
, Standard_Boolean
);
4536 when Attribute_Index
=> Index
: declare
4539 Spec_Id
: Entity_Id
;
4543 Analyze_Index_Attribute
(Legal
, Spec_Id
);
4545 if not Legal
or else No
(Spec_Id
) then
4546 Error_Attr
("attribute % must apply to entry family", P
);
4551 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
4554 if Ekind
(Ent
) /= E_Entry_Family
then
4556 ("attribute % must apply to entry family", P
);
4558 -- Analysis of pre/postconditions of an entry [family] occurs when
4559 -- the conditions are relocated to the contract wrapper procedure
4560 -- (see subprogram Build_Contract_Wrapper).
4562 elsif Contract_Wrapper
(Ent
) /= Spec_Id
then
4564 ("attribute % must apply to current entry family", P
);
4567 elsif Nkind
(P
) in N_Indexed_Component
4568 | N_Selected_Component
4571 ("attribute % must apply to current entry family", P
);
4574 Error_Attr
("invalid entry family name", N
);
4577 Set_Etype
(N
, Entry_Index_Type
(Ent
));
4580 -----------------------
4581 -- Has_Tagged_Values --
4582 -----------------------
4584 -- Shares processing with Has_Access_Values attribute
4586 -----------------------
4587 -- Has_Discriminants --
4588 -----------------------
4590 when Attribute_Has_Discriminants
=>
4591 Legal_Formal_Attribute
;
4597 when Attribute_Identity
=>
4600 if Etype
(P
) = Standard_Exception_Type
then
4601 Set_Etype
(N
, RTE
(RE_Exception_Id
));
4603 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
4604 -- interface class-wide types.
4606 elsif Is_Task_Type
(Etype
(P
))
4607 or else (Is_Access_Type
(Etype
(P
))
4608 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
4609 or else (Ada_Version
>= Ada_2005
4610 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
4611 and then Is_Interface
(Etype
(P
))
4612 and then Is_Task_Interface
(Etype
(P
)))
4615 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
4618 if Ada_Version
>= Ada_2005
then
4620 ("prefix of % attribute must be an exception, a task or a "
4621 & "task interface class-wide object");
4624 ("prefix of % attribute must be a task or an exception");
4632 when Attribute_Image
=>
4633 if Is_Real_Type
(P_Type
) then
4634 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4635 Error_Msg_Name_1
:= Aname
;
4637 ("(Ada 83) % attribute not allowed for real types", N
);
4641 Analyze_Image_Attribute
(Standard_String
);
4647 when Attribute_Img
=>
4648 Analyze_Image_Attribute
(Standard_String
);
4654 when Attribute_Initialized
=>
4657 if Comes_From_Source
(N
) then
4659 -- This attribute can be prefixed with references to objects or
4660 -- values (such as a current instance value given within a type
4661 -- or subtype aspect).
4663 if not Is_Object_Reference
(P
)
4664 and then not Is_Current_Instance_Reference_In_Type_Aspect
(P
)
4666 Error_Attr_P
("prefix of % attribute must be object");
4668 -- Just like attribute 'Valid_Scalars this attribute is illegal
4669 -- on unchecked union types.
4671 elsif Has_Unchecked_Union
(Validated_View
(P_Type
)) then
4673 ("attribute % not allowed for Unchecked_Union type");
4677 Set_Etype
(N
, Standard_Boolean
);
4683 when Attribute_Input
=>
4685 Check_Stream_Attribute
(TSS_Stream_Input
);
4686 Set_Etype
(N
, P_Base_Type
);
4692 when Attribute_Integer_Value
=>
4695 Resolve
(E1
, Any_Fixed
);
4697 -- Signal an error if argument type is not a specific fixed-point
4698 -- subtype. An error has been signalled already if the argument
4699 -- was not of a fixed-point type.
4701 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4702 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4705 Set_Etype
(N
, P_Base_Type
);
4711 when Attribute_Invalid_Value
=>
4714 Set_Etype
(N
, P_Base_Type
);
4715 Invalid_Value_Used
:= True;
4721 when Attribute_Large
4723 | Attribute_Safe_Large
4724 | Attribute_Safe_Small
4728 Set_Etype
(N
, Universal_Real
);
4734 -- Shares processing with First attribute
4740 -- Shares processing with First_Bit attribute
4746 -- Shares processing with First_Valid attribute
4752 -- Shares processing with Compose attribute
4758 when Attribute_Length
=>
4760 Set_Etype
(N
, Universal_Integer
);
4766 when Attribute_Library_Level
=>
4769 if not Is_Entity_Name
(P
) then
4770 Error_Attr_P
("prefix of % attribute must be an entity name");
4773 if not Inside_A_Generic
then
4774 Set_Boolean_Result
(N
,
4775 Is_Library_Level_Entity
(Entity
(P
)));
4778 Set_Etype
(N
, Standard_Boolean
);
4784 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4785 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4786 -- Inspect the prefix for any uses of entities declared within the
4787 -- related loop. Loop_Id denotes the loop identifier.
4789 --------------------------------
4790 -- Check_References_In_Prefix --
4791 --------------------------------
4793 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4794 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4796 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4797 -- Detect attribute 'Loop_Entry in prefix P and determine whether
4798 -- a reference mentions an entity declared within the related
4801 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4802 -- Determine whether Nod appears in the subtree of Loop_Decl but
4803 -- not within the subtree of the prefix P itself.
4805 ---------------------
4806 -- Check_Reference --
4807 ---------------------
4809 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4810 Orig_Nod
: constant Node_Id
:= Original_Node
(Nod
);
4811 -- Check presence of Loop_Entry in the prefix P by looking at
4812 -- the original node for Nod, as it will have been rewritten
4813 -- into its own prefix if the assertion is ignored (see code
4817 if Is_Attribute_Loop_Entry
(Orig_Nod
) then
4818 Error_Msg_Name_1
:= Name_Loop_Entry
;
4819 Error_Msg_Name_2
:= Name_Loop_Entry
;
4821 ("attribute % cannot appear in the prefix of attribute %",
4825 elsif Nkind
(Nod
) = N_Identifier
4826 and then Present
(Entity
(Nod
))
4827 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4830 ("prefix of attribute % cannot reference local entities",
4835 end Check_Reference
;
4837 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4839 ---------------------
4840 -- Declared_Within --
4841 ---------------------
4843 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4848 while Present
(Stmt
) loop
4849 if Stmt
= Loop_Decl
then
4855 -- Prevent the search from going too far
4857 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4861 Stmt
:= Parent
(Stmt
);
4865 end Declared_Within
;
4867 -- Start of processing for Check_Prefix_For_Local_References
4870 Check_References
(P
);
4871 end Check_References_In_Prefix
;
4875 Context
: constant Node_Id
:= Parent
(N
);
4877 Encl_Loop
: Node_Id
:= Empty
;
4878 Encl_Prag
: Node_Id
:= Empty
;
4879 Loop_Id
: Entity_Id
:= Empty
;
4883 -- Start of processing for Loop_Entry
4888 -- Set the type of the attribute now to ensure the successful
4889 -- continuation of analysis even if the attribute is misplaced.
4891 Set_Etype
(Attr
, P_Type
);
4893 -- Attribute 'Loop_Entry may appear in several flavors:
4895 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4896 -- nearest enclosing loop.
4898 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4899 -- attribute may be related to a loop denoted by label Expr or
4900 -- the prefix may denote an array object and Expr may act as an
4901 -- indexed component.
4903 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4904 -- to the nearest enclosing loop, all expressions are part of
4905 -- an indexed component.
4907 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4908 -- denotes, the attribute may be related to a loop denoted by
4909 -- label Expr or the prefix may denote a multidimensional array
4910 -- array object and Expr along with the rest of the expressions
4911 -- may act as indexed components.
4913 -- Regardless of variations, the attribute reference does not have an
4914 -- expression list. Instead, all available expressions are stored as
4915 -- indexed components.
4917 -- When the attribute is part of an indexed component, find the first
4918 -- expression as it will determine the semantics of 'Loop_Entry.
4920 -- If the attribute is itself an index in an indexed component, i.e.
4921 -- a member of a list, the context itself is not relevant (the code
4922 -- below would lead to an infinite loop) and the attribute applies
4923 -- to the enclosing loop.
4925 if Nkind
(Context
) = N_Indexed_Component
4926 and then not Is_List_Member
(N
)
4928 E1
:= First
(Expressions
(Context
));
4931 -- The attribute reference appears in the following form:
4933 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4935 -- In this case, the loop name is omitted and no rewriting is
4938 if Present
(E2
) then
4941 -- The form of the attribute is:
4943 -- Prefix'Loop_Entry (Expr) [(...)]
4945 -- If Expr denotes a loop entry, the whole attribute and indexed
4946 -- component will have to be rewritten to reflect this relation.
4949 pragma Assert
(Present
(E1
));
4951 -- Do not expand the expression as it may have side effects.
4952 -- Simply preanalyze to determine whether it is a loop name or
4955 Preanalyze_And_Resolve
(E1
);
4957 if Is_Entity_Name
(E1
)
4958 and then Present
(Entity
(E1
))
4959 and then Ekind
(Entity
(E1
)) = E_Loop
4961 Loop_Id
:= Entity
(E1
);
4963 -- Transform the attribute and enclosing indexed component
4965 Set_Expressions
(N
, Expressions
(Context
));
4966 Rewrite
(Context
, N
);
4967 Set_Etype
(Context
, P_Type
);
4974 -- The prefix must denote an object
4976 if not Is_Object_Reference
(P
) then
4977 Error_Attr_P
("prefix of attribute % must denote an object");
4980 -- The prefix cannot be of a limited type because the expansion of
4981 -- Loop_Entry must create a constant initialized by the evaluated
4984 if Is_Inherently_Limited_Type
(Etype
(P
)) then
4985 Error_Attr_P
("prefix of attribute % cannot be limited");
4988 -- Climb the parent chain to verify the location of the attribute and
4989 -- find the enclosing loop.
4992 while Present
(Stmt
) loop
4994 -- Locate the corresponding enclosing pragma. Note that in the
4995 -- case of Assert[And_Cut] and Assume, we have already checked
4996 -- that the pragma appears in an appropriate loop location.
4998 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
5000 Pragma_Name_Unmapped
(Original_Node
(Stmt
))
5001 in Name_Loop_Invariant
5004 | Name_Assert_And_Cut
5007 Encl_Prag
:= Original_Node
(Stmt
);
5009 -- Locate the enclosing loop (if any). Note that Ada 2012 array
5010 -- iteration may be expanded into several nested loops, we are
5011 -- interested in the outermost one which has the loop identifier,
5012 -- and comes from source.
5014 elsif Nkind
(Stmt
) = N_Loop_Statement
5015 and then Present
(Identifier
(Stmt
))
5016 and then Comes_From_Source
(Original_Node
(Stmt
))
5017 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
5021 -- The original attribute reference may lack a loop name. Use
5022 -- the name of the enclosing loop because it is the related
5025 if No
(Loop_Id
) then
5026 Loop_Id
:= Entity
(Identifier
(Encl_Loop
));
5031 -- Prevent the search from going too far
5033 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
5037 Stmt
:= Parent
(Stmt
);
5040 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
5041 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
5042 -- purpose if they appear in an appropriate location in a loop,
5043 -- which was already checked by the top level pragma circuit).
5045 -- Loop_Entry also denotes a value and as such can appear within an
5046 -- expression that is an argument for another loop aspect. In that
5047 -- case it will have been expanded into the corresponding assignment.
5050 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
5051 and then not Comes_From_Source
(Parent
(N
))
5055 elsif No
(Encl_Prag
) then
5056 Error_Attr
("attribute% must appear within appropriate pragma", N
);
5059 -- A Loop_Entry that applies to a given loop statement must not
5060 -- appear within a body of accept statement, if this construct is
5061 -- itself enclosed by the given loop statement.
5063 for Index
in reverse 0 .. Scope_Stack
.Last
loop
5064 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
5066 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
5068 elsif Ekind
(Scop
) in E_Block | E_Loop | E_Return_Statement
then
5072 ("attribute % cannot appear in body or accept statement", N
);
5076 -- The prefix cannot mention entities declared within the related
5077 -- loop because they will not be visible once the prefix is moved
5078 -- outside the loop.
5080 Check_References_In_Prefix
(Loop_Id
);
5082 -- The prefix must statically name an object if the pragma does not
5083 -- apply to the innermost enclosing loop statement, or if it appears
5084 -- within a potentially unevaluated expression.
5086 if Is_Entity_Name
(P
)
5087 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
5088 or else Statically_Names_Object
(P
)
5092 elsif Present
(Encl_Loop
)
5093 and then Entity
(Identifier
(Encl_Loop
)) /= Loop_Id
5096 ("prefix of attribute % that applies to outer loop must denote "
5099 elsif Is_Potentially_Unevaluated
(P
) then
5103 -- Replace the Loop_Entry attribute reference by its prefix if the
5104 -- related pragma is ignored. This transformation is OK with respect
5105 -- to typing because Loop_Entry's type is that of its prefix. This
5106 -- early transformation also avoids the generation of a useless loop
5109 if Present
(Encl_Prag
) and then Is_Ignored
(Encl_Prag
) then
5110 Rewrite
(N
, Relocate_Node
(P
));
5111 Preanalyze_And_Resolve
(N
);
5114 Preanalyze_And_Resolve
(P
);
5122 -- Shares processing with Ceiling attribute
5128 -- Shares processing with Emax attribute
5134 -- Shares processing with Emax attribute
5136 ----------------------
5137 -- Machine_Mantissa --
5138 ----------------------
5140 -- Shares processing with Emax attribute
5142 -----------------------
5143 -- Machine_Overflows --
5144 -----------------------
5146 when Attribute_Machine_Overflows
5147 | Attribute_Machine_Rounds
5151 Set_Etype
(N
, Standard_Boolean
);
5157 when Attribute_Machine_Radix
5158 | Attribute_Mantissa
5162 Set_Etype
(N
, Universal_Integer
);
5164 ----------------------
5165 -- Machine_Rounding --
5166 ----------------------
5168 -- Shares processing with Ceiling attribute
5170 --------------------
5171 -- Machine_Rounds --
5172 --------------------
5174 -- Shares processing with Machine_Overflows attribute
5180 when Attribute_Machine_Size
5181 | Attribute_Object_Size
5182 | Attribute_Value_Size
5186 Check_Not_Incomplete_Type
;
5187 Set_Etype
(N
, Universal_Integer
);
5193 -- Shares processing with Machine_Radix attribute
5199 when Attribute_Max
=>
5202 ----------------------------------
5203 -- Max_Alignment_For_Allocation --
5204 ----------------------------------
5206 when Attribute_Max_Size_In_Storage_Elements
=>
5207 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5209 ----------------------
5210 -- Max_Integer_Size --
5211 ----------------------
5213 when Attribute_Max_Integer_Size
=>
5214 Standard_Attribute
(System_Max_Integer_Size
);
5216 ----------------------------------
5217 -- Max_Size_In_Storage_Elements --
5218 ----------------------------------
5220 when Attribute_Max_Alignment_For_Allocation
=>
5221 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5223 -----------------------
5224 -- Maximum_Alignment --
5225 -----------------------
5227 when Attribute_Maximum_Alignment
=>
5228 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
5230 --------------------
5231 -- Mechanism_Code --
5232 --------------------
5234 when Attribute_Mechanism_Code
=>
5235 if not Is_Entity_Name
(P
)
5236 or else not Is_Subprogram
(Entity
(P
))
5238 Error_Attr_P
("prefix of % attribute must be subprogram");
5241 Check_Either_E0_Or_E1
;
5243 if Present
(E1
) then
5244 Resolve
(E1
, Any_Integer
);
5245 Set_Etype
(E1
, Standard_Integer
);
5247 if not Is_OK_Static_Expression
(E1
) then
5248 Flag_Non_Static_Expr
5249 ("expression for parameter number must be static!", E1
);
5252 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
5253 or else Intval
(E1
) < 0
5255 Error_Attr
("invalid parameter number for % attribute", E1
);
5259 Set_Etype
(N
, Universal_Integer
);
5265 when Attribute_Min
=>
5272 when Attribute_Mod
=>
5274 -- Note: this attribute is only allowed in Ada 2005 mode, but
5275 -- we do not need to test that here, since Mod is only recognized
5276 -- as an attribute name in Ada 2005 mode during the parse.
5279 Check_Modular_Integer_Type
;
5280 Resolve
(E1
, Any_Integer
);
5281 Set_Etype
(N
, P_Base_Type
);
5287 -- Shares processing with Ceiling attribute
5293 -- Shares processing with Emax attribute
5299 -- Shares processing with Epsilon attribute
5301 --------------------
5302 -- Model_Mantissa --
5303 --------------------
5305 -- Shares processing with Emax attribute
5311 -- Shares processing with Epsilon attribute
5317 when Attribute_Modulus
=>
5319 Check_Modular_Integer_Type
;
5320 Set_Etype
(N
, Universal_Integer
);
5322 --------------------
5323 -- Null_Parameter --
5324 --------------------
5326 when Attribute_Null_Parameter
=> Null_Parameter
: declare
5327 Parnt
: constant Node_Id
:= Parent
(N
);
5328 GParnt
: constant Node_Id
:= Parent
(Parnt
);
5330 procedure Bad_Null_Parameter
(Msg
: String);
5331 -- Used if bad Null parameter attribute node is found. Issues
5332 -- given error message, and also sets the type to Any_Type to
5333 -- avoid blowups later on from dealing with a junk node.
5335 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
5336 -- Called to check that Proc_Ent is imported subprogram
5338 ------------------------
5339 -- Bad_Null_Parameter --
5340 ------------------------
5342 procedure Bad_Null_Parameter
(Msg
: String) is
5344 Error_Msg_N
(Msg
, N
);
5345 Set_Etype
(N
, Any_Type
);
5346 end Bad_Null_Parameter
;
5348 ----------------------
5349 -- Must_Be_Imported --
5350 ----------------------
5352 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
5353 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
5356 -- Ignore check if procedure not frozen yet (we will get
5357 -- another chance when the default parameter is reanalyzed)
5359 if not Is_Frozen
(Pent
) then
5362 elsif not Is_Imported
(Pent
) then
5364 ("Null_Parameter can only be used with imported subprogram");
5369 end Must_Be_Imported
;
5371 -- Start of processing for Null_Parameter
5376 Set_Etype
(N
, P_Type
);
5378 -- Case of attribute used as default expression
5380 if Nkind
(Parnt
) = N_Parameter_Specification
then
5381 Must_Be_Imported
(Defining_Entity
(GParnt
));
5383 -- Case of attribute used as actual for subprogram (positional)
5385 elsif Nkind
(Parnt
) in N_Subprogram_Call
5386 and then Is_Entity_Name
(Name
(Parnt
))
5388 Must_Be_Imported
(Entity
(Name
(Parnt
)));
5390 -- Case of attribute used as actual for subprogram (named)
5392 elsif Nkind
(Parnt
) = N_Parameter_Association
5393 and then Nkind
(GParnt
) in N_Subprogram_Call
5394 and then Is_Entity_Name
(Name
(GParnt
))
5396 Must_Be_Imported
(Entity
(Name
(GParnt
)));
5398 -- Not an allowed case
5402 ("Null_Parameter must be actual or default parameter");
5410 -- Shares processing with Machine_Size attribute
5416 when Attribute_Old
=> Old
: declare
5417 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
5418 -- Inspect the contents of the prefix and detect illegal uses of a
5419 -- nested 'Old, attribute 'Result or a use of an entity declared in
5420 -- the related postcondition expression. Subp_Id is the subprogram to
5421 -- which the related postcondition applies.
5423 --------------------------------
5424 -- Check_References_In_Prefix --
5425 --------------------------------
5427 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
5428 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
5429 -- Detect attribute 'Old, attribute 'Result of a use of an entity
5430 -- and perform the appropriate semantic check.
5432 ---------------------
5433 -- Check_Reference --
5434 ---------------------
5436 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
5438 -- Attributes 'Old and 'Result cannot appear in the prefix of
5439 -- another attribute 'Old.
5441 if Nkind
(Nod
) = N_Attribute_Reference
5442 and then Attribute_Name
(Nod
) in Name_Old | Name_Result
5444 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
5445 Error_Msg_Name_2
:= Name_Old
;
5447 ("attribute % cannot appear in the prefix of attribute %",
5451 -- Entities mentioned within the prefix of attribute 'Old must
5452 -- be global to the related postcondition. If this is not the
5453 -- case, then the scope of the local entity is nested within
5454 -- that of the subprogram. Moreover, we need to know whether
5455 -- Entity (Nod) occurs in the tree rooted at the prefix to
5456 -- ensure the entity is not declared within then prefix itself.
5458 elsif Is_Entity_Name
(Nod
)
5459 and then Present
(Entity
(Nod
))
5460 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
5461 and then not In_Subtree
(Entity
(Nod
), P
)
5464 ("prefix of attribute % cannot reference local entities",
5467 -- Otherwise keep inspecting the prefix
5472 end Check_Reference
;
5474 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
5476 -- Start of processing for Check_References_In_Prefix
5479 Check_References
(P
);
5480 end Check_References_In_Prefix
;
5485 Pref_Id
: Entity_Id
;
5486 Pref_Typ
: Entity_Id
;
5487 Spec_Id
: Entity_Id
;
5489 -- Start of processing for Old
5492 -- The attribute reference is a primary. If any expressions follow,
5493 -- then the attribute reference is an indexable object. Transform the
5494 -- attribute into an indexed component and analyze it.
5496 if Present
(E1
) then
5498 Make_Indexed_Component
(Loc
,
5500 Make_Attribute_Reference
(Loc
,
5501 Prefix
=> Relocate_Node
(P
),
5502 Attribute_Name
=> Name_Old
),
5503 Expressions
=> Expressions
(N
)));
5508 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5510 -- The aspect or pragma where attribute 'Old resides should be
5511 -- associated with a subprogram declaration or a body. If this is not
5512 -- the case, then the aspect or pragma is illegal. Return as analysis
5513 -- cannot be carried out.
5515 -- The exception to this rule is when generating C since in this case
5516 -- postconditions are inlined.
5519 and then Modify_Tree_For_C
5520 and then In_Inlined_Body
5522 Spec_Id
:= Entity
(P
);
5524 elsif not Legal
then
5528 -- The prefix must be preanalyzed as the full analysis will take
5529 -- place during expansion.
5531 Preanalyze_And_Resolve
(P
);
5533 -- Ensure that the prefix does not contain attributes 'Old or 'Result
5535 Check_References_In_Prefix
(Spec_Id
);
5537 -- Set the type of the attribute now to prevent cascaded errors
5539 Pref_Typ
:= Etype
(P
);
5540 Set_Etype
(N
, Pref_Typ
);
5544 if Is_Limited_Type
(Pref_Typ
) then
5545 Error_Attr
("attribute % cannot apply to limited objects", P
);
5548 -- The prefix is a simple name
5550 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
5551 Pref_Id
:= Entity
(P
);
5553 -- Emit a warning when the prefix is a constant. Note that the use
5554 -- of Error_Attr would reset the type of N to Any_Type even though
5555 -- this is a warning. Use Error_Msg_XXX instead.
5557 if Is_Constant_Object
(Pref_Id
) then
5558 Error_Msg_Name_1
:= Name_Old
;
5560 ("??attribute % applied to constant has no effect", P
);
5563 -- Otherwise the prefix is not a simple name
5566 -- Ensure that the prefix of attribute 'Old is an entity when it
5567 -- is potentially unevaluated (6.1.1 (27/3)). This rule is
5568 -- relaxed in Ada 2022 - this relaxation is reflected in the
5569 -- call (below) to Eligible_For_Conditional_Evaluation.
5571 if Is_Potentially_Unevaluated
(N
)
5572 and then not Statically_Names_Object
(P
)
5574 Old_Attr_Util
.Conditional_Evaluation
5575 .Eligible_For_Conditional_Evaluation
(N
)
5579 -- Detect a possible infinite recursion when the prefix denotes
5580 -- the related function.
5582 -- function Func (...) return ...
5583 -- with Post => Func'Old ...;
5585 -- The function may be specified in qualified form X.Y where X is
5586 -- a protected object and Y is a protected function. In that case
5587 -- ensure that the qualified form has an entity.
5589 elsif Nkind
(P
) = N_Function_Call
5590 and then Nkind
(Name
(P
)) in N_Has_Entity
5592 Pref_Id
:= Entity
(Name
(P
));
5594 if Ekind
(Spec_Id
) in E_Function | E_Generic_Function
5595 and then Pref_Id
= Spec_Id
5597 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5598 Error_Msg_N
("!possible infinite recursion<<", P
);
5599 Error_Msg_N
("\!??Storage_Error ]<<", P
);
5603 -- The prefix of attribute 'Old may refer to a component of a
5604 -- formal parameter. In this case its expansion may generate
5605 -- actual subtypes that are referenced in an inner context and
5606 -- that must be elaborated within the subprogram itself. If the
5607 -- prefix includes a function call, it may involve finalization
5608 -- actions that should be inserted when the attribute has been
5609 -- rewritten as a declaration. Create a declaration for the prefix
5610 -- and insert it at the start of the enclosing subprogram. This is
5611 -- an expansion activity that has to be performed now to prevent
5612 -- out-of-order issues.
5614 -- This expansion is both harmful and not needed in SPARK mode,
5615 -- since the formal verification back end relies on the types of
5616 -- nodes (hence is not robust w.r.t. a change to base type here),
5617 -- and does not suffer from the out-of-order issue described
5618 -- above. Thus, this expansion is skipped in SPARK mode.
5620 -- The expansion is not relevant for discrete types, which will
5621 -- not generate extra declarations, and where use of the base type
5622 -- may lead to spurious errors if context is a case.
5624 if not GNATprove_Mode
then
5625 if not Is_Discrete_Type
(Pref_Typ
) then
5626 Pref_Typ
:= Base_Type
(Pref_Typ
);
5629 Set_Etype
(N
, Pref_Typ
);
5630 Set_Etype
(P
, Pref_Typ
);
5632 Analyze_Dimension
(N
);
5642 when Attribute_Output
=>
5644 Check_Stream_Attribute
(TSS_Stream_Output
);
5645 Set_Etype
(N
, Standard_Void_Type
);
5646 Resolve
(N
, Standard_Void_Type
);
5652 when Attribute_Partition_ID
=>
5655 if P_Type
/= Any_Type
then
5656 if not Is_Library_Level_Entity
(Entity
(P
)) then
5658 ("prefix of % attribute must be library-level entity");
5660 -- The defining entity of prefix should not be declared inside a
5661 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5663 elsif Is_Entity_Name
(P
)
5664 and then Is_Pure
(Entity
(P
))
5666 Error_Attr_P
("prefix of% attribute must not be declared pure");
5670 Set_Etype
(N
, Universal_Integer
);
5672 -------------------------
5673 -- Passed_By_Reference --
5674 -------------------------
5676 when Attribute_Passed_By_Reference
=>
5679 Check_Not_Incomplete_Type
;
5680 Set_Etype
(N
, Standard_Boolean
);
5686 when Attribute_Pool_Address
=>
5688 Set_Etype
(N
, RTE
(RE_Address
));
5694 when Attribute_Pos
=>
5695 Check_Discrete_Type
;
5697 Resolve
(E1
, P_Base_Type
);
5698 Set_Etype
(N
, Universal_Integer
);
5704 -- Shares processing with First_Bit attribute
5715 Resolve
(E1
, P_Base_Type
);
5716 Set_Etype
(N
, P_Base_Type
);
5718 -- Since Pred/Succ work on the base type, we normally do no check for
5719 -- the floating-point case, since the base type is unconstrained. But
5720 -- we make an exception in Check_Float_Overflow mode.
5722 if Is_Floating_Point_Type
(P_Type
) then
5723 if not Range_Checks_Suppressed
(P_Base_Type
) then
5724 Set_Do_Range_Check
(E1
);
5727 -- If not modular type, test for overflow check required
5730 if not Is_Modular_Integer_Type
(P_Type
)
5731 and then not Range_Checks_Suppressed
(P_Base_Type
)
5733 Enable_Range_Check
(E1
);
5737 ----------------------------------
5738 -- Preelaborable_Initialization --
5739 ----------------------------------
5741 when Attribute_Preelaborable_Initialization
=>
5745 -- If we're in an instance, we know that the legality of the
5746 -- attribute prefix type was already checked in the generic.
5748 if not In_Instance
then
5750 -- If the prefix type is a generic formal type, then it must be
5751 -- either a formal private type or a formal derived type.
5753 if Is_Generic_Type
(P_Type
) then
5754 if not Is_Private_Type
(P_Type
)
5755 and then not Is_Derived_Type
(P_Type
)
5757 Error_Attr_P
("formal type prefix of % attribute must be "
5758 & "formal private or formal derived type");
5761 -- Otherwise, the prefix type must be a nonformal composite
5762 -- type declared within the visible part of a package or
5765 elsif not Is_Composite_Type
(P_Type
)
5766 or else not Original_View_In_Visible_Part
(P_Type
)
5769 ("prefix of % attribute must be composite type declared "
5770 & "in visible part of a package or generic package");
5774 Set_Etype
(N
, Standard_Boolean
);
5780 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5782 when Attribute_Priority
=>
5783 if Ada_Version
< Ada_2005
then
5784 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5789 Check_Restriction
(No_Dynamic_Priorities
, N
);
5791 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5793 if Is_Protected_Type
(Etype
(P
))
5794 or else (Is_Access_Type
(Etype
(P
))
5795 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5799 Error_Attr_P
("prefix of % attribute must be a protected object");
5802 Set_Etype
(N
, Standard_Integer
);
5804 -- Must be called from within a protected procedure or entry of the
5805 -- protected object.
5812 while S
/= Etype
(P
)
5813 and then S
/= Standard_Standard
5818 if S
= Standard_Standard
then
5819 Error_Attr
("the attribute % is only allowed inside protected "
5824 Validate_Non_Static_Attribute_Function_Call
;
5830 when Attribute_Put_Image
=>
5832 Check_Put_Image_Attribute
;
5833 Set_Etype
(N
, Standard_Void_Type
);
5834 Resolve
(N
, Standard_Void_Type
);
5840 when Attribute_Range
=>
5841 Check_Array_Or_Scalar_Type
;
5842 Bad_Attribute_For_Predicate
;
5844 if Ada_Version
= Ada_83
5845 and then Is_Scalar_Type
(P_Type
)
5846 and then Comes_From_Source
(N
)
5849 ("(Ada 83) % attribute not allowed for scalar type", P
);
5856 when Attribute_Result
=> Result
: declare
5857 function Denote_Same_Function
5858 (Pref_Id
: Entity_Id
;
5859 Spec_Id
: Entity_Id
) return Boolean;
5860 -- Determine whether the entity of the prefix Pref_Id denotes the
5861 -- same entity as that of the related subprogram Spec_Id.
5863 --------------------------
5864 -- Denote_Same_Function --
5865 --------------------------
5867 function Denote_Same_Function
5868 (Pref_Id
: Entity_Id
;
5869 Spec_Id
: Entity_Id
) return Boolean
5871 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5872 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5875 -- The prefix denotes the related subprogram
5877 if Pref_Id
= Spec_Id
then
5880 -- Account for a special case when attribute 'Result appears in
5881 -- the postcondition of a generic function.
5884 -- function Gen_Func return ...
5885 -- with Post => Gen_Func'Result ...;
5887 -- When the generic function is instantiated, the Chars field of
5888 -- the instantiated prefix still denotes the name of the generic
5889 -- function. Note that any preemptive transformation is impossible
5890 -- without a proper analysis. The structure of the wrapper package
5893 -- package Anon_Gen_Pack is
5894 -- <subtypes and renamings>
5895 -- function Subp_Decl return ...; -- (!)
5896 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5897 -- function Gen_Func ... renames Subp_Decl;
5898 -- end Anon_Gen_Pack;
5900 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5901 and then Present
(Generic_Parent
(Subp_Spec
))
5902 and then Ekind
(Pref_Id
) in E_Generic_Function | E_Function
5904 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5907 elsif Present
(Alias
(Pref_Id
))
5908 and then Alias
(Pref_Id
) = Spec_Id
5913 -- Account for a special case where a primitive of a tagged type
5914 -- inherits a class-wide postcondition from a parent type. In this
5915 -- case the prefix of attribute 'Result denotes the overriding
5918 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5921 -- When a qualified name is used for the prefix, homonyms may come
5922 -- before the current function in the homonym chain.
5924 elsif Has_Homonym
(Pref_Id
)
5925 and then Present
(Homonym
(Pref_Id
))
5927 return Denote_Same_Function
(Homonym
(Pref_Id
), Spec_Id
);
5930 -- Otherwise the prefix does not denote the related subprogram
5933 end Denote_Same_Function
;
5937 In_Inlined_C_Postcondition
: constant Boolean :=
5939 and then In_Inlined_Body
;
5942 Pref_Id
: Entity_Id
;
5943 Spec_Id
: Entity_Id
;
5945 -- Start of processing for Result
5948 -- The attribute reference is a primary. If any expressions follow,
5949 -- then the attribute reference is an indexable object. Transform the
5950 -- attribute into an indexed component and analyze it.
5952 if Present
(E1
) then
5954 Make_Indexed_Component
(Loc
,
5956 Make_Attribute_Reference
(Loc
,
5957 Prefix
=> Relocate_Node
(P
),
5958 Attribute_Name
=> Name_Result
),
5959 Expressions
=> Expressions
(N
)));
5964 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5966 -- The aspect or pragma where attribute 'Result resides should be
5967 -- associated with a subprogram declaration or a body. If this is not
5968 -- the case, then the aspect or pragma is illegal. Return as analysis
5969 -- cannot be carried out.
5971 -- The exception to this rule is when generating C since in this case
5972 -- postconditions are inlined.
5974 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5975 Spec_Id
:= Entity
(P
);
5977 elsif not Legal
then
5978 Error_Attr
("prefix of % attribute must be a function", P
);
5981 -- Attribute 'Result is part of postconditions expansion. There is
5982 -- no need to perform the semantic checks below as they were already
5983 -- verified when the attribute was analyzed in its original context.
5984 -- Instead, rewrite the attribute as a reference to formal parameter
5985 -- _Result of the _Wrapped_Statements procedure.
5987 if Chars
(Spec_Id
) = Name_uWrapped_Statements
5989 (In_Inlined_C_Postcondition
5990 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5992 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5994 -- The type of formal parameter _Result is that of the function
5995 -- encapsulating the _Postconditions procedure. Resolution must
5996 -- be carried out against the function return type.
5998 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
6000 -- Otherwise attribute 'Result appears in its original context and
6001 -- all semantic checks should be carried out.
6004 -- Verify the legality of the prefix. It must denotes the entity
6005 -- of the related [generic] function.
6007 if Is_Entity_Name
(P
) then
6008 Pref_Id
:= Entity
(P
);
6010 -- Either both the prefix and the annotated spec must be
6011 -- generic functions, or they both must be nongeneric
6012 -- functions, or the prefix must be generic and the spec
6013 -- must be nongeneric (i.e. it must denote an instance).
6015 if (Ekind
(Pref_Id
) in E_Function | E_Generic_Function
6016 and then Ekind
(Pref_Id
) = Ekind
(Spec_Id
))
6018 (Ekind
(Pref_Id
) = E_Generic_Function
6019 and then Ekind
(Spec_Id
) = E_Function
)
6021 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
6023 -- Correct the prefix of the attribute when the context
6024 -- is a generic function.
6026 if Pref_Id
/= Spec_Id
then
6027 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
6031 Set_Etype
(N
, Etype
(Spec_Id
));
6033 -- Otherwise the prefix denotes some unrelated function
6036 Error_Msg_Name_2
:= Chars
(Spec_Id
);
6038 ("incorrect prefix for attribute %, expected %", P
);
6041 -- If the prefix is an access-to-subprogram type, then it must
6042 -- be the same as the annotated type.
6044 elsif Is_Access_Subprogram_Type
(Pref_Id
) then
6045 if Pref_Id
= Spec_Id
then
6046 Set_Etype
(N
, Etype
(Designated_Type
(Spec_Id
)));
6048 Error_Msg_Name_2
:= Chars
(Spec_Id
);
6050 ("incorrect prefix for attribute %, expected %", P
);
6053 -- Otherwise the prefix denotes some other form of subprogram
6058 ("attribute % can only appear in postcondition of "
6062 -- Otherwise the prefix is illegal
6065 Error_Msg_Name_2
:= Chars
(Spec_Id
);
6066 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
6075 when Attribute_Range_Length
=>
6077 Check_Discrete_Type
;
6078 Set_Etype
(N
, Universal_Integer
);
6084 when Attribute_Reduce
=>
6086 Error_Msg_Ada_2022_Feature
("Reduce attribute", Sloc
(N
));
6089 Stream
: constant Node_Id
:= Prefix
(N
);
6092 if Nkind
(Stream
) /= N_Aggregate
then
6093 -- Prefix is a name, as for other attributes.
6095 -- If the object is a function we asume that it is not
6096 -- overloaded. AI12-242 does not suggest a name resolution
6097 -- rule for that case, but we can suppose that the expected
6098 -- type of the reduction is the expected type of the component
6101 Analyze_And_Resolve
(Stream
);
6102 Typ
:= Etype
(Stream
);
6104 -- Verify that prefix can be iterated upon.
6106 if Is_Array_Type
(Typ
)
6107 or else Has_Aspect
(Typ
, Aspect_Default_Iterator
)
6108 or else Has_Aspect
(Typ
, Aspect_Iterable
)
6113 ("cannot apply Reduce to object of type&", N
, Typ
);
6116 elsif Present
(Expressions
(Stream
))
6117 or else No
(Component_Associations
(Stream
))
6118 or else Nkind
(First
(Component_Associations
(Stream
))) /=
6119 N_Iterated_Component_Association
6122 ("prefix of Reduce must be an iterated component", N
);
6127 Set_Etype
(N
, Etype
(E2
));
6134 when Attribute_Read
=>
6136 Check_Stream_Attribute
(TSS_Stream_Read
);
6137 Set_Etype
(N
, Standard_Void_Type
);
6138 Resolve
(N
, Standard_Void_Type
);
6139 Note_Possible_Modification
(E2
, Sure
=> True);
6145 when Attribute_Ref
=>
6148 if Nkind
(P
) /= N_Expanded_Name
6149 or else not Is_RTE
(P_Type
, RE_Address
)
6151 Error_Attr_P
("prefix of % attribute must be System.Address");
6154 Analyze_And_Resolve
(E1
, Any_Integer
);
6155 Set_Etype
(N
, RTE
(RE_Address
));
6161 -- Shares processing with Adjacent attribute
6163 ---------------------
6164 -- Restriction_Set --
6165 ---------------------
6167 when Attribute_Restriction_Set
=> Restriction_Set
: declare
6170 Unam
: Unit_Name_Type
;
6174 Check_System_Prefix
;
6176 -- No_Dependence case
6178 if Nkind
(E1
) = N_Parameter_Association
then
6179 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
6180 U
:= Explicit_Actual_Parameter
(E1
);
6182 if not OK_No_Dependence_Unit_Name
(U
) then
6183 Set_Boolean_Result
(N
, False);
6187 -- See if there is an entry already in the table. That's the
6188 -- case in which we can return True.
6190 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
6191 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
6192 and then No_Dependences
.Table
(J
).Warn
= False
6194 Set_Boolean_Result
(N
, True);
6199 -- If not in the No_Dependence table, result is False
6201 Set_Boolean_Result
(N
, False);
6203 -- In this case, we must ensure that the binder will reject any
6204 -- other unit in the partition that sets No_Dependence for this
6205 -- unit. We do that by making an entry in the special table kept
6206 -- for this purpose (if the entry is not there already).
6208 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
6210 for J
in Restriction_Set_Dependences
.First
..
6211 Restriction_Set_Dependences
.Last
6213 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
6218 Restriction_Set_Dependences
.Append
(Unam
);
6220 -- Normal restriction case
6223 if Nkind
(E1
) /= N_Identifier
then
6224 Set_Boolean_Result
(N
, False);
6225 Error_Attr
("attribute % requires restriction identifier", E1
);
6228 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
6230 if R
= Not_A_Restriction_Id
then
6231 Set_Boolean_Result
(N
, False);
6232 Error_Msg_Node_1
:= E1
;
6233 Error_Attr
("invalid restriction identifier &", E1
);
6235 elsif R
not in Partition_Boolean_Restrictions
then
6236 Set_Boolean_Result
(N
, False);
6237 Error_Msg_Node_1
:= E1
;
6239 ("& is not a boolean partition-wide restriction", E1
);
6242 if Restriction_Active
(R
) then
6243 Set_Boolean_Result
(N
, True);
6245 Check_Restriction
(R
, N
);
6246 Set_Boolean_Result
(N
, False);
6250 end Restriction_Set
;
6256 when Attribute_Round
=>
6258 Check_Decimal_Fixed_Point_Type
;
6259 Set_Etype
(N
, P_Base_Type
);
6261 -- Because the context is universal_real (3.5.10(12)) it is a
6262 -- legal context for a universal fixed expression. This is the
6263 -- only attribute whose functional description involves U_R.
6265 if Etype
(E1
) = Universal_Fixed
then
6267 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
6268 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
6269 Expression
=> Relocate_Node
(E1
));
6277 Resolve
(E1
, Any_Real
);
6283 -- Shares processing with Ceiling attribute
6289 -- Shares processing with Emax attribute
6295 -- Shares processing with Epsilon attribute
6301 -- Shares processing with Large attribute
6307 -- Shares processing with Epsilon attribute
6313 -- Shares processing with Large attribute
6315 --------------------------
6316 -- Scalar_Storage_Order --
6317 --------------------------
6319 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
6320 Ent
: Entity_Id
:= Empty
;
6326 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
6328 -- The attribute applies to generic private types (in which case
6329 -- the legality rule is applied in the instance) as well as to
6330 -- composite types. For noncomposite types it always returns the
6331 -- default bit order for the target.
6332 -- Allowing formal private types was originally introduced in
6333 -- GNAT_Mode only, to compile instances of Sequential_IO, but
6334 -- users find it more generally useful in generic units.
6336 if not (Is_Generic_Type
(P_Type
) and then Is_Private_Type
(P_Type
))
6337 and then not In_Instance
6340 ("prefix of % attribute must be record or array type");
6342 elsif not Is_Generic_Type
(P_Type
) then
6343 if Bytes_Big_Endian
then
6344 Ent
:= RTE
(RE_High_Order_First
);
6346 Ent
:= RTE
(RE_Low_Order_First
);
6350 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
6351 Ent
:= RTE
(RE_High_Order_First
);
6354 Ent
:= RTE
(RE_Low_Order_First
);
6357 if Present
(Ent
) then
6358 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
6361 Set_Etype
(N
, RTE
(RE_Bit_Order
));
6364 -- Reset incorrect indication of staticness
6366 Set_Is_Static_Expression
(N
, False);
6367 end Scalar_Storage_Order
;
6373 when Attribute_Scale
=>
6375 Check_Decimal_Fixed_Point_Type
;
6376 Set_Etype
(N
, Universal_Integer
);
6382 -- Shares processing with Compose attribute
6388 -- Shares processing with Denorm attribute
6395 | Attribute_VADS_Size
6399 -- If prefix is parameterless function call, rewrite and resolve
6402 if Is_Entity_Name
(P
)
6403 and then Ekind
(Entity
(P
)) = E_Function
6407 -- Similar processing for a protected function call
6409 elsif Nkind
(P
) = N_Selected_Component
6410 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
6415 if Is_Object_Reference
(P
) then
6416 Check_Object_Reference
(P
);
6418 elsif Is_Entity_Name
(P
)
6419 and then (Is_Type
(Entity
(P
))
6420 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6424 elsif Nkind
(P
) = N_Type_Conversion
6425 and then not Comes_From_Source
(P
)
6429 -- Some other compilers allow dubious use of X'???'Size
6431 elsif Relaxed_RM_Semantics
6432 and then Nkind
(P
) = N_Attribute_Reference
6437 Error_Attr_P
("invalid prefix for % attribute");
6440 Check_Not_Incomplete_Type
;
6442 Set_Etype
(N
, Universal_Integer
);
6444 -- If we are processing pragmas Compile_Time_Warning and Compile_
6445 -- Time_Errors after the back end has been called and this occurrence
6446 -- of 'Size is known at compile time then it is safe to perform this
6447 -- evaluation. Needed to perform the static evaluation of the full
6448 -- boolean expression of these pragmas. Note that Known_RM_Size is
6449 -- sometimes True when Size_Known_At_Compile_Time is False, when the
6450 -- back end has computed it.
6452 if In_Compile_Time_Warning_Or_Error
6453 and then Is_Entity_Name
(P
)
6454 and then (Is_Type
(Entity
(P
))
6455 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6456 and then (Known_RM_Size
(Entity
(P
))
6457 or else Size_Known_At_Compile_Time
(Entity
(P
)))
6460 Prefix_E
: Entity_Id
:= Entity
(P
);
6464 -- Handle private and incomplete types
6466 if Present
(Underlying_Type
(Prefix_E
)) then
6467 Prefix_E
:= Underlying_Type
(Prefix_E
);
6470 if Known_Static_RM_Size
(Prefix_E
) then
6471 Siz
:= RM_Size
(Prefix_E
);
6473 Siz
:= Esize
(Prefix_E
);
6476 -- Protect the frontend against cases where the attribute
6477 -- Size_Known_At_Compile_Time is set, but the Esize value
6478 -- is not available (see Einfo.ads).
6480 if Present
(Siz
) then
6481 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Siz
));
6491 -- Shares processing with Large attribute
6493 ---------------------------------------
6494 -- Small_Denominator/Small_Numerator --
6495 ---------------------------------------
6497 when Attribute_Small_Denominator
6498 | Attribute_Small_Numerator
6500 Check_Fixed_Point_Type_0
;
6501 Set_Etype
(N
, Universal_Integer
);
6507 when Attribute_Storage_Pool
6508 | Attribute_Simple_Storage_Pool
6512 if Is_Access_Type
(P_Type
) then
6513 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6515 ("cannot use % attribute for access-to-subprogram type");
6518 -- Set appropriate entity
6520 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
6521 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
6523 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
6526 if Attr_Id
= Attribute_Storage_Pool
then
6527 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6528 Name_Simple_Storage_Pool_Type
))
6530 Error_Msg_Name_1
:= Aname
;
6531 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6533 ("cannot use % attribute for type with simple storage "
6535 Error_Msg_N
("\Program_Error [<<", N
);
6538 (N
, Make_Raise_Program_Error
6539 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
6542 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6544 -- In the Simple_Storage_Pool case, verify that the pool entity is
6545 -- actually of a simple storage pool type, and set the attribute's
6546 -- type to the pool object's type.
6549 if No
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6550 Name_Simple_Storage_Pool_Type
))
6553 ("cannot use % attribute for type without simple " &
6557 Set_Etype
(N
, Etype
(Entity
(N
)));
6560 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6561 -- Storage_Pool since this attribute is not defined for such
6562 -- types (RM E.2.2(17)).
6564 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6567 Error_Attr_P
("prefix of % attribute must be access type");
6574 when Attribute_Storage_Size
=>
6577 if Is_Task_Type
(P_Type
) then
6578 Set_Etype
(N
, Universal_Integer
);
6580 -- Use with tasks is an obsolescent feature
6582 Check_Restriction
(No_Obsolescent_Features
, P
);
6584 elsif Is_Access_Type
(P_Type
) then
6585 Set_Etype
(N
, Universal_Integer
);
6587 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6589 ("cannot use % attribute for access-to-subprogram type");
6592 if Is_Entity_Name
(P
)
6593 and then Is_Type
(Entity
(P
))
6597 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6598 -- Storage_Size since this attribute is not defined for
6599 -- such types (RM E.2.2(17)).
6601 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6603 -- The prefix is allowed to be an implicit dereference of an
6604 -- access value designating a task.
6611 Error_Attr_P
("prefix of % attribute must be access or task type");
6618 when Attribute_Storage_Unit
=>
6619 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
6625 when Attribute_Stream_Size
=>
6629 if Is_Entity_Name
(P
)
6630 and then Is_Elementary_Type
(Entity
(P
))
6632 Set_Etype
(N
, Universal_Integer
);
6634 Error_Attr_P
("invalid prefix for % attribute");
6641 when Attribute_Stub_Type
=>
6645 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
6647 -- For a real RACW [sub]type, use corresponding stub type
6649 if not Is_Generic_Type
(P_Type
) then
6652 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
6654 -- For a generic type (that has been marked as an RACW using the
6655 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
6656 -- type. Note that if the actual is not a remote access type, the
6657 -- instantiation will fail.
6660 -- Note: we go to the underlying type here because the view
6661 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
6665 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
6670 ("prefix of% attribute must be remote access-to-class-wide");
6677 -- Shares processing with Pred attribute
6679 --------------------------------
6680 -- System_Allocator_Alignment --
6681 --------------------------------
6683 when Attribute_System_Allocator_Alignment
=>
6684 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
6690 when Attribute_Tag
=>
6694 if not Is_Tagged_Type
(P_Type
) then
6695 Error_Attr_P
("prefix of % attribute must be tagged");
6697 -- Next test does not apply to generated code why not, and what does
6698 -- the illegal reference mean???
6700 elsif Is_Object_Reference
(P
)
6701 and then not Is_Class_Wide_Type
(P_Type
)
6702 and then Comes_From_Source
(N
)
6705 ("% attribute can only be applied to objects " &
6706 "of class-wide type");
6709 -- The prefix cannot be an incomplete type. However, references to
6710 -- 'Tag can be generated when expanding interface conversions, and
6713 if Comes_From_Source
(N
) then
6714 Check_Not_Incomplete_Type
;
6716 -- 'Tag requires visibility on the corresponding package holding
6717 -- the tag, so record a reference here, to avoid spurious unused
6718 -- with_clause reported when compiling the main unit.
6720 if In_Extended_Main_Source_Unit
(Current_Scope
) then
6721 Set_Referenced
(P_Type
, True);
6722 Set_Referenced
(Scope
(P_Type
), True);
6726 -- Set appropriate type
6728 Set_Etype
(N
, RTE
(RE_Tag
));
6734 when Attribute_Target_Name
=> Target_Name
: declare
6735 TN
: constant String := Sdefault
.Target_Name
.all;
6739 Check_Standard_Prefix
;
6743 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6748 Make_String_Literal
(Loc
,
6749 Strval
=> TN
(TN
'First .. TL
)));
6750 Analyze_And_Resolve
(N
, Standard_String
);
6751 Set_Is_Static_Expression
(N
, True);
6758 -- Shares processing with Callable attribute
6764 when Attribute_To_Address
=> To_Address
: declare
6768 Check_System_Prefix
;
6770 Generate_Reference
(RTE
(RE_Address
), P
);
6771 Analyze_And_Resolve
(E1
, Any_Integer
);
6772 Set_Etype
(N
, RTE
(RE_Address
));
6773 Set_Is_Static_Expression
(N
, Is_Static_Expression
(E1
));
6775 -- OK static expression case, check range and set appropriate type
6777 if Is_OK_Static_Expression
(E1
) then
6778 Val
:= Expr_Value
(E1
);
6780 if Val
< -(Uint_2
** (System_Address_Size
- 1))
6782 Val
> Uint_2
** System_Address_Size
- 1
6784 Error_Attr
("address value out of range for % attribute", E1
);
6787 -- In most cases the expression is a numeric literal or some other
6788 -- address expression, but if it is a declared constant it may be
6789 -- of a compatible type that must be left on the node.
6791 if Is_Entity_Name
(E1
) then
6794 -- Set type to universal integer if negative
6797 Set_Etype
(E1
, Universal_Integer
);
6799 -- Otherwise set type to Unsigned_64 to accommodate large values
6802 Set_Etype
(E1
, Standard_Unsigned_64
);
6811 when Attribute_To_Any
=>
6813 Check_PolyORB_Attribute
;
6814 Set_Etype
(N
, RTE
(RE_Any
));
6820 -- Shares processing with Ceiling attribute
6826 when Attribute_Type_Class
=>
6829 Check_Not_Incomplete_Type
;
6830 Set_Etype
(N
, RTE
(RE_Type_Class
));
6836 when Attribute_TypeCode
=>
6838 Check_PolyORB_Attribute
;
6839 Set_Etype
(N
, RTE
(RE_TypeCode
));
6845 when Attribute_Type_Key
=> Type_Key
: declare
6846 Full_Name
: constant String_Id
:=
6847 Fully_Qualified_Name_String
(Entity
(P
));
6850 -- The computed signature for the type
6853 -- To simplify the handling of mutually recursive types, follow a
6854 -- single dereference link in a composite type.
6856 procedure Compute_Type_Key
(T
: Entity_Id
);
6857 -- Create a CRC integer from the declaration of the type. For a
6858 -- composite type, fold in the representation of its components in
6859 -- recursive fashion. We use directly the source representation of
6860 -- the types involved.
6862 ----------------------
6863 -- Compute_Type_Key --
6864 ----------------------
6866 procedure Compute_Type_Key
(T
: Entity_Id
) is
6867 Buffer
: Source_Buffer_Ptr
;
6871 SFI
: Source_File_Index
;
6873 procedure Process_One_Declaration
;
6874 -- Update CRC with the characters of one type declaration, or a
6875 -- representation pragma that applies to the type.
6877 -----------------------------
6878 -- Process_One_Declaration --
6879 -----------------------------
6881 procedure Process_One_Declaration
is
6883 -- Scan type declaration, skipping blanks
6885 for Ptr
in P_Min
.. P_Max
loop
6886 if Buffer
(Ptr
) /= ' ' then
6887 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6890 end Process_One_Declaration
;
6892 -- Start of processing for Compute_Type_Key
6895 if Is_Itype
(T
) then
6899 -- If the type is declared in Standard, there is no source, so
6900 -- just use its name.
6902 if Scope
(T
) = Standard_Standard
then
6904 Name
: constant String := Get_Name_String
(Chars
(T
));
6906 for J
in Name
'Range loop
6907 System
.CRC32
.Update
(CRC
, Name
(J
));
6914 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6915 SFI
:= Get_Source_File_Index
(P_Min
);
6916 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6917 Buffer
:= Source_Text
(SFI
);
6919 Process_One_Declaration
;
6921 -- Recurse on relevant component types
6923 if Is_Array_Type
(T
) then
6924 Compute_Type_Key
(Component_Type
(T
));
6926 elsif Is_Access_Type
(T
) then
6929 Compute_Type_Key
(Designated_Type
(T
));
6932 elsif Is_Derived_Type
(T
) then
6933 Compute_Type_Key
(Etype
(T
));
6935 elsif Is_Record_Type
(T
) then
6939 Comp
:= First_Component
(T
);
6940 while Present
(Comp
) loop
6941 Compute_Type_Key
(Etype
(Comp
));
6942 Next_Component
(Comp
);
6947 if Is_First_Subtype
(T
) then
6949 -- Fold in representation aspects for the type, which appear in
6950 -- the same source buffer. If the representation aspects are in
6951 -- a different source file, then skip them; they apply to some
6952 -- other type, perhaps one we're derived from.
6954 Rep
:= First_Rep_Item
(T
);
6956 while Present
(Rep
) loop
6957 if Comes_From_Source
(Rep
) then
6958 Sloc_Range
(Rep
, P_Min
, P_Max
);
6960 if SFI
= Get_Source_File_Index
(P_Min
) then
6961 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6962 Process_One_Declaration
;
6966 Next_Rep_Item
(Rep
);
6969 end Compute_Type_Key
;
6971 -- Start of processing for Type_Key
6980 -- Copy all characters in Full_Name but the trailing NUL
6982 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6983 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6986 -- Compute CRC and convert it to string one character at a time, so
6987 -- as not to use Image within the compiler.
6990 Compute_Type_Key
(Entity
(P
));
6992 if not Is_Frozen
(Entity
(P
))
6993 and then not Is_Generic_Type
(Entity
(P
))
6994 and then not Is_Generic_Actual_Type
(Entity
(P
))
6996 Error_Msg_N
("premature usage of Type_Key?", N
);
7000 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
7004 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
7005 Analyze_And_Resolve
(N
, Standard_String
);
7008 -----------------------
7009 -- Unbiased_Rounding --
7010 -----------------------
7012 -- Shares processing with Ceiling attribute
7014 ----------------------
7015 -- Unchecked_Access --
7016 ----------------------
7018 when Attribute_Unchecked_Access
=>
7019 if Comes_From_Source
(N
) then
7020 Check_Restriction
(No_Unchecked_Access
, N
);
7023 Analyze_Access_Attribute
;
7024 Check_Not_Incomplete_Type
;
7026 -------------------------
7027 -- Unconstrained_Array --
7028 -------------------------
7030 when Attribute_Unconstrained_Array
=>
7033 Check_Not_Incomplete_Type
;
7034 Set_Etype
(N
, Standard_Boolean
);
7035 Set_Is_Static_Expression
(N
, True);
7037 ------------------------------
7038 -- Universal_Literal_String --
7039 ------------------------------
7041 -- This is a GNAT specific attribute whose prefix must be a named
7042 -- number where the expression is either a single numeric literal,
7043 -- or a numeric literal immediately preceded by a minus sign. The
7044 -- result is equivalent to a string literal containing the text of
7045 -- the literal as it appeared in the source program with a possible
7046 -- leading minus sign.
7048 when Attribute_Universal_Literal_String
=>
7051 if not Is_Entity_Name
(P
)
7052 or else not Is_Named_Number
(Entity
(P
))
7054 Error_Attr_P
("prefix for % attribute must be named number");
7061 Src
: Source_Buffer_Ptr
;
7064 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
7066 if Nkind
(Expr
) = N_Op_Minus
then
7068 Expr
:= Original_Node
(Right_Opnd
(Expr
));
7073 if Nkind
(Expr
) not in N_Integer_Literal | N_Real_Literal
then
7075 ("named number for % attribute must be simple literal", N
);
7078 -- Build string literal corresponding to source literal text
7083 Store_String_Char
(Get_Char_Code
('-'));
7087 Src
:= Source_Text
(Get_Source_File_Index
(S
));
7089 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
7090 Store_String_Char
(Get_Char_Code
(Src
(S
)));
7094 -- Now we rewrite the attribute with the string literal
7097 Make_String_Literal
(Loc
, End_String
));
7099 Set_Is_Static_Expression
(N
, True);
7103 -------------------------
7104 -- Unrestricted_Access --
7105 -------------------------
7107 -- This is a GNAT specific attribute which is like Access except that
7108 -- all scope checks and checks for aliased views are omitted. It is
7109 -- documented as being equivalent to the use of the Address attribute
7110 -- followed by an unchecked conversion to the target access type.
7112 when Attribute_Unrestricted_Access
=>
7114 -- If from source, deal with relevant restrictions
7116 if Comes_From_Source
(N
) then
7117 Check_Restriction
(No_Unchecked_Access
, N
);
7119 if Nkind
(P
) in N_Has_Entity
7120 and then Present
(Entity
(P
))
7121 and then Is_Object
(Entity
(P
))
7123 Check_Restriction
(No_Implicit_Aliasing
, N
);
7127 if Is_Entity_Name
(P
) then
7128 Set_Address_Taken
(Entity
(P
));
7131 -- It might seem reasonable to call Address_Checks here to apply the
7132 -- same set of semantic checks that we enforce for 'Address (after
7133 -- all we document Unrestricted_Access as being equivalent to the
7134 -- use of Address followed by an Unchecked_Conversion). However, if
7135 -- we do enable these checks, we get multiple failures in both the
7136 -- compiler run-time and in our regression test suite, so we leave
7137 -- out these checks for now. To be investigated further some time???
7141 -- Now complete analysis using common access processing
7143 Analyze_Access_Attribute
;
7149 when Attribute_Update
=> Update
: declare
7150 Common_Typ
: Entity_Id
;
7151 -- The common type of a multiple component update for a record
7153 Comps
: Elist_Id
:= No_Elist
;
7154 -- A list used in the resolution of a record update. It contains the
7155 -- entities of all record components processed so far.
7157 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
7158 -- Analyze and resolve array_component_association Assoc against the
7159 -- index of array type P_Type.
7161 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
7162 -- Analyze and resolve record_component_association Comp against
7163 -- record type P_Type.
7165 ------------------------------------
7166 -- Analyze_Array_Component_Update --
7167 ------------------------------------
7169 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
7173 Index_Typ
: Entity_Id
;
7177 -- The current association contains a sequence of indexes denoting
7178 -- an element of a multidimensional array:
7180 -- (Index_1, ..., Index_N)
7182 -- Examine each individual index and resolve it against the proper
7183 -- index type of the array.
7185 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
7186 Expr
:= First
(Choices
(Assoc
));
7187 while Present
(Expr
) loop
7189 -- The use of others is illegal (SPARK RM 4.4.1(12))
7191 if Nkind
(Expr
) = N_Others_Choice
then
7193 ("OTHERS choice not allowed in attribute %", Expr
);
7195 -- Otherwise analyze and resolve all indexes
7198 Index
:= First
(Expressions
(Expr
));
7199 Index_Typ
:= First_Index
(P_Type
);
7200 while Present
(Index
) and then Present
(Index_Typ
) loop
7201 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7203 Next_Index
(Index_Typ
);
7206 -- Detect a case where the association either lacks an
7207 -- index or contains an extra index.
7209 if Present
(Index
) or else Present
(Index_Typ
) then
7211 ("dimension mismatch in index list", Assoc
);
7218 -- The current association denotes either a single component or a
7219 -- range of components of a one dimensional array:
7223 -- Resolve the index or its high and low bounds (if range) against
7224 -- the proper index type of the array.
7227 Index
:= First
(Choices
(Assoc
));
7228 Index_Typ
:= First_Index
(P_Type
);
7230 if Present
(Next_Index
(Index_Typ
)) then
7231 Error_Msg_N
("too few subscripts in array reference", Assoc
);
7234 while Present
(Index
) loop
7236 -- The use of others is illegal (SPARK RM 4.4.1(12))
7238 if Nkind
(Index
) = N_Others_Choice
then
7240 ("OTHERS choice not allowed in attribute %", Index
);
7242 -- The index denotes a range of elements
7244 elsif Nkind
(Index
) = N_Range
then
7245 Low
:= Low_Bound
(Index
);
7246 High
:= High_Bound
(Index
);
7248 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
7249 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
7251 -- Otherwise the index denotes a single element
7254 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7260 end Analyze_Array_Component_Update
;
7262 -------------------------------------
7263 -- Analyze_Record_Component_Update --
7264 -------------------------------------
7266 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
7267 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
7268 Base_Typ
: Entity_Id
;
7269 Comp_Or_Discr
: Entity_Id
;
7272 -- Find the discriminant or component whose name corresponds to
7273 -- Comp. A simple character comparison is sufficient because all
7274 -- visible names within a record type are unique.
7276 Comp_Or_Discr
:= First_Entity
(P_Type
);
7277 while Present
(Comp_Or_Discr
) loop
7278 if Chars
(Comp_Or_Discr
) = Comp_Name
then
7280 -- Decorate the component reference by setting its entity
7281 -- and type for resolution purposes.
7283 Set_Entity
(Comp
, Comp_Or_Discr
);
7284 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
7288 Next_Entity
(Comp_Or_Discr
);
7291 -- Diagnose an illegal reference
7293 if Present
(Comp_Or_Discr
) then
7294 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
7296 ("attribute % may not modify record discriminants", Comp
);
7298 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
7299 if Contains
(Comps
, Comp_Or_Discr
) then
7300 Error_Msg_N
("component & already updated", Comp
);
7302 -- Mark this component as processed
7305 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
7309 -- The update aggregate mentions an entity that does not belong to
7313 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
7316 -- Verify the consistency of types when the current component is
7317 -- part of a multiple component update.
7319 -- Comp_1 | ... | Comp_N => <value>
7321 if Present
(Etype
(Comp
)) then
7322 Base_Typ
:= Base_Type
(Etype
(Comp
));
7324 -- Save the type of the first component reference as the
7325 -- remaning references (if any) must resolve to this type.
7327 if No
(Common_Typ
) then
7328 Common_Typ
:= Base_Typ
;
7330 elsif Base_Typ
/= Common_Typ
then
7332 ("components in choice list must have same type", Comp
);
7335 end Analyze_Record_Component_Update
;
7342 -- Start of processing for Update
7345 if Warn_On_Obsolescent_Feature
then
7346 Error_Msg_N
("?j?attribute Update is an obsolescent feature", N
);
7347 Error_Msg_N
("\?j?use a delta aggregate instead", N
);
7352 if not Is_Object_Reference
(P
) then
7353 Error_Attr_P
("prefix of attribute % must denote an object");
7355 elsif not Is_Array_Type
(P_Type
)
7356 and then not Is_Record_Type
(P_Type
)
7358 Error_Attr_P
("prefix of attribute % must be a record or array");
7360 elsif Is_Inherently_Limited_Type
(P_Type
) then
7361 Error_Attr
("prefix of attribute % cannot be limited", N
);
7363 elsif Nkind
(E1
) /= N_Aggregate
then
7364 Error_Attr
("attribute % requires component association list", N
);
7366 elsif Present
(Expressions
(E1
)) then
7367 Error_Attr
("attribute % requires named component associations",
7368 First
(Expressions
(E1
)));
7372 -- Inspect the update aggregate, looking at all the associations and
7373 -- choices. Perform the following checks:
7375 -- 1) Legality of "others" in all cases
7376 -- 2) Legality of <>
7377 -- 3) Component legality for arrays
7378 -- 4) Component legality for records
7380 -- The remaining checks are performed on the expanded attribute
7382 Assoc
:= First
(Component_Associations
(E1
));
7383 while Present
(Assoc
) loop
7385 -- The use of <> is illegal (SPARK RM 4.4.1(1))
7387 if Box_Present
(Assoc
) then
7389 ("default initialization not allowed in attribute %", Assoc
);
7391 -- Otherwise process the association
7394 Analyze
(Expression
(Assoc
));
7396 if Is_Array_Type
(P_Type
) then
7397 Analyze_Array_Component_Update
(Assoc
);
7399 elsif Is_Record_Type
(P_Type
) then
7401 -- Reset the common type used in a multiple component update
7402 -- as we are processing the contents of a new association.
7404 Common_Typ
:= Empty
;
7406 Comp
:= First
(Choices
(Assoc
));
7407 while Present
(Comp
) loop
7408 if Nkind
(Comp
) = N_Identifier
then
7409 Analyze_Record_Component_Update
(Comp
);
7411 -- The use of others is illegal (SPARK RM 4.4.1(5))
7413 elsif Nkind
(Comp
) = N_Others_Choice
then
7415 ("OTHERS choice not allowed in attribute %", Comp
);
7417 -- The name of a record component cannot appear in any
7422 ("name should be identifier or OTHERS", Comp
);
7433 -- The type of attribute 'Update is that of the prefix
7435 Set_Etype
(N
, P_Type
);
7437 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
7444 when Attribute_Val
=>
7446 Check_Discrete_Type
;
7448 -- Note, we need a range check in general, but we wait for the
7449 -- Resolve call to do this, since we want to let Eval_Attribute
7450 -- have a chance to find an static illegality first.
7452 Resolve
(E1
, Any_Integer
);
7453 Set_Etype
(N
, P_Base_Type
);
7459 when Attribute_Valid
=> Valid
: declare
7460 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
7465 -- Ignore check for object if we have a 'Valid reference generated
7466 -- by the expanded code, since in some cases valid checks can occur
7467 -- on items that are names, but are not objects (e.g. attributes).
7469 if Comes_From_Source
(N
) then
7470 Check_Object_Reference
(P
);
7472 if not Is_Scalar_Type
(P_Type
) then
7473 Error_Attr_P
("object for % attribute must be of scalar type");
7476 -- If the attribute appears within the subtype's own predicate
7477 -- function, then issue a warning that this will cause infinite
7480 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
7481 Error_Msg_N
("attribute Valid requires a predicate check??", N
);
7482 Error_Msg_N
("\and will result in infinite recursion??", N
);
7486 Set_Etype
(N
, Standard_Boolean
);
7493 when Attribute_Valid_Value
=>
7495 Check_Enumeration_Type
;
7496 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7497 Set_Etype
(N
, Standard_Boolean
);
7498 Validate_Non_Static_Attribute_Function_Call
;
7500 if P_Type
in Standard_Boolean
7501 | Standard_Character
7502 | Standard_Wide_Character
7503 | Standard_Wide_Wide_Character
7506 ("prefix of % attribute must not be a type in Standard");
7509 if Discard_Names
(First_Subtype
(P_Type
)) then
7511 ("prefix of % attribute must not have Discard_Names");
7518 when Attribute_Valid_Scalars
=> Valid_Scalars
: declare
7522 if Comes_From_Source
(N
) then
7523 Check_Object_Reference
(P
);
7525 -- Attribute 'Valid_Scalars is illegal on unchecked union types
7526 -- regardles of the privacy, because it is not always guaranteed
7527 -- that the components are retrievable based on whether the
7528 -- discriminants are inferable.
7530 if Has_Unchecked_Union
(Validated_View
(P_Type
)) then
7532 ("attribute % not allowed for Unchecked_Union type");
7534 -- Do not emit any diagnostics related to private types to avoid
7535 -- disclosing the structure of the type.
7537 elsif Is_Private_Type
(P_Type
) then
7539 -- Attribute 'Valid_Scalars is not supported on private tagged
7540 -- types due to a code generation issue. Is_Visible_Component
7541 -- does not allow for a component of a private tagged type to
7542 -- be successfully retrieved.
7543 -- ??? This attribute should simply ignore type privacy
7544 -- (see Validated_View). It should examine components of the
7545 -- tagged type extensions (if any) and recursively examine
7546 -- 'Valid_Scalars of the parent's type (if any).
7548 -- Do not use Error_Attr_P because this bypasses any subsequent
7549 -- processing and leaves the attribute with type Any_Type. This
7550 -- in turn prevents the proper expansion of the attribute into
7553 if Is_Tagged_Type
(P_Type
) then
7554 Error_Msg_Name_1
:= Aname
;
7555 Error_Msg_N
("??effects of attribute % are ignored", N
);
7558 -- Otherwise the type is not private
7561 if not Scalar_Part_Present
(P_Type
) then
7562 Error_Msg_Name_1
:= Aname
;
7564 ("??attribute % always True, no scalars to check", P
);
7565 Set_Boolean_Result
(N
, True);
7570 Set_Etype
(N
, Standard_Boolean
);
7577 when Attribute_Value
7578 | Attribute_Wide_Value
7579 | Attribute_Wide_Wide_Value
7583 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7585 -- Set Etype before resolving expression because expansion of
7586 -- expression may require enclosing type. Note that the type
7587 -- returned by 'Value is the base type of the prefix type.
7589 Set_Etype
(N
, P_Base_Type
);
7590 Validate_Non_Static_Attribute_Function_Call
;
7592 -- Check restriction No_Fixed_IO
7594 if Restriction_Check_Required
(No_Fixed_IO
)
7595 and then Is_Fixed_Point_Type
(P_Type
)
7597 Check_Restriction
(No_Fixed_IO
, P
);
7604 -- Shares processing with Machine_Size attribute
7610 when Attribute_Version
=>
7613 Set_Etype
(N
, RTE
(RE_Version_String
));
7619 when Attribute_Wchar_T_Size
=>
7620 Standard_Attribute
(Interfaces_Wchar_T_Size
);
7626 when Attribute_Wide_Image
=>
7627 Analyze_Image_Attribute
(Standard_Wide_String
);
7629 ---------------------
7630 -- Wide_Wide_Image --
7631 ---------------------
7633 when Attribute_Wide_Wide_Image
=>
7634 Analyze_Image_Attribute
(Standard_Wide_Wide_String
);
7640 -- Shares processing with Value attribute
7642 ---------------------
7643 -- Wide_Wide_Value --
7644 ---------------------
7646 -- Shares processing with Value attribute
7648 ---------------------
7649 -- Wide_Wide_Width --
7650 ---------------------
7652 when Attribute_Wide_Wide_Width
7653 | Attribute_Wide_Width
7658 Set_Etype
(N
, Universal_Integer
);
7664 -- Shares processing with Wide_Wide_Width attribute
7670 -- Shares processing with Wide_Wide_Width attribute
7676 when Attribute_Word_Size
=>
7677 Standard_Attribute
(System_Word_Size
);
7683 when Attribute_Write
=>
7685 Check_Stream_Attribute
(TSS_Stream_Write
);
7686 Set_Etype
(N
, Standard_Void_Type
);
7687 Resolve
(N
, Standard_Void_Type
);
7691 -- In SPARK certain attributes (see below) depend on Tasking_State.
7692 -- Ensure that the entity is available for gnat2why by loading it.
7693 -- See SPARK RM 9(19) for the relevant rule.
7695 if GNATprove_Mode
then
7697 when Attribute_Callable
7700 | Attribute_Terminated
7702 SPARK_Implicit_Load
(RE_Tasking_State
);
7709 -- All errors raise Bad_Attribute, so that we get out before any further
7710 -- damage occurs when an error is detected (for example, if we check for
7711 -- one attribute expression, and the check succeeds, we want to be able
7712 -- to proceed securely assuming that an expression is in fact present.
7714 -- Note: we set the attribute analyzed in this case to prevent any
7715 -- attempt at reanalysis which could generate spurious error msgs.
7718 when Bad_Attribute
=>
7720 Set_Etype
(N
, Any_Type
);
7722 end Analyze_Attribute
;
7724 --------------------
7725 -- Eval_Attribute --
7726 --------------------
7728 procedure Eval_Attribute
(N
: Node_Id
) is
7729 Loc
: constant Source_Ptr
:= Sloc
(N
);
7731 C_Type
: constant Entity_Id
:= Etype
(N
);
7732 -- The type imposed by the context
7735 -- Attribute_Name (N) after verification of validity of N
7738 -- Get_Attribute_Id (Aname) after Aname is set
7741 -- Prefix (N) after verification of validity of N
7744 -- First expression, or Empty if none
7747 -- Second expression, or Empty if none
7749 P_Entity
: Entity_Id
;
7750 -- Entity denoted by prefix
7753 -- The type of the prefix
7755 P_Base_Type
: Entity_Id
;
7756 -- The base type of the prefix type
7758 P_Root_Type
: Entity_Id
;
7759 -- The root type of the prefix type
7761 Static
: Boolean := False;
7762 -- True if the result is Static. This is set by the general processing
7763 -- to true if the prefix is static, and all expressions are static. It
7764 -- can be reset as processing continues for particular attributes. This
7765 -- flag can still be True if the reference raises a constraint error.
7766 -- Is_Static_Expression (N) is set to follow this value as it is set
7767 -- and we could always reference this, but it is convenient to have a
7768 -- simple short name to use, since it is frequently referenced.
7770 Lo_Bound
, Hi_Bound
: Node_Id
;
7771 -- Expressions for low and high bounds of type or array index referenced
7772 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7775 -- Constraint error node used if we have an attribute reference has
7776 -- an argument that raises a constraint error. In this case we replace
7777 -- the attribute with a raise constraint_error node. This is important
7778 -- processing, since otherwise gigi might see an attribute which it is
7779 -- unprepared to deal with.
7781 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7782 -- If Bound is a reference to a discriminant of a task or protected type
7783 -- occurring within the object's body, rewrite attribute reference into
7784 -- a reference to the corresponding discriminal. Use for the expansion
7785 -- of checks against bounds of entry family index subtypes.
7787 procedure Check_Expressions
;
7788 -- In case where the attribute is not foldable, the expressions, if
7789 -- any, of the attribute, are in a non-static context. This procedure
7790 -- performs the required additional checks.
7792 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7793 -- Determines if the given type has compile time known bounds. Note
7794 -- that we enter the case statement even in cases where the prefix
7795 -- type does NOT have known bounds, so it is important to guard any
7796 -- attempt to evaluate both bounds with a call to this function.
7798 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7799 -- This procedure is called when the attribute N has a non-static
7800 -- but compile time known value given by Val. It includes the
7801 -- necessary checks for out of range values.
7803 function Fore_Value
return Nat
;
7804 -- Computes the Fore value for the current attribute prefix, which is
7805 -- known to be a static fixed-point type. Used by Fore and Width.
7807 function Mantissa
return Uint
;
7808 -- Returns the Mantissa value for the prefix type
7810 procedure Set_Bounds
;
7811 -- Used for First, Last and Length attributes applied to an array or
7812 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7813 -- and high bound expressions for the index referenced by the attribute
7814 -- designator (i.e. the first index if no expression is present, and the
7815 -- N'th index if the value N is present as an expression). Also used for
7816 -- First and Last of scalar types and for First_Valid and Last_Valid.
7817 -- Static is reset to False if the type or index type is not statically
7820 -----------------------------------
7821 -- Check_Concurrent_Discriminant --
7822 -----------------------------------
7824 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7826 -- The concurrent (task or protected) type
7829 if Nkind
(Bound
) = N_Identifier
7830 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7831 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7833 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7835 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7837 -- Find discriminant of original concurrent type, and use
7838 -- its current discriminal, which is the renaming within
7839 -- the task/protected body.
7843 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7846 end Check_Concurrent_Discriminant
;
7848 -----------------------
7849 -- Check_Expressions --
7850 -----------------------
7852 procedure Check_Expressions
is
7856 while Present
(E
) loop
7857 Check_Non_Static_Context
(E
);
7860 end Check_Expressions
;
7862 ----------------------------------
7863 -- Compile_Time_Known_Attribute --
7864 ----------------------------------
7866 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7867 T
: constant Entity_Id
:= Etype
(N
);
7870 Fold_Uint
(N
, Val
, False);
7872 -- Check that result is in bounds of the type if it is static
7874 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7877 elsif Is_Out_Of_Range
(N
, T
) then
7878 Apply_Compile_Time_Constraint_Error
7879 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7881 elsif not Range_Checks_Suppressed
(T
) then
7882 Enable_Range_Check
(N
);
7885 Set_Do_Range_Check
(N
, False);
7887 end Compile_Time_Known_Attribute
;
7889 -------------------------------
7890 -- Compile_Time_Known_Bounds --
7891 -------------------------------
7893 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7896 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7898 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7899 end Compile_Time_Known_Bounds
;
7905 -- Note that the Fore calculation is based on the actual values
7906 -- of the bounds, and does not take into account possible rounding.
7908 function Fore_Value
return Nat
is
7909 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7910 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7911 Small
: constant Ureal
:= Small_Value
(P_Type
);
7912 Lo_Real
: constant Ureal
:= Lo
* Small
;
7913 Hi_Real
: constant Ureal
:= Hi
* Small
;
7918 -- Bounds are given in terms of small units, so first compute
7919 -- proper values as reals.
7921 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7924 -- Loop to compute proper value if more than one digit required
7926 while T
>= Ureal_10
loop
7938 -- Table of mantissa values accessed by function Computed using
7941 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7943 -- where D is T'Digits (RM83 3.5.7)
7945 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7987 function Mantissa
return Uint
is
7990 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7997 procedure Set_Bounds
is
8003 -- For a string literal subtype, we have to construct the bounds.
8004 -- Valid Ada code never applies attributes to string literals, but
8005 -- it is convenient to allow the expander to generate attribute
8006 -- references of this type (e.g. First and Last applied to a string
8009 -- Note that the whole point of the E_String_Literal_Subtype is to
8010 -- avoid this construction of bounds, but the cases in which we
8011 -- have to materialize them are rare enough that we don't worry.
8013 -- The low bound is simply the low bound of the base type. The
8014 -- high bound is computed from the length of the string and this
8017 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
8018 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
8019 Lo_Bound
:= Type_Low_Bound
(Ityp
);
8022 Make_Integer_Literal
(Sloc
(P
),
8024 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
8026 Set_Parent
(Hi_Bound
, P
);
8027 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
8030 -- For non-array case, just get bounds of scalar type
8032 elsif Is_Scalar_Type
(P_Type
) then
8035 -- For a fixed-point type, we must freeze to get the attributes
8036 -- of the fixed-point type set now so we can reference them.
8038 if Is_Fixed_Point_Type
(P_Type
)
8039 and then not Is_Frozen
(Base_Type
(P_Type
))
8040 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8041 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8043 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
8046 -- For array case, get type of proper index
8052 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
8055 Indx
:= First_Index
(P_Type
);
8056 for J
in 1 .. Ndim
- 1 loop
8060 -- If no index type, get out (some other error occurred, and
8061 -- we don't have enough information to complete the job).
8069 Ityp
:= Etype
(Indx
);
8072 -- A discrete range in an index constraint is allowed to be a
8073 -- subtype indication. This is syntactically a pain, but should
8074 -- not propagate to the entity for the corresponding index subtype.
8075 -- After checking that the subtype indication is legal, the range
8076 -- of the subtype indication should be transfered to the entity.
8077 -- The attributes for the bounds should remain the simple retrievals
8078 -- that they are now.
8080 Lo_Bound
:= Type_Low_Bound
(Ityp
);
8081 Hi_Bound
:= Type_High_Bound
(Ityp
);
8083 -- If subtype is non-static, result is definitely non-static
8085 if not Is_Static_Subtype
(Ityp
) then
8087 Set_Is_Static_Expression
(N
, False);
8089 -- Subtype is static, does it raise CE?
8091 elsif not Is_OK_Static_Subtype
(Ityp
) then
8092 Set_Raises_Constraint_Error
(N
);
8096 -- Start of processing for Eval_Attribute
8099 -- Return immediately if e.g. N has been rewritten or is malformed due
8100 -- to previous errors.
8102 if Nkind
(N
) /= N_Attribute_Reference
then
8106 Aname
:= Attribute_Name
(N
);
8107 Id
:= Get_Attribute_Id
(Aname
);
8110 -- The To_Address attribute can be static, but it cannot be evaluated at
8111 -- compile time, so just return.
8113 if Id
= Attribute_To_Address
then
8117 -- Initialize result as non-static, will be reset if appropriate
8119 Set_Is_Static_Expression
(N
, False);
8121 -- Acquire first two expressions (at the moment, no attributes take more
8122 -- than two expressions in any case).
8124 if Present
(Expressions
(N
)) then
8125 E1
:= First
(Expressions
(N
));
8132 -- Special processing for Enabled attribute. This attribute has a very
8133 -- special prefix, and the easiest way to avoid lots of special checks
8134 -- to protect this special prefix from causing trouble is to deal with
8135 -- this attribute immediately and be done with it.
8137 if Id
= Attribute_Enabled
then
8139 -- We skip evaluation if the expander is not active. This is not just
8140 -- an optimization. It is of key importance that we not rewrite the
8141 -- attribute in a generic template, since we want to pick up the
8142 -- setting of the check in the instance.
8144 if not Inside_A_Generic
then
8146 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
8151 if C
in Predefined_Check_Id
then
8152 R
:= Scope_Suppress
.Suppress
(C
);
8154 R
:= Is_Check_Suppressed
(Empty
, C
);
8158 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
8161 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
8168 -- Attribute 'Img applied to a static enumeration value is static, and
8169 -- we will do the folding right here (things get confused if we let this
8170 -- case go through the normal circuitry).
8172 if Id
= Attribute_Img
8173 and then Is_Entity_Name
(P
)
8174 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
8175 and then Is_OK_Static_Expression
(P
)
8178 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
8183 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8184 Set_Casing
(All_Upper_Case
);
8185 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8188 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8189 Analyze_And_Resolve
(N
, Standard_String
);
8190 Set_Is_Static_Expression
(N
, True);
8196 -- Special processing for cases where the prefix is an object or value,
8197 -- including string literals (attributes of string literals can only
8198 -- appear in generated code) and current instance prefixes in type or
8201 if Is_Object_Reference
(P
)
8202 or else Is_Current_Instance_Reference_In_Type_Aspect
(P
)
8203 or else Nkind
(P
) = N_String_Literal
8204 or else (Is_Entity_Name
(P
)
8205 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
8207 -- For Alignment, give alignment of object if available, otherwise we
8208 -- cannot fold Alignment.
8210 if Id
= Attribute_Alignment
then
8211 if Is_Entity_Name
(P
) and then Known_Alignment
(Entity
(P
)) then
8212 Compile_Time_Known_Attribute
(N
, Alignment
(Entity
(P
)));
8219 -- For Component_Size, the prefix is an array object, and we apply
8220 -- the attribute to the type of the object. This is allowed for both
8221 -- unconstrained and constrained arrays, since the bounds have no
8222 -- influence on the value of this attribute.
8224 elsif Id
= Attribute_Component_Size
then
8225 P_Entity
:= Etype
(P
);
8227 -- For Enum_Rep, evaluation depends on the nature of the prefix and
8228 -- the optional argument.
8230 elsif Id
= Attribute_Enum_Rep
then
8231 if Is_Entity_Name
(P
) then
8234 Enum_Expr
: Node_Id
;
8235 -- The enumeration-type expression of interest
8240 if Ekind
(Entity
(P
)) in E_Constant | E_Enumeration_Literal
8244 -- Enum_Type'Enum_Rep (E1) case
8246 elsif Is_Enumeration_Type
(Entity
(P
)) then
8249 -- Otherwise the attribute must be expanded into a
8250 -- conversion and evaluated at run time.
8257 -- We can fold if the expression is an enumeration
8258 -- literal, or if it denotes a constant whose value
8259 -- is known at compile time.
8261 if Nkind
(Enum_Expr
) in N_Has_Entity
8262 and then (Ekind
(Entity
(Enum_Expr
)) =
8263 E_Enumeration_Literal
8265 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
8266 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
8267 N_Object_Declaration
8269 (Expression
(Parent
(Entity
(P
))))
8270 and then Compile_Time_Known_Value
8271 (Expression
(Parent
(Entity
(P
))))))
8273 P_Entity
:= Etype
(P
);
8280 -- Otherwise the attribute is illegal, do not attempt to perform
8281 -- any kind of folding.
8287 -- For Bit_Position, give Component_Bit_Offset of object if available
8288 -- otherwise we cannot fold Bit_Position. Note that the attribute can
8289 -- be applied to a naked record component in generated code, in which
8290 -- case the prefix is an identifier that references the component or
8291 -- discriminant entity.
8293 elsif Id
= Attribute_Bit_Position
then
8298 if Is_Entity_Name
(P
) then
8301 CE
:= Entity
(Selector_Name
(P
));
8304 if Known_Static_Component_Bit_Offset
(CE
) then
8305 Compile_Time_Known_Attribute
8306 (N
, Component_Bit_Offset
(CE
));
8314 -- For Position, in Ada 2005 (or later) if we have the non-default
8315 -- bit order, we return the original value as given in the component
8316 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8317 -- default bit order) return the value if it is known statically.
8319 elsif Id
= Attribute_Position
then
8321 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8324 if Present
(Component_Clause
(CE
))
8325 and then Ada_Version
>= Ada_2005
8326 and then Reverse_Bit_Order
(Scope
(CE
))
8328 Compile_Time_Known_Attribute
8329 (N
, Expr_Value
(Position
(Component_Clause
(CE
))));
8331 elsif Known_Static_Component_Bit_Offset
(CE
) then
8332 Compile_Time_Known_Attribute
8333 (N
, Component_Bit_Offset
(CE
) / System_Storage_Unit
);
8342 -- For First_Bit, in Ada 2005 (or later) if we have the non-default
8343 -- bit order, we return the original value as given in the component
8344 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8345 -- default bit order) return the value if it is known statically.
8347 elsif Id
= Attribute_First_Bit
then
8349 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8352 if Present
(Component_Clause
(CE
))
8353 and then Ada_Version
>= Ada_2005
8354 and then Reverse_Bit_Order
(Scope
(CE
))
8356 Compile_Time_Known_Attribute
8357 (N
, Expr_Value
(First_Bit
(Component_Clause
(CE
))));
8359 elsif Known_Static_Component_Bit_Offset
(CE
) then
8360 Compile_Time_Known_Attribute
8361 (N
, Component_Bit_Offset
(CE
) mod System_Storage_Unit
);
8370 -- For Last_Bit, in Ada 2005 (or later) if we have the non-default
8371 -- bit order, we return the original value as given in the component
8372 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8373 -- default bit order) return the value if it is known statically.
8375 elsif Id
= Attribute_Last_Bit
then
8377 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8380 if Present
(Component_Clause
(CE
))
8381 and then Ada_Version
>= Ada_2005
8382 and then Reverse_Bit_Order
(Scope
(CE
))
8384 Compile_Time_Known_Attribute
8385 (N
, Expr_Value
(Last_Bit
(Component_Clause
(CE
))));
8387 elsif Known_Static_Component_Bit_Offset
(CE
)
8388 and then Known_Static_Esize
(CE
)
8390 Compile_Time_Known_Attribute
8391 (N
, (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
8400 -- For First, Last and Length, the prefix is an array object, and we
8401 -- apply the attribute to its type, but we need a constrained type
8402 -- for this, so we use the actual subtype if available.
8404 elsif Id
= Attribute_First
8405 or else Id
= Attribute_Last
8406 or else Id
= Attribute_Length
8409 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
8412 if Present
(AS
) and then Is_Constrained
(AS
) then
8415 -- If we have an unconstrained type we cannot fold
8423 elsif Id
= Attribute_Size
then
8424 -- For Enum_Lit'Size, use Enum_Type'Object_Size. Taking the 'Size
8425 -- of a literal is kind of a strange thing to do, so we don't want
8426 -- to pass this oddity on to the back end. Note that Etype of an
8427 -- enumeration literal is always a (base) type, never a
8428 -- constrained subtype, so the Esize is always known.
8430 if Is_Entity_Name
(P
)
8431 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
8433 pragma Assert
(Known_Static_Esize
(Etype
(P
)));
8434 Compile_Time_Known_Attribute
(N
, Esize
(Etype
(P
)));
8436 -- Otherwise, if Size is available, use that
8438 elsif Is_Entity_Name
(P
) and then Known_Static_Esize
(Entity
(P
))
8440 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
8442 -- Otherwise, we cannot fold
8455 -- Cases where P is not an object. Cannot do anything if P is not the
8456 -- name of an entity.
8458 elsif not Is_Entity_Name
(P
) then
8462 -- Otherwise get prefix entity
8465 P_Entity
:= Entity
(P
);
8468 -- If we are asked to evaluate an attribute where the prefix is a
8469 -- non-frozen generic actual type whose RM_Size has not been set,
8470 -- then abandon the effort.
8472 if Is_Type
(P_Entity
)
8473 and then (not Is_Frozen
(P_Entity
)
8474 and then Is_Generic_Actual_Type
(P_Entity
)
8475 and then not Known_RM_Size
(P_Entity
))
8477 -- However, the attribute Unconstrained_Array must be evaluated,
8478 -- since it is documented to be a static attribute (and can for
8479 -- example appear in a Compile_Time_Warning pragma). The frozen
8480 -- status of the type does not affect its evaluation. Likewise
8481 -- for attributes intended to be used with generic definitions.
8483 and then Id
not in Attribute_Unconstrained_Array
8484 | Attribute_Has_Access_Values
8485 | Attribute_Has_Discriminants
8486 | Attribute_Has_Tagged_Values
8491 -- At this stage P_Entity is the entity to which the attribute
8492 -- is to be applied. This is usually simply the entity of the
8493 -- prefix, except in some cases of attributes for objects, where
8494 -- as described above, we apply the attribute to the object type.
8496 -- Here is where we make sure that static attributes are properly
8497 -- marked as such. These are attributes whose prefix is a static
8498 -- scalar subtype, whose result is scalar, and whose arguments, if
8499 -- present, are static scalar expressions. Note that such references
8500 -- are static expressions even if they raise Constraint_Error.
8502 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
8503 -- though evaluating it raises constraint error. This means that a
8504 -- declaration like:
8506 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
8508 -- is legal, since here this expression appears in a statically
8509 -- unevaluated position, so it does not actually raise an exception.
8511 -- T'Descriptor_Size is never static, even if T is static.
8513 if Is_Scalar_Type
(P_Entity
)
8514 and then not Is_Generic_Type
(P_Entity
)
8515 and then Is_Static_Subtype
(P_Entity
)
8516 and then Is_Scalar_Type
(Etype
(N
))
8519 or else (Is_Static_Expression
(E1
)
8520 and then Is_Scalar_Type
(Etype
(E1
))))
8523 or else (Is_Static_Expression
(E2
)
8524 and then Is_Scalar_Type
(Etype
(E1
))))
8525 and then Id
/= Attribute_Descriptor_Size
8527 -- If the front-end conjures up Integer'Pred (Integer'First)
8528 -- as the high bound of a null array aggregate, then we don't
8529 -- want to reject that as an illegal static expression.
8531 and then not Is_Null_Array_Aggregate_High_Bound
(N
)
8534 Set_Is_Static_Expression
(N
, True);
8537 -- First foldable possibility is a scalar or array type (RM 4.9(7))
8538 -- that is not generic (generic types are eliminated by RM 4.9(25)).
8539 -- Note we allow nonstatic nongeneric types at this stage as further
8542 if Is_Type
(P_Entity
)
8543 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
8544 and then not Is_Generic_Type
(P_Entity
)
8548 -- Second foldable possibility is an array object (RM 4.9(8))
8550 elsif Ekind
(P_Entity
) in E_Variable | E_Constant
8551 and then Is_Array_Type
(Etype
(P_Entity
))
8552 and then not Is_Generic_Type
(Etype
(P_Entity
))
8554 P_Type
:= Etype
(P_Entity
);
8556 -- If the entity is an array constant with an unconstrained nominal
8557 -- subtype then get the type from the initial value. If the value has
8558 -- been expanded into assignments, there is no expression and the
8559 -- attribute reference remains dynamic.
8561 -- We could do better here and retrieve the type ???
8563 if Ekind
(P_Entity
) = E_Constant
8564 and then not Is_Constrained
(P_Type
)
8566 if No
(Constant_Value
(P_Entity
)) then
8569 P_Type
:= Etype
(Constant_Value
(P_Entity
));
8573 -- Definite must be folded if the prefix is not a generic type, that
8574 -- is to say if we are within an instantiation. Same processing applies
8575 -- to selected GNAT attributes.
8577 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
8578 Id
= Attribute_Definite
or else
8579 Id
= Attribute_Descriptor_Size
or else
8580 Id
= Attribute_Has_Access_Values
or else
8581 Id
= Attribute_Has_Discriminants
or else
8582 Id
= Attribute_Has_Tagged_Values
or else
8583 Id
= Attribute_Preelaborable_Initialization
or else
8584 Id
= Attribute_Type_Class
or else
8585 Id
= Attribute_Unconstrained_Array
or else
8586 Id
= Attribute_Max_Alignment_For_Allocation
)
8587 and then not Is_Generic_Type
(P_Entity
)
8591 -- We can fold 'Size applied to a type if the size is known (as happens
8592 -- for a size from an attribute definition clause). At this stage, this
8593 -- can happen only for types (e.g. record types) for which the size is
8594 -- always non-static. We exclude generic types from consideration (since
8595 -- they have bogus sizes set within templates). We can also fold
8596 -- Max_Size_In_Storage_Elements in the same cases.
8598 elsif (Id
= Attribute_Size
or
8599 Id
= Attribute_Max_Size_In_Storage_Elements
)
8600 and then Is_Type
(P_Entity
)
8601 and then not Is_Generic_Type
(P_Entity
)
8602 and then Known_Static_RM_Size
(P_Entity
)
8605 Attr_Value
: Uint
:= RM_Size
(P_Entity
);
8607 if Id
= Attribute_Max_Size_In_Storage_Elements
then
8608 Attr_Value
:= (Attr_Value
+ System_Storage_Unit
- 1)
8609 / System_Storage_Unit
;
8611 Compile_Time_Known_Attribute
(N
, Attr_Value
);
8615 -- We can fold 'Alignment applied to a type if the alignment is known
8616 -- (as happens for an alignment from an attribute definition clause).
8617 -- At this stage, this can happen only for types (e.g. record types) for
8618 -- which the size is always non-static. We exclude generic types from
8619 -- consideration (since they have bogus sizes set within templates).
8621 elsif Id
= Attribute_Alignment
8622 and then Is_Type
(P_Entity
)
8623 and then not Is_Generic_Type
(P_Entity
)
8624 and then Known_Alignment
(P_Entity
)
8626 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
8629 -- If this is an access attribute that is known to fail accessibility
8630 -- check, rewrite accordingly.
8632 elsif Id
= Attribute_Address
8633 and then Raises_Constraint_Error
(N
)
8636 Make_Raise_Program_Error
(Loc
,
8637 Reason
=> PE_Accessibility_Check_Failed
));
8638 Set_Etype
(N
, C_Type
);
8641 -- No other cases are foldable (they certainly aren't static, and at
8642 -- the moment we don't try to fold any cases other than the ones above).
8649 -- If either attribute or the prefix is Any_Type, then propagate
8650 -- Any_Type to the result and don't do anything else at all.
8652 if P_Type
= Any_Type
8653 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
8654 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
8656 Set_Etype
(N
, Any_Type
);
8660 -- Scalar subtype case. We have not yet enforced the static requirement
8661 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
8662 -- of non-static attribute references (e.g. S'Digits for a non-static
8663 -- floating-point type, which we can compute at compile time).
8665 -- Note: this folding of non-static attributes is not simply a case of
8666 -- optimization. For many of the attributes affected, Gigi cannot handle
8667 -- the attribute and depends on the front end having folded them away.
8669 -- Note: although we don't require staticness at this stage, we do set
8670 -- the Static variable to record the staticness, for easy reference by
8671 -- those attributes where it matters (e.g. Succ and Pred), and also to
8672 -- be used to ensure that non-static folded things are not marked as
8673 -- being static (a check that is done right at the end).
8675 P_Root_Type
:= Root_Type
(P_Type
);
8676 P_Base_Type
:= Base_Type
(P_Type
);
8678 -- If the root type or base type is generic, then we cannot fold. This
8679 -- test is needed because subtypes of generic types are not always
8680 -- marked as being generic themselves (which seems odd???)
8682 if Is_Generic_Type
(P_Root_Type
)
8683 or else Is_Generic_Type
(P_Base_Type
)
8688 if Is_Scalar_Type
(P_Type
) then
8689 if not Is_Static_Subtype
(P_Type
) then
8691 Set_Is_Static_Expression
(N
, False);
8692 elsif not Is_OK_Static_Subtype
(P_Type
) then
8693 Set_Raises_Constraint_Error
(N
);
8696 -- RM 13.14(8/4): a nonstatic expression in a spec expression does
8697 -- not cause freezing, so the representation attributes cannot be
8698 -- evaluated at this point if the type is not already frozen.
8701 and then In_Spec_Expression
8702 and then Id
in Attribute_Alignment
8703 | Attribute_Component_Size
8704 | Attribute_Max_Alignment_For_Allocation
8705 | Attribute_Max_Size_In_Storage_Elements
8706 | Attribute_Object_Size
8709 | Attribute_VADS_Size
8710 | Attribute_Value_Size
8711 and then not Is_Frozen
(P_Type
)
8716 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
8717 -- since we can't do anything with unconstrained arrays. In addition,
8718 -- only the First, Last and Length attributes are possibly static.
8720 -- Atomic_Always_Lock_Free, Definite, Descriptor_Size, Has_Access_Values
8721 -- Has_Discriminants, Has_Tagged_Values, Type_Class, and
8722 -- Unconstrained_Array are again exceptions, because they apply as well
8723 -- to unconstrained types.
8725 -- In addition Component_Size is an exception since it is possibly
8726 -- foldable, even though it is never static, and it does apply to
8727 -- unconstrained arrays. Furthermore, it is essential to fold this
8728 -- in the packed case, since otherwise the value will be incorrect.
8730 -- Folding can also be done for Preelaborable_Initialization based on
8731 -- whether the prefix type has preelaborable initialization, even though
8732 -- the attribute is nonstatic.
8734 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
8735 Id
= Attribute_Definite
or else
8736 Id
= Attribute_Descriptor_Size
or else
8737 Id
= Attribute_Has_Access_Values
or else
8738 Id
= Attribute_Has_Discriminants
or else
8739 Id
= Attribute_Has_Tagged_Values
or else
8740 Id
= Attribute_Preelaborable_Initialization
or else
8741 Id
= Attribute_Type_Class
or else
8742 Id
= Attribute_Unconstrained_Array
or else
8743 Id
= Attribute_Component_Size
8746 Set_Is_Static_Expression
(N
, False);
8748 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
8749 if not Is_Constrained
(P_Type
)
8750 or else (Id
/= Attribute_First
and then
8751 Id
/= Attribute_Last
and then
8752 Id
/= Attribute_Length
)
8758 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
8759 -- scalar case, we hold off on enforcing staticness, since there are
8760 -- cases which we can fold at compile time even though they are not
8761 -- static (e.g. 'Length applied to a static index, even though other
8762 -- non-static indexes make the array type non-static). This is only
8763 -- an optimization, but it falls out essentially free, so why not.
8764 -- Again we compute the variable Static for easy reference later
8765 -- (note that no array attributes are static in Ada 83).
8767 -- We also need to set Static properly for subsequent legality checks
8768 -- which might otherwise accept non-static constants in contexts
8769 -- where they are not legal.
8772 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
8773 Set_Is_Static_Expression
(N
, Static
);
8779 Nod
:= First_Index
(P_Type
);
8781 -- The expression is static if the array type is constrained
8782 -- by given bounds, and not by an initial expression. Constant
8783 -- strings are static in any case.
8785 if Root_Type
(P_Type
) /= Standard_String
then
8787 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
8788 Set_Is_Static_Expression
(N
, Static
);
8791 while Present
(Nod
) loop
8792 if not Is_Static_Subtype
(Etype
(Nod
)) then
8794 Set_Is_Static_Expression
(N
, False);
8796 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
8797 Set_Raises_Constraint_Error
(N
);
8799 Set_Is_Static_Expression
(N
, False);
8802 -- If however the index type is generic, or derived from
8803 -- one, attributes cannot be folded.
8805 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
8806 and then Id
/= Attribute_Component_Size
8816 -- Check any expressions that are present. Note that these expressions,
8817 -- depending on the particular attribute type, are either part of the
8818 -- attribute designator, or they are arguments in a case where the
8819 -- attribute reference returns a function. In the latter case, the
8820 -- rule in (RM 4.9(22)) applies and in particular requires the type
8821 -- of the expressions to be scalar in order for the attribute to be
8822 -- considered to be static.
8830 while Present
(E
) loop
8832 -- If expression is not static, then the attribute reference
8833 -- result certainly cannot be static.
8835 if not Is_Static_Expression
(E
) then
8837 Set_Is_Static_Expression
(N
, False);
8840 if Raises_Constraint_Error
(E
) then
8841 Set_Raises_Constraint_Error
(N
);
8844 -- If the result is not known at compile time, or is not of
8845 -- a scalar type, then the result is definitely not static,
8846 -- so we can quit now.
8848 if not Compile_Time_Known_Value
(E
)
8849 or else not Is_Scalar_Type
(Etype
(E
))
8854 -- If the expression raises a constraint error, then so does
8855 -- the attribute reference. We keep going in this case because
8856 -- we are still interested in whether the attribute reference
8857 -- is static even if it is not static.
8859 elsif Raises_Constraint_Error
(E
) then
8860 Set_Raises_Constraint_Error
(N
);
8866 if Raises_Constraint_Error
(Prefix
(N
)) then
8867 Set_Is_Static_Expression
(N
, False);
8872 -- Deal with the case of a static attribute reference that raises
8873 -- constraint error. The Raises_Constraint_Error flag will already
8874 -- have been set, and the Static flag shows whether the attribute
8875 -- reference is static. In any case we certainly can't fold such an
8876 -- attribute reference.
8878 -- Note that the rewriting of the attribute node with the constraint
8879 -- error node is essential in this case, because otherwise Gigi might
8880 -- blow up on one of the attributes it never expects to see.
8882 -- The constraint_error node must have the type imposed by the context,
8883 -- to avoid spurious errors in the enclosing expression.
8885 if Raises_Constraint_Error
(N
) then
8887 Make_Raise_Constraint_Error
(Sloc
(N
),
8888 Reason
=> CE_Range_Check_Failed
);
8889 Set_Etype
(CE_Node
, Etype
(N
));
8890 Set_Raises_Constraint_Error
(CE_Node
);
8892 Rewrite
(N
, Relocate_Node
(CE_Node
));
8893 Set_Raises_Constraint_Error
(N
, True);
8897 -- At this point we have a potentially foldable attribute reference.
8898 -- If Static is set, then the attribute reference definitely obeys
8899 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8900 -- folded. If Static is not set, then the attribute may or may not
8901 -- be foldable, and the individual attribute processing routines
8902 -- test Static as required in cases where it makes a difference.
8904 -- In the case where Static is not set, we do know that all the
8905 -- expressions present are at least known at compile time (we assumed
8906 -- above that if this was not the case, then there was no hope of static
8907 -- evaluation). However, we did not require that the bounds of the
8908 -- prefix type be compile time known, let alone static). That's because
8909 -- there are many attributes that can be computed at compile time on
8910 -- non-static subtypes, even though such references are not static
8913 -- For VAX float, the root type is an IEEE type. So make sure to use the
8914 -- base type instead of the root-type for floating point attributes.
8918 -- Attributes related to Ada 2012 iterators; nothing to evaluate for
8921 when Attribute_Constant_Indexing
8922 | Attribute_Default_Iterator
8923 | Attribute_Implicit_Dereference
8924 | Attribute_Iterator_Element
8925 | Attribute_Iterable
8927 | Attribute_Variable_Indexing
8931 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8932 -- These were already rejected by the parser. Thus they shouldn't
8935 when Internal_Attribute_Id
=>
8936 raise Program_Error
;
8942 when Attribute_Adjacent
=>
8946 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8953 when Attribute_Aft
=>
8954 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8960 when Attribute_Alignment
=> Alignment_Block
: declare
8961 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8964 -- Fold if alignment is set and not otherwise
8966 if Known_Alignment
(P_TypeA
) then
8967 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8969 end Alignment_Block
;
8971 -----------------------------
8972 -- Atomic_Always_Lock_Free --
8973 -----------------------------
8975 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8978 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8980 V
: constant Entity_Id
:=
8982 (Support_Atomic_Primitives_On_Target
8983 and then Support_Atomic_Primitives
(P_Type
));
8986 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8988 -- Analyze and resolve as boolean. Note that this attribute is a
8989 -- static attribute in GNAT.
8991 Analyze_And_Resolve
(N
, Standard_Boolean
);
8993 Set_Is_Static_Expression
(N
);
8994 end Atomic_Always_Lock_Free
;
9000 -- Bit can never be folded
9002 when Attribute_Bit
=>
9009 -- Body_version can never be static
9011 when Attribute_Body_Version
=>
9018 when Attribute_Ceiling
=>
9020 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9022 --------------------
9023 -- Component_Size --
9024 --------------------
9026 -- Fold Component_Size if it is known at compile time, which is always
9027 -- true in the packed array case. It is important that the packed array
9028 -- case is handled here since the back end would otherwise get confused
9029 -- by the equivalent packed array type.
9031 when Attribute_Component_Size
=>
9032 if Known_Static_Component_Size
(P_Type
) then
9033 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
9040 when Attribute_Compose
=>
9043 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9050 -- Constrained is never folded for now, there may be cases that
9051 -- could be handled at compile time. To be looked at later.
9053 when Attribute_Constrained
=>
9055 -- The expander might fold it and set the static flag accordingly,
9056 -- but with expansion disabled, it remains as an attribute reference,
9057 -- and this reference is not static.
9059 Set_Is_Static_Expression
(N
, False);
9065 when Attribute_Copy_Sign
=>
9069 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
9076 when Attribute_Definite
=>
9077 Rewrite
(N
, New_Occurrence_Of
(
9078 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
9079 Analyze_And_Resolve
(N
, Standard_Boolean
);
9085 when Attribute_Delta
=>
9086 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
9092 when Attribute_Denorm
=>
9094 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
9096 ---------------------
9097 -- Descriptor_Size --
9098 ---------------------
9100 -- Descriptor_Size is nonnull only for unconstrained array types
9102 when Attribute_Descriptor_Size
=>
9103 if not Is_Array_Type
(P_Type
) or else Is_Constrained
(P_Type
) then
9104 Fold_Uint
(N
, Uint_0
, Static
);
9111 when Attribute_Digits
=>
9112 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
9118 when Attribute_Emax
=>
9120 -- Ada 83 attribute is defined as (RM83 3.5.8)
9122 -- T'Emax = 4 * T'Mantissa
9124 Fold_Uint
(N
, 4 * Mantissa
, Static
);
9130 when Attribute_Enum_Rep
=> Enum_Rep
: declare
9134 -- The attribute appears in the form:
9136 -- Enum_Typ'Enum_Rep (Const)
9137 -- Enum_Typ'Enum_Rep (Enum_Lit)
9139 if Present
(E1
) then
9142 -- Otherwise the prefix denotes a constant or enumeration literal:
9145 -- Enum_Lit'Enum_Rep
9151 -- For an enumeration type with a non-standard representation use
9152 -- the Enumeration_Rep field of the proper constant. Note that this
9153 -- will not work for types Character/Wide_[Wide-]Character, since no
9154 -- real entities are created for the enumeration literals, but that
9155 -- does not matter since these two types do not have non-standard
9156 -- representations anyway.
9158 if Is_Enumeration_Type
(P_Type
)
9159 and then Has_Non_Standard_Rep
(P_Type
)
9161 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
9163 -- For enumeration types with standard representations and all other
9164 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
9168 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
9176 when Attribute_Enum_Val
=> Enum_Val
: declare
9180 -- We have something like Enum_Type'Enum_Val (23), so search for a
9181 -- corresponding value in the list of Enum_Rep values for the type.
9183 Lit
:= First_Literal
(P_Base_Type
);
9185 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
9186 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
9193 Apply_Compile_Time_Constraint_Error
9194 (N
, "no representation value matches",
9195 CE_Range_Check_Failed
,
9196 Warn
=> not Static
);
9206 when Attribute_Epsilon
=>
9208 -- Ada 83 attribute is defined as (RM83 3.5.8)
9210 -- T'Epsilon = 2.0**(1 - T'Mantissa)
9212 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
9218 when Attribute_Exponent
=>
9220 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9222 -----------------------
9223 -- Finalization_Size --
9224 -----------------------
9226 when Attribute_Finalization_Size
=>
9233 when Attribute_First
=>
9236 if Compile_Time_Known_Value
(Lo_Bound
) then
9237 if Is_Real_Type
(P_Type
) then
9238 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
9240 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9244 Check_Concurrent_Discriminant
(Lo_Bound
);
9251 when Attribute_First_Valid
=>
9252 if Has_Predicates
(P_Type
)
9253 and then Has_Static_Predicate
(P_Type
)
9256 FirstN
: constant Node_Id
:=
9257 First
(Static_Discrete_Predicate
(P_Type
));
9259 if Nkind
(FirstN
) = N_Range
then
9260 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
9262 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
9268 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9275 when Attribute_Fixed_Value
=>
9282 when Attribute_Floor
=>
9284 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9290 when Attribute_Fore
=>
9291 if Compile_Time_Known_Bounds
(P_Type
) then
9292 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
9299 when Attribute_Fraction
=>
9301 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9303 -----------------------
9304 -- Has_Access_Values --
9305 -----------------------
9307 when Attribute_Has_Access_Values
=>
9308 Rewrite
(N
, New_Occurrence_Of
9309 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
9310 Analyze_And_Resolve
(N
, Standard_Boolean
);
9312 -----------------------
9313 -- Has_Discriminants --
9314 -----------------------
9316 when Attribute_Has_Discriminants
=>
9317 Rewrite
(N
, New_Occurrence_Of
(
9318 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
9319 Analyze_And_Resolve
(N
, Standard_Boolean
);
9321 ----------------------
9322 -- Has_Same_Storage --
9323 ----------------------
9325 when Attribute_Has_Same_Storage
=>
9328 -----------------------
9329 -- Has_Tagged_Values --
9330 -----------------------
9332 when Attribute_Has_Tagged_Values
=>
9333 Rewrite
(N
, New_Occurrence_Of
9334 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
9335 Analyze_And_Resolve
(N
, Standard_Boolean
);
9341 when Attribute_Identity
=>
9348 -- Image is a scalar attribute, but is never static, because it is
9349 -- not a static function (having a non-scalar argument (RM 4.9(22))
9350 -- However, we can constant-fold the image of an enumeration literal
9351 -- if names are available and default Image implementation has not
9354 when Attribute_Image
=>
9355 if Is_Entity_Name
(E1
)
9356 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
9357 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
9358 and then not Global_Discard_Names
9359 and then not Has_Aspect
(Etype
(E1
), Aspect_Put_Image
)
9362 Lit
: constant Entity_Id
:= Entity
(E1
);
9366 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
9367 Set_Casing
(All_Upper_Case
);
9368 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
9370 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
9371 Analyze_And_Resolve
(N
, Standard_String
);
9372 Set_Is_Static_Expression
(N
, False);
9380 -- We never try to fold Integer_Value (though perhaps we could???)
9382 when Attribute_Integer_Value
=>
9389 -- Invalid_Value is a scalar attribute that is never static, because
9390 -- the value is by design out of range.
9392 when Attribute_Invalid_Value
=>
9399 when Attribute_Large
=>
9401 -- For fixed-point, we use the identity:
9403 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
9405 if Is_Fixed_Point_Type
(P_Type
) then
9407 Make_Op_Multiply
(Loc
,
9409 Make_Op_Subtract
(Loc
,
9413 Make_Real_Literal
(Loc
, Ureal_2
),
9415 Make_Attribute_Reference
(Loc
,
9417 Attribute_Name
=> Name_Mantissa
)),
9418 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
9421 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
9423 Analyze_And_Resolve
(N
, C_Type
);
9425 -- Floating-point (Ada 83 compatibility)
9428 -- Ada 83 attribute is defined as (RM83 3.5.8)
9430 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
9434 -- T'Emax = 4 * T'Mantissa
9438 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
9446 when Attribute_Last
=>
9449 if Compile_Time_Known_Value
(Hi_Bound
) then
9450 if Is_Real_Type
(P_Type
) then
9451 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
9453 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9457 Check_Concurrent_Discriminant
(Hi_Bound
);
9464 when Attribute_Last_Valid
=>
9465 if Has_Predicates
(P_Type
)
9466 and then Has_Static_Predicate
(P_Type
)
9469 LastN
: constant Node_Id
:=
9470 Last
(Static_Discrete_Predicate
(P_Type
));
9472 if Nkind
(LastN
) = N_Range
then
9473 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
9475 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
9481 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9488 when Attribute_Leading_Part
=> Leading_Part
: declare
9489 Radix_Digits
: constant Uint
:= Expr_Value
(E2
);
9492 if UI_Le
(Radix_Digits
, Uint_0
) then
9493 Apply_Compile_Time_Constraint_Error
9494 (N
, "Radix_Digits in Leading_Part is zero or negative",
9496 Warn
=> not Static
);
9504 Eval_Fat
.Leading_Part
9505 (P_Base_Type
, Expr_Value_R
(E1
), Radix_Digits
),
9513 when Attribute_Length
=> Length
: declare
9517 -- If any index type is a formal type, or derived from one, the
9518 -- bounds are not static. Treating them as static can produce
9519 -- spurious warnings or improper constant folding.
9521 Ind
:= First_Index
(P_Type
);
9522 while Present
(Ind
) loop
9523 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
9532 -- For two compile time values, we can compute length
9534 if Compile_Time_Known_Value
(Lo_Bound
)
9535 and then Compile_Time_Known_Value
(Hi_Bound
)
9538 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
9542 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9543 -- comparable, and we can figure out the difference between them.
9546 Diff
: aliased Uint
;
9550 Compile_Time_Compare
9551 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9554 Fold_Uint
(N
, Uint_1
, Static
);
9557 Fold_Uint
(N
, Uint_0
, Static
);
9560 if Present
(Diff
) then
9561 Fold_Uint
(N
, Diff
+ 1, Static
);
9574 -- Loop_Entry acts as an alias of a constant initialized to the prefix
9575 -- of the said attribute at the point of entry into the related loop. As
9576 -- such, the attribute reference does not need to be evaluated because
9577 -- the prefix is the one that is evaluted.
9579 when Attribute_Loop_Entry
=>
9586 -- We use the same rounding as the one used for RM 4.9(38/2)
9588 when Attribute_Machine
=>
9590 (N
, Machine_Number
(P_Base_Type
, Expr_Value_R
(E1
), N
), Static
);
9591 Set_Is_Machine_Number
(N
);
9597 when Attribute_Machine_Emax
=>
9598 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
9604 when Attribute_Machine_Emin
=>
9605 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
9607 ----------------------
9608 -- Machine_Mantissa --
9609 ----------------------
9611 when Attribute_Machine_Mantissa
=>
9612 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
9614 -----------------------
9615 -- Machine_Overflows --
9616 -----------------------
9618 when Attribute_Machine_Overflows
=>
9620 -- Always true for fixed-point
9622 if Is_Fixed_Point_Type
(P_Type
) then
9623 Fold_Uint
(N
, True_Value
, Static
);
9625 -- Floating point case
9629 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
9637 when Attribute_Machine_Radix
=>
9638 if Is_Fixed_Point_Type
(P_Type
) then
9639 if Is_Decimal_Fixed_Point_Type
(P_Type
)
9640 and then Machine_Radix_10
(P_Type
)
9642 Fold_Uint
(N
, Uint_10
, Static
);
9644 Fold_Uint
(N
, Uint_2
, Static
);
9647 -- All floating-point type always have radix 2
9650 Fold_Uint
(N
, Uint_2
, Static
);
9653 ----------------------
9654 -- Machine_Rounding --
9655 ----------------------
9657 -- Note: for the folding case, it is fine to treat Machine_Rounding
9658 -- exactly the same way as Rounding, since this is one of the allowed
9659 -- behaviors, and performance is not an issue here. It might be a bit
9660 -- better to give the same result as it would give at run time, even
9661 -- though the non-determinism is certainly permitted.
9663 when Attribute_Machine_Rounding
=>
9665 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9667 --------------------
9668 -- Machine_Rounds --
9669 --------------------
9671 when Attribute_Machine_Rounds
=>
9673 -- Always False for fixed-point
9675 if Is_Fixed_Point_Type
(P_Type
) then
9676 Fold_Uint
(N
, False_Value
, Static
);
9678 -- Else yield proper floating-point result
9682 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
9690 -- Note: Machine_Size is identical to Object_Size
9692 when Attribute_Machine_Size
=> Machine_Size
: declare
9693 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9696 if Known_Esize
(P_TypeA
) then
9697 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9705 when Attribute_Mantissa
=>
9707 -- Fixed-point mantissa
9709 if Is_Fixed_Point_Type
(P_Type
) then
9711 -- Compile time foldable case
9713 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
9715 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
9717 -- The calculation of the obsolete Ada 83 attribute Mantissa
9718 -- is annoying, because of AI00143, quoted here:
9720 -- !question 84-01-10
9722 -- Consider the model numbers for F:
9724 -- type F is delta 1.0 range -7.0 .. 8.0;
9726 -- The wording requires that F'MANTISSA be the SMALLEST
9727 -- integer number for which each bound of the specified
9728 -- range is either a model number or lies at most small
9729 -- distant from a model number. This means F'MANTISSA
9730 -- is required to be 3 since the range -7.0 .. 7.0 fits
9731 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
9732 -- number, namely, 7. Is this analysis correct? Note that
9733 -- this implies the upper bound of the range is not
9734 -- represented as a model number.
9736 -- !response 84-03-17
9738 -- The analysis is correct. The upper and lower bounds for
9739 -- a fixed point type can lie outside the range of model
9750 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
9751 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
9752 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
9753 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
9755 -- If the Bound is exactly a model number, i.e. a multiple
9756 -- of Small, then we back it off by one to get the integer
9757 -- value that must be representable.
9759 if Small_Value
(P_Type
) * Max_Man
= Bound
then
9760 Max_Man
:= Max_Man
- 1;
9763 -- Now find corresponding size = Mantissa value
9766 while 2 ** Siz
< Max_Man
loop
9770 Fold_Uint
(N
, Siz
, Static
);
9774 -- The case of dynamic bounds cannot be evaluated at compile
9775 -- time. Instead we use a runtime routine (see Exp_Attr).
9780 -- Floating-point Mantissa
9783 Fold_Uint
(N
, Mantissa
, Static
);
9790 when Attribute_Max
=>
9791 if Is_Real_Type
(P_Type
) then
9793 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9795 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9798 ----------------------------------
9799 -- Max_Alignment_For_Allocation --
9800 ----------------------------------
9802 -- Max_Alignment_For_Allocation is usually the Alignment. However,
9803 -- arrays are allocated with dope, so we need to take into account both
9804 -- the alignment of the array, which comes from the component alignment,
9805 -- and the alignment of the dope. Also, if the alignment is unknown, we
9806 -- use the max (it's OK to be pessimistic).
9808 when Attribute_Max_Alignment_For_Allocation
=> Max_Align
: declare
9809 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
9811 if Known_Alignment
(P_Type
)
9812 and then (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
9814 A
:= Alignment
(P_Type
);
9817 Fold_Uint
(N
, A
, Static
);
9820 ----------------------------------
9821 -- Max_Size_In_Storage_Elements --
9822 ----------------------------------
9824 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9825 -- Storage_Unit boundary. We can fold any cases for which the size
9826 -- is known by the front end.
9828 when Attribute_Max_Size_In_Storage_Elements
=>
9829 if Known_Esize
(P_Type
) then
9831 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9832 System_Storage_Unit
,
9836 --------------------
9837 -- Mechanism_Code --
9838 --------------------
9840 when Attribute_Mechanism_Code
=> Mechanism_Code
: declare
9842 Mech
: Mechanism_Type
;
9847 Mech
:= Mechanism
(P_Entity
);
9850 Val
:= UI_To_Int
(Expr_Value
(E1
));
9852 Formal
:= First_Formal
(P_Entity
);
9853 for J
in 1 .. Val
- 1 loop
9854 Next_Formal
(Formal
);
9857 Mech
:= Mechanism
(Formal
);
9861 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9869 when Attribute_Min
=>
9870 if Is_Real_Type
(P_Type
) then
9872 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9875 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9882 when Attribute_Mod
=>
9884 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9890 when Attribute_Model
=>
9892 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9898 when Attribute_Model_Emin
=>
9899 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9905 when Attribute_Model_Epsilon
=>
9906 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9908 --------------------
9909 -- Model_Mantissa --
9910 --------------------
9912 when Attribute_Model_Mantissa
=>
9913 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9919 when Attribute_Model_Small
=>
9920 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9926 when Attribute_Modulus
=>
9927 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9929 --------------------
9930 -- Null_Parameter --
9931 --------------------
9933 -- Cannot fold, we know the value sort of, but the whole point is
9934 -- that there is no way to talk about this imaginary value except
9935 -- by using the attribute, so we leave it the way it is.
9937 when Attribute_Null_Parameter
=>
9944 -- The Object_Size attribute for a type returns the Esize of the
9945 -- type and can be folded if this value is known.
9947 when Attribute_Object_Size
=> Object_Size
: declare
9948 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9951 if Known_Esize
(P_TypeA
) then
9952 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9956 ----------------------
9957 -- Overlaps_Storage --
9958 ----------------------
9960 when Attribute_Overlaps_Storage
=>
9963 -------------------------
9964 -- Passed_By_Reference --
9965 -------------------------
9967 -- Scalar types are never passed by reference
9969 when Attribute_Passed_By_Reference
=>
9970 Fold_Uint
(N
, False_Value
, Static
);
9976 when Attribute_Pos
=>
9977 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9983 when Attribute_Pred
=>
9985 -- Floating-point case
9987 if Is_Floating_Point_Type
(P_Type
) then
9989 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9993 elsif Is_Fixed_Point_Type
(P_Type
) then
9995 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9997 -- Modular integer case (wraps)
9999 elsif Is_Modular_Integer_Type
(P_Type
) then
10000 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
10002 -- Other scalar cases
10005 pragma Assert
(Is_Scalar_Type
(P_Type
));
10007 if Is_Enumeration_Type
(P_Type
)
10008 and then Expr_Value
(E1
) =
10009 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
10011 Apply_Compile_Time_Constraint_Error
10012 (N
, "Pred of `&''First`",
10013 CE_Overflow_Check_Failed
,
10014 Ent
=> P_Base_Type
,
10015 Warn
=> not Static
);
10020 -- Rewrite the FE-constructed high bound of a null array
10021 -- aggregate to raise CE.
10023 elsif Is_Signed_Integer_Type
(P_Type
)
10024 and then Expr_Value
(E1
) =
10025 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
10026 and then Is_Null_Array_Aggregate_High_Bound
(N
)
10028 Apply_Compile_Time_Constraint_Error
10029 (N
, "Pred of `&''First`",
10030 CE_Overflow_Check_Failed
,
10031 Ent
=> P_Base_Type
,
10034 Rewrite
(N
, Make_Raise_Constraint_Error
(Sloc
(N
),
10035 Reason
=> CE_Overflow_Check_Failed
));
10036 Set_Etype
(N
, P_Base_Type
);
10040 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
10043 ----------------------------------
10044 -- Preelaborable_Initialization --
10045 ----------------------------------
10047 when Attribute_Preelaborable_Initialization
=>
10051 (Boolean'Pos (Has_Preelaborable_Initialization
(P_Type
))),
10058 -- No processing required, because by this stage, Range has been
10059 -- replaced by First .. Last, so this branch can never be taken.
10061 when Attribute_Range
=>
10062 raise Program_Error
;
10068 when Attribute_Range_Length
=> Range_Length
: declare
10069 Diff
: aliased Uint
;
10074 -- Can fold if both bounds are compile time known
10076 if Compile_Time_Known_Value
(Hi_Bound
)
10077 and then Compile_Time_Known_Value
(Lo_Bound
)
10081 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
10085 -- One more case is where Hi_Bound and Lo_Bound are compile-time
10086 -- comparable, and we can figure out the difference between them.
10088 case Compile_Time_Compare
10089 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
10092 Fold_Uint
(N
, Uint_1
, Static
);
10095 Fold_Uint
(N
, Uint_0
, Static
);
10098 if Present
(Diff
) then
10099 Fold_Uint
(N
, Diff
+ 1, Static
);
10111 when Attribute_Ref
=>
10112 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
10118 when Attribute_Remainder
=> Remainder
: declare
10119 X
: constant Ureal
:= Expr_Value_R
(E1
);
10120 Y
: constant Ureal
:= Expr_Value_R
(E2
);
10123 if UR_Is_Zero
(Y
) then
10124 Apply_Compile_Time_Constraint_Error
10125 (N
, "division by zero in Remainder",
10126 CE_Overflow_Check_Failed
,
10127 Warn
=> not Static
);
10133 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
10140 when Attribute_Restriction_Set
=>
10141 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
10142 Set_Is_Static_Expression
(N
);
10148 when Attribute_Round
=> Round
: declare
10153 -- First we get the (exact result) in units of small
10155 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
10157 -- Now round that exactly to an integer
10159 Si
:= UR_To_Uint
(Sr
);
10161 -- Finally the result is obtained by converting back to real
10163 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
10170 when Attribute_Rounding
=>
10172 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10178 when Attribute_Safe_Emax
=>
10179 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
10185 when Attribute_Safe_First
=>
10186 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
10192 when Attribute_Safe_Large
=>
10193 if Is_Fixed_Point_Type
(P_Type
) then
10195 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
10197 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10204 when Attribute_Safe_Last
=>
10205 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10211 when Attribute_Safe_Small
=>
10213 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
10214 -- for fixed-point, since is the same as Small, but we implement
10215 -- it for backwards compatibility.
10217 if Is_Fixed_Point_Type
(P_Type
) then
10218 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
10220 -- Ada 83 Safe_Small for floating-point cases
10223 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
10230 when Attribute_Scale
=>
10231 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
10237 when Attribute_Scaling
=>
10241 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
10248 when Attribute_Signed_Zeros
=>
10250 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
10256 -- Size attribute returns the RM size. All scalar types can be folded,
10257 -- as well as any types for which the size is known by the front end,
10258 -- including any type for which a size attribute is specified. This is
10259 -- one of the places where it is annoying that a size of zero means two
10260 -- things (zero size for scalars, unspecified size for non-scalars).
10262 when Attribute_Size
10263 | Attribute_VADS_Size
10266 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10270 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10271 if Known_RM_Size
(P_TypeA
) then
10274 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
10276 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
10279 -- If a size clause applies, then use the size from it.
10280 -- This is one of the rare cases where we can use the
10281 -- Size_Clause field for a subtype when Has_Size_Clause
10282 -- is False. Consider:
10284 -- type x is range 1 .. 64;
10285 -- for x'size use 12;
10286 -- subtype y is x range 0 .. 3;
10288 -- Here y has a size clause inherited from x, but
10289 -- normally it does not apply, and y'size is 2. However,
10290 -- y'VADS_Size is indeed 12 and not 2.
10293 and then Is_OK_Static_Expression
(Expression
(S
))
10295 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
10297 -- If no size is specified, then we simply use the object
10298 -- size in the VADS_Size case (e.g. Natural'Size is equal
10299 -- to Integer'Size, not one less).
10302 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
10306 -- Normal case (Size) in which case we want the RM_Size
10309 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10318 when Attribute_Small
=>
10320 -- The floating-point case is present only for Ada 83 compatibility.
10321 -- Note that strictly this is an illegal addition, since we are
10322 -- extending an Ada 95 defined attribute, but we anticipate an
10323 -- ARG ruling that will permit this.
10325 if Is_Floating_Point_Type
(P_Type
) then
10327 -- Ada 83 attribute is defined as (RM83 3.5.8)
10329 -- T'Small = 2.0**(-T'Emax - 1)
10333 -- T'Emax = 4 * T'Mantissa
10335 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
10337 -- Normal Ada 95 fixed-point case
10340 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
10343 -----------------------
10344 -- Small_Denominator --
10345 -----------------------
10347 when Attribute_Small_Denominator
=>
10348 Fold_Uint
(N
, Norm_Den
(Small_Value
(P_Type
)), True);
10350 ---------------------
10351 -- Small_Numerator --
10352 ---------------------
10354 when Attribute_Small_Numerator
=>
10355 Fold_Uint
(N
, Norm_Num
(Small_Value
(P_Type
)), True);
10361 when Attribute_Stream_Size
=>
10368 when Attribute_Succ
=>
10369 -- Floating-point case
10371 if Is_Floating_Point_Type
(P_Type
) then
10373 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10375 -- Fixed-point case
10377 elsif Is_Fixed_Point_Type
(P_Type
) then
10378 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
10380 -- Modular integer case (wraps)
10382 elsif Is_Modular_Integer_Type
(P_Type
) then
10383 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
10385 -- Other scalar cases
10388 pragma Assert
(Is_Scalar_Type
(P_Type
));
10390 if Is_Enumeration_Type
(P_Type
)
10391 and then Expr_Value
(E1
) =
10392 Expr_Value
(Type_High_Bound
(P_Base_Type
))
10394 Apply_Compile_Time_Constraint_Error
10395 (N
, "Succ of `&''Last`",
10396 CE_Overflow_Check_Failed
,
10397 Ent
=> P_Base_Type
,
10398 Warn
=> not Static
);
10403 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
10411 when Attribute_Truncation
=>
10414 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
10421 when Attribute_Type_Class
=> Type_Class
: declare
10422 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
10426 if Is_Descendant_Of_Address
(Typ
) then
10427 Id
:= RE_Type_Class_Address
;
10429 elsif Is_Enumeration_Type
(Typ
) then
10430 Id
:= RE_Type_Class_Enumeration
;
10432 elsif Is_Integer_Type
(Typ
) then
10433 Id
:= RE_Type_Class_Integer
;
10435 elsif Is_Fixed_Point_Type
(Typ
) then
10436 Id
:= RE_Type_Class_Fixed_Point
;
10438 elsif Is_Floating_Point_Type
(Typ
) then
10439 Id
:= RE_Type_Class_Floating_Point
;
10441 elsif Is_Array_Type
(Typ
) then
10442 Id
:= RE_Type_Class_Array
;
10444 elsif Is_Record_Type
(Typ
) then
10445 Id
:= RE_Type_Class_Record
;
10447 elsif Is_Access_Type
(Typ
) then
10448 Id
:= RE_Type_Class_Access
;
10450 elsif Is_Task_Type
(Typ
) then
10451 Id
:= RE_Type_Class_Task
;
10453 -- We treat protected types like task types. It would make more
10454 -- sense to have another enumeration value, but after all the
10455 -- whole point of this feature is to be exactly DEC compatible,
10456 -- and changing the type Type_Class would not meet this requirement.
10458 elsif Is_Protected_Type
(Typ
) then
10459 Id
:= RE_Type_Class_Task
;
10461 -- Not clear if there are any other possibilities, but if there
10462 -- are, then we will treat them as the address case.
10465 Id
:= RE_Type_Class_Address
;
10468 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
10471 -----------------------
10472 -- Unbiased_Rounding --
10473 -----------------------
10475 when Attribute_Unbiased_Rounding
=>
10478 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
10481 -------------------------
10482 -- Unconstrained_Array --
10483 -------------------------
10485 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
10486 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10489 Rewrite
(N
, New_Occurrence_Of
(
10491 Is_Array_Type
(P_Type
)
10492 and then not Is_Constrained
(Typ
)), Loc
));
10494 -- Analyze and resolve as boolean, note that this attribute is
10495 -- a static attribute in GNAT.
10497 Analyze_And_Resolve
(N
, Standard_Boolean
);
10499 Set_Is_Static_Expression
(N
, True);
10500 end Unconstrained_Array
;
10502 -- Attribute Update is never static
10504 when Attribute_Update
=>
10511 -- Processing is shared with Size
10517 when Attribute_Val
=>
10518 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
10520 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
10522 Apply_Compile_Time_Constraint_Error
10523 (N
, "Val expression out of range",
10524 CE_Range_Check_Failed
,
10525 Warn
=> not Static
);
10531 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
10538 -- The Value_Size attribute for a type returns the RM size of the type.
10539 -- This an always be folded for scalar types, and can also be folded for
10540 -- non-scalar types if the size is set. This is one of the places where
10541 -- it is annoying that a size of zero means two things!
10543 when Attribute_Value_Size
=> Value_Size
: declare
10544 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10548 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10549 if Known_RM_Size
(P_TypeA
) then
10550 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10558 -- Version can never be static
10560 when Attribute_Version
=>
10567 -- Wide_Image is a scalar attribute, but is never static, because it
10568 -- is not a static function (having a non-scalar argument (RM 4.9(22))
10570 when Attribute_Wide_Image
=>
10573 ---------------------
10574 -- Wide_Wide_Image --
10575 ---------------------
10577 -- Wide_Wide_Image is a scalar attribute but is never static, because it
10578 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
10580 when Attribute_Wide_Wide_Image
=>
10583 ---------------------
10584 -- Wide_Wide_Width --
10585 ---------------------
10587 -- Processing for Wide_Wide_Width is combined with Width
10593 -- Processing for Wide_Width is combined with Width
10599 -- This processing also handles the case of Wide_[Wide_]Width
10601 when Attribute_Width
10602 | Attribute_Wide_Width
10603 | Attribute_Wide_Wide_Width
10605 if Compile_Time_Known_Bounds
(P_Type
) then
10607 -- Floating-point types
10609 if Is_Floating_Point_Type
(P_Type
) then
10611 -- Width is zero for a null range (RM 3.5 (38))
10613 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
10614 Expr_Value_R
(Type_Low_Bound
(P_Type
))
10616 Fold_Uint
(N
, Uint_0
, Static
);
10619 -- For floating-point, we have +N.dddE+nnn where length
10620 -- of ddd is determined by type'Digits - 1, but is one
10621 -- if Digits is one (RM 3.5 (33)).
10623 -- nnn is set to 2 for Short_Float and Float (32 bit
10624 -- floats), and 3 for Long_Float and Long_Long_Float.
10625 -- For machines where Long_Long_Float is the IEEE
10626 -- extended precision type, the exponent takes 4 digits.
10630 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
10633 if Esize
(P_Type
) <= 32 then
10635 elsif Esize
(P_Type
) = 64 then
10641 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
10645 -- Fixed-point types
10647 elsif Is_Fixed_Point_Type
(P_Type
) then
10649 -- Width is zero for a null range (RM 3.5 (38))
10651 if Expr_Value
(Type_High_Bound
(P_Type
)) <
10652 Expr_Value
(Type_Low_Bound
(P_Type
))
10654 Fold_Uint
(N
, Uint_0
, Static
);
10656 -- The non-null case depends on the specific real type
10659 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
10662 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
10670 R
: constant Entity_Id
:= Root_Type
(P_Type
);
10671 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
10672 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
10685 -- Width for types derived from Standard.Character
10686 -- and Standard.Wide_[Wide_]Character.
10688 elsif Is_Standard_Character_Type
(P_Type
) then
10691 -- Set W larger if needed
10693 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
10695 -- All wide characters look like Hex_hhhhhhhh
10699 -- No need to compute this more than once
10704 C
:= Character'Val (J
);
10706 -- Test for all cases where Character'Image
10707 -- yields an image that is longer than three
10708 -- characters. First the cases of Reserved_xxx
10709 -- names (length = 12).
10786 when Space
.. Tilde
10787 | No_Break_Space
.. LC_Y_Diaeresis
10789 -- Special case of soft hyphen in Ada 2005
10791 if C
= Character'Val (16#AD#
)
10792 and then Ada_Version
>= Ada_2005
10800 W
:= Int
'Max (W
, Wt
);
10804 -- Width for types derived from Standard.Boolean
10806 elsif R
= Standard_Boolean
then
10813 -- Width for integer types
10815 elsif Is_Integer_Type
(P_Type
) then
10816 T
:= UI_Max
(abs Lo
, abs Hi
);
10824 -- User declared enum type with discard names
10826 elsif Discard_Names
(R
) then
10828 -- If range is null, result is zero, that has already
10829 -- been dealt with, so what we need is the power of ten
10830 -- that accommodates the Pos of the largest value, which
10831 -- is the high bound of the range + one for the space.
10840 -- Only remaining possibility is user declared enum type
10841 -- with normal case of Discard_Names not active.
10844 pragma Assert
(Is_Enumeration_Type
(P_Type
));
10847 L
:= First_Literal
(P_Type
);
10848 while Present
(L
) loop
10850 -- Only pay attention to in range characters
10852 if Lo
<= Enumeration_Pos
(L
)
10853 and then Enumeration_Pos
(L
) <= Hi
10855 -- For Width case, use decoded name
10857 if Id
= Attribute_Width
then
10858 Get_Decoded_Name_String
(Chars
(L
));
10859 Wt
:= Nat
(Name_Len
);
10861 -- For Wide_[Wide_]Width, use encoded name, and
10862 -- then adjust for the encoding.
10865 Get_Name_String
(Chars
(L
));
10867 -- Character literals are always of length 3
10869 if Name_Buffer
(1) = 'Q' then
10872 -- Otherwise loop to adjust for upper/wide chars
10875 Wt
:= Nat
(Name_Len
);
10877 for J
in 1 .. Name_Len
loop
10878 if Name_Buffer
(J
) = 'U' then
10880 elsif Name_Buffer
(J
) = 'W' then
10887 W
:= Int
'Max (W
, Wt
);
10894 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
10899 -- The following attributes denote functions that cannot be folded
10901 when Attribute_From_Any
10903 | Attribute_TypeCode
10907 -- The following attributes can never be folded, and furthermore we
10908 -- should not even have entered the case statement for any of these.
10909 -- Note that in some cases, the values have already been folded as
10910 -- a result of the processing in Analyze_Attribute or earlier in
10913 when Attribute_Abort_Signal
10915 | Attribute_Address
10916 | Attribute_Address_Size
10917 | Attribute_Asm_Input
10918 | Attribute_Asm_Output
10920 | Attribute_Bit_Order
10921 | Attribute_Bit_Position
10922 | Attribute_Callable
10925 | Attribute_Code_Address
10926 | Attribute_Compiler_Version
10928 | Attribute_Default_Bit_Order
10929 | Attribute_Default_Scalar_Storage_Order
10931 | Attribute_Elaborated
10932 | Attribute_Elab_Body
10933 | Attribute_Elab_Spec
10934 | Attribute_Elab_Subp_Body
10935 | Attribute_Enabled
10936 | Attribute_External_Tag
10937 | Attribute_Fast_Math
10938 | Attribute_First_Bit
10942 | Attribute_Initialized
10943 | Attribute_Last_Bit
10944 | Attribute_Library_Level
10945 | Attribute_Max_Integer_Size
10946 | Attribute_Maximum_Alignment
10949 | Attribute_Partition_ID
10950 | Attribute_Pool_Address
10951 | Attribute_Position
10952 | Attribute_Priority
10953 | Attribute_Put_Image
10956 | Attribute_Scalar_Storage_Order
10957 | Attribute_Simple_Storage_Pool
10958 | Attribute_Storage_Pool
10959 | Attribute_Storage_Size
10960 | Attribute_Storage_Unit
10961 | Attribute_Stub_Type
10962 | Attribute_System_Allocator_Alignment
10964 | Attribute_Target_Name
10965 | Attribute_Terminated
10966 | Attribute_To_Address
10967 | Attribute_Type_Key
10968 | Attribute_Unchecked_Access
10969 | Attribute_Universal_Literal_String
10970 | Attribute_Unrestricted_Access
10972 | Attribute_Valid_Scalars
10973 | Attribute_Valid_Value
10975 | Attribute_Wchar_T_Size
10976 | Attribute_Wide_Value
10977 | Attribute_Wide_Wide_Value
10978 | Attribute_Word_Size
10981 raise Program_Error
;
10984 -- At the end of the case, one more check. If we did a static evaluation
10985 -- so that the result is now a literal, then set Is_Static_Expression
10986 -- in the constant only if the prefix type is a static subtype. For
10987 -- non-static subtypes, the folding is still OK, but not static.
10989 -- An exception is the GNAT attribute Constrained_Array which is
10990 -- defined to be a static attribute in all cases.
10992 if Nkind
(N
) in N_Integer_Literal
10994 | N_Character_Literal
10996 or else (Is_Entity_Name
(N
)
10997 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10999 Set_Is_Static_Expression
(N
, Static
);
11001 -- If this is still an attribute reference, then it has not been folded
11002 -- and that means that its expressions are in a non-static context.
11004 elsif Nkind
(N
) = N_Attribute_Reference
then
11007 -- Note: the else case not covered here are odd cases where the
11008 -- processing has transformed the attribute into something other
11009 -- than a constant. Nothing more to do in such cases.
11014 end Eval_Attribute
;
11016 ------------------------------
11017 -- Is_Anonymous_Tagged_Base --
11018 ------------------------------
11020 function Is_Anonymous_Tagged_Base
11022 Typ
: Entity_Id
) return Boolean
11026 Anon
= Current_Scope
11027 and then Is_Itype
(Anon
)
11028 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
11029 end Is_Anonymous_Tagged_Base
;
11031 --------------------------------
11032 -- Name_Implies_Lvalue_Prefix --
11033 --------------------------------
11035 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
11036 pragma Assert
(Is_Attribute_Name
(Nam
));
11038 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
11039 end Name_Implies_Lvalue_Prefix
;
11041 -----------------------
11042 -- Resolve_Attribute --
11043 -----------------------
11045 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
11046 Loc
: constant Source_Ptr
:= Sloc
(N
);
11047 P
: constant Node_Id
:= Prefix
(N
);
11048 Aname
: constant Name_Id
:= Attribute_Name
(N
);
11049 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
11050 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
11051 Des_Btyp
: Entity_Id
;
11052 Index
: Interp_Index
;
11054 Nom_Subt
: Entity_Id
;
11056 function Declared_Within_Generic_Unit
11057 (Entity
: Entity_Id
;
11058 Generic_Unit
: Node_Id
) return Boolean;
11059 -- Returns True if Declared_Entity is declared within the declarative
11060 -- region of Generic_Unit; otherwise returns False.
11062 function Is_Thin_Pointer_To_Unc_Array
(T
: Entity_Id
) return Boolean;
11063 -- Return True if T is a thin pointer to an unconstrained array type
11065 ----------------------------------
11066 -- Declared_Within_Generic_Unit --
11067 ----------------------------------
11069 function Declared_Within_Generic_Unit
11070 (Entity
: Entity_Id
;
11071 Generic_Unit
: Node_Id
) return Boolean
11073 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
11076 while Present
(Generic_Encloser
) loop
11077 if Generic_Encloser
= Generic_Unit
then
11081 -- We have to step to the scope of the generic's entity, because
11082 -- otherwise we'll just get back the same generic.
11084 Generic_Encloser
:=
11085 Enclosing_Generic_Unit
11086 (Scope
(Defining_Entity
(Generic_Encloser
)));
11090 end Declared_Within_Generic_Unit
;
11092 ----------------------------------
11093 -- Is_Thin_Pointer_To_Unc_Array --
11094 ----------------------------------
11096 function Is_Thin_Pointer_To_Unc_Array
(T
: Entity_Id
) return Boolean is
11098 if Is_Access_Type
(T
)
11099 and then Has_Size_Clause
(T
)
11100 and then RM_Size
(T
) = System_Address_Size
11103 DT
: constant Entity_Id
:= Designated_Type
(T
);
11106 return Is_Array_Type
(DT
) and then not Is_Constrained
(DT
);
11112 end Is_Thin_Pointer_To_Unc_Array
;
11114 -- Start of processing for Resolve_Attribute
11117 -- If error during analysis, no point in continuing, except for array
11118 -- types, where we get better recovery by using unconstrained indexes
11119 -- than nothing at all (see Check_Array_Type).
11121 if Error_Posted
(N
)
11122 and then Attr_Id
/= Attribute_First
11123 and then Attr_Id
/= Attribute_Last
11124 and then Attr_Id
/= Attribute_Length
11125 and then Attr_Id
/= Attribute_Range
11130 -- If attribute was universal type, reset to actual type
11132 if Is_Universal_Numeric_Type
(Etype
(N
)) then
11133 Set_Etype
(N
, Typ
);
11136 -- A Ghost attribute must appear in a specific context
11138 if Is_Ghost_Attribute_Reference
(N
) then
11139 Check_Ghost_Context
(Empty
, N
);
11142 -- Remaining processing depends on attribute
11150 -- For access attributes, if the prefix denotes an entity, it is
11151 -- interpreted as a name, never as a call. It may be overloaded,
11152 -- in which case resolution uses the profile of the context type.
11153 -- Otherwise prefix must be resolved.
11155 when Attribute_Access
11156 | Attribute_Unchecked_Access
11157 | Attribute_Unrestricted_Access
11159 -- Note possible modification if we have a variable
11162 and then not Is_Access_Constant
(Typ
)
11164 Note_Possible_Modification
(P
, Sure
=> False);
11167 -- Case where prefix is an entity name
11169 if Is_Entity_Name
(P
) then
11171 -- Deal with case where prefix itself is overloaded
11173 if Is_Overloaded
(P
) then
11174 Get_First_Interp
(P
, Index
, It
);
11175 while Present
(It
.Nam
) loop
11176 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11177 Set_Entity
(P
, It
.Nam
);
11179 -- The prefix is definitely NOT overloaded anymore at
11180 -- this point, so we reset the Is_Overloaded flag to
11181 -- avoid any confusion when reanalyzing the node.
11183 Set_Is_Overloaded
(P
, False);
11184 Set_Is_Overloaded
(N
, False);
11185 Generate_Reference
(Entity
(P
), P
);
11189 Get_Next_Interp
(Index
, It
);
11192 -- If Prefix is a subprogram name, this reference freezes,
11193 -- but not if within spec expression mode. The profile of
11194 -- the subprogram is not frozen at this point.
11196 if not In_Spec_Expression
then
11197 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11200 -- If it is a type, there is nothing to resolve.
11201 -- If it is a subprogram, do not freeze its profile.
11202 -- If it is an object, complete its resolution.
11204 elsif Is_Overloadable
(Entity
(P
)) then
11205 if not In_Spec_Expression
then
11206 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11209 -- Nothing to do if prefix is a type name
11211 elsif Is_Type
(Entity
(P
)) then
11214 -- Otherwise non-overloaded other case, resolve the prefix
11220 -- Some further error checks
11222 Error_Msg_Name_1
:= Aname
;
11224 if not Is_Entity_Name
(P
) then
11227 elsif Is_Overloadable
(Entity
(P
))
11228 and then Is_Abstract_Subprogram
(Entity
(P
))
11230 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
11231 Set_Etype
(N
, Any_Type
);
11233 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
11235 ("prefix of % attribute cannot be enumeration literal", P
);
11236 Set_Etype
(N
, Any_Type
);
11238 -- An attempt to take 'Access of a function that renames an
11239 -- enumeration literal. Issue a specialized error message.
11241 elsif Ekind
(Entity
(P
)) = E_Function
11242 and then Present
(Alias
(Entity
(P
)))
11243 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
11246 ("prefix of % attribute cannot be function renaming "
11247 & "an enumeration literal", P
);
11248 Set_Etype
(N
, Any_Type
);
11250 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
11251 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
11252 Set_Etype
(N
, Any_Type
);
11255 -- Assignments, return statements, components of aggregates,
11256 -- generic instantiations will require convention checks if
11257 -- the type is an access to subprogram. Given that there will
11258 -- also be accessibility checks on those, this is where the
11259 -- checks can eventually be centralized ???
11261 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11262 | E_Access_Subprogram_Type
11263 | E_Anonymous_Access_Protected_Subprogram_Type
11264 | E_Anonymous_Access_Subprogram_Type
11266 -- Deal with convention mismatch
11268 if Convention
(Designated_Type
(Btyp
)) /=
11269 Convention
(Entity
(P
))
11272 ("subprogram & has wrong convention", P
, Entity
(P
));
11273 Error_Msg_Sloc
:= Sloc
(Btyp
);
11274 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
11276 if not Is_Itype
(Btyp
)
11277 and then not Has_Convention_Pragma
(Btyp
)
11278 and then Convention
(Entity
(P
)) /= Convention_Intrinsic
11281 ("\probable missing pragma Convention for &",
11286 Check_Subtype_Conformant
11287 (New_Id
=> Entity
(P
),
11288 Old_Id
=> Designated_Type
(Btyp
),
11292 if Attr_Id
= Attribute_Unchecked_Access
then
11293 Error_Msg_Name_1
:= Aname
;
11295 ("attribute% cannot be applied to a subprogram", P
);
11297 elsif Aname
= Name_Unrestricted_Access
then
11298 null; -- Nothing to check
11300 -- Check the static accessibility rule of 3.10.2(32).
11301 -- This rule also applies within the private part of an
11302 -- instantiation. This rule does not apply to anonymous
11303 -- access-to-subprogram types in access parameters.
11305 elsif Attr_Id
= Attribute_Access
11306 and then not In_Instance_Body
11308 (Ekind
(Btyp
) = E_Access_Subprogram_Type
11309 or else Is_Local_Anonymous_Access
(Btyp
))
11310 and then Subprogram_Access_Level
(Entity
(P
)) >
11311 Type_Access_Level
(Btyp
)
11314 ("subprogram must not be deeper than access type", P
);
11316 -- Check the restriction of 3.10.2(32) that disallows the
11317 -- access attribute within a generic body when the ultimate
11318 -- ancestor of the type of the attribute is declared outside
11319 -- of the generic unit and the subprogram is declared within
11320 -- that generic unit. This includes any such attribute that
11321 -- occurs within the body of a generic unit that is a child
11322 -- of the generic unit where the subprogram is declared.
11324 -- The rule also prohibits applying the attribute when the
11325 -- access type is a generic formal access type (since the
11326 -- level of the actual type is not known). This restriction
11327 -- does not apply when the attribute type is an anonymous
11328 -- access-to-subprogram type. Note that this check was
11329 -- revised by AI-229, because the original Ada 95 rule
11330 -- was too lax. The original rule only applied when the
11331 -- subprogram was declared within the body of the generic,
11332 -- which allowed the possibility of dangling references).
11333 -- The rule was also too strict in some cases, in that it
11334 -- didn't permit the access to be declared in the generic
11335 -- spec, whereas the revised rule does (as long as it's not
11338 -- There are a couple of subtleties of the test for applying
11339 -- the check that are worth noting. First, we only apply it
11340 -- when the levels of the subprogram and access type are the
11341 -- same (the case where the subprogram is statically deeper
11342 -- was applied above, and the case where the type is deeper
11343 -- is always safe). Second, we want the check to apply
11344 -- within nested generic bodies and generic child unit
11345 -- bodies, but not to apply to an attribute that appears in
11346 -- the generic unit's specification. This is done by testing
11347 -- that the attribute's innermost enclosing generic body is
11348 -- not the same as the innermost generic body enclosing the
11349 -- generic unit where the subprogram is declared (we don't
11350 -- want the check to apply when the access attribute is in
11351 -- the spec and there's some other generic body enclosing
11352 -- generic). Finally, there's no point applying the check
11353 -- when within an instance, because any violations will have
11354 -- been caught by the compilation of the generic unit.
11356 -- We relax this check in Relaxed_RM_Semantics mode for
11357 -- compatibility with legacy code for use by Ada source
11358 -- code analyzers (e.g. CodePeer).
11360 elsif Attr_Id
= Attribute_Access
11361 and then not Relaxed_RM_Semantics
11362 and then not In_Instance
11363 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
11364 and then Present
(Enclosing_Generic_Body
(N
))
11365 and then Enclosing_Generic_Body
(N
) /=
11366 Enclosing_Generic_Body
11367 (Enclosing_Generic_Unit
(Entity
(P
)))
11368 and then Subprogram_Access_Level
(Entity
(P
)) =
11369 Type_Access_Level
(Btyp
)
11370 and then Ekind
(Btyp
) /=
11371 E_Anonymous_Access_Subprogram_Type
11372 and then Ekind
(Btyp
) /=
11373 E_Anonymous_Access_Protected_Subprogram_Type
11375 -- The attribute type's ultimate ancestor must be
11376 -- declared within the same generic unit as the
11377 -- subprogram is declared (including within another
11378 -- nested generic unit). The error message is
11379 -- specialized to say "ancestor" for the case where the
11380 -- access type is not its own ancestor, since saying
11381 -- simply "access type" would be very confusing.
11383 if not Declared_Within_Generic_Unit
11385 Enclosing_Generic_Unit
(Entity
(P
)))
11388 ("''Access attribute not allowed in generic body",
11391 if Root_Type
(Btyp
) = Btyp
then
11394 "access type & is declared outside " &
11395 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11398 ("\because ancestor of " &
11399 "access type & is declared outside " &
11400 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11404 ("\move ''Access to private part, or " &
11405 "(Ada 2005) use anonymous access type instead of &",
11408 -- If the ultimate ancestor of the attribute's type is
11409 -- a formal type, then the attribute is illegal because
11410 -- the actual type might be declared at a higher level.
11411 -- The error message is specialized to say "ancestor"
11412 -- for the case where the access type is not its own
11413 -- ancestor, since saying simply "access type" would be
11416 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
11417 if Root_Type
(Btyp
) = Btyp
then
11419 ("access type must not be a generic formal type",
11423 ("ancestor access type must not be a generic " &
11430 -- If this is a renaming, an inherited operation, or a
11431 -- subprogram instance, use the original entity. This may make
11432 -- the node type-inconsistent, so this transformation can only
11433 -- be done if the node will not be reanalyzed. In particular,
11434 -- if it is within a default expression, the transformation
11435 -- must be delayed until the default subprogram is created for
11436 -- it, when the enclosing subprogram is frozen.
11438 if Is_Entity_Name
(P
)
11439 and then Is_Overloadable
(Entity
(P
))
11440 and then Present
(Alias
(Entity
(P
)))
11441 and then Expander_Active
11444 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11447 elsif Nkind
(P
) = N_Selected_Component
11448 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
11450 -- Protected operation. If operation is overloaded, must
11451 -- disambiguate. Prefix that denotes protected object itself
11452 -- is resolved with its own type.
11454 if Attr_Id
= Attribute_Unchecked_Access
then
11455 Error_Msg_Name_1
:= Aname
;
11457 ("attribute% cannot be applied to protected operation", P
);
11460 Resolve
(Prefix
(P
));
11462 if not Is_Overloaded
(P
) then
11463 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11466 Get_First_Interp
(P
, Index
, It
);
11467 while Present
(It
.Nam
) loop
11468 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11469 Set_Entity
(Selector_Name
(P
), It
.Nam
);
11471 -- The prefix is definitely NOT overloaded anymore at
11472 -- this point, so we reset the Is_Overloaded flag to
11473 -- avoid any confusion when reanalyzing the node.
11475 Set_Is_Overloaded
(P
, False);
11476 Set_Is_Overloaded
(N
, False);
11477 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11481 Get_Next_Interp
(Index
, It
);
11485 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
11486 -- statically illegal if F is an anonymous access to subprogram.
11488 elsif Nkind
(P
) = N_Explicit_Dereference
11489 and then Is_Entity_Name
(Prefix
(P
))
11490 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
11491 E_Anonymous_Access_Subprogram_Type
11493 Error_Msg_N
("anonymous access to subprogram "
11494 & "has deeper accessibility than any master", P
);
11496 elsif Is_Overloaded
(P
) then
11498 -- Use the designated type of the context to disambiguate
11499 -- Note that this was not strictly conformant to Ada 95,
11500 -- but was the implementation adopted by most Ada 95 compilers.
11501 -- The use of the context type to resolve an Access attribute
11502 -- reference is now mandated in AI-235 for Ada 2005.
11505 Index
: Interp_Index
;
11509 Get_First_Interp
(P
, Index
, It
);
11510 while Present
(It
.Typ
) loop
11511 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
11512 Resolve
(P
, It
.Typ
);
11516 Get_Next_Interp
(Index
, It
);
11523 -- Refuse to compute access to variables and constants when that
11524 -- would drop the strub mode associated with them, unless they're
11525 -- unchecked conversions. We don't have to do this when the types
11526 -- of the data objects are annotated: then the access type
11527 -- designates the annotated type, and there's no loss. Only when
11528 -- the variable is annotated directly that the pragma gets
11529 -- attached to the variable, rather than to its type, and then,
11530 -- expressing an access-to-annotated-type type to hold the 'Access
11531 -- result is not possible without resorting to that very annotated
11534 if Attr_Id
/= Attribute_Unchecked_Access
11535 and then Comes_From_Source
(N
)
11536 and then Is_Entity_Name
(P
)
11537 and then Explicit_Strub_Mode
(Entity
(P
)) = Enabled
11539 Explicit_Strub_Mode
(Designated_Type
(Btyp
)) = Unspecified
11541 Error_Msg_F
("target access type drops `strub` mode from &", P
);
11544 -- X'Access is illegal if X denotes a constant and the access type
11545 -- is access-to-variable. Same for 'Unchecked_Access. The rule
11546 -- does not apply to 'Unrestricted_Access. If the reference is a
11547 -- default-initialized aggregate component for a self-referential
11548 -- type the reference is legal.
11550 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
11551 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
11552 or else (Is_Record_Type
(Btyp
)
11554 Present
(Corresponding_Remote_Type
(Btyp
)))
11555 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11556 or else Ekind
(Btyp
)
11557 = E_Anonymous_Access_Protected_Subprogram_Type
11558 or else Is_Access_Constant
(Btyp
)
11559 or else Is_Variable
(P
)
11560 or else Attr_Id
= Attribute_Unrestricted_Access
)
11562 if Is_Entity_Name
(P
)
11563 and then Is_Type
(Entity
(P
))
11565 -- Legality of a self-reference through an access
11566 -- attribute has been verified in Analyze_Access_Attribute.
11570 elsif Comes_From_Source
(N
) then
11571 Error_Msg_F
("access-to-variable designates constant", P
);
11575 Des_Btyp
:= Designated_Type
(Btyp
);
11577 if Ada_Version
>= Ada_2005
11578 and then Is_Incomplete_Type
(Des_Btyp
)
11580 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
11581 -- imported entity, and the non-limited view is visible, make
11582 -- use of it. If it is an incomplete subtype, use the base type
11585 if From_Limited_With
(Des_Btyp
)
11586 and then Present
(Non_Limited_View
(Des_Btyp
))
11588 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
11590 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
11591 Des_Btyp
:= Etype
(Des_Btyp
);
11595 if Ekind
(Btyp
) in E_General_Access_Type | E_Anonymous_Access_Type
11597 -- Ada 2005 (AI-230): Check the accessibility of anonymous
11598 -- access types for stand-alone objects, record and array
11599 -- components, and return objects. For a component definition
11600 -- the level is the same of the enclosing composite type.
11602 if Ada_Version
>= Ada_2005
11603 and then Attr_Id
= Attribute_Access
11604 and then (Is_Local_Anonymous_Access
(Btyp
)
11606 -- Handle cases where Btyp is the anonymous access
11607 -- type of an Ada 2012 stand-alone object.
11609 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
11610 N_Object_Declaration
)
11612 -- Verify that static checking is OK (namely that we aren't
11613 -- in a specific context requiring dynamic checks on
11614 -- expicitly aliased parameters), and then check the level.
11616 -- Otherwise a check will be generated later when the return
11617 -- statement gets expanded.
11619 and then not Is_Special_Aliased_Formal_Access
(N
)
11621 Static_Accessibility_Level
(N
, Zero_On_Dynamic_Level
) >
11622 Deepest_Type_Access_Level
(Btyp
)
11624 -- In an instance, this is a runtime check, but one we know
11625 -- will fail, so generate an appropriate warning. As usual,
11626 -- this kind of warning is an error in SPARK mode.
11628 if In_Instance_Body
then
11632 not No_Dynamic_Accessibility_Checks_Enabled
(P
);
11635 ("non-local pointer cannot point to local object<<", P
);
11636 Error_Msg_F
("\Program_Error [<<", P
);
11639 Make_Raise_Program_Error
(Loc
,
11640 Reason
=> PE_Accessibility_Check_Failed
));
11641 Set_Etype
(N
, Typ
);
11645 ("non-local pointer cannot point to local object", P
);
11649 if Attr_Id
/= Attribute_Unrestricted_Access
11650 and then Is_Dependent_Component_Of_Mutable_Object
(P
)
11653 ("illegal attribute for discriminant-dependent component",
11657 -- Check static matching rule of 3.10.2(27). Nominal subtype
11658 -- of the prefix must statically match the designated type.
11660 Nom_Subt
:= Etype
(P
);
11662 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
11663 Nom_Subt
:= Base_Type
(Nom_Subt
);
11666 -- We do not enforce static matching for Unrestricted_Access
11667 -- except for a thin pointer to an unconstrained array type,
11668 -- because, in this case, the designated object must contain
11669 -- its bounds, which means that it must have an unconstrained
11670 -- nominal subtype (and be aliased, as will be checked below).
11672 if Attr_Id
= Attribute_Unrestricted_Access
11673 and then not (Is_Thin_Pointer_To_Unc_Array
(Typ
)
11674 and then Is_Aliased_View
(Original_Node
(P
)))
11678 elsif Is_Tagged_Type
(Designated_Type
(Typ
)) then
11680 -- If the attribute is in the context of an access
11681 -- parameter, then the prefix is allowed to be of
11682 -- the class-wide type (by AI-127).
11684 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
11685 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11686 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
11692 Desig
:= Designated_Type
(Typ
);
11694 if Is_Class_Wide_Type
(Desig
) then
11695 Desig
:= Etype
(Desig
);
11698 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
11703 ("type of prefix: & not compatible",
11706 ("\with &, the expected designated type",
11707 P
, Designated_Type
(Typ
));
11712 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11714 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11715 and then Is_Class_Wide_Type
(Nom_Subt
))
11718 ("type of prefix: & is not covered", P
, Nom_Subt
);
11720 ("\by &, the expected designated type" &
11721 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
11724 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
11725 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
11726 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
11727 and then Designated_Type
(Typ
) /= Nom_Subt
11729 Apply_Discriminant_Check
11730 (N
, Etype
(Designated_Type
(Typ
)));
11733 -- Ada 2005 (AI-363): Require static matching when designated
11734 -- type has discriminants and a constrained partial view, since
11735 -- in general objects of such types are mutable, so we can't
11736 -- allow the access value to designate a constrained object
11737 -- (because access values must be assumed to designate mutable
11738 -- objects when designated type does not impose a constraint).
11740 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
11743 elsif Has_Discriminants
(Designated_Type
(Typ
))
11744 and then not Is_Constrained
(Des_Btyp
)
11746 (Ada_Version
< Ada_2005
11748 not Object_Type_Has_Constrained_Partial_View
11749 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
11750 Scop
=> Current_Scope
))
11756 ("object subtype must statically match "
11757 & "designated subtype", P
);
11759 if Is_Entity_Name
(P
)
11760 and then Is_Array_Type
(Designated_Type
(Typ
))
11763 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
11766 ("aliased object has explicit bounds??", D
);
11768 ("\declare without bounds (and with explicit "
11769 & "initialization)??", D
);
11771 ("\for use with unconstrained access??", D
);
11776 -- Check the static accessibility rule of 3.10.2(28). Note that
11777 -- this check is not performed for the case of an anonymous
11778 -- access type, since the access attribute is always legal
11779 -- in such a context - unless the restriction
11780 -- No_Dynamic_Accessibility_Checks is active.
11783 No_Dynamic_Acc_Checks
: constant Boolean :=
11784 No_Dynamic_Accessibility_Checks_Enabled
(Btyp
);
11786 Compatible_Alt_Checks
: constant Boolean :=
11787 No_Dynamic_Acc_Checks
and then not Debug_Flag_Underscore_B
;
11790 if Attr_Id
= Attribute_Access
11791 and then (Ekind
(Btyp
) = E_General_Access_Type
11792 or else No_Dynamic_Acc_Checks
)
11794 -- In the case of the alternate "compatibility"
11795 -- accessibility model we do not perform a static
11796 -- accessibility check on actuals for anonymous access
11797 -- types - so exclude them here.
11799 and then not (Compatible_Alt_Checks
11800 and then Is_Actual_Parameter
(N
)
11801 and then Ekind
(Btyp
)
11802 = E_Anonymous_Access_Type
)
11804 -- Call Accessibility_Level directly to avoid returning
11805 -- zero on cases where the prefix is an explicitly aliased
11806 -- parameter in a return statement, instead of using the
11807 -- normal Static_Accessibility_Level function.
11809 -- Shouldn't this be handled somehow in
11810 -- Static_Accessibility_Level ???
11812 and then Nkind
(Accessibility_Level
(P
, Dynamic_Level
))
11813 = N_Integer_Literal
11815 Intval
(Accessibility_Level
(P
, Dynamic_Level
))
11816 > Deepest_Type_Access_Level
(Btyp
)
11818 Accessibility_Message
(N
, Typ
);
11824 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11825 | E_Anonymous_Access_Protected_Subprogram_Type
11827 if Is_Entity_Name
(P
)
11828 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
11830 Error_Msg_F
("context requires a protected subprogram", P
);
11832 -- Check accessibility of protected object against that of the
11833 -- access type, but only on user code, because the expander
11834 -- creates access references for handlers. If the context is an
11835 -- anonymous_access_to_protected, there are no accessibility
11836 -- checks either. Omit check entirely for Unrestricted_Access.
11838 elsif Static_Accessibility_Level
(P
, Zero_On_Dynamic_Level
)
11839 > Deepest_Type_Access_Level
(Btyp
)
11840 and then Comes_From_Source
(N
)
11841 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11842 and then Attr_Id
/= Attribute_Unrestricted_Access
11844 Accessibility_Message
(N
, Typ
);
11847 -- AI05-0225: If the context is not an access to protected
11848 -- function, the prefix must be a variable, given that it may
11849 -- be used subsequently in a protected call.
11851 elsif Nkind
(P
) = N_Selected_Component
11852 and then not Is_Variable
(Prefix
(P
))
11853 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
11856 ("target object of access to protected procedure "
11857 & "must be variable", N
);
11859 elsif Is_Entity_Name
(P
) then
11860 Check_Internal_Protected_Use
(N
, Entity
(P
));
11863 elsif Ekind
(Btyp
) in E_Access_Subprogram_Type
11864 | E_Anonymous_Access_Subprogram_Type
11865 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
11867 Error_Msg_F
("context requires a non-protected subprogram", P
);
11870 -- AI12-0412: The rule in RM 6.1.1(18.2/5) disallows applying
11871 -- attribute Access to a primitive of an abstract type when the
11872 -- primitive has any Pre'Class or Post'Class aspects specified
11873 -- with nonstatic expressions.
11875 if Attr_Id
= Attribute_Access
11876 and then Ekind
(Btyp
) in E_Access_Subprogram_Type
11877 | E_Anonymous_Access_Subprogram_Type
11878 and then Is_Entity_Name
(P
)
11879 and then Is_Dispatching_Operation
(Entity
(P
))
11881 Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
(Entity
(P
))
11884 ("attribute not allowed for primitive of abstract type with "
11885 & "nonstatic class-wide pre/postconditions",
11889 -- The context cannot be a pool-specific type, but this is a
11890 -- legality rule, not a resolution rule, so it must be checked
11891 -- separately, after possibly disambiguation (see AI-245).
11893 if Ekind
(Btyp
) = E_Access_Type
11894 and then Attr_Id
/= Attribute_Unrestricted_Access
11896 Wrong_Type
(N
, Typ
);
11899 -- The context may be a constrained access type (however ill-
11900 -- advised such subtypes might be) so in order to generate a
11901 -- constraint check we need to set the type of the attribute
11902 -- reference to the base type of the context.
11904 Set_Etype
(N
, Btyp
);
11906 -- Check for incorrect atomic/volatile/VFA reference (RM C.6(12))
11908 if Attr_Id
/= Attribute_Unrestricted_Access
then
11909 if Is_Atomic_Object
(P
)
11910 and then not Is_Atomic
(Designated_Type
(Typ
))
11913 ("access to atomic object cannot yield access-to-" &
11914 "non-atomic type", P
);
11916 elsif Is_Volatile_Object_Ref
(P
)
11917 and then not Is_Volatile
(Designated_Type
(Typ
))
11920 ("access to volatile object cannot yield access-to-" &
11921 "non-volatile type", P
);
11923 elsif Is_Volatile_Full_Access_Object_Ref
(P
)
11924 and then not Is_Volatile_Full_Access
(Designated_Type
(Typ
))
11927 ("access to full access object cannot yield access-to-" &
11928 "non-full-access type", P
);
11931 -- Check for nonatomic subcomponent of a full access object
11932 -- in Ada 2022 (RM C.6 (12)).
11934 if Ada_Version
>= Ada_2022
11935 and then Is_Subcomponent_Of_Full_Access_Object
(P
)
11936 and then not Is_Atomic_Object
(P
)
11939 ("cannot have access attribute with prefix &", N
, P
);
11941 ("\nonatomic subcomponent of full access object "
11942 & "(RM C.6(12))", N
);
11946 -- Check for aliased view. We allow a nonaliased prefix when in
11947 -- an instance because the prefix may have been a tagged formal
11948 -- object, which is defined to be aliased even when the actual
11949 -- might not be (other instance cases will have been caught in
11950 -- the generic). Similarly, within an inlined body we know that
11951 -- the attribute is legal in the original subprogram, therefore
11952 -- legal in the expansion.
11954 if not (Is_Entity_Name
(P
)
11955 and then Is_Overloadable
(Entity
(P
)))
11956 and then not (Nkind
(P
) = N_Selected_Component
11958 Is_Overloadable
(Entity
(Selector_Name
(P
))))
11959 and then not Is_Aliased_View
(Original_Node
(P
))
11960 and then not In_Instance
11961 and then not In_Inlined_Body
11962 and then Comes_From_Source
(N
)
11964 -- Here we have a non-aliased view. This is illegal unless we
11965 -- have the case of Unrestricted_Access, where for now we allow
11966 -- this (we will reject later if expected type is access to an
11967 -- unconstrained array with a thin pointer).
11969 -- No need for an error message on a generated access reference
11970 -- for the controlling argument in a dispatching call: error
11971 -- will be reported when resolving the call.
11973 if Attr_Id
/= Attribute_Unrestricted_Access
then
11974 Error_Msg_Name_1
:= Aname
;
11975 Error_Msg_N
("prefix of % attribute must be aliased", P
);
11977 -- Check for unrestricted access where expected type is a thin
11978 -- pointer to an unconstrained array.
11980 elsif Is_Thin_Pointer_To_Unc_Array
(Typ
) then
11982 ("illegal use of Unrestricted_Access attribute", P
);
11984 ("\attempt to generate thin pointer to unaliased "
11989 -- Check that the prefix does not have a value conversion of an
11990 -- array type since a value conversion is like an aggregate with
11991 -- respect to determining accessibility level (RM 3.10.2).
11993 if not Prefix_With_Safe_Accessibility_Level
(N
, Typ
) then
11994 Accessibility_Message
(N
, Typ
);
11998 -- Mark that address of entity is taken in case of
11999 -- 'Unrestricted_Access or in case of a subprogram.
12001 if Is_Entity_Name
(P
)
12002 and then (Attr_Id
= Attribute_Unrestricted_Access
12003 or else Is_Subprogram
(Entity
(P
)))
12005 Set_Address_Taken
(Entity
(P
));
12008 -- Deal with possible elaboration check
12010 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
12012 Subp_Id
: constant Entity_Id
:= Entity
(P
);
12013 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
12014 Subp_Decl
: constant Node_Id
:=
12015 Unit_Declaration_Node
(Subp_Id
);
12016 Flag_Id
: Entity_Id
;
12017 Subp_Body
: Node_Id
;
12019 -- If the access has been taken and the body of the subprogram
12020 -- has not been see yet, indirect calls must be protected with
12021 -- elaboration checks. We have the proper elaboration machinery
12022 -- for subprograms declared in packages, but within a block or
12023 -- a subprogram the body will appear in the same declarative
12024 -- part, and we must insert a check in the eventual body itself
12025 -- using the elaboration flag that we generate now. The check
12026 -- is then inserted when the body is expanded. This processing
12027 -- is not needed for a stand alone expression function because
12028 -- the internally generated spec and body are always inserted
12029 -- as a pair in the same declarative list.
12033 and then Comes_From_Source
(Subp_Id
)
12034 and then Comes_From_Source
(N
)
12035 and then In_Open_Scopes
(Scop
)
12036 and then Ekind
(Scop
) in E_Block | E_Procedure | E_Function
12037 and then not Has_Completion
(Subp_Id
)
12038 and then No
(Elaboration_Entity
(Subp_Id
))
12039 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12040 and then Nkind
(Original_Node
(Subp_Decl
)) /=
12041 N_Expression_Function
12043 -- Create elaboration variable for it
12045 Flag_Id
:= Make_Temporary
(Loc
, 'E');
12046 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
12047 Set_Is_Frozen
(Flag_Id
);
12049 -- Insert declaration for flag after subprogram
12050 -- declaration. Note that attribute reference may
12051 -- appear within a nested scope.
12053 Insert_After_And_Analyze
(Subp_Decl
,
12054 Make_Object_Declaration
(Loc
,
12055 Defining_Identifier
=> Flag_Id
,
12056 Object_Definition
=>
12057 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
12059 Make_Integer_Literal
(Loc
, Uint_0
)));
12061 -- The above sets the Scope of the flag entity to the
12062 -- current scope, in which the attribute appears, but
12063 -- the flag declaration has been inserted after that
12064 -- of Subp_Id, so the scope of the flag is the same as
12065 -- that of Subp_Id. This is relevant when unnesting,
12066 -- where processing depends on correct scope setting.
12068 Set_Scope
(Flag_Id
, Scop
);
12071 -- Taking the 'Access of an expression function freezes its
12072 -- expression (RM 13.14 10.3/3). This does not apply to an
12073 -- expression function that acts as a completion because the
12074 -- generated body is immediately analyzed and the expression
12075 -- is automatically frozen.
12077 if Is_Expression_Function
(Subp_Id
)
12078 and then Present
(Corresponding_Body
(Subp_Decl
))
12081 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
12083 -- The body has already been analyzed when the expression
12084 -- function acts as a completion.
12086 if Analyzed
(Subp_Body
) then
12089 -- Attribute 'Access may appear within the generated body
12090 -- of the expression function subject to the attribute:
12092 -- function F is (... F'Access ...);
12094 -- If the expression function is on the scope stack, then
12095 -- the body is currently being analyzed. Do not reanalyze
12096 -- it because this will lead to infinite recursion.
12098 elsif In_Open_Scopes
(Subp_Id
) then
12101 -- If reference to the expression function appears in an
12102 -- inner scope, for example as an actual in an instance,
12103 -- this is not a freeze point either.
12105 elsif Scope
(Subp_Id
) /= Current_Scope
then
12108 -- Dispatch tables are not a freeze point either
12110 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
12111 and then Is_Dispatch_Table_Entity
(Etype
(Parent
(N
)))
12115 -- Analyze the body of the expression function to freeze
12119 Analyze
(Subp_Body
);
12129 -- Deal with resolving the type for Address attribute, overloading
12130 -- is not permitted here, since there is no context to resolve it.
12132 when Attribute_Address
12133 | Attribute_Code_Address
12135 -- To be safe, assume that if the address of a variable is taken,
12136 -- it may be modified via this address, so note modification.
12138 if Is_Variable
(P
) then
12139 Note_Possible_Modification
(P
, Sure
=> False);
12142 if Nkind
(P
) in N_Subexpr
and then Is_Overloaded
(P
) then
12143 Get_First_Interp
(P
, Index
, It
);
12144 Get_Next_Interp
(Index
, It
);
12146 if Present
(It
.Nam
) then
12147 Error_Msg_Name_1
:= Aname
;
12149 ("prefix of % attribute cannot be overloaded", P
);
12153 if not Is_Entity_Name
(P
)
12154 or else not Is_Overloadable
(Entity
(P
))
12159 -- If this is the name of a derived subprogram, or that of a
12160 -- generic actual, the address is that of the original entity.
12162 if Is_Entity_Name
(P
)
12163 and then Is_Overloadable
(Entity
(P
))
12164 and then Present
(Alias
(Entity
(P
)))
12167 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
12170 if Is_Entity_Name
(P
) then
12171 Set_Address_Taken
(Entity
(P
));
12174 if Nkind
(P
) = N_Slice
then
12176 -- Arr (X .. Y)'address is identical to Arr (X)'address,
12177 -- even if the array is packed and the slice itself is not
12178 -- addressable. Transform the prefix into an indexed component.
12180 -- Note that the transformation is safe only if we know that
12181 -- the slice is non-null. That is because a null slice can have
12182 -- an out of bounds index value.
12184 -- Right now, gigi blows up if given 'Address on a slice as a
12185 -- result of some incorrect freeze nodes generated by the front
12186 -- end, and this covers up that bug in one case, but the bug is
12187 -- likely still there in the cases not handled by this code ???
12189 -- It's not clear what 'Address *should* return for a null
12190 -- slice with out of bounds indexes, this might be worth an ARG
12193 -- One approach would be to do a length check unconditionally,
12194 -- and then do the transformation below unconditionally, but
12195 -- analyze with checks off, avoiding the problem of the out of
12196 -- bounds index. This approach would interpret the address of
12197 -- an out of bounds null slice as being the address where the
12198 -- array element would be if there was one, which is probably
12199 -- as reasonable an interpretation as any ???
12202 Loc
: constant Source_Ptr
:= Sloc
(P
);
12203 D
: constant Node_Id
:= Discrete_Range
(P
);
12207 if Is_Entity_Name
(D
)
12210 (Type_Low_Bound
(Entity
(D
)),
12211 Type_High_Bound
(Entity
(D
)))
12214 Make_Attribute_Reference
(Loc
,
12215 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
12216 Attribute_Name
=> Name_First
);
12218 elsif Nkind
(D
) = N_Range
12219 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
12221 Lo
:= Low_Bound
(D
);
12227 if Present
(Lo
) then
12229 Make_Indexed_Component
(Loc
,
12230 Prefix
=> Relocate_Node
(Prefix
(P
)),
12231 Expressions
=> New_List
(Lo
)));
12233 Analyze_And_Resolve
(P
);
12242 -- Prefix of Body_Version attribute can be a subprogram name which
12243 -- must not be resolved, since this is not a call.
12245 when Attribute_Body_Version
=>
12252 -- Prefix of Caller attribute is an entry name which must not
12253 -- be resolved, since this is definitely not an entry call.
12255 when Attribute_Caller
=>
12262 -- Shares processing with Address attribute
12268 -- If the prefix of the Count attribute is an entry name it must not
12269 -- be resolved, since this is definitely not an entry call. However,
12270 -- if it is an element of an entry family, the index itself may
12271 -- have to be resolved because it can be a general expression.
12273 when Attribute_Count
12276 if Nkind
(P
) = N_Indexed_Component
12277 and then Is_Entity_Name
(Prefix
(P
))
12280 Indx
: constant Node_Id
:= First
(Expressions
(P
));
12281 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
12283 Resolve
(Indx
, Entry_Index_Type
(Fam
));
12284 Apply_Scalar_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
12292 -- Prefix of the Elaborated attribute is a subprogram name which
12293 -- must not be resolved, since this is definitely not a call. Note
12294 -- that it is a library unit, so it cannot be overloaded here.
12296 when Attribute_Elaborated
=>
12303 -- Prefix of Enabled attribute is a check name, which must be treated
12304 -- specially and not touched by Resolve.
12306 when Attribute_Enabled
=>
12313 -- Processing is shared with Count
12319 -- Do not resolve the prefix of Loop_Entry, instead wait until the
12320 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
12321 -- The delay ensures that any generated checks or temporaries are
12322 -- inserted before the relocated prefix.
12324 when Attribute_Loop_Entry
=>
12327 --------------------
12328 -- Mechanism_Code --
12329 --------------------
12331 -- Prefix of the Mechanism_Code attribute is a function name
12332 -- which must not be resolved. Should we check for overloaded ???
12334 when Attribute_Mechanism_Code
=>
12341 -- Most processing is done in sem_dist, after determining the
12342 -- context type. Node is rewritten as a conversion to a runtime call.
12344 when Attribute_Partition_ID
=>
12345 Process_Partition_Id
(N
);
12352 when Attribute_Pool_Address
=>
12359 -- We replace the Range attribute node with a range expression whose
12360 -- bounds are the 'First and 'Last attributes applied to the same
12361 -- prefix. The reason that we do this transformation here instead of
12362 -- in the expander is that it simplifies other parts of the semantic
12363 -- analysis which assume that the Range has been replaced; thus it
12364 -- must be done even when in semantic-only mode (note that the RM
12365 -- specifically mentions this equivalence, we take care that the
12366 -- prefix is only evaluated once).
12368 when Attribute_Range
=> Range_Attribute
: declare
12374 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12377 -- If the prefix is a function call returning on the secondary
12378 -- stack, we must make sure to mark/release the stack.
12380 if Nkind
(P
) = N_Function_Call
12381 and then Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
12382 and then Requires_Transient_Scope
(Etype
(P
))
12384 Set_Uses_Sec_Stack
(Scope
(Current_Scope
));
12388 Dims
:= Expressions
(N
);
12391 Make_Attribute_Reference
(Loc
,
12392 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
12393 Attribute_Name
=> Name_Last
,
12394 Expressions
=> Dims
);
12397 Make_Attribute_Reference
(Loc
,
12399 Attribute_Name
=> Name_First
,
12400 Expressions
=> (Dims
));
12402 -- Do not share the dimension indicator, if present. Even though
12403 -- it is a static constant, its source location may be modified
12404 -- when printing expanded code and node sharing will lead to chaos
12407 if Present
(Dims
) then
12408 Set_Expressions
(LB
, New_List
(New_Copy_Tree
(First
(Dims
))));
12411 -- If the original was marked as Must_Not_Freeze (see code in
12412 -- Sem_Ch3.Make_Index), then make sure the rewriting does not
12415 if Must_Not_Freeze
(N
) then
12416 Set_Must_Not_Freeze
(HB
);
12417 Set_Must_Not_Freeze
(LB
);
12418 Set_Must_Not_Freeze
(Prefix
(HB
));
12419 Set_Must_Not_Freeze
(Prefix
(LB
));
12422 if Raises_Constraint_Error
(Prefix
(N
)) then
12424 -- Preserve Sloc of prefix in the new bounds, so that the
12425 -- posted warning can be removed if we are within unreachable
12428 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
12429 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
12432 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
12433 Analyze_And_Resolve
(N
, Typ
);
12435 -- Ensure that the expanded range does not have side effects
12437 Force_Evaluation
(LB
);
12438 Force_Evaluation
(HB
);
12440 -- Normally after resolving attribute nodes, Eval_Attribute
12441 -- is called to do any possible static evaluation of the node.
12442 -- However, here since the Range attribute has just been
12443 -- transformed into a range expression it is no longer an
12444 -- attribute node and therefore the call needs to be avoided
12445 -- and is accomplished by simply returning from the procedure.
12448 end Range_Attribute
;
12454 when Attribute_Reduce
=>
12456 E1
: constant Node_Id
:= First
(Expressions
(N
));
12457 E2
: constant Node_Id
:= Next
(E1
);
12458 Op
: Entity_Id
:= Empty
;
12460 Index
: Interp_Index
;
12462 function Proper_Op
(Op
: Entity_Id
) return Boolean;
12468 function Proper_Op
(Op
: Entity_Id
) return Boolean is
12469 F1
, F2
: Entity_Id
;
12472 F1
:= First_Formal
(Op
);
12476 F2
:= Next_Formal
(F1
);
12478 or else Present
(Next_Formal
(F2
))
12482 elsif Ekind
(Op
) = E_Procedure
then
12483 return Ekind
(F1
) = E_In_Out_Parameter
12484 and then Covers
(Typ
, Etype
(F1
));
12488 (Ekind
(Op
) = E_Operator
12489 and then Scope
(Op
) = Standard_Standard
)
12490 or else Covers
(Typ
, Etype
(Op
));
12497 if Is_Overloaded
(E1
) then
12498 Get_First_Interp
(E1
, Index
, It
);
12499 while Present
(It
.Nam
) loop
12500 if Proper_Op
(It
.Nam
) then
12502 Set_Entity
(E1
, Op
);
12506 Get_Next_Interp
(Index
, It
);
12509 elsif Nkind
(E1
) = N_Attribute_Reference
12510 and then (Attribute_Name
(E1
) = Name_Max
12511 or else Attribute_Name
(E1
) = Name_Min
)
12515 elsif Proper_Op
(Entity
(E1
)) then
12517 Set_Etype
(N
, Typ
);
12521 Error_Msg_N
("No visible subprogram for reduction", E1
);
12529 -- We will only come here during the prescan of a spec expression
12530 -- containing a Result attribute. In that case the proper Etype has
12531 -- already been set, and nothing more needs to be done here.
12533 when Attribute_Result
=>
12536 ----------------------
12537 -- Unchecked_Access --
12538 ----------------------
12540 -- Processing is shared with Access
12542 -------------------------
12543 -- Unrestricted_Access --
12544 -------------------------
12546 -- Processing is shared with Access
12552 -- Resolve aggregate components in component associations
12554 when Attribute_Update
=> Update
: declare
12555 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
12556 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
12562 -- Set the Etype of the aggregate to that of the prefix, even
12563 -- though the aggregate may not be a proper representation of a
12564 -- value of the type (missing or duplicated associations, etc.)
12565 -- Complete resolution of the prefix. Note that in Ada 2012 it
12566 -- can be a qualified expression that is e.g. an aggregate.
12568 Set_Etype
(Aggr
, Typ
);
12569 Resolve
(Prefix
(N
), Typ
);
12571 -- For an array type, resolve expressions with the component type
12572 -- of the array, and apply constraint checks when needed.
12574 if Is_Array_Type
(Typ
) then
12575 Assoc
:= First
(Component_Associations
(Aggr
));
12576 while Present
(Assoc
) loop
12577 Expr
:= Expression
(Assoc
);
12578 Resolve
(Expr
, Component_Type
(Typ
));
12580 -- The choices in the association are static constants,
12581 -- or static aggregates each of whose components belongs
12582 -- to the proper index type. However, they must also
12583 -- belong to the index subtype (s) of the prefix, which
12584 -- may be a subtype (e.g. given by a slice).
12586 -- Choices may also be identifiers with no staticness
12587 -- requirements, in which case they must resolve to the
12596 C
:= First
(Choices
(Assoc
));
12597 while Present
(C
) loop
12598 Indx
:= First_Index
(Etype
(Prefix
(N
)));
12600 if Nkind
(C
) /= N_Aggregate
then
12601 Analyze_And_Resolve
(C
, Etype
(Indx
));
12603 C_E
:= First
(Expressions
(C
));
12604 while Present
(C_E
) loop
12605 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
12619 -- For a record type, use type of each component, which is
12620 -- recorded during analysis.
12623 Assoc
:= First
(Component_Associations
(Aggr
));
12624 while Present
(Assoc
) loop
12625 Comp
:= First
(Choices
(Assoc
));
12626 Expr
:= Expression
(Assoc
);
12628 if Nkind
(Comp
) /= N_Others_Choice
12629 and then not Error_Posted
(Comp
)
12631 Resolve
(Expr
, Etype
(Entity
(Comp
)));
12643 -- Apply range check. Note that we did not do this during the
12644 -- analysis phase, since we wanted Eval_Attribute to have a
12645 -- chance at finding an illegal out of range value.
12647 when Attribute_Val
=>
12649 -- Note that we do our own Eval_Attribute call here rather than
12650 -- use the common one, because we need to do processing after
12651 -- the call, as per above comment.
12653 Eval_Attribute
(N
);
12655 -- Eval_Attribute may replace the node with a raise CE, or
12656 -- fold it to a constant. Obviously we only apply a scalar
12657 -- range check if this did not happen.
12659 if Nkind
(N
) = N_Attribute_Reference
12660 and then Attribute_Name
(N
) = Name_Val
12662 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
12671 -- Prefix of Version attribute can be a subprogram name which
12672 -- must not be resolved, since this is not a call.
12674 when Attribute_Version
=>
12677 ----------------------
12678 -- Other Attributes --
12679 ----------------------
12681 -- For other attributes, resolve prefix unless it is a type. If
12682 -- the attribute reference itself is a type name ('Base and 'Class)
12683 -- then this is only legal within a task or protected record.
12686 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12690 -- If the attribute reference itself is a type name ('Base,
12691 -- 'Class) then this is only legal within a task or protected
12692 -- record. What is this all about ???
12694 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
12695 if Is_Concurrent_Type
(Entity
(N
))
12696 and then In_Open_Scopes
(Entity
(P
))
12701 ("invalid use of subtype name in expression or call", N
);
12705 -- For attributes whose argument may be a string, complete
12706 -- resolution of argument now. This avoids premature expansion
12707 -- (and the creation of transient scopes) before the attribute
12708 -- reference is resolved.
12711 when Attribute_Valid_Value | Attribute_Value
=>
12712 Resolve
(First
(Expressions
(N
)), Standard_String
);
12714 when Attribute_Wide_Value
=>
12715 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
12717 when Attribute_Wide_Wide_Value
=>
12718 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
12720 when others => null;
12723 -- Ensure that attribute expressions are resolved at this stage;
12724 -- required for preanalyzed references to discriminants since
12725 -- their resolution (and expansion) will take care of updating
12726 -- their Entity attribute to reference their discriminal.
12729 and then Present
(Expressions
(N
))
12732 Expr
: Node_Id
:= First
(Expressions
(N
));
12735 while Present
(Expr
) loop
12736 if not Analyzed
(Expr
) then
12737 Resolve
(Expr
, Etype
(Expr
));
12745 -- If the prefix of the attribute is a class-wide type then it
12746 -- will be expanded into a dispatching call to a predefined
12747 -- primitive. Therefore we must check for potential violation
12748 -- of such restriction.
12750 if Is_Class_Wide_Type
(Etype
(P
)) then
12751 Check_Restriction
(No_Dispatching_Calls
, N
);
12755 -- Mark use clauses of the original prefix if the attribute is applied
12758 if Nkind
(Original_Node
(P
)) in N_Has_Entity
12759 and then Present
(Entity
(Original_Node
(P
)))
12761 Mark_Use_Clauses
(Original_Node
(P
));
12764 -- Normally the Freezing is done by Resolve but sometimes the Prefix
12765 -- is not resolved, in which case the freezing must be done now.
12767 -- For an elaboration check on a subprogram, we do not freeze its type.
12768 -- It may be declared in an unrelated scope, in particular in the case
12769 -- of a generic function whose type may remain unelaborated.
12771 if Attr_Id
= Attribute_Elaborated
then
12774 -- Should this be restricted to Expander_Active???
12777 Freeze_Expression
(P
);
12780 -- Finally perform static evaluation on the attribute reference
12782 Analyze_Dimension
(N
);
12783 Eval_Attribute
(N
);
12784 end Resolve_Attribute
;
12786 ------------------------
12787 -- Set_Boolean_Result --
12788 ------------------------
12790 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
12792 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(B
), Sloc
(N
)));
12793 end Set_Boolean_Result
;
12795 --------------------------------
12796 -- Stream_Attribute_Available --
12797 --------------------------------
12799 function Stream_Attribute_Available
12801 Nam
: TSS_Name_Type
;
12802 Partial_View
: Entity_Id
:= Empty
) return Boolean
12804 Etyp
: Entity_Id
:= Typ
;
12806 Real_Rep
: Node_Id
;
12808 -- Start of processing for Stream_Attribute_Available
12811 -- Test if the attribute is specified directly on the type
12813 if Has_Stream_Attribute_Definition
(Typ
, Nam
, Real_Rep
) then
12817 -- We assume class-wide types have stream attributes
12818 -- when they are not limited. Otherwise we recurse on the
12821 if Is_Class_Wide_Type
(Typ
) then
12822 return not Is_Limited_Type
(Typ
)
12823 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
12826 -- Non-class-wide abstract types cannot have Input streams
12829 if Nam
= TSS_Stream_Input
12830 and then Is_Abstract_Type
(Typ
)
12831 and then not Is_Class_Wide_Type
(Typ
)
12836 -- Otherwise, nonlimited types have stream attributes
12838 if not (Is_Limited_Type
(Typ
)
12839 or else (Present
(Partial_View
)
12840 and then Is_Limited_Type
(Partial_View
)))
12845 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
12847 if Nam
= TSS_Stream_Input
12848 and then Ada_Version
>= Ada_2005
12849 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
, Real_Rep
)
12853 elsif Nam
= TSS_Stream_Output
12854 and then Ada_Version
>= Ada_2005
12855 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
, Real_Rep
)
12860 -- Case of Read and Write: check for attribute definition clause that
12861 -- applies to an ancestor type.
12863 while Etype
(Etyp
) /= Etyp
loop
12865 Derived_Type
: constant Entity_Id
:= Etyp
;
12867 Etyp
:= Etype
(Etyp
);
12869 if Has_Stream_Attribute_Definition
(Etyp
, Nam
, Real_Rep
) then
12870 if not Derivation_Too_Early_To_Inherit
(Derived_Type
, Nam
) then
12877 if Ada_Version
< Ada_2005
then
12879 -- In Ada 95 mode, also consider a non-visible definition
12882 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
12885 and then Stream_Attribute_Available
12886 (Btyp
, Nam
, Partial_View
=> Typ
);
12891 end Stream_Attribute_Available
;