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
);
235 -- Type of prefix after analysis
237 P_Base_Type
: Entity_Id
;
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
);
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 -- Signal unexpected attribute argument (En is the argument)
451 procedure Validate_Non_Static_Attribute_Function_Call
;
452 -- Called when processing an attribute that is a function call to a
453 -- non-static function, i.e. an attribute function that either takes
454 -- non-scalar arguments or returns a non-scalar result. Verifies that
455 -- such a call does not appear in a preelaborable context.
461 procedure Address_Checks
is
463 -- An Address attribute created by expansion is legal even when it
464 -- applies to other entity-denoting expressions.
466 if not Comes_From_Source
(N
) then
469 -- Address attribute on a protected object self reference is legal
471 elsif Is_Protected_Self_Reference
(P
) then
474 -- Address applied to an entity
476 elsif Is_Entity_Name
(P
) then
478 Ent
: constant Entity_Id
:= Entity
(P
);
481 if Is_Subprogram
(Ent
) then
482 Set_Address_Taken
(Ent
);
483 Kill_Current_Values
(Ent
);
485 -- An Address attribute is accepted when generated by the
486 -- compiler for dispatching operation, and an error is
487 -- issued once the subprogram is frozen (to avoid confusing
488 -- errors about implicit uses of Address in the dispatch
489 -- table initialization).
491 if Has_Pragma_Inline_Always
(Entity
(P
))
492 and then Comes_From_Source
(P
)
495 ("prefix of % attribute cannot be Inline_Always "
498 -- It is illegal to apply 'Address to an intrinsic
499 -- subprogram. This is now formalized in AI05-0095.
500 -- In an instance, an attempt to obtain 'Address of an
501 -- intrinsic subprogram (e.g the renaming of a predefined
502 -- operator that is an actual) raises Program_Error.
504 elsif Convention
(Ent
) = Convention_Intrinsic
then
507 Make_Raise_Program_Error
(Loc
,
508 Reason
=> PE_Address_Of_Intrinsic
));
511 Error_Msg_Name_1
:= Aname
;
513 ("cannot take % of intrinsic subprogram", N
);
516 -- Issue an error if prefix denotes an eliminated subprogram
519 Check_For_Eliminated_Subprogram
(P
, Ent
);
522 -- Object or label reference
524 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
525 Set_Address_Taken
(Ent
);
527 -- Deal with No_Implicit_Aliasing restriction
529 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
530 if not Is_Aliased_View
(P
) then
531 Check_Restriction
(No_Implicit_Aliasing
, P
);
533 Check_No_Implicit_Aliasing
(P
);
537 -- If we have an address of an object, and the attribute
538 -- comes from source, then set the object as potentially
539 -- source modified. We do this because the resulting address
540 -- can potentially be used to modify the variable and we
541 -- might not detect this, leading to some junk warnings.
543 Set_Never_Set_In_Source
(Ent
, False);
545 -- Allow Address to be applied to task or protected type,
546 -- returning null address (what is that about???)
548 elsif (Is_Concurrent_Type
(Etype
(Ent
))
549 and then Etype
(Ent
) = Base_Type
(Ent
))
550 or else Ekind
(Ent
) = E_Package
551 or else Is_Generic_Unit
(Ent
)
554 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
556 -- Anything else is illegal
559 Error_Attr
("invalid prefix for % attribute", P
);
565 elsif Is_Object_Reference
(P
) then
568 -- Subprogram called using dot notation
570 elsif Nkind
(P
) = N_Selected_Component
571 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
575 -- What exactly are we allowing here ??? and is this properly
576 -- documented in the sinfo documentation for this node ???
578 elsif Relaxed_RM_Semantics
579 and then Nkind
(P
) = N_Attribute_Reference
583 -- All other non-entity name cases are illegal
586 Error_Attr
("invalid prefix for % attribute", P
);
590 ------------------------------
591 -- Analyze_Access_Attribute --
592 ------------------------------
594 procedure Analyze_Access_Attribute
is
595 Acc_Type
: Entity_Id
;
600 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
601 -- Build an access-to-object type whose designated type is DT,
602 -- and whose Ekind is appropriate to the attribute type. The
603 -- type that is constructed is returned as the result.
605 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
606 -- Build an access to subprogram whose designated type is the type of
607 -- the prefix. If prefix is overloaded, so is the node itself. The
608 -- result is stored in Acc_Type.
610 function OK_Self_Reference
return Boolean;
611 -- An access reference whose prefix is a type can legally appear
612 -- within an aggregate, where it is obtained by expansion of
613 -- a defaulted aggregate. The enclosing aggregate that contains
614 -- the self-referenced is flagged so that the self-reference can
615 -- be expanded into a reference to the target object (see exp_aggr).
617 ------------------------------
618 -- Build_Access_Object_Type --
619 ------------------------------
621 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
622 Typ
: constant Entity_Id
:=
624 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
626 Set_Etype
(Typ
, Typ
);
628 Set_Associated_Node_For_Itype
(Typ
, N
);
629 Set_Directly_Designated_Type
(Typ
, DT
);
631 end Build_Access_Object_Type
;
633 ----------------------------------
634 -- Build_Access_Subprogram_Type --
635 ----------------------------------
637 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
638 Index
: Interp_Index
;
641 procedure Check_Local_Access
(E
: Entity_Id
);
642 -- Deal with possible access to local subprogram. If we have such
643 -- an access, we set a flag to kill all tracked values on any call
644 -- because this access value may be passed around, and any called
645 -- code might use it to access a local procedure which clobbers a
646 -- tracked value. If the scope is a loop or block, indicate that
647 -- value tracking is disabled for the enclosing subprogram.
649 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
650 -- Distinguish between access to regular/protected subprograms
652 ------------------------
653 -- Check_Local_Access --
654 ------------------------
656 procedure Check_Local_Access
(E
: Entity_Id
) is
658 if not Is_Library_Level_Entity
(E
) then
659 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
660 Set_Suppress_Value_Tracking_On_Call
661 (Nearest_Dynamic_Scope
(Current_Scope
));
663 end Check_Local_Access
;
669 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
671 if Convention
(E
) = Convention_Protected
then
672 return E_Access_Protected_Subprogram_Type
;
674 return E_Access_Subprogram_Type
;
678 -- Start of processing for Build_Access_Subprogram_Type
681 -- In the case of an access to subprogram, use the name of the
682 -- subprogram itself as the designated type. Type-checking in
683 -- this case compares the signatures of the designated types.
685 -- Note: This fragment of the tree is temporarily malformed
686 -- because the correct tree requires an E_Subprogram_Type entity
687 -- as the designated type. In most cases this designated type is
688 -- later overridden by the semantics with the type imposed by the
689 -- context during the resolution phase. In the specific case of
690 -- the expression Address!(Prim'Unrestricted_Access), used to
691 -- initialize slots of dispatch tables, this work will be done by
692 -- the expander (see Exp_Aggr).
694 -- The reason to temporarily add this kind of node to the tree
695 -- instead of a proper E_Subprogram_Type itype, is the following:
696 -- in case of errors found in the source file we report better
697 -- error messages. For example, instead of generating the
700 -- "expected access to subprogram with profile
701 -- defined at line X"
703 -- we currently generate:
705 -- "expected access to function Z defined at line X"
707 Set_Etype
(N
, Any_Type
);
709 if not Is_Overloaded
(P
) then
710 Check_Local_Access
(Entity
(P
));
712 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
713 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
714 Set_Is_Public
(Acc_Type
, False);
715 Set_Etype
(Acc_Type
, Acc_Type
);
716 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
717 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
718 Set_Etype
(N
, Acc_Type
);
719 Freeze_Before
(N
, Acc_Type
);
723 Get_First_Interp
(P
, Index
, It
);
724 while Present
(It
.Nam
) loop
725 Check_Local_Access
(It
.Nam
);
727 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
728 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
729 Set_Is_Public
(Acc_Type
, False);
730 Set_Etype
(Acc_Type
, Acc_Type
);
731 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
732 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
733 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
734 Freeze_Before
(N
, Acc_Type
);
737 Get_Next_Interp
(Index
, It
);
741 -- Cannot be applied to intrinsic. Looking at the tests above,
742 -- the only way Etype (N) can still be set to Any_Type is if
743 -- Is_Intrinsic_Subprogram was True for some referenced entity.
745 if Etype
(N
) = Any_Type
then
746 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
748 end Build_Access_Subprogram_Type
;
750 ----------------------
751 -- OK_Self_Reference --
752 ----------------------
754 function OK_Self_Reference
return Boolean is
761 (Nkind
(Par
) = N_Component_Association
762 or else Nkind
(Par
) in N_Subexpr
)
764 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
765 if Etype
(Par
) = Typ
then
766 Set_Has_Self_Reference
(Par
);
768 -- Check the context: the aggregate must be part of the
769 -- initialization of a type or component, or it is the
770 -- resulting expansion in an initialization procedure.
772 if Is_Init_Proc
(Current_Scope
) then
776 while Present
(Par
) loop
777 if Nkind
(Par
) = N_Full_Type_Declaration
then
792 -- No enclosing aggregate, or not a self-reference
795 end OK_Self_Reference
;
797 -- Start of processing for Analyze_Access_Attribute
800 Check_SPARK_05_Restriction_On_Attribute
;
803 if Nkind
(P
) = N_Character_Literal
then
805 ("prefix of % attribute cannot be enumeration literal");
808 -- Preserve relevant elaboration-related attributes of the context
809 -- which are no longer available or very expensive to recompute once
810 -- analysis, resolution, and expansion are over.
812 Mark_Elaboration_Attributes
817 -- Save the scenario for later examination by the ABE Processing
820 Record_Elaboration_Scenario
(N
);
822 -- Case of access to subprogram
824 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
825 if Has_Pragma_Inline_Always
(Entity
(P
)) then
827 ("prefix of % attribute cannot be Inline_Always subprogram");
829 elsif Aname
= Name_Unchecked_Access
then
830 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
833 -- Issue an error if the prefix denotes an eliminated subprogram
835 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
837 -- Check for obsolescent subprogram reference
839 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
841 -- Build the appropriate subprogram type
843 Build_Access_Subprogram_Type
(P
);
845 -- For P'Access or P'Unrestricted_Access, where P is a nested
846 -- subprogram, we might be passing P to another subprogram (but we
847 -- don't check that here), which might call P. P could modify
848 -- local variables, so we need to kill current values. It is
849 -- important not to do this for library-level subprograms, because
850 -- Kill_Current_Values is very inefficient in the case of library
851 -- level packages with lots of tagged types.
853 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
856 -- Do not kill values on nodes initializing dispatch tables
857 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
858 -- is currently generated by the expander only for this
859 -- purpose. Done to keep the quality of warnings currently
860 -- generated by the compiler (otherwise any declaration of
861 -- a tagged type cleans constant indications from its scope).
863 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
864 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
866 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
867 and then Is_Dispatching_Operation
868 (Directly_Designated_Type
(Etype
(N
)))
878 -- Component is an operation of a protected type
880 elsif Nkind
(P
) = N_Selected_Component
881 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
883 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
884 Error_Attr_P
("prefix of % attribute must be subprogram");
887 Build_Access_Subprogram_Type
(Selector_Name
(P
));
891 -- Deal with incorrect reference to a type, but note that some
892 -- accesses are allowed: references to the current type instance,
893 -- or in Ada 2005 self-referential pointer in a default-initialized
896 if Is_Entity_Name
(P
) then
899 -- The reference may appear in an aggregate that has been expanded
900 -- into a loop. Locate scope of type definition, if any.
902 Scop
:= Current_Scope
;
903 while Ekind
(Scop
) = E_Loop
loop
904 Scop
:= Scope
(Scop
);
907 if Is_Type
(Typ
) then
909 -- OK if we are within the scope of a limited type
910 -- let's mark the component as having per object constraint
912 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
920 Q
: Node_Id
:= Parent
(N
);
924 and then Nkind
(Q
) /= N_Component_Declaration
930 Set_Has_Per_Object_Constraint
931 (Defining_Identifier
(Q
), True);
935 if Nkind
(P
) = N_Expanded_Name
then
937 ("current instance prefix must be a direct name", P
);
940 -- If a current instance attribute appears in a component
941 -- constraint it must appear alone; other contexts (spec-
942 -- expressions, within a task body) are not subject to this
945 if not In_Spec_Expression
946 and then not Has_Completion
(Scop
)
948 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
949 N_Index_Or_Discriminant_Constraint
)
952 ("current instance attribute must appear alone", N
);
955 if Is_CPP_Class
(Root_Type
(Typ
)) then
957 ("??current instance unsupported for derivations of "
958 & "'C'P'P types", N
);
961 -- OK if we are in initialization procedure for the type
962 -- in question, in which case the reference to the type
963 -- is rewritten as a reference to the current object.
965 elsif Ekind
(Scop
) = E_Procedure
966 and then Is_Init_Proc
(Scop
)
967 and then Etype
(First_Formal
(Scop
)) = Typ
970 Make_Attribute_Reference
(Loc
,
971 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
972 Attribute_Name
=> Name_Unrestricted_Access
));
976 -- OK if a task type, this test needs sharpening up ???
978 elsif Is_Task_Type
(Typ
) then
981 -- OK if self-reference in an aggregate in Ada 2005, and
982 -- the reference comes from a copied default expression.
984 -- Note that we check legality of self-reference even if the
985 -- expression comes from source, e.g. when a single component
986 -- association in an aggregate has a box association.
988 elsif Ada_Version
>= Ada_2005
989 and then OK_Self_Reference
993 -- OK if reference to current instance of a protected object
995 elsif Is_Protected_Self_Reference
(P
) then
998 -- Otherwise we have an error case
1001 Error_Attr
("% attribute cannot be applied to type", P
);
1007 -- If we fall through, we have a normal access to object case
1009 -- Unrestricted_Access is (for now) legal wherever an allocator would
1010 -- be legal, so its Etype is set to E_Allocator. The expected type
1011 -- of the other attributes is a general access type, and therefore
1012 -- we label them with E_Access_Attribute_Type.
1014 if not Is_Overloaded
(P
) then
1015 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
1016 Set_Etype
(N
, Acc_Type
);
1020 Index
: Interp_Index
;
1023 Set_Etype
(N
, Any_Type
);
1024 Get_First_Interp
(P
, Index
, It
);
1025 while Present
(It
.Typ
) loop
1026 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1027 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1028 Get_Next_Interp
(Index
, It
);
1033 -- Special cases when we can find a prefix that is an entity name
1042 if Is_Entity_Name
(PP
) then
1045 -- If we have an access to an object, and the attribute
1046 -- comes from source, then set the object as potentially
1047 -- source modified. We do this because the resulting access
1048 -- pointer can be used to modify the variable, and we might
1049 -- not detect this, leading to some junk warnings.
1051 -- We only do this for source references, since otherwise
1052 -- we can suppress warnings, e.g. from the unrestricted
1053 -- access generated for validity checks in -gnatVa mode.
1055 if Comes_From_Source
(N
) then
1056 Set_Never_Set_In_Source
(Ent
, False);
1059 -- Mark entity as address taken in the case of
1060 -- 'Unrestricted_Access or subprograms, and kill current
1063 if Aname
= Name_Unrestricted_Access
1064 or else Is_Subprogram
(Ent
)
1066 Set_Address_Taken
(Ent
);
1069 Kill_Current_Values
(Ent
);
1072 elsif Nkind_In
(PP
, N_Selected_Component
,
1073 N_Indexed_Component
)
1082 end Analyze_Access_Attribute
;
1084 ----------------------------------
1085 -- Analyze_Attribute_Old_Result --
1086 ----------------------------------
1088 procedure Analyze_Attribute_Old_Result
1089 (Legal
: out Boolean;
1090 Spec_Id
: out Entity_Id
)
1092 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1093 -- Verify that the attribute appears within pragma Check that mimics
1096 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1097 -- Verify that the attribute appears within a consequence of aspect
1098 -- or pragma Contract_Cases denoted by Prag.
1100 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1101 -- Verify that the attribute appears within the "Ensures" argument of
1102 -- aspect or pragma Test_Case denoted by Prag.
1106 Encl_Nod
: Node_Id
) return Boolean;
1107 -- Subsidiary to Check_Placemenet_In_XXX. Determine whether arbitrary
1108 -- node Nod is within enclosing node Encl_Nod.
1110 procedure Placement_Error
;
1111 -- Emit a general error when the attributes does not appear in a
1112 -- postcondition-like aspect or pragma.
1114 ------------------------------
1115 -- Check_Placement_In_Check --
1116 ------------------------------
1118 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1119 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1120 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1123 -- The "Name" argument of pragma Check denotes a postcondition
1125 if Nam_In
(Nam
, Name_Post
,
1132 -- Otherwise the placement of the attribute is illegal
1137 end Check_Placement_In_Check
;
1139 ---------------------------------------
1140 -- Check_Placement_In_Contract_Cases --
1141 ---------------------------------------
1143 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1149 -- Obtain the argument of the aspect or pragma
1151 if Nkind
(Prag
) = N_Aspect_Specification
then
1154 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1157 Cases
:= Expression
(Arg
);
1159 if Present
(Component_Associations
(Cases
)) then
1160 CCase
:= First
(Component_Associations
(Cases
));
1161 while Present
(CCase
) loop
1163 -- Detect whether the attribute appears within the
1164 -- consequence of the current contract case.
1166 if Nkind
(CCase
) = N_Component_Association
1167 and then Is_Within
(N
, Expression
(CCase
))
1176 -- Otherwise aspect or pragma Contract_Cases is either malformed
1177 -- or the attribute does not appear within a consequence.
1180 ("attribute % must appear in the consequence of a contract case",
1182 end Check_Placement_In_Contract_Cases
;
1184 ----------------------------------
1185 -- Check_Placement_In_Test_Case --
1186 ----------------------------------
1188 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1189 Arg
: constant Node_Id
:=
1192 Arg_Nam
=> Name_Ensures
,
1193 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1196 -- Detect whether the attribute appears within the "Ensures"
1197 -- expression of aspect or pragma Test_Case.
1199 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1204 ("attribute % must appear in the ensures expression of a "
1207 end Check_Placement_In_Test_Case
;
1215 Encl_Nod
: Node_Id
) return Boolean
1221 while Present
(Par
) loop
1222 if Par
= Encl_Nod
then
1225 -- Prevent the search from going too far
1227 elsif Is_Body_Or_Package_Declaration
(Par
) then
1231 Par
:= Parent
(Par
);
1237 ---------------------
1238 -- Placement_Error --
1239 ---------------------
1241 procedure Placement_Error
is
1243 if Aname
= Name_Old
then
1244 Error_Attr
("attribute % can only appear in postcondition", P
);
1246 -- Specialize the error message for attribute 'Result
1250 ("attribute % can only appear in postcondition of function",
1253 end Placement_Error
;
1259 Subp_Decl
: Node_Id
;
1261 -- Start of processing for Analyze_Attribute_Old_Result
1264 -- Assume that the attribute is illegal
1269 -- Traverse the parent chain to find the aspect or pragma where the
1270 -- attribute resides.
1273 while Present
(Prag
) loop
1274 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1277 -- Prevent the search from going too far
1279 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1283 Prag
:= Parent
(Prag
);
1286 -- The attribute is allowed to appear only in postcondition-like
1287 -- aspects or pragmas.
1289 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1290 if Nkind
(Prag
) = N_Aspect_Specification
then
1291 Prag_Nam
:= Chars
(Identifier
(Prag
));
1293 Prag_Nam
:= Pragma_Name
(Prag
);
1296 if Prag_Nam
= Name_Check
then
1297 Check_Placement_In_Check
(Prag
);
1299 elsif Prag_Nam
= Name_Contract_Cases
then
1300 Check_Placement_In_Contract_Cases
(Prag
);
1302 -- Attribute 'Result is allowed to appear in aspect or pragma
1303 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1305 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Refined_Depends
)
1306 and then Aname
= Name_Result
1310 elsif Nam_In
(Prag_Nam
, Name_Post
,
1317 elsif Prag_Nam
= Name_Test_Case
then
1318 Check_Placement_In_Test_Case
(Prag
);
1325 -- Otherwise the placement of the attribute is illegal
1332 -- Find the related subprogram subject to the aspect or pragma
1334 if Nkind
(Prag
) = N_Aspect_Specification
then
1335 Subp_Decl
:= Parent
(Prag
);
1337 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1340 -- The aspect or pragma where the attribute resides should be
1341 -- associated with a subprogram declaration or a body. If this is not
1342 -- the case, then the aspect or pragma is illegal. Return as analysis
1343 -- cannot be carried out. Note that it is legal to have the aspect
1344 -- appear on a subprogram renaming, when the renamed entity is an
1345 -- attribute reference.
1347 -- Generating C code the internally built nested _postcondition
1348 -- subprograms are inlined; after expanded, inlined aspects are
1349 -- located in the internal block generated by the frontend.
1351 if Nkind
(Subp_Decl
) = N_Block_Statement
1352 and then Modify_Tree_For_C
1353 and then In_Inlined_Body
1357 elsif not Nkind_In
(Subp_Decl
, N_Abstract_Subprogram_Declaration
,
1358 N_Entry_Declaration
,
1359 N_Expression_Function
,
1360 N_Generic_Subprogram_Declaration
,
1362 N_Subprogram_Body_Stub
,
1363 N_Subprogram_Declaration
,
1364 N_Subprogram_Renaming_Declaration
)
1369 -- If we get here, then the attribute is legal
1372 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1374 -- When generating C code, nested _postcondition subprograms are
1375 -- inlined by the front end to avoid problems (when unnested) with
1376 -- referenced itypes. Handle that here, since as part of inlining the
1377 -- expander nests subprogram within a dummy procedure named _parent
1378 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1379 -- Hence, in this context, the spec_id of _postconditions is the
1382 if Modify_Tree_For_C
1383 and then Chars
(Spec_Id
) = Name_uParent
1384 and then Chars
(Scope
(Spec_Id
)) = Name_uPostconditions
1386 -- This situation occurs only when preanalyzing the inlined body
1388 pragma Assert
(not Full_Analysis
);
1390 Spec_Id
:= Scope
(Spec_Id
);
1391 pragma Assert
(Is_Inlined
(Spec_Id
));
1393 end Analyze_Attribute_Old_Result
;
1395 -----------------------------
1396 -- Analyze_Image_Attribute --
1397 -----------------------------
1399 procedure Analyze_Image_Attribute
(Str_Typ
: Entity_Id
) is
1401 Check_SPARK_05_Restriction_On_Attribute
;
1403 -- AI12-00124: The ARG has adopted the GNAT semantics of 'Img for
1404 -- scalar types, so that the prefix can be an object, a named value,
1405 -- or a type, and there is no need for an argument in this case.
1407 if Attr_Id
= Attribute_Img
1408 or else (Ada_Version
> Ada_2005
and then Is_Object_Image
(P
))
1411 Set_Etype
(N
, Str_Typ
);
1413 if Attr_Id
= Attribute_Img
and then not Is_Object_Image
(P
) then
1415 ("prefix of % attribute must be a scalar object name");
1419 Set_Etype
(N
, Str_Typ
);
1421 -- Check that the prefix type is scalar - much in the same way as
1422 -- Check_Scalar_Type but with custom error messages to denote the
1423 -- variants of 'Image attributes.
1425 if Is_Entity_Name
(P
)
1426 and then Is_Type
(Entity
(P
))
1427 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1428 and then Present
(Full_View
(Entity
(P
)))
1430 P_Type
:= Full_View
(Entity
(P
));
1431 Set_Entity
(P
, P_Type
);
1434 if not Is_Entity_Name
(P
)
1435 or else not Is_Type
(Entity
(P
))
1436 or else not Is_Scalar_Type
(P_Type
)
1438 if Ada_Version
> Ada_2005
then
1440 ("prefix of % attribute must be a scalar type or a scalar "
1443 Error_Attr_P
("prefix of % attribute must be a scalar type");
1446 elsif Is_Protected_Self_Reference
(P
) then
1448 ("prefix of % attribute denotes current instance "
1449 & "(RM 9.4(21/2))");
1452 Resolve
(E1
, P_Base_Type
);
1453 Validate_Non_Static_Attribute_Function_Call
;
1458 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
1459 -- to avoid giving a duplicate message for when Image attributes
1460 -- applied to object references get expanded into type-based Image
1463 if Restriction_Check_Required
(No_Fixed_IO
)
1464 and then Comes_From_Source
(N
)
1465 and then Is_Fixed_Point_Type
(P_Type
)
1467 Check_Restriction
(No_Fixed_IO
, P
);
1469 end Analyze_Image_Attribute
;
1471 ---------------------------------
1472 -- Bad_Attribute_For_Predicate --
1473 ---------------------------------
1475 procedure Bad_Attribute_For_Predicate
is
1477 if Is_Scalar_Type
(P_Type
)
1478 and then Comes_From_Source
(N
)
1480 Error_Msg_Name_1
:= Aname
;
1481 Bad_Predicated_Subtype_Use
1482 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1484 end Bad_Attribute_For_Predicate
;
1486 --------------------------------
1487 -- Check_Array_Or_Scalar_Type --
1488 --------------------------------
1490 procedure Check_Array_Or_Scalar_Type
is
1491 function In_Aspect_Specification
return Boolean;
1492 -- A current instance of a type in an aspect specification is an
1493 -- object and not a type, and therefore cannot be of a scalar type
1494 -- in the prefix of one of the array attributes if the attribute
1495 -- reference is part of an aspect expression.
1497 -----------------------------
1498 -- In_Aspect_Specification --
1499 -----------------------------
1501 function In_Aspect_Specification
return Boolean is
1506 while Present
(P
) loop
1507 if Nkind
(P
) = N_Aspect_Specification
then
1508 return P_Type
= Entity
(P
);
1510 elsif Nkind
(P
) in N_Declaration
then
1518 end In_Aspect_Specification
;
1525 -- Start of processing for Check_Array_Or_Scalar_Type
1528 -- Case of string literal or string literal subtype. These cases
1529 -- cannot arise from legal Ada code, but the expander is allowed
1530 -- to generate them. They require special handling because string
1531 -- literal subtypes do not have standard bounds (the whole idea
1532 -- of these subtypes is to avoid having to generate the bounds)
1534 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1535 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1540 elsif Is_Scalar_Type
(P_Type
) then
1543 if Present
(E1
) then
1544 Error_Attr
("invalid argument in % attribute", E1
);
1546 elsif In_Aspect_Specification
then
1548 ("prefix of % attribute cannot be the current instance of a "
1549 & "scalar type", P
);
1552 Set_Etype
(N
, P_Base_Type
);
1556 -- The following is a special test to allow 'First to apply to
1557 -- private scalar types if the attribute comes from generated
1558 -- code. This occurs in the case of Normalize_Scalars code.
1560 elsif Is_Private_Type
(P_Type
)
1561 and then Present
(Full_View
(P_Type
))
1562 and then Is_Scalar_Type
(Full_View
(P_Type
))
1563 and then not Comes_From_Source
(N
)
1565 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1567 -- Array types other than string literal subtypes handled above
1572 -- We know prefix is an array type, or the name of an array
1573 -- object, and that the expression, if present, is static
1574 -- and within the range of the dimensions of the type.
1576 pragma Assert
(Is_Array_Type
(P_Type
));
1577 Index
:= First_Index
(P_Base_Type
);
1581 -- First dimension assumed
1583 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1586 Dims
:= UI_To_Int
(Intval
(E1
));
1588 for J
in 1 .. Dims
- 1 loop
1592 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1593 Set_Etype
(E1
, Standard_Integer
);
1596 end Check_Array_Or_Scalar_Type
;
1598 ----------------------
1599 -- Check_Array_Type --
1600 ----------------------
1602 procedure Check_Array_Type
is
1604 -- Dimension number for array attributes
1607 -- If the type is a string literal type, then this must be generated
1608 -- internally, and no further check is required on its legality.
1610 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1613 -- If the type is a composite, it is an illegal aggregate, no point
1616 elsif P_Type
= Any_Composite
then
1617 raise Bad_Attribute
;
1620 -- Normal case of array type or subtype
1622 Check_Either_E0_Or_E1
;
1625 if Is_Array_Type
(P_Type
) then
1626 if not Is_Constrained
(P_Type
)
1627 and then Is_Entity_Name
(P
)
1628 and then Is_Type
(Entity
(P
))
1630 -- Note: we do not call Error_Attr here, since we prefer to
1631 -- continue, using the relevant index type of the array,
1632 -- even though it is unconstrained. This gives better error
1633 -- recovery behavior.
1635 Error_Msg_Name_1
:= Aname
;
1637 ("prefix for % attribute must be constrained array", P
);
1640 -- The attribute reference freezes the type, and thus the
1641 -- component type, even if the attribute may not depend on the
1642 -- component. Diagnose arrays with incomplete components now.
1643 -- If the prefix is an access to array, this does not freeze
1644 -- the designated type.
1646 if Nkind
(P
) /= N_Explicit_Dereference
then
1647 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1650 D
:= Number_Dimensions
(P_Type
);
1653 if Is_Private_Type
(P_Type
) then
1654 Error_Attr_P
("prefix for % attribute may not be private type");
1656 elsif Is_Access_Type
(P_Type
)
1657 and then Is_Array_Type
(Designated_Type
(P_Type
))
1658 and then Is_Entity_Name
(P
)
1659 and then Is_Type
(Entity
(P
))
1661 Error_Attr_P
("prefix of % attribute cannot be access type");
1663 elsif Attr_Id
= Attribute_First
1665 Attr_Id
= Attribute_Last
1667 Error_Attr
("invalid prefix for % attribute", P
);
1670 Error_Attr_P
("prefix for % attribute must be array");
1674 if Present
(E1
) then
1675 Resolve
(E1
, Any_Integer
);
1676 Set_Etype
(E1
, Standard_Integer
);
1678 if not Is_OK_Static_Expression
(E1
)
1679 or else Raises_Constraint_Error
(E1
)
1681 Flag_Non_Static_Expr
1682 ("expression for dimension must be static!", E1
);
1685 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1686 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1688 Error_Attr
("invalid dimension number for array type", E1
);
1692 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1693 and then Comes_From_Source
(N
)
1695 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1697 end Check_Array_Type
;
1699 -------------------------
1700 -- Check_Asm_Attribute --
1701 -------------------------
1703 procedure Check_Asm_Attribute
is
1708 -- Check first argument is static string expression
1710 Analyze_And_Resolve
(E1
, Standard_String
);
1712 if Etype
(E1
) = Any_Type
then
1715 elsif not Is_OK_Static_Expression
(E1
) then
1716 Flag_Non_Static_Expr
1717 ("constraint argument must be static string expression!", E1
);
1721 -- Check second argument is right type
1723 Analyze_And_Resolve
(E2
, Entity
(P
));
1725 -- Note: that is all we need to do, we don't need to check
1726 -- that it appears in a correct context. The Ada type system
1727 -- will do that for us.
1729 end Check_Asm_Attribute
;
1731 ---------------------
1732 -- Check_Component --
1733 ---------------------
1735 procedure Check_Component
is
1739 if Nkind
(P
) /= N_Selected_Component
1741 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1743 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1745 Error_Attr_P
("prefix for % attribute must be selected component");
1747 end Check_Component
;
1749 ------------------------------------
1750 -- Check_Decimal_Fixed_Point_Type --
1751 ------------------------------------
1753 procedure Check_Decimal_Fixed_Point_Type
is
1757 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1758 Error_Attr_P
("prefix of % attribute must be decimal type");
1760 end Check_Decimal_Fixed_Point_Type
;
1762 -----------------------
1763 -- Check_Dereference --
1764 -----------------------
1766 procedure Check_Dereference
is
1769 -- Case of a subtype mark
1771 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1775 -- Case of an expression
1779 if Is_Access_Type
(P_Type
) then
1781 -- If there is an implicit dereference, then we must freeze the
1782 -- designated type of the access type, since the type of the
1783 -- referenced array is this type (see AI95-00106).
1785 -- As done elsewhere, freezing must not happen when pre-analyzing
1786 -- a pre- or postcondition or a default value for an object or for
1787 -- a formal parameter.
1789 if not In_Spec_Expression
then
1790 Freeze_Before
(N
, Designated_Type
(P_Type
));
1794 Make_Explicit_Dereference
(Sloc
(P
),
1795 Prefix
=> Relocate_Node
(P
)));
1797 Analyze_And_Resolve
(P
);
1798 P_Type
:= Etype
(P
);
1800 if P_Type
= Any_Type
then
1801 raise Bad_Attribute
;
1804 P_Base_Type
:= Base_Type
(P_Type
);
1806 end Check_Dereference
;
1808 -------------------------
1809 -- Check_Discrete_Type --
1810 -------------------------
1812 procedure Check_Discrete_Type
is
1816 if not Is_Discrete_Type
(P_Type
) then
1817 Error_Attr_P
("prefix of % attribute must be discrete type");
1819 end Check_Discrete_Type
;
1825 procedure Check_E0
is
1827 if Present
(E1
) then
1828 Unexpected_Argument
(E1
);
1836 procedure Check_E1
is
1838 Check_Either_E0_Or_E1
;
1842 -- Special-case attributes that are functions and that appear as
1843 -- the prefix of another attribute. Error is posted on parent.
1845 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1846 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1850 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1851 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1852 Set_Etype
(Parent
(N
), Any_Type
);
1853 Set_Entity
(Parent
(N
), Any_Type
);
1854 raise Bad_Attribute
;
1857 Error_Attr
("missing argument for % attribute", N
);
1866 procedure Check_E2
is
1869 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1871 Error_Attr
("missing argument for % attribute (2 required)", N
);
1875 ---------------------------
1876 -- Check_Either_E0_Or_E1 --
1877 ---------------------------
1879 procedure Check_Either_E0_Or_E1
is
1881 if Present
(E2
) then
1882 Unexpected_Argument
(E2
);
1884 end Check_Either_E0_Or_E1
;
1886 ----------------------
1887 -- Check_Enum_Image --
1888 ----------------------
1890 procedure Check_Enum_Image
is
1894 -- When an enumeration type appears in an attribute reference, all
1895 -- literals of the type are marked as referenced. This must only be
1896 -- done if the attribute reference appears in the current source.
1897 -- Otherwise the information on references may differ between a
1898 -- normal compilation and one that performs inlining.
1900 if Is_Enumeration_Type
(P_Base_Type
)
1901 and then In_Extended_Main_Code_Unit
(N
)
1903 Lit
:= First_Literal
(P_Base_Type
);
1904 while Present
(Lit
) loop
1905 Set_Referenced
(Lit
);
1909 end Check_Enum_Image
;
1911 ----------------------------
1912 -- Check_First_Last_Valid --
1913 ----------------------------
1915 procedure Check_First_Last_Valid
is
1917 Check_Discrete_Type
;
1919 -- Freeze the subtype now, so that the following test for predicates
1920 -- works (we set the predicates stuff up at freeze time)
1922 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1924 -- Now test for dynamic predicate
1926 if Has_Predicates
(P_Type
)
1927 and then not (Has_Static_Predicate
(P_Type
))
1930 ("prefix of % attribute may not have dynamic predicate");
1933 -- Check non-static subtype
1935 if not Is_OK_Static_Subtype
(P_Type
) then
1936 Error_Attr_P
("prefix of % attribute must be a static subtype");
1939 -- Test case for no values
1941 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1942 Expr_Value
(Type_High_Bound
(P_Type
))
1943 or else (Has_Predicates
(P_Type
)
1945 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1948 ("prefix of % attribute must be subtype with at least one "
1951 end Check_First_Last_Valid
;
1953 ----------------------------
1954 -- Check_Fixed_Point_Type --
1955 ----------------------------
1957 procedure Check_Fixed_Point_Type
is
1961 if not Is_Fixed_Point_Type
(P_Type
) then
1962 Error_Attr_P
("prefix of % attribute must be fixed point type");
1964 end Check_Fixed_Point_Type
;
1966 ------------------------------
1967 -- Check_Fixed_Point_Type_0 --
1968 ------------------------------
1970 procedure Check_Fixed_Point_Type_0
is
1972 Check_Fixed_Point_Type
;
1974 end Check_Fixed_Point_Type_0
;
1976 -------------------------------
1977 -- Check_Floating_Point_Type --
1978 -------------------------------
1980 procedure Check_Floating_Point_Type
is
1984 if not Is_Floating_Point_Type
(P_Type
) then
1985 Error_Attr_P
("prefix of % attribute must be float type");
1987 end Check_Floating_Point_Type
;
1989 ---------------------------------
1990 -- Check_Floating_Point_Type_0 --
1991 ---------------------------------
1993 procedure Check_Floating_Point_Type_0
is
1995 Check_Floating_Point_Type
;
1997 end Check_Floating_Point_Type_0
;
1999 ---------------------------------
2000 -- Check_Floating_Point_Type_1 --
2001 ---------------------------------
2003 procedure Check_Floating_Point_Type_1
is
2005 Check_Floating_Point_Type
;
2007 end Check_Floating_Point_Type_1
;
2009 ---------------------------------
2010 -- Check_Floating_Point_Type_2 --
2011 ---------------------------------
2013 procedure Check_Floating_Point_Type_2
is
2015 Check_Floating_Point_Type
;
2017 end Check_Floating_Point_Type_2
;
2019 ------------------------
2020 -- Check_Integer_Type --
2021 ------------------------
2023 procedure Check_Integer_Type
is
2027 if not Is_Integer_Type
(P_Type
) then
2028 Error_Attr_P
("prefix of % attribute must be integer type");
2030 end Check_Integer_Type
;
2032 --------------------------------
2033 -- Check_Modular_Integer_Type --
2034 --------------------------------
2036 procedure Check_Modular_Integer_Type
is
2040 if not Is_Modular_Integer_Type
(P_Type
) then
2042 ("prefix of % attribute must be modular integer type");
2044 end Check_Modular_Integer_Type
;
2046 ------------------------
2047 -- Check_Not_CPP_Type --
2048 ------------------------
2050 procedure Check_Not_CPP_Type
is
2052 if Is_Tagged_Type
(Etype
(P
))
2053 and then Convention
(Etype
(P
)) = Convention_CPP
2054 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
2057 ("invalid use of % attribute with 'C'P'P tagged type");
2059 end Check_Not_CPP_Type
;
2061 -------------------------------
2062 -- Check_Not_Incomplete_Type --
2063 -------------------------------
2065 procedure Check_Not_Incomplete_Type
is
2070 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2071 -- dereference we have to check wrong uses of incomplete types
2072 -- (other wrong uses are checked at their freezing point).
2074 -- In Ada 2012, incomplete types can appear in subprogram
2075 -- profiles, but formals with incomplete types cannot be the
2076 -- prefix of attributes.
2078 -- Example 1: Limited-with
2080 -- limited with Pkg;
2082 -- type Acc is access Pkg.T;
2084 -- S : Integer := X.all'Size; -- ERROR
2087 -- Example 2: Tagged incomplete
2089 -- type T is tagged;
2090 -- type Acc is access all T;
2092 -- S : constant Integer := X.all'Size; -- ERROR
2093 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2095 if Ada_Version
>= Ada_2005
2096 and then Nkind
(P
) = N_Explicit_Dereference
2099 while Nkind
(E
) = N_Explicit_Dereference
loop
2105 if From_Limited_With
(Typ
) then
2107 ("prefix of % attribute cannot be an incomplete type");
2109 -- If the prefix is an access type check the designated type
2111 elsif Is_Access_Type
(Typ
)
2112 and then Nkind
(P
) = N_Explicit_Dereference
2114 Typ
:= Directly_Designated_Type
(Typ
);
2117 if Is_Class_Wide_Type
(Typ
) then
2118 Typ
:= Root_Type
(Typ
);
2121 -- A legal use of a shadow entity occurs only when the unit where
2122 -- the non-limited view resides is imported via a regular with
2123 -- clause in the current body. Such references to shadow entities
2124 -- may occur in subprogram formals.
2126 if Is_Incomplete_Type
(Typ
)
2127 and then From_Limited_With
(Typ
)
2128 and then Present
(Non_Limited_View
(Typ
))
2129 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2131 Typ
:= Non_Limited_View
(Typ
);
2134 -- If still incomplete, it can be a local incomplete type, or a
2135 -- limited view whose scope is also a limited view.
2137 if Ekind
(Typ
) = E_Incomplete_Type
then
2138 if not From_Limited_With
(Typ
)
2139 and then No
(Full_View
(Typ
))
2142 ("prefix of % attribute cannot be an incomplete type");
2144 -- The limited view may be available indirectly through
2145 -- an intermediate unit. If the non-limited view is available
2146 -- the attribute reference is legal.
2148 elsif From_Limited_With
(Typ
)
2150 (No
(Non_Limited_View
(Typ
))
2151 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2154 ("prefix of % attribute cannot be an incomplete type");
2158 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2161 elsif Is_Entity_Name
(P
)
2162 and then Is_Formal
(Entity
(P
))
2163 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2166 ("prefix of % attribute cannot be an incomplete type");
2169 if not Is_Entity_Name
(P
)
2170 or else not Is_Type
(Entity
(P
))
2171 or else In_Spec_Expression
2175 Check_Fully_Declared
(P_Type
, P
);
2177 end Check_Not_Incomplete_Type
;
2179 ----------------------------
2180 -- Check_Object_Reference --
2181 ----------------------------
2183 procedure Check_Object_Reference
(P
: Node_Id
) is
2187 -- If we need an object, and we have a prefix that is the name of
2188 -- a function entity, convert it into a function call.
2190 if Is_Entity_Name
(P
)
2191 and then Ekind
(Entity
(P
)) = E_Function
2193 Rtyp
:= Etype
(Entity
(P
));
2196 Make_Function_Call
(Sloc
(P
),
2197 Name
=> Relocate_Node
(P
)));
2199 Analyze_And_Resolve
(P
, Rtyp
);
2201 -- Otherwise we must have an object reference
2203 elsif not Is_Object_Reference
(P
) then
2204 Error_Attr_P
("prefix of % attribute must be object");
2206 end Check_Object_Reference
;
2208 ----------------------------
2209 -- Check_PolyORB_Attribute --
2210 ----------------------------
2212 procedure Check_PolyORB_Attribute
is
2214 Validate_Non_Static_Attribute_Function_Call
;
2219 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2221 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2223 end Check_PolyORB_Attribute
;
2225 ------------------------
2226 -- Check_Program_Unit --
2227 ------------------------
2229 procedure Check_Program_Unit
is
2231 if Is_Entity_Name
(P
) then
2233 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
2234 T
: constant Entity_Id
:= Etype
(Entity
(P
));
2237 if K
in Subprogram_Kind
2238 or else K
in Task_Kind
2239 or else K
in Protected_Kind
2240 or else K
= E_Package
2241 or else K
in Generic_Unit_Kind
2242 or else (K
= E_Variable
2246 Is_Protected_Type
(T
)))
2253 Error_Attr_P
("prefix of % attribute must be program unit");
2254 end Check_Program_Unit
;
2256 ---------------------
2257 -- Check_Real_Type --
2258 ---------------------
2260 procedure Check_Real_Type
is
2264 if not Is_Real_Type
(P_Type
) then
2265 Error_Attr_P
("prefix of % attribute must be real type");
2267 end Check_Real_Type
;
2269 -----------------------
2270 -- Check_Scalar_Type --
2271 -----------------------
2273 procedure Check_Scalar_Type
is
2277 if not Is_Scalar_Type
(P_Type
) then
2278 Error_Attr_P
("prefix of % attribute must be scalar type");
2280 end Check_Scalar_Type
;
2282 ------------------------------------------
2283 -- Check_SPARK_05_Restriction_On_Attribute --
2284 ------------------------------------------
2286 procedure Check_SPARK_05_Restriction_On_Attribute
is
2288 Error_Msg_Name_1
:= Aname
;
2289 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
2290 end Check_SPARK_05_Restriction_On_Attribute
;
2292 ---------------------------
2293 -- Check_Standard_Prefix --
2294 ---------------------------
2296 procedure Check_Standard_Prefix
is
2300 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2301 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2303 end Check_Standard_Prefix
;
2305 ----------------------------
2306 -- Check_Stream_Attribute --
2307 ----------------------------
2309 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2313 In_Shared_Var_Procs
: Boolean;
2314 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2315 -- For this runtime package (always compiled in GNAT mode), we allow
2316 -- stream attributes references for limited types for the case where
2317 -- shared passive objects are implemented using stream attributes,
2318 -- which is the default in GNAT's persistent storage implementation.
2321 Validate_Non_Static_Attribute_Function_Call
;
2323 -- With the exception of 'Input, Stream attributes are procedures,
2324 -- and can only appear at the position of procedure calls. We check
2325 -- for this here, before they are rewritten, to give a more precise
2328 if Nam
= TSS_Stream_Input
then
2331 elsif Is_List_Member
(N
)
2332 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
2339 ("invalid context for attribute%, which is a procedure", N
);
2343 Btyp
:= Implementation_Base_Type
(P_Type
);
2345 -- Stream attributes not allowed on limited types unless the
2346 -- attribute reference was generated by the expander (in which
2347 -- case the underlying type will be used, as described in Sinfo),
2348 -- or the attribute was specified explicitly for the type itself
2349 -- or one of its ancestors (taking visibility rules into account if
2350 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2351 -- (with no visibility restriction).
2354 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2356 if Present
(Gen_Body
) then
2357 In_Shared_Var_Procs
:=
2358 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2360 In_Shared_Var_Procs
:= False;
2364 if (Comes_From_Source
(N
)
2365 and then not (In_Shared_Var_Procs
or In_Instance
))
2366 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2367 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2369 Error_Msg_Name_1
:= Aname
;
2371 if Is_Limited_Type
(P_Type
) then
2373 ("limited type& has no% attribute", P
, P_Type
);
2374 Explain_Limited_Type
(P_Type
, P
);
2377 ("attribute% for type& is not available", P
, P_Type
);
2381 -- Check for no stream operations allowed from No_Tagged_Streams
2383 if Is_Tagged_Type
(P_Type
)
2384 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2386 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2388 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2392 -- Check restriction violations
2394 -- First check the No_Streams restriction, which prohibits the use
2395 -- of explicit stream attributes in the source program. We do not
2396 -- prevent the occurrence of stream attributes in generated code,
2397 -- for instance those generated implicitly for dispatching purposes.
2399 if Comes_From_Source
(N
) then
2400 Check_Restriction
(No_Streams
, P
);
2403 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2404 -- it is illegal to use a predefined elementary type stream attribute
2405 -- either by itself, or more importantly as part of the attribute
2406 -- subprogram for a composite type. However, if the broader
2407 -- restriction No_Streams is active, stream operations are not
2408 -- generated, and there is no error.
2410 if Restriction_Active
(No_Default_Stream_Attributes
)
2411 and then not Restriction_Active
(No_Streams
)
2417 if Nam
= TSS_Stream_Input
2419 Nam
= TSS_Stream_Read
2422 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2425 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2429 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2432 ("missing user-defined Stream Read or Write for type&",
2434 if not Is_Elementary_Type
(P_Type
) then
2436 ("\which is a component of type&", N
, P_Type
);
2442 -- Check special case of Exception_Id and Exception_Occurrence which
2443 -- are not allowed for restriction No_Exception_Registration.
2445 if Restriction_Check_Required
(No_Exception_Registration
)
2446 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2448 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2450 Check_Restriction
(No_Exception_Registration
, P
);
2453 -- Here we must check that the first argument is an access type
2454 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2456 Analyze_And_Resolve
(E1
);
2459 -- Note: the double call to Root_Type here is needed because the
2460 -- root type of a class-wide type is the corresponding type (e.g.
2461 -- X for X'Class, and we really want to go to the root.)
2463 if not Is_Access_Type
(Etyp
)
2464 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
2465 RTE
(RE_Root_Stream_Type
)
2468 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2471 -- Check that the second argument is of the right type if there is
2472 -- one (the Input attribute has only one argument so this is skipped)
2474 if Present
(E2
) then
2477 if Nam
= TSS_Stream_Read
2478 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2481 ("second argument of % attribute must be a variable", E2
);
2484 Resolve
(E2
, P_Type
);
2488 end Check_Stream_Attribute
;
2490 -------------------------
2491 -- Check_System_Prefix --
2492 -------------------------
2494 procedure Check_System_Prefix
is
2496 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2497 Error_Attr
("only allowed prefix for % attribute is System", P
);
2499 end Check_System_Prefix
;
2501 -----------------------
2502 -- Check_Task_Prefix --
2503 -----------------------
2505 procedure Check_Task_Prefix
is
2509 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2510 -- task interface class-wide types.
2512 if Is_Task_Type
(Etype
(P
))
2513 or else (Is_Access_Type
(Etype
(P
))
2514 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2515 or else (Ada_Version
>= Ada_2005
2516 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2517 and then Is_Interface
(Etype
(P
))
2518 and then Is_Task_Interface
(Etype
(P
)))
2523 if Ada_Version
>= Ada_2005
then
2525 ("prefix of % attribute must be a task or a task " &
2526 "interface class-wide object");
2529 Error_Attr_P
("prefix of % attribute must be a task");
2532 end Check_Task_Prefix
;
2538 -- The possibilities are an entity name denoting a type, or an
2539 -- attribute reference that denotes a type (Base or Class). If
2540 -- the type is incomplete, replace it with its full view.
2542 procedure Check_Type
is
2544 if not Is_Entity_Name
(P
)
2545 or else not Is_Type
(Entity
(P
))
2547 Error_Attr_P
("prefix of % attribute must be a type");
2549 elsif Is_Protected_Self_Reference
(P
) then
2551 ("prefix of % attribute denotes current instance "
2552 & "(RM 9.4(21/2))");
2554 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2555 and then Present
(Full_View
(Entity
(P
)))
2557 P_Type
:= Full_View
(Entity
(P
));
2558 Set_Entity
(P
, P_Type
);
2562 ---------------------
2563 -- Check_Unit_Name --
2564 ---------------------
2566 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2568 if Nkind
(Nod
) = N_Identifier
then
2571 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2572 Check_Unit_Name
(Prefix
(Nod
));
2574 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2579 Error_Attr
("argument for % attribute must be unit name", P
);
2580 end Check_Unit_Name
;
2586 procedure Error_Attr
is
2588 Set_Etype
(N
, Any_Type
);
2589 Set_Entity
(N
, Any_Type
);
2590 raise Bad_Attribute
;
2593 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2595 Error_Msg_Name_1
:= Aname
;
2596 Error_Msg_N
(Msg
, Error_Node
);
2604 procedure Error_Attr_P
(Msg
: String) is
2606 Error_Msg_Name_1
:= Aname
;
2607 Error_Msg_F
(Msg
, P
);
2611 ----------------------------
2612 -- Legal_Formal_Attribute --
2613 ----------------------------
2615 procedure Legal_Formal_Attribute
is
2619 if not Is_Entity_Name
(P
)
2620 or else not Is_Type
(Entity
(P
))
2622 Error_Attr_P
("prefix of % attribute must be generic type");
2624 elsif Is_Generic_Actual_Type
(Entity
(P
))
2626 or else In_Inlined_Body
2630 elsif Is_Generic_Type
(Entity
(P
)) then
2631 if Is_Definite_Subtype
(Entity
(P
)) then
2633 ("prefix of % attribute must be indefinite generic type");
2638 ("prefix of % attribute must be indefinite generic type");
2641 Set_Etype
(N
, Standard_Boolean
);
2642 end Legal_Formal_Attribute
;
2644 ---------------------------------------------------------------
2645 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2646 ---------------------------------------------------------------
2648 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2652 Check_Not_Incomplete_Type
;
2653 Set_Etype
(N
, Universal_Integer
);
2654 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2660 procedure Min_Max
is
2664 Resolve
(E1
, P_Base_Type
);
2665 Resolve
(E2
, P_Base_Type
);
2666 Set_Etype
(N
, P_Base_Type
);
2668 -- Check for comparison on unordered enumeration type
2670 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2671 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2673 ("comparison on unordered enumeration type& declared#?U?",
2678 ------------------------
2679 -- Standard_Attribute --
2680 ------------------------
2682 procedure Standard_Attribute
(Val
: Int
) is
2684 Check_Standard_Prefix
;
2685 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2687 Set_Is_Static_Expression
(N
, True);
2688 end Standard_Attribute
;
2690 --------------------
2691 -- Uneval_Old_Msg --
2692 --------------------
2694 procedure Uneval_Old_Msg
is
2695 Uneval_Old_Setting
: Character;
2699 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2700 -- N_Aspect_Specification node that corresponds to the attribute.
2702 -- First find the pragma in which we appear (note that at this stage,
2703 -- even if we appeared originally within an aspect specification, we
2704 -- are now within the corresponding pragma).
2708 Prag
:= Parent
(Prag
);
2709 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2712 if Present
(Prag
) then
2713 if Uneval_Old_Accept
(Prag
) then
2714 Uneval_Old_Setting
:= 'A';
2715 elsif Uneval_Old_Warn
(Prag
) then
2716 Uneval_Old_Setting
:= 'W';
2718 Uneval_Old_Setting
:= 'E';
2721 -- If we did not find the pragma, that's odd, just use the setting
2722 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2725 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2728 -- Processing depends on the setting of Uneval_Old
2730 case Uneval_Old_Setting
is
2733 ("prefix of attribute % that is potentially "
2734 & "unevaluated must denote an entity");
2737 Error_Msg_Name_1
:= Aname
;
2739 ("??prefix of attribute % appears in potentially "
2740 & "unevaluated context, exception may be raised", P
);
2746 raise Program_Error
;
2750 -------------------------
2751 -- Unexpected Argument --
2752 -------------------------
2754 procedure Unexpected_Argument
(En
: Node_Id
) is
2756 Error_Attr
("unexpected argument for % attribute", En
);
2757 end Unexpected_Argument
;
2759 -------------------------------------------------
2760 -- Validate_Non_Static_Attribute_Function_Call --
2761 -------------------------------------------------
2763 -- This function should be moved to Sem_Dist ???
2765 procedure Validate_Non_Static_Attribute_Function_Call
is
2767 if In_Preelaborated_Unit
2768 and then not In_Subprogram_Or_Concurrent_Unit
2770 Flag_Non_Static_Expr
2771 ("non-static function call in preelaborated unit!", N
);
2773 end Validate_Non_Static_Attribute_Function_Call
;
2775 -- Start of processing for Analyze_Attribute
2778 -- Immediate return if unrecognized attribute (already diagnosed by
2779 -- parser, so there is nothing more that we need to do).
2781 if not Is_Attribute_Name
(Aname
) then
2782 raise Bad_Attribute
;
2785 Check_Restriction_No_Use_Of_Attribute
(N
);
2787 -- Deal with Ada 83 issues
2789 if Comes_From_Source
(N
) then
2790 if not Attribute_83
(Attr_Id
) then
2791 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2792 Error_Msg_Name_1
:= Aname
;
2793 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2796 if Attribute_Impl_Def
(Attr_Id
) then
2797 Check_Restriction
(No_Implementation_Attributes
, N
);
2802 -- Deal with Ada 2005 attributes that are implementation attributes
2803 -- because they appear in a version of Ada before Ada 2005, and
2804 -- similarly for Ada 2012 attributes appearing in an earlier version.
2806 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2808 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2810 Check_Restriction
(No_Implementation_Attributes
, N
);
2813 -- Remote access to subprogram type access attribute reference needs
2814 -- unanalyzed copy for tree transformation. The analyzed copy is used
2815 -- for its semantic information (whether prefix is a remote subprogram
2816 -- name), the unanalyzed copy is used to construct new subtree rooted
2817 -- with N_Aggregate which represents a fat pointer aggregate.
2819 if Aname
= Name_Access
then
2820 Discard_Node
(Copy_Separate_Tree
(N
));
2823 -- Analyze prefix and exit if error in analysis. If the prefix is an
2824 -- incomplete type, use full view if available. Note that there are
2825 -- some attributes for which we do not analyze the prefix, since the
2826 -- prefix is not a normal name, or else needs special handling.
2828 if Aname
/= Name_Elab_Body
and then
2829 Aname
/= Name_Elab_Spec
and then
2830 Aname
/= Name_Elab_Subp_Body
and then
2831 Aname
/= Name_Enabled
and then
2835 P_Type
:= Etype
(P
);
2837 if Is_Entity_Name
(P
)
2838 and then Present
(Entity
(P
))
2839 and then Is_Type
(Entity
(P
))
2841 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2842 P_Type
:= Get_Full_View
(P_Type
);
2843 Set_Entity
(P
, P_Type
);
2844 Set_Etype
(P
, P_Type
);
2846 elsif Entity
(P
) = Current_Scope
2847 and then Is_Record_Type
(Entity
(P
))
2849 -- Use of current instance within the type. Verify that if the
2850 -- attribute appears within a constraint, it yields an access
2851 -- type, other uses are illegal.
2859 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2861 Par
:= Parent
(Par
);
2865 and then Nkind
(Par
) = N_Subtype_Indication
2867 if Attr_Id
/= Attribute_Access
2868 and then Attr_Id
/= Attribute_Unchecked_Access
2869 and then Attr_Id
/= Attribute_Unrestricted_Access
2872 ("in a constraint the current instance can only "
2873 & "be used with an access attribute", N
);
2880 if P_Type
= Any_Type
then
2881 raise Bad_Attribute
;
2884 P_Base_Type
:= Base_Type
(P_Type
);
2887 -- Analyze expressions that may be present, exiting if an error occurs
2894 E1
:= First
(Exprs
);
2896 -- Skip analysis for case of Restriction_Set, we do not expect
2897 -- the argument to be analyzed in this case.
2899 if Aname
/= Name_Restriction_Set
then
2902 -- Check for missing/bad expression (result of previous error)
2904 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2905 raise Bad_Attribute
;
2911 if Present
(E2
) then
2914 if Etype
(E2
) = Any_Type
then
2915 raise Bad_Attribute
;
2918 if Present
(Next
(E2
)) then
2919 Unexpected_Argument
(Next
(E2
));
2924 -- Cases where prefix must be resolvable by itself
2926 if Is_Overloaded
(P
)
2927 and then Aname
/= Name_Access
2928 and then Aname
/= Name_Address
2929 and then Aname
/= Name_Code_Address
2930 and then Aname
/= Name_Result
2931 and then Aname
/= Name_Unchecked_Access
2933 -- The prefix must be resolvable by itself, without reference to the
2934 -- attribute. One case that requires special handling is a prefix
2935 -- that is a function name, where one interpretation may be a
2936 -- parameterless call. Entry attributes are handled specially below.
2938 if Is_Entity_Name
(P
)
2939 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2941 Check_Parameterless_Call
(P
);
2944 if Is_Overloaded
(P
) then
2946 -- Ada 2005 (AI-345): Since protected and task types have
2947 -- primitive entry wrappers, the attributes Count, and Caller
2948 -- require a context check
2950 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2952 Count
: Natural := 0;
2957 Get_First_Interp
(P
, I
, It
);
2958 while Present
(It
.Nam
) loop
2959 if Comes_From_Source
(It
.Nam
) then
2965 Get_Next_Interp
(I
, It
);
2969 Error_Attr
("ambiguous prefix for % attribute", P
);
2971 Set_Is_Overloaded
(P
, False);
2976 Error_Attr
("ambiguous prefix for % attribute", P
);
2981 -- In SPARK, attributes of private types are only allowed if the full
2982 -- type declaration is visible.
2984 -- Note: the check for Present (Entity (P)) defends against some error
2985 -- conditions where the Entity field is not set.
2987 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2988 and then Is_Type
(Entity
(P
))
2989 and then Is_Private_Type
(P_Type
)
2990 and then not In_Open_Scopes
(Scope
(P_Type
))
2991 and then not In_Spec_Expression
2993 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
2996 -- Remaining processing depends on attribute
3000 -- Attributes related to Ada 2012 iterators. Attribute specifications
3001 -- exist for these, but they cannot be queried.
3003 when Attribute_Constant_Indexing
3004 | Attribute_Default_Iterator
3005 | Attribute_Implicit_Dereference
3006 | Attribute_Iterator_Element
3007 | Attribute_Iterable
3008 | Attribute_Variable_Indexing
3010 Error_Msg_N
("illegal attribute", N
);
3012 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
3013 -- were already rejected by the parser. Thus they shouldn't appear here.
3015 when Internal_Attribute_Id
=>
3016 raise Program_Error
;
3022 when Attribute_Abort_Signal
=>
3023 Check_Standard_Prefix
;
3024 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
3031 when Attribute_Access
=>
3032 Analyze_Access_Attribute
;
3033 Check_Not_Incomplete_Type
;
3039 when Attribute_Address
=>
3042 Check_Not_Incomplete_Type
;
3043 Set_Etype
(N
, RTE
(RE_Address
));
3049 when Attribute_Address_Size
=>
3050 Standard_Attribute
(System_Address_Size
);
3056 when Attribute_Adjacent
=>
3057 Check_Floating_Point_Type_2
;
3058 Set_Etype
(N
, P_Base_Type
);
3059 Resolve
(E1
, P_Base_Type
);
3060 Resolve
(E2
, P_Base_Type
);
3066 when Attribute_Aft
=>
3067 Check_Fixed_Point_Type_0
;
3068 Set_Etype
(N
, Universal_Integer
);
3074 when Attribute_Alignment
=>
3076 -- Don't we need more checking here, cf Size ???
3079 Check_Not_Incomplete_Type
;
3081 Set_Etype
(N
, Universal_Integer
);
3087 when Attribute_Asm_Input
=>
3088 Check_Asm_Attribute
;
3090 -- The back end may need to take the address of E2
3092 if Is_Entity_Name
(E2
) then
3093 Set_Address_Taken
(Entity
(E2
));
3096 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3102 when Attribute_Asm_Output
=>
3103 Check_Asm_Attribute
;
3105 if Etype
(E2
) = Any_Type
then
3108 elsif Aname
= Name_Asm_Output
then
3109 if not Is_Variable
(E2
) then
3111 ("second argument for Asm_Output is not variable", E2
);
3115 Note_Possible_Modification
(E2
, Sure
=> True);
3117 -- The back end may need to take the address of E2
3119 if Is_Entity_Name
(E2
) then
3120 Set_Address_Taken
(Entity
(E2
));
3123 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3125 -----------------------------
3126 -- Atomic_Always_Lock_Free --
3127 -----------------------------
3129 when Attribute_Atomic_Always_Lock_Free
=>
3132 Set_Etype
(N
, Standard_Boolean
);
3138 -- Note: when the base attribute appears in the context of a subtype
3139 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3140 -- the following circuit.
3142 when Attribute_Base
=> Base
: declare
3150 if Ada_Version
>= Ada_95
3151 and then not Is_Scalar_Type
(Typ
)
3152 and then not Is_Generic_Type
(Typ
)
3154 Error_Attr_P
("prefix of Base attribute must be scalar type");
3156 elsif Sloc
(Typ
) = Standard_Location
3157 and then Base_Type
(Typ
) = Typ
3158 and then Warn_On_Redundant_Constructs
3160 Error_Msg_NE
-- CODEFIX
3161 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3164 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
3165 Error_Msg_Name_1
:= Aname
;
3166 Check_SPARK_05_Restriction
3167 ("attribute% is only allowed as prefix of another attribute", P
);
3170 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3171 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3172 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3180 when Attribute_Bit
=>
3183 if not Is_Object_Reference
(P
) then
3184 Error_Attr_P
("prefix for % attribute must be object");
3186 -- What about the access object cases ???
3192 Set_Etype
(N
, Universal_Integer
);
3198 when Attribute_Bit_Order
=>
3202 if not Is_Record_Type
(P_Type
) then
3203 Error_Attr_P
("prefix of % attribute must be record type");
3206 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3208 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3211 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3214 Set_Etype
(N
, RTE
(RE_Bit_Order
));
3217 -- Reset incorrect indication of staticness
3219 Set_Is_Static_Expression
(N
, False);
3225 -- Note: in generated code, we can have a Bit_Position attribute
3226 -- applied to a (naked) record component (i.e. the prefix is an
3227 -- identifier that references an E_Component or E_Discriminant
3228 -- entity directly, and this is interpreted as expected by Gigi.
3229 -- The following code will not tolerate such usage, but when the
3230 -- expander creates this special case, it marks it as analyzed
3231 -- immediately and sets an appropriate type.
3233 when Attribute_Bit_Position
=>
3234 if Comes_From_Source
(N
) then
3238 Set_Etype
(N
, Universal_Integer
);
3244 when Attribute_Body_Version
=>
3247 Set_Etype
(N
, RTE
(RE_Version_String
));
3253 when Attribute_Callable
=>
3255 Set_Etype
(N
, Standard_Boolean
);
3262 when Attribute_Caller
=> Caller
: declare
3269 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3272 if not Is_Entry
(Ent
) then
3273 Error_Attr
("invalid entry name", N
);
3277 Error_Attr
("invalid entry name", N
);
3281 for J
in reverse 0 .. Scope_Stack
.Last
loop
3282 S
:= Scope_Stack
.Table
(J
).Entity
;
3284 if S
= Scope
(Ent
) then
3285 Error_Attr
("Caller must appear in matching accept or body", N
);
3291 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3298 when Attribute_Ceiling
=>
3299 Check_Floating_Point_Type_1
;
3300 Set_Etype
(N
, P_Base_Type
);
3301 Resolve
(E1
, P_Base_Type
);
3307 when Attribute_Class
=>
3308 Check_Restriction
(No_Dispatch
, N
);
3312 -- Applying Class to untagged incomplete type is obsolescent in Ada
3313 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3314 -- this flag gets set by Find_Type in this situation.
3316 if Restriction_Check_Required
(No_Obsolescent_Features
)
3317 and then Ada_Version
>= Ada_2005
3318 and then Ekind
(P_Type
) = E_Incomplete_Type
3321 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3323 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3324 and then not Tagged_Present
(DN
)
3326 Check_Restriction
(No_Obsolescent_Features
, P
);
3335 when Attribute_Code_Address
=>
3338 if Nkind
(P
) = N_Attribute_Reference
3339 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
3343 elsif not Is_Entity_Name
(P
)
3344 or else (Ekind
(Entity
(P
)) /= E_Function
3346 Ekind
(Entity
(P
)) /= E_Procedure
)
3348 Error_Attr
("invalid prefix for % attribute", P
);
3349 Set_Address_Taken
(Entity
(P
));
3351 -- Issue an error if the prefix denotes an eliminated subprogram
3354 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3357 Set_Etype
(N
, RTE
(RE_Address
));
3359 ----------------------
3360 -- Compiler_Version --
3361 ----------------------
3363 when Attribute_Compiler_Version
=>
3365 Check_Standard_Prefix
;
3366 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3367 Analyze_And_Resolve
(N
, Standard_String
);
3368 Set_Is_Static_Expression
(N
, True);
3370 --------------------
3371 -- Component_Size --
3372 --------------------
3374 when Attribute_Component_Size
=>
3376 Set_Etype
(N
, Universal_Integer
);
3378 -- Note: unlike other array attributes, unconstrained arrays are OK
3380 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3390 when Attribute_Compose
=>
3391 Check_Floating_Point_Type_2
;
3392 Set_Etype
(N
, P_Base_Type
);
3393 Resolve
(E1
, P_Base_Type
);
3394 Resolve
(E2
, Any_Integer
);
3400 when Attribute_Constrained
=>
3402 Set_Etype
(N
, Standard_Boolean
);
3404 -- Case from RM J.4(2) of constrained applied to private type
3406 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3407 Check_Restriction
(No_Obsolescent_Features
, P
);
3409 if Warn_On_Obsolescent_Feature
then
3411 ("constrained for private type is an obsolescent feature "
3412 & "(RM J.4)?j?", N
);
3415 -- If we are within an instance, the attribute must be legal
3416 -- because it was valid in the generic unit. Ditto if this is
3417 -- an inlining of a function declared in an instance.
3419 if In_Instance
or else In_Inlined_Body
then
3422 -- For sure OK if we have a real private type itself, but must
3423 -- be completed, cannot apply Constrained to incomplete type.
3425 elsif Is_Private_Type
(Entity
(P
)) then
3427 -- Note: this is one of the Annex J features that does not
3428 -- generate a warning from -gnatwj, since in fact it seems
3429 -- very useful, and is used in the GNAT runtime.
3431 Check_Not_Incomplete_Type
;
3435 -- Normal (non-obsolescent case) of application to object of
3436 -- a discriminated type.
3439 Check_Object_Reference
(P
);
3441 -- If N does not come from source, then we allow the
3442 -- the attribute prefix to be of a private type whose
3443 -- full type has discriminants. This occurs in cases
3444 -- involving expanded calls to stream attributes.
3446 if not Comes_From_Source
(N
) then
3447 P_Type
:= Underlying_Type
(P_Type
);
3450 -- Must have discriminants or be an access type designating a type
3451 -- with discriminants. If it is a class-wide type it has unknown
3454 if Has_Discriminants
(P_Type
)
3455 or else Has_Unknown_Discriminants
(P_Type
)
3457 (Is_Access_Type
(P_Type
)
3458 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3462 -- The rule given in 3.7.2 is part of static semantics, but the
3463 -- intent is clearly that it be treated as a legality rule, and
3464 -- rechecked in the visible part of an instance. Nevertheless
3465 -- the intent also seems to be it should legally apply to the
3466 -- actual of a formal with unknown discriminants, regardless of
3467 -- whether the actual has discriminants, in which case the value
3468 -- of the attribute is determined using the J.4 rules. This choice
3469 -- seems the most useful, and is compatible with existing tests.
3471 elsif In_Instance
then
3474 -- Also allow an object of a generic type if extensions allowed
3475 -- and allow this for any type at all. (this may be obsolete ???)
3477 elsif (Is_Generic_Type
(P_Type
)
3478 or else Is_Generic_Actual_Type
(P_Type
))
3479 and then Extensions_Allowed
3485 -- Fall through if bad prefix
3488 ("prefix of % attribute must be object of discriminated type");
3494 when Attribute_Copy_Sign
=>
3495 Check_Floating_Point_Type_2
;
3496 Set_Etype
(N
, P_Base_Type
);
3497 Resolve
(E1
, P_Base_Type
);
3498 Resolve
(E2
, P_Base_Type
);
3504 when Attribute_Count
=> Count
: declare
3512 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3515 if Ekind
(Ent
) /= E_Entry
then
3516 Error_Attr
("invalid entry name", N
);
3519 elsif Nkind
(P
) = N_Indexed_Component
then
3520 if not Is_Entity_Name
(Prefix
(P
))
3521 or else No
(Entity
(Prefix
(P
)))
3522 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3524 if Nkind
(Prefix
(P
)) = N_Selected_Component
3525 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3526 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3530 ("attribute % must apply to entry of current task", P
);
3533 Error_Attr
("invalid entry family name", P
);
3538 Ent
:= Entity
(Prefix
(P
));
3541 elsif Nkind
(P
) = N_Selected_Component
3542 and then Present
(Entity
(Selector_Name
(P
)))
3543 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3546 ("attribute % must apply to entry of current task", P
);
3549 Error_Attr
("invalid entry name", N
);
3553 for J
in reverse 0 .. Scope_Stack
.Last
loop
3554 S
:= Scope_Stack
.Table
(J
).Entity
;
3556 if S
= Scope
(Ent
) then
3557 if Nkind
(P
) = N_Expanded_Name
then
3558 Tsk
:= Entity
(Prefix
(P
));
3560 -- The prefix denotes either the task type, or else a
3561 -- single task whose task type is being analyzed.
3563 if (Is_Type
(Tsk
) and then Tsk
= S
)
3564 or else (not Is_Type
(Tsk
)
3565 and then Etype
(Tsk
) = S
3566 and then not (Comes_From_Source
(S
)))
3571 ("Attribute % must apply to entry of current task", N
);
3577 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3578 and then not Ekind_In
(S
, E_Block
,
3583 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3585 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3586 and then not Has_Completion
(Scope
(Ent
))
3588 Error_Attr
("attribute % can only be used inside body", N
);
3592 if Is_Overloaded
(P
) then
3594 Index
: Interp_Index
;
3598 Get_First_Interp
(P
, Index
, It
);
3599 while Present
(It
.Nam
) loop
3600 if It
.Nam
= Ent
then
3603 -- Ada 2005 (AI-345): Do not consider primitive entry
3604 -- wrappers generated for task or protected types.
3606 elsif Ada_Version
>= Ada_2005
3607 and then not Comes_From_Source
(It
.Nam
)
3612 Error_Attr
("ambiguous entry name", N
);
3615 Get_Next_Interp
(Index
, It
);
3620 Set_Etype
(N
, Universal_Integer
);
3623 -----------------------
3624 -- Default_Bit_Order --
3625 -----------------------
3627 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
3628 Target_Default_Bit_Order
: System
.Bit_Order
;
3631 Check_Standard_Prefix
;
3633 if Bytes_Big_Endian
then
3634 Target_Default_Bit_Order
:= System
.High_Order_First
;
3636 Target_Default_Bit_Order
:= System
.Low_Order_First
;
3640 Make_Integer_Literal
(Loc
,
3641 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
3643 Set_Etype
(N
, Universal_Integer
);
3644 Set_Is_Static_Expression
(N
);
3645 end Default_Bit_Order
;
3647 ----------------------------------
3648 -- Default_Scalar_Storage_Order --
3649 ----------------------------------
3651 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
3652 RE_Default_SSO
: RE_Id
;
3655 Check_Standard_Prefix
;
3657 case Opt
.Default_SSO
is
3659 if Bytes_Big_Endian
then
3660 RE_Default_SSO
:= RE_High_Order_First
;
3662 RE_Default_SSO
:= RE_Low_Order_First
;
3666 RE_Default_SSO
:= RE_High_Order_First
;
3669 RE_Default_SSO
:= RE_Low_Order_First
;
3672 raise Program_Error
;
3675 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
3682 when Attribute_Definite
=>
3683 Legal_Formal_Attribute
;
3689 when Attribute_Delta
=>
3690 Check_Fixed_Point_Type_0
;
3691 Set_Etype
(N
, Universal_Real
);
3697 when Attribute_Denorm
=>
3698 Check_Floating_Point_Type_0
;
3699 Set_Etype
(N
, Standard_Boolean
);
3705 when Attribute_Deref
=>
3708 Resolve
(E1
, RTE
(RE_Address
));
3709 Set_Etype
(N
, P_Type
);
3711 ---------------------
3712 -- Descriptor_Size --
3713 ---------------------
3715 when Attribute_Descriptor_Size
=>
3718 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3719 Error_Attr_P
("prefix of attribute % must denote a type");
3722 Set_Etype
(N
, Universal_Integer
);
3728 when Attribute_Digits
=>
3732 if not Is_Floating_Point_Type
(P_Type
)
3733 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3736 ("prefix of % attribute must be float or decimal type");
3739 Set_Etype
(N
, Universal_Integer
);
3745 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3747 when Attribute_Elab_Body
3748 | Attribute_Elab_Spec
3749 | Attribute_Elab_Subp_Body
3752 Check_Unit_Name
(P
);
3753 Set_Etype
(N
, Standard_Void_Type
);
3755 -- We have to manually call the expander in this case to get
3756 -- the necessary expansion (normally attributes that return
3757 -- entities are not expanded).
3765 -- Shares processing with Elab_Body
3771 when Attribute_Elaborated
=>
3773 Check_Unit_Name
(P
);
3774 Set_Etype
(N
, Standard_Boolean
);
3780 when Attribute_Emax
=>
3781 Check_Floating_Point_Type_0
;
3782 Set_Etype
(N
, Universal_Integer
);
3788 when Attribute_Enabled
=>
3789 Check_Either_E0_Or_E1
;
3791 if Present
(E1
) then
3792 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3793 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3798 if Nkind
(P
) /= N_Identifier
then
3799 Error_Msg_N
("identifier expected (check name)", P
);
3800 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3801 Error_Msg_N
("& is not a recognized check name", P
);
3804 Set_Etype
(N
, Standard_Boolean
);
3810 when Attribute_Enum_Rep
=>
3812 -- T'Enum_Rep (X) case
3814 if Present
(E1
) then
3816 Check_Discrete_Type
;
3817 Resolve
(E1
, P_Base_Type
);
3819 -- X'Enum_Rep case. X must be an object or enumeration literal, and
3820 -- it must be of a discrete type.
3823 ((Is_Object_Reference
(P
)
3826 and then Ekind
(Entity
(P
)) = E_Enumeration_Literal
))
3827 and then Is_Discrete_Type
(Etype
(P
)))
3829 Error_Attr_P
("prefix of % attribute must be discrete object");
3832 Set_Etype
(N
, Universal_Integer
);
3838 when Attribute_Enum_Val
=>
3842 if not Is_Enumeration_Type
(P_Type
) then
3843 Error_Attr_P
("prefix of % attribute must be enumeration type");
3846 -- If the enumeration type has a standard representation, the effect
3847 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3849 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3851 Make_Attribute_Reference
(Loc
,
3852 Prefix
=> Relocate_Node
(Prefix
(N
)),
3853 Attribute_Name
=> Name_Val
,
3854 Expressions
=> New_List
(Relocate_Node
(E1
))));
3855 Analyze_And_Resolve
(N
, P_Base_Type
);
3857 -- Non-standard representation case (enumeration with holes)
3861 Resolve
(E1
, Any_Integer
);
3862 Set_Etype
(N
, P_Base_Type
);
3869 when Attribute_Epsilon
=>
3870 Check_Floating_Point_Type_0
;
3871 Set_Etype
(N
, Universal_Real
);
3877 when Attribute_Exponent
=>
3878 Check_Floating_Point_Type_1
;
3879 Set_Etype
(N
, Universal_Integer
);
3880 Resolve
(E1
, P_Base_Type
);
3886 when Attribute_External_Tag
=>
3890 Set_Etype
(N
, Standard_String
);
3892 if not Is_Tagged_Type
(P_Type
) then
3893 Error_Attr_P
("prefix of % attribute must be tagged");
3900 when Attribute_Fast_Math
=>
3901 Check_Standard_Prefix
;
3902 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3904 -----------------------
3905 -- Finalization_Size --
3906 -----------------------
3908 when Attribute_Finalization_Size
=>
3911 -- The prefix denotes an object
3913 if Is_Object_Reference
(P
) then
3914 Check_Object_Reference
(P
);
3916 -- The prefix denotes a type
3918 elsif Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3920 Check_Not_Incomplete_Type
;
3922 -- Attribute 'Finalization_Size is not defined for class-wide
3923 -- types because it is not possible to know statically whether
3924 -- a definite type will have controlled components or not.
3926 if Is_Class_Wide_Type
(Etype
(P
)) then
3928 ("prefix of % attribute cannot denote a class-wide type");
3931 -- The prefix denotes an illegal construct
3935 ("prefix of % attribute must be a definite type or an object");
3938 Set_Etype
(N
, Universal_Integer
);
3944 when Attribute_First
=>
3945 Check_Array_Or_Scalar_Type
;
3946 Bad_Attribute_For_Predicate
;
3952 when Attribute_First_Bit
=>
3954 Set_Etype
(N
, Universal_Integer
);
3960 when Attribute_First_Valid
=>
3961 Check_First_Last_Valid
;
3962 Set_Etype
(N
, P_Type
);
3968 when Attribute_Fixed_Value
=>
3970 Check_Fixed_Point_Type
;
3971 Resolve
(E1
, Any_Integer
);
3972 Set_Etype
(N
, P_Base_Type
);
3978 when Attribute_Floor
=>
3979 Check_Floating_Point_Type_1
;
3980 Set_Etype
(N
, P_Base_Type
);
3981 Resolve
(E1
, P_Base_Type
);
3987 when Attribute_Fore
=>
3988 Check_Fixed_Point_Type_0
;
3989 Set_Etype
(N
, Universal_Integer
);
3995 when Attribute_Fraction
=>
3996 Check_Floating_Point_Type_1
;
3997 Set_Etype
(N
, P_Base_Type
);
3998 Resolve
(E1
, P_Base_Type
);
4004 when Attribute_From_Any
=>
4006 Check_PolyORB_Attribute
;
4007 Set_Etype
(N
, P_Base_Type
);
4009 -----------------------
4010 -- Has_Access_Values --
4011 -----------------------
4013 when Attribute_Has_Access_Values
=>
4016 Set_Etype
(N
, Standard_Boolean
);
4018 ----------------------
4019 -- Has_Same_Storage --
4020 ----------------------
4022 when Attribute_Has_Same_Storage
=>
4025 -- The arguments must be objects of any type
4027 Analyze_And_Resolve
(P
);
4028 Analyze_And_Resolve
(E1
);
4029 Check_Object_Reference
(P
);
4030 Check_Object_Reference
(E1
);
4031 Set_Etype
(N
, Standard_Boolean
);
4033 -----------------------
4034 -- Has_Tagged_Values --
4035 -----------------------
4037 when Attribute_Has_Tagged_Values
=>
4040 Set_Etype
(N
, Standard_Boolean
);
4042 -----------------------
4043 -- Has_Discriminants --
4044 -----------------------
4046 when Attribute_Has_Discriminants
=>
4047 Legal_Formal_Attribute
;
4053 when Attribute_Identity
=>
4057 if Etype
(P
) = Standard_Exception_Type
then
4058 Set_Etype
(N
, RTE
(RE_Exception_Id
));
4060 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
4061 -- interface class-wide types.
4063 elsif Is_Task_Type
(Etype
(P
))
4064 or else (Is_Access_Type
(Etype
(P
))
4065 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
4066 or else (Ada_Version
>= Ada_2005
4067 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
4068 and then Is_Interface
(Etype
(P
))
4069 and then Is_Task_Interface
(Etype
(P
)))
4072 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
4075 if Ada_Version
>= Ada_2005
then
4077 ("prefix of % attribute must be an exception, a task or a "
4078 & "task interface class-wide object");
4081 ("prefix of % attribute must be a task or an exception");
4089 when Attribute_Image
=>
4090 if Is_Real_Type
(P_Type
) then
4091 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4092 Error_Msg_Name_1
:= Aname
;
4094 ("(Ada 83) % attribute not allowed for real types", N
);
4098 Analyze_Image_Attribute
(Standard_String
);
4104 when Attribute_Img
=>
4105 Analyze_Image_Attribute
(Standard_String
);
4111 when Attribute_Input
=>
4113 Check_Stream_Attribute
(TSS_Stream_Input
);
4114 Set_Etype
(N
, P_Base_Type
);
4120 when Attribute_Integer_Value
=>
4123 Resolve
(E1
, Any_Fixed
);
4125 -- Signal an error if argument type is not a specific fixed-point
4126 -- subtype. An error has been signalled already if the argument
4127 -- was not of a fixed-point type.
4129 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4130 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4133 Set_Etype
(N
, P_Base_Type
);
4139 when Attribute_Invalid_Value
=>
4142 Set_Etype
(N
, P_Base_Type
);
4143 Invalid_Value_Used
:= True;
4149 when Attribute_Large
=>
4152 Set_Etype
(N
, Universal_Real
);
4158 when Attribute_Last
=>
4159 Check_Array_Or_Scalar_Type
;
4160 Bad_Attribute_For_Predicate
;
4166 when Attribute_Last_Bit
=>
4168 Set_Etype
(N
, Universal_Integer
);
4174 when Attribute_Last_Valid
=>
4175 Check_First_Last_Valid
;
4176 Set_Etype
(N
, P_Type
);
4182 when Attribute_Leading_Part
=>
4183 Check_Floating_Point_Type_2
;
4184 Set_Etype
(N
, P_Base_Type
);
4185 Resolve
(E1
, P_Base_Type
);
4186 Resolve
(E2
, Any_Integer
);
4192 when Attribute_Length
=>
4194 Set_Etype
(N
, Universal_Integer
);
4200 when Attribute_Library_Level
=>
4203 if not Is_Entity_Name
(P
) then
4204 Error_Attr_P
("prefix of % attribute must be an entity name");
4207 if not Inside_A_Generic
then
4208 Set_Boolean_Result
(N
,
4209 Is_Library_Level_Entity
(Entity
(P
)));
4212 Set_Etype
(N
, Standard_Boolean
);
4218 when Attribute_Lock_Free
=>
4220 Set_Etype
(N
, Standard_Boolean
);
4222 if not Is_Protected_Type
(P_Type
) then
4224 ("prefix of % attribute must be a protected object");
4231 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4232 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4233 -- Inspect the prefix for any uses of entities declared within the
4234 -- related loop. Loop_Id denotes the loop identifier.
4236 --------------------------------
4237 -- Check_References_In_Prefix --
4238 --------------------------------
4240 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4241 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4243 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4244 -- Determine whether a reference mentions an entity declared
4245 -- within the related loop.
4247 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4248 -- Determine whether Nod appears in the subtree of Loop_Decl
4250 ---------------------
4251 -- Check_Reference --
4252 ---------------------
4254 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4256 if Nkind
(Nod
) = N_Identifier
4257 and then Present
(Entity
(Nod
))
4258 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4261 ("prefix of attribute % cannot reference local entities",
4267 end Check_Reference
;
4269 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4271 ---------------------
4272 -- Declared_Within --
4273 ---------------------
4275 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4280 while Present
(Stmt
) loop
4281 if Stmt
= Loop_Decl
then
4284 -- Prevent the search from going too far
4286 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4290 Stmt
:= Parent
(Stmt
);
4294 end Declared_Within
;
4296 -- Start of processing for Check_Prefix_For_Local_References
4299 Check_References
(P
);
4300 end Check_References_In_Prefix
;
4304 Context
: constant Node_Id
:= Parent
(N
);
4306 Encl_Loop
: Node_Id
:= Empty
;
4307 Encl_Prag
: Node_Id
:= Empty
;
4308 Loop_Id
: Entity_Id
:= Empty
;
4312 -- Start of processing for Loop_Entry
4317 -- Set the type of the attribute now to ensure the successful
4318 -- continuation of analysis even if the attribute is misplaced.
4320 Set_Etype
(Attr
, P_Type
);
4322 -- Attribute 'Loop_Entry may appear in several flavors:
4324 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4325 -- nearest enclosing loop.
4327 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4328 -- attribute may be related to a loop denoted by label Expr or
4329 -- the prefix may denote an array object and Expr may act as an
4330 -- indexed component.
4332 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4333 -- to the nearest enclosing loop, all expressions are part of
4334 -- an indexed component.
4336 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4337 -- denotes, the attribute may be related to a loop denoted by
4338 -- label Expr or the prefix may denote a multidimensional array
4339 -- array object and Expr along with the rest of the expressions
4340 -- may act as indexed components.
4342 -- Regardless of variations, the attribute reference does not have an
4343 -- expression list. Instead, all available expressions are stored as
4344 -- indexed components.
4346 -- When the attribute is part of an indexed component, find the first
4347 -- expression as it will determine the semantics of 'Loop_Entry.
4349 -- If the attribute is itself an index in an indexed component, i.e.
4350 -- a member of a list, the context itself is not relevant (the code
4351 -- below would lead to an infinite loop) and the attribute applies
4352 -- to the enclosing loop.
4354 if Nkind
(Context
) = N_Indexed_Component
4355 and then not Is_List_Member
(N
)
4357 E1
:= First
(Expressions
(Context
));
4360 -- The attribute reference appears in the following form:
4362 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4364 -- In this case, the loop name is omitted and no rewriting is
4367 if Present
(E2
) then
4370 -- The form of the attribute is:
4372 -- Prefix'Loop_Entry (Expr) [(...)]
4374 -- If Expr denotes a loop entry, the whole attribute and indexed
4375 -- component will have to be rewritten to reflect this relation.
4378 pragma Assert
(Present
(E1
));
4380 -- Do not expand the expression as it may have side effects.
4381 -- Simply preanalyze to determine whether it is a loop name or
4384 Preanalyze_And_Resolve
(E1
);
4386 if Is_Entity_Name
(E1
)
4387 and then Present
(Entity
(E1
))
4388 and then Ekind
(Entity
(E1
)) = E_Loop
4390 Loop_Id
:= Entity
(E1
);
4392 -- Transform the attribute and enclosing indexed component
4394 Set_Expressions
(N
, Expressions
(Context
));
4395 Rewrite
(Context
, N
);
4396 Set_Etype
(Context
, P_Type
);
4403 -- The prefix must denote an object
4405 if not Is_Object_Reference
(P
) then
4406 Error_Attr_P
("prefix of attribute % must denote an object");
4409 -- The prefix cannot be of a limited type because the expansion of
4410 -- Loop_Entry must create a constant initialized by the evaluated
4413 if Is_Limited_View
(Etype
(P
)) then
4414 Error_Attr_P
("prefix of attribute % cannot be limited");
4417 -- Climb the parent chain to verify the location of the attribute and
4418 -- find the enclosing loop.
4421 while Present
(Stmt
) loop
4423 -- Locate the corresponding enclosing pragma. Note that in the
4424 -- case of Assert[And_Cut] and Assume, we have already checked
4425 -- that the pragma appears in an appropriate loop location.
4427 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4428 and then Nam_In
(Pragma_Name_Unmapped
(Original_Node
(Stmt
)),
4429 Name_Loop_Invariant
,
4432 Name_Assert_And_Cut
,
4435 Encl_Prag
:= Original_Node
(Stmt
);
4437 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4438 -- iteration may be expanded into several nested loops, we are
4439 -- interested in the outermost one which has the loop identifier,
4440 -- and comes from source.
4442 elsif Nkind
(Stmt
) = N_Loop_Statement
4443 and then Present
(Identifier
(Stmt
))
4444 and then Comes_From_Source
(Original_Node
(Stmt
))
4445 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
4449 -- The original attribute reference may lack a loop name. Use
4450 -- the name of the enclosing loop because it is the related
4453 if No
(Loop_Id
) then
4454 Loop_Id
:= Entity
(Identifier
(Encl_Loop
));
4459 -- Prevent the search from going too far
4461 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4465 Stmt
:= Parent
(Stmt
);
4468 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4469 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4470 -- purpose if they appear in an appropriate location in a loop,
4471 -- which was already checked by the top level pragma circuit).
4473 -- Loop_Entry also denotes a value and as such can appear within an
4474 -- expression that is an argument for another loop aspect. In that
4475 -- case it will have been expanded into the corresponding assignment.
4478 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
4479 and then not Comes_From_Source
(Parent
(N
))
4483 elsif No
(Encl_Prag
) then
4484 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4487 -- A Loop_Entry that applies to a given loop statement must not
4488 -- appear within a body of accept statement, if this construct is
4489 -- itself enclosed by the given loop statement.
4491 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4492 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4494 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4496 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4500 ("attribute % cannot appear in body or accept statement", N
);
4505 -- The prefix cannot mention entities declared within the related
4506 -- loop because they will not be visible once the prefix is moved
4507 -- outside the loop.
4509 Check_References_In_Prefix
(Loop_Id
);
4511 -- The prefix must denote a static entity if the pragma does not
4512 -- apply to the innermost enclosing loop statement, or if it appears
4513 -- within a potentially unevaluated epxression.
4515 if Is_Entity_Name
(P
)
4516 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4517 or else Statically_Denotes_Object
(P
)
4521 elsif Present
(Encl_Loop
)
4522 and then Entity
(Identifier
(Encl_Loop
)) /= Loop_Id
4525 ("prefix of attribute % that applies to outer loop must denote "
4528 elsif Is_Potentially_Unevaluated
(P
) then
4532 -- Replace the Loop_Entry attribute reference by its prefix if the
4533 -- related pragma is ignored. This transformation is OK with respect
4534 -- to typing because Loop_Entry's type is that of its prefix. This
4535 -- early transformation also avoids the generation of a useless loop
4538 if Present
(Encl_Prag
) and then Is_Ignored
(Encl_Prag
) then
4539 Rewrite
(N
, Relocate_Node
(P
));
4540 Preanalyze_And_Resolve
(N
);
4543 Preanalyze_And_Resolve
(P
);
4551 when Attribute_Machine
=>
4552 Check_Floating_Point_Type_1
;
4553 Set_Etype
(N
, P_Base_Type
);
4554 Resolve
(E1
, P_Base_Type
);
4560 when Attribute_Machine_Emax
=>
4561 Check_Floating_Point_Type_0
;
4562 Set_Etype
(N
, Universal_Integer
);
4568 when Attribute_Machine_Emin
=>
4569 Check_Floating_Point_Type_0
;
4570 Set_Etype
(N
, Universal_Integer
);
4572 ----------------------
4573 -- Machine_Mantissa --
4574 ----------------------
4576 when Attribute_Machine_Mantissa
=>
4577 Check_Floating_Point_Type_0
;
4578 Set_Etype
(N
, Universal_Integer
);
4580 -----------------------
4581 -- Machine_Overflows --
4582 -----------------------
4584 when Attribute_Machine_Overflows
=>
4587 Set_Etype
(N
, Standard_Boolean
);
4593 when Attribute_Machine_Radix
=>
4596 Set_Etype
(N
, Universal_Integer
);
4598 ----------------------
4599 -- Machine_Rounding --
4600 ----------------------
4602 when Attribute_Machine_Rounding
=>
4603 Check_Floating_Point_Type_1
;
4604 Set_Etype
(N
, P_Base_Type
);
4605 Resolve
(E1
, P_Base_Type
);
4607 --------------------
4608 -- Machine_Rounds --
4609 --------------------
4611 when Attribute_Machine_Rounds
=>
4614 Set_Etype
(N
, Standard_Boolean
);
4620 when Attribute_Machine_Size
=>
4623 Check_Not_Incomplete_Type
;
4624 Set_Etype
(N
, Universal_Integer
);
4630 when Attribute_Mantissa
=>
4633 Set_Etype
(N
, Universal_Integer
);
4639 when Attribute_Max
=>
4642 ----------------------------------
4643 -- Max_Alignment_For_Allocation --
4644 ----------------------------------
4646 when Attribute_Max_Size_In_Storage_Elements
=>
4647 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4649 ----------------------------------
4650 -- Max_Size_In_Storage_Elements --
4651 ----------------------------------
4653 when Attribute_Max_Alignment_For_Allocation
=>
4654 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4656 -----------------------
4657 -- Maximum_Alignment --
4658 -----------------------
4660 when Attribute_Maximum_Alignment
=>
4661 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4663 --------------------
4664 -- Mechanism_Code --
4665 --------------------
4667 when Attribute_Mechanism_Code
=>
4668 if not Is_Entity_Name
(P
)
4669 or else not Is_Subprogram
(Entity
(P
))
4671 Error_Attr_P
("prefix of % attribute must be subprogram");
4674 Check_Either_E0_Or_E1
;
4676 if Present
(E1
) then
4677 Resolve
(E1
, Any_Integer
);
4678 Set_Etype
(E1
, Standard_Integer
);
4680 if not Is_OK_Static_Expression
(E1
) then
4681 Flag_Non_Static_Expr
4682 ("expression for parameter number must be static!", E1
);
4685 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4686 or else UI_To_Int
(Intval
(E1
)) < 0
4688 Error_Attr
("invalid parameter number for % attribute", E1
);
4692 Set_Etype
(N
, Universal_Integer
);
4698 when Attribute_Min
=>
4705 when Attribute_Mod
=>
4707 -- Note: this attribute is only allowed in Ada 2005 mode, but
4708 -- we do not need to test that here, since Mod is only recognized
4709 -- as an attribute name in Ada 2005 mode during the parse.
4712 Check_Modular_Integer_Type
;
4713 Resolve
(E1
, Any_Integer
);
4714 Set_Etype
(N
, P_Base_Type
);
4720 when Attribute_Model
=>
4721 Check_Floating_Point_Type_1
;
4722 Set_Etype
(N
, P_Base_Type
);
4723 Resolve
(E1
, P_Base_Type
);
4729 when Attribute_Model_Emin
=>
4730 Check_Floating_Point_Type_0
;
4731 Set_Etype
(N
, Universal_Integer
);
4737 when Attribute_Model_Epsilon
=>
4738 Check_Floating_Point_Type_0
;
4739 Set_Etype
(N
, Universal_Real
);
4741 --------------------
4742 -- Model_Mantissa --
4743 --------------------
4745 when Attribute_Model_Mantissa
=>
4746 Check_Floating_Point_Type_0
;
4747 Set_Etype
(N
, Universal_Integer
);
4753 when Attribute_Model_Small
=>
4754 Check_Floating_Point_Type_0
;
4755 Set_Etype
(N
, Universal_Real
);
4761 when Attribute_Modulus
=>
4763 Check_Modular_Integer_Type
;
4764 Set_Etype
(N
, Universal_Integer
);
4766 --------------------
4767 -- Null_Parameter --
4768 --------------------
4770 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4771 Parnt
: constant Node_Id
:= Parent
(N
);
4772 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4774 procedure Bad_Null_Parameter
(Msg
: String);
4775 -- Used if bad Null parameter attribute node is found. Issues
4776 -- given error message, and also sets the type to Any_Type to
4777 -- avoid blowups later on from dealing with a junk node.
4779 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4780 -- Called to check that Proc_Ent is imported subprogram
4782 ------------------------
4783 -- Bad_Null_Parameter --
4784 ------------------------
4786 procedure Bad_Null_Parameter
(Msg
: String) is
4788 Error_Msg_N
(Msg
, N
);
4789 Set_Etype
(N
, Any_Type
);
4790 end Bad_Null_Parameter
;
4792 ----------------------
4793 -- Must_Be_Imported --
4794 ----------------------
4796 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4797 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4800 -- Ignore check if procedure not frozen yet (we will get
4801 -- another chance when the default parameter is reanalyzed)
4803 if not Is_Frozen
(Pent
) then
4806 elsif not Is_Imported
(Pent
) then
4808 ("Null_Parameter can only be used with imported subprogram");
4813 end Must_Be_Imported
;
4815 -- Start of processing for Null_Parameter
4820 Set_Etype
(N
, P_Type
);
4822 -- Case of attribute used as default expression
4824 if Nkind
(Parnt
) = N_Parameter_Specification
then
4825 Must_Be_Imported
(Defining_Entity
(GParnt
));
4827 -- Case of attribute used as actual for subprogram (positional)
4829 elsif Nkind
(Parnt
) in N_Subprogram_Call
4830 and then Is_Entity_Name
(Name
(Parnt
))
4832 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4834 -- Case of attribute used as actual for subprogram (named)
4836 elsif Nkind
(Parnt
) = N_Parameter_Association
4837 and then Nkind
(GParnt
) in N_Subprogram_Call
4838 and then Is_Entity_Name
(Name
(GParnt
))
4840 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4842 -- Not an allowed case
4846 ("Null_Parameter must be actual or default parameter");
4854 when Attribute_Object_Size
=>
4857 Check_Not_Incomplete_Type
;
4858 Set_Etype
(N
, Universal_Integer
);
4864 when Attribute_Old
=> Old
: declare
4865 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4866 -- Inspect the contents of the prefix and detect illegal uses of a
4867 -- nested 'Old, attribute 'Result or a use of an entity declared in
4868 -- the related postcondition expression. Subp_Id is the subprogram to
4869 -- which the related postcondition applies.
4871 --------------------------------
4872 -- Check_References_In_Prefix --
4873 --------------------------------
4875 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4876 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4877 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4878 -- and perform the appropriate semantic check.
4880 ---------------------
4881 -- Check_Reference --
4882 ---------------------
4884 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4886 -- Attributes 'Old and 'Result cannot appear in the prefix of
4887 -- another attribute 'Old.
4889 if Nkind
(Nod
) = N_Attribute_Reference
4890 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4893 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4894 Error_Msg_Name_2
:= Name_Old
;
4896 ("attribute % cannot appear in the prefix of attribute %",
4900 -- Entities mentioned within the prefix of attribute 'Old must
4901 -- be global to the related postcondition. If this is not the
4902 -- case, then the scope of the local entity is nested within
4903 -- that of the subprogram.
4905 elsif Is_Entity_Name
(Nod
)
4906 and then Present
(Entity
(Nod
))
4907 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4910 ("prefix of attribute % cannot reference local entities",
4914 -- Otherwise keep inspecting the prefix
4919 end Check_Reference
;
4921 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4923 -- Start of processing for Check_References_In_Prefix
4926 Check_References
(P
);
4927 end Check_References_In_Prefix
;
4932 Pref_Id
: Entity_Id
;
4933 Pref_Typ
: Entity_Id
;
4934 Spec_Id
: Entity_Id
;
4936 -- Start of processing for Old
4939 -- The attribute reference is a primary. If any expressions follow,
4940 -- then the attribute reference is an indexable object. Transform the
4941 -- attribute into an indexed component and analyze it.
4943 if Present
(E1
) then
4945 Make_Indexed_Component
(Loc
,
4947 Make_Attribute_Reference
(Loc
,
4948 Prefix
=> Relocate_Node
(P
),
4949 Attribute_Name
=> Name_Old
),
4950 Expressions
=> Expressions
(N
)));
4955 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
4957 -- The aspect or pragma where attribute 'Old resides should be
4958 -- associated with a subprogram declaration or a body. If this is not
4959 -- the case, then the aspect or pragma is illegal. Return as analysis
4960 -- cannot be carried out.
4962 -- The exception to this rule is when generating C since in this case
4963 -- postconditions are inlined.
4966 and then Modify_Tree_For_C
4967 and then In_Inlined_Body
4969 Spec_Id
:= Entity
(P
);
4971 elsif not Legal
then
4975 -- The prefix must be preanalyzed as the full analysis will take
4976 -- place during expansion.
4978 Preanalyze_And_Resolve
(P
);
4980 -- Ensure that the prefix does not contain attributes 'Old or 'Result
4982 Check_References_In_Prefix
(Spec_Id
);
4984 -- Set the type of the attribute now to prevent cascaded errors
4986 Pref_Typ
:= Etype
(P
);
4987 Set_Etype
(N
, Pref_Typ
);
4991 if Is_Limited_Type
(Pref_Typ
) then
4992 Error_Attr
("attribute % cannot apply to limited objects", P
);
4995 -- The prefix is a simple name
4997 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
4998 Pref_Id
:= Entity
(P
);
5000 -- Emit a warning when the prefix is a constant. Note that the use
5001 -- of Error_Attr would reset the type of N to Any_Type even though
5002 -- this is a warning. Use Error_Msg_XXX instead.
5004 if Is_Constant_Object
(Pref_Id
) then
5005 Error_Msg_Name_1
:= Name_Old
;
5007 ("??attribute % applied to constant has no effect", P
);
5010 -- Otherwise the prefix is not a simple name
5013 -- Ensure that the prefix of attribute 'Old is an entity when it
5014 -- is potentially unevaluated (6.1.1 (27/3)).
5016 if Is_Potentially_Unevaluated
(N
)
5017 and then not Statically_Denotes_Object
(P
)
5021 -- Detect a possible infinite recursion when the prefix denotes
5022 -- the related function.
5024 -- function Func (...) return ...
5025 -- with Post => Func'Old ...;
5027 -- The function may be specified in qualified form X.Y where X is
5028 -- a protected object and Y is a protected function. In that case
5029 -- ensure that the qualified form has an entity.
5031 elsif Nkind
(P
) = N_Function_Call
5032 and then Nkind
(Name
(P
)) in N_Has_Entity
5034 Pref_Id
:= Entity
(Name
(P
));
5036 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
5037 and then Pref_Id
= Spec_Id
5039 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5040 Error_Msg_N
("!possible infinite recursion<<", P
);
5041 Error_Msg_N
("\!??Storage_Error ]<<", P
);
5045 -- The prefix of attribute 'Old may refer to a component of a
5046 -- formal parameter. In this case its expansion may generate
5047 -- actual subtypes that are referenced in an inner context and
5048 -- that must be elaborated within the subprogram itself. If the
5049 -- prefix includes a function call, it may involve finalization
5050 -- actions that should be inserted when the attribute has been
5051 -- rewritten as a declaration. Create a declaration for the prefix
5052 -- and insert it at the start of the enclosing subprogram. This is
5053 -- an expansion activity that has to be performed now to prevent
5054 -- out-of-order issues.
5056 -- This expansion is both harmful and not needed in SPARK mode,
5057 -- since the formal verification back end relies on the types of
5058 -- nodes (hence is not robust w.r.t. a change to base type here),
5059 -- and does not suffer from the out-of-order issue described
5060 -- above. Thus, this expansion is skipped in SPARK mode.
5062 -- The expansion is not relevant for discrete types, which will
5063 -- not generate extra declarations, and where use of the base type
5064 -- may lead to spurious errors if context is a case.
5066 if not GNATprove_Mode
then
5067 if not Is_Discrete_Type
(Pref_Typ
) then
5068 Pref_Typ
:= Base_Type
(Pref_Typ
);
5071 Set_Etype
(N
, Pref_Typ
);
5072 Set_Etype
(P
, Pref_Typ
);
5074 Analyze_Dimension
(N
);
5080 ----------------------
5081 -- Overlaps_Storage --
5082 ----------------------
5084 when Attribute_Overlaps_Storage
=>
5087 -- Both arguments must be objects of any type
5089 Analyze_And_Resolve
(P
);
5090 Analyze_And_Resolve
(E1
);
5091 Check_Object_Reference
(P
);
5092 Check_Object_Reference
(E1
);
5093 Set_Etype
(N
, Standard_Boolean
);
5099 when Attribute_Output
=>
5101 Check_Stream_Attribute
(TSS_Stream_Output
);
5102 Set_Etype
(N
, Standard_Void_Type
);
5103 Resolve
(N
, Standard_Void_Type
);
5109 when Attribute_Partition_ID
=>
5112 if P_Type
/= Any_Type
then
5113 if not Is_Library_Level_Entity
(Entity
(P
)) then
5115 ("prefix of % attribute must be library-level entity");
5117 -- The defining entity of prefix should not be declared inside a
5118 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5120 elsif Is_Entity_Name
(P
)
5121 and then Is_Pure
(Entity
(P
))
5123 Error_Attr_P
("prefix of% attribute must not be declared pure");
5127 Set_Etype
(N
, Universal_Integer
);
5129 -------------------------
5130 -- Passed_By_Reference --
5131 -------------------------
5133 when Attribute_Passed_By_Reference
=>
5136 Set_Etype
(N
, Standard_Boolean
);
5142 when Attribute_Pool_Address
=>
5144 Set_Etype
(N
, RTE
(RE_Address
));
5150 when Attribute_Pos
=>
5151 Check_Discrete_Type
;
5154 if Is_Boolean_Type
(P_Type
) then
5155 Error_Msg_Name_1
:= Aname
;
5156 Error_Msg_Name_2
:= Chars
(P_Type
);
5157 Check_SPARK_05_Restriction
5158 ("attribute% is not allowed for type%", P
);
5161 Resolve
(E1
, P_Base_Type
);
5162 Set_Etype
(N
, Universal_Integer
);
5168 when Attribute_Position
=>
5170 Set_Etype
(N
, Universal_Integer
);
5176 when Attribute_Pred
=>
5180 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5181 Error_Msg_Name_1
:= Aname
;
5182 Error_Msg_Name_2
:= Chars
(P_Type
);
5183 Check_SPARK_05_Restriction
5184 ("attribute% is not allowed for type%", P
);
5187 Resolve
(E1
, P_Base_Type
);
5188 Set_Etype
(N
, P_Base_Type
);
5190 -- Since Pred works on the base type, we normally do no check for the
5191 -- floating-point case, since the base type is unconstrained. But we
5192 -- make an exception in Check_Float_Overflow mode.
5194 if Is_Floating_Point_Type
(P_Type
) then
5195 if not Range_Checks_Suppressed
(P_Base_Type
) then
5196 Set_Do_Range_Check
(E1
);
5199 -- If not modular type, test for overflow check required
5202 if not Is_Modular_Integer_Type
(P_Type
)
5203 and then not Range_Checks_Suppressed
(P_Base_Type
)
5205 Enable_Range_Check
(E1
);
5213 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5215 when Attribute_Priority
=>
5216 if Ada_Version
< Ada_2005
then
5217 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5222 Check_Restriction
(No_Dynamic_Priorities
, N
);
5224 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5228 if Is_Protected_Type
(Etype
(P
))
5229 or else (Is_Access_Type
(Etype
(P
))
5230 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5232 Resolve
(P
, Etype
(P
));
5234 Error_Attr_P
("prefix of % attribute must be a protected object");
5237 Set_Etype
(N
, Standard_Integer
);
5239 -- Must be called from within a protected procedure or entry of the
5240 -- protected object.
5247 while S
/= Etype
(P
)
5248 and then S
/= Standard_Standard
5253 if S
= Standard_Standard
then
5254 Error_Attr
("the attribute % is only allowed inside protected "
5259 Validate_Non_Static_Attribute_Function_Call
;
5265 when Attribute_Range
=>
5266 Check_Array_Or_Scalar_Type
;
5267 Bad_Attribute_For_Predicate
;
5269 if Ada_Version
= Ada_83
5270 and then Is_Scalar_Type
(P_Type
)
5271 and then Comes_From_Source
(N
)
5274 ("(Ada 83) % attribute not allowed for scalar type", P
);
5281 when Attribute_Result
=> Result
: declare
5282 function Denote_Same_Function
5283 (Pref_Id
: Entity_Id
;
5284 Spec_Id
: Entity_Id
) return Boolean;
5285 -- Determine whether the entity of the prefix Pref_Id denotes the
5286 -- same entity as that of the related subprogram Spec_Id.
5288 --------------------------
5289 -- Denote_Same_Function --
5290 --------------------------
5292 function Denote_Same_Function
5293 (Pref_Id
: Entity_Id
;
5294 Spec_Id
: Entity_Id
) return Boolean
5296 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5297 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5300 -- The prefix denotes the related subprogram
5302 if Pref_Id
= Spec_Id
then
5305 -- Account for a special case when attribute 'Result appears in
5306 -- the postcondition of a generic function.
5309 -- function Gen_Func return ...
5310 -- with Post => Gen_Func'Result ...;
5312 -- When the generic function is instantiated, the Chars field of
5313 -- the instantiated prefix still denotes the name of the generic
5314 -- function. Note that any preemptive transformation is impossible
5315 -- without a proper analysis. The structure of the wrapper package
5318 -- package Anon_Gen_Pack is
5319 -- <subtypes and renamings>
5320 -- function Subp_Decl return ...; -- (!)
5321 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5322 -- function Gen_Func ... renames Subp_Decl;
5323 -- end Anon_Gen_Pack;
5325 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5326 and then Present
(Generic_Parent
(Subp_Spec
))
5327 and then Ekind_In
(Pref_Id
, E_Generic_Function
, E_Function
)
5329 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5332 elsif Present
(Alias
(Pref_Id
))
5333 and then Alias
(Pref_Id
) = Spec_Id
5338 -- Account for a special case where a primitive of a tagged type
5339 -- inherits a class-wide postcondition from a parent type. In this
5340 -- case the prefix of attribute 'Result denotes the overriding
5343 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5347 -- Otherwise the prefix does not denote the related subprogram
5350 end Denote_Same_Function
;
5354 In_Inlined_C_Postcondition
: constant Boolean :=
5356 and then In_Inlined_Body
;
5359 Pref_Id
: Entity_Id
;
5360 Spec_Id
: Entity_Id
;
5362 -- Start of processing for Result
5365 -- The attribute reference is a primary. If any expressions follow,
5366 -- then the attribute reference is an indexable object. Transform the
5367 -- attribute into an indexed component and analyze it.
5369 if Present
(E1
) then
5371 Make_Indexed_Component
(Loc
,
5373 Make_Attribute_Reference
(Loc
,
5374 Prefix
=> Relocate_Node
(P
),
5375 Attribute_Name
=> Name_Result
),
5376 Expressions
=> Expressions
(N
)));
5381 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5383 -- The aspect or pragma where attribute 'Result resides should be
5384 -- associated with a subprogram declaration or a body. If this is not
5385 -- the case, then the aspect or pragma is illegal. Return as analysis
5386 -- cannot be carried out.
5388 -- The exception to this rule is when generating C since in this case
5389 -- postconditions are inlined.
5391 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5392 Spec_Id
:= Entity
(P
);
5394 elsif not Legal
then
5398 -- Attribute 'Result is part of a _Postconditions procedure. There is
5399 -- no need to perform the semantic checks below as they were already
5400 -- verified when the attribute was analyzed in its original context.
5401 -- Instead, rewrite the attribute as a reference to formal parameter
5402 -- _Result of the _Postconditions procedure.
5404 if Chars
(Spec_Id
) = Name_uPostconditions
5406 (In_Inlined_C_Postcondition
5407 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5409 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5411 -- The type of formal parameter _Result is that of the function
5412 -- encapsulating the _Postconditions procedure. Resolution must
5413 -- be carried out against the function return type.
5415 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
5417 -- Otherwise attribute 'Result appears in its original context and
5418 -- all semantic checks should be carried out.
5421 -- Verify the legality of the prefix. It must denotes the entity
5422 -- of the related [generic] function.
5424 if Is_Entity_Name
(P
) then
5425 Pref_Id
:= Entity
(P
);
5427 if Ekind_In
(Pref_Id
, E_Function
, E_Generic_Function
)
5428 and then Ekind
(Spec_Id
) = Ekind
(Pref_Id
)
5430 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
5432 -- Correct the prefix of the attribute when the context
5433 -- is a generic function.
5435 if Pref_Id
/= Spec_Id
then
5436 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
5440 Set_Etype
(N
, Etype
(Spec_Id
));
5442 -- Otherwise the prefix denotes some unrelated function
5445 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5447 ("incorrect prefix for attribute %, expected %", P
);
5450 -- Otherwise the prefix denotes some other form of subprogram
5455 ("attribute % can only appear in postcondition of "
5459 -- Otherwise the prefix is illegal
5462 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5463 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
5472 when Attribute_Range_Length
=>
5474 Check_Discrete_Type
;
5475 Set_Etype
(N
, Universal_Integer
);
5481 when Attribute_Read
=>
5483 Check_Stream_Attribute
(TSS_Stream_Read
);
5484 Set_Etype
(N
, Standard_Void_Type
);
5485 Resolve
(N
, Standard_Void_Type
);
5486 Note_Possible_Modification
(E2
, Sure
=> True);
5492 when Attribute_Ref
=>
5496 if Nkind
(P
) /= N_Expanded_Name
5497 or else not Is_RTE
(P_Type
, RE_Address
)
5499 Error_Attr_P
("prefix of % attribute must be System.Address");
5502 Analyze_And_Resolve
(E1
, Any_Integer
);
5503 Set_Etype
(N
, RTE
(RE_Address
));
5509 when Attribute_Remainder
=>
5510 Check_Floating_Point_Type_2
;
5511 Set_Etype
(N
, P_Base_Type
);
5512 Resolve
(E1
, P_Base_Type
);
5513 Resolve
(E2
, P_Base_Type
);
5515 ---------------------
5516 -- Restriction_Set --
5517 ---------------------
5519 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5522 Unam
: Unit_Name_Type
;
5527 Check_System_Prefix
;
5529 -- No_Dependence case
5531 if Nkind
(E1
) = N_Parameter_Association
then
5532 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5533 U
:= Explicit_Actual_Parameter
(E1
);
5535 if not OK_No_Dependence_Unit_Name
(U
) then
5536 Set_Boolean_Result
(N
, False);
5540 -- See if there is an entry already in the table. That's the
5541 -- case in which we can return True.
5543 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5544 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5545 and then No_Dependences
.Table
(J
).Warn
= False
5547 Set_Boolean_Result
(N
, True);
5552 -- If not in the No_Dependence table, result is False
5554 Set_Boolean_Result
(N
, False);
5556 -- In this case, we must ensure that the binder will reject any
5557 -- other unit in the partition that sets No_Dependence for this
5558 -- unit. We do that by making an entry in the special table kept
5559 -- for this purpose (if the entry is not there already).
5561 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5563 for J
in Restriction_Set_Dependences
.First
..
5564 Restriction_Set_Dependences
.Last
5566 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5571 Restriction_Set_Dependences
.Append
(Unam
);
5573 -- Normal restriction case
5576 if Nkind
(E1
) /= N_Identifier
then
5577 Set_Boolean_Result
(N
, False);
5578 Error_Attr
("attribute % requires restriction identifier", E1
);
5581 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5583 if R
= Not_A_Restriction_Id
then
5584 Set_Boolean_Result
(N
, False);
5585 Error_Msg_Node_1
:= E1
;
5586 Error_Attr
("invalid restriction identifier &", E1
);
5588 elsif R
not in Partition_Boolean_Restrictions
then
5589 Set_Boolean_Result
(N
, False);
5590 Error_Msg_Node_1
:= E1
;
5592 ("& is not a boolean partition-wide restriction", E1
);
5595 if Restriction_Active
(R
) then
5596 Set_Boolean_Result
(N
, True);
5598 Check_Restriction
(R
, N
);
5599 Set_Boolean_Result
(N
, False);
5603 end Restriction_Set
;
5609 when Attribute_Round
=>
5611 Check_Decimal_Fixed_Point_Type
;
5612 Set_Etype
(N
, P_Base_Type
);
5614 -- Because the context is universal_real (3.5.10(12)) it is a
5615 -- legal context for a universal fixed expression. This is the
5616 -- only attribute whose functional description involves U_R.
5618 if Etype
(E1
) = Universal_Fixed
then
5620 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5621 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5622 Expression
=> Relocate_Node
(E1
));
5630 Resolve
(E1
, Any_Real
);
5636 when Attribute_Rounding
=>
5637 Check_Floating_Point_Type_1
;
5638 Set_Etype
(N
, P_Base_Type
);
5639 Resolve
(E1
, P_Base_Type
);
5645 when Attribute_Safe_Emax
=>
5646 Check_Floating_Point_Type_0
;
5647 Set_Etype
(N
, Universal_Integer
);
5653 when Attribute_Safe_First
=>
5654 Check_Floating_Point_Type_0
;
5655 Set_Etype
(N
, Universal_Real
);
5661 when Attribute_Safe_Large
=>
5664 Set_Etype
(N
, Universal_Real
);
5670 when Attribute_Safe_Last
=>
5671 Check_Floating_Point_Type_0
;
5672 Set_Etype
(N
, Universal_Real
);
5678 when Attribute_Safe_Small
=>
5681 Set_Etype
(N
, Universal_Real
);
5683 --------------------------
5684 -- Scalar_Storage_Order --
5685 --------------------------
5687 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5688 Ent
: Entity_Id
:= Empty
;
5694 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5696 -- In GNAT mode, the attribute applies to generic types as well
5697 -- as composite types, and for non-composite types always returns
5698 -- the default bit order for the target.
5700 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5701 and then not In_Instance
5704 ("prefix of % attribute must be record or array type");
5706 elsif not Is_Generic_Type
(P_Type
) then
5707 if Bytes_Big_Endian
then
5708 Ent
:= RTE
(RE_High_Order_First
);
5710 Ent
:= RTE
(RE_Low_Order_First
);
5714 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5715 Ent
:= RTE
(RE_High_Order_First
);
5718 Ent
:= RTE
(RE_Low_Order_First
);
5721 if Present
(Ent
) then
5722 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5725 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5728 -- Reset incorrect indication of staticness
5730 Set_Is_Static_Expression
(N
, False);
5731 end Scalar_Storage_Order
;
5737 when Attribute_Scale
=>
5739 Check_Decimal_Fixed_Point_Type
;
5740 Set_Etype
(N
, Universal_Integer
);
5746 when Attribute_Scaling
=>
5747 Check_Floating_Point_Type_2
;
5748 Set_Etype
(N
, P_Base_Type
);
5749 Resolve
(E1
, P_Base_Type
);
5755 when Attribute_Signed_Zeros
=>
5756 Check_Floating_Point_Type_0
;
5757 Set_Etype
(N
, Standard_Boolean
);
5764 | Attribute_VADS_Size
5768 -- If prefix is parameterless function call, rewrite and resolve
5771 if Is_Entity_Name
(P
)
5772 and then Ekind
(Entity
(P
)) = E_Function
5776 -- Similar processing for a protected function call
5778 elsif Nkind
(P
) = N_Selected_Component
5779 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5784 if Is_Object_Reference
(P
) then
5785 Check_Object_Reference
(P
);
5787 elsif Is_Entity_Name
(P
)
5788 and then (Is_Type
(Entity
(P
))
5789 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5793 elsif Nkind
(P
) = N_Type_Conversion
5794 and then not Comes_From_Source
(P
)
5798 -- Some other compilers allow dubious use of X'???'Size
5800 elsif Relaxed_RM_Semantics
5801 and then Nkind
(P
) = N_Attribute_Reference
5806 Error_Attr_P
("invalid prefix for % attribute");
5809 Check_Not_Incomplete_Type
;
5811 Set_Etype
(N
, Universal_Integer
);
5813 -- If we are processing pragmas Compile_Time_Warning and Compile_
5814 -- Time_Errors after the back end has been called and this occurrence
5815 -- of 'Size is known at compile time then it is safe to perform this
5816 -- evaluation. Needed to perform the static evaluation of the full
5817 -- boolean expression of these pragmas.
5819 if In_Compile_Time_Warning_Or_Error
5820 and then Is_Entity_Name
(P
)
5821 and then (Is_Type
(Entity
(P
))
5822 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5823 and then Size_Known_At_Compile_Time
(Entity
(P
))
5825 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Esize
(Entity
(P
))));
5833 when Attribute_Small
=>
5836 Set_Etype
(N
, Universal_Real
);
5842 when Attribute_Storage_Pool
5843 | Attribute_Simple_Storage_Pool
5847 if Is_Access_Type
(P_Type
) then
5848 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5850 ("cannot use % attribute for access-to-subprogram type");
5853 -- Set appropriate entity
5855 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5856 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5858 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5861 if Attr_Id
= Attribute_Storage_Pool
then
5862 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5863 Name_Simple_Storage_Pool_Type
))
5865 Error_Msg_Name_1
:= Aname
;
5866 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5868 ("cannot use % attribute for type with simple storage "
5870 Error_Msg_N
("\Program_Error [<<", N
);
5873 (N
, Make_Raise_Program_Error
5874 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5877 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5879 -- In the Simple_Storage_Pool case, verify that the pool entity is
5880 -- actually of a simple storage pool type, and set the attribute's
5881 -- type to the pool object's type.
5884 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5885 Name_Simple_Storage_Pool_Type
))
5888 ("cannot use % attribute for type without simple " &
5892 Set_Etype
(N
, Etype
(Entity
(N
)));
5895 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5896 -- Storage_Pool since this attribute is not defined for such
5897 -- types (RM E.2.3(22)).
5899 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5902 Error_Attr_P
("prefix of % attribute must be access type");
5909 when Attribute_Storage_Size
=>
5912 if Is_Task_Type
(P_Type
) then
5913 Set_Etype
(N
, Universal_Integer
);
5915 -- Use with tasks is an obsolescent feature
5917 Check_Restriction
(No_Obsolescent_Features
, P
);
5919 elsif Is_Access_Type
(P_Type
) then
5920 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5922 ("cannot use % attribute for access-to-subprogram type");
5925 if Is_Entity_Name
(P
)
5926 and then Is_Type
(Entity
(P
))
5929 Set_Etype
(N
, Universal_Integer
);
5931 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5932 -- Storage_Size since this attribute is not defined for
5933 -- such types (RM E.2.3(22)).
5935 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5937 -- The prefix is allowed to be an implicit dereference of an
5938 -- access value designating a task.
5942 Set_Etype
(N
, Universal_Integer
);
5946 Error_Attr_P
("prefix of % attribute must be access or task type");
5953 when Attribute_Storage_Unit
=>
5954 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5960 when Attribute_Stream_Size
=>
5964 if Is_Entity_Name
(P
)
5965 and then Is_Elementary_Type
(Entity
(P
))
5967 Set_Etype
(N
, Universal_Integer
);
5969 Error_Attr_P
("invalid prefix for % attribute");
5976 when Attribute_Stub_Type
=>
5980 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5982 -- For a real RACW [sub]type, use corresponding stub type
5984 if not Is_Generic_Type
(P_Type
) then
5987 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5989 -- For a generic type (that has been marked as an RACW using the
5990 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5991 -- type. Note that if the actual is not a remote access type, the
5992 -- instantiation will fail.
5995 -- Note: we go to the underlying type here because the view
5996 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
6000 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
6005 ("prefix of% attribute must be remote access-to-class-wide");
6012 when Attribute_Succ
=>
6016 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
6017 Error_Msg_Name_1
:= Aname
;
6018 Error_Msg_Name_2
:= Chars
(P_Type
);
6019 Check_SPARK_05_Restriction
6020 ("attribute% is not allowed for type%", P
);
6023 Resolve
(E1
, P_Base_Type
);
6024 Set_Etype
(N
, P_Base_Type
);
6026 -- Since Pred works on the base type, we normally do no check for the
6027 -- floating-point case, since the base type is unconstrained. But we
6028 -- make an exception in Check_Float_Overflow mode.
6030 if Is_Floating_Point_Type
(P_Type
) then
6031 if not Range_Checks_Suppressed
(P_Base_Type
) then
6032 Set_Do_Range_Check
(E1
);
6035 -- If not modular type, test for overflow check required
6038 if not Is_Modular_Integer_Type
(P_Type
)
6039 and then not Range_Checks_Suppressed
(P_Base_Type
)
6041 Enable_Range_Check
(E1
);
6045 --------------------------------
6046 -- System_Allocator_Alignment --
6047 --------------------------------
6049 when Attribute_System_Allocator_Alignment
=>
6050 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
6056 when Attribute_Tag
=>
6060 if not Is_Tagged_Type
(P_Type
) then
6061 Error_Attr_P
("prefix of % attribute must be tagged");
6063 -- Next test does not apply to generated code why not, and what does
6064 -- the illegal reference mean???
6066 elsif Is_Object_Reference
(P
)
6067 and then not Is_Class_Wide_Type
(P_Type
)
6068 and then Comes_From_Source
(N
)
6071 ("% attribute can only be applied to objects " &
6072 "of class - wide type");
6075 -- The prefix cannot be an incomplete type. However, references to
6076 -- 'Tag can be generated when expanding interface conversions, and
6079 if Comes_From_Source
(N
) then
6080 Check_Not_Incomplete_Type
;
6083 -- Set appropriate type
6085 Set_Etype
(N
, RTE
(RE_Tag
));
6091 when Attribute_Target_Name
=> Target_Name
: declare
6092 TN
: constant String := Sdefault
.Target_Name
.all;
6096 Check_Standard_Prefix
;
6100 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6105 Make_String_Literal
(Loc
,
6106 Strval
=> TN
(TN
'First .. TL
)));
6107 Analyze_And_Resolve
(N
, Standard_String
);
6108 Set_Is_Static_Expression
(N
, True);
6115 when Attribute_Terminated
=>
6117 Set_Etype
(N
, Standard_Boolean
);
6124 when Attribute_To_Address
=> To_Address
: declare
6130 Check_System_Prefix
;
6132 Generate_Reference
(RTE
(RE_Address
), P
);
6133 Analyze_And_Resolve
(E1
, Any_Integer
);
6134 Set_Etype
(N
, RTE
(RE_Address
));
6136 if Is_Static_Expression
(E1
) then
6137 Set_Is_Static_Expression
(N
, True);
6140 -- OK static expression case, check range and set appropriate type
6142 if Is_OK_Static_Expression
(E1
) then
6143 Val
:= Expr_Value
(E1
);
6145 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
6147 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
6149 Error_Attr
("address value out of range for % attribute", E1
);
6152 -- In most cases the expression is a numeric literal or some other
6153 -- address expression, but if it is a declared constant it may be
6154 -- of a compatible type that must be left on the node.
6156 if Is_Entity_Name
(E1
) then
6159 -- Set type to universal integer if negative
6162 Set_Etype
(E1
, Universal_Integer
);
6164 -- Otherwise set type to Unsigned_64 to accommodate max values
6167 Set_Etype
(E1
, Standard_Unsigned_64
);
6171 Set_Is_Static_Expression
(N
, True);
6178 when Attribute_To_Any
=>
6180 Check_PolyORB_Attribute
;
6181 Set_Etype
(N
, RTE
(RE_Any
));
6187 when Attribute_Truncation
=>
6188 Check_Floating_Point_Type_1
;
6189 Resolve
(E1
, P_Base_Type
);
6190 Set_Etype
(N
, P_Base_Type
);
6196 when Attribute_Type_Class
=>
6199 Check_Not_Incomplete_Type
;
6200 Set_Etype
(N
, RTE
(RE_Type_Class
));
6206 when Attribute_TypeCode
=>
6208 Check_PolyORB_Attribute
;
6209 Set_Etype
(N
, RTE
(RE_TypeCode
));
6215 when Attribute_Type_Key
=> Type_Key
: declare
6216 Full_Name
: constant String_Id
:=
6217 Fully_Qualified_Name_String
(Entity
(P
));
6220 -- The computed signature for the type
6223 -- To simplify the handling of mutually recursive types, follow a
6224 -- single dereference link in a composite type.
6226 procedure Compute_Type_Key
(T
: Entity_Id
);
6227 -- Create a CRC integer from the declaration of the type. For a
6228 -- composite type, fold in the representation of its components in
6229 -- recursive fashion. We use directly the source representation of
6230 -- the types involved.
6232 ----------------------
6233 -- Compute_Type_Key --
6234 ----------------------
6236 procedure Compute_Type_Key
(T
: Entity_Id
) is
6237 Buffer
: Source_Buffer_Ptr
;
6241 SFI
: Source_File_Index
;
6243 procedure Process_One_Declaration
;
6244 -- Update CRC with the characters of one type declaration, or a
6245 -- representation pragma that applies to the type.
6247 -----------------------------
6248 -- Process_One_Declaration --
6249 -----------------------------
6251 procedure Process_One_Declaration
is
6253 -- Scan type declaration, skipping blanks
6255 for Ptr
in P_Min
.. P_Max
loop
6256 if Buffer
(Ptr
) /= ' ' then
6257 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6260 end Process_One_Declaration
;
6262 -- Start of processing for Compute_Type_Key
6265 if Is_Itype
(T
) then
6269 -- If the type is declared in Standard, there is no source, so
6270 -- just use its name.
6272 if Scope
(T
) = Standard_Standard
then
6274 Name
: constant String := Get_Name_String
(Chars
(T
));
6276 for J
in Name
'Range loop
6277 System
.CRC32
.Update
(CRC
, Name
(J
));
6284 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6285 SFI
:= Get_Source_File_Index
(P_Min
);
6286 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6287 Buffer
:= Source_Text
(SFI
);
6289 Process_One_Declaration
;
6291 -- Recurse on relevant component types
6293 if Is_Array_Type
(T
) then
6294 Compute_Type_Key
(Component_Type
(T
));
6296 elsif Is_Access_Type
(T
) then
6299 Compute_Type_Key
(Designated_Type
(T
));
6302 elsif Is_Derived_Type
(T
) then
6303 Compute_Type_Key
(Etype
(T
));
6305 elsif Is_Record_Type
(T
) then
6309 Comp
:= First_Component
(T
);
6310 while Present
(Comp
) loop
6311 Compute_Type_Key
(Etype
(Comp
));
6312 Next_Component
(Comp
);
6317 if Is_First_Subtype
(T
) then
6319 -- Fold in representation aspects for the type, which appear in
6320 -- the same source buffer. If the representation aspects are in
6321 -- a different source file, then skip them; they apply to some
6322 -- other type, perhaps one we're derived from.
6324 Rep
:= First_Rep_Item
(T
);
6326 while Present
(Rep
) loop
6327 if Comes_From_Source
(Rep
) then
6328 Sloc_Range
(Rep
, P_Min
, P_Max
);
6330 if SFI
= Get_Source_File_Index
(P_Min
) then
6331 pragma Assert
(SFI
= Get_Source_File_Index
(P_Max
));
6332 Process_One_Declaration
;
6336 Rep
:= Next_Rep_Item
(Rep
);
6339 end Compute_Type_Key
;
6341 -- Start of processing for Type_Key
6350 -- Copy all characters in Full_Name but the trailing NUL
6352 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6353 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6356 -- Compute CRC and convert it to string one character at a time, so
6357 -- as not to use Image within the compiler.
6360 Compute_Type_Key
(Entity
(P
));
6362 if not Is_Frozen
(Entity
(P
)) then
6363 Error_Msg_N
("premature usage of Type_Key?", N
);
6367 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
6371 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
6372 Analyze_And_Resolve
(N
, Standard_String
);
6375 -----------------------
6376 -- Unbiased_Rounding --
6377 -----------------------
6379 when Attribute_Unbiased_Rounding
=>
6380 Check_Floating_Point_Type_1
;
6381 Set_Etype
(N
, P_Base_Type
);
6382 Resolve
(E1
, P_Base_Type
);
6384 ----------------------
6385 -- Unchecked_Access --
6386 ----------------------
6388 when Attribute_Unchecked_Access
=>
6389 if Comes_From_Source
(N
) then
6390 Check_Restriction
(No_Unchecked_Access
, N
);
6393 Analyze_Access_Attribute
;
6394 Check_Not_Incomplete_Type
;
6396 -------------------------
6397 -- Unconstrained_Array --
6398 -------------------------
6400 when Attribute_Unconstrained_Array
=>
6403 Check_Not_Incomplete_Type
;
6404 Set_Etype
(N
, Standard_Boolean
);
6405 Set_Is_Static_Expression
(N
, True);
6407 ------------------------------
6408 -- Universal_Literal_String --
6409 ------------------------------
6411 -- This is a GNAT specific attribute whose prefix must be a named
6412 -- number where the expression is either a single numeric literal,
6413 -- or a numeric literal immediately preceded by a minus sign. The
6414 -- result is equivalent to a string literal containing the text of
6415 -- the literal as it appeared in the source program with a possible
6416 -- leading minus sign.
6418 when Attribute_Universal_Literal_String
=>
6421 if not Is_Entity_Name
(P
)
6422 or else Ekind
(Entity
(P
)) not in Named_Kind
6424 Error_Attr_P
("prefix for % attribute must be named number");
6431 Src
: Source_Buffer_Ptr
;
6434 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6436 if Nkind
(Expr
) = N_Op_Minus
then
6438 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6443 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6445 ("named number for % attribute must be simple literal", N
);
6448 -- Build string literal corresponding to source literal text
6453 Store_String_Char
(Get_Char_Code
('-'));
6457 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6459 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6460 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6464 -- Now we rewrite the attribute with the string literal
6467 Make_String_Literal
(Loc
, End_String
));
6469 Set_Is_Static_Expression
(N
, True);
6473 -------------------------
6474 -- Unrestricted_Access --
6475 -------------------------
6477 -- This is a GNAT specific attribute which is like Access except that
6478 -- all scope checks and checks for aliased views are omitted. It is
6479 -- documented as being equivalent to the use of the Address attribute
6480 -- followed by an unchecked conversion to the target access type.
6482 when Attribute_Unrestricted_Access
=>
6484 -- If from source, deal with relevant restrictions
6486 if Comes_From_Source
(N
) then
6487 Check_Restriction
(No_Unchecked_Access
, N
);
6489 if Nkind
(P
) in N_Has_Entity
6490 and then Present
(Entity
(P
))
6491 and then Is_Object
(Entity
(P
))
6493 Check_Restriction
(No_Implicit_Aliasing
, N
);
6497 if Is_Entity_Name
(P
) then
6498 Set_Address_Taken
(Entity
(P
));
6501 -- It might seem reasonable to call Address_Checks here to apply the
6502 -- same set of semantic checks that we enforce for 'Address (after
6503 -- all we document Unrestricted_Access as being equivalent to the
6504 -- use of Address followed by an Unchecked_Conversion). However, if
6505 -- we do enable these checks, we get multiple failures in both the
6506 -- compiler run-time and in our regression test suite, so we leave
6507 -- out these checks for now. To be investigated further some time???
6511 -- Now complete analysis using common access processing
6513 Analyze_Access_Attribute
;
6519 when Attribute_Update
=> Update
: declare
6520 Common_Typ
: Entity_Id
;
6521 -- The common type of a multiple component update for a record
6523 Comps
: Elist_Id
:= No_Elist
;
6524 -- A list used in the resolution of a record update. It contains the
6525 -- entities of all record components processed so far.
6527 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6528 -- Analyze and resolve array_component_association Assoc against the
6529 -- index of array type P_Type.
6531 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6532 -- Analyze and resolve record_component_association Comp against
6533 -- record type P_Type.
6535 ------------------------------------
6536 -- Analyze_Array_Component_Update --
6537 ------------------------------------
6539 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6543 Index_Typ
: Entity_Id
;
6547 -- The current association contains a sequence of indexes denoting
6548 -- an element of a multidimensional array:
6550 -- (Index_1, ..., Index_N)
6552 -- Examine each individual index and resolve it against the proper
6553 -- index type of the array.
6555 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6556 Expr
:= First
(Choices
(Assoc
));
6557 while Present
(Expr
) loop
6559 -- The use of others is illegal (SPARK RM 4.4.1(12))
6561 if Nkind
(Expr
) = N_Others_Choice
then
6563 ("others choice not allowed in attribute %", Expr
);
6565 -- Otherwise analyze and resolve all indexes
6568 Index
:= First
(Expressions
(Expr
));
6569 Index_Typ
:= First_Index
(P_Type
);
6570 while Present
(Index
) and then Present
(Index_Typ
) loop
6571 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6573 Next_Index
(Index_Typ
);
6576 -- Detect a case where the association either lacks an
6577 -- index or contains an extra index.
6579 if Present
(Index
) or else Present
(Index_Typ
) then
6581 ("dimension mismatch in index list", Assoc
);
6588 -- The current association denotes either a single component or a
6589 -- range of components of a one dimensional array:
6593 -- Resolve the index or its high and low bounds (if range) against
6594 -- the proper index type of the array.
6597 Index
:= First
(Choices
(Assoc
));
6598 Index_Typ
:= First_Index
(P_Type
);
6600 if Present
(Next_Index
(Index_Typ
)) then
6601 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6604 while Present
(Index
) loop
6606 -- The use of others is illegal (SPARK RM 4.4.1(12))
6608 if Nkind
(Index
) = N_Others_Choice
then
6610 ("others choice not allowed in attribute %", Index
);
6612 -- The index denotes a range of elements
6614 elsif Nkind
(Index
) = N_Range
then
6615 Low
:= Low_Bound
(Index
);
6616 High
:= High_Bound
(Index
);
6618 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6619 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6621 -- Add a range check to ensure that the bounds of the
6622 -- range are within the index type when this cannot be
6623 -- determined statically.
6625 if not Is_OK_Static_Expression
(Low
) then
6626 Set_Do_Range_Check
(Low
);
6629 if not Is_OK_Static_Expression
(High
) then
6630 Set_Do_Range_Check
(High
);
6633 -- Otherwise the index denotes a single element
6636 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6638 -- Add a range check to ensure that the index is within
6639 -- the index type when it is not possible to determine
6642 if not Is_OK_Static_Expression
(Index
) then
6643 Set_Do_Range_Check
(Index
);
6650 end Analyze_Array_Component_Update
;
6652 -------------------------------------
6653 -- Analyze_Record_Component_Update --
6654 -------------------------------------
6656 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6657 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6658 Base_Typ
: Entity_Id
;
6659 Comp_Or_Discr
: Entity_Id
;
6662 -- Find the discriminant or component whose name corresponds to
6663 -- Comp. A simple character comparison is sufficient because all
6664 -- visible names within a record type are unique.
6666 Comp_Or_Discr
:= First_Entity
(P_Type
);
6667 while Present
(Comp_Or_Discr
) loop
6668 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6670 -- Decorate the component reference by setting its entity
6671 -- and type for resolution purposes.
6673 Set_Entity
(Comp
, Comp_Or_Discr
);
6674 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6678 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6681 -- Diagnose an illegal reference
6683 if Present
(Comp_Or_Discr
) then
6684 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6686 ("attribute % may not modify record discriminants", Comp
);
6688 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6689 if Contains
(Comps
, Comp_Or_Discr
) then
6690 Error_Msg_N
("component & already updated", Comp
);
6692 -- Mark this component as processed
6695 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6699 -- The update aggregate mentions an entity that does not belong to
6703 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6706 -- Verify the consistency of types when the current component is
6707 -- part of a miltiple component update.
6709 -- Comp_1, ..., Comp_N => <value>
6711 if Present
(Etype
(Comp
)) then
6712 Base_Typ
:= Base_Type
(Etype
(Comp
));
6714 -- Save the type of the first component reference as the
6715 -- remaning references (if any) must resolve to this type.
6717 if No
(Common_Typ
) then
6718 Common_Typ
:= Base_Typ
;
6720 elsif Base_Typ
/= Common_Typ
then
6722 ("components in choice list must have same type", Comp
);
6725 end Analyze_Record_Component_Update
;
6732 -- Start of processing for Update
6737 if not Is_Object_Reference
(P
) then
6738 Error_Attr_P
("prefix of attribute % must denote an object");
6740 elsif not Is_Array_Type
(P_Type
)
6741 and then not Is_Record_Type
(P_Type
)
6743 Error_Attr_P
("prefix of attribute % must be a record or array");
6745 elsif Is_Limited_View
(P_Type
) then
6746 Error_Attr
("prefix of attribute % cannot be limited", N
);
6748 elsif Nkind
(E1
) /= N_Aggregate
then
6749 Error_Attr
("attribute % requires component association list", N
);
6752 -- Inspect the update aggregate, looking at all the associations and
6753 -- choices. Perform the following checks:
6755 -- 1) Legality of "others" in all cases
6756 -- 2) Legality of <>
6757 -- 3) Component legality for arrays
6758 -- 4) Component legality for records
6760 -- The remaining checks are performed on the expanded attribute
6762 Assoc
:= First
(Component_Associations
(E1
));
6763 while Present
(Assoc
) loop
6765 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6767 if Box_Present
(Assoc
) then
6769 ("default initialization not allowed in attribute %", Assoc
);
6771 -- Otherwise process the association
6774 Analyze
(Expression
(Assoc
));
6776 if Is_Array_Type
(P_Type
) then
6777 Analyze_Array_Component_Update
(Assoc
);
6779 elsif Is_Record_Type
(P_Type
) then
6781 -- Reset the common type used in a multiple component update
6782 -- as we are processing the contents of a new association.
6784 Common_Typ
:= Empty
;
6786 Comp
:= First
(Choices
(Assoc
));
6787 while Present
(Comp
) loop
6788 if Nkind
(Comp
) = N_Identifier
then
6789 Analyze_Record_Component_Update
(Comp
);
6791 -- The use of others is illegal (SPARK RM 4.4.1(5))
6793 elsif Nkind
(Comp
) = N_Others_Choice
then
6795 ("others choice not allowed in attribute %", Comp
);
6797 -- The name of a record component cannot appear in any
6802 ("name should be identifier or OTHERS", Comp
);
6813 -- The type of attribute 'Update is that of the prefix
6815 Set_Etype
(N
, P_Type
);
6817 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
6824 when Attribute_Val
=>
6826 Check_Discrete_Type
;
6828 if Is_Boolean_Type
(P_Type
) then
6829 Error_Msg_Name_1
:= Aname
;
6830 Error_Msg_Name_2
:= Chars
(P_Type
);
6831 Check_SPARK_05_Restriction
6832 ("attribute% is not allowed for type%", P
);
6835 -- Note, we need a range check in general, but we wait for the
6836 -- Resolve call to do this, since we want to let Eval_Attribute
6837 -- have a chance to find an static illegality first.
6839 Resolve
(E1
, Any_Integer
);
6840 Set_Etype
(N
, P_Base_Type
);
6846 when Attribute_Valid
=>
6849 -- Ignore check for object if we have a 'Valid reference generated
6850 -- by the expanded code, since in some cases valid checks can occur
6851 -- on items that are names, but are not objects (e.g. attributes).
6853 if Comes_From_Source
(N
) then
6854 Check_Object_Reference
(P
);
6857 if not Is_Scalar_Type
(P_Type
) then
6858 Error_Attr_P
("object for % attribute must be of scalar type");
6861 -- If the attribute appears within the subtype's own predicate
6862 -- function, then issue a warning that this will cause infinite
6866 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6869 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6871 ("attribute Valid requires a predicate check??", N
);
6872 Error_Msg_N
("\and will result in infinite recursion??", N
);
6876 Set_Etype
(N
, Standard_Boolean
);
6882 when Attribute_Valid_Scalars
=>
6884 Check_Object_Reference
(P
);
6885 Set_Etype
(N
, Standard_Boolean
);
6887 -- Following checks are only for source types
6889 if Comes_From_Source
(N
) then
6890 if not Scalar_Part_Present
(P_Type
) then
6892 ("??attribute % always True, no scalars to check");
6895 -- Not allowed for unchecked union type
6897 if Has_Unchecked_Union
(P_Type
) then
6899 ("attribute % not allowed for Unchecked_Union type");
6907 when Attribute_Value
=>
6908 Check_SPARK_05_Restriction_On_Attribute
;
6912 -- Case of enumeration type
6914 -- When an enumeration type appears in an attribute reference, all
6915 -- literals of the type are marked as referenced. This must only be
6916 -- done if the attribute reference appears in the current source.
6917 -- Otherwise the information on references may differ between a
6918 -- normal compilation and one that performs inlining.
6920 if Is_Enumeration_Type
(P_Type
)
6921 and then In_Extended_Main_Code_Unit
(N
)
6923 Check_Restriction
(No_Enumeration_Maps
, N
);
6925 -- Mark all enumeration literals as referenced, since the use of
6926 -- the Value attribute can implicitly reference any of the
6927 -- literals of the enumeration base type.
6930 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6932 while Present
(Ent
) loop
6933 Set_Referenced
(Ent
);
6939 -- Set Etype before resolving expression because expansion of
6940 -- expression may require enclosing type. Note that the type
6941 -- returned by 'Value is the base type of the prefix type.
6943 Set_Etype
(N
, P_Base_Type
);
6944 Validate_Non_Static_Attribute_Function_Call
;
6946 -- Check restriction No_Fixed_IO
6948 if Restriction_Check_Required
(No_Fixed_IO
)
6949 and then Is_Fixed_Point_Type
(P_Type
)
6951 Check_Restriction
(No_Fixed_IO
, P
);
6958 when Attribute_Value_Size
=>
6961 Check_Not_Incomplete_Type
;
6962 Set_Etype
(N
, Universal_Integer
);
6968 when Attribute_Version
=>
6971 Set_Etype
(N
, RTE
(RE_Version_String
));
6977 when Attribute_Wchar_T_Size
=>
6978 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6984 when Attribute_Wide_Image
=>
6985 Analyze_Image_Attribute
(Standard_Wide_String
);
6987 ---------------------
6988 -- Wide_Wide_Image --
6989 ---------------------
6991 when Attribute_Wide_Wide_Image
=>
6992 Analyze_Image_Attribute
(Standard_Wide_Wide_String
);
6998 when Attribute_Wide_Value
=>
6999 Check_SPARK_05_Restriction_On_Attribute
;
7003 -- Set Etype before resolving expression because expansion
7004 -- of expression may require enclosing type.
7006 Set_Etype
(N
, P_Type
);
7007 Validate_Non_Static_Attribute_Function_Call
;
7009 -- Check restriction No_Fixed_IO
7011 if Restriction_Check_Required
(No_Fixed_IO
)
7012 and then Is_Fixed_Point_Type
(P_Type
)
7014 Check_Restriction
(No_Fixed_IO
, P
);
7017 ---------------------
7018 -- Wide_Wide_Value --
7019 ---------------------
7021 when Attribute_Wide_Wide_Value
=>
7025 -- Set Etype before resolving expression because expansion
7026 -- of expression may require enclosing type.
7028 Set_Etype
(N
, P_Type
);
7029 Validate_Non_Static_Attribute_Function_Call
;
7031 -- Check restriction No_Fixed_IO
7033 if Restriction_Check_Required
(No_Fixed_IO
)
7034 and then Is_Fixed_Point_Type
(P_Type
)
7036 Check_Restriction
(No_Fixed_IO
, P
);
7039 ---------------------
7040 -- Wide_Wide_Width --
7041 ---------------------
7043 when Attribute_Wide_Wide_Width
=>
7046 Set_Etype
(N
, Universal_Integer
);
7052 when Attribute_Wide_Width
=>
7053 Check_SPARK_05_Restriction_On_Attribute
;
7056 Set_Etype
(N
, Universal_Integer
);
7062 when Attribute_Width
=>
7063 Check_SPARK_05_Restriction_On_Attribute
;
7066 Set_Etype
(N
, Universal_Integer
);
7072 when Attribute_Word_Size
=>
7073 Standard_Attribute
(System_Word_Size
);
7079 when Attribute_Write
=>
7081 Check_Stream_Attribute
(TSS_Stream_Write
);
7082 Set_Etype
(N
, Standard_Void_Type
);
7083 Resolve
(N
, Standard_Void_Type
);
7087 -- In SPARK certain attributes (see below) depend on Tasking_State.
7088 -- Ensure that the entity is available for gnat2why by loading it.
7089 -- See SPARK RM 9(18) for the relevant rule.
7091 if GNATprove_Mode
then
7097 when Attribute_Callable
7100 | Attribute_Terminated
7102 Unused
:= RTE
(RE_Tasking_State
);
7110 -- All errors raise Bad_Attribute, so that we get out before any further
7111 -- damage occurs when an error is detected (for example, if we check for
7112 -- one attribute expression, and the check succeeds, we want to be able
7113 -- to proceed securely assuming that an expression is in fact present.
7115 -- Note: we set the attribute analyzed in this case to prevent any
7116 -- attempt at reanalysis which could generate spurious error msgs.
7119 when Bad_Attribute
=>
7121 Set_Etype
(N
, Any_Type
);
7123 end Analyze_Attribute
;
7125 --------------------
7126 -- Eval_Attribute --
7127 --------------------
7129 procedure Eval_Attribute
(N
: Node_Id
) is
7130 Loc
: constant Source_Ptr
:= Sloc
(N
);
7131 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7132 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7133 P
: constant Node_Id
:= Prefix
(N
);
7135 C_Type
: constant Entity_Id
:= Etype
(N
);
7136 -- The type imposed by the context
7139 -- First expression, or Empty if none
7142 -- Second expression, or Empty if none
7144 P_Entity
: Entity_Id
;
7145 -- Entity denoted by prefix
7148 -- The type of the prefix
7150 P_Base_Type
: Entity_Id
;
7151 -- The base type of the prefix type
7153 P_Root_Type
: Entity_Id
;
7154 -- The root type of the prefix type
7157 -- True if the result is Static. This is set by the general processing
7158 -- to true if the prefix is static, and all expressions are static. It
7159 -- can be reset as processing continues for particular attributes. This
7160 -- flag can still be True if the reference raises a constraint error.
7161 -- Is_Static_Expression (N) is set to follow this value as it is set
7162 -- and we could always reference this, but it is convenient to have a
7163 -- simple short name to use, since it is frequently referenced.
7165 Lo_Bound
, Hi_Bound
: Node_Id
;
7166 -- Expressions for low and high bounds of type or array index referenced
7167 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7170 -- Constraint error node used if we have an attribute reference has
7171 -- an argument that raises a constraint error. In this case we replace
7172 -- the attribute with a raise constraint_error node. This is important
7173 -- processing, since otherwise gigi might see an attribute which it is
7174 -- unprepared to deal with.
7176 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7177 -- If Bound is a reference to a discriminant of a task or protected type
7178 -- occurring within the object's body, rewrite attribute reference into
7179 -- a reference to the corresponding discriminal. Use for the expansion
7180 -- of checks against bounds of entry family index subtypes.
7182 procedure Check_Expressions
;
7183 -- In case where the attribute is not foldable, the expressions, if
7184 -- any, of the attribute, are in a non-static context. This procedure
7185 -- performs the required additional checks.
7187 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7188 -- Determines if the given type has compile time known bounds. Note
7189 -- that we enter the case statement even in cases where the prefix
7190 -- type does NOT have known bounds, so it is important to guard any
7191 -- attempt to evaluate both bounds with a call to this function.
7193 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7194 -- This procedure is called when the attribute N has a non-static
7195 -- but compile time known value given by Val. It includes the
7196 -- necessary checks for out of range values.
7198 function Fore_Value
return Nat
;
7199 -- Computes the Fore value for the current attribute prefix, which is
7200 -- known to be a static fixed-point type. Used by Fore and Width.
7202 function Mantissa
return Uint
;
7203 -- Returns the Mantissa value for the prefix type
7205 procedure Set_Bounds
;
7206 -- Used for First, Last and Length attributes applied to an array or
7207 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7208 -- and high bound expressions for the index referenced by the attribute
7209 -- designator (i.e. the first index if no expression is present, and the
7210 -- N'th index if the value N is present as an expression). Also used for
7211 -- First and Last of scalar types and for First_Valid and Last_Valid.
7212 -- Static is reset to False if the type or index type is not statically
7215 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
7216 -- Verify that the prefix of a potentially static array attribute
7217 -- satisfies the conditions of 4.9 (14).
7219 -----------------------------------
7220 -- Check_Concurrent_Discriminant --
7221 -----------------------------------
7223 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7225 -- The concurrent (task or protected) type
7228 if Nkind
(Bound
) = N_Identifier
7229 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7230 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7232 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7234 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7236 -- Find discriminant of original concurrent type, and use
7237 -- its current discriminal, which is the renaming within
7238 -- the task/protected body.
7242 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7245 end Check_Concurrent_Discriminant
;
7247 -----------------------
7248 -- Check_Expressions --
7249 -----------------------
7251 procedure Check_Expressions
is
7255 while Present
(E
) loop
7256 Check_Non_Static_Context
(E
);
7259 end Check_Expressions
;
7261 ----------------------------------
7262 -- Compile_Time_Known_Attribute --
7263 ----------------------------------
7265 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7266 T
: constant Entity_Id
:= Etype
(N
);
7269 Fold_Uint
(N
, Val
, False);
7271 -- Check that result is in bounds of the type if it is static
7273 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7276 elsif Is_Out_Of_Range
(N
, T
) then
7277 Apply_Compile_Time_Constraint_Error
7278 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7280 elsif not Range_Checks_Suppressed
(T
) then
7281 Enable_Range_Check
(N
);
7284 Set_Do_Range_Check
(N
, False);
7286 end Compile_Time_Known_Attribute
;
7288 -------------------------------
7289 -- Compile_Time_Known_Bounds --
7290 -------------------------------
7292 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7295 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7297 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7298 end Compile_Time_Known_Bounds
;
7304 -- Note that the Fore calculation is based on the actual values
7305 -- of the bounds, and does not take into account possible rounding.
7307 function Fore_Value
return Nat
is
7308 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7309 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7310 Small
: constant Ureal
:= Small_Value
(P_Type
);
7311 Lo_Real
: constant Ureal
:= Lo
* Small
;
7312 Hi_Real
: constant Ureal
:= Hi
* Small
;
7317 -- Bounds are given in terms of small units, so first compute
7318 -- proper values as reals.
7320 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7323 -- Loop to compute proper value if more than one digit required
7325 while T
>= Ureal_10
loop
7337 -- Table of mantissa values accessed by function Computed using
7340 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7342 -- where D is T'Digits (RM83 3.5.7)
7344 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7386 function Mantissa
return Uint
is
7389 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7396 procedure Set_Bounds
is
7402 -- For a string literal subtype, we have to construct the bounds.
7403 -- Valid Ada code never applies attributes to string literals, but
7404 -- it is convenient to allow the expander to generate attribute
7405 -- references of this type (e.g. First and Last applied to a string
7408 -- Note that the whole point of the E_String_Literal_Subtype is to
7409 -- avoid this construction of bounds, but the cases in which we
7410 -- have to materialize them are rare enough that we don't worry.
7412 -- The low bound is simply the low bound of the base type. The
7413 -- high bound is computed from the length of the string and this
7416 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7417 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7418 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7421 Make_Integer_Literal
(Sloc
(P
),
7423 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7425 Set_Parent
(Hi_Bound
, P
);
7426 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7429 -- For non-array case, just get bounds of scalar type
7431 elsif Is_Scalar_Type
(P_Type
) then
7434 -- For a fixed-point type, we must freeze to get the attributes
7435 -- of the fixed-point type set now so we can reference them.
7437 if Is_Fixed_Point_Type
(P_Type
)
7438 and then not Is_Frozen
(Base_Type
(P_Type
))
7439 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7440 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7442 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7445 -- For array case, get type of proper index
7451 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7454 Indx
:= First_Index
(P_Type
);
7455 for J
in 1 .. Ndim
- 1 loop
7459 -- If no index type, get out (some other error occurred, and
7460 -- we don't have enough information to complete the job).
7468 Ityp
:= Etype
(Indx
);
7471 -- A discrete range in an index constraint is allowed to be a
7472 -- subtype indication. This is syntactically a pain, but should
7473 -- not propagate to the entity for the corresponding index subtype.
7474 -- After checking that the subtype indication is legal, the range
7475 -- of the subtype indication should be transfered to the entity.
7476 -- The attributes for the bounds should remain the simple retrievals
7477 -- that they are now.
7479 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7480 Hi_Bound
:= Type_High_Bound
(Ityp
);
7482 -- If subtype is non-static, result is definitely non-static
7484 if not Is_Static_Subtype
(Ityp
) then
7486 Set_Is_Static_Expression
(N
, False);
7488 -- Subtype is static, does it raise CE?
7490 elsif not Is_OK_Static_Subtype
(Ityp
) then
7491 Set_Raises_Constraint_Error
(N
);
7495 -------------------------------
7496 -- Statically_Denotes_Entity --
7497 -------------------------------
7499 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7503 if not Is_Entity_Name
(N
) then
7510 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7511 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7512 end Statically_Denotes_Entity
;
7514 -- Start of processing for Eval_Attribute
7517 -- Initialize result as non-static, will be reset if appropriate
7519 Set_Is_Static_Expression
(N
, False);
7522 -- Acquire first two expressions (at the moment, no attributes take more
7523 -- than two expressions in any case).
7525 if Present
(Expressions
(N
)) then
7526 E1
:= First
(Expressions
(N
));
7533 -- Special processing for Enabled attribute. This attribute has a very
7534 -- special prefix, and the easiest way to avoid lots of special checks
7535 -- to protect this special prefix from causing trouble is to deal with
7536 -- this attribute immediately and be done with it.
7538 if Id
= Attribute_Enabled
then
7540 -- We skip evaluation if the expander is not active. This is not just
7541 -- an optimization. It is of key importance that we not rewrite the
7542 -- attribute in a generic template, since we want to pick up the
7543 -- setting of the check in the instance, Testing Expander_Active
7544 -- might seem an easy way of doing this, but we need to account for
7545 -- ASIS needs, so check explicitly for a generic context.
7547 if not Inside_A_Generic
then
7549 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7554 if C
in Predefined_Check_Id
then
7555 R
:= Scope_Suppress
.Suppress
(C
);
7557 R
:= Is_Check_Suppressed
(Empty
, C
);
7561 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7564 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7571 -- Attribute 'Img applied to a static enumeration value is static, and
7572 -- we will do the folding right here (things get confused if we let this
7573 -- case go through the normal circuitry).
7575 if Attribute_Name
(N
) = Name_Img
7576 and then Is_Entity_Name
(P
)
7577 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
7578 and then Is_OK_Static_Expression
(P
)
7581 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
7586 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
7587 Set_Casing
(All_Upper_Case
);
7588 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
7591 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
7592 Analyze_And_Resolve
(N
, Standard_String
);
7593 Set_Is_Static_Expression
(N
, True);
7599 -- Special processing for cases where the prefix is an object. For this
7600 -- purpose, a string literal counts as an object (attributes of string
7601 -- literals can only appear in generated code).
7603 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7605 -- For Component_Size, the prefix is an array object, and we apply
7606 -- the attribute to the type of the object. This is allowed for both
7607 -- unconstrained and constrained arrays, since the bounds have no
7608 -- influence on the value of this attribute.
7610 if Id
= Attribute_Component_Size
then
7611 P_Entity
:= Etype
(P
);
7613 -- For Enum_Rep, evaluation depends on the nature of the prefix and
7614 -- the optional argument.
7616 elsif Id
= Attribute_Enum_Rep
then
7617 if Is_Entity_Name
(P
) then
7620 Enum_Expr
: Node_Id
;
7621 -- The enumeration-type expression of interest
7626 if Ekind_In
(Entity
(P
), E_Constant
,
7627 E_Enumeration_Literal
)
7631 -- Enum_Type'Enum_Rep (E1) case
7633 elsif Is_Enumeration_Type
(Entity
(P
)) then
7636 -- Otherwise the attribute must be expanded into a
7637 -- conversion and evaluated at run time.
7644 -- We can fold if the expression is an enumeration
7645 -- literal, or if it denotes a constant whose value
7646 -- is known at compile time.
7648 if Nkind
(Enum_Expr
) in N_Has_Entity
7649 and then (Ekind
(Entity
(Enum_Expr
)) =
7650 E_Enumeration_Literal
7652 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
7653 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
7654 N_Object_Declaration
7655 and then Compile_Time_Known_Value
7656 (Expression
(Parent
(Entity
(P
))))))
7658 P_Entity
:= Etype
(P
);
7665 -- Otherwise the attribute is illegal, do not attempt to perform
7666 -- any kind of folding.
7672 -- For First and Last, the prefix is an array object, and we apply
7673 -- the attribute to the type of the array, but we need a constrained
7674 -- type for this, so we use the actual subtype if available.
7676 elsif Id
= Attribute_First
or else
7677 Id
= Attribute_Last
or else
7678 Id
= Attribute_Length
7681 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7684 if Present
(AS
) and then Is_Constrained
(AS
) then
7687 -- If we have an unconstrained type we cannot fold
7695 -- For Size, give size of object if available, otherwise we
7696 -- cannot fold Size.
7698 elsif Id
= Attribute_Size
then
7699 if Is_Entity_Name
(P
)
7700 and then Known_Esize
(Entity
(P
))
7702 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7710 -- For Alignment, give size of object if available, otherwise we
7711 -- cannot fold Alignment.
7713 elsif Id
= Attribute_Alignment
then
7714 if Is_Entity_Name
(P
)
7715 and then Known_Alignment
(Entity
(P
))
7717 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7725 -- For Lock_Free, we apply the attribute to the type of the object.
7726 -- This is allowed since we have already verified that the type is a
7729 elsif Id
= Attribute_Lock_Free
then
7730 P_Entity
:= Etype
(P
);
7732 -- No other attributes for objects are folded
7739 -- Cases where P is not an object. Cannot do anything if P is not the
7740 -- name of an entity.
7742 elsif not Is_Entity_Name
(P
) then
7746 -- Otherwise get prefix entity
7749 P_Entity
:= Entity
(P
);
7752 -- If we are asked to evaluate an attribute where the prefix is a
7753 -- non-frozen generic actual type whose RM_Size is still set to zero,
7754 -- then abandon the effort.
7756 if Is_Type
(P_Entity
)
7757 and then (not Is_Frozen
(P_Entity
)
7758 and then Is_Generic_Actual_Type
(P_Entity
)
7759 and then RM_Size
(P_Entity
) = 0)
7761 -- However, the attribute Unconstrained_Array must be evaluated,
7762 -- since it is documented to be a static attribute (and can for
7763 -- example appear in a Compile_Time_Warning pragma). The frozen
7764 -- status of the type does not affect its evaluation.
7766 and then Id
/= Attribute_Unconstrained_Array
7771 -- At this stage P_Entity is the entity to which the attribute
7772 -- is to be applied. This is usually simply the entity of the
7773 -- prefix, except in some cases of attributes for objects, where
7774 -- as described above, we apply the attribute to the object type.
7776 -- Here is where we make sure that static attributes are properly
7777 -- marked as such. These are attributes whose prefix is a static
7778 -- scalar subtype, whose result is scalar, and whose arguments, if
7779 -- present, are static scalar expressions. Note that such references
7780 -- are static expressions even if they raise Constraint_Error.
7782 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7783 -- though evaluating it raises constraint error. This means that a
7784 -- declaration like:
7786 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7788 -- is legal, since here this expression appears in a statically
7789 -- unevaluated position, so it does not actually raise an exception.
7791 if Is_Scalar_Type
(P_Entity
)
7792 and then (not Is_Generic_Type
(P_Entity
))
7793 and then Is_Static_Subtype
(P_Entity
)
7794 and then Is_Scalar_Type
(Etype
(N
))
7797 or else (Is_Static_Expression
(E1
)
7798 and then Is_Scalar_Type
(Etype
(E1
))))
7801 or else (Is_Static_Expression
(E2
)
7802 and then Is_Scalar_Type
(Etype
(E1
))))
7805 Set_Is_Static_Expression
(N
, True);
7808 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7809 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7810 -- Note we allow non-static non-generic types at this stage as further
7813 if Is_Type
(P_Entity
)
7814 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7815 and then (not Is_Generic_Type
(P_Entity
))
7819 -- Second foldable possibility is an array object (RM 4.9(8))
7821 elsif Ekind_In
(P_Entity
, E_Variable
, E_Constant
)
7822 and then Is_Array_Type
(Etype
(P_Entity
))
7823 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7825 P_Type
:= Etype
(P_Entity
);
7827 -- If the entity is an array constant with an unconstrained nominal
7828 -- subtype then get the type from the initial value. If the value has
7829 -- been expanded into assignments, there is no expression and the
7830 -- attribute reference remains dynamic.
7832 -- We could do better here and retrieve the type ???
7834 if Ekind
(P_Entity
) = E_Constant
7835 and then not Is_Constrained
(P_Type
)
7837 if No
(Constant_Value
(P_Entity
)) then
7840 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7844 -- Definite must be folded if the prefix is not a generic type, that
7845 -- is to say if we are within an instantiation. Same processing applies
7846 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7847 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7849 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7850 Id
= Attribute_Definite
or else
7851 Id
= Attribute_Has_Access_Values
or else
7852 Id
= Attribute_Has_Discriminants
or else
7853 Id
= Attribute_Has_Tagged_Values
or else
7854 Id
= Attribute_Lock_Free
or else
7855 Id
= Attribute_Type_Class
or else
7856 Id
= Attribute_Unconstrained_Array
or else
7857 Id
= Attribute_Max_Alignment_For_Allocation
)
7858 and then not Is_Generic_Type
(P_Entity
)
7862 -- We can fold 'Size applied to a type if the size is known (as happens
7863 -- for a size from an attribute definition clause). At this stage, this
7864 -- can happen only for types (e.g. record types) for which the size is
7865 -- always non-static. We exclude generic types from consideration (since
7866 -- they have bogus sizes set within templates).
7868 elsif Id
= Attribute_Size
7869 and then Is_Type
(P_Entity
)
7870 and then (not Is_Generic_Type
(P_Entity
))
7871 and then Known_Static_RM_Size
(P_Entity
)
7873 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7876 -- We can fold 'Alignment applied to a type if the alignment is known
7877 -- (as happens for an alignment from an attribute definition clause).
7878 -- At this stage, this can happen only for types (e.g. record types) for
7879 -- which the size is always non-static. We exclude generic types from
7880 -- consideration (since they have bogus sizes set within templates).
7882 elsif Id
= Attribute_Alignment
7883 and then Is_Type
(P_Entity
)
7884 and then (not Is_Generic_Type
(P_Entity
))
7885 and then Known_Alignment
(P_Entity
)
7887 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7890 -- If this is an access attribute that is known to fail accessibility
7891 -- check, rewrite accordingly.
7893 elsif Attribute_Name
(N
) = Name_Access
7894 and then Raises_Constraint_Error
(N
)
7897 Make_Raise_Program_Error
(Loc
,
7898 Reason
=> PE_Accessibility_Check_Failed
));
7899 Set_Etype
(N
, C_Type
);
7902 -- No other cases are foldable (they certainly aren't static, and at
7903 -- the moment we don't try to fold any cases other than the ones above).
7910 -- If either attribute or the prefix is Any_Type, then propagate
7911 -- Any_Type to the result and don't do anything else at all.
7913 if P_Type
= Any_Type
7914 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7915 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7917 Set_Etype
(N
, Any_Type
);
7921 -- Scalar subtype case. We have not yet enforced the static requirement
7922 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7923 -- of non-static attribute references (e.g. S'Digits for a non-static
7924 -- floating-point type, which we can compute at compile time).
7926 -- Note: this folding of non-static attributes is not simply a case of
7927 -- optimization. For many of the attributes affected, Gigi cannot handle
7928 -- the attribute and depends on the front end having folded them away.
7930 -- Note: although we don't require staticness at this stage, we do set
7931 -- the Static variable to record the staticness, for easy reference by
7932 -- those attributes where it matters (e.g. Succ and Pred), and also to
7933 -- be used to ensure that non-static folded things are not marked as
7934 -- being static (a check that is done right at the end).
7936 P_Root_Type
:= Root_Type
(P_Type
);
7937 P_Base_Type
:= Base_Type
(P_Type
);
7939 -- If the root type or base type is generic, then we cannot fold. This
7940 -- test is needed because subtypes of generic types are not always
7941 -- marked as being generic themselves (which seems odd???)
7943 if Is_Generic_Type
(P_Root_Type
)
7944 or else Is_Generic_Type
(P_Base_Type
)
7949 if Is_Scalar_Type
(P_Type
) then
7950 if not Is_Static_Subtype
(P_Type
) then
7952 Set_Is_Static_Expression
(N
, False);
7953 elsif not Is_OK_Static_Subtype
(P_Type
) then
7954 Set_Raises_Constraint_Error
(N
);
7957 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7958 -- since we can't do anything with unconstrained arrays. In addition,
7959 -- only the First, Last and Length attributes are possibly static.
7961 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7962 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7963 -- Unconstrained_Array are again exceptions, because they apply as well
7964 -- to unconstrained types.
7966 -- In addition Component_Size is an exception since it is possibly
7967 -- foldable, even though it is never static, and it does apply to
7968 -- unconstrained arrays. Furthermore, it is essential to fold this
7969 -- in the packed case, since otherwise the value will be incorrect.
7971 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7972 Id
= Attribute_Definite
or else
7973 Id
= Attribute_Has_Access_Values
or else
7974 Id
= Attribute_Has_Discriminants
or else
7975 Id
= Attribute_Has_Tagged_Values
or else
7976 Id
= Attribute_Lock_Free
or else
7977 Id
= Attribute_Type_Class
or else
7978 Id
= Attribute_Unconstrained_Array
or else
7979 Id
= Attribute_Component_Size
7982 Set_Is_Static_Expression
(N
, False);
7984 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7985 if not Is_Constrained
(P_Type
)
7986 or else (Id
/= Attribute_First
and then
7987 Id
/= Attribute_Last
and then
7988 Id
/= Attribute_Length
)
7994 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7995 -- scalar case, we hold off on enforcing staticness, since there are
7996 -- cases which we can fold at compile time even though they are not
7997 -- static (e.g. 'Length applied to a static index, even though other
7998 -- non-static indexes make the array type non-static). This is only
7999 -- an optimization, but it falls out essentially free, so why not.
8000 -- Again we compute the variable Static for easy reference later
8001 -- (note that no array attributes are static in Ada 83).
8003 -- We also need to set Static properly for subsequent legality checks
8004 -- which might otherwise accept non-static constants in contexts
8005 -- where they are not legal.
8008 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
8009 Set_Is_Static_Expression
(N
, Static
);
8015 Nod
:= First_Index
(P_Type
);
8017 -- The expression is static if the array type is constrained
8018 -- by given bounds, and not by an initial expression. Constant
8019 -- strings are static in any case.
8021 if Root_Type
(P_Type
) /= Standard_String
then
8023 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
8024 Set_Is_Static_Expression
(N
, Static
);
8027 while Present
(Nod
) loop
8028 if not Is_Static_Subtype
(Etype
(Nod
)) then
8030 Set_Is_Static_Expression
(N
, False);
8032 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
8033 Set_Raises_Constraint_Error
(N
);
8035 Set_Is_Static_Expression
(N
, False);
8038 -- If however the index type is generic, or derived from
8039 -- one, attributes cannot be folded.
8041 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
8042 and then Id
/= Attribute_Component_Size
8052 -- Check any expressions that are present. Note that these expressions,
8053 -- depending on the particular attribute type, are either part of the
8054 -- attribute designator, or they are arguments in a case where the
8055 -- attribute reference returns a function. In the latter case, the
8056 -- rule in (RM 4.9(22)) applies and in particular requires the type
8057 -- of the expressions to be scalar in order for the attribute to be
8058 -- considered to be static.
8066 while Present
(E
) loop
8068 -- If expression is not static, then the attribute reference
8069 -- result certainly cannot be static.
8071 if not Is_Static_Expression
(E
) then
8073 Set_Is_Static_Expression
(N
, False);
8076 if Raises_Constraint_Error
(E
) then
8077 Set_Raises_Constraint_Error
(N
);
8080 -- If the result is not known at compile time, or is not of
8081 -- a scalar type, then the result is definitely not static,
8082 -- so we can quit now.
8084 if not Compile_Time_Known_Value
(E
)
8085 or else not Is_Scalar_Type
(Etype
(E
))
8087 -- An odd special case, if this is a Pos attribute, this
8088 -- is where we need to apply a range check since it does
8089 -- not get done anywhere else.
8091 if Id
= Attribute_Pos
then
8092 if Is_Integer_Type
(Etype
(E
)) then
8093 Apply_Range_Check
(E
, Etype
(N
));
8100 -- If the expression raises a constraint error, then so does
8101 -- the attribute reference. We keep going in this case because
8102 -- we are still interested in whether the attribute reference
8103 -- is static even if it is not static.
8105 elsif Raises_Constraint_Error
(E
) then
8106 Set_Raises_Constraint_Error
(N
);
8112 if Raises_Constraint_Error
(Prefix
(N
)) then
8113 Set_Is_Static_Expression
(N
, False);
8118 -- Deal with the case of a static attribute reference that raises
8119 -- constraint error. The Raises_Constraint_Error flag will already
8120 -- have been set, and the Static flag shows whether the attribute
8121 -- reference is static. In any case we certainly can't fold such an
8122 -- attribute reference.
8124 -- Note that the rewriting of the attribute node with the constraint
8125 -- error node is essential in this case, because otherwise Gigi might
8126 -- blow up on one of the attributes it never expects to see.
8128 -- The constraint_error node must have the type imposed by the context,
8129 -- to avoid spurious errors in the enclosing expression.
8131 if Raises_Constraint_Error
(N
) then
8133 Make_Raise_Constraint_Error
(Sloc
(N
),
8134 Reason
=> CE_Range_Check_Failed
);
8135 Set_Etype
(CE_Node
, Etype
(N
));
8136 Set_Raises_Constraint_Error
(CE_Node
);
8138 Rewrite
(N
, Relocate_Node
(CE_Node
));
8139 Set_Raises_Constraint_Error
(N
, True);
8143 -- At this point we have a potentially foldable attribute reference.
8144 -- If Static is set, then the attribute reference definitely obeys
8145 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8146 -- folded. If Static is not set, then the attribute may or may not
8147 -- be foldable, and the individual attribute processing routines
8148 -- test Static as required in cases where it makes a difference.
8150 -- In the case where Static is not set, we do know that all the
8151 -- expressions present are at least known at compile time (we assumed
8152 -- above that if this was not the case, then there was no hope of static
8153 -- evaluation). However, we did not require that the bounds of the
8154 -- prefix type be compile time known, let alone static). That's because
8155 -- there are many attributes that can be computed at compile time on
8156 -- non-static subtypes, even though such references are not static
8159 -- For VAX float, the root type is an IEEE type. So make sure to use the
8160 -- base type instead of the root-type for floating point attributes.
8164 -- Attributes related to Ada 2012 iterators; nothing to evaluate for
8167 when Attribute_Constant_Indexing
8168 | Attribute_Default_Iterator
8169 | Attribute_Implicit_Dereference
8170 | Attribute_Iterator_Element
8171 | Attribute_Iterable
8172 | Attribute_Variable_Indexing
8176 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8177 -- These were already rejected by the parser. Thus they shouldn't
8180 when Internal_Attribute_Id
=>
8181 raise Program_Error
;
8187 when Attribute_Adjacent
=>
8191 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8198 when Attribute_Aft
=>
8199 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8205 when Attribute_Alignment
=> Alignment_Block
: declare
8206 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8209 -- Fold if alignment is set and not otherwise
8211 if Known_Alignment
(P_TypeA
) then
8212 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8214 end Alignment_Block
;
8216 -----------------------------
8217 -- Atomic_Always_Lock_Free --
8218 -----------------------------
8220 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8223 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8225 V
: constant Entity_Id
:=
8227 (Support_Atomic_Primitives_On_Target
8228 and then Support_Atomic_Primitives
(P_Type
));
8231 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8233 -- Analyze and resolve as boolean. Note that this attribute is a
8234 -- static attribute in GNAT.
8236 Analyze_And_Resolve
(N
, Standard_Boolean
);
8238 Set_Is_Static_Expression
(N
, True);
8239 end Atomic_Always_Lock_Free
;
8245 -- Bit can never be folded
8247 when Attribute_Bit
=>
8254 -- Body_version can never be static
8256 when Attribute_Body_Version
=>
8263 when Attribute_Ceiling
=>
8265 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8267 --------------------
8268 -- Component_Size --
8269 --------------------
8271 when Attribute_Component_Size
=>
8272 if Known_Static_Component_Size
(P_Type
) then
8273 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
8280 when Attribute_Compose
=>
8283 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8290 -- Constrained is never folded for now, there may be cases that
8291 -- could be handled at compile time. To be looked at later.
8293 when Attribute_Constrained
=>
8295 -- The expander might fold it and set the static flag accordingly,
8296 -- but with expansion disabled (as in ASIS), it remains as an
8297 -- attribute reference, and this reference is not static.
8299 Set_Is_Static_Expression
(N
, False);
8306 when Attribute_Copy_Sign
=>
8310 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8317 when Attribute_Definite
=>
8318 Rewrite
(N
, New_Occurrence_Of
(
8319 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
8320 Analyze_And_Resolve
(N
, Standard_Boolean
);
8326 when Attribute_Delta
=>
8327 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
8333 when Attribute_Denorm
=>
8335 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
8337 ---------------------
8338 -- Descriptor_Size --
8339 ---------------------
8341 when Attribute_Descriptor_Size
=>
8348 when Attribute_Digits
=>
8349 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
8355 when Attribute_Emax
=>
8357 -- Ada 83 attribute is defined as (RM83 3.5.8)
8359 -- T'Emax = 4 * T'Mantissa
8361 Fold_Uint
(N
, 4 * Mantissa
, Static
);
8367 when Attribute_Enum_Rep
=> Enum_Rep
: declare
8371 -- The attribute appears in the form:
8373 -- Enum_Typ'Enum_Rep (Const)
8374 -- Enum_Typ'Enum_Rep (Enum_Lit)
8376 if Present
(E1
) then
8379 -- Otherwise the prefix denotes a constant or enumeration literal:
8382 -- Enum_Lit'Enum_Rep
8388 -- For an enumeration type with a non-standard representation use
8389 -- the Enumeration_Rep field of the proper constant. Note that this
8390 -- will not work for types Character/Wide_[Wide-]Character, since no
8391 -- real entities are created for the enumeration literals, but that
8392 -- does not matter since these two types do not have non-standard
8393 -- representations anyway.
8395 if Is_Enumeration_Type
(P_Type
)
8396 and then Has_Non_Standard_Rep
(P_Type
)
8398 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
8400 -- For enumeration types with standard representations and all other
8401 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
8405 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
8413 when Attribute_Enum_Val
=> Enum_Val
: declare
8417 -- We have something like Enum_Type'Enum_Val (23), so search for a
8418 -- corresponding value in the list of Enum_Rep values for the type.
8420 Lit
:= First_Literal
(P_Base_Type
);
8422 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
8423 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
8430 Apply_Compile_Time_Constraint_Error
8431 (N
, "no representation value matches",
8432 CE_Range_Check_Failed
,
8433 Warn
=> not Static
);
8443 when Attribute_Epsilon
=>
8445 -- Ada 83 attribute is defined as (RM83 3.5.8)
8447 -- T'Epsilon = 2.0**(1 - T'Mantissa)
8449 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
8455 when Attribute_Exponent
=>
8457 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8459 -----------------------
8460 -- Finalization_Size --
8461 -----------------------
8463 when Attribute_Finalization_Size
=>
8470 when Attribute_First
=>
8473 if Compile_Time_Known_Value
(Lo_Bound
) then
8474 if Is_Real_Type
(P_Type
) then
8475 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
8477 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8481 Check_Concurrent_Discriminant
(Lo_Bound
);
8488 when Attribute_First_Valid
=>
8489 if Has_Predicates
(P_Type
)
8490 and then Has_Static_Predicate
(P_Type
)
8493 FirstN
: constant Node_Id
:=
8494 First
(Static_Discrete_Predicate
(P_Type
));
8496 if Nkind
(FirstN
) = N_Range
then
8497 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
8499 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
8505 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8512 when Attribute_Fixed_Value
=>
8519 when Attribute_Floor
=>
8521 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8527 when Attribute_Fore
=>
8528 if Compile_Time_Known_Bounds
(P_Type
) then
8529 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
8536 when Attribute_Fraction
=>
8538 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8540 -----------------------
8541 -- Has_Access_Values --
8542 -----------------------
8544 when Attribute_Has_Access_Values
=>
8545 Rewrite
(N
, New_Occurrence_Of
8546 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8547 Analyze_And_Resolve
(N
, Standard_Boolean
);
8549 -----------------------
8550 -- Has_Discriminants --
8551 -----------------------
8553 when Attribute_Has_Discriminants
=>
8554 Rewrite
(N
, New_Occurrence_Of
(
8555 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8556 Analyze_And_Resolve
(N
, Standard_Boolean
);
8558 ----------------------
8559 -- Has_Same_Storage --
8560 ----------------------
8562 when Attribute_Has_Same_Storage
=>
8565 -----------------------
8566 -- Has_Tagged_Values --
8567 -----------------------
8569 when Attribute_Has_Tagged_Values
=>
8570 Rewrite
(N
, New_Occurrence_Of
8571 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8572 Analyze_And_Resolve
(N
, Standard_Boolean
);
8578 when Attribute_Identity
=>
8585 -- Image is a scalar attribute, but is never static, because it is
8586 -- not a static function (having a non-scalar argument (RM 4.9(22))
8587 -- However, we can constant-fold the image of an enumeration literal
8588 -- if names are available.
8590 when Attribute_Image
=>
8591 if Is_Entity_Name
(E1
)
8592 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8593 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8594 and then not Global_Discard_Names
8597 Lit
: constant Entity_Id
:= Entity
(E1
);
8601 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8602 Set_Casing
(All_Upper_Case
);
8603 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8605 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8606 Analyze_And_Resolve
(N
, Standard_String
);
8607 Set_Is_Static_Expression
(N
, False);
8615 -- We never try to fold Integer_Value (though perhaps we could???)
8617 when Attribute_Integer_Value
=>
8624 -- Invalid_Value is a scalar attribute that is never static, because
8625 -- the value is by design out of range.
8627 when Attribute_Invalid_Value
=>
8634 when Attribute_Large
=>
8636 -- For fixed-point, we use the identity:
8638 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8640 if Is_Fixed_Point_Type
(P_Type
) then
8642 Make_Op_Multiply
(Loc
,
8644 Make_Op_Subtract
(Loc
,
8648 Make_Real_Literal
(Loc
, Ureal_2
),
8650 Make_Attribute_Reference
(Loc
,
8652 Attribute_Name
=> Name_Mantissa
)),
8653 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8656 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8658 Analyze_And_Resolve
(N
, C_Type
);
8660 -- Floating-point (Ada 83 compatibility)
8663 -- Ada 83 attribute is defined as (RM83 3.5.8)
8665 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8669 -- T'Emax = 4 * T'Mantissa
8673 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8681 when Attribute_Lock_Free
=> Lock_Free
: declare
8682 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8685 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8687 -- Analyze and resolve as boolean. Note that this attribute is a
8688 -- static attribute in GNAT.
8690 Analyze_And_Resolve
(N
, Standard_Boolean
);
8692 Set_Is_Static_Expression
(N
, True);
8699 when Attribute_Last
=>
8702 if Compile_Time_Known_Value
(Hi_Bound
) then
8703 if Is_Real_Type
(P_Type
) then
8704 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8706 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8710 Check_Concurrent_Discriminant
(Hi_Bound
);
8717 when Attribute_Last_Valid
=>
8718 if Has_Predicates
(P_Type
)
8719 and then Has_Static_Predicate
(P_Type
)
8722 LastN
: constant Node_Id
:=
8723 Last
(Static_Discrete_Predicate
(P_Type
));
8725 if Nkind
(LastN
) = N_Range
then
8726 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8728 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8734 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8741 when Attribute_Leading_Part
=>
8744 Eval_Fat
.Leading_Part
8745 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8752 when Attribute_Length
=> Length
: declare
8756 -- If any index type is a formal type, or derived from one, the
8757 -- bounds are not static. Treating them as static can produce
8758 -- spurious warnings or improper constant folding.
8760 Ind
:= First_Index
(P_Type
);
8761 while Present
(Ind
) loop
8762 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8771 -- For two compile time values, we can compute length
8773 if Compile_Time_Known_Value
(Lo_Bound
)
8774 and then Compile_Time_Known_Value
(Hi_Bound
)
8777 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8781 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8782 -- comparable, and we can figure out the difference between them.
8785 Diff
: aliased Uint
;
8789 Compile_Time_Compare
8790 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8793 Fold_Uint
(N
, Uint_1
, Static
);
8796 Fold_Uint
(N
, Uint_0
, Static
);
8799 if Diff
/= No_Uint
then
8800 Fold_Uint
(N
, Diff
+ 1, Static
);
8813 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8814 -- of the said attribute at the point of entry into the related loop. As
8815 -- such, the attribute reference does not need to be evaluated because
8816 -- the prefix is the one that is evaluted.
8818 when Attribute_Loop_Entry
=>
8825 when Attribute_Machine
=>
8829 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8836 when Attribute_Machine_Emax
=>
8837 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8843 when Attribute_Machine_Emin
=>
8844 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8846 ----------------------
8847 -- Machine_Mantissa --
8848 ----------------------
8850 when Attribute_Machine_Mantissa
=>
8851 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8853 -----------------------
8854 -- Machine_Overflows --
8855 -----------------------
8857 when Attribute_Machine_Overflows
=>
8859 -- Always true for fixed-point
8861 if Is_Fixed_Point_Type
(P_Type
) then
8862 Fold_Uint
(N
, True_Value
, Static
);
8864 -- Floating point case
8868 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8876 when Attribute_Machine_Radix
=>
8877 if Is_Fixed_Point_Type
(P_Type
) then
8878 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8879 and then Machine_Radix_10
(P_Type
)
8881 Fold_Uint
(N
, Uint_10
, Static
);
8883 Fold_Uint
(N
, Uint_2
, Static
);
8886 -- All floating-point type always have radix 2
8889 Fold_Uint
(N
, Uint_2
, Static
);
8892 ----------------------
8893 -- Machine_Rounding --
8894 ----------------------
8896 -- Note: for the folding case, it is fine to treat Machine_Rounding
8897 -- exactly the same way as Rounding, since this is one of the allowed
8898 -- behaviors, and performance is not an issue here. It might be a bit
8899 -- better to give the same result as it would give at run time, even
8900 -- though the non-determinism is certainly permitted.
8902 when Attribute_Machine_Rounding
=>
8904 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8906 --------------------
8907 -- Machine_Rounds --
8908 --------------------
8910 when Attribute_Machine_Rounds
=>
8912 -- Always False for fixed-point
8914 if Is_Fixed_Point_Type
(P_Type
) then
8915 Fold_Uint
(N
, False_Value
, Static
);
8917 -- Else yield proper floating-point result
8921 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8929 -- Note: Machine_Size is identical to Object_Size
8931 when Attribute_Machine_Size
=> Machine_Size
: declare
8932 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8935 if Known_Esize
(P_TypeA
) then
8936 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8944 when Attribute_Mantissa
=>
8946 -- Fixed-point mantissa
8948 if Is_Fixed_Point_Type
(P_Type
) then
8950 -- Compile time foldable case
8952 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8954 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8956 -- The calculation of the obsolete Ada 83 attribute Mantissa
8957 -- is annoying, because of AI00143, quoted here:
8959 -- !question 84-01-10
8961 -- Consider the model numbers for F:
8963 -- type F is delta 1.0 range -7.0 .. 8.0;
8965 -- The wording requires that F'MANTISSA be the SMALLEST
8966 -- integer number for which each bound of the specified
8967 -- range is either a model number or lies at most small
8968 -- distant from a model number. This means F'MANTISSA
8969 -- is required to be 3 since the range -7.0 .. 7.0 fits
8970 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8971 -- number, namely, 7. Is this analysis correct? Note that
8972 -- this implies the upper bound of the range is not
8973 -- represented as a model number.
8975 -- !response 84-03-17
8977 -- The analysis is correct. The upper and lower bounds for
8978 -- a fixed point type can lie outside the range of model
8989 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8990 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8991 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8992 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8994 -- If the Bound is exactly a model number, i.e. a multiple
8995 -- of Small, then we back it off by one to get the integer
8996 -- value that must be representable.
8998 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8999 Max_Man
:= Max_Man
- 1;
9002 -- Now find corresponding size = Mantissa value
9005 while 2 ** Siz
< Max_Man
loop
9009 Fold_Uint
(N
, Siz
, Static
);
9013 -- The case of dynamic bounds cannot be evaluated at compile
9014 -- time. Instead we use a runtime routine (see Exp_Attr).
9019 -- Floating-point Mantissa
9022 Fold_Uint
(N
, Mantissa
, Static
);
9029 when Attribute_Max
=>
9030 if Is_Real_Type
(P_Type
) then
9032 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9034 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9037 ----------------------------------
9038 -- Max_Alignment_For_Allocation --
9039 ----------------------------------
9041 -- Max_Alignment_For_Allocation is usually the Alignment. However,
9042 -- arrays are allocated with dope, so we need to take into account both
9043 -- the alignment of the array, which comes from the component alignment,
9044 -- and the alignment of the dope. Also, if the alignment is unknown, we
9045 -- use the max (it's OK to be pessimistic).
9047 when Attribute_Max_Alignment_For_Allocation
=> Max_Align
: declare
9048 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
9050 if Known_Alignment
(P_Type
)
9051 and then (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
9053 A
:= Alignment
(P_Type
);
9056 Fold_Uint
(N
, A
, Static
);
9059 ----------------------------------
9060 -- Max_Size_In_Storage_Elements --
9061 ----------------------------------
9063 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9064 -- Storage_Unit boundary. We can fold any cases for which the size
9065 -- is known by the front end.
9067 when Attribute_Max_Size_In_Storage_Elements
=>
9068 if Known_Esize
(P_Type
) then
9070 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9071 System_Storage_Unit
,
9075 --------------------
9076 -- Mechanism_Code --
9077 --------------------
9079 when Attribute_Mechanism_Code
=> Mechanism_Code
: declare
9081 Mech
: Mechanism_Type
;
9086 Mech
:= Mechanism
(P_Entity
);
9089 Val
:= UI_To_Int
(Expr_Value
(E1
));
9091 Formal
:= First_Formal
(P_Entity
);
9092 for J
in 1 .. Val
- 1 loop
9093 Next_Formal
(Formal
);
9096 Mech
:= Mechanism
(Formal
);
9100 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9108 when Attribute_Min
=>
9109 if Is_Real_Type
(P_Type
) then
9111 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9114 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9121 when Attribute_Mod
=>
9123 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9129 when Attribute_Model
=>
9131 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9137 when Attribute_Model_Emin
=>
9138 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9144 when Attribute_Model_Epsilon
=>
9145 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9147 --------------------
9148 -- Model_Mantissa --
9149 --------------------
9151 when Attribute_Model_Mantissa
=>
9152 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9158 when Attribute_Model_Small
=>
9159 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9165 when Attribute_Modulus
=>
9166 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9168 --------------------
9169 -- Null_Parameter --
9170 --------------------
9172 -- Cannot fold, we know the value sort of, but the whole point is
9173 -- that there is no way to talk about this imaginary value except
9174 -- by using the attribute, so we leave it the way it is.
9176 when Attribute_Null_Parameter
=>
9183 -- The Object_Size attribute for a type returns the Esize of the
9184 -- type and can be folded if this value is known.
9186 when Attribute_Object_Size
=> Object_Size
: declare
9187 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9190 if Known_Esize
(P_TypeA
) then
9191 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9195 ----------------------
9196 -- Overlaps_Storage --
9197 ----------------------
9199 when Attribute_Overlaps_Storage
=>
9202 -------------------------
9203 -- Passed_By_Reference --
9204 -------------------------
9206 -- Scalar types are never passed by reference
9208 when Attribute_Passed_By_Reference
=>
9209 Fold_Uint
(N
, False_Value
, Static
);
9215 when Attribute_Pos
=>
9216 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9222 when Attribute_Pred
=>
9224 -- Floating-point case
9226 if Is_Floating_Point_Type
(P_Type
) then
9228 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9232 elsif Is_Fixed_Point_Type
(P_Type
) then
9234 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9236 -- Modular integer case (wraps)
9238 elsif Is_Modular_Integer_Type
(P_Type
) then
9239 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
9241 -- Other scalar cases
9244 pragma Assert
(Is_Scalar_Type
(P_Type
));
9246 if Is_Enumeration_Type
(P_Type
)
9247 and then Expr_Value
(E1
) =
9248 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9250 Apply_Compile_Time_Constraint_Error
9251 (N
, "Pred of `&''First`",
9252 CE_Overflow_Check_Failed
,
9254 Warn
=> not Static
);
9260 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
9267 -- No processing required, because by this stage, Range has been
9268 -- replaced by First .. Last, so this branch can never be taken.
9270 when Attribute_Range
=>
9271 raise Program_Error
;
9277 when Attribute_Range_Length
=> Range_Length
: declare
9278 Diff
: aliased Uint
;
9283 -- Can fold if both bounds are compile time known
9285 if Compile_Time_Known_Value
(Hi_Bound
)
9286 and then Compile_Time_Known_Value
(Lo_Bound
)
9290 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
9294 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9295 -- comparable, and we can figure out the difference between them.
9297 case Compile_Time_Compare
9298 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9301 Fold_Uint
(N
, Uint_1
, Static
);
9304 Fold_Uint
(N
, Uint_0
, Static
);
9307 if Diff
/= No_Uint
then
9308 Fold_Uint
(N
, Diff
+ 1, Static
);
9320 when Attribute_Ref
=>
9321 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9327 when Attribute_Remainder
=> Remainder
: declare
9328 X
: constant Ureal
:= Expr_Value_R
(E1
);
9329 Y
: constant Ureal
:= Expr_Value_R
(E2
);
9332 if UR_Is_Zero
(Y
) then
9333 Apply_Compile_Time_Constraint_Error
9334 (N
, "division by zero in Remainder",
9335 CE_Overflow_Check_Failed
,
9336 Warn
=> not Static
);
9342 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
9349 when Attribute_Restriction_Set
=>
9350 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
9351 Set_Is_Static_Expression
(N
);
9357 when Attribute_Round
=> Round
: declare
9362 -- First we get the (exact result) in units of small
9364 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
9366 -- Now round that exactly to an integer
9368 Si
:= UR_To_Uint
(Sr
);
9370 -- Finally the result is obtained by converting back to real
9372 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
9379 when Attribute_Rounding
=>
9381 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9387 when Attribute_Safe_Emax
=>
9388 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
9394 when Attribute_Safe_First
=>
9395 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
9401 when Attribute_Safe_Large
=>
9402 if Is_Fixed_Point_Type
(P_Type
) then
9404 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
9406 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9413 when Attribute_Safe_Last
=>
9414 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9420 when Attribute_Safe_Small
=>
9422 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
9423 -- for fixed-point, since is the same as Small, but we implement
9424 -- it for backwards compatibility.
9426 if Is_Fixed_Point_Type
(P_Type
) then
9427 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
9429 -- Ada 83 Safe_Small for floating-point cases
9432 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
9439 when Attribute_Scale
=>
9440 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
9446 when Attribute_Scaling
=>
9450 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9457 when Attribute_Signed_Zeros
=>
9459 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
9465 -- Size attribute returns the RM size. All scalar types can be folded,
9466 -- as well as any types for which the size is known by the front end,
9467 -- including any type for which a size attribute is specified. This is
9468 -- one of the places where it is annoying that a size of zero means two
9469 -- things (zero size for scalars, unspecified size for non-scalars).
9472 | Attribute_VADS_Size
9475 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9478 if Is_Scalar_Type
(P_TypeA
)
9479 or else RM_Size
(P_TypeA
) /= Uint_0
9483 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
9485 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
9488 -- If a size clause applies, then use the size from it.
9489 -- This is one of the rare cases where we can use the
9490 -- Size_Clause field for a subtype when Has_Size_Clause
9491 -- is False. Consider:
9493 -- type x is range 1 .. 64;
9494 -- for x'size use 12;
9495 -- subtype y is x range 0 .. 3;
9497 -- Here y has a size clause inherited from x, but
9498 -- normally it does not apply, and y'size is 2. However,
9499 -- y'VADS_Size is indeed 12 and not 2.
9502 and then Is_OK_Static_Expression
(Expression
(S
))
9504 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
9506 -- If no size is specified, then we simply use the object
9507 -- size in the VADS_Size case (e.g. Natural'Size is equal
9508 -- to Integer'Size, not one less).
9511 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9515 -- Normal case (Size) in which case we want the RM_Size
9518 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9527 when Attribute_Small
=>
9529 -- The floating-point case is present only for Ada 83 compatibility.
9530 -- Note that strictly this is an illegal addition, since we are
9531 -- extending an Ada 95 defined attribute, but we anticipate an
9532 -- ARG ruling that will permit this.
9534 if Is_Floating_Point_Type
(P_Type
) then
9536 -- Ada 83 attribute is defined as (RM83 3.5.8)
9538 -- T'Small = 2.0**(-T'Emax - 1)
9542 -- T'Emax = 4 * T'Mantissa
9544 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9546 -- Normal Ada 95 fixed-point case
9549 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9556 when Attribute_Stream_Size
=>
9563 when Attribute_Succ
=>
9564 -- Floating-point case
9566 if Is_Floating_Point_Type
(P_Type
) then
9568 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9572 elsif Is_Fixed_Point_Type
(P_Type
) then
9573 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9575 -- Modular integer case (wraps)
9577 elsif Is_Modular_Integer_Type
(P_Type
) then
9578 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9580 -- Other scalar cases
9583 pragma Assert
(Is_Scalar_Type
(P_Type
));
9585 if Is_Enumeration_Type
(P_Type
)
9586 and then Expr_Value
(E1
) =
9587 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9589 Apply_Compile_Time_Constraint_Error
9590 (N
, "Succ of `&''Last`",
9591 CE_Overflow_Check_Failed
,
9593 Warn
=> not Static
);
9598 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9606 when Attribute_Truncation
=>
9609 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9616 when Attribute_Type_Class
=> Type_Class
: declare
9617 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9621 if Is_Descendant_Of_Address
(Typ
) then
9622 Id
:= RE_Type_Class_Address
;
9624 elsif Is_Enumeration_Type
(Typ
) then
9625 Id
:= RE_Type_Class_Enumeration
;
9627 elsif Is_Integer_Type
(Typ
) then
9628 Id
:= RE_Type_Class_Integer
;
9630 elsif Is_Fixed_Point_Type
(Typ
) then
9631 Id
:= RE_Type_Class_Fixed_Point
;
9633 elsif Is_Floating_Point_Type
(Typ
) then
9634 Id
:= RE_Type_Class_Floating_Point
;
9636 elsif Is_Array_Type
(Typ
) then
9637 Id
:= RE_Type_Class_Array
;
9639 elsif Is_Record_Type
(Typ
) then
9640 Id
:= RE_Type_Class_Record
;
9642 elsif Is_Access_Type
(Typ
) then
9643 Id
:= RE_Type_Class_Access
;
9645 elsif Is_Task_Type
(Typ
) then
9646 Id
:= RE_Type_Class_Task
;
9648 -- We treat protected types like task types. It would make more
9649 -- sense to have another enumeration value, but after all the
9650 -- whole point of this feature is to be exactly DEC compatible,
9651 -- and changing the type Type_Class would not meet this requirement.
9653 elsif Is_Protected_Type
(Typ
) then
9654 Id
:= RE_Type_Class_Task
;
9656 -- Not clear if there are any other possibilities, but if there
9657 -- are, then we will treat them as the address case.
9660 Id
:= RE_Type_Class_Address
;
9663 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9666 -----------------------
9667 -- Unbiased_Rounding --
9668 -----------------------
9670 when Attribute_Unbiased_Rounding
=>
9673 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9676 -------------------------
9677 -- Unconstrained_Array --
9678 -------------------------
9680 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9681 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9684 Rewrite
(N
, New_Occurrence_Of
(
9686 Is_Array_Type
(P_Type
)
9687 and then not Is_Constrained
(Typ
)), Loc
));
9689 -- Analyze and resolve as boolean, note that this attribute is
9690 -- a static attribute in GNAT.
9692 Analyze_And_Resolve
(N
, Standard_Boolean
);
9694 Set_Is_Static_Expression
(N
, True);
9695 end Unconstrained_Array
;
9697 -- Attribute Update is never static
9699 when Attribute_Update
=>
9706 -- Processing is shared with Size
9712 when Attribute_Val
=>
9713 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9715 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9717 Apply_Compile_Time_Constraint_Error
9718 (N
, "Val expression out of range",
9719 CE_Range_Check_Failed
,
9720 Warn
=> not Static
);
9726 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9733 -- The Value_Size attribute for a type returns the RM size of the type.
9734 -- This an always be folded for scalar types, and can also be folded for
9735 -- non-scalar types if the size is set. This is one of the places where
9736 -- it is annoying that a size of zero means two things!
9738 when Attribute_Value_Size
=> Value_Size
: declare
9739 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9742 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9743 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9751 -- Version can never be static
9753 when Attribute_Version
=>
9760 -- Wide_Image is a scalar attribute, but is never static, because it
9761 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9763 when Attribute_Wide_Image
=>
9766 ---------------------
9767 -- Wide_Wide_Image --
9768 ---------------------
9770 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9771 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9773 when Attribute_Wide_Wide_Image
=>
9776 ---------------------
9777 -- Wide_Wide_Width --
9778 ---------------------
9780 -- Processing for Wide_Wide_Width is combined with Width
9786 -- Processing for Wide_Width is combined with Width
9792 -- This processing also handles the case of Wide_[Wide_]Width
9794 when Attribute_Width
9795 | Attribute_Wide_Width
9796 | Attribute_Wide_Wide_Width
9798 if Compile_Time_Known_Bounds
(P_Type
) then
9800 -- Floating-point types
9802 if Is_Floating_Point_Type
(P_Type
) then
9804 -- Width is zero for a null range (RM 3.5 (38))
9806 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9807 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9809 Fold_Uint
(N
, Uint_0
, Static
);
9812 -- For floating-point, we have +N.dddE+nnn where length
9813 -- of ddd is determined by type'Digits - 1, but is one
9814 -- if Digits is one (RM 3.5 (33)).
9816 -- nnn is set to 2 for Short_Float and Float (32 bit
9817 -- floats), and 3 for Long_Float and Long_Long_Float.
9818 -- For machines where Long_Long_Float is the IEEE
9819 -- extended precision type, the exponent takes 4 digits.
9823 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9826 if Esize
(P_Type
) <= 32 then
9828 elsif Esize
(P_Type
) = 64 then
9834 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9838 -- Fixed-point types
9840 elsif Is_Fixed_Point_Type
(P_Type
) then
9842 -- Width is zero for a null range (RM 3.5 (38))
9844 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9845 Expr_Value
(Type_Low_Bound
(P_Type
))
9847 Fold_Uint
(N
, Uint_0
, Static
);
9849 -- The non-null case depends on the specific real type
9852 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9855 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9863 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9864 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9865 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9878 -- Width for types derived from Standard.Character
9879 -- and Standard.Wide_[Wide_]Character.
9881 elsif Is_Standard_Character_Type
(P_Type
) then
9884 -- Set W larger if needed
9886 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9888 -- All wide characters look like Hex_hhhhhhhh
9892 -- No need to compute this more than once
9897 C
:= Character'Val (J
);
9899 -- Test for all cases where Character'Image
9900 -- yields an image that is longer than three
9901 -- characters. First the cases of Reserved_xxx
9902 -- names (length = 12).
9980 | No_Break_Space
.. LC_Y_Diaeresis
9982 -- Special case of soft hyphen in Ada 2005
9984 if C
= Character'Val (16#AD#
)
9985 and then Ada_Version
>= Ada_2005
9993 W
:= Int
'Max (W
, Wt
);
9997 -- Width for types derived from Standard.Boolean
9999 elsif R
= Standard_Boolean
then
10006 -- Width for integer types
10008 elsif Is_Integer_Type
(P_Type
) then
10009 T
:= UI_Max
(abs Lo
, abs Hi
);
10017 -- User declared enum type with discard names
10019 elsif Discard_Names
(R
) then
10021 -- If range is null, result is zero, that has already
10022 -- been dealt with, so what we need is the power of ten
10023 -- that accommodates the Pos of the largest value, which
10024 -- is the high bound of the range + one for the space.
10033 -- Only remaining possibility is user declared enum type
10034 -- with normal case of Discard_Names not active.
10037 pragma Assert
(Is_Enumeration_Type
(P_Type
));
10040 L
:= First_Literal
(P_Type
);
10041 while Present
(L
) loop
10043 -- Only pay attention to in range characters
10045 if Lo
<= Enumeration_Pos
(L
)
10046 and then Enumeration_Pos
(L
) <= Hi
10048 -- For Width case, use decoded name
10050 if Id
= Attribute_Width
then
10051 Get_Decoded_Name_String
(Chars
(L
));
10052 Wt
:= Nat
(Name_Len
);
10054 -- For Wide_[Wide_]Width, use encoded name, and
10055 -- then adjust for the encoding.
10058 Get_Name_String
(Chars
(L
));
10060 -- Character literals are always of length 3
10062 if Name_Buffer
(1) = 'Q' then
10065 -- Otherwise loop to adjust for upper/wide chars
10068 Wt
:= Nat
(Name_Len
);
10070 for J
in 1 .. Name_Len
loop
10071 if Name_Buffer
(J
) = 'U' then
10073 elsif Name_Buffer
(J
) = 'W' then
10080 W
:= Int
'Max (W
, Wt
);
10087 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
10092 -- The following attributes denote functions that cannot be folded
10094 when Attribute_From_Any
10096 | Attribute_TypeCode
10100 -- The following attributes can never be folded, and furthermore we
10101 -- should not even have entered the case statement for any of these.
10102 -- Note that in some cases, the values have already been folded as
10103 -- a result of the processing in Analyze_Attribute or earlier in
10106 when Attribute_Abort_Signal
10108 | Attribute_Address
10109 | Attribute_Address_Size
10110 | Attribute_Asm_Input
10111 | Attribute_Asm_Output
10113 | Attribute_Bit_Order
10114 | Attribute_Bit_Position
10115 | Attribute_Callable
10118 | Attribute_Code_Address
10119 | Attribute_Compiler_Version
10121 | Attribute_Default_Bit_Order
10122 | Attribute_Default_Scalar_Storage_Order
10124 | Attribute_Elaborated
10125 | Attribute_Elab_Body
10126 | Attribute_Elab_Spec
10127 | Attribute_Elab_Subp_Body
10128 | Attribute_Enabled
10129 | Attribute_External_Tag
10130 | Attribute_Fast_Math
10131 | Attribute_First_Bit
10134 | Attribute_Last_Bit
10135 | Attribute_Library_Level
10136 | Attribute_Maximum_Alignment
10139 | Attribute_Partition_ID
10140 | Attribute_Pool_Address
10141 | Attribute_Position
10142 | Attribute_Priority
10145 | Attribute_Scalar_Storage_Order
10146 | Attribute_Simple_Storage_Pool
10147 | Attribute_Storage_Pool
10148 | Attribute_Storage_Size
10149 | Attribute_Storage_Unit
10150 | Attribute_Stub_Type
10151 | Attribute_System_Allocator_Alignment
10153 | Attribute_Target_Name
10154 | Attribute_Terminated
10155 | Attribute_To_Address
10156 | Attribute_Type_Key
10157 | Attribute_Unchecked_Access
10158 | Attribute_Universal_Literal_String
10159 | Attribute_Unrestricted_Access
10161 | Attribute_Valid_Scalars
10163 | Attribute_Wchar_T_Size
10164 | Attribute_Wide_Value
10165 | Attribute_Wide_Wide_Value
10166 | Attribute_Word_Size
10169 raise Program_Error
;
10172 -- At the end of the case, one more check. If we did a static evaluation
10173 -- so that the result is now a literal, then set Is_Static_Expression
10174 -- in the constant only if the prefix type is a static subtype. For
10175 -- non-static subtypes, the folding is still OK, but not static.
10177 -- An exception is the GNAT attribute Constrained_Array which is
10178 -- defined to be a static attribute in all cases.
10180 if Nkind_In
(N
, N_Integer_Literal
,
10182 N_Character_Literal
,
10184 or else (Is_Entity_Name
(N
)
10185 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10187 Set_Is_Static_Expression
(N
, Static
);
10189 -- If this is still an attribute reference, then it has not been folded
10190 -- and that means that its expressions are in a non-static context.
10192 elsif Nkind
(N
) = N_Attribute_Reference
then
10195 -- Note: the else case not covered here are odd cases where the
10196 -- processing has transformed the attribute into something other
10197 -- than a constant. Nothing more to do in such cases.
10202 end Eval_Attribute
;
10204 ------------------------------
10205 -- Is_Anonymous_Tagged_Base --
10206 ------------------------------
10208 function Is_Anonymous_Tagged_Base
10210 Typ
: Entity_Id
) return Boolean
10214 Anon
= Current_Scope
10215 and then Is_Itype
(Anon
)
10216 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
10217 end Is_Anonymous_Tagged_Base
;
10219 --------------------------------
10220 -- Name_Implies_Lvalue_Prefix --
10221 --------------------------------
10223 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
10224 pragma Assert
(Is_Attribute_Name
(Nam
));
10226 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
10227 end Name_Implies_Lvalue_Prefix
;
10229 -----------------------
10230 -- Resolve_Attribute --
10231 -----------------------
10233 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
10234 Loc
: constant Source_Ptr
:= Sloc
(N
);
10235 P
: constant Node_Id
:= Prefix
(N
);
10236 Aname
: constant Name_Id
:= Attribute_Name
(N
);
10237 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
10238 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10239 Des_Btyp
: Entity_Id
;
10240 Index
: Interp_Index
;
10242 Nom_Subt
: Entity_Id
;
10244 procedure Accessibility_Message
;
10245 -- Error, or warning within an instance, if the static accessibility
10246 -- rules of 3.10.2 are violated.
10248 function Declared_Within_Generic_Unit
10249 (Entity
: Entity_Id
;
10250 Generic_Unit
: Node_Id
) return Boolean;
10251 -- Returns True if Declared_Entity is declared within the declarative
10252 -- region of Generic_Unit; otherwise returns False.
10254 ---------------------------
10255 -- Accessibility_Message --
10256 ---------------------------
10258 procedure Accessibility_Message
is
10259 Indic
: Node_Id
:= Parent
(Parent
(N
));
10262 -- In an instance, this is a runtime check, but one we
10263 -- know will fail, so generate an appropriate warning.
10265 if In_Instance_Body
then
10266 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10268 ("non-local pointer cannot point to local object<<", P
);
10269 Error_Msg_F
("\Program_Error [<<", P
);
10271 Make_Raise_Program_Error
(Loc
,
10272 Reason
=> PE_Accessibility_Check_Failed
));
10273 Set_Etype
(N
, Typ
);
10277 Error_Msg_F
("non-local pointer cannot point to local object", P
);
10279 -- Check for case where we have a missing access definition
10281 if Is_Record_Type
(Current_Scope
)
10283 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
10284 N_Index_Or_Discriminant_Constraint
)
10286 Indic
:= Parent
(Parent
(N
));
10287 while Present
(Indic
)
10288 and then Nkind
(Indic
) /= N_Subtype_Indication
10290 Indic
:= Parent
(Indic
);
10293 if Present
(Indic
) then
10295 ("\use an access definition for" &
10296 " the access discriminant of&",
10297 N
, Entity
(Subtype_Mark
(Indic
)));
10301 end Accessibility_Message
;
10303 ----------------------------------
10304 -- Declared_Within_Generic_Unit --
10305 ----------------------------------
10307 function Declared_Within_Generic_Unit
10308 (Entity
: Entity_Id
;
10309 Generic_Unit
: Node_Id
) return Boolean
10311 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
10314 while Present
(Generic_Encloser
) loop
10315 if Generic_Encloser
= Generic_Unit
then
10319 -- We have to step to the scope of the generic's entity, because
10320 -- otherwise we'll just get back the same generic.
10322 Generic_Encloser
:=
10323 Enclosing_Generic_Unit
10324 (Scope
(Defining_Entity
(Generic_Encloser
)));
10328 end Declared_Within_Generic_Unit
;
10330 -- Start of processing for Resolve_Attribute
10333 -- If error during analysis, no point in continuing, except for array
10334 -- types, where we get better recovery by using unconstrained indexes
10335 -- than nothing at all (see Check_Array_Type).
10337 if Error_Posted
(N
)
10338 and then Attr_Id
/= Attribute_First
10339 and then Attr_Id
/= Attribute_Last
10340 and then Attr_Id
/= Attribute_Length
10341 and then Attr_Id
/= Attribute_Range
10346 -- If attribute was universal type, reset to actual type
10348 if Etype
(N
) = Universal_Integer
10349 or else Etype
(N
) = Universal_Real
10351 Set_Etype
(N
, Typ
);
10354 -- Remaining processing depends on attribute
10362 -- For access attributes, if the prefix denotes an entity, it is
10363 -- interpreted as a name, never as a call. It may be overloaded,
10364 -- in which case resolution uses the profile of the context type.
10365 -- Otherwise prefix must be resolved.
10367 when Attribute_Access
10368 | Attribute_Unchecked_Access
10369 | Attribute_Unrestricted_Access
10371 -- Note possible modification if we have a variable
10373 if Is_Variable
(P
) then
10375 PN
: constant Node_Id
:= Parent
(N
);
10378 Note
: Boolean := True;
10379 -- Skip this for the case of Unrestricted_Access occuring in
10380 -- the context of a Valid check, since this otherwise leads
10381 -- to a missed warning (the Valid check does not really
10382 -- modify!) If this case, Note will be reset to False.
10384 -- Skip it as well if the type is an Acccess_To_Constant,
10385 -- given that no use of the value can modify the prefix.
10388 if Attr_Id
= Attribute_Unrestricted_Access
10389 and then Nkind
(PN
) = N_Function_Call
10393 if Nkind
(Nm
) = N_Expanded_Name
10394 and then Chars
(Nm
) = Name_Valid
10395 and then Nkind
(Prefix
(Nm
)) = N_Identifier
10396 and then Chars
(Prefix
(Nm
)) = Name_Attr_Long_Float
10401 elsif Is_Access_Constant
(Typ
) then
10406 Note_Possible_Modification
(P
, Sure
=> False);
10411 -- The following comes from a query concerning improper use of
10412 -- universal_access in equality tests involving anonymous access
10413 -- types. Another good reason for 'Ref, but for now disable the
10414 -- test, which breaks several filed tests???
10416 if Ekind
(Typ
) = E_Anonymous_Access_Type
10417 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
10420 Error_Msg_N
("need unique type to resolve 'Access", N
);
10421 Error_Msg_N
("\qualify attribute with some access type", N
);
10424 -- Case where prefix is an entity name
10426 if Is_Entity_Name
(P
) then
10428 -- Deal with case where prefix itself is overloaded
10430 if Is_Overloaded
(P
) then
10431 Get_First_Interp
(P
, Index
, It
);
10432 while Present
(It
.Nam
) loop
10433 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
10434 Set_Entity
(P
, It
.Nam
);
10436 -- The prefix is definitely NOT overloaded anymore at
10437 -- this point, so we reset the Is_Overloaded flag to
10438 -- avoid any confusion when reanalyzing the node.
10440 Set_Is_Overloaded
(P
, False);
10441 Set_Is_Overloaded
(N
, False);
10442 Generate_Reference
(Entity
(P
), P
);
10446 Get_Next_Interp
(Index
, It
);
10449 -- If Prefix is a subprogram name, this reference freezes,
10450 -- but not if within spec expression mode. The profile of
10451 -- the subprogram is not frozen at this point.
10453 if not In_Spec_Expression
then
10454 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10457 -- If it is a type, there is nothing to resolve.
10458 -- If it is a subprogram, do not freeze its profile.
10459 -- If it is an object, complete its resolution.
10461 elsif Is_Overloadable
(Entity
(P
)) then
10462 if not In_Spec_Expression
then
10463 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10466 -- Nothing to do if prefix is a type name
10468 elsif Is_Type
(Entity
(P
)) then
10471 -- Otherwise non-overloaded other case, resolve the prefix
10477 -- Some further error checks
10479 Error_Msg_Name_1
:= Aname
;
10481 if not Is_Entity_Name
(P
) then
10484 elsif Is_Overloadable
(Entity
(P
))
10485 and then Is_Abstract_Subprogram
(Entity
(P
))
10487 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
10488 Set_Etype
(N
, Any_Type
);
10490 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
10492 ("prefix of % attribute cannot be enumeration literal", P
);
10493 Set_Etype
(N
, Any_Type
);
10495 -- An attempt to take 'Access of a function that renames an
10496 -- enumeration literal. Issue a specialized error message.
10498 elsif Ekind
(Entity
(P
)) = E_Function
10499 and then Present
(Alias
(Entity
(P
)))
10500 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
10503 ("prefix of % attribute cannot be function renaming "
10504 & "an enumeration literal", P
);
10505 Set_Etype
(N
, Any_Type
);
10507 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
10508 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
10509 Set_Etype
(N
, Any_Type
);
10512 -- Assignments, return statements, components of aggregates,
10513 -- generic instantiations will require convention checks if
10514 -- the type is an access to subprogram. Given that there will
10515 -- also be accessibility checks on those, this is where the
10516 -- checks can eventually be centralized ???
10518 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10519 E_Access_Subprogram_Type
,
10520 E_Anonymous_Access_Protected_Subprogram_Type
,
10521 E_Anonymous_Access_Subprogram_Type
)
10523 -- Deal with convention mismatch
10525 if Convention
(Designated_Type
(Btyp
)) /=
10526 Convention
(Entity
(P
))
10528 -- The rule in 6.3.1 (8) deserves a special error
10531 if Convention
(Btyp
) = Convention_Intrinsic
10532 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
10533 and then Is_Entity_Name
(Name
(Parent
(N
)))
10534 and then Inside_A_Generic
10537 Subp
: constant Entity_Id
:=
10538 Entity
(Name
(Parent
(N
)));
10540 if Convention
(Subp
) = Convention_Intrinsic
then
10542 ("?subprogram and its formal access "
10543 & "parameters have convention Intrinsic",
10546 ("actual cannot be access attribute", N
);
10552 ("subprogram & has wrong convention", P
, Entity
(P
));
10553 Error_Msg_Sloc
:= Sloc
(Btyp
);
10554 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
10557 if not Is_Itype
(Btyp
)
10558 and then not Has_Convention_Pragma
(Btyp
)
10561 ("\probable missing pragma Convention for &",
10566 Check_Subtype_Conformant
10567 (New_Id
=> Entity
(P
),
10568 Old_Id
=> Designated_Type
(Btyp
),
10572 if Attr_Id
= Attribute_Unchecked_Access
then
10573 Error_Msg_Name_1
:= Aname
;
10575 ("attribute% cannot be applied to a subprogram", P
);
10577 elsif Aname
= Name_Unrestricted_Access
then
10578 null; -- Nothing to check
10580 -- Check the static accessibility rule of 3.10.2(32).
10581 -- This rule also applies within the private part of an
10582 -- instantiation. This rule does not apply to anonymous
10583 -- access-to-subprogram types in access parameters.
10585 elsif Attr_Id
= Attribute_Access
10586 and then not In_Instance_Body
10588 (Ekind
(Btyp
) = E_Access_Subprogram_Type
10589 or else Is_Local_Anonymous_Access
(Btyp
))
10590 and then Subprogram_Access_Level
(Entity
(P
)) >
10591 Type_Access_Level
(Btyp
)
10594 ("subprogram must not be deeper than access type", P
);
10596 -- Check the restriction of 3.10.2(32) that disallows the
10597 -- access attribute within a generic body when the ultimate
10598 -- ancestor of the type of the attribute is declared outside
10599 -- of the generic unit and the subprogram is declared within
10600 -- that generic unit. This includes any such attribute that
10601 -- occurs within the body of a generic unit that is a child
10602 -- of the generic unit where the subprogram is declared.
10604 -- The rule also prohibits applying the attribute when the
10605 -- access type is a generic formal access type (since the
10606 -- level of the actual type is not known). This restriction
10607 -- does not apply when the attribute type is an anonymous
10608 -- access-to-subprogram type. Note that this check was
10609 -- revised by AI-229, because the original Ada 95 rule
10610 -- was too lax. The original rule only applied when the
10611 -- subprogram was declared within the body of the generic,
10612 -- which allowed the possibility of dangling references).
10613 -- The rule was also too strict in some cases, in that it
10614 -- didn't permit the access to be declared in the generic
10615 -- spec, whereas the revised rule does (as long as it's not
10618 -- There are a couple of subtleties of the test for applying
10619 -- the check that are worth noting. First, we only apply it
10620 -- when the levels of the subprogram and access type are the
10621 -- same (the case where the subprogram is statically deeper
10622 -- was applied above, and the case where the type is deeper
10623 -- is always safe). Second, we want the check to apply
10624 -- within nested generic bodies and generic child unit
10625 -- bodies, but not to apply to an attribute that appears in
10626 -- the generic unit's specification. This is done by testing
10627 -- that the attribute's innermost enclosing generic body is
10628 -- not the same as the innermost generic body enclosing the
10629 -- generic unit where the subprogram is declared (we don't
10630 -- want the check to apply when the access attribute is in
10631 -- the spec and there's some other generic body enclosing
10632 -- generic). Finally, there's no point applying the check
10633 -- when within an instance, because any violations will have
10634 -- been caught by the compilation of the generic unit.
10636 -- We relax this check in Relaxed_RM_Semantics mode for
10637 -- compatibility with legacy code for use by Ada source
10638 -- code analyzers (e.g. CodePeer).
10640 elsif Attr_Id
= Attribute_Access
10641 and then not Relaxed_RM_Semantics
10642 and then not In_Instance
10643 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
10644 and then Present
(Enclosing_Generic_Body
(N
))
10645 and then Enclosing_Generic_Body
(N
) /=
10646 Enclosing_Generic_Body
10647 (Enclosing_Generic_Unit
(Entity
(P
)))
10648 and then Subprogram_Access_Level
(Entity
(P
)) =
10649 Type_Access_Level
(Btyp
)
10650 and then Ekind
(Btyp
) /=
10651 E_Anonymous_Access_Subprogram_Type
10652 and then Ekind
(Btyp
) /=
10653 E_Anonymous_Access_Protected_Subprogram_Type
10655 -- The attribute type's ultimate ancestor must be
10656 -- declared within the same generic unit as the
10657 -- subprogram is declared (including within another
10658 -- nested generic unit). The error message is
10659 -- specialized to say "ancestor" for the case where the
10660 -- access type is not its own ancestor, since saying
10661 -- simply "access type" would be very confusing.
10663 if not Declared_Within_Generic_Unit
10665 Enclosing_Generic_Unit
(Entity
(P
)))
10668 ("''Access attribute not allowed in generic body",
10671 if Root_Type
(Btyp
) = Btyp
then
10674 "access type & is declared outside " &
10675 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10678 ("\because ancestor of " &
10679 "access type & is declared outside " &
10680 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10684 ("\move ''Access to private part, or " &
10685 "(Ada 2005) use anonymous access type instead of &",
10688 -- If the ultimate ancestor of the attribute's type is
10689 -- a formal type, then the attribute is illegal because
10690 -- the actual type might be declared at a higher level.
10691 -- The error message is specialized to say "ancestor"
10692 -- for the case where the access type is not its own
10693 -- ancestor, since saying simply "access type" would be
10696 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10697 if Root_Type
(Btyp
) = Btyp
then
10699 ("access type must not be a generic formal type",
10703 ("ancestor access type must not be a generic " &
10710 -- If this is a renaming, an inherited operation, or a
10711 -- subprogram instance, use the original entity. This may make
10712 -- the node type-inconsistent, so this transformation can only
10713 -- be done if the node will not be reanalyzed. In particular,
10714 -- if it is within a default expression, the transformation
10715 -- must be delayed until the default subprogram is created for
10716 -- it, when the enclosing subprogram is frozen.
10718 if Is_Entity_Name
(P
)
10719 and then Is_Overloadable
(Entity
(P
))
10720 and then Present
(Alias
(Entity
(P
)))
10721 and then Expander_Active
10724 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10727 elsif Nkind
(P
) = N_Selected_Component
10728 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10730 -- Protected operation. If operation is overloaded, must
10731 -- disambiguate. Prefix that denotes protected object itself
10732 -- is resolved with its own type.
10734 if Attr_Id
= Attribute_Unchecked_Access
then
10735 Error_Msg_Name_1
:= Aname
;
10737 ("attribute% cannot be applied to protected operation", P
);
10740 Resolve
(Prefix
(P
));
10741 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10743 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10744 -- statically illegal if F is an anonymous access to subprogram.
10746 elsif Nkind
(P
) = N_Explicit_Dereference
10747 and then Is_Entity_Name
(Prefix
(P
))
10748 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10749 E_Anonymous_Access_Subprogram_Type
10751 Error_Msg_N
("anonymous access to subprogram "
10752 & "has deeper accessibility than any master", P
);
10754 elsif Is_Overloaded
(P
) then
10756 -- Use the designated type of the context to disambiguate
10757 -- Note that this was not strictly conformant to Ada 95,
10758 -- but was the implementation adopted by most Ada 95 compilers.
10759 -- The use of the context type to resolve an Access attribute
10760 -- reference is now mandated in AI-235 for Ada 2005.
10763 Index
: Interp_Index
;
10767 Get_First_Interp
(P
, Index
, It
);
10768 while Present
(It
.Typ
) loop
10769 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10770 Resolve
(P
, It
.Typ
);
10774 Get_Next_Interp
(Index
, It
);
10781 -- X'Access is illegal if X denotes a constant and the access type
10782 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10783 -- does not apply to 'Unrestricted_Access. If the reference is a
10784 -- default-initialized aggregate component for a self-referential
10785 -- type the reference is legal.
10787 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10788 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10789 or else (Is_Record_Type
(Btyp
)
10791 Present
(Corresponding_Remote_Type
(Btyp
)))
10792 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10793 or else Ekind
(Btyp
)
10794 = E_Anonymous_Access_Protected_Subprogram_Type
10795 or else Is_Access_Constant
(Btyp
)
10796 or else Is_Variable
(P
)
10797 or else Attr_Id
= Attribute_Unrestricted_Access
)
10799 if Is_Entity_Name
(P
)
10800 and then Is_Type
(Entity
(P
))
10802 -- Legality of a self-reference through an access
10803 -- attribute has been verified in Analyze_Access_Attribute.
10807 elsif Comes_From_Source
(N
) then
10808 Error_Msg_F
("access-to-variable designates constant", P
);
10812 Des_Btyp
:= Designated_Type
(Btyp
);
10814 if Ada_Version
>= Ada_2005
10815 and then Is_Incomplete_Type
(Des_Btyp
)
10817 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10818 -- imported entity, and the non-limited view is visible, make
10819 -- use of it. If it is an incomplete subtype, use the base type
10822 if From_Limited_With
(Des_Btyp
)
10823 and then Present
(Non_Limited_View
(Des_Btyp
))
10825 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10827 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10828 Des_Btyp
:= Etype
(Des_Btyp
);
10832 if (Attr_Id
= Attribute_Access
10834 Attr_Id
= Attribute_Unchecked_Access
)
10835 and then (Ekind
(Btyp
) = E_General_Access_Type
10836 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10838 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10839 -- access types for stand-alone objects, record and array
10840 -- components, and return objects. For a component definition
10841 -- the level is the same of the enclosing composite type.
10843 if Ada_Version
>= Ada_2005
10844 and then (Is_Local_Anonymous_Access
(Btyp
)
10846 -- Handle cases where Btyp is the anonymous access
10847 -- type of an Ada 2012 stand-alone object.
10849 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10850 N_Object_Declaration
)
10852 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10853 and then Attr_Id
= Attribute_Access
10855 -- In an instance, this is a runtime check, but one we know
10856 -- will fail, so generate an appropriate warning. As usual,
10857 -- this kind of warning is an error in SPARK mode.
10859 if In_Instance_Body
then
10860 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10862 ("non-local pointer cannot point to local object<<", P
);
10863 Error_Msg_F
("\Program_Error [<<", P
);
10866 Make_Raise_Program_Error
(Loc
,
10867 Reason
=> PE_Accessibility_Check_Failed
));
10868 Set_Etype
(N
, Typ
);
10872 ("non-local pointer cannot point to local object", P
);
10876 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10878 ("illegal attribute for discriminant-dependent component",
10882 -- Check static matching rule of 3.10.2(27). Nominal subtype
10883 -- of the prefix must statically match the designated type.
10885 Nom_Subt
:= Etype
(P
);
10887 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10888 Nom_Subt
:= Base_Type
(Nom_Subt
);
10891 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10893 -- If the attribute is in the context of an access
10894 -- parameter, then the prefix is allowed to be of
10895 -- the class-wide type (by AI-127).
10897 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10898 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10899 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10905 Desig
:= Designated_Type
(Typ
);
10907 if Is_Class_Wide_Type
(Desig
) then
10908 Desig
:= Etype
(Desig
);
10911 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10916 ("type of prefix: & not compatible",
10919 ("\with &, the expected designated type",
10920 P
, Designated_Type
(Typ
));
10925 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10927 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10928 and then Is_Class_Wide_Type
(Nom_Subt
))
10931 ("type of prefix: & is not covered", P
, Nom_Subt
);
10933 ("\by &, the expected designated type" &
10934 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10937 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10938 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10939 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10940 and then Designated_Type
(Typ
) /= Nom_Subt
10942 Apply_Discriminant_Check
10943 (N
, Etype
(Designated_Type
(Typ
)));
10946 -- Ada 2005 (AI-363): Require static matching when designated
10947 -- type has discriminants and a constrained partial view, since
10948 -- in general objects of such types are mutable, so we can't
10949 -- allow the access value to designate a constrained object
10950 -- (because access values must be assumed to designate mutable
10951 -- objects when designated type does not impose a constraint).
10953 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10956 elsif Has_Discriminants
(Designated_Type
(Typ
))
10957 and then not Is_Constrained
(Des_Btyp
)
10959 (Ada_Version
< Ada_2005
10961 not Object_Type_Has_Constrained_Partial_View
10962 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10963 Scop
=> Current_Scope
))
10969 ("object subtype must statically match "
10970 & "designated subtype", P
);
10972 if Is_Entity_Name
(P
)
10973 and then Is_Array_Type
(Designated_Type
(Typ
))
10976 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10979 ("aliased object has explicit bounds??", D
);
10981 ("\declare without bounds (and with explicit "
10982 & "initialization)??", D
);
10984 ("\for use with unconstrained access??", D
);
10989 -- Check the static accessibility rule of 3.10.2(28). Note that
10990 -- this check is not performed for the case of an anonymous
10991 -- access type, since the access attribute is always legal
10992 -- in such a context.
10994 if Attr_Id
/= Attribute_Unchecked_Access
10995 and then Ekind
(Btyp
) = E_General_Access_Type
10997 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10999 Accessibility_Message
;
11004 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
11005 E_Anonymous_Access_Protected_Subprogram_Type
)
11007 if Is_Entity_Name
(P
)
11008 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
11010 Error_Msg_F
("context requires a protected subprogram", P
);
11012 -- Check accessibility of protected object against that of the
11013 -- access type, but only on user code, because the expander
11014 -- creates access references for handlers. If the context is an
11015 -- anonymous_access_to_protected, there are no accessibility
11016 -- checks either. Omit check entirely for Unrestricted_Access.
11018 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
11019 and then Comes_From_Source
(N
)
11020 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
11021 and then Attr_Id
/= Attribute_Unrestricted_Access
11023 Accessibility_Message
;
11026 -- AI05-0225: If the context is not an access to protected
11027 -- function, the prefix must be a variable, given that it may
11028 -- be used subsequently in a protected call.
11030 elsif Nkind
(P
) = N_Selected_Component
11031 and then not Is_Variable
(Prefix
(P
))
11032 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
11035 ("target object of access to protected procedure "
11036 & "must be variable", N
);
11038 elsif Is_Entity_Name
(P
) then
11039 Check_Internal_Protected_Use
(N
, Entity
(P
));
11042 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
11043 E_Anonymous_Access_Subprogram_Type
)
11044 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
11046 Error_Msg_F
("context requires a non-protected subprogram", P
);
11049 -- The context cannot be a pool-specific type, but this is a
11050 -- legality rule, not a resolution rule, so it must be checked
11051 -- separately, after possibly disambiguation (see AI-245).
11053 if Ekind
(Btyp
) = E_Access_Type
11054 and then Attr_Id
/= Attribute_Unrestricted_Access
11056 Wrong_Type
(N
, Typ
);
11059 -- The context may be a constrained access type (however ill-
11060 -- advised such subtypes might be) so in order to generate a
11061 -- constraint check when needed set the type of the attribute
11062 -- reference to the base type of the context.
11064 Set_Etype
(N
, Btyp
);
11066 -- Check for incorrect atomic/volatile reference (RM C.6(12))
11068 if Attr_Id
/= Attribute_Unrestricted_Access
then
11069 if Is_Atomic_Object
(P
)
11070 and then not Is_Atomic
(Designated_Type
(Typ
))
11073 ("access to atomic object cannot yield access-to-" &
11074 "non-atomic type", P
);
11076 elsif Is_Volatile_Object
(P
)
11077 and then not Is_Volatile
(Designated_Type
(Typ
))
11080 ("access to volatile object cannot yield access-to-" &
11081 "non-volatile type", P
);
11085 -- Check for aliased view. We allow a nonaliased prefix when in
11086 -- an instance because the prefix may have been a tagged formal
11087 -- object, which is defined to be aliased even when the actual
11088 -- might not be (other instance cases will have been caught in
11089 -- the generic). Similarly, within an inlined body we know that
11090 -- the attribute is legal in the original subprogram, therefore
11091 -- legal in the expansion.
11093 if not (Is_Entity_Name
(P
)
11094 and then Is_Overloadable
(Entity
(P
)))
11095 and then not (Nkind
(P
) = N_Selected_Component
11097 Is_Overloadable
(Entity
(Selector_Name
(P
))))
11098 and then not Is_Aliased_View
(P
)
11099 and then not In_Instance
11100 and then not In_Inlined_Body
11101 and then Comes_From_Source
(N
)
11103 -- Here we have a non-aliased view. This is illegal unless we
11104 -- have the case of Unrestricted_Access, where for now we allow
11105 -- this (we will reject later if expected type is access to an
11106 -- unconstrained array with a thin pointer).
11108 -- No need for an error message on a generated access reference
11109 -- for the controlling argument in a dispatching call: error
11110 -- will be reported when resolving the call.
11112 if Attr_Id
/= Attribute_Unrestricted_Access
then
11113 Error_Msg_N
("prefix of % attribute must be aliased", P
);
11115 -- Check for unrestricted access where expected type is a thin
11116 -- pointer to an unconstrained array.
11118 elsif Has_Size_Clause
(Typ
)
11119 and then RM_Size
(Typ
) = System_Address_Size
11122 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
11124 if Is_Array_Type
(DT
)
11125 and then not Is_Constrained
(DT
)
11128 ("illegal use of Unrestricted_Access attribute", P
);
11130 ("\attempt to generate thin pointer to unaliased "
11137 -- Mark that address of entity is taken in case of
11138 -- 'Unrestricted_Access or in case of a subprogram.
11140 if Is_Entity_Name
(P
)
11141 and then (Attr_Id
= Attribute_Unrestricted_Access
11142 or else Is_Subprogram
(Entity
(P
)))
11144 Set_Address_Taken
(Entity
(P
));
11147 -- Deal with possible elaboration check
11149 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
11151 Subp_Id
: constant Entity_Id
:= Entity
(P
);
11152 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
11153 Subp_Decl
: constant Node_Id
:=
11154 Unit_Declaration_Node
(Subp_Id
);
11155 Flag_Id
: Entity_Id
;
11156 Subp_Body
: Node_Id
;
11158 -- If the access has been taken and the body of the subprogram
11159 -- has not been see yet, indirect calls must be protected with
11160 -- elaboration checks. We have the proper elaboration machinery
11161 -- for subprograms declared in packages, but within a block or
11162 -- a subprogram the body will appear in the same declarative
11163 -- part, and we must insert a check in the eventual body itself
11164 -- using the elaboration flag that we generate now. The check
11165 -- is then inserted when the body is expanded. This processing
11166 -- is not needed for a stand alone expression function because
11167 -- the internally generated spec and body are always inserted
11168 -- as a pair in the same declarative list.
11172 and then Comes_From_Source
(Subp_Id
)
11173 and then Comes_From_Source
(N
)
11174 and then In_Open_Scopes
(Scop
)
11175 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
11176 and then not Has_Completion
(Subp_Id
)
11177 and then No
(Elaboration_Entity
(Subp_Id
))
11178 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11179 and then Nkind
(Original_Node
(Subp_Decl
)) /=
11180 N_Expression_Function
11182 -- Create elaboration variable for it
11184 Flag_Id
:= Make_Temporary
(Loc
, 'E');
11185 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
11186 Set_Is_Frozen
(Flag_Id
);
11188 -- Insert declaration for flag after subprogram
11189 -- declaration. Note that attribute reference may
11190 -- appear within a nested scope.
11192 Insert_After_And_Analyze
(Subp_Decl
,
11193 Make_Object_Declaration
(Loc
,
11194 Defining_Identifier
=> Flag_Id
,
11195 Object_Definition
=>
11196 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
11198 Make_Integer_Literal
(Loc
, Uint_0
)));
11201 -- Taking the 'Access of an expression function freezes its
11202 -- expression (RM 13.14 10.3/3). This does not apply to an
11203 -- expression function that acts as a completion because the
11204 -- generated body is immediately analyzed and the expression
11205 -- is automatically frozen.
11207 if Is_Expression_Function
(Subp_Id
)
11208 and then Present
(Corresponding_Body
(Subp_Decl
))
11211 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
11213 -- The body has already been analyzed when the expression
11214 -- function acts as a completion.
11216 if Analyzed
(Subp_Body
) then
11219 -- Attribute 'Access may appear within the generated body
11220 -- of the expression function subject to the attribute:
11222 -- function F is (... F'Access ...);
11224 -- If the expression function is on the scope stack, then
11225 -- the body is currently being analyzed. Do not reanalyze
11226 -- it because this will lead to infinite recursion.
11228 elsif In_Open_Scopes
(Subp_Id
) then
11231 -- If reference to the expression function appears in an
11232 -- inner scope, for example as an actual in an instance,
11233 -- this is not a freeze point either.
11235 elsif Scope
(Subp_Id
) /= Current_Scope
then
11238 -- Analyze the body of the expression function to freeze
11239 -- the expression. This takes care of the case where the
11240 -- 'Access is part of dispatch table initialization and
11241 -- the generated body of the expression function has not
11242 -- been analyzed yet.
11245 Analyze
(Subp_Body
);
11255 -- Deal with resolving the type for Address attribute, overloading
11256 -- is not permitted here, since there is no context to resolve it.
11258 when Attribute_Address
11259 | Attribute_Code_Address
11261 -- To be safe, assume that if the address of a variable is taken,
11262 -- it may be modified via this address, so note modification.
11264 if Is_Variable
(P
) then
11265 Note_Possible_Modification
(P
, Sure
=> False);
11268 if Nkind
(P
) in N_Subexpr
11269 and then Is_Overloaded
(P
)
11271 Get_First_Interp
(P
, Index
, It
);
11272 Get_Next_Interp
(Index
, It
);
11274 if Present
(It
.Nam
) then
11275 Error_Msg_Name_1
:= Aname
;
11277 ("prefix of % attribute cannot be overloaded", P
);
11281 if not Is_Entity_Name
(P
)
11282 or else not Is_Overloadable
(Entity
(P
))
11284 if not Is_Task_Type
(Etype
(P
))
11285 or else Nkind
(P
) = N_Explicit_Dereference
11291 -- If this is the name of a derived subprogram, or that of a
11292 -- generic actual, the address is that of the original entity.
11294 if Is_Entity_Name
(P
)
11295 and then Is_Overloadable
(Entity
(P
))
11296 and then Present
(Alias
(Entity
(P
)))
11299 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11302 if Is_Entity_Name
(P
) then
11303 Set_Address_Taken
(Entity
(P
));
11306 if Nkind
(P
) = N_Slice
then
11308 -- Arr (X .. Y)'address is identical to Arr (X)'address,
11309 -- even if the array is packed and the slice itself is not
11310 -- addressable. Transform the prefix into an indexed component.
11312 -- Note that the transformation is safe only if we know that
11313 -- the slice is non-null. That is because a null slice can have
11314 -- an out of bounds index value.
11316 -- Right now, gigi blows up if given 'Address on a slice as a
11317 -- result of some incorrect freeze nodes generated by the front
11318 -- end, and this covers up that bug in one case, but the bug is
11319 -- likely still there in the cases not handled by this code ???
11321 -- It's not clear what 'Address *should* return for a null
11322 -- slice with out of bounds indexes, this might be worth an ARG
11325 -- One approach would be to do a length check unconditionally,
11326 -- and then do the transformation below unconditionally, but
11327 -- analyze with checks off, avoiding the problem of the out of
11328 -- bounds index. This approach would interpret the address of
11329 -- an out of bounds null slice as being the address where the
11330 -- array element would be if there was one, which is probably
11331 -- as reasonable an interpretation as any ???
11334 Loc
: constant Source_Ptr
:= Sloc
(P
);
11335 D
: constant Node_Id
:= Discrete_Range
(P
);
11339 if Is_Entity_Name
(D
)
11342 (Type_Low_Bound
(Entity
(D
)),
11343 Type_High_Bound
(Entity
(D
)))
11346 Make_Attribute_Reference
(Loc
,
11347 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
11348 Attribute_Name
=> Name_First
);
11350 elsif Nkind
(D
) = N_Range
11351 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
11353 Lo
:= Low_Bound
(D
);
11359 if Present
(Lo
) then
11361 Make_Indexed_Component
(Loc
,
11362 Prefix
=> Relocate_Node
(Prefix
(P
)),
11363 Expressions
=> New_List
(Lo
)));
11365 Analyze_And_Resolve
(P
);
11374 -- Prefix of Body_Version attribute can be a subprogram name which
11375 -- must not be resolved, since this is not a call.
11377 when Attribute_Body_Version
=>
11384 -- Prefix of Caller attribute is an entry name which must not
11385 -- be resolved, since this is definitely not an entry call.
11387 when Attribute_Caller
=>
11394 -- Shares processing with Address attribute
11400 -- If the prefix of the Count attribute is an entry name it must not
11401 -- be resolved, since this is definitely not an entry call. However,
11402 -- if it is an element of an entry family, the index itself may
11403 -- have to be resolved because it can be a general expression.
11405 when Attribute_Count
=>
11406 if Nkind
(P
) = N_Indexed_Component
11407 and then Is_Entity_Name
(Prefix
(P
))
11410 Indx
: constant Node_Id
:= First
(Expressions
(P
));
11411 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
11413 Resolve
(Indx
, Entry_Index_Type
(Fam
));
11414 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
11422 -- Prefix of the Elaborated attribute is a subprogram name which
11423 -- must not be resolved, since this is definitely not a call. Note
11424 -- that it is a library unit, so it cannot be overloaded here.
11426 when Attribute_Elaborated
=>
11433 -- Prefix of Enabled attribute is a check name, which must be treated
11434 -- specially and not touched by Resolve.
11436 when Attribute_Enabled
=>
11443 -- Do not resolve the prefix of Loop_Entry, instead wait until the
11444 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
11445 -- The delay ensures that any generated checks or temporaries are
11446 -- inserted before the relocated prefix.
11448 when Attribute_Loop_Entry
=>
11451 --------------------
11452 -- Mechanism_Code --
11453 --------------------
11455 -- Prefix of the Mechanism_Code attribute is a function name
11456 -- which must not be resolved. Should we check for overloaded ???
11458 when Attribute_Mechanism_Code
=>
11465 -- Most processing is done in sem_dist, after determining the
11466 -- context type. Node is rewritten as a conversion to a runtime call.
11468 when Attribute_Partition_ID
=>
11469 Process_Partition_Id
(N
);
11476 when Attribute_Pool_Address
=>
11483 -- We replace the Range attribute node with a range expression whose
11484 -- bounds are the 'First and 'Last attributes applied to the same
11485 -- prefix. The reason that we do this transformation here instead of
11486 -- in the expander is that it simplifies other parts of the semantic
11487 -- analysis which assume that the Range has been replaced; thus it
11488 -- must be done even when in semantic-only mode (note that the RM
11489 -- specifically mentions this equivalence, we take care that the
11490 -- prefix is only evaluated once).
11492 when Attribute_Range
=> Range_Attribute
: declare
11498 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11502 Dims
:= Expressions
(N
);
11505 Make_Attribute_Reference
(Loc
,
11506 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
11507 Attribute_Name
=> Name_Last
,
11508 Expressions
=> Dims
);
11511 Make_Attribute_Reference
(Loc
,
11513 Attribute_Name
=> Name_First
,
11514 Expressions
=> (Dims
));
11516 -- Do not share the dimension indicator, if present. Even though
11517 -- it is a static constant, its source location may be modified
11518 -- when printing expanded code and node sharing will lead to chaos
11521 if Present
(Dims
) then
11522 Set_Expressions
(LB
, New_List
(New_Copy_Tree
(First
(Dims
))));
11525 -- If the original was marked as Must_Not_Freeze (see code in
11526 -- Sem_Ch3.Make_Index), then make sure the rewriting does not
11529 if Must_Not_Freeze
(N
) then
11530 Set_Must_Not_Freeze
(HB
);
11531 Set_Must_Not_Freeze
(LB
);
11532 Set_Must_Not_Freeze
(Prefix
(HB
));
11533 Set_Must_Not_Freeze
(Prefix
(LB
));
11536 if Raises_Constraint_Error
(Prefix
(N
)) then
11538 -- Preserve Sloc of prefix in the new bounds, so that the
11539 -- posted warning can be removed if we are within unreachable
11542 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
11543 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
11546 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
11547 Analyze_And_Resolve
(N
, Typ
);
11549 -- Ensure that the expanded range does not have side effects
11551 Force_Evaluation
(LB
);
11552 Force_Evaluation
(HB
);
11554 -- Normally after resolving attribute nodes, Eval_Attribute
11555 -- is called to do any possible static evaluation of the node.
11556 -- However, here since the Range attribute has just been
11557 -- transformed into a range expression it is no longer an
11558 -- attribute node and therefore the call needs to be avoided
11559 -- and is accomplished by simply returning from the procedure.
11562 end Range_Attribute
;
11568 -- We will only come here during the prescan of a spec expression
11569 -- containing a Result attribute. In that case the proper Etype has
11570 -- already been set, and nothing more needs to be done here.
11572 when Attribute_Result
=>
11575 ----------------------
11576 -- Unchecked_Access --
11577 ----------------------
11579 -- Processing is shared with Access
11581 -------------------------
11582 -- Unrestricted_Access --
11583 -------------------------
11585 -- Processing is shared with Access
11591 -- Resolve aggregate components in component associations
11593 when Attribute_Update
=> Update
: declare
11594 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
11595 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
11601 -- Set the Etype of the aggregate to that of the prefix, even
11602 -- though the aggregate may not be a proper representation of a
11603 -- value of the type (missing or duplicated associations, etc.)
11604 -- Complete resolution of the prefix. Note that in Ada 2012 it
11605 -- can be a qualified expression that is e.g. an aggregate.
11607 Set_Etype
(Aggr
, Typ
);
11608 Resolve
(Prefix
(N
), Typ
);
11610 -- For an array type, resolve expressions with the component type
11611 -- of the array, and apply constraint checks when needed.
11613 if Is_Array_Type
(Typ
) then
11614 Assoc
:= First
(Component_Associations
(Aggr
));
11615 while Present
(Assoc
) loop
11616 Expr
:= Expression
(Assoc
);
11617 Resolve
(Expr
, Component_Type
(Typ
));
11619 -- For scalar array components set Do_Range_Check when
11620 -- needed. Constraint checking on non-scalar components
11621 -- is done in Aggregate_Constraint_Checks, but only if
11622 -- full analysis is enabled. These flags are not set in
11623 -- the front-end in GnatProve mode.
11625 if Is_Scalar_Type
(Component_Type
(Typ
))
11626 and then not Is_OK_Static_Expression
(Expr
)
11627 and then not Range_Checks_Suppressed
(Component_Type
(Typ
))
11629 if Is_Entity_Name
(Expr
)
11630 and then Etype
(Expr
) = Component_Type
(Typ
)
11635 Set_Do_Range_Check
(Expr
);
11639 -- The choices in the association are static constants,
11640 -- or static aggregates each of whose components belongs
11641 -- to the proper index type. However, they must also
11642 -- belong to the index subtype (s) of the prefix, which
11643 -- may be a subtype (e.g. given by a slice).
11645 -- Choices may also be identifiers with no staticness
11646 -- requirements, in which case they must resolve to the
11655 C
:= First
(Choices
(Assoc
));
11656 while Present
(C
) loop
11657 Indx
:= First_Index
(Etype
(Prefix
(N
)));
11659 if Nkind
(C
) /= N_Aggregate
then
11660 Analyze_And_Resolve
(C
, Etype
(Indx
));
11661 Apply_Constraint_Check
(C
, Etype
(Indx
));
11662 Check_Non_Static_Context
(C
);
11665 C_E
:= First
(Expressions
(C
));
11666 while Present
(C_E
) loop
11667 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
11668 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
11669 Check_Non_Static_Context
(C_E
);
11683 -- For a record type, use type of each component, which is
11684 -- recorded during analysis.
11687 Assoc
:= First
(Component_Associations
(Aggr
));
11688 while Present
(Assoc
) loop
11689 Comp
:= First
(Choices
(Assoc
));
11690 Expr
:= Expression
(Assoc
);
11692 if Nkind
(Comp
) /= N_Others_Choice
11693 and then not Error_Posted
(Comp
)
11695 Resolve
(Expr
, Etype
(Entity
(Comp
)));
11697 if Is_Scalar_Type
(Etype
(Entity
(Comp
)))
11698 and then not Is_OK_Static_Expression
(Expr
)
11699 and then not Range_Checks_Suppressed
11700 (Etype
(Entity
(Comp
)))
11702 Set_Do_Range_Check
(Expr
);
11715 -- Apply range check. Note that we did not do this during the
11716 -- analysis phase, since we wanted Eval_Attribute to have a
11717 -- chance at finding an illegal out of range value.
11719 when Attribute_Val
=>
11721 -- Note that we do our own Eval_Attribute call here rather than
11722 -- use the common one, because we need to do processing after
11723 -- the call, as per above comment.
11725 Eval_Attribute
(N
);
11727 -- Eval_Attribute may replace the node with a raise CE, or
11728 -- fold it to a constant. Obviously we only apply a scalar
11729 -- range check if this did not happen.
11731 if Nkind
(N
) = N_Attribute_Reference
11732 and then Attribute_Name
(N
) = Name_Val
11734 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11743 -- Prefix of Version attribute can be a subprogram name which
11744 -- must not be resolved, since this is not a call.
11746 when Attribute_Version
=>
11749 ----------------------
11750 -- Other Attributes --
11751 ----------------------
11753 -- For other attributes, resolve prefix unless it is a type. If
11754 -- the attribute reference itself is a type name ('Base and 'Class)
11755 -- then this is only legal within a task or protected record.
11758 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11762 -- If the attribute reference itself is a type name ('Base,
11763 -- 'Class) then this is only legal within a task or protected
11764 -- record. What is this all about ???
11766 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11767 if Is_Concurrent_Type
(Entity
(N
))
11768 and then In_Open_Scopes
(Entity
(P
))
11773 ("invalid use of subtype name in expression or call", N
);
11777 -- For attributes whose argument may be a string, complete
11778 -- resolution of argument now. This avoids premature expansion
11779 -- (and the creation of transient scopes) before the attribute
11780 -- reference is resolved.
11783 when Attribute_Value
=>
11784 Resolve
(First
(Expressions
(N
)), Standard_String
);
11786 when Attribute_Wide_Value
=>
11787 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11789 when Attribute_Wide_Wide_Value
=>
11790 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11792 when others => null;
11795 -- If the prefix of the attribute is a class-wide type then it
11796 -- will be expanded into a dispatching call to a predefined
11797 -- primitive. Therefore we must check for potential violation
11798 -- of such restriction.
11800 if Is_Class_Wide_Type
(Etype
(P
)) then
11801 Check_Restriction
(No_Dispatching_Calls
, N
);
11805 -- Mark use clauses of the original prefix if the attribute is applied
11808 if Nkind
(Original_Node
(P
)) in N_Has_Entity
11809 and then Present
(Entity
(Original_Node
(P
)))
11811 Mark_Use_Clauses
(Original_Node
(P
));
11814 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11815 -- is not resolved, in which case the freezing must be done now.
11817 -- For an elaboration check on a subprogram, we do not freeze its type.
11818 -- It may be declared in an unrelated scope, in particular in the case
11819 -- of a generic function whose type may remain unelaborated.
11821 if Attr_Id
= Attribute_Elaborated
then
11825 Freeze_Expression
(P
);
11828 -- Finally perform static evaluation on the attribute reference
11830 Analyze_Dimension
(N
);
11831 Eval_Attribute
(N
);
11832 end Resolve_Attribute
;
11834 ------------------------
11835 -- Set_Boolean_Result --
11836 ------------------------
11838 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11839 Loc
: constant Source_Ptr
:= Sloc
(N
);
11842 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11844 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11846 end Set_Boolean_Result
;
11848 -------------------------------
11849 -- Statically_Denotes_Object --
11850 -------------------------------
11852 function Statically_Denotes_Object
(N
: Node_Id
) return Boolean is
11856 if Is_Entity_Name
(N
) then
11859 elsif Nkind
(N
) = N_Selected_Component
11860 and then Statically_Denotes_Object
(Prefix
(N
))
11861 and then Present
(Entity
(Selector_Name
(N
)))
11864 Sel_Id
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
11865 Comp_Decl
: constant Node_Id
:= Parent
(Sel_Id
);
11868 if Depends_On_Discriminant
(Sel_Id
) then
11871 elsif Nkind
(Parent
(Parent
(Comp_Decl
))) = N_Variant
then
11879 elsif Nkind
(N
) = N_Indexed_Component
11880 and then Statically_Denotes_Object
(Prefix
(N
))
11881 and then Is_Constrained
(Etype
(Prefix
(N
)))
11883 Indx
:= First
(Expressions
(N
));
11884 while Present
(Indx
) loop
11885 if not Compile_Time_Known_Value
(Indx
)
11886 or else Do_Range_Check
(Indx
)
11899 end Statically_Denotes_Object
;
11901 --------------------------------
11902 -- Stream_Attribute_Available --
11903 --------------------------------
11905 function Stream_Attribute_Available
11907 Nam
: TSS_Name_Type
;
11908 Partial_View
: Node_Id
:= Empty
) return Boolean
11910 Etyp
: Entity_Id
:= Typ
;
11912 -- Start of processing for Stream_Attribute_Available
11915 -- We need some comments in this body ???
11917 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11921 if Is_Class_Wide_Type
(Typ
) then
11922 return not Is_Limited_Type
(Typ
)
11923 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11926 if Nam
= TSS_Stream_Input
11927 and then Is_Abstract_Type
(Typ
)
11928 and then not Is_Class_Wide_Type
(Typ
)
11933 if not (Is_Limited_Type
(Typ
)
11934 or else (Present
(Partial_View
)
11935 and then Is_Limited_Type
(Partial_View
)))
11940 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11942 if Nam
= TSS_Stream_Input
11943 and then Ada_Version
>= Ada_2005
11944 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11948 elsif Nam
= TSS_Stream_Output
11949 and then Ada_Version
>= Ada_2005
11950 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11955 -- Case of Read and Write: check for attribute definition clause that
11956 -- applies to an ancestor type.
11958 while Etype
(Etyp
) /= Etyp
loop
11959 Etyp
:= Etype
(Etyp
);
11961 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11966 if Ada_Version
< Ada_2005
then
11968 -- In Ada 95 mode, also consider a non-visible definition
11971 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11974 and then Stream_Attribute_Available
11975 (Btyp
, Nam
, Partial_View
=> Typ
);
11980 end Stream_Attribute_Available
;