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
;
68 with Stringt
; use Stringt
;
70 with Stylesw
; use Stylesw
;
71 with Targparm
; use Targparm
;
72 with Ttypes
; use Ttypes
;
73 with Tbuild
; use Tbuild
;
74 with Uintp
; use Uintp
;
75 with Uname
; use Uname
;
76 with Urealp
; use Urealp
;
78 package body Sem_Attr
is
80 True_Value
: constant Uint
:= Uint_1
;
81 False_Value
: constant Uint
:= Uint_0
;
82 -- Synonyms to be used when these constants are used as Boolean values
84 Bad_Attribute
: exception;
85 -- Exception raised if an error is detected during attribute processing,
86 -- used so that we can abandon the processing so we don't run into
87 -- trouble with cascaded errors.
89 -- The following array is the list of attributes defined in the Ada 83 RM.
90 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
91 -- modes all these attributes are recognized, even if removed in Ada 95.
93 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
99 Attribute_Constrained |
106 Attribute_First_Bit |
112 Attribute_Leading_Part |
114 Attribute_Machine_Emax |
115 Attribute_Machine_Emin |
116 Attribute_Machine_Mantissa |
117 Attribute_Machine_Overflows |
118 Attribute_Machine_Radix |
119 Attribute_Machine_Rounds |
125 Attribute_Safe_Emax |
126 Attribute_Safe_Large |
127 Attribute_Safe_Small |
130 Attribute_Storage_Size |
132 Attribute_Terminated |
135 Attribute_Width => True,
138 -- The following array is the list of attributes defined in the Ada 2005
139 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
140 -- but in Ada 95 they are considered to be implementation defined.
142 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
143 Attribute_Machine_Rounding |
146 Attribute_Stream_Size |
147 Attribute_Wide_Wide_Width
=> True,
150 -- The following array is the list of attributes defined in the Ada 2012
151 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
152 -- and Ada 2005 modes, but are considered to be implementation defined.
154 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
155 Attribute_First_Valid |
156 Attribute_Has_Same_Storage |
157 Attribute_Last_Valid |
158 Attribute_Max_Alignment_For_Allocation => True,
161 -- The following array contains all attributes that imply a modification
162 -- of their prefixes or result in an access value. Such prefixes can be
163 -- considered as lvalues.
165 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
166 Attribute_Class_Array'(
171 Attribute_Unchecked_Access |
172 Attribute_Unrestricted_Access
=> True,
175 -----------------------
176 -- Local_Subprograms --
177 -----------------------
179 procedure Eval_Attribute
(N
: Node_Id
);
180 -- Performs compile time evaluation of attributes where possible, leaving
181 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
182 -- set, and replacing the node with a literal node if the value can be
183 -- computed at compile time. All static attribute references are folded,
184 -- as well as a number of cases of non-static attributes that can always
185 -- be computed at compile time (e.g. floating-point model attributes that
186 -- are applied to non-static subtypes). Of course in such cases, the
187 -- Is_Static_Expression flag will not be set on the resulting literal.
188 -- Note that the only required action of this procedure is to catch the
189 -- static expression cases as described in the RM. Folding of other cases
190 -- is done where convenient, but some additional non-static folding is in
191 -- Expand_N_Attribute_Reference in cases where this is more convenient.
193 function Is_Anonymous_Tagged_Base
195 Typ
: Entity_Id
) return Boolean;
196 -- For derived tagged types that constrain parent discriminants we build
197 -- an anonymous unconstrained base type. We need to recognize the relation
198 -- between the two when analyzing an access attribute for a constrained
199 -- component, before the full declaration for Typ has been analyzed, and
200 -- where therefore the prefix of the attribute does not match the enclosing
203 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean);
204 -- Rewrites node N with an occurrence of either Standard_False or
205 -- Standard_True, depending on the value of the parameter B. The
206 -- result is marked as a static expression.
208 -----------------------
209 -- Analyze_Attribute --
210 -----------------------
212 procedure Analyze_Attribute
(N
: Node_Id
) is
213 Loc
: constant Source_Ptr
:= Sloc
(N
);
214 Aname
: constant Name_Id
:= Attribute_Name
(N
);
215 P
: constant Node_Id
:= Prefix
(N
);
216 Exprs
: constant List_Id
:= Expressions
(N
);
217 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
222 -- Type of prefix after analysis
224 P_Base_Type
: Entity_Id
;
225 -- Base type of prefix after analysis
227 -----------------------
228 -- Local Subprograms --
229 -----------------------
231 procedure Address_Checks
;
232 -- Semantic checks for valid use of Address attribute. This was made
233 -- a separate routine with the idea of using it for unrestricted access
234 -- which seems like it should follow the same rules, but that turned
235 -- out to be impractical. So now this is only used for Address.
237 procedure Analyze_Access_Attribute
;
238 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
239 -- Internally, Id distinguishes which of the three cases is involved.
241 procedure Bad_Attribute_For_Predicate
;
242 -- Output error message for use of a predicate (First, Last, Range) not
243 -- allowed with a type that has predicates. If the type is a generic
244 -- actual, then the message is a warning, and we generate code to raise
245 -- program error with an appropriate reason. No error message is given
246 -- for internally generated uses of the attributes. This legality rule
247 -- only applies to scalar types.
249 procedure Check_Array_Or_Scalar_Type
;
250 -- Common procedure used by First, Last, Range attribute to check
251 -- that the prefix is a constrained array or scalar type, or a name
252 -- of an array object, and that an argument appears only if appropriate
253 -- (i.e. only in the array case).
255 procedure Check_Array_Type
;
256 -- Common semantic checks for all array attributes. Checks that the
257 -- prefix is a constrained array type or the name of an array object.
258 -- The error message for non-arrays is specialized appropriately.
260 procedure Check_Asm_Attribute
;
261 -- Common semantic checks for Asm_Input and Asm_Output attributes
263 procedure Check_Component
;
264 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
265 -- Position. Checks prefix is an appropriate selected component.
267 procedure Check_Decimal_Fixed_Point_Type
;
268 -- Check that prefix of attribute N is a decimal fixed-point type
270 procedure Check_Dereference
;
271 -- If the prefix of attribute is an object of an access type, then
272 -- introduce an explicit dereference, and adjust P_Type accordingly.
274 procedure Check_Discrete_Type
;
275 -- Verify that prefix of attribute N is a discrete type
278 -- Check that no attribute arguments are present
280 procedure Check_Either_E0_Or_E1
;
281 -- Check that there are zero or one attribute arguments present
284 -- Check that exactly one attribute argument is present
287 -- Check that two attribute arguments are present
289 procedure Check_Enum_Image
;
290 -- If the prefix type is an enumeration type, set all its literals
291 -- as referenced, since the image function could possibly end up
292 -- referencing any of the literals indirectly. Same for Enum_Val.
293 -- Set the flag only if the reference is in the main code unit. Same
294 -- restriction when resolving 'Value; otherwise an improperly set
295 -- reference when analyzing an inlined body will lose a proper warning
296 -- on a useless with_clause.
298 procedure Check_First_Last_Valid
;
299 -- Perform all checks for First_Valid and Last_Valid attributes
301 procedure Check_Fixed_Point_Type
;
302 -- Verify that prefix of attribute N is a fixed type
304 procedure Check_Fixed_Point_Type_0
;
305 -- Verify that prefix of attribute N is a fixed type and that
306 -- no attribute expressions are present
308 procedure Check_Floating_Point_Type
;
309 -- Verify that prefix of attribute N is a float type
311 procedure Check_Floating_Point_Type_0
;
312 -- Verify that prefix of attribute N is a float type and that
313 -- no attribute expressions are present
315 procedure Check_Floating_Point_Type_1
;
316 -- Verify that prefix of attribute N is a float type and that
317 -- exactly one attribute expression is present
319 procedure Check_Floating_Point_Type_2
;
320 -- Verify that prefix of attribute N is a float type and that
321 -- two attribute expressions are present
323 procedure Check_SPARK_05_Restriction_On_Attribute
;
324 -- Issue an error in formal mode because attribute N is allowed
326 procedure Check_Integer_Type
;
327 -- Verify that prefix of attribute N is an integer type
329 procedure Check_Modular_Integer_Type
;
330 -- Verify that prefix of attribute N is a modular integer type
332 procedure Check_Not_CPP_Type
;
333 -- Check that P (the prefix of the attribute) is not an CPP type
334 -- for which no Ada predefined primitive is available.
336 procedure Check_Not_Incomplete_Type
;
337 -- Check that P (the prefix of the attribute) is not an incomplete
338 -- type or a private type for which no full view has been given.
340 procedure Check_Object_Reference
(P
: Node_Id
);
341 -- Check that P is an object reference
343 procedure Check_Program_Unit
;
344 -- Verify that prefix of attribute N is a program unit
346 procedure Check_Real_Type
;
347 -- Verify that prefix of attribute N is fixed or float type
349 procedure Check_Scalar_Type
;
350 -- Verify that prefix of attribute N is a scalar type
352 procedure Check_Standard_Prefix
;
353 -- Verify that prefix of attribute N is package Standard. Also checks
354 -- that there are no arguments.
356 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
357 -- Validity checking for stream attribute. Nam is the TSS name of the
358 -- corresponding possible defined attribute function (e.g. for the
359 -- Read attribute, Nam will be TSS_Stream_Read).
361 procedure Check_System_Prefix
;
362 -- Verify that prefix of attribute N is package System
364 procedure Check_PolyORB_Attribute
;
365 -- Validity checking for PolyORB/DSA attribute
367 procedure Check_Task_Prefix
;
368 -- Verify that prefix of attribute N is a task or task type
370 procedure Check_Type
;
371 -- Verify that the prefix of attribute N is a type
373 procedure Check_Unit_Name
(Nod
: Node_Id
);
374 -- Check that Nod is of the form of a library unit name, i.e that
375 -- it is an identifier, or a selected component whose prefix is
376 -- itself of the form of a library unit name. Note that this is
377 -- quite different from Check_Program_Unit, since it only checks
378 -- the syntactic form of the name, not the semantic identity. This
379 -- is because it is used with attributes (Elab_Body, Elab_Spec,
380 -- UET_Address and Elaborated) which can refer to non-visible unit.
382 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
383 pragma No_Return
(Error_Attr
);
384 procedure Error_Attr
;
385 pragma No_Return
(Error_Attr
);
386 -- Posts error using Error_Msg_N at given node, sets type of attribute
387 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
388 -- semantic processing. The message typically contains a % insertion
389 -- character which is replaced by the attribute name. The call with
390 -- no arguments is used when the caller has already generated the
391 -- required error messages.
393 procedure Error_Attr_P
(Msg
: String);
394 pragma No_Return
(Error_Attr
);
395 -- Like Error_Attr, but error is posted at the start of the prefix
397 function In_Refined_Post
return Boolean;
398 -- Determine whether the current attribute appears in pragma
401 procedure Legal_Formal_Attribute
;
402 -- Common processing for attributes Definite and Has_Discriminants.
403 -- Checks that prefix is generic indefinite formal type.
405 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
406 -- Common processing for attributes Max_Alignment_For_Allocation and
407 -- Max_Size_In_Storage_Elements.
410 -- Common processing for attributes Max and Min
412 procedure Standard_Attribute
(Val
: Int
);
413 -- Used to process attributes whose prefix is package Standard which
414 -- yield values of type Universal_Integer. The attribute reference
415 -- node is rewritten with an integer literal of the given value which
416 -- is marked as static.
418 procedure Uneval_Old_Msg
;
419 -- Called when Loop_Entry or Old is used in a potentially unevaluated
420 -- expression. Generates appropriate message or warning depending on
421 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
422 -- node in the aspect case).
424 procedure Unexpected_Argument
(En
: Node_Id
);
425 -- Signal unexpected attribute argument (En is the argument)
427 procedure Validate_Non_Static_Attribute_Function_Call
;
428 -- Called when processing an attribute that is a function call to a
429 -- non-static function, i.e. an attribute function that either takes
430 -- non-scalar arguments or returns a non-scalar result. Verifies that
431 -- such a call does not appear in a preelaborable context.
437 procedure Address_Checks
is
439 -- An Address attribute created by expansion is legal even when it
440 -- applies to other entity-denoting expressions.
442 if not Comes_From_Source
(N
) then
445 -- Address attribute on a protected object self reference is legal
447 elsif Is_Protected_Self_Reference
(P
) then
450 -- Address applied to an entity
452 elsif Is_Entity_Name
(P
) then
454 Ent
: constant Entity_Id
:= Entity
(P
);
457 if Is_Subprogram
(Ent
) then
458 Set_Address_Taken
(Ent
);
459 Kill_Current_Values
(Ent
);
461 -- An Address attribute is accepted when generated by the
462 -- compiler for dispatching operation, and an error is
463 -- issued once the subprogram is frozen (to avoid confusing
464 -- errors about implicit uses of Address in the dispatch
465 -- table initialization).
467 if Has_Pragma_Inline_Always
(Entity
(P
))
468 and then Comes_From_Source
(P
)
471 ("prefix of % attribute cannot be Inline_Always "
474 -- It is illegal to apply 'Address to an intrinsic
475 -- subprogram. This is now formalized in AI05-0095.
476 -- In an instance, an attempt to obtain 'Address of an
477 -- intrinsic subprogram (e.g the renaming of a predefined
478 -- operator that is an actual) raises Program_Error.
480 elsif Convention
(Ent
) = Convention_Intrinsic
then
483 Make_Raise_Program_Error
(Loc
,
484 Reason
=> PE_Address_Of_Intrinsic
));
487 Error_Msg_Name_1
:= Aname
;
489 ("cannot take % of intrinsic subprogram", N
);
492 -- Issue an error if prefix denotes an eliminated subprogram
495 Check_For_Eliminated_Subprogram
(P
, Ent
);
498 -- Object or label reference
500 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
501 Set_Address_Taken
(Ent
);
503 -- Deal with No_Implicit_Aliasing restriction
505 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
506 if not Is_Aliased_View
(P
) then
507 Check_Restriction
(No_Implicit_Aliasing
, P
);
509 Check_No_Implicit_Aliasing
(P
);
513 -- If we have an address of an object, and the attribute
514 -- comes from source, then set the object as potentially
515 -- source modified. We do this because the resulting address
516 -- can potentially be used to modify the variable and we
517 -- might not detect this, leading to some junk warnings.
519 Set_Never_Set_In_Source
(Ent
, False);
521 -- Allow Address to be applied to task or protected type,
522 -- returning null address (what is that about???)
524 elsif (Is_Concurrent_Type
(Etype
(Ent
))
525 and then Etype
(Ent
) = Base_Type
(Ent
))
526 or else Ekind
(Ent
) = E_Package
527 or else Is_Generic_Unit
(Ent
)
530 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
532 -- Anything else is illegal
535 Error_Attr
("invalid prefix for % attribute", P
);
541 elsif Is_Object_Reference
(P
) then
544 -- Subprogram called using dot notation
546 elsif Nkind
(P
) = N_Selected_Component
547 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
551 -- What exactly are we allowing here ??? and is this properly
552 -- documented in the sinfo documentation for this node ???
554 elsif Relaxed_RM_Semantics
555 and then Nkind
(P
) = N_Attribute_Reference
559 -- All other non-entity name cases are illegal
562 Error_Attr
("invalid prefix for % attribute", P
);
566 ------------------------------
567 -- Analyze_Access_Attribute --
568 ------------------------------
570 procedure Analyze_Access_Attribute
is
571 Acc_Type
: Entity_Id
;
576 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
577 -- Build an access-to-object type whose designated type is DT,
578 -- and whose Ekind is appropriate to the attribute type. The
579 -- type that is constructed is returned as the result.
581 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
582 -- Build an access to subprogram whose designated type is the type of
583 -- the prefix. If prefix is overloaded, so is the node itself. The
584 -- result is stored in Acc_Type.
586 function OK_Self_Reference
return Boolean;
587 -- An access reference whose prefix is a type can legally appear
588 -- within an aggregate, where it is obtained by expansion of
589 -- a defaulted aggregate. The enclosing aggregate that contains
590 -- the self-referenced is flagged so that the self-reference can
591 -- be expanded into a reference to the target object (see exp_aggr).
593 ------------------------------
594 -- Build_Access_Object_Type --
595 ------------------------------
597 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
598 Typ
: constant Entity_Id
:=
600 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
602 Set_Etype
(Typ
, Typ
);
604 Set_Associated_Node_For_Itype
(Typ
, N
);
605 Set_Directly_Designated_Type
(Typ
, DT
);
607 end Build_Access_Object_Type
;
609 ----------------------------------
610 -- Build_Access_Subprogram_Type --
611 ----------------------------------
613 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
614 Index
: Interp_Index
;
617 procedure Check_Local_Access
(E
: Entity_Id
);
618 -- Deal with possible access to local subprogram. If we have such
619 -- an access, we set a flag to kill all tracked values on any call
620 -- because this access value may be passed around, and any called
621 -- code might use it to access a local procedure which clobbers a
622 -- tracked value. If the scope is a loop or block, indicate that
623 -- value tracking is disabled for the enclosing subprogram.
625 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
626 -- Distinguish between access to regular/protected subprograms
628 ------------------------
629 -- Check_Local_Access --
630 ------------------------
632 procedure Check_Local_Access
(E
: Entity_Id
) is
634 if not Is_Library_Level_Entity
(E
) then
635 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
636 Set_Suppress_Value_Tracking_On_Call
637 (Nearest_Dynamic_Scope
(Current_Scope
));
639 end Check_Local_Access
;
645 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
647 if Convention
(E
) = Convention_Protected
then
648 return E_Access_Protected_Subprogram_Type
;
650 return E_Access_Subprogram_Type
;
654 -- Start of processing for Build_Access_Subprogram_Type
657 -- In the case of an access to subprogram, use the name of the
658 -- subprogram itself as the designated type. Type-checking in
659 -- this case compares the signatures of the designated types.
661 -- Note: This fragment of the tree is temporarily malformed
662 -- because the correct tree requires an E_Subprogram_Type entity
663 -- as the designated type. In most cases this designated type is
664 -- later overridden by the semantics with the type imposed by the
665 -- context during the resolution phase. In the specific case of
666 -- the expression Address!(Prim'Unrestricted_Access), used to
667 -- initialize slots of dispatch tables, this work will be done by
668 -- the expander (see Exp_Aggr).
670 -- The reason to temporarily add this kind of node to the tree
671 -- instead of a proper E_Subprogram_Type itype, is the following:
672 -- in case of errors found in the source file we report better
673 -- error messages. For example, instead of generating the
676 -- "expected access to subprogram with profile
677 -- defined at line X"
679 -- we currently generate:
681 -- "expected access to function Z defined at line X"
683 Set_Etype
(N
, Any_Type
);
685 if not Is_Overloaded
(P
) then
686 Check_Local_Access
(Entity
(P
));
688 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
689 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
690 Set_Is_Public
(Acc_Type
, False);
691 Set_Etype
(Acc_Type
, Acc_Type
);
692 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
693 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
694 Set_Etype
(N
, Acc_Type
);
695 Freeze_Before
(N
, Acc_Type
);
699 Get_First_Interp
(P
, Index
, It
);
700 while Present
(It
.Nam
) loop
701 Check_Local_Access
(It
.Nam
);
703 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
704 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
705 Set_Is_Public
(Acc_Type
, False);
706 Set_Etype
(Acc_Type
, Acc_Type
);
707 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
708 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
709 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
710 Freeze_Before
(N
, Acc_Type
);
713 Get_Next_Interp
(Index
, It
);
717 -- Cannot be applied to intrinsic. Looking at the tests above,
718 -- the only way Etype (N) can still be set to Any_Type is if
719 -- Is_Intrinsic_Subprogram was True for some referenced entity.
721 if Etype
(N
) = Any_Type
then
722 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
724 end Build_Access_Subprogram_Type
;
726 ----------------------
727 -- OK_Self_Reference --
728 ----------------------
730 function OK_Self_Reference
return Boolean is
737 (Nkind
(Par
) = N_Component_Association
738 or else Nkind
(Par
) in N_Subexpr
)
740 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
741 if Etype
(Par
) = Typ
then
742 Set_Has_Self_Reference
(Par
);
750 -- No enclosing aggregate, or not a self-reference
753 end OK_Self_Reference
;
755 -- Start of processing for Analyze_Access_Attribute
758 Check_SPARK_05_Restriction_On_Attribute
;
761 if Nkind
(P
) = N_Character_Literal
then
763 ("prefix of % attribute cannot be enumeration literal");
766 -- Case of access to subprogram
768 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
769 if Has_Pragma_Inline_Always
(Entity
(P
)) then
771 ("prefix of % attribute cannot be Inline_Always subprogram");
773 elsif Aname
= Name_Unchecked_Access
then
774 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
776 elsif Is_Ghost_Subprogram
(Entity
(P
)) then
778 ("prefix of % attribute cannot be a ghost subprogram");
781 -- Issue an error if the prefix denotes an eliminated subprogram
783 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
785 -- Check for obsolescent subprogram reference
787 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
789 -- Build the appropriate subprogram type
791 Build_Access_Subprogram_Type
(P
);
793 -- For P'Access or P'Unrestricted_Access, where P is a nested
794 -- subprogram, we might be passing P to another subprogram (but we
795 -- don't check that here), which might call P. P could modify
796 -- local variables, so we need to kill current values. It is
797 -- important not to do this for library-level subprograms, because
798 -- Kill_Current_Values is very inefficient in the case of library
799 -- level packages with lots of tagged types.
801 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
804 -- Do not kill values on nodes initializing dispatch tables
805 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
806 -- is currently generated by the expander only for this
807 -- purpose. Done to keep the quality of warnings currently
808 -- generated by the compiler (otherwise any declaration of
809 -- a tagged type cleans constant indications from its scope).
811 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
812 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
814 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
815 and then Is_Dispatching_Operation
816 (Directly_Designated_Type
(Etype
(N
)))
824 -- In the static elaboration model, treat the attribute reference
825 -- as a call for elaboration purposes. Suppress this treatment
826 -- under debug flag. In any case, we are all done.
828 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
834 -- Component is an operation of a protected type
836 elsif Nkind
(P
) = N_Selected_Component
837 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
839 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
840 Error_Attr_P
("prefix of % attribute must be subprogram");
843 Build_Access_Subprogram_Type
(Selector_Name
(P
));
847 -- Deal with incorrect reference to a type, but note that some
848 -- accesses are allowed: references to the current type instance,
849 -- or in Ada 2005 self-referential pointer in a default-initialized
852 if Is_Entity_Name
(P
) then
855 -- The reference may appear in an aggregate that has been expanded
856 -- into a loop. Locate scope of type definition, if any.
858 Scop
:= Current_Scope
;
859 while Ekind
(Scop
) = E_Loop
loop
860 Scop
:= Scope
(Scop
);
863 if Is_Type
(Typ
) then
865 -- OK if we are within the scope of a limited type
866 -- let's mark the component as having per object constraint
868 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
876 Q
: Node_Id
:= Parent
(N
);
880 and then Nkind
(Q
) /= N_Component_Declaration
886 Set_Has_Per_Object_Constraint
887 (Defining_Identifier
(Q
), True);
891 if Nkind
(P
) = N_Expanded_Name
then
893 ("current instance prefix must be a direct name", P
);
896 -- If a current instance attribute appears in a component
897 -- constraint it must appear alone; other contexts (spec-
898 -- expressions, within a task body) are not subject to this
901 if not In_Spec_Expression
902 and then not Has_Completion
(Scop
)
904 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
905 N_Index_Or_Discriminant_Constraint
)
908 ("current instance attribute must appear alone", N
);
911 if Is_CPP_Class
(Root_Type
(Typ
)) then
913 ("??current instance unsupported for derivations of "
914 & "'C'P'P types", N
);
917 -- OK if we are in initialization procedure for the type
918 -- in question, in which case the reference to the type
919 -- is rewritten as a reference to the current object.
921 elsif Ekind
(Scop
) = E_Procedure
922 and then Is_Init_Proc
(Scop
)
923 and then Etype
(First_Formal
(Scop
)) = Typ
926 Make_Attribute_Reference
(Loc
,
927 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
928 Attribute_Name
=> Name_Unrestricted_Access
));
932 -- OK if a task type, this test needs sharpening up ???
934 elsif Is_Task_Type
(Typ
) then
937 -- OK if self-reference in an aggregate in Ada 2005, and
938 -- the reference comes from a copied default expression.
940 -- Note that we check legality of self-reference even if the
941 -- expression comes from source, e.g. when a single component
942 -- association in an aggregate has a box association.
944 elsif Ada_Version
>= Ada_2005
945 and then OK_Self_Reference
949 -- OK if reference to current instance of a protected object
951 elsif Is_Protected_Self_Reference
(P
) then
954 -- Otherwise we have an error case
957 Error_Attr
("% attribute cannot be applied to type", P
);
963 -- If we fall through, we have a normal access to object case
965 -- Unrestricted_Access is (for now) legal wherever an allocator would
966 -- be legal, so its Etype is set to E_Allocator. The expected type
967 -- of the other attributes is a general access type, and therefore
968 -- we label them with E_Access_Attribute_Type.
970 if not Is_Overloaded
(P
) then
971 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
972 Set_Etype
(N
, Acc_Type
);
976 Index
: Interp_Index
;
979 Set_Etype
(N
, Any_Type
);
980 Get_First_Interp
(P
, Index
, It
);
981 while Present
(It
.Typ
) loop
982 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
983 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
984 Get_Next_Interp
(Index
, It
);
989 -- Special cases when we can find a prefix that is an entity name
998 if Is_Entity_Name
(PP
) then
1001 -- If we have an access to an object, and the attribute
1002 -- comes from source, then set the object as potentially
1003 -- source modified. We do this because the resulting access
1004 -- pointer can be used to modify the variable, and we might
1005 -- not detect this, leading to some junk warnings.
1007 Set_Never_Set_In_Source
(Ent
, False);
1009 -- Mark entity as address taken, and kill current values
1011 Set_Address_Taken
(Ent
);
1012 Kill_Current_Values
(Ent
);
1015 elsif Nkind_In
(PP
, N_Selected_Component
,
1016 N_Indexed_Component
)
1026 -- Check for aliased view.. We allow a nonaliased prefix when within
1027 -- an instance because the prefix may have been a tagged formal
1028 -- object, which is defined to be aliased even when the actual
1029 -- might not be (other instance cases will have been caught in the
1030 -- generic). Similarly, within an inlined body we know that the
1031 -- attribute is legal in the original subprogram, and therefore
1032 -- legal in the expansion.
1034 if not Is_Aliased_View
(P
)
1035 and then not In_Instance
1036 and then not In_Inlined_Body
1038 -- Here we have a non-aliased view. This is illegal unless we
1039 -- have the case of Unrestricted_Access, where for now we allow
1040 -- this (we will reject later if expected type is access to an
1041 -- unconstrained array with a thin pointer).
1043 if Aname
/= Name_Unrestricted_Access
then
1044 Error_Attr_P
("prefix of % attribute must be aliased");
1045 Check_No_Implicit_Aliasing
(P
);
1047 -- For Unrestricted_Access, record that prefix is not aliased
1048 -- to simplify legality check later on.
1051 Set_Non_Aliased_Prefix
(N
);
1054 -- If we have an aliased view, and we have Unrestricted_Access, then
1055 -- output a warning that Unchecked_Access would have been fine, and
1056 -- change the node to be Unchecked_Access.
1059 -- For now, hold off on this change ???
1063 end Analyze_Access_Attribute
;
1065 ---------------------------------
1066 -- Bad_Attribute_For_Predicate --
1067 ---------------------------------
1069 procedure Bad_Attribute_For_Predicate
is
1071 if Is_Scalar_Type
(P_Type
)
1072 and then Comes_From_Source
(N
)
1074 Error_Msg_Name_1
:= Aname
;
1075 Bad_Predicated_Subtype_Use
1076 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1078 end Bad_Attribute_For_Predicate
;
1080 --------------------------------
1081 -- Check_Array_Or_Scalar_Type --
1082 --------------------------------
1084 procedure Check_Array_Or_Scalar_Type
is
1088 -- Dimension number for array attributes
1091 -- Case of string literal or string literal subtype. These cases
1092 -- cannot arise from legal Ada code, but the expander is allowed
1093 -- to generate them. They require special handling because string
1094 -- literal subtypes do not have standard bounds (the whole idea
1095 -- of these subtypes is to avoid having to generate the bounds)
1097 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1098 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1103 elsif Is_Scalar_Type
(P_Type
) then
1106 if Present
(E1
) then
1107 Error_Attr
("invalid argument in % attribute", E1
);
1109 Set_Etype
(N
, P_Base_Type
);
1113 -- The following is a special test to allow 'First to apply to
1114 -- private scalar types if the attribute comes from generated
1115 -- code. This occurs in the case of Normalize_Scalars code.
1117 elsif Is_Private_Type
(P_Type
)
1118 and then Present
(Full_View
(P_Type
))
1119 and then Is_Scalar_Type
(Full_View
(P_Type
))
1120 and then not Comes_From_Source
(N
)
1122 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1124 -- Array types other than string literal subtypes handled above
1129 -- We know prefix is an array type, or the name of an array
1130 -- object, and that the expression, if present, is static
1131 -- and within the range of the dimensions of the type.
1133 pragma Assert
(Is_Array_Type
(P_Type
));
1134 Index
:= First_Index
(P_Base_Type
);
1138 -- First dimension assumed
1140 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1143 D
:= UI_To_Int
(Intval
(E1
));
1145 for J
in 1 .. D
- 1 loop
1149 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1150 Set_Etype
(E1
, Standard_Integer
);
1153 end Check_Array_Or_Scalar_Type
;
1155 ----------------------
1156 -- Check_Array_Type --
1157 ----------------------
1159 procedure Check_Array_Type
is
1161 -- Dimension number for array attributes
1164 -- If the type is a string literal type, then this must be generated
1165 -- internally, and no further check is required on its legality.
1167 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1170 -- If the type is a composite, it is an illegal aggregate, no point
1173 elsif P_Type
= Any_Composite
then
1174 raise Bad_Attribute
;
1177 -- Normal case of array type or subtype
1179 Check_Either_E0_Or_E1
;
1182 if Is_Array_Type
(P_Type
) then
1183 if not Is_Constrained
(P_Type
)
1184 and then Is_Entity_Name
(P
)
1185 and then Is_Type
(Entity
(P
))
1187 -- Note: we do not call Error_Attr here, since we prefer to
1188 -- continue, using the relevant index type of the array,
1189 -- even though it is unconstrained. This gives better error
1190 -- recovery behavior.
1192 Error_Msg_Name_1
:= Aname
;
1194 ("prefix for % attribute must be constrained array", P
);
1197 -- The attribute reference freezes the type, and thus the
1198 -- component type, even if the attribute may not depend on the
1199 -- component. Diagnose arrays with incomplete components now.
1200 -- If the prefix is an access to array, this does not freeze
1201 -- the designated type.
1203 if Nkind
(P
) /= N_Explicit_Dereference
then
1204 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1207 D
:= Number_Dimensions
(P_Type
);
1210 if Is_Private_Type
(P_Type
) then
1211 Error_Attr_P
("prefix for % attribute may not be private type");
1213 elsif Is_Access_Type
(P_Type
)
1214 and then Is_Array_Type
(Designated_Type
(P_Type
))
1215 and then Is_Entity_Name
(P
)
1216 and then Is_Type
(Entity
(P
))
1218 Error_Attr_P
("prefix of % attribute cannot be access type");
1220 elsif Attr_Id
= Attribute_First
1222 Attr_Id
= Attribute_Last
1224 Error_Attr
("invalid prefix for % attribute", P
);
1227 Error_Attr_P
("prefix for % attribute must be array");
1231 if Present
(E1
) then
1232 Resolve
(E1
, Any_Integer
);
1233 Set_Etype
(E1
, Standard_Integer
);
1235 if not Is_OK_Static_Expression
(E1
)
1236 or else Raises_Constraint_Error
(E1
)
1238 Flag_Non_Static_Expr
1239 ("expression for dimension must be static!", E1
);
1242 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1243 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1245 Error_Attr
("invalid dimension number for array type", E1
);
1249 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1250 and then Comes_From_Source
(N
)
1252 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1254 end Check_Array_Type
;
1256 -------------------------
1257 -- Check_Asm_Attribute --
1258 -------------------------
1260 procedure Check_Asm_Attribute
is
1265 -- Check first argument is static string expression
1267 Analyze_And_Resolve
(E1
, Standard_String
);
1269 if Etype
(E1
) = Any_Type
then
1272 elsif not Is_OK_Static_Expression
(E1
) then
1273 Flag_Non_Static_Expr
1274 ("constraint argument must be static string expression!", E1
);
1278 -- Check second argument is right type
1280 Analyze_And_Resolve
(E2
, Entity
(P
));
1282 -- Note: that is all we need to do, we don't need to check
1283 -- that it appears in a correct context. The Ada type system
1284 -- will do that for us.
1286 end Check_Asm_Attribute
;
1288 ---------------------
1289 -- Check_Component --
1290 ---------------------
1292 procedure Check_Component
is
1296 if Nkind
(P
) /= N_Selected_Component
1298 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1300 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1302 Error_Attr_P
("prefix for % attribute must be selected component");
1304 end Check_Component
;
1306 ------------------------------------
1307 -- Check_Decimal_Fixed_Point_Type --
1308 ------------------------------------
1310 procedure Check_Decimal_Fixed_Point_Type
is
1314 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1315 Error_Attr_P
("prefix of % attribute must be decimal type");
1317 end Check_Decimal_Fixed_Point_Type
;
1319 -----------------------
1320 -- Check_Dereference --
1321 -----------------------
1323 procedure Check_Dereference
is
1326 -- Case of a subtype mark
1328 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1332 -- Case of an expression
1336 if Is_Access_Type
(P_Type
) then
1338 -- If there is an implicit dereference, then we must freeze the
1339 -- designated type of the access type, since the type of the
1340 -- referenced array is this type (see AI95-00106).
1342 -- As done elsewhere, freezing must not happen when pre-analyzing
1343 -- a pre- or postcondition or a default value for an object or for
1344 -- a formal parameter.
1346 if not In_Spec_Expression
then
1347 Freeze_Before
(N
, Designated_Type
(P_Type
));
1351 Make_Explicit_Dereference
(Sloc
(P
),
1352 Prefix
=> Relocate_Node
(P
)));
1354 Analyze_And_Resolve
(P
);
1355 P_Type
:= Etype
(P
);
1357 if P_Type
= Any_Type
then
1358 raise Bad_Attribute
;
1361 P_Base_Type
:= Base_Type
(P_Type
);
1363 end Check_Dereference
;
1365 -------------------------
1366 -- Check_Discrete_Type --
1367 -------------------------
1369 procedure Check_Discrete_Type
is
1373 if not Is_Discrete_Type
(P_Type
) then
1374 Error_Attr_P
("prefix of % attribute must be discrete type");
1376 end Check_Discrete_Type
;
1382 procedure Check_E0
is
1384 if Present
(E1
) then
1385 Unexpected_Argument
(E1
);
1393 procedure Check_E1
is
1395 Check_Either_E0_Or_E1
;
1399 -- Special-case attributes that are functions and that appear as
1400 -- the prefix of another attribute. Error is posted on parent.
1402 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1403 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1407 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1408 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1409 Set_Etype
(Parent
(N
), Any_Type
);
1410 Set_Entity
(Parent
(N
), Any_Type
);
1411 raise Bad_Attribute
;
1414 Error_Attr
("missing argument for % attribute", N
);
1423 procedure Check_E2
is
1426 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1428 Error_Attr
("missing argument for % attribute (2 required)", N
);
1432 ---------------------------
1433 -- Check_Either_E0_Or_E1 --
1434 ---------------------------
1436 procedure Check_Either_E0_Or_E1
is
1438 if Present
(E2
) then
1439 Unexpected_Argument
(E2
);
1441 end Check_Either_E0_Or_E1
;
1443 ----------------------
1444 -- Check_Enum_Image --
1445 ----------------------
1447 procedure Check_Enum_Image
is
1451 -- When an enumeration type appears in an attribute reference, all
1452 -- literals of the type are marked as referenced. This must only be
1453 -- done if the attribute reference appears in the current source.
1454 -- Otherwise the information on references may differ between a
1455 -- normal compilation and one that performs inlining.
1457 if Is_Enumeration_Type
(P_Base_Type
)
1458 and then In_Extended_Main_Code_Unit
(N
)
1460 Lit
:= First_Literal
(P_Base_Type
);
1461 while Present
(Lit
) loop
1462 Set_Referenced
(Lit
);
1466 end Check_Enum_Image
;
1468 ----------------------------
1469 -- Check_First_Last_Valid --
1470 ----------------------------
1472 procedure Check_First_Last_Valid
is
1474 Check_Discrete_Type
;
1476 -- Freeze the subtype now, so that the following test for predicates
1477 -- works (we set the predicates stuff up at freeze time)
1479 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1481 -- Now test for dynamic predicate
1483 if Has_Predicates
(P_Type
)
1484 and then not (Has_Static_Predicate
(P_Type
))
1487 ("prefix of % attribute may not have dynamic predicate");
1490 -- Check non-static subtype
1492 if not Is_OK_Static_Subtype
(P_Type
) then
1493 Error_Attr_P
("prefix of % attribute must be a static subtype");
1496 -- Test case for no values
1498 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1499 Expr_Value
(Type_High_Bound
(P_Type
))
1500 or else (Has_Predicates
(P_Type
)
1502 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1505 ("prefix of % attribute must be subtype with "
1506 & "at least one value");
1508 end Check_First_Last_Valid
;
1510 ----------------------------
1511 -- Check_Fixed_Point_Type --
1512 ----------------------------
1514 procedure Check_Fixed_Point_Type
is
1518 if not Is_Fixed_Point_Type
(P_Type
) then
1519 Error_Attr_P
("prefix of % attribute must be fixed point type");
1521 end Check_Fixed_Point_Type
;
1523 ------------------------------
1524 -- Check_Fixed_Point_Type_0 --
1525 ------------------------------
1527 procedure Check_Fixed_Point_Type_0
is
1529 Check_Fixed_Point_Type
;
1531 end Check_Fixed_Point_Type_0
;
1533 -------------------------------
1534 -- Check_Floating_Point_Type --
1535 -------------------------------
1537 procedure Check_Floating_Point_Type
is
1541 if not Is_Floating_Point_Type
(P_Type
) then
1542 Error_Attr_P
("prefix of % attribute must be float type");
1544 end Check_Floating_Point_Type
;
1546 ---------------------------------
1547 -- Check_Floating_Point_Type_0 --
1548 ---------------------------------
1550 procedure Check_Floating_Point_Type_0
is
1552 Check_Floating_Point_Type
;
1554 end Check_Floating_Point_Type_0
;
1556 ---------------------------------
1557 -- Check_Floating_Point_Type_1 --
1558 ---------------------------------
1560 procedure Check_Floating_Point_Type_1
is
1562 Check_Floating_Point_Type
;
1564 end Check_Floating_Point_Type_1
;
1566 ---------------------------------
1567 -- Check_Floating_Point_Type_2 --
1568 ---------------------------------
1570 procedure Check_Floating_Point_Type_2
is
1572 Check_Floating_Point_Type
;
1574 end Check_Floating_Point_Type_2
;
1576 ------------------------
1577 -- Check_Integer_Type --
1578 ------------------------
1580 procedure Check_Integer_Type
is
1584 if not Is_Integer_Type
(P_Type
) then
1585 Error_Attr_P
("prefix of % attribute must be integer type");
1587 end Check_Integer_Type
;
1589 --------------------------------
1590 -- Check_Modular_Integer_Type --
1591 --------------------------------
1593 procedure Check_Modular_Integer_Type
is
1597 if not Is_Modular_Integer_Type
(P_Type
) then
1599 ("prefix of % attribute must be modular integer type");
1601 end Check_Modular_Integer_Type
;
1603 ------------------------
1604 -- Check_Not_CPP_Type --
1605 ------------------------
1607 procedure Check_Not_CPP_Type
is
1609 if Is_Tagged_Type
(Etype
(P
))
1610 and then Convention
(Etype
(P
)) = Convention_CPP
1611 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1614 ("invalid use of % attribute with 'C'P'P tagged type");
1616 end Check_Not_CPP_Type
;
1618 -------------------------------
1619 -- Check_Not_Incomplete_Type --
1620 -------------------------------
1622 procedure Check_Not_Incomplete_Type
is
1627 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1628 -- dereference we have to check wrong uses of incomplete types
1629 -- (other wrong uses are checked at their freezing point).
1631 -- Example 1: Limited-with
1633 -- limited with Pkg;
1635 -- type Acc is access Pkg.T;
1637 -- S : Integer := X.all'Size; -- ERROR
1640 -- Example 2: Tagged incomplete
1642 -- type T is tagged;
1643 -- type Acc is access all T;
1645 -- S : constant Integer := X.all'Size; -- ERROR
1646 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1648 if Ada_Version
>= Ada_2005
1649 and then Nkind
(P
) = N_Explicit_Dereference
1652 while Nkind
(E
) = N_Explicit_Dereference
loop
1658 if From_Limited_With
(Typ
) then
1660 ("prefix of % attribute cannot be an incomplete type");
1663 if Is_Access_Type
(Typ
) then
1664 Typ
:= Directly_Designated_Type
(Typ
);
1667 if Is_Class_Wide_Type
(Typ
) then
1668 Typ
:= Root_Type
(Typ
);
1671 -- A legal use of a shadow entity occurs only when the unit
1672 -- where the non-limited view resides is imported via a regular
1673 -- with clause in the current body. Such references to shadow
1674 -- entities may occur in subprogram formals.
1676 if Is_Incomplete_Type
(Typ
)
1677 and then From_Limited_With
(Typ
)
1678 and then Present
(Non_Limited_View
(Typ
))
1679 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1681 Typ
:= Non_Limited_View
(Typ
);
1684 if Ekind
(Typ
) = E_Incomplete_Type
1685 and then No
(Full_View
(Typ
))
1688 ("prefix of % attribute cannot be an incomplete type");
1693 if not Is_Entity_Name
(P
)
1694 or else not Is_Type
(Entity
(P
))
1695 or else In_Spec_Expression
1699 Check_Fully_Declared
(P_Type
, P
);
1701 end Check_Not_Incomplete_Type
;
1703 ----------------------------
1704 -- Check_Object_Reference --
1705 ----------------------------
1707 procedure Check_Object_Reference
(P
: Node_Id
) is
1711 -- If we need an object, and we have a prefix that is the name of
1712 -- a function entity, convert it into a function call.
1714 if Is_Entity_Name
(P
)
1715 and then Ekind
(Entity
(P
)) = E_Function
1717 Rtyp
:= Etype
(Entity
(P
));
1720 Make_Function_Call
(Sloc
(P
),
1721 Name
=> Relocate_Node
(P
)));
1723 Analyze_And_Resolve
(P
, Rtyp
);
1725 -- Otherwise we must have an object reference
1727 elsif not Is_Object_Reference
(P
) then
1728 Error_Attr_P
("prefix of % attribute must be object");
1730 end Check_Object_Reference
;
1732 ----------------------------
1733 -- Check_PolyORB_Attribute --
1734 ----------------------------
1736 procedure Check_PolyORB_Attribute
is
1738 Validate_Non_Static_Attribute_Function_Call
;
1743 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1745 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1747 end Check_PolyORB_Attribute
;
1749 ------------------------
1750 -- Check_Program_Unit --
1751 ------------------------
1753 procedure Check_Program_Unit
is
1755 if Is_Entity_Name
(P
) then
1757 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1758 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1761 if K
in Subprogram_Kind
1762 or else K
in Task_Kind
1763 or else K
in Protected_Kind
1764 or else K
= E_Package
1765 or else K
in Generic_Unit_Kind
1766 or else (K
= E_Variable
1770 Is_Protected_Type
(T
)))
1777 Error_Attr_P
("prefix of % attribute must be program unit");
1778 end Check_Program_Unit
;
1780 ---------------------
1781 -- Check_Real_Type --
1782 ---------------------
1784 procedure Check_Real_Type
is
1788 if not Is_Real_Type
(P_Type
) then
1789 Error_Attr_P
("prefix of % attribute must be real type");
1791 end Check_Real_Type
;
1793 -----------------------
1794 -- Check_Scalar_Type --
1795 -----------------------
1797 procedure Check_Scalar_Type
is
1801 if not Is_Scalar_Type
(P_Type
) then
1802 Error_Attr_P
("prefix of % attribute must be scalar type");
1804 end Check_Scalar_Type
;
1806 ------------------------------------------
1807 -- Check_SPARK_05_Restriction_On_Attribute --
1808 ------------------------------------------
1810 procedure Check_SPARK_05_Restriction_On_Attribute
is
1812 Error_Msg_Name_1
:= Aname
;
1813 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
1814 end Check_SPARK_05_Restriction_On_Attribute
;
1816 ---------------------------
1817 -- Check_Standard_Prefix --
1818 ---------------------------
1820 procedure Check_Standard_Prefix
is
1824 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
1825 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1827 end Check_Standard_Prefix
;
1829 ----------------------------
1830 -- Check_Stream_Attribute --
1831 ----------------------------
1833 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1837 In_Shared_Var_Procs
: Boolean;
1838 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1839 -- For this runtime package (always compiled in GNAT mode), we allow
1840 -- stream attributes references for limited types for the case where
1841 -- shared passive objects are implemented using stream attributes,
1842 -- which is the default in GNAT's persistent storage implementation.
1845 Validate_Non_Static_Attribute_Function_Call
;
1847 -- With the exception of 'Input, Stream attributes are procedures,
1848 -- and can only appear at the position of procedure calls. We check
1849 -- for this here, before they are rewritten, to give a more precise
1852 if Nam
= TSS_Stream_Input
then
1855 elsif Is_List_Member
(N
)
1856 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1863 ("invalid context for attribute%, which is a procedure", N
);
1867 Btyp
:= Implementation_Base_Type
(P_Type
);
1869 -- Stream attributes not allowed on limited types unless the
1870 -- attribute reference was generated by the expander (in which
1871 -- case the underlying type will be used, as described in Sinfo),
1872 -- or the attribute was specified explicitly for the type itself
1873 -- or one of its ancestors (taking visibility rules into account if
1874 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1875 -- (with no visibility restriction).
1878 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1880 if Present
(Gen_Body
) then
1881 In_Shared_Var_Procs
:=
1882 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1884 In_Shared_Var_Procs
:= False;
1888 if (Comes_From_Source
(N
)
1889 and then not (In_Shared_Var_Procs
or In_Instance
))
1890 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1891 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1893 Error_Msg_Name_1
:= Aname
;
1895 if Is_Limited_Type
(P_Type
) then
1897 ("limited type& has no% attribute", P
, P_Type
);
1898 Explain_Limited_Type
(P_Type
, P
);
1901 ("attribute% for type& is not available", P
, P_Type
);
1905 -- Check restriction violations
1907 -- First check the No_Streams restriction, which prohibits the use
1908 -- of explicit stream attributes in the source program. We do not
1909 -- prevent the occurrence of stream attributes in generated code,
1910 -- for instance those generated implicitly for dispatching purposes.
1912 if Comes_From_Source
(N
) then
1913 Check_Restriction
(No_Streams
, P
);
1916 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1917 -- it is illegal to use a predefined elementary type stream attribute
1918 -- either by itself, or more importantly as part of the attribute
1919 -- subprogram for a composite type. However, if the broader
1920 -- restriction No_Streams is active, stream operations are not
1921 -- generated, and there is no error.
1923 if Restriction_Active
(No_Default_Stream_Attributes
)
1924 and then not Restriction_Active
(No_Streams
)
1930 if Nam
= TSS_Stream_Input
1932 Nam
= TSS_Stream_Read
1935 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1938 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1942 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1945 ("missing user-defined Stream Read or Write for type&",
1947 if not Is_Elementary_Type
(P_Type
) then
1949 ("\which is a component of type&", N
, P_Type
);
1955 -- Check special case of Exception_Id and Exception_Occurrence which
1956 -- are not allowed for restriction No_Exception_Registration.
1958 if Restriction_Check_Required
(No_Exception_Registration
)
1959 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1961 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1963 Check_Restriction
(No_Exception_Registration
, P
);
1966 -- Here we must check that the first argument is an access type
1967 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1969 Analyze_And_Resolve
(E1
);
1972 -- Note: the double call to Root_Type here is needed because the
1973 -- root type of a class-wide type is the corresponding type (e.g.
1974 -- X for X'Class, and we really want to go to the root.)
1976 if not Is_Access_Type
(Etyp
)
1977 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1978 RTE
(RE_Root_Stream_Type
)
1981 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1984 -- Check that the second argument is of the right type if there is
1985 -- one (the Input attribute has only one argument so this is skipped)
1987 if Present
(E2
) then
1990 if Nam
= TSS_Stream_Read
1991 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1994 ("second argument of % attribute must be a variable", E2
);
1997 Resolve
(E2
, P_Type
);
2001 end Check_Stream_Attribute
;
2003 -------------------------
2004 -- Check_System_Prefix --
2005 -------------------------
2007 procedure Check_System_Prefix
is
2009 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2010 Error_Attr
("only allowed prefix for % attribute is System", P
);
2012 end Check_System_Prefix
;
2014 -----------------------
2015 -- Check_Task_Prefix --
2016 -----------------------
2018 procedure Check_Task_Prefix
is
2022 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2023 -- task interface class-wide types.
2025 if Is_Task_Type
(Etype
(P
))
2026 or else (Is_Access_Type
(Etype
(P
))
2027 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2028 or else (Ada_Version
>= Ada_2005
2029 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2030 and then Is_Interface
(Etype
(P
))
2031 and then Is_Task_Interface
(Etype
(P
)))
2036 if Ada_Version
>= Ada_2005
then
2038 ("prefix of % attribute must be a task or a task " &
2039 "interface class-wide object");
2042 Error_Attr_P
("prefix of % attribute must be a task");
2045 end Check_Task_Prefix
;
2051 -- The possibilities are an entity name denoting a type, or an
2052 -- attribute reference that denotes a type (Base or Class). If
2053 -- the type is incomplete, replace it with its full view.
2055 procedure Check_Type
is
2057 if not Is_Entity_Name
(P
)
2058 or else not Is_Type
(Entity
(P
))
2060 Error_Attr_P
("prefix of % attribute must be a type");
2062 elsif Is_Protected_Self_Reference
(P
) then
2064 ("prefix of % attribute denotes current instance "
2065 & "(RM 9.4(21/2))");
2067 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2068 and then Present
(Full_View
(Entity
(P
)))
2070 P_Type
:= Full_View
(Entity
(P
));
2071 Set_Entity
(P
, P_Type
);
2075 ---------------------
2076 -- Check_Unit_Name --
2077 ---------------------
2079 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2081 if Nkind
(Nod
) = N_Identifier
then
2084 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2085 Check_Unit_Name
(Prefix
(Nod
));
2087 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2092 Error_Attr
("argument for % attribute must be unit name", P
);
2093 end Check_Unit_Name
;
2099 procedure Error_Attr
is
2101 Set_Etype
(N
, Any_Type
);
2102 Set_Entity
(N
, Any_Type
);
2103 raise Bad_Attribute
;
2106 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2108 Error_Msg_Name_1
:= Aname
;
2109 Error_Msg_N
(Msg
, Error_Node
);
2117 procedure Error_Attr_P
(Msg
: String) is
2119 Error_Msg_Name_1
:= Aname
;
2120 Error_Msg_F
(Msg
, P
);
2124 ---------------------
2125 -- In_Refined_Post --
2126 ---------------------
2128 function In_Refined_Post
return Boolean is
2129 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean;
2130 -- Determine whether Prag denotes one of the incarnations of pragma
2131 -- Refined_Post (either as is or pragma Check (Refined_Post, ...).
2133 ---------------------
2134 -- Is_Refined_Post --
2135 ---------------------
2137 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean is
2138 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
2139 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2142 if Nam
= Name_Refined_Post
then
2145 elsif Nam
= Name_Check
then
2146 pragma Assert
(Present
(Args
));
2148 return Chars
(Expression
(First
(Args
))) = Name_Refined_Post
;
2152 end Is_Refined_Post
;
2158 -- Start of processing for In_Refined_Post
2162 while Present
(Stmt
) loop
2163 if Nkind
(Stmt
) = N_Pragma
and then Is_Refined_Post
(Stmt
) then
2166 -- Prevent the search from going too far
2168 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
2172 Stmt
:= Parent
(Stmt
);
2176 end In_Refined_Post
;
2178 ----------------------------
2179 -- Legal_Formal_Attribute --
2180 ----------------------------
2182 procedure Legal_Formal_Attribute
is
2186 if not Is_Entity_Name
(P
)
2187 or else not Is_Type
(Entity
(P
))
2189 Error_Attr_P
("prefix of % attribute must be generic type");
2191 elsif Is_Generic_Actual_Type
(Entity
(P
))
2193 or else In_Inlined_Body
2197 elsif Is_Generic_Type
(Entity
(P
)) then
2198 if not Is_Indefinite_Subtype
(Entity
(P
)) then
2200 ("prefix of % attribute must be indefinite generic type");
2205 ("prefix of % attribute must be indefinite generic type");
2208 Set_Etype
(N
, Standard_Boolean
);
2209 end Legal_Formal_Attribute
;
2211 ---------------------------------------------------------------
2212 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2213 ---------------------------------------------------------------
2215 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2219 Check_Not_Incomplete_Type
;
2220 Set_Etype
(N
, Universal_Integer
);
2221 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2227 procedure Min_Max
is
2231 Resolve
(E1
, P_Base_Type
);
2232 Resolve
(E2
, P_Base_Type
);
2233 Set_Etype
(N
, P_Base_Type
);
2235 -- Check for comparison on unordered enumeration type
2237 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2238 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2240 ("comparison on unordered enumeration type& declared#?U?",
2245 ------------------------
2246 -- Standard_Attribute --
2247 ------------------------
2249 procedure Standard_Attribute
(Val
: Int
) is
2251 Check_Standard_Prefix
;
2252 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2254 Set_Is_Static_Expression
(N
, True);
2255 end Standard_Attribute
;
2257 --------------------
2258 -- Uneval_Old_Msg --
2259 --------------------
2261 procedure Uneval_Old_Msg
is
2262 Uneval_Old_Setting
: Character;
2266 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2267 -- N_Aspect_Specification node that corresponds to the attribute.
2269 -- First find the pragma in which we appear (note that at this stage,
2270 -- even if we appeared originally within an aspect specification, we
2271 -- are now within the corresponding pragma).
2275 Prag
:= Parent
(Prag
);
2276 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2279 if Present
(Prag
) then
2280 if Uneval_Old_Accept
(Prag
) then
2281 Uneval_Old_Setting
:= 'A';
2282 elsif Uneval_Old_Warn
(Prag
) then
2283 Uneval_Old_Setting
:= 'W';
2285 Uneval_Old_Setting
:= 'E';
2288 -- If we did not find the pragma, that's odd, just use the setting
2289 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2292 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2295 -- Processing depends on the setting of Uneval_Old
2297 case Uneval_Old_Setting
is
2300 ("prefix of attribute % that is potentially "
2301 & "unevaluated must denote an entity");
2304 Error_Msg_Name_1
:= Aname
;
2306 ("??prefix of attribute % appears in potentially "
2307 & "unevaluated context, exception may be raised", P
);
2313 raise Program_Error
;
2317 -------------------------
2318 -- Unexpected Argument --
2319 -------------------------
2321 procedure Unexpected_Argument
(En
: Node_Id
) is
2323 Error_Attr
("unexpected argument for % attribute", En
);
2324 end Unexpected_Argument
;
2326 -------------------------------------------------
2327 -- Validate_Non_Static_Attribute_Function_Call --
2328 -------------------------------------------------
2330 -- This function should be moved to Sem_Dist ???
2332 procedure Validate_Non_Static_Attribute_Function_Call
is
2334 if In_Preelaborated_Unit
2335 and then not In_Subprogram_Or_Concurrent_Unit
2337 Flag_Non_Static_Expr
2338 ("non-static function call in preelaborated unit!", N
);
2340 end Validate_Non_Static_Attribute_Function_Call
;
2342 -- Start of processing for Analyze_Attribute
2345 -- Immediate return if unrecognized attribute (already diagnosed
2346 -- by parser, so there is nothing more that we need to do)
2348 if not Is_Attribute_Name
(Aname
) then
2349 raise Bad_Attribute
;
2352 -- Deal with Ada 83 issues
2354 if Comes_From_Source
(N
) then
2355 if not Attribute_83
(Attr_Id
) then
2356 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2357 Error_Msg_Name_1
:= Aname
;
2358 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2361 if Attribute_Impl_Def
(Attr_Id
) then
2362 Check_Restriction
(No_Implementation_Attributes
, N
);
2367 -- Deal with Ada 2005 attributes that are implementation attributes
2368 -- because they appear in a version of Ada before Ada 2005, and
2369 -- similarly for Ada 2012 attributes appearing in an earlier version.
2371 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2373 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2375 Check_Restriction
(No_Implementation_Attributes
, N
);
2378 -- Remote access to subprogram type access attribute reference needs
2379 -- unanalyzed copy for tree transformation. The analyzed copy is used
2380 -- for its semantic information (whether prefix is a remote subprogram
2381 -- name), the unanalyzed copy is used to construct new subtree rooted
2382 -- with N_Aggregate which represents a fat pointer aggregate.
2384 if Aname
= Name_Access
then
2385 Discard_Node
(Copy_Separate_Tree
(N
));
2388 -- Analyze prefix and exit if error in analysis. If the prefix is an
2389 -- incomplete type, use full view if available. Note that there are
2390 -- some attributes for which we do not analyze the prefix, since the
2391 -- prefix is not a normal name, or else needs special handling.
2393 if Aname
/= Name_Elab_Body
and then
2394 Aname
/= Name_Elab_Spec
and then
2395 Aname
/= Name_Elab_Subp_Body
and then
2396 Aname
/= Name_UET_Address
and then
2397 Aname
/= Name_Enabled
and then
2401 P_Type
:= Etype
(P
);
2403 if Is_Entity_Name
(P
)
2404 and then Present
(Entity
(P
))
2405 and then Is_Type
(Entity
(P
))
2407 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2408 P_Type
:= Get_Full_View
(P_Type
);
2409 Set_Entity
(P
, P_Type
);
2410 Set_Etype
(P
, P_Type
);
2412 elsif Entity
(P
) = Current_Scope
2413 and then Is_Record_Type
(Entity
(P
))
2415 -- Use of current instance within the type. Verify that if the
2416 -- attribute appears within a constraint, it yields an access
2417 -- type, other uses are illegal.
2425 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2427 Par
:= Parent
(Par
);
2431 and then Nkind
(Par
) = N_Subtype_Indication
2433 if Attr_Id
/= Attribute_Access
2434 and then Attr_Id
/= Attribute_Unchecked_Access
2435 and then Attr_Id
/= Attribute_Unrestricted_Access
2438 ("in a constraint the current instance can only"
2439 & " be used with an access attribute", N
);
2446 if P_Type
= Any_Type
then
2447 raise Bad_Attribute
;
2450 P_Base_Type
:= Base_Type
(P_Type
);
2453 -- Analyze expressions that may be present, exiting if an error occurs
2460 E1
:= First
(Exprs
);
2462 -- Skip analysis for case of Restriction_Set, we do not expect
2463 -- the argument to be analyzed in this case.
2465 if Aname
/= Name_Restriction_Set
then
2468 -- Check for missing/bad expression (result of previous error)
2470 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2471 raise Bad_Attribute
;
2477 if Present
(E2
) then
2480 if Etype
(E2
) = Any_Type
then
2481 raise Bad_Attribute
;
2484 if Present
(Next
(E2
)) then
2485 Unexpected_Argument
(Next
(E2
));
2490 -- Cases where prefix must be resolvable by itself
2492 if Is_Overloaded
(P
)
2493 and then Aname
/= Name_Access
2494 and then Aname
/= Name_Address
2495 and then Aname
/= Name_Code_Address
2496 and then Aname
/= Name_Result
2497 and then Aname
/= Name_Unchecked_Access
2499 -- The prefix must be resolvable by itself, without reference to the
2500 -- attribute. One case that requires special handling is a prefix
2501 -- that is a function name, where one interpretation may be a
2502 -- parameterless call. Entry attributes are handled specially below.
2504 if Is_Entity_Name
(P
)
2505 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2507 Check_Parameterless_Call
(P
);
2510 if Is_Overloaded
(P
) then
2512 -- Ada 2005 (AI-345): Since protected and task types have
2513 -- primitive entry wrappers, the attributes Count, and Caller
2514 -- require a context check
2516 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2518 Count
: Natural := 0;
2523 Get_First_Interp
(P
, I
, It
);
2524 while Present
(It
.Nam
) loop
2525 if Comes_From_Source
(It
.Nam
) then
2531 Get_Next_Interp
(I
, It
);
2535 Error_Attr
("ambiguous prefix for % attribute", P
);
2537 Set_Is_Overloaded
(P
, False);
2542 Error_Attr
("ambiguous prefix for % attribute", P
);
2547 -- In SPARK, attributes of private types are only allowed if the full
2548 -- type declaration is visible.
2550 -- Note: the check for Present (Entity (P)) defends against some error
2551 -- conditions where the Entity field is not set.
2553 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2554 and then Is_Type
(Entity
(P
))
2555 and then Is_Private_Type
(P_Type
)
2556 and then not In_Open_Scopes
(Scope
(P_Type
))
2557 and then not In_Spec_Expression
2559 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
2562 -- Remaining processing depends on attribute
2566 -- Attributes related to Ada 2012 iterators. Attribute specifications
2567 -- exist for these, but they cannot be queried.
2569 when Attribute_Constant_Indexing |
2570 Attribute_Default_Iterator |
2571 Attribute_Implicit_Dereference |
2572 Attribute_Iterator_Element |
2573 Attribute_Iterable |
2574 Attribute_Variable_Indexing
=>
2575 Error_Msg_N
("illegal attribute", N
);
2577 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2578 -- were already rejected by the parser. Thus they shouldn't appear here.
2580 when Internal_Attribute_Id
=>
2581 raise Program_Error
;
2587 when Attribute_Abort_Signal
=>
2588 Check_Standard_Prefix
;
2589 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
2596 when Attribute_Access
=>
2597 Analyze_Access_Attribute
;
2603 when Attribute_Address
=>
2606 Set_Etype
(N
, RTE
(RE_Address
));
2612 when Attribute_Address_Size
=>
2613 Standard_Attribute
(System_Address_Size
);
2619 when Attribute_Adjacent
=>
2620 Check_Floating_Point_Type_2
;
2621 Set_Etype
(N
, P_Base_Type
);
2622 Resolve
(E1
, P_Base_Type
);
2623 Resolve
(E2
, P_Base_Type
);
2629 when Attribute_Aft
=>
2630 Check_Fixed_Point_Type_0
;
2631 Set_Etype
(N
, Universal_Integer
);
2637 when Attribute_Alignment
=>
2639 -- Don't we need more checking here, cf Size ???
2642 Check_Not_Incomplete_Type
;
2644 Set_Etype
(N
, Universal_Integer
);
2650 when Attribute_Asm_Input
=>
2651 Check_Asm_Attribute
;
2653 -- The back-end may need to take the address of E2
2655 if Is_Entity_Name
(E2
) then
2656 Set_Address_Taken
(Entity
(E2
));
2659 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2665 when Attribute_Asm_Output
=>
2666 Check_Asm_Attribute
;
2668 if Etype
(E2
) = Any_Type
then
2671 elsif Aname
= Name_Asm_Output
then
2672 if not Is_Variable
(E2
) then
2674 ("second argument for Asm_Output is not variable", E2
);
2678 Note_Possible_Modification
(E2
, Sure
=> True);
2680 -- The back-end may need to take the address of E2
2682 if Is_Entity_Name
(E2
) then
2683 Set_Address_Taken
(Entity
(E2
));
2686 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2688 -----------------------------
2689 -- Atomic_Always_Lock_Free --
2690 -----------------------------
2692 when Attribute_Atomic_Always_Lock_Free
=>
2695 Set_Etype
(N
, Standard_Boolean
);
2701 -- Note: when the base attribute appears in the context of a subtype
2702 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2703 -- the following circuit.
2705 when Attribute_Base
=> Base
: declare
2713 if Ada_Version
>= Ada_95
2714 and then not Is_Scalar_Type
(Typ
)
2715 and then not Is_Generic_Type
(Typ
)
2717 Error_Attr_P
("prefix of Base attribute must be scalar type");
2719 elsif Sloc
(Typ
) = Standard_Location
2720 and then Base_Type
(Typ
) = Typ
2721 and then Warn_On_Redundant_Constructs
2723 Error_Msg_NE
-- CODEFIX
2724 ("?r?redundant attribute, & is its own base type", N
, Typ
);
2727 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2728 Error_Msg_Name_1
:= Aname
;
2729 Check_SPARK_05_Restriction
2730 ("attribute% is only allowed as prefix of another attribute", P
);
2733 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2734 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2735 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
2743 when Attribute_Bit
=> Bit
:
2747 if not Is_Object_Reference
(P
) then
2748 Error_Attr_P
("prefix for % attribute must be object");
2750 -- What about the access object cases ???
2756 Set_Etype
(N
, Universal_Integer
);
2763 when Attribute_Bit_Order
=> Bit_Order
:
2768 if not Is_Record_Type
(P_Type
) then
2769 Error_Attr_P
("prefix of % attribute must be record type");
2772 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2774 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2777 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2780 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2783 -- Reset incorrect indication of staticness
2785 Set_Is_Static_Expression
(N
, False);
2792 -- Note: in generated code, we can have a Bit_Position attribute
2793 -- applied to a (naked) record component (i.e. the prefix is an
2794 -- identifier that references an E_Component or E_Discriminant
2795 -- entity directly, and this is interpreted as expected by Gigi.
2796 -- The following code will not tolerate such usage, but when the
2797 -- expander creates this special case, it marks it as analyzed
2798 -- immediately and sets an appropriate type.
2800 when Attribute_Bit_Position
=>
2801 if Comes_From_Source
(N
) then
2805 Set_Etype
(N
, Universal_Integer
);
2811 when Attribute_Body_Version
=>
2814 Set_Etype
(N
, RTE
(RE_Version_String
));
2820 when Attribute_Callable
=>
2822 Set_Etype
(N
, Standard_Boolean
);
2829 when Attribute_Caller
=> Caller
: declare
2836 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2839 if not Is_Entry
(Ent
) then
2840 Error_Attr
("invalid entry name", N
);
2844 Error_Attr
("invalid entry name", N
);
2848 for J
in reverse 0 .. Scope_Stack
.Last
loop
2849 S
:= Scope_Stack
.Table
(J
).Entity
;
2851 if S
= Scope
(Ent
) then
2852 Error_Attr
("Caller must appear in matching accept or body", N
);
2858 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2865 when Attribute_Ceiling
=>
2866 Check_Floating_Point_Type_1
;
2867 Set_Etype
(N
, P_Base_Type
);
2868 Resolve
(E1
, P_Base_Type
);
2874 when Attribute_Class
=>
2875 Check_Restriction
(No_Dispatch
, N
);
2879 -- Applying Class to untagged incomplete type is obsolescent in Ada
2880 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2881 -- this flag gets set by Find_Type in this situation.
2883 if Restriction_Check_Required
(No_Obsolescent_Features
)
2884 and then Ada_Version
>= Ada_2005
2885 and then Ekind
(P_Type
) = E_Incomplete_Type
2888 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2890 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2891 and then not Tagged_Present
(DN
)
2893 Check_Restriction
(No_Obsolescent_Features
, P
);
2902 when Attribute_Code_Address
=>
2905 if Nkind
(P
) = N_Attribute_Reference
2906 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
2910 elsif not Is_Entity_Name
(P
)
2911 or else (Ekind
(Entity
(P
)) /= E_Function
2913 Ekind
(Entity
(P
)) /= E_Procedure
)
2915 Error_Attr
("invalid prefix for % attribute", P
);
2916 Set_Address_Taken
(Entity
(P
));
2918 -- Issue an error if the prefix denotes an eliminated subprogram
2921 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2924 Set_Etype
(N
, RTE
(RE_Address
));
2926 ----------------------
2927 -- Compiler_Version --
2928 ----------------------
2930 when Attribute_Compiler_Version
=>
2932 Check_Standard_Prefix
;
2933 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2934 Analyze_And_Resolve
(N
, Standard_String
);
2935 Set_Is_Static_Expression
(N
, True);
2937 --------------------
2938 -- Component_Size --
2939 --------------------
2941 when Attribute_Component_Size
=>
2943 Set_Etype
(N
, Universal_Integer
);
2945 -- Note: unlike other array attributes, unconstrained arrays are OK
2947 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2957 when Attribute_Compose
=>
2958 Check_Floating_Point_Type_2
;
2959 Set_Etype
(N
, P_Base_Type
);
2960 Resolve
(E1
, P_Base_Type
);
2961 Resolve
(E2
, Any_Integer
);
2967 when Attribute_Constrained
=>
2969 Set_Etype
(N
, Standard_Boolean
);
2971 -- Case from RM J.4(2) of constrained applied to private type
2973 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2974 Check_Restriction
(No_Obsolescent_Features
, P
);
2976 if Warn_On_Obsolescent_Feature
then
2978 ("constrained for private type is an " &
2979 "obsolescent feature (RM J.4)?j?", N
);
2982 -- If we are within an instance, the attribute must be legal
2983 -- because it was valid in the generic unit. Ditto if this is
2984 -- an inlining of a function declared in an instance.
2986 if In_Instance
or else In_Inlined_Body
then
2989 -- For sure OK if we have a real private type itself, but must
2990 -- be completed, cannot apply Constrained to incomplete type.
2992 elsif Is_Private_Type
(Entity
(P
)) then
2994 -- Note: this is one of the Annex J features that does not
2995 -- generate a warning from -gnatwj, since in fact it seems
2996 -- very useful, and is used in the GNAT runtime.
2998 Check_Not_Incomplete_Type
;
3002 -- Normal (non-obsolescent case) of application to object of
3003 -- a discriminated type.
3006 Check_Object_Reference
(P
);
3008 -- If N does not come from source, then we allow the
3009 -- the attribute prefix to be of a private type whose
3010 -- full type has discriminants. This occurs in cases
3011 -- involving expanded calls to stream attributes.
3013 if not Comes_From_Source
(N
) then
3014 P_Type
:= Underlying_Type
(P_Type
);
3017 -- Must have discriminants or be an access type designating
3018 -- a type with discriminants. If it is a classwide type it
3019 -- has unknown discriminants.
3021 if Has_Discriminants
(P_Type
)
3022 or else Has_Unknown_Discriminants
(P_Type
)
3024 (Is_Access_Type
(P_Type
)
3025 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3029 -- The rule given in 3.7.2 is part of static semantics, but the
3030 -- intent is clearly that it be treated as a legality rule, and
3031 -- rechecked in the visible part of an instance. Nevertheless
3032 -- the intent also seems to be it should legally apply to the
3033 -- actual of a formal with unknown discriminants, regardless of
3034 -- whether the actual has discriminants, in which case the value
3035 -- of the attribute is determined using the J.4 rules. This choice
3036 -- seems the most useful, and is compatible with existing tests.
3038 elsif In_Instance
then
3041 -- Also allow an object of a generic type if extensions allowed
3042 -- and allow this for any type at all. (this may be obsolete ???)
3044 elsif (Is_Generic_Type
(P_Type
)
3045 or else Is_Generic_Actual_Type
(P_Type
))
3046 and then Extensions_Allowed
3052 -- Fall through if bad prefix
3055 ("prefix of % attribute must be object of discriminated type");
3061 when Attribute_Copy_Sign
=>
3062 Check_Floating_Point_Type_2
;
3063 Set_Etype
(N
, P_Base_Type
);
3064 Resolve
(E1
, P_Base_Type
);
3065 Resolve
(E2
, P_Base_Type
);
3071 when Attribute_Count
=> Count
:
3080 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3083 if Ekind
(Ent
) /= E_Entry
then
3084 Error_Attr
("invalid entry name", N
);
3087 elsif Nkind
(P
) = N_Indexed_Component
then
3088 if not Is_Entity_Name
(Prefix
(P
))
3089 or else No
(Entity
(Prefix
(P
)))
3090 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3092 if Nkind
(Prefix
(P
)) = N_Selected_Component
3093 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3094 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3098 ("attribute % must apply to entry of current task", P
);
3101 Error_Attr
("invalid entry family name", P
);
3106 Ent
:= Entity
(Prefix
(P
));
3109 elsif Nkind
(P
) = N_Selected_Component
3110 and then Present
(Entity
(Selector_Name
(P
)))
3111 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3114 ("attribute % must apply to entry of current task", P
);
3117 Error_Attr
("invalid entry name", N
);
3121 for J
in reverse 0 .. Scope_Stack
.Last
loop
3122 S
:= Scope_Stack
.Table
(J
).Entity
;
3124 if S
= Scope
(Ent
) then
3125 if Nkind
(P
) = N_Expanded_Name
then
3126 Tsk
:= Entity
(Prefix
(P
));
3128 -- The prefix denotes either the task type, or else a
3129 -- single task whose task type is being analyzed.
3131 if (Is_Type
(Tsk
) and then Tsk
= S
)
3132 or else (not Is_Type
(Tsk
)
3133 and then Etype
(Tsk
) = S
3134 and then not (Comes_From_Source
(S
)))
3139 ("Attribute % must apply to entry of current task", N
);
3145 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3147 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3149 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3151 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3152 and then not Has_Completion
(Scope
(Ent
))
3154 Error_Attr
("attribute % can only be used inside body", N
);
3158 if Is_Overloaded
(P
) then
3160 Index
: Interp_Index
;
3164 Get_First_Interp
(P
, Index
, It
);
3165 while Present
(It
.Nam
) loop
3166 if It
.Nam
= Ent
then
3169 -- Ada 2005 (AI-345): Do not consider primitive entry
3170 -- wrappers generated for task or protected types.
3172 elsif Ada_Version
>= Ada_2005
3173 and then not Comes_From_Source
(It
.Nam
)
3178 Error_Attr
("ambiguous entry name", N
);
3181 Get_Next_Interp
(Index
, It
);
3186 Set_Etype
(N
, Universal_Integer
);
3189 -----------------------
3190 -- Default_Bit_Order --
3191 -----------------------
3193 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
3195 Check_Standard_Prefix
;
3197 if Bytes_Big_Endian
then
3199 Make_Integer_Literal
(Loc
, False_Value
));
3202 Make_Integer_Literal
(Loc
, True_Value
));
3205 Set_Etype
(N
, Universal_Integer
);
3206 Set_Is_Static_Expression
(N
);
3207 end Default_Bit_Order
;
3213 when Attribute_Definite
=>
3214 Legal_Formal_Attribute
;
3220 when Attribute_Delta
=>
3221 Check_Fixed_Point_Type_0
;
3222 Set_Etype
(N
, Universal_Real
);
3228 when Attribute_Denorm
=>
3229 Check_Floating_Point_Type_0
;
3230 Set_Etype
(N
, Standard_Boolean
);
3232 ---------------------
3233 -- Descriptor_Size --
3234 ---------------------
3236 when Attribute_Descriptor_Size
=>
3239 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3240 Error_Attr_P
("prefix of attribute % must denote a type");
3243 Set_Etype
(N
, Universal_Integer
);
3249 when Attribute_Digits
=>
3253 if not Is_Floating_Point_Type
(P_Type
)
3254 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3257 ("prefix of % attribute must be float or decimal type");
3260 Set_Etype
(N
, Universal_Integer
);
3266 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3268 when Attribute_Elab_Body |
3269 Attribute_Elab_Spec |
3270 Attribute_Elab_Subp_Body
=>
3273 Check_Unit_Name
(P
);
3274 Set_Etype
(N
, Standard_Void_Type
);
3276 -- We have to manually call the expander in this case to get
3277 -- the necessary expansion (normally attributes that return
3278 -- entities are not expanded).
3286 -- Shares processing with Elab_Body
3292 when Attribute_Elaborated
=>
3294 Check_Unit_Name
(P
);
3295 Set_Etype
(N
, Standard_Boolean
);
3301 when Attribute_Emax
=>
3302 Check_Floating_Point_Type_0
;
3303 Set_Etype
(N
, Universal_Integer
);
3309 when Attribute_Enabled
=>
3310 Check_Either_E0_Or_E1
;
3312 if Present
(E1
) then
3313 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3314 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3319 if Nkind
(P
) /= N_Identifier
then
3320 Error_Msg_N
("identifier expected (check name)", P
);
3321 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3322 Error_Msg_N
("& is not a recognized check name", P
);
3325 Set_Etype
(N
, Standard_Boolean
);
3331 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3333 if Present
(E1
) then
3335 Check_Discrete_Type
;
3336 Resolve
(E1
, P_Base_Type
);
3339 if not Is_Entity_Name
(P
)
3340 or else (not Is_Object
(Entity
(P
))
3341 and then Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3344 ("prefix of % attribute must be " &
3345 "discrete type/object or enum literal");
3349 Set_Etype
(N
, Universal_Integer
);
3356 when Attribute_Enum_Val
=> Enum_Val
: begin
3360 if not Is_Enumeration_Type
(P_Type
) then
3361 Error_Attr_P
("prefix of % attribute must be enumeration type");
3364 -- If the enumeration type has a standard representation, the effect
3365 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3367 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3369 Make_Attribute_Reference
(Loc
,
3370 Prefix
=> Relocate_Node
(Prefix
(N
)),
3371 Attribute_Name
=> Name_Val
,
3372 Expressions
=> New_List
(Relocate_Node
(E1
))));
3373 Analyze_And_Resolve
(N
, P_Base_Type
);
3375 -- Non-standard representation case (enumeration with holes)
3379 Resolve
(E1
, Any_Integer
);
3380 Set_Etype
(N
, P_Base_Type
);
3388 when Attribute_Epsilon
=>
3389 Check_Floating_Point_Type_0
;
3390 Set_Etype
(N
, Universal_Real
);
3396 when Attribute_Exponent
=>
3397 Check_Floating_Point_Type_1
;
3398 Set_Etype
(N
, Universal_Integer
);
3399 Resolve
(E1
, P_Base_Type
);
3405 when Attribute_External_Tag
=>
3409 Set_Etype
(N
, Standard_String
);
3411 if not Is_Tagged_Type
(P_Type
) then
3412 Error_Attr_P
("prefix of % attribute must be tagged");
3419 when Attribute_Fast_Math
=>
3420 Check_Standard_Prefix
;
3421 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3427 when Attribute_First
=>
3428 Check_Array_Or_Scalar_Type
;
3429 Bad_Attribute_For_Predicate
;
3435 when Attribute_First_Bit
=>
3437 Set_Etype
(N
, Universal_Integer
);
3443 when Attribute_First_Valid
=>
3444 Check_First_Last_Valid
;
3445 Set_Etype
(N
, P_Type
);
3451 when Attribute_Fixed_Value
=>
3453 Check_Fixed_Point_Type
;
3454 Resolve
(E1
, Any_Integer
);
3455 Set_Etype
(N
, P_Base_Type
);
3461 when Attribute_Floor
=>
3462 Check_Floating_Point_Type_1
;
3463 Set_Etype
(N
, P_Base_Type
);
3464 Resolve
(E1
, P_Base_Type
);
3470 when Attribute_Fore
=>
3471 Check_Fixed_Point_Type_0
;
3472 Set_Etype
(N
, Universal_Integer
);
3478 when Attribute_Fraction
=>
3479 Check_Floating_Point_Type_1
;
3480 Set_Etype
(N
, P_Base_Type
);
3481 Resolve
(E1
, P_Base_Type
);
3487 when Attribute_From_Any
=>
3489 Check_PolyORB_Attribute
;
3490 Set_Etype
(N
, P_Base_Type
);
3492 -----------------------
3493 -- Has_Access_Values --
3494 -----------------------
3496 when Attribute_Has_Access_Values
=>
3499 Set_Etype
(N
, Standard_Boolean
);
3501 ----------------------
3502 -- Has_Same_Storage --
3503 ----------------------
3505 when Attribute_Has_Same_Storage
=>
3508 -- The arguments must be objects of any type
3510 Analyze_And_Resolve
(P
);
3511 Analyze_And_Resolve
(E1
);
3512 Check_Object_Reference
(P
);
3513 Check_Object_Reference
(E1
);
3514 Set_Etype
(N
, Standard_Boolean
);
3516 -----------------------
3517 -- Has_Tagged_Values --
3518 -----------------------
3520 when Attribute_Has_Tagged_Values
=>
3523 Set_Etype
(N
, Standard_Boolean
);
3525 -----------------------
3526 -- Has_Discriminants --
3527 -----------------------
3529 when Attribute_Has_Discriminants
=>
3530 Legal_Formal_Attribute
;
3536 when Attribute_Identity
=>
3540 if Etype
(P
) = Standard_Exception_Type
then
3541 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3543 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
3544 -- interface class-wide types.
3546 elsif Is_Task_Type
(Etype
(P
))
3547 or else (Is_Access_Type
(Etype
(P
))
3548 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3549 or else (Ada_Version
>= Ada_2005
3550 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3551 and then Is_Interface
(Etype
(P
))
3552 and then Is_Task_Interface
(Etype
(P
)))
3555 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3558 if Ada_Version
>= Ada_2005
then
3560 ("prefix of % attribute must be an exception, a " &
3561 "task or a task interface class-wide object");
3564 ("prefix of % attribute must be a task or an exception");
3572 when Attribute_Image
=> Image
:
3574 Check_SPARK_05_Restriction_On_Attribute
;
3576 Set_Etype
(N
, Standard_String
);
3578 if Is_Real_Type
(P_Type
) then
3579 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3580 Error_Msg_Name_1
:= Aname
;
3582 ("(Ada 83) % attribute not allowed for real types", N
);
3586 if Is_Enumeration_Type
(P_Type
) then
3587 Check_Restriction
(No_Enumeration_Maps
, N
);
3591 Resolve
(E1
, P_Base_Type
);
3593 Validate_Non_Static_Attribute_Function_Call
;
3595 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
3596 -- to avoid giving a duplicate message for Img expanded into Image.
3598 if Restriction_Check_Required
(No_Fixed_IO
)
3599 and then Comes_From_Source
(N
)
3600 and then Is_Fixed_Point_Type
(P_Type
)
3602 Check_Restriction
(No_Fixed_IO
, P
);
3610 when Attribute_Img
=> Img
:
3613 Set_Etype
(N
, Standard_String
);
3615 if not Is_Scalar_Type
(P_Type
)
3616 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3619 ("prefix of % attribute must be scalar object name");
3624 -- Check restriction No_Fixed_IO
3626 if Restriction_Check_Required
(No_Fixed_IO
)
3627 and then Is_Fixed_Point_Type
(P_Type
)
3629 Check_Restriction
(No_Fixed_IO
, P
);
3637 when Attribute_Input
=>
3639 Check_Stream_Attribute
(TSS_Stream_Input
);
3640 Set_Etype
(N
, P_Base_Type
);
3646 when Attribute_Integer_Value
=>
3649 Resolve
(E1
, Any_Fixed
);
3651 -- Signal an error if argument type is not a specific fixed-point
3652 -- subtype. An error has been signalled already if the argument
3653 -- was not of a fixed-point type.
3655 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3656 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3659 Set_Etype
(N
, P_Base_Type
);
3665 when Attribute_Invalid_Value
=>
3668 Set_Etype
(N
, P_Base_Type
);
3669 Invalid_Value_Used
:= True;
3675 when Attribute_Large
=>
3678 Set_Etype
(N
, Universal_Real
);
3684 when Attribute_Last
=>
3685 Check_Array_Or_Scalar_Type
;
3686 Bad_Attribute_For_Predicate
;
3692 when Attribute_Last_Bit
=>
3694 Set_Etype
(N
, Universal_Integer
);
3700 when Attribute_Last_Valid
=>
3701 Check_First_Last_Valid
;
3702 Set_Etype
(N
, P_Type
);
3708 when Attribute_Leading_Part
=>
3709 Check_Floating_Point_Type_2
;
3710 Set_Etype
(N
, P_Base_Type
);
3711 Resolve
(E1
, P_Base_Type
);
3712 Resolve
(E2
, Any_Integer
);
3718 when Attribute_Length
=>
3720 Set_Etype
(N
, Universal_Integer
);
3726 when Attribute_Library_Level
=>
3729 if not Is_Entity_Name
(P
) then
3730 Error_Attr_P
("prefix of % attribute must be an entity name");
3733 if not Inside_A_Generic
then
3734 Set_Boolean_Result
(N
,
3735 Is_Library_Level_Entity
(Entity
(P
)));
3738 Set_Etype
(N
, Standard_Boolean
);
3744 when Attribute_Lock_Free
=>
3746 Set_Etype
(N
, Standard_Boolean
);
3748 if not Is_Protected_Type
(P_Type
) then
3750 ("prefix of % attribute must be a protected object");
3757 when Attribute_Loop_Entry
=> Loop_Entry
: declare
3758 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
3759 -- Inspect the prefix for any uses of entities declared within the
3760 -- related loop. Loop_Id denotes the loop identifier.
3762 --------------------------------
3763 -- Check_References_In_Prefix --
3764 --------------------------------
3766 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
3767 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
3769 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
3770 -- Determine whether a reference mentions an entity declared
3771 -- within the related loop.
3773 function Declared_Within
(Nod
: Node_Id
) return Boolean;
3774 -- Determine whether Nod appears in the subtree of Loop_Decl
3776 ---------------------
3777 -- Check_Reference --
3778 ---------------------
3780 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
3782 if Nkind
(Nod
) = N_Identifier
3783 and then Present
(Entity
(Nod
))
3784 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
3787 ("prefix of attribute % cannot reference local entities",
3793 end Check_Reference
;
3795 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
3797 ---------------------
3798 -- Declared_Within --
3799 ---------------------
3801 function Declared_Within
(Nod
: Node_Id
) return Boolean is
3806 while Present
(Stmt
) loop
3807 if Stmt
= Loop_Decl
then
3810 -- Prevent the search from going too far
3812 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3816 Stmt
:= Parent
(Stmt
);
3820 end Declared_Within
;
3822 -- Start of processing for Check_Prefix_For_Local_References
3825 Check_References
(P
);
3826 end Check_References_In_Prefix
;
3830 Context
: constant Node_Id
:= Parent
(N
);
3832 Enclosing_Loop
: Node_Id
;
3833 Loop_Id
: Entity_Id
:= Empty
;
3836 Enclosing_Pragma
: Node_Id
:= Empty
;
3838 -- Start of processing for Loop_Entry
3843 -- Set the type of the attribute now to ensure the successfull
3844 -- continuation of analysis even if the attribute is misplaced.
3846 Set_Etype
(Attr
, P_Type
);
3848 -- Attribute 'Loop_Entry may appear in several flavors:
3850 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3851 -- nearest enclosing loop.
3853 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3854 -- attribute may be related to a loop denoted by label Expr or
3855 -- the prefix may denote an array object and Expr may act as an
3856 -- indexed component.
3858 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3859 -- to the nearest enclosing loop, all expressions are part of
3860 -- an indexed component.
3862 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3863 -- denotes, the attribute may be related to a loop denoted by
3864 -- label Expr or the prefix may denote a multidimensional array
3865 -- array object and Expr along with the rest of the expressions
3866 -- may act as indexed components.
3868 -- Regardless of variations, the attribute reference does not have an
3869 -- expression list. Instead, all available expressions are stored as
3870 -- indexed components.
3872 -- When the attribute is part of an indexed component, find the first
3873 -- expression as it will determine the semantics of 'Loop_Entry.
3875 if Nkind
(Context
) = N_Indexed_Component
then
3876 E1
:= First
(Expressions
(Context
));
3879 -- The attribute reference appears in the following form:
3881 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3883 -- In this case, the loop name is omitted and no rewriting is
3886 if Present
(E2
) then
3889 -- The form of the attribute is:
3891 -- Prefix'Loop_Entry (Expr) [(...)]
3893 -- If Expr denotes a loop entry, the whole attribute and indexed
3894 -- component will have to be rewritten to reflect this relation.
3897 pragma Assert
(Present
(E1
));
3899 -- Do not expand the expression as it may have side effects.
3900 -- Simply preanalyze to determine whether it is a loop name or
3903 Preanalyze_And_Resolve
(E1
);
3905 if Is_Entity_Name
(E1
)
3906 and then Present
(Entity
(E1
))
3907 and then Ekind
(Entity
(E1
)) = E_Loop
3909 Loop_Id
:= Entity
(E1
);
3911 -- Transform the attribute and enclosing indexed component
3913 Set_Expressions
(N
, Expressions
(Context
));
3914 Rewrite
(Context
, N
);
3915 Set_Etype
(Context
, P_Type
);
3922 -- The prefix must denote an object
3924 if not Is_Object_Reference
(P
) then
3925 Error_Attr_P
("prefix of attribute % must denote an object");
3928 -- The prefix cannot be of a limited type because the expansion of
3929 -- Loop_Entry must create a constant initialized by the evaluated
3932 if Is_Limited_View
(Etype
(P
)) then
3933 Error_Attr_P
("prefix of attribute % cannot be limited");
3936 -- Climb the parent chain to verify the location of the attribute and
3937 -- find the enclosing loop.
3940 while Present
(Stmt
) loop
3942 -- Locate the corresponding enclosing pragma. Note that in the
3943 -- case of Assert[And_Cut] and Assume, we have already checked
3944 -- that the pragma appears in an appropriate loop location.
3946 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
3947 and then Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
3948 Name_Loop_Invariant
,
3951 Name_Assert_And_Cut
,
3954 Enclosing_Pragma
:= Original_Node
(Stmt
);
3956 -- Locate the enclosing loop (if any). Note that Ada 2012 array
3957 -- iteration may be expanded into several nested loops, we are
3958 -- interested in the outermost one which has the loop identifier.
3960 elsif Nkind
(Stmt
) = N_Loop_Statement
3961 and then Present
(Identifier
(Stmt
))
3963 Enclosing_Loop
:= Stmt
;
3965 -- The original attribute reference may lack a loop name. Use
3966 -- the name of the enclosing loop because it is the related
3969 if No
(Loop_Id
) then
3970 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
3975 -- Prevent the search from going too far
3977 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3981 Stmt
:= Parent
(Stmt
);
3984 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
3985 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
3986 -- purpose if they appear in an appropriate location in a loop,
3987 -- which was already checked by the top level pragma circuit).
3989 if No
(Enclosing_Pragma
) then
3990 Error_Attr
("attribute% must appear within appropriate pragma", N
);
3993 -- A Loop_Entry that applies to a given loop statement must not
3994 -- appear within a body of accept statement, if this construct is
3995 -- itself enclosed by the given loop statement.
3997 for Index
in reverse 0 .. Scope_Stack
.Last
loop
3998 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4000 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4002 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4006 ("attribute % cannot appear in body or accept statement", N
);
4011 -- The prefix cannot mention entities declared within the related
4012 -- loop because they will not be visible once the prefix is moved
4013 -- outside the loop.
4015 Check_References_In_Prefix
(Loop_Id
);
4017 -- The prefix must denote a static entity if the pragma does not
4018 -- apply to the innermost enclosing loop statement, or if it appears
4019 -- within a potentially unevaluated epxression.
4021 if Is_Entity_Name
(P
)
4022 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4026 elsif Present
(Enclosing_Loop
)
4027 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
4030 ("prefix of attribute % that applies to outer loop must denote "
4033 elsif Is_Potentially_Unevaluated
(P
) then
4037 -- Replace the Loop_Entry attribute reference by its prefix if the
4038 -- related pragma is ignored. This transformation is OK with respect
4039 -- to typing because Loop_Entry's type is that of its prefix. This
4040 -- early transformation also avoids the generation of a useless loop
4043 if Is_Ignored
(Enclosing_Pragma
) then
4044 Rewrite
(N
, Relocate_Node
(P
));
4047 Preanalyze_And_Resolve
(P
);
4054 when Attribute_Machine
=>
4055 Check_Floating_Point_Type_1
;
4056 Set_Etype
(N
, P_Base_Type
);
4057 Resolve
(E1
, P_Base_Type
);
4063 when Attribute_Machine_Emax
=>
4064 Check_Floating_Point_Type_0
;
4065 Set_Etype
(N
, Universal_Integer
);
4071 when Attribute_Machine_Emin
=>
4072 Check_Floating_Point_Type_0
;
4073 Set_Etype
(N
, Universal_Integer
);
4075 ----------------------
4076 -- Machine_Mantissa --
4077 ----------------------
4079 when Attribute_Machine_Mantissa
=>
4080 Check_Floating_Point_Type_0
;
4081 Set_Etype
(N
, Universal_Integer
);
4083 -----------------------
4084 -- Machine_Overflows --
4085 -----------------------
4087 when Attribute_Machine_Overflows
=>
4090 Set_Etype
(N
, Standard_Boolean
);
4096 when Attribute_Machine_Radix
=>
4099 Set_Etype
(N
, Universal_Integer
);
4101 ----------------------
4102 -- Machine_Rounding --
4103 ----------------------
4105 when Attribute_Machine_Rounding
=>
4106 Check_Floating_Point_Type_1
;
4107 Set_Etype
(N
, P_Base_Type
);
4108 Resolve
(E1
, P_Base_Type
);
4110 --------------------
4111 -- Machine_Rounds --
4112 --------------------
4114 when Attribute_Machine_Rounds
=>
4117 Set_Etype
(N
, Standard_Boolean
);
4123 when Attribute_Machine_Size
=>
4126 Check_Not_Incomplete_Type
;
4127 Set_Etype
(N
, Universal_Integer
);
4133 when Attribute_Mantissa
=>
4136 Set_Etype
(N
, Universal_Integer
);
4142 when Attribute_Max
=>
4145 ----------------------------------
4146 -- Max_Alignment_For_Allocation --
4147 ----------------------------------
4149 when Attribute_Max_Size_In_Storage_Elements
=>
4150 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4152 ----------------------------------
4153 -- Max_Size_In_Storage_Elements --
4154 ----------------------------------
4156 when Attribute_Max_Alignment_For_Allocation
=>
4157 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4159 -----------------------
4160 -- Maximum_Alignment --
4161 -----------------------
4163 when Attribute_Maximum_Alignment
=>
4164 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4166 --------------------
4167 -- Mechanism_Code --
4168 --------------------
4170 when Attribute_Mechanism_Code
=>
4171 if not Is_Entity_Name
(P
)
4172 or else not Is_Subprogram
(Entity
(P
))
4174 Error_Attr_P
("prefix of % attribute must be subprogram");
4177 Check_Either_E0_Or_E1
;
4179 if Present
(E1
) then
4180 Resolve
(E1
, Any_Integer
);
4181 Set_Etype
(E1
, Standard_Integer
);
4183 if not Is_OK_Static_Expression
(E1
) then
4184 Flag_Non_Static_Expr
4185 ("expression for parameter number must be static!", E1
);
4188 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4189 or else UI_To_Int
(Intval
(E1
)) < 0
4191 Error_Attr
("invalid parameter number for % attribute", E1
);
4195 Set_Etype
(N
, Universal_Integer
);
4201 when Attribute_Min
=>
4208 when Attribute_Mod
=>
4210 -- Note: this attribute is only allowed in Ada 2005 mode, but
4211 -- we do not need to test that here, since Mod is only recognized
4212 -- as an attribute name in Ada 2005 mode during the parse.
4215 Check_Modular_Integer_Type
;
4216 Resolve
(E1
, Any_Integer
);
4217 Set_Etype
(N
, P_Base_Type
);
4223 when Attribute_Model
=>
4224 Check_Floating_Point_Type_1
;
4225 Set_Etype
(N
, P_Base_Type
);
4226 Resolve
(E1
, P_Base_Type
);
4232 when Attribute_Model_Emin
=>
4233 Check_Floating_Point_Type_0
;
4234 Set_Etype
(N
, Universal_Integer
);
4240 when Attribute_Model_Epsilon
=>
4241 Check_Floating_Point_Type_0
;
4242 Set_Etype
(N
, Universal_Real
);
4244 --------------------
4245 -- Model_Mantissa --
4246 --------------------
4248 when Attribute_Model_Mantissa
=>
4249 Check_Floating_Point_Type_0
;
4250 Set_Etype
(N
, Universal_Integer
);
4256 when Attribute_Model_Small
=>
4257 Check_Floating_Point_Type_0
;
4258 Set_Etype
(N
, Universal_Real
);
4264 when Attribute_Modulus
=>
4266 Check_Modular_Integer_Type
;
4267 Set_Etype
(N
, Universal_Integer
);
4269 --------------------
4270 -- Null_Parameter --
4271 --------------------
4273 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4274 Parnt
: constant Node_Id
:= Parent
(N
);
4275 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4277 procedure Bad_Null_Parameter
(Msg
: String);
4278 -- Used if bad Null parameter attribute node is found. Issues
4279 -- given error message, and also sets the type to Any_Type to
4280 -- avoid blowups later on from dealing with a junk node.
4282 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4283 -- Called to check that Proc_Ent is imported subprogram
4285 ------------------------
4286 -- Bad_Null_Parameter --
4287 ------------------------
4289 procedure Bad_Null_Parameter
(Msg
: String) is
4291 Error_Msg_N
(Msg
, N
);
4292 Set_Etype
(N
, Any_Type
);
4293 end Bad_Null_Parameter
;
4295 ----------------------
4296 -- Must_Be_Imported --
4297 ----------------------
4299 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4300 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4303 -- Ignore check if procedure not frozen yet (we will get
4304 -- another chance when the default parameter is reanalyzed)
4306 if not Is_Frozen
(Pent
) then
4309 elsif not Is_Imported
(Pent
) then
4311 ("Null_Parameter can only be used with imported subprogram");
4316 end Must_Be_Imported
;
4318 -- Start of processing for Null_Parameter
4323 Set_Etype
(N
, P_Type
);
4325 -- Case of attribute used as default expression
4327 if Nkind
(Parnt
) = N_Parameter_Specification
then
4328 Must_Be_Imported
(Defining_Entity
(GParnt
));
4330 -- Case of attribute used as actual for subprogram (positional)
4332 elsif Nkind
(Parnt
) in N_Subprogram_Call
4333 and then Is_Entity_Name
(Name
(Parnt
))
4335 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4337 -- Case of attribute used as actual for subprogram (named)
4339 elsif Nkind
(Parnt
) = N_Parameter_Association
4340 and then Nkind
(GParnt
) in N_Subprogram_Call
4341 and then Is_Entity_Name
(Name
(GParnt
))
4343 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4345 -- Not an allowed case
4349 ("Null_Parameter must be actual or default parameter");
4357 when Attribute_Object_Size
=>
4360 Check_Not_Incomplete_Type
;
4361 Set_Etype
(N
, Universal_Integer
);
4367 when Attribute_Old
=> Old
: declare
4368 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4369 -- Inspect the contents of the prefix and detect illegal uses of a
4370 -- nested 'Old, attribute 'Result or a use of an entity declared in
4371 -- the related postcondition expression. Subp_Id is the subprogram to
4372 -- which the related postcondition applies.
4374 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
);
4375 -- Perform various semantic checks related to the placement of the
4376 -- attribute in pragma Contract_Cases.
4378 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
);
4379 -- Perform various semantic checks related to the placement of the
4380 -- attribute in pragma Contract_Cases.
4382 --------------------------------
4383 -- Check_References_In_Prefix --
4384 --------------------------------
4386 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4387 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4388 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4389 -- and perform the appropriate semantic check.
4391 ---------------------
4392 -- Check_Reference --
4393 ---------------------
4395 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4397 -- Attributes 'Old and 'Result cannot appear in the prefix of
4398 -- another attribute 'Old.
4400 if Nkind
(Nod
) = N_Attribute_Reference
4401 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4404 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4405 Error_Msg_Name_2
:= Name_Old
;
4407 ("attribute % cannot appear in the prefix of attribute %",
4411 -- Entities mentioned within the prefix of attribute 'Old must
4412 -- be global to the related postcondition. If this is not the
4413 -- case, then the scope of the local entity is nested within
4414 -- that of the subprogram.
4416 elsif Nkind
(Nod
) = N_Identifier
4417 and then Present
(Entity
(Nod
))
4418 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4421 ("prefix of attribute % cannot reference local entities",
4427 end Check_Reference
;
4429 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4431 -- Start of processing for Check_References_In_Prefix
4434 Check_References
(P
);
4435 end Check_References_In_Prefix
;
4437 ---------------------------------
4438 -- Check_Use_In_Contract_Cases --
4439 ---------------------------------
4441 procedure Check_Use_In_Contract_Cases
(Prag
: Node_Id
) is
4442 Cases
: constant Node_Id
:=
4444 (First
(Pragma_Argument_Associations
(Prag
)));
4448 -- Climb the parent chain to reach the top of the expression where
4449 -- attribute 'Old resides.
4452 while Parent
(Parent
(Expr
)) /= Cases
loop
4453 Expr
:= Parent
(Expr
);
4456 -- Ensure that the obtained expression is the consequence of a
4457 -- contract case as this is the only postcondition-like part of
4458 -- the pragma. Otherwise, attribute 'Old appears in the condition
4459 -- of a contract case. Emit an error since this is not a
4460 -- postcondition-like context. (SPARK RM 6.1.3(2))
4462 if Expr
/= Expression
(Parent
(Expr
)) then
4464 ("attribute % cannot appear in the condition "
4465 & "of a contract case", P
);
4467 end Check_Use_In_Contract_Cases
;
4469 ----------------------------
4470 -- Check_Use_In_Test_Case --
4471 ----------------------------
4473 procedure Check_Use_In_Test_Case
(Prag
: Node_Id
) is
4474 Ensures
: constant Node_Id
:= Get_Ensures_From_CTC_Pragma
(Prag
);
4478 -- Climb the parent chain to reach the top of the Ensures part of
4479 -- pragma Test_Case.
4482 while Expr
/= Prag
loop
4483 if Expr
= Ensures
then
4487 Expr
:= Parent
(Expr
);
4490 -- If we get there, then attribute 'Old appears in the requires
4491 -- expression of pragma Test_Case which is not a postcondition-
4495 ("attribute % cannot appear in the requires expression of a "
4497 end Check_Use_In_Test_Case
;
4502 -- The enclosing scope, excluding loops for quantified expressions.
4503 -- During analysis, it is the postcondition subprogram. During
4504 -- pre-analysis, it is the scope of the subprogram declaration.
4507 -- During pre-analysis, Prag is the enclosing pragma node if any
4509 -- Start of processing for Old
4514 -- Find enclosing scopes, excluding loops
4516 CS
:= Current_Scope
;
4517 while Ekind
(CS
) = E_Loop
loop
4521 -- A Contract_Cases, Postcondition or Test_Case pragma is in the
4522 -- process of being preanalyzed. Perform the semantic checks now
4523 -- before the pragma is relocated and/or expanded.
4525 -- For a generic subprogram, postconditions are preanalyzed as well
4526 -- for name capture, and still appear within an aspect spec.
4528 if In_Spec_Expression
or Inside_A_Generic
then
4530 while Present
(Prag
)
4531 and then not Nkind_In
(Prag
, N_Aspect_Specification
,
4532 N_Function_Specification
,
4534 N_Procedure_Specification
,
4537 Prag
:= Parent
(Prag
);
4540 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4541 -- corresponding pragma. Don't issue errors when analyzing aspect.
4543 if Nkind
(Prag
) = N_Aspect_Specification
4544 and then Chars
(Identifier
(Prag
)) = Name_Post
4548 -- In all other cases the related context must be a pragma
4550 elsif Nkind
(Prag
) /= N_Pragma
then
4551 Error_Attr
("% attribute can only appear in postcondition", P
);
4553 -- Verify the placement of the attribute with respect to the
4557 case Get_Pragma_Id
(Prag
) is
4558 when Pragma_Contract_Cases
=>
4559 Check_Use_In_Contract_Cases
(Prag
);
4561 when Pragma_Postcondition | Pragma_Refined_Post
=>
4564 when Pragma_Test_Case
=>
4565 Check_Use_In_Test_Case
(Prag
);
4569 ("% attribute can only appear in postcondition", P
);
4573 -- Check the legality of attribute 'Old when it appears inside pragma
4574 -- Refined_Post. These specialized checks are required only when code
4575 -- generation is disabled. In the general case pragma Refined_Post is
4576 -- transformed into pragma Check by Process_PPCs which in turn is
4577 -- relocated to procedure _Postconditions. From then on the legality
4578 -- of 'Old is determined as usual.
4580 elsif not Expander_Active
and then In_Refined_Post
then
4581 Preanalyze_And_Resolve
(P
);
4582 Check_References_In_Prefix
(CS
);
4583 P_Type
:= Etype
(P
);
4584 Set_Etype
(N
, P_Type
);
4586 if Is_Limited_Type
(P_Type
) then
4587 Error_Attr
("attribute % cannot apply to limited objects", P
);
4590 if Is_Entity_Name
(P
)
4591 and then Is_Constant_Object
(Entity
(P
))
4594 ("??attribute Old applied to constant has no effect", P
);
4599 -- Body case, where we must be inside a generated _Postconditions
4600 -- procedure, or else the attribute use is definitely misplaced. The
4601 -- postcondition itself may have generated transient scopes, and is
4602 -- not necessarily the current one.
4605 while Present
(CS
) and then CS
/= Standard_Standard
loop
4606 if Chars
(CS
) = Name_uPostconditions
then
4613 if Chars
(CS
) /= Name_uPostconditions
then
4614 Error_Attr
("% attribute can only appear in postcondition", P
);
4618 -- If the attribute reference is generated for a Requires clause,
4619 -- then no expressions follow. Otherwise it is a primary, in which
4620 -- case, if expressions follow, the attribute reference must be an
4621 -- indexable object, so rewrite the node accordingly.
4623 if Present
(E1
) then
4625 Make_Indexed_Component
(Loc
,
4627 Make_Attribute_Reference
(Loc
,
4628 Prefix
=> Relocate_Node
(Prefix
(N
)),
4629 Attribute_Name
=> Name_Old
),
4630 Expressions
=> Expressions
(N
)));
4638 -- Prefix has not been analyzed yet, and its full analysis will take
4639 -- place during expansion (see below).
4641 Preanalyze_And_Resolve
(P
);
4642 Check_References_In_Prefix
(CS
);
4643 P_Type
:= Etype
(P
);
4644 Set_Etype
(N
, P_Type
);
4646 if Is_Limited_Type
(P_Type
) then
4647 Error_Attr
("attribute % cannot apply to limited objects", P
);
4650 if Is_Entity_Name
(P
)
4651 and then Is_Constant_Object
(Entity
(P
))
4654 ("??attribute Old applied to constant has no effect", P
);
4657 -- Check that the prefix of 'Old is an entity when it may be
4658 -- potentially unevaluated (6.1.1 (27/3)).
4661 and then Is_Potentially_Unevaluated
(N
)
4662 and then not Is_Entity_Name
(P
)
4667 -- The attribute appears within a pre/postcondition, but refers to
4668 -- an entity in the enclosing subprogram. If it is a component of
4669 -- a formal its expansion might generate actual subtypes that may
4670 -- be referenced in an inner context, and which must be elaborated
4671 -- within the subprogram itself. If the prefix includes a function
4672 -- call it may involve finalization actions that should only be
4673 -- inserted when the attribute has been rewritten as a declarations.
4674 -- As a result, if the prefix is not a simple name we create
4675 -- a declaration for it now, and insert it at the start of the
4676 -- enclosing subprogram. This is properly an expansion activity
4677 -- but it has to be performed now to prevent out-of-order issues.
4679 -- This expansion is both harmful and not needed in SPARK mode, since
4680 -- the formal verification backend relies on the types of nodes
4681 -- (hence is not robust w.r.t. a change to base type here), and does
4682 -- not suffer from the out-of-order issue described above. Thus, this
4683 -- expansion is skipped in SPARK mode.
4685 if not Is_Entity_Name
(P
) and then not GNATprove_Mode
then
4686 P_Type
:= Base_Type
(P_Type
);
4687 Set_Etype
(N
, P_Type
);
4688 Set_Etype
(P
, P_Type
);
4689 Analyze_Dimension
(N
);
4694 ----------------------
4695 -- Overlaps_Storage --
4696 ----------------------
4698 when Attribute_Overlaps_Storage
=>
4701 -- Both arguments must be objects of any type
4703 Analyze_And_Resolve
(P
);
4704 Analyze_And_Resolve
(E1
);
4705 Check_Object_Reference
(P
);
4706 Check_Object_Reference
(E1
);
4707 Set_Etype
(N
, Standard_Boolean
);
4713 when Attribute_Output
=>
4715 Check_Stream_Attribute
(TSS_Stream_Output
);
4716 Set_Etype
(N
, Standard_Void_Type
);
4717 Resolve
(N
, Standard_Void_Type
);
4723 when Attribute_Partition_ID
=> Partition_Id
:
4727 if P_Type
/= Any_Type
then
4728 if not Is_Library_Level_Entity
(Entity
(P
)) then
4730 ("prefix of % attribute must be library-level entity");
4732 -- The defining entity of prefix should not be declared inside a
4733 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4735 elsif Is_Entity_Name
(P
)
4736 and then Is_Pure
(Entity
(P
))
4738 Error_Attr_P
("prefix of% attribute must not be declared pure");
4742 Set_Etype
(N
, Universal_Integer
);
4745 -------------------------
4746 -- Passed_By_Reference --
4747 -------------------------
4749 when Attribute_Passed_By_Reference
=>
4752 Set_Etype
(N
, Standard_Boolean
);
4758 when Attribute_Pool_Address
=>
4760 Set_Etype
(N
, RTE
(RE_Address
));
4766 when Attribute_Pos
=>
4767 Check_Discrete_Type
;
4770 if Is_Boolean_Type
(P_Type
) then
4771 Error_Msg_Name_1
:= Aname
;
4772 Error_Msg_Name_2
:= Chars
(P_Type
);
4773 Check_SPARK_05_Restriction
4774 ("attribute% is not allowed for type%", P
);
4777 Resolve
(E1
, P_Base_Type
);
4778 Set_Etype
(N
, Universal_Integer
);
4784 when Attribute_Position
=>
4786 Set_Etype
(N
, Universal_Integer
);
4792 when Attribute_Pred
=>
4796 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4797 Error_Msg_Name_1
:= Aname
;
4798 Error_Msg_Name_2
:= Chars
(P_Type
);
4799 Check_SPARK_05_Restriction
4800 ("attribute% is not allowed for type%", P
);
4803 Resolve
(E1
, P_Base_Type
);
4804 Set_Etype
(N
, P_Base_Type
);
4806 -- Since Pred works on the base type, we normally do no check for the
4807 -- floating-point case, since the base type is unconstrained. But we
4808 -- make an exception in Check_Float_Overflow mode.
4810 if Is_Floating_Point_Type
(P_Type
) then
4811 if not Range_Checks_Suppressed
(P_Base_Type
) then
4812 Set_Do_Range_Check
(E1
);
4815 -- If not modular type, test for overflow check required
4818 if not Is_Modular_Integer_Type
(P_Type
)
4819 and then not Range_Checks_Suppressed
(P_Base_Type
)
4821 Enable_Range_Check
(E1
);
4829 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4831 when Attribute_Priority
=>
4832 if Ada_Version
< Ada_2005
then
4833 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4838 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4842 if Is_Protected_Type
(Etype
(P
))
4843 or else (Is_Access_Type
(Etype
(P
))
4844 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4846 Resolve
(P
, Etype
(P
));
4848 Error_Attr_P
("prefix of % attribute must be a protected object");
4851 Set_Etype
(N
, Standard_Integer
);
4853 -- Must be called from within a protected procedure or entry of the
4854 -- protected object.
4861 while S
/= Etype
(P
)
4862 and then S
/= Standard_Standard
4867 if S
= Standard_Standard
then
4868 Error_Attr
("the attribute % is only allowed inside protected "
4873 Validate_Non_Static_Attribute_Function_Call
;
4879 when Attribute_Range
=>
4880 Check_Array_Or_Scalar_Type
;
4881 Bad_Attribute_For_Predicate
;
4883 if Ada_Version
= Ada_83
4884 and then Is_Scalar_Type
(P_Type
)
4885 and then Comes_From_Source
(N
)
4888 ("(Ada 83) % attribute not allowed for scalar type", P
);
4895 when Attribute_Result
=> Result
: declare
4897 -- The enclosing scope, excluding loops for quantified expressions
4900 -- During analysis, CS is the postcondition subprogram and PS the
4901 -- source subprogram to which the postcondition applies. During
4902 -- pre-analysis, CS is the scope of the subprogram declaration.
4905 -- During pre-analysis, Prag is the enclosing pragma node if any
4908 -- Find the proper enclosing scope
4910 CS
:= Current_Scope
;
4911 while Present
(CS
) loop
4913 -- Skip generated loops
4915 if Ekind
(CS
) = E_Loop
then
4918 -- Skip the special _Parent scope generated to capture references
4919 -- to formals during the process of subprogram inlining.
4921 elsif Ekind
(CS
) = E_Function
4922 and then Chars
(CS
) = Name_uParent
4932 -- If the enclosing subprogram is always inlined, the enclosing
4933 -- postcondition will not be propagated to the expanded call.
4935 if not In_Spec_Expression
4936 and then Has_Pragma_Inline_Always
(PS
)
4937 and then Warn_On_Redundant_Constructs
4940 ("postconditions on inlined functions not enforced?r?", N
);
4943 -- If we are in the scope of a function and in Spec_Expression mode,
4944 -- this is likely the prescan of the postcondition (or contract case,
4945 -- or test case) pragma, and we just set the proper type. If there is
4946 -- an error it will be caught when the real Analyze call is done.
4948 if Ekind
(CS
) = E_Function
4949 and then In_Spec_Expression
4953 if Chars
(CS
) /= Chars
(P
) then
4954 Error_Msg_Name_1
:= Name_Result
;
4957 ("incorrect prefix for % attribute, expected &", P
, CS
);
4961 -- Check in postcondition, Test_Case or Contract_Cases of function
4964 while Present
(Prag
)
4965 and then not Nkind_In
(Prag
, N_Pragma
,
4966 N_Function_Specification
,
4967 N_Aspect_Specification
,
4970 Prag
:= Parent
(Prag
);
4973 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4974 -- corresponding pragma. Do not issue errors when analyzing the
4977 if Nkind
(Prag
) = N_Aspect_Specification
then
4980 -- Must have a pragma
4982 elsif Nkind
(Prag
) /= N_Pragma
then
4984 ("% attribute can only appear in postcondition of function",
4987 -- Processing depends on which pragma we have
4990 case Get_Pragma_Id
(Prag
) is
4992 when Pragma_Test_Case
=>
4994 Arg_Ens
: constant Node_Id
:=
4995 Get_Ensures_From_CTC_Pragma
(Prag
);
5000 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
5001 Arg
:= Parent
(Arg
);
5004 if Arg
/= Arg_Ens
then
5006 ("% attribute misplaced inside test case", P
);
5010 when Pragma_Contract_Cases
=>
5012 Aggr
: constant Node_Id
:=
5014 (Pragma_Argument_Associations
(Prag
)));
5020 and then Parent
(Parent
(Arg
)) /= Aggr
5022 Arg
:= Parent
(Arg
);
5025 -- At this point, Parent (Arg) should be a component
5026 -- association. Attribute Result is only allowed in
5027 -- the expression part of this association.
5029 if Nkind
(Parent
(Arg
)) /= N_Component_Association
5030 or else Arg
/= Expression
(Parent
(Arg
))
5033 ("% attribute misplaced inside contract cases",
5038 when Pragma_Postcondition | Pragma_Refined_Post
=>
5043 ("% attribute can only appear in postcondition "
5044 & "of function", P
);
5048 -- The attribute reference is a primary. If expressions follow,
5049 -- the attribute reference is really an indexable object, so
5050 -- rewrite and analyze as an indexed component.
5052 if Present
(E1
) then
5054 Make_Indexed_Component
(Loc
,
5056 Make_Attribute_Reference
(Loc
,
5057 Prefix
=> Relocate_Node
(Prefix
(N
)),
5058 Attribute_Name
=> Name_Result
),
5059 Expressions
=> Expressions
(N
)));
5064 Set_Etype
(N
, Etype
(CS
));
5066 -- If several functions with that name are visible, the intended
5067 -- one is the current scope.
5069 if Is_Overloaded
(P
) then
5071 Set_Is_Overloaded
(P
, False);
5074 -- Check the legality of attribute 'Result when it appears inside
5075 -- pragma Refined_Post. These specialized checks are required only
5076 -- when code generation is disabled. In the general case pragma
5077 -- Refined_Post is transformed into pragma Check by Process_PPCs
5078 -- which in turn is relocated to procedure _Postconditions. From
5079 -- then on the legality of 'Result is determined as usual.
5081 elsif not Expander_Active
and then In_Refined_Post
then
5082 PS
:= Current_Scope
;
5084 -- The prefix denotes the proper related function
5086 if Is_Entity_Name
(P
)
5087 and then Ekind
(Entity
(P
)) = E_Function
5088 and then Entity
(P
) = PS
5093 Error_Msg_Name_2
:= Chars
(PS
);
5094 Error_Attr
("incorrect prefix for % attribute, expected %", P
);
5097 Set_Etype
(N
, Etype
(PS
));
5099 -- Body case, where we must be inside a generated _Postconditions
5100 -- procedure, and the prefix must be on the scope stack, or else the
5101 -- attribute use is definitely misplaced. The postcondition itself
5102 -- may have generated transient scopes, and is not necessarily the
5106 while Present
(CS
) and then CS
/= Standard_Standard
loop
5107 if Chars
(CS
) = Name_uPostconditions
then
5116 if Chars
(CS
) = Name_uPostconditions
5117 and then Ekind
(PS
) = E_Function
5121 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
5122 and then Chars
(P
) = Chars
(PS
)
5126 -- Within an instance, the prefix designates the local renaming
5127 -- of the original generic.
5129 elsif Is_Entity_Name
(P
)
5130 and then Ekind
(Entity
(P
)) = E_Function
5131 and then Present
(Alias
(Entity
(P
)))
5132 and then Chars
(Alias
(Entity
(P
))) = Chars
(PS
)
5137 Error_Msg_Name_2
:= Chars
(PS
);
5139 ("incorrect prefix for % attribute, expected %", P
);
5142 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
5143 Analyze_And_Resolve
(N
, Etype
(PS
));
5147 ("% attribute can only appear in postcondition of function",
5157 when Attribute_Range_Length
=>
5159 Check_Discrete_Type
;
5160 Set_Etype
(N
, Universal_Integer
);
5166 when Attribute_Read
=>
5168 Check_Stream_Attribute
(TSS_Stream_Read
);
5169 Set_Etype
(N
, Standard_Void_Type
);
5170 Resolve
(N
, Standard_Void_Type
);
5171 Note_Possible_Modification
(E2
, Sure
=> True);
5177 when Attribute_Ref
=>
5181 if Nkind
(P
) /= N_Expanded_Name
5182 or else not Is_RTE
(P_Type
, RE_Address
)
5184 Error_Attr_P
("prefix of % attribute must be System.Address");
5187 Analyze_And_Resolve
(E1
, Any_Integer
);
5188 Set_Etype
(N
, RTE
(RE_Address
));
5194 when Attribute_Remainder
=>
5195 Check_Floating_Point_Type_2
;
5196 Set_Etype
(N
, P_Base_Type
);
5197 Resolve
(E1
, P_Base_Type
);
5198 Resolve
(E2
, P_Base_Type
);
5200 ---------------------
5201 -- Restriction_Set --
5202 ---------------------
5204 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5207 Unam
: Unit_Name_Type
;
5212 Check_System_Prefix
;
5214 -- No_Dependence case
5216 if Nkind
(E1
) = N_Parameter_Association
then
5217 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5218 U
:= Explicit_Actual_Parameter
(E1
);
5220 if not OK_No_Dependence_Unit_Name
(U
) then
5221 Set_Boolean_Result
(N
, False);
5225 -- See if there is an entry already in the table. That's the
5226 -- case in which we can return True.
5228 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5229 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5230 and then No_Dependences
.Table
(J
).Warn
= False
5232 Set_Boolean_Result
(N
, True);
5237 -- If not in the No_Dependence table, result is False
5239 Set_Boolean_Result
(N
, False);
5241 -- In this case, we must ensure that the binder will reject any
5242 -- other unit in the partition that sets No_Dependence for this
5243 -- unit. We do that by making an entry in the special table kept
5244 -- for this purpose (if the entry is not there already).
5246 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5248 for J
in Restriction_Set_Dependences
.First
..
5249 Restriction_Set_Dependences
.Last
5251 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5256 Restriction_Set_Dependences
.Append
(Unam
);
5258 -- Normal restriction case
5261 if Nkind
(E1
) /= N_Identifier
then
5262 Set_Boolean_Result
(N
, False);
5263 Error_Attr
("attribute % requires restriction identifier", E1
);
5266 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5268 if R
= Not_A_Restriction_Id
then
5269 Set_Boolean_Result
(N
, False);
5270 Error_Msg_Node_1
:= E1
;
5271 Error_Attr
("invalid restriction identifier &", E1
);
5273 elsif R
not in Partition_Boolean_Restrictions
then
5274 Set_Boolean_Result
(N
, False);
5275 Error_Msg_Node_1
:= E1
;
5277 ("& is not a boolean partition-wide restriction", E1
);
5280 if Restriction_Active
(R
) then
5281 Set_Boolean_Result
(N
, True);
5283 Check_Restriction
(R
, N
);
5284 Set_Boolean_Result
(N
, False);
5288 end Restriction_Set
;
5294 when Attribute_Round
=>
5296 Check_Decimal_Fixed_Point_Type
;
5297 Set_Etype
(N
, P_Base_Type
);
5299 -- Because the context is universal_real (3.5.10(12)) it is a
5300 -- legal context for a universal fixed expression. This is the
5301 -- only attribute whose functional description involves U_R.
5303 if Etype
(E1
) = Universal_Fixed
then
5305 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5306 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5307 Expression
=> Relocate_Node
(E1
));
5315 Resolve
(E1
, Any_Real
);
5321 when Attribute_Rounding
=>
5322 Check_Floating_Point_Type_1
;
5323 Set_Etype
(N
, P_Base_Type
);
5324 Resolve
(E1
, P_Base_Type
);
5330 when Attribute_Safe_Emax
=>
5331 Check_Floating_Point_Type_0
;
5332 Set_Etype
(N
, Universal_Integer
);
5338 when Attribute_Safe_First
=>
5339 Check_Floating_Point_Type_0
;
5340 Set_Etype
(N
, Universal_Real
);
5346 when Attribute_Safe_Large
=>
5349 Set_Etype
(N
, Universal_Real
);
5355 when Attribute_Safe_Last
=>
5356 Check_Floating_Point_Type_0
;
5357 Set_Etype
(N
, Universal_Real
);
5363 when Attribute_Safe_Small
=>
5366 Set_Etype
(N
, Universal_Real
);
5368 --------------------------
5369 -- Scalar_Storage_Order --
5370 --------------------------
5372 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5374 Ent
: Entity_Id
:= Empty
;
5380 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5382 -- In GNAT mode, the attribute applies to generic types as well
5383 -- as composite types, and for non-composite types always returns
5384 -- the default bit order for the target.
5386 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5387 and then not In_Instance
5390 ("prefix of % attribute must be record or array type");
5392 elsif not Is_Generic_Type
(P_Type
) then
5393 if Bytes_Big_Endian
then
5394 Ent
:= RTE
(RE_High_Order_First
);
5396 Ent
:= RTE
(RE_Low_Order_First
);
5400 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5401 Ent
:= RTE
(RE_High_Order_First
);
5404 Ent
:= RTE
(RE_Low_Order_First
);
5407 if Present
(Ent
) then
5408 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5411 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5414 -- Reset incorrect indication of staticness
5416 Set_Is_Static_Expression
(N
, False);
5417 end Scalar_Storage_Order
;
5423 when Attribute_Scale
=>
5425 Check_Decimal_Fixed_Point_Type
;
5426 Set_Etype
(N
, Universal_Integer
);
5432 when Attribute_Scaling
=>
5433 Check_Floating_Point_Type_2
;
5434 Set_Etype
(N
, P_Base_Type
);
5435 Resolve
(E1
, P_Base_Type
);
5441 when Attribute_Signed_Zeros
=>
5442 Check_Floating_Point_Type_0
;
5443 Set_Etype
(N
, Standard_Boolean
);
5449 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5453 -- If prefix is parameterless function call, rewrite and resolve
5456 if Is_Entity_Name
(P
)
5457 and then Ekind
(Entity
(P
)) = E_Function
5461 -- Similar processing for a protected function call
5463 elsif Nkind
(P
) = N_Selected_Component
5464 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5469 if Is_Object_Reference
(P
) then
5470 Check_Object_Reference
(P
);
5472 elsif Is_Entity_Name
(P
)
5473 and then (Is_Type
(Entity
(P
))
5474 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5478 elsif Nkind
(P
) = N_Type_Conversion
5479 and then not Comes_From_Source
(P
)
5483 -- Some other compilers allow dubious use of X'???'Size
5485 elsif Relaxed_RM_Semantics
5486 and then Nkind
(P
) = N_Attribute_Reference
5491 Error_Attr_P
("invalid prefix for % attribute");
5494 Check_Not_Incomplete_Type
;
5496 Set_Etype
(N
, Universal_Integer
);
5503 when Attribute_Small
=>
5506 Set_Etype
(N
, Universal_Real
);
5512 when Attribute_Storage_Pool |
5513 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5517 if Is_Access_Type
(P_Type
) then
5518 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5520 ("cannot use % attribute for access-to-subprogram type");
5523 -- Set appropriate entity
5525 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5526 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5528 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5531 if Attr_Id
= Attribute_Storage_Pool
then
5532 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5533 Name_Simple_Storage_Pool_Type
))
5535 Error_Msg_Name_1
:= Aname
;
5536 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5537 Error_Msg_N
("cannot use % attribute for type with simple "
5538 & "storage pool<<", N
);
5539 Error_Msg_N
("\Program_Error [<<", N
);
5542 (N
, Make_Raise_Program_Error
5543 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5546 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5548 -- In the Simple_Storage_Pool case, verify that the pool entity is
5549 -- actually of a simple storage pool type, and set the attribute's
5550 -- type to the pool object's type.
5553 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5554 Name_Simple_Storage_Pool_Type
))
5557 ("cannot use % attribute for type without simple " &
5561 Set_Etype
(N
, Etype
(Entity
(N
)));
5564 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5565 -- Storage_Pool since this attribute is not defined for such
5566 -- types (RM E.2.3(22)).
5568 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5571 Error_Attr_P
("prefix of % attribute must be access type");
5579 when Attribute_Storage_Size
=> Storage_Size
:
5583 if Is_Task_Type
(P_Type
) then
5584 Set_Etype
(N
, Universal_Integer
);
5586 -- Use with tasks is an obsolescent feature
5588 Check_Restriction
(No_Obsolescent_Features
, P
);
5590 elsif Is_Access_Type
(P_Type
) then
5591 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5593 ("cannot use % attribute for access-to-subprogram type");
5596 if Is_Entity_Name
(P
)
5597 and then Is_Type
(Entity
(P
))
5600 Set_Etype
(N
, Universal_Integer
);
5602 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5603 -- Storage_Size since this attribute is not defined for
5604 -- such types (RM E.2.3(22)).
5606 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5608 -- The prefix is allowed to be an implicit dereference of an
5609 -- access value designating a task.
5613 Set_Etype
(N
, Universal_Integer
);
5617 Error_Attr_P
("prefix of % attribute must be access or task type");
5625 when Attribute_Storage_Unit
=>
5626 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5632 when Attribute_Stream_Size
=>
5636 if Is_Entity_Name
(P
)
5637 and then Is_Elementary_Type
(Entity
(P
))
5639 Set_Etype
(N
, Universal_Integer
);
5641 Error_Attr_P
("invalid prefix for % attribute");
5648 when Attribute_Stub_Type
=>
5652 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5654 -- For a real RACW [sub]type, use corresponding stub type
5656 if not Is_Generic_Type
(P_Type
) then
5659 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5661 -- For a generic type (that has been marked as an RACW using the
5662 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5663 -- type. Note that if the actual is not a remote access type, the
5664 -- instantiation will fail.
5667 -- Note: we go to the underlying type here because the view
5668 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5672 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5677 ("prefix of% attribute must be remote access to classwide");
5684 when Attribute_Succ
=>
5688 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5689 Error_Msg_Name_1
:= Aname
;
5690 Error_Msg_Name_2
:= Chars
(P_Type
);
5691 Check_SPARK_05_Restriction
5692 ("attribute% is not allowed for type%", P
);
5695 Resolve
(E1
, P_Base_Type
);
5696 Set_Etype
(N
, P_Base_Type
);
5698 -- Since Pred works on the base type, we normally do no check for the
5699 -- floating-point case, since the base type is unconstrained. But we
5700 -- make an exception in Check_Float_Overflow mode.
5702 if Is_Floating_Point_Type
(P_Type
) then
5703 if not Range_Checks_Suppressed
(P_Base_Type
) then
5704 Set_Do_Range_Check
(E1
);
5707 -- If not modular type, test for overflow check required
5710 if not Is_Modular_Integer_Type
(P_Type
)
5711 and then not Range_Checks_Suppressed
(P_Base_Type
)
5713 Enable_Range_Check
(E1
);
5717 --------------------------------
5718 -- System_Allocator_Alignment --
5719 --------------------------------
5721 when Attribute_System_Allocator_Alignment
=>
5722 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5728 when Attribute_Tag
=> Tag
:
5733 if not Is_Tagged_Type
(P_Type
) then
5734 Error_Attr_P
("prefix of % attribute must be tagged");
5736 -- Next test does not apply to generated code why not, and what does
5737 -- the illegal reference mean???
5739 elsif Is_Object_Reference
(P
)
5740 and then not Is_Class_Wide_Type
(P_Type
)
5741 and then Comes_From_Source
(N
)
5744 ("% attribute can only be applied to objects " &
5745 "of class - wide type");
5748 -- The prefix cannot be an incomplete type. However, references to
5749 -- 'Tag can be generated when expanding interface conversions, and
5752 if Comes_From_Source
(N
) then
5753 Check_Not_Incomplete_Type
;
5756 -- Set appropriate type
5758 Set_Etype
(N
, RTE
(RE_Tag
));
5765 when Attribute_Target_Name
=> Target_Name
: declare
5766 TN
: constant String := Sdefault
.Target_Name
.all;
5770 Check_Standard_Prefix
;
5774 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
5779 Make_String_Literal
(Loc
,
5780 Strval
=> TN
(TN
'First .. TL
)));
5781 Analyze_And_Resolve
(N
, Standard_String
);
5782 Set_Is_Static_Expression
(N
, True);
5789 when Attribute_Terminated
=>
5791 Set_Etype
(N
, Standard_Boolean
);
5798 when Attribute_To_Address
=> To_Address
: declare
5804 Check_System_Prefix
;
5806 Generate_Reference
(RTE
(RE_Address
), P
);
5807 Analyze_And_Resolve
(E1
, Any_Integer
);
5808 Set_Etype
(N
, RTE
(RE_Address
));
5810 if Is_Static_Expression
(E1
) then
5811 Set_Is_Static_Expression
(N
, True);
5814 -- OK static expression case, check range and set appropriate type
5816 if Is_OK_Static_Expression
(E1
) then
5817 Val
:= Expr_Value
(E1
);
5819 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
5821 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
5823 Error_Attr
("address value out of range for % attribute", E1
);
5826 -- In most cases the expression is a numeric literal or some other
5827 -- address expression, but if it is a declared constant it may be
5828 -- of a compatible type that must be left on the node.
5830 if Is_Entity_Name
(E1
) then
5833 -- Set type to universal integer if negative
5836 Set_Etype
(E1
, Universal_Integer
);
5838 -- Otherwise set type to Unsigned_64 to accomodate max values
5841 Set_Etype
(E1
, Standard_Unsigned_64
);
5845 Set_Is_Static_Expression
(N
, True);
5852 when Attribute_To_Any
=>
5854 Check_PolyORB_Attribute
;
5855 Set_Etype
(N
, RTE
(RE_Any
));
5861 when Attribute_Truncation
=>
5862 Check_Floating_Point_Type_1
;
5863 Resolve
(E1
, P_Base_Type
);
5864 Set_Etype
(N
, P_Base_Type
);
5870 when Attribute_Type_Class
=>
5873 Check_Not_Incomplete_Type
;
5874 Set_Etype
(N
, RTE
(RE_Type_Class
));
5880 when Attribute_TypeCode
=>
5882 Check_PolyORB_Attribute
;
5883 Set_Etype
(N
, RTE
(RE_TypeCode
));
5889 when Attribute_Type_Key
=>
5893 -- This processing belongs in Eval_Attribute ???
5896 function Type_Key
return String_Id
;
5897 -- A very preliminary implementation. For now, a signature
5898 -- consists of only the type name. This is clearly incomplete
5899 -- (e.g., adding a new field to a record type should change the
5900 -- type's Type_Key attribute).
5906 function Type_Key
return String_Id
is
5907 Full_Name
: constant String_Id
:=
5908 Fully_Qualified_Name_String
(Entity
(P
));
5911 -- Copy all characters in Full_Name but the trailing NUL
5914 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5915 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5918 Store_String_Chars
("'Type_Key");
5923 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5926 Analyze_And_Resolve
(N
, Standard_String
);
5932 when Attribute_UET_Address
=>
5934 Check_Unit_Name
(P
);
5935 Set_Etype
(N
, RTE
(RE_Address
));
5937 -----------------------
5938 -- Unbiased_Rounding --
5939 -----------------------
5941 when Attribute_Unbiased_Rounding
=>
5942 Check_Floating_Point_Type_1
;
5943 Set_Etype
(N
, P_Base_Type
);
5944 Resolve
(E1
, P_Base_Type
);
5946 ----------------------
5947 -- Unchecked_Access --
5948 ----------------------
5950 when Attribute_Unchecked_Access
=>
5951 if Comes_From_Source
(N
) then
5952 Check_Restriction
(No_Unchecked_Access
, N
);
5955 Analyze_Access_Attribute
;
5957 -------------------------
5958 -- Unconstrained_Array --
5959 -------------------------
5961 when Attribute_Unconstrained_Array
=>
5964 Check_Not_Incomplete_Type
;
5965 Set_Etype
(N
, Standard_Boolean
);
5966 Set_Is_Static_Expression
(N
, True);
5968 ------------------------------
5969 -- Universal_Literal_String --
5970 ------------------------------
5972 -- This is a GNAT specific attribute whose prefix must be a named
5973 -- number where the expression is either a single numeric literal,
5974 -- or a numeric literal immediately preceded by a minus sign. The
5975 -- result is equivalent to a string literal containing the text of
5976 -- the literal as it appeared in the source program with a possible
5977 -- leading minus sign.
5979 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
5983 if not Is_Entity_Name
(P
)
5984 or else Ekind
(Entity
(P
)) not in Named_Kind
5986 Error_Attr_P
("prefix for % attribute must be named number");
5993 Src
: Source_Buffer_Ptr
;
5996 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
5998 if Nkind
(Expr
) = N_Op_Minus
then
6000 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6005 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6007 ("named number for % attribute must be simple literal", N
);
6010 -- Build string literal corresponding to source literal text
6015 Store_String_Char
(Get_Char_Code
('-'));
6019 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6021 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6022 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6026 -- Now we rewrite the attribute with the string literal
6029 Make_String_Literal
(Loc
, End_String
));
6031 Set_Is_Static_Expression
(N
, True);
6034 end Universal_Literal_String
;
6036 -------------------------
6037 -- Unrestricted_Access --
6038 -------------------------
6040 -- This is a GNAT specific attribute which is like Access except that
6041 -- all scope checks and checks for aliased views are omitted. It is
6042 -- documented as being equivalent to the use of the Address attribute
6043 -- followed by an unchecked conversion to the target access type.
6045 when Attribute_Unrestricted_Access
=>
6047 -- If from source, deal with relevant restrictions
6049 if Comes_From_Source
(N
) then
6050 Check_Restriction
(No_Unchecked_Access
, N
);
6052 if Nkind
(P
) in N_Has_Entity
6053 and then Present
(Entity
(P
))
6054 and then Is_Object
(Entity
(P
))
6056 Check_Restriction
(No_Implicit_Aliasing
, N
);
6060 if Is_Entity_Name
(P
) then
6061 Set_Address_Taken
(Entity
(P
));
6064 -- It might seem reasonable to call Address_Checks here to apply the
6065 -- same set of semantic checks that we enforce for 'Address (after
6066 -- all we document Unrestricted_Access as being equivalent to the
6067 -- use of Address followed by an Unchecked_Conversion). However, if
6068 -- we do enable these checks, we get multiple failures in both the
6069 -- compiler run-time and in our regression test suite, so we leave
6070 -- out these checks for now. To be investigated further some time???
6074 -- Now complete analysis using common access processing
6076 Analyze_Access_Attribute
;
6082 when Attribute_Update
=> Update
: declare
6083 Common_Typ
: Entity_Id
;
6084 -- The common type of a multiple component update for a record
6086 Comps
: Elist_Id
:= No_Elist
;
6087 -- A list used in the resolution of a record update. It contains the
6088 -- entities of all record components processed so far.
6090 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6091 -- Analyze and resolve array_component_association Assoc against the
6092 -- index of array type P_Type.
6094 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6095 -- Analyze and resolve record_component_association Comp against
6096 -- record type P_Type.
6098 ------------------------------------
6099 -- Analyze_Array_Component_Update --
6100 ------------------------------------
6102 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6106 Index_Typ
: Entity_Id
;
6110 -- The current association contains a sequence of indexes denoting
6111 -- an element of a multidimensional array:
6113 -- (Index_1, ..., Index_N)
6115 -- Examine each individual index and resolve it against the proper
6116 -- index type of the array.
6118 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6119 Expr
:= First
(Choices
(Assoc
));
6120 while Present
(Expr
) loop
6122 -- The use of others is illegal (SPARK RM 4.4.1(12))
6124 if Nkind
(Expr
) = N_Others_Choice
then
6126 ("others choice not allowed in attribute %", Expr
);
6128 -- Otherwise analyze and resolve all indexes
6131 Index
:= First
(Expressions
(Expr
));
6132 Index_Typ
:= First_Index
(P_Type
);
6133 while Present
(Index
) and then Present
(Index_Typ
) loop
6134 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6136 Next_Index
(Index_Typ
);
6139 -- Detect a case where the association either lacks an
6140 -- index or contains an extra index.
6142 if Present
(Index
) or else Present
(Index_Typ
) then
6144 ("dimension mismatch in index list", Assoc
);
6151 -- The current association denotes either a single component or a
6152 -- range of components of a one dimensional array:
6156 -- Resolve the index or its high and low bounds (if range) against
6157 -- the proper index type of the array.
6160 Index
:= First
(Choices
(Assoc
));
6161 Index_Typ
:= First_Index
(P_Type
);
6163 if Present
(Next_Index
(Index_Typ
)) then
6164 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6167 while Present
(Index
) loop
6169 -- The use of others is illegal (SPARK RM 4.4.1(12))
6171 if Nkind
(Index
) = N_Others_Choice
then
6173 ("others choice not allowed in attribute %", Index
);
6175 -- The index denotes a range of elements
6177 elsif Nkind
(Index
) = N_Range
then
6178 Low
:= Low_Bound
(Index
);
6179 High
:= High_Bound
(Index
);
6181 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6182 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6184 -- Add a range check to ensure that the bounds of the
6185 -- range are within the index type when this cannot be
6186 -- determined statically.
6188 if not Is_OK_Static_Expression
(Low
) then
6189 Set_Do_Range_Check
(Low
);
6192 if not Is_OK_Static_Expression
(High
) then
6193 Set_Do_Range_Check
(High
);
6196 -- Otherwise the index denotes a single element
6199 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6201 -- Add a range check to ensure that the index is within
6202 -- the index type when it is not possible to determine
6205 if not Is_OK_Static_Expression
(Index
) then
6206 Set_Do_Range_Check
(Index
);
6213 end Analyze_Array_Component_Update
;
6215 -------------------------------------
6216 -- Analyze_Record_Component_Update --
6217 -------------------------------------
6219 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6220 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6221 Base_Typ
: Entity_Id
;
6222 Comp_Or_Discr
: Entity_Id
;
6225 -- Find the discriminant or component whose name corresponds to
6226 -- Comp. A simple character comparison is sufficient because all
6227 -- visible names within a record type are unique.
6229 Comp_Or_Discr
:= First_Entity
(P_Type
);
6230 while Present
(Comp_Or_Discr
) loop
6231 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6233 -- Decorate the component reference by setting its entity
6234 -- and type for resolution purposes.
6236 Set_Entity
(Comp
, Comp_Or_Discr
);
6237 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6241 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6244 -- Diagnose an illegal reference
6246 if Present
(Comp_Or_Discr
) then
6247 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6249 ("attribute % may not modify record discriminants", Comp
);
6251 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6252 if Contains
(Comps
, Comp_Or_Discr
) then
6253 Error_Msg_N
("component & already updated", Comp
);
6255 -- Mark this component as processed
6258 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6262 -- The update aggregate mentions an entity that does not belong to
6266 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6269 -- Verify the consistency of types when the current component is
6270 -- part of a miltiple component update.
6272 -- Comp_1, ..., Comp_N => <value>
6274 if Present
(Etype
(Comp
)) then
6275 Base_Typ
:= Base_Type
(Etype
(Comp
));
6277 -- Save the type of the first component reference as the
6278 -- remaning references (if any) must resolve to this type.
6280 if No
(Common_Typ
) then
6281 Common_Typ
:= Base_Typ
;
6283 elsif Base_Typ
/= Common_Typ
then
6285 ("components in choice list must have same type", Comp
);
6288 end Analyze_Record_Component_Update
;
6295 -- Start of processing for Update
6300 if not Is_Object_Reference
(P
) then
6301 Error_Attr_P
("prefix of attribute % must denote an object");
6303 elsif not Is_Array_Type
(P_Type
)
6304 and then not Is_Record_Type
(P_Type
)
6306 Error_Attr_P
("prefix of attribute % must be a record or array");
6308 elsif Is_Limited_View
(P_Type
) then
6309 Error_Attr
("prefix of attribute % cannot be limited", N
);
6311 elsif Nkind
(E1
) /= N_Aggregate
then
6312 Error_Attr
("attribute % requires component association list", N
);
6315 -- Inspect the update aggregate, looking at all the associations and
6316 -- choices. Perform the following checks:
6318 -- 1) Legality of "others" in all cases
6319 -- 2) Legality of <>
6320 -- 3) Component legality for arrays
6321 -- 4) Component legality for records
6323 -- The remaining checks are performed on the expanded attribute
6325 Assoc
:= First
(Component_Associations
(E1
));
6326 while Present
(Assoc
) loop
6328 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6330 if Box_Present
(Assoc
) then
6332 ("default initialization not allowed in attribute %", Assoc
);
6334 -- Otherwise process the association
6337 Analyze
(Expression
(Assoc
));
6339 if Is_Array_Type
(P_Type
) then
6340 Analyze_Array_Component_Update
(Assoc
);
6342 elsif Is_Record_Type
(P_Type
) then
6344 -- Reset the common type used in a multiple component update
6345 -- as we are processing the contents of a new association.
6347 Common_Typ
:= Empty
;
6349 Comp
:= First
(Choices
(Assoc
));
6350 while Present
(Comp
) loop
6351 if Nkind
(Comp
) = N_Identifier
then
6352 Analyze_Record_Component_Update
(Comp
);
6354 -- The use of others is illegal (SPARK RM 4.4.1(5))
6356 elsif Nkind
(Comp
) = N_Others_Choice
then
6358 ("others choice not allowed in attribute %", Comp
);
6360 -- The name of a record component cannot appear in any
6365 ("name should be identifier or OTHERS", Comp
);
6376 -- The type of attribute 'Update is that of the prefix
6378 Set_Etype
(N
, P_Type
);
6385 when Attribute_Val
=> Val
: declare
6388 Check_Discrete_Type
;
6390 if Is_Boolean_Type
(P_Type
) then
6391 Error_Msg_Name_1
:= Aname
;
6392 Error_Msg_Name_2
:= Chars
(P_Type
);
6393 Check_SPARK_05_Restriction
6394 ("attribute% is not allowed for type%", P
);
6397 Resolve
(E1
, Any_Integer
);
6398 Set_Etype
(N
, P_Base_Type
);
6400 -- Note, we need a range check in general, but we wait for the
6401 -- Resolve call to do this, since we want to let Eval_Attribute
6402 -- have a chance to find an static illegality first.
6409 when Attribute_Valid
=>
6412 -- Ignore check for object if we have a 'Valid reference generated
6413 -- by the expanded code, since in some cases valid checks can occur
6414 -- on items that are names, but are not objects (e.g. attributes).
6416 if Comes_From_Source
(N
) then
6417 Check_Object_Reference
(P
);
6420 if not Is_Scalar_Type
(P_Type
) then
6421 Error_Attr_P
("object for % attribute must be of scalar type");
6424 -- If the attribute appears within the subtype's own predicate
6425 -- function, then issue a warning that this will cause infinite
6429 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6432 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6434 ("attribute Valid requires a predicate check??", N
);
6435 Error_Msg_N
("\and will result in infinite recursion??", N
);
6439 Set_Etype
(N
, Standard_Boolean
);
6445 when Attribute_Valid_Scalars
=>
6447 Check_Object_Reference
(P
);
6448 Set_Etype
(N
, Standard_Boolean
);
6450 -- Following checks are only for source types
6452 if Comes_From_Source
(N
) then
6453 if not Scalar_Part_Present
(P_Type
) then
6455 ("??attribute % always True, no scalars to check");
6458 -- Not allowed for unchecked union type
6460 if Has_Unchecked_Union
(P_Type
) then
6462 ("attribute % not allowed for Unchecked_Union type");
6470 when Attribute_Value
=> Value
:
6472 Check_SPARK_05_Restriction_On_Attribute
;
6476 -- Case of enumeration type
6478 -- When an enumeration type appears in an attribute reference, all
6479 -- literals of the type are marked as referenced. This must only be
6480 -- done if the attribute reference appears in the current source.
6481 -- Otherwise the information on references may differ between a
6482 -- normal compilation and one that performs inlining.
6484 if Is_Enumeration_Type
(P_Type
)
6485 and then In_Extended_Main_Code_Unit
(N
)
6487 Check_Restriction
(No_Enumeration_Maps
, N
);
6489 -- Mark all enumeration literals as referenced, since the use of
6490 -- the Value attribute can implicitly reference any of the
6491 -- literals of the enumeration base type.
6494 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6496 while Present
(Ent
) loop
6497 Set_Referenced
(Ent
);
6503 -- Set Etype before resolving expression because expansion of
6504 -- expression may require enclosing type. Note that the type
6505 -- returned by 'Value is the base type of the prefix type.
6507 Set_Etype
(N
, P_Base_Type
);
6508 Validate_Non_Static_Attribute_Function_Call
;
6510 -- Check restriction No_Fixed_IO
6512 if Restriction_Check_Required
(No_Fixed_IO
)
6513 and then Is_Fixed_Point_Type
(P_Type
)
6515 Check_Restriction
(No_Fixed_IO
, P
);
6523 when Attribute_Value_Size
=>
6526 Check_Not_Incomplete_Type
;
6527 Set_Etype
(N
, Universal_Integer
);
6533 when Attribute_Version
=>
6536 Set_Etype
(N
, RTE
(RE_Version_String
));
6542 when Attribute_Wchar_T_Size
=>
6543 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6549 when Attribute_Wide_Image
=> Wide_Image
:
6551 Check_SPARK_05_Restriction_On_Attribute
;
6553 Set_Etype
(N
, Standard_Wide_String
);
6555 Resolve
(E1
, P_Base_Type
);
6556 Validate_Non_Static_Attribute_Function_Call
;
6558 -- Check restriction No_Fixed_IO
6560 if Restriction_Check_Required
(No_Fixed_IO
)
6561 and then Is_Fixed_Point_Type
(P_Type
)
6563 Check_Restriction
(No_Fixed_IO
, P
);
6567 ---------------------
6568 -- Wide_Wide_Image --
6569 ---------------------
6571 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
6574 Set_Etype
(N
, Standard_Wide_Wide_String
);
6576 Resolve
(E1
, P_Base_Type
);
6577 Validate_Non_Static_Attribute_Function_Call
;
6579 -- Check restriction No_Fixed_IO
6581 if Restriction_Check_Required
(No_Fixed_IO
)
6582 and then Is_Fixed_Point_Type
(P_Type
)
6584 Check_Restriction
(No_Fixed_IO
, P
);
6586 end Wide_Wide_Image
;
6592 when Attribute_Wide_Value
=> Wide_Value
:
6594 Check_SPARK_05_Restriction_On_Attribute
;
6598 -- Set Etype before resolving expression because expansion
6599 -- of expression may require enclosing type.
6601 Set_Etype
(N
, P_Type
);
6602 Validate_Non_Static_Attribute_Function_Call
;
6604 -- Check restriction No_Fixed_IO
6606 if Restriction_Check_Required
(No_Fixed_IO
)
6607 and then Is_Fixed_Point_Type
(P_Type
)
6609 Check_Restriction
(No_Fixed_IO
, P
);
6613 ---------------------
6614 -- Wide_Wide_Value --
6615 ---------------------
6617 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6622 -- Set Etype before resolving expression because expansion
6623 -- of expression may require enclosing type.
6625 Set_Etype
(N
, P_Type
);
6626 Validate_Non_Static_Attribute_Function_Call
;
6628 -- Check restriction No_Fixed_IO
6630 if Restriction_Check_Required
(No_Fixed_IO
)
6631 and then Is_Fixed_Point_Type
(P_Type
)
6633 Check_Restriction
(No_Fixed_IO
, P
);
6635 end Wide_Wide_Value
;
6637 ---------------------
6638 -- Wide_Wide_Width --
6639 ---------------------
6641 when Attribute_Wide_Wide_Width
=>
6644 Set_Etype
(N
, Universal_Integer
);
6650 when Attribute_Wide_Width
=>
6651 Check_SPARK_05_Restriction_On_Attribute
;
6654 Set_Etype
(N
, Universal_Integer
);
6660 when Attribute_Width
=>
6661 Check_SPARK_05_Restriction_On_Attribute
;
6664 Set_Etype
(N
, Universal_Integer
);
6670 when Attribute_Word_Size
=>
6671 Standard_Attribute
(System_Word_Size
);
6677 when Attribute_Write
=>
6679 Check_Stream_Attribute
(TSS_Stream_Write
);
6680 Set_Etype
(N
, Standard_Void_Type
);
6681 Resolve
(N
, Standard_Void_Type
);
6685 -- All errors raise Bad_Attribute, so that we get out before any further
6686 -- damage occurs when an error is detected (for example, if we check for
6687 -- one attribute expression, and the check succeeds, we want to be able
6688 -- to proceed securely assuming that an expression is in fact present.
6690 -- Note: we set the attribute analyzed in this case to prevent any
6691 -- attempt at reanalysis which could generate spurious error msgs.
6694 when Bad_Attribute
=>
6696 Set_Etype
(N
, Any_Type
);
6698 end Analyze_Attribute
;
6700 --------------------
6701 -- Eval_Attribute --
6702 --------------------
6704 procedure Eval_Attribute
(N
: Node_Id
) is
6705 Loc
: constant Source_Ptr
:= Sloc
(N
);
6706 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6707 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6708 P
: constant Node_Id
:= Prefix
(N
);
6710 C_Type
: constant Entity_Id
:= Etype
(N
);
6711 -- The type imposed by the context
6714 -- First expression, or Empty if none
6717 -- Second expression, or Empty if none
6719 P_Entity
: Entity_Id
;
6720 -- Entity denoted by prefix
6723 -- The type of the prefix
6725 P_Base_Type
: Entity_Id
;
6726 -- The base type of the prefix type
6728 P_Root_Type
: Entity_Id
;
6729 -- The root type of the prefix type
6732 -- True if the result is Static. This is set by the general processing
6733 -- to true if the prefix is static, and all expressions are static. It
6734 -- can be reset as processing continues for particular attributes. This
6735 -- flag can still be True if the reference raises a constraint error.
6736 -- Is_Static_Expression (N) is set to follow this value as it is set
6737 -- and we could always reference this, but it is convenient to have a
6738 -- simple short name to use, since it is frequently referenced.
6740 Lo_Bound
, Hi_Bound
: Node_Id
;
6741 -- Expressions for low and high bounds of type or array index referenced
6742 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6745 -- Constraint error node used if we have an attribute reference has
6746 -- an argument that raises a constraint error. In this case we replace
6747 -- the attribute with a raise constraint_error node. This is important
6748 -- processing, since otherwise gigi might see an attribute which it is
6749 -- unprepared to deal with.
6751 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
6752 -- If Bound is a reference to a discriminant of a task or protected type
6753 -- occurring within the object's body, rewrite attribute reference into
6754 -- a reference to the corresponding discriminal. Use for the expansion
6755 -- of checks against bounds of entry family index subtypes.
6757 procedure Check_Expressions
;
6758 -- In case where the attribute is not foldable, the expressions, if
6759 -- any, of the attribute, are in a non-static context. This procedure
6760 -- performs the required additional checks.
6762 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
6763 -- Determines if the given type has compile time known bounds. Note
6764 -- that we enter the case statement even in cases where the prefix
6765 -- type does NOT have known bounds, so it is important to guard any
6766 -- attempt to evaluate both bounds with a call to this function.
6768 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
6769 -- This procedure is called when the attribute N has a non-static
6770 -- but compile time known value given by Val. It includes the
6771 -- necessary checks for out of range values.
6773 function Fore_Value
return Nat
;
6774 -- Computes the Fore value for the current attribute prefix, which is
6775 -- known to be a static fixed-point type. Used by Fore and Width.
6777 function Mantissa
return Uint
;
6778 -- Returns the Mantissa value for the prefix type
6780 procedure Set_Bounds
;
6781 -- Used for First, Last and Length attributes applied to an array or
6782 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6783 -- and high bound expressions for the index referenced by the attribute
6784 -- designator (i.e. the first index if no expression is present, and the
6785 -- N'th index if the value N is present as an expression). Also used for
6786 -- First and Last of scalar types and for First_Valid and Last_Valid.
6787 -- Static is reset to False if the type or index type is not statically
6790 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
6791 -- Verify that the prefix of a potentially static array attribute
6792 -- satisfies the conditions of 4.9 (14).
6794 -----------------------------------
6795 -- Check_Concurrent_Discriminant --
6796 -----------------------------------
6798 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
6800 -- The concurrent (task or protected) type
6803 if Nkind
(Bound
) = N_Identifier
6804 and then Ekind
(Entity
(Bound
)) = E_Discriminant
6805 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
6807 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
6809 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
6811 -- Find discriminant of original concurrent type, and use
6812 -- its current discriminal, which is the renaming within
6813 -- the task/protected body.
6817 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
6820 end Check_Concurrent_Discriminant
;
6822 -----------------------
6823 -- Check_Expressions --
6824 -----------------------
6826 procedure Check_Expressions
is
6830 while Present
(E
) loop
6831 Check_Non_Static_Context
(E
);
6834 end Check_Expressions
;
6836 ----------------------------------
6837 -- Compile_Time_Known_Attribute --
6838 ----------------------------------
6840 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
6841 T
: constant Entity_Id
:= Etype
(N
);
6844 Fold_Uint
(N
, Val
, False);
6846 -- Check that result is in bounds of the type if it is static
6848 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
6851 elsif Is_Out_Of_Range
(N
, T
) then
6852 Apply_Compile_Time_Constraint_Error
6853 (N
, "value not in range of}??", CE_Range_Check_Failed
);
6855 elsif not Range_Checks_Suppressed
(T
) then
6856 Enable_Range_Check
(N
);
6859 Set_Do_Range_Check
(N
, False);
6861 end Compile_Time_Known_Attribute
;
6863 -------------------------------
6864 -- Compile_Time_Known_Bounds --
6865 -------------------------------
6867 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
6870 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
6872 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
6873 end Compile_Time_Known_Bounds
;
6879 -- Note that the Fore calculation is based on the actual values
6880 -- of the bounds, and does not take into account possible rounding.
6882 function Fore_Value
return Nat
is
6883 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
6884 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
6885 Small
: constant Ureal
:= Small_Value
(P_Type
);
6886 Lo_Real
: constant Ureal
:= Lo
* Small
;
6887 Hi_Real
: constant Ureal
:= Hi
* Small
;
6892 -- Bounds are given in terms of small units, so first compute
6893 -- proper values as reals.
6895 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
6898 -- Loop to compute proper value if more than one digit required
6900 while T
>= Ureal_10
loop
6912 -- Table of mantissa values accessed by function Computed using
6915 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6917 -- where D is T'Digits (RM83 3.5.7)
6919 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
6961 function Mantissa
return Uint
is
6964 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
6971 procedure Set_Bounds
is
6977 -- For a string literal subtype, we have to construct the bounds.
6978 -- Valid Ada code never applies attributes to string literals, but
6979 -- it is convenient to allow the expander to generate attribute
6980 -- references of this type (e.g. First and Last applied to a string
6983 -- Note that the whole point of the E_String_Literal_Subtype is to
6984 -- avoid this construction of bounds, but the cases in which we
6985 -- have to materialize them are rare enough that we don't worry.
6987 -- The low bound is simply the low bound of the base type. The
6988 -- high bound is computed from the length of the string and this
6991 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
6992 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
6993 Lo_Bound
:= Type_Low_Bound
(Ityp
);
6996 Make_Integer_Literal
(Sloc
(P
),
6998 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7000 Set_Parent
(Hi_Bound
, P
);
7001 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7004 -- For non-array case, just get bounds of scalar type
7006 elsif Is_Scalar_Type
(P_Type
) then
7009 -- For a fixed-point type, we must freeze to get the attributes
7010 -- of the fixed-point type set now so we can reference them.
7012 if Is_Fixed_Point_Type
(P_Type
)
7013 and then not Is_Frozen
(Base_Type
(P_Type
))
7014 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7015 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7017 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7020 -- For array case, get type of proper index
7026 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7029 Indx
:= First_Index
(P_Type
);
7030 for J
in 1 .. Ndim
- 1 loop
7034 -- If no index type, get out (some other error occurred, and
7035 -- we don't have enough information to complete the job).
7043 Ityp
:= Etype
(Indx
);
7046 -- A discrete range in an index constraint is allowed to be a
7047 -- subtype indication. This is syntactically a pain, but should
7048 -- not propagate to the entity for the corresponding index subtype.
7049 -- After checking that the subtype indication is legal, the range
7050 -- of the subtype indication should be transfered to the entity.
7051 -- The attributes for the bounds should remain the simple retrievals
7052 -- that they are now.
7054 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7055 Hi_Bound
:= Type_High_Bound
(Ityp
);
7057 -- If subtype is non-static, result is definitely non-static
7059 if not Is_Static_Subtype
(Ityp
) then
7061 Set_Is_Static_Expression
(N
, False);
7063 -- Subtype is static, does it raise CE?
7065 elsif not Is_OK_Static_Subtype
(Ityp
) then
7066 Set_Raises_Constraint_Error
(N
);
7070 -------------------------------
7071 -- Statically_Denotes_Entity --
7072 -------------------------------
7074 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7078 if not Is_Entity_Name
(N
) then
7085 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7086 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7087 end Statically_Denotes_Entity
;
7089 -- Start of processing for Eval_Attribute
7092 -- Initialize result as non-static, will be reset if appropriate
7094 Set_Is_Static_Expression
(N
, False);
7097 -- Acquire first two expressions (at the moment, no attributes take more
7098 -- than two expressions in any case).
7100 if Present
(Expressions
(N
)) then
7101 E1
:= First
(Expressions
(N
));
7108 -- Special processing for Enabled attribute. This attribute has a very
7109 -- special prefix, and the easiest way to avoid lots of special checks
7110 -- to protect this special prefix from causing trouble is to deal with
7111 -- this attribute immediately and be done with it.
7113 if Id
= Attribute_Enabled
then
7115 -- We skip evaluation if the expander is not active. This is not just
7116 -- an optimization. It is of key importance that we not rewrite the
7117 -- attribute in a generic template, since we want to pick up the
7118 -- setting of the check in the instance, and testing expander active
7119 -- is as easy way of doing this as any.
7121 if Expander_Active
then
7123 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7128 if C
in Predefined_Check_Id
then
7129 R
:= Scope_Suppress
.Suppress
(C
);
7131 R
:= Is_Check_Suppressed
(Empty
, C
);
7135 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7138 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7145 -- Special processing for cases where the prefix is an object. For
7146 -- this purpose, a string literal counts as an object (attributes
7147 -- of string literals can only appear in generated code).
7149 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7151 -- For Component_Size, the prefix is an array object, and we apply
7152 -- the attribute to the type of the object. This is allowed for
7153 -- both unconstrained and constrained arrays, since the bounds
7154 -- have no influence on the value of this attribute.
7156 if Id
= Attribute_Component_Size
then
7157 P_Entity
:= Etype
(P
);
7159 -- For First and Last, the prefix is an array object, and we apply
7160 -- the attribute to the type of the array, but we need a constrained
7161 -- type for this, so we use the actual subtype if available.
7163 elsif Id
= Attribute_First
or else
7164 Id
= Attribute_Last
or else
7165 Id
= Attribute_Length
7168 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7171 if Present
(AS
) and then Is_Constrained
(AS
) then
7174 -- If we have an unconstrained type we cannot fold
7182 -- For Size, give size of object if available, otherwise we
7183 -- cannot fold Size.
7185 elsif Id
= Attribute_Size
then
7186 if Is_Entity_Name
(P
)
7187 and then Known_Esize
(Entity
(P
))
7189 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7197 -- For Alignment, give size of object if available, otherwise we
7198 -- cannot fold Alignment.
7200 elsif Id
= Attribute_Alignment
then
7201 if Is_Entity_Name
(P
)
7202 and then Known_Alignment
(Entity
(P
))
7204 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7212 -- For Lock_Free, we apply the attribute to the type of the object.
7213 -- This is allowed since we have already verified that the type is a
7216 elsif Id
= Attribute_Lock_Free
then
7217 P_Entity
:= Etype
(P
);
7219 -- No other attributes for objects are folded
7226 -- Cases where P is not an object. Cannot do anything if P is not the
7227 -- name of an entity.
7229 elsif not Is_Entity_Name
(P
) then
7233 -- Otherwise get prefix entity
7236 P_Entity
:= Entity
(P
);
7239 -- If we are asked to evaluate an attribute where the prefix is a
7240 -- non-frozen generic actual type whose RM_Size is still set to zero,
7241 -- then abandon the effort.
7243 if Is_Type
(P_Entity
)
7244 and then (not Is_Frozen
(P_Entity
)
7245 and then Is_Generic_Actual_Type
(P_Entity
)
7246 and then RM_Size
(P_Entity
) = 0)
7248 -- However, the attribute Unconstrained_Array must be evaluated,
7249 -- since it is documented to be a static attribute (and can for
7250 -- example appear in a Compile_Time_Warning pragma). The frozen
7251 -- status of the type does not affect its evaluation.
7253 and then Id
/= Attribute_Unconstrained_Array
7258 -- At this stage P_Entity is the entity to which the attribute
7259 -- is to be applied. This is usually simply the entity of the
7260 -- prefix, except in some cases of attributes for objects, where
7261 -- as described above, we apply the attribute to the object type.
7263 -- Here is where we make sure that static attributes are properly
7264 -- marked as such. These are attributes whose prefix is a static
7265 -- scalar subtype, whose result is scalar, and whose arguments, if
7266 -- present, are static scalar expressions. Note that such references
7267 -- are static expressions even if they raise Constraint_Error.
7269 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7270 -- though evaluating it raises constraint error. This means that a
7271 -- declaration like:
7273 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7275 -- is legal, since here this expression appears in a statically
7276 -- unevaluated position, so it does not actually raise an exception.
7278 if Is_Scalar_Type
(P_Entity
)
7279 and then (not Is_Generic_Type
(P_Entity
))
7280 and then Is_Static_Subtype
(P_Entity
)
7281 and then Is_Scalar_Type
(Etype
(N
))
7284 or else (Is_Static_Expression
(E1
)
7285 and then Is_Scalar_Type
(Etype
(E1
))))
7288 or else (Is_Static_Expression
(E2
)
7289 and then Is_Scalar_Type
(Etype
(E1
))))
7292 Set_Is_Static_Expression
(N
, True);
7295 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7296 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7297 -- Note we allow non-static non-generic types at this stage as further
7300 if Is_Type
(P_Entity
)
7301 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7302 and then (not Is_Generic_Type
(P_Entity
))
7306 -- Second foldable possibility is an array object (RM 4.9(8))
7308 elsif (Ekind
(P_Entity
) = E_Variable
7310 Ekind
(P_Entity
) = E_Constant
)
7311 and then Is_Array_Type
(Etype
(P_Entity
))
7312 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7314 P_Type
:= Etype
(P_Entity
);
7316 -- If the entity is an array constant with an unconstrained nominal
7317 -- subtype then get the type from the initial value. If the value has
7318 -- been expanded into assignments, there is no expression and the
7319 -- attribute reference remains dynamic.
7321 -- We could do better here and retrieve the type ???
7323 if Ekind
(P_Entity
) = E_Constant
7324 and then not Is_Constrained
(P_Type
)
7326 if No
(Constant_Value
(P_Entity
)) then
7329 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7333 -- Definite must be folded if the prefix is not a generic type, that
7334 -- is to say if we are within an instantiation. Same processing applies
7335 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7336 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7338 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7339 Id
= Attribute_Definite
or else
7340 Id
= Attribute_Has_Access_Values
or else
7341 Id
= Attribute_Has_Discriminants
or else
7342 Id
= Attribute_Has_Tagged_Values
or else
7343 Id
= Attribute_Lock_Free
or else
7344 Id
= Attribute_Type_Class
or else
7345 Id
= Attribute_Unconstrained_Array
or else
7346 Id
= Attribute_Max_Alignment_For_Allocation
)
7347 and then not Is_Generic_Type
(P_Entity
)
7351 -- We can fold 'Size applied to a type if the size is known (as happens
7352 -- for a size from an attribute definition clause). At this stage, this
7353 -- can happen only for types (e.g. record types) for which the size is
7354 -- always non-static. We exclude generic types from consideration (since
7355 -- they have bogus sizes set within templates).
7357 elsif Id
= Attribute_Size
7358 and then Is_Type
(P_Entity
)
7359 and then (not Is_Generic_Type
(P_Entity
))
7360 and then Known_Static_RM_Size
(P_Entity
)
7362 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7365 -- We can fold 'Alignment applied to a type if the alignment is known
7366 -- (as happens for an alignment from an attribute definition clause).
7367 -- At this stage, this can happen only for types (e.g. record types) for
7368 -- which the size is always non-static. We exclude generic types from
7369 -- consideration (since they have bogus sizes set within templates).
7371 elsif Id
= Attribute_Alignment
7372 and then Is_Type
(P_Entity
)
7373 and then (not Is_Generic_Type
(P_Entity
))
7374 and then Known_Alignment
(P_Entity
)
7376 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7379 -- If this is an access attribute that is known to fail accessibility
7380 -- check, rewrite accordingly.
7382 elsif Attribute_Name
(N
) = Name_Access
7383 and then Raises_Constraint_Error
(N
)
7386 Make_Raise_Program_Error
(Loc
,
7387 Reason
=> PE_Accessibility_Check_Failed
));
7388 Set_Etype
(N
, C_Type
);
7391 -- No other cases are foldable (they certainly aren't static, and at
7392 -- the moment we don't try to fold any cases other than the ones above).
7399 -- If either attribute or the prefix is Any_Type, then propagate
7400 -- Any_Type to the result and don't do anything else at all.
7402 if P_Type
= Any_Type
7403 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7404 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7406 Set_Etype
(N
, Any_Type
);
7410 -- Scalar subtype case. We have not yet enforced the static requirement
7411 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7412 -- of non-static attribute references (e.g. S'Digits for a non-static
7413 -- floating-point type, which we can compute at compile time).
7415 -- Note: this folding of non-static attributes is not simply a case of
7416 -- optimization. For many of the attributes affected, Gigi cannot handle
7417 -- the attribute and depends on the front end having folded them away.
7419 -- Note: although we don't require staticness at this stage, we do set
7420 -- the Static variable to record the staticness, for easy reference by
7421 -- those attributes where it matters (e.g. Succ and Pred), and also to
7422 -- be used to ensure that non-static folded things are not marked as
7423 -- being static (a check that is done right at the end).
7425 P_Root_Type
:= Root_Type
(P_Type
);
7426 P_Base_Type
:= Base_Type
(P_Type
);
7428 -- If the root type or base type is generic, then we cannot fold. This
7429 -- test is needed because subtypes of generic types are not always
7430 -- marked as being generic themselves (which seems odd???)
7432 if Is_Generic_Type
(P_Root_Type
)
7433 or else Is_Generic_Type
(P_Base_Type
)
7438 if Is_Scalar_Type
(P_Type
) then
7439 if not Is_Static_Subtype
(P_Type
) then
7441 Set_Is_Static_Expression
(N
, False);
7442 elsif not Is_OK_Static_Subtype
(P_Type
) then
7443 Set_Raises_Constraint_Error
(N
);
7446 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7447 -- since we can't do anything with unconstrained arrays. In addition,
7448 -- only the First, Last and Length attributes are possibly static.
7450 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7451 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7452 -- Unconstrained_Array are again exceptions, because they apply as well
7453 -- to unconstrained types.
7455 -- In addition Component_Size is an exception since it is possibly
7456 -- foldable, even though it is never static, and it does apply to
7457 -- unconstrained arrays. Furthermore, it is essential to fold this
7458 -- in the packed case, since otherwise the value will be incorrect.
7460 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7461 Id
= Attribute_Definite
or else
7462 Id
= Attribute_Has_Access_Values
or else
7463 Id
= Attribute_Has_Discriminants
or else
7464 Id
= Attribute_Has_Tagged_Values
or else
7465 Id
= Attribute_Lock_Free
or else
7466 Id
= Attribute_Type_Class
or else
7467 Id
= Attribute_Unconstrained_Array
or else
7468 Id
= Attribute_Component_Size
7471 Set_Is_Static_Expression
(N
, False);
7473 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7474 if not Is_Constrained
(P_Type
)
7475 or else (Id
/= Attribute_First
and then
7476 Id
/= Attribute_Last
and then
7477 Id
/= Attribute_Length
)
7483 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7484 -- scalar case, we hold off on enforcing staticness, since there are
7485 -- cases which we can fold at compile time even though they are not
7486 -- static (e.g. 'Length applied to a static index, even though other
7487 -- non-static indexes make the array type non-static). This is only
7488 -- an optimization, but it falls out essentially free, so why not.
7489 -- Again we compute the variable Static for easy reference later
7490 -- (note that no array attributes are static in Ada 83).
7492 -- We also need to set Static properly for subsequent legality checks
7493 -- which might otherwise accept non-static constants in contexts
7494 -- where they are not legal.
7497 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
7498 Set_Is_Static_Expression
(N
, Static
);
7504 Nod
:= First_Index
(P_Type
);
7506 -- The expression is static if the array type is constrained
7507 -- by given bounds, and not by an initial expression. Constant
7508 -- strings are static in any case.
7510 if Root_Type
(P_Type
) /= Standard_String
then
7512 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
7513 Set_Is_Static_Expression
(N
, Static
);
7517 while Present
(Nod
) loop
7518 if not Is_Static_Subtype
(Etype
(Nod
)) then
7520 Set_Is_Static_Expression
(N
, False);
7521 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
7522 Set_Raises_Constraint_Error
(N
);
7525 -- If however the index type is generic, or derived from
7526 -- one, attributes cannot be folded.
7528 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
7529 and then Id
/= Attribute_Component_Size
7539 -- Check any expressions that are present. Note that these expressions,
7540 -- depending on the particular attribute type, are either part of the
7541 -- attribute designator, or they are arguments in a case where the
7542 -- attribute reference returns a function. In the latter case, the
7543 -- rule in (RM 4.9(22)) applies and in particular requires the type
7544 -- of the expressions to be scalar in order for the attribute to be
7545 -- considered to be static.
7552 while Present
(E
) loop
7554 -- If expression is not static, then the attribute reference
7555 -- result certainly cannot be static.
7557 if not Is_Static_Expression
(E
) then
7559 Set_Is_Static_Expression
(N
, False);
7562 if Raises_Constraint_Error
(E
) then
7563 Set_Raises_Constraint_Error
(N
);
7566 -- If the result is not known at compile time, or is not of
7567 -- a scalar type, then the result is definitely not static,
7568 -- so we can quit now.
7570 if not Compile_Time_Known_Value
(E
)
7571 or else not Is_Scalar_Type
(Etype
(E
))
7573 -- An odd special case, if this is a Pos attribute, this
7574 -- is where we need to apply a range check since it does
7575 -- not get done anywhere else.
7577 if Id
= Attribute_Pos
then
7578 if Is_Integer_Type
(Etype
(E
)) then
7579 Apply_Range_Check
(E
, Etype
(N
));
7586 -- If the expression raises a constraint error, then so does
7587 -- the attribute reference. We keep going in this case because
7588 -- we are still interested in whether the attribute reference
7589 -- is static even if it is not static.
7591 elsif Raises_Constraint_Error
(E
) then
7592 Set_Raises_Constraint_Error
(N
);
7598 if Raises_Constraint_Error
(Prefix
(N
)) then
7603 -- Deal with the case of a static attribute reference that raises
7604 -- constraint error. The Raises_Constraint_Error flag will already
7605 -- have been set, and the Static flag shows whether the attribute
7606 -- reference is static. In any case we certainly can't fold such an
7607 -- attribute reference.
7609 -- Note that the rewriting of the attribute node with the constraint
7610 -- error node is essential in this case, because otherwise Gigi might
7611 -- blow up on one of the attributes it never expects to see.
7613 -- The constraint_error node must have the type imposed by the context,
7614 -- to avoid spurious errors in the enclosing expression.
7616 if Raises_Constraint_Error
(N
) then
7618 Make_Raise_Constraint_Error
(Sloc
(N
),
7619 Reason
=> CE_Range_Check_Failed
);
7620 Set_Etype
(CE_Node
, Etype
(N
));
7621 Set_Raises_Constraint_Error
(CE_Node
);
7623 Rewrite
(N
, Relocate_Node
(CE_Node
));
7624 Set_Raises_Constraint_Error
(N
, True);
7628 -- At this point we have a potentially foldable attribute reference.
7629 -- If Static is set, then the attribute reference definitely obeys
7630 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
7631 -- folded. If Static is not set, then the attribute may or may not
7632 -- be foldable, and the individual attribute processing routines
7633 -- test Static as required in cases where it makes a difference.
7635 -- In the case where Static is not set, we do know that all the
7636 -- expressions present are at least known at compile time (we assumed
7637 -- above that if this was not the case, then there was no hope of static
7638 -- evaluation). However, we did not require that the bounds of the
7639 -- prefix type be compile time known, let alone static). That's because
7640 -- there are many attributes that can be computed at compile time on
7641 -- non-static subtypes, even though such references are not static
7644 -- For VAX float, the root type is an IEEE type. So make sure to use the
7645 -- base type instead of the root-type for floating point attributes.
7649 -- Attributes related to Ada 2012 iterators (placeholder ???)
7651 when Attribute_Constant_Indexing |
7652 Attribute_Default_Iterator |
7653 Attribute_Implicit_Dereference |
7654 Attribute_Iterator_Element |
7655 Attribute_Iterable |
7656 Attribute_Variable_Indexing
=> null;
7658 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7659 -- These were already rejected by the parser. Thus they shouldn't
7662 when Internal_Attribute_Id
=>
7663 raise Program_Error
;
7669 when Attribute_Adjacent
=>
7673 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7680 when Attribute_Aft
=>
7681 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
7687 when Attribute_Alignment
=> Alignment_Block
: declare
7688 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7691 -- Fold if alignment is set and not otherwise
7693 if Known_Alignment
(P_TypeA
) then
7694 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
7696 end Alignment_Block
;
7698 -----------------------------
7699 -- Atomic_Always_Lock_Free --
7700 -----------------------------
7702 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7705 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
7707 V
: constant Entity_Id
:=
7709 (Support_Atomic_Primitives_On_Target
7710 and then Support_Atomic_Primitives
(P_Type
));
7713 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7715 -- Analyze and resolve as boolean. Note that this attribute is a
7716 -- static attribute in GNAT.
7718 Analyze_And_Resolve
(N
, Standard_Boolean
);
7720 Set_Is_Static_Expression
(N
, True);
7721 end Atomic_Always_Lock_Free
;
7727 -- Bit can never be folded
7729 when Attribute_Bit
=>
7736 -- Body_version can never be static
7738 when Attribute_Body_Version
=>
7745 when Attribute_Ceiling
=>
7747 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7749 --------------------
7750 -- Component_Size --
7751 --------------------
7753 when Attribute_Component_Size
=>
7754 if Known_Static_Component_Size
(P_Type
) then
7755 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
7762 when Attribute_Compose
=>
7765 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7772 -- Constrained is never folded for now, there may be cases that
7773 -- could be handled at compile time. To be looked at later.
7775 when Attribute_Constrained
=>
7777 -- The expander might fold it and set the static flag accordingly,
7778 -- but with expansion disabled (as in ASIS), it remains as an
7779 -- attribute reference, and this reference is not static.
7781 Set_Is_Static_Expression
(N
, False);
7788 when Attribute_Copy_Sign
=>
7792 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7799 when Attribute_Definite
=>
7800 Rewrite
(N
, New_Occurrence_Of
(
7801 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
7802 Analyze_And_Resolve
(N
, Standard_Boolean
);
7808 when Attribute_Delta
=>
7809 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
7815 when Attribute_Denorm
=>
7817 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
7819 ---------------------
7820 -- Descriptor_Size --
7821 ---------------------
7823 when Attribute_Descriptor_Size
=>
7830 when Attribute_Digits
=>
7831 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
7837 when Attribute_Emax
=>
7839 -- Ada 83 attribute is defined as (RM83 3.5.8)
7841 -- T'Emax = 4 * T'Mantissa
7843 Fold_Uint
(N
, 4 * Mantissa
, Static
);
7849 when Attribute_Enum_Rep
=>
7851 -- For an enumeration type with a non-standard representation use
7852 -- the Enumeration_Rep field of the proper constant. Note that this
7853 -- will not work for types Character/Wide_[Wide-]Character, since no
7854 -- real entities are created for the enumeration literals, but that
7855 -- does not matter since these two types do not have non-standard
7856 -- representations anyway.
7858 if Is_Enumeration_Type
(P_Type
)
7859 and then Has_Non_Standard_Rep
(P_Type
)
7861 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
7863 -- For enumeration types with standard representations and all
7864 -- other cases (i.e. all integer and modular types), Enum_Rep
7865 -- is equivalent to Pos.
7868 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7875 when Attribute_Enum_Val
=> Enum_Val
: declare
7879 -- We have something like Enum_Type'Enum_Val (23), so search for a
7880 -- corresponding value in the list of Enum_Rep values for the type.
7882 Lit
:= First_Literal
(P_Base_Type
);
7884 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
7885 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
7892 Apply_Compile_Time_Constraint_Error
7893 (N
, "no representation value matches",
7894 CE_Range_Check_Failed
,
7895 Warn
=> not Static
);
7905 when Attribute_Epsilon
=>
7907 -- Ada 83 attribute is defined as (RM83 3.5.8)
7909 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7911 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
7917 when Attribute_Exponent
=>
7919 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7925 when Attribute_First
=> First_Attr
:
7929 if Compile_Time_Known_Value
(Lo_Bound
) then
7930 if Is_Real_Type
(P_Type
) then
7931 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
7933 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7937 Check_Concurrent_Discriminant
(Lo_Bound
);
7945 when Attribute_First_Valid
=> First_Valid
:
7947 if Has_Predicates
(P_Type
)
7948 and then Has_Static_Predicate
(P_Type
)
7951 FirstN
: constant Node_Id
:=
7952 First
(Static_Discrete_Predicate
(P_Type
));
7954 if Nkind
(FirstN
) = N_Range
then
7955 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
7957 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
7963 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7971 when Attribute_Fixed_Value
=>
7978 when Attribute_Floor
=>
7980 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7986 when Attribute_Fore
=>
7987 if Compile_Time_Known_Bounds
(P_Type
) then
7988 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
7995 when Attribute_Fraction
=>
7997 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7999 -----------------------
8000 -- Has_Access_Values --
8001 -----------------------
8003 when Attribute_Has_Access_Values
=>
8004 Rewrite
(N
, New_Occurrence_Of
8005 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8006 Analyze_And_Resolve
(N
, Standard_Boolean
);
8008 -----------------------
8009 -- Has_Discriminants --
8010 -----------------------
8012 when Attribute_Has_Discriminants
=>
8013 Rewrite
(N
, New_Occurrence_Of
(
8014 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8015 Analyze_And_Resolve
(N
, Standard_Boolean
);
8017 ----------------------
8018 -- Has_Same_Storage --
8019 ----------------------
8021 when Attribute_Has_Same_Storage
=>
8024 -----------------------
8025 -- Has_Tagged_Values --
8026 -----------------------
8028 when Attribute_Has_Tagged_Values
=>
8029 Rewrite
(N
, New_Occurrence_Of
8030 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8031 Analyze_And_Resolve
(N
, Standard_Boolean
);
8037 when Attribute_Identity
=>
8044 -- Image is a scalar attribute, but is never static, because it is
8045 -- not a static function (having a non-scalar argument (RM 4.9(22))
8046 -- However, we can constant-fold the image of an enumeration literal
8047 -- if names are available.
8049 when Attribute_Image
=>
8050 if Is_Entity_Name
(E1
)
8051 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8052 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8053 and then not Global_Discard_Names
8056 Lit
: constant Entity_Id
:= Entity
(E1
);
8060 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8061 Set_Casing
(All_Upper_Case
);
8062 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8064 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8065 Analyze_And_Resolve
(N
, Standard_String
);
8066 Set_Is_Static_Expression
(N
, False);
8074 -- Img is a scalar attribute, but is never static, because it is
8075 -- not a static function (having a non-scalar argument (RM 4.9(22))
8077 when Attribute_Img
=>
8084 -- We never try to fold Integer_Value (though perhaps we could???)
8086 when Attribute_Integer_Value
=>
8093 -- Invalid_Value is a scalar attribute that is never static, because
8094 -- the value is by design out of range.
8096 when Attribute_Invalid_Value
=>
8103 when Attribute_Large
=>
8105 -- For fixed-point, we use the identity:
8107 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8109 if Is_Fixed_Point_Type
(P_Type
) then
8111 Make_Op_Multiply
(Loc
,
8113 Make_Op_Subtract
(Loc
,
8117 Make_Real_Literal
(Loc
, Ureal_2
),
8119 Make_Attribute_Reference
(Loc
,
8121 Attribute_Name
=> Name_Mantissa
)),
8122 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8125 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8127 Analyze_And_Resolve
(N
, C_Type
);
8129 -- Floating-point (Ada 83 compatibility)
8132 -- Ada 83 attribute is defined as (RM83 3.5.8)
8134 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8138 -- T'Emax = 4 * T'Mantissa
8142 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8150 when Attribute_Lock_Free
=> Lock_Free
: declare
8151 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8154 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8156 -- Analyze and resolve as boolean. Note that this attribute is a
8157 -- static attribute in GNAT.
8159 Analyze_And_Resolve
(N
, Standard_Boolean
);
8161 Set_Is_Static_Expression
(N
, True);
8168 when Attribute_Last
=> Last_Attr
:
8172 if Compile_Time_Known_Value
(Hi_Bound
) then
8173 if Is_Real_Type
(P_Type
) then
8174 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8176 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8180 Check_Concurrent_Discriminant
(Hi_Bound
);
8188 when Attribute_Last_Valid
=> Last_Valid
:
8190 if Has_Predicates
(P_Type
)
8191 and then Has_Static_Predicate
(P_Type
)
8194 LastN
: constant Node_Id
:=
8195 Last
(Static_Discrete_Predicate
(P_Type
));
8197 if Nkind
(LastN
) = N_Range
then
8198 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8200 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8206 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8214 when Attribute_Leading_Part
=>
8217 Eval_Fat
.Leading_Part
8218 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8225 when Attribute_Length
=> Length
: declare
8229 -- If any index type is a formal type, or derived from one, the
8230 -- bounds are not static. Treating them as static can produce
8231 -- spurious warnings or improper constant folding.
8233 Ind
:= First_Index
(P_Type
);
8234 while Present
(Ind
) loop
8235 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8244 -- For two compile time values, we can compute length
8246 if Compile_Time_Known_Value
(Lo_Bound
)
8247 and then Compile_Time_Known_Value
(Hi_Bound
)
8250 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8254 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8255 -- comparable, and we can figure out the difference between them.
8258 Diff
: aliased Uint
;
8262 Compile_Time_Compare
8263 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8266 Fold_Uint
(N
, Uint_1
, Static
);
8269 Fold_Uint
(N
, Uint_0
, Static
);
8272 if Diff
/= No_Uint
then
8273 Fold_Uint
(N
, Diff
+ 1, Static
);
8286 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8287 -- of the said attribute at the point of entry into the related loop. As
8288 -- such, the attribute reference does not need to be evaluated because
8289 -- the prefix is the one that is evaluted.
8291 when Attribute_Loop_Entry
=>
8298 when Attribute_Machine
=>
8302 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8309 when Attribute_Machine_Emax
=>
8310 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8316 when Attribute_Machine_Emin
=>
8317 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8319 ----------------------
8320 -- Machine_Mantissa --
8321 ----------------------
8323 when Attribute_Machine_Mantissa
=>
8324 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8326 -----------------------
8327 -- Machine_Overflows --
8328 -----------------------
8330 when Attribute_Machine_Overflows
=>
8332 -- Always true for fixed-point
8334 if Is_Fixed_Point_Type
(P_Type
) then
8335 Fold_Uint
(N
, True_Value
, Static
);
8337 -- Floating point case
8341 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8349 when Attribute_Machine_Radix
=>
8350 if Is_Fixed_Point_Type
(P_Type
) then
8351 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8352 and then Machine_Radix_10
(P_Type
)
8354 Fold_Uint
(N
, Uint_10
, Static
);
8356 Fold_Uint
(N
, Uint_2
, Static
);
8359 -- All floating-point type always have radix 2
8362 Fold_Uint
(N
, Uint_2
, Static
);
8365 ----------------------
8366 -- Machine_Rounding --
8367 ----------------------
8369 -- Note: for the folding case, it is fine to treat Machine_Rounding
8370 -- exactly the same way as Rounding, since this is one of the allowed
8371 -- behaviors, and performance is not an issue here. It might be a bit
8372 -- better to give the same result as it would give at run time, even
8373 -- though the non-determinism is certainly permitted.
8375 when Attribute_Machine_Rounding
=>
8377 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8379 --------------------
8380 -- Machine_Rounds --
8381 --------------------
8383 when Attribute_Machine_Rounds
=>
8385 -- Always False for fixed-point
8387 if Is_Fixed_Point_Type
(P_Type
) then
8388 Fold_Uint
(N
, False_Value
, Static
);
8390 -- Else yield proper floating-point result
8394 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8402 -- Note: Machine_Size is identical to Object_Size
8404 when Attribute_Machine_Size
=> Machine_Size
: declare
8405 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8408 if Known_Esize
(P_TypeA
) then
8409 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8417 when Attribute_Mantissa
=>
8419 -- Fixed-point mantissa
8421 if Is_Fixed_Point_Type
(P_Type
) then
8423 -- Compile time foldable case
8425 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8427 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8429 -- The calculation of the obsolete Ada 83 attribute Mantissa
8430 -- is annoying, because of AI00143, quoted here:
8432 -- !question 84-01-10
8434 -- Consider the model numbers for F:
8436 -- type F is delta 1.0 range -7.0 .. 8.0;
8438 -- The wording requires that F'MANTISSA be the SMALLEST
8439 -- integer number for which each bound of the specified
8440 -- range is either a model number or lies at most small
8441 -- distant from a model number. This means F'MANTISSA
8442 -- is required to be 3 since the range -7.0 .. 7.0 fits
8443 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8444 -- number, namely, 7. Is this analysis correct? Note that
8445 -- this implies the upper bound of the range is not
8446 -- represented as a model number.
8448 -- !response 84-03-17
8450 -- The analysis is correct. The upper and lower bounds for
8451 -- a fixed point type can lie outside the range of model
8462 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8463 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8464 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8465 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8467 -- If the Bound is exactly a model number, i.e. a multiple
8468 -- of Small, then we back it off by one to get the integer
8469 -- value that must be representable.
8471 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8472 Max_Man
:= Max_Man
- 1;
8475 -- Now find corresponding size = Mantissa value
8478 while 2 ** Siz
< Max_Man
loop
8482 Fold_Uint
(N
, Siz
, Static
);
8486 -- The case of dynamic bounds cannot be evaluated at compile
8487 -- time. Instead we use a runtime routine (see Exp_Attr).
8492 -- Floating-point Mantissa
8495 Fold_Uint
(N
, Mantissa
, Static
);
8502 when Attribute_Max
=> Max
:
8504 if Is_Real_Type
(P_Type
) then
8506 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8508 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8512 ----------------------------------
8513 -- Max_Alignment_For_Allocation --
8514 ----------------------------------
8516 -- Max_Alignment_For_Allocation is usually the Alignment. However,
8517 -- arrays are allocated with dope, so we need to take into account both
8518 -- the alignment of the array, which comes from the component alignment,
8519 -- and the alignment of the dope. Also, if the alignment is unknown, we
8520 -- use the max (it's OK to be pessimistic).
8522 when Attribute_Max_Alignment_For_Allocation
=>
8524 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
8526 if Known_Alignment
(P_Type
) and then
8527 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
8529 A
:= Alignment
(P_Type
);
8532 Fold_Uint
(N
, A
, Static
);
8535 ----------------------------------
8536 -- Max_Size_In_Storage_Elements --
8537 ----------------------------------
8539 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
8540 -- Storage_Unit boundary. We can fold any cases for which the size
8541 -- is known by the front end.
8543 when Attribute_Max_Size_In_Storage_Elements
=>
8544 if Known_Esize
(P_Type
) then
8546 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
8547 System_Storage_Unit
,
8551 --------------------
8552 -- Mechanism_Code --
8553 --------------------
8555 when Attribute_Mechanism_Code
=>
8559 Mech
: Mechanism_Type
;
8563 Mech
:= Mechanism
(P_Entity
);
8566 Val
:= UI_To_Int
(Expr_Value
(E1
));
8568 Formal
:= First_Formal
(P_Entity
);
8569 for J
in 1 .. Val
- 1 loop
8570 Next_Formal
(Formal
);
8572 Mech
:= Mechanism
(Formal
);
8576 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
8584 when Attribute_Min
=> Min
:
8586 if Is_Real_Type
(P_Type
) then
8588 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8591 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8599 when Attribute_Mod
=>
8601 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
8607 when Attribute_Model
=>
8609 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8615 when Attribute_Model_Emin
=>
8616 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
8622 when Attribute_Model_Epsilon
=>
8623 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
8625 --------------------
8626 -- Model_Mantissa --
8627 --------------------
8629 when Attribute_Model_Mantissa
=>
8630 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
8636 when Attribute_Model_Small
=>
8637 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
8643 when Attribute_Modulus
=>
8644 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
8646 --------------------
8647 -- Null_Parameter --
8648 --------------------
8650 -- Cannot fold, we know the value sort of, but the whole point is
8651 -- that there is no way to talk about this imaginary value except
8652 -- by using the attribute, so we leave it the way it is.
8654 when Attribute_Null_Parameter
=>
8661 -- The Object_Size attribute for a type returns the Esize of the
8662 -- type and can be folded if this value is known.
8664 when Attribute_Object_Size
=> Object_Size
: declare
8665 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8668 if Known_Esize
(P_TypeA
) then
8669 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8673 ----------------------
8674 -- Overlaps_Storage --
8675 ----------------------
8677 when Attribute_Overlaps_Storage
=>
8680 -------------------------
8681 -- Passed_By_Reference --
8682 -------------------------
8684 -- Scalar types are never passed by reference
8686 when Attribute_Passed_By_Reference
=>
8687 Fold_Uint
(N
, False_Value
, Static
);
8693 when Attribute_Pos
=>
8694 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8700 when Attribute_Pred
=> Pred
:
8702 -- Floating-point case
8704 if Is_Floating_Point_Type
(P_Type
) then
8706 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8710 elsif Is_Fixed_Point_Type
(P_Type
) then
8712 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
8714 -- Modular integer case (wraps)
8716 elsif Is_Modular_Integer_Type
(P_Type
) then
8717 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
8719 -- Other scalar cases
8722 pragma Assert
(Is_Scalar_Type
(P_Type
));
8724 if Is_Enumeration_Type
(P_Type
)
8725 and then Expr_Value
(E1
) =
8726 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8728 Apply_Compile_Time_Constraint_Error
8729 (N
, "Pred of `&''First`",
8730 CE_Overflow_Check_Failed
,
8732 Warn
=> not Static
);
8738 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
8746 -- No processing required, because by this stage, Range has been
8747 -- replaced by First .. Last, so this branch can never be taken.
8749 when Attribute_Range
=>
8750 raise Program_Error
;
8756 when Attribute_Range_Length
=>
8759 -- Can fold if both bounds are compile time known
8761 if Compile_Time_Known_Value
(Hi_Bound
)
8762 and then Compile_Time_Known_Value
(Lo_Bound
)
8766 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
8770 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8771 -- comparable, and we can figure out the difference between them.
8774 Diff
: aliased Uint
;
8778 Compile_Time_Compare
8779 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8782 Fold_Uint
(N
, Uint_1
, Static
);
8785 Fold_Uint
(N
, Uint_0
, Static
);
8788 if Diff
/= No_Uint
then
8789 Fold_Uint
(N
, Diff
+ 1, Static
);
8801 when Attribute_Ref
=>
8802 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8808 when Attribute_Remainder
=> Remainder
: declare
8809 X
: constant Ureal
:= Expr_Value_R
(E1
);
8810 Y
: constant Ureal
:= Expr_Value_R
(E2
);
8813 if UR_Is_Zero
(Y
) then
8814 Apply_Compile_Time_Constraint_Error
8815 (N
, "division by zero in Remainder",
8816 CE_Overflow_Check_Failed
,
8817 Warn
=> not Static
);
8823 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
8830 when Attribute_Restriction_Set
=> Restriction_Set
: declare
8832 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
8833 Set_Is_Static_Expression
(N
);
8834 end Restriction_Set
;
8840 when Attribute_Round
=> Round
:
8846 -- First we get the (exact result) in units of small
8848 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
8850 -- Now round that exactly to an integer
8852 Si
:= UR_To_Uint
(Sr
);
8854 -- Finally the result is obtained by converting back to real
8856 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
8863 when Attribute_Rounding
=>
8865 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8871 when Attribute_Safe_Emax
=>
8872 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
8878 when Attribute_Safe_First
=>
8879 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
8885 when Attribute_Safe_Large
=>
8886 if Is_Fixed_Point_Type
(P_Type
) then
8888 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
8890 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8897 when Attribute_Safe_Last
=>
8898 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8904 when Attribute_Safe_Small
=>
8906 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8907 -- for fixed-point, since is the same as Small, but we implement
8908 -- it for backwards compatibility.
8910 if Is_Fixed_Point_Type
(P_Type
) then
8911 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
8913 -- Ada 83 Safe_Small for floating-point cases
8916 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
8923 when Attribute_Scale
=>
8924 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
8930 when Attribute_Scaling
=>
8934 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8941 when Attribute_Signed_Zeros
=>
8943 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
8949 -- Size attribute returns the RM size. All scalar types can be folded,
8950 -- as well as any types for which the size is known by the front end,
8951 -- including any type for which a size attribute is specified. This is
8952 -- one of the places where it is annoying that a size of zero means two
8953 -- things (zero size for scalars, unspecified size for non-scalars).
8955 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
8956 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8959 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
8963 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
8965 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
8968 -- If a size clause applies, then use the size from it.
8969 -- This is one of the rare cases where we can use the
8970 -- Size_Clause field for a subtype when Has_Size_Clause
8971 -- is False. Consider:
8973 -- type x is range 1 .. 64;
8974 -- for x'size use 12;
8975 -- subtype y is x range 0 .. 3;
8977 -- Here y has a size clause inherited from x, but normally
8978 -- it does not apply, and y'size is 2. However, y'VADS_Size
8979 -- is indeed 12 and not 2.
8982 and then Is_OK_Static_Expression
(Expression
(S
))
8984 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
8986 -- If no size is specified, then we simply use the object
8987 -- size in the VADS_Size case (e.g. Natural'Size is equal
8988 -- to Integer'Size, not one less).
8991 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8995 -- Normal case (Size) in which case we want the RM_Size
8998 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9007 when Attribute_Small
=>
9009 -- The floating-point case is present only for Ada 83 compatibility.
9010 -- Note that strictly this is an illegal addition, since we are
9011 -- extending an Ada 95 defined attribute, but we anticipate an
9012 -- ARG ruling that will permit this.
9014 if Is_Floating_Point_Type
(P_Type
) then
9016 -- Ada 83 attribute is defined as (RM83 3.5.8)
9018 -- T'Small = 2.0**(-T'Emax - 1)
9022 -- T'Emax = 4 * T'Mantissa
9024 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9026 -- Normal Ada 95 fixed-point case
9029 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9036 when Attribute_Stream_Size
=>
9043 when Attribute_Succ
=> Succ
:
9045 -- Floating-point case
9047 if Is_Floating_Point_Type
(P_Type
) then
9049 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9053 elsif Is_Fixed_Point_Type
(P_Type
) then
9054 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9056 -- Modular integer case (wraps)
9058 elsif Is_Modular_Integer_Type
(P_Type
) then
9059 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9061 -- Other scalar cases
9064 pragma Assert
(Is_Scalar_Type
(P_Type
));
9066 if Is_Enumeration_Type
(P_Type
)
9067 and then Expr_Value
(E1
) =
9068 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9070 Apply_Compile_Time_Constraint_Error
9071 (N
, "Succ of `&''Last`",
9072 CE_Overflow_Check_Failed
,
9074 Warn
=> not Static
);
9079 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9088 when Attribute_Truncation
=>
9091 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9098 when Attribute_Type_Class
=> Type_Class
: declare
9099 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9103 if Is_Descendent_Of_Address
(Typ
) then
9104 Id
:= RE_Type_Class_Address
;
9106 elsif Is_Enumeration_Type
(Typ
) then
9107 Id
:= RE_Type_Class_Enumeration
;
9109 elsif Is_Integer_Type
(Typ
) then
9110 Id
:= RE_Type_Class_Integer
;
9112 elsif Is_Fixed_Point_Type
(Typ
) then
9113 Id
:= RE_Type_Class_Fixed_Point
;
9115 elsif Is_Floating_Point_Type
(Typ
) then
9116 Id
:= RE_Type_Class_Floating_Point
;
9118 elsif Is_Array_Type
(Typ
) then
9119 Id
:= RE_Type_Class_Array
;
9121 elsif Is_Record_Type
(Typ
) then
9122 Id
:= RE_Type_Class_Record
;
9124 elsif Is_Access_Type
(Typ
) then
9125 Id
:= RE_Type_Class_Access
;
9127 elsif Is_Enumeration_Type
(Typ
) then
9128 Id
:= RE_Type_Class_Enumeration
;
9130 elsif Is_Task_Type
(Typ
) then
9131 Id
:= RE_Type_Class_Task
;
9133 -- We treat protected types like task types. It would make more
9134 -- sense to have another enumeration value, but after all the
9135 -- whole point of this feature is to be exactly DEC compatible,
9136 -- and changing the type Type_Class would not meet this requirement.
9138 elsif Is_Protected_Type
(Typ
) then
9139 Id
:= RE_Type_Class_Task
;
9141 -- Not clear if there are any other possibilities, but if there
9142 -- are, then we will treat them as the address case.
9145 Id
:= RE_Type_Class_Address
;
9148 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9151 -----------------------
9152 -- Unbiased_Rounding --
9153 -----------------------
9155 when Attribute_Unbiased_Rounding
=>
9158 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9161 -------------------------
9162 -- Unconstrained_Array --
9163 -------------------------
9165 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9166 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9169 Rewrite
(N
, New_Occurrence_Of
(
9171 Is_Array_Type
(P_Type
)
9172 and then not Is_Constrained
(Typ
)), Loc
));
9174 -- Analyze and resolve as boolean, note that this attribute is
9175 -- a static attribute in GNAT.
9177 Analyze_And_Resolve
(N
, Standard_Boolean
);
9179 Set_Is_Static_Expression
(N
, True);
9180 end Unconstrained_Array
;
9182 -- Attribute Update is never static
9184 when Attribute_Update
=>
9191 -- Processing is shared with Size
9197 when Attribute_Val
=> Val
:
9199 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9201 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9203 Apply_Compile_Time_Constraint_Error
9204 (N
, "Val expression out of range",
9205 CE_Range_Check_Failed
,
9206 Warn
=> not Static
);
9212 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9220 -- The Value_Size attribute for a type returns the RM size of the type.
9221 -- This an always be folded for scalar types, and can also be folded for
9222 -- non-scalar types if the size is set. This is one of the places where
9223 -- it is annoying that a size of zero means two things!
9225 when Attribute_Value_Size
=> Value_Size
: declare
9226 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9228 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9229 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9237 -- Version can never be static
9239 when Attribute_Version
=>
9246 -- Wide_Image is a scalar attribute, but is never static, because it
9247 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9249 when Attribute_Wide_Image
=>
9252 ---------------------
9253 -- Wide_Wide_Image --
9254 ---------------------
9256 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9257 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9259 when Attribute_Wide_Wide_Image
=>
9262 ---------------------
9263 -- Wide_Wide_Width --
9264 ---------------------
9266 -- Processing for Wide_Wide_Width is combined with Width
9272 -- Processing for Wide_Width is combined with Width
9278 -- This processing also handles the case of Wide_[Wide_]Width
9280 when Attribute_Width |
9281 Attribute_Wide_Width |
9282 Attribute_Wide_Wide_Width
=> Width
:
9284 if Compile_Time_Known_Bounds
(P_Type
) then
9286 -- Floating-point types
9288 if Is_Floating_Point_Type
(P_Type
) then
9290 -- Width is zero for a null range (RM 3.5 (38))
9292 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9293 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9295 Fold_Uint
(N
, Uint_0
, Static
);
9298 -- For floating-point, we have +N.dddE+nnn where length
9299 -- of ddd is determined by type'Digits - 1, but is one
9300 -- if Digits is one (RM 3.5 (33)).
9302 -- nnn is set to 2 for Short_Float and Float (32 bit
9303 -- floats), and 3 for Long_Float and Long_Long_Float.
9304 -- For machines where Long_Long_Float is the IEEE
9305 -- extended precision type, the exponent takes 4 digits.
9309 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9312 if Esize
(P_Type
) <= 32 then
9314 elsif Esize
(P_Type
) = 64 then
9320 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9324 -- Fixed-point types
9326 elsif Is_Fixed_Point_Type
(P_Type
) then
9328 -- Width is zero for a null range (RM 3.5 (38))
9330 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9331 Expr_Value
(Type_Low_Bound
(P_Type
))
9333 Fold_Uint
(N
, Uint_0
, Static
);
9335 -- The non-null case depends on the specific real type
9338 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9341 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9349 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9350 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9351 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9364 -- Width for types derived from Standard.Character
9365 -- and Standard.Wide_[Wide_]Character.
9367 elsif Is_Standard_Character_Type
(P_Type
) then
9370 -- Set W larger if needed
9372 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9374 -- All wide characters look like Hex_hhhhhhhh
9378 -- No need to compute this more than once
9383 C
:= Character'Val (J
);
9385 -- Test for all cases where Character'Image
9386 -- yields an image that is longer than three
9387 -- characters. First the cases of Reserved_xxx
9388 -- names (length = 12).
9391 when Reserved_128 | Reserved_129 |
9392 Reserved_132 | Reserved_153
9395 when BS | HT | LF | VT | FF | CR |
9396 SO | SI | EM | FS | GS | RS |
9397 US | RI | MW | ST | PM
9400 when NUL | SOH | STX | ETX | EOT |
9401 ENQ | ACK | BEL | DLE | DC1 |
9402 DC2 | DC3 | DC4 | NAK | SYN |
9403 ETB | CAN | SUB | ESC | DEL |
9404 BPH | NBH | NEL | SSA | ESA |
9405 HTS | HTJ | VTS | PLD | PLU |
9406 SS2 | SS3 | DCS | PU1 | PU2 |
9407 STS | CCH | SPA | EPA | SOS |
9408 SCI | CSI | OSC | APC
9411 when Space
.. Tilde |
9412 No_Break_Space
.. LC_Y_Diaeresis
9414 -- Special case of soft hyphen in Ada 2005
9416 if C
= Character'Val (16#AD#
)
9417 and then Ada_Version
>= Ada_2005
9425 W
:= Int
'Max (W
, Wt
);
9429 -- Width for types derived from Standard.Boolean
9431 elsif R
= Standard_Boolean
then
9438 -- Width for integer types
9440 elsif Is_Integer_Type
(P_Type
) then
9441 T
:= UI_Max
(abs Lo
, abs Hi
);
9449 -- User declared enum type with discard names
9451 elsif Discard_Names
(R
) then
9453 -- If range is null, result is zero, that has already
9454 -- been dealt with, so what we need is the power of ten
9455 -- that accomodates the Pos of the largest value, which
9456 -- is the high bound of the range + one for the space.
9465 -- Only remaining possibility is user declared enum type
9466 -- with normal case of Discard_Names not active.
9469 pragma Assert
(Is_Enumeration_Type
(P_Type
));
9472 L
:= First_Literal
(P_Type
);
9473 while Present
(L
) loop
9475 -- Only pay attention to in range characters
9477 if Lo
<= Enumeration_Pos
(L
)
9478 and then Enumeration_Pos
(L
) <= Hi
9480 -- For Width case, use decoded name
9482 if Id
= Attribute_Width
then
9483 Get_Decoded_Name_String
(Chars
(L
));
9484 Wt
:= Nat
(Name_Len
);
9486 -- For Wide_[Wide_]Width, use encoded name, and
9487 -- then adjust for the encoding.
9490 Get_Name_String
(Chars
(L
));
9492 -- Character literals are always of length 3
9494 if Name_Buffer
(1) = 'Q' then
9497 -- Otherwise loop to adjust for upper/wide chars
9500 Wt
:= Nat
(Name_Len
);
9502 for J
in 1 .. Name_Len
loop
9503 if Name_Buffer
(J
) = 'U' then
9505 elsif Name_Buffer
(J
) = 'W' then
9512 W
:= Int
'Max (W
, Wt
);
9519 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
9525 -- The following attributes denote functions that cannot be folded
9527 when Attribute_From_Any |
9529 Attribute_TypeCode
=>
9532 -- The following attributes can never be folded, and furthermore we
9533 -- should not even have entered the case statement for any of these.
9534 -- Note that in some cases, the values have already been folded as
9535 -- a result of the processing in Analyze_Attribute.
9537 when Attribute_Abort_Signal |
9540 Attribute_Address_Size |
9541 Attribute_Asm_Input |
9542 Attribute_Asm_Output |
9544 Attribute_Bit_Order |
9545 Attribute_Bit_Position |
9546 Attribute_Callable |
9549 Attribute_Code_Address |
9550 Attribute_Compiler_Version |
9552 Attribute_Default_Bit_Order |
9553 Attribute_Elaborated |
9554 Attribute_Elab_Body |
9555 Attribute_Elab_Spec |
9556 Attribute_Elab_Subp_Body |
9558 Attribute_External_Tag |
9559 Attribute_Fast_Math |
9560 Attribute_First_Bit |
9562 Attribute_Last_Bit |
9563 Attribute_Library_Level |
9564 Attribute_Maximum_Alignment |
9567 Attribute_Partition_ID |
9568 Attribute_Pool_Address |
9569 Attribute_Position |
9570 Attribute_Priority |
9573 Attribute_Scalar_Storage_Order |
9574 Attribute_Simple_Storage_Pool |
9575 Attribute_Storage_Pool |
9576 Attribute_Storage_Size |
9577 Attribute_Storage_Unit |
9578 Attribute_Stub_Type |
9579 Attribute_System_Allocator_Alignment |
9581 Attribute_Target_Name |
9582 Attribute_Terminated |
9583 Attribute_To_Address |
9584 Attribute_Type_Key |
9585 Attribute_UET_Address |
9586 Attribute_Unchecked_Access |
9587 Attribute_Universal_Literal_String |
9588 Attribute_Unrestricted_Access |
9590 Attribute_Valid_Scalars |
9592 Attribute_Wchar_T_Size |
9593 Attribute_Wide_Value |
9594 Attribute_Wide_Wide_Value |
9595 Attribute_Word_Size |
9598 raise Program_Error
;
9601 -- At the end of the case, one more check. If we did a static evaluation
9602 -- so that the result is now a literal, then set Is_Static_Expression
9603 -- in the constant only if the prefix type is a static subtype. For
9604 -- non-static subtypes, the folding is still OK, but not static.
9606 -- An exception is the GNAT attribute Constrained_Array which is
9607 -- defined to be a static attribute in all cases.
9609 if Nkind_In
(N
, N_Integer_Literal
,
9611 N_Character_Literal
,
9613 or else (Is_Entity_Name
(N
)
9614 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
9616 Set_Is_Static_Expression
(N
, Static
);
9618 -- If this is still an attribute reference, then it has not been folded
9619 -- and that means that its expressions are in a non-static context.
9621 elsif Nkind
(N
) = N_Attribute_Reference
then
9624 -- Note: the else case not covered here are odd cases where the
9625 -- processing has transformed the attribute into something other
9626 -- than a constant. Nothing more to do in such cases.
9633 ------------------------------
9634 -- Is_Anonymous_Tagged_Base --
9635 ------------------------------
9637 function Is_Anonymous_Tagged_Base
9639 Typ
: Entity_Id
) return Boolean
9643 Anon
= Current_Scope
9644 and then Is_Itype
(Anon
)
9645 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
9646 end Is_Anonymous_Tagged_Base
;
9648 --------------------------------
9649 -- Name_Implies_Lvalue_Prefix --
9650 --------------------------------
9652 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
9653 pragma Assert
(Is_Attribute_Name
(Nam
));
9655 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
9656 end Name_Implies_Lvalue_Prefix
;
9658 -----------------------
9659 -- Resolve_Attribute --
9660 -----------------------
9662 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
9663 Loc
: constant Source_Ptr
:= Sloc
(N
);
9664 P
: constant Node_Id
:= Prefix
(N
);
9665 Aname
: constant Name_Id
:= Attribute_Name
(N
);
9666 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
9667 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9668 Des_Btyp
: Entity_Id
;
9669 Index
: Interp_Index
;
9671 Nom_Subt
: Entity_Id
;
9673 procedure Accessibility_Message
;
9674 -- Error, or warning within an instance, if the static accessibility
9675 -- rules of 3.10.2 are violated.
9677 ---------------------------
9678 -- Accessibility_Message --
9679 ---------------------------
9681 procedure Accessibility_Message
is
9682 Indic
: Node_Id
:= Parent
(Parent
(N
));
9685 -- In an instance, this is a runtime check, but one we
9686 -- know will fail, so generate an appropriate warning.
9688 if In_Instance_Body
then
9689 Error_Msg_Warn
:= SPARK_Mode
/= On
;
9691 ("non-local pointer cannot point to local object<<", P
);
9692 Error_Msg_F
("\Program_Error [<<", P
);
9694 Make_Raise_Program_Error
(Loc
,
9695 Reason
=> PE_Accessibility_Check_Failed
));
9700 Error_Msg_F
("non-local pointer cannot point to local object", P
);
9702 -- Check for case where we have a missing access definition
9704 if Is_Record_Type
(Current_Scope
)
9706 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
9707 N_Index_Or_Discriminant_Constraint
)
9709 Indic
:= Parent
(Parent
(N
));
9710 while Present
(Indic
)
9711 and then Nkind
(Indic
) /= N_Subtype_Indication
9713 Indic
:= Parent
(Indic
);
9716 if Present
(Indic
) then
9718 ("\use an access definition for" &
9719 " the access discriminant of&",
9720 N
, Entity
(Subtype_Mark
(Indic
)));
9724 end Accessibility_Message
;
9726 -- Start of processing for Resolve_Attribute
9729 -- If error during analysis, no point in continuing, except for array
9730 -- types, where we get better recovery by using unconstrained indexes
9731 -- than nothing at all (see Check_Array_Type).
9734 and then Attr_Id
/= Attribute_First
9735 and then Attr_Id
/= Attribute_Last
9736 and then Attr_Id
/= Attribute_Length
9737 and then Attr_Id
/= Attribute_Range
9742 -- If attribute was universal type, reset to actual type
9744 if Etype
(N
) = Universal_Integer
9745 or else Etype
(N
) = Universal_Real
9750 -- Remaining processing depends on attribute
9758 -- For access attributes, if the prefix denotes an entity, it is
9759 -- interpreted as a name, never as a call. It may be overloaded,
9760 -- in which case resolution uses the profile of the context type.
9761 -- Otherwise prefix must be resolved.
9763 when Attribute_Access
9764 | Attribute_Unchecked_Access
9765 | Attribute_Unrestricted_Access
=>
9769 if Is_Variable
(P
) then
9770 Note_Possible_Modification
(P
, Sure
=> False);
9773 -- The following comes from a query concerning improper use of
9774 -- universal_access in equality tests involving anonymous access
9775 -- types. Another good reason for 'Ref, but for now disable the
9776 -- test, which breaks several filed tests???
9778 if Ekind
(Typ
) = E_Anonymous_Access_Type
9779 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
9782 Error_Msg_N
("need unique type to resolve 'Access", N
);
9783 Error_Msg_N
("\qualify attribute with some access type", N
);
9786 -- Case where prefix is an entity name
9788 if Is_Entity_Name
(P
) then
9790 -- Deal with case where prefix itself is overloaded
9792 if Is_Overloaded
(P
) then
9793 Get_First_Interp
(P
, Index
, It
);
9794 while Present
(It
.Nam
) loop
9795 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
9796 Set_Entity
(P
, It
.Nam
);
9798 -- The prefix is definitely NOT overloaded anymore at
9799 -- this point, so we reset the Is_Overloaded flag to
9800 -- avoid any confusion when reanalyzing the node.
9802 Set_Is_Overloaded
(P
, False);
9803 Set_Is_Overloaded
(N
, False);
9804 Generate_Reference
(Entity
(P
), P
);
9808 Get_Next_Interp
(Index
, It
);
9811 -- If Prefix is a subprogram name, this reference freezes:
9813 -- If it is a type, there is nothing to resolve.
9814 -- If it is an object, complete its resolution.
9816 elsif Is_Overloadable
(Entity
(P
)) then
9818 -- Avoid insertion of freeze actions in spec expression mode
9820 if not In_Spec_Expression
then
9821 Freeze_Before
(N
, Entity
(P
));
9824 -- Nothing to do if prefix is a type name
9826 elsif Is_Type
(Entity
(P
)) then
9829 -- Otherwise non-overloaded other case, resolve the prefix
9835 -- Some further error checks
9837 Error_Msg_Name_1
:= Aname
;
9839 if not Is_Entity_Name
(P
) then
9842 elsif Is_Overloadable
(Entity
(P
))
9843 and then Is_Abstract_Subprogram
(Entity
(P
))
9845 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
9846 Set_Etype
(N
, Any_Type
);
9848 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
9850 ("prefix of % attribute cannot be enumeration literal", P
);
9851 Set_Etype
(N
, Any_Type
);
9853 -- An attempt to take 'Access of a function that renames an
9854 -- enumeration literal. Issue a specialized error message.
9856 elsif Ekind
(Entity
(P
)) = E_Function
9857 and then Present
(Alias
(Entity
(P
)))
9858 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
9861 ("prefix of % attribute cannot be function renaming "
9862 & "an enumeration literal", P
);
9863 Set_Etype
(N
, Any_Type
);
9865 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
9866 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
9867 Set_Etype
(N
, Any_Type
);
9870 -- Assignments, return statements, components of aggregates,
9871 -- generic instantiations will require convention checks if
9872 -- the type is an access to subprogram. Given that there will
9873 -- also be accessibility checks on those, this is where the
9874 -- checks can eventually be centralized ???
9876 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9877 E_Anonymous_Access_Subprogram_Type
,
9878 E_Access_Protected_Subprogram_Type
,
9879 E_Anonymous_Access_Protected_Subprogram_Type
)
9881 -- Deal with convention mismatch
9883 if Convention
(Designated_Type
(Btyp
)) /=
9884 Convention
(Entity
(P
))
9887 ("subprogram & has wrong convention", P
, Entity
(P
));
9888 Error_Msg_Sloc
:= Sloc
(Btyp
);
9889 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
9891 if not Is_Itype
(Btyp
)
9892 and then not Has_Convention_Pragma
(Btyp
)
9895 ("\probable missing pragma Convention for &",
9900 Check_Subtype_Conformant
9901 (New_Id
=> Entity
(P
),
9902 Old_Id
=> Designated_Type
(Btyp
),
9906 if Attr_Id
= Attribute_Unchecked_Access
then
9907 Error_Msg_Name_1
:= Aname
;
9909 ("attribute% cannot be applied to a subprogram", P
);
9911 elsif Aname
= Name_Unrestricted_Access
then
9912 null; -- Nothing to check
9914 -- Check the static accessibility rule of 3.10.2(32).
9915 -- This rule also applies within the private part of an
9916 -- instantiation. This rule does not apply to anonymous
9917 -- access-to-subprogram types in access parameters.
9919 elsif Attr_Id
= Attribute_Access
9920 and then not In_Instance_Body
9922 (Ekind
(Btyp
) = E_Access_Subprogram_Type
9923 or else Is_Local_Anonymous_Access
(Btyp
))
9924 and then Subprogram_Access_Level
(Entity
(P
)) >
9925 Type_Access_Level
(Btyp
)
9928 ("subprogram must not be deeper than access type", P
);
9930 -- Check the restriction of 3.10.2(32) that disallows the
9931 -- access attribute within a generic body when the ultimate
9932 -- ancestor of the type of the attribute is declared outside
9933 -- of the generic unit and the subprogram is declared within
9934 -- that generic unit. This includes any such attribute that
9935 -- occurs within the body of a generic unit that is a child
9936 -- of the generic unit where the subprogram is declared.
9938 -- The rule also prohibits applying the attribute when the
9939 -- access type is a generic formal access type (since the
9940 -- level of the actual type is not known). This restriction
9941 -- does not apply when the attribute type is an anonymous
9942 -- access-to-subprogram type. Note that this check was
9943 -- revised by AI-229, because the originally Ada 95 rule
9944 -- was too lax. The original rule only applied when the
9945 -- subprogram was declared within the body of the generic,
9946 -- which allowed the possibility of dangling references).
9947 -- The rule was also too strict in some case, in that it
9948 -- didn't permit the access to be declared in the generic
9949 -- spec, whereas the revised rule does (as long as it's not
9952 -- There are a couple of subtleties of the test for applying
9953 -- the check that are worth noting. First, we only apply it
9954 -- when the levels of the subprogram and access type are the
9955 -- same (the case where the subprogram is statically deeper
9956 -- was applied above, and the case where the type is deeper
9957 -- is always safe). Second, we want the check to apply
9958 -- within nested generic bodies and generic child unit
9959 -- bodies, but not to apply to an attribute that appears in
9960 -- the generic unit's specification. This is done by testing
9961 -- that the attribute's innermost enclosing generic body is
9962 -- not the same as the innermost generic body enclosing the
9963 -- generic unit where the subprogram is declared (we don't
9964 -- want the check to apply when the access attribute is in
9965 -- the spec and there's some other generic body enclosing
9966 -- generic). Finally, there's no point applying the check
9967 -- when within an instance, because any violations will have
9968 -- been caught by the compilation of the generic unit.
9970 -- We relax this check in Relaxed_RM_Semantics mode for
9971 -- compatibility with legacy code for use by Ada source
9972 -- code analyzers (e.g. CodePeer).
9974 elsif Attr_Id
= Attribute_Access
9975 and then not Relaxed_RM_Semantics
9976 and then not In_Instance
9977 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
9978 and then Present
(Enclosing_Generic_Body
(N
))
9979 and then Enclosing_Generic_Body
(N
) /=
9980 Enclosing_Generic_Body
9981 (Enclosing_Generic_Unit
(Entity
(P
)))
9982 and then Subprogram_Access_Level
(Entity
(P
)) =
9983 Type_Access_Level
(Btyp
)
9984 and then Ekind
(Btyp
) /=
9985 E_Anonymous_Access_Subprogram_Type
9986 and then Ekind
(Btyp
) /=
9987 E_Anonymous_Access_Protected_Subprogram_Type
9989 -- The attribute type's ultimate ancestor must be
9990 -- declared within the same generic unit as the
9991 -- subprogram is declared. The error message is
9992 -- specialized to say "ancestor" for the case where the
9993 -- access type is not its own ancestor, since saying
9994 -- simply "access type" would be very confusing.
9996 if Enclosing_Generic_Unit
(Entity
(P
)) /=
9997 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
10000 ("''Access attribute not allowed in generic body",
10003 if Root_Type
(Btyp
) = Btyp
then
10006 "access type & is declared outside " &
10007 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10010 ("\because ancestor of " &
10011 "access type & is declared outside " &
10012 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10016 ("\move ''Access to private part, or " &
10017 "(Ada 2005) use anonymous access type instead of &",
10020 -- If the ultimate ancestor of the attribute's type is
10021 -- a formal type, then the attribute is illegal because
10022 -- the actual type might be declared at a higher level.
10023 -- The error message is specialized to say "ancestor"
10024 -- for the case where the access type is not its own
10025 -- ancestor, since saying simply "access type" would be
10028 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10029 if Root_Type
(Btyp
) = Btyp
then
10031 ("access type must not be a generic formal type",
10035 ("ancestor access type must not be a generic " &
10042 -- If this is a renaming, an inherited operation, or a
10043 -- subprogram instance, use the original entity. This may make
10044 -- the node type-inconsistent, so this transformation can only
10045 -- be done if the node will not be reanalyzed. In particular,
10046 -- if it is within a default expression, the transformation
10047 -- must be delayed until the default subprogram is created for
10048 -- it, when the enclosing subprogram is frozen.
10050 if Is_Entity_Name
(P
)
10051 and then Is_Overloadable
(Entity
(P
))
10052 and then Present
(Alias
(Entity
(P
)))
10053 and then Expander_Active
10056 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10059 elsif Nkind
(P
) = N_Selected_Component
10060 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10062 -- Protected operation. If operation is overloaded, must
10063 -- disambiguate. Prefix that denotes protected object itself
10064 -- is resolved with its own type.
10066 if Attr_Id
= Attribute_Unchecked_Access
then
10067 Error_Msg_Name_1
:= Aname
;
10069 ("attribute% cannot be applied to protected operation", P
);
10072 Resolve
(Prefix
(P
));
10073 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10075 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10076 -- statically illegal if F is an anonymous access to subprogram.
10078 elsif Nkind
(P
) = N_Explicit_Dereference
10079 and then Is_Entity_Name
(Prefix
(P
))
10080 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10081 E_Anonymous_Access_Subprogram_Type
10083 Error_Msg_N
("anonymous access to subprogram "
10084 & "has deeper accessibility than any master", P
);
10086 elsif Is_Overloaded
(P
) then
10088 -- Use the designated type of the context to disambiguate
10089 -- Note that this was not strictly conformant to Ada 95,
10090 -- but was the implementation adopted by most Ada 95 compilers.
10091 -- The use of the context type to resolve an Access attribute
10092 -- reference is now mandated in AI-235 for Ada 2005.
10095 Index
: Interp_Index
;
10099 Get_First_Interp
(P
, Index
, It
);
10100 while Present
(It
.Typ
) loop
10101 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10102 Resolve
(P
, It
.Typ
);
10106 Get_Next_Interp
(Index
, It
);
10113 -- X'Access is illegal if X denotes a constant and the access type
10114 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10115 -- does not apply to 'Unrestricted_Access. If the reference is a
10116 -- default-initialized aggregate component for a self-referential
10117 -- type the reference is legal.
10119 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10120 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10121 or else (Is_Record_Type
(Btyp
)
10123 Present
(Corresponding_Remote_Type
(Btyp
)))
10124 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10125 or else Ekind
(Btyp
)
10126 = E_Anonymous_Access_Protected_Subprogram_Type
10127 or else Is_Access_Constant
(Btyp
)
10128 or else Is_Variable
(P
)
10129 or else Attr_Id
= Attribute_Unrestricted_Access
)
10131 if Is_Entity_Name
(P
)
10132 and then Is_Type
(Entity
(P
))
10134 -- Legality of a self-reference through an access
10135 -- attribute has been verified in Analyze_Access_Attribute.
10139 elsif Comes_From_Source
(N
) then
10140 Error_Msg_F
("access-to-variable designates constant", P
);
10144 Des_Btyp
:= Designated_Type
(Btyp
);
10146 if Ada_Version
>= Ada_2005
10147 and then Is_Incomplete_Type
(Des_Btyp
)
10149 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10150 -- imported entity, and the non-limited view is visible, make
10151 -- use of it. If it is an incomplete subtype, use the base type
10154 if From_Limited_With
(Des_Btyp
)
10155 and then Present
(Non_Limited_View
(Des_Btyp
))
10157 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10159 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10160 Des_Btyp
:= Etype
(Des_Btyp
);
10164 if (Attr_Id
= Attribute_Access
10166 Attr_Id
= Attribute_Unchecked_Access
)
10167 and then (Ekind
(Btyp
) = E_General_Access_Type
10168 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10170 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10171 -- access types for stand-alone objects, record and array
10172 -- components, and return objects. For a component definition
10173 -- the level is the same of the enclosing composite type.
10175 if Ada_Version
>= Ada_2005
10176 and then (Is_Local_Anonymous_Access
(Btyp
)
10178 -- Handle cases where Btyp is the anonymous access
10179 -- type of an Ada 2012 stand-alone object.
10181 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10182 N_Object_Declaration
)
10184 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10185 and then Attr_Id
= Attribute_Access
10187 -- In an instance, this is a runtime check, but one we know
10188 -- will fail, so generate an appropriate warning. As usual,
10189 -- this kind of warning is an error in SPARK mode.
10191 if In_Instance_Body
then
10192 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10194 ("non-local pointer cannot point to local object<<", P
);
10195 Error_Msg_F
("\Program_Error [<<", P
);
10198 Make_Raise_Program_Error
(Loc
,
10199 Reason
=> PE_Accessibility_Check_Failed
));
10200 Set_Etype
(N
, Typ
);
10204 ("non-local pointer cannot point to local object", P
);
10208 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10210 ("illegal attribute for discriminant-dependent component",
10214 -- Check static matching rule of 3.10.2(27). Nominal subtype
10215 -- of the prefix must statically match the designated type.
10217 Nom_Subt
:= Etype
(P
);
10219 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10220 Nom_Subt
:= Base_Type
(Nom_Subt
);
10223 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10225 -- If the attribute is in the context of an access
10226 -- parameter, then the prefix is allowed to be of
10227 -- the class-wide type (by AI-127).
10229 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10230 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10231 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10237 Desig
:= Designated_Type
(Typ
);
10239 if Is_Class_Wide_Type
(Desig
) then
10240 Desig
:= Etype
(Desig
);
10243 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10248 ("type of prefix: & not compatible",
10251 ("\with &, the expected designated type",
10252 P
, Designated_Type
(Typ
));
10257 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10259 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10260 and then Is_Class_Wide_Type
(Nom_Subt
))
10263 ("type of prefix: & is not covered", P
, Nom_Subt
);
10265 ("\by &, the expected designated type" &
10266 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10269 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10270 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10271 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10272 and then Designated_Type
(Typ
) /= Nom_Subt
10274 Apply_Discriminant_Check
10275 (N
, Etype
(Designated_Type
(Typ
)));
10278 -- Ada 2005 (AI-363): Require static matching when designated
10279 -- type has discriminants and a constrained partial view, since
10280 -- in general objects of such types are mutable, so we can't
10281 -- allow the access value to designate a constrained object
10282 -- (because access values must be assumed to designate mutable
10283 -- objects when designated type does not impose a constraint).
10285 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10288 elsif Has_Discriminants
(Designated_Type
(Typ
))
10289 and then not Is_Constrained
(Des_Btyp
)
10291 (Ada_Version
< Ada_2005
10293 not Object_Type_Has_Constrained_Partial_View
10294 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10295 Scop
=> Current_Scope
))
10301 ("object subtype must statically match "
10302 & "designated subtype", P
);
10304 if Is_Entity_Name
(P
)
10305 and then Is_Array_Type
(Designated_Type
(Typ
))
10308 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10311 ("aliased object has explicit bounds??", D
);
10313 ("\declare without bounds (and with explicit "
10314 & "initialization)??", D
);
10316 ("\for use with unconstrained access??", D
);
10321 -- Check the static accessibility rule of 3.10.2(28). Note that
10322 -- this check is not performed for the case of an anonymous
10323 -- access type, since the access attribute is always legal
10324 -- in such a context.
10326 if Attr_Id
/= Attribute_Unchecked_Access
10327 and then Ekind
(Btyp
) = E_General_Access_Type
10329 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10331 Accessibility_Message
;
10336 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10337 E_Anonymous_Access_Protected_Subprogram_Type
)
10339 if Is_Entity_Name
(P
)
10340 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
10342 Error_Msg_F
("context requires a protected subprogram", P
);
10344 -- Check accessibility of protected object against that of the
10345 -- access type, but only on user code, because the expander
10346 -- creates access references for handlers. If the context is an
10347 -- anonymous_access_to_protected, there are no accessibility
10348 -- checks either. Omit check entirely for Unrestricted_Access.
10350 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10351 and then Comes_From_Source
(N
)
10352 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10353 and then Attr_Id
/= Attribute_Unrestricted_Access
10355 Accessibility_Message
;
10358 -- AI05-0225: If the context is not an access to protected
10359 -- function, the prefix must be a variable, given that it may
10360 -- be used subsequently in a protected call.
10362 elsif Nkind
(P
) = N_Selected_Component
10363 and then not Is_Variable
(Prefix
(P
))
10364 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
10367 ("target object of access to protected procedure "
10368 & "must be variable", N
);
10370 elsif Is_Entity_Name
(P
) then
10371 Check_Internal_Protected_Use
(N
, Entity
(P
));
10374 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10375 E_Anonymous_Access_Subprogram_Type
)
10376 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
10378 Error_Msg_F
("context requires a non-protected subprogram", P
);
10381 -- The context cannot be a pool-specific type, but this is a
10382 -- legality rule, not a resolution rule, so it must be checked
10383 -- separately, after possibly disambiguation (see AI-245).
10385 if Ekind
(Btyp
) = E_Access_Type
10386 and then Attr_Id
/= Attribute_Unrestricted_Access
10388 Wrong_Type
(N
, Typ
);
10391 -- The context may be a constrained access type (however ill-
10392 -- advised such subtypes might be) so in order to generate a
10393 -- constraint check when needed set the type of the attribute
10394 -- reference to the base type of the context.
10396 Set_Etype
(N
, Btyp
);
10398 -- Check for incorrect atomic/volatile reference (RM C.6(12))
10400 if Attr_Id
/= Attribute_Unrestricted_Access
then
10401 if Is_Atomic_Object
(P
)
10402 and then not Is_Atomic
(Designated_Type
(Typ
))
10405 ("access to atomic object cannot yield access-to-" &
10406 "non-atomic type", P
);
10408 elsif Is_Volatile_Object
(P
)
10409 and then not Is_Volatile
(Designated_Type
(Typ
))
10412 ("access to volatile object cannot yield access-to-" &
10413 "non-volatile type", P
);
10417 -- Check for unrestricted access where expected type is a thin
10418 -- pointer to an unconstrained array.
10420 if Non_Aliased_Prefix
(N
)
10421 and then Has_Size_Clause
(Typ
)
10422 and then RM_Size
(Typ
) = System_Address_Size
10425 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
10427 if Is_Array_Type
(DT
) and then not Is_Constrained
(DT
) then
10429 ("illegal use of Unrestricted_Access attribute", P
);
10431 ("\attempt to generate thin pointer to unaliased "
10437 -- Mark that address of entity is taken
10439 if Is_Entity_Name
(P
) then
10440 Set_Address_Taken
(Entity
(P
));
10443 -- Deal with possible elaboration check
10445 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
10447 Subp_Id
: constant Entity_Id
:= Entity
(P
);
10448 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
10449 Subp_Decl
: constant Node_Id
:=
10450 Unit_Declaration_Node
(Subp_Id
);
10452 Flag_Id
: Entity_Id
;
10456 -- If the access has been taken and the body of the subprogram
10457 -- has not been see yet, indirect calls must be protected with
10458 -- elaboration checks. We have the proper elaboration machinery
10459 -- for subprograms declared in packages, but within a block or
10460 -- a subprogram the body will appear in the same declarative
10461 -- part, and we must insert a check in the eventual body itself
10462 -- using the elaboration flag that we generate now. The check
10463 -- is then inserted when the body is expanded. This processing
10464 -- is not needed for a stand alone expression function because
10465 -- the internally generated spec and body are always inserted
10466 -- as a pair in the same declarative list.
10470 and then Comes_From_Source
(Subp_Id
)
10471 and then Comes_From_Source
(N
)
10472 and then In_Open_Scopes
(Scop
)
10473 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
10474 and then not Has_Completion
(Subp_Id
)
10475 and then No
(Elaboration_Entity
(Subp_Id
))
10476 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10477 and then Nkind
(Original_Node
(Subp_Decl
)) /=
10478 N_Expression_Function
10480 -- Create elaboration variable for it
10482 Flag_Id
:= Make_Temporary
(Loc
, 'E');
10483 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
10484 Set_Is_Frozen
(Flag_Id
);
10486 -- Insert declaration for flag after subprogram
10487 -- declaration. Note that attribute reference may
10488 -- appear within a nested scope.
10490 Insert_After_And_Analyze
(Subp_Decl
,
10491 Make_Object_Declaration
(Loc
,
10492 Defining_Identifier
=> Flag_Id
,
10493 Object_Definition
=>
10494 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
10496 Make_Integer_Literal
(Loc
, Uint_0
)));
10499 -- Taking the 'Access of an expression function freezes its
10500 -- expression (RM 13.14 10.3/3). This does not apply to an
10501 -- expression function that acts as a completion because the
10502 -- generated body is immediately analyzed and the expression
10503 -- is automatically frozen.
10505 if Ekind
(Subp_Id
) = E_Function
10506 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10507 and then Nkind
(Original_Node
(Subp_Decl
)) =
10508 N_Expression_Function
10509 and then Present
(Corresponding_Body
(Subp_Decl
))
10510 and then not Analyzed
(Corresponding_Body
(Subp_Decl
))
10513 Handled_Statement_Sequence
10514 (Unit_Declaration_Node
10515 (Corresponding_Body
(Subp_Decl
)));
10517 if Present
(HSS
) then
10518 Stmt
:= First
(Statements
(HSS
));
10520 if Nkind
(Stmt
) = N_Simple_Return_Statement
then
10521 Freeze_Expression
(Expression
(Stmt
));
10527 end Access_Attribute
;
10533 -- Deal with resolving the type for Address attribute, overloading
10534 -- is not permitted here, since there is no context to resolve it.
10536 when Attribute_Address | Attribute_Code_Address
=>
10537 Address_Attribute
: begin
10539 -- To be safe, assume that if the address of a variable is taken,
10540 -- it may be modified via this address, so note modification.
10542 if Is_Variable
(P
) then
10543 Note_Possible_Modification
(P
, Sure
=> False);
10546 if Nkind
(P
) in N_Subexpr
10547 and then Is_Overloaded
(P
)
10549 Get_First_Interp
(P
, Index
, It
);
10550 Get_Next_Interp
(Index
, It
);
10552 if Present
(It
.Nam
) then
10553 Error_Msg_Name_1
:= Aname
;
10555 ("prefix of % attribute cannot be overloaded", P
);
10559 if not Is_Entity_Name
(P
)
10560 or else not Is_Overloadable
(Entity
(P
))
10562 if not Is_Task_Type
(Etype
(P
))
10563 or else Nkind
(P
) = N_Explicit_Dereference
10569 -- If this is the name of a derived subprogram, or that of a
10570 -- generic actual, the address is that of the original entity.
10572 if Is_Entity_Name
(P
)
10573 and then Is_Overloadable
(Entity
(P
))
10574 and then Present
(Alias
(Entity
(P
)))
10577 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10580 if Is_Entity_Name
(P
) then
10581 Set_Address_Taken
(Entity
(P
));
10584 if Nkind
(P
) = N_Slice
then
10586 -- Arr (X .. Y)'address is identical to Arr (X)'address,
10587 -- even if the array is packed and the slice itself is not
10588 -- addressable. Transform the prefix into an indexed component.
10590 -- Note that the transformation is safe only if we know that
10591 -- the slice is non-null. That is because a null slice can have
10592 -- an out of bounds index value.
10594 -- Right now, gigi blows up if given 'Address on a slice as a
10595 -- result of some incorrect freeze nodes generated by the front
10596 -- end, and this covers up that bug in one case, but the bug is
10597 -- likely still there in the cases not handled by this code ???
10599 -- It's not clear what 'Address *should* return for a null
10600 -- slice with out of bounds indexes, this might be worth an ARG
10603 -- One approach would be to do a length check unconditionally,
10604 -- and then do the transformation below unconditionally, but
10605 -- analyze with checks off, avoiding the problem of the out of
10606 -- bounds index. This approach would interpret the address of
10607 -- an out of bounds null slice as being the address where the
10608 -- array element would be if there was one, which is probably
10609 -- as reasonable an interpretation as any ???
10612 Loc
: constant Source_Ptr
:= Sloc
(P
);
10613 D
: constant Node_Id
:= Discrete_Range
(P
);
10617 if Is_Entity_Name
(D
)
10620 (Type_Low_Bound
(Entity
(D
)),
10621 Type_High_Bound
(Entity
(D
)))
10624 Make_Attribute_Reference
(Loc
,
10625 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
10626 Attribute_Name
=> Name_First
);
10628 elsif Nkind
(D
) = N_Range
10629 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
10631 Lo
:= Low_Bound
(D
);
10637 if Present
(Lo
) then
10639 Make_Indexed_Component
(Loc
,
10640 Prefix
=> Relocate_Node
(Prefix
(P
)),
10641 Expressions
=> New_List
(Lo
)));
10643 Analyze_And_Resolve
(P
);
10647 end Address_Attribute
;
10653 -- Prefix of Body_Version attribute can be a subprogram name which
10654 -- must not be resolved, since this is not a call.
10656 when Attribute_Body_Version
=>
10663 -- Prefix of Caller attribute is an entry name which must not
10664 -- be resolved, since this is definitely not an entry call.
10666 when Attribute_Caller
=>
10673 -- Shares processing with Address attribute
10679 -- If the prefix of the Count attribute is an entry name it must not
10680 -- be resolved, since this is definitely not an entry call. However,
10681 -- if it is an element of an entry family, the index itself may
10682 -- have to be resolved because it can be a general expression.
10684 when Attribute_Count
=>
10685 if Nkind
(P
) = N_Indexed_Component
10686 and then Is_Entity_Name
(Prefix
(P
))
10689 Indx
: constant Node_Id
:= First
(Expressions
(P
));
10690 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
10692 Resolve
(Indx
, Entry_Index_Type
(Fam
));
10693 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
10701 -- Prefix of the Elaborated attribute is a subprogram name which
10702 -- must not be resolved, since this is definitely not a call. Note
10703 -- that it is a library unit, so it cannot be overloaded here.
10705 when Attribute_Elaborated
=>
10712 -- Prefix of Enabled attribute is a check name, which must be treated
10713 -- specially and not touched by Resolve.
10715 when Attribute_Enabled
=>
10722 -- Do not resolve the prefix of Loop_Entry, instead wait until the
10723 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
10724 -- The delay ensures that any generated checks or temporaries are
10725 -- inserted before the relocated prefix.
10727 when Attribute_Loop_Entry
=>
10730 --------------------
10731 -- Mechanism_Code --
10732 --------------------
10734 -- Prefix of the Mechanism_Code attribute is a function name
10735 -- which must not be resolved. Should we check for overloaded ???
10737 when Attribute_Mechanism_Code
=>
10744 -- Most processing is done in sem_dist, after determining the
10745 -- context type. Node is rewritten as a conversion to a runtime call.
10747 when Attribute_Partition_ID
=>
10748 Process_Partition_Id
(N
);
10755 when Attribute_Pool_Address
=>
10762 -- We replace the Range attribute node with a range expression whose
10763 -- bounds are the 'First and 'Last attributes applied to the same
10764 -- prefix. The reason that we do this transformation here instead of
10765 -- in the expander is that it simplifies other parts of the semantic
10766 -- analysis which assume that the Range has been replaced; thus it
10767 -- must be done even when in semantic-only mode (note that the RM
10768 -- specifically mentions this equivalence, we take care that the
10769 -- prefix is only evaluated once).
10771 when Attribute_Range
=> Range_Attribute
:
10778 if not Is_Entity_Name
(P
)
10779 or else not Is_Type
(Entity
(P
))
10784 Dims
:= Expressions
(N
);
10787 Make_Attribute_Reference
(Loc
,
10788 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
10789 Attribute_Name
=> Name_Last
,
10790 Expressions
=> Dims
);
10793 Make_Attribute_Reference
(Loc
,
10795 Attribute_Name
=> Name_First
,
10796 Expressions
=> (Dims
));
10798 -- Do not share the dimension indicator, if present. Even
10799 -- though it is a static constant, its source location
10800 -- may be modified when printing expanded code and node
10801 -- sharing will lead to chaos in Sprint.
10803 if Present
(Dims
) then
10804 Set_Expressions
(LB
,
10805 New_List
(New_Copy_Tree
(First
(Dims
))));
10808 -- If the original was marked as Must_Not_Freeze (see code
10809 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10810 -- does not freeze either.
10812 if Must_Not_Freeze
(N
) then
10813 Set_Must_Not_Freeze
(HB
);
10814 Set_Must_Not_Freeze
(LB
);
10815 Set_Must_Not_Freeze
(Prefix
(HB
));
10816 Set_Must_Not_Freeze
(Prefix
(LB
));
10819 if Raises_Constraint_Error
(Prefix
(N
)) then
10821 -- Preserve Sloc of prefix in the new bounds, so that
10822 -- the posted warning can be removed if we are within
10823 -- unreachable code.
10825 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
10826 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
10829 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
10830 Analyze_And_Resolve
(N
, Typ
);
10832 -- Ensure that the expanded range does not have side effects
10834 Force_Evaluation
(LB
);
10835 Force_Evaluation
(HB
);
10837 -- Normally after resolving attribute nodes, Eval_Attribute
10838 -- is called to do any possible static evaluation of the node.
10839 -- However, here since the Range attribute has just been
10840 -- transformed into a range expression it is no longer an
10841 -- attribute node and therefore the call needs to be avoided
10842 -- and is accomplished by simply returning from the procedure.
10845 end Range_Attribute
;
10851 -- We will only come here during the prescan of a spec expression
10852 -- containing a Result attribute. In that case the proper Etype has
10853 -- already been set, and nothing more needs to be done here.
10855 when Attribute_Result
=>
10862 -- Prefix must not be resolved in this case, since it is not a
10863 -- real entity reference. No action of any kind is require.
10865 when Attribute_UET_Address
=>
10868 ----------------------
10869 -- Unchecked_Access --
10870 ----------------------
10872 -- Processing is shared with Access
10874 -------------------------
10875 -- Unrestricted_Access --
10876 -------------------------
10878 -- Processing is shared with Access
10884 -- Resolve aggregate components in component associations
10886 when Attribute_Update
=>
10888 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
10889 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
10895 -- Set the Etype of the aggregate to that of the prefix, even
10896 -- though the aggregate may not be a proper representation of a
10897 -- value of the type (missing or duplicated associations, etc.)
10898 -- Complete resolution of the prefix. Note that in Ada 2012 it
10899 -- can be a qualified expression that is e.g. an aggregate.
10901 Set_Etype
(Aggr
, Typ
);
10902 Resolve
(Prefix
(N
), Typ
);
10904 -- For an array type, resolve expressions with the component
10905 -- type of the array, and apply constraint checks when needed.
10907 if Is_Array_Type
(Typ
) then
10908 Assoc
:= First
(Component_Associations
(Aggr
));
10909 while Present
(Assoc
) loop
10910 Expr
:= Expression
(Assoc
);
10911 Resolve
(Expr
, Component_Type
(Typ
));
10913 -- For scalar array components set Do_Range_Check when
10914 -- needed. Constraint checking on non-scalar components
10915 -- is done in Aggregate_Constraint_Checks, but only if
10916 -- full analysis is enabled. These flags are not set in
10917 -- the front-end in GnatProve mode.
10919 if Is_Scalar_Type
(Component_Type
(Typ
))
10920 and then not Is_OK_Static_Expression
(Expr
)
10922 if Is_Entity_Name
(Expr
)
10923 and then Etype
(Expr
) = Component_Type
(Typ
)
10928 Set_Do_Range_Check
(Expr
);
10932 -- The choices in the association are static constants,
10933 -- or static aggregates each of whose components belongs
10934 -- to the proper index type. However, they must also
10935 -- belong to the index subtype (s) of the prefix, which
10936 -- may be a subtype (e.g. given by a slice).
10938 -- Choices may also be identifiers with no staticness
10939 -- requirements, in which case they must resolve to the
10948 C
:= First
(Choices
(Assoc
));
10949 while Present
(C
) loop
10950 Indx
:= First_Index
(Etype
(Prefix
(N
)));
10952 if Nkind
(C
) /= N_Aggregate
then
10953 Analyze_And_Resolve
(C
, Etype
(Indx
));
10954 Apply_Constraint_Check
(C
, Etype
(Indx
));
10955 Check_Non_Static_Context
(C
);
10958 C_E
:= First
(Expressions
(C
));
10959 while Present
(C_E
) loop
10960 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
10961 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
10962 Check_Non_Static_Context
(C_E
);
10976 -- For a record type, use type of each component, which is
10977 -- recorded during analysis.
10980 Assoc
:= First
(Component_Associations
(Aggr
));
10981 while Present
(Assoc
) loop
10982 Comp
:= First
(Choices
(Assoc
));
10984 if Nkind
(Comp
) /= N_Others_Choice
10985 and then not Error_Posted
(Comp
)
10987 Resolve
(Expression
(Assoc
), Etype
(Entity
(Comp
)));
10999 -- Apply range check. Note that we did not do this during the
11000 -- analysis phase, since we wanted Eval_Attribute to have a
11001 -- chance at finding an illegal out of range value.
11003 when Attribute_Val
=>
11005 -- Note that we do our own Eval_Attribute call here rather than
11006 -- use the common one, because we need to do processing after
11007 -- the call, as per above comment.
11009 Eval_Attribute
(N
);
11011 -- Eval_Attribute may replace the node with a raise CE, or
11012 -- fold it to a constant. Obviously we only apply a scalar
11013 -- range check if this did not happen.
11015 if Nkind
(N
) = N_Attribute_Reference
11016 and then Attribute_Name
(N
) = Name_Val
11018 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11027 -- Prefix of Version attribute can be a subprogram name which
11028 -- must not be resolved, since this is not a call.
11030 when Attribute_Version
=>
11033 ----------------------
11034 -- Other Attributes --
11035 ----------------------
11037 -- For other attributes, resolve prefix unless it is a type. If
11038 -- the attribute reference itself is a type name ('Base and 'Class)
11039 -- then this is only legal within a task or protected record.
11042 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11046 -- If the attribute reference itself is a type name ('Base,
11047 -- 'Class) then this is only legal within a task or protected
11048 -- record. What is this all about ???
11050 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11051 if Is_Concurrent_Type
(Entity
(N
))
11052 and then In_Open_Scopes
(Entity
(P
))
11057 ("invalid use of subtype name in expression or call", N
);
11061 -- For attributes whose argument may be a string, complete
11062 -- resolution of argument now. This avoids premature expansion
11063 -- (and the creation of transient scopes) before the attribute
11064 -- reference is resolved.
11067 when Attribute_Value
=>
11068 Resolve
(First
(Expressions
(N
)), Standard_String
);
11070 when Attribute_Wide_Value
=>
11071 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11073 when Attribute_Wide_Wide_Value
=>
11074 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11076 when others => null;
11079 -- If the prefix of the attribute is a class-wide type then it
11080 -- will be expanded into a dispatching call to a predefined
11081 -- primitive. Therefore we must check for potential violation
11082 -- of such restriction.
11084 if Is_Class_Wide_Type
(Etype
(P
)) then
11085 Check_Restriction
(No_Dispatching_Calls
, N
);
11089 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11090 -- is not resolved, in which case the freezing must be done now.
11092 Freeze_Expression
(P
);
11094 -- Finally perform static evaluation on the attribute reference
11096 Analyze_Dimension
(N
);
11097 Eval_Attribute
(N
);
11098 end Resolve_Attribute
;
11100 ------------------------
11101 -- Set_Boolean_Result --
11102 ------------------------
11104 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11105 Loc
: constant Source_Ptr
:= Sloc
(N
);
11108 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11110 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11112 end Set_Boolean_Result
;
11114 --------------------------------
11115 -- Stream_Attribute_Available --
11116 --------------------------------
11118 function Stream_Attribute_Available
11120 Nam
: TSS_Name_Type
;
11121 Partial_View
: Node_Id
:= Empty
) return Boolean
11123 Etyp
: Entity_Id
:= Typ
;
11125 -- Start of processing for Stream_Attribute_Available
11128 -- We need some comments in this body ???
11130 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11134 if Is_Class_Wide_Type
(Typ
) then
11135 return not Is_Limited_Type
(Typ
)
11136 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11139 if Nam
= TSS_Stream_Input
11140 and then Is_Abstract_Type
(Typ
)
11141 and then not Is_Class_Wide_Type
(Typ
)
11146 if not (Is_Limited_Type
(Typ
)
11147 or else (Present
(Partial_View
)
11148 and then Is_Limited_Type
(Partial_View
)))
11153 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11155 if Nam
= TSS_Stream_Input
11156 and then Ada_Version
>= Ada_2005
11157 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11161 elsif Nam
= TSS_Stream_Output
11162 and then Ada_Version
>= Ada_2005
11163 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11168 -- Case of Read and Write: check for attribute definition clause that
11169 -- applies to an ancestor type.
11171 while Etype
(Etyp
) /= Etyp
loop
11172 Etyp
:= Etype
(Etyp
);
11174 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11179 if Ada_Version
< Ada_2005
then
11181 -- In Ada 95 mode, also consider a non-visible definition
11184 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11187 and then Stream_Attribute_Available
11188 (Btyp
, Nam
, Partial_View
=> Typ
);
11193 end Stream_Attribute_Available
;