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
);
777 elsif Is_Ghost_Subprogram
(Entity
(P
)) then
779 ("prefix of % attribute cannot be a ghost subprogram");
782 -- Issue an error if the prefix denotes an eliminated subprogram
784 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
786 -- Check for obsolescent subprogram reference
788 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
790 -- Build the appropriate subprogram type
792 Build_Access_Subprogram_Type
(P
);
794 -- For P'Access or P'Unrestricted_Access, where P is a nested
795 -- subprogram, we might be passing P to another subprogram (but we
796 -- don't check that here), which might call P. P could modify
797 -- local variables, so we need to kill current values. It is
798 -- important not to do this for library-level subprograms, because
799 -- Kill_Current_Values is very inefficient in the case of library
800 -- level packages with lots of tagged types.
802 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
805 -- Do not kill values on nodes initializing dispatch tables
806 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
807 -- is currently generated by the expander only for this
808 -- purpose. Done to keep the quality of warnings currently
809 -- generated by the compiler (otherwise any declaration of
810 -- a tagged type cleans constant indications from its scope).
812 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
813 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
815 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
816 and then Is_Dispatching_Operation
817 (Directly_Designated_Type
(Etype
(N
)))
825 -- In the static elaboration model, treat the attribute reference
826 -- as a call for elaboration purposes. Suppress this treatment
827 -- under debug flag. In any case, we are all done.
829 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
835 -- Component is an operation of a protected type
837 elsif Nkind
(P
) = N_Selected_Component
838 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
840 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
841 Error_Attr_P
("prefix of % attribute must be subprogram");
844 Build_Access_Subprogram_Type
(Selector_Name
(P
));
848 -- Deal with incorrect reference to a type, but note that some
849 -- accesses are allowed: references to the current type instance,
850 -- or in Ada 2005 self-referential pointer in a default-initialized
853 if Is_Entity_Name
(P
) then
856 -- The reference may appear in an aggregate that has been expanded
857 -- into a loop. Locate scope of type definition, if any.
859 Scop
:= Current_Scope
;
860 while Ekind
(Scop
) = E_Loop
loop
861 Scop
:= Scope
(Scop
);
864 if Is_Type
(Typ
) then
866 -- OK if we are within the scope of a limited type
867 -- let's mark the component as having per object constraint
869 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
877 Q
: Node_Id
:= Parent
(N
);
881 and then Nkind
(Q
) /= N_Component_Declaration
887 Set_Has_Per_Object_Constraint
888 (Defining_Identifier
(Q
), True);
892 if Nkind
(P
) = N_Expanded_Name
then
894 ("current instance prefix must be a direct name", P
);
897 -- If a current instance attribute appears in a component
898 -- constraint it must appear alone; other contexts (spec-
899 -- expressions, within a task body) are not subject to this
902 if not In_Spec_Expression
903 and then not Has_Completion
(Scop
)
905 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
906 N_Index_Or_Discriminant_Constraint
)
909 ("current instance attribute must appear alone", N
);
912 if Is_CPP_Class
(Root_Type
(Typ
)) then
914 ("??current instance unsupported for derivations of "
915 & "'C'P'P types", N
);
918 -- OK if we are in initialization procedure for the type
919 -- in question, in which case the reference to the type
920 -- is rewritten as a reference to the current object.
922 elsif Ekind
(Scop
) = E_Procedure
923 and then Is_Init_Proc
(Scop
)
924 and then Etype
(First_Formal
(Scop
)) = Typ
927 Make_Attribute_Reference
(Loc
,
928 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
929 Attribute_Name
=> Name_Unrestricted_Access
));
933 -- OK if a task type, this test needs sharpening up ???
935 elsif Is_Task_Type
(Typ
) then
938 -- OK if self-reference in an aggregate in Ada 2005, and
939 -- the reference comes from a copied default expression.
941 -- Note that we check legality of self-reference even if the
942 -- expression comes from source, e.g. when a single component
943 -- association in an aggregate has a box association.
945 elsif Ada_Version
>= Ada_2005
946 and then OK_Self_Reference
950 -- OK if reference to current instance of a protected object
952 elsif Is_Protected_Self_Reference
(P
) then
955 -- Otherwise we have an error case
958 Error_Attr
("% attribute cannot be applied to type", P
);
964 -- If we fall through, we have a normal access to object case
966 -- Unrestricted_Access is (for now) legal wherever an allocator would
967 -- be legal, so its Etype is set to E_Allocator. The expected type
968 -- of the other attributes is a general access type, and therefore
969 -- we label them with E_Access_Attribute_Type.
971 if not Is_Overloaded
(P
) then
972 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
973 Set_Etype
(N
, Acc_Type
);
977 Index
: Interp_Index
;
980 Set_Etype
(N
, Any_Type
);
981 Get_First_Interp
(P
, Index
, It
);
982 while Present
(It
.Typ
) loop
983 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
984 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
985 Get_Next_Interp
(Index
, It
);
990 -- Special cases when we can find a prefix that is an entity name
999 if Is_Entity_Name
(PP
) then
1002 -- If we have an access to an object, and the attribute
1003 -- comes from source, then set the object as potentially
1004 -- source modified. We do this because the resulting access
1005 -- pointer can be used to modify the variable, and we might
1006 -- not detect this, leading to some junk warnings.
1008 -- We only do this for source references, since otherwise
1009 -- we can suppress warnings, e.g. from the unrestricted
1010 -- access generated for validity checks in -gnatVa mode.
1012 if Comes_From_Source
(N
) then
1013 Set_Never_Set_In_Source
(Ent
, False);
1016 -- Mark entity as address taken, and kill current values
1018 Set_Address_Taken
(Ent
);
1019 Kill_Current_Values
(Ent
);
1022 elsif Nkind_In
(PP
, N_Selected_Component
,
1023 N_Indexed_Component
)
1033 -- Check for aliased view.. We allow a nonaliased prefix when within
1034 -- an instance because the prefix may have been a tagged formal
1035 -- object, which is defined to be aliased even when the actual
1036 -- might not be (other instance cases will have been caught in the
1037 -- generic). Similarly, within an inlined body we know that the
1038 -- attribute is legal in the original subprogram, and therefore
1039 -- legal in the expansion.
1041 if not Is_Aliased_View
(P
)
1042 and then not In_Instance
1043 and then not In_Inlined_Body
1045 -- Here we have a non-aliased view. This is illegal unless we
1046 -- have the case of Unrestricted_Access, where for now we allow
1047 -- this (we will reject later if expected type is access to an
1048 -- unconstrained array with a thin pointer).
1050 if Aname
/= Name_Unrestricted_Access
then
1051 Error_Attr_P
("prefix of % attribute must be aliased");
1052 Check_No_Implicit_Aliasing
(P
);
1054 -- For Unrestricted_Access, record that prefix is not aliased
1055 -- to simplify legality check later on.
1058 Set_Non_Aliased_Prefix
(N
);
1061 -- If we have an aliased view, and we have Unrestricted_Access, then
1062 -- output a warning that Unchecked_Access would have been fine, and
1063 -- change the node to be Unchecked_Access.
1066 -- For now, hold off on this change ???
1070 end Analyze_Access_Attribute
;
1072 ---------------------------------
1073 -- Bad_Attribute_For_Predicate --
1074 ---------------------------------
1076 procedure Bad_Attribute_For_Predicate
is
1078 if Is_Scalar_Type
(P_Type
)
1079 and then Comes_From_Source
(N
)
1081 Error_Msg_Name_1
:= Aname
;
1082 Bad_Predicated_Subtype_Use
1083 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1085 end Bad_Attribute_For_Predicate
;
1087 --------------------------------
1088 -- Check_Array_Or_Scalar_Type --
1089 --------------------------------
1091 procedure Check_Array_Or_Scalar_Type
is
1095 -- Dimension number for array attributes
1098 -- Case of string literal or string literal subtype. These cases
1099 -- cannot arise from legal Ada code, but the expander is allowed
1100 -- to generate them. They require special handling because string
1101 -- literal subtypes do not have standard bounds (the whole idea
1102 -- of these subtypes is to avoid having to generate the bounds)
1104 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1105 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1110 elsif Is_Scalar_Type
(P_Type
) then
1113 if Present
(E1
) then
1114 Error_Attr
("invalid argument in % attribute", E1
);
1116 Set_Etype
(N
, P_Base_Type
);
1120 -- The following is a special test to allow 'First to apply to
1121 -- private scalar types if the attribute comes from generated
1122 -- code. This occurs in the case of Normalize_Scalars code.
1124 elsif Is_Private_Type
(P_Type
)
1125 and then Present
(Full_View
(P_Type
))
1126 and then Is_Scalar_Type
(Full_View
(P_Type
))
1127 and then not Comes_From_Source
(N
)
1129 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1131 -- Array types other than string literal subtypes handled above
1136 -- We know prefix is an array type, or the name of an array
1137 -- object, and that the expression, if present, is static
1138 -- and within the range of the dimensions of the type.
1140 pragma Assert
(Is_Array_Type
(P_Type
));
1141 Index
:= First_Index
(P_Base_Type
);
1145 -- First dimension assumed
1147 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1150 D
:= UI_To_Int
(Intval
(E1
));
1152 for J
in 1 .. D
- 1 loop
1156 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1157 Set_Etype
(E1
, Standard_Integer
);
1160 end Check_Array_Or_Scalar_Type
;
1162 ----------------------
1163 -- Check_Array_Type --
1164 ----------------------
1166 procedure Check_Array_Type
is
1168 -- Dimension number for array attributes
1171 -- If the type is a string literal type, then this must be generated
1172 -- internally, and no further check is required on its legality.
1174 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1177 -- If the type is a composite, it is an illegal aggregate, no point
1180 elsif P_Type
= Any_Composite
then
1181 raise Bad_Attribute
;
1184 -- Normal case of array type or subtype
1186 Check_Either_E0_Or_E1
;
1189 if Is_Array_Type
(P_Type
) then
1190 if not Is_Constrained
(P_Type
)
1191 and then Is_Entity_Name
(P
)
1192 and then Is_Type
(Entity
(P
))
1194 -- Note: we do not call Error_Attr here, since we prefer to
1195 -- continue, using the relevant index type of the array,
1196 -- even though it is unconstrained. This gives better error
1197 -- recovery behavior.
1199 Error_Msg_Name_1
:= Aname
;
1201 ("prefix for % attribute must be constrained array", P
);
1204 -- The attribute reference freezes the type, and thus the
1205 -- component type, even if the attribute may not depend on the
1206 -- component. Diagnose arrays with incomplete components now.
1207 -- If the prefix is an access to array, this does not freeze
1208 -- the designated type.
1210 if Nkind
(P
) /= N_Explicit_Dereference
then
1211 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1214 D
:= Number_Dimensions
(P_Type
);
1217 if Is_Private_Type
(P_Type
) then
1218 Error_Attr_P
("prefix for % attribute may not be private type");
1220 elsif Is_Access_Type
(P_Type
)
1221 and then Is_Array_Type
(Designated_Type
(P_Type
))
1222 and then Is_Entity_Name
(P
)
1223 and then Is_Type
(Entity
(P
))
1225 Error_Attr_P
("prefix of % attribute cannot be access type");
1227 elsif Attr_Id
= Attribute_First
1229 Attr_Id
= Attribute_Last
1231 Error_Attr
("invalid prefix for % attribute", P
);
1234 Error_Attr_P
("prefix for % attribute must be array");
1238 if Present
(E1
) then
1239 Resolve
(E1
, Any_Integer
);
1240 Set_Etype
(E1
, Standard_Integer
);
1242 if not Is_OK_Static_Expression
(E1
)
1243 or else Raises_Constraint_Error
(E1
)
1245 Flag_Non_Static_Expr
1246 ("expression for dimension must be static!", E1
);
1249 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1250 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1252 Error_Attr
("invalid dimension number for array type", E1
);
1256 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1257 and then Comes_From_Source
(N
)
1259 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1261 end Check_Array_Type
;
1263 -------------------------
1264 -- Check_Asm_Attribute --
1265 -------------------------
1267 procedure Check_Asm_Attribute
is
1272 -- Check first argument is static string expression
1274 Analyze_And_Resolve
(E1
, Standard_String
);
1276 if Etype
(E1
) = Any_Type
then
1279 elsif not Is_OK_Static_Expression
(E1
) then
1280 Flag_Non_Static_Expr
1281 ("constraint argument must be static string expression!", E1
);
1285 -- Check second argument is right type
1287 Analyze_And_Resolve
(E2
, Entity
(P
));
1289 -- Note: that is all we need to do, we don't need to check
1290 -- that it appears in a correct context. The Ada type system
1291 -- will do that for us.
1293 end Check_Asm_Attribute
;
1295 ---------------------
1296 -- Check_Component --
1297 ---------------------
1299 procedure Check_Component
is
1303 if Nkind
(P
) /= N_Selected_Component
1305 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1307 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1309 Error_Attr_P
("prefix for % attribute must be selected component");
1311 end Check_Component
;
1313 ------------------------------------
1314 -- Check_Decimal_Fixed_Point_Type --
1315 ------------------------------------
1317 procedure Check_Decimal_Fixed_Point_Type
is
1321 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1322 Error_Attr_P
("prefix of % attribute must be decimal type");
1324 end Check_Decimal_Fixed_Point_Type
;
1326 -----------------------
1327 -- Check_Dereference --
1328 -----------------------
1330 procedure Check_Dereference
is
1333 -- Case of a subtype mark
1335 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1339 -- Case of an expression
1343 if Is_Access_Type
(P_Type
) then
1345 -- If there is an implicit dereference, then we must freeze the
1346 -- designated type of the access type, since the type of the
1347 -- referenced array is this type (see AI95-00106).
1349 -- As done elsewhere, freezing must not happen when pre-analyzing
1350 -- a pre- or postcondition or a default value for an object or for
1351 -- a formal parameter.
1353 if not In_Spec_Expression
then
1354 Freeze_Before
(N
, Designated_Type
(P_Type
));
1358 Make_Explicit_Dereference
(Sloc
(P
),
1359 Prefix
=> Relocate_Node
(P
)));
1361 Analyze_And_Resolve
(P
);
1362 P_Type
:= Etype
(P
);
1364 if P_Type
= Any_Type
then
1365 raise Bad_Attribute
;
1368 P_Base_Type
:= Base_Type
(P_Type
);
1370 end Check_Dereference
;
1372 -------------------------
1373 -- Check_Discrete_Type --
1374 -------------------------
1376 procedure Check_Discrete_Type
is
1380 if not Is_Discrete_Type
(P_Type
) then
1381 Error_Attr_P
("prefix of % attribute must be discrete type");
1383 end Check_Discrete_Type
;
1389 procedure Check_E0
is
1391 if Present
(E1
) then
1392 Unexpected_Argument
(E1
);
1400 procedure Check_E1
is
1402 Check_Either_E0_Or_E1
;
1406 -- Special-case attributes that are functions and that appear as
1407 -- the prefix of another attribute. Error is posted on parent.
1409 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1410 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1414 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1415 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1416 Set_Etype
(Parent
(N
), Any_Type
);
1417 Set_Entity
(Parent
(N
), Any_Type
);
1418 raise Bad_Attribute
;
1421 Error_Attr
("missing argument for % attribute", N
);
1430 procedure Check_E2
is
1433 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1435 Error_Attr
("missing argument for % attribute (2 required)", N
);
1439 ---------------------------
1440 -- Check_Either_E0_Or_E1 --
1441 ---------------------------
1443 procedure Check_Either_E0_Or_E1
is
1445 if Present
(E2
) then
1446 Unexpected_Argument
(E2
);
1448 end Check_Either_E0_Or_E1
;
1450 ----------------------
1451 -- Check_Enum_Image --
1452 ----------------------
1454 procedure Check_Enum_Image
is
1458 -- When an enumeration type appears in an attribute reference, all
1459 -- literals of the type are marked as referenced. This must only be
1460 -- done if the attribute reference appears in the current source.
1461 -- Otherwise the information on references may differ between a
1462 -- normal compilation and one that performs inlining.
1464 if Is_Enumeration_Type
(P_Base_Type
)
1465 and then In_Extended_Main_Code_Unit
(N
)
1467 Lit
:= First_Literal
(P_Base_Type
);
1468 while Present
(Lit
) loop
1469 Set_Referenced
(Lit
);
1473 end Check_Enum_Image
;
1475 ----------------------------
1476 -- Check_First_Last_Valid --
1477 ----------------------------
1479 procedure Check_First_Last_Valid
is
1481 Check_Discrete_Type
;
1483 -- Freeze the subtype now, so that the following test for predicates
1484 -- works (we set the predicates stuff up at freeze time)
1486 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1488 -- Now test for dynamic predicate
1490 if Has_Predicates
(P_Type
)
1491 and then not (Has_Static_Predicate
(P_Type
))
1494 ("prefix of % attribute may not have dynamic predicate");
1497 -- Check non-static subtype
1499 if not Is_OK_Static_Subtype
(P_Type
) then
1500 Error_Attr_P
("prefix of % attribute must be a static subtype");
1503 -- Test case for no values
1505 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1506 Expr_Value
(Type_High_Bound
(P_Type
))
1507 or else (Has_Predicates
(P_Type
)
1509 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1512 ("prefix of % attribute must be subtype with at least one "
1515 end Check_First_Last_Valid
;
1517 ----------------------------
1518 -- Check_Fixed_Point_Type --
1519 ----------------------------
1521 procedure Check_Fixed_Point_Type
is
1525 if not Is_Fixed_Point_Type
(P_Type
) then
1526 Error_Attr_P
("prefix of % attribute must be fixed point type");
1528 end Check_Fixed_Point_Type
;
1530 ------------------------------
1531 -- Check_Fixed_Point_Type_0 --
1532 ------------------------------
1534 procedure Check_Fixed_Point_Type_0
is
1536 Check_Fixed_Point_Type
;
1538 end Check_Fixed_Point_Type_0
;
1540 -------------------------------
1541 -- Check_Floating_Point_Type --
1542 -------------------------------
1544 procedure Check_Floating_Point_Type
is
1548 if not Is_Floating_Point_Type
(P_Type
) then
1549 Error_Attr_P
("prefix of % attribute must be float type");
1551 end Check_Floating_Point_Type
;
1553 ---------------------------------
1554 -- Check_Floating_Point_Type_0 --
1555 ---------------------------------
1557 procedure Check_Floating_Point_Type_0
is
1559 Check_Floating_Point_Type
;
1561 end Check_Floating_Point_Type_0
;
1563 ---------------------------------
1564 -- Check_Floating_Point_Type_1 --
1565 ---------------------------------
1567 procedure Check_Floating_Point_Type_1
is
1569 Check_Floating_Point_Type
;
1571 end Check_Floating_Point_Type_1
;
1573 ---------------------------------
1574 -- Check_Floating_Point_Type_2 --
1575 ---------------------------------
1577 procedure Check_Floating_Point_Type_2
is
1579 Check_Floating_Point_Type
;
1581 end Check_Floating_Point_Type_2
;
1583 ------------------------
1584 -- Check_Integer_Type --
1585 ------------------------
1587 procedure Check_Integer_Type
is
1591 if not Is_Integer_Type
(P_Type
) then
1592 Error_Attr_P
("prefix of % attribute must be integer type");
1594 end Check_Integer_Type
;
1596 --------------------------------
1597 -- Check_Modular_Integer_Type --
1598 --------------------------------
1600 procedure Check_Modular_Integer_Type
is
1604 if not Is_Modular_Integer_Type
(P_Type
) then
1606 ("prefix of % attribute must be modular integer type");
1608 end Check_Modular_Integer_Type
;
1610 ------------------------
1611 -- Check_Not_CPP_Type --
1612 ------------------------
1614 procedure Check_Not_CPP_Type
is
1616 if Is_Tagged_Type
(Etype
(P
))
1617 and then Convention
(Etype
(P
)) = Convention_CPP
1618 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1621 ("invalid use of % attribute with 'C'P'P tagged type");
1623 end Check_Not_CPP_Type
;
1625 -------------------------------
1626 -- Check_Not_Incomplete_Type --
1627 -------------------------------
1629 procedure Check_Not_Incomplete_Type
is
1634 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1635 -- dereference we have to check wrong uses of incomplete types
1636 -- (other wrong uses are checked at their freezing point).
1638 -- Example 1: Limited-with
1640 -- limited with Pkg;
1642 -- type Acc is access Pkg.T;
1644 -- S : Integer := X.all'Size; -- ERROR
1647 -- Example 2: Tagged incomplete
1649 -- type T is tagged;
1650 -- type Acc is access all T;
1652 -- S : constant Integer := X.all'Size; -- ERROR
1653 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1655 if Ada_Version
>= Ada_2005
1656 and then Nkind
(P
) = N_Explicit_Dereference
1659 while Nkind
(E
) = N_Explicit_Dereference
loop
1665 if From_Limited_With
(Typ
) then
1667 ("prefix of % attribute cannot be an incomplete type");
1670 if Is_Access_Type
(Typ
) then
1671 Typ
:= Directly_Designated_Type
(Typ
);
1674 if Is_Class_Wide_Type
(Typ
) then
1675 Typ
:= Root_Type
(Typ
);
1678 -- A legal use of a shadow entity occurs only when the unit
1679 -- where the non-limited view resides is imported via a regular
1680 -- with clause in the current body. Such references to shadow
1681 -- entities may occur in subprogram formals.
1683 if Is_Incomplete_Type
(Typ
)
1684 and then From_Limited_With
(Typ
)
1685 and then Present
(Non_Limited_View
(Typ
))
1686 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1688 Typ
:= Non_Limited_View
(Typ
);
1691 if Ekind
(Typ
) = E_Incomplete_Type
1692 and then No
(Full_View
(Typ
))
1695 ("prefix of % attribute cannot be an incomplete type");
1700 if not Is_Entity_Name
(P
)
1701 or else not Is_Type
(Entity
(P
))
1702 or else In_Spec_Expression
1706 Check_Fully_Declared
(P_Type
, P
);
1708 end Check_Not_Incomplete_Type
;
1710 ----------------------------
1711 -- Check_Object_Reference --
1712 ----------------------------
1714 procedure Check_Object_Reference
(P
: Node_Id
) is
1718 -- If we need an object, and we have a prefix that is the name of
1719 -- a function entity, convert it into a function call.
1721 if Is_Entity_Name
(P
)
1722 and then Ekind
(Entity
(P
)) = E_Function
1724 Rtyp
:= Etype
(Entity
(P
));
1727 Make_Function_Call
(Sloc
(P
),
1728 Name
=> Relocate_Node
(P
)));
1730 Analyze_And_Resolve
(P
, Rtyp
);
1732 -- Otherwise we must have an object reference
1734 elsif not Is_Object_Reference
(P
) then
1735 Error_Attr_P
("prefix of % attribute must be object");
1737 end Check_Object_Reference
;
1739 ----------------------------
1740 -- Check_PolyORB_Attribute --
1741 ----------------------------
1743 procedure Check_PolyORB_Attribute
is
1745 Validate_Non_Static_Attribute_Function_Call
;
1750 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1752 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1754 end Check_PolyORB_Attribute
;
1756 ------------------------
1757 -- Check_Program_Unit --
1758 ------------------------
1760 procedure Check_Program_Unit
is
1762 if Is_Entity_Name
(P
) then
1764 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1765 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1768 if K
in Subprogram_Kind
1769 or else K
in Task_Kind
1770 or else K
in Protected_Kind
1771 or else K
= E_Package
1772 or else K
in Generic_Unit_Kind
1773 or else (K
= E_Variable
1777 Is_Protected_Type
(T
)))
1784 Error_Attr_P
("prefix of % attribute must be program unit");
1785 end Check_Program_Unit
;
1787 ---------------------
1788 -- Check_Real_Type --
1789 ---------------------
1791 procedure Check_Real_Type
is
1795 if not Is_Real_Type
(P_Type
) then
1796 Error_Attr_P
("prefix of % attribute must be real type");
1798 end Check_Real_Type
;
1800 -----------------------
1801 -- Check_Scalar_Type --
1802 -----------------------
1804 procedure Check_Scalar_Type
is
1808 if not Is_Scalar_Type
(P_Type
) then
1809 Error_Attr_P
("prefix of % attribute must be scalar type");
1811 end Check_Scalar_Type
;
1813 ------------------------------------------
1814 -- Check_SPARK_05_Restriction_On_Attribute --
1815 ------------------------------------------
1817 procedure Check_SPARK_05_Restriction_On_Attribute
is
1819 Error_Msg_Name_1
:= Aname
;
1820 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
1821 end Check_SPARK_05_Restriction_On_Attribute
;
1823 ---------------------------
1824 -- Check_Standard_Prefix --
1825 ---------------------------
1827 procedure Check_Standard_Prefix
is
1831 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
1832 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1834 end Check_Standard_Prefix
;
1836 ----------------------------
1837 -- Check_Stream_Attribute --
1838 ----------------------------
1840 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1844 In_Shared_Var_Procs
: Boolean;
1845 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1846 -- For this runtime package (always compiled in GNAT mode), we allow
1847 -- stream attributes references for limited types for the case where
1848 -- shared passive objects are implemented using stream attributes,
1849 -- which is the default in GNAT's persistent storage implementation.
1852 Validate_Non_Static_Attribute_Function_Call
;
1854 -- With the exception of 'Input, Stream attributes are procedures,
1855 -- and can only appear at the position of procedure calls. We check
1856 -- for this here, before they are rewritten, to give a more precise
1859 if Nam
= TSS_Stream_Input
then
1862 elsif Is_List_Member
(N
)
1863 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1870 ("invalid context for attribute%, which is a procedure", N
);
1874 Btyp
:= Implementation_Base_Type
(P_Type
);
1876 -- Stream attributes not allowed on limited types unless the
1877 -- attribute reference was generated by the expander (in which
1878 -- case the underlying type will be used, as described in Sinfo),
1879 -- or the attribute was specified explicitly for the type itself
1880 -- or one of its ancestors (taking visibility rules into account if
1881 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1882 -- (with no visibility restriction).
1885 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1887 if Present
(Gen_Body
) then
1888 In_Shared_Var_Procs
:=
1889 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1891 In_Shared_Var_Procs
:= False;
1895 if (Comes_From_Source
(N
)
1896 and then not (In_Shared_Var_Procs
or In_Instance
))
1897 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1898 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1900 Error_Msg_Name_1
:= Aname
;
1902 if Is_Limited_Type
(P_Type
) then
1904 ("limited type& has no% attribute", P
, P_Type
);
1905 Explain_Limited_Type
(P_Type
, P
);
1908 ("attribute% for type& is not available", P
, P_Type
);
1912 -- Check for no stream operations allowed from No_Tagged_Streams
1914 if Is_Tagged_Type
(P_Type
)
1915 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
1917 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
1919 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
1923 -- Check restriction violations
1925 -- First check the No_Streams restriction, which prohibits the use
1926 -- of explicit stream attributes in the source program. We do not
1927 -- prevent the occurrence of stream attributes in generated code,
1928 -- for instance those generated implicitly for dispatching purposes.
1930 if Comes_From_Source
(N
) then
1931 Check_Restriction
(No_Streams
, P
);
1934 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1935 -- it is illegal to use a predefined elementary type stream attribute
1936 -- either by itself, or more importantly as part of the attribute
1937 -- subprogram for a composite type. However, if the broader
1938 -- restriction No_Streams is active, stream operations are not
1939 -- generated, and there is no error.
1941 if Restriction_Active
(No_Default_Stream_Attributes
)
1942 and then not Restriction_Active
(No_Streams
)
1948 if Nam
= TSS_Stream_Input
1950 Nam
= TSS_Stream_Read
1953 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1956 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1960 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1963 ("missing user-defined Stream Read or Write for type&",
1965 if not Is_Elementary_Type
(P_Type
) then
1967 ("\which is a component of type&", N
, P_Type
);
1973 -- Check special case of Exception_Id and Exception_Occurrence which
1974 -- are not allowed for restriction No_Exception_Registration.
1976 if Restriction_Check_Required
(No_Exception_Registration
)
1977 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1979 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1981 Check_Restriction
(No_Exception_Registration
, P
);
1984 -- Here we must check that the first argument is an access type
1985 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1987 Analyze_And_Resolve
(E1
);
1990 -- Note: the double call to Root_Type here is needed because the
1991 -- root type of a class-wide type is the corresponding type (e.g.
1992 -- X for X'Class, and we really want to go to the root.)
1994 if not Is_Access_Type
(Etyp
)
1995 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1996 RTE
(RE_Root_Stream_Type
)
1999 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2002 -- Check that the second argument is of the right type if there is
2003 -- one (the Input attribute has only one argument so this is skipped)
2005 if Present
(E2
) then
2008 if Nam
= TSS_Stream_Read
2009 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2012 ("second argument of % attribute must be a variable", E2
);
2015 Resolve
(E2
, P_Type
);
2019 end Check_Stream_Attribute
;
2021 -------------------------
2022 -- Check_System_Prefix --
2023 -------------------------
2025 procedure Check_System_Prefix
is
2027 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2028 Error_Attr
("only allowed prefix for % attribute is System", P
);
2030 end Check_System_Prefix
;
2032 -----------------------
2033 -- Check_Task_Prefix --
2034 -----------------------
2036 procedure Check_Task_Prefix
is
2040 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2041 -- task interface class-wide types.
2043 if Is_Task_Type
(Etype
(P
))
2044 or else (Is_Access_Type
(Etype
(P
))
2045 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2046 or else (Ada_Version
>= Ada_2005
2047 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2048 and then Is_Interface
(Etype
(P
))
2049 and then Is_Task_Interface
(Etype
(P
)))
2054 if Ada_Version
>= Ada_2005
then
2056 ("prefix of % attribute must be a task or a task " &
2057 "interface class-wide object");
2060 Error_Attr_P
("prefix of % attribute must be a task");
2063 end Check_Task_Prefix
;
2069 -- The possibilities are an entity name denoting a type, or an
2070 -- attribute reference that denotes a type (Base or Class). If
2071 -- the type is incomplete, replace it with its full view.
2073 procedure Check_Type
is
2075 if not Is_Entity_Name
(P
)
2076 or else not Is_Type
(Entity
(P
))
2078 Error_Attr_P
("prefix of % attribute must be a type");
2080 elsif Is_Protected_Self_Reference
(P
) then
2082 ("prefix of % attribute denotes current instance "
2083 & "(RM 9.4(21/2))");
2085 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2086 and then Present
(Full_View
(Entity
(P
)))
2088 P_Type
:= Full_View
(Entity
(P
));
2089 Set_Entity
(P
, P_Type
);
2093 ---------------------
2094 -- Check_Unit_Name --
2095 ---------------------
2097 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2099 if Nkind
(Nod
) = N_Identifier
then
2102 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2103 Check_Unit_Name
(Prefix
(Nod
));
2105 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2110 Error_Attr
("argument for % attribute must be unit name", P
);
2111 end Check_Unit_Name
;
2117 procedure Error_Attr
is
2119 Set_Etype
(N
, Any_Type
);
2120 Set_Entity
(N
, Any_Type
);
2121 raise Bad_Attribute
;
2124 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2126 Error_Msg_Name_1
:= Aname
;
2127 Error_Msg_N
(Msg
, Error_Node
);
2135 procedure Error_Attr_P
(Msg
: String) is
2137 Error_Msg_Name_1
:= Aname
;
2138 Error_Msg_F
(Msg
, P
);
2142 ---------------------
2143 -- In_Refined_Post --
2144 ---------------------
2146 function In_Refined_Post
return Boolean is
2147 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean;
2148 -- Determine whether Prag denotes one of the incarnations of pragma
2149 -- Refined_Post (either as is or pragma Check (Refined_Post, ...).
2151 ---------------------
2152 -- Is_Refined_Post --
2153 ---------------------
2155 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean is
2156 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
2157 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2160 if Nam
= Name_Refined_Post
then
2163 elsif Nam
= Name_Check
then
2164 pragma Assert
(Present
(Args
));
2166 return Chars
(Expression
(First
(Args
))) = Name_Refined_Post
;
2170 end Is_Refined_Post
;
2176 -- Start of processing for In_Refined_Post
2180 while Present
(Stmt
) loop
2181 if Nkind
(Stmt
) = N_Pragma
and then Is_Refined_Post
(Stmt
) then
2184 -- Prevent the search from going too far
2186 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
2190 Stmt
:= Parent
(Stmt
);
2194 end In_Refined_Post
;
2196 ----------------------------
2197 -- Legal_Formal_Attribute --
2198 ----------------------------
2200 procedure Legal_Formal_Attribute
is
2204 if not Is_Entity_Name
(P
)
2205 or else not Is_Type
(Entity
(P
))
2207 Error_Attr_P
("prefix of % attribute must be generic type");
2209 elsif Is_Generic_Actual_Type
(Entity
(P
))
2211 or else In_Inlined_Body
2215 elsif Is_Generic_Type
(Entity
(P
)) then
2216 if not Is_Indefinite_Subtype
(Entity
(P
)) then
2218 ("prefix of % attribute must be indefinite generic type");
2223 ("prefix of % attribute must be indefinite generic type");
2226 Set_Etype
(N
, Standard_Boolean
);
2227 end Legal_Formal_Attribute
;
2229 ---------------------------------------------------------------
2230 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2231 ---------------------------------------------------------------
2233 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2237 Check_Not_Incomplete_Type
;
2238 Set_Etype
(N
, Universal_Integer
);
2239 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2245 procedure Min_Max
is
2249 Resolve
(E1
, P_Base_Type
);
2250 Resolve
(E2
, P_Base_Type
);
2251 Set_Etype
(N
, P_Base_Type
);
2253 -- Check for comparison on unordered enumeration type
2255 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2256 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2258 ("comparison on unordered enumeration type& declared#?U?",
2263 ------------------------
2264 -- Standard_Attribute --
2265 ------------------------
2267 procedure Standard_Attribute
(Val
: Int
) is
2269 Check_Standard_Prefix
;
2270 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2272 Set_Is_Static_Expression
(N
, True);
2273 end Standard_Attribute
;
2275 --------------------
2276 -- Uneval_Old_Msg --
2277 --------------------
2279 procedure Uneval_Old_Msg
is
2280 Uneval_Old_Setting
: Character;
2284 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2285 -- N_Aspect_Specification node that corresponds to the attribute.
2287 -- First find the pragma in which we appear (note that at this stage,
2288 -- even if we appeared originally within an aspect specification, we
2289 -- are now within the corresponding pragma).
2293 Prag
:= Parent
(Prag
);
2294 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2297 if Present
(Prag
) then
2298 if Uneval_Old_Accept
(Prag
) then
2299 Uneval_Old_Setting
:= 'A';
2300 elsif Uneval_Old_Warn
(Prag
) then
2301 Uneval_Old_Setting
:= 'W';
2303 Uneval_Old_Setting
:= 'E';
2306 -- If we did not find the pragma, that's odd, just use the setting
2307 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2310 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2313 -- Processing depends on the setting of Uneval_Old
2315 case Uneval_Old_Setting
is
2318 ("prefix of attribute % that is potentially "
2319 & "unevaluated must denote an entity");
2322 Error_Msg_Name_1
:= Aname
;
2324 ("??prefix of attribute % appears in potentially "
2325 & "unevaluated context, exception may be raised", P
);
2331 raise Program_Error
;
2335 -------------------------
2336 -- Unexpected Argument --
2337 -------------------------
2339 procedure Unexpected_Argument
(En
: Node_Id
) is
2341 Error_Attr
("unexpected argument for % attribute", En
);
2342 end Unexpected_Argument
;
2344 -------------------------------------------------
2345 -- Validate_Non_Static_Attribute_Function_Call --
2346 -------------------------------------------------
2348 -- This function should be moved to Sem_Dist ???
2350 procedure Validate_Non_Static_Attribute_Function_Call
is
2352 if In_Preelaborated_Unit
2353 and then not In_Subprogram_Or_Concurrent_Unit
2355 Flag_Non_Static_Expr
2356 ("non-static function call in preelaborated unit!", N
);
2358 end Validate_Non_Static_Attribute_Function_Call
;
2360 -- Start of processing for Analyze_Attribute
2363 -- Immediate return if unrecognized attribute (already diagnosed
2364 -- by parser, so there is nothing more that we need to do)
2366 if not Is_Attribute_Name
(Aname
) then
2367 raise Bad_Attribute
;
2370 -- Deal with Ada 83 issues
2372 if Comes_From_Source
(N
) then
2373 if not Attribute_83
(Attr_Id
) then
2374 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2375 Error_Msg_Name_1
:= Aname
;
2376 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2379 if Attribute_Impl_Def
(Attr_Id
) then
2380 Check_Restriction
(No_Implementation_Attributes
, N
);
2385 -- Deal with Ada 2005 attributes that are implementation attributes
2386 -- because they appear in a version of Ada before Ada 2005, and
2387 -- similarly for Ada 2012 attributes appearing in an earlier version.
2389 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2391 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2393 Check_Restriction
(No_Implementation_Attributes
, N
);
2396 -- Remote access to subprogram type access attribute reference needs
2397 -- unanalyzed copy for tree transformation. The analyzed copy is used
2398 -- for its semantic information (whether prefix is a remote subprogram
2399 -- name), the unanalyzed copy is used to construct new subtree rooted
2400 -- with N_Aggregate which represents a fat pointer aggregate.
2402 if Aname
= Name_Access
then
2403 Discard_Node
(Copy_Separate_Tree
(N
));
2406 -- Analyze prefix and exit if error in analysis. If the prefix is an
2407 -- incomplete type, use full view if available. Note that there are
2408 -- some attributes for which we do not analyze the prefix, since the
2409 -- prefix is not a normal name, or else needs special handling.
2411 if Aname
/= Name_Elab_Body
and then
2412 Aname
/= Name_Elab_Spec
and then
2413 Aname
/= Name_Elab_Subp_Body
and then
2414 Aname
/= Name_UET_Address
and then
2415 Aname
/= Name_Enabled
and then
2419 P_Type
:= Etype
(P
);
2421 if Is_Entity_Name
(P
)
2422 and then Present
(Entity
(P
))
2423 and then Is_Type
(Entity
(P
))
2425 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2426 P_Type
:= Get_Full_View
(P_Type
);
2427 Set_Entity
(P
, P_Type
);
2428 Set_Etype
(P
, P_Type
);
2430 elsif Entity
(P
) = Current_Scope
2431 and then Is_Record_Type
(Entity
(P
))
2433 -- Use of current instance within the type. Verify that if the
2434 -- attribute appears within a constraint, it yields an access
2435 -- type, other uses are illegal.
2443 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2445 Par
:= Parent
(Par
);
2449 and then Nkind
(Par
) = N_Subtype_Indication
2451 if Attr_Id
/= Attribute_Access
2452 and then Attr_Id
/= Attribute_Unchecked_Access
2453 and then Attr_Id
/= Attribute_Unrestricted_Access
2456 ("in a constraint the current instance can only"
2457 & " be used with an access attribute", N
);
2464 if P_Type
= Any_Type
then
2465 raise Bad_Attribute
;
2468 P_Base_Type
:= Base_Type
(P_Type
);
2471 -- Analyze expressions that may be present, exiting if an error occurs
2478 E1
:= First
(Exprs
);
2480 -- Skip analysis for case of Restriction_Set, we do not expect
2481 -- the argument to be analyzed in this case.
2483 if Aname
/= Name_Restriction_Set
then
2486 -- Check for missing/bad expression (result of previous error)
2488 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2489 raise Bad_Attribute
;
2495 if Present
(E2
) then
2498 if Etype
(E2
) = Any_Type
then
2499 raise Bad_Attribute
;
2502 if Present
(Next
(E2
)) then
2503 Unexpected_Argument
(Next
(E2
));
2508 -- Cases where prefix must be resolvable by itself
2510 if Is_Overloaded
(P
)
2511 and then Aname
/= Name_Access
2512 and then Aname
/= Name_Address
2513 and then Aname
/= Name_Code_Address
2514 and then Aname
/= Name_Result
2515 and then Aname
/= Name_Unchecked_Access
2517 -- The prefix must be resolvable by itself, without reference to the
2518 -- attribute. One case that requires special handling is a prefix
2519 -- that is a function name, where one interpretation may be a
2520 -- parameterless call. Entry attributes are handled specially below.
2522 if Is_Entity_Name
(P
)
2523 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2525 Check_Parameterless_Call
(P
);
2528 if Is_Overloaded
(P
) then
2530 -- Ada 2005 (AI-345): Since protected and task types have
2531 -- primitive entry wrappers, the attributes Count, and Caller
2532 -- require a context check
2534 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2536 Count
: Natural := 0;
2541 Get_First_Interp
(P
, I
, It
);
2542 while Present
(It
.Nam
) loop
2543 if Comes_From_Source
(It
.Nam
) then
2549 Get_Next_Interp
(I
, It
);
2553 Error_Attr
("ambiguous prefix for % attribute", P
);
2555 Set_Is_Overloaded
(P
, False);
2560 Error_Attr
("ambiguous prefix for % attribute", P
);
2565 -- In SPARK, attributes of private types are only allowed if the full
2566 -- type declaration is visible.
2568 -- Note: the check for Present (Entity (P)) defends against some error
2569 -- conditions where the Entity field is not set.
2571 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2572 and then Is_Type
(Entity
(P
))
2573 and then Is_Private_Type
(P_Type
)
2574 and then not In_Open_Scopes
(Scope
(P_Type
))
2575 and then not In_Spec_Expression
2577 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
2580 -- Remaining processing depends on attribute
2584 -- Attributes related to Ada 2012 iterators. Attribute specifications
2585 -- exist for these, but they cannot be queried.
2587 when Attribute_Constant_Indexing |
2588 Attribute_Default_Iterator |
2589 Attribute_Implicit_Dereference |
2590 Attribute_Iterator_Element |
2591 Attribute_Iterable |
2592 Attribute_Variable_Indexing
=>
2593 Error_Msg_N
("illegal attribute", N
);
2595 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2596 -- were already rejected by the parser. Thus they shouldn't appear here.
2598 when Internal_Attribute_Id
=>
2599 raise Program_Error
;
2605 when Attribute_Abort_Signal
=>
2606 Check_Standard_Prefix
;
2607 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
2614 when Attribute_Access
=>
2615 Analyze_Access_Attribute
;
2621 when Attribute_Address
=>
2624 Set_Etype
(N
, RTE
(RE_Address
));
2630 when Attribute_Address_Size
=>
2631 Standard_Attribute
(System_Address_Size
);
2637 when Attribute_Adjacent
=>
2638 Check_Floating_Point_Type_2
;
2639 Set_Etype
(N
, P_Base_Type
);
2640 Resolve
(E1
, P_Base_Type
);
2641 Resolve
(E2
, P_Base_Type
);
2647 when Attribute_Aft
=>
2648 Check_Fixed_Point_Type_0
;
2649 Set_Etype
(N
, Universal_Integer
);
2655 when Attribute_Alignment
=>
2657 -- Don't we need more checking here, cf Size ???
2660 Check_Not_Incomplete_Type
;
2662 Set_Etype
(N
, Universal_Integer
);
2668 when Attribute_Asm_Input
=>
2669 Check_Asm_Attribute
;
2671 -- The back-end may need to take the address of E2
2673 if Is_Entity_Name
(E2
) then
2674 Set_Address_Taken
(Entity
(E2
));
2677 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2683 when Attribute_Asm_Output
=>
2684 Check_Asm_Attribute
;
2686 if Etype
(E2
) = Any_Type
then
2689 elsif Aname
= Name_Asm_Output
then
2690 if not Is_Variable
(E2
) then
2692 ("second argument for Asm_Output is not variable", E2
);
2696 Note_Possible_Modification
(E2
, Sure
=> True);
2698 -- The back-end may need to take the address of E2
2700 if Is_Entity_Name
(E2
) then
2701 Set_Address_Taken
(Entity
(E2
));
2704 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2706 -----------------------------
2707 -- Atomic_Always_Lock_Free --
2708 -----------------------------
2710 when Attribute_Atomic_Always_Lock_Free
=>
2713 Set_Etype
(N
, Standard_Boolean
);
2719 -- Note: when the base attribute appears in the context of a subtype
2720 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2721 -- the following circuit.
2723 when Attribute_Base
=> Base
: declare
2731 if Ada_Version
>= Ada_95
2732 and then not Is_Scalar_Type
(Typ
)
2733 and then not Is_Generic_Type
(Typ
)
2735 Error_Attr_P
("prefix of Base attribute must be scalar type");
2737 elsif Sloc
(Typ
) = Standard_Location
2738 and then Base_Type
(Typ
) = Typ
2739 and then Warn_On_Redundant_Constructs
2741 Error_Msg_NE
-- CODEFIX
2742 ("?r?redundant attribute, & is its own base type", N
, Typ
);
2745 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2746 Error_Msg_Name_1
:= Aname
;
2747 Check_SPARK_05_Restriction
2748 ("attribute% is only allowed as prefix of another attribute", P
);
2751 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2752 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2753 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
2761 when Attribute_Bit
=> Bit
:
2765 if not Is_Object_Reference
(P
) then
2766 Error_Attr_P
("prefix for % attribute must be object");
2768 -- What about the access object cases ???
2774 Set_Etype
(N
, Universal_Integer
);
2781 when Attribute_Bit_Order
=> Bit_Order
:
2786 if not Is_Record_Type
(P_Type
) then
2787 Error_Attr_P
("prefix of % attribute must be record type");
2790 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2792 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2795 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2798 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2801 -- Reset incorrect indication of staticness
2803 Set_Is_Static_Expression
(N
, False);
2810 -- Note: in generated code, we can have a Bit_Position attribute
2811 -- applied to a (naked) record component (i.e. the prefix is an
2812 -- identifier that references an E_Component or E_Discriminant
2813 -- entity directly, and this is interpreted as expected by Gigi.
2814 -- The following code will not tolerate such usage, but when the
2815 -- expander creates this special case, it marks it as analyzed
2816 -- immediately and sets an appropriate type.
2818 when Attribute_Bit_Position
=>
2819 if Comes_From_Source
(N
) then
2823 Set_Etype
(N
, Universal_Integer
);
2829 when Attribute_Body_Version
=>
2832 Set_Etype
(N
, RTE
(RE_Version_String
));
2838 when Attribute_Callable
=>
2840 Set_Etype
(N
, Standard_Boolean
);
2847 when Attribute_Caller
=> Caller
: declare
2854 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2857 if not Is_Entry
(Ent
) then
2858 Error_Attr
("invalid entry name", N
);
2862 Error_Attr
("invalid entry name", N
);
2866 for J
in reverse 0 .. Scope_Stack
.Last
loop
2867 S
:= Scope_Stack
.Table
(J
).Entity
;
2869 if S
= Scope
(Ent
) then
2870 Error_Attr
("Caller must appear in matching accept or body", N
);
2876 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2883 when Attribute_Ceiling
=>
2884 Check_Floating_Point_Type_1
;
2885 Set_Etype
(N
, P_Base_Type
);
2886 Resolve
(E1
, P_Base_Type
);
2892 when Attribute_Class
=>
2893 Check_Restriction
(No_Dispatch
, N
);
2897 -- Applying Class to untagged incomplete type is obsolescent in Ada
2898 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2899 -- this flag gets set by Find_Type in this situation.
2901 if Restriction_Check_Required
(No_Obsolescent_Features
)
2902 and then Ada_Version
>= Ada_2005
2903 and then Ekind
(P_Type
) = E_Incomplete_Type
2906 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2908 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2909 and then not Tagged_Present
(DN
)
2911 Check_Restriction
(No_Obsolescent_Features
, P
);
2920 when Attribute_Code_Address
=>
2923 if Nkind
(P
) = N_Attribute_Reference
2924 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
2928 elsif not Is_Entity_Name
(P
)
2929 or else (Ekind
(Entity
(P
)) /= E_Function
2931 Ekind
(Entity
(P
)) /= E_Procedure
)
2933 Error_Attr
("invalid prefix for % attribute", P
);
2934 Set_Address_Taken
(Entity
(P
));
2936 -- Issue an error if the prefix denotes an eliminated subprogram
2939 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2942 Set_Etype
(N
, RTE
(RE_Address
));
2944 ----------------------
2945 -- Compiler_Version --
2946 ----------------------
2948 when Attribute_Compiler_Version
=>
2950 Check_Standard_Prefix
;
2951 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2952 Analyze_And_Resolve
(N
, Standard_String
);
2953 Set_Is_Static_Expression
(N
, True);
2955 --------------------
2956 -- Component_Size --
2957 --------------------
2959 when Attribute_Component_Size
=>
2961 Set_Etype
(N
, Universal_Integer
);
2963 -- Note: unlike other array attributes, unconstrained arrays are OK
2965 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2975 when Attribute_Compose
=>
2976 Check_Floating_Point_Type_2
;
2977 Set_Etype
(N
, P_Base_Type
);
2978 Resolve
(E1
, P_Base_Type
);
2979 Resolve
(E2
, Any_Integer
);
2985 when Attribute_Constrained
=>
2987 Set_Etype
(N
, Standard_Boolean
);
2989 -- Case from RM J.4(2) of constrained applied to private type
2991 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2992 Check_Restriction
(No_Obsolescent_Features
, P
);
2994 if Warn_On_Obsolescent_Feature
then
2996 ("constrained for private type is an " &
2997 "obsolescent feature (RM J.4)?j?", N
);
3000 -- If we are within an instance, the attribute must be legal
3001 -- because it was valid in the generic unit. Ditto if this is
3002 -- an inlining of a function declared in an instance.
3004 if In_Instance
or else In_Inlined_Body
then
3007 -- For sure OK if we have a real private type itself, but must
3008 -- be completed, cannot apply Constrained to incomplete type.
3010 elsif Is_Private_Type
(Entity
(P
)) then
3012 -- Note: this is one of the Annex J features that does not
3013 -- generate a warning from -gnatwj, since in fact it seems
3014 -- very useful, and is used in the GNAT runtime.
3016 Check_Not_Incomplete_Type
;
3020 -- Normal (non-obsolescent case) of application to object of
3021 -- a discriminated type.
3024 Check_Object_Reference
(P
);
3026 -- If N does not come from source, then we allow the
3027 -- the attribute prefix to be of a private type whose
3028 -- full type has discriminants. This occurs in cases
3029 -- involving expanded calls to stream attributes.
3031 if not Comes_From_Source
(N
) then
3032 P_Type
:= Underlying_Type
(P_Type
);
3035 -- Must have discriminants or be an access type designating
3036 -- a type with discriminants. If it is a classwide type it
3037 -- has unknown discriminants.
3039 if Has_Discriminants
(P_Type
)
3040 or else Has_Unknown_Discriminants
(P_Type
)
3042 (Is_Access_Type
(P_Type
)
3043 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3047 -- The rule given in 3.7.2 is part of static semantics, but the
3048 -- intent is clearly that it be treated as a legality rule, and
3049 -- rechecked in the visible part of an instance. Nevertheless
3050 -- the intent also seems to be it should legally apply to the
3051 -- actual of a formal with unknown discriminants, regardless of
3052 -- whether the actual has discriminants, in which case the value
3053 -- of the attribute is determined using the J.4 rules. This choice
3054 -- seems the most useful, and is compatible with existing tests.
3056 elsif In_Instance
then
3059 -- Also allow an object of a generic type if extensions allowed
3060 -- and allow this for any type at all. (this may be obsolete ???)
3062 elsif (Is_Generic_Type
(P_Type
)
3063 or else Is_Generic_Actual_Type
(P_Type
))
3064 and then Extensions_Allowed
3070 -- Fall through if bad prefix
3073 ("prefix of % attribute must be object of discriminated type");
3079 when Attribute_Copy_Sign
=>
3080 Check_Floating_Point_Type_2
;
3081 Set_Etype
(N
, P_Base_Type
);
3082 Resolve
(E1
, P_Base_Type
);
3083 Resolve
(E2
, P_Base_Type
);
3089 when Attribute_Count
=> Count
:
3098 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3101 if Ekind
(Ent
) /= E_Entry
then
3102 Error_Attr
("invalid entry name", N
);
3105 elsif Nkind
(P
) = N_Indexed_Component
then
3106 if not Is_Entity_Name
(Prefix
(P
))
3107 or else No
(Entity
(Prefix
(P
)))
3108 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3110 if Nkind
(Prefix
(P
)) = N_Selected_Component
3111 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3112 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3116 ("attribute % must apply to entry of current task", P
);
3119 Error_Attr
("invalid entry family name", P
);
3124 Ent
:= Entity
(Prefix
(P
));
3127 elsif Nkind
(P
) = N_Selected_Component
3128 and then Present
(Entity
(Selector_Name
(P
)))
3129 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3132 ("attribute % must apply to entry of current task", P
);
3135 Error_Attr
("invalid entry name", N
);
3139 for J
in reverse 0 .. Scope_Stack
.Last
loop
3140 S
:= Scope_Stack
.Table
(J
).Entity
;
3142 if S
= Scope
(Ent
) then
3143 if Nkind
(P
) = N_Expanded_Name
then
3144 Tsk
:= Entity
(Prefix
(P
));
3146 -- The prefix denotes either the task type, or else a
3147 -- single task whose task type is being analyzed.
3149 if (Is_Type
(Tsk
) and then Tsk
= S
)
3150 or else (not Is_Type
(Tsk
)
3151 and then Etype
(Tsk
) = S
3152 and then not (Comes_From_Source
(S
)))
3157 ("Attribute % must apply to entry of current task", N
);
3163 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3165 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3167 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3169 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3170 and then not Has_Completion
(Scope
(Ent
))
3172 Error_Attr
("attribute % can only be used inside body", N
);
3176 if Is_Overloaded
(P
) then
3178 Index
: Interp_Index
;
3182 Get_First_Interp
(P
, Index
, It
);
3183 while Present
(It
.Nam
) loop
3184 if It
.Nam
= Ent
then
3187 -- Ada 2005 (AI-345): Do not consider primitive entry
3188 -- wrappers generated for task or protected types.
3190 elsif Ada_Version
>= Ada_2005
3191 and then not Comes_From_Source
(It
.Nam
)
3196 Error_Attr
("ambiguous entry name", N
);
3199 Get_Next_Interp
(Index
, It
);
3204 Set_Etype
(N
, Universal_Integer
);
3207 -----------------------
3208 -- Default_Bit_Order --
3209 -----------------------
3211 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
3212 Target_Default_Bit_Order
: System
.Bit_Order
;
3215 Check_Standard_Prefix
;
3217 if Bytes_Big_Endian
then
3218 Target_Default_Bit_Order
:= System
.High_Order_First
;
3220 Target_Default_Bit_Order
:= System
.Low_Order_First
;
3224 Make_Integer_Literal
(Loc
,
3225 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
3227 Set_Etype
(N
, Universal_Integer
);
3228 Set_Is_Static_Expression
(N
);
3229 end Default_Bit_Order
;
3231 ----------------------------------
3232 -- Default_Scalar_Storage_Order --
3233 ----------------------------------
3235 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
3236 RE_Default_SSO
: RE_Id
;
3239 Check_Standard_Prefix
;
3241 case Opt
.Default_SSO
is
3243 if Bytes_Big_Endian
then
3244 RE_Default_SSO
:= RE_High_Order_First
;
3246 RE_Default_SSO
:= RE_Low_Order_First
;
3250 RE_Default_SSO
:= RE_High_Order_First
;
3253 RE_Default_SSO
:= RE_Low_Order_First
;
3256 raise Program_Error
;
3259 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
3266 when Attribute_Definite
=>
3267 Legal_Formal_Attribute
;
3273 when Attribute_Delta
=>
3274 Check_Fixed_Point_Type_0
;
3275 Set_Etype
(N
, Universal_Real
);
3281 when Attribute_Denorm
=>
3282 Check_Floating_Point_Type_0
;
3283 Set_Etype
(N
, Standard_Boolean
);
3285 ---------------------
3286 -- Descriptor_Size --
3287 ---------------------
3289 when Attribute_Descriptor_Size
=>
3292 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3293 Error_Attr_P
("prefix of attribute % must denote a type");
3296 Set_Etype
(N
, Universal_Integer
);
3302 when Attribute_Digits
=>
3306 if not Is_Floating_Point_Type
(P_Type
)
3307 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3310 ("prefix of % attribute must be float or decimal type");
3313 Set_Etype
(N
, Universal_Integer
);
3319 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3321 when Attribute_Elab_Body |
3322 Attribute_Elab_Spec |
3323 Attribute_Elab_Subp_Body
=>
3326 Check_Unit_Name
(P
);
3327 Set_Etype
(N
, Standard_Void_Type
);
3329 -- We have to manually call the expander in this case to get
3330 -- the necessary expansion (normally attributes that return
3331 -- entities are not expanded).
3339 -- Shares processing with Elab_Body
3345 when Attribute_Elaborated
=>
3347 Check_Unit_Name
(P
);
3348 Set_Etype
(N
, Standard_Boolean
);
3354 when Attribute_Emax
=>
3355 Check_Floating_Point_Type_0
;
3356 Set_Etype
(N
, Universal_Integer
);
3362 when Attribute_Enabled
=>
3363 Check_Either_E0_Or_E1
;
3365 if Present
(E1
) then
3366 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3367 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3372 if Nkind
(P
) /= N_Identifier
then
3373 Error_Msg_N
("identifier expected (check name)", P
);
3374 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3375 Error_Msg_N
("& is not a recognized check name", P
);
3378 Set_Etype
(N
, Standard_Boolean
);
3384 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3386 if Present
(E1
) then
3388 Check_Discrete_Type
;
3389 Resolve
(E1
, P_Base_Type
);
3392 if not Is_Entity_Name
(P
)
3393 or else (not Is_Object
(Entity
(P
))
3394 and then Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3397 ("prefix of % attribute must be " &
3398 "discrete type/object or enum literal");
3402 Set_Etype
(N
, Universal_Integer
);
3409 when Attribute_Enum_Val
=> Enum_Val
: begin
3413 if not Is_Enumeration_Type
(P_Type
) then
3414 Error_Attr_P
("prefix of % attribute must be enumeration type");
3417 -- If the enumeration type has a standard representation, the effect
3418 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3420 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3422 Make_Attribute_Reference
(Loc
,
3423 Prefix
=> Relocate_Node
(Prefix
(N
)),
3424 Attribute_Name
=> Name_Val
,
3425 Expressions
=> New_List
(Relocate_Node
(E1
))));
3426 Analyze_And_Resolve
(N
, P_Base_Type
);
3428 -- Non-standard representation case (enumeration with holes)
3432 Resolve
(E1
, Any_Integer
);
3433 Set_Etype
(N
, P_Base_Type
);
3441 when Attribute_Epsilon
=>
3442 Check_Floating_Point_Type_0
;
3443 Set_Etype
(N
, Universal_Real
);
3449 when Attribute_Exponent
=>
3450 Check_Floating_Point_Type_1
;
3451 Set_Etype
(N
, Universal_Integer
);
3452 Resolve
(E1
, P_Base_Type
);
3458 when Attribute_External_Tag
=>
3462 Set_Etype
(N
, Standard_String
);
3464 if not Is_Tagged_Type
(P_Type
) then
3465 Error_Attr_P
("prefix of % attribute must be tagged");
3472 when Attribute_Fast_Math
=>
3473 Check_Standard_Prefix
;
3474 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3480 when Attribute_First
=>
3481 Check_Array_Or_Scalar_Type
;
3482 Bad_Attribute_For_Predicate
;
3488 when Attribute_First_Bit
=>
3490 Set_Etype
(N
, Universal_Integer
);
3496 when Attribute_First_Valid
=>
3497 Check_First_Last_Valid
;
3498 Set_Etype
(N
, P_Type
);
3504 when Attribute_Fixed_Value
=>
3506 Check_Fixed_Point_Type
;
3507 Resolve
(E1
, Any_Integer
);
3508 Set_Etype
(N
, P_Base_Type
);
3514 when Attribute_Floor
=>
3515 Check_Floating_Point_Type_1
;
3516 Set_Etype
(N
, P_Base_Type
);
3517 Resolve
(E1
, P_Base_Type
);
3523 when Attribute_Fore
=>
3524 Check_Fixed_Point_Type_0
;
3525 Set_Etype
(N
, Universal_Integer
);
3531 when Attribute_Fraction
=>
3532 Check_Floating_Point_Type_1
;
3533 Set_Etype
(N
, P_Base_Type
);
3534 Resolve
(E1
, P_Base_Type
);
3540 when Attribute_From_Any
=>
3542 Check_PolyORB_Attribute
;
3543 Set_Etype
(N
, P_Base_Type
);
3545 -----------------------
3546 -- Has_Access_Values --
3547 -----------------------
3549 when Attribute_Has_Access_Values
=>
3552 Set_Etype
(N
, Standard_Boolean
);
3554 ----------------------
3555 -- Has_Same_Storage --
3556 ----------------------
3558 when Attribute_Has_Same_Storage
=>
3561 -- The arguments must be objects of any type
3563 Analyze_And_Resolve
(P
);
3564 Analyze_And_Resolve
(E1
);
3565 Check_Object_Reference
(P
);
3566 Check_Object_Reference
(E1
);
3567 Set_Etype
(N
, Standard_Boolean
);
3569 -----------------------
3570 -- Has_Tagged_Values --
3571 -----------------------
3573 when Attribute_Has_Tagged_Values
=>
3576 Set_Etype
(N
, Standard_Boolean
);
3578 -----------------------
3579 -- Has_Discriminants --
3580 -----------------------
3582 when Attribute_Has_Discriminants
=>
3583 Legal_Formal_Attribute
;
3589 when Attribute_Identity
=>
3593 if Etype
(P
) = Standard_Exception_Type
then
3594 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3596 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
3597 -- interface class-wide types.
3599 elsif Is_Task_Type
(Etype
(P
))
3600 or else (Is_Access_Type
(Etype
(P
))
3601 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3602 or else (Ada_Version
>= Ada_2005
3603 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3604 and then Is_Interface
(Etype
(P
))
3605 and then Is_Task_Interface
(Etype
(P
)))
3608 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3611 if Ada_Version
>= Ada_2005
then
3613 ("prefix of % attribute must be an exception, a " &
3614 "task or a task interface class-wide object");
3617 ("prefix of % attribute must be a task or an exception");
3625 when Attribute_Image
=> Image
:
3627 Check_SPARK_05_Restriction_On_Attribute
;
3629 Set_Etype
(N
, Standard_String
);
3631 if Is_Real_Type
(P_Type
) then
3632 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3633 Error_Msg_Name_1
:= Aname
;
3635 ("(Ada 83) % attribute not allowed for real types", N
);
3639 if Is_Enumeration_Type
(P_Type
) then
3640 Check_Restriction
(No_Enumeration_Maps
, N
);
3644 Resolve
(E1
, P_Base_Type
);
3646 Validate_Non_Static_Attribute_Function_Call
;
3648 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
3649 -- to avoid giving a duplicate message for Img expanded into Image.
3651 if Restriction_Check_Required
(No_Fixed_IO
)
3652 and then Comes_From_Source
(N
)
3653 and then Is_Fixed_Point_Type
(P_Type
)
3655 Check_Restriction
(No_Fixed_IO
, P
);
3663 when Attribute_Img
=> Img
:
3666 Set_Etype
(N
, Standard_String
);
3668 if not Is_Scalar_Type
(P_Type
)
3669 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3672 ("prefix of % attribute must be scalar object name");
3677 -- Check restriction No_Fixed_IO
3679 if Restriction_Check_Required
(No_Fixed_IO
)
3680 and then Is_Fixed_Point_Type
(P_Type
)
3682 Check_Restriction
(No_Fixed_IO
, P
);
3690 when Attribute_Input
=>
3692 Check_Stream_Attribute
(TSS_Stream_Input
);
3693 Set_Etype
(N
, P_Base_Type
);
3699 when Attribute_Integer_Value
=>
3702 Resolve
(E1
, Any_Fixed
);
3704 -- Signal an error if argument type is not a specific fixed-point
3705 -- subtype. An error has been signalled already if the argument
3706 -- was not of a fixed-point type.
3708 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3709 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3712 Set_Etype
(N
, P_Base_Type
);
3718 when Attribute_Invalid_Value
=>
3721 Set_Etype
(N
, P_Base_Type
);
3722 Invalid_Value_Used
:= True;
3728 when Attribute_Large
=>
3731 Set_Etype
(N
, Universal_Real
);
3737 when Attribute_Last
=>
3738 Check_Array_Or_Scalar_Type
;
3739 Bad_Attribute_For_Predicate
;
3745 when Attribute_Last_Bit
=>
3747 Set_Etype
(N
, Universal_Integer
);
3753 when Attribute_Last_Valid
=>
3754 Check_First_Last_Valid
;
3755 Set_Etype
(N
, P_Type
);
3761 when Attribute_Leading_Part
=>
3762 Check_Floating_Point_Type_2
;
3763 Set_Etype
(N
, P_Base_Type
);
3764 Resolve
(E1
, P_Base_Type
);
3765 Resolve
(E2
, Any_Integer
);
3771 when Attribute_Length
=>
3773 Set_Etype
(N
, Universal_Integer
);
3779 when Attribute_Library_Level
=>
3782 if not Is_Entity_Name
(P
) then
3783 Error_Attr_P
("prefix of % attribute must be an entity name");
3786 if not Inside_A_Generic
then
3787 Set_Boolean_Result
(N
,
3788 Is_Library_Level_Entity
(Entity
(P
)));
3791 Set_Etype
(N
, Standard_Boolean
);
3797 when Attribute_Lock_Free
=>
3799 Set_Etype
(N
, Standard_Boolean
);
3801 if not Is_Protected_Type
(P_Type
) then
3803 ("prefix of % attribute must be a protected object");
3810 when Attribute_Loop_Entry
=> Loop_Entry
: declare
3811 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
3812 -- Inspect the prefix for any uses of entities declared within the
3813 -- related loop. Loop_Id denotes the loop identifier.
3815 --------------------------------
3816 -- Check_References_In_Prefix --
3817 --------------------------------
3819 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
3820 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
3822 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
3823 -- Determine whether a reference mentions an entity declared
3824 -- within the related loop.
3826 function Declared_Within
(Nod
: Node_Id
) return Boolean;
3827 -- Determine whether Nod appears in the subtree of Loop_Decl
3829 ---------------------
3830 -- Check_Reference --
3831 ---------------------
3833 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
3835 if Nkind
(Nod
) = N_Identifier
3836 and then Present
(Entity
(Nod
))
3837 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
3840 ("prefix of attribute % cannot reference local entities",
3846 end Check_Reference
;
3848 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
3850 ---------------------
3851 -- Declared_Within --
3852 ---------------------
3854 function Declared_Within
(Nod
: Node_Id
) return Boolean is
3859 while Present
(Stmt
) loop
3860 if Stmt
= Loop_Decl
then
3863 -- Prevent the search from going too far
3865 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3869 Stmt
:= Parent
(Stmt
);
3873 end Declared_Within
;
3875 -- Start of processing for Check_Prefix_For_Local_References
3878 Check_References
(P
);
3879 end Check_References_In_Prefix
;
3883 Context
: constant Node_Id
:= Parent
(N
);
3885 Enclosing_Loop
: Node_Id
;
3886 Loop_Id
: Entity_Id
:= Empty
;
3889 Enclosing_Pragma
: Node_Id
:= Empty
;
3891 -- Start of processing for Loop_Entry
3896 -- Set the type of the attribute now to ensure the successfull
3897 -- continuation of analysis even if the attribute is misplaced.
3899 Set_Etype
(Attr
, P_Type
);
3901 -- Attribute 'Loop_Entry may appear in several flavors:
3903 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3904 -- nearest enclosing loop.
3906 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3907 -- attribute may be related to a loop denoted by label Expr or
3908 -- the prefix may denote an array object and Expr may act as an
3909 -- indexed component.
3911 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3912 -- to the nearest enclosing loop, all expressions are part of
3913 -- an indexed component.
3915 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3916 -- denotes, the attribute may be related to a loop denoted by
3917 -- label Expr or the prefix may denote a multidimensional array
3918 -- array object and Expr along with the rest of the expressions
3919 -- may act as indexed components.
3921 -- Regardless of variations, the attribute reference does not have an
3922 -- expression list. Instead, all available expressions are stored as
3923 -- indexed components.
3925 -- When the attribute is part of an indexed component, find the first
3926 -- expression as it will determine the semantics of 'Loop_Entry.
3928 if Nkind
(Context
) = N_Indexed_Component
then
3929 E1
:= First
(Expressions
(Context
));
3932 -- The attribute reference appears in the following form:
3934 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3936 -- In this case, the loop name is omitted and no rewriting is
3939 if Present
(E2
) then
3942 -- The form of the attribute is:
3944 -- Prefix'Loop_Entry (Expr) [(...)]
3946 -- If Expr denotes a loop entry, the whole attribute and indexed
3947 -- component will have to be rewritten to reflect this relation.
3950 pragma Assert
(Present
(E1
));
3952 -- Do not expand the expression as it may have side effects.
3953 -- Simply preanalyze to determine whether it is a loop name or
3956 Preanalyze_And_Resolve
(E1
);
3958 if Is_Entity_Name
(E1
)
3959 and then Present
(Entity
(E1
))
3960 and then Ekind
(Entity
(E1
)) = E_Loop
3962 Loop_Id
:= Entity
(E1
);
3964 -- Transform the attribute and enclosing indexed component
3966 Set_Expressions
(N
, Expressions
(Context
));
3967 Rewrite
(Context
, N
);
3968 Set_Etype
(Context
, P_Type
);
3975 -- The prefix must denote an object
3977 if not Is_Object_Reference
(P
) then
3978 Error_Attr_P
("prefix of attribute % must denote an object");
3981 -- The prefix cannot be of a limited type because the expansion of
3982 -- Loop_Entry must create a constant initialized by the evaluated
3985 if Is_Limited_View
(Etype
(P
)) then
3986 Error_Attr_P
("prefix of attribute % cannot be limited");
3989 -- Climb the parent chain to verify the location of the attribute and
3990 -- find the enclosing loop.
3993 while Present
(Stmt
) loop
3995 -- Locate the corresponding enclosing pragma. Note that in the
3996 -- case of Assert[And_Cut] and Assume, we have already checked
3997 -- that the pragma appears in an appropriate loop location.
3999 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4000 and then Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
4001 Name_Loop_Invariant
,
4004 Name_Assert_And_Cut
,
4007 Enclosing_Pragma
:= Original_Node
(Stmt
);
4009 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4010 -- iteration may be expanded into several nested loops, we are
4011 -- interested in the outermost one which has the loop identifier.
4013 elsif Nkind
(Stmt
) = N_Loop_Statement
4014 and then Present
(Identifier
(Stmt
))
4016 Enclosing_Loop
:= Stmt
;
4018 -- The original attribute reference may lack a loop name. Use
4019 -- the name of the enclosing loop because it is the related
4022 if No
(Loop_Id
) then
4023 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
4028 -- Prevent the search from going too far
4030 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4034 Stmt
:= Parent
(Stmt
);
4037 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4038 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4039 -- purpose if they appear in an appropriate location in a loop,
4040 -- which was already checked by the top level pragma circuit).
4042 if No
(Enclosing_Pragma
) then
4043 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4046 -- A Loop_Entry that applies to a given loop statement must not
4047 -- appear within a body of accept statement, if this construct is
4048 -- itself enclosed by the given loop statement.
4050 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4051 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4053 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4055 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4059 ("attribute % cannot appear in body or accept statement", N
);
4064 -- The prefix cannot mention entities declared within the related
4065 -- loop because they will not be visible once the prefix is moved
4066 -- outside the loop.
4068 Check_References_In_Prefix
(Loop_Id
);
4070 -- The prefix must denote a static entity if the pragma does not
4071 -- apply to the innermost enclosing loop statement, or if it appears
4072 -- within a potentially unevaluated epxression.
4074 if Is_Entity_Name
(P
)
4075 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4079 elsif Present
(Enclosing_Loop
)
4080 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
4083 ("prefix of attribute % that applies to outer loop must denote "
4086 elsif Is_Potentially_Unevaluated
(P
) then
4090 -- Replace the Loop_Entry attribute reference by its prefix if the
4091 -- related pragma is ignored. This transformation is OK with respect
4092 -- to typing because Loop_Entry's type is that of its prefix. This
4093 -- early transformation also avoids the generation of a useless loop
4096 if Is_Ignored
(Enclosing_Pragma
) then
4097 Rewrite
(N
, Relocate_Node
(P
));
4100 Preanalyze_And_Resolve
(P
);
4107 when Attribute_Machine
=>
4108 Check_Floating_Point_Type_1
;
4109 Set_Etype
(N
, P_Base_Type
);
4110 Resolve
(E1
, P_Base_Type
);
4116 when Attribute_Machine_Emax
=>
4117 Check_Floating_Point_Type_0
;
4118 Set_Etype
(N
, Universal_Integer
);
4124 when Attribute_Machine_Emin
=>
4125 Check_Floating_Point_Type_0
;
4126 Set_Etype
(N
, Universal_Integer
);
4128 ----------------------
4129 -- Machine_Mantissa --
4130 ----------------------
4132 when Attribute_Machine_Mantissa
=>
4133 Check_Floating_Point_Type_0
;
4134 Set_Etype
(N
, Universal_Integer
);
4136 -----------------------
4137 -- Machine_Overflows --
4138 -----------------------
4140 when Attribute_Machine_Overflows
=>
4143 Set_Etype
(N
, Standard_Boolean
);
4149 when Attribute_Machine_Radix
=>
4152 Set_Etype
(N
, Universal_Integer
);
4154 ----------------------
4155 -- Machine_Rounding --
4156 ----------------------
4158 when Attribute_Machine_Rounding
=>
4159 Check_Floating_Point_Type_1
;
4160 Set_Etype
(N
, P_Base_Type
);
4161 Resolve
(E1
, P_Base_Type
);
4163 --------------------
4164 -- Machine_Rounds --
4165 --------------------
4167 when Attribute_Machine_Rounds
=>
4170 Set_Etype
(N
, Standard_Boolean
);
4176 when Attribute_Machine_Size
=>
4179 Check_Not_Incomplete_Type
;
4180 Set_Etype
(N
, Universal_Integer
);
4186 when Attribute_Mantissa
=>
4189 Set_Etype
(N
, Universal_Integer
);
4195 when Attribute_Max
=>
4198 ----------------------------------
4199 -- Max_Alignment_For_Allocation --
4200 ----------------------------------
4202 when Attribute_Max_Size_In_Storage_Elements
=>
4203 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4205 ----------------------------------
4206 -- Max_Size_In_Storage_Elements --
4207 ----------------------------------
4209 when Attribute_Max_Alignment_For_Allocation
=>
4210 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4212 -----------------------
4213 -- Maximum_Alignment --
4214 -----------------------
4216 when Attribute_Maximum_Alignment
=>
4217 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4219 --------------------
4220 -- Mechanism_Code --
4221 --------------------
4223 when Attribute_Mechanism_Code
=>
4224 if not Is_Entity_Name
(P
)
4225 or else not Is_Subprogram
(Entity
(P
))
4227 Error_Attr_P
("prefix of % attribute must be subprogram");
4230 Check_Either_E0_Or_E1
;
4232 if Present
(E1
) then
4233 Resolve
(E1
, Any_Integer
);
4234 Set_Etype
(E1
, Standard_Integer
);
4236 if not Is_OK_Static_Expression
(E1
) then
4237 Flag_Non_Static_Expr
4238 ("expression for parameter number must be static!", E1
);
4241 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4242 or else UI_To_Int
(Intval
(E1
)) < 0
4244 Error_Attr
("invalid parameter number for % attribute", E1
);
4248 Set_Etype
(N
, Universal_Integer
);
4254 when Attribute_Min
=>
4261 when Attribute_Mod
=>
4263 -- Note: this attribute is only allowed in Ada 2005 mode, but
4264 -- we do not need to test that here, since Mod is only recognized
4265 -- as an attribute name in Ada 2005 mode during the parse.
4268 Check_Modular_Integer_Type
;
4269 Resolve
(E1
, Any_Integer
);
4270 Set_Etype
(N
, P_Base_Type
);
4276 when Attribute_Model
=>
4277 Check_Floating_Point_Type_1
;
4278 Set_Etype
(N
, P_Base_Type
);
4279 Resolve
(E1
, P_Base_Type
);
4285 when Attribute_Model_Emin
=>
4286 Check_Floating_Point_Type_0
;
4287 Set_Etype
(N
, Universal_Integer
);
4293 when Attribute_Model_Epsilon
=>
4294 Check_Floating_Point_Type_0
;
4295 Set_Etype
(N
, Universal_Real
);
4297 --------------------
4298 -- Model_Mantissa --
4299 --------------------
4301 when Attribute_Model_Mantissa
=>
4302 Check_Floating_Point_Type_0
;
4303 Set_Etype
(N
, Universal_Integer
);
4309 when Attribute_Model_Small
=>
4310 Check_Floating_Point_Type_0
;
4311 Set_Etype
(N
, Universal_Real
);
4317 when Attribute_Modulus
=>
4319 Check_Modular_Integer_Type
;
4320 Set_Etype
(N
, Universal_Integer
);
4322 --------------------
4323 -- Null_Parameter --
4324 --------------------
4326 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4327 Parnt
: constant Node_Id
:= Parent
(N
);
4328 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4330 procedure Bad_Null_Parameter
(Msg
: String);
4331 -- Used if bad Null parameter attribute node is found. Issues
4332 -- given error message, and also sets the type to Any_Type to
4333 -- avoid blowups later on from dealing with a junk node.
4335 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4336 -- Called to check that Proc_Ent is imported subprogram
4338 ------------------------
4339 -- Bad_Null_Parameter --
4340 ------------------------
4342 procedure Bad_Null_Parameter
(Msg
: String) is
4344 Error_Msg_N
(Msg
, N
);
4345 Set_Etype
(N
, Any_Type
);
4346 end Bad_Null_Parameter
;
4348 ----------------------
4349 -- Must_Be_Imported --
4350 ----------------------
4352 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4353 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4356 -- Ignore check if procedure not frozen yet (we will get
4357 -- another chance when the default parameter is reanalyzed)
4359 if not Is_Frozen
(Pent
) then
4362 elsif not Is_Imported
(Pent
) then
4364 ("Null_Parameter can only be used with imported subprogram");
4369 end Must_Be_Imported
;
4371 -- Start of processing for Null_Parameter
4376 Set_Etype
(N
, P_Type
);
4378 -- Case of attribute used as default expression
4380 if Nkind
(Parnt
) = N_Parameter_Specification
then
4381 Must_Be_Imported
(Defining_Entity
(GParnt
));
4383 -- Case of attribute used as actual for subprogram (positional)
4385 elsif Nkind
(Parnt
) in N_Subprogram_Call
4386 and then Is_Entity_Name
(Name
(Parnt
))
4388 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4390 -- Case of attribute used as actual for subprogram (named)
4392 elsif Nkind
(Parnt
) = N_Parameter_Association
4393 and then Nkind
(GParnt
) in N_Subprogram_Call
4394 and then Is_Entity_Name
(Name
(GParnt
))
4396 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4398 -- Not an allowed case
4402 ("Null_Parameter must be actual or default parameter");
4410 when Attribute_Object_Size
=>
4413 Check_Not_Incomplete_Type
;
4414 Set_Etype
(N
, Universal_Integer
);
4420 when Attribute_Old
=> Old
: declare
4421 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4422 -- Inspect the contents of the prefix and detect illegal uses of a
4423 -- nested 'Old, attribute 'Result or a use of an entity declared in
4424 -- the related postcondition expression. Subp_Id is the subprogram to
4425 -- which the related postcondition applies.
4427 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
);
4428 -- Perform various semantic checks related to the placement of the
4429 -- attribute in pragma Contract_Cases.
4431 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
);
4432 -- Perform various semantic checks related to the placement of the
4433 -- attribute in pragma Contract_Cases.
4435 --------------------------------
4436 -- Check_References_In_Prefix --
4437 --------------------------------
4439 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4440 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4441 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4442 -- and perform the appropriate semantic check.
4444 ---------------------
4445 -- Check_Reference --
4446 ---------------------
4448 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4450 -- Attributes 'Old and 'Result cannot appear in the prefix of
4451 -- another attribute 'Old.
4453 if Nkind
(Nod
) = N_Attribute_Reference
4454 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4457 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4458 Error_Msg_Name_2
:= Name_Old
;
4460 ("attribute % cannot appear in the prefix of attribute %",
4464 -- Entities mentioned within the prefix of attribute 'Old must
4465 -- be global to the related postcondition. If this is not the
4466 -- case, then the scope of the local entity is nested within
4467 -- that of the subprogram.
4469 elsif Nkind
(Nod
) = N_Identifier
4470 and then Present
(Entity
(Nod
))
4471 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4474 ("prefix of attribute % cannot reference local entities",
4480 end Check_Reference
;
4482 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4484 -- Start of processing for Check_References_In_Prefix
4487 Check_References
(P
);
4488 end Check_References_In_Prefix
;
4490 ---------------------------------
4491 -- Check_Use_In_Contract_Cases --
4492 ---------------------------------
4494 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
) is
4495 Cases
: constant Node_Id
:=
4497 (First
(Pragma_Argument_Associations
(Prag
)));
4501 -- Climb the parent chain to reach the top of the expression where
4502 -- attribute 'Old resides.
4505 while Parent
(Parent
(Expr
)) /= Cases
loop
4506 Expr
:= Parent
(Expr
);
4509 -- Ensure that the obtained expression is the consequence of a
4510 -- contract case as this is the only postcondition-like part of
4511 -- the pragma. Otherwise, attribute 'Old appears in the condition
4512 -- of a contract case. Emit an error since this is not a
4513 -- postcondition-like context. (SPARK RM 6.1.3(2))
4515 if Expr
/= Expression
(Parent
(Expr
)) then
4517 ("attribute % cannot appear in the condition "
4518 & "of a contract case", P
);
4520 end Check_Use_In_Contract_Cases
;
4522 ----------------------------
4523 -- Check_Use_In_Test_Case --
4524 ----------------------------
4526 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
) is
4527 Ensures
: constant Node_Id
:= Get_Ensures_From_CTC_Pragma
(Prag
);
4531 -- Climb the parent chain to reach the top of the Ensures part of
4532 -- pragma Test_Case.
4535 while Expr
/= Prag
loop
4536 if Expr
= Ensures
then
4540 Expr
:= Parent
(Expr
);
4543 -- If we get there, then attribute 'Old appears in the requires
4544 -- expression of pragma Test_Case which is not a postcondition-
4548 ("attribute % cannot appear in the requires expression of a "
4550 end Check_Use_In_Test_Case
;
4555 -- The enclosing scope, excluding loops for quantified expressions.
4556 -- During analysis, it is the postcondition subprogram. During
4557 -- pre-analysis, it is the scope of the subprogram declaration.
4560 -- During pre-analysis, Prag is the enclosing pragma node if any
4562 -- Start of processing for Old
4567 -- Find enclosing scopes, excluding loops
4569 CS
:= Current_Scope
;
4570 while Ekind
(CS
) = E_Loop
loop
4574 -- A Contract_Cases, Postcondition or Test_Case pragma is in the
4575 -- process of being preanalyzed. Perform the semantic checks now
4576 -- before the pragma is relocated and/or expanded.
4578 -- For a generic subprogram, postconditions are preanalyzed as well
4579 -- for name capture, and still appear within an aspect spec.
4581 if In_Spec_Expression
or Inside_A_Generic
then
4583 while Present
(Prag
)
4584 and then not Nkind_In
(Prag
, N_Aspect_Specification
,
4585 N_Function_Specification
,
4587 N_Procedure_Specification
,
4590 Prag
:= Parent
(Prag
);
4593 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4594 -- corresponding pragma. Don't issue errors when analyzing aspect.
4596 if Nkind
(Prag
) = N_Aspect_Specification
4597 and then Chars
(Identifier
(Prag
)) = Name_Post
4601 -- In all other cases the related context must be a pragma
4603 elsif Nkind
(Prag
) /= N_Pragma
then
4604 Error_Attr
("% attribute can only appear in postcondition", P
);
4606 -- Verify the placement of the attribute with respect to the
4610 case Get_Pragma_Id
(Prag
) is
4611 when Pragma_Contract_Cases
=>
4612 Check_Use_In_Contract_Cases
(Prag
);
4614 when Pragma_Postcondition | Pragma_Refined_Post
=>
4617 when Pragma_Test_Case
=>
4618 Check_Use_In_Test_Case
(Prag
);
4622 ("% attribute can only appear in postcondition", P
);
4626 -- Check the legality of attribute 'Old when it appears inside pragma
4627 -- Refined_Post. These specialized checks are required only when code
4628 -- generation is disabled. In the general case pragma Refined_Post is
4629 -- transformed into pragma Check by Process_PPCs which in turn is
4630 -- relocated to procedure _Postconditions. From then on the legality
4631 -- of 'Old is determined as usual.
4633 elsif not Expander_Active
and then In_Refined_Post
then
4634 Preanalyze_And_Resolve
(P
);
4635 Check_References_In_Prefix
(CS
);
4636 P_Type
:= Etype
(P
);
4637 Set_Etype
(N
, P_Type
);
4639 if Is_Limited_Type
(P_Type
) then
4640 Error_Attr
("attribute % cannot apply to limited objects", P
);
4643 if Is_Entity_Name
(P
)
4644 and then Is_Constant_Object
(Entity
(P
))
4647 ("??attribute Old applied to constant has no effect", P
);
4652 -- Body case, where we must be inside a generated _Postconditions
4653 -- procedure, or else the attribute use is definitely misplaced. The
4654 -- postcondition itself may have generated transient scopes, and is
4655 -- not necessarily the current one.
4658 while Present
(CS
) and then CS
/= Standard_Standard
loop
4659 if Chars
(CS
) = Name_uPostconditions
then
4666 if Chars
(CS
) /= Name_uPostconditions
then
4667 Error_Attr
("% attribute can only appear in postcondition", P
);
4671 -- If the attribute reference is generated for a Requires clause,
4672 -- then no expressions follow. Otherwise it is a primary, in which
4673 -- case, if expressions follow, the attribute reference must be an
4674 -- indexable object, so rewrite the node accordingly.
4676 if Present
(E1
) then
4678 Make_Indexed_Component
(Loc
,
4680 Make_Attribute_Reference
(Loc
,
4681 Prefix
=> Relocate_Node
(Prefix
(N
)),
4682 Attribute_Name
=> Name_Old
),
4683 Expressions
=> Expressions
(N
)));
4691 -- Prefix has not been analyzed yet, and its full analysis will take
4692 -- place during expansion (see below).
4694 Preanalyze_And_Resolve
(P
);
4695 Check_References_In_Prefix
(CS
);
4696 P_Type
:= Etype
(P
);
4697 Set_Etype
(N
, P_Type
);
4699 if Is_Limited_Type
(P_Type
) then
4700 Error_Attr
("attribute % cannot apply to limited objects", P
);
4703 if Is_Entity_Name
(P
)
4704 and then Is_Constant_Object
(Entity
(P
))
4707 ("??attribute Old applied to constant has no effect", P
);
4710 -- Check that the prefix of 'Old is an entity when it may be
4711 -- potentially unevaluated (6.1.1 (27/3)).
4714 and then Is_Potentially_Unevaluated
(N
)
4715 and then not Is_Entity_Name
(P
)
4720 -- The attribute appears within a pre/postcondition, but refers to
4721 -- an entity in the enclosing subprogram. If it is a component of
4722 -- a formal its expansion might generate actual subtypes that may
4723 -- be referenced in an inner context, and which must be elaborated
4724 -- within the subprogram itself. If the prefix includes a function
4725 -- call it may involve finalization actions that should only be
4726 -- inserted when the attribute has been rewritten as a declarations.
4727 -- As a result, if the prefix is not a simple name we create
4728 -- a declaration for it now, and insert it at the start of the
4729 -- enclosing subprogram. This is properly an expansion activity
4730 -- but it has to be performed now to prevent out-of-order issues.
4732 -- This expansion is both harmful and not needed in SPARK mode, since
4733 -- the formal verification backend relies on the types of nodes
4734 -- (hence is not robust w.r.t. a change to base type here), and does
4735 -- not suffer from the out-of-order issue described above. Thus, this
4736 -- expansion is skipped in SPARK mode.
4738 if not Is_Entity_Name
(P
) and then not GNATprove_Mode
then
4739 P_Type
:= Base_Type
(P_Type
);
4740 Set_Etype
(N
, P_Type
);
4741 Set_Etype
(P
, P_Type
);
4742 Analyze_Dimension
(N
);
4747 ----------------------
4748 -- Overlaps_Storage --
4749 ----------------------
4751 when Attribute_Overlaps_Storage
=>
4754 -- Both arguments must be objects of any type
4756 Analyze_And_Resolve
(P
);
4757 Analyze_And_Resolve
(E1
);
4758 Check_Object_Reference
(P
);
4759 Check_Object_Reference
(E1
);
4760 Set_Etype
(N
, Standard_Boolean
);
4766 when Attribute_Output
=>
4768 Check_Stream_Attribute
(TSS_Stream_Output
);
4769 Set_Etype
(N
, Standard_Void_Type
);
4770 Resolve
(N
, Standard_Void_Type
);
4776 when Attribute_Partition_ID
=> Partition_Id
:
4780 if P_Type
/= Any_Type
then
4781 if not Is_Library_Level_Entity
(Entity
(P
)) then
4783 ("prefix of % attribute must be library-level entity");
4785 -- The defining entity of prefix should not be declared inside a
4786 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4788 elsif Is_Entity_Name
(P
)
4789 and then Is_Pure
(Entity
(P
))
4791 Error_Attr_P
("prefix of% attribute must not be declared pure");
4795 Set_Etype
(N
, Universal_Integer
);
4798 -------------------------
4799 -- Passed_By_Reference --
4800 -------------------------
4802 when Attribute_Passed_By_Reference
=>
4805 Set_Etype
(N
, Standard_Boolean
);
4811 when Attribute_Pool_Address
=>
4813 Set_Etype
(N
, RTE
(RE_Address
));
4819 when Attribute_Pos
=>
4820 Check_Discrete_Type
;
4823 if Is_Boolean_Type
(P_Type
) then
4824 Error_Msg_Name_1
:= Aname
;
4825 Error_Msg_Name_2
:= Chars
(P_Type
);
4826 Check_SPARK_05_Restriction
4827 ("attribute% is not allowed for type%", P
);
4830 Resolve
(E1
, P_Base_Type
);
4831 Set_Etype
(N
, Universal_Integer
);
4837 when Attribute_Position
=>
4839 Set_Etype
(N
, Universal_Integer
);
4845 when Attribute_Pred
=>
4849 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4850 Error_Msg_Name_1
:= Aname
;
4851 Error_Msg_Name_2
:= Chars
(P_Type
);
4852 Check_SPARK_05_Restriction
4853 ("attribute% is not allowed for type%", P
);
4856 Resolve
(E1
, P_Base_Type
);
4857 Set_Etype
(N
, P_Base_Type
);
4859 -- Since Pred works on the base type, we normally do no check for the
4860 -- floating-point case, since the base type is unconstrained. But we
4861 -- make an exception in Check_Float_Overflow mode.
4863 if Is_Floating_Point_Type
(P_Type
) then
4864 if not Range_Checks_Suppressed
(P_Base_Type
) then
4865 Set_Do_Range_Check
(E1
);
4868 -- If not modular type, test for overflow check required
4871 if not Is_Modular_Integer_Type
(P_Type
)
4872 and then not Range_Checks_Suppressed
(P_Base_Type
)
4874 Enable_Range_Check
(E1
);
4882 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4884 when Attribute_Priority
=>
4885 if Ada_Version
< Ada_2005
then
4886 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4891 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4895 if Is_Protected_Type
(Etype
(P
))
4896 or else (Is_Access_Type
(Etype
(P
))
4897 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4899 Resolve
(P
, Etype
(P
));
4901 Error_Attr_P
("prefix of % attribute must be a protected object");
4904 Set_Etype
(N
, Standard_Integer
);
4906 -- Must be called from within a protected procedure or entry of the
4907 -- protected object.
4914 while S
/= Etype
(P
)
4915 and then S
/= Standard_Standard
4920 if S
= Standard_Standard
then
4921 Error_Attr
("the attribute % is only allowed inside protected "
4926 Validate_Non_Static_Attribute_Function_Call
;
4932 when Attribute_Range
=>
4933 Check_Array_Or_Scalar_Type
;
4934 Bad_Attribute_For_Predicate
;
4936 if Ada_Version
= Ada_83
4937 and then Is_Scalar_Type
(P_Type
)
4938 and then Comes_From_Source
(N
)
4941 ("(Ada 83) % attribute not allowed for scalar type", P
);
4948 when Attribute_Result
=> Result
: declare
4949 Post_Id
: Entity_Id
;
4950 -- The entity of the _Postconditions procedure
4953 -- During pre-analysis, Prag is the enclosing pragma node if any
4955 Subp_Id
: Entity_Id
;
4956 -- The entity of the enclosing subprogram
4959 -- Find the proper enclosing scope
4961 Post_Id
:= Current_Scope
;
4962 while Present
(Post_Id
) loop
4964 -- Skip generated loops
4966 if Ekind
(Post_Id
) = E_Loop
then
4967 Post_Id
:= Scope
(Post_Id
);
4969 -- Skip the special _Parent scope generated to capture references
4970 -- to formals during the process of subprogram inlining.
4972 elsif Ekind
(Post_Id
) = E_Function
4973 and then Chars
(Post_Id
) = Name_uParent
4975 Post_Id
:= Scope
(Post_Id
);
4977 -- Otherwise this must be _Postconditions
4984 Subp_Id
:= Scope
(Post_Id
);
4986 -- If the enclosing subprogram is always inlined, the enclosing
4987 -- postcondition will not be propagated to the expanded call.
4989 if not In_Spec_Expression
4990 and then Has_Pragma_Inline_Always
(Subp_Id
)
4991 and then Warn_On_Redundant_Constructs
4994 ("postconditions on inlined functions not enforced?r?", N
);
4997 -- If we are in the scope of a function and in Spec_Expression mode,
4998 -- this is likely the prescan of the postcondition (or contract case,
4999 -- or test case) pragma, and we just set the proper type. If there is
5000 -- an error it will be caught when the real Analyze call is done.
5002 if Ekind
(Post_Id
) = E_Function
and then In_Spec_Expression
then
5006 if Chars
(Post_Id
) /= Chars
(P
) then
5007 Error_Msg_Name_1
:= Name_Result
;
5009 ("incorrect prefix for % attribute, expected &", P
, Post_Id
);
5013 -- Check in postcondition, Test_Case or Contract_Cases of function
5016 while Present
(Prag
)
5017 and then not Nkind_In
(Prag
, N_Pragma
,
5018 N_Function_Specification
,
5019 N_Aspect_Specification
,
5022 Prag
:= Parent
(Prag
);
5025 -- In ASIS mode, the aspect itself is analyzed, in addition to the
5026 -- corresponding pragma. Do not issue errors when analyzing the
5029 if Nkind
(Prag
) = N_Aspect_Specification
then
5032 -- Must have a pragma
5034 elsif Nkind
(Prag
) /= N_Pragma
then
5036 ("% attribute can only appear in postcondition of function",
5039 -- Processing depends on which pragma we have
5042 case Get_Pragma_Id
(Prag
) is
5043 when Pragma_Test_Case
=>
5045 Arg_Ens
: constant Node_Id
:=
5046 Get_Ensures_From_CTC_Pragma
(Prag
);
5051 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
5052 Arg
:= Parent
(Arg
);
5055 if Arg
/= Arg_Ens
then
5057 ("% attribute misplaced inside test case", P
);
5061 when Pragma_Contract_Cases
=>
5063 Aggr
: constant Node_Id
:=
5065 (Pragma_Argument_Associations
(Prag
)));
5071 and then Parent
(Parent
(Arg
)) /= Aggr
5073 Arg
:= Parent
(Arg
);
5076 -- At this point, Parent (Arg) should be a component
5077 -- association. Attribute Result is only allowed in
5078 -- the expression part of this association.
5080 if Nkind
(Parent
(Arg
)) /= N_Component_Association
5081 or else Arg
/= Expression
(Parent
(Arg
))
5084 ("% attribute misplaced inside contract cases",
5089 when Pragma_Postcondition | Pragma_Refined_Post
=>
5094 ("% attribute can only appear in postcondition "
5095 & "of function", P
);
5099 -- The attribute reference is a primary. If expressions follow,
5100 -- the attribute reference is really an indexable object, so
5101 -- rewrite and analyze as an indexed component.
5103 if Present
(E1
) then
5105 Make_Indexed_Component
(Loc
,
5107 Make_Attribute_Reference
(Loc
,
5108 Prefix
=> Relocate_Node
(Prefix
(N
)),
5109 Attribute_Name
=> Name_Result
),
5110 Expressions
=> Expressions
(N
)));
5115 Set_Etype
(N
, Etype
(Post_Id
));
5117 -- If several functions with that name are visible, the intended
5118 -- one is the current scope.
5120 if Is_Overloaded
(P
) then
5121 Set_Entity
(P
, Post_Id
);
5122 Set_Is_Overloaded
(P
, False);
5125 -- Check the legality of attribute 'Result when it appears inside
5126 -- pragma Refined_Post. These specialized checks are required only
5127 -- when code generation is disabled. In the general case pragma
5128 -- Refined_Post is transformed into pragma Check by Process_PPCs
5129 -- which in turn is relocated to procedure _Postconditions. From
5130 -- then on the legality of 'Result is determined as usual.
5132 elsif not Expander_Active
and then In_Refined_Post
then
5134 -- Routine _Postconditions has not been generated yet, the nearest
5135 -- enclosing subprogram is denoted by the current scope.
5137 if Ekind
(Post_Id
) /= E_Procedure
5138 or else Chars
(Post_Id
) /= Name_uPostconditions
5140 Subp_Id
:= Current_Scope
;
5143 -- The prefix denotes the nearest enclosing function
5145 if Is_Entity_Name
(P
)
5146 and then Ekind
(Entity
(P
)) = E_Function
5147 and then Entity
(P
) = Subp_Id
5151 -- Otherwise the use of 'Result is illegal
5154 Error_Msg_Name_2
:= Chars
(Subp_Id
);
5155 Error_Attr
("incorrect prefix for % attribute, expected %", P
);
5158 Set_Etype
(N
, Etype
(Subp_Id
));
5160 -- Body case, where we must be inside a generated _Postconditions
5161 -- procedure, and the prefix must be on the scope stack, or else the
5162 -- attribute use is definitely misplaced. The postcondition itself
5163 -- may have generated transient scopes, and is not necessarily the
5167 while Present
(Post_Id
)
5168 and then Post_Id
/= Standard_Standard
5170 if Chars
(Post_Id
) = Name_uPostconditions
then
5173 Post_Id
:= Scope
(Post_Id
);
5177 Subp_Id
:= Scope
(Post_Id
);
5179 if Chars
(Post_Id
) = Name_uPostconditions
5180 and then Ekind
(Subp_Id
) = E_Function
5184 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
5185 and then Chars
(P
) = Chars
(Subp_Id
)
5189 -- Within an instance, the prefix designates the local renaming
5190 -- of the original generic.
5192 elsif Is_Entity_Name
(P
)
5193 and then Ekind
(Entity
(P
)) = E_Function
5194 and then Present
(Alias
(Entity
(P
)))
5195 and then Chars
(Alias
(Entity
(P
))) = Chars
(Subp_Id
)
5200 Error_Msg_Name_2
:= Chars
(Subp_Id
);
5202 ("incorrect prefix for % attribute, expected %", P
);
5205 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
5206 Analyze_And_Resolve
(N
, Etype
(Subp_Id
));
5210 ("% attribute can only appear in postcondition of function",
5220 when Attribute_Range_Length
=>
5222 Check_Discrete_Type
;
5223 Set_Etype
(N
, Universal_Integer
);
5229 when Attribute_Read
=>
5231 Check_Stream_Attribute
(TSS_Stream_Read
);
5232 Set_Etype
(N
, Standard_Void_Type
);
5233 Resolve
(N
, Standard_Void_Type
);
5234 Note_Possible_Modification
(E2
, Sure
=> True);
5240 when Attribute_Ref
=>
5244 if Nkind
(P
) /= N_Expanded_Name
5245 or else not Is_RTE
(P_Type
, RE_Address
)
5247 Error_Attr_P
("prefix of % attribute must be System.Address");
5250 Analyze_And_Resolve
(E1
, Any_Integer
);
5251 Set_Etype
(N
, RTE
(RE_Address
));
5257 when Attribute_Remainder
=>
5258 Check_Floating_Point_Type_2
;
5259 Set_Etype
(N
, P_Base_Type
);
5260 Resolve
(E1
, P_Base_Type
);
5261 Resolve
(E2
, P_Base_Type
);
5263 ---------------------
5264 -- Restriction_Set --
5265 ---------------------
5267 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5270 Unam
: Unit_Name_Type
;
5275 Check_System_Prefix
;
5277 -- No_Dependence case
5279 if Nkind
(E1
) = N_Parameter_Association
then
5280 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5281 U
:= Explicit_Actual_Parameter
(E1
);
5283 if not OK_No_Dependence_Unit_Name
(U
) then
5284 Set_Boolean_Result
(N
, False);
5288 -- See if there is an entry already in the table. That's the
5289 -- case in which we can return True.
5291 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5292 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5293 and then No_Dependences
.Table
(J
).Warn
= False
5295 Set_Boolean_Result
(N
, True);
5300 -- If not in the No_Dependence table, result is False
5302 Set_Boolean_Result
(N
, False);
5304 -- In this case, we must ensure that the binder will reject any
5305 -- other unit in the partition that sets No_Dependence for this
5306 -- unit. We do that by making an entry in the special table kept
5307 -- for this purpose (if the entry is not there already).
5309 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5311 for J
in Restriction_Set_Dependences
.First
..
5312 Restriction_Set_Dependences
.Last
5314 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5319 Restriction_Set_Dependences
.Append
(Unam
);
5321 -- Normal restriction case
5324 if Nkind
(E1
) /= N_Identifier
then
5325 Set_Boolean_Result
(N
, False);
5326 Error_Attr
("attribute % requires restriction identifier", E1
);
5329 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5331 if R
= Not_A_Restriction_Id
then
5332 Set_Boolean_Result
(N
, False);
5333 Error_Msg_Node_1
:= E1
;
5334 Error_Attr
("invalid restriction identifier &", E1
);
5336 elsif R
not in Partition_Boolean_Restrictions
then
5337 Set_Boolean_Result
(N
, False);
5338 Error_Msg_Node_1
:= E1
;
5340 ("& is not a boolean partition-wide restriction", E1
);
5343 if Restriction_Active
(R
) then
5344 Set_Boolean_Result
(N
, True);
5346 Check_Restriction
(R
, N
);
5347 Set_Boolean_Result
(N
, False);
5351 end Restriction_Set
;
5357 when Attribute_Round
=>
5359 Check_Decimal_Fixed_Point_Type
;
5360 Set_Etype
(N
, P_Base_Type
);
5362 -- Because the context is universal_real (3.5.10(12)) it is a
5363 -- legal context for a universal fixed expression. This is the
5364 -- only attribute whose functional description involves U_R.
5366 if Etype
(E1
) = Universal_Fixed
then
5368 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5369 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5370 Expression
=> Relocate_Node
(E1
));
5378 Resolve
(E1
, Any_Real
);
5384 when Attribute_Rounding
=>
5385 Check_Floating_Point_Type_1
;
5386 Set_Etype
(N
, P_Base_Type
);
5387 Resolve
(E1
, P_Base_Type
);
5393 when Attribute_Safe_Emax
=>
5394 Check_Floating_Point_Type_0
;
5395 Set_Etype
(N
, Universal_Integer
);
5401 when Attribute_Safe_First
=>
5402 Check_Floating_Point_Type_0
;
5403 Set_Etype
(N
, Universal_Real
);
5409 when Attribute_Safe_Large
=>
5412 Set_Etype
(N
, Universal_Real
);
5418 when Attribute_Safe_Last
=>
5419 Check_Floating_Point_Type_0
;
5420 Set_Etype
(N
, Universal_Real
);
5426 when Attribute_Safe_Small
=>
5429 Set_Etype
(N
, Universal_Real
);
5431 --------------------------
5432 -- Scalar_Storage_Order --
5433 --------------------------
5435 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5437 Ent
: Entity_Id
:= Empty
;
5443 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5445 -- In GNAT mode, the attribute applies to generic types as well
5446 -- as composite types, and for non-composite types always returns
5447 -- the default bit order for the target.
5449 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5450 and then not In_Instance
5453 ("prefix of % attribute must be record or array type");
5455 elsif not Is_Generic_Type
(P_Type
) then
5456 if Bytes_Big_Endian
then
5457 Ent
:= RTE
(RE_High_Order_First
);
5459 Ent
:= RTE
(RE_Low_Order_First
);
5463 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5464 Ent
:= RTE
(RE_High_Order_First
);
5467 Ent
:= RTE
(RE_Low_Order_First
);
5470 if Present
(Ent
) then
5471 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5474 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5477 -- Reset incorrect indication of staticness
5479 Set_Is_Static_Expression
(N
, False);
5480 end Scalar_Storage_Order
;
5486 when Attribute_Scale
=>
5488 Check_Decimal_Fixed_Point_Type
;
5489 Set_Etype
(N
, Universal_Integer
);
5495 when Attribute_Scaling
=>
5496 Check_Floating_Point_Type_2
;
5497 Set_Etype
(N
, P_Base_Type
);
5498 Resolve
(E1
, P_Base_Type
);
5504 when Attribute_Signed_Zeros
=>
5505 Check_Floating_Point_Type_0
;
5506 Set_Etype
(N
, Standard_Boolean
);
5512 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5516 -- If prefix is parameterless function call, rewrite and resolve
5519 if Is_Entity_Name
(P
)
5520 and then Ekind
(Entity
(P
)) = E_Function
5524 -- Similar processing for a protected function call
5526 elsif Nkind
(P
) = N_Selected_Component
5527 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5532 if Is_Object_Reference
(P
) then
5533 Check_Object_Reference
(P
);
5535 elsif Is_Entity_Name
(P
)
5536 and then (Is_Type
(Entity
(P
))
5537 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5541 elsif Nkind
(P
) = N_Type_Conversion
5542 and then not Comes_From_Source
(P
)
5546 -- Some other compilers allow dubious use of X'???'Size
5548 elsif Relaxed_RM_Semantics
5549 and then Nkind
(P
) = N_Attribute_Reference
5554 Error_Attr_P
("invalid prefix for % attribute");
5557 Check_Not_Incomplete_Type
;
5559 Set_Etype
(N
, Universal_Integer
);
5566 when Attribute_Small
=>
5569 Set_Etype
(N
, Universal_Real
);
5575 when Attribute_Storage_Pool |
5576 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5580 if Is_Access_Type
(P_Type
) then
5581 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5583 ("cannot use % attribute for access-to-subprogram type");
5586 -- Set appropriate entity
5588 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5589 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5591 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5594 if Attr_Id
= Attribute_Storage_Pool
then
5595 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5596 Name_Simple_Storage_Pool_Type
))
5598 Error_Msg_Name_1
:= Aname
;
5599 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5600 Error_Msg_N
("cannot use % attribute for type with simple "
5601 & "storage pool<<", N
);
5602 Error_Msg_N
("\Program_Error [<<", N
);
5605 (N
, Make_Raise_Program_Error
5606 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5609 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5611 -- In the Simple_Storage_Pool case, verify that the pool entity is
5612 -- actually of a simple storage pool type, and set the attribute's
5613 -- type to the pool object's type.
5616 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5617 Name_Simple_Storage_Pool_Type
))
5620 ("cannot use % attribute for type without simple " &
5624 Set_Etype
(N
, Etype
(Entity
(N
)));
5627 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5628 -- Storage_Pool since this attribute is not defined for such
5629 -- types (RM E.2.3(22)).
5631 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5634 Error_Attr_P
("prefix of % attribute must be access type");
5642 when Attribute_Storage_Size
=> Storage_Size
:
5646 if Is_Task_Type
(P_Type
) then
5647 Set_Etype
(N
, Universal_Integer
);
5649 -- Use with tasks is an obsolescent feature
5651 Check_Restriction
(No_Obsolescent_Features
, P
);
5653 elsif Is_Access_Type
(P_Type
) then
5654 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5656 ("cannot use % attribute for access-to-subprogram type");
5659 if Is_Entity_Name
(P
)
5660 and then Is_Type
(Entity
(P
))
5663 Set_Etype
(N
, Universal_Integer
);
5665 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5666 -- Storage_Size since this attribute is not defined for
5667 -- such types (RM E.2.3(22)).
5669 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5671 -- The prefix is allowed to be an implicit dereference of an
5672 -- access value designating a task.
5676 Set_Etype
(N
, Universal_Integer
);
5680 Error_Attr_P
("prefix of % attribute must be access or task type");
5688 when Attribute_Storage_Unit
=>
5689 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5695 when Attribute_Stream_Size
=>
5699 if Is_Entity_Name
(P
)
5700 and then Is_Elementary_Type
(Entity
(P
))
5702 Set_Etype
(N
, Universal_Integer
);
5704 Error_Attr_P
("invalid prefix for % attribute");
5711 when Attribute_Stub_Type
=>
5715 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5717 -- For a real RACW [sub]type, use corresponding stub type
5719 if not Is_Generic_Type
(P_Type
) then
5722 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5724 -- For a generic type (that has been marked as an RACW using the
5725 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5726 -- type. Note that if the actual is not a remote access type, the
5727 -- instantiation will fail.
5730 -- Note: we go to the underlying type here because the view
5731 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5735 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5740 ("prefix of% attribute must be remote access to classwide");
5747 when Attribute_Succ
=>
5751 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5752 Error_Msg_Name_1
:= Aname
;
5753 Error_Msg_Name_2
:= Chars
(P_Type
);
5754 Check_SPARK_05_Restriction
5755 ("attribute% is not allowed for type%", P
);
5758 Resolve
(E1
, P_Base_Type
);
5759 Set_Etype
(N
, P_Base_Type
);
5761 -- Since Pred works on the base type, we normally do no check for the
5762 -- floating-point case, since the base type is unconstrained. But we
5763 -- make an exception in Check_Float_Overflow mode.
5765 if Is_Floating_Point_Type
(P_Type
) then
5766 if not Range_Checks_Suppressed
(P_Base_Type
) then
5767 Set_Do_Range_Check
(E1
);
5770 -- If not modular type, test for overflow check required
5773 if not Is_Modular_Integer_Type
(P_Type
)
5774 and then not Range_Checks_Suppressed
(P_Base_Type
)
5776 Enable_Range_Check
(E1
);
5780 --------------------------------
5781 -- System_Allocator_Alignment --
5782 --------------------------------
5784 when Attribute_System_Allocator_Alignment
=>
5785 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5791 when Attribute_Tag
=> Tag
:
5796 if not Is_Tagged_Type
(P_Type
) then
5797 Error_Attr_P
("prefix of % attribute must be tagged");
5799 -- Next test does not apply to generated code why not, and what does
5800 -- the illegal reference mean???
5802 elsif Is_Object_Reference
(P
)
5803 and then not Is_Class_Wide_Type
(P_Type
)
5804 and then Comes_From_Source
(N
)
5807 ("% attribute can only be applied to objects " &
5808 "of class - wide type");
5811 -- The prefix cannot be an incomplete type. However, references to
5812 -- 'Tag can be generated when expanding interface conversions, and
5815 if Comes_From_Source
(N
) then
5816 Check_Not_Incomplete_Type
;
5819 -- Set appropriate type
5821 Set_Etype
(N
, RTE
(RE_Tag
));
5828 when Attribute_Target_Name
=> Target_Name
: declare
5829 TN
: constant String := Sdefault
.Target_Name
.all;
5833 Check_Standard_Prefix
;
5837 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
5842 Make_String_Literal
(Loc
,
5843 Strval
=> TN
(TN
'First .. TL
)));
5844 Analyze_And_Resolve
(N
, Standard_String
);
5845 Set_Is_Static_Expression
(N
, True);
5852 when Attribute_Terminated
=>
5854 Set_Etype
(N
, Standard_Boolean
);
5861 when Attribute_To_Address
=> To_Address
: declare
5867 Check_System_Prefix
;
5869 Generate_Reference
(RTE
(RE_Address
), P
);
5870 Analyze_And_Resolve
(E1
, Any_Integer
);
5871 Set_Etype
(N
, RTE
(RE_Address
));
5873 if Is_Static_Expression
(E1
) then
5874 Set_Is_Static_Expression
(N
, True);
5877 -- OK static expression case, check range and set appropriate type
5879 if Is_OK_Static_Expression
(E1
) then
5880 Val
:= Expr_Value
(E1
);
5882 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
5884 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
5886 Error_Attr
("address value out of range for % attribute", E1
);
5889 -- In most cases the expression is a numeric literal or some other
5890 -- address expression, but if it is a declared constant it may be
5891 -- of a compatible type that must be left on the node.
5893 if Is_Entity_Name
(E1
) then
5896 -- Set type to universal integer if negative
5899 Set_Etype
(E1
, Universal_Integer
);
5901 -- Otherwise set type to Unsigned_64 to accomodate max values
5904 Set_Etype
(E1
, Standard_Unsigned_64
);
5908 Set_Is_Static_Expression
(N
, True);
5915 when Attribute_To_Any
=>
5917 Check_PolyORB_Attribute
;
5918 Set_Etype
(N
, RTE
(RE_Any
));
5924 when Attribute_Truncation
=>
5925 Check_Floating_Point_Type_1
;
5926 Resolve
(E1
, P_Base_Type
);
5927 Set_Etype
(N
, P_Base_Type
);
5933 when Attribute_Type_Class
=>
5936 Check_Not_Incomplete_Type
;
5937 Set_Etype
(N
, RTE
(RE_Type_Class
));
5943 when Attribute_TypeCode
=>
5945 Check_PolyORB_Attribute
;
5946 Set_Etype
(N
, RTE
(RE_TypeCode
));
5952 when Attribute_Type_Key
=>
5956 -- This processing belongs in Eval_Attribute ???
5959 function Type_Key
return String_Id
;
5960 -- A very preliminary implementation. For now, a signature
5961 -- consists of only the type name. This is clearly incomplete
5962 -- (e.g., adding a new field to a record type should change the
5963 -- type's Type_Key attribute).
5969 function Type_Key
return String_Id
is
5970 Full_Name
: constant String_Id
:=
5971 Fully_Qualified_Name_String
(Entity
(P
));
5974 -- Copy all characters in Full_Name but the trailing NUL
5977 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5978 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5981 Store_String_Chars
("'Type_Key");
5986 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5989 Analyze_And_Resolve
(N
, Standard_String
);
5995 when Attribute_UET_Address
=>
5997 Check_Unit_Name
(P
);
5998 Set_Etype
(N
, RTE
(RE_Address
));
6000 -----------------------
6001 -- Unbiased_Rounding --
6002 -----------------------
6004 when Attribute_Unbiased_Rounding
=>
6005 Check_Floating_Point_Type_1
;
6006 Set_Etype
(N
, P_Base_Type
);
6007 Resolve
(E1
, P_Base_Type
);
6009 ----------------------
6010 -- Unchecked_Access --
6011 ----------------------
6013 when Attribute_Unchecked_Access
=>
6014 if Comes_From_Source
(N
) then
6015 Check_Restriction
(No_Unchecked_Access
, N
);
6018 Analyze_Access_Attribute
;
6020 -------------------------
6021 -- Unconstrained_Array --
6022 -------------------------
6024 when Attribute_Unconstrained_Array
=>
6027 Check_Not_Incomplete_Type
;
6028 Set_Etype
(N
, Standard_Boolean
);
6029 Set_Is_Static_Expression
(N
, True);
6031 ------------------------------
6032 -- Universal_Literal_String --
6033 ------------------------------
6035 -- This is a GNAT specific attribute whose prefix must be a named
6036 -- number where the expression is either a single numeric literal,
6037 -- or a numeric literal immediately preceded by a minus sign. The
6038 -- result is equivalent to a string literal containing the text of
6039 -- the literal as it appeared in the source program with a possible
6040 -- leading minus sign.
6042 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
6046 if not Is_Entity_Name
(P
)
6047 or else Ekind
(Entity
(P
)) not in Named_Kind
6049 Error_Attr_P
("prefix for % attribute must be named number");
6056 Src
: Source_Buffer_Ptr
;
6059 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6061 if Nkind
(Expr
) = N_Op_Minus
then
6063 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6068 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6070 ("named number for % attribute must be simple literal", N
);
6073 -- Build string literal corresponding to source literal text
6078 Store_String_Char
(Get_Char_Code
('-'));
6082 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6084 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6085 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6089 -- Now we rewrite the attribute with the string literal
6092 Make_String_Literal
(Loc
, End_String
));
6094 Set_Is_Static_Expression
(N
, True);
6097 end Universal_Literal_String
;
6099 -------------------------
6100 -- Unrestricted_Access --
6101 -------------------------
6103 -- This is a GNAT specific attribute which is like Access except that
6104 -- all scope checks and checks for aliased views are omitted. It is
6105 -- documented as being equivalent to the use of the Address attribute
6106 -- followed by an unchecked conversion to the target access type.
6108 when Attribute_Unrestricted_Access
=>
6110 -- If from source, deal with relevant restrictions
6112 if Comes_From_Source
(N
) then
6113 Check_Restriction
(No_Unchecked_Access
, N
);
6115 if Nkind
(P
) in N_Has_Entity
6116 and then Present
(Entity
(P
))
6117 and then Is_Object
(Entity
(P
))
6119 Check_Restriction
(No_Implicit_Aliasing
, N
);
6123 if Is_Entity_Name
(P
) then
6124 Set_Address_Taken
(Entity
(P
));
6127 -- It might seem reasonable to call Address_Checks here to apply the
6128 -- same set of semantic checks that we enforce for 'Address (after
6129 -- all we document Unrestricted_Access as being equivalent to the
6130 -- use of Address followed by an Unchecked_Conversion). However, if
6131 -- we do enable these checks, we get multiple failures in both the
6132 -- compiler run-time and in our regression test suite, so we leave
6133 -- out these checks for now. To be investigated further some time???
6137 -- Now complete analysis using common access processing
6139 Analyze_Access_Attribute
;
6145 when Attribute_Update
=> Update
: declare
6146 Common_Typ
: Entity_Id
;
6147 -- The common type of a multiple component update for a record
6149 Comps
: Elist_Id
:= No_Elist
;
6150 -- A list used in the resolution of a record update. It contains the
6151 -- entities of all record components processed so far.
6153 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6154 -- Analyze and resolve array_component_association Assoc against the
6155 -- index of array type P_Type.
6157 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6158 -- Analyze and resolve record_component_association Comp against
6159 -- record type P_Type.
6161 ------------------------------------
6162 -- Analyze_Array_Component_Update --
6163 ------------------------------------
6165 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6169 Index_Typ
: Entity_Id
;
6173 -- The current association contains a sequence of indexes denoting
6174 -- an element of a multidimensional array:
6176 -- (Index_1, ..., Index_N)
6178 -- Examine each individual index and resolve it against the proper
6179 -- index type of the array.
6181 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6182 Expr
:= First
(Choices
(Assoc
));
6183 while Present
(Expr
) loop
6185 -- The use of others is illegal (SPARK RM 4.4.1(12))
6187 if Nkind
(Expr
) = N_Others_Choice
then
6189 ("others choice not allowed in attribute %", Expr
);
6191 -- Otherwise analyze and resolve all indexes
6194 Index
:= First
(Expressions
(Expr
));
6195 Index_Typ
:= First_Index
(P_Type
);
6196 while Present
(Index
) and then Present
(Index_Typ
) loop
6197 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6199 Next_Index
(Index_Typ
);
6202 -- Detect a case where the association either lacks an
6203 -- index or contains an extra index.
6205 if Present
(Index
) or else Present
(Index_Typ
) then
6207 ("dimension mismatch in index list", Assoc
);
6214 -- The current association denotes either a single component or a
6215 -- range of components of a one dimensional array:
6219 -- Resolve the index or its high and low bounds (if range) against
6220 -- the proper index type of the array.
6223 Index
:= First
(Choices
(Assoc
));
6224 Index_Typ
:= First_Index
(P_Type
);
6226 if Present
(Next_Index
(Index_Typ
)) then
6227 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6230 while Present
(Index
) loop
6232 -- The use of others is illegal (SPARK RM 4.4.1(12))
6234 if Nkind
(Index
) = N_Others_Choice
then
6236 ("others choice not allowed in attribute %", Index
);
6238 -- The index denotes a range of elements
6240 elsif Nkind
(Index
) = N_Range
then
6241 Low
:= Low_Bound
(Index
);
6242 High
:= High_Bound
(Index
);
6244 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6245 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6247 -- Add a range check to ensure that the bounds of the
6248 -- range are within the index type when this cannot be
6249 -- determined statically.
6251 if not Is_OK_Static_Expression
(Low
) then
6252 Set_Do_Range_Check
(Low
);
6255 if not Is_OK_Static_Expression
(High
) then
6256 Set_Do_Range_Check
(High
);
6259 -- Otherwise the index denotes a single element
6262 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6264 -- Add a range check to ensure that the index is within
6265 -- the index type when it is not possible to determine
6268 if not Is_OK_Static_Expression
(Index
) then
6269 Set_Do_Range_Check
(Index
);
6276 end Analyze_Array_Component_Update
;
6278 -------------------------------------
6279 -- Analyze_Record_Component_Update --
6280 -------------------------------------
6282 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6283 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6284 Base_Typ
: Entity_Id
;
6285 Comp_Or_Discr
: Entity_Id
;
6288 -- Find the discriminant or component whose name corresponds to
6289 -- Comp. A simple character comparison is sufficient because all
6290 -- visible names within a record type are unique.
6292 Comp_Or_Discr
:= First_Entity
(P_Type
);
6293 while Present
(Comp_Or_Discr
) loop
6294 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6296 -- Decorate the component reference by setting its entity
6297 -- and type for resolution purposes.
6299 Set_Entity
(Comp
, Comp_Or_Discr
);
6300 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6304 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6307 -- Diagnose an illegal reference
6309 if Present
(Comp_Or_Discr
) then
6310 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6312 ("attribute % may not modify record discriminants", Comp
);
6314 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6315 if Contains
(Comps
, Comp_Or_Discr
) then
6316 Error_Msg_N
("component & already updated", Comp
);
6318 -- Mark this component as processed
6321 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6325 -- The update aggregate mentions an entity that does not belong to
6329 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6332 -- Verify the consistency of types when the current component is
6333 -- part of a miltiple component update.
6335 -- Comp_1, ..., Comp_N => <value>
6337 if Present
(Etype
(Comp
)) then
6338 Base_Typ
:= Base_Type
(Etype
(Comp
));
6340 -- Save the type of the first component reference as the
6341 -- remaning references (if any) must resolve to this type.
6343 if No
(Common_Typ
) then
6344 Common_Typ
:= Base_Typ
;
6346 elsif Base_Typ
/= Common_Typ
then
6348 ("components in choice list must have same type", Comp
);
6351 end Analyze_Record_Component_Update
;
6358 -- Start of processing for Update
6363 if not Is_Object_Reference
(P
) then
6364 Error_Attr_P
("prefix of attribute % must denote an object");
6366 elsif not Is_Array_Type
(P_Type
)
6367 and then not Is_Record_Type
(P_Type
)
6369 Error_Attr_P
("prefix of attribute % must be a record or array");
6371 elsif Is_Limited_View
(P_Type
) then
6372 Error_Attr
("prefix of attribute % cannot be limited", N
);
6374 elsif Nkind
(E1
) /= N_Aggregate
then
6375 Error_Attr
("attribute % requires component association list", N
);
6378 -- Inspect the update aggregate, looking at all the associations and
6379 -- choices. Perform the following checks:
6381 -- 1) Legality of "others" in all cases
6382 -- 2) Legality of <>
6383 -- 3) Component legality for arrays
6384 -- 4) Component legality for records
6386 -- The remaining checks are performed on the expanded attribute
6388 Assoc
:= First
(Component_Associations
(E1
));
6389 while Present
(Assoc
) loop
6391 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6393 if Box_Present
(Assoc
) then
6395 ("default initialization not allowed in attribute %", Assoc
);
6397 -- Otherwise process the association
6400 Analyze
(Expression
(Assoc
));
6402 if Is_Array_Type
(P_Type
) then
6403 Analyze_Array_Component_Update
(Assoc
);
6405 elsif Is_Record_Type
(P_Type
) then
6407 -- Reset the common type used in a multiple component update
6408 -- as we are processing the contents of a new association.
6410 Common_Typ
:= Empty
;
6412 Comp
:= First
(Choices
(Assoc
));
6413 while Present
(Comp
) loop
6414 if Nkind
(Comp
) = N_Identifier
then
6415 Analyze_Record_Component_Update
(Comp
);
6417 -- The use of others is illegal (SPARK RM 4.4.1(5))
6419 elsif Nkind
(Comp
) = N_Others_Choice
then
6421 ("others choice not allowed in attribute %", Comp
);
6423 -- The name of a record component cannot appear in any
6428 ("name should be identifier or OTHERS", Comp
);
6439 -- The type of attribute 'Update is that of the prefix
6441 Set_Etype
(N
, P_Type
);
6448 when Attribute_Val
=> Val
: declare
6451 Check_Discrete_Type
;
6453 if Is_Boolean_Type
(P_Type
) then
6454 Error_Msg_Name_1
:= Aname
;
6455 Error_Msg_Name_2
:= Chars
(P_Type
);
6456 Check_SPARK_05_Restriction
6457 ("attribute% is not allowed for type%", P
);
6460 Resolve
(E1
, Any_Integer
);
6461 Set_Etype
(N
, P_Base_Type
);
6463 -- Note, we need a range check in general, but we wait for the
6464 -- Resolve call to do this, since we want to let Eval_Attribute
6465 -- have a chance to find an static illegality first.
6472 when Attribute_Valid
=>
6475 -- Ignore check for object if we have a 'Valid reference generated
6476 -- by the expanded code, since in some cases valid checks can occur
6477 -- on items that are names, but are not objects (e.g. attributes).
6479 if Comes_From_Source
(N
) then
6480 Check_Object_Reference
(P
);
6483 if not Is_Scalar_Type
(P_Type
) then
6484 Error_Attr_P
("object for % attribute must be of scalar type");
6487 -- If the attribute appears within the subtype's own predicate
6488 -- function, then issue a warning that this will cause infinite
6492 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6495 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6497 ("attribute Valid requires a predicate check??", N
);
6498 Error_Msg_N
("\and will result in infinite recursion??", N
);
6502 Set_Etype
(N
, Standard_Boolean
);
6508 when Attribute_Valid_Scalars
=>
6510 Check_Object_Reference
(P
);
6511 Set_Etype
(N
, Standard_Boolean
);
6513 -- Following checks are only for source types
6515 if Comes_From_Source
(N
) then
6516 if not Scalar_Part_Present
(P_Type
) then
6518 ("??attribute % always True, no scalars to check");
6521 -- Not allowed for unchecked union type
6523 if Has_Unchecked_Union
(P_Type
) then
6525 ("attribute % not allowed for Unchecked_Union type");
6533 when Attribute_Value
=> Value
:
6535 Check_SPARK_05_Restriction_On_Attribute
;
6539 -- Case of enumeration type
6541 -- When an enumeration type appears in an attribute reference, all
6542 -- literals of the type are marked as referenced. This must only be
6543 -- done if the attribute reference appears in the current source.
6544 -- Otherwise the information on references may differ between a
6545 -- normal compilation and one that performs inlining.
6547 if Is_Enumeration_Type
(P_Type
)
6548 and then In_Extended_Main_Code_Unit
(N
)
6550 Check_Restriction
(No_Enumeration_Maps
, N
);
6552 -- Mark all enumeration literals as referenced, since the use of
6553 -- the Value attribute can implicitly reference any of the
6554 -- literals of the enumeration base type.
6557 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6559 while Present
(Ent
) loop
6560 Set_Referenced
(Ent
);
6566 -- Set Etype before resolving expression because expansion of
6567 -- expression may require enclosing type. Note that the type
6568 -- returned by 'Value is the base type of the prefix type.
6570 Set_Etype
(N
, P_Base_Type
);
6571 Validate_Non_Static_Attribute_Function_Call
;
6573 -- Check restriction No_Fixed_IO
6575 if Restriction_Check_Required
(No_Fixed_IO
)
6576 and then Is_Fixed_Point_Type
(P_Type
)
6578 Check_Restriction
(No_Fixed_IO
, P
);
6586 when Attribute_Value_Size
=>
6589 Check_Not_Incomplete_Type
;
6590 Set_Etype
(N
, Universal_Integer
);
6596 when Attribute_Version
=>
6599 Set_Etype
(N
, RTE
(RE_Version_String
));
6605 when Attribute_Wchar_T_Size
=>
6606 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6612 when Attribute_Wide_Image
=> Wide_Image
:
6614 Check_SPARK_05_Restriction_On_Attribute
;
6616 Set_Etype
(N
, Standard_Wide_String
);
6618 Resolve
(E1
, P_Base_Type
);
6619 Validate_Non_Static_Attribute_Function_Call
;
6621 -- Check restriction No_Fixed_IO
6623 if Restriction_Check_Required
(No_Fixed_IO
)
6624 and then Is_Fixed_Point_Type
(P_Type
)
6626 Check_Restriction
(No_Fixed_IO
, P
);
6630 ---------------------
6631 -- Wide_Wide_Image --
6632 ---------------------
6634 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
6637 Set_Etype
(N
, Standard_Wide_Wide_String
);
6639 Resolve
(E1
, P_Base_Type
);
6640 Validate_Non_Static_Attribute_Function_Call
;
6642 -- Check restriction No_Fixed_IO
6644 if Restriction_Check_Required
(No_Fixed_IO
)
6645 and then Is_Fixed_Point_Type
(P_Type
)
6647 Check_Restriction
(No_Fixed_IO
, P
);
6649 end Wide_Wide_Image
;
6655 when Attribute_Wide_Value
=> Wide_Value
:
6657 Check_SPARK_05_Restriction_On_Attribute
;
6661 -- Set Etype before resolving expression because expansion
6662 -- of expression may require enclosing type.
6664 Set_Etype
(N
, P_Type
);
6665 Validate_Non_Static_Attribute_Function_Call
;
6667 -- Check restriction No_Fixed_IO
6669 if Restriction_Check_Required
(No_Fixed_IO
)
6670 and then Is_Fixed_Point_Type
(P_Type
)
6672 Check_Restriction
(No_Fixed_IO
, P
);
6676 ---------------------
6677 -- Wide_Wide_Value --
6678 ---------------------
6680 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6685 -- Set Etype before resolving expression because expansion
6686 -- of expression may require enclosing type.
6688 Set_Etype
(N
, P_Type
);
6689 Validate_Non_Static_Attribute_Function_Call
;
6691 -- Check restriction No_Fixed_IO
6693 if Restriction_Check_Required
(No_Fixed_IO
)
6694 and then Is_Fixed_Point_Type
(P_Type
)
6696 Check_Restriction
(No_Fixed_IO
, P
);
6698 end Wide_Wide_Value
;
6700 ---------------------
6701 -- Wide_Wide_Width --
6702 ---------------------
6704 when Attribute_Wide_Wide_Width
=>
6707 Set_Etype
(N
, Universal_Integer
);
6713 when Attribute_Wide_Width
=>
6714 Check_SPARK_05_Restriction_On_Attribute
;
6717 Set_Etype
(N
, Universal_Integer
);
6723 when Attribute_Width
=>
6724 Check_SPARK_05_Restriction_On_Attribute
;
6727 Set_Etype
(N
, Universal_Integer
);
6733 when Attribute_Word_Size
=>
6734 Standard_Attribute
(System_Word_Size
);
6740 when Attribute_Write
=>
6742 Check_Stream_Attribute
(TSS_Stream_Write
);
6743 Set_Etype
(N
, Standard_Void_Type
);
6744 Resolve
(N
, Standard_Void_Type
);
6748 -- All errors raise Bad_Attribute, so that we get out before any further
6749 -- damage occurs when an error is detected (for example, if we check for
6750 -- one attribute expression, and the check succeeds, we want to be able
6751 -- to proceed securely assuming that an expression is in fact present.
6753 -- Note: we set the attribute analyzed in this case to prevent any
6754 -- attempt at reanalysis which could generate spurious error msgs.
6757 when Bad_Attribute
=>
6759 Set_Etype
(N
, Any_Type
);
6761 end Analyze_Attribute
;
6763 --------------------
6764 -- Eval_Attribute --
6765 --------------------
6767 procedure Eval_Attribute
(N
: Node_Id
) is
6768 Loc
: constant Source_Ptr
:= Sloc
(N
);
6769 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6770 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6771 P
: constant Node_Id
:= Prefix
(N
);
6773 C_Type
: constant Entity_Id
:= Etype
(N
);
6774 -- The type imposed by the context
6777 -- First expression, or Empty if none
6780 -- Second expression, or Empty if none
6782 P_Entity
: Entity_Id
;
6783 -- Entity denoted by prefix
6786 -- The type of the prefix
6788 P_Base_Type
: Entity_Id
;
6789 -- The base type of the prefix type
6791 P_Root_Type
: Entity_Id
;
6792 -- The root type of the prefix type
6795 -- True if the result is Static. This is set by the general processing
6796 -- to true if the prefix is static, and all expressions are static. It
6797 -- can be reset as processing continues for particular attributes. This
6798 -- flag can still be True if the reference raises a constraint error.
6799 -- Is_Static_Expression (N) is set to follow this value as it is set
6800 -- and we could always reference this, but it is convenient to have a
6801 -- simple short name to use, since it is frequently referenced.
6803 Lo_Bound
, Hi_Bound
: Node_Id
;
6804 -- Expressions for low and high bounds of type or array index referenced
6805 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6808 -- Constraint error node used if we have an attribute reference has
6809 -- an argument that raises a constraint error. In this case we replace
6810 -- the attribute with a raise constraint_error node. This is important
6811 -- processing, since otherwise gigi might see an attribute which it is
6812 -- unprepared to deal with.
6814 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
6815 -- If Bound is a reference to a discriminant of a task or protected type
6816 -- occurring within the object's body, rewrite attribute reference into
6817 -- a reference to the corresponding discriminal. Use for the expansion
6818 -- of checks against bounds of entry family index subtypes.
6820 procedure Check_Expressions
;
6821 -- In case where the attribute is not foldable, the expressions, if
6822 -- any, of the attribute, are in a non-static context. This procedure
6823 -- performs the required additional checks.
6825 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
6826 -- Determines if the given type has compile time known bounds. Note
6827 -- that we enter the case statement even in cases where the prefix
6828 -- type does NOT have known bounds, so it is important to guard any
6829 -- attempt to evaluate both bounds with a call to this function.
6831 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
6832 -- This procedure is called when the attribute N has a non-static
6833 -- but compile time known value given by Val. It includes the
6834 -- necessary checks for out of range values.
6836 function Fore_Value
return Nat
;
6837 -- Computes the Fore value for the current attribute prefix, which is
6838 -- known to be a static fixed-point type. Used by Fore and Width.
6840 function Mantissa
return Uint
;
6841 -- Returns the Mantissa value for the prefix type
6843 procedure Set_Bounds
;
6844 -- Used for First, Last and Length attributes applied to an array or
6845 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6846 -- and high bound expressions for the index referenced by the attribute
6847 -- designator (i.e. the first index if no expression is present, and the
6848 -- N'th index if the value N is present as an expression). Also used for
6849 -- First and Last of scalar types and for First_Valid and Last_Valid.
6850 -- Static is reset to False if the type or index type is not statically
6853 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
6854 -- Verify that the prefix of a potentially static array attribute
6855 -- satisfies the conditions of 4.9 (14).
6857 -----------------------------------
6858 -- Check_Concurrent_Discriminant --
6859 -----------------------------------
6861 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
6863 -- The concurrent (task or protected) type
6866 if Nkind
(Bound
) = N_Identifier
6867 and then Ekind
(Entity
(Bound
)) = E_Discriminant
6868 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
6870 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
6872 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
6874 -- Find discriminant of original concurrent type, and use
6875 -- its current discriminal, which is the renaming within
6876 -- the task/protected body.
6880 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
6883 end Check_Concurrent_Discriminant
;
6885 -----------------------
6886 -- Check_Expressions --
6887 -----------------------
6889 procedure Check_Expressions
is
6893 while Present
(E
) loop
6894 Check_Non_Static_Context
(E
);
6897 end Check_Expressions
;
6899 ----------------------------------
6900 -- Compile_Time_Known_Attribute --
6901 ----------------------------------
6903 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
6904 T
: constant Entity_Id
:= Etype
(N
);
6907 Fold_Uint
(N
, Val
, False);
6909 -- Check that result is in bounds of the type if it is static
6911 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
6914 elsif Is_Out_Of_Range
(N
, T
) then
6915 Apply_Compile_Time_Constraint_Error
6916 (N
, "value not in range of}??", CE_Range_Check_Failed
);
6918 elsif not Range_Checks_Suppressed
(T
) then
6919 Enable_Range_Check
(N
);
6922 Set_Do_Range_Check
(N
, False);
6924 end Compile_Time_Known_Attribute
;
6926 -------------------------------
6927 -- Compile_Time_Known_Bounds --
6928 -------------------------------
6930 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
6933 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
6935 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
6936 end Compile_Time_Known_Bounds
;
6942 -- Note that the Fore calculation is based on the actual values
6943 -- of the bounds, and does not take into account possible rounding.
6945 function Fore_Value
return Nat
is
6946 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
6947 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
6948 Small
: constant Ureal
:= Small_Value
(P_Type
);
6949 Lo_Real
: constant Ureal
:= Lo
* Small
;
6950 Hi_Real
: constant Ureal
:= Hi
* Small
;
6955 -- Bounds are given in terms of small units, so first compute
6956 -- proper values as reals.
6958 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
6961 -- Loop to compute proper value if more than one digit required
6963 while T
>= Ureal_10
loop
6975 -- Table of mantissa values accessed by function Computed using
6978 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6980 -- where D is T'Digits (RM83 3.5.7)
6982 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7024 function Mantissa
return Uint
is
7027 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7034 procedure Set_Bounds
is
7040 -- For a string literal subtype, we have to construct the bounds.
7041 -- Valid Ada code never applies attributes to string literals, but
7042 -- it is convenient to allow the expander to generate attribute
7043 -- references of this type (e.g. First and Last applied to a string
7046 -- Note that the whole point of the E_String_Literal_Subtype is to
7047 -- avoid this construction of bounds, but the cases in which we
7048 -- have to materialize them are rare enough that we don't worry.
7050 -- The low bound is simply the low bound of the base type. The
7051 -- high bound is computed from the length of the string and this
7054 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7055 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7056 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7059 Make_Integer_Literal
(Sloc
(P
),
7061 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7063 Set_Parent
(Hi_Bound
, P
);
7064 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7067 -- For non-array case, just get bounds of scalar type
7069 elsif Is_Scalar_Type
(P_Type
) then
7072 -- For a fixed-point type, we must freeze to get the attributes
7073 -- of the fixed-point type set now so we can reference them.
7075 if Is_Fixed_Point_Type
(P_Type
)
7076 and then not Is_Frozen
(Base_Type
(P_Type
))
7077 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7078 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7080 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7083 -- For array case, get type of proper index
7089 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7092 Indx
:= First_Index
(P_Type
);
7093 for J
in 1 .. Ndim
- 1 loop
7097 -- If no index type, get out (some other error occurred, and
7098 -- we don't have enough information to complete the job).
7106 Ityp
:= Etype
(Indx
);
7109 -- A discrete range in an index constraint is allowed to be a
7110 -- subtype indication. This is syntactically a pain, but should
7111 -- not propagate to the entity for the corresponding index subtype.
7112 -- After checking that the subtype indication is legal, the range
7113 -- of the subtype indication should be transfered to the entity.
7114 -- The attributes for the bounds should remain the simple retrievals
7115 -- that they are now.
7117 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7118 Hi_Bound
:= Type_High_Bound
(Ityp
);
7120 -- If subtype is non-static, result is definitely non-static
7122 if not Is_Static_Subtype
(Ityp
) then
7124 Set_Is_Static_Expression
(N
, False);
7126 -- Subtype is static, does it raise CE?
7128 elsif not Is_OK_Static_Subtype
(Ityp
) then
7129 Set_Raises_Constraint_Error
(N
);
7133 -------------------------------
7134 -- Statically_Denotes_Entity --
7135 -------------------------------
7137 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7141 if not Is_Entity_Name
(N
) then
7148 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7149 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7150 end Statically_Denotes_Entity
;
7152 -- Start of processing for Eval_Attribute
7155 -- Initialize result as non-static, will be reset if appropriate
7157 Set_Is_Static_Expression
(N
, False);
7160 -- Acquire first two expressions (at the moment, no attributes take more
7161 -- than two expressions in any case).
7163 if Present
(Expressions
(N
)) then
7164 E1
:= First
(Expressions
(N
));
7171 -- Special processing for Enabled attribute. This attribute has a very
7172 -- special prefix, and the easiest way to avoid lots of special checks
7173 -- to protect this special prefix from causing trouble is to deal with
7174 -- this attribute immediately and be done with it.
7176 if Id
= Attribute_Enabled
then
7178 -- We skip evaluation if the expander is not active. This is not just
7179 -- an optimization. It is of key importance that we not rewrite the
7180 -- attribute in a generic template, since we want to pick up the
7181 -- setting of the check in the instance, and testing expander active
7182 -- is as easy way of doing this as any.
7184 if Expander_Active
then
7186 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7191 if C
in Predefined_Check_Id
then
7192 R
:= Scope_Suppress
.Suppress
(C
);
7194 R
:= Is_Check_Suppressed
(Empty
, C
);
7198 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7201 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7208 -- Special processing for cases where the prefix is an object. For
7209 -- this purpose, a string literal counts as an object (attributes
7210 -- of string literals can only appear in generated code).
7212 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7214 -- For Component_Size, the prefix is an array object, and we apply
7215 -- the attribute to the type of the object. This is allowed for
7216 -- both unconstrained and constrained arrays, since the bounds
7217 -- have no influence on the value of this attribute.
7219 if Id
= Attribute_Component_Size
then
7220 P_Entity
:= Etype
(P
);
7222 -- For First and Last, the prefix is an array object, and we apply
7223 -- the attribute to the type of the array, but we need a constrained
7224 -- type for this, so we use the actual subtype if available.
7226 elsif Id
= Attribute_First
or else
7227 Id
= Attribute_Last
or else
7228 Id
= Attribute_Length
7231 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7234 if Present
(AS
) and then Is_Constrained
(AS
) then
7237 -- If we have an unconstrained type we cannot fold
7245 -- For Size, give size of object if available, otherwise we
7246 -- cannot fold Size.
7248 elsif Id
= Attribute_Size
then
7249 if Is_Entity_Name
(P
)
7250 and then Known_Esize
(Entity
(P
))
7252 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7260 -- For Alignment, give size of object if available, otherwise we
7261 -- cannot fold Alignment.
7263 elsif Id
= Attribute_Alignment
then
7264 if Is_Entity_Name
(P
)
7265 and then Known_Alignment
(Entity
(P
))
7267 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7275 -- For Lock_Free, we apply the attribute to the type of the object.
7276 -- This is allowed since we have already verified that the type is a
7279 elsif Id
= Attribute_Lock_Free
then
7280 P_Entity
:= Etype
(P
);
7282 -- No other attributes for objects are folded
7289 -- Cases where P is not an object. Cannot do anything if P is not the
7290 -- name of an entity.
7292 elsif not Is_Entity_Name
(P
) then
7296 -- Otherwise get prefix entity
7299 P_Entity
:= Entity
(P
);
7302 -- If we are asked to evaluate an attribute where the prefix is a
7303 -- non-frozen generic actual type whose RM_Size is still set to zero,
7304 -- then abandon the effort.
7306 if Is_Type
(P_Entity
)
7307 and then (not Is_Frozen
(P_Entity
)
7308 and then Is_Generic_Actual_Type
(P_Entity
)
7309 and then RM_Size
(P_Entity
) = 0)
7311 -- However, the attribute Unconstrained_Array must be evaluated,
7312 -- since it is documented to be a static attribute (and can for
7313 -- example appear in a Compile_Time_Warning pragma). The frozen
7314 -- status of the type does not affect its evaluation.
7316 and then Id
/= Attribute_Unconstrained_Array
7321 -- At this stage P_Entity is the entity to which the attribute
7322 -- is to be applied. This is usually simply the entity of the
7323 -- prefix, except in some cases of attributes for objects, where
7324 -- as described above, we apply the attribute to the object type.
7326 -- Here is where we make sure that static attributes are properly
7327 -- marked as such. These are attributes whose prefix is a static
7328 -- scalar subtype, whose result is scalar, and whose arguments, if
7329 -- present, are static scalar expressions. Note that such references
7330 -- are static expressions even if they raise Constraint_Error.
7332 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7333 -- though evaluating it raises constraint error. This means that a
7334 -- declaration like:
7336 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7338 -- is legal, since here this expression appears in a statically
7339 -- unevaluated position, so it does not actually raise an exception.
7341 if Is_Scalar_Type
(P_Entity
)
7342 and then (not Is_Generic_Type
(P_Entity
))
7343 and then Is_Static_Subtype
(P_Entity
)
7344 and then Is_Scalar_Type
(Etype
(N
))
7347 or else (Is_Static_Expression
(E1
)
7348 and then Is_Scalar_Type
(Etype
(E1
))))
7351 or else (Is_Static_Expression
(E2
)
7352 and then Is_Scalar_Type
(Etype
(E1
))))
7355 Set_Is_Static_Expression
(N
, True);
7358 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7359 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7360 -- Note we allow non-static non-generic types at this stage as further
7363 if Is_Type
(P_Entity
)
7364 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7365 and then (not Is_Generic_Type
(P_Entity
))
7369 -- Second foldable possibility is an array object (RM 4.9(8))
7371 elsif (Ekind
(P_Entity
) = E_Variable
7373 Ekind
(P_Entity
) = E_Constant
)
7374 and then Is_Array_Type
(Etype
(P_Entity
))
7375 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7377 P_Type
:= Etype
(P_Entity
);
7379 -- If the entity is an array constant with an unconstrained nominal
7380 -- subtype then get the type from the initial value. If the value has
7381 -- been expanded into assignments, there is no expression and the
7382 -- attribute reference remains dynamic.
7384 -- We could do better here and retrieve the type ???
7386 if Ekind
(P_Entity
) = E_Constant
7387 and then not Is_Constrained
(P_Type
)
7389 if No
(Constant_Value
(P_Entity
)) then
7392 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7396 -- Definite must be folded if the prefix is not a generic type, that
7397 -- is to say if we are within an instantiation. Same processing applies
7398 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7399 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7401 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7402 Id
= Attribute_Definite
or else
7403 Id
= Attribute_Has_Access_Values
or else
7404 Id
= Attribute_Has_Discriminants
or else
7405 Id
= Attribute_Has_Tagged_Values
or else
7406 Id
= Attribute_Lock_Free
or else
7407 Id
= Attribute_Type_Class
or else
7408 Id
= Attribute_Unconstrained_Array
or else
7409 Id
= Attribute_Max_Alignment_For_Allocation
)
7410 and then not Is_Generic_Type
(P_Entity
)
7414 -- We can fold 'Size applied to a type if the size is known (as happens
7415 -- for a size from an attribute definition clause). At this stage, this
7416 -- can happen only for types (e.g. record types) for which the size is
7417 -- always non-static. We exclude generic types from consideration (since
7418 -- they have bogus sizes set within templates).
7420 elsif Id
= Attribute_Size
7421 and then Is_Type
(P_Entity
)
7422 and then (not Is_Generic_Type
(P_Entity
))
7423 and then Known_Static_RM_Size
(P_Entity
)
7425 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7428 -- We can fold 'Alignment applied to a type if the alignment is known
7429 -- (as happens for an alignment from an attribute definition clause).
7430 -- At this stage, this can happen only for types (e.g. record types) for
7431 -- which the size is always non-static. We exclude generic types from
7432 -- consideration (since they have bogus sizes set within templates).
7434 elsif Id
= Attribute_Alignment
7435 and then Is_Type
(P_Entity
)
7436 and then (not Is_Generic_Type
(P_Entity
))
7437 and then Known_Alignment
(P_Entity
)
7439 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7442 -- If this is an access attribute that is known to fail accessibility
7443 -- check, rewrite accordingly.
7445 elsif Attribute_Name
(N
) = Name_Access
7446 and then Raises_Constraint_Error
(N
)
7449 Make_Raise_Program_Error
(Loc
,
7450 Reason
=> PE_Accessibility_Check_Failed
));
7451 Set_Etype
(N
, C_Type
);
7454 -- No other cases are foldable (they certainly aren't static, and at
7455 -- the moment we don't try to fold any cases other than the ones above).
7462 -- If either attribute or the prefix is Any_Type, then propagate
7463 -- Any_Type to the result and don't do anything else at all.
7465 if P_Type
= Any_Type
7466 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7467 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7469 Set_Etype
(N
, Any_Type
);
7473 -- Scalar subtype case. We have not yet enforced the static requirement
7474 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7475 -- of non-static attribute references (e.g. S'Digits for a non-static
7476 -- floating-point type, which we can compute at compile time).
7478 -- Note: this folding of non-static attributes is not simply a case of
7479 -- optimization. For many of the attributes affected, Gigi cannot handle
7480 -- the attribute and depends on the front end having folded them away.
7482 -- Note: although we don't require staticness at this stage, we do set
7483 -- the Static variable to record the staticness, for easy reference by
7484 -- those attributes where it matters (e.g. Succ and Pred), and also to
7485 -- be used to ensure that non-static folded things are not marked as
7486 -- being static (a check that is done right at the end).
7488 P_Root_Type
:= Root_Type
(P_Type
);
7489 P_Base_Type
:= Base_Type
(P_Type
);
7491 -- If the root type or base type is generic, then we cannot fold. This
7492 -- test is needed because subtypes of generic types are not always
7493 -- marked as being generic themselves (which seems odd???)
7495 if Is_Generic_Type
(P_Root_Type
)
7496 or else Is_Generic_Type
(P_Base_Type
)
7501 if Is_Scalar_Type
(P_Type
) then
7502 if not Is_Static_Subtype
(P_Type
) then
7504 Set_Is_Static_Expression
(N
, False);
7505 elsif not Is_OK_Static_Subtype
(P_Type
) then
7506 Set_Raises_Constraint_Error
(N
);
7509 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7510 -- since we can't do anything with unconstrained arrays. In addition,
7511 -- only the First, Last and Length attributes are possibly static.
7513 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7514 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7515 -- Unconstrained_Array are again exceptions, because they apply as well
7516 -- to unconstrained types.
7518 -- In addition Component_Size is an exception since it is possibly
7519 -- foldable, even though it is never static, and it does apply to
7520 -- unconstrained arrays. Furthermore, it is essential to fold this
7521 -- in the packed case, since otherwise the value will be incorrect.
7523 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7524 Id
= Attribute_Definite
or else
7525 Id
= Attribute_Has_Access_Values
or else
7526 Id
= Attribute_Has_Discriminants
or else
7527 Id
= Attribute_Has_Tagged_Values
or else
7528 Id
= Attribute_Lock_Free
or else
7529 Id
= Attribute_Type_Class
or else
7530 Id
= Attribute_Unconstrained_Array
or else
7531 Id
= Attribute_Component_Size
7534 Set_Is_Static_Expression
(N
, False);
7536 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7537 if not Is_Constrained
(P_Type
)
7538 or else (Id
/= Attribute_First
and then
7539 Id
/= Attribute_Last
and then
7540 Id
/= Attribute_Length
)
7546 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7547 -- scalar case, we hold off on enforcing staticness, since there are
7548 -- cases which we can fold at compile time even though they are not
7549 -- static (e.g. 'Length applied to a static index, even though other
7550 -- non-static indexes make the array type non-static). This is only
7551 -- an optimization, but it falls out essentially free, so why not.
7552 -- Again we compute the variable Static for easy reference later
7553 -- (note that no array attributes are static in Ada 83).
7555 -- We also need to set Static properly for subsequent legality checks
7556 -- which might otherwise accept non-static constants in contexts
7557 -- where they are not legal.
7560 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
7561 Set_Is_Static_Expression
(N
, Static
);
7567 Nod
:= First_Index
(P_Type
);
7569 -- The expression is static if the array type is constrained
7570 -- by given bounds, and not by an initial expression. Constant
7571 -- strings are static in any case.
7573 if Root_Type
(P_Type
) /= Standard_String
then
7575 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
7576 Set_Is_Static_Expression
(N
, Static
);
7579 while Present
(Nod
) loop
7580 if not Is_Static_Subtype
(Etype
(Nod
)) then
7582 Set_Is_Static_Expression
(N
, False);
7584 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
7585 Set_Raises_Constraint_Error
(N
);
7587 Set_Is_Static_Expression
(N
, False);
7590 -- If however the index type is generic, or derived from
7591 -- one, attributes cannot be folded.
7593 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
7594 and then Id
/= Attribute_Component_Size
7604 -- Check any expressions that are present. Note that these expressions,
7605 -- depending on the particular attribute type, are either part of the
7606 -- attribute designator, or they are arguments in a case where the
7607 -- attribute reference returns a function. In the latter case, the
7608 -- rule in (RM 4.9(22)) applies and in particular requires the type
7609 -- of the expressions to be scalar in order for the attribute to be
7610 -- considered to be static.
7618 while Present
(E
) loop
7620 -- If expression is not static, then the attribute reference
7621 -- result certainly cannot be static.
7623 if not Is_Static_Expression
(E
) then
7625 Set_Is_Static_Expression
(N
, False);
7628 if Raises_Constraint_Error
(E
) then
7629 Set_Raises_Constraint_Error
(N
);
7632 -- If the result is not known at compile time, or is not of
7633 -- a scalar type, then the result is definitely not static,
7634 -- so we can quit now.
7636 if not Compile_Time_Known_Value
(E
)
7637 or else not Is_Scalar_Type
(Etype
(E
))
7639 -- An odd special case, if this is a Pos attribute, this
7640 -- is where we need to apply a range check since it does
7641 -- not get done anywhere else.
7643 if Id
= Attribute_Pos
then
7644 if Is_Integer_Type
(Etype
(E
)) then
7645 Apply_Range_Check
(E
, Etype
(N
));
7652 -- If the expression raises a constraint error, then so does
7653 -- the attribute reference. We keep going in this case because
7654 -- we are still interested in whether the attribute reference
7655 -- is static even if it is not static.
7657 elsif Raises_Constraint_Error
(E
) then
7658 Set_Raises_Constraint_Error
(N
);
7664 if Raises_Constraint_Error
(Prefix
(N
)) then
7665 Set_Is_Static_Expression
(N
, False);
7670 -- Deal with the case of a static attribute reference that raises
7671 -- constraint error. The Raises_Constraint_Error flag will already
7672 -- have been set, and the Static flag shows whether the attribute
7673 -- reference is static. In any case we certainly can't fold such an
7674 -- attribute reference.
7676 -- Note that the rewriting of the attribute node with the constraint
7677 -- error node is essential in this case, because otherwise Gigi might
7678 -- blow up on one of the attributes it never expects to see.
7680 -- The constraint_error node must have the type imposed by the context,
7681 -- to avoid spurious errors in the enclosing expression.
7683 if Raises_Constraint_Error
(N
) then
7685 Make_Raise_Constraint_Error
(Sloc
(N
),
7686 Reason
=> CE_Range_Check_Failed
);
7687 Set_Etype
(CE_Node
, Etype
(N
));
7688 Set_Raises_Constraint_Error
(CE_Node
);
7690 Rewrite
(N
, Relocate_Node
(CE_Node
));
7691 Set_Raises_Constraint_Error
(N
, True);
7695 -- At this point we have a potentially foldable attribute reference.
7696 -- If Static is set, then the attribute reference definitely obeys
7697 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
7698 -- folded. If Static is not set, then the attribute may or may not
7699 -- be foldable, and the individual attribute processing routines
7700 -- test Static as required in cases where it makes a difference.
7702 -- In the case where Static is not set, we do know that all the
7703 -- expressions present are at least known at compile time (we assumed
7704 -- above that if this was not the case, then there was no hope of static
7705 -- evaluation). However, we did not require that the bounds of the
7706 -- prefix type be compile time known, let alone static). That's because
7707 -- there are many attributes that can be computed at compile time on
7708 -- non-static subtypes, even though such references are not static
7711 -- For VAX float, the root type is an IEEE type. So make sure to use the
7712 -- base type instead of the root-type for floating point attributes.
7716 -- Attributes related to Ada 2012 iterators (placeholder ???)
7718 when Attribute_Constant_Indexing |
7719 Attribute_Default_Iterator |
7720 Attribute_Implicit_Dereference |
7721 Attribute_Iterator_Element |
7722 Attribute_Iterable |
7723 Attribute_Variable_Indexing
=> null;
7725 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7726 -- These were already rejected by the parser. Thus they shouldn't
7729 when Internal_Attribute_Id
=>
7730 raise Program_Error
;
7736 when Attribute_Adjacent
=>
7740 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7747 when Attribute_Aft
=>
7748 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
7754 when Attribute_Alignment
=> Alignment_Block
: declare
7755 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7758 -- Fold if alignment is set and not otherwise
7760 if Known_Alignment
(P_TypeA
) then
7761 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
7763 end Alignment_Block
;
7765 -----------------------------
7766 -- Atomic_Always_Lock_Free --
7767 -----------------------------
7769 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7772 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
7774 V
: constant Entity_Id
:=
7776 (Support_Atomic_Primitives_On_Target
7777 and then Support_Atomic_Primitives
(P_Type
));
7780 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7782 -- Analyze and resolve as boolean. Note that this attribute is a
7783 -- static attribute in GNAT.
7785 Analyze_And_Resolve
(N
, Standard_Boolean
);
7787 Set_Is_Static_Expression
(N
, True);
7788 end Atomic_Always_Lock_Free
;
7794 -- Bit can never be folded
7796 when Attribute_Bit
=>
7803 -- Body_version can never be static
7805 when Attribute_Body_Version
=>
7812 when Attribute_Ceiling
=>
7814 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7816 --------------------
7817 -- Component_Size --
7818 --------------------
7820 when Attribute_Component_Size
=>
7821 if Known_Static_Component_Size
(P_Type
) then
7822 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
7829 when Attribute_Compose
=>
7832 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7839 -- Constrained is never folded for now, there may be cases that
7840 -- could be handled at compile time. To be looked at later.
7842 when Attribute_Constrained
=>
7844 -- The expander might fold it and set the static flag accordingly,
7845 -- but with expansion disabled (as in ASIS), it remains as an
7846 -- attribute reference, and this reference is not static.
7848 Set_Is_Static_Expression
(N
, False);
7855 when Attribute_Copy_Sign
=>
7859 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7866 when Attribute_Definite
=>
7867 Rewrite
(N
, New_Occurrence_Of
(
7868 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
7869 Analyze_And_Resolve
(N
, Standard_Boolean
);
7875 when Attribute_Delta
=>
7876 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
7882 when Attribute_Denorm
=>
7884 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
7886 ---------------------
7887 -- Descriptor_Size --
7888 ---------------------
7890 when Attribute_Descriptor_Size
=>
7897 when Attribute_Digits
=>
7898 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
7904 when Attribute_Emax
=>
7906 -- Ada 83 attribute is defined as (RM83 3.5.8)
7908 -- T'Emax = 4 * T'Mantissa
7910 Fold_Uint
(N
, 4 * Mantissa
, Static
);
7916 when Attribute_Enum_Rep
=>
7918 -- For an enumeration type with a non-standard representation use
7919 -- the Enumeration_Rep field of the proper constant. Note that this
7920 -- will not work for types Character/Wide_[Wide-]Character, since no
7921 -- real entities are created for the enumeration literals, but that
7922 -- does not matter since these two types do not have non-standard
7923 -- representations anyway.
7925 if Is_Enumeration_Type
(P_Type
)
7926 and then Has_Non_Standard_Rep
(P_Type
)
7928 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
7930 -- For enumeration types with standard representations and all
7931 -- other cases (i.e. all integer and modular types), Enum_Rep
7932 -- is equivalent to Pos.
7935 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7942 when Attribute_Enum_Val
=> Enum_Val
: declare
7946 -- We have something like Enum_Type'Enum_Val (23), so search for a
7947 -- corresponding value in the list of Enum_Rep values for the type.
7949 Lit
:= First_Literal
(P_Base_Type
);
7951 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
7952 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
7959 Apply_Compile_Time_Constraint_Error
7960 (N
, "no representation value matches",
7961 CE_Range_Check_Failed
,
7962 Warn
=> not Static
);
7972 when Attribute_Epsilon
=>
7974 -- Ada 83 attribute is defined as (RM83 3.5.8)
7976 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7978 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
7984 when Attribute_Exponent
=>
7986 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7992 when Attribute_First
=> First_Attr
:
7996 if Compile_Time_Known_Value
(Lo_Bound
) then
7997 if Is_Real_Type
(P_Type
) then
7998 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
8000 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8004 Check_Concurrent_Discriminant
(Lo_Bound
);
8012 when Attribute_First_Valid
=> First_Valid
:
8014 if Has_Predicates
(P_Type
)
8015 and then Has_Static_Predicate
(P_Type
)
8018 FirstN
: constant Node_Id
:=
8019 First
(Static_Discrete_Predicate
(P_Type
));
8021 if Nkind
(FirstN
) = N_Range
then
8022 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
8024 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
8030 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8038 when Attribute_Fixed_Value
=>
8045 when Attribute_Floor
=>
8047 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8053 when Attribute_Fore
=>
8054 if Compile_Time_Known_Bounds
(P_Type
) then
8055 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
8062 when Attribute_Fraction
=>
8064 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8066 -----------------------
8067 -- Has_Access_Values --
8068 -----------------------
8070 when Attribute_Has_Access_Values
=>
8071 Rewrite
(N
, New_Occurrence_Of
8072 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8073 Analyze_And_Resolve
(N
, Standard_Boolean
);
8075 -----------------------
8076 -- Has_Discriminants --
8077 -----------------------
8079 when Attribute_Has_Discriminants
=>
8080 Rewrite
(N
, New_Occurrence_Of
(
8081 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8082 Analyze_And_Resolve
(N
, Standard_Boolean
);
8084 ----------------------
8085 -- Has_Same_Storage --
8086 ----------------------
8088 when Attribute_Has_Same_Storage
=>
8091 -----------------------
8092 -- Has_Tagged_Values --
8093 -----------------------
8095 when Attribute_Has_Tagged_Values
=>
8096 Rewrite
(N
, New_Occurrence_Of
8097 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8098 Analyze_And_Resolve
(N
, Standard_Boolean
);
8104 when Attribute_Identity
=>
8111 -- Image is a scalar attribute, but is never static, because it is
8112 -- not a static function (having a non-scalar argument (RM 4.9(22))
8113 -- However, we can constant-fold the image of an enumeration literal
8114 -- if names are available.
8116 when Attribute_Image
=>
8117 if Is_Entity_Name
(E1
)
8118 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8119 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8120 and then not Global_Discard_Names
8123 Lit
: constant Entity_Id
:= Entity
(E1
);
8127 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8128 Set_Casing
(All_Upper_Case
);
8129 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8131 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8132 Analyze_And_Resolve
(N
, Standard_String
);
8133 Set_Is_Static_Expression
(N
, False);
8141 -- Img is a scalar attribute, but is never static, because it is
8142 -- not a static function (having a non-scalar argument (RM 4.9(22))
8144 when Attribute_Img
=>
8151 -- We never try to fold Integer_Value (though perhaps we could???)
8153 when Attribute_Integer_Value
=>
8160 -- Invalid_Value is a scalar attribute that is never static, because
8161 -- the value is by design out of range.
8163 when Attribute_Invalid_Value
=>
8170 when Attribute_Large
=>
8172 -- For fixed-point, we use the identity:
8174 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8176 if Is_Fixed_Point_Type
(P_Type
) then
8178 Make_Op_Multiply
(Loc
,
8180 Make_Op_Subtract
(Loc
,
8184 Make_Real_Literal
(Loc
, Ureal_2
),
8186 Make_Attribute_Reference
(Loc
,
8188 Attribute_Name
=> Name_Mantissa
)),
8189 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8192 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8194 Analyze_And_Resolve
(N
, C_Type
);
8196 -- Floating-point (Ada 83 compatibility)
8199 -- Ada 83 attribute is defined as (RM83 3.5.8)
8201 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8205 -- T'Emax = 4 * T'Mantissa
8209 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8217 when Attribute_Lock_Free
=> Lock_Free
: declare
8218 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8221 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8223 -- Analyze and resolve as boolean. Note that this attribute is a
8224 -- static attribute in GNAT.
8226 Analyze_And_Resolve
(N
, Standard_Boolean
);
8228 Set_Is_Static_Expression
(N
, True);
8235 when Attribute_Last
=> Last_Attr
:
8239 if Compile_Time_Known_Value
(Hi_Bound
) then
8240 if Is_Real_Type
(P_Type
) then
8241 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8243 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8247 Check_Concurrent_Discriminant
(Hi_Bound
);
8255 when Attribute_Last_Valid
=> Last_Valid
:
8257 if Has_Predicates
(P_Type
)
8258 and then Has_Static_Predicate
(P_Type
)
8261 LastN
: constant Node_Id
:=
8262 Last
(Static_Discrete_Predicate
(P_Type
));
8264 if Nkind
(LastN
) = N_Range
then
8265 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8267 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8273 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8281 when Attribute_Leading_Part
=>
8284 Eval_Fat
.Leading_Part
8285 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8292 when Attribute_Length
=> Length
: declare
8296 -- If any index type is a formal type, or derived from one, the
8297 -- bounds are not static. Treating them as static can produce
8298 -- spurious warnings or improper constant folding.
8300 Ind
:= First_Index
(P_Type
);
8301 while Present
(Ind
) loop
8302 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8311 -- For two compile time values, we can compute length
8313 if Compile_Time_Known_Value
(Lo_Bound
)
8314 and then Compile_Time_Known_Value
(Hi_Bound
)
8317 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8321 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8322 -- comparable, and we can figure out the difference between them.
8325 Diff
: aliased Uint
;
8329 Compile_Time_Compare
8330 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8333 Fold_Uint
(N
, Uint_1
, Static
);
8336 Fold_Uint
(N
, Uint_0
, Static
);
8339 if Diff
/= No_Uint
then
8340 Fold_Uint
(N
, Diff
+ 1, Static
);
8353 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8354 -- of the said attribute at the point of entry into the related loop. As
8355 -- such, the attribute reference does not need to be evaluated because
8356 -- the prefix is the one that is evaluted.
8358 when Attribute_Loop_Entry
=>
8365 when Attribute_Machine
=>
8369 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8376 when Attribute_Machine_Emax
=>
8377 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8383 when Attribute_Machine_Emin
=>
8384 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8386 ----------------------
8387 -- Machine_Mantissa --
8388 ----------------------
8390 when Attribute_Machine_Mantissa
=>
8391 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8393 -----------------------
8394 -- Machine_Overflows --
8395 -----------------------
8397 when Attribute_Machine_Overflows
=>
8399 -- Always true for fixed-point
8401 if Is_Fixed_Point_Type
(P_Type
) then
8402 Fold_Uint
(N
, True_Value
, Static
);
8404 -- Floating point case
8408 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8416 when Attribute_Machine_Radix
=>
8417 if Is_Fixed_Point_Type
(P_Type
) then
8418 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8419 and then Machine_Radix_10
(P_Type
)
8421 Fold_Uint
(N
, Uint_10
, Static
);
8423 Fold_Uint
(N
, Uint_2
, Static
);
8426 -- All floating-point type always have radix 2
8429 Fold_Uint
(N
, Uint_2
, Static
);
8432 ----------------------
8433 -- Machine_Rounding --
8434 ----------------------
8436 -- Note: for the folding case, it is fine to treat Machine_Rounding
8437 -- exactly the same way as Rounding, since this is one of the allowed
8438 -- behaviors, and performance is not an issue here. It might be a bit
8439 -- better to give the same result as it would give at run time, even
8440 -- though the non-determinism is certainly permitted.
8442 when Attribute_Machine_Rounding
=>
8444 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8446 --------------------
8447 -- Machine_Rounds --
8448 --------------------
8450 when Attribute_Machine_Rounds
=>
8452 -- Always False for fixed-point
8454 if Is_Fixed_Point_Type
(P_Type
) then
8455 Fold_Uint
(N
, False_Value
, Static
);
8457 -- Else yield proper floating-point result
8461 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8469 -- Note: Machine_Size is identical to Object_Size
8471 when Attribute_Machine_Size
=> Machine_Size
: declare
8472 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8475 if Known_Esize
(P_TypeA
) then
8476 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8484 when Attribute_Mantissa
=>
8486 -- Fixed-point mantissa
8488 if Is_Fixed_Point_Type
(P_Type
) then
8490 -- Compile time foldable case
8492 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8494 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8496 -- The calculation of the obsolete Ada 83 attribute Mantissa
8497 -- is annoying, because of AI00143, quoted here:
8499 -- !question 84-01-10
8501 -- Consider the model numbers for F:
8503 -- type F is delta 1.0 range -7.0 .. 8.0;
8505 -- The wording requires that F'MANTISSA be the SMALLEST
8506 -- integer number for which each bound of the specified
8507 -- range is either a model number or lies at most small
8508 -- distant from a model number. This means F'MANTISSA
8509 -- is required to be 3 since the range -7.0 .. 7.0 fits
8510 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8511 -- number, namely, 7. Is this analysis correct? Note that
8512 -- this implies the upper bound of the range is not
8513 -- represented as a model number.
8515 -- !response 84-03-17
8517 -- The analysis is correct. The upper and lower bounds for
8518 -- a fixed point type can lie outside the range of model
8529 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8530 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8531 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8532 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8534 -- If the Bound is exactly a model number, i.e. a multiple
8535 -- of Small, then we back it off by one to get the integer
8536 -- value that must be representable.
8538 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8539 Max_Man
:= Max_Man
- 1;
8542 -- Now find corresponding size = Mantissa value
8545 while 2 ** Siz
< Max_Man
loop
8549 Fold_Uint
(N
, Siz
, Static
);
8553 -- The case of dynamic bounds cannot be evaluated at compile
8554 -- time. Instead we use a runtime routine (see Exp_Attr).
8559 -- Floating-point Mantissa
8562 Fold_Uint
(N
, Mantissa
, Static
);
8569 when Attribute_Max
=> Max
:
8571 if Is_Real_Type
(P_Type
) then
8573 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8575 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8579 ----------------------------------
8580 -- Max_Alignment_For_Allocation --
8581 ----------------------------------
8583 -- Max_Alignment_For_Allocation is usually the Alignment. However,
8584 -- arrays are allocated with dope, so we need to take into account both
8585 -- the alignment of the array, which comes from the component alignment,
8586 -- and the alignment of the dope. Also, if the alignment is unknown, we
8587 -- use the max (it's OK to be pessimistic).
8589 when Attribute_Max_Alignment_For_Allocation
=>
8591 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
8593 if Known_Alignment
(P_Type
) and then
8594 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
8596 A
:= Alignment
(P_Type
);
8599 Fold_Uint
(N
, A
, Static
);
8602 ----------------------------------
8603 -- Max_Size_In_Storage_Elements --
8604 ----------------------------------
8606 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
8607 -- Storage_Unit boundary. We can fold any cases for which the size
8608 -- is known by the front end.
8610 when Attribute_Max_Size_In_Storage_Elements
=>
8611 if Known_Esize
(P_Type
) then
8613 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
8614 System_Storage_Unit
,
8618 --------------------
8619 -- Mechanism_Code --
8620 --------------------
8622 when Attribute_Mechanism_Code
=>
8626 Mech
: Mechanism_Type
;
8630 Mech
:= Mechanism
(P_Entity
);
8633 Val
:= UI_To_Int
(Expr_Value
(E1
));
8635 Formal
:= First_Formal
(P_Entity
);
8636 for J
in 1 .. Val
- 1 loop
8637 Next_Formal
(Formal
);
8639 Mech
:= Mechanism
(Formal
);
8643 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
8651 when Attribute_Min
=> Min
:
8653 if Is_Real_Type
(P_Type
) then
8655 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8658 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8666 when Attribute_Mod
=>
8668 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
8674 when Attribute_Model
=>
8676 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8682 when Attribute_Model_Emin
=>
8683 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
8689 when Attribute_Model_Epsilon
=>
8690 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
8692 --------------------
8693 -- Model_Mantissa --
8694 --------------------
8696 when Attribute_Model_Mantissa
=>
8697 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
8703 when Attribute_Model_Small
=>
8704 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
8710 when Attribute_Modulus
=>
8711 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
8713 --------------------
8714 -- Null_Parameter --
8715 --------------------
8717 -- Cannot fold, we know the value sort of, but the whole point is
8718 -- that there is no way to talk about this imaginary value except
8719 -- by using the attribute, so we leave it the way it is.
8721 when Attribute_Null_Parameter
=>
8728 -- The Object_Size attribute for a type returns the Esize of the
8729 -- type and can be folded if this value is known.
8731 when Attribute_Object_Size
=> Object_Size
: declare
8732 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8735 if Known_Esize
(P_TypeA
) then
8736 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8740 ----------------------
8741 -- Overlaps_Storage --
8742 ----------------------
8744 when Attribute_Overlaps_Storage
=>
8747 -------------------------
8748 -- Passed_By_Reference --
8749 -------------------------
8751 -- Scalar types are never passed by reference
8753 when Attribute_Passed_By_Reference
=>
8754 Fold_Uint
(N
, False_Value
, Static
);
8760 when Attribute_Pos
=>
8761 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8767 when Attribute_Pred
=> Pred
:
8769 -- Floating-point case
8771 if Is_Floating_Point_Type
(P_Type
) then
8773 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8777 elsif Is_Fixed_Point_Type
(P_Type
) then
8779 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
8781 -- Modular integer case (wraps)
8783 elsif Is_Modular_Integer_Type
(P_Type
) then
8784 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
8786 -- Other scalar cases
8789 pragma Assert
(Is_Scalar_Type
(P_Type
));
8791 if Is_Enumeration_Type
(P_Type
)
8792 and then Expr_Value
(E1
) =
8793 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8795 Apply_Compile_Time_Constraint_Error
8796 (N
, "Pred of `&''First`",
8797 CE_Overflow_Check_Failed
,
8799 Warn
=> not Static
);
8805 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
8813 -- No processing required, because by this stage, Range has been
8814 -- replaced by First .. Last, so this branch can never be taken.
8816 when Attribute_Range
=>
8817 raise Program_Error
;
8823 when Attribute_Range_Length
=>
8826 -- Can fold if both bounds are compile time known
8828 if Compile_Time_Known_Value
(Hi_Bound
)
8829 and then Compile_Time_Known_Value
(Lo_Bound
)
8833 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
8837 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8838 -- comparable, and we can figure out the difference between them.
8841 Diff
: aliased Uint
;
8845 Compile_Time_Compare
8846 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8849 Fold_Uint
(N
, Uint_1
, Static
);
8852 Fold_Uint
(N
, Uint_0
, Static
);
8855 if Diff
/= No_Uint
then
8856 Fold_Uint
(N
, Diff
+ 1, Static
);
8868 when Attribute_Ref
=>
8869 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8875 when Attribute_Remainder
=> Remainder
: declare
8876 X
: constant Ureal
:= Expr_Value_R
(E1
);
8877 Y
: constant Ureal
:= Expr_Value_R
(E2
);
8880 if UR_Is_Zero
(Y
) then
8881 Apply_Compile_Time_Constraint_Error
8882 (N
, "division by zero in Remainder",
8883 CE_Overflow_Check_Failed
,
8884 Warn
=> not Static
);
8890 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
8897 when Attribute_Restriction_Set
=> Restriction_Set
: declare
8899 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
8900 Set_Is_Static_Expression
(N
);
8901 end Restriction_Set
;
8907 when Attribute_Round
=> Round
:
8913 -- First we get the (exact result) in units of small
8915 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
8917 -- Now round that exactly to an integer
8919 Si
:= UR_To_Uint
(Sr
);
8921 -- Finally the result is obtained by converting back to real
8923 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
8930 when Attribute_Rounding
=>
8932 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8938 when Attribute_Safe_Emax
=>
8939 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
8945 when Attribute_Safe_First
=>
8946 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
8952 when Attribute_Safe_Large
=>
8953 if Is_Fixed_Point_Type
(P_Type
) then
8955 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
8957 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8964 when Attribute_Safe_Last
=>
8965 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8971 when Attribute_Safe_Small
=>
8973 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8974 -- for fixed-point, since is the same as Small, but we implement
8975 -- it for backwards compatibility.
8977 if Is_Fixed_Point_Type
(P_Type
) then
8978 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
8980 -- Ada 83 Safe_Small for floating-point cases
8983 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
8990 when Attribute_Scale
=>
8991 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
8997 when Attribute_Scaling
=>
9001 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9008 when Attribute_Signed_Zeros
=>
9010 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
9016 -- Size attribute returns the RM size. All scalar types can be folded,
9017 -- as well as any types for which the size is known by the front end,
9018 -- including any type for which a size attribute is specified. This is
9019 -- one of the places where it is annoying that a size of zero means two
9020 -- things (zero size for scalars, unspecified size for non-scalars).
9022 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
9023 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9026 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9030 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
9032 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
9035 -- If a size clause applies, then use the size from it.
9036 -- This is one of the rare cases where we can use the
9037 -- Size_Clause field for a subtype when Has_Size_Clause
9038 -- is False. Consider:
9040 -- type x is range 1 .. 64;
9041 -- for x'size use 12;
9042 -- subtype y is x range 0 .. 3;
9044 -- Here y has a size clause inherited from x, but normally
9045 -- it does not apply, and y'size is 2. However, y'VADS_Size
9046 -- is indeed 12 and not 2.
9049 and then Is_OK_Static_Expression
(Expression
(S
))
9051 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
9053 -- If no size is specified, then we simply use the object
9054 -- size in the VADS_Size case (e.g. Natural'Size is equal
9055 -- to Integer'Size, not one less).
9058 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9062 -- Normal case (Size) in which case we want the RM_Size
9065 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9074 when Attribute_Small
=>
9076 -- The floating-point case is present only for Ada 83 compatibility.
9077 -- Note that strictly this is an illegal addition, since we are
9078 -- extending an Ada 95 defined attribute, but we anticipate an
9079 -- ARG ruling that will permit this.
9081 if Is_Floating_Point_Type
(P_Type
) then
9083 -- Ada 83 attribute is defined as (RM83 3.5.8)
9085 -- T'Small = 2.0**(-T'Emax - 1)
9089 -- T'Emax = 4 * T'Mantissa
9091 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9093 -- Normal Ada 95 fixed-point case
9096 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9103 when Attribute_Stream_Size
=>
9110 when Attribute_Succ
=> Succ
:
9112 -- Floating-point case
9114 if Is_Floating_Point_Type
(P_Type
) then
9116 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9120 elsif Is_Fixed_Point_Type
(P_Type
) then
9121 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9123 -- Modular integer case (wraps)
9125 elsif Is_Modular_Integer_Type
(P_Type
) then
9126 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9128 -- Other scalar cases
9131 pragma Assert
(Is_Scalar_Type
(P_Type
));
9133 if Is_Enumeration_Type
(P_Type
)
9134 and then Expr_Value
(E1
) =
9135 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9137 Apply_Compile_Time_Constraint_Error
9138 (N
, "Succ of `&''Last`",
9139 CE_Overflow_Check_Failed
,
9141 Warn
=> not Static
);
9146 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9155 when Attribute_Truncation
=>
9158 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9165 when Attribute_Type_Class
=> Type_Class
: declare
9166 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9170 if Is_Descendent_Of_Address
(Typ
) then
9171 Id
:= RE_Type_Class_Address
;
9173 elsif Is_Enumeration_Type
(Typ
) then
9174 Id
:= RE_Type_Class_Enumeration
;
9176 elsif Is_Integer_Type
(Typ
) then
9177 Id
:= RE_Type_Class_Integer
;
9179 elsif Is_Fixed_Point_Type
(Typ
) then
9180 Id
:= RE_Type_Class_Fixed_Point
;
9182 elsif Is_Floating_Point_Type
(Typ
) then
9183 Id
:= RE_Type_Class_Floating_Point
;
9185 elsif Is_Array_Type
(Typ
) then
9186 Id
:= RE_Type_Class_Array
;
9188 elsif Is_Record_Type
(Typ
) then
9189 Id
:= RE_Type_Class_Record
;
9191 elsif Is_Access_Type
(Typ
) then
9192 Id
:= RE_Type_Class_Access
;
9194 elsif Is_Enumeration_Type
(Typ
) then
9195 Id
:= RE_Type_Class_Enumeration
;
9197 elsif Is_Task_Type
(Typ
) then
9198 Id
:= RE_Type_Class_Task
;
9200 -- We treat protected types like task types. It would make more
9201 -- sense to have another enumeration value, but after all the
9202 -- whole point of this feature is to be exactly DEC compatible,
9203 -- and changing the type Type_Class would not meet this requirement.
9205 elsif Is_Protected_Type
(Typ
) then
9206 Id
:= RE_Type_Class_Task
;
9208 -- Not clear if there are any other possibilities, but if there
9209 -- are, then we will treat them as the address case.
9212 Id
:= RE_Type_Class_Address
;
9215 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9218 -----------------------
9219 -- Unbiased_Rounding --
9220 -----------------------
9222 when Attribute_Unbiased_Rounding
=>
9225 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9228 -------------------------
9229 -- Unconstrained_Array --
9230 -------------------------
9232 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9233 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9236 Rewrite
(N
, New_Occurrence_Of
(
9238 Is_Array_Type
(P_Type
)
9239 and then not Is_Constrained
(Typ
)), Loc
));
9241 -- Analyze and resolve as boolean, note that this attribute is
9242 -- a static attribute in GNAT.
9244 Analyze_And_Resolve
(N
, Standard_Boolean
);
9246 Set_Is_Static_Expression
(N
, True);
9247 end Unconstrained_Array
;
9249 -- Attribute Update is never static
9251 when Attribute_Update
=>
9258 -- Processing is shared with Size
9264 when Attribute_Val
=> Val
:
9266 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9268 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9270 Apply_Compile_Time_Constraint_Error
9271 (N
, "Val expression out of range",
9272 CE_Range_Check_Failed
,
9273 Warn
=> not Static
);
9279 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9287 -- The Value_Size attribute for a type returns the RM size of the type.
9288 -- This an always be folded for scalar types, and can also be folded for
9289 -- non-scalar types if the size is set. This is one of the places where
9290 -- it is annoying that a size of zero means two things!
9292 when Attribute_Value_Size
=> Value_Size
: declare
9293 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9295 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9296 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9304 -- Version can never be static
9306 when Attribute_Version
=>
9313 -- Wide_Image is a scalar attribute, but is never static, because it
9314 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9316 when Attribute_Wide_Image
=>
9319 ---------------------
9320 -- Wide_Wide_Image --
9321 ---------------------
9323 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9324 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9326 when Attribute_Wide_Wide_Image
=>
9329 ---------------------
9330 -- Wide_Wide_Width --
9331 ---------------------
9333 -- Processing for Wide_Wide_Width is combined with Width
9339 -- Processing for Wide_Width is combined with Width
9345 -- This processing also handles the case of Wide_[Wide_]Width
9347 when Attribute_Width |
9348 Attribute_Wide_Width |
9349 Attribute_Wide_Wide_Width
=> Width
:
9351 if Compile_Time_Known_Bounds
(P_Type
) then
9353 -- Floating-point types
9355 if Is_Floating_Point_Type
(P_Type
) then
9357 -- Width is zero for a null range (RM 3.5 (38))
9359 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9360 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9362 Fold_Uint
(N
, Uint_0
, Static
);
9365 -- For floating-point, we have +N.dddE+nnn where length
9366 -- of ddd is determined by type'Digits - 1, but is one
9367 -- if Digits is one (RM 3.5 (33)).
9369 -- nnn is set to 2 for Short_Float and Float (32 bit
9370 -- floats), and 3 for Long_Float and Long_Long_Float.
9371 -- For machines where Long_Long_Float is the IEEE
9372 -- extended precision type, the exponent takes 4 digits.
9376 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9379 if Esize
(P_Type
) <= 32 then
9381 elsif Esize
(P_Type
) = 64 then
9387 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9391 -- Fixed-point types
9393 elsif Is_Fixed_Point_Type
(P_Type
) then
9395 -- Width is zero for a null range (RM 3.5 (38))
9397 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9398 Expr_Value
(Type_Low_Bound
(P_Type
))
9400 Fold_Uint
(N
, Uint_0
, Static
);
9402 -- The non-null case depends on the specific real type
9405 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9408 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9416 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9417 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9418 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9431 -- Width for types derived from Standard.Character
9432 -- and Standard.Wide_[Wide_]Character.
9434 elsif Is_Standard_Character_Type
(P_Type
) then
9437 -- Set W larger if needed
9439 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9441 -- All wide characters look like Hex_hhhhhhhh
9445 -- No need to compute this more than once
9450 C
:= Character'Val (J
);
9452 -- Test for all cases where Character'Image
9453 -- yields an image that is longer than three
9454 -- characters. First the cases of Reserved_xxx
9455 -- names (length = 12).
9458 when Reserved_128 | Reserved_129 |
9459 Reserved_132 | Reserved_153
9462 when BS | HT | LF | VT | FF | CR |
9463 SO | SI | EM | FS | GS | RS |
9464 US | RI | MW | ST | PM
9467 when NUL | SOH | STX | ETX | EOT |
9468 ENQ | ACK | BEL | DLE | DC1 |
9469 DC2 | DC3 | DC4 | NAK | SYN |
9470 ETB | CAN | SUB | ESC | DEL |
9471 BPH | NBH | NEL | SSA | ESA |
9472 HTS | HTJ | VTS | PLD | PLU |
9473 SS2 | SS3 | DCS | PU1 | PU2 |
9474 STS | CCH | SPA | EPA | SOS |
9475 SCI | CSI | OSC | APC
9478 when Space
.. Tilde |
9479 No_Break_Space
.. LC_Y_Diaeresis
9481 -- Special case of soft hyphen in Ada 2005
9483 if C
= Character'Val (16#AD#
)
9484 and then Ada_Version
>= Ada_2005
9492 W
:= Int
'Max (W
, Wt
);
9496 -- Width for types derived from Standard.Boolean
9498 elsif R
= Standard_Boolean
then
9505 -- Width for integer types
9507 elsif Is_Integer_Type
(P_Type
) then
9508 T
:= UI_Max
(abs Lo
, abs Hi
);
9516 -- User declared enum type with discard names
9518 elsif Discard_Names
(R
) then
9520 -- If range is null, result is zero, that has already
9521 -- been dealt with, so what we need is the power of ten
9522 -- that accomodates the Pos of the largest value, which
9523 -- is the high bound of the range + one for the space.
9532 -- Only remaining possibility is user declared enum type
9533 -- with normal case of Discard_Names not active.
9536 pragma Assert
(Is_Enumeration_Type
(P_Type
));
9539 L
:= First_Literal
(P_Type
);
9540 while Present
(L
) loop
9542 -- Only pay attention to in range characters
9544 if Lo
<= Enumeration_Pos
(L
)
9545 and then Enumeration_Pos
(L
) <= Hi
9547 -- For Width case, use decoded name
9549 if Id
= Attribute_Width
then
9550 Get_Decoded_Name_String
(Chars
(L
));
9551 Wt
:= Nat
(Name_Len
);
9553 -- For Wide_[Wide_]Width, use encoded name, and
9554 -- then adjust for the encoding.
9557 Get_Name_String
(Chars
(L
));
9559 -- Character literals are always of length 3
9561 if Name_Buffer
(1) = 'Q' then
9564 -- Otherwise loop to adjust for upper/wide chars
9567 Wt
:= Nat
(Name_Len
);
9569 for J
in 1 .. Name_Len
loop
9570 if Name_Buffer
(J
) = 'U' then
9572 elsif Name_Buffer
(J
) = 'W' then
9579 W
:= Int
'Max (W
, Wt
);
9586 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
9592 -- The following attributes denote functions that cannot be folded
9594 when Attribute_From_Any |
9596 Attribute_TypeCode
=>
9599 -- The following attributes can never be folded, and furthermore we
9600 -- should not even have entered the case statement for any of these.
9601 -- Note that in some cases, the values have already been folded as
9602 -- a result of the processing in Analyze_Attribute.
9604 when Attribute_Abort_Signal |
9607 Attribute_Address_Size |
9608 Attribute_Asm_Input |
9609 Attribute_Asm_Output |
9611 Attribute_Bit_Order |
9612 Attribute_Bit_Position |
9613 Attribute_Callable |
9616 Attribute_Code_Address |
9617 Attribute_Compiler_Version |
9619 Attribute_Default_Bit_Order |
9620 Attribute_Default_Scalar_Storage_Order |
9621 Attribute_Elaborated |
9622 Attribute_Elab_Body |
9623 Attribute_Elab_Spec |
9624 Attribute_Elab_Subp_Body |
9626 Attribute_External_Tag |
9627 Attribute_Fast_Math |
9628 Attribute_First_Bit |
9630 Attribute_Last_Bit |
9631 Attribute_Library_Level |
9632 Attribute_Maximum_Alignment |
9635 Attribute_Partition_ID |
9636 Attribute_Pool_Address |
9637 Attribute_Position |
9638 Attribute_Priority |
9641 Attribute_Scalar_Storage_Order |
9642 Attribute_Simple_Storage_Pool |
9643 Attribute_Storage_Pool |
9644 Attribute_Storage_Size |
9645 Attribute_Storage_Unit |
9646 Attribute_Stub_Type |
9647 Attribute_System_Allocator_Alignment |
9649 Attribute_Target_Name |
9650 Attribute_Terminated |
9651 Attribute_To_Address |
9652 Attribute_Type_Key |
9653 Attribute_UET_Address |
9654 Attribute_Unchecked_Access |
9655 Attribute_Universal_Literal_String |
9656 Attribute_Unrestricted_Access |
9658 Attribute_Valid_Scalars |
9660 Attribute_Wchar_T_Size |
9661 Attribute_Wide_Value |
9662 Attribute_Wide_Wide_Value |
9663 Attribute_Word_Size |
9666 raise Program_Error
;
9669 -- At the end of the case, one more check. If we did a static evaluation
9670 -- so that the result is now a literal, then set Is_Static_Expression
9671 -- in the constant only if the prefix type is a static subtype. For
9672 -- non-static subtypes, the folding is still OK, but not static.
9674 -- An exception is the GNAT attribute Constrained_Array which is
9675 -- defined to be a static attribute in all cases.
9677 if Nkind_In
(N
, N_Integer_Literal
,
9679 N_Character_Literal
,
9681 or else (Is_Entity_Name
(N
)
9682 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
9684 Set_Is_Static_Expression
(N
, Static
);
9686 -- If this is still an attribute reference, then it has not been folded
9687 -- and that means that its expressions are in a non-static context.
9689 elsif Nkind
(N
) = N_Attribute_Reference
then
9692 -- Note: the else case not covered here are odd cases where the
9693 -- processing has transformed the attribute into something other
9694 -- than a constant. Nothing more to do in such cases.
9701 ------------------------------
9702 -- Is_Anonymous_Tagged_Base --
9703 ------------------------------
9705 function Is_Anonymous_Tagged_Base
9707 Typ
: Entity_Id
) return Boolean
9711 Anon
= Current_Scope
9712 and then Is_Itype
(Anon
)
9713 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
9714 end Is_Anonymous_Tagged_Base
;
9716 --------------------------------
9717 -- Name_Implies_Lvalue_Prefix --
9718 --------------------------------
9720 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
9721 pragma Assert
(Is_Attribute_Name
(Nam
));
9723 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
9724 end Name_Implies_Lvalue_Prefix
;
9726 -----------------------
9727 -- Resolve_Attribute --
9728 -----------------------
9730 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
9731 Loc
: constant Source_Ptr
:= Sloc
(N
);
9732 P
: constant Node_Id
:= Prefix
(N
);
9733 Aname
: constant Name_Id
:= Attribute_Name
(N
);
9734 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
9735 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9736 Des_Btyp
: Entity_Id
;
9737 Index
: Interp_Index
;
9739 Nom_Subt
: Entity_Id
;
9741 procedure Accessibility_Message
;
9742 -- Error, or warning within an instance, if the static accessibility
9743 -- rules of 3.10.2 are violated.
9745 ---------------------------
9746 -- Accessibility_Message --
9747 ---------------------------
9749 procedure Accessibility_Message
is
9750 Indic
: Node_Id
:= Parent
(Parent
(N
));
9753 -- In an instance, this is a runtime check, but one we
9754 -- know will fail, so generate an appropriate warning.
9756 if In_Instance_Body
then
9757 Error_Msg_Warn
:= SPARK_Mode
/= On
;
9759 ("non-local pointer cannot point to local object<<", P
);
9760 Error_Msg_F
("\Program_Error [<<", P
);
9762 Make_Raise_Program_Error
(Loc
,
9763 Reason
=> PE_Accessibility_Check_Failed
));
9768 Error_Msg_F
("non-local pointer cannot point to local object", P
);
9770 -- Check for case where we have a missing access definition
9772 if Is_Record_Type
(Current_Scope
)
9774 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
9775 N_Index_Or_Discriminant_Constraint
)
9777 Indic
:= Parent
(Parent
(N
));
9778 while Present
(Indic
)
9779 and then Nkind
(Indic
) /= N_Subtype_Indication
9781 Indic
:= Parent
(Indic
);
9784 if Present
(Indic
) then
9786 ("\use an access definition for" &
9787 " the access discriminant of&",
9788 N
, Entity
(Subtype_Mark
(Indic
)));
9792 end Accessibility_Message
;
9794 -- Start of processing for Resolve_Attribute
9797 -- If error during analysis, no point in continuing, except for array
9798 -- types, where we get better recovery by using unconstrained indexes
9799 -- than nothing at all (see Check_Array_Type).
9802 and then Attr_Id
/= Attribute_First
9803 and then Attr_Id
/= Attribute_Last
9804 and then Attr_Id
/= Attribute_Length
9805 and then Attr_Id
/= Attribute_Range
9810 -- If attribute was universal type, reset to actual type
9812 if Etype
(N
) = Universal_Integer
9813 or else Etype
(N
) = Universal_Real
9818 -- Remaining processing depends on attribute
9826 -- For access attributes, if the prefix denotes an entity, it is
9827 -- interpreted as a name, never as a call. It may be overloaded,
9828 -- in which case resolution uses the profile of the context type.
9829 -- Otherwise prefix must be resolved.
9831 when Attribute_Access
9832 | Attribute_Unchecked_Access
9833 | Attribute_Unrestricted_Access
=>
9837 if Is_Variable
(P
) then
9838 Note_Possible_Modification
(P
, Sure
=> False);
9841 -- The following comes from a query concerning improper use of
9842 -- universal_access in equality tests involving anonymous access
9843 -- types. Another good reason for 'Ref, but for now disable the
9844 -- test, which breaks several filed tests???
9846 if Ekind
(Typ
) = E_Anonymous_Access_Type
9847 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
9850 Error_Msg_N
("need unique type to resolve 'Access", N
);
9851 Error_Msg_N
("\qualify attribute with some access type", N
);
9854 -- Case where prefix is an entity name
9856 if Is_Entity_Name
(P
) then
9858 -- Deal with case where prefix itself is overloaded
9860 if Is_Overloaded
(P
) then
9861 Get_First_Interp
(P
, Index
, It
);
9862 while Present
(It
.Nam
) loop
9863 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
9864 Set_Entity
(P
, It
.Nam
);
9866 -- The prefix is definitely NOT overloaded anymore at
9867 -- this point, so we reset the Is_Overloaded flag to
9868 -- avoid any confusion when reanalyzing the node.
9870 Set_Is_Overloaded
(P
, False);
9871 Set_Is_Overloaded
(N
, False);
9872 Generate_Reference
(Entity
(P
), P
);
9876 Get_Next_Interp
(Index
, It
);
9879 -- If Prefix is a subprogram name, this reference freezes:
9881 -- If it is a type, there is nothing to resolve.
9882 -- If it is an object, complete its resolution.
9884 elsif Is_Overloadable
(Entity
(P
)) then
9886 -- Avoid insertion of freeze actions in spec expression mode
9888 if not In_Spec_Expression
then
9889 Freeze_Before
(N
, Entity
(P
));
9892 -- Nothing to do if prefix is a type name
9894 elsif Is_Type
(Entity
(P
)) then
9897 -- Otherwise non-overloaded other case, resolve the prefix
9903 -- Some further error checks
9905 Error_Msg_Name_1
:= Aname
;
9907 if not Is_Entity_Name
(P
) then
9910 elsif Is_Overloadable
(Entity
(P
))
9911 and then Is_Abstract_Subprogram
(Entity
(P
))
9913 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
9914 Set_Etype
(N
, Any_Type
);
9916 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
9918 ("prefix of % attribute cannot be enumeration literal", P
);
9919 Set_Etype
(N
, Any_Type
);
9921 -- An attempt to take 'Access of a function that renames an
9922 -- enumeration literal. Issue a specialized error message.
9924 elsif Ekind
(Entity
(P
)) = E_Function
9925 and then Present
(Alias
(Entity
(P
)))
9926 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
9929 ("prefix of % attribute cannot be function renaming "
9930 & "an enumeration literal", P
);
9931 Set_Etype
(N
, Any_Type
);
9933 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
9934 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
9935 Set_Etype
(N
, Any_Type
);
9938 -- Assignments, return statements, components of aggregates,
9939 -- generic instantiations will require convention checks if
9940 -- the type is an access to subprogram. Given that there will
9941 -- also be accessibility checks on those, this is where the
9942 -- checks can eventually be centralized ???
9944 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9945 E_Anonymous_Access_Subprogram_Type
,
9946 E_Access_Protected_Subprogram_Type
,
9947 E_Anonymous_Access_Protected_Subprogram_Type
)
9949 -- Deal with convention mismatch
9951 if Convention
(Designated_Type
(Btyp
)) /=
9952 Convention
(Entity
(P
))
9955 ("subprogram & has wrong convention", P
, Entity
(P
));
9956 Error_Msg_Sloc
:= Sloc
(Btyp
);
9957 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
9959 if not Is_Itype
(Btyp
)
9960 and then not Has_Convention_Pragma
(Btyp
)
9963 ("\probable missing pragma Convention for &",
9968 Check_Subtype_Conformant
9969 (New_Id
=> Entity
(P
),
9970 Old_Id
=> Designated_Type
(Btyp
),
9974 if Attr_Id
= Attribute_Unchecked_Access
then
9975 Error_Msg_Name_1
:= Aname
;
9977 ("attribute% cannot be applied to a subprogram", P
);
9979 elsif Aname
= Name_Unrestricted_Access
then
9980 null; -- Nothing to check
9982 -- Check the static accessibility rule of 3.10.2(32).
9983 -- This rule also applies within the private part of an
9984 -- instantiation. This rule does not apply to anonymous
9985 -- access-to-subprogram types in access parameters.
9987 elsif Attr_Id
= Attribute_Access
9988 and then not In_Instance_Body
9990 (Ekind
(Btyp
) = E_Access_Subprogram_Type
9991 or else Is_Local_Anonymous_Access
(Btyp
))
9992 and then Subprogram_Access_Level
(Entity
(P
)) >
9993 Type_Access_Level
(Btyp
)
9996 ("subprogram must not be deeper than access type", P
);
9998 -- Check the restriction of 3.10.2(32) that disallows the
9999 -- access attribute within a generic body when the ultimate
10000 -- ancestor of the type of the attribute is declared outside
10001 -- of the generic unit and the subprogram is declared within
10002 -- that generic unit. This includes any such attribute that
10003 -- occurs within the body of a generic unit that is a child
10004 -- of the generic unit where the subprogram is declared.
10006 -- The rule also prohibits applying the attribute when the
10007 -- access type is a generic formal access type (since the
10008 -- level of the actual type is not known). This restriction
10009 -- does not apply when the attribute type is an anonymous
10010 -- access-to-subprogram type. Note that this check was
10011 -- revised by AI-229, because the originally Ada 95 rule
10012 -- was too lax. The original rule only applied when the
10013 -- subprogram was declared within the body of the generic,
10014 -- which allowed the possibility of dangling references).
10015 -- The rule was also too strict in some case, in that it
10016 -- didn't permit the access to be declared in the generic
10017 -- spec, whereas the revised rule does (as long as it's not
10020 -- There are a couple of subtleties of the test for applying
10021 -- the check that are worth noting. First, we only apply it
10022 -- when the levels of the subprogram and access type are the
10023 -- same (the case where the subprogram is statically deeper
10024 -- was applied above, and the case where the type is deeper
10025 -- is always safe). Second, we want the check to apply
10026 -- within nested generic bodies and generic child unit
10027 -- bodies, but not to apply to an attribute that appears in
10028 -- the generic unit's specification. This is done by testing
10029 -- that the attribute's innermost enclosing generic body is
10030 -- not the same as the innermost generic body enclosing the
10031 -- generic unit where the subprogram is declared (we don't
10032 -- want the check to apply when the access attribute is in
10033 -- the spec and there's some other generic body enclosing
10034 -- generic). Finally, there's no point applying the check
10035 -- when within an instance, because any violations will have
10036 -- been caught by the compilation of the generic unit.
10038 -- We relax this check in Relaxed_RM_Semantics mode for
10039 -- compatibility with legacy code for use by Ada source
10040 -- code analyzers (e.g. CodePeer).
10042 elsif Attr_Id
= Attribute_Access
10043 and then not Relaxed_RM_Semantics
10044 and then not In_Instance
10045 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
10046 and then Present
(Enclosing_Generic_Body
(N
))
10047 and then Enclosing_Generic_Body
(N
) /=
10048 Enclosing_Generic_Body
10049 (Enclosing_Generic_Unit
(Entity
(P
)))
10050 and then Subprogram_Access_Level
(Entity
(P
)) =
10051 Type_Access_Level
(Btyp
)
10052 and then Ekind
(Btyp
) /=
10053 E_Anonymous_Access_Subprogram_Type
10054 and then Ekind
(Btyp
) /=
10055 E_Anonymous_Access_Protected_Subprogram_Type
10057 -- The attribute type's ultimate ancestor must be
10058 -- declared within the same generic unit as the
10059 -- subprogram is declared. The error message is
10060 -- specialized to say "ancestor" for the case where the
10061 -- access type is not its own ancestor, since saying
10062 -- simply "access type" would be very confusing.
10064 if Enclosing_Generic_Unit
(Entity
(P
)) /=
10065 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
10068 ("''Access attribute not allowed in generic body",
10071 if Root_Type
(Btyp
) = Btyp
then
10074 "access type & is declared outside " &
10075 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10078 ("\because ancestor of " &
10079 "access type & is declared outside " &
10080 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10084 ("\move ''Access to private part, or " &
10085 "(Ada 2005) use anonymous access type instead of &",
10088 -- If the ultimate ancestor of the attribute's type is
10089 -- a formal type, then the attribute is illegal because
10090 -- the actual type might be declared at a higher level.
10091 -- The error message is specialized to say "ancestor"
10092 -- for the case where the access type is not its own
10093 -- ancestor, since saying simply "access type" would be
10096 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10097 if Root_Type
(Btyp
) = Btyp
then
10099 ("access type must not be a generic formal type",
10103 ("ancestor access type must not be a generic " &
10110 -- If this is a renaming, an inherited operation, or a
10111 -- subprogram instance, use the original entity. This may make
10112 -- the node type-inconsistent, so this transformation can only
10113 -- be done if the node will not be reanalyzed. In particular,
10114 -- if it is within a default expression, the transformation
10115 -- must be delayed until the default subprogram is created for
10116 -- it, when the enclosing subprogram is frozen.
10118 if Is_Entity_Name
(P
)
10119 and then Is_Overloadable
(Entity
(P
))
10120 and then Present
(Alias
(Entity
(P
)))
10121 and then Expander_Active
10124 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10127 elsif Nkind
(P
) = N_Selected_Component
10128 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10130 -- Protected operation. If operation is overloaded, must
10131 -- disambiguate. Prefix that denotes protected object itself
10132 -- is resolved with its own type.
10134 if Attr_Id
= Attribute_Unchecked_Access
then
10135 Error_Msg_Name_1
:= Aname
;
10137 ("attribute% cannot be applied to protected operation", P
);
10140 Resolve
(Prefix
(P
));
10141 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10143 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10144 -- statically illegal if F is an anonymous access to subprogram.
10146 elsif Nkind
(P
) = N_Explicit_Dereference
10147 and then Is_Entity_Name
(Prefix
(P
))
10148 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10149 E_Anonymous_Access_Subprogram_Type
10151 Error_Msg_N
("anonymous access to subprogram "
10152 & "has deeper accessibility than any master", P
);
10154 elsif Is_Overloaded
(P
) then
10156 -- Use the designated type of the context to disambiguate
10157 -- Note that this was not strictly conformant to Ada 95,
10158 -- but was the implementation adopted by most Ada 95 compilers.
10159 -- The use of the context type to resolve an Access attribute
10160 -- reference is now mandated in AI-235 for Ada 2005.
10163 Index
: Interp_Index
;
10167 Get_First_Interp
(P
, Index
, It
);
10168 while Present
(It
.Typ
) loop
10169 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10170 Resolve
(P
, It
.Typ
);
10174 Get_Next_Interp
(Index
, It
);
10181 -- X'Access is illegal if X denotes a constant and the access type
10182 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10183 -- does not apply to 'Unrestricted_Access. If the reference is a
10184 -- default-initialized aggregate component for a self-referential
10185 -- type the reference is legal.
10187 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10188 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10189 or else (Is_Record_Type
(Btyp
)
10191 Present
(Corresponding_Remote_Type
(Btyp
)))
10192 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10193 or else Ekind
(Btyp
)
10194 = E_Anonymous_Access_Protected_Subprogram_Type
10195 or else Is_Access_Constant
(Btyp
)
10196 or else Is_Variable
(P
)
10197 or else Attr_Id
= Attribute_Unrestricted_Access
)
10199 if Is_Entity_Name
(P
)
10200 and then Is_Type
(Entity
(P
))
10202 -- Legality of a self-reference through an access
10203 -- attribute has been verified in Analyze_Access_Attribute.
10207 elsif Comes_From_Source
(N
) then
10208 Error_Msg_F
("access-to-variable designates constant", P
);
10212 Des_Btyp
:= Designated_Type
(Btyp
);
10214 if Ada_Version
>= Ada_2005
10215 and then Is_Incomplete_Type
(Des_Btyp
)
10217 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10218 -- imported entity, and the non-limited view is visible, make
10219 -- use of it. If it is an incomplete subtype, use the base type
10222 if From_Limited_With
(Des_Btyp
)
10223 and then Present
(Non_Limited_View
(Des_Btyp
))
10225 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10227 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10228 Des_Btyp
:= Etype
(Des_Btyp
);
10232 if (Attr_Id
= Attribute_Access
10234 Attr_Id
= Attribute_Unchecked_Access
)
10235 and then (Ekind
(Btyp
) = E_General_Access_Type
10236 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10238 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10239 -- access types for stand-alone objects, record and array
10240 -- components, and return objects. For a component definition
10241 -- the level is the same of the enclosing composite type.
10243 if Ada_Version
>= Ada_2005
10244 and then (Is_Local_Anonymous_Access
(Btyp
)
10246 -- Handle cases where Btyp is the anonymous access
10247 -- type of an Ada 2012 stand-alone object.
10249 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10250 N_Object_Declaration
)
10252 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10253 and then Attr_Id
= Attribute_Access
10255 -- In an instance, this is a runtime check, but one we know
10256 -- will fail, so generate an appropriate warning. As usual,
10257 -- this kind of warning is an error in SPARK mode.
10259 if In_Instance_Body
then
10260 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10262 ("non-local pointer cannot point to local object<<", P
);
10263 Error_Msg_F
("\Program_Error [<<", P
);
10266 Make_Raise_Program_Error
(Loc
,
10267 Reason
=> PE_Accessibility_Check_Failed
));
10268 Set_Etype
(N
, Typ
);
10272 ("non-local pointer cannot point to local object", P
);
10276 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10278 ("illegal attribute for discriminant-dependent component",
10282 -- Check static matching rule of 3.10.2(27). Nominal subtype
10283 -- of the prefix must statically match the designated type.
10285 Nom_Subt
:= Etype
(P
);
10287 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10288 Nom_Subt
:= Base_Type
(Nom_Subt
);
10291 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10293 -- If the attribute is in the context of an access
10294 -- parameter, then the prefix is allowed to be of
10295 -- the class-wide type (by AI-127).
10297 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10298 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10299 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10305 Desig
:= Designated_Type
(Typ
);
10307 if Is_Class_Wide_Type
(Desig
) then
10308 Desig
:= Etype
(Desig
);
10311 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10316 ("type of prefix: & not compatible",
10319 ("\with &, the expected designated type",
10320 P
, Designated_Type
(Typ
));
10325 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10327 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10328 and then Is_Class_Wide_Type
(Nom_Subt
))
10331 ("type of prefix: & is not covered", P
, Nom_Subt
);
10333 ("\by &, the expected designated type" &
10334 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10337 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10338 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10339 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10340 and then Designated_Type
(Typ
) /= Nom_Subt
10342 Apply_Discriminant_Check
10343 (N
, Etype
(Designated_Type
(Typ
)));
10346 -- Ada 2005 (AI-363): Require static matching when designated
10347 -- type has discriminants and a constrained partial view, since
10348 -- in general objects of such types are mutable, so we can't
10349 -- allow the access value to designate a constrained object
10350 -- (because access values must be assumed to designate mutable
10351 -- objects when designated type does not impose a constraint).
10353 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10356 elsif Has_Discriminants
(Designated_Type
(Typ
))
10357 and then not Is_Constrained
(Des_Btyp
)
10359 (Ada_Version
< Ada_2005
10361 not Object_Type_Has_Constrained_Partial_View
10362 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10363 Scop
=> Current_Scope
))
10369 ("object subtype must statically match "
10370 & "designated subtype", P
);
10372 if Is_Entity_Name
(P
)
10373 and then Is_Array_Type
(Designated_Type
(Typ
))
10376 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10379 ("aliased object has explicit bounds??", D
);
10381 ("\declare without bounds (and with explicit "
10382 & "initialization)??", D
);
10384 ("\for use with unconstrained access??", D
);
10389 -- Check the static accessibility rule of 3.10.2(28). Note that
10390 -- this check is not performed for the case of an anonymous
10391 -- access type, since the access attribute is always legal
10392 -- in such a context.
10394 if Attr_Id
/= Attribute_Unchecked_Access
10395 and then Ekind
(Btyp
) = E_General_Access_Type
10397 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10399 Accessibility_Message
;
10404 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10405 E_Anonymous_Access_Protected_Subprogram_Type
)
10407 if Is_Entity_Name
(P
)
10408 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
10410 Error_Msg_F
("context requires a protected subprogram", P
);
10412 -- Check accessibility of protected object against that of the
10413 -- access type, but only on user code, because the expander
10414 -- creates access references for handlers. If the context is an
10415 -- anonymous_access_to_protected, there are no accessibility
10416 -- checks either. Omit check entirely for Unrestricted_Access.
10418 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10419 and then Comes_From_Source
(N
)
10420 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10421 and then Attr_Id
/= Attribute_Unrestricted_Access
10423 Accessibility_Message
;
10426 -- AI05-0225: If the context is not an access to protected
10427 -- function, the prefix must be a variable, given that it may
10428 -- be used subsequently in a protected call.
10430 elsif Nkind
(P
) = N_Selected_Component
10431 and then not Is_Variable
(Prefix
(P
))
10432 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
10435 ("target object of access to protected procedure "
10436 & "must be variable", N
);
10438 elsif Is_Entity_Name
(P
) then
10439 Check_Internal_Protected_Use
(N
, Entity
(P
));
10442 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10443 E_Anonymous_Access_Subprogram_Type
)
10444 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
10446 Error_Msg_F
("context requires a non-protected subprogram", P
);
10449 -- The context cannot be a pool-specific type, but this is a
10450 -- legality rule, not a resolution rule, so it must be checked
10451 -- separately, after possibly disambiguation (see AI-245).
10453 if Ekind
(Btyp
) = E_Access_Type
10454 and then Attr_Id
/= Attribute_Unrestricted_Access
10456 Wrong_Type
(N
, Typ
);
10459 -- The context may be a constrained access type (however ill-
10460 -- advised such subtypes might be) so in order to generate a
10461 -- constraint check when needed set the type of the attribute
10462 -- reference to the base type of the context.
10464 Set_Etype
(N
, Btyp
);
10466 -- Check for incorrect atomic/volatile reference (RM C.6(12))
10468 if Attr_Id
/= Attribute_Unrestricted_Access
then
10469 if Is_Atomic_Object
(P
)
10470 and then not Is_Atomic
(Designated_Type
(Typ
))
10473 ("access to atomic object cannot yield access-to-" &
10474 "non-atomic type", P
);
10476 elsif Is_Volatile_Object
(P
)
10477 and then not Is_Volatile
(Designated_Type
(Typ
))
10480 ("access to volatile object cannot yield access-to-" &
10481 "non-volatile type", P
);
10485 -- Check for unrestricted access where expected type is a thin
10486 -- pointer to an unconstrained array.
10488 if Non_Aliased_Prefix
(N
)
10489 and then Has_Size_Clause
(Typ
)
10490 and then RM_Size
(Typ
) = System_Address_Size
10493 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
10495 if Is_Array_Type
(DT
) and then not Is_Constrained
(DT
) then
10497 ("illegal use of Unrestricted_Access attribute", P
);
10499 ("\attempt to generate thin pointer to unaliased "
10505 -- Mark that address of entity is taken
10507 if Is_Entity_Name
(P
) then
10508 Set_Address_Taken
(Entity
(P
));
10511 -- Deal with possible elaboration check
10513 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
10515 Subp_Id
: constant Entity_Id
:= Entity
(P
);
10516 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
10517 Subp_Decl
: constant Node_Id
:=
10518 Unit_Declaration_Node
(Subp_Id
);
10520 Flag_Id
: Entity_Id
;
10524 -- If the access has been taken and the body of the subprogram
10525 -- has not been see yet, indirect calls must be protected with
10526 -- elaboration checks. We have the proper elaboration machinery
10527 -- for subprograms declared in packages, but within a block or
10528 -- a subprogram the body will appear in the same declarative
10529 -- part, and we must insert a check in the eventual body itself
10530 -- using the elaboration flag that we generate now. The check
10531 -- is then inserted when the body is expanded. This processing
10532 -- is not needed for a stand alone expression function because
10533 -- the internally generated spec and body are always inserted
10534 -- as a pair in the same declarative list.
10538 and then Comes_From_Source
(Subp_Id
)
10539 and then Comes_From_Source
(N
)
10540 and then In_Open_Scopes
(Scop
)
10541 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
10542 and then not Has_Completion
(Subp_Id
)
10543 and then No
(Elaboration_Entity
(Subp_Id
))
10544 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10545 and then Nkind
(Original_Node
(Subp_Decl
)) /=
10546 N_Expression_Function
10548 -- Create elaboration variable for it
10550 Flag_Id
:= Make_Temporary
(Loc
, 'E');
10551 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
10552 Set_Is_Frozen
(Flag_Id
);
10554 -- Insert declaration for flag after subprogram
10555 -- declaration. Note that attribute reference may
10556 -- appear within a nested scope.
10558 Insert_After_And_Analyze
(Subp_Decl
,
10559 Make_Object_Declaration
(Loc
,
10560 Defining_Identifier
=> Flag_Id
,
10561 Object_Definition
=>
10562 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
10564 Make_Integer_Literal
(Loc
, Uint_0
)));
10567 -- Taking the 'Access of an expression function freezes its
10568 -- expression (RM 13.14 10.3/3). This does not apply to an
10569 -- expression function that acts as a completion because the
10570 -- generated body is immediately analyzed and the expression
10571 -- is automatically frozen.
10573 if Ekind
(Subp_Id
) = E_Function
10574 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10575 and then Nkind
(Original_Node
(Subp_Decl
)) =
10576 N_Expression_Function
10577 and then Present
(Corresponding_Body
(Subp_Decl
))
10578 and then not Analyzed
(Corresponding_Body
(Subp_Decl
))
10581 Handled_Statement_Sequence
10582 (Unit_Declaration_Node
10583 (Corresponding_Body
(Subp_Decl
)));
10585 if Present
(HSS
) then
10586 Stmt
:= First
(Statements
(HSS
));
10588 if Nkind
(Stmt
) = N_Simple_Return_Statement
then
10589 Freeze_Expression
(Expression
(Stmt
));
10595 end Access_Attribute
;
10601 -- Deal with resolving the type for Address attribute, overloading
10602 -- is not permitted here, since there is no context to resolve it.
10604 when Attribute_Address | Attribute_Code_Address
=>
10605 Address_Attribute
: begin
10607 -- To be safe, assume that if the address of a variable is taken,
10608 -- it may be modified via this address, so note modification.
10610 if Is_Variable
(P
) then
10611 Note_Possible_Modification
(P
, Sure
=> False);
10614 if Nkind
(P
) in N_Subexpr
10615 and then Is_Overloaded
(P
)
10617 Get_First_Interp
(P
, Index
, It
);
10618 Get_Next_Interp
(Index
, It
);
10620 if Present
(It
.Nam
) then
10621 Error_Msg_Name_1
:= Aname
;
10623 ("prefix of % attribute cannot be overloaded", P
);
10627 if not Is_Entity_Name
(P
)
10628 or else not Is_Overloadable
(Entity
(P
))
10630 if not Is_Task_Type
(Etype
(P
))
10631 or else Nkind
(P
) = N_Explicit_Dereference
10637 -- If this is the name of a derived subprogram, or that of a
10638 -- generic actual, the address is that of the original entity.
10640 if Is_Entity_Name
(P
)
10641 and then Is_Overloadable
(Entity
(P
))
10642 and then Present
(Alias
(Entity
(P
)))
10645 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10648 if Is_Entity_Name
(P
) then
10649 Set_Address_Taken
(Entity
(P
));
10652 if Nkind
(P
) = N_Slice
then
10654 -- Arr (X .. Y)'address is identical to Arr (X)'address,
10655 -- even if the array is packed and the slice itself is not
10656 -- addressable. Transform the prefix into an indexed component.
10658 -- Note that the transformation is safe only if we know that
10659 -- the slice is non-null. That is because a null slice can have
10660 -- an out of bounds index value.
10662 -- Right now, gigi blows up if given 'Address on a slice as a
10663 -- result of some incorrect freeze nodes generated by the front
10664 -- end, and this covers up that bug in one case, but the bug is
10665 -- likely still there in the cases not handled by this code ???
10667 -- It's not clear what 'Address *should* return for a null
10668 -- slice with out of bounds indexes, this might be worth an ARG
10671 -- One approach would be to do a length check unconditionally,
10672 -- and then do the transformation below unconditionally, but
10673 -- analyze with checks off, avoiding the problem of the out of
10674 -- bounds index. This approach would interpret the address of
10675 -- an out of bounds null slice as being the address where the
10676 -- array element would be if there was one, which is probably
10677 -- as reasonable an interpretation as any ???
10680 Loc
: constant Source_Ptr
:= Sloc
(P
);
10681 D
: constant Node_Id
:= Discrete_Range
(P
);
10685 if Is_Entity_Name
(D
)
10688 (Type_Low_Bound
(Entity
(D
)),
10689 Type_High_Bound
(Entity
(D
)))
10692 Make_Attribute_Reference
(Loc
,
10693 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
10694 Attribute_Name
=> Name_First
);
10696 elsif Nkind
(D
) = N_Range
10697 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
10699 Lo
:= Low_Bound
(D
);
10705 if Present
(Lo
) then
10707 Make_Indexed_Component
(Loc
,
10708 Prefix
=> Relocate_Node
(Prefix
(P
)),
10709 Expressions
=> New_List
(Lo
)));
10711 Analyze_And_Resolve
(P
);
10715 end Address_Attribute
;
10721 -- Prefix of Body_Version attribute can be a subprogram name which
10722 -- must not be resolved, since this is not a call.
10724 when Attribute_Body_Version
=>
10731 -- Prefix of Caller attribute is an entry name which must not
10732 -- be resolved, since this is definitely not an entry call.
10734 when Attribute_Caller
=>
10741 -- Shares processing with Address attribute
10747 -- If the prefix of the Count attribute is an entry name it must not
10748 -- be resolved, since this is definitely not an entry call. However,
10749 -- if it is an element of an entry family, the index itself may
10750 -- have to be resolved because it can be a general expression.
10752 when Attribute_Count
=>
10753 if Nkind
(P
) = N_Indexed_Component
10754 and then Is_Entity_Name
(Prefix
(P
))
10757 Indx
: constant Node_Id
:= First
(Expressions
(P
));
10758 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
10760 Resolve
(Indx
, Entry_Index_Type
(Fam
));
10761 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
10769 -- Prefix of the Elaborated attribute is a subprogram name which
10770 -- must not be resolved, since this is definitely not a call. Note
10771 -- that it is a library unit, so it cannot be overloaded here.
10773 when Attribute_Elaborated
=>
10780 -- Prefix of Enabled attribute is a check name, which must be treated
10781 -- specially and not touched by Resolve.
10783 when Attribute_Enabled
=>
10790 -- Do not resolve the prefix of Loop_Entry, instead wait until the
10791 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
10792 -- The delay ensures that any generated checks or temporaries are
10793 -- inserted before the relocated prefix.
10795 when Attribute_Loop_Entry
=>
10798 --------------------
10799 -- Mechanism_Code --
10800 --------------------
10802 -- Prefix of the Mechanism_Code attribute is a function name
10803 -- which must not be resolved. Should we check for overloaded ???
10805 when Attribute_Mechanism_Code
=>
10812 -- Most processing is done in sem_dist, after determining the
10813 -- context type. Node is rewritten as a conversion to a runtime call.
10815 when Attribute_Partition_ID
=>
10816 Process_Partition_Id
(N
);
10823 when Attribute_Pool_Address
=>
10830 -- We replace the Range attribute node with a range expression whose
10831 -- bounds are the 'First and 'Last attributes applied to the same
10832 -- prefix. The reason that we do this transformation here instead of
10833 -- in the expander is that it simplifies other parts of the semantic
10834 -- analysis which assume that the Range has been replaced; thus it
10835 -- must be done even when in semantic-only mode (note that the RM
10836 -- specifically mentions this equivalence, we take care that the
10837 -- prefix is only evaluated once).
10839 when Attribute_Range
=> Range_Attribute
:
10846 if not Is_Entity_Name
(P
)
10847 or else not Is_Type
(Entity
(P
))
10852 Dims
:= Expressions
(N
);
10855 Make_Attribute_Reference
(Loc
,
10856 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
10857 Attribute_Name
=> Name_Last
,
10858 Expressions
=> Dims
);
10861 Make_Attribute_Reference
(Loc
,
10863 Attribute_Name
=> Name_First
,
10864 Expressions
=> (Dims
));
10866 -- Do not share the dimension indicator, if present. Even
10867 -- though it is a static constant, its source location
10868 -- may be modified when printing expanded code and node
10869 -- sharing will lead to chaos in Sprint.
10871 if Present
(Dims
) then
10872 Set_Expressions
(LB
,
10873 New_List
(New_Copy_Tree
(First
(Dims
))));
10876 -- If the original was marked as Must_Not_Freeze (see code
10877 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10878 -- does not freeze either.
10880 if Must_Not_Freeze
(N
) then
10881 Set_Must_Not_Freeze
(HB
);
10882 Set_Must_Not_Freeze
(LB
);
10883 Set_Must_Not_Freeze
(Prefix
(HB
));
10884 Set_Must_Not_Freeze
(Prefix
(LB
));
10887 if Raises_Constraint_Error
(Prefix
(N
)) then
10889 -- Preserve Sloc of prefix in the new bounds, so that
10890 -- the posted warning can be removed if we are within
10891 -- unreachable code.
10893 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
10894 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
10897 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
10898 Analyze_And_Resolve
(N
, Typ
);
10900 -- Ensure that the expanded range does not have side effects
10902 Force_Evaluation
(LB
);
10903 Force_Evaluation
(HB
);
10905 -- Normally after resolving attribute nodes, Eval_Attribute
10906 -- is called to do any possible static evaluation of the node.
10907 -- However, here since the Range attribute has just been
10908 -- transformed into a range expression it is no longer an
10909 -- attribute node and therefore the call needs to be avoided
10910 -- and is accomplished by simply returning from the procedure.
10913 end Range_Attribute
;
10919 -- We will only come here during the prescan of a spec expression
10920 -- containing a Result attribute. In that case the proper Etype has
10921 -- already been set, and nothing more needs to be done here.
10923 when Attribute_Result
=>
10930 -- Prefix must not be resolved in this case, since it is not a
10931 -- real entity reference. No action of any kind is require.
10933 when Attribute_UET_Address
=>
10936 ----------------------
10937 -- Unchecked_Access --
10938 ----------------------
10940 -- Processing is shared with Access
10942 -------------------------
10943 -- Unrestricted_Access --
10944 -------------------------
10946 -- Processing is shared with Access
10952 -- Resolve aggregate components in component associations
10954 when Attribute_Update
=>
10956 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
10957 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
10963 -- Set the Etype of the aggregate to that of the prefix, even
10964 -- though the aggregate may not be a proper representation of a
10965 -- value of the type (missing or duplicated associations, etc.)
10966 -- Complete resolution of the prefix. Note that in Ada 2012 it
10967 -- can be a qualified expression that is e.g. an aggregate.
10969 Set_Etype
(Aggr
, Typ
);
10970 Resolve
(Prefix
(N
), Typ
);
10972 -- For an array type, resolve expressions with the component
10973 -- type of the array, and apply constraint checks when needed.
10975 if Is_Array_Type
(Typ
) then
10976 Assoc
:= First
(Component_Associations
(Aggr
));
10977 while Present
(Assoc
) loop
10978 Expr
:= Expression
(Assoc
);
10979 Resolve
(Expr
, Component_Type
(Typ
));
10981 -- For scalar array components set Do_Range_Check when
10982 -- needed. Constraint checking on non-scalar components
10983 -- is done in Aggregate_Constraint_Checks, but only if
10984 -- full analysis is enabled. These flags are not set in
10985 -- the front-end in GnatProve mode.
10987 if Is_Scalar_Type
(Component_Type
(Typ
))
10988 and then not Is_OK_Static_Expression
(Expr
)
10990 if Is_Entity_Name
(Expr
)
10991 and then Etype
(Expr
) = Component_Type
(Typ
)
10996 Set_Do_Range_Check
(Expr
);
11000 -- The choices in the association are static constants,
11001 -- or static aggregates each of whose components belongs
11002 -- to the proper index type. However, they must also
11003 -- belong to the index subtype (s) of the prefix, which
11004 -- may be a subtype (e.g. given by a slice).
11006 -- Choices may also be identifiers with no staticness
11007 -- requirements, in which case they must resolve to the
11016 C
:= First
(Choices
(Assoc
));
11017 while Present
(C
) loop
11018 Indx
:= First_Index
(Etype
(Prefix
(N
)));
11020 if Nkind
(C
) /= N_Aggregate
then
11021 Analyze_And_Resolve
(C
, Etype
(Indx
));
11022 Apply_Constraint_Check
(C
, Etype
(Indx
));
11023 Check_Non_Static_Context
(C
);
11026 C_E
:= First
(Expressions
(C
));
11027 while Present
(C_E
) loop
11028 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
11029 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
11030 Check_Non_Static_Context
(C_E
);
11044 -- For a record type, use type of each component, which is
11045 -- recorded during analysis.
11048 Assoc
:= First
(Component_Associations
(Aggr
));
11049 while Present
(Assoc
) loop
11050 Comp
:= First
(Choices
(Assoc
));
11051 Expr
:= Expression
(Assoc
);
11053 if Nkind
(Comp
) /= N_Others_Choice
11054 and then not Error_Posted
(Comp
)
11056 Resolve
(Expr
, Etype
(Entity
(Comp
)));
11058 if Is_Scalar_Type
(Etype
(Entity
(Comp
)))
11059 and then not Is_OK_Static_Expression
(Expr
)
11061 Set_Do_Range_Check
(Expr
);
11074 -- Apply range check. Note that we did not do this during the
11075 -- analysis phase, since we wanted Eval_Attribute to have a
11076 -- chance at finding an illegal out of range value.
11078 when Attribute_Val
=>
11080 -- Note that we do our own Eval_Attribute call here rather than
11081 -- use the common one, because we need to do processing after
11082 -- the call, as per above comment.
11084 Eval_Attribute
(N
);
11086 -- Eval_Attribute may replace the node with a raise CE, or
11087 -- fold it to a constant. Obviously we only apply a scalar
11088 -- range check if this did not happen.
11090 if Nkind
(N
) = N_Attribute_Reference
11091 and then Attribute_Name
(N
) = Name_Val
11093 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11102 -- Prefix of Version attribute can be a subprogram name which
11103 -- must not be resolved, since this is not a call.
11105 when Attribute_Version
=>
11108 ----------------------
11109 -- Other Attributes --
11110 ----------------------
11112 -- For other attributes, resolve prefix unless it is a type. If
11113 -- the attribute reference itself is a type name ('Base and 'Class)
11114 -- then this is only legal within a task or protected record.
11117 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11121 -- If the attribute reference itself is a type name ('Base,
11122 -- 'Class) then this is only legal within a task or protected
11123 -- record. What is this all about ???
11125 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11126 if Is_Concurrent_Type
(Entity
(N
))
11127 and then In_Open_Scopes
(Entity
(P
))
11132 ("invalid use of subtype name in expression or call", N
);
11136 -- For attributes whose argument may be a string, complete
11137 -- resolution of argument now. This avoids premature expansion
11138 -- (and the creation of transient scopes) before the attribute
11139 -- reference is resolved.
11142 when Attribute_Value
=>
11143 Resolve
(First
(Expressions
(N
)), Standard_String
);
11145 when Attribute_Wide_Value
=>
11146 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11148 when Attribute_Wide_Wide_Value
=>
11149 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11151 when others => null;
11154 -- If the prefix of the attribute is a class-wide type then it
11155 -- will be expanded into a dispatching call to a predefined
11156 -- primitive. Therefore we must check for potential violation
11157 -- of such restriction.
11159 if Is_Class_Wide_Type
(Etype
(P
)) then
11160 Check_Restriction
(No_Dispatching_Calls
, N
);
11164 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11165 -- is not resolved, in which case the freezing must be done now.
11167 Freeze_Expression
(P
);
11169 -- Finally perform static evaluation on the attribute reference
11171 Analyze_Dimension
(N
);
11172 Eval_Attribute
(N
);
11173 end Resolve_Attribute
;
11175 ------------------------
11176 -- Set_Boolean_Result --
11177 ------------------------
11179 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11180 Loc
: constant Source_Ptr
:= Sloc
(N
);
11183 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11185 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11187 end Set_Boolean_Result
;
11189 --------------------------------
11190 -- Stream_Attribute_Available --
11191 --------------------------------
11193 function Stream_Attribute_Available
11195 Nam
: TSS_Name_Type
;
11196 Partial_View
: Node_Id
:= Empty
) return Boolean
11198 Etyp
: Entity_Id
:= Typ
;
11200 -- Start of processing for Stream_Attribute_Available
11203 -- We need some comments in this body ???
11205 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11209 if Is_Class_Wide_Type
(Typ
) then
11210 return not Is_Limited_Type
(Typ
)
11211 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11214 if Nam
= TSS_Stream_Input
11215 and then Is_Abstract_Type
(Typ
)
11216 and then not Is_Class_Wide_Type
(Typ
)
11221 if not (Is_Limited_Type
(Typ
)
11222 or else (Present
(Partial_View
)
11223 and then Is_Limited_Type
(Partial_View
)))
11228 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11230 if Nam
= TSS_Stream_Input
11231 and then Ada_Version
>= Ada_2005
11232 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11236 elsif Nam
= TSS_Stream_Output
11237 and then Ada_Version
>= Ada_2005
11238 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11243 -- Case of Read and Write: check for attribute definition clause that
11244 -- applies to an ancestor type.
11246 while Etype
(Etyp
) /= Etyp
loop
11247 Etyp
:= Etype
(Etyp
);
11249 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11254 if Ada_Version
< Ada_2005
then
11256 -- In Ada 95 mode, also consider a non-visible definition
11259 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11262 and then Stream_Attribute_Available
11263 (Btyp
, Nam
, Partial_View
=> Typ
);
11268 end Stream_Attribute_Available
;