1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 -- that are not included in Ada 95, but still get recognized in GNAT.
92 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
98 Attribute_Constrained |
105 Attribute_First_Bit |
111 Attribute_Leading_Part |
113 Attribute_Machine_Emax |
114 Attribute_Machine_Emin |
115 Attribute_Machine_Mantissa |
116 Attribute_Machine_Overflows |
117 Attribute_Machine_Radix |
118 Attribute_Machine_Rounds |
124 Attribute_Safe_Emax |
125 Attribute_Safe_Large |
126 Attribute_Safe_Small |
129 Attribute_Storage_Size |
131 Attribute_Terminated |
134 Attribute_Width => True,
137 -- The following array is the list of attributes defined in the Ada 2005
138 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
139 -- but in Ada 95 they are considered to be implementation defined.
141 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
142 Attribute_Machine_Rounding |
145 Attribute_Stream_Size |
146 Attribute_Wide_Wide_Width
=> True,
149 -- The following array contains all attributes that imply a modification
150 -- of their prefixes or result in an access value. Such prefixes can be
151 -- considered as lvalues.
153 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
154 Attribute_Class_Array
'(
159 Attribute_Unchecked_Access |
160 Attribute_Unrestricted_Access => True,
163 -----------------------
164 -- Local_Subprograms --
165 -----------------------
167 procedure Eval_Attribute (N : Node_Id);
168 -- Performs compile time evaluation of attributes where possible, leaving
169 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
170 -- set, and replacing the node with a literal node if the value can be
171 -- computed at compile time. All static attribute references are folded,
172 -- as well as a number of cases of non-static attributes that can always
173 -- be computed at compile time (e.g. floating-point model attributes that
174 -- are applied to non-static subtypes). Of course in such cases, the
175 -- Is_Static_Expression flag will not be set on the resulting literal.
176 -- Note that the only required action of this procedure is to catch the
177 -- static expression cases as described in the RM. Folding of other cases
178 -- is done where convenient, but some additional non-static folding is in
179 -- Expand_N_Attribute_Reference in cases where this is more convenient.
181 function Is_Anonymous_Tagged_Base
185 -- For derived tagged types that constrain parent discriminants we build
186 -- an anonymous unconstrained base type. We need to recognize the relation
187 -- between the two when analyzing an access attribute for a constrained
188 -- component, before the full declaration for Typ has been analyzed, and
189 -- where therefore the prefix of the attribute does not match the enclosing
192 procedure Set_Boolean_Result (N : Node_Id; B : Boolean);
193 -- Rewrites node N with an occurrence of either Standard_False or
194 -- Standard_True, depending on the value of the parameter B. The
195 -- result is marked as a static expression.
197 -----------------------
198 -- Analyze_Attribute --
199 -----------------------
201 procedure Analyze_Attribute (N : Node_Id) is
202 Loc : constant Source_Ptr := Sloc (N);
203 Aname : constant Name_Id := Attribute_Name (N);
204 P : constant Node_Id := Prefix (N);
205 Exprs : constant List_Id := Expressions (N);
206 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
211 -- Type of prefix after analysis
213 P_Base_Type : Entity_Id;
214 -- Base type of prefix after analysis
216 -----------------------
217 -- Local Subprograms --
218 -----------------------
220 procedure Address_Checks;
221 -- Semantic checks for valid use of Address attribute. This was made
222 -- a separate routine with the idea of using it for unrestricted access
223 -- which seems like it should follow the same rules, but that turned
224 -- out to be impractical. So now this is only used for Address.
226 procedure Analyze_Access_Attribute;
227 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
228 -- Internally, Id distinguishes which of the three cases is involved.
230 procedure Bad_Attribute_For_Predicate;
231 -- Output error message for use of a predicate (First, Last, Range) not
232 -- allowed with a type that has predicates. If the type is a generic
233 -- actual, then the message is a warning, and we generate code to raise
234 -- program error with an appropriate reason. No error message is given
235 -- for internally generated uses of the attributes. This legality rule
236 -- only applies to scalar types.
238 procedure Check_Ada_2012_Attribute;
239 -- Check that we are in Ada 2012 mode for an Ada 2012 attribute, and
240 -- issue appropriate messages if not (and return to caller even in
243 procedure Check_Array_Or_Scalar_Type;
244 -- Common procedure used by First, Last, Range attribute to check
245 -- that the prefix is a constrained array or scalar type, or a name
246 -- of an array object, and that an argument appears only if appropriate
247 -- (i.e. only in the array case).
249 procedure Check_Array_Type;
250 -- Common semantic checks for all array attributes. Checks that the
251 -- prefix is a constrained array type or the name of an array object.
252 -- The error message for non-arrays is specialized appropriately.
254 procedure Check_Asm_Attribute;
255 -- Common semantic checks for Asm_Input and Asm_Output attributes
257 procedure Check_Component;
258 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
259 -- Position. Checks prefix is an appropriate selected component.
261 procedure Check_Decimal_Fixed_Point_Type;
262 -- Check that prefix of attribute N is a decimal fixed-point type
264 procedure Check_Dereference;
265 -- If the prefix of attribute is an object of an access type, then
266 -- introduce an explicit dereference, and adjust P_Type accordingly.
268 procedure Check_Discrete_Type;
269 -- Verify that prefix of attribute N is a discrete type
272 -- Check that no attribute arguments are present
274 procedure Check_Either_E0_Or_E1;
275 -- Check that there are zero or one attribute arguments present
278 -- Check that exactly one attribute argument is present
281 -- Check that two attribute arguments are present
283 procedure Check_Enum_Image;
284 -- If the prefix type is an enumeration type, set all its literals
285 -- as referenced, since the image function could possibly end up
286 -- referencing any of the literals indirectly. Same for Enum_Val.
287 -- Set the flag only if the reference is in the main code unit. Same
288 -- restriction when resolving 'Value
; otherwise an improperly set
289 -- reference when analyzing an inlined body will lose a proper warning
290 -- on a useless with_clause.
292 procedure Check_First_Last_Valid
;
293 -- Perform all checks for First_Valid and Last_Valid attributes
295 procedure Check_Fixed_Point_Type
;
296 -- Verify that prefix of attribute N is a fixed type
298 procedure Check_Fixed_Point_Type_0
;
299 -- Verify that prefix of attribute N is a fixed type and that
300 -- no attribute expressions are present
302 procedure Check_Floating_Point_Type
;
303 -- Verify that prefix of attribute N is a float type
305 procedure Check_Floating_Point_Type_0
;
306 -- Verify that prefix of attribute N is a float type and that
307 -- no attribute expressions are present
309 procedure Check_Floating_Point_Type_1
;
310 -- Verify that prefix of attribute N is a float type and that
311 -- exactly one attribute expression is present
313 procedure Check_Floating_Point_Type_2
;
314 -- Verify that prefix of attribute N is a float type and that
315 -- two attribute expressions are present
317 procedure Check_SPARK_Restriction_On_Attribute
;
318 -- Issue an error in formal mode because attribute N is allowed
320 procedure Check_Integer_Type
;
321 -- Verify that prefix of attribute N is an integer type
323 procedure Check_Modular_Integer_Type
;
324 -- Verify that prefix of attribute N is a modular integer type
326 procedure Check_Not_CPP_Type
;
327 -- Check that P (the prefix of the attribute) is not an CPP type
328 -- for which no Ada predefined primitive is available.
330 procedure Check_Not_Incomplete_Type
;
331 -- Check that P (the prefix of the attribute) is not an incomplete
332 -- type or a private type for which no full view has been given.
334 procedure Check_Object_Reference
(P
: Node_Id
);
335 -- Check that P is an object reference
337 procedure Check_Program_Unit
;
338 -- Verify that prefix of attribute N is a program unit
340 procedure Check_Real_Type
;
341 -- Verify that prefix of attribute N is fixed or float type
343 procedure Check_Scalar_Type
;
344 -- Verify that prefix of attribute N is a scalar type
346 procedure Check_Standard_Prefix
;
347 -- Verify that prefix of attribute N is package Standard. Also checks
348 -- that there are no arguments.
350 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
351 -- Validity checking for stream attribute. Nam is the TSS name of the
352 -- corresponding possible defined attribute function (e.g. for the
353 -- Read attribute, Nam will be TSS_Stream_Read).
355 procedure Check_System_Prefix
;
356 -- Verify that prefix of attribute N is package System
358 procedure Check_PolyORB_Attribute
;
359 -- Validity checking for PolyORB/DSA attribute
361 procedure Check_Task_Prefix
;
362 -- Verify that prefix of attribute N is a task or task type
364 procedure Check_Type
;
365 -- Verify that the prefix of attribute N is a type
367 procedure Check_Unit_Name
(Nod
: Node_Id
);
368 -- Check that Nod is of the form of a library unit name, i.e that
369 -- it is an identifier, or a selected component whose prefix is
370 -- itself of the form of a library unit name. Note that this is
371 -- quite different from Check_Program_Unit, since it only checks
372 -- the syntactic form of the name, not the semantic identity. This
373 -- is because it is used with attributes (Elab_Body, Elab_Spec,
374 -- UET_Address and Elaborated) which can refer to non-visible unit.
376 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
377 pragma No_Return
(Error_Attr
);
378 procedure Error_Attr
;
379 pragma No_Return
(Error_Attr
);
380 -- Posts error using Error_Msg_N at given node, sets type of attribute
381 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
382 -- semantic processing. The message typically contains a % insertion
383 -- character which is replaced by the attribute name. The call with
384 -- no arguments is used when the caller has already generated the
385 -- required error messages.
387 procedure Error_Attr_P
(Msg
: String);
388 pragma No_Return
(Error_Attr
);
389 -- Like Error_Attr, but error is posted at the start of the prefix
391 function In_Refined_Post
return Boolean;
392 -- Determine whether the current attribute appears in pragma
395 procedure Legal_Formal_Attribute
;
396 -- Common processing for attributes Definite and Has_Discriminants.
397 -- Checks that prefix is generic indefinite formal type.
399 procedure Standard_Attribute
(Val
: Int
);
400 -- Used to process attributes whose prefix is package Standard which
401 -- yield values of type Universal_Integer. The attribute reference
402 -- node is rewritten with an integer literal of the given value.
404 procedure Unexpected_Argument
(En
: Node_Id
);
405 -- Signal unexpected attribute argument (En is the argument)
407 procedure Validate_Non_Static_Attribute_Function_Call
;
408 -- Called when processing an attribute that is a function call to a
409 -- non-static function, i.e. an attribute function that either takes
410 -- non-scalar arguments or returns a non-scalar result. Verifies that
411 -- such a call does not appear in a preelaborable context.
417 procedure Address_Checks
is
419 -- An Address attribute created by expansion is legal even when it
420 -- applies to other entity-denoting expressions.
422 if not Comes_From_Source
(N
) then
425 -- Address attribute on a protected object self reference is legal
427 elsif Is_Protected_Self_Reference
(P
) then
430 -- Address applied to an entity
432 elsif Is_Entity_Name
(P
) then
434 Ent
: constant Entity_Id
:= Entity
(P
);
437 if Is_Subprogram
(Ent
) then
438 Set_Address_Taken
(Ent
);
439 Kill_Current_Values
(Ent
);
441 -- An Address attribute is accepted when generated by the
442 -- compiler for dispatching operation, and an error is
443 -- issued once the subprogram is frozen (to avoid confusing
444 -- errors about implicit uses of Address in the dispatch
445 -- table initialization).
447 if Has_Pragma_Inline_Always
(Entity
(P
))
448 and then Comes_From_Source
(P
)
451 ("prefix of % attribute cannot be Inline_Always "
454 -- It is illegal to apply 'Address to an intrinsic
455 -- subprogram. This is now formalized in AI05-0095.
456 -- In an instance, an attempt to obtain 'Address of an
457 -- intrinsic subprogram (e.g the renaming of a predefined
458 -- operator that is an actual) raises Program_Error.
460 elsif Convention
(Ent
) = Convention_Intrinsic
then
463 Make_Raise_Program_Error
(Loc
,
464 Reason
=> PE_Address_Of_Intrinsic
));
467 Error_Msg_Name_1
:= Aname
;
469 ("cannot take % of intrinsic subprogram", N
);
472 -- Issue an error if prefix denotes an eliminated subprogram
475 Check_For_Eliminated_Subprogram
(P
, Ent
);
478 -- Object or label reference
480 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
481 Set_Address_Taken
(Ent
);
483 -- Deal with No_Implicit_Aliasing restriction
485 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
486 if not Is_Aliased_View
(P
) then
487 Check_Restriction
(No_Implicit_Aliasing
, P
);
489 Check_No_Implicit_Aliasing
(P
);
493 -- If we have an address of an object, and the attribute
494 -- comes from source, then set the object as potentially
495 -- source modified. We do this because the resulting address
496 -- can potentially be used to modify the variable and we
497 -- might not detect this, leading to some junk warnings.
499 Set_Never_Set_In_Source
(Ent
, False);
501 -- Allow Address to be applied to task or protected type,
502 -- returning null address (what is that about???)
504 elsif (Is_Concurrent_Type
(Etype
(Ent
))
505 and then Etype
(Ent
) = Base_Type
(Ent
))
506 or else Ekind
(Ent
) = E_Package
507 or else Is_Generic_Unit
(Ent
)
510 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
512 -- Anything else is illegal
515 Error_Attr
("invalid prefix for % attribute", P
);
519 -- Allow Address if the prefix is a reference to the AST_Entry
520 -- attribute. If expansion is active, the attribute will be
521 -- replaced by a function call, and address will work fine and
522 -- get the proper value, but if expansion is not active, then
523 -- the check here allows proper semantic analysis of the reference.
525 elsif Nkind
(P
) = N_Attribute_Reference
526 and then Attribute_Name
(P
) = Name_AST_Entry
529 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
533 elsif Is_Object_Reference
(P
) then
536 -- Subprogram called using dot notation
538 elsif Nkind
(P
) = N_Selected_Component
539 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
543 -- What exactly are we allowing here ??? and is this properly
544 -- documented in the sinfo documentation for this node ???
546 elsif Relaxed_RM_Semantics
547 and then Nkind
(P
) = N_Attribute_Reference
551 -- All other non-entity name cases are illegal
554 Error_Attr
("invalid prefix for % attribute", P
);
558 ------------------------------
559 -- Analyze_Access_Attribute --
560 ------------------------------
562 procedure Analyze_Access_Attribute
is
563 Acc_Type
: Entity_Id
;
568 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
569 -- Build an access-to-object type whose designated type is DT,
570 -- and whose Ekind is appropriate to the attribute type. The
571 -- type that is constructed is returned as the result.
573 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
574 -- Build an access to subprogram whose designated type is the type of
575 -- the prefix. If prefix is overloaded, so is the node itself. The
576 -- result is stored in Acc_Type.
578 function OK_Self_Reference
return Boolean;
579 -- An access reference whose prefix is a type can legally appear
580 -- within an aggregate, where it is obtained by expansion of
581 -- a defaulted aggregate. The enclosing aggregate that contains
582 -- the self-referenced is flagged so that the self-reference can
583 -- be expanded into a reference to the target object (see exp_aggr).
585 ------------------------------
586 -- Build_Access_Object_Type --
587 ------------------------------
589 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
590 Typ
: constant Entity_Id
:=
592 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
594 Set_Etype
(Typ
, Typ
);
596 Set_Associated_Node_For_Itype
(Typ
, N
);
597 Set_Directly_Designated_Type
(Typ
, DT
);
599 end Build_Access_Object_Type
;
601 ----------------------------------
602 -- Build_Access_Subprogram_Type --
603 ----------------------------------
605 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
606 Index
: Interp_Index
;
609 procedure Check_Local_Access
(E
: Entity_Id
);
610 -- Deal with possible access to local subprogram. If we have such
611 -- an access, we set a flag to kill all tracked values on any call
612 -- because this access value may be passed around, and any called
613 -- code might use it to access a local procedure which clobbers a
614 -- tracked value. If the scope is a loop or block, indicate that
615 -- value tracking is disabled for the enclosing subprogram.
617 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
618 -- Distinguish between access to regular/protected subprograms
620 ------------------------
621 -- Check_Local_Access --
622 ------------------------
624 procedure Check_Local_Access
(E
: Entity_Id
) is
626 if not Is_Library_Level_Entity
(E
) then
627 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
628 Set_Suppress_Value_Tracking_On_Call
629 (Nearest_Dynamic_Scope
(Current_Scope
));
631 end Check_Local_Access
;
637 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
639 if Convention
(E
) = Convention_Protected
then
640 return E_Access_Protected_Subprogram_Type
;
642 return E_Access_Subprogram_Type
;
646 -- Start of processing for Build_Access_Subprogram_Type
649 -- In the case of an access to subprogram, use the name of the
650 -- subprogram itself as the designated type. Type-checking in
651 -- this case compares the signatures of the designated types.
653 -- Note: This fragment of the tree is temporarily malformed
654 -- because the correct tree requires an E_Subprogram_Type entity
655 -- as the designated type. In most cases this designated type is
656 -- later overridden by the semantics with the type imposed by the
657 -- context during the resolution phase. In the specific case of
658 -- the expression Address!(Prim'Unrestricted_Access), used to
659 -- initialize slots of dispatch tables, this work will be done by
660 -- the expander (see Exp_Aggr).
662 -- The reason to temporarily add this kind of node to the tree
663 -- instead of a proper E_Subprogram_Type itype, is the following:
664 -- in case of errors found in the source file we report better
665 -- error messages. For example, instead of generating the
668 -- "expected access to subprogram with profile
669 -- defined at line X"
671 -- we currently generate:
673 -- "expected access to function Z defined at line X"
675 Set_Etype
(N
, Any_Type
);
677 if not Is_Overloaded
(P
) then
678 Check_Local_Access
(Entity
(P
));
680 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
681 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
682 Set_Is_Public
(Acc_Type
, False);
683 Set_Etype
(Acc_Type
, Acc_Type
);
684 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
685 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
686 Set_Etype
(N
, Acc_Type
);
687 Freeze_Before
(N
, Acc_Type
);
691 Get_First_Interp
(P
, Index
, It
);
692 while Present
(It
.Nam
) loop
693 Check_Local_Access
(It
.Nam
);
695 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
696 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
697 Set_Is_Public
(Acc_Type
, False);
698 Set_Etype
(Acc_Type
, Acc_Type
);
699 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
700 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
701 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
702 Freeze_Before
(N
, Acc_Type
);
705 Get_Next_Interp
(Index
, It
);
709 -- Cannot be applied to intrinsic. Looking at the tests above,
710 -- the only way Etype (N) can still be set to Any_Type is if
711 -- Is_Intrinsic_Subprogram was True for some referenced entity.
713 if Etype
(N
) = Any_Type
then
714 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
716 end Build_Access_Subprogram_Type
;
718 ----------------------
719 -- OK_Self_Reference --
720 ----------------------
722 function OK_Self_Reference
return Boolean is
729 (Nkind
(Par
) = N_Component_Association
730 or else Nkind
(Par
) in N_Subexpr
)
732 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
733 if Etype
(Par
) = Typ
then
734 Set_Has_Self_Reference
(Par
);
742 -- No enclosing aggregate, or not a self-reference
745 end OK_Self_Reference
;
747 -- Start of processing for Analyze_Access_Attribute
750 Check_SPARK_Restriction_On_Attribute
;
753 if Nkind
(P
) = N_Character_Literal
then
755 ("prefix of % attribute cannot be enumeration literal");
758 -- Case of access to subprogram
760 if Is_Entity_Name
(P
)
761 and then Is_Overloadable
(Entity
(P
))
763 if Has_Pragma_Inline_Always
(Entity
(P
)) then
765 ("prefix of % attribute cannot be Inline_Always subprogram");
767 elsif Aname
= Name_Unchecked_Access
then
768 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
770 elsif Is_Ghost_Subprogram
(Entity
(P
)) then
772 ("prefix of % attribute cannot be a ghost subprogram");
775 -- Issue an error if the prefix denotes an eliminated subprogram
777 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
779 -- Check for obsolescent subprogram reference
781 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
783 -- Build the appropriate subprogram type
785 Build_Access_Subprogram_Type
(P
);
787 -- For P'Access or P'Unrestricted_Access, where P is a nested
788 -- subprogram, we might be passing P to another subprogram (but we
789 -- don't check that here), which might call P. P could modify
790 -- local variables, so we need to kill current values. It is
791 -- important not to do this for library-level subprograms, because
792 -- Kill_Current_Values is very inefficient in the case of library
793 -- level packages with lots of tagged types.
795 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
798 -- Do not kill values on nodes initializing dispatch tables
799 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
800 -- is currently generated by the expander only for this
801 -- purpose. Done to keep the quality of warnings currently
802 -- generated by the compiler (otherwise any declaration of
803 -- a tagged type cleans constant indications from its scope).
805 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
806 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
808 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
809 and then Is_Dispatching_Operation
810 (Directly_Designated_Type
(Etype
(N
)))
818 -- In the static elaboration model, treat the attribute reference
819 -- as a call for elaboration purposes. Suppress this treatment
820 -- under debug flag. In any case, we are all done.
822 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
828 -- Component is an operation of a protected type
830 elsif Nkind
(P
) = N_Selected_Component
831 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
833 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
834 Error_Attr_P
("prefix of % attribute must be subprogram");
837 Build_Access_Subprogram_Type
(Selector_Name
(P
));
841 -- Deal with incorrect reference to a type, but note that some
842 -- accesses are allowed: references to the current type instance,
843 -- or in Ada 2005 self-referential pointer in a default-initialized
846 if Is_Entity_Name
(P
) then
849 -- The reference may appear in an aggregate that has been expanded
850 -- into a loop. Locate scope of type definition, if any.
852 Scop
:= Current_Scope
;
853 while Ekind
(Scop
) = E_Loop
loop
854 Scop
:= Scope
(Scop
);
857 if Is_Type
(Typ
) then
859 -- OK if we are within the scope of a limited type
860 -- let's mark the component as having per object constraint
862 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
870 Q
: Node_Id
:= Parent
(N
);
874 and then Nkind
(Q
) /= N_Component_Declaration
880 Set_Has_Per_Object_Constraint
881 (Defining_Identifier
(Q
), True);
885 if Nkind
(P
) = N_Expanded_Name
then
887 ("current instance prefix must be a direct name", P
);
890 -- If a current instance attribute appears in a component
891 -- constraint it must appear alone; other contexts (spec-
892 -- expressions, within a task body) are not subject to this
895 if not In_Spec_Expression
896 and then not Has_Completion
(Scop
)
898 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
899 N_Index_Or_Discriminant_Constraint
)
902 ("current instance attribute must appear alone", N
);
905 if Is_CPP_Class
(Root_Type
(Typ
)) then
907 ("??current instance unsupported for derivations of "
908 & "'C'P'P types", N
);
911 -- OK if we are in initialization procedure for the type
912 -- in question, in which case the reference to the type
913 -- is rewritten as a reference to the current object.
915 elsif Ekind
(Scop
) = E_Procedure
916 and then Is_Init_Proc
(Scop
)
917 and then Etype
(First_Formal
(Scop
)) = Typ
920 Make_Attribute_Reference
(Loc
,
921 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
922 Attribute_Name
=> Name_Unrestricted_Access
));
926 -- OK if a task type, this test needs sharpening up ???
928 elsif Is_Task_Type
(Typ
) then
931 -- OK if self-reference in an aggregate in Ada 2005, and
932 -- the reference comes from a copied default expression.
934 -- Note that we check legality of self-reference even if the
935 -- expression comes from source, e.g. when a single component
936 -- association in an aggregate has a box association.
938 elsif Ada_Version
>= Ada_2005
939 and then OK_Self_Reference
943 -- OK if reference to current instance of a protected object
945 elsif Is_Protected_Self_Reference
(P
) then
948 -- Otherwise we have an error case
951 Error_Attr
("% attribute cannot be applied to type", P
);
957 -- If we fall through, we have a normal access to object case.
958 -- Unrestricted_Access is legal wherever an allocator would be
959 -- legal, so its Etype is set to E_Allocator. The expected type
960 -- of the other attributes is a general access type, and therefore
961 -- we label them with E_Access_Attribute_Type.
963 if not Is_Overloaded
(P
) then
964 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
965 Set_Etype
(N
, Acc_Type
);
968 Index
: Interp_Index
;
971 Set_Etype
(N
, Any_Type
);
972 Get_First_Interp
(P
, Index
, It
);
973 while Present
(It
.Typ
) loop
974 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
975 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
976 Get_Next_Interp
(Index
, It
);
981 -- Special cases when we can find a prefix that is an entity name
990 if Is_Entity_Name
(PP
) then
993 -- If we have an access to an object, and the attribute
994 -- comes from source, then set the object as potentially
995 -- source modified. We do this because the resulting access
996 -- pointer can be used to modify the variable, and we might
997 -- not detect this, leading to some junk warnings.
999 Set_Never_Set_In_Source
(Ent
, False);
1001 -- Mark entity as address taken, and kill current values
1003 Set_Address_Taken
(Ent
);
1004 Kill_Current_Values
(Ent
);
1007 elsif Nkind_In
(PP
, N_Selected_Component
,
1008 N_Indexed_Component
)
1018 -- Check for aliased view unless unrestricted case. We allow a
1019 -- nonaliased prefix when within an instance because the prefix may
1020 -- have been a tagged formal object, which is defined to be aliased
1021 -- even when the actual might not be (other instance cases will have
1022 -- been caught in the generic). Similarly, within an inlined body we
1023 -- know that the attribute is legal in the original subprogram, and
1024 -- therefore legal in the expansion.
1026 if Aname
/= Name_Unrestricted_Access
1027 and then not Is_Aliased_View
(P
)
1028 and then not In_Instance
1029 and then not In_Inlined_Body
1031 Error_Attr_P
("prefix of % attribute must be aliased");
1032 Check_No_Implicit_Aliasing
(P
);
1034 end Analyze_Access_Attribute
;
1036 ---------------------------------
1037 -- Bad_Attribute_For_Predicate --
1038 ---------------------------------
1040 procedure Bad_Attribute_For_Predicate
is
1042 if Is_Scalar_Type
(P_Type
)
1043 and then Comes_From_Source
(N
)
1045 Error_Msg_Name_1
:= Aname
;
1046 Bad_Predicated_Subtype_Use
1047 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1049 end Bad_Attribute_For_Predicate
;
1051 ------------------------------
1052 -- Check_Ada_2012_Attribute --
1053 ------------------------------
1055 procedure Check_Ada_2012_Attribute
is
1057 Error_Msg_Name_1
:= Aname
;
1058 Error_Msg_Ada_2012_Feature
("attribute %", Sloc
(N
));
1059 end Check_Ada_2012_Attribute
;
1061 --------------------------------
1062 -- Check_Array_Or_Scalar_Type --
1063 --------------------------------
1065 procedure Check_Array_Or_Scalar_Type
is
1069 -- Dimension number for array attributes
1072 -- Case of string literal or string literal subtype. These cases
1073 -- cannot arise from legal Ada code, but the expander is allowed
1074 -- to generate them. They require special handling because string
1075 -- literal subtypes do not have standard bounds (the whole idea
1076 -- of these subtypes is to avoid having to generate the bounds)
1078 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1079 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1084 elsif Is_Scalar_Type
(P_Type
) then
1087 if Present
(E1
) then
1088 Error_Attr
("invalid argument in % attribute", E1
);
1090 Set_Etype
(N
, P_Base_Type
);
1094 -- The following is a special test to allow 'First to apply to
1095 -- private scalar types if the attribute comes from generated
1096 -- code. This occurs in the case of Normalize_Scalars code.
1098 elsif Is_Private_Type
(P_Type
)
1099 and then Present
(Full_View
(P_Type
))
1100 and then Is_Scalar_Type
(Full_View
(P_Type
))
1101 and then not Comes_From_Source
(N
)
1103 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1105 -- Array types other than string literal subtypes handled above
1110 -- We know prefix is an array type, or the name of an array
1111 -- object, and that the expression, if present, is static
1112 -- and within the range of the dimensions of the type.
1114 pragma Assert
(Is_Array_Type
(P_Type
));
1115 Index
:= First_Index
(P_Base_Type
);
1119 -- First dimension assumed
1121 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1124 D
:= UI_To_Int
(Intval
(E1
));
1126 for J
in 1 .. D
- 1 loop
1130 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1131 Set_Etype
(E1
, Standard_Integer
);
1134 end Check_Array_Or_Scalar_Type
;
1136 ----------------------
1137 -- Check_Array_Type --
1138 ----------------------
1140 procedure Check_Array_Type
is
1142 -- Dimension number for array attributes
1145 -- If the type is a string literal type, then this must be generated
1146 -- internally, and no further check is required on its legality.
1148 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1151 -- If the type is a composite, it is an illegal aggregate, no point
1154 elsif P_Type
= Any_Composite
then
1155 raise Bad_Attribute
;
1158 -- Normal case of array type or subtype
1160 Check_Either_E0_Or_E1
;
1163 if Is_Array_Type
(P_Type
) then
1164 if not Is_Constrained
(P_Type
)
1165 and then Is_Entity_Name
(P
)
1166 and then Is_Type
(Entity
(P
))
1168 -- Note: we do not call Error_Attr here, since we prefer to
1169 -- continue, using the relevant index type of the array,
1170 -- even though it is unconstrained. This gives better error
1171 -- recovery behavior.
1173 Error_Msg_Name_1
:= Aname
;
1175 ("prefix for % attribute must be constrained array", P
);
1178 -- The attribute reference freezes the type, and thus the
1179 -- component type, even if the attribute may not depend on the
1180 -- component. Diagnose arrays with incomplete components now.
1181 -- If the prefix is an access to array, this does not freeze
1182 -- the designated type.
1184 if Nkind
(P
) /= N_Explicit_Dereference
then
1185 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1188 D
:= Number_Dimensions
(P_Type
);
1191 if Is_Private_Type
(P_Type
) then
1192 Error_Attr_P
("prefix for % attribute may not be private type");
1194 elsif Is_Access_Type
(P_Type
)
1195 and then Is_Array_Type
(Designated_Type
(P_Type
))
1196 and then Is_Entity_Name
(P
)
1197 and then Is_Type
(Entity
(P
))
1199 Error_Attr_P
("prefix of % attribute cannot be access type");
1201 elsif Attr_Id
= Attribute_First
1203 Attr_Id
= Attribute_Last
1205 Error_Attr
("invalid prefix for % attribute", P
);
1208 Error_Attr_P
("prefix for % attribute must be array");
1212 if Present
(E1
) then
1213 Resolve
(E1
, Any_Integer
);
1214 Set_Etype
(E1
, Standard_Integer
);
1216 if not Is_Static_Expression
(E1
)
1217 or else Raises_Constraint_Error
(E1
)
1219 Flag_Non_Static_Expr
1220 ("expression for dimension must be static!", E1
);
1223 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1224 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1226 Error_Attr
("invalid dimension number for array type", E1
);
1230 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1231 and then Comes_From_Source
(N
)
1233 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1235 end Check_Array_Type
;
1237 -------------------------
1238 -- Check_Asm_Attribute --
1239 -------------------------
1241 procedure Check_Asm_Attribute
is
1246 -- Check first argument is static string expression
1248 Analyze_And_Resolve
(E1
, Standard_String
);
1250 if Etype
(E1
) = Any_Type
then
1253 elsif not Is_OK_Static_Expression
(E1
) then
1254 Flag_Non_Static_Expr
1255 ("constraint argument must be static string expression!", E1
);
1259 -- Check second argument is right type
1261 Analyze_And_Resolve
(E2
, Entity
(P
));
1263 -- Note: that is all we need to do, we don't need to check
1264 -- that it appears in a correct context. The Ada type system
1265 -- will do that for us.
1267 end Check_Asm_Attribute
;
1269 ---------------------
1270 -- Check_Component --
1271 ---------------------
1273 procedure Check_Component
is
1277 if Nkind
(P
) /= N_Selected_Component
1279 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1281 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1283 Error_Attr_P
("prefix for % attribute must be selected component");
1285 end Check_Component
;
1287 ------------------------------------
1288 -- Check_Decimal_Fixed_Point_Type --
1289 ------------------------------------
1291 procedure Check_Decimal_Fixed_Point_Type
is
1295 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1296 Error_Attr_P
("prefix of % attribute must be decimal type");
1298 end Check_Decimal_Fixed_Point_Type
;
1300 -----------------------
1301 -- Check_Dereference --
1302 -----------------------
1304 procedure Check_Dereference
is
1307 -- Case of a subtype mark
1309 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1313 -- Case of an expression
1317 if Is_Access_Type
(P_Type
) then
1319 -- If there is an implicit dereference, then we must freeze the
1320 -- designated type of the access type, since the type of the
1321 -- referenced array is this type (see AI95-00106).
1323 -- As done elsewhere, freezing must not happen when pre-analyzing
1324 -- a pre- or postcondition or a default value for an object or for
1325 -- a formal parameter.
1327 if not In_Spec_Expression
then
1328 Freeze_Before
(N
, Designated_Type
(P_Type
));
1332 Make_Explicit_Dereference
(Sloc
(P
),
1333 Prefix
=> Relocate_Node
(P
)));
1335 Analyze_And_Resolve
(P
);
1336 P_Type
:= Etype
(P
);
1338 if P_Type
= Any_Type
then
1339 raise Bad_Attribute
;
1342 P_Base_Type
:= Base_Type
(P_Type
);
1344 end Check_Dereference
;
1346 -------------------------
1347 -- Check_Discrete_Type --
1348 -------------------------
1350 procedure Check_Discrete_Type
is
1354 if not Is_Discrete_Type
(P_Type
) then
1355 Error_Attr_P
("prefix of % attribute must be discrete type");
1357 end Check_Discrete_Type
;
1363 procedure Check_E0
is
1365 if Present
(E1
) then
1366 Unexpected_Argument
(E1
);
1374 procedure Check_E1
is
1376 Check_Either_E0_Or_E1
;
1380 -- Special-case attributes that are functions and that appear as
1381 -- the prefix of another attribute. Error is posted on parent.
1383 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1384 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1388 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1389 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1390 Set_Etype
(Parent
(N
), Any_Type
);
1391 Set_Entity
(Parent
(N
), Any_Type
);
1392 raise Bad_Attribute
;
1395 Error_Attr
("missing argument for % attribute", N
);
1404 procedure Check_E2
is
1407 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1409 Error_Attr
("missing argument for % attribute (2 required)", N
);
1413 ---------------------------
1414 -- Check_Either_E0_Or_E1 --
1415 ---------------------------
1417 procedure Check_Either_E0_Or_E1
is
1419 if Present
(E2
) then
1420 Unexpected_Argument
(E2
);
1422 end Check_Either_E0_Or_E1
;
1424 ----------------------
1425 -- Check_Enum_Image --
1426 ----------------------
1428 procedure Check_Enum_Image
is
1432 -- When an enumeration type appears in an attribute reference, all
1433 -- literals of the type are marked as referenced. This must only be
1434 -- done if the attribute reference appears in the current source.
1435 -- Otherwise the information on references may differ between a
1436 -- normal compilation and one that performs inlining.
1438 if Is_Enumeration_Type
(P_Base_Type
)
1439 and then In_Extended_Main_Code_Unit
(N
)
1441 Lit
:= First_Literal
(P_Base_Type
);
1442 while Present
(Lit
) loop
1443 Set_Referenced
(Lit
);
1447 end Check_Enum_Image
;
1449 ----------------------------
1450 -- Check_First_Last_Valid --
1451 ----------------------------
1453 procedure Check_First_Last_Valid
is
1455 Check_Ada_2012_Attribute
;
1456 Check_Discrete_Type
;
1458 -- Freeze the subtype now, so that the following test for predicates
1459 -- works (we set the predicates stuff up at freeze time)
1461 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1463 -- Now test for dynamic predicate
1465 if Has_Predicates
(P_Type
)
1466 and then No
(Static_Predicate
(P_Type
))
1469 ("prefix of % attribute may not have dynamic predicate");
1472 -- Check non-static subtype
1474 if not Is_Static_Subtype
(P_Type
) then
1475 Error_Attr_P
("prefix of % attribute must be a static subtype");
1478 -- Test case for no values
1480 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1481 Expr_Value
(Type_High_Bound
(P_Type
))
1482 or else (Has_Predicates
(P_Type
)
1483 and then Is_Empty_List
(Static_Predicate
(P_Type
)))
1486 ("prefix of % attribute must be subtype with "
1487 & "at least one value");
1489 end Check_First_Last_Valid
;
1491 ----------------------------
1492 -- Check_Fixed_Point_Type --
1493 ----------------------------
1495 procedure Check_Fixed_Point_Type
is
1499 if not Is_Fixed_Point_Type
(P_Type
) then
1500 Error_Attr_P
("prefix of % attribute must be fixed point type");
1502 end Check_Fixed_Point_Type
;
1504 ------------------------------
1505 -- Check_Fixed_Point_Type_0 --
1506 ------------------------------
1508 procedure Check_Fixed_Point_Type_0
is
1510 Check_Fixed_Point_Type
;
1512 end Check_Fixed_Point_Type_0
;
1514 -------------------------------
1515 -- Check_Floating_Point_Type --
1516 -------------------------------
1518 procedure Check_Floating_Point_Type
is
1522 if not Is_Floating_Point_Type
(P_Type
) then
1523 Error_Attr_P
("prefix of % attribute must be float type");
1525 end Check_Floating_Point_Type
;
1527 ---------------------------------
1528 -- Check_Floating_Point_Type_0 --
1529 ---------------------------------
1531 procedure Check_Floating_Point_Type_0
is
1533 Check_Floating_Point_Type
;
1535 end Check_Floating_Point_Type_0
;
1537 ---------------------------------
1538 -- Check_Floating_Point_Type_1 --
1539 ---------------------------------
1541 procedure Check_Floating_Point_Type_1
is
1543 Check_Floating_Point_Type
;
1545 end Check_Floating_Point_Type_1
;
1547 ---------------------------------
1548 -- Check_Floating_Point_Type_2 --
1549 ---------------------------------
1551 procedure Check_Floating_Point_Type_2
is
1553 Check_Floating_Point_Type
;
1555 end Check_Floating_Point_Type_2
;
1557 ------------------------
1558 -- Check_Integer_Type --
1559 ------------------------
1561 procedure Check_Integer_Type
is
1565 if not Is_Integer_Type
(P_Type
) then
1566 Error_Attr_P
("prefix of % attribute must be integer type");
1568 end Check_Integer_Type
;
1570 --------------------------------
1571 -- Check_Modular_Integer_Type --
1572 --------------------------------
1574 procedure Check_Modular_Integer_Type
is
1578 if not Is_Modular_Integer_Type
(P_Type
) then
1580 ("prefix of % attribute must be modular integer type");
1582 end Check_Modular_Integer_Type
;
1584 ------------------------
1585 -- Check_Not_CPP_Type --
1586 ------------------------
1588 procedure Check_Not_CPP_Type
is
1590 if Is_Tagged_Type
(Etype
(P
))
1591 and then Convention
(Etype
(P
)) = Convention_CPP
1592 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1595 ("invalid use of % attribute with 'C'P'P tagged type");
1597 end Check_Not_CPP_Type
;
1599 -------------------------------
1600 -- Check_Not_Incomplete_Type --
1601 -------------------------------
1603 procedure Check_Not_Incomplete_Type
is
1608 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1609 -- dereference we have to check wrong uses of incomplete types
1610 -- (other wrong uses are checked at their freezing point).
1612 -- Example 1: Limited-with
1614 -- limited with Pkg;
1616 -- type Acc is access Pkg.T;
1618 -- S : Integer := X.all'Size; -- ERROR
1621 -- Example 2: Tagged incomplete
1623 -- type T is tagged;
1624 -- type Acc is access all T;
1626 -- S : constant Integer := X.all'Size; -- ERROR
1627 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1629 if Ada_Version
>= Ada_2005
1630 and then Nkind
(P
) = N_Explicit_Dereference
1633 while Nkind
(E
) = N_Explicit_Dereference
loop
1639 if From_Limited_With
(Typ
) then
1641 ("prefix of % attribute cannot be an incomplete type");
1644 if Is_Access_Type
(Typ
) then
1645 Typ
:= Directly_Designated_Type
(Typ
);
1648 if Is_Class_Wide_Type
(Typ
) then
1649 Typ
:= Root_Type
(Typ
);
1652 -- A legal use of a shadow entity occurs only when the unit
1653 -- where the non-limited view resides is imported via a regular
1654 -- with clause in the current body. Such references to shadow
1655 -- entities may occur in subprogram formals.
1657 if Is_Incomplete_Type
(Typ
)
1658 and then From_Limited_With
(Typ
)
1659 and then Present
(Non_Limited_View
(Typ
))
1660 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
1662 Typ
:= Non_Limited_View
(Typ
);
1665 if Ekind
(Typ
) = E_Incomplete_Type
1666 and then No
(Full_View
(Typ
))
1669 ("prefix of % attribute cannot be an incomplete type");
1674 if not Is_Entity_Name
(P
)
1675 or else not Is_Type
(Entity
(P
))
1676 or else In_Spec_Expression
1680 Check_Fully_Declared
(P_Type
, P
);
1682 end Check_Not_Incomplete_Type
;
1684 ----------------------------
1685 -- Check_Object_Reference --
1686 ----------------------------
1688 procedure Check_Object_Reference
(P
: Node_Id
) is
1692 -- If we need an object, and we have a prefix that is the name of
1693 -- a function entity, convert it into a function call.
1695 if Is_Entity_Name
(P
)
1696 and then Ekind
(Entity
(P
)) = E_Function
1698 Rtyp
:= Etype
(Entity
(P
));
1701 Make_Function_Call
(Sloc
(P
),
1702 Name
=> Relocate_Node
(P
)));
1704 Analyze_And_Resolve
(P
, Rtyp
);
1706 -- Otherwise we must have an object reference
1708 elsif not Is_Object_Reference
(P
) then
1709 Error_Attr_P
("prefix of % attribute must be object");
1711 end Check_Object_Reference
;
1713 ----------------------------
1714 -- Check_PolyORB_Attribute --
1715 ----------------------------
1717 procedure Check_PolyORB_Attribute
is
1719 Validate_Non_Static_Attribute_Function_Call
;
1724 if Get_PCS_Name
/= Name_PolyORB_DSA
then
1726 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
1728 end Check_PolyORB_Attribute
;
1730 ------------------------
1731 -- Check_Program_Unit --
1732 ------------------------
1734 procedure Check_Program_Unit
is
1736 if Is_Entity_Name
(P
) then
1738 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1739 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1742 if K
in Subprogram_Kind
1743 or else K
in Task_Kind
1744 or else K
in Protected_Kind
1745 or else K
= E_Package
1746 or else K
in Generic_Unit_Kind
1747 or else (K
= E_Variable
1751 Is_Protected_Type
(T
)))
1758 Error_Attr_P
("prefix of % attribute must be program unit");
1759 end Check_Program_Unit
;
1761 ---------------------
1762 -- Check_Real_Type --
1763 ---------------------
1765 procedure Check_Real_Type
is
1769 if not Is_Real_Type
(P_Type
) then
1770 Error_Attr_P
("prefix of % attribute must be real type");
1772 end Check_Real_Type
;
1774 -----------------------
1775 -- Check_Scalar_Type --
1776 -----------------------
1778 procedure Check_Scalar_Type
is
1782 if not Is_Scalar_Type
(P_Type
) then
1783 Error_Attr_P
("prefix of % attribute must be scalar type");
1785 end Check_Scalar_Type
;
1787 ------------------------------------------
1788 -- Check_SPARK_Restriction_On_Attribute --
1789 ------------------------------------------
1791 procedure Check_SPARK_Restriction_On_Attribute
is
1793 Error_Msg_Name_1
:= Aname
;
1794 Check_SPARK_Restriction
("attribute % is not allowed", P
);
1795 end Check_SPARK_Restriction_On_Attribute
;
1797 ---------------------------
1798 -- Check_Standard_Prefix --
1799 ---------------------------
1801 procedure Check_Standard_Prefix
is
1805 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
1806 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1808 end Check_Standard_Prefix
;
1810 ----------------------------
1811 -- Check_Stream_Attribute --
1812 ----------------------------
1814 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1818 In_Shared_Var_Procs
: Boolean;
1819 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1820 -- For this runtime package (always compiled in GNAT mode), we allow
1821 -- stream attributes references for limited types for the case where
1822 -- shared passive objects are implemented using stream attributes,
1823 -- which is the default in GNAT's persistent storage implementation.
1826 Validate_Non_Static_Attribute_Function_Call
;
1828 -- With the exception of 'Input, Stream attributes are procedures,
1829 -- and can only appear at the position of procedure calls. We check
1830 -- for this here, before they are rewritten, to give a more precise
1833 if Nam
= TSS_Stream_Input
then
1836 elsif Is_List_Member
(N
)
1837 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1844 ("invalid context for attribute%, which is a procedure", N
);
1848 Btyp
:= Implementation_Base_Type
(P_Type
);
1850 -- Stream attributes not allowed on limited types unless the
1851 -- attribute reference was generated by the expander (in which
1852 -- case the underlying type will be used, as described in Sinfo),
1853 -- or the attribute was specified explicitly for the type itself
1854 -- or one of its ancestors (taking visibility rules into account if
1855 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1856 -- (with no visibility restriction).
1859 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1861 if Present
(Gen_Body
) then
1862 In_Shared_Var_Procs
:=
1863 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1865 In_Shared_Var_Procs
:= False;
1869 if (Comes_From_Source
(N
)
1870 and then not (In_Shared_Var_Procs
or In_Instance
))
1871 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1872 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1874 Error_Msg_Name_1
:= Aname
;
1876 if Is_Limited_Type
(P_Type
) then
1878 ("limited type& has no% attribute", P
, P_Type
);
1879 Explain_Limited_Type
(P_Type
, P
);
1882 ("attribute% for type& is not available", P
, P_Type
);
1886 -- Check restriction violations
1888 -- First check the No_Streams restriction, which prohibits the use
1889 -- of explicit stream attributes in the source program. We do not
1890 -- prevent the occurrence of stream attributes in generated code,
1891 -- for instance those generated implicitly for dispatching purposes.
1893 if Comes_From_Source
(N
) then
1894 Check_Restriction
(No_Streams
, P
);
1897 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1898 -- it is illegal to use a predefined elementary type stream attribute
1899 -- either by itself, or more importantly as part of the attribute
1900 -- subprogram for a composite type. However, if the broader
1901 -- restriction No_Streams is active, stream operations are not
1902 -- generated, and there is no error.
1904 if Restriction_Active
(No_Default_Stream_Attributes
)
1905 and then not Restriction_Active
(No_Streams
)
1911 if Nam
= TSS_Stream_Input
1913 Nam
= TSS_Stream_Read
1916 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
1919 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
1923 Check_Restriction
(No_Default_Stream_Attributes
, N
);
1926 ("missing user-defined Stream Read or Write for type&",
1928 if not Is_Elementary_Type
(P_Type
) then
1930 ("\which is a component of type&", N
, P_Type
);
1936 -- Check special case of Exception_Id and Exception_Occurrence which
1937 -- are not allowed for restriction No_Exception_Registration.
1939 if Restriction_Check_Required
(No_Exception_Registration
)
1940 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
1942 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
1944 Check_Restriction
(No_Exception_Registration
, P
);
1947 -- Here we must check that the first argument is an access type
1948 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1950 Analyze_And_Resolve
(E1
);
1953 -- Note: the double call to Root_Type here is needed because the
1954 -- root type of a class-wide type is the corresponding type (e.g.
1955 -- X for X'Class, and we really want to go to the root.)
1957 if not Is_Access_Type
(Etyp
)
1958 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1959 RTE
(RE_Root_Stream_Type
)
1962 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1965 -- Check that the second argument is of the right type if there is
1966 -- one (the Input attribute has only one argument so this is skipped)
1968 if Present
(E2
) then
1971 if Nam
= TSS_Stream_Read
1972 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1975 ("second argument of % attribute must be a variable", E2
);
1978 Resolve
(E2
, P_Type
);
1982 end Check_Stream_Attribute
;
1984 -------------------------
1985 -- Check_System_Prefix --
1986 -------------------------
1988 procedure Check_System_Prefix
is
1990 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
1991 Error_Attr
("only allowed prefix for % attribute is System", P
);
1993 end Check_System_Prefix
;
1995 -----------------------
1996 -- Check_Task_Prefix --
1997 -----------------------
1999 procedure Check_Task_Prefix
is
2003 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2004 -- task interface class-wide types.
2006 if Is_Task_Type
(Etype
(P
))
2007 or else (Is_Access_Type
(Etype
(P
))
2008 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2009 or else (Ada_Version
>= Ada_2005
2010 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2011 and then Is_Interface
(Etype
(P
))
2012 and then Is_Task_Interface
(Etype
(P
)))
2017 if Ada_Version
>= Ada_2005
then
2019 ("prefix of % attribute must be a task or a task " &
2020 "interface class-wide object");
2023 Error_Attr_P
("prefix of % attribute must be a task");
2026 end Check_Task_Prefix
;
2032 -- The possibilities are an entity name denoting a type, or an
2033 -- attribute reference that denotes a type (Base or Class). If
2034 -- the type is incomplete, replace it with its full view.
2036 procedure Check_Type
is
2038 if not Is_Entity_Name
(P
)
2039 or else not Is_Type
(Entity
(P
))
2041 Error_Attr_P
("prefix of % attribute must be a type");
2043 elsif Is_Protected_Self_Reference
(P
) then
2045 ("prefix of % attribute denotes current instance "
2046 & "(RM 9.4(21/2))");
2048 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2049 and then Present
(Full_View
(Entity
(P
)))
2051 P_Type
:= Full_View
(Entity
(P
));
2052 Set_Entity
(P
, P_Type
);
2056 ---------------------
2057 -- Check_Unit_Name --
2058 ---------------------
2060 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2062 if Nkind
(Nod
) = N_Identifier
then
2065 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2066 Check_Unit_Name
(Prefix
(Nod
));
2068 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2073 Error_Attr
("argument for % attribute must be unit name", P
);
2074 end Check_Unit_Name
;
2080 procedure Error_Attr
is
2082 Set_Etype
(N
, Any_Type
);
2083 Set_Entity
(N
, Any_Type
);
2084 raise Bad_Attribute
;
2087 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2089 Error_Msg_Name_1
:= Aname
;
2090 Error_Msg_N
(Msg
, Error_Node
);
2098 procedure Error_Attr_P
(Msg
: String) is
2100 Error_Msg_Name_1
:= Aname
;
2101 Error_Msg_F
(Msg
, P
);
2105 ---------------------
2106 -- In_Refined_Post --
2107 ---------------------
2109 function In_Refined_Post
return Boolean is
2110 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean;
2111 -- Determine whether Prag denotes one of the incarnations of pragma
2112 -- Refined_Post (either as is or pragma Check (Refined_Post, ...).
2114 ---------------------
2115 -- Is_Refined_Post --
2116 ---------------------
2118 function Is_Refined_Post
(Prag
: Node_Id
) return Boolean is
2119 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
2120 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2123 if Nam
= Name_Refined_Post
then
2126 elsif Nam
= Name_Check
then
2127 pragma Assert
(Present
(Args
));
2129 return Chars
(Expression
(First
(Args
))) = Name_Refined_Post
;
2133 end Is_Refined_Post
;
2139 -- Start of processing for In_Refined_Post
2143 while Present
(Stmt
) loop
2144 if Nkind
(Stmt
) = N_Pragma
and then Is_Refined_Post
(Stmt
) then
2147 -- Prevent the search from going too far
2149 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
2153 Stmt
:= Parent
(Stmt
);
2157 end In_Refined_Post
;
2159 ----------------------------
2160 -- Legal_Formal_Attribute --
2161 ----------------------------
2163 procedure Legal_Formal_Attribute
is
2167 if not Is_Entity_Name
(P
)
2168 or else not Is_Type
(Entity
(P
))
2170 Error_Attr_P
("prefix of % attribute must be generic type");
2172 elsif Is_Generic_Actual_Type
(Entity
(P
))
2174 or else In_Inlined_Body
2178 elsif Is_Generic_Type
(Entity
(P
)) then
2179 if not Is_Indefinite_Subtype
(Entity
(P
)) then
2181 ("prefix of % attribute must be indefinite generic type");
2186 ("prefix of % attribute must be indefinite generic type");
2189 Set_Etype
(N
, Standard_Boolean
);
2190 end Legal_Formal_Attribute
;
2192 ------------------------
2193 -- Standard_Attribute --
2194 ------------------------
2196 procedure Standard_Attribute
(Val
: Int
) is
2198 Check_Standard_Prefix
;
2199 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2201 end Standard_Attribute
;
2203 -------------------------
2204 -- Unexpected Argument --
2205 -------------------------
2207 procedure Unexpected_Argument
(En
: Node_Id
) is
2209 Error_Attr
("unexpected argument for % attribute", En
);
2210 end Unexpected_Argument
;
2212 -------------------------------------------------
2213 -- Validate_Non_Static_Attribute_Function_Call --
2214 -------------------------------------------------
2216 -- This function should be moved to Sem_Dist ???
2218 procedure Validate_Non_Static_Attribute_Function_Call
is
2220 if In_Preelaborated_Unit
2221 and then not In_Subprogram_Or_Concurrent_Unit
2223 Flag_Non_Static_Expr
2224 ("non-static function call in preelaborated unit!", N
);
2226 end Validate_Non_Static_Attribute_Function_Call
;
2228 -- Start of processing for Analyze_Attribute
2231 -- Immediate return if unrecognized attribute (already diagnosed
2232 -- by parser, so there is nothing more that we need to do)
2234 if not Is_Attribute_Name
(Aname
) then
2235 raise Bad_Attribute
;
2238 -- Deal with Ada 83 issues
2240 if Comes_From_Source
(N
) then
2241 if not Attribute_83
(Attr_Id
) then
2242 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2243 Error_Msg_Name_1
:= Aname
;
2244 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2247 if Attribute_Impl_Def
(Attr_Id
) then
2248 Check_Restriction
(No_Implementation_Attributes
, N
);
2253 -- Deal with Ada 2005 attributes that are
2255 if Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
then
2256 Check_Restriction
(No_Implementation_Attributes
, N
);
2259 -- Remote access to subprogram type access attribute reference needs
2260 -- unanalyzed copy for tree transformation. The analyzed copy is used
2261 -- for its semantic information (whether prefix is a remote subprogram
2262 -- name), the unanalyzed copy is used to construct new subtree rooted
2263 -- with N_Aggregate which represents a fat pointer aggregate.
2265 if Aname
= Name_Access
then
2266 Discard_Node
(Copy_Separate_Tree
(N
));
2269 -- Analyze prefix and exit if error in analysis. If the prefix is an
2270 -- incomplete type, use full view if available. Note that there are
2271 -- some attributes for which we do not analyze the prefix, since the
2272 -- prefix is not a normal name, or else needs special handling.
2274 if Aname
/= Name_Elab_Body
and then
2275 Aname
/= Name_Elab_Spec
and then
2276 Aname
/= Name_Elab_Subp_Body
and then
2277 Aname
/= Name_UET_Address
and then
2278 Aname
/= Name_Enabled
and then
2282 P_Type
:= Etype
(P
);
2284 if Is_Entity_Name
(P
)
2285 and then Present
(Entity
(P
))
2286 and then Is_Type
(Entity
(P
))
2288 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2289 P_Type
:= Get_Full_View
(P_Type
);
2290 Set_Entity
(P
, P_Type
);
2291 Set_Etype
(P
, P_Type
);
2293 elsif Entity
(P
) = Current_Scope
2294 and then Is_Record_Type
(Entity
(P
))
2296 -- Use of current instance within the type. Verify that if the
2297 -- attribute appears within a constraint, it yields an access
2298 -- type, other uses are illegal.
2306 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2308 Par
:= Parent
(Par
);
2312 and then Nkind
(Par
) = N_Subtype_Indication
2314 if Attr_Id
/= Attribute_Access
2315 and then Attr_Id
/= Attribute_Unchecked_Access
2316 and then Attr_Id
/= Attribute_Unrestricted_Access
2319 ("in a constraint the current instance can only"
2320 & " be used with an access attribute", N
);
2327 if P_Type
= Any_Type
then
2328 raise Bad_Attribute
;
2331 P_Base_Type
:= Base_Type
(P_Type
);
2334 -- Analyze expressions that may be present, exiting if an error occurs
2341 E1
:= First
(Exprs
);
2343 -- Skip analysis for case of Restriction_Set, we do not expect
2344 -- the argument to be analyzed in this case.
2346 if Aname
/= Name_Restriction_Set
then
2349 -- Check for missing/bad expression (result of previous error)
2351 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2352 raise Bad_Attribute
;
2358 if Present
(E2
) then
2361 if Etype
(E2
) = Any_Type
then
2362 raise Bad_Attribute
;
2365 if Present
(Next
(E2
)) then
2366 Unexpected_Argument
(Next
(E2
));
2371 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
2372 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
2374 if Ada_Version
< Ada_2005
2375 and then Is_Overloaded
(P
)
2376 and then Aname
/= Name_Access
2377 and then Aname
/= Name_Address
2378 and then Aname
/= Name_Code_Address
2379 and then Aname
/= Name_Count
2380 and then Aname
/= Name_Result
2381 and then Aname
/= Name_Unchecked_Access
2383 Error_Attr
("ambiguous prefix for % attribute", P
);
2385 elsif Ada_Version
>= Ada_2005
2386 and then Is_Overloaded
(P
)
2387 and then Aname
/= Name_Access
2388 and then Aname
/= Name_Address
2389 and then Aname
/= Name_Code_Address
2390 and then Aname
/= Name_Result
2391 and then Aname
/= Name_Unchecked_Access
2393 -- Ada 2005 (AI-345): Since protected and task types have primitive
2394 -- entry wrappers, the attributes Count, Caller and AST_Entry require
2397 if Ada_Version
>= Ada_2005
2398 and then Nam_In
(Aname
, Name_Count
, Name_Caller
, Name_AST_Entry
)
2401 Count
: Natural := 0;
2406 Get_First_Interp
(P
, I
, It
);
2407 while Present
(It
.Nam
) loop
2408 if Comes_From_Source
(It
.Nam
) then
2414 Get_Next_Interp
(I
, It
);
2418 Error_Attr
("ambiguous prefix for % attribute", P
);
2420 Set_Is_Overloaded
(P
, False);
2425 Error_Attr
("ambiguous prefix for % attribute", P
);
2429 -- In SPARK, attributes of private types are only allowed if the full
2430 -- type declaration is visible.
2432 if Is_Entity_Name
(P
)
2433 and then Present
(Entity
(P
)) -- needed in some cases
2434 and then Is_Type
(Entity
(P
))
2435 and then Is_Private_Type
(P_Type
)
2436 and then not In_Open_Scopes
(Scope
(P_Type
))
2437 and then not In_Spec_Expression
2439 Check_SPARK_Restriction
("invisible attribute of type", N
);
2442 -- Remaining processing depends on attribute
2446 -- Attributes related to Ada 2012 iterators. Attribute specifications
2447 -- exist for these, but they cannot be queried.
2449 when Attribute_Constant_Indexing |
2450 Attribute_Default_Iterator |
2451 Attribute_Implicit_Dereference |
2452 Attribute_Iterator_Element |
2453 Attribute_Variable_Indexing
=>
2454 Error_Msg_N
("illegal attribute", N
);
2456 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2457 -- were already rejected by the parser. Thus they shouldn't appear here.
2459 when Internal_Attribute_Id
=>
2460 raise Program_Error
;
2466 when Attribute_Abort_Signal
=>
2467 Check_Standard_Prefix
;
2468 Rewrite
(N
, New_Reference_To
(Stand
.Abort_Signal
, Loc
));
2475 when Attribute_Access
=>
2476 Analyze_Access_Attribute
;
2482 when Attribute_Address
=>
2485 Set_Etype
(N
, RTE
(RE_Address
));
2491 when Attribute_Address_Size
=>
2492 Standard_Attribute
(System_Address_Size
);
2498 when Attribute_Adjacent
=>
2499 Check_Floating_Point_Type_2
;
2500 Set_Etype
(N
, P_Base_Type
);
2501 Resolve
(E1
, P_Base_Type
);
2502 Resolve
(E2
, P_Base_Type
);
2508 when Attribute_Aft
=>
2509 Check_Fixed_Point_Type_0
;
2510 Set_Etype
(N
, Universal_Integer
);
2516 when Attribute_Alignment
=>
2518 -- Don't we need more checking here, cf Size ???
2521 Check_Not_Incomplete_Type
;
2523 Set_Etype
(N
, Universal_Integer
);
2529 when Attribute_Asm_Input
=>
2530 Check_Asm_Attribute
;
2532 -- The back-end may need to take the address of E2
2534 if Is_Entity_Name
(E2
) then
2535 Set_Address_Taken
(Entity
(E2
));
2538 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2544 when Attribute_Asm_Output
=>
2545 Check_Asm_Attribute
;
2547 if Etype
(E2
) = Any_Type
then
2550 elsif Aname
= Name_Asm_Output
then
2551 if not Is_Variable
(E2
) then
2553 ("second argument for Asm_Output is not variable", E2
);
2557 Note_Possible_Modification
(E2
, Sure
=> True);
2559 -- The back-end may need to take the address of E2
2561 if Is_Entity_Name
(E2
) then
2562 Set_Address_Taken
(Entity
(E2
));
2565 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2571 when Attribute_AST_Entry
=> AST_Entry
: declare
2577 -- Indicates if entry family index is present. Note the coding
2578 -- here handles the entry family case, but in fact it cannot be
2579 -- executed currently, because pragma AST_Entry does not permit
2580 -- the specification of an entry family.
2582 procedure Bad_AST_Entry
;
2583 -- Signal a bad AST_Entry pragma
2585 function OK_Entry
(E
: Entity_Id
) return Boolean;
2586 -- Checks that E is of an appropriate entity kind for an entry
2587 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2588 -- is set True for the entry family case). In the True case,
2589 -- makes sure that Is_AST_Entry is set on the entry.
2595 procedure Bad_AST_Entry
is
2597 Error_Attr_P
("prefix for % attribute must be task entry");
2604 function OK_Entry
(E
: Entity_Id
) return Boolean is
2609 Result
:= (Ekind
(E
) = E_Entry_Family
);
2611 Result
:= (Ekind
(E
) = E_Entry
);
2615 if not Is_AST_Entry
(E
) then
2616 Error_Msg_Name_2
:= Aname
;
2617 Error_Attr
("% attribute requires previous % pragma", P
);
2624 -- Start of processing for AST_Entry
2630 -- Deal with entry family case
2632 if Nkind
(P
) = N_Indexed_Component
then
2640 Ptyp
:= Etype
(Pref
);
2642 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2646 -- If the prefix is a selected component whose prefix is of an
2647 -- access type, then introduce an explicit dereference.
2648 -- ??? Could we reuse Check_Dereference here?
2650 if Nkind
(Pref
) = N_Selected_Component
2651 and then Is_Access_Type
(Ptyp
)
2654 Make_Explicit_Dereference
(Sloc
(Pref
),
2655 Relocate_Node
(Pref
)));
2656 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2659 -- Prefix can be of the form a.b, where a is a task object
2660 -- and b is one of the entries of the corresponding task type.
2662 if Nkind
(Pref
) = N_Selected_Component
2663 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2664 and then Is_Object_Reference
(Prefix
(Pref
))
2665 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2669 -- Otherwise the prefix must be an entry of a containing task,
2670 -- or of a variable of the enclosing task type.
2673 if Nkind_In
(Pref
, N_Identifier
, N_Expanded_Name
) then
2674 Ent
:= Entity
(Pref
);
2676 if not OK_Entry
(Ent
)
2677 or else not In_Open_Scopes
(Scope
(Ent
))
2687 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2690 -----------------------------
2691 -- Atomic_Always_Lock_Free --
2692 -----------------------------
2694 when Attribute_Atomic_Always_Lock_Free
=>
2697 Set_Etype
(N
, Standard_Boolean
);
2703 -- Note: when the base attribute appears in the context of a subtype
2704 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2705 -- the following circuit.
2707 when Attribute_Base
=> Base
: declare
2715 if Ada_Version
>= Ada_95
2716 and then not Is_Scalar_Type
(Typ
)
2717 and then not Is_Generic_Type
(Typ
)
2719 Error_Attr_P
("prefix of Base attribute must be scalar type");
2721 elsif Sloc
(Typ
) = Standard_Location
2722 and then Base_Type
(Typ
) = Typ
2723 and then Warn_On_Redundant_Constructs
2725 Error_Msg_NE
-- CODEFIX
2726 ("?r?redundant attribute, & is its own base type", N
, Typ
);
2729 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
2730 Error_Msg_Name_1
:= Aname
;
2731 Check_SPARK_Restriction
2732 ("attribute% is only allowed as prefix of another attribute", P
);
2735 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2736 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2737 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2745 when Attribute_Bit
=> Bit
:
2749 if not Is_Object_Reference
(P
) then
2750 Error_Attr_P
("prefix for % attribute must be object");
2752 -- What about the access object cases ???
2758 Set_Etype
(N
, Universal_Integer
);
2765 when Attribute_Bit_Order
=> Bit_Order
:
2770 if not Is_Record_Type
(P_Type
) then
2771 Error_Attr_P
("prefix of % attribute must be record type");
2774 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2776 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2779 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2782 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2785 -- Reset incorrect indication of staticness
2787 Set_Is_Static_Expression
(N
, False);
2794 -- Note: in generated code, we can have a Bit_Position attribute
2795 -- applied to a (naked) record component (i.e. the prefix is an
2796 -- identifier that references an E_Component or E_Discriminant
2797 -- entity directly, and this is interpreted as expected by Gigi.
2798 -- The following code will not tolerate such usage, but when the
2799 -- expander creates this special case, it marks it as analyzed
2800 -- immediately and sets an appropriate type.
2802 when Attribute_Bit_Position
=>
2803 if Comes_From_Source
(N
) then
2807 Set_Etype
(N
, Universal_Integer
);
2813 when Attribute_Body_Version
=>
2816 Set_Etype
(N
, RTE
(RE_Version_String
));
2822 when Attribute_Callable
=>
2824 Set_Etype
(N
, Standard_Boolean
);
2831 when Attribute_Caller
=> Caller
: declare
2838 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2841 if not Is_Entry
(Ent
) then
2842 Error_Attr
("invalid entry name", N
);
2846 Error_Attr
("invalid entry name", N
);
2850 for J
in reverse 0 .. Scope_Stack
.Last
loop
2851 S
:= Scope_Stack
.Table
(J
).Entity
;
2853 if S
= Scope
(Ent
) then
2854 Error_Attr
("Caller must appear in matching accept or body", N
);
2860 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2867 when Attribute_Ceiling
=>
2868 Check_Floating_Point_Type_1
;
2869 Set_Etype
(N
, P_Base_Type
);
2870 Resolve
(E1
, P_Base_Type
);
2876 when Attribute_Class
=>
2877 Check_Restriction
(No_Dispatch
, N
);
2881 -- Applying Class to untagged incomplete type is obsolescent in Ada
2882 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2883 -- this flag gets set by Find_Type in this situation.
2885 if Restriction_Check_Required
(No_Obsolescent_Features
)
2886 and then Ada_Version
>= Ada_2005
2887 and then Ekind
(P_Type
) = E_Incomplete_Type
2890 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
2892 if Nkind
(DN
) = N_Incomplete_Type_Declaration
2893 and then not Tagged_Present
(DN
)
2895 Check_Restriction
(No_Obsolescent_Features
, P
);
2904 when Attribute_Code_Address
=>
2907 if Nkind
(P
) = N_Attribute_Reference
2908 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
2912 elsif not Is_Entity_Name
(P
)
2913 or else (Ekind
(Entity
(P
)) /= E_Function
2915 Ekind
(Entity
(P
)) /= E_Procedure
)
2917 Error_Attr
("invalid prefix for % attribute", P
);
2918 Set_Address_Taken
(Entity
(P
));
2920 -- Issue an error if the prefix denotes an eliminated subprogram
2923 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
2926 Set_Etype
(N
, RTE
(RE_Address
));
2928 ----------------------
2929 -- Compiler_Version --
2930 ----------------------
2932 when Attribute_Compiler_Version
=>
2934 Check_Standard_Prefix
;
2935 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
2936 Analyze_And_Resolve
(N
, Standard_String
);
2938 --------------------
2939 -- Component_Size --
2940 --------------------
2942 when Attribute_Component_Size
=>
2944 Set_Etype
(N
, Universal_Integer
);
2946 -- Note: unlike other array attributes, unconstrained arrays are OK
2948 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2958 when Attribute_Compose
=>
2959 Check_Floating_Point_Type_2
;
2960 Set_Etype
(N
, P_Base_Type
);
2961 Resolve
(E1
, P_Base_Type
);
2962 Resolve
(E2
, Any_Integer
);
2968 when Attribute_Constrained
=>
2970 Set_Etype
(N
, Standard_Boolean
);
2972 -- Case from RM J.4(2) of constrained applied to private type
2974 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2975 Check_Restriction
(No_Obsolescent_Features
, P
);
2977 if Warn_On_Obsolescent_Feature
then
2979 ("constrained for private type is an " &
2980 "obsolescent feature (RM J.4)?j?", N
);
2983 -- If we are within an instance, the attribute must be legal
2984 -- because it was valid in the generic unit. Ditto if this is
2985 -- an inlining of a function declared in an instance.
2988 or else In_Inlined_Body
2992 -- For sure OK if we have a real private type itself, but must
2993 -- be completed, cannot apply Constrained to incomplete type.
2995 elsif Is_Private_Type
(Entity
(P
)) then
2997 -- Note: this is one of the Annex J features that does not
2998 -- generate a warning from -gnatwj, since in fact it seems
2999 -- very useful, and is used in the GNAT runtime.
3001 Check_Not_Incomplete_Type
;
3005 -- Normal (non-obsolescent case) of application to object of
3006 -- a discriminated type.
3009 Check_Object_Reference
(P
);
3011 -- If N does not come from source, then we allow the
3012 -- the attribute prefix to be of a private type whose
3013 -- full type has discriminants. This occurs in cases
3014 -- involving expanded calls to stream attributes.
3016 if not Comes_From_Source
(N
) then
3017 P_Type
:= Underlying_Type
(P_Type
);
3020 -- Must have discriminants or be an access type designating
3021 -- a type with discriminants. If it is a classwide type it
3022 -- has unknown discriminants.
3024 if Has_Discriminants
(P_Type
)
3025 or else Has_Unknown_Discriminants
(P_Type
)
3027 (Is_Access_Type
(P_Type
)
3028 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3032 -- The rule given in 3.7.2 is part of static semantics, but the
3033 -- intent is clearly that it be treated as a legality rule, and
3034 -- rechecked in the visible part of an instance. Nevertheless
3035 -- the intent also seems to be it should legally apply to the
3036 -- actual of a formal with unknown discriminants, regardless of
3037 -- whether the actual has discriminants, in which case the value
3038 -- of the attribute is determined using the J.4 rules. This choice
3039 -- seems the most useful, and is compatible with existing tests.
3041 elsif In_Instance
then
3044 -- Also allow an object of a generic type if extensions allowed
3045 -- and allow this for any type at all. (this may be obsolete ???)
3047 elsif (Is_Generic_Type
(P_Type
)
3048 or else Is_Generic_Actual_Type
(P_Type
))
3049 and then Extensions_Allowed
3055 -- Fall through if bad prefix
3058 ("prefix of % attribute must be object of discriminated type");
3064 when Attribute_Copy_Sign
=>
3065 Check_Floating_Point_Type_2
;
3066 Set_Etype
(N
, P_Base_Type
);
3067 Resolve
(E1
, P_Base_Type
);
3068 Resolve
(E2
, P_Base_Type
);
3074 when Attribute_Count
=> Count
:
3083 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3086 if Ekind
(Ent
) /= E_Entry
then
3087 Error_Attr
("invalid entry name", N
);
3090 elsif Nkind
(P
) = N_Indexed_Component
then
3091 if not Is_Entity_Name
(Prefix
(P
))
3092 or else No
(Entity
(Prefix
(P
)))
3093 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3095 if Nkind
(Prefix
(P
)) = N_Selected_Component
3096 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3097 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3101 ("attribute % must apply to entry of current task", P
);
3104 Error_Attr
("invalid entry family name", P
);
3109 Ent
:= Entity
(Prefix
(P
));
3112 elsif Nkind
(P
) = N_Selected_Component
3113 and then Present
(Entity
(Selector_Name
(P
)))
3114 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3117 ("attribute % must apply to entry of current task", P
);
3120 Error_Attr
("invalid entry name", N
);
3124 for J
in reverse 0 .. Scope_Stack
.Last
loop
3125 S
:= Scope_Stack
.Table
(J
).Entity
;
3127 if S
= Scope
(Ent
) then
3128 if Nkind
(P
) = N_Expanded_Name
then
3129 Tsk
:= Entity
(Prefix
(P
));
3131 -- The prefix denotes either the task type, or else a
3132 -- single task whose task type is being analyzed.
3137 or else (not Is_Type
(Tsk
)
3138 and then Etype
(Tsk
) = S
3139 and then not (Comes_From_Source
(S
)))
3144 ("Attribute % must apply to entry of current task", N
);
3150 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3152 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3154 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3156 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3157 and then not Has_Completion
(Scope
(Ent
))
3159 Error_Attr
("attribute % can only be used inside body", N
);
3163 if Is_Overloaded
(P
) then
3165 Index
: Interp_Index
;
3169 Get_First_Interp
(P
, Index
, It
);
3171 while Present
(It
.Nam
) loop
3172 if It
.Nam
= Ent
then
3175 -- Ada 2005 (AI-345): Do not consider primitive entry
3176 -- wrappers generated for task or protected types.
3178 elsif Ada_Version
>= Ada_2005
3179 and then not Comes_From_Source
(It
.Nam
)
3184 Error_Attr
("ambiguous entry name", N
);
3187 Get_Next_Interp
(Index
, It
);
3192 Set_Etype
(N
, Universal_Integer
);
3195 -----------------------
3196 -- Default_Bit_Order --
3197 -----------------------
3199 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
3201 Check_Standard_Prefix
;
3203 if Bytes_Big_Endian
then
3205 Make_Integer_Literal
(Loc
, False_Value
));
3208 Make_Integer_Literal
(Loc
, True_Value
));
3211 Set_Etype
(N
, Universal_Integer
);
3212 Set_Is_Static_Expression
(N
);
3213 end Default_Bit_Order
;
3219 when Attribute_Definite
=>
3220 Legal_Formal_Attribute
;
3226 when Attribute_Delta
=>
3227 Check_Fixed_Point_Type_0
;
3228 Set_Etype
(N
, Universal_Real
);
3234 when Attribute_Denorm
=>
3235 Check_Floating_Point_Type_0
;
3236 Set_Etype
(N
, Standard_Boolean
);
3238 ---------------------
3239 -- Descriptor_Size --
3240 ---------------------
3242 when Attribute_Descriptor_Size
=>
3245 if not Is_Entity_Name
(P
)
3246 or else not Is_Type
(Entity
(P
))
3248 Error_Attr_P
("prefix of attribute % must denote a type");
3251 Set_Etype
(N
, Universal_Integer
);
3257 when Attribute_Digits
=>
3261 if not Is_Floating_Point_Type
(P_Type
)
3262 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3265 ("prefix of % attribute must be float or decimal type");
3268 Set_Etype
(N
, Universal_Integer
);
3274 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3276 when Attribute_Elab_Body |
3277 Attribute_Elab_Spec |
3278 Attribute_Elab_Subp_Body
=>
3281 Check_Unit_Name
(P
);
3282 Set_Etype
(N
, Standard_Void_Type
);
3284 -- We have to manually call the expander in this case to get
3285 -- the necessary expansion (normally attributes that return
3286 -- entities are not expanded).
3294 -- Shares processing with Elab_Body
3300 when Attribute_Elaborated
=>
3302 Check_Unit_Name
(P
);
3303 Set_Etype
(N
, Standard_Boolean
);
3309 when Attribute_Emax
=>
3310 Check_Floating_Point_Type_0
;
3311 Set_Etype
(N
, Universal_Integer
);
3317 when Attribute_Enabled
=>
3318 Check_Either_E0_Or_E1
;
3320 if Present
(E1
) then
3321 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3322 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3327 if Nkind
(P
) /= N_Identifier
then
3328 Error_Msg_N
("identifier expected (check name)", P
);
3329 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3330 Error_Msg_N
("& is not a recognized check name", P
);
3333 Set_Etype
(N
, Standard_Boolean
);
3339 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3341 if Present
(E1
) then
3343 Check_Discrete_Type
;
3344 Resolve
(E1
, P_Base_Type
);
3347 if not Is_Entity_Name
(P
)
3348 or else (not Is_Object
(Entity
(P
))
3350 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
3353 ("prefix of % attribute must be " &
3354 "discrete type/object or enum literal");
3358 Set_Etype
(N
, Universal_Integer
);
3365 when Attribute_Enum_Val
=> Enum_Val
: begin
3369 if not Is_Enumeration_Type
(P_Type
) then
3370 Error_Attr_P
("prefix of % attribute must be enumeration type");
3373 -- If the enumeration type has a standard representation, the effect
3374 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3376 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3378 Make_Attribute_Reference
(Loc
,
3379 Prefix
=> Relocate_Node
(Prefix
(N
)),
3380 Attribute_Name
=> Name_Val
,
3381 Expressions
=> New_List
(Relocate_Node
(E1
))));
3382 Analyze_And_Resolve
(N
, P_Base_Type
);
3384 -- Non-standard representation case (enumeration with holes)
3388 Resolve
(E1
, Any_Integer
);
3389 Set_Etype
(N
, P_Base_Type
);
3397 when Attribute_Epsilon
=>
3398 Check_Floating_Point_Type_0
;
3399 Set_Etype
(N
, Universal_Real
);
3405 when Attribute_Exponent
=>
3406 Check_Floating_Point_Type_1
;
3407 Set_Etype
(N
, Universal_Integer
);
3408 Resolve
(E1
, P_Base_Type
);
3414 when Attribute_External_Tag
=>
3418 Set_Etype
(N
, Standard_String
);
3420 if not Is_Tagged_Type
(P_Type
) then
3421 Error_Attr_P
("prefix of % attribute must be tagged");
3428 when Attribute_Fast_Math
=>
3429 Check_Standard_Prefix
;
3430 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3436 when Attribute_First
=>
3437 Check_Array_Or_Scalar_Type
;
3438 Bad_Attribute_For_Predicate
;
3444 when Attribute_First_Bit
=>
3446 Set_Etype
(N
, Universal_Integer
);
3452 when Attribute_First_Valid
=>
3453 Check_First_Last_Valid
;
3454 Set_Etype
(N
, P_Type
);
3460 when Attribute_Fixed_Value
=>
3462 Check_Fixed_Point_Type
;
3463 Resolve
(E1
, Any_Integer
);
3464 Set_Etype
(N
, P_Base_Type
);
3470 when Attribute_Floor
=>
3471 Check_Floating_Point_Type_1
;
3472 Set_Etype
(N
, P_Base_Type
);
3473 Resolve
(E1
, P_Base_Type
);
3479 when Attribute_Fore
=>
3480 Check_Fixed_Point_Type_0
;
3481 Set_Etype
(N
, Universal_Integer
);
3487 when Attribute_Fraction
=>
3488 Check_Floating_Point_Type_1
;
3489 Set_Etype
(N
, P_Base_Type
);
3490 Resolve
(E1
, P_Base_Type
);
3496 when Attribute_From_Any
=>
3498 Check_PolyORB_Attribute
;
3499 Set_Etype
(N
, P_Base_Type
);
3501 -----------------------
3502 -- Has_Access_Values --
3503 -----------------------
3505 when Attribute_Has_Access_Values
=>
3508 Set_Etype
(N
, Standard_Boolean
);
3510 -----------------------
3511 -- Has_Tagged_Values --
3512 -----------------------
3514 when Attribute_Has_Tagged_Values
=>
3517 Set_Etype
(N
, Standard_Boolean
);
3519 -----------------------
3520 -- Has_Discriminants --
3521 -----------------------
3523 when Attribute_Has_Discriminants
=>
3524 Legal_Formal_Attribute
;
3530 when Attribute_Identity
=>
3534 if Etype
(P
) = Standard_Exception_Type
then
3535 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3537 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3538 -- task interface class-wide types.
3540 elsif Is_Task_Type
(Etype
(P
))
3541 or else (Is_Access_Type
(Etype
(P
))
3542 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3543 or else (Ada_Version
>= Ada_2005
3544 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3545 and then Is_Interface
(Etype
(P
))
3546 and then Is_Task_Interface
(Etype
(P
)))
3549 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3552 if Ada_Version
>= Ada_2005
then
3554 ("prefix of % attribute must be an exception, a " &
3555 "task or a task interface class-wide object");
3558 ("prefix of % attribute must be a task or an exception");
3566 when Attribute_Image
=> Image
:
3568 Check_SPARK_Restriction_On_Attribute
;
3570 Set_Etype
(N
, Standard_String
);
3572 if Is_Real_Type
(P_Type
) then
3573 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3574 Error_Msg_Name_1
:= Aname
;
3576 ("(Ada 83) % attribute not allowed for real types", N
);
3580 if Is_Enumeration_Type
(P_Type
) then
3581 Check_Restriction
(No_Enumeration_Maps
, N
);
3585 Resolve
(E1
, P_Base_Type
);
3587 Validate_Non_Static_Attribute_Function_Call
;
3594 when Attribute_Img
=> Img
:
3597 Set_Etype
(N
, Standard_String
);
3599 if not Is_Scalar_Type
(P_Type
)
3600 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3603 ("prefix of % attribute must be scalar object name");
3613 when Attribute_Input
=>
3615 Check_Stream_Attribute
(TSS_Stream_Input
);
3616 Set_Etype
(N
, P_Base_Type
);
3622 when Attribute_Integer_Value
=>
3625 Resolve
(E1
, Any_Fixed
);
3627 -- Signal an error if argument type is not a specific fixed-point
3628 -- subtype. An error has been signalled already if the argument
3629 -- was not of a fixed-point type.
3631 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3632 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3635 Set_Etype
(N
, P_Base_Type
);
3641 when Attribute_Invalid_Value
=>
3644 Set_Etype
(N
, P_Base_Type
);
3645 Invalid_Value_Used
:= True;
3651 when Attribute_Large
=>
3654 Set_Etype
(N
, Universal_Real
);
3660 when Attribute_Last
=>
3661 Check_Array_Or_Scalar_Type
;
3662 Bad_Attribute_For_Predicate
;
3668 when Attribute_Last_Bit
=>
3670 Set_Etype
(N
, Universal_Integer
);
3676 when Attribute_Last_Valid
=>
3677 Check_First_Last_Valid
;
3678 Set_Etype
(N
, P_Type
);
3684 when Attribute_Leading_Part
=>
3685 Check_Floating_Point_Type_2
;
3686 Set_Etype
(N
, P_Base_Type
);
3687 Resolve
(E1
, P_Base_Type
);
3688 Resolve
(E2
, Any_Integer
);
3694 when Attribute_Length
=>
3696 Set_Etype
(N
, Universal_Integer
);
3702 when Attribute_Library_Level
=>
3705 if not Is_Entity_Name
(P
) then
3706 Error_Attr_P
("prefix of % attribute must be an entity name");
3709 if not Inside_A_Generic
then
3710 Set_Boolean_Result
(N
,
3711 Is_Library_Level_Entity
(Entity
(P
)));
3714 Set_Etype
(N
, Standard_Boolean
);
3720 when Attribute_Lock_Free
=>
3722 Set_Etype
(N
, Standard_Boolean
);
3724 if not Is_Protected_Type
(P_Type
) then
3726 ("prefix of % attribute must be a protected object");
3733 when Attribute_Loop_Entry
=> Loop_Entry
: declare
3734 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
3735 -- Inspect the prefix for any uses of entities declared within the
3736 -- related loop. Loop_Id denotes the loop identifier.
3738 --------------------------------
3739 -- Check_References_In_Prefix --
3740 --------------------------------
3742 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
3743 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
3745 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
3746 -- Determine whether a reference mentions an entity declared
3747 -- within the related loop.
3749 function Declared_Within
(Nod
: Node_Id
) return Boolean;
3750 -- Determine whether Nod appears in the subtree of Loop_Decl
3752 ---------------------
3753 -- Check_Reference --
3754 ---------------------
3756 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
3758 if Nkind
(Nod
) = N_Identifier
3759 and then Present
(Entity
(Nod
))
3760 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
3763 ("prefix of attribute % cannot reference local entities",
3769 end Check_Reference
;
3771 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
3773 ---------------------
3774 -- Declared_Within --
3775 ---------------------
3777 function Declared_Within
(Nod
: Node_Id
) return Boolean is
3782 while Present
(Stmt
) loop
3783 if Stmt
= Loop_Decl
then
3786 -- Prevent the search from going too far
3788 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3792 Stmt
:= Parent
(Stmt
);
3796 end Declared_Within
;
3798 -- Start of processing for Check_Prefix_For_Local_References
3801 Check_References
(P
);
3802 end Check_References_In_Prefix
;
3806 Context
: constant Node_Id
:= Parent
(N
);
3808 Enclosing_Loop
: Node_Id
;
3809 In_Loop_Assertion
: Boolean := False;
3810 Loop_Id
: Entity_Id
:= Empty
;
3814 -- Start of processing for Loop_Entry
3819 -- Set the type of the attribute now to ensure the successfull
3820 -- continuation of analysis even if the attribute is misplaced.
3822 Set_Etype
(Attr
, P_Type
);
3824 -- Attribute 'Loop_Entry may appear in several flavors:
3826 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3827 -- nearest enclosing loop.
3829 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3830 -- attribute may be related to a loop denoted by label Expr or
3831 -- the prefix may denote an array object and Expr may act as an
3832 -- indexed component.
3834 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3835 -- to the nearest enclosing loop, all expressions are part of
3836 -- an indexed component.
3838 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3839 -- denotes, the attribute may be related to a loop denoted by
3840 -- label Expr or the prefix may denote a multidimensional array
3841 -- array object and Expr along with the rest of the expressions
3842 -- may act as indexed components.
3844 -- Regardless of variations, the attribute reference does not have an
3845 -- expression list. Instead, all available expressions are stored as
3846 -- indexed components.
3848 -- When the attribute is part of an indexed component, find the first
3849 -- expression as it will determine the semantics of 'Loop_Entry.
3851 if Nkind
(Context
) = N_Indexed_Component
then
3852 E1
:= First
(Expressions
(Context
));
3855 -- The attribute reference appears in the following form:
3857 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3859 -- In this case, the loop name is omitted and no rewriting is
3862 if Present
(E2
) then
3865 -- The form of the attribute is:
3867 -- Prefix'Loop_Entry (Expr) [(...)]
3869 -- If Expr denotes a loop entry, the whole attribute and indexed
3870 -- component will have to be rewritten to reflect this relation.
3873 pragma Assert
(Present
(E1
));
3875 -- Do not expand the expression as it may have side effects.
3876 -- Simply preanalyze to determine whether it is a loop name or
3879 Preanalyze_And_Resolve
(E1
);
3881 if Is_Entity_Name
(E1
)
3882 and then Present
(Entity
(E1
))
3883 and then Ekind
(Entity
(E1
)) = E_Loop
3885 Loop_Id
:= Entity
(E1
);
3887 -- Transform the attribute and enclosing indexed component
3889 Set_Expressions
(N
, Expressions
(Context
));
3890 Rewrite
(Context
, N
);
3891 Set_Etype
(Context
, P_Type
);
3898 -- The prefix must denote an object
3900 if not Is_Object_Reference
(P
) then
3901 Error_Attr_P
("prefix of attribute % must denote an object");
3904 -- The prefix cannot be of a limited type because the expansion of
3905 -- Loop_Entry must create a constant initialized by the evaluated
3908 if Is_Limited_View
(Etype
(P
)) then
3909 Error_Attr_P
("prefix of attribute % cannot be limited");
3912 -- Climb the parent chain to verify the location of the attribute and
3913 -- find the enclosing loop.
3916 while Present
(Stmt
) loop
3918 -- Locate the corresponding enclosing pragma. Note that in the
3919 -- case of Assert[And_Cut] and Assume, we have already checked
3920 -- that the pragma appears in an appropriate loop location.
3922 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
3923 and then Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
3924 Name_Loop_Invariant
,
3927 Name_Assert_And_Cut
,
3930 In_Loop_Assertion
:= True;
3932 -- Locate the enclosing loop (if any). Note that Ada 2012 array
3933 -- iteration may be expanded into several nested loops, we are
3934 -- interested in the outermost one which has the loop identifier.
3936 elsif Nkind
(Stmt
) = N_Loop_Statement
3937 and then Present
(Identifier
(Stmt
))
3939 Enclosing_Loop
:= Stmt
;
3941 -- The original attribute reference may lack a loop name. Use
3942 -- the name of the enclosing loop because it is the related
3945 if No
(Loop_Id
) then
3946 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
3951 -- Prevent the search from going too far
3953 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
3957 Stmt
:= Parent
(Stmt
);
3960 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
3961 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
3962 -- purpose if they appear in an appropriate location in a loop,
3963 -- which was already checked by the top level pragma circuit).
3965 if not In_Loop_Assertion
then
3967 ("attribute % must appear within appropriate pragma", N
);
3970 -- A Loop_Entry that applies to a given loop statement shall not
3971 -- appear within a body of accept statement, if this construct is
3972 -- itself enclosed by the given loop statement.
3974 for Index
in reverse 0 .. Scope_Stack
.Last
loop
3975 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
3977 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
3980 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
3985 ("attribute % cannot appear in body or accept statement", N
);
3990 -- The prefix cannot mention entities declared within the related
3991 -- loop because they will not be visible once the prefix is moved
3992 -- outside the loop.
3994 Check_References_In_Prefix
(Loop_Id
);
3996 -- The prefix must denote a static entity if the pragma does not
3997 -- apply to the innermost enclosing loop statement, or if it appears
3998 -- within a potentially unevaluated epxression.
4000 if Is_Entity_Name
(P
)
4001 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4005 elsif Present
(Enclosing_Loop
)
4006 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
4008 Error_Attr_P
("prefix of attribute % that applies to "
4009 & "outer loop must denote an entity");
4011 elsif Is_Potentially_Unevaluated
(P
) then
4012 Error_Attr_P
("prefix of attribute % that is potentially "
4013 & "unevaluated must denote an entity");
4021 when Attribute_Machine
=>
4022 Check_Floating_Point_Type_1
;
4023 Set_Etype
(N
, P_Base_Type
);
4024 Resolve
(E1
, P_Base_Type
);
4030 when Attribute_Machine_Emax
=>
4031 Check_Floating_Point_Type_0
;
4032 Set_Etype
(N
, Universal_Integer
);
4038 when Attribute_Machine_Emin
=>
4039 Check_Floating_Point_Type_0
;
4040 Set_Etype
(N
, Universal_Integer
);
4042 ----------------------
4043 -- Machine_Mantissa --
4044 ----------------------
4046 when Attribute_Machine_Mantissa
=>
4047 Check_Floating_Point_Type_0
;
4048 Set_Etype
(N
, Universal_Integer
);
4050 -----------------------
4051 -- Machine_Overflows --
4052 -----------------------
4054 when Attribute_Machine_Overflows
=>
4057 Set_Etype
(N
, Standard_Boolean
);
4063 when Attribute_Machine_Radix
=>
4066 Set_Etype
(N
, Universal_Integer
);
4068 ----------------------
4069 -- Machine_Rounding --
4070 ----------------------
4072 when Attribute_Machine_Rounding
=>
4073 Check_Floating_Point_Type_1
;
4074 Set_Etype
(N
, P_Base_Type
);
4075 Resolve
(E1
, P_Base_Type
);
4077 --------------------
4078 -- Machine_Rounds --
4079 --------------------
4081 when Attribute_Machine_Rounds
=>
4084 Set_Etype
(N
, Standard_Boolean
);
4090 when Attribute_Machine_Size
=>
4093 Check_Not_Incomplete_Type
;
4094 Set_Etype
(N
, Universal_Integer
);
4100 when Attribute_Mantissa
=>
4103 Set_Etype
(N
, Universal_Integer
);
4109 when Attribute_Max
=>
4112 Resolve
(E1
, P_Base_Type
);
4113 Resolve
(E2
, P_Base_Type
);
4114 Set_Etype
(N
, P_Base_Type
);
4116 ----------------------------------
4117 -- Max_Alignment_For_Allocation --
4118 -- Max_Size_In_Storage_Elements --
4119 ----------------------------------
4121 when Attribute_Max_Alignment_For_Allocation |
4122 Attribute_Max_Size_In_Storage_Elements
=>
4125 Check_Not_Incomplete_Type
;
4126 Set_Etype
(N
, Universal_Integer
);
4128 -----------------------
4129 -- Maximum_Alignment --
4130 -----------------------
4132 when Attribute_Maximum_Alignment
=>
4133 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4135 --------------------
4136 -- Mechanism_Code --
4137 --------------------
4139 when Attribute_Mechanism_Code
=>
4140 if not Is_Entity_Name
(P
)
4141 or else not Is_Subprogram
(Entity
(P
))
4143 Error_Attr_P
("prefix of % attribute must be subprogram");
4146 Check_Either_E0_Or_E1
;
4148 if Present
(E1
) then
4149 Resolve
(E1
, Any_Integer
);
4150 Set_Etype
(E1
, Standard_Integer
);
4152 if not Is_Static_Expression
(E1
) then
4153 Flag_Non_Static_Expr
4154 ("expression for parameter number must be static!", E1
);
4157 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4158 or else UI_To_Int
(Intval
(E1
)) < 0
4160 Error_Attr
("invalid parameter number for % attribute", E1
);
4164 Set_Etype
(N
, Universal_Integer
);
4170 when Attribute_Min
=>
4173 Resolve
(E1
, P_Base_Type
);
4174 Resolve
(E2
, P_Base_Type
);
4175 Set_Etype
(N
, P_Base_Type
);
4181 when Attribute_Mod
=>
4183 -- Note: this attribute is only allowed in Ada 2005 mode, but
4184 -- we do not need to test that here, since Mod is only recognized
4185 -- as an attribute name in Ada 2005 mode during the parse.
4188 Check_Modular_Integer_Type
;
4189 Resolve
(E1
, Any_Integer
);
4190 Set_Etype
(N
, P_Base_Type
);
4196 when Attribute_Model
=>
4197 Check_Floating_Point_Type_1
;
4198 Set_Etype
(N
, P_Base_Type
);
4199 Resolve
(E1
, P_Base_Type
);
4205 when Attribute_Model_Emin
=>
4206 Check_Floating_Point_Type_0
;
4207 Set_Etype
(N
, Universal_Integer
);
4213 when Attribute_Model_Epsilon
=>
4214 Check_Floating_Point_Type_0
;
4215 Set_Etype
(N
, Universal_Real
);
4217 --------------------
4218 -- Model_Mantissa --
4219 --------------------
4221 when Attribute_Model_Mantissa
=>
4222 Check_Floating_Point_Type_0
;
4223 Set_Etype
(N
, Universal_Integer
);
4229 when Attribute_Model_Small
=>
4230 Check_Floating_Point_Type_0
;
4231 Set_Etype
(N
, Universal_Real
);
4237 when Attribute_Modulus
=>
4239 Check_Modular_Integer_Type
;
4240 Set_Etype
(N
, Universal_Integer
);
4242 --------------------
4243 -- Null_Parameter --
4244 --------------------
4246 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4247 Parnt
: constant Node_Id
:= Parent
(N
);
4248 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4250 procedure Bad_Null_Parameter
(Msg
: String);
4251 -- Used if bad Null parameter attribute node is found. Issues
4252 -- given error message, and also sets the type to Any_Type to
4253 -- avoid blowups later on from dealing with a junk node.
4255 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4256 -- Called to check that Proc_Ent is imported subprogram
4258 ------------------------
4259 -- Bad_Null_Parameter --
4260 ------------------------
4262 procedure Bad_Null_Parameter
(Msg
: String) is
4264 Error_Msg_N
(Msg
, N
);
4265 Set_Etype
(N
, Any_Type
);
4266 end Bad_Null_Parameter
;
4268 ----------------------
4269 -- Must_Be_Imported --
4270 ----------------------
4272 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4273 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4276 -- Ignore check if procedure not frozen yet (we will get
4277 -- another chance when the default parameter is reanalyzed)
4279 if not Is_Frozen
(Pent
) then
4282 elsif not Is_Imported
(Pent
) then
4284 ("Null_Parameter can only be used with imported subprogram");
4289 end Must_Be_Imported
;
4291 -- Start of processing for Null_Parameter
4296 Set_Etype
(N
, P_Type
);
4298 -- Case of attribute used as default expression
4300 if Nkind
(Parnt
) = N_Parameter_Specification
then
4301 Must_Be_Imported
(Defining_Entity
(GParnt
));
4303 -- Case of attribute used as actual for subprogram (positional)
4305 elsif Nkind
(Parnt
) in N_Subprogram_Call
4306 and then Is_Entity_Name
(Name
(Parnt
))
4308 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4310 -- Case of attribute used as actual for subprogram (named)
4312 elsif Nkind
(Parnt
) = N_Parameter_Association
4313 and then Nkind
(GParnt
) in N_Subprogram_Call
4314 and then Is_Entity_Name
(Name
(GParnt
))
4316 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4318 -- Not an allowed case
4322 ("Null_Parameter must be actual or default parameter");
4330 when Attribute_Object_Size
=>
4333 Check_Not_Incomplete_Type
;
4334 Set_Etype
(N
, Universal_Integer
);
4340 when Attribute_Old
=> Old
: declare
4342 -- The enclosing scope, excluding loops for quantified expressions.
4343 -- During analysis, it is the postcondition subprogram. During
4344 -- pre-analysis, it is the scope of the subprogram declaration.
4347 -- During pre-analysis, Prag is the enclosing pragma node if any
4352 -- Find enclosing scopes, excluding loops
4354 CS
:= Current_Scope
;
4355 while Ekind
(CS
) = E_Loop
loop
4359 -- If we are in Spec_Expression mode, this should be the prescan of
4360 -- the postcondition (or contract case, or test case) pragma.
4362 if In_Spec_Expression
then
4364 -- Check in postcondition, Test_Case or Contract_Cases
4367 while Present
(Prag
)
4368 and then not Nkind_In
(Prag
, N_Pragma
,
4369 N_Function_Specification
,
4370 N_Procedure_Specification
,
4371 N_Aspect_Specification
,
4374 Prag
:= Parent
(Prag
);
4377 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4378 -- corresponding pragma. Do not issue errors when analyzing the
4381 if Nkind
(Prag
) = N_Aspect_Specification
then
4384 -- We must have a pragma
4386 elsif Nkind
(Prag
) /= N_Pragma
then
4387 Error_Attr
("% attribute can only appear in postcondition", P
);
4389 -- Processing depends on which pragma we have
4392 case Get_Pragma_Id
(Prag
) is
4393 when Pragma_Test_Case
=>
4395 Arg_Ens
: constant Node_Id
:=
4396 Get_Ensures_From_CTC_Pragma
(Prag
);
4401 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
4402 Arg
:= Parent
(Arg
);
4405 if Arg
/= Arg_Ens
then
4407 ("% attribute misplaced inside test case", P
);
4411 when Pragma_Contract_Cases
=>
4413 Aggr
: constant Node_Id
:=
4415 (First
(Pragma_Argument_Associations
(Prag
)));
4421 and then Parent
(Parent
(Arg
)) /= Aggr
4423 Arg
:= Parent
(Arg
);
4426 -- At this point, Parent (Arg) should be a component
4427 -- association. Attribute Result is only allowed in
4428 -- the expression part of this association.
4430 if Nkind
(Parent
(Arg
)) /= N_Component_Association
4431 or else Arg
/= Expression
(Parent
(Arg
))
4434 ("% attribute misplaced inside contract cases",
4439 when Pragma_Postcondition | Pragma_Refined_Post
=>
4444 ("% attribute can only appear in postcondition", P
);
4448 -- Check the legality of attribute 'Old when it appears inside pragma
4449 -- Refined_Post. These specialized checks are required only when code
4450 -- generation is disabled. In the general case pragma Refined_Post is
4451 -- transformed into pragma Check by Process_PPCs which in turn is
4452 -- relocated to procedure _Postconditions. From then on the legality
4453 -- of 'Old is determined as usual.
4455 elsif not Expander_Active
and then In_Refined_Post
then
4456 Preanalyze_And_Resolve
(P
);
4457 P_Type
:= Etype
(P
);
4458 Set_Etype
(N
, P_Type
);
4460 if Is_Limited_Type
(P_Type
) then
4461 Error_Attr
("attribute % cannot apply to limited objects", P
);
4464 if Is_Entity_Name
(P
)
4465 and then Is_Constant_Object
(Entity
(P
))
4468 ("??attribute Old applied to constant has no effect", P
);
4473 -- Body case, where we must be inside a generated _Postconditions
4474 -- procedure, or else the attribute use is definitely misplaced. The
4475 -- postcondition itself may have generated transient scopes, and is
4476 -- not necessarily the current one.
4479 while Present
(CS
) and then CS
/= Standard_Standard
loop
4480 if Chars
(CS
) = Name_uPostconditions
then
4487 if Chars
(CS
) /= Name_uPostconditions
then
4488 Error_Attr
("% attribute can only appear in postcondition", P
);
4492 -- If the attribute reference is generated for a Requires clause,
4493 -- then no expressions follow. Otherwise it is a primary, in which
4494 -- case, if expressions follow, the attribute reference must be an
4495 -- indexable object, so rewrite the node accordingly.
4497 if Present
(E1
) then
4499 Make_Indexed_Component
(Loc
,
4501 Make_Attribute_Reference
(Loc
,
4502 Prefix
=> Relocate_Node
(Prefix
(N
)),
4503 Attribute_Name
=> Name_Old
),
4504 Expressions
=> Expressions
(N
)));
4512 -- Prefix has not been analyzed yet, and its full analysis will take
4513 -- place during expansion (see below).
4515 Preanalyze_And_Resolve
(P
);
4516 P_Type
:= Etype
(P
);
4517 Set_Etype
(N
, P_Type
);
4519 if Is_Limited_Type
(P_Type
) then
4520 Error_Attr
("attribute % cannot apply to limited objects", P
);
4523 if Is_Entity_Name
(P
)
4524 and then Is_Constant_Object
(Entity
(P
))
4527 ("??attribute Old applied to constant has no effect", P
);
4530 -- Check that the prefix of 'Old is an entity, when it appears in
4531 -- a postcondition and may be potentially unevaluated (6.1.1 (27/3)).
4534 and then Get_Pragma_Id
(Prag
) = Pragma_Postcondition
4535 and then Is_Potentially_Unevaluated
(N
)
4536 and then not Is_Entity_Name
(P
)
4538 Error_Attr_P
("prefix of attribute % that is potentially "
4539 & "unevaluated must denote an entity");
4542 -- The attribute appears within a pre/postcondition, but refers to
4543 -- an entity in the enclosing subprogram. If it is a component of
4544 -- a formal its expansion might generate actual subtypes that may
4545 -- be referenced in an inner context, and which must be elaborated
4546 -- within the subprogram itself. If the prefix includes a function
4547 -- call it may involve finalization actions that should only be
4548 -- inserted when the attribute has been rewritten as a declarations.
4549 -- As a result, if the prefix is not a simple name we create
4550 -- a declaration for it now, and insert it at the start of the
4551 -- enclosing subprogram. This is properly an expansion activity
4552 -- but it has to be performed now to prevent out-of-order issues.
4554 -- This expansion is both harmful and not needed in SPARK mode, since
4555 -- the formal verification backend relies on the types of nodes
4556 -- (hence is not robust w.r.t. a change to base type here), and does
4557 -- not suffer from the out-of-order issue described above. Thus, this
4558 -- expansion is skipped in SPARK mode.
4560 if not Is_Entity_Name
(P
) and then not GNATprove_Mode
then
4561 P_Type
:= Base_Type
(P_Type
);
4562 Set_Etype
(N
, P_Type
);
4563 Set_Etype
(P
, P_Type
);
4564 Analyze_Dimension
(N
);
4569 ----------------------
4570 -- Overlaps_Storage --
4571 ----------------------
4573 when Attribute_Overlaps_Storage
=>
4576 -- Both arguments must be objects of any type
4578 Analyze_And_Resolve
(P
);
4579 Analyze_And_Resolve
(E1
);
4580 Check_Object_Reference
(P
);
4581 Check_Object_Reference
(E1
);
4582 Set_Etype
(N
, Standard_Boolean
);
4588 when Attribute_Output
=>
4590 Check_Stream_Attribute
(TSS_Stream_Output
);
4591 Set_Etype
(N
, Standard_Void_Type
);
4592 Resolve
(N
, Standard_Void_Type
);
4598 when Attribute_Partition_ID
=> Partition_Id
:
4602 if P_Type
/= Any_Type
then
4603 if not Is_Library_Level_Entity
(Entity
(P
)) then
4605 ("prefix of % attribute must be library-level entity");
4607 -- The defining entity of prefix should not be declared inside a
4608 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4610 elsif Is_Entity_Name
(P
)
4611 and then Is_Pure
(Entity
(P
))
4613 Error_Attr_P
("prefix of% attribute must not be declared pure");
4617 Set_Etype
(N
, Universal_Integer
);
4620 -------------------------
4621 -- Passed_By_Reference --
4622 -------------------------
4624 when Attribute_Passed_By_Reference
=>
4627 Set_Etype
(N
, Standard_Boolean
);
4633 when Attribute_Pool_Address
=>
4635 Set_Etype
(N
, RTE
(RE_Address
));
4641 when Attribute_Pos
=>
4642 Check_Discrete_Type
;
4645 if Is_Boolean_Type
(P_Type
) then
4646 Error_Msg_Name_1
:= Aname
;
4647 Error_Msg_Name_2
:= Chars
(P_Type
);
4648 Check_SPARK_Restriction
4649 ("attribute% is not allowed for type%", P
);
4652 Resolve
(E1
, P_Base_Type
);
4653 Set_Etype
(N
, Universal_Integer
);
4659 when Attribute_Position
=>
4661 Set_Etype
(N
, Universal_Integer
);
4667 when Attribute_Pred
=>
4671 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
4672 Error_Msg_Name_1
:= Aname
;
4673 Error_Msg_Name_2
:= Chars
(P_Type
);
4674 Check_SPARK_Restriction
4675 ("attribute% is not allowed for type%", P
);
4678 Resolve
(E1
, P_Base_Type
);
4679 Set_Etype
(N
, P_Base_Type
);
4681 -- Nothing to do for real type case
4683 if Is_Real_Type
(P_Type
) then
4686 -- If not modular type, test for overflow check required
4689 if not Is_Modular_Integer_Type
(P_Type
)
4690 and then not Range_Checks_Suppressed
(P_Base_Type
)
4692 Enable_Range_Check
(E1
);
4700 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4702 when Attribute_Priority
=>
4703 if Ada_Version
< Ada_2005
then
4704 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
4709 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4713 if Is_Protected_Type
(Etype
(P
))
4714 or else (Is_Access_Type
(Etype
(P
))
4715 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
4717 Resolve
(P
, Etype
(P
));
4719 Error_Attr_P
("prefix of % attribute must be a protected object");
4722 Set_Etype
(N
, Standard_Integer
);
4724 -- Must be called from within a protected procedure or entry of the
4725 -- protected object.
4732 while S
/= Etype
(P
)
4733 and then S
/= Standard_Standard
4738 if S
= Standard_Standard
then
4739 Error_Attr
("the attribute % is only allowed inside protected "
4744 Validate_Non_Static_Attribute_Function_Call
;
4750 when Attribute_Range
=>
4751 Check_Array_Or_Scalar_Type
;
4752 Bad_Attribute_For_Predicate
;
4754 if Ada_Version
= Ada_83
4755 and then Is_Scalar_Type
(P_Type
)
4756 and then Comes_From_Source
(N
)
4759 ("(Ada 83) % attribute not allowed for scalar type", P
);
4766 when Attribute_Result
=> Result
: declare
4768 -- The enclosing scope, excluding loops for quantified expressions
4771 -- During analysis, CS is the postcondition subprogram and PS the
4772 -- source subprogram to which the postcondition applies. During
4773 -- pre-analysis, CS is the scope of the subprogram declaration.
4776 -- During pre-analysis, Prag is the enclosing pragma node if any
4779 -- Find the proper enclosing scope
4781 CS
:= Current_Scope
;
4782 while Present
(CS
) loop
4784 -- Skip generated loops
4786 if Ekind
(CS
) = E_Loop
then
4789 -- Skip the special _Parent scope generated to capture references
4790 -- to formals during the process of subprogram inlining.
4792 elsif Ekind
(CS
) = E_Function
4793 and then Chars
(CS
) = Name_uParent
4803 -- If the enclosing subprogram is always inlined, the enclosing
4804 -- postcondition will not be propagated to the expanded call.
4806 if not In_Spec_Expression
4807 and then Has_Pragma_Inline_Always
(PS
)
4808 and then Warn_On_Redundant_Constructs
4811 ("postconditions on inlined functions not enforced?r?", N
);
4814 -- If we are in the scope of a function and in Spec_Expression mode,
4815 -- this is likely the prescan of the postcondition (or contract case,
4816 -- or test case) pragma, and we just set the proper type. If there is
4817 -- an error it will be caught when the real Analyze call is done.
4819 if Ekind
(CS
) = E_Function
4820 and then In_Spec_Expression
4824 if Chars
(CS
) /= Chars
(P
) then
4825 Error_Msg_Name_1
:= Name_Result
;
4828 ("incorrect prefix for % attribute, expected &", P
, CS
);
4832 -- Check in postcondition, Test_Case or Contract_Cases of function
4835 while Present
(Prag
)
4836 and then not Nkind_In
(Prag
, N_Pragma
,
4837 N_Function_Specification
,
4838 N_Aspect_Specification
,
4841 Prag
:= Parent
(Prag
);
4844 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4845 -- corresponding pragma. Do not issue errors when analyzing the
4848 if Nkind
(Prag
) = N_Aspect_Specification
then
4851 -- Must have a pragma
4853 elsif Nkind
(Prag
) /= N_Pragma
then
4855 ("% attribute can only appear in postcondition of function",
4858 -- Processing depends on which pragma we have
4861 case Get_Pragma_Id
(Prag
) is
4863 when Pragma_Test_Case
=>
4865 Arg_Ens
: constant Node_Id
:=
4866 Get_Ensures_From_CTC_Pragma
(Prag
);
4871 while Arg
/= Prag
and then Arg
/= Arg_Ens
loop
4872 Arg
:= Parent
(Arg
);
4875 if Arg
/= Arg_Ens
then
4877 ("% attribute misplaced inside test case", P
);
4881 when Pragma_Contract_Cases
=>
4883 Aggr
: constant Node_Id
:=
4885 (Pragma_Argument_Associations
(Prag
)));
4891 and then Parent
(Parent
(Arg
)) /= Aggr
4893 Arg
:= Parent
(Arg
);
4896 -- At this point, Parent (Arg) should be a component
4897 -- association. Attribute Result is only allowed in
4898 -- the expression part of this association.
4900 if Nkind
(Parent
(Arg
)) /= N_Component_Association
4901 or else Arg
/= Expression
(Parent
(Arg
))
4904 ("% attribute misplaced inside contract cases",
4909 when Pragma_Postcondition | Pragma_Refined_Post
=>
4914 ("% attribute can only appear in postcondition "
4915 & "of function", P
);
4919 -- The attribute reference is a primary. If expressions follow,
4920 -- the attribute reference is really an indexable object, so
4921 -- rewrite and analyze as an indexed component.
4923 if Present
(E1
) then
4925 Make_Indexed_Component
(Loc
,
4927 Make_Attribute_Reference
(Loc
,
4928 Prefix
=> Relocate_Node
(Prefix
(N
)),
4929 Attribute_Name
=> Name_Result
),
4930 Expressions
=> Expressions
(N
)));
4935 Set_Etype
(N
, Etype
(CS
));
4937 -- If several functions with that name are visible, the intended
4938 -- one is the current scope.
4940 if Is_Overloaded
(P
) then
4942 Set_Is_Overloaded
(P
, False);
4945 -- Check the legality of attribute 'Result when it appears inside
4946 -- pragma Refined_Post. These specialized checks are required only
4947 -- when code generation is disabled. In the general case pragma
4948 -- Refined_Post is transformed into pragma Check by Process_PPCs
4949 -- which in turn is relocated to procedure _Postconditions. From
4950 -- then on the legality of 'Result is determined as usual.
4952 elsif not Expander_Active
and then In_Refined_Post
then
4953 PS
:= Current_Scope
;
4955 -- The prefix denotes the proper related function
4957 if Is_Entity_Name
(P
)
4958 and then Ekind
(Entity
(P
)) = E_Function
4959 and then Entity
(P
) = PS
4964 Error_Msg_Name_2
:= Chars
(PS
);
4965 Error_Attr
("incorrect prefix for % attribute, expected %", P
);
4968 Set_Etype
(N
, Etype
(PS
));
4970 -- Body case, where we must be inside a generated _Postconditions
4971 -- procedure, and the prefix must be on the scope stack, or else the
4972 -- attribute use is definitely misplaced. The postcondition itself
4973 -- may have generated transient scopes, and is not necessarily the
4977 while Present
(CS
) and then CS
/= Standard_Standard
loop
4978 if Chars
(CS
) = Name_uPostconditions
then
4987 if Chars
(CS
) = Name_uPostconditions
4988 and then Ekind
(PS
) = E_Function
4992 if Nkind_In
(P
, N_Identifier
, N_Operator_Symbol
)
4993 and then Chars
(P
) = Chars
(PS
)
4997 -- Within an instance, the prefix designates the local renaming
4998 -- of the original generic.
5000 elsif Is_Entity_Name
(P
)
5001 and then Ekind
(Entity
(P
)) = E_Function
5002 and then Present
(Alias
(Entity
(P
)))
5003 and then Chars
(Alias
(Entity
(P
))) = Chars
(PS
)
5008 Error_Msg_Name_2
:= Chars
(PS
);
5010 ("incorrect prefix for % attribute, expected %", P
);
5013 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Name_uResult
));
5014 Analyze_And_Resolve
(N
, Etype
(PS
));
5018 ("% attribute can only appear in postcondition of function",
5028 when Attribute_Range_Length
=>
5030 Check_Discrete_Type
;
5031 Set_Etype
(N
, Universal_Integer
);
5037 when Attribute_Read
=>
5039 Check_Stream_Attribute
(TSS_Stream_Read
);
5040 Set_Etype
(N
, Standard_Void_Type
);
5041 Resolve
(N
, Standard_Void_Type
);
5042 Note_Possible_Modification
(E2
, Sure
=> True);
5048 when Attribute_Ref
=>
5052 if Nkind
(P
) /= N_Expanded_Name
5053 or else not Is_RTE
(P_Type
, RE_Address
)
5055 Error_Attr_P
("prefix of % attribute must be System.Address");
5058 Analyze_And_Resolve
(E1
, Any_Integer
);
5059 Set_Etype
(N
, RTE
(RE_Address
));
5065 when Attribute_Remainder
=>
5066 Check_Floating_Point_Type_2
;
5067 Set_Etype
(N
, P_Base_Type
);
5068 Resolve
(E1
, P_Base_Type
);
5069 Resolve
(E2
, P_Base_Type
);
5071 ---------------------
5072 -- Restriction_Set --
5073 ---------------------
5075 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5078 Unam
: Unit_Name_Type
;
5083 Check_System_Prefix
;
5085 -- No_Dependence case
5087 if Nkind
(E1
) = N_Parameter_Association
then
5088 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5089 U
:= Explicit_Actual_Parameter
(E1
);
5091 if not OK_No_Dependence_Unit_Name
(U
) then
5092 Set_Boolean_Result
(N
, False);
5096 -- See if there is an entry already in the table. That's the
5097 -- case in which we can return True.
5099 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5100 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5101 and then No_Dependences
.Table
(J
).Warn
= False
5103 Set_Boolean_Result
(N
, True);
5108 -- If not in the No_Dependence table, result is False
5110 Set_Boolean_Result
(N
, False);
5112 -- In this case, we must ensure that the binder will reject any
5113 -- other unit in the partition that sets No_Dependence for this
5114 -- unit. We do that by making an entry in the special table kept
5115 -- for this purpose (if the entry is not there already).
5117 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5119 for J
in Restriction_Set_Dependences
.First
..
5120 Restriction_Set_Dependences
.Last
5122 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5127 Restriction_Set_Dependences
.Append
(Unam
);
5129 -- Normal restriction case
5132 if Nkind
(E1
) /= N_Identifier
then
5133 Set_Boolean_Result
(N
, False);
5134 Error_Attr
("attribute % requires restriction identifier", E1
);
5137 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5139 if R
= Not_A_Restriction_Id
then
5140 Set_Boolean_Result
(N
, False);
5141 Error_Msg_Node_1
:= E1
;
5142 Error_Attr
("invalid restriction identifier &", E1
);
5144 elsif R
not in Partition_Boolean_Restrictions
then
5145 Set_Boolean_Result
(N
, False);
5146 Error_Msg_Node_1
:= E1
;
5148 ("& is not a boolean partition-wide restriction", E1
);
5151 if Restriction_Active
(R
) then
5152 Set_Boolean_Result
(N
, True);
5154 Check_Restriction
(R
, N
);
5155 Set_Boolean_Result
(N
, False);
5159 end Restriction_Set
;
5165 when Attribute_Round
=>
5167 Check_Decimal_Fixed_Point_Type
;
5168 Set_Etype
(N
, P_Base_Type
);
5170 -- Because the context is universal_real (3.5.10(12)) it is a
5171 -- legal context for a universal fixed expression. This is the
5172 -- only attribute whose functional description involves U_R.
5174 if Etype
(E1
) = Universal_Fixed
then
5176 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5177 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5178 Expression
=> Relocate_Node
(E1
));
5186 Resolve
(E1
, Any_Real
);
5192 when Attribute_Rounding
=>
5193 Check_Floating_Point_Type_1
;
5194 Set_Etype
(N
, P_Base_Type
);
5195 Resolve
(E1
, P_Base_Type
);
5201 when Attribute_Safe_Emax
=>
5202 Check_Floating_Point_Type_0
;
5203 Set_Etype
(N
, Universal_Integer
);
5209 when Attribute_Safe_First
=>
5210 Check_Floating_Point_Type_0
;
5211 Set_Etype
(N
, Universal_Real
);
5217 when Attribute_Safe_Large
=>
5220 Set_Etype
(N
, Universal_Real
);
5226 when Attribute_Safe_Last
=>
5227 Check_Floating_Point_Type_0
;
5228 Set_Etype
(N
, Universal_Real
);
5234 when Attribute_Safe_Small
=>
5237 Set_Etype
(N
, Universal_Real
);
5243 when Attribute_Same_Storage
=>
5244 Check_Ada_2012_Attribute
;
5247 -- The arguments must be objects of any type
5249 Analyze_And_Resolve
(P
);
5250 Analyze_And_Resolve
(E1
);
5251 Check_Object_Reference
(P
);
5252 Check_Object_Reference
(E1
);
5253 Set_Etype
(N
, Standard_Boolean
);
5255 --------------------------
5256 -- Scalar_Storage_Order --
5257 --------------------------
5259 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5261 Ent
: Entity_Id
:= Empty
;
5267 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5269 -- In GNAT mode, the attribute applies to generic types as well
5270 -- as composite types, and for non-composite types always returns
5271 -- the default bit order for the target.
5273 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5274 and then not In_Instance
5277 ("prefix of % attribute must be record or array type");
5279 elsif not Is_Generic_Type
(P_Type
) then
5280 if Bytes_Big_Endian
then
5281 Ent
:= RTE
(RE_High_Order_First
);
5283 Ent
:= RTE
(RE_Low_Order_First
);
5287 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5288 Ent
:= RTE
(RE_High_Order_First
);
5291 Ent
:= RTE
(RE_Low_Order_First
);
5294 if Present
(Ent
) then
5295 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5298 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5301 -- Reset incorrect indication of staticness
5303 Set_Is_Static_Expression
(N
, False);
5304 end Scalar_Storage_Order
;
5310 when Attribute_Scale
=>
5312 Check_Decimal_Fixed_Point_Type
;
5313 Set_Etype
(N
, Universal_Integer
);
5319 when Attribute_Scaling
=>
5320 Check_Floating_Point_Type_2
;
5321 Set_Etype
(N
, P_Base_Type
);
5322 Resolve
(E1
, P_Base_Type
);
5328 when Attribute_Signed_Zeros
=>
5329 Check_Floating_Point_Type_0
;
5330 Set_Etype
(N
, Standard_Boolean
);
5336 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5340 -- If prefix is parameterless function call, rewrite and resolve
5343 if Is_Entity_Name
(P
)
5344 and then Ekind
(Entity
(P
)) = E_Function
5348 -- Similar processing for a protected function call
5350 elsif Nkind
(P
) = N_Selected_Component
5351 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5356 if Is_Object_Reference
(P
) then
5357 Check_Object_Reference
(P
);
5359 elsif Is_Entity_Name
(P
)
5360 and then (Is_Type
(Entity
(P
))
5361 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5365 elsif Nkind
(P
) = N_Type_Conversion
5366 and then not Comes_From_Source
(P
)
5370 -- Some other compilers allow dubious use of X'???'Size
5372 elsif Relaxed_RM_Semantics
5373 and then Nkind
(P
) = N_Attribute_Reference
5378 Error_Attr_P
("invalid prefix for % attribute");
5381 Check_Not_Incomplete_Type
;
5383 Set_Etype
(N
, Universal_Integer
);
5390 when Attribute_Small
=>
5393 Set_Etype
(N
, Universal_Real
);
5399 when Attribute_Storage_Pool |
5400 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5404 if Is_Access_Type
(P_Type
) then
5405 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5407 ("cannot use % attribute for access-to-subprogram type");
5410 -- Set appropriate entity
5412 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5413 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5415 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5418 if Attr_Id
= Attribute_Storage_Pool
then
5419 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5420 Name_Simple_Storage_Pool_Type
))
5422 Error_Msg_Name_1
:= Aname
;
5423 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5424 Error_Msg_N
("cannot use % attribute for type with simple "
5425 & "storage pool<<", N
);
5426 Error_Msg_N
("\Program_Error [<<", N
);
5429 (N
, Make_Raise_Program_Error
5430 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5433 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5435 -- In the Simple_Storage_Pool case, verify that the pool entity is
5436 -- actually of a simple storage pool type, and set the attribute's
5437 -- type to the pool object's type.
5440 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5441 Name_Simple_Storage_Pool_Type
))
5444 ("cannot use % attribute for type without simple " &
5448 Set_Etype
(N
, Etype
(Entity
(N
)));
5451 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5452 -- Storage_Pool since this attribute is not defined for such
5453 -- types (RM E.2.3(22)).
5455 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5458 Error_Attr_P
("prefix of % attribute must be access type");
5466 when Attribute_Storage_Size
=> Storage_Size
:
5470 if Is_Task_Type
(P_Type
) then
5471 Set_Etype
(N
, Universal_Integer
);
5473 -- Use with tasks is an obsolescent feature
5475 Check_Restriction
(No_Obsolescent_Features
, P
);
5477 elsif Is_Access_Type
(P_Type
) then
5478 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5480 ("cannot use % attribute for access-to-subprogram type");
5483 if Is_Entity_Name
(P
)
5484 and then Is_Type
(Entity
(P
))
5487 Set_Etype
(N
, Universal_Integer
);
5489 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5490 -- Storage_Size since this attribute is not defined for
5491 -- such types (RM E.2.3(22)).
5493 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5495 -- The prefix is allowed to be an implicit dereference of an
5496 -- access value designating a task.
5500 Set_Etype
(N
, Universal_Integer
);
5504 Error_Attr_P
("prefix of % attribute must be access or task type");
5512 when Attribute_Storage_Unit
=>
5513 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5519 when Attribute_Stream_Size
=>
5523 if Is_Entity_Name
(P
)
5524 and then Is_Elementary_Type
(Entity
(P
))
5526 Set_Etype
(N
, Universal_Integer
);
5528 Error_Attr_P
("invalid prefix for % attribute");
5535 when Attribute_Stub_Type
=>
5539 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5541 -- For a real RACW [sub]type, use corresponding stub type
5543 if not Is_Generic_Type
(P_Type
) then
5546 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5548 -- For a generic type (that has been marked as an RACW using the
5549 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5550 -- type. Note that if the actual is not a remote access type, the
5551 -- instantiation will fail.
5554 -- Note: we go to the underlying type here because the view
5555 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5559 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5564 ("prefix of% attribute must be remote access to classwide");
5571 when Attribute_Succ
=>
5575 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5576 Error_Msg_Name_1
:= Aname
;
5577 Error_Msg_Name_2
:= Chars
(P_Type
);
5578 Check_SPARK_Restriction
5579 ("attribute% is not allowed for type%", P
);
5582 Resolve
(E1
, P_Base_Type
);
5583 Set_Etype
(N
, P_Base_Type
);
5585 -- Nothing to do for real type case
5587 if Is_Real_Type
(P_Type
) then
5590 -- If not modular type, test for overflow check required
5593 if not Is_Modular_Integer_Type
(P_Type
)
5594 and then not Range_Checks_Suppressed
(P_Base_Type
)
5596 Enable_Range_Check
(E1
);
5600 --------------------------------
5601 -- System_Allocator_Alignment --
5602 --------------------------------
5604 when Attribute_System_Allocator_Alignment
=>
5605 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5611 when Attribute_Tag
=> Tag
:
5616 if not Is_Tagged_Type
(P_Type
) then
5617 Error_Attr_P
("prefix of % attribute must be tagged");
5619 -- Next test does not apply to generated code why not, and what does
5620 -- the illegal reference mean???
5622 elsif Is_Object_Reference
(P
)
5623 and then not Is_Class_Wide_Type
(P_Type
)
5624 and then Comes_From_Source
(N
)
5627 ("% attribute can only be applied to objects " &
5628 "of class - wide type");
5631 -- The prefix cannot be an incomplete type. However, references to
5632 -- 'Tag can be generated when expanding interface conversions, and
5635 if Comes_From_Source
(N
) then
5636 Check_Not_Incomplete_Type
;
5639 -- Set appropriate type
5641 Set_Etype
(N
, RTE
(RE_Tag
));
5648 when Attribute_Target_Name
=> Target_Name
: declare
5649 TN
: constant String := Sdefault
.Target_Name
.all;
5653 Check_Standard_Prefix
;
5657 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
5662 Make_String_Literal
(Loc
,
5663 Strval
=> TN
(TN
'First .. TL
)));
5664 Analyze_And_Resolve
(N
, Standard_String
);
5671 when Attribute_Terminated
=>
5673 Set_Etype
(N
, Standard_Boolean
);
5680 when Attribute_To_Address
=> To_Address
: declare
5686 Check_System_Prefix
;
5688 Generate_Reference
(RTE
(RE_Address
), P
);
5689 Analyze_And_Resolve
(E1
, Any_Integer
);
5690 Set_Etype
(N
, RTE
(RE_Address
));
5692 -- Static expression case, check range and set appropriate type
5694 if Is_OK_Static_Expression
(E1
) then
5695 Val
:= Expr_Value
(E1
);
5697 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
5699 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
5701 Error_Attr
("address value out of range for % attribute", E1
);
5704 -- In most cases the expression is a numeric literal or some other
5705 -- address expression, but if it is a declared constant it may be
5706 -- of a compatible type that must be left on the node.
5708 if Is_Entity_Name
(E1
) then
5711 -- Set type to universal integer if negative
5714 Set_Etype
(E1
, Universal_Integer
);
5716 -- Otherwise set type to Unsigned_64 to accomodate max values
5719 Set_Etype
(E1
, Standard_Unsigned_64
);
5728 when Attribute_To_Any
=>
5730 Check_PolyORB_Attribute
;
5731 Set_Etype
(N
, RTE
(RE_Any
));
5737 when Attribute_Truncation
=>
5738 Check_Floating_Point_Type_1
;
5739 Resolve
(E1
, P_Base_Type
);
5740 Set_Etype
(N
, P_Base_Type
);
5746 when Attribute_Type_Class
=>
5749 Check_Not_Incomplete_Type
;
5750 Set_Etype
(N
, RTE
(RE_Type_Class
));
5756 when Attribute_TypeCode
=>
5758 Check_PolyORB_Attribute
;
5759 Set_Etype
(N
, RTE
(RE_TypeCode
));
5765 when Attribute_Type_Key
=>
5769 -- This processing belongs in Eval_Attribute ???
5772 function Type_Key
return String_Id
;
5773 -- A very preliminary implementation. For now, a signature
5774 -- consists of only the type name. This is clearly incomplete
5775 -- (e.g., adding a new field to a record type should change the
5776 -- type's Type_Key attribute).
5782 function Type_Key
return String_Id
is
5783 Full_Name
: constant String_Id
:=
5784 Fully_Qualified_Name_String
(Entity
(P
));
5787 -- Copy all characters in Full_Name but the trailing NUL
5790 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
5791 Store_String_Char
(Get_String_Char
(Full_Name
, Int
(J
)));
5794 Store_String_Chars
("'Type_Key");
5799 Rewrite
(N
, Make_String_Literal
(Loc
, Type_Key
));
5802 Analyze_And_Resolve
(N
, Standard_String
);
5808 when Attribute_UET_Address
=>
5810 Check_Unit_Name
(P
);
5811 Set_Etype
(N
, RTE
(RE_Address
));
5813 -----------------------
5814 -- Unbiased_Rounding --
5815 -----------------------
5817 when Attribute_Unbiased_Rounding
=>
5818 Check_Floating_Point_Type_1
;
5819 Set_Etype
(N
, P_Base_Type
);
5820 Resolve
(E1
, P_Base_Type
);
5822 ----------------------
5823 -- Unchecked_Access --
5824 ----------------------
5826 when Attribute_Unchecked_Access
=>
5827 if Comes_From_Source
(N
) then
5828 Check_Restriction
(No_Unchecked_Access
, N
);
5831 Analyze_Access_Attribute
;
5833 -------------------------
5834 -- Unconstrained_Array --
5835 -------------------------
5837 when Attribute_Unconstrained_Array
=>
5840 Check_Not_Incomplete_Type
;
5841 Set_Etype
(N
, Standard_Boolean
);
5843 ------------------------------
5844 -- Universal_Literal_String --
5845 ------------------------------
5847 -- This is a GNAT specific attribute whose prefix must be a named
5848 -- number where the expression is either a single numeric literal,
5849 -- or a numeric literal immediately preceded by a minus sign. The
5850 -- result is equivalent to a string literal containing the text of
5851 -- the literal as it appeared in the source program with a possible
5852 -- leading minus sign.
5854 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
5858 if not Is_Entity_Name
(P
)
5859 or else Ekind
(Entity
(P
)) not in Named_Kind
5861 Error_Attr_P
("prefix for % attribute must be named number");
5868 Src
: Source_Buffer_Ptr
;
5871 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
5873 if Nkind
(Expr
) = N_Op_Minus
then
5875 Expr
:= Original_Node
(Right_Opnd
(Expr
));
5880 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
5882 ("named number for % attribute must be simple literal", N
);
5885 -- Build string literal corresponding to source literal text
5890 Store_String_Char
(Get_Char_Code
('-'));
5894 Src
:= Source_Text
(Get_Source_File_Index
(S
));
5896 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
5897 Store_String_Char
(Get_Char_Code
(Src
(S
)));
5901 -- Now we rewrite the attribute with the string literal
5904 Make_String_Literal
(Loc
, End_String
));
5908 end Universal_Literal_String
;
5910 -------------------------
5911 -- Unrestricted_Access --
5912 -------------------------
5914 -- This is a GNAT specific attribute which is like Access except that
5915 -- all scope checks and checks for aliased views are omitted. It is
5916 -- documented as being equivalent to the use of the Address attribute
5917 -- followed by an unchecked conversion to the target access type.
5919 when Attribute_Unrestricted_Access
=>
5921 -- If from source, deal with relevant restrictions
5923 if Comes_From_Source
(N
) then
5924 Check_Restriction
(No_Unchecked_Access
, N
);
5926 if Nkind
(P
) in N_Has_Entity
5927 and then Present
(Entity
(P
))
5928 and then Is_Object
(Entity
(P
))
5930 Check_Restriction
(No_Implicit_Aliasing
, N
);
5934 if Is_Entity_Name
(P
) then
5935 Set_Address_Taken
(Entity
(P
));
5938 -- It might seem reasonable to call Address_Checks here to apply the
5939 -- same set of semantic checks that we enforce for 'Address (after
5940 -- all we document Unrestricted_Access as being equivalent to the
5941 -- use of Address followed by an Unchecked_Conversion). However, if
5942 -- we do enable these checks, we get multiple failures in both the
5943 -- compiler run-time and in our regression test suite, so we leave
5944 -- out these checks for now. To be investigated further some time???
5948 -- Now complete analysis using common access processing
5950 Analyze_Access_Attribute
;
5956 when Attribute_Update
=> Update
: declare
5957 Comps
: Elist_Id
:= No_Elist
;
5959 procedure Check_Component_Reference
5962 -- Comp is a record component (possibly a discriminant) and Typ is a
5963 -- record type. Determine whether Comp is a legal component of Typ.
5964 -- Emit an error if Comp mentions a discriminant or is not a unique
5965 -- component reference in the update aggregate.
5967 -------------------------------
5968 -- Check_Component_Reference --
5969 -------------------------------
5971 procedure Check_Component_Reference
5975 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
5977 function Is_Duplicate_Component
return Boolean;
5978 -- Determine whether component Comp already appears in list Comps
5980 ----------------------------
5981 -- Is_Duplicate_Component --
5982 ----------------------------
5984 function Is_Duplicate_Component
return Boolean is
5985 Comp_Elmt
: Elmt_Id
;
5988 if Present
(Comps
) then
5989 Comp_Elmt
:= First_Elmt
(Comps
);
5990 while Present
(Comp_Elmt
) loop
5991 if Chars
(Node
(Comp_Elmt
)) = Comp_Name
then
5995 Next_Elmt
(Comp_Elmt
);
6000 end Is_Duplicate_Component
;
6004 Comp_Or_Discr
: Entity_Id
;
6006 -- Start of processing for Check_Component_Reference
6009 -- Find the discriminant or component whose name corresponds to
6010 -- Comp. A simple character comparison is sufficient because all
6011 -- visible names within a record type are unique.
6013 Comp_Or_Discr
:= First_Entity
(Typ
);
6014 while Present
(Comp_Or_Discr
) loop
6015 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6017 -- Record component entity in the given aggregate choice,
6018 -- for subsequent resolution.
6020 Set_Entity
(Comp
, Comp_Or_Discr
);
6024 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6027 -- Diagnose possible erroneous references
6029 if Present
(Comp_Or_Discr
) then
6030 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6032 ("attribute % may not modify record discriminants", Comp
);
6034 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6035 if Is_Duplicate_Component
then
6036 Error_Msg_NE
("component & already updated", Comp
, Comp
);
6038 -- Mark this component as processed
6042 Comps
:= New_Elmt_List
;
6045 Append_Elmt
(Comp
, Comps
);
6049 -- The update aggregate mentions an entity that does not belong to
6054 ("& is not a component of aggregate subtype", Comp
, Comp
);
6056 end Check_Component_Reference
;
6063 -- Start of processing for Update
6067 Check_Ada_2012_Attribute
;
6069 if not Is_Object_Reference
(P
) then
6070 Error_Attr_P
("prefix of attribute % must denote an object");
6072 elsif not Is_Array_Type
(P_Type
)
6073 and then not Is_Record_Type
(P_Type
)
6075 Error_Attr_P
("prefix of attribute % must be a record or array");
6077 elsif Is_Limited_View
(P_Type
) then
6078 Error_Attr
("prefix of attribute % cannot be limited", N
);
6080 elsif Nkind
(E1
) /= N_Aggregate
then
6081 Error_Attr
("attribute % requires component association list", N
);
6084 -- Inspect the update aggregate, looking at all the associations and
6085 -- choices. Perform the following checks:
6087 -- 1) Legality of "others" in all cases
6088 -- 2) Component legality for records
6090 -- The remaining checks are performed on the expanded attribute
6092 Assoc
:= First
(Component_Associations
(E1
));
6093 while Present
(Assoc
) loop
6094 Comp
:= First
(Choices
(Assoc
));
6095 Analyze
(Expression
(Assoc
));
6096 while Present
(Comp
) loop
6097 if Nkind
(Comp
) = N_Others_Choice
then
6099 ("others choice not allowed in attribute %", Comp
);
6101 elsif Is_Array_Type
(P_Type
) then
6104 Index_Type
: Entity_Id
;
6107 if Nkind
(First
(Choices
(Assoc
))) /= N_Aggregate
then
6109 -- Choices denote separate components of one-
6110 -- dimensional array.
6112 Index_Type
:= First_Index
(P_Type
);
6114 Index
:= First
(Choices
(Assoc
));
6115 while Present
(Index
) loop
6116 if Nkind
(Index
) = N_Range
then
6118 (Low_Bound
(Index
), Etype
(Index_Type
));
6120 (High_Bound
(Index
), Etype
(Index_Type
));
6121 Set_Etype
(Index
, Etype
(Index_Type
));
6124 Analyze_And_Resolve
(Index
, Etype
(Index_Type
));
6130 -- Choice is a sequence of indexes for each dimension
6133 Index_Type
:= First_Index
(P_Type
);
6134 Index
:= First
(Expressions
(First
(Choices
(Assoc
))));
6135 while Present
(Index_Type
)
6136 and then Present
(Index
)
6138 Analyze_And_Resolve
(Index
, Etype
(Index_Type
));
6139 Next_Index
(Index_Type
);
6143 if Present
(Index
) or else Present
(Index_Type
) then
6145 ("dimension mismatch in index list", Assoc
);
6150 elsif Is_Record_Type
(P_Type
) then
6151 Check_Component_Reference
(Comp
, P_Type
);
6160 -- The type of attribute Update is that of the prefix
6162 Set_Etype
(N
, P_Type
);
6169 when Attribute_Val
=> Val
: declare
6172 Check_Discrete_Type
;
6174 if Is_Boolean_Type
(P_Type
) then
6175 Error_Msg_Name_1
:= Aname
;
6176 Error_Msg_Name_2
:= Chars
(P_Type
);
6177 Check_SPARK_Restriction
6178 ("attribute% is not allowed for type%", P
);
6181 Resolve
(E1
, Any_Integer
);
6182 Set_Etype
(N
, P_Base_Type
);
6184 -- Note, we need a range check in general, but we wait for the
6185 -- Resolve call to do this, since we want to let Eval_Attribute
6186 -- have a chance to find an static illegality first.
6193 when Attribute_Valid
=>
6196 -- Ignore check for object if we have a 'Valid reference generated
6197 -- by the expanded code, since in some cases valid checks can occur
6198 -- on items that are names, but are not objects (e.g. attributes).
6200 if Comes_From_Source
(N
) then
6201 Check_Object_Reference
(P
);
6204 if not Is_Scalar_Type
(P_Type
) then
6205 Error_Attr_P
("object for % attribute must be of scalar type");
6208 -- If the attribute appears within the subtype's own predicate
6209 -- function, then issue a warning that this will cause infinite
6213 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6216 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6218 ("attribute Valid requires a predicate check??", N
);
6219 Error_Msg_N
("\and will result in infinite recursion??", N
);
6223 Set_Etype
(N
, Standard_Boolean
);
6229 when Attribute_Valid_Scalars
=>
6231 Check_Object_Reference
(P
);
6233 if No_Scalar_Parts
(P_Type
) then
6234 Error_Attr_P
("??attribute % always True, no scalars to check");
6237 Set_Etype
(N
, Standard_Boolean
);
6243 when Attribute_Value
=> Value
:
6245 Check_SPARK_Restriction_On_Attribute
;
6249 -- Case of enumeration type
6251 -- When an enumeration type appears in an attribute reference, all
6252 -- literals of the type are marked as referenced. This must only be
6253 -- done if the attribute reference appears in the current source.
6254 -- Otherwise the information on references may differ between a
6255 -- normal compilation and one that performs inlining.
6257 if Is_Enumeration_Type
(P_Type
)
6258 and then In_Extended_Main_Code_Unit
(N
)
6260 Check_Restriction
(No_Enumeration_Maps
, N
);
6262 -- Mark all enumeration literals as referenced, since the use of
6263 -- the Value attribute can implicitly reference any of the
6264 -- literals of the enumeration base type.
6267 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6269 while Present
(Ent
) loop
6270 Set_Referenced
(Ent
);
6276 -- Set Etype before resolving expression because expansion of
6277 -- expression may require enclosing type. Note that the type
6278 -- returned by 'Value is the base type of the prefix type.
6280 Set_Etype
(N
, P_Base_Type
);
6281 Validate_Non_Static_Attribute_Function_Call
;
6288 when Attribute_Value_Size
=>
6291 Check_Not_Incomplete_Type
;
6292 Set_Etype
(N
, Universal_Integer
);
6298 when Attribute_Version
=>
6301 Set_Etype
(N
, RTE
(RE_Version_String
));
6307 when Attribute_Wchar_T_Size
=>
6308 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6314 when Attribute_Wide_Image
=> Wide_Image
:
6316 Check_SPARK_Restriction_On_Attribute
;
6318 Set_Etype
(N
, Standard_Wide_String
);
6320 Resolve
(E1
, P_Base_Type
);
6321 Validate_Non_Static_Attribute_Function_Call
;
6324 ---------------------
6325 -- Wide_Wide_Image --
6326 ---------------------
6328 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
6331 Set_Etype
(N
, Standard_Wide_Wide_String
);
6333 Resolve
(E1
, P_Base_Type
);
6334 Validate_Non_Static_Attribute_Function_Call
;
6335 end Wide_Wide_Image
;
6341 when Attribute_Wide_Value
=> Wide_Value
:
6343 Check_SPARK_Restriction_On_Attribute
;
6347 -- Set Etype before resolving expression because expansion
6348 -- of expression may require enclosing type.
6350 Set_Etype
(N
, P_Type
);
6351 Validate_Non_Static_Attribute_Function_Call
;
6354 ---------------------
6355 -- Wide_Wide_Value --
6356 ---------------------
6358 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6363 -- Set Etype before resolving expression because expansion
6364 -- of expression may require enclosing type.
6366 Set_Etype
(N
, P_Type
);
6367 Validate_Non_Static_Attribute_Function_Call
;
6368 end Wide_Wide_Value
;
6370 ---------------------
6371 -- Wide_Wide_Width --
6372 ---------------------
6374 when Attribute_Wide_Wide_Width
=>
6377 Set_Etype
(N
, Universal_Integer
);
6383 when Attribute_Wide_Width
=>
6384 Check_SPARK_Restriction_On_Attribute
;
6387 Set_Etype
(N
, Universal_Integer
);
6393 when Attribute_Width
=>
6394 Check_SPARK_Restriction_On_Attribute
;
6397 Set_Etype
(N
, Universal_Integer
);
6403 when Attribute_Word_Size
=>
6404 Standard_Attribute
(System_Word_Size
);
6410 when Attribute_Write
=>
6412 Check_Stream_Attribute
(TSS_Stream_Write
);
6413 Set_Etype
(N
, Standard_Void_Type
);
6414 Resolve
(N
, Standard_Void_Type
);
6418 -- All errors raise Bad_Attribute, so that we get out before any further
6419 -- damage occurs when an error is detected (for example, if we check for
6420 -- one attribute expression, and the check succeeds, we want to be able
6421 -- to proceed securely assuming that an expression is in fact present.
6423 -- Note: we set the attribute analyzed in this case to prevent any
6424 -- attempt at reanalysis which could generate spurious error msgs.
6427 when Bad_Attribute
=>
6429 Set_Etype
(N
, Any_Type
);
6431 end Analyze_Attribute
;
6433 --------------------
6434 -- Eval_Attribute --
6435 --------------------
6437 procedure Eval_Attribute
(N
: Node_Id
) is
6438 Loc
: constant Source_Ptr
:= Sloc
(N
);
6439 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6440 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6441 P
: constant Node_Id
:= Prefix
(N
);
6443 C_Type
: constant Entity_Id
:= Etype
(N
);
6444 -- The type imposed by the context
6447 -- First expression, or Empty if none
6450 -- Second expression, or Empty if none
6452 P_Entity
: Entity_Id
;
6453 -- Entity denoted by prefix
6456 -- The type of the prefix
6458 P_Base_Type
: Entity_Id
;
6459 -- The base type of the prefix type
6461 P_Root_Type
: Entity_Id
;
6462 -- The root type of the prefix type
6465 -- True if the result is Static. This is set by the general processing
6466 -- to true if the prefix is static, and all expressions are static. It
6467 -- can be reset as processing continues for particular attributes
6469 Lo_Bound
, Hi_Bound
: Node_Id
;
6470 -- Expressions for low and high bounds of type or array index referenced
6471 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6474 -- Constraint error node used if we have an attribute reference has
6475 -- an argument that raises a constraint error. In this case we replace
6476 -- the attribute with a raise constraint_error node. This is important
6477 -- processing, since otherwise gigi might see an attribute which it is
6478 -- unprepared to deal with.
6480 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
6481 -- If Bound is a reference to a discriminant of a task or protected type
6482 -- occurring within the object's body, rewrite attribute reference into
6483 -- a reference to the corresponding discriminal. Use for the expansion
6484 -- of checks against bounds of entry family index subtypes.
6486 procedure Check_Expressions
;
6487 -- In case where the attribute is not foldable, the expressions, if
6488 -- any, of the attribute, are in a non-static context. This procedure
6489 -- performs the required additional checks.
6491 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
6492 -- Determines if the given type has compile time known bounds. Note
6493 -- that we enter the case statement even in cases where the prefix
6494 -- type does NOT have known bounds, so it is important to guard any
6495 -- attempt to evaluate both bounds with a call to this function.
6497 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
6498 -- This procedure is called when the attribute N has a non-static
6499 -- but compile time known value given by Val. It includes the
6500 -- necessary checks for out of range values.
6502 function Fore_Value
return Nat
;
6503 -- Computes the Fore value for the current attribute prefix, which is
6504 -- known to be a static fixed-point type. Used by Fore and Width.
6506 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean;
6507 -- Determine whether Typ denotes a VAX floating point type
6509 function Mantissa
return Uint
;
6510 -- Returns the Mantissa value for the prefix type
6512 procedure Set_Bounds
;
6513 -- Used for First, Last and Length attributes applied to an array or
6514 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6515 -- and high bound expressions for the index referenced by the attribute
6516 -- designator (i.e. the first index if no expression is present, and the
6517 -- N'th index if the value N is present as an expression). Also used for
6518 -- First and Last of scalar types and for First_Valid and Last_Valid.
6519 -- Static is reset to False if the type or index type is not statically
6522 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
6523 -- Verify that the prefix of a potentially static array attribute
6524 -- satisfies the conditions of 4.9 (14).
6526 -----------------------------------
6527 -- Check_Concurrent_Discriminant --
6528 -----------------------------------
6530 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
6532 -- The concurrent (task or protected) type
6535 if Nkind
(Bound
) = N_Identifier
6536 and then Ekind
(Entity
(Bound
)) = E_Discriminant
6537 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
6539 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
6541 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
6543 -- Find discriminant of original concurrent type, and use
6544 -- its current discriminal, which is the renaming within
6545 -- the task/protected body.
6549 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
6552 end Check_Concurrent_Discriminant
;
6554 -----------------------
6555 -- Check_Expressions --
6556 -----------------------
6558 procedure Check_Expressions
is
6562 while Present
(E
) loop
6563 Check_Non_Static_Context
(E
);
6566 end Check_Expressions
;
6568 ----------------------------------
6569 -- Compile_Time_Known_Attribute --
6570 ----------------------------------
6572 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
6573 T
: constant Entity_Id
:= Etype
(N
);
6576 Fold_Uint
(N
, Val
, False);
6578 -- Check that result is in bounds of the type if it is static
6580 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
6583 elsif Is_Out_Of_Range
(N
, T
) then
6584 Apply_Compile_Time_Constraint_Error
6585 (N
, "value not in range of}??", CE_Range_Check_Failed
);
6587 elsif not Range_Checks_Suppressed
(T
) then
6588 Enable_Range_Check
(N
);
6591 Set_Do_Range_Check
(N
, False);
6593 end Compile_Time_Known_Attribute
;
6595 -------------------------------
6596 -- Compile_Time_Known_Bounds --
6597 -------------------------------
6599 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
6602 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
6604 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
6605 end Compile_Time_Known_Bounds
;
6611 -- Note that the Fore calculation is based on the actual values
6612 -- of the bounds, and does not take into account possible rounding.
6614 function Fore_Value
return Nat
is
6615 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
6616 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
6617 Small
: constant Ureal
:= Small_Value
(P_Type
);
6618 Lo_Real
: constant Ureal
:= Lo
* Small
;
6619 Hi_Real
: constant Ureal
:= Hi
* Small
;
6624 -- Bounds are given in terms of small units, so first compute
6625 -- proper values as reals.
6627 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
6630 -- Loop to compute proper value if more than one digit required
6632 while T
>= Ureal_10
loop
6644 function Is_VAX_Float
(Typ
: Entity_Id
) return Boolean is
6647 Is_Floating_Point_Type
(Typ
)
6649 (Float_Format
= 'V' or else Float_Rep
(Typ
) = VAX_Native
);
6656 -- Table of mantissa values accessed by function Computed using
6659 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6661 -- where D is T'Digits (RM83 3.5.7)
6663 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
6705 function Mantissa
return Uint
is
6708 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
6715 procedure Set_Bounds
is
6721 -- For a string literal subtype, we have to construct the bounds.
6722 -- Valid Ada code never applies attributes to string literals, but
6723 -- it is convenient to allow the expander to generate attribute
6724 -- references of this type (e.g. First and Last applied to a string
6727 -- Note that the whole point of the E_String_Literal_Subtype is to
6728 -- avoid this construction of bounds, but the cases in which we
6729 -- have to materialize them are rare enough that we don't worry.
6731 -- The low bound is simply the low bound of the base type. The
6732 -- high bound is computed from the length of the string and this
6735 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
6736 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
6737 Lo_Bound
:= Type_Low_Bound
(Ityp
);
6740 Make_Integer_Literal
(Sloc
(P
),
6742 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
6744 Set_Parent
(Hi_Bound
, P
);
6745 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
6748 -- For non-array case, just get bounds of scalar type
6750 elsif Is_Scalar_Type
(P_Type
) then
6753 -- For a fixed-point type, we must freeze to get the attributes
6754 -- of the fixed-point type set now so we can reference them.
6756 if Is_Fixed_Point_Type
(P_Type
)
6757 and then not Is_Frozen
(Base_Type
(P_Type
))
6758 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
6759 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
6761 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
6764 -- For array case, get type of proper index
6770 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
6773 Indx
:= First_Index
(P_Type
);
6774 for J
in 1 .. Ndim
- 1 loop
6778 -- If no index type, get out (some other error occurred, and
6779 -- we don't have enough information to complete the job).
6787 Ityp
:= Etype
(Indx
);
6790 -- A discrete range in an index constraint is allowed to be a
6791 -- subtype indication. This is syntactically a pain, but should
6792 -- not propagate to the entity for the corresponding index subtype.
6793 -- After checking that the subtype indication is legal, the range
6794 -- of the subtype indication should be transfered to the entity.
6795 -- The attributes for the bounds should remain the simple retrievals
6796 -- that they are now.
6798 Lo_Bound
:= Type_Low_Bound
(Ityp
);
6799 Hi_Bound
:= Type_High_Bound
(Ityp
);
6801 if not Is_Static_Subtype
(Ityp
) then
6806 -------------------------------
6807 -- Statically_Denotes_Entity --
6808 -------------------------------
6810 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
6814 if not Is_Entity_Name
(N
) then
6821 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
6822 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
6823 end Statically_Denotes_Entity
;
6825 -- Start of processing for Eval_Attribute
6828 -- Acquire first two expressions (at the moment, no attributes take more
6829 -- than two expressions in any case).
6831 if Present
(Expressions
(N
)) then
6832 E1
:= First
(Expressions
(N
));
6839 -- Special processing for Enabled attribute. This attribute has a very
6840 -- special prefix, and the easiest way to avoid lots of special checks
6841 -- to protect this special prefix from causing trouble is to deal with
6842 -- this attribute immediately and be done with it.
6844 if Id
= Attribute_Enabled
then
6846 -- We skip evaluation if the expander is not active. This is not just
6847 -- an optimization. It is of key importance that we not rewrite the
6848 -- attribute in a generic template, since we want to pick up the
6849 -- setting of the check in the instance, and testing expander active
6850 -- is as easy way of doing this as any.
6852 if Expander_Active
then
6854 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
6859 if C
in Predefined_Check_Id
then
6860 R
:= Scope_Suppress
.Suppress
(C
);
6862 R
:= Is_Check_Suppressed
(Empty
, C
);
6866 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
6869 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
6876 -- Special processing for cases where the prefix is an object. For
6877 -- this purpose, a string literal counts as an object (attributes
6878 -- of string literals can only appear in generated code).
6880 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
6882 -- For Component_Size, the prefix is an array object, and we apply
6883 -- the attribute to the type of the object. This is allowed for
6884 -- both unconstrained and constrained arrays, since the bounds
6885 -- have no influence on the value of this attribute.
6887 if Id
= Attribute_Component_Size
then
6888 P_Entity
:= Etype
(P
);
6890 -- For First and Last, the prefix is an array object, and we apply
6891 -- the attribute to the type of the array, but we need a constrained
6892 -- type for this, so we use the actual subtype if available.
6894 elsif Id
= Attribute_First
6898 Id
= Attribute_Length
6901 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
6904 if Present
(AS
) and then Is_Constrained
(AS
) then
6907 -- If we have an unconstrained type we cannot fold
6915 -- For Size, give size of object if available, otherwise we
6916 -- cannot fold Size.
6918 elsif Id
= Attribute_Size
then
6919 if Is_Entity_Name
(P
)
6920 and then Known_Esize
(Entity
(P
))
6922 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
6930 -- For Alignment, give size of object if available, otherwise we
6931 -- cannot fold Alignment.
6933 elsif Id
= Attribute_Alignment
then
6934 if Is_Entity_Name
(P
)
6935 and then Known_Alignment
(Entity
(P
))
6937 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
6945 -- For Lock_Free, we apply the attribute to the type of the object.
6946 -- This is allowed since we have already verified that the type is a
6949 elsif Id
= Attribute_Lock_Free
then
6950 P_Entity
:= Etype
(P
);
6952 -- No other attributes for objects are folded
6959 -- Cases where P is not an object. Cannot do anything if P is not the
6960 -- name of an entity.
6962 elsif not Is_Entity_Name
(P
) then
6966 -- Otherwise get prefix entity
6969 P_Entity
:= Entity
(P
);
6972 -- At this stage P_Entity is the entity to which the attribute
6973 -- is to be applied. This is usually simply the entity of the
6974 -- prefix, except in some cases of attributes for objects, where
6975 -- as described above, we apply the attribute to the object type.
6977 -- First foldable possibility is a scalar or array type (RM 4.9(7))
6978 -- that is not generic (generic types are eliminated by RM 4.9(25)).
6979 -- Note we allow non-static non-generic types at this stage as further
6982 if Is_Type
(P_Entity
)
6983 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
6984 and then (not Is_Generic_Type
(P_Entity
))
6988 -- Second foldable possibility is an array object (RM 4.9(8))
6990 elsif (Ekind
(P_Entity
) = E_Variable
6992 Ekind
(P_Entity
) = E_Constant
)
6993 and then Is_Array_Type
(Etype
(P_Entity
))
6994 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
6996 P_Type
:= Etype
(P_Entity
);
6998 -- If the entity is an array constant with an unconstrained nominal
6999 -- subtype then get the type from the initial value. If the value has
7000 -- been expanded into assignments, there is no expression and the
7001 -- attribute reference remains dynamic.
7003 -- We could do better here and retrieve the type ???
7005 if Ekind
(P_Entity
) = E_Constant
7006 and then not Is_Constrained
(P_Type
)
7008 if No
(Constant_Value
(P_Entity
)) then
7011 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7015 -- Definite must be folded if the prefix is not a generic type,
7016 -- that is to say if we are within an instantiation. Same processing
7017 -- applies to the GNAT attributes Atomic_Always_Lock_Free,
7018 -- Has_Discriminants, Lock_Free, Type_Class, Has_Tagged_Value, and
7019 -- Unconstrained_Array.
7021 elsif (Id
= Attribute_Atomic_Always_Lock_Free
7023 Id
= Attribute_Definite
7025 Id
= Attribute_Has_Access_Values
7027 Id
= Attribute_Has_Discriminants
7029 Id
= Attribute_Has_Tagged_Values
7031 Id
= Attribute_Lock_Free
7033 Id
= Attribute_Type_Class
7035 Id
= Attribute_Unconstrained_Array
7037 Id
= Attribute_Max_Alignment_For_Allocation
)
7038 and then not Is_Generic_Type
(P_Entity
)
7042 -- We can fold 'Size applied to a type if the size is known (as happens
7043 -- for a size from an attribute definition clause). At this stage, this
7044 -- can happen only for types (e.g. record types) for which the size is
7045 -- always non-static. We exclude generic types from consideration (since
7046 -- they have bogus sizes set within templates).
7048 elsif Id
= Attribute_Size
7049 and then Is_Type
(P_Entity
)
7050 and then (not Is_Generic_Type
(P_Entity
))
7051 and then Known_Static_RM_Size
(P_Entity
)
7053 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7056 -- We can fold 'Alignment applied to a type if the alignment is known
7057 -- (as happens for an alignment from an attribute definition clause).
7058 -- At this stage, this can happen only for types (e.g. record types) for
7059 -- which the size is always non-static. We exclude generic types from
7060 -- consideration (since they have bogus sizes set within templates).
7062 elsif Id
= Attribute_Alignment
7063 and then Is_Type
(P_Entity
)
7064 and then (not Is_Generic_Type
(P_Entity
))
7065 and then Known_Alignment
(P_Entity
)
7067 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7070 -- If this is an access attribute that is known to fail accessibility
7071 -- check, rewrite accordingly.
7073 elsif Attribute_Name
(N
) = Name_Access
7074 and then Raises_Constraint_Error
(N
)
7077 Make_Raise_Program_Error
(Loc
,
7078 Reason
=> PE_Accessibility_Check_Failed
));
7079 Set_Etype
(N
, C_Type
);
7082 -- No other cases are foldable (they certainly aren't static, and at
7083 -- the moment we don't try to fold any cases other than the ones above).
7090 -- If either attribute or the prefix is Any_Type, then propagate
7091 -- Any_Type to the result and don't do anything else at all.
7093 if P_Type
= Any_Type
7094 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7095 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7097 Set_Etype
(N
, Any_Type
);
7101 -- Scalar subtype case. We have not yet enforced the static requirement
7102 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7103 -- of non-static attribute references (e.g. S'Digits for a non-static
7104 -- floating-point type, which we can compute at compile time).
7106 -- Note: this folding of non-static attributes is not simply a case of
7107 -- optimization. For many of the attributes affected, Gigi cannot handle
7108 -- the attribute and depends on the front end having folded them away.
7110 -- Note: although we don't require staticness at this stage, we do set
7111 -- the Static variable to record the staticness, for easy reference by
7112 -- those attributes where it matters (e.g. Succ and Pred), and also to
7113 -- be used to ensure that non-static folded things are not marked as
7114 -- being static (a check that is done right at the end).
7116 P_Root_Type
:= Root_Type
(P_Type
);
7117 P_Base_Type
:= Base_Type
(P_Type
);
7119 -- If the root type or base type is generic, then we cannot fold. This
7120 -- test is needed because subtypes of generic types are not always
7121 -- marked as being generic themselves (which seems odd???)
7123 if Is_Generic_Type
(P_Root_Type
)
7124 or else Is_Generic_Type
(P_Base_Type
)
7129 if Is_Scalar_Type
(P_Type
) then
7130 Static
:= Is_OK_Static_Subtype
(P_Type
);
7132 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7133 -- since we can't do anything with unconstrained arrays. In addition,
7134 -- only the First, Last and Length attributes are possibly static.
7136 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7137 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7138 -- Unconstrained_Array are again exceptions, because they apply as well
7139 -- to unconstrained types.
7141 -- In addition Component_Size is an exception since it is possibly
7142 -- foldable, even though it is never static, and it does apply to
7143 -- unconstrained arrays. Furthermore, it is essential to fold this
7144 -- in the packed case, since otherwise the value will be incorrect.
7146 elsif Id
= Attribute_Atomic_Always_Lock_Free
7148 Id
= Attribute_Definite
7150 Id
= Attribute_Has_Access_Values
7152 Id
= Attribute_Has_Discriminants
7154 Id
= Attribute_Has_Tagged_Values
7156 Id
= Attribute_Lock_Free
7158 Id
= Attribute_Type_Class
7160 Id
= Attribute_Unconstrained_Array
7162 Id
= Attribute_Component_Size
7166 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7167 if not Is_Constrained
(P_Type
)
7168 or else (Id
/= Attribute_First
and then
7169 Id
/= Attribute_Last
and then
7170 Id
/= Attribute_Length
)
7176 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7177 -- scalar case, we hold off on enforcing staticness, since there are
7178 -- cases which we can fold at compile time even though they are not
7179 -- static (e.g. 'Length applied to a static index, even though other
7180 -- non-static indexes make the array type non-static). This is only
7181 -- an optimization, but it falls out essentially free, so why not.
7182 -- Again we compute the variable Static for easy reference later
7183 -- (note that no array attributes are static in Ada 83).
7185 -- We also need to set Static properly for subsequent legality checks
7186 -- which might otherwise accept non-static constants in contexts
7187 -- where they are not legal.
7189 Static
:= Ada_Version
>= Ada_95
7190 and then Statically_Denotes_Entity
(P
);
7196 N
:= First_Index
(P_Type
);
7198 -- The expression is static if the array type is constrained
7199 -- by given bounds, and not by an initial expression. Constant
7200 -- strings are static in any case.
7202 if Root_Type
(P_Type
) /= Standard_String
then
7204 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
7207 while Present
(N
) loop
7208 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
7210 -- If however the index type is generic, or derived from
7211 -- one, attributes cannot be folded.
7213 if Is_Generic_Type
(Root_Type
(Etype
(N
)))
7214 and then Id
/= Attribute_Component_Size
7224 -- Check any expressions that are present. Note that these expressions,
7225 -- depending on the particular attribute type, are either part of the
7226 -- attribute designator, or they are arguments in a case where the
7227 -- attribute reference returns a function. In the latter case, the
7228 -- rule in (RM 4.9(22)) applies and in particular requires the type
7229 -- of the expressions to be scalar in order for the attribute to be
7230 -- considered to be static.
7237 while Present
(E
) loop
7239 -- If expression is not static, then the attribute reference
7240 -- result certainly cannot be static.
7242 if not Is_Static_Expression
(E
) then
7246 -- If the result is not known at compile time, or is not of
7247 -- a scalar type, then the result is definitely not static,
7248 -- so we can quit now.
7250 if not Compile_Time_Known_Value
(E
)
7251 or else not Is_Scalar_Type
(Etype
(E
))
7253 -- An odd special case, if this is a Pos attribute, this
7254 -- is where we need to apply a range check since it does
7255 -- not get done anywhere else.
7257 if Id
= Attribute_Pos
then
7258 if Is_Integer_Type
(Etype
(E
)) then
7259 Apply_Range_Check
(E
, Etype
(N
));
7266 -- If the expression raises a constraint error, then so does
7267 -- the attribute reference. We keep going in this case because
7268 -- we are still interested in whether the attribute reference
7269 -- is static even if it is not static.
7271 elsif Raises_Constraint_Error
(E
) then
7272 Set_Raises_Constraint_Error
(N
);
7278 if Raises_Constraint_Error
(Prefix
(N
)) then
7283 -- Deal with the case of a static attribute reference that raises
7284 -- constraint error. The Raises_Constraint_Error flag will already
7285 -- have been set, and the Static flag shows whether the attribute
7286 -- reference is static. In any case we certainly can't fold such an
7287 -- attribute reference.
7289 -- Note that the rewriting of the attribute node with the constraint
7290 -- error node is essential in this case, because otherwise Gigi might
7291 -- blow up on one of the attributes it never expects to see.
7293 -- The constraint_error node must have the type imposed by the context,
7294 -- to avoid spurious errors in the enclosing expression.
7296 if Raises_Constraint_Error
(N
) then
7298 Make_Raise_Constraint_Error
(Sloc
(N
),
7299 Reason
=> CE_Range_Check_Failed
);
7300 Set_Etype
(CE_Node
, Etype
(N
));
7301 Set_Raises_Constraint_Error
(CE_Node
);
7303 Rewrite
(N
, Relocate_Node
(CE_Node
));
7304 Set_Is_Static_Expression
(N
, Static
);
7308 -- At this point we have a potentially foldable attribute reference.
7309 -- If Static is set, then the attribute reference definitely obeys
7310 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
7311 -- folded. If Static is not set, then the attribute may or may not
7312 -- be foldable, and the individual attribute processing routines
7313 -- test Static as required in cases where it makes a difference.
7315 -- In the case where Static is not set, we do know that all the
7316 -- expressions present are at least known at compile time (we assumed
7317 -- above that if this was not the case, then there was no hope of static
7318 -- evaluation). However, we did not require that the bounds of the
7319 -- prefix type be compile time known, let alone static). That's because
7320 -- there are many attributes that can be computed at compile time on
7321 -- non-static subtypes, even though such references are not static
7324 -- For VAX float, the root type is an IEEE type. So make sure to use the
7325 -- base type instead of the root-type for floating point attributes.
7329 -- Attributes related to Ada 2012 iterators (placeholder ???)
7331 when Attribute_Constant_Indexing |
7332 Attribute_Default_Iterator |
7333 Attribute_Implicit_Dereference |
7334 Attribute_Iterator_Element |
7335 Attribute_Variable_Indexing
=> null;
7337 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7338 -- These were already rejected by the parser. Thus they shouldn't
7341 when Internal_Attribute_Id
=>
7342 raise Program_Error
;
7348 when Attribute_Adjacent
=>
7352 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7359 when Attribute_Aft
=>
7360 Fold_Uint
(N
, Aft_Value
(P_Type
), True);
7366 when Attribute_Alignment
=> Alignment_Block
: declare
7367 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7370 -- Fold if alignment is set and not otherwise
7372 if Known_Alignment
(P_TypeA
) then
7373 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
7375 end Alignment_Block
;
7381 -- Can only be folded in No_Ast_Handler case
7383 when Attribute_AST_Entry
=>
7384 if not Is_AST_Entry
(P_Entity
) then
7386 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
7391 -----------------------------
7392 -- Atomic_Always_Lock_Free --
7393 -----------------------------
7395 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7398 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
7400 V
: constant Entity_Id
:=
7402 (Support_Atomic_Primitives_On_Target
7403 and then Support_Atomic_Primitives
(P_Type
));
7406 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7408 -- Analyze and resolve as boolean. Note that this attribute is a
7409 -- static attribute in GNAT.
7411 Analyze_And_Resolve
(N
, Standard_Boolean
);
7413 end Atomic_Always_Lock_Free
;
7419 -- Bit can never be folded
7421 when Attribute_Bit
=>
7428 -- Body_version can never be static
7430 when Attribute_Body_Version
=>
7437 when Attribute_Ceiling
=>
7439 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7441 --------------------
7442 -- Component_Size --
7443 --------------------
7445 when Attribute_Component_Size
=>
7446 if Known_Static_Component_Size
(P_Type
) then
7447 Fold_Uint
(N
, Component_Size
(P_Type
), False);
7454 when Attribute_Compose
=>
7457 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7464 -- Constrained is never folded for now, there may be cases that
7465 -- could be handled at compile time. To be looked at later.
7467 when Attribute_Constrained
=>
7474 when Attribute_Copy_Sign
=>
7478 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
7485 when Attribute_Definite
=>
7486 Rewrite
(N
, New_Occurrence_Of
(
7487 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
7488 Analyze_And_Resolve
(N
, Standard_Boolean
);
7494 when Attribute_Delta
=>
7495 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
7501 when Attribute_Denorm
=>
7503 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), True);
7505 ---------------------
7506 -- Descriptor_Size --
7507 ---------------------
7509 when Attribute_Descriptor_Size
=>
7516 when Attribute_Digits
=>
7517 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
7523 when Attribute_Emax
=>
7525 -- Ada 83 attribute is defined as (RM83 3.5.8)
7527 -- T'Emax = 4 * T'Mantissa
7529 Fold_Uint
(N
, 4 * Mantissa
, True);
7535 when Attribute_Enum_Rep
=>
7537 -- For an enumeration type with a non-standard representation use
7538 -- the Enumeration_Rep field of the proper constant. Note that this
7539 -- will not work for types Character/Wide_[Wide-]Character, since no
7540 -- real entities are created for the enumeration literals, but that
7541 -- does not matter since these two types do not have non-standard
7542 -- representations anyway.
7544 if Is_Enumeration_Type
(P_Type
)
7545 and then Has_Non_Standard_Rep
(P_Type
)
7547 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
7549 -- For enumeration types with standard representations and all
7550 -- other cases (i.e. all integer and modular types), Enum_Rep
7551 -- is equivalent to Pos.
7554 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
7561 when Attribute_Enum_Val
=> Enum_Val
: declare
7565 -- We have something like Enum_Type'Enum_Val (23), so search for a
7566 -- corresponding value in the list of Enum_Rep values for the type.
7568 Lit
:= First_Literal
(P_Base_Type
);
7570 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
7571 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
7578 Apply_Compile_Time_Constraint_Error
7579 (N
, "no representation value matches",
7580 CE_Range_Check_Failed
,
7581 Warn
=> not Static
);
7591 when Attribute_Epsilon
=>
7593 -- Ada 83 attribute is defined as (RM83 3.5.8)
7595 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7597 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
7603 when Attribute_Exponent
=>
7605 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7611 when Attribute_First
=> First_Attr
:
7615 if Compile_Time_Known_Value
(Lo_Bound
) then
7616 if Is_Real_Type
(P_Type
) then
7617 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
7619 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7622 -- Replace VAX Float_Type'First with a reference to the temporary
7623 -- which represents the low bound of the type. This transformation
7624 -- is needed since the back end cannot evaluate 'First on VAX.
7626 elsif Is_VAX_Float
(P_Type
)
7627 and then Nkind
(Lo_Bound
) = N_Identifier
7629 Rewrite
(N
, New_Reference_To
(Entity
(Lo_Bound
), Sloc
(N
)));
7633 Check_Concurrent_Discriminant
(Lo_Bound
);
7641 when Attribute_First_Valid
=> First_Valid
:
7643 if Has_Predicates
(P_Type
)
7644 and then Present
(Static_Predicate
(P_Type
))
7647 FirstN
: constant Node_Id
:= First
(Static_Predicate
(P_Type
));
7649 if Nkind
(FirstN
) = N_Range
then
7650 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
7652 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
7658 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
7666 when Attribute_Fixed_Value
=>
7673 when Attribute_Floor
=>
7675 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7681 when Attribute_Fore
=>
7682 if Compile_Time_Known_Bounds
(P_Type
) then
7683 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
7690 when Attribute_Fraction
=>
7692 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
7694 -----------------------
7695 -- Has_Access_Values --
7696 -----------------------
7698 when Attribute_Has_Access_Values
=>
7699 Rewrite
(N
, New_Occurrence_Of
7700 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
7701 Analyze_And_Resolve
(N
, Standard_Boolean
);
7703 -----------------------
7704 -- Has_Discriminants --
7705 -----------------------
7707 when Attribute_Has_Discriminants
=>
7708 Rewrite
(N
, New_Occurrence_Of
(
7709 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
7710 Analyze_And_Resolve
(N
, Standard_Boolean
);
7712 -----------------------
7713 -- Has_Tagged_Values --
7714 -----------------------
7716 when Attribute_Has_Tagged_Values
=>
7717 Rewrite
(N
, New_Occurrence_Of
7718 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
7719 Analyze_And_Resolve
(N
, Standard_Boolean
);
7725 when Attribute_Identity
=>
7732 -- Image is a scalar attribute, but is never static, because it is
7733 -- not a static function (having a non-scalar argument (RM 4.9(22))
7734 -- However, we can constant-fold the image of an enumeration literal
7735 -- if names are available.
7737 when Attribute_Image
=>
7738 if Is_Entity_Name
(E1
)
7739 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
7740 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
7741 and then not Global_Discard_Names
7744 Lit
: constant Entity_Id
:= Entity
(E1
);
7748 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
7749 Set_Casing
(All_Upper_Case
);
7750 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
7752 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
7753 Analyze_And_Resolve
(N
, Standard_String
);
7754 Set_Is_Static_Expression
(N
, False);
7762 -- Img is a scalar attribute, but is never static, because it is
7763 -- not a static function (having a non-scalar argument (RM 4.9(22))
7765 when Attribute_Img
=>
7772 -- We never try to fold Integer_Value (though perhaps we could???)
7774 when Attribute_Integer_Value
=>
7781 -- Invalid_Value is a scalar attribute that is never static, because
7782 -- the value is by design out of range.
7784 when Attribute_Invalid_Value
=>
7791 when Attribute_Large
=>
7793 -- For fixed-point, we use the identity:
7795 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
7797 if Is_Fixed_Point_Type
(P_Type
) then
7799 Make_Op_Multiply
(Loc
,
7801 Make_Op_Subtract
(Loc
,
7805 Make_Real_Literal
(Loc
, Ureal_2
),
7807 Make_Attribute_Reference
(Loc
,
7809 Attribute_Name
=> Name_Mantissa
)),
7810 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
7813 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
7815 Analyze_And_Resolve
(N
, C_Type
);
7817 -- Floating-point (Ada 83 compatibility)
7820 -- Ada 83 attribute is defined as (RM83 3.5.8)
7822 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
7826 -- T'Emax = 4 * T'Mantissa
7830 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
7838 when Attribute_Lock_Free
=> Lock_Free
: declare
7839 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
7842 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
7844 -- Analyze and resolve as boolean. Note that this attribute is a
7845 -- static attribute in GNAT.
7847 Analyze_And_Resolve
(N
, Standard_Boolean
);
7855 when Attribute_Last
=> Last_Attr
:
7859 if Compile_Time_Known_Value
(Hi_Bound
) then
7860 if Is_Real_Type
(P_Type
) then
7861 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
7863 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
7866 -- Replace VAX Float_Type'Last with a reference to the temporary
7867 -- which represents the high bound of the type. This transformation
7868 -- is needed since the back end cannot evaluate 'Last on VAX.
7870 elsif Is_VAX_Float
(P_Type
)
7871 and then Nkind
(Hi_Bound
) = N_Identifier
7873 Rewrite
(N
, New_Reference_To
(Entity
(Hi_Bound
), Sloc
(N
)));
7877 Check_Concurrent_Discriminant
(Hi_Bound
);
7885 when Attribute_Last_Valid
=> Last_Valid
:
7887 if Has_Predicates
(P_Type
)
7888 and then Present
(Static_Predicate
(P_Type
))
7891 LastN
: constant Node_Id
:= Last
(Static_Predicate
(P_Type
));
7893 if Nkind
(LastN
) = N_Range
then
7894 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
7896 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
7902 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
7910 when Attribute_Leading_Part
=>
7913 Eval_Fat
.Leading_Part
7914 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
7921 when Attribute_Length
=> Length
: declare
7925 -- If any index type is a formal type, or derived from one, the
7926 -- bounds are not static. Treating them as static can produce
7927 -- spurious warnings or improper constant folding.
7929 Ind
:= First_Index
(P_Type
);
7930 while Present
(Ind
) loop
7931 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
7940 -- For two compile time values, we can compute length
7942 if Compile_Time_Known_Value
(Lo_Bound
)
7943 and then Compile_Time_Known_Value
(Hi_Bound
)
7946 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
7950 -- One more case is where Hi_Bound and Lo_Bound are compile-time
7951 -- comparable, and we can figure out the difference between them.
7954 Diff
: aliased Uint
;
7958 Compile_Time_Compare
7959 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
7962 Fold_Uint
(N
, Uint_1
, False);
7965 Fold_Uint
(N
, Uint_0
, False);
7968 if Diff
/= No_Uint
then
7969 Fold_Uint
(N
, Diff
+ 1, False);
7982 -- Loop_Entry acts as an alias of a constant initialized to the prefix
7983 -- of the said attribute at the point of entry into the related loop. As
7984 -- such, the attribute reference does not need to be evaluated because
7985 -- the prefix is the one that is evaluted.
7987 when Attribute_Loop_Entry
=>
7994 when Attribute_Machine
=>
7998 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8005 when Attribute_Machine_Emax
=>
8006 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8012 when Attribute_Machine_Emin
=>
8013 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8015 ----------------------
8016 -- Machine_Mantissa --
8017 ----------------------
8019 when Attribute_Machine_Mantissa
=>
8020 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8022 -----------------------
8023 -- Machine_Overflows --
8024 -----------------------
8026 when Attribute_Machine_Overflows
=>
8028 -- Always true for fixed-point
8030 if Is_Fixed_Point_Type
(P_Type
) then
8031 Fold_Uint
(N
, True_Value
, True);
8033 -- Floating point case
8037 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8045 when Attribute_Machine_Radix
=>
8046 if Is_Fixed_Point_Type
(P_Type
) then
8047 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8048 and then Machine_Radix_10
(P_Type
)
8050 Fold_Uint
(N
, Uint_10
, True);
8052 Fold_Uint
(N
, Uint_2
, True);
8055 -- All floating-point type always have radix 2
8058 Fold_Uint
(N
, Uint_2
, True);
8061 ----------------------
8062 -- Machine_Rounding --
8063 ----------------------
8065 -- Note: for the folding case, it is fine to treat Machine_Rounding
8066 -- exactly the same way as Rounding, since this is one of the allowed
8067 -- behaviors, and performance is not an issue here. It might be a bit
8068 -- better to give the same result as it would give at run time, even
8069 -- though the non-determinism is certainly permitted.
8071 when Attribute_Machine_Rounding
=>
8073 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8075 --------------------
8076 -- Machine_Rounds --
8077 --------------------
8079 when Attribute_Machine_Rounds
=>
8081 -- Always False for fixed-point
8083 if Is_Fixed_Point_Type
(P_Type
) then
8084 Fold_Uint
(N
, False_Value
, True);
8086 -- Else yield proper floating-point result
8090 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
8097 -- Note: Machine_Size is identical to Object_Size
8099 when Attribute_Machine_Size
=> Machine_Size
: declare
8100 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8103 if Known_Esize
(P_TypeA
) then
8104 Fold_Uint
(N
, Esize
(P_TypeA
), True);
8112 when Attribute_Mantissa
=>
8114 -- Fixed-point mantissa
8116 if Is_Fixed_Point_Type
(P_Type
) then
8118 -- Compile time foldable case
8120 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8122 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8124 -- The calculation of the obsolete Ada 83 attribute Mantissa
8125 -- is annoying, because of AI00143, quoted here:
8127 -- !question 84-01-10
8129 -- Consider the model numbers for F:
8131 -- type F is delta 1.0 range -7.0 .. 8.0;
8133 -- The wording requires that F'MANTISSA be the SMALLEST
8134 -- integer number for which each bound of the specified
8135 -- range is either a model number or lies at most small
8136 -- distant from a model number. This means F'MANTISSA
8137 -- is required to be 3 since the range -7.0 .. 7.0 fits
8138 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8139 -- number, namely, 7. Is this analysis correct? Note that
8140 -- this implies the upper bound of the range is not
8141 -- represented as a model number.
8143 -- !response 84-03-17
8145 -- The analysis is correct. The upper and lower bounds for
8146 -- a fixed point type can lie outside the range of model
8157 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8158 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8159 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8160 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8162 -- If the Bound is exactly a model number, i.e. a multiple
8163 -- of Small, then we back it off by one to get the integer
8164 -- value that must be representable.
8166 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8167 Max_Man
:= Max_Man
- 1;
8170 -- Now find corresponding size = Mantissa value
8173 while 2 ** Siz
< Max_Man
loop
8177 Fold_Uint
(N
, Siz
, True);
8181 -- The case of dynamic bounds cannot be evaluated at compile
8182 -- time. Instead we use a runtime routine (see Exp_Attr).
8187 -- Floating-point Mantissa
8190 Fold_Uint
(N
, Mantissa
, True);
8197 when Attribute_Max
=> Max
:
8199 if Is_Real_Type
(P_Type
) then
8201 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8203 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8207 ----------------------------------
8208 -- Max_Alignment_For_Allocation --
8209 ----------------------------------
8211 -- Max_Alignment_For_Allocation is usually the Alignment. However,
8212 -- arrays are allocated with dope, so we need to take into account both
8213 -- the alignment of the array, which comes from the component alignment,
8214 -- and the alignment of the dope. Also, if the alignment is unknown, we
8215 -- use the max (it's OK to be pessimistic).
8217 when Attribute_Max_Alignment_For_Allocation
=>
8219 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
8221 if Known_Alignment
(P_Type
) and then
8222 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
8224 A
:= Alignment
(P_Type
);
8227 Fold_Uint
(N
, A
, Static
);
8230 ----------------------------------
8231 -- Max_Size_In_Storage_Elements --
8232 ----------------------------------
8234 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
8235 -- Storage_Unit boundary. We can fold any cases for which the size
8236 -- is known by the front end.
8238 when Attribute_Max_Size_In_Storage_Elements
=>
8239 if Known_Esize
(P_Type
) then
8241 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
8242 System_Storage_Unit
,
8246 --------------------
8247 -- Mechanism_Code --
8248 --------------------
8250 when Attribute_Mechanism_Code
=>
8254 Mech
: Mechanism_Type
;
8258 Mech
:= Mechanism
(P_Entity
);
8261 Val
:= UI_To_Int
(Expr_Value
(E1
));
8263 Formal
:= First_Formal
(P_Entity
);
8264 for J
in 1 .. Val
- 1 loop
8265 Next_Formal
(Formal
);
8267 Mech
:= Mechanism
(Formal
);
8271 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
8279 when Attribute_Min
=> Min
:
8281 if Is_Real_Type
(P_Type
) then
8283 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8286 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8294 when Attribute_Mod
=>
8296 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
8302 when Attribute_Model
=>
8304 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8310 when Attribute_Model_Emin
=>
8311 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
8317 when Attribute_Model_Epsilon
=>
8318 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
8320 --------------------
8321 -- Model_Mantissa --
8322 --------------------
8324 when Attribute_Model_Mantissa
=>
8325 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
8331 when Attribute_Model_Small
=>
8332 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
8338 when Attribute_Modulus
=>
8339 Fold_Uint
(N
, Modulus
(P_Type
), True);
8341 --------------------
8342 -- Null_Parameter --
8343 --------------------
8345 -- Cannot fold, we know the value sort of, but the whole point is
8346 -- that there is no way to talk about this imaginary value except
8347 -- by using the attribute, so we leave it the way it is.
8349 when Attribute_Null_Parameter
=>
8356 -- The Object_Size attribute for a type returns the Esize of the
8357 -- type and can be folded if this value is known.
8359 when Attribute_Object_Size
=> Object_Size
: declare
8360 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8363 if Known_Esize
(P_TypeA
) then
8364 Fold_Uint
(N
, Esize
(P_TypeA
), True);
8368 ----------------------
8369 -- Overlaps_Storage --
8370 ----------------------
8372 when Attribute_Overlaps_Storage
=>
8375 -------------------------
8376 -- Passed_By_Reference --
8377 -------------------------
8379 -- Scalar types are never passed by reference
8381 when Attribute_Passed_By_Reference
=>
8382 Fold_Uint
(N
, False_Value
, True);
8388 when Attribute_Pos
=>
8389 Fold_Uint
(N
, Expr_Value
(E1
), True);
8395 when Attribute_Pred
=> Pred
:
8397 -- Floating-point case
8399 if Is_Floating_Point_Type
(P_Type
) then
8401 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8405 elsif Is_Fixed_Point_Type
(P_Type
) then
8407 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
8409 -- Modular integer case (wraps)
8411 elsif Is_Modular_Integer_Type
(P_Type
) then
8412 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
8414 -- Other scalar cases
8417 pragma Assert
(Is_Scalar_Type
(P_Type
));
8419 if Is_Enumeration_Type
(P_Type
)
8420 and then Expr_Value
(E1
) =
8421 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8423 Apply_Compile_Time_Constraint_Error
8424 (N
, "Pred of `&''First`",
8425 CE_Overflow_Check_Failed
,
8427 Warn
=> not Static
);
8433 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
8441 -- No processing required, because by this stage, Range has been
8442 -- replaced by First .. Last, so this branch can never be taken.
8444 when Attribute_Range
=>
8445 raise Program_Error
;
8451 when Attribute_Range_Length
=>
8454 -- Can fold if both bounds are compile time known
8456 if Compile_Time_Known_Value
(Hi_Bound
)
8457 and then Compile_Time_Known_Value
(Lo_Bound
)
8461 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
8465 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8466 -- comparable, and we can figure out the difference between them.
8469 Diff
: aliased Uint
;
8473 Compile_Time_Compare
8474 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8477 Fold_Uint
(N
, Uint_1
, False);
8480 Fold_Uint
(N
, Uint_0
, False);
8483 if Diff
/= No_Uint
then
8484 Fold_Uint
(N
, Diff
+ 1, False);
8496 when Attribute_Ref
=>
8497 Fold_Uint
(N
, Expr_Value
(E1
), True);
8503 when Attribute_Remainder
=> Remainder
: declare
8504 X
: constant Ureal
:= Expr_Value_R
(E1
);
8505 Y
: constant Ureal
:= Expr_Value_R
(E2
);
8508 if UR_Is_Zero
(Y
) then
8509 Apply_Compile_Time_Constraint_Error
8510 (N
, "division by zero in Remainder",
8511 CE_Overflow_Check_Failed
,
8512 Warn
=> not Static
);
8518 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
8525 when Attribute_Restriction_Set
=> Restriction_Set
: declare
8527 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
8528 Set_Is_Static_Expression
(N
);
8529 end Restriction_Set
;
8535 when Attribute_Round
=> Round
:
8541 -- First we get the (exact result) in units of small
8543 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
8545 -- Now round that exactly to an integer
8547 Si
:= UR_To_Uint
(Sr
);
8549 -- Finally the result is obtained by converting back to real
8551 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
8558 when Attribute_Rounding
=>
8560 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8566 when Attribute_Safe_Emax
=>
8567 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
8573 when Attribute_Safe_First
=>
8574 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
8580 when Attribute_Safe_Large
=>
8581 if Is_Fixed_Point_Type
(P_Type
) then
8583 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
8585 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8592 when Attribute_Safe_Last
=>
8593 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
8599 when Attribute_Safe_Small
=>
8601 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8602 -- for fixed-point, since is the same as Small, but we implement
8603 -- it for backwards compatibility.
8605 if Is_Fixed_Point_Type
(P_Type
) then
8606 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
8608 -- Ada 83 Safe_Small for floating-point cases
8611 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
8618 when Attribute_Same_Storage
=>
8625 when Attribute_Scale
=>
8626 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
8632 when Attribute_Scaling
=>
8636 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8643 when Attribute_Signed_Zeros
=>
8645 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
8651 -- Size attribute returns the RM size. All scalar types can be folded,
8652 -- as well as any types for which the size is known by the front end,
8653 -- including any type for which a size attribute is specified.
8655 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
8656 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8659 if RM_Size
(P_TypeA
) /= Uint_0
then
8663 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
8665 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
8668 -- If a size clause applies, then use the size from it.
8669 -- This is one of the rare cases where we can use the
8670 -- Size_Clause field for a subtype when Has_Size_Clause
8671 -- is False. Consider:
8673 -- type x is range 1 .. 64;
8674 -- for x'size use 12;
8675 -- subtype y is x range 0 .. 3;
8677 -- Here y has a size clause inherited from x, but normally
8678 -- it does not apply, and y'size is 2. However, y'VADS_Size
8679 -- is indeed 12 and not 2.
8682 and then Is_OK_Static_Expression
(Expression
(S
))
8684 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
8686 -- If no size is specified, then we simply use the object
8687 -- size in the VADS_Size case (e.g. Natural'Size is equal
8688 -- to Integer'Size, not one less).
8691 Fold_Uint
(N
, Esize
(P_TypeA
), True);
8695 -- Normal case (Size) in which case we want the RM_Size
8700 Static
and then Is_Discrete_Type
(P_TypeA
));
8709 when Attribute_Small
=>
8711 -- The floating-point case is present only for Ada 83 compatibility.
8712 -- Note that strictly this is an illegal addition, since we are
8713 -- extending an Ada 95 defined attribute, but we anticipate an
8714 -- ARG ruling that will permit this.
8716 if Is_Floating_Point_Type
(P_Type
) then
8718 -- Ada 83 attribute is defined as (RM83 3.5.8)
8720 -- T'Small = 2.0**(-T'Emax - 1)
8724 -- T'Emax = 4 * T'Mantissa
8726 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
8728 -- Normal Ada 95 fixed-point case
8731 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
8738 when Attribute_Stream_Size
=>
8745 when Attribute_Succ
=> Succ
:
8747 -- Floating-point case
8749 if Is_Floating_Point_Type
(P_Type
) then
8751 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8755 elsif Is_Fixed_Point_Type
(P_Type
) then
8756 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
8758 -- Modular integer case (wraps)
8760 elsif Is_Modular_Integer_Type
(P_Type
) then
8761 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
8763 -- Other scalar cases
8766 pragma Assert
(Is_Scalar_Type
(P_Type
));
8768 if Is_Enumeration_Type
(P_Type
)
8769 and then Expr_Value
(E1
) =
8770 Expr_Value
(Type_High_Bound
(P_Base_Type
))
8772 Apply_Compile_Time_Constraint_Error
8773 (N
, "Succ of `&''Last`",
8774 CE_Overflow_Check_Failed
,
8776 Warn
=> not Static
);
8781 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
8790 when Attribute_Truncation
=>
8793 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
8800 when Attribute_Type_Class
=> Type_Class
: declare
8801 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
8805 if Is_Descendent_Of_Address
(Typ
) then
8806 Id
:= RE_Type_Class_Address
;
8808 elsif Is_Enumeration_Type
(Typ
) then
8809 Id
:= RE_Type_Class_Enumeration
;
8811 elsif Is_Integer_Type
(Typ
) then
8812 Id
:= RE_Type_Class_Integer
;
8814 elsif Is_Fixed_Point_Type
(Typ
) then
8815 Id
:= RE_Type_Class_Fixed_Point
;
8817 elsif Is_Floating_Point_Type
(Typ
) then
8818 Id
:= RE_Type_Class_Floating_Point
;
8820 elsif Is_Array_Type
(Typ
) then
8821 Id
:= RE_Type_Class_Array
;
8823 elsif Is_Record_Type
(Typ
) then
8824 Id
:= RE_Type_Class_Record
;
8826 elsif Is_Access_Type
(Typ
) then
8827 Id
:= RE_Type_Class_Access
;
8829 elsif Is_Enumeration_Type
(Typ
) then
8830 Id
:= RE_Type_Class_Enumeration
;
8832 elsif Is_Task_Type
(Typ
) then
8833 Id
:= RE_Type_Class_Task
;
8835 -- We treat protected types like task types. It would make more
8836 -- sense to have another enumeration value, but after all the
8837 -- whole point of this feature is to be exactly DEC compatible,
8838 -- and changing the type Type_Class would not meet this requirement.
8840 elsif Is_Protected_Type
(Typ
) then
8841 Id
:= RE_Type_Class_Task
;
8843 -- Not clear if there are any other possibilities, but if there
8844 -- are, then we will treat them as the address case.
8847 Id
:= RE_Type_Class_Address
;
8850 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
8853 -----------------------
8854 -- Unbiased_Rounding --
8855 -----------------------
8857 when Attribute_Unbiased_Rounding
=>
8860 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
8863 -------------------------
8864 -- Unconstrained_Array --
8865 -------------------------
8867 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
8868 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8871 Rewrite
(N
, New_Occurrence_Of
(
8873 Is_Array_Type
(P_Type
)
8874 and then not Is_Constrained
(Typ
)), Loc
));
8876 -- Analyze and resolve as boolean, note that this attribute is
8877 -- a static attribute in GNAT.
8879 Analyze_And_Resolve
(N
, Standard_Boolean
);
8881 end Unconstrained_Array
;
8883 -- Attribute Update is never static
8885 when Attribute_Update
=>
8892 -- Processing is shared with Size
8898 when Attribute_Val
=> Val
:
8900 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
8902 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
8904 Apply_Compile_Time_Constraint_Error
8905 (N
, "Val expression out of range",
8906 CE_Range_Check_Failed
,
8907 Warn
=> not Static
);
8913 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
8921 -- The Value_Size attribute for a type returns the RM size of the
8922 -- type. This an always be folded for scalar types, and can also
8923 -- be folded for non-scalar types if the size is set.
8925 when Attribute_Value_Size
=> Value_Size
: declare
8926 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8928 if RM_Size
(P_TypeA
) /= Uint_0
then
8929 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
8937 -- Version can never be static
8939 when Attribute_Version
=>
8946 -- Wide_Image is a scalar attribute, but is never static, because it
8947 -- is not a static function (having a non-scalar argument (RM 4.9(22))
8949 when Attribute_Wide_Image
=>
8952 ---------------------
8953 -- Wide_Wide_Image --
8954 ---------------------
8956 -- Wide_Wide_Image is a scalar attribute but is never static, because it
8957 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
8959 when Attribute_Wide_Wide_Image
=>
8962 ---------------------
8963 -- Wide_Wide_Width --
8964 ---------------------
8966 -- Processing for Wide_Wide_Width is combined with Width
8972 -- Processing for Wide_Width is combined with Width
8978 -- This processing also handles the case of Wide_[Wide_]Width
8980 when Attribute_Width |
8981 Attribute_Wide_Width |
8982 Attribute_Wide_Wide_Width
=> Width
:
8984 if Compile_Time_Known_Bounds
(P_Type
) then
8986 -- Floating-point types
8988 if Is_Floating_Point_Type
(P_Type
) then
8990 -- Width is zero for a null range (RM 3.5 (38))
8992 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
8993 Expr_Value_R
(Type_Low_Bound
(P_Type
))
8995 Fold_Uint
(N
, Uint_0
, True);
8998 -- For floating-point, we have +N.dddE+nnn where length
8999 -- of ddd is determined by type'Digits - 1, but is one
9000 -- if Digits is one (RM 3.5 (33)).
9002 -- nnn is set to 2 for Short_Float and Float (32 bit
9003 -- floats), and 3 for Long_Float and Long_Long_Float.
9004 -- For machines where Long_Long_Float is the IEEE
9005 -- extended precision type, the exponent takes 4 digits.
9009 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9012 if Esize
(P_Type
) <= 32 then
9014 elsif Esize
(P_Type
) = 64 then
9020 Fold_Uint
(N
, UI_From_Int
(Len
), True);
9024 -- Fixed-point types
9026 elsif Is_Fixed_Point_Type
(P_Type
) then
9028 -- Width is zero for a null range (RM 3.5 (38))
9030 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9031 Expr_Value
(Type_Low_Bound
(P_Type
))
9033 Fold_Uint
(N
, Uint_0
, True);
9035 -- The non-null case depends on the specific real type
9038 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9041 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9049 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9050 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9051 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9064 -- Width for types derived from Standard.Character
9065 -- and Standard.Wide_[Wide_]Character.
9067 elsif Is_Standard_Character_Type
(P_Type
) then
9070 -- Set W larger if needed
9072 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9074 -- All wide characters look like Hex_hhhhhhhh
9078 -- No need to compute this more than once
9083 C
:= Character'Val (J
);
9085 -- Test for all cases where Character'Image
9086 -- yields an image that is longer than three
9087 -- characters. First the cases of Reserved_xxx
9088 -- names (length = 12).
9091 when Reserved_128 | Reserved_129 |
9092 Reserved_132 | Reserved_153
9095 when BS | HT | LF | VT | FF | CR |
9096 SO | SI | EM | FS | GS | RS |
9097 US | RI | MW | ST | PM
9100 when NUL | SOH | STX | ETX | EOT |
9101 ENQ | ACK | BEL | DLE | DC1 |
9102 DC2 | DC3 | DC4 | NAK | SYN |
9103 ETB | CAN | SUB | ESC | DEL |
9104 BPH | NBH | NEL | SSA | ESA |
9105 HTS | HTJ | VTS | PLD | PLU |
9106 SS2 | SS3 | DCS | PU1 | PU2 |
9107 STS | CCH | SPA | EPA | SOS |
9108 SCI | CSI | OSC | APC
9111 when Space
.. Tilde |
9112 No_Break_Space
.. LC_Y_Diaeresis
9114 -- Special case of soft hyphen in Ada 2005
9116 if C
= Character'Val (16#AD#
)
9117 and then Ada_Version
>= Ada_2005
9125 W
:= Int
'Max (W
, Wt
);
9129 -- Width for types derived from Standard.Boolean
9131 elsif R
= Standard_Boolean
then
9138 -- Width for integer types
9140 elsif Is_Integer_Type
(P_Type
) then
9141 T
:= UI_Max
(abs Lo
, abs Hi
);
9149 -- User declared enum type with discard names
9151 elsif Discard_Names
(R
) then
9153 -- If range is null, result is zero, that has already
9154 -- been dealt with, so what we need is the power of ten
9155 -- that accomodates the Pos of the largest value, which
9156 -- is the high bound of the range + one for the space.
9165 -- Only remaining possibility is user declared enum type
9166 -- with normal case of Discard_Names not active.
9169 pragma Assert
(Is_Enumeration_Type
(P_Type
));
9172 L
:= First_Literal
(P_Type
);
9173 while Present
(L
) loop
9175 -- Only pay attention to in range characters
9177 if Lo
<= Enumeration_Pos
(L
)
9178 and then Enumeration_Pos
(L
) <= Hi
9180 -- For Width case, use decoded name
9182 if Id
= Attribute_Width
then
9183 Get_Decoded_Name_String
(Chars
(L
));
9184 Wt
:= Nat
(Name_Len
);
9186 -- For Wide_[Wide_]Width, use encoded name, and
9187 -- then adjust for the encoding.
9190 Get_Name_String
(Chars
(L
));
9192 -- Character literals are always of length 3
9194 if Name_Buffer
(1) = 'Q' then
9197 -- Otherwise loop to adjust for upper/wide chars
9200 Wt
:= Nat
(Name_Len
);
9202 for J
in 1 .. Name_Len
loop
9203 if Name_Buffer
(J
) = 'U' then
9205 elsif Name_Buffer
(J
) = 'W' then
9212 W
:= Int
'Max (W
, Wt
);
9219 Fold_Uint
(N
, UI_From_Int
(W
), True);
9225 -- The following attributes denote functions that cannot be folded
9227 when Attribute_From_Any |
9229 Attribute_TypeCode
=>
9232 -- The following attributes can never be folded, and furthermore we
9233 -- should not even have entered the case statement for any of these.
9234 -- Note that in some cases, the values have already been folded as
9235 -- a result of the processing in Analyze_Attribute.
9237 when Attribute_Abort_Signal |
9240 Attribute_Address_Size |
9241 Attribute_Asm_Input |
9242 Attribute_Asm_Output |
9244 Attribute_Bit_Order |
9245 Attribute_Bit_Position |
9246 Attribute_Callable |
9249 Attribute_Code_Address |
9250 Attribute_Compiler_Version |
9252 Attribute_Default_Bit_Order |
9253 Attribute_Elaborated |
9254 Attribute_Elab_Body |
9255 Attribute_Elab_Spec |
9256 Attribute_Elab_Subp_Body |
9258 Attribute_External_Tag |
9259 Attribute_Fast_Math |
9260 Attribute_First_Bit |
9262 Attribute_Last_Bit |
9263 Attribute_Library_Level |
9264 Attribute_Maximum_Alignment |
9267 Attribute_Partition_ID |
9268 Attribute_Pool_Address |
9269 Attribute_Position |
9270 Attribute_Priority |
9273 Attribute_Scalar_Storage_Order |
9274 Attribute_Simple_Storage_Pool |
9275 Attribute_Storage_Pool |
9276 Attribute_Storage_Size |
9277 Attribute_Storage_Unit |
9278 Attribute_Stub_Type |
9279 Attribute_System_Allocator_Alignment |
9281 Attribute_Target_Name |
9282 Attribute_Terminated |
9283 Attribute_To_Address |
9284 Attribute_Type_Key |
9285 Attribute_UET_Address |
9286 Attribute_Unchecked_Access |
9287 Attribute_Universal_Literal_String |
9288 Attribute_Unrestricted_Access |
9290 Attribute_Valid_Scalars |
9292 Attribute_Wchar_T_Size |
9293 Attribute_Wide_Value |
9294 Attribute_Wide_Wide_Value |
9295 Attribute_Word_Size |
9298 raise Program_Error
;
9301 -- At the end of the case, one more check. If we did a static evaluation
9302 -- so that the result is now a literal, then set Is_Static_Expression
9303 -- in the constant only if the prefix type is a static subtype. For
9304 -- non-static subtypes, the folding is still OK, but not static.
9306 -- An exception is the GNAT attribute Constrained_Array which is
9307 -- defined to be a static attribute in all cases.
9309 if Nkind_In
(N
, N_Integer_Literal
,
9311 N_Character_Literal
,
9313 or else (Is_Entity_Name
(N
)
9314 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
9316 Set_Is_Static_Expression
(N
, Static
);
9318 -- If this is still an attribute reference, then it has not been folded
9319 -- and that means that its expressions are in a non-static context.
9321 elsif Nkind
(N
) = N_Attribute_Reference
then
9324 -- Note: the else case not covered here are odd cases where the
9325 -- processing has transformed the attribute into something other
9326 -- than a constant. Nothing more to do in such cases.
9333 ------------------------------
9334 -- Is_Anonymous_Tagged_Base --
9335 ------------------------------
9337 function Is_Anonymous_Tagged_Base
9344 Anon
= Current_Scope
9345 and then Is_Itype
(Anon
)
9346 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
9347 end Is_Anonymous_Tagged_Base
;
9349 --------------------------------
9350 -- Name_Implies_Lvalue_Prefix --
9351 --------------------------------
9353 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
9354 pragma Assert
(Is_Attribute_Name
(Nam
));
9356 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
9357 end Name_Implies_Lvalue_Prefix
;
9359 -----------------------
9360 -- Resolve_Attribute --
9361 -----------------------
9363 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
9364 Loc
: constant Source_Ptr
:= Sloc
(N
);
9365 P
: constant Node_Id
:= Prefix
(N
);
9366 Aname
: constant Name_Id
:= Attribute_Name
(N
);
9367 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
9368 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9369 Des_Btyp
: Entity_Id
;
9370 Index
: Interp_Index
;
9372 Nom_Subt
: Entity_Id
;
9374 procedure Accessibility_Message
;
9375 -- Error, or warning within an instance, if the static accessibility
9376 -- rules of 3.10.2 are violated.
9378 ---------------------------
9379 -- Accessibility_Message --
9380 ---------------------------
9382 procedure Accessibility_Message
is
9383 Indic
: Node_Id
:= Parent
(Parent
(N
));
9386 -- In an instance, this is a runtime check, but one we
9387 -- know will fail, so generate an appropriate warning.
9389 if In_Instance_Body
then
9390 Error_Msg_Warn
:= SPARK_Mode
/= On
;
9392 ("non-local pointer cannot point to local object<<", P
);
9393 Error_Msg_F
("\Program_Error [<<", P
);
9395 Make_Raise_Program_Error
(Loc
,
9396 Reason
=> PE_Accessibility_Check_Failed
));
9401 Error_Msg_F
("non-local pointer cannot point to local object", P
);
9403 -- Check for case where we have a missing access definition
9405 if Is_Record_Type
(Current_Scope
)
9407 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
9408 N_Index_Or_Discriminant_Constraint
)
9410 Indic
:= Parent
(Parent
(N
));
9411 while Present
(Indic
)
9412 and then Nkind
(Indic
) /= N_Subtype_Indication
9414 Indic
:= Parent
(Indic
);
9417 if Present
(Indic
) then
9419 ("\use an access definition for" &
9420 " the access discriminant of&",
9421 N
, Entity
(Subtype_Mark
(Indic
)));
9425 end Accessibility_Message
;
9427 -- Start of processing for Resolve_Attribute
9430 -- If error during analysis, no point in continuing, except for array
9431 -- types, where we get better recovery by using unconstrained indexes
9432 -- than nothing at all (see Check_Array_Type).
9435 and then Attr_Id
/= Attribute_First
9436 and then Attr_Id
/= Attribute_Last
9437 and then Attr_Id
/= Attribute_Length
9438 and then Attr_Id
/= Attribute_Range
9443 -- If attribute was universal type, reset to actual type
9445 if Etype
(N
) = Universal_Integer
9446 or else Etype
(N
) = Universal_Real
9451 -- Remaining processing depends on attribute
9459 -- For access attributes, if the prefix denotes an entity, it is
9460 -- interpreted as a name, never as a call. It may be overloaded,
9461 -- in which case resolution uses the profile of the context type.
9462 -- Otherwise prefix must be resolved.
9464 when Attribute_Access
9465 | Attribute_Unchecked_Access
9466 | Attribute_Unrestricted_Access
=>
9470 if Is_Variable
(P
) then
9471 Note_Possible_Modification
(P
, Sure
=> False);
9474 -- The following comes from a query by Adam Beneschan, concerning
9475 -- improper use of universal_access in equality tests involving
9476 -- anonymous access types. Another good reason for 'Ref, but
9477 -- for now disable the test, which breaks several filed tests.
9479 if Ekind
(Typ
) = E_Anonymous_Access_Type
9480 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
9483 Error_Msg_N
("need unique type to resolve 'Access", N
);
9484 Error_Msg_N
("\qualify attribute with some access type", N
);
9487 if Is_Entity_Name
(P
) then
9488 if Is_Overloaded
(P
) then
9489 Get_First_Interp
(P
, Index
, It
);
9490 while Present
(It
.Nam
) loop
9491 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
9492 Set_Entity
(P
, It
.Nam
);
9494 -- The prefix is definitely NOT overloaded anymore at
9495 -- this point, so we reset the Is_Overloaded flag to
9496 -- avoid any confusion when reanalyzing the node.
9498 Set_Is_Overloaded
(P
, False);
9499 Set_Is_Overloaded
(N
, False);
9500 Generate_Reference
(Entity
(P
), P
);
9504 Get_Next_Interp
(Index
, It
);
9507 -- If Prefix is a subprogram name, it is frozen by this
9510 -- If it is a type, there is nothing to resolve.
9511 -- If it is an object, complete its resolution.
9513 elsif Is_Overloadable
(Entity
(P
)) then
9515 -- Avoid insertion of freeze actions in spec expression mode
9517 if not In_Spec_Expression
then
9518 Freeze_Before
(N
, Entity
(P
));
9521 elsif Is_Type
(Entity
(P
)) then
9527 Error_Msg_Name_1
:= Aname
;
9529 if not Is_Entity_Name
(P
) then
9532 elsif Is_Overloadable
(Entity
(P
))
9533 and then Is_Abstract_Subprogram
(Entity
(P
))
9535 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
9536 Set_Etype
(N
, Any_Type
);
9538 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
9539 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
9541 ("prefix of % attribute cannot be enumeration literal",
9545 ("prefix of % attribute cannot be intrinsic", P
);
9548 Set_Etype
(N
, Any_Type
);
9551 -- Assignments, return statements, components of aggregates,
9552 -- generic instantiations will require convention checks if
9553 -- the type is an access to subprogram. Given that there will
9554 -- also be accessibility checks on those, this is where the
9555 -- checks can eventually be centralized ???
9557 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
9558 E_Anonymous_Access_Subprogram_Type
,
9559 E_Access_Protected_Subprogram_Type
,
9560 E_Anonymous_Access_Protected_Subprogram_Type
)
9562 -- Deal with convention mismatch
9564 if Convention
(Designated_Type
(Btyp
)) /=
9565 Convention
(Entity
(P
))
9568 ("subprogram & has wrong convention", P
, Entity
(P
));
9570 ("\does not match convention of access type &",
9573 if not Has_Convention_Pragma
(Btyp
) then
9575 ("\probable missing pragma Convention for &",
9580 Check_Subtype_Conformant
9581 (New_Id
=> Entity
(P
),
9582 Old_Id
=> Designated_Type
(Btyp
),
9586 if Attr_Id
= Attribute_Unchecked_Access
then
9587 Error_Msg_Name_1
:= Aname
;
9589 ("attribute% cannot be applied to a subprogram", P
);
9591 elsif Aname
= Name_Unrestricted_Access
then
9592 null; -- Nothing to check
9594 -- Check the static accessibility rule of 3.10.2(32).
9595 -- This rule also applies within the private part of an
9596 -- instantiation. This rule does not apply to anonymous
9597 -- access-to-subprogram types in access parameters.
9599 elsif Attr_Id
= Attribute_Access
9600 and then not In_Instance_Body
9602 (Ekind
(Btyp
) = E_Access_Subprogram_Type
9603 or else Is_Local_Anonymous_Access
(Btyp
))
9604 and then Subprogram_Access_Level
(Entity
(P
)) >
9605 Type_Access_Level
(Btyp
)
9608 ("subprogram must not be deeper than access type", P
);
9610 -- Check the restriction of 3.10.2(32) that disallows the
9611 -- access attribute within a generic body when the ultimate
9612 -- ancestor of the type of the attribute is declared outside
9613 -- of the generic unit and the subprogram is declared within
9614 -- that generic unit. This includes any such attribute that
9615 -- occurs within the body of a generic unit that is a child
9616 -- of the generic unit where the subprogram is declared.
9618 -- The rule also prohibits applying the attribute when the
9619 -- access type is a generic formal access type (since the
9620 -- level of the actual type is not known). This restriction
9621 -- does not apply when the attribute type is an anonymous
9622 -- access-to-subprogram type. Note that this check was
9623 -- revised by AI-229, because the originally Ada 95 rule
9624 -- was too lax. The original rule only applied when the
9625 -- subprogram was declared within the body of the generic,
9626 -- which allowed the possibility of dangling references).
9627 -- The rule was also too strict in some case, in that it
9628 -- didn't permit the access to be declared in the generic
9629 -- spec, whereas the revised rule does (as long as it's not
9632 -- There are a couple of subtleties of the test for applying
9633 -- the check that are worth noting. First, we only apply it
9634 -- when the levels of the subprogram and access type are the
9635 -- same (the case where the subprogram is statically deeper
9636 -- was applied above, and the case where the type is deeper
9637 -- is always safe). Second, we want the check to apply
9638 -- within nested generic bodies and generic child unit
9639 -- bodies, but not to apply to an attribute that appears in
9640 -- the generic unit's specification. This is done by testing
9641 -- that the attribute's innermost enclosing generic body is
9642 -- not the same as the innermost generic body enclosing the
9643 -- generic unit where the subprogram is declared (we don't
9644 -- want the check to apply when the access attribute is in
9645 -- the spec and there's some other generic body enclosing
9646 -- generic). Finally, there's no point applying the check
9647 -- when within an instance, because any violations will have
9648 -- been caught by the compilation of the generic unit.
9650 -- We relax this check in Relaxed_RM_Semantics mode for
9651 -- compatibility with legacy code for use by Ada source
9652 -- code analyzers (e.g. CodePeer).
9654 elsif Attr_Id
= Attribute_Access
9655 and then not Relaxed_RM_Semantics
9656 and then not In_Instance
9657 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
9658 and then Present
(Enclosing_Generic_Body
(N
))
9659 and then Enclosing_Generic_Body
(N
) /=
9660 Enclosing_Generic_Body
9661 (Enclosing_Generic_Unit
(Entity
(P
)))
9662 and then Subprogram_Access_Level
(Entity
(P
)) =
9663 Type_Access_Level
(Btyp
)
9664 and then Ekind
(Btyp
) /=
9665 E_Anonymous_Access_Subprogram_Type
9666 and then Ekind
(Btyp
) /=
9667 E_Anonymous_Access_Protected_Subprogram_Type
9669 -- The attribute type's ultimate ancestor must be
9670 -- declared within the same generic unit as the
9671 -- subprogram is declared. The error message is
9672 -- specialized to say "ancestor" for the case where the
9673 -- access type is not its own ancestor, since saying
9674 -- simply "access type" would be very confusing.
9676 if Enclosing_Generic_Unit
(Entity
(P
)) /=
9677 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
9680 ("''Access attribute not allowed in generic body",
9683 if Root_Type
(Btyp
) = Btyp
then
9686 "access type & is declared outside " &
9687 "generic unit (RM 3.10.2(32))", N
, Btyp
);
9690 ("\because ancestor of " &
9691 "access type & is declared outside " &
9692 "generic unit (RM 3.10.2(32))", N
, Btyp
);
9696 ("\move ''Access to private part, or " &
9697 "(Ada 2005) use anonymous access type instead of &",
9700 -- If the ultimate ancestor of the attribute's type is
9701 -- a formal type, then the attribute is illegal because
9702 -- the actual type might be declared at a higher level.
9703 -- The error message is specialized to say "ancestor"
9704 -- for the case where the access type is not its own
9705 -- ancestor, since saying simply "access type" would be
9708 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
9709 if Root_Type
(Btyp
) = Btyp
then
9711 ("access type must not be a generic formal type",
9715 ("ancestor access type must not be a generic " &
9722 -- If this is a renaming, an inherited operation, or a
9723 -- subprogram instance, use the original entity. This may make
9724 -- the node type-inconsistent, so this transformation can only
9725 -- be done if the node will not be reanalyzed. In particular,
9726 -- if it is within a default expression, the transformation
9727 -- must be delayed until the default subprogram is created for
9728 -- it, when the enclosing subprogram is frozen.
9730 if Is_Entity_Name
(P
)
9731 and then Is_Overloadable
(Entity
(P
))
9732 and then Present
(Alias
(Entity
(P
)))
9733 and then Expander_Active
9736 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
9739 elsif Nkind
(P
) = N_Selected_Component
9740 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
9742 -- Protected operation. If operation is overloaded, must
9743 -- disambiguate. Prefix that denotes protected object itself
9744 -- is resolved with its own type.
9746 if Attr_Id
= Attribute_Unchecked_Access
then
9747 Error_Msg_Name_1
:= Aname
;
9749 ("attribute% cannot be applied to protected operation", P
);
9752 Resolve
(Prefix
(P
));
9753 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
9755 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
9756 -- statically illegal if F is an anonymous access to subprogram.
9758 elsif Nkind
(P
) = N_Explicit_Dereference
9759 and then Is_Entity_Name
(Prefix
(P
))
9760 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
9761 E_Anonymous_Access_Subprogram_Type
9763 Error_Msg_N
("anonymous access to subprogram "
9764 & "has deeper accessibility than any master", P
);
9766 elsif Is_Overloaded
(P
) then
9768 -- Use the designated type of the context to disambiguate
9769 -- Note that this was not strictly conformant to Ada 95,
9770 -- but was the implementation adopted by most Ada 95 compilers.
9771 -- The use of the context type to resolve an Access attribute
9772 -- reference is now mandated in AI-235 for Ada 2005.
9775 Index
: Interp_Index
;
9779 Get_First_Interp
(P
, Index
, It
);
9780 while Present
(It
.Typ
) loop
9781 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
9782 Resolve
(P
, It
.Typ
);
9786 Get_Next_Interp
(Index
, It
);
9793 -- X'Access is illegal if X denotes a constant and the access type
9794 -- is access-to-variable. Same for 'Unchecked_Access. The rule
9795 -- does not apply to 'Unrestricted_Access. If the reference is a
9796 -- default-initialized aggregate component for a self-referential
9797 -- type the reference is legal.
9799 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
9800 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
9801 or else (Is_Record_Type
(Btyp
)
9803 Present
(Corresponding_Remote_Type
(Btyp
)))
9804 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
9805 or else Ekind
(Btyp
)
9806 = E_Anonymous_Access_Protected_Subprogram_Type
9807 or else Is_Access_Constant
(Btyp
)
9808 or else Is_Variable
(P
)
9809 or else Attr_Id
= Attribute_Unrestricted_Access
)
9811 if Is_Entity_Name
(P
)
9812 and then Is_Type
(Entity
(P
))
9814 -- Legality of a self-reference through an access
9815 -- attribute has been verified in Analyze_Access_Attribute.
9819 elsif Comes_From_Source
(N
) then
9820 Error_Msg_F
("access-to-variable designates constant", P
);
9824 Des_Btyp
:= Designated_Type
(Btyp
);
9826 if Ada_Version
>= Ada_2005
9827 and then Is_Incomplete_Type
(Des_Btyp
)
9829 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
9830 -- imported entity, and the non-limited view is visible, make
9831 -- use of it. If it is an incomplete subtype, use the base type
9834 if From_Limited_With
(Des_Btyp
)
9835 and then Present
(Non_Limited_View
(Des_Btyp
))
9837 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
9839 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
9840 Des_Btyp
:= Etype
(Des_Btyp
);
9844 if (Attr_Id
= Attribute_Access
9846 Attr_Id
= Attribute_Unchecked_Access
)
9847 and then (Ekind
(Btyp
) = E_General_Access_Type
9848 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
9850 -- Ada 2005 (AI-230): Check the accessibility of anonymous
9851 -- access types for stand-alone objects, record and array
9852 -- components, and return objects. For a component definition
9853 -- the level is the same of the enclosing composite type.
9855 if Ada_Version
>= Ada_2005
9856 and then (Is_Local_Anonymous_Access
(Btyp
)
9858 -- Handle cases where Btyp is the anonymous access
9859 -- type of an Ada 2012 stand-alone object.
9861 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9862 N_Object_Declaration
)
9864 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
9865 and then Attr_Id
= Attribute_Access
9867 -- In an instance, this is a runtime check, but one we know
9868 -- will fail, so generate an appropriate warning. As usual,
9869 -- this kind of warning is an error in SPARK mode.
9871 if In_Instance_Body
then
9872 Error_Msg_Warn
:= SPARK_Mode
/= On
;
9874 ("non-local pointer cannot point to local object<<", P
);
9875 Error_Msg_F
("\Program_Error [<<", P
);
9878 Make_Raise_Program_Error
(Loc
,
9879 Reason
=> PE_Accessibility_Check_Failed
));
9884 ("non-local pointer cannot point to local object", P
);
9888 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
9890 ("illegal attribute for discriminant-dependent component",
9894 -- Check static matching rule of 3.10.2(27). Nominal subtype
9895 -- of the prefix must statically match the designated type.
9897 Nom_Subt
:= Etype
(P
);
9899 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
9900 Nom_Subt
:= Base_Type
(Nom_Subt
);
9903 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
9905 -- If the attribute is in the context of an access
9906 -- parameter, then the prefix is allowed to be of the
9907 -- class-wide type (by AI-127).
9909 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
9910 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
9911 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
9917 Desig
:= Designated_Type
(Typ
);
9919 if Is_Class_Wide_Type
(Desig
) then
9920 Desig
:= Etype
(Desig
);
9923 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
9928 ("type of prefix: & not compatible",
9931 ("\with &, the expected designated type",
9932 P
, Designated_Type
(Typ
));
9937 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
9939 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
9940 and then Is_Class_Wide_Type
(Nom_Subt
))
9943 ("type of prefix: & is not covered", P
, Nom_Subt
);
9945 ("\by &, the expected designated type" &
9946 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
9949 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
9950 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
9951 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
9952 and then Designated_Type
(Typ
) /= Nom_Subt
9954 Apply_Discriminant_Check
9955 (N
, Etype
(Designated_Type
(Typ
)));
9958 -- Ada 2005 (AI-363): Require static matching when designated
9959 -- type has discriminants and a constrained partial view, since
9960 -- in general objects of such types are mutable, so we can't
9961 -- allow the access value to designate a constrained object
9962 -- (because access values must be assumed to designate mutable
9963 -- objects when designated type does not impose a constraint).
9965 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
9968 elsif Has_Discriminants
(Designated_Type
(Typ
))
9969 and then not Is_Constrained
(Des_Btyp
)
9971 (Ada_Version
< Ada_2005
9973 not Object_Type_Has_Constrained_Partial_View
9974 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
9975 Scop
=> Current_Scope
))
9981 ("object subtype must statically match "
9982 & "designated subtype", P
);
9984 if Is_Entity_Name
(P
)
9985 and then Is_Array_Type
(Designated_Type
(Typ
))
9988 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
9991 ("aliased object has explicit bounds??", D
);
9993 ("\declare without bounds (and with explicit "
9994 & "initialization)??", D
);
9996 ("\for use with unconstrained access??", D
);
10001 -- Check the static accessibility rule of 3.10.2(28). Note that
10002 -- this check is not performed for the case of an anonymous
10003 -- access type, since the access attribute is always legal
10004 -- in such a context.
10006 if Attr_Id
/= Attribute_Unchecked_Access
10007 and then Ekind
(Btyp
) = E_General_Access_Type
10009 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10011 Accessibility_Message
;
10016 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10017 E_Anonymous_Access_Protected_Subprogram_Type
)
10019 if Is_Entity_Name
(P
)
10020 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
10022 Error_Msg_F
("context requires a protected subprogram", P
);
10024 -- Check accessibility of protected object against that of the
10025 -- access type, but only on user code, because the expander
10026 -- creates access references for handlers. If the context is an
10027 -- anonymous_access_to_protected, there are no accessibility
10028 -- checks either. Omit check entirely for Unrestricted_Access.
10030 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10031 and then Comes_From_Source
(N
)
10032 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10033 and then Attr_Id
/= Attribute_Unrestricted_Access
10035 Accessibility_Message
;
10038 -- AI05-0225: If the context is not an access to protected
10039 -- function, the prefix must be a variable, given that it may
10040 -- be used subsequently in a protected call.
10042 elsif Nkind
(P
) = N_Selected_Component
10043 and then not Is_Variable
(Prefix
(P
))
10044 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
10047 ("target object of access to protected procedure "
10048 & "must be variable", N
);
10050 elsif Is_Entity_Name
(P
) then
10051 Check_Internal_Protected_Use
(N
, Entity
(P
));
10054 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10055 E_Anonymous_Access_Subprogram_Type
)
10056 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
10058 Error_Msg_F
("context requires a non-protected subprogram", P
);
10061 -- The context cannot be a pool-specific type, but this is a
10062 -- legality rule, not a resolution rule, so it must be checked
10063 -- separately, after possibly disambiguation (see AI-245).
10065 if Ekind
(Btyp
) = E_Access_Type
10066 and then Attr_Id
/= Attribute_Unrestricted_Access
10068 Wrong_Type
(N
, Typ
);
10071 -- The context may be a constrained access type (however ill-
10072 -- advised such subtypes might be) so in order to generate a
10073 -- constraint check when needed set the type of the attribute
10074 -- reference to the base type of the context.
10076 Set_Etype
(N
, Btyp
);
10078 -- Check for incorrect atomic/volatile reference (RM C.6(12))
10080 if Attr_Id
/= Attribute_Unrestricted_Access
then
10081 if Is_Atomic_Object
(P
)
10082 and then not Is_Atomic
(Designated_Type
(Typ
))
10085 ("access to atomic object cannot yield access-to-" &
10086 "non-atomic type", P
);
10088 elsif Is_Volatile_Object
(P
)
10089 and then not Is_Volatile
(Designated_Type
(Typ
))
10092 ("access to volatile object cannot yield access-to-" &
10093 "non-volatile type", P
);
10097 if Is_Entity_Name
(P
) then
10098 Set_Address_Taken
(Entity
(P
));
10100 end Access_Attribute
;
10106 -- Deal with resolving the type for Address attribute, overloading
10107 -- is not permitted here, since there is no context to resolve it.
10109 when Attribute_Address | Attribute_Code_Address
=>
10110 Address_Attribute
: begin
10112 -- To be safe, assume that if the address of a variable is taken,
10113 -- it may be modified via this address, so note modification.
10115 if Is_Variable
(P
) then
10116 Note_Possible_Modification
(P
, Sure
=> False);
10119 if Nkind
(P
) in N_Subexpr
10120 and then Is_Overloaded
(P
)
10122 Get_First_Interp
(P
, Index
, It
);
10123 Get_Next_Interp
(Index
, It
);
10125 if Present
(It
.Nam
) then
10126 Error_Msg_Name_1
:= Aname
;
10128 ("prefix of % attribute cannot be overloaded", P
);
10132 if not Is_Entity_Name
(P
)
10133 or else not Is_Overloadable
(Entity
(P
))
10135 if not Is_Task_Type
(Etype
(P
))
10136 or else Nkind
(P
) = N_Explicit_Dereference
10142 -- If this is the name of a derived subprogram, or that of a
10143 -- generic actual, the address is that of the original entity.
10145 if Is_Entity_Name
(P
)
10146 and then Is_Overloadable
(Entity
(P
))
10147 and then Present
(Alias
(Entity
(P
)))
10150 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10153 if Is_Entity_Name
(P
) then
10154 Set_Address_Taken
(Entity
(P
));
10157 if Nkind
(P
) = N_Slice
then
10159 -- Arr (X .. Y)'address is identical to Arr (X)'address,
10160 -- even if the array is packed and the slice itself is not
10161 -- addressable. Transform the prefix into an indexed component.
10163 -- Note that the transformation is safe only if we know that
10164 -- the slice is non-null. That is because a null slice can have
10165 -- an out of bounds index value.
10167 -- Right now, gigi blows up if given 'Address on a slice as a
10168 -- result of some incorrect freeze nodes generated by the front
10169 -- end, and this covers up that bug in one case, but the bug is
10170 -- likely still there in the cases not handled by this code ???
10172 -- It's not clear what 'Address *should* return for a null
10173 -- slice with out of bounds indexes, this might be worth an ARG
10176 -- One approach would be to do a length check unconditionally,
10177 -- and then do the transformation below unconditionally, but
10178 -- analyze with checks off, avoiding the problem of the out of
10179 -- bounds index. This approach would interpret the address of
10180 -- an out of bounds null slice as being the address where the
10181 -- array element would be if there was one, which is probably
10182 -- as reasonable an interpretation as any ???
10185 Loc
: constant Source_Ptr
:= Sloc
(P
);
10186 D
: constant Node_Id
:= Discrete_Range
(P
);
10190 if Is_Entity_Name
(D
)
10193 (Type_Low_Bound
(Entity
(D
)),
10194 Type_High_Bound
(Entity
(D
)))
10197 Make_Attribute_Reference
(Loc
,
10198 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
10199 Attribute_Name
=> Name_First
);
10201 elsif Nkind
(D
) = N_Range
10202 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
10204 Lo
:= Low_Bound
(D
);
10210 if Present
(Lo
) then
10212 Make_Indexed_Component
(Loc
,
10213 Prefix
=> Relocate_Node
(Prefix
(P
)),
10214 Expressions
=> New_List
(Lo
)));
10216 Analyze_And_Resolve
(P
);
10220 end Address_Attribute
;
10226 -- Prefix of the AST_Entry attribute is an entry name which must
10227 -- not be resolved, since this is definitely not an entry call.
10229 when Attribute_AST_Entry
=>
10236 -- Prefix of Body_Version attribute can be a subprogram name which
10237 -- must not be resolved, since this is not a call.
10239 when Attribute_Body_Version
=>
10246 -- Prefix of Caller attribute is an entry name which must not
10247 -- be resolved, since this is definitely not an entry call.
10249 when Attribute_Caller
=>
10256 -- Shares processing with Address attribute
10262 -- If the prefix of the Count attribute is an entry name it must not
10263 -- be resolved, since this is definitely not an entry call. However,
10264 -- if it is an element of an entry family, the index itself may
10265 -- have to be resolved because it can be a general expression.
10267 when Attribute_Count
=>
10268 if Nkind
(P
) = N_Indexed_Component
10269 and then Is_Entity_Name
(Prefix
(P
))
10272 Indx
: constant Node_Id
:= First
(Expressions
(P
));
10273 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
10275 Resolve
(Indx
, Entry_Index_Type
(Fam
));
10276 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
10284 -- Prefix of the Elaborated attribute is a subprogram name which
10285 -- must not be resolved, since this is definitely not a call. Note
10286 -- that it is a library unit, so it cannot be overloaded here.
10288 when Attribute_Elaborated
=>
10295 -- Prefix of Enabled attribute is a check name, which must be treated
10296 -- specially and not touched by Resolve.
10298 when Attribute_Enabled
=>
10305 -- Do not resolve the prefix of Loop_Entry, instead wait until the
10306 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
10307 -- The delay ensures that any generated checks or temporaries are
10308 -- inserted before the relocated prefix.
10310 when Attribute_Loop_Entry
=>
10313 --------------------
10314 -- Mechanism_Code --
10315 --------------------
10317 -- Prefix of the Mechanism_Code attribute is a function name
10318 -- which must not be resolved. Should we check for overloaded ???
10320 when Attribute_Mechanism_Code
=>
10327 -- Most processing is done in sem_dist, after determining the
10328 -- context type. Node is rewritten as a conversion to a runtime call.
10330 when Attribute_Partition_ID
=>
10331 Process_Partition_Id
(N
);
10338 when Attribute_Pool_Address
=>
10345 -- We replace the Range attribute node with a range expression whose
10346 -- bounds are the 'First and 'Last attributes applied to the same
10347 -- prefix. The reason that we do this transformation here instead of
10348 -- in the expander is that it simplifies other parts of the semantic
10349 -- analysis which assume that the Range has been replaced; thus it
10350 -- must be done even when in semantic-only mode (note that the RM
10351 -- specifically mentions this equivalence, we take care that the
10352 -- prefix is only evaluated once).
10354 when Attribute_Range
=> Range_Attribute
:
10361 if not Is_Entity_Name
(P
)
10362 or else not Is_Type
(Entity
(P
))
10367 Dims
:= Expressions
(N
);
10370 Make_Attribute_Reference
(Loc
,
10372 Duplicate_Subexpr
(P
, Name_Req
=> True),
10373 Attribute_Name
=> Name_Last
,
10374 Expressions
=> Dims
);
10377 Make_Attribute_Reference
(Loc
,
10379 Attribute_Name
=> Name_First
,
10380 Expressions
=> (Dims
));
10382 -- Do not share the dimension indicator, if present. Even
10383 -- though it is a static constant, its source location
10384 -- may be modified when printing expanded code and node
10385 -- sharing will lead to chaos in Sprint.
10387 if Present
(Dims
) then
10388 Set_Expressions
(LB
,
10389 New_List
(New_Copy_Tree
(First
(Dims
))));
10392 -- If the original was marked as Must_Not_Freeze (see code
10393 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10394 -- does not freeze either.
10396 if Must_Not_Freeze
(N
) then
10397 Set_Must_Not_Freeze
(HB
);
10398 Set_Must_Not_Freeze
(LB
);
10399 Set_Must_Not_Freeze
(Prefix
(HB
));
10400 Set_Must_Not_Freeze
(Prefix
(LB
));
10403 if Raises_Constraint_Error
(Prefix
(N
)) then
10405 -- Preserve Sloc of prefix in the new bounds, so that
10406 -- the posted warning can be removed if we are within
10407 -- unreachable code.
10409 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
10410 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
10413 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
10414 Analyze_And_Resolve
(N
, Typ
);
10416 -- Ensure that the expanded range does not have side effects
10418 Force_Evaluation
(LB
);
10419 Force_Evaluation
(HB
);
10421 -- Normally after resolving attribute nodes, Eval_Attribute
10422 -- is called to do any possible static evaluation of the node.
10423 -- However, here since the Range attribute has just been
10424 -- transformed into a range expression it is no longer an
10425 -- attribute node and therefore the call needs to be avoided
10426 -- and is accomplished by simply returning from the procedure.
10429 end Range_Attribute
;
10435 -- We will only come here during the prescan of a spec expression
10436 -- containing a Result attribute. In that case the proper Etype has
10437 -- already been set, and nothing more needs to be done here.
10439 when Attribute_Result
=>
10446 -- Prefix must not be resolved in this case, since it is not a
10447 -- real entity reference. No action of any kind is require.
10449 when Attribute_UET_Address
=>
10452 ----------------------
10453 -- Unchecked_Access --
10454 ----------------------
10456 -- Processing is shared with Access
10458 -------------------------
10459 -- Unrestricted_Access --
10460 -------------------------
10462 -- Processing is shared with Access
10468 -- Resolve aggregate components in component associations
10470 when Attribute_Update
=>
10472 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
10473 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
10478 -- Set the Etype of the aggregate to that of the prefix, even
10479 -- though the aggregate may not be a proper representation of a
10480 -- value of the type (missing or duplicated associations, etc.)
10481 -- Complete resolution of the prefix. Note that in Ada 2012 it
10482 -- can be a qualified expression that is e.g. an aggregate.
10484 Set_Etype
(Aggr
, Typ
);
10485 Resolve
(Prefix
(N
), Typ
);
10487 -- For an array type, resolve expressions with the component
10488 -- type of the array.
10490 if Is_Array_Type
(Typ
) then
10491 Assoc
:= First
(Component_Associations
(Aggr
));
10492 while Present
(Assoc
) loop
10493 Resolve
(Expression
(Assoc
), Component_Type
(Typ
));
10497 -- For a record type, use type of each component, which is
10498 -- recorded during analysis.
10501 Assoc
:= First
(Component_Associations
(Aggr
));
10502 while Present
(Assoc
) loop
10503 Comp
:= First
(Choices
(Assoc
));
10504 if Nkind
(Comp
) /= N_Others_Choice
10505 and then not Error_Posted
(Comp
)
10507 Resolve
(Expression
(Assoc
), Etype
(Entity
(Comp
)));
10514 -- Premature return requires comment ???
10522 -- Apply range check. Note that we did not do this during the
10523 -- analysis phase, since we wanted Eval_Attribute to have a
10524 -- chance at finding an illegal out of range value.
10526 when Attribute_Val
=>
10528 -- Note that we do our own Eval_Attribute call here rather than
10529 -- use the common one, because we need to do processing after
10530 -- the call, as per above comment.
10532 Eval_Attribute
(N
);
10534 -- Eval_Attribute may replace the node with a raise CE, or
10535 -- fold it to a constant. Obviously we only apply a scalar
10536 -- range check if this did not happen.
10538 if Nkind
(N
) = N_Attribute_Reference
10539 and then Attribute_Name
(N
) = Name_Val
10541 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
10550 -- Prefix of Version attribute can be a subprogram name which
10551 -- must not be resolved, since this is not a call.
10553 when Attribute_Version
=>
10556 ----------------------
10557 -- Other Attributes --
10558 ----------------------
10560 -- For other attributes, resolve prefix unless it is a type. If
10561 -- the attribute reference itself is a type name ('Base and 'Class)
10562 -- then this is only legal within a task or protected record.
10565 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
10569 -- If the attribute reference itself is a type name ('Base,
10570 -- 'Class) then this is only legal within a task or protected
10571 -- record. What is this all about ???
10573 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
10574 if Is_Concurrent_Type
(Entity
(N
))
10575 and then In_Open_Scopes
(Entity
(P
))
10580 ("invalid use of subtype name in expression or call", N
);
10584 -- For attributes whose argument may be a string, complete
10585 -- resolution of argument now. This avoids premature expansion
10586 -- (and the creation of transient scopes) before the attribute
10587 -- reference is resolved.
10590 when Attribute_Value
=>
10591 Resolve
(First
(Expressions
(N
)), Standard_String
);
10593 when Attribute_Wide_Value
=>
10594 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
10596 when Attribute_Wide_Wide_Value
=>
10597 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
10599 when others => null;
10602 -- If the prefix of the attribute is a class-wide type then it
10603 -- will be expanded into a dispatching call to a predefined
10604 -- primitive. Therefore we must check for potential violation
10605 -- of such restriction.
10607 if Is_Class_Wide_Type
(Etype
(P
)) then
10608 Check_Restriction
(No_Dispatching_Calls
, N
);
10612 -- Normally the Freezing is done by Resolve but sometimes the Prefix
10613 -- is not resolved, in which case the freezing must be done now.
10615 Freeze_Expression
(P
);
10617 -- Finally perform static evaluation on the attribute reference
10619 Analyze_Dimension
(N
);
10620 Eval_Attribute
(N
);
10621 end Resolve_Attribute
;
10623 ------------------------
10624 -- Set_Boolean_Result --
10625 ------------------------
10627 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
10628 Loc
: constant Source_Ptr
:= Sloc
(N
);
10632 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
10634 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
10637 Set_Is_Static_Expression
(N
);
10638 end Set_Boolean_Result
;
10640 --------------------------------
10641 -- Stream_Attribute_Available --
10642 --------------------------------
10644 function Stream_Attribute_Available
10646 Nam
: TSS_Name_Type
;
10647 Partial_View
: Node_Id
:= Empty
) return Boolean
10649 Etyp
: Entity_Id
:= Typ
;
10651 -- Start of processing for Stream_Attribute_Available
10654 -- We need some comments in this body ???
10656 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
10660 if Is_Class_Wide_Type
(Typ
) then
10661 return not Is_Limited_Type
(Typ
)
10662 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
10665 if Nam
= TSS_Stream_Input
10666 and then Is_Abstract_Type
(Typ
)
10667 and then not Is_Class_Wide_Type
(Typ
)
10672 if not (Is_Limited_Type
(Typ
)
10673 or else (Present
(Partial_View
)
10674 and then Is_Limited_Type
(Partial_View
)))
10679 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
10681 if Nam
= TSS_Stream_Input
10682 and then Ada_Version
>= Ada_2005
10683 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
10687 elsif Nam
= TSS_Stream_Output
10688 and then Ada_Version
>= Ada_2005
10689 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
10694 -- Case of Read and Write: check for attribute definition clause that
10695 -- applies to an ancestor type.
10697 while Etype
(Etyp
) /= Etyp
loop
10698 Etyp
:= Etype
(Etyp
);
10700 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
10705 if Ada_Version
< Ada_2005
then
10707 -- In Ada 95 mode, also consider a non-visible definition
10710 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
10713 and then Stream_Attribute_Available
10714 (Btyp
, Nam
, Partial_View
=> Typ
);
10719 end Stream_Attribute_Available
;