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 Gnatvsn
; use Gnatvsn
;
45 with Itypes
; use Itypes
;
47 with Lib
.Xref
; use Lib
.Xref
;
48 with Nlists
; use Nlists
;
49 with Nmake
; use Nmake
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
56 with Sem_Aggr
; use Sem_Aggr
;
57 with Sem_Aux
; use Sem_Aux
;
58 with Sem_Cat
; use Sem_Cat
;
59 with Sem_Ch6
; use Sem_Ch6
;
60 with Sem_Ch8
; use Sem_Ch8
;
61 with Sem_Ch10
; use Sem_Ch10
;
62 with Sem_Dim
; use Sem_Dim
;
63 with Sem_Dist
; use Sem_Dist
;
64 with Sem_Elab
; use Sem_Elab
;
65 with Sem_Elim
; use Sem_Elim
;
66 with Sem_Eval
; use Sem_Eval
;
67 with Sem_Prag
; use Sem_Prag
;
68 with Sem_Res
; use Sem_Res
;
69 with Sem_Type
; use Sem_Type
;
70 with Sem_Util
; use Sem_Util
;
72 with Stand
; use Stand
;
73 with Sinfo
; use Sinfo
;
74 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
75 with Sinfo
.Utils
; use Sinfo
.Utils
;
76 with Sinput
; use Sinput
;
78 with Stringt
; use Stringt
;
79 with Strub
; use Strub
;
81 with Stylesw
; use Stylesw
;
82 with Targparm
; use Targparm
;
83 with Ttypes
; use Ttypes
;
84 with Tbuild
; use Tbuild
;
85 with Uintp
; use Uintp
;
86 with Uname
; use Uname
;
87 with Urealp
; use Urealp
;
88 with Warnsw
; use Warnsw
;
90 with System
.CRC32
; use System
.CRC32
;
92 package body Sem_Attr
is
94 True_Value
: constant Uint
:= Uint_1
;
95 False_Value
: constant Uint
:= Uint_0
;
96 -- Synonyms to be used when these constants are used as Boolean values
98 Bad_Attribute
: exception;
99 -- Exception raised if an error is detected during attribute processing,
100 -- used so that we can abandon the processing so we don't run into
101 -- trouble with cascaded errors.
103 -- The following array is the list of attributes defined in the Ada 83 RM.
104 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
105 -- modes all these attributes are recognized, even if removed in Ada 95.
107 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
110 Attribute_Alignment |
113 Attribute_Constrained |
120 Attribute_First_Bit |
126 Attribute_Leading_Part |
128 Attribute_Machine_Emax |
129 Attribute_Machine_Emin |
130 Attribute_Machine_Mantissa |
131 Attribute_Machine_Overflows |
132 Attribute_Machine_Radix |
133 Attribute_Machine_Rounds |
139 Attribute_Safe_Emax |
140 Attribute_Safe_Large |
141 Attribute_Safe_Small |
144 Attribute_Storage_Size |
146 Attribute_Terminated |
149 Attribute_Width => True,
152 -- The following array is the list of attributes defined in the Ada 2005
153 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
154 -- but in Ada 95 they are considered to be implementation defined.
156 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
157 Attribute_Machine_Rounding |
160 Attribute_Stream_Size |
161 Attribute_Wide_Wide_Width
=> True,
164 -- The following array is the list of attributes defined in the Ada 2012
165 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
166 -- and Ada 2005 modes, but are considered to be implementation defined.
168 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
169 Attribute_First_Valid |
170 Attribute_Has_Same_Storage |
171 Attribute_Last_Valid |
172 Attribute_Max_Alignment_For_Allocation => True,
175 -- The following array is the list of attributes defined in the Ada 2022
176 -- RM which are not defined in Ada 2012. These are recognized in Ada
177 -- 95/2005/2012 modes, but are considered to be implementation defined.
179 Attribute_22 : constant Attribute_Class_Array := Attribute_Class_Array'(
181 Attribute_Enum_Val
=> True,
182 Attribute_Index
=> True,
183 Attribute_Preelaborable_Initialization
=> True,
186 -- The following array contains all attributes that imply a modification
187 -- of their prefixes or result in an access value. Such prefixes can be
188 -- considered as lvalues.
190 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
191 Attribute_Class_Array
'(
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 a task type, this test needs sharpening up ???
1073 elsif Is_Task_Type
(Typ
) then
1076 -- OK if self-reference in an aggregate in Ada 2005, and
1077 -- the reference comes from a copied default expression.
1079 -- Note that we check legality of self-reference even if the
1080 -- expression comes from source, e.g. when a single component
1081 -- association in an aggregate has a box association.
1083 elsif Ada_Version
>= Ada_2005
and then OK_Self_Reference
then
1086 -- OK if reference to current instance of a protected object
1088 elsif Is_Protected_Self_Reference
(P
) then
1091 -- Otherwise we have an error case
1094 Error_Attr
("% attribute cannot be applied to type", P
);
1099 -- If we fall through, we have a normal access to object case
1101 -- Unrestricted_Access is (for now) legal wherever an allocator would
1102 -- be legal, so its Etype is set to E_Allocator. The expected type
1103 -- of the other attributes is a general access type, and therefore
1104 -- we label them with E_Access_Attribute_Type.
1106 if not Is_Overloaded
(P
) then
1107 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
1108 Set_Etype
(N
, Acc_Type
);
1112 Index
: Interp_Index
;
1115 Set_Etype
(N
, Any_Type
);
1116 Get_First_Interp
(P
, Index
, It
);
1117 while Present
(It
.Typ
) loop
1118 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1119 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1120 Get_Next_Interp
(Index
, It
);
1125 -- Special cases when we can find a prefix that is an entity name
1134 if Is_Entity_Name
(PP
) then
1137 -- If we have an access to an object, and the attribute
1138 -- comes from source, then set the object as potentially
1139 -- source modified. We do this because the resulting access
1140 -- pointer can be used to modify the variable, and we might
1141 -- not detect this, leading to some junk warnings.
1143 -- We do this only for source references, since otherwise
1144 -- we can suppress warnings, e.g. from the unrestricted
1145 -- access generated for validity checks in -gnatVa mode.
1147 if Comes_From_Source
(N
) then
1148 Set_Never_Set_In_Source
(Ent
, False);
1151 -- Mark entity as address taken in the case of
1152 -- 'Unrestricted_Access or subprograms, and kill current
1155 if Aname
= Name_Unrestricted_Access
1156 or else Is_Subprogram
(Ent
)
1158 Set_Address_Taken
(Ent
);
1161 Kill_Current_Values
(Ent
);
1164 elsif Nkind
(PP
) in N_Selected_Component | N_Indexed_Component
1173 end Analyze_Access_Attribute
;
1175 ----------------------------------
1176 -- Analyze_Attribute_Old_Result --
1177 ----------------------------------
1179 procedure Analyze_Attribute_Old_Result
1180 (Legal
: out Boolean;
1181 Spec_Id
: out Entity_Id
)
1183 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1184 -- Verify that the attribute appears within pragma Check that mimics
1187 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1188 -- Verify that the attribute appears within a consequence of aspect
1189 -- or pragma Contract_Cases denoted by Prag.
1191 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1192 -- Verify that the attribute appears within the "Ensures" argument of
1193 -- aspect or pragma Test_Case denoted by Prag.
1197 Encl_Nod
: Node_Id
) return Boolean;
1198 -- Subsidiary to Check_Placement_In_XXX. Determine whether arbitrary
1199 -- node Nod is within enclosing node Encl_Nod.
1201 procedure Placement_Error
;
1202 pragma No_Return
(Placement_Error
);
1203 -- Emit a general error when the attributes does not appear in a
1204 -- postcondition-like aspect or pragma, and then raises Bad_Attribute
1205 -- to avoid any further semantic processing.
1207 ------------------------------
1208 -- Check_Placement_In_Check --
1209 ------------------------------
1211 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1212 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1213 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1216 -- The "Name" argument of pragma Check denotes a postcondition
1220 | Name_Postcondition
1225 -- Otherwise the placement of the attribute is illegal
1230 end Check_Placement_In_Check
;
1232 ---------------------------------------
1233 -- Check_Placement_In_Contract_Cases --
1234 ---------------------------------------
1236 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1242 -- Obtain the argument of the aspect or pragma
1244 if Nkind
(Prag
) = N_Aspect_Specification
then
1247 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1250 Cases
:= Expression
(Arg
);
1252 if Present
(Component_Associations
(Cases
)) then
1253 CCase
:= First
(Component_Associations
(Cases
));
1254 while Present
(CCase
) loop
1256 -- Detect whether the attribute appears within the
1257 -- consequence of the current contract case.
1259 if Nkind
(CCase
) = N_Component_Association
1260 and then Is_Within
(N
, Expression
(CCase
))
1269 -- Otherwise aspect or pragma Contract_Cases is either malformed
1270 -- or the attribute does not appear within a consequence.
1273 ("attribute % must appear in the consequence of a contract case",
1275 end Check_Placement_In_Contract_Cases
;
1277 ----------------------------------
1278 -- Check_Placement_In_Test_Case --
1279 ----------------------------------
1281 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1282 Arg
: constant Node_Id
:=
1285 Arg_Nam
=> Name_Ensures
,
1286 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1289 -- Detect whether the attribute appears within the "Ensures"
1290 -- expression of aspect or pragma Test_Case.
1292 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1297 ("attribute % must appear in the ensures expression of a "
1300 end Check_Placement_In_Test_Case
;
1308 Encl_Nod
: Node_Id
) return Boolean
1314 while Present
(Par
) loop
1315 if Par
= Encl_Nod
then
1318 -- Prevent the search from going too far
1320 elsif Is_Body_Or_Package_Declaration
(Par
) then
1324 Par
:= Parent
(Par
);
1330 ---------------------
1331 -- Placement_Error --
1332 ---------------------
1334 procedure Placement_Error
is
1336 if Aname
= Name_Old
then
1337 Error_Attr
("attribute % can only appear in postcondition", P
);
1339 -- Specialize the error message for attribute 'Result
1343 ("attribute % can only appear in postcondition of function",
1346 end Placement_Error
;
1352 Subp_Decl
: Node_Id
;
1354 -- Start of processing for Analyze_Attribute_Old_Result
1357 -- Assume that the attribute is illegal
1362 -- Skip processing during preanalysis of class-wide preconditions and
1363 -- postconditions since at this stage the expression is not installed
1364 -- yet on its definite context.
1366 if Inside_Class_Condition_Preanalysis
then
1368 Spec_Id
:= Current_Scope
;
1372 -- Traverse the parent chain to find the aspect or pragma where the
1373 -- attribute resides.
1376 while Present
(Prag
) loop
1377 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1380 -- Prevent the search from going too far
1382 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1386 Prag
:= Parent
(Prag
);
1389 -- The attribute is allowed to appear only in postcondition-like
1390 -- aspects or pragmas.
1392 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1393 if Nkind
(Prag
) = N_Aspect_Specification
then
1394 Prag_Nam
:= Chars
(Identifier
(Prag
));
1396 Prag_Nam
:= Pragma_Name
(Prag
);
1399 if Prag_Nam
= Name_Check
then
1400 Check_Placement_In_Check
(Prag
);
1402 elsif Prag_Nam
= Name_Contract_Cases
then
1403 Check_Placement_In_Contract_Cases
(Prag
);
1405 -- Attribute 'Result is allowed to appear in aspect or pragma
1406 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1408 elsif Prag_Nam
in Name_Depends | Name_Refined_Depends
1409 and then Aname
= Name_Result
1413 -- Attribute 'Result is allowed to appear in aspect
1414 -- Relaxed_Initialization (SPARK RM 6.10).
1416 elsif Prag_Nam
= Name_Relaxed_Initialization
1417 and then Aname
= Name_Result
1421 elsif Prag_Nam
in Name_Post
1423 | Name_Postcondition
1428 elsif Prag_Nam
= Name_Test_Case
then
1429 Check_Placement_In_Test_Case
(Prag
);
1435 -- 'Old attribute reference ok in a _Wrapped_Statements procedure
1437 elsif Nkind
(Prag
) = N_Subprogram_Body
1438 and then Ekind
(Defining_Entity
(Prag
)) in Subprogram_Kind
1439 and then Present
(Wrapped_Statements
(Defining_Entity
(Prag
)))
1443 -- Otherwise the placement of the attribute is illegal
1449 -- Find the related subprogram subject to the aspect or pragma
1451 if Nkind
(Prag
) = N_Aspect_Specification
then
1452 Subp_Decl
:= Parent
(Prag
);
1453 elsif Nkind
(Prag
) = N_Subprogram_Body
then
1456 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1459 -- 'Old objects appear in block and extended return statements as
1460 -- part of the expansion of contract wrappers.
1462 if Nkind
(Subp_Decl
) in N_Block_Statement
1463 | N_Extended_Return_Statement
1465 Subp_Decl
:= Parent
(Parent
(Subp_Decl
));
1468 -- The aspect or pragma where the attribute resides should be
1469 -- associated with a subprogram declaration or a body. If this is not
1470 -- the case, then the aspect or pragma is illegal. Return as analysis
1471 -- cannot be carried out. Note that it is legal to have the aspect
1472 -- appear on a subprogram renaming, when the renamed entity is an
1473 -- attribute reference.
1475 -- Generating C code the internally built nested _postcondition
1476 -- subprograms are inlined; after expanded, inlined aspects are
1477 -- located in the internal block generated by the frontend.
1479 if Nkind
(Subp_Decl
) = N_Block_Statement
1480 and then Modify_Tree_For_C
1481 and then In_Inlined_Body
1485 elsif Nkind
(Subp_Decl
) not in N_Abstract_Subprogram_Declaration
1486 | N_Entry_Declaration
1487 | N_Expression_Function
1488 | N_Generic_Subprogram_Declaration
1490 | N_Subprogram_Body_Stub
1491 | N_Subprogram_Declaration
1492 | N_Subprogram_Renaming_Declaration
1497 -- If we get here, then the attribute is legal
1500 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1502 -- When generating C code, nested _postcondition subprograms are
1503 -- inlined by the front end to avoid problems (when unnested) with
1504 -- referenced itypes. Handle that here, since as part of inlining the
1505 -- expander nests subprogram within a dummy procedure named _parent
1506 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1507 -- Hence, in this context, the spec_id of _postconditions is the
1510 if Modify_Tree_For_C
1511 and then Chars
(Spec_Id
) = Name_uParent
1512 and then Chars
(Scope
(Spec_Id
)) = Name_uWrapped_Statements
1514 -- This situation occurs only when analyzing the body-to-inline
1516 pragma Assert
(Inside_A_Generic
);
1518 Spec_Id
:= Scope
(Spec_Id
);
1519 pragma Assert
(Is_Inlined
(Spec_Id
));
1521 end Analyze_Attribute_Old_Result
;
1523 -----------------------------
1524 -- Analyze_Image_Attribute --
1525 -----------------------------
1527 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
) is
1528 procedure Check_Image_Type
(Image_Type
: Entity_Id
);
1529 -- Check that Image_Type is legal as the type of a prefix of 'Image.
1530 -- Legality depends on the Ada language version.
1532 ----------------------
1533 -- Check_Image_Type --
1534 ----------------------
1536 procedure Check_Image_Type
(Image_Type
: Entity_Id
) is
1538 -- Image_Type may be empty in case of another error detected,
1539 -- or if an N_Raise_xxx_Error node is a parent of N.
1541 if Ada_Version
< Ada_2022
1542 and then Present
(Image_Type
)
1543 and then not Is_Scalar_Type
(Image_Type
)
1545 Error_Msg_Ada_2022_Feature
("nonscalar ''Image", Sloc
(P
));
1548 end Check_Image_Type
;
1550 -- Start of processing for Analyze_Image_Attribute
1553 -- AI12-0124: The ARG has adopted the GNAT semantics of 'Img for
1554 -- scalar types, so that the prefix can be an object, a named value,
1555 -- or a type. If the prefix is an object, there is no argument.
1557 if Is_Object_Image
(P
) then
1559 Set_Etype
(N
, Str_Typ
);
1560 Check_Image_Type
(Etype
(P
));
1562 if Attr_Id
/= Attribute_Img
then
1563 Error_Msg_Ada_2012_Feature
("|Object''Image", Sloc
(P
));
1567 Set_Etype
(N
, Str_Typ
);
1569 pragma Assert
(Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)));
1571 if Ekind
(Entity
(P
)) = E_Incomplete_Type
1572 and then Present
(Full_View
(Entity
(P
)))
1574 P_Type
:= Full_View
(Entity
(P
));
1575 P_Base_Type
:= Base_Type
(P_Type
);
1576 Set_Entity
(P
, P_Type
);
1579 Check_Image_Type
(P_Type
);
1580 Resolve
(E1
, P_Base_Type
);
1581 Validate_Non_Static_Attribute_Function_Call
;
1584 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
1586 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
1587 -- to avoid giving a duplicate message for when Image attributes
1588 -- applied to object references get expanded into type-based Image
1591 if Restriction_Check_Required
(No_Fixed_IO
)
1592 and then Comes_From_Source
(N
)
1593 and then Is_Fixed_Point_Type
(P_Type
)
1595 Check_Restriction
(No_Fixed_IO
, P
);
1597 end Analyze_Image_Attribute
;
1599 -----------------------------
1600 -- Analyze_Index_Attribute --
1601 -----------------------------
1603 procedure Analyze_Index_Attribute
1604 (Legal
: out Boolean;
1605 Spec_Id
: out Entity_Id
)
1607 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1608 -- Verify that the attribute appears within pragma Check that mimics
1611 procedure Placement_Error
;
1612 pragma No_Return
(Placement_Error
);
1613 -- Emit a general error when the attributes does not appear in a
1614 -- precondition or postcondition aspect or pragma, and then raises
1615 -- Bad_Attribute to avoid any further semantic processing.
1617 ------------------------------
1618 -- Check_Placement_In_Check --
1619 ------------------------------
1621 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1622 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1623 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1626 -- The "Name" argument of pragma Check denotes a precondition or
1630 | Name_Postcondition
1637 -- Otherwise the placement of the attribute is illegal
1642 end Check_Placement_In_Check
;
1644 ---------------------
1645 -- Placement_Error --
1646 ---------------------
1648 procedure Placement_Error
is
1651 ("attribute % can only appear in pre- or postcondition", P
);
1652 end Placement_Error
;
1658 Subp_Decl
: Node_Id
;
1660 -- Start of processing for Analyze_Index_Attribute
1663 -- Assume that the attribute is illegal
1668 -- Skip processing during preanalysis of class-wide preconditions and
1669 -- postconditions since at this stage the expression is not installed
1670 -- yet on its definite context.
1672 if Inside_Class_Condition_Preanalysis
then
1674 Spec_Id
:= Current_Scope
;
1678 -- Traverse the parent chain to find the aspect or pragma where the
1679 -- attribute resides.
1682 while Present
(Prag
) loop
1683 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1686 -- Prevent the search from going too far
1688 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1692 Prag
:= Parent
(Prag
);
1695 -- The attribute is allowed to appear only in precondition and
1696 -- postcondition-like aspects or pragmas.
1698 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1699 if Nkind
(Prag
) = N_Aspect_Specification
then
1700 Prag_Nam
:= Chars
(Identifier
(Prag
));
1702 Prag_Nam
:= Pragma_Name
(Prag
);
1705 if Prag_Nam
= Name_Check
then
1706 Check_Placement_In_Check
(Prag
);
1708 elsif Prag_Nam
in Name_Post
1709 | Name_Postcondition
1720 -- Otherwise the placement of the attribute is illegal
1726 -- Find the related subprogram subject to the aspect or pragma
1728 if Nkind
(Prag
) = N_Aspect_Specification
then
1729 Subp_Decl
:= Parent
(Prag
);
1731 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1734 -- The aspect or pragma where the attribute resides should be
1735 -- associated with a subprogram declaration or a body since the
1736 -- analysis of pre-/postconditions of entry and entry families is
1737 -- performed in their wrapper subprogram. If this is not the case,
1738 -- then the aspect or pragma is illegal and no further analysis is
1741 if Nkind
(Subp_Decl
) not in N_Subprogram_Body
1742 | N_Subprogram_Declaration
1747 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1749 -- If we get here and Spec_Id denotes the entity of the entry wrapper
1750 -- (or the postcondition procedure of the entry wrapper) then the
1751 -- attribute is legal.
1753 if Is_Entry_Wrapper
(Spec_Id
) then
1756 elsif Chars
(Spec_Id
) = Name_uWrapped_Statements
1757 and then Is_Entry_Wrapper
(Scope
(Spec_Id
))
1759 Spec_Id
:= Scope
(Spec_Id
);
1762 -- Otherwise the attribute is illegal and we return Empty
1767 end Analyze_Index_Attribute
;
1769 ---------------------------------
1770 -- Bad_Attribute_For_Predicate --
1771 ---------------------------------
1773 procedure Bad_Attribute_For_Predicate
is
1775 if Is_Scalar_Type
(P_Type
)
1776 and then Comes_From_Source
(N
)
1778 Error_Msg_Name_1
:= Aname
;
1779 Bad_Predicated_Subtype_Use
1780 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1782 end Bad_Attribute_For_Predicate
;
1784 --------------------------------
1785 -- Check_Array_Or_Scalar_Type --
1786 --------------------------------
1788 procedure Check_Array_Or_Scalar_Type
is
1789 function In_Aspect_Specification
return Boolean;
1790 -- A current instance of a type in an aspect specification is an
1791 -- object and not a type, and therefore cannot be of a scalar type
1792 -- in the prefix of one of the array attributes if the attribute
1793 -- reference is part of an aspect expression.
1795 -----------------------------
1796 -- In_Aspect_Specification --
1797 -----------------------------
1799 function In_Aspect_Specification
return Boolean is
1804 while Present
(P
) loop
1805 if Nkind
(P
) = N_Aspect_Specification
then
1806 return P_Type
= Entity
(P
);
1808 elsif Nkind
(P
) in N_Declaration
then
1816 end In_Aspect_Specification
;
1822 -- Start of processing for Check_Array_Or_Scalar_Type
1825 -- Case of string literal or string literal subtype. These cases
1826 -- cannot arise from legal Ada code, but the expander is allowed
1827 -- to generate them. They require special handling because string
1828 -- literal subtypes do not have standard bounds (the whole idea
1829 -- of these subtypes is to avoid having to generate the bounds)
1831 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1832 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1837 elsif Is_Scalar_Type
(P_Type
) then
1840 if Present
(E1
) then
1841 Error_Attr
("invalid argument in % attribute", E1
);
1843 elsif In_Aspect_Specification
then
1845 ("prefix of % attribute cannot be the current instance of a "
1846 & "scalar type", P
);
1849 Set_Etype
(N
, P_Base_Type
);
1853 -- The following is a special test to allow 'First to apply to
1854 -- private scalar types if the attribute comes from generated
1855 -- code. This occurs in the case of Normalize_Scalars code.
1857 elsif Is_Private_Type
(P_Type
)
1858 and then Present
(Full_View
(P_Type
))
1859 and then Is_Scalar_Type
(Full_View
(P_Type
))
1860 and then not Comes_From_Source
(N
)
1862 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1864 -- Array types other than string literal subtypes handled above
1869 -- We know prefix is an array type, or the name of an array
1870 -- object, and that the expression, if present, is static
1871 -- and within the range of the dimensions of the type.
1873 pragma Assert
(Is_Array_Type
(P_Type
));
1874 Index
:= First_Index
(P_Base_Type
);
1878 -- First dimension assumed
1880 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1884 Udims
: constant Uint
:= Expr_Value
(E1
);
1885 Dims
: constant Int
:= UI_To_Int
(Udims
);
1887 for J
in 1 .. Dims
- 1 loop
1892 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1895 end Check_Array_Or_Scalar_Type
;
1897 ----------------------
1898 -- Check_Array_Type --
1899 ----------------------
1901 procedure Check_Array_Type
is
1903 -- Dimension number for array attributes
1906 -- If the type is a string literal type, then this must be generated
1907 -- internally, and no further check is required on its legality.
1909 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1912 -- If the type is a composite, it is an illegal aggregate, no point
1915 elsif P_Type
= Any_Composite
then
1916 raise Bad_Attribute
;
1919 -- Normal case of array type or subtype. Note that if the
1920 -- prefix is a current instance of a type declaration it
1921 -- appears within an aspect specification and is legal.
1923 Check_Either_E0_Or_E1
;
1926 if Is_Array_Type
(P_Type
) then
1927 if not Is_Constrained
(P_Type
)
1928 and then Is_Entity_Name
(P
)
1929 and then Is_Type
(Entity
(P
))
1930 and then not Is_Current_Instance
(P
)
1932 -- Note: we do not call Error_Attr here, since we prefer to
1933 -- continue, using the relevant index type of the array,
1934 -- even though it is unconstrained. This gives better error
1935 -- recovery behavior.
1937 Error_Msg_Name_1
:= Aname
;
1939 ("prefix for % attribute must be constrained array", P
);
1942 -- The attribute reference freezes the type, and thus the
1943 -- component type, even if the attribute may not depend on the
1944 -- component. Diagnose arrays with incomplete components now.
1945 -- If the prefix is an access to array, this does not freeze
1946 -- the designated type.
1948 if Nkind
(P
) /= N_Explicit_Dereference
then
1949 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1952 D
:= Number_Dimensions
(P_Type
);
1955 if Is_Private_Type
(P_Type
) then
1956 Error_Attr_P
("prefix for % attribute may not be private type");
1958 elsif Is_Access_Type
(P_Type
)
1959 and then Is_Array_Type
(Designated_Type
(P_Type
))
1960 and then Is_Entity_Name
(P
)
1961 and then Is_Type
(Entity
(P
))
1963 Error_Attr_P
("prefix of % attribute cannot be access type");
1965 elsif Attr_Id
= Attribute_First
1967 Attr_Id
= Attribute_Last
1969 Error_Attr
("invalid prefix for % attribute", P
);
1972 Error_Attr_P
("prefix for % attribute must be array");
1976 if Present
(E1
) then
1977 Resolve
(E1
, Any_Integer
);
1978 Set_Etype
(E1
, Standard_Integer
);
1980 if not Is_OK_Static_Expression
(E1
)
1981 or else Raises_Constraint_Error
(E1
)
1983 Flag_Non_Static_Expr
1984 ("expression for dimension must be static!", E1
);
1987 elsif Expr_Value
(E1
) > D
or else Expr_Value
(E1
) < 1 then
1988 Error_Attr
("invalid dimension number for array type", E1
);
1992 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1993 and then Comes_From_Source
(N
)
1995 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1997 end Check_Array_Type
;
1999 -------------------------
2000 -- Check_Asm_Attribute --
2001 -------------------------
2003 procedure Check_Asm_Attribute
is
2008 -- Check first argument is static string expression
2010 Analyze_And_Resolve
(E1
, Standard_String
);
2012 if Etype
(E1
) = Any_Type
then
2015 elsif not Is_OK_Static_Expression
(E1
) then
2016 Flag_Non_Static_Expr
2017 ("constraint argument must be static string expression!", E1
);
2021 -- Check second argument is right type
2023 Analyze_And_Resolve
(E2
, Entity
(P
));
2025 -- Note: that is all we need to do, we don't need to check
2026 -- that it appears in a correct context. The Ada type system
2027 -- will do that for us.
2029 end Check_Asm_Attribute
;
2031 ---------------------
2032 -- Check_Component --
2033 ---------------------
2035 procedure Check_Component
is
2039 if Nkind
(P
) /= N_Selected_Component
2041 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
2043 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
2045 Error_Attr_P
("prefix for % attribute must be selected component");
2047 end Check_Component
;
2049 ------------------------------------
2050 -- Check_Decimal_Fixed_Point_Type --
2051 ------------------------------------
2053 procedure Check_Decimal_Fixed_Point_Type
is
2057 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
2058 Error_Attr_P
("prefix of % attribute must be decimal type");
2060 end Check_Decimal_Fixed_Point_Type
;
2062 -----------------------
2063 -- Check_Dereference --
2064 -----------------------
2066 procedure Check_Dereference
is
2069 -- Case of a subtype mark
2071 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2075 -- Case of an expression
2079 if Is_Access_Type
(P_Type
) then
2081 -- If there is an implicit dereference, then we must freeze the
2082 -- designated type of the access type, since the type of the
2083 -- referenced array is this type (see AI95-00106).
2085 -- As done elsewhere, freezing must not happen when preanalyzing
2086 -- a pre- or postcondition or a default value for an object or for
2087 -- a formal parameter.
2089 if not In_Spec_Expression
then
2090 Freeze_Before
(N
, Designated_Type
(P_Type
));
2094 Make_Explicit_Dereference
(Sloc
(P_Old
),
2095 Prefix
=> Relocate_Node
(P_Old
)));
2097 Analyze_And_Resolve
(P_Old
);
2098 P_Type
:= Etype
(P_Old
);
2100 if P_Type
= Any_Type
then
2101 raise Bad_Attribute
;
2104 P_Base_Type
:= Base_Type
(P_Type
);
2106 end Check_Dereference
;
2108 -------------------------
2109 -- Check_Discrete_Type --
2110 -------------------------
2112 procedure Check_Discrete_Type
is
2116 if not Is_Discrete_Type
(P_Type
) then
2117 Error_Attr_P
("prefix of % attribute must be discrete type");
2119 end Check_Discrete_Type
;
2125 procedure Check_E0
is
2127 if Present
(E1
) then
2128 Unexpected_Argument
(E1
);
2136 procedure Check_E1
is
2138 Check_Either_E0_Or_E1
;
2142 -- Special-case attributes that are functions and that appear as
2143 -- the prefix of another attribute. Error is posted on parent.
2145 if Nkind
(Parent
(N
)) = N_Attribute_Reference
2146 and then Attribute_Name
(Parent
(N
)) in Name_Address
2150 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
2151 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
2152 Set_Etype
(Parent
(N
), Any_Type
);
2153 Set_Entity
(Parent
(N
), Any_Type
);
2154 raise Bad_Attribute
;
2157 Error_Attr
("missing argument for % attribute", N
);
2166 procedure Check_E2
is
2169 Error_Attr
("missing arguments for % attribute (2 required)", N
);
2171 Error_Attr
("missing argument for % attribute (2 required)", N
);
2175 ---------------------------
2176 -- Check_Either_E0_Or_E1 --
2177 ---------------------------
2179 procedure Check_Either_E0_Or_E1
is
2181 if Present
(E2
) then
2182 Unexpected_Argument
(E2
);
2184 end Check_Either_E0_Or_E1
;
2186 ----------------------
2187 -- Check_Enum_Image --
2188 ----------------------
2190 procedure Check_Enum_Image
(Check_Enumeration_Maps
: Boolean := False) is
2194 -- Ensure that Check_Enumeration_Maps parameter is set precisely for
2195 -- attributes whose implementation requires enumeration maps.
2198 (Check_Enumeration_Maps
= (Attr_Id
in Attribute_Image
2200 | Attribute_Valid_Value
2202 | Attribute_Wide_Image
2203 | Attribute_Wide_Value
2204 | Attribute_Wide_Wide_Image
2205 | Attribute_Wide_Wide_Value
));
2207 -- When an enumeration type appears in an attribute reference, all
2208 -- literals of the type are marked as referenced. This must only be
2209 -- done if the attribute reference appears in the current source.
2210 -- Otherwise the information on references may differ between a
2211 -- normal compilation and one that performs inlining.
2213 if Is_Enumeration_Type
(P_Base_Type
)
2214 and then In_Extended_Main_Code_Unit
(N
)
2216 if Check_Enumeration_Maps
then
2217 Check_Restriction
(No_Enumeration_Maps
, N
);
2220 Lit
:= First_Literal
(P_Base_Type
);
2221 while Present
(Lit
) loop
2222 Set_Referenced
(Lit
);
2226 end Check_Enum_Image
;
2228 ----------------------------
2229 -- Check_First_Last_Valid --
2230 ----------------------------
2232 procedure Check_First_Last_Valid
is
2234 Check_Discrete_Type
;
2236 -- Freeze the subtype now, so that the following test for predicates
2237 -- works (we set the predicates stuff up at freeze time)
2239 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
2241 -- Now test for dynamic predicate
2243 if Has_Predicates
(P_Type
)
2244 and then not (Has_Static_Predicate
(P_Type
))
2247 ("prefix of % attribute may not have dynamic predicate");
2250 -- Check non-static subtype
2252 if not Is_OK_Static_Subtype
(P_Type
) then
2253 Error_Attr_P
("prefix of % attribute must be a static subtype");
2256 -- Test case for no values
2258 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
2259 Expr_Value
(Type_High_Bound
(P_Type
))
2260 or else (Has_Predicates
(P_Type
)
2262 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
2265 ("prefix of % attribute must be subtype with at least one "
2268 end Check_First_Last_Valid
;
2270 ----------------------------
2271 -- Check_Fixed_Point_Type --
2272 ----------------------------
2274 procedure Check_Fixed_Point_Type
is
2278 if not Is_Fixed_Point_Type
(P_Type
) then
2279 Error_Attr_P
("prefix of % attribute must be fixed point type");
2281 end Check_Fixed_Point_Type
;
2283 ------------------------------
2284 -- Check_Fixed_Point_Type_0 --
2285 ------------------------------
2287 procedure Check_Fixed_Point_Type_0
is
2289 Check_Fixed_Point_Type
;
2291 end Check_Fixed_Point_Type_0
;
2293 -------------------------------
2294 -- Check_Floating_Point_Type --
2295 -------------------------------
2297 procedure Check_Floating_Point_Type
is
2301 if not Is_Floating_Point_Type
(P_Type
) then
2302 Error_Attr_P
("prefix of % attribute must be float type");
2304 end Check_Floating_Point_Type
;
2306 ---------------------------------
2307 -- Check_Floating_Point_Type_0 --
2308 ---------------------------------
2310 procedure Check_Floating_Point_Type_0
is
2312 Check_Floating_Point_Type
;
2314 end Check_Floating_Point_Type_0
;
2316 ---------------------------------
2317 -- Check_Floating_Point_Type_1 --
2318 ---------------------------------
2320 procedure Check_Floating_Point_Type_1
is
2322 Check_Floating_Point_Type
;
2324 end Check_Floating_Point_Type_1
;
2326 ---------------------------------
2327 -- Check_Floating_Point_Type_2 --
2328 ---------------------------------
2330 procedure Check_Floating_Point_Type_2
is
2332 Check_Floating_Point_Type
;
2334 end Check_Floating_Point_Type_2
;
2336 ------------------------
2337 -- Check_Integer_Type --
2338 ------------------------
2340 procedure Check_Integer_Type
is
2344 if not Is_Integer_Type
(P_Type
) then
2345 Error_Attr_P
("prefix of % attribute must be integer type");
2347 end Check_Integer_Type
;
2349 --------------------------------
2350 -- Check_Modular_Integer_Type --
2351 --------------------------------
2353 procedure Check_Modular_Integer_Type
is
2357 if not Is_Modular_Integer_Type
(P_Type
) then
2359 ("prefix of % attribute must be modular integer type");
2361 end Check_Modular_Integer_Type
;
2363 ------------------------
2364 -- Check_Not_CPP_Type --
2365 ------------------------
2367 procedure Check_Not_CPP_Type
is
2369 if Is_Tagged_Type
(Etype
(P
))
2370 and then Convention
(Etype
(P
)) = Convention_CPP
2371 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
2374 ("invalid use of % attribute with 'C'P'P tagged type");
2376 end Check_Not_CPP_Type
;
2378 -------------------------------
2379 -- Check_Not_Incomplete_Type --
2380 -------------------------------
2382 procedure Check_Not_Incomplete_Type
is
2387 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2388 -- dereference we have to check wrong uses of incomplete types
2389 -- (other wrong uses are checked at their freezing point).
2391 -- In Ada 2012, incomplete types can appear in subprogram
2392 -- profiles, but formals with incomplete types cannot be the
2393 -- prefix of attributes.
2395 -- Example 1: Limited-with
2397 -- limited with Pkg;
2399 -- type Acc is access Pkg.T;
2401 -- S : Integer := X.all'Size; -- ERROR
2404 -- Example 2: Tagged incomplete
2406 -- type T is tagged;
2407 -- type Acc is access all T;
2409 -- S : constant Integer := X.all'Size; -- ERROR
2410 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2412 if Ada_Version
>= Ada_2005
2413 and then Nkind
(P
) = N_Explicit_Dereference
2416 while Nkind
(E
) = N_Explicit_Dereference
loop
2422 if From_Limited_With
(Typ
) then
2424 ("prefix of % attribute cannot be an incomplete type");
2426 -- If the prefix is an access type check the designated type
2428 elsif Is_Access_Type
(Typ
)
2429 and then Nkind
(P
) = N_Explicit_Dereference
2431 Typ
:= Directly_Designated_Type
(Typ
);
2434 if Is_Class_Wide_Type
(Typ
) then
2435 Typ
:= Root_Type
(Typ
);
2438 -- A legal use of a shadow entity occurs only when the unit where
2439 -- the non-limited view resides is imported via a regular with
2440 -- clause in the current body. Such references to shadow entities
2441 -- may occur in subprogram formals.
2443 if Is_Incomplete_Type
(Typ
)
2444 and then From_Limited_With
(Typ
)
2445 and then Present
(Non_Limited_View
(Typ
))
2446 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2448 Typ
:= Non_Limited_View
(Typ
);
2451 -- If still incomplete, it can be a local incomplete type, or a
2452 -- limited view whose scope is also a limited view.
2454 if Ekind
(Typ
) = E_Incomplete_Type
then
2455 if not From_Limited_With
(Typ
)
2456 and then No
(Full_View
(Typ
))
2459 ("prefix of % attribute cannot be an incomplete type");
2461 -- The limited view may be available indirectly through
2462 -- an intermediate unit. If the non-limited view is available
2463 -- the attribute reference is legal.
2465 elsif From_Limited_With
(Typ
)
2467 (No
(Non_Limited_View
(Typ
))
2468 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2471 ("prefix of % attribute cannot be an incomplete type");
2475 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2478 elsif Is_Entity_Name
(P
)
2479 and then Is_Formal
(Entity
(P
))
2480 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2483 ("prefix of % attribute cannot be an incomplete type");
2486 if not Is_Entity_Name
(P
)
2487 or else not Is_Type
(Entity
(P
))
2488 or else In_Spec_Expression
2492 Check_Fully_Declared
(P_Type
, P
);
2494 end Check_Not_Incomplete_Type
;
2496 ----------------------------
2497 -- Check_Object_Reference --
2498 ----------------------------
2500 procedure Check_Object_Reference
(P
: Node_Id
) is
2504 -- If we need an object, and we have a prefix that is the name of a
2505 -- function entity, convert it into a function call.
2507 if Is_Entity_Name
(P
)
2508 and then Ekind
(Entity
(P
)) = E_Function
2510 Rtyp
:= Etype
(Entity
(P
));
2513 Make_Function_Call
(Sloc
(P
),
2514 Name
=> Relocate_Node
(P
)));
2516 Analyze_And_Resolve
(P
, Rtyp
);
2518 -- Otherwise we must have an object reference
2520 elsif not Is_Object_Reference
(P
) then
2521 Error_Attr_P
("prefix of % attribute must be object");
2523 end Check_Object_Reference
;
2525 ----------------------------
2526 -- Check_PolyORB_Attribute --
2527 ----------------------------
2529 procedure Check_PolyORB_Attribute
is
2531 Validate_Non_Static_Attribute_Function_Call
;
2536 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2538 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2540 end Check_PolyORB_Attribute
;
2542 ------------------------
2543 -- Check_Program_Unit --
2544 ------------------------
2546 procedure Check_Program_Unit
is
2548 if Is_Entity_Name
(P
) then
2550 E
: constant Entity_Id
:= Entity
(P
);
2552 if Ekind
(E
) in E_Protected_Type
2558 or else Is_Single_Concurrent_Object
(E
)
2565 Error_Attr_P
("prefix of % attribute must be program unit");
2566 end Check_Program_Unit
;
2568 ---------------------
2569 -- Check_Real_Type --
2570 ---------------------
2572 procedure Check_Real_Type
is
2576 if not Is_Real_Type
(P_Type
) then
2577 Error_Attr_P
("prefix of % attribute must be real type");
2579 end Check_Real_Type
;
2581 ----------------------------
2582 -- Check_Enumeration_Type --
2583 ----------------------------
2585 procedure Check_Enumeration_Type
is
2589 if not Is_Enumeration_Type
(P_Type
) then
2590 Error_Attr_P
("prefix of % attribute must be enumeration type");
2592 end Check_Enumeration_Type
;
2594 -----------------------
2595 -- Check_Scalar_Type --
2596 -----------------------
2598 procedure Check_Scalar_Type
is
2602 if not Is_Scalar_Type
(P_Type
) then
2603 Error_Attr_P
("prefix of % attribute must be scalar type");
2605 end Check_Scalar_Type
;
2607 ---------------------------
2608 -- Check_Standard_Prefix --
2609 ---------------------------
2611 procedure Check_Standard_Prefix
is
2615 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2616 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2618 end Check_Standard_Prefix
;
2620 -------------------------------
2621 -- Check_Put_Image_Attribute --
2622 -------------------------------
2624 procedure Check_Put_Image_Attribute
is
2626 -- Put_Image is a procedure, and can only appear at the position of a
2627 -- procedure call. If it's a list member and it's parent is a
2628 -- procedure call or aggregate, then this is appearing as an actual
2629 -- parameter or component association, which is wrong.
2631 if Is_List_Member
(N
)
2632 and then Nkind
(Parent
(N
)) not in
2633 N_Procedure_Call_Statement | N_Aggregate
2638 ("invalid context for attribute%, which is a procedure", N
);
2642 Analyze_And_Resolve
(E1
);
2644 -- Check that the first argument is
2645 -- Ada.Strings.Text_Buffers.Root_Buffer_Type'Class.
2647 -- Note: the double call to Root_Type here is needed because the
2648 -- root type of a class-wide type is the corresponding type (e.g.
2649 -- X for X'Class, and we really want to go to the root.)
2651 if not Is_RTE
(Root_Type
(Root_Type
(Etype
(E1
))),
2652 RE_Root_Buffer_Type
)
2655 ("expected Ada.Strings.Text_Buffers.Root_Buffer_Type''Class",
2659 -- Check that the second argument is of the right type
2662 Resolve
(E2
, P_Type
);
2663 end Check_Put_Image_Attribute
;
2665 ----------------------------
2666 -- Check_Stream_Attribute --
2667 ----------------------------
2669 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2673 In_Shared_Var_Procs
: Boolean;
2674 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2675 -- For this runtime package (always compiled in GNAT mode), we allow
2676 -- stream attributes references for limited types for the case where
2677 -- shared passive objects are implemented using stream attributes,
2678 -- which is the default in GNAT's persistent storage implementation.
2681 Validate_Non_Static_Attribute_Function_Call
;
2683 -- With the exception of 'Input, Stream attributes are procedures,
2684 -- and can only appear at the position of procedure calls. We check
2685 -- for this here, before they are rewritten, to give a more precise
2688 if Nam
= TSS_Stream_Input
then
2691 elsif Is_List_Member
(N
)
2692 and then Nkind
(Parent
(N
)) not in
2693 N_Procedure_Call_Statement | N_Aggregate
2699 ("invalid context for attribute%, which is a procedure", N
);
2703 Btyp
:= Implementation_Base_Type
(P_Type
);
2705 -- Stream attributes not allowed on limited types unless the
2706 -- attribute reference was generated by the expander (in which
2707 -- case the underlying type will be used, as described in Sinfo),
2708 -- or the attribute was specified explicitly for the type itself
2709 -- or one of its ancestors (taking visibility rules into account if
2710 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2711 -- (with no visibility restriction).
2714 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2716 if Present
(Gen_Body
) then
2717 In_Shared_Var_Procs
:=
2718 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2720 In_Shared_Var_Procs
:= False;
2724 if (Comes_From_Source
(N
)
2725 and then not (In_Shared_Var_Procs
or In_Instance
))
2726 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2727 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2729 Error_Msg_Name_1
:= Aname
;
2731 if Is_Limited_Type
(P_Type
) then
2733 ("limited type& has no% attribute", P
, P_Type
);
2734 Explain_Limited_Type
(P_Type
, P
);
2737 ("attribute% for type& is not available", P
, P_Type
);
2741 -- Check for no stream operations allowed from No_Tagged_Streams
2743 if Is_Tagged_Type
(P_Type
)
2744 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2746 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2748 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2752 -- Check restriction violations
2754 -- First check the No_Streams restriction, which prohibits the use
2755 -- of explicit stream attributes in the source program. We do not
2756 -- prevent the occurrence of stream attributes in generated code,
2757 -- for instance those generated implicitly for dispatching purposes.
2759 if Comes_From_Source
(N
) then
2760 Check_Restriction
(No_Streams
, P
);
2763 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2764 -- it is illegal to use a predefined elementary type stream attribute
2765 -- either by itself, or more importantly as part of the attribute
2766 -- subprogram for a composite type. However, if the broader
2767 -- restriction No_Streams is active, stream operations are not
2768 -- generated, and there is no error.
2770 if Restriction_Active
(No_Default_Stream_Attributes
)
2771 and then not Restriction_Active
(No_Streams
)
2777 if Nam
= TSS_Stream_Input
2779 Nam
= TSS_Stream_Read
2782 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2785 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2789 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2792 ("missing user-defined Stream Read or Write for type&",
2794 if not Is_Elementary_Type
(P_Type
) then
2796 ("\which is a component of type&", N
, P_Type
);
2802 -- Check special case of Exception_Id and Exception_Occurrence which
2803 -- are not allowed for restriction No_Exception_Registration.
2805 if Restriction_Check_Required
(No_Exception_Registration
)
2806 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2808 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2810 Check_Restriction
(No_Exception_Registration
, P
);
2813 -- If the No_Tagged_Type_Registration restriction is active, then
2814 -- class-wide streaming attributes are not allowed.
2816 if Restriction_Check_Required
(No_Tagged_Type_Registration
)
2817 and then Is_Class_Wide_Type
(P_Type
)
2819 Check_Restriction
(No_Tagged_Type_Registration
, P
);
2822 -- Here we must check that the first argument is an access type
2823 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2825 Analyze_And_Resolve
(E1
);
2828 -- Note: the double call to Root_Type here is needed because the
2829 -- root type of a class-wide type is the corresponding type (e.g.
2830 -- X for X'Class, and we really want to go to the root.)
2832 if not Is_Access_Type
(Etyp
)
2833 or else not Is_RTE
(Root_Type
(Root_Type
(Designated_Type
(Etyp
))),
2834 RE_Root_Stream_Type
)
2837 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2840 -- Check that the second argument is of the right type if there is
2841 -- one (the Input attribute has only one argument so this is skipped)
2843 if Present
(E2
) then
2846 if Nam
= TSS_Stream_Read
2847 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2850 ("second argument of % attribute must be a variable", E2
);
2853 Resolve
(E2
, P_Type
);
2857 end Check_Stream_Attribute
;
2859 -------------------------
2860 -- Check_System_Prefix --
2861 -------------------------
2863 procedure Check_System_Prefix
is
2865 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2866 Error_Attr
("only allowed prefix for % attribute is System", P
);
2868 end Check_System_Prefix
;
2870 -----------------------
2871 -- Check_Task_Prefix --
2872 -----------------------
2874 procedure Check_Task_Prefix
is
2876 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2877 -- task interface class-wide types.
2879 if Is_Task_Type
(Etype
(P
))
2880 or else (Is_Access_Type
(Etype
(P
))
2881 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2882 or else (Ada_Version
>= Ada_2005
2883 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2884 and then Is_Interface
(Etype
(P
))
2885 and then Is_Task_Interface
(Etype
(P
)))
2890 if Ada_Version
>= Ada_2005
then
2892 ("prefix of % attribute must be a task or a task " &
2893 "interface class-wide object");
2896 Error_Attr_P
("prefix of % attribute must be a task");
2899 end Check_Task_Prefix
;
2905 -- The possibilities are an entity name denoting a type, or an
2906 -- attribute reference that denotes a type (Base or Class). If
2907 -- the type is incomplete, replace it with its full view.
2909 procedure Check_Type
is
2911 if not Is_Entity_Name
(P
)
2912 or else not Is_Type
(Entity
(P
))
2914 Error_Attr_P
("prefix of % attribute must be a type");
2916 elsif Is_Protected_Self_Reference
(P
) then
2918 ("prefix of % attribute denotes current instance "
2919 & "(RM 9.4(21/2))");
2921 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2922 and then Present
(Full_View
(Entity
(P
)))
2924 P_Type
:= Full_View
(Entity
(P
));
2925 Set_Entity
(P
, P_Type
);
2929 ---------------------
2930 -- Check_Unit_Name --
2931 ---------------------
2933 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2935 if Nkind
(Nod
) = N_Identifier
then
2938 elsif Nkind
(Nod
) in N_Selected_Component | N_Expanded_Name
then
2939 Check_Unit_Name
(Prefix
(Nod
));
2941 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2946 Error_Attr
("argument for % attribute must be unit name", P
);
2947 end Check_Unit_Name
;
2953 procedure Error_Attr
is
2955 Set_Etype
(N
, Any_Type
);
2956 Set_Entity
(N
, Any_Type
);
2957 raise Bad_Attribute
;
2960 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2962 Error_Msg_Name_1
:= Aname
;
2963 Error_Msg_N
(Msg
, Error_Node
);
2971 procedure Error_Attr_P
(Msg
: String; Msg_Cont
: String := "") is
2973 Error_Msg_Name_1
:= Aname
;
2974 Error_Msg_F
(Msg
, P
);
2975 if Msg_Cont
/= "" then
2976 Error_Msg_F
(Msg_Cont
, P
);
2981 ----------------------------
2982 -- Legal_Formal_Attribute --
2983 ----------------------------
2985 procedure Legal_Formal_Attribute
is
2989 if not Is_Entity_Name
(P
)
2990 or else not Is_Type
(Entity
(P
))
2992 Error_Attr_P
("prefix of % attribute must be generic type");
2994 elsif Is_Generic_Actual_Type
(Entity
(P
))
2996 or else In_Inlined_Body
3000 elsif Is_Generic_Type
(Entity
(P
)) then
3001 if Is_Definite_Subtype
(Entity
(P
)) then
3003 ("prefix of % attribute must be indefinite generic type");
3008 ("prefix of % attribute must be indefinite generic type");
3011 Set_Etype
(N
, Standard_Boolean
);
3012 end Legal_Formal_Attribute
;
3014 ---------------------------------------------------------------
3015 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
3016 ---------------------------------------------------------------
3018 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
3022 Check_Not_Incomplete_Type
;
3023 Set_Etype
(N
, Universal_Integer
);
3024 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
3030 procedure Min_Max
is
3032 -- Attribute can appear as function name in a reduction.
3033 -- Semantic checks are performed later.
3035 if Nkind
(Parent
(N
)) = N_Attribute_Reference
3036 and then Attribute_Name
(Parent
(N
)) = Name_Reduce
3038 Set_Etype
(N
, P_Base_Type
);
3044 Resolve
(E1
, P_Base_Type
);
3045 Resolve
(E2
, P_Base_Type
);
3046 Set_Etype
(N
, P_Base_Type
);
3048 -- Check for comparison on unordered enumeration type
3050 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
3051 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
3053 ("comparison on unordered enumeration type& declared#?.u?",
3058 ------------------------
3059 -- Standard_Attribute --
3060 ------------------------
3062 procedure Standard_Attribute
(Val
: Int
) is
3064 Check_Standard_Prefix
;
3065 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
3067 Set_Is_Static_Expression
(N
, True);
3068 end Standard_Attribute
;
3070 --------------------
3071 -- Uneval_Old_Msg --
3072 --------------------
3074 procedure Uneval_Old_Msg
is
3075 Uneval_Old_Setting
: Character;
3079 -- If from aspect, then Uneval_Old_Setting comes from flags in the
3080 -- N_Aspect_Specification node that corresponds to the attribute.
3082 -- First find the pragma in which we appear (note that at this stage,
3083 -- even if we appeared originally within an aspect specification, we
3084 -- are now within the corresponding pragma).
3088 Prag
:= Parent
(Prag
);
3089 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
3092 if Present
(Prag
) then
3093 if Uneval_Old_Accept
(Prag
) then
3094 Uneval_Old_Setting
:= 'A';
3095 elsif Uneval_Old_Warn
(Prag
) then
3096 Uneval_Old_Setting
:= 'W';
3098 Uneval_Old_Setting
:= 'E';
3101 -- If we did not find the pragma, that's odd, just use the setting
3102 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
3105 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
3108 -- Processing depends on the setting of Uneval_Old
3110 case Uneval_Old_Setting
is
3112 -- ??? In the case where Ada_Version is < Ada_2022 and
3113 -- an illegal 'Old prefix would be legal in Ada_2022,
3114 -- we'd like to call Error_Msg_Ada_2022_Feature.
3115 -- Identifying that case involves some work.
3118 ("prefix of attribute % that is potentially "
3119 & "unevaluated must statically name an entity"
3121 -- further text needed for accuracy if Ada_2022
3122 & (if Ada_Version
>= Ada_2022
3123 and then Attr_Id
= Attribute_Old
3124 then " or be eligible for conditional evaluation"
3125 & " (RM 6.1.1 (27))"
3128 "\using pragma Unevaluated_Use_Of_Old (Allow) will make "
3132 Error_Msg_Name_1
:= Aname
;
3134 ("??prefix of attribute % appears in potentially "
3135 & "unevaluated context, exception may be raised", P
);
3141 raise Program_Error
;
3145 -------------------------
3146 -- Unexpected Argument --
3147 -------------------------
3149 procedure Unexpected_Argument
(En
: Node_Id
) is
3151 Error_Attr
("unexpected argument for % attribute", En
);
3152 end Unexpected_Argument
;
3154 -------------------------------------------------
3155 -- Validate_Non_Static_Attribute_Function_Call --
3156 -------------------------------------------------
3158 -- This function should be moved to Sem_Dist ???
3160 procedure Validate_Non_Static_Attribute_Function_Call
is
3162 if In_Preelaborated_Unit
3163 and then not In_Subprogram_Or_Concurrent_Unit
3165 Flag_Non_Static_Expr
3166 ("non-static function call in preelaborated unit!", N
);
3168 end Validate_Non_Static_Attribute_Function_Call
;
3170 -- Start of processing for Analyze_Attribute
3173 -- Immediate return if unrecognized attribute (already diagnosed by
3174 -- parser, so there is nothing more that we need to do).
3176 if not Is_Attribute_Name
(Aname
) then
3177 raise Bad_Attribute
;
3180 Check_Restriction_No_Use_Of_Attribute
(N
);
3182 -- Deal with Ada 83 issues
3184 if Comes_From_Source
(N
) then
3185 if not Attribute_83
(Attr_Id
) then
3186 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3187 Error_Msg_Name_1
:= Aname
;
3188 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
3191 if Attribute_Impl_Def
(Attr_Id
) then
3192 Check_Restriction
(No_Implementation_Attributes
, N
);
3197 -- Deal with Ada 2005 attributes that are implementation attributes
3198 -- because they appear in a version of Ada before Ada 2005, ditto for
3199 -- Ada 2012 and Ada 2022 attributes appearing in an earlier version.
3201 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
3203 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
3205 (Attribute_22
(Attr_Id
) and then Ada_Version
< Ada_2022
)
3207 Check_Restriction
(No_Implementation_Attributes
, N
);
3210 -- Remote access to subprogram type access attribute reference needs
3211 -- unanalyzed copy for tree transformation. The analyzed copy is used
3212 -- for its semantic information (whether prefix is a remote subprogram
3213 -- name), the unanalyzed copy is used to construct new subtree rooted
3214 -- with N_Aggregate which represents a fat pointer aggregate.
3216 if Aname
= Name_Access
then
3217 Discard_Node
(Copy_Separate_Tree
(N
));
3220 -- Analyze prefix and exit if error in analysis. If the prefix is an
3221 -- incomplete type, use full view if available. Note that there are
3222 -- some attributes for which we do not analyze the prefix, since the
3223 -- prefix is not a normal name, or else needs special handling.
3225 if Aname
/= Name_Elab_Body
and then
3226 Aname
/= Name_Elab_Spec
and then
3227 Aname
/= Name_Elab_Subp_Body
and then
3228 Aname
/= Name_Enabled
and then
3232 P_Type
:= Etype
(P
);
3234 if Is_Entity_Name
(P
)
3235 and then Present
(Entity
(P
))
3236 and then Is_Type
(Entity
(P
))
3238 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
3239 P_Type
:= Get_Full_View
(P_Type
);
3240 Set_Entity
(P
, P_Type
);
3241 Set_Etype
(P
, P_Type
);
3243 elsif Entity
(P
) = Current_Scope
3244 and then Is_Record_Type
(Entity
(P
))
3246 -- Use of current instance within the type. Verify that if the
3247 -- attribute appears within a constraint, it yields an access
3248 -- type, other uses are illegal.
3256 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
3258 Par
:= Parent
(Par
);
3262 and then Nkind
(Par
) = N_Subtype_Indication
3264 if Attr_Id
/= Attribute_Access
3265 and then Attr_Id
/= Attribute_Unchecked_Access
3266 and then Attr_Id
/= Attribute_Unrestricted_Access
3269 ("in a constraint the current instance can only "
3270 & "be used with an access attribute", N
);
3277 if P_Type
= Any_Type
then
3278 raise Bad_Attribute
;
3281 P_Base_Type
:= Base_Type
(P_Type
);
3284 -- Analyze expressions that may be present, exiting if an error occurs
3291 E1
:= First
(Exprs
);
3293 -- Skip analysis for case of Restriction_Set, we do not expect
3294 -- the argument to be analyzed in this case.
3296 if Aname
/= Name_Restriction_Set
then
3299 -- Check for missing/bad expression (result of previous error)
3301 if No
(E1
) or else Etype
(E1
) = Any_Type
then
3302 raise Bad_Attribute
;
3308 if Present
(E2
) then
3311 if Etype
(E2
) = Any_Type
then
3312 raise Bad_Attribute
;
3315 if Present
(Next
(E2
)) then
3316 Unexpected_Argument
(Next
(E2
));
3321 -- Cases where prefix must be resolvable by itself
3323 if Is_Overloaded
(P
)
3324 and then Aname
/= Name_Access
3325 and then Aname
/= Name_Address
3326 and then Aname
/= Name_Code_Address
3327 and then Aname
/= Name_Result
3328 and then Aname
/= Name_Unchecked_Access
3330 -- The prefix must be resolvable by itself, without reference to the
3331 -- attribute. One case that requires special handling is a prefix
3332 -- that is a function name, where one interpretation may be a
3333 -- parameterless call. Entry attributes are handled specially below.
3335 if Is_Entity_Name
(P
)
3336 and then Aname
not in Name_Count | Name_Caller
3338 Check_Parameterless_Call
(P
);
3341 if Is_Overloaded
(P
) then
3343 -- Ada 2005 (AI-345): Since protected and task types have
3344 -- primitive entry wrappers, the attributes Count, and Caller
3345 -- require a context check
3347 if Aname
in Name_Count | Name_Caller
then
3349 Count
: Natural := 0;
3354 Get_First_Interp
(P
, I
, It
);
3355 while Present
(It
.Nam
) loop
3356 if Comes_From_Source
(It
.Nam
) then
3362 Get_Next_Interp
(I
, It
);
3366 Error_Attr
("ambiguous prefix for % attribute", P
);
3368 Set_Is_Overloaded
(P
, False);
3373 Error_Attr
("ambiguous prefix for % attribute", P
);
3378 -- If the prefix was rewritten as a raise node, then rewrite N as a
3379 -- raise node, to avoid creating inconsistent trees. We still need to
3380 -- perform legality checks on the original tree.
3382 if Nkind
(P
) in N_Raise_xxx_Error
then
3383 Rewrite
(N
, Relocate_Node
(P
));
3384 P
:= Original_Node
(P_Old
);
3387 -- Remaining processing depends on attribute
3391 -- Attributes related to Ada 2012 iterators. Attribute specifications
3392 -- exist for these, but they cannot be queried.
3394 when Attribute_Constant_Indexing
3395 | Attribute_Default_Iterator
3396 | Attribute_Implicit_Dereference
3397 | Attribute_Iterator_Element
3398 | Attribute_Iterable
3399 | Attribute_Variable_Indexing
3401 Error_Msg_N
("illegal attribute", N
);
3403 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
3404 -- were already rejected by the parser. Thus they shouldn't appear here.
3406 when Internal_Attribute_Id
=>
3407 raise Program_Error
;
3413 when Attribute_Abort_Signal
=>
3414 Check_Standard_Prefix
;
3415 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
3422 when Attribute_Access
=>
3423 Analyze_Access_Attribute
;
3424 Check_Not_Incomplete_Type
;
3430 when Attribute_Address
=>
3433 Check_Not_Incomplete_Type
;
3435 -- If the prefix is a dereference of a value whose associated access
3436 -- type has been specified with aspect Designated_Storage_Model, then
3437 -- use the associated Storage_Model_Type's address type as the type
3438 -- of the attribute. Otherwise we use System.Address as usual. This
3439 -- isn't normally legit for a predefined attribute, but this is for
3440 -- our own extension to addressing and currently requires extensions
3441 -- to be enabled (such as with -gnatX0).
3444 Prefix_Obj
: constant Node_Id
:= Get_Referenced_Object
(P
);
3445 Addr_Type
: Entity_Id
:= RTE
(RE_Address
);
3447 if Nkind
(Prefix_Obj
) = N_Explicit_Dereference
then
3449 P_Type
: constant Entity_Id
:= Etype
(Prefix
(Prefix_Obj
));
3451 use Storage_Model_Support
;
3453 if Has_Designated_Storage_Model_Aspect
(P_Type
) then
3454 Addr_Type
:= Storage_Model_Address_Type
3455 (Storage_Model_Object
(P_Type
));
3460 Set_Etype
(N
, Addr_Type
);
3467 when Attribute_Address_Size
=>
3468 Standard_Attribute
(System_Address_Size
);
3474 when Attribute_Adjacent
3475 | Attribute_Copy_Sign
3476 | Attribute_Remainder
3478 Check_Floating_Point_Type_2
;
3479 Set_Etype
(N
, P_Base_Type
);
3480 Resolve
(E1
, P_Base_Type
);
3481 Resolve
(E2
, P_Base_Type
);
3487 when Attribute_Aft
=>
3488 Check_Fixed_Point_Type_0
;
3489 Set_Etype
(N
, Universal_Integer
);
3495 when Attribute_Alignment
=>
3497 -- Don't we need more checking here, cf Size ???
3500 Check_Not_Incomplete_Type
;
3502 Set_Etype
(N
, Universal_Integer
);
3508 when Attribute_Asm_Input
=>
3509 Check_Asm_Attribute
;
3511 -- The back end may need to take the address of E2
3513 if Is_Entity_Name
(E2
) then
3514 Set_Address_Taken
(Entity
(E2
));
3517 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3523 when Attribute_Asm_Output
=>
3524 Check_Asm_Attribute
;
3526 if Etype
(E2
) = Any_Type
then
3529 elsif Aname
= Name_Asm_Output
then
3530 if not Is_Variable
(E2
) then
3532 ("second argument for Asm_Output is not variable", E2
);
3536 Note_Possible_Modification
(E2
, Sure
=> True);
3538 -- The back end may need to take the address of E2
3540 if Is_Entity_Name
(E2
) then
3541 Set_Address_Taken
(Entity
(E2
));
3544 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3546 -----------------------------
3547 -- Atomic_Always_Lock_Free --
3548 -----------------------------
3550 when Attribute_Atomic_Always_Lock_Free
=>
3553 Set_Etype
(N
, Standard_Boolean
);
3559 -- Note: when the base attribute appears in the context of a subtype
3560 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3561 -- the following circuit.
3563 when Attribute_Base
=> Base
: declare
3571 if Ada_Version
>= Ada_95
3572 and then not Is_Scalar_Type
(Typ
)
3573 and then not Is_Generic_Type
(Typ
)
3575 Error_Attr_P
("prefix of Base attribute must be scalar type");
3577 elsif Sloc
(Typ
) = Standard_Location
3578 and then Base_Type
(Typ
) = Typ
3579 and then Warn_On_Redundant_Constructs
3581 Error_Msg_NE
-- CODEFIX
3582 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3585 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3586 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3587 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3595 when Attribute_Bit
=>
3598 if not Is_Object_Reference
(P
) then
3599 Error_Attr_P
("prefix of % attribute must be object");
3601 -- What about the access object cases ???
3607 Set_Etype
(N
, Universal_Integer
);
3613 when Attribute_Bit_Order
=>
3617 if not Is_Record_Type
(P_Type
) then
3618 Error_Attr_P
("prefix of % attribute must be record type");
3621 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3623 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3626 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3631 -- Reset incorrect indication of staticness
3633 Set_Is_Static_Expression
(N
, False);
3639 -- Note: in generated code, we can have a Bit_Position attribute
3640 -- applied to a (naked) record component (i.e. the prefix is an
3641 -- identifier that references an E_Component or E_Discriminant
3642 -- entity directly, and this is interpreted as expected by Gigi.
3643 -- The following code will not tolerate such usage, but when the
3644 -- expander creates this special case, it marks it as analyzed
3645 -- immediately and sets an appropriate type.
3647 when Attribute_Bit_Position
=>
3648 if Comes_From_Source
(N
) then
3652 Set_Etype
(N
, Universal_Integer
);
3658 when Attribute_Body_Version
=>
3661 Set_Etype
(N
, RTE
(RE_Version_String
));
3667 when Attribute_Callable
3668 | Attribute_Terminated
3671 Set_Etype
(N
, Standard_Boolean
);
3678 when Attribute_Caller
=> Caller
: declare
3685 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3688 if not Is_Entry
(Ent
) then
3689 Error_Attr
("invalid entry name", N
);
3693 Error_Attr
("invalid entry name", N
);
3696 for J
in reverse 0 .. Scope_Stack
.Last
loop
3697 S
:= Scope_Stack
.Table
(J
).Entity
;
3699 if S
= Scope
(Ent
) then
3700 Error_Attr
("Caller must appear in matching accept or body", N
);
3706 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3713 when Attribute_Ceiling
3715 | Attribute_Fraction
3717 | Attribute_Machine_Rounding
3719 | Attribute_Rounding
3720 | Attribute_Truncation
3721 | Attribute_Unbiased_Rounding
3723 Check_Floating_Point_Type_1
;
3724 Set_Etype
(N
, P_Base_Type
);
3725 Resolve
(E1
, P_Base_Type
);
3731 when Attribute_Class
=>
3732 Check_Restriction
(No_Dispatch
, N
);
3736 -- Applying Class to untagged incomplete type is obsolescent in Ada
3737 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3738 -- this flag gets set by Find_Type in this situation.
3740 if Restriction_Check_Required
(No_Obsolescent_Features
)
3741 and then Ada_Version
>= Ada_2005
3742 and then Ekind
(P_Type
) = E_Incomplete_Type
3745 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3747 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3748 and then not Tagged_Present
(DN
)
3750 Check_Restriction
(No_Obsolescent_Features
, P
);
3759 when Attribute_Code_Address
=>
3762 if Nkind
(P
) = N_Attribute_Reference
3763 and then Attribute_Name
(P
) in Name_Elab_Body | Name_Elab_Spec
3767 elsif not Is_Entity_Name
(P
)
3768 or else (Ekind
(Entity
(P
)) /= E_Function
3770 Ekind
(Entity
(P
)) /= E_Procedure
)
3772 Error_Attr
("invalid prefix for % attribute", P
);
3774 -- Issue an error if the prefix denotes an eliminated subprogram
3777 Set_Address_Taken
(Entity
(P
));
3778 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3781 Set_Etype
(N
, RTE
(RE_Address
));
3783 ----------------------
3784 -- Compiler_Version --
3785 ----------------------
3787 when Attribute_Compiler_Version
=>
3789 Check_Standard_Prefix
;
3790 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3791 Analyze_And_Resolve
(N
, Standard_String
);
3792 Set_Is_Static_Expression
(N
, True);
3794 --------------------
3795 -- Component_Size --
3796 --------------------
3798 when Attribute_Component_Size
=>
3800 Set_Etype
(N
, Universal_Integer
);
3802 -- Note: unlike other array attributes, unconstrained arrays are OK
3804 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3814 when Attribute_Compose
3815 | Attribute_Leading_Part
3818 Check_Floating_Point_Type_2
;
3819 Set_Etype
(N
, P_Base_Type
);
3820 Resolve
(E1
, P_Base_Type
);
3821 Resolve
(E2
, Any_Integer
);
3827 when Attribute_Constrained
=>
3829 Set_Etype
(N
, Standard_Boolean
);
3831 -- Case from RM J.4(2) of constrained applied to private type
3833 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3834 Check_Restriction
(No_Obsolescent_Features
, P
);
3836 if Warn_On_Obsolescent_Feature
then
3838 ("constrained for private type is an obsolescent feature "
3839 & "(RM J.4)?j?", N
);
3842 -- If we are within an instance, the attribute must be legal
3843 -- because it was valid in the generic unit. Ditto if this is
3844 -- an inlining of a function declared in an instance.
3846 if In_Instance
or else In_Inlined_Body
then
3849 -- For sure OK if we have a real private type itself, but must
3850 -- be completed, cannot apply Constrained to incomplete type.
3852 elsif Is_Private_Type
(Entity
(P
)) then
3854 -- Note: this is one of the Annex J features that does not
3855 -- generate a warning from -gnatwj, since in fact it seems
3856 -- very useful, and is used in the GNAT runtime.
3858 Check_Not_Incomplete_Type
;
3862 -- Normal (non-obsolescent case) of application to object or value of
3863 -- a discriminated type.
3866 -- AI12-0068: In a type or subtype aspect, a prefix denoting the
3867 -- current instance of the (sub)type is defined to be a value,
3868 -- not an object, so the Constrained attribute is always True
3869 -- (see RM 8.6(18/5) and RM 3.7.2(3/5)). We issue a warning about
3870 -- this unintuitive result, to help avoid confusion.
3872 if Is_Current_Instance_Reference_In_Type_Aspect
(P
) then
3873 Error_Msg_Name_1
:= Aname
;
3875 ("current instance attribute % in subtype aspect always " &
3879 Check_Object_Reference
(P
);
3882 -- If N does not come from source, then we allow the
3883 -- the attribute prefix to be of a private type whose
3884 -- full type has discriminants. This occurs in cases
3885 -- involving expanded calls to stream attributes.
3887 if not Comes_From_Source
(N
) then
3888 P_Type
:= Underlying_Type
(P_Type
);
3891 -- Must have discriminants or be an access type designating a type
3892 -- with discriminants. If it is a class-wide type it has unknown
3895 if Has_Discriminants
(P_Type
)
3896 or else Has_Unknown_Discriminants
(P_Type
)
3898 (Is_Access_Type
(P_Type
)
3899 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3903 -- The rule given in 3.7.2 is part of static semantics, but the
3904 -- intent is clearly that it be treated as a legality rule, and
3905 -- rechecked in the visible part of an instance. Nevertheless
3906 -- the intent also seems to be it should legally apply to the
3907 -- actual of a formal with unknown discriminants, regardless of
3908 -- whether the actual has discriminants, in which case the value
3909 -- of the attribute is determined using the J.4 rules. This choice
3910 -- seems the most useful, and is compatible with existing tests.
3912 elsif In_Instance
then
3915 -- Also allow an object of a generic type if extensions allowed
3916 -- and allow this for any type at all.
3918 elsif (Is_Generic_Type
(P_Type
)
3919 or else Is_Generic_Actual_Type
(P_Type
))
3920 and then All_Extensions_Allowed
3926 -- Fall through if bad prefix
3929 ("prefix of % attribute must be object of discriminated type");
3935 -- Shares processing with Adjacent attribute
3941 when Attribute_Count
=> Count
: declare
3949 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3952 if Ekind
(Ent
) /= E_Entry
then
3953 Error_Attr
("invalid entry name", N
);
3956 elsif Nkind
(P
) = N_Indexed_Component
then
3957 if not Is_Entity_Name
(Prefix
(P
))
3958 or else No
(Entity
(Prefix
(P
)))
3959 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3961 if Nkind
(Prefix
(P
)) = N_Selected_Component
3962 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3963 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3967 ("attribute % must apply to entry of current task", P
);
3970 Error_Attr
("invalid entry family name", P
);
3974 Ent
:= Entity
(Prefix
(P
));
3977 elsif Nkind
(P
) = N_Selected_Component
3978 and then Present
(Entity
(Selector_Name
(P
)))
3979 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3982 ("attribute % must apply to entry of current task", P
);
3985 Error_Attr
("invalid entry name", N
);
3988 for J
in reverse 0 .. Scope_Stack
.Last
loop
3989 S
:= Scope_Stack
.Table
(J
).Entity
;
3991 if S
= Scope
(Ent
) then
3992 if Nkind
(P
) = N_Expanded_Name
then
3993 Tsk
:= Entity
(Prefix
(P
));
3995 -- The prefix denotes either the task type, or else a
3996 -- single task whose task type is being analyzed.
3998 if (Is_Type
(Tsk
) and then Tsk
= S
)
3999 or else (not Is_Type
(Tsk
)
4000 and then Etype
(Tsk
) = S
4001 and then not (Comes_From_Source
(S
)))
4006 ("attribute % must apply to entry of current task", N
);
4012 elsif Ekind
(Scope
(Ent
)) in Task_Kind
4013 and then Ekind
(S
) not in E_Block
4018 Error_Attr
("attribute % cannot appear in inner unit", N
);
4020 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
4021 and then not Has_Completion
(Scope
(Ent
))
4023 Error_Attr
("attribute % can only be used inside body", N
);
4027 if Is_Overloaded
(P
) then
4029 Index
: Interp_Index
;
4033 Get_First_Interp
(P
, Index
, It
);
4034 while Present
(It
.Nam
) loop
4035 if It
.Nam
= Ent
then
4038 -- Ada 2005 (AI-345): Do not consider primitive entry
4039 -- wrappers generated for task or protected types.
4041 elsif Ada_Version
>= Ada_2005
4042 and then not Comes_From_Source
(It
.Nam
)
4047 Error_Attr
("ambiguous entry name", N
);
4050 Get_Next_Interp
(Index
, It
);
4055 Set_Etype
(N
, Universal_Integer
);
4058 -----------------------
4059 -- Default_Bit_Order --
4060 -----------------------
4062 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
4063 Target_Default_Bit_Order
: System
.Bit_Order
;
4066 Check_Standard_Prefix
;
4068 if Bytes_Big_Endian
then
4069 Target_Default_Bit_Order
:= System
.High_Order_First
;
4071 Target_Default_Bit_Order
:= System
.Low_Order_First
;
4075 Make_Integer_Literal
(Loc
,
4076 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
4078 Set_Etype
(N
, Universal_Integer
);
4079 Set_Is_Static_Expression
(N
);
4080 end Default_Bit_Order
;
4082 ----------------------------------
4083 -- Default_Scalar_Storage_Order --
4084 ----------------------------------
4086 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
4087 RE_Default_SSO
: RE_Id
;
4090 Check_Standard_Prefix
;
4092 case Opt
.Default_SSO
is
4094 if Bytes_Big_Endian
then
4095 RE_Default_SSO
:= RE_High_Order_First
;
4097 RE_Default_SSO
:= RE_Low_Order_First
;
4101 RE_Default_SSO
:= RE_High_Order_First
;
4104 RE_Default_SSO
:= RE_Low_Order_First
;
4107 raise Program_Error
;
4110 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
4117 when Attribute_Definite
=>
4118 Legal_Formal_Attribute
;
4124 when Attribute_Delta
=>
4125 Check_Fixed_Point_Type_0
;
4126 Set_Etype
(N
, Universal_Real
);
4132 when Attribute_Denorm
4133 | Attribute_Signed_Zeros
4135 Check_Floating_Point_Type_0
;
4136 Set_Etype
(N
, Standard_Boolean
);
4142 when Attribute_Deref
=>
4145 Resolve
(E1
, RTE
(RE_Address
));
4146 Set_Etype
(N
, P_Type
);
4148 ---------------------
4149 -- Descriptor_Size --
4150 ---------------------
4152 when Attribute_Descriptor_Size
=>
4155 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
4156 Error_Attr_P
("prefix of attribute % must denote a type");
4159 Set_Etype
(N
, Universal_Integer
);
4165 when Attribute_Digits
=>
4169 if not Is_Floating_Point_Type
(P_Type
)
4170 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
4173 ("prefix of % attribute must be float or decimal type");
4176 Set_Etype
(N
, Universal_Integer
);
4182 -- Also handles processing for Elab_Spec and Elab_Subp_Body
4184 when Attribute_Elab_Body
4185 | Attribute_Elab_Spec
4186 | Attribute_Elab_Subp_Body
4189 Check_Unit_Name
(P
);
4190 Set_Etype
(N
, Standard_Void_Type
);
4192 -- We have to manually call the expander in this case to get
4193 -- the necessary expansion (normally attributes that return
4194 -- entities are not expanded).
4202 -- Shares processing with Elab_Body attribute
4208 when Attribute_Elaborated
=>
4210 Check_Unit_Name
(P
);
4211 Set_Etype
(N
, Standard_Boolean
);
4218 | Attribute_Machine_Emax
4219 | Attribute_Machine_Emin
4220 | Attribute_Machine_Mantissa
4221 | Attribute_Model_Emin
4222 | Attribute_Model_Mantissa
4223 | Attribute_Safe_Emax
4225 Check_Floating_Point_Type_0
;
4226 Set_Etype
(N
, Universal_Integer
);
4232 when Attribute_Enabled
=>
4233 Check_Either_E0_Or_E1
;
4235 if Present
(E1
) then
4236 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
4237 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
4242 if Nkind
(P
) /= N_Identifier
then
4243 Error_Msg_N
("identifier expected (check name)", P
);
4244 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
4245 Error_Msg_N
("& is not a recognized check name", P
);
4248 Set_Etype
(N
, Standard_Boolean
);
4254 when Attribute_Enum_Rep
=>
4256 -- T'Enum_Rep (X) case
4258 if Present
(E1
) then
4260 Check_Discrete_Type
;
4261 Resolve
(E1
, P_Base_Type
);
4263 -- X'Enum_Rep case. X must be an object or enumeration literal
4264 -- (including an attribute reference), and it must be of a
4268 ((Is_Object_Reference
(P
)
4271 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
4272 or else Nkind
(P
) = N_Attribute_Reference
)
4273 and then Is_Discrete_Type
(Etype
(P
)))
4275 Error_Attr_P
("prefix of % attribute must be discrete object");
4278 Set_Etype
(N
, Universal_Integer
);
4284 when Attribute_Enum_Val
=>
4288 if not Is_Enumeration_Type
(P_Type
) then
4289 Error_Attr_P
("prefix of % attribute must be enumeration type");
4292 -- If the enumeration type has a standard representation, the effect
4293 -- is the same as 'Val, so rewrite the attribute as a 'Val.
4295 if not Has_Non_Standard_Rep
(P_Base_Type
) then
4297 Make_Attribute_Reference
(Loc
,
4298 Prefix
=> Relocate_Node
(Prefix
(N
)),
4299 Attribute_Name
=> Name_Val
,
4300 Expressions
=> New_List
(Relocate_Node
(E1
))));
4301 Analyze_And_Resolve
(N
, P_Base_Type
);
4303 -- Non-standard representation case (enumeration with holes)
4307 Resolve
(E1
, Any_Integer
);
4308 Set_Etype
(N
, P_Base_Type
);
4315 when Attribute_Epsilon
4316 | Attribute_Model_Epsilon
4317 | Attribute_Model_Small
4318 | Attribute_Safe_First
4319 | Attribute_Safe_Last
4321 Check_Floating_Point_Type_0
;
4322 Set_Etype
(N
, Universal_Real
);
4328 when Attribute_Exponent
=>
4329 Check_Floating_Point_Type_1
;
4330 Set_Etype
(N
, Universal_Integer
);
4331 Resolve
(E1
, P_Base_Type
);
4337 when Attribute_External_Tag
=>
4341 Set_Etype
(N
, Standard_String
);
4343 if not Is_Tagged_Type
(P_Type
) then
4344 Error_Attr_P
("prefix of % attribute must be tagged");
4351 when Attribute_Fast_Math
=>
4352 Check_Standard_Prefix
;
4353 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
4355 -----------------------
4356 -- Finalization_Size --
4357 -----------------------
4359 when Attribute_Finalization_Size
=>
4362 -- The prefix denotes an object
4364 if Is_Object_Reference
(P
) then
4365 Check_Object_Reference
(P
);
4367 -- The prefix denotes a type
4369 elsif Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
4371 Check_Not_Incomplete_Type
;
4373 -- Attribute 'Finalization_Size is not defined for class-wide
4374 -- types because it is not possible to know statically whether
4375 -- a definite type will have controlled components or not.
4377 if Is_Class_Wide_Type
(Etype
(P
)) then
4379 ("prefix of % attribute cannot denote a class-wide type");
4382 -- The prefix denotes an illegal construct
4386 ("prefix of % attribute must be a definite type or an object");
4389 Set_Etype
(N
, Universal_Integer
);
4395 when Attribute_First
4398 Check_Array_Or_Scalar_Type
;
4399 Bad_Attribute_For_Predicate
;
4405 when Attribute_First_Bit
4406 | Attribute_Last_Bit
4407 | Attribute_Position
4410 Set_Etype
(N
, Universal_Integer
);
4416 when Attribute_First_Valid
4417 | Attribute_Last_Valid
4419 Check_First_Last_Valid
;
4420 Set_Etype
(N
, P_Type
);
4426 when Attribute_Fixed_Value
=>
4427 Check_Fixed_Point_Type
;
4429 Resolve
(E1
, Any_Integer
);
4430 Set_Etype
(N
, P_Base_Type
);
4436 -- Shares processing with Ceiling attribute
4442 when Attribute_Fore
=>
4443 Check_Fixed_Point_Type_0
;
4444 Set_Etype
(N
, Universal_Integer
);
4450 -- Shares processing with Ceiling attribute
4456 when Attribute_From_Any
=>
4458 Check_PolyORB_Attribute
;
4459 Set_Etype
(N
, P_Base_Type
);
4461 -----------------------
4462 -- Has_Access_Values --
4463 -----------------------
4465 when Attribute_Has_Access_Values
4466 | Attribute_Has_Tagged_Values
4470 Set_Etype
(N
, Standard_Boolean
);
4472 ----------------------
4473 -- Has_Same_Storage --
4474 ----------------------
4476 when Attribute_Has_Same_Storage
4477 | Attribute_Overlaps_Storage
4481 -- The arguments must be objects of any type
4483 Analyze_And_Resolve
(P
);
4484 Analyze_And_Resolve
(E1
);
4485 Check_Object_Reference
(P
);
4486 Check_Object_Reference
(E1
);
4487 Set_Etype
(N
, Standard_Boolean
);
4493 when Attribute_Index
=> Index
: declare
4496 Spec_Id
: Entity_Id
;
4500 Analyze_Index_Attribute
(Legal
, Spec_Id
);
4502 if not Legal
or else No
(Spec_Id
) then
4503 Error_Attr
("attribute % must apply to entry family", P
);
4508 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
4511 if Ekind
(Ent
) /= E_Entry_Family
then
4513 ("attribute % must apply to entry family", P
);
4515 -- Analysis of pre/postconditions of an entry [family] occurs when
4516 -- the conditions are relocated to the contract wrapper procedure
4517 -- (see subprogram Build_Contract_Wrapper).
4519 elsif Contract_Wrapper
(Ent
) /= Spec_Id
then
4521 ("attribute % must apply to current entry family", P
);
4524 elsif Nkind
(P
) in N_Indexed_Component
4525 | N_Selected_Component
4528 ("attribute % must apply to current entry family", P
);
4531 Error_Attr
("invalid entry family name", N
);
4534 Set_Etype
(N
, Entry_Index_Type
(Ent
));
4537 -----------------------
4538 -- Has_Tagged_Values --
4539 -----------------------
4541 -- Shares processing with Has_Access_Values attribute
4543 -----------------------
4544 -- Has_Discriminants --
4545 -----------------------
4547 when Attribute_Has_Discriminants
=>
4548 Legal_Formal_Attribute
;
4554 when Attribute_Identity
=>
4557 if Etype
(P
) = Standard_Exception_Type
then
4558 Set_Etype
(N
, RTE
(RE_Exception_Id
));
4560 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
4561 -- interface class-wide types.
4563 elsif Is_Task_Type
(Etype
(P
))
4564 or else (Is_Access_Type
(Etype
(P
))
4565 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
4566 or else (Ada_Version
>= Ada_2005
4567 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
4568 and then Is_Interface
(Etype
(P
))
4569 and then Is_Task_Interface
(Etype
(P
)))
4572 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
4575 if Ada_Version
>= Ada_2005
then
4577 ("prefix of % attribute must be an exception, a task or a "
4578 & "task interface class-wide object");
4581 ("prefix of % attribute must be a task or an exception");
4589 when Attribute_Image
=>
4590 if Is_Real_Type
(P_Type
) then
4591 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4592 Error_Msg_Name_1
:= Aname
;
4594 ("(Ada 83) % attribute not allowed for real types", N
);
4598 Analyze_Image_Attribute
(Standard_String
);
4604 when Attribute_Img
=>
4605 Analyze_Image_Attribute
(Standard_String
);
4611 when Attribute_Initialized
=>
4614 if Comes_From_Source
(N
) then
4616 -- This attribute be prefixed with references to objects or
4617 -- values (such as a current instance value given within a type
4618 -- or subtype aspect).
4620 if not Is_Object_Reference
(P
)
4621 and then not Is_Current_Instance_Reference_In_Type_Aspect
(P
)
4623 Error_Attr_P
("prefix of % attribute must be object");
4627 Set_Etype
(N
, Standard_Boolean
);
4633 when Attribute_Input
=>
4635 Check_Stream_Attribute
(TSS_Stream_Input
);
4636 Set_Etype
(N
, P_Base_Type
);
4642 when Attribute_Integer_Value
=>
4645 Resolve
(E1
, Any_Fixed
);
4647 -- Signal an error if argument type is not a specific fixed-point
4648 -- subtype. An error has been signalled already if the argument
4649 -- was not of a fixed-point type.
4651 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4652 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4655 Set_Etype
(N
, P_Base_Type
);
4661 when Attribute_Invalid_Value
=>
4664 Set_Etype
(N
, P_Base_Type
);
4665 Invalid_Value_Used
:= True;
4671 when Attribute_Large
4673 | Attribute_Safe_Large
4674 | Attribute_Safe_Small
4678 Set_Etype
(N
, Universal_Real
);
4684 -- Shares processing with First attribute
4690 -- Shares processing with First_Bit attribute
4696 -- Shares processing with First_Valid attribute
4702 -- Shares processing with Compose attribute
4708 when Attribute_Length
=>
4710 Set_Etype
(N
, Universal_Integer
);
4716 when Attribute_Library_Level
=>
4719 if not Is_Entity_Name
(P
) then
4720 Error_Attr_P
("prefix of % attribute must be an entity name");
4723 if not Inside_A_Generic
then
4724 Set_Boolean_Result
(N
,
4725 Is_Library_Level_Entity
(Entity
(P
)));
4728 Set_Etype
(N
, Standard_Boolean
);
4734 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4735 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4736 -- Inspect the prefix for any uses of entities declared within the
4737 -- related loop. Loop_Id denotes the loop identifier.
4739 --------------------------------
4740 -- Check_References_In_Prefix --
4741 --------------------------------
4743 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4744 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4746 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4747 -- Determine whether a reference mentions an entity declared
4748 -- within the related loop.
4750 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4751 -- Determine whether Nod appears in the subtree of Loop_Decl but
4752 -- not within the subtree of the prefix P itself.
4754 ---------------------
4755 -- Check_Reference --
4756 ---------------------
4758 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4760 if Nkind
(Nod
) = N_Identifier
4761 and then Present
(Entity
(Nod
))
4762 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4765 ("prefix of attribute % cannot reference local entities",
4770 end Check_Reference
;
4772 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4774 ---------------------
4775 -- Declared_Within --
4776 ---------------------
4778 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4783 while Present
(Stmt
) loop
4784 if Stmt
= Loop_Decl
then
4790 -- Prevent the search from going too far
4792 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4796 Stmt
:= Parent
(Stmt
);
4800 end Declared_Within
;
4802 -- Start of processing for Check_Prefix_For_Local_References
4805 Check_References
(P
);
4806 end Check_References_In_Prefix
;
4810 Context
: constant Node_Id
:= Parent
(N
);
4812 Encl_Loop
: Node_Id
:= Empty
;
4813 Encl_Prag
: Node_Id
:= Empty
;
4814 Loop_Id
: Entity_Id
:= Empty
;
4818 -- Start of processing for Loop_Entry
4823 -- Set the type of the attribute now to ensure the successful
4824 -- continuation of analysis even if the attribute is misplaced.
4826 Set_Etype
(Attr
, P_Type
);
4828 -- Attribute 'Loop_Entry may appear in several flavors:
4830 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4831 -- nearest enclosing loop.
4833 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4834 -- attribute may be related to a loop denoted by label Expr or
4835 -- the prefix may denote an array object and Expr may act as an
4836 -- indexed component.
4838 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4839 -- to the nearest enclosing loop, all expressions are part of
4840 -- an indexed component.
4842 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4843 -- denotes, the attribute may be related to a loop denoted by
4844 -- label Expr or the prefix may denote a multidimensional array
4845 -- array object and Expr along with the rest of the expressions
4846 -- may act as indexed components.
4848 -- Regardless of variations, the attribute reference does not have an
4849 -- expression list. Instead, all available expressions are stored as
4850 -- indexed components.
4852 -- When the attribute is part of an indexed component, find the first
4853 -- expression as it will determine the semantics of 'Loop_Entry.
4855 -- If the attribute is itself an index in an indexed component, i.e.
4856 -- a member of a list, the context itself is not relevant (the code
4857 -- below would lead to an infinite loop) and the attribute applies
4858 -- to the enclosing loop.
4860 if Nkind
(Context
) = N_Indexed_Component
4861 and then not Is_List_Member
(N
)
4863 E1
:= First
(Expressions
(Context
));
4866 -- The attribute reference appears in the following form:
4868 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4870 -- In this case, the loop name is omitted and no rewriting is
4873 if Present
(E2
) then
4876 -- The form of the attribute is:
4878 -- Prefix'Loop_Entry (Expr) [(...)]
4880 -- If Expr denotes a loop entry, the whole attribute and indexed
4881 -- component will have to be rewritten to reflect this relation.
4884 pragma Assert
(Present
(E1
));
4886 -- Do not expand the expression as it may have side effects.
4887 -- Simply preanalyze to determine whether it is a loop name or
4890 Preanalyze_And_Resolve
(E1
);
4892 if Is_Entity_Name
(E1
)
4893 and then Present
(Entity
(E1
))
4894 and then Ekind
(Entity
(E1
)) = E_Loop
4896 Loop_Id
:= Entity
(E1
);
4898 -- Transform the attribute and enclosing indexed component
4900 Set_Expressions
(N
, Expressions
(Context
));
4901 Rewrite
(Context
, N
);
4902 Set_Etype
(Context
, P_Type
);
4909 -- The prefix must denote an object
4911 if not Is_Object_Reference
(P
) then
4912 Error_Attr_P
("prefix of attribute % must denote an object");
4915 -- The prefix cannot be of a limited type because the expansion of
4916 -- Loop_Entry must create a constant initialized by the evaluated
4919 if Is_Limited_View
(Etype
(P
)) then
4920 Error_Attr_P
("prefix of attribute % cannot be limited");
4923 -- Climb the parent chain to verify the location of the attribute and
4924 -- find the enclosing loop.
4927 while Present
(Stmt
) loop
4929 -- Locate the corresponding enclosing pragma. Note that in the
4930 -- case of Assert[And_Cut] and Assume, we have already checked
4931 -- that the pragma appears in an appropriate loop location.
4933 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4935 Pragma_Name_Unmapped
(Original_Node
(Stmt
))
4936 in Name_Loop_Invariant
4939 | Name_Assert_And_Cut
4942 Encl_Prag
:= Original_Node
(Stmt
);
4944 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4945 -- iteration may be expanded into several nested loops, we are
4946 -- interested in the outermost one which has the loop identifier,
4947 -- and comes from source.
4949 elsif Nkind
(Stmt
) = N_Loop_Statement
4950 and then Present
(Identifier
(Stmt
))
4951 and then Comes_From_Source
(Original_Node
(Stmt
))
4952 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
4956 -- The original attribute reference may lack a loop name. Use
4957 -- the name of the enclosing loop because it is the related
4960 if No
(Loop_Id
) then
4961 Loop_Id
:= Entity
(Identifier
(Encl_Loop
));
4966 -- Prevent the search from going too far
4968 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4972 Stmt
:= Parent
(Stmt
);
4975 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4976 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4977 -- purpose if they appear in an appropriate location in a loop,
4978 -- which was already checked by the top level pragma circuit).
4980 -- Loop_Entry also denotes a value and as such can appear within an
4981 -- expression that is an argument for another loop aspect. In that
4982 -- case it will have been expanded into the corresponding assignment.
4985 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
4986 and then not Comes_From_Source
(Parent
(N
))
4990 elsif No
(Encl_Prag
) then
4991 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4994 -- A Loop_Entry that applies to a given loop statement must not
4995 -- appear within a body of accept statement, if this construct is
4996 -- itself enclosed by the given loop statement.
4998 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4999 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
5001 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
5003 elsif Ekind
(Scop
) in E_Block | E_Loop | E_Return_Statement
then
5007 ("attribute % cannot appear in body or accept statement", N
);
5011 -- The prefix cannot mention entities declared within the related
5012 -- loop because they will not be visible once the prefix is moved
5013 -- outside the loop.
5015 Check_References_In_Prefix
(Loop_Id
);
5017 -- The prefix must statically name an object if the pragma does not
5018 -- apply to the innermost enclosing loop statement, or if it appears
5019 -- within a potentially unevaluated expression.
5021 if Is_Entity_Name
(P
)
5022 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
5023 or else Statically_Names_Object
(P
)
5027 elsif Present
(Encl_Loop
)
5028 and then Entity
(Identifier
(Encl_Loop
)) /= Loop_Id
5031 ("prefix of attribute % that applies to outer loop must denote "
5034 elsif Is_Potentially_Unevaluated
(P
) then
5038 -- Replace the Loop_Entry attribute reference by its prefix if the
5039 -- related pragma is ignored. This transformation is OK with respect
5040 -- to typing because Loop_Entry's type is that of its prefix. This
5041 -- early transformation also avoids the generation of a useless loop
5044 if Present
(Encl_Prag
) and then Is_Ignored
(Encl_Prag
) then
5045 Rewrite
(N
, Relocate_Node
(P
));
5046 Preanalyze_And_Resolve
(N
);
5049 Preanalyze_And_Resolve
(P
);
5057 -- Shares processing with Ceiling attribute
5063 -- Shares processing with Emax attribute
5069 -- Shares processing with Emax attribute
5071 ----------------------
5072 -- Machine_Mantissa --
5073 ----------------------
5075 -- Shares processing with Emax attribute
5077 -----------------------
5078 -- Machine_Overflows --
5079 -----------------------
5081 when Attribute_Machine_Overflows
5082 | Attribute_Machine_Rounds
5086 Set_Etype
(N
, Standard_Boolean
);
5092 when Attribute_Machine_Radix
5093 | Attribute_Mantissa
5097 Set_Etype
(N
, Universal_Integer
);
5099 ----------------------
5100 -- Machine_Rounding --
5101 ----------------------
5103 -- Shares processing with Ceiling attribute
5105 --------------------
5106 -- Machine_Rounds --
5107 --------------------
5109 -- Shares processing with Machine_Overflows attribute
5115 when Attribute_Machine_Size
5116 | Attribute_Object_Size
5117 | Attribute_Value_Size
5121 Check_Not_Incomplete_Type
;
5122 Set_Etype
(N
, Universal_Integer
);
5128 -- Shares processing with Machine_Radix attribute
5134 when Attribute_Max
=>
5137 ----------------------------------
5138 -- Max_Alignment_For_Allocation --
5139 ----------------------------------
5141 when Attribute_Max_Size_In_Storage_Elements
=>
5142 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5144 ----------------------
5145 -- Max_Integer_Size --
5146 ----------------------
5148 when Attribute_Max_Integer_Size
=>
5149 Standard_Attribute
(System_Max_Integer_Size
);
5151 ----------------------------------
5152 -- Max_Size_In_Storage_Elements --
5153 ----------------------------------
5155 when Attribute_Max_Alignment_For_Allocation
=>
5156 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5158 -----------------------
5159 -- Maximum_Alignment --
5160 -----------------------
5162 when Attribute_Maximum_Alignment
=>
5163 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
5165 --------------------
5166 -- Mechanism_Code --
5167 --------------------
5169 when Attribute_Mechanism_Code
=>
5170 if not Is_Entity_Name
(P
)
5171 or else not Is_Subprogram
(Entity
(P
))
5173 Error_Attr_P
("prefix of % attribute must be subprogram");
5176 Check_Either_E0_Or_E1
;
5178 if Present
(E1
) then
5179 Resolve
(E1
, Any_Integer
);
5180 Set_Etype
(E1
, Standard_Integer
);
5182 if not Is_OK_Static_Expression
(E1
) then
5183 Flag_Non_Static_Expr
5184 ("expression for parameter number must be static!", E1
);
5187 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
5188 or else Intval
(E1
) < 0
5190 Error_Attr
("invalid parameter number for % attribute", E1
);
5194 Set_Etype
(N
, Universal_Integer
);
5200 when Attribute_Min
=>
5207 when Attribute_Mod
=>
5209 -- Note: this attribute is only allowed in Ada 2005 mode, but
5210 -- we do not need to test that here, since Mod is only recognized
5211 -- as an attribute name in Ada 2005 mode during the parse.
5214 Check_Modular_Integer_Type
;
5215 Resolve
(E1
, Any_Integer
);
5216 Set_Etype
(N
, P_Base_Type
);
5222 -- Shares processing with Ceiling attribute
5228 -- Shares processing with Emax attribute
5234 -- Shares processing with Epsilon attribute
5236 --------------------
5237 -- Model_Mantissa --
5238 --------------------
5240 -- Shares processing with Emax attribute
5246 -- Shares processing with Epsilon attribute
5252 when Attribute_Modulus
=>
5254 Check_Modular_Integer_Type
;
5255 Set_Etype
(N
, Universal_Integer
);
5257 --------------------
5258 -- Null_Parameter --
5259 --------------------
5261 when Attribute_Null_Parameter
=> Null_Parameter
: declare
5262 Parnt
: constant Node_Id
:= Parent
(N
);
5263 GParnt
: constant Node_Id
:= Parent
(Parnt
);
5265 procedure Bad_Null_Parameter
(Msg
: String);
5266 -- Used if bad Null parameter attribute node is found. Issues
5267 -- given error message, and also sets the type to Any_Type to
5268 -- avoid blowups later on from dealing with a junk node.
5270 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
5271 -- Called to check that Proc_Ent is imported subprogram
5273 ------------------------
5274 -- Bad_Null_Parameter --
5275 ------------------------
5277 procedure Bad_Null_Parameter
(Msg
: String) is
5279 Error_Msg_N
(Msg
, N
);
5280 Set_Etype
(N
, Any_Type
);
5281 end Bad_Null_Parameter
;
5283 ----------------------
5284 -- Must_Be_Imported --
5285 ----------------------
5287 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
5288 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
5291 -- Ignore check if procedure not frozen yet (we will get
5292 -- another chance when the default parameter is reanalyzed)
5294 if not Is_Frozen
(Pent
) then
5297 elsif not Is_Imported
(Pent
) then
5299 ("Null_Parameter can only be used with imported subprogram");
5304 end Must_Be_Imported
;
5306 -- Start of processing for Null_Parameter
5311 Set_Etype
(N
, P_Type
);
5313 -- Case of attribute used as default expression
5315 if Nkind
(Parnt
) = N_Parameter_Specification
then
5316 Must_Be_Imported
(Defining_Entity
(GParnt
));
5318 -- Case of attribute used as actual for subprogram (positional)
5320 elsif Nkind
(Parnt
) in N_Subprogram_Call
5321 and then Is_Entity_Name
(Name
(Parnt
))
5323 Must_Be_Imported
(Entity
(Name
(Parnt
)));
5325 -- Case of attribute used as actual for subprogram (named)
5327 elsif Nkind
(Parnt
) = N_Parameter_Association
5328 and then Nkind
(GParnt
) in N_Subprogram_Call
5329 and then Is_Entity_Name
(Name
(GParnt
))
5331 Must_Be_Imported
(Entity
(Name
(GParnt
)));
5333 -- Not an allowed case
5337 ("Null_Parameter must be actual or default parameter");
5345 -- Shares processing with Machine_Size attribute
5351 when Attribute_Old
=> Old
: declare
5352 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
5353 -- Inspect the contents of the prefix and detect illegal uses of a
5354 -- nested 'Old, attribute 'Result or a use of an entity declared in
5355 -- the related postcondition expression. Subp_Id is the subprogram to
5356 -- which the related postcondition applies.
5358 --------------------------------
5359 -- Check_References_In_Prefix --
5360 --------------------------------
5362 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
5363 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
5364 -- Detect attribute 'Old, attribute 'Result of a use of an entity
5365 -- and perform the appropriate semantic check.
5367 ---------------------
5368 -- Check_Reference --
5369 ---------------------
5371 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
5373 -- Attributes 'Old and 'Result cannot appear in the prefix of
5374 -- another attribute 'Old.
5376 if Nkind
(Nod
) = N_Attribute_Reference
5377 and then Attribute_Name
(Nod
) in Name_Old | Name_Result
5379 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
5380 Error_Msg_Name_2
:= Name_Old
;
5382 ("attribute % cannot appear in the prefix of attribute %",
5386 -- Entities mentioned within the prefix of attribute 'Old must
5387 -- be global to the related postcondition. If this is not the
5388 -- case, then the scope of the local entity is nested within
5389 -- that of the subprogram. Moreover, we need to know whether
5390 -- Entity (Nod) occurs in the tree rooted at the prefix to
5391 -- ensure the entity is not declared within then prefix itself.
5393 elsif Is_Entity_Name
(Nod
)
5394 and then Present
(Entity
(Nod
))
5395 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
5396 and then not In_Subtree
(Entity
(Nod
), P
)
5399 ("prefix of attribute % cannot reference local entities",
5402 -- Otherwise keep inspecting the prefix
5407 end Check_Reference
;
5409 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
5411 -- Start of processing for Check_References_In_Prefix
5414 Check_References
(P
);
5415 end Check_References_In_Prefix
;
5420 Pref_Id
: Entity_Id
;
5421 Pref_Typ
: Entity_Id
;
5422 Spec_Id
: Entity_Id
;
5424 -- Start of processing for Old
5427 -- The attribute reference is a primary. If any expressions follow,
5428 -- then the attribute reference is an indexable object. Transform the
5429 -- attribute into an indexed component and analyze it.
5431 if Present
(E1
) then
5433 Make_Indexed_Component
(Loc
,
5435 Make_Attribute_Reference
(Loc
,
5436 Prefix
=> Relocate_Node
(P
),
5437 Attribute_Name
=> Name_Old
),
5438 Expressions
=> Expressions
(N
)));
5443 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5445 -- The aspect or pragma where attribute 'Old resides should be
5446 -- associated with a subprogram declaration or a body. If this is not
5447 -- the case, then the aspect or pragma is illegal. Return as analysis
5448 -- cannot be carried out.
5450 -- The exception to this rule is when generating C since in this case
5451 -- postconditions are inlined.
5454 and then Modify_Tree_For_C
5455 and then In_Inlined_Body
5457 Spec_Id
:= Entity
(P
);
5459 elsif not Legal
then
5463 -- The prefix must be preanalyzed as the full analysis will take
5464 -- place during expansion.
5466 Preanalyze_And_Resolve
(P
);
5468 -- Ensure that the prefix does not contain attributes 'Old or 'Result
5470 Check_References_In_Prefix
(Spec_Id
);
5472 -- Set the type of the attribute now to prevent cascaded errors
5474 Pref_Typ
:= Etype
(P
);
5475 Set_Etype
(N
, Pref_Typ
);
5479 if Is_Limited_Type
(Pref_Typ
) then
5480 Error_Attr
("attribute % cannot apply to limited objects", P
);
5483 -- The prefix is a simple name
5485 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
5486 Pref_Id
:= Entity
(P
);
5488 -- Emit a warning when the prefix is a constant. Note that the use
5489 -- of Error_Attr would reset the type of N to Any_Type even though
5490 -- this is a warning. Use Error_Msg_XXX instead.
5492 if Is_Constant_Object
(Pref_Id
) then
5493 Error_Msg_Name_1
:= Name_Old
;
5495 ("??attribute % applied to constant has no effect", P
);
5498 -- Otherwise the prefix is not a simple name
5501 -- Ensure that the prefix of attribute 'Old is an entity when it
5502 -- is potentially unevaluated (6.1.1 (27/3)). This rule is
5503 -- relaxed in Ada 2022 - this relaxation is reflected in the
5504 -- call (below) to Eligible_For_Conditional_Evaluation.
5506 if Is_Potentially_Unevaluated
(N
)
5507 and then not Statically_Names_Object
(P
)
5509 Old_Attr_Util
.Conditional_Evaluation
5510 .Eligible_For_Conditional_Evaluation
(N
)
5514 -- Detect a possible infinite recursion when the prefix denotes
5515 -- the related function.
5517 -- function Func (...) return ...
5518 -- with Post => Func'Old ...;
5520 -- The function may be specified in qualified form X.Y where X is
5521 -- a protected object and Y is a protected function. In that case
5522 -- ensure that the qualified form has an entity.
5524 elsif Nkind
(P
) = N_Function_Call
5525 and then Nkind
(Name
(P
)) in N_Has_Entity
5527 Pref_Id
:= Entity
(Name
(P
));
5529 if Ekind
(Spec_Id
) in E_Function | E_Generic_Function
5530 and then Pref_Id
= Spec_Id
5532 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5533 Error_Msg_N
("!possible infinite recursion<<", P
);
5534 Error_Msg_N
("\!??Storage_Error ]<<", P
);
5538 -- The prefix of attribute 'Old may refer to a component of a
5539 -- formal parameter. In this case its expansion may generate
5540 -- actual subtypes that are referenced in an inner context and
5541 -- that must be elaborated within the subprogram itself. If the
5542 -- prefix includes a function call, it may involve finalization
5543 -- actions that should be inserted when the attribute has been
5544 -- rewritten as a declaration. Create a declaration for the prefix
5545 -- and insert it at the start of the enclosing subprogram. This is
5546 -- an expansion activity that has to be performed now to prevent
5547 -- out-of-order issues.
5549 -- This expansion is both harmful and not needed in SPARK mode,
5550 -- since the formal verification back end relies on the types of
5551 -- nodes (hence is not robust w.r.t. a change to base type here),
5552 -- and does not suffer from the out-of-order issue described
5553 -- above. Thus, this expansion is skipped in SPARK mode.
5555 -- The expansion is not relevant for discrete types, which will
5556 -- not generate extra declarations, and where use of the base type
5557 -- may lead to spurious errors if context is a case.
5559 if not GNATprove_Mode
then
5560 if not Is_Discrete_Type
(Pref_Typ
) then
5561 Pref_Typ
:= Base_Type
(Pref_Typ
);
5564 Set_Etype
(N
, Pref_Typ
);
5565 Set_Etype
(P
, Pref_Typ
);
5567 Analyze_Dimension
(N
);
5577 when Attribute_Output
=>
5579 Check_Stream_Attribute
(TSS_Stream_Output
);
5580 Set_Etype
(N
, Standard_Void_Type
);
5581 Resolve
(N
, Standard_Void_Type
);
5587 when Attribute_Partition_ID
=>
5590 if P_Type
/= Any_Type
then
5591 if not Is_Library_Level_Entity
(Entity
(P
)) then
5593 ("prefix of % attribute must be library-level entity");
5595 -- The defining entity of prefix should not be declared inside a
5596 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5598 elsif Is_Entity_Name
(P
)
5599 and then Is_Pure
(Entity
(P
))
5601 Error_Attr_P
("prefix of% attribute must not be declared pure");
5605 Set_Etype
(N
, Universal_Integer
);
5607 -------------------------
5608 -- Passed_By_Reference --
5609 -------------------------
5611 when Attribute_Passed_By_Reference
=>
5614 Check_Not_Incomplete_Type
;
5615 Set_Etype
(N
, Standard_Boolean
);
5621 when Attribute_Pool_Address
=>
5623 Set_Etype
(N
, RTE
(RE_Address
));
5629 when Attribute_Pos
=>
5630 Check_Discrete_Type
;
5632 Resolve
(E1
, P_Base_Type
);
5633 Set_Etype
(N
, Universal_Integer
);
5639 -- Shares processing with First_Bit attribute
5650 Resolve
(E1
, P_Base_Type
);
5651 Set_Etype
(N
, P_Base_Type
);
5653 -- Since Pred/Succ work on the base type, we normally do no check for
5654 -- the floating-point case, since the base type is unconstrained. But
5655 -- we make an exception in Check_Float_Overflow mode.
5657 if Is_Floating_Point_Type
(P_Type
) then
5658 if not Range_Checks_Suppressed
(P_Base_Type
) then
5659 Set_Do_Range_Check
(E1
);
5662 -- If not modular type, test for overflow check required
5665 if not Is_Modular_Integer_Type
(P_Type
)
5666 and then not Range_Checks_Suppressed
(P_Base_Type
)
5668 Enable_Range_Check
(E1
);
5672 ----------------------------------
5673 -- Preelaborable_Initialization --
5674 ----------------------------------
5676 when Attribute_Preelaborable_Initialization
=>
5680 -- If we're in an instance, we know that the legality of the
5681 -- attribute prefix type was already checked in the generic.
5683 if not In_Instance
then
5685 -- If the prefix type is a generic formal type, then it must be
5686 -- either a formal private type or a formal derived type.
5688 if Is_Generic_Type
(P_Type
) then
5689 if not Is_Private_Type
(P_Type
)
5690 and then not Is_Derived_Type
(P_Type
)
5692 Error_Attr_P
("formal type prefix of % attribute must be "
5693 & "formal private or formal derived type");
5696 -- Otherwise, the prefix type must be a nonformal composite
5697 -- type declared within the visible part of a package or
5700 elsif not Is_Composite_Type
(P_Type
)
5701 or else not Original_View_In_Visible_Part
(P_Type
)
5704 ("prefix of % attribute must be composite type declared "
5705 & "in visible part of a package or generic package");
5709 Set_Etype
(N
, Standard_Boolean
);
5715 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5717 when Attribute_Priority
=>
5718 if Ada_Version
< Ada_2005
then
5719 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5724 Check_Restriction
(No_Dynamic_Priorities
, N
);
5726 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5728 if Is_Protected_Type
(Etype
(P
))
5729 or else (Is_Access_Type
(Etype
(P
))
5730 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5734 Error_Attr_P
("prefix of % attribute must be a protected object");
5737 Set_Etype
(N
, Standard_Integer
);
5739 -- Must be called from within a protected procedure or entry of the
5740 -- protected object.
5747 while S
/= Etype
(P
)
5748 and then S
/= Standard_Standard
5753 if S
= Standard_Standard
then
5754 Error_Attr
("the attribute % is only allowed inside protected "
5759 Validate_Non_Static_Attribute_Function_Call
;
5765 when Attribute_Put_Image
=>
5767 Check_Put_Image_Attribute
;
5768 Set_Etype
(N
, Standard_Void_Type
);
5769 Resolve
(N
, Standard_Void_Type
);
5775 when Attribute_Range
=>
5776 Check_Array_Or_Scalar_Type
;
5777 Bad_Attribute_For_Predicate
;
5779 if Ada_Version
= Ada_83
5780 and then Is_Scalar_Type
(P_Type
)
5781 and then Comes_From_Source
(N
)
5784 ("(Ada 83) % attribute not allowed for scalar type", P
);
5791 when Attribute_Result
=> Result
: declare
5792 function Denote_Same_Function
5793 (Pref_Id
: Entity_Id
;
5794 Spec_Id
: Entity_Id
) return Boolean;
5795 -- Determine whether the entity of the prefix Pref_Id denotes the
5796 -- same entity as that of the related subprogram Spec_Id.
5798 --------------------------
5799 -- Denote_Same_Function --
5800 --------------------------
5802 function Denote_Same_Function
5803 (Pref_Id
: Entity_Id
;
5804 Spec_Id
: Entity_Id
) return Boolean
5806 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5807 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5810 -- The prefix denotes the related subprogram
5812 if Pref_Id
= Spec_Id
then
5815 -- Account for a special case when attribute 'Result appears in
5816 -- the postcondition of a generic function.
5819 -- function Gen_Func return ...
5820 -- with Post => Gen_Func'Result ...;
5822 -- When the generic function is instantiated, the Chars field of
5823 -- the instantiated prefix still denotes the name of the generic
5824 -- function. Note that any preemptive transformation is impossible
5825 -- without a proper analysis. The structure of the wrapper package
5828 -- package Anon_Gen_Pack is
5829 -- <subtypes and renamings>
5830 -- function Subp_Decl return ...; -- (!)
5831 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5832 -- function Gen_Func ... renames Subp_Decl;
5833 -- end Anon_Gen_Pack;
5835 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5836 and then Present
(Generic_Parent
(Subp_Spec
))
5837 and then Ekind
(Pref_Id
) in E_Generic_Function | E_Function
5839 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5842 elsif Present
(Alias
(Pref_Id
))
5843 and then Alias
(Pref_Id
) = Spec_Id
5848 -- Account for a special case where a primitive of a tagged type
5849 -- inherits a class-wide postcondition from a parent type. In this
5850 -- case the prefix of attribute 'Result denotes the overriding
5853 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5856 -- When a qualified name is used for the prefix, homonyms may come
5857 -- before the current function in the homonym chain.
5859 elsif Has_Homonym
(Pref_Id
) then
5860 return Denote_Same_Function
(Homonym
(Pref_Id
), Spec_Id
);
5863 -- Otherwise the prefix does not denote the related subprogram
5866 end Denote_Same_Function
;
5870 In_Inlined_C_Postcondition
: constant Boolean :=
5872 and then In_Inlined_Body
;
5875 Pref_Id
: Entity_Id
;
5876 Spec_Id
: Entity_Id
;
5878 -- Start of processing for Result
5881 -- The attribute reference is a primary. If any expressions follow,
5882 -- then the attribute reference is an indexable object. Transform the
5883 -- attribute into an indexed component and analyze it.
5885 if Present
(E1
) then
5887 Make_Indexed_Component
(Loc
,
5889 Make_Attribute_Reference
(Loc
,
5890 Prefix
=> Relocate_Node
(P
),
5891 Attribute_Name
=> Name_Result
),
5892 Expressions
=> Expressions
(N
)));
5897 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5899 -- The aspect or pragma where attribute 'Result resides should be
5900 -- associated with a subprogram declaration or a body. If this is not
5901 -- the case, then the aspect or pragma is illegal. Return as analysis
5902 -- cannot be carried out.
5904 -- The exception to this rule is when generating C since in this case
5905 -- postconditions are inlined.
5907 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5908 Spec_Id
:= Entity
(P
);
5910 elsif not Legal
then
5911 Error_Attr
("prefix of % attribute must be a function", P
);
5914 -- Attribute 'Result is part of postconditions expansion. There is
5915 -- no need to perform the semantic checks below as they were already
5916 -- verified when the attribute was analyzed in its original context.
5917 -- Instead, rewrite the attribute as a reference to formal parameter
5918 -- _Result of the _Wrapped_Statements procedure.
5920 if Chars
(Spec_Id
) = Name_uWrapped_Statements
5922 (In_Inlined_C_Postcondition
5923 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5925 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5927 -- The type of formal parameter _Result is that of the function
5928 -- encapsulating the _Postconditions procedure. Resolution must
5929 -- be carried out against the function return type.
5931 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
5933 -- Otherwise attribute 'Result appears in its original context and
5934 -- all semantic checks should be carried out.
5937 -- Verify the legality of the prefix. It must denotes the entity
5938 -- of the related [generic] function.
5940 if Is_Entity_Name
(P
) then
5941 Pref_Id
:= Entity
(P
);
5943 -- Either both the prefix and the annotated spec must be
5944 -- generic functions, or they both must be nongeneric
5945 -- functions, or the prefix must be generic and the spec
5946 -- must be nongeneric (i.e. it must denote an instance).
5948 if (Ekind
(Pref_Id
) in E_Function | E_Generic_Function
5949 and then Ekind
(Pref_Id
) = Ekind
(Spec_Id
))
5951 (Ekind
(Pref_Id
) = E_Generic_Function
5952 and then Ekind
(Spec_Id
) = E_Function
)
5954 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
5956 -- Correct the prefix of the attribute when the context
5957 -- is a generic function.
5959 if Pref_Id
/= Spec_Id
then
5960 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
5964 Set_Etype
(N
, Etype
(Spec_Id
));
5966 -- Otherwise the prefix denotes some unrelated function
5969 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5971 ("incorrect prefix for attribute %, expected %", P
);
5974 -- Otherwise the prefix denotes some other form of subprogram
5979 ("attribute % can only appear in postcondition of "
5983 -- Otherwise the prefix is illegal
5986 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5987 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
5996 when Attribute_Range_Length
=>
5998 Check_Discrete_Type
;
5999 Set_Etype
(N
, Universal_Integer
);
6005 when Attribute_Reduce
=>
6007 Error_Msg_Ada_2022_Feature
("Reduce attribute", Sloc
(N
));
6010 Stream
: constant Node_Id
:= Prefix
(N
);
6013 if Nkind
(Stream
) /= N_Aggregate
then
6014 -- Prefix is a name, as for other attributes.
6016 -- If the object is a function we asume that it is not
6017 -- overloaded. AI12-242 does not suggest a name resolution
6018 -- rule for that case, but we can suppose that the expected
6019 -- type of the reduction is the expected type of the component
6022 Analyze_And_Resolve
(Stream
);
6023 Typ
:= Etype
(Stream
);
6025 -- Verify that prefix can be iterated upon.
6027 if Is_Array_Type
(Typ
)
6028 or else Has_Aspect
(Typ
, Aspect_Default_Iterator
)
6029 or else Has_Aspect
(Typ
, Aspect_Iterable
)
6034 ("cannot apply Reduce to object of type&", N
, Typ
);
6037 elsif Present
(Expressions
(Stream
))
6038 or else No
(Component_Associations
(Stream
))
6039 or else Nkind
(First
(Component_Associations
(Stream
))) /=
6040 N_Iterated_Component_Association
6043 ("prefix of Reduce must be an iterated component", N
);
6048 Set_Etype
(N
, Etype
(E2
));
6055 when Attribute_Read
=>
6057 Check_Stream_Attribute
(TSS_Stream_Read
);
6058 Set_Etype
(N
, Standard_Void_Type
);
6059 Resolve
(N
, Standard_Void_Type
);
6060 Note_Possible_Modification
(E2
, Sure
=> True);
6066 when Attribute_Ref
=>
6069 if Nkind
(P
) /= N_Expanded_Name
6070 or else not Is_RTE
(P_Type
, RE_Address
)
6072 Error_Attr_P
("prefix of % attribute must be System.Address");
6075 Analyze_And_Resolve
(E1
, Any_Integer
);
6076 Set_Etype
(N
, RTE
(RE_Address
));
6082 -- Shares processing with Adjacent attribute
6084 ---------------------
6085 -- Restriction_Set --
6086 ---------------------
6088 when Attribute_Restriction_Set
=> Restriction_Set
: declare
6091 Unam
: Unit_Name_Type
;
6095 Check_System_Prefix
;
6097 -- No_Dependence case
6099 if Nkind
(E1
) = N_Parameter_Association
then
6100 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
6101 U
:= Explicit_Actual_Parameter
(E1
);
6103 if not OK_No_Dependence_Unit_Name
(U
) then
6104 Set_Boolean_Result
(N
, False);
6108 -- See if there is an entry already in the table. That's the
6109 -- case in which we can return True.
6111 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
6112 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
6113 and then No_Dependences
.Table
(J
).Warn
= False
6115 Set_Boolean_Result
(N
, True);
6120 -- If not in the No_Dependence table, result is False
6122 Set_Boolean_Result
(N
, False);
6124 -- In this case, we must ensure that the binder will reject any
6125 -- other unit in the partition that sets No_Dependence for this
6126 -- unit. We do that by making an entry in the special table kept
6127 -- for this purpose (if the entry is not there already).
6129 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
6131 for J
in Restriction_Set_Dependences
.First
..
6132 Restriction_Set_Dependences
.Last
6134 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
6139 Restriction_Set_Dependences
.Append
(Unam
);
6141 -- Normal restriction case
6144 if Nkind
(E1
) /= N_Identifier
then
6145 Set_Boolean_Result
(N
, False);
6146 Error_Attr
("attribute % requires restriction identifier", E1
);
6149 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
6151 if R
= Not_A_Restriction_Id
then
6152 Set_Boolean_Result
(N
, False);
6153 Error_Msg_Node_1
:= E1
;
6154 Error_Attr
("invalid restriction identifier &", E1
);
6156 elsif R
not in Partition_Boolean_Restrictions
then
6157 Set_Boolean_Result
(N
, False);
6158 Error_Msg_Node_1
:= E1
;
6160 ("& is not a boolean partition-wide restriction", E1
);
6163 if Restriction_Active
(R
) then
6164 Set_Boolean_Result
(N
, True);
6166 Check_Restriction
(R
, N
);
6167 Set_Boolean_Result
(N
, False);
6171 end Restriction_Set
;
6177 when Attribute_Round
=>
6179 Check_Decimal_Fixed_Point_Type
;
6180 Set_Etype
(N
, P_Base_Type
);
6182 -- Because the context is universal_real (3.5.10(12)) it is a
6183 -- legal context for a universal fixed expression. This is the
6184 -- only attribute whose functional description involves U_R.
6186 if Etype
(E1
) = Universal_Fixed
then
6188 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
6189 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
6190 Expression
=> Relocate_Node
(E1
));
6198 Resolve
(E1
, Any_Real
);
6204 -- Shares processing with Ceiling attribute
6210 -- Shares processing with Emax attribute
6216 -- Shares processing with Epsilon attribute
6222 -- Shares processing with Large attribute
6228 -- Shares processing with Epsilon attribute
6234 -- Shares processing with Large attribute
6236 --------------------------
6237 -- Scalar_Storage_Order --
6238 --------------------------
6240 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
6241 Ent
: Entity_Id
:= Empty
;
6247 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
6249 -- The attribute applies to generic private types (in which case
6250 -- the legality rule is applied in the instance) as well as to
6251 -- composite types. For noncomposite types it always returns the
6252 -- default bit order for the target.
6253 -- Allowing formal private types was originally introduced in
6254 -- GNAT_Mode only, to compile instances of Sequential_IO, but
6255 -- users find it more generally useful in generic units.
6257 if not (Is_Generic_Type
(P_Type
) and then Is_Private_Type
(P_Type
))
6258 and then not In_Instance
6261 ("prefix of % attribute must be record or array type");
6263 elsif not Is_Generic_Type
(P_Type
) then
6264 if Bytes_Big_Endian
then
6265 Ent
:= RTE
(RE_High_Order_First
);
6267 Ent
:= RTE
(RE_Low_Order_First
);
6271 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
6272 Ent
:= RTE
(RE_High_Order_First
);
6275 Ent
:= RTE
(RE_Low_Order_First
);
6278 if Present
(Ent
) then
6279 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
6282 Set_Etype
(N
, RTE
(RE_Bit_Order
));
6285 -- Reset incorrect indication of staticness
6287 Set_Is_Static_Expression
(N
, False);
6288 end Scalar_Storage_Order
;
6294 when Attribute_Scale
=>
6296 Check_Decimal_Fixed_Point_Type
;
6297 Set_Etype
(N
, Universal_Integer
);
6303 -- Shares processing with Compose attribute
6309 -- Shares processing with Denorm attribute
6316 | Attribute_VADS_Size
6320 -- If prefix is parameterless function call, rewrite and resolve
6323 if Is_Entity_Name
(P
)
6324 and then Ekind
(Entity
(P
)) = E_Function
6328 -- Similar processing for a protected function call
6330 elsif Nkind
(P
) = N_Selected_Component
6331 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
6336 if Is_Object_Reference
(P
) then
6337 Check_Object_Reference
(P
);
6339 elsif Is_Entity_Name
(P
)
6340 and then (Is_Type
(Entity
(P
))
6341 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6345 elsif Nkind
(P
) = N_Type_Conversion
6346 and then not Comes_From_Source
(P
)
6350 -- Some other compilers allow dubious use of X'???'Size
6352 elsif Relaxed_RM_Semantics
6353 and then Nkind
(P
) = N_Attribute_Reference
6358 Error_Attr_P
("invalid prefix for % attribute");
6361 Check_Not_Incomplete_Type
;
6363 Set_Etype
(N
, Universal_Integer
);
6365 -- If we are processing pragmas Compile_Time_Warning and Compile_
6366 -- Time_Errors after the back end has been called and this occurrence
6367 -- of 'Size is known at compile time then it is safe to perform this
6368 -- evaluation. Needed to perform the static evaluation of the full
6369 -- boolean expression of these pragmas. Note that Known_RM_Size is
6370 -- sometimes True when Size_Known_At_Compile_Time is False, when the
6371 -- back end has computed it.
6373 if In_Compile_Time_Warning_Or_Error
6374 and then Is_Entity_Name
(P
)
6375 and then (Is_Type
(Entity
(P
))
6376 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6377 and then (Known_RM_Size
(Entity
(P
))
6378 or else Size_Known_At_Compile_Time
(Entity
(P
)))
6384 if Known_Static_RM_Size
(Entity
(P
)) then
6385 Siz
:= RM_Size
(Entity
(P
));
6387 Siz
:= Esize
(Entity
(P
));
6390 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Siz
));
6399 -- Shares processing with Large attribute
6401 ---------------------------------------
6402 -- Small_Denominator/Small_Numerator --
6403 ---------------------------------------
6405 when Attribute_Small_Denominator
6406 | Attribute_Small_Numerator
6408 Check_Fixed_Point_Type_0
;
6409 Set_Etype
(N
, Universal_Integer
);
6415 when Attribute_Storage_Pool
6416 | Attribute_Simple_Storage_Pool
6420 if Is_Access_Type
(P_Type
) then
6421 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6423 ("cannot use % attribute for access-to-subprogram type");
6426 -- Set appropriate entity
6428 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
6429 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
6431 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
6434 if Attr_Id
= Attribute_Storage_Pool
then
6435 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6436 Name_Simple_Storage_Pool_Type
))
6438 Error_Msg_Name_1
:= Aname
;
6439 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6441 ("cannot use % attribute for type with simple storage "
6443 Error_Msg_N
("\Program_Error [<<", N
);
6446 (N
, Make_Raise_Program_Error
6447 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
6450 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6452 -- In the Simple_Storage_Pool case, verify that the pool entity is
6453 -- actually of a simple storage pool type, and set the attribute's
6454 -- type to the pool object's type.
6457 if No
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6458 Name_Simple_Storage_Pool_Type
))
6461 ("cannot use % attribute for type without simple " &
6465 Set_Etype
(N
, Etype
(Entity
(N
)));
6468 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6469 -- Storage_Pool since this attribute is not defined for such
6470 -- types (RM E.2.2(17)).
6472 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6475 Error_Attr_P
("prefix of % attribute must be access type");
6482 when Attribute_Storage_Size
=>
6485 if Is_Task_Type
(P_Type
) then
6486 Set_Etype
(N
, Universal_Integer
);
6488 -- Use with tasks is an obsolescent feature
6490 Check_Restriction
(No_Obsolescent_Features
, P
);
6492 elsif Is_Access_Type
(P_Type
) then
6493 Set_Etype
(N
, Universal_Integer
);
6495 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6497 ("cannot use % attribute for access-to-subprogram type");
6500 if Is_Entity_Name
(P
)
6501 and then Is_Type
(Entity
(P
))
6505 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6506 -- Storage_Size since this attribute is not defined for
6507 -- such types (RM E.2.2(17)).
6509 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6511 -- The prefix is allowed to be an implicit dereference of an
6512 -- access value designating a task.
6519 Error_Attr_P
("prefix of % attribute must be access or task type");
6526 when Attribute_Storage_Unit
=>
6527 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
6533 when Attribute_Stream_Size
=>
6537 if Is_Entity_Name
(P
)
6538 and then Is_Elementary_Type
(Entity
(P
))
6540 Set_Etype
(N
, Universal_Integer
);
6542 Error_Attr_P
("invalid prefix for % attribute");
6549 when Attribute_Stub_Type
=>
6553 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
6555 -- For a real RACW [sub]type, use corresponding stub type
6557 if not Is_Generic_Type
(P_Type
) then
6560 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
6562 -- For a generic type (that has been marked as an RACW using the
6563 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
6564 -- type. Note that if the actual is not a remote access type, the
6565 -- instantiation will fail.
6568 -- Note: we go to the underlying type here because the view
6569 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
6573 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
6578 ("prefix of% attribute must be remote access-to-class-wide");
6585 -- Shares processing with Pred attribute
6587 --------------------------------
6588 -- System_Allocator_Alignment --
6589 --------------------------------
6591 when Attribute_System_Allocator_Alignment
=>
6592 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
6598 when Attribute_Tag
=>
6602 if not Is_Tagged_Type
(P_Type
) then
6603 Error_Attr_P
("prefix of % attribute must be tagged");
6605 -- Next test does not apply to generated code why not, and what does
6606 -- the illegal reference mean???
6608 elsif Is_Object_Reference
(P
)
6609 and then not Is_Class_Wide_Type
(P_Type
)
6610 and then Comes_From_Source
(N
)
6613 ("% attribute can only be applied to objects " &
6614 "of class-wide type");
6617 -- The prefix cannot be an incomplete type. However, references to
6618 -- 'Tag can be generated when expanding interface conversions, and
6621 if Comes_From_Source
(N
) then
6622 Check_Not_Incomplete_Type
;
6624 -- 'Tag requires visibility on the corresponding package holding
6625 -- the tag, so record a reference here, to avoid spurious unused
6626 -- with_clause reported when compiling the main unit.
6628 if In_Extended_Main_Source_Unit
(Current_Scope
) then
6629 Set_Referenced
(P_Type
, True);
6630 Set_Referenced
(Scope
(P_Type
), True);
6634 -- Set appropriate type
6636 Set_Etype
(N
, RTE
(RE_Tag
));
6642 when Attribute_Target_Name
=> Target_Name
: declare
6643 TN
: constant String := Sdefault
.Target_Name
.all;
6647 Check_Standard_Prefix
;
6651 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6656 Make_String_Literal
(Loc
,
6657 Strval
=> TN
(TN
'First .. TL
)));
6658 Analyze_And_Resolve
(N
, Standard_String
);
6659 Set_Is_Static_Expression
(N
, True);
6666 -- Shares processing with Callable attribute
6672 when Attribute_To_Address
=> To_Address
: declare
6676 Check_System_Prefix
;
6678 Generate_Reference
(RTE
(RE_Address
), P
);
6679 Analyze_And_Resolve
(E1
, Any_Integer
);
6680 Set_Etype
(N
, RTE
(RE_Address
));
6681 Set_Is_Static_Expression
(N
, Is_Static_Expression
(E1
));
6683 -- OK static expression case, check range and set appropriate type
6685 if Is_OK_Static_Expression
(E1
) then
6686 Val
:= Expr_Value
(E1
);
6688 if Val
< -(Uint_2
** (System_Address_Size
- 1))
6690 Val
> Uint_2
** System_Address_Size
- 1
6692 Error_Attr
("address value out of range for % attribute", E1
);
6695 -- In most cases the expression is a numeric literal or some other
6696 -- address expression, but if it is a declared constant it may be
6697 -- of a compatible type that must be left on the node.
6699 if Is_Entity_Name
(E1
) then
6702 -- Set type to universal integer if negative
6705 Set_Etype
(E1
, Universal_Integer
);
6707 -- Otherwise set type to Unsigned_64 to accommodate large values
6710 Set_Etype
(E1
, Standard_Unsigned_64
);
6719 when Attribute_To_Any
=>
6721 Check_PolyORB_Attribute
;
6722 Set_Etype
(N
, RTE
(RE_Any
));
6728 -- Shares processing with Ceiling attribute
6734 when Attribute_Type_Class
=>
6737 Check_Not_Incomplete_Type
;
6738 Set_Etype
(N
, RTE
(RE_Type_Class
));
6744 when Attribute_TypeCode
=>
6746 Check_PolyORB_Attribute
;
6747 Set_Etype
(N
, RTE
(RE_TypeCode
));
6753 when Attribute_Type_Key
=> Type_Key
: declare
6754 Full_Name
: constant String_Id
:=
6755 Fully_Qualified_Name_String
(Entity
(P
));
6758 -- The computed signature for the type
6761 -- To simplify the handling of mutually recursive types, follow a
6762 -- single dereference link in a composite type.
6764 procedure Compute_Type_Key
(T
: Entity_Id
);
6765 -- Create a CRC integer from the declaration of the type. For a
6766 -- composite type, fold in the representation of its components in
6767 -- recursive fashion. We use directly the source representation of
6768 -- the types involved.
6770 ----------------------
6771 -- Compute_Type_Key --
6772 ----------------------
6774 procedure Compute_Type_Key
(T
: Entity_Id
) is
6775 Buffer
: Source_Buffer_Ptr
;
6779 SFI
: Source_File_Index
;
6781 procedure Process_One_Declaration
;
6782 -- Update CRC with the characters of one type declaration, or a
6783 -- representation pragma that applies to the type.
6785 -----------------------------
6786 -- Process_One_Declaration --
6787 -----------------------------
6789 procedure Process_One_Declaration
is
6791 -- Scan type declaration, skipping blanks
6793 for Ptr
in P_Min
.. P_Max
loop
6794 if Buffer
(Ptr
) /= ' ' then
6795 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6798 end Process_One_Declaration
;
6800 -- Start of processing for Compute_Type_Key
6803 if Is_Itype
(T
) then
6807 -- If the type is declared in Standard, there is no source, so
6808 -- just use its name.
6810 if Scope
(T
) = Standard_Standard
then
6812 Name
: constant String := Get_Name_String
(Chars
(T
));
6814 for J
in Name
'Range loop
6815 System
.CRC32
.Update
(CRC
, Name
(J
));
6822 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6823 SFI
:= Get_Source_File_Index
(P_Min
);
6824 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6825 Buffer
:= Source_Text
(SFI
);
6827 Process_One_Declaration
;
6829 -- Recurse on relevant component types
6831 if Is_Array_Type
(T
) then
6832 Compute_Type_Key
(Component_Type
(T
));
6834 elsif Is_Access_Type
(T
) then
6837 Compute_Type_Key
(Designated_Type
(T
));
6840 elsif Is_Derived_Type
(T
) then
6841 Compute_Type_Key
(Etype
(T
));
6843 elsif Is_Record_Type
(T
) then
6847 Comp
:= First_Component
(T
);
6848 while Present
(Comp
) loop
6849 Compute_Type_Key
(Etype
(Comp
));
6850 Next_Component
(Comp
);
6855 if Is_First_Subtype
(T
) then
6857 -- Fold in representation aspects for the type, which appear in
6858 -- the same source buffer. If the representation aspects are in
6859 -- a different source file, then skip them; they apply to some
6860 -- other type, perhaps one we're derived from.
6862 Rep
:= First_Rep_Item
(T
);
6864 while Present
(Rep
) loop
6865 if Comes_From_Source
(Rep
) then
6866 Sloc_Range
(Rep
, P_Min
, P_Max
);
6868 if SFI
= Get_Source_File_Index
(P_Min
) then
6869 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6870 Process_One_Declaration
;
6874 Next_Rep_Item
(Rep
);
6877 end Compute_Type_Key
;
6879 -- Start of processing for Type_Key
6888 -- Copy all characters in Full_Name but the trailing NUL
6890 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6891 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6894 -- Compute CRC and convert it to string one character at a time, so
6895 -- as not to use Image within the compiler.
6898 Compute_Type_Key
(Entity
(P
));
6900 if not Is_Frozen
(Entity
(P
))
6901 and then not Is_Generic_Type
(Entity
(P
))
6902 and then not Is_Generic_Actual_Type
(Entity
(P
))
6904 Error_Msg_N
("premature usage of Type_Key?", N
);
6908 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
6912 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
6913 Analyze_And_Resolve
(N
, Standard_String
);
6916 -----------------------
6917 -- Unbiased_Rounding --
6918 -----------------------
6920 -- Shares processing with Ceiling attribute
6922 ----------------------
6923 -- Unchecked_Access --
6924 ----------------------
6926 when Attribute_Unchecked_Access
=>
6927 if Comes_From_Source
(N
) then
6928 Check_Restriction
(No_Unchecked_Access
, N
);
6931 Analyze_Access_Attribute
;
6932 Check_Not_Incomplete_Type
;
6934 -------------------------
6935 -- Unconstrained_Array --
6936 -------------------------
6938 when Attribute_Unconstrained_Array
=>
6941 Check_Not_Incomplete_Type
;
6942 Set_Etype
(N
, Standard_Boolean
);
6943 Set_Is_Static_Expression
(N
, True);
6945 ------------------------------
6946 -- Universal_Literal_String --
6947 ------------------------------
6949 -- This is a GNAT specific attribute whose prefix must be a named
6950 -- number where the expression is either a single numeric literal,
6951 -- or a numeric literal immediately preceded by a minus sign. The
6952 -- result is equivalent to a string literal containing the text of
6953 -- the literal as it appeared in the source program with a possible
6954 -- leading minus sign.
6956 when Attribute_Universal_Literal_String
=>
6959 if not Is_Entity_Name
(P
)
6960 or else not Is_Named_Number
(Entity
(P
))
6962 Error_Attr_P
("prefix for % attribute must be named number");
6969 Src
: Source_Buffer_Ptr
;
6972 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6974 if Nkind
(Expr
) = N_Op_Minus
then
6976 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6981 if Nkind
(Expr
) not in N_Integer_Literal | N_Real_Literal
then
6983 ("named number for % attribute must be simple literal", N
);
6986 -- Build string literal corresponding to source literal text
6991 Store_String_Char
(Get_Char_Code
('-'));
6995 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6997 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6998 Store_String_Char
(Get_Char_Code
(Src
(S
)));
7002 -- Now we rewrite the attribute with the string literal
7005 Make_String_Literal
(Loc
, End_String
));
7007 Set_Is_Static_Expression
(N
, True);
7011 -------------------------
7012 -- Unrestricted_Access --
7013 -------------------------
7015 -- This is a GNAT specific attribute which is like Access except that
7016 -- all scope checks and checks for aliased views are omitted. It is
7017 -- documented as being equivalent to the use of the Address attribute
7018 -- followed by an unchecked conversion to the target access type.
7020 when Attribute_Unrestricted_Access
=>
7022 -- If from source, deal with relevant restrictions
7024 if Comes_From_Source
(N
) then
7025 Check_Restriction
(No_Unchecked_Access
, N
);
7027 if Nkind
(P
) in N_Has_Entity
7028 and then Present
(Entity
(P
))
7029 and then Is_Object
(Entity
(P
))
7031 Check_Restriction
(No_Implicit_Aliasing
, N
);
7035 if Is_Entity_Name
(P
) then
7036 Set_Address_Taken
(Entity
(P
));
7039 -- It might seem reasonable to call Address_Checks here to apply the
7040 -- same set of semantic checks that we enforce for 'Address (after
7041 -- all we document Unrestricted_Access as being equivalent to the
7042 -- use of Address followed by an Unchecked_Conversion). However, if
7043 -- we do enable these checks, we get multiple failures in both the
7044 -- compiler run-time and in our regression test suite, so we leave
7045 -- out these checks for now. To be investigated further some time???
7049 -- Now complete analysis using common access processing
7051 Analyze_Access_Attribute
;
7057 when Attribute_Update
=> Update
: declare
7058 Common_Typ
: Entity_Id
;
7059 -- The common type of a multiple component update for a record
7061 Comps
: Elist_Id
:= No_Elist
;
7062 -- A list used in the resolution of a record update. It contains the
7063 -- entities of all record components processed so far.
7065 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
7066 -- Analyze and resolve array_component_association Assoc against the
7067 -- index of array type P_Type.
7069 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
7070 -- Analyze and resolve record_component_association Comp against
7071 -- record type P_Type.
7073 ------------------------------------
7074 -- Analyze_Array_Component_Update --
7075 ------------------------------------
7077 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
7081 Index_Typ
: Entity_Id
;
7085 -- The current association contains a sequence of indexes denoting
7086 -- an element of a multidimensional array:
7088 -- (Index_1, ..., Index_N)
7090 -- Examine each individual index and resolve it against the proper
7091 -- index type of the array.
7093 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
7094 Expr
:= First
(Choices
(Assoc
));
7095 while Present
(Expr
) loop
7097 -- The use of others is illegal (SPARK RM 4.4.1(12))
7099 if Nkind
(Expr
) = N_Others_Choice
then
7101 ("OTHERS choice not allowed in attribute %", Expr
);
7103 -- Otherwise analyze and resolve all indexes
7106 Index
:= First
(Expressions
(Expr
));
7107 Index_Typ
:= First_Index
(P_Type
);
7108 while Present
(Index
) and then Present
(Index_Typ
) loop
7109 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7111 Next_Index
(Index_Typ
);
7114 -- Detect a case where the association either lacks an
7115 -- index or contains an extra index.
7117 if Present
(Index
) or else Present
(Index_Typ
) then
7119 ("dimension mismatch in index list", Assoc
);
7126 -- The current association denotes either a single component or a
7127 -- range of components of a one dimensional array:
7131 -- Resolve the index or its high and low bounds (if range) against
7132 -- the proper index type of the array.
7135 Index
:= First
(Choices
(Assoc
));
7136 Index_Typ
:= First_Index
(P_Type
);
7138 if Present
(Next_Index
(Index_Typ
)) then
7139 Error_Msg_N
("too few subscripts in array reference", Assoc
);
7142 while Present
(Index
) loop
7144 -- The use of others is illegal (SPARK RM 4.4.1(12))
7146 if Nkind
(Index
) = N_Others_Choice
then
7148 ("OTHERS choice not allowed in attribute %", Index
);
7150 -- The index denotes a range of elements
7152 elsif Nkind
(Index
) = N_Range
then
7153 Low
:= Low_Bound
(Index
);
7154 High
:= High_Bound
(Index
);
7156 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
7157 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
7159 -- Otherwise the index denotes a single element
7162 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7168 end Analyze_Array_Component_Update
;
7170 -------------------------------------
7171 -- Analyze_Record_Component_Update --
7172 -------------------------------------
7174 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
7175 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
7176 Base_Typ
: Entity_Id
;
7177 Comp_Or_Discr
: Entity_Id
;
7180 -- Find the discriminant or component whose name corresponds to
7181 -- Comp. A simple character comparison is sufficient because all
7182 -- visible names within a record type are unique.
7184 Comp_Or_Discr
:= First_Entity
(P_Type
);
7185 while Present
(Comp_Or_Discr
) loop
7186 if Chars
(Comp_Or_Discr
) = Comp_Name
then
7188 -- Decorate the component reference by setting its entity
7189 -- and type for resolution purposes.
7191 Set_Entity
(Comp
, Comp_Or_Discr
);
7192 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
7196 Next_Entity
(Comp_Or_Discr
);
7199 -- Diagnose an illegal reference
7201 if Present
(Comp_Or_Discr
) then
7202 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
7204 ("attribute % may not modify record discriminants", Comp
);
7206 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
7207 if Contains
(Comps
, Comp_Or_Discr
) then
7208 Error_Msg_N
("component & already updated", Comp
);
7210 -- Mark this component as processed
7213 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
7217 -- The update aggregate mentions an entity that does not belong to
7221 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
7224 -- Verify the consistency of types when the current component is
7225 -- part of a multiple component update.
7227 -- Comp_1 | ... | Comp_N => <value>
7229 if Present
(Etype
(Comp
)) then
7230 Base_Typ
:= Base_Type
(Etype
(Comp
));
7232 -- Save the type of the first component reference as the
7233 -- remaning references (if any) must resolve to this type.
7235 if No
(Common_Typ
) then
7236 Common_Typ
:= Base_Typ
;
7238 elsif Base_Typ
/= Common_Typ
then
7240 ("components in choice list must have same type", Comp
);
7243 end Analyze_Record_Component_Update
;
7250 -- Start of processing for Update
7253 if Warn_On_Obsolescent_Feature
then
7254 Error_Msg_N
("?j?attribute Update is an obsolescent feature", N
);
7255 Error_Msg_N
("\?j?use a delta aggregate instead", N
);
7260 if not Is_Object_Reference
(P
) then
7261 Error_Attr_P
("prefix of attribute % must denote an object");
7263 elsif not Is_Array_Type
(P_Type
)
7264 and then not Is_Record_Type
(P_Type
)
7266 Error_Attr_P
("prefix of attribute % must be a record or array");
7268 elsif Is_Limited_View
(P_Type
) then
7269 Error_Attr
("prefix of attribute % cannot be limited", N
);
7271 elsif Nkind
(E1
) /= N_Aggregate
then
7272 Error_Attr
("attribute % requires component association list", N
);
7274 elsif Present
(Expressions
(E1
)) then
7275 Error_Attr
("attribute % requires named component associations",
7276 First
(Expressions
(E1
)));
7280 -- Inspect the update aggregate, looking at all the associations and
7281 -- choices. Perform the following checks:
7283 -- 1) Legality of "others" in all cases
7284 -- 2) Legality of <>
7285 -- 3) Component legality for arrays
7286 -- 4) Component legality for records
7288 -- The remaining checks are performed on the expanded attribute
7290 Assoc
:= First
(Component_Associations
(E1
));
7291 while Present
(Assoc
) loop
7293 -- The use of <> is illegal (SPARK RM 4.4.1(1))
7295 if Box_Present
(Assoc
) then
7297 ("default initialization not allowed in attribute %", Assoc
);
7299 -- Otherwise process the association
7302 Analyze
(Expression
(Assoc
));
7304 if Is_Array_Type
(P_Type
) then
7305 Analyze_Array_Component_Update
(Assoc
);
7307 elsif Is_Record_Type
(P_Type
) then
7309 -- Reset the common type used in a multiple component update
7310 -- as we are processing the contents of a new association.
7312 Common_Typ
:= Empty
;
7314 Comp
:= First
(Choices
(Assoc
));
7315 while Present
(Comp
) loop
7316 if Nkind
(Comp
) = N_Identifier
then
7317 Analyze_Record_Component_Update
(Comp
);
7319 -- The use of others is illegal (SPARK RM 4.4.1(5))
7321 elsif Nkind
(Comp
) = N_Others_Choice
then
7323 ("OTHERS choice not allowed in attribute %", Comp
);
7325 -- The name of a record component cannot appear in any
7330 ("name should be identifier or OTHERS", Comp
);
7341 -- The type of attribute 'Update is that of the prefix
7343 Set_Etype
(N
, P_Type
);
7345 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
7352 when Attribute_Val
=>
7354 Check_Discrete_Type
;
7356 -- Note, we need a range check in general, but we wait for the
7357 -- Resolve call to do this, since we want to let Eval_Attribute
7358 -- have a chance to find an static illegality first.
7360 Resolve
(E1
, Any_Integer
);
7361 Set_Etype
(N
, P_Base_Type
);
7367 when Attribute_Valid
=> Valid
: declare
7368 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
7373 -- Ignore check for object if we have a 'Valid reference generated
7374 -- by the expanded code, since in some cases valid checks can occur
7375 -- on items that are names, but are not objects (e.g. attributes).
7377 if Comes_From_Source
(N
) then
7378 Check_Object_Reference
(P
);
7380 if not Is_Scalar_Type
(P_Type
) then
7381 Error_Attr_P
("object for % attribute must be of scalar type");
7384 -- If the attribute appears within the subtype's own predicate
7385 -- function, then issue a warning that this will cause infinite
7388 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
7389 Error_Msg_N
("attribute Valid requires a predicate check??", N
);
7390 Error_Msg_N
("\and will result in infinite recursion??", N
);
7394 Set_Etype
(N
, Standard_Boolean
);
7401 when Attribute_Valid_Value
=>
7403 Check_Enumeration_Type
;
7404 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7405 Set_Etype
(N
, Standard_Boolean
);
7406 Validate_Non_Static_Attribute_Function_Call
;
7408 if P_Type
in Standard_Boolean
7409 | Standard_Character
7410 | Standard_Wide_Character
7411 | Standard_Wide_Wide_Character
7414 ("prefix of % attribute must not be a type in Standard");
7417 if Discard_Names
(First_Subtype
(P_Type
)) then
7419 ("prefix of % attribute must not have Discard_Names");
7426 when Attribute_Valid_Scalars
=> Valid_Scalars
: declare
7430 if Comes_From_Source
(N
) then
7431 Check_Object_Reference
(P
);
7433 -- Attribute 'Valid_Scalars is illegal on unchecked union types
7434 -- regardles of the privacy, because it is not always guaranteed
7435 -- that the components are retrievable based on whether the
7436 -- discriminants are inferable.
7438 if Has_Unchecked_Union
(Validated_View
(P_Type
)) then
7440 ("attribute % not allowed for Unchecked_Union type");
7442 -- Do not emit any diagnostics related to private types to avoid
7443 -- disclosing the structure of the type.
7445 elsif Is_Private_Type
(P_Type
) then
7447 -- Attribute 'Valid_Scalars is not supported on private tagged
7448 -- types due to a code generation issue. Is_Visible_Component
7449 -- does not allow for a component of a private tagged type to
7450 -- be successfully retrieved.
7451 -- ??? This attribute should simply ignore type privacy
7452 -- (see Validated_View). It should examine components of the
7453 -- tagged type extensions (if any) and recursively examine
7454 -- 'Valid_Scalars of the parent's type (if any).
7456 -- Do not use Error_Attr_P because this bypasses any subsequent
7457 -- processing and leaves the attribute with type Any_Type. This
7458 -- in turn prevents the proper expansion of the attribute into
7461 if Is_Tagged_Type
(P_Type
) then
7462 Error_Msg_Name_1
:= Aname
;
7463 Error_Msg_N
("??effects of attribute % are ignored", N
);
7466 -- Otherwise the type is not private
7469 if not Scalar_Part_Present
(P_Type
) then
7470 Error_Msg_Name_1
:= Aname
;
7472 ("??attribute % always True, no scalars to check", P
);
7473 Set_Boolean_Result
(N
, True);
7478 Set_Etype
(N
, Standard_Boolean
);
7485 when Attribute_Value
7486 | Attribute_Wide_Value
7487 | Attribute_Wide_Wide_Value
7491 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7493 -- Set Etype before resolving expression because expansion of
7494 -- expression may require enclosing type. Note that the type
7495 -- returned by 'Value is the base type of the prefix type.
7497 Set_Etype
(N
, P_Base_Type
);
7498 Validate_Non_Static_Attribute_Function_Call
;
7500 -- Check restriction No_Fixed_IO
7502 if Restriction_Check_Required
(No_Fixed_IO
)
7503 and then Is_Fixed_Point_Type
(P_Type
)
7505 Check_Restriction
(No_Fixed_IO
, P
);
7512 -- Shares processing with Machine_Size attribute
7518 when Attribute_Version
=>
7521 Set_Etype
(N
, RTE
(RE_Version_String
));
7527 when Attribute_Wchar_T_Size
=>
7528 Standard_Attribute
(Interfaces_Wchar_T_Size
);
7534 when Attribute_Wide_Image
=>
7535 Analyze_Image_Attribute
(Standard_Wide_String
);
7537 ---------------------
7538 -- Wide_Wide_Image --
7539 ---------------------
7541 when Attribute_Wide_Wide_Image
=>
7542 Analyze_Image_Attribute
(Standard_Wide_Wide_String
);
7548 -- Shares processing with Value attribute
7550 ---------------------
7551 -- Wide_Wide_Value --
7552 ---------------------
7554 -- Shares processing with Value attribute
7556 ---------------------
7557 -- Wide_Wide_Width --
7558 ---------------------
7560 when Attribute_Wide_Wide_Width
7561 | Attribute_Wide_Width
7566 Set_Etype
(N
, Universal_Integer
);
7572 -- Shares processing with Wide_Wide_Width attribute
7578 -- Shares processing with Wide_Wide_Width attribute
7584 when Attribute_Word_Size
=>
7585 Standard_Attribute
(System_Word_Size
);
7591 when Attribute_Write
=>
7593 Check_Stream_Attribute
(TSS_Stream_Write
);
7594 Set_Etype
(N
, Standard_Void_Type
);
7595 Resolve
(N
, Standard_Void_Type
);
7599 -- In SPARK certain attributes (see below) depend on Tasking_State.
7600 -- Ensure that the entity is available for gnat2why by loading it.
7601 -- See SPARK RM 9(18) for the relevant rule.
7603 if GNATprove_Mode
then
7605 when Attribute_Callable
7608 | Attribute_Terminated
7610 SPARK_Implicit_Load
(RE_Tasking_State
);
7617 -- All errors raise Bad_Attribute, so that we get out before any further
7618 -- damage occurs when an error is detected (for example, if we check for
7619 -- one attribute expression, and the check succeeds, we want to be able
7620 -- to proceed securely assuming that an expression is in fact present.
7622 -- Note: we set the attribute analyzed in this case to prevent any
7623 -- attempt at reanalysis which could generate spurious error msgs.
7626 when Bad_Attribute
=>
7628 Set_Etype
(N
, Any_Type
);
7630 end Analyze_Attribute
;
7632 --------------------
7633 -- Eval_Attribute --
7634 --------------------
7636 procedure Eval_Attribute
(N
: Node_Id
) is
7637 Loc
: constant Source_Ptr
:= Sloc
(N
);
7639 C_Type
: constant Entity_Id
:= Etype
(N
);
7640 -- The type imposed by the context
7643 -- Attribute_Name (N) after verification of validity of N
7646 -- Get_Attribute_Id (Aname) after Aname is set
7649 -- Prefix (N) after verification of validity of N
7652 -- First expression, or Empty if none
7655 -- Second expression, or Empty if none
7657 P_Entity
: Entity_Id
;
7658 -- Entity denoted by prefix
7661 -- The type of the prefix
7663 P_Base_Type
: Entity_Id
;
7664 -- The base type of the prefix type
7666 P_Root_Type
: Entity_Id
;
7667 -- The root type of the prefix type
7669 Static
: Boolean := False;
7670 -- True if the result is Static. This is set by the general processing
7671 -- to true if the prefix is static, and all expressions are static. It
7672 -- can be reset as processing continues for particular attributes. This
7673 -- flag can still be True if the reference raises a constraint error.
7674 -- Is_Static_Expression (N) is set to follow this value as it is set
7675 -- and we could always reference this, but it is convenient to have a
7676 -- simple short name to use, since it is frequently referenced.
7678 Lo_Bound
, Hi_Bound
: Node_Id
;
7679 -- Expressions for low and high bounds of type or array index referenced
7680 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7683 -- Constraint error node used if we have an attribute reference has
7684 -- an argument that raises a constraint error. In this case we replace
7685 -- the attribute with a raise constraint_error node. This is important
7686 -- processing, since otherwise gigi might see an attribute which it is
7687 -- unprepared to deal with.
7689 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7690 -- If Bound is a reference to a discriminant of a task or protected type
7691 -- occurring within the object's body, rewrite attribute reference into
7692 -- a reference to the corresponding discriminal. Use for the expansion
7693 -- of checks against bounds of entry family index subtypes.
7695 procedure Check_Expressions
;
7696 -- In case where the attribute is not foldable, the expressions, if
7697 -- any, of the attribute, are in a non-static context. This procedure
7698 -- performs the required additional checks.
7700 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7701 -- Determines if the given type has compile time known bounds. Note
7702 -- that we enter the case statement even in cases where the prefix
7703 -- type does NOT have known bounds, so it is important to guard any
7704 -- attempt to evaluate both bounds with a call to this function.
7706 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7707 -- This procedure is called when the attribute N has a non-static
7708 -- but compile time known value given by Val. It includes the
7709 -- necessary checks for out of range values.
7711 function Fore_Value
return Nat
;
7712 -- Computes the Fore value for the current attribute prefix, which is
7713 -- known to be a static fixed-point type. Used by Fore and Width.
7715 function Mantissa
return Uint
;
7716 -- Returns the Mantissa value for the prefix type
7718 procedure Set_Bounds
;
7719 -- Used for First, Last and Length attributes applied to an array or
7720 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7721 -- and high bound expressions for the index referenced by the attribute
7722 -- designator (i.e. the first index if no expression is present, and the
7723 -- N'th index if the value N is present as an expression). Also used for
7724 -- First and Last of scalar types and for First_Valid and Last_Valid.
7725 -- Static is reset to False if the type or index type is not statically
7728 -----------------------------------
7729 -- Check_Concurrent_Discriminant --
7730 -----------------------------------
7732 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7734 -- The concurrent (task or protected) type
7737 if Nkind
(Bound
) = N_Identifier
7738 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7739 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7741 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7743 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7745 -- Find discriminant of original concurrent type, and use
7746 -- its current discriminal, which is the renaming within
7747 -- the task/protected body.
7751 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7754 end Check_Concurrent_Discriminant
;
7756 -----------------------
7757 -- Check_Expressions --
7758 -----------------------
7760 procedure Check_Expressions
is
7764 while Present
(E
) loop
7765 Check_Non_Static_Context
(E
);
7768 end Check_Expressions
;
7770 ----------------------------------
7771 -- Compile_Time_Known_Attribute --
7772 ----------------------------------
7774 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7775 T
: constant Entity_Id
:= Etype
(N
);
7778 Fold_Uint
(N
, Val
, False);
7780 -- Check that result is in bounds of the type if it is static
7782 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7785 elsif Is_Out_Of_Range
(N
, T
) then
7786 Apply_Compile_Time_Constraint_Error
7787 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7789 elsif not Range_Checks_Suppressed
(T
) then
7790 Enable_Range_Check
(N
);
7793 Set_Do_Range_Check
(N
, False);
7795 end Compile_Time_Known_Attribute
;
7797 -------------------------------
7798 -- Compile_Time_Known_Bounds --
7799 -------------------------------
7801 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7804 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7806 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7807 end Compile_Time_Known_Bounds
;
7813 -- Note that the Fore calculation is based on the actual values
7814 -- of the bounds, and does not take into account possible rounding.
7816 function Fore_Value
return Nat
is
7817 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7818 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7819 Small
: constant Ureal
:= Small_Value
(P_Type
);
7820 Lo_Real
: constant Ureal
:= Lo
* Small
;
7821 Hi_Real
: constant Ureal
:= Hi
* Small
;
7826 -- Bounds are given in terms of small units, so first compute
7827 -- proper values as reals.
7829 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7832 -- Loop to compute proper value if more than one digit required
7834 while T
>= Ureal_10
loop
7846 -- Table of mantissa values accessed by function Computed using
7849 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7851 -- where D is T'Digits (RM83 3.5.7)
7853 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7895 function Mantissa
return Uint
is
7898 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7905 procedure Set_Bounds
is
7911 -- For a string literal subtype, we have to construct the bounds.
7912 -- Valid Ada code never applies attributes to string literals, but
7913 -- it is convenient to allow the expander to generate attribute
7914 -- references of this type (e.g. First and Last applied to a string
7917 -- Note that the whole point of the E_String_Literal_Subtype is to
7918 -- avoid this construction of bounds, but the cases in which we
7919 -- have to materialize them are rare enough that we don't worry.
7921 -- The low bound is simply the low bound of the base type. The
7922 -- high bound is computed from the length of the string and this
7925 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7926 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7927 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7930 Make_Integer_Literal
(Sloc
(P
),
7932 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7934 Set_Parent
(Hi_Bound
, P
);
7935 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7938 -- For non-array case, just get bounds of scalar type
7940 elsif Is_Scalar_Type
(P_Type
) then
7943 -- For a fixed-point type, we must freeze to get the attributes
7944 -- of the fixed-point type set now so we can reference them.
7946 if Is_Fixed_Point_Type
(P_Type
)
7947 and then not Is_Frozen
(Base_Type
(P_Type
))
7948 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7949 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7951 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7954 -- For array case, get type of proper index
7960 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7963 Indx
:= First_Index
(P_Type
);
7964 for J
in 1 .. Ndim
- 1 loop
7968 -- If no index type, get out (some other error occurred, and
7969 -- we don't have enough information to complete the job).
7977 Ityp
:= Etype
(Indx
);
7980 -- A discrete range in an index constraint is allowed to be a
7981 -- subtype indication. This is syntactically a pain, but should
7982 -- not propagate to the entity for the corresponding index subtype.
7983 -- After checking that the subtype indication is legal, the range
7984 -- of the subtype indication should be transfered to the entity.
7985 -- The attributes for the bounds should remain the simple retrievals
7986 -- that they are now.
7988 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7989 Hi_Bound
:= Type_High_Bound
(Ityp
);
7991 -- If subtype is non-static, result is definitely non-static
7993 if not Is_Static_Subtype
(Ityp
) then
7995 Set_Is_Static_Expression
(N
, False);
7997 -- Subtype is static, does it raise CE?
7999 elsif not Is_OK_Static_Subtype
(Ityp
) then
8000 Set_Raises_Constraint_Error
(N
);
8004 -- Start of processing for Eval_Attribute
8007 -- Return immediately if e.g. N has been rewritten or is malformed due
8008 -- to previous errors.
8010 if Nkind
(N
) /= N_Attribute_Reference
then
8014 Aname
:= Attribute_Name
(N
);
8015 Id
:= Get_Attribute_Id
(Aname
);
8018 -- The To_Address attribute can be static, but it cannot be evaluated at
8019 -- compile time, so just return.
8021 if Id
= Attribute_To_Address
then
8025 -- Initialize result as non-static, will be reset if appropriate
8027 Set_Is_Static_Expression
(N
, False);
8029 -- Acquire first two expressions (at the moment, no attributes take more
8030 -- than two expressions in any case).
8032 if Present
(Expressions
(N
)) then
8033 E1
:= First
(Expressions
(N
));
8040 -- Special processing for Enabled attribute. This attribute has a very
8041 -- special prefix, and the easiest way to avoid lots of special checks
8042 -- to protect this special prefix from causing trouble is to deal with
8043 -- this attribute immediately and be done with it.
8045 if Id
= Attribute_Enabled
then
8047 -- We skip evaluation if the expander is not active. This is not just
8048 -- an optimization. It is of key importance that we not rewrite the
8049 -- attribute in a generic template, since we want to pick up the
8050 -- setting of the check in the instance.
8052 if not Inside_A_Generic
then
8054 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
8059 if C
in Predefined_Check_Id
then
8060 R
:= Scope_Suppress
.Suppress
(C
);
8062 R
:= Is_Check_Suppressed
(Empty
, C
);
8066 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
8069 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
8076 -- Attribute 'Img applied to a static enumeration value is static, and
8077 -- we will do the folding right here (things get confused if we let this
8078 -- case go through the normal circuitry).
8080 if Id
= Attribute_Img
8081 and then Is_Entity_Name
(P
)
8082 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
8083 and then Is_OK_Static_Expression
(P
)
8086 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
8091 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8092 Set_Casing
(All_Upper_Case
);
8093 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8096 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8097 Analyze_And_Resolve
(N
, Standard_String
);
8098 Set_Is_Static_Expression
(N
, True);
8104 -- Special processing for cases where the prefix is an object or value,
8105 -- including string literals (attributes of string literals can only
8106 -- appear in generated code) and current instance prefixes in type or
8109 if Is_Object_Reference
(P
)
8110 or else Is_Current_Instance_Reference_In_Type_Aspect
(P
)
8111 or else Nkind
(P
) = N_String_Literal
8112 or else (Is_Entity_Name
(P
)
8113 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
8115 -- For Alignment, give alignment of object if available, otherwise we
8116 -- cannot fold Alignment.
8118 if Id
= Attribute_Alignment
then
8119 if Is_Entity_Name
(P
) and then Known_Alignment
(Entity
(P
)) then
8120 Compile_Time_Known_Attribute
(N
, Alignment
(Entity
(P
)));
8127 -- For Component_Size, the prefix is an array object, and we apply
8128 -- the attribute to the type of the object. This is allowed for both
8129 -- unconstrained and constrained arrays, since the bounds have no
8130 -- influence on the value of this attribute.
8132 elsif Id
= Attribute_Component_Size
then
8133 P_Entity
:= Etype
(P
);
8135 -- For Enum_Rep, evaluation depends on the nature of the prefix and
8136 -- the optional argument.
8138 elsif Id
= Attribute_Enum_Rep
then
8139 if Is_Entity_Name
(P
) then
8142 Enum_Expr
: Node_Id
;
8143 -- The enumeration-type expression of interest
8148 if Ekind
(Entity
(P
)) in E_Constant | E_Enumeration_Literal
8152 -- Enum_Type'Enum_Rep (E1) case
8154 elsif Is_Enumeration_Type
(Entity
(P
)) then
8157 -- Otherwise the attribute must be expanded into a
8158 -- conversion and evaluated at run time.
8165 -- We can fold if the expression is an enumeration
8166 -- literal, or if it denotes a constant whose value
8167 -- is known at compile time.
8169 if Nkind
(Enum_Expr
) in N_Has_Entity
8170 and then (Ekind
(Entity
(Enum_Expr
)) =
8171 E_Enumeration_Literal
8173 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
8174 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
8175 N_Object_Declaration
8177 (Expression
(Parent
(Entity
(P
))))
8178 and then Compile_Time_Known_Value
8179 (Expression
(Parent
(Entity
(P
))))))
8181 P_Entity
:= Etype
(P
);
8188 -- Otherwise the attribute is illegal, do not attempt to perform
8189 -- any kind of folding.
8195 -- For Bit_Position, give Component_Bit_Offset of object if available
8196 -- otherwise we cannot fold Bit_Position. Note that the attribute can
8197 -- be applied to a naked record component in generated code, in which
8198 -- case the prefix is an identifier that references the component or
8199 -- discriminant entity.
8201 elsif Id
= Attribute_Bit_Position
then
8206 if Is_Entity_Name
(P
) then
8209 CE
:= Entity
(Selector_Name
(P
));
8212 if Known_Static_Component_Bit_Offset
(CE
) then
8213 Compile_Time_Known_Attribute
8214 (N
, Component_Bit_Offset
(CE
));
8222 -- For Position, in Ada 2005 (or later) if we have the non-default
8223 -- bit order, we return the original value as given in the component
8224 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8225 -- default bit order) return the value if it is known statically.
8227 elsif Id
= Attribute_Position
then
8229 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8232 if Present
(Component_Clause
(CE
))
8233 and then Ada_Version
>= Ada_2005
8234 and then Reverse_Bit_Order
(Scope
(CE
))
8236 Compile_Time_Known_Attribute
8237 (N
, Expr_Value
(Position
(Component_Clause
(CE
))));
8239 elsif Known_Static_Component_Bit_Offset
(CE
) then
8240 Compile_Time_Known_Attribute
8241 (N
, Component_Bit_Offset
(CE
) / System_Storage_Unit
);
8250 -- For First_Bit, in Ada 2005 (or later) if we have the non-default
8251 -- bit order, we return the original value as given in the component
8252 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8253 -- default bit order) return the value if it is known statically.
8255 elsif Id
= Attribute_First_Bit
then
8257 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8260 if Present
(Component_Clause
(CE
))
8261 and then Ada_Version
>= Ada_2005
8262 and then Reverse_Bit_Order
(Scope
(CE
))
8264 Compile_Time_Known_Attribute
8265 (N
, Expr_Value
(First_Bit
(Component_Clause
(CE
))));
8267 elsif Known_Static_Component_Bit_Offset
(CE
) then
8268 Compile_Time_Known_Attribute
8269 (N
, Component_Bit_Offset
(CE
) mod System_Storage_Unit
);
8278 -- For Last_Bit, in Ada 2005 (or later) if we have the non-default
8279 -- bit order, we return the original value as given in the component
8280 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8281 -- default bit order) return the value if it is known statically.
8283 elsif Id
= Attribute_Last_Bit
then
8285 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8288 if Present
(Component_Clause
(CE
))
8289 and then Ada_Version
>= Ada_2005
8290 and then Reverse_Bit_Order
(Scope
(CE
))
8292 Compile_Time_Known_Attribute
8293 (N
, Expr_Value
(Last_Bit
(Component_Clause
(CE
))));
8295 elsif Known_Static_Component_Bit_Offset
(CE
)
8296 and then Known_Static_Esize
(CE
)
8298 Compile_Time_Known_Attribute
8299 (N
, (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
8308 -- For First, Last and Length, the prefix is an array object, and we
8309 -- apply the attribute to its type, but we need a constrained type
8310 -- for this, so we use the actual subtype if available.
8312 elsif Id
= Attribute_First
8313 or else Id
= Attribute_Last
8314 or else Id
= Attribute_Length
8317 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
8320 if Present
(AS
) and then Is_Constrained
(AS
) then
8323 -- If we have an unconstrained type we cannot fold
8331 elsif Id
= Attribute_Size
then
8332 -- For Enum_Lit'Size, use Enum_Type'Object_Size. Taking the 'Size
8333 -- of a literal is kind of a strange thing to do, so we don't want
8334 -- to pass this oddity on to the back end. Note that Etype of an
8335 -- enumeration literal is always a (base) type, never a
8336 -- constrained subtype, so the Esize is always known.
8338 if Is_Entity_Name
(P
)
8339 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
8341 pragma Assert
(Known_Static_Esize
(Etype
(P
)));
8342 Compile_Time_Known_Attribute
(N
, Esize
(Etype
(P
)));
8344 -- Otherwise, if Size is available, use that
8346 elsif Is_Entity_Name
(P
) and then Known_Static_Esize
(Entity
(P
))
8348 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
8350 -- Otherwise, we cannot fold
8363 -- Cases where P is not an object. Cannot do anything if P is not the
8364 -- name of an entity.
8366 elsif not Is_Entity_Name
(P
) then
8370 -- Otherwise get prefix entity
8373 P_Entity
:= Entity
(P
);
8376 -- If we are asked to evaluate an attribute where the prefix is a
8377 -- non-frozen generic actual type whose RM_Size has not been set,
8378 -- then abandon the effort.
8380 if Is_Type
(P_Entity
)
8381 and then (not Is_Frozen
(P_Entity
)
8382 and then Is_Generic_Actual_Type
(P_Entity
)
8383 and then not Known_RM_Size
(P_Entity
))
8385 -- However, the attribute Unconstrained_Array must be evaluated,
8386 -- since it is documented to be a static attribute (and can for
8387 -- example appear in a Compile_Time_Warning pragma). The frozen
8388 -- status of the type does not affect its evaluation.
8390 and then Id
/= Attribute_Unconstrained_Array
8395 -- At this stage P_Entity is the entity to which the attribute
8396 -- is to be applied. This is usually simply the entity of the
8397 -- prefix, except in some cases of attributes for objects, where
8398 -- as described above, we apply the attribute to the object type.
8400 -- Here is where we make sure that static attributes are properly
8401 -- marked as such. These are attributes whose prefix is a static
8402 -- scalar subtype, whose result is scalar, and whose arguments, if
8403 -- present, are static scalar expressions. Note that such references
8404 -- are static expressions even if they raise Constraint_Error.
8406 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
8407 -- though evaluating it raises constraint error. This means that a
8408 -- declaration like:
8410 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
8412 -- is legal, since here this expression appears in a statically
8413 -- unevaluated position, so it does not actually raise an exception.
8415 -- T'Descriptor_Size is never static, even if T is static.
8417 if Is_Scalar_Type
(P_Entity
)
8418 and then not Is_Generic_Type
(P_Entity
)
8419 and then Is_Static_Subtype
(P_Entity
)
8420 and then Is_Scalar_Type
(Etype
(N
))
8423 or else (Is_Static_Expression
(E1
)
8424 and then Is_Scalar_Type
(Etype
(E1
))))
8427 or else (Is_Static_Expression
(E2
)
8428 and then Is_Scalar_Type
(Etype
(E1
))))
8429 and then Id
/= Attribute_Descriptor_Size
8431 -- If the front-end conjures up Integer'Pred (Integer'First)
8432 -- as the high bound of a null array aggregate, then we don't
8433 -- want to reject that as an illegal static expression.
8435 and then not Is_Null_Array_Aggregate_High_Bound
(N
)
8438 Set_Is_Static_Expression
(N
, True);
8441 -- First foldable possibility is a scalar or array type (RM 4.9(7))
8442 -- that is not generic (generic types are eliminated by RM 4.9(25)).
8443 -- Note we allow nonstatic nongeneric types at this stage as further
8446 if Is_Type
(P_Entity
)
8447 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
8448 and then not Is_Generic_Type
(P_Entity
)
8452 -- Second foldable possibility is an array object (RM 4.9(8))
8454 elsif Ekind
(P_Entity
) in E_Variable | E_Constant
8455 and then Is_Array_Type
(Etype
(P_Entity
))
8456 and then not Is_Generic_Type
(Etype
(P_Entity
))
8458 P_Type
:= Etype
(P_Entity
);
8460 -- If the entity is an array constant with an unconstrained nominal
8461 -- subtype then get the type from the initial value. If the value has
8462 -- been expanded into assignments, there is no expression and the
8463 -- attribute reference remains dynamic.
8465 -- We could do better here and retrieve the type ???
8467 if Ekind
(P_Entity
) = E_Constant
8468 and then not Is_Constrained
(P_Type
)
8470 if No
(Constant_Value
(P_Entity
)) then
8473 P_Type
:= Etype
(Constant_Value
(P_Entity
));
8477 -- Definite must be folded if the prefix is not a generic type, that
8478 -- is to say if we are within an instantiation. Same processing applies
8479 -- to selected GNAT attributes.
8481 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
8482 Id
= Attribute_Definite
or else
8483 Id
= Attribute_Descriptor_Size
or else
8484 Id
= Attribute_Has_Access_Values
or else
8485 Id
= Attribute_Has_Discriminants
or else
8486 Id
= Attribute_Has_Tagged_Values
or else
8487 Id
= Attribute_Preelaborable_Initialization
or else
8488 Id
= Attribute_Type_Class
or else
8489 Id
= Attribute_Unconstrained_Array
or else
8490 Id
= Attribute_Max_Alignment_For_Allocation
)
8491 and then not Is_Generic_Type
(P_Entity
)
8495 -- We can fold 'Size applied to a type if the size is known (as happens
8496 -- for a size from an attribute definition clause). At this stage, this
8497 -- can happen only for types (e.g. record types) for which the size is
8498 -- always non-static. We exclude generic types from consideration (since
8499 -- they have bogus sizes set within templates). We can also fold
8500 -- Max_Size_In_Storage_Elements in the same cases.
8502 elsif (Id
= Attribute_Size
or
8503 Id
= Attribute_Max_Size_In_Storage_Elements
)
8504 and then Is_Type
(P_Entity
)
8505 and then not Is_Generic_Type
(P_Entity
)
8506 and then Known_Static_RM_Size
(P_Entity
)
8509 Attr_Value
: Uint
:= RM_Size
(P_Entity
);
8511 if Id
= Attribute_Max_Size_In_Storage_Elements
then
8512 Attr_Value
:= (Attr_Value
+ System_Storage_Unit
- 1)
8513 / System_Storage_Unit
;
8515 Compile_Time_Known_Attribute
(N
, Attr_Value
);
8519 -- We can fold 'Alignment applied to a type if the alignment is known
8520 -- (as happens for an alignment from an attribute definition clause).
8521 -- At this stage, this can happen only for types (e.g. record types) for
8522 -- which the size is always non-static. We exclude generic types from
8523 -- consideration (since they have bogus sizes set within templates).
8525 elsif Id
= Attribute_Alignment
8526 and then Is_Type
(P_Entity
)
8527 and then not Is_Generic_Type
(P_Entity
)
8528 and then Known_Alignment
(P_Entity
)
8530 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
8533 -- If this is an access attribute that is known to fail accessibility
8534 -- check, rewrite accordingly.
8536 elsif Id
= Attribute_Address
8537 and then Raises_Constraint_Error
(N
)
8540 Make_Raise_Program_Error
(Loc
,
8541 Reason
=> PE_Accessibility_Check_Failed
));
8542 Set_Etype
(N
, C_Type
);
8545 -- No other cases are foldable (they certainly aren't static, and at
8546 -- the moment we don't try to fold any cases other than the ones above).
8553 -- If either attribute or the prefix is Any_Type, then propagate
8554 -- Any_Type to the result and don't do anything else at all.
8556 if P_Type
= Any_Type
8557 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
8558 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
8560 Set_Etype
(N
, Any_Type
);
8564 -- Scalar subtype case. We have not yet enforced the static requirement
8565 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
8566 -- of non-static attribute references (e.g. S'Digits for a non-static
8567 -- floating-point type, which we can compute at compile time).
8569 -- Note: this folding of non-static attributes is not simply a case of
8570 -- optimization. For many of the attributes affected, Gigi cannot handle
8571 -- the attribute and depends on the front end having folded them away.
8573 -- Note: although we don't require staticness at this stage, we do set
8574 -- the Static variable to record the staticness, for easy reference by
8575 -- those attributes where it matters (e.g. Succ and Pred), and also to
8576 -- be used to ensure that non-static folded things are not marked as
8577 -- being static (a check that is done right at the end).
8579 P_Root_Type
:= Root_Type
(P_Type
);
8580 P_Base_Type
:= Base_Type
(P_Type
);
8582 -- If the root type or base type is generic, then we cannot fold. This
8583 -- test is needed because subtypes of generic types are not always
8584 -- marked as being generic themselves (which seems odd???)
8586 if Is_Generic_Type
(P_Root_Type
)
8587 or else Is_Generic_Type
(P_Base_Type
)
8592 if Is_Scalar_Type
(P_Type
) then
8593 if not Is_Static_Subtype
(P_Type
) then
8595 Set_Is_Static_Expression
(N
, False);
8596 elsif not Is_OK_Static_Subtype
(P_Type
) then
8597 Set_Raises_Constraint_Error
(N
);
8600 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
8601 -- since we can't do anything with unconstrained arrays. In addition,
8602 -- only the First, Last and Length attributes are possibly static.
8604 -- Atomic_Always_Lock_Free, Definite, Descriptor_Size, Has_Access_Values
8605 -- Has_Discriminants, Has_Tagged_Values, Type_Class, and
8606 -- Unconstrained_Array are again exceptions, because they apply as well
8607 -- to unconstrained types.
8609 -- In addition Component_Size is an exception since it is possibly
8610 -- foldable, even though it is never static, and it does apply to
8611 -- unconstrained arrays. Furthermore, it is essential to fold this
8612 -- in the packed case, since otherwise the value will be incorrect.
8614 -- Folding can also be done for Preelaborable_Initialization based on
8615 -- whether the prefix type has preelaborable initialization, even though
8616 -- the attribute is nonstatic.
8618 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
8619 Id
= Attribute_Definite
or else
8620 Id
= Attribute_Descriptor_Size
or else
8621 Id
= Attribute_Has_Access_Values
or else
8622 Id
= Attribute_Has_Discriminants
or else
8623 Id
= Attribute_Has_Tagged_Values
or else
8624 Id
= Attribute_Preelaborable_Initialization
or else
8625 Id
= Attribute_Type_Class
or else
8626 Id
= Attribute_Unconstrained_Array
or else
8627 Id
= Attribute_Component_Size
8630 Set_Is_Static_Expression
(N
, False);
8632 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
8633 if not Is_Constrained
(P_Type
)
8634 or else (Id
/= Attribute_First
and then
8635 Id
/= Attribute_Last
and then
8636 Id
/= Attribute_Length
)
8642 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
8643 -- scalar case, we hold off on enforcing staticness, since there are
8644 -- cases which we can fold at compile time even though they are not
8645 -- static (e.g. 'Length applied to a static index, even though other
8646 -- non-static indexes make the array type non-static). This is only
8647 -- an optimization, but it falls out essentially free, so why not.
8648 -- Again we compute the variable Static for easy reference later
8649 -- (note that no array attributes are static in Ada 83).
8651 -- We also need to set Static properly for subsequent legality checks
8652 -- which might otherwise accept non-static constants in contexts
8653 -- where they are not legal.
8656 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
8657 Set_Is_Static_Expression
(N
, Static
);
8663 Nod
:= First_Index
(P_Type
);
8665 -- The expression is static if the array type is constrained
8666 -- by given bounds, and not by an initial expression. Constant
8667 -- strings are static in any case.
8669 if Root_Type
(P_Type
) /= Standard_String
then
8671 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
8672 Set_Is_Static_Expression
(N
, Static
);
8675 while Present
(Nod
) loop
8676 if not Is_Static_Subtype
(Etype
(Nod
)) then
8678 Set_Is_Static_Expression
(N
, False);
8680 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
8681 Set_Raises_Constraint_Error
(N
);
8683 Set_Is_Static_Expression
(N
, False);
8686 -- If however the index type is generic, or derived from
8687 -- one, attributes cannot be folded.
8689 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
8690 and then Id
/= Attribute_Component_Size
8700 -- Check any expressions that are present. Note that these expressions,
8701 -- depending on the particular attribute type, are either part of the
8702 -- attribute designator, or they are arguments in a case where the
8703 -- attribute reference returns a function. In the latter case, the
8704 -- rule in (RM 4.9(22)) applies and in particular requires the type
8705 -- of the expressions to be scalar in order for the attribute to be
8706 -- considered to be static.
8714 while Present
(E
) loop
8716 -- If expression is not static, then the attribute reference
8717 -- result certainly cannot be static.
8719 if not Is_Static_Expression
(E
) then
8721 Set_Is_Static_Expression
(N
, False);
8724 if Raises_Constraint_Error
(E
) then
8725 Set_Raises_Constraint_Error
(N
);
8728 -- If the result is not known at compile time, or is not of
8729 -- a scalar type, then the result is definitely not static,
8730 -- so we can quit now.
8732 if not Compile_Time_Known_Value
(E
)
8733 or else not Is_Scalar_Type
(Etype
(E
))
8738 -- If the expression raises a constraint error, then so does
8739 -- the attribute reference. We keep going in this case because
8740 -- we are still interested in whether the attribute reference
8741 -- is static even if it is not static.
8743 elsif Raises_Constraint_Error
(E
) then
8744 Set_Raises_Constraint_Error
(N
);
8750 if Raises_Constraint_Error
(Prefix
(N
)) then
8751 Set_Is_Static_Expression
(N
, False);
8756 -- Deal with the case of a static attribute reference that raises
8757 -- constraint error. The Raises_Constraint_Error flag will already
8758 -- have been set, and the Static flag shows whether the attribute
8759 -- reference is static. In any case we certainly can't fold such an
8760 -- attribute reference.
8762 -- Note that the rewriting of the attribute node with the constraint
8763 -- error node is essential in this case, because otherwise Gigi might
8764 -- blow up on one of the attributes it never expects to see.
8766 -- The constraint_error node must have the type imposed by the context,
8767 -- to avoid spurious errors in the enclosing expression.
8769 if Raises_Constraint_Error
(N
) then
8771 Make_Raise_Constraint_Error
(Sloc
(N
),
8772 Reason
=> CE_Range_Check_Failed
);
8773 Set_Etype
(CE_Node
, Etype
(N
));
8774 Set_Raises_Constraint_Error
(CE_Node
);
8776 Rewrite
(N
, Relocate_Node
(CE_Node
));
8777 Set_Raises_Constraint_Error
(N
, True);
8781 -- At this point we have a potentially foldable attribute reference.
8782 -- If Static is set, then the attribute reference definitely obeys
8783 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8784 -- folded. If Static is not set, then the attribute may or may not
8785 -- be foldable, and the individual attribute processing routines
8786 -- test Static as required in cases where it makes a difference.
8788 -- In the case where Static is not set, we do know that all the
8789 -- expressions present are at least known at compile time (we assumed
8790 -- above that if this was not the case, then there was no hope of static
8791 -- evaluation). However, we did not require that the bounds of the
8792 -- prefix type be compile time known, let alone static). That's because
8793 -- there are many attributes that can be computed at compile time on
8794 -- non-static subtypes, even though such references are not static
8797 -- For VAX float, the root type is an IEEE type. So make sure to use the
8798 -- base type instead of the root-type for floating point attributes.
8802 -- Attributes related to Ada 2012 iterators; nothing to evaluate for
8805 when Attribute_Constant_Indexing
8806 | Attribute_Default_Iterator
8807 | Attribute_Implicit_Dereference
8808 | Attribute_Iterator_Element
8809 | Attribute_Iterable
8811 | Attribute_Variable_Indexing
8815 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8816 -- These were already rejected by the parser. Thus they shouldn't
8819 when Internal_Attribute_Id
=>
8820 raise Program_Error
;
8826 when Attribute_Adjacent
=>
8830 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8837 when Attribute_Aft
=>
8838 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8844 when Attribute_Alignment
=> Alignment_Block
: declare
8845 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8848 -- Fold if alignment is set and not otherwise
8850 if Known_Alignment
(P_TypeA
) then
8851 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8853 end Alignment_Block
;
8855 -----------------------------
8856 -- Atomic_Always_Lock_Free --
8857 -----------------------------
8859 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8862 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8864 V
: constant Entity_Id
:=
8866 (Support_Atomic_Primitives_On_Target
8867 and then Support_Atomic_Primitives
(P_Type
));
8870 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8872 -- Analyze and resolve as boolean. Note that this attribute is a
8873 -- static attribute in GNAT.
8875 Analyze_And_Resolve
(N
, Standard_Boolean
);
8877 Set_Is_Static_Expression
(N
);
8878 end Atomic_Always_Lock_Free
;
8884 -- Bit can never be folded
8886 when Attribute_Bit
=>
8893 -- Body_version can never be static
8895 when Attribute_Body_Version
=>
8902 when Attribute_Ceiling
=>
8904 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8906 --------------------
8907 -- Component_Size --
8908 --------------------
8910 -- Fold Component_Size if it is known at compile time, which is always
8911 -- true in the packed array case. It is important that the packed array
8912 -- case is handled here since the back end would otherwise get confused
8913 -- by the equivalent packed array type.
8915 when Attribute_Component_Size
=>
8916 if Known_Static_Component_Size
(P_Type
) then
8917 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
8924 when Attribute_Compose
=>
8927 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8934 -- Constrained is never folded for now, there may be cases that
8935 -- could be handled at compile time. To be looked at later.
8937 when Attribute_Constrained
=>
8939 -- The expander might fold it and set the static flag accordingly,
8940 -- but with expansion disabled, it remains as an attribute reference,
8941 -- and this reference is not static.
8943 Set_Is_Static_Expression
(N
, False);
8949 when Attribute_Copy_Sign
=>
8953 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8960 when Attribute_Definite
=>
8961 Rewrite
(N
, New_Occurrence_Of
(
8962 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
8963 Analyze_And_Resolve
(N
, Standard_Boolean
);
8969 when Attribute_Delta
=>
8970 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
8976 when Attribute_Denorm
=>
8978 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
8980 ---------------------
8981 -- Descriptor_Size --
8982 ---------------------
8984 -- Descriptor_Size is nonnull only for unconstrained array types
8986 when Attribute_Descriptor_Size
=>
8987 if not Is_Array_Type
(P_Type
) or else Is_Constrained
(P_Type
) then
8988 Fold_Uint
(N
, Uint_0
, Static
);
8995 when Attribute_Digits
=>
8996 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
9002 when Attribute_Emax
=>
9004 -- Ada 83 attribute is defined as (RM83 3.5.8)
9006 -- T'Emax = 4 * T'Mantissa
9008 Fold_Uint
(N
, 4 * Mantissa
, Static
);
9014 when Attribute_Enum_Rep
=> Enum_Rep
: declare
9018 -- The attribute appears in the form:
9020 -- Enum_Typ'Enum_Rep (Const)
9021 -- Enum_Typ'Enum_Rep (Enum_Lit)
9023 if Present
(E1
) then
9026 -- Otherwise the prefix denotes a constant or enumeration literal:
9029 -- Enum_Lit'Enum_Rep
9035 -- For an enumeration type with a non-standard representation use
9036 -- the Enumeration_Rep field of the proper constant. Note that this
9037 -- will not work for types Character/Wide_[Wide-]Character, since no
9038 -- real entities are created for the enumeration literals, but that
9039 -- does not matter since these two types do not have non-standard
9040 -- representations anyway.
9042 if Is_Enumeration_Type
(P_Type
)
9043 and then Has_Non_Standard_Rep
(P_Type
)
9045 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
9047 -- For enumeration types with standard representations and all other
9048 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
9052 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
9060 when Attribute_Enum_Val
=> Enum_Val
: declare
9064 -- We have something like Enum_Type'Enum_Val (23), so search for a
9065 -- corresponding value in the list of Enum_Rep values for the type.
9067 Lit
:= First_Literal
(P_Base_Type
);
9069 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
9070 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
9077 Apply_Compile_Time_Constraint_Error
9078 (N
, "no representation value matches",
9079 CE_Range_Check_Failed
,
9080 Warn
=> not Static
);
9090 when Attribute_Epsilon
=>
9092 -- Ada 83 attribute is defined as (RM83 3.5.8)
9094 -- T'Epsilon = 2.0**(1 - T'Mantissa)
9096 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
9102 when Attribute_Exponent
=>
9104 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9106 -----------------------
9107 -- Finalization_Size --
9108 -----------------------
9110 when Attribute_Finalization_Size
=>
9117 when Attribute_First
=>
9120 if Compile_Time_Known_Value
(Lo_Bound
) then
9121 if Is_Real_Type
(P_Type
) then
9122 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
9124 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9128 Check_Concurrent_Discriminant
(Lo_Bound
);
9135 when Attribute_First_Valid
=>
9136 if Has_Predicates
(P_Type
)
9137 and then Has_Static_Predicate
(P_Type
)
9140 FirstN
: constant Node_Id
:=
9141 First
(Static_Discrete_Predicate
(P_Type
));
9143 if Nkind
(FirstN
) = N_Range
then
9144 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
9146 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
9152 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9159 when Attribute_Fixed_Value
=>
9166 when Attribute_Floor
=>
9168 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9174 when Attribute_Fore
=>
9175 if Compile_Time_Known_Bounds
(P_Type
) then
9176 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
9183 when Attribute_Fraction
=>
9185 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9187 -----------------------
9188 -- Has_Access_Values --
9189 -----------------------
9191 when Attribute_Has_Access_Values
=>
9192 Rewrite
(N
, New_Occurrence_Of
9193 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
9194 Analyze_And_Resolve
(N
, Standard_Boolean
);
9196 -----------------------
9197 -- Has_Discriminants --
9198 -----------------------
9200 when Attribute_Has_Discriminants
=>
9201 Rewrite
(N
, New_Occurrence_Of
(
9202 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
9203 Analyze_And_Resolve
(N
, Standard_Boolean
);
9205 ----------------------
9206 -- Has_Same_Storage --
9207 ----------------------
9209 when Attribute_Has_Same_Storage
=>
9212 -----------------------
9213 -- Has_Tagged_Values --
9214 -----------------------
9216 when Attribute_Has_Tagged_Values
=>
9217 Rewrite
(N
, New_Occurrence_Of
9218 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
9219 Analyze_And_Resolve
(N
, Standard_Boolean
);
9225 when Attribute_Identity
=>
9232 -- Image is a scalar attribute, but is never static, because it is
9233 -- not a static function (having a non-scalar argument (RM 4.9(22))
9234 -- However, we can constant-fold the image of an enumeration literal
9235 -- if names are available and default Image implementation has not
9238 when Attribute_Image
=>
9239 if Is_Entity_Name
(E1
)
9240 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
9241 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
9242 and then not Global_Discard_Names
9243 and then not Has_Aspect
(Etype
(E1
), Aspect_Put_Image
)
9246 Lit
: constant Entity_Id
:= Entity
(E1
);
9250 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
9251 Set_Casing
(All_Upper_Case
);
9252 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
9254 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
9255 Analyze_And_Resolve
(N
, Standard_String
);
9256 Set_Is_Static_Expression
(N
, False);
9264 -- We never try to fold Integer_Value (though perhaps we could???)
9266 when Attribute_Integer_Value
=>
9273 -- Invalid_Value is a scalar attribute that is never static, because
9274 -- the value is by design out of range.
9276 when Attribute_Invalid_Value
=>
9283 when Attribute_Large
=>
9285 -- For fixed-point, we use the identity:
9287 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
9289 if Is_Fixed_Point_Type
(P_Type
) then
9291 Make_Op_Multiply
(Loc
,
9293 Make_Op_Subtract
(Loc
,
9297 Make_Real_Literal
(Loc
, Ureal_2
),
9299 Make_Attribute_Reference
(Loc
,
9301 Attribute_Name
=> Name_Mantissa
)),
9302 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
9305 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
9307 Analyze_And_Resolve
(N
, C_Type
);
9309 -- Floating-point (Ada 83 compatibility)
9312 -- Ada 83 attribute is defined as (RM83 3.5.8)
9314 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
9318 -- T'Emax = 4 * T'Mantissa
9322 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
9330 when Attribute_Last
=>
9333 if Compile_Time_Known_Value
(Hi_Bound
) then
9334 if Is_Real_Type
(P_Type
) then
9335 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
9337 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9341 Check_Concurrent_Discriminant
(Hi_Bound
);
9348 when Attribute_Last_Valid
=>
9349 if Has_Predicates
(P_Type
)
9350 and then Has_Static_Predicate
(P_Type
)
9353 LastN
: constant Node_Id
:=
9354 Last
(Static_Discrete_Predicate
(P_Type
));
9356 if Nkind
(LastN
) = N_Range
then
9357 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
9359 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
9365 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9372 when Attribute_Leading_Part
=> Leading_Part
: declare
9373 Radix_Digits
: constant Uint
:= Expr_Value
(E2
);
9376 if UI_Le
(Radix_Digits
, Uint_0
) then
9377 Apply_Compile_Time_Constraint_Error
9378 (N
, "Radix_Digits in Leading_Part is zero or negative",
9380 Warn
=> not Static
);
9388 Eval_Fat
.Leading_Part
9389 (P_Base_Type
, Expr_Value_R
(E1
), Radix_Digits
),
9397 when Attribute_Length
=> Length
: declare
9401 -- If any index type is a formal type, or derived from one, the
9402 -- bounds are not static. Treating them as static can produce
9403 -- spurious warnings or improper constant folding.
9405 Ind
:= First_Index
(P_Type
);
9406 while Present
(Ind
) loop
9407 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
9416 -- For two compile time values, we can compute length
9418 if Compile_Time_Known_Value
(Lo_Bound
)
9419 and then Compile_Time_Known_Value
(Hi_Bound
)
9422 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
9426 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9427 -- comparable, and we can figure out the difference between them.
9430 Diff
: aliased Uint
;
9434 Compile_Time_Compare
9435 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9438 Fold_Uint
(N
, Uint_1
, Static
);
9441 Fold_Uint
(N
, Uint_0
, Static
);
9444 if Present
(Diff
) then
9445 Fold_Uint
(N
, Diff
+ 1, Static
);
9458 -- Loop_Entry acts as an alias of a constant initialized to the prefix
9459 -- of the said attribute at the point of entry into the related loop. As
9460 -- such, the attribute reference does not need to be evaluated because
9461 -- the prefix is the one that is evaluted.
9463 when Attribute_Loop_Entry
=>
9470 -- We use the same rounding as the one used for RM 4.9(38/2)
9472 when Attribute_Machine
=>
9474 (N
, Machine_Number
(P_Base_Type
, Expr_Value_R
(E1
), N
), Static
);
9475 Set_Is_Machine_Number
(N
);
9481 when Attribute_Machine_Emax
=>
9482 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
9488 when Attribute_Machine_Emin
=>
9489 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
9491 ----------------------
9492 -- Machine_Mantissa --
9493 ----------------------
9495 when Attribute_Machine_Mantissa
=>
9496 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
9498 -----------------------
9499 -- Machine_Overflows --
9500 -----------------------
9502 when Attribute_Machine_Overflows
=>
9504 -- Always true for fixed-point
9506 if Is_Fixed_Point_Type
(P_Type
) then
9507 Fold_Uint
(N
, True_Value
, Static
);
9509 -- Floating point case
9513 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
9521 when Attribute_Machine_Radix
=>
9522 if Is_Fixed_Point_Type
(P_Type
) then
9523 if Is_Decimal_Fixed_Point_Type
(P_Type
)
9524 and then Machine_Radix_10
(P_Type
)
9526 Fold_Uint
(N
, Uint_10
, Static
);
9528 Fold_Uint
(N
, Uint_2
, Static
);
9531 -- All floating-point type always have radix 2
9534 Fold_Uint
(N
, Uint_2
, Static
);
9537 ----------------------
9538 -- Machine_Rounding --
9539 ----------------------
9541 -- Note: for the folding case, it is fine to treat Machine_Rounding
9542 -- exactly the same way as Rounding, since this is one of the allowed
9543 -- behaviors, and performance is not an issue here. It might be a bit
9544 -- better to give the same result as it would give at run time, even
9545 -- though the non-determinism is certainly permitted.
9547 when Attribute_Machine_Rounding
=>
9549 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9551 --------------------
9552 -- Machine_Rounds --
9553 --------------------
9555 when Attribute_Machine_Rounds
=>
9557 -- Always False for fixed-point
9559 if Is_Fixed_Point_Type
(P_Type
) then
9560 Fold_Uint
(N
, False_Value
, Static
);
9562 -- Else yield proper floating-point result
9566 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
9574 -- Note: Machine_Size is identical to Object_Size
9576 when Attribute_Machine_Size
=> Machine_Size
: declare
9577 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9580 if Known_Esize
(P_TypeA
) then
9581 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9589 when Attribute_Mantissa
=>
9591 -- Fixed-point mantissa
9593 if Is_Fixed_Point_Type
(P_Type
) then
9595 -- Compile time foldable case
9597 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
9599 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
9601 -- The calculation of the obsolete Ada 83 attribute Mantissa
9602 -- is annoying, because of AI00143, quoted here:
9604 -- !question 84-01-10
9606 -- Consider the model numbers for F:
9608 -- type F is delta 1.0 range -7.0 .. 8.0;
9610 -- The wording requires that F'MANTISSA be the SMALLEST
9611 -- integer number for which each bound of the specified
9612 -- range is either a model number or lies at most small
9613 -- distant from a model number. This means F'MANTISSA
9614 -- is required to be 3 since the range -7.0 .. 7.0 fits
9615 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
9616 -- number, namely, 7. Is this analysis correct? Note that
9617 -- this implies the upper bound of the range is not
9618 -- represented as a model number.
9620 -- !response 84-03-17
9622 -- The analysis is correct. The upper and lower bounds for
9623 -- a fixed point type can lie outside the range of model
9634 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
9635 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
9636 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
9637 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
9639 -- If the Bound is exactly a model number, i.e. a multiple
9640 -- of Small, then we back it off by one to get the integer
9641 -- value that must be representable.
9643 if Small_Value
(P_Type
) * Max_Man
= Bound
then
9644 Max_Man
:= Max_Man
- 1;
9647 -- Now find corresponding size = Mantissa value
9650 while 2 ** Siz
< Max_Man
loop
9654 Fold_Uint
(N
, Siz
, Static
);
9658 -- The case of dynamic bounds cannot be evaluated at compile
9659 -- time. Instead we use a runtime routine (see Exp_Attr).
9664 -- Floating-point Mantissa
9667 Fold_Uint
(N
, Mantissa
, Static
);
9674 when Attribute_Max
=>
9675 if Is_Real_Type
(P_Type
) then
9677 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9679 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9682 ----------------------------------
9683 -- Max_Alignment_For_Allocation --
9684 ----------------------------------
9686 -- Max_Alignment_For_Allocation is usually the Alignment. However,
9687 -- arrays are allocated with dope, so we need to take into account both
9688 -- the alignment of the array, which comes from the component alignment,
9689 -- and the alignment of the dope. Also, if the alignment is unknown, we
9690 -- use the max (it's OK to be pessimistic).
9692 when Attribute_Max_Alignment_For_Allocation
=> Max_Align
: declare
9693 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
9695 if Known_Alignment
(P_Type
)
9696 and then (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
9698 A
:= Alignment
(P_Type
);
9701 Fold_Uint
(N
, A
, Static
);
9704 ----------------------------------
9705 -- Max_Size_In_Storage_Elements --
9706 ----------------------------------
9708 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9709 -- Storage_Unit boundary. We can fold any cases for which the size
9710 -- is known by the front end.
9712 when Attribute_Max_Size_In_Storage_Elements
=>
9713 if Known_Esize
(P_Type
) then
9715 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9716 System_Storage_Unit
,
9720 --------------------
9721 -- Mechanism_Code --
9722 --------------------
9724 when Attribute_Mechanism_Code
=> Mechanism_Code
: declare
9726 Mech
: Mechanism_Type
;
9731 Mech
:= Mechanism
(P_Entity
);
9734 Val
:= UI_To_Int
(Expr_Value
(E1
));
9736 Formal
:= First_Formal
(P_Entity
);
9737 for J
in 1 .. Val
- 1 loop
9738 Next_Formal
(Formal
);
9741 Mech
:= Mechanism
(Formal
);
9745 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9753 when Attribute_Min
=>
9754 if Is_Real_Type
(P_Type
) then
9756 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9759 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9766 when Attribute_Mod
=>
9768 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9774 when Attribute_Model
=>
9776 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9782 when Attribute_Model_Emin
=>
9783 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9789 when Attribute_Model_Epsilon
=>
9790 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9792 --------------------
9793 -- Model_Mantissa --
9794 --------------------
9796 when Attribute_Model_Mantissa
=>
9797 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9803 when Attribute_Model_Small
=>
9804 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9810 when Attribute_Modulus
=>
9811 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9813 --------------------
9814 -- Null_Parameter --
9815 --------------------
9817 -- Cannot fold, we know the value sort of, but the whole point is
9818 -- that there is no way to talk about this imaginary value except
9819 -- by using the attribute, so we leave it the way it is.
9821 when Attribute_Null_Parameter
=>
9828 -- The Object_Size attribute for a type returns the Esize of the
9829 -- type and can be folded if this value is known.
9831 when Attribute_Object_Size
=> Object_Size
: declare
9832 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9835 if Known_Esize
(P_TypeA
) then
9836 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9840 ----------------------
9841 -- Overlaps_Storage --
9842 ----------------------
9844 when Attribute_Overlaps_Storage
=>
9847 -------------------------
9848 -- Passed_By_Reference --
9849 -------------------------
9851 -- Scalar types are never passed by reference
9853 when Attribute_Passed_By_Reference
=>
9854 Fold_Uint
(N
, False_Value
, Static
);
9860 when Attribute_Pos
=>
9861 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9867 when Attribute_Pred
=>
9869 -- Floating-point case
9871 if Is_Floating_Point_Type
(P_Type
) then
9873 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9877 elsif Is_Fixed_Point_Type
(P_Type
) then
9879 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9881 -- Modular integer case (wraps)
9883 elsif Is_Modular_Integer_Type
(P_Type
) then
9884 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
9886 -- Other scalar cases
9889 pragma Assert
(Is_Scalar_Type
(P_Type
));
9891 if Is_Enumeration_Type
(P_Type
)
9892 and then Expr_Value
(E1
) =
9893 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9895 Apply_Compile_Time_Constraint_Error
9896 (N
, "Pred of `&''First`",
9897 CE_Overflow_Check_Failed
,
9899 Warn
=> not Static
);
9904 -- Rewrite the FE-constructed high bound of a null array
9905 -- aggregate to raise CE.
9907 elsif Is_Signed_Integer_Type
(P_Type
)
9908 and then Expr_Value
(E1
) =
9909 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9910 and then Is_Null_Array_Aggregate_High_Bound
(N
)
9912 Apply_Compile_Time_Constraint_Error
9913 (N
, "Pred of `&''First`",
9914 CE_Overflow_Check_Failed
,
9918 Rewrite
(N
, Make_Raise_Constraint_Error
(Sloc
(N
),
9919 Reason
=> CE_Overflow_Check_Failed
));
9920 Set_Etype
(N
, P_Base_Type
);
9924 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
9927 ----------------------------------
9928 -- Preelaborable_Initialization --
9929 ----------------------------------
9931 when Attribute_Preelaborable_Initialization
=>
9935 (Boolean'Pos (Has_Preelaborable_Initialization
(P_Type
))),
9942 -- No processing required, because by this stage, Range has been
9943 -- replaced by First .. Last, so this branch can never be taken.
9945 when Attribute_Range
=>
9946 raise Program_Error
;
9952 when Attribute_Range_Length
=> Range_Length
: declare
9953 Diff
: aliased Uint
;
9958 -- Can fold if both bounds are compile time known
9960 if Compile_Time_Known_Value
(Hi_Bound
)
9961 and then Compile_Time_Known_Value
(Lo_Bound
)
9965 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
9969 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9970 -- comparable, and we can figure out the difference between them.
9972 case Compile_Time_Compare
9973 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9976 Fold_Uint
(N
, Uint_1
, Static
);
9979 Fold_Uint
(N
, Uint_0
, Static
);
9982 if Present
(Diff
) then
9983 Fold_Uint
(N
, Diff
+ 1, Static
);
9995 when Attribute_Ref
=>
9996 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
10002 when Attribute_Remainder
=> Remainder
: declare
10003 X
: constant Ureal
:= Expr_Value_R
(E1
);
10004 Y
: constant Ureal
:= Expr_Value_R
(E2
);
10007 if UR_Is_Zero
(Y
) then
10008 Apply_Compile_Time_Constraint_Error
10009 (N
, "division by zero in Remainder",
10010 CE_Overflow_Check_Failed
,
10011 Warn
=> not Static
);
10017 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
10024 when Attribute_Restriction_Set
=>
10025 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
10026 Set_Is_Static_Expression
(N
);
10032 when Attribute_Round
=> Round
: declare
10037 -- First we get the (exact result) in units of small
10039 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
10041 -- Now round that exactly to an integer
10043 Si
:= UR_To_Uint
(Sr
);
10045 -- Finally the result is obtained by converting back to real
10047 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
10054 when Attribute_Rounding
=>
10056 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10062 when Attribute_Safe_Emax
=>
10063 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
10069 when Attribute_Safe_First
=>
10070 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
10076 when Attribute_Safe_Large
=>
10077 if Is_Fixed_Point_Type
(P_Type
) then
10079 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
10081 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10088 when Attribute_Safe_Last
=>
10089 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10095 when Attribute_Safe_Small
=>
10097 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
10098 -- for fixed-point, since is the same as Small, but we implement
10099 -- it for backwards compatibility.
10101 if Is_Fixed_Point_Type
(P_Type
) then
10102 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
10104 -- Ada 83 Safe_Small for floating-point cases
10107 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
10114 when Attribute_Scale
=>
10115 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
10121 when Attribute_Scaling
=>
10125 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
10132 when Attribute_Signed_Zeros
=>
10134 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
10140 -- Size attribute returns the RM size. All scalar types can be folded,
10141 -- as well as any types for which the size is known by the front end,
10142 -- including any type for which a size attribute is specified. This is
10143 -- one of the places where it is annoying that a size of zero means two
10144 -- things (zero size for scalars, unspecified size for non-scalars).
10146 when Attribute_Size
10147 | Attribute_VADS_Size
10150 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10154 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10155 if Known_RM_Size
(P_TypeA
) then
10158 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
10160 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
10163 -- If a size clause applies, then use the size from it.
10164 -- This is one of the rare cases where we can use the
10165 -- Size_Clause field for a subtype when Has_Size_Clause
10166 -- is False. Consider:
10168 -- type x is range 1 .. 64;
10169 -- for x'size use 12;
10170 -- subtype y is x range 0 .. 3;
10172 -- Here y has a size clause inherited from x, but
10173 -- normally it does not apply, and y'size is 2. However,
10174 -- y'VADS_Size is indeed 12 and not 2.
10177 and then Is_OK_Static_Expression
(Expression
(S
))
10179 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
10181 -- If no size is specified, then we simply use the object
10182 -- size in the VADS_Size case (e.g. Natural'Size is equal
10183 -- to Integer'Size, not one less).
10186 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
10190 -- Normal case (Size) in which case we want the RM_Size
10193 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10202 when Attribute_Small
=>
10204 -- The floating-point case is present only for Ada 83 compatibility.
10205 -- Note that strictly this is an illegal addition, since we are
10206 -- extending an Ada 95 defined attribute, but we anticipate an
10207 -- ARG ruling that will permit this.
10209 if Is_Floating_Point_Type
(P_Type
) then
10211 -- Ada 83 attribute is defined as (RM83 3.5.8)
10213 -- T'Small = 2.0**(-T'Emax - 1)
10217 -- T'Emax = 4 * T'Mantissa
10219 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
10221 -- Normal Ada 95 fixed-point case
10224 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
10227 -----------------------
10228 -- Small_Denominator --
10229 -----------------------
10231 when Attribute_Small_Denominator
=>
10232 Fold_Uint
(N
, Norm_Den
(Small_Value
(P_Type
)), True);
10234 ---------------------
10235 -- Small_Numerator --
10236 ---------------------
10238 when Attribute_Small_Numerator
=>
10239 Fold_Uint
(N
, Norm_Num
(Small_Value
(P_Type
)), True);
10245 when Attribute_Stream_Size
=>
10252 when Attribute_Succ
=>
10253 -- Floating-point case
10255 if Is_Floating_Point_Type
(P_Type
) then
10257 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10259 -- Fixed-point case
10261 elsif Is_Fixed_Point_Type
(P_Type
) then
10262 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
10264 -- Modular integer case (wraps)
10266 elsif Is_Modular_Integer_Type
(P_Type
) then
10267 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
10269 -- Other scalar cases
10272 pragma Assert
(Is_Scalar_Type
(P_Type
));
10274 if Is_Enumeration_Type
(P_Type
)
10275 and then Expr_Value
(E1
) =
10276 Expr_Value
(Type_High_Bound
(P_Base_Type
))
10278 Apply_Compile_Time_Constraint_Error
10279 (N
, "Succ of `&''Last`",
10280 CE_Overflow_Check_Failed
,
10281 Ent
=> P_Base_Type
,
10282 Warn
=> not Static
);
10287 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
10295 when Attribute_Truncation
=>
10298 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
10305 when Attribute_Type_Class
=> Type_Class
: declare
10306 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
10310 if Is_Descendant_Of_Address
(Typ
) then
10311 Id
:= RE_Type_Class_Address
;
10313 elsif Is_Enumeration_Type
(Typ
) then
10314 Id
:= RE_Type_Class_Enumeration
;
10316 elsif Is_Integer_Type
(Typ
) then
10317 Id
:= RE_Type_Class_Integer
;
10319 elsif Is_Fixed_Point_Type
(Typ
) then
10320 Id
:= RE_Type_Class_Fixed_Point
;
10322 elsif Is_Floating_Point_Type
(Typ
) then
10323 Id
:= RE_Type_Class_Floating_Point
;
10325 elsif Is_Array_Type
(Typ
) then
10326 Id
:= RE_Type_Class_Array
;
10328 elsif Is_Record_Type
(Typ
) then
10329 Id
:= RE_Type_Class_Record
;
10331 elsif Is_Access_Type
(Typ
) then
10332 Id
:= RE_Type_Class_Access
;
10334 elsif Is_Task_Type
(Typ
) then
10335 Id
:= RE_Type_Class_Task
;
10337 -- We treat protected types like task types. It would make more
10338 -- sense to have another enumeration value, but after all the
10339 -- whole point of this feature is to be exactly DEC compatible,
10340 -- and changing the type Type_Class would not meet this requirement.
10342 elsif Is_Protected_Type
(Typ
) then
10343 Id
:= RE_Type_Class_Task
;
10345 -- Not clear if there are any other possibilities, but if there
10346 -- are, then we will treat them as the address case.
10349 Id
:= RE_Type_Class_Address
;
10352 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
10355 -----------------------
10356 -- Unbiased_Rounding --
10357 -----------------------
10359 when Attribute_Unbiased_Rounding
=>
10362 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
10365 -------------------------
10366 -- Unconstrained_Array --
10367 -------------------------
10369 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
10370 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10373 Rewrite
(N
, New_Occurrence_Of
(
10375 Is_Array_Type
(P_Type
)
10376 and then not Is_Constrained
(Typ
)), Loc
));
10378 -- Analyze and resolve as boolean, note that this attribute is
10379 -- a static attribute in GNAT.
10381 Analyze_And_Resolve
(N
, Standard_Boolean
);
10383 Set_Is_Static_Expression
(N
, True);
10384 end Unconstrained_Array
;
10386 -- Attribute Update is never static
10388 when Attribute_Update
=>
10395 -- Processing is shared with Size
10401 when Attribute_Val
=>
10402 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
10404 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
10406 Apply_Compile_Time_Constraint_Error
10407 (N
, "Val expression out of range",
10408 CE_Range_Check_Failed
,
10409 Warn
=> not Static
);
10415 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
10422 -- The Value_Size attribute for a type returns the RM size of the type.
10423 -- This an always be folded for scalar types, and can also be folded for
10424 -- non-scalar types if the size is set. This is one of the places where
10425 -- it is annoying that a size of zero means two things!
10427 when Attribute_Value_Size
=> Value_Size
: declare
10428 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10432 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10433 if Known_RM_Size
(P_TypeA
) then
10434 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10442 -- Version can never be static
10444 when Attribute_Version
=>
10451 -- Wide_Image is a scalar attribute, but is never static, because it
10452 -- is not a static function (having a non-scalar argument (RM 4.9(22))
10454 when Attribute_Wide_Image
=>
10457 ---------------------
10458 -- Wide_Wide_Image --
10459 ---------------------
10461 -- Wide_Wide_Image is a scalar attribute but is never static, because it
10462 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
10464 when Attribute_Wide_Wide_Image
=>
10467 ---------------------
10468 -- Wide_Wide_Width --
10469 ---------------------
10471 -- Processing for Wide_Wide_Width is combined with Width
10477 -- Processing for Wide_Width is combined with Width
10483 -- This processing also handles the case of Wide_[Wide_]Width
10485 when Attribute_Width
10486 | Attribute_Wide_Width
10487 | Attribute_Wide_Wide_Width
10489 if Compile_Time_Known_Bounds
(P_Type
) then
10491 -- Floating-point types
10493 if Is_Floating_Point_Type
(P_Type
) then
10495 -- Width is zero for a null range (RM 3.5 (38))
10497 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
10498 Expr_Value_R
(Type_Low_Bound
(P_Type
))
10500 Fold_Uint
(N
, Uint_0
, Static
);
10503 -- For floating-point, we have +N.dddE+nnn where length
10504 -- of ddd is determined by type'Digits - 1, but is one
10505 -- if Digits is one (RM 3.5 (33)).
10507 -- nnn is set to 2 for Short_Float and Float (32 bit
10508 -- floats), and 3 for Long_Float and Long_Long_Float.
10509 -- For machines where Long_Long_Float is the IEEE
10510 -- extended precision type, the exponent takes 4 digits.
10514 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
10517 if Esize
(P_Type
) <= 32 then
10519 elsif Esize
(P_Type
) = 64 then
10525 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
10529 -- Fixed-point types
10531 elsif Is_Fixed_Point_Type
(P_Type
) then
10533 -- Width is zero for a null range (RM 3.5 (38))
10535 if Expr_Value
(Type_High_Bound
(P_Type
)) <
10536 Expr_Value
(Type_Low_Bound
(P_Type
))
10538 Fold_Uint
(N
, Uint_0
, Static
);
10540 -- The non-null case depends on the specific real type
10543 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
10546 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
10554 R
: constant Entity_Id
:= Root_Type
(P_Type
);
10555 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
10556 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
10569 -- Width for types derived from Standard.Character
10570 -- and Standard.Wide_[Wide_]Character.
10572 elsif Is_Standard_Character_Type
(P_Type
) then
10575 -- Set W larger if needed
10577 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
10579 -- All wide characters look like Hex_hhhhhhhh
10583 -- No need to compute this more than once
10588 C
:= Character'Val (J
);
10590 -- Test for all cases where Character'Image
10591 -- yields an image that is longer than three
10592 -- characters. First the cases of Reserved_xxx
10593 -- names (length = 12).
10670 when Space
.. Tilde
10671 | No_Break_Space
.. LC_Y_Diaeresis
10673 -- Special case of soft hyphen in Ada 2005
10675 if C
= Character'Val (16#AD#
)
10676 and then Ada_Version
>= Ada_2005
10684 W
:= Int
'Max (W
, Wt
);
10688 -- Width for types derived from Standard.Boolean
10690 elsif R
= Standard_Boolean
then
10697 -- Width for integer types
10699 elsif Is_Integer_Type
(P_Type
) then
10700 T
:= UI_Max
(abs Lo
, abs Hi
);
10708 -- User declared enum type with discard names
10710 elsif Discard_Names
(R
) then
10712 -- If range is null, result is zero, that has already
10713 -- been dealt with, so what we need is the power of ten
10714 -- that accommodates the Pos of the largest value, which
10715 -- is the high bound of the range + one for the space.
10724 -- Only remaining possibility is user declared enum type
10725 -- with normal case of Discard_Names not active.
10728 pragma Assert
(Is_Enumeration_Type
(P_Type
));
10731 L
:= First_Literal
(P_Type
);
10732 while Present
(L
) loop
10734 -- Only pay attention to in range characters
10736 if Lo
<= Enumeration_Pos
(L
)
10737 and then Enumeration_Pos
(L
) <= Hi
10739 -- For Width case, use decoded name
10741 if Id
= Attribute_Width
then
10742 Get_Decoded_Name_String
(Chars
(L
));
10743 Wt
:= Nat
(Name_Len
);
10745 -- For Wide_[Wide_]Width, use encoded name, and
10746 -- then adjust for the encoding.
10749 Get_Name_String
(Chars
(L
));
10751 -- Character literals are always of length 3
10753 if Name_Buffer
(1) = 'Q' then
10756 -- Otherwise loop to adjust for upper/wide chars
10759 Wt
:= Nat
(Name_Len
);
10761 for J
in 1 .. Name_Len
loop
10762 if Name_Buffer
(J
) = 'U' then
10764 elsif Name_Buffer
(J
) = 'W' then
10771 W
:= Int
'Max (W
, Wt
);
10778 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
10783 -- The following attributes denote functions that cannot be folded
10785 when Attribute_From_Any
10787 | Attribute_TypeCode
10791 -- The following attributes can never be folded, and furthermore we
10792 -- should not even have entered the case statement for any of these.
10793 -- Note that in some cases, the values have already been folded as
10794 -- a result of the processing in Analyze_Attribute or earlier in
10797 when Attribute_Abort_Signal
10799 | Attribute_Address
10800 | Attribute_Address_Size
10801 | Attribute_Asm_Input
10802 | Attribute_Asm_Output
10804 | Attribute_Bit_Order
10805 | Attribute_Bit_Position
10806 | Attribute_Callable
10809 | Attribute_Code_Address
10810 | Attribute_Compiler_Version
10812 | Attribute_Default_Bit_Order
10813 | Attribute_Default_Scalar_Storage_Order
10815 | Attribute_Elaborated
10816 | Attribute_Elab_Body
10817 | Attribute_Elab_Spec
10818 | Attribute_Elab_Subp_Body
10819 | Attribute_Enabled
10820 | Attribute_External_Tag
10821 | Attribute_Fast_Math
10822 | Attribute_First_Bit
10826 | Attribute_Initialized
10827 | Attribute_Last_Bit
10828 | Attribute_Library_Level
10829 | Attribute_Max_Integer_Size
10830 | Attribute_Maximum_Alignment
10833 | Attribute_Partition_ID
10834 | Attribute_Pool_Address
10835 | Attribute_Position
10836 | Attribute_Priority
10837 | Attribute_Put_Image
10840 | Attribute_Scalar_Storage_Order
10841 | Attribute_Simple_Storage_Pool
10842 | Attribute_Storage_Pool
10843 | Attribute_Storage_Size
10844 | Attribute_Storage_Unit
10845 | Attribute_Stub_Type
10846 | Attribute_System_Allocator_Alignment
10848 | Attribute_Target_Name
10849 | Attribute_Terminated
10850 | Attribute_To_Address
10851 | Attribute_Type_Key
10852 | Attribute_Unchecked_Access
10853 | Attribute_Universal_Literal_String
10854 | Attribute_Unrestricted_Access
10856 | Attribute_Valid_Scalars
10857 | Attribute_Valid_Value
10859 | Attribute_Wchar_T_Size
10860 | Attribute_Wide_Value
10861 | Attribute_Wide_Wide_Value
10862 | Attribute_Word_Size
10865 raise Program_Error
;
10868 -- At the end of the case, one more check. If we did a static evaluation
10869 -- so that the result is now a literal, then set Is_Static_Expression
10870 -- in the constant only if the prefix type is a static subtype. For
10871 -- non-static subtypes, the folding is still OK, but not static.
10873 -- An exception is the GNAT attribute Constrained_Array which is
10874 -- defined to be a static attribute in all cases.
10876 if Nkind
(N
) in N_Integer_Literal
10878 | N_Character_Literal
10880 or else (Is_Entity_Name
(N
)
10881 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10883 Set_Is_Static_Expression
(N
, Static
);
10885 -- If this is still an attribute reference, then it has not been folded
10886 -- and that means that its expressions are in a non-static context.
10888 elsif Nkind
(N
) = N_Attribute_Reference
then
10891 -- Note: the else case not covered here are odd cases where the
10892 -- processing has transformed the attribute into something other
10893 -- than a constant. Nothing more to do in such cases.
10898 end Eval_Attribute
;
10900 ------------------------------
10901 -- Is_Anonymous_Tagged_Base --
10902 ------------------------------
10904 function Is_Anonymous_Tagged_Base
10906 Typ
: Entity_Id
) return Boolean
10910 Anon
= Current_Scope
10911 and then Is_Itype
(Anon
)
10912 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
10913 end Is_Anonymous_Tagged_Base
;
10915 --------------------------------
10916 -- Name_Implies_Lvalue_Prefix --
10917 --------------------------------
10919 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
10920 pragma Assert
(Is_Attribute_Name
(Nam
));
10922 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
10923 end Name_Implies_Lvalue_Prefix
;
10925 -----------------------
10926 -- Resolve_Attribute --
10927 -----------------------
10929 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
10930 Loc
: constant Source_Ptr
:= Sloc
(N
);
10931 P
: constant Node_Id
:= Prefix
(N
);
10932 Aname
: constant Name_Id
:= Attribute_Name
(N
);
10933 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
10934 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10935 Des_Btyp
: Entity_Id
;
10936 Index
: Interp_Index
;
10938 Nom_Subt
: Entity_Id
;
10940 function Declared_Within_Generic_Unit
10941 (Entity
: Entity_Id
;
10942 Generic_Unit
: Node_Id
) return Boolean;
10943 -- Returns True if Declared_Entity is declared within the declarative
10944 -- region of Generic_Unit; otherwise returns False.
10946 ----------------------------------
10947 -- Declared_Within_Generic_Unit --
10948 ----------------------------------
10950 function Declared_Within_Generic_Unit
10951 (Entity
: Entity_Id
;
10952 Generic_Unit
: Node_Id
) return Boolean
10954 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
10957 while Present
(Generic_Encloser
) loop
10958 if Generic_Encloser
= Generic_Unit
then
10962 -- We have to step to the scope of the generic's entity, because
10963 -- otherwise we'll just get back the same generic.
10965 Generic_Encloser
:=
10966 Enclosing_Generic_Unit
10967 (Scope
(Defining_Entity
(Generic_Encloser
)));
10971 end Declared_Within_Generic_Unit
;
10973 -- Start of processing for Resolve_Attribute
10976 -- If error during analysis, no point in continuing, except for array
10977 -- types, where we get better recovery by using unconstrained indexes
10978 -- than nothing at all (see Check_Array_Type).
10980 if Error_Posted
(N
)
10981 and then Attr_Id
/= Attribute_First
10982 and then Attr_Id
/= Attribute_Last
10983 and then Attr_Id
/= Attribute_Length
10984 and then Attr_Id
/= Attribute_Range
10989 -- If attribute was universal type, reset to actual type
10991 if Is_Universal_Numeric_Type
(Etype
(N
)) then
10992 Set_Etype
(N
, Typ
);
10995 -- Remaining processing depends on attribute
11003 -- For access attributes, if the prefix denotes an entity, it is
11004 -- interpreted as a name, never as a call. It may be overloaded,
11005 -- in which case resolution uses the profile of the context type.
11006 -- Otherwise prefix must be resolved.
11008 when Attribute_Access
11009 | Attribute_Unchecked_Access
11010 | Attribute_Unrestricted_Access
11012 -- Note possible modification if we have a variable
11015 and then not Is_Access_Constant
(Typ
)
11017 Note_Possible_Modification
(P
, Sure
=> False);
11020 -- Case where prefix is an entity name
11022 if Is_Entity_Name
(P
) then
11024 -- Deal with case where prefix itself is overloaded
11026 if Is_Overloaded
(P
) then
11027 Get_First_Interp
(P
, Index
, It
);
11028 while Present
(It
.Nam
) loop
11029 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11030 Set_Entity
(P
, It
.Nam
);
11032 -- The prefix is definitely NOT overloaded anymore at
11033 -- this point, so we reset the Is_Overloaded flag to
11034 -- avoid any confusion when reanalyzing the node.
11036 Set_Is_Overloaded
(P
, False);
11037 Set_Is_Overloaded
(N
, False);
11038 Generate_Reference
(Entity
(P
), P
);
11042 Get_Next_Interp
(Index
, It
);
11045 -- If Prefix is a subprogram name, this reference freezes,
11046 -- but not if within spec expression mode. The profile of
11047 -- the subprogram is not frozen at this point.
11049 if not In_Spec_Expression
then
11050 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11053 -- If it is a type, there is nothing to resolve.
11054 -- If it is a subprogram, do not freeze its profile.
11055 -- If it is an object, complete its resolution.
11057 elsif Is_Overloadable
(Entity
(P
)) then
11058 if not In_Spec_Expression
then
11059 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11062 -- Nothing to do if prefix is a type name
11064 elsif Is_Type
(Entity
(P
)) then
11067 -- Otherwise non-overloaded other case, resolve the prefix
11073 -- Some further error checks
11075 Error_Msg_Name_1
:= Aname
;
11077 if not Is_Entity_Name
(P
) then
11080 elsif Is_Overloadable
(Entity
(P
))
11081 and then Is_Abstract_Subprogram
(Entity
(P
))
11083 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
11084 Set_Etype
(N
, Any_Type
);
11086 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
11088 ("prefix of % attribute cannot be enumeration literal", P
);
11089 Set_Etype
(N
, Any_Type
);
11091 -- An attempt to take 'Access of a function that renames an
11092 -- enumeration literal. Issue a specialized error message.
11094 elsif Ekind
(Entity
(P
)) = E_Function
11095 and then Present
(Alias
(Entity
(P
)))
11096 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
11099 ("prefix of % attribute cannot be function renaming "
11100 & "an enumeration literal", P
);
11101 Set_Etype
(N
, Any_Type
);
11103 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
11104 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
11105 Set_Etype
(N
, Any_Type
);
11108 -- Assignments, return statements, components of aggregates,
11109 -- generic instantiations will require convention checks if
11110 -- the type is an access to subprogram. Given that there will
11111 -- also be accessibility checks on those, this is where the
11112 -- checks can eventually be centralized ???
11114 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11115 | E_Access_Subprogram_Type
11116 | E_Anonymous_Access_Protected_Subprogram_Type
11117 | E_Anonymous_Access_Subprogram_Type
11119 -- Deal with convention mismatch
11121 if Convention
(Designated_Type
(Btyp
)) /=
11122 Convention
(Entity
(P
))
11125 ("subprogram & has wrong convention", P
, Entity
(P
));
11126 Error_Msg_Sloc
:= Sloc
(Btyp
);
11127 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
11129 if not Is_Itype
(Btyp
)
11130 and then not Has_Convention_Pragma
(Btyp
)
11131 and then Convention
(Entity
(P
)) /= Convention_Intrinsic
11134 ("\probable missing pragma Convention for &",
11139 Check_Subtype_Conformant
11140 (New_Id
=> Entity
(P
),
11141 Old_Id
=> Designated_Type
(Btyp
),
11145 if Attr_Id
= Attribute_Unchecked_Access
then
11146 Error_Msg_Name_1
:= Aname
;
11148 ("attribute% cannot be applied to a subprogram", P
);
11150 elsif Aname
= Name_Unrestricted_Access
then
11151 null; -- Nothing to check
11153 -- Check the static accessibility rule of 3.10.2(32).
11154 -- This rule also applies within the private part of an
11155 -- instantiation. This rule does not apply to anonymous
11156 -- access-to-subprogram types in access parameters.
11158 elsif Attr_Id
= Attribute_Access
11159 and then not In_Instance_Body
11161 (Ekind
(Btyp
) = E_Access_Subprogram_Type
11162 or else Is_Local_Anonymous_Access
(Btyp
))
11163 and then Subprogram_Access_Level
(Entity
(P
)) >
11164 Type_Access_Level
(Btyp
)
11167 ("subprogram must not be deeper than access type", P
);
11169 -- Check the restriction of 3.10.2(32) that disallows the
11170 -- access attribute within a generic body when the ultimate
11171 -- ancestor of the type of the attribute is declared outside
11172 -- of the generic unit and the subprogram is declared within
11173 -- that generic unit. This includes any such attribute that
11174 -- occurs within the body of a generic unit that is a child
11175 -- of the generic unit where the subprogram is declared.
11177 -- The rule also prohibits applying the attribute when the
11178 -- access type is a generic formal access type (since the
11179 -- level of the actual type is not known). This restriction
11180 -- does not apply when the attribute type is an anonymous
11181 -- access-to-subprogram type. Note that this check was
11182 -- revised by AI-229, because the original Ada 95 rule
11183 -- was too lax. The original rule only applied when the
11184 -- subprogram was declared within the body of the generic,
11185 -- which allowed the possibility of dangling references).
11186 -- The rule was also too strict in some cases, in that it
11187 -- didn't permit the access to be declared in the generic
11188 -- spec, whereas the revised rule does (as long as it's not
11191 -- There are a couple of subtleties of the test for applying
11192 -- the check that are worth noting. First, we only apply it
11193 -- when the levels of the subprogram and access type are the
11194 -- same (the case where the subprogram is statically deeper
11195 -- was applied above, and the case where the type is deeper
11196 -- is always safe). Second, we want the check to apply
11197 -- within nested generic bodies and generic child unit
11198 -- bodies, but not to apply to an attribute that appears in
11199 -- the generic unit's specification. This is done by testing
11200 -- that the attribute's innermost enclosing generic body is
11201 -- not the same as the innermost generic body enclosing the
11202 -- generic unit where the subprogram is declared (we don't
11203 -- want the check to apply when the access attribute is in
11204 -- the spec and there's some other generic body enclosing
11205 -- generic). Finally, there's no point applying the check
11206 -- when within an instance, because any violations will have
11207 -- been caught by the compilation of the generic unit.
11209 -- We relax this check in Relaxed_RM_Semantics mode for
11210 -- compatibility with legacy code for use by Ada source
11211 -- code analyzers (e.g. CodePeer).
11213 elsif Attr_Id
= Attribute_Access
11214 and then not Relaxed_RM_Semantics
11215 and then not In_Instance
11216 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
11217 and then Present
(Enclosing_Generic_Body
(N
))
11218 and then Enclosing_Generic_Body
(N
) /=
11219 Enclosing_Generic_Body
11220 (Enclosing_Generic_Unit
(Entity
(P
)))
11221 and then Subprogram_Access_Level
(Entity
(P
)) =
11222 Type_Access_Level
(Btyp
)
11223 and then Ekind
(Btyp
) /=
11224 E_Anonymous_Access_Subprogram_Type
11225 and then Ekind
(Btyp
) /=
11226 E_Anonymous_Access_Protected_Subprogram_Type
11228 -- The attribute type's ultimate ancestor must be
11229 -- declared within the same generic unit as the
11230 -- subprogram is declared (including within another
11231 -- nested generic unit). The error message is
11232 -- specialized to say "ancestor" for the case where the
11233 -- access type is not its own ancestor, since saying
11234 -- simply "access type" would be very confusing.
11236 if not Declared_Within_Generic_Unit
11238 Enclosing_Generic_Unit
(Entity
(P
)))
11241 ("''Access attribute not allowed in generic body",
11244 if Root_Type
(Btyp
) = Btyp
then
11247 "access type & is declared outside " &
11248 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11251 ("\because ancestor of " &
11252 "access type & is declared outside " &
11253 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11257 ("\move ''Access to private part, or " &
11258 "(Ada 2005) use anonymous access type instead of &",
11261 -- If the ultimate ancestor of the attribute's type is
11262 -- a formal type, then the attribute is illegal because
11263 -- the actual type might be declared at a higher level.
11264 -- The error message is specialized to say "ancestor"
11265 -- for the case where the access type is not its own
11266 -- ancestor, since saying simply "access type" would be
11269 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
11270 if Root_Type
(Btyp
) = Btyp
then
11272 ("access type must not be a generic formal type",
11276 ("ancestor access type must not be a generic " &
11283 -- If this is a renaming, an inherited operation, or a
11284 -- subprogram instance, use the original entity. This may make
11285 -- the node type-inconsistent, so this transformation can only
11286 -- be done if the node will not be reanalyzed. In particular,
11287 -- if it is within a default expression, the transformation
11288 -- must be delayed until the default subprogram is created for
11289 -- it, when the enclosing subprogram is frozen.
11291 if Is_Entity_Name
(P
)
11292 and then Is_Overloadable
(Entity
(P
))
11293 and then Present
(Alias
(Entity
(P
)))
11294 and then Expander_Active
11297 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11300 elsif Nkind
(P
) = N_Selected_Component
11301 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
11303 -- Protected operation. If operation is overloaded, must
11304 -- disambiguate. Prefix that denotes protected object itself
11305 -- is resolved with its own type.
11307 if Attr_Id
= Attribute_Unchecked_Access
then
11308 Error_Msg_Name_1
:= Aname
;
11310 ("attribute% cannot be applied to protected operation", P
);
11313 Resolve
(Prefix
(P
));
11315 if not Is_Overloaded
(P
) then
11316 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11319 Get_First_Interp
(P
, Index
, It
);
11320 while Present
(It
.Nam
) loop
11321 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11322 Set_Entity
(Selector_Name
(P
), It
.Nam
);
11324 -- The prefix is definitely NOT overloaded anymore at
11325 -- this point, so we reset the Is_Overloaded flag to
11326 -- avoid any confusion when reanalyzing the node.
11328 Set_Is_Overloaded
(P
, False);
11329 Set_Is_Overloaded
(N
, False);
11330 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11334 Get_Next_Interp
(Index
, It
);
11338 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
11339 -- statically illegal if F is an anonymous access to subprogram.
11341 elsif Nkind
(P
) = N_Explicit_Dereference
11342 and then Is_Entity_Name
(Prefix
(P
))
11343 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
11344 E_Anonymous_Access_Subprogram_Type
11346 Error_Msg_N
("anonymous access to subprogram "
11347 & "has deeper accessibility than any master", P
);
11349 elsif Is_Overloaded
(P
) then
11351 -- Use the designated type of the context to disambiguate
11352 -- Note that this was not strictly conformant to Ada 95,
11353 -- but was the implementation adopted by most Ada 95 compilers.
11354 -- The use of the context type to resolve an Access attribute
11355 -- reference is now mandated in AI-235 for Ada 2005.
11358 Index
: Interp_Index
;
11362 Get_First_Interp
(P
, Index
, It
);
11363 while Present
(It
.Typ
) loop
11364 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
11365 Resolve
(P
, It
.Typ
);
11369 Get_Next_Interp
(Index
, It
);
11376 -- Refuse to compute access to variables and constants when that
11377 -- would drop the strub mode associated with them, unless they're
11378 -- unchecked conversions. We don't have to do this when the types
11379 -- of the data objects are annotated: then the access type
11380 -- designates the annotated type, and there's no loss. Only when
11381 -- the variable is annotated directly that the pragma gets
11382 -- attached to the variable, rather than to its type, and then,
11383 -- expressing an access-to-annotated-type type to hold the 'Access
11384 -- result is not possible without resorting to that very annotated
11387 if Attr_Id
/= Attribute_Unchecked_Access
11388 and then Comes_From_Source
(N
)
11389 and then Is_Entity_Name
(P
)
11390 and then Explicit_Strub_Mode
(Entity
(P
)) = Enabled
11392 Explicit_Strub_Mode
(Designated_Type
(Btyp
)) = Unspecified
11394 Error_Msg_F
("target access type drops `strub` mode from &", P
);
11397 -- X'Access is illegal if X denotes a constant and the access type
11398 -- is access-to-variable. Same for 'Unchecked_Access. The rule
11399 -- does not apply to 'Unrestricted_Access. If the reference is a
11400 -- default-initialized aggregate component for a self-referential
11401 -- type the reference is legal.
11403 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
11404 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
11405 or else (Is_Record_Type
(Btyp
)
11407 Present
(Corresponding_Remote_Type
(Btyp
)))
11408 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11409 or else Ekind
(Btyp
)
11410 = E_Anonymous_Access_Protected_Subprogram_Type
11411 or else Is_Access_Constant
(Btyp
)
11412 or else Is_Variable
(P
)
11413 or else Attr_Id
= Attribute_Unrestricted_Access
)
11415 if Is_Entity_Name
(P
)
11416 and then Is_Type
(Entity
(P
))
11418 -- Legality of a self-reference through an access
11419 -- attribute has been verified in Analyze_Access_Attribute.
11423 elsif Comes_From_Source
(N
) then
11424 Error_Msg_F
("access-to-variable designates constant", P
);
11428 Des_Btyp
:= Designated_Type
(Btyp
);
11430 if Ada_Version
>= Ada_2005
11431 and then Is_Incomplete_Type
(Des_Btyp
)
11433 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
11434 -- imported entity, and the non-limited view is visible, make
11435 -- use of it. If it is an incomplete subtype, use the base type
11438 if From_Limited_With
(Des_Btyp
)
11439 and then Present
(Non_Limited_View
(Des_Btyp
))
11441 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
11443 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
11444 Des_Btyp
:= Etype
(Des_Btyp
);
11448 if Attr_Id
in Attribute_Access | Attribute_Unchecked_Access
11449 and then (Ekind
(Btyp
) = E_General_Access_Type
11450 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
11452 -- Ada 2005 (AI-230): Check the accessibility of anonymous
11453 -- access types for stand-alone objects, record and array
11454 -- components, and return objects. For a component definition
11455 -- the level is the same of the enclosing composite type.
11457 if Ada_Version
>= Ada_2005
11458 and then (Is_Local_Anonymous_Access
(Btyp
)
11460 -- Handle cases where Btyp is the anonymous access
11461 -- type of an Ada 2012 stand-alone object.
11463 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
11464 N_Object_Declaration
)
11465 and then Attr_Id
= Attribute_Access
11467 -- Verify that static checking is OK (namely that we aren't
11468 -- in a specific context requiring dynamic checks on
11469 -- expicitly aliased parameters), and then check the level.
11471 -- Otherwise a check will be generated later when the return
11472 -- statement gets expanded.
11474 and then not Is_Special_Aliased_Formal_Access
(N
)
11476 Static_Accessibility_Level
(N
, Zero_On_Dynamic_Level
) >
11477 Deepest_Type_Access_Level
(Btyp
)
11479 -- In an instance, this is a runtime check, but one we know
11480 -- will fail, so generate an appropriate warning. As usual,
11481 -- this kind of warning is an error in SPARK mode.
11483 if In_Instance_Body
then
11487 not No_Dynamic_Accessibility_Checks_Enabled
(P
);
11490 ("non-local pointer cannot point to local object<<", P
);
11491 Error_Msg_F
("\Program_Error [<<", P
);
11494 Make_Raise_Program_Error
(Loc
,
11495 Reason
=> PE_Accessibility_Check_Failed
));
11496 Set_Etype
(N
, Typ
);
11500 ("non-local pointer cannot point to local object", P
);
11504 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
11506 ("illegal attribute for discriminant-dependent component",
11510 -- Check static matching rule of 3.10.2(27). Nominal subtype
11511 -- of the prefix must statically match the designated type.
11513 Nom_Subt
:= Etype
(P
);
11515 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
11516 Nom_Subt
:= Base_Type
(Nom_Subt
);
11519 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
11521 -- If the attribute is in the context of an access
11522 -- parameter, then the prefix is allowed to be of
11523 -- the class-wide type (by AI-127).
11525 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
11526 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11527 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
11533 Desig
:= Designated_Type
(Typ
);
11535 if Is_Class_Wide_Type
(Desig
) then
11536 Desig
:= Etype
(Desig
);
11539 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
11544 ("type of prefix: & not compatible",
11547 ("\with &, the expected designated type",
11548 P
, Designated_Type
(Typ
));
11553 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11555 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11556 and then Is_Class_Wide_Type
(Nom_Subt
))
11559 ("type of prefix: & is not covered", P
, Nom_Subt
);
11561 ("\by &, the expected designated type" &
11562 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
11565 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
11566 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
11567 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
11568 and then Designated_Type
(Typ
) /= Nom_Subt
11570 Apply_Discriminant_Check
11571 (N
, Etype
(Designated_Type
(Typ
)));
11574 -- Ada 2005 (AI-363): Require static matching when designated
11575 -- type has discriminants and a constrained partial view, since
11576 -- in general objects of such types are mutable, so we can't
11577 -- allow the access value to designate a constrained object
11578 -- (because access values must be assumed to designate mutable
11579 -- objects when designated type does not impose a constraint).
11581 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
11584 elsif Has_Discriminants
(Designated_Type
(Typ
))
11585 and then not Is_Constrained
(Des_Btyp
)
11587 (Ada_Version
< Ada_2005
11589 not Object_Type_Has_Constrained_Partial_View
11590 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
11591 Scop
=> Current_Scope
))
11597 ("object subtype must statically match "
11598 & "designated subtype", P
);
11600 if Is_Entity_Name
(P
)
11601 and then Is_Array_Type
(Designated_Type
(Typ
))
11604 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
11607 ("aliased object has explicit bounds??", D
);
11609 ("\declare without bounds (and with explicit "
11610 & "initialization)??", D
);
11612 ("\for use with unconstrained access??", D
);
11617 -- Check the static accessibility rule of 3.10.2(28). Note that
11618 -- this check is not performed for the case of an anonymous
11619 -- access type, since the access attribute is always legal
11620 -- in such a context - unless the restriction
11621 -- No_Dynamic_Accessibility_Checks is active.
11624 No_Dynamic_Acc_Checks
: constant Boolean :=
11625 No_Dynamic_Accessibility_Checks_Enabled
(Btyp
);
11627 Compatible_Alt_Checks
: constant Boolean :=
11628 No_Dynamic_Acc_Checks
and then not Debug_Flag_Underscore_B
;
11630 if Attr_Id
/= Attribute_Unchecked_Access
11631 and then (Ekind
(Btyp
) = E_General_Access_Type
11632 or else No_Dynamic_Acc_Checks
)
11634 -- In the case of the alternate "compatibility"
11635 -- accessibility model we do not perform a static
11636 -- accessibility check on actuals for anonymous access
11637 -- types - so exclude them here.
11639 and then not (Compatible_Alt_Checks
11640 and then Is_Actual_Parameter
(N
)
11641 and then Ekind
(Btyp
)
11642 = E_Anonymous_Access_Type
)
11644 -- Call Accessibility_Level directly to avoid returning
11645 -- zero on cases where the prefix is an explicitly aliased
11646 -- parameter in a return statement, instead of using the
11647 -- normal Static_Accessibility_Level function.
11649 -- Shouldn't this be handled somehow in
11650 -- Static_Accessibility_Level ???
11652 and then Nkind
(Accessibility_Level
(P
, Dynamic_Level
))
11653 = N_Integer_Literal
11655 Intval
(Accessibility_Level
(P
, Dynamic_Level
))
11656 > Deepest_Type_Access_Level
(Btyp
)
11658 Accessibility_Message
(N
, Typ
);
11664 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11665 | E_Anonymous_Access_Protected_Subprogram_Type
11667 if Is_Entity_Name
(P
)
11668 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
11670 Error_Msg_F
("context requires a protected subprogram", P
);
11672 -- Check accessibility of protected object against that of the
11673 -- access type, but only on user code, because the expander
11674 -- creates access references for handlers. If the context is an
11675 -- anonymous_access_to_protected, there are no accessibility
11676 -- checks either. Omit check entirely for Unrestricted_Access.
11678 elsif Static_Accessibility_Level
(P
, Zero_On_Dynamic_Level
)
11679 > Deepest_Type_Access_Level
(Btyp
)
11680 and then Comes_From_Source
(N
)
11681 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11682 and then Attr_Id
/= Attribute_Unrestricted_Access
11684 Accessibility_Message
(N
, Typ
);
11687 -- AI05-0225: If the context is not an access to protected
11688 -- function, the prefix must be a variable, given that it may
11689 -- be used subsequently in a protected call.
11691 elsif Nkind
(P
) = N_Selected_Component
11692 and then not Is_Variable
(Prefix
(P
))
11693 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
11696 ("target object of access to protected procedure "
11697 & "must be variable", N
);
11699 elsif Is_Entity_Name
(P
) then
11700 Check_Internal_Protected_Use
(N
, Entity
(P
));
11703 elsif Ekind
(Btyp
) in E_Access_Subprogram_Type
11704 | E_Anonymous_Access_Subprogram_Type
11705 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
11707 Error_Msg_F
("context requires a non-protected subprogram", P
);
11710 -- AI12-0412: The rule in RM 6.1.1(18.2/5) disallows applying
11711 -- attribute Access to a primitive of an abstract type when the
11712 -- primitive has any Pre'Class or Post'Class aspects specified
11713 -- with nonstatic expressions.
11715 if Attr_Id
= Attribute_Access
11716 and then Ekind
(Btyp
) in E_Access_Subprogram_Type
11717 | E_Anonymous_Access_Subprogram_Type
11718 and then Is_Entity_Name
(P
)
11719 and then Is_Dispatching_Operation
(Entity
(P
))
11721 Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
(Entity
(P
))
11724 ("attribute not allowed for primitive of abstract type with "
11725 & "nonstatic class-wide pre/postconditions",
11729 -- The context cannot be a pool-specific type, but this is a
11730 -- legality rule, not a resolution rule, so it must be checked
11731 -- separately, after possibly disambiguation (see AI-245).
11733 if Ekind
(Btyp
) = E_Access_Type
11734 and then Attr_Id
/= Attribute_Unrestricted_Access
11736 Wrong_Type
(N
, Typ
);
11739 -- The context may be a constrained access type (however ill-
11740 -- advised such subtypes might be) so in order to generate a
11741 -- constraint check we need to set the type of the attribute
11742 -- reference to the base type of the context.
11744 Set_Etype
(N
, Btyp
);
11746 -- Check for incorrect atomic/volatile/VFA reference (RM C.6(12))
11748 if Attr_Id
/= Attribute_Unrestricted_Access
then
11749 if Is_Atomic_Object
(P
)
11750 and then not Is_Atomic
(Designated_Type
(Typ
))
11753 ("access to atomic object cannot yield access-to-" &
11754 "non-atomic type", P
);
11756 elsif Is_Volatile_Object_Ref
(P
)
11757 and then not Is_Volatile
(Designated_Type
(Typ
))
11760 ("access to volatile object cannot yield access-to-" &
11761 "non-volatile type", P
);
11763 elsif Is_Volatile_Full_Access_Object_Ref
(P
)
11764 and then not Is_Volatile_Full_Access
(Designated_Type
(Typ
))
11767 ("access to full access object cannot yield access-to-" &
11768 "non-full-access type", P
);
11771 -- Check for nonatomic subcomponent of a full access object
11772 -- in Ada 2022 (RM C.6 (12)).
11774 if Ada_Version
>= Ada_2022
11775 and then Is_Subcomponent_Of_Full_Access_Object
(P
)
11776 and then not Is_Atomic_Object
(P
)
11779 ("cannot have access attribute with prefix &", N
, P
);
11781 ("\nonatomic subcomponent of full access object "
11782 & "(RM C.6(12))", N
);
11786 -- Check for aliased view. We allow a nonaliased prefix when in
11787 -- an instance because the prefix may have been a tagged formal
11788 -- object, which is defined to be aliased even when the actual
11789 -- might not be (other instance cases will have been caught in
11790 -- the generic). Similarly, within an inlined body we know that
11791 -- the attribute is legal in the original subprogram, therefore
11792 -- legal in the expansion.
11794 if not (Is_Entity_Name
(P
)
11795 and then Is_Overloadable
(Entity
(P
)))
11796 and then not (Nkind
(P
) = N_Selected_Component
11798 Is_Overloadable
(Entity
(Selector_Name
(P
))))
11799 and then not Is_Aliased_View
(Original_Node
(P
))
11800 and then not In_Instance
11801 and then not In_Inlined_Body
11802 and then Comes_From_Source
(N
)
11804 -- Here we have a non-aliased view. This is illegal unless we
11805 -- have the case of Unrestricted_Access, where for now we allow
11806 -- this (we will reject later if expected type is access to an
11807 -- unconstrained array with a thin pointer).
11809 -- No need for an error message on a generated access reference
11810 -- for the controlling argument in a dispatching call: error
11811 -- will be reported when resolving the call.
11813 if Attr_Id
/= Attribute_Unrestricted_Access
then
11814 Error_Msg_Name_1
:= Aname
;
11815 Error_Msg_N
("prefix of % attribute must be aliased", P
);
11817 -- Check for unrestricted access where expected type is a thin
11818 -- pointer to an unconstrained array.
11820 elsif Has_Size_Clause
(Typ
)
11821 and then RM_Size
(Typ
) = System_Address_Size
11824 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
11826 if Is_Array_Type
(DT
)
11827 and then not Is_Constrained
(DT
)
11830 ("illegal use of Unrestricted_Access attribute", P
);
11832 ("\attempt to generate thin pointer to unaliased "
11839 -- Check that the prefix does not have a value conversion of an
11840 -- array type since a value conversion is like an aggregate with
11841 -- respect to determining accessibility level (RM 3.10.2).
11843 if not Prefix_With_Safe_Accessibility_Level
(N
, Typ
) then
11844 Accessibility_Message
(N
, Typ
);
11848 -- Mark that address of entity is taken in case of
11849 -- 'Unrestricted_Access or in case of a subprogram.
11851 if Is_Entity_Name
(P
)
11852 and then (Attr_Id
= Attribute_Unrestricted_Access
11853 or else Is_Subprogram
(Entity
(P
)))
11855 Set_Address_Taken
(Entity
(P
));
11858 -- Deal with possible elaboration check
11860 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
11862 Subp_Id
: constant Entity_Id
:= Entity
(P
);
11863 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
11864 Subp_Decl
: constant Node_Id
:=
11865 Unit_Declaration_Node
(Subp_Id
);
11866 Flag_Id
: Entity_Id
;
11867 Subp_Body
: Node_Id
;
11869 -- If the access has been taken and the body of the subprogram
11870 -- has not been see yet, indirect calls must be protected with
11871 -- elaboration checks. We have the proper elaboration machinery
11872 -- for subprograms declared in packages, but within a block or
11873 -- a subprogram the body will appear in the same declarative
11874 -- part, and we must insert a check in the eventual body itself
11875 -- using the elaboration flag that we generate now. The check
11876 -- is then inserted when the body is expanded. This processing
11877 -- is not needed for a stand alone expression function because
11878 -- the internally generated spec and body are always inserted
11879 -- as a pair in the same declarative list.
11883 and then Comes_From_Source
(Subp_Id
)
11884 and then Comes_From_Source
(N
)
11885 and then In_Open_Scopes
(Scop
)
11886 and then Ekind
(Scop
) in E_Block | E_Procedure | E_Function
11887 and then not Has_Completion
(Subp_Id
)
11888 and then No
(Elaboration_Entity
(Subp_Id
))
11889 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11890 and then Nkind
(Original_Node
(Subp_Decl
)) /=
11891 N_Expression_Function
11893 -- Create elaboration variable for it
11895 Flag_Id
:= Make_Temporary
(Loc
, 'E');
11896 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
11897 Set_Is_Frozen
(Flag_Id
);
11899 -- Insert declaration for flag after subprogram
11900 -- declaration. Note that attribute reference may
11901 -- appear within a nested scope.
11903 Insert_After_And_Analyze
(Subp_Decl
,
11904 Make_Object_Declaration
(Loc
,
11905 Defining_Identifier
=> Flag_Id
,
11906 Object_Definition
=>
11907 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
11909 Make_Integer_Literal
(Loc
, Uint_0
)));
11911 -- The above sets the Scope of the flag entity to the
11912 -- current scope, in which the attribute appears, but
11913 -- the flag declaration has been inserted after that
11914 -- of Subp_Id, so the scope of the flag is the same as
11915 -- that of Subp_Id. This is relevant when unnesting,
11916 -- where processing depends on correct scope setting.
11918 Set_Scope
(Flag_Id
, Scop
);
11921 -- Taking the 'Access of an expression function freezes its
11922 -- expression (RM 13.14 10.3/3). This does not apply to an
11923 -- expression function that acts as a completion because the
11924 -- generated body is immediately analyzed and the expression
11925 -- is automatically frozen.
11927 if Is_Expression_Function
(Subp_Id
)
11928 and then Present
(Corresponding_Body
(Subp_Decl
))
11931 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
11933 -- The body has already been analyzed when the expression
11934 -- function acts as a completion.
11936 if Analyzed
(Subp_Body
) then
11939 -- Attribute 'Access may appear within the generated body
11940 -- of the expression function subject to the attribute:
11942 -- function F is (... F'Access ...);
11944 -- If the expression function is on the scope stack, then
11945 -- the body is currently being analyzed. Do not reanalyze
11946 -- it because this will lead to infinite recursion.
11948 elsif In_Open_Scopes
(Subp_Id
) then
11951 -- If reference to the expression function appears in an
11952 -- inner scope, for example as an actual in an instance,
11953 -- this is not a freeze point either.
11955 elsif Scope
(Subp_Id
) /= Current_Scope
then
11958 -- Dispatch tables are not a freeze point either
11960 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
11961 and then Is_Dispatch_Table_Entity
(Etype
(Parent
(N
)))
11965 -- Analyze the body of the expression function to freeze
11969 Analyze
(Subp_Body
);
11979 -- Deal with resolving the type for Address attribute, overloading
11980 -- is not permitted here, since there is no context to resolve it.
11982 when Attribute_Address
11983 | Attribute_Code_Address
11985 -- To be safe, assume that if the address of a variable is taken,
11986 -- it may be modified via this address, so note modification.
11988 if Is_Variable
(P
) then
11989 Note_Possible_Modification
(P
, Sure
=> False);
11992 if Nkind
(P
) in N_Subexpr
11993 and then Is_Overloaded
(P
)
11995 Get_First_Interp
(P
, Index
, It
);
11996 Get_Next_Interp
(Index
, It
);
11998 if Present
(It
.Nam
) then
11999 Error_Msg_Name_1
:= Aname
;
12001 ("prefix of % attribute cannot be overloaded", P
);
12005 if not Is_Entity_Name
(P
)
12006 or else not Is_Overloadable
(Entity
(P
))
12008 if not Is_Task_Type
(Etype
(P
))
12009 or else Nkind
(P
) = N_Explicit_Dereference
12015 -- If this is the name of a derived subprogram, or that of a
12016 -- generic actual, the address is that of the original entity.
12018 if Is_Entity_Name
(P
)
12019 and then Is_Overloadable
(Entity
(P
))
12020 and then Present
(Alias
(Entity
(P
)))
12023 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
12026 if Is_Entity_Name
(P
) then
12027 Set_Address_Taken
(Entity
(P
));
12030 if Nkind
(P
) = N_Slice
then
12032 -- Arr (X .. Y)'address is identical to Arr (X)'address,
12033 -- even if the array is packed and the slice itself is not
12034 -- addressable. Transform the prefix into an indexed component.
12036 -- Note that the transformation is safe only if we know that
12037 -- the slice is non-null. That is because a null slice can have
12038 -- an out of bounds index value.
12040 -- Right now, gigi blows up if given 'Address on a slice as a
12041 -- result of some incorrect freeze nodes generated by the front
12042 -- end, and this covers up that bug in one case, but the bug is
12043 -- likely still there in the cases not handled by this code ???
12045 -- It's not clear what 'Address *should* return for a null
12046 -- slice with out of bounds indexes, this might be worth an ARG
12049 -- One approach would be to do a length check unconditionally,
12050 -- and then do the transformation below unconditionally, but
12051 -- analyze with checks off, avoiding the problem of the out of
12052 -- bounds index. This approach would interpret the address of
12053 -- an out of bounds null slice as being the address where the
12054 -- array element would be if there was one, which is probably
12055 -- as reasonable an interpretation as any ???
12058 Loc
: constant Source_Ptr
:= Sloc
(P
);
12059 D
: constant Node_Id
:= Discrete_Range
(P
);
12063 if Is_Entity_Name
(D
)
12066 (Type_Low_Bound
(Entity
(D
)),
12067 Type_High_Bound
(Entity
(D
)))
12070 Make_Attribute_Reference
(Loc
,
12071 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
12072 Attribute_Name
=> Name_First
);
12074 elsif Nkind
(D
) = N_Range
12075 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
12077 Lo
:= Low_Bound
(D
);
12083 if Present
(Lo
) then
12085 Make_Indexed_Component
(Loc
,
12086 Prefix
=> Relocate_Node
(Prefix
(P
)),
12087 Expressions
=> New_List
(Lo
)));
12089 Analyze_And_Resolve
(P
);
12098 -- Prefix of Body_Version attribute can be a subprogram name which
12099 -- must not be resolved, since this is not a call.
12101 when Attribute_Body_Version
=>
12108 -- Prefix of Caller attribute is an entry name which must not
12109 -- be resolved, since this is definitely not an entry call.
12111 when Attribute_Caller
=>
12118 -- Shares processing with Address attribute
12124 -- If the prefix of the Count attribute is an entry name it must not
12125 -- be resolved, since this is definitely not an entry call. However,
12126 -- if it is an element of an entry family, the index itself may
12127 -- have to be resolved because it can be a general expression.
12129 when Attribute_Count
12132 if Nkind
(P
) = N_Indexed_Component
12133 and then Is_Entity_Name
(Prefix
(P
))
12136 Indx
: constant Node_Id
:= First
(Expressions
(P
));
12137 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
12139 Resolve
(Indx
, Entry_Index_Type
(Fam
));
12140 Apply_Scalar_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
12148 -- Prefix of the Elaborated attribute is a subprogram name which
12149 -- must not be resolved, since this is definitely not a call. Note
12150 -- that it is a library unit, so it cannot be overloaded here.
12152 when Attribute_Elaborated
=>
12159 -- Prefix of Enabled attribute is a check name, which must be treated
12160 -- specially and not touched by Resolve.
12162 when Attribute_Enabled
=>
12169 -- Processing is shared with Count
12175 -- Do not resolve the prefix of Loop_Entry, instead wait until the
12176 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
12177 -- The delay ensures that any generated checks or temporaries are
12178 -- inserted before the relocated prefix.
12180 when Attribute_Loop_Entry
=>
12183 --------------------
12184 -- Mechanism_Code --
12185 --------------------
12187 -- Prefix of the Mechanism_Code attribute is a function name
12188 -- which must not be resolved. Should we check for overloaded ???
12190 when Attribute_Mechanism_Code
=>
12197 -- Most processing is done in sem_dist, after determining the
12198 -- context type. Node is rewritten as a conversion to a runtime call.
12200 when Attribute_Partition_ID
=>
12201 Process_Partition_Id
(N
);
12208 when Attribute_Pool_Address
=>
12215 -- We replace the Range attribute node with a range expression whose
12216 -- bounds are the 'First and 'Last attributes applied to the same
12217 -- prefix. The reason that we do this transformation here instead of
12218 -- in the expander is that it simplifies other parts of the semantic
12219 -- analysis which assume that the Range has been replaced; thus it
12220 -- must be done even when in semantic-only mode (note that the RM
12221 -- specifically mentions this equivalence, we take care that the
12222 -- prefix is only evaluated once).
12224 when Attribute_Range
=> Range_Attribute
: declare
12230 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12233 -- If the prefix is a function call returning on the secondary
12234 -- stack, we must make sure to mark/release the stack.
12236 if Nkind
(P
) = N_Function_Call
12237 and then Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
12238 and then Requires_Transient_Scope
(Etype
(P
))
12240 Set_Uses_Sec_Stack
(Scope
(Current_Scope
));
12244 Dims
:= Expressions
(N
);
12247 Make_Attribute_Reference
(Loc
,
12248 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
12249 Attribute_Name
=> Name_Last
,
12250 Expressions
=> Dims
);
12253 Make_Attribute_Reference
(Loc
,
12255 Attribute_Name
=> Name_First
,
12256 Expressions
=> (Dims
));
12258 -- Do not share the dimension indicator, if present. Even though
12259 -- it is a static constant, its source location may be modified
12260 -- when printing expanded code and node sharing will lead to chaos
12263 if Present
(Dims
) then
12264 Set_Expressions
(LB
, New_List
(New_Copy_Tree
(First
(Dims
))));
12267 -- If the original was marked as Must_Not_Freeze (see code in
12268 -- Sem_Ch3.Make_Index), then make sure the rewriting does not
12271 if Must_Not_Freeze
(N
) then
12272 Set_Must_Not_Freeze
(HB
);
12273 Set_Must_Not_Freeze
(LB
);
12274 Set_Must_Not_Freeze
(Prefix
(HB
));
12275 Set_Must_Not_Freeze
(Prefix
(LB
));
12278 if Raises_Constraint_Error
(Prefix
(N
)) then
12280 -- Preserve Sloc of prefix in the new bounds, so that the
12281 -- posted warning can be removed if we are within unreachable
12284 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
12285 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
12288 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
12289 Analyze_And_Resolve
(N
, Typ
);
12291 -- Ensure that the expanded range does not have side effects
12293 Force_Evaluation
(LB
);
12294 Force_Evaluation
(HB
);
12296 -- Normally after resolving attribute nodes, Eval_Attribute
12297 -- is called to do any possible static evaluation of the node.
12298 -- However, here since the Range attribute has just been
12299 -- transformed into a range expression it is no longer an
12300 -- attribute node and therefore the call needs to be avoided
12301 -- and is accomplished by simply returning from the procedure.
12304 end Range_Attribute
;
12310 when Attribute_Reduce
=>
12312 E1
: constant Node_Id
:= First
(Expressions
(N
));
12313 E2
: constant Node_Id
:= Next
(E1
);
12314 Op
: Entity_Id
:= Empty
;
12316 Index
: Interp_Index
;
12318 function Proper_Op
(Op
: Entity_Id
) return Boolean;
12324 function Proper_Op
(Op
: Entity_Id
) return Boolean is
12325 F1
, F2
: Entity_Id
;
12328 F1
:= First_Formal
(Op
);
12332 F2
:= Next_Formal
(F1
);
12334 or else Present
(Next_Formal
(F2
))
12338 elsif Ekind
(Op
) = E_Procedure
then
12339 return Ekind
(F1
) = E_In_Out_Parameter
12340 and then Covers
(Typ
, Etype
(F1
));
12344 (Ekind
(Op
) = E_Operator
12345 and then Scope
(Op
) = Standard_Standard
)
12346 or else Covers
(Typ
, Etype
(Op
));
12353 if Is_Overloaded
(E1
) then
12354 Get_First_Interp
(E1
, Index
, It
);
12355 while Present
(It
.Nam
) loop
12356 if Proper_Op
(It
.Nam
) then
12358 Set_Entity
(E1
, Op
);
12362 Get_Next_Interp
(Index
, It
);
12365 elsif Nkind
(E1
) = N_Attribute_Reference
12366 and then (Attribute_Name
(E1
) = Name_Max
12367 or else Attribute_Name
(E1
) = Name_Min
)
12371 elsif Proper_Op
(Entity
(E1
)) then
12373 Set_Etype
(N
, Typ
);
12377 Error_Msg_N
("No visible subprogram for reduction", E1
);
12385 -- We will only come here during the prescan of a spec expression
12386 -- containing a Result attribute. In that case the proper Etype has
12387 -- already been set, and nothing more needs to be done here.
12389 when Attribute_Result
=>
12392 ----------------------
12393 -- Unchecked_Access --
12394 ----------------------
12396 -- Processing is shared with Access
12398 -------------------------
12399 -- Unrestricted_Access --
12400 -------------------------
12402 -- Processing is shared with Access
12408 -- Resolve aggregate components in component associations
12410 when Attribute_Update
=> Update
: declare
12411 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
12412 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
12418 -- Set the Etype of the aggregate to that of the prefix, even
12419 -- though the aggregate may not be a proper representation of a
12420 -- value of the type (missing or duplicated associations, etc.)
12421 -- Complete resolution of the prefix. Note that in Ada 2012 it
12422 -- can be a qualified expression that is e.g. an aggregate.
12424 Set_Etype
(Aggr
, Typ
);
12425 Resolve
(Prefix
(N
), Typ
);
12427 -- For an array type, resolve expressions with the component type
12428 -- of the array, and apply constraint checks when needed.
12430 if Is_Array_Type
(Typ
) then
12431 Assoc
:= First
(Component_Associations
(Aggr
));
12432 while Present
(Assoc
) loop
12433 Expr
:= Expression
(Assoc
);
12434 Resolve
(Expr
, Component_Type
(Typ
));
12436 -- The choices in the association are static constants,
12437 -- or static aggregates each of whose components belongs
12438 -- to the proper index type. However, they must also
12439 -- belong to the index subtype (s) of the prefix, which
12440 -- may be a subtype (e.g. given by a slice).
12442 -- Choices may also be identifiers with no staticness
12443 -- requirements, in which case they must resolve to the
12452 C
:= First
(Choices
(Assoc
));
12453 while Present
(C
) loop
12454 Indx
:= First_Index
(Etype
(Prefix
(N
)));
12456 if Nkind
(C
) /= N_Aggregate
then
12457 Analyze_And_Resolve
(C
, Etype
(Indx
));
12459 C_E
:= First
(Expressions
(C
));
12460 while Present
(C_E
) loop
12461 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
12475 -- For a record type, use type of each component, which is
12476 -- recorded during analysis.
12479 Assoc
:= First
(Component_Associations
(Aggr
));
12480 while Present
(Assoc
) loop
12481 Comp
:= First
(Choices
(Assoc
));
12482 Expr
:= Expression
(Assoc
);
12484 if Nkind
(Comp
) /= N_Others_Choice
12485 and then not Error_Posted
(Comp
)
12487 Resolve
(Expr
, Etype
(Entity
(Comp
)));
12499 -- Apply range check. Note that we did not do this during the
12500 -- analysis phase, since we wanted Eval_Attribute to have a
12501 -- chance at finding an illegal out of range value.
12503 when Attribute_Val
=>
12505 -- Note that we do our own Eval_Attribute call here rather than
12506 -- use the common one, because we need to do processing after
12507 -- the call, as per above comment.
12509 Eval_Attribute
(N
);
12511 -- Eval_Attribute may replace the node with a raise CE, or
12512 -- fold it to a constant. Obviously we only apply a scalar
12513 -- range check if this did not happen.
12515 if Nkind
(N
) = N_Attribute_Reference
12516 and then Attribute_Name
(N
) = Name_Val
12518 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
12527 -- Prefix of Version attribute can be a subprogram name which
12528 -- must not be resolved, since this is not a call.
12530 when Attribute_Version
=>
12533 ----------------------
12534 -- Other Attributes --
12535 ----------------------
12537 -- For other attributes, resolve prefix unless it is a type. If
12538 -- the attribute reference itself is a type name ('Base and 'Class)
12539 -- then this is only legal within a task or protected record.
12542 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12546 -- If the attribute reference itself is a type name ('Base,
12547 -- 'Class) then this is only legal within a task or protected
12548 -- record. What is this all about ???
12550 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
12551 if Is_Concurrent_Type
(Entity
(N
))
12552 and then In_Open_Scopes
(Entity
(P
))
12557 ("invalid use of subtype name in expression or call", N
);
12561 -- For attributes whose argument may be a string, complete
12562 -- resolution of argument now. This avoids premature expansion
12563 -- (and the creation of transient scopes) before the attribute
12564 -- reference is resolved.
12567 when Attribute_Valid_Value | Attribute_Value
=>
12568 Resolve
(First
(Expressions
(N
)), Standard_String
);
12570 when Attribute_Wide_Value
=>
12571 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
12573 when Attribute_Wide_Wide_Value
=>
12574 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
12576 when others => null;
12579 -- Ensure that attribute expressions are resolved at this stage;
12580 -- required for preanalyzed references to discriminants since
12581 -- their resolution (and expansion) will take care of updating
12582 -- their Entity attribute to reference their discriminal.
12585 and then Present
(Expressions
(N
))
12588 Expr
: Node_Id
:= First
(Expressions
(N
));
12591 while Present
(Expr
) loop
12592 if not Analyzed
(Expr
) then
12593 Resolve
(Expr
, Etype
(Expr
));
12601 -- If the prefix of the attribute is a class-wide type then it
12602 -- will be expanded into a dispatching call to a predefined
12603 -- primitive. Therefore we must check for potential violation
12604 -- of such restriction.
12606 if Is_Class_Wide_Type
(Etype
(P
)) then
12607 Check_Restriction
(No_Dispatching_Calls
, N
);
12611 -- Mark use clauses of the original prefix if the attribute is applied
12614 if Nkind
(Original_Node
(P
)) in N_Has_Entity
12615 and then Present
(Entity
(Original_Node
(P
)))
12617 Mark_Use_Clauses
(Original_Node
(P
));
12620 -- Normally the Freezing is done by Resolve but sometimes the Prefix
12621 -- is not resolved, in which case the freezing must be done now.
12623 -- For an elaboration check on a subprogram, we do not freeze its type.
12624 -- It may be declared in an unrelated scope, in particular in the case
12625 -- of a generic function whose type may remain unelaborated.
12627 if Attr_Id
= Attribute_Elaborated
then
12630 -- Should this be restricted to Expander_Active???
12633 Freeze_Expression
(P
);
12636 -- Finally perform static evaluation on the attribute reference
12638 Analyze_Dimension
(N
);
12639 Eval_Attribute
(N
);
12640 end Resolve_Attribute
;
12642 ------------------------
12643 -- Set_Boolean_Result --
12644 ------------------------
12646 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
12648 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(B
), Sloc
(N
)));
12649 end Set_Boolean_Result
;
12651 --------------------------------
12652 -- Stream_Attribute_Available --
12653 --------------------------------
12655 function Stream_Attribute_Available
12657 Nam
: TSS_Name_Type
;
12658 Partial_View
: Entity_Id
:= Empty
) return Boolean
12660 Etyp
: Entity_Id
:= Typ
;
12662 Real_Rep
: Node_Id
;
12664 -- Start of processing for Stream_Attribute_Available
12667 -- Test if the attribute is specified directly on the type
12669 if Has_Stream_Attribute_Definition
(Typ
, Nam
, Real_Rep
) then
12673 -- We assume class-wide types have stream attributes
12674 -- when they are not limited. Otherwise we recurse on the
12677 if Is_Class_Wide_Type
(Typ
) then
12678 return not Is_Limited_Type
(Typ
)
12679 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
12682 -- Non-class-wide abstract types cannot have Input streams
12685 if Nam
= TSS_Stream_Input
12686 and then Is_Abstract_Type
(Typ
)
12687 and then not Is_Class_Wide_Type
(Typ
)
12692 -- Otherwise, nonlimited types have stream attributes
12694 if not (Is_Limited_Type
(Typ
)
12695 or else (Present
(Partial_View
)
12696 and then Is_Limited_Type
(Partial_View
)))
12701 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
12703 if Nam
= TSS_Stream_Input
12704 and then Ada_Version
>= Ada_2005
12705 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
, Real_Rep
)
12709 elsif Nam
= TSS_Stream_Output
12710 and then Ada_Version
>= Ada_2005
12711 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
, Real_Rep
)
12716 -- Case of Read and Write: check for attribute definition clause that
12717 -- applies to an ancestor type.
12719 while Etype
(Etyp
) /= Etyp
loop
12721 Derived_Type
: constant Entity_Id
:= Etyp
;
12723 Etyp
:= Etype
(Etyp
);
12725 if Has_Stream_Attribute_Definition
(Etyp
, Nam
, Real_Rep
) then
12726 if not Derivation_Too_Early_To_Inherit
(Derived_Type
, Nam
) then
12733 if Ada_Version
< Ada_2005
then
12735 -- In Ada 95 mode, also consider a non-visible definition
12738 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
12741 and then Stream_Attribute_Available
12742 (Btyp
, Nam
, Partial_View
=> Typ
);
12747 end Stream_Attribute_Available
;