1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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 Aspects
; use Aspects
;
29 with Atree
; use Atree
;
30 with Casing
; use Casing
;
31 with Checks
; use Checks
;
32 with Debug
; use Debug
;
33 with Einfo
; use Einfo
;
34 with Einfo
.Entities
; use Einfo
.Entities
;
35 with Einfo
.Utils
; use Einfo
.Utils
;
36 with Elists
; use Elists
;
37 with Errout
; use Errout
;
39 with Exp_Dist
; use Exp_Dist
;
40 with Exp_Util
; use Exp_Util
;
41 with Expander
; use Expander
;
42 with Freeze
; use Freeze
;
43 with Gnatvsn
; use Gnatvsn
;
44 with Itypes
; use Itypes
;
46 with Lib
.Xref
; use Lib
.Xref
;
47 with Nlists
; use Nlists
;
48 with Nmake
; use Nmake
;
50 with Restrict
; use Restrict
;
51 with Rident
; use Rident
;
52 with Rtsfind
; use Rtsfind
;
55 with Sem_Aggr
; use Sem_Aggr
;
56 with Sem_Aux
; use Sem_Aux
;
57 with Sem_Cat
; use Sem_Cat
;
58 with Sem_Ch6
; use Sem_Ch6
;
59 with Sem_Ch8
; use Sem_Ch8
;
60 with Sem_Ch10
; use Sem_Ch10
;
61 with Sem_Dim
; use Sem_Dim
;
62 with Sem_Dist
; use Sem_Dist
;
63 with Sem_Elab
; use Sem_Elab
;
64 with Sem_Elim
; use Sem_Elim
;
65 with Sem_Eval
; use Sem_Eval
;
66 with Sem_Prag
; use Sem_Prag
;
67 with Sem_Res
; use Sem_Res
;
68 with Sem_Type
; use Sem_Type
;
69 with Sem_Util
; use Sem_Util
;
71 with Stand
; use Stand
;
72 with Sinfo
; use Sinfo
;
73 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
74 with Sinfo
.Utils
; use Sinfo
.Utils
;
75 with Sinput
; use Sinput
;
77 with Stringt
; use Stringt
;
78 with Strub
; use Strub
;
80 with Stylesw
; use Stylesw
;
81 with Targparm
; use Targparm
;
82 with Ttypes
; use Ttypes
;
83 with Tbuild
; use Tbuild
;
84 with Uintp
; use Uintp
;
85 with Uname
; use Uname
;
86 with Urealp
; use Urealp
;
88 with System
.CRC32
; use System
.CRC32
;
90 package body Sem_Attr
is
92 True_Value
: constant Uint
:= Uint_1
;
93 False_Value
: constant Uint
:= Uint_0
;
94 -- Synonyms to be used when these constants are used as Boolean values
96 Bad_Attribute
: exception;
97 -- Exception raised if an error is detected during attribute processing,
98 -- used so that we can abandon the processing so we don't run into
99 -- trouble with cascaded errors.
101 -- The following array is the list of attributes defined in the Ada 83 RM.
102 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
103 -- modes all these attributes are recognized, even if removed in Ada 95.
105 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
108 Attribute_Alignment |
111 Attribute_Constrained |
118 Attribute_First_Bit |
124 Attribute_Leading_Part |
126 Attribute_Machine_Emax |
127 Attribute_Machine_Emin |
128 Attribute_Machine_Mantissa |
129 Attribute_Machine_Overflows |
130 Attribute_Machine_Radix |
131 Attribute_Machine_Rounds |
137 Attribute_Safe_Emax |
138 Attribute_Safe_Large |
139 Attribute_Safe_Small |
142 Attribute_Storage_Size |
144 Attribute_Terminated |
147 Attribute_Width => True,
150 -- The following array is the list of attributes defined in the Ada 2005
151 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
152 -- but in Ada 95 they are considered to be implementation defined.
154 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
155 Attribute_Machine_Rounding |
158 Attribute_Stream_Size |
159 Attribute_Wide_Wide_Width
=> True,
162 -- The following array is the list of attributes defined in the Ada 2012
163 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
164 -- and Ada 2005 modes, but are considered to be implementation defined.
166 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
167 Attribute_First_Valid |
168 Attribute_Has_Same_Storage |
169 Attribute_Last_Valid |
170 Attribute_Max_Alignment_For_Allocation => True,
173 -- The following array is the list of attributes defined in the Ada 2022
174 -- RM which are not defined in Ada 2012. These are recognized in Ada
175 -- 95/2005/2012 modes, but are considered to be implementation defined.
177 Attribute_22 : constant Attribute_Class_Array := Attribute_Class_Array'(
179 Attribute_Enum_Val
=> True,
180 Attribute_Index
=> True,
181 Attribute_Preelaborable_Initialization
=> True,
184 -- The following array contains all attributes that imply a modification
185 -- of their prefixes or result in an access value. Such prefixes can be
186 -- considered as lvalues.
188 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
189 Attribute_Class_Array
'(
194 Attribute_Unchecked_Access |
195 Attribute_Unrestricted_Access => True,
198 -----------------------
199 -- Local_Subprograms --
200 -----------------------
202 procedure Eval_Attribute (N : Node_Id);
203 -- Performs compile time evaluation of attributes where possible, leaving
204 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
205 -- set, and replacing the node with a literal node if the value can be
206 -- computed at compile time. All static attribute references are folded,
207 -- as well as a number of cases of non-static attributes that can always
208 -- be computed at compile time (e.g. floating-point model attributes that
209 -- are applied to non-static subtypes). Of course in such cases, the
210 -- Is_Static_Expression flag will not be set on the resulting literal.
211 -- Note that the only required action of this procedure is to catch the
212 -- static expression cases as described in the RM. Folding of other cases
213 -- is done where convenient, but some additional non-static folding is in
214 -- Expand_N_Attribute_Reference in cases where this is more convenient.
216 function Is_Anonymous_Tagged_Base
218 Typ : Entity_Id) return Boolean;
219 -- For derived tagged types that constrain parent discriminants we build
220 -- an anonymous unconstrained base type. We need to recognize the relation
221 -- between the two when analyzing an access attribute for a constrained
222 -- component, before the full declaration for Typ has been analyzed, and
223 -- where therefore the prefix of the attribute does not match the enclosing
226 procedure Set_Boolean_Result (N : Node_Id; B : Boolean);
227 -- Rewrites node N with an occurrence of either Standard_False or
228 -- Standard_True, depending on the value of the parameter B. The
229 -- result is marked as a static expression.
231 -----------------------
232 -- Analyze_Attribute --
233 -----------------------
235 procedure Analyze_Attribute (N : Node_Id) is
236 Loc : constant Source_Ptr := Sloc (N);
237 Aname : constant Name_Id := Attribute_Name (N);
238 Exprs : constant List_Id := Expressions (N);
239 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
240 P_Old : constant Node_Id := Prefix (N);
242 P : Node_Id := P_Old;
246 P_Type : Entity_Id := Empty;
247 -- Type of prefix after analysis
249 P_Base_Type : Entity_Id := Empty;
250 -- Base type of prefix after analysis
252 -----------------------
253 -- Local Subprograms --
254 -----------------------
256 procedure Address_Checks;
257 -- Semantic checks for valid use of Address attribute. This was made
258 -- a separate routine with the idea of using it for unrestricted access
259 -- which seems like it should follow the same rules, but that turned
260 -- out to be impractical. So now this is only used for Address.
262 procedure Analyze_Access_Attribute;
263 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
264 -- Internally, Id distinguishes which of the three cases is involved.
266 procedure Analyze_Attribute_Old_Result
267 (Legal : out Boolean;
268 Spec_Id : out Entity_Id);
269 -- Common processing for attributes 'Old
and 'Result. The routine checks
270 -- that the attribute appears in a postcondition-like aspect or pragma
271 -- associated with a suitable subprogram or a body. Flag Legal is set
272 -- when the above criteria are met. Spec_Id denotes the entity of the
273 -- subprogram [body] or Empty if the attribute is illegal.
275 procedure Analyze_Image_Attribute (Str_Typ : Entity_Id);
276 -- Common processing for attributes 'Img
, 'Image, 'Wide_Image
, and
277 -- 'Wide_Wide_Image. The routine checks that the prefix is valid and
278 -- sets the type of the attribute to the one specified by Str_Typ (e.g.
279 -- Standard_String for 'Image and Standard_Wide_String for 'Wide_Image).
281 procedure Analyze_Index_Attribute
282 (Legal
: out Boolean;
283 Spec_Id
: out Entity_Id
);
284 -- Processing for attribute 'Index. It checks that the attribute appears
285 -- in a pre/postcondition-like aspect or pragma associated with an entry
286 -- family. Flag Legal is set when the above criteria are met. Spec_Id
287 -- denotes the entity of the wrapper of the entry family or Empty if
288 -- the attribute is illegal.
290 procedure Bad_Attribute_For_Predicate
;
291 -- Output error message for use of a predicate (First, Last, Range) not
292 -- allowed with a type that has predicates. If the type is a generic
293 -- actual, then the message is a warning, and we generate code to raise
294 -- program error with an appropriate reason. No error message is given
295 -- for internally generated uses of the attributes. This legality rule
296 -- only applies to scalar types.
298 procedure Check_Array_Or_Scalar_Type
;
299 -- Common procedure used by First, Last, Range attribute to check
300 -- that the prefix is a constrained array or scalar type, or a name
301 -- of an array object, and that an argument appears only if appropriate
302 -- (i.e. only in the array case).
304 procedure Check_Array_Type
;
305 -- Common semantic checks for all array attributes. Checks that the
306 -- prefix is a constrained array type or the name of an array object.
307 -- The error message for non-arrays is specialized appropriately.
309 procedure Check_Asm_Attribute
;
310 -- Common semantic checks for Asm_Input and Asm_Output attributes
312 procedure Check_Component
;
313 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
314 -- Position. Checks prefix is an appropriate selected component.
316 procedure Check_Decimal_Fixed_Point_Type
;
317 -- Check that prefix of attribute N is a decimal fixed-point type
319 procedure Check_Dereference
;
320 -- If the prefix of attribute is an object of an access type, then
321 -- introduce an explicit dereference, and adjust P_Type accordingly.
323 procedure Check_Discrete_Type
;
324 -- Verify that prefix of attribute N is a discrete type
327 -- Check that no attribute arguments are present
329 procedure Check_Either_E0_Or_E1
;
330 -- Check that there are zero or one attribute arguments present
333 -- Check that exactly one attribute argument is present
336 -- Check that two attribute arguments are present
338 procedure Check_Enum_Image
(Check_Enumeration_Maps
: Boolean := False);
339 -- Common processing for the Image and Value family of attributes,
340 -- including their Wide and Wide_Wide versions, Enum_Val, Img,
343 -- If the prefix type of an attribute is an enumeration type, set all
344 -- its literals as referenced, since the attribute function can
345 -- indirectly reference any of the literals. Set the referenced flag
346 -- only if the attribute is in the main code unit; otherwise an
347 -- improperly set reference when analyzing an inlined body will lose a
348 -- proper warning on a useless with_clause.
350 -- If Check_Enumeration_Maps is True, then the attribute expansion
351 -- requires enumeration maps, so check whether restriction
352 -- No_Enumeration_Maps is active.
354 procedure Check_First_Last_Valid
;
355 -- Perform all checks for First_Valid and Last_Valid attributes
357 procedure Check_Fixed_Point_Type
;
358 -- Verify that prefix of attribute N is a fixed type
360 procedure Check_Fixed_Point_Type_0
;
361 -- Verify that prefix of attribute N is a fixed type and that
362 -- no attribute expressions are present.
364 procedure Check_Floating_Point_Type
;
365 -- Verify that prefix of attribute N is a float type
367 procedure Check_Floating_Point_Type_0
;
368 -- Verify that prefix of attribute N is a float type and that
369 -- no attribute expressions are present.
371 procedure Check_Floating_Point_Type_1
;
372 -- Verify that prefix of attribute N is a float type and that
373 -- exactly one attribute expression is present.
375 procedure Check_Floating_Point_Type_2
;
376 -- Verify that prefix of attribute N is a float type and that
377 -- two attribute expressions are present.
379 procedure Check_Integer_Type
;
380 -- Verify that prefix of attribute N is an integer type
382 procedure Check_Modular_Integer_Type
;
383 -- Verify that prefix of attribute N is a modular integer type
385 procedure Check_Not_CPP_Type
;
386 -- Check that P (the prefix of the attribute) is not an CPP type
387 -- for which no Ada predefined primitive is available.
389 procedure Check_Not_Incomplete_Type
;
390 -- Check that P (the prefix of the attribute) is not an incomplete
391 -- type or a private type for which no full view has been given.
393 procedure Check_Object_Reference
(P
: Node_Id
);
394 -- Check that P is an object reference
396 procedure Check_PolyORB_Attribute
;
397 -- Validity checking for PolyORB/DSA attribute
399 procedure Check_Program_Unit
;
400 -- Verify that prefix of attribute N is a program unit
402 procedure Check_Real_Type
;
403 -- Verify that prefix of attribute N is fixed or float type
405 procedure Check_Enumeration_Type
;
406 -- Verify that prefix of attribute N is an enumeration type
408 procedure Check_Scalar_Type
;
409 -- Verify that prefix of attribute N is a scalar type
411 procedure Check_Standard_Prefix
;
412 -- Verify that prefix of attribute N is package Standard. Also checks
413 -- that there are no arguments.
415 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
416 -- Validity checking for stream attribute. Nam is the TSS name of the
417 -- corresponding possible defined attribute function (e.g. for the
418 -- Read attribute, Nam will be TSS_Stream_Read).
420 procedure Check_Put_Image_Attribute
;
421 -- Validity checking for Put_Image attribute
423 procedure Check_System_Prefix
;
424 -- Verify that prefix of attribute N is package System
426 procedure Check_Task_Prefix
;
427 -- Verify that prefix of attribute N is a task or task type
429 procedure Check_Type
;
430 -- Verify that the prefix of attribute N is a type
432 procedure Check_Unit_Name
(Nod
: Node_Id
);
433 -- Check that Nod is of the form of a library unit name, i.e that
434 -- it is an identifier, or a selected component whose prefix is
435 -- itself of the form of a library unit name. Note that this is
436 -- quite different from Check_Program_Unit, since it only checks
437 -- the syntactic form of the name, not the semantic identity. This
438 -- is because it is used with attributes (Elab_Body, Elab_Spec and
439 -- Elaborated) which can refer to non-visible unit.
441 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
442 pragma No_Return
(Error_Attr
);
443 procedure Error_Attr
;
444 pragma No_Return
(Error_Attr
);
445 -- Posts error using Error_Msg_N at given node, sets type of attribute
446 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
447 -- semantic processing. The message typically contains a % insertion
448 -- character which is replaced by the attribute name. The call with
449 -- no arguments is used when the caller has already generated the
450 -- required error messages.
452 procedure Error_Attr_P
(Msg
: String; Msg_Cont
: String := "");
453 pragma No_Return
(Error_Attr_P
);
454 -- Like Error_Attr, but error is posted at the start of the prefix. The
455 -- second message Msg_Cont is useful to issue a continuation message
456 -- before raising Bad_Attribute.
458 procedure Legal_Formal_Attribute
;
459 -- Common processing for attributes Definite and Has_Discriminants.
460 -- Checks that prefix is generic indefinite formal type.
462 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
463 -- Common processing for attributes Max_Alignment_For_Allocation and
464 -- Max_Size_In_Storage_Elements.
467 -- Common processing for attributes Max and Min
469 procedure Standard_Attribute
(Val
: Int
);
470 -- Used to process attributes whose prefix is package Standard which
471 -- yield values of type Universal_Integer. The attribute reference
472 -- node is rewritten with an integer literal of the given value which
473 -- is marked as static.
475 procedure Uneval_Old_Msg
;
476 -- Called when Loop_Entry or Old is used in a potentially unevaluated
477 -- expression. Generates appropriate message or warning depending on
478 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
479 -- node in the aspect case).
481 procedure Unexpected_Argument
(En
: Node_Id
);
482 pragma No_Return
(Unexpected_Argument
);
483 -- Signal unexpected attribute argument (En is the argument), and then
484 -- raises Bad_Attribute to avoid any further semantic processing.
486 procedure Validate_Non_Static_Attribute_Function_Call
;
487 -- Called when processing an attribute that is a function call to a
488 -- non-static function, i.e. an attribute function that either takes
489 -- non-scalar arguments or returns a non-scalar result. Verifies that
490 -- such a call does not appear in a preelaborable context.
496 procedure Address_Checks
is
498 -- An Address attribute created by expansion is legal even when it
499 -- applies to other entity-denoting expressions.
501 if not Comes_From_Source
(N
) then
504 -- Address attribute on a protected object self reference is legal
506 elsif Is_Protected_Self_Reference
(P
) then
509 -- Address applied to an entity
511 elsif Is_Entity_Name
(P
) then
513 Ent
: constant Entity_Id
:= Entity
(P
);
516 if Is_Subprogram
(Ent
) then
517 Set_Address_Taken
(Ent
);
519 -- An Address attribute is accepted when generated by the
520 -- compiler for dispatching operation, and an error is
521 -- issued once the subprogram is frozen (to avoid confusing
522 -- errors about implicit uses of Address in the dispatch
523 -- table initialization).
525 if Has_Pragma_Inline_Always
(Entity
(P
))
526 and then Comes_From_Source
(P
)
529 ("prefix of % attribute cannot be Inline_Always "
532 -- It is illegal to apply 'Address to an intrinsic
533 -- subprogram. This is now formalized in AI05-0095.
534 -- In an instance, an attempt to obtain 'Address of an
535 -- intrinsic subprogram (e.g the renaming of a predefined
536 -- operator that is an actual) raises Program_Error.
538 elsif Convention
(Ent
) = Convention_Intrinsic
then
541 Make_Raise_Program_Error
(Loc
,
542 Reason
=> PE_Address_Of_Intrinsic
));
545 Error_Msg_Name_1
:= Aname
;
547 ("cannot take % of intrinsic subprogram", N
);
550 -- Issue an error if prefix denotes an eliminated subprogram
553 Check_For_Eliminated_Subprogram
(P
, Ent
);
556 -- Object or label reference
558 elsif Is_Object_Reference
(P
) or else Ekind
(Ent
) = E_Label
then
559 Set_Address_Taken
(Ent
);
561 -- Deal with No_Implicit_Aliasing restriction
563 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
564 if not Is_Aliased_View
(P
) then
565 Check_Restriction
(No_Implicit_Aliasing
, P
);
567 Check_No_Implicit_Aliasing
(P
);
571 -- If we have an address of an object, and the attribute
572 -- comes from source, then set the object as potentially
573 -- source modified. We do this because the resulting address
574 -- can potentially be used to modify the variable and we
575 -- might not detect this, leading to some junk warnings.
577 Set_Never_Set_In_Source
(Ent
, False);
579 -- Allow Address to be applied to task or protected type,
580 -- returning null address (what is that about???)
582 elsif (Is_Concurrent_Type
(Etype
(Ent
))
583 and then Etype
(Ent
) = Base_Type
(Ent
))
584 or else Ekind
(Ent
) = E_Package
585 or else Is_Generic_Unit
(Ent
)
588 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
590 -- Anything else is illegal
593 Error_Attr
("invalid prefix for % attribute", P
);
599 elsif Is_Object_Reference
(P
) then
602 -- Subprogram called using dot notation
604 elsif Nkind
(P
) = N_Selected_Component
605 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
609 -- What exactly are we allowing here ??? and is this properly
610 -- documented in the sinfo documentation for this node ???
612 elsif Relaxed_RM_Semantics
613 and then Nkind
(P
) = N_Attribute_Reference
617 -- All other non-entity name cases are illegal
620 Error_Attr
("invalid prefix for % attribute", P
);
624 ------------------------------
625 -- Analyze_Access_Attribute --
626 ------------------------------
628 procedure Analyze_Access_Attribute
is
629 Acc_Type
: Entity_Id
;
634 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
635 -- Build an access-to-object type whose designated type is DT,
636 -- and whose Ekind is appropriate to the attribute type. The
637 -- type that is constructed is returned as the result.
639 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
640 -- Build an access to subprogram whose designated type is the type of
641 -- the prefix. If prefix is overloaded, so is the node itself. The
642 -- result is stored in Acc_Type.
644 function OK_Self_Reference
return Boolean;
645 -- An access reference whose prefix is a type can legally appear
646 -- within an aggregate, where it is obtained by expansion of
647 -- a defaulted aggregate. The enclosing aggregate that contains
648 -- the self-referenced is flagged so that the self-reference can
649 -- be expanded into a reference to the target object (see exp_aggr).
651 ------------------------------
652 -- Build_Access_Object_Type --
653 ------------------------------
655 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
656 Typ
: constant Entity_Id
:=
658 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
660 Set_Etype
(Typ
, Typ
);
662 Set_Associated_Node_For_Itype
(Typ
, N
);
663 Set_Directly_Designated_Type
(Typ
, DT
);
665 end Build_Access_Object_Type
;
667 ----------------------------------
668 -- Build_Access_Subprogram_Type --
669 ----------------------------------
671 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
672 Index
: Interp_Index
;
675 procedure Check_Local_Access
(E
: Entity_Id
);
676 -- Deal with possible access to local subprogram. If we have such
677 -- an access, we set a flag to kill all tracked values on any call
678 -- because this access value may be passed around, and any called
679 -- code might use it to access a local procedure which clobbers a
680 -- tracked value. If the scope is a loop or block, indicate that
681 -- value tracking is disabled for the enclosing subprogram.
683 function Get_Convention
(E
: Entity_Id
) return Convention_Id
;
684 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
685 -- Distinguish between access to regular/protected subprograms
687 ------------------------
688 -- Check_Local_Access --
689 ------------------------
691 procedure Check_Local_Access
(E
: Entity_Id
) is
693 if not Is_Library_Level_Entity
(E
) then
694 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
695 Set_Suppress_Value_Tracking_On_Call
696 (Nearest_Dynamic_Scope
(Current_Scope
));
698 end Check_Local_Access
;
704 function Get_Convention
(E
: Entity_Id
) return Convention_Id
is
706 -- Restrict handling by_protected_procedure access subprograms
707 -- to source entities; required to avoid building access to
708 -- subprogram types with convention protected when building
711 if Comes_From_Source
(P
)
712 and then Is_By_Protected_Procedure
(E
)
714 return Convention_Protected
;
716 return Convention
(E
);
724 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
726 if Get_Convention
(E
) = Convention_Protected
then
727 return E_Access_Protected_Subprogram_Type
;
729 return E_Access_Subprogram_Type
;
733 -- Start of processing for Build_Access_Subprogram_Type
736 -- In the case of an access to subprogram, use the name of the
737 -- subprogram itself as the designated type. Type-checking in
738 -- this case compares the signatures of the designated types.
740 -- Note: This fragment of the tree is temporarily malformed
741 -- because the correct tree requires an E_Subprogram_Type entity
742 -- as the designated type. In most cases this designated type is
743 -- later overridden by the semantics with the type imposed by the
744 -- context during the resolution phase. In the specific case of
745 -- the expression Address!(Prim'Unrestricted_Access), used to
746 -- initialize slots of dispatch tables, this work will be done by
747 -- the expander (see Exp_Aggr).
749 -- The reason to temporarily add this kind of node to the tree
750 -- instead of a proper E_Subprogram_Type itype, is the following:
751 -- in case of errors found in the source file we report better
752 -- error messages. For example, instead of generating the
755 -- "expected access to subprogram with profile
756 -- defined at line X"
758 -- we currently generate:
760 -- "expected access to function Z defined at line X"
762 Set_Etype
(N
, Any_Type
);
764 if not Is_Overloaded
(P
) then
765 Check_Local_Access
(Entity
(P
));
767 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
768 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
769 Set_Is_Public
(Acc_Type
, False);
770 Set_Etype
(Acc_Type
, Acc_Type
);
771 Set_Convention
(Acc_Type
, Get_Convention
(Entity
(P
)));
772 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
773 Set_Etype
(N
, Acc_Type
);
774 Freeze_Before
(N
, Acc_Type
);
778 Get_First_Interp
(P
, Index
, It
);
779 while Present
(It
.Nam
) loop
780 Check_Local_Access
(It
.Nam
);
782 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
783 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
784 Set_Is_Public
(Acc_Type
, False);
785 Set_Etype
(Acc_Type
, Acc_Type
);
786 Set_Convention
(Acc_Type
, Get_Convention
(It
.Nam
));
787 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
788 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
789 Freeze_Before
(N
, Acc_Type
);
792 Get_Next_Interp
(Index
, It
);
796 -- Cannot be applied to intrinsic. Looking at the tests above,
797 -- the only way Etype (N) can still be set to Any_Type is if
798 -- Is_Intrinsic_Subprogram was True for some referenced entity.
800 if Etype
(N
) = Any_Type
then
801 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
803 end Build_Access_Subprogram_Type
;
805 ----------------------
806 -- OK_Self_Reference --
807 ----------------------
809 function OK_Self_Reference
return Boolean is
813 -- If N does not come from source, the reference is assumed to be
816 if not Comes_From_Source
(N
) then
823 (Nkind
(Par
) = N_Component_Association
824 or else Nkind
(Par
) in N_Subexpr
)
826 if Nkind
(Par
) in N_Aggregate | N_Extension_Aggregate
then
827 if Etype
(Par
) = Typ
then
828 Set_Has_Self_Reference
(Par
);
830 -- Check the context: the aggregate must be part of the
831 -- initialization of a type or component, or it is the
832 -- resulting expansion in an initialization procedure.
834 if Is_Init_Proc
(Current_Scope
) then
838 while Present
(Par
) loop
839 if Nkind
(Par
) = N_Full_Type_Declaration
then
854 -- No enclosing aggregate, or not a self-reference
857 end OK_Self_Reference
;
859 -- Start of processing for Analyze_Access_Attribute
862 -- Access and Unchecked_Access are illegal in declare_expressions,
863 -- according to the RM. We also make the GNAT Unrestricted_Access
864 -- attribute illegal if it comes from source.
866 if In_Declare_Expr
> 0
867 and then (Attr_Id
/= Attribute_Unrestricted_Access
868 or else Comes_From_Source
(N
))
870 Error_Attr
("% attribute cannot occur in a declare_expression", N
);
875 if Nkind
(P
) = N_Character_Literal
then
877 ("prefix of % attribute cannot be enumeration literal");
880 -- Preserve relevant elaboration-related attributes of the context
881 -- which are no longer available or very expensive to recompute once
882 -- analysis, resolution, and expansion are over.
884 Mark_Elaboration_Attributes
890 -- Save the scenario for later examination by the ABE Processing
893 Record_Elaboration_Scenario
(N
);
895 -- Case of access to subprogram
897 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
898 if Has_Pragma_Inline_Always
(Entity
(P
)) then
900 ("prefix of % attribute cannot be Inline_Always subprogram");
902 elsif Aname
= Name_Unchecked_Access
then
903 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
906 -- Issue an error if the prefix denotes an eliminated subprogram
908 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
910 -- Check for obsolescent subprogram reference
912 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
914 -- Build the appropriate subprogram type
916 Build_Access_Subprogram_Type
(P
);
918 -- For P'Access or P'Unrestricted_Access, where P is a nested
919 -- subprogram, we might be passing P to another subprogram (but we
920 -- don't check that here), which might call P. P could modify
921 -- local variables, so we need to kill current values. It is
922 -- important not to do this for library-level subprograms, because
923 -- Kill_Current_Values is very inefficient in the case of library
924 -- level packages with lots of tagged types.
926 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
929 -- Do not kill values on nodes initializing dispatch tables
930 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
931 -- is currently generated by the expander only for this
932 -- purpose. Done to keep the quality of warnings currently
933 -- generated by the compiler (otherwise any declaration of
934 -- a tagged type cleans constant indications from its scope).
936 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
937 and then (Is_RTE
(Etype
(Parent
(N
)), RE_Prim_Ptr
)
939 Is_RTE
(Etype
(Parent
(N
)), RE_Size_Ptr
))
940 and then Is_Dispatching_Operation
941 (Directly_Designated_Type
(Etype
(N
)))
949 -- In the static elaboration model, treat the attribute reference
950 -- as a subprogram call for elaboration purposes. Suppress this
951 -- treatment under debug flag. In any case, we are all done.
953 if Legacy_Elaboration_Checks
954 and not Dynamic_Elaboration_Checks
955 and not Debug_Flag_Dot_UU
962 -- Component is an operation of a protected type
964 elsif Nkind
(P
) = N_Selected_Component
965 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
967 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
968 Error_Attr_P
("prefix of % attribute must be subprogram");
971 Build_Access_Subprogram_Type
(Selector_Name
(P
));
975 -- Deal with incorrect reference to a type, but note that some
976 -- accesses are allowed: references to the current type instance,
977 -- or in Ada 2005 self-referential pointer in a default-initialized
980 if Is_Entity_Name
(P
) then
983 -- The reference may appear in an aggregate that has been expanded
984 -- into a loop. Locate scope of type definition, if any.
986 Scop
:= Current_Scope
;
987 while Ekind
(Scop
) = E_Loop
loop
988 Scop
:= Scope
(Scop
);
991 if Is_Type
(Typ
) then
993 -- OK if we are within the scope of a limited type
994 -- let's mark the component as having per object constraint
996 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
1002 -- A current instance typically appears immediately within
1003 -- the type declaration, but may be nested within an internally
1004 -- generated temporary scope - as for an aggregate of a
1005 -- discriminated component.
1008 or else (In_Open_Scopes
(Typ
)
1009 and then not Comes_From_Source
(Scop
))
1012 Q
: Node_Id
:= Parent
(N
);
1016 and then Nkind
(Q
) /= N_Component_Declaration
1022 Set_Has_Per_Object_Constraint
1023 (Defining_Identifier
(Q
), True);
1027 if Nkind
(P
) = N_Expanded_Name
then
1029 ("current instance prefix must be a direct name", P
);
1032 -- If a current instance attribute appears in a component
1033 -- constraint it must appear alone; other contexts (spec-
1034 -- expressions, within a task body) are not subject to this
1037 if not In_Spec_Expression
1038 and then not Has_Completion
(Scop
)
1040 Nkind
(Parent
(N
)) not in
1041 N_Discriminant_Association |
1042 N_Index_Or_Discriminant_Constraint
1045 ("current instance attribute must appear alone", N
);
1048 if Is_CPP_Class
(Root_Type
(Typ
)) then
1050 ("??current instance unsupported for derivations of "
1051 & "'C'P'P types", N
);
1054 -- OK if we are in initialization procedure for the type
1055 -- in question, in which case the reference to the type
1056 -- is rewritten as a reference to the current object.
1058 elsif Ekind
(Scop
) = E_Procedure
1059 and then Is_Init_Proc
(Scop
)
1060 and then Etype
(First_Formal
(Scop
)) = Typ
1063 Make_Attribute_Reference
(Loc
,
1064 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1065 Attribute_Name
=> Name_Unrestricted_Access
));
1069 -- OK if a task type, this test needs sharpening up ???
1071 elsif Is_Task_Type
(Typ
) then
1074 -- OK if self-reference in an aggregate in Ada 2005, and
1075 -- the reference comes from a copied default expression.
1077 -- Note that we check legality of self-reference even if the
1078 -- expression comes from source, e.g. when a single component
1079 -- association in an aggregate has a box association.
1081 elsif Ada_Version
>= Ada_2005
and then OK_Self_Reference
then
1084 -- OK if reference to current instance of a protected object
1086 elsif Is_Protected_Self_Reference
(P
) then
1089 -- Otherwise we have an error case
1092 Error_Attr
("% attribute cannot be applied to type", P
);
1097 -- If we fall through, we have a normal access to object case
1099 -- Unrestricted_Access is (for now) legal wherever an allocator would
1100 -- be legal, so its Etype is set to E_Allocator. The expected type
1101 -- of the other attributes is a general access type, and therefore
1102 -- we label them with E_Access_Attribute_Type.
1104 if not Is_Overloaded
(P
) then
1105 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
1106 Set_Etype
(N
, Acc_Type
);
1110 Index
: Interp_Index
;
1113 Set_Etype
(N
, Any_Type
);
1114 Get_First_Interp
(P
, Index
, It
);
1115 while Present
(It
.Typ
) loop
1116 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1117 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1118 Get_Next_Interp
(Index
, It
);
1123 -- Special cases when we can find a prefix that is an entity name
1132 if Is_Entity_Name
(PP
) then
1135 -- If we have an access to an object, and the attribute
1136 -- comes from source, then set the object as potentially
1137 -- source modified. We do this because the resulting access
1138 -- pointer can be used to modify the variable, and we might
1139 -- not detect this, leading to some junk warnings.
1141 -- We only do this for source references, since otherwise
1142 -- we can suppress warnings, e.g. from the unrestricted
1143 -- access generated for validity checks in -gnatVa mode.
1145 if Comes_From_Source
(N
) then
1146 Set_Never_Set_In_Source
(Ent
, False);
1149 -- Mark entity as address taken in the case of
1150 -- 'Unrestricted_Access or subprograms, and kill current
1153 if Aname
= Name_Unrestricted_Access
1154 or else Is_Subprogram
(Ent
)
1156 Set_Address_Taken
(Ent
);
1159 Kill_Current_Values
(Ent
);
1162 elsif Nkind
(PP
) in N_Selected_Component | N_Indexed_Component
1171 end Analyze_Access_Attribute
;
1173 ----------------------------------
1174 -- Analyze_Attribute_Old_Result --
1175 ----------------------------------
1177 procedure Analyze_Attribute_Old_Result
1178 (Legal
: out Boolean;
1179 Spec_Id
: out Entity_Id
)
1181 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1182 -- Verify that the attribute appears within pragma Check that mimics
1185 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1186 -- Verify that the attribute appears within a consequence of aspect
1187 -- or pragma Contract_Cases denoted by Prag.
1189 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1190 -- Verify that the attribute appears within the "Ensures" argument of
1191 -- aspect or pragma Test_Case denoted by Prag.
1195 Encl_Nod
: Node_Id
) return Boolean;
1196 -- Subsidiary to Check_Placement_In_XXX. Determine whether arbitrary
1197 -- node Nod is within enclosing node Encl_Nod.
1199 procedure Placement_Error
;
1200 pragma No_Return
(Placement_Error
);
1201 -- Emit a general error when the attributes does not appear in a
1202 -- postcondition-like aspect or pragma, and then raises Bad_Attribute
1203 -- to avoid any further semantic processing.
1205 ------------------------------
1206 -- Check_Placement_In_Check --
1207 ------------------------------
1209 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1210 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1211 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1214 -- The "Name" argument of pragma Check denotes a postcondition
1218 | Name_Postcondition
1223 -- Otherwise the placement of the attribute is illegal
1228 end Check_Placement_In_Check
;
1230 ---------------------------------------
1231 -- Check_Placement_In_Contract_Cases --
1232 ---------------------------------------
1234 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1240 -- Obtain the argument of the aspect or pragma
1242 if Nkind
(Prag
) = N_Aspect_Specification
then
1245 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1248 Cases
:= Expression
(Arg
);
1250 if Present
(Component_Associations
(Cases
)) then
1251 CCase
:= First
(Component_Associations
(Cases
));
1252 while Present
(CCase
) loop
1254 -- Detect whether the attribute appears within the
1255 -- consequence of the current contract case.
1257 if Nkind
(CCase
) = N_Component_Association
1258 and then Is_Within
(N
, Expression
(CCase
))
1267 -- Otherwise aspect or pragma Contract_Cases is either malformed
1268 -- or the attribute does not appear within a consequence.
1271 ("attribute % must appear in the consequence of a contract case",
1273 end Check_Placement_In_Contract_Cases
;
1275 ----------------------------------
1276 -- Check_Placement_In_Test_Case --
1277 ----------------------------------
1279 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1280 Arg
: constant Node_Id
:=
1283 Arg_Nam
=> Name_Ensures
,
1284 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1287 -- Detect whether the attribute appears within the "Ensures"
1288 -- expression of aspect or pragma Test_Case.
1290 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1295 ("attribute % must appear in the ensures expression of a "
1298 end Check_Placement_In_Test_Case
;
1306 Encl_Nod
: Node_Id
) return Boolean
1312 while Present
(Par
) loop
1313 if Par
= Encl_Nod
then
1316 -- Prevent the search from going too far
1318 elsif Is_Body_Or_Package_Declaration
(Par
) then
1322 Par
:= Parent
(Par
);
1328 ---------------------
1329 -- Placement_Error --
1330 ---------------------
1332 procedure Placement_Error
is
1334 if Aname
= Name_Old
then
1335 Error_Attr
("attribute % can only appear in postcondition", P
);
1337 -- Specialize the error message for attribute 'Result
1341 ("attribute % can only appear in postcondition of function",
1344 end Placement_Error
;
1350 Subp_Decl
: Node_Id
;
1352 -- Start of processing for Analyze_Attribute_Old_Result
1355 -- Assume that the attribute is illegal
1360 -- Skip processing during preanalysis of class-wide preconditions and
1361 -- postconditions since at this stage the expression is not installed
1362 -- yet on its definite context.
1364 if Inside_Class_Condition_Preanalysis
then
1366 Spec_Id
:= Current_Scope
;
1370 -- Traverse the parent chain to find the aspect or pragma where the
1371 -- attribute resides.
1374 while Present
(Prag
) loop
1375 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1378 -- Prevent the search from going too far
1380 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1384 Prag
:= Parent
(Prag
);
1387 -- The attribute is allowed to appear only in postcondition-like
1388 -- aspects or pragmas.
1390 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1391 if Nkind
(Prag
) = N_Aspect_Specification
then
1392 Prag_Nam
:= Chars
(Identifier
(Prag
));
1394 Prag_Nam
:= Pragma_Name
(Prag
);
1397 if Prag_Nam
= Name_Check
then
1398 Check_Placement_In_Check
(Prag
);
1400 elsif Prag_Nam
= Name_Contract_Cases
then
1401 Check_Placement_In_Contract_Cases
(Prag
);
1403 -- Attribute 'Result is allowed to appear in aspect or pragma
1404 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1406 elsif Prag_Nam
in Name_Depends | Name_Refined_Depends
1407 and then Aname
= Name_Result
1411 -- Attribute 'Result is allowed to appear in aspect
1412 -- Relaxed_Initialization (SPARK RM 6.10).
1414 elsif Prag_Nam
= Name_Relaxed_Initialization
1415 and then Aname
= Name_Result
1419 elsif Prag_Nam
in Name_Post
1421 | Name_Postcondition
1426 elsif Prag_Nam
= Name_Test_Case
then
1427 Check_Placement_In_Test_Case
(Prag
);
1433 -- 'Old attribute reference ok in a _Wrapped_Statements procedure
1435 elsif Nkind
(Prag
) = N_Subprogram_Body
1436 and then Ekind
(Defining_Entity
(Prag
)) in Subprogram_Kind
1437 and then Present
(Wrapped_Statements
(Defining_Entity
(Prag
)))
1441 -- Otherwise the placement of the attribute is illegal
1447 -- Find the related subprogram subject to the aspect or pragma
1449 if Nkind
(Prag
) = N_Aspect_Specification
then
1450 Subp_Decl
:= Parent
(Prag
);
1451 elsif Nkind
(Prag
) = N_Subprogram_Body
then
1454 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1457 -- 'Old objects appear in block and extended return statements as
1458 -- part of the expansion of contract wrappers.
1460 if Nkind
(Subp_Decl
) in N_Block_Statement
1461 | N_Extended_Return_Statement
1463 Subp_Decl
:= Parent
(Parent
(Subp_Decl
));
1466 -- The aspect or pragma where the attribute resides should be
1467 -- associated with a subprogram declaration or a body. If this is not
1468 -- the case, then the aspect or pragma is illegal. Return as analysis
1469 -- cannot be carried out. Note that it is legal to have the aspect
1470 -- appear on a subprogram renaming, when the renamed entity is an
1471 -- attribute reference.
1473 -- Generating C code the internally built nested _postcondition
1474 -- subprograms are inlined; after expanded, inlined aspects are
1475 -- located in the internal block generated by the frontend.
1477 if Nkind
(Subp_Decl
) = N_Block_Statement
1478 and then Modify_Tree_For_C
1479 and then In_Inlined_Body
1483 elsif Nkind
(Subp_Decl
) not in N_Abstract_Subprogram_Declaration
1484 | N_Entry_Declaration
1485 | N_Expression_Function
1486 | N_Generic_Subprogram_Declaration
1488 | N_Subprogram_Body_Stub
1489 | N_Subprogram_Declaration
1490 | N_Subprogram_Renaming_Declaration
1495 -- If we get here, then the attribute is legal
1498 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1500 -- When generating C code, nested _postcondition subprograms are
1501 -- inlined by the front end to avoid problems (when unnested) with
1502 -- referenced itypes. Handle that here, since as part of inlining the
1503 -- expander nests subprogram within a dummy procedure named _parent
1504 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1505 -- Hence, in this context, the spec_id of _postconditions is the
1508 if Modify_Tree_For_C
1509 and then Chars
(Spec_Id
) = Name_uParent
1510 and then Chars
(Scope
(Spec_Id
)) = Name_uWrapped_Statements
1512 -- This situation occurs only when analyzing the body-to-inline
1514 pragma Assert
(Inside_A_Generic
);
1516 Spec_Id
:= Scope
(Spec_Id
);
1517 pragma Assert
(Is_Inlined
(Spec_Id
));
1519 end Analyze_Attribute_Old_Result
;
1521 -----------------------------
1522 -- Analyze_Image_Attribute --
1523 -----------------------------
1525 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
) is
1526 procedure Check_Image_Type
(Image_Type
: Entity_Id
);
1527 -- Check that Image_Type is legal as the type of a prefix of 'Image.
1528 -- Legality depends on the Ada language version.
1530 ----------------------
1531 -- Check_Image_Type --
1532 ----------------------
1534 procedure Check_Image_Type
(Image_Type
: Entity_Id
) is
1536 -- Image_Type may be empty in case of another error detected,
1537 -- or if an N_Raise_xxx_Error node is a parent of N.
1539 if Ada_Version
< Ada_2022
1540 and then Present
(Image_Type
)
1541 and then not Is_Scalar_Type
(Image_Type
)
1543 Error_Msg_Ada_2022_Feature
("nonscalar ''Image", Sloc
(P
));
1546 end Check_Image_Type
;
1548 -- Start of processing for Analyze_Image_Attribute
1551 -- AI12-0124: The ARG has adopted the GNAT semantics of 'Img for
1552 -- scalar types, so that the prefix can be an object, a named value,
1553 -- or a type. If the prefix is an object, there is no argument.
1555 if Is_Object_Image
(P
) then
1557 Set_Etype
(N
, Str_Typ
);
1558 Check_Image_Type
(Etype
(P
));
1560 if Attr_Id
/= Attribute_Img
then
1561 Error_Msg_Ada_2012_Feature
("|Object''Image", Sloc
(P
));
1565 Set_Etype
(N
, Str_Typ
);
1567 pragma Assert
(Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)));
1569 if Ekind
(Entity
(P
)) = E_Incomplete_Type
1570 and then Present
(Full_View
(Entity
(P
)))
1572 P_Type
:= Full_View
(Entity
(P
));
1573 P_Base_Type
:= Base_Type
(P_Type
);
1574 Set_Entity
(P
, P_Type
);
1577 Check_Image_Type
(P_Type
);
1578 Resolve
(E1
, P_Base_Type
);
1579 Validate_Non_Static_Attribute_Function_Call
;
1582 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
1584 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
1585 -- to avoid giving a duplicate message for when Image attributes
1586 -- applied to object references get expanded into type-based Image
1589 if Restriction_Check_Required
(No_Fixed_IO
)
1590 and then Comes_From_Source
(N
)
1591 and then Is_Fixed_Point_Type
(P_Type
)
1593 Check_Restriction
(No_Fixed_IO
, P
);
1595 end Analyze_Image_Attribute
;
1597 -----------------------------
1598 -- Analyze_Index_Attribute --
1599 -----------------------------
1601 procedure Analyze_Index_Attribute
1602 (Legal
: out Boolean;
1603 Spec_Id
: out Entity_Id
)
1605 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1606 -- Verify that the attribute appears within pragma Check that mimics
1609 procedure Placement_Error
;
1610 pragma No_Return
(Placement_Error
);
1611 -- Emit a general error when the attributes does not appear in a
1612 -- precondition or postcondition aspect or pragma, and then raises
1613 -- Bad_Attribute to avoid any further semantic processing.
1615 ------------------------------
1616 -- Check_Placement_In_Check --
1617 ------------------------------
1619 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1620 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1621 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1624 -- The "Name" argument of pragma Check denotes a precondition or
1628 | Name_Postcondition
1635 -- Otherwise the placement of the attribute is illegal
1640 end Check_Placement_In_Check
;
1642 ---------------------
1643 -- Placement_Error --
1644 ---------------------
1646 procedure Placement_Error
is
1649 ("attribute % can only appear in pre- or postcondition", P
);
1650 end Placement_Error
;
1656 Subp_Decl
: Node_Id
;
1658 -- Start of processing for Analyze_Index_Attribute
1661 -- Assume that the attribute is illegal
1666 -- Skip processing during preanalysis of class-wide preconditions and
1667 -- postconditions since at this stage the expression is not installed
1668 -- yet on its definite context.
1670 if Inside_Class_Condition_Preanalysis
then
1672 Spec_Id
:= Current_Scope
;
1676 -- Traverse the parent chain to find the aspect or pragma where the
1677 -- attribute resides.
1680 while Present
(Prag
) loop
1681 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1684 -- Prevent the search from going too far
1686 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1690 Prag
:= Parent
(Prag
);
1693 -- The attribute is allowed to appear only in precondition and
1694 -- postcondition-like aspects or pragmas.
1696 if Nkind
(Prag
) in N_Aspect_Specification | N_Pragma
then
1697 if Nkind
(Prag
) = N_Aspect_Specification
then
1698 Prag_Nam
:= Chars
(Identifier
(Prag
));
1700 Prag_Nam
:= Pragma_Name
(Prag
);
1703 if Prag_Nam
= Name_Check
then
1704 Check_Placement_In_Check
(Prag
);
1706 elsif Prag_Nam
in Name_Post
1707 | Name_Postcondition
1718 -- Otherwise the placement of the attribute is illegal
1724 -- Find the related subprogram subject to the aspect or pragma
1726 if Nkind
(Prag
) = N_Aspect_Specification
then
1727 Subp_Decl
:= Parent
(Prag
);
1729 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1732 -- The aspect or pragma where the attribute resides should be
1733 -- associated with a subprogram declaration or a body since the
1734 -- analysis of pre-/postconditions of entry and entry families is
1735 -- performed in their wrapper subprogram. If this is not the case,
1736 -- then the aspect or pragma is illegal and no further analysis is
1739 if Nkind
(Subp_Decl
) not in N_Subprogram_Body
1740 | N_Subprogram_Declaration
1745 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1747 -- If we get here and Spec_Id denotes the entity of the entry wrapper
1748 -- (or the postcondition procedure of the entry wrapper) then the
1749 -- attribute is legal.
1751 if Is_Entry_Wrapper
(Spec_Id
) then
1754 elsif Chars
(Spec_Id
) = Name_uWrapped_Statements
1755 and then Is_Entry_Wrapper
(Scope
(Spec_Id
))
1757 Spec_Id
:= Scope
(Spec_Id
);
1760 -- Otherwise the attribute is illegal and we return Empty
1765 end Analyze_Index_Attribute
;
1767 ---------------------------------
1768 -- Bad_Attribute_For_Predicate --
1769 ---------------------------------
1771 procedure Bad_Attribute_For_Predicate
is
1773 if Is_Scalar_Type
(P_Type
)
1774 and then Comes_From_Source
(N
)
1776 Error_Msg_Name_1
:= Aname
;
1777 Bad_Predicated_Subtype_Use
1778 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1780 end Bad_Attribute_For_Predicate
;
1782 --------------------------------
1783 -- Check_Array_Or_Scalar_Type --
1784 --------------------------------
1786 procedure Check_Array_Or_Scalar_Type
is
1787 function In_Aspect_Specification
return Boolean;
1788 -- A current instance of a type in an aspect specification is an
1789 -- object and not a type, and therefore cannot be of a scalar type
1790 -- in the prefix of one of the array attributes if the attribute
1791 -- reference is part of an aspect expression.
1793 -----------------------------
1794 -- In_Aspect_Specification --
1795 -----------------------------
1797 function In_Aspect_Specification
return Boolean is
1802 while Present
(P
) loop
1803 if Nkind
(P
) = N_Aspect_Specification
then
1804 return P_Type
= Entity
(P
);
1806 elsif Nkind
(P
) in N_Declaration
then
1814 end In_Aspect_Specification
;
1820 -- Start of processing for Check_Array_Or_Scalar_Type
1823 -- Case of string literal or string literal subtype. These cases
1824 -- cannot arise from legal Ada code, but the expander is allowed
1825 -- to generate them. They require special handling because string
1826 -- literal subtypes do not have standard bounds (the whole idea
1827 -- of these subtypes is to avoid having to generate the bounds)
1829 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1830 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1835 elsif Is_Scalar_Type
(P_Type
) then
1838 if Present
(E1
) then
1839 Error_Attr
("invalid argument in % attribute", E1
);
1841 elsif In_Aspect_Specification
then
1843 ("prefix of % attribute cannot be the current instance of a "
1844 & "scalar type", P
);
1847 Set_Etype
(N
, P_Base_Type
);
1851 -- The following is a special test to allow 'First to apply to
1852 -- private scalar types if the attribute comes from generated
1853 -- code. This occurs in the case of Normalize_Scalars code.
1855 elsif Is_Private_Type
(P_Type
)
1856 and then Present
(Full_View
(P_Type
))
1857 and then Is_Scalar_Type
(Full_View
(P_Type
))
1858 and then not Comes_From_Source
(N
)
1860 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1862 -- Array types other than string literal subtypes handled above
1867 -- We know prefix is an array type, or the name of an array
1868 -- object, and that the expression, if present, is static
1869 -- and within the range of the dimensions of the type.
1871 pragma Assert
(Is_Array_Type
(P_Type
));
1872 Index
:= First_Index
(P_Base_Type
);
1876 -- First dimension assumed
1878 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1882 Udims
: constant Uint
:= Expr_Value
(E1
);
1883 Dims
: constant Int
:= UI_To_Int
(Udims
);
1885 for J
in 1 .. Dims
- 1 loop
1890 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1893 end Check_Array_Or_Scalar_Type
;
1895 ----------------------
1896 -- Check_Array_Type --
1897 ----------------------
1899 procedure Check_Array_Type
is
1901 -- Dimension number for array attributes
1904 -- If the type is a string literal type, then this must be generated
1905 -- internally, and no further check is required on its legality.
1907 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1910 -- If the type is a composite, it is an illegal aggregate, no point
1913 elsif P_Type
= Any_Composite
then
1914 raise Bad_Attribute
;
1917 -- Normal case of array type or subtype. Note that if the
1918 -- prefix is a current instance of a type declaration it
1919 -- appears within an aspect specification and is legal.
1921 Check_Either_E0_Or_E1
;
1924 if Is_Array_Type
(P_Type
) then
1925 if not Is_Constrained
(P_Type
)
1926 and then Is_Entity_Name
(P
)
1927 and then Is_Type
(Entity
(P
))
1928 and then not Is_Current_Instance
(P
)
1930 -- Note: we do not call Error_Attr here, since we prefer to
1931 -- continue, using the relevant index type of the array,
1932 -- even though it is unconstrained. This gives better error
1933 -- recovery behavior.
1935 Error_Msg_Name_1
:= Aname
;
1937 ("prefix for % attribute must be constrained array", P
);
1940 -- The attribute reference freezes the type, and thus the
1941 -- component type, even if the attribute may not depend on the
1942 -- component. Diagnose arrays with incomplete components now.
1943 -- If the prefix is an access to array, this does not freeze
1944 -- the designated type.
1946 if Nkind
(P
) /= N_Explicit_Dereference
then
1947 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1950 D
:= Number_Dimensions
(P_Type
);
1953 if Is_Private_Type
(P_Type
) then
1954 Error_Attr_P
("prefix for % attribute may not be private type");
1956 elsif Is_Access_Type
(P_Type
)
1957 and then Is_Array_Type
(Designated_Type
(P_Type
))
1958 and then Is_Entity_Name
(P
)
1959 and then Is_Type
(Entity
(P
))
1961 Error_Attr_P
("prefix of % attribute cannot be access type");
1963 elsif Attr_Id
= Attribute_First
1965 Attr_Id
= Attribute_Last
1967 Error_Attr
("invalid prefix for % attribute", P
);
1970 Error_Attr_P
("prefix for % attribute must be array");
1974 if Present
(E1
) then
1975 Resolve
(E1
, Any_Integer
);
1976 Set_Etype
(E1
, Standard_Integer
);
1978 if not Is_OK_Static_Expression
(E1
)
1979 or else Raises_Constraint_Error
(E1
)
1981 Flag_Non_Static_Expr
1982 ("expression for dimension must be static!", E1
);
1985 elsif Expr_Value
(E1
) > D
or else Expr_Value
(E1
) < 1 then
1986 Error_Attr
("invalid dimension number for array type", E1
);
1990 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1991 and then Comes_From_Source
(N
)
1993 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1995 end Check_Array_Type
;
1997 -------------------------
1998 -- Check_Asm_Attribute --
1999 -------------------------
2001 procedure Check_Asm_Attribute
is
2006 -- Check first argument is static string expression
2008 Analyze_And_Resolve
(E1
, Standard_String
);
2010 if Etype
(E1
) = Any_Type
then
2013 elsif not Is_OK_Static_Expression
(E1
) then
2014 Flag_Non_Static_Expr
2015 ("constraint argument must be static string expression!", E1
);
2019 -- Check second argument is right type
2021 Analyze_And_Resolve
(E2
, Entity
(P
));
2023 -- Note: that is all we need to do, we don't need to check
2024 -- that it appears in a correct context. The Ada type system
2025 -- will do that for us.
2027 end Check_Asm_Attribute
;
2029 ---------------------
2030 -- Check_Component --
2031 ---------------------
2033 procedure Check_Component
is
2037 if Nkind
(P
) /= N_Selected_Component
2039 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
2041 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
2043 Error_Attr_P
("prefix for % attribute must be selected component");
2045 end Check_Component
;
2047 ------------------------------------
2048 -- Check_Decimal_Fixed_Point_Type --
2049 ------------------------------------
2051 procedure Check_Decimal_Fixed_Point_Type
is
2055 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
2056 Error_Attr_P
("prefix of % attribute must be decimal type");
2058 end Check_Decimal_Fixed_Point_Type
;
2060 -----------------------
2061 -- Check_Dereference --
2062 -----------------------
2064 procedure Check_Dereference
is
2067 -- Case of a subtype mark
2069 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2073 -- Case of an expression
2077 if Is_Access_Type
(P_Type
) then
2079 -- If there is an implicit dereference, then we must freeze the
2080 -- designated type of the access type, since the type of the
2081 -- referenced array is this type (see AI95-00106).
2083 -- As done elsewhere, freezing must not happen when preanalyzing
2084 -- a pre- or postcondition or a default value for an object or for
2085 -- a formal parameter.
2087 if not In_Spec_Expression
then
2088 Freeze_Before
(N
, Designated_Type
(P_Type
));
2092 Make_Explicit_Dereference
(Sloc
(P_Old
),
2093 Prefix
=> Relocate_Node
(P_Old
)));
2095 Analyze_And_Resolve
(P_Old
);
2096 P_Type
:= Etype
(P_Old
);
2098 if P_Type
= Any_Type
then
2099 raise Bad_Attribute
;
2102 P_Base_Type
:= Base_Type
(P_Type
);
2104 end Check_Dereference
;
2106 -------------------------
2107 -- Check_Discrete_Type --
2108 -------------------------
2110 procedure Check_Discrete_Type
is
2114 if not Is_Discrete_Type
(P_Type
) then
2115 Error_Attr_P
("prefix of % attribute must be discrete type");
2117 end Check_Discrete_Type
;
2123 procedure Check_E0
is
2125 if Present
(E1
) then
2126 Unexpected_Argument
(E1
);
2134 procedure Check_E1
is
2136 Check_Either_E0_Or_E1
;
2140 -- Special-case attributes that are functions and that appear as
2141 -- the prefix of another attribute. Error is posted on parent.
2143 if Nkind
(Parent
(N
)) = N_Attribute_Reference
2144 and then Attribute_Name
(Parent
(N
)) in Name_Address
2148 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
2149 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
2150 Set_Etype
(Parent
(N
), Any_Type
);
2151 Set_Entity
(Parent
(N
), Any_Type
);
2152 raise Bad_Attribute
;
2155 Error_Attr
("missing argument for % attribute", N
);
2164 procedure Check_E2
is
2167 Error_Attr
("missing arguments for % attribute (2 required)", N
);
2169 Error_Attr
("missing argument for % attribute (2 required)", N
);
2173 ---------------------------
2174 -- Check_Either_E0_Or_E1 --
2175 ---------------------------
2177 procedure Check_Either_E0_Or_E1
is
2179 if Present
(E2
) then
2180 Unexpected_Argument
(E2
);
2182 end Check_Either_E0_Or_E1
;
2184 ----------------------
2185 -- Check_Enum_Image --
2186 ----------------------
2188 procedure Check_Enum_Image
(Check_Enumeration_Maps
: Boolean := False) is
2192 -- Ensure that Check_Enumeration_Maps parameter is set precisely for
2193 -- attributes whose implementation requires enumeration maps.
2196 (Check_Enumeration_Maps
= (Attr_Id
in Attribute_Image
2198 | Attribute_Valid_Value
2200 | Attribute_Wide_Image
2201 | Attribute_Wide_Value
2202 | Attribute_Wide_Wide_Image
2203 | Attribute_Wide_Wide_Value
));
2205 -- When an enumeration type appears in an attribute reference, all
2206 -- literals of the type are marked as referenced. This must only be
2207 -- done if the attribute reference appears in the current source.
2208 -- Otherwise the information on references may differ between a
2209 -- normal compilation and one that performs inlining.
2211 if Is_Enumeration_Type
(P_Base_Type
)
2212 and then In_Extended_Main_Code_Unit
(N
)
2214 if Check_Enumeration_Maps
then
2215 Check_Restriction
(No_Enumeration_Maps
, N
);
2218 Lit
:= First_Literal
(P_Base_Type
);
2219 while Present
(Lit
) loop
2220 Set_Referenced
(Lit
);
2224 end Check_Enum_Image
;
2226 ----------------------------
2227 -- Check_First_Last_Valid --
2228 ----------------------------
2230 procedure Check_First_Last_Valid
is
2232 Check_Discrete_Type
;
2234 -- Freeze the subtype now, so that the following test for predicates
2235 -- works (we set the predicates stuff up at freeze time)
2237 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
2239 -- Now test for dynamic predicate
2241 if Has_Predicates
(P_Type
)
2242 and then not (Has_Static_Predicate
(P_Type
))
2245 ("prefix of % attribute may not have dynamic predicate");
2248 -- Check non-static subtype
2250 if not Is_OK_Static_Subtype
(P_Type
) then
2251 Error_Attr_P
("prefix of % attribute must be a static subtype");
2254 -- Test case for no values
2256 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
2257 Expr_Value
(Type_High_Bound
(P_Type
))
2258 or else (Has_Predicates
(P_Type
)
2260 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
2263 ("prefix of % attribute must be subtype with at least one "
2266 end Check_First_Last_Valid
;
2268 ----------------------------
2269 -- Check_Fixed_Point_Type --
2270 ----------------------------
2272 procedure Check_Fixed_Point_Type
is
2276 if not Is_Fixed_Point_Type
(P_Type
) then
2277 Error_Attr_P
("prefix of % attribute must be fixed point type");
2279 end Check_Fixed_Point_Type
;
2281 ------------------------------
2282 -- Check_Fixed_Point_Type_0 --
2283 ------------------------------
2285 procedure Check_Fixed_Point_Type_0
is
2287 Check_Fixed_Point_Type
;
2289 end Check_Fixed_Point_Type_0
;
2291 -------------------------------
2292 -- Check_Floating_Point_Type --
2293 -------------------------------
2295 procedure Check_Floating_Point_Type
is
2299 if not Is_Floating_Point_Type
(P_Type
) then
2300 Error_Attr_P
("prefix of % attribute must be float type");
2302 end Check_Floating_Point_Type
;
2304 ---------------------------------
2305 -- Check_Floating_Point_Type_0 --
2306 ---------------------------------
2308 procedure Check_Floating_Point_Type_0
is
2310 Check_Floating_Point_Type
;
2312 end Check_Floating_Point_Type_0
;
2314 ---------------------------------
2315 -- Check_Floating_Point_Type_1 --
2316 ---------------------------------
2318 procedure Check_Floating_Point_Type_1
is
2320 Check_Floating_Point_Type
;
2322 end Check_Floating_Point_Type_1
;
2324 ---------------------------------
2325 -- Check_Floating_Point_Type_2 --
2326 ---------------------------------
2328 procedure Check_Floating_Point_Type_2
is
2330 Check_Floating_Point_Type
;
2332 end Check_Floating_Point_Type_2
;
2334 ------------------------
2335 -- Check_Integer_Type --
2336 ------------------------
2338 procedure Check_Integer_Type
is
2342 if not Is_Integer_Type
(P_Type
) then
2343 Error_Attr_P
("prefix of % attribute must be integer type");
2345 end Check_Integer_Type
;
2347 --------------------------------
2348 -- Check_Modular_Integer_Type --
2349 --------------------------------
2351 procedure Check_Modular_Integer_Type
is
2355 if not Is_Modular_Integer_Type
(P_Type
) then
2357 ("prefix of % attribute must be modular integer type");
2359 end Check_Modular_Integer_Type
;
2361 ------------------------
2362 -- Check_Not_CPP_Type --
2363 ------------------------
2365 procedure Check_Not_CPP_Type
is
2367 if Is_Tagged_Type
(Etype
(P
))
2368 and then Convention
(Etype
(P
)) = Convention_CPP
2369 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
2372 ("invalid use of % attribute with 'C'P'P tagged type");
2374 end Check_Not_CPP_Type
;
2376 -------------------------------
2377 -- Check_Not_Incomplete_Type --
2378 -------------------------------
2380 procedure Check_Not_Incomplete_Type
is
2385 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2386 -- dereference we have to check wrong uses of incomplete types
2387 -- (other wrong uses are checked at their freezing point).
2389 -- In Ada 2012, incomplete types can appear in subprogram
2390 -- profiles, but formals with incomplete types cannot be the
2391 -- prefix of attributes.
2393 -- Example 1: Limited-with
2395 -- limited with Pkg;
2397 -- type Acc is access Pkg.T;
2399 -- S : Integer := X.all'Size; -- ERROR
2402 -- Example 2: Tagged incomplete
2404 -- type T is tagged;
2405 -- type Acc is access all T;
2407 -- S : constant Integer := X.all'Size; -- ERROR
2408 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2410 if Ada_Version
>= Ada_2005
2411 and then Nkind
(P
) = N_Explicit_Dereference
2414 while Nkind
(E
) = N_Explicit_Dereference
loop
2420 if From_Limited_With
(Typ
) then
2422 ("prefix of % attribute cannot be an incomplete type");
2424 -- If the prefix is an access type check the designated type
2426 elsif Is_Access_Type
(Typ
)
2427 and then Nkind
(P
) = N_Explicit_Dereference
2429 Typ
:= Directly_Designated_Type
(Typ
);
2432 if Is_Class_Wide_Type
(Typ
) then
2433 Typ
:= Root_Type
(Typ
);
2436 -- A legal use of a shadow entity occurs only when the unit where
2437 -- the non-limited view resides is imported via a regular with
2438 -- clause in the current body. Such references to shadow entities
2439 -- may occur in subprogram formals.
2441 if Is_Incomplete_Type
(Typ
)
2442 and then From_Limited_With
(Typ
)
2443 and then Present
(Non_Limited_View
(Typ
))
2444 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2446 Typ
:= Non_Limited_View
(Typ
);
2449 -- If still incomplete, it can be a local incomplete type, or a
2450 -- limited view whose scope is also a limited view.
2452 if Ekind
(Typ
) = E_Incomplete_Type
then
2453 if not From_Limited_With
(Typ
)
2454 and then No
(Full_View
(Typ
))
2457 ("prefix of % attribute cannot be an incomplete type");
2459 -- The limited view may be available indirectly through
2460 -- an intermediate unit. If the non-limited view is available
2461 -- the attribute reference is legal.
2463 elsif From_Limited_With
(Typ
)
2465 (No
(Non_Limited_View
(Typ
))
2466 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2469 ("prefix of % attribute cannot be an incomplete type");
2473 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2476 elsif Is_Entity_Name
(P
)
2477 and then Is_Formal
(Entity
(P
))
2478 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2481 ("prefix of % attribute cannot be an incomplete type");
2484 if not Is_Entity_Name
(P
)
2485 or else not Is_Type
(Entity
(P
))
2486 or else In_Spec_Expression
2490 Check_Fully_Declared
(P_Type
, P
);
2492 end Check_Not_Incomplete_Type
;
2494 ----------------------------
2495 -- Check_Object_Reference --
2496 ----------------------------
2498 procedure Check_Object_Reference
(P
: Node_Id
) is
2502 -- If we need an object, and we have a prefix that is the name of a
2503 -- function entity, convert it into a function call.
2505 if Is_Entity_Name
(P
)
2506 and then Ekind
(Entity
(P
)) = E_Function
2508 Rtyp
:= Etype
(Entity
(P
));
2511 Make_Function_Call
(Sloc
(P
),
2512 Name
=> Relocate_Node
(P
)));
2514 Analyze_And_Resolve
(P
, Rtyp
);
2516 -- Otherwise we must have an object reference
2518 elsif not Is_Object_Reference
(P
) then
2519 Error_Attr_P
("prefix of % attribute must be object");
2521 end Check_Object_Reference
;
2523 ----------------------------
2524 -- Check_PolyORB_Attribute --
2525 ----------------------------
2527 procedure Check_PolyORB_Attribute
is
2529 Validate_Non_Static_Attribute_Function_Call
;
2534 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2536 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2538 end Check_PolyORB_Attribute
;
2540 ------------------------
2541 -- Check_Program_Unit --
2542 ------------------------
2544 procedure Check_Program_Unit
is
2546 if Is_Entity_Name
(P
) then
2548 E
: constant Entity_Id
:= Entity
(P
);
2550 if Ekind
(E
) in E_Protected_Type
2556 or else Is_Single_Concurrent_Object
(E
)
2563 Error_Attr_P
("prefix of % attribute must be program unit");
2564 end Check_Program_Unit
;
2566 ---------------------
2567 -- Check_Real_Type --
2568 ---------------------
2570 procedure Check_Real_Type
is
2574 if not Is_Real_Type
(P_Type
) then
2575 Error_Attr_P
("prefix of % attribute must be real type");
2577 end Check_Real_Type
;
2579 ----------------------------
2580 -- Check_Enumeration_Type --
2581 ----------------------------
2583 procedure Check_Enumeration_Type
is
2587 if not Is_Enumeration_Type
(P_Type
) then
2588 Error_Attr_P
("prefix of % attribute must be enumeration type");
2590 end Check_Enumeration_Type
;
2592 -----------------------
2593 -- Check_Scalar_Type --
2594 -----------------------
2596 procedure Check_Scalar_Type
is
2600 if not Is_Scalar_Type
(P_Type
) then
2601 Error_Attr_P
("prefix of % attribute must be scalar type");
2603 end Check_Scalar_Type
;
2605 ---------------------------
2606 -- Check_Standard_Prefix --
2607 ---------------------------
2609 procedure Check_Standard_Prefix
is
2613 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2614 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2616 end Check_Standard_Prefix
;
2618 -------------------------------
2619 -- Check_Put_Image_Attribute --
2620 -------------------------------
2622 procedure Check_Put_Image_Attribute
is
2624 -- Put_Image is a procedure, and can only appear at the position of a
2625 -- procedure call. If it's a list member and it's parent is a
2626 -- procedure call or aggregate, then this is appearing as an actual
2627 -- parameter or component association, which is wrong.
2629 if Is_List_Member
(N
)
2630 and then Nkind
(Parent
(N
)) not in
2631 N_Procedure_Call_Statement | N_Aggregate
2636 ("invalid context for attribute%, which is a procedure", N
);
2640 Analyze_And_Resolve
(E1
);
2642 -- Check that the first argument is
2643 -- Ada.Strings.Text_Buffers.Root_Buffer_Type'Class.
2645 -- Note: the double call to Root_Type here is needed because the
2646 -- root type of a class-wide type is the corresponding type (e.g.
2647 -- X for X'Class, and we really want to go to the root.)
2649 if not Is_RTE
(Root_Type
(Root_Type
(Etype
(E1
))),
2650 RE_Root_Buffer_Type
)
2653 ("expected Ada.Strings.Text_Buffers.Root_Buffer_Type''Class",
2657 -- Check that the second argument is of the right type
2660 Resolve
(E2
, P_Type
);
2661 end Check_Put_Image_Attribute
;
2663 ----------------------------
2664 -- Check_Stream_Attribute --
2665 ----------------------------
2667 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2671 In_Shared_Var_Procs
: Boolean;
2672 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2673 -- For this runtime package (always compiled in GNAT mode), we allow
2674 -- stream attributes references for limited types for the case where
2675 -- shared passive objects are implemented using stream attributes,
2676 -- which is the default in GNAT's persistent storage implementation.
2679 Validate_Non_Static_Attribute_Function_Call
;
2681 -- With the exception of 'Input, Stream attributes are procedures,
2682 -- and can only appear at the position of procedure calls. We check
2683 -- for this here, before they are rewritten, to give a more precise
2686 if Nam
= TSS_Stream_Input
then
2689 elsif Is_List_Member
(N
)
2690 and then Nkind
(Parent
(N
)) not in
2691 N_Procedure_Call_Statement | N_Aggregate
2697 ("invalid context for attribute%, which is a procedure", N
);
2701 Btyp
:= Implementation_Base_Type
(P_Type
);
2703 -- Stream attributes not allowed on limited types unless the
2704 -- attribute reference was generated by the expander (in which
2705 -- case the underlying type will be used, as described in Sinfo),
2706 -- or the attribute was specified explicitly for the type itself
2707 -- or one of its ancestors (taking visibility rules into account if
2708 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2709 -- (with no visibility restriction).
2712 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2714 if Present
(Gen_Body
) then
2715 In_Shared_Var_Procs
:=
2716 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2718 In_Shared_Var_Procs
:= False;
2722 if (Comes_From_Source
(N
)
2723 and then not (In_Shared_Var_Procs
or In_Instance
))
2724 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2725 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2727 Error_Msg_Name_1
:= Aname
;
2729 if Is_Limited_Type
(P_Type
) then
2731 ("limited type& has no% attribute", P
, P_Type
);
2732 Explain_Limited_Type
(P_Type
, P
);
2735 ("attribute% for type& is not available", P
, P_Type
);
2739 -- Check for no stream operations allowed from No_Tagged_Streams
2741 if Is_Tagged_Type
(P_Type
)
2742 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2744 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2746 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2750 -- Check restriction violations
2752 -- First check the No_Streams restriction, which prohibits the use
2753 -- of explicit stream attributes in the source program. We do not
2754 -- prevent the occurrence of stream attributes in generated code,
2755 -- for instance those generated implicitly for dispatching purposes.
2757 if Comes_From_Source
(N
) then
2758 Check_Restriction
(No_Streams
, P
);
2761 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2762 -- it is illegal to use a predefined elementary type stream attribute
2763 -- either by itself, or more importantly as part of the attribute
2764 -- subprogram for a composite type. However, if the broader
2765 -- restriction No_Streams is active, stream operations are not
2766 -- generated, and there is no error.
2768 if Restriction_Active
(No_Default_Stream_Attributes
)
2769 and then not Restriction_Active
(No_Streams
)
2775 if Nam
= TSS_Stream_Input
2777 Nam
= TSS_Stream_Read
2780 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2783 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2787 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2790 ("missing user-defined Stream Read or Write for type&",
2792 if not Is_Elementary_Type
(P_Type
) then
2794 ("\which is a component of type&", N
, P_Type
);
2800 -- Check special case of Exception_Id and Exception_Occurrence which
2801 -- are not allowed for restriction No_Exception_Registration.
2803 if Restriction_Check_Required
(No_Exception_Registration
)
2804 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2806 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2808 Check_Restriction
(No_Exception_Registration
, P
);
2811 -- If the No_Tagged_Type_Registration restriction is active, then
2812 -- class-wide streaming attributes are not allowed.
2814 if Restriction_Check_Required
(No_Tagged_Type_Registration
)
2815 and then Is_Class_Wide_Type
(P_Type
)
2817 Check_Restriction
(No_Tagged_Type_Registration
, P
);
2820 -- Here we must check that the first argument is an access type
2821 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2823 Analyze_And_Resolve
(E1
);
2826 -- Note: the double call to Root_Type here is needed because the
2827 -- root type of a class-wide type is the corresponding type (e.g.
2828 -- X for X'Class, and we really want to go to the root.)
2830 if not Is_Access_Type
(Etyp
)
2831 or else not Is_RTE
(Root_Type
(Root_Type
(Designated_Type
(Etyp
))),
2832 RE_Root_Stream_Type
)
2835 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2838 -- Check that the second argument is of the right type if there is
2839 -- one (the Input attribute has only one argument so this is skipped)
2841 if Present
(E2
) then
2844 if Nam
= TSS_Stream_Read
2845 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2848 ("second argument of % attribute must be a variable", E2
);
2851 Resolve
(E2
, P_Type
);
2855 end Check_Stream_Attribute
;
2857 -------------------------
2858 -- Check_System_Prefix --
2859 -------------------------
2861 procedure Check_System_Prefix
is
2863 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2864 Error_Attr
("only allowed prefix for % attribute is System", P
);
2866 end Check_System_Prefix
;
2868 -----------------------
2869 -- Check_Task_Prefix --
2870 -----------------------
2872 procedure Check_Task_Prefix
is
2874 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2875 -- task interface class-wide types.
2877 if Is_Task_Type
(Etype
(P
))
2878 or else (Is_Access_Type
(Etype
(P
))
2879 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2880 or else (Ada_Version
>= Ada_2005
2881 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2882 and then Is_Interface
(Etype
(P
))
2883 and then Is_Task_Interface
(Etype
(P
)))
2888 if Ada_Version
>= Ada_2005
then
2890 ("prefix of % attribute must be a task or a task " &
2891 "interface class-wide object");
2894 Error_Attr_P
("prefix of % attribute must be a task");
2897 end Check_Task_Prefix
;
2903 -- The possibilities are an entity name denoting a type, or an
2904 -- attribute reference that denotes a type (Base or Class). If
2905 -- the type is incomplete, replace it with its full view.
2907 procedure Check_Type
is
2909 if not Is_Entity_Name
(P
)
2910 or else not Is_Type
(Entity
(P
))
2912 Error_Attr_P
("prefix of % attribute must be a type");
2914 elsif Is_Protected_Self_Reference
(P
) then
2916 ("prefix of % attribute denotes current instance "
2917 & "(RM 9.4(21/2))");
2919 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2920 and then Present
(Full_View
(Entity
(P
)))
2922 P_Type
:= Full_View
(Entity
(P
));
2923 Set_Entity
(P
, P_Type
);
2927 ---------------------
2928 -- Check_Unit_Name --
2929 ---------------------
2931 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2933 if Nkind
(Nod
) = N_Identifier
then
2936 elsif Nkind
(Nod
) in N_Selected_Component | N_Expanded_Name
then
2937 Check_Unit_Name
(Prefix
(Nod
));
2939 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2944 Error_Attr
("argument for % attribute must be unit name", P
);
2945 end Check_Unit_Name
;
2951 procedure Error_Attr
is
2953 Set_Etype
(N
, Any_Type
);
2954 Set_Entity
(N
, Any_Type
);
2955 raise Bad_Attribute
;
2958 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2960 Error_Msg_Name_1
:= Aname
;
2961 Error_Msg_N
(Msg
, Error_Node
);
2969 procedure Error_Attr_P
(Msg
: String; Msg_Cont
: String := "") is
2971 Error_Msg_Name_1
:= Aname
;
2972 Error_Msg_F
(Msg
, P
);
2973 if Msg_Cont
/= "" then
2974 Error_Msg_F
(Msg_Cont
, P
);
2979 ----------------------------
2980 -- Legal_Formal_Attribute --
2981 ----------------------------
2983 procedure Legal_Formal_Attribute
is
2987 if not Is_Entity_Name
(P
)
2988 or else not Is_Type
(Entity
(P
))
2990 Error_Attr_P
("prefix of % attribute must be generic type");
2992 elsif Is_Generic_Actual_Type
(Entity
(P
))
2994 or else In_Inlined_Body
2998 elsif Is_Generic_Type
(Entity
(P
)) then
2999 if Is_Definite_Subtype
(Entity
(P
)) then
3001 ("prefix of % attribute must be indefinite generic type");
3006 ("prefix of % attribute must be indefinite generic type");
3009 Set_Etype
(N
, Standard_Boolean
);
3010 end Legal_Formal_Attribute
;
3012 ---------------------------------------------------------------
3013 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
3014 ---------------------------------------------------------------
3016 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
3020 Check_Not_Incomplete_Type
;
3021 Set_Etype
(N
, Universal_Integer
);
3022 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
3028 procedure Min_Max
is
3030 -- Attribute can appear as function name in a reduction.
3031 -- Semantic checks are performed later.
3033 if Nkind
(Parent
(N
)) = N_Attribute_Reference
3034 and then Attribute_Name
(Parent
(N
)) = Name_Reduce
3036 Set_Etype
(N
, P_Base_Type
);
3042 Resolve
(E1
, P_Base_Type
);
3043 Resolve
(E2
, P_Base_Type
);
3044 Set_Etype
(N
, P_Base_Type
);
3046 -- Check for comparison on unordered enumeration type
3048 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
3049 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
3051 ("comparison on unordered enumeration type& declared#?.u?",
3056 ------------------------
3057 -- Standard_Attribute --
3058 ------------------------
3060 procedure Standard_Attribute
(Val
: Int
) is
3062 Check_Standard_Prefix
;
3063 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
3065 Set_Is_Static_Expression
(N
, True);
3066 end Standard_Attribute
;
3068 --------------------
3069 -- Uneval_Old_Msg --
3070 --------------------
3072 procedure Uneval_Old_Msg
is
3073 Uneval_Old_Setting
: Character;
3077 -- If from aspect, then Uneval_Old_Setting comes from flags in the
3078 -- N_Aspect_Specification node that corresponds to the attribute.
3080 -- First find the pragma in which we appear (note that at this stage,
3081 -- even if we appeared originally within an aspect specification, we
3082 -- are now within the corresponding pragma).
3086 Prag
:= Parent
(Prag
);
3087 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
3090 if Present
(Prag
) then
3091 if Uneval_Old_Accept
(Prag
) then
3092 Uneval_Old_Setting
:= 'A';
3093 elsif Uneval_Old_Warn
(Prag
) then
3094 Uneval_Old_Setting
:= 'W';
3096 Uneval_Old_Setting
:= 'E';
3099 -- If we did not find the pragma, that's odd, just use the setting
3100 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
3103 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
3106 -- Processing depends on the setting of Uneval_Old
3108 case Uneval_Old_Setting
is
3110 -- ??? In the case where Ada_Version is < Ada_2022 and
3111 -- an illegal 'Old prefix would be legal in Ada_2022,
3112 -- we'd like to call Error_Msg_Ada_2022_Feature.
3113 -- Identifying that case involves some work.
3116 ("prefix of attribute % that is potentially "
3117 & "unevaluated must statically name an entity"
3119 -- further text needed for accuracy if Ada_2022
3120 & (if Ada_Version
>= Ada_2022
3121 and then Attr_Id
= Attribute_Old
3122 then " or be eligible for conditional evaluation"
3123 & " (RM 6.1.1 (27))"
3126 "\using pragma Unevaluated_Use_Of_Old (Allow) will make "
3130 Error_Msg_Name_1
:= Aname
;
3132 ("??prefix of attribute % appears in potentially "
3133 & "unevaluated context, exception may be raised", P
);
3139 raise Program_Error
;
3143 -------------------------
3144 -- Unexpected Argument --
3145 -------------------------
3147 procedure Unexpected_Argument
(En
: Node_Id
) is
3149 Error_Attr
("unexpected argument for % attribute", En
);
3150 end Unexpected_Argument
;
3152 -------------------------------------------------
3153 -- Validate_Non_Static_Attribute_Function_Call --
3154 -------------------------------------------------
3156 -- This function should be moved to Sem_Dist ???
3158 procedure Validate_Non_Static_Attribute_Function_Call
is
3160 if In_Preelaborated_Unit
3161 and then not In_Subprogram_Or_Concurrent_Unit
3163 Flag_Non_Static_Expr
3164 ("non-static function call in preelaborated unit!", N
);
3166 end Validate_Non_Static_Attribute_Function_Call
;
3168 -- Start of processing for Analyze_Attribute
3171 -- Immediate return if unrecognized attribute (already diagnosed by
3172 -- parser, so there is nothing more that we need to do).
3174 if not Is_Attribute_Name
(Aname
) then
3175 raise Bad_Attribute
;
3178 Check_Restriction_No_Use_Of_Attribute
(N
);
3180 -- Deal with Ada 83 issues
3182 if Comes_From_Source
(N
) then
3183 if not Attribute_83
(Attr_Id
) then
3184 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3185 Error_Msg_Name_1
:= Aname
;
3186 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
3189 if Attribute_Impl_Def
(Attr_Id
) then
3190 Check_Restriction
(No_Implementation_Attributes
, N
);
3195 -- Deal with Ada 2005 attributes that are implementation attributes
3196 -- because they appear in a version of Ada before Ada 2005, ditto for
3197 -- Ada 2012 and Ada 2022 attributes appearing in an earlier version.
3199 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
3201 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
3203 (Attribute_22
(Attr_Id
) and then Ada_Version
< Ada_2022
)
3205 Check_Restriction
(No_Implementation_Attributes
, N
);
3208 -- Remote access to subprogram type access attribute reference needs
3209 -- unanalyzed copy for tree transformation. The analyzed copy is used
3210 -- for its semantic information (whether prefix is a remote subprogram
3211 -- name), the unanalyzed copy is used to construct new subtree rooted
3212 -- with N_Aggregate which represents a fat pointer aggregate.
3214 if Aname
= Name_Access
then
3215 Discard_Node
(Copy_Separate_Tree
(N
));
3218 -- Analyze prefix and exit if error in analysis. If the prefix is an
3219 -- incomplete type, use full view if available. Note that there are
3220 -- some attributes for which we do not analyze the prefix, since the
3221 -- prefix is not a normal name, or else needs special handling.
3223 if Aname
/= Name_Elab_Body
and then
3224 Aname
/= Name_Elab_Spec
and then
3225 Aname
/= Name_Elab_Subp_Body
and then
3226 Aname
/= Name_Enabled
and then
3230 P_Type
:= Etype
(P
);
3232 if Is_Entity_Name
(P
)
3233 and then Present
(Entity
(P
))
3234 and then Is_Type
(Entity
(P
))
3236 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
3237 P_Type
:= Get_Full_View
(P_Type
);
3238 Set_Entity
(P
, P_Type
);
3239 Set_Etype
(P
, P_Type
);
3241 elsif Entity
(P
) = Current_Scope
3242 and then Is_Record_Type
(Entity
(P
))
3244 -- Use of current instance within the type. Verify that if the
3245 -- attribute appears within a constraint, it yields an access
3246 -- type, other uses are illegal.
3254 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
3256 Par
:= Parent
(Par
);
3260 and then Nkind
(Par
) = N_Subtype_Indication
3262 if Attr_Id
/= Attribute_Access
3263 and then Attr_Id
/= Attribute_Unchecked_Access
3264 and then Attr_Id
/= Attribute_Unrestricted_Access
3267 ("in a constraint the current instance can only "
3268 & "be used with an access attribute", N
);
3275 if P_Type
= Any_Type
then
3276 raise Bad_Attribute
;
3279 P_Base_Type
:= Base_Type
(P_Type
);
3282 -- Analyze expressions that may be present, exiting if an error occurs
3289 E1
:= First
(Exprs
);
3291 -- Skip analysis for case of Restriction_Set, we do not expect
3292 -- the argument to be analyzed in this case.
3294 if Aname
/= Name_Restriction_Set
then
3297 -- Check for missing/bad expression (result of previous error)
3299 if No
(E1
) or else Etype
(E1
) = Any_Type
then
3300 raise Bad_Attribute
;
3306 if Present
(E2
) then
3309 if Etype
(E2
) = Any_Type
then
3310 raise Bad_Attribute
;
3313 if Present
(Next
(E2
)) then
3314 Unexpected_Argument
(Next
(E2
));
3319 -- Cases where prefix must be resolvable by itself
3321 if Is_Overloaded
(P
)
3322 and then Aname
/= Name_Access
3323 and then Aname
/= Name_Address
3324 and then Aname
/= Name_Code_Address
3325 and then Aname
/= Name_Result
3326 and then Aname
/= Name_Unchecked_Access
3328 -- The prefix must be resolvable by itself, without reference to the
3329 -- attribute. One case that requires special handling is a prefix
3330 -- that is a function name, where one interpretation may be a
3331 -- parameterless call. Entry attributes are handled specially below.
3333 if Is_Entity_Name
(P
)
3334 and then Aname
not in Name_Count | Name_Caller
3336 Check_Parameterless_Call
(P
);
3339 if Is_Overloaded
(P
) then
3341 -- Ada 2005 (AI-345): Since protected and task types have
3342 -- primitive entry wrappers, the attributes Count, and Caller
3343 -- require a context check
3345 if Aname
in Name_Count | Name_Caller
then
3347 Count
: Natural := 0;
3352 Get_First_Interp
(P
, I
, It
);
3353 while Present
(It
.Nam
) loop
3354 if Comes_From_Source
(It
.Nam
) then
3360 Get_Next_Interp
(I
, It
);
3364 Error_Attr
("ambiguous prefix for % attribute", P
);
3366 Set_Is_Overloaded
(P
, False);
3371 Error_Attr
("ambiguous prefix for % attribute", P
);
3376 -- If the prefix was rewritten as a raise node, then rewrite N as a
3377 -- raise node, to avoid creating inconsistent trees. We still need to
3378 -- perform legality checks on the original tree.
3380 if Nkind
(P
) in N_Raise_xxx_Error
then
3381 Rewrite
(N
, Relocate_Node
(P
));
3382 P
:= Original_Node
(P_Old
);
3385 -- Remaining processing depends on attribute
3389 -- Attributes related to Ada 2012 iterators. Attribute specifications
3390 -- exist for these, but they cannot be queried.
3392 when Attribute_Constant_Indexing
3393 | Attribute_Default_Iterator
3394 | Attribute_Implicit_Dereference
3395 | Attribute_Iterator_Element
3396 | Attribute_Iterable
3397 | Attribute_Variable_Indexing
3399 Error_Msg_N
("illegal attribute", N
);
3401 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
3402 -- were already rejected by the parser. Thus they shouldn't appear here.
3404 when Internal_Attribute_Id
=>
3405 raise Program_Error
;
3411 when Attribute_Abort_Signal
=>
3412 Check_Standard_Prefix
;
3413 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
3420 when Attribute_Access
=>
3421 Analyze_Access_Attribute
;
3422 Check_Not_Incomplete_Type
;
3428 when Attribute_Address
=>
3431 Check_Not_Incomplete_Type
;
3432 Set_Etype
(N
, RTE
(RE_Address
));
3438 when Attribute_Address_Size
=>
3439 Standard_Attribute
(System_Address_Size
);
3445 when Attribute_Adjacent
3446 | Attribute_Copy_Sign
3447 | Attribute_Remainder
3449 Check_Floating_Point_Type_2
;
3450 Set_Etype
(N
, P_Base_Type
);
3451 Resolve
(E1
, P_Base_Type
);
3452 Resolve
(E2
, P_Base_Type
);
3458 when Attribute_Aft
=>
3459 Check_Fixed_Point_Type_0
;
3460 Set_Etype
(N
, Universal_Integer
);
3466 when Attribute_Alignment
=>
3468 -- Don't we need more checking here, cf Size ???
3471 Check_Not_Incomplete_Type
;
3473 Set_Etype
(N
, Universal_Integer
);
3479 when Attribute_Asm_Input
=>
3480 Check_Asm_Attribute
;
3482 -- The back end may need to take the address of E2
3484 if Is_Entity_Name
(E2
) then
3485 Set_Address_Taken
(Entity
(E2
));
3488 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3494 when Attribute_Asm_Output
=>
3495 Check_Asm_Attribute
;
3497 if Etype
(E2
) = Any_Type
then
3500 elsif Aname
= Name_Asm_Output
then
3501 if not Is_Variable
(E2
) then
3503 ("second argument for Asm_Output is not variable", E2
);
3507 Note_Possible_Modification
(E2
, Sure
=> True);
3509 -- The back end may need to take the address of E2
3511 if Is_Entity_Name
(E2
) then
3512 Set_Address_Taken
(Entity
(E2
));
3515 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3517 -----------------------------
3518 -- Atomic_Always_Lock_Free --
3519 -----------------------------
3521 when Attribute_Atomic_Always_Lock_Free
=>
3524 Set_Etype
(N
, Standard_Boolean
);
3530 -- Note: when the base attribute appears in the context of a subtype
3531 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3532 -- the following circuit.
3534 when Attribute_Base
=> Base
: declare
3542 if Ada_Version
>= Ada_95
3543 and then not Is_Scalar_Type
(Typ
)
3544 and then not Is_Generic_Type
(Typ
)
3546 Error_Attr_P
("prefix of Base attribute must be scalar type");
3548 elsif Sloc
(Typ
) = Standard_Location
3549 and then Base_Type
(Typ
) = Typ
3550 and then Warn_On_Redundant_Constructs
3552 Error_Msg_NE
-- CODEFIX
3553 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3556 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3557 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3558 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3566 when Attribute_Bit
=>
3569 if not Is_Object_Reference
(P
) then
3570 Error_Attr_P
("prefix of % attribute must be object");
3572 -- What about the access object cases ???
3578 Set_Etype
(N
, Universal_Integer
);
3584 when Attribute_Bit_Order
=>
3588 if not Is_Record_Type
(P_Type
) then
3589 Error_Attr_P
("prefix of % attribute must be record type");
3592 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3594 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3597 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3602 -- Reset incorrect indication of staticness
3604 Set_Is_Static_Expression
(N
, False);
3610 -- Note: in generated code, we can have a Bit_Position attribute
3611 -- applied to a (naked) record component (i.e. the prefix is an
3612 -- identifier that references an E_Component or E_Discriminant
3613 -- entity directly, and this is interpreted as expected by Gigi.
3614 -- The following code will not tolerate such usage, but when the
3615 -- expander creates this special case, it marks it as analyzed
3616 -- immediately and sets an appropriate type.
3618 when Attribute_Bit_Position
=>
3619 if Comes_From_Source
(N
) then
3623 Set_Etype
(N
, Universal_Integer
);
3629 when Attribute_Body_Version
=>
3632 Set_Etype
(N
, RTE
(RE_Version_String
));
3638 when Attribute_Callable
3639 | Attribute_Terminated
3642 Set_Etype
(N
, Standard_Boolean
);
3649 when Attribute_Caller
=> Caller
: declare
3656 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3659 if not Is_Entry
(Ent
) then
3660 Error_Attr
("invalid entry name", N
);
3664 Error_Attr
("invalid entry name", N
);
3667 for J
in reverse 0 .. Scope_Stack
.Last
loop
3668 S
:= Scope_Stack
.Table
(J
).Entity
;
3670 if S
= Scope
(Ent
) then
3671 Error_Attr
("Caller must appear in matching accept or body", N
);
3677 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3684 when Attribute_Ceiling
3686 | Attribute_Fraction
3688 | Attribute_Machine_Rounding
3690 | Attribute_Rounding
3691 | Attribute_Truncation
3692 | Attribute_Unbiased_Rounding
3694 Check_Floating_Point_Type_1
;
3695 Set_Etype
(N
, P_Base_Type
);
3696 Resolve
(E1
, P_Base_Type
);
3702 when Attribute_Class
=>
3703 Check_Restriction
(No_Dispatch
, N
);
3707 -- Applying Class to untagged incomplete type is obsolescent in Ada
3708 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3709 -- this flag gets set by Find_Type in this situation.
3711 if Restriction_Check_Required
(No_Obsolescent_Features
)
3712 and then Ada_Version
>= Ada_2005
3713 and then Ekind
(P_Type
) = E_Incomplete_Type
3716 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3718 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3719 and then not Tagged_Present
(DN
)
3721 Check_Restriction
(No_Obsolescent_Features
, P
);
3730 when Attribute_Code_Address
=>
3733 if Nkind
(P
) = N_Attribute_Reference
3734 and then Attribute_Name
(P
) in Name_Elab_Body | Name_Elab_Spec
3738 elsif not Is_Entity_Name
(P
)
3739 or else (Ekind
(Entity
(P
)) /= E_Function
3741 Ekind
(Entity
(P
)) /= E_Procedure
)
3743 Error_Attr
("invalid prefix for % attribute", P
);
3745 -- Issue an error if the prefix denotes an eliminated subprogram
3748 Set_Address_Taken
(Entity
(P
));
3749 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3752 Set_Etype
(N
, RTE
(RE_Address
));
3754 ----------------------
3755 -- Compiler_Version --
3756 ----------------------
3758 when Attribute_Compiler_Version
=>
3760 Check_Standard_Prefix
;
3761 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3762 Analyze_And_Resolve
(N
, Standard_String
);
3763 Set_Is_Static_Expression
(N
, True);
3765 --------------------
3766 -- Component_Size --
3767 --------------------
3769 when Attribute_Component_Size
=>
3771 Set_Etype
(N
, Universal_Integer
);
3773 -- Note: unlike other array attributes, unconstrained arrays are OK
3775 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3785 when Attribute_Compose
3786 | Attribute_Leading_Part
3789 Check_Floating_Point_Type_2
;
3790 Set_Etype
(N
, P_Base_Type
);
3791 Resolve
(E1
, P_Base_Type
);
3792 Resolve
(E2
, Any_Integer
);
3798 when Attribute_Constrained
=>
3800 Set_Etype
(N
, Standard_Boolean
);
3802 -- Case from RM J.4(2) of constrained applied to private type
3804 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3805 Check_Restriction
(No_Obsolescent_Features
, P
);
3807 if Warn_On_Obsolescent_Feature
then
3809 ("constrained for private type is an obsolescent feature "
3810 & "(RM J.4)?j?", N
);
3813 -- If we are within an instance, the attribute must be legal
3814 -- because it was valid in the generic unit. Ditto if this is
3815 -- an inlining of a function declared in an instance.
3817 if In_Instance
or else In_Inlined_Body
then
3820 -- For sure OK if we have a real private type itself, but must
3821 -- be completed, cannot apply Constrained to incomplete type.
3823 elsif Is_Private_Type
(Entity
(P
)) then
3825 -- Note: this is one of the Annex J features that does not
3826 -- generate a warning from -gnatwj, since in fact it seems
3827 -- very useful, and is used in the GNAT runtime.
3829 Check_Not_Incomplete_Type
;
3833 -- Normal (non-obsolescent case) of application to object or value of
3834 -- a discriminated type.
3837 -- AI12-0068: In a type or subtype aspect, a prefix denoting the
3838 -- current instance of the (sub)type is defined to be a value,
3839 -- not an object, so the Constrained attribute is always True
3840 -- (see RM 8.6(18/5) and RM 3.7.2(3/5)). We issue a warning about
3841 -- this unintuitive result, to help avoid confusion.
3843 if Is_Current_Instance_Reference_In_Type_Aspect
(P
) then
3844 Error_Msg_Name_1
:= Aname
;
3846 ("current instance attribute % in subtype aspect always " &
3850 Check_Object_Reference
(P
);
3853 -- If N does not come from source, then we allow the
3854 -- the attribute prefix to be of a private type whose
3855 -- full type has discriminants. This occurs in cases
3856 -- involving expanded calls to stream attributes.
3858 if not Comes_From_Source
(N
) then
3859 P_Type
:= Underlying_Type
(P_Type
);
3862 -- Must have discriminants or be an access type designating a type
3863 -- with discriminants. If it is a class-wide type it has unknown
3866 if Has_Discriminants
(P_Type
)
3867 or else Has_Unknown_Discriminants
(P_Type
)
3869 (Is_Access_Type
(P_Type
)
3870 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3874 -- The rule given in 3.7.2 is part of static semantics, but the
3875 -- intent is clearly that it be treated as a legality rule, and
3876 -- rechecked in the visible part of an instance. Nevertheless
3877 -- the intent also seems to be it should legally apply to the
3878 -- actual of a formal with unknown discriminants, regardless of
3879 -- whether the actual has discriminants, in which case the value
3880 -- of the attribute is determined using the J.4 rules. This choice
3881 -- seems the most useful, and is compatible with existing tests.
3883 elsif In_Instance
then
3886 -- Also allow an object of a generic type if extensions allowed
3887 -- and allow this for any type at all.
3889 elsif (Is_Generic_Type
(P_Type
)
3890 or else Is_Generic_Actual_Type
(P_Type
))
3891 and then All_Extensions_Allowed
3897 -- Fall through if bad prefix
3900 ("prefix of % attribute must be object of discriminated type");
3906 -- Shares processing with Adjacent attribute
3912 when Attribute_Count
=> Count
: declare
3920 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
3923 if Ekind
(Ent
) /= E_Entry
then
3924 Error_Attr
("invalid entry name", N
);
3927 elsif Nkind
(P
) = N_Indexed_Component
then
3928 if not Is_Entity_Name
(Prefix
(P
))
3929 or else No
(Entity
(Prefix
(P
)))
3930 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3932 if Nkind
(Prefix
(P
)) = N_Selected_Component
3933 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3934 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3938 ("attribute % must apply to entry of current task", P
);
3941 Error_Attr
("invalid entry family name", P
);
3945 Ent
:= Entity
(Prefix
(P
));
3948 elsif Nkind
(P
) = N_Selected_Component
3949 and then Present
(Entity
(Selector_Name
(P
)))
3950 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3953 ("attribute % must apply to entry of current task", P
);
3956 Error_Attr
("invalid entry name", N
);
3959 for J
in reverse 0 .. Scope_Stack
.Last
loop
3960 S
:= Scope_Stack
.Table
(J
).Entity
;
3962 if S
= Scope
(Ent
) then
3963 if Nkind
(P
) = N_Expanded_Name
then
3964 Tsk
:= Entity
(Prefix
(P
));
3966 -- The prefix denotes either the task type, or else a
3967 -- single task whose task type is being analyzed.
3969 if (Is_Type
(Tsk
) and then Tsk
= S
)
3970 or else (not Is_Type
(Tsk
)
3971 and then Etype
(Tsk
) = S
3972 and then not (Comes_From_Source
(S
)))
3977 ("attribute % must apply to entry of current task", N
);
3983 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3984 and then Ekind
(S
) not in E_Block
3989 Error_Attr
("attribute % cannot appear in inner unit", N
);
3991 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3992 and then not Has_Completion
(Scope
(Ent
))
3994 Error_Attr
("attribute % can only be used inside body", N
);
3998 if Is_Overloaded
(P
) then
4000 Index
: Interp_Index
;
4004 Get_First_Interp
(P
, Index
, It
);
4005 while Present
(It
.Nam
) loop
4006 if It
.Nam
= Ent
then
4009 -- Ada 2005 (AI-345): Do not consider primitive entry
4010 -- wrappers generated for task or protected types.
4012 elsif Ada_Version
>= Ada_2005
4013 and then not Comes_From_Source
(It
.Nam
)
4018 Error_Attr
("ambiguous entry name", N
);
4021 Get_Next_Interp
(Index
, It
);
4026 Set_Etype
(N
, Universal_Integer
);
4029 -----------------------
4030 -- Default_Bit_Order --
4031 -----------------------
4033 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
4034 Target_Default_Bit_Order
: System
.Bit_Order
;
4037 Check_Standard_Prefix
;
4039 if Bytes_Big_Endian
then
4040 Target_Default_Bit_Order
:= System
.High_Order_First
;
4042 Target_Default_Bit_Order
:= System
.Low_Order_First
;
4046 Make_Integer_Literal
(Loc
,
4047 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
4049 Set_Etype
(N
, Universal_Integer
);
4050 Set_Is_Static_Expression
(N
);
4051 end Default_Bit_Order
;
4053 ----------------------------------
4054 -- Default_Scalar_Storage_Order --
4055 ----------------------------------
4057 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
4058 RE_Default_SSO
: RE_Id
;
4061 Check_Standard_Prefix
;
4063 case Opt
.Default_SSO
is
4065 if Bytes_Big_Endian
then
4066 RE_Default_SSO
:= RE_High_Order_First
;
4068 RE_Default_SSO
:= RE_Low_Order_First
;
4072 RE_Default_SSO
:= RE_High_Order_First
;
4075 RE_Default_SSO
:= RE_Low_Order_First
;
4078 raise Program_Error
;
4081 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
4088 when Attribute_Definite
=>
4089 Legal_Formal_Attribute
;
4095 when Attribute_Delta
=>
4096 Check_Fixed_Point_Type_0
;
4097 Set_Etype
(N
, Universal_Real
);
4103 when Attribute_Denorm
4104 | Attribute_Signed_Zeros
4106 Check_Floating_Point_Type_0
;
4107 Set_Etype
(N
, Standard_Boolean
);
4113 when Attribute_Deref
=>
4116 Resolve
(E1
, RTE
(RE_Address
));
4117 Set_Etype
(N
, P_Type
);
4119 ---------------------
4120 -- Descriptor_Size --
4121 ---------------------
4123 when Attribute_Descriptor_Size
=>
4126 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
4127 Error_Attr_P
("prefix of attribute % must denote a type");
4130 Set_Etype
(N
, Universal_Integer
);
4136 when Attribute_Digits
=>
4140 if not Is_Floating_Point_Type
(P_Type
)
4141 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
4144 ("prefix of % attribute must be float or decimal type");
4147 Set_Etype
(N
, Universal_Integer
);
4153 -- Also handles processing for Elab_Spec and Elab_Subp_Body
4155 when Attribute_Elab_Body
4156 | Attribute_Elab_Spec
4157 | Attribute_Elab_Subp_Body
4160 Check_Unit_Name
(P
);
4161 Set_Etype
(N
, Standard_Void_Type
);
4163 -- We have to manually call the expander in this case to get
4164 -- the necessary expansion (normally attributes that return
4165 -- entities are not expanded).
4173 -- Shares processing with Elab_Body attribute
4179 when Attribute_Elaborated
=>
4181 Check_Unit_Name
(P
);
4182 Set_Etype
(N
, Standard_Boolean
);
4189 | Attribute_Machine_Emax
4190 | Attribute_Machine_Emin
4191 | Attribute_Machine_Mantissa
4192 | Attribute_Model_Emin
4193 | Attribute_Model_Mantissa
4194 | Attribute_Safe_Emax
4196 Check_Floating_Point_Type_0
;
4197 Set_Etype
(N
, Universal_Integer
);
4203 when Attribute_Enabled
=>
4204 Check_Either_E0_Or_E1
;
4206 if Present
(E1
) then
4207 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
4208 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
4213 if Nkind
(P
) /= N_Identifier
then
4214 Error_Msg_N
("identifier expected (check name)", P
);
4215 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
4216 Error_Msg_N
("& is not a recognized check name", P
);
4219 Set_Etype
(N
, Standard_Boolean
);
4225 when Attribute_Enum_Rep
=>
4227 -- T'Enum_Rep (X) case
4229 if Present
(E1
) then
4231 Check_Discrete_Type
;
4232 Resolve
(E1
, P_Base_Type
);
4234 -- X'Enum_Rep case. X must be an object or enumeration literal
4235 -- (including an attribute reference), and it must be of a
4239 ((Is_Object_Reference
(P
)
4242 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
4243 or else Nkind
(P
) = N_Attribute_Reference
)
4244 and then Is_Discrete_Type
(Etype
(P
)))
4246 Error_Attr_P
("prefix of % attribute must be discrete object");
4249 Set_Etype
(N
, Universal_Integer
);
4255 when Attribute_Enum_Val
=>
4259 if not Is_Enumeration_Type
(P_Type
) then
4260 Error_Attr_P
("prefix of % attribute must be enumeration type");
4263 -- If the enumeration type has a standard representation, the effect
4264 -- is the same as 'Val, so rewrite the attribute as a 'Val.
4266 if not Has_Non_Standard_Rep
(P_Base_Type
) then
4268 Make_Attribute_Reference
(Loc
,
4269 Prefix
=> Relocate_Node
(Prefix
(N
)),
4270 Attribute_Name
=> Name_Val
,
4271 Expressions
=> New_List
(Relocate_Node
(E1
))));
4272 Analyze_And_Resolve
(N
, P_Base_Type
);
4274 -- Non-standard representation case (enumeration with holes)
4278 Resolve
(E1
, Any_Integer
);
4279 Set_Etype
(N
, P_Base_Type
);
4286 when Attribute_Epsilon
4287 | Attribute_Model_Epsilon
4288 | Attribute_Model_Small
4289 | Attribute_Safe_First
4290 | Attribute_Safe_Last
4292 Check_Floating_Point_Type_0
;
4293 Set_Etype
(N
, Universal_Real
);
4299 when Attribute_Exponent
=>
4300 Check_Floating_Point_Type_1
;
4301 Set_Etype
(N
, Universal_Integer
);
4302 Resolve
(E1
, P_Base_Type
);
4308 when Attribute_External_Tag
=>
4312 Set_Etype
(N
, Standard_String
);
4314 if not Is_Tagged_Type
(P_Type
) then
4315 Error_Attr_P
("prefix of % attribute must be tagged");
4322 when Attribute_Fast_Math
=>
4323 Check_Standard_Prefix
;
4324 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
4326 -----------------------
4327 -- Finalization_Size --
4328 -----------------------
4330 when Attribute_Finalization_Size
=>
4333 -- The prefix denotes an object
4335 if Is_Object_Reference
(P
) then
4336 Check_Object_Reference
(P
);
4338 -- The prefix denotes a type
4340 elsif Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
4342 Check_Not_Incomplete_Type
;
4344 -- Attribute 'Finalization_Size is not defined for class-wide
4345 -- types because it is not possible to know statically whether
4346 -- a definite type will have controlled components or not.
4348 if Is_Class_Wide_Type
(Etype
(P
)) then
4350 ("prefix of % attribute cannot denote a class-wide type");
4353 -- The prefix denotes an illegal construct
4357 ("prefix of % attribute must be a definite type or an object");
4360 Set_Etype
(N
, Universal_Integer
);
4366 when Attribute_First
4369 Check_Array_Or_Scalar_Type
;
4370 Bad_Attribute_For_Predicate
;
4376 when Attribute_First_Bit
4377 | Attribute_Last_Bit
4378 | Attribute_Position
4381 Set_Etype
(N
, Universal_Integer
);
4387 when Attribute_First_Valid
4388 | Attribute_Last_Valid
4390 Check_First_Last_Valid
;
4391 Set_Etype
(N
, P_Type
);
4397 when Attribute_Fixed_Value
=>
4398 Check_Fixed_Point_Type
;
4400 Resolve
(E1
, Any_Integer
);
4401 Set_Etype
(N
, P_Base_Type
);
4407 -- Shares processing with Ceiling attribute
4413 when Attribute_Fore
=>
4414 Check_Fixed_Point_Type_0
;
4415 Set_Etype
(N
, Universal_Integer
);
4421 -- Shares processing with Ceiling attribute
4427 when Attribute_From_Any
=>
4429 Check_PolyORB_Attribute
;
4430 Set_Etype
(N
, P_Base_Type
);
4432 -----------------------
4433 -- Has_Access_Values --
4434 -----------------------
4436 when Attribute_Has_Access_Values
4437 | Attribute_Has_Tagged_Values
4441 Set_Etype
(N
, Standard_Boolean
);
4443 ----------------------
4444 -- Has_Same_Storage --
4445 ----------------------
4447 when Attribute_Has_Same_Storage
4448 | Attribute_Overlaps_Storage
4452 -- The arguments must be objects of any type
4454 Analyze_And_Resolve
(P
);
4455 Analyze_And_Resolve
(E1
);
4456 Check_Object_Reference
(P
);
4457 Check_Object_Reference
(E1
);
4458 Set_Etype
(N
, Standard_Boolean
);
4464 when Attribute_Index
=> Index
: declare
4467 Spec_Id
: Entity_Id
;
4471 Analyze_Index_Attribute
(Legal
, Spec_Id
);
4473 if not Legal
or else No
(Spec_Id
) then
4474 Error_Attr
("attribute % must apply to entry family", P
);
4479 if Nkind
(P
) in N_Identifier | N_Expanded_Name
then
4482 if Ekind
(Ent
) /= E_Entry_Family
then
4484 ("attribute % must apply to entry family", P
);
4486 -- Analysis of pre/postconditions of an entry [family] occurs when
4487 -- the conditions are relocated to the contract wrapper procedure
4488 -- (see subprogram Build_Contract_Wrapper).
4490 elsif Contract_Wrapper
(Ent
) /= Spec_Id
then
4492 ("attribute % must apply to current entry family", P
);
4495 elsif Nkind
(P
) in N_Indexed_Component
4496 | N_Selected_Component
4499 ("attribute % must apply to current entry family", P
);
4502 Error_Attr
("invalid entry family name", N
);
4505 Set_Etype
(N
, Entry_Index_Type
(Ent
));
4508 -----------------------
4509 -- Has_Tagged_Values --
4510 -----------------------
4512 -- Shares processing with Has_Access_Values attribute
4514 -----------------------
4515 -- Has_Discriminants --
4516 -----------------------
4518 when Attribute_Has_Discriminants
=>
4519 Legal_Formal_Attribute
;
4525 when Attribute_Identity
=>
4528 if Etype
(P
) = Standard_Exception_Type
then
4529 Set_Etype
(N
, RTE
(RE_Exception_Id
));
4531 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
4532 -- interface class-wide types.
4534 elsif Is_Task_Type
(Etype
(P
))
4535 or else (Is_Access_Type
(Etype
(P
))
4536 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
4537 or else (Ada_Version
>= Ada_2005
4538 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
4539 and then Is_Interface
(Etype
(P
))
4540 and then Is_Task_Interface
(Etype
(P
)))
4543 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
4546 if Ada_Version
>= Ada_2005
then
4548 ("prefix of % attribute must be an exception, a task or a "
4549 & "task interface class-wide object");
4552 ("prefix of % attribute must be a task or an exception");
4560 when Attribute_Image
=>
4561 if Is_Real_Type
(P_Type
) then
4562 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4563 Error_Msg_Name_1
:= Aname
;
4565 ("(Ada 83) % attribute not allowed for real types", N
);
4569 Analyze_Image_Attribute
(Standard_String
);
4575 when Attribute_Img
=>
4576 Analyze_Image_Attribute
(Standard_String
);
4582 when Attribute_Initialized
=>
4585 if Comes_From_Source
(N
) then
4587 -- This attribute be prefixed with references to objects or
4588 -- values (such as a current instance value given within a type
4589 -- or subtype aspect).
4591 if not Is_Object_Reference
(P
)
4592 and then not Is_Current_Instance_Reference_In_Type_Aspect
(P
)
4594 Error_Attr_P
("prefix of % attribute must be object");
4598 Set_Etype
(N
, Standard_Boolean
);
4604 when Attribute_Input
=>
4606 Check_Stream_Attribute
(TSS_Stream_Input
);
4607 Set_Etype
(N
, P_Base_Type
);
4613 when Attribute_Integer_Value
=>
4616 Resolve
(E1
, Any_Fixed
);
4618 -- Signal an error if argument type is not a specific fixed-point
4619 -- subtype. An error has been signalled already if the argument
4620 -- was not of a fixed-point type.
4622 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4623 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4626 Set_Etype
(N
, P_Base_Type
);
4632 when Attribute_Invalid_Value
=>
4635 Set_Etype
(N
, P_Base_Type
);
4636 Invalid_Value_Used
:= True;
4642 when Attribute_Large
4644 | Attribute_Safe_Large
4645 | Attribute_Safe_Small
4649 Set_Etype
(N
, Universal_Real
);
4655 -- Shares processing with First attribute
4661 -- Shares processing with First_Bit attribute
4667 -- Shares processing with First_Valid attribute
4673 -- Shares processing with Compose attribute
4679 when Attribute_Length
=>
4681 Set_Etype
(N
, Universal_Integer
);
4687 when Attribute_Library_Level
=>
4690 if not Is_Entity_Name
(P
) then
4691 Error_Attr_P
("prefix of % attribute must be an entity name");
4694 if not Inside_A_Generic
then
4695 Set_Boolean_Result
(N
,
4696 Is_Library_Level_Entity
(Entity
(P
)));
4699 Set_Etype
(N
, Standard_Boolean
);
4705 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4706 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4707 -- Inspect the prefix for any uses of entities declared within the
4708 -- related loop. Loop_Id denotes the loop identifier.
4710 --------------------------------
4711 -- Check_References_In_Prefix --
4712 --------------------------------
4714 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4715 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4717 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4718 -- Determine whether a reference mentions an entity declared
4719 -- within the related loop.
4721 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4722 -- Determine whether Nod appears in the subtree of Loop_Decl but
4723 -- not within the subtree of the prefix P itself.
4725 ---------------------
4726 -- Check_Reference --
4727 ---------------------
4729 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4731 if Nkind
(Nod
) = N_Identifier
4732 and then Present
(Entity
(Nod
))
4733 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4736 ("prefix of attribute % cannot reference local entities",
4741 end Check_Reference
;
4743 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4745 ---------------------
4746 -- Declared_Within --
4747 ---------------------
4749 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4754 while Present
(Stmt
) loop
4755 if Stmt
= Loop_Decl
then
4761 -- Prevent the search from going too far
4763 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4767 Stmt
:= Parent
(Stmt
);
4771 end Declared_Within
;
4773 -- Start of processing for Check_Prefix_For_Local_References
4776 Check_References
(P
);
4777 end Check_References_In_Prefix
;
4781 Context
: constant Node_Id
:= Parent
(N
);
4783 Encl_Loop
: Node_Id
:= Empty
;
4784 Encl_Prag
: Node_Id
:= Empty
;
4785 Loop_Id
: Entity_Id
:= Empty
;
4789 -- Start of processing for Loop_Entry
4794 -- Set the type of the attribute now to ensure the successful
4795 -- continuation of analysis even if the attribute is misplaced.
4797 Set_Etype
(Attr
, P_Type
);
4799 -- Attribute 'Loop_Entry may appear in several flavors:
4801 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4802 -- nearest enclosing loop.
4804 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4805 -- attribute may be related to a loop denoted by label Expr or
4806 -- the prefix may denote an array object and Expr may act as an
4807 -- indexed component.
4809 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4810 -- to the nearest enclosing loop, all expressions are part of
4811 -- an indexed component.
4813 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4814 -- denotes, the attribute may be related to a loop denoted by
4815 -- label Expr or the prefix may denote a multidimensional array
4816 -- array object and Expr along with the rest of the expressions
4817 -- may act as indexed components.
4819 -- Regardless of variations, the attribute reference does not have an
4820 -- expression list. Instead, all available expressions are stored as
4821 -- indexed components.
4823 -- When the attribute is part of an indexed component, find the first
4824 -- expression as it will determine the semantics of 'Loop_Entry.
4826 -- If the attribute is itself an index in an indexed component, i.e.
4827 -- a member of a list, the context itself is not relevant (the code
4828 -- below would lead to an infinite loop) and the attribute applies
4829 -- to the enclosing loop.
4831 if Nkind
(Context
) = N_Indexed_Component
4832 and then not Is_List_Member
(N
)
4834 E1
:= First
(Expressions
(Context
));
4837 -- The attribute reference appears in the following form:
4839 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4841 -- In this case, the loop name is omitted and no rewriting is
4844 if Present
(E2
) then
4847 -- The form of the attribute is:
4849 -- Prefix'Loop_Entry (Expr) [(...)]
4851 -- If Expr denotes a loop entry, the whole attribute and indexed
4852 -- component will have to be rewritten to reflect this relation.
4855 pragma Assert
(Present
(E1
));
4857 -- Do not expand the expression as it may have side effects.
4858 -- Simply preanalyze to determine whether it is a loop name or
4861 Preanalyze_And_Resolve
(E1
);
4863 if Is_Entity_Name
(E1
)
4864 and then Present
(Entity
(E1
))
4865 and then Ekind
(Entity
(E1
)) = E_Loop
4867 Loop_Id
:= Entity
(E1
);
4869 -- Transform the attribute and enclosing indexed component
4871 Set_Expressions
(N
, Expressions
(Context
));
4872 Rewrite
(Context
, N
);
4873 Set_Etype
(Context
, P_Type
);
4880 -- The prefix must denote an object
4882 if not Is_Object_Reference
(P
) then
4883 Error_Attr_P
("prefix of attribute % must denote an object");
4886 -- The prefix cannot be of a limited type because the expansion of
4887 -- Loop_Entry must create a constant initialized by the evaluated
4890 if Is_Limited_View
(Etype
(P
)) then
4891 Error_Attr_P
("prefix of attribute % cannot be limited");
4894 -- Climb the parent chain to verify the location of the attribute and
4895 -- find the enclosing loop.
4898 while Present
(Stmt
) loop
4900 -- Locate the corresponding enclosing pragma. Note that in the
4901 -- case of Assert[And_Cut] and Assume, we have already checked
4902 -- that the pragma appears in an appropriate loop location.
4904 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4906 Pragma_Name_Unmapped
(Original_Node
(Stmt
))
4907 in Name_Loop_Invariant
4910 | Name_Assert_And_Cut
4913 Encl_Prag
:= Original_Node
(Stmt
);
4915 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4916 -- iteration may be expanded into several nested loops, we are
4917 -- interested in the outermost one which has the loop identifier,
4918 -- and comes from source.
4920 elsif Nkind
(Stmt
) = N_Loop_Statement
4921 and then Present
(Identifier
(Stmt
))
4922 and then Comes_From_Source
(Original_Node
(Stmt
))
4923 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
4927 -- The original attribute reference may lack a loop name. Use
4928 -- the name of the enclosing loop because it is the related
4931 if No
(Loop_Id
) then
4932 Loop_Id
:= Entity
(Identifier
(Encl_Loop
));
4937 -- Prevent the search from going too far
4939 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4943 Stmt
:= Parent
(Stmt
);
4946 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4947 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4948 -- purpose if they appear in an appropriate location in a loop,
4949 -- which was already checked by the top level pragma circuit).
4951 -- Loop_Entry also denotes a value and as such can appear within an
4952 -- expression that is an argument for another loop aspect. In that
4953 -- case it will have been expanded into the corresponding assignment.
4956 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
4957 and then not Comes_From_Source
(Parent
(N
))
4961 elsif No
(Encl_Prag
) then
4962 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4965 -- A Loop_Entry that applies to a given loop statement must not
4966 -- appear within a body of accept statement, if this construct is
4967 -- itself enclosed by the given loop statement.
4969 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4970 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4972 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4974 elsif Ekind
(Scop
) in E_Block | E_Loop | E_Return_Statement
then
4978 ("attribute % cannot appear in body or accept statement", N
);
4982 -- The prefix cannot mention entities declared within the related
4983 -- loop because they will not be visible once the prefix is moved
4984 -- outside the loop.
4986 Check_References_In_Prefix
(Loop_Id
);
4988 -- The prefix must statically name an object if the pragma does not
4989 -- apply to the innermost enclosing loop statement, or if it appears
4990 -- within a potentially unevaluated expression.
4992 if Is_Entity_Name
(P
)
4993 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4994 or else Statically_Names_Object
(P
)
4998 elsif Present
(Encl_Loop
)
4999 and then Entity
(Identifier
(Encl_Loop
)) /= Loop_Id
5002 ("prefix of attribute % that applies to outer loop must denote "
5005 elsif Is_Potentially_Unevaluated
(P
) then
5009 -- Replace the Loop_Entry attribute reference by its prefix if the
5010 -- related pragma is ignored. This transformation is OK with respect
5011 -- to typing because Loop_Entry's type is that of its prefix. This
5012 -- early transformation also avoids the generation of a useless loop
5015 if Present
(Encl_Prag
) and then Is_Ignored
(Encl_Prag
) then
5016 Rewrite
(N
, Relocate_Node
(P
));
5017 Preanalyze_And_Resolve
(N
);
5020 Preanalyze_And_Resolve
(P
);
5028 -- Shares processing with Ceiling attribute
5034 -- Shares processing with Emax attribute
5040 -- Shares processing with Emax attribute
5042 ----------------------
5043 -- Machine_Mantissa --
5044 ----------------------
5046 -- Shares processing with Emax attribute
5048 -----------------------
5049 -- Machine_Overflows --
5050 -----------------------
5052 when Attribute_Machine_Overflows
5053 | Attribute_Machine_Rounds
5057 Set_Etype
(N
, Standard_Boolean
);
5063 when Attribute_Machine_Radix
5064 | Attribute_Mantissa
5068 Set_Etype
(N
, Universal_Integer
);
5070 ----------------------
5071 -- Machine_Rounding --
5072 ----------------------
5074 -- Shares processing with Ceiling attribute
5076 --------------------
5077 -- Machine_Rounds --
5078 --------------------
5080 -- Shares processing with Machine_Overflows attribute
5086 when Attribute_Machine_Size
5087 | Attribute_Object_Size
5088 | Attribute_Value_Size
5092 Check_Not_Incomplete_Type
;
5093 Set_Etype
(N
, Universal_Integer
);
5099 -- Shares processing with Machine_Radix attribute
5105 when Attribute_Max
=>
5108 ----------------------------------
5109 -- Max_Alignment_For_Allocation --
5110 ----------------------------------
5112 when Attribute_Max_Size_In_Storage_Elements
=>
5113 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5115 ----------------------
5116 -- Max_Integer_Size --
5117 ----------------------
5119 when Attribute_Max_Integer_Size
=>
5120 Standard_Attribute
(System_Max_Integer_Size
);
5122 ----------------------------------
5123 -- Max_Size_In_Storage_Elements --
5124 ----------------------------------
5126 when Attribute_Max_Alignment_For_Allocation
=>
5127 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
5129 -----------------------
5130 -- Maximum_Alignment --
5131 -----------------------
5133 when Attribute_Maximum_Alignment
=>
5134 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
5136 --------------------
5137 -- Mechanism_Code --
5138 --------------------
5140 when Attribute_Mechanism_Code
=>
5141 if not Is_Entity_Name
(P
)
5142 or else not Is_Subprogram
(Entity
(P
))
5144 Error_Attr_P
("prefix of % attribute must be subprogram");
5147 Check_Either_E0_Or_E1
;
5149 if Present
(E1
) then
5150 Resolve
(E1
, Any_Integer
);
5151 Set_Etype
(E1
, Standard_Integer
);
5153 if not Is_OK_Static_Expression
(E1
) then
5154 Flag_Non_Static_Expr
5155 ("expression for parameter number must be static!", E1
);
5158 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
5159 or else Intval
(E1
) < 0
5161 Error_Attr
("invalid parameter number for % attribute", E1
);
5165 Set_Etype
(N
, Universal_Integer
);
5171 when Attribute_Min
=>
5178 when Attribute_Mod
=>
5180 -- Note: this attribute is only allowed in Ada 2005 mode, but
5181 -- we do not need to test that here, since Mod is only recognized
5182 -- as an attribute name in Ada 2005 mode during the parse.
5185 Check_Modular_Integer_Type
;
5186 Resolve
(E1
, Any_Integer
);
5187 Set_Etype
(N
, P_Base_Type
);
5193 -- Shares processing with Ceiling attribute
5199 -- Shares processing with Emax attribute
5205 -- Shares processing with Epsilon attribute
5207 --------------------
5208 -- Model_Mantissa --
5209 --------------------
5211 -- Shares processing with Emax attribute
5217 -- Shares processing with Epsilon attribute
5223 when Attribute_Modulus
=>
5225 Check_Modular_Integer_Type
;
5226 Set_Etype
(N
, Universal_Integer
);
5228 --------------------
5229 -- Null_Parameter --
5230 --------------------
5232 when Attribute_Null_Parameter
=> Null_Parameter
: declare
5233 Parnt
: constant Node_Id
:= Parent
(N
);
5234 GParnt
: constant Node_Id
:= Parent
(Parnt
);
5236 procedure Bad_Null_Parameter
(Msg
: String);
5237 -- Used if bad Null parameter attribute node is found. Issues
5238 -- given error message, and also sets the type to Any_Type to
5239 -- avoid blowups later on from dealing with a junk node.
5241 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
5242 -- Called to check that Proc_Ent is imported subprogram
5244 ------------------------
5245 -- Bad_Null_Parameter --
5246 ------------------------
5248 procedure Bad_Null_Parameter
(Msg
: String) is
5250 Error_Msg_N
(Msg
, N
);
5251 Set_Etype
(N
, Any_Type
);
5252 end Bad_Null_Parameter
;
5254 ----------------------
5255 -- Must_Be_Imported --
5256 ----------------------
5258 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
5259 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
5262 -- Ignore check if procedure not frozen yet (we will get
5263 -- another chance when the default parameter is reanalyzed)
5265 if not Is_Frozen
(Pent
) then
5268 elsif not Is_Imported
(Pent
) then
5270 ("Null_Parameter can only be used with imported subprogram");
5275 end Must_Be_Imported
;
5277 -- Start of processing for Null_Parameter
5282 Set_Etype
(N
, P_Type
);
5284 -- Case of attribute used as default expression
5286 if Nkind
(Parnt
) = N_Parameter_Specification
then
5287 Must_Be_Imported
(Defining_Entity
(GParnt
));
5289 -- Case of attribute used as actual for subprogram (positional)
5291 elsif Nkind
(Parnt
) in N_Subprogram_Call
5292 and then Is_Entity_Name
(Name
(Parnt
))
5294 Must_Be_Imported
(Entity
(Name
(Parnt
)));
5296 -- Case of attribute used as actual for subprogram (named)
5298 elsif Nkind
(Parnt
) = N_Parameter_Association
5299 and then Nkind
(GParnt
) in N_Subprogram_Call
5300 and then Is_Entity_Name
(Name
(GParnt
))
5302 Must_Be_Imported
(Entity
(Name
(GParnt
)));
5304 -- Not an allowed case
5308 ("Null_Parameter must be actual or default parameter");
5316 -- Shares processing with Machine_Size attribute
5322 when Attribute_Old
=> Old
: declare
5323 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
5324 -- Inspect the contents of the prefix and detect illegal uses of a
5325 -- nested 'Old, attribute 'Result or a use of an entity declared in
5326 -- the related postcondition expression. Subp_Id is the subprogram to
5327 -- which the related postcondition applies.
5329 --------------------------------
5330 -- Check_References_In_Prefix --
5331 --------------------------------
5333 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
5334 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
5335 -- Detect attribute 'Old, attribute 'Result of a use of an entity
5336 -- and perform the appropriate semantic check.
5338 ---------------------
5339 -- Check_Reference --
5340 ---------------------
5342 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
5344 -- Attributes 'Old and 'Result cannot appear in the prefix of
5345 -- another attribute 'Old.
5347 if Nkind
(Nod
) = N_Attribute_Reference
5348 and then Attribute_Name
(Nod
) in Name_Old | Name_Result
5350 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
5351 Error_Msg_Name_2
:= Name_Old
;
5353 ("attribute % cannot appear in the prefix of attribute %",
5357 -- Entities mentioned within the prefix of attribute 'Old must
5358 -- be global to the related postcondition. If this is not the
5359 -- case, then the scope of the local entity is nested within
5360 -- that of the subprogram. Moreover, we need to know whether
5361 -- Entity (Nod) occurs in the tree rooted at the prefix to
5362 -- ensure the entity is not declared within then prefix itself.
5364 elsif Is_Entity_Name
(Nod
)
5365 and then Present
(Entity
(Nod
))
5366 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
5367 and then not In_Subtree
(Entity
(Nod
), P
)
5370 ("prefix of attribute % cannot reference local entities",
5373 -- Otherwise keep inspecting the prefix
5378 end Check_Reference
;
5380 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
5382 -- Start of processing for Check_References_In_Prefix
5385 Check_References
(P
);
5386 end Check_References_In_Prefix
;
5391 Pref_Id
: Entity_Id
;
5392 Pref_Typ
: Entity_Id
;
5393 Spec_Id
: Entity_Id
;
5395 -- Start of processing for Old
5398 -- The attribute reference is a primary. If any expressions follow,
5399 -- then the attribute reference is an indexable object. Transform the
5400 -- attribute into an indexed component and analyze it.
5402 if Present
(E1
) then
5404 Make_Indexed_Component
(Loc
,
5406 Make_Attribute_Reference
(Loc
,
5407 Prefix
=> Relocate_Node
(P
),
5408 Attribute_Name
=> Name_Old
),
5409 Expressions
=> Expressions
(N
)));
5414 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5416 -- The aspect or pragma where attribute 'Old resides should be
5417 -- associated with a subprogram declaration or a body. If this is not
5418 -- the case, then the aspect or pragma is illegal. Return as analysis
5419 -- cannot be carried out.
5421 -- The exception to this rule is when generating C since in this case
5422 -- postconditions are inlined.
5425 and then Modify_Tree_For_C
5426 and then In_Inlined_Body
5428 Spec_Id
:= Entity
(P
);
5430 elsif not Legal
then
5434 -- The prefix must be preanalyzed as the full analysis will take
5435 -- place during expansion.
5437 Preanalyze_And_Resolve
(P
);
5439 -- Ensure that the prefix does not contain attributes 'Old or 'Result
5441 Check_References_In_Prefix
(Spec_Id
);
5443 -- Set the type of the attribute now to prevent cascaded errors
5445 Pref_Typ
:= Etype
(P
);
5446 Set_Etype
(N
, Pref_Typ
);
5450 if Is_Limited_Type
(Pref_Typ
) then
5451 Error_Attr
("attribute % cannot apply to limited objects", P
);
5454 -- The prefix is a simple name
5456 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
5457 Pref_Id
:= Entity
(P
);
5459 -- Emit a warning when the prefix is a constant. Note that the use
5460 -- of Error_Attr would reset the type of N to Any_Type even though
5461 -- this is a warning. Use Error_Msg_XXX instead.
5463 if Is_Constant_Object
(Pref_Id
) then
5464 Error_Msg_Name_1
:= Name_Old
;
5466 ("??attribute % applied to constant has no effect", P
);
5469 -- Otherwise the prefix is not a simple name
5472 -- Ensure that the prefix of attribute 'Old is an entity when it
5473 -- is potentially unevaluated (6.1.1 (27/3)). This rule is
5474 -- relaxed in Ada 2022 - this relaxation is reflected in the
5475 -- call (below) to Eligible_For_Conditional_Evaluation.
5477 if Is_Potentially_Unevaluated
(N
)
5478 and then not Statically_Names_Object
(P
)
5480 Old_Attr_Util
.Conditional_Evaluation
5481 .Eligible_For_Conditional_Evaluation
(N
)
5485 -- Detect a possible infinite recursion when the prefix denotes
5486 -- the related function.
5488 -- function Func (...) return ...
5489 -- with Post => Func'Old ...;
5491 -- The function may be specified in qualified form X.Y where X is
5492 -- a protected object and Y is a protected function. In that case
5493 -- ensure that the qualified form has an entity.
5495 elsif Nkind
(P
) = N_Function_Call
5496 and then Nkind
(Name
(P
)) in N_Has_Entity
5498 Pref_Id
:= Entity
(Name
(P
));
5500 if Ekind
(Spec_Id
) in E_Function | E_Generic_Function
5501 and then Pref_Id
= Spec_Id
5503 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5504 Error_Msg_N
("!possible infinite recursion<<", P
);
5505 Error_Msg_N
("\!??Storage_Error ]<<", P
);
5509 -- The prefix of attribute 'Old may refer to a component of a
5510 -- formal parameter. In this case its expansion may generate
5511 -- actual subtypes that are referenced in an inner context and
5512 -- that must be elaborated within the subprogram itself. If the
5513 -- prefix includes a function call, it may involve finalization
5514 -- actions that should be inserted when the attribute has been
5515 -- rewritten as a declaration. Create a declaration for the prefix
5516 -- and insert it at the start of the enclosing subprogram. This is
5517 -- an expansion activity that has to be performed now to prevent
5518 -- out-of-order issues.
5520 -- This expansion is both harmful and not needed in SPARK mode,
5521 -- since the formal verification back end relies on the types of
5522 -- nodes (hence is not robust w.r.t. a change to base type here),
5523 -- and does not suffer from the out-of-order issue described
5524 -- above. Thus, this expansion is skipped in SPARK mode.
5526 -- The expansion is not relevant for discrete types, which will
5527 -- not generate extra declarations, and where use of the base type
5528 -- may lead to spurious errors if context is a case.
5530 if not GNATprove_Mode
then
5531 if not Is_Discrete_Type
(Pref_Typ
) then
5532 Pref_Typ
:= Base_Type
(Pref_Typ
);
5535 Set_Etype
(N
, Pref_Typ
);
5536 Set_Etype
(P
, Pref_Typ
);
5538 Analyze_Dimension
(N
);
5548 when Attribute_Output
=>
5550 Check_Stream_Attribute
(TSS_Stream_Output
);
5551 Set_Etype
(N
, Standard_Void_Type
);
5552 Resolve
(N
, Standard_Void_Type
);
5558 when Attribute_Partition_ID
=>
5561 if P_Type
/= Any_Type
then
5562 if not Is_Library_Level_Entity
(Entity
(P
)) then
5564 ("prefix of % attribute must be library-level entity");
5566 -- The defining entity of prefix should not be declared inside a
5567 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5569 elsif Is_Entity_Name
(P
)
5570 and then Is_Pure
(Entity
(P
))
5572 Error_Attr_P
("prefix of% attribute must not be declared pure");
5576 Set_Etype
(N
, Universal_Integer
);
5578 -------------------------
5579 -- Passed_By_Reference --
5580 -------------------------
5582 when Attribute_Passed_By_Reference
=>
5585 Check_Not_Incomplete_Type
;
5586 Set_Etype
(N
, Standard_Boolean
);
5592 when Attribute_Pool_Address
=>
5594 Set_Etype
(N
, RTE
(RE_Address
));
5600 when Attribute_Pos
=>
5601 Check_Discrete_Type
;
5603 Resolve
(E1
, P_Base_Type
);
5604 Set_Etype
(N
, Universal_Integer
);
5610 -- Shares processing with First_Bit attribute
5621 Resolve
(E1
, P_Base_Type
);
5622 Set_Etype
(N
, P_Base_Type
);
5624 -- Since Pred/Succ work on the base type, we normally do no check for
5625 -- the floating-point case, since the base type is unconstrained. But
5626 -- we make an exception in Check_Float_Overflow mode.
5628 if Is_Floating_Point_Type
(P_Type
) then
5629 if not Range_Checks_Suppressed
(P_Base_Type
) then
5630 Set_Do_Range_Check
(E1
);
5633 -- If not modular type, test for overflow check required
5636 if not Is_Modular_Integer_Type
(P_Type
)
5637 and then not Range_Checks_Suppressed
(P_Base_Type
)
5639 Enable_Range_Check
(E1
);
5643 ----------------------------------
5644 -- Preelaborable_Initialization --
5645 ----------------------------------
5647 when Attribute_Preelaborable_Initialization
=>
5651 -- If we're in an instance, we know that the legality of the
5652 -- attribute prefix type was already checked in the generic.
5654 if not In_Instance
then
5656 -- If the prefix type is a generic formal type, then it must be
5657 -- either a formal private type or a formal derived type.
5659 if Is_Generic_Type
(P_Type
) then
5660 if not Is_Private_Type
(P_Type
)
5661 and then not Is_Derived_Type
(P_Type
)
5663 Error_Attr_P
("formal type prefix of % attribute must be "
5664 & "formal private or formal derived type");
5667 -- Otherwise, the prefix type must be a nonformal composite
5668 -- type declared within the visible part of a package or
5671 elsif not Is_Composite_Type
(P_Type
)
5672 or else not Original_View_In_Visible_Part
(P_Type
)
5675 ("prefix of % attribute must be composite type declared "
5676 & "in visible part of a package or generic package");
5680 Set_Etype
(N
, Standard_Boolean
);
5686 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5688 when Attribute_Priority
=>
5689 if Ada_Version
< Ada_2005
then
5690 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5695 Check_Restriction
(No_Dynamic_Priorities
, N
);
5697 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5699 if Is_Protected_Type
(Etype
(P
))
5700 or else (Is_Access_Type
(Etype
(P
))
5701 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5705 Error_Attr_P
("prefix of % attribute must be a protected object");
5708 Set_Etype
(N
, Standard_Integer
);
5710 -- Must be called from within a protected procedure or entry of the
5711 -- protected object.
5718 while S
/= Etype
(P
)
5719 and then S
/= Standard_Standard
5724 if S
= Standard_Standard
then
5725 Error_Attr
("the attribute % is only allowed inside protected "
5730 Validate_Non_Static_Attribute_Function_Call
;
5736 when Attribute_Put_Image
=>
5738 Check_Put_Image_Attribute
;
5739 Set_Etype
(N
, Standard_Void_Type
);
5740 Resolve
(N
, Standard_Void_Type
);
5746 when Attribute_Range
=>
5747 Check_Array_Or_Scalar_Type
;
5748 Bad_Attribute_For_Predicate
;
5750 if Ada_Version
= Ada_83
5751 and then Is_Scalar_Type
(P_Type
)
5752 and then Comes_From_Source
(N
)
5755 ("(Ada 83) % attribute not allowed for scalar type", P
);
5762 when Attribute_Result
=> Result
: declare
5763 function Denote_Same_Function
5764 (Pref_Id
: Entity_Id
;
5765 Spec_Id
: Entity_Id
) return Boolean;
5766 -- Determine whether the entity of the prefix Pref_Id denotes the
5767 -- same entity as that of the related subprogram Spec_Id.
5769 --------------------------
5770 -- Denote_Same_Function --
5771 --------------------------
5773 function Denote_Same_Function
5774 (Pref_Id
: Entity_Id
;
5775 Spec_Id
: Entity_Id
) return Boolean
5777 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5778 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5781 -- The prefix denotes the related subprogram
5783 if Pref_Id
= Spec_Id
then
5786 -- Account for a special case when attribute 'Result appears in
5787 -- the postcondition of a generic function.
5790 -- function Gen_Func return ...
5791 -- with Post => Gen_Func'Result ...;
5793 -- When the generic function is instantiated, the Chars field of
5794 -- the instantiated prefix still denotes the name of the generic
5795 -- function. Note that any preemptive transformation is impossible
5796 -- without a proper analysis. The structure of the wrapper package
5799 -- package Anon_Gen_Pack is
5800 -- <subtypes and renamings>
5801 -- function Subp_Decl return ...; -- (!)
5802 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5803 -- function Gen_Func ... renames Subp_Decl;
5804 -- end Anon_Gen_Pack;
5806 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5807 and then Present
(Generic_Parent
(Subp_Spec
))
5808 and then Ekind
(Pref_Id
) in E_Generic_Function | E_Function
5810 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5813 elsif Present
(Alias
(Pref_Id
))
5814 and then Alias
(Pref_Id
) = Spec_Id
5819 -- Account for a special case where a primitive of a tagged type
5820 -- inherits a class-wide postcondition from a parent type. In this
5821 -- case the prefix of attribute 'Result denotes the overriding
5824 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5827 -- When a qualified name is used for the prefix, homonyms may come
5828 -- before the current function in the homonym chain.
5830 elsif Has_Homonym
(Pref_Id
) then
5831 return Denote_Same_Function
(Homonym
(Pref_Id
), Spec_Id
);
5834 -- Otherwise the prefix does not denote the related subprogram
5837 end Denote_Same_Function
;
5841 In_Inlined_C_Postcondition
: constant Boolean :=
5843 and then In_Inlined_Body
;
5846 Pref_Id
: Entity_Id
;
5847 Spec_Id
: Entity_Id
;
5849 -- Start of processing for Result
5852 -- The attribute reference is a primary. If any expressions follow,
5853 -- then the attribute reference is an indexable object. Transform the
5854 -- attribute into an indexed component and analyze it.
5856 if Present
(E1
) then
5858 Make_Indexed_Component
(Loc
,
5860 Make_Attribute_Reference
(Loc
,
5861 Prefix
=> Relocate_Node
(P
),
5862 Attribute_Name
=> Name_Result
),
5863 Expressions
=> Expressions
(N
)));
5868 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5870 -- The aspect or pragma where attribute 'Result resides should be
5871 -- associated with a subprogram declaration or a body. If this is not
5872 -- the case, then the aspect or pragma is illegal. Return as analysis
5873 -- cannot be carried out.
5875 -- The exception to this rule is when generating C since in this case
5876 -- postconditions are inlined.
5878 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5879 Spec_Id
:= Entity
(P
);
5881 elsif not Legal
then
5882 Error_Attr
("prefix of % attribute must be a function", P
);
5885 -- Attribute 'Result is part of postconditions expansion. There is
5886 -- no need to perform the semantic checks below as they were already
5887 -- verified when the attribute was analyzed in its original context.
5888 -- Instead, rewrite the attribute as a reference to formal parameter
5889 -- _Result of the _Wrapped_Statements procedure.
5891 if Chars
(Spec_Id
) = Name_uWrapped_Statements
5893 (In_Inlined_C_Postcondition
5894 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5896 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5898 -- The type of formal parameter _Result is that of the function
5899 -- encapsulating the _Postconditions procedure. Resolution must
5900 -- be carried out against the function return type.
5902 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
5904 -- Otherwise attribute 'Result appears in its original context and
5905 -- all semantic checks should be carried out.
5908 -- Verify the legality of the prefix. It must denotes the entity
5909 -- of the related [generic] function.
5911 if Is_Entity_Name
(P
) then
5912 Pref_Id
:= Entity
(P
);
5914 -- Either both the prefix and the annotated spec must be
5915 -- generic functions, or they both must be nongeneric
5916 -- functions, or the prefix must be generic and the spec
5917 -- must be nongeneric (i.e. it must denote an instance).
5919 if (Ekind
(Pref_Id
) in E_Function | E_Generic_Function
5920 and then Ekind
(Pref_Id
) = Ekind
(Spec_Id
))
5922 (Ekind
(Pref_Id
) = E_Generic_Function
5923 and then Ekind
(Spec_Id
) = E_Function
)
5925 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
5927 -- Correct the prefix of the attribute when the context
5928 -- is a generic function.
5930 if Pref_Id
/= Spec_Id
then
5931 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
5935 Set_Etype
(N
, Etype
(Spec_Id
));
5937 -- Otherwise the prefix denotes some unrelated function
5940 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5942 ("incorrect prefix for attribute %, expected %", P
);
5945 -- Otherwise the prefix denotes some other form of subprogram
5950 ("attribute % can only appear in postcondition of "
5954 -- Otherwise the prefix is illegal
5957 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5958 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
5967 when Attribute_Range_Length
=>
5969 Check_Discrete_Type
;
5970 Set_Etype
(N
, Universal_Integer
);
5976 when Attribute_Reduce
=>
5978 Error_Msg_Ada_2022_Feature
("Reduce attribute", Sloc
(N
));
5981 Stream
: constant Node_Id
:= Prefix
(N
);
5984 if Nkind
(Stream
) /= N_Aggregate
then
5985 -- Prefix is a name, as for other attributes.
5987 -- If the object is a function we asume that it is not
5988 -- overloaded. AI12-242 does not suggest a name resolution
5989 -- rule for that case, but we can suppose that the expected
5990 -- type of the reduction is the expected type of the component
5993 Analyze_And_Resolve
(Stream
);
5994 Typ
:= Etype
(Stream
);
5996 -- Verify that prefix can be iterated upon.
5998 if Is_Array_Type
(Typ
)
5999 or else Present
(Find_Aspect
(Typ
, Aspect_Default_Iterator
))
6000 or else Present
(Find_Aspect
(Typ
, Aspect_Iterable
))
6005 ("cannot apply Reduce to object of type&", N
, Typ
);
6008 elsif Present
(Expressions
(Stream
))
6009 or else No
(Component_Associations
(Stream
))
6010 or else Nkind
(First
(Component_Associations
(Stream
))) /=
6011 N_Iterated_Component_Association
6014 ("prefix of Reduce must be an iterated component", N
);
6019 Set_Etype
(N
, Etype
(E2
));
6026 when Attribute_Read
=>
6028 Check_Stream_Attribute
(TSS_Stream_Read
);
6029 Set_Etype
(N
, Standard_Void_Type
);
6030 Resolve
(N
, Standard_Void_Type
);
6031 Note_Possible_Modification
(E2
, Sure
=> True);
6037 when Attribute_Ref
=>
6040 if Nkind
(P
) /= N_Expanded_Name
6041 or else not Is_RTE
(P_Type
, RE_Address
)
6043 Error_Attr_P
("prefix of % attribute must be System.Address");
6046 Analyze_And_Resolve
(E1
, Any_Integer
);
6047 Set_Etype
(N
, RTE
(RE_Address
));
6053 -- Shares processing with Adjacent attribute
6055 ---------------------
6056 -- Restriction_Set --
6057 ---------------------
6059 when Attribute_Restriction_Set
=> Restriction_Set
: declare
6062 Unam
: Unit_Name_Type
;
6066 Check_System_Prefix
;
6068 -- No_Dependence case
6070 if Nkind
(E1
) = N_Parameter_Association
then
6071 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
6072 U
:= Explicit_Actual_Parameter
(E1
);
6074 if not OK_No_Dependence_Unit_Name
(U
) then
6075 Set_Boolean_Result
(N
, False);
6079 -- See if there is an entry already in the table. That's the
6080 -- case in which we can return True.
6082 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
6083 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
6084 and then No_Dependences
.Table
(J
).Warn
= False
6086 Set_Boolean_Result
(N
, True);
6091 -- If not in the No_Dependence table, result is False
6093 Set_Boolean_Result
(N
, False);
6095 -- In this case, we must ensure that the binder will reject any
6096 -- other unit in the partition that sets No_Dependence for this
6097 -- unit. We do that by making an entry in the special table kept
6098 -- for this purpose (if the entry is not there already).
6100 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
6102 for J
in Restriction_Set_Dependences
.First
..
6103 Restriction_Set_Dependences
.Last
6105 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
6110 Restriction_Set_Dependences
.Append
(Unam
);
6112 -- Normal restriction case
6115 if Nkind
(E1
) /= N_Identifier
then
6116 Set_Boolean_Result
(N
, False);
6117 Error_Attr
("attribute % requires restriction identifier", E1
);
6120 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
6122 if R
= Not_A_Restriction_Id
then
6123 Set_Boolean_Result
(N
, False);
6124 Error_Msg_Node_1
:= E1
;
6125 Error_Attr
("invalid restriction identifier &", E1
);
6127 elsif R
not in Partition_Boolean_Restrictions
then
6128 Set_Boolean_Result
(N
, False);
6129 Error_Msg_Node_1
:= E1
;
6131 ("& is not a boolean partition-wide restriction", E1
);
6134 if Restriction_Active
(R
) then
6135 Set_Boolean_Result
(N
, True);
6137 Check_Restriction
(R
, N
);
6138 Set_Boolean_Result
(N
, False);
6142 end Restriction_Set
;
6148 when Attribute_Round
=>
6150 Check_Decimal_Fixed_Point_Type
;
6151 Set_Etype
(N
, P_Base_Type
);
6153 -- Because the context is universal_real (3.5.10(12)) it is a
6154 -- legal context for a universal fixed expression. This is the
6155 -- only attribute whose functional description involves U_R.
6157 if Etype
(E1
) = Universal_Fixed
then
6159 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
6160 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
6161 Expression
=> Relocate_Node
(E1
));
6169 Resolve
(E1
, Any_Real
);
6175 -- Shares processing with Ceiling attribute
6181 -- Shares processing with Emax attribute
6187 -- Shares processing with Epsilon attribute
6193 -- Shares processing with Large attribute
6199 -- Shares processing with Epsilon attribute
6205 -- Shares processing with Large attribute
6207 --------------------------
6208 -- Scalar_Storage_Order --
6209 --------------------------
6211 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
6212 Ent
: Entity_Id
:= Empty
;
6218 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
6220 -- The attribute applies to generic private types (in which case
6221 -- the legality rule is applied in the instance) as well as to
6222 -- composite types. For noncomposite types it always returns the
6223 -- default bit order for the target.
6224 -- Allowing formal private types was originally introduced in
6225 -- GNAT_Mode only, to compile instances of Sequential_IO, but
6226 -- users find it more generally useful in generic units.
6228 if not (Is_Generic_Type
(P_Type
) and then Is_Private_Type
(P_Type
))
6229 and then not In_Instance
6232 ("prefix of % attribute must be record or array type");
6234 elsif not Is_Generic_Type
(P_Type
) then
6235 if Bytes_Big_Endian
then
6236 Ent
:= RTE
(RE_High_Order_First
);
6238 Ent
:= RTE
(RE_Low_Order_First
);
6242 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
6243 Ent
:= RTE
(RE_High_Order_First
);
6246 Ent
:= RTE
(RE_Low_Order_First
);
6249 if Present
(Ent
) then
6250 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
6253 Set_Etype
(N
, RTE
(RE_Bit_Order
));
6256 -- Reset incorrect indication of staticness
6258 Set_Is_Static_Expression
(N
, False);
6259 end Scalar_Storage_Order
;
6265 when Attribute_Scale
=>
6267 Check_Decimal_Fixed_Point_Type
;
6268 Set_Etype
(N
, Universal_Integer
);
6274 -- Shares processing with Compose attribute
6280 -- Shares processing with Denorm attribute
6287 | Attribute_VADS_Size
6291 -- If prefix is parameterless function call, rewrite and resolve
6294 if Is_Entity_Name
(P
)
6295 and then Ekind
(Entity
(P
)) = E_Function
6299 -- Similar processing for a protected function call
6301 elsif Nkind
(P
) = N_Selected_Component
6302 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
6307 if Is_Object_Reference
(P
) then
6308 Check_Object_Reference
(P
);
6310 elsif Is_Entity_Name
(P
)
6311 and then (Is_Type
(Entity
(P
))
6312 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6316 elsif Nkind
(P
) = N_Type_Conversion
6317 and then not Comes_From_Source
(P
)
6321 -- Some other compilers allow dubious use of X'???'Size
6323 elsif Relaxed_RM_Semantics
6324 and then Nkind
(P
) = N_Attribute_Reference
6329 Error_Attr_P
("invalid prefix for % attribute");
6332 Check_Not_Incomplete_Type
;
6334 Set_Etype
(N
, Universal_Integer
);
6336 -- If we are processing pragmas Compile_Time_Warning and Compile_
6337 -- Time_Errors after the back end has been called and this occurrence
6338 -- of 'Size is known at compile time then it is safe to perform this
6339 -- evaluation. Needed to perform the static evaluation of the full
6340 -- boolean expression of these pragmas. Note that Known_RM_Size is
6341 -- sometimes True when Size_Known_At_Compile_Time is False, when the
6342 -- back end has computed it.
6344 if In_Compile_Time_Warning_Or_Error
6345 and then Is_Entity_Name
(P
)
6346 and then (Is_Type
(Entity
(P
))
6347 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
6348 and then (Known_RM_Size
(Entity
(P
))
6349 or else Size_Known_At_Compile_Time
(Entity
(P
)))
6355 if Known_Static_RM_Size
(Entity
(P
)) then
6356 Siz
:= RM_Size
(Entity
(P
));
6358 Siz
:= Esize
(Entity
(P
));
6361 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Siz
));
6370 -- Shares processing with Large attribute
6372 ---------------------------------------
6373 -- Small_Denominator/Small_Numerator --
6374 ---------------------------------------
6376 when Attribute_Small_Denominator
6377 | Attribute_Small_Numerator
6379 Check_Fixed_Point_Type_0
;
6380 Set_Etype
(N
, Universal_Integer
);
6386 when Attribute_Storage_Pool
6387 | Attribute_Simple_Storage_Pool
6391 if Is_Access_Type
(P_Type
) then
6392 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6394 ("cannot use % attribute for access-to-subprogram type");
6397 -- Set appropriate entity
6399 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
6400 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
6402 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
6405 if Attr_Id
= Attribute_Storage_Pool
then
6406 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6407 Name_Simple_Storage_Pool_Type
))
6409 Error_Msg_Name_1
:= Aname
;
6410 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6412 ("cannot use % attribute for type with simple storage "
6414 Error_Msg_N
("\Program_Error [<<", N
);
6417 (N
, Make_Raise_Program_Error
6418 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
6421 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6423 -- In the Simple_Storage_Pool case, verify that the pool entity is
6424 -- actually of a simple storage pool type, and set the attribute's
6425 -- type to the pool object's type.
6428 if No
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
6429 Name_Simple_Storage_Pool_Type
))
6432 ("cannot use % attribute for type without simple " &
6436 Set_Etype
(N
, Etype
(Entity
(N
)));
6439 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6440 -- Storage_Pool since this attribute is not defined for such
6441 -- types (RM E.2.2(17)).
6443 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6446 Error_Attr_P
("prefix of % attribute must be access type");
6453 when Attribute_Storage_Size
=>
6456 if Is_Task_Type
(P_Type
) then
6457 Set_Etype
(N
, Universal_Integer
);
6459 -- Use with tasks is an obsolescent feature
6461 Check_Restriction
(No_Obsolescent_Features
, P
);
6463 elsif Is_Access_Type
(P_Type
) then
6464 Set_Etype
(N
, Universal_Integer
);
6466 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
6468 ("cannot use % attribute for access-to-subprogram type");
6471 if Is_Entity_Name
(P
)
6472 and then Is_Type
(Entity
(P
))
6476 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
6477 -- Storage_Size since this attribute is not defined for
6478 -- such types (RM E.2.2(17)).
6480 Validate_Remote_Access_To_Class_Wide_Type
(N
);
6482 -- The prefix is allowed to be an implicit dereference of an
6483 -- access value designating a task.
6490 Error_Attr_P
("prefix of % attribute must be access or task type");
6497 when Attribute_Storage_Unit
=>
6498 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
6504 when Attribute_Stream_Size
=>
6508 if Is_Entity_Name
(P
)
6509 and then Is_Elementary_Type
(Entity
(P
))
6511 Set_Etype
(N
, Universal_Integer
);
6513 Error_Attr_P
("invalid prefix for % attribute");
6520 when Attribute_Stub_Type
=>
6524 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
6526 -- For a real RACW [sub]type, use corresponding stub type
6528 if not Is_Generic_Type
(P_Type
) then
6531 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
6533 -- For a generic type (that has been marked as an RACW using the
6534 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
6535 -- type. Note that if the actual is not a remote access type, the
6536 -- instantiation will fail.
6539 -- Note: we go to the underlying type here because the view
6540 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
6544 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
6549 ("prefix of% attribute must be remote access-to-class-wide");
6556 -- Shares processing with Pred attribute
6558 --------------------------------
6559 -- System_Allocator_Alignment --
6560 --------------------------------
6562 when Attribute_System_Allocator_Alignment
=>
6563 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
6569 when Attribute_Tag
=>
6573 if not Is_Tagged_Type
(P_Type
) then
6574 Error_Attr_P
("prefix of % attribute must be tagged");
6576 -- Next test does not apply to generated code why not, and what does
6577 -- the illegal reference mean???
6579 elsif Is_Object_Reference
(P
)
6580 and then not Is_Class_Wide_Type
(P_Type
)
6581 and then Comes_From_Source
(N
)
6584 ("% attribute can only be applied to objects " &
6585 "of class-wide type");
6588 -- The prefix cannot be an incomplete type. However, references to
6589 -- 'Tag can be generated when expanding interface conversions, and
6592 if Comes_From_Source
(N
) then
6593 Check_Not_Incomplete_Type
;
6595 -- 'Tag requires visibility on the corresponding package holding
6596 -- the tag, so record a reference here, to avoid spurious unused
6597 -- with_clause reported when compiling the main unit.
6599 if In_Extended_Main_Source_Unit
(Current_Scope
) then
6600 Set_Referenced
(P_Type
, True);
6601 Set_Referenced
(Scope
(P_Type
), True);
6605 -- Set appropriate type
6607 Set_Etype
(N
, RTE
(RE_Tag
));
6613 when Attribute_Target_Name
=> Target_Name
: declare
6614 TN
: constant String := Sdefault
.Target_Name
.all;
6618 Check_Standard_Prefix
;
6622 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6627 Make_String_Literal
(Loc
,
6628 Strval
=> TN
(TN
'First .. TL
)));
6629 Analyze_And_Resolve
(N
, Standard_String
);
6630 Set_Is_Static_Expression
(N
, True);
6637 -- Shares processing with Callable attribute
6643 when Attribute_To_Address
=> To_Address
: declare
6647 Check_System_Prefix
;
6649 Generate_Reference
(RTE
(RE_Address
), P
);
6650 Analyze_And_Resolve
(E1
, Any_Integer
);
6651 Set_Etype
(N
, RTE
(RE_Address
));
6652 Set_Is_Static_Expression
(N
, Is_Static_Expression
(E1
));
6654 -- OK static expression case, check range and set appropriate type
6656 if Is_OK_Static_Expression
(E1
) then
6657 Val
:= Expr_Value
(E1
);
6659 if Val
< -(Uint_2
** (System_Address_Size
- 1))
6661 Val
> Uint_2
** System_Address_Size
- 1
6663 Error_Attr
("address value out of range for % attribute", E1
);
6666 -- In most cases the expression is a numeric literal or some other
6667 -- address expression, but if it is a declared constant it may be
6668 -- of a compatible type that must be left on the node.
6670 if Is_Entity_Name
(E1
) then
6673 -- Set type to universal integer if negative
6676 Set_Etype
(E1
, Universal_Integer
);
6678 -- Otherwise set type to Unsigned_64 to accommodate large values
6681 Set_Etype
(E1
, Standard_Unsigned_64
);
6690 when Attribute_To_Any
=>
6692 Check_PolyORB_Attribute
;
6693 Set_Etype
(N
, RTE
(RE_Any
));
6699 -- Shares processing with Ceiling attribute
6705 when Attribute_Type_Class
=>
6708 Check_Not_Incomplete_Type
;
6709 Set_Etype
(N
, RTE
(RE_Type_Class
));
6715 when Attribute_TypeCode
=>
6717 Check_PolyORB_Attribute
;
6718 Set_Etype
(N
, RTE
(RE_TypeCode
));
6724 when Attribute_Type_Key
=> Type_Key
: declare
6725 Full_Name
: constant String_Id
:=
6726 Fully_Qualified_Name_String
(Entity
(P
));
6729 -- The computed signature for the type
6732 -- To simplify the handling of mutually recursive types, follow a
6733 -- single dereference link in a composite type.
6735 procedure Compute_Type_Key
(T
: Entity_Id
);
6736 -- Create a CRC integer from the declaration of the type. For a
6737 -- composite type, fold in the representation of its components in
6738 -- recursive fashion. We use directly the source representation of
6739 -- the types involved.
6741 ----------------------
6742 -- Compute_Type_Key --
6743 ----------------------
6745 procedure Compute_Type_Key
(T
: Entity_Id
) is
6746 Buffer
: Source_Buffer_Ptr
;
6750 SFI
: Source_File_Index
;
6752 procedure Process_One_Declaration
;
6753 -- Update CRC with the characters of one type declaration, or a
6754 -- representation pragma that applies to the type.
6756 -----------------------------
6757 -- Process_One_Declaration --
6758 -----------------------------
6760 procedure Process_One_Declaration
is
6762 -- Scan type declaration, skipping blanks
6764 for Ptr
in P_Min
.. P_Max
loop
6765 if Buffer
(Ptr
) /= ' ' then
6766 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6769 end Process_One_Declaration
;
6771 -- Start of processing for Compute_Type_Key
6774 if Is_Itype
(T
) then
6778 -- If the type is declared in Standard, there is no source, so
6779 -- just use its name.
6781 if Scope
(T
) = Standard_Standard
then
6783 Name
: constant String := Get_Name_String
(Chars
(T
));
6785 for J
in Name
'Range loop
6786 System
.CRC32
.Update
(CRC
, Name
(J
));
6793 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6794 SFI
:= Get_Source_File_Index
(P_Min
);
6795 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6796 Buffer
:= Source_Text
(SFI
);
6798 Process_One_Declaration
;
6800 -- Recurse on relevant component types
6802 if Is_Array_Type
(T
) then
6803 Compute_Type_Key
(Component_Type
(T
));
6805 elsif Is_Access_Type
(T
) then
6808 Compute_Type_Key
(Designated_Type
(T
));
6811 elsif Is_Derived_Type
(T
) then
6812 Compute_Type_Key
(Etype
(T
));
6814 elsif Is_Record_Type
(T
) then
6818 Comp
:= First_Component
(T
);
6819 while Present
(Comp
) loop
6820 Compute_Type_Key
(Etype
(Comp
));
6821 Next_Component
(Comp
);
6826 if Is_First_Subtype
(T
) then
6828 -- Fold in representation aspects for the type, which appear in
6829 -- the same source buffer. If the representation aspects are in
6830 -- a different source file, then skip them; they apply to some
6831 -- other type, perhaps one we're derived from.
6833 Rep
:= First_Rep_Item
(T
);
6835 while Present
(Rep
) loop
6836 if Comes_From_Source
(Rep
) then
6837 Sloc_Range
(Rep
, P_Min
, P_Max
);
6839 if SFI
= Get_Source_File_Index
(P_Min
) then
6840 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6841 Process_One_Declaration
;
6845 Next_Rep_Item
(Rep
);
6848 end Compute_Type_Key
;
6850 -- Start of processing for Type_Key
6859 -- Copy all characters in Full_Name but the trailing NUL
6861 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6862 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6865 -- Compute CRC and convert it to string one character at a time, so
6866 -- as not to use Image within the compiler.
6869 Compute_Type_Key
(Entity
(P
));
6871 if not Is_Frozen
(Entity
(P
))
6872 and then not Is_Generic_Type
(Entity
(P
))
6873 and then not Is_Generic_Actual_Type
(Entity
(P
))
6875 Error_Msg_N
("premature usage of Type_Key?", N
);
6879 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
6883 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
6884 Analyze_And_Resolve
(N
, Standard_String
);
6887 -----------------------
6888 -- Unbiased_Rounding --
6889 -----------------------
6891 -- Shares processing with Ceiling attribute
6893 ----------------------
6894 -- Unchecked_Access --
6895 ----------------------
6897 when Attribute_Unchecked_Access
=>
6898 if Comes_From_Source
(N
) then
6899 Check_Restriction
(No_Unchecked_Access
, N
);
6902 Analyze_Access_Attribute
;
6903 Check_Not_Incomplete_Type
;
6905 -------------------------
6906 -- Unconstrained_Array --
6907 -------------------------
6909 when Attribute_Unconstrained_Array
=>
6912 Check_Not_Incomplete_Type
;
6913 Set_Etype
(N
, Standard_Boolean
);
6914 Set_Is_Static_Expression
(N
, True);
6916 ------------------------------
6917 -- Universal_Literal_String --
6918 ------------------------------
6920 -- This is a GNAT specific attribute whose prefix must be a named
6921 -- number where the expression is either a single numeric literal,
6922 -- or a numeric literal immediately preceded by a minus sign. The
6923 -- result is equivalent to a string literal containing the text of
6924 -- the literal as it appeared in the source program with a possible
6925 -- leading minus sign.
6927 when Attribute_Universal_Literal_String
=>
6930 if not Is_Entity_Name
(P
)
6931 or else not Is_Named_Number
(Entity
(P
))
6933 Error_Attr_P
("prefix for % attribute must be named number");
6940 Src
: Source_Buffer_Ptr
;
6943 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6945 if Nkind
(Expr
) = N_Op_Minus
then
6947 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6952 if Nkind
(Expr
) not in N_Integer_Literal | N_Real_Literal
then
6954 ("named number for % attribute must be simple literal", N
);
6957 -- Build string literal corresponding to source literal text
6962 Store_String_Char
(Get_Char_Code
('-'));
6966 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6968 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6969 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6973 -- Now we rewrite the attribute with the string literal
6976 Make_String_Literal
(Loc
, End_String
));
6978 Set_Is_Static_Expression
(N
, True);
6982 -------------------------
6983 -- Unrestricted_Access --
6984 -------------------------
6986 -- This is a GNAT specific attribute which is like Access except that
6987 -- all scope checks and checks for aliased views are omitted. It is
6988 -- documented as being equivalent to the use of the Address attribute
6989 -- followed by an unchecked conversion to the target access type.
6991 when Attribute_Unrestricted_Access
=>
6993 -- If from source, deal with relevant restrictions
6995 if Comes_From_Source
(N
) then
6996 Check_Restriction
(No_Unchecked_Access
, N
);
6998 if Nkind
(P
) in N_Has_Entity
6999 and then Present
(Entity
(P
))
7000 and then Is_Object
(Entity
(P
))
7002 Check_Restriction
(No_Implicit_Aliasing
, N
);
7006 if Is_Entity_Name
(P
) then
7007 Set_Address_Taken
(Entity
(P
));
7010 -- It might seem reasonable to call Address_Checks here to apply the
7011 -- same set of semantic checks that we enforce for 'Address (after
7012 -- all we document Unrestricted_Access as being equivalent to the
7013 -- use of Address followed by an Unchecked_Conversion). However, if
7014 -- we do enable these checks, we get multiple failures in both the
7015 -- compiler run-time and in our regression test suite, so we leave
7016 -- out these checks for now. To be investigated further some time???
7020 -- Now complete analysis using common access processing
7022 Analyze_Access_Attribute
;
7028 when Attribute_Update
=> Update
: declare
7029 Common_Typ
: Entity_Id
;
7030 -- The common type of a multiple component update for a record
7032 Comps
: Elist_Id
:= No_Elist
;
7033 -- A list used in the resolution of a record update. It contains the
7034 -- entities of all record components processed so far.
7036 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
7037 -- Analyze and resolve array_component_association Assoc against the
7038 -- index of array type P_Type.
7040 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
7041 -- Analyze and resolve record_component_association Comp against
7042 -- record type P_Type.
7044 ------------------------------------
7045 -- Analyze_Array_Component_Update --
7046 ------------------------------------
7048 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
7052 Index_Typ
: Entity_Id
;
7056 -- The current association contains a sequence of indexes denoting
7057 -- an element of a multidimensional array:
7059 -- (Index_1, ..., Index_N)
7061 -- Examine each individual index and resolve it against the proper
7062 -- index type of the array.
7064 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
7065 Expr
:= First
(Choices
(Assoc
));
7066 while Present
(Expr
) loop
7068 -- The use of others is illegal (SPARK RM 4.4.1(12))
7070 if Nkind
(Expr
) = N_Others_Choice
then
7072 ("OTHERS choice not allowed in attribute %", Expr
);
7074 -- Otherwise analyze and resolve all indexes
7077 Index
:= First
(Expressions
(Expr
));
7078 Index_Typ
:= First_Index
(P_Type
);
7079 while Present
(Index
) and then Present
(Index_Typ
) loop
7080 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7082 Next_Index
(Index_Typ
);
7085 -- Detect a case where the association either lacks an
7086 -- index or contains an extra index.
7088 if Present
(Index
) or else Present
(Index_Typ
) then
7090 ("dimension mismatch in index list", Assoc
);
7097 -- The current association denotes either a single component or a
7098 -- range of components of a one dimensional array:
7102 -- Resolve the index or its high and low bounds (if range) against
7103 -- the proper index type of the array.
7106 Index
:= First
(Choices
(Assoc
));
7107 Index_Typ
:= First_Index
(P_Type
);
7109 if Present
(Next_Index
(Index_Typ
)) then
7110 Error_Msg_N
("too few subscripts in array reference", Assoc
);
7113 while Present
(Index
) loop
7115 -- The use of others is illegal (SPARK RM 4.4.1(12))
7117 if Nkind
(Index
) = N_Others_Choice
then
7119 ("OTHERS choice not allowed in attribute %", Index
);
7121 -- The index denotes a range of elements
7123 elsif Nkind
(Index
) = N_Range
then
7124 Low
:= Low_Bound
(Index
);
7125 High
:= High_Bound
(Index
);
7127 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
7128 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
7130 -- Otherwise the index denotes a single element
7133 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
7139 end Analyze_Array_Component_Update
;
7141 -------------------------------------
7142 -- Analyze_Record_Component_Update --
7143 -------------------------------------
7145 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
7146 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
7147 Base_Typ
: Entity_Id
;
7148 Comp_Or_Discr
: Entity_Id
;
7151 -- Find the discriminant or component whose name corresponds to
7152 -- Comp. A simple character comparison is sufficient because all
7153 -- visible names within a record type are unique.
7155 Comp_Or_Discr
:= First_Entity
(P_Type
);
7156 while Present
(Comp_Or_Discr
) loop
7157 if Chars
(Comp_Or_Discr
) = Comp_Name
then
7159 -- Decorate the component reference by setting its entity
7160 -- and type for resolution purposes.
7162 Set_Entity
(Comp
, Comp_Or_Discr
);
7163 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
7167 Next_Entity
(Comp_Or_Discr
);
7170 -- Diagnose an illegal reference
7172 if Present
(Comp_Or_Discr
) then
7173 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
7175 ("attribute % may not modify record discriminants", Comp
);
7177 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
7178 if Contains
(Comps
, Comp_Or_Discr
) then
7179 Error_Msg_N
("component & already updated", Comp
);
7181 -- Mark this component as processed
7184 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
7188 -- The update aggregate mentions an entity that does not belong to
7192 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
7195 -- Verify the consistency of types when the current component is
7196 -- part of a multiple component update.
7198 -- Comp_1 | ... | Comp_N => <value>
7200 if Present
(Etype
(Comp
)) then
7201 Base_Typ
:= Base_Type
(Etype
(Comp
));
7203 -- Save the type of the first component reference as the
7204 -- remaning references (if any) must resolve to this type.
7206 if No
(Common_Typ
) then
7207 Common_Typ
:= Base_Typ
;
7209 elsif Base_Typ
/= Common_Typ
then
7211 ("components in choice list must have same type", Comp
);
7214 end Analyze_Record_Component_Update
;
7221 -- Start of processing for Update
7224 if Warn_On_Obsolescent_Feature
then
7225 Error_Msg_N
("?j?attribute Update is an obsolescent feature", N
);
7226 Error_Msg_N
("\?j?use a delta aggregate instead", N
);
7231 if not Is_Object_Reference
(P
) then
7232 Error_Attr_P
("prefix of attribute % must denote an object");
7234 elsif not Is_Array_Type
(P_Type
)
7235 and then not Is_Record_Type
(P_Type
)
7237 Error_Attr_P
("prefix of attribute % must be a record or array");
7239 elsif Is_Limited_View
(P_Type
) then
7240 Error_Attr
("prefix of attribute % cannot be limited", N
);
7242 elsif Nkind
(E1
) /= N_Aggregate
then
7243 Error_Attr
("attribute % requires component association list", N
);
7245 elsif Present
(Expressions
(E1
)) then
7246 Error_Attr
("attribute % requires named component associations",
7247 First
(Expressions
(E1
)));
7251 -- Inspect the update aggregate, looking at all the associations and
7252 -- choices. Perform the following checks:
7254 -- 1) Legality of "others" in all cases
7255 -- 2) Legality of <>
7256 -- 3) Component legality for arrays
7257 -- 4) Component legality for records
7259 -- The remaining checks are performed on the expanded attribute
7261 Assoc
:= First
(Component_Associations
(E1
));
7262 while Present
(Assoc
) loop
7264 -- The use of <> is illegal (SPARK RM 4.4.1(1))
7266 if Box_Present
(Assoc
) then
7268 ("default initialization not allowed in attribute %", Assoc
);
7270 -- Otherwise process the association
7273 Analyze
(Expression
(Assoc
));
7275 if Is_Array_Type
(P_Type
) then
7276 Analyze_Array_Component_Update
(Assoc
);
7278 elsif Is_Record_Type
(P_Type
) then
7280 -- Reset the common type used in a multiple component update
7281 -- as we are processing the contents of a new association.
7283 Common_Typ
:= Empty
;
7285 Comp
:= First
(Choices
(Assoc
));
7286 while Present
(Comp
) loop
7287 if Nkind
(Comp
) = N_Identifier
then
7288 Analyze_Record_Component_Update
(Comp
);
7290 -- The use of others is illegal (SPARK RM 4.4.1(5))
7292 elsif Nkind
(Comp
) = N_Others_Choice
then
7294 ("OTHERS choice not allowed in attribute %", Comp
);
7296 -- The name of a record component cannot appear in any
7301 ("name should be identifier or OTHERS", Comp
);
7312 -- The type of attribute 'Update is that of the prefix
7314 Set_Etype
(N
, P_Type
);
7316 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
7323 when Attribute_Val
=>
7325 Check_Discrete_Type
;
7327 -- Note, we need a range check in general, but we wait for the
7328 -- Resolve call to do this, since we want to let Eval_Attribute
7329 -- have a chance to find an static illegality first.
7331 Resolve
(E1
, Any_Integer
);
7332 Set_Etype
(N
, P_Base_Type
);
7338 when Attribute_Valid
=> Valid
: declare
7339 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
7344 -- Ignore check for object if we have a 'Valid reference generated
7345 -- by the expanded code, since in some cases valid checks can occur
7346 -- on items that are names, but are not objects (e.g. attributes).
7348 if Comes_From_Source
(N
) then
7349 Check_Object_Reference
(P
);
7351 if not Is_Scalar_Type
(P_Type
) then
7352 Error_Attr_P
("object for % attribute must be of scalar type");
7355 -- If the attribute appears within the subtype's own predicate
7356 -- function, then issue a warning that this will cause infinite
7359 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
7360 Error_Msg_N
("attribute Valid requires a predicate check??", N
);
7361 Error_Msg_N
("\and will result in infinite recursion??", N
);
7365 Set_Etype
(N
, Standard_Boolean
);
7372 when Attribute_Valid_Value
=>
7374 Check_Enumeration_Type
;
7375 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7376 Set_Etype
(N
, Standard_Boolean
);
7377 Validate_Non_Static_Attribute_Function_Call
;
7379 if P_Type
in Standard_Boolean
7380 | Standard_Character
7381 | Standard_Wide_Character
7382 | Standard_Wide_Wide_Character
7385 ("prefix of % attribute must not be a type in Standard");
7388 if Discard_Names
(First_Subtype
(P_Type
)) then
7390 ("prefix of % attribute must not have Discard_Names");
7397 when Attribute_Valid_Scalars
=> Valid_Scalars
: declare
7401 if Comes_From_Source
(N
) then
7402 Check_Object_Reference
(P
);
7404 -- Attribute 'Valid_Scalars is illegal on unchecked union types
7405 -- regardles of the privacy, because it is not always guaranteed
7406 -- that the components are retrievable based on whether the
7407 -- discriminants are inferable.
7409 if Has_Unchecked_Union
(Validated_View
(P_Type
)) then
7411 ("attribute % not allowed for Unchecked_Union type");
7413 -- Do not emit any diagnostics related to private types to avoid
7414 -- disclosing the structure of the type.
7416 elsif Is_Private_Type
(P_Type
) then
7418 -- Attribute 'Valid_Scalars is not supported on private tagged
7419 -- types due to a code generation issue. Is_Visible_Component
7420 -- does not allow for a component of a private tagged type to
7421 -- be successfully retrieved.
7422 -- ??? This attribute should simply ignore type privacy
7423 -- (see Validated_View). It should examine components of the
7424 -- tagged type extensions (if any) and recursively examine
7425 -- 'Valid_Scalars of the parent's type (if any).
7427 -- Do not use Error_Attr_P because this bypasses any subsequent
7428 -- processing and leaves the attribute with type Any_Type. This
7429 -- in turn prevents the proper expansion of the attribute into
7432 if Is_Tagged_Type
(P_Type
) then
7433 Error_Msg_Name_1
:= Aname
;
7434 Error_Msg_N
("??effects of attribute % are ignored", N
);
7437 -- Otherwise the type is not private
7440 if not Scalar_Part_Present
(P_Type
) then
7441 Error_Msg_Name_1
:= Aname
;
7443 ("??attribute % always True, no scalars to check", P
);
7444 Set_Boolean_Result
(N
, True);
7449 Set_Etype
(N
, Standard_Boolean
);
7456 when Attribute_Value
7457 | Attribute_Wide_Value
7458 | Attribute_Wide_Wide_Value
7462 Check_Enum_Image
(Check_Enumeration_Maps
=> True);
7464 -- Set Etype before resolving expression because expansion of
7465 -- expression may require enclosing type. Note that the type
7466 -- returned by 'Value is the base type of the prefix type.
7468 Set_Etype
(N
, P_Base_Type
);
7469 Validate_Non_Static_Attribute_Function_Call
;
7471 -- Check restriction No_Fixed_IO
7473 if Restriction_Check_Required
(No_Fixed_IO
)
7474 and then Is_Fixed_Point_Type
(P_Type
)
7476 Check_Restriction
(No_Fixed_IO
, P
);
7483 -- Shares processing with Machine_Size attribute
7489 when Attribute_Version
=>
7492 Set_Etype
(N
, RTE
(RE_Version_String
));
7498 when Attribute_Wchar_T_Size
=>
7499 Standard_Attribute
(Interfaces_Wchar_T_Size
);
7505 when Attribute_Wide_Image
=>
7506 Analyze_Image_Attribute
(Standard_Wide_String
);
7508 ---------------------
7509 -- Wide_Wide_Image --
7510 ---------------------
7512 when Attribute_Wide_Wide_Image
=>
7513 Analyze_Image_Attribute
(Standard_Wide_Wide_String
);
7519 -- Shares processing with Value attribute
7521 ---------------------
7522 -- Wide_Wide_Value --
7523 ---------------------
7525 -- Shares processing with Value attribute
7527 ---------------------
7528 -- Wide_Wide_Width --
7529 ---------------------
7531 when Attribute_Wide_Wide_Width
7532 | Attribute_Wide_Width
7537 Set_Etype
(N
, Universal_Integer
);
7543 -- Shares processing with Wide_Wide_Width attribute
7549 -- Shares processing with Wide_Wide_Width attribute
7555 when Attribute_Word_Size
=>
7556 Standard_Attribute
(System_Word_Size
);
7562 when Attribute_Write
=>
7564 Check_Stream_Attribute
(TSS_Stream_Write
);
7565 Set_Etype
(N
, Standard_Void_Type
);
7566 Resolve
(N
, Standard_Void_Type
);
7570 -- In SPARK certain attributes (see below) depend on Tasking_State.
7571 -- Ensure that the entity is available for gnat2why by loading it.
7572 -- See SPARK RM 9(18) for the relevant rule.
7574 if GNATprove_Mode
then
7576 when Attribute_Callable
7579 | Attribute_Terminated
7581 SPARK_Implicit_Load
(RE_Tasking_State
);
7588 -- All errors raise Bad_Attribute, so that we get out before any further
7589 -- damage occurs when an error is detected (for example, if we check for
7590 -- one attribute expression, and the check succeeds, we want to be able
7591 -- to proceed securely assuming that an expression is in fact present.
7593 -- Note: we set the attribute analyzed in this case to prevent any
7594 -- attempt at reanalysis which could generate spurious error msgs.
7597 when Bad_Attribute
=>
7599 Set_Etype
(N
, Any_Type
);
7601 end Analyze_Attribute
;
7603 --------------------
7604 -- Eval_Attribute --
7605 --------------------
7607 procedure Eval_Attribute
(N
: Node_Id
) is
7608 Loc
: constant Source_Ptr
:= Sloc
(N
);
7610 C_Type
: constant Entity_Id
:= Etype
(N
);
7611 -- The type imposed by the context
7614 -- Attribute_Name (N) after verification of validity of N
7617 -- Get_Attribute_Id (Aname) after Aname is set
7620 -- Prefix (N) after verification of validity of N
7623 -- First expression, or Empty if none
7626 -- Second expression, or Empty if none
7628 P_Entity
: Entity_Id
;
7629 -- Entity denoted by prefix
7632 -- The type of the prefix
7634 P_Base_Type
: Entity_Id
;
7635 -- The base type of the prefix type
7637 P_Root_Type
: Entity_Id
;
7638 -- The root type of the prefix type
7640 Static
: Boolean := False;
7641 -- True if the result is Static. This is set by the general processing
7642 -- to true if the prefix is static, and all expressions are static. It
7643 -- can be reset as processing continues for particular attributes. This
7644 -- flag can still be True if the reference raises a constraint error.
7645 -- Is_Static_Expression (N) is set to follow this value as it is set
7646 -- and we could always reference this, but it is convenient to have a
7647 -- simple short name to use, since it is frequently referenced.
7649 Lo_Bound
, Hi_Bound
: Node_Id
;
7650 -- Expressions for low and high bounds of type or array index referenced
7651 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7654 -- Constraint error node used if we have an attribute reference has
7655 -- an argument that raises a constraint error. In this case we replace
7656 -- the attribute with a raise constraint_error node. This is important
7657 -- processing, since otherwise gigi might see an attribute which it is
7658 -- unprepared to deal with.
7660 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7661 -- If Bound is a reference to a discriminant of a task or protected type
7662 -- occurring within the object's body, rewrite attribute reference into
7663 -- a reference to the corresponding discriminal. Use for the expansion
7664 -- of checks against bounds of entry family index subtypes.
7666 procedure Check_Expressions
;
7667 -- In case where the attribute is not foldable, the expressions, if
7668 -- any, of the attribute, are in a non-static context. This procedure
7669 -- performs the required additional checks.
7671 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7672 -- Determines if the given type has compile time known bounds. Note
7673 -- that we enter the case statement even in cases where the prefix
7674 -- type does NOT have known bounds, so it is important to guard any
7675 -- attempt to evaluate both bounds with a call to this function.
7677 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7678 -- This procedure is called when the attribute N has a non-static
7679 -- but compile time known value given by Val. It includes the
7680 -- necessary checks for out of range values.
7682 function Fore_Value
return Nat
;
7683 -- Computes the Fore value for the current attribute prefix, which is
7684 -- known to be a static fixed-point type. Used by Fore and Width.
7686 function Mantissa
return Uint
;
7687 -- Returns the Mantissa value for the prefix type
7689 procedure Set_Bounds
;
7690 -- Used for First, Last and Length attributes applied to an array or
7691 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7692 -- and high bound expressions for the index referenced by the attribute
7693 -- designator (i.e. the first index if no expression is present, and the
7694 -- N'th index if the value N is present as an expression). Also used for
7695 -- First and Last of scalar types and for First_Valid and Last_Valid.
7696 -- Static is reset to False if the type or index type is not statically
7699 -----------------------------------
7700 -- Check_Concurrent_Discriminant --
7701 -----------------------------------
7703 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7705 -- The concurrent (task or protected) type
7708 if Nkind
(Bound
) = N_Identifier
7709 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7710 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7712 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7714 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7716 -- Find discriminant of original concurrent type, and use
7717 -- its current discriminal, which is the renaming within
7718 -- the task/protected body.
7722 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7725 end Check_Concurrent_Discriminant
;
7727 -----------------------
7728 -- Check_Expressions --
7729 -----------------------
7731 procedure Check_Expressions
is
7735 while Present
(E
) loop
7736 Check_Non_Static_Context
(E
);
7739 end Check_Expressions
;
7741 ----------------------------------
7742 -- Compile_Time_Known_Attribute --
7743 ----------------------------------
7745 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7746 T
: constant Entity_Id
:= Etype
(N
);
7749 Fold_Uint
(N
, Val
, False);
7751 -- Check that result is in bounds of the type if it is static
7753 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7756 elsif Is_Out_Of_Range
(N
, T
) then
7757 Apply_Compile_Time_Constraint_Error
7758 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7760 elsif not Range_Checks_Suppressed
(T
) then
7761 Enable_Range_Check
(N
);
7764 Set_Do_Range_Check
(N
, False);
7766 end Compile_Time_Known_Attribute
;
7768 -------------------------------
7769 -- Compile_Time_Known_Bounds --
7770 -------------------------------
7772 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7775 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7777 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7778 end Compile_Time_Known_Bounds
;
7784 -- Note that the Fore calculation is based on the actual values
7785 -- of the bounds, and does not take into account possible rounding.
7787 function Fore_Value
return Nat
is
7788 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7789 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7790 Small
: constant Ureal
:= Small_Value
(P_Type
);
7791 Lo_Real
: constant Ureal
:= Lo
* Small
;
7792 Hi_Real
: constant Ureal
:= Hi
* Small
;
7797 -- Bounds are given in terms of small units, so first compute
7798 -- proper values as reals.
7800 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7803 -- Loop to compute proper value if more than one digit required
7805 while T
>= Ureal_10
loop
7817 -- Table of mantissa values accessed by function Computed using
7820 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7822 -- where D is T'Digits (RM83 3.5.7)
7824 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7866 function Mantissa
return Uint
is
7869 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7876 procedure Set_Bounds
is
7882 -- For a string literal subtype, we have to construct the bounds.
7883 -- Valid Ada code never applies attributes to string literals, but
7884 -- it is convenient to allow the expander to generate attribute
7885 -- references of this type (e.g. First and Last applied to a string
7888 -- Note that the whole point of the E_String_Literal_Subtype is to
7889 -- avoid this construction of bounds, but the cases in which we
7890 -- have to materialize them are rare enough that we don't worry.
7892 -- The low bound is simply the low bound of the base type. The
7893 -- high bound is computed from the length of the string and this
7896 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7897 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7898 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7901 Make_Integer_Literal
(Sloc
(P
),
7903 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7905 Set_Parent
(Hi_Bound
, P
);
7906 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7909 -- For non-array case, just get bounds of scalar type
7911 elsif Is_Scalar_Type
(P_Type
) then
7914 -- For a fixed-point type, we must freeze to get the attributes
7915 -- of the fixed-point type set now so we can reference them.
7917 if Is_Fixed_Point_Type
(P_Type
)
7918 and then not Is_Frozen
(Base_Type
(P_Type
))
7919 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7920 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7922 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7925 -- For array case, get type of proper index
7931 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7934 Indx
:= First_Index
(P_Type
);
7935 for J
in 1 .. Ndim
- 1 loop
7939 -- If no index type, get out (some other error occurred, and
7940 -- we don't have enough information to complete the job).
7948 Ityp
:= Etype
(Indx
);
7951 -- A discrete range in an index constraint is allowed to be a
7952 -- subtype indication. This is syntactically a pain, but should
7953 -- not propagate to the entity for the corresponding index subtype.
7954 -- After checking that the subtype indication is legal, the range
7955 -- of the subtype indication should be transfered to the entity.
7956 -- The attributes for the bounds should remain the simple retrievals
7957 -- that they are now.
7959 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7960 Hi_Bound
:= Type_High_Bound
(Ityp
);
7962 -- If subtype is non-static, result is definitely non-static
7964 if not Is_Static_Subtype
(Ityp
) then
7966 Set_Is_Static_Expression
(N
, False);
7968 -- Subtype is static, does it raise CE?
7970 elsif not Is_OK_Static_Subtype
(Ityp
) then
7971 Set_Raises_Constraint_Error
(N
);
7975 -- Start of processing for Eval_Attribute
7978 -- Return immediately if e.g. N has been rewritten or is malformed due
7979 -- to previous errors.
7981 if Nkind
(N
) /= N_Attribute_Reference
then
7985 Aname
:= Attribute_Name
(N
);
7986 Id
:= Get_Attribute_Id
(Aname
);
7989 -- The To_Address attribute can be static, but it cannot be evaluated at
7990 -- compile time, so just return.
7992 if Id
= Attribute_To_Address
then
7996 -- Initialize result as non-static, will be reset if appropriate
7998 Set_Is_Static_Expression
(N
, False);
8000 -- Acquire first two expressions (at the moment, no attributes take more
8001 -- than two expressions in any case).
8003 if Present
(Expressions
(N
)) then
8004 E1
:= First
(Expressions
(N
));
8011 -- Special processing for Enabled attribute. This attribute has a very
8012 -- special prefix, and the easiest way to avoid lots of special checks
8013 -- to protect this special prefix from causing trouble is to deal with
8014 -- this attribute immediately and be done with it.
8016 if Id
= Attribute_Enabled
then
8018 -- We skip evaluation if the expander is not active. This is not just
8019 -- an optimization. It is of key importance that we not rewrite the
8020 -- attribute in a generic template, since we want to pick up the
8021 -- setting of the check in the instance.
8023 if not Inside_A_Generic
then
8025 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
8030 if C
in Predefined_Check_Id
then
8031 R
:= Scope_Suppress
.Suppress
(C
);
8033 R
:= Is_Check_Suppressed
(Empty
, C
);
8037 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
8040 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
8047 -- Attribute 'Img applied to a static enumeration value is static, and
8048 -- we will do the folding right here (things get confused if we let this
8049 -- case go through the normal circuitry).
8051 if Id
= Attribute_Img
8052 and then Is_Entity_Name
(P
)
8053 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
8054 and then Is_OK_Static_Expression
(P
)
8057 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
8062 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8063 Set_Casing
(All_Upper_Case
);
8064 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8067 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8068 Analyze_And_Resolve
(N
, Standard_String
);
8069 Set_Is_Static_Expression
(N
, True);
8075 -- Special processing for cases where the prefix is an object or value,
8076 -- including string literals (attributes of string literals can only
8077 -- appear in generated code) and current instance prefixes in type or
8080 if Is_Object_Reference
(P
)
8081 or else Is_Current_Instance_Reference_In_Type_Aspect
(P
)
8082 or else Nkind
(P
) = N_String_Literal
8083 or else (Is_Entity_Name
(P
)
8084 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
8086 -- For Alignment, give alignment of object if available, otherwise we
8087 -- cannot fold Alignment.
8089 if Id
= Attribute_Alignment
then
8090 if Is_Entity_Name
(P
) and then Known_Alignment
(Entity
(P
)) then
8091 Compile_Time_Known_Attribute
(N
, Alignment
(Entity
(P
)));
8098 -- For Component_Size, the prefix is an array object, and we apply
8099 -- the attribute to the type of the object. This is allowed for both
8100 -- unconstrained and constrained arrays, since the bounds have no
8101 -- influence on the value of this attribute.
8103 elsif Id
= Attribute_Component_Size
then
8104 P_Entity
:= Etype
(P
);
8106 -- For Enum_Rep, evaluation depends on the nature of the prefix and
8107 -- the optional argument.
8109 elsif Id
= Attribute_Enum_Rep
then
8110 if Is_Entity_Name
(P
) then
8113 Enum_Expr
: Node_Id
;
8114 -- The enumeration-type expression of interest
8119 if Ekind
(Entity
(P
)) in E_Constant | E_Enumeration_Literal
8123 -- Enum_Type'Enum_Rep (E1) case
8125 elsif Is_Enumeration_Type
(Entity
(P
)) then
8128 -- Otherwise the attribute must be expanded into a
8129 -- conversion and evaluated at run time.
8136 -- We can fold if the expression is an enumeration
8137 -- literal, or if it denotes a constant whose value
8138 -- is known at compile time.
8140 if Nkind
(Enum_Expr
) in N_Has_Entity
8141 and then (Ekind
(Entity
(Enum_Expr
)) =
8142 E_Enumeration_Literal
8144 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
8145 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
8146 N_Object_Declaration
8148 (Expression
(Parent
(Entity
(P
))))
8149 and then Compile_Time_Known_Value
8150 (Expression
(Parent
(Entity
(P
))))))
8152 P_Entity
:= Etype
(P
);
8159 -- Otherwise the attribute is illegal, do not attempt to perform
8160 -- any kind of folding.
8166 -- For Bit_Position, give Component_Bit_Offset of object if available
8167 -- otherwise we cannot fold Bit_Position. Note that the attribute can
8168 -- be applied to a naked record component in generated code, in which
8169 -- case the prefix is an identifier that references the component or
8170 -- discriminant entity.
8172 elsif Id
= Attribute_Bit_Position
then
8177 if Is_Entity_Name
(P
) then
8180 CE
:= Entity
(Selector_Name
(P
));
8183 if Known_Static_Component_Bit_Offset
(CE
) then
8184 Compile_Time_Known_Attribute
8185 (N
, Component_Bit_Offset
(CE
));
8193 -- For Position, in Ada 2005 (or later) if we have the non-default
8194 -- bit order, we return the original value as given in the component
8195 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8196 -- default bit order) return the value if it is known statically.
8198 elsif Id
= Attribute_Position
then
8200 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8203 if Present
(Component_Clause
(CE
))
8204 and then Ada_Version
>= Ada_2005
8205 and then Reverse_Bit_Order
(Scope
(CE
))
8207 Compile_Time_Known_Attribute
8208 (N
, Expr_Value
(Position
(Component_Clause
(CE
))));
8210 elsif Known_Static_Component_Bit_Offset
(CE
) then
8211 Compile_Time_Known_Attribute
8212 (N
, Component_Bit_Offset
(CE
) / System_Storage_Unit
);
8221 -- For First_Bit, in Ada 2005 (or later) if we have the non-default
8222 -- bit order, we return the original value as given in the component
8223 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8224 -- default bit order) return the value if it is known statically.
8226 elsif Id
= Attribute_First_Bit
then
8228 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8231 if Present
(Component_Clause
(CE
))
8232 and then Ada_Version
>= Ada_2005
8233 and then Reverse_Bit_Order
(Scope
(CE
))
8235 Compile_Time_Known_Attribute
8236 (N
, Expr_Value
(First_Bit
(Component_Clause
(CE
))));
8238 elsif Known_Static_Component_Bit_Offset
(CE
) then
8239 Compile_Time_Known_Attribute
8240 (N
, Component_Bit_Offset
(CE
) mod System_Storage_Unit
);
8249 -- For Last_Bit, in Ada 2005 (or later) if we have the non-default
8250 -- bit order, we return the original value as given in the component
8251 -- clause (RM 2005 13.5.2(3/2)). Otherwise (Ada 83/95, or later with
8252 -- default bit order) return the value if it is known statically.
8254 elsif Id
= Attribute_Last_Bit
then
8256 CE
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
8259 if Present
(Component_Clause
(CE
))
8260 and then Ada_Version
>= Ada_2005
8261 and then Reverse_Bit_Order
(Scope
(CE
))
8263 Compile_Time_Known_Attribute
8264 (N
, Expr_Value
(Last_Bit
(Component_Clause
(CE
))));
8266 elsif Known_Static_Component_Bit_Offset
(CE
)
8267 and then Known_Static_Esize
(CE
)
8269 Compile_Time_Known_Attribute
8270 (N
, (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
8279 -- For First, Last and Length, the prefix is an array object, and we
8280 -- apply the attribute to its type, but we need a constrained type
8281 -- for this, so we use the actual subtype if available.
8283 elsif Id
= Attribute_First
8284 or else Id
= Attribute_Last
8285 or else Id
= Attribute_Length
8288 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
8291 if Present
(AS
) and then Is_Constrained
(AS
) then
8294 -- If we have an unconstrained type we cannot fold
8302 elsif Id
= Attribute_Size
then
8303 -- For Enum_Lit'Size, use Enum_Type'Object_Size. Taking the 'Size
8304 -- of a literal is kind of a strange thing to do, so we don't want
8305 -- to pass this oddity on to the back end. Note that Etype of an
8306 -- enumeration literal is always a (base) type, never a
8307 -- constrained subtype, so the Esize is always known.
8309 if Is_Entity_Name
(P
)
8310 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
8312 pragma Assert
(Known_Static_Esize
(Etype
(P
)));
8313 Compile_Time_Known_Attribute
(N
, Esize
(Etype
(P
)));
8315 -- Otherwise, if Size is available, use that
8317 elsif Is_Entity_Name
(P
) and then Known_Static_Esize
(Entity
(P
))
8319 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
8321 -- Otherwise, we cannot fold
8334 -- Cases where P is not an object. Cannot do anything if P is not the
8335 -- name of an entity.
8337 elsif not Is_Entity_Name
(P
) then
8341 -- Otherwise get prefix entity
8344 P_Entity
:= Entity
(P
);
8347 -- If we are asked to evaluate an attribute where the prefix is a
8348 -- non-frozen generic actual type whose RM_Size has not been set,
8349 -- then abandon the effort.
8351 if Is_Type
(P_Entity
)
8352 and then (not Is_Frozen
(P_Entity
)
8353 and then Is_Generic_Actual_Type
(P_Entity
)
8354 and then not Known_RM_Size
(P_Entity
))
8356 -- However, the attribute Unconstrained_Array must be evaluated,
8357 -- since it is documented to be a static attribute (and can for
8358 -- example appear in a Compile_Time_Warning pragma). The frozen
8359 -- status of the type does not affect its evaluation.
8361 and then Id
/= Attribute_Unconstrained_Array
8366 -- At this stage P_Entity is the entity to which the attribute
8367 -- is to be applied. This is usually simply the entity of the
8368 -- prefix, except in some cases of attributes for objects, where
8369 -- as described above, we apply the attribute to the object type.
8371 -- Here is where we make sure that static attributes are properly
8372 -- marked as such. These are attributes whose prefix is a static
8373 -- scalar subtype, whose result is scalar, and whose arguments, if
8374 -- present, are static scalar expressions. Note that such references
8375 -- are static expressions even if they raise Constraint_Error.
8377 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
8378 -- though evaluating it raises constraint error. This means that a
8379 -- declaration like:
8381 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
8383 -- is legal, since here this expression appears in a statically
8384 -- unevaluated position, so it does not actually raise an exception.
8386 -- T'Descriptor_Size is never static, even if T is static.
8388 if Is_Scalar_Type
(P_Entity
)
8389 and then not Is_Generic_Type
(P_Entity
)
8390 and then Is_Static_Subtype
(P_Entity
)
8391 and then Is_Scalar_Type
(Etype
(N
))
8394 or else (Is_Static_Expression
(E1
)
8395 and then Is_Scalar_Type
(Etype
(E1
))))
8398 or else (Is_Static_Expression
(E2
)
8399 and then Is_Scalar_Type
(Etype
(E1
))))
8400 and then Id
/= Attribute_Descriptor_Size
8402 -- If the front-end conjures up Integer'Pred (Integer'First)
8403 -- as the high bound of a null array aggregate, then we don't
8404 -- want to reject that as an illegal static expression.
8406 and then not Is_Null_Array_Aggregate_High_Bound
(N
)
8409 Set_Is_Static_Expression
(N
, True);
8412 -- First foldable possibility is a scalar or array type (RM 4.9(7))
8413 -- that is not generic (generic types are eliminated by RM 4.9(25)).
8414 -- Note we allow nonstatic nongeneric types at this stage as further
8417 if Is_Type
(P_Entity
)
8418 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
8419 and then not Is_Generic_Type
(P_Entity
)
8423 -- Second foldable possibility is an array object (RM 4.9(8))
8425 elsif Ekind
(P_Entity
) in E_Variable | E_Constant
8426 and then Is_Array_Type
(Etype
(P_Entity
))
8427 and then not Is_Generic_Type
(Etype
(P_Entity
))
8429 P_Type
:= Etype
(P_Entity
);
8431 -- If the entity is an array constant with an unconstrained nominal
8432 -- subtype then get the type from the initial value. If the value has
8433 -- been expanded into assignments, there is no expression and the
8434 -- attribute reference remains dynamic.
8436 -- We could do better here and retrieve the type ???
8438 if Ekind
(P_Entity
) = E_Constant
8439 and then not Is_Constrained
(P_Type
)
8441 if No
(Constant_Value
(P_Entity
)) then
8444 P_Type
:= Etype
(Constant_Value
(P_Entity
));
8448 -- Definite must be folded if the prefix is not a generic type, that
8449 -- is to say if we are within an instantiation. Same processing applies
8450 -- to selected GNAT attributes.
8452 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
8453 Id
= Attribute_Definite
or else
8454 Id
= Attribute_Descriptor_Size
or else
8455 Id
= Attribute_Has_Access_Values
or else
8456 Id
= Attribute_Has_Discriminants
or else
8457 Id
= Attribute_Has_Tagged_Values
or else
8458 Id
= Attribute_Preelaborable_Initialization
or else
8459 Id
= Attribute_Type_Class
or else
8460 Id
= Attribute_Unconstrained_Array
or else
8461 Id
= Attribute_Max_Alignment_For_Allocation
)
8462 and then not Is_Generic_Type
(P_Entity
)
8466 -- We can fold 'Size applied to a type if the size is known (as happens
8467 -- for a size from an attribute definition clause). At this stage, this
8468 -- can happen only for types (e.g. record types) for which the size is
8469 -- always non-static. We exclude generic types from consideration (since
8470 -- they have bogus sizes set within templates). We can also fold
8471 -- Max_Size_In_Storage_Elements in the same cases.
8473 elsif (Id
= Attribute_Size
or
8474 Id
= Attribute_Max_Size_In_Storage_Elements
)
8475 and then Is_Type
(P_Entity
)
8476 and then not Is_Generic_Type
(P_Entity
)
8477 and then Known_Static_RM_Size
(P_Entity
)
8480 Attr_Value
: Uint
:= RM_Size
(P_Entity
);
8482 if Id
= Attribute_Max_Size_In_Storage_Elements
then
8483 Attr_Value
:= (Attr_Value
+ System_Storage_Unit
- 1)
8484 / System_Storage_Unit
;
8486 Compile_Time_Known_Attribute
(N
, Attr_Value
);
8490 -- We can fold 'Alignment applied to a type if the alignment is known
8491 -- (as happens for an alignment from an attribute definition clause).
8492 -- At this stage, this can happen only for types (e.g. record types) for
8493 -- which the size is always non-static. We exclude generic types from
8494 -- consideration (since they have bogus sizes set within templates).
8496 elsif Id
= Attribute_Alignment
8497 and then Is_Type
(P_Entity
)
8498 and then not Is_Generic_Type
(P_Entity
)
8499 and then Known_Alignment
(P_Entity
)
8501 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
8504 -- If this is an access attribute that is known to fail accessibility
8505 -- check, rewrite accordingly.
8507 elsif Id
= Attribute_Address
8508 and then Raises_Constraint_Error
(N
)
8511 Make_Raise_Program_Error
(Loc
,
8512 Reason
=> PE_Accessibility_Check_Failed
));
8513 Set_Etype
(N
, C_Type
);
8516 -- No other cases are foldable (they certainly aren't static, and at
8517 -- the moment we don't try to fold any cases other than the ones above).
8524 -- If either attribute or the prefix is Any_Type, then propagate
8525 -- Any_Type to the result and don't do anything else at all.
8527 if P_Type
= Any_Type
8528 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
8529 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
8531 Set_Etype
(N
, Any_Type
);
8535 -- Scalar subtype case. We have not yet enforced the static requirement
8536 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
8537 -- of non-static attribute references (e.g. S'Digits for a non-static
8538 -- floating-point type, which we can compute at compile time).
8540 -- Note: this folding of non-static attributes is not simply a case of
8541 -- optimization. For many of the attributes affected, Gigi cannot handle
8542 -- the attribute and depends on the front end having folded them away.
8544 -- Note: although we don't require staticness at this stage, we do set
8545 -- the Static variable to record the staticness, for easy reference by
8546 -- those attributes where it matters (e.g. Succ and Pred), and also to
8547 -- be used to ensure that non-static folded things are not marked as
8548 -- being static (a check that is done right at the end).
8550 P_Root_Type
:= Root_Type
(P_Type
);
8551 P_Base_Type
:= Base_Type
(P_Type
);
8553 -- If the root type or base type is generic, then we cannot fold. This
8554 -- test is needed because subtypes of generic types are not always
8555 -- marked as being generic themselves (which seems odd???)
8557 if Is_Generic_Type
(P_Root_Type
)
8558 or else Is_Generic_Type
(P_Base_Type
)
8563 if Is_Scalar_Type
(P_Type
) then
8564 if not Is_Static_Subtype
(P_Type
) then
8566 Set_Is_Static_Expression
(N
, False);
8567 elsif not Is_OK_Static_Subtype
(P_Type
) then
8568 Set_Raises_Constraint_Error
(N
);
8571 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
8572 -- since we can't do anything with unconstrained arrays. In addition,
8573 -- only the First, Last and Length attributes are possibly static.
8575 -- Atomic_Always_Lock_Free, Definite, Descriptor_Size, Has_Access_Values
8576 -- Has_Discriminants, Has_Tagged_Values, Type_Class, and
8577 -- Unconstrained_Array are again exceptions, because they apply as well
8578 -- to unconstrained types.
8580 -- In addition Component_Size is an exception since it is possibly
8581 -- foldable, even though it is never static, and it does apply to
8582 -- unconstrained arrays. Furthermore, it is essential to fold this
8583 -- in the packed case, since otherwise the value will be incorrect.
8585 -- Folding can also be done for Preelaborable_Initialization based on
8586 -- whether the prefix type has preelaborable initialization, even though
8587 -- the attribute is nonstatic.
8589 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
8590 Id
= Attribute_Definite
or else
8591 Id
= Attribute_Descriptor_Size
or else
8592 Id
= Attribute_Has_Access_Values
or else
8593 Id
= Attribute_Has_Discriminants
or else
8594 Id
= Attribute_Has_Tagged_Values
or else
8595 Id
= Attribute_Preelaborable_Initialization
or else
8596 Id
= Attribute_Type_Class
or else
8597 Id
= Attribute_Unconstrained_Array
or else
8598 Id
= Attribute_Component_Size
8601 Set_Is_Static_Expression
(N
, False);
8603 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
8604 if not Is_Constrained
(P_Type
)
8605 or else (Id
/= Attribute_First
and then
8606 Id
/= Attribute_Last
and then
8607 Id
/= Attribute_Length
)
8613 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
8614 -- scalar case, we hold off on enforcing staticness, since there are
8615 -- cases which we can fold at compile time even though they are not
8616 -- static (e.g. 'Length applied to a static index, even though other
8617 -- non-static indexes make the array type non-static). This is only
8618 -- an optimization, but it falls out essentially free, so why not.
8619 -- Again we compute the variable Static for easy reference later
8620 -- (note that no array attributes are static in Ada 83).
8622 -- We also need to set Static properly for subsequent legality checks
8623 -- which might otherwise accept non-static constants in contexts
8624 -- where they are not legal.
8627 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
8628 Set_Is_Static_Expression
(N
, Static
);
8634 Nod
:= First_Index
(P_Type
);
8636 -- The expression is static if the array type is constrained
8637 -- by given bounds, and not by an initial expression. Constant
8638 -- strings are static in any case.
8640 if Root_Type
(P_Type
) /= Standard_String
then
8642 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
8643 Set_Is_Static_Expression
(N
, Static
);
8646 while Present
(Nod
) loop
8647 if not Is_Static_Subtype
(Etype
(Nod
)) then
8649 Set_Is_Static_Expression
(N
, False);
8651 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
8652 Set_Raises_Constraint_Error
(N
);
8654 Set_Is_Static_Expression
(N
, False);
8657 -- If however the index type is generic, or derived from
8658 -- one, attributes cannot be folded.
8660 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
8661 and then Id
/= Attribute_Component_Size
8671 -- Check any expressions that are present. Note that these expressions,
8672 -- depending on the particular attribute type, are either part of the
8673 -- attribute designator, or they are arguments in a case where the
8674 -- attribute reference returns a function. In the latter case, the
8675 -- rule in (RM 4.9(22)) applies and in particular requires the type
8676 -- of the expressions to be scalar in order for the attribute to be
8677 -- considered to be static.
8685 while Present
(E
) loop
8687 -- If expression is not static, then the attribute reference
8688 -- result certainly cannot be static.
8690 if not Is_Static_Expression
(E
) then
8692 Set_Is_Static_Expression
(N
, False);
8695 if Raises_Constraint_Error
(E
) then
8696 Set_Raises_Constraint_Error
(N
);
8699 -- If the result is not known at compile time, or is not of
8700 -- a scalar type, then the result is definitely not static,
8701 -- so we can quit now.
8703 if not Compile_Time_Known_Value
(E
)
8704 or else not Is_Scalar_Type
(Etype
(E
))
8709 -- If the expression raises a constraint error, then so does
8710 -- the attribute reference. We keep going in this case because
8711 -- we are still interested in whether the attribute reference
8712 -- is static even if it is not static.
8714 elsif Raises_Constraint_Error
(E
) then
8715 Set_Raises_Constraint_Error
(N
);
8721 if Raises_Constraint_Error
(Prefix
(N
)) then
8722 Set_Is_Static_Expression
(N
, False);
8727 -- Deal with the case of a static attribute reference that raises
8728 -- constraint error. The Raises_Constraint_Error flag will already
8729 -- have been set, and the Static flag shows whether the attribute
8730 -- reference is static. In any case we certainly can't fold such an
8731 -- attribute reference.
8733 -- Note that the rewriting of the attribute node with the constraint
8734 -- error node is essential in this case, because otherwise Gigi might
8735 -- blow up on one of the attributes it never expects to see.
8737 -- The constraint_error node must have the type imposed by the context,
8738 -- to avoid spurious errors in the enclosing expression.
8740 if Raises_Constraint_Error
(N
) then
8742 Make_Raise_Constraint_Error
(Sloc
(N
),
8743 Reason
=> CE_Range_Check_Failed
);
8744 Set_Etype
(CE_Node
, Etype
(N
));
8745 Set_Raises_Constraint_Error
(CE_Node
);
8747 Rewrite
(N
, Relocate_Node
(CE_Node
));
8748 Set_Raises_Constraint_Error
(N
, True);
8752 -- At this point we have a potentially foldable attribute reference.
8753 -- If Static is set, then the attribute reference definitely obeys
8754 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8755 -- folded. If Static is not set, then the attribute may or may not
8756 -- be foldable, and the individual attribute processing routines
8757 -- test Static as required in cases where it makes a difference.
8759 -- In the case where Static is not set, we do know that all the
8760 -- expressions present are at least known at compile time (we assumed
8761 -- above that if this was not the case, then there was no hope of static
8762 -- evaluation). However, we did not require that the bounds of the
8763 -- prefix type be compile time known, let alone static). That's because
8764 -- there are many attributes that can be computed at compile time on
8765 -- non-static subtypes, even though such references are not static
8768 -- For VAX float, the root type is an IEEE type. So make sure to use the
8769 -- base type instead of the root-type for floating point attributes.
8773 -- Attributes related to Ada 2012 iterators; nothing to evaluate for
8776 when Attribute_Constant_Indexing
8777 | Attribute_Default_Iterator
8778 | Attribute_Implicit_Dereference
8779 | Attribute_Iterator_Element
8780 | Attribute_Iterable
8782 | Attribute_Variable_Indexing
8786 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8787 -- These were already rejected by the parser. Thus they shouldn't
8790 when Internal_Attribute_Id
=>
8791 raise Program_Error
;
8797 when Attribute_Adjacent
=>
8801 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8808 when Attribute_Aft
=>
8809 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8815 when Attribute_Alignment
=> Alignment_Block
: declare
8816 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8819 -- Fold if alignment is set and not otherwise
8821 if Known_Alignment
(P_TypeA
) then
8822 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8824 end Alignment_Block
;
8826 -----------------------------
8827 -- Atomic_Always_Lock_Free --
8828 -----------------------------
8830 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8833 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8835 V
: constant Entity_Id
:=
8837 (Support_Atomic_Primitives_On_Target
8838 and then Support_Atomic_Primitives
(P_Type
));
8841 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8843 -- Analyze and resolve as boolean. Note that this attribute is a
8844 -- static attribute in GNAT.
8846 Analyze_And_Resolve
(N
, Standard_Boolean
);
8848 Set_Is_Static_Expression
(N
);
8849 end Atomic_Always_Lock_Free
;
8855 -- Bit can never be folded
8857 when Attribute_Bit
=>
8864 -- Body_version can never be static
8866 when Attribute_Body_Version
=>
8873 when Attribute_Ceiling
=>
8875 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8877 --------------------
8878 -- Component_Size --
8879 --------------------
8881 -- Fold Component_Size if it is known at compile time, which is always
8882 -- true in the packed array case. It is important that the packed array
8883 -- case is handled here since the back end would otherwise get confused
8884 -- by the equivalent packed array type.
8886 when Attribute_Component_Size
=>
8887 if Known_Static_Component_Size
(P_Type
) then
8888 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
8895 when Attribute_Compose
=>
8898 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8905 -- Constrained is never folded for now, there may be cases that
8906 -- could be handled at compile time. To be looked at later.
8908 when Attribute_Constrained
=>
8910 -- The expander might fold it and set the static flag accordingly,
8911 -- but with expansion disabled, it remains as an attribute reference,
8912 -- and this reference is not static.
8914 Set_Is_Static_Expression
(N
, False);
8920 when Attribute_Copy_Sign
=>
8924 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8931 when Attribute_Definite
=>
8932 Rewrite
(N
, New_Occurrence_Of
(
8933 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
8934 Analyze_And_Resolve
(N
, Standard_Boolean
);
8940 when Attribute_Delta
=>
8941 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
8947 when Attribute_Denorm
=>
8949 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
8951 ---------------------
8952 -- Descriptor_Size --
8953 ---------------------
8955 -- Descriptor_Size is nonnull only for unconstrained array types
8957 when Attribute_Descriptor_Size
=>
8958 if not Is_Array_Type
(P_Type
) or else Is_Constrained
(P_Type
) then
8959 Fold_Uint
(N
, Uint_0
, Static
);
8966 when Attribute_Digits
=>
8967 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
8973 when Attribute_Emax
=>
8975 -- Ada 83 attribute is defined as (RM83 3.5.8)
8977 -- T'Emax = 4 * T'Mantissa
8979 Fold_Uint
(N
, 4 * Mantissa
, Static
);
8985 when Attribute_Enum_Rep
=> Enum_Rep
: declare
8989 -- The attribute appears in the form:
8991 -- Enum_Typ'Enum_Rep (Const)
8992 -- Enum_Typ'Enum_Rep (Enum_Lit)
8994 if Present
(E1
) then
8997 -- Otherwise the prefix denotes a constant or enumeration literal:
9000 -- Enum_Lit'Enum_Rep
9006 -- For an enumeration type with a non-standard representation use
9007 -- the Enumeration_Rep field of the proper constant. Note that this
9008 -- will not work for types Character/Wide_[Wide-]Character, since no
9009 -- real entities are created for the enumeration literals, but that
9010 -- does not matter since these two types do not have non-standard
9011 -- representations anyway.
9013 if Is_Enumeration_Type
(P_Type
)
9014 and then Has_Non_Standard_Rep
(P_Type
)
9016 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
9018 -- For enumeration types with standard representations and all other
9019 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
9023 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
9031 when Attribute_Enum_Val
=> Enum_Val
: declare
9035 -- We have something like Enum_Type'Enum_Val (23), so search for a
9036 -- corresponding value in the list of Enum_Rep values for the type.
9038 Lit
:= First_Literal
(P_Base_Type
);
9040 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
9041 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
9048 Apply_Compile_Time_Constraint_Error
9049 (N
, "no representation value matches",
9050 CE_Range_Check_Failed
,
9051 Warn
=> not Static
);
9061 when Attribute_Epsilon
=>
9063 -- Ada 83 attribute is defined as (RM83 3.5.8)
9065 -- T'Epsilon = 2.0**(1 - T'Mantissa)
9067 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
9073 when Attribute_Exponent
=>
9075 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9077 -----------------------
9078 -- Finalization_Size --
9079 -----------------------
9081 when Attribute_Finalization_Size
=>
9088 when Attribute_First
=>
9091 if Compile_Time_Known_Value
(Lo_Bound
) then
9092 if Is_Real_Type
(P_Type
) then
9093 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
9095 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9099 Check_Concurrent_Discriminant
(Lo_Bound
);
9106 when Attribute_First_Valid
=>
9107 if Has_Predicates
(P_Type
)
9108 and then Has_Static_Predicate
(P_Type
)
9111 FirstN
: constant Node_Id
:=
9112 First
(Static_Discrete_Predicate
(P_Type
));
9114 if Nkind
(FirstN
) = N_Range
then
9115 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
9117 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
9123 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
9130 when Attribute_Fixed_Value
=>
9137 when Attribute_Floor
=>
9139 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9145 when Attribute_Fore
=>
9146 if Compile_Time_Known_Bounds
(P_Type
) then
9147 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
9154 when Attribute_Fraction
=>
9156 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9158 -----------------------
9159 -- Has_Access_Values --
9160 -----------------------
9162 when Attribute_Has_Access_Values
=>
9163 Rewrite
(N
, New_Occurrence_Of
9164 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
9165 Analyze_And_Resolve
(N
, Standard_Boolean
);
9167 -----------------------
9168 -- Has_Discriminants --
9169 -----------------------
9171 when Attribute_Has_Discriminants
=>
9172 Rewrite
(N
, New_Occurrence_Of
(
9173 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
9174 Analyze_And_Resolve
(N
, Standard_Boolean
);
9176 ----------------------
9177 -- Has_Same_Storage --
9178 ----------------------
9180 when Attribute_Has_Same_Storage
=>
9183 -----------------------
9184 -- Has_Tagged_Values --
9185 -----------------------
9187 when Attribute_Has_Tagged_Values
=>
9188 Rewrite
(N
, New_Occurrence_Of
9189 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
9190 Analyze_And_Resolve
(N
, Standard_Boolean
);
9196 when Attribute_Identity
=>
9203 -- Image is a scalar attribute, but is never static, because it is
9204 -- not a static function (having a non-scalar argument (RM 4.9(22))
9205 -- However, we can constant-fold the image of an enumeration literal
9206 -- if names are available.
9208 when Attribute_Image
=>
9209 if Is_Entity_Name
(E1
)
9210 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
9211 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
9212 and then not Global_Discard_Names
9215 Lit
: constant Entity_Id
:= Entity
(E1
);
9219 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
9220 Set_Casing
(All_Upper_Case
);
9221 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
9223 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
9224 Analyze_And_Resolve
(N
, Standard_String
);
9225 Set_Is_Static_Expression
(N
, False);
9233 -- We never try to fold Integer_Value (though perhaps we could???)
9235 when Attribute_Integer_Value
=>
9242 -- Invalid_Value is a scalar attribute that is never static, because
9243 -- the value is by design out of range.
9245 when Attribute_Invalid_Value
=>
9252 when Attribute_Large
=>
9254 -- For fixed-point, we use the identity:
9256 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
9258 if Is_Fixed_Point_Type
(P_Type
) then
9260 Make_Op_Multiply
(Loc
,
9262 Make_Op_Subtract
(Loc
,
9266 Make_Real_Literal
(Loc
, Ureal_2
),
9268 Make_Attribute_Reference
(Loc
,
9270 Attribute_Name
=> Name_Mantissa
)),
9271 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
9274 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
9276 Analyze_And_Resolve
(N
, C_Type
);
9278 -- Floating-point (Ada 83 compatibility)
9281 -- Ada 83 attribute is defined as (RM83 3.5.8)
9283 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
9287 -- T'Emax = 4 * T'Mantissa
9291 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
9299 when Attribute_Last
=>
9302 if Compile_Time_Known_Value
(Hi_Bound
) then
9303 if Is_Real_Type
(P_Type
) then
9304 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
9306 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9310 Check_Concurrent_Discriminant
(Hi_Bound
);
9317 when Attribute_Last_Valid
=>
9318 if Has_Predicates
(P_Type
)
9319 and then Has_Static_Predicate
(P_Type
)
9322 LastN
: constant Node_Id
:=
9323 Last
(Static_Discrete_Predicate
(P_Type
));
9325 if Nkind
(LastN
) = N_Range
then
9326 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
9328 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
9334 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
9341 when Attribute_Leading_Part
=> Leading_Part
: declare
9342 Radix_Digits
: constant Uint
:= Expr_Value
(E2
);
9345 if UI_Le
(Radix_Digits
, Uint_0
) then
9346 Apply_Compile_Time_Constraint_Error
9347 (N
, "Radix_Digits in Leading_Part is zero or negative",
9349 Warn
=> not Static
);
9357 Eval_Fat
.Leading_Part
9358 (P_Base_Type
, Expr_Value_R
(E1
), Radix_Digits
),
9366 when Attribute_Length
=> Length
: declare
9370 -- If any index type is a formal type, or derived from one, the
9371 -- bounds are not static. Treating them as static can produce
9372 -- spurious warnings or improper constant folding.
9374 Ind
:= First_Index
(P_Type
);
9375 while Present
(Ind
) loop
9376 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
9385 -- For two compile time values, we can compute length
9387 if Compile_Time_Known_Value
(Lo_Bound
)
9388 and then Compile_Time_Known_Value
(Hi_Bound
)
9391 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
9395 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9396 -- comparable, and we can figure out the difference between them.
9399 Diff
: aliased Uint
;
9403 Compile_Time_Compare
9404 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9407 Fold_Uint
(N
, Uint_1
, Static
);
9410 Fold_Uint
(N
, Uint_0
, Static
);
9413 if Present
(Diff
) then
9414 Fold_Uint
(N
, Diff
+ 1, Static
);
9427 -- Loop_Entry acts as an alias of a constant initialized to the prefix
9428 -- of the said attribute at the point of entry into the related loop. As
9429 -- such, the attribute reference does not need to be evaluated because
9430 -- the prefix is the one that is evaluted.
9432 when Attribute_Loop_Entry
=>
9439 -- We use the same rounding as the one used for RM 4.9(38/2)
9441 when Attribute_Machine
=>
9443 (N
, Machine_Number
(P_Base_Type
, Expr_Value_R
(E1
), N
), Static
);
9444 Set_Is_Machine_Number
(N
);
9450 when Attribute_Machine_Emax
=>
9451 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
9457 when Attribute_Machine_Emin
=>
9458 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
9460 ----------------------
9461 -- Machine_Mantissa --
9462 ----------------------
9464 when Attribute_Machine_Mantissa
=>
9465 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
9467 -----------------------
9468 -- Machine_Overflows --
9469 -----------------------
9471 when Attribute_Machine_Overflows
=>
9473 -- Always true for fixed-point
9475 if Is_Fixed_Point_Type
(P_Type
) then
9476 Fold_Uint
(N
, True_Value
, Static
);
9478 -- Floating point case
9482 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
9490 when Attribute_Machine_Radix
=>
9491 if Is_Fixed_Point_Type
(P_Type
) then
9492 if Is_Decimal_Fixed_Point_Type
(P_Type
)
9493 and then Machine_Radix_10
(P_Type
)
9495 Fold_Uint
(N
, Uint_10
, Static
);
9497 Fold_Uint
(N
, Uint_2
, Static
);
9500 -- All floating-point type always have radix 2
9503 Fold_Uint
(N
, Uint_2
, Static
);
9506 ----------------------
9507 -- Machine_Rounding --
9508 ----------------------
9510 -- Note: for the folding case, it is fine to treat Machine_Rounding
9511 -- exactly the same way as Rounding, since this is one of the allowed
9512 -- behaviors, and performance is not an issue here. It might be a bit
9513 -- better to give the same result as it would give at run time, even
9514 -- though the non-determinism is certainly permitted.
9516 when Attribute_Machine_Rounding
=>
9518 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9520 --------------------
9521 -- Machine_Rounds --
9522 --------------------
9524 when Attribute_Machine_Rounds
=>
9526 -- Always False for fixed-point
9528 if Is_Fixed_Point_Type
(P_Type
) then
9529 Fold_Uint
(N
, False_Value
, Static
);
9531 -- Else yield proper floating-point result
9535 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
9543 -- Note: Machine_Size is identical to Object_Size
9545 when Attribute_Machine_Size
=> Machine_Size
: declare
9546 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9549 if Known_Esize
(P_TypeA
) then
9550 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9558 when Attribute_Mantissa
=>
9560 -- Fixed-point mantissa
9562 if Is_Fixed_Point_Type
(P_Type
) then
9564 -- Compile time foldable case
9566 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
9568 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
9570 -- The calculation of the obsolete Ada 83 attribute Mantissa
9571 -- is annoying, because of AI00143, quoted here:
9573 -- !question 84-01-10
9575 -- Consider the model numbers for F:
9577 -- type F is delta 1.0 range -7.0 .. 8.0;
9579 -- The wording requires that F'MANTISSA be the SMALLEST
9580 -- integer number for which each bound of the specified
9581 -- range is either a model number or lies at most small
9582 -- distant from a model number. This means F'MANTISSA
9583 -- is required to be 3 since the range -7.0 .. 7.0 fits
9584 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
9585 -- number, namely, 7. Is this analysis correct? Note that
9586 -- this implies the upper bound of the range is not
9587 -- represented as a model number.
9589 -- !response 84-03-17
9591 -- The analysis is correct. The upper and lower bounds for
9592 -- a fixed point type can lie outside the range of model
9603 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
9604 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
9605 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
9606 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
9608 -- If the Bound is exactly a model number, i.e. a multiple
9609 -- of Small, then we back it off by one to get the integer
9610 -- value that must be representable.
9612 if Small_Value
(P_Type
) * Max_Man
= Bound
then
9613 Max_Man
:= Max_Man
- 1;
9616 -- Now find corresponding size = Mantissa value
9619 while 2 ** Siz
< Max_Man
loop
9623 Fold_Uint
(N
, Siz
, Static
);
9627 -- The case of dynamic bounds cannot be evaluated at compile
9628 -- time. Instead we use a runtime routine (see Exp_Attr).
9633 -- Floating-point Mantissa
9636 Fold_Uint
(N
, Mantissa
, Static
);
9643 when Attribute_Max
=>
9644 if Is_Real_Type
(P_Type
) then
9646 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9648 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9651 ----------------------------------
9652 -- Max_Alignment_For_Allocation --
9653 ----------------------------------
9655 -- Max_Alignment_For_Allocation is usually the Alignment. However,
9656 -- arrays are allocated with dope, so we need to take into account both
9657 -- the alignment of the array, which comes from the component alignment,
9658 -- and the alignment of the dope. Also, if the alignment is unknown, we
9659 -- use the max (it's OK to be pessimistic).
9661 when Attribute_Max_Alignment_For_Allocation
=> Max_Align
: declare
9662 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
9664 if Known_Alignment
(P_Type
)
9665 and then (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
9667 A
:= Alignment
(P_Type
);
9670 Fold_Uint
(N
, A
, Static
);
9673 ----------------------------------
9674 -- Max_Size_In_Storage_Elements --
9675 ----------------------------------
9677 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9678 -- Storage_Unit boundary. We can fold any cases for which the size
9679 -- is known by the front end.
9681 when Attribute_Max_Size_In_Storage_Elements
=>
9682 if Known_Esize
(P_Type
) then
9684 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9685 System_Storage_Unit
,
9689 --------------------
9690 -- Mechanism_Code --
9691 --------------------
9693 when Attribute_Mechanism_Code
=> Mechanism_Code
: declare
9695 Mech
: Mechanism_Type
;
9700 Mech
:= Mechanism
(P_Entity
);
9703 Val
:= UI_To_Int
(Expr_Value
(E1
));
9705 Formal
:= First_Formal
(P_Entity
);
9706 for J
in 1 .. Val
- 1 loop
9707 Next_Formal
(Formal
);
9710 Mech
:= Mechanism
(Formal
);
9714 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9722 when Attribute_Min
=>
9723 if Is_Real_Type
(P_Type
) then
9725 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9728 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9735 when Attribute_Mod
=>
9737 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9743 when Attribute_Model
=>
9745 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9751 when Attribute_Model_Emin
=>
9752 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9758 when Attribute_Model_Epsilon
=>
9759 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9761 --------------------
9762 -- Model_Mantissa --
9763 --------------------
9765 when Attribute_Model_Mantissa
=>
9766 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9772 when Attribute_Model_Small
=>
9773 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9779 when Attribute_Modulus
=>
9780 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9782 --------------------
9783 -- Null_Parameter --
9784 --------------------
9786 -- Cannot fold, we know the value sort of, but the whole point is
9787 -- that there is no way to talk about this imaginary value except
9788 -- by using the attribute, so we leave it the way it is.
9790 when Attribute_Null_Parameter
=>
9797 -- The Object_Size attribute for a type returns the Esize of the
9798 -- type and can be folded if this value is known.
9800 when Attribute_Object_Size
=> Object_Size
: declare
9801 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9804 if Known_Esize
(P_TypeA
) then
9805 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9809 ----------------------
9810 -- Overlaps_Storage --
9811 ----------------------
9813 when Attribute_Overlaps_Storage
=>
9816 -------------------------
9817 -- Passed_By_Reference --
9818 -------------------------
9820 -- Scalar types are never passed by reference
9822 when Attribute_Passed_By_Reference
=>
9823 Fold_Uint
(N
, False_Value
, Static
);
9829 when Attribute_Pos
=>
9830 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9836 when Attribute_Pred
=>
9838 -- Floating-point case
9840 if Is_Floating_Point_Type
(P_Type
) then
9842 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9846 elsif Is_Fixed_Point_Type
(P_Type
) then
9848 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9850 -- Modular integer case (wraps)
9852 elsif Is_Modular_Integer_Type
(P_Type
) then
9853 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
9855 -- Other scalar cases
9858 pragma Assert
(Is_Scalar_Type
(P_Type
));
9860 if Is_Enumeration_Type
(P_Type
)
9861 and then Expr_Value
(E1
) =
9862 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9864 Apply_Compile_Time_Constraint_Error
9865 (N
, "Pred of `&''First`",
9866 CE_Overflow_Check_Failed
,
9868 Warn
=> not Static
);
9873 -- Rewrite the FE-constructed high bound of a null array
9874 -- aggregate to raise CE.
9876 elsif Is_Signed_Integer_Type
(P_Type
)
9877 and then Expr_Value
(E1
) =
9878 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9879 and then Is_Null_Array_Aggregate_High_Bound
(N
)
9881 Apply_Compile_Time_Constraint_Error
9882 (N
, "Pred of `&''First`",
9883 CE_Overflow_Check_Failed
,
9887 Rewrite
(N
, Make_Raise_Constraint_Error
(Sloc
(N
),
9888 Reason
=> CE_Overflow_Check_Failed
));
9889 Set_Etype
(N
, P_Base_Type
);
9893 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
9896 ----------------------------------
9897 -- Preelaborable_Initialization --
9898 ----------------------------------
9900 when Attribute_Preelaborable_Initialization
=>
9904 (Boolean'Pos (Has_Preelaborable_Initialization
(P_Type
))),
9911 -- No processing required, because by this stage, Range has been
9912 -- replaced by First .. Last, so this branch can never be taken.
9914 when Attribute_Range
=>
9915 raise Program_Error
;
9921 when Attribute_Range_Length
=> Range_Length
: declare
9922 Diff
: aliased Uint
;
9927 -- Can fold if both bounds are compile time known
9929 if Compile_Time_Known_Value
(Hi_Bound
)
9930 and then Compile_Time_Known_Value
(Lo_Bound
)
9934 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
9938 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9939 -- comparable, and we can figure out the difference between them.
9941 case Compile_Time_Compare
9942 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9945 Fold_Uint
(N
, Uint_1
, Static
);
9948 Fold_Uint
(N
, Uint_0
, Static
);
9951 if Present
(Diff
) then
9952 Fold_Uint
(N
, Diff
+ 1, Static
);
9964 when Attribute_Ref
=>
9965 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9971 when Attribute_Remainder
=> Remainder
: declare
9972 X
: constant Ureal
:= Expr_Value_R
(E1
);
9973 Y
: constant Ureal
:= Expr_Value_R
(E2
);
9976 if UR_Is_Zero
(Y
) then
9977 Apply_Compile_Time_Constraint_Error
9978 (N
, "division by zero in Remainder",
9979 CE_Overflow_Check_Failed
,
9980 Warn
=> not Static
);
9986 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
9993 when Attribute_Restriction_Set
=>
9994 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
9995 Set_Is_Static_Expression
(N
);
10001 when Attribute_Round
=> Round
: declare
10006 -- First we get the (exact result) in units of small
10008 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
10010 -- Now round that exactly to an integer
10012 Si
:= UR_To_Uint
(Sr
);
10014 -- Finally the result is obtained by converting back to real
10016 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
10023 when Attribute_Rounding
=>
10025 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10031 when Attribute_Safe_Emax
=>
10032 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
10038 when Attribute_Safe_First
=>
10039 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
10045 when Attribute_Safe_Large
=>
10046 if Is_Fixed_Point_Type
(P_Type
) then
10048 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
10050 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10057 when Attribute_Safe_Last
=>
10058 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
10064 when Attribute_Safe_Small
=>
10066 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
10067 -- for fixed-point, since is the same as Small, but we implement
10068 -- it for backwards compatibility.
10070 if Is_Fixed_Point_Type
(P_Type
) then
10071 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
10073 -- Ada 83 Safe_Small for floating-point cases
10076 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
10083 when Attribute_Scale
=>
10084 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
10090 when Attribute_Scaling
=>
10094 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
10101 when Attribute_Signed_Zeros
=>
10103 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
10109 -- Size attribute returns the RM size. All scalar types can be folded,
10110 -- as well as any types for which the size is known by the front end,
10111 -- including any type for which a size attribute is specified. This is
10112 -- one of the places where it is annoying that a size of zero means two
10113 -- things (zero size for scalars, unspecified size for non-scalars).
10115 when Attribute_Size
10116 | Attribute_VADS_Size
10119 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10123 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10124 if Known_RM_Size
(P_TypeA
) then
10127 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
10129 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
10132 -- If a size clause applies, then use the size from it.
10133 -- This is one of the rare cases where we can use the
10134 -- Size_Clause field for a subtype when Has_Size_Clause
10135 -- is False. Consider:
10137 -- type x is range 1 .. 64;
10138 -- for x'size use 12;
10139 -- subtype y is x range 0 .. 3;
10141 -- Here y has a size clause inherited from x, but
10142 -- normally it does not apply, and y'size is 2. However,
10143 -- y'VADS_Size is indeed 12 and not 2.
10146 and then Is_OK_Static_Expression
(Expression
(S
))
10148 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
10150 -- If no size is specified, then we simply use the object
10151 -- size in the VADS_Size case (e.g. Natural'Size is equal
10152 -- to Integer'Size, not one less).
10155 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
10159 -- Normal case (Size) in which case we want the RM_Size
10162 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10171 when Attribute_Small
=>
10173 -- The floating-point case is present only for Ada 83 compatibility.
10174 -- Note that strictly this is an illegal addition, since we are
10175 -- extending an Ada 95 defined attribute, but we anticipate an
10176 -- ARG ruling that will permit this.
10178 if Is_Floating_Point_Type
(P_Type
) then
10180 -- Ada 83 attribute is defined as (RM83 3.5.8)
10182 -- T'Small = 2.0**(-T'Emax - 1)
10186 -- T'Emax = 4 * T'Mantissa
10188 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
10190 -- Normal Ada 95 fixed-point case
10193 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
10196 -----------------------
10197 -- Small_Denominator --
10198 -----------------------
10200 when Attribute_Small_Denominator
=>
10201 Fold_Uint
(N
, Norm_Den
(Small_Value
(P_Type
)), True);
10203 ---------------------
10204 -- Small_Numerator --
10205 ---------------------
10207 when Attribute_Small_Numerator
=>
10208 Fold_Uint
(N
, Norm_Num
(Small_Value
(P_Type
)), True);
10214 when Attribute_Stream_Size
=>
10221 when Attribute_Succ
=>
10222 -- Floating-point case
10224 if Is_Floating_Point_Type
(P_Type
) then
10226 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
10228 -- Fixed-point case
10230 elsif Is_Fixed_Point_Type
(P_Type
) then
10231 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
10233 -- Modular integer case (wraps)
10235 elsif Is_Modular_Integer_Type
(P_Type
) then
10236 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
10238 -- Other scalar cases
10241 pragma Assert
(Is_Scalar_Type
(P_Type
));
10243 if Is_Enumeration_Type
(P_Type
)
10244 and then Expr_Value
(E1
) =
10245 Expr_Value
(Type_High_Bound
(P_Base_Type
))
10247 Apply_Compile_Time_Constraint_Error
10248 (N
, "Succ of `&''Last`",
10249 CE_Overflow_Check_Failed
,
10250 Ent
=> P_Base_Type
,
10251 Warn
=> not Static
);
10256 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
10264 when Attribute_Truncation
=>
10267 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
10274 when Attribute_Type_Class
=> Type_Class
: declare
10275 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
10279 if Is_Descendant_Of_Address
(Typ
) then
10280 Id
:= RE_Type_Class_Address
;
10282 elsif Is_Enumeration_Type
(Typ
) then
10283 Id
:= RE_Type_Class_Enumeration
;
10285 elsif Is_Integer_Type
(Typ
) then
10286 Id
:= RE_Type_Class_Integer
;
10288 elsif Is_Fixed_Point_Type
(Typ
) then
10289 Id
:= RE_Type_Class_Fixed_Point
;
10291 elsif Is_Floating_Point_Type
(Typ
) then
10292 Id
:= RE_Type_Class_Floating_Point
;
10294 elsif Is_Array_Type
(Typ
) then
10295 Id
:= RE_Type_Class_Array
;
10297 elsif Is_Record_Type
(Typ
) then
10298 Id
:= RE_Type_Class_Record
;
10300 elsif Is_Access_Type
(Typ
) then
10301 Id
:= RE_Type_Class_Access
;
10303 elsif Is_Task_Type
(Typ
) then
10304 Id
:= RE_Type_Class_Task
;
10306 -- We treat protected types like task types. It would make more
10307 -- sense to have another enumeration value, but after all the
10308 -- whole point of this feature is to be exactly DEC compatible,
10309 -- and changing the type Type_Class would not meet this requirement.
10311 elsif Is_Protected_Type
(Typ
) then
10312 Id
:= RE_Type_Class_Task
;
10314 -- Not clear if there are any other possibilities, but if there
10315 -- are, then we will treat them as the address case.
10318 Id
:= RE_Type_Class_Address
;
10321 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
10324 -----------------------
10325 -- Unbiased_Rounding --
10326 -----------------------
10328 when Attribute_Unbiased_Rounding
=>
10331 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
10334 -------------------------
10335 -- Unconstrained_Array --
10336 -------------------------
10338 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
10339 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10342 Rewrite
(N
, New_Occurrence_Of
(
10344 Is_Array_Type
(P_Type
)
10345 and then not Is_Constrained
(Typ
)), Loc
));
10347 -- Analyze and resolve as boolean, note that this attribute is
10348 -- a static attribute in GNAT.
10350 Analyze_And_Resolve
(N
, Standard_Boolean
);
10352 Set_Is_Static_Expression
(N
, True);
10353 end Unconstrained_Array
;
10355 -- Attribute Update is never static
10357 when Attribute_Update
=>
10364 -- Processing is shared with Size
10370 when Attribute_Val
=>
10371 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
10373 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
10375 Apply_Compile_Time_Constraint_Error
10376 (N
, "Val expression out of range",
10377 CE_Range_Check_Failed
,
10378 Warn
=> not Static
);
10384 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
10391 -- The Value_Size attribute for a type returns the RM size of the type.
10392 -- This an always be folded for scalar types, and can also be folded for
10393 -- non-scalar types if the size is set. This is one of the places where
10394 -- it is annoying that a size of zero means two things!
10396 when Attribute_Value_Size
=> Value_Size
: declare
10397 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
10401 (if Is_Scalar_Type
(P_TypeA
) then Known_RM_Size
(P_TypeA
));
10402 if Known_RM_Size
(P_TypeA
) then
10403 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
10411 -- Version can never be static
10413 when Attribute_Version
=>
10420 -- Wide_Image is a scalar attribute, but is never static, because it
10421 -- is not a static function (having a non-scalar argument (RM 4.9(22))
10423 when Attribute_Wide_Image
=>
10426 ---------------------
10427 -- Wide_Wide_Image --
10428 ---------------------
10430 -- Wide_Wide_Image is a scalar attribute but is never static, because it
10431 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
10433 when Attribute_Wide_Wide_Image
=>
10436 ---------------------
10437 -- Wide_Wide_Width --
10438 ---------------------
10440 -- Processing for Wide_Wide_Width is combined with Width
10446 -- Processing for Wide_Width is combined with Width
10452 -- This processing also handles the case of Wide_[Wide_]Width
10454 when Attribute_Width
10455 | Attribute_Wide_Width
10456 | Attribute_Wide_Wide_Width
10458 if Compile_Time_Known_Bounds
(P_Type
) then
10460 -- Floating-point types
10462 if Is_Floating_Point_Type
(P_Type
) then
10464 -- Width is zero for a null range (RM 3.5 (38))
10466 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
10467 Expr_Value_R
(Type_Low_Bound
(P_Type
))
10469 Fold_Uint
(N
, Uint_0
, Static
);
10472 -- For floating-point, we have +N.dddE+nnn where length
10473 -- of ddd is determined by type'Digits - 1, but is one
10474 -- if Digits is one (RM 3.5 (33)).
10476 -- nnn is set to 2 for Short_Float and Float (32 bit
10477 -- floats), and 3 for Long_Float and Long_Long_Float.
10478 -- For machines where Long_Long_Float is the IEEE
10479 -- extended precision type, the exponent takes 4 digits.
10483 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
10486 if Esize
(P_Type
) <= 32 then
10488 elsif Esize
(P_Type
) = 64 then
10494 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
10498 -- Fixed-point types
10500 elsif Is_Fixed_Point_Type
(P_Type
) then
10502 -- Width is zero for a null range (RM 3.5 (38))
10504 if Expr_Value
(Type_High_Bound
(P_Type
)) <
10505 Expr_Value
(Type_Low_Bound
(P_Type
))
10507 Fold_Uint
(N
, Uint_0
, Static
);
10509 -- The non-null case depends on the specific real type
10512 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
10515 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
10523 R
: constant Entity_Id
:= Root_Type
(P_Type
);
10524 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
10525 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
10538 -- Width for types derived from Standard.Character
10539 -- and Standard.Wide_[Wide_]Character.
10541 elsif Is_Standard_Character_Type
(P_Type
) then
10544 -- Set W larger if needed
10546 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
10548 -- All wide characters look like Hex_hhhhhhhh
10552 -- No need to compute this more than once
10557 C
:= Character'Val (J
);
10559 -- Test for all cases where Character'Image
10560 -- yields an image that is longer than three
10561 -- characters. First the cases of Reserved_xxx
10562 -- names (length = 12).
10639 when Space
.. Tilde
10640 | No_Break_Space
.. LC_Y_Diaeresis
10642 -- Special case of soft hyphen in Ada 2005
10644 if C
= Character'Val (16#AD#
)
10645 and then Ada_Version
>= Ada_2005
10653 W
:= Int
'Max (W
, Wt
);
10657 -- Width for types derived from Standard.Boolean
10659 elsif R
= Standard_Boolean
then
10666 -- Width for integer types
10668 elsif Is_Integer_Type
(P_Type
) then
10669 T
:= UI_Max
(abs Lo
, abs Hi
);
10677 -- User declared enum type with discard names
10679 elsif Discard_Names
(R
) then
10681 -- If range is null, result is zero, that has already
10682 -- been dealt with, so what we need is the power of ten
10683 -- that accommodates the Pos of the largest value, which
10684 -- is the high bound of the range + one for the space.
10693 -- Only remaining possibility is user declared enum type
10694 -- with normal case of Discard_Names not active.
10697 pragma Assert
(Is_Enumeration_Type
(P_Type
));
10700 L
:= First_Literal
(P_Type
);
10701 while Present
(L
) loop
10703 -- Only pay attention to in range characters
10705 if Lo
<= Enumeration_Pos
(L
)
10706 and then Enumeration_Pos
(L
) <= Hi
10708 -- For Width case, use decoded name
10710 if Id
= Attribute_Width
then
10711 Get_Decoded_Name_String
(Chars
(L
));
10712 Wt
:= Nat
(Name_Len
);
10714 -- For Wide_[Wide_]Width, use encoded name, and
10715 -- then adjust for the encoding.
10718 Get_Name_String
(Chars
(L
));
10720 -- Character literals are always of length 3
10722 if Name_Buffer
(1) = 'Q' then
10725 -- Otherwise loop to adjust for upper/wide chars
10728 Wt
:= Nat
(Name_Len
);
10730 for J
in 1 .. Name_Len
loop
10731 if Name_Buffer
(J
) = 'U' then
10733 elsif Name_Buffer
(J
) = 'W' then
10740 W
:= Int
'Max (W
, Wt
);
10747 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
10752 -- The following attributes denote functions that cannot be folded
10754 when Attribute_From_Any
10756 | Attribute_TypeCode
10760 -- The following attributes can never be folded, and furthermore we
10761 -- should not even have entered the case statement for any of these.
10762 -- Note that in some cases, the values have already been folded as
10763 -- a result of the processing in Analyze_Attribute or earlier in
10766 when Attribute_Abort_Signal
10768 | Attribute_Address
10769 | Attribute_Address_Size
10770 | Attribute_Asm_Input
10771 | Attribute_Asm_Output
10773 | Attribute_Bit_Order
10774 | Attribute_Bit_Position
10775 | Attribute_Callable
10778 | Attribute_Code_Address
10779 | Attribute_Compiler_Version
10781 | Attribute_Default_Bit_Order
10782 | Attribute_Default_Scalar_Storage_Order
10784 | Attribute_Elaborated
10785 | Attribute_Elab_Body
10786 | Attribute_Elab_Spec
10787 | Attribute_Elab_Subp_Body
10788 | Attribute_Enabled
10789 | Attribute_External_Tag
10790 | Attribute_Fast_Math
10791 | Attribute_First_Bit
10795 | Attribute_Initialized
10796 | Attribute_Last_Bit
10797 | Attribute_Library_Level
10798 | Attribute_Max_Integer_Size
10799 | Attribute_Maximum_Alignment
10802 | Attribute_Partition_ID
10803 | Attribute_Pool_Address
10804 | Attribute_Position
10805 | Attribute_Priority
10806 | Attribute_Put_Image
10809 | Attribute_Scalar_Storage_Order
10810 | Attribute_Simple_Storage_Pool
10811 | Attribute_Storage_Pool
10812 | Attribute_Storage_Size
10813 | Attribute_Storage_Unit
10814 | Attribute_Stub_Type
10815 | Attribute_System_Allocator_Alignment
10817 | Attribute_Target_Name
10818 | Attribute_Terminated
10819 | Attribute_To_Address
10820 | Attribute_Type_Key
10821 | Attribute_Unchecked_Access
10822 | Attribute_Universal_Literal_String
10823 | Attribute_Unrestricted_Access
10825 | Attribute_Valid_Scalars
10826 | Attribute_Valid_Value
10828 | Attribute_Wchar_T_Size
10829 | Attribute_Wide_Value
10830 | Attribute_Wide_Wide_Value
10831 | Attribute_Word_Size
10834 raise Program_Error
;
10837 -- At the end of the case, one more check. If we did a static evaluation
10838 -- so that the result is now a literal, then set Is_Static_Expression
10839 -- in the constant only if the prefix type is a static subtype. For
10840 -- non-static subtypes, the folding is still OK, but not static.
10842 -- An exception is the GNAT attribute Constrained_Array which is
10843 -- defined to be a static attribute in all cases.
10845 if Nkind
(N
) in N_Integer_Literal
10847 | N_Character_Literal
10849 or else (Is_Entity_Name
(N
)
10850 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10852 Set_Is_Static_Expression
(N
, Static
);
10854 -- If this is still an attribute reference, then it has not been folded
10855 -- and that means that its expressions are in a non-static context.
10857 elsif Nkind
(N
) = N_Attribute_Reference
then
10860 -- Note: the else case not covered here are odd cases where the
10861 -- processing has transformed the attribute into something other
10862 -- than a constant. Nothing more to do in such cases.
10867 end Eval_Attribute
;
10869 ------------------------------
10870 -- Is_Anonymous_Tagged_Base --
10871 ------------------------------
10873 function Is_Anonymous_Tagged_Base
10875 Typ
: Entity_Id
) return Boolean
10879 Anon
= Current_Scope
10880 and then Is_Itype
(Anon
)
10881 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
10882 end Is_Anonymous_Tagged_Base
;
10884 --------------------------------
10885 -- Name_Implies_Lvalue_Prefix --
10886 --------------------------------
10888 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
10889 pragma Assert
(Is_Attribute_Name
(Nam
));
10891 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
10892 end Name_Implies_Lvalue_Prefix
;
10894 -----------------------
10895 -- Resolve_Attribute --
10896 -----------------------
10898 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
10899 Loc
: constant Source_Ptr
:= Sloc
(N
);
10900 P
: constant Node_Id
:= Prefix
(N
);
10901 Aname
: constant Name_Id
:= Attribute_Name
(N
);
10902 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
10903 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10904 Des_Btyp
: Entity_Id
;
10905 Index
: Interp_Index
;
10907 Nom_Subt
: Entity_Id
;
10909 procedure Accessibility_Message
;
10910 -- Error, or warning within an instance, if the static accessibility
10911 -- rules of 3.10.2 are violated.
10913 function Declared_Within_Generic_Unit
10914 (Entity
: Entity_Id
;
10915 Generic_Unit
: Node_Id
) return Boolean;
10916 -- Returns True if Declared_Entity is declared within the declarative
10917 -- region of Generic_Unit; otherwise returns False.
10919 function Prefix_With_Safe_Accessibility_Level
return Boolean;
10920 -- Return True if the prefix does not have a value conversion of an
10921 -- array because a value conversion is like an aggregate with respect
10922 -- to determining accessibility level (RM 3.10.2); even if evaluation
10923 -- of a value conversion is guaranteed to not create a new object,
10924 -- accessibility rules are defined as if it might.
10926 ---------------------------
10927 -- Accessibility_Message --
10928 ---------------------------
10930 procedure Accessibility_Message
is
10931 Indic
: Node_Id
:= Parent
(Parent
(N
));
10934 -- In an instance, this is a runtime check, but one we
10935 -- know will fail, so generate an appropriate warning.
10937 if In_Instance_Body
then
10938 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10940 ("non-local pointer cannot point to local object<<", P
);
10941 Error_Msg_F
("\Program_Error [<<", P
);
10943 Make_Raise_Program_Error
(Loc
,
10944 Reason
=> PE_Accessibility_Check_Failed
));
10945 Set_Etype
(N
, Typ
);
10949 Error_Msg_F
("non-local pointer cannot point to local object", P
);
10951 -- Check for case where we have a missing access definition
10953 if Is_Record_Type
(Current_Scope
)
10955 Nkind
(Parent
(N
)) in N_Discriminant_Association
10956 | N_Index_Or_Discriminant_Constraint
10958 Indic
:= Parent
(Parent
(N
));
10959 while Present
(Indic
)
10960 and then Nkind
(Indic
) /= N_Subtype_Indication
10962 Indic
:= Parent
(Indic
);
10965 if Present
(Indic
) then
10967 ("\use an access definition for" &
10968 " the access discriminant of&",
10969 N
, Entity
(Subtype_Mark
(Indic
)));
10973 end Accessibility_Message
;
10975 ----------------------------------
10976 -- Declared_Within_Generic_Unit --
10977 ----------------------------------
10979 function Declared_Within_Generic_Unit
10980 (Entity
: Entity_Id
;
10981 Generic_Unit
: Node_Id
) return Boolean
10983 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
10986 while Present
(Generic_Encloser
) loop
10987 if Generic_Encloser
= Generic_Unit
then
10991 -- We have to step to the scope of the generic's entity, because
10992 -- otherwise we'll just get back the same generic.
10994 Generic_Encloser
:=
10995 Enclosing_Generic_Unit
10996 (Scope
(Defining_Entity
(Generic_Encloser
)));
11000 end Declared_Within_Generic_Unit
;
11002 ------------------------------------------
11003 -- Prefix_With_Safe_Accessibility_Level --
11004 ------------------------------------------
11006 function Prefix_With_Safe_Accessibility_Level
return Boolean is
11007 function Safe_Value_Conversions
return Boolean;
11008 -- Return False if the prefix has a value conversion of an array type
11010 ----------------------------
11011 -- Safe_Value_Conversions --
11012 ----------------------------
11014 function Safe_Value_Conversions
return Boolean is
11019 if Nkind
(PP
) in N_Selected_Component | N_Indexed_Component
then
11022 elsif Comes_From_Source
(PP
)
11023 and then Nkind
(PP
) in N_Type_Conversion
11024 | N_Unchecked_Type_Conversion
11025 and then Is_Array_Type
(Etype
(PP
))
11029 elsif Comes_From_Source
(PP
)
11030 and then Nkind
(PP
) = N_Qualified_Expression
11031 and then Is_Array_Type
(Etype
(PP
))
11032 and then Nkind
(Original_Node
(Expression
(PP
))) in
11033 N_Aggregate | N_Extension_Aggregate
11043 end Safe_Value_Conversions
;
11045 -- Start of processing for Prefix_With_Safe_Accessibility_Level
11048 -- No check required for unchecked and unrestricted access
11050 if Attr_Id
= Attribute_Unchecked_Access
11051 or else Attr_Id
= Attribute_Unrestricted_Access
11055 -- Check value conversions
11057 elsif Ekind
(Btyp
) = E_General_Access_Type
11058 and then not Safe_Value_Conversions
11064 end Prefix_With_Safe_Accessibility_Level
;
11066 -- Start of processing for Resolve_Attribute
11069 -- If error during analysis, no point in continuing, except for array
11070 -- types, where we get better recovery by using unconstrained indexes
11071 -- than nothing at all (see Check_Array_Type).
11073 if Error_Posted
(N
)
11074 and then Attr_Id
/= Attribute_First
11075 and then Attr_Id
/= Attribute_Last
11076 and then Attr_Id
/= Attribute_Length
11077 and then Attr_Id
/= Attribute_Range
11082 -- If attribute was universal type, reset to actual type
11084 if Is_Universal_Numeric_Type
(Etype
(N
)) then
11085 Set_Etype
(N
, Typ
);
11088 -- Remaining processing depends on attribute
11096 -- For access attributes, if the prefix denotes an entity, it is
11097 -- interpreted as a name, never as a call. It may be overloaded,
11098 -- in which case resolution uses the profile of the context type.
11099 -- Otherwise prefix must be resolved.
11101 when Attribute_Access
11102 | Attribute_Unchecked_Access
11103 | Attribute_Unrestricted_Access
11105 -- Note possible modification if we have a variable
11108 and then not Is_Access_Constant
(Typ
)
11110 Note_Possible_Modification
(P
, Sure
=> False);
11113 -- Case where prefix is an entity name
11115 if Is_Entity_Name
(P
) then
11117 -- Deal with case where prefix itself is overloaded
11119 if Is_Overloaded
(P
) then
11120 Get_First_Interp
(P
, Index
, It
);
11121 while Present
(It
.Nam
) loop
11122 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11123 Set_Entity
(P
, It
.Nam
);
11125 -- The prefix is definitely NOT overloaded anymore at
11126 -- this point, so we reset the Is_Overloaded flag to
11127 -- avoid any confusion when reanalyzing the node.
11129 Set_Is_Overloaded
(P
, False);
11130 Set_Is_Overloaded
(N
, False);
11131 Generate_Reference
(Entity
(P
), P
);
11135 Get_Next_Interp
(Index
, It
);
11138 -- If Prefix is a subprogram name, this reference freezes,
11139 -- but not if within spec expression mode. The profile of
11140 -- the subprogram is not frozen at this point.
11142 if not In_Spec_Expression
then
11143 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11146 -- If it is a type, there is nothing to resolve.
11147 -- If it is a subprogram, do not freeze its profile.
11148 -- If it is an object, complete its resolution.
11150 elsif Is_Overloadable
(Entity
(P
)) then
11151 if not In_Spec_Expression
then
11152 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
11155 -- Nothing to do if prefix is a type name
11157 elsif Is_Type
(Entity
(P
)) then
11160 -- Otherwise non-overloaded other case, resolve the prefix
11166 -- Some further error checks
11168 Error_Msg_Name_1
:= Aname
;
11170 if not Is_Entity_Name
(P
) then
11173 elsif Is_Overloadable
(Entity
(P
))
11174 and then Is_Abstract_Subprogram
(Entity
(P
))
11176 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
11177 Set_Etype
(N
, Any_Type
);
11179 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
11181 ("prefix of % attribute cannot be enumeration literal", P
);
11182 Set_Etype
(N
, Any_Type
);
11184 -- An attempt to take 'Access of a function that renames an
11185 -- enumeration literal. Issue a specialized error message.
11187 elsif Ekind
(Entity
(P
)) = E_Function
11188 and then Present
(Alias
(Entity
(P
)))
11189 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
11192 ("prefix of % attribute cannot be function renaming "
11193 & "an enumeration literal", P
);
11194 Set_Etype
(N
, Any_Type
);
11196 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
11197 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
11198 Set_Etype
(N
, Any_Type
);
11201 -- Assignments, return statements, components of aggregates,
11202 -- generic instantiations will require convention checks if
11203 -- the type is an access to subprogram. Given that there will
11204 -- also be accessibility checks on those, this is where the
11205 -- checks can eventually be centralized ???
11207 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11208 | E_Access_Subprogram_Type
11209 | E_Anonymous_Access_Protected_Subprogram_Type
11210 | E_Anonymous_Access_Subprogram_Type
11212 -- Deal with convention mismatch
11214 if Convention
(Designated_Type
(Btyp
)) /=
11215 Convention
(Entity
(P
))
11218 ("subprogram & has wrong convention", P
, Entity
(P
));
11219 Error_Msg_Sloc
:= Sloc
(Btyp
);
11220 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
11222 if not Is_Itype
(Btyp
)
11223 and then not Has_Convention_Pragma
(Btyp
)
11224 and then Convention
(Entity
(P
)) /= Convention_Intrinsic
11227 ("\probable missing pragma Convention for &",
11232 Check_Subtype_Conformant
11233 (New_Id
=> Entity
(P
),
11234 Old_Id
=> Designated_Type
(Btyp
),
11238 if Attr_Id
= Attribute_Unchecked_Access
then
11239 Error_Msg_Name_1
:= Aname
;
11241 ("attribute% cannot be applied to a subprogram", P
);
11243 elsif Aname
= Name_Unrestricted_Access
then
11244 null; -- Nothing to check
11246 -- Check the static accessibility rule of 3.10.2(32).
11247 -- This rule also applies within the private part of an
11248 -- instantiation. This rule does not apply to anonymous
11249 -- access-to-subprogram types in access parameters.
11251 elsif Attr_Id
= Attribute_Access
11252 and then not In_Instance_Body
11254 (Ekind
(Btyp
) = E_Access_Subprogram_Type
11255 or else Is_Local_Anonymous_Access
(Btyp
))
11256 and then Subprogram_Access_Level
(Entity
(P
)) >
11257 Type_Access_Level
(Btyp
)
11260 ("subprogram must not be deeper than access type", P
);
11262 -- Check the restriction of 3.10.2(32) that disallows the
11263 -- access attribute within a generic body when the ultimate
11264 -- ancestor of the type of the attribute is declared outside
11265 -- of the generic unit and the subprogram is declared within
11266 -- that generic unit. This includes any such attribute that
11267 -- occurs within the body of a generic unit that is a child
11268 -- of the generic unit where the subprogram is declared.
11270 -- The rule also prohibits applying the attribute when the
11271 -- access type is a generic formal access type (since the
11272 -- level of the actual type is not known). This restriction
11273 -- does not apply when the attribute type is an anonymous
11274 -- access-to-subprogram type. Note that this check was
11275 -- revised by AI-229, because the original Ada 95 rule
11276 -- was too lax. The original rule only applied when the
11277 -- subprogram was declared within the body of the generic,
11278 -- which allowed the possibility of dangling references).
11279 -- The rule was also too strict in some cases, in that it
11280 -- didn't permit the access to be declared in the generic
11281 -- spec, whereas the revised rule does (as long as it's not
11284 -- There are a couple of subtleties of the test for applying
11285 -- the check that are worth noting. First, we only apply it
11286 -- when the levels of the subprogram and access type are the
11287 -- same (the case where the subprogram is statically deeper
11288 -- was applied above, and the case where the type is deeper
11289 -- is always safe). Second, we want the check to apply
11290 -- within nested generic bodies and generic child unit
11291 -- bodies, but not to apply to an attribute that appears in
11292 -- the generic unit's specification. This is done by testing
11293 -- that the attribute's innermost enclosing generic body is
11294 -- not the same as the innermost generic body enclosing the
11295 -- generic unit where the subprogram is declared (we don't
11296 -- want the check to apply when the access attribute is in
11297 -- the spec and there's some other generic body enclosing
11298 -- generic). Finally, there's no point applying the check
11299 -- when within an instance, because any violations will have
11300 -- been caught by the compilation of the generic unit.
11302 -- We relax this check in Relaxed_RM_Semantics mode for
11303 -- compatibility with legacy code for use by Ada source
11304 -- code analyzers (e.g. CodePeer).
11306 elsif Attr_Id
= Attribute_Access
11307 and then not Relaxed_RM_Semantics
11308 and then not In_Instance
11309 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
11310 and then Present
(Enclosing_Generic_Body
(N
))
11311 and then Enclosing_Generic_Body
(N
) /=
11312 Enclosing_Generic_Body
11313 (Enclosing_Generic_Unit
(Entity
(P
)))
11314 and then Subprogram_Access_Level
(Entity
(P
)) =
11315 Type_Access_Level
(Btyp
)
11316 and then Ekind
(Btyp
) /=
11317 E_Anonymous_Access_Subprogram_Type
11318 and then Ekind
(Btyp
) /=
11319 E_Anonymous_Access_Protected_Subprogram_Type
11321 -- The attribute type's ultimate ancestor must be
11322 -- declared within the same generic unit as the
11323 -- subprogram is declared (including within another
11324 -- nested generic unit). The error message is
11325 -- specialized to say "ancestor" for the case where the
11326 -- access type is not its own ancestor, since saying
11327 -- simply "access type" would be very confusing.
11329 if not Declared_Within_Generic_Unit
11331 Enclosing_Generic_Unit
(Entity
(P
)))
11334 ("''Access attribute not allowed in generic body",
11337 if Root_Type
(Btyp
) = Btyp
then
11340 "access type & is declared outside " &
11341 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11344 ("\because ancestor of " &
11345 "access type & is declared outside " &
11346 "generic unit (RM 3.10.2(32))", N
, Btyp
);
11350 ("\move ''Access to private part, or " &
11351 "(Ada 2005) use anonymous access type instead of &",
11354 -- If the ultimate ancestor of the attribute's type is
11355 -- a formal type, then the attribute is illegal because
11356 -- the actual type might be declared at a higher level.
11357 -- The error message is specialized to say "ancestor"
11358 -- for the case where the access type is not its own
11359 -- ancestor, since saying simply "access type" would be
11362 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
11363 if Root_Type
(Btyp
) = Btyp
then
11365 ("access type must not be a generic formal type",
11369 ("ancestor access type must not be a generic " &
11376 -- If this is a renaming, an inherited operation, or a
11377 -- subprogram instance, use the original entity. This may make
11378 -- the node type-inconsistent, so this transformation can only
11379 -- be done if the node will not be reanalyzed. In particular,
11380 -- if it is within a default expression, the transformation
11381 -- must be delayed until the default subprogram is created for
11382 -- it, when the enclosing subprogram is frozen.
11384 if Is_Entity_Name
(P
)
11385 and then Is_Overloadable
(Entity
(P
))
11386 and then Present
(Alias
(Entity
(P
)))
11387 and then Expander_Active
11390 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11393 elsif Nkind
(P
) = N_Selected_Component
11394 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
11396 -- Protected operation. If operation is overloaded, must
11397 -- disambiguate. Prefix that denotes protected object itself
11398 -- is resolved with its own type.
11400 if Attr_Id
= Attribute_Unchecked_Access
then
11401 Error_Msg_Name_1
:= Aname
;
11403 ("attribute% cannot be applied to protected operation", P
);
11406 Resolve
(Prefix
(P
));
11408 if not Is_Overloaded
(P
) then
11409 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11412 Get_First_Interp
(P
, Index
, It
);
11413 while Present
(It
.Nam
) loop
11414 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
11415 Set_Entity
(Selector_Name
(P
), It
.Nam
);
11417 -- The prefix is definitely NOT overloaded anymore at
11418 -- this point, so we reset the Is_Overloaded flag to
11419 -- avoid any confusion when reanalyzing the node.
11421 Set_Is_Overloaded
(P
, False);
11422 Set_Is_Overloaded
(N
, False);
11423 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
11427 Get_Next_Interp
(Index
, It
);
11431 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
11432 -- statically illegal if F is an anonymous access to subprogram.
11434 elsif Nkind
(P
) = N_Explicit_Dereference
11435 and then Is_Entity_Name
(Prefix
(P
))
11436 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
11437 E_Anonymous_Access_Subprogram_Type
11439 Error_Msg_N
("anonymous access to subprogram "
11440 & "has deeper accessibility than any master", P
);
11442 elsif Is_Overloaded
(P
) then
11444 -- Use the designated type of the context to disambiguate
11445 -- Note that this was not strictly conformant to Ada 95,
11446 -- but was the implementation adopted by most Ada 95 compilers.
11447 -- The use of the context type to resolve an Access attribute
11448 -- reference is now mandated in AI-235 for Ada 2005.
11451 Index
: Interp_Index
;
11455 Get_First_Interp
(P
, Index
, It
);
11456 while Present
(It
.Typ
) loop
11457 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
11458 Resolve
(P
, It
.Typ
);
11462 Get_Next_Interp
(Index
, It
);
11469 -- Refuse to compute access to variables and constants when that
11470 -- would drop the strub mode associated with them, unless they're
11471 -- unchecked conversions. We don't have to do this when the types
11472 -- of the data objects are annotated: then the access type
11473 -- designates the annotated type, and there's no loss. Only when
11474 -- the variable is annotated directly that the pragma gets
11475 -- attached to the variable, rather than to its type, and then,
11476 -- expressing an access-to-annotated-type type to hold the 'Access
11477 -- result is not possible without resorting to that very annotated
11480 if Attr_Id
/= Attribute_Unchecked_Access
11481 and then Comes_From_Source
(N
)
11482 and then Is_Entity_Name
(P
)
11483 and then Explicit_Strub_Mode
(Entity
(P
)) = Enabled
11485 Explicit_Strub_Mode
(Designated_Type
(Btyp
)) = Unspecified
11487 Error_Msg_F
("target access type drops `strub` mode from &", P
);
11490 -- X'Access is illegal if X denotes a constant and the access type
11491 -- is access-to-variable. Same for 'Unchecked_Access. The rule
11492 -- does not apply to 'Unrestricted_Access. If the reference is a
11493 -- default-initialized aggregate component for a self-referential
11494 -- type the reference is legal.
11496 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
11497 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
11498 or else (Is_Record_Type
(Btyp
)
11500 Present
(Corresponding_Remote_Type
(Btyp
)))
11501 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11502 or else Ekind
(Btyp
)
11503 = E_Anonymous_Access_Protected_Subprogram_Type
11504 or else Is_Access_Constant
(Btyp
)
11505 or else Is_Variable
(P
)
11506 or else Attr_Id
= Attribute_Unrestricted_Access
)
11508 if Is_Entity_Name
(P
)
11509 and then Is_Type
(Entity
(P
))
11511 -- Legality of a self-reference through an access
11512 -- attribute has been verified in Analyze_Access_Attribute.
11516 elsif Comes_From_Source
(N
) then
11517 Error_Msg_F
("access-to-variable designates constant", P
);
11521 Des_Btyp
:= Designated_Type
(Btyp
);
11523 if Ada_Version
>= Ada_2005
11524 and then Is_Incomplete_Type
(Des_Btyp
)
11526 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
11527 -- imported entity, and the non-limited view is visible, make
11528 -- use of it. If it is an incomplete subtype, use the base type
11531 if From_Limited_With
(Des_Btyp
)
11532 and then Present
(Non_Limited_View
(Des_Btyp
))
11534 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
11536 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
11537 Des_Btyp
:= Etype
(Des_Btyp
);
11541 if Attr_Id
in Attribute_Access | Attribute_Unchecked_Access
11542 and then (Ekind
(Btyp
) = E_General_Access_Type
11543 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
11545 -- Ada 2005 (AI-230): Check the accessibility of anonymous
11546 -- access types for stand-alone objects, record and array
11547 -- components, and return objects. For a component definition
11548 -- the level is the same of the enclosing composite type.
11550 if Ada_Version
>= Ada_2005
11551 and then (Is_Local_Anonymous_Access
(Btyp
)
11553 -- Handle cases where Btyp is the anonymous access
11554 -- type of an Ada 2012 stand-alone object.
11556 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
11557 N_Object_Declaration
)
11558 and then Attr_Id
= Attribute_Access
11560 -- Verify that static checking is OK (namely that we aren't
11561 -- in a specific context requiring dynamic checks on
11562 -- expicitly aliased parameters), and then check the level.
11564 -- Otherwise a check will be generated later when the return
11565 -- statement gets expanded.
11567 and then not Is_Special_Aliased_Formal_Access
(N
)
11569 Static_Accessibility_Level
(N
, Zero_On_Dynamic_Level
) >
11570 Deepest_Type_Access_Level
(Btyp
)
11572 -- In an instance, this is a runtime check, but one we know
11573 -- will fail, so generate an appropriate warning. As usual,
11574 -- this kind of warning is an error in SPARK mode.
11576 if In_Instance_Body
then
11580 not No_Dynamic_Accessibility_Checks_Enabled
(P
);
11583 ("non-local pointer cannot point to local object<<", P
);
11584 Error_Msg_F
("\Program_Error [<<", P
);
11587 Make_Raise_Program_Error
(Loc
,
11588 Reason
=> PE_Accessibility_Check_Failed
));
11589 Set_Etype
(N
, Typ
);
11593 ("non-local pointer cannot point to local object", P
);
11597 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
11599 ("illegal attribute for discriminant-dependent component",
11603 -- Check static matching rule of 3.10.2(27). Nominal subtype
11604 -- of the prefix must statically match the designated type.
11606 Nom_Subt
:= Etype
(P
);
11608 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
11609 Nom_Subt
:= Base_Type
(Nom_Subt
);
11612 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
11614 -- If the attribute is in the context of an access
11615 -- parameter, then the prefix is allowed to be of
11616 -- the class-wide type (by AI-127).
11618 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
11619 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11620 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
11626 Desig
:= Designated_Type
(Typ
);
11628 if Is_Class_Wide_Type
(Desig
) then
11629 Desig
:= Etype
(Desig
);
11632 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
11637 ("type of prefix: & not compatible",
11640 ("\with &, the expected designated type",
11641 P
, Designated_Type
(Typ
));
11646 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
11648 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11649 and then Is_Class_Wide_Type
(Nom_Subt
))
11652 ("type of prefix: & is not covered", P
, Nom_Subt
);
11654 ("\by &, the expected designated type" &
11655 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
11658 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
11659 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
11660 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
11661 and then Designated_Type
(Typ
) /= Nom_Subt
11663 Apply_Discriminant_Check
11664 (N
, Etype
(Designated_Type
(Typ
)));
11667 -- Ada 2005 (AI-363): Require static matching when designated
11668 -- type has discriminants and a constrained partial view, since
11669 -- in general objects of such types are mutable, so we can't
11670 -- allow the access value to designate a constrained object
11671 -- (because access values must be assumed to designate mutable
11672 -- objects when designated type does not impose a constraint).
11674 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
11677 elsif Has_Discriminants
(Designated_Type
(Typ
))
11678 and then not Is_Constrained
(Des_Btyp
)
11680 (Ada_Version
< Ada_2005
11682 not Object_Type_Has_Constrained_Partial_View
11683 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
11684 Scop
=> Current_Scope
))
11690 ("object subtype must statically match "
11691 & "designated subtype", P
);
11693 if Is_Entity_Name
(P
)
11694 and then Is_Array_Type
(Designated_Type
(Typ
))
11697 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
11700 ("aliased object has explicit bounds??", D
);
11702 ("\declare without bounds (and with explicit "
11703 & "initialization)??", D
);
11705 ("\for use with unconstrained access??", D
);
11710 -- Check the static accessibility rule of 3.10.2(28). Note that
11711 -- this check is not performed for the case of an anonymous
11712 -- access type, since the access attribute is always legal
11713 -- in such a context - unless the restriction
11714 -- No_Dynamic_Accessibility_Checks is active.
11717 No_Dynamic_Acc_Checks
: constant Boolean :=
11718 No_Dynamic_Accessibility_Checks_Enabled
(Btyp
);
11720 Compatible_Alt_Checks
: constant Boolean :=
11721 No_Dynamic_Acc_Checks
and then not Debug_Flag_Underscore_B
;
11723 if Attr_Id
/= Attribute_Unchecked_Access
11724 and then (Ekind
(Btyp
) = E_General_Access_Type
11725 or else No_Dynamic_Acc_Checks
)
11727 -- In the case of the alternate "compatibility"
11728 -- accessibility model we do not perform a static
11729 -- accessibility check on actuals for anonymous access
11730 -- types - so exclude them here.
11732 and then not (Compatible_Alt_Checks
11733 and then Is_Actual_Parameter
(N
)
11734 and then Ekind
(Btyp
)
11735 = E_Anonymous_Access_Type
)
11737 -- Call Accessibility_Level directly to avoid returning
11738 -- zero on cases where the prefix is an explicitly aliased
11739 -- parameter in a return statement, instead of using the
11740 -- normal Static_Accessibility_Level function.
11742 -- Shouldn't this be handled somehow in
11743 -- Static_Accessibility_Level ???
11745 and then Nkind
(Accessibility_Level
(P
, Dynamic_Level
))
11746 = N_Integer_Literal
11748 Intval
(Accessibility_Level
(P
, Dynamic_Level
))
11749 > Deepest_Type_Access_Level
(Btyp
)
11751 Accessibility_Message
;
11757 if Ekind
(Btyp
) in E_Access_Protected_Subprogram_Type
11758 | E_Anonymous_Access_Protected_Subprogram_Type
11760 if Is_Entity_Name
(P
)
11761 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
11763 Error_Msg_F
("context requires a protected subprogram", P
);
11765 -- Check accessibility of protected object against that of the
11766 -- access type, but only on user code, because the expander
11767 -- creates access references for handlers. If the context is an
11768 -- anonymous_access_to_protected, there are no accessibility
11769 -- checks either. Omit check entirely for Unrestricted_Access.
11771 elsif Static_Accessibility_Level
(P
, Zero_On_Dynamic_Level
)
11772 > Deepest_Type_Access_Level
(Btyp
)
11773 and then Comes_From_Source
(N
)
11774 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11775 and then Attr_Id
/= Attribute_Unrestricted_Access
11777 Accessibility_Message
;
11780 -- AI05-0225: If the context is not an access to protected
11781 -- function, the prefix must be a variable, given that it may
11782 -- be used subsequently in a protected call.
11784 elsif Nkind
(P
) = N_Selected_Component
11785 and then not Is_Variable
(Prefix
(P
))
11786 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
11789 ("target object of access to protected procedure "
11790 & "must be variable", N
);
11792 elsif Is_Entity_Name
(P
) then
11793 Check_Internal_Protected_Use
(N
, Entity
(P
));
11796 elsif Ekind
(Btyp
) in E_Access_Subprogram_Type
11797 | E_Anonymous_Access_Subprogram_Type
11798 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
11800 Error_Msg_F
("context requires a non-protected subprogram", P
);
11803 -- AI12-0412: The rule in RM 6.1.1(18.2/5) disallows applying
11804 -- attribute Access to a primitive of an abstract type when the
11805 -- primitive has any Pre'Class or Post'Class aspects specified
11806 -- with nonstatic expressions.
11808 if Attr_Id
= Attribute_Access
11809 and then Ekind
(Btyp
) in E_Access_Subprogram_Type
11810 | E_Anonymous_Access_Subprogram_Type
11811 and then Is_Entity_Name
(P
)
11812 and then Is_Dispatching_Operation
(Entity
(P
))
11814 Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
(Entity
(P
))
11817 ("attribute not allowed for primitive of abstract type with "
11818 & "nonstatic class-wide pre/postconditions",
11822 -- The context cannot be a pool-specific type, but this is a
11823 -- legality rule, not a resolution rule, so it must be checked
11824 -- separately, after possibly disambiguation (see AI-245).
11826 if Ekind
(Btyp
) = E_Access_Type
11827 and then Attr_Id
/= Attribute_Unrestricted_Access
11829 Wrong_Type
(N
, Typ
);
11832 -- The context may be a constrained access type (however ill-
11833 -- advised such subtypes might be) so in order to generate a
11834 -- constraint check we need to set the type of the attribute
11835 -- reference to the base type of the context.
11837 Set_Etype
(N
, Btyp
);
11839 -- Check for incorrect atomic/volatile/VFA reference (RM C.6(12))
11841 if Attr_Id
/= Attribute_Unrestricted_Access
then
11842 if Is_Atomic_Object
(P
)
11843 and then not Is_Atomic
(Designated_Type
(Typ
))
11846 ("access to atomic object cannot yield access-to-" &
11847 "non-atomic type", P
);
11849 elsif Is_Volatile_Object_Ref
(P
)
11850 and then not Is_Volatile
(Designated_Type
(Typ
))
11853 ("access to volatile object cannot yield access-to-" &
11854 "non-volatile type", P
);
11856 elsif Is_Volatile_Full_Access_Object_Ref
(P
)
11857 and then not Is_Volatile_Full_Access
(Designated_Type
(Typ
))
11860 ("access to full access object cannot yield access-to-" &
11861 "non-full-access type", P
);
11864 -- Check for nonatomic subcomponent of a full access object
11865 -- in Ada 2022 (RM C.6 (12)).
11867 if Ada_Version
>= Ada_2022
11868 and then Is_Subcomponent_Of_Full_Access_Object
(P
)
11869 and then not Is_Atomic_Object
(P
)
11872 ("cannot have access attribute with prefix &", N
, P
);
11874 ("\nonatomic subcomponent of full access object "
11875 & "(RM C.6(12))", N
);
11879 -- Check for aliased view. We allow a nonaliased prefix when in
11880 -- an instance because the prefix may have been a tagged formal
11881 -- object, which is defined to be aliased even when the actual
11882 -- might not be (other instance cases will have been caught in
11883 -- the generic). Similarly, within an inlined body we know that
11884 -- the attribute is legal in the original subprogram, therefore
11885 -- legal in the expansion.
11887 if not (Is_Entity_Name
(P
)
11888 and then Is_Overloadable
(Entity
(P
)))
11889 and then not (Nkind
(P
) = N_Selected_Component
11891 Is_Overloadable
(Entity
(Selector_Name
(P
))))
11892 and then not Is_Aliased_View
(Original_Node
(P
))
11893 and then not In_Instance
11894 and then not In_Inlined_Body
11895 and then Comes_From_Source
(N
)
11897 -- Here we have a non-aliased view. This is illegal unless we
11898 -- have the case of Unrestricted_Access, where for now we allow
11899 -- this (we will reject later if expected type is access to an
11900 -- unconstrained array with a thin pointer).
11902 -- No need for an error message on a generated access reference
11903 -- for the controlling argument in a dispatching call: error
11904 -- will be reported when resolving the call.
11906 if Attr_Id
/= Attribute_Unrestricted_Access
then
11907 Error_Msg_Name_1
:= Aname
;
11908 Error_Msg_N
("prefix of % attribute must be aliased", P
);
11910 -- Check for unrestricted access where expected type is a thin
11911 -- pointer to an unconstrained array.
11913 elsif Has_Size_Clause
(Typ
)
11914 and then RM_Size
(Typ
) = System_Address_Size
11917 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
11919 if Is_Array_Type
(DT
)
11920 and then not Is_Constrained
(DT
)
11923 ("illegal use of Unrestricted_Access attribute", P
);
11925 ("\attempt to generate thin pointer to unaliased "
11932 -- Check that the prefix does not have a value conversion of an
11933 -- array type since a value conversion is like an aggregate with
11934 -- respect to determining accessibility level (RM 3.10.2).
11936 if not Prefix_With_Safe_Accessibility_Level
then
11937 Accessibility_Message
;
11941 -- Mark that address of entity is taken in case of
11942 -- 'Unrestricted_Access or in case of a subprogram.
11944 if Is_Entity_Name
(P
)
11945 and then (Attr_Id
= Attribute_Unrestricted_Access
11946 or else Is_Subprogram
(Entity
(P
)))
11948 Set_Address_Taken
(Entity
(P
));
11951 -- Deal with possible elaboration check
11953 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
11955 Subp_Id
: constant Entity_Id
:= Entity
(P
);
11956 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
11957 Subp_Decl
: constant Node_Id
:=
11958 Unit_Declaration_Node
(Subp_Id
);
11959 Flag_Id
: Entity_Id
;
11960 Subp_Body
: Node_Id
;
11962 -- If the access has been taken and the body of the subprogram
11963 -- has not been see yet, indirect calls must be protected with
11964 -- elaboration checks. We have the proper elaboration machinery
11965 -- for subprograms declared in packages, but within a block or
11966 -- a subprogram the body will appear in the same declarative
11967 -- part, and we must insert a check in the eventual body itself
11968 -- using the elaboration flag that we generate now. The check
11969 -- is then inserted when the body is expanded. This processing
11970 -- is not needed for a stand alone expression function because
11971 -- the internally generated spec and body are always inserted
11972 -- as a pair in the same declarative list.
11976 and then Comes_From_Source
(Subp_Id
)
11977 and then Comes_From_Source
(N
)
11978 and then In_Open_Scopes
(Scop
)
11979 and then Ekind
(Scop
) in E_Block | E_Procedure | E_Function
11980 and then not Has_Completion
(Subp_Id
)
11981 and then No
(Elaboration_Entity
(Subp_Id
))
11982 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11983 and then Nkind
(Original_Node
(Subp_Decl
)) /=
11984 N_Expression_Function
11986 -- Create elaboration variable for it
11988 Flag_Id
:= Make_Temporary
(Loc
, 'E');
11989 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
11990 Set_Is_Frozen
(Flag_Id
);
11992 -- Insert declaration for flag after subprogram
11993 -- declaration. Note that attribute reference may
11994 -- appear within a nested scope.
11996 Insert_After_And_Analyze
(Subp_Decl
,
11997 Make_Object_Declaration
(Loc
,
11998 Defining_Identifier
=> Flag_Id
,
11999 Object_Definition
=>
12000 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
12002 Make_Integer_Literal
(Loc
, Uint_0
)));
12004 -- The above sets the Scope of the flag entity to the
12005 -- current scope, in which the attribute appears, but
12006 -- the flag declaration has been inserted after that
12007 -- of Subp_Id, so the scope of the flag is the same as
12008 -- that of Subp_Id. This is relevant when unnesting,
12009 -- where processing depends on correct scope setting.
12011 Set_Scope
(Flag_Id
, Scop
);
12014 -- Taking the 'Access of an expression function freezes its
12015 -- expression (RM 13.14 10.3/3). This does not apply to an
12016 -- expression function that acts as a completion because the
12017 -- generated body is immediately analyzed and the expression
12018 -- is automatically frozen.
12020 if Is_Expression_Function
(Subp_Id
)
12021 and then Present
(Corresponding_Body
(Subp_Decl
))
12024 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
12026 -- The body has already been analyzed when the expression
12027 -- function acts as a completion.
12029 if Analyzed
(Subp_Body
) then
12032 -- Attribute 'Access may appear within the generated body
12033 -- of the expression function subject to the attribute:
12035 -- function F is (... F'Access ...);
12037 -- If the expression function is on the scope stack, then
12038 -- the body is currently being analyzed. Do not reanalyze
12039 -- it because this will lead to infinite recursion.
12041 elsif In_Open_Scopes
(Subp_Id
) then
12044 -- If reference to the expression function appears in an
12045 -- inner scope, for example as an actual in an instance,
12046 -- this is not a freeze point either.
12048 elsif Scope
(Subp_Id
) /= Current_Scope
then
12051 -- Dispatch tables are not a freeze point either
12053 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
12054 and then Is_Dispatch_Table_Entity
(Etype
(Parent
(N
)))
12058 -- Analyze the body of the expression function to freeze
12062 Analyze
(Subp_Body
);
12072 -- Deal with resolving the type for Address attribute, overloading
12073 -- is not permitted here, since there is no context to resolve it.
12075 when Attribute_Address
12076 | Attribute_Code_Address
12078 -- To be safe, assume that if the address of a variable is taken,
12079 -- it may be modified via this address, so note modification.
12081 if Is_Variable
(P
) then
12082 Note_Possible_Modification
(P
, Sure
=> False);
12085 if Nkind
(P
) in N_Subexpr
12086 and then Is_Overloaded
(P
)
12088 Get_First_Interp
(P
, Index
, It
);
12089 Get_Next_Interp
(Index
, It
);
12091 if Present
(It
.Nam
) then
12092 Error_Msg_Name_1
:= Aname
;
12094 ("prefix of % attribute cannot be overloaded", P
);
12098 if not Is_Entity_Name
(P
)
12099 or else not Is_Overloadable
(Entity
(P
))
12101 if not Is_Task_Type
(Etype
(P
))
12102 or else Nkind
(P
) = N_Explicit_Dereference
12108 -- If this is the name of a derived subprogram, or that of a
12109 -- generic actual, the address is that of the original entity.
12111 if Is_Entity_Name
(P
)
12112 and then Is_Overloadable
(Entity
(P
))
12113 and then Present
(Alias
(Entity
(P
)))
12116 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
12119 if Is_Entity_Name
(P
) then
12120 Set_Address_Taken
(Entity
(P
));
12123 if Nkind
(P
) = N_Slice
then
12125 -- Arr (X .. Y)'address is identical to Arr (X)'address,
12126 -- even if the array is packed and the slice itself is not
12127 -- addressable. Transform the prefix into an indexed component.
12129 -- Note that the transformation is safe only if we know that
12130 -- the slice is non-null. That is because a null slice can have
12131 -- an out of bounds index value.
12133 -- Right now, gigi blows up if given 'Address on a slice as a
12134 -- result of some incorrect freeze nodes generated by the front
12135 -- end, and this covers up that bug in one case, but the bug is
12136 -- likely still there in the cases not handled by this code ???
12138 -- It's not clear what 'Address *should* return for a null
12139 -- slice with out of bounds indexes, this might be worth an ARG
12142 -- One approach would be to do a length check unconditionally,
12143 -- and then do the transformation below unconditionally, but
12144 -- analyze with checks off, avoiding the problem of the out of
12145 -- bounds index. This approach would interpret the address of
12146 -- an out of bounds null slice as being the address where the
12147 -- array element would be if there was one, which is probably
12148 -- as reasonable an interpretation as any ???
12151 Loc
: constant Source_Ptr
:= Sloc
(P
);
12152 D
: constant Node_Id
:= Discrete_Range
(P
);
12156 if Is_Entity_Name
(D
)
12159 (Type_Low_Bound
(Entity
(D
)),
12160 Type_High_Bound
(Entity
(D
)))
12163 Make_Attribute_Reference
(Loc
,
12164 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
12165 Attribute_Name
=> Name_First
);
12167 elsif Nkind
(D
) = N_Range
12168 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
12170 Lo
:= Low_Bound
(D
);
12176 if Present
(Lo
) then
12178 Make_Indexed_Component
(Loc
,
12179 Prefix
=> Relocate_Node
(Prefix
(P
)),
12180 Expressions
=> New_List
(Lo
)));
12182 Analyze_And_Resolve
(P
);
12191 -- Prefix of Body_Version attribute can be a subprogram name which
12192 -- must not be resolved, since this is not a call.
12194 when Attribute_Body_Version
=>
12201 -- Prefix of Caller attribute is an entry name which must not
12202 -- be resolved, since this is definitely not an entry call.
12204 when Attribute_Caller
=>
12211 -- Shares processing with Address attribute
12217 -- If the prefix of the Count attribute is an entry name it must not
12218 -- be resolved, since this is definitely not an entry call. However,
12219 -- if it is an element of an entry family, the index itself may
12220 -- have to be resolved because it can be a general expression.
12222 when Attribute_Count
12225 if Nkind
(P
) = N_Indexed_Component
12226 and then Is_Entity_Name
(Prefix
(P
))
12229 Indx
: constant Node_Id
:= First
(Expressions
(P
));
12230 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
12232 Resolve
(Indx
, Entry_Index_Type
(Fam
));
12233 Apply_Scalar_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
12241 -- Prefix of the Elaborated attribute is a subprogram name which
12242 -- must not be resolved, since this is definitely not a call. Note
12243 -- that it is a library unit, so it cannot be overloaded here.
12245 when Attribute_Elaborated
=>
12252 -- Prefix of Enabled attribute is a check name, which must be treated
12253 -- specially and not touched by Resolve.
12255 when Attribute_Enabled
=>
12262 -- Processing is shared with Count
12268 -- Do not resolve the prefix of Loop_Entry, instead wait until the
12269 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
12270 -- The delay ensures that any generated checks or temporaries are
12271 -- inserted before the relocated prefix.
12273 when Attribute_Loop_Entry
=>
12276 --------------------
12277 -- Mechanism_Code --
12278 --------------------
12280 -- Prefix of the Mechanism_Code attribute is a function name
12281 -- which must not be resolved. Should we check for overloaded ???
12283 when Attribute_Mechanism_Code
=>
12290 -- Most processing is done in sem_dist, after determining the
12291 -- context type. Node is rewritten as a conversion to a runtime call.
12293 when Attribute_Partition_ID
=>
12294 Process_Partition_Id
(N
);
12301 when Attribute_Pool_Address
=>
12308 -- We replace the Range attribute node with a range expression whose
12309 -- bounds are the 'First and 'Last attributes applied to the same
12310 -- prefix. The reason that we do this transformation here instead of
12311 -- in the expander is that it simplifies other parts of the semantic
12312 -- analysis which assume that the Range has been replaced; thus it
12313 -- must be done even when in semantic-only mode (note that the RM
12314 -- specifically mentions this equivalence, we take care that the
12315 -- prefix is only evaluated once).
12317 when Attribute_Range
=> Range_Attribute
: declare
12323 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12326 -- If the prefix is a function call returning on the secondary
12327 -- stack, we must make sure to mark/release the stack.
12329 if Nkind
(P
) = N_Function_Call
12330 and then Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
12331 and then Requires_Transient_Scope
(Etype
(P
))
12333 Set_Uses_Sec_Stack
(Scope
(Current_Scope
));
12337 Dims
:= Expressions
(N
);
12340 Make_Attribute_Reference
(Loc
,
12341 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
12342 Attribute_Name
=> Name_Last
,
12343 Expressions
=> Dims
);
12346 Make_Attribute_Reference
(Loc
,
12348 Attribute_Name
=> Name_First
,
12349 Expressions
=> (Dims
));
12351 -- Do not share the dimension indicator, if present. Even though
12352 -- it is a static constant, its source location may be modified
12353 -- when printing expanded code and node sharing will lead to chaos
12356 if Present
(Dims
) then
12357 Set_Expressions
(LB
, New_List
(New_Copy_Tree
(First
(Dims
))));
12360 -- If the original was marked as Must_Not_Freeze (see code in
12361 -- Sem_Ch3.Make_Index), then make sure the rewriting does not
12364 if Must_Not_Freeze
(N
) then
12365 Set_Must_Not_Freeze
(HB
);
12366 Set_Must_Not_Freeze
(LB
);
12367 Set_Must_Not_Freeze
(Prefix
(HB
));
12368 Set_Must_Not_Freeze
(Prefix
(LB
));
12371 if Raises_Constraint_Error
(Prefix
(N
)) then
12373 -- Preserve Sloc of prefix in the new bounds, so that the
12374 -- posted warning can be removed if we are within unreachable
12377 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
12378 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
12381 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
12382 Analyze_And_Resolve
(N
, Typ
);
12384 -- Ensure that the expanded range does not have side effects
12386 Force_Evaluation
(LB
);
12387 Force_Evaluation
(HB
);
12389 -- Normally after resolving attribute nodes, Eval_Attribute
12390 -- is called to do any possible static evaluation of the node.
12391 -- However, here since the Range attribute has just been
12392 -- transformed into a range expression it is no longer an
12393 -- attribute node and therefore the call needs to be avoided
12394 -- and is accomplished by simply returning from the procedure.
12397 end Range_Attribute
;
12403 when Attribute_Reduce
=>
12405 E1
: constant Node_Id
:= First
(Expressions
(N
));
12406 E2
: constant Node_Id
:= Next
(E1
);
12407 Op
: Entity_Id
:= Empty
;
12409 Index
: Interp_Index
;
12411 function Proper_Op
(Op
: Entity_Id
) return Boolean;
12417 function Proper_Op
(Op
: Entity_Id
) return Boolean is
12418 F1
, F2
: Entity_Id
;
12421 F1
:= First_Formal
(Op
);
12425 F2
:= Next_Formal
(F1
);
12427 or else Present
(Next_Formal
(F2
))
12431 elsif Ekind
(Op
) = E_Procedure
then
12432 return Ekind
(F1
) = E_In_Out_Parameter
12433 and then Covers
(Typ
, Etype
(F1
));
12437 (Ekind
(Op
) = E_Operator
12438 and then Scope
(Op
) = Standard_Standard
)
12439 or else Covers
(Typ
, Etype
(Op
));
12446 if Is_Overloaded
(E1
) then
12447 Get_First_Interp
(E1
, Index
, It
);
12448 while Present
(It
.Nam
) loop
12449 if Proper_Op
(It
.Nam
) then
12451 Set_Entity
(E1
, Op
);
12455 Get_Next_Interp
(Index
, It
);
12458 elsif Nkind
(E1
) = N_Attribute_Reference
12459 and then (Attribute_Name
(E1
) = Name_Max
12460 or else Attribute_Name
(E1
) = Name_Min
)
12464 elsif Proper_Op
(Entity
(E1
)) then
12466 Set_Etype
(N
, Typ
);
12470 Error_Msg_N
("No visible subprogram for reduction", E1
);
12478 -- We will only come here during the prescan of a spec expression
12479 -- containing a Result attribute. In that case the proper Etype has
12480 -- already been set, and nothing more needs to be done here.
12482 when Attribute_Result
=>
12485 ----------------------
12486 -- Unchecked_Access --
12487 ----------------------
12489 -- Processing is shared with Access
12491 -------------------------
12492 -- Unrestricted_Access --
12493 -------------------------
12495 -- Processing is shared with Access
12501 -- Resolve aggregate components in component associations
12503 when Attribute_Update
=> Update
: declare
12504 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
12505 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
12511 -- Set the Etype of the aggregate to that of the prefix, even
12512 -- though the aggregate may not be a proper representation of a
12513 -- value of the type (missing or duplicated associations, etc.)
12514 -- Complete resolution of the prefix. Note that in Ada 2012 it
12515 -- can be a qualified expression that is e.g. an aggregate.
12517 Set_Etype
(Aggr
, Typ
);
12518 Resolve
(Prefix
(N
), Typ
);
12520 -- For an array type, resolve expressions with the component type
12521 -- of the array, and apply constraint checks when needed.
12523 if Is_Array_Type
(Typ
) then
12524 Assoc
:= First
(Component_Associations
(Aggr
));
12525 while Present
(Assoc
) loop
12526 Expr
:= Expression
(Assoc
);
12527 Resolve
(Expr
, Component_Type
(Typ
));
12529 -- The choices in the association are static constants,
12530 -- or static aggregates each of whose components belongs
12531 -- to the proper index type. However, they must also
12532 -- belong to the index subtype (s) of the prefix, which
12533 -- may be a subtype (e.g. given by a slice).
12535 -- Choices may also be identifiers with no staticness
12536 -- requirements, in which case they must resolve to the
12545 C
:= First
(Choices
(Assoc
));
12546 while Present
(C
) loop
12547 Indx
:= First_Index
(Etype
(Prefix
(N
)));
12549 if Nkind
(C
) /= N_Aggregate
then
12550 Analyze_And_Resolve
(C
, Etype
(Indx
));
12552 C_E
:= First
(Expressions
(C
));
12553 while Present
(C_E
) loop
12554 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
12568 -- For a record type, use type of each component, which is
12569 -- recorded during analysis.
12572 Assoc
:= First
(Component_Associations
(Aggr
));
12573 while Present
(Assoc
) loop
12574 Comp
:= First
(Choices
(Assoc
));
12575 Expr
:= Expression
(Assoc
);
12577 if Nkind
(Comp
) /= N_Others_Choice
12578 and then not Error_Posted
(Comp
)
12580 Resolve
(Expr
, Etype
(Entity
(Comp
)));
12592 -- Apply range check. Note that we did not do this during the
12593 -- analysis phase, since we wanted Eval_Attribute to have a
12594 -- chance at finding an illegal out of range value.
12596 when Attribute_Val
=>
12598 -- Note that we do our own Eval_Attribute call here rather than
12599 -- use the common one, because we need to do processing after
12600 -- the call, as per above comment.
12602 Eval_Attribute
(N
);
12604 -- Eval_Attribute may replace the node with a raise CE, or
12605 -- fold it to a constant. Obviously we only apply a scalar
12606 -- range check if this did not happen.
12608 if Nkind
(N
) = N_Attribute_Reference
12609 and then Attribute_Name
(N
) = Name_Val
12611 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
12620 -- Prefix of Version attribute can be a subprogram name which
12621 -- must not be resolved, since this is not a call.
12623 when Attribute_Version
=>
12626 ----------------------
12627 -- Other Attributes --
12628 ----------------------
12630 -- For other attributes, resolve prefix unless it is a type. If
12631 -- the attribute reference itself is a type name ('Base and 'Class)
12632 -- then this is only legal within a task or protected record.
12635 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
12639 -- If the attribute reference itself is a type name ('Base,
12640 -- 'Class) then this is only legal within a task or protected
12641 -- record. What is this all about ???
12643 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
12644 if Is_Concurrent_Type
(Entity
(N
))
12645 and then In_Open_Scopes
(Entity
(P
))
12650 ("invalid use of subtype name in expression or call", N
);
12654 -- For attributes whose argument may be a string, complete
12655 -- resolution of argument now. This avoids premature expansion
12656 -- (and the creation of transient scopes) before the attribute
12657 -- reference is resolved.
12660 when Attribute_Valid_Value | Attribute_Value
=>
12661 Resolve
(First
(Expressions
(N
)), Standard_String
);
12663 when Attribute_Wide_Value
=>
12664 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
12666 when Attribute_Wide_Wide_Value
=>
12667 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
12669 when others => null;
12672 -- Ensure that attribute expressions are resolved at this stage;
12673 -- required for preanalyzed references to discriminants since
12674 -- their resolution (and expansion) will take care of updating
12675 -- their Entity attribute to reference their discriminal.
12678 and then Present
(Expressions
(N
))
12681 Expr
: Node_Id
:= First
(Expressions
(N
));
12684 while Present
(Expr
) loop
12685 if not Analyzed
(Expr
) then
12686 Resolve
(Expr
, Etype
(Expr
));
12694 -- If the prefix of the attribute is a class-wide type then it
12695 -- will be expanded into a dispatching call to a predefined
12696 -- primitive. Therefore we must check for potential violation
12697 -- of such restriction.
12699 if Is_Class_Wide_Type
(Etype
(P
)) then
12700 Check_Restriction
(No_Dispatching_Calls
, N
);
12704 -- Mark use clauses of the original prefix if the attribute is applied
12707 if Nkind
(Original_Node
(P
)) in N_Has_Entity
12708 and then Present
(Entity
(Original_Node
(P
)))
12710 Mark_Use_Clauses
(Original_Node
(P
));
12713 -- Normally the Freezing is done by Resolve but sometimes the Prefix
12714 -- is not resolved, in which case the freezing must be done now.
12716 -- For an elaboration check on a subprogram, we do not freeze its type.
12717 -- It may be declared in an unrelated scope, in particular in the case
12718 -- of a generic function whose type may remain unelaborated.
12720 if Attr_Id
= Attribute_Elaborated
then
12723 -- Should this be restricted to Expander_Active???
12726 Freeze_Expression
(P
);
12729 -- Finally perform static evaluation on the attribute reference
12731 Analyze_Dimension
(N
);
12732 Eval_Attribute
(N
);
12733 end Resolve_Attribute
;
12735 ------------------------
12736 -- Set_Boolean_Result --
12737 ------------------------
12739 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
12741 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(B
), Sloc
(N
)));
12742 end Set_Boolean_Result
;
12744 --------------------------------
12745 -- Stream_Attribute_Available --
12746 --------------------------------
12748 function Stream_Attribute_Available
12750 Nam
: TSS_Name_Type
;
12751 Partial_View
: Entity_Id
:= Empty
) return Boolean
12753 Etyp
: Entity_Id
:= Typ
;
12755 Real_Rep
: Node_Id
;
12757 -- Start of processing for Stream_Attribute_Available
12760 -- Test if the attribute is specified directly on the type
12762 if Has_Stream_Attribute_Definition
(Typ
, Nam
, Real_Rep
) then
12766 -- We assume class-wide types have stream attributes
12767 -- when they are not limited. Otherwise we recurse on the
12770 if Is_Class_Wide_Type
(Typ
) then
12771 return not Is_Limited_Type
(Typ
)
12772 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
12775 -- Non-class-wide abstract types cannot have Input streams
12778 if Nam
= TSS_Stream_Input
12779 and then Is_Abstract_Type
(Typ
)
12780 and then not Is_Class_Wide_Type
(Typ
)
12785 -- Otherwise, nonlimited types have stream attributes
12787 if not (Is_Limited_Type
(Typ
)
12788 or else (Present
(Partial_View
)
12789 and then Is_Limited_Type
(Partial_View
)))
12794 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
12796 if Nam
= TSS_Stream_Input
12797 and then Ada_Version
>= Ada_2005
12798 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
, Real_Rep
)
12802 elsif Nam
= TSS_Stream_Output
12803 and then Ada_Version
>= Ada_2005
12804 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
, Real_Rep
)
12809 -- Case of Read and Write: check for attribute definition clause that
12810 -- applies to an ancestor type.
12812 while Etype
(Etyp
) /= Etyp
loop
12814 Derived_Type
: constant Entity_Id
:= Etyp
;
12816 Etyp
:= Etype
(Etyp
);
12818 if Has_Stream_Attribute_Definition
(Etyp
, Nam
, Real_Rep
) then
12819 if not Derivation_Too_Early_To_Inherit
(Derived_Type
, Nam
) then
12826 if Ada_Version
< Ada_2005
then
12828 -- In Ada 95 mode, also consider a non-visible definition
12831 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
12834 and then Stream_Attribute_Available
12835 (Btyp
, Nam
, Partial_View
=> Typ
);
12840 end Stream_Attribute_Available
;