1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Debug
; use Debug
;
32 with Einfo
; use Einfo
;
33 with Elists
; use Elists
;
34 with Errout
; use Errout
;
36 with Exp_Dist
; use Exp_Dist
;
37 with Exp_Util
; use Exp_Util
;
38 with Expander
; use Expander
;
39 with Freeze
; use Freeze
;
40 with Gnatvsn
; use Gnatvsn
;
41 with Itypes
; use Itypes
;
43 with Lib
.Xref
; use Lib
.Xref
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
50 with Sdefault
; use Sdefault
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Cat
; use Sem_Cat
;
54 with Sem_Ch6
; use Sem_Ch6
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch10
; use Sem_Ch10
;
57 with Sem_Dim
; use Sem_Dim
;
58 with Sem_Dist
; use Sem_Dist
;
59 with Sem_Elab
; use Sem_Elab
;
60 with Sem_Elim
; use Sem_Elim
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Res
; use Sem_Res
;
63 with Sem_Type
; use Sem_Type
;
64 with Sem_Util
; use Sem_Util
;
65 with Stand
; use Stand
;
66 with Sinfo
; use Sinfo
;
67 with Sinput
; use Sinput
;
69 with Stringt
; use Stringt
;
71 with Stylesw
; use Stylesw
;
72 with Targparm
; use Targparm
;
73 with Ttypes
; use Ttypes
;
74 with Tbuild
; use Tbuild
;
75 with Uintp
; use Uintp
;
76 with Uname
; use Uname
;
77 with Urealp
; use Urealp
;
79 package body Sem_Attr
is
81 True_Value
: constant Uint
:= Uint_1
;
82 False_Value
: constant Uint
:= Uint_0
;
83 -- Synonyms to be used when these constants are used as Boolean values
85 Bad_Attribute
: exception;
86 -- Exception raised if an error is detected during attribute processing,
87 -- used so that we can abandon the processing so we don't run into
88 -- trouble with cascaded errors.
90 -- The following array is the list of attributes defined in the Ada 83 RM.
91 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
92 -- modes all these attributes are recognized, even if removed in Ada 95.
94 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
100 Attribute_Constrained |
107 Attribute_First_Bit |
113 Attribute_Leading_Part |
115 Attribute_Machine_Emax |
116 Attribute_Machine_Emin |
117 Attribute_Machine_Mantissa |
118 Attribute_Machine_Overflows |
119 Attribute_Machine_Radix |
120 Attribute_Machine_Rounds |
126 Attribute_Safe_Emax |
127 Attribute_Safe_Large |
128 Attribute_Safe_Small |
131 Attribute_Storage_Size |
133 Attribute_Terminated |
136 Attribute_Width => True,
139 -- The following array is the list of attributes defined in the Ada 2005
140 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
141 -- but in Ada 95 they are considered to be implementation defined.
143 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
144 Attribute_Machine_Rounding |
147 Attribute_Stream_Size |
148 Attribute_Wide_Wide_Width
=> True,
151 -- The following array is the list of attributes defined in the Ada 2012
152 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
153 -- and Ada 2005 modes, but are considered to be implementation defined.
155 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
156 Attribute_First_Valid |
157 Attribute_Has_Same_Storage |
158 Attribute_Last_Valid |
159 Attribute_Max_Alignment_For_Allocation => True,
162 -- The following array contains all attributes that imply a modification
163 -- of their prefixes or result in an access value. Such prefixes can be
164 -- considered as lvalues.
166 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
167 Attribute_Class_Array'(
172 Attribute_Unchecked_Access |
173 Attribute_Unrestricted_Access
=> True,
176 -----------------------
177 -- Local_Subprograms --
178 -----------------------
180 procedure Eval_Attribute
(N
: Node_Id
);
181 -- Performs compile time evaluation of attributes where possible, leaving
182 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
183 -- set, and replacing the node with a literal node if the value can be
184 -- computed at compile time. All static attribute references are folded,
185 -- as well as a number of cases of non-static attributes that can always
186 -- be computed at compile time (e.g. floating-point model attributes that
187 -- are applied to non-static subtypes). Of course in such cases, the
188 -- Is_Static_Expression flag will not be set on the resulting literal.
189 -- Note that the only required action of this procedure is to catch the
190 -- static expression cases as described in the RM. Folding of other cases
191 -- is done where convenient, but some additional non-static folding is in
192 -- Expand_N_Attribute_Reference in cases where this is more convenient.
194 function Is_Anonymous_Tagged_Base
196 Typ
: Entity_Id
) return Boolean;
197 -- For derived tagged types that constrain parent discriminants we build
198 -- an anonymous unconstrained base type. We need to recognize the relation
199 -- between the two when analyzing an access attribute for a constrained
200 -- component, before the full declaration for Typ has been analyzed, and
201 -- where therefore the prefix of the attribute does not match the enclosing
204 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean);
205 -- Rewrites node N with an occurrence of either Standard_False or
206 -- Standard_True, depending on the value of the parameter B. The
207 -- result is marked as a static expression.
209 -----------------------
210 -- Analyze_Attribute --
211 -----------------------
213 procedure Analyze_Attribute
(N
: Node_Id
) is
214 Loc
: constant Source_Ptr
:= Sloc
(N
);
215 Aname
: constant Name_Id
:= Attribute_Name
(N
);
216 P
: constant Node_Id
:= Prefix
(N
);
217 Exprs
: constant List_Id
:= Expressions
(N
);
218 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
223 -- Type of prefix after analysis
225 P_Base_Type
: Entity_Id
;
226 -- Base type of prefix after analysis
228 -----------------------
229 -- Local Subprograms --
230 -----------------------
232 procedure Address_Checks
;
233 -- Semantic checks for valid use of Address attribute. This was made
234 -- a separate routine with the idea of using it for unrestricted access
235 -- which seems like it should follow the same rules, but that turned
236 -- out to be impractical. So now this is only used for Address.
238 procedure Analyze_Access_Attribute
;
239 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
240 -- Internally, Id distinguishes which of the three cases is involved.
242 procedure Bad_Attribute_For_Predicate
;
243 -- Output error message for use of a predicate (First, Last, Range) not
244 -- allowed with a type that has predicates. If the type is a generic
245 -- actual, then the message is a warning, and we generate code to raise
246 -- program error with an appropriate reason. No error message is given
247 -- for internally generated uses of the attributes. This legality rule
248 -- only applies to scalar types.
250 procedure Check_Array_Or_Scalar_Type
;
251 -- Common procedure used by First, Last, Range attribute to check
252 -- that the prefix is a constrained array or scalar type, or a name
253 -- of an array object, and that an argument appears only if appropriate
254 -- (i.e. only in the array case).
256 procedure Check_Array_Type
;
257 -- Common semantic checks for all array attributes. Checks that the
258 -- prefix is a constrained array type or the name of an array object.
259 -- The error message for non-arrays is specialized appropriately.
261 procedure Check_Asm_Attribute
;
262 -- Common semantic checks for Asm_Input and Asm_Output attributes
264 procedure Check_Component
;
265 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
266 -- Position. Checks prefix is an appropriate selected component.
268 procedure Check_Decimal_Fixed_Point_Type
;
269 -- Check that prefix of attribute N is a decimal fixed-point type
271 procedure Check_Dereference
;
272 -- If the prefix of attribute is an object of an access type, then
273 -- introduce an explicit dereference, and adjust P_Type accordingly.
275 procedure Check_Discrete_Type
;
276 -- Verify that prefix of attribute N is a discrete type
279 -- Check that no attribute arguments are present
281 procedure Check_Either_E0_Or_E1
;
282 -- Check that there are zero or one attribute arguments present
285 -- Check that exactly one attribute argument is present
288 -- Check that two attribute arguments are present
290 procedure Check_Enum_Image
;
291 -- If the prefix type is an enumeration type, set all its literals
292 -- as referenced, since the image function could possibly end up
293 -- referencing any of the literals indirectly. Same for Enum_Val.
294 -- Set the flag only if the reference is in the main code unit. Same
295 -- restriction when resolving 'Value; otherwise an improperly set
296 -- reference when analyzing an inlined body will lose a proper warning
297 -- on a useless with_clause.
299 procedure Check_First_Last_Valid
;
300 -- Perform all checks for First_Valid and Last_Valid attributes
302 procedure Check_Fixed_Point_Type
;
303 -- Verify that prefix of attribute N is a fixed type
305 procedure Check_Fixed_Point_Type_0
;
306 -- Verify that prefix of attribute N is a fixed type and that
307 -- no attribute expressions are present
309 procedure Check_Floating_Point_Type
;
310 -- Verify that prefix of attribute N is a float type
312 procedure Check_Floating_Point_Type_0
;
313 -- Verify that prefix of attribute N is a float type and that
314 -- no attribute expressions are present
316 procedure Check_Floating_Point_Type_1
;
317 -- Verify that prefix of attribute N is a float type and that
318 -- exactly one attribute expression is present
320 procedure Check_Floating_Point_Type_2
;
321 -- Verify that prefix of attribute N is a float type and that
322 -- two attribute expressions are present
324 procedure Check_SPARK_05_Restriction_On_Attribute
;
325 -- Issue an error in formal mode because attribute N is allowed
327 procedure Check_Integer_Type
;
328 -- Verify that prefix of attribute N is an integer type
330 procedure Check_Modular_Integer_Type
;
331 -- Verify that prefix of attribute N is a modular integer type
333 procedure Check_Not_CPP_Type
;
334 -- Check that P (the prefix of the attribute) is not an CPP type
335 -- for which no Ada predefined primitive is available.
337 procedure Check_Not_Incomplete_Type
;
338 -- Check that P (the prefix of the attribute) is not an incomplete
339 -- type or a private type for which no full view has been given.
341 procedure Check_Object_Reference
(P
: Node_Id
);
342 -- Check that P is an object reference
344 procedure Check_Program_Unit
;
345 -- Verify that prefix of attribute N is a program unit
347 procedure Check_Real_Type
;
348 -- Verify that prefix of attribute N is fixed or float type
350 procedure Check_Scalar_Type
;
351 -- Verify that prefix of attribute N is a scalar type
353 procedure Check_Standard_Prefix
;
354 -- Verify that prefix of attribute N is package Standard. Also checks
355 -- that there are no arguments.
357 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
358 -- Validity checking for stream attribute. Nam is the TSS name of the
359 -- corresponding possible defined attribute function (e.g. for the
360 -- Read attribute, Nam will be TSS_Stream_Read).
362 procedure Check_System_Prefix
;
363 -- Verify that prefix of attribute N is package System
365 procedure Check_PolyORB_Attribute
;
366 -- Validity checking for PolyORB/DSA attribute
368 procedure Check_Task_Prefix
;
369 -- Verify that prefix of attribute N is a task or task type
371 procedure Check_Type
;
372 -- Verify that the prefix of attribute N is a type
374 procedure Check_Unit_Name
(Nod
: Node_Id
);
375 -- Check that Nod is of the form of a library unit name, i.e that
376 -- it is an identifier, or a selected component whose prefix is
377 -- itself of the form of a library unit name. Note that this is
378 -- quite different from Check_Program_Unit, since it only checks
379 -- the syntactic form of the name, not the semantic identity. This
380 -- is because it is used with attributes (Elab_Body, Elab_Spec,
381 -- UET_Address and Elaborated) which can refer to non-visible unit.
383 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
384 pragma No_Return
(Error_Attr
);
385 procedure Error_Attr
;
386 pragma No_Return
(Error_Attr
);
387 -- Posts error using Error_Msg_N at given node, sets type of attribute
388 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
389 -- semantic processing. The message typically contains a % insertion
390 -- character which is replaced by the attribute name. The call with
391 -- no arguments is used when the caller has already generated the
392 -- required error messages.
394 procedure Error_Attr_P
(Msg
: String);
395 pragma No_Return
(Error_Attr
);
396 -- Like Error_Attr, but error is posted at the start of the prefix
398 function In_Refined_Post
return Boolean;
399 -- Determine whether the current attribute appears in pragma
402 procedure Legal_Formal_Attribute
;
403 -- Common processing for attributes Definite and Has_Discriminants.
404 -- Checks that prefix is generic indefinite formal type.
406 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
407 -- Common processing for attributes Max_Alignment_For_Allocation and
408 -- Max_Size_In_Storage_Elements.
411 -- Common processing for attributes Max and Min
413 procedure Standard_Attribute
(Val
: Int
);
414 -- Used to process attributes whose prefix is package Standard which
415 -- yield values of type Universal_Integer. The attribute reference
416 -- node is rewritten with an integer literal of the given value which
417 -- is marked as static.
419 procedure Uneval_Old_Msg
;
420 -- Called when Loop_Entry or Old is used in a potentially unevaluated
421 -- expression. Generates appropriate message or warning depending on
422 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
423 -- node in the aspect case).
425 procedure Unexpected_Argument
(En
: Node_Id
);
426 -- Signal unexpected attribute argument (En is the argument)
428 procedure Validate_Non_Static_Attribute_Function_Call
;
429 -- Called when processing an attribute that is a function call to a
430 -- non-static function, i.e. an attribute function that either takes
431 -- non-scalar arguments or returns a non-scalar result. Verifies that
432 -- such a call does not appear in a preelaborable context.
438 procedure Address_Checks
is
440 -- An Address attribute created by expansion is legal even when it
441 -- applies to other entity-denoting expressions.
443 if not Comes_From_Source
(N
) then
446 -- Address attribute on a protected object self reference is legal
448 elsif Is_Protected_Self_Reference
(P
) then
451 -- Address applied to an entity
453 elsif Is_Entity_Name
(P
) then
455 Ent
: constant Entity_Id
:= Entity
(P
);
458 if Is_Subprogram
(Ent
) then
459 Set_Address_Taken
(Ent
);
460 Kill_Current_Values
(Ent
);
462 -- An Address attribute is accepted when generated by the
463 -- compiler for dispatching operation, and an error is
464 -- issued once the subprogram is frozen (to avoid confusing
465 -- errors about implicit uses of Address in the dispatch
466 -- table initialization).
468 if Has_Pragma_Inline_Always
(Entity
(P
))
469 and then Comes_From_Source
(P
)
472 ("prefix of % attribute cannot be Inline_Always "
475 -- It is illegal to apply 'Address to an intrinsic
476 -- subprogram. This is now formalized in AI05-0095.
477 -- In an instance, an attempt to obtain 'Address of an
478 -- intrinsic subprogram (e.g the renaming of a predefined
479 -- operator that is an actual) raises Program_Error.
481 elsif Convention
(Ent
) = Convention_Intrinsic
then
484 Make_Raise_Program_Error
(Loc
,
485 Reason
=> PE_Address_Of_Intrinsic
));
488 Error_Msg_Name_1
:= Aname
;
490 ("cannot take % of intrinsic subprogram", N
);
493 -- Issue an error if prefix denotes an eliminated subprogram
496 Check_For_Eliminated_Subprogram
(P
, Ent
);
499 -- Object or label reference
501 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
502 Set_Address_Taken
(Ent
);
504 -- Deal with No_Implicit_Aliasing restriction
506 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
507 if not Is_Aliased_View
(P
) then
508 Check_Restriction
(No_Implicit_Aliasing
, P
);
510 Check_No_Implicit_Aliasing
(P
);
514 -- If we have an address of an object, and the attribute
515 -- comes from source, then set the object as potentially
516 -- source modified. We do this because the resulting address
517 -- can potentially be used to modify the variable and we
518 -- might not detect this, leading to some junk warnings.
520 Set_Never_Set_In_Source
(Ent
, False);
522 -- Allow Address to be applied to task or protected type,
523 -- returning null address (what is that about???)
525 elsif (Is_Concurrent_Type
(Etype
(Ent
))
526 and then Etype
(Ent
) = Base_Type
(Ent
))
527 or else Ekind
(Ent
) = E_Package
528 or else Is_Generic_Unit
(Ent
)
531 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
533 -- Anything else is illegal
536 Error_Attr
("invalid prefix for % attribute", P
);
542 elsif Is_Object_Reference
(P
) then
545 -- Subprogram called using dot notation
547 elsif Nkind
(P
) = N_Selected_Component
548 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
552 -- What exactly are we allowing here ??? and is this properly
553 -- documented in the sinfo documentation for this node ???
555 elsif Relaxed_RM_Semantics
556 and then Nkind
(P
) = N_Attribute_Reference
560 -- All other non-entity name cases are illegal
563 Error_Attr
("invalid prefix for % attribute", P
);
567 ------------------------------
568 -- Analyze_Access_Attribute --
569 ------------------------------
571 procedure Analyze_Access_Attribute
is
572 Acc_Type
: Entity_Id
;
577 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
578 -- Build an access-to-object type whose designated type is DT,
579 -- and whose Ekind is appropriate to the attribute type. The
580 -- type that is constructed is returned as the result.
582 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
583 -- Build an access to subprogram whose designated type is the type of
584 -- the prefix. If prefix is overloaded, so is the node itself. The
585 -- result is stored in Acc_Type.
587 function OK_Self_Reference
return Boolean;
588 -- An access reference whose prefix is a type can legally appear
589 -- within an aggregate, where it is obtained by expansion of
590 -- a defaulted aggregate. The enclosing aggregate that contains
591 -- the self-referenced is flagged so that the self-reference can
592 -- be expanded into a reference to the target object (see exp_aggr).
594 ------------------------------
595 -- Build_Access_Object_Type --
596 ------------------------------
598 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
599 Typ
: constant Entity_Id
:=
601 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
603 Set_Etype
(Typ
, Typ
);
605 Set_Associated_Node_For_Itype
(Typ
, N
);
606 Set_Directly_Designated_Type
(Typ
, DT
);
608 end Build_Access_Object_Type
;
610 ----------------------------------
611 -- Build_Access_Subprogram_Type --
612 ----------------------------------
614 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
615 Index
: Interp_Index
;
618 procedure Check_Local_Access
(E
: Entity_Id
);
619 -- Deal with possible access to local subprogram. If we have such
620 -- an access, we set a flag to kill all tracked values on any call
621 -- because this access value may be passed around, and any called
622 -- code might use it to access a local procedure which clobbers a
623 -- tracked value. If the scope is a loop or block, indicate that
624 -- value tracking is disabled for the enclosing subprogram.
626 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
627 -- Distinguish between access to regular/protected subprograms
629 ------------------------
630 -- Check_Local_Access --
631 ------------------------
633 procedure Check_Local_Access
(E
: Entity_Id
) is
635 if not Is_Library_Level_Entity
(E
) then
636 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
637 Set_Suppress_Value_Tracking_On_Call
638 (Nearest_Dynamic_Scope
(Current_Scope
));
640 end Check_Local_Access
;
646 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
648 if Convention
(E
) = Convention_Protected
then
649 return E_Access_Protected_Subprogram_Type
;
651 return E_Access_Subprogram_Type
;
655 -- Start of processing for Build_Access_Subprogram_Type
658 -- In the case of an access to subprogram, use the name of the
659 -- subprogram itself as the designated type. Type-checking in
660 -- this case compares the signatures of the designated types.
662 -- Note: This fragment of the tree is temporarily malformed
663 -- because the correct tree requires an E_Subprogram_Type entity
664 -- as the designated type. In most cases this designated type is
665 -- later overridden by the semantics with the type imposed by the
666 -- context during the resolution phase. In the specific case of
667 -- the expression Address!(Prim'Unrestricted_Access), used to
668 -- initialize slots of dispatch tables, this work will be done by
669 -- the expander (see Exp_Aggr).
671 -- The reason to temporarily add this kind of node to the tree
672 -- instead of a proper E_Subprogram_Type itype, is the following:
673 -- in case of errors found in the source file we report better
674 -- error messages. For example, instead of generating the
677 -- "expected access to subprogram with profile
678 -- defined at line X"
680 -- we currently generate:
682 -- "expected access to function Z defined at line X"
684 Set_Etype
(N
, Any_Type
);
686 if not Is_Overloaded
(P
) then
687 Check_Local_Access
(Entity
(P
));
689 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
690 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
691 Set_Is_Public
(Acc_Type
, False);
692 Set_Etype
(Acc_Type
, Acc_Type
);
693 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
694 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
695 Set_Etype
(N
, Acc_Type
);
696 Freeze_Before
(N
, Acc_Type
);
700 Get_First_Interp
(P
, Index
, It
);
701 while Present
(It
.Nam
) loop
702 Check_Local_Access
(It
.Nam
);
704 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
705 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
706 Set_Is_Public
(Acc_Type
, False);
707 Set_Etype
(Acc_Type
, Acc_Type
);
708 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
709 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
710 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
711 Freeze_Before
(N
, Acc_Type
);
714 Get_Next_Interp
(Index
, It
);
718 -- Cannot be applied to intrinsic. Looking at the tests above,
719 -- the only way Etype (N) can still be set to Any_Type is if
720 -- Is_Intrinsic_Subprogram was True for some referenced entity.
722 if Etype
(N
) = Any_Type
then
723 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
725 end Build_Access_Subprogram_Type
;
727 ----------------------
728 -- OK_Self_Reference --
729 ----------------------
731 function OK_Self_Reference
return Boolean is
738 (Nkind
(Par
) = N_Component_Association
739 or else Nkind
(Par
) in N_Subexpr
)
741 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
742 if Etype
(Par
) = Typ
then
743 Set_Has_Self_Reference
(Par
);
751 -- No enclosing aggregate, or not a self-reference
754 end OK_Self_Reference
;
756 -- Start of processing for Analyze_Access_Attribute
759 Check_SPARK_05_Restriction_On_Attribute
;
762 if Nkind
(P
) = N_Character_Literal
then
764 ("prefix of % attribute cannot be enumeration literal");
767 -- Case of access to subprogram
769 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
770 if Has_Pragma_Inline_Always
(Entity
(P
)) then
772 ("prefix of % attribute cannot be Inline_Always subprogram");
774 elsif Aname
= Name_Unchecked_Access
then
775 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
778 -- Issue an error if the prefix denotes an eliminated subprogram
780 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
782 -- Check for obsolescent subprogram reference
784 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
786 -- Build the appropriate subprogram type
788 Build_Access_Subprogram_Type
(P
);
790 -- For P'Access or P'Unrestricted_Access, where P is a nested
791 -- subprogram, we might be passing P to another subprogram (but we
792 -- don't check that here), which might call P. P could modify
793 -- local variables, so we need to kill current values. It is
794 -- important not to do this for library-level subprograms, because
795 -- Kill_Current_Values is very inefficient in the case of library
796 -- level packages with lots of tagged types.
798 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
801 -- Do not kill values on nodes initializing dispatch tables
802 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
803 -- is currently generated by the expander only for this
804 -- purpose. Done to keep the quality of warnings currently
805 -- generated by the compiler (otherwise any declaration of
806 -- a tagged type cleans constant indications from its scope).
808 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
809 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
811 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
812 and then Is_Dispatching_Operation
813 (Directly_Designated_Type
(Etype
(N
)))
821 -- In the static elaboration model, treat the attribute reference
822 -- as a call for elaboration purposes. Suppress this treatment
823 -- under debug flag. In any case, we are all done.
825 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
831 -- Component is an operation of a protected type
833 elsif Nkind
(P
) = N_Selected_Component
834 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
836 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
837 Error_Attr_P
("prefix of % attribute must be subprogram");
840 Build_Access_Subprogram_Type
(Selector_Name
(P
));
844 -- Deal with incorrect reference to a type, but note that some
845 -- accesses are allowed: references to the current type instance,
846 -- or in Ada 2005 self-referential pointer in a default-initialized
849 if Is_Entity_Name
(P
) then
852 -- The reference may appear in an aggregate that has been expanded
853 -- into a loop. Locate scope of type definition, if any.
855 Scop
:= Current_Scope
;
856 while Ekind
(Scop
) = E_Loop
loop
857 Scop
:= Scope
(Scop
);
860 if Is_Type
(Typ
) then
862 -- OK if we are within the scope of a limited type
863 -- let's mark the component as having per object constraint
865 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
873 Q
: Node_Id
:= Parent
(N
);
877 and then Nkind
(Q
) /= N_Component_Declaration
883 Set_Has_Per_Object_Constraint
884 (Defining_Identifier
(Q
), True);
888 if Nkind
(P
) = N_Expanded_Name
then
890 ("current instance prefix must be a direct name", P
);
893 -- If a current instance attribute appears in a component
894 -- constraint it must appear alone; other contexts (spec-
895 -- expressions, within a task body) are not subject to this
898 if not In_Spec_Expression
899 and then not Has_Completion
(Scop
)
901 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
902 N_Index_Or_Discriminant_Constraint
)
905 ("current instance attribute must appear alone", N
);
908 if Is_CPP_Class
(Root_Type
(Typ
)) then
910 ("??current instance unsupported for derivations of "
911 & "'C'P'P types", N
);
914 -- OK if we are in initialization procedure for the type
915 -- in question, in which case the reference to the type
916 -- is rewritten as a reference to the current object.
918 elsif Ekind
(Scop
) = E_Procedure
919 and then Is_Init_Proc
(Scop
)
920 and then Etype
(First_Formal
(Scop
)) = Typ
923 Make_Attribute_Reference
(Loc
,
924 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
925 Attribute_Name
=> Name_Unrestricted_Access
));
929 -- OK if a task type, this test needs sharpening up ???
931 elsif Is_Task_Type
(Typ
) then
934 -- OK if self-reference in an aggregate in Ada 2005, and
935 -- the reference comes from a copied default expression.
937 -- Note that we check legality of self-reference even if the
938 -- expression comes from source, e.g. when a single component
939 -- association in an aggregate has a box association.
941 elsif Ada_Version
>= Ada_2005
942 and then OK_Self_Reference
946 -- OK if reference to current instance of a protected object
948 elsif Is_Protected_Self_Reference
(P
) then
951 -- Otherwise we have an error case
954 Error_Attr
("% attribute cannot be applied to type", P
);
960 -- If we fall through, we have a normal access to object case
962 -- Unrestricted_Access is (for now) legal wherever an allocator would
963 -- be legal, so its Etype is set to E_Allocator. The expected type
964 -- of the other attributes is a general access type, and therefore
965 -- we label them with E_Access_Attribute_Type.
967 if not Is_Overloaded
(P
) then
968 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
969 Set_Etype
(N
, Acc_Type
);
973 Index
: Interp_Index
;
976 Set_Etype
(N
, Any_Type
);
977 Get_First_Interp
(P
, Index
, It
);
978 while Present
(It
.Typ
) loop
979 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
980 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
981 Get_Next_Interp
(Index
, It
);
986 -- Special cases when we can find a prefix that is an entity name
995 if Is_Entity_Name
(PP
) then
998 -- If we have an access to an object, and the attribute
999 -- comes from source, then set the object as potentially
1000 -- source modified. We do this because the resulting access
1001 -- pointer can be used to modify the variable, and we might
1002 -- not detect this, leading to some junk warnings.
1004 -- We only do this for source references, since otherwise
1005 -- we can suppress warnings, e.g. from the unrestricted
1006 -- access generated for validity checks in -gnatVa mode.
1008 if Comes_From_Source
(N
) then
1009 Set_Never_Set_In_Source
(Ent
, False);
1012 -- Mark entity as address taken, and kill current values
1014 Set_Address_Taken
(Ent
);
1015 Kill_Current_Values
(Ent
);
1018 elsif Nkind_In
(PP
, N_Selected_Component
,
1019 N_Indexed_Component
)
1029 -- Check for aliased view.. We allow a nonaliased prefix when within
1030 -- an instance because the prefix may have been a tagged formal
1031 -- object, which is defined to be aliased even when the actual
1032 -- might not be (other instance cases will have been caught in the
1033 -- generic). Similarly, within an inlined body we know that the
1034 -- attribute is legal in the original subprogram, and therefore
1035 -- legal in the expansion.
1037 if not Is_Aliased_View
(P
)
1038 and then not In_Instance
1039 and then not In_Inlined_Body
1040 and then Comes_From_Source
(N
)
1042 -- Here we have a non-aliased view. This is illegal unless we
1043 -- have the case of Unrestricted_Access, where for now we allow
1044 -- this (we will reject later if expected type is access to an
1045 -- unconstrained array with a thin pointer).
1047 -- No need for an error message on a generated access reference
1048 -- for the controlling argument in a dispatching call: error will
1049 -- be reported when resolving the call.
1051 if Aname
/= Name_Unrestricted_Access
then
1052 Error_Attr_P
("prefix of % attribute must be aliased");
1053 Check_No_Implicit_Aliasing
(P
);
1055 -- For Unrestricted_Access, record that prefix is not aliased
1056 -- to simplify legality check later on.
1059 Set_Non_Aliased_Prefix
(N
);
1062 -- If we have an aliased view, and we have Unrestricted_Access, then
1063 -- output a warning that Unchecked_Access would have been fine, and
1064 -- change the node to be Unchecked_Access.
1067 -- For now, hold off on this change ???
1071 end Analyze_Access_Attribute
;
1073 ---------------------------------
1074 -- Bad_Attribute_For_Predicate --
1075 ---------------------------------
1077 procedure Bad_Attribute_For_Predicate
is
1079 if Is_Scalar_Type
(P_Type
)
1080 and then Comes_From_Source
(N
)
1082 Error_Msg_Name_1
:= Aname
;
1083 Bad_Predicated_Subtype_Use
1084 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1086 end Bad_Attribute_For_Predicate
;
1088 --------------------------------
1089 -- Check_Array_Or_Scalar_Type --
1090 --------------------------------
1092 procedure Check_Array_Or_Scalar_Type
is
1096 -- Dimension number for array attributes
1099 -- Case of string literal or string literal subtype. These cases
1100 -- cannot arise from legal Ada code, but the expander is allowed
1101 -- to generate them. They require special handling because string
1102 -- literal subtypes do not have standard bounds (the whole idea
1103 -- of these subtypes is to avoid having to generate the bounds)
1105 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1106 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1111 elsif Is_Scalar_Type
(P_Type
) then
1114 if Present
(E1
) then
1115 Error_Attr
("invalid argument in % attribute", E1
);
1117 Set_Etype
(N
, P_Base_Type
);
1121 -- The following is a special test to allow 'First to apply to
1122 -- private scalar types if the attribute comes from generated
1123 -- code. This occurs in the case of Normalize_Scalars code.
1125 elsif Is_Private_Type
(P_Type
)
1126 and then Present
(Full_View
(P_Type
))
1127 and then Is_Scalar_Type
(Full_View
(P_Type
))
1128 and then not Comes_From_Source
(N
)
1130 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1132 -- Array types other than string literal subtypes handled above
1137 -- We know prefix is an array type, or the name of an array
1138 -- object, and that the expression, if present, is static
1139 -- and within the range of the dimensions of the type.
1141 pragma Assert
(Is_Array_Type
(P_Type
));
1142 Index
:= First_Index
(P_Base_Type
);
1146 -- First dimension assumed
1148 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1151 D
:= UI_To_Int
(Intval
(E1
));
1153 for J
in 1 .. D
- 1 loop
1157 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1158 Set_Etype
(E1
, Standard_Integer
);
1161 end Check_Array_Or_Scalar_Type
;
1163 ----------------------
1164 -- Check_Array_Type --
1165 ----------------------
1167 procedure Check_Array_Type
is
1169 -- Dimension number for array attributes
1172 -- If the type is a string literal type, then this must be generated
1173 -- internally, and no further check is required on its legality.
1175 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1178 -- If the type is a composite, it is an illegal aggregate, no point
1181 elsif P_Type
= Any_Composite
then
1182 raise Bad_Attribute
;
1185 -- Normal case of array type or subtype
1187 Check_Either_E0_Or_E1
;
1190 if Is_Array_Type
(P_Type
) then
1191 if not Is_Constrained
(P_Type
)
1192 and then Is_Entity_Name
(P
)
1193 and then Is_Type
(Entity
(P
))
1195 -- Note: we do not call Error_Attr here, since we prefer to
1196 -- continue, using the relevant index type of the array,
1197 -- even though it is unconstrained. This gives better error
1198 -- recovery behavior.
1200 Error_Msg_Name_1
:= Aname
;
1202 ("prefix for % attribute must be constrained array", P
);
1205 -- The attribute reference freezes the type, and thus the
1206 -- component type, even if the attribute may not depend on the
1207 -- component. Diagnose arrays with incomplete components now.
1208 -- If the prefix is an access to array, this does not freeze
1209 -- the designated type.
1211 if Nkind
(P
) /= N_Explicit_Dereference
then
1212 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1215 D
:= Number_Dimensions
(P_Type
);
1218 if Is_Private_Type
(P_Type
) then
1219 Error_Attr_P
("prefix for % attribute may not be private type");
1221 elsif Is_Access_Type
(P_Type
)
1222 and then Is_Array_Type
(Designated_Type
(P_Type
))
1223 and then Is_Entity_Name
(P
)
1224 and then Is_Type
(Entity
(P
))
1226 Error_Attr_P
("prefix of % attribute cannot be access type");
1228 elsif Attr_Id
= Attribute_First
1230 Attr_Id
= Attribute_Last
1232 Error_Attr
("invalid prefix for % attribute", P
);
1235 Error_Attr_P
("prefix for % attribute must be array");
1239 if Present
(E1
) then
1240 Resolve
(E1
, Any_Integer
);
1241 Set_Etype
(E1
, Standard_Integer
);
1243 if not Is_OK_Static_Expression
(E1
)
1244 or else Raises_Constraint_Error
(E1
)
1246 Flag_Non_Static_Expr
1247 ("expression for dimension must be static!", E1
);
1250 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1251 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1253 Error_Attr
("invalid dimension number for array type", E1
);
1257 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1258 and then Comes_From_Source
(N
)
1260 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1262 end Check_Array_Type
;
1264 -------------------------
1265 -- Check_Asm_Attribute --
1266 -------------------------
1268 procedure Check_Asm_Attribute
is
1273 -- Check first argument is static string expression
1275 Analyze_And_Resolve
(E1
, Standard_String
);
1277 if Etype
(E1
) = Any_Type
then
1280 elsif not Is_OK_Static_Expression
(E1
) then
1281 Flag_Non_Static_Expr
1282 ("constraint argument must be static string expression!", E1
);
1286 -- Check second argument is right type
1288 Analyze_And_Resolve
(E2
, Entity
(P
));
1290 -- Note: that is all we need to do, we don't need to check
1291 -- that it appears in a correct context. The Ada type system
1292 -- will do that for us.
1294 end Check_Asm_Attribute
;
1296 ---------------------
1297 -- Check_Component --
1298 ---------------------
1300 procedure Check_Component
is
1304 if Nkind
(P
) /= N_Selected_Component
1306 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1308 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1310 Error_Attr_P
("prefix for % attribute must be selected component");
1312 end Check_Component
;
1314 ------------------------------------
1315 -- Check_Decimal_Fixed_Point_Type --
1316 ------------------------------------
1318 procedure Check_Decimal_Fixed_Point_Type
is
1322 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1323 Error_Attr_P
("prefix of % attribute must be decimal type");
1325 end Check_Decimal_Fixed_Point_Type
;
1327 -----------------------
1328 -- Check_Dereference --
1329 -----------------------
1331 procedure Check_Dereference
is
1334 -- Case of a subtype mark
1336 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1340 -- Case of an expression
1344 if Is_Access_Type
(P_Type
) then
1346 -- If there is an implicit dereference, then we must freeze the
1347 -- designated type of the access type, since the type of the
1348 -- referenced array is this type (see AI95-00106).
1350 -- As done elsewhere, freezing must not happen when pre-analyzing
1351 -- a pre- or postcondition or a default value for an object or for
1352 -- a formal parameter.
1354 if not In_Spec_Expression
then
1355 Freeze_Before
(N
, Designated_Type
(P_Type
));
1359 Make_Explicit_Dereference
(Sloc
(P
),
1360 Prefix
=> Relocate_Node
(P
)));
1362 Analyze_And_Resolve
(P
);
1363 P_Type
:= Etype
(P
);
1365 if P_Type
= Any_Type
then
1366 raise Bad_Attribute
;
1369 P_Base_Type
:= Base_Type
(P_Type
);
1371 end Check_Dereference
;
1373 -------------------------
1374 -- Check_Discrete_Type --
1375 -------------------------
1377 procedure Check_Discrete_Type
is
1381 if not Is_Discrete_Type
(P_Type
) then
1382 Error_Attr_P
("prefix of % attribute must be discrete type");
1384 end Check_Discrete_Type
;
1390 procedure Check_E0
is
1392 if Present
(E1
) then
1393 Unexpected_Argument
(E1
);
1401 procedure Check_E1
is
1403 Check_Either_E0_Or_E1
;
1407 -- Special-case attributes that are functions and that appear as
1408 -- the prefix of another attribute. Error is posted on parent.
1410 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1411 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1415 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1416 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1417 Set_Etype
(Parent
(N
), Any_Type
);
1418 Set_Entity
(Parent
(N
), Any_Type
);
1419 raise Bad_Attribute
;
1422 Error_Attr
("missing argument for % attribute", N
);
1431 procedure Check_E2
is
1434 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1436 Error_Attr
("missing argument for % attribute (2 required)", N
);
1440 ---------------------------
1441 -- Check_Either_E0_Or_E1 --
1442 ---------------------------
1444 procedure Check_Either_E0_Or_E1
is
1446 if Present
(E2
) then
1447 Unexpected_Argument
(E2
);
1449 end Check_Either_E0_Or_E1
;
1451 ----------------------
1452 -- Check_Enum_Image --
1453 ----------------------
1455 procedure Check_Enum_Image
is
1459 -- When an enumeration type appears in an attribute reference, all
1460 -- literals of the type are marked as referenced. This must only be
1461 -- done if the attribute reference appears in the current source.
1462 -- Otherwise the information on references may differ between a
1463 -- normal compilation and one that performs inlining.
1465 if Is_Enumeration_Type
(P_Base_Type
)
1466 and then In_Extended_Main_Code_Unit
(N
)
1468 Lit
:= First_Literal
(P_Base_Type
);
1469 while Present
(Lit
) loop
1470 Set_Referenced
(Lit
);
1474 end Check_Enum_Image
;
1476 ----------------------------
1477 -- Check_First_Last_Valid --
1478 ----------------------------
1480 procedure Check_First_Last_Valid
is
1482 Check_Discrete_Type
;
1484 -- Freeze the subtype now, so that the following test for predicates
1485 -- works (we set the predicates stuff up at freeze time)
1487 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1489 -- Now test for dynamic predicate
1491 if Has_Predicates
(P_Type
)
1492 and then not (Has_Static_Predicate
(P_Type
))
1495 ("prefix of % attribute may not have dynamic predicate");
1498 -- Check non-static subtype
1500 if not Is_OK_Static_Subtype
(P_Type
) then
1501 Error_Attr_P
("prefix of % attribute must be a static subtype");
1504 -- Test case for no values
1506 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1507 Expr_Value
(Type_High_Bound
(P_Type
))
1508 or else (Has_Predicates
(P_Type
)
1510 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1513 ("prefix of % attribute must be subtype with at least one "
1516 end Check_First_Last_Valid
;
1518 ----------------------------
1519 -- Check_Fixed_Point_Type --
1520 ----------------------------
1522 procedure Check_Fixed_Point_Type
is
1526 if not Is_Fixed_Point_Type
(P_Type
) then
1527 Error_Attr_P
("prefix of % attribute must be fixed point type");
1529 end Check_Fixed_Point_Type
;
1531 ------------------------------
1532 -- Check_Fixed_Point_Type_0 --
1533 ------------------------------
1535 procedure Check_Fixed_Point_Type_0
is
1537 Check_Fixed_Point_Type
;
1539 end Check_Fixed_Point_Type_0
;
1541 -------------------------------
1542 -- Check_Floating_Point_Type --
1543 -------------------------------
1545 procedure Check_Floating_Point_Type
is
1549 if not Is_Floating_Point_Type
(P_Type
) then
1550 Error_Attr_P
("prefix of % attribute must be float type");
1552 end Check_Floating_Point_Type
;
1554 ---------------------------------
1555 -- Check_Floating_Point_Type_0 --
1556 ---------------------------------
1558 procedure Check_Floating_Point_Type_0
is
1560 Check_Floating_Point_Type
;
1562 end Check_Floating_Point_Type_0
;
1564 ---------------------------------
1565 -- Check_Floating_Point_Type_1 --
1566 ---------------------------------
1568 procedure Check_Floating_Point_Type_1
is
1570 Check_Floating_Point_Type
;
1572 end Check_Floating_Point_Type_1
;
1574 ---------------------------------
1575 -- Check_Floating_Point_Type_2 --
1576 ---------------------------------
1578 procedure Check_Floating_Point_Type_2
is
1580 Check_Floating_Point_Type
;
1582 end Check_Floating_Point_Type_2
;
1584 ------------------------
1585 -- Check_Integer_Type --
1586 ------------------------
1588 procedure Check_Integer_Type
is
1592 if not Is_Integer_Type
(P_Type
) then
1593 Error_Attr_P
("prefix of % attribute must be integer type");
1595 end Check_Integer_Type
;
1597 --------------------------------
1598 -- Check_Modular_Integer_Type --
1599 --------------------------------
1601 procedure Check_Modular_Integer_Type
is
1605 if not Is_Modular_Integer_Type
(P_Type
) then
1607 ("prefix of % attribute must be modular integer type");
1609 end Check_Modular_Integer_Type
;
1611 ------------------------
1612 -- Check_Not_CPP_Type --
1613 ------------------------
1615 procedure Check_Not_CPP_Type
is
1617 if Is_Tagged_Type
(Etype
(P
))
1618 and then Convention
(Etype
(P
)) = Convention_CPP
1619 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1622 ("invalid use of % attribute with 'C'P'P tagged type");
1624 end Check_Not_CPP_Type
;
1626 -------------------------------
1627 -- Check_Not_Incomplete_Type --
1628 -------------------------------
1630 procedure Check_Not_Incomplete_Type
is
1635 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1636 -- dereference we have to check wrong uses of incomplete types
1637 -- (other wrong uses are checked at their freezing point).
1639 -- Example 1: Limited-with
1641 -- limited with Pkg;
1643 -- type Acc is access Pkg.T;
1645 -- S : Integer := X.all'Size; -- ERROR
1648 -- Example 2: Tagged incomplete
1650 -- type T is tagged;
1651 -- type Acc is access all T;
1653 -- S : constant Integer := X.all'Size; -- ERROR
1654 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1656 if Ada_Version
>= Ada_2005
1657 and then Nkind
(P
) = N_Explicit_Dereference
1660 while Nkind
(E
) = N_Explicit_Dereference
loop
1666 if From_Limited_With
(Typ
) then
1668 ("prefix of % attribute cannot be an incomplete type");
1671 if Is_Access_Type
(Typ
) then
1672 Typ
:= Directly_Designated_Type
(Typ
);
1675 if Is_Class_Wide_Type
(Typ
) then
1676 Typ
:= Root_Type
(Typ
);
1679 -- A legal use of a shadow entity occurs only when the unit
1680 -- where the non-limited view resides is imported via a regular
1681 -- with clause in the current body. Such references to shadow
1682 -- entities may occur in subprogram formals.
1684 if Is_Incomplete_Type
(Typ
)
1685 and then From_Limited_With
(Typ
)
1686 and then Present
(Non_Limited_View
(Typ
))
1687 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1689 Typ
:= Non_Limited_View
(Typ
);
1692 if Ekind
(Typ
) = E_Incomplete_Type
1693 and then No
(Full_View
(Typ
))
1696 ("prefix of % attribute cannot be an incomplete type");
1701 if not Is_Entity_Name
(P
)
1702 or else not Is_Type
(Entity
(P
))
1703 or else In_Spec_Expression
1707 Check_Fully_Declared
(P_Type
, P
);
1709 end Check_Not_Incomplete_Type
;
1711 ----------------------------
1712 -- Check_Object_Reference --
1713 ----------------------------
1715 procedure Check_Object_Reference
(P
: Node_Id
) is
1719 -- If we need an object, and we have a prefix that is the name of
1720 -- a function entity, convert it into a function call.
1722 if Is_Entity_Name
(P
)
1723 and then Ekind
(Entity
(P
)) = E_Function
1725 Rtyp
:= Etype
(Entity
(P
));
1728 Make_Function_Call
(Sloc
(P
),
1729 Name
=> Relocate_Node
(P
)));
1731 Analyze_And_Resolve
(P
, Rtyp
);
1733 -- Otherwise we must have an object reference
1735 elsif not Is_Object_Reference
(P
) then
1736 Error_Attr_P
("prefix of % attribute must be object");
1738 end Check_Object_Reference
;
1740 ----------------------------
1741 -- Check_PolyORB_Attribute --
1742 ----------------------------
1744 procedure Check_PolyORB_Attribute
is
1746 Validate_Non_Static_Attribute_Function_Call
;
1751 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1753 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1755 end Check_PolyORB_Attribute
;
1757 ------------------------
1758 -- Check_Program_Unit --
1759 ------------------------
1761 procedure Check_Program_Unit
is
1763 if Is_Entity_Name
(P
) then
1765 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1766 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1769 if K
in Subprogram_Kind
1770 or else K
in Task_Kind
1771 or else K
in Protected_Kind
1772 or else K
= E_Package
1773 or else K
in Generic_Unit_Kind
1774 or else (K
= E_Variable
1778 Is_Protected_Type
(T
)))
1785 Error_Attr_P
("prefix of % attribute must be program unit");
1786 end Check_Program_Unit
;
1788 ---------------------
1789 -- Check_Real_Type --
1790 ---------------------
1792 procedure Check_Real_Type
is
1796 if not Is_Real_Type
(P_Type
) then
1797 Error_Attr_P
("prefix of % attribute must be real type");
1799 end Check_Real_Type
;
1801 -----------------------
1802 -- Check_Scalar_Type --
1803 -----------------------
1805 procedure Check_Scalar_Type
is
1809 if not Is_Scalar_Type
(P_Type
) then
1810 Error_Attr_P
("prefix of % attribute must be scalar type");
1812 end Check_Scalar_Type
;
1814 ------------------------------------------
1815 -- Check_SPARK_05_Restriction_On_Attribute --
1816 ------------------------------------------
1818 procedure Check_SPARK_05_Restriction_On_Attribute
is
1820 Error_Msg_Name_1
:= Aname
;
1821 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
1822 end Check_SPARK_05_Restriction_On_Attribute
;
1824 ---------------------------
1825 -- Check_Standard_Prefix --
1826 ---------------------------
1828 procedure Check_Standard_Prefix
is
1832 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
1833 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1835 end Check_Standard_Prefix
;
1837 ----------------------------
1838 -- Check_Stream_Attribute --
1839 ----------------------------
1841 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1845 In_Shared_Var_Procs
: Boolean;
1846 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1847 -- For this runtime package (always compiled in GNAT mode), we allow
1848 -- stream attributes references for limited types for the case where
1849 -- shared passive objects are implemented using stream attributes,
1850 -- which is the default in GNAT's persistent storage implementation.
1853 Validate_Non_Static_Attribute_Function_Call
;
1855 -- With the exception of 'Input, Stream attributes are procedures,
1856 -- and can only appear at the position of procedure calls. We check
1857 -- for this here, before they are rewritten, to give a more precise
1860 if Nam
= TSS_Stream_Input
then
1863 elsif Is_List_Member
(N
)
1864 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1871 ("invalid context for attribute%, which is a procedure", N
);
1875 Btyp
:= Implementation_Base_Type
(P_Type
);
1877 -- Stream attributes not allowed on limited types unless the
1878 -- attribute reference was generated by the expander (in which
1879 -- case the underlying type will be used, as described in Sinfo),
1880 -- or the attribute was specified explicitly for the type itself
1881 -- or one of its ancestors (taking visibility rules into account if
1882 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1883 -- (with no visibility restriction).
1886 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1888 if Present
(Gen_Body
) then
1889 In_Shared_Var_Procs
:=
1890 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1892 In_Shared_Var_Procs
:= False;
1896 if (Comes_From_Source
(N
)
1897 and then not (In_Shared_Var_Procs
or In_Instance
))
1898 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1899 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1901 Error_Msg_Name_1
:= Aname
;
1903 if Is_Limited_Type
(P_Type
) then
1905 ("limited type& has no% attribute", P
, P_Type
);
1906 Explain_Limited_Type
(P_Type
, P
);
1909 ("attribute% for type& is not available", P
, P_Type
);
1913 -- Check for no stream operations allowed from No_Tagged_Streams
1915 if Is_Tagged_Type
(P_Type
)
1916 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
1918 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
1920 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
1924 -- Check restriction violations
1926 -- First check the No_Streams restriction, which prohibits the use
1927 -- of explicit stream attributes in the source program. We do not
1928 -- prevent the occurrence of stream attributes in generated code,
1929 -- for instance those generated implicitly for dispatching purposes.
1931 if Comes_From_Source
(N
) then
1932 Check_Restriction
(No_Streams
, P
);
1935 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1936 -- it is illegal to use a predefined elementary type stream attribute
1937 -- either by itself, or more importantly as part of the attribute
1938 -- subprogram for a composite type. However, if the broader
1939 -- restriction No_Streams is active, stream operations are not
1940 -- generated, and there is no error.
1942 if Restriction_Active
(No_Default_Stream_Attributes
)
1943 and then not Restriction_Active
(No_Streams
)
1949 if Nam
= TSS_Stream_Input
1951 Nam
= TSS_Stream_Read
1954 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1957 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1961 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1964 ("missing user-defined Stream Read or Write for type&",
1966 if not Is_Elementary_Type
(P_Type
) then
1968 ("\which is a component of type&", N
, P_Type
);
1974 -- Check special case of Exception_Id and Exception_Occurrence which
1975 -- are not allowed for restriction No_Exception_Registration.
1977 if Restriction_Check_Required
(No_Exception_Registration
)
1978 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1980 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1982 Check_Restriction
(No_Exception_Registration
, P
);
1985 -- Here we must check that the first argument is an access type
1986 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1988 Analyze_And_Resolve
(E1
);
1991 -- Note: the double call to Root_Type here is needed because the
1992 -- root type of a class-wide type is the corresponding type (e.g.
1993 -- X for X'Class, and we really want to go to the root.)
1995 if not Is_Access_Type
(Etyp
)
1996 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1997 RTE
(RE_Root_Stream_Type
)
2000 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2003 -- Check that the second argument is of the right type if there is
2004 -- one (the Input attribute has only one argument so this is skipped)
2006 if Present
(E2
) then
2009 if Nam
= TSS_Stream_Read
2010 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2013 ("second argument of % attribute must be a variable", E2
);
2016 Resolve
(E2
, P_Type
);
2020 end Check_Stream_Attribute
;
2022 -------------------------
2023 -- Check_System_Prefix --
2024 -------------------------
2026 procedure Check_System_Prefix
is
2028 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2029 Error_Attr
("only allowed prefix for % attribute is System", P
);
2031 end Check_System_Prefix
;
2033 -----------------------
2034 -- Check_Task_Prefix --
2035 -----------------------
2037 procedure Check_Task_Prefix
is
2041 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2042 -- task interface class-wide types.
2044 if Is_Task_Type
(Etype
(P
))
2045 or else (Is_Access_Type
(Etype
(P
))
2046 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2047 or else (Ada_Version
>= Ada_2005
2048 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2049 and then Is_Interface
(Etype
(P
))
2050 and then Is_Task_Interface
(Etype
(P
)))
2055 if Ada_Version
>= Ada_2005
then
2057 ("prefix of % attribute must be a task or a task " &
2058 "interface class-wide object");
2061 Error_Attr_P
("prefix of % attribute must be a task");
2064 end Check_Task_Prefix
;
2070 -- The possibilities are an entity name denoting a type, or an
2071 -- attribute reference that denotes a type (Base or Class). If
2072 -- the type is incomplete, replace it with its full view.
2074 procedure Check_Type
is
2076 if not Is_Entity_Name
(P
)
2077 or else not Is_Type
(Entity
(P
))
2079 Error_Attr_P
("prefix of % attribute must be a type");
2081 elsif Is_Protected_Self_Reference
(P
) then
2083 ("prefix of % attribute denotes current instance "
2084 & "(RM 9.4(21/2))");
2086 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2087 and then Present
(Full_View
(Entity
(P
)))
2089 P_Type
:= Full_View
(Entity
(P
));
2090 Set_Entity
(P
, P_Type
);
2094 ---------------------
2095 -- Check_Unit_Name --
2096 ---------------------
2098 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2100 if Nkind
(Nod
) = N_Identifier
then
2103 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2104 Check_Unit_Name
(Prefix
(Nod
));
2106 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2111 Error_Attr
("argument for % attribute must be unit name", P
);
2112 end Check_Unit_Name
;
2118 procedure Error_Attr
is
2120 Set_Etype
(N
, Any_Type
);
2121 Set_Entity
(N
, Any_Type
);
2122 raise Bad_Attribute
;
2125 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2127 Error_Msg_Name_1
:= Aname
;
2128 Error_Msg_N
(Msg
, Error_Node
);
2136 procedure Error_Attr_P
(Msg
: String) is
2138 Error_Msg_Name_1
:= Aname
;
2139 Error_Msg_F
(Msg
, P
);
2143 ---------------------
2144 -- In_Refined_Post --
2145 ---------------------
2147 function In_Refined_Post
return Boolean is
2148 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean;
2149 -- Determine whether Prag denotes one of the incarnations of pragma
2150 -- Refined_Post (either as is or pragma Check (Refined_Post, ...).
2152 ---------------------
2153 -- Is_Refined_Post --
2154 ---------------------
2156 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean is
2157 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
2158 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2161 if Nam
= Name_Refined_Post
then
2164 elsif Nam
= Name_Check
then
2165 pragma Assert
(Present
(Args
));
2167 return Chars
(Expression
(First
(Args
))) = Name_Refined_Post
;
2171 end Is_Refined_Post
;
2177 -- Start of processing for In_Refined_Post
2181 while Present
(Stmt
) loop
2182 if Nkind
(Stmt
) = N_Pragma
and then Is_Refined_Post
(Stmt
) then
2185 -- Prevent the search from going too far
2187 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
2191 Stmt
:= Parent
(Stmt
);
2195 end In_Refined_Post
;
2197 ----------------------------
2198 -- Legal_Formal_Attribute --
2199 ----------------------------
2201 procedure Legal_Formal_Attribute
is
2205 if not Is_Entity_Name
(P
)
2206 or else not Is_Type
(Entity
(P
))
2208 Error_Attr_P
("prefix of % attribute must be generic type");
2210 elsif Is_Generic_Actual_Type
(Entity
(P
))
2212 or else In_Inlined_Body
2216 elsif Is_Generic_Type
(Entity
(P
)) then
2217 if not Is_Indefinite_Subtype
(Entity
(P
)) then
2219 ("prefix of % attribute must be indefinite generic type");
2224 ("prefix of % attribute must be indefinite generic type");
2227 Set_Etype
(N
, Standard_Boolean
);
2228 end Legal_Formal_Attribute
;
2230 ---------------------------------------------------------------
2231 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2232 ---------------------------------------------------------------
2234 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2238 Check_Not_Incomplete_Type
;
2239 Set_Etype
(N
, Universal_Integer
);
2240 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2246 procedure Min_Max
is
2250 Resolve
(E1
, P_Base_Type
);
2251 Resolve
(E2
, P_Base_Type
);
2252 Set_Etype
(N
, P_Base_Type
);
2254 -- Check for comparison on unordered enumeration type
2256 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2257 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2259 ("comparison on unordered enumeration type& declared#?U?",
2264 ------------------------
2265 -- Standard_Attribute --
2266 ------------------------
2268 procedure Standard_Attribute
(Val
: Int
) is
2270 Check_Standard_Prefix
;
2271 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2273 Set_Is_Static_Expression
(N
, True);
2274 end Standard_Attribute
;
2276 --------------------
2277 -- Uneval_Old_Msg --
2278 --------------------
2280 procedure Uneval_Old_Msg
is
2281 Uneval_Old_Setting
: Character;
2285 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2286 -- N_Aspect_Specification node that corresponds to the attribute.
2288 -- First find the pragma in which we appear (note that at this stage,
2289 -- even if we appeared originally within an aspect specification, we
2290 -- are now within the corresponding pragma).
2294 Prag
:= Parent
(Prag
);
2295 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2298 if Present
(Prag
) then
2299 if Uneval_Old_Accept
(Prag
) then
2300 Uneval_Old_Setting
:= 'A';
2301 elsif Uneval_Old_Warn
(Prag
) then
2302 Uneval_Old_Setting
:= 'W';
2304 Uneval_Old_Setting
:= 'E';
2307 -- If we did not find the pragma, that's odd, just use the setting
2308 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2311 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2314 -- Processing depends on the setting of Uneval_Old
2316 case Uneval_Old_Setting
is
2319 ("prefix of attribute % that is potentially "
2320 & "unevaluated must denote an entity");
2323 Error_Msg_Name_1
:= Aname
;
2325 ("??prefix of attribute % appears in potentially "
2326 & "unevaluated context, exception may be raised", P
);
2332 raise Program_Error
;
2336 -------------------------
2337 -- Unexpected Argument --
2338 -------------------------
2340 procedure Unexpected_Argument
(En
: Node_Id
) is
2342 Error_Attr
("unexpected argument for % attribute", En
);
2343 end Unexpected_Argument
;
2345 -------------------------------------------------
2346 -- Validate_Non_Static_Attribute_Function_Call --
2347 -------------------------------------------------
2349 -- This function should be moved to Sem_Dist ???
2351 procedure Validate_Non_Static_Attribute_Function_Call
is
2353 if In_Preelaborated_Unit
2354 and then not In_Subprogram_Or_Concurrent_Unit
2356 Flag_Non_Static_Expr
2357 ("non-static function call in preelaborated unit!", N
);
2359 end Validate_Non_Static_Attribute_Function_Call
;
2361 -- Start of processing for Analyze_Attribute
2364 -- Immediate return if unrecognized attribute (already diagnosed
2365 -- by parser, so there is nothing more that we need to do)
2367 if not Is_Attribute_Name
(Aname
) then
2368 raise Bad_Attribute
;
2371 -- Deal with Ada 83 issues
2373 if Comes_From_Source
(N
) then
2374 if not Attribute_83
(Attr_Id
) then
2375 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2376 Error_Msg_Name_1
:= Aname
;
2377 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2380 if Attribute_Impl_Def
(Attr_Id
) then
2381 Check_Restriction
(No_Implementation_Attributes
, N
);
2386 -- Deal with Ada 2005 attributes that are implementation attributes
2387 -- because they appear in a version of Ada before Ada 2005, and
2388 -- similarly for Ada 2012 attributes appearing in an earlier version.
2390 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2392 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2394 Check_Restriction
(No_Implementation_Attributes
, N
);
2397 -- Remote access to subprogram type access attribute reference needs
2398 -- unanalyzed copy for tree transformation. The analyzed copy is used
2399 -- for its semantic information (whether prefix is a remote subprogram
2400 -- name), the unanalyzed copy is used to construct new subtree rooted
2401 -- with N_Aggregate which represents a fat pointer aggregate.
2403 if Aname
= Name_Access
then
2404 Discard_Node
(Copy_Separate_Tree
(N
));
2407 -- Analyze prefix and exit if error in analysis. If the prefix is an
2408 -- incomplete type, use full view if available. Note that there are
2409 -- some attributes for which we do not analyze the prefix, since the
2410 -- prefix is not a normal name, or else needs special handling.
2412 if Aname
/= Name_Elab_Body
and then
2413 Aname
/= Name_Elab_Spec
and then
2414 Aname
/= Name_Elab_Subp_Body
and then
2415 Aname
/= Name_UET_Address
and then
2416 Aname
/= Name_Enabled
and then
2420 P_Type
:= Etype
(P
);
2422 if Is_Entity_Name
(P
)
2423 and then Present
(Entity
(P
))
2424 and then Is_Type
(Entity
(P
))
2426 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2427 P_Type
:= Get_Full_View
(P_Type
);
2428 Set_Entity
(P
, P_Type
);
2429 Set_Etype
(P
, P_Type
);
2431 elsif Entity
(P
) = Current_Scope
2432 and then Is_Record_Type
(Entity
(P
))
2434 -- Use of current instance within the type. Verify that if the
2435 -- attribute appears within a constraint, it yields an access
2436 -- type, other uses are illegal.
2444 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2446 Par
:= Parent
(Par
);
2450 and then Nkind
(Par
) = N_Subtype_Indication
2452 if Attr_Id
/= Attribute_Access
2453 and then Attr_Id
/= Attribute_Unchecked_Access
2454 and then Attr_Id
/= Attribute_Unrestricted_Access
2457 ("in a constraint the current instance can only"
2458 & " be used with an access attribute", N
);
2465 if P_Type
= Any_Type
then
2466 raise Bad_Attribute
;
2469 P_Base_Type
:= Base_Type
(P_Type
);
2472 -- Analyze expressions that may be present, exiting if an error occurs
2479 E1
:= First
(Exprs
);
2481 -- Skip analysis for case of Restriction_Set, we do not expect
2482 -- the argument to be analyzed in this case.
2484 if Aname
/= Name_Restriction_Set
then
2487 -- Check for missing/bad expression (result of previous error)
2489 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2490 raise Bad_Attribute
;
2496 if Present
(E2
) then
2499 if Etype
(E2
) = Any_Type
then
2500 raise Bad_Attribute
;
2503 if Present
(Next
(E2
)) then
2504 Unexpected_Argument
(Next
(E2
));
2509 -- Cases where prefix must be resolvable by itself
2511 if Is_Overloaded
(P
)
2512 and then Aname
/= Name_Access
2513 and then Aname
/= Name_Address
2514 and then Aname
/= Name_Code_Address
2515 and then Aname
/= Name_Result
2516 and then Aname
/= Name_Unchecked_Access
2518 -- The prefix must be resolvable by itself, without reference to the
2519 -- attribute. One case that requires special handling is a prefix
2520 -- that is a function name, where one interpretation may be a
2521 -- parameterless call. Entry attributes are handled specially below.
2523 if Is_Entity_Name
(P
)
2524 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2526 Check_Parameterless_Call
(P
);
2529 if Is_Overloaded
(P
) then
2531 -- Ada 2005 (AI-345): Since protected and task types have
2532 -- primitive entry wrappers, the attributes Count, and Caller
2533 -- require a context check
2535 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2537 Count
: Natural := 0;
2542 Get_First_Interp
(P
, I
, It
);
2543 while Present
(It
.Nam
) loop
2544 if Comes_From_Source
(It
.Nam
) then
2550 Get_Next_Interp
(I
, It
);
2554 Error_Attr
("ambiguous prefix for % attribute", P
);
2556 Set_Is_Overloaded
(P
, False);
2561 Error_Attr
("ambiguous prefix for % attribute", P
);
2566 -- In SPARK, attributes of private types are only allowed if the full
2567 -- type declaration is visible.
2569 -- Note: the check for Present (Entity (P)) defends against some error
2570 -- conditions where the Entity field is not set.
2572 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2573 and then Is_Type
(Entity
(P
))
2574 and then Is_Private_Type
(P_Type
)
2575 and then not In_Open_Scopes
(Scope
(P_Type
))
2576 and then not In_Spec_Expression
2578 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
2581 -- Remaining processing depends on attribute
2585 -- Attributes related to Ada 2012 iterators. Attribute specifications
2586 -- exist for these, but they cannot be queried.
2588 when Attribute_Constant_Indexing |
2589 Attribute_Default_Iterator |
2590 Attribute_Implicit_Dereference |
2591 Attribute_Iterator_Element |
2592 Attribute_Iterable |
2593 Attribute_Variable_Indexing
=>
2594 Error_Msg_N
("illegal attribute", N
);
2596 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2597 -- were already rejected by the parser. Thus they shouldn't appear here.
2599 when Internal_Attribute_Id
=>
2600 raise Program_Error
;
2606 when Attribute_Abort_Signal
=>
2607 Check_Standard_Prefix
;
2608 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
2615 when Attribute_Access
=>
2616 Analyze_Access_Attribute
;
2622 when Attribute_Address
=>
2625 Set_Etype
(N
, RTE
(RE_Address
));
2631 when Attribute_Address_Size
=>
2632 Standard_Attribute
(System_Address_Size
);
2638 when Attribute_Adjacent
=>
2639 Check_Floating_Point_Type_2
;
2640 Set_Etype
(N
, P_Base_Type
);
2641 Resolve
(E1
, P_Base_Type
);
2642 Resolve
(E2
, P_Base_Type
);
2648 when Attribute_Aft
=>
2649 Check_Fixed_Point_Type_0
;
2650 Set_Etype
(N
, Universal_Integer
);
2656 when Attribute_Alignment
=>
2658 -- Don't we need more checking here, cf Size ???
2661 Check_Not_Incomplete_Type
;
2663 Set_Etype
(N
, Universal_Integer
);
2669 when Attribute_Asm_Input
=>
2670 Check_Asm_Attribute
;
2672 -- The back-end may need to take the address of E2
2674 if Is_Entity_Name
(E2
) then
2675 Set_Address_Taken
(Entity
(E2
));
2678 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2684 when Attribute_Asm_Output
=>
2685 Check_Asm_Attribute
;
2687 if Etype
(E2
) = Any_Type
then
2690 elsif Aname
= Name_Asm_Output
then
2691 if not Is_Variable
(E2
) then
2693 ("second argument for Asm_Output is not variable", E2
);
2697 Note_Possible_Modification
(E2
, Sure
=> True);
2699 -- The back-end may need to take the address of E2
2701 if Is_Entity_Name
(E2
) then
2702 Set_Address_Taken
(Entity
(E2
));
2705 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2707 -----------------------------
2708 -- Atomic_Always_Lock_Free --
2709 -----------------------------
2711 when Attribute_Atomic_Always_Lock_Free
=>
2714 Set_Etype
(N
, Standard_Boolean
);
2720 -- Note: when the base attribute appears in the context of a subtype
2721 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2722 -- the following circuit.
2724 when Attribute_Base
=> Base
: declare
2732 if Ada_Version
>= Ada_95
2733 and then not Is_Scalar_Type
(Typ
)
2734 and then not Is_Generic_Type
(Typ
)
2736 Error_Attr_P
("prefix of Base attribute must be scalar type");
2738 elsif Sloc
(Typ
) = Standard_Location
2739 and then Base_Type
(Typ
) = Typ
2740 and then Warn_On_Redundant_Constructs
2742 Error_Msg_NE
-- CODEFIX
2743 ("?r?redundant attribute, & is its own base type", N
, Typ
);
2746 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2747 Error_Msg_Name_1
:= Aname
;
2748 Check_SPARK_05_Restriction
2749 ("attribute% is only allowed as prefix of another attribute", P
);
2752 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2753 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2754 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
2762 when Attribute_Bit
=> Bit
:
2766 if not Is_Object_Reference
(P
) then
2767 Error_Attr_P
("prefix for % attribute must be object");
2769 -- What about the access object cases ???
2775 Set_Etype
(N
, Universal_Integer
);
2782 when Attribute_Bit_Order
=> Bit_Order
:
2787 if not Is_Record_Type
(P_Type
) then
2788 Error_Attr_P
("prefix of % attribute must be record type");
2791 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2793 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2796 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2799 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2802 -- Reset incorrect indication of staticness
2804 Set_Is_Static_Expression
(N
, False);
2811 -- Note: in generated code, we can have a Bit_Position attribute
2812 -- applied to a (naked) record component (i.e. the prefix is an
2813 -- identifier that references an E_Component or E_Discriminant
2814 -- entity directly, and this is interpreted as expected by Gigi.
2815 -- The following code will not tolerate such usage, but when the
2816 -- expander creates this special case, it marks it as analyzed
2817 -- immediately and sets an appropriate type.
2819 when Attribute_Bit_Position
=>
2820 if Comes_From_Source
(N
) then
2824 Set_Etype
(N
, Universal_Integer
);
2830 when Attribute_Body_Version
=>
2833 Set_Etype
(N
, RTE
(RE_Version_String
));
2839 when Attribute_Callable
=>
2841 Set_Etype
(N
, Standard_Boolean
);
2848 when Attribute_Caller
=> Caller
: declare
2855 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2858 if not Is_Entry
(Ent
) then
2859 Error_Attr
("invalid entry name", N
);
2863 Error_Attr
("invalid entry name", N
);
2867 for J
in reverse 0 .. Scope_Stack
.Last
loop
2868 S
:= Scope_Stack
.Table
(J
).Entity
;
2870 if S
= Scope
(Ent
) then
2871 Error_Attr
("Caller must appear in matching accept or body", N
);
2877 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2884 when Attribute_Ceiling
=>
2885 Check_Floating_Point_Type_1
;
2886 Set_Etype
(N
, P_Base_Type
);
2887 Resolve
(E1
, P_Base_Type
);
2893 when Attribute_Class
=>
2894 Check_Restriction
(No_Dispatch
, N
);
2898 -- Applying Class to untagged incomplete type is obsolescent in Ada
2899 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2900 -- this flag gets set by Find_Type in this situation.
2902 if Restriction_Check_Required
(No_Obsolescent_Features
)
2903 and then Ada_Version
>= Ada_2005
2904 and then Ekind
(P_Type
) = E_Incomplete_Type
2907 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2909 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2910 and then not Tagged_Present
(DN
)
2912 Check_Restriction
(No_Obsolescent_Features
, P
);
2921 when Attribute_Code_Address
=>
2924 if Nkind
(P
) = N_Attribute_Reference
2925 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
2929 elsif not Is_Entity_Name
(P
)
2930 or else (Ekind
(Entity
(P
)) /= E_Function
2932 Ekind
(Entity
(P
)) /= E_Procedure
)
2934 Error_Attr
("invalid prefix for % attribute", P
);
2935 Set_Address_Taken
(Entity
(P
));
2937 -- Issue an error if the prefix denotes an eliminated subprogram
2940 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2943 Set_Etype
(N
, RTE
(RE_Address
));
2945 ----------------------
2946 -- Compiler_Version --
2947 ----------------------
2949 when Attribute_Compiler_Version
=>
2951 Check_Standard_Prefix
;
2952 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2953 Analyze_And_Resolve
(N
, Standard_String
);
2954 Set_Is_Static_Expression
(N
, True);
2956 --------------------
2957 -- Component_Size --
2958 --------------------
2960 when Attribute_Component_Size
=>
2962 Set_Etype
(N
, Universal_Integer
);
2964 -- Note: unlike other array attributes, unconstrained arrays are OK
2966 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2976 when Attribute_Compose
=>
2977 Check_Floating_Point_Type_2
;
2978 Set_Etype
(N
, P_Base_Type
);
2979 Resolve
(E1
, P_Base_Type
);
2980 Resolve
(E2
, Any_Integer
);
2986 when Attribute_Constrained
=>
2988 Set_Etype
(N
, Standard_Boolean
);
2990 -- Case from RM J.4(2) of constrained applied to private type
2992 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2993 Check_Restriction
(No_Obsolescent_Features
, P
);
2995 if Warn_On_Obsolescent_Feature
then
2997 ("constrained for private type is an " &
2998 "obsolescent feature (RM J.4)?j?", N
);
3001 -- If we are within an instance, the attribute must be legal
3002 -- because it was valid in the generic unit. Ditto if this is
3003 -- an inlining of a function declared in an instance.
3005 if In_Instance
or else In_Inlined_Body
then
3008 -- For sure OK if we have a real private type itself, but must
3009 -- be completed, cannot apply Constrained to incomplete type.
3011 elsif Is_Private_Type
(Entity
(P
)) then
3013 -- Note: this is one of the Annex J features that does not
3014 -- generate a warning from -gnatwj, since in fact it seems
3015 -- very useful, and is used in the GNAT runtime.
3017 Check_Not_Incomplete_Type
;
3021 -- Normal (non-obsolescent case) of application to object of
3022 -- a discriminated type.
3025 Check_Object_Reference
(P
);
3027 -- If N does not come from source, then we allow the
3028 -- the attribute prefix to be of a private type whose
3029 -- full type has discriminants. This occurs in cases
3030 -- involving expanded calls to stream attributes.
3032 if not Comes_From_Source
(N
) then
3033 P_Type
:= Underlying_Type
(P_Type
);
3036 -- Must have discriminants or be an access type designating
3037 -- a type with discriminants. If it is a classwide type it
3038 -- has unknown discriminants.
3040 if Has_Discriminants
(P_Type
)
3041 or else Has_Unknown_Discriminants
(P_Type
)
3043 (Is_Access_Type
(P_Type
)
3044 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3048 -- The rule given in 3.7.2 is part of static semantics, but the
3049 -- intent is clearly that it be treated as a legality rule, and
3050 -- rechecked in the visible part of an instance. Nevertheless
3051 -- the intent also seems to be it should legally apply to the
3052 -- actual of a formal with unknown discriminants, regardless of
3053 -- whether the actual has discriminants, in which case the value
3054 -- of the attribute is determined using the J.4 rules. This choice
3055 -- seems the most useful, and is compatible with existing tests.
3057 elsif In_Instance
then
3060 -- Also allow an object of a generic type if extensions allowed
3061 -- and allow this for any type at all. (this may be obsolete ???)
3063 elsif (Is_Generic_Type
(P_Type
)
3064 or else Is_Generic_Actual_Type
(P_Type
))
3065 and then Extensions_Allowed
3071 -- Fall through if bad prefix
3074 ("prefix of % attribute must be object of discriminated type");
3080 when Attribute_Copy_Sign
=>
3081 Check_Floating_Point_Type_2
;
3082 Set_Etype
(N
, P_Base_Type
);
3083 Resolve
(E1
, P_Base_Type
);
3084 Resolve
(E2
, P_Base_Type
);
3090 when Attribute_Count
=> Count
:
3099 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3102 if Ekind
(Ent
) /= E_Entry
then
3103 Error_Attr
("invalid entry name", N
);
3106 elsif Nkind
(P
) = N_Indexed_Component
then
3107 if not Is_Entity_Name
(Prefix
(P
))
3108 or else No
(Entity
(Prefix
(P
)))
3109 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3111 if Nkind
(Prefix
(P
)) = N_Selected_Component
3112 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3113 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3117 ("attribute % must apply to entry of current task", P
);
3120 Error_Attr
("invalid entry family name", P
);
3125 Ent
:= Entity
(Prefix
(P
));
3128 elsif Nkind
(P
) = N_Selected_Component
3129 and then Present
(Entity
(Selector_Name
(P
)))
3130 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3133 ("attribute % must apply to entry of current task", P
);
3136 Error_Attr
("invalid entry name", N
);
3140 for J
in reverse 0 .. Scope_Stack
.Last
loop
3141 S
:= Scope_Stack
.Table
(J
).Entity
;
3143 if S
= Scope
(Ent
) then
3144 if Nkind
(P
) = N_Expanded_Name
then
3145 Tsk
:= Entity
(Prefix
(P
));
3147 -- The prefix denotes either the task type, or else a
3148 -- single task whose task type is being analyzed.
3150 if (Is_Type
(Tsk
) and then Tsk
= S
)
3151 or else (not Is_Type
(Tsk
)
3152 and then Etype
(Tsk
) = S
3153 and then not (Comes_From_Source
(S
)))
3158 ("Attribute % must apply to entry of current task", N
);
3164 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3166 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3168 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3170 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3171 and then not Has_Completion
(Scope
(Ent
))
3173 Error_Attr
("attribute % can only be used inside body", N
);
3177 if Is_Overloaded
(P
) then
3179 Index
: Interp_Index
;
3183 Get_First_Interp
(P
, Index
, It
);
3184 while Present
(It
.Nam
) loop
3185 if It
.Nam
= Ent
then
3188 -- Ada 2005 (AI-345): Do not consider primitive entry
3189 -- wrappers generated for task or protected types.
3191 elsif Ada_Version
>= Ada_2005
3192 and then not Comes_From_Source
(It
.Nam
)
3197 Error_Attr
("ambiguous entry name", N
);
3200 Get_Next_Interp
(Index
, It
);
3205 Set_Etype
(N
, Universal_Integer
);
3208 -----------------------
3209 -- Default_Bit_Order --
3210 -----------------------
3212 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
3213 Target_Default_Bit_Order
: System
.Bit_Order
;
3216 Check_Standard_Prefix
;
3218 if Bytes_Big_Endian
then
3219 Target_Default_Bit_Order
:= System
.High_Order_First
;
3221 Target_Default_Bit_Order
:= System
.Low_Order_First
;
3225 Make_Integer_Literal
(Loc
,
3226 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
3228 Set_Etype
(N
, Universal_Integer
);
3229 Set_Is_Static_Expression
(N
);
3230 end Default_Bit_Order
;
3232 ----------------------------------
3233 -- Default_Scalar_Storage_Order --
3234 ----------------------------------
3236 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
3237 RE_Default_SSO
: RE_Id
;
3240 Check_Standard_Prefix
;
3242 case Opt
.Default_SSO
is
3244 if Bytes_Big_Endian
then
3245 RE_Default_SSO
:= RE_High_Order_First
;
3247 RE_Default_SSO
:= RE_Low_Order_First
;
3251 RE_Default_SSO
:= RE_High_Order_First
;
3254 RE_Default_SSO
:= RE_Low_Order_First
;
3257 raise Program_Error
;
3260 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
3267 when Attribute_Definite
=>
3268 Legal_Formal_Attribute
;
3274 when Attribute_Delta
=>
3275 Check_Fixed_Point_Type_0
;
3276 Set_Etype
(N
, Universal_Real
);
3282 when Attribute_Denorm
=>
3283 Check_Floating_Point_Type_0
;
3284 Set_Etype
(N
, Standard_Boolean
);
3286 ---------------------
3287 -- Descriptor_Size --
3288 ---------------------
3290 when Attribute_Descriptor_Size
=>
3293 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3294 Error_Attr_P
("prefix of attribute % must denote a type");
3297 Set_Etype
(N
, Universal_Integer
);
3303 when Attribute_Digits
=>
3307 if not Is_Floating_Point_Type
(P_Type
)
3308 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3311 ("prefix of % attribute must be float or decimal type");
3314 Set_Etype
(N
, Universal_Integer
);
3320 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3322 when Attribute_Elab_Body |
3323 Attribute_Elab_Spec |
3324 Attribute_Elab_Subp_Body
=>
3327 Check_Unit_Name
(P
);
3328 Set_Etype
(N
, Standard_Void_Type
);
3330 -- We have to manually call the expander in this case to get
3331 -- the necessary expansion (normally attributes that return
3332 -- entities are not expanded).
3340 -- Shares processing with Elab_Body
3346 when Attribute_Elaborated
=>
3348 Check_Unit_Name
(P
);
3349 Set_Etype
(N
, Standard_Boolean
);
3355 when Attribute_Emax
=>
3356 Check_Floating_Point_Type_0
;
3357 Set_Etype
(N
, Universal_Integer
);
3363 when Attribute_Enabled
=>
3364 Check_Either_E0_Or_E1
;
3366 if Present
(E1
) then
3367 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3368 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3373 if Nkind
(P
) /= N_Identifier
then
3374 Error_Msg_N
("identifier expected (check name)", P
);
3375 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3376 Error_Msg_N
("& is not a recognized check name", P
);
3379 Set_Etype
(N
, Standard_Boolean
);
3385 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3387 if Present
(E1
) then
3389 Check_Discrete_Type
;
3390 Resolve
(E1
, P_Base_Type
);
3393 if not Is_Entity_Name
(P
)
3394 or else (not Is_Object
(Entity
(P
))
3395 and then Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3398 ("prefix of % attribute must be " &
3399 "discrete type/object or enum literal");
3403 Set_Etype
(N
, Universal_Integer
);
3410 when Attribute_Enum_Val
=> Enum_Val
: begin
3414 if not Is_Enumeration_Type
(P_Type
) then
3415 Error_Attr_P
("prefix of % attribute must be enumeration type");
3418 -- If the enumeration type has a standard representation, the effect
3419 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3421 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3423 Make_Attribute_Reference
(Loc
,
3424 Prefix
=> Relocate_Node
(Prefix
(N
)),
3425 Attribute_Name
=> Name_Val
,
3426 Expressions
=> New_List
(Relocate_Node
(E1
))));
3427 Analyze_And_Resolve
(N
, P_Base_Type
);
3429 -- Non-standard representation case (enumeration with holes)
3433 Resolve
(E1
, Any_Integer
);
3434 Set_Etype
(N
, P_Base_Type
);
3442 when Attribute_Epsilon
=>
3443 Check_Floating_Point_Type_0
;
3444 Set_Etype
(N
, Universal_Real
);
3450 when Attribute_Exponent
=>
3451 Check_Floating_Point_Type_1
;
3452 Set_Etype
(N
, Universal_Integer
);
3453 Resolve
(E1
, P_Base_Type
);
3459 when Attribute_External_Tag
=>
3463 Set_Etype
(N
, Standard_String
);
3465 if not Is_Tagged_Type
(P_Type
) then
3466 Error_Attr_P
("prefix of % attribute must be tagged");
3473 when Attribute_Fast_Math
=>
3474 Check_Standard_Prefix
;
3475 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3481 when Attribute_First
=>
3482 Check_Array_Or_Scalar_Type
;
3483 Bad_Attribute_For_Predicate
;
3489 when Attribute_First_Bit
=>
3491 Set_Etype
(N
, Universal_Integer
);
3497 when Attribute_First_Valid
=>
3498 Check_First_Last_Valid
;
3499 Set_Etype
(N
, P_Type
);
3505 when Attribute_Fixed_Value
=>
3507 Check_Fixed_Point_Type
;
3508 Resolve
(E1
, Any_Integer
);
3509 Set_Etype
(N
, P_Base_Type
);
3515 when Attribute_Floor
=>
3516 Check_Floating_Point_Type_1
;
3517 Set_Etype
(N
, P_Base_Type
);
3518 Resolve
(E1
, P_Base_Type
);
3524 when Attribute_Fore
=>
3525 Check_Fixed_Point_Type_0
;
3526 Set_Etype
(N
, Universal_Integer
);
3532 when Attribute_Fraction
=>
3533 Check_Floating_Point_Type_1
;
3534 Set_Etype
(N
, P_Base_Type
);
3535 Resolve
(E1
, P_Base_Type
);
3541 when Attribute_From_Any
=>
3543 Check_PolyORB_Attribute
;
3544 Set_Etype
(N
, P_Base_Type
);
3546 -----------------------
3547 -- Has_Access_Values --
3548 -----------------------
3550 when Attribute_Has_Access_Values
=>
3553 Set_Etype
(N
, Standard_Boolean
);
3555 ----------------------
3556 -- Has_Same_Storage --
3557 ----------------------
3559 when Attribute_Has_Same_Storage
=>
3562 -- The arguments must be objects of any type
3564 Analyze_And_Resolve
(P
);
3565 Analyze_And_Resolve
(E1
);
3566 Check_Object_Reference
(P
);
3567 Check_Object_Reference
(E1
);
3568 Set_Etype
(N
, Standard_Boolean
);
3570 -----------------------
3571 -- Has_Tagged_Values --
3572 -----------------------
3574 when Attribute_Has_Tagged_Values
=>
3577 Set_Etype
(N
, Standard_Boolean
);
3579 -----------------------
3580 -- Has_Discriminants --
3581 -----------------------
3583 when Attribute_Has_Discriminants
=>
3584 Legal_Formal_Attribute
;
3590 when Attribute_Identity
=>
3594 if Etype
(P
) = Standard_Exception_Type
then
3595 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3597 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
3598 -- interface class-wide types.
3600 elsif Is_Task_Type
(Etype
(P
))
3601 or else (Is_Access_Type
(Etype
(P
))
3602 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3603 or else (Ada_Version
>= Ada_2005
3604 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3605 and then Is_Interface
(Etype
(P
))
3606 and then Is_Task_Interface
(Etype
(P
)))
3609 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3612 if Ada_Version
>= Ada_2005
then
3614 ("prefix of % attribute must be an exception, a " &
3615 "task or a task interface class-wide object");
3618 ("prefix of % attribute must be a task or an exception");
3626 when Attribute_Image
=> Image
:
3628 Check_SPARK_05_Restriction_On_Attribute
;
3630 Set_Etype
(N
, Standard_String
);
3632 if Is_Real_Type
(P_Type
) then
3633 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3634 Error_Msg_Name_1
:= Aname
;
3636 ("(Ada 83) % attribute not allowed for real types", N
);
3640 if Is_Enumeration_Type
(P_Type
) then
3641 Check_Restriction
(No_Enumeration_Maps
, N
);
3645 Resolve
(E1
, P_Base_Type
);
3647 Validate_Non_Static_Attribute_Function_Call
;
3649 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
3650 -- to avoid giving a duplicate message for Img expanded into Image.
3652 if Restriction_Check_Required
(No_Fixed_IO
)
3653 and then Comes_From_Source
(N
)
3654 and then Is_Fixed_Point_Type
(P_Type
)
3656 Check_Restriction
(No_Fixed_IO
, P
);
3664 when Attribute_Img
=> Img
:
3667 Set_Etype
(N
, Standard_String
);
3669 if not Is_Scalar_Type
(P_Type
)
3670 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3673 ("prefix of % attribute must be scalar object name");
3678 -- Check restriction No_Fixed_IO
3680 if Restriction_Check_Required
(No_Fixed_IO
)
3681 and then Is_Fixed_Point_Type
(P_Type
)
3683 Check_Restriction
(No_Fixed_IO
, P
);
3691 when Attribute_Input
=>
3693 Check_Stream_Attribute
(TSS_Stream_Input
);
3694 Set_Etype
(N
, P_Base_Type
);
3700 when Attribute_Integer_Value
=>
3703 Resolve
(E1
, Any_Fixed
);
3705 -- Signal an error if argument type is not a specific fixed-point
3706 -- subtype. An error has been signalled already if the argument
3707 -- was not of a fixed-point type.
3709 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3710 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3713 Set_Etype
(N
, P_Base_Type
);
3719 when Attribute_Invalid_Value
=>
3722 Set_Etype
(N
, P_Base_Type
);
3723 Invalid_Value_Used
:= True;
3729 when Attribute_Large
=>
3732 Set_Etype
(N
, Universal_Real
);
3738 when Attribute_Last
=>
3739 Check_Array_Or_Scalar_Type
;
3740 Bad_Attribute_For_Predicate
;
3746 when Attribute_Last_Bit
=>
3748 Set_Etype
(N
, Universal_Integer
);
3754 when Attribute_Last_Valid
=>
3755 Check_First_Last_Valid
;
3756 Set_Etype
(N
, P_Type
);
3762 when Attribute_Leading_Part
=>
3763 Check_Floating_Point_Type_2
;
3764 Set_Etype
(N
, P_Base_Type
);
3765 Resolve
(E1
, P_Base_Type
);
3766 Resolve
(E2
, Any_Integer
);
3772 when Attribute_Length
=>
3774 Set_Etype
(N
, Universal_Integer
);
3780 when Attribute_Library_Level
=>
3783 if not Is_Entity_Name
(P
) then
3784 Error_Attr_P
("prefix of % attribute must be an entity name");
3787 if not Inside_A_Generic
then
3788 Set_Boolean_Result
(N
,
3789 Is_Library_Level_Entity
(Entity
(P
)));
3792 Set_Etype
(N
, Standard_Boolean
);
3798 when Attribute_Lock_Free
=>
3800 Set_Etype
(N
, Standard_Boolean
);
3802 if not Is_Protected_Type
(P_Type
) then
3804 ("prefix of % attribute must be a protected object");
3811 when Attribute_Loop_Entry
=> Loop_Entry
: declare
3812 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
3813 -- Inspect the prefix for any uses of entities declared within the
3814 -- related loop. Loop_Id denotes the loop identifier.
3816 --------------------------------
3817 -- Check_References_In_Prefix --
3818 --------------------------------
3820 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
3821 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
3823 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
3824 -- Determine whether a reference mentions an entity declared
3825 -- within the related loop.
3827 function Declared_Within
(Nod
: Node_Id
) return Boolean;
3828 -- Determine whether Nod appears in the subtree of Loop_Decl
3830 ---------------------
3831 -- Check_Reference --
3832 ---------------------
3834 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
3836 if Nkind
(Nod
) = N_Identifier
3837 and then Present
(Entity
(Nod
))
3838 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
3841 ("prefix of attribute % cannot reference local entities",
3847 end Check_Reference
;
3849 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
3851 ---------------------
3852 -- Declared_Within --
3853 ---------------------
3855 function Declared_Within
(Nod
: Node_Id
) return Boolean is
3860 while Present
(Stmt
) loop
3861 if Stmt
= Loop_Decl
then
3864 -- Prevent the search from going too far
3866 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3870 Stmt
:= Parent
(Stmt
);
3874 end Declared_Within
;
3876 -- Start of processing for Check_Prefix_For_Local_References
3879 Check_References
(P
);
3880 end Check_References_In_Prefix
;
3884 Context
: constant Node_Id
:= Parent
(N
);
3886 Enclosing_Loop
: Node_Id
;
3887 Loop_Id
: Entity_Id
:= Empty
;
3890 Enclosing_Pragma
: Node_Id
:= Empty
;
3892 -- Start of processing for Loop_Entry
3897 -- Set the type of the attribute now to ensure the successfull
3898 -- continuation of analysis even if the attribute is misplaced.
3900 Set_Etype
(Attr
, P_Type
);
3902 -- Attribute 'Loop_Entry may appear in several flavors:
3904 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3905 -- nearest enclosing loop.
3907 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3908 -- attribute may be related to a loop denoted by label Expr or
3909 -- the prefix may denote an array object and Expr may act as an
3910 -- indexed component.
3912 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3913 -- to the nearest enclosing loop, all expressions are part of
3914 -- an indexed component.
3916 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3917 -- denotes, the attribute may be related to a loop denoted by
3918 -- label Expr or the prefix may denote a multidimensional array
3919 -- array object and Expr along with the rest of the expressions
3920 -- may act as indexed components.
3922 -- Regardless of variations, the attribute reference does not have an
3923 -- expression list. Instead, all available expressions are stored as
3924 -- indexed components.
3926 -- When the attribute is part of an indexed component, find the first
3927 -- expression as it will determine the semantics of 'Loop_Entry.
3929 if Nkind
(Context
) = N_Indexed_Component
then
3930 E1
:= First
(Expressions
(Context
));
3933 -- The attribute reference appears in the following form:
3935 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3937 -- In this case, the loop name is omitted and no rewriting is
3940 if Present
(E2
) then
3943 -- The form of the attribute is:
3945 -- Prefix'Loop_Entry (Expr) [(...)]
3947 -- If Expr denotes a loop entry, the whole attribute and indexed
3948 -- component will have to be rewritten to reflect this relation.
3951 pragma Assert
(Present
(E1
));
3953 -- Do not expand the expression as it may have side effects.
3954 -- Simply preanalyze to determine whether it is a loop name or
3957 Preanalyze_And_Resolve
(E1
);
3959 if Is_Entity_Name
(E1
)
3960 and then Present
(Entity
(E1
))
3961 and then Ekind
(Entity
(E1
)) = E_Loop
3963 Loop_Id
:= Entity
(E1
);
3965 -- Transform the attribute and enclosing indexed component
3967 Set_Expressions
(N
, Expressions
(Context
));
3968 Rewrite
(Context
, N
);
3969 Set_Etype
(Context
, P_Type
);
3976 -- The prefix must denote an object
3978 if not Is_Object_Reference
(P
) then
3979 Error_Attr_P
("prefix of attribute % must denote an object");
3982 -- The prefix cannot be of a limited type because the expansion of
3983 -- Loop_Entry must create a constant initialized by the evaluated
3986 if Is_Limited_View
(Etype
(P
)) then
3987 Error_Attr_P
("prefix of attribute % cannot be limited");
3990 -- Climb the parent chain to verify the location of the attribute and
3991 -- find the enclosing loop.
3994 while Present
(Stmt
) loop
3996 -- Locate the corresponding enclosing pragma. Note that in the
3997 -- case of Assert[And_Cut] and Assume, we have already checked
3998 -- that the pragma appears in an appropriate loop location.
4000 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4001 and then Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
4002 Name_Loop_Invariant
,
4005 Name_Assert_And_Cut
,
4008 Enclosing_Pragma
:= Original_Node
(Stmt
);
4010 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4011 -- iteration may be expanded into several nested loops, we are
4012 -- interested in the outermost one which has the loop identifier.
4014 elsif Nkind
(Stmt
) = N_Loop_Statement
4015 and then Present
(Identifier
(Stmt
))
4017 Enclosing_Loop
:= Stmt
;
4019 -- The original attribute reference may lack a loop name. Use
4020 -- the name of the enclosing loop because it is the related
4023 if No
(Loop_Id
) then
4024 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
4029 -- Prevent the search from going too far
4031 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4035 Stmt
:= Parent
(Stmt
);
4038 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4039 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4040 -- purpose if they appear in an appropriate location in a loop,
4041 -- which was already checked by the top level pragma circuit).
4043 if No
(Enclosing_Pragma
) then
4044 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4047 -- A Loop_Entry that applies to a given loop statement must not
4048 -- appear within a body of accept statement, if this construct is
4049 -- itself enclosed by the given loop statement.
4051 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4052 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4054 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4056 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4060 ("attribute % cannot appear in body or accept statement", N
);
4065 -- The prefix cannot mention entities declared within the related
4066 -- loop because they will not be visible once the prefix is moved
4067 -- outside the loop.
4069 Check_References_In_Prefix
(Loop_Id
);
4071 -- The prefix must denote a static entity if the pragma does not
4072 -- apply to the innermost enclosing loop statement, or if it appears
4073 -- within a potentially unevaluated epxression.
4075 if Is_Entity_Name
(P
)
4076 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4080 elsif Present
(Enclosing_Loop
)
4081 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
4084 ("prefix of attribute % that applies to outer loop must denote "
4087 elsif Is_Potentially_Unevaluated
(P
) then
4091 -- Replace the Loop_Entry attribute reference by its prefix if the
4092 -- related pragma is ignored. This transformation is OK with respect
4093 -- to typing because Loop_Entry's type is that of its prefix. This
4094 -- early transformation also avoids the generation of a useless loop
4097 if Is_Ignored
(Enclosing_Pragma
) then
4098 Rewrite
(N
, Relocate_Node
(P
));
4101 Preanalyze_And_Resolve
(P
);
4108 when Attribute_Machine
=>
4109 Check_Floating_Point_Type_1
;
4110 Set_Etype
(N
, P_Base_Type
);
4111 Resolve
(E1
, P_Base_Type
);
4117 when Attribute_Machine_Emax
=>
4118 Check_Floating_Point_Type_0
;
4119 Set_Etype
(N
, Universal_Integer
);
4125 when Attribute_Machine_Emin
=>
4126 Check_Floating_Point_Type_0
;
4127 Set_Etype
(N
, Universal_Integer
);
4129 ----------------------
4130 -- Machine_Mantissa --
4131 ----------------------
4133 when Attribute_Machine_Mantissa
=>
4134 Check_Floating_Point_Type_0
;
4135 Set_Etype
(N
, Universal_Integer
);
4137 -----------------------
4138 -- Machine_Overflows --
4139 -----------------------
4141 when Attribute_Machine_Overflows
=>
4144 Set_Etype
(N
, Standard_Boolean
);
4150 when Attribute_Machine_Radix
=>
4153 Set_Etype
(N
, Universal_Integer
);
4155 ----------------------
4156 -- Machine_Rounding --
4157 ----------------------
4159 when Attribute_Machine_Rounding
=>
4160 Check_Floating_Point_Type_1
;
4161 Set_Etype
(N
, P_Base_Type
);
4162 Resolve
(E1
, P_Base_Type
);
4164 --------------------
4165 -- Machine_Rounds --
4166 --------------------
4168 when Attribute_Machine_Rounds
=>
4171 Set_Etype
(N
, Standard_Boolean
);
4177 when Attribute_Machine_Size
=>
4180 Check_Not_Incomplete_Type
;
4181 Set_Etype
(N
, Universal_Integer
);
4187 when Attribute_Mantissa
=>
4190 Set_Etype
(N
, Universal_Integer
);
4196 when Attribute_Max
=>
4199 ----------------------------------
4200 -- Max_Alignment_For_Allocation --
4201 ----------------------------------
4203 when Attribute_Max_Size_In_Storage_Elements
=>
4204 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4206 ----------------------------------
4207 -- Max_Size_In_Storage_Elements --
4208 ----------------------------------
4210 when Attribute_Max_Alignment_For_Allocation
=>
4211 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4213 -----------------------
4214 -- Maximum_Alignment --
4215 -----------------------
4217 when Attribute_Maximum_Alignment
=>
4218 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4220 --------------------
4221 -- Mechanism_Code --
4222 --------------------
4224 when Attribute_Mechanism_Code
=>
4225 if not Is_Entity_Name
(P
)
4226 or else not Is_Subprogram
(Entity
(P
))
4228 Error_Attr_P
("prefix of % attribute must be subprogram");
4231 Check_Either_E0_Or_E1
;
4233 if Present
(E1
) then
4234 Resolve
(E1
, Any_Integer
);
4235 Set_Etype
(E1
, Standard_Integer
);
4237 if not Is_OK_Static_Expression
(E1
) then
4238 Flag_Non_Static_Expr
4239 ("expression for parameter number must be static!", E1
);
4242 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4243 or else UI_To_Int
(Intval
(E1
)) < 0
4245 Error_Attr
("invalid parameter number for % attribute", E1
);
4249 Set_Etype
(N
, Universal_Integer
);
4255 when Attribute_Min
=>
4262 when Attribute_Mod
=>
4264 -- Note: this attribute is only allowed in Ada 2005 mode, but
4265 -- we do not need to test that here, since Mod is only recognized
4266 -- as an attribute name in Ada 2005 mode during the parse.
4269 Check_Modular_Integer_Type
;
4270 Resolve
(E1
, Any_Integer
);
4271 Set_Etype
(N
, P_Base_Type
);
4277 when Attribute_Model
=>
4278 Check_Floating_Point_Type_1
;
4279 Set_Etype
(N
, P_Base_Type
);
4280 Resolve
(E1
, P_Base_Type
);
4286 when Attribute_Model_Emin
=>
4287 Check_Floating_Point_Type_0
;
4288 Set_Etype
(N
, Universal_Integer
);
4294 when Attribute_Model_Epsilon
=>
4295 Check_Floating_Point_Type_0
;
4296 Set_Etype
(N
, Universal_Real
);
4298 --------------------
4299 -- Model_Mantissa --
4300 --------------------
4302 when Attribute_Model_Mantissa
=>
4303 Check_Floating_Point_Type_0
;
4304 Set_Etype
(N
, Universal_Integer
);
4310 when Attribute_Model_Small
=>
4311 Check_Floating_Point_Type_0
;
4312 Set_Etype
(N
, Universal_Real
);
4318 when Attribute_Modulus
=>
4320 Check_Modular_Integer_Type
;
4321 Set_Etype
(N
, Universal_Integer
);
4323 --------------------
4324 -- Null_Parameter --
4325 --------------------
4327 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4328 Parnt
: constant Node_Id
:= Parent
(N
);
4329 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4331 procedure Bad_Null_Parameter
(Msg
: String);
4332 -- Used if bad Null parameter attribute node is found. Issues
4333 -- given error message, and also sets the type to Any_Type to
4334 -- avoid blowups later on from dealing with a junk node.
4336 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4337 -- Called to check that Proc_Ent is imported subprogram
4339 ------------------------
4340 -- Bad_Null_Parameter --
4341 ------------------------
4343 procedure Bad_Null_Parameter
(Msg
: String) is
4345 Error_Msg_N
(Msg
, N
);
4346 Set_Etype
(N
, Any_Type
);
4347 end Bad_Null_Parameter
;
4349 ----------------------
4350 -- Must_Be_Imported --
4351 ----------------------
4353 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4354 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4357 -- Ignore check if procedure not frozen yet (we will get
4358 -- another chance when the default parameter is reanalyzed)
4360 if not Is_Frozen
(Pent
) then
4363 elsif not Is_Imported
(Pent
) then
4365 ("Null_Parameter can only be used with imported subprogram");
4370 end Must_Be_Imported
;
4372 -- Start of processing for Null_Parameter
4377 Set_Etype
(N
, P_Type
);
4379 -- Case of attribute used as default expression
4381 if Nkind
(Parnt
) = N_Parameter_Specification
then
4382 Must_Be_Imported
(Defining_Entity
(GParnt
));
4384 -- Case of attribute used as actual for subprogram (positional)
4386 elsif Nkind
(Parnt
) in N_Subprogram_Call
4387 and then Is_Entity_Name
(Name
(Parnt
))
4389 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4391 -- Case of attribute used as actual for subprogram (named)
4393 elsif Nkind
(Parnt
) = N_Parameter_Association
4394 and then Nkind
(GParnt
) in N_Subprogram_Call
4395 and then Is_Entity_Name
(Name
(GParnt
))
4397 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4399 -- Not an allowed case
4403 ("Null_Parameter must be actual or default parameter");
4411 when Attribute_Object_Size
=>
4414 Check_Not_Incomplete_Type
;
4415 Set_Etype
(N
, Universal_Integer
);
4421 when Attribute_Old
=> Old
: declare
4422 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4423 -- Inspect the contents of the prefix and detect illegal uses of a
4424 -- nested 'Old, attribute 'Result or a use of an entity declared in
4425 -- the related postcondition expression. Subp_Id is the subprogram to
4426 -- which the related postcondition applies.
4428 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
);
4429 -- Perform various semantic checks related to the placement of the
4430 -- attribute in pragma Contract_Cases.
4432 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
);
4433 -- Perform various semantic checks related to the placement of the
4434 -- attribute in pragma Contract_Cases.
4436 --------------------------------
4437 -- Check_References_In_Prefix --
4438 --------------------------------
4440 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4441 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4442 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4443 -- and perform the appropriate semantic check.
4445 ---------------------
4446 -- Check_Reference --
4447 ---------------------
4449 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4451 -- Attributes 'Old and 'Result cannot appear in the prefix of
4452 -- another attribute 'Old.
4454 if Nkind
(Nod
) = N_Attribute_Reference
4455 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4458 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4459 Error_Msg_Name_2
:= Name_Old
;
4461 ("attribute % cannot appear in the prefix of attribute %",
4465 -- Entities mentioned within the prefix of attribute 'Old must
4466 -- be global to the related postcondition. If this is not the
4467 -- case, then the scope of the local entity is nested within
4468 -- that of the subprogram.
4470 elsif Nkind
(Nod
) = N_Identifier
4471 and then Present
(Entity
(Nod
))
4472 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4475 ("prefix of attribute % cannot reference local entities",
4481 end Check_Reference
;
4483 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4485 -- Start of processing for Check_References_In_Prefix
4488 Check_References
(P
);
4489 end Check_References_In_Prefix
;
4491 ---------------------------------
4492 -- Check_Use_In_Contract_Cases --
4493 ---------------------------------
4495 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
) is
4496 Cases
: constant Node_Id
:=
4498 (First
(Pragma_Argument_Associations
(Prag
)));
4502 -- Climb the parent chain to reach the top of the expression where
4503 -- attribute 'Old resides.
4506 while Parent
(Parent
(Expr
)) /= Cases
loop
4507 Expr
:= Parent
(Expr
);
4510 -- Ensure that the obtained expression is the consequence of a
4511 -- contract case as this is the only postcondition-like part of
4512 -- the pragma. Otherwise, attribute 'Old appears in the condition
4513 -- of a contract case. Emit an error since this is not a
4514 -- postcondition-like context. (SPARK RM 6.1.3(2))
4516 if Expr
/= Expression
(Parent
(Expr
)) then
4518 ("attribute % cannot appear in the condition "
4519 & "of a contract case", P
);
4521 end Check_Use_In_Contract_Cases
;
4523 ----------------------------
4524 -- Check_Use_In_Test_Case --
4525 ----------------------------
4527 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
) is
4528 Ensures
: constant Node_Id
:= Get_Ensures_From_CTC_Pragma
(Prag
);
4532 -- Climb the parent chain to reach the top of the Ensures part of
4533 -- pragma Test_Case.
4536 while Expr
/= Prag
loop
4537 if Expr
= Ensures
then
4541 Expr
:= Parent
(Expr
);
4544 -- If we get there, then attribute 'Old appears in the requires
4545 -- expression of pragma Test_Case which is not a postcondition-
4549 ("attribute % cannot appear in the requires expression of a "
4551 end Check_Use_In_Test_Case
;
4556 -- The enclosing scope, excluding loops for quantified expressions.
4557 -- During analysis, it is the postcondition subprogram. During
4558 -- pre-analysis, it is the scope of the subprogram declaration.
4561 -- During pre-analysis, Prag is the enclosing pragma node if any
4563 -- Start of processing for Old
4568 -- Find enclosing scopes, excluding loops
4570 CS
:= Current_Scope
;
4571 while Ekind
(CS
) = E_Loop
loop
4575 -- A Contract_Cases, Postcondition or Test_Case pragma is in the
4576 -- process of being preanalyzed. Perform the semantic checks now
4577 -- before the pragma is relocated and/or expanded.
4579 -- For a generic subprogram, postconditions are preanalyzed as well
4580 -- for name capture, and still appear within an aspect spec.
4582 if In_Spec_Expression
or Inside_A_Generic
then
4584 while Present
(Prag
)
4585 and then not Nkind_In
(Prag
, N_Aspect_Specification
,
4586 N_Function_Specification
,
4588 N_Procedure_Specification
,
4591 Prag
:= Parent
(Prag
);
4594 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4595 -- corresponding pragma. Don't issue errors when analyzing aspect.
4597 if Nkind
(Prag
) = N_Aspect_Specification
4598 and then Chars
(Identifier
(Prag
)) = Name_Post
4602 -- In all other cases the related context must be a pragma
4604 elsif Nkind
(Prag
) /= N_Pragma
then
4605 Error_Attr
("% attribute can only appear in postcondition", P
);
4607 -- Verify the placement of the attribute with respect to the
4611 case Get_Pragma_Id
(Prag
) is
4612 when Pragma_Contract_Cases
=>
4613 Check_Use_In_Contract_Cases
(Prag
);
4615 when Pragma_Postcondition | Pragma_Refined_Post
=>
4618 when Pragma_Test_Case
=>
4619 Check_Use_In_Test_Case
(Prag
);
4623 ("% attribute can only appear in postcondition", P
);
4627 -- Check the legality of attribute 'Old when it appears inside pragma
4628 -- Refined_Post. These specialized checks are required only when code
4629 -- generation is disabled. In the general case pragma Refined_Post is
4630 -- transformed into pragma Check by Process_PPCs which in turn is
4631 -- relocated to procedure _Postconditions. From then on the legality
4632 -- of 'Old is determined as usual.
4634 elsif not Expander_Active
and then In_Refined_Post
then
4635 Preanalyze_And_Resolve
(P
);
4636 Check_References_In_Prefix
(CS
);
4637 P_Type
:= Etype
(P
);
4638 Set_Etype
(N
, P_Type
);
4640 if Is_Limited_Type
(P_Type
) then
4641 Error_Attr
("attribute % cannot apply to limited objects", P
);
4644 if Is_Entity_Name
(P
)
4645 and then Is_Constant_Object
(Entity
(P
))
4648 ("??attribute Old applied to constant has no effect", P
);
4653 -- Body case, where we must be inside a generated _Postconditions
4654 -- procedure, or else the attribute use is definitely misplaced. The
4655 -- postcondition itself may have generated transient scopes, and is
4656 -- not necessarily the current one.
4659 while Present
(CS
) and then CS
/= Standard_Standard
loop
4660 if Chars
(CS
) = Name_uPostconditions
then
4667 if Chars
(CS
) /= Name_uPostconditions
then
4668 Error_Attr
("% attribute can only appear in postcondition", P
);
4672 -- If the attribute reference is generated for a Requires clause,
4673 -- then no expressions follow. Otherwise it is a primary, in which
4674 -- case, if expressions follow, the attribute reference must be an
4675 -- indexable object, so rewrite the node accordingly.
4677 if Present
(E1
) then
4679 Make_Indexed_Component
(Loc
,
4681 Make_Attribute_Reference
(Loc
,
4682 Prefix
=> Relocate_Node
(Prefix
(N
)),
4683 Attribute_Name
=> Name_Old
),
4684 Expressions
=> Expressions
(N
)));
4692 -- Prefix has not been analyzed yet, and its full analysis will take
4693 -- place during expansion (see below).
4695 Preanalyze_And_Resolve
(P
);
4696 Check_References_In_Prefix
(CS
);
4697 P_Type
:= Etype
(P
);
4698 Set_Etype
(N
, P_Type
);
4700 if Is_Limited_Type
(P_Type
) then
4701 Error_Attr
("attribute % cannot apply to limited objects", P
);
4704 if Is_Entity_Name
(P
)
4705 and then Is_Constant_Object
(Entity
(P
))
4708 ("??attribute Old applied to constant has no effect", P
);
4711 -- Check that the prefix of 'Old is an entity when it may be
4712 -- potentially unevaluated (6.1.1 (27/3)).
4715 and then Is_Potentially_Unevaluated
(N
)
4716 and then not Is_Entity_Name
(P
)
4721 -- The attribute appears within a pre/postcondition, but refers to
4722 -- an entity in the enclosing subprogram. If it is a component of
4723 -- a formal its expansion might generate actual subtypes that may
4724 -- be referenced in an inner context, and which must be elaborated
4725 -- within the subprogram itself. If the prefix includes a function
4726 -- call it may involve finalization actions that should only be
4727 -- inserted when the attribute has been rewritten as a declarations.
4728 -- As a result, if the prefix is not a simple name we create
4729 -- a declaration for it now, and insert it at the start of the
4730 -- enclosing subprogram. This is properly an expansion activity
4731 -- but it has to be performed now to prevent out-of-order issues.
4733 -- This expansion is both harmful and not needed in SPARK mode, since
4734 -- the formal verification backend relies on the types of nodes
4735 -- (hence is not robust w.r.t. a change to base type here), and does
4736 -- not suffer from the out-of-order issue described above. Thus, this
4737 -- expansion is skipped in SPARK mode.
4739 if not Is_Entity_Name
(P
) and then not GNATprove_Mode
then
4740 P_Type
:= Base_Type
(P_Type
);
4741 Set_Etype
(N
, P_Type
);
4742 Set_Etype
(P
, P_Type
);
4743 Analyze_Dimension
(N
);
4748 ----------------------
4749 -- Overlaps_Storage --
4750 ----------------------
4752 when Attribute_Overlaps_Storage
=>
4755 -- Both arguments must be objects of any type
4757 Analyze_And_Resolve
(P
);
4758 Analyze_And_Resolve
(E1
);
4759 Check_Object_Reference
(P
);
4760 Check_Object_Reference
(E1
);
4761 Set_Etype
(N
, Standard_Boolean
);
4767 when Attribute_Output
=>
4769 Check_Stream_Attribute
(TSS_Stream_Output
);
4770 Set_Etype
(N
, Standard_Void_Type
);
4771 Resolve
(N
, Standard_Void_Type
);
4777 when Attribute_Partition_ID
=> Partition_Id
:
4781 if P_Type
/= Any_Type
then
4782 if not Is_Library_Level_Entity
(Entity
(P
)) then
4784 ("prefix of % attribute must be library-level entity");
4786 -- The defining entity of prefix should not be declared inside a
4787 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4789 elsif Is_Entity_Name
(P
)
4790 and then Is_Pure
(Entity
(P
))
4792 Error_Attr_P
("prefix of% attribute must not be declared pure");
4796 Set_Etype
(N
, Universal_Integer
);
4799 -------------------------
4800 -- Passed_By_Reference --
4801 -------------------------
4803 when Attribute_Passed_By_Reference
=>
4806 Set_Etype
(N
, Standard_Boolean
);
4812 when Attribute_Pool_Address
=>
4814 Set_Etype
(N
, RTE
(RE_Address
));
4820 when Attribute_Pos
=>
4821 Check_Discrete_Type
;
4824 if Is_Boolean_Type
(P_Type
) then
4825 Error_Msg_Name_1
:= Aname
;
4826 Error_Msg_Name_2
:= Chars
(P_Type
);
4827 Check_SPARK_05_Restriction
4828 ("attribute% is not allowed for type%", P
);
4831 Resolve
(E1
, P_Base_Type
);
4832 Set_Etype
(N
, Universal_Integer
);
4838 when Attribute_Position
=>
4840 Set_Etype
(N
, Universal_Integer
);
4846 when Attribute_Pred
=>
4850 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4851 Error_Msg_Name_1
:= Aname
;
4852 Error_Msg_Name_2
:= Chars
(P_Type
);
4853 Check_SPARK_05_Restriction
4854 ("attribute% is not allowed for type%", P
);
4857 Resolve
(E1
, P_Base_Type
);
4858 Set_Etype
(N
, P_Base_Type
);
4860 -- Since Pred works on the base type, we normally do no check for the
4861 -- floating-point case, since the base type is unconstrained. But we
4862 -- make an exception in Check_Float_Overflow mode.
4864 if Is_Floating_Point_Type
(P_Type
) then
4865 if not Range_Checks_Suppressed
(P_Base_Type
) then
4866 Set_Do_Range_Check
(E1
);
4869 -- If not modular type, test for overflow check required
4872 if not Is_Modular_Integer_Type
(P_Type
)
4873 and then not Range_Checks_Suppressed
(P_Base_Type
)
4875 Enable_Range_Check
(E1
);
4883 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4885 when Attribute_Priority
=>
4886 if Ada_Version
< Ada_2005
then
4887 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4892 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4896 if Is_Protected_Type
(Etype
(P
))
4897 or else (Is_Access_Type
(Etype
(P
))
4898 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4900 Resolve
(P
, Etype
(P
));
4902 Error_Attr_P
("prefix of % attribute must be a protected object");
4905 Set_Etype
(N
, Standard_Integer
);
4907 -- Must be called from within a protected procedure or entry of the
4908 -- protected object.
4915 while S
/= Etype
(P
)
4916 and then S
/= Standard_Standard
4921 if S
= Standard_Standard
then
4922 Error_Attr
("the attribute % is only allowed inside protected "
4927 Validate_Non_Static_Attribute_Function_Call
;
4933 when Attribute_Range
=>
4934 Check_Array_Or_Scalar_Type
;
4935 Bad_Attribute_For_Predicate
;
4937 if Ada_Version
= Ada_83
4938 and then Is_Scalar_Type
(P_Type
)
4939 and then Comes_From_Source
(N
)
4942 ("(Ada 83) % attribute not allowed for scalar type", P
);
4949 when Attribute_Result
=> Result
: declare
4950 Post_Id
: Entity_Id
;
4951 -- The entity of the _Postconditions procedure
4954 -- During pre-analysis, Prag is the enclosing pragma node if any
4956 Subp_Id
: Entity_Id
;
4957 -- The entity of the enclosing subprogram
4960 -- Find the proper enclosing scope
4962 Post_Id
:= Current_Scope
;
4963 while Present
(Post_Id
) loop
4965 -- Skip generated loops
4967 if Ekind
(Post_Id
) = E_Loop
then
4968 Post_Id
:= Scope
(Post_Id
);
4970 -- Skip the special _Parent scope generated to capture references
4971 -- to formals during the process of subprogram inlining.
4973 elsif Ekind
(Post_Id
) = E_Function
4974 and then Chars
(Post_Id
) = Name_uParent
4976 Post_Id
:= Scope
(Post_Id
);
4978 -- Otherwise this must be _Postconditions
4985 Subp_Id
:= Scope
(Post_Id
);
4987 -- If the enclosing subprogram is always inlined, the enclosing
4988 -- postcondition will not be propagated to the expanded call.
4990 if not In_Spec_Expression
4991 and then Has_Pragma_Inline_Always
(Subp_Id
)
4992 and then Warn_On_Redundant_Constructs
4995 ("postconditions on inlined functions not enforced?r?", N
);
4998 -- If we are in the scope of a function and in Spec_Expression mode,
4999 -- this is likely the prescan of the postcondition (or contract case,
5000 -- or test case) pragma, and we just set the proper type. If there is
5001 -- an error it will be caught when the real Analyze call is done.
5003 if Ekind
(Post_Id
) = E_Function
and then In_Spec_Expression
then
5007 if Chars
(Post_Id
) /= Chars
(P
) then
5008 Error_Msg_Name_1
:= Name_Result
;
5010 ("incorrect prefix for % attribute, expected &", P
, Post_Id
);
5014 -- Check in postcondition, Test_Case or Contract_Cases of function
5017 while Present
(Prag
)
5018 and then not Nkind_In
(Prag
, N_Pragma
,
5019 N_Function_Specification
,
5020 N_Aspect_Specification
,
5023 Prag
:= Parent
(Prag
);
5026 -- In ASIS mode, the aspect itself is analyzed, in addition to the
5027 -- corresponding pragma. Do not issue errors when analyzing the
5030 if Nkind
(Prag
) = N_Aspect_Specification
then
5033 -- Must have a pragma
5035 elsif Nkind
(Prag
) /= N_Pragma
then
5037 ("% attribute can only appear in postcondition of function",
5040 -- Processing depends on which pragma we have
5043 case Get_Pragma_Id
(Prag
) is
5044 when Pragma_Test_Case
=>
5046 Arg_Ens
: constant Node_Id
:=
5047 Get_Ensures_From_CTC_Pragma
(Prag
);
5052 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
5053 Arg
:= Parent
(Arg
);
5056 if Arg
/= Arg_Ens
then
5058 ("% attribute misplaced inside test case", P
);
5062 when Pragma_Contract_Cases
=>
5064 Aggr
: constant Node_Id
:=
5066 (Pragma_Argument_Associations
(Prag
)));
5072 and then Parent
(Parent
(Arg
)) /= Aggr
5074 Arg
:= Parent
(Arg
);
5077 -- At this point, Parent (Arg) should be a component
5078 -- association. Attribute Result is only allowed in
5079 -- the expression part of this association.
5081 if Nkind
(Parent
(Arg
)) /= N_Component_Association
5082 or else Arg
/= Expression
(Parent
(Arg
))
5085 ("% attribute misplaced inside contract cases",
5090 when Pragma_Postcondition | Pragma_Refined_Post
=>
5095 ("% attribute can only appear in postcondition "
5096 & "of function", P
);
5100 -- The attribute reference is a primary. If expressions follow,
5101 -- the attribute reference is really an indexable object, so
5102 -- rewrite and analyze as an indexed component.
5104 if Present
(E1
) then
5106 Make_Indexed_Component
(Loc
,
5108 Make_Attribute_Reference
(Loc
,
5109 Prefix
=> Relocate_Node
(Prefix
(N
)),
5110 Attribute_Name
=> Name_Result
),
5111 Expressions
=> Expressions
(N
)));
5116 Set_Etype
(N
, Etype
(Post_Id
));
5118 -- If several functions with that name are visible, the intended
5119 -- one is the current scope.
5121 if Is_Overloaded
(P
) then
5122 Set_Entity
(P
, Post_Id
);
5123 Set_Is_Overloaded
(P
, False);
5126 -- Check the legality of attribute 'Result when it appears inside
5127 -- pragma Refined_Post. These specialized checks are required only
5128 -- when code generation is disabled. In the general case pragma
5129 -- Refined_Post is transformed into pragma Check by Process_PPCs
5130 -- which in turn is relocated to procedure _Postconditions. From
5131 -- then on the legality of 'Result is determined as usual.
5133 elsif not Expander_Active
and then In_Refined_Post
then
5135 -- Routine _Postconditions has not been generated yet, the nearest
5136 -- enclosing subprogram is denoted by the current scope.
5138 if Ekind
(Post_Id
) /= E_Procedure
5139 or else Chars
(Post_Id
) /= Name_uPostconditions
5141 Subp_Id
:= Current_Scope
;
5144 -- The prefix denotes the nearest enclosing function
5146 if Is_Entity_Name
(P
)
5147 and then Ekind
(Entity
(P
)) = E_Function
5148 and then Entity
(P
) = Subp_Id
5152 -- Otherwise the use of 'Result is illegal
5155 Error_Msg_Name_2
:= Chars
(Subp_Id
);
5156 Error_Attr
("incorrect prefix for % attribute, expected %", P
);
5159 Set_Etype
(N
, Etype
(Subp_Id
));
5161 -- Body case, where we must be inside a generated _Postconditions
5162 -- procedure, and the prefix must be on the scope stack, or else the
5163 -- attribute use is definitely misplaced. The postcondition itself
5164 -- may have generated transient scopes, and is not necessarily the
5168 while Present
(Post_Id
)
5169 and then Post_Id
/= Standard_Standard
5171 if Chars
(Post_Id
) = Name_uPostconditions
then
5174 Post_Id
:= Scope
(Post_Id
);
5178 Subp_Id
:= Scope
(Post_Id
);
5180 if Chars
(Post_Id
) = Name_uPostconditions
5181 and then Ekind
(Subp_Id
) = E_Function
5185 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
5186 and then Chars
(P
) = Chars
(Subp_Id
)
5190 -- Within an instance, the prefix designates the local renaming
5191 -- of the original generic.
5193 elsif Is_Entity_Name
(P
)
5194 and then Ekind
(Entity
(P
)) = E_Function
5195 and then Present
(Alias
(Entity
(P
)))
5196 and then Chars
(Alias
(Entity
(P
))) = Chars
(Subp_Id
)
5201 Error_Msg_Name_2
:= Chars
(Subp_Id
);
5203 ("incorrect prefix for % attribute, expected %", P
);
5206 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
5207 Analyze_And_Resolve
(N
, Etype
(Subp_Id
));
5211 ("% attribute can only appear in postcondition of function",
5221 when Attribute_Range_Length
=>
5223 Check_Discrete_Type
;
5224 Set_Etype
(N
, Universal_Integer
);
5230 when Attribute_Read
=>
5232 Check_Stream_Attribute
(TSS_Stream_Read
);
5233 Set_Etype
(N
, Standard_Void_Type
);
5234 Resolve
(N
, Standard_Void_Type
);
5235 Note_Possible_Modification
(E2
, Sure
=> True);
5241 when Attribute_Ref
=>
5245 if Nkind
(P
) /= N_Expanded_Name
5246 or else not Is_RTE
(P_Type
, RE_Address
)
5248 Error_Attr_P
("prefix of % attribute must be System.Address");
5251 Analyze_And_Resolve
(E1
, Any_Integer
);
5252 Set_Etype
(N
, RTE
(RE_Address
));
5258 when Attribute_Remainder
=>
5259 Check_Floating_Point_Type_2
;
5260 Set_Etype
(N
, P_Base_Type
);
5261 Resolve
(E1
, P_Base_Type
);
5262 Resolve
(E2
, P_Base_Type
);
5264 ---------------------
5265 -- Restriction_Set --
5266 ---------------------
5268 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5271 Unam
: Unit_Name_Type
;
5276 Check_System_Prefix
;
5278 -- No_Dependence case
5280 if Nkind
(E1
) = N_Parameter_Association
then
5281 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5282 U
:= Explicit_Actual_Parameter
(E1
);
5284 if not OK_No_Dependence_Unit_Name
(U
) then
5285 Set_Boolean_Result
(N
, False);
5289 -- See if there is an entry already in the table. That's the
5290 -- case in which we can return True.
5292 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5293 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5294 and then No_Dependences
.Table
(J
).Warn
= False
5296 Set_Boolean_Result
(N
, True);
5301 -- If not in the No_Dependence table, result is False
5303 Set_Boolean_Result
(N
, False);
5305 -- In this case, we must ensure that the binder will reject any
5306 -- other unit in the partition that sets No_Dependence for this
5307 -- unit. We do that by making an entry in the special table kept
5308 -- for this purpose (if the entry is not there already).
5310 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5312 for J
in Restriction_Set_Dependences
.First
..
5313 Restriction_Set_Dependences
.Last
5315 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5320 Restriction_Set_Dependences
.Append
(Unam
);
5322 -- Normal restriction case
5325 if Nkind
(E1
) /= N_Identifier
then
5326 Set_Boolean_Result
(N
, False);
5327 Error_Attr
("attribute % requires restriction identifier", E1
);
5330 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5332 if R
= Not_A_Restriction_Id
then
5333 Set_Boolean_Result
(N
, False);
5334 Error_Msg_Node_1
:= E1
;
5335 Error_Attr
("invalid restriction identifier &", E1
);
5337 elsif R
not in Partition_Boolean_Restrictions
then
5338 Set_Boolean_Result
(N
, False);
5339 Error_Msg_Node_1
:= E1
;
5341 ("& is not a boolean partition-wide restriction", E1
);
5344 if Restriction_Active
(R
) then
5345 Set_Boolean_Result
(N
, True);
5347 Check_Restriction
(R
, N
);
5348 Set_Boolean_Result
(N
, False);
5352 end Restriction_Set
;
5358 when Attribute_Round
=>
5360 Check_Decimal_Fixed_Point_Type
;
5361 Set_Etype
(N
, P_Base_Type
);
5363 -- Because the context is universal_real (3.5.10(12)) it is a
5364 -- legal context for a universal fixed expression. This is the
5365 -- only attribute whose functional description involves U_R.
5367 if Etype
(E1
) = Universal_Fixed
then
5369 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5370 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5371 Expression
=> Relocate_Node
(E1
));
5379 Resolve
(E1
, Any_Real
);
5385 when Attribute_Rounding
=>
5386 Check_Floating_Point_Type_1
;
5387 Set_Etype
(N
, P_Base_Type
);
5388 Resolve
(E1
, P_Base_Type
);
5394 when Attribute_Safe_Emax
=>
5395 Check_Floating_Point_Type_0
;
5396 Set_Etype
(N
, Universal_Integer
);
5402 when Attribute_Safe_First
=>
5403 Check_Floating_Point_Type_0
;
5404 Set_Etype
(N
, Universal_Real
);
5410 when Attribute_Safe_Large
=>
5413 Set_Etype
(N
, Universal_Real
);
5419 when Attribute_Safe_Last
=>
5420 Check_Floating_Point_Type_0
;
5421 Set_Etype
(N
, Universal_Real
);
5427 when Attribute_Safe_Small
=>
5430 Set_Etype
(N
, Universal_Real
);
5432 --------------------------
5433 -- Scalar_Storage_Order --
5434 --------------------------
5436 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5438 Ent
: Entity_Id
:= Empty
;
5444 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5446 -- In GNAT mode, the attribute applies to generic types as well
5447 -- as composite types, and for non-composite types always returns
5448 -- the default bit order for the target.
5450 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5451 and then not In_Instance
5454 ("prefix of % attribute must be record or array type");
5456 elsif not Is_Generic_Type
(P_Type
) then
5457 if Bytes_Big_Endian
then
5458 Ent
:= RTE
(RE_High_Order_First
);
5460 Ent
:= RTE
(RE_Low_Order_First
);
5464 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5465 Ent
:= RTE
(RE_High_Order_First
);
5468 Ent
:= RTE
(RE_Low_Order_First
);
5471 if Present
(Ent
) then
5472 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5475 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5478 -- Reset incorrect indication of staticness
5480 Set_Is_Static_Expression
(N
, False);
5481 end Scalar_Storage_Order
;
5487 when Attribute_Scale
=>
5489 Check_Decimal_Fixed_Point_Type
;
5490 Set_Etype
(N
, Universal_Integer
);
5496 when Attribute_Scaling
=>
5497 Check_Floating_Point_Type_2
;
5498 Set_Etype
(N
, P_Base_Type
);
5499 Resolve
(E1
, P_Base_Type
);
5505 when Attribute_Signed_Zeros
=>
5506 Check_Floating_Point_Type_0
;
5507 Set_Etype
(N
, Standard_Boolean
);
5513 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5517 -- If prefix is parameterless function call, rewrite and resolve
5520 if Is_Entity_Name
(P
)
5521 and then Ekind
(Entity
(P
)) = E_Function
5525 -- Similar processing for a protected function call
5527 elsif Nkind
(P
) = N_Selected_Component
5528 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5533 if Is_Object_Reference
(P
) then
5534 Check_Object_Reference
(P
);
5536 elsif Is_Entity_Name
(P
)
5537 and then (Is_Type
(Entity
(P
))
5538 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5542 elsif Nkind
(P
) = N_Type_Conversion
5543 and then not Comes_From_Source
(P
)
5547 -- Some other compilers allow dubious use of X'???'Size
5549 elsif Relaxed_RM_Semantics
5550 and then Nkind
(P
) = N_Attribute_Reference
5555 Error_Attr_P
("invalid prefix for % attribute");
5558 Check_Not_Incomplete_Type
;
5560 Set_Etype
(N
, Universal_Integer
);
5567 when Attribute_Small
=>
5570 Set_Etype
(N
, Universal_Real
);
5576 when Attribute_Storage_Pool |
5577 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5581 if Is_Access_Type
(P_Type
) then
5582 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5584 ("cannot use % attribute for access-to-subprogram type");
5587 -- Set appropriate entity
5589 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5590 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5592 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5595 if Attr_Id
= Attribute_Storage_Pool
then
5596 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5597 Name_Simple_Storage_Pool_Type
))
5599 Error_Msg_Name_1
:= Aname
;
5600 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5601 Error_Msg_N
("cannot use % attribute for type with simple "
5602 & "storage pool<<", N
);
5603 Error_Msg_N
("\Program_Error [<<", N
);
5606 (N
, Make_Raise_Program_Error
5607 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5610 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5612 -- In the Simple_Storage_Pool case, verify that the pool entity is
5613 -- actually of a simple storage pool type, and set the attribute's
5614 -- type to the pool object's type.
5617 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5618 Name_Simple_Storage_Pool_Type
))
5621 ("cannot use % attribute for type without simple " &
5625 Set_Etype
(N
, Etype
(Entity
(N
)));
5628 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5629 -- Storage_Pool since this attribute is not defined for such
5630 -- types (RM E.2.3(22)).
5632 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5635 Error_Attr_P
("prefix of % attribute must be access type");
5643 when Attribute_Storage_Size
=> Storage_Size
:
5647 if Is_Task_Type
(P_Type
) then
5648 Set_Etype
(N
, Universal_Integer
);
5650 -- Use with tasks is an obsolescent feature
5652 Check_Restriction
(No_Obsolescent_Features
, P
);
5654 elsif Is_Access_Type
(P_Type
) then
5655 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5657 ("cannot use % attribute for access-to-subprogram type");
5660 if Is_Entity_Name
(P
)
5661 and then Is_Type
(Entity
(P
))
5664 Set_Etype
(N
, Universal_Integer
);
5666 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5667 -- Storage_Size since this attribute is not defined for
5668 -- such types (RM E.2.3(22)).
5670 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5672 -- The prefix is allowed to be an implicit dereference of an
5673 -- access value designating a task.
5677 Set_Etype
(N
, Universal_Integer
);
5681 Error_Attr_P
("prefix of % attribute must be access or task type");
5689 when Attribute_Storage_Unit
=>
5690 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5696 when Attribute_Stream_Size
=>
5700 if Is_Entity_Name
(P
)
5701 and then Is_Elementary_Type
(Entity
(P
))
5703 Set_Etype
(N
, Universal_Integer
);
5705 Error_Attr_P
("invalid prefix for % attribute");
5712 when Attribute_Stub_Type
=>
5716 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5718 -- For a real RACW [sub]type, use corresponding stub type
5720 if not Is_Generic_Type
(P_Type
) then
5723 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5725 -- For a generic type (that has been marked as an RACW using the
5726 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5727 -- type. Note that if the actual is not a remote access type, the
5728 -- instantiation will fail.
5731 -- Note: we go to the underlying type here because the view
5732 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5736 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5741 ("prefix of% attribute must be remote access to classwide");
5748 when Attribute_Succ
=>
5752 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5753 Error_Msg_Name_1
:= Aname
;
5754 Error_Msg_Name_2
:= Chars
(P_Type
);
5755 Check_SPARK_05_Restriction
5756 ("attribute% is not allowed for type%", P
);
5759 Resolve
(E1
, P_Base_Type
);
5760 Set_Etype
(N
, P_Base_Type
);
5762 -- Since Pred works on the base type, we normally do no check for the
5763 -- floating-point case, since the base type is unconstrained. But we
5764 -- make an exception in Check_Float_Overflow mode.
5766 if Is_Floating_Point_Type
(P_Type
) then
5767 if not Range_Checks_Suppressed
(P_Base_Type
) then
5768 Set_Do_Range_Check
(E1
);
5771 -- If not modular type, test for overflow check required
5774 if not Is_Modular_Integer_Type
(P_Type
)
5775 and then not Range_Checks_Suppressed
(P_Base_Type
)
5777 Enable_Range_Check
(E1
);
5781 --------------------------------
5782 -- System_Allocator_Alignment --
5783 --------------------------------
5785 when Attribute_System_Allocator_Alignment
=>
5786 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5792 when Attribute_Tag
=> Tag
:
5797 if not Is_Tagged_Type
(P_Type
) then
5798 Error_Attr_P
("prefix of % attribute must be tagged");
5800 -- Next test does not apply to generated code why not, and what does
5801 -- the illegal reference mean???
5803 elsif Is_Object_Reference
(P
)
5804 and then not Is_Class_Wide_Type
(P_Type
)
5805 and then Comes_From_Source
(N
)
5808 ("% attribute can only be applied to objects " &
5809 "of class - wide type");
5812 -- The prefix cannot be an incomplete type. However, references to
5813 -- 'Tag can be generated when expanding interface conversions, and
5816 if Comes_From_Source
(N
) then
5817 Check_Not_Incomplete_Type
;
5820 -- Set appropriate type
5822 Set_Etype
(N
, RTE
(RE_Tag
));
5829 when Attribute_Target_Name
=> Target_Name
: declare
5830 TN
: constant String := Sdefault
.Target_Name
.all;
5834 Check_Standard_Prefix
;
5838 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
5843 Make_String_Literal
(Loc
,
5844 Strval
=> TN
(TN
'First .. TL
)));
5845 Analyze_And_Resolve
(N
, Standard_String
);
5846 Set_Is_Static_Expression
(N
, True);
5853 when Attribute_Terminated
=>
5855 Set_Etype
(N
, Standard_Boolean
);
5862 when Attribute_To_Address
=> To_Address
: declare
5868 Check_System_Prefix
;
5870 Generate_Reference
(RTE
(RE_Address
), P
);
5871 Analyze_And_Resolve
(E1
, Any_Integer
);
5872 Set_Etype
(N
, RTE
(RE_Address
));
5874 if Is_Static_Expression
(E1
) then
5875 Set_Is_Static_Expression
(N
, True);
5878 -- OK static expression case, check range and set appropriate type
5880 if Is_OK_Static_Expression
(E1
) then
5881 Val
:= Expr_Value
(E1
);
5883 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
5885 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
5887 Error_Attr
("address value out of range for % attribute", E1
);
5890 -- In most cases the expression is a numeric literal or some other
5891 -- address expression, but if it is a declared constant it may be
5892 -- of a compatible type that must be left on the node.
5894 if Is_Entity_Name
(E1
) then
5897 -- Set type to universal integer if negative
5900 Set_Etype
(E1
, Universal_Integer
);
5902 -- Otherwise set type to Unsigned_64 to accomodate max values
5905 Set_Etype
(E1
, Standard_Unsigned_64
);
5909 Set_Is_Static_Expression
(N
, True);
5916 when Attribute_To_Any
=>
5918 Check_PolyORB_Attribute
;
5919 Set_Etype
(N
, RTE
(RE_Any
));
5925 when Attribute_Truncation
=>
5926 Check_Floating_Point_Type_1
;
5927 Resolve
(E1
, P_Base_Type
);
5928 Set_Etype
(N
, P_Base_Type
);
5934 when Attribute_Type_Class
=>
5937 Check_Not_Incomplete_Type
;
5938 Set_Etype
(N
, RTE
(RE_Type_Class
));
5944 when Attribute_TypeCode
=>
5946 Check_PolyORB_Attribute
;
5947 Set_Etype
(N
, RTE
(RE_TypeCode
));
5953 when Attribute_Type_Key
=>
5957 -- This processing belongs in Eval_Attribute ???
5960 function Type_Key
return String_Id
;
5961 -- A very preliminary implementation. For now, a signature
5962 -- consists of only the type name. This is clearly incomplete
5963 -- (e.g., adding a new field to a record type should change the
5964 -- type's Type_Key attribute).
5970 function Type_Key
return String_Id
is
5971 Full_Name
: constant String_Id
:=
5972 Fully_Qualified_Name_String
(Entity
(P
));
5975 -- Copy all characters in Full_Name but the trailing NUL
5978 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5979 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5982 Store_String_Chars
("'Type_Key");
5987 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5990 Analyze_And_Resolve
(N
, Standard_String
);
5996 when Attribute_UET_Address
=>
5998 Check_Unit_Name
(P
);
5999 Set_Etype
(N
, RTE
(RE_Address
));
6001 -----------------------
6002 -- Unbiased_Rounding --
6003 -----------------------
6005 when Attribute_Unbiased_Rounding
=>
6006 Check_Floating_Point_Type_1
;
6007 Set_Etype
(N
, P_Base_Type
);
6008 Resolve
(E1
, P_Base_Type
);
6010 ----------------------
6011 -- Unchecked_Access --
6012 ----------------------
6014 when Attribute_Unchecked_Access
=>
6015 if Comes_From_Source
(N
) then
6016 Check_Restriction
(No_Unchecked_Access
, N
);
6019 Analyze_Access_Attribute
;
6021 -------------------------
6022 -- Unconstrained_Array --
6023 -------------------------
6025 when Attribute_Unconstrained_Array
=>
6028 Check_Not_Incomplete_Type
;
6029 Set_Etype
(N
, Standard_Boolean
);
6030 Set_Is_Static_Expression
(N
, True);
6032 ------------------------------
6033 -- Universal_Literal_String --
6034 ------------------------------
6036 -- This is a GNAT specific attribute whose prefix must be a named
6037 -- number where the expression is either a single numeric literal,
6038 -- or a numeric literal immediately preceded by a minus sign. The
6039 -- result is equivalent to a string literal containing the text of
6040 -- the literal as it appeared in the source program with a possible
6041 -- leading minus sign.
6043 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
6047 if not Is_Entity_Name
(P
)
6048 or else Ekind
(Entity
(P
)) not in Named_Kind
6050 Error_Attr_P
("prefix for % attribute must be named number");
6057 Src
: Source_Buffer_Ptr
;
6060 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6062 if Nkind
(Expr
) = N_Op_Minus
then
6064 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6069 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6071 ("named number for % attribute must be simple literal", N
);
6074 -- Build string literal corresponding to source literal text
6079 Store_String_Char
(Get_Char_Code
('-'));
6083 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6085 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6086 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6090 -- Now we rewrite the attribute with the string literal
6093 Make_String_Literal
(Loc
, End_String
));
6095 Set_Is_Static_Expression
(N
, True);
6098 end Universal_Literal_String
;
6100 -------------------------
6101 -- Unrestricted_Access --
6102 -------------------------
6104 -- This is a GNAT specific attribute which is like Access except that
6105 -- all scope checks and checks for aliased views are omitted. It is
6106 -- documented as being equivalent to the use of the Address attribute
6107 -- followed by an unchecked conversion to the target access type.
6109 when Attribute_Unrestricted_Access
=>
6111 -- If from source, deal with relevant restrictions
6113 if Comes_From_Source
(N
) then
6114 Check_Restriction
(No_Unchecked_Access
, N
);
6116 if Nkind
(P
) in N_Has_Entity
6117 and then Present
(Entity
(P
))
6118 and then Is_Object
(Entity
(P
))
6120 Check_Restriction
(No_Implicit_Aliasing
, N
);
6124 if Is_Entity_Name
(P
) then
6125 Set_Address_Taken
(Entity
(P
));
6128 -- It might seem reasonable to call Address_Checks here to apply the
6129 -- same set of semantic checks that we enforce for 'Address (after
6130 -- all we document Unrestricted_Access as being equivalent to the
6131 -- use of Address followed by an Unchecked_Conversion). However, if
6132 -- we do enable these checks, we get multiple failures in both the
6133 -- compiler run-time and in our regression test suite, so we leave
6134 -- out these checks for now. To be investigated further some time???
6138 -- Now complete analysis using common access processing
6140 Analyze_Access_Attribute
;
6146 when Attribute_Update
=> Update
: declare
6147 Common_Typ
: Entity_Id
;
6148 -- The common type of a multiple component update for a record
6150 Comps
: Elist_Id
:= No_Elist
;
6151 -- A list used in the resolution of a record update. It contains the
6152 -- entities of all record components processed so far.
6154 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6155 -- Analyze and resolve array_component_association Assoc against the
6156 -- index of array type P_Type.
6158 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6159 -- Analyze and resolve record_component_association Comp against
6160 -- record type P_Type.
6162 ------------------------------------
6163 -- Analyze_Array_Component_Update --
6164 ------------------------------------
6166 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6170 Index_Typ
: Entity_Id
;
6174 -- The current association contains a sequence of indexes denoting
6175 -- an element of a multidimensional array:
6177 -- (Index_1, ..., Index_N)
6179 -- Examine each individual index and resolve it against the proper
6180 -- index type of the array.
6182 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6183 Expr
:= First
(Choices
(Assoc
));
6184 while Present
(Expr
) loop
6186 -- The use of others is illegal (SPARK RM 4.4.1(12))
6188 if Nkind
(Expr
) = N_Others_Choice
then
6190 ("others choice not allowed in attribute %", Expr
);
6192 -- Otherwise analyze and resolve all indexes
6195 Index
:= First
(Expressions
(Expr
));
6196 Index_Typ
:= First_Index
(P_Type
);
6197 while Present
(Index
) and then Present
(Index_Typ
) loop
6198 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6200 Next_Index
(Index_Typ
);
6203 -- Detect a case where the association either lacks an
6204 -- index or contains an extra index.
6206 if Present
(Index
) or else Present
(Index_Typ
) then
6208 ("dimension mismatch in index list", Assoc
);
6215 -- The current association denotes either a single component or a
6216 -- range of components of a one dimensional array:
6220 -- Resolve the index or its high and low bounds (if range) against
6221 -- the proper index type of the array.
6224 Index
:= First
(Choices
(Assoc
));
6225 Index_Typ
:= First_Index
(P_Type
);
6227 if Present
(Next_Index
(Index_Typ
)) then
6228 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6231 while Present
(Index
) loop
6233 -- The use of others is illegal (SPARK RM 4.4.1(12))
6235 if Nkind
(Index
) = N_Others_Choice
then
6237 ("others choice not allowed in attribute %", Index
);
6239 -- The index denotes a range of elements
6241 elsif Nkind
(Index
) = N_Range
then
6242 Low
:= Low_Bound
(Index
);
6243 High
:= High_Bound
(Index
);
6245 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6246 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6248 -- Add a range check to ensure that the bounds of the
6249 -- range are within the index type when this cannot be
6250 -- determined statically.
6252 if not Is_OK_Static_Expression
(Low
) then
6253 Set_Do_Range_Check
(Low
);
6256 if not Is_OK_Static_Expression
(High
) then
6257 Set_Do_Range_Check
(High
);
6260 -- Otherwise the index denotes a single element
6263 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6265 -- Add a range check to ensure that the index is within
6266 -- the index type when it is not possible to determine
6269 if not Is_OK_Static_Expression
(Index
) then
6270 Set_Do_Range_Check
(Index
);
6277 end Analyze_Array_Component_Update
;
6279 -------------------------------------
6280 -- Analyze_Record_Component_Update --
6281 -------------------------------------
6283 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6284 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6285 Base_Typ
: Entity_Id
;
6286 Comp_Or_Discr
: Entity_Id
;
6289 -- Find the discriminant or component whose name corresponds to
6290 -- Comp. A simple character comparison is sufficient because all
6291 -- visible names within a record type are unique.
6293 Comp_Or_Discr
:= First_Entity
(P_Type
);
6294 while Present
(Comp_Or_Discr
) loop
6295 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6297 -- Decorate the component reference by setting its entity
6298 -- and type for resolution purposes.
6300 Set_Entity
(Comp
, Comp_Or_Discr
);
6301 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6305 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6308 -- Diagnose an illegal reference
6310 if Present
(Comp_Or_Discr
) then
6311 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6313 ("attribute % may not modify record discriminants", Comp
);
6315 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6316 if Contains
(Comps
, Comp_Or_Discr
) then
6317 Error_Msg_N
("component & already updated", Comp
);
6319 -- Mark this component as processed
6322 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6326 -- The update aggregate mentions an entity that does not belong to
6330 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6333 -- Verify the consistency of types when the current component is
6334 -- part of a miltiple component update.
6336 -- Comp_1, ..., Comp_N => <value>
6338 if Present
(Etype
(Comp
)) then
6339 Base_Typ
:= Base_Type
(Etype
(Comp
));
6341 -- Save the type of the first component reference as the
6342 -- remaning references (if any) must resolve to this type.
6344 if No
(Common_Typ
) then
6345 Common_Typ
:= Base_Typ
;
6347 elsif Base_Typ
/= Common_Typ
then
6349 ("components in choice list must have same type", Comp
);
6352 end Analyze_Record_Component_Update
;
6359 -- Start of processing for Update
6364 if not Is_Object_Reference
(P
) then
6365 Error_Attr_P
("prefix of attribute % must denote an object");
6367 elsif not Is_Array_Type
(P_Type
)
6368 and then not Is_Record_Type
(P_Type
)
6370 Error_Attr_P
("prefix of attribute % must be a record or array");
6372 elsif Is_Limited_View
(P_Type
) then
6373 Error_Attr
("prefix of attribute % cannot be limited", N
);
6375 elsif Nkind
(E1
) /= N_Aggregate
then
6376 Error_Attr
("attribute % requires component association list", N
);
6379 -- Inspect the update aggregate, looking at all the associations and
6380 -- choices. Perform the following checks:
6382 -- 1) Legality of "others" in all cases
6383 -- 2) Legality of <>
6384 -- 3) Component legality for arrays
6385 -- 4) Component legality for records
6387 -- The remaining checks are performed on the expanded attribute
6389 Assoc
:= First
(Component_Associations
(E1
));
6390 while Present
(Assoc
) loop
6392 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6394 if Box_Present
(Assoc
) then
6396 ("default initialization not allowed in attribute %", Assoc
);
6398 -- Otherwise process the association
6401 Analyze
(Expression
(Assoc
));
6403 if Is_Array_Type
(P_Type
) then
6404 Analyze_Array_Component_Update
(Assoc
);
6406 elsif Is_Record_Type
(P_Type
) then
6408 -- Reset the common type used in a multiple component update
6409 -- as we are processing the contents of a new association.
6411 Common_Typ
:= Empty
;
6413 Comp
:= First
(Choices
(Assoc
));
6414 while Present
(Comp
) loop
6415 if Nkind
(Comp
) = N_Identifier
then
6416 Analyze_Record_Component_Update
(Comp
);
6418 -- The use of others is illegal (SPARK RM 4.4.1(5))
6420 elsif Nkind
(Comp
) = N_Others_Choice
then
6422 ("others choice not allowed in attribute %", Comp
);
6424 -- The name of a record component cannot appear in any
6429 ("name should be identifier or OTHERS", Comp
);
6440 -- The type of attribute 'Update is that of the prefix
6442 Set_Etype
(N
, P_Type
);
6449 when Attribute_Val
=> Val
: declare
6452 Check_Discrete_Type
;
6454 if Is_Boolean_Type
(P_Type
) then
6455 Error_Msg_Name_1
:= Aname
;
6456 Error_Msg_Name_2
:= Chars
(P_Type
);
6457 Check_SPARK_05_Restriction
6458 ("attribute% is not allowed for type%", P
);
6461 Resolve
(E1
, Any_Integer
);
6462 Set_Etype
(N
, P_Base_Type
);
6464 -- Note, we need a range check in general, but we wait for the
6465 -- Resolve call to do this, since we want to let Eval_Attribute
6466 -- have a chance to find an static illegality first.
6473 when Attribute_Valid
=>
6476 -- Ignore check for object if we have a 'Valid reference generated
6477 -- by the expanded code, since in some cases valid checks can occur
6478 -- on items that are names, but are not objects (e.g. attributes).
6480 if Comes_From_Source
(N
) then
6481 Check_Object_Reference
(P
);
6484 if not Is_Scalar_Type
(P_Type
) then
6485 Error_Attr_P
("object for % attribute must be of scalar type");
6488 -- If the attribute appears within the subtype's own predicate
6489 -- function, then issue a warning that this will cause infinite
6493 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6496 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6498 ("attribute Valid requires a predicate check??", N
);
6499 Error_Msg_N
("\and will result in infinite recursion??", N
);
6503 Set_Etype
(N
, Standard_Boolean
);
6509 when Attribute_Valid_Scalars
=>
6511 Check_Object_Reference
(P
);
6512 Set_Etype
(N
, Standard_Boolean
);
6514 -- Following checks are only for source types
6516 if Comes_From_Source
(N
) then
6517 if not Scalar_Part_Present
(P_Type
) then
6519 ("??attribute % always True, no scalars to check");
6522 -- Not allowed for unchecked union type
6524 if Has_Unchecked_Union
(P_Type
) then
6526 ("attribute % not allowed for Unchecked_Union type");
6534 when Attribute_Value
=> Value
:
6536 Check_SPARK_05_Restriction_On_Attribute
;
6540 -- Case of enumeration type
6542 -- When an enumeration type appears in an attribute reference, all
6543 -- literals of the type are marked as referenced. This must only be
6544 -- done if the attribute reference appears in the current source.
6545 -- Otherwise the information on references may differ between a
6546 -- normal compilation and one that performs inlining.
6548 if Is_Enumeration_Type
(P_Type
)
6549 and then In_Extended_Main_Code_Unit
(N
)
6551 Check_Restriction
(No_Enumeration_Maps
, N
);
6553 -- Mark all enumeration literals as referenced, since the use of
6554 -- the Value attribute can implicitly reference any of the
6555 -- literals of the enumeration base type.
6558 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6560 while Present
(Ent
) loop
6561 Set_Referenced
(Ent
);
6567 -- Set Etype before resolving expression because expansion of
6568 -- expression may require enclosing type. Note that the type
6569 -- returned by 'Value is the base type of the prefix type.
6571 Set_Etype
(N
, P_Base_Type
);
6572 Validate_Non_Static_Attribute_Function_Call
;
6574 -- Check restriction No_Fixed_IO
6576 if Restriction_Check_Required
(No_Fixed_IO
)
6577 and then Is_Fixed_Point_Type
(P_Type
)
6579 Check_Restriction
(No_Fixed_IO
, P
);
6587 when Attribute_Value_Size
=>
6590 Check_Not_Incomplete_Type
;
6591 Set_Etype
(N
, Universal_Integer
);
6597 when Attribute_Version
=>
6600 Set_Etype
(N
, RTE
(RE_Version_String
));
6606 when Attribute_Wchar_T_Size
=>
6607 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6613 when Attribute_Wide_Image
=> Wide_Image
:
6615 Check_SPARK_05_Restriction_On_Attribute
;
6617 Set_Etype
(N
, Standard_Wide_String
);
6619 Resolve
(E1
, P_Base_Type
);
6620 Validate_Non_Static_Attribute_Function_Call
;
6622 -- Check restriction No_Fixed_IO
6624 if Restriction_Check_Required
(No_Fixed_IO
)
6625 and then Is_Fixed_Point_Type
(P_Type
)
6627 Check_Restriction
(No_Fixed_IO
, P
);
6631 ---------------------
6632 -- Wide_Wide_Image --
6633 ---------------------
6635 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
6638 Set_Etype
(N
, Standard_Wide_Wide_String
);
6640 Resolve
(E1
, P_Base_Type
);
6641 Validate_Non_Static_Attribute_Function_Call
;
6643 -- Check restriction No_Fixed_IO
6645 if Restriction_Check_Required
(No_Fixed_IO
)
6646 and then Is_Fixed_Point_Type
(P_Type
)
6648 Check_Restriction
(No_Fixed_IO
, P
);
6650 end Wide_Wide_Image
;
6656 when Attribute_Wide_Value
=> Wide_Value
:
6658 Check_SPARK_05_Restriction_On_Attribute
;
6662 -- Set Etype before resolving expression because expansion
6663 -- of expression may require enclosing type.
6665 Set_Etype
(N
, P_Type
);
6666 Validate_Non_Static_Attribute_Function_Call
;
6668 -- Check restriction No_Fixed_IO
6670 if Restriction_Check_Required
(No_Fixed_IO
)
6671 and then Is_Fixed_Point_Type
(P_Type
)
6673 Check_Restriction
(No_Fixed_IO
, P
);
6677 ---------------------
6678 -- Wide_Wide_Value --
6679 ---------------------
6681 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6686 -- Set Etype before resolving expression because expansion
6687 -- of expression may require enclosing type.
6689 Set_Etype
(N
, P_Type
);
6690 Validate_Non_Static_Attribute_Function_Call
;
6692 -- Check restriction No_Fixed_IO
6694 if Restriction_Check_Required
(No_Fixed_IO
)
6695 and then Is_Fixed_Point_Type
(P_Type
)
6697 Check_Restriction
(No_Fixed_IO
, P
);
6699 end Wide_Wide_Value
;
6701 ---------------------
6702 -- Wide_Wide_Width --
6703 ---------------------
6705 when Attribute_Wide_Wide_Width
=>
6708 Set_Etype
(N
, Universal_Integer
);
6714 when Attribute_Wide_Width
=>
6715 Check_SPARK_05_Restriction_On_Attribute
;
6718 Set_Etype
(N
, Universal_Integer
);
6724 when Attribute_Width
=>
6725 Check_SPARK_05_Restriction_On_Attribute
;
6728 Set_Etype
(N
, Universal_Integer
);
6734 when Attribute_Word_Size
=>
6735 Standard_Attribute
(System_Word_Size
);
6741 when Attribute_Write
=>
6743 Check_Stream_Attribute
(TSS_Stream_Write
);
6744 Set_Etype
(N
, Standard_Void_Type
);
6745 Resolve
(N
, Standard_Void_Type
);
6749 -- All errors raise Bad_Attribute, so that we get out before any further
6750 -- damage occurs when an error is detected (for example, if we check for
6751 -- one attribute expression, and the check succeeds, we want to be able
6752 -- to proceed securely assuming that an expression is in fact present.
6754 -- Note: we set the attribute analyzed in this case to prevent any
6755 -- attempt at reanalysis which could generate spurious error msgs.
6758 when Bad_Attribute
=>
6760 Set_Etype
(N
, Any_Type
);
6762 end Analyze_Attribute
;
6764 --------------------
6765 -- Eval_Attribute --
6766 --------------------
6768 procedure Eval_Attribute
(N
: Node_Id
) is
6769 Loc
: constant Source_Ptr
:= Sloc
(N
);
6770 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6771 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6772 P
: constant Node_Id
:= Prefix
(N
);
6774 C_Type
: constant Entity_Id
:= Etype
(N
);
6775 -- The type imposed by the context
6778 -- First expression, or Empty if none
6781 -- Second expression, or Empty if none
6783 P_Entity
: Entity_Id
;
6784 -- Entity denoted by prefix
6787 -- The type of the prefix
6789 P_Base_Type
: Entity_Id
;
6790 -- The base type of the prefix type
6792 P_Root_Type
: Entity_Id
;
6793 -- The root type of the prefix type
6796 -- True if the result is Static. This is set by the general processing
6797 -- to true if the prefix is static, and all expressions are static. It
6798 -- can be reset as processing continues for particular attributes. This
6799 -- flag can still be True if the reference raises a constraint error.
6800 -- Is_Static_Expression (N) is set to follow this value as it is set
6801 -- and we could always reference this, but it is convenient to have a
6802 -- simple short name to use, since it is frequently referenced.
6804 Lo_Bound
, Hi_Bound
: Node_Id
;
6805 -- Expressions for low and high bounds of type or array index referenced
6806 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6809 -- Constraint error node used if we have an attribute reference has
6810 -- an argument that raises a constraint error. In this case we replace
6811 -- the attribute with a raise constraint_error node. This is important
6812 -- processing, since otherwise gigi might see an attribute which it is
6813 -- unprepared to deal with.
6815 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
6816 -- If Bound is a reference to a discriminant of a task or protected type
6817 -- occurring within the object's body, rewrite attribute reference into
6818 -- a reference to the corresponding discriminal. Use for the expansion
6819 -- of checks against bounds of entry family index subtypes.
6821 procedure Check_Expressions
;
6822 -- In case where the attribute is not foldable, the expressions, if
6823 -- any, of the attribute, are in a non-static context. This procedure
6824 -- performs the required additional checks.
6826 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
6827 -- Determines if the given type has compile time known bounds. Note
6828 -- that we enter the case statement even in cases where the prefix
6829 -- type does NOT have known bounds, so it is important to guard any
6830 -- attempt to evaluate both bounds with a call to this function.
6832 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
6833 -- This procedure is called when the attribute N has a non-static
6834 -- but compile time known value given by Val. It includes the
6835 -- necessary checks for out of range values.
6837 function Fore_Value
return Nat
;
6838 -- Computes the Fore value for the current attribute prefix, which is
6839 -- known to be a static fixed-point type. Used by Fore and Width.
6841 function Mantissa
return Uint
;
6842 -- Returns the Mantissa value for the prefix type
6844 procedure Set_Bounds
;
6845 -- Used for First, Last and Length attributes applied to an array or
6846 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6847 -- and high bound expressions for the index referenced by the attribute
6848 -- designator (i.e. the first index if no expression is present, and the
6849 -- N'th index if the value N is present as an expression). Also used for
6850 -- First and Last of scalar types and for First_Valid and Last_Valid.
6851 -- Static is reset to False if the type or index type is not statically
6854 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
6855 -- Verify that the prefix of a potentially static array attribute
6856 -- satisfies the conditions of 4.9 (14).
6858 -----------------------------------
6859 -- Check_Concurrent_Discriminant --
6860 -----------------------------------
6862 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
6864 -- The concurrent (task or protected) type
6867 if Nkind
(Bound
) = N_Identifier
6868 and then Ekind
(Entity
(Bound
)) = E_Discriminant
6869 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
6871 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
6873 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
6875 -- Find discriminant of original concurrent type, and use
6876 -- its current discriminal, which is the renaming within
6877 -- the task/protected body.
6881 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
6884 end Check_Concurrent_Discriminant
;
6886 -----------------------
6887 -- Check_Expressions --
6888 -----------------------
6890 procedure Check_Expressions
is
6894 while Present
(E
) loop
6895 Check_Non_Static_Context
(E
);
6898 end Check_Expressions
;
6900 ----------------------------------
6901 -- Compile_Time_Known_Attribute --
6902 ----------------------------------
6904 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
6905 T
: constant Entity_Id
:= Etype
(N
);
6908 Fold_Uint
(N
, Val
, False);
6910 -- Check that result is in bounds of the type if it is static
6912 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
6915 elsif Is_Out_Of_Range
(N
, T
) then
6916 Apply_Compile_Time_Constraint_Error
6917 (N
, "value not in range of}??", CE_Range_Check_Failed
);
6919 elsif not Range_Checks_Suppressed
(T
) then
6920 Enable_Range_Check
(N
);
6923 Set_Do_Range_Check
(N
, False);
6925 end Compile_Time_Known_Attribute
;
6927 -------------------------------
6928 -- Compile_Time_Known_Bounds --
6929 -------------------------------
6931 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
6934 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
6936 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
6937 end Compile_Time_Known_Bounds
;
6943 -- Note that the Fore calculation is based on the actual values
6944 -- of the bounds, and does not take into account possible rounding.
6946 function Fore_Value
return Nat
is
6947 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
6948 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
6949 Small
: constant Ureal
:= Small_Value
(P_Type
);
6950 Lo_Real
: constant Ureal
:= Lo
* Small
;
6951 Hi_Real
: constant Ureal
:= Hi
* Small
;
6956 -- Bounds are given in terms of small units, so first compute
6957 -- proper values as reals.
6959 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
6962 -- Loop to compute proper value if more than one digit required
6964 while T
>= Ureal_10
loop
6976 -- Table of mantissa values accessed by function Computed using
6979 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6981 -- where D is T'Digits (RM83 3.5.7)
6983 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7025 function Mantissa
return Uint
is
7028 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7035 procedure Set_Bounds
is
7041 -- For a string literal subtype, we have to construct the bounds.
7042 -- Valid Ada code never applies attributes to string literals, but
7043 -- it is convenient to allow the expander to generate attribute
7044 -- references of this type (e.g. First and Last applied to a string
7047 -- Note that the whole point of the E_String_Literal_Subtype is to
7048 -- avoid this construction of bounds, but the cases in which we
7049 -- have to materialize them are rare enough that we don't worry.
7051 -- The low bound is simply the low bound of the base type. The
7052 -- high bound is computed from the length of the string and this
7055 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7056 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7057 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7060 Make_Integer_Literal
(Sloc
(P
),
7062 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7064 Set_Parent
(Hi_Bound
, P
);
7065 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7068 -- For non-array case, just get bounds of scalar type
7070 elsif Is_Scalar_Type
(P_Type
) then
7073 -- For a fixed-point type, we must freeze to get the attributes
7074 -- of the fixed-point type set now so we can reference them.
7076 if Is_Fixed_Point_Type
(P_Type
)
7077 and then not Is_Frozen
(Base_Type
(P_Type
))
7078 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7079 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7081 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7084 -- For array case, get type of proper index
7090 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7093 Indx
:= First_Index
(P_Type
);
7094 for J
in 1 .. Ndim
- 1 loop
7098 -- If no index type, get out (some other error occurred, and
7099 -- we don't have enough information to complete the job).
7107 Ityp
:= Etype
(Indx
);
7110 -- A discrete range in an index constraint is allowed to be a
7111 -- subtype indication. This is syntactically a pain, but should
7112 -- not propagate to the entity for the corresponding index subtype.
7113 -- After checking that the subtype indication is legal, the range
7114 -- of the subtype indication should be transfered to the entity.
7115 -- The attributes for the bounds should remain the simple retrievals
7116 -- that they are now.
7118 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7119 Hi_Bound
:= Type_High_Bound
(Ityp
);
7121 -- If subtype is non-static, result is definitely non-static
7123 if not Is_Static_Subtype
(Ityp
) then
7125 Set_Is_Static_Expression
(N
, False);
7127 -- Subtype is static, does it raise CE?
7129 elsif not Is_OK_Static_Subtype
(Ityp
) then
7130 Set_Raises_Constraint_Error
(N
);
7134 -------------------------------
7135 -- Statically_Denotes_Entity --
7136 -------------------------------
7138 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7142 if not Is_Entity_Name
(N
) then
7149 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7150 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7151 end Statically_Denotes_Entity
;
7153 -- Start of processing for Eval_Attribute
7156 -- Initialize result as non-static, will be reset if appropriate
7158 Set_Is_Static_Expression
(N
, False);
7161 -- Acquire first two expressions (at the moment, no attributes take more
7162 -- than two expressions in any case).
7164 if Present
(Expressions
(N
)) then
7165 E1
:= First
(Expressions
(N
));
7172 -- Special processing for Enabled attribute. This attribute has a very
7173 -- special prefix, and the easiest way to avoid lots of special checks
7174 -- to protect this special prefix from causing trouble is to deal with
7175 -- this attribute immediately and be done with it.
7177 if Id
= Attribute_Enabled
then
7179 -- We skip evaluation if the expander is not active. This is not just
7180 -- an optimization. It is of key importance that we not rewrite the
7181 -- attribute in a generic template, since we want to pick up the
7182 -- setting of the check in the instance, and testing expander active
7183 -- is as easy way of doing this as any.
7185 if Expander_Active
then
7187 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7192 if C
in Predefined_Check_Id
then
7193 R
:= Scope_Suppress
.Suppress
(C
);
7195 R
:= Is_Check_Suppressed
(Empty
, C
);
7199 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7202 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7209 -- Special processing for cases where the prefix is an object. For
7210 -- this purpose, a string literal counts as an object (attributes
7211 -- of string literals can only appear in generated code).
7213 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7215 -- For Component_Size, the prefix is an array object, and we apply
7216 -- the attribute to the type of the object. This is allowed for
7217 -- both unconstrained and constrained arrays, since the bounds
7218 -- have no influence on the value of this attribute.
7220 if Id
= Attribute_Component_Size
then
7221 P_Entity
:= Etype
(P
);
7223 -- For First and Last, the prefix is an array object, and we apply
7224 -- the attribute to the type of the array, but we need a constrained
7225 -- type for this, so we use the actual subtype if available.
7227 elsif Id
= Attribute_First
or else
7228 Id
= Attribute_Last
or else
7229 Id
= Attribute_Length
7232 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7235 if Present
(AS
) and then Is_Constrained
(AS
) then
7238 -- If we have an unconstrained type we cannot fold
7246 -- For Size, give size of object if available, otherwise we
7247 -- cannot fold Size.
7249 elsif Id
= Attribute_Size
then
7250 if Is_Entity_Name
(P
)
7251 and then Known_Esize
(Entity
(P
))
7253 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7261 -- For Alignment, give size of object if available, otherwise we
7262 -- cannot fold Alignment.
7264 elsif Id
= Attribute_Alignment
then
7265 if Is_Entity_Name
(P
)
7266 and then Known_Alignment
(Entity
(P
))
7268 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7276 -- For Lock_Free, we apply the attribute to the type of the object.
7277 -- This is allowed since we have already verified that the type is a
7280 elsif Id
= Attribute_Lock_Free
then
7281 P_Entity
:= Etype
(P
);
7283 -- No other attributes for objects are folded
7290 -- Cases where P is not an object. Cannot do anything if P is not the
7291 -- name of an entity.
7293 elsif not Is_Entity_Name
(P
) then
7297 -- Otherwise get prefix entity
7300 P_Entity
:= Entity
(P
);
7303 -- If we are asked to evaluate an attribute where the prefix is a
7304 -- non-frozen generic actual type whose RM_Size is still set to zero,
7305 -- then abandon the effort.
7307 if Is_Type
(P_Entity
)
7308 and then (not Is_Frozen
(P_Entity
)
7309 and then Is_Generic_Actual_Type
(P_Entity
)
7310 and then RM_Size
(P_Entity
) = 0)
7312 -- However, the attribute Unconstrained_Array must be evaluated,
7313 -- since it is documented to be a static attribute (and can for
7314 -- example appear in a Compile_Time_Warning pragma). The frozen
7315 -- status of the type does not affect its evaluation.
7317 and then Id
/= Attribute_Unconstrained_Array
7322 -- At this stage P_Entity is the entity to which the attribute
7323 -- is to be applied. This is usually simply the entity of the
7324 -- prefix, except in some cases of attributes for objects, where
7325 -- as described above, we apply the attribute to the object type.
7327 -- Here is where we make sure that static attributes are properly
7328 -- marked as such. These are attributes whose prefix is a static
7329 -- scalar subtype, whose result is scalar, and whose arguments, if
7330 -- present, are static scalar expressions. Note that such references
7331 -- are static expressions even if they raise Constraint_Error.
7333 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7334 -- though evaluating it raises constraint error. This means that a
7335 -- declaration like:
7337 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7339 -- is legal, since here this expression appears in a statically
7340 -- unevaluated position, so it does not actually raise an exception.
7342 if Is_Scalar_Type
(P_Entity
)
7343 and then (not Is_Generic_Type
(P_Entity
))
7344 and then Is_Static_Subtype
(P_Entity
)
7345 and then Is_Scalar_Type
(Etype
(N
))
7348 or else (Is_Static_Expression
(E1
)
7349 and then Is_Scalar_Type
(Etype
(E1
))))
7352 or else (Is_Static_Expression
(E2
)
7353 and then Is_Scalar_Type
(Etype
(E1
))))
7356 Set_Is_Static_Expression
(N
, True);
7359 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7360 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7361 -- Note we allow non-static non-generic types at this stage as further
7364 if Is_Type
(P_Entity
)
7365 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7366 and then (not Is_Generic_Type
(P_Entity
))
7370 -- Second foldable possibility is an array object (RM 4.9(8))
7372 elsif (Ekind
(P_Entity
) = E_Variable
7374 Ekind
(P_Entity
) = E_Constant
)
7375 and then Is_Array_Type
(Etype
(P_Entity
))
7376 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7378 P_Type
:= Etype
(P_Entity
);
7380 -- If the entity is an array constant with an unconstrained nominal
7381 -- subtype then get the type from the initial value. If the value has
7382 -- been expanded into assignments, there is no expression and the
7383 -- attribute reference remains dynamic.
7385 -- We could do better here and retrieve the type ???
7387 if Ekind
(P_Entity
) = E_Constant
7388 and then not Is_Constrained
(P_Type
)
7390 if No
(Constant_Value
(P_Entity
)) then
7393 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7397 -- Definite must be folded if the prefix is not a generic type, that
7398 -- is to say if we are within an instantiation. Same processing applies
7399 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7400 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7402 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7403 Id
= Attribute_Definite
or else
7404 Id
= Attribute_Has_Access_Values
or else
7405 Id
= Attribute_Has_Discriminants
or else
7406 Id
= Attribute_Has_Tagged_Values
or else
7407 Id
= Attribute_Lock_Free
or else
7408 Id
= Attribute_Type_Class
or else
7409 Id
= Attribute_Unconstrained_Array
or else
7410 Id
= Attribute_Max_Alignment_For_Allocation
)
7411 and then not Is_Generic_Type
(P_Entity
)
7415 -- We can fold 'Size applied to a type if the size is known (as happens
7416 -- for a size from an attribute definition clause). At this stage, this
7417 -- can happen only for types (e.g. record types) for which the size is
7418 -- always non-static. We exclude generic types from consideration (since
7419 -- they have bogus sizes set within templates).
7421 elsif Id
= Attribute_Size
7422 and then Is_Type
(P_Entity
)
7423 and then (not Is_Generic_Type
(P_Entity
))
7424 and then Known_Static_RM_Size
(P_Entity
)
7426 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7429 -- We can fold 'Alignment applied to a type if the alignment is known
7430 -- (as happens for an alignment from an attribute definition clause).
7431 -- At this stage, this can happen only for types (e.g. record types) for
7432 -- which the size is always non-static. We exclude generic types from
7433 -- consideration (since they have bogus sizes set within templates).
7435 elsif Id
= Attribute_Alignment
7436 and then Is_Type
(P_Entity
)
7437 and then (not Is_Generic_Type
(P_Entity
))
7438 and then Known_Alignment
(P_Entity
)
7440 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7443 -- If this is an access attribute that is known to fail accessibility
7444 -- check, rewrite accordingly.
7446 elsif Attribute_Name
(N
) = Name_Access
7447 and then Raises_Constraint_Error
(N
)
7450 Make_Raise_Program_Error
(Loc
,
7451 Reason
=> PE_Accessibility_Check_Failed
));
7452 Set_Etype
(N
, C_Type
);
7455 -- No other cases are foldable (they certainly aren't static, and at
7456 -- the moment we don't try to fold any cases other than the ones above).
7463 -- If either attribute or the prefix is Any_Type, then propagate
7464 -- Any_Type to the result and don't do anything else at all.
7466 if P_Type
= Any_Type
7467 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7468 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7470 Set_Etype
(N
, Any_Type
);
7474 -- Scalar subtype case. We have not yet enforced the static requirement
7475 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7476 -- of non-static attribute references (e.g. S'Digits for a non-static
7477 -- floating-point type, which we can compute at compile time).
7479 -- Note: this folding of non-static attributes is not simply a case of
7480 -- optimization. For many of the attributes affected, Gigi cannot handle
7481 -- the attribute and depends on the front end having folded them away.
7483 -- Note: although we don't require staticness at this stage, we do set
7484 -- the Static variable to record the staticness, for easy reference by
7485 -- those attributes where it matters (e.g. Succ and Pred), and also to
7486 -- be used to ensure that non-static folded things are not marked as
7487 -- being static (a check that is done right at the end).
7489 P_Root_Type
:= Root_Type
(P_Type
);
7490 P_Base_Type
:= Base_Type
(P_Type
);
7492 -- If the root type or base type is generic, then we cannot fold. This
7493 -- test is needed because subtypes of generic types are not always
7494 -- marked as being generic themselves (which seems odd???)
7496 if Is_Generic_Type
(P_Root_Type
)
7497 or else Is_Generic_Type
(P_Base_Type
)
7502 if Is_Scalar_Type
(P_Type
) then
7503 if not Is_Static_Subtype
(P_Type
) then
7505 Set_Is_Static_Expression
(N
, False);
7506 elsif not Is_OK_Static_Subtype
(P_Type
) then
7507 Set_Raises_Constraint_Error
(N
);
7510 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7511 -- since we can't do anything with unconstrained arrays. In addition,
7512 -- only the First, Last and Length attributes are possibly static.
7514 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7515 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7516 -- Unconstrained_Array are again exceptions, because they apply as well
7517 -- to unconstrained types.
7519 -- In addition Component_Size is an exception since it is possibly
7520 -- foldable, even though it is never static, and it does apply to
7521 -- unconstrained arrays. Furthermore, it is essential to fold this
7522 -- in the packed case, since otherwise the value will be incorrect.
7524 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7525 Id
= Attribute_Definite
or else
7526 Id
= Attribute_Has_Access_Values
or else
7527 Id
= Attribute_Has_Discriminants
or else
7528 Id
= Attribute_Has_Tagged_Values
or else
7529 Id
= Attribute_Lock_Free
or else
7530 Id
= Attribute_Type_Class
or else
7531 Id
= Attribute_Unconstrained_Array
or else
7532 Id
= Attribute_Component_Size
7535 Set_Is_Static_Expression
(N
, False);
7537 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7538 if not Is_Constrained
(P_Type
)
7539 or else (Id
/= Attribute_First
and then
7540 Id
/= Attribute_Last
and then
7541 Id
/= Attribute_Length
)
7547 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7548 -- scalar case, we hold off on enforcing staticness, since there are
7549 -- cases which we can fold at compile time even though they are not
7550 -- static (e.g. 'Length applied to a static index, even though other
7551 -- non-static indexes make the array type non-static). This is only
7552 -- an optimization, but it falls out essentially free, so why not.
7553 -- Again we compute the variable Static for easy reference later
7554 -- (note that no array attributes are static in Ada 83).
7556 -- We also need to set Static properly for subsequent legality checks
7557 -- which might otherwise accept non-static constants in contexts
7558 -- where they are not legal.
7561 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
7562 Set_Is_Static_Expression
(N
, Static
);
7568 Nod
:= First_Index
(P_Type
);
7570 -- The expression is static if the array type is constrained
7571 -- by given bounds, and not by an initial expression. Constant
7572 -- strings are static in any case.
7574 if Root_Type
(P_Type
) /= Standard_String
then
7576 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
7577 Set_Is_Static_Expression
(N
, Static
);
7580 while Present
(Nod
) loop
7581 if not Is_Static_Subtype
(Etype
(Nod
)) then
7583 Set_Is_Static_Expression
(N
, False);
7585 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
7586 Set_Raises_Constraint_Error
(N
);
7588 Set_Is_Static_Expression
(N
, False);
7591 -- If however the index type is generic, or derived from
7592 -- one, attributes cannot be folded.
7594 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
7595 and then Id
/= Attribute_Component_Size
7605 -- Check any expressions that are present. Note that these expressions,
7606 -- depending on the particular attribute type, are either part of the
7607 -- attribute designator, or they are arguments in a case where the
7608 -- attribute reference returns a function. In the latter case, the
7609 -- rule in (RM 4.9(22)) applies and in particular requires the type
7610 -- of the expressions to be scalar in order for the attribute to be
7611 -- considered to be static.
7619 while Present
(E
) loop
7621 -- If expression is not static, then the attribute reference
7622 -- result certainly cannot be static.
7624 if not Is_Static_Expression
(E
) then
7626 Set_Is_Static_Expression
(N
, False);
7629 if Raises_Constraint_Error
(E
) then
7630 Set_Raises_Constraint_Error
(N
);
7633 -- If the result is not known at compile time, or is not of
7634 -- a scalar type, then the result is definitely not static,
7635 -- so we can quit now.
7637 if not Compile_Time_Known_Value
(E
)
7638 or else not Is_Scalar_Type
(Etype
(E
))
7640 -- An odd special case, if this is a Pos attribute, this
7641 -- is where we need to apply a range check since it does
7642 -- not get done anywhere else.
7644 if Id
= Attribute_Pos
then
7645 if Is_Integer_Type
(Etype
(E
)) then
7646 Apply_Range_Check
(E
, Etype
(N
));
7653 -- If the expression raises a constraint error, then so does
7654 -- the attribute reference. We keep going in this case because
7655 -- we are still interested in whether the attribute reference
7656 -- is static even if it is not static.
7658 elsif Raises_Constraint_Error
(E
) then
7659 Set_Raises_Constraint_Error
(N
);
7665 if Raises_Constraint_Error
(Prefix
(N
)) then
7666 Set_Is_Static_Expression
(N
, False);
7671 -- Deal with the case of a static attribute reference that raises
7672 -- constraint error. The Raises_Constraint_Error flag will already
7673 -- have been set, and the Static flag shows whether the attribute
7674 -- reference is static. In any case we certainly can't fold such an
7675 -- attribute reference.
7677 -- Note that the rewriting of the attribute node with the constraint
7678 -- error node is essential in this case, because otherwise Gigi might
7679 -- blow up on one of the attributes it never expects to see.
7681 -- The constraint_error node must have the type imposed by the context,
7682 -- to avoid spurious errors in the enclosing expression.
7684 if Raises_Constraint_Error
(N
) then
7686 Make_Raise_Constraint_Error
(Sloc
(N
),
7687 Reason
=> CE_Range_Check_Failed
);
7688 Set_Etype
(CE_Node
, Etype
(N
));
7689 Set_Raises_Constraint_Error
(CE_Node
);
7691 Rewrite
(N
, Relocate_Node
(CE_Node
));
7692 Set_Raises_Constraint_Error
(N
, True);
7696 -- At this point we have a potentially foldable attribute reference.
7697 -- If Static is set, then the attribute reference definitely obeys
7698 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
7699 -- folded. If Static is not set, then the attribute may or may not
7700 -- be foldable, and the individual attribute processing routines
7701 -- test Static as required in cases where it makes a difference.
7703 -- In the case where Static is not set, we do know that all the
7704 -- expressions present are at least known at compile time (we assumed
7705 -- above that if this was not the case, then there was no hope of static
7706 -- evaluation). However, we did not require that the bounds of the
7707 -- prefix type be compile time known, let alone static). That's because
7708 -- there are many attributes that can be computed at compile time on
7709 -- non-static subtypes, even though such references are not static
7712 -- For VAX float, the root type is an IEEE type. So make sure to use the
7713 -- base type instead of the root-type for floating point attributes.
7717 -- Attributes related to Ada 2012 iterators (placeholder ???)
7719 when Attribute_Constant_Indexing |
7720 Attribute_Default_Iterator |
7721 Attribute_Implicit_Dereference |
7722 Attribute_Iterator_Element |
7723 Attribute_Iterable |
7724 Attribute_Variable_Indexing
=> null;
7726 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7727 -- These were already rejected by the parser. Thus they shouldn't
7730 when Internal_Attribute_Id
=>
7731 raise Program_Error
;
7737 when Attribute_Adjacent
=>
7741 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7748 when Attribute_Aft
=>
7749 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
7755 when Attribute_Alignment
=> Alignment_Block
: declare
7756 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7759 -- Fold if alignment is set and not otherwise
7761 if Known_Alignment
(P_TypeA
) then
7762 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
7764 end Alignment_Block
;
7766 -----------------------------
7767 -- Atomic_Always_Lock_Free --
7768 -----------------------------
7770 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7773 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
7775 V
: constant Entity_Id
:=
7777 (Support_Atomic_Primitives_On_Target
7778 and then Support_Atomic_Primitives
(P_Type
));
7781 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7783 -- Analyze and resolve as boolean. Note that this attribute is a
7784 -- static attribute in GNAT.
7786 Analyze_And_Resolve
(N
, Standard_Boolean
);
7788 Set_Is_Static_Expression
(N
, True);
7789 end Atomic_Always_Lock_Free
;
7795 -- Bit can never be folded
7797 when Attribute_Bit
=>
7804 -- Body_version can never be static
7806 when Attribute_Body_Version
=>
7813 when Attribute_Ceiling
=>
7815 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7817 --------------------
7818 -- Component_Size --
7819 --------------------
7821 when Attribute_Component_Size
=>
7822 if Known_Static_Component_Size
(P_Type
) then
7823 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
7830 when Attribute_Compose
=>
7833 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7840 -- Constrained is never folded for now, there may be cases that
7841 -- could be handled at compile time. To be looked at later.
7843 when Attribute_Constrained
=>
7845 -- The expander might fold it and set the static flag accordingly,
7846 -- but with expansion disabled (as in ASIS), it remains as an
7847 -- attribute reference, and this reference is not static.
7849 Set_Is_Static_Expression
(N
, False);
7856 when Attribute_Copy_Sign
=>
7860 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7867 when Attribute_Definite
=>
7868 Rewrite
(N
, New_Occurrence_Of
(
7869 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
7870 Analyze_And_Resolve
(N
, Standard_Boolean
);
7876 when Attribute_Delta
=>
7877 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
7883 when Attribute_Denorm
=>
7885 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
7887 ---------------------
7888 -- Descriptor_Size --
7889 ---------------------
7891 when Attribute_Descriptor_Size
=>
7898 when Attribute_Digits
=>
7899 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
7905 when Attribute_Emax
=>
7907 -- Ada 83 attribute is defined as (RM83 3.5.8)
7909 -- T'Emax = 4 * T'Mantissa
7911 Fold_Uint
(N
, 4 * Mantissa
, Static
);
7917 when Attribute_Enum_Rep
=>
7919 -- For an enumeration type with a non-standard representation use
7920 -- the Enumeration_Rep field of the proper constant. Note that this
7921 -- will not work for types Character/Wide_[Wide-]Character, since no
7922 -- real entities are created for the enumeration literals, but that
7923 -- does not matter since these two types do not have non-standard
7924 -- representations anyway.
7926 if Is_Enumeration_Type
(P_Type
)
7927 and then Has_Non_Standard_Rep
(P_Type
)
7929 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
7931 -- For enumeration types with standard representations and all
7932 -- other cases (i.e. all integer and modular types), Enum_Rep
7933 -- is equivalent to Pos.
7936 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7943 when Attribute_Enum_Val
=> Enum_Val
: declare
7947 -- We have something like Enum_Type'Enum_Val (23), so search for a
7948 -- corresponding value in the list of Enum_Rep values for the type.
7950 Lit
:= First_Literal
(P_Base_Type
);
7952 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
7953 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
7960 Apply_Compile_Time_Constraint_Error
7961 (N
, "no representation value matches",
7962 CE_Range_Check_Failed
,
7963 Warn
=> not Static
);
7973 when Attribute_Epsilon
=>
7975 -- Ada 83 attribute is defined as (RM83 3.5.8)
7977 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7979 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
7985 when Attribute_Exponent
=>
7987 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7993 when Attribute_First
=> First_Attr
:
7997 if Compile_Time_Known_Value
(Lo_Bound
) then
7998 if Is_Real_Type
(P_Type
) then
7999 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
8001 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8005 Check_Concurrent_Discriminant
(Lo_Bound
);
8013 when Attribute_First_Valid
=> First_Valid
:
8015 if Has_Predicates
(P_Type
)
8016 and then Has_Static_Predicate
(P_Type
)
8019 FirstN
: constant Node_Id
:=
8020 First
(Static_Discrete_Predicate
(P_Type
));
8022 if Nkind
(FirstN
) = N_Range
then
8023 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
8025 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
8031 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8039 when Attribute_Fixed_Value
=>
8046 when Attribute_Floor
=>
8048 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8054 when Attribute_Fore
=>
8055 if Compile_Time_Known_Bounds
(P_Type
) then
8056 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
8063 when Attribute_Fraction
=>
8065 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8067 -----------------------
8068 -- Has_Access_Values --
8069 -----------------------
8071 when Attribute_Has_Access_Values
=>
8072 Rewrite
(N
, New_Occurrence_Of
8073 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8074 Analyze_And_Resolve
(N
, Standard_Boolean
);
8076 -----------------------
8077 -- Has_Discriminants --
8078 -----------------------
8080 when Attribute_Has_Discriminants
=>
8081 Rewrite
(N
, New_Occurrence_Of
(
8082 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8083 Analyze_And_Resolve
(N
, Standard_Boolean
);
8085 ----------------------
8086 -- Has_Same_Storage --
8087 ----------------------
8089 when Attribute_Has_Same_Storage
=>
8092 -----------------------
8093 -- Has_Tagged_Values --
8094 -----------------------
8096 when Attribute_Has_Tagged_Values
=>
8097 Rewrite
(N
, New_Occurrence_Of
8098 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8099 Analyze_And_Resolve
(N
, Standard_Boolean
);
8105 when Attribute_Identity
=>
8112 -- Image is a scalar attribute, but is never static, because it is
8113 -- not a static function (having a non-scalar argument (RM 4.9(22))
8114 -- However, we can constant-fold the image of an enumeration literal
8115 -- if names are available.
8117 when Attribute_Image
=>
8118 if Is_Entity_Name
(E1
)
8119 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8120 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8121 and then not Global_Discard_Names
8124 Lit
: constant Entity_Id
:= Entity
(E1
);
8128 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8129 Set_Casing
(All_Upper_Case
);
8130 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8132 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8133 Analyze_And_Resolve
(N
, Standard_String
);
8134 Set_Is_Static_Expression
(N
, False);
8142 -- Img is a scalar attribute, but is never static, because it is
8143 -- not a static function (having a non-scalar argument (RM 4.9(22))
8145 when Attribute_Img
=>
8152 -- We never try to fold Integer_Value (though perhaps we could???)
8154 when Attribute_Integer_Value
=>
8161 -- Invalid_Value is a scalar attribute that is never static, because
8162 -- the value is by design out of range.
8164 when Attribute_Invalid_Value
=>
8171 when Attribute_Large
=>
8173 -- For fixed-point, we use the identity:
8175 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8177 if Is_Fixed_Point_Type
(P_Type
) then
8179 Make_Op_Multiply
(Loc
,
8181 Make_Op_Subtract
(Loc
,
8185 Make_Real_Literal
(Loc
, Ureal_2
),
8187 Make_Attribute_Reference
(Loc
,
8189 Attribute_Name
=> Name_Mantissa
)),
8190 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8193 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8195 Analyze_And_Resolve
(N
, C_Type
);
8197 -- Floating-point (Ada 83 compatibility)
8200 -- Ada 83 attribute is defined as (RM83 3.5.8)
8202 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8206 -- T'Emax = 4 * T'Mantissa
8210 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8218 when Attribute_Lock_Free
=> Lock_Free
: declare
8219 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8222 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8224 -- Analyze and resolve as boolean. Note that this attribute is a
8225 -- static attribute in GNAT.
8227 Analyze_And_Resolve
(N
, Standard_Boolean
);
8229 Set_Is_Static_Expression
(N
, True);
8236 when Attribute_Last
=> Last_Attr
:
8240 if Compile_Time_Known_Value
(Hi_Bound
) then
8241 if Is_Real_Type
(P_Type
) then
8242 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8244 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8248 Check_Concurrent_Discriminant
(Hi_Bound
);
8256 when Attribute_Last_Valid
=> Last_Valid
:
8258 if Has_Predicates
(P_Type
)
8259 and then Has_Static_Predicate
(P_Type
)
8262 LastN
: constant Node_Id
:=
8263 Last
(Static_Discrete_Predicate
(P_Type
));
8265 if Nkind
(LastN
) = N_Range
then
8266 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8268 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8274 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8282 when Attribute_Leading_Part
=>
8285 Eval_Fat
.Leading_Part
8286 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8293 when Attribute_Length
=> Length
: declare
8297 -- If any index type is a formal type, or derived from one, the
8298 -- bounds are not static. Treating them as static can produce
8299 -- spurious warnings or improper constant folding.
8301 Ind
:= First_Index
(P_Type
);
8302 while Present
(Ind
) loop
8303 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8312 -- For two compile time values, we can compute length
8314 if Compile_Time_Known_Value
(Lo_Bound
)
8315 and then Compile_Time_Known_Value
(Hi_Bound
)
8318 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8322 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8323 -- comparable, and we can figure out the difference between them.
8326 Diff
: aliased Uint
;
8330 Compile_Time_Compare
8331 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8334 Fold_Uint
(N
, Uint_1
, Static
);
8337 Fold_Uint
(N
, Uint_0
, Static
);
8340 if Diff
/= No_Uint
then
8341 Fold_Uint
(N
, Diff
+ 1, Static
);
8354 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8355 -- of the said attribute at the point of entry into the related loop. As
8356 -- such, the attribute reference does not need to be evaluated because
8357 -- the prefix is the one that is evaluted.
8359 when Attribute_Loop_Entry
=>
8366 when Attribute_Machine
=>
8370 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8377 when Attribute_Machine_Emax
=>
8378 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8384 when Attribute_Machine_Emin
=>
8385 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8387 ----------------------
8388 -- Machine_Mantissa --
8389 ----------------------
8391 when Attribute_Machine_Mantissa
=>
8392 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8394 -----------------------
8395 -- Machine_Overflows --
8396 -----------------------
8398 when Attribute_Machine_Overflows
=>
8400 -- Always true for fixed-point
8402 if Is_Fixed_Point_Type
(P_Type
) then
8403 Fold_Uint
(N
, True_Value
, Static
);
8405 -- Floating point case
8409 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8417 when Attribute_Machine_Radix
=>
8418 if Is_Fixed_Point_Type
(P_Type
) then
8419 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8420 and then Machine_Radix_10
(P_Type
)
8422 Fold_Uint
(N
, Uint_10
, Static
);
8424 Fold_Uint
(N
, Uint_2
, Static
);
8427 -- All floating-point type always have radix 2
8430 Fold_Uint
(N
, Uint_2
, Static
);
8433 ----------------------
8434 -- Machine_Rounding --
8435 ----------------------
8437 -- Note: for the folding case, it is fine to treat Machine_Rounding
8438 -- exactly the same way as Rounding, since this is one of the allowed
8439 -- behaviors, and performance is not an issue here. It might be a bit
8440 -- better to give the same result as it would give at run time, even
8441 -- though the non-determinism is certainly permitted.
8443 when Attribute_Machine_Rounding
=>
8445 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8447 --------------------
8448 -- Machine_Rounds --
8449 --------------------
8451 when Attribute_Machine_Rounds
=>
8453 -- Always False for fixed-point
8455 if Is_Fixed_Point_Type
(P_Type
) then
8456 Fold_Uint
(N
, False_Value
, Static
);
8458 -- Else yield proper floating-point result
8462 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8470 -- Note: Machine_Size is identical to Object_Size
8472 when Attribute_Machine_Size
=> Machine_Size
: declare
8473 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8476 if Known_Esize
(P_TypeA
) then
8477 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8485 when Attribute_Mantissa
=>
8487 -- Fixed-point mantissa
8489 if Is_Fixed_Point_Type
(P_Type
) then
8491 -- Compile time foldable case
8493 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8495 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8497 -- The calculation of the obsolete Ada 83 attribute Mantissa
8498 -- is annoying, because of AI00143, quoted here:
8500 -- !question 84-01-10
8502 -- Consider the model numbers for F:
8504 -- type F is delta 1.0 range -7.0 .. 8.0;
8506 -- The wording requires that F'MANTISSA be the SMALLEST
8507 -- integer number for which each bound of the specified
8508 -- range is either a model number or lies at most small
8509 -- distant from a model number. This means F'MANTISSA
8510 -- is required to be 3 since the range -7.0 .. 7.0 fits
8511 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8512 -- number, namely, 7. Is this analysis correct? Note that
8513 -- this implies the upper bound of the range is not
8514 -- represented as a model number.
8516 -- !response 84-03-17
8518 -- The analysis is correct. The upper and lower bounds for
8519 -- a fixed point type can lie outside the range of model
8530 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8531 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8532 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8533 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8535 -- If the Bound is exactly a model number, i.e. a multiple
8536 -- of Small, then we back it off by one to get the integer
8537 -- value that must be representable.
8539 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8540 Max_Man
:= Max_Man
- 1;
8543 -- Now find corresponding size = Mantissa value
8546 while 2 ** Siz
< Max_Man
loop
8550 Fold_Uint
(N
, Siz
, Static
);
8554 -- The case of dynamic bounds cannot be evaluated at compile
8555 -- time. Instead we use a runtime routine (see Exp_Attr).
8560 -- Floating-point Mantissa
8563 Fold_Uint
(N
, Mantissa
, Static
);
8570 when Attribute_Max
=> Max
:
8572 if Is_Real_Type
(P_Type
) then
8574 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8576 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8580 ----------------------------------
8581 -- Max_Alignment_For_Allocation --
8582 ----------------------------------
8584 -- Max_Alignment_For_Allocation is usually the Alignment. However,
8585 -- arrays are allocated with dope, so we need to take into account both
8586 -- the alignment of the array, which comes from the component alignment,
8587 -- and the alignment of the dope. Also, if the alignment is unknown, we
8588 -- use the max (it's OK to be pessimistic).
8590 when Attribute_Max_Alignment_For_Allocation
=>
8592 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
8594 if Known_Alignment
(P_Type
) and then
8595 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
8597 A
:= Alignment
(P_Type
);
8600 Fold_Uint
(N
, A
, Static
);
8603 ----------------------------------
8604 -- Max_Size_In_Storage_Elements --
8605 ----------------------------------
8607 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
8608 -- Storage_Unit boundary. We can fold any cases for which the size
8609 -- is known by the front end.
8611 when Attribute_Max_Size_In_Storage_Elements
=>
8612 if Known_Esize
(P_Type
) then
8614 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
8615 System_Storage_Unit
,
8619 --------------------
8620 -- Mechanism_Code --
8621 --------------------
8623 when Attribute_Mechanism_Code
=>
8627 Mech
: Mechanism_Type
;
8631 Mech
:= Mechanism
(P_Entity
);
8634 Val
:= UI_To_Int
(Expr_Value
(E1
));
8636 Formal
:= First_Formal
(P_Entity
);
8637 for J
in 1 .. Val
- 1 loop
8638 Next_Formal
(Formal
);
8640 Mech
:= Mechanism
(Formal
);
8644 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
8652 when Attribute_Min
=> Min
:
8654 if Is_Real_Type
(P_Type
) then
8656 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8659 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8667 when Attribute_Mod
=>
8669 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
8675 when Attribute_Model
=>
8677 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8683 when Attribute_Model_Emin
=>
8684 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
8690 when Attribute_Model_Epsilon
=>
8691 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
8693 --------------------
8694 -- Model_Mantissa --
8695 --------------------
8697 when Attribute_Model_Mantissa
=>
8698 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
8704 when Attribute_Model_Small
=>
8705 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
8711 when Attribute_Modulus
=>
8712 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
8714 --------------------
8715 -- Null_Parameter --
8716 --------------------
8718 -- Cannot fold, we know the value sort of, but the whole point is
8719 -- that there is no way to talk about this imaginary value except
8720 -- by using the attribute, so we leave it the way it is.
8722 when Attribute_Null_Parameter
=>
8729 -- The Object_Size attribute for a type returns the Esize of the
8730 -- type and can be folded if this value is known.
8732 when Attribute_Object_Size
=> Object_Size
: declare
8733 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8736 if Known_Esize
(P_TypeA
) then
8737 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8741 ----------------------
8742 -- Overlaps_Storage --
8743 ----------------------
8745 when Attribute_Overlaps_Storage
=>
8748 -------------------------
8749 -- Passed_By_Reference --
8750 -------------------------
8752 -- Scalar types are never passed by reference
8754 when Attribute_Passed_By_Reference
=>
8755 Fold_Uint
(N
, False_Value
, Static
);
8761 when Attribute_Pos
=>
8762 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8768 when Attribute_Pred
=> Pred
:
8770 -- Floating-point case
8772 if Is_Floating_Point_Type
(P_Type
) then
8774 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8778 elsif Is_Fixed_Point_Type
(P_Type
) then
8780 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
8782 -- Modular integer case (wraps)
8784 elsif Is_Modular_Integer_Type
(P_Type
) then
8785 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
8787 -- Other scalar cases
8790 pragma Assert
(Is_Scalar_Type
(P_Type
));
8792 if Is_Enumeration_Type
(P_Type
)
8793 and then Expr_Value
(E1
) =
8794 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8796 Apply_Compile_Time_Constraint_Error
8797 (N
, "Pred of `&''First`",
8798 CE_Overflow_Check_Failed
,
8800 Warn
=> not Static
);
8806 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
8814 -- No processing required, because by this stage, Range has been
8815 -- replaced by First .. Last, so this branch can never be taken.
8817 when Attribute_Range
=>
8818 raise Program_Error
;
8824 when Attribute_Range_Length
=>
8827 -- Can fold if both bounds are compile time known
8829 if Compile_Time_Known_Value
(Hi_Bound
)
8830 and then Compile_Time_Known_Value
(Lo_Bound
)
8834 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
8838 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8839 -- comparable, and we can figure out the difference between them.
8842 Diff
: aliased Uint
;
8846 Compile_Time_Compare
8847 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8850 Fold_Uint
(N
, Uint_1
, Static
);
8853 Fold_Uint
(N
, Uint_0
, Static
);
8856 if Diff
/= No_Uint
then
8857 Fold_Uint
(N
, Diff
+ 1, Static
);
8869 when Attribute_Ref
=>
8870 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8876 when Attribute_Remainder
=> Remainder
: declare
8877 X
: constant Ureal
:= Expr_Value_R
(E1
);
8878 Y
: constant Ureal
:= Expr_Value_R
(E2
);
8881 if UR_Is_Zero
(Y
) then
8882 Apply_Compile_Time_Constraint_Error
8883 (N
, "division by zero in Remainder",
8884 CE_Overflow_Check_Failed
,
8885 Warn
=> not Static
);
8891 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
8898 when Attribute_Restriction_Set
=> Restriction_Set
: declare
8900 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
8901 Set_Is_Static_Expression
(N
);
8902 end Restriction_Set
;
8908 when Attribute_Round
=> Round
:
8914 -- First we get the (exact result) in units of small
8916 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
8918 -- Now round that exactly to an integer
8920 Si
:= UR_To_Uint
(Sr
);
8922 -- Finally the result is obtained by converting back to real
8924 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
8931 when Attribute_Rounding
=>
8933 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8939 when Attribute_Safe_Emax
=>
8940 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
8946 when Attribute_Safe_First
=>
8947 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
8953 when Attribute_Safe_Large
=>
8954 if Is_Fixed_Point_Type
(P_Type
) then
8956 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
8958 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8965 when Attribute_Safe_Last
=>
8966 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8972 when Attribute_Safe_Small
=>
8974 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8975 -- for fixed-point, since is the same as Small, but we implement
8976 -- it for backwards compatibility.
8978 if Is_Fixed_Point_Type
(P_Type
) then
8979 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
8981 -- Ada 83 Safe_Small for floating-point cases
8984 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
8991 when Attribute_Scale
=>
8992 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
8998 when Attribute_Scaling
=>
9002 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9009 when Attribute_Signed_Zeros
=>
9011 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
9017 -- Size attribute returns the RM size. All scalar types can be folded,
9018 -- as well as any types for which the size is known by the front end,
9019 -- including any type for which a size attribute is specified. This is
9020 -- one of the places where it is annoying that a size of zero means two
9021 -- things (zero size for scalars, unspecified size for non-scalars).
9023 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
9024 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9027 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9031 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
9033 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
9036 -- If a size clause applies, then use the size from it.
9037 -- This is one of the rare cases where we can use the
9038 -- Size_Clause field for a subtype when Has_Size_Clause
9039 -- is False. Consider:
9041 -- type x is range 1 .. 64;
9042 -- for x'size use 12;
9043 -- subtype y is x range 0 .. 3;
9045 -- Here y has a size clause inherited from x, but normally
9046 -- it does not apply, and y'size is 2. However, y'VADS_Size
9047 -- is indeed 12 and not 2.
9050 and then Is_OK_Static_Expression
(Expression
(S
))
9052 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
9054 -- If no size is specified, then we simply use the object
9055 -- size in the VADS_Size case (e.g. Natural'Size is equal
9056 -- to Integer'Size, not one less).
9059 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9063 -- Normal case (Size) in which case we want the RM_Size
9066 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9075 when Attribute_Small
=>
9077 -- The floating-point case is present only for Ada 83 compatibility.
9078 -- Note that strictly this is an illegal addition, since we are
9079 -- extending an Ada 95 defined attribute, but we anticipate an
9080 -- ARG ruling that will permit this.
9082 if Is_Floating_Point_Type
(P_Type
) then
9084 -- Ada 83 attribute is defined as (RM83 3.5.8)
9086 -- T'Small = 2.0**(-T'Emax - 1)
9090 -- T'Emax = 4 * T'Mantissa
9092 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9094 -- Normal Ada 95 fixed-point case
9097 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9104 when Attribute_Stream_Size
=>
9111 when Attribute_Succ
=> Succ
:
9113 -- Floating-point case
9115 if Is_Floating_Point_Type
(P_Type
) then
9117 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9121 elsif Is_Fixed_Point_Type
(P_Type
) then
9122 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9124 -- Modular integer case (wraps)
9126 elsif Is_Modular_Integer_Type
(P_Type
) then
9127 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9129 -- Other scalar cases
9132 pragma Assert
(Is_Scalar_Type
(P_Type
));
9134 if Is_Enumeration_Type
(P_Type
)
9135 and then Expr_Value
(E1
) =
9136 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9138 Apply_Compile_Time_Constraint_Error
9139 (N
, "Succ of `&''Last`",
9140 CE_Overflow_Check_Failed
,
9142 Warn
=> not Static
);
9147 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9156 when Attribute_Truncation
=>
9159 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9166 when Attribute_Type_Class
=> Type_Class
: declare
9167 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9171 if Is_Descendent_Of_Address
(Typ
) then
9172 Id
:= RE_Type_Class_Address
;
9174 elsif Is_Enumeration_Type
(Typ
) then
9175 Id
:= RE_Type_Class_Enumeration
;
9177 elsif Is_Integer_Type
(Typ
) then
9178 Id
:= RE_Type_Class_Integer
;
9180 elsif Is_Fixed_Point_Type
(Typ
) then
9181 Id
:= RE_Type_Class_Fixed_Point
;
9183 elsif Is_Floating_Point_Type
(Typ
) then
9184 Id
:= RE_Type_Class_Floating_Point
;
9186 elsif Is_Array_Type
(Typ
) then
9187 Id
:= RE_Type_Class_Array
;
9189 elsif Is_Record_Type
(Typ
) then
9190 Id
:= RE_Type_Class_Record
;
9192 elsif Is_Access_Type
(Typ
) then
9193 Id
:= RE_Type_Class_Access
;
9195 elsif Is_Enumeration_Type
(Typ
) then
9196 Id
:= RE_Type_Class_Enumeration
;
9198 elsif Is_Task_Type
(Typ
) then
9199 Id
:= RE_Type_Class_Task
;
9201 -- We treat protected types like task types. It would make more
9202 -- sense to have another enumeration value, but after all the
9203 -- whole point of this feature is to be exactly DEC compatible,
9204 -- and changing the type Type_Class would not meet this requirement.
9206 elsif Is_Protected_Type
(Typ
) then
9207 Id
:= RE_Type_Class_Task
;
9209 -- Not clear if there are any other possibilities, but if there
9210 -- are, then we will treat them as the address case.
9213 Id
:= RE_Type_Class_Address
;
9216 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9219 -----------------------
9220 -- Unbiased_Rounding --
9221 -----------------------
9223 when Attribute_Unbiased_Rounding
=>
9226 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9229 -------------------------
9230 -- Unconstrained_Array --
9231 -------------------------
9233 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9234 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9237 Rewrite
(N
, New_Occurrence_Of
(
9239 Is_Array_Type
(P_Type
)
9240 and then not Is_Constrained
(Typ
)), Loc
));
9242 -- Analyze and resolve as boolean, note that this attribute is
9243 -- a static attribute in GNAT.
9245 Analyze_And_Resolve
(N
, Standard_Boolean
);
9247 Set_Is_Static_Expression
(N
, True);
9248 end Unconstrained_Array
;
9250 -- Attribute Update is never static
9252 when Attribute_Update
=>
9259 -- Processing is shared with Size
9265 when Attribute_Val
=> Val
:
9267 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9269 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9271 Apply_Compile_Time_Constraint_Error
9272 (N
, "Val expression out of range",
9273 CE_Range_Check_Failed
,
9274 Warn
=> not Static
);
9280 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9288 -- The Value_Size attribute for a type returns the RM size of the type.
9289 -- This an always be folded for scalar types, and can also be folded for
9290 -- non-scalar types if the size is set. This is one of the places where
9291 -- it is annoying that a size of zero means two things!
9293 when Attribute_Value_Size
=> Value_Size
: declare
9294 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9296 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9297 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9305 -- Version can never be static
9307 when Attribute_Version
=>
9314 -- Wide_Image is a scalar attribute, but is never static, because it
9315 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9317 when Attribute_Wide_Image
=>
9320 ---------------------
9321 -- Wide_Wide_Image --
9322 ---------------------
9324 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9325 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9327 when Attribute_Wide_Wide_Image
=>
9330 ---------------------
9331 -- Wide_Wide_Width --
9332 ---------------------
9334 -- Processing for Wide_Wide_Width is combined with Width
9340 -- Processing for Wide_Width is combined with Width
9346 -- This processing also handles the case of Wide_[Wide_]Width
9348 when Attribute_Width |
9349 Attribute_Wide_Width |
9350 Attribute_Wide_Wide_Width
=> Width
:
9352 if Compile_Time_Known_Bounds
(P_Type
) then
9354 -- Floating-point types
9356 if Is_Floating_Point_Type
(P_Type
) then
9358 -- Width is zero for a null range (RM 3.5 (38))
9360 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9361 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9363 Fold_Uint
(N
, Uint_0
, Static
);
9366 -- For floating-point, we have +N.dddE+nnn where length
9367 -- of ddd is determined by type'Digits - 1, but is one
9368 -- if Digits is one (RM 3.5 (33)).
9370 -- nnn is set to 2 for Short_Float and Float (32 bit
9371 -- floats), and 3 for Long_Float and Long_Long_Float.
9372 -- For machines where Long_Long_Float is the IEEE
9373 -- extended precision type, the exponent takes 4 digits.
9377 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9380 if Esize
(P_Type
) <= 32 then
9382 elsif Esize
(P_Type
) = 64 then
9388 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9392 -- Fixed-point types
9394 elsif Is_Fixed_Point_Type
(P_Type
) then
9396 -- Width is zero for a null range (RM 3.5 (38))
9398 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9399 Expr_Value
(Type_Low_Bound
(P_Type
))
9401 Fold_Uint
(N
, Uint_0
, Static
);
9403 -- The non-null case depends on the specific real type
9406 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9409 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9417 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9418 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9419 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9432 -- Width for types derived from Standard.Character
9433 -- and Standard.Wide_[Wide_]Character.
9435 elsif Is_Standard_Character_Type
(P_Type
) then
9438 -- Set W larger if needed
9440 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9442 -- All wide characters look like Hex_hhhhhhhh
9446 -- No need to compute this more than once
9451 C
:= Character'Val (J
);
9453 -- Test for all cases where Character'Image
9454 -- yields an image that is longer than three
9455 -- characters. First the cases of Reserved_xxx
9456 -- names (length = 12).
9459 when Reserved_128 | Reserved_129 |
9460 Reserved_132 | Reserved_153
9463 when BS | HT | LF | VT | FF | CR |
9464 SO | SI | EM | FS | GS | RS |
9465 US | RI | MW | ST | PM
9468 when NUL | SOH | STX | ETX | EOT |
9469 ENQ | ACK | BEL | DLE | DC1 |
9470 DC2 | DC3 | DC4 | NAK | SYN |
9471 ETB | CAN | SUB | ESC | DEL |
9472 BPH | NBH | NEL | SSA | ESA |
9473 HTS | HTJ | VTS | PLD | PLU |
9474 SS2 | SS3 | DCS | PU1 | PU2 |
9475 STS | CCH | SPA | EPA | SOS |
9476 SCI | CSI | OSC | APC
9479 when Space
.. Tilde |
9480 No_Break_Space
.. LC_Y_Diaeresis
9482 -- Special case of soft hyphen in Ada 2005
9484 if C
= Character'Val (16#AD#
)
9485 and then Ada_Version
>= Ada_2005
9493 W
:= Int
'Max (W
, Wt
);
9497 -- Width for types derived from Standard.Boolean
9499 elsif R
= Standard_Boolean
then
9506 -- Width for integer types
9508 elsif Is_Integer_Type
(P_Type
) then
9509 T
:= UI_Max
(abs Lo
, abs Hi
);
9517 -- User declared enum type with discard names
9519 elsif Discard_Names
(R
) then
9521 -- If range is null, result is zero, that has already
9522 -- been dealt with, so what we need is the power of ten
9523 -- that accomodates the Pos of the largest value, which
9524 -- is the high bound of the range + one for the space.
9533 -- Only remaining possibility is user declared enum type
9534 -- with normal case of Discard_Names not active.
9537 pragma Assert
(Is_Enumeration_Type
(P_Type
));
9540 L
:= First_Literal
(P_Type
);
9541 while Present
(L
) loop
9543 -- Only pay attention to in range characters
9545 if Lo
<= Enumeration_Pos
(L
)
9546 and then Enumeration_Pos
(L
) <= Hi
9548 -- For Width case, use decoded name
9550 if Id
= Attribute_Width
then
9551 Get_Decoded_Name_String
(Chars
(L
));
9552 Wt
:= Nat
(Name_Len
);
9554 -- For Wide_[Wide_]Width, use encoded name, and
9555 -- then adjust for the encoding.
9558 Get_Name_String
(Chars
(L
));
9560 -- Character literals are always of length 3
9562 if Name_Buffer
(1) = 'Q' then
9565 -- Otherwise loop to adjust for upper/wide chars
9568 Wt
:= Nat
(Name_Len
);
9570 for J
in 1 .. Name_Len
loop
9571 if Name_Buffer
(J
) = 'U' then
9573 elsif Name_Buffer
(J
) = 'W' then
9580 W
:= Int
'Max (W
, Wt
);
9587 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
9593 -- The following attributes denote functions that cannot be folded
9595 when Attribute_From_Any |
9597 Attribute_TypeCode
=>
9600 -- The following attributes can never be folded, and furthermore we
9601 -- should not even have entered the case statement for any of these.
9602 -- Note that in some cases, the values have already been folded as
9603 -- a result of the processing in Analyze_Attribute.
9605 when Attribute_Abort_Signal |
9608 Attribute_Address_Size |
9609 Attribute_Asm_Input |
9610 Attribute_Asm_Output |
9612 Attribute_Bit_Order |
9613 Attribute_Bit_Position |
9614 Attribute_Callable |
9617 Attribute_Code_Address |
9618 Attribute_Compiler_Version |
9620 Attribute_Default_Bit_Order |
9621 Attribute_Default_Scalar_Storage_Order |
9622 Attribute_Elaborated |
9623 Attribute_Elab_Body |
9624 Attribute_Elab_Spec |
9625 Attribute_Elab_Subp_Body |
9627 Attribute_External_Tag |
9628 Attribute_Fast_Math |
9629 Attribute_First_Bit |
9631 Attribute_Last_Bit |
9632 Attribute_Library_Level |
9633 Attribute_Maximum_Alignment |
9636 Attribute_Partition_ID |
9637 Attribute_Pool_Address |
9638 Attribute_Position |
9639 Attribute_Priority |
9642 Attribute_Scalar_Storage_Order |
9643 Attribute_Simple_Storage_Pool |
9644 Attribute_Storage_Pool |
9645 Attribute_Storage_Size |
9646 Attribute_Storage_Unit |
9647 Attribute_Stub_Type |
9648 Attribute_System_Allocator_Alignment |
9650 Attribute_Target_Name |
9651 Attribute_Terminated |
9652 Attribute_To_Address |
9653 Attribute_Type_Key |
9654 Attribute_UET_Address |
9655 Attribute_Unchecked_Access |
9656 Attribute_Universal_Literal_String |
9657 Attribute_Unrestricted_Access |
9659 Attribute_Valid_Scalars |
9661 Attribute_Wchar_T_Size |
9662 Attribute_Wide_Value |
9663 Attribute_Wide_Wide_Value |
9664 Attribute_Word_Size |
9667 raise Program_Error
;
9670 -- At the end of the case, one more check. If we did a static evaluation
9671 -- so that the result is now a literal, then set Is_Static_Expression
9672 -- in the constant only if the prefix type is a static subtype. For
9673 -- non-static subtypes, the folding is still OK, but not static.
9675 -- An exception is the GNAT attribute Constrained_Array which is
9676 -- defined to be a static attribute in all cases.
9678 if Nkind_In
(N
, N_Integer_Literal
,
9680 N_Character_Literal
,
9682 or else (Is_Entity_Name
(N
)
9683 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
9685 Set_Is_Static_Expression
(N
, Static
);
9687 -- If this is still an attribute reference, then it has not been folded
9688 -- and that means that its expressions are in a non-static context.
9690 elsif Nkind
(N
) = N_Attribute_Reference
then
9693 -- Note: the else case not covered here are odd cases where the
9694 -- processing has transformed the attribute into something other
9695 -- than a constant. Nothing more to do in such cases.
9702 ------------------------------
9703 -- Is_Anonymous_Tagged_Base --
9704 ------------------------------
9706 function Is_Anonymous_Tagged_Base
9708 Typ
: Entity_Id
) return Boolean
9712 Anon
= Current_Scope
9713 and then Is_Itype
(Anon
)
9714 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
9715 end Is_Anonymous_Tagged_Base
;
9717 --------------------------------
9718 -- Name_Implies_Lvalue_Prefix --
9719 --------------------------------
9721 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
9722 pragma Assert
(Is_Attribute_Name
(Nam
));
9724 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
9725 end Name_Implies_Lvalue_Prefix
;
9727 -----------------------
9728 -- Resolve_Attribute --
9729 -----------------------
9731 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
9732 Loc
: constant Source_Ptr
:= Sloc
(N
);
9733 P
: constant Node_Id
:= Prefix
(N
);
9734 Aname
: constant Name_Id
:= Attribute_Name
(N
);
9735 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
9736 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9737 Des_Btyp
: Entity_Id
;
9738 Index
: Interp_Index
;
9740 Nom_Subt
: Entity_Id
;
9742 procedure Accessibility_Message
;
9743 -- Error, or warning within an instance, if the static accessibility
9744 -- rules of 3.10.2 are violated.
9746 ---------------------------
9747 -- Accessibility_Message --
9748 ---------------------------
9750 procedure Accessibility_Message
is
9751 Indic
: Node_Id
:= Parent
(Parent
(N
));
9754 -- In an instance, this is a runtime check, but one we
9755 -- know will fail, so generate an appropriate warning.
9757 if In_Instance_Body
then
9758 Error_Msg_Warn
:= SPARK_Mode
/= On
;
9760 ("non-local pointer cannot point to local object<<", P
);
9761 Error_Msg_F
("\Program_Error [<<", P
);
9763 Make_Raise_Program_Error
(Loc
,
9764 Reason
=> PE_Accessibility_Check_Failed
));
9769 Error_Msg_F
("non-local pointer cannot point to local object", P
);
9771 -- Check for case where we have a missing access definition
9773 if Is_Record_Type
(Current_Scope
)
9775 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
9776 N_Index_Or_Discriminant_Constraint
)
9778 Indic
:= Parent
(Parent
(N
));
9779 while Present
(Indic
)
9780 and then Nkind
(Indic
) /= N_Subtype_Indication
9782 Indic
:= Parent
(Indic
);
9785 if Present
(Indic
) then
9787 ("\use an access definition for" &
9788 " the access discriminant of&",
9789 N
, Entity
(Subtype_Mark
(Indic
)));
9793 end Accessibility_Message
;
9795 -- Start of processing for Resolve_Attribute
9798 -- If error during analysis, no point in continuing, except for array
9799 -- types, where we get better recovery by using unconstrained indexes
9800 -- than nothing at all (see Check_Array_Type).
9803 and then Attr_Id
/= Attribute_First
9804 and then Attr_Id
/= Attribute_Last
9805 and then Attr_Id
/= Attribute_Length
9806 and then Attr_Id
/= Attribute_Range
9811 -- If attribute was universal type, reset to actual type
9813 if Etype
(N
) = Universal_Integer
9814 or else Etype
(N
) = Universal_Real
9819 -- Remaining processing depends on attribute
9827 -- For access attributes, if the prefix denotes an entity, it is
9828 -- interpreted as a name, never as a call. It may be overloaded,
9829 -- in which case resolution uses the profile of the context type.
9830 -- Otherwise prefix must be resolved.
9832 when Attribute_Access
9833 | Attribute_Unchecked_Access
9834 | Attribute_Unrestricted_Access
=>
9838 if Is_Variable
(P
) then
9839 Note_Possible_Modification
(P
, Sure
=> False);
9842 -- The following comes from a query concerning improper use of
9843 -- universal_access in equality tests involving anonymous access
9844 -- types. Another good reason for 'Ref, but for now disable the
9845 -- test, which breaks several filed tests???
9847 if Ekind
(Typ
) = E_Anonymous_Access_Type
9848 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
9851 Error_Msg_N
("need unique type to resolve 'Access", N
);
9852 Error_Msg_N
("\qualify attribute with some access type", N
);
9855 -- Case where prefix is an entity name
9857 if Is_Entity_Name
(P
) then
9859 -- Deal with case where prefix itself is overloaded
9861 if Is_Overloaded
(P
) then
9862 Get_First_Interp
(P
, Index
, It
);
9863 while Present
(It
.Nam
) loop
9864 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
9865 Set_Entity
(P
, It
.Nam
);
9867 -- The prefix is definitely NOT overloaded anymore at
9868 -- this point, so we reset the Is_Overloaded flag to
9869 -- avoid any confusion when reanalyzing the node.
9871 Set_Is_Overloaded
(P
, False);
9872 Set_Is_Overloaded
(N
, False);
9873 Generate_Reference
(Entity
(P
), P
);
9877 Get_Next_Interp
(Index
, It
);
9880 -- If Prefix is a subprogram name, this reference freezes:
9882 -- If it is a type, there is nothing to resolve.
9883 -- If it is an object, complete its resolution.
9885 elsif Is_Overloadable
(Entity
(P
)) then
9887 -- Avoid insertion of freeze actions in spec expression mode
9889 if not In_Spec_Expression
then
9890 Freeze_Before
(N
, Entity
(P
));
9893 -- Nothing to do if prefix is a type name
9895 elsif Is_Type
(Entity
(P
)) then
9898 -- Otherwise non-overloaded other case, resolve the prefix
9904 -- Some further error checks
9906 Error_Msg_Name_1
:= Aname
;
9908 if not Is_Entity_Name
(P
) then
9911 elsif Is_Overloadable
(Entity
(P
))
9912 and then Is_Abstract_Subprogram
(Entity
(P
))
9914 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
9915 Set_Etype
(N
, Any_Type
);
9917 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
9919 ("prefix of % attribute cannot be enumeration literal", P
);
9920 Set_Etype
(N
, Any_Type
);
9922 -- An attempt to take 'Access of a function that renames an
9923 -- enumeration literal. Issue a specialized error message.
9925 elsif Ekind
(Entity
(P
)) = E_Function
9926 and then Present
(Alias
(Entity
(P
)))
9927 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
9930 ("prefix of % attribute cannot be function renaming "
9931 & "an enumeration literal", P
);
9932 Set_Etype
(N
, Any_Type
);
9934 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
9935 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
9936 Set_Etype
(N
, Any_Type
);
9939 -- Assignments, return statements, components of aggregates,
9940 -- generic instantiations will require convention checks if
9941 -- the type is an access to subprogram. Given that there will
9942 -- also be accessibility checks on those, this is where the
9943 -- checks can eventually be centralized ???
9945 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9946 E_Anonymous_Access_Subprogram_Type
,
9947 E_Access_Protected_Subprogram_Type
,
9948 E_Anonymous_Access_Protected_Subprogram_Type
)
9950 -- Deal with convention mismatch
9952 if Convention
(Designated_Type
(Btyp
)) /=
9953 Convention
(Entity
(P
))
9956 ("subprogram & has wrong convention", P
, Entity
(P
));
9957 Error_Msg_Sloc
:= Sloc
(Btyp
);
9958 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
9960 if not Is_Itype
(Btyp
)
9961 and then not Has_Convention_Pragma
(Btyp
)
9964 ("\probable missing pragma Convention for &",
9969 Check_Subtype_Conformant
9970 (New_Id
=> Entity
(P
),
9971 Old_Id
=> Designated_Type
(Btyp
),
9975 if Attr_Id
= Attribute_Unchecked_Access
then
9976 Error_Msg_Name_1
:= Aname
;
9978 ("attribute% cannot be applied to a subprogram", P
);
9980 elsif Aname
= Name_Unrestricted_Access
then
9981 null; -- Nothing to check
9983 -- Check the static accessibility rule of 3.10.2(32).
9984 -- This rule also applies within the private part of an
9985 -- instantiation. This rule does not apply to anonymous
9986 -- access-to-subprogram types in access parameters.
9988 elsif Attr_Id
= Attribute_Access
9989 and then not In_Instance_Body
9991 (Ekind
(Btyp
) = E_Access_Subprogram_Type
9992 or else Is_Local_Anonymous_Access
(Btyp
))
9993 and then Subprogram_Access_Level
(Entity
(P
)) >
9994 Type_Access_Level
(Btyp
)
9997 ("subprogram must not be deeper than access type", P
);
9999 -- Check the restriction of 3.10.2(32) that disallows the
10000 -- access attribute within a generic body when the ultimate
10001 -- ancestor of the type of the attribute is declared outside
10002 -- of the generic unit and the subprogram is declared within
10003 -- that generic unit. This includes any such attribute that
10004 -- occurs within the body of a generic unit that is a child
10005 -- of the generic unit where the subprogram is declared.
10007 -- The rule also prohibits applying the attribute when the
10008 -- access type is a generic formal access type (since the
10009 -- level of the actual type is not known). This restriction
10010 -- does not apply when the attribute type is an anonymous
10011 -- access-to-subprogram type. Note that this check was
10012 -- revised by AI-229, because the originally Ada 95 rule
10013 -- was too lax. The original rule only applied when the
10014 -- subprogram was declared within the body of the generic,
10015 -- which allowed the possibility of dangling references).
10016 -- The rule was also too strict in some case, in that it
10017 -- didn't permit the access to be declared in the generic
10018 -- spec, whereas the revised rule does (as long as it's not
10021 -- There are a couple of subtleties of the test for applying
10022 -- the check that are worth noting. First, we only apply it
10023 -- when the levels of the subprogram and access type are the
10024 -- same (the case where the subprogram is statically deeper
10025 -- was applied above, and the case where the type is deeper
10026 -- is always safe). Second, we want the check to apply
10027 -- within nested generic bodies and generic child unit
10028 -- bodies, but not to apply to an attribute that appears in
10029 -- the generic unit's specification. This is done by testing
10030 -- that the attribute's innermost enclosing generic body is
10031 -- not the same as the innermost generic body enclosing the
10032 -- generic unit where the subprogram is declared (we don't
10033 -- want the check to apply when the access attribute is in
10034 -- the spec and there's some other generic body enclosing
10035 -- generic). Finally, there's no point applying the check
10036 -- when within an instance, because any violations will have
10037 -- been caught by the compilation of the generic unit.
10039 -- We relax this check in Relaxed_RM_Semantics mode for
10040 -- compatibility with legacy code for use by Ada source
10041 -- code analyzers (e.g. CodePeer).
10043 elsif Attr_Id
= Attribute_Access
10044 and then not Relaxed_RM_Semantics
10045 and then not In_Instance
10046 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
10047 and then Present
(Enclosing_Generic_Body
(N
))
10048 and then Enclosing_Generic_Body
(N
) /=
10049 Enclosing_Generic_Body
10050 (Enclosing_Generic_Unit
(Entity
(P
)))
10051 and then Subprogram_Access_Level
(Entity
(P
)) =
10052 Type_Access_Level
(Btyp
)
10053 and then Ekind
(Btyp
) /=
10054 E_Anonymous_Access_Subprogram_Type
10055 and then Ekind
(Btyp
) /=
10056 E_Anonymous_Access_Protected_Subprogram_Type
10058 -- The attribute type's ultimate ancestor must be
10059 -- declared within the same generic unit as the
10060 -- subprogram is declared. The error message is
10061 -- specialized to say "ancestor" for the case where the
10062 -- access type is not its own ancestor, since saying
10063 -- simply "access type" would be very confusing.
10065 if Enclosing_Generic_Unit
(Entity
(P
)) /=
10066 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
10069 ("''Access attribute not allowed in generic body",
10072 if Root_Type
(Btyp
) = Btyp
then
10075 "access type & is declared outside " &
10076 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10079 ("\because ancestor of " &
10080 "access type & is declared outside " &
10081 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10085 ("\move ''Access to private part, or " &
10086 "(Ada 2005) use anonymous access type instead of &",
10089 -- If the ultimate ancestor of the attribute's type is
10090 -- a formal type, then the attribute is illegal because
10091 -- the actual type might be declared at a higher level.
10092 -- The error message is specialized to say "ancestor"
10093 -- for the case where the access type is not its own
10094 -- ancestor, since saying simply "access type" would be
10097 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10098 if Root_Type
(Btyp
) = Btyp
then
10100 ("access type must not be a generic formal type",
10104 ("ancestor access type must not be a generic " &
10111 -- If this is a renaming, an inherited operation, or a
10112 -- subprogram instance, use the original entity. This may make
10113 -- the node type-inconsistent, so this transformation can only
10114 -- be done if the node will not be reanalyzed. In particular,
10115 -- if it is within a default expression, the transformation
10116 -- must be delayed until the default subprogram is created for
10117 -- it, when the enclosing subprogram is frozen.
10119 if Is_Entity_Name
(P
)
10120 and then Is_Overloadable
(Entity
(P
))
10121 and then Present
(Alias
(Entity
(P
)))
10122 and then Expander_Active
10125 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10128 elsif Nkind
(P
) = N_Selected_Component
10129 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10131 -- Protected operation. If operation is overloaded, must
10132 -- disambiguate. Prefix that denotes protected object itself
10133 -- is resolved with its own type.
10135 if Attr_Id
= Attribute_Unchecked_Access
then
10136 Error_Msg_Name_1
:= Aname
;
10138 ("attribute% cannot be applied to protected operation", P
);
10141 Resolve
(Prefix
(P
));
10142 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10144 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10145 -- statically illegal if F is an anonymous access to subprogram.
10147 elsif Nkind
(P
) = N_Explicit_Dereference
10148 and then Is_Entity_Name
(Prefix
(P
))
10149 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10150 E_Anonymous_Access_Subprogram_Type
10152 Error_Msg_N
("anonymous access to subprogram "
10153 & "has deeper accessibility than any master", P
);
10155 elsif Is_Overloaded
(P
) then
10157 -- Use the designated type of the context to disambiguate
10158 -- Note that this was not strictly conformant to Ada 95,
10159 -- but was the implementation adopted by most Ada 95 compilers.
10160 -- The use of the context type to resolve an Access attribute
10161 -- reference is now mandated in AI-235 for Ada 2005.
10164 Index
: Interp_Index
;
10168 Get_First_Interp
(P
, Index
, It
);
10169 while Present
(It
.Typ
) loop
10170 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10171 Resolve
(P
, It
.Typ
);
10175 Get_Next_Interp
(Index
, It
);
10182 -- X'Access is illegal if X denotes a constant and the access type
10183 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10184 -- does not apply to 'Unrestricted_Access. If the reference is a
10185 -- default-initialized aggregate component for a self-referential
10186 -- type the reference is legal.
10188 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10189 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10190 or else (Is_Record_Type
(Btyp
)
10192 Present
(Corresponding_Remote_Type
(Btyp
)))
10193 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10194 or else Ekind
(Btyp
)
10195 = E_Anonymous_Access_Protected_Subprogram_Type
10196 or else Is_Access_Constant
(Btyp
)
10197 or else Is_Variable
(P
)
10198 or else Attr_Id
= Attribute_Unrestricted_Access
)
10200 if Is_Entity_Name
(P
)
10201 and then Is_Type
(Entity
(P
))
10203 -- Legality of a self-reference through an access
10204 -- attribute has been verified in Analyze_Access_Attribute.
10208 elsif Comes_From_Source
(N
) then
10209 Error_Msg_F
("access-to-variable designates constant", P
);
10213 Des_Btyp
:= Designated_Type
(Btyp
);
10215 if Ada_Version
>= Ada_2005
10216 and then Is_Incomplete_Type
(Des_Btyp
)
10218 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10219 -- imported entity, and the non-limited view is visible, make
10220 -- use of it. If it is an incomplete subtype, use the base type
10223 if From_Limited_With
(Des_Btyp
)
10224 and then Present
(Non_Limited_View
(Des_Btyp
))
10226 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10228 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10229 Des_Btyp
:= Etype
(Des_Btyp
);
10233 if (Attr_Id
= Attribute_Access
10235 Attr_Id
= Attribute_Unchecked_Access
)
10236 and then (Ekind
(Btyp
) = E_General_Access_Type
10237 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10239 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10240 -- access types for stand-alone objects, record and array
10241 -- components, and return objects. For a component definition
10242 -- the level is the same of the enclosing composite type.
10244 if Ada_Version
>= Ada_2005
10245 and then (Is_Local_Anonymous_Access
(Btyp
)
10247 -- Handle cases where Btyp is the anonymous access
10248 -- type of an Ada 2012 stand-alone object.
10250 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10251 N_Object_Declaration
)
10253 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10254 and then Attr_Id
= Attribute_Access
10256 -- In an instance, this is a runtime check, but one we know
10257 -- will fail, so generate an appropriate warning. As usual,
10258 -- this kind of warning is an error in SPARK mode.
10260 if In_Instance_Body
then
10261 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10263 ("non-local pointer cannot point to local object<<", P
);
10264 Error_Msg_F
("\Program_Error [<<", P
);
10267 Make_Raise_Program_Error
(Loc
,
10268 Reason
=> PE_Accessibility_Check_Failed
));
10269 Set_Etype
(N
, Typ
);
10273 ("non-local pointer cannot point to local object", P
);
10277 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10279 ("illegal attribute for discriminant-dependent component",
10283 -- Check static matching rule of 3.10.2(27). Nominal subtype
10284 -- of the prefix must statically match the designated type.
10286 Nom_Subt
:= Etype
(P
);
10288 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10289 Nom_Subt
:= Base_Type
(Nom_Subt
);
10292 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10294 -- If the attribute is in the context of an access
10295 -- parameter, then the prefix is allowed to be of
10296 -- the class-wide type (by AI-127).
10298 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10299 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10300 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10306 Desig
:= Designated_Type
(Typ
);
10308 if Is_Class_Wide_Type
(Desig
) then
10309 Desig
:= Etype
(Desig
);
10312 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10317 ("type of prefix: & not compatible",
10320 ("\with &, the expected designated type",
10321 P
, Designated_Type
(Typ
));
10326 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10328 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10329 and then Is_Class_Wide_Type
(Nom_Subt
))
10332 ("type of prefix: & is not covered", P
, Nom_Subt
);
10334 ("\by &, the expected designated type" &
10335 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10338 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10339 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10340 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10341 and then Designated_Type
(Typ
) /= Nom_Subt
10343 Apply_Discriminant_Check
10344 (N
, Etype
(Designated_Type
(Typ
)));
10347 -- Ada 2005 (AI-363): Require static matching when designated
10348 -- type has discriminants and a constrained partial view, since
10349 -- in general objects of such types are mutable, so we can't
10350 -- allow the access value to designate a constrained object
10351 -- (because access values must be assumed to designate mutable
10352 -- objects when designated type does not impose a constraint).
10354 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10357 elsif Has_Discriminants
(Designated_Type
(Typ
))
10358 and then not Is_Constrained
(Des_Btyp
)
10360 (Ada_Version
< Ada_2005
10362 not Object_Type_Has_Constrained_Partial_View
10363 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10364 Scop
=> Current_Scope
))
10370 ("object subtype must statically match "
10371 & "designated subtype", P
);
10373 if Is_Entity_Name
(P
)
10374 and then Is_Array_Type
(Designated_Type
(Typ
))
10377 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10380 ("aliased object has explicit bounds??", D
);
10382 ("\declare without bounds (and with explicit "
10383 & "initialization)??", D
);
10385 ("\for use with unconstrained access??", D
);
10390 -- Check the static accessibility rule of 3.10.2(28). Note that
10391 -- this check is not performed for the case of an anonymous
10392 -- access type, since the access attribute is always legal
10393 -- in such a context.
10395 if Attr_Id
/= Attribute_Unchecked_Access
10396 and then Ekind
(Btyp
) = E_General_Access_Type
10398 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10400 Accessibility_Message
;
10405 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10406 E_Anonymous_Access_Protected_Subprogram_Type
)
10408 if Is_Entity_Name
(P
)
10409 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
10411 Error_Msg_F
("context requires a protected subprogram", P
);
10413 -- Check accessibility of protected object against that of the
10414 -- access type, but only on user code, because the expander
10415 -- creates access references for handlers. If the context is an
10416 -- anonymous_access_to_protected, there are no accessibility
10417 -- checks either. Omit check entirely for Unrestricted_Access.
10419 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10420 and then Comes_From_Source
(N
)
10421 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10422 and then Attr_Id
/= Attribute_Unrestricted_Access
10424 Accessibility_Message
;
10427 -- AI05-0225: If the context is not an access to protected
10428 -- function, the prefix must be a variable, given that it may
10429 -- be used subsequently in a protected call.
10431 elsif Nkind
(P
) = N_Selected_Component
10432 and then not Is_Variable
(Prefix
(P
))
10433 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
10436 ("target object of access to protected procedure "
10437 & "must be variable", N
);
10439 elsif Is_Entity_Name
(P
) then
10440 Check_Internal_Protected_Use
(N
, Entity
(P
));
10443 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10444 E_Anonymous_Access_Subprogram_Type
)
10445 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
10447 Error_Msg_F
("context requires a non-protected subprogram", P
);
10450 -- The context cannot be a pool-specific type, but this is a
10451 -- legality rule, not a resolution rule, so it must be checked
10452 -- separately, after possibly disambiguation (see AI-245).
10454 if Ekind
(Btyp
) = E_Access_Type
10455 and then Attr_Id
/= Attribute_Unrestricted_Access
10457 Wrong_Type
(N
, Typ
);
10460 -- The context may be a constrained access type (however ill-
10461 -- advised such subtypes might be) so in order to generate a
10462 -- constraint check when needed set the type of the attribute
10463 -- reference to the base type of the context.
10465 Set_Etype
(N
, Btyp
);
10467 -- Check for incorrect atomic/volatile reference (RM C.6(12))
10469 if Attr_Id
/= Attribute_Unrestricted_Access
then
10470 if Is_Atomic_Object
(P
)
10471 and then not Is_Atomic
(Designated_Type
(Typ
))
10474 ("access to atomic object cannot yield access-to-" &
10475 "non-atomic type", P
);
10477 elsif Is_Volatile_Object
(P
)
10478 and then not Is_Volatile
(Designated_Type
(Typ
))
10481 ("access to volatile object cannot yield access-to-" &
10482 "non-volatile type", P
);
10486 -- Check for unrestricted access where expected type is a thin
10487 -- pointer to an unconstrained array.
10489 if Non_Aliased_Prefix
(N
)
10490 and then Has_Size_Clause
(Typ
)
10491 and then RM_Size
(Typ
) = System_Address_Size
10494 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
10496 if Is_Array_Type
(DT
) and then not Is_Constrained
(DT
) then
10498 ("illegal use of Unrestricted_Access attribute", P
);
10500 ("\attempt to generate thin pointer to unaliased "
10506 -- Mark that address of entity is taken
10508 if Is_Entity_Name
(P
) then
10509 Set_Address_Taken
(Entity
(P
));
10512 -- Deal with possible elaboration check
10514 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
10516 Subp_Id
: constant Entity_Id
:= Entity
(P
);
10517 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
10518 Subp_Decl
: constant Node_Id
:=
10519 Unit_Declaration_Node
(Subp_Id
);
10521 Flag_Id
: Entity_Id
;
10525 -- If the access has been taken and the body of the subprogram
10526 -- has not been see yet, indirect calls must be protected with
10527 -- elaboration checks. We have the proper elaboration machinery
10528 -- for subprograms declared in packages, but within a block or
10529 -- a subprogram the body will appear in the same declarative
10530 -- part, and we must insert a check in the eventual body itself
10531 -- using the elaboration flag that we generate now. The check
10532 -- is then inserted when the body is expanded. This processing
10533 -- is not needed for a stand alone expression function because
10534 -- the internally generated spec and body are always inserted
10535 -- as a pair in the same declarative list.
10539 and then Comes_From_Source
(Subp_Id
)
10540 and then Comes_From_Source
(N
)
10541 and then In_Open_Scopes
(Scop
)
10542 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
10543 and then not Has_Completion
(Subp_Id
)
10544 and then No
(Elaboration_Entity
(Subp_Id
))
10545 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10546 and then Nkind
(Original_Node
(Subp_Decl
)) /=
10547 N_Expression_Function
10549 -- Create elaboration variable for it
10551 Flag_Id
:= Make_Temporary
(Loc
, 'E');
10552 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
10553 Set_Is_Frozen
(Flag_Id
);
10555 -- Insert declaration for flag after subprogram
10556 -- declaration. Note that attribute reference may
10557 -- appear within a nested scope.
10559 Insert_After_And_Analyze
(Subp_Decl
,
10560 Make_Object_Declaration
(Loc
,
10561 Defining_Identifier
=> Flag_Id
,
10562 Object_Definition
=>
10563 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
10565 Make_Integer_Literal
(Loc
, Uint_0
)));
10568 -- Taking the 'Access of an expression function freezes its
10569 -- expression (RM 13.14 10.3/3). This does not apply to an
10570 -- expression function that acts as a completion because the
10571 -- generated body is immediately analyzed and the expression
10572 -- is automatically frozen.
10574 if Ekind
(Subp_Id
) = E_Function
10575 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10576 and then Nkind
(Original_Node
(Subp_Decl
)) =
10577 N_Expression_Function
10578 and then Present
(Corresponding_Body
(Subp_Decl
))
10579 and then not Analyzed
(Corresponding_Body
(Subp_Decl
))
10582 Handled_Statement_Sequence
10583 (Unit_Declaration_Node
10584 (Corresponding_Body
(Subp_Decl
)));
10586 if Present
(HSS
) then
10587 Stmt
:= First
(Statements
(HSS
));
10589 if Nkind
(Stmt
) = N_Simple_Return_Statement
then
10590 Freeze_Expression
(Expression
(Stmt
));
10596 end Access_Attribute
;
10602 -- Deal with resolving the type for Address attribute, overloading
10603 -- is not permitted here, since there is no context to resolve it.
10605 when Attribute_Address | Attribute_Code_Address
=>
10606 Address_Attribute
: begin
10608 -- To be safe, assume that if the address of a variable is taken,
10609 -- it may be modified via this address, so note modification.
10611 if Is_Variable
(P
) then
10612 Note_Possible_Modification
(P
, Sure
=> False);
10615 if Nkind
(P
) in N_Subexpr
10616 and then Is_Overloaded
(P
)
10618 Get_First_Interp
(P
, Index
, It
);
10619 Get_Next_Interp
(Index
, It
);
10621 if Present
(It
.Nam
) then
10622 Error_Msg_Name_1
:= Aname
;
10624 ("prefix of % attribute cannot be overloaded", P
);
10628 if not Is_Entity_Name
(P
)
10629 or else not Is_Overloadable
(Entity
(P
))
10631 if not Is_Task_Type
(Etype
(P
))
10632 or else Nkind
(P
) = N_Explicit_Dereference
10638 -- If this is the name of a derived subprogram, or that of a
10639 -- generic actual, the address is that of the original entity.
10641 if Is_Entity_Name
(P
)
10642 and then Is_Overloadable
(Entity
(P
))
10643 and then Present
(Alias
(Entity
(P
)))
10646 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10649 if Is_Entity_Name
(P
) then
10650 Set_Address_Taken
(Entity
(P
));
10653 if Nkind
(P
) = N_Slice
then
10655 -- Arr (X .. Y)'address is identical to Arr (X)'address,
10656 -- even if the array is packed and the slice itself is not
10657 -- addressable. Transform the prefix into an indexed component.
10659 -- Note that the transformation is safe only if we know that
10660 -- the slice is non-null. That is because a null slice can have
10661 -- an out of bounds index value.
10663 -- Right now, gigi blows up if given 'Address on a slice as a
10664 -- result of some incorrect freeze nodes generated by the front
10665 -- end, and this covers up that bug in one case, but the bug is
10666 -- likely still there in the cases not handled by this code ???
10668 -- It's not clear what 'Address *should* return for a null
10669 -- slice with out of bounds indexes, this might be worth an ARG
10672 -- One approach would be to do a length check unconditionally,
10673 -- and then do the transformation below unconditionally, but
10674 -- analyze with checks off, avoiding the problem of the out of
10675 -- bounds index. This approach would interpret the address of
10676 -- an out of bounds null slice as being the address where the
10677 -- array element would be if there was one, which is probably
10678 -- as reasonable an interpretation as any ???
10681 Loc
: constant Source_Ptr
:= Sloc
(P
);
10682 D
: constant Node_Id
:= Discrete_Range
(P
);
10686 if Is_Entity_Name
(D
)
10689 (Type_Low_Bound
(Entity
(D
)),
10690 Type_High_Bound
(Entity
(D
)))
10693 Make_Attribute_Reference
(Loc
,
10694 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
10695 Attribute_Name
=> Name_First
);
10697 elsif Nkind
(D
) = N_Range
10698 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
10700 Lo
:= Low_Bound
(D
);
10706 if Present
(Lo
) then
10708 Make_Indexed_Component
(Loc
,
10709 Prefix
=> Relocate_Node
(Prefix
(P
)),
10710 Expressions
=> New_List
(Lo
)));
10712 Analyze_And_Resolve
(P
);
10716 end Address_Attribute
;
10722 -- Prefix of Body_Version attribute can be a subprogram name which
10723 -- must not be resolved, since this is not a call.
10725 when Attribute_Body_Version
=>
10732 -- Prefix of Caller attribute is an entry name which must not
10733 -- be resolved, since this is definitely not an entry call.
10735 when Attribute_Caller
=>
10742 -- Shares processing with Address attribute
10748 -- If the prefix of the Count attribute is an entry name it must not
10749 -- be resolved, since this is definitely not an entry call. However,
10750 -- if it is an element of an entry family, the index itself may
10751 -- have to be resolved because it can be a general expression.
10753 when Attribute_Count
=>
10754 if Nkind
(P
) = N_Indexed_Component
10755 and then Is_Entity_Name
(Prefix
(P
))
10758 Indx
: constant Node_Id
:= First
(Expressions
(P
));
10759 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
10761 Resolve
(Indx
, Entry_Index_Type
(Fam
));
10762 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
10770 -- Prefix of the Elaborated attribute is a subprogram name which
10771 -- must not be resolved, since this is definitely not a call. Note
10772 -- that it is a library unit, so it cannot be overloaded here.
10774 when Attribute_Elaborated
=>
10781 -- Prefix of Enabled attribute is a check name, which must be treated
10782 -- specially and not touched by Resolve.
10784 when Attribute_Enabled
=>
10791 -- Do not resolve the prefix of Loop_Entry, instead wait until the
10792 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
10793 -- The delay ensures that any generated checks or temporaries are
10794 -- inserted before the relocated prefix.
10796 when Attribute_Loop_Entry
=>
10799 --------------------
10800 -- Mechanism_Code --
10801 --------------------
10803 -- Prefix of the Mechanism_Code attribute is a function name
10804 -- which must not be resolved. Should we check for overloaded ???
10806 when Attribute_Mechanism_Code
=>
10813 -- Most processing is done in sem_dist, after determining the
10814 -- context type. Node is rewritten as a conversion to a runtime call.
10816 when Attribute_Partition_ID
=>
10817 Process_Partition_Id
(N
);
10824 when Attribute_Pool_Address
=>
10831 -- We replace the Range attribute node with a range expression whose
10832 -- bounds are the 'First and 'Last attributes applied to the same
10833 -- prefix. The reason that we do this transformation here instead of
10834 -- in the expander is that it simplifies other parts of the semantic
10835 -- analysis which assume that the Range has been replaced; thus it
10836 -- must be done even when in semantic-only mode (note that the RM
10837 -- specifically mentions this equivalence, we take care that the
10838 -- prefix is only evaluated once).
10840 when Attribute_Range
=> Range_Attribute
:
10847 if not Is_Entity_Name
(P
)
10848 or else not Is_Type
(Entity
(P
))
10853 Dims
:= Expressions
(N
);
10856 Make_Attribute_Reference
(Loc
,
10857 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
10858 Attribute_Name
=> Name_Last
,
10859 Expressions
=> Dims
);
10862 Make_Attribute_Reference
(Loc
,
10864 Attribute_Name
=> Name_First
,
10865 Expressions
=> (Dims
));
10867 -- Do not share the dimension indicator, if present. Even
10868 -- though it is a static constant, its source location
10869 -- may be modified when printing expanded code and node
10870 -- sharing will lead to chaos in Sprint.
10872 if Present
(Dims
) then
10873 Set_Expressions
(LB
,
10874 New_List
(New_Copy_Tree
(First
(Dims
))));
10877 -- If the original was marked as Must_Not_Freeze (see code
10878 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10879 -- does not freeze either.
10881 if Must_Not_Freeze
(N
) then
10882 Set_Must_Not_Freeze
(HB
);
10883 Set_Must_Not_Freeze
(LB
);
10884 Set_Must_Not_Freeze
(Prefix
(HB
));
10885 Set_Must_Not_Freeze
(Prefix
(LB
));
10888 if Raises_Constraint_Error
(Prefix
(N
)) then
10890 -- Preserve Sloc of prefix in the new bounds, so that
10891 -- the posted warning can be removed if we are within
10892 -- unreachable code.
10894 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
10895 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
10898 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
10899 Analyze_And_Resolve
(N
, Typ
);
10901 -- Ensure that the expanded range does not have side effects
10903 Force_Evaluation
(LB
);
10904 Force_Evaluation
(HB
);
10906 -- Normally after resolving attribute nodes, Eval_Attribute
10907 -- is called to do any possible static evaluation of the node.
10908 -- However, here since the Range attribute has just been
10909 -- transformed into a range expression it is no longer an
10910 -- attribute node and therefore the call needs to be avoided
10911 -- and is accomplished by simply returning from the procedure.
10914 end Range_Attribute
;
10920 -- We will only come here during the prescan of a spec expression
10921 -- containing a Result attribute. In that case the proper Etype has
10922 -- already been set, and nothing more needs to be done here.
10924 when Attribute_Result
=>
10931 -- Prefix must not be resolved in this case, since it is not a
10932 -- real entity reference. No action of any kind is require.
10934 when Attribute_UET_Address
=>
10937 ----------------------
10938 -- Unchecked_Access --
10939 ----------------------
10941 -- Processing is shared with Access
10943 -------------------------
10944 -- Unrestricted_Access --
10945 -------------------------
10947 -- Processing is shared with Access
10953 -- Resolve aggregate components in component associations
10955 when Attribute_Update
=>
10957 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
10958 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
10964 -- Set the Etype of the aggregate to that of the prefix, even
10965 -- though the aggregate may not be a proper representation of a
10966 -- value of the type (missing or duplicated associations, etc.)
10967 -- Complete resolution of the prefix. Note that in Ada 2012 it
10968 -- can be a qualified expression that is e.g. an aggregate.
10970 Set_Etype
(Aggr
, Typ
);
10971 Resolve
(Prefix
(N
), Typ
);
10973 -- For an array type, resolve expressions with the component
10974 -- type of the array, and apply constraint checks when needed.
10976 if Is_Array_Type
(Typ
) then
10977 Assoc
:= First
(Component_Associations
(Aggr
));
10978 while Present
(Assoc
) loop
10979 Expr
:= Expression
(Assoc
);
10980 Resolve
(Expr
, Component_Type
(Typ
));
10982 -- For scalar array components set Do_Range_Check when
10983 -- needed. Constraint checking on non-scalar components
10984 -- is done in Aggregate_Constraint_Checks, but only if
10985 -- full analysis is enabled. These flags are not set in
10986 -- the front-end in GnatProve mode.
10988 if Is_Scalar_Type
(Component_Type
(Typ
))
10989 and then not Is_OK_Static_Expression
(Expr
)
10991 if Is_Entity_Name
(Expr
)
10992 and then Etype
(Expr
) = Component_Type
(Typ
)
10997 Set_Do_Range_Check
(Expr
);
11001 -- The choices in the association are static constants,
11002 -- or static aggregates each of whose components belongs
11003 -- to the proper index type. However, they must also
11004 -- belong to the index subtype (s) of the prefix, which
11005 -- may be a subtype (e.g. given by a slice).
11007 -- Choices may also be identifiers with no staticness
11008 -- requirements, in which case they must resolve to the
11017 C
:= First
(Choices
(Assoc
));
11018 while Present
(C
) loop
11019 Indx
:= First_Index
(Etype
(Prefix
(N
)));
11021 if Nkind
(C
) /= N_Aggregate
then
11022 Analyze_And_Resolve
(C
, Etype
(Indx
));
11023 Apply_Constraint_Check
(C
, Etype
(Indx
));
11024 Check_Non_Static_Context
(C
);
11027 C_E
:= First
(Expressions
(C
));
11028 while Present
(C_E
) loop
11029 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
11030 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
11031 Check_Non_Static_Context
(C_E
);
11045 -- For a record type, use type of each component, which is
11046 -- recorded during analysis.
11049 Assoc
:= First
(Component_Associations
(Aggr
));
11050 while Present
(Assoc
) loop
11051 Comp
:= First
(Choices
(Assoc
));
11052 Expr
:= Expression
(Assoc
);
11054 if Nkind
(Comp
) /= N_Others_Choice
11055 and then not Error_Posted
(Comp
)
11057 Resolve
(Expr
, Etype
(Entity
(Comp
)));
11059 if Is_Scalar_Type
(Etype
(Entity
(Comp
)))
11060 and then not Is_OK_Static_Expression
(Expr
)
11062 Set_Do_Range_Check
(Expr
);
11075 -- Apply range check. Note that we did not do this during the
11076 -- analysis phase, since we wanted Eval_Attribute to have a
11077 -- chance at finding an illegal out of range value.
11079 when Attribute_Val
=>
11081 -- Note that we do our own Eval_Attribute call here rather than
11082 -- use the common one, because we need to do processing after
11083 -- the call, as per above comment.
11085 Eval_Attribute
(N
);
11087 -- Eval_Attribute may replace the node with a raise CE, or
11088 -- fold it to a constant. Obviously we only apply a scalar
11089 -- range check if this did not happen.
11091 if Nkind
(N
) = N_Attribute_Reference
11092 and then Attribute_Name
(N
) = Name_Val
11094 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11103 -- Prefix of Version attribute can be a subprogram name which
11104 -- must not be resolved, since this is not a call.
11106 when Attribute_Version
=>
11109 ----------------------
11110 -- Other Attributes --
11111 ----------------------
11113 -- For other attributes, resolve prefix unless it is a type. If
11114 -- the attribute reference itself is a type name ('Base and 'Class)
11115 -- then this is only legal within a task or protected record.
11118 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11122 -- If the attribute reference itself is a type name ('Base,
11123 -- 'Class) then this is only legal within a task or protected
11124 -- record. What is this all about ???
11126 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11127 if Is_Concurrent_Type
(Entity
(N
))
11128 and then In_Open_Scopes
(Entity
(P
))
11133 ("invalid use of subtype name in expression or call", N
);
11137 -- For attributes whose argument may be a string, complete
11138 -- resolution of argument now. This avoids premature expansion
11139 -- (and the creation of transient scopes) before the attribute
11140 -- reference is resolved.
11143 when Attribute_Value
=>
11144 Resolve
(First
(Expressions
(N
)), Standard_String
);
11146 when Attribute_Wide_Value
=>
11147 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11149 when Attribute_Wide_Wide_Value
=>
11150 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11152 when others => null;
11155 -- If the prefix of the attribute is a class-wide type then it
11156 -- will be expanded into a dispatching call to a predefined
11157 -- primitive. Therefore we must check for potential violation
11158 -- of such restriction.
11160 if Is_Class_Wide_Type
(Etype
(P
)) then
11161 Check_Restriction
(No_Dispatching_Calls
, N
);
11165 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11166 -- is not resolved, in which case the freezing must be done now.
11168 -- For an elaboration check on a subprogram, we do not freeze its type.
11169 -- It may be declared in an unrelated scope, in particular in the case
11170 -- of a generic function whose type may remain unelaborated.
11172 if Attr_Id
= Attribute_Elaborated
then
11176 Freeze_Expression
(P
);
11179 -- Finally perform static evaluation on the attribute reference
11181 Analyze_Dimension
(N
);
11182 Eval_Attribute
(N
);
11183 end Resolve_Attribute
;
11185 ------------------------
11186 -- Set_Boolean_Result --
11187 ------------------------
11189 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11190 Loc
: constant Source_Ptr
:= Sloc
(N
);
11193 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11195 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11197 end Set_Boolean_Result
;
11199 --------------------------------
11200 -- Stream_Attribute_Available --
11201 --------------------------------
11203 function Stream_Attribute_Available
11205 Nam
: TSS_Name_Type
;
11206 Partial_View
: Node_Id
:= Empty
) return Boolean
11208 Etyp
: Entity_Id
:= Typ
;
11210 -- Start of processing for Stream_Attribute_Available
11213 -- We need some comments in this body ???
11215 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11219 if Is_Class_Wide_Type
(Typ
) then
11220 return not Is_Limited_Type
(Typ
)
11221 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11224 if Nam
= TSS_Stream_Input
11225 and then Is_Abstract_Type
(Typ
)
11226 and then not Is_Class_Wide_Type
(Typ
)
11231 if not (Is_Limited_Type
(Typ
)
11232 or else (Present
(Partial_View
)
11233 and then Is_Limited_Type
(Partial_View
)))
11238 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11240 if Nam
= TSS_Stream_Input
11241 and then Ada_Version
>= Ada_2005
11242 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11246 elsif Nam
= TSS_Stream_Output
11247 and then Ada_Version
>= Ada_2005
11248 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11253 -- Case of Read and Write: check for attribute definition clause that
11254 -- applies to an ancestor type.
11256 while Etype
(Etyp
) /= Etyp
loop
11257 Etyp
:= Etype
(Etyp
);
11259 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11264 if Ada_Version
< Ada_2005
then
11266 -- In Ada 95 mode, also consider a non-visible definition
11269 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11272 and then Stream_Attribute_Available
11273 (Btyp
, Nam
, Partial_View
=> Typ
);
11278 end Stream_Attribute_Available
;