1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
28 with Atree
; use Atree
;
29 with Casing
; use Casing
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
35 with Exp_Dist
; use Exp_Dist
;
36 with Exp_Util
; use Exp_Util
;
37 with Expander
; use Expander
;
38 with Freeze
; use Freeze
;
39 with Gnatvsn
; use Gnatvsn
;
40 with Itypes
; use Itypes
;
42 with Lib
.Xref
; use Lib
.Xref
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Cat
; use Sem_Cat
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch10
; use Sem_Ch10
;
56 with Sem_Dim
; use Sem_Dim
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Elab
; use Sem_Elab
;
59 with Sem_Elim
; use Sem_Elim
;
60 with Sem_Eval
; use Sem_Eval
;
61 with Sem_Prag
; use Sem_Prag
;
62 with Sem_Res
; use Sem_Res
;
63 with Sem_Type
; use Sem_Type
;
64 with Sem_Util
; use Sem_Util
;
66 with Stand
; use Stand
;
67 with Sinfo
; use Sinfo
;
68 with Sinput
; use Sinput
;
70 with Stringt
; use Stringt
;
72 with Stylesw
; use Stylesw
;
73 with Targparm
; use Targparm
;
74 with Ttypes
; use Ttypes
;
75 with Tbuild
; use Tbuild
;
76 with Uintp
; use Uintp
;
77 with Uname
; use Uname
;
78 with Urealp
; use Urealp
;
80 with System
.CRC32
; use System
.CRC32
;
82 package body Sem_Attr
is
84 True_Value
: constant Uint
:= Uint_1
;
85 False_Value
: constant Uint
:= Uint_0
;
86 -- Synonyms to be used when these constants are used as Boolean values
88 Bad_Attribute
: exception;
89 -- Exception raised if an error is detected during attribute processing,
90 -- used so that we can abandon the processing so we don't run into
91 -- trouble with cascaded errors.
93 -- The following array is the list of attributes defined in the Ada 83 RM.
94 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
95 -- modes all these attributes are recognized, even if removed in Ada 95.
97 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
100 Attribute_Alignment |
103 Attribute_Constrained |
110 Attribute_First_Bit |
116 Attribute_Leading_Part |
118 Attribute_Machine_Emax |
119 Attribute_Machine_Emin |
120 Attribute_Machine_Mantissa |
121 Attribute_Machine_Overflows |
122 Attribute_Machine_Radix |
123 Attribute_Machine_Rounds |
129 Attribute_Safe_Emax |
130 Attribute_Safe_Large |
131 Attribute_Safe_Small |
134 Attribute_Storage_Size |
136 Attribute_Terminated |
139 Attribute_Width => True,
142 -- The following array is the list of attributes defined in the Ada 2005
143 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
144 -- but in Ada 95 they are considered to be implementation defined.
146 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
147 Attribute_Machine_Rounding |
150 Attribute_Stream_Size |
151 Attribute_Wide_Wide_Width
=> True,
154 -- The following array is the list of attributes defined in the Ada 2012
155 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
156 -- and Ada 2005 modes, but are considered to be implementation defined.
158 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
159 Attribute_First_Valid |
160 Attribute_Has_Same_Storage |
161 Attribute_Last_Valid |
162 Attribute_Max_Alignment_For_Allocation => True,
165 -- The following array contains all attributes that imply a modification
166 -- of their prefixes or result in an access value. Such prefixes can be
167 -- considered as lvalues.
169 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
170 Attribute_Class_Array'(
175 Attribute_Unchecked_Access |
176 Attribute_Unrestricted_Access
=> True,
179 -----------------------
180 -- Local_Subprograms --
181 -----------------------
183 procedure Eval_Attribute
(N
: Node_Id
);
184 -- Performs compile time evaluation of attributes where possible, leaving
185 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
186 -- set, and replacing the node with a literal node if the value can be
187 -- computed at compile time. All static attribute references are folded,
188 -- as well as a number of cases of non-static attributes that can always
189 -- be computed at compile time (e.g. floating-point model attributes that
190 -- are applied to non-static subtypes). Of course in such cases, the
191 -- Is_Static_Expression flag will not be set on the resulting literal.
192 -- Note that the only required action of this procedure is to catch the
193 -- static expression cases as described in the RM. Folding of other cases
194 -- is done where convenient, but some additional non-static folding is in
195 -- Expand_N_Attribute_Reference in cases where this is more convenient.
197 function Is_Anonymous_Tagged_Base
199 Typ
: Entity_Id
) return Boolean;
200 -- For derived tagged types that constrain parent discriminants we build
201 -- an anonymous unconstrained base type. We need to recognize the relation
202 -- between the two when analyzing an access attribute for a constrained
203 -- component, before the full declaration for Typ has been analyzed, and
204 -- where therefore the prefix of the attribute does not match the enclosing
207 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean);
208 -- Rewrites node N with an occurrence of either Standard_False or
209 -- Standard_True, depending on the value of the parameter B. The
210 -- result is marked as a static expression.
212 function Statically_Denotes_Object
(N
: Node_Id
) return Boolean;
213 -- Predicate used to check the legality of the prefix to 'Loop_Entry and
214 -- 'Old, when the prefix is not an entity name. Current RM specfies that
215 -- the prefix must be a direct or expanded name, but it has been proposed
216 -- that the prefix be allowed to be a selected component that does not
217 -- depend on a discriminant, or an indexed component with static indices.
218 -- Current code for this predicate implements this more permissive
221 -----------------------
222 -- Analyze_Attribute --
223 -----------------------
225 procedure Analyze_Attribute
(N
: Node_Id
) is
226 Loc
: constant Source_Ptr
:= Sloc
(N
);
227 Aname
: constant Name_Id
:= Attribute_Name
(N
);
228 P
: constant Node_Id
:= Prefix
(N
);
229 Exprs
: constant List_Id
:= Expressions
(N
);
230 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
234 P_Type
: Entity_Id
:= Empty
;
235 -- Type of prefix after analysis
237 P_Base_Type
: Entity_Id
:= Empty
;
238 -- Base type of prefix after analysis
240 -----------------------
241 -- Local Subprograms --
242 -----------------------
244 procedure Address_Checks
;
245 -- Semantic checks for valid use of Address attribute. This was made
246 -- a separate routine with the idea of using it for unrestricted access
247 -- which seems like it should follow the same rules, but that turned
248 -- out to be impractical. So now this is only used for Address.
250 procedure Analyze_Access_Attribute
;
251 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
252 -- Internally, Id distinguishes which of the three cases is involved.
254 procedure Analyze_Attribute_Old_Result
255 (Legal
: out Boolean;
256 Spec_Id
: out Entity_Id
);
257 -- Common processing for attributes 'Old and 'Result. The routine checks
258 -- that the attribute appears in a postcondition-like aspect or pragma
259 -- associated with a suitable subprogram or a body. Flag Legal is set
260 -- when the above criteria are met. Spec_Id denotes the entity of the
261 -- subprogram [body] or Empty if the attribute is illegal.
263 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
);
264 -- Common processing for attributes 'Img, 'Image, 'Wide_Image, and
265 -- 'Wide_Wide_Image. The routine checks that the prefix is valid and
266 -- sets the type of the attribute to the one specified by Str_Typ (e.g.
267 -- Standard_String for 'Image and Standard_Wide_String for 'Wide_Image).
269 procedure Bad_Attribute_For_Predicate
;
270 -- Output error message for use of a predicate (First, Last, Range) not
271 -- allowed with a type that has predicates. If the type is a generic
272 -- actual, then the message is a warning, and we generate code to raise
273 -- program error with an appropriate reason. No error message is given
274 -- for internally generated uses of the attributes. This legality rule
275 -- only applies to scalar types.
277 procedure Check_Array_Or_Scalar_Type
;
278 -- Common procedure used by First, Last, Range attribute to check
279 -- that the prefix is a constrained array or scalar type, or a name
280 -- of an array object, and that an argument appears only if appropriate
281 -- (i.e. only in the array case).
283 procedure Check_Array_Type
;
284 -- Common semantic checks for all array attributes. Checks that the
285 -- prefix is a constrained array type or the name of an array object.
286 -- The error message for non-arrays is specialized appropriately.
288 procedure Check_Asm_Attribute
;
289 -- Common semantic checks for Asm_Input and Asm_Output attributes
291 procedure Check_Component
;
292 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
293 -- Position. Checks prefix is an appropriate selected component.
295 procedure Check_Decimal_Fixed_Point_Type
;
296 -- Check that prefix of attribute N is a decimal fixed-point type
298 procedure Check_Dereference
;
299 -- If the prefix of attribute is an object of an access type, then
300 -- introduce an explicit dereference, and adjust P_Type accordingly.
302 procedure Check_Discrete_Type
;
303 -- Verify that prefix of attribute N is a discrete type
306 -- Check that no attribute arguments are present
308 procedure Check_Either_E0_Or_E1
;
309 -- Check that there are zero or one attribute arguments present
312 -- Check that exactly one attribute argument is present
315 -- Check that two attribute arguments are present
317 procedure Check_Enum_Image
;
318 -- If the prefix type of 'Image is an enumeration type, set all its
319 -- literals as referenced, since the image function could possibly end
320 -- up referencing any of the literals indirectly. Same for Enum_Val.
321 -- Set the flag only if the reference is in the main code unit. Same
322 -- restriction when resolving 'Value; otherwise an improperly set
323 -- reference when analyzing an inlined body will lose a proper
324 -- warning on a useless with_clause.
326 procedure Check_First_Last_Valid
;
327 -- Perform all checks for First_Valid and Last_Valid attributes
329 procedure Check_Fixed_Point_Type
;
330 -- Verify that prefix of attribute N is a fixed type
332 procedure Check_Fixed_Point_Type_0
;
333 -- Verify that prefix of attribute N is a fixed type and that
334 -- no attribute expressions are present.
336 procedure Check_Floating_Point_Type
;
337 -- Verify that prefix of attribute N is a float type
339 procedure Check_Floating_Point_Type_0
;
340 -- Verify that prefix of attribute N is a float type and that
341 -- no attribute expressions are present.
343 procedure Check_Floating_Point_Type_1
;
344 -- Verify that prefix of attribute N is a float type and that
345 -- exactly one attribute expression is present.
347 procedure Check_Floating_Point_Type_2
;
348 -- Verify that prefix of attribute N is a float type and that
349 -- two attribute expressions are present
351 procedure Check_SPARK_05_Restriction_On_Attribute
;
352 -- Issue an error in formal mode because attribute N is allowed
354 procedure Check_Integer_Type
;
355 -- Verify that prefix of attribute N is an integer type
357 procedure Check_Modular_Integer_Type
;
358 -- Verify that prefix of attribute N is a modular integer type
360 procedure Check_Not_CPP_Type
;
361 -- Check that P (the prefix of the attribute) is not an CPP type
362 -- for which no Ada predefined primitive is available.
364 procedure Check_Not_Incomplete_Type
;
365 -- Check that P (the prefix of the attribute) is not an incomplete
366 -- type or a private type for which no full view has been given.
368 procedure Check_Object_Reference
(P
: Node_Id
);
369 -- Check that P is an object reference
371 procedure Check_PolyORB_Attribute
;
372 -- Validity checking for PolyORB/DSA attribute
374 procedure Check_Program_Unit
;
375 -- Verify that prefix of attribute N is a program unit
377 procedure Check_Real_Type
;
378 -- Verify that prefix of attribute N is fixed or float type
380 procedure Check_Scalar_Type
;
381 -- Verify that prefix of attribute N is a scalar type
383 procedure Check_Standard_Prefix
;
384 -- Verify that prefix of attribute N is package Standard. Also checks
385 -- that there are no arguments.
387 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
388 -- Validity checking for stream attribute. Nam is the TSS name of the
389 -- corresponding possible defined attribute function (e.g. for the
390 -- Read attribute, Nam will be TSS_Stream_Read).
392 procedure Check_System_Prefix
;
393 -- Verify that prefix of attribute N is package System
395 procedure Check_Task_Prefix
;
396 -- Verify that prefix of attribute N is a task or task type
398 procedure Check_Type
;
399 -- Verify that the prefix of attribute N is a type
401 procedure Check_Unit_Name
(Nod
: Node_Id
);
402 -- Check that Nod is of the form of a library unit name, i.e that
403 -- it is an identifier, or a selected component whose prefix is
404 -- itself of the form of a library unit name. Note that this is
405 -- quite different from Check_Program_Unit, since it only checks
406 -- the syntactic form of the name, not the semantic identity. This
407 -- is because it is used with attributes (Elab_Body, Elab_Spec and
408 -- Elaborated) which can refer to non-visible unit.
410 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
411 pragma No_Return
(Error_Attr
);
412 procedure Error_Attr
;
413 pragma No_Return
(Error_Attr
);
414 -- Posts error using Error_Msg_N at given node, sets type of attribute
415 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
416 -- semantic processing. The message typically contains a % insertion
417 -- character which is replaced by the attribute name. The call with
418 -- no arguments is used when the caller has already generated the
419 -- required error messages.
421 procedure Error_Attr_P
(Msg
: String);
422 pragma No_Return
(Error_Attr_P
);
423 -- Like Error_Attr, but error is posted at the start of the prefix
425 procedure Legal_Formal_Attribute
;
426 -- Common processing for attributes Definite and Has_Discriminants.
427 -- Checks that prefix is generic indefinite formal type.
429 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
430 -- Common processing for attributes Max_Alignment_For_Allocation and
431 -- Max_Size_In_Storage_Elements.
434 -- Common processing for attributes Max and Min
436 procedure Standard_Attribute
(Val
: Int
);
437 -- Used to process attributes whose prefix is package Standard which
438 -- yield values of type Universal_Integer. The attribute reference
439 -- node is rewritten with an integer literal of the given value which
440 -- is marked as static.
442 procedure Uneval_Old_Msg
;
443 -- Called when Loop_Entry or Old is used in a potentially unevaluated
444 -- expression. Generates appropriate message or warning depending on
445 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
446 -- node in the aspect case).
448 procedure Unexpected_Argument
(En
: Node_Id
);
449 pragma No_Return
(Unexpected_Argument
);
450 -- Signal unexpected attribute argument (En is the argument), and then
451 -- raises Bad_Attribute to avoid any further semantic processing.
453 procedure Validate_Non_Static_Attribute_Function_Call
;
454 -- Called when processing an attribute that is a function call to a
455 -- non-static function, i.e. an attribute function that either takes
456 -- non-scalar arguments or returns a non-scalar result. Verifies that
457 -- such a call does not appear in a preelaborable context.
463 procedure Address_Checks
is
465 -- An Address attribute created by expansion is legal even when it
466 -- applies to other entity-denoting expressions.
468 if not Comes_From_Source
(N
) then
471 -- Address attribute on a protected object self reference is legal
473 elsif Is_Protected_Self_Reference
(P
) then
476 -- Address applied to an entity
478 elsif Is_Entity_Name
(P
) then
480 Ent
: constant Entity_Id
:= Entity
(P
);
483 if Is_Subprogram
(Ent
) then
484 Set_Address_Taken
(Ent
);
485 Kill_Current_Values
(Ent
);
487 -- An Address attribute is accepted when generated by the
488 -- compiler for dispatching operation, and an error is
489 -- issued once the subprogram is frozen (to avoid confusing
490 -- errors about implicit uses of Address in the dispatch
491 -- table initialization).
493 if Has_Pragma_Inline_Always
(Entity
(P
))
494 and then Comes_From_Source
(P
)
497 ("prefix of % attribute cannot be Inline_Always "
500 -- It is illegal to apply 'Address to an intrinsic
501 -- subprogram. This is now formalized in AI05-0095.
502 -- In an instance, an attempt to obtain 'Address of an
503 -- intrinsic subprogram (e.g the renaming of a predefined
504 -- operator that is an actual) raises Program_Error.
506 elsif Convention
(Ent
) = Convention_Intrinsic
then
509 Make_Raise_Program_Error
(Loc
,
510 Reason
=> PE_Address_Of_Intrinsic
));
513 Error_Msg_Name_1
:= Aname
;
515 ("cannot take % of intrinsic subprogram", N
);
518 -- Issue an error if prefix denotes an eliminated subprogram
521 Check_For_Eliminated_Subprogram
(P
, Ent
);
524 -- Object or label reference
526 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
527 Set_Address_Taken
(Ent
);
529 -- Deal with No_Implicit_Aliasing restriction
531 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
532 if not Is_Aliased_View
(P
) then
533 Check_Restriction
(No_Implicit_Aliasing
, P
);
535 Check_No_Implicit_Aliasing
(P
);
539 -- If we have an address of an object, and the attribute
540 -- comes from source, then set the object as potentially
541 -- source modified. We do this because the resulting address
542 -- can potentially be used to modify the variable and we
543 -- might not detect this, leading to some junk warnings.
545 Set_Never_Set_In_Source
(Ent
, False);
547 -- Allow Address to be applied to task or protected type,
548 -- returning null address (what is that about???)
550 elsif (Is_Concurrent_Type
(Etype
(Ent
))
551 and then Etype
(Ent
) = Base_Type
(Ent
))
552 or else Ekind
(Ent
) = E_Package
553 or else Is_Generic_Unit
(Ent
)
556 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
558 -- Anything else is illegal
561 Error_Attr
("invalid prefix for % attribute", P
);
567 elsif Is_Object_Reference
(P
) then
570 -- Subprogram called using dot notation
572 elsif Nkind
(P
) = N_Selected_Component
573 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
577 -- What exactly are we allowing here ??? and is this properly
578 -- documented in the sinfo documentation for this node ???
580 elsif Relaxed_RM_Semantics
581 and then Nkind
(P
) = N_Attribute_Reference
585 -- All other non-entity name cases are illegal
588 Error_Attr
("invalid prefix for % attribute", P
);
592 ------------------------------
593 -- Analyze_Access_Attribute --
594 ------------------------------
596 procedure Analyze_Access_Attribute
is
597 Acc_Type
: Entity_Id
;
602 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
603 -- Build an access-to-object type whose designated type is DT,
604 -- and whose Ekind is appropriate to the attribute type. The
605 -- type that is constructed is returned as the result.
607 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
608 -- Build an access to subprogram whose designated type is the type of
609 -- the prefix. If prefix is overloaded, so is the node itself. The
610 -- result is stored in Acc_Type.
612 function OK_Self_Reference
return Boolean;
613 -- An access reference whose prefix is a type can legally appear
614 -- within an aggregate, where it is obtained by expansion of
615 -- a defaulted aggregate. The enclosing aggregate that contains
616 -- the self-referenced is flagged so that the self-reference can
617 -- be expanded into a reference to the target object (see exp_aggr).
619 ------------------------------
620 -- Build_Access_Object_Type --
621 ------------------------------
623 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
624 Typ
: constant Entity_Id
:=
626 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
628 Set_Etype
(Typ
, Typ
);
630 Set_Associated_Node_For_Itype
(Typ
, N
);
631 Set_Directly_Designated_Type
(Typ
, DT
);
633 end Build_Access_Object_Type
;
635 ----------------------------------
636 -- Build_Access_Subprogram_Type --
637 ----------------------------------
639 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
640 Index
: Interp_Index
;
643 procedure Check_Local_Access
(E
: Entity_Id
);
644 -- Deal with possible access to local subprogram. If we have such
645 -- an access, we set a flag to kill all tracked values on any call
646 -- because this access value may be passed around, and any called
647 -- code might use it to access a local procedure which clobbers a
648 -- tracked value. If the scope is a loop or block, indicate that
649 -- value tracking is disabled for the enclosing subprogram.
651 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
652 -- Distinguish between access to regular/protected subprograms
654 ------------------------
655 -- Check_Local_Access --
656 ------------------------
658 procedure Check_Local_Access
(E
: Entity_Id
) is
660 if not Is_Library_Level_Entity
(E
) then
661 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
662 Set_Suppress_Value_Tracking_On_Call
663 (Nearest_Dynamic_Scope
(Current_Scope
));
665 end Check_Local_Access
;
671 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
673 if Convention
(E
) = Convention_Protected
then
674 return E_Access_Protected_Subprogram_Type
;
676 return E_Access_Subprogram_Type
;
680 -- Start of processing for Build_Access_Subprogram_Type
683 -- In the case of an access to subprogram, use the name of the
684 -- subprogram itself as the designated type. Type-checking in
685 -- this case compares the signatures of the designated types.
687 -- Note: This fragment of the tree is temporarily malformed
688 -- because the correct tree requires an E_Subprogram_Type entity
689 -- as the designated type. In most cases this designated type is
690 -- later overridden by the semantics with the type imposed by the
691 -- context during the resolution phase. In the specific case of
692 -- the expression Address!(Prim'Unrestricted_Access), used to
693 -- initialize slots of dispatch tables, this work will be done by
694 -- the expander (see Exp_Aggr).
696 -- The reason to temporarily add this kind of node to the tree
697 -- instead of a proper E_Subprogram_Type itype, is the following:
698 -- in case of errors found in the source file we report better
699 -- error messages. For example, instead of generating the
702 -- "expected access to subprogram with profile
703 -- defined at line X"
705 -- we currently generate:
707 -- "expected access to function Z defined at line X"
709 Set_Etype
(N
, Any_Type
);
711 if not Is_Overloaded
(P
) then
712 Check_Local_Access
(Entity
(P
));
714 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
715 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
716 Set_Is_Public
(Acc_Type
, False);
717 Set_Etype
(Acc_Type
, Acc_Type
);
718 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
719 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
720 Set_Etype
(N
, Acc_Type
);
721 Freeze_Before
(N
, Acc_Type
);
725 Get_First_Interp
(P
, Index
, It
);
726 while Present
(It
.Nam
) loop
727 Check_Local_Access
(It
.Nam
);
729 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
730 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
731 Set_Is_Public
(Acc_Type
, False);
732 Set_Etype
(Acc_Type
, Acc_Type
);
733 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
734 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
735 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
736 Freeze_Before
(N
, Acc_Type
);
739 Get_Next_Interp
(Index
, It
);
743 -- Cannot be applied to intrinsic. Looking at the tests above,
744 -- the only way Etype (N) can still be set to Any_Type is if
745 -- Is_Intrinsic_Subprogram was True for some referenced entity.
747 if Etype
(N
) = Any_Type
then
748 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
750 end Build_Access_Subprogram_Type
;
752 ----------------------
753 -- OK_Self_Reference --
754 ----------------------
756 function OK_Self_Reference
return Boolean is
763 (Nkind
(Par
) = N_Component_Association
764 or else Nkind
(Par
) in N_Subexpr
)
766 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
767 if Etype
(Par
) = Typ
then
768 Set_Has_Self_Reference
(Par
);
770 -- Check the context: the aggregate must be part of the
771 -- initialization of a type or component, or it is the
772 -- resulting expansion in an initialization procedure.
774 if Is_Init_Proc
(Current_Scope
) then
778 while Present
(Par
) loop
779 if Nkind
(Par
) = N_Full_Type_Declaration
then
794 -- No enclosing aggregate, or not a self-reference
797 end OK_Self_Reference
;
799 -- Start of processing for Analyze_Access_Attribute
802 Check_SPARK_05_Restriction_On_Attribute
;
805 if Nkind
(P
) = N_Character_Literal
then
807 ("prefix of % attribute cannot be enumeration literal");
810 -- Preserve relevant elaboration-related attributes of the context
811 -- which are no longer available or very expensive to recompute once
812 -- analysis, resolution, and expansion are over.
814 Mark_Elaboration_Attributes
819 -- Save the scenario for later examination by the ABE Processing
822 Record_Elaboration_Scenario
(N
);
824 -- Case of access to subprogram
826 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
827 if Has_Pragma_Inline_Always
(Entity
(P
)) then
829 ("prefix of % attribute cannot be Inline_Always subprogram");
831 elsif Aname
= Name_Unchecked_Access
then
832 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
835 -- Issue an error if the prefix denotes an eliminated subprogram
837 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
839 -- Check for obsolescent subprogram reference
841 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
843 -- Build the appropriate subprogram type
845 Build_Access_Subprogram_Type
(P
);
847 -- For P'Access or P'Unrestricted_Access, where P is a nested
848 -- subprogram, we might be passing P to another subprogram (but we
849 -- don't check that here), which might call P. P could modify
850 -- local variables, so we need to kill current values. It is
851 -- important not to do this for library-level subprograms, because
852 -- Kill_Current_Values is very inefficient in the case of library
853 -- level packages with lots of tagged types.
855 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
858 -- Do not kill values on nodes initializing dispatch tables
859 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
860 -- is currently generated by the expander only for this
861 -- purpose. Done to keep the quality of warnings currently
862 -- generated by the compiler (otherwise any declaration of
863 -- a tagged type cleans constant indications from its scope).
865 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
866 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
868 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
869 and then Is_Dispatching_Operation
870 (Directly_Designated_Type
(Etype
(N
)))
880 -- Component is an operation of a protected type
882 elsif Nkind
(P
) = N_Selected_Component
883 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
885 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
886 Error_Attr_P
("prefix of % attribute must be subprogram");
889 Build_Access_Subprogram_Type
(Selector_Name
(P
));
893 -- Deal with incorrect reference to a type, but note that some
894 -- accesses are allowed: references to the current type instance,
895 -- or in Ada 2005 self-referential pointer in a default-initialized
898 if Is_Entity_Name
(P
) then
901 -- The reference may appear in an aggregate that has been expanded
902 -- into a loop. Locate scope of type definition, if any.
904 Scop
:= Current_Scope
;
905 while Ekind
(Scop
) = E_Loop
loop
906 Scop
:= Scope
(Scop
);
909 if Is_Type
(Typ
) then
911 -- OK if we are within the scope of a limited type
912 -- let's mark the component as having per object constraint
914 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
922 Q
: Node_Id
:= Parent
(N
);
926 and then Nkind
(Q
) /= N_Component_Declaration
932 Set_Has_Per_Object_Constraint
933 (Defining_Identifier
(Q
), True);
937 if Nkind
(P
) = N_Expanded_Name
then
939 ("current instance prefix must be a direct name", P
);
942 -- If a current instance attribute appears in a component
943 -- constraint it must appear alone; other contexts (spec-
944 -- expressions, within a task body) are not subject to this
947 if not In_Spec_Expression
948 and then not Has_Completion
(Scop
)
950 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
951 N_Index_Or_Discriminant_Constraint
)
954 ("current instance attribute must appear alone", N
);
957 if Is_CPP_Class
(Root_Type
(Typ
)) then
959 ("??current instance unsupported for derivations of "
960 & "'C'P'P types", N
);
963 -- OK if we are in initialization procedure for the type
964 -- in question, in which case the reference to the type
965 -- is rewritten as a reference to the current object.
967 elsif Ekind
(Scop
) = E_Procedure
968 and then Is_Init_Proc
(Scop
)
969 and then Etype
(First_Formal
(Scop
)) = Typ
972 Make_Attribute_Reference
(Loc
,
973 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
974 Attribute_Name
=> Name_Unrestricted_Access
));
978 -- OK if a task type, this test needs sharpening up ???
980 elsif Is_Task_Type
(Typ
) then
983 -- OK if self-reference in an aggregate in Ada 2005, and
984 -- the reference comes from a copied default expression.
986 -- Note that we check legality of self-reference even if the
987 -- expression comes from source, e.g. when a single component
988 -- association in an aggregate has a box association.
990 elsif Ada_Version
>= Ada_2005
991 and then OK_Self_Reference
995 -- OK if reference to current instance of a protected object
997 elsif Is_Protected_Self_Reference
(P
) then
1000 -- Otherwise we have an error case
1003 Error_Attr
("% attribute cannot be applied to type", P
);
1009 -- If we fall through, we have a normal access to object case
1011 -- Unrestricted_Access is (for now) legal wherever an allocator would
1012 -- be legal, so its Etype is set to E_Allocator. The expected type
1013 -- of the other attributes is a general access type, and therefore
1014 -- we label them with E_Access_Attribute_Type.
1016 if not Is_Overloaded
(P
) then
1017 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
1018 Set_Etype
(N
, Acc_Type
);
1022 Index
: Interp_Index
;
1025 Set_Etype
(N
, Any_Type
);
1026 Get_First_Interp
(P
, Index
, It
);
1027 while Present
(It
.Typ
) loop
1028 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1029 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1030 Get_Next_Interp
(Index
, It
);
1035 -- Special cases when we can find a prefix that is an entity name
1044 if Is_Entity_Name
(PP
) then
1047 -- If we have an access to an object, and the attribute
1048 -- comes from source, then set the object as potentially
1049 -- source modified. We do this because the resulting access
1050 -- pointer can be used to modify the variable, and we might
1051 -- not detect this, leading to some junk warnings.
1053 -- We only do this for source references, since otherwise
1054 -- we can suppress warnings, e.g. from the unrestricted
1055 -- access generated for validity checks in -gnatVa mode.
1057 if Comes_From_Source
(N
) then
1058 Set_Never_Set_In_Source
(Ent
, False);
1061 -- Mark entity as address taken in the case of
1062 -- 'Unrestricted_Access or subprograms, and kill current
1065 if Aname
= Name_Unrestricted_Access
1066 or else Is_Subprogram
(Ent
)
1068 Set_Address_Taken
(Ent
);
1071 Kill_Current_Values
(Ent
);
1074 elsif Nkind_In
(PP
, N_Selected_Component
,
1075 N_Indexed_Component
)
1084 end Analyze_Access_Attribute
;
1086 ----------------------------------
1087 -- Analyze_Attribute_Old_Result --
1088 ----------------------------------
1090 procedure Analyze_Attribute_Old_Result
1091 (Legal
: out Boolean;
1092 Spec_Id
: out Entity_Id
)
1094 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1095 -- Verify that the attribute appears within pragma Check that mimics
1098 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1099 -- Verify that the attribute appears within a consequence of aspect
1100 -- or pragma Contract_Cases denoted by Prag.
1102 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1103 -- Verify that the attribute appears within the "Ensures" argument of
1104 -- aspect or pragma Test_Case denoted by Prag.
1108 Encl_Nod
: Node_Id
) return Boolean;
1109 -- Subsidiary to Check_Placemenet_In_XXX. Determine whether arbitrary
1110 -- node Nod is within enclosing node Encl_Nod.
1112 procedure Placement_Error
;
1113 pragma No_Return
(Placement_Error
);
1114 -- Emit a general error when the attributes does not appear in a
1115 -- postcondition-like aspect or pragma, and then raises Bad_Attribute
1116 -- to avoid any further semantic processing.
1118 ------------------------------
1119 -- Check_Placement_In_Check --
1120 ------------------------------
1122 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1123 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1124 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1127 -- The "Name" argument of pragma Check denotes a postcondition
1129 if Nam_In
(Nam
, Name_Post
,
1136 -- Otherwise the placement of the attribute is illegal
1141 end Check_Placement_In_Check
;
1143 ---------------------------------------
1144 -- Check_Placement_In_Contract_Cases --
1145 ---------------------------------------
1147 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1153 -- Obtain the argument of the aspect or pragma
1155 if Nkind
(Prag
) = N_Aspect_Specification
then
1158 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1161 Cases
:= Expression
(Arg
);
1163 if Present
(Component_Associations
(Cases
)) then
1164 CCase
:= First
(Component_Associations
(Cases
));
1165 while Present
(CCase
) loop
1167 -- Detect whether the attribute appears within the
1168 -- consequence of the current contract case.
1170 if Nkind
(CCase
) = N_Component_Association
1171 and then Is_Within
(N
, Expression
(CCase
))
1180 -- Otherwise aspect or pragma Contract_Cases is either malformed
1181 -- or the attribute does not appear within a consequence.
1184 ("attribute % must appear in the consequence of a contract case",
1186 end Check_Placement_In_Contract_Cases
;
1188 ----------------------------------
1189 -- Check_Placement_In_Test_Case --
1190 ----------------------------------
1192 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1193 Arg
: constant Node_Id
:=
1196 Arg_Nam
=> Name_Ensures
,
1197 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1200 -- Detect whether the attribute appears within the "Ensures"
1201 -- expression of aspect or pragma Test_Case.
1203 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1208 ("attribute % must appear in the ensures expression of a "
1211 end Check_Placement_In_Test_Case
;
1219 Encl_Nod
: Node_Id
) return Boolean
1225 while Present
(Par
) loop
1226 if Par
= Encl_Nod
then
1229 -- Prevent the search from going too far
1231 elsif Is_Body_Or_Package_Declaration
(Par
) then
1235 Par
:= Parent
(Par
);
1241 ---------------------
1242 -- Placement_Error --
1243 ---------------------
1245 procedure Placement_Error
is
1247 if Aname
= Name_Old
then
1248 Error_Attr
("attribute % can only appear in postcondition", P
);
1250 -- Specialize the error message for attribute 'Result
1254 ("attribute % can only appear in postcondition of function",
1257 end Placement_Error
;
1263 Subp_Decl
: Node_Id
;
1265 -- Start of processing for Analyze_Attribute_Old_Result
1268 -- Assume that the attribute is illegal
1273 -- Traverse the parent chain to find the aspect or pragma where the
1274 -- attribute resides.
1277 while Present
(Prag
) loop
1278 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1281 -- Prevent the search from going too far
1283 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1287 Prag
:= Parent
(Prag
);
1290 -- The attribute is allowed to appear only in postcondition-like
1291 -- aspects or pragmas.
1293 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1294 if Nkind
(Prag
) = N_Aspect_Specification
then
1295 Prag_Nam
:= Chars
(Identifier
(Prag
));
1297 Prag_Nam
:= Pragma_Name
(Prag
);
1300 if Prag_Nam
= Name_Check
then
1301 Check_Placement_In_Check
(Prag
);
1303 elsif Prag_Nam
= Name_Contract_Cases
then
1304 Check_Placement_In_Contract_Cases
(Prag
);
1306 -- Attribute 'Result is allowed to appear in aspect or pragma
1307 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1309 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Refined_Depends
)
1310 and then Aname
= Name_Result
1314 elsif Nam_In
(Prag_Nam
, Name_Post
,
1321 elsif Prag_Nam
= Name_Test_Case
then
1322 Check_Placement_In_Test_Case
(Prag
);
1329 -- Otherwise the placement of the attribute is illegal
1336 -- Find the related subprogram subject to the aspect or pragma
1338 if Nkind
(Prag
) = N_Aspect_Specification
then
1339 Subp_Decl
:= Parent
(Prag
);
1341 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1344 -- The aspect or pragma where the attribute resides should be
1345 -- associated with a subprogram declaration or a body. If this is not
1346 -- the case, then the aspect or pragma is illegal. Return as analysis
1347 -- cannot be carried out. Note that it is legal to have the aspect
1348 -- appear on a subprogram renaming, when the renamed entity is an
1349 -- attribute reference.
1351 -- Generating C code the internally built nested _postcondition
1352 -- subprograms are inlined; after expanded, inlined aspects are
1353 -- located in the internal block generated by the frontend.
1355 if Nkind
(Subp_Decl
) = N_Block_Statement
1356 and then Modify_Tree_For_C
1357 and then In_Inlined_Body
1361 elsif not Nkind_In
(Subp_Decl
, N_Abstract_Subprogram_Declaration
,
1362 N_Entry_Declaration
,
1363 N_Expression_Function
,
1364 N_Generic_Subprogram_Declaration
,
1366 N_Subprogram_Body_Stub
,
1367 N_Subprogram_Declaration
,
1368 N_Subprogram_Renaming_Declaration
)
1373 -- If we get here, then the attribute is legal
1376 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1378 -- When generating C code, nested _postcondition subprograms are
1379 -- inlined by the front end to avoid problems (when unnested) with
1380 -- referenced itypes. Handle that here, since as part of inlining the
1381 -- expander nests subprogram within a dummy procedure named _parent
1382 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1383 -- Hence, in this context, the spec_id of _postconditions is the
1386 if Modify_Tree_For_C
1387 and then Chars
(Spec_Id
) = Name_uParent
1388 and then Chars
(Scope
(Spec_Id
)) = Name_uPostconditions
1390 -- This situation occurs only when preanalyzing the inlined body
1392 pragma Assert
(not Full_Analysis
);
1394 Spec_Id
:= Scope
(Spec_Id
);
1395 pragma Assert
(Is_Inlined
(Spec_Id
));
1397 end Analyze_Attribute_Old_Result
;
1399 -----------------------------
1400 -- Analyze_Image_Attribute --
1401 -----------------------------
1403 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
) is
1405 Check_SPARK_05_Restriction_On_Attribute
;
1407 -- AI12-00124: The ARG has adopted the GNAT semantics of 'Img for
1408 -- scalar types, so that the prefix can be an object, a named value,
1409 -- or a type, and there is no need for an argument in this case.
1411 if Attr_Id
= Attribute_Img
1412 or else (Ada_Version
> Ada_2005
and then Is_Object_Image
(P
))
1415 Set_Etype
(N
, Str_Typ
);
1417 if Attr_Id
= Attribute_Img
and then not Is_Object_Image
(P
) then
1419 ("prefix of % attribute must be a scalar object name");
1423 Set_Etype
(N
, Str_Typ
);
1425 -- Check that the prefix type is scalar - much in the same way as
1426 -- Check_Scalar_Type but with custom error messages to denote the
1427 -- variants of 'Image attributes.
1429 if Is_Entity_Name
(P
)
1430 and then Is_Type
(Entity
(P
))
1431 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1432 and then Present
(Full_View
(Entity
(P
)))
1434 P_Type
:= Full_View
(Entity
(P
));
1435 Set_Entity
(P
, P_Type
);
1438 if not Is_Entity_Name
(P
)
1439 or else not Is_Type
(Entity
(P
))
1440 or else not Is_Scalar_Type
(P_Type
)
1442 if Ada_Version
> Ada_2005
then
1444 ("prefix of % attribute must be a scalar type or a scalar "
1447 Error_Attr_P
("prefix of % attribute must be a scalar type");
1450 elsif Is_Protected_Self_Reference
(P
) then
1452 ("prefix of % attribute denotes current instance "
1453 & "(RM 9.4(21/2))");
1456 Resolve
(E1
, P_Base_Type
);
1457 Validate_Non_Static_Attribute_Function_Call
;
1462 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
1463 -- to avoid giving a duplicate message for when Image attributes
1464 -- applied to object references get expanded into type-based Image
1467 if Restriction_Check_Required
(No_Fixed_IO
)
1468 and then Comes_From_Source
(N
)
1469 and then Is_Fixed_Point_Type
(P_Type
)
1471 Check_Restriction
(No_Fixed_IO
, P
);
1473 end Analyze_Image_Attribute
;
1475 ---------------------------------
1476 -- Bad_Attribute_For_Predicate --
1477 ---------------------------------
1479 procedure Bad_Attribute_For_Predicate
is
1481 if Is_Scalar_Type
(P_Type
)
1482 and then Comes_From_Source
(N
)
1484 Error_Msg_Name_1
:= Aname
;
1485 Bad_Predicated_Subtype_Use
1486 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1488 end Bad_Attribute_For_Predicate
;
1490 --------------------------------
1491 -- Check_Array_Or_Scalar_Type --
1492 --------------------------------
1494 procedure Check_Array_Or_Scalar_Type
is
1495 function In_Aspect_Specification
return Boolean;
1496 -- A current instance of a type in an aspect specification is an
1497 -- object and not a type, and therefore cannot be of a scalar type
1498 -- in the prefix of one of the array attributes if the attribute
1499 -- reference is part of an aspect expression.
1501 -----------------------------
1502 -- In_Aspect_Specification --
1503 -----------------------------
1505 function In_Aspect_Specification
return Boolean is
1510 while Present
(P
) loop
1511 if Nkind
(P
) = N_Aspect_Specification
then
1512 return P_Type
= Entity
(P
);
1514 elsif Nkind
(P
) in N_Declaration
then
1522 end In_Aspect_Specification
;
1529 -- Start of processing for Check_Array_Or_Scalar_Type
1532 -- Case of string literal or string literal subtype. These cases
1533 -- cannot arise from legal Ada code, but the expander is allowed
1534 -- to generate them. They require special handling because string
1535 -- literal subtypes do not have standard bounds (the whole idea
1536 -- of these subtypes is to avoid having to generate the bounds)
1538 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1539 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1544 elsif Is_Scalar_Type
(P_Type
) then
1547 if Present
(E1
) then
1548 Error_Attr
("invalid argument in % attribute", E1
);
1550 elsif In_Aspect_Specification
then
1552 ("prefix of % attribute cannot be the current instance of a "
1553 & "scalar type", P
);
1556 Set_Etype
(N
, P_Base_Type
);
1560 -- The following is a special test to allow 'First to apply to
1561 -- private scalar types if the attribute comes from generated
1562 -- code. This occurs in the case of Normalize_Scalars code.
1564 elsif Is_Private_Type
(P_Type
)
1565 and then Present
(Full_View
(P_Type
))
1566 and then Is_Scalar_Type
(Full_View
(P_Type
))
1567 and then not Comes_From_Source
(N
)
1569 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1571 -- Array types other than string literal subtypes handled above
1576 -- We know prefix is an array type, or the name of an array
1577 -- object, and that the expression, if present, is static
1578 -- and within the range of the dimensions of the type.
1580 pragma Assert
(Is_Array_Type
(P_Type
));
1581 Index
:= First_Index
(P_Base_Type
);
1585 -- First dimension assumed
1587 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1590 Dims
:= UI_To_Int
(Intval
(E1
));
1592 for J
in 1 .. Dims
- 1 loop
1596 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1597 Set_Etype
(E1
, Standard_Integer
);
1600 end Check_Array_Or_Scalar_Type
;
1602 ----------------------
1603 -- Check_Array_Type --
1604 ----------------------
1606 procedure Check_Array_Type
is
1608 -- Dimension number for array attributes
1611 -- If the type is a string literal type, then this must be generated
1612 -- internally, and no further check is required on its legality.
1614 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1617 -- If the type is a composite, it is an illegal aggregate, no point
1620 elsif P_Type
= Any_Composite
then
1621 raise Bad_Attribute
;
1624 -- Normal case of array type or subtype
1626 Check_Either_E0_Or_E1
;
1629 if Is_Array_Type
(P_Type
) then
1630 if not Is_Constrained
(P_Type
)
1631 and then Is_Entity_Name
(P
)
1632 and then Is_Type
(Entity
(P
))
1634 -- Note: we do not call Error_Attr here, since we prefer to
1635 -- continue, using the relevant index type of the array,
1636 -- even though it is unconstrained. This gives better error
1637 -- recovery behavior.
1639 Error_Msg_Name_1
:= Aname
;
1641 ("prefix for % attribute must be constrained array", P
);
1644 -- The attribute reference freezes the type, and thus the
1645 -- component type, even if the attribute may not depend on the
1646 -- component. Diagnose arrays with incomplete components now.
1647 -- If the prefix is an access to array, this does not freeze
1648 -- the designated type.
1650 if Nkind
(P
) /= N_Explicit_Dereference
then
1651 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1654 D
:= Number_Dimensions
(P_Type
);
1657 if Is_Private_Type
(P_Type
) then
1658 Error_Attr_P
("prefix for % attribute may not be private type");
1660 elsif Is_Access_Type
(P_Type
)
1661 and then Is_Array_Type
(Designated_Type
(P_Type
))
1662 and then Is_Entity_Name
(P
)
1663 and then Is_Type
(Entity
(P
))
1665 Error_Attr_P
("prefix of % attribute cannot be access type");
1667 elsif Attr_Id
= Attribute_First
1669 Attr_Id
= Attribute_Last
1671 Error_Attr
("invalid prefix for % attribute", P
);
1674 Error_Attr_P
("prefix for % attribute must be array");
1678 if Present
(E1
) then
1679 Resolve
(E1
, Any_Integer
);
1680 Set_Etype
(E1
, Standard_Integer
);
1682 if not Is_OK_Static_Expression
(E1
)
1683 or else Raises_Constraint_Error
(E1
)
1685 Flag_Non_Static_Expr
1686 ("expression for dimension must be static!", E1
);
1689 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1690 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1692 Error_Attr
("invalid dimension number for array type", E1
);
1696 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1697 and then Comes_From_Source
(N
)
1699 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1701 end Check_Array_Type
;
1703 -------------------------
1704 -- Check_Asm_Attribute --
1705 -------------------------
1707 procedure Check_Asm_Attribute
is
1712 -- Check first argument is static string expression
1714 Analyze_And_Resolve
(E1
, Standard_String
);
1716 if Etype
(E1
) = Any_Type
then
1719 elsif not Is_OK_Static_Expression
(E1
) then
1720 Flag_Non_Static_Expr
1721 ("constraint argument must be static string expression!", E1
);
1725 -- Check second argument is right type
1727 Analyze_And_Resolve
(E2
, Entity
(P
));
1729 -- Note: that is all we need to do, we don't need to check
1730 -- that it appears in a correct context. The Ada type system
1731 -- will do that for us.
1733 end Check_Asm_Attribute
;
1735 ---------------------
1736 -- Check_Component --
1737 ---------------------
1739 procedure Check_Component
is
1743 if Nkind
(P
) /= N_Selected_Component
1745 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1747 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1749 Error_Attr_P
("prefix for % attribute must be selected component");
1751 end Check_Component
;
1753 ------------------------------------
1754 -- Check_Decimal_Fixed_Point_Type --
1755 ------------------------------------
1757 procedure Check_Decimal_Fixed_Point_Type
is
1761 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1762 Error_Attr_P
("prefix of % attribute must be decimal type");
1764 end Check_Decimal_Fixed_Point_Type
;
1766 -----------------------
1767 -- Check_Dereference --
1768 -----------------------
1770 procedure Check_Dereference
is
1773 -- Case of a subtype mark
1775 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1779 -- Case of an expression
1783 if Is_Access_Type
(P_Type
) then
1785 -- If there is an implicit dereference, then we must freeze the
1786 -- designated type of the access type, since the type of the
1787 -- referenced array is this type (see AI95-00106).
1789 -- As done elsewhere, freezing must not happen when pre-analyzing
1790 -- a pre- or postcondition or a default value for an object or for
1791 -- a formal parameter.
1793 if not In_Spec_Expression
then
1794 Freeze_Before
(N
, Designated_Type
(P_Type
));
1798 Make_Explicit_Dereference
(Sloc
(P
),
1799 Prefix
=> Relocate_Node
(P
)));
1801 Analyze_And_Resolve
(P
);
1802 P_Type
:= Etype
(P
);
1804 if P_Type
= Any_Type
then
1805 raise Bad_Attribute
;
1808 P_Base_Type
:= Base_Type
(P_Type
);
1810 end Check_Dereference
;
1812 -------------------------
1813 -- Check_Discrete_Type --
1814 -------------------------
1816 procedure Check_Discrete_Type
is
1820 if not Is_Discrete_Type
(P_Type
) then
1821 Error_Attr_P
("prefix of % attribute must be discrete type");
1823 end Check_Discrete_Type
;
1829 procedure Check_E0
is
1831 if Present
(E1
) then
1832 Unexpected_Argument
(E1
);
1840 procedure Check_E1
is
1842 Check_Either_E0_Or_E1
;
1846 -- Special-case attributes that are functions and that appear as
1847 -- the prefix of another attribute. Error is posted on parent.
1849 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1850 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1854 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1855 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1856 Set_Etype
(Parent
(N
), Any_Type
);
1857 Set_Entity
(Parent
(N
), Any_Type
);
1858 raise Bad_Attribute
;
1861 Error_Attr
("missing argument for % attribute", N
);
1870 procedure Check_E2
is
1873 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1875 Error_Attr
("missing argument for % attribute (2 required)", N
);
1879 ---------------------------
1880 -- Check_Either_E0_Or_E1 --
1881 ---------------------------
1883 procedure Check_Either_E0_Or_E1
is
1885 if Present
(E2
) then
1886 Unexpected_Argument
(E2
);
1888 end Check_Either_E0_Or_E1
;
1890 ----------------------
1891 -- Check_Enum_Image --
1892 ----------------------
1894 procedure Check_Enum_Image
is
1898 -- When an enumeration type appears in an attribute reference, all
1899 -- literals of the type are marked as referenced. This must only be
1900 -- done if the attribute reference appears in the current source.
1901 -- Otherwise the information on references may differ between a
1902 -- normal compilation and one that performs inlining.
1904 if Is_Enumeration_Type
(P_Base_Type
)
1905 and then In_Extended_Main_Code_Unit
(N
)
1907 Lit
:= First_Literal
(P_Base_Type
);
1908 while Present
(Lit
) loop
1909 Set_Referenced
(Lit
);
1913 end Check_Enum_Image
;
1915 ----------------------------
1916 -- Check_First_Last_Valid --
1917 ----------------------------
1919 procedure Check_First_Last_Valid
is
1921 Check_Discrete_Type
;
1923 -- Freeze the subtype now, so that the following test for predicates
1924 -- works (we set the predicates stuff up at freeze time)
1926 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1928 -- Now test for dynamic predicate
1930 if Has_Predicates
(P_Type
)
1931 and then not (Has_Static_Predicate
(P_Type
))
1934 ("prefix of % attribute may not have dynamic predicate");
1937 -- Check non-static subtype
1939 if not Is_OK_Static_Subtype
(P_Type
) then
1940 Error_Attr_P
("prefix of % attribute must be a static subtype");
1943 -- Test case for no values
1945 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1946 Expr_Value
(Type_High_Bound
(P_Type
))
1947 or else (Has_Predicates
(P_Type
)
1949 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1952 ("prefix of % attribute must be subtype with at least one "
1955 end Check_First_Last_Valid
;
1957 ----------------------------
1958 -- Check_Fixed_Point_Type --
1959 ----------------------------
1961 procedure Check_Fixed_Point_Type
is
1965 if not Is_Fixed_Point_Type
(P_Type
) then
1966 Error_Attr_P
("prefix of % attribute must be fixed point type");
1968 end Check_Fixed_Point_Type
;
1970 ------------------------------
1971 -- Check_Fixed_Point_Type_0 --
1972 ------------------------------
1974 procedure Check_Fixed_Point_Type_0
is
1976 Check_Fixed_Point_Type
;
1978 end Check_Fixed_Point_Type_0
;
1980 -------------------------------
1981 -- Check_Floating_Point_Type --
1982 -------------------------------
1984 procedure Check_Floating_Point_Type
is
1988 if not Is_Floating_Point_Type
(P_Type
) then
1989 Error_Attr_P
("prefix of % attribute must be float type");
1991 end Check_Floating_Point_Type
;
1993 ---------------------------------
1994 -- Check_Floating_Point_Type_0 --
1995 ---------------------------------
1997 procedure Check_Floating_Point_Type_0
is
1999 Check_Floating_Point_Type
;
2001 end Check_Floating_Point_Type_0
;
2003 ---------------------------------
2004 -- Check_Floating_Point_Type_1 --
2005 ---------------------------------
2007 procedure Check_Floating_Point_Type_1
is
2009 Check_Floating_Point_Type
;
2011 end Check_Floating_Point_Type_1
;
2013 ---------------------------------
2014 -- Check_Floating_Point_Type_2 --
2015 ---------------------------------
2017 procedure Check_Floating_Point_Type_2
is
2019 Check_Floating_Point_Type
;
2021 end Check_Floating_Point_Type_2
;
2023 ------------------------
2024 -- Check_Integer_Type --
2025 ------------------------
2027 procedure Check_Integer_Type
is
2031 if not Is_Integer_Type
(P_Type
) then
2032 Error_Attr_P
("prefix of % attribute must be integer type");
2034 end Check_Integer_Type
;
2036 --------------------------------
2037 -- Check_Modular_Integer_Type --
2038 --------------------------------
2040 procedure Check_Modular_Integer_Type
is
2044 if not Is_Modular_Integer_Type
(P_Type
) then
2046 ("prefix of % attribute must be modular integer type");
2048 end Check_Modular_Integer_Type
;
2050 ------------------------
2051 -- Check_Not_CPP_Type --
2052 ------------------------
2054 procedure Check_Not_CPP_Type
is
2056 if Is_Tagged_Type
(Etype
(P
))
2057 and then Convention
(Etype
(P
)) = Convention_CPP
2058 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
2061 ("invalid use of % attribute with 'C'P'P tagged type");
2063 end Check_Not_CPP_Type
;
2065 -------------------------------
2066 -- Check_Not_Incomplete_Type --
2067 -------------------------------
2069 procedure Check_Not_Incomplete_Type
is
2074 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2075 -- dereference we have to check wrong uses of incomplete types
2076 -- (other wrong uses are checked at their freezing point).
2078 -- In Ada 2012, incomplete types can appear in subprogram
2079 -- profiles, but formals with incomplete types cannot be the
2080 -- prefix of attributes.
2082 -- Example 1: Limited-with
2084 -- limited with Pkg;
2086 -- type Acc is access Pkg.T;
2088 -- S : Integer := X.all'Size; -- ERROR
2091 -- Example 2: Tagged incomplete
2093 -- type T is tagged;
2094 -- type Acc is access all T;
2096 -- S : constant Integer := X.all'Size; -- ERROR
2097 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2099 if Ada_Version
>= Ada_2005
2100 and then Nkind
(P
) = N_Explicit_Dereference
2103 while Nkind
(E
) = N_Explicit_Dereference
loop
2109 if From_Limited_With
(Typ
) then
2111 ("prefix of % attribute cannot be an incomplete type");
2113 -- If the prefix is an access type check the designated type
2115 elsif Is_Access_Type
(Typ
)
2116 and then Nkind
(P
) = N_Explicit_Dereference
2118 Typ
:= Directly_Designated_Type
(Typ
);
2121 if Is_Class_Wide_Type
(Typ
) then
2122 Typ
:= Root_Type
(Typ
);
2125 -- A legal use of a shadow entity occurs only when the unit where
2126 -- the non-limited view resides is imported via a regular with
2127 -- clause in the current body. Such references to shadow entities
2128 -- may occur in subprogram formals.
2130 if Is_Incomplete_Type
(Typ
)
2131 and then From_Limited_With
(Typ
)
2132 and then Present
(Non_Limited_View
(Typ
))
2133 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2135 Typ
:= Non_Limited_View
(Typ
);
2138 -- If still incomplete, it can be a local incomplete type, or a
2139 -- limited view whose scope is also a limited view.
2141 if Ekind
(Typ
) = E_Incomplete_Type
then
2142 if not From_Limited_With
(Typ
)
2143 and then No
(Full_View
(Typ
))
2146 ("prefix of % attribute cannot be an incomplete type");
2148 -- The limited view may be available indirectly through
2149 -- an intermediate unit. If the non-limited view is available
2150 -- the attribute reference is legal.
2152 elsif From_Limited_With
(Typ
)
2154 (No
(Non_Limited_View
(Typ
))
2155 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2158 ("prefix of % attribute cannot be an incomplete type");
2162 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2165 elsif Is_Entity_Name
(P
)
2166 and then Is_Formal
(Entity
(P
))
2167 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2170 ("prefix of % attribute cannot be an incomplete type");
2173 if not Is_Entity_Name
(P
)
2174 or else not Is_Type
(Entity
(P
))
2175 or else In_Spec_Expression
2179 Check_Fully_Declared
(P_Type
, P
);
2181 end Check_Not_Incomplete_Type
;
2183 ----------------------------
2184 -- Check_Object_Reference --
2185 ----------------------------
2187 procedure Check_Object_Reference
(P
: Node_Id
) is
2191 -- If we need an object, and we have a prefix that is the name of
2192 -- a function entity, convert it into a function call.
2194 if Is_Entity_Name
(P
)
2195 and then Ekind
(Entity
(P
)) = E_Function
2197 Rtyp
:= Etype
(Entity
(P
));
2200 Make_Function_Call
(Sloc
(P
),
2201 Name
=> Relocate_Node
(P
)));
2203 Analyze_And_Resolve
(P
, Rtyp
);
2205 -- Otherwise we must have an object reference
2207 elsif not Is_Object_Reference
(P
) then
2208 Error_Attr_P
("prefix of % attribute must be object");
2210 end Check_Object_Reference
;
2212 ----------------------------
2213 -- Check_PolyORB_Attribute --
2214 ----------------------------
2216 procedure Check_PolyORB_Attribute
is
2218 Validate_Non_Static_Attribute_Function_Call
;
2223 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2225 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2227 end Check_PolyORB_Attribute
;
2229 ------------------------
2230 -- Check_Program_Unit --
2231 ------------------------
2233 procedure Check_Program_Unit
is
2235 if Is_Entity_Name
(P
) then
2237 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
2238 T
: constant Entity_Id
:= Etype
(Entity
(P
));
2241 if K
in Subprogram_Kind
2242 or else K
in Task_Kind
2243 or else K
in Protected_Kind
2244 or else K
= E_Package
2245 or else K
in Generic_Unit_Kind
2246 or else (K
= E_Variable
2250 Is_Protected_Type
(T
)))
2257 Error_Attr_P
("prefix of % attribute must be program unit");
2258 end Check_Program_Unit
;
2260 ---------------------
2261 -- Check_Real_Type --
2262 ---------------------
2264 procedure Check_Real_Type
is
2268 if not Is_Real_Type
(P_Type
) then
2269 Error_Attr_P
("prefix of % attribute must be real type");
2271 end Check_Real_Type
;
2273 -----------------------
2274 -- Check_Scalar_Type --
2275 -----------------------
2277 procedure Check_Scalar_Type
is
2281 if not Is_Scalar_Type
(P_Type
) then
2282 Error_Attr_P
("prefix of % attribute must be scalar type");
2284 end Check_Scalar_Type
;
2286 ------------------------------------------
2287 -- Check_SPARK_05_Restriction_On_Attribute --
2288 ------------------------------------------
2290 procedure Check_SPARK_05_Restriction_On_Attribute
is
2292 Error_Msg_Name_1
:= Aname
;
2293 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
2294 end Check_SPARK_05_Restriction_On_Attribute
;
2296 ---------------------------
2297 -- Check_Standard_Prefix --
2298 ---------------------------
2300 procedure Check_Standard_Prefix
is
2304 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2305 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2307 end Check_Standard_Prefix
;
2309 ----------------------------
2310 -- Check_Stream_Attribute --
2311 ----------------------------
2313 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2317 In_Shared_Var_Procs
: Boolean;
2318 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2319 -- For this runtime package (always compiled in GNAT mode), we allow
2320 -- stream attributes references for limited types for the case where
2321 -- shared passive objects are implemented using stream attributes,
2322 -- which is the default in GNAT's persistent storage implementation.
2325 Validate_Non_Static_Attribute_Function_Call
;
2327 -- With the exception of 'Input, Stream attributes are procedures,
2328 -- and can only appear at the position of procedure calls. We check
2329 -- for this here, before they are rewritten, to give a more precise
2332 if Nam
= TSS_Stream_Input
then
2335 elsif Is_List_Member
(N
)
2336 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
2343 ("invalid context for attribute%, which is a procedure", N
);
2347 Btyp
:= Implementation_Base_Type
(P_Type
);
2349 -- Stream attributes not allowed on limited types unless the
2350 -- attribute reference was generated by the expander (in which
2351 -- case the underlying type will be used, as described in Sinfo),
2352 -- or the attribute was specified explicitly for the type itself
2353 -- or one of its ancestors (taking visibility rules into account if
2354 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2355 -- (with no visibility restriction).
2358 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2360 if Present
(Gen_Body
) then
2361 In_Shared_Var_Procs
:=
2362 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2364 In_Shared_Var_Procs
:= False;
2368 if (Comes_From_Source
(N
)
2369 and then not (In_Shared_Var_Procs
or In_Instance
))
2370 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2371 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2373 Error_Msg_Name_1
:= Aname
;
2375 if Is_Limited_Type
(P_Type
) then
2377 ("limited type& has no% attribute", P
, P_Type
);
2378 Explain_Limited_Type
(P_Type
, P
);
2381 ("attribute% for type& is not available", P
, P_Type
);
2385 -- Check for no stream operations allowed from No_Tagged_Streams
2387 if Is_Tagged_Type
(P_Type
)
2388 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2390 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2392 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2396 -- Check restriction violations
2398 -- First check the No_Streams restriction, which prohibits the use
2399 -- of explicit stream attributes in the source program. We do not
2400 -- prevent the occurrence of stream attributes in generated code,
2401 -- for instance those generated implicitly for dispatching purposes.
2403 if Comes_From_Source
(N
) then
2404 Check_Restriction
(No_Streams
, P
);
2407 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2408 -- it is illegal to use a predefined elementary type stream attribute
2409 -- either by itself, or more importantly as part of the attribute
2410 -- subprogram for a composite type. However, if the broader
2411 -- restriction No_Streams is active, stream operations are not
2412 -- generated, and there is no error.
2414 if Restriction_Active
(No_Default_Stream_Attributes
)
2415 and then not Restriction_Active
(No_Streams
)
2421 if Nam
= TSS_Stream_Input
2423 Nam
= TSS_Stream_Read
2426 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2429 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2433 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2436 ("missing user-defined Stream Read or Write for type&",
2438 if not Is_Elementary_Type
(P_Type
) then
2440 ("\which is a component of type&", N
, P_Type
);
2446 -- Check special case of Exception_Id and Exception_Occurrence which
2447 -- are not allowed for restriction No_Exception_Registration.
2449 if Restriction_Check_Required
(No_Exception_Registration
)
2450 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2452 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2454 Check_Restriction
(No_Exception_Registration
, P
);
2457 -- Here we must check that the first argument is an access type
2458 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2460 Analyze_And_Resolve
(E1
);
2463 -- Note: the double call to Root_Type here is needed because the
2464 -- root type of a class-wide type is the corresponding type (e.g.
2465 -- X for X'Class, and we really want to go to the root.)
2467 if not Is_Access_Type
(Etyp
)
2468 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
2469 RTE
(RE_Root_Stream_Type
)
2472 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2475 -- Check that the second argument is of the right type if there is
2476 -- one (the Input attribute has only one argument so this is skipped)
2478 if Present
(E2
) then
2481 if Nam
= TSS_Stream_Read
2482 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2485 ("second argument of % attribute must be a variable", E2
);
2488 Resolve
(E2
, P_Type
);
2492 end Check_Stream_Attribute
;
2494 -------------------------
2495 -- Check_System_Prefix --
2496 -------------------------
2498 procedure Check_System_Prefix
is
2500 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2501 Error_Attr
("only allowed prefix for % attribute is System", P
);
2503 end Check_System_Prefix
;
2505 -----------------------
2506 -- Check_Task_Prefix --
2507 -----------------------
2509 procedure Check_Task_Prefix
is
2513 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2514 -- task interface class-wide types.
2516 if Is_Task_Type
(Etype
(P
))
2517 or else (Is_Access_Type
(Etype
(P
))
2518 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2519 or else (Ada_Version
>= Ada_2005
2520 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2521 and then Is_Interface
(Etype
(P
))
2522 and then Is_Task_Interface
(Etype
(P
)))
2527 if Ada_Version
>= Ada_2005
then
2529 ("prefix of % attribute must be a task or a task " &
2530 "interface class-wide object");
2533 Error_Attr_P
("prefix of % attribute must be a task");
2536 end Check_Task_Prefix
;
2542 -- The possibilities are an entity name denoting a type, or an
2543 -- attribute reference that denotes a type (Base or Class). If
2544 -- the type is incomplete, replace it with its full view.
2546 procedure Check_Type
is
2548 if not Is_Entity_Name
(P
)
2549 or else not Is_Type
(Entity
(P
))
2551 Error_Attr_P
("prefix of % attribute must be a type");
2553 elsif Is_Protected_Self_Reference
(P
) then
2555 ("prefix of % attribute denotes current instance "
2556 & "(RM 9.4(21/2))");
2558 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2559 and then Present
(Full_View
(Entity
(P
)))
2561 P_Type
:= Full_View
(Entity
(P
));
2562 Set_Entity
(P
, P_Type
);
2566 ---------------------
2567 -- Check_Unit_Name --
2568 ---------------------
2570 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2572 if Nkind
(Nod
) = N_Identifier
then
2575 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2576 Check_Unit_Name
(Prefix
(Nod
));
2578 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2583 Error_Attr
("argument for % attribute must be unit name", P
);
2584 end Check_Unit_Name
;
2590 procedure Error_Attr
is
2592 Set_Etype
(N
, Any_Type
);
2593 Set_Entity
(N
, Any_Type
);
2594 raise Bad_Attribute
;
2597 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2599 Error_Msg_Name_1
:= Aname
;
2600 Error_Msg_N
(Msg
, Error_Node
);
2608 procedure Error_Attr_P
(Msg
: String) is
2610 Error_Msg_Name_1
:= Aname
;
2611 Error_Msg_F
(Msg
, P
);
2615 ----------------------------
2616 -- Legal_Formal_Attribute --
2617 ----------------------------
2619 procedure Legal_Formal_Attribute
is
2623 if not Is_Entity_Name
(P
)
2624 or else not Is_Type
(Entity
(P
))
2626 Error_Attr_P
("prefix of % attribute must be generic type");
2628 elsif Is_Generic_Actual_Type
(Entity
(P
))
2630 or else In_Inlined_Body
2634 elsif Is_Generic_Type
(Entity
(P
)) then
2635 if Is_Definite_Subtype
(Entity
(P
)) then
2637 ("prefix of % attribute must be indefinite generic type");
2642 ("prefix of % attribute must be indefinite generic type");
2645 Set_Etype
(N
, Standard_Boolean
);
2646 end Legal_Formal_Attribute
;
2648 ---------------------------------------------------------------
2649 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2650 ---------------------------------------------------------------
2652 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2656 Check_Not_Incomplete_Type
;
2657 Set_Etype
(N
, Universal_Integer
);
2658 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2664 procedure Min_Max
is
2668 Resolve
(E1
, P_Base_Type
);
2669 Resolve
(E2
, P_Base_Type
);
2670 Set_Etype
(N
, P_Base_Type
);
2672 -- Check for comparison on unordered enumeration type
2674 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2675 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2677 ("comparison on unordered enumeration type& declared#?U?",
2682 ------------------------
2683 -- Standard_Attribute --
2684 ------------------------
2686 procedure Standard_Attribute
(Val
: Int
) is
2688 Check_Standard_Prefix
;
2689 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2691 Set_Is_Static_Expression
(N
, True);
2692 end Standard_Attribute
;
2694 --------------------
2695 -- Uneval_Old_Msg --
2696 --------------------
2698 procedure Uneval_Old_Msg
is
2699 Uneval_Old_Setting
: Character;
2703 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2704 -- N_Aspect_Specification node that corresponds to the attribute.
2706 -- First find the pragma in which we appear (note that at this stage,
2707 -- even if we appeared originally within an aspect specification, we
2708 -- are now within the corresponding pragma).
2712 Prag
:= Parent
(Prag
);
2713 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2716 if Present
(Prag
) then
2717 if Uneval_Old_Accept
(Prag
) then
2718 Uneval_Old_Setting
:= 'A';
2719 elsif Uneval_Old_Warn
(Prag
) then
2720 Uneval_Old_Setting
:= 'W';
2722 Uneval_Old_Setting
:= 'E';
2725 -- If we did not find the pragma, that's odd, just use the setting
2726 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2729 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2732 -- Processing depends on the setting of Uneval_Old
2734 case Uneval_Old_Setting
is
2737 ("prefix of attribute % that is potentially "
2738 & "unevaluated must denote an entity");
2741 Error_Msg_Name_1
:= Aname
;
2743 ("??prefix of attribute % appears in potentially "
2744 & "unevaluated context, exception may be raised", P
);
2750 raise Program_Error
;
2754 -------------------------
2755 -- Unexpected Argument --
2756 -------------------------
2758 procedure Unexpected_Argument
(En
: Node_Id
) is
2760 Error_Attr
("unexpected argument for % attribute", En
);
2761 end Unexpected_Argument
;
2763 -------------------------------------------------
2764 -- Validate_Non_Static_Attribute_Function_Call --
2765 -------------------------------------------------
2767 -- This function should be moved to Sem_Dist ???
2769 procedure Validate_Non_Static_Attribute_Function_Call
is
2771 if In_Preelaborated_Unit
2772 and then not In_Subprogram_Or_Concurrent_Unit
2774 Flag_Non_Static_Expr
2775 ("non-static function call in preelaborated unit!", N
);
2777 end Validate_Non_Static_Attribute_Function_Call
;
2779 -- Start of processing for Analyze_Attribute
2782 -- Immediate return if unrecognized attribute (already diagnosed by
2783 -- parser, so there is nothing more that we need to do).
2785 if not Is_Attribute_Name
(Aname
) then
2786 raise Bad_Attribute
;
2789 Check_Restriction_No_Use_Of_Attribute
(N
);
2791 -- Deal with Ada 83 issues
2793 if Comes_From_Source
(N
) then
2794 if not Attribute_83
(Attr_Id
) then
2795 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2796 Error_Msg_Name_1
:= Aname
;
2797 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2800 if Attribute_Impl_Def
(Attr_Id
) then
2801 Check_Restriction
(No_Implementation_Attributes
, N
);
2806 -- Deal with Ada 2005 attributes that are implementation attributes
2807 -- because they appear in a version of Ada before Ada 2005, and
2808 -- similarly for Ada 2012 attributes appearing in an earlier version.
2810 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2812 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2814 Check_Restriction
(No_Implementation_Attributes
, N
);
2817 -- Remote access to subprogram type access attribute reference needs
2818 -- unanalyzed copy for tree transformation. The analyzed copy is used
2819 -- for its semantic information (whether prefix is a remote subprogram
2820 -- name), the unanalyzed copy is used to construct new subtree rooted
2821 -- with N_Aggregate which represents a fat pointer aggregate.
2823 if Aname
= Name_Access
then
2824 Discard_Node
(Copy_Separate_Tree
(N
));
2827 -- Analyze prefix and exit if error in analysis. If the prefix is an
2828 -- incomplete type, use full view if available. Note that there are
2829 -- some attributes for which we do not analyze the prefix, since the
2830 -- prefix is not a normal name, or else needs special handling.
2832 if Aname
/= Name_Elab_Body
and then
2833 Aname
/= Name_Elab_Spec
and then
2834 Aname
/= Name_Elab_Subp_Body
and then
2835 Aname
/= Name_Enabled
and then
2839 P_Type
:= Etype
(P
);
2841 if Is_Entity_Name
(P
)
2842 and then Present
(Entity
(P
))
2843 and then Is_Type
(Entity
(P
))
2845 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2846 P_Type
:= Get_Full_View
(P_Type
);
2847 Set_Entity
(P
, P_Type
);
2848 Set_Etype
(P
, P_Type
);
2850 elsif Entity
(P
) = Current_Scope
2851 and then Is_Record_Type
(Entity
(P
))
2853 -- Use of current instance within the type. Verify that if the
2854 -- attribute appears within a constraint, it yields an access
2855 -- type, other uses are illegal.
2863 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2865 Par
:= Parent
(Par
);
2869 and then Nkind
(Par
) = N_Subtype_Indication
2871 if Attr_Id
/= Attribute_Access
2872 and then Attr_Id
/= Attribute_Unchecked_Access
2873 and then Attr_Id
/= Attribute_Unrestricted_Access
2876 ("in a constraint the current instance can only "
2877 & "be used with an access attribute", N
);
2884 if P_Type
= Any_Type
then
2885 raise Bad_Attribute
;
2888 P_Base_Type
:= Base_Type
(P_Type
);
2891 -- Analyze expressions that may be present, exiting if an error occurs
2898 E1
:= First
(Exprs
);
2900 -- Skip analysis for case of Restriction_Set, we do not expect
2901 -- the argument to be analyzed in this case.
2903 if Aname
/= Name_Restriction_Set
then
2906 -- Check for missing/bad expression (result of previous error)
2908 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2909 raise Bad_Attribute
;
2915 if Present
(E2
) then
2918 if Etype
(E2
) = Any_Type
then
2919 raise Bad_Attribute
;
2922 if Present
(Next
(E2
)) then
2923 Unexpected_Argument
(Next
(E2
));
2928 -- Cases where prefix must be resolvable by itself
2930 if Is_Overloaded
(P
)
2931 and then Aname
/= Name_Access
2932 and then Aname
/= Name_Address
2933 and then Aname
/= Name_Code_Address
2934 and then Aname
/= Name_Result
2935 and then Aname
/= Name_Unchecked_Access
2937 -- The prefix must be resolvable by itself, without reference to the
2938 -- attribute. One case that requires special handling is a prefix
2939 -- that is a function name, where one interpretation may be a
2940 -- parameterless call. Entry attributes are handled specially below.
2942 if Is_Entity_Name
(P
)
2943 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2945 Check_Parameterless_Call
(P
);
2948 if Is_Overloaded
(P
) then
2950 -- Ada 2005 (AI-345): Since protected and task types have
2951 -- primitive entry wrappers, the attributes Count, and Caller
2952 -- require a context check
2954 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2956 Count
: Natural := 0;
2961 Get_First_Interp
(P
, I
, It
);
2962 while Present
(It
.Nam
) loop
2963 if Comes_From_Source
(It
.Nam
) then
2969 Get_Next_Interp
(I
, It
);
2973 Error_Attr
("ambiguous prefix for % attribute", P
);
2975 Set_Is_Overloaded
(P
, False);
2980 Error_Attr
("ambiguous prefix for % attribute", P
);
2985 -- In SPARK, attributes of private types are only allowed if the full
2986 -- type declaration is visible.
2988 -- Note: the check for Present (Entity (P)) defends against some error
2989 -- conditions where the Entity field is not set.
2991 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2992 and then Is_Type
(Entity
(P
))
2993 and then Is_Private_Type
(P_Type
)
2994 and then not In_Open_Scopes
(Scope
(P_Type
))
2995 and then not In_Spec_Expression
2997 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
3000 -- Remaining processing depends on attribute
3004 -- Attributes related to Ada 2012 iterators. Attribute specifications
3005 -- exist for these, but they cannot be queried.
3007 when Attribute_Constant_Indexing
3008 | Attribute_Default_Iterator
3009 | Attribute_Implicit_Dereference
3010 | Attribute_Iterator_Element
3011 | Attribute_Iterable
3012 | Attribute_Variable_Indexing
3014 Error_Msg_N
("illegal attribute", N
);
3016 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
3017 -- were already rejected by the parser. Thus they shouldn't appear here.
3019 when Internal_Attribute_Id
=>
3020 raise Program_Error
;
3026 when Attribute_Abort_Signal
=>
3027 Check_Standard_Prefix
;
3028 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
3035 when Attribute_Access
=>
3036 Analyze_Access_Attribute
;
3037 Check_Not_Incomplete_Type
;
3043 when Attribute_Address
=>
3046 Check_Not_Incomplete_Type
;
3047 Set_Etype
(N
, RTE
(RE_Address
));
3053 when Attribute_Address_Size
=>
3054 Standard_Attribute
(System_Address_Size
);
3060 when Attribute_Adjacent
=>
3061 Check_Floating_Point_Type_2
;
3062 Set_Etype
(N
, P_Base_Type
);
3063 Resolve
(E1
, P_Base_Type
);
3064 Resolve
(E2
, P_Base_Type
);
3070 when Attribute_Aft
=>
3071 Check_Fixed_Point_Type_0
;
3072 Set_Etype
(N
, Universal_Integer
);
3078 when Attribute_Alignment
=>
3080 -- Don't we need more checking here, cf Size ???
3083 Check_Not_Incomplete_Type
;
3085 Set_Etype
(N
, Universal_Integer
);
3091 when Attribute_Asm_Input
=>
3092 Check_Asm_Attribute
;
3094 -- The back end may need to take the address of E2
3096 if Is_Entity_Name
(E2
) then
3097 Set_Address_Taken
(Entity
(E2
));
3100 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3106 when Attribute_Asm_Output
=>
3107 Check_Asm_Attribute
;
3109 if Etype
(E2
) = Any_Type
then
3112 elsif Aname
= Name_Asm_Output
then
3113 if not Is_Variable
(E2
) then
3115 ("second argument for Asm_Output is not variable", E2
);
3119 Note_Possible_Modification
(E2
, Sure
=> True);
3121 -- The back end may need to take the address of E2
3123 if Is_Entity_Name
(E2
) then
3124 Set_Address_Taken
(Entity
(E2
));
3127 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3129 -----------------------------
3130 -- Atomic_Always_Lock_Free --
3131 -----------------------------
3133 when Attribute_Atomic_Always_Lock_Free
=>
3136 Set_Etype
(N
, Standard_Boolean
);
3142 -- Note: when the base attribute appears in the context of a subtype
3143 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3144 -- the following circuit.
3146 when Attribute_Base
=> Base
: declare
3154 if Ada_Version
>= Ada_95
3155 and then not Is_Scalar_Type
(Typ
)
3156 and then not Is_Generic_Type
(Typ
)
3158 Error_Attr_P
("prefix of Base attribute must be scalar type");
3160 elsif Sloc
(Typ
) = Standard_Location
3161 and then Base_Type
(Typ
) = Typ
3162 and then Warn_On_Redundant_Constructs
3164 Error_Msg_NE
-- CODEFIX
3165 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3168 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
3169 Error_Msg_Name_1
:= Aname
;
3170 Check_SPARK_05_Restriction
3171 ("attribute% is only allowed as prefix of another attribute", P
);
3174 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3175 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3176 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3184 when Attribute_Bit
=>
3187 if not Is_Object_Reference
(P
) then
3188 Error_Attr_P
("prefix for % attribute must be object");
3190 -- What about the access object cases ???
3196 Set_Etype
(N
, Universal_Integer
);
3202 when Attribute_Bit_Order
=>
3206 if not Is_Record_Type
(P_Type
) then
3207 Error_Attr_P
("prefix of % attribute must be record type");
3210 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3212 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3215 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3218 Set_Etype
(N
, RTE
(RE_Bit_Order
));
3221 -- Reset incorrect indication of staticness
3223 Set_Is_Static_Expression
(N
, False);
3229 -- Note: in generated code, we can have a Bit_Position attribute
3230 -- applied to a (naked) record component (i.e. the prefix is an
3231 -- identifier that references an E_Component or E_Discriminant
3232 -- entity directly, and this is interpreted as expected by Gigi.
3233 -- The following code will not tolerate such usage, but when the
3234 -- expander creates this special case, it marks it as analyzed
3235 -- immediately and sets an appropriate type.
3237 when Attribute_Bit_Position
=>
3238 if Comes_From_Source
(N
) then
3242 Set_Etype
(N
, Universal_Integer
);
3248 when Attribute_Body_Version
=>
3251 Set_Etype
(N
, RTE
(RE_Version_String
));
3257 when Attribute_Callable
=>
3259 Set_Etype
(N
, Standard_Boolean
);
3266 when Attribute_Caller
=> Caller
: declare
3273 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3276 if not Is_Entry
(Ent
) then
3277 Error_Attr
("invalid entry name", N
);
3281 Error_Attr
("invalid entry name", N
);
3285 for J
in reverse 0 .. Scope_Stack
.Last
loop
3286 S
:= Scope_Stack
.Table
(J
).Entity
;
3288 if S
= Scope
(Ent
) then
3289 Error_Attr
("Caller must appear in matching accept or body", N
);
3295 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3302 when Attribute_Ceiling
=>
3303 Check_Floating_Point_Type_1
;
3304 Set_Etype
(N
, P_Base_Type
);
3305 Resolve
(E1
, P_Base_Type
);
3311 when Attribute_Class
=>
3312 Check_Restriction
(No_Dispatch
, N
);
3316 -- Applying Class to untagged incomplete type is obsolescent in Ada
3317 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3318 -- this flag gets set by Find_Type in this situation.
3320 if Restriction_Check_Required
(No_Obsolescent_Features
)
3321 and then Ada_Version
>= Ada_2005
3322 and then Ekind
(P_Type
) = E_Incomplete_Type
3325 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3327 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3328 and then not Tagged_Present
(DN
)
3330 Check_Restriction
(No_Obsolescent_Features
, P
);
3339 when Attribute_Code_Address
=>
3342 if Nkind
(P
) = N_Attribute_Reference
3343 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
3347 elsif not Is_Entity_Name
(P
)
3348 or else (Ekind
(Entity
(P
)) /= E_Function
3350 Ekind
(Entity
(P
)) /= E_Procedure
)
3352 Error_Attr
("invalid prefix for % attribute", P
);
3353 Set_Address_Taken
(Entity
(P
));
3355 -- Issue an error if the prefix denotes an eliminated subprogram
3358 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3361 Set_Etype
(N
, RTE
(RE_Address
));
3363 ----------------------
3364 -- Compiler_Version --
3365 ----------------------
3367 when Attribute_Compiler_Version
=>
3369 Check_Standard_Prefix
;
3370 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3371 Analyze_And_Resolve
(N
, Standard_String
);
3372 Set_Is_Static_Expression
(N
, True);
3374 --------------------
3375 -- Component_Size --
3376 --------------------
3378 when Attribute_Component_Size
=>
3380 Set_Etype
(N
, Universal_Integer
);
3382 -- Note: unlike other array attributes, unconstrained arrays are OK
3384 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3394 when Attribute_Compose
=>
3395 Check_Floating_Point_Type_2
;
3396 Set_Etype
(N
, P_Base_Type
);
3397 Resolve
(E1
, P_Base_Type
);
3398 Resolve
(E2
, Any_Integer
);
3404 when Attribute_Constrained
=>
3406 Set_Etype
(N
, Standard_Boolean
);
3408 -- Case from RM J.4(2) of constrained applied to private type
3410 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3411 Check_Restriction
(No_Obsolescent_Features
, P
);
3413 if Warn_On_Obsolescent_Feature
then
3415 ("constrained for private type is an obsolescent feature "
3416 & "(RM J.4)?j?", N
);
3419 -- If we are within an instance, the attribute must be legal
3420 -- because it was valid in the generic unit. Ditto if this is
3421 -- an inlining of a function declared in an instance.
3423 if In_Instance
or else In_Inlined_Body
then
3426 -- For sure OK if we have a real private type itself, but must
3427 -- be completed, cannot apply Constrained to incomplete type.
3429 elsif Is_Private_Type
(Entity
(P
)) then
3431 -- Note: this is one of the Annex J features that does not
3432 -- generate a warning from -gnatwj, since in fact it seems
3433 -- very useful, and is used in the GNAT runtime.
3435 Check_Not_Incomplete_Type
;
3439 -- Normal (non-obsolescent case) of application to object of
3440 -- a discriminated type.
3443 Check_Object_Reference
(P
);
3445 -- If N does not come from source, then we allow the
3446 -- the attribute prefix to be of a private type whose
3447 -- full type has discriminants. This occurs in cases
3448 -- involving expanded calls to stream attributes.
3450 if not Comes_From_Source
(N
) then
3451 P_Type
:= Underlying_Type
(P_Type
);
3454 -- Must have discriminants or be an access type designating a type
3455 -- with discriminants. If it is a class-wide type it has unknown
3458 if Has_Discriminants
(P_Type
)
3459 or else Has_Unknown_Discriminants
(P_Type
)
3461 (Is_Access_Type
(P_Type
)
3462 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3466 -- The rule given in 3.7.2 is part of static semantics, but the
3467 -- intent is clearly that it be treated as a legality rule, and
3468 -- rechecked in the visible part of an instance. Nevertheless
3469 -- the intent also seems to be it should legally apply to the
3470 -- actual of a formal with unknown discriminants, regardless of
3471 -- whether the actual has discriminants, in which case the value
3472 -- of the attribute is determined using the J.4 rules. This choice
3473 -- seems the most useful, and is compatible with existing tests.
3475 elsif In_Instance
then
3478 -- Also allow an object of a generic type if extensions allowed
3479 -- and allow this for any type at all. (this may be obsolete ???)
3481 elsif (Is_Generic_Type
(P_Type
)
3482 or else Is_Generic_Actual_Type
(P_Type
))
3483 and then Extensions_Allowed
3489 -- Fall through if bad prefix
3492 ("prefix of % attribute must be object of discriminated type");
3498 when Attribute_Copy_Sign
=>
3499 Check_Floating_Point_Type_2
;
3500 Set_Etype
(N
, P_Base_Type
);
3501 Resolve
(E1
, P_Base_Type
);
3502 Resolve
(E2
, P_Base_Type
);
3508 when Attribute_Count
=> Count
: declare
3516 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3519 if Ekind
(Ent
) /= E_Entry
then
3520 Error_Attr
("invalid entry name", N
);
3523 elsif Nkind
(P
) = N_Indexed_Component
then
3524 if not Is_Entity_Name
(Prefix
(P
))
3525 or else No
(Entity
(Prefix
(P
)))
3526 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3528 if Nkind
(Prefix
(P
)) = N_Selected_Component
3529 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3530 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3534 ("attribute % must apply to entry of current task", P
);
3537 Error_Attr
("invalid entry family name", P
);
3542 Ent
:= Entity
(Prefix
(P
));
3545 elsif Nkind
(P
) = N_Selected_Component
3546 and then Present
(Entity
(Selector_Name
(P
)))
3547 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3550 ("attribute % must apply to entry of current task", P
);
3553 Error_Attr
("invalid entry name", N
);
3557 for J
in reverse 0 .. Scope_Stack
.Last
loop
3558 S
:= Scope_Stack
.Table
(J
).Entity
;
3560 if S
= Scope
(Ent
) then
3561 if Nkind
(P
) = N_Expanded_Name
then
3562 Tsk
:= Entity
(Prefix
(P
));
3564 -- The prefix denotes either the task type, or else a
3565 -- single task whose task type is being analyzed.
3567 if (Is_Type
(Tsk
) and then Tsk
= S
)
3568 or else (not Is_Type
(Tsk
)
3569 and then Etype
(Tsk
) = S
3570 and then not (Comes_From_Source
(S
)))
3575 ("Attribute % must apply to entry of current task", N
);
3581 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3582 and then not Ekind_In
(S
, E_Block
,
3587 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3589 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3590 and then not Has_Completion
(Scope
(Ent
))
3592 Error_Attr
("attribute % can only be used inside body", N
);
3596 if Is_Overloaded
(P
) then
3598 Index
: Interp_Index
;
3602 Get_First_Interp
(P
, Index
, It
);
3603 while Present
(It
.Nam
) loop
3604 if It
.Nam
= Ent
then
3607 -- Ada 2005 (AI-345): Do not consider primitive entry
3608 -- wrappers generated for task or protected types.
3610 elsif Ada_Version
>= Ada_2005
3611 and then not Comes_From_Source
(It
.Nam
)
3616 Error_Attr
("ambiguous entry name", N
);
3619 Get_Next_Interp
(Index
, It
);
3624 Set_Etype
(N
, Universal_Integer
);
3627 -----------------------
3628 -- Default_Bit_Order --
3629 -----------------------
3631 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
3632 Target_Default_Bit_Order
: System
.Bit_Order
;
3635 Check_Standard_Prefix
;
3637 if Bytes_Big_Endian
then
3638 Target_Default_Bit_Order
:= System
.High_Order_First
;
3640 Target_Default_Bit_Order
:= System
.Low_Order_First
;
3644 Make_Integer_Literal
(Loc
,
3645 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
3647 Set_Etype
(N
, Universal_Integer
);
3648 Set_Is_Static_Expression
(N
);
3649 end Default_Bit_Order
;
3651 ----------------------------------
3652 -- Default_Scalar_Storage_Order --
3653 ----------------------------------
3655 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
3656 RE_Default_SSO
: RE_Id
;
3659 Check_Standard_Prefix
;
3661 case Opt
.Default_SSO
is
3663 if Bytes_Big_Endian
then
3664 RE_Default_SSO
:= RE_High_Order_First
;
3666 RE_Default_SSO
:= RE_Low_Order_First
;
3670 RE_Default_SSO
:= RE_High_Order_First
;
3673 RE_Default_SSO
:= RE_Low_Order_First
;
3676 raise Program_Error
;
3679 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
3686 when Attribute_Definite
=>
3687 Legal_Formal_Attribute
;
3693 when Attribute_Delta
=>
3694 Check_Fixed_Point_Type_0
;
3695 Set_Etype
(N
, Universal_Real
);
3701 when Attribute_Denorm
=>
3702 Check_Floating_Point_Type_0
;
3703 Set_Etype
(N
, Standard_Boolean
);
3709 when Attribute_Deref
=>
3712 Resolve
(E1
, RTE
(RE_Address
));
3713 Set_Etype
(N
, P_Type
);
3715 ---------------------
3716 -- Descriptor_Size --
3717 ---------------------
3719 when Attribute_Descriptor_Size
=>
3722 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3723 Error_Attr_P
("prefix of attribute % must denote a type");
3726 Set_Etype
(N
, Universal_Integer
);
3732 when Attribute_Digits
=>
3736 if not Is_Floating_Point_Type
(P_Type
)
3737 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3740 ("prefix of % attribute must be float or decimal type");
3743 Set_Etype
(N
, Universal_Integer
);
3749 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3751 when Attribute_Elab_Body
3752 | Attribute_Elab_Spec
3753 | Attribute_Elab_Subp_Body
3756 Check_Unit_Name
(P
);
3757 Set_Etype
(N
, Standard_Void_Type
);
3759 -- We have to manually call the expander in this case to get
3760 -- the necessary expansion (normally attributes that return
3761 -- entities are not expanded).
3769 -- Shares processing with Elab_Body
3775 when Attribute_Elaborated
=>
3777 Check_Unit_Name
(P
);
3778 Set_Etype
(N
, Standard_Boolean
);
3784 when Attribute_Emax
=>
3785 Check_Floating_Point_Type_0
;
3786 Set_Etype
(N
, Universal_Integer
);
3792 when Attribute_Enabled
=>
3793 Check_Either_E0_Or_E1
;
3795 if Present
(E1
) then
3796 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3797 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3802 if Nkind
(P
) /= N_Identifier
then
3803 Error_Msg_N
("identifier expected (check name)", P
);
3804 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3805 Error_Msg_N
("& is not a recognized check name", P
);
3808 Set_Etype
(N
, Standard_Boolean
);
3814 when Attribute_Enum_Rep
=>
3816 -- T'Enum_Rep (X) case
3818 if Present
(E1
) then
3820 Check_Discrete_Type
;
3821 Resolve
(E1
, P_Base_Type
);
3823 -- X'Enum_Rep case. X must be an object or enumeration literal, and
3824 -- it must be of a discrete type.
3827 ((Is_Object_Reference
(P
)
3830 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
))
3831 and then Is_Discrete_Type
(Etype
(P
)))
3833 Error_Attr_P
("prefix of % attribute must be discrete object");
3836 Set_Etype
(N
, Universal_Integer
);
3842 when Attribute_Enum_Val
=>
3846 if not Is_Enumeration_Type
(P_Type
) then
3847 Error_Attr_P
("prefix of % attribute must be enumeration type");
3850 -- If the enumeration type has a standard representation, the effect
3851 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3853 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3855 Make_Attribute_Reference
(Loc
,
3856 Prefix
=> Relocate_Node
(Prefix
(N
)),
3857 Attribute_Name
=> Name_Val
,
3858 Expressions
=> New_List
(Relocate_Node
(E1
))));
3859 Analyze_And_Resolve
(N
, P_Base_Type
);
3861 -- Non-standard representation case (enumeration with holes)
3865 Resolve
(E1
, Any_Integer
);
3866 Set_Etype
(N
, P_Base_Type
);
3873 when Attribute_Epsilon
=>
3874 Check_Floating_Point_Type_0
;
3875 Set_Etype
(N
, Universal_Real
);
3881 when Attribute_Exponent
=>
3882 Check_Floating_Point_Type_1
;
3883 Set_Etype
(N
, Universal_Integer
);
3884 Resolve
(E1
, P_Base_Type
);
3890 when Attribute_External_Tag
=>
3894 Set_Etype
(N
, Standard_String
);
3896 if not Is_Tagged_Type
(P_Type
) then
3897 Error_Attr_P
("prefix of % attribute must be tagged");
3904 when Attribute_Fast_Math
=>
3905 Check_Standard_Prefix
;
3906 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3908 -----------------------
3909 -- Finalization_Size --
3910 -----------------------
3912 when Attribute_Finalization_Size
=>
3915 -- The prefix denotes an object
3917 if Is_Object_Reference
(P
) then
3918 Check_Object_Reference
(P
);
3920 -- The prefix denotes a type
3922 elsif Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3924 Check_Not_Incomplete_Type
;
3926 -- Attribute 'Finalization_Size is not defined for class-wide
3927 -- types because it is not possible to know statically whether
3928 -- a definite type will have controlled components or not.
3930 if Is_Class_Wide_Type
(Etype
(P
)) then
3932 ("prefix of % attribute cannot denote a class-wide type");
3935 -- The prefix denotes an illegal construct
3939 ("prefix of % attribute must be a definite type or an object");
3942 Set_Etype
(N
, Universal_Integer
);
3948 when Attribute_First
=>
3949 Check_Array_Or_Scalar_Type
;
3950 Bad_Attribute_For_Predicate
;
3956 when Attribute_First_Bit
=>
3958 Set_Etype
(N
, Universal_Integer
);
3964 when Attribute_First_Valid
=>
3965 Check_First_Last_Valid
;
3966 Set_Etype
(N
, P_Type
);
3972 when Attribute_Fixed_Value
=>
3974 Check_Fixed_Point_Type
;
3975 Resolve
(E1
, Any_Integer
);
3976 Set_Etype
(N
, P_Base_Type
);
3982 when Attribute_Floor
=>
3983 Check_Floating_Point_Type_1
;
3984 Set_Etype
(N
, P_Base_Type
);
3985 Resolve
(E1
, P_Base_Type
);
3991 when Attribute_Fore
=>
3992 Check_Fixed_Point_Type_0
;
3993 Set_Etype
(N
, Universal_Integer
);
3999 when Attribute_Fraction
=>
4000 Check_Floating_Point_Type_1
;
4001 Set_Etype
(N
, P_Base_Type
);
4002 Resolve
(E1
, P_Base_Type
);
4008 when Attribute_From_Any
=>
4010 Check_PolyORB_Attribute
;
4011 Set_Etype
(N
, P_Base_Type
);
4013 -----------------------
4014 -- Has_Access_Values --
4015 -----------------------
4017 when Attribute_Has_Access_Values
=>
4020 Set_Etype
(N
, Standard_Boolean
);
4022 ----------------------
4023 -- Has_Same_Storage --
4024 ----------------------
4026 when Attribute_Has_Same_Storage
=>
4029 -- The arguments must be objects of any type
4031 Analyze_And_Resolve
(P
);
4032 Analyze_And_Resolve
(E1
);
4033 Check_Object_Reference
(P
);
4034 Check_Object_Reference
(E1
);
4035 Set_Etype
(N
, Standard_Boolean
);
4037 -----------------------
4038 -- Has_Tagged_Values --
4039 -----------------------
4041 when Attribute_Has_Tagged_Values
=>
4044 Set_Etype
(N
, Standard_Boolean
);
4046 -----------------------
4047 -- Has_Discriminants --
4048 -----------------------
4050 when Attribute_Has_Discriminants
=>
4051 Legal_Formal_Attribute
;
4057 when Attribute_Identity
=>
4061 if Etype
(P
) = Standard_Exception_Type
then
4062 Set_Etype
(N
, RTE
(RE_Exception_Id
));
4064 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
4065 -- interface class-wide types.
4067 elsif Is_Task_Type
(Etype
(P
))
4068 or else (Is_Access_Type
(Etype
(P
))
4069 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
4070 or else (Ada_Version
>= Ada_2005
4071 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
4072 and then Is_Interface
(Etype
(P
))
4073 and then Is_Task_Interface
(Etype
(P
)))
4076 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
4079 if Ada_Version
>= Ada_2005
then
4081 ("prefix of % attribute must be an exception, a task or a "
4082 & "task interface class-wide object");
4085 ("prefix of % attribute must be a task or an exception");
4093 when Attribute_Image
=>
4094 if Is_Real_Type
(P_Type
) then
4095 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4096 Error_Msg_Name_1
:= Aname
;
4098 ("(Ada 83) % attribute not allowed for real types", N
);
4102 Analyze_Image_Attribute
(Standard_String
);
4108 when Attribute_Img
=>
4109 Analyze_Image_Attribute
(Standard_String
);
4115 when Attribute_Input
=>
4117 Check_Stream_Attribute
(TSS_Stream_Input
);
4118 Set_Etype
(N
, P_Base_Type
);
4124 when Attribute_Integer_Value
=>
4127 Resolve
(E1
, Any_Fixed
);
4129 -- Signal an error if argument type is not a specific fixed-point
4130 -- subtype. An error has been signalled already if the argument
4131 -- was not of a fixed-point type.
4133 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4134 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4137 Set_Etype
(N
, P_Base_Type
);
4143 when Attribute_Invalid_Value
=>
4146 Set_Etype
(N
, P_Base_Type
);
4147 Invalid_Value_Used
:= True;
4153 when Attribute_Large
=>
4156 Set_Etype
(N
, Universal_Real
);
4162 when Attribute_Last
=>
4163 Check_Array_Or_Scalar_Type
;
4164 Bad_Attribute_For_Predicate
;
4170 when Attribute_Last_Bit
=>
4172 Set_Etype
(N
, Universal_Integer
);
4178 when Attribute_Last_Valid
=>
4179 Check_First_Last_Valid
;
4180 Set_Etype
(N
, P_Type
);
4186 when Attribute_Leading_Part
=>
4187 Check_Floating_Point_Type_2
;
4188 Set_Etype
(N
, P_Base_Type
);
4189 Resolve
(E1
, P_Base_Type
);
4190 Resolve
(E2
, Any_Integer
);
4196 when Attribute_Length
=>
4198 Set_Etype
(N
, Universal_Integer
);
4204 when Attribute_Library_Level
=>
4207 if not Is_Entity_Name
(P
) then
4208 Error_Attr_P
("prefix of % attribute must be an entity name");
4211 if not Inside_A_Generic
then
4212 Set_Boolean_Result
(N
,
4213 Is_Library_Level_Entity
(Entity
(P
)));
4216 Set_Etype
(N
, Standard_Boolean
);
4222 when Attribute_Lock_Free
=>
4224 Set_Etype
(N
, Standard_Boolean
);
4226 if not Is_Protected_Type
(P_Type
) then
4228 ("prefix of % attribute must be a protected object");
4235 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4236 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4237 -- Inspect the prefix for any uses of entities declared within the
4238 -- related loop. Loop_Id denotes the loop identifier.
4240 --------------------------------
4241 -- Check_References_In_Prefix --
4242 --------------------------------
4244 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4245 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4247 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4248 -- Determine whether a reference mentions an entity declared
4249 -- within the related loop.
4251 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4252 -- Determine whether Nod appears in the subtree of Loop_Decl
4254 ---------------------
4255 -- Check_Reference --
4256 ---------------------
4258 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4260 if Nkind
(Nod
) = N_Identifier
4261 and then Present
(Entity
(Nod
))
4262 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4265 ("prefix of attribute % cannot reference local entities",
4271 end Check_Reference
;
4273 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4275 ---------------------
4276 -- Declared_Within --
4277 ---------------------
4279 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4284 while Present
(Stmt
) loop
4285 if Stmt
= Loop_Decl
then
4288 -- Prevent the search from going too far
4290 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4294 Stmt
:= Parent
(Stmt
);
4298 end Declared_Within
;
4300 -- Start of processing for Check_Prefix_For_Local_References
4303 Check_References
(P
);
4304 end Check_References_In_Prefix
;
4308 Context
: constant Node_Id
:= Parent
(N
);
4310 Encl_Loop
: Node_Id
:= Empty
;
4311 Encl_Prag
: Node_Id
:= Empty
;
4312 Loop_Id
: Entity_Id
:= Empty
;
4316 -- Start of processing for Loop_Entry
4321 -- Set the type of the attribute now to ensure the successful
4322 -- continuation of analysis even if the attribute is misplaced.
4324 Set_Etype
(Attr
, P_Type
);
4326 -- Attribute 'Loop_Entry may appear in several flavors:
4328 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4329 -- nearest enclosing loop.
4331 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4332 -- attribute may be related to a loop denoted by label Expr or
4333 -- the prefix may denote an array object and Expr may act as an
4334 -- indexed component.
4336 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4337 -- to the nearest enclosing loop, all expressions are part of
4338 -- an indexed component.
4340 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4341 -- denotes, the attribute may be related to a loop denoted by
4342 -- label Expr or the prefix may denote a multidimensional array
4343 -- array object and Expr along with the rest of the expressions
4344 -- may act as indexed components.
4346 -- Regardless of variations, the attribute reference does not have an
4347 -- expression list. Instead, all available expressions are stored as
4348 -- indexed components.
4350 -- When the attribute is part of an indexed component, find the first
4351 -- expression as it will determine the semantics of 'Loop_Entry.
4353 -- If the attribute is itself an index in an indexed component, i.e.
4354 -- a member of a list, the context itself is not relevant (the code
4355 -- below would lead to an infinite loop) and the attribute applies
4356 -- to the enclosing loop.
4358 if Nkind
(Context
) = N_Indexed_Component
4359 and then not Is_List_Member
(N
)
4361 E1
:= First
(Expressions
(Context
));
4364 -- The attribute reference appears in the following form:
4366 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4368 -- In this case, the loop name is omitted and no rewriting is
4371 if Present
(E2
) then
4374 -- The form of the attribute is:
4376 -- Prefix'Loop_Entry (Expr) [(...)]
4378 -- If Expr denotes a loop entry, the whole attribute and indexed
4379 -- component will have to be rewritten to reflect this relation.
4382 pragma Assert
(Present
(E1
));
4384 -- Do not expand the expression as it may have side effects.
4385 -- Simply preanalyze to determine whether it is a loop name or
4388 Preanalyze_And_Resolve
(E1
);
4390 if Is_Entity_Name
(E1
)
4391 and then Present
(Entity
(E1
))
4392 and then Ekind
(Entity
(E1
)) = E_Loop
4394 Loop_Id
:= Entity
(E1
);
4396 -- Transform the attribute and enclosing indexed component
4398 Set_Expressions
(N
, Expressions
(Context
));
4399 Rewrite
(Context
, N
);
4400 Set_Etype
(Context
, P_Type
);
4407 -- The prefix must denote an object
4409 if not Is_Object_Reference
(P
) then
4410 Error_Attr_P
("prefix of attribute % must denote an object");
4413 -- The prefix cannot be of a limited type because the expansion of
4414 -- Loop_Entry must create a constant initialized by the evaluated
4417 if Is_Limited_View
(Etype
(P
)) then
4418 Error_Attr_P
("prefix of attribute % cannot be limited");
4421 -- Climb the parent chain to verify the location of the attribute and
4422 -- find the enclosing loop.
4425 while Present
(Stmt
) loop
4427 -- Locate the corresponding enclosing pragma. Note that in the
4428 -- case of Assert[And_Cut] and Assume, we have already checked
4429 -- that the pragma appears in an appropriate loop location.
4431 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4432 and then Nam_In
(Pragma_Name_Unmapped
(Original_Node
(Stmt
)),
4433 Name_Loop_Invariant
,
4436 Name_Assert_And_Cut
,
4439 Encl_Prag
:= Original_Node
(Stmt
);
4441 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4442 -- iteration may be expanded into several nested loops, we are
4443 -- interested in the outermost one which has the loop identifier,
4444 -- and comes from source.
4446 elsif Nkind
(Stmt
) = N_Loop_Statement
4447 and then Present
(Identifier
(Stmt
))
4448 and then Comes_From_Source
(Original_Node
(Stmt
))
4449 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
4453 -- The original attribute reference may lack a loop name. Use
4454 -- the name of the enclosing loop because it is the related
4457 if No
(Loop_Id
) then
4458 Loop_Id
:= Entity
(Identifier
(Encl_Loop
));
4463 -- Prevent the search from going too far
4465 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4469 Stmt
:= Parent
(Stmt
);
4472 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4473 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4474 -- purpose if they appear in an appropriate location in a loop,
4475 -- which was already checked by the top level pragma circuit).
4477 -- Loop_Entry also denotes a value and as such can appear within an
4478 -- expression that is an argument for another loop aspect. In that
4479 -- case it will have been expanded into the corresponding assignment.
4482 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
4483 and then not Comes_From_Source
(Parent
(N
))
4487 elsif No
(Encl_Prag
) then
4488 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4491 -- A Loop_Entry that applies to a given loop statement must not
4492 -- appear within a body of accept statement, if this construct is
4493 -- itself enclosed by the given loop statement.
4495 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4496 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4498 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4500 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4504 ("attribute % cannot appear in body or accept statement", N
);
4509 -- The prefix cannot mention entities declared within the related
4510 -- loop because they will not be visible once the prefix is moved
4511 -- outside the loop.
4513 Check_References_In_Prefix
(Loop_Id
);
4515 -- The prefix must denote a static entity if the pragma does not
4516 -- apply to the innermost enclosing loop statement, or if it appears
4517 -- within a potentially unevaluated epxression.
4519 if Is_Entity_Name
(P
)
4520 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4521 or else Statically_Denotes_Object
(P
)
4525 elsif Present
(Encl_Loop
)
4526 and then Entity
(Identifier
(Encl_Loop
)) /= Loop_Id
4529 ("prefix of attribute % that applies to outer loop must denote "
4532 elsif Is_Potentially_Unevaluated
(P
) then
4536 -- Replace the Loop_Entry attribute reference by its prefix if the
4537 -- related pragma is ignored. This transformation is OK with respect
4538 -- to typing because Loop_Entry's type is that of its prefix. This
4539 -- early transformation also avoids the generation of a useless loop
4542 if Present
(Encl_Prag
) and then Is_Ignored
(Encl_Prag
) then
4543 Rewrite
(N
, Relocate_Node
(P
));
4544 Preanalyze_And_Resolve
(N
);
4547 Preanalyze_And_Resolve
(P
);
4555 when Attribute_Machine
=>
4556 Check_Floating_Point_Type_1
;
4557 Set_Etype
(N
, P_Base_Type
);
4558 Resolve
(E1
, P_Base_Type
);
4564 when Attribute_Machine_Emax
=>
4565 Check_Floating_Point_Type_0
;
4566 Set_Etype
(N
, Universal_Integer
);
4572 when Attribute_Machine_Emin
=>
4573 Check_Floating_Point_Type_0
;
4574 Set_Etype
(N
, Universal_Integer
);
4576 ----------------------
4577 -- Machine_Mantissa --
4578 ----------------------
4580 when Attribute_Machine_Mantissa
=>
4581 Check_Floating_Point_Type_0
;
4582 Set_Etype
(N
, Universal_Integer
);
4584 -----------------------
4585 -- Machine_Overflows --
4586 -----------------------
4588 when Attribute_Machine_Overflows
=>
4591 Set_Etype
(N
, Standard_Boolean
);
4597 when Attribute_Machine_Radix
=>
4600 Set_Etype
(N
, Universal_Integer
);
4602 ----------------------
4603 -- Machine_Rounding --
4604 ----------------------
4606 when Attribute_Machine_Rounding
=>
4607 Check_Floating_Point_Type_1
;
4608 Set_Etype
(N
, P_Base_Type
);
4609 Resolve
(E1
, P_Base_Type
);
4611 --------------------
4612 -- Machine_Rounds --
4613 --------------------
4615 when Attribute_Machine_Rounds
=>
4618 Set_Etype
(N
, Standard_Boolean
);
4624 when Attribute_Machine_Size
=>
4627 Check_Not_Incomplete_Type
;
4628 Set_Etype
(N
, Universal_Integer
);
4634 when Attribute_Mantissa
=>
4637 Set_Etype
(N
, Universal_Integer
);
4643 when Attribute_Max
=>
4646 ----------------------------------
4647 -- Max_Alignment_For_Allocation --
4648 ----------------------------------
4650 when Attribute_Max_Size_In_Storage_Elements
=>
4651 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4653 ----------------------------------
4654 -- Max_Size_In_Storage_Elements --
4655 ----------------------------------
4657 when Attribute_Max_Alignment_For_Allocation
=>
4658 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4660 -----------------------
4661 -- Maximum_Alignment --
4662 -----------------------
4664 when Attribute_Maximum_Alignment
=>
4665 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4667 --------------------
4668 -- Mechanism_Code --
4669 --------------------
4671 when Attribute_Mechanism_Code
=>
4672 if not Is_Entity_Name
(P
)
4673 or else not Is_Subprogram
(Entity
(P
))
4675 Error_Attr_P
("prefix of % attribute must be subprogram");
4678 Check_Either_E0_Or_E1
;
4680 if Present
(E1
) then
4681 Resolve
(E1
, Any_Integer
);
4682 Set_Etype
(E1
, Standard_Integer
);
4684 if not Is_OK_Static_Expression
(E1
) then
4685 Flag_Non_Static_Expr
4686 ("expression for parameter number must be static!", E1
);
4689 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4690 or else UI_To_Int
(Intval
(E1
)) < 0
4692 Error_Attr
("invalid parameter number for % attribute", E1
);
4696 Set_Etype
(N
, Universal_Integer
);
4702 when Attribute_Min
=>
4709 when Attribute_Mod
=>
4711 -- Note: this attribute is only allowed in Ada 2005 mode, but
4712 -- we do not need to test that here, since Mod is only recognized
4713 -- as an attribute name in Ada 2005 mode during the parse.
4716 Check_Modular_Integer_Type
;
4717 Resolve
(E1
, Any_Integer
);
4718 Set_Etype
(N
, P_Base_Type
);
4724 when Attribute_Model
=>
4725 Check_Floating_Point_Type_1
;
4726 Set_Etype
(N
, P_Base_Type
);
4727 Resolve
(E1
, P_Base_Type
);
4733 when Attribute_Model_Emin
=>
4734 Check_Floating_Point_Type_0
;
4735 Set_Etype
(N
, Universal_Integer
);
4741 when Attribute_Model_Epsilon
=>
4742 Check_Floating_Point_Type_0
;
4743 Set_Etype
(N
, Universal_Real
);
4745 --------------------
4746 -- Model_Mantissa --
4747 --------------------
4749 when Attribute_Model_Mantissa
=>
4750 Check_Floating_Point_Type_0
;
4751 Set_Etype
(N
, Universal_Integer
);
4757 when Attribute_Model_Small
=>
4758 Check_Floating_Point_Type_0
;
4759 Set_Etype
(N
, Universal_Real
);
4765 when Attribute_Modulus
=>
4767 Check_Modular_Integer_Type
;
4768 Set_Etype
(N
, Universal_Integer
);
4770 --------------------
4771 -- Null_Parameter --
4772 --------------------
4774 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4775 Parnt
: constant Node_Id
:= Parent
(N
);
4776 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4778 procedure Bad_Null_Parameter
(Msg
: String);
4779 -- Used if bad Null parameter attribute node is found. Issues
4780 -- given error message, and also sets the type to Any_Type to
4781 -- avoid blowups later on from dealing with a junk node.
4783 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4784 -- Called to check that Proc_Ent is imported subprogram
4786 ------------------------
4787 -- Bad_Null_Parameter --
4788 ------------------------
4790 procedure Bad_Null_Parameter
(Msg
: String) is
4792 Error_Msg_N
(Msg
, N
);
4793 Set_Etype
(N
, Any_Type
);
4794 end Bad_Null_Parameter
;
4796 ----------------------
4797 -- Must_Be_Imported --
4798 ----------------------
4800 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4801 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4804 -- Ignore check if procedure not frozen yet (we will get
4805 -- another chance when the default parameter is reanalyzed)
4807 if not Is_Frozen
(Pent
) then
4810 elsif not Is_Imported
(Pent
) then
4812 ("Null_Parameter can only be used with imported subprogram");
4817 end Must_Be_Imported
;
4819 -- Start of processing for Null_Parameter
4824 Set_Etype
(N
, P_Type
);
4826 -- Case of attribute used as default expression
4828 if Nkind
(Parnt
) = N_Parameter_Specification
then
4829 Must_Be_Imported
(Defining_Entity
(GParnt
));
4831 -- Case of attribute used as actual for subprogram (positional)
4833 elsif Nkind
(Parnt
) in N_Subprogram_Call
4834 and then Is_Entity_Name
(Name
(Parnt
))
4836 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4838 -- Case of attribute used as actual for subprogram (named)
4840 elsif Nkind
(Parnt
) = N_Parameter_Association
4841 and then Nkind
(GParnt
) in N_Subprogram_Call
4842 and then Is_Entity_Name
(Name
(GParnt
))
4844 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4846 -- Not an allowed case
4850 ("Null_Parameter must be actual or default parameter");
4858 when Attribute_Object_Size
=>
4861 Check_Not_Incomplete_Type
;
4862 Set_Etype
(N
, Universal_Integer
);
4868 when Attribute_Old
=> Old
: declare
4869 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4870 -- Inspect the contents of the prefix and detect illegal uses of a
4871 -- nested 'Old, attribute 'Result or a use of an entity declared in
4872 -- the related postcondition expression. Subp_Id is the subprogram to
4873 -- which the related postcondition applies.
4875 --------------------------------
4876 -- Check_References_In_Prefix --
4877 --------------------------------
4879 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4880 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4881 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4882 -- and perform the appropriate semantic check.
4884 ---------------------
4885 -- Check_Reference --
4886 ---------------------
4888 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4890 -- Attributes 'Old and 'Result cannot appear in the prefix of
4891 -- another attribute 'Old.
4893 if Nkind
(Nod
) = N_Attribute_Reference
4894 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4897 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4898 Error_Msg_Name_2
:= Name_Old
;
4900 ("attribute % cannot appear in the prefix of attribute %",
4904 -- Entities mentioned within the prefix of attribute 'Old must
4905 -- be global to the related postcondition. If this is not the
4906 -- case, then the scope of the local entity is nested within
4907 -- that of the subprogram.
4909 elsif Is_Entity_Name
(Nod
)
4910 and then Present
(Entity
(Nod
))
4911 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4914 ("prefix of attribute % cannot reference local entities",
4918 -- Otherwise keep inspecting the prefix
4923 end Check_Reference
;
4925 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4927 -- Start of processing for Check_References_In_Prefix
4930 Check_References
(P
);
4931 end Check_References_In_Prefix
;
4936 Pref_Id
: Entity_Id
;
4937 Pref_Typ
: Entity_Id
;
4938 Spec_Id
: Entity_Id
;
4940 -- Start of processing for Old
4943 -- The attribute reference is a primary. If any expressions follow,
4944 -- then the attribute reference is an indexable object. Transform the
4945 -- attribute into an indexed component and analyze it.
4947 if Present
(E1
) then
4949 Make_Indexed_Component
(Loc
,
4951 Make_Attribute_Reference
(Loc
,
4952 Prefix
=> Relocate_Node
(P
),
4953 Attribute_Name
=> Name_Old
),
4954 Expressions
=> Expressions
(N
)));
4959 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
4961 -- The aspect or pragma where attribute 'Old resides should be
4962 -- associated with a subprogram declaration or a body. If this is not
4963 -- the case, then the aspect or pragma is illegal. Return as analysis
4964 -- cannot be carried out.
4966 -- The exception to this rule is when generating C since in this case
4967 -- postconditions are inlined.
4970 and then Modify_Tree_For_C
4971 and then In_Inlined_Body
4973 Spec_Id
:= Entity
(P
);
4975 elsif not Legal
then
4979 -- The prefix must be preanalyzed as the full analysis will take
4980 -- place during expansion.
4982 Preanalyze_And_Resolve
(P
);
4984 -- Ensure that the prefix does not contain attributes 'Old or 'Result
4986 Check_References_In_Prefix
(Spec_Id
);
4988 -- Set the type of the attribute now to prevent cascaded errors
4990 Pref_Typ
:= Etype
(P
);
4991 Set_Etype
(N
, Pref_Typ
);
4995 if Is_Limited_Type
(Pref_Typ
) then
4996 Error_Attr
("attribute % cannot apply to limited objects", P
);
4999 -- The prefix is a simple name
5001 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
5002 Pref_Id
:= Entity
(P
);
5004 -- Emit a warning when the prefix is a constant. Note that the use
5005 -- of Error_Attr would reset the type of N to Any_Type even though
5006 -- this is a warning. Use Error_Msg_XXX instead.
5008 if Is_Constant_Object
(Pref_Id
) then
5009 Error_Msg_Name_1
:= Name_Old
;
5011 ("??attribute % applied to constant has no effect", P
);
5014 -- Otherwise the prefix is not a simple name
5017 -- Ensure that the prefix of attribute 'Old is an entity when it
5018 -- is potentially unevaluated (6.1.1 (27/3)).
5020 if Is_Potentially_Unevaluated
(N
)
5021 and then not Statically_Denotes_Object
(P
)
5025 -- Detect a possible infinite recursion when the prefix denotes
5026 -- the related function.
5028 -- function Func (...) return ...
5029 -- with Post => Func'Old ...;
5031 -- The function may be specified in qualified form X.Y where X is
5032 -- a protected object and Y is a protected function. In that case
5033 -- ensure that the qualified form has an entity.
5035 elsif Nkind
(P
) = N_Function_Call
5036 and then Nkind
(Name
(P
)) in N_Has_Entity
5038 Pref_Id
:= Entity
(Name
(P
));
5040 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
5041 and then Pref_Id
= Spec_Id
5043 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5044 Error_Msg_N
("!possible infinite recursion<<", P
);
5045 Error_Msg_N
("\!??Storage_Error ]<<", P
);
5049 -- The prefix of attribute 'Old may refer to a component of a
5050 -- formal parameter. In this case its expansion may generate
5051 -- actual subtypes that are referenced in an inner context and
5052 -- that must be elaborated within the subprogram itself. If the
5053 -- prefix includes a function call, it may involve finalization
5054 -- actions that should be inserted when the attribute has been
5055 -- rewritten as a declaration. Create a declaration for the prefix
5056 -- and insert it at the start of the enclosing subprogram. This is
5057 -- an expansion activity that has to be performed now to prevent
5058 -- out-of-order issues.
5060 -- This expansion is both harmful and not needed in SPARK mode,
5061 -- since the formal verification back end relies on the types of
5062 -- nodes (hence is not robust w.r.t. a change to base type here),
5063 -- and does not suffer from the out-of-order issue described
5064 -- above. Thus, this expansion is skipped in SPARK mode.
5066 -- The expansion is not relevant for discrete types, which will
5067 -- not generate extra declarations, and where use of the base type
5068 -- may lead to spurious errors if context is a case.
5070 if not GNATprove_Mode
then
5071 if not Is_Discrete_Type
(Pref_Typ
) then
5072 Pref_Typ
:= Base_Type
(Pref_Typ
);
5075 Set_Etype
(N
, Pref_Typ
);
5076 Set_Etype
(P
, Pref_Typ
);
5078 Analyze_Dimension
(N
);
5084 ----------------------
5085 -- Overlaps_Storage --
5086 ----------------------
5088 when Attribute_Overlaps_Storage
=>
5091 -- Both arguments must be objects of any type
5093 Analyze_And_Resolve
(P
);
5094 Analyze_And_Resolve
(E1
);
5095 Check_Object_Reference
(P
);
5096 Check_Object_Reference
(E1
);
5097 Set_Etype
(N
, Standard_Boolean
);
5103 when Attribute_Output
=>
5105 Check_Stream_Attribute
(TSS_Stream_Output
);
5106 Set_Etype
(N
, Standard_Void_Type
);
5107 Resolve
(N
, Standard_Void_Type
);
5113 when Attribute_Partition_ID
=>
5116 if P_Type
/= Any_Type
then
5117 if not Is_Library_Level_Entity
(Entity
(P
)) then
5119 ("prefix of % attribute must be library-level entity");
5121 -- The defining entity of prefix should not be declared inside a
5122 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5124 elsif Is_Entity_Name
(P
)
5125 and then Is_Pure
(Entity
(P
))
5127 Error_Attr_P
("prefix of% attribute must not be declared pure");
5131 Set_Etype
(N
, Universal_Integer
);
5133 -------------------------
5134 -- Passed_By_Reference --
5135 -------------------------
5137 when Attribute_Passed_By_Reference
=>
5140 Set_Etype
(N
, Standard_Boolean
);
5146 when Attribute_Pool_Address
=>
5148 Set_Etype
(N
, RTE
(RE_Address
));
5154 when Attribute_Pos
=>
5155 Check_Discrete_Type
;
5158 if Is_Boolean_Type
(P_Type
) then
5159 Error_Msg_Name_1
:= Aname
;
5160 Error_Msg_Name_2
:= Chars
(P_Type
);
5161 Check_SPARK_05_Restriction
5162 ("attribute% is not allowed for type%", P
);
5165 Resolve
(E1
, P_Base_Type
);
5166 Set_Etype
(N
, Universal_Integer
);
5172 when Attribute_Position
=>
5174 Set_Etype
(N
, Universal_Integer
);
5180 when Attribute_Pred
=>
5184 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5185 Error_Msg_Name_1
:= Aname
;
5186 Error_Msg_Name_2
:= Chars
(P_Type
);
5187 Check_SPARK_05_Restriction
5188 ("attribute% is not allowed for type%", P
);
5191 Resolve
(E1
, P_Base_Type
);
5192 Set_Etype
(N
, P_Base_Type
);
5194 -- Since Pred works on the base type, we normally do no check for the
5195 -- floating-point case, since the base type is unconstrained. But we
5196 -- make an exception in Check_Float_Overflow mode.
5198 if Is_Floating_Point_Type
(P_Type
) then
5199 if not Range_Checks_Suppressed
(P_Base_Type
) then
5200 Set_Do_Range_Check
(E1
);
5203 -- If not modular type, test for overflow check required
5206 if not Is_Modular_Integer_Type
(P_Type
)
5207 and then not Range_Checks_Suppressed
(P_Base_Type
)
5209 Enable_Range_Check
(E1
);
5217 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5219 when Attribute_Priority
=>
5220 if Ada_Version
< Ada_2005
then
5221 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5226 Check_Restriction
(No_Dynamic_Priorities
, N
);
5228 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5232 if Is_Protected_Type
(Etype
(P
))
5233 or else (Is_Access_Type
(Etype
(P
))
5234 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5236 Resolve
(P
, Etype
(P
));
5238 Error_Attr_P
("prefix of % attribute must be a protected object");
5241 Set_Etype
(N
, Standard_Integer
);
5243 -- Must be called from within a protected procedure or entry of the
5244 -- protected object.
5251 while S
/= Etype
(P
)
5252 and then S
/= Standard_Standard
5257 if S
= Standard_Standard
then
5258 Error_Attr
("the attribute % is only allowed inside protected "
5263 Validate_Non_Static_Attribute_Function_Call
;
5269 when Attribute_Range
=>
5270 Check_Array_Or_Scalar_Type
;
5271 Bad_Attribute_For_Predicate
;
5273 if Ada_Version
= Ada_83
5274 and then Is_Scalar_Type
(P_Type
)
5275 and then Comes_From_Source
(N
)
5278 ("(Ada 83) % attribute not allowed for scalar type", P
);
5285 when Attribute_Result
=> Result
: declare
5286 function Denote_Same_Function
5287 (Pref_Id
: Entity_Id
;
5288 Spec_Id
: Entity_Id
) return Boolean;
5289 -- Determine whether the entity of the prefix Pref_Id denotes the
5290 -- same entity as that of the related subprogram Spec_Id.
5292 --------------------------
5293 -- Denote_Same_Function --
5294 --------------------------
5296 function Denote_Same_Function
5297 (Pref_Id
: Entity_Id
;
5298 Spec_Id
: Entity_Id
) return Boolean
5300 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5301 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5304 -- The prefix denotes the related subprogram
5306 if Pref_Id
= Spec_Id
then
5309 -- Account for a special case when attribute 'Result appears in
5310 -- the postcondition of a generic function.
5313 -- function Gen_Func return ...
5314 -- with Post => Gen_Func'Result ...;
5316 -- When the generic function is instantiated, the Chars field of
5317 -- the instantiated prefix still denotes the name of the generic
5318 -- function. Note that any preemptive transformation is impossible
5319 -- without a proper analysis. The structure of the wrapper package
5322 -- package Anon_Gen_Pack is
5323 -- <subtypes and renamings>
5324 -- function Subp_Decl return ...; -- (!)
5325 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5326 -- function Gen_Func ... renames Subp_Decl;
5327 -- end Anon_Gen_Pack;
5329 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5330 and then Present
(Generic_Parent
(Subp_Spec
))
5331 and then Ekind_In
(Pref_Id
, E_Generic_Function
, E_Function
)
5333 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5336 elsif Present
(Alias
(Pref_Id
))
5337 and then Alias
(Pref_Id
) = Spec_Id
5342 -- Account for a special case where a primitive of a tagged type
5343 -- inherits a class-wide postcondition from a parent type. In this
5344 -- case the prefix of attribute 'Result denotes the overriding
5347 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5351 -- Otherwise the prefix does not denote the related subprogram
5354 end Denote_Same_Function
;
5358 In_Inlined_C_Postcondition
: constant Boolean :=
5360 and then In_Inlined_Body
;
5363 Pref_Id
: Entity_Id
;
5364 Spec_Id
: Entity_Id
;
5366 -- Start of processing for Result
5369 -- The attribute reference is a primary. If any expressions follow,
5370 -- then the attribute reference is an indexable object. Transform the
5371 -- attribute into an indexed component and analyze it.
5373 if Present
(E1
) then
5375 Make_Indexed_Component
(Loc
,
5377 Make_Attribute_Reference
(Loc
,
5378 Prefix
=> Relocate_Node
(P
),
5379 Attribute_Name
=> Name_Result
),
5380 Expressions
=> Expressions
(N
)));
5385 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5387 -- The aspect or pragma where attribute 'Result resides should be
5388 -- associated with a subprogram declaration or a body. If this is not
5389 -- the case, then the aspect or pragma is illegal. Return as analysis
5390 -- cannot be carried out.
5392 -- The exception to this rule is when generating C since in this case
5393 -- postconditions are inlined.
5395 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5396 Spec_Id
:= Entity
(P
);
5398 elsif not Legal
then
5402 -- Attribute 'Result is part of a _Postconditions procedure. There is
5403 -- no need to perform the semantic checks below as they were already
5404 -- verified when the attribute was analyzed in its original context.
5405 -- Instead, rewrite the attribute as a reference to formal parameter
5406 -- _Result of the _Postconditions procedure.
5408 if Chars
(Spec_Id
) = Name_uPostconditions
5410 (In_Inlined_C_Postcondition
5411 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5413 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5415 -- The type of formal parameter _Result is that of the function
5416 -- encapsulating the _Postconditions procedure. Resolution must
5417 -- be carried out against the function return type.
5419 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
5421 -- Otherwise attribute 'Result appears in its original context and
5422 -- all semantic checks should be carried out.
5425 -- Verify the legality of the prefix. It must denotes the entity
5426 -- of the related [generic] function.
5428 if Is_Entity_Name
(P
) then
5429 Pref_Id
:= Entity
(P
);
5431 if Ekind_In
(Pref_Id
, E_Function
, E_Generic_Function
)
5432 and then Ekind
(Spec_Id
) = Ekind
(Pref_Id
)
5434 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
5436 -- Correct the prefix of the attribute when the context
5437 -- is a generic function.
5439 if Pref_Id
/= Spec_Id
then
5440 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
5444 Set_Etype
(N
, Etype
(Spec_Id
));
5446 -- Otherwise the prefix denotes some unrelated function
5449 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5451 ("incorrect prefix for attribute %, expected %", P
);
5454 -- Otherwise the prefix denotes some other form of subprogram
5459 ("attribute % can only appear in postcondition of "
5463 -- Otherwise the prefix is illegal
5466 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5467 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
5476 when Attribute_Range_Length
=>
5478 Check_Discrete_Type
;
5479 Set_Etype
(N
, Universal_Integer
);
5485 when Attribute_Read
=>
5487 Check_Stream_Attribute
(TSS_Stream_Read
);
5488 Set_Etype
(N
, Standard_Void_Type
);
5489 Resolve
(N
, Standard_Void_Type
);
5490 Note_Possible_Modification
(E2
, Sure
=> True);
5496 when Attribute_Ref
=>
5500 if Nkind
(P
) /= N_Expanded_Name
5501 or else not Is_RTE
(P_Type
, RE_Address
)
5503 Error_Attr_P
("prefix of % attribute must be System.Address");
5506 Analyze_And_Resolve
(E1
, Any_Integer
);
5507 Set_Etype
(N
, RTE
(RE_Address
));
5513 when Attribute_Remainder
=>
5514 Check_Floating_Point_Type_2
;
5515 Set_Etype
(N
, P_Base_Type
);
5516 Resolve
(E1
, P_Base_Type
);
5517 Resolve
(E2
, P_Base_Type
);
5519 ---------------------
5520 -- Restriction_Set --
5521 ---------------------
5523 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5526 Unam
: Unit_Name_Type
;
5531 Check_System_Prefix
;
5533 -- No_Dependence case
5535 if Nkind
(E1
) = N_Parameter_Association
then
5536 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5537 U
:= Explicit_Actual_Parameter
(E1
);
5539 if not OK_No_Dependence_Unit_Name
(U
) then
5540 Set_Boolean_Result
(N
, False);
5544 -- See if there is an entry already in the table. That's the
5545 -- case in which we can return True.
5547 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5548 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5549 and then No_Dependences
.Table
(J
).Warn
= False
5551 Set_Boolean_Result
(N
, True);
5556 -- If not in the No_Dependence table, result is False
5558 Set_Boolean_Result
(N
, False);
5560 -- In this case, we must ensure that the binder will reject any
5561 -- other unit in the partition that sets No_Dependence for this
5562 -- unit. We do that by making an entry in the special table kept
5563 -- for this purpose (if the entry is not there already).
5565 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5567 for J
in Restriction_Set_Dependences
.First
..
5568 Restriction_Set_Dependences
.Last
5570 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5575 Restriction_Set_Dependences
.Append
(Unam
);
5577 -- Normal restriction case
5580 if Nkind
(E1
) /= N_Identifier
then
5581 Set_Boolean_Result
(N
, False);
5582 Error_Attr
("attribute % requires restriction identifier", E1
);
5585 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5587 if R
= Not_A_Restriction_Id
then
5588 Set_Boolean_Result
(N
, False);
5589 Error_Msg_Node_1
:= E1
;
5590 Error_Attr
("invalid restriction identifier &", E1
);
5592 elsif R
not in Partition_Boolean_Restrictions
then
5593 Set_Boolean_Result
(N
, False);
5594 Error_Msg_Node_1
:= E1
;
5596 ("& is not a boolean partition-wide restriction", E1
);
5599 if Restriction_Active
(R
) then
5600 Set_Boolean_Result
(N
, True);
5602 Check_Restriction
(R
, N
);
5603 Set_Boolean_Result
(N
, False);
5607 end Restriction_Set
;
5613 when Attribute_Round
=>
5615 Check_Decimal_Fixed_Point_Type
;
5616 Set_Etype
(N
, P_Base_Type
);
5618 -- Because the context is universal_real (3.5.10(12)) it is a
5619 -- legal context for a universal fixed expression. This is the
5620 -- only attribute whose functional description involves U_R.
5622 if Etype
(E1
) = Universal_Fixed
then
5624 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5625 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5626 Expression
=> Relocate_Node
(E1
));
5634 Resolve
(E1
, Any_Real
);
5640 when Attribute_Rounding
=>
5641 Check_Floating_Point_Type_1
;
5642 Set_Etype
(N
, P_Base_Type
);
5643 Resolve
(E1
, P_Base_Type
);
5649 when Attribute_Safe_Emax
=>
5650 Check_Floating_Point_Type_0
;
5651 Set_Etype
(N
, Universal_Integer
);
5657 when Attribute_Safe_First
=>
5658 Check_Floating_Point_Type_0
;
5659 Set_Etype
(N
, Universal_Real
);
5665 when Attribute_Safe_Large
=>
5668 Set_Etype
(N
, Universal_Real
);
5674 when Attribute_Safe_Last
=>
5675 Check_Floating_Point_Type_0
;
5676 Set_Etype
(N
, Universal_Real
);
5682 when Attribute_Safe_Small
=>
5685 Set_Etype
(N
, Universal_Real
);
5687 --------------------------
5688 -- Scalar_Storage_Order --
5689 --------------------------
5691 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5692 Ent
: Entity_Id
:= Empty
;
5698 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5700 -- In GNAT mode, the attribute applies to generic types as well
5701 -- as composite types, and for non-composite types always returns
5702 -- the default bit order for the target.
5704 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5705 and then not In_Instance
5708 ("prefix of % attribute must be record or array type");
5710 elsif not Is_Generic_Type
(P_Type
) then
5711 if Bytes_Big_Endian
then
5712 Ent
:= RTE
(RE_High_Order_First
);
5714 Ent
:= RTE
(RE_Low_Order_First
);
5718 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5719 Ent
:= RTE
(RE_High_Order_First
);
5722 Ent
:= RTE
(RE_Low_Order_First
);
5725 if Present
(Ent
) then
5726 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5729 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5732 -- Reset incorrect indication of staticness
5734 Set_Is_Static_Expression
(N
, False);
5735 end Scalar_Storage_Order
;
5741 when Attribute_Scale
=>
5743 Check_Decimal_Fixed_Point_Type
;
5744 Set_Etype
(N
, Universal_Integer
);
5750 when Attribute_Scaling
=>
5751 Check_Floating_Point_Type_2
;
5752 Set_Etype
(N
, P_Base_Type
);
5753 Resolve
(E1
, P_Base_Type
);
5759 when Attribute_Signed_Zeros
=>
5760 Check_Floating_Point_Type_0
;
5761 Set_Etype
(N
, Standard_Boolean
);
5768 | Attribute_VADS_Size
5772 -- If prefix is parameterless function call, rewrite and resolve
5775 if Is_Entity_Name
(P
)
5776 and then Ekind
(Entity
(P
)) = E_Function
5780 -- Similar processing for a protected function call
5782 elsif Nkind
(P
) = N_Selected_Component
5783 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5788 if Is_Object_Reference
(P
) then
5789 Check_Object_Reference
(P
);
5791 elsif Is_Entity_Name
(P
)
5792 and then (Is_Type
(Entity
(P
))
5793 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5797 elsif Nkind
(P
) = N_Type_Conversion
5798 and then not Comes_From_Source
(P
)
5802 -- Some other compilers allow dubious use of X'???'Size
5804 elsif Relaxed_RM_Semantics
5805 and then Nkind
(P
) = N_Attribute_Reference
5810 Error_Attr_P
("invalid prefix for % attribute");
5813 Check_Not_Incomplete_Type
;
5815 Set_Etype
(N
, Universal_Integer
);
5817 -- If we are processing pragmas Compile_Time_Warning and Compile_
5818 -- Time_Errors after the back end has been called and this occurrence
5819 -- of 'Size is known at compile time then it is safe to perform this
5820 -- evaluation. Needed to perform the static evaluation of the full
5821 -- boolean expression of these pragmas.
5823 if In_Compile_Time_Warning_Or_Error
5824 and then Is_Entity_Name
(P
)
5825 and then (Is_Type
(Entity
(P
))
5826 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5827 and then Size_Known_At_Compile_Time
(Entity
(P
))
5829 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Esize
(Entity
(P
))));
5837 when Attribute_Small
=>
5840 Set_Etype
(N
, Universal_Real
);
5846 when Attribute_Storage_Pool
5847 | Attribute_Simple_Storage_Pool
5851 if Is_Access_Type
(P_Type
) then
5852 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5854 ("cannot use % attribute for access-to-subprogram type");
5857 -- Set appropriate entity
5859 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5860 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5862 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5865 if Attr_Id
= Attribute_Storage_Pool
then
5866 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5867 Name_Simple_Storage_Pool_Type
))
5869 Error_Msg_Name_1
:= Aname
;
5870 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5872 ("cannot use % attribute for type with simple storage "
5874 Error_Msg_N
("\Program_Error [<<", N
);
5877 (N
, Make_Raise_Program_Error
5878 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5881 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5883 -- In the Simple_Storage_Pool case, verify that the pool entity is
5884 -- actually of a simple storage pool type, and set the attribute's
5885 -- type to the pool object's type.
5888 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5889 Name_Simple_Storage_Pool_Type
))
5892 ("cannot use % attribute for type without simple " &
5896 Set_Etype
(N
, Etype
(Entity
(N
)));
5899 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5900 -- Storage_Pool since this attribute is not defined for such
5901 -- types (RM E.2.3(22)).
5903 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5906 Error_Attr_P
("prefix of % attribute must be access type");
5913 when Attribute_Storage_Size
=>
5916 if Is_Task_Type
(P_Type
) then
5917 Set_Etype
(N
, Universal_Integer
);
5919 -- Use with tasks is an obsolescent feature
5921 Check_Restriction
(No_Obsolescent_Features
, P
);
5923 elsif Is_Access_Type
(P_Type
) then
5924 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5926 ("cannot use % attribute for access-to-subprogram type");
5929 if Is_Entity_Name
(P
)
5930 and then Is_Type
(Entity
(P
))
5933 Set_Etype
(N
, Universal_Integer
);
5935 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5936 -- Storage_Size since this attribute is not defined for
5937 -- such types (RM E.2.3(22)).
5939 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5941 -- The prefix is allowed to be an implicit dereference of an
5942 -- access value designating a task.
5946 Set_Etype
(N
, Universal_Integer
);
5950 Error_Attr_P
("prefix of % attribute must be access or task type");
5957 when Attribute_Storage_Unit
=>
5958 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5964 when Attribute_Stream_Size
=>
5968 if Is_Entity_Name
(P
)
5969 and then Is_Elementary_Type
(Entity
(P
))
5971 Set_Etype
(N
, Universal_Integer
);
5973 Error_Attr_P
("invalid prefix for % attribute");
5980 when Attribute_Stub_Type
=>
5984 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5986 -- For a real RACW [sub]type, use corresponding stub type
5988 if not Is_Generic_Type
(P_Type
) then
5991 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5993 -- For a generic type (that has been marked as an RACW using the
5994 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5995 -- type. Note that if the actual is not a remote access type, the
5996 -- instantiation will fail.
5999 -- Note: we go to the underlying type here because the view
6000 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
6004 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
6009 ("prefix of% attribute must be remote access-to-class-wide");
6016 when Attribute_Succ
=>
6020 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
6021 Error_Msg_Name_1
:= Aname
;
6022 Error_Msg_Name_2
:= Chars
(P_Type
);
6023 Check_SPARK_05_Restriction
6024 ("attribute% is not allowed for type%", P
);
6027 Resolve
(E1
, P_Base_Type
);
6028 Set_Etype
(N
, P_Base_Type
);
6030 -- Since Pred works on the base type, we normally do no check for the
6031 -- floating-point case, since the base type is unconstrained. But we
6032 -- make an exception in Check_Float_Overflow mode.
6034 if Is_Floating_Point_Type
(P_Type
) then
6035 if not Range_Checks_Suppressed
(P_Base_Type
) then
6036 Set_Do_Range_Check
(E1
);
6039 -- If not modular type, test for overflow check required
6042 if not Is_Modular_Integer_Type
(P_Type
)
6043 and then not Range_Checks_Suppressed
(P_Base_Type
)
6045 Enable_Range_Check
(E1
);
6049 --------------------------------
6050 -- System_Allocator_Alignment --
6051 --------------------------------
6053 when Attribute_System_Allocator_Alignment
=>
6054 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
6060 when Attribute_Tag
=>
6064 if not Is_Tagged_Type
(P_Type
) then
6065 Error_Attr_P
("prefix of % attribute must be tagged");
6067 -- Next test does not apply to generated code why not, and what does
6068 -- the illegal reference mean???
6070 elsif Is_Object_Reference
(P
)
6071 and then not Is_Class_Wide_Type
(P_Type
)
6072 and then Comes_From_Source
(N
)
6075 ("% attribute can only be applied to objects " &
6076 "of class - wide type");
6079 -- The prefix cannot be an incomplete type. However, references to
6080 -- 'Tag can be generated when expanding interface conversions, and
6083 if Comes_From_Source
(N
) then
6084 Check_Not_Incomplete_Type
;
6087 -- Set appropriate type
6089 Set_Etype
(N
, RTE
(RE_Tag
));
6095 when Attribute_Target_Name
=> Target_Name
: declare
6096 TN
: constant String := Sdefault
.Target_Name
.all;
6100 Check_Standard_Prefix
;
6104 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6109 Make_String_Literal
(Loc
,
6110 Strval
=> TN
(TN
'First .. TL
)));
6111 Analyze_And_Resolve
(N
, Standard_String
);
6112 Set_Is_Static_Expression
(N
, True);
6119 when Attribute_Terminated
=>
6121 Set_Etype
(N
, Standard_Boolean
);
6128 when Attribute_To_Address
=> To_Address
: declare
6134 Check_System_Prefix
;
6136 Generate_Reference
(RTE
(RE_Address
), P
);
6137 Analyze_And_Resolve
(E1
, Any_Integer
);
6138 Set_Etype
(N
, RTE
(RE_Address
));
6140 if Is_Static_Expression
(E1
) then
6141 Set_Is_Static_Expression
(N
, True);
6144 -- OK static expression case, check range and set appropriate type
6146 if Is_OK_Static_Expression
(E1
) then
6147 Val
:= Expr_Value
(E1
);
6149 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
6151 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
6153 Error_Attr
("address value out of range for % attribute", E1
);
6156 -- In most cases the expression is a numeric literal or some other
6157 -- address expression, but if it is a declared constant it may be
6158 -- of a compatible type that must be left on the node.
6160 if Is_Entity_Name
(E1
) then
6163 -- Set type to universal integer if negative
6166 Set_Etype
(E1
, Universal_Integer
);
6168 -- Otherwise set type to Unsigned_64 to accommodate max values
6171 Set_Etype
(E1
, Standard_Unsigned_64
);
6175 Set_Is_Static_Expression
(N
, True);
6182 when Attribute_To_Any
=>
6184 Check_PolyORB_Attribute
;
6185 Set_Etype
(N
, RTE
(RE_Any
));
6191 when Attribute_Truncation
=>
6192 Check_Floating_Point_Type_1
;
6193 Resolve
(E1
, P_Base_Type
);
6194 Set_Etype
(N
, P_Base_Type
);
6200 when Attribute_Type_Class
=>
6203 Check_Not_Incomplete_Type
;
6204 Set_Etype
(N
, RTE
(RE_Type_Class
));
6210 when Attribute_TypeCode
=>
6212 Check_PolyORB_Attribute
;
6213 Set_Etype
(N
, RTE
(RE_TypeCode
));
6219 when Attribute_Type_Key
=> Type_Key
: declare
6220 Full_Name
: constant String_Id
:=
6221 Fully_Qualified_Name_String
(Entity
(P
));
6224 -- The computed signature for the type
6227 -- To simplify the handling of mutually recursive types, follow a
6228 -- single dereference link in a composite type.
6230 procedure Compute_Type_Key
(T
: Entity_Id
);
6231 -- Create a CRC integer from the declaration of the type. For a
6232 -- composite type, fold in the representation of its components in
6233 -- recursive fashion. We use directly the source representation of
6234 -- the types involved.
6236 ----------------------
6237 -- Compute_Type_Key --
6238 ----------------------
6240 procedure Compute_Type_Key
(T
: Entity_Id
) is
6241 Buffer
: Source_Buffer_Ptr
;
6245 SFI
: Source_File_Index
;
6247 procedure Process_One_Declaration
;
6248 -- Update CRC with the characters of one type declaration, or a
6249 -- representation pragma that applies to the type.
6251 -----------------------------
6252 -- Process_One_Declaration --
6253 -----------------------------
6255 procedure Process_One_Declaration
is
6257 -- Scan type declaration, skipping blanks
6259 for Ptr
in P_Min
.. P_Max
loop
6260 if Buffer
(Ptr
) /= ' ' then
6261 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6264 end Process_One_Declaration
;
6266 -- Start of processing for Compute_Type_Key
6269 if Is_Itype
(T
) then
6273 -- If the type is declared in Standard, there is no source, so
6274 -- just use its name.
6276 if Scope
(T
) = Standard_Standard
then
6278 Name
: constant String := Get_Name_String
(Chars
(T
));
6280 for J
in Name
'Range loop
6281 System
.CRC32
.Update
(CRC
, Name
(J
));
6288 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6289 SFI
:= Get_Source_File_Index
(P_Min
);
6290 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6291 Buffer
:= Source_Text
(SFI
);
6293 Process_One_Declaration
;
6295 -- Recurse on relevant component types
6297 if Is_Array_Type
(T
) then
6298 Compute_Type_Key
(Component_Type
(T
));
6300 elsif Is_Access_Type
(T
) then
6303 Compute_Type_Key
(Designated_Type
(T
));
6306 elsif Is_Derived_Type
(T
) then
6307 Compute_Type_Key
(Etype
(T
));
6309 elsif Is_Record_Type
(T
) then
6313 Comp
:= First_Component
(T
);
6314 while Present
(Comp
) loop
6315 Compute_Type_Key
(Etype
(Comp
));
6316 Next_Component
(Comp
);
6321 if Is_First_Subtype
(T
) then
6323 -- Fold in representation aspects for the type, which appear in
6324 -- the same source buffer. If the representation aspects are in
6325 -- a different source file, then skip them; they apply to some
6326 -- other type, perhaps one we're derived from.
6328 Rep
:= First_Rep_Item
(T
);
6330 while Present
(Rep
) loop
6331 if Comes_From_Source
(Rep
) then
6332 Sloc_Range
(Rep
, P_Min
, P_Max
);
6334 if SFI
= Get_Source_File_Index
(P_Min
) then
6335 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6336 Process_One_Declaration
;
6340 Rep
:= Next_Rep_Item
(Rep
);
6343 end Compute_Type_Key
;
6345 -- Start of processing for Type_Key
6354 -- Copy all characters in Full_Name but the trailing NUL
6356 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6357 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6360 -- Compute CRC and convert it to string one character at a time, so
6361 -- as not to use Image within the compiler.
6364 Compute_Type_Key
(Entity
(P
));
6366 if not Is_Frozen
(Entity
(P
)) then
6367 Error_Msg_N
("premature usage of Type_Key?", N
);
6371 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
6375 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
6376 Analyze_And_Resolve
(N
, Standard_String
);
6379 -----------------------
6380 -- Unbiased_Rounding --
6381 -----------------------
6383 when Attribute_Unbiased_Rounding
=>
6384 Check_Floating_Point_Type_1
;
6385 Set_Etype
(N
, P_Base_Type
);
6386 Resolve
(E1
, P_Base_Type
);
6388 ----------------------
6389 -- Unchecked_Access --
6390 ----------------------
6392 when Attribute_Unchecked_Access
=>
6393 if Comes_From_Source
(N
) then
6394 Check_Restriction
(No_Unchecked_Access
, N
);
6397 Analyze_Access_Attribute
;
6398 Check_Not_Incomplete_Type
;
6400 -------------------------
6401 -- Unconstrained_Array --
6402 -------------------------
6404 when Attribute_Unconstrained_Array
=>
6407 Check_Not_Incomplete_Type
;
6408 Set_Etype
(N
, Standard_Boolean
);
6409 Set_Is_Static_Expression
(N
, True);
6411 ------------------------------
6412 -- Universal_Literal_String --
6413 ------------------------------
6415 -- This is a GNAT specific attribute whose prefix must be a named
6416 -- number where the expression is either a single numeric literal,
6417 -- or a numeric literal immediately preceded by a minus sign. The
6418 -- result is equivalent to a string literal containing the text of
6419 -- the literal as it appeared in the source program with a possible
6420 -- leading minus sign.
6422 when Attribute_Universal_Literal_String
=>
6425 if not Is_Entity_Name
(P
)
6426 or else Ekind
(Entity
(P
)) not in Named_Kind
6428 Error_Attr_P
("prefix for % attribute must be named number");
6435 Src
: Source_Buffer_Ptr
;
6438 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6440 if Nkind
(Expr
) = N_Op_Minus
then
6442 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6447 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6449 ("named number for % attribute must be simple literal", N
);
6452 -- Build string literal corresponding to source literal text
6457 Store_String_Char
(Get_Char_Code
('-'));
6461 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6463 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6464 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6468 -- Now we rewrite the attribute with the string literal
6471 Make_String_Literal
(Loc
, End_String
));
6473 Set_Is_Static_Expression
(N
, True);
6477 -------------------------
6478 -- Unrestricted_Access --
6479 -------------------------
6481 -- This is a GNAT specific attribute which is like Access except that
6482 -- all scope checks and checks for aliased views are omitted. It is
6483 -- documented as being equivalent to the use of the Address attribute
6484 -- followed by an unchecked conversion to the target access type.
6486 when Attribute_Unrestricted_Access
=>
6488 -- If from source, deal with relevant restrictions
6490 if Comes_From_Source
(N
) then
6491 Check_Restriction
(No_Unchecked_Access
, N
);
6493 if Nkind
(P
) in N_Has_Entity
6494 and then Present
(Entity
(P
))
6495 and then Is_Object
(Entity
(P
))
6497 Check_Restriction
(No_Implicit_Aliasing
, N
);
6501 if Is_Entity_Name
(P
) then
6502 Set_Address_Taken
(Entity
(P
));
6505 -- It might seem reasonable to call Address_Checks here to apply the
6506 -- same set of semantic checks that we enforce for 'Address (after
6507 -- all we document Unrestricted_Access as being equivalent to the
6508 -- use of Address followed by an Unchecked_Conversion). However, if
6509 -- we do enable these checks, we get multiple failures in both the
6510 -- compiler run-time and in our regression test suite, so we leave
6511 -- out these checks for now. To be investigated further some time???
6515 -- Now complete analysis using common access processing
6517 Analyze_Access_Attribute
;
6523 when Attribute_Update
=> Update
: declare
6524 Common_Typ
: Entity_Id
;
6525 -- The common type of a multiple component update for a record
6527 Comps
: Elist_Id
:= No_Elist
;
6528 -- A list used in the resolution of a record update. It contains the
6529 -- entities of all record components processed so far.
6531 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6532 -- Analyze and resolve array_component_association Assoc against the
6533 -- index of array type P_Type.
6535 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6536 -- Analyze and resolve record_component_association Comp against
6537 -- record type P_Type.
6539 ------------------------------------
6540 -- Analyze_Array_Component_Update --
6541 ------------------------------------
6543 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6547 Index_Typ
: Entity_Id
;
6551 -- The current association contains a sequence of indexes denoting
6552 -- an element of a multidimensional array:
6554 -- (Index_1, ..., Index_N)
6556 -- Examine each individual index and resolve it against the proper
6557 -- index type of the array.
6559 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6560 Expr
:= First
(Choices
(Assoc
));
6561 while Present
(Expr
) loop
6563 -- The use of others is illegal (SPARK RM 4.4.1(12))
6565 if Nkind
(Expr
) = N_Others_Choice
then
6567 ("others choice not allowed in attribute %", Expr
);
6569 -- Otherwise analyze and resolve all indexes
6572 Index
:= First
(Expressions
(Expr
));
6573 Index_Typ
:= First_Index
(P_Type
);
6574 while Present
(Index
) and then Present
(Index_Typ
) loop
6575 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6577 Next_Index
(Index_Typ
);
6580 -- Detect a case where the association either lacks an
6581 -- index or contains an extra index.
6583 if Present
(Index
) or else Present
(Index_Typ
) then
6585 ("dimension mismatch in index list", Assoc
);
6592 -- The current association denotes either a single component or a
6593 -- range of components of a one dimensional array:
6597 -- Resolve the index or its high and low bounds (if range) against
6598 -- the proper index type of the array.
6601 Index
:= First
(Choices
(Assoc
));
6602 Index_Typ
:= First_Index
(P_Type
);
6604 if Present
(Next_Index
(Index_Typ
)) then
6605 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6608 while Present
(Index
) loop
6610 -- The use of others is illegal (SPARK RM 4.4.1(12))
6612 if Nkind
(Index
) = N_Others_Choice
then
6614 ("others choice not allowed in attribute %", Index
);
6616 -- The index denotes a range of elements
6618 elsif Nkind
(Index
) = N_Range
then
6619 Low
:= Low_Bound
(Index
);
6620 High
:= High_Bound
(Index
);
6622 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6623 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6625 -- Add a range check to ensure that the bounds of the
6626 -- range are within the index type when this cannot be
6627 -- determined statically.
6629 if not Is_OK_Static_Expression
(Low
) then
6630 Set_Do_Range_Check
(Low
);
6633 if not Is_OK_Static_Expression
(High
) then
6634 Set_Do_Range_Check
(High
);
6637 -- Otherwise the index denotes a single element
6640 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6642 -- Add a range check to ensure that the index is within
6643 -- the index type when it is not possible to determine
6646 if not Is_OK_Static_Expression
(Index
) then
6647 Set_Do_Range_Check
(Index
);
6654 end Analyze_Array_Component_Update
;
6656 -------------------------------------
6657 -- Analyze_Record_Component_Update --
6658 -------------------------------------
6660 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6661 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6662 Base_Typ
: Entity_Id
;
6663 Comp_Or_Discr
: Entity_Id
;
6666 -- Find the discriminant or component whose name corresponds to
6667 -- Comp. A simple character comparison is sufficient because all
6668 -- visible names within a record type are unique.
6670 Comp_Or_Discr
:= First_Entity
(P_Type
);
6671 while Present
(Comp_Or_Discr
) loop
6672 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6674 -- Decorate the component reference by setting its entity
6675 -- and type for resolution purposes.
6677 Set_Entity
(Comp
, Comp_Or_Discr
);
6678 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6682 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6685 -- Diagnose an illegal reference
6687 if Present
(Comp_Or_Discr
) then
6688 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6690 ("attribute % may not modify record discriminants", Comp
);
6692 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6693 if Contains
(Comps
, Comp_Or_Discr
) then
6694 Error_Msg_N
("component & already updated", Comp
);
6696 -- Mark this component as processed
6699 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6703 -- The update aggregate mentions an entity that does not belong to
6707 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6710 -- Verify the consistency of types when the current component is
6711 -- part of a miltiple component update.
6713 -- Comp_1, ..., Comp_N => <value>
6715 if Present
(Etype
(Comp
)) then
6716 Base_Typ
:= Base_Type
(Etype
(Comp
));
6718 -- Save the type of the first component reference as the
6719 -- remaning references (if any) must resolve to this type.
6721 if No
(Common_Typ
) then
6722 Common_Typ
:= Base_Typ
;
6724 elsif Base_Typ
/= Common_Typ
then
6726 ("components in choice list must have same type", Comp
);
6729 end Analyze_Record_Component_Update
;
6736 -- Start of processing for Update
6741 if not Is_Object_Reference
(P
) then
6742 Error_Attr_P
("prefix of attribute % must denote an object");
6744 elsif not Is_Array_Type
(P_Type
)
6745 and then not Is_Record_Type
(P_Type
)
6747 Error_Attr_P
("prefix of attribute % must be a record or array");
6749 elsif Is_Limited_View
(P_Type
) then
6750 Error_Attr
("prefix of attribute % cannot be limited", N
);
6752 elsif Nkind
(E1
) /= N_Aggregate
then
6753 Error_Attr
("attribute % requires component association list", N
);
6756 -- Inspect the update aggregate, looking at all the associations and
6757 -- choices. Perform the following checks:
6759 -- 1) Legality of "others" in all cases
6760 -- 2) Legality of <>
6761 -- 3) Component legality for arrays
6762 -- 4) Component legality for records
6764 -- The remaining checks are performed on the expanded attribute
6766 Assoc
:= First
(Component_Associations
(E1
));
6767 while Present
(Assoc
) loop
6769 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6771 if Box_Present
(Assoc
) then
6773 ("default initialization not allowed in attribute %", Assoc
);
6775 -- Otherwise process the association
6778 Analyze
(Expression
(Assoc
));
6780 if Is_Array_Type
(P_Type
) then
6781 Analyze_Array_Component_Update
(Assoc
);
6783 elsif Is_Record_Type
(P_Type
) then
6785 -- Reset the common type used in a multiple component update
6786 -- as we are processing the contents of a new association.
6788 Common_Typ
:= Empty
;
6790 Comp
:= First
(Choices
(Assoc
));
6791 while Present
(Comp
) loop
6792 if Nkind
(Comp
) = N_Identifier
then
6793 Analyze_Record_Component_Update
(Comp
);
6795 -- The use of others is illegal (SPARK RM 4.4.1(5))
6797 elsif Nkind
(Comp
) = N_Others_Choice
then
6799 ("others choice not allowed in attribute %", Comp
);
6801 -- The name of a record component cannot appear in any
6806 ("name should be identifier or OTHERS", Comp
);
6817 -- The type of attribute 'Update is that of the prefix
6819 Set_Etype
(N
, P_Type
);
6821 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
6828 when Attribute_Val
=>
6830 Check_Discrete_Type
;
6832 if Is_Boolean_Type
(P_Type
) then
6833 Error_Msg_Name_1
:= Aname
;
6834 Error_Msg_Name_2
:= Chars
(P_Type
);
6835 Check_SPARK_05_Restriction
6836 ("attribute% is not allowed for type%", P
);
6839 -- Note, we need a range check in general, but we wait for the
6840 -- Resolve call to do this, since we want to let Eval_Attribute
6841 -- have a chance to find an static illegality first.
6843 Resolve
(E1
, Any_Integer
);
6844 Set_Etype
(N
, P_Base_Type
);
6850 when Attribute_Valid
=>
6853 -- Ignore check for object if we have a 'Valid reference generated
6854 -- by the expanded code, since in some cases valid checks can occur
6855 -- on items that are names, but are not objects (e.g. attributes).
6857 if Comes_From_Source
(N
) then
6858 Check_Object_Reference
(P
);
6861 if not Is_Scalar_Type
(P_Type
) then
6862 Error_Attr_P
("object for % attribute must be of scalar type");
6865 -- If the attribute appears within the subtype's own predicate
6866 -- function, then issue a warning that this will cause infinite
6870 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6873 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6875 ("attribute Valid requires a predicate check??", N
);
6876 Error_Msg_N
("\and will result in infinite recursion??", N
);
6880 Set_Etype
(N
, Standard_Boolean
);
6886 when Attribute_Valid_Scalars
=>
6888 Check_Object_Reference
(P
);
6889 Set_Etype
(N
, Standard_Boolean
);
6891 -- Following checks are only for source types
6893 if Comes_From_Source
(N
) then
6894 if not Scalar_Part_Present
(P_Type
) then
6896 ("??attribute % always True, no scalars to check");
6899 -- Not allowed for unchecked union type
6901 if Has_Unchecked_Union
(P_Type
) then
6903 ("attribute % not allowed for Unchecked_Union type");
6911 when Attribute_Value
=>
6912 Check_SPARK_05_Restriction_On_Attribute
;
6916 -- Case of enumeration type
6918 -- When an enumeration type appears in an attribute reference, all
6919 -- literals of the type are marked as referenced. This must only be
6920 -- done if the attribute reference appears in the current source.
6921 -- Otherwise the information on references may differ between a
6922 -- normal compilation and one that performs inlining.
6924 if Is_Enumeration_Type
(P_Type
)
6925 and then In_Extended_Main_Code_Unit
(N
)
6927 Check_Restriction
(No_Enumeration_Maps
, N
);
6929 -- Mark all enumeration literals as referenced, since the use of
6930 -- the Value attribute can implicitly reference any of the
6931 -- literals of the enumeration base type.
6934 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6936 while Present
(Ent
) loop
6937 Set_Referenced
(Ent
);
6943 -- Set Etype before resolving expression because expansion of
6944 -- expression may require enclosing type. Note that the type
6945 -- returned by 'Value is the base type of the prefix type.
6947 Set_Etype
(N
, P_Base_Type
);
6948 Validate_Non_Static_Attribute_Function_Call
;
6950 -- Check restriction No_Fixed_IO
6952 if Restriction_Check_Required
(No_Fixed_IO
)
6953 and then Is_Fixed_Point_Type
(P_Type
)
6955 Check_Restriction
(No_Fixed_IO
, P
);
6962 when Attribute_Value_Size
=>
6965 Check_Not_Incomplete_Type
;
6966 Set_Etype
(N
, Universal_Integer
);
6972 when Attribute_Version
=>
6975 Set_Etype
(N
, RTE
(RE_Version_String
));
6981 when Attribute_Wchar_T_Size
=>
6982 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6988 when Attribute_Wide_Image
=>
6989 Analyze_Image_Attribute
(Standard_Wide_String
);
6991 ---------------------
6992 -- Wide_Wide_Image --
6993 ---------------------
6995 when Attribute_Wide_Wide_Image
=>
6996 Analyze_Image_Attribute
(Standard_Wide_Wide_String
);
7002 when Attribute_Wide_Value
=>
7003 Check_SPARK_05_Restriction_On_Attribute
;
7007 -- Set Etype before resolving expression because expansion
7008 -- of expression may require enclosing type.
7010 Set_Etype
(N
, P_Type
);
7011 Validate_Non_Static_Attribute_Function_Call
;
7013 -- Check restriction No_Fixed_IO
7015 if Restriction_Check_Required
(No_Fixed_IO
)
7016 and then Is_Fixed_Point_Type
(P_Type
)
7018 Check_Restriction
(No_Fixed_IO
, P
);
7021 ---------------------
7022 -- Wide_Wide_Value --
7023 ---------------------
7025 when Attribute_Wide_Wide_Value
=>
7029 -- Set Etype before resolving expression because expansion
7030 -- of expression may require enclosing type.
7032 Set_Etype
(N
, P_Type
);
7033 Validate_Non_Static_Attribute_Function_Call
;
7035 -- Check restriction No_Fixed_IO
7037 if Restriction_Check_Required
(No_Fixed_IO
)
7038 and then Is_Fixed_Point_Type
(P_Type
)
7040 Check_Restriction
(No_Fixed_IO
, P
);
7043 ---------------------
7044 -- Wide_Wide_Width --
7045 ---------------------
7047 when Attribute_Wide_Wide_Width
=>
7050 Set_Etype
(N
, Universal_Integer
);
7056 when Attribute_Wide_Width
=>
7057 Check_SPARK_05_Restriction_On_Attribute
;
7060 Set_Etype
(N
, Universal_Integer
);
7066 when Attribute_Width
=>
7067 Check_SPARK_05_Restriction_On_Attribute
;
7070 Set_Etype
(N
, Universal_Integer
);
7076 when Attribute_Word_Size
=>
7077 Standard_Attribute
(System_Word_Size
);
7083 when Attribute_Write
=>
7085 Check_Stream_Attribute
(TSS_Stream_Write
);
7086 Set_Etype
(N
, Standard_Void_Type
);
7087 Resolve
(N
, Standard_Void_Type
);
7091 -- In SPARK certain attributes (see below) depend on Tasking_State.
7092 -- Ensure that the entity is available for gnat2why by loading it.
7093 -- See SPARK RM 9(18) for the relevant rule.
7095 if GNATprove_Mode
then
7101 when Attribute_Callable
7104 | Attribute_Terminated
7106 Unused
:= RTE
(RE_Tasking_State
);
7114 -- All errors raise Bad_Attribute, so that we get out before any further
7115 -- damage occurs when an error is detected (for example, if we check for
7116 -- one attribute expression, and the check succeeds, we want to be able
7117 -- to proceed securely assuming that an expression is in fact present.
7119 -- Note: we set the attribute analyzed in this case to prevent any
7120 -- attempt at reanalysis which could generate spurious error msgs.
7123 when Bad_Attribute
=>
7125 Set_Etype
(N
, Any_Type
);
7127 end Analyze_Attribute
;
7129 --------------------
7130 -- Eval_Attribute --
7131 --------------------
7133 procedure Eval_Attribute
(N
: Node_Id
) is
7134 Loc
: constant Source_Ptr
:= Sloc
(N
);
7135 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7136 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7137 P
: constant Node_Id
:= Prefix
(N
);
7139 C_Type
: constant Entity_Id
:= Etype
(N
);
7140 -- The type imposed by the context
7143 -- First expression, or Empty if none
7146 -- Second expression, or Empty if none
7148 P_Entity
: Entity_Id
;
7149 -- Entity denoted by prefix
7152 -- The type of the prefix
7154 P_Base_Type
: Entity_Id
;
7155 -- The base type of the prefix type
7157 P_Root_Type
: Entity_Id
;
7158 -- The root type of the prefix type
7161 -- True if the result is Static. This is set by the general processing
7162 -- to true if the prefix is static, and all expressions are static. It
7163 -- can be reset as processing continues for particular attributes. This
7164 -- flag can still be True if the reference raises a constraint error.
7165 -- Is_Static_Expression (N) is set to follow this value as it is set
7166 -- and we could always reference this, but it is convenient to have a
7167 -- simple short name to use, since it is frequently referenced.
7169 Lo_Bound
, Hi_Bound
: Node_Id
;
7170 -- Expressions for low and high bounds of type or array index referenced
7171 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7174 -- Constraint error node used if we have an attribute reference has
7175 -- an argument that raises a constraint error. In this case we replace
7176 -- the attribute with a raise constraint_error node. This is important
7177 -- processing, since otherwise gigi might see an attribute which it is
7178 -- unprepared to deal with.
7180 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7181 -- If Bound is a reference to a discriminant of a task or protected type
7182 -- occurring within the object's body, rewrite attribute reference into
7183 -- a reference to the corresponding discriminal. Use for the expansion
7184 -- of checks against bounds of entry family index subtypes.
7186 procedure Check_Expressions
;
7187 -- In case where the attribute is not foldable, the expressions, if
7188 -- any, of the attribute, are in a non-static context. This procedure
7189 -- performs the required additional checks.
7191 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7192 -- Determines if the given type has compile time known bounds. Note
7193 -- that we enter the case statement even in cases where the prefix
7194 -- type does NOT have known bounds, so it is important to guard any
7195 -- attempt to evaluate both bounds with a call to this function.
7197 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7198 -- This procedure is called when the attribute N has a non-static
7199 -- but compile time known value given by Val. It includes the
7200 -- necessary checks for out of range values.
7202 function Fore_Value
return Nat
;
7203 -- Computes the Fore value for the current attribute prefix, which is
7204 -- known to be a static fixed-point type. Used by Fore and Width.
7206 function Mantissa
return Uint
;
7207 -- Returns the Mantissa value for the prefix type
7209 procedure Set_Bounds
;
7210 -- Used for First, Last and Length attributes applied to an array or
7211 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7212 -- and high bound expressions for the index referenced by the attribute
7213 -- designator (i.e. the first index if no expression is present, and the
7214 -- N'th index if the value N is present as an expression). Also used for
7215 -- First and Last of scalar types and for First_Valid and Last_Valid.
7216 -- Static is reset to False if the type or index type is not statically
7219 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
7220 -- Verify that the prefix of a potentially static array attribute
7221 -- satisfies the conditions of 4.9 (14).
7223 -----------------------------------
7224 -- Check_Concurrent_Discriminant --
7225 -----------------------------------
7227 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7229 -- The concurrent (task or protected) type
7232 if Nkind
(Bound
) = N_Identifier
7233 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7234 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7236 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7238 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7240 -- Find discriminant of original concurrent type, and use
7241 -- its current discriminal, which is the renaming within
7242 -- the task/protected body.
7246 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7249 end Check_Concurrent_Discriminant
;
7251 -----------------------
7252 -- Check_Expressions --
7253 -----------------------
7255 procedure Check_Expressions
is
7259 while Present
(E
) loop
7260 Check_Non_Static_Context
(E
);
7263 end Check_Expressions
;
7265 ----------------------------------
7266 -- Compile_Time_Known_Attribute --
7267 ----------------------------------
7269 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7270 T
: constant Entity_Id
:= Etype
(N
);
7273 Fold_Uint
(N
, Val
, False);
7275 -- Check that result is in bounds of the type if it is static
7277 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7280 elsif Is_Out_Of_Range
(N
, T
) then
7281 Apply_Compile_Time_Constraint_Error
7282 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7284 elsif not Range_Checks_Suppressed
(T
) then
7285 Enable_Range_Check
(N
);
7288 Set_Do_Range_Check
(N
, False);
7290 end Compile_Time_Known_Attribute
;
7292 -------------------------------
7293 -- Compile_Time_Known_Bounds --
7294 -------------------------------
7296 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7299 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7301 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7302 end Compile_Time_Known_Bounds
;
7308 -- Note that the Fore calculation is based on the actual values
7309 -- of the bounds, and does not take into account possible rounding.
7311 function Fore_Value
return Nat
is
7312 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7313 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7314 Small
: constant Ureal
:= Small_Value
(P_Type
);
7315 Lo_Real
: constant Ureal
:= Lo
* Small
;
7316 Hi_Real
: constant Ureal
:= Hi
* Small
;
7321 -- Bounds are given in terms of small units, so first compute
7322 -- proper values as reals.
7324 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7327 -- Loop to compute proper value if more than one digit required
7329 while T
>= Ureal_10
loop
7341 -- Table of mantissa values accessed by function Computed using
7344 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7346 -- where D is T'Digits (RM83 3.5.7)
7348 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7390 function Mantissa
return Uint
is
7393 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7400 procedure Set_Bounds
is
7406 -- For a string literal subtype, we have to construct the bounds.
7407 -- Valid Ada code never applies attributes to string literals, but
7408 -- it is convenient to allow the expander to generate attribute
7409 -- references of this type (e.g. First and Last applied to a string
7412 -- Note that the whole point of the E_String_Literal_Subtype is to
7413 -- avoid this construction of bounds, but the cases in which we
7414 -- have to materialize them are rare enough that we don't worry.
7416 -- The low bound is simply the low bound of the base type. The
7417 -- high bound is computed from the length of the string and this
7420 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7421 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7422 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7425 Make_Integer_Literal
(Sloc
(P
),
7427 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7429 Set_Parent
(Hi_Bound
, P
);
7430 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7433 -- For non-array case, just get bounds of scalar type
7435 elsif Is_Scalar_Type
(P_Type
) then
7438 -- For a fixed-point type, we must freeze to get the attributes
7439 -- of the fixed-point type set now so we can reference them.
7441 if Is_Fixed_Point_Type
(P_Type
)
7442 and then not Is_Frozen
(Base_Type
(P_Type
))
7443 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7444 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7446 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7449 -- For array case, get type of proper index
7455 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7458 Indx
:= First_Index
(P_Type
);
7459 for J
in 1 .. Ndim
- 1 loop
7463 -- If no index type, get out (some other error occurred, and
7464 -- we don't have enough information to complete the job).
7472 Ityp
:= Etype
(Indx
);
7475 -- A discrete range in an index constraint is allowed to be a
7476 -- subtype indication. This is syntactically a pain, but should
7477 -- not propagate to the entity for the corresponding index subtype.
7478 -- After checking that the subtype indication is legal, the range
7479 -- of the subtype indication should be transfered to the entity.
7480 -- The attributes for the bounds should remain the simple retrievals
7481 -- that they are now.
7483 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7484 Hi_Bound
:= Type_High_Bound
(Ityp
);
7486 -- If subtype is non-static, result is definitely non-static
7488 if not Is_Static_Subtype
(Ityp
) then
7490 Set_Is_Static_Expression
(N
, False);
7492 -- Subtype is static, does it raise CE?
7494 elsif not Is_OK_Static_Subtype
(Ityp
) then
7495 Set_Raises_Constraint_Error
(N
);
7499 -------------------------------
7500 -- Statically_Denotes_Entity --
7501 -------------------------------
7503 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7507 if not Is_Entity_Name
(N
) then
7514 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7515 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7516 end Statically_Denotes_Entity
;
7518 -- Start of processing for Eval_Attribute
7521 -- Initialize result as non-static, will be reset if appropriate
7523 Set_Is_Static_Expression
(N
, False);
7526 -- Acquire first two expressions (at the moment, no attributes take more
7527 -- than two expressions in any case).
7529 if Present
(Expressions
(N
)) then
7530 E1
:= First
(Expressions
(N
));
7537 -- Special processing for Enabled attribute. This attribute has a very
7538 -- special prefix, and the easiest way to avoid lots of special checks
7539 -- to protect this special prefix from causing trouble is to deal with
7540 -- this attribute immediately and be done with it.
7542 if Id
= Attribute_Enabled
then
7544 -- We skip evaluation if the expander is not active. This is not just
7545 -- an optimization. It is of key importance that we not rewrite the
7546 -- attribute in a generic template, since we want to pick up the
7547 -- setting of the check in the instance, Testing Expander_Active
7548 -- might seem an easy way of doing this, but we need to account for
7549 -- ASIS needs, so check explicitly for a generic context.
7551 if not Inside_A_Generic
then
7553 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7558 if C
in Predefined_Check_Id
then
7559 R
:= Scope_Suppress
.Suppress
(C
);
7561 R
:= Is_Check_Suppressed
(Empty
, C
);
7565 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7568 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7575 -- Attribute 'Img applied to a static enumeration value is static, and
7576 -- we will do the folding right here (things get confused if we let this
7577 -- case go through the normal circuitry).
7579 if Attribute_Name
(N
) = Name_Img
7580 and then Is_Entity_Name
(P
)
7581 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
7582 and then Is_OK_Static_Expression
(P
)
7585 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
7590 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
7591 Set_Casing
(All_Upper_Case
);
7592 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
7595 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
7596 Analyze_And_Resolve
(N
, Standard_String
);
7597 Set_Is_Static_Expression
(N
, True);
7603 -- Special processing for cases where the prefix is an object. For this
7604 -- purpose, a string literal counts as an object (attributes of string
7605 -- literals can only appear in generated code).
7607 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7609 -- For Component_Size, the prefix is an array object, and we apply
7610 -- the attribute to the type of the object. This is allowed for both
7611 -- unconstrained and constrained arrays, since the bounds have no
7612 -- influence on the value of this attribute.
7614 if Id
= Attribute_Component_Size
then
7615 P_Entity
:= Etype
(P
);
7617 -- For Enum_Rep, evaluation depends on the nature of the prefix and
7618 -- the optional argument.
7620 elsif Id
= Attribute_Enum_Rep
then
7621 if Is_Entity_Name
(P
) then
7624 Enum_Expr
: Node_Id
;
7625 -- The enumeration-type expression of interest
7630 if Ekind_In
(Entity
(P
), E_Constant
,
7631 E_Enumeration_Literal
)
7635 -- Enum_Type'Enum_Rep (E1) case
7637 elsif Is_Enumeration_Type
(Entity
(P
)) then
7640 -- Otherwise the attribute must be expanded into a
7641 -- conversion and evaluated at run time.
7648 -- We can fold if the expression is an enumeration
7649 -- literal, or if it denotes a constant whose value
7650 -- is known at compile time.
7652 if Nkind
(Enum_Expr
) in N_Has_Entity
7653 and then (Ekind
(Entity
(Enum_Expr
)) =
7654 E_Enumeration_Literal
7656 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
7657 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
7658 N_Object_Declaration
7659 and then Compile_Time_Known_Value
7660 (Expression
(Parent
(Entity
(P
))))))
7662 P_Entity
:= Etype
(P
);
7669 -- Otherwise the attribute is illegal, do not attempt to perform
7670 -- any kind of folding.
7676 -- For First and Last, the prefix is an array object, and we apply
7677 -- the attribute to the type of the array, but we need a constrained
7678 -- type for this, so we use the actual subtype if available.
7680 elsif Id
= Attribute_First
or else
7681 Id
= Attribute_Last
or else
7682 Id
= Attribute_Length
7685 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7688 if Present
(AS
) and then Is_Constrained
(AS
) then
7691 -- If we have an unconstrained type we cannot fold
7699 -- For Size, give size of object if available, otherwise we
7700 -- cannot fold Size.
7702 elsif Id
= Attribute_Size
then
7703 if Is_Entity_Name
(P
)
7704 and then Known_Esize
(Entity
(P
))
7706 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7714 -- For Alignment, give size of object if available, otherwise we
7715 -- cannot fold Alignment.
7717 elsif Id
= Attribute_Alignment
then
7718 if Is_Entity_Name
(P
)
7719 and then Known_Alignment
(Entity
(P
))
7721 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7729 -- For Lock_Free, we apply the attribute to the type of the object.
7730 -- This is allowed since we have already verified that the type is a
7733 elsif Id
= Attribute_Lock_Free
then
7734 P_Entity
:= Etype
(P
);
7736 -- No other attributes for objects are folded
7743 -- Cases where P is not an object. Cannot do anything if P is not the
7744 -- name of an entity.
7746 elsif not Is_Entity_Name
(P
) then
7750 -- Otherwise get prefix entity
7753 P_Entity
:= Entity
(P
);
7756 -- If we are asked to evaluate an attribute where the prefix is a
7757 -- non-frozen generic actual type whose RM_Size is still set to zero,
7758 -- then abandon the effort.
7760 if Is_Type
(P_Entity
)
7761 and then (not Is_Frozen
(P_Entity
)
7762 and then Is_Generic_Actual_Type
(P_Entity
)
7763 and then RM_Size
(P_Entity
) = 0)
7765 -- However, the attribute Unconstrained_Array must be evaluated,
7766 -- since it is documented to be a static attribute (and can for
7767 -- example appear in a Compile_Time_Warning pragma). The frozen
7768 -- status of the type does not affect its evaluation.
7770 and then Id
/= Attribute_Unconstrained_Array
7775 -- At this stage P_Entity is the entity to which the attribute
7776 -- is to be applied. This is usually simply the entity of the
7777 -- prefix, except in some cases of attributes for objects, where
7778 -- as described above, we apply the attribute to the object type.
7780 -- Here is where we make sure that static attributes are properly
7781 -- marked as such. These are attributes whose prefix is a static
7782 -- scalar subtype, whose result is scalar, and whose arguments, if
7783 -- present, are static scalar expressions. Note that such references
7784 -- are static expressions even if they raise Constraint_Error.
7786 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7787 -- though evaluating it raises constraint error. This means that a
7788 -- declaration like:
7790 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7792 -- is legal, since here this expression appears in a statically
7793 -- unevaluated position, so it does not actually raise an exception.
7795 if Is_Scalar_Type
(P_Entity
)
7796 and then (not Is_Generic_Type
(P_Entity
))
7797 and then Is_Static_Subtype
(P_Entity
)
7798 and then Is_Scalar_Type
(Etype
(N
))
7801 or else (Is_Static_Expression
(E1
)
7802 and then Is_Scalar_Type
(Etype
(E1
))))
7805 or else (Is_Static_Expression
(E2
)
7806 and then Is_Scalar_Type
(Etype
(E1
))))
7809 Set_Is_Static_Expression
(N
, True);
7812 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7813 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7814 -- Note we allow non-static non-generic types at this stage as further
7817 if Is_Type
(P_Entity
)
7818 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7819 and then (not Is_Generic_Type
(P_Entity
))
7823 -- Second foldable possibility is an array object (RM 4.9(8))
7825 elsif Ekind_In
(P_Entity
, E_Variable
, E_Constant
)
7826 and then Is_Array_Type
(Etype
(P_Entity
))
7827 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7829 P_Type
:= Etype
(P_Entity
);
7831 -- If the entity is an array constant with an unconstrained nominal
7832 -- subtype then get the type from the initial value. If the value has
7833 -- been expanded into assignments, there is no expression and the
7834 -- attribute reference remains dynamic.
7836 -- We could do better here and retrieve the type ???
7838 if Ekind
(P_Entity
) = E_Constant
7839 and then not Is_Constrained
(P_Type
)
7841 if No
(Constant_Value
(P_Entity
)) then
7844 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7848 -- Definite must be folded if the prefix is not a generic type, that
7849 -- is to say if we are within an instantiation. Same processing applies
7850 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7851 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7853 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7854 Id
= Attribute_Definite
or else
7855 Id
= Attribute_Has_Access_Values
or else
7856 Id
= Attribute_Has_Discriminants
or else
7857 Id
= Attribute_Has_Tagged_Values
or else
7858 Id
= Attribute_Lock_Free
or else
7859 Id
= Attribute_Type_Class
or else
7860 Id
= Attribute_Unconstrained_Array
or else
7861 Id
= Attribute_Max_Alignment_For_Allocation
)
7862 and then not Is_Generic_Type
(P_Entity
)
7866 -- We can fold 'Size applied to a type if the size is known (as happens
7867 -- for a size from an attribute definition clause). At this stage, this
7868 -- can happen only for types (e.g. record types) for which the size is
7869 -- always non-static. We exclude generic types from consideration (since
7870 -- they have bogus sizes set within templates).
7872 elsif Id
= Attribute_Size
7873 and then Is_Type
(P_Entity
)
7874 and then (not Is_Generic_Type
(P_Entity
))
7875 and then Known_Static_RM_Size
(P_Entity
)
7877 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7880 -- We can fold 'Alignment applied to a type if the alignment is known
7881 -- (as happens for an alignment from an attribute definition clause).
7882 -- At this stage, this can happen only for types (e.g. record types) for
7883 -- which the size is always non-static. We exclude generic types from
7884 -- consideration (since they have bogus sizes set within templates).
7886 elsif Id
= Attribute_Alignment
7887 and then Is_Type
(P_Entity
)
7888 and then (not Is_Generic_Type
(P_Entity
))
7889 and then Known_Alignment
(P_Entity
)
7891 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7894 -- If this is an access attribute that is known to fail accessibility
7895 -- check, rewrite accordingly.
7897 elsif Attribute_Name
(N
) = Name_Access
7898 and then Raises_Constraint_Error
(N
)
7901 Make_Raise_Program_Error
(Loc
,
7902 Reason
=> PE_Accessibility_Check_Failed
));
7903 Set_Etype
(N
, C_Type
);
7906 -- No other cases are foldable (they certainly aren't static, and at
7907 -- the moment we don't try to fold any cases other than the ones above).
7914 -- If either attribute or the prefix is Any_Type, then propagate
7915 -- Any_Type to the result and don't do anything else at all.
7917 if P_Type
= Any_Type
7918 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7919 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7921 Set_Etype
(N
, Any_Type
);
7925 -- Scalar subtype case. We have not yet enforced the static requirement
7926 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7927 -- of non-static attribute references (e.g. S'Digits for a non-static
7928 -- floating-point type, which we can compute at compile time).
7930 -- Note: this folding of non-static attributes is not simply a case of
7931 -- optimization. For many of the attributes affected, Gigi cannot handle
7932 -- the attribute and depends on the front end having folded them away.
7934 -- Note: although we don't require staticness at this stage, we do set
7935 -- the Static variable to record the staticness, for easy reference by
7936 -- those attributes where it matters (e.g. Succ and Pred), and also to
7937 -- be used to ensure that non-static folded things are not marked as
7938 -- being static (a check that is done right at the end).
7940 P_Root_Type
:= Root_Type
(P_Type
);
7941 P_Base_Type
:= Base_Type
(P_Type
);
7943 -- If the root type or base type is generic, then we cannot fold. This
7944 -- test is needed because subtypes of generic types are not always
7945 -- marked as being generic themselves (which seems odd???)
7947 if Is_Generic_Type
(P_Root_Type
)
7948 or else Is_Generic_Type
(P_Base_Type
)
7953 if Is_Scalar_Type
(P_Type
) then
7954 if not Is_Static_Subtype
(P_Type
) then
7956 Set_Is_Static_Expression
(N
, False);
7957 elsif not Is_OK_Static_Subtype
(P_Type
) then
7958 Set_Raises_Constraint_Error
(N
);
7961 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7962 -- since we can't do anything with unconstrained arrays. In addition,
7963 -- only the First, Last and Length attributes are possibly static.
7965 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7966 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7967 -- Unconstrained_Array are again exceptions, because they apply as well
7968 -- to unconstrained types.
7970 -- In addition Component_Size is an exception since it is possibly
7971 -- foldable, even though it is never static, and it does apply to
7972 -- unconstrained arrays. Furthermore, it is essential to fold this
7973 -- in the packed case, since otherwise the value will be incorrect.
7975 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7976 Id
= Attribute_Definite
or else
7977 Id
= Attribute_Has_Access_Values
or else
7978 Id
= Attribute_Has_Discriminants
or else
7979 Id
= Attribute_Has_Tagged_Values
or else
7980 Id
= Attribute_Lock_Free
or else
7981 Id
= Attribute_Type_Class
or else
7982 Id
= Attribute_Unconstrained_Array
or else
7983 Id
= Attribute_Component_Size
7986 Set_Is_Static_Expression
(N
, False);
7988 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7989 if not Is_Constrained
(P_Type
)
7990 or else (Id
/= Attribute_First
and then
7991 Id
/= Attribute_Last
and then
7992 Id
/= Attribute_Length
)
7998 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7999 -- scalar case, we hold off on enforcing staticness, since there are
8000 -- cases which we can fold at compile time even though they are not
8001 -- static (e.g. 'Length applied to a static index, even though other
8002 -- non-static indexes make the array type non-static). This is only
8003 -- an optimization, but it falls out essentially free, so why not.
8004 -- Again we compute the variable Static for easy reference later
8005 -- (note that no array attributes are static in Ada 83).
8007 -- We also need to set Static properly for subsequent legality checks
8008 -- which might otherwise accept non-static constants in contexts
8009 -- where they are not legal.
8012 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
8013 Set_Is_Static_Expression
(N
, Static
);
8019 Nod
:= First_Index
(P_Type
);
8021 -- The expression is static if the array type is constrained
8022 -- by given bounds, and not by an initial expression. Constant
8023 -- strings are static in any case.
8025 if Root_Type
(P_Type
) /= Standard_String
then
8027 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
8028 Set_Is_Static_Expression
(N
, Static
);
8031 while Present
(Nod
) loop
8032 if not Is_Static_Subtype
(Etype
(Nod
)) then
8034 Set_Is_Static_Expression
(N
, False);
8036 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
8037 Set_Raises_Constraint_Error
(N
);
8039 Set_Is_Static_Expression
(N
, False);
8042 -- If however the index type is generic, or derived from
8043 -- one, attributes cannot be folded.
8045 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
8046 and then Id
/= Attribute_Component_Size
8056 -- Check any expressions that are present. Note that these expressions,
8057 -- depending on the particular attribute type, are either part of the
8058 -- attribute designator, or they are arguments in a case where the
8059 -- attribute reference returns a function. In the latter case, the
8060 -- rule in (RM 4.9(22)) applies and in particular requires the type
8061 -- of the expressions to be scalar in order for the attribute to be
8062 -- considered to be static.
8070 while Present
(E
) loop
8072 -- If expression is not static, then the attribute reference
8073 -- result certainly cannot be static.
8075 if not Is_Static_Expression
(E
) then
8077 Set_Is_Static_Expression
(N
, False);
8080 if Raises_Constraint_Error
(E
) then
8081 Set_Raises_Constraint_Error
(N
);
8084 -- If the result is not known at compile time, or is not of
8085 -- a scalar type, then the result is definitely not static,
8086 -- so we can quit now.
8088 if not Compile_Time_Known_Value
(E
)
8089 or else not Is_Scalar_Type
(Etype
(E
))
8091 -- An odd special case, if this is a Pos attribute, this
8092 -- is where we need to apply a range check since it does
8093 -- not get done anywhere else.
8095 if Id
= Attribute_Pos
then
8096 if Is_Integer_Type
(Etype
(E
)) then
8097 Apply_Range_Check
(E
, Etype
(N
));
8104 -- If the expression raises a constraint error, then so does
8105 -- the attribute reference. We keep going in this case because
8106 -- we are still interested in whether the attribute reference
8107 -- is static even if it is not static.
8109 elsif Raises_Constraint_Error
(E
) then
8110 Set_Raises_Constraint_Error
(N
);
8116 if Raises_Constraint_Error
(Prefix
(N
)) then
8117 Set_Is_Static_Expression
(N
, False);
8122 -- Deal with the case of a static attribute reference that raises
8123 -- constraint error. The Raises_Constraint_Error flag will already
8124 -- have been set, and the Static flag shows whether the attribute
8125 -- reference is static. In any case we certainly can't fold such an
8126 -- attribute reference.
8128 -- Note that the rewriting of the attribute node with the constraint
8129 -- error node is essential in this case, because otherwise Gigi might
8130 -- blow up on one of the attributes it never expects to see.
8132 -- The constraint_error node must have the type imposed by the context,
8133 -- to avoid spurious errors in the enclosing expression.
8135 if Raises_Constraint_Error
(N
) then
8137 Make_Raise_Constraint_Error
(Sloc
(N
),
8138 Reason
=> CE_Range_Check_Failed
);
8139 Set_Etype
(CE_Node
, Etype
(N
));
8140 Set_Raises_Constraint_Error
(CE_Node
);
8142 Rewrite
(N
, Relocate_Node
(CE_Node
));
8143 Set_Raises_Constraint_Error
(N
, True);
8147 -- At this point we have a potentially foldable attribute reference.
8148 -- If Static is set, then the attribute reference definitely obeys
8149 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8150 -- folded. If Static is not set, then the attribute may or may not
8151 -- be foldable, and the individual attribute processing routines
8152 -- test Static as required in cases where it makes a difference.
8154 -- In the case where Static is not set, we do know that all the
8155 -- expressions present are at least known at compile time (we assumed
8156 -- above that if this was not the case, then there was no hope of static
8157 -- evaluation). However, we did not require that the bounds of the
8158 -- prefix type be compile time known, let alone static). That's because
8159 -- there are many attributes that can be computed at compile time on
8160 -- non-static subtypes, even though such references are not static
8163 -- For VAX float, the root type is an IEEE type. So make sure to use the
8164 -- base type instead of the root-type for floating point attributes.
8168 -- Attributes related to Ada 2012 iterators; nothing to evaluate for
8171 when Attribute_Constant_Indexing
8172 | Attribute_Default_Iterator
8173 | Attribute_Implicit_Dereference
8174 | Attribute_Iterator_Element
8175 | Attribute_Iterable
8176 | Attribute_Variable_Indexing
8180 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8181 -- These were already rejected by the parser. Thus they shouldn't
8184 when Internal_Attribute_Id
=>
8185 raise Program_Error
;
8191 when Attribute_Adjacent
=>
8195 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8202 when Attribute_Aft
=>
8203 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8209 when Attribute_Alignment
=> Alignment_Block
: declare
8210 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8213 -- Fold if alignment is set and not otherwise
8215 if Known_Alignment
(P_TypeA
) then
8216 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8218 end Alignment_Block
;
8220 -----------------------------
8221 -- Atomic_Always_Lock_Free --
8222 -----------------------------
8224 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8227 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8229 V
: constant Entity_Id
:=
8231 (Support_Atomic_Primitives_On_Target
8232 and then Support_Atomic_Primitives
(P_Type
));
8235 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8237 -- Analyze and resolve as boolean. Note that this attribute is a
8238 -- static attribute in GNAT.
8240 Analyze_And_Resolve
(N
, Standard_Boolean
);
8242 Set_Is_Static_Expression
(N
, True);
8243 end Atomic_Always_Lock_Free
;
8249 -- Bit can never be folded
8251 when Attribute_Bit
=>
8258 -- Body_version can never be static
8260 when Attribute_Body_Version
=>
8267 when Attribute_Ceiling
=>
8269 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8271 --------------------
8272 -- Component_Size --
8273 --------------------
8275 when Attribute_Component_Size
=>
8276 if Known_Static_Component_Size
(P_Type
) then
8277 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
8284 when Attribute_Compose
=>
8287 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8294 -- Constrained is never folded for now, there may be cases that
8295 -- could be handled at compile time. To be looked at later.
8297 when Attribute_Constrained
=>
8299 -- The expander might fold it and set the static flag accordingly,
8300 -- but with expansion disabled (as in ASIS), it remains as an
8301 -- attribute reference, and this reference is not static.
8303 Set_Is_Static_Expression
(N
, False);
8310 when Attribute_Copy_Sign
=>
8314 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8321 when Attribute_Definite
=>
8322 Rewrite
(N
, New_Occurrence_Of
(
8323 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
8324 Analyze_And_Resolve
(N
, Standard_Boolean
);
8330 when Attribute_Delta
=>
8331 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
8337 when Attribute_Denorm
=>
8339 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
8341 ---------------------
8342 -- Descriptor_Size --
8343 ---------------------
8345 when Attribute_Descriptor_Size
=>
8352 when Attribute_Digits
=>
8353 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
8359 when Attribute_Emax
=>
8361 -- Ada 83 attribute is defined as (RM83 3.5.8)
8363 -- T'Emax = 4 * T'Mantissa
8365 Fold_Uint
(N
, 4 * Mantissa
, Static
);
8371 when Attribute_Enum_Rep
=> Enum_Rep
: declare
8375 -- The attribute appears in the form:
8377 -- Enum_Typ'Enum_Rep (Const)
8378 -- Enum_Typ'Enum_Rep (Enum_Lit)
8380 if Present
(E1
) then
8383 -- Otherwise the prefix denotes a constant or enumeration literal:
8386 -- Enum_Lit'Enum_Rep
8392 -- For an enumeration type with a non-standard representation use
8393 -- the Enumeration_Rep field of the proper constant. Note that this
8394 -- will not work for types Character/Wide_[Wide-]Character, since no
8395 -- real entities are created for the enumeration literals, but that
8396 -- does not matter since these two types do not have non-standard
8397 -- representations anyway.
8399 if Is_Enumeration_Type
(P_Type
)
8400 and then Has_Non_Standard_Rep
(P_Type
)
8402 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
8404 -- For enumeration types with standard representations and all other
8405 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
8409 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
8417 when Attribute_Enum_Val
=> Enum_Val
: declare
8421 -- We have something like Enum_Type'Enum_Val (23), so search for a
8422 -- corresponding value in the list of Enum_Rep values for the type.
8424 Lit
:= First_Literal
(P_Base_Type
);
8426 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
8427 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
8434 Apply_Compile_Time_Constraint_Error
8435 (N
, "no representation value matches",
8436 CE_Range_Check_Failed
,
8437 Warn
=> not Static
);
8447 when Attribute_Epsilon
=>
8449 -- Ada 83 attribute is defined as (RM83 3.5.8)
8451 -- T'Epsilon = 2.0**(1 - T'Mantissa)
8453 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
8459 when Attribute_Exponent
=>
8461 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8463 -----------------------
8464 -- Finalization_Size --
8465 -----------------------
8467 when Attribute_Finalization_Size
=>
8474 when Attribute_First
=>
8477 if Compile_Time_Known_Value
(Lo_Bound
) then
8478 if Is_Real_Type
(P_Type
) then
8479 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
8481 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8485 Check_Concurrent_Discriminant
(Lo_Bound
);
8492 when Attribute_First_Valid
=>
8493 if Has_Predicates
(P_Type
)
8494 and then Has_Static_Predicate
(P_Type
)
8497 FirstN
: constant Node_Id
:=
8498 First
(Static_Discrete_Predicate
(P_Type
));
8500 if Nkind
(FirstN
) = N_Range
then
8501 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
8503 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
8509 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8516 when Attribute_Fixed_Value
=>
8523 when Attribute_Floor
=>
8525 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8531 when Attribute_Fore
=>
8532 if Compile_Time_Known_Bounds
(P_Type
) then
8533 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
8540 when Attribute_Fraction
=>
8542 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8544 -----------------------
8545 -- Has_Access_Values --
8546 -----------------------
8548 when Attribute_Has_Access_Values
=>
8549 Rewrite
(N
, New_Occurrence_Of
8550 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8551 Analyze_And_Resolve
(N
, Standard_Boolean
);
8553 -----------------------
8554 -- Has_Discriminants --
8555 -----------------------
8557 when Attribute_Has_Discriminants
=>
8558 Rewrite
(N
, New_Occurrence_Of
(
8559 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8560 Analyze_And_Resolve
(N
, Standard_Boolean
);
8562 ----------------------
8563 -- Has_Same_Storage --
8564 ----------------------
8566 when Attribute_Has_Same_Storage
=>
8569 -----------------------
8570 -- Has_Tagged_Values --
8571 -----------------------
8573 when Attribute_Has_Tagged_Values
=>
8574 Rewrite
(N
, New_Occurrence_Of
8575 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8576 Analyze_And_Resolve
(N
, Standard_Boolean
);
8582 when Attribute_Identity
=>
8589 -- Image is a scalar attribute, but is never static, because it is
8590 -- not a static function (having a non-scalar argument (RM 4.9(22))
8591 -- However, we can constant-fold the image of an enumeration literal
8592 -- if names are available.
8594 when Attribute_Image
=>
8595 if Is_Entity_Name
(E1
)
8596 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8597 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8598 and then not Global_Discard_Names
8601 Lit
: constant Entity_Id
:= Entity
(E1
);
8605 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8606 Set_Casing
(All_Upper_Case
);
8607 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8609 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8610 Analyze_And_Resolve
(N
, Standard_String
);
8611 Set_Is_Static_Expression
(N
, False);
8619 -- We never try to fold Integer_Value (though perhaps we could???)
8621 when Attribute_Integer_Value
=>
8628 -- Invalid_Value is a scalar attribute that is never static, because
8629 -- the value is by design out of range.
8631 when Attribute_Invalid_Value
=>
8638 when Attribute_Large
=>
8640 -- For fixed-point, we use the identity:
8642 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8644 if Is_Fixed_Point_Type
(P_Type
) then
8646 Make_Op_Multiply
(Loc
,
8648 Make_Op_Subtract
(Loc
,
8652 Make_Real_Literal
(Loc
, Ureal_2
),
8654 Make_Attribute_Reference
(Loc
,
8656 Attribute_Name
=> Name_Mantissa
)),
8657 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8660 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8662 Analyze_And_Resolve
(N
, C_Type
);
8664 -- Floating-point (Ada 83 compatibility)
8667 -- Ada 83 attribute is defined as (RM83 3.5.8)
8669 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8673 -- T'Emax = 4 * T'Mantissa
8677 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8685 when Attribute_Lock_Free
=> Lock_Free
: declare
8686 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8689 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8691 -- Analyze and resolve as boolean. Note that this attribute is a
8692 -- static attribute in GNAT.
8694 Analyze_And_Resolve
(N
, Standard_Boolean
);
8696 Set_Is_Static_Expression
(N
, True);
8703 when Attribute_Last
=>
8706 if Compile_Time_Known_Value
(Hi_Bound
) then
8707 if Is_Real_Type
(P_Type
) then
8708 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8710 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8714 Check_Concurrent_Discriminant
(Hi_Bound
);
8721 when Attribute_Last_Valid
=>
8722 if Has_Predicates
(P_Type
)
8723 and then Has_Static_Predicate
(P_Type
)
8726 LastN
: constant Node_Id
:=
8727 Last
(Static_Discrete_Predicate
(P_Type
));
8729 if Nkind
(LastN
) = N_Range
then
8730 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8732 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8738 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8745 when Attribute_Leading_Part
=>
8748 Eval_Fat
.Leading_Part
8749 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8756 when Attribute_Length
=> Length
: declare
8760 -- If any index type is a formal type, or derived from one, the
8761 -- bounds are not static. Treating them as static can produce
8762 -- spurious warnings or improper constant folding.
8764 Ind
:= First_Index
(P_Type
);
8765 while Present
(Ind
) loop
8766 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8775 -- For two compile time values, we can compute length
8777 if Compile_Time_Known_Value
(Lo_Bound
)
8778 and then Compile_Time_Known_Value
(Hi_Bound
)
8781 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8785 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8786 -- comparable, and we can figure out the difference between them.
8789 Diff
: aliased Uint
;
8793 Compile_Time_Compare
8794 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8797 Fold_Uint
(N
, Uint_1
, Static
);
8800 Fold_Uint
(N
, Uint_0
, Static
);
8803 if Diff
/= No_Uint
then
8804 Fold_Uint
(N
, Diff
+ 1, Static
);
8817 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8818 -- of the said attribute at the point of entry into the related loop. As
8819 -- such, the attribute reference does not need to be evaluated because
8820 -- the prefix is the one that is evaluted.
8822 when Attribute_Loop_Entry
=>
8829 when Attribute_Machine
=>
8833 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8840 when Attribute_Machine_Emax
=>
8841 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8847 when Attribute_Machine_Emin
=>
8848 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8850 ----------------------
8851 -- Machine_Mantissa --
8852 ----------------------
8854 when Attribute_Machine_Mantissa
=>
8855 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8857 -----------------------
8858 -- Machine_Overflows --
8859 -----------------------
8861 when Attribute_Machine_Overflows
=>
8863 -- Always true for fixed-point
8865 if Is_Fixed_Point_Type
(P_Type
) then
8866 Fold_Uint
(N
, True_Value
, Static
);
8868 -- Floating point case
8872 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8880 when Attribute_Machine_Radix
=>
8881 if Is_Fixed_Point_Type
(P_Type
) then
8882 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8883 and then Machine_Radix_10
(P_Type
)
8885 Fold_Uint
(N
, Uint_10
, Static
);
8887 Fold_Uint
(N
, Uint_2
, Static
);
8890 -- All floating-point type always have radix 2
8893 Fold_Uint
(N
, Uint_2
, Static
);
8896 ----------------------
8897 -- Machine_Rounding --
8898 ----------------------
8900 -- Note: for the folding case, it is fine to treat Machine_Rounding
8901 -- exactly the same way as Rounding, since this is one of the allowed
8902 -- behaviors, and performance is not an issue here. It might be a bit
8903 -- better to give the same result as it would give at run time, even
8904 -- though the non-determinism is certainly permitted.
8906 when Attribute_Machine_Rounding
=>
8908 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8910 --------------------
8911 -- Machine_Rounds --
8912 --------------------
8914 when Attribute_Machine_Rounds
=>
8916 -- Always False for fixed-point
8918 if Is_Fixed_Point_Type
(P_Type
) then
8919 Fold_Uint
(N
, False_Value
, Static
);
8921 -- Else yield proper floating-point result
8925 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8933 -- Note: Machine_Size is identical to Object_Size
8935 when Attribute_Machine_Size
=> Machine_Size
: declare
8936 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8939 if Known_Esize
(P_TypeA
) then
8940 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8948 when Attribute_Mantissa
=>
8950 -- Fixed-point mantissa
8952 if Is_Fixed_Point_Type
(P_Type
) then
8954 -- Compile time foldable case
8956 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8958 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8960 -- The calculation of the obsolete Ada 83 attribute Mantissa
8961 -- is annoying, because of AI00143, quoted here:
8963 -- !question 84-01-10
8965 -- Consider the model numbers for F:
8967 -- type F is delta 1.0 range -7.0 .. 8.0;
8969 -- The wording requires that F'MANTISSA be the SMALLEST
8970 -- integer number for which each bound of the specified
8971 -- range is either a model number or lies at most small
8972 -- distant from a model number. This means F'MANTISSA
8973 -- is required to be 3 since the range -7.0 .. 7.0 fits
8974 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8975 -- number, namely, 7. Is this analysis correct? Note that
8976 -- this implies the upper bound of the range is not
8977 -- represented as a model number.
8979 -- !response 84-03-17
8981 -- The analysis is correct. The upper and lower bounds for
8982 -- a fixed point type can lie outside the range of model
8993 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8994 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8995 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8996 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8998 -- If the Bound is exactly a model number, i.e. a multiple
8999 -- of Small, then we back it off by one to get the integer
9000 -- value that must be representable.
9002 if Small_Value
(P_Type
) * Max_Man
= Bound
then
9003 Max_Man
:= Max_Man
- 1;
9006 -- Now find corresponding size = Mantissa value
9009 while 2 ** Siz
< Max_Man
loop
9013 Fold_Uint
(N
, Siz
, Static
);
9017 -- The case of dynamic bounds cannot be evaluated at compile
9018 -- time. Instead we use a runtime routine (see Exp_Attr).
9023 -- Floating-point Mantissa
9026 Fold_Uint
(N
, Mantissa
, Static
);
9033 when Attribute_Max
=>
9034 if Is_Real_Type
(P_Type
) then
9036 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9038 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9041 ----------------------------------
9042 -- Max_Alignment_For_Allocation --
9043 ----------------------------------
9045 -- Max_Alignment_For_Allocation is usually the Alignment. However,
9046 -- arrays are allocated with dope, so we need to take into account both
9047 -- the alignment of the array, which comes from the component alignment,
9048 -- and the alignment of the dope. Also, if the alignment is unknown, we
9049 -- use the max (it's OK to be pessimistic).
9051 when Attribute_Max_Alignment_For_Allocation
=> Max_Align
: declare
9052 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
9054 if Known_Alignment
(P_Type
)
9055 and then (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
9057 A
:= Alignment
(P_Type
);
9060 Fold_Uint
(N
, A
, Static
);
9063 ----------------------------------
9064 -- Max_Size_In_Storage_Elements --
9065 ----------------------------------
9067 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9068 -- Storage_Unit boundary. We can fold any cases for which the size
9069 -- is known by the front end.
9071 when Attribute_Max_Size_In_Storage_Elements
=>
9072 if Known_Esize
(P_Type
) then
9074 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9075 System_Storage_Unit
,
9079 --------------------
9080 -- Mechanism_Code --
9081 --------------------
9083 when Attribute_Mechanism_Code
=> Mechanism_Code
: declare
9085 Mech
: Mechanism_Type
;
9090 Mech
:= Mechanism
(P_Entity
);
9093 Val
:= UI_To_Int
(Expr_Value
(E1
));
9095 Formal
:= First_Formal
(P_Entity
);
9096 for J
in 1 .. Val
- 1 loop
9097 Next_Formal
(Formal
);
9100 Mech
:= Mechanism
(Formal
);
9104 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9112 when Attribute_Min
=>
9113 if Is_Real_Type
(P_Type
) then
9115 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9118 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9125 when Attribute_Mod
=>
9127 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9133 when Attribute_Model
=>
9135 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9141 when Attribute_Model_Emin
=>
9142 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9148 when Attribute_Model_Epsilon
=>
9149 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9151 --------------------
9152 -- Model_Mantissa --
9153 --------------------
9155 when Attribute_Model_Mantissa
=>
9156 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9162 when Attribute_Model_Small
=>
9163 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9169 when Attribute_Modulus
=>
9170 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9172 --------------------
9173 -- Null_Parameter --
9174 --------------------
9176 -- Cannot fold, we know the value sort of, but the whole point is
9177 -- that there is no way to talk about this imaginary value except
9178 -- by using the attribute, so we leave it the way it is.
9180 when Attribute_Null_Parameter
=>
9187 -- The Object_Size attribute for a type returns the Esize of the
9188 -- type and can be folded if this value is known.
9190 when Attribute_Object_Size
=> Object_Size
: declare
9191 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9194 if Known_Esize
(P_TypeA
) then
9195 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9199 ----------------------
9200 -- Overlaps_Storage --
9201 ----------------------
9203 when Attribute_Overlaps_Storage
=>
9206 -------------------------
9207 -- Passed_By_Reference --
9208 -------------------------
9210 -- Scalar types are never passed by reference
9212 when Attribute_Passed_By_Reference
=>
9213 Fold_Uint
(N
, False_Value
, Static
);
9219 when Attribute_Pos
=>
9220 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9226 when Attribute_Pred
=>
9228 -- Floating-point case
9230 if Is_Floating_Point_Type
(P_Type
) then
9232 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9236 elsif Is_Fixed_Point_Type
(P_Type
) then
9238 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9240 -- Modular integer case (wraps)
9242 elsif Is_Modular_Integer_Type
(P_Type
) then
9243 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
9245 -- Other scalar cases
9248 pragma Assert
(Is_Scalar_Type
(P_Type
));
9250 if Is_Enumeration_Type
(P_Type
)
9251 and then Expr_Value
(E1
) =
9252 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9254 Apply_Compile_Time_Constraint_Error
9255 (N
, "Pred of `&''First`",
9256 CE_Overflow_Check_Failed
,
9258 Warn
=> not Static
);
9264 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
9271 -- No processing required, because by this stage, Range has been
9272 -- replaced by First .. Last, so this branch can never be taken.
9274 when Attribute_Range
=>
9275 raise Program_Error
;
9281 when Attribute_Range_Length
=> Range_Length
: declare
9282 Diff
: aliased Uint
;
9287 -- Can fold if both bounds are compile time known
9289 if Compile_Time_Known_Value
(Hi_Bound
)
9290 and then Compile_Time_Known_Value
(Lo_Bound
)
9294 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
9298 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9299 -- comparable, and we can figure out the difference between them.
9301 case Compile_Time_Compare
9302 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9305 Fold_Uint
(N
, Uint_1
, Static
);
9308 Fold_Uint
(N
, Uint_0
, Static
);
9311 if Diff
/= No_Uint
then
9312 Fold_Uint
(N
, Diff
+ 1, Static
);
9324 when Attribute_Ref
=>
9325 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9331 when Attribute_Remainder
=> Remainder
: declare
9332 X
: constant Ureal
:= Expr_Value_R
(E1
);
9333 Y
: constant Ureal
:= Expr_Value_R
(E2
);
9336 if UR_Is_Zero
(Y
) then
9337 Apply_Compile_Time_Constraint_Error
9338 (N
, "division by zero in Remainder",
9339 CE_Overflow_Check_Failed
,
9340 Warn
=> not Static
);
9346 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
9353 when Attribute_Restriction_Set
=>
9354 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
9355 Set_Is_Static_Expression
(N
);
9361 when Attribute_Round
=> Round
: declare
9366 -- First we get the (exact result) in units of small
9368 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
9370 -- Now round that exactly to an integer
9372 Si
:= UR_To_Uint
(Sr
);
9374 -- Finally the result is obtained by converting back to real
9376 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
9383 when Attribute_Rounding
=>
9385 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9391 when Attribute_Safe_Emax
=>
9392 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
9398 when Attribute_Safe_First
=>
9399 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
9405 when Attribute_Safe_Large
=>
9406 if Is_Fixed_Point_Type
(P_Type
) then
9408 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
9410 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9417 when Attribute_Safe_Last
=>
9418 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9424 when Attribute_Safe_Small
=>
9426 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
9427 -- for fixed-point, since is the same as Small, but we implement
9428 -- it for backwards compatibility.
9430 if Is_Fixed_Point_Type
(P_Type
) then
9431 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
9433 -- Ada 83 Safe_Small for floating-point cases
9436 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
9443 when Attribute_Scale
=>
9444 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
9450 when Attribute_Scaling
=>
9454 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9461 when Attribute_Signed_Zeros
=>
9463 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
9469 -- Size attribute returns the RM size. All scalar types can be folded,
9470 -- as well as any types for which the size is known by the front end,
9471 -- including any type for which a size attribute is specified. This is
9472 -- one of the places where it is annoying that a size of zero means two
9473 -- things (zero size for scalars, unspecified size for non-scalars).
9476 | Attribute_VADS_Size
9479 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9482 if Is_Scalar_Type
(P_TypeA
)
9483 or else RM_Size
(P_TypeA
) /= Uint_0
9487 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
9489 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
9492 -- If a size clause applies, then use the size from it.
9493 -- This is one of the rare cases where we can use the
9494 -- Size_Clause field for a subtype when Has_Size_Clause
9495 -- is False. Consider:
9497 -- type x is range 1 .. 64;
9498 -- for x'size use 12;
9499 -- subtype y is x range 0 .. 3;
9501 -- Here y has a size clause inherited from x, but
9502 -- normally it does not apply, and y'size is 2. However,
9503 -- y'VADS_Size is indeed 12 and not 2.
9506 and then Is_OK_Static_Expression
(Expression
(S
))
9508 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
9510 -- If no size is specified, then we simply use the object
9511 -- size in the VADS_Size case (e.g. Natural'Size is equal
9512 -- to Integer'Size, not one less).
9515 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9519 -- Normal case (Size) in which case we want the RM_Size
9522 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9531 when Attribute_Small
=>
9533 -- The floating-point case is present only for Ada 83 compatibility.
9534 -- Note that strictly this is an illegal addition, since we are
9535 -- extending an Ada 95 defined attribute, but we anticipate an
9536 -- ARG ruling that will permit this.
9538 if Is_Floating_Point_Type
(P_Type
) then
9540 -- Ada 83 attribute is defined as (RM83 3.5.8)
9542 -- T'Small = 2.0**(-T'Emax - 1)
9546 -- T'Emax = 4 * T'Mantissa
9548 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9550 -- Normal Ada 95 fixed-point case
9553 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9560 when Attribute_Stream_Size
=>
9567 when Attribute_Succ
=>
9568 -- Floating-point case
9570 if Is_Floating_Point_Type
(P_Type
) then
9572 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9576 elsif Is_Fixed_Point_Type
(P_Type
) then
9577 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9579 -- Modular integer case (wraps)
9581 elsif Is_Modular_Integer_Type
(P_Type
) then
9582 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9584 -- Other scalar cases
9587 pragma Assert
(Is_Scalar_Type
(P_Type
));
9589 if Is_Enumeration_Type
(P_Type
)
9590 and then Expr_Value
(E1
) =
9591 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9593 Apply_Compile_Time_Constraint_Error
9594 (N
, "Succ of `&''Last`",
9595 CE_Overflow_Check_Failed
,
9597 Warn
=> not Static
);
9602 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9610 when Attribute_Truncation
=>
9613 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9620 when Attribute_Type_Class
=> Type_Class
: declare
9621 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9625 if Is_Descendant_Of_Address
(Typ
) then
9626 Id
:= RE_Type_Class_Address
;
9628 elsif Is_Enumeration_Type
(Typ
) then
9629 Id
:= RE_Type_Class_Enumeration
;
9631 elsif Is_Integer_Type
(Typ
) then
9632 Id
:= RE_Type_Class_Integer
;
9634 elsif Is_Fixed_Point_Type
(Typ
) then
9635 Id
:= RE_Type_Class_Fixed_Point
;
9637 elsif Is_Floating_Point_Type
(Typ
) then
9638 Id
:= RE_Type_Class_Floating_Point
;
9640 elsif Is_Array_Type
(Typ
) then
9641 Id
:= RE_Type_Class_Array
;
9643 elsif Is_Record_Type
(Typ
) then
9644 Id
:= RE_Type_Class_Record
;
9646 elsif Is_Access_Type
(Typ
) then
9647 Id
:= RE_Type_Class_Access
;
9649 elsif Is_Task_Type
(Typ
) then
9650 Id
:= RE_Type_Class_Task
;
9652 -- We treat protected types like task types. It would make more
9653 -- sense to have another enumeration value, but after all the
9654 -- whole point of this feature is to be exactly DEC compatible,
9655 -- and changing the type Type_Class would not meet this requirement.
9657 elsif Is_Protected_Type
(Typ
) then
9658 Id
:= RE_Type_Class_Task
;
9660 -- Not clear if there are any other possibilities, but if there
9661 -- are, then we will treat them as the address case.
9664 Id
:= RE_Type_Class_Address
;
9667 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9670 -----------------------
9671 -- Unbiased_Rounding --
9672 -----------------------
9674 when Attribute_Unbiased_Rounding
=>
9677 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9680 -------------------------
9681 -- Unconstrained_Array --
9682 -------------------------
9684 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9685 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9688 Rewrite
(N
, New_Occurrence_Of
(
9690 Is_Array_Type
(P_Type
)
9691 and then not Is_Constrained
(Typ
)), Loc
));
9693 -- Analyze and resolve as boolean, note that this attribute is
9694 -- a static attribute in GNAT.
9696 Analyze_And_Resolve
(N
, Standard_Boolean
);
9698 Set_Is_Static_Expression
(N
, True);
9699 end Unconstrained_Array
;
9701 -- Attribute Update is never static
9703 when Attribute_Update
=>
9710 -- Processing is shared with Size
9716 when Attribute_Val
=>
9717 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9719 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9721 Apply_Compile_Time_Constraint_Error
9722 (N
, "Val expression out of range",
9723 CE_Range_Check_Failed
,
9724 Warn
=> not Static
);
9730 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9737 -- The Value_Size attribute for a type returns the RM size of the type.
9738 -- This an always be folded for scalar types, and can also be folded for
9739 -- non-scalar types if the size is set. This is one of the places where
9740 -- it is annoying that a size of zero means two things!
9742 when Attribute_Value_Size
=> Value_Size
: declare
9743 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9746 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9747 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9755 -- Version can never be static
9757 when Attribute_Version
=>
9764 -- Wide_Image is a scalar attribute, but is never static, because it
9765 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9767 when Attribute_Wide_Image
=>
9770 ---------------------
9771 -- Wide_Wide_Image --
9772 ---------------------
9774 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9775 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9777 when Attribute_Wide_Wide_Image
=>
9780 ---------------------
9781 -- Wide_Wide_Width --
9782 ---------------------
9784 -- Processing for Wide_Wide_Width is combined with Width
9790 -- Processing for Wide_Width is combined with Width
9796 -- This processing also handles the case of Wide_[Wide_]Width
9798 when Attribute_Width
9799 | Attribute_Wide_Width
9800 | Attribute_Wide_Wide_Width
9802 if Compile_Time_Known_Bounds
(P_Type
) then
9804 -- Floating-point types
9806 if Is_Floating_Point_Type
(P_Type
) then
9808 -- Width is zero for a null range (RM 3.5 (38))
9810 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9811 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9813 Fold_Uint
(N
, Uint_0
, Static
);
9816 -- For floating-point, we have +N.dddE+nnn where length
9817 -- of ddd is determined by type'Digits - 1, but is one
9818 -- if Digits is one (RM 3.5 (33)).
9820 -- nnn is set to 2 for Short_Float and Float (32 bit
9821 -- floats), and 3 for Long_Float and Long_Long_Float.
9822 -- For machines where Long_Long_Float is the IEEE
9823 -- extended precision type, the exponent takes 4 digits.
9827 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9830 if Esize
(P_Type
) <= 32 then
9832 elsif Esize
(P_Type
) = 64 then
9838 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9842 -- Fixed-point types
9844 elsif Is_Fixed_Point_Type
(P_Type
) then
9846 -- Width is zero for a null range (RM 3.5 (38))
9848 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9849 Expr_Value
(Type_Low_Bound
(P_Type
))
9851 Fold_Uint
(N
, Uint_0
, Static
);
9853 -- The non-null case depends on the specific real type
9856 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9859 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9867 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9868 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9869 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9882 -- Width for types derived from Standard.Character
9883 -- and Standard.Wide_[Wide_]Character.
9885 elsif Is_Standard_Character_Type
(P_Type
) then
9888 -- Set W larger if needed
9890 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9892 -- All wide characters look like Hex_hhhhhhhh
9896 -- No need to compute this more than once
9901 C
:= Character'Val (J
);
9903 -- Test for all cases where Character'Image
9904 -- yields an image that is longer than three
9905 -- characters. First the cases of Reserved_xxx
9906 -- names (length = 12).
9984 | No_Break_Space
.. LC_Y_Diaeresis
9986 -- Special case of soft hyphen in Ada 2005
9988 if C
= Character'Val (16#AD#
)
9989 and then Ada_Version
>= Ada_2005
9997 W
:= Int
'Max (W
, Wt
);
10001 -- Width for types derived from Standard.Boolean
10003 elsif R
= Standard_Boolean
then
10010 -- Width for integer types
10012 elsif Is_Integer_Type
(P_Type
) then
10013 T
:= UI_Max
(abs Lo
, abs Hi
);
10021 -- User declared enum type with discard names
10023 elsif Discard_Names
(R
) then
10025 -- If range is null, result is zero, that has already
10026 -- been dealt with, so what we need is the power of ten
10027 -- that accommodates the Pos of the largest value, which
10028 -- is the high bound of the range + one for the space.
10037 -- Only remaining possibility is user declared enum type
10038 -- with normal case of Discard_Names not active.
10041 pragma Assert
(Is_Enumeration_Type
(P_Type
));
10044 L
:= First_Literal
(P_Type
);
10045 while Present
(L
) loop
10047 -- Only pay attention to in range characters
10049 if Lo
<= Enumeration_Pos
(L
)
10050 and then Enumeration_Pos
(L
) <= Hi
10052 -- For Width case, use decoded name
10054 if Id
= Attribute_Width
then
10055 Get_Decoded_Name_String
(Chars
(L
));
10056 Wt
:= Nat
(Name_Len
);
10058 -- For Wide_[Wide_]Width, use encoded name, and
10059 -- then adjust for the encoding.
10062 Get_Name_String
(Chars
(L
));
10064 -- Character literals are always of length 3
10066 if Name_Buffer
(1) = 'Q' then
10069 -- Otherwise loop to adjust for upper/wide chars
10072 Wt
:= Nat
(Name_Len
);
10074 for J
in 1 .. Name_Len
loop
10075 if Name_Buffer
(J
) = 'U' then
10077 elsif Name_Buffer
(J
) = 'W' then
10084 W
:= Int
'Max (W
, Wt
);
10091 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
10096 -- The following attributes denote functions that cannot be folded
10098 when Attribute_From_Any
10100 | Attribute_TypeCode
10104 -- The following attributes can never be folded, and furthermore we
10105 -- should not even have entered the case statement for any of these.
10106 -- Note that in some cases, the values have already been folded as
10107 -- a result of the processing in Analyze_Attribute or earlier in
10110 when Attribute_Abort_Signal
10112 | Attribute_Address
10113 | Attribute_Address_Size
10114 | Attribute_Asm_Input
10115 | Attribute_Asm_Output
10117 | Attribute_Bit_Order
10118 | Attribute_Bit_Position
10119 | Attribute_Callable
10122 | Attribute_Code_Address
10123 | Attribute_Compiler_Version
10125 | Attribute_Default_Bit_Order
10126 | Attribute_Default_Scalar_Storage_Order
10128 | Attribute_Elaborated
10129 | Attribute_Elab_Body
10130 | Attribute_Elab_Spec
10131 | Attribute_Elab_Subp_Body
10132 | Attribute_Enabled
10133 | Attribute_External_Tag
10134 | Attribute_Fast_Math
10135 | Attribute_First_Bit
10138 | Attribute_Last_Bit
10139 | Attribute_Library_Level
10140 | Attribute_Maximum_Alignment
10143 | Attribute_Partition_ID
10144 | Attribute_Pool_Address
10145 | Attribute_Position
10146 | Attribute_Priority
10149 | Attribute_Scalar_Storage_Order
10150 | Attribute_Simple_Storage_Pool
10151 | Attribute_Storage_Pool
10152 | Attribute_Storage_Size
10153 | Attribute_Storage_Unit
10154 | Attribute_Stub_Type
10155 | Attribute_System_Allocator_Alignment
10157 | Attribute_Target_Name
10158 | Attribute_Terminated
10159 | Attribute_To_Address
10160 | Attribute_Type_Key
10161 | Attribute_Unchecked_Access
10162 | Attribute_Universal_Literal_String
10163 | Attribute_Unrestricted_Access
10165 | Attribute_Valid_Scalars
10167 | Attribute_Wchar_T_Size
10168 | Attribute_Wide_Value
10169 | Attribute_Wide_Wide_Value
10170 | Attribute_Word_Size
10173 raise Program_Error
;
10176 -- At the end of the case, one more check. If we did a static evaluation
10177 -- so that the result is now a literal, then set Is_Static_Expression
10178 -- in the constant only if the prefix type is a static subtype. For
10179 -- non-static subtypes, the folding is still OK, but not static.
10181 -- An exception is the GNAT attribute Constrained_Array which is
10182 -- defined to be a static attribute in all cases.
10184 if Nkind_In
(N
, N_Integer_Literal
,
10186 N_Character_Literal
,
10188 or else (Is_Entity_Name
(N
)
10189 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10191 Set_Is_Static_Expression
(N
, Static
);
10193 -- If this is still an attribute reference, then it has not been folded
10194 -- and that means that its expressions are in a non-static context.
10196 elsif Nkind
(N
) = N_Attribute_Reference
then
10199 -- Note: the else case not covered here are odd cases where the
10200 -- processing has transformed the attribute into something other
10201 -- than a constant. Nothing more to do in such cases.
10206 end Eval_Attribute
;
10208 ------------------------------
10209 -- Is_Anonymous_Tagged_Base --
10210 ------------------------------
10212 function Is_Anonymous_Tagged_Base
10214 Typ
: Entity_Id
) return Boolean
10218 Anon
= Current_Scope
10219 and then Is_Itype
(Anon
)
10220 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
10221 end Is_Anonymous_Tagged_Base
;
10223 --------------------------------
10224 -- Name_Implies_Lvalue_Prefix --
10225 --------------------------------
10227 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
10228 pragma Assert
(Is_Attribute_Name
(Nam
));
10230 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
10231 end Name_Implies_Lvalue_Prefix
;
10233 -----------------------
10234 -- Resolve_Attribute --
10235 -----------------------
10237 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
10238 Loc
: constant Source_Ptr
:= Sloc
(N
);
10239 P
: constant Node_Id
:= Prefix
(N
);
10240 Aname
: constant Name_Id
:= Attribute_Name
(N
);
10241 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
10242 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10243 Des_Btyp
: Entity_Id
;
10244 Index
: Interp_Index
;
10246 Nom_Subt
: Entity_Id
;
10248 procedure Accessibility_Message
;
10249 -- Error, or warning within an instance, if the static accessibility
10250 -- rules of 3.10.2 are violated.
10252 function Declared_Within_Generic_Unit
10253 (Entity
: Entity_Id
;
10254 Generic_Unit
: Node_Id
) return Boolean;
10255 -- Returns True if Declared_Entity is declared within the declarative
10256 -- region of Generic_Unit; otherwise returns False.
10258 ---------------------------
10259 -- Accessibility_Message --
10260 ---------------------------
10262 procedure Accessibility_Message
is
10263 Indic
: Node_Id
:= Parent
(Parent
(N
));
10266 -- In an instance, this is a runtime check, but one we
10267 -- know will fail, so generate an appropriate warning.
10269 if In_Instance_Body
then
10270 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10272 ("non-local pointer cannot point to local object<<", P
);
10273 Error_Msg_F
("\Program_Error [<<", P
);
10275 Make_Raise_Program_Error
(Loc
,
10276 Reason
=> PE_Accessibility_Check_Failed
));
10277 Set_Etype
(N
, Typ
);
10281 Error_Msg_F
("non-local pointer cannot point to local object", P
);
10283 -- Check for case where we have a missing access definition
10285 if Is_Record_Type
(Current_Scope
)
10287 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
10288 N_Index_Or_Discriminant_Constraint
)
10290 Indic
:= Parent
(Parent
(N
));
10291 while Present
(Indic
)
10292 and then Nkind
(Indic
) /= N_Subtype_Indication
10294 Indic
:= Parent
(Indic
);
10297 if Present
(Indic
) then
10299 ("\use an access definition for" &
10300 " the access discriminant of&",
10301 N
, Entity
(Subtype_Mark
(Indic
)));
10305 end Accessibility_Message
;
10307 ----------------------------------
10308 -- Declared_Within_Generic_Unit --
10309 ----------------------------------
10311 function Declared_Within_Generic_Unit
10312 (Entity
: Entity_Id
;
10313 Generic_Unit
: Node_Id
) return Boolean
10315 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
10318 while Present
(Generic_Encloser
) loop
10319 if Generic_Encloser
= Generic_Unit
then
10323 -- We have to step to the scope of the generic's entity, because
10324 -- otherwise we'll just get back the same generic.
10326 Generic_Encloser
:=
10327 Enclosing_Generic_Unit
10328 (Scope
(Defining_Entity
(Generic_Encloser
)));
10332 end Declared_Within_Generic_Unit
;
10334 -- Start of processing for Resolve_Attribute
10337 -- If error during analysis, no point in continuing, except for array
10338 -- types, where we get better recovery by using unconstrained indexes
10339 -- than nothing at all (see Check_Array_Type).
10341 if Error_Posted
(N
)
10342 and then Attr_Id
/= Attribute_First
10343 and then Attr_Id
/= Attribute_Last
10344 and then Attr_Id
/= Attribute_Length
10345 and then Attr_Id
/= Attribute_Range
10350 -- If attribute was universal type, reset to actual type
10352 if Etype
(N
) = Universal_Integer
10353 or else Etype
(N
) = Universal_Real
10355 Set_Etype
(N
, Typ
);
10358 -- Remaining processing depends on attribute
10366 -- For access attributes, if the prefix denotes an entity, it is
10367 -- interpreted as a name, never as a call. It may be overloaded,
10368 -- in which case resolution uses the profile of the context type.
10369 -- Otherwise prefix must be resolved.
10371 when Attribute_Access
10372 | Attribute_Unchecked_Access
10373 | Attribute_Unrestricted_Access
10375 -- Note possible modification if we have a variable
10377 if Is_Variable
(P
) then
10379 PN
: constant Node_Id
:= Parent
(N
);
10382 Note
: Boolean := True;
10383 -- Skip this for the case of Unrestricted_Access occuring in
10384 -- the context of a Valid check, since this otherwise leads
10385 -- to a missed warning (the Valid check does not really
10386 -- modify!) If this case, Note will be reset to False.
10388 -- Skip it as well if the type is an Acccess_To_Constant,
10389 -- given that no use of the value can modify the prefix.
10392 if Attr_Id
= Attribute_Unrestricted_Access
10393 and then Nkind
(PN
) = N_Function_Call
10397 if Nkind
(Nm
) = N_Expanded_Name
10398 and then Chars
(Nm
) = Name_Valid
10399 and then Nkind
(Prefix
(Nm
)) = N_Identifier
10400 and then Chars
(Prefix
(Nm
)) = Name_Attr_Long_Float
10405 elsif Is_Access_Constant
(Typ
) then
10410 Note_Possible_Modification
(P
, Sure
=> False);
10415 -- The following comes from a query concerning improper use of
10416 -- universal_access in equality tests involving anonymous access
10417 -- types. Another good reason for 'Ref, but for now disable the
10418 -- test, which breaks several filed tests???
10420 if Ekind
(Typ
) = E_Anonymous_Access_Type
10421 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
10424 Error_Msg_N
("need unique type to resolve 'Access", N
);
10425 Error_Msg_N
("\qualify attribute with some access type", N
);
10428 -- Case where prefix is an entity name
10430 if Is_Entity_Name
(P
) then
10432 -- Deal with case where prefix itself is overloaded
10434 if Is_Overloaded
(P
) then
10435 Get_First_Interp
(P
, Index
, It
);
10436 while Present
(It
.Nam
) loop
10437 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
10438 Set_Entity
(P
, It
.Nam
);
10440 -- The prefix is definitely NOT overloaded anymore at
10441 -- this point, so we reset the Is_Overloaded flag to
10442 -- avoid any confusion when reanalyzing the node.
10444 Set_Is_Overloaded
(P
, False);
10445 Set_Is_Overloaded
(N
, False);
10446 Generate_Reference
(Entity
(P
), P
);
10450 Get_Next_Interp
(Index
, It
);
10453 -- If Prefix is a subprogram name, this reference freezes,
10454 -- but not if within spec expression mode. The profile of
10455 -- the subprogram is not frozen at this point.
10457 if not In_Spec_Expression
then
10458 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10461 -- If it is a type, there is nothing to resolve.
10462 -- If it is a subprogram, do not freeze its profile.
10463 -- If it is an object, complete its resolution.
10465 elsif Is_Overloadable
(Entity
(P
)) then
10466 if not In_Spec_Expression
then
10467 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10470 -- Nothing to do if prefix is a type name
10472 elsif Is_Type
(Entity
(P
)) then
10475 -- Otherwise non-overloaded other case, resolve the prefix
10481 -- Some further error checks
10483 Error_Msg_Name_1
:= Aname
;
10485 if not Is_Entity_Name
(P
) then
10488 elsif Is_Overloadable
(Entity
(P
))
10489 and then Is_Abstract_Subprogram
(Entity
(P
))
10491 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
10492 Set_Etype
(N
, Any_Type
);
10494 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
10496 ("prefix of % attribute cannot be enumeration literal", P
);
10497 Set_Etype
(N
, Any_Type
);
10499 -- An attempt to take 'Access of a function that renames an
10500 -- enumeration literal. Issue a specialized error message.
10502 elsif Ekind
(Entity
(P
)) = E_Function
10503 and then Present
(Alias
(Entity
(P
)))
10504 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
10507 ("prefix of % attribute cannot be function renaming "
10508 & "an enumeration literal", P
);
10509 Set_Etype
(N
, Any_Type
);
10511 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
10512 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
10513 Set_Etype
(N
, Any_Type
);
10516 -- Assignments, return statements, components of aggregates,
10517 -- generic instantiations will require convention checks if
10518 -- the type is an access to subprogram. Given that there will
10519 -- also be accessibility checks on those, this is where the
10520 -- checks can eventually be centralized ???
10522 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10523 E_Access_Subprogram_Type
,
10524 E_Anonymous_Access_Protected_Subprogram_Type
,
10525 E_Anonymous_Access_Subprogram_Type
)
10527 -- Deal with convention mismatch
10529 if Convention
(Designated_Type
(Btyp
)) /=
10530 Convention
(Entity
(P
))
10532 -- The rule in 6.3.1 (8) deserves a special error
10535 if Convention
(Btyp
) = Convention_Intrinsic
10536 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
10537 and then Is_Entity_Name
(Name
(Parent
(N
)))
10538 and then Inside_A_Generic
10541 Subp
: constant Entity_Id
:=
10542 Entity
(Name
(Parent
(N
)));
10544 if Convention
(Subp
) = Convention_Intrinsic
then
10546 ("?subprogram and its formal access "
10547 & "parameters have convention Intrinsic",
10550 ("actual cannot be access attribute", N
);
10556 ("subprogram & has wrong convention", P
, Entity
(P
));
10557 Error_Msg_Sloc
:= Sloc
(Btyp
);
10558 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
10561 if not Is_Itype
(Btyp
)
10562 and then not Has_Convention_Pragma
(Btyp
)
10565 ("\probable missing pragma Convention for &",
10570 Check_Subtype_Conformant
10571 (New_Id
=> Entity
(P
),
10572 Old_Id
=> Designated_Type
(Btyp
),
10576 if Attr_Id
= Attribute_Unchecked_Access
then
10577 Error_Msg_Name_1
:= Aname
;
10579 ("attribute% cannot be applied to a subprogram", P
);
10581 elsif Aname
= Name_Unrestricted_Access
then
10582 null; -- Nothing to check
10584 -- Check the static accessibility rule of 3.10.2(32).
10585 -- This rule also applies within the private part of an
10586 -- instantiation. This rule does not apply to anonymous
10587 -- access-to-subprogram types in access parameters.
10589 elsif Attr_Id
= Attribute_Access
10590 and then not In_Instance_Body
10592 (Ekind
(Btyp
) = E_Access_Subprogram_Type
10593 or else Is_Local_Anonymous_Access
(Btyp
))
10594 and then Subprogram_Access_Level
(Entity
(P
)) >
10595 Type_Access_Level
(Btyp
)
10598 ("subprogram must not be deeper than access type", P
);
10600 -- Check the restriction of 3.10.2(32) that disallows the
10601 -- access attribute within a generic body when the ultimate
10602 -- ancestor of the type of the attribute is declared outside
10603 -- of the generic unit and the subprogram is declared within
10604 -- that generic unit. This includes any such attribute that
10605 -- occurs within the body of a generic unit that is a child
10606 -- of the generic unit where the subprogram is declared.
10608 -- The rule also prohibits applying the attribute when the
10609 -- access type is a generic formal access type (since the
10610 -- level of the actual type is not known). This restriction
10611 -- does not apply when the attribute type is an anonymous
10612 -- access-to-subprogram type. Note that this check was
10613 -- revised by AI-229, because the original Ada 95 rule
10614 -- was too lax. The original rule only applied when the
10615 -- subprogram was declared within the body of the generic,
10616 -- which allowed the possibility of dangling references).
10617 -- The rule was also too strict in some cases, in that it
10618 -- didn't permit the access to be declared in the generic
10619 -- spec, whereas the revised rule does (as long as it's not
10622 -- There are a couple of subtleties of the test for applying
10623 -- the check that are worth noting. First, we only apply it
10624 -- when the levels of the subprogram and access type are the
10625 -- same (the case where the subprogram is statically deeper
10626 -- was applied above, and the case where the type is deeper
10627 -- is always safe). Second, we want the check to apply
10628 -- within nested generic bodies and generic child unit
10629 -- bodies, but not to apply to an attribute that appears in
10630 -- the generic unit's specification. This is done by testing
10631 -- that the attribute's innermost enclosing generic body is
10632 -- not the same as the innermost generic body enclosing the
10633 -- generic unit where the subprogram is declared (we don't
10634 -- want the check to apply when the access attribute is in
10635 -- the spec and there's some other generic body enclosing
10636 -- generic). Finally, there's no point applying the check
10637 -- when within an instance, because any violations will have
10638 -- been caught by the compilation of the generic unit.
10640 -- We relax this check in Relaxed_RM_Semantics mode for
10641 -- compatibility with legacy code for use by Ada source
10642 -- code analyzers (e.g. CodePeer).
10644 elsif Attr_Id
= Attribute_Access
10645 and then not Relaxed_RM_Semantics
10646 and then not In_Instance
10647 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
10648 and then Present
(Enclosing_Generic_Body
(N
))
10649 and then Enclosing_Generic_Body
(N
) /=
10650 Enclosing_Generic_Body
10651 (Enclosing_Generic_Unit
(Entity
(P
)))
10652 and then Subprogram_Access_Level
(Entity
(P
)) =
10653 Type_Access_Level
(Btyp
)
10654 and then Ekind
(Btyp
) /=
10655 E_Anonymous_Access_Subprogram_Type
10656 and then Ekind
(Btyp
) /=
10657 E_Anonymous_Access_Protected_Subprogram_Type
10659 -- The attribute type's ultimate ancestor must be
10660 -- declared within the same generic unit as the
10661 -- subprogram is declared (including within another
10662 -- nested generic unit). The error message is
10663 -- specialized to say "ancestor" for the case where the
10664 -- access type is not its own ancestor, since saying
10665 -- simply "access type" would be very confusing.
10667 if not Declared_Within_Generic_Unit
10669 Enclosing_Generic_Unit
(Entity
(P
)))
10672 ("''Access attribute not allowed in generic body",
10675 if Root_Type
(Btyp
) = Btyp
then
10678 "access type & is declared outside " &
10679 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10682 ("\because ancestor of " &
10683 "access type & is declared outside " &
10684 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10688 ("\move ''Access to private part, or " &
10689 "(Ada 2005) use anonymous access type instead of &",
10692 -- If the ultimate ancestor of the attribute's type is
10693 -- a formal type, then the attribute is illegal because
10694 -- the actual type might be declared at a higher level.
10695 -- The error message is specialized to say "ancestor"
10696 -- for the case where the access type is not its own
10697 -- ancestor, since saying simply "access type" would be
10700 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10701 if Root_Type
(Btyp
) = Btyp
then
10703 ("access type must not be a generic formal type",
10707 ("ancestor access type must not be a generic " &
10714 -- If this is a renaming, an inherited operation, or a
10715 -- subprogram instance, use the original entity. This may make
10716 -- the node type-inconsistent, so this transformation can only
10717 -- be done if the node will not be reanalyzed. In particular,
10718 -- if it is within a default expression, the transformation
10719 -- must be delayed until the default subprogram is created for
10720 -- it, when the enclosing subprogram is frozen.
10722 if Is_Entity_Name
(P
)
10723 and then Is_Overloadable
(Entity
(P
))
10724 and then Present
(Alias
(Entity
(P
)))
10725 and then Expander_Active
10728 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10731 elsif Nkind
(P
) = N_Selected_Component
10732 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10734 -- Protected operation. If operation is overloaded, must
10735 -- disambiguate. Prefix that denotes protected object itself
10736 -- is resolved with its own type.
10738 if Attr_Id
= Attribute_Unchecked_Access
then
10739 Error_Msg_Name_1
:= Aname
;
10741 ("attribute% cannot be applied to protected operation", P
);
10744 Resolve
(Prefix
(P
));
10745 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10747 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10748 -- statically illegal if F is an anonymous access to subprogram.
10750 elsif Nkind
(P
) = N_Explicit_Dereference
10751 and then Is_Entity_Name
(Prefix
(P
))
10752 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10753 E_Anonymous_Access_Subprogram_Type
10755 Error_Msg_N
("anonymous access to subprogram "
10756 & "has deeper accessibility than any master", P
);
10758 elsif Is_Overloaded
(P
) then
10760 -- Use the designated type of the context to disambiguate
10761 -- Note that this was not strictly conformant to Ada 95,
10762 -- but was the implementation adopted by most Ada 95 compilers.
10763 -- The use of the context type to resolve an Access attribute
10764 -- reference is now mandated in AI-235 for Ada 2005.
10767 Index
: Interp_Index
;
10771 Get_First_Interp
(P
, Index
, It
);
10772 while Present
(It
.Typ
) loop
10773 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10774 Resolve
(P
, It
.Typ
);
10778 Get_Next_Interp
(Index
, It
);
10785 -- X'Access is illegal if X denotes a constant and the access type
10786 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10787 -- does not apply to 'Unrestricted_Access. If the reference is a
10788 -- default-initialized aggregate component for a self-referential
10789 -- type the reference is legal.
10791 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10792 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10793 or else (Is_Record_Type
(Btyp
)
10795 Present
(Corresponding_Remote_Type
(Btyp
)))
10796 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10797 or else Ekind
(Btyp
)
10798 = E_Anonymous_Access_Protected_Subprogram_Type
10799 or else Is_Access_Constant
(Btyp
)
10800 or else Is_Variable
(P
)
10801 or else Attr_Id
= Attribute_Unrestricted_Access
)
10803 if Is_Entity_Name
(P
)
10804 and then Is_Type
(Entity
(P
))
10806 -- Legality of a self-reference through an access
10807 -- attribute has been verified in Analyze_Access_Attribute.
10811 elsif Comes_From_Source
(N
) then
10812 Error_Msg_F
("access-to-variable designates constant", P
);
10816 Des_Btyp
:= Designated_Type
(Btyp
);
10818 if Ada_Version
>= Ada_2005
10819 and then Is_Incomplete_Type
(Des_Btyp
)
10821 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10822 -- imported entity, and the non-limited view is visible, make
10823 -- use of it. If it is an incomplete subtype, use the base type
10826 if From_Limited_With
(Des_Btyp
)
10827 and then Present
(Non_Limited_View
(Des_Btyp
))
10829 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10831 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10832 Des_Btyp
:= Etype
(Des_Btyp
);
10836 if (Attr_Id
= Attribute_Access
10838 Attr_Id
= Attribute_Unchecked_Access
)
10839 and then (Ekind
(Btyp
) = E_General_Access_Type
10840 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10842 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10843 -- access types for stand-alone objects, record and array
10844 -- components, and return objects. For a component definition
10845 -- the level is the same of the enclosing composite type.
10847 if Ada_Version
>= Ada_2005
10848 and then (Is_Local_Anonymous_Access
(Btyp
)
10850 -- Handle cases where Btyp is the anonymous access
10851 -- type of an Ada 2012 stand-alone object.
10853 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10854 N_Object_Declaration
)
10856 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10857 and then Attr_Id
= Attribute_Access
10859 -- In an instance, this is a runtime check, but one we know
10860 -- will fail, so generate an appropriate warning. As usual,
10861 -- this kind of warning is an error in SPARK mode.
10863 if In_Instance_Body
then
10864 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10866 ("non-local pointer cannot point to local object<<", P
);
10867 Error_Msg_F
("\Program_Error [<<", P
);
10870 Make_Raise_Program_Error
(Loc
,
10871 Reason
=> PE_Accessibility_Check_Failed
));
10872 Set_Etype
(N
, Typ
);
10876 ("non-local pointer cannot point to local object", P
);
10880 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10882 ("illegal attribute for discriminant-dependent component",
10886 -- Check static matching rule of 3.10.2(27). Nominal subtype
10887 -- of the prefix must statically match the designated type.
10889 Nom_Subt
:= Etype
(P
);
10891 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10892 Nom_Subt
:= Base_Type
(Nom_Subt
);
10895 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10897 -- If the attribute is in the context of an access
10898 -- parameter, then the prefix is allowed to be of
10899 -- the class-wide type (by AI-127).
10901 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10902 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10903 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10909 Desig
:= Designated_Type
(Typ
);
10911 if Is_Class_Wide_Type
(Desig
) then
10912 Desig
:= Etype
(Desig
);
10915 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10920 ("type of prefix: & not compatible",
10923 ("\with &, the expected designated type",
10924 P
, Designated_Type
(Typ
));
10929 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10931 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10932 and then Is_Class_Wide_Type
(Nom_Subt
))
10935 ("type of prefix: & is not covered", P
, Nom_Subt
);
10937 ("\by &, the expected designated type" &
10938 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10941 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10942 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10943 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10944 and then Designated_Type
(Typ
) /= Nom_Subt
10946 Apply_Discriminant_Check
10947 (N
, Etype
(Designated_Type
(Typ
)));
10950 -- Ada 2005 (AI-363): Require static matching when designated
10951 -- type has discriminants and a constrained partial view, since
10952 -- in general objects of such types are mutable, so we can't
10953 -- allow the access value to designate a constrained object
10954 -- (because access values must be assumed to designate mutable
10955 -- objects when designated type does not impose a constraint).
10957 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10960 elsif Has_Discriminants
(Designated_Type
(Typ
))
10961 and then not Is_Constrained
(Des_Btyp
)
10963 (Ada_Version
< Ada_2005
10965 not Object_Type_Has_Constrained_Partial_View
10966 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10967 Scop
=> Current_Scope
))
10973 ("object subtype must statically match "
10974 & "designated subtype", P
);
10976 if Is_Entity_Name
(P
)
10977 and then Is_Array_Type
(Designated_Type
(Typ
))
10980 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10983 ("aliased object has explicit bounds??", D
);
10985 ("\declare without bounds (and with explicit "
10986 & "initialization)??", D
);
10988 ("\for use with unconstrained access??", D
);
10993 -- Check the static accessibility rule of 3.10.2(28). Note that
10994 -- this check is not performed for the case of an anonymous
10995 -- access type, since the access attribute is always legal
10996 -- in such a context.
10998 if Attr_Id
/= Attribute_Unchecked_Access
10999 and then Ekind
(Btyp
) = E_General_Access_Type
11001 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
11003 Accessibility_Message
;
11008 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
11009 E_Anonymous_Access_Protected_Subprogram_Type
)
11011 if Is_Entity_Name
(P
)
11012 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
11014 Error_Msg_F
("context requires a protected subprogram", P
);
11016 -- Check accessibility of protected object against that of the
11017 -- access type, but only on user code, because the expander
11018 -- creates access references for handlers. If the context is an
11019 -- anonymous_access_to_protected, there are no accessibility
11020 -- checks either. Omit check entirely for Unrestricted_Access.
11022 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
11023 and then Comes_From_Source
(N
)
11024 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11025 and then Attr_Id
/= Attribute_Unrestricted_Access
11027 Accessibility_Message
;
11030 -- AI05-0225: If the context is not an access to protected
11031 -- function, the prefix must be a variable, given that it may
11032 -- be used subsequently in a protected call.
11034 elsif Nkind
(P
) = N_Selected_Component
11035 and then not Is_Variable
(Prefix
(P
))
11036 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
11039 ("target object of access to protected procedure "
11040 & "must be variable", N
);
11042 elsif Is_Entity_Name
(P
) then
11043 Check_Internal_Protected_Use
(N
, Entity
(P
));
11046 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
11047 E_Anonymous_Access_Subprogram_Type
)
11048 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
11050 Error_Msg_F
("context requires a non-protected subprogram", P
);
11053 -- The context cannot be a pool-specific type, but this is a
11054 -- legality rule, not a resolution rule, so it must be checked
11055 -- separately, after possibly disambiguation (see AI-245).
11057 if Ekind
(Btyp
) = E_Access_Type
11058 and then Attr_Id
/= Attribute_Unrestricted_Access
11060 Wrong_Type
(N
, Typ
);
11063 -- The context may be a constrained access type (however ill-
11064 -- advised such subtypes might be) so in order to generate a
11065 -- constraint check when needed set the type of the attribute
11066 -- reference to the base type of the context.
11068 Set_Etype
(N
, Btyp
);
11070 -- Check for incorrect atomic/volatile reference (RM C.6(12))
11072 if Attr_Id
/= Attribute_Unrestricted_Access
then
11073 if Is_Atomic_Object
(P
)
11074 and then not Is_Atomic
(Designated_Type
(Typ
))
11077 ("access to atomic object cannot yield access-to-" &
11078 "non-atomic type", P
);
11080 elsif Is_Volatile_Object
(P
)
11081 and then not Is_Volatile
(Designated_Type
(Typ
))
11084 ("access to volatile object cannot yield access-to-" &
11085 "non-volatile type", P
);
11089 -- Check for aliased view. We allow a nonaliased prefix when in
11090 -- an instance because the prefix may have been a tagged formal
11091 -- object, which is defined to be aliased even when the actual
11092 -- might not be (other instance cases will have been caught in
11093 -- the generic). Similarly, within an inlined body we know that
11094 -- the attribute is legal in the original subprogram, therefore
11095 -- legal in the expansion.
11097 if not (Is_Entity_Name
(P
)
11098 and then Is_Overloadable
(Entity
(P
)))
11099 and then not (Nkind
(P
) = N_Selected_Component
11101 Is_Overloadable
(Entity
(Selector_Name
(P
))))
11102 and then not Is_Aliased_View
(P
)
11103 and then not In_Instance
11104 and then not In_Inlined_Body
11105 and then Comes_From_Source
(N
)
11107 -- Here we have a non-aliased view. This is illegal unless we
11108 -- have the case of Unrestricted_Access, where for now we allow
11109 -- this (we will reject later if expected type is access to an
11110 -- unconstrained array with a thin pointer).
11112 -- No need for an error message on a generated access reference
11113 -- for the controlling argument in a dispatching call: error
11114 -- will be reported when resolving the call.
11116 if Attr_Id
/= Attribute_Unrestricted_Access
then
11117 Error_Msg_N
("prefix of % attribute must be aliased", P
);
11119 -- Check for unrestricted access where expected type is a thin
11120 -- pointer to an unconstrained array.
11122 elsif Has_Size_Clause
(Typ
)
11123 and then RM_Size
(Typ
) = System_Address_Size
11126 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
11128 if Is_Array_Type
(DT
)
11129 and then not Is_Constrained
(DT
)
11132 ("illegal use of Unrestricted_Access attribute", P
);
11134 ("\attempt to generate thin pointer to unaliased "
11141 -- Mark that address of entity is taken in case of
11142 -- 'Unrestricted_Access or in case of a subprogram.
11144 if Is_Entity_Name
(P
)
11145 and then (Attr_Id
= Attribute_Unrestricted_Access
11146 or else Is_Subprogram
(Entity
(P
)))
11148 Set_Address_Taken
(Entity
(P
));
11151 -- Deal with possible elaboration check
11153 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
11155 Subp_Id
: constant Entity_Id
:= Entity
(P
);
11156 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
11157 Subp_Decl
: constant Node_Id
:=
11158 Unit_Declaration_Node
(Subp_Id
);
11159 Flag_Id
: Entity_Id
;
11160 Subp_Body
: Node_Id
;
11162 -- If the access has been taken and the body of the subprogram
11163 -- has not been see yet, indirect calls must be protected with
11164 -- elaboration checks. We have the proper elaboration machinery
11165 -- for subprograms declared in packages, but within a block or
11166 -- a subprogram the body will appear in the same declarative
11167 -- part, and we must insert a check in the eventual body itself
11168 -- using the elaboration flag that we generate now. The check
11169 -- is then inserted when the body is expanded. This processing
11170 -- is not needed for a stand alone expression function because
11171 -- the internally generated spec and body are always inserted
11172 -- as a pair in the same declarative list.
11176 and then Comes_From_Source
(Subp_Id
)
11177 and then Comes_From_Source
(N
)
11178 and then In_Open_Scopes
(Scop
)
11179 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
11180 and then not Has_Completion
(Subp_Id
)
11181 and then No
(Elaboration_Entity
(Subp_Id
))
11182 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11183 and then Nkind
(Original_Node
(Subp_Decl
)) /=
11184 N_Expression_Function
11186 -- Create elaboration variable for it
11188 Flag_Id
:= Make_Temporary
(Loc
, 'E');
11189 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
11190 Set_Is_Frozen
(Flag_Id
);
11192 -- Insert declaration for flag after subprogram
11193 -- declaration. Note that attribute reference may
11194 -- appear within a nested scope.
11196 Insert_After_And_Analyze
(Subp_Decl
,
11197 Make_Object_Declaration
(Loc
,
11198 Defining_Identifier
=> Flag_Id
,
11199 Object_Definition
=>
11200 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
11202 Make_Integer_Literal
(Loc
, Uint_0
)));
11205 -- Taking the 'Access of an expression function freezes its
11206 -- expression (RM 13.14 10.3/3). This does not apply to an
11207 -- expression function that acts as a completion because the
11208 -- generated body is immediately analyzed and the expression
11209 -- is automatically frozen.
11211 if Is_Expression_Function
(Subp_Id
)
11212 and then Present
(Corresponding_Body
(Subp_Decl
))
11215 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
11217 -- The body has already been analyzed when the expression
11218 -- function acts as a completion.
11220 if Analyzed
(Subp_Body
) then
11223 -- Attribute 'Access may appear within the generated body
11224 -- of the expression function subject to the attribute:
11226 -- function F is (... F'Access ...);
11228 -- If the expression function is on the scope stack, then
11229 -- the body is currently being analyzed. Do not reanalyze
11230 -- it because this will lead to infinite recursion.
11232 elsif In_Open_Scopes
(Subp_Id
) then
11235 -- If reference to the expression function appears in an
11236 -- inner scope, for example as an actual in an instance,
11237 -- this is not a freeze point either.
11239 elsif Scope
(Subp_Id
) /= Current_Scope
then
11242 -- Analyze the body of the expression function to freeze
11243 -- the expression. This takes care of the case where the
11244 -- 'Access is part of dispatch table initialization and
11245 -- the generated body of the expression function has not
11246 -- been analyzed yet.
11249 Analyze
(Subp_Body
);
11259 -- Deal with resolving the type for Address attribute, overloading
11260 -- is not permitted here, since there is no context to resolve it.
11262 when Attribute_Address
11263 | Attribute_Code_Address
11265 -- To be safe, assume that if the address of a variable is taken,
11266 -- it may be modified via this address, so note modification.
11268 if Is_Variable
(P
) then
11269 Note_Possible_Modification
(P
, Sure
=> False);
11272 if Nkind
(P
) in N_Subexpr
11273 and then Is_Overloaded
(P
)
11275 Get_First_Interp
(P
, Index
, It
);
11276 Get_Next_Interp
(Index
, It
);
11278 if Present
(It
.Nam
) then
11279 Error_Msg_Name_1
:= Aname
;
11281 ("prefix of % attribute cannot be overloaded", P
);
11285 if not Is_Entity_Name
(P
)
11286 or else not Is_Overloadable
(Entity
(P
))
11288 if not Is_Task_Type
(Etype
(P
))
11289 or else Nkind
(P
) = N_Explicit_Dereference
11295 -- If this is the name of a derived subprogram, or that of a
11296 -- generic actual, the address is that of the original entity.
11298 if Is_Entity_Name
(P
)
11299 and then Is_Overloadable
(Entity
(P
))
11300 and then Present
(Alias
(Entity
(P
)))
11303 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11306 if Is_Entity_Name
(P
) then
11307 Set_Address_Taken
(Entity
(P
));
11310 if Nkind
(P
) = N_Slice
then
11312 -- Arr (X .. Y)'address is identical to Arr (X)'address,
11313 -- even if the array is packed and the slice itself is not
11314 -- addressable. Transform the prefix into an indexed component.
11316 -- Note that the transformation is safe only if we know that
11317 -- the slice is non-null. That is because a null slice can have
11318 -- an out of bounds index value.
11320 -- Right now, gigi blows up if given 'Address on a slice as a
11321 -- result of some incorrect freeze nodes generated by the front
11322 -- end, and this covers up that bug in one case, but the bug is
11323 -- likely still there in the cases not handled by this code ???
11325 -- It's not clear what 'Address *should* return for a null
11326 -- slice with out of bounds indexes, this might be worth an ARG
11329 -- One approach would be to do a length check unconditionally,
11330 -- and then do the transformation below unconditionally, but
11331 -- analyze with checks off, avoiding the problem of the out of
11332 -- bounds index. This approach would interpret the address of
11333 -- an out of bounds null slice as being the address where the
11334 -- array element would be if there was one, which is probably
11335 -- as reasonable an interpretation as any ???
11338 Loc
: constant Source_Ptr
:= Sloc
(P
);
11339 D
: constant Node_Id
:= Discrete_Range
(P
);
11343 if Is_Entity_Name
(D
)
11346 (Type_Low_Bound
(Entity
(D
)),
11347 Type_High_Bound
(Entity
(D
)))
11350 Make_Attribute_Reference
(Loc
,
11351 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
11352 Attribute_Name
=> Name_First
);
11354 elsif Nkind
(D
) = N_Range
11355 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
11357 Lo
:= Low_Bound
(D
);
11363 if Present
(Lo
) then
11365 Make_Indexed_Component
(Loc
,
11366 Prefix
=> Relocate_Node
(Prefix
(P
)),
11367 Expressions
=> New_List
(Lo
)));
11369 Analyze_And_Resolve
(P
);
11378 -- Prefix of Body_Version attribute can be a subprogram name which
11379 -- must not be resolved, since this is not a call.
11381 when Attribute_Body_Version
=>
11388 -- Prefix of Caller attribute is an entry name which must not
11389 -- be resolved, since this is definitely not an entry call.
11391 when Attribute_Caller
=>
11398 -- Shares processing with Address attribute
11404 -- If the prefix of the Count attribute is an entry name it must not
11405 -- be resolved, since this is definitely not an entry call. However,
11406 -- if it is an element of an entry family, the index itself may
11407 -- have to be resolved because it can be a general expression.
11409 when Attribute_Count
=>
11410 if Nkind
(P
) = N_Indexed_Component
11411 and then Is_Entity_Name
(Prefix
(P
))
11414 Indx
: constant Node_Id
:= First
(Expressions
(P
));
11415 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
11417 Resolve
(Indx
, Entry_Index_Type
(Fam
));
11418 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
11426 -- Prefix of the Elaborated attribute is a subprogram name which
11427 -- must not be resolved, since this is definitely not a call. Note
11428 -- that it is a library unit, so it cannot be overloaded here.
11430 when Attribute_Elaborated
=>
11437 -- Prefix of Enabled attribute is a check name, which must be treated
11438 -- specially and not touched by Resolve.
11440 when Attribute_Enabled
=>
11447 -- Do not resolve the prefix of Loop_Entry, instead wait until the
11448 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
11449 -- The delay ensures that any generated checks or temporaries are
11450 -- inserted before the relocated prefix.
11452 when Attribute_Loop_Entry
=>
11455 --------------------
11456 -- Mechanism_Code --
11457 --------------------
11459 -- Prefix of the Mechanism_Code attribute is a function name
11460 -- which must not be resolved. Should we check for overloaded ???
11462 when Attribute_Mechanism_Code
=>
11469 -- Most processing is done in sem_dist, after determining the
11470 -- context type. Node is rewritten as a conversion to a runtime call.
11472 when Attribute_Partition_ID
=>
11473 Process_Partition_Id
(N
);
11480 when Attribute_Pool_Address
=>
11487 -- We replace the Range attribute node with a range expression whose
11488 -- bounds are the 'First and 'Last attributes applied to the same
11489 -- prefix. The reason that we do this transformation here instead of
11490 -- in the expander is that it simplifies other parts of the semantic
11491 -- analysis which assume that the Range has been replaced; thus it
11492 -- must be done even when in semantic-only mode (note that the RM
11493 -- specifically mentions this equivalence, we take care that the
11494 -- prefix is only evaluated once).
11496 when Attribute_Range
=> Range_Attribute
: declare
11502 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11506 Dims
:= Expressions
(N
);
11509 Make_Attribute_Reference
(Loc
,
11510 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
11511 Attribute_Name
=> Name_Last
,
11512 Expressions
=> Dims
);
11515 Make_Attribute_Reference
(Loc
,
11517 Attribute_Name
=> Name_First
,
11518 Expressions
=> (Dims
));
11520 -- Do not share the dimension indicator, if present. Even though
11521 -- it is a static constant, its source location may be modified
11522 -- when printing expanded code and node sharing will lead to chaos
11525 if Present
(Dims
) then
11526 Set_Expressions
(LB
, New_List
(New_Copy_Tree
(First
(Dims
))));
11529 -- If the original was marked as Must_Not_Freeze (see code in
11530 -- Sem_Ch3.Make_Index), then make sure the rewriting does not
11533 if Must_Not_Freeze
(N
) then
11534 Set_Must_Not_Freeze
(HB
);
11535 Set_Must_Not_Freeze
(LB
);
11536 Set_Must_Not_Freeze
(Prefix
(HB
));
11537 Set_Must_Not_Freeze
(Prefix
(LB
));
11540 if Raises_Constraint_Error
(Prefix
(N
)) then
11542 -- Preserve Sloc of prefix in the new bounds, so that the
11543 -- posted warning can be removed if we are within unreachable
11546 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
11547 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
11550 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
11551 Analyze_And_Resolve
(N
, Typ
);
11553 -- Ensure that the expanded range does not have side effects
11555 Force_Evaluation
(LB
);
11556 Force_Evaluation
(HB
);
11558 -- Normally after resolving attribute nodes, Eval_Attribute
11559 -- is called to do any possible static evaluation of the node.
11560 -- However, here since the Range attribute has just been
11561 -- transformed into a range expression it is no longer an
11562 -- attribute node and therefore the call needs to be avoided
11563 -- and is accomplished by simply returning from the procedure.
11566 end Range_Attribute
;
11572 -- We will only come here during the prescan of a spec expression
11573 -- containing a Result attribute. In that case the proper Etype has
11574 -- already been set, and nothing more needs to be done here.
11576 when Attribute_Result
=>
11579 ----------------------
11580 -- Unchecked_Access --
11581 ----------------------
11583 -- Processing is shared with Access
11585 -------------------------
11586 -- Unrestricted_Access --
11587 -------------------------
11589 -- Processing is shared with Access
11595 -- Resolve aggregate components in component associations
11597 when Attribute_Update
=> Update
: declare
11598 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
11599 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
11605 -- Set the Etype of the aggregate to that of the prefix, even
11606 -- though the aggregate may not be a proper representation of a
11607 -- value of the type (missing or duplicated associations, etc.)
11608 -- Complete resolution of the prefix. Note that in Ada 2012 it
11609 -- can be a qualified expression that is e.g. an aggregate.
11611 Set_Etype
(Aggr
, Typ
);
11612 Resolve
(Prefix
(N
), Typ
);
11614 -- For an array type, resolve expressions with the component type
11615 -- of the array, and apply constraint checks when needed.
11617 if Is_Array_Type
(Typ
) then
11618 Assoc
:= First
(Component_Associations
(Aggr
));
11619 while Present
(Assoc
) loop
11620 Expr
:= Expression
(Assoc
);
11621 Resolve
(Expr
, Component_Type
(Typ
));
11623 -- For scalar array components set Do_Range_Check when
11624 -- needed. Constraint checking on non-scalar components
11625 -- is done in Aggregate_Constraint_Checks, but only if
11626 -- full analysis is enabled. These flags are not set in
11627 -- the front-end in GnatProve mode.
11629 if Is_Scalar_Type
(Component_Type
(Typ
))
11630 and then not Is_OK_Static_Expression
(Expr
)
11631 and then not Range_Checks_Suppressed
(Component_Type
(Typ
))
11633 if Is_Entity_Name
(Expr
)
11634 and then Etype
(Expr
) = Component_Type
(Typ
)
11639 Set_Do_Range_Check
(Expr
);
11643 -- The choices in the association are static constants,
11644 -- or static aggregates each of whose components belongs
11645 -- to the proper index type. However, they must also
11646 -- belong to the index subtype (s) of the prefix, which
11647 -- may be a subtype (e.g. given by a slice).
11649 -- Choices may also be identifiers with no staticness
11650 -- requirements, in which case they must resolve to the
11659 C
:= First
(Choices
(Assoc
));
11660 while Present
(C
) loop
11661 Indx
:= First_Index
(Etype
(Prefix
(N
)));
11663 if Nkind
(C
) /= N_Aggregate
then
11664 Analyze_And_Resolve
(C
, Etype
(Indx
));
11665 Apply_Constraint_Check
(C
, Etype
(Indx
));
11666 Check_Non_Static_Context
(C
);
11669 C_E
:= First
(Expressions
(C
));
11670 while Present
(C_E
) loop
11671 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
11672 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
11673 Check_Non_Static_Context
(C_E
);
11687 -- For a record type, use type of each component, which is
11688 -- recorded during analysis.
11691 Assoc
:= First
(Component_Associations
(Aggr
));
11692 while Present
(Assoc
) loop
11693 Comp
:= First
(Choices
(Assoc
));
11694 Expr
:= Expression
(Assoc
);
11696 if Nkind
(Comp
) /= N_Others_Choice
11697 and then not Error_Posted
(Comp
)
11699 Resolve
(Expr
, Etype
(Entity
(Comp
)));
11701 if Is_Scalar_Type
(Etype
(Entity
(Comp
)))
11702 and then not Is_OK_Static_Expression
(Expr
)
11703 and then not Range_Checks_Suppressed
11704 (Etype
(Entity
(Comp
)))
11706 Set_Do_Range_Check
(Expr
);
11719 -- Apply range check. Note that we did not do this during the
11720 -- analysis phase, since we wanted Eval_Attribute to have a
11721 -- chance at finding an illegal out of range value.
11723 when Attribute_Val
=>
11725 -- Note that we do our own Eval_Attribute call here rather than
11726 -- use the common one, because we need to do processing after
11727 -- the call, as per above comment.
11729 Eval_Attribute
(N
);
11731 -- Eval_Attribute may replace the node with a raise CE, or
11732 -- fold it to a constant. Obviously we only apply a scalar
11733 -- range check if this did not happen.
11735 if Nkind
(N
) = N_Attribute_Reference
11736 and then Attribute_Name
(N
) = Name_Val
11738 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11747 -- Prefix of Version attribute can be a subprogram name which
11748 -- must not be resolved, since this is not a call.
11750 when Attribute_Version
=>
11753 ----------------------
11754 -- Other Attributes --
11755 ----------------------
11757 -- For other attributes, resolve prefix unless it is a type. If
11758 -- the attribute reference itself is a type name ('Base and 'Class)
11759 -- then this is only legal within a task or protected record.
11762 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11766 -- If the attribute reference itself is a type name ('Base,
11767 -- 'Class) then this is only legal within a task or protected
11768 -- record. What is this all about ???
11770 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11771 if Is_Concurrent_Type
(Entity
(N
))
11772 and then In_Open_Scopes
(Entity
(P
))
11777 ("invalid use of subtype name in expression or call", N
);
11781 -- For attributes whose argument may be a string, complete
11782 -- resolution of argument now. This avoids premature expansion
11783 -- (and the creation of transient scopes) before the attribute
11784 -- reference is resolved.
11787 when Attribute_Value
=>
11788 Resolve
(First
(Expressions
(N
)), Standard_String
);
11790 when Attribute_Wide_Value
=>
11791 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11793 when Attribute_Wide_Wide_Value
=>
11794 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11796 when others => null;
11799 -- If the prefix of the attribute is a class-wide type then it
11800 -- will be expanded into a dispatching call to a predefined
11801 -- primitive. Therefore we must check for potential violation
11802 -- of such restriction.
11804 if Is_Class_Wide_Type
(Etype
(P
)) then
11805 Check_Restriction
(No_Dispatching_Calls
, N
);
11809 -- Mark use clauses of the original prefix if the attribute is applied
11812 if Nkind
(Original_Node
(P
)) in N_Has_Entity
11813 and then Present
(Entity
(Original_Node
(P
)))
11815 Mark_Use_Clauses
(Original_Node
(P
));
11818 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11819 -- is not resolved, in which case the freezing must be done now.
11821 -- For an elaboration check on a subprogram, we do not freeze its type.
11822 -- It may be declared in an unrelated scope, in particular in the case
11823 -- of a generic function whose type may remain unelaborated.
11825 if Attr_Id
= Attribute_Elaborated
then
11829 Freeze_Expression
(P
);
11832 -- Finally perform static evaluation on the attribute reference
11834 Analyze_Dimension
(N
);
11835 Eval_Attribute
(N
);
11836 end Resolve_Attribute
;
11838 ------------------------
11839 -- Set_Boolean_Result --
11840 ------------------------
11842 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11843 Loc
: constant Source_Ptr
:= Sloc
(N
);
11846 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11848 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11850 end Set_Boolean_Result
;
11852 -------------------------------
11853 -- Statically_Denotes_Object --
11854 -------------------------------
11856 function Statically_Denotes_Object
(N
: Node_Id
) return Boolean is
11860 if Is_Entity_Name
(N
) then
11863 elsif Nkind
(N
) = N_Selected_Component
11864 and then Statically_Denotes_Object
(Prefix
(N
))
11865 and then Present
(Entity
(Selector_Name
(N
)))
11868 Sel_Id
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
11869 Comp_Decl
: constant Node_Id
:= Parent
(Sel_Id
);
11872 if Depends_On_Discriminant
(Sel_Id
) then
11875 elsif Nkind
(Parent
(Parent
(Comp_Decl
))) = N_Variant
then
11883 elsif Nkind
(N
) = N_Indexed_Component
11884 and then Statically_Denotes_Object
(Prefix
(N
))
11885 and then Is_Constrained
(Etype
(Prefix
(N
)))
11887 Indx
:= First
(Expressions
(N
));
11888 while Present
(Indx
) loop
11889 if not Compile_Time_Known_Value
(Indx
)
11890 or else Do_Range_Check
(Indx
)
11903 end Statically_Denotes_Object
;
11905 --------------------------------
11906 -- Stream_Attribute_Available --
11907 --------------------------------
11909 function Stream_Attribute_Available
11911 Nam
: TSS_Name_Type
;
11912 Partial_View
: Node_Id
:= Empty
) return Boolean
11914 Etyp
: Entity_Id
:= Typ
;
11916 -- Start of processing for Stream_Attribute_Available
11919 -- We need some comments in this body ???
11921 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11925 if Is_Class_Wide_Type
(Typ
) then
11926 return not Is_Limited_Type
(Typ
)
11927 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11930 if Nam
= TSS_Stream_Input
11931 and then Is_Abstract_Type
(Typ
)
11932 and then not Is_Class_Wide_Type
(Typ
)
11937 if not (Is_Limited_Type
(Typ
)
11938 or else (Present
(Partial_View
)
11939 and then Is_Limited_Type
(Partial_View
)))
11944 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11946 if Nam
= TSS_Stream_Input
11947 and then Ada_Version
>= Ada_2005
11948 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11952 elsif Nam
= TSS_Stream_Output
11953 and then Ada_Version
>= Ada_2005
11954 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11959 -- Case of Read and Write: check for attribute definition clause that
11960 -- applies to an ancestor type.
11962 while Etype
(Etyp
) /= Etyp
loop
11963 Etyp
:= Etype
(Etyp
);
11965 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11970 if Ada_Version
< Ada_2005
then
11972 -- In Ada 95 mode, also consider a non-visible definition
11975 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11978 and then Stream_Attribute_Available
11979 (Btyp
, Nam
, Partial_View
=> Typ
);
11984 end Stream_Attribute_Available
;