1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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_Prag
; use Sem_Prag
;
63 with Sem_Res
; use Sem_Res
;
64 with Sem_Type
; use Sem_Type
;
65 with Sem_Util
; use Sem_Util
;
67 with Stand
; use Stand
;
68 with Sinfo
; use Sinfo
;
69 with Sinput
; use Sinput
;
71 with Stringt
; use Stringt
;
73 with Stylesw
; use Stylesw
;
74 with Targparm
; use Targparm
;
75 with Ttypes
; use Ttypes
;
76 with Tbuild
; use Tbuild
;
77 with Uintp
; use Uintp
;
78 with Uname
; use Uname
;
79 with Urealp
; use Urealp
;
81 with System
.CRC32
; use System
.CRC32
;
83 package body Sem_Attr
is
85 True_Value
: constant Uint
:= Uint_1
;
86 False_Value
: constant Uint
:= Uint_0
;
87 -- Synonyms to be used when these constants are used as Boolean values
89 Bad_Attribute
: exception;
90 -- Exception raised if an error is detected during attribute processing,
91 -- used so that we can abandon the processing so we don't run into
92 -- trouble with cascaded errors.
94 -- The following array is the list of attributes defined in the Ada 83 RM.
95 -- In Ada 83 mode, these are the only recognized attributes. In other Ada
96 -- modes all these attributes are recognized, even if removed in Ada 95.
98 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
101 Attribute_Alignment |
104 Attribute_Constrained |
111 Attribute_First_Bit |
117 Attribute_Leading_Part |
119 Attribute_Machine_Emax |
120 Attribute_Machine_Emin |
121 Attribute_Machine_Mantissa |
122 Attribute_Machine_Overflows |
123 Attribute_Machine_Radix |
124 Attribute_Machine_Rounds |
130 Attribute_Safe_Emax |
131 Attribute_Safe_Large |
132 Attribute_Safe_Small |
135 Attribute_Storage_Size |
137 Attribute_Terminated |
140 Attribute_Width => True,
143 -- The following array is the list of attributes defined in the Ada 2005
144 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
145 -- but in Ada 95 they are considered to be implementation defined.
147 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
148 Attribute_Machine_Rounding |
151 Attribute_Stream_Size |
152 Attribute_Wide_Wide_Width
=> True,
155 -- The following array is the list of attributes defined in the Ada 2012
156 -- RM which are not defined in Ada 2005. These are recognized in Ada 95
157 -- and Ada 2005 modes, but are considered to be implementation defined.
159 Attribute_12
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
160 Attribute_First_Valid |
161 Attribute_Has_Same_Storage |
162 Attribute_Last_Valid |
163 Attribute_Max_Alignment_For_Allocation => True,
166 -- The following array contains all attributes that imply a modification
167 -- of their prefixes or result in an access value. Such prefixes can be
168 -- considered as lvalues.
170 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
171 Attribute_Class_Array'(
176 Attribute_Unchecked_Access |
177 Attribute_Unrestricted_Access
=> True,
180 -----------------------
181 -- Local_Subprograms --
182 -----------------------
184 procedure Eval_Attribute
(N
: Node_Id
);
185 -- Performs compile time evaluation of attributes where possible, leaving
186 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
187 -- set, and replacing the node with a literal node if the value can be
188 -- computed at compile time. All static attribute references are folded,
189 -- as well as a number of cases of non-static attributes that can always
190 -- be computed at compile time (e.g. floating-point model attributes that
191 -- are applied to non-static subtypes). Of course in such cases, the
192 -- Is_Static_Expression flag will not be set on the resulting literal.
193 -- Note that the only required action of this procedure is to catch the
194 -- static expression cases as described in the RM. Folding of other cases
195 -- is done where convenient, but some additional non-static folding is in
196 -- Expand_N_Attribute_Reference in cases where this is more convenient.
198 function Is_Anonymous_Tagged_Base
200 Typ
: Entity_Id
) return Boolean;
201 -- For derived tagged types that constrain parent discriminants we build
202 -- an anonymous unconstrained base type. We need to recognize the relation
203 -- between the two when analyzing an access attribute for a constrained
204 -- component, before the full declaration for Typ has been analyzed, and
205 -- where therefore the prefix of the attribute does not match the enclosing
208 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean);
209 -- Rewrites node N with an occurrence of either Standard_False or
210 -- Standard_True, depending on the value of the parameter B. The
211 -- result is marked as a static expression.
213 -----------------------
214 -- Analyze_Attribute --
215 -----------------------
217 procedure Analyze_Attribute
(N
: Node_Id
) is
218 Loc
: constant Source_Ptr
:= Sloc
(N
);
219 Aname
: constant Name_Id
:= Attribute_Name
(N
);
220 P
: constant Node_Id
:= Prefix
(N
);
221 Exprs
: constant List_Id
:= Expressions
(N
);
222 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
227 -- Type of prefix after analysis
229 P_Base_Type
: Entity_Id
;
230 -- Base type of prefix after analysis
232 -----------------------
233 -- Local Subprograms --
234 -----------------------
236 procedure Address_Checks
;
237 -- Semantic checks for valid use of Address attribute. This was made
238 -- a separate routine with the idea of using it for unrestricted access
239 -- which seems like it should follow the same rules, but that turned
240 -- out to be impractical. So now this is only used for Address.
242 procedure Analyze_Access_Attribute
;
243 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
244 -- Internally, Id distinguishes which of the three cases is involved.
246 procedure Analyze_Attribute_Old_Result
247 (Legal
: out Boolean;
248 Spec_Id
: out Entity_Id
);
249 -- Common processing for attributes 'Old and 'Result. The routine checks
250 -- that the attribute appears in a postcondition-like aspect or pragma
251 -- associated with a suitable subprogram or a body. Flag Legal is set
252 -- when the above criteria are met. Spec_Id denotes the entity of the
253 -- subprogram [body] or Empty if the attribute is illegal.
255 procedure Bad_Attribute_For_Predicate
;
256 -- Output error message for use of a predicate (First, Last, Range) not
257 -- allowed with a type that has predicates. If the type is a generic
258 -- actual, then the message is a warning, and we generate code to raise
259 -- program error with an appropriate reason. No error message is given
260 -- for internally generated uses of the attributes. This legality rule
261 -- only applies to scalar types.
263 procedure Check_Array_Or_Scalar_Type
;
264 -- Common procedure used by First, Last, Range attribute to check
265 -- that the prefix is a constrained array or scalar type, or a name
266 -- of an array object, and that an argument appears only if appropriate
267 -- (i.e. only in the array case).
269 procedure Check_Array_Type
;
270 -- Common semantic checks for all array attributes. Checks that the
271 -- prefix is a constrained array type or the name of an array object.
272 -- The error message for non-arrays is specialized appropriately.
274 procedure Check_Asm_Attribute
;
275 -- Common semantic checks for Asm_Input and Asm_Output attributes
277 procedure Check_Component
;
278 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
279 -- Position. Checks prefix is an appropriate selected component.
281 procedure Check_Decimal_Fixed_Point_Type
;
282 -- Check that prefix of attribute N is a decimal fixed-point type
284 procedure Check_Dereference
;
285 -- If the prefix of attribute is an object of an access type, then
286 -- introduce an explicit dereference, and adjust P_Type accordingly.
288 procedure Check_Discrete_Type
;
289 -- Verify that prefix of attribute N is a discrete type
292 -- Check that no attribute arguments are present
294 procedure Check_Either_E0_Or_E1
;
295 -- Check that there are zero or one attribute arguments present
298 -- Check that exactly one attribute argument is present
301 -- Check that two attribute arguments are present
303 procedure Check_Enum_Image
;
304 -- If the prefix type of 'Image is an enumeration type, set all its
305 -- literals as referenced, since the image function could possibly end
306 -- up referencing any of the literals indirectly. Same for Enum_Val.
307 -- Set the flag only if the reference is in the main code unit. Same
308 -- restriction when resolving 'Value; otherwise an improperly set
309 -- reference when analyzing an inlined body will lose a proper
310 -- warning on a useless with_clause.
312 procedure Check_First_Last_Valid
;
313 -- Perform all checks for First_Valid and Last_Valid attributes
315 procedure Check_Fixed_Point_Type
;
316 -- Verify that prefix of attribute N is a fixed type
318 procedure Check_Fixed_Point_Type_0
;
319 -- Verify that prefix of attribute N is a fixed type and that
320 -- no attribute expressions are present
322 procedure Check_Floating_Point_Type
;
323 -- Verify that prefix of attribute N is a float type
325 procedure Check_Floating_Point_Type_0
;
326 -- Verify that prefix of attribute N is a float type and that
327 -- no attribute expressions are present
329 procedure Check_Floating_Point_Type_1
;
330 -- Verify that prefix of attribute N is a float type and that
331 -- exactly one attribute expression is present
333 procedure Check_Floating_Point_Type_2
;
334 -- Verify that prefix of attribute N is a float type and that
335 -- two attribute expressions are present
337 procedure Check_SPARK_05_Restriction_On_Attribute
;
338 -- Issue an error in formal mode because attribute N is allowed
340 procedure Check_Integer_Type
;
341 -- Verify that prefix of attribute N is an integer type
343 procedure Check_Modular_Integer_Type
;
344 -- Verify that prefix of attribute N is a modular integer type
346 procedure Check_Not_CPP_Type
;
347 -- Check that P (the prefix of the attribute) is not an CPP type
348 -- for which no Ada predefined primitive is available.
350 procedure Check_Not_Incomplete_Type
;
351 -- Check that P (the prefix of the attribute) is not an incomplete
352 -- type or a private type for which no full view has been given.
354 procedure Check_Object_Reference
(P
: Node_Id
);
355 -- Check that P is an object reference
357 procedure Check_PolyORB_Attribute
;
358 -- Validity checking for PolyORB/DSA attribute
360 procedure Check_Program_Unit
;
361 -- Verify that prefix of attribute N is a program unit
363 procedure Check_Real_Type
;
364 -- Verify that prefix of attribute N is fixed or float type
366 procedure Check_Scalar_Type
;
367 -- Verify that prefix of attribute N is a scalar type
369 procedure Check_Standard_Prefix
;
370 -- Verify that prefix of attribute N is package Standard. Also checks
371 -- that there are no arguments.
373 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
);
374 -- Validity checking for stream attribute. Nam is the TSS name of the
375 -- corresponding possible defined attribute function (e.g. for the
376 -- Read attribute, Nam will be TSS_Stream_Read).
378 procedure Check_System_Prefix
;
379 -- Verify that prefix of attribute N is package System
381 procedure Check_Task_Prefix
;
382 -- Verify that prefix of attribute N is a task or task type
384 procedure Check_Type
;
385 -- Verify that the prefix of attribute N is a type
387 procedure Check_Unit_Name
(Nod
: Node_Id
);
388 -- Check that Nod is of the form of a library unit name, i.e that
389 -- it is an identifier, or a selected component whose prefix is
390 -- itself of the form of a library unit name. Note that this is
391 -- quite different from Check_Program_Unit, since it only checks
392 -- the syntactic form of the name, not the semantic identity. This
393 -- is because it is used with attributes (Elab_Body, Elab_Spec and
394 -- Elaborated) which can refer to non-visible unit.
396 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
);
397 pragma No_Return
(Error_Attr
);
398 procedure Error_Attr
;
399 pragma No_Return
(Error_Attr
);
400 -- Posts error using Error_Msg_N at given node, sets type of attribute
401 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
402 -- semantic processing. The message typically contains a % insertion
403 -- character which is replaced by the attribute name. The call with
404 -- no arguments is used when the caller has already generated the
405 -- required error messages.
407 procedure Error_Attr_P
(Msg
: String);
408 pragma No_Return
(Error_Attr
);
409 -- Like Error_Attr, but error is posted at the start of the prefix
411 procedure Legal_Formal_Attribute
;
412 -- Common processing for attributes Definite and Has_Discriminants.
413 -- Checks that prefix is generic indefinite formal type.
415 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
416 -- Common processing for attributes Max_Alignment_For_Allocation and
417 -- Max_Size_In_Storage_Elements.
420 -- Common processing for attributes Max and Min
422 procedure Standard_Attribute
(Val
: Int
);
423 -- Used to process attributes whose prefix is package Standard which
424 -- yield values of type Universal_Integer. The attribute reference
425 -- node is rewritten with an integer literal of the given value which
426 -- is marked as static.
428 procedure Uneval_Old_Msg
;
429 -- Called when Loop_Entry or Old is used in a potentially unevaluated
430 -- expression. Generates appropriate message or warning depending on
431 -- the setting of Opt.Uneval_Old (or flags in an N_Aspect_Specification
432 -- node in the aspect case).
434 procedure Unexpected_Argument
(En
: Node_Id
);
435 -- Signal unexpected attribute argument (En is the argument)
437 procedure Validate_Non_Static_Attribute_Function_Call
;
438 -- Called when processing an attribute that is a function call to a
439 -- non-static function, i.e. an attribute function that either takes
440 -- non-scalar arguments or returns a non-scalar result. Verifies that
441 -- such a call does not appear in a preelaborable context.
447 procedure Address_Checks
is
449 -- An Address attribute created by expansion is legal even when it
450 -- applies to other entity-denoting expressions.
452 if not Comes_From_Source
(N
) then
455 -- Address attribute on a protected object self reference is legal
457 elsif Is_Protected_Self_Reference
(P
) then
460 -- Address applied to an entity
462 elsif Is_Entity_Name
(P
) then
464 Ent
: constant Entity_Id
:= Entity
(P
);
467 if Is_Subprogram
(Ent
) then
468 Set_Address_Taken
(Ent
);
469 Kill_Current_Values
(Ent
);
471 -- An Address attribute is accepted when generated by the
472 -- compiler for dispatching operation, and an error is
473 -- issued once the subprogram is frozen (to avoid confusing
474 -- errors about implicit uses of Address in the dispatch
475 -- table initialization).
477 if Has_Pragma_Inline_Always
(Entity
(P
))
478 and then Comes_From_Source
(P
)
481 ("prefix of % attribute cannot be Inline_Always "
484 -- It is illegal to apply 'Address to an intrinsic
485 -- subprogram. This is now formalized in AI05-0095.
486 -- In an instance, an attempt to obtain 'Address of an
487 -- intrinsic subprogram (e.g the renaming of a predefined
488 -- operator that is an actual) raises Program_Error.
490 elsif Convention
(Ent
) = Convention_Intrinsic
then
493 Make_Raise_Program_Error
(Loc
,
494 Reason
=> PE_Address_Of_Intrinsic
));
497 Error_Msg_Name_1
:= Aname
;
499 ("cannot take % of intrinsic subprogram", N
);
502 -- Issue an error if prefix denotes an eliminated subprogram
505 Check_For_Eliminated_Subprogram
(P
, Ent
);
508 -- Object or label reference
510 elsif Is_Object
(Ent
) or else Ekind
(Ent
) = E_Label
then
511 Set_Address_Taken
(Ent
);
513 -- Deal with No_Implicit_Aliasing restriction
515 if Restriction_Check_Required
(No_Implicit_Aliasing
) then
516 if not Is_Aliased_View
(P
) then
517 Check_Restriction
(No_Implicit_Aliasing
, P
);
519 Check_No_Implicit_Aliasing
(P
);
523 -- If we have an address of an object, and the attribute
524 -- comes from source, then set the object as potentially
525 -- source modified. We do this because the resulting address
526 -- can potentially be used to modify the variable and we
527 -- might not detect this, leading to some junk warnings.
529 Set_Never_Set_In_Source
(Ent
, False);
531 -- Allow Address to be applied to task or protected type,
532 -- returning null address (what is that about???)
534 elsif (Is_Concurrent_Type
(Etype
(Ent
))
535 and then Etype
(Ent
) = Base_Type
(Ent
))
536 or else Ekind
(Ent
) = E_Package
537 or else Is_Generic_Unit
(Ent
)
540 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
542 -- Anything else is illegal
545 Error_Attr
("invalid prefix for % attribute", P
);
551 elsif Is_Object_Reference
(P
) then
554 -- Subprogram called using dot notation
556 elsif Nkind
(P
) = N_Selected_Component
557 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
561 -- What exactly are we allowing here ??? and is this properly
562 -- documented in the sinfo documentation for this node ???
564 elsif Relaxed_RM_Semantics
565 and then Nkind
(P
) = N_Attribute_Reference
569 -- All other non-entity name cases are illegal
572 Error_Attr
("invalid prefix for % attribute", P
);
576 ------------------------------
577 -- Analyze_Access_Attribute --
578 ------------------------------
580 procedure Analyze_Access_Attribute
is
581 Acc_Type
: Entity_Id
;
586 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
;
587 -- Build an access-to-object type whose designated type is DT,
588 -- and whose Ekind is appropriate to the attribute type. The
589 -- type that is constructed is returned as the result.
591 procedure Build_Access_Subprogram_Type
(P
: Node_Id
);
592 -- Build an access to subprogram whose designated type is the type of
593 -- the prefix. If prefix is overloaded, so is the node itself. The
594 -- result is stored in Acc_Type.
596 function OK_Self_Reference
return Boolean;
597 -- An access reference whose prefix is a type can legally appear
598 -- within an aggregate, where it is obtained by expansion of
599 -- a defaulted aggregate. The enclosing aggregate that contains
600 -- the self-referenced is flagged so that the self-reference can
601 -- be expanded into a reference to the target object (see exp_aggr).
603 ------------------------------
604 -- Build_Access_Object_Type --
605 ------------------------------
607 function Build_Access_Object_Type
(DT
: Entity_Id
) return Entity_Id
is
608 Typ
: constant Entity_Id
:=
610 (E_Access_Attribute_Type
, Current_Scope
, Loc
, 'A');
612 Set_Etype
(Typ
, Typ
);
614 Set_Associated_Node_For_Itype
(Typ
, N
);
615 Set_Directly_Designated_Type
(Typ
, DT
);
617 end Build_Access_Object_Type
;
619 ----------------------------------
620 -- Build_Access_Subprogram_Type --
621 ----------------------------------
623 procedure Build_Access_Subprogram_Type
(P
: Node_Id
) is
624 Index
: Interp_Index
;
627 procedure Check_Local_Access
(E
: Entity_Id
);
628 -- Deal with possible access to local subprogram. If we have such
629 -- an access, we set a flag to kill all tracked values on any call
630 -- because this access value may be passed around, and any called
631 -- code might use it to access a local procedure which clobbers a
632 -- tracked value. If the scope is a loop or block, indicate that
633 -- value tracking is disabled for the enclosing subprogram.
635 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
;
636 -- Distinguish between access to regular/protected subprograms
638 ------------------------
639 -- Check_Local_Access --
640 ------------------------
642 procedure Check_Local_Access
(E
: Entity_Id
) is
644 if not Is_Library_Level_Entity
(E
) then
645 Set_Suppress_Value_Tracking_On_Call
(Current_Scope
);
646 Set_Suppress_Value_Tracking_On_Call
647 (Nearest_Dynamic_Scope
(Current_Scope
));
649 end Check_Local_Access
;
655 function Get_Kind
(E
: Entity_Id
) return Entity_Kind
is
657 if Convention
(E
) = Convention_Protected
then
658 return E_Access_Protected_Subprogram_Type
;
660 return E_Access_Subprogram_Type
;
664 -- Start of processing for Build_Access_Subprogram_Type
667 -- In the case of an access to subprogram, use the name of the
668 -- subprogram itself as the designated type. Type-checking in
669 -- this case compares the signatures of the designated types.
671 -- Note: This fragment of the tree is temporarily malformed
672 -- because the correct tree requires an E_Subprogram_Type entity
673 -- as the designated type. In most cases this designated type is
674 -- later overridden by the semantics with the type imposed by the
675 -- context during the resolution phase. In the specific case of
676 -- the expression Address!(Prim'Unrestricted_Access), used to
677 -- initialize slots of dispatch tables, this work will be done by
678 -- the expander (see Exp_Aggr).
680 -- The reason to temporarily add this kind of node to the tree
681 -- instead of a proper E_Subprogram_Type itype, is the following:
682 -- in case of errors found in the source file we report better
683 -- error messages. For example, instead of generating the
686 -- "expected access to subprogram with profile
687 -- defined at line X"
689 -- we currently generate:
691 -- "expected access to function Z defined at line X"
693 Set_Etype
(N
, Any_Type
);
695 if not Is_Overloaded
(P
) then
696 Check_Local_Access
(Entity
(P
));
698 if not Is_Intrinsic_Subprogram
(Entity
(P
)) then
699 Acc_Type
:= Create_Itype
(Get_Kind
(Entity
(P
)), N
);
700 Set_Is_Public
(Acc_Type
, False);
701 Set_Etype
(Acc_Type
, Acc_Type
);
702 Set_Convention
(Acc_Type
, Convention
(Entity
(P
)));
703 Set_Directly_Designated_Type
(Acc_Type
, Entity
(P
));
704 Set_Etype
(N
, Acc_Type
);
705 Freeze_Before
(N
, Acc_Type
);
709 Get_First_Interp
(P
, Index
, It
);
710 while Present
(It
.Nam
) loop
711 Check_Local_Access
(It
.Nam
);
713 if not Is_Intrinsic_Subprogram
(It
.Nam
) then
714 Acc_Type
:= Create_Itype
(Get_Kind
(It
.Nam
), N
);
715 Set_Is_Public
(Acc_Type
, False);
716 Set_Etype
(Acc_Type
, Acc_Type
);
717 Set_Convention
(Acc_Type
, Convention
(It
.Nam
));
718 Set_Directly_Designated_Type
(Acc_Type
, It
.Nam
);
719 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
720 Freeze_Before
(N
, Acc_Type
);
723 Get_Next_Interp
(Index
, It
);
727 -- Cannot be applied to intrinsic. Looking at the tests above,
728 -- the only way Etype (N) can still be set to Any_Type is if
729 -- Is_Intrinsic_Subprogram was True for some referenced entity.
731 if Etype
(N
) = Any_Type
then
732 Error_Attr_P
("prefix of % attribute cannot be intrinsic");
734 end Build_Access_Subprogram_Type
;
736 ----------------------
737 -- OK_Self_Reference --
738 ----------------------
740 function OK_Self_Reference
return Boolean is
747 (Nkind
(Par
) = N_Component_Association
748 or else Nkind
(Par
) in N_Subexpr
)
750 if Nkind_In
(Par
, N_Aggregate
, N_Extension_Aggregate
) then
751 if Etype
(Par
) = Typ
then
752 Set_Has_Self_Reference
(Par
);
754 -- Check the context: the aggregate must be part of the
755 -- initialization of a type or component, or it is the
756 -- resulting expansion in an initialization procedure.
758 if Is_Init_Proc
(Current_Scope
) then
762 while Present
(Par
) loop
763 if Nkind
(Par
) = N_Full_Type_Declaration
then
778 -- No enclosing aggregate, or not a self-reference
781 end OK_Self_Reference
;
783 -- Start of processing for Analyze_Access_Attribute
786 Check_SPARK_05_Restriction_On_Attribute
;
789 if Nkind
(P
) = N_Character_Literal
then
791 ("prefix of % attribute cannot be enumeration literal");
794 -- Case of access to subprogram
796 if Is_Entity_Name
(P
) and then Is_Overloadable
(Entity
(P
)) then
797 if Has_Pragma_Inline_Always
(Entity
(P
)) then
799 ("prefix of % attribute cannot be Inline_Always subprogram");
801 elsif Aname
= Name_Unchecked_Access
then
802 Error_Attr
("attribute% cannot be applied to a subprogram", P
);
805 -- Issue an error if the prefix denotes an eliminated subprogram
807 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
809 -- Check for obsolescent subprogram reference
811 Check_Obsolescent_2005_Entity
(Entity
(P
), P
);
813 -- Build the appropriate subprogram type
815 Build_Access_Subprogram_Type
(P
);
817 -- For P'Access or P'Unrestricted_Access, where P is a nested
818 -- subprogram, we might be passing P to another subprogram (but we
819 -- don't check that here), which might call P. P could modify
820 -- local variables, so we need to kill current values. It is
821 -- important not to do this for library-level subprograms, because
822 -- Kill_Current_Values is very inefficient in the case of library
823 -- level packages with lots of tagged types.
825 if Is_Library_Level_Entity
(Entity
(Prefix
(N
))) then
828 -- Do not kill values on nodes initializing dispatch tables
829 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
830 -- is currently generated by the expander only for this
831 -- purpose. Done to keep the quality of warnings currently
832 -- generated by the compiler (otherwise any declaration of
833 -- a tagged type cleans constant indications from its scope).
835 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
836 and then (Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
838 Etype
(Parent
(N
)) = RTE
(RE_Size_Ptr
))
839 and then Is_Dispatching_Operation
840 (Directly_Designated_Type
(Etype
(N
)))
848 -- In the static elaboration model, treat the attribute reference
849 -- as a call for elaboration purposes. Suppress this treatment
850 -- under debug flag. In any case, we are all done.
852 if not Dynamic_Elaboration_Checks
and not Debug_Flag_Dot_UU
then
858 -- Component is an operation of a protected type
860 elsif Nkind
(P
) = N_Selected_Component
861 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
863 if Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
then
864 Error_Attr_P
("prefix of % attribute must be subprogram");
867 Build_Access_Subprogram_Type
(Selector_Name
(P
));
871 -- Deal with incorrect reference to a type, but note that some
872 -- accesses are allowed: references to the current type instance,
873 -- or in Ada 2005 self-referential pointer in a default-initialized
876 if Is_Entity_Name
(P
) then
879 -- The reference may appear in an aggregate that has been expanded
880 -- into a loop. Locate scope of type definition, if any.
882 Scop
:= Current_Scope
;
883 while Ekind
(Scop
) = E_Loop
loop
884 Scop
:= Scope
(Scop
);
887 if Is_Type
(Typ
) then
889 -- OK if we are within the scope of a limited type
890 -- let's mark the component as having per object constraint
892 if Is_Anonymous_Tagged_Base
(Scop
, Typ
) then
900 Q
: Node_Id
:= Parent
(N
);
904 and then Nkind
(Q
) /= N_Component_Declaration
910 Set_Has_Per_Object_Constraint
911 (Defining_Identifier
(Q
), True);
915 if Nkind
(P
) = N_Expanded_Name
then
917 ("current instance prefix must be a direct name", P
);
920 -- If a current instance attribute appears in a component
921 -- constraint it must appear alone; other contexts (spec-
922 -- expressions, within a task body) are not subject to this
925 if not In_Spec_Expression
926 and then not Has_Completion
(Scop
)
928 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
929 N_Index_Or_Discriminant_Constraint
)
932 ("current instance attribute must appear alone", N
);
935 if Is_CPP_Class
(Root_Type
(Typ
)) then
937 ("??current instance unsupported for derivations of "
938 & "'C'P'P types", N
);
941 -- OK if we are in initialization procedure for the type
942 -- in question, in which case the reference to the type
943 -- is rewritten as a reference to the current object.
945 elsif Ekind
(Scop
) = E_Procedure
946 and then Is_Init_Proc
(Scop
)
947 and then Etype
(First_Formal
(Scop
)) = Typ
950 Make_Attribute_Reference
(Loc
,
951 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
952 Attribute_Name
=> Name_Unrestricted_Access
));
956 -- OK if a task type, this test needs sharpening up ???
958 elsif Is_Task_Type
(Typ
) then
961 -- OK if self-reference in an aggregate in Ada 2005, and
962 -- the reference comes from a copied default expression.
964 -- Note that we check legality of self-reference even if the
965 -- expression comes from source, e.g. when a single component
966 -- association in an aggregate has a box association.
968 elsif Ada_Version
>= Ada_2005
969 and then OK_Self_Reference
973 -- OK if reference to current instance of a protected object
975 elsif Is_Protected_Self_Reference
(P
) then
978 -- Otherwise we have an error case
981 Error_Attr
("% attribute cannot be applied to type", P
);
987 -- If we fall through, we have a normal access to object case
989 -- Unrestricted_Access is (for now) legal wherever an allocator would
990 -- be legal, so its Etype is set to E_Allocator. The expected type
991 -- of the other attributes is a general access type, and therefore
992 -- we label them with E_Access_Attribute_Type.
994 if not Is_Overloaded
(P
) then
995 Acc_Type
:= Build_Access_Object_Type
(P_Type
);
996 Set_Etype
(N
, Acc_Type
);
1000 Index
: Interp_Index
;
1003 Set_Etype
(N
, Any_Type
);
1004 Get_First_Interp
(P
, Index
, It
);
1005 while Present
(It
.Typ
) loop
1006 Acc_Type
:= Build_Access_Object_Type
(It
.Typ
);
1007 Add_One_Interp
(N
, Acc_Type
, Acc_Type
);
1008 Get_Next_Interp
(Index
, It
);
1013 -- Special cases when we can find a prefix that is an entity name
1022 if Is_Entity_Name
(PP
) then
1025 -- If we have an access to an object, and the attribute
1026 -- comes from source, then set the object as potentially
1027 -- source modified. We do this because the resulting access
1028 -- pointer can be used to modify the variable, and we might
1029 -- not detect this, leading to some junk warnings.
1031 -- We only do this for source references, since otherwise
1032 -- we can suppress warnings, e.g. from the unrestricted
1033 -- access generated for validity checks in -gnatVa mode.
1035 if Comes_From_Source
(N
) then
1036 Set_Never_Set_In_Source
(Ent
, False);
1039 -- Mark entity as address taken, and kill current values
1041 Set_Address_Taken
(Ent
);
1042 Kill_Current_Values
(Ent
);
1045 elsif Nkind_In
(PP
, N_Selected_Component
,
1046 N_Indexed_Component
)
1056 -- Check for aliased view.. We allow a nonaliased prefix when within
1057 -- an instance because the prefix may have been a tagged formal
1058 -- object, which is defined to be aliased even when the actual
1059 -- might not be (other instance cases will have been caught in the
1060 -- generic). Similarly, within an inlined body we know that the
1061 -- attribute is legal in the original subprogram, and therefore
1062 -- legal in the expansion.
1064 if not Is_Aliased_View
(P
)
1065 and then not In_Instance
1066 and then not In_Inlined_Body
1067 and then Comes_From_Source
(N
)
1069 -- Here we have a non-aliased view. This is illegal unless we
1070 -- have the case of Unrestricted_Access, where for now we allow
1071 -- this (we will reject later if expected type is access to an
1072 -- unconstrained array with a thin pointer).
1074 -- No need for an error message on a generated access reference
1075 -- for the controlling argument in a dispatching call: error will
1076 -- be reported when resolving the call.
1078 if Aname
/= Name_Unrestricted_Access
then
1079 Error_Attr_P
("prefix of % attribute must be aliased");
1080 Check_No_Implicit_Aliasing
(P
);
1082 -- For Unrestricted_Access, record that prefix is not aliased
1083 -- to simplify legality check later on.
1086 Set_Non_Aliased_Prefix
(N
);
1089 -- If we have an aliased view, and we have Unrestricted_Access, then
1090 -- output a warning that Unchecked_Access would have been fine, and
1091 -- change the node to be Unchecked_Access.
1094 -- For now, hold off on this change ???
1098 end Analyze_Access_Attribute
;
1100 ----------------------------------
1101 -- Analyze_Attribute_Old_Result --
1102 ----------------------------------
1104 procedure Analyze_Attribute_Old_Result
1105 (Legal
: out Boolean;
1106 Spec_Id
: out Entity_Id
)
1108 procedure Check_Placement_In_Check
(Prag
: Node_Id
);
1109 -- Verify that the attribute appears within pragma Check that mimics
1112 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
);
1113 -- Verify that the attribute appears within a consequence of aspect
1114 -- or pragma Contract_Cases denoted by Prag.
1116 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
);
1117 -- Verify that the attribute appears within the "Ensures" argument of
1118 -- aspect or pragma Test_Case denoted by Prag.
1122 Encl_Nod
: Node_Id
) return Boolean;
1123 -- Subsidiary to Check_Placemenet_In_XXX. Determine whether arbitrary
1124 -- node Nod is within enclosing node Encl_Nod.
1126 procedure Placement_Error
;
1127 -- Emit a general error when the attributes does not appear in a
1128 -- postcondition-like aspect or pragma.
1130 ------------------------------
1131 -- Check_Placement_In_Check --
1132 ------------------------------
1134 procedure Check_Placement_In_Check
(Prag
: Node_Id
) is
1135 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
1136 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(Args
)));
1139 -- The "Name" argument of pragma Check denotes a postcondition
1141 if Nam_In
(Nam
, Name_Post
,
1148 -- Otherwise the placement of the attribute is illegal
1153 end Check_Placement_In_Check
;
1155 ---------------------------------------
1156 -- Check_Placement_In_Contract_Cases --
1157 ---------------------------------------
1159 procedure Check_Placement_In_Contract_Cases
(Prag
: Node_Id
) is
1165 -- Obtain the argument of the aspect or pragma
1167 if Nkind
(Prag
) = N_Aspect_Specification
then
1170 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
1173 Cases
:= Expression
(Arg
);
1175 if Present
(Component_Associations
(Cases
)) then
1176 CCase
:= First
(Component_Associations
(Cases
));
1177 while Present
(CCase
) loop
1179 -- Detect whether the attribute appears within the
1180 -- consequence of the current contract case.
1182 if Nkind
(CCase
) = N_Component_Association
1183 and then Is_Within
(N
, Expression
(CCase
))
1192 -- Otherwise aspect or pragma Contract_Cases is either malformed
1193 -- or the attribute does not appear within a consequence.
1196 ("attribute % must appear in the consequence of a contract case",
1198 end Check_Placement_In_Contract_Cases
;
1200 ----------------------------------
1201 -- Check_Placement_In_Test_Case --
1202 ----------------------------------
1204 procedure Check_Placement_In_Test_Case
(Prag
: Node_Id
) is
1205 Arg
: constant Node_Id
:=
1208 Arg_Nam
=> Name_Ensures
,
1209 From_Aspect
=> Nkind
(Prag
) = N_Aspect_Specification
);
1212 -- Detect whether the attribute appears within the "Ensures"
1213 -- expression of aspect or pragma Test_Case.
1215 if Present
(Arg
) and then Is_Within
(N
, Arg
) then
1220 ("attribute % must appear in the ensures expression of a "
1223 end Check_Placement_In_Test_Case
;
1231 Encl_Nod
: Node_Id
) return Boolean
1237 while Present
(Par
) loop
1238 if Par
= Encl_Nod
then
1241 -- Prevent the search from going too far
1243 elsif Is_Body_Or_Package_Declaration
(Par
) then
1247 Par
:= Parent
(Par
);
1253 ---------------------
1254 -- Placement_Error --
1255 ---------------------
1257 procedure Placement_Error
is
1259 if Aname
= Name_Old
then
1260 Error_Attr
("attribute % can only appear in postcondition", P
);
1262 -- Specialize the error message for attribute 'Result
1266 ("attribute % can only appear in postcondition of function",
1269 end Placement_Error
;
1275 Subp_Decl
: Node_Id
;
1277 -- Start of processing for Analyze_Attribute_Old_Result
1280 -- Assume that the attribute is illegal
1285 -- Traverse the parent chain to find the aspect or pragma where the
1286 -- attribute resides.
1289 while Present
(Prag
) loop
1290 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1293 -- Prevent the search from going too far
1295 elsif Is_Body_Or_Package_Declaration
(Prag
) then
1299 Prag
:= Parent
(Prag
);
1302 -- The attribute is allowed to appear only in postcondition-like
1303 -- aspects or pragmas.
1305 if Nkind_In
(Prag
, N_Aspect_Specification
, N_Pragma
) then
1306 if Nkind
(Prag
) = N_Aspect_Specification
then
1307 Prag_Nam
:= Chars
(Identifier
(Prag
));
1309 Prag_Nam
:= Pragma_Name
(Prag
);
1312 if Prag_Nam
= Name_Check
then
1313 Check_Placement_In_Check
(Prag
);
1315 elsif Prag_Nam
= Name_Contract_Cases
then
1316 Check_Placement_In_Contract_Cases
(Prag
);
1318 -- Attribute 'Result is allowed to appear in aspect or pragma
1319 -- [Refined_]Depends (SPARK RM 6.1.5(11)).
1321 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Refined_Depends
)
1322 and then Aname
= Name_Result
1326 elsif Nam_In
(Prag_Nam
, Name_Post
,
1333 elsif Prag_Nam
= Name_Test_Case
then
1334 Check_Placement_In_Test_Case
(Prag
);
1341 -- Otherwise the placement of the attribute is illegal
1348 -- Find the related subprogram subject to the aspect or pragma
1350 if Nkind
(Prag
) = N_Aspect_Specification
then
1351 Subp_Decl
:= Parent
(Prag
);
1353 Subp_Decl
:= Find_Related_Declaration_Or_Body
(Prag
);
1356 -- The aspect or pragma where the attribute resides should be
1357 -- associated with a subprogram declaration or a body. If this is not
1358 -- the case, then the aspect or pragma is illegal. Return as analysis
1359 -- cannot be carried out. Note that it is legal to have the aspect
1360 -- appear on a subprogram renaming, when the renamed entity is an
1361 -- attribute reference.
1363 -- Generating C code the internally built nested _postcondition
1364 -- subprograms are inlined; after expanded, inlined aspects are
1365 -- located in the internal block generated by the frontend.
1367 if Nkind
(Subp_Decl
) = N_Block_Statement
1368 and then Modify_Tree_For_C
1369 and then In_Inlined_Body
1373 elsif not Nkind_In
(Subp_Decl
, N_Abstract_Subprogram_Declaration
,
1374 N_Entry_Declaration
,
1375 N_Generic_Subprogram_Declaration
,
1377 N_Subprogram_Body_Stub
,
1378 N_Subprogram_Declaration
,
1379 N_Subprogram_Renaming_Declaration
)
1384 -- If we get here, then the attribute is legal
1387 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1389 -- When generating C code, nested _postcondition subprograms are
1390 -- inlined by the front end to avoid problems (when unnested) with
1391 -- referenced itypes. Handle that here, since as part of inlining the
1392 -- expander nests subprogram within a dummy procedure named _parent
1393 -- (see Build_Postconditions_Procedure and Build_Body_To_Inline).
1394 -- Hence, in this context, the spec_id of _postconditions is the
1397 if Modify_Tree_For_C
1398 and then Chars
(Spec_Id
) = Name_uParent
1399 and then Chars
(Scope
(Spec_Id
)) = Name_uPostconditions
1401 -- This situation occurs only when preanalyzing the inlined body
1403 pragma Assert
(not Full_Analysis
);
1405 Spec_Id
:= Scope
(Spec_Id
);
1406 pragma Assert
(Is_Inlined
(Spec_Id
));
1408 end Analyze_Attribute_Old_Result
;
1410 ---------------------------------
1411 -- Bad_Attribute_For_Predicate --
1412 ---------------------------------
1414 procedure Bad_Attribute_For_Predicate
is
1416 if Is_Scalar_Type
(P_Type
)
1417 and then Comes_From_Source
(N
)
1419 Error_Msg_Name_1
:= Aname
;
1420 Bad_Predicated_Subtype_Use
1421 ("type& has predicates, attribute % not allowed", N
, P_Type
);
1423 end Bad_Attribute_For_Predicate
;
1425 --------------------------------
1426 -- Check_Array_Or_Scalar_Type --
1427 --------------------------------
1429 procedure Check_Array_Or_Scalar_Type
is
1430 function In_Aspect_Specification
return Boolean;
1431 -- A current instance of a type in an aspect specification is an
1432 -- object and not a type, and therefore cannot be of a scalar type
1433 -- in the prefix of one of the array attributes if the attribute
1434 -- reference is part of an aspect expression.
1436 -----------------------------
1437 -- In_Aspect_Specification --
1438 -----------------------------
1440 function In_Aspect_Specification
return Boolean is
1445 while Present
(P
) loop
1446 if Nkind
(P
) = N_Aspect_Specification
then
1447 return P_Type
= Entity
(P
);
1449 elsif Nkind
(P
) in N_Declaration
then
1457 end In_Aspect_Specification
;
1464 -- Start of processing for Check_Array_Or_Scalar_Type
1467 -- Case of string literal or string literal subtype. These cases
1468 -- cannot arise from legal Ada code, but the expander is allowed
1469 -- to generate them. They require special handling because string
1470 -- literal subtypes do not have standard bounds (the whole idea
1471 -- of these subtypes is to avoid having to generate the bounds)
1473 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1474 Set_Etype
(N
, Etype
(First_Index
(P_Base_Type
)));
1479 elsif Is_Scalar_Type
(P_Type
) then
1482 if Present
(E1
) then
1483 Error_Attr
("invalid argument in % attribute", E1
);
1485 elsif In_Aspect_Specification
then
1487 ("prefix of % attribute cannot be the current instance of a "
1488 & "scalar type", P
);
1491 Set_Etype
(N
, P_Base_Type
);
1495 -- The following is a special test to allow 'First to apply to
1496 -- private scalar types if the attribute comes from generated
1497 -- code. This occurs in the case of Normalize_Scalars code.
1499 elsif Is_Private_Type
(P_Type
)
1500 and then Present
(Full_View
(P_Type
))
1501 and then Is_Scalar_Type
(Full_View
(P_Type
))
1502 and then not Comes_From_Source
(N
)
1504 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
1506 -- Array types other than string literal subtypes handled above
1511 -- We know prefix is an array type, or the name of an array
1512 -- object, and that the expression, if present, is static
1513 -- and within the range of the dimensions of the type.
1515 pragma Assert
(Is_Array_Type
(P_Type
));
1516 Index
:= First_Index
(P_Base_Type
);
1520 -- First dimension assumed
1522 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1525 Dims
:= UI_To_Int
(Intval
(E1
));
1527 for J
in 1 .. Dims
- 1 loop
1531 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
1532 Set_Etype
(E1
, Standard_Integer
);
1535 end Check_Array_Or_Scalar_Type
;
1537 ----------------------
1538 -- Check_Array_Type --
1539 ----------------------
1541 procedure Check_Array_Type
is
1543 -- Dimension number for array attributes
1546 -- If the type is a string literal type, then this must be generated
1547 -- internally, and no further check is required on its legality.
1549 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
1552 -- If the type is a composite, it is an illegal aggregate, no point
1555 elsif P_Type
= Any_Composite
then
1556 raise Bad_Attribute
;
1559 -- Normal case of array type or subtype
1561 Check_Either_E0_Or_E1
;
1564 if Is_Array_Type
(P_Type
) then
1565 if not Is_Constrained
(P_Type
)
1566 and then Is_Entity_Name
(P
)
1567 and then Is_Type
(Entity
(P
))
1569 -- Note: we do not call Error_Attr here, since we prefer to
1570 -- continue, using the relevant index type of the array,
1571 -- even though it is unconstrained. This gives better error
1572 -- recovery behavior.
1574 Error_Msg_Name_1
:= Aname
;
1576 ("prefix for % attribute must be constrained array", P
);
1579 -- The attribute reference freezes the type, and thus the
1580 -- component type, even if the attribute may not depend on the
1581 -- component. Diagnose arrays with incomplete components now.
1582 -- If the prefix is an access to array, this does not freeze
1583 -- the designated type.
1585 if Nkind
(P
) /= N_Explicit_Dereference
then
1586 Check_Fully_Declared
(Component_Type
(P_Type
), P
);
1589 D
:= Number_Dimensions
(P_Type
);
1592 if Is_Private_Type
(P_Type
) then
1593 Error_Attr_P
("prefix for % attribute may not be private type");
1595 elsif Is_Access_Type
(P_Type
)
1596 and then Is_Array_Type
(Designated_Type
(P_Type
))
1597 and then Is_Entity_Name
(P
)
1598 and then Is_Type
(Entity
(P
))
1600 Error_Attr_P
("prefix of % attribute cannot be access type");
1602 elsif Attr_Id
= Attribute_First
1604 Attr_Id
= Attribute_Last
1606 Error_Attr
("invalid prefix for % attribute", P
);
1609 Error_Attr_P
("prefix for % attribute must be array");
1613 if Present
(E1
) then
1614 Resolve
(E1
, Any_Integer
);
1615 Set_Etype
(E1
, Standard_Integer
);
1617 if not Is_OK_Static_Expression
(E1
)
1618 or else Raises_Constraint_Error
(E1
)
1620 Flag_Non_Static_Expr
1621 ("expression for dimension must be static!", E1
);
1624 elsif UI_To_Int
(Expr_Value
(E1
)) > D
1625 or else UI_To_Int
(Expr_Value
(E1
)) < 1
1627 Error_Attr
("invalid dimension number for array type", E1
);
1631 if (Style_Check
and Style_Check_Array_Attribute_Index
)
1632 and then Comes_From_Source
(N
)
1634 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
1636 end Check_Array_Type
;
1638 -------------------------
1639 -- Check_Asm_Attribute --
1640 -------------------------
1642 procedure Check_Asm_Attribute
is
1647 -- Check first argument is static string expression
1649 Analyze_And_Resolve
(E1
, Standard_String
);
1651 if Etype
(E1
) = Any_Type
then
1654 elsif not Is_OK_Static_Expression
(E1
) then
1655 Flag_Non_Static_Expr
1656 ("constraint argument must be static string expression!", E1
);
1660 -- Check second argument is right type
1662 Analyze_And_Resolve
(E2
, Entity
(P
));
1664 -- Note: that is all we need to do, we don't need to check
1665 -- that it appears in a correct context. The Ada type system
1666 -- will do that for us.
1668 end Check_Asm_Attribute
;
1670 ---------------------
1671 -- Check_Component --
1672 ---------------------
1674 procedure Check_Component
is
1678 if Nkind
(P
) /= N_Selected_Component
1680 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1682 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1684 Error_Attr_P
("prefix for % attribute must be selected component");
1686 end Check_Component
;
1688 ------------------------------------
1689 -- Check_Decimal_Fixed_Point_Type --
1690 ------------------------------------
1692 procedure Check_Decimal_Fixed_Point_Type
is
1696 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1697 Error_Attr_P
("prefix of % attribute must be decimal type");
1699 end Check_Decimal_Fixed_Point_Type
;
1701 -----------------------
1702 -- Check_Dereference --
1703 -----------------------
1705 procedure Check_Dereference
is
1708 -- Case of a subtype mark
1710 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
1714 -- Case of an expression
1718 if Is_Access_Type
(P_Type
) then
1720 -- If there is an implicit dereference, then we must freeze the
1721 -- designated type of the access type, since the type of the
1722 -- referenced array is this type (see AI95-00106).
1724 -- As done elsewhere, freezing must not happen when pre-analyzing
1725 -- a pre- or postcondition or a default value for an object or for
1726 -- a formal parameter.
1728 if not In_Spec_Expression
then
1729 Freeze_Before
(N
, Designated_Type
(P_Type
));
1733 Make_Explicit_Dereference
(Sloc
(P
),
1734 Prefix
=> Relocate_Node
(P
)));
1736 Analyze_And_Resolve
(P
);
1737 P_Type
:= Etype
(P
);
1739 if P_Type
= Any_Type
then
1740 raise Bad_Attribute
;
1743 P_Base_Type
:= Base_Type
(P_Type
);
1745 end Check_Dereference
;
1747 -------------------------
1748 -- Check_Discrete_Type --
1749 -------------------------
1751 procedure Check_Discrete_Type
is
1755 if not Is_Discrete_Type
(P_Type
) then
1756 Error_Attr_P
("prefix of % attribute must be discrete type");
1758 end Check_Discrete_Type
;
1764 procedure Check_E0
is
1766 if Present
(E1
) then
1767 Unexpected_Argument
(E1
);
1775 procedure Check_E1
is
1777 Check_Either_E0_Or_E1
;
1781 -- Special-case attributes that are functions and that appear as
1782 -- the prefix of another attribute. Error is posted on parent.
1784 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1785 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1789 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1790 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1791 Set_Etype
(Parent
(N
), Any_Type
);
1792 Set_Entity
(Parent
(N
), Any_Type
);
1793 raise Bad_Attribute
;
1796 Error_Attr
("missing argument for % attribute", N
);
1805 procedure Check_E2
is
1808 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1810 Error_Attr
("missing argument for % attribute (2 required)", N
);
1814 ---------------------------
1815 -- Check_Either_E0_Or_E1 --
1816 ---------------------------
1818 procedure Check_Either_E0_Or_E1
is
1820 if Present
(E2
) then
1821 Unexpected_Argument
(E2
);
1823 end Check_Either_E0_Or_E1
;
1825 ----------------------
1826 -- Check_Enum_Image --
1827 ----------------------
1829 procedure Check_Enum_Image
is
1833 -- When an enumeration type appears in an attribute reference, all
1834 -- literals of the type are marked as referenced. This must only be
1835 -- done if the attribute reference appears in the current source.
1836 -- Otherwise the information on references may differ between a
1837 -- normal compilation and one that performs inlining.
1839 if Is_Enumeration_Type
(P_Base_Type
)
1840 and then In_Extended_Main_Code_Unit
(N
)
1842 Lit
:= First_Literal
(P_Base_Type
);
1843 while Present
(Lit
) loop
1844 Set_Referenced
(Lit
);
1848 end Check_Enum_Image
;
1850 ----------------------------
1851 -- Check_First_Last_Valid --
1852 ----------------------------
1854 procedure Check_First_Last_Valid
is
1856 Check_Discrete_Type
;
1858 -- Freeze the subtype now, so that the following test for predicates
1859 -- works (we set the predicates stuff up at freeze time)
1861 Insert_Actions
(N
, Freeze_Entity
(P_Type
, P
));
1863 -- Now test for dynamic predicate
1865 if Has_Predicates
(P_Type
)
1866 and then not (Has_Static_Predicate
(P_Type
))
1869 ("prefix of % attribute may not have dynamic predicate");
1872 -- Check non-static subtype
1874 if not Is_OK_Static_Subtype
(P_Type
) then
1875 Error_Attr_P
("prefix of % attribute must be a static subtype");
1878 -- Test case for no values
1880 if Expr_Value
(Type_Low_Bound
(P_Type
)) >
1881 Expr_Value
(Type_High_Bound
(P_Type
))
1882 or else (Has_Predicates
(P_Type
)
1884 Is_Empty_List
(Static_Discrete_Predicate
(P_Type
)))
1887 ("prefix of % attribute must be subtype with at least one "
1890 end Check_First_Last_Valid
;
1892 ----------------------------
1893 -- Check_Fixed_Point_Type --
1894 ----------------------------
1896 procedure Check_Fixed_Point_Type
is
1900 if not Is_Fixed_Point_Type
(P_Type
) then
1901 Error_Attr_P
("prefix of % attribute must be fixed point type");
1903 end Check_Fixed_Point_Type
;
1905 ------------------------------
1906 -- Check_Fixed_Point_Type_0 --
1907 ------------------------------
1909 procedure Check_Fixed_Point_Type_0
is
1911 Check_Fixed_Point_Type
;
1913 end Check_Fixed_Point_Type_0
;
1915 -------------------------------
1916 -- Check_Floating_Point_Type --
1917 -------------------------------
1919 procedure Check_Floating_Point_Type
is
1923 if not Is_Floating_Point_Type
(P_Type
) then
1924 Error_Attr_P
("prefix of % attribute must be float type");
1926 end Check_Floating_Point_Type
;
1928 ---------------------------------
1929 -- Check_Floating_Point_Type_0 --
1930 ---------------------------------
1932 procedure Check_Floating_Point_Type_0
is
1934 Check_Floating_Point_Type
;
1936 end Check_Floating_Point_Type_0
;
1938 ---------------------------------
1939 -- Check_Floating_Point_Type_1 --
1940 ---------------------------------
1942 procedure Check_Floating_Point_Type_1
is
1944 Check_Floating_Point_Type
;
1946 end Check_Floating_Point_Type_1
;
1948 ---------------------------------
1949 -- Check_Floating_Point_Type_2 --
1950 ---------------------------------
1952 procedure Check_Floating_Point_Type_2
is
1954 Check_Floating_Point_Type
;
1956 end Check_Floating_Point_Type_2
;
1958 ------------------------
1959 -- Check_Integer_Type --
1960 ------------------------
1962 procedure Check_Integer_Type
is
1966 if not Is_Integer_Type
(P_Type
) then
1967 Error_Attr_P
("prefix of % attribute must be integer type");
1969 end Check_Integer_Type
;
1971 --------------------------------
1972 -- Check_Modular_Integer_Type --
1973 --------------------------------
1975 procedure Check_Modular_Integer_Type
is
1979 if not Is_Modular_Integer_Type
(P_Type
) then
1981 ("prefix of % attribute must be modular integer type");
1983 end Check_Modular_Integer_Type
;
1985 ------------------------
1986 -- Check_Not_CPP_Type --
1987 ------------------------
1989 procedure Check_Not_CPP_Type
is
1991 if Is_Tagged_Type
(Etype
(P
))
1992 and then Convention
(Etype
(P
)) = Convention_CPP
1993 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1996 ("invalid use of % attribute with 'C'P'P tagged type");
1998 end Check_Not_CPP_Type
;
2000 -------------------------------
2001 -- Check_Not_Incomplete_Type --
2002 -------------------------------
2004 procedure Check_Not_Incomplete_Type
is
2009 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
2010 -- dereference we have to check wrong uses of incomplete types
2011 -- (other wrong uses are checked at their freezing point).
2013 -- In Ada 2012, incomplete types can appear in subprogram
2014 -- profiles, but formals with incomplete types cannot be the
2015 -- prefix of attributes.
2017 -- Example 1: Limited-with
2019 -- limited with Pkg;
2021 -- type Acc is access Pkg.T;
2023 -- S : Integer := X.all'Size; -- ERROR
2026 -- Example 2: Tagged incomplete
2028 -- type T is tagged;
2029 -- type Acc is access all T;
2031 -- S : constant Integer := X.all'Size; -- ERROR
2032 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
2034 if Ada_Version
>= Ada_2005
2035 and then Nkind
(P
) = N_Explicit_Dereference
2038 while Nkind
(E
) = N_Explicit_Dereference
loop
2044 if From_Limited_With
(Typ
) then
2046 ("prefix of % attribute cannot be an incomplete type");
2048 -- If the prefix is an access type check the designated type
2050 elsif Is_Access_Type
(Typ
)
2051 and then Nkind
(P
) = N_Explicit_Dereference
2053 Typ
:= Directly_Designated_Type
(Typ
);
2056 if Is_Class_Wide_Type
(Typ
) then
2057 Typ
:= Root_Type
(Typ
);
2060 -- A legal use of a shadow entity occurs only when the unit where
2061 -- the non-limited view resides is imported via a regular with
2062 -- clause in the current body. Such references to shadow entities
2063 -- may occur in subprogram formals.
2065 if Is_Incomplete_Type
(Typ
)
2066 and then From_Limited_With
(Typ
)
2067 and then Present
(Non_Limited_View
(Typ
))
2068 and then Is_Legal_Shadow_Entity_In_Body
(Typ
)
2070 Typ
:= Non_Limited_View
(Typ
);
2073 -- If still incomplete, it can be a local incomplete type, or a
2074 -- limited view whose scope is also a limited view.
2076 if Ekind
(Typ
) = E_Incomplete_Type
then
2077 if not From_Limited_With
(Typ
)
2078 and then No
(Full_View
(Typ
))
2081 ("prefix of % attribute cannot be an incomplete type");
2083 -- The limited view may be available indirectly through
2084 -- an intermediate unit. If the non-limited view is available
2085 -- the attribute reference is legal.
2087 elsif From_Limited_With
(Typ
)
2089 (No
(Non_Limited_View
(Typ
))
2090 or else Is_Incomplete_Type
(Non_Limited_View
(Typ
)))
2093 ("prefix of % attribute cannot be an incomplete type");
2097 -- Ada 2012 : formals in bodies may be incomplete, but no attribute
2100 elsif Is_Entity_Name
(P
)
2101 and then Is_Formal
(Entity
(P
))
2102 and then Is_Incomplete_Type
(Etype
(Etype
(P
)))
2105 ("prefix of % attribute cannot be an incomplete type");
2108 if not Is_Entity_Name
(P
)
2109 or else not Is_Type
(Entity
(P
))
2110 or else In_Spec_Expression
2114 Check_Fully_Declared
(P_Type
, P
);
2116 end Check_Not_Incomplete_Type
;
2118 ----------------------------
2119 -- Check_Object_Reference --
2120 ----------------------------
2122 procedure Check_Object_Reference
(P
: Node_Id
) is
2126 -- If we need an object, and we have a prefix that is the name of
2127 -- a function entity, convert it into a function call.
2129 if Is_Entity_Name
(P
)
2130 and then Ekind
(Entity
(P
)) = E_Function
2132 Rtyp
:= Etype
(Entity
(P
));
2135 Make_Function_Call
(Sloc
(P
),
2136 Name
=> Relocate_Node
(P
)));
2138 Analyze_And_Resolve
(P
, Rtyp
);
2140 -- Otherwise we must have an object reference
2142 elsif not Is_Object_Reference
(P
) then
2143 Error_Attr_P
("prefix of % attribute must be object");
2145 end Check_Object_Reference
;
2147 ----------------------------
2148 -- Check_PolyORB_Attribute --
2149 ----------------------------
2151 procedure Check_PolyORB_Attribute
is
2153 Validate_Non_Static_Attribute_Function_Call
;
2158 if Get_PCS_Name
/= Name_PolyORB_DSA
then
2160 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N
);
2162 end Check_PolyORB_Attribute
;
2164 ------------------------
2165 -- Check_Program_Unit --
2166 ------------------------
2168 procedure Check_Program_Unit
is
2170 if Is_Entity_Name
(P
) then
2172 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
2173 T
: constant Entity_Id
:= Etype
(Entity
(P
));
2176 if K
in Subprogram_Kind
2177 or else K
in Task_Kind
2178 or else K
in Protected_Kind
2179 or else K
= E_Package
2180 or else K
in Generic_Unit_Kind
2181 or else (K
= E_Variable
2185 Is_Protected_Type
(T
)))
2192 Error_Attr_P
("prefix of % attribute must be program unit");
2193 end Check_Program_Unit
;
2195 ---------------------
2196 -- Check_Real_Type --
2197 ---------------------
2199 procedure Check_Real_Type
is
2203 if not Is_Real_Type
(P_Type
) then
2204 Error_Attr_P
("prefix of % attribute must be real type");
2206 end Check_Real_Type
;
2208 -----------------------
2209 -- Check_Scalar_Type --
2210 -----------------------
2212 procedure Check_Scalar_Type
is
2216 if not Is_Scalar_Type
(P_Type
) then
2217 Error_Attr_P
("prefix of % attribute must be scalar type");
2219 end Check_Scalar_Type
;
2221 ------------------------------------------
2222 -- Check_SPARK_05_Restriction_On_Attribute --
2223 ------------------------------------------
2225 procedure Check_SPARK_05_Restriction_On_Attribute
is
2227 Error_Msg_Name_1
:= Aname
;
2228 Check_SPARK_05_Restriction
("attribute % is not allowed", P
);
2229 end Check_SPARK_05_Restriction_On_Attribute
;
2231 ---------------------------
2232 -- Check_Standard_Prefix --
2233 ---------------------------
2235 procedure Check_Standard_Prefix
is
2239 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_Standard
then
2240 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
2242 end Check_Standard_Prefix
;
2244 ----------------------------
2245 -- Check_Stream_Attribute --
2246 ----------------------------
2248 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
2252 In_Shared_Var_Procs
: Boolean;
2253 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
2254 -- For this runtime package (always compiled in GNAT mode), we allow
2255 -- stream attributes references for limited types for the case where
2256 -- shared passive objects are implemented using stream attributes,
2257 -- which is the default in GNAT's persistent storage implementation.
2260 Validate_Non_Static_Attribute_Function_Call
;
2262 -- With the exception of 'Input, Stream attributes are procedures,
2263 -- and can only appear at the position of procedure calls. We check
2264 -- for this here, before they are rewritten, to give a more precise
2267 if Nam
= TSS_Stream_Input
then
2270 elsif Is_List_Member
(N
)
2271 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
2278 ("invalid context for attribute%, which is a procedure", N
);
2282 Btyp
:= Implementation_Base_Type
(P_Type
);
2284 -- Stream attributes not allowed on limited types unless the
2285 -- attribute reference was generated by the expander (in which
2286 -- case the underlying type will be used, as described in Sinfo),
2287 -- or the attribute was specified explicitly for the type itself
2288 -- or one of its ancestors (taking visibility rules into account if
2289 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
2290 -- (with no visibility restriction).
2293 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
2295 if Present
(Gen_Body
) then
2296 In_Shared_Var_Procs
:=
2297 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
2299 In_Shared_Var_Procs
:= False;
2303 if (Comes_From_Source
(N
)
2304 and then not (In_Shared_Var_Procs
or In_Instance
))
2305 and then not Stream_Attribute_Available
(P_Type
, Nam
)
2306 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
2308 Error_Msg_Name_1
:= Aname
;
2310 if Is_Limited_Type
(P_Type
) then
2312 ("limited type& has no% attribute", P
, P_Type
);
2313 Explain_Limited_Type
(P_Type
, P
);
2316 ("attribute% for type& is not available", P
, P_Type
);
2320 -- Check for no stream operations allowed from No_Tagged_Streams
2322 if Is_Tagged_Type
(P_Type
)
2323 and then Present
(No_Tagged_Streams_Pragma
(P_Type
))
2325 Error_Msg_Sloc
:= Sloc
(No_Tagged_Streams_Pragma
(P_Type
));
2327 ("no stream operations for & (No_Tagged_Streams #)", N
, P_Type
);
2331 -- Check restriction violations
2333 -- First check the No_Streams restriction, which prohibits the use
2334 -- of explicit stream attributes in the source program. We do not
2335 -- prevent the occurrence of stream attributes in generated code,
2336 -- for instance those generated implicitly for dispatching purposes.
2338 if Comes_From_Source
(N
) then
2339 Check_Restriction
(No_Streams
, P
);
2342 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
2343 -- it is illegal to use a predefined elementary type stream attribute
2344 -- either by itself, or more importantly as part of the attribute
2345 -- subprogram for a composite type. However, if the broader
2346 -- restriction No_Streams is active, stream operations are not
2347 -- generated, and there is no error.
2349 if Restriction_Active
(No_Default_Stream_Attributes
)
2350 and then not Restriction_Active
(No_Streams
)
2356 if Nam
= TSS_Stream_Input
2358 Nam
= TSS_Stream_Read
2361 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Read
);
2364 Type_Without_Stream_Operation
(P_Type
, TSS_Stream_Write
);
2368 Check_Restriction
(No_Default_Stream_Attributes
, N
);
2371 ("missing user-defined Stream Read or Write for type&",
2373 if not Is_Elementary_Type
(P_Type
) then
2375 ("\which is a component of type&", N
, P_Type
);
2381 -- Check special case of Exception_Id and Exception_Occurrence which
2382 -- are not allowed for restriction No_Exception_Registration.
2384 if Restriction_Check_Required
(No_Exception_Registration
)
2385 and then (Is_RTE
(P_Type
, RE_Exception_Id
)
2387 Is_RTE
(P_Type
, RE_Exception_Occurrence
))
2389 Check_Restriction
(No_Exception_Registration
, P
);
2392 -- Here we must check that the first argument is an access type
2393 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
2395 Analyze_And_Resolve
(E1
);
2398 -- Note: the double call to Root_Type here is needed because the
2399 -- root type of a class-wide type is the corresponding type (e.g.
2400 -- X for X'Class, and we really want to go to the root.)
2402 if not Is_Access_Type
(Etyp
)
2403 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
2404 RTE
(RE_Root_Stream_Type
)
2407 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
2410 -- Check that the second argument is of the right type if there is
2411 -- one (the Input attribute has only one argument so this is skipped)
2413 if Present
(E2
) then
2416 if Nam
= TSS_Stream_Read
2417 and then not Is_OK_Variable_For_Out_Formal
(E2
)
2420 ("second argument of % attribute must be a variable", E2
);
2423 Resolve
(E2
, P_Type
);
2427 end Check_Stream_Attribute
;
2429 -------------------------
2430 -- Check_System_Prefix --
2431 -------------------------
2433 procedure Check_System_Prefix
is
2435 if Nkind
(P
) /= N_Identifier
or else Chars
(P
) /= Name_System
then
2436 Error_Attr
("only allowed prefix for % attribute is System", P
);
2438 end Check_System_Prefix
;
2440 -----------------------
2441 -- Check_Task_Prefix --
2442 -----------------------
2444 procedure Check_Task_Prefix
is
2448 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
2449 -- task interface class-wide types.
2451 if Is_Task_Type
(Etype
(P
))
2452 or else (Is_Access_Type
(Etype
(P
))
2453 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2454 or else (Ada_Version
>= Ada_2005
2455 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
2456 and then Is_Interface
(Etype
(P
))
2457 and then Is_Task_Interface
(Etype
(P
)))
2462 if Ada_Version
>= Ada_2005
then
2464 ("prefix of % attribute must be a task or a task " &
2465 "interface class-wide object");
2468 Error_Attr_P
("prefix of % attribute must be a task");
2471 end Check_Task_Prefix
;
2477 -- The possibilities are an entity name denoting a type, or an
2478 -- attribute reference that denotes a type (Base or Class). If
2479 -- the type is incomplete, replace it with its full view.
2481 procedure Check_Type
is
2483 if not Is_Entity_Name
(P
)
2484 or else not Is_Type
(Entity
(P
))
2486 Error_Attr_P
("prefix of % attribute must be a type");
2488 elsif Is_Protected_Self_Reference
(P
) then
2490 ("prefix of % attribute denotes current instance "
2491 & "(RM 9.4(21/2))");
2493 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
2494 and then Present
(Full_View
(Entity
(P
)))
2496 P_Type
:= Full_View
(Entity
(P
));
2497 Set_Entity
(P
, P_Type
);
2501 ---------------------
2502 -- Check_Unit_Name --
2503 ---------------------
2505 procedure Check_Unit_Name
(Nod
: Node_Id
) is
2507 if Nkind
(Nod
) = N_Identifier
then
2510 elsif Nkind_In
(Nod
, N_Selected_Component
, N_Expanded_Name
) then
2511 Check_Unit_Name
(Prefix
(Nod
));
2513 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
2518 Error_Attr
("argument for % attribute must be unit name", P
);
2519 end Check_Unit_Name
;
2525 procedure Error_Attr
is
2527 Set_Etype
(N
, Any_Type
);
2528 Set_Entity
(N
, Any_Type
);
2529 raise Bad_Attribute
;
2532 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
2534 Error_Msg_Name_1
:= Aname
;
2535 Error_Msg_N
(Msg
, Error_Node
);
2543 procedure Error_Attr_P
(Msg
: String) is
2545 Error_Msg_Name_1
:= Aname
;
2546 Error_Msg_F
(Msg
, P
);
2550 ----------------------------
2551 -- Legal_Formal_Attribute --
2552 ----------------------------
2554 procedure Legal_Formal_Attribute
is
2558 if not Is_Entity_Name
(P
)
2559 or else not Is_Type
(Entity
(P
))
2561 Error_Attr_P
("prefix of % attribute must be generic type");
2563 elsif Is_Generic_Actual_Type
(Entity
(P
))
2565 or else In_Inlined_Body
2569 elsif Is_Generic_Type
(Entity
(P
)) then
2570 if Is_Definite_Subtype
(Entity
(P
)) then
2572 ("prefix of % attribute must be indefinite generic type");
2577 ("prefix of % attribute must be indefinite generic type");
2580 Set_Etype
(N
, Standard_Boolean
);
2581 end Legal_Formal_Attribute
;
2583 ---------------------------------------------------------------
2584 -- Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements --
2585 ---------------------------------------------------------------
2587 procedure Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
is
2591 Check_Not_Incomplete_Type
;
2592 Set_Etype
(N
, Universal_Integer
);
2593 end Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
2599 procedure Min_Max
is
2603 Resolve
(E1
, P_Base_Type
);
2604 Resolve
(E2
, P_Base_Type
);
2605 Set_Etype
(N
, P_Base_Type
);
2607 -- Check for comparison on unordered enumeration type
2609 if Bad_Unordered_Enumeration_Reference
(N
, P_Base_Type
) then
2610 Error_Msg_Sloc
:= Sloc
(P_Base_Type
);
2612 ("comparison on unordered enumeration type& declared#?U?",
2617 ------------------------
2618 -- Standard_Attribute --
2619 ------------------------
2621 procedure Standard_Attribute
(Val
: Int
) is
2623 Check_Standard_Prefix
;
2624 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
2626 Set_Is_Static_Expression
(N
, True);
2627 end Standard_Attribute
;
2629 --------------------
2630 -- Uneval_Old_Msg --
2631 --------------------
2633 procedure Uneval_Old_Msg
is
2634 Uneval_Old_Setting
: Character;
2638 -- If from aspect, then Uneval_Old_Setting comes from flags in the
2639 -- N_Aspect_Specification node that corresponds to the attribute.
2641 -- First find the pragma in which we appear (note that at this stage,
2642 -- even if we appeared originally within an aspect specification, we
2643 -- are now within the corresponding pragma).
2647 Prag
:= Parent
(Prag
);
2648 exit when No
(Prag
) or else Nkind
(Prag
) = N_Pragma
;
2651 if Present
(Prag
) then
2652 if Uneval_Old_Accept
(Prag
) then
2653 Uneval_Old_Setting
:= 'A';
2654 elsif Uneval_Old_Warn
(Prag
) then
2655 Uneval_Old_Setting
:= 'W';
2657 Uneval_Old_Setting
:= 'E';
2660 -- If we did not find the pragma, that's odd, just use the setting
2661 -- from Opt.Uneval_Old. Perhaps this is due to a previous error?
2664 Uneval_Old_Setting
:= Opt
.Uneval_Old
;
2667 -- Processing depends on the setting of Uneval_Old
2669 case Uneval_Old_Setting
is
2672 ("prefix of attribute % that is potentially "
2673 & "unevaluated must denote an entity");
2676 Error_Msg_Name_1
:= Aname
;
2678 ("??prefix of attribute % appears in potentially "
2679 & "unevaluated context, exception may be raised", P
);
2685 raise Program_Error
;
2689 -------------------------
2690 -- Unexpected Argument --
2691 -------------------------
2693 procedure Unexpected_Argument
(En
: Node_Id
) is
2695 Error_Attr
("unexpected argument for % attribute", En
);
2696 end Unexpected_Argument
;
2698 -------------------------------------------------
2699 -- Validate_Non_Static_Attribute_Function_Call --
2700 -------------------------------------------------
2702 -- This function should be moved to Sem_Dist ???
2704 procedure Validate_Non_Static_Attribute_Function_Call
is
2706 if In_Preelaborated_Unit
2707 and then not In_Subprogram_Or_Concurrent_Unit
2709 Flag_Non_Static_Expr
2710 ("non-static function call in preelaborated unit!", N
);
2712 end Validate_Non_Static_Attribute_Function_Call
;
2714 -- Start of processing for Analyze_Attribute
2717 -- Immediate return if unrecognized attribute (already diagnosed by
2718 -- parser, so there is nothing more that we need to do).
2720 if not Is_Attribute_Name
(Aname
) then
2721 raise Bad_Attribute
;
2724 Check_Restriction_No_Use_Of_Attribute
(N
);
2726 -- Deal with Ada 83 issues
2728 if Comes_From_Source
(N
) then
2729 if not Attribute_83
(Attr_Id
) then
2730 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2731 Error_Msg_Name_1
:= Aname
;
2732 Error_Msg_N
("(Ada 83) attribute% is not standard??", N
);
2735 if Attribute_Impl_Def
(Attr_Id
) then
2736 Check_Restriction
(No_Implementation_Attributes
, N
);
2741 -- Deal with Ada 2005 attributes that are implementation attributes
2742 -- because they appear in a version of Ada before Ada 2005, and
2743 -- similarly for Ada 2012 attributes appearing in an earlier version.
2745 if (Attribute_05
(Attr_Id
) and then Ada_Version
< Ada_2005
)
2747 (Attribute_12
(Attr_Id
) and then Ada_Version
< Ada_2012
)
2749 Check_Restriction
(No_Implementation_Attributes
, N
);
2752 -- Remote access to subprogram type access attribute reference needs
2753 -- unanalyzed copy for tree transformation. The analyzed copy is used
2754 -- for its semantic information (whether prefix is a remote subprogram
2755 -- name), the unanalyzed copy is used to construct new subtree rooted
2756 -- with N_Aggregate which represents a fat pointer aggregate.
2758 if Aname
= Name_Access
then
2759 Discard_Node
(Copy_Separate_Tree
(N
));
2762 -- Analyze prefix and exit if error in analysis. If the prefix is an
2763 -- incomplete type, use full view if available. Note that there are
2764 -- some attributes for which we do not analyze the prefix, since the
2765 -- prefix is not a normal name, or else needs special handling.
2767 if Aname
/= Name_Elab_Body
and then
2768 Aname
/= Name_Elab_Spec
and then
2769 Aname
/= Name_Elab_Subp_Body
and then
2770 Aname
/= Name_Enabled
and then
2774 P_Type
:= Etype
(P
);
2776 if Is_Entity_Name
(P
)
2777 and then Present
(Entity
(P
))
2778 and then Is_Type
(Entity
(P
))
2780 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
2781 P_Type
:= Get_Full_View
(P_Type
);
2782 Set_Entity
(P
, P_Type
);
2783 Set_Etype
(P
, P_Type
);
2785 elsif Entity
(P
) = Current_Scope
2786 and then Is_Record_Type
(Entity
(P
))
2788 -- Use of current instance within the type. Verify that if the
2789 -- attribute appears within a constraint, it yields an access
2790 -- type, other uses are illegal.
2798 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
2800 Par
:= Parent
(Par
);
2804 and then Nkind
(Par
) = N_Subtype_Indication
2806 if Attr_Id
/= Attribute_Access
2807 and then Attr_Id
/= Attribute_Unchecked_Access
2808 and then Attr_Id
/= Attribute_Unrestricted_Access
2811 ("in a constraint the current instance can only "
2812 & "be used with an access attribute", N
);
2819 if P_Type
= Any_Type
then
2820 raise Bad_Attribute
;
2823 P_Base_Type
:= Base_Type
(P_Type
);
2826 -- Analyze expressions that may be present, exiting if an error occurs
2833 E1
:= First
(Exprs
);
2835 -- Skip analysis for case of Restriction_Set, we do not expect
2836 -- the argument to be analyzed in this case.
2838 if Aname
/= Name_Restriction_Set
then
2841 -- Check for missing/bad expression (result of previous error)
2843 if No
(E1
) or else Etype
(E1
) = Any_Type
then
2844 raise Bad_Attribute
;
2850 if Present
(E2
) then
2853 if Etype
(E2
) = Any_Type
then
2854 raise Bad_Attribute
;
2857 if Present
(Next
(E2
)) then
2858 Unexpected_Argument
(Next
(E2
));
2863 -- Cases where prefix must be resolvable by itself
2865 if Is_Overloaded
(P
)
2866 and then Aname
/= Name_Access
2867 and then Aname
/= Name_Address
2868 and then Aname
/= Name_Code_Address
2869 and then Aname
/= Name_Result
2870 and then Aname
/= Name_Unchecked_Access
2872 -- The prefix must be resolvable by itself, without reference to the
2873 -- attribute. One case that requires special handling is a prefix
2874 -- that is a function name, where one interpretation may be a
2875 -- parameterless call. Entry attributes are handled specially below.
2877 if Is_Entity_Name
(P
)
2878 and then not Nam_In
(Aname
, Name_Count
, Name_Caller
)
2880 Check_Parameterless_Call
(P
);
2883 if Is_Overloaded
(P
) then
2885 -- Ada 2005 (AI-345): Since protected and task types have
2886 -- primitive entry wrappers, the attributes Count, and Caller
2887 -- require a context check
2889 if Nam_In
(Aname
, Name_Count
, Name_Caller
) then
2891 Count
: Natural := 0;
2896 Get_First_Interp
(P
, I
, It
);
2897 while Present
(It
.Nam
) loop
2898 if Comes_From_Source
(It
.Nam
) then
2904 Get_Next_Interp
(I
, It
);
2908 Error_Attr
("ambiguous prefix for % attribute", P
);
2910 Set_Is_Overloaded
(P
, False);
2915 Error_Attr
("ambiguous prefix for % attribute", P
);
2920 -- In SPARK, attributes of private types are only allowed if the full
2921 -- type declaration is visible.
2923 -- Note: the check for Present (Entity (P)) defends against some error
2924 -- conditions where the Entity field is not set.
2926 if Is_Entity_Name
(P
) and then Present
(Entity
(P
))
2927 and then Is_Type
(Entity
(P
))
2928 and then Is_Private_Type
(P_Type
)
2929 and then not In_Open_Scopes
(Scope
(P_Type
))
2930 and then not In_Spec_Expression
2932 Check_SPARK_05_Restriction
("invisible attribute of type", N
);
2935 -- Remaining processing depends on attribute
2939 -- Attributes related to Ada 2012 iterators. Attribute specifications
2940 -- exist for these, but they cannot be queried.
2942 when Attribute_Constant_Indexing |
2943 Attribute_Default_Iterator |
2944 Attribute_Implicit_Dereference |
2945 Attribute_Iterator_Element |
2946 Attribute_Iterable |
2947 Attribute_Variable_Indexing
=>
2948 Error_Msg_N
("illegal attribute", N
);
2950 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2951 -- were already rejected by the parser. Thus they shouldn't appear here.
2953 when Internal_Attribute_Id
=>
2954 raise Program_Error
;
2960 when Attribute_Abort_Signal
=>
2961 Check_Standard_Prefix
;
2962 Rewrite
(N
, New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
));
2969 when Attribute_Access
=>
2970 Analyze_Access_Attribute
;
2971 Check_Not_Incomplete_Type
;
2977 when Attribute_Address
=>
2980 Check_Not_Incomplete_Type
;
2981 Set_Etype
(N
, RTE
(RE_Address
));
2987 when Attribute_Address_Size
=>
2988 Standard_Attribute
(System_Address_Size
);
2994 when Attribute_Adjacent
=>
2995 Check_Floating_Point_Type_2
;
2996 Set_Etype
(N
, P_Base_Type
);
2997 Resolve
(E1
, P_Base_Type
);
2998 Resolve
(E2
, P_Base_Type
);
3004 when Attribute_Aft
=>
3005 Check_Fixed_Point_Type_0
;
3006 Set_Etype
(N
, Universal_Integer
);
3012 when Attribute_Alignment
=>
3014 -- Don't we need more checking here, cf Size ???
3017 Check_Not_Incomplete_Type
;
3019 Set_Etype
(N
, Universal_Integer
);
3025 when Attribute_Asm_Input
=>
3026 Check_Asm_Attribute
;
3028 -- The back end may need to take the address of E2
3030 if Is_Entity_Name
(E2
) then
3031 Set_Address_Taken
(Entity
(E2
));
3034 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
3040 when Attribute_Asm_Output
=>
3041 Check_Asm_Attribute
;
3043 if Etype
(E2
) = Any_Type
then
3046 elsif Aname
= Name_Asm_Output
then
3047 if not Is_Variable
(E2
) then
3049 ("second argument for Asm_Output is not variable", E2
);
3053 Note_Possible_Modification
(E2
, Sure
=> True);
3055 -- The back end may need to take the address of E2
3057 if Is_Entity_Name
(E2
) then
3058 Set_Address_Taken
(Entity
(E2
));
3061 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
3063 -----------------------------
3064 -- Atomic_Always_Lock_Free --
3065 -----------------------------
3067 when Attribute_Atomic_Always_Lock_Free
=>
3070 Set_Etype
(N
, Standard_Boolean
);
3076 -- Note: when the base attribute appears in the context of a subtype
3077 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
3078 -- the following circuit.
3080 when Attribute_Base
=> Base
: declare
3088 if Ada_Version
>= Ada_95
3089 and then not Is_Scalar_Type
(Typ
)
3090 and then not Is_Generic_Type
(Typ
)
3092 Error_Attr_P
("prefix of Base attribute must be scalar type");
3094 elsif Sloc
(Typ
) = Standard_Location
3095 and then Base_Type
(Typ
) = Typ
3096 and then Warn_On_Redundant_Constructs
3098 Error_Msg_NE
-- CODEFIX
3099 ("?r?redundant attribute, & is its own base type", N
, Typ
);
3102 if Nkind
(Parent
(N
)) /= N_Attribute_Reference
then
3103 Error_Msg_Name_1
:= Aname
;
3104 Check_SPARK_05_Restriction
3105 ("attribute% is only allowed as prefix of another attribute", P
);
3108 Set_Etype
(N
, Base_Type
(Entity
(P
)));
3109 Set_Entity
(N
, Base_Type
(Entity
(P
)));
3110 Rewrite
(N
, New_Occurrence_Of
(Entity
(N
), Loc
));
3118 when Attribute_Bit
=> Bit
:
3122 if not Is_Object_Reference
(P
) then
3123 Error_Attr_P
("prefix for % attribute must be object");
3125 -- What about the access object cases ???
3131 Set_Etype
(N
, Universal_Integer
);
3138 when Attribute_Bit_Order
=> Bit_Order
:
3143 if not Is_Record_Type
(P_Type
) then
3144 Error_Attr_P
("prefix of % attribute must be record type");
3147 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
3149 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
3152 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
3155 Set_Etype
(N
, RTE
(RE_Bit_Order
));
3158 -- Reset incorrect indication of staticness
3160 Set_Is_Static_Expression
(N
, False);
3167 -- Note: in generated code, we can have a Bit_Position attribute
3168 -- applied to a (naked) record component (i.e. the prefix is an
3169 -- identifier that references an E_Component or E_Discriminant
3170 -- entity directly, and this is interpreted as expected by Gigi.
3171 -- The following code will not tolerate such usage, but when the
3172 -- expander creates this special case, it marks it as analyzed
3173 -- immediately and sets an appropriate type.
3175 when Attribute_Bit_Position
=>
3176 if Comes_From_Source
(N
) then
3180 Set_Etype
(N
, Universal_Integer
);
3186 when Attribute_Body_Version
=>
3189 Set_Etype
(N
, RTE
(RE_Version_String
));
3195 when Attribute_Callable
=>
3197 Set_Etype
(N
, Standard_Boolean
);
3204 when Attribute_Caller
=> Caller
: declare
3211 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3214 if not Is_Entry
(Ent
) then
3215 Error_Attr
("invalid entry name", N
);
3219 Error_Attr
("invalid entry name", N
);
3223 for J
in reverse 0 .. Scope_Stack
.Last
loop
3224 S
:= Scope_Stack
.Table
(J
).Entity
;
3226 if S
= Scope
(Ent
) then
3227 Error_Attr
("Caller must appear in matching accept or body", N
);
3233 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3240 when Attribute_Ceiling
=>
3241 Check_Floating_Point_Type_1
;
3242 Set_Etype
(N
, P_Base_Type
);
3243 Resolve
(E1
, P_Base_Type
);
3249 when Attribute_Class
=>
3250 Check_Restriction
(No_Dispatch
, N
);
3254 -- Applying Class to untagged incomplete type is obsolescent in Ada
3255 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
3256 -- this flag gets set by Find_Type in this situation.
3258 if Restriction_Check_Required
(No_Obsolescent_Features
)
3259 and then Ada_Version
>= Ada_2005
3260 and then Ekind
(P_Type
) = E_Incomplete_Type
3263 DN
: constant Node_Id
:= Declaration_Node
(P_Type
);
3265 if Nkind
(DN
) = N_Incomplete_Type_Declaration
3266 and then not Tagged_Present
(DN
)
3268 Check_Restriction
(No_Obsolescent_Features
, P
);
3277 when Attribute_Code_Address
=>
3280 if Nkind
(P
) = N_Attribute_Reference
3281 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Body
, Name_Elab_Spec
)
3285 elsif not Is_Entity_Name
(P
)
3286 or else (Ekind
(Entity
(P
)) /= E_Function
3288 Ekind
(Entity
(P
)) /= E_Procedure
)
3290 Error_Attr
("invalid prefix for % attribute", P
);
3291 Set_Address_Taken
(Entity
(P
));
3293 -- Issue an error if the prefix denotes an eliminated subprogram
3296 Check_For_Eliminated_Subprogram
(P
, Entity
(P
));
3299 Set_Etype
(N
, RTE
(RE_Address
));
3301 ----------------------
3302 -- Compiler_Version --
3303 ----------------------
3305 when Attribute_Compiler_Version
=>
3307 Check_Standard_Prefix
;
3308 Rewrite
(N
, Make_String_Literal
(Loc
, "GNAT " & Gnat_Version_String
));
3309 Analyze_And_Resolve
(N
, Standard_String
);
3310 Set_Is_Static_Expression
(N
, True);
3312 --------------------
3313 -- Component_Size --
3314 --------------------
3316 when Attribute_Component_Size
=>
3318 Set_Etype
(N
, Universal_Integer
);
3320 -- Note: unlike other array attributes, unconstrained arrays are OK
3322 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
3332 when Attribute_Compose
=>
3333 Check_Floating_Point_Type_2
;
3334 Set_Etype
(N
, P_Base_Type
);
3335 Resolve
(E1
, P_Base_Type
);
3336 Resolve
(E2
, Any_Integer
);
3342 when Attribute_Constrained
=>
3344 Set_Etype
(N
, Standard_Boolean
);
3346 -- Case from RM J.4(2) of constrained applied to private type
3348 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
3349 Check_Restriction
(No_Obsolescent_Features
, P
);
3351 if Warn_On_Obsolescent_Feature
then
3353 ("constrained for private type is an " &
3354 "obsolescent feature (RM J.4)?j?", N
);
3357 -- If we are within an instance, the attribute must be legal
3358 -- because it was valid in the generic unit. Ditto if this is
3359 -- an inlining of a function declared in an instance.
3361 if In_Instance
or else In_Inlined_Body
then
3364 -- For sure OK if we have a real private type itself, but must
3365 -- be completed, cannot apply Constrained to incomplete type.
3367 elsif Is_Private_Type
(Entity
(P
)) then
3369 -- Note: this is one of the Annex J features that does not
3370 -- generate a warning from -gnatwj, since in fact it seems
3371 -- very useful, and is used in the GNAT runtime.
3373 Check_Not_Incomplete_Type
;
3377 -- Normal (non-obsolescent case) of application to object of
3378 -- a discriminated type.
3381 Check_Object_Reference
(P
);
3383 -- If N does not come from source, then we allow the
3384 -- the attribute prefix to be of a private type whose
3385 -- full type has discriminants. This occurs in cases
3386 -- involving expanded calls to stream attributes.
3388 if not Comes_From_Source
(N
) then
3389 P_Type
:= Underlying_Type
(P_Type
);
3392 -- Must have discriminants or be an access type designating a type
3393 -- with discriminants. If it is a class-wide type it has unknown
3396 if Has_Discriminants
(P_Type
)
3397 or else Has_Unknown_Discriminants
(P_Type
)
3399 (Is_Access_Type
(P_Type
)
3400 and then Has_Discriminants
(Designated_Type
(P_Type
)))
3404 -- The rule given in 3.7.2 is part of static semantics, but the
3405 -- intent is clearly that it be treated as a legality rule, and
3406 -- rechecked in the visible part of an instance. Nevertheless
3407 -- the intent also seems to be it should legally apply to the
3408 -- actual of a formal with unknown discriminants, regardless of
3409 -- whether the actual has discriminants, in which case the value
3410 -- of the attribute is determined using the J.4 rules. This choice
3411 -- seems the most useful, and is compatible with existing tests.
3413 elsif In_Instance
then
3416 -- Also allow an object of a generic type if extensions allowed
3417 -- and allow this for any type at all. (this may be obsolete ???)
3419 elsif (Is_Generic_Type
(P_Type
)
3420 or else Is_Generic_Actual_Type
(P_Type
))
3421 and then Extensions_Allowed
3427 -- Fall through if bad prefix
3430 ("prefix of % attribute must be object of discriminated type");
3436 when Attribute_Copy_Sign
=>
3437 Check_Floating_Point_Type_2
;
3438 Set_Etype
(N
, P_Base_Type
);
3439 Resolve
(E1
, P_Base_Type
);
3440 Resolve
(E2
, P_Base_Type
);
3446 when Attribute_Count
=> Count
:
3455 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
3458 if Ekind
(Ent
) /= E_Entry
then
3459 Error_Attr
("invalid entry name", N
);
3462 elsif Nkind
(P
) = N_Indexed_Component
then
3463 if not Is_Entity_Name
(Prefix
(P
))
3464 or else No
(Entity
(Prefix
(P
)))
3465 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
3467 if Nkind
(Prefix
(P
)) = N_Selected_Component
3468 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
3469 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
3473 ("attribute % must apply to entry of current task", P
);
3476 Error_Attr
("invalid entry family name", P
);
3481 Ent
:= Entity
(Prefix
(P
));
3484 elsif Nkind
(P
) = N_Selected_Component
3485 and then Present
(Entity
(Selector_Name
(P
)))
3486 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
3489 ("attribute % must apply to entry of current task", P
);
3492 Error_Attr
("invalid entry name", N
);
3496 for J
in reverse 0 .. Scope_Stack
.Last
loop
3497 S
:= Scope_Stack
.Table
(J
).Entity
;
3499 if S
= Scope
(Ent
) then
3500 if Nkind
(P
) = N_Expanded_Name
then
3501 Tsk
:= Entity
(Prefix
(P
));
3503 -- The prefix denotes either the task type, or else a
3504 -- single task whose task type is being analyzed.
3506 if (Is_Type
(Tsk
) and then Tsk
= S
)
3507 or else (not Is_Type
(Tsk
)
3508 and then Etype
(Tsk
) = S
3509 and then not (Comes_From_Source
(S
)))
3514 ("Attribute % must apply to entry of current task", N
);
3520 elsif Ekind
(Scope
(Ent
)) in Task_Kind
3522 not Ekind_In
(S
, E_Loop
, E_Block
, E_Entry
, E_Entry_Family
)
3524 Error_Attr
("Attribute % cannot appear in inner unit", N
);
3526 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
3527 and then not Has_Completion
(Scope
(Ent
))
3529 Error_Attr
("attribute % can only be used inside body", N
);
3533 if Is_Overloaded
(P
) then
3535 Index
: Interp_Index
;
3539 Get_First_Interp
(P
, Index
, It
);
3540 while Present
(It
.Nam
) loop
3541 if It
.Nam
= Ent
then
3544 -- Ada 2005 (AI-345): Do not consider primitive entry
3545 -- wrappers generated for task or protected types.
3547 elsif Ada_Version
>= Ada_2005
3548 and then not Comes_From_Source
(It
.Nam
)
3553 Error_Attr
("ambiguous entry name", N
);
3556 Get_Next_Interp
(Index
, It
);
3561 Set_Etype
(N
, Universal_Integer
);
3564 -----------------------
3565 -- Default_Bit_Order --
3566 -----------------------
3568 when Attribute_Default_Bit_Order
=> Default_Bit_Order
: declare
3569 Target_Default_Bit_Order
: System
.Bit_Order
;
3572 Check_Standard_Prefix
;
3574 if Bytes_Big_Endian
then
3575 Target_Default_Bit_Order
:= System
.High_Order_First
;
3577 Target_Default_Bit_Order
:= System
.Low_Order_First
;
3581 Make_Integer_Literal
(Loc
,
3582 UI_From_Int
(System
.Bit_Order
'Pos (Target_Default_Bit_Order
))));
3584 Set_Etype
(N
, Universal_Integer
);
3585 Set_Is_Static_Expression
(N
);
3586 end Default_Bit_Order
;
3588 ----------------------------------
3589 -- Default_Scalar_Storage_Order --
3590 ----------------------------------
3592 when Attribute_Default_Scalar_Storage_Order
=> Default_SSO
: declare
3593 RE_Default_SSO
: RE_Id
;
3596 Check_Standard_Prefix
;
3598 case Opt
.Default_SSO
is
3600 if Bytes_Big_Endian
then
3601 RE_Default_SSO
:= RE_High_Order_First
;
3603 RE_Default_SSO
:= RE_Low_Order_First
;
3607 RE_Default_SSO
:= RE_High_Order_First
;
3610 RE_Default_SSO
:= RE_Low_Order_First
;
3613 raise Program_Error
;
3616 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Default_SSO
), Loc
));
3623 when Attribute_Definite
=>
3624 Legal_Formal_Attribute
;
3630 when Attribute_Delta
=>
3631 Check_Fixed_Point_Type_0
;
3632 Set_Etype
(N
, Universal_Real
);
3638 when Attribute_Denorm
=>
3639 Check_Floating_Point_Type_0
;
3640 Set_Etype
(N
, Standard_Boolean
);
3646 when Attribute_Deref
=>
3649 Resolve
(E1
, RTE
(RE_Address
));
3650 Set_Etype
(N
, P_Type
);
3652 ---------------------
3653 -- Descriptor_Size --
3654 ---------------------
3656 when Attribute_Descriptor_Size
=>
3659 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
3660 Error_Attr_P
("prefix of attribute % must denote a type");
3663 Set_Etype
(N
, Universal_Integer
);
3669 when Attribute_Digits
=>
3673 if not Is_Floating_Point_Type
(P_Type
)
3674 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
3677 ("prefix of % attribute must be float or decimal type");
3680 Set_Etype
(N
, Universal_Integer
);
3686 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3688 when Attribute_Elab_Body |
3689 Attribute_Elab_Spec |
3690 Attribute_Elab_Subp_Body
=>
3693 Check_Unit_Name
(P
);
3694 Set_Etype
(N
, Standard_Void_Type
);
3696 -- We have to manually call the expander in this case to get
3697 -- the necessary expansion (normally attributes that return
3698 -- entities are not expanded).
3706 -- Shares processing with Elab_Body
3712 when Attribute_Elaborated
=>
3714 Check_Unit_Name
(P
);
3715 Set_Etype
(N
, Standard_Boolean
);
3721 when Attribute_Emax
=>
3722 Check_Floating_Point_Type_0
;
3723 Set_Etype
(N
, Universal_Integer
);
3729 when Attribute_Enabled
=>
3730 Check_Either_E0_Or_E1
;
3732 if Present
(E1
) then
3733 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
3734 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
3739 if Nkind
(P
) /= N_Identifier
then
3740 Error_Msg_N
("identifier expected (check name)", P
);
3741 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
3742 Error_Msg_N
("& is not a recognized check name", P
);
3745 Set_Etype
(N
, Standard_Boolean
);
3751 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3753 if Present
(E1
) then
3755 Check_Discrete_Type
;
3756 Resolve
(E1
, P_Base_Type
);
3758 elsif not Is_Discrete_Type
(Etype
(P
)) then
3759 Error_Attr_P
("prefix of % attribute must be of discrete type");
3762 Set_Etype
(N
, Universal_Integer
);
3769 when Attribute_Enum_Val
=> Enum_Val
: begin
3773 if not Is_Enumeration_Type
(P_Type
) then
3774 Error_Attr_P
("prefix of % attribute must be enumeration type");
3777 -- If the enumeration type has a standard representation, the effect
3778 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3780 if not Has_Non_Standard_Rep
(P_Base_Type
) then
3782 Make_Attribute_Reference
(Loc
,
3783 Prefix
=> Relocate_Node
(Prefix
(N
)),
3784 Attribute_Name
=> Name_Val
,
3785 Expressions
=> New_List
(Relocate_Node
(E1
))));
3786 Analyze_And_Resolve
(N
, P_Base_Type
);
3788 -- Non-standard representation case (enumeration with holes)
3792 Resolve
(E1
, Any_Integer
);
3793 Set_Etype
(N
, P_Base_Type
);
3801 when Attribute_Epsilon
=>
3802 Check_Floating_Point_Type_0
;
3803 Set_Etype
(N
, Universal_Real
);
3809 when Attribute_Exponent
=>
3810 Check_Floating_Point_Type_1
;
3811 Set_Etype
(N
, Universal_Integer
);
3812 Resolve
(E1
, P_Base_Type
);
3818 when Attribute_External_Tag
=>
3822 Set_Etype
(N
, Standard_String
);
3824 if not Is_Tagged_Type
(P_Type
) then
3825 Error_Attr_P
("prefix of % attribute must be tagged");
3832 when Attribute_Fast_Math
=>
3833 Check_Standard_Prefix
;
3834 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Fast_Math
), Loc
));
3840 when Attribute_First
=>
3841 Check_Array_Or_Scalar_Type
;
3842 Bad_Attribute_For_Predicate
;
3848 when Attribute_First_Bit
=>
3850 Set_Etype
(N
, Universal_Integer
);
3856 when Attribute_First_Valid
=>
3857 Check_First_Last_Valid
;
3858 Set_Etype
(N
, P_Type
);
3864 when Attribute_Fixed_Value
=>
3866 Check_Fixed_Point_Type
;
3867 Resolve
(E1
, Any_Integer
);
3868 Set_Etype
(N
, P_Base_Type
);
3874 when Attribute_Floor
=>
3875 Check_Floating_Point_Type_1
;
3876 Set_Etype
(N
, P_Base_Type
);
3877 Resolve
(E1
, P_Base_Type
);
3883 when Attribute_Fore
=>
3884 Check_Fixed_Point_Type_0
;
3885 Set_Etype
(N
, Universal_Integer
);
3891 when Attribute_Fraction
=>
3892 Check_Floating_Point_Type_1
;
3893 Set_Etype
(N
, P_Base_Type
);
3894 Resolve
(E1
, P_Base_Type
);
3900 when Attribute_From_Any
=>
3902 Check_PolyORB_Attribute
;
3903 Set_Etype
(N
, P_Base_Type
);
3905 -----------------------
3906 -- Has_Access_Values --
3907 -----------------------
3909 when Attribute_Has_Access_Values
=>
3912 Set_Etype
(N
, Standard_Boolean
);
3914 ----------------------
3915 -- Has_Same_Storage --
3916 ----------------------
3918 when Attribute_Has_Same_Storage
=>
3921 -- The arguments must be objects of any type
3923 Analyze_And_Resolve
(P
);
3924 Analyze_And_Resolve
(E1
);
3925 Check_Object_Reference
(P
);
3926 Check_Object_Reference
(E1
);
3927 Set_Etype
(N
, Standard_Boolean
);
3929 -----------------------
3930 -- Has_Tagged_Values --
3931 -----------------------
3933 when Attribute_Has_Tagged_Values
=>
3936 Set_Etype
(N
, Standard_Boolean
);
3938 -----------------------
3939 -- Has_Discriminants --
3940 -----------------------
3942 when Attribute_Has_Discriminants
=>
3943 Legal_Formal_Attribute
;
3949 when Attribute_Identity
=>
3953 if Etype
(P
) = Standard_Exception_Type
then
3954 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3956 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to task
3957 -- interface class-wide types.
3959 elsif Is_Task_Type
(Etype
(P
))
3960 or else (Is_Access_Type
(Etype
(P
))
3961 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3962 or else (Ada_Version
>= Ada_2005
3963 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3964 and then Is_Interface
(Etype
(P
))
3965 and then Is_Task_Interface
(Etype
(P
)))
3968 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3971 if Ada_Version
>= Ada_2005
then
3973 ("prefix of % attribute must be an exception, a " &
3974 "task or a task interface class-wide object");
3977 ("prefix of % attribute must be a task or an exception");
3985 when Attribute_Image
=> Image
: begin
3986 Check_SPARK_05_Restriction_On_Attribute
;
3988 -- AI12-00124-1 : The ARG has adopted the GNAT semantics of 'Img
3989 -- for scalar types, so that the prefix can be an object and not
3990 -- a type, and there is no need for an argument. Given this vote
3991 -- of confidence from the ARG, simplest is to transform this new
3992 -- usage of 'Image into a reference to 'Img.
3994 if Ada_Version
> Ada_2005
3995 and then Is_Object_Reference
(P
)
3996 and then Is_Scalar_Type
(P_Type
)
3999 Make_Attribute_Reference
(Loc
,
4000 Prefix
=> Relocate_Node
(P
),
4001 Attribute_Name
=> Name_Img
));
4009 Set_Etype
(N
, Standard_String
);
4011 if Is_Real_Type
(P_Type
) then
4012 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4013 Error_Msg_Name_1
:= Aname
;
4015 ("(Ada 83) % attribute not allowed for real types", N
);
4019 if Is_Enumeration_Type
(P_Type
) then
4020 Check_Restriction
(No_Enumeration_Maps
, N
);
4024 Resolve
(E1
, P_Base_Type
);
4026 Validate_Non_Static_Attribute_Function_Call
;
4028 -- Check restriction No_Fixed_IO. Note the check of Comes_From_Source
4029 -- to avoid giving a duplicate message for Img expanded into Image.
4031 if Restriction_Check_Required
(No_Fixed_IO
)
4032 and then Comes_From_Source
(N
)
4033 and then Is_Fixed_Point_Type
(P_Type
)
4035 Check_Restriction
(No_Fixed_IO
, P
);
4043 when Attribute_Img
=> Img
:
4046 Set_Etype
(N
, Standard_String
);
4048 if not Is_Scalar_Type
(P_Type
)
4049 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
4052 ("prefix of % attribute must be scalar object name");
4057 -- Check restriction No_Fixed_IO
4059 if Restriction_Check_Required
(No_Fixed_IO
)
4060 and then Is_Fixed_Point_Type
(P_Type
)
4062 Check_Restriction
(No_Fixed_IO
, P
);
4070 when Attribute_Input
=>
4072 Check_Stream_Attribute
(TSS_Stream_Input
);
4073 Set_Etype
(N
, P_Base_Type
);
4079 when Attribute_Integer_Value
=>
4082 Resolve
(E1
, Any_Fixed
);
4084 -- Signal an error if argument type is not a specific fixed-point
4085 -- subtype. An error has been signalled already if the argument
4086 -- was not of a fixed-point type.
4088 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
4089 Error_Attr
("argument of % must be of a fixed-point type", E1
);
4092 Set_Etype
(N
, P_Base_Type
);
4098 when Attribute_Invalid_Value
=>
4101 Set_Etype
(N
, P_Base_Type
);
4102 Invalid_Value_Used
:= True;
4108 when Attribute_Large
=>
4111 Set_Etype
(N
, Universal_Real
);
4117 when Attribute_Last
=>
4118 Check_Array_Or_Scalar_Type
;
4119 Bad_Attribute_For_Predicate
;
4125 when Attribute_Last_Bit
=>
4127 Set_Etype
(N
, Universal_Integer
);
4133 when Attribute_Last_Valid
=>
4134 Check_First_Last_Valid
;
4135 Set_Etype
(N
, P_Type
);
4141 when Attribute_Leading_Part
=>
4142 Check_Floating_Point_Type_2
;
4143 Set_Etype
(N
, P_Base_Type
);
4144 Resolve
(E1
, P_Base_Type
);
4145 Resolve
(E2
, Any_Integer
);
4151 when Attribute_Length
=>
4153 Set_Etype
(N
, Universal_Integer
);
4159 when Attribute_Library_Level
=>
4162 if not Is_Entity_Name
(P
) then
4163 Error_Attr_P
("prefix of % attribute must be an entity name");
4166 if not Inside_A_Generic
then
4167 Set_Boolean_Result
(N
,
4168 Is_Library_Level_Entity
(Entity
(P
)));
4171 Set_Etype
(N
, Standard_Boolean
);
4177 when Attribute_Lock_Free
=>
4179 Set_Etype
(N
, Standard_Boolean
);
4181 if not Is_Protected_Type
(P_Type
) then
4183 ("prefix of % attribute must be a protected object");
4190 when Attribute_Loop_Entry
=> Loop_Entry
: declare
4191 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
);
4192 -- Inspect the prefix for any uses of entities declared within the
4193 -- related loop. Loop_Id denotes the loop identifier.
4195 --------------------------------
4196 -- Check_References_In_Prefix --
4197 --------------------------------
4199 procedure Check_References_In_Prefix
(Loop_Id
: Entity_Id
) is
4200 Loop_Decl
: constant Node_Id
:= Label_Construct
(Parent
(Loop_Id
));
4202 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4203 -- Determine whether a reference mentions an entity declared
4204 -- within the related loop.
4206 function Declared_Within
(Nod
: Node_Id
) return Boolean;
4207 -- Determine whether Nod appears in the subtree of Loop_Decl
4209 ---------------------
4210 -- Check_Reference --
4211 ---------------------
4213 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4215 if Nkind
(Nod
) = N_Identifier
4216 and then Present
(Entity
(Nod
))
4217 and then Declared_Within
(Declaration_Node
(Entity
(Nod
)))
4220 ("prefix of attribute % cannot reference local entities",
4226 end Check_Reference
;
4228 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4230 ---------------------
4231 -- Declared_Within --
4232 ---------------------
4234 function Declared_Within
(Nod
: Node_Id
) return Boolean is
4239 while Present
(Stmt
) loop
4240 if Stmt
= Loop_Decl
then
4243 -- Prevent the search from going too far
4245 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4249 Stmt
:= Parent
(Stmt
);
4253 end Declared_Within
;
4255 -- Start of processing for Check_Prefix_For_Local_References
4258 Check_References
(P
);
4259 end Check_References_In_Prefix
;
4263 Context
: constant Node_Id
:= Parent
(N
);
4265 Enclosing_Loop
: Node_Id
;
4266 Loop_Id
: Entity_Id
:= Empty
;
4269 Enclosing_Pragma
: Node_Id
:= Empty
;
4271 -- Start of processing for Loop_Entry
4276 -- Set the type of the attribute now to ensure the successfull
4277 -- continuation of analysis even if the attribute is misplaced.
4279 Set_Etype
(Attr
, P_Type
);
4281 -- Attribute 'Loop_Entry may appear in several flavors:
4283 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
4284 -- nearest enclosing loop.
4286 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
4287 -- attribute may be related to a loop denoted by label Expr or
4288 -- the prefix may denote an array object and Expr may act as an
4289 -- indexed component.
4291 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
4292 -- to the nearest enclosing loop, all expressions are part of
4293 -- an indexed component.
4295 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
4296 -- denotes, the attribute may be related to a loop denoted by
4297 -- label Expr or the prefix may denote a multidimensional array
4298 -- array object and Expr along with the rest of the expressions
4299 -- may act as indexed components.
4301 -- Regardless of variations, the attribute reference does not have an
4302 -- expression list. Instead, all available expressions are stored as
4303 -- indexed components.
4305 -- When the attribute is part of an indexed component, find the first
4306 -- expression as it will determine the semantics of 'Loop_Entry.
4308 if Nkind
(Context
) = N_Indexed_Component
then
4309 E1
:= First
(Expressions
(Context
));
4312 -- The attribute reference appears in the following form:
4314 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
4316 -- In this case, the loop name is omitted and no rewriting is
4319 if Present
(E2
) then
4322 -- The form of the attribute is:
4324 -- Prefix'Loop_Entry (Expr) [(...)]
4326 -- If Expr denotes a loop entry, the whole attribute and indexed
4327 -- component will have to be rewritten to reflect this relation.
4330 pragma Assert
(Present
(E1
));
4332 -- Do not expand the expression as it may have side effects.
4333 -- Simply preanalyze to determine whether it is a loop name or
4336 Preanalyze_And_Resolve
(E1
);
4338 if Is_Entity_Name
(E1
)
4339 and then Present
(Entity
(E1
))
4340 and then Ekind
(Entity
(E1
)) = E_Loop
4342 Loop_Id
:= Entity
(E1
);
4344 -- Transform the attribute and enclosing indexed component
4346 Set_Expressions
(N
, Expressions
(Context
));
4347 Rewrite
(Context
, N
);
4348 Set_Etype
(Context
, P_Type
);
4355 -- The prefix must denote an object
4357 if not Is_Object_Reference
(P
) then
4358 Error_Attr_P
("prefix of attribute % must denote an object");
4361 -- The prefix cannot be of a limited type because the expansion of
4362 -- Loop_Entry must create a constant initialized by the evaluated
4365 if Is_Limited_View
(Etype
(P
)) then
4366 Error_Attr_P
("prefix of attribute % cannot be limited");
4369 -- Climb the parent chain to verify the location of the attribute and
4370 -- find the enclosing loop.
4373 while Present
(Stmt
) loop
4375 -- Locate the corresponding enclosing pragma. Note that in the
4376 -- case of Assert[And_Cut] and Assume, we have already checked
4377 -- that the pragma appears in an appropriate loop location.
4379 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
4380 and then Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
4381 Name_Loop_Invariant
,
4384 Name_Assert_And_Cut
,
4387 Enclosing_Pragma
:= Original_Node
(Stmt
);
4389 -- Locate the enclosing loop (if any). Note that Ada 2012 array
4390 -- iteration may be expanded into several nested loops, we are
4391 -- interested in the outermost one which has the loop identifier,
4392 -- and comes from source.
4394 elsif Nkind
(Stmt
) = N_Loop_Statement
4395 and then Present
(Identifier
(Stmt
))
4396 and then Comes_From_Source
(Original_Node
(Stmt
))
4397 and then Nkind
(Original_Node
(Stmt
)) = N_Loop_Statement
4399 Enclosing_Loop
:= Stmt
;
4401 -- The original attribute reference may lack a loop name. Use
4402 -- the name of the enclosing loop because it is the related
4405 if No
(Loop_Id
) then
4406 Loop_Id
:= Entity
(Identifier
(Enclosing_Loop
));
4411 -- Prevent the search from going too far
4413 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
4417 Stmt
:= Parent
(Stmt
);
4420 -- Loop_Entry must appear within a Loop_Assertion pragma (Assert,
4421 -- Assert_And_Cut, Assume count as loop assertion pragmas for this
4422 -- purpose if they appear in an appropriate location in a loop,
4423 -- which was already checked by the top level pragma circuit).
4425 if No
(Enclosing_Pragma
) then
4426 Error_Attr
("attribute% must appear within appropriate pragma", N
);
4429 -- A Loop_Entry that applies to a given loop statement must not
4430 -- appear within a body of accept statement, if this construct is
4431 -- itself enclosed by the given loop statement.
4433 for Index
in reverse 0 .. Scope_Stack
.Last
loop
4434 Scop
:= Scope_Stack
.Table
(Index
).Entity
;
4436 if Ekind
(Scop
) = E_Loop
and then Scop
= Loop_Id
then
4438 elsif Ekind_In
(Scop
, E_Block
, E_Loop
, E_Return_Statement
) then
4442 ("attribute % cannot appear in body or accept statement", N
);
4447 -- The prefix cannot mention entities declared within the related
4448 -- loop because they will not be visible once the prefix is moved
4449 -- outside the loop.
4451 Check_References_In_Prefix
(Loop_Id
);
4453 -- The prefix must denote a static entity if the pragma does not
4454 -- apply to the innermost enclosing loop statement, or if it appears
4455 -- within a potentially unevaluated epxression.
4457 if Is_Entity_Name
(P
)
4458 or else Nkind
(Parent
(P
)) = N_Object_Renaming_Declaration
4462 elsif Present
(Enclosing_Loop
)
4463 and then Entity
(Identifier
(Enclosing_Loop
)) /= Loop_Id
4466 ("prefix of attribute % that applies to outer loop must denote "
4469 elsif Is_Potentially_Unevaluated
(P
) then
4473 -- Replace the Loop_Entry attribute reference by its prefix if the
4474 -- related pragma is ignored. This transformation is OK with respect
4475 -- to typing because Loop_Entry's type is that of its prefix. This
4476 -- early transformation also avoids the generation of a useless loop
4479 if Is_Ignored
(Enclosing_Pragma
) then
4480 Rewrite
(N
, Relocate_Node
(P
));
4483 Preanalyze_And_Resolve
(P
);
4490 when Attribute_Machine
=>
4491 Check_Floating_Point_Type_1
;
4492 Set_Etype
(N
, P_Base_Type
);
4493 Resolve
(E1
, P_Base_Type
);
4499 when Attribute_Machine_Emax
=>
4500 Check_Floating_Point_Type_0
;
4501 Set_Etype
(N
, Universal_Integer
);
4507 when Attribute_Machine_Emin
=>
4508 Check_Floating_Point_Type_0
;
4509 Set_Etype
(N
, Universal_Integer
);
4511 ----------------------
4512 -- Machine_Mantissa --
4513 ----------------------
4515 when Attribute_Machine_Mantissa
=>
4516 Check_Floating_Point_Type_0
;
4517 Set_Etype
(N
, Universal_Integer
);
4519 -----------------------
4520 -- Machine_Overflows --
4521 -----------------------
4523 when Attribute_Machine_Overflows
=>
4526 Set_Etype
(N
, Standard_Boolean
);
4532 when Attribute_Machine_Radix
=>
4535 Set_Etype
(N
, Universal_Integer
);
4537 ----------------------
4538 -- Machine_Rounding --
4539 ----------------------
4541 when Attribute_Machine_Rounding
=>
4542 Check_Floating_Point_Type_1
;
4543 Set_Etype
(N
, P_Base_Type
);
4544 Resolve
(E1
, P_Base_Type
);
4546 --------------------
4547 -- Machine_Rounds --
4548 --------------------
4550 when Attribute_Machine_Rounds
=>
4553 Set_Etype
(N
, Standard_Boolean
);
4559 when Attribute_Machine_Size
=>
4562 Check_Not_Incomplete_Type
;
4563 Set_Etype
(N
, Universal_Integer
);
4569 when Attribute_Mantissa
=>
4572 Set_Etype
(N
, Universal_Integer
);
4578 when Attribute_Max
=>
4581 ----------------------------------
4582 -- Max_Alignment_For_Allocation --
4583 ----------------------------------
4585 when Attribute_Max_Size_In_Storage_Elements
=>
4586 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4588 ----------------------------------
4589 -- Max_Size_In_Storage_Elements --
4590 ----------------------------------
4592 when Attribute_Max_Alignment_For_Allocation
=>
4593 Max_Alignment_For_Allocation_Max_Size_In_Storage_Elements
;
4595 -----------------------
4596 -- Maximum_Alignment --
4597 -----------------------
4599 when Attribute_Maximum_Alignment
=>
4600 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
4602 --------------------
4603 -- Mechanism_Code --
4604 --------------------
4606 when Attribute_Mechanism_Code
=>
4607 if not Is_Entity_Name
(P
)
4608 or else not Is_Subprogram
(Entity
(P
))
4610 Error_Attr_P
("prefix of % attribute must be subprogram");
4613 Check_Either_E0_Or_E1
;
4615 if Present
(E1
) then
4616 Resolve
(E1
, Any_Integer
);
4617 Set_Etype
(E1
, Standard_Integer
);
4619 if not Is_OK_Static_Expression
(E1
) then
4620 Flag_Non_Static_Expr
4621 ("expression for parameter number must be static!", E1
);
4624 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
4625 or else UI_To_Int
(Intval
(E1
)) < 0
4627 Error_Attr
("invalid parameter number for % attribute", E1
);
4631 Set_Etype
(N
, Universal_Integer
);
4637 when Attribute_Min
=>
4644 when Attribute_Mod
=>
4646 -- Note: this attribute is only allowed in Ada 2005 mode, but
4647 -- we do not need to test that here, since Mod is only recognized
4648 -- as an attribute name in Ada 2005 mode during the parse.
4651 Check_Modular_Integer_Type
;
4652 Resolve
(E1
, Any_Integer
);
4653 Set_Etype
(N
, P_Base_Type
);
4659 when Attribute_Model
=>
4660 Check_Floating_Point_Type_1
;
4661 Set_Etype
(N
, P_Base_Type
);
4662 Resolve
(E1
, P_Base_Type
);
4668 when Attribute_Model_Emin
=>
4669 Check_Floating_Point_Type_0
;
4670 Set_Etype
(N
, Universal_Integer
);
4676 when Attribute_Model_Epsilon
=>
4677 Check_Floating_Point_Type_0
;
4678 Set_Etype
(N
, Universal_Real
);
4680 --------------------
4681 -- Model_Mantissa --
4682 --------------------
4684 when Attribute_Model_Mantissa
=>
4685 Check_Floating_Point_Type_0
;
4686 Set_Etype
(N
, Universal_Integer
);
4692 when Attribute_Model_Small
=>
4693 Check_Floating_Point_Type_0
;
4694 Set_Etype
(N
, Universal_Real
);
4700 when Attribute_Modulus
=>
4702 Check_Modular_Integer_Type
;
4703 Set_Etype
(N
, Universal_Integer
);
4705 --------------------
4706 -- Null_Parameter --
4707 --------------------
4709 when Attribute_Null_Parameter
=> Null_Parameter
: declare
4710 Parnt
: constant Node_Id
:= Parent
(N
);
4711 GParnt
: constant Node_Id
:= Parent
(Parnt
);
4713 procedure Bad_Null_Parameter
(Msg
: String);
4714 -- Used if bad Null parameter attribute node is found. Issues
4715 -- given error message, and also sets the type to Any_Type to
4716 -- avoid blowups later on from dealing with a junk node.
4718 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
4719 -- Called to check that Proc_Ent is imported subprogram
4721 ------------------------
4722 -- Bad_Null_Parameter --
4723 ------------------------
4725 procedure Bad_Null_Parameter
(Msg
: String) is
4727 Error_Msg_N
(Msg
, N
);
4728 Set_Etype
(N
, Any_Type
);
4729 end Bad_Null_Parameter
;
4731 ----------------------
4732 -- Must_Be_Imported --
4733 ----------------------
4735 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
4736 Pent
: constant Entity_Id
:= Ultimate_Alias
(Proc_Ent
);
4739 -- Ignore check if procedure not frozen yet (we will get
4740 -- another chance when the default parameter is reanalyzed)
4742 if not Is_Frozen
(Pent
) then
4745 elsif not Is_Imported
(Pent
) then
4747 ("Null_Parameter can only be used with imported subprogram");
4752 end Must_Be_Imported
;
4754 -- Start of processing for Null_Parameter
4759 Set_Etype
(N
, P_Type
);
4761 -- Case of attribute used as default expression
4763 if Nkind
(Parnt
) = N_Parameter_Specification
then
4764 Must_Be_Imported
(Defining_Entity
(GParnt
));
4766 -- Case of attribute used as actual for subprogram (positional)
4768 elsif Nkind
(Parnt
) in N_Subprogram_Call
4769 and then Is_Entity_Name
(Name
(Parnt
))
4771 Must_Be_Imported
(Entity
(Name
(Parnt
)));
4773 -- Case of attribute used as actual for subprogram (named)
4775 elsif Nkind
(Parnt
) = N_Parameter_Association
4776 and then Nkind
(GParnt
) in N_Subprogram_Call
4777 and then Is_Entity_Name
(Name
(GParnt
))
4779 Must_Be_Imported
(Entity
(Name
(GParnt
)));
4781 -- Not an allowed case
4785 ("Null_Parameter must be actual or default parameter");
4793 when Attribute_Object_Size
=>
4796 Check_Not_Incomplete_Type
;
4797 Set_Etype
(N
, Universal_Integer
);
4803 when Attribute_Old
=> Old
: declare
4804 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
);
4805 -- Inspect the contents of the prefix and detect illegal uses of a
4806 -- nested 'Old, attribute 'Result or a use of an entity declared in
4807 -- the related postcondition expression. Subp_Id is the subprogram to
4808 -- which the related postcondition applies.
4810 --------------------------------
4811 -- Check_References_In_Prefix --
4812 --------------------------------
4814 procedure Check_References_In_Prefix
(Subp_Id
: Entity_Id
) is
4815 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
;
4816 -- Detect attribute 'Old, attribute 'Result of a use of an entity
4817 -- and perform the appropriate semantic check.
4819 ---------------------
4820 -- Check_Reference --
4821 ---------------------
4823 function Check_Reference
(Nod
: Node_Id
) return Traverse_Result
is
4825 -- Attributes 'Old and 'Result cannot appear in the prefix of
4826 -- another attribute 'Old.
4828 if Nkind
(Nod
) = N_Attribute_Reference
4829 and then Nam_In
(Attribute_Name
(Nod
), Name_Old
,
4832 Error_Msg_Name_1
:= Attribute_Name
(Nod
);
4833 Error_Msg_Name_2
:= Name_Old
;
4835 ("attribute % cannot appear in the prefix of attribute %",
4839 -- Entities mentioned within the prefix of attribute 'Old must
4840 -- be global to the related postcondition. If this is not the
4841 -- case, then the scope of the local entity is nested within
4842 -- that of the subprogram.
4844 elsif Is_Entity_Name
(Nod
)
4845 and then Present
(Entity
(Nod
))
4846 and then Scope_Within
(Scope
(Entity
(Nod
)), Subp_Id
)
4849 ("prefix of attribute % cannot reference local entities",
4853 -- Otherwise keep inspecting the prefix
4858 end Check_Reference
;
4860 procedure Check_References
is new Traverse_Proc
(Check_Reference
);
4862 -- Start of processing for Check_References_In_Prefix
4865 Check_References
(P
);
4866 end Check_References_In_Prefix
;
4871 Pref_Id
: Entity_Id
;
4872 Pref_Typ
: Entity_Id
;
4873 Spec_Id
: Entity_Id
;
4875 -- Start of processing for Old
4878 -- The attribute reference is a primary. If any expressions follow,
4879 -- then the attribute reference is an indexable object. Transform the
4880 -- attribute into an indexed component and analyze it.
4882 if Present
(E1
) then
4884 Make_Indexed_Component
(Loc
,
4886 Make_Attribute_Reference
(Loc
,
4887 Prefix
=> Relocate_Node
(P
),
4888 Attribute_Name
=> Name_Old
),
4889 Expressions
=> Expressions
(N
)));
4894 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
4896 -- The aspect or pragma where attribute 'Old resides should be
4897 -- associated with a subprogram declaration or a body. If this is not
4898 -- the case, then the aspect or pragma is illegal. Return as analysis
4899 -- cannot be carried out.
4901 -- The exception to this rule is when generating C since in this case
4902 -- postconditions are inlined.
4905 and then Modify_Tree_For_C
4906 and then In_Inlined_Body
4908 Spec_Id
:= Entity
(P
);
4910 elsif not Legal
then
4914 -- The prefix must be preanalyzed as the full analysis will take
4915 -- place during expansion.
4917 Preanalyze_And_Resolve
(P
);
4919 -- Ensure that the prefix does not contain attributes 'Old or 'Result
4921 Check_References_In_Prefix
(Spec_Id
);
4923 -- Set the type of the attribute now to prevent cascaded errors
4925 Pref_Typ
:= Etype
(P
);
4926 Set_Etype
(N
, Pref_Typ
);
4930 if Is_Limited_Type
(Pref_Typ
) then
4931 Error_Attr
("attribute % cannot apply to limited objects", P
);
4934 -- The prefix is a simple name
4936 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
4937 Pref_Id
:= Entity
(P
);
4939 -- Emit a warning when the prefix is a constant. Note that the use
4940 -- of Error_Attr would reset the type of N to Any_Type even though
4941 -- this is a warning. Use Error_Msg_XXX instead.
4943 if Is_Constant_Object
(Pref_Id
) then
4944 Error_Msg_Name_1
:= Name_Old
;
4946 ("??attribute % applied to constant has no effect", P
);
4949 -- Otherwise the prefix is not a simple name
4952 -- Ensure that the prefix of attribute 'Old is an entity when it
4953 -- is potentially unevaluated (6.1.1 (27/3)).
4955 if Is_Potentially_Unevaluated
(N
) then
4958 -- Detect a possible infinite recursion when the prefix denotes
4959 -- the related function.
4961 -- function Func (...) return ...
4962 -- with Post => Func'Old ...;
4964 -- The function may be specified in qualified form X.Y where X is
4965 -- a protected object and Y is a protected function. In that case
4966 -- ensure that the qualified form has an entity.
4968 elsif Nkind
(P
) = N_Function_Call
4969 and then Nkind
(Name
(P
)) in N_Has_Entity
4971 Pref_Id
:= Entity
(Name
(P
));
4973 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
4974 and then Pref_Id
= Spec_Id
4976 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4977 Error_Msg_N
("!possible infinite recursion<<", P
);
4978 Error_Msg_N
("\!??Storage_Error ]<<", P
);
4982 -- The prefix of attribute 'Old may refer to a component of a
4983 -- formal parameter. In this case its expansion may generate
4984 -- actual subtypes that are referenced in an inner context and
4985 -- that must be elaborated within the subprogram itself. If the
4986 -- prefix includes a function call, it may involve finalization
4987 -- actions that should be inserted when the attribute has been
4988 -- rewritten as a declaration. Create a declaration for the prefix
4989 -- and insert it at the start of the enclosing subprogram. This is
4990 -- an expansion activity that has to be performed now to prevent
4991 -- out-of-order issues.
4993 -- This expansion is both harmful and not needed in SPARK mode,
4994 -- since the formal verification back end relies on the types of
4995 -- nodes (hence is not robust w.r.t. a change to base type here),
4996 -- and does not suffer from the out-of-order issue described
4997 -- above. Thus, this expansion is skipped in SPARK mode.
4999 -- The expansion is not relevant for discrete types, which will
5000 -- not generate extra declarations, and where use of the base type
5001 -- may lead to spurious errors if context is a case.
5003 if not GNATprove_Mode
then
5004 if not Is_Discrete_Type
(Pref_Typ
) then
5005 Pref_Typ
:= Base_Type
(Pref_Typ
);
5008 Set_Etype
(N
, Pref_Typ
);
5009 Set_Etype
(P
, Pref_Typ
);
5011 Analyze_Dimension
(N
);
5017 ----------------------
5018 -- Overlaps_Storage --
5019 ----------------------
5021 when Attribute_Overlaps_Storage
=>
5024 -- Both arguments must be objects of any type
5026 Analyze_And_Resolve
(P
);
5027 Analyze_And_Resolve
(E1
);
5028 Check_Object_Reference
(P
);
5029 Check_Object_Reference
(E1
);
5030 Set_Etype
(N
, Standard_Boolean
);
5036 when Attribute_Output
=>
5038 Check_Stream_Attribute
(TSS_Stream_Output
);
5039 Set_Etype
(N
, Standard_Void_Type
);
5040 Resolve
(N
, Standard_Void_Type
);
5046 when Attribute_Partition_ID
=> Partition_Id
:
5050 if P_Type
/= Any_Type
then
5051 if not Is_Library_Level_Entity
(Entity
(P
)) then
5053 ("prefix of % attribute must be library-level entity");
5055 -- The defining entity of prefix should not be declared inside a
5056 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
5058 elsif Is_Entity_Name
(P
)
5059 and then Is_Pure
(Entity
(P
))
5061 Error_Attr_P
("prefix of% attribute must not be declared pure");
5065 Set_Etype
(N
, Universal_Integer
);
5068 -------------------------
5069 -- Passed_By_Reference --
5070 -------------------------
5072 when Attribute_Passed_By_Reference
=>
5075 Set_Etype
(N
, Standard_Boolean
);
5081 when Attribute_Pool_Address
=>
5083 Set_Etype
(N
, RTE
(RE_Address
));
5089 when Attribute_Pos
=>
5090 Check_Discrete_Type
;
5093 if Is_Boolean_Type
(P_Type
) then
5094 Error_Msg_Name_1
:= Aname
;
5095 Error_Msg_Name_2
:= Chars
(P_Type
);
5096 Check_SPARK_05_Restriction
5097 ("attribute% is not allowed for type%", P
);
5100 Resolve
(E1
, P_Base_Type
);
5101 Set_Etype
(N
, Universal_Integer
);
5107 when Attribute_Position
=>
5109 Set_Etype
(N
, Universal_Integer
);
5115 when Attribute_Pred
=>
5119 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5120 Error_Msg_Name_1
:= Aname
;
5121 Error_Msg_Name_2
:= Chars
(P_Type
);
5122 Check_SPARK_05_Restriction
5123 ("attribute% is not allowed for type%", P
);
5126 Resolve
(E1
, P_Base_Type
);
5127 Set_Etype
(N
, P_Base_Type
);
5129 -- Since Pred works on the base type, we normally do no check for the
5130 -- floating-point case, since the base type is unconstrained. But we
5131 -- make an exception in Check_Float_Overflow mode.
5133 if Is_Floating_Point_Type
(P_Type
) then
5134 if not Range_Checks_Suppressed
(P_Base_Type
) then
5135 Set_Do_Range_Check
(E1
);
5138 -- If not modular type, test for overflow check required
5141 if not Is_Modular_Integer_Type
(P_Type
)
5142 and then not Range_Checks_Suppressed
(P_Base_Type
)
5144 Enable_Range_Check
(E1
);
5152 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5154 when Attribute_Priority
=>
5155 if Ada_Version
< Ada_2005
then
5156 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
5161 -- The prefix must be a protected object (AARM D.5.2 (2/2))
5165 if Is_Protected_Type
(Etype
(P
))
5166 or else (Is_Access_Type
(Etype
(P
))
5167 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
5169 Resolve
(P
, Etype
(P
));
5171 Error_Attr_P
("prefix of % attribute must be a protected object");
5174 Set_Etype
(N
, Standard_Integer
);
5176 -- Must be called from within a protected procedure or entry of the
5177 -- protected object.
5184 while S
/= Etype
(P
)
5185 and then S
/= Standard_Standard
5190 if S
= Standard_Standard
then
5191 Error_Attr
("the attribute % is only allowed inside protected "
5196 Validate_Non_Static_Attribute_Function_Call
;
5202 when Attribute_Range
=>
5203 Check_Array_Or_Scalar_Type
;
5204 Bad_Attribute_For_Predicate
;
5206 if Ada_Version
= Ada_83
5207 and then Is_Scalar_Type
(P_Type
)
5208 and then Comes_From_Source
(N
)
5211 ("(Ada 83) % attribute not allowed for scalar type", P
);
5218 when Attribute_Result
=> Result
: declare
5219 function Denote_Same_Function
5220 (Pref_Id
: Entity_Id
;
5221 Spec_Id
: Entity_Id
) return Boolean;
5222 -- Determine whether the entity of the prefix Pref_Id denotes the
5223 -- same entity as that of the related subprogram Spec_Id.
5225 --------------------------
5226 -- Denote_Same_Function --
5227 --------------------------
5229 function Denote_Same_Function
5230 (Pref_Id
: Entity_Id
;
5231 Spec_Id
: Entity_Id
) return Boolean
5233 Over_Id
: constant Entity_Id
:= Overridden_Operation
(Spec_Id
);
5234 Subp_Spec
: constant Node_Id
:= Parent
(Spec_Id
);
5237 -- The prefix denotes the related subprogram
5239 if Pref_Id
= Spec_Id
then
5242 -- Account for a special case when attribute 'Result appears in
5243 -- the postcondition of a generic function.
5246 -- function Gen_Func return ...
5247 -- with Post => Gen_Func'Result ...;
5249 -- When the generic function is instantiated, the Chars field of
5250 -- the instantiated prefix still denotes the name of the generic
5251 -- function. Note that any preemptive transformation is impossible
5252 -- without a proper analysis. The structure of the wrapper package
5255 -- package Anon_Gen_Pack is
5256 -- <subtypes and renamings>
5257 -- function Subp_Decl return ...; -- (!)
5258 -- pragma Postcondition (Gen_Func'Result ...); -- (!)
5259 -- function Gen_Func ... renames Subp_Decl;
5260 -- end Anon_Gen_Pack;
5262 elsif Nkind
(Subp_Spec
) = N_Function_Specification
5263 and then Present
(Generic_Parent
(Subp_Spec
))
5264 and then Ekind_In
(Pref_Id
, E_Generic_Function
, E_Function
)
5266 if Generic_Parent
(Subp_Spec
) = Pref_Id
then
5269 elsif Present
(Alias
(Pref_Id
))
5270 and then Alias
(Pref_Id
) = Spec_Id
5275 -- Account for a special case where a primitive of a tagged type
5276 -- inherits a class-wide postcondition from a parent type. In this
5277 -- case the prefix of attribute 'Result denotes the overriding
5280 elsif Present
(Over_Id
) and then Pref_Id
= Over_Id
then
5284 -- Otherwise the prefix does not denote the related subprogram
5287 end Denote_Same_Function
;
5291 In_Inlined_C_Postcondition
: constant Boolean :=
5293 and then In_Inlined_Body
;
5296 Pref_Id
: Entity_Id
;
5297 Spec_Id
: Entity_Id
;
5299 -- Start of processing for Result
5302 -- The attribute reference is a primary. If any expressions follow,
5303 -- then the attribute reference is an indexable object. Transform the
5304 -- attribute into an indexed component and analyze it.
5306 if Present
(E1
) then
5308 Make_Indexed_Component
(Loc
,
5310 Make_Attribute_Reference
(Loc
,
5311 Prefix
=> Relocate_Node
(P
),
5312 Attribute_Name
=> Name_Result
),
5313 Expressions
=> Expressions
(N
)));
5318 Analyze_Attribute_Old_Result
(Legal
, Spec_Id
);
5320 -- The aspect or pragma where attribute 'Result resides should be
5321 -- associated with a subprogram declaration or a body. If this is not
5322 -- the case, then the aspect or pragma is illegal. Return as analysis
5323 -- cannot be carried out.
5325 -- The exception to this rule is when generating C since in this case
5326 -- postconditions are inlined.
5328 if No
(Spec_Id
) and then In_Inlined_C_Postcondition
then
5329 Spec_Id
:= Entity
(P
);
5331 elsif not Legal
then
5335 -- Attribute 'Result is part of a _Postconditions procedure. There is
5336 -- no need to perform the semantic checks below as they were already
5337 -- verified when the attribute was analyzed in its original context.
5338 -- Instead, rewrite the attribute as a reference to formal parameter
5339 -- _Result of the _Postconditions procedure.
5341 if Chars
(Spec_Id
) = Name_uPostconditions
5343 (In_Inlined_C_Postcondition
5344 and then Nkind
(Parent
(Spec_Id
)) = N_Block_Statement
)
5346 Rewrite
(N
, Make_Identifier
(Loc
, Name_uResult
));
5348 -- The type of formal parameter _Result is that of the function
5349 -- encapsulating the _Postconditions procedure. Resolution must
5350 -- be carried out against the function return type.
5352 Analyze_And_Resolve
(N
, Etype
(Scope
(Spec_Id
)));
5354 -- Otherwise attribute 'Result appears in its original context and
5355 -- all semantic checks should be carried out.
5358 -- Verify the legality of the prefix. It must denotes the entity
5359 -- of the related [generic] function.
5361 if Is_Entity_Name
(P
) then
5362 Pref_Id
:= Entity
(P
);
5364 if Ekind_In
(Pref_Id
, E_Function
, E_Generic_Function
)
5365 and then Ekind
(Spec_Id
) = Ekind
(Pref_Id
)
5367 if Denote_Same_Function
(Pref_Id
, Spec_Id
) then
5369 -- Correct the prefix of the attribute when the context
5370 -- is a generic function.
5372 if Pref_Id
/= Spec_Id
then
5373 Rewrite
(P
, New_Occurrence_Of
(Spec_Id
, Loc
));
5377 Set_Etype
(N
, Etype
(Spec_Id
));
5379 -- Otherwise the prefix denotes some unrelated function
5382 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5384 ("incorrect prefix for attribute %, expected %", P
);
5387 -- Otherwise the prefix denotes some other form of subprogram
5392 ("attribute % can only appear in postcondition of "
5396 -- Otherwise the prefix is illegal
5399 Error_Msg_Name_2
:= Chars
(Spec_Id
);
5400 Error_Attr
("incorrect prefix for attribute %, expected %", P
);
5409 when Attribute_Range_Length
=>
5411 Check_Discrete_Type
;
5412 Set_Etype
(N
, Universal_Integer
);
5418 when Attribute_Read
=>
5420 Check_Stream_Attribute
(TSS_Stream_Read
);
5421 Set_Etype
(N
, Standard_Void_Type
);
5422 Resolve
(N
, Standard_Void_Type
);
5423 Note_Possible_Modification
(E2
, Sure
=> True);
5429 when Attribute_Ref
=>
5433 if Nkind
(P
) /= N_Expanded_Name
5434 or else not Is_RTE
(P_Type
, RE_Address
)
5436 Error_Attr_P
("prefix of % attribute must be System.Address");
5439 Analyze_And_Resolve
(E1
, Any_Integer
);
5440 Set_Etype
(N
, RTE
(RE_Address
));
5446 when Attribute_Remainder
=>
5447 Check_Floating_Point_Type_2
;
5448 Set_Etype
(N
, P_Base_Type
);
5449 Resolve
(E1
, P_Base_Type
);
5450 Resolve
(E2
, P_Base_Type
);
5452 ---------------------
5453 -- Restriction_Set --
5454 ---------------------
5456 when Attribute_Restriction_Set
=> Restriction_Set
: declare
5459 Unam
: Unit_Name_Type
;
5464 Check_System_Prefix
;
5466 -- No_Dependence case
5468 if Nkind
(E1
) = N_Parameter_Association
then
5469 pragma Assert
(Chars
(Selector_Name
(E1
)) = Name_No_Dependence
);
5470 U
:= Explicit_Actual_Parameter
(E1
);
5472 if not OK_No_Dependence_Unit_Name
(U
) then
5473 Set_Boolean_Result
(N
, False);
5477 -- See if there is an entry already in the table. That's the
5478 -- case in which we can return True.
5480 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
5481 if Designate_Same_Unit
(U
, No_Dependences
.Table
(J
).Unit
)
5482 and then No_Dependences
.Table
(J
).Warn
= False
5484 Set_Boolean_Result
(N
, True);
5489 -- If not in the No_Dependence table, result is False
5491 Set_Boolean_Result
(N
, False);
5493 -- In this case, we must ensure that the binder will reject any
5494 -- other unit in the partition that sets No_Dependence for this
5495 -- unit. We do that by making an entry in the special table kept
5496 -- for this purpose (if the entry is not there already).
5498 Unam
:= Get_Spec_Name
(Get_Unit_Name
(U
));
5500 for J
in Restriction_Set_Dependences
.First
..
5501 Restriction_Set_Dependences
.Last
5503 if Restriction_Set_Dependences
.Table
(J
) = Unam
then
5508 Restriction_Set_Dependences
.Append
(Unam
);
5510 -- Normal restriction case
5513 if Nkind
(E1
) /= N_Identifier
then
5514 Set_Boolean_Result
(N
, False);
5515 Error_Attr
("attribute % requires restriction identifier", E1
);
5518 R
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(E1
));
5520 if R
= Not_A_Restriction_Id
then
5521 Set_Boolean_Result
(N
, False);
5522 Error_Msg_Node_1
:= E1
;
5523 Error_Attr
("invalid restriction identifier &", E1
);
5525 elsif R
not in Partition_Boolean_Restrictions
then
5526 Set_Boolean_Result
(N
, False);
5527 Error_Msg_Node_1
:= E1
;
5529 ("& is not a boolean partition-wide restriction", E1
);
5532 if Restriction_Active
(R
) then
5533 Set_Boolean_Result
(N
, True);
5535 Check_Restriction
(R
, N
);
5536 Set_Boolean_Result
(N
, False);
5540 end Restriction_Set
;
5546 when Attribute_Round
=>
5548 Check_Decimal_Fixed_Point_Type
;
5549 Set_Etype
(N
, P_Base_Type
);
5551 -- Because the context is universal_real (3.5.10(12)) it is a
5552 -- legal context for a universal fixed expression. This is the
5553 -- only attribute whose functional description involves U_R.
5555 if Etype
(E1
) = Universal_Fixed
then
5557 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
5558 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
5559 Expression
=> Relocate_Node
(E1
));
5567 Resolve
(E1
, Any_Real
);
5573 when Attribute_Rounding
=>
5574 Check_Floating_Point_Type_1
;
5575 Set_Etype
(N
, P_Base_Type
);
5576 Resolve
(E1
, P_Base_Type
);
5582 when Attribute_Safe_Emax
=>
5583 Check_Floating_Point_Type_0
;
5584 Set_Etype
(N
, Universal_Integer
);
5590 when Attribute_Safe_First
=>
5591 Check_Floating_Point_Type_0
;
5592 Set_Etype
(N
, Universal_Real
);
5598 when Attribute_Safe_Large
=>
5601 Set_Etype
(N
, Universal_Real
);
5607 when Attribute_Safe_Last
=>
5608 Check_Floating_Point_Type_0
;
5609 Set_Etype
(N
, Universal_Real
);
5615 when Attribute_Safe_Small
=>
5618 Set_Etype
(N
, Universal_Real
);
5620 --------------------------
5621 -- Scalar_Storage_Order --
5622 --------------------------
5624 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
:
5626 Ent
: Entity_Id
:= Empty
;
5632 if not (Is_Record_Type
(P_Type
) or else Is_Array_Type
(P_Type
)) then
5634 -- In GNAT mode, the attribute applies to generic types as well
5635 -- as composite types, and for non-composite types always returns
5636 -- the default bit order for the target.
5638 if not (GNAT_Mode
and then Is_Generic_Type
(P_Type
))
5639 and then not In_Instance
5642 ("prefix of % attribute must be record or array type");
5644 elsif not Is_Generic_Type
(P_Type
) then
5645 if Bytes_Big_Endian
then
5646 Ent
:= RTE
(RE_High_Order_First
);
5648 Ent
:= RTE
(RE_Low_Order_First
);
5652 elsif Bytes_Big_Endian
xor Reverse_Storage_Order
(P_Type
) then
5653 Ent
:= RTE
(RE_High_Order_First
);
5656 Ent
:= RTE
(RE_Low_Order_First
);
5659 if Present
(Ent
) then
5660 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
5663 Set_Etype
(N
, RTE
(RE_Bit_Order
));
5666 -- Reset incorrect indication of staticness
5668 Set_Is_Static_Expression
(N
, False);
5669 end Scalar_Storage_Order
;
5675 when Attribute_Scale
=>
5677 Check_Decimal_Fixed_Point_Type
;
5678 Set_Etype
(N
, Universal_Integer
);
5684 when Attribute_Scaling
=>
5685 Check_Floating_Point_Type_2
;
5686 Set_Etype
(N
, P_Base_Type
);
5687 Resolve
(E1
, P_Base_Type
);
5693 when Attribute_Signed_Zeros
=>
5694 Check_Floating_Point_Type_0
;
5695 Set_Etype
(N
, Standard_Boolean
);
5701 when Attribute_Size | Attribute_VADS_Size
=> Size
:
5705 -- If prefix is parameterless function call, rewrite and resolve
5708 if Is_Entity_Name
(P
)
5709 and then Ekind
(Entity
(P
)) = E_Function
5713 -- Similar processing for a protected function call
5715 elsif Nkind
(P
) = N_Selected_Component
5716 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
5721 if Is_Object_Reference
(P
) then
5722 Check_Object_Reference
(P
);
5724 elsif Is_Entity_Name
(P
)
5725 and then (Is_Type
(Entity
(P
))
5726 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5730 elsif Nkind
(P
) = N_Type_Conversion
5731 and then not Comes_From_Source
(P
)
5735 -- Some other compilers allow dubious use of X'???'Size
5737 elsif Relaxed_RM_Semantics
5738 and then Nkind
(P
) = N_Attribute_Reference
5743 Error_Attr_P
("invalid prefix for % attribute");
5746 Check_Not_Incomplete_Type
;
5748 Set_Etype
(N
, Universal_Integer
);
5750 -- If we are processing pragmas Compile_Time_Warning and Compile_
5751 -- Time_Errors after the back end has been called and this occurrence
5752 -- of 'Size is known at compile time then it is safe to perform this
5753 -- evaluation. Needed to perform the static evaluation of the full
5754 -- boolean expression of these pragmas.
5756 if In_Compile_Time_Warning_Or_Error
5757 and then Is_Entity_Name
(P
)
5758 and then (Is_Type
(Entity
(P
))
5759 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
5760 and then Size_Known_At_Compile_Time
(Entity
(P
))
5762 Rewrite
(N
, Make_Integer_Literal
(Sloc
(N
), Esize
(Entity
(P
))));
5771 when Attribute_Small
=>
5774 Set_Etype
(N
, Universal_Real
);
5780 when Attribute_Storage_Pool |
5781 Attribute_Simple_Storage_Pool
=> Storage_Pool
:
5785 if Is_Access_Type
(P_Type
) then
5786 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5788 ("cannot use % attribute for access-to-subprogram type");
5791 -- Set appropriate entity
5793 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
5794 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
5796 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
5799 if Attr_Id
= Attribute_Storage_Pool
then
5800 if Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5801 Name_Simple_Storage_Pool_Type
))
5803 Error_Msg_Name_1
:= Aname
;
5804 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5805 Error_Msg_N
("cannot use % attribute for type with simple "
5806 & "storage pool<<", N
);
5807 Error_Msg_N
("\Program_Error [<<", N
);
5810 (N
, Make_Raise_Program_Error
5811 (Sloc
(N
), Reason
=> PE_Explicit_Raise
));
5814 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5816 -- In the Simple_Storage_Pool case, verify that the pool entity is
5817 -- actually of a simple storage pool type, and set the attribute's
5818 -- type to the pool object's type.
5821 if not Present
(Get_Rep_Pragma
(Etype
(Entity
(N
)),
5822 Name_Simple_Storage_Pool_Type
))
5825 ("cannot use % attribute for type without simple " &
5829 Set_Etype
(N
, Etype
(Entity
(N
)));
5832 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5833 -- Storage_Pool since this attribute is not defined for such
5834 -- types (RM E.2.3(22)).
5836 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5839 Error_Attr_P
("prefix of % attribute must be access type");
5847 when Attribute_Storage_Size
=> Storage_Size
:
5851 if Is_Task_Type
(P_Type
) then
5852 Set_Etype
(N
, Universal_Integer
);
5854 -- Use with tasks is an obsolescent feature
5856 Check_Restriction
(No_Obsolescent_Features
, P
);
5858 elsif Is_Access_Type
(P_Type
) then
5859 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
5861 ("cannot use % attribute for access-to-subprogram type");
5864 if Is_Entity_Name
(P
)
5865 and then Is_Type
(Entity
(P
))
5868 Set_Etype
(N
, Universal_Integer
);
5870 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5871 -- Storage_Size since this attribute is not defined for
5872 -- such types (RM E.2.3(22)).
5874 Validate_Remote_Access_To_Class_Wide_Type
(N
);
5876 -- The prefix is allowed to be an implicit dereference of an
5877 -- access value designating a task.
5881 Set_Etype
(N
, Universal_Integer
);
5885 Error_Attr_P
("prefix of % attribute must be access or task type");
5893 when Attribute_Storage_Unit
=>
5894 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
5900 when Attribute_Stream_Size
=>
5904 if Is_Entity_Name
(P
)
5905 and then Is_Elementary_Type
(Entity
(P
))
5907 Set_Etype
(N
, Universal_Integer
);
5909 Error_Attr_P
("invalid prefix for % attribute");
5916 when Attribute_Stub_Type
=>
5920 if Is_Remote_Access_To_Class_Wide_Type
(Base_Type
(P_Type
)) then
5922 -- For a real RACW [sub]type, use corresponding stub type
5924 if not Is_Generic_Type
(P_Type
) then
5927 (Corresponding_Stub_Type
(Base_Type
(P_Type
)), Loc
));
5929 -- For a generic type (that has been marked as an RACW using the
5930 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5931 -- type. Note that if the actual is not a remote access type, the
5932 -- instantiation will fail.
5935 -- Note: we go to the underlying type here because the view
5936 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5940 (Underlying_Type
(RTE
(RE_RACW_Stub_Type
)), Loc
));
5945 ("prefix of% attribute must be remote access-to-class-wide");
5952 when Attribute_Succ
=>
5956 if Is_Real_Type
(P_Type
) or else Is_Boolean_Type
(P_Type
) then
5957 Error_Msg_Name_1
:= Aname
;
5958 Error_Msg_Name_2
:= Chars
(P_Type
);
5959 Check_SPARK_05_Restriction
5960 ("attribute% is not allowed for type%", P
);
5963 Resolve
(E1
, P_Base_Type
);
5964 Set_Etype
(N
, P_Base_Type
);
5966 -- Since Pred works on the base type, we normally do no check for the
5967 -- floating-point case, since the base type is unconstrained. But we
5968 -- make an exception in Check_Float_Overflow mode.
5970 if Is_Floating_Point_Type
(P_Type
) then
5971 if not Range_Checks_Suppressed
(P_Base_Type
) then
5972 Set_Do_Range_Check
(E1
);
5975 -- If not modular type, test for overflow check required
5978 if not Is_Modular_Integer_Type
(P_Type
)
5979 and then not Range_Checks_Suppressed
(P_Base_Type
)
5981 Enable_Range_Check
(E1
);
5985 --------------------------------
5986 -- System_Allocator_Alignment --
5987 --------------------------------
5989 when Attribute_System_Allocator_Alignment
=>
5990 Standard_Attribute
(Ttypes
.System_Allocator_Alignment
);
5996 when Attribute_Tag
=> Tag
:
6001 if not Is_Tagged_Type
(P_Type
) then
6002 Error_Attr_P
("prefix of % attribute must be tagged");
6004 -- Next test does not apply to generated code why not, and what does
6005 -- the illegal reference mean???
6007 elsif Is_Object_Reference
(P
)
6008 and then not Is_Class_Wide_Type
(P_Type
)
6009 and then Comes_From_Source
(N
)
6012 ("% attribute can only be applied to objects " &
6013 "of class - wide type");
6016 -- The prefix cannot be an incomplete type. However, references to
6017 -- 'Tag can be generated when expanding interface conversions, and
6020 if Comes_From_Source
(N
) then
6021 Check_Not_Incomplete_Type
;
6024 -- Set appropriate type
6026 Set_Etype
(N
, RTE
(RE_Tag
));
6033 when Attribute_Target_Name
=> Target_Name
: declare
6034 TN
: constant String := Sdefault
.Target_Name
.all;
6038 Check_Standard_Prefix
;
6042 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
6047 Make_String_Literal
(Loc
,
6048 Strval
=> TN
(TN
'First .. TL
)));
6049 Analyze_And_Resolve
(N
, Standard_String
);
6050 Set_Is_Static_Expression
(N
, True);
6057 when Attribute_Terminated
=>
6059 Set_Etype
(N
, Standard_Boolean
);
6066 when Attribute_To_Address
=> To_Address
: declare
6072 Check_System_Prefix
;
6074 Generate_Reference
(RTE
(RE_Address
), P
);
6075 Analyze_And_Resolve
(E1
, Any_Integer
);
6076 Set_Etype
(N
, RTE
(RE_Address
));
6078 if Is_Static_Expression
(E1
) then
6079 Set_Is_Static_Expression
(N
, True);
6082 -- OK static expression case, check range and set appropriate type
6084 if Is_OK_Static_Expression
(E1
) then
6085 Val
:= Expr_Value
(E1
);
6087 if Val
< -(2 ** UI_From_Int
(Standard
'Address_Size - 1))
6089 Val
> 2 ** UI_From_Int
(Standard
'Address_Size) - 1
6091 Error_Attr
("address value out of range for % attribute", E1
);
6094 -- In most cases the expression is a numeric literal or some other
6095 -- address expression, but if it is a declared constant it may be
6096 -- of a compatible type that must be left on the node.
6098 if Is_Entity_Name
(E1
) then
6101 -- Set type to universal integer if negative
6104 Set_Etype
(E1
, Universal_Integer
);
6106 -- Otherwise set type to Unsigned_64 to accomodate max values
6109 Set_Etype
(E1
, Standard_Unsigned_64
);
6113 Set_Is_Static_Expression
(N
, True);
6120 when Attribute_To_Any
=>
6122 Check_PolyORB_Attribute
;
6123 Set_Etype
(N
, RTE
(RE_Any
));
6129 when Attribute_Truncation
=>
6130 Check_Floating_Point_Type_1
;
6131 Resolve
(E1
, P_Base_Type
);
6132 Set_Etype
(N
, P_Base_Type
);
6138 when Attribute_Type_Class
=>
6141 Check_Not_Incomplete_Type
;
6142 Set_Etype
(N
, RTE
(RE_Type_Class
));
6148 when Attribute_TypeCode
=>
6150 Check_PolyORB_Attribute
;
6151 Set_Etype
(N
, RTE
(RE_TypeCode
));
6157 when Attribute_Type_Key
=> Type_Key
: declare
6158 Full_Name
: constant String_Id
:=
6159 Fully_Qualified_Name_String
(Entity
(P
));
6162 -- The computed signature for the type
6165 -- To simplify the handling of mutually recursive types, follow a
6166 -- single dereference link in a composite type.
6168 procedure Compute_Type_Key
(T
: Entity_Id
);
6169 -- Create a CRC integer from the declaration of the type, For a
6170 -- composite type, fold in the representation of its components in
6171 -- recursive fashion. We use directly the source representation of
6172 -- the types involved.
6174 ----------------------
6175 -- Compute_Type_Key --
6176 ----------------------
6178 procedure Compute_Type_Key
(T
: Entity_Id
) is
6179 Buffer
: Source_Buffer_Ptr
;
6183 SFI
: Source_File_Index
;
6185 procedure Process_One_Declaration
;
6186 -- Update CRC with the characters of one type declaration, or a
6187 -- representation pragma that applies to the type.
6189 -----------------------------
6190 -- Process_One_Declaration --
6191 -----------------------------
6193 procedure Process_One_Declaration
is
6199 -- Scan type declaration, skipping blanks
6201 while Ptr
<= P_Max
loop
6202 if Buffer
(Ptr
) /= ' ' then
6203 System
.CRC32
.Update
(CRC
, Buffer
(Ptr
));
6208 end Process_One_Declaration
;
6210 -- Start of processing for Compute_Type_Key
6213 if Is_Itype
(T
) then
6217 Sloc_Range
(Enclosing_Declaration
(T
), P_Min
, P_Max
);
6218 SFI
:= Get_Source_File_Index
(P_Min
);
6219 Buffer
:= Source_Text
(SFI
);
6221 Process_One_Declaration
;
6223 -- Recurse on relevant component types
6225 if Is_Array_Type
(T
) then
6226 Compute_Type_Key
(Component_Type
(T
));
6228 elsif Is_Access_Type
(T
) then
6231 Compute_Type_Key
(Designated_Type
(T
));
6234 elsif Is_Derived_Type
(T
) then
6235 Compute_Type_Key
(Etype
(T
));
6237 elsif Is_Record_Type
(T
) then
6241 Comp
:= First_Component
(T
);
6242 while Present
(Comp
) loop
6243 Compute_Type_Key
(Etype
(Comp
));
6244 Next_Component
(Comp
);
6249 -- Fold in representation aspects for the type, which appear in
6250 -- the same source buffer.
6252 Rep
:= First_Rep_Item
(T
);
6254 while Present
(Rep
) loop
6255 if Comes_From_Source
(Rep
) then
6256 Sloc_Range
(Rep
, P_Min
, P_Max
);
6257 Process_One_Declaration
;
6260 Rep
:= Next_Rep_Item
(Rep
);
6262 end Compute_Type_Key
;
6264 -- Start of processing for Type_Key
6273 -- Copy all characters in Full_Name but the trailing NUL
6275 for J
in 1 .. String_Length
(Full_Name
) - 1 loop
6276 Store_String_Char
(Get_String_Char
(Full_Name
, Pos
(J
)));
6279 -- For standard types return the name of the type, as there is no
6280 -- explicit source declaration to use. Otherwise compute CRC and
6281 -- convert it to string one character at a time, so as not to use
6282 -- Image within the compiler.
6284 if Scope
(Entity
(P
)) /= Standard_Standard
then
6286 Compute_Type_Key
(Entity
(P
));
6288 if not Is_Frozen
(Entity
(P
)) then
6289 Error_Msg_N
("premature usage of Type_Key?", N
);
6293 Store_String_Char
(Character'Val (48 + (CRC
rem 10)));
6298 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
6299 Analyze_And_Resolve
(N
, Standard_String
);
6302 -----------------------
6303 -- Unbiased_Rounding --
6304 -----------------------
6306 when Attribute_Unbiased_Rounding
=>
6307 Check_Floating_Point_Type_1
;
6308 Set_Etype
(N
, P_Base_Type
);
6309 Resolve
(E1
, P_Base_Type
);
6311 ----------------------
6312 -- Unchecked_Access --
6313 ----------------------
6315 when Attribute_Unchecked_Access
=>
6316 if Comes_From_Source
(N
) then
6317 Check_Restriction
(No_Unchecked_Access
, N
);
6320 Analyze_Access_Attribute
;
6321 Check_Not_Incomplete_Type
;
6323 -------------------------
6324 -- Unconstrained_Array --
6325 -------------------------
6327 when Attribute_Unconstrained_Array
=>
6330 Check_Not_Incomplete_Type
;
6331 Set_Etype
(N
, Standard_Boolean
);
6332 Set_Is_Static_Expression
(N
, True);
6334 ------------------------------
6335 -- Universal_Literal_String --
6336 ------------------------------
6338 -- This is a GNAT specific attribute whose prefix must be a named
6339 -- number where the expression is either a single numeric literal,
6340 -- or a numeric literal immediately preceded by a minus sign. The
6341 -- result is equivalent to a string literal containing the text of
6342 -- the literal as it appeared in the source program with a possible
6343 -- leading minus sign.
6345 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
6349 if not Is_Entity_Name
(P
)
6350 or else Ekind
(Entity
(P
)) not in Named_Kind
6352 Error_Attr_P
("prefix for % attribute must be named number");
6359 Src
: Source_Buffer_Ptr
;
6362 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
6364 if Nkind
(Expr
) = N_Op_Minus
then
6366 Expr
:= Original_Node
(Right_Opnd
(Expr
));
6371 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
6373 ("named number for % attribute must be simple literal", N
);
6376 -- Build string literal corresponding to source literal text
6381 Store_String_Char
(Get_Char_Code
('-'));
6385 Src
:= Source_Text
(Get_Source_File_Index
(S
));
6387 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
6388 Store_String_Char
(Get_Char_Code
(Src
(S
)));
6392 -- Now we rewrite the attribute with the string literal
6395 Make_String_Literal
(Loc
, End_String
));
6397 Set_Is_Static_Expression
(N
, True);
6400 end Universal_Literal_String
;
6402 -------------------------
6403 -- Unrestricted_Access --
6404 -------------------------
6406 -- This is a GNAT specific attribute which is like Access except that
6407 -- all scope checks and checks for aliased views are omitted. It is
6408 -- documented as being equivalent to the use of the Address attribute
6409 -- followed by an unchecked conversion to the target access type.
6411 when Attribute_Unrestricted_Access
=>
6413 -- If from source, deal with relevant restrictions
6415 if Comes_From_Source
(N
) then
6416 Check_Restriction
(No_Unchecked_Access
, N
);
6418 if Nkind
(P
) in N_Has_Entity
6419 and then Present
(Entity
(P
))
6420 and then Is_Object
(Entity
(P
))
6422 Check_Restriction
(No_Implicit_Aliasing
, N
);
6426 if Is_Entity_Name
(P
) then
6427 Set_Address_Taken
(Entity
(P
));
6430 -- It might seem reasonable to call Address_Checks here to apply the
6431 -- same set of semantic checks that we enforce for 'Address (after
6432 -- all we document Unrestricted_Access as being equivalent to the
6433 -- use of Address followed by an Unchecked_Conversion). However, if
6434 -- we do enable these checks, we get multiple failures in both the
6435 -- compiler run-time and in our regression test suite, so we leave
6436 -- out these checks for now. To be investigated further some time???
6440 -- Now complete analysis using common access processing
6442 Analyze_Access_Attribute
;
6448 when Attribute_Update
=> Update
: declare
6449 Common_Typ
: Entity_Id
;
6450 -- The common type of a multiple component update for a record
6452 Comps
: Elist_Id
:= No_Elist
;
6453 -- A list used in the resolution of a record update. It contains the
6454 -- entities of all record components processed so far.
6456 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
);
6457 -- Analyze and resolve array_component_association Assoc against the
6458 -- index of array type P_Type.
6460 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
);
6461 -- Analyze and resolve record_component_association Comp against
6462 -- record type P_Type.
6464 ------------------------------------
6465 -- Analyze_Array_Component_Update --
6466 ------------------------------------
6468 procedure Analyze_Array_Component_Update
(Assoc
: Node_Id
) is
6472 Index_Typ
: Entity_Id
;
6476 -- The current association contains a sequence of indexes denoting
6477 -- an element of a multidimensional array:
6479 -- (Index_1, ..., Index_N)
6481 -- Examine each individual index and resolve it against the proper
6482 -- index type of the array.
6484 if Nkind
(First
(Choices
(Assoc
))) = N_Aggregate
then
6485 Expr
:= First
(Choices
(Assoc
));
6486 while Present
(Expr
) loop
6488 -- The use of others is illegal (SPARK RM 4.4.1(12))
6490 if Nkind
(Expr
) = N_Others_Choice
then
6492 ("others choice not allowed in attribute %", Expr
);
6494 -- Otherwise analyze and resolve all indexes
6497 Index
:= First
(Expressions
(Expr
));
6498 Index_Typ
:= First_Index
(P_Type
);
6499 while Present
(Index
) and then Present
(Index_Typ
) loop
6500 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6502 Next_Index
(Index_Typ
);
6505 -- Detect a case where the association either lacks an
6506 -- index or contains an extra index.
6508 if Present
(Index
) or else Present
(Index_Typ
) then
6510 ("dimension mismatch in index list", Assoc
);
6517 -- The current association denotes either a single component or a
6518 -- range of components of a one dimensional array:
6522 -- Resolve the index or its high and low bounds (if range) against
6523 -- the proper index type of the array.
6526 Index
:= First
(Choices
(Assoc
));
6527 Index_Typ
:= First_Index
(P_Type
);
6529 if Present
(Next_Index
(Index_Typ
)) then
6530 Error_Msg_N
("too few subscripts in array reference", Assoc
);
6533 while Present
(Index
) loop
6535 -- The use of others is illegal (SPARK RM 4.4.1(12))
6537 if Nkind
(Index
) = N_Others_Choice
then
6539 ("others choice not allowed in attribute %", Index
);
6541 -- The index denotes a range of elements
6543 elsif Nkind
(Index
) = N_Range
then
6544 Low
:= Low_Bound
(Index
);
6545 High
:= High_Bound
(Index
);
6547 Analyze_And_Resolve
(Low
, Etype
(Index_Typ
));
6548 Analyze_And_Resolve
(High
, Etype
(Index_Typ
));
6550 -- Add a range check to ensure that the bounds of the
6551 -- range are within the index type when this cannot be
6552 -- determined statically.
6554 if not Is_OK_Static_Expression
(Low
) then
6555 Set_Do_Range_Check
(Low
);
6558 if not Is_OK_Static_Expression
(High
) then
6559 Set_Do_Range_Check
(High
);
6562 -- Otherwise the index denotes a single element
6565 Analyze_And_Resolve
(Index
, Etype
(Index_Typ
));
6567 -- Add a range check to ensure that the index is within
6568 -- the index type when it is not possible to determine
6571 if not Is_OK_Static_Expression
(Index
) then
6572 Set_Do_Range_Check
(Index
);
6579 end Analyze_Array_Component_Update
;
6581 -------------------------------------
6582 -- Analyze_Record_Component_Update --
6583 -------------------------------------
6585 procedure Analyze_Record_Component_Update
(Comp
: Node_Id
) is
6586 Comp_Name
: constant Name_Id
:= Chars
(Comp
);
6587 Base_Typ
: Entity_Id
;
6588 Comp_Or_Discr
: Entity_Id
;
6591 -- Find the discriminant or component whose name corresponds to
6592 -- Comp. A simple character comparison is sufficient because all
6593 -- visible names within a record type are unique.
6595 Comp_Or_Discr
:= First_Entity
(P_Type
);
6596 while Present
(Comp_Or_Discr
) loop
6597 if Chars
(Comp_Or_Discr
) = Comp_Name
then
6599 -- Decorate the component reference by setting its entity
6600 -- and type for resolution purposes.
6602 Set_Entity
(Comp
, Comp_Or_Discr
);
6603 Set_Etype
(Comp
, Etype
(Comp_Or_Discr
));
6607 Comp_Or_Discr
:= Next_Entity
(Comp_Or_Discr
);
6610 -- Diagnose an illegal reference
6612 if Present
(Comp_Or_Discr
) then
6613 if Ekind
(Comp_Or_Discr
) = E_Discriminant
then
6615 ("attribute % may not modify record discriminants", Comp
);
6617 else pragma Assert
(Ekind
(Comp_Or_Discr
) = E_Component
);
6618 if Contains
(Comps
, Comp_Or_Discr
) then
6619 Error_Msg_N
("component & already updated", Comp
);
6621 -- Mark this component as processed
6624 Append_New_Elmt
(Comp_Or_Discr
, Comps
);
6628 -- The update aggregate mentions an entity that does not belong to
6632 Error_Msg_N
("& is not a component of aggregate subtype", Comp
);
6635 -- Verify the consistency of types when the current component is
6636 -- part of a miltiple component update.
6638 -- Comp_1, ..., Comp_N => <value>
6640 if Present
(Etype
(Comp
)) then
6641 Base_Typ
:= Base_Type
(Etype
(Comp
));
6643 -- Save the type of the first component reference as the
6644 -- remaning references (if any) must resolve to this type.
6646 if No
(Common_Typ
) then
6647 Common_Typ
:= Base_Typ
;
6649 elsif Base_Typ
/= Common_Typ
then
6651 ("components in choice list must have same type", Comp
);
6654 end Analyze_Record_Component_Update
;
6661 -- Start of processing for Update
6666 if not Is_Object_Reference
(P
) then
6667 Error_Attr_P
("prefix of attribute % must denote an object");
6669 elsif not Is_Array_Type
(P_Type
)
6670 and then not Is_Record_Type
(P_Type
)
6672 Error_Attr_P
("prefix of attribute % must be a record or array");
6674 elsif Is_Limited_View
(P_Type
) then
6675 Error_Attr
("prefix of attribute % cannot be limited", N
);
6677 elsif Nkind
(E1
) /= N_Aggregate
then
6678 Error_Attr
("attribute % requires component association list", N
);
6681 -- Inspect the update aggregate, looking at all the associations and
6682 -- choices. Perform the following checks:
6684 -- 1) Legality of "others" in all cases
6685 -- 2) Legality of <>
6686 -- 3) Component legality for arrays
6687 -- 4) Component legality for records
6689 -- The remaining checks are performed on the expanded attribute
6691 Assoc
:= First
(Component_Associations
(E1
));
6692 while Present
(Assoc
) loop
6694 -- The use of <> is illegal (SPARK RM 4.4.1(1))
6696 if Box_Present
(Assoc
) then
6698 ("default initialization not allowed in attribute %", Assoc
);
6700 -- Otherwise process the association
6703 Analyze
(Expression
(Assoc
));
6705 if Is_Array_Type
(P_Type
) then
6706 Analyze_Array_Component_Update
(Assoc
);
6708 elsif Is_Record_Type
(P_Type
) then
6710 -- Reset the common type used in a multiple component update
6711 -- as we are processing the contents of a new association.
6713 Common_Typ
:= Empty
;
6715 Comp
:= First
(Choices
(Assoc
));
6716 while Present
(Comp
) loop
6717 if Nkind
(Comp
) = N_Identifier
then
6718 Analyze_Record_Component_Update
(Comp
);
6720 -- The use of others is illegal (SPARK RM 4.4.1(5))
6722 elsif Nkind
(Comp
) = N_Others_Choice
then
6724 ("others choice not allowed in attribute %", Comp
);
6726 -- The name of a record component cannot appear in any
6731 ("name should be identifier or OTHERS", Comp
);
6742 -- The type of attribute 'Update is that of the prefix
6744 Set_Etype
(N
, P_Type
);
6746 Sem_Warn
.Warn_On_Suspicious_Update
(N
);
6753 when Attribute_Val
=> Val
: declare
6756 Check_Discrete_Type
;
6758 if Is_Boolean_Type
(P_Type
) then
6759 Error_Msg_Name_1
:= Aname
;
6760 Error_Msg_Name_2
:= Chars
(P_Type
);
6761 Check_SPARK_05_Restriction
6762 ("attribute% is not allowed for type%", P
);
6765 Resolve
(E1
, Any_Integer
);
6766 Set_Etype
(N
, P_Base_Type
);
6768 -- Note, we need a range check in general, but we wait for the
6769 -- Resolve call to do this, since we want to let Eval_Attribute
6770 -- have a chance to find an static illegality first.
6777 when Attribute_Valid
=>
6780 -- Ignore check for object if we have a 'Valid reference generated
6781 -- by the expanded code, since in some cases valid checks can occur
6782 -- on items that are names, but are not objects (e.g. attributes).
6784 if Comes_From_Source
(N
) then
6785 Check_Object_Reference
(P
);
6788 if not Is_Scalar_Type
(P_Type
) then
6789 Error_Attr_P
("object for % attribute must be of scalar type");
6792 -- If the attribute appears within the subtype's own predicate
6793 -- function, then issue a warning that this will cause infinite
6797 Pred_Func
: constant Entity_Id
:= Predicate_Function
(P_Type
);
6800 if Present
(Pred_Func
) and then Current_Scope
= Pred_Func
then
6802 ("attribute Valid requires a predicate check??", N
);
6803 Error_Msg_N
("\and will result in infinite recursion??", N
);
6807 Set_Etype
(N
, Standard_Boolean
);
6813 when Attribute_Valid_Scalars
=>
6815 Check_Object_Reference
(P
);
6816 Set_Etype
(N
, Standard_Boolean
);
6818 -- Following checks are only for source types
6820 if Comes_From_Source
(N
) then
6821 if not Scalar_Part_Present
(P_Type
) then
6823 ("??attribute % always True, no scalars to check");
6826 -- Not allowed for unchecked union type
6828 if Has_Unchecked_Union
(P_Type
) then
6830 ("attribute % not allowed for Unchecked_Union type");
6838 when Attribute_Value
=> Value
:
6840 Check_SPARK_05_Restriction_On_Attribute
;
6844 -- Case of enumeration type
6846 -- When an enumeration type appears in an attribute reference, all
6847 -- literals of the type are marked as referenced. This must only be
6848 -- done if the attribute reference appears in the current source.
6849 -- Otherwise the information on references may differ between a
6850 -- normal compilation and one that performs inlining.
6852 if Is_Enumeration_Type
(P_Type
)
6853 and then In_Extended_Main_Code_Unit
(N
)
6855 Check_Restriction
(No_Enumeration_Maps
, N
);
6857 -- Mark all enumeration literals as referenced, since the use of
6858 -- the Value attribute can implicitly reference any of the
6859 -- literals of the enumeration base type.
6862 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
6864 while Present
(Ent
) loop
6865 Set_Referenced
(Ent
);
6871 -- Set Etype before resolving expression because expansion of
6872 -- expression may require enclosing type. Note that the type
6873 -- returned by 'Value is the base type of the prefix type.
6875 Set_Etype
(N
, P_Base_Type
);
6876 Validate_Non_Static_Attribute_Function_Call
;
6878 -- Check restriction No_Fixed_IO
6880 if Restriction_Check_Required
(No_Fixed_IO
)
6881 and then Is_Fixed_Point_Type
(P_Type
)
6883 Check_Restriction
(No_Fixed_IO
, P
);
6891 when Attribute_Value_Size
=>
6894 Check_Not_Incomplete_Type
;
6895 Set_Etype
(N
, Universal_Integer
);
6901 when Attribute_Version
=>
6904 Set_Etype
(N
, RTE
(RE_Version_String
));
6910 when Attribute_Wchar_T_Size
=>
6911 Standard_Attribute
(Interfaces_Wchar_T_Size
);
6917 when Attribute_Wide_Image
=> Wide_Image
:
6919 Check_SPARK_05_Restriction_On_Attribute
;
6921 Set_Etype
(N
, Standard_Wide_String
);
6923 Resolve
(E1
, P_Base_Type
);
6924 Validate_Non_Static_Attribute_Function_Call
;
6926 -- Check restriction No_Fixed_IO
6928 if Restriction_Check_Required
(No_Fixed_IO
)
6929 and then Is_Fixed_Point_Type
(P_Type
)
6931 Check_Restriction
(No_Fixed_IO
, P
);
6935 ---------------------
6936 -- Wide_Wide_Image --
6937 ---------------------
6939 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
6942 Set_Etype
(N
, Standard_Wide_Wide_String
);
6944 Resolve
(E1
, P_Base_Type
);
6945 Validate_Non_Static_Attribute_Function_Call
;
6947 -- Check restriction No_Fixed_IO
6949 if Restriction_Check_Required
(No_Fixed_IO
)
6950 and then Is_Fixed_Point_Type
(P_Type
)
6952 Check_Restriction
(No_Fixed_IO
, P
);
6954 end Wide_Wide_Image
;
6960 when Attribute_Wide_Value
=> Wide_Value
:
6962 Check_SPARK_05_Restriction_On_Attribute
;
6966 -- Set Etype before resolving expression because expansion
6967 -- of expression may require enclosing type.
6969 Set_Etype
(N
, P_Type
);
6970 Validate_Non_Static_Attribute_Function_Call
;
6972 -- Check restriction No_Fixed_IO
6974 if Restriction_Check_Required
(No_Fixed_IO
)
6975 and then Is_Fixed_Point_Type
(P_Type
)
6977 Check_Restriction
(No_Fixed_IO
, P
);
6981 ---------------------
6982 -- Wide_Wide_Value --
6983 ---------------------
6985 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
6990 -- Set Etype before resolving expression because expansion
6991 -- of expression may require enclosing type.
6993 Set_Etype
(N
, P_Type
);
6994 Validate_Non_Static_Attribute_Function_Call
;
6996 -- Check restriction No_Fixed_IO
6998 if Restriction_Check_Required
(No_Fixed_IO
)
6999 and then Is_Fixed_Point_Type
(P_Type
)
7001 Check_Restriction
(No_Fixed_IO
, P
);
7003 end Wide_Wide_Value
;
7005 ---------------------
7006 -- Wide_Wide_Width --
7007 ---------------------
7009 when Attribute_Wide_Wide_Width
=>
7012 Set_Etype
(N
, Universal_Integer
);
7018 when Attribute_Wide_Width
=>
7019 Check_SPARK_05_Restriction_On_Attribute
;
7022 Set_Etype
(N
, Universal_Integer
);
7028 when Attribute_Width
=>
7029 Check_SPARK_05_Restriction_On_Attribute
;
7032 Set_Etype
(N
, Universal_Integer
);
7038 when Attribute_Word_Size
=>
7039 Standard_Attribute
(System_Word_Size
);
7045 when Attribute_Write
=>
7047 Check_Stream_Attribute
(TSS_Stream_Write
);
7048 Set_Etype
(N
, Standard_Void_Type
);
7049 Resolve
(N
, Standard_Void_Type
);
7053 -- All errors raise Bad_Attribute, so that we get out before any further
7054 -- damage occurs when an error is detected (for example, if we check for
7055 -- one attribute expression, and the check succeeds, we want to be able
7056 -- to proceed securely assuming that an expression is in fact present.
7058 -- Note: we set the attribute analyzed in this case to prevent any
7059 -- attempt at reanalysis which could generate spurious error msgs.
7062 when Bad_Attribute
=>
7064 Set_Etype
(N
, Any_Type
);
7066 end Analyze_Attribute
;
7068 --------------------
7069 -- Eval_Attribute --
7070 --------------------
7072 procedure Eval_Attribute
(N
: Node_Id
) is
7073 Loc
: constant Source_Ptr
:= Sloc
(N
);
7074 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7075 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7076 P
: constant Node_Id
:= Prefix
(N
);
7078 C_Type
: constant Entity_Id
:= Etype
(N
);
7079 -- The type imposed by the context
7082 -- First expression, or Empty if none
7085 -- Second expression, or Empty if none
7087 P_Entity
: Entity_Id
;
7088 -- Entity denoted by prefix
7091 -- The type of the prefix
7093 P_Base_Type
: Entity_Id
;
7094 -- The base type of the prefix type
7096 P_Root_Type
: Entity_Id
;
7097 -- The root type of the prefix type
7100 -- True if the result is Static. This is set by the general processing
7101 -- to true if the prefix is static, and all expressions are static. It
7102 -- can be reset as processing continues for particular attributes. This
7103 -- flag can still be True if the reference raises a constraint error.
7104 -- Is_Static_Expression (N) is set to follow this value as it is set
7105 -- and we could always reference this, but it is convenient to have a
7106 -- simple short name to use, since it is frequently referenced.
7108 Lo_Bound
, Hi_Bound
: Node_Id
;
7109 -- Expressions for low and high bounds of type or array index referenced
7110 -- by First, Last, or Length attribute for array, set by Set_Bounds.
7113 -- Constraint error node used if we have an attribute reference has
7114 -- an argument that raises a constraint error. In this case we replace
7115 -- the attribute with a raise constraint_error node. This is important
7116 -- processing, since otherwise gigi might see an attribute which it is
7117 -- unprepared to deal with.
7119 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
);
7120 -- If Bound is a reference to a discriminant of a task or protected type
7121 -- occurring within the object's body, rewrite attribute reference into
7122 -- a reference to the corresponding discriminal. Use for the expansion
7123 -- of checks against bounds of entry family index subtypes.
7125 procedure Check_Expressions
;
7126 -- In case where the attribute is not foldable, the expressions, if
7127 -- any, of the attribute, are in a non-static context. This procedure
7128 -- performs the required additional checks.
7130 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
7131 -- Determines if the given type has compile time known bounds. Note
7132 -- that we enter the case statement even in cases where the prefix
7133 -- type does NOT have known bounds, so it is important to guard any
7134 -- attempt to evaluate both bounds with a call to this function.
7136 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
7137 -- This procedure is called when the attribute N has a non-static
7138 -- but compile time known value given by Val. It includes the
7139 -- necessary checks for out of range values.
7141 function Fore_Value
return Nat
;
7142 -- Computes the Fore value for the current attribute prefix, which is
7143 -- known to be a static fixed-point type. Used by Fore and Width.
7145 function Mantissa
return Uint
;
7146 -- Returns the Mantissa value for the prefix type
7148 procedure Set_Bounds
;
7149 -- Used for First, Last and Length attributes applied to an array or
7150 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
7151 -- and high bound expressions for the index referenced by the attribute
7152 -- designator (i.e. the first index if no expression is present, and the
7153 -- N'th index if the value N is present as an expression). Also used for
7154 -- First and Last of scalar types and for First_Valid and Last_Valid.
7155 -- Static is reset to False if the type or index type is not statically
7158 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
7159 -- Verify that the prefix of a potentially static array attribute
7160 -- satisfies the conditions of 4.9 (14).
7162 -----------------------------------
7163 -- Check_Concurrent_Discriminant --
7164 -----------------------------------
7166 procedure Check_Concurrent_Discriminant
(Bound
: Node_Id
) is
7168 -- The concurrent (task or protected) type
7171 if Nkind
(Bound
) = N_Identifier
7172 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7173 and then Is_Concurrent_Record_Type
(Scope
(Entity
(Bound
)))
7175 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Entity
(Bound
)));
7177 if In_Open_Scopes
(Tsk
) and then Has_Completion
(Tsk
) then
7179 -- Find discriminant of original concurrent type, and use
7180 -- its current discriminal, which is the renaming within
7181 -- the task/protected body.
7185 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
));
7188 end Check_Concurrent_Discriminant
;
7190 -----------------------
7191 -- Check_Expressions --
7192 -----------------------
7194 procedure Check_Expressions
is
7198 while Present
(E
) loop
7199 Check_Non_Static_Context
(E
);
7202 end Check_Expressions
;
7204 ----------------------------------
7205 -- Compile_Time_Known_Attribute --
7206 ----------------------------------
7208 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
7209 T
: constant Entity_Id
:= Etype
(N
);
7212 Fold_Uint
(N
, Val
, False);
7214 -- Check that result is in bounds of the type if it is static
7216 if Is_In_Range
(N
, T
, Assume_Valid
=> False) then
7219 elsif Is_Out_Of_Range
(N
, T
) then
7220 Apply_Compile_Time_Constraint_Error
7221 (N
, "value not in range of}??", CE_Range_Check_Failed
);
7223 elsif not Range_Checks_Suppressed
(T
) then
7224 Enable_Range_Check
(N
);
7227 Set_Do_Range_Check
(N
, False);
7229 end Compile_Time_Known_Attribute
;
7231 -------------------------------
7232 -- Compile_Time_Known_Bounds --
7233 -------------------------------
7235 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
7238 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
7240 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
7241 end Compile_Time_Known_Bounds
;
7247 -- Note that the Fore calculation is based on the actual values
7248 -- of the bounds, and does not take into account possible rounding.
7250 function Fore_Value
return Nat
is
7251 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7252 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7253 Small
: constant Ureal
:= Small_Value
(P_Type
);
7254 Lo_Real
: constant Ureal
:= Lo
* Small
;
7255 Hi_Real
: constant Ureal
:= Hi
* Small
;
7260 -- Bounds are given in terms of small units, so first compute
7261 -- proper values as reals.
7263 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
7266 -- Loop to compute proper value if more than one digit required
7268 while T
>= Ureal_10
loop
7280 -- Table of mantissa values accessed by function Computed using
7283 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
7285 -- where D is T'Digits (RM83 3.5.7)
7287 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
7329 function Mantissa
return Uint
is
7332 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
7339 procedure Set_Bounds
is
7345 -- For a string literal subtype, we have to construct the bounds.
7346 -- Valid Ada code never applies attributes to string literals, but
7347 -- it is convenient to allow the expander to generate attribute
7348 -- references of this type (e.g. First and Last applied to a string
7351 -- Note that the whole point of the E_String_Literal_Subtype is to
7352 -- avoid this construction of bounds, but the cases in which we
7353 -- have to materialize them are rare enough that we don't worry.
7355 -- The low bound is simply the low bound of the base type. The
7356 -- high bound is computed from the length of the string and this
7359 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
7360 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
7361 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7364 Make_Integer_Literal
(Sloc
(P
),
7366 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
7368 Set_Parent
(Hi_Bound
, P
);
7369 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
7372 -- For non-array case, just get bounds of scalar type
7374 elsif Is_Scalar_Type
(P_Type
) then
7377 -- For a fixed-point type, we must freeze to get the attributes
7378 -- of the fixed-point type set now so we can reference them.
7380 if Is_Fixed_Point_Type
(P_Type
)
7381 and then not Is_Frozen
(Base_Type
(P_Type
))
7382 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
7383 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
7385 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
7388 -- For array case, get type of proper index
7394 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
7397 Indx
:= First_Index
(P_Type
);
7398 for J
in 1 .. Ndim
- 1 loop
7402 -- If no index type, get out (some other error occurred, and
7403 -- we don't have enough information to complete the job).
7411 Ityp
:= Etype
(Indx
);
7414 -- A discrete range in an index constraint is allowed to be a
7415 -- subtype indication. This is syntactically a pain, but should
7416 -- not propagate to the entity for the corresponding index subtype.
7417 -- After checking that the subtype indication is legal, the range
7418 -- of the subtype indication should be transfered to the entity.
7419 -- The attributes for the bounds should remain the simple retrievals
7420 -- that they are now.
7422 Lo_Bound
:= Type_Low_Bound
(Ityp
);
7423 Hi_Bound
:= Type_High_Bound
(Ityp
);
7425 -- If subtype is non-static, result is definitely non-static
7427 if not Is_Static_Subtype
(Ityp
) then
7429 Set_Is_Static_Expression
(N
, False);
7431 -- Subtype is static, does it raise CE?
7433 elsif not Is_OK_Static_Subtype
(Ityp
) then
7434 Set_Raises_Constraint_Error
(N
);
7438 -------------------------------
7439 -- Statically_Denotes_Entity --
7440 -------------------------------
7442 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
7446 if not Is_Entity_Name
(N
) then
7453 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7454 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
7455 end Statically_Denotes_Entity
;
7457 -- Start of processing for Eval_Attribute
7460 -- Initialize result as non-static, will be reset if appropriate
7462 Set_Is_Static_Expression
(N
, False);
7465 -- Acquire first two expressions (at the moment, no attributes take more
7466 -- than two expressions in any case).
7468 if Present
(Expressions
(N
)) then
7469 E1
:= First
(Expressions
(N
));
7476 -- Special processing for Enabled attribute. This attribute has a very
7477 -- special prefix, and the easiest way to avoid lots of special checks
7478 -- to protect this special prefix from causing trouble is to deal with
7479 -- this attribute immediately and be done with it.
7481 if Id
= Attribute_Enabled
then
7483 -- We skip evaluation if the expander is not active. This is not just
7484 -- an optimization. It is of key importance that we not rewrite the
7485 -- attribute in a generic template, since we want to pick up the
7486 -- setting of the check in the instance, Testing Expander_Active
7487 -- might seem an easy way of doing this, but we need to account for
7488 -- ASIS needs, so check explicitly for a generic context.
7490 if not Inside_A_Generic
then
7492 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
7497 if C
in Predefined_Check_Id
then
7498 R
:= Scope_Suppress
.Suppress
(C
);
7500 R
:= Is_Check_Suppressed
(Empty
, C
);
7504 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
7507 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(not R
), Loc
));
7514 -- Attribute 'Img applied to a static enumeration value is static, and
7515 -- we will do the folding right here (things get confused if we let this
7516 -- case go through the normal circuitry).
7518 if Attribute_Name
(N
) = Name_Img
7519 and then Is_Entity_Name
(P
)
7520 and then Is_Enumeration_Type
(Etype
(Entity
(P
)))
7521 and then Is_OK_Static_Expression
(P
)
7524 Lit
: constant Entity_Id
:= Expr_Value_E
(P
);
7529 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
7530 Set_Casing
(All_Upper_Case
);
7531 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
7534 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
7535 Analyze_And_Resolve
(N
, Standard_String
);
7536 Set_Is_Static_Expression
(N
, True);
7542 -- Special processing for cases where the prefix is an object. For this
7543 -- purpose, a string literal counts as an object (attributes of string
7544 -- literals can only appear in generated code).
7546 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
7548 -- For Component_Size, the prefix is an array object, and we apply
7549 -- the attribute to the type of the object. This is allowed for both
7550 -- unconstrained and constrained arrays, since the bounds have no
7551 -- influence on the value of this attribute.
7553 if Id
= Attribute_Component_Size
then
7554 P_Entity
:= Etype
(P
);
7556 -- For Enum_Rep, evaluation depends on the nature of the prefix and
7557 -- the optional argument.
7559 elsif Id
= Attribute_Enum_Rep
then
7560 if Is_Entity_Name
(P
) then
7563 Enum_Expr
: Node_Id
;
7564 -- The enumeration-type expression of interest
7569 if Ekind_In
(Entity
(P
), E_Constant
,
7570 E_Enumeration_Literal
)
7574 -- Enum_Type'Enum_Rep (E1) case
7576 elsif Is_Enumeration_Type
(Entity
(P
)) then
7579 -- Otherwise the attribute must be expanded into a
7580 -- conversion and evaluated at run time.
7587 -- We can fold if the expression is an enumeration
7588 -- literal, or if it denotes a constant whose value
7589 -- is known at compile time.
7591 if Nkind
(Enum_Expr
) in N_Has_Entity
7592 and then (Ekind
(Entity
(Enum_Expr
)) =
7593 E_Enumeration_Literal
7595 (Ekind
(Entity
(Enum_Expr
)) = E_Constant
7596 and then Nkind
(Parent
(Entity
(Enum_Expr
))) =
7597 N_Object_Declaration
7598 and then Compile_Time_Known_Value
7599 (Expression
(Parent
(Entity
(P
))))))
7601 P_Entity
:= Etype
(P
);
7608 -- Otherwise the attribute is illegal, do not attempt to perform
7609 -- any kind of folding.
7615 -- For First and Last, the prefix is an array object, and we apply
7616 -- the attribute to the type of the array, but we need a constrained
7617 -- type for this, so we use the actual subtype if available.
7619 elsif Id
= Attribute_First
or else
7620 Id
= Attribute_Last
or else
7621 Id
= Attribute_Length
7624 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
7627 if Present
(AS
) and then Is_Constrained
(AS
) then
7630 -- If we have an unconstrained type we cannot fold
7638 -- For Size, give size of object if available, otherwise we
7639 -- cannot fold Size.
7641 elsif Id
= Attribute_Size
then
7642 if Is_Entity_Name
(P
)
7643 and then Known_Esize
(Entity
(P
))
7645 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
7653 -- For Alignment, give size of object if available, otherwise we
7654 -- cannot fold Alignment.
7656 elsif Id
= Attribute_Alignment
then
7657 if Is_Entity_Name
(P
)
7658 and then Known_Alignment
(Entity
(P
))
7660 Fold_Uint
(N
, Alignment
(Entity
(P
)), Static
);
7668 -- For Lock_Free, we apply the attribute to the type of the object.
7669 -- This is allowed since we have already verified that the type is a
7672 elsif Id
= Attribute_Lock_Free
then
7673 P_Entity
:= Etype
(P
);
7675 -- No other attributes for objects are folded
7682 -- Cases where P is not an object. Cannot do anything if P is not the
7683 -- name of an entity.
7685 elsif not Is_Entity_Name
(P
) then
7689 -- Otherwise get prefix entity
7692 P_Entity
:= Entity
(P
);
7695 -- If we are asked to evaluate an attribute where the prefix is a
7696 -- non-frozen generic actual type whose RM_Size is still set to zero,
7697 -- then abandon the effort.
7699 if Is_Type
(P_Entity
)
7700 and then (not Is_Frozen
(P_Entity
)
7701 and then Is_Generic_Actual_Type
(P_Entity
)
7702 and then RM_Size
(P_Entity
) = 0)
7704 -- However, the attribute Unconstrained_Array must be evaluated,
7705 -- since it is documented to be a static attribute (and can for
7706 -- example appear in a Compile_Time_Warning pragma). The frozen
7707 -- status of the type does not affect its evaluation.
7709 and then Id
/= Attribute_Unconstrained_Array
7714 -- At this stage P_Entity is the entity to which the attribute
7715 -- is to be applied. This is usually simply the entity of the
7716 -- prefix, except in some cases of attributes for objects, where
7717 -- as described above, we apply the attribute to the object type.
7719 -- Here is where we make sure that static attributes are properly
7720 -- marked as such. These are attributes whose prefix is a static
7721 -- scalar subtype, whose result is scalar, and whose arguments, if
7722 -- present, are static scalar expressions. Note that such references
7723 -- are static expressions even if they raise Constraint_Error.
7725 -- For example, Boolean'Pos (1/0 = 0) is a static expression, even
7726 -- though evaluating it raises constraint error. This means that a
7727 -- declaration like:
7729 -- X : constant := (if True then 1 else Boolean'Pos (1/0 = 0));
7731 -- is legal, since here this expression appears in a statically
7732 -- unevaluated position, so it does not actually raise an exception.
7734 if Is_Scalar_Type
(P_Entity
)
7735 and then (not Is_Generic_Type
(P_Entity
))
7736 and then Is_Static_Subtype
(P_Entity
)
7737 and then Is_Scalar_Type
(Etype
(N
))
7740 or else (Is_Static_Expression
(E1
)
7741 and then Is_Scalar_Type
(Etype
(E1
))))
7744 or else (Is_Static_Expression
(E2
)
7745 and then Is_Scalar_Type
(Etype
(E1
))))
7748 Set_Is_Static_Expression
(N
, True);
7751 -- First foldable possibility is a scalar or array type (RM 4.9(7))
7752 -- that is not generic (generic types are eliminated by RM 4.9(25)).
7753 -- Note we allow non-static non-generic types at this stage as further
7756 if Is_Type
(P_Entity
)
7757 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
7758 and then (not Is_Generic_Type
(P_Entity
))
7762 -- Second foldable possibility is an array object (RM 4.9(8))
7764 elsif Ekind_In
(P_Entity
, E_Variable
, E_Constant
)
7765 and then Is_Array_Type
(Etype
(P_Entity
))
7766 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
7768 P_Type
:= Etype
(P_Entity
);
7770 -- If the entity is an array constant with an unconstrained nominal
7771 -- subtype then get the type from the initial value. If the value has
7772 -- been expanded into assignments, there is no expression and the
7773 -- attribute reference remains dynamic.
7775 -- We could do better here and retrieve the type ???
7777 if Ekind
(P_Entity
) = E_Constant
7778 and then not Is_Constrained
(P_Type
)
7780 if No
(Constant_Value
(P_Entity
)) then
7783 P_Type
:= Etype
(Constant_Value
(P_Entity
));
7787 -- Definite must be folded if the prefix is not a generic type, that
7788 -- is to say if we are within an instantiation. Same processing applies
7789 -- to the GNAT attributes Atomic_Always_Lock_Free, Has_Discriminants,
7790 -- Lock_Free, Type_Class, Has_Tagged_Value, and Unconstrained_Array.
7792 elsif (Id
= Attribute_Atomic_Always_Lock_Free
or else
7793 Id
= Attribute_Definite
or else
7794 Id
= Attribute_Has_Access_Values
or else
7795 Id
= Attribute_Has_Discriminants
or else
7796 Id
= Attribute_Has_Tagged_Values
or else
7797 Id
= Attribute_Lock_Free
or else
7798 Id
= Attribute_Type_Class
or else
7799 Id
= Attribute_Unconstrained_Array
or else
7800 Id
= Attribute_Max_Alignment_For_Allocation
)
7801 and then not Is_Generic_Type
(P_Entity
)
7805 -- We can fold 'Size applied to a type if the size is known (as happens
7806 -- for a size from an attribute definition clause). At this stage, this
7807 -- can happen only for types (e.g. record types) for which the size is
7808 -- always non-static. We exclude generic types from consideration (since
7809 -- they have bogus sizes set within templates).
7811 elsif Id
= Attribute_Size
7812 and then Is_Type
(P_Entity
)
7813 and then (not Is_Generic_Type
(P_Entity
))
7814 and then Known_Static_RM_Size
(P_Entity
)
7816 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
7819 -- We can fold 'Alignment applied to a type if the alignment is known
7820 -- (as happens for an alignment from an attribute definition clause).
7821 -- At this stage, this can happen only for types (e.g. record types) for
7822 -- which the size is always non-static. We exclude generic types from
7823 -- consideration (since they have bogus sizes set within templates).
7825 elsif Id
= Attribute_Alignment
7826 and then Is_Type
(P_Entity
)
7827 and then (not Is_Generic_Type
(P_Entity
))
7828 and then Known_Alignment
(P_Entity
)
7830 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
7833 -- If this is an access attribute that is known to fail accessibility
7834 -- check, rewrite accordingly.
7836 elsif Attribute_Name
(N
) = Name_Access
7837 and then Raises_Constraint_Error
(N
)
7840 Make_Raise_Program_Error
(Loc
,
7841 Reason
=> PE_Accessibility_Check_Failed
));
7842 Set_Etype
(N
, C_Type
);
7845 -- No other cases are foldable (they certainly aren't static, and at
7846 -- the moment we don't try to fold any cases other than the ones above).
7853 -- If either attribute or the prefix is Any_Type, then propagate
7854 -- Any_Type to the result and don't do anything else at all.
7856 if P_Type
= Any_Type
7857 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
7858 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
7860 Set_Etype
(N
, Any_Type
);
7864 -- Scalar subtype case. We have not yet enforced the static requirement
7865 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
7866 -- of non-static attribute references (e.g. S'Digits for a non-static
7867 -- floating-point type, which we can compute at compile time).
7869 -- Note: this folding of non-static attributes is not simply a case of
7870 -- optimization. For many of the attributes affected, Gigi cannot handle
7871 -- the attribute and depends on the front end having folded them away.
7873 -- Note: although we don't require staticness at this stage, we do set
7874 -- the Static variable to record the staticness, for easy reference by
7875 -- those attributes where it matters (e.g. Succ and Pred), and also to
7876 -- be used to ensure that non-static folded things are not marked as
7877 -- being static (a check that is done right at the end).
7879 P_Root_Type
:= Root_Type
(P_Type
);
7880 P_Base_Type
:= Base_Type
(P_Type
);
7882 -- If the root type or base type is generic, then we cannot fold. This
7883 -- test is needed because subtypes of generic types are not always
7884 -- marked as being generic themselves (which seems odd???)
7886 if Is_Generic_Type
(P_Root_Type
)
7887 or else Is_Generic_Type
(P_Base_Type
)
7892 if Is_Scalar_Type
(P_Type
) then
7893 if not Is_Static_Subtype
(P_Type
) then
7895 Set_Is_Static_Expression
(N
, False);
7896 elsif not Is_OK_Static_Subtype
(P_Type
) then
7897 Set_Raises_Constraint_Error
(N
);
7900 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
7901 -- since we can't do anything with unconstrained arrays. In addition,
7902 -- only the First, Last and Length attributes are possibly static.
7904 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
7905 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
7906 -- Unconstrained_Array are again exceptions, because they apply as well
7907 -- to unconstrained types.
7909 -- In addition Component_Size is an exception since it is possibly
7910 -- foldable, even though it is never static, and it does apply to
7911 -- unconstrained arrays. Furthermore, it is essential to fold this
7912 -- in the packed case, since otherwise the value will be incorrect.
7914 elsif Id
= Attribute_Atomic_Always_Lock_Free
or else
7915 Id
= Attribute_Definite
or else
7916 Id
= Attribute_Has_Access_Values
or else
7917 Id
= Attribute_Has_Discriminants
or else
7918 Id
= Attribute_Has_Tagged_Values
or else
7919 Id
= Attribute_Lock_Free
or else
7920 Id
= Attribute_Type_Class
or else
7921 Id
= Attribute_Unconstrained_Array
or else
7922 Id
= Attribute_Component_Size
7925 Set_Is_Static_Expression
(N
, False);
7927 elsif Id
/= Attribute_Max_Alignment_For_Allocation
then
7928 if not Is_Constrained
(P_Type
)
7929 or else (Id
/= Attribute_First
and then
7930 Id
/= Attribute_Last
and then
7931 Id
/= Attribute_Length
)
7937 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
7938 -- scalar case, we hold off on enforcing staticness, since there are
7939 -- cases which we can fold at compile time even though they are not
7940 -- static (e.g. 'Length applied to a static index, even though other
7941 -- non-static indexes make the array type non-static). This is only
7942 -- an optimization, but it falls out essentially free, so why not.
7943 -- Again we compute the variable Static for easy reference later
7944 -- (note that no array attributes are static in Ada 83).
7946 -- We also need to set Static properly for subsequent legality checks
7947 -- which might otherwise accept non-static constants in contexts
7948 -- where they are not legal.
7951 Ada_Version
>= Ada_95
and then Statically_Denotes_Entity
(P
);
7952 Set_Is_Static_Expression
(N
, Static
);
7958 Nod
:= First_Index
(P_Type
);
7960 -- The expression is static if the array type is constrained
7961 -- by given bounds, and not by an initial expression. Constant
7962 -- strings are static in any case.
7964 if Root_Type
(P_Type
) /= Standard_String
then
7966 Static
and then not Is_Constr_Subt_For_U_Nominal
(P_Type
);
7967 Set_Is_Static_Expression
(N
, Static
);
7970 while Present
(Nod
) loop
7971 if not Is_Static_Subtype
(Etype
(Nod
)) then
7973 Set_Is_Static_Expression
(N
, False);
7975 elsif not Is_OK_Static_Subtype
(Etype
(Nod
)) then
7976 Set_Raises_Constraint_Error
(N
);
7978 Set_Is_Static_Expression
(N
, False);
7981 -- If however the index type is generic, or derived from
7982 -- one, attributes cannot be folded.
7984 if Is_Generic_Type
(Root_Type
(Etype
(Nod
)))
7985 and then Id
/= Attribute_Component_Size
7995 -- Check any expressions that are present. Note that these expressions,
7996 -- depending on the particular attribute type, are either part of the
7997 -- attribute designator, or they are arguments in a case where the
7998 -- attribute reference returns a function. In the latter case, the
7999 -- rule in (RM 4.9(22)) applies and in particular requires the type
8000 -- of the expressions to be scalar in order for the attribute to be
8001 -- considered to be static.
8009 while Present
(E
) loop
8011 -- If expression is not static, then the attribute reference
8012 -- result certainly cannot be static.
8014 if not Is_Static_Expression
(E
) then
8016 Set_Is_Static_Expression
(N
, False);
8019 if Raises_Constraint_Error
(E
) then
8020 Set_Raises_Constraint_Error
(N
);
8023 -- If the result is not known at compile time, or is not of
8024 -- a scalar type, then the result is definitely not static,
8025 -- so we can quit now.
8027 if not Compile_Time_Known_Value
(E
)
8028 or else not Is_Scalar_Type
(Etype
(E
))
8030 -- An odd special case, if this is a Pos attribute, this
8031 -- is where we need to apply a range check since it does
8032 -- not get done anywhere else.
8034 if Id
= Attribute_Pos
then
8035 if Is_Integer_Type
(Etype
(E
)) then
8036 Apply_Range_Check
(E
, Etype
(N
));
8043 -- If the expression raises a constraint error, then so does
8044 -- the attribute reference. We keep going in this case because
8045 -- we are still interested in whether the attribute reference
8046 -- is static even if it is not static.
8048 elsif Raises_Constraint_Error
(E
) then
8049 Set_Raises_Constraint_Error
(N
);
8055 if Raises_Constraint_Error
(Prefix
(N
)) then
8056 Set_Is_Static_Expression
(N
, False);
8061 -- Deal with the case of a static attribute reference that raises
8062 -- constraint error. The Raises_Constraint_Error flag will already
8063 -- have been set, and the Static flag shows whether the attribute
8064 -- reference is static. In any case we certainly can't fold such an
8065 -- attribute reference.
8067 -- Note that the rewriting of the attribute node with the constraint
8068 -- error node is essential in this case, because otherwise Gigi might
8069 -- blow up on one of the attributes it never expects to see.
8071 -- The constraint_error node must have the type imposed by the context,
8072 -- to avoid spurious errors in the enclosing expression.
8074 if Raises_Constraint_Error
(N
) then
8076 Make_Raise_Constraint_Error
(Sloc
(N
),
8077 Reason
=> CE_Range_Check_Failed
);
8078 Set_Etype
(CE_Node
, Etype
(N
));
8079 Set_Raises_Constraint_Error
(CE_Node
);
8081 Rewrite
(N
, Relocate_Node
(CE_Node
));
8082 Set_Raises_Constraint_Error
(N
, True);
8086 -- At this point we have a potentially foldable attribute reference.
8087 -- If Static is set, then the attribute reference definitely obeys
8088 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
8089 -- folded. If Static is not set, then the attribute may or may not
8090 -- be foldable, and the individual attribute processing routines
8091 -- test Static as required in cases where it makes a difference.
8093 -- In the case where Static is not set, we do know that all the
8094 -- expressions present are at least known at compile time (we assumed
8095 -- above that if this was not the case, then there was no hope of static
8096 -- evaluation). However, we did not require that the bounds of the
8097 -- prefix type be compile time known, let alone static). That's because
8098 -- there are many attributes that can be computed at compile time on
8099 -- non-static subtypes, even though such references are not static
8102 -- For VAX float, the root type is an IEEE type. So make sure to use the
8103 -- base type instead of the root-type for floating point attributes.
8107 -- Attributes related to Ada 2012 iterators (placeholder ???)
8109 when Attribute_Constant_Indexing |
8110 Attribute_Default_Iterator |
8111 Attribute_Implicit_Dereference |
8112 Attribute_Iterator_Element |
8113 Attribute_Iterable |
8114 Attribute_Variable_Indexing
=> null;
8116 -- Internal attributes used to deal with Ada 2012 delayed aspects.
8117 -- These were already rejected by the parser. Thus they shouldn't
8120 when Internal_Attribute_Id
=>
8121 raise Program_Error
;
8127 when Attribute_Adjacent
=>
8131 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8138 when Attribute_Aft
=>
8139 Fold_Uint
(N
, Aft_Value
(P_Type
), Static
);
8145 when Attribute_Alignment
=> Alignment_Block
: declare
8146 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8149 -- Fold if alignment is set and not otherwise
8151 if Known_Alignment
(P_TypeA
) then
8152 Fold_Uint
(N
, Alignment
(P_TypeA
), Static
);
8154 end Alignment_Block
;
8156 -----------------------------
8157 -- Atomic_Always_Lock_Free --
8158 -----------------------------
8160 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
8163 when Attribute_Atomic_Always_Lock_Free
=> Atomic_Always_Lock_Free
:
8165 V
: constant Entity_Id
:=
8167 (Support_Atomic_Primitives_On_Target
8168 and then Support_Atomic_Primitives
(P_Type
));
8171 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8173 -- Analyze and resolve as boolean. Note that this attribute is a
8174 -- static attribute in GNAT.
8176 Analyze_And_Resolve
(N
, Standard_Boolean
);
8178 Set_Is_Static_Expression
(N
, True);
8179 end Atomic_Always_Lock_Free
;
8185 -- Bit can never be folded
8187 when Attribute_Bit
=>
8194 -- Body_version can never be static
8196 when Attribute_Body_Version
=>
8203 when Attribute_Ceiling
=>
8205 (N
, Eval_Fat
.Ceiling
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8207 --------------------
8208 -- Component_Size --
8209 --------------------
8211 when Attribute_Component_Size
=>
8212 if Known_Static_Component_Size
(P_Type
) then
8213 Fold_Uint
(N
, Component_Size
(P_Type
), Static
);
8220 when Attribute_Compose
=>
8223 Eval_Fat
.Compose
(P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8230 -- Constrained is never folded for now, there may be cases that
8231 -- could be handled at compile time. To be looked at later.
8233 when Attribute_Constrained
=>
8235 -- The expander might fold it and set the static flag accordingly,
8236 -- but with expansion disabled (as in ASIS), it remains as an
8237 -- attribute reference, and this reference is not static.
8239 Set_Is_Static_Expression
(N
, False);
8246 when Attribute_Copy_Sign
=>
8250 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)),
8257 when Attribute_Definite
=>
8258 Rewrite
(N
, New_Occurrence_Of
(
8259 Boolean_Literals
(Is_Definite_Subtype
(P_Entity
)), Loc
));
8260 Analyze_And_Resolve
(N
, Standard_Boolean
);
8266 when Attribute_Delta
=>
8267 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
8273 when Attribute_Denorm
=>
8275 (N
, UI_From_Int
(Boolean'Pos (Has_Denormals
(P_Type
))), Static
);
8277 ---------------------
8278 -- Descriptor_Size --
8279 ---------------------
8281 when Attribute_Descriptor_Size
=>
8288 when Attribute_Digits
=>
8289 Fold_Uint
(N
, Digits_Value
(P_Type
), Static
);
8295 when Attribute_Emax
=>
8297 -- Ada 83 attribute is defined as (RM83 3.5.8)
8299 -- T'Emax = 4 * T'Mantissa
8301 Fold_Uint
(N
, 4 * Mantissa
, Static
);
8307 when Attribute_Enum_Rep
=> Enum_Rep
: declare
8311 -- The attribute appears in the form:
8313 -- Enum_Typ'Enum_Rep (Const)
8314 -- Enum_Typ'Enum_Rep (Enum_Lit)
8316 if Present
(E1
) then
8319 -- Otherwise the prefix denotes a constant or enumeration literal:
8322 -- Enum_Lit'Enum_Rep
8328 -- For an enumeration type with a non-standard representation use
8329 -- the Enumeration_Rep field of the proper constant. Note that this
8330 -- will not work for types Character/Wide_[Wide-]Character, since no
8331 -- real entities are created for the enumeration literals, but that
8332 -- does not matter since these two types do not have non-standard
8333 -- representations anyway.
8335 if Is_Enumeration_Type
(P_Type
)
8336 and then Has_Non_Standard_Rep
(P_Type
)
8338 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(Val
)), Static
);
8340 -- For enumeration types with standard representations and all other
8341 -- cases (i.e. all integer and modular types), Enum_Rep is equivalent
8345 Fold_Uint
(N
, Expr_Value
(Val
), Static
);
8353 when Attribute_Enum_Val
=> Enum_Val
: declare
8357 -- We have something like Enum_Type'Enum_Val (23), so search for a
8358 -- corresponding value in the list of Enum_Rep values for the type.
8360 Lit
:= First_Literal
(P_Base_Type
);
8362 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
8363 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
8370 Apply_Compile_Time_Constraint_Error
8371 (N
, "no representation value matches",
8372 CE_Range_Check_Failed
,
8373 Warn
=> not Static
);
8383 when Attribute_Epsilon
=>
8385 -- Ada 83 attribute is defined as (RM83 3.5.8)
8387 -- T'Epsilon = 2.0**(1 - T'Mantissa)
8389 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
8395 when Attribute_Exponent
=>
8397 Eval_Fat
.Exponent
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8403 when Attribute_First
=> First_Attr
:
8407 if Compile_Time_Known_Value
(Lo_Bound
) then
8408 if Is_Real_Type
(P_Type
) then
8409 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
8411 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8415 Check_Concurrent_Discriminant
(Lo_Bound
);
8423 when Attribute_First_Valid
=> First_Valid
:
8425 if Has_Predicates
(P_Type
)
8426 and then Has_Static_Predicate
(P_Type
)
8429 FirstN
: constant Node_Id
:=
8430 First
(Static_Discrete_Predicate
(P_Type
));
8432 if Nkind
(FirstN
) = N_Range
then
8433 Fold_Uint
(N
, Expr_Value
(Low_Bound
(FirstN
)), Static
);
8435 Fold_Uint
(N
, Expr_Value
(FirstN
), Static
);
8441 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
8449 when Attribute_Fixed_Value
=>
8456 when Attribute_Floor
=>
8458 (N
, Eval_Fat
.Floor
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8464 when Attribute_Fore
=>
8465 if Compile_Time_Known_Bounds
(P_Type
) then
8466 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
8473 when Attribute_Fraction
=>
8475 (N
, Eval_Fat
.Fraction
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8477 -----------------------
8478 -- Has_Access_Values --
8479 -----------------------
8481 when Attribute_Has_Access_Values
=>
8482 Rewrite
(N
, New_Occurrence_Of
8483 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
8484 Analyze_And_Resolve
(N
, Standard_Boolean
);
8486 -----------------------
8487 -- Has_Discriminants --
8488 -----------------------
8490 when Attribute_Has_Discriminants
=>
8491 Rewrite
(N
, New_Occurrence_Of
(
8492 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
8493 Analyze_And_Resolve
(N
, Standard_Boolean
);
8495 ----------------------
8496 -- Has_Same_Storage --
8497 ----------------------
8499 when Attribute_Has_Same_Storage
=>
8502 -----------------------
8503 -- Has_Tagged_Values --
8504 -----------------------
8506 when Attribute_Has_Tagged_Values
=>
8507 Rewrite
(N
, New_Occurrence_Of
8508 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
8509 Analyze_And_Resolve
(N
, Standard_Boolean
);
8515 when Attribute_Identity
=>
8522 -- Image is a scalar attribute, but is never static, because it is
8523 -- not a static function (having a non-scalar argument (RM 4.9(22))
8524 -- However, we can constant-fold the image of an enumeration literal
8525 -- if names are available.
8527 when Attribute_Image
=>
8528 if Is_Entity_Name
(E1
)
8529 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
8530 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
8531 and then not Global_Discard_Names
8534 Lit
: constant Entity_Id
:= Entity
(E1
);
8538 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
8539 Set_Casing
(All_Upper_Case
);
8540 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
8542 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
8543 Analyze_And_Resolve
(N
, Standard_String
);
8544 Set_Is_Static_Expression
(N
, False);
8552 -- We never try to fold Integer_Value (though perhaps we could???)
8554 when Attribute_Integer_Value
=>
8561 -- Invalid_Value is a scalar attribute that is never static, because
8562 -- the value is by design out of range.
8564 when Attribute_Invalid_Value
=>
8571 when Attribute_Large
=>
8573 -- For fixed-point, we use the identity:
8575 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
8577 if Is_Fixed_Point_Type
(P_Type
) then
8579 Make_Op_Multiply
(Loc
,
8581 Make_Op_Subtract
(Loc
,
8585 Make_Real_Literal
(Loc
, Ureal_2
),
8587 Make_Attribute_Reference
(Loc
,
8589 Attribute_Name
=> Name_Mantissa
)),
8590 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
8593 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
8595 Analyze_And_Resolve
(N
, C_Type
);
8597 -- Floating-point (Ada 83 compatibility)
8600 -- Ada 83 attribute is defined as (RM83 3.5.8)
8602 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
8606 -- T'Emax = 4 * T'Mantissa
8610 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
8618 when Attribute_Lock_Free
=> Lock_Free
: declare
8619 V
: constant Entity_Id
:= Boolean_Literals
(Uses_Lock_Free
(P_Type
));
8622 Rewrite
(N
, New_Occurrence_Of
(V
, Loc
));
8624 -- Analyze and resolve as boolean. Note that this attribute is a
8625 -- static attribute in GNAT.
8627 Analyze_And_Resolve
(N
, Standard_Boolean
);
8629 Set_Is_Static_Expression
(N
, True);
8636 when Attribute_Last
=> Last_Attr
:
8640 if Compile_Time_Known_Value
(Hi_Bound
) then
8641 if Is_Real_Type
(P_Type
) then
8642 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
8644 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8648 Check_Concurrent_Discriminant
(Hi_Bound
);
8656 when Attribute_Last_Valid
=> Last_Valid
:
8658 if Has_Predicates
(P_Type
)
8659 and then Has_Static_Predicate
(P_Type
)
8662 LastN
: constant Node_Id
:=
8663 Last
(Static_Discrete_Predicate
(P_Type
));
8665 if Nkind
(LastN
) = N_Range
then
8666 Fold_Uint
(N
, Expr_Value
(High_Bound
(LastN
)), Static
);
8668 Fold_Uint
(N
, Expr_Value
(LastN
), Static
);
8674 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
8682 when Attribute_Leading_Part
=>
8685 Eval_Fat
.Leading_Part
8686 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
8693 when Attribute_Length
=> Length
: declare
8697 -- If any index type is a formal type, or derived from one, the
8698 -- bounds are not static. Treating them as static can produce
8699 -- spurious warnings or improper constant folding.
8701 Ind
:= First_Index
(P_Type
);
8702 while Present
(Ind
) loop
8703 if Is_Generic_Type
(Root_Type
(Etype
(Ind
))) then
8712 -- For two compile time values, we can compute length
8714 if Compile_Time_Known_Value
(Lo_Bound
)
8715 and then Compile_Time_Known_Value
(Hi_Bound
)
8718 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
8722 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8723 -- comparable, and we can figure out the difference between them.
8726 Diff
: aliased Uint
;
8730 Compile_Time_Compare
8731 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
8734 Fold_Uint
(N
, Uint_1
, Static
);
8737 Fold_Uint
(N
, Uint_0
, Static
);
8740 if Diff
/= No_Uint
then
8741 Fold_Uint
(N
, Diff
+ 1, Static
);
8754 -- Loop_Entry acts as an alias of a constant initialized to the prefix
8755 -- of the said attribute at the point of entry into the related loop. As
8756 -- such, the attribute reference does not need to be evaluated because
8757 -- the prefix is the one that is evaluted.
8759 when Attribute_Loop_Entry
=>
8766 when Attribute_Machine
=>
8770 (P_Base_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
8777 when Attribute_Machine_Emax
=>
8778 Fold_Uint
(N
, Machine_Emax_Value
(P_Type
), Static
);
8784 when Attribute_Machine_Emin
=>
8785 Fold_Uint
(N
, Machine_Emin_Value
(P_Type
), Static
);
8787 ----------------------
8788 -- Machine_Mantissa --
8789 ----------------------
8791 when Attribute_Machine_Mantissa
=>
8792 Fold_Uint
(N
, Machine_Mantissa_Value
(P_Type
), Static
);
8794 -----------------------
8795 -- Machine_Overflows --
8796 -----------------------
8798 when Attribute_Machine_Overflows
=>
8800 -- Always true for fixed-point
8802 if Is_Fixed_Point_Type
(P_Type
) then
8803 Fold_Uint
(N
, True_Value
, Static
);
8805 -- Floating point case
8809 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
8817 when Attribute_Machine_Radix
=>
8818 if Is_Fixed_Point_Type
(P_Type
) then
8819 if Is_Decimal_Fixed_Point_Type
(P_Type
)
8820 and then Machine_Radix_10
(P_Type
)
8822 Fold_Uint
(N
, Uint_10
, Static
);
8824 Fold_Uint
(N
, Uint_2
, Static
);
8827 -- All floating-point type always have radix 2
8830 Fold_Uint
(N
, Uint_2
, Static
);
8833 ----------------------
8834 -- Machine_Rounding --
8835 ----------------------
8837 -- Note: for the folding case, it is fine to treat Machine_Rounding
8838 -- exactly the same way as Rounding, since this is one of the allowed
8839 -- behaviors, and performance is not an issue here. It might be a bit
8840 -- better to give the same result as it would give at run time, even
8841 -- though the non-determinism is certainly permitted.
8843 when Attribute_Machine_Rounding
=>
8845 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
8847 --------------------
8848 -- Machine_Rounds --
8849 --------------------
8851 when Attribute_Machine_Rounds
=>
8853 -- Always False for fixed-point
8855 if Is_Fixed_Point_Type
(P_Type
) then
8856 Fold_Uint
(N
, False_Value
, Static
);
8858 -- Else yield proper floating-point result
8862 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)),
8870 -- Note: Machine_Size is identical to Object_Size
8872 when Attribute_Machine_Size
=> Machine_Size
: declare
8873 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
8876 if Known_Esize
(P_TypeA
) then
8877 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
8885 when Attribute_Mantissa
=>
8887 -- Fixed-point mantissa
8889 if Is_Fixed_Point_Type
(P_Type
) then
8891 -- Compile time foldable case
8893 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
8895 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
8897 -- The calculation of the obsolete Ada 83 attribute Mantissa
8898 -- is annoying, because of AI00143, quoted here:
8900 -- !question 84-01-10
8902 -- Consider the model numbers for F:
8904 -- type F is delta 1.0 range -7.0 .. 8.0;
8906 -- The wording requires that F'MANTISSA be the SMALLEST
8907 -- integer number for which each bound of the specified
8908 -- range is either a model number or lies at most small
8909 -- distant from a model number. This means F'MANTISSA
8910 -- is required to be 3 since the range -7.0 .. 7.0 fits
8911 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
8912 -- number, namely, 7. Is this analysis correct? Note that
8913 -- this implies the upper bound of the range is not
8914 -- represented as a model number.
8916 -- !response 84-03-17
8918 -- The analysis is correct. The upper and lower bounds for
8919 -- a fixed point type can lie outside the range of model
8930 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
8931 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
8932 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
8933 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
8935 -- If the Bound is exactly a model number, i.e. a multiple
8936 -- of Small, then we back it off by one to get the integer
8937 -- value that must be representable.
8939 if Small_Value
(P_Type
) * Max_Man
= Bound
then
8940 Max_Man
:= Max_Man
- 1;
8943 -- Now find corresponding size = Mantissa value
8946 while 2 ** Siz
< Max_Man
loop
8950 Fold_Uint
(N
, Siz
, Static
);
8954 -- The case of dynamic bounds cannot be evaluated at compile
8955 -- time. Instead we use a runtime routine (see Exp_Attr).
8960 -- Floating-point Mantissa
8963 Fold_Uint
(N
, Mantissa
, Static
);
8970 when Attribute_Max
=> Max
:
8972 if Is_Real_Type
(P_Type
) then
8974 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
8976 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
8980 ----------------------------------
8981 -- Max_Alignment_For_Allocation --
8982 ----------------------------------
8984 -- Max_Alignment_For_Allocation is usually the Alignment. However,
8985 -- arrays are allocated with dope, so we need to take into account both
8986 -- the alignment of the array, which comes from the component alignment,
8987 -- and the alignment of the dope. Also, if the alignment is unknown, we
8988 -- use the max (it's OK to be pessimistic).
8990 when Attribute_Max_Alignment_For_Allocation
=>
8992 A
: Uint
:= UI_From_Int
(Ttypes
.Maximum_Alignment
);
8994 if Known_Alignment
(P_Type
) and then
8995 (not Is_Array_Type
(P_Type
) or else Alignment
(P_Type
) > A
)
8997 A
:= Alignment
(P_Type
);
9000 Fold_Uint
(N
, A
, Static
);
9003 ----------------------------------
9004 -- Max_Size_In_Storage_Elements --
9005 ----------------------------------
9007 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
9008 -- Storage_Unit boundary. We can fold any cases for which the size
9009 -- is known by the front end.
9011 when Attribute_Max_Size_In_Storage_Elements
=>
9012 if Known_Esize
(P_Type
) then
9014 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
9015 System_Storage_Unit
,
9019 --------------------
9020 -- Mechanism_Code --
9021 --------------------
9023 when Attribute_Mechanism_Code
=>
9027 Mech
: Mechanism_Type
;
9031 Mech
:= Mechanism
(P_Entity
);
9034 Val
:= UI_To_Int
(Expr_Value
(E1
));
9036 Formal
:= First_Formal
(P_Entity
);
9037 for J
in 1 .. Val
- 1 loop
9038 Next_Formal
(Formal
);
9040 Mech
:= Mechanism
(Formal
);
9044 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), Static
);
9052 when Attribute_Min
=> Min
:
9054 if Is_Real_Type
(P_Type
) then
9056 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
9059 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
9067 when Attribute_Mod
=>
9069 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
9075 when Attribute_Model
=>
9077 (N
, Eval_Fat
.Model
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9083 when Attribute_Model_Emin
=>
9084 Fold_Uint
(N
, Model_Emin_Value
(P_Base_Type
), Static
);
9090 when Attribute_Model_Epsilon
=>
9091 Fold_Ureal
(N
, Model_Epsilon_Value
(P_Base_Type
), Static
);
9093 --------------------
9094 -- Model_Mantissa --
9095 --------------------
9097 when Attribute_Model_Mantissa
=>
9098 Fold_Uint
(N
, Model_Mantissa_Value
(P_Base_Type
), Static
);
9104 when Attribute_Model_Small
=>
9105 Fold_Ureal
(N
, Model_Small_Value
(P_Base_Type
), Static
);
9111 when Attribute_Modulus
=>
9112 Fold_Uint
(N
, Modulus
(P_Type
), Static
);
9114 --------------------
9115 -- Null_Parameter --
9116 --------------------
9118 -- Cannot fold, we know the value sort of, but the whole point is
9119 -- that there is no way to talk about this imaginary value except
9120 -- by using the attribute, so we leave it the way it is.
9122 when Attribute_Null_Parameter
=>
9129 -- The Object_Size attribute for a type returns the Esize of the
9130 -- type and can be folded if this value is known.
9132 when Attribute_Object_Size
=> Object_Size
: declare
9133 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9136 if Known_Esize
(P_TypeA
) then
9137 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9141 ----------------------
9142 -- Overlaps_Storage --
9143 ----------------------
9145 when Attribute_Overlaps_Storage
=>
9148 -------------------------
9149 -- Passed_By_Reference --
9150 -------------------------
9152 -- Scalar types are never passed by reference
9154 when Attribute_Passed_By_Reference
=>
9155 Fold_Uint
(N
, False_Value
, Static
);
9161 when Attribute_Pos
=>
9162 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9168 when Attribute_Pred
=> Pred
:
9170 -- Floating-point case
9172 if Is_Floating_Point_Type
(P_Type
) then
9174 (N
, Eval_Fat
.Pred
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9178 elsif Is_Fixed_Point_Type
(P_Type
) then
9180 (N
, Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
9182 -- Modular integer case (wraps)
9184 elsif Is_Modular_Integer_Type
(P_Type
) then
9185 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
9187 -- Other scalar cases
9190 pragma Assert
(Is_Scalar_Type
(P_Type
));
9192 if Is_Enumeration_Type
(P_Type
)
9193 and then Expr_Value
(E1
) =
9194 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9196 Apply_Compile_Time_Constraint_Error
9197 (N
, "Pred of `&''First`",
9198 CE_Overflow_Check_Failed
,
9200 Warn
=> not Static
);
9206 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
9214 -- No processing required, because by this stage, Range has been
9215 -- replaced by First .. Last, so this branch can never be taken.
9217 when Attribute_Range
=>
9218 raise Program_Error
;
9224 when Attribute_Range_Length
=>
9227 -- Can fold if both bounds are compile time known
9229 if Compile_Time_Known_Value
(Hi_Bound
)
9230 and then Compile_Time_Known_Value
(Lo_Bound
)
9234 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
9238 -- One more case is where Hi_Bound and Lo_Bound are compile-time
9239 -- comparable, and we can figure out the difference between them.
9242 Diff
: aliased Uint
;
9246 Compile_Time_Compare
9247 (Lo_Bound
, Hi_Bound
, Diff
'Access, Assume_Valid
=> False)
9250 Fold_Uint
(N
, Uint_1
, Static
);
9253 Fold_Uint
(N
, Uint_0
, Static
);
9256 if Diff
/= No_Uint
then
9257 Fold_Uint
(N
, Diff
+ 1, Static
);
9269 when Attribute_Ref
=>
9270 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9276 when Attribute_Remainder
=> Remainder
: declare
9277 X
: constant Ureal
:= Expr_Value_R
(E1
);
9278 Y
: constant Ureal
:= Expr_Value_R
(E2
);
9281 if UR_Is_Zero
(Y
) then
9282 Apply_Compile_Time_Constraint_Error
9283 (N
, "division by zero in Remainder",
9284 CE_Overflow_Check_Failed
,
9285 Warn
=> not Static
);
9291 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Base_Type
, X
, Y
), Static
);
9298 when Attribute_Restriction_Set
=> Restriction_Set
: declare
9300 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
9301 Set_Is_Static_Expression
(N
);
9302 end Restriction_Set
;
9308 when Attribute_Round
=> Round
:
9314 -- First we get the (exact result) in units of small
9316 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
9318 -- Now round that exactly to an integer
9320 Si
:= UR_To_Uint
(Sr
);
9322 -- Finally the result is obtained by converting back to real
9324 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
9331 when Attribute_Rounding
=>
9333 (N
, Eval_Fat
.Rounding
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9339 when Attribute_Safe_Emax
=>
9340 Fold_Uint
(N
, Safe_Emax_Value
(P_Type
), Static
);
9346 when Attribute_Safe_First
=>
9347 Fold_Ureal
(N
, Safe_First_Value
(P_Type
), Static
);
9353 when Attribute_Safe_Large
=>
9354 if Is_Fixed_Point_Type
(P_Type
) then
9356 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
9358 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9365 when Attribute_Safe_Last
=>
9366 Fold_Ureal
(N
, Safe_Last_Value
(P_Type
), Static
);
9372 when Attribute_Safe_Small
=>
9374 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
9375 -- for fixed-point, since is the same as Small, but we implement
9376 -- it for backwards compatibility.
9378 if Is_Fixed_Point_Type
(P_Type
) then
9379 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
9381 -- Ada 83 Safe_Small for floating-point cases
9384 Fold_Ureal
(N
, Model_Small_Value
(P_Type
), Static
);
9391 when Attribute_Scale
=>
9392 Fold_Uint
(N
, Scale_Value
(P_Type
), Static
);
9398 when Attribute_Scaling
=>
9402 (P_Base_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
9409 when Attribute_Signed_Zeros
=>
9411 (N
, UI_From_Int
(Boolean'Pos (Has_Signed_Zeros
(P_Type
))), Static
);
9417 -- Size attribute returns the RM size. All scalar types can be folded,
9418 -- as well as any types for which the size is known by the front end,
9419 -- including any type for which a size attribute is specified. This is
9420 -- one of the places where it is annoying that a size of zero means two
9421 -- things (zero size for scalars, unspecified size for non-scalars).
9423 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
9424 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9427 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9431 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
9433 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
9436 -- If a size clause applies, then use the size from it.
9437 -- This is one of the rare cases where we can use the
9438 -- Size_Clause field for a subtype when Has_Size_Clause
9439 -- is False. Consider:
9441 -- type x is range 1 .. 64;
9442 -- for x'size use 12;
9443 -- subtype y is x range 0 .. 3;
9445 -- Here y has a size clause inherited from x, but normally
9446 -- it does not apply, and y'size is 2. However, y'VADS_Size
9447 -- is indeed 12 and not 2.
9450 and then Is_OK_Static_Expression
(Expression
(S
))
9452 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), Static
);
9454 -- If no size is specified, then we simply use the object
9455 -- size in the VADS_Size case (e.g. Natural'Size is equal
9456 -- to Integer'Size, not one less).
9459 Fold_Uint
(N
, Esize
(P_TypeA
), Static
);
9463 -- Normal case (Size) in which case we want the RM_Size
9466 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9475 when Attribute_Small
=>
9477 -- The floating-point case is present only for Ada 83 compatibility.
9478 -- Note that strictly this is an illegal addition, since we are
9479 -- extending an Ada 95 defined attribute, but we anticipate an
9480 -- ARG ruling that will permit this.
9482 if Is_Floating_Point_Type
(P_Type
) then
9484 -- Ada 83 attribute is defined as (RM83 3.5.8)
9486 -- T'Small = 2.0**(-T'Emax - 1)
9490 -- T'Emax = 4 * T'Mantissa
9492 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
9494 -- Normal Ada 95 fixed-point case
9497 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
9504 when Attribute_Stream_Size
=>
9511 when Attribute_Succ
=> Succ
:
9513 -- Floating-point case
9515 if Is_Floating_Point_Type
(P_Type
) then
9517 (N
, Eval_Fat
.Succ
(P_Base_Type
, Expr_Value_R
(E1
)), Static
);
9521 elsif Is_Fixed_Point_Type
(P_Type
) then
9522 Fold_Ureal
(N
, Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
9524 -- Modular integer case (wraps)
9526 elsif Is_Modular_Integer_Type
(P_Type
) then
9527 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
9529 -- Other scalar cases
9532 pragma Assert
(Is_Scalar_Type
(P_Type
));
9534 if Is_Enumeration_Type
(P_Type
)
9535 and then Expr_Value
(E1
) =
9536 Expr_Value
(Type_High_Bound
(P_Base_Type
))
9538 Apply_Compile_Time_Constraint_Error
9539 (N
, "Succ of `&''Last`",
9540 CE_Overflow_Check_Failed
,
9542 Warn
=> not Static
);
9547 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
9556 when Attribute_Truncation
=>
9559 Eval_Fat
.Truncation
(P_Base_Type
, Expr_Value_R
(E1
)),
9566 when Attribute_Type_Class
=> Type_Class
: declare
9567 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
9571 if Is_Descendant_Of_Address
(Typ
) then
9572 Id
:= RE_Type_Class_Address
;
9574 elsif Is_Enumeration_Type
(Typ
) then
9575 Id
:= RE_Type_Class_Enumeration
;
9577 elsif Is_Integer_Type
(Typ
) then
9578 Id
:= RE_Type_Class_Integer
;
9580 elsif Is_Fixed_Point_Type
(Typ
) then
9581 Id
:= RE_Type_Class_Fixed_Point
;
9583 elsif Is_Floating_Point_Type
(Typ
) then
9584 Id
:= RE_Type_Class_Floating_Point
;
9586 elsif Is_Array_Type
(Typ
) then
9587 Id
:= RE_Type_Class_Array
;
9589 elsif Is_Record_Type
(Typ
) then
9590 Id
:= RE_Type_Class_Record
;
9592 elsif Is_Access_Type
(Typ
) then
9593 Id
:= RE_Type_Class_Access
;
9595 elsif Is_Enumeration_Type
(Typ
) then
9596 Id
:= RE_Type_Class_Enumeration
;
9598 elsif Is_Task_Type
(Typ
) then
9599 Id
:= RE_Type_Class_Task
;
9601 -- We treat protected types like task types. It would make more
9602 -- sense to have another enumeration value, but after all the
9603 -- whole point of this feature is to be exactly DEC compatible,
9604 -- and changing the type Type_Class would not meet this requirement.
9606 elsif Is_Protected_Type
(Typ
) then
9607 Id
:= RE_Type_Class_Task
;
9609 -- Not clear if there are any other possibilities, but if there
9610 -- are, then we will treat them as the address case.
9613 Id
:= RE_Type_Class_Address
;
9616 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
9619 -----------------------
9620 -- Unbiased_Rounding --
9621 -----------------------
9623 when Attribute_Unbiased_Rounding
=>
9626 Eval_Fat
.Unbiased_Rounding
(P_Base_Type
, Expr_Value_R
(E1
)),
9629 -------------------------
9630 -- Unconstrained_Array --
9631 -------------------------
9633 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
9634 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9637 Rewrite
(N
, New_Occurrence_Of
(
9639 Is_Array_Type
(P_Type
)
9640 and then not Is_Constrained
(Typ
)), Loc
));
9642 -- Analyze and resolve as boolean, note that this attribute is
9643 -- a static attribute in GNAT.
9645 Analyze_And_Resolve
(N
, Standard_Boolean
);
9647 Set_Is_Static_Expression
(N
, True);
9648 end Unconstrained_Array
;
9650 -- Attribute Update is never static
9652 when Attribute_Update
=>
9659 -- Processing is shared with Size
9665 when Attribute_Val
=> Val
:
9667 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
9669 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
9671 Apply_Compile_Time_Constraint_Error
9672 (N
, "Val expression out of range",
9673 CE_Range_Check_Failed
,
9674 Warn
=> not Static
);
9680 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
9688 -- The Value_Size attribute for a type returns the RM size of the type.
9689 -- This an always be folded for scalar types, and can also be folded for
9690 -- non-scalar types if the size is set. This is one of the places where
9691 -- it is annoying that a size of zero means two things!
9693 when Attribute_Value_Size
=> Value_Size
: declare
9694 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
9696 if Is_Scalar_Type
(P_TypeA
) or else RM_Size
(P_TypeA
) /= Uint_0
then
9697 Fold_Uint
(N
, RM_Size
(P_TypeA
), Static
);
9705 -- Version can never be static
9707 when Attribute_Version
=>
9714 -- Wide_Image is a scalar attribute, but is never static, because it
9715 -- is not a static function (having a non-scalar argument (RM 4.9(22))
9717 when Attribute_Wide_Image
=>
9720 ---------------------
9721 -- Wide_Wide_Image --
9722 ---------------------
9724 -- Wide_Wide_Image is a scalar attribute but is never static, because it
9725 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
9727 when Attribute_Wide_Wide_Image
=>
9730 ---------------------
9731 -- Wide_Wide_Width --
9732 ---------------------
9734 -- Processing for Wide_Wide_Width is combined with Width
9740 -- Processing for Wide_Width is combined with Width
9746 -- This processing also handles the case of Wide_[Wide_]Width
9748 when Attribute_Width |
9749 Attribute_Wide_Width |
9750 Attribute_Wide_Wide_Width
=> Width
:
9752 if Compile_Time_Known_Bounds
(P_Type
) then
9754 -- Floating-point types
9756 if Is_Floating_Point_Type
(P_Type
) then
9758 -- Width is zero for a null range (RM 3.5 (38))
9760 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
9761 Expr_Value_R
(Type_Low_Bound
(P_Type
))
9763 Fold_Uint
(N
, Uint_0
, Static
);
9766 -- For floating-point, we have +N.dddE+nnn where length
9767 -- of ddd is determined by type'Digits - 1, but is one
9768 -- if Digits is one (RM 3.5 (33)).
9770 -- nnn is set to 2 for Short_Float and Float (32 bit
9771 -- floats), and 3 for Long_Float and Long_Long_Float.
9772 -- For machines where Long_Long_Float is the IEEE
9773 -- extended precision type, the exponent takes 4 digits.
9777 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
9780 if Esize
(P_Type
) <= 32 then
9782 elsif Esize
(P_Type
) = 64 then
9788 Fold_Uint
(N
, UI_From_Int
(Len
), Static
);
9792 -- Fixed-point types
9794 elsif Is_Fixed_Point_Type
(P_Type
) then
9796 -- Width is zero for a null range (RM 3.5 (38))
9798 if Expr_Value
(Type_High_Bound
(P_Type
)) <
9799 Expr_Value
(Type_Low_Bound
(P_Type
))
9801 Fold_Uint
(N
, Uint_0
, Static
);
9803 -- The non-null case depends on the specific real type
9806 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
9809 (N
, UI_From_Int
(Fore_Value
+ 1) + Aft_Value
(P_Type
),
9817 R
: constant Entity_Id
:= Root_Type
(P_Type
);
9818 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
9819 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
9832 -- Width for types derived from Standard.Character
9833 -- and Standard.Wide_[Wide_]Character.
9835 elsif Is_Standard_Character_Type
(P_Type
) then
9838 -- Set W larger if needed
9840 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
9842 -- All wide characters look like Hex_hhhhhhhh
9846 -- No need to compute this more than once
9851 C
:= Character'Val (J
);
9853 -- Test for all cases where Character'Image
9854 -- yields an image that is longer than three
9855 -- characters. First the cases of Reserved_xxx
9856 -- names (length = 12).
9859 when Reserved_128 | Reserved_129 |
9860 Reserved_132 | Reserved_153
9863 when BS | HT | LF | VT | FF | CR |
9864 SO | SI | EM | FS | GS | RS |
9865 US | RI | MW | ST | PM
9868 when NUL | SOH | STX | ETX | EOT |
9869 ENQ | ACK | BEL | DLE | DC1 |
9870 DC2 | DC3 | DC4 | NAK | SYN |
9871 ETB | CAN | SUB | ESC | DEL |
9872 BPH | NBH | NEL | SSA | ESA |
9873 HTS | HTJ | VTS | PLD | PLU |
9874 SS2 | SS3 | DCS | PU1 | PU2 |
9875 STS | CCH | SPA | EPA | SOS |
9876 SCI | CSI | OSC | APC
9879 when Space
.. Tilde |
9880 No_Break_Space
.. LC_Y_Diaeresis
9882 -- Special case of soft hyphen in Ada 2005
9884 if C
= Character'Val (16#AD#
)
9885 and then Ada_Version
>= Ada_2005
9893 W
:= Int
'Max (W
, Wt
);
9897 -- Width for types derived from Standard.Boolean
9899 elsif R
= Standard_Boolean
then
9906 -- Width for integer types
9908 elsif Is_Integer_Type
(P_Type
) then
9909 T
:= UI_Max
(abs Lo
, abs Hi
);
9917 -- User declared enum type with discard names
9919 elsif Discard_Names
(R
) then
9921 -- If range is null, result is zero, that has already
9922 -- been dealt with, so what we need is the power of ten
9923 -- that accomodates the Pos of the largest value, which
9924 -- is the high bound of the range + one for the space.
9933 -- Only remaining possibility is user declared enum type
9934 -- with normal case of Discard_Names not active.
9937 pragma Assert
(Is_Enumeration_Type
(P_Type
));
9940 L
:= First_Literal
(P_Type
);
9941 while Present
(L
) loop
9943 -- Only pay attention to in range characters
9945 if Lo
<= Enumeration_Pos
(L
)
9946 and then Enumeration_Pos
(L
) <= Hi
9948 -- For Width case, use decoded name
9950 if Id
= Attribute_Width
then
9951 Get_Decoded_Name_String
(Chars
(L
));
9952 Wt
:= Nat
(Name_Len
);
9954 -- For Wide_[Wide_]Width, use encoded name, and
9955 -- then adjust for the encoding.
9958 Get_Name_String
(Chars
(L
));
9960 -- Character literals are always of length 3
9962 if Name_Buffer
(1) = 'Q' then
9965 -- Otherwise loop to adjust for upper/wide chars
9968 Wt
:= Nat
(Name_Len
);
9970 for J
in 1 .. Name_Len
loop
9971 if Name_Buffer
(J
) = 'U' then
9973 elsif Name_Buffer
(J
) = 'W' then
9980 W
:= Int
'Max (W
, Wt
);
9987 Fold_Uint
(N
, UI_From_Int
(W
), Static
);
9993 -- The following attributes denote functions that cannot be folded
9995 when Attribute_From_Any |
9997 Attribute_TypeCode
=>
10000 -- The following attributes can never be folded, and furthermore we
10001 -- should not even have entered the case statement for any of these.
10002 -- Note that in some cases, the values have already been folded as
10003 -- a result of the processing in Analyze_Attribute or earlier in
10006 when Attribute_Abort_Signal |
10008 Attribute_Address |
10009 Attribute_Address_Size |
10010 Attribute_Asm_Input |
10011 Attribute_Asm_Output |
10013 Attribute_Bit_Order |
10014 Attribute_Bit_Position |
10015 Attribute_Callable |
10018 Attribute_Code_Address |
10019 Attribute_Compiler_Version |
10021 Attribute_Default_Bit_Order |
10022 Attribute_Default_Scalar_Storage_Order |
10024 Attribute_Elaborated |
10025 Attribute_Elab_Body |
10026 Attribute_Elab_Spec |
10027 Attribute_Elab_Subp_Body |
10028 Attribute_Enabled |
10029 Attribute_External_Tag |
10030 Attribute_Fast_Math |
10031 Attribute_First_Bit |
10034 Attribute_Last_Bit |
10035 Attribute_Library_Level |
10036 Attribute_Maximum_Alignment |
10039 Attribute_Partition_ID |
10040 Attribute_Pool_Address |
10041 Attribute_Position |
10042 Attribute_Priority |
10045 Attribute_Scalar_Storage_Order |
10046 Attribute_Simple_Storage_Pool |
10047 Attribute_Storage_Pool |
10048 Attribute_Storage_Size |
10049 Attribute_Storage_Unit |
10050 Attribute_Stub_Type |
10051 Attribute_System_Allocator_Alignment |
10053 Attribute_Target_Name |
10054 Attribute_Terminated |
10055 Attribute_To_Address |
10056 Attribute_Type_Key |
10057 Attribute_Unchecked_Access |
10058 Attribute_Universal_Literal_String |
10059 Attribute_Unrestricted_Access |
10061 Attribute_Valid_Scalars |
10063 Attribute_Wchar_T_Size |
10064 Attribute_Wide_Value |
10065 Attribute_Wide_Wide_Value |
10066 Attribute_Word_Size |
10069 raise Program_Error
;
10072 -- At the end of the case, one more check. If we did a static evaluation
10073 -- so that the result is now a literal, then set Is_Static_Expression
10074 -- in the constant only if the prefix type is a static subtype. For
10075 -- non-static subtypes, the folding is still OK, but not static.
10077 -- An exception is the GNAT attribute Constrained_Array which is
10078 -- defined to be a static attribute in all cases.
10080 if Nkind_In
(N
, N_Integer_Literal
,
10082 N_Character_Literal
,
10084 or else (Is_Entity_Name
(N
)
10085 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
10087 Set_Is_Static_Expression
(N
, Static
);
10089 -- If this is still an attribute reference, then it has not been folded
10090 -- and that means that its expressions are in a non-static context.
10092 elsif Nkind
(N
) = N_Attribute_Reference
then
10095 -- Note: the else case not covered here are odd cases where the
10096 -- processing has transformed the attribute into something other
10097 -- than a constant. Nothing more to do in such cases.
10102 end Eval_Attribute
;
10104 ------------------------------
10105 -- Is_Anonymous_Tagged_Base --
10106 ------------------------------
10108 function Is_Anonymous_Tagged_Base
10110 Typ
: Entity_Id
) return Boolean
10114 Anon
= Current_Scope
10115 and then Is_Itype
(Anon
)
10116 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
10117 end Is_Anonymous_Tagged_Base
;
10119 --------------------------------
10120 -- Name_Implies_Lvalue_Prefix --
10121 --------------------------------
10123 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
10124 pragma Assert
(Is_Attribute_Name
(Nam
));
10126 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
10127 end Name_Implies_Lvalue_Prefix
;
10129 -----------------------
10130 -- Resolve_Attribute --
10131 -----------------------
10133 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
10134 Loc
: constant Source_Ptr
:= Sloc
(N
);
10135 P
: constant Node_Id
:= Prefix
(N
);
10136 Aname
: constant Name_Id
:= Attribute_Name
(N
);
10137 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
10138 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10139 Des_Btyp
: Entity_Id
;
10140 Index
: Interp_Index
;
10142 Nom_Subt
: Entity_Id
;
10144 procedure Accessibility_Message
;
10145 -- Error, or warning within an instance, if the static accessibility
10146 -- rules of 3.10.2 are violated.
10148 function Declared_Within_Generic_Unit
10149 (Entity
: Entity_Id
;
10150 Generic_Unit
: Node_Id
) return Boolean;
10151 -- Returns True if Declared_Entity is declared within the declarative
10152 -- region of Generic_Unit; otherwise returns False.
10154 ---------------------------
10155 -- Accessibility_Message --
10156 ---------------------------
10158 procedure Accessibility_Message
is
10159 Indic
: Node_Id
:= Parent
(Parent
(N
));
10162 -- In an instance, this is a runtime check, but one we
10163 -- know will fail, so generate an appropriate warning.
10165 if In_Instance_Body
then
10166 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10168 ("non-local pointer cannot point to local object<<", P
);
10169 Error_Msg_F
("\Program_Error [<<", P
);
10171 Make_Raise_Program_Error
(Loc
,
10172 Reason
=> PE_Accessibility_Check_Failed
));
10173 Set_Etype
(N
, Typ
);
10177 Error_Msg_F
("non-local pointer cannot point to local object", P
);
10179 -- Check for case where we have a missing access definition
10181 if Is_Record_Type
(Current_Scope
)
10183 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
10184 N_Index_Or_Discriminant_Constraint
)
10186 Indic
:= Parent
(Parent
(N
));
10187 while Present
(Indic
)
10188 and then Nkind
(Indic
) /= N_Subtype_Indication
10190 Indic
:= Parent
(Indic
);
10193 if Present
(Indic
) then
10195 ("\use an access definition for" &
10196 " the access discriminant of&",
10197 N
, Entity
(Subtype_Mark
(Indic
)));
10201 end Accessibility_Message
;
10203 ----------------------------------
10204 -- Declared_Within_Generic_Unit --
10205 ----------------------------------
10207 function Declared_Within_Generic_Unit
10208 (Entity
: Entity_Id
;
10209 Generic_Unit
: Node_Id
) return Boolean
10211 Generic_Encloser
: Node_Id
:= Enclosing_Generic_Unit
(Entity
);
10214 while Present
(Generic_Encloser
) loop
10215 if Generic_Encloser
= Generic_Unit
then
10219 -- We have to step to the scope of the generic's entity, because
10220 -- otherwise we'll just get back the same generic.
10222 Generic_Encloser
:=
10223 Enclosing_Generic_Unit
10224 (Scope
(Defining_Entity
(Generic_Encloser
)));
10228 end Declared_Within_Generic_Unit
;
10230 -- Start of processing for Resolve_Attribute
10233 -- If error during analysis, no point in continuing, except for array
10234 -- types, where we get better recovery by using unconstrained indexes
10235 -- than nothing at all (see Check_Array_Type).
10237 if Error_Posted
(N
)
10238 and then Attr_Id
/= Attribute_First
10239 and then Attr_Id
/= Attribute_Last
10240 and then Attr_Id
/= Attribute_Length
10241 and then Attr_Id
/= Attribute_Range
10246 -- If attribute was universal type, reset to actual type
10248 if Etype
(N
) = Universal_Integer
10249 or else Etype
(N
) = Universal_Real
10251 Set_Etype
(N
, Typ
);
10254 -- Remaining processing depends on attribute
10262 -- For access attributes, if the prefix denotes an entity, it is
10263 -- interpreted as a name, never as a call. It may be overloaded,
10264 -- in which case resolution uses the profile of the context type.
10265 -- Otherwise prefix must be resolved.
10267 when Attribute_Access
10268 | Attribute_Unchecked_Access
10269 | Attribute_Unrestricted_Access
=>
10273 -- Note possible modification if we have a variable
10275 if Is_Variable
(P
) then
10277 PN
: constant Node_Id
:= Parent
(N
);
10280 Note
: Boolean := True;
10281 -- Skip this for the case of Unrestricted_Access occuring in
10282 -- the context of a Valid check, since this otherwise leads
10283 -- to a missed warning (the Valid check does not really
10284 -- modify!) If this case, Note will be reset to False.
10286 -- Skip it as well if the type is an Acccess_To_Constant,
10287 -- given that no use of the value can modify the prefix.
10290 if Attr_Id
= Attribute_Unrestricted_Access
10291 and then Nkind
(PN
) = N_Function_Call
10295 if Nkind
(Nm
) = N_Expanded_Name
10296 and then Chars
(Nm
) = Name_Valid
10297 and then Nkind
(Prefix
(Nm
)) = N_Identifier
10298 and then Chars
(Prefix
(Nm
)) = Name_Attr_Long_Float
10303 elsif Is_Access_Constant
(Typ
) then
10308 Note_Possible_Modification
(P
, Sure
=> False);
10313 -- The following comes from a query concerning improper use of
10314 -- universal_access in equality tests involving anonymous access
10315 -- types. Another good reason for 'Ref, but for now disable the
10316 -- test, which breaks several filed tests???
10318 if Ekind
(Typ
) = E_Anonymous_Access_Type
10319 and then Nkind_In
(Parent
(N
), N_Op_Eq
, N_Op_Ne
)
10322 Error_Msg_N
("need unique type to resolve 'Access", N
);
10323 Error_Msg_N
("\qualify attribute with some access type", N
);
10326 -- Case where prefix is an entity name
10328 if Is_Entity_Name
(P
) then
10330 -- Deal with case where prefix itself is overloaded
10332 if Is_Overloaded
(P
) then
10333 Get_First_Interp
(P
, Index
, It
);
10334 while Present
(It
.Nam
) loop
10335 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
10336 Set_Entity
(P
, It
.Nam
);
10338 -- The prefix is definitely NOT overloaded anymore at
10339 -- this point, so we reset the Is_Overloaded flag to
10340 -- avoid any confusion when reanalyzing the node.
10342 Set_Is_Overloaded
(P
, False);
10343 Set_Is_Overloaded
(N
, False);
10344 Generate_Reference
(Entity
(P
), P
);
10348 Get_Next_Interp
(Index
, It
);
10351 -- If Prefix is a subprogram name, this reference freezes,
10352 -- but not if within spec expression mode. The profile of
10353 -- the subprogram is not frozen at this point.
10355 if not In_Spec_Expression
then
10356 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10359 -- If it is a type, there is nothing to resolve.
10360 -- If it is a subprogram, do not freeze its profile.
10361 -- If it is an object, complete its resolution.
10363 elsif Is_Overloadable
(Entity
(P
)) then
10364 if not In_Spec_Expression
then
10365 Freeze_Before
(N
, Entity
(P
), Do_Freeze_Profile
=> False);
10368 -- Nothing to do if prefix is a type name
10370 elsif Is_Type
(Entity
(P
)) then
10373 -- Otherwise non-overloaded other case, resolve the prefix
10379 -- Some further error checks
10381 Error_Msg_Name_1
:= Aname
;
10383 if not Is_Entity_Name
(P
) then
10386 elsif Is_Overloadable
(Entity
(P
))
10387 and then Is_Abstract_Subprogram
(Entity
(P
))
10389 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
10390 Set_Etype
(N
, Any_Type
);
10392 elsif Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
10394 ("prefix of % attribute cannot be enumeration literal", P
);
10395 Set_Etype
(N
, Any_Type
);
10397 -- An attempt to take 'Access of a function that renames an
10398 -- enumeration literal. Issue a specialized error message.
10400 elsif Ekind
(Entity
(P
)) = E_Function
10401 and then Present
(Alias
(Entity
(P
)))
10402 and then Ekind
(Alias
(Entity
(P
))) = E_Enumeration_Literal
10405 ("prefix of % attribute cannot be function renaming "
10406 & "an enumeration literal", P
);
10407 Set_Etype
(N
, Any_Type
);
10409 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
10410 Error_Msg_F
("prefix of % attribute cannot be intrinsic", P
);
10411 Set_Etype
(N
, Any_Type
);
10414 -- Assignments, return statements, components of aggregates,
10415 -- generic instantiations will require convention checks if
10416 -- the type is an access to subprogram. Given that there will
10417 -- also be accessibility checks on those, this is where the
10418 -- checks can eventually be centralized ???
10420 if Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10421 E_Anonymous_Access_Subprogram_Type
,
10422 E_Access_Protected_Subprogram_Type
,
10423 E_Anonymous_Access_Protected_Subprogram_Type
)
10425 -- Deal with convention mismatch
10427 if Convention
(Designated_Type
(Btyp
)) /=
10428 Convention
(Entity
(P
))
10431 ("subprogram & has wrong convention", P
, Entity
(P
));
10432 Error_Msg_Sloc
:= Sloc
(Btyp
);
10433 Error_Msg_FE
("\does not match & declared#", P
, Btyp
);
10435 if not Is_Itype
(Btyp
)
10436 and then not Has_Convention_Pragma
(Btyp
)
10439 ("\probable missing pragma Convention for &",
10444 Check_Subtype_Conformant
10445 (New_Id
=> Entity
(P
),
10446 Old_Id
=> Designated_Type
(Btyp
),
10450 if Attr_Id
= Attribute_Unchecked_Access
then
10451 Error_Msg_Name_1
:= Aname
;
10453 ("attribute% cannot be applied to a subprogram", P
);
10455 elsif Aname
= Name_Unrestricted_Access
then
10456 null; -- Nothing to check
10458 -- Check the static accessibility rule of 3.10.2(32).
10459 -- This rule also applies within the private part of an
10460 -- instantiation. This rule does not apply to anonymous
10461 -- access-to-subprogram types in access parameters.
10463 elsif Attr_Id
= Attribute_Access
10464 and then not In_Instance_Body
10466 (Ekind
(Btyp
) = E_Access_Subprogram_Type
10467 or else Is_Local_Anonymous_Access
(Btyp
))
10468 and then Subprogram_Access_Level
(Entity
(P
)) >
10469 Type_Access_Level
(Btyp
)
10472 ("subprogram must not be deeper than access type", P
);
10474 -- Check the restriction of 3.10.2(32) that disallows the
10475 -- access attribute within a generic body when the ultimate
10476 -- ancestor of the type of the attribute is declared outside
10477 -- of the generic unit and the subprogram is declared within
10478 -- that generic unit. This includes any such attribute that
10479 -- occurs within the body of a generic unit that is a child
10480 -- of the generic unit where the subprogram is declared.
10482 -- The rule also prohibits applying the attribute when the
10483 -- access type is a generic formal access type (since the
10484 -- level of the actual type is not known). This restriction
10485 -- does not apply when the attribute type is an anonymous
10486 -- access-to-subprogram type. Note that this check was
10487 -- revised by AI-229, because the original Ada 95 rule
10488 -- was too lax. The original rule only applied when the
10489 -- subprogram was declared within the body of the generic,
10490 -- which allowed the possibility of dangling references).
10491 -- The rule was also too strict in some cases, in that it
10492 -- didn't permit the access to be declared in the generic
10493 -- spec, whereas the revised rule does (as long as it's not
10496 -- There are a couple of subtleties of the test for applying
10497 -- the check that are worth noting. First, we only apply it
10498 -- when the levels of the subprogram and access type are the
10499 -- same (the case where the subprogram is statically deeper
10500 -- was applied above, and the case where the type is deeper
10501 -- is always safe). Second, we want the check to apply
10502 -- within nested generic bodies and generic child unit
10503 -- bodies, but not to apply to an attribute that appears in
10504 -- the generic unit's specification. This is done by testing
10505 -- that the attribute's innermost enclosing generic body is
10506 -- not the same as the innermost generic body enclosing the
10507 -- generic unit where the subprogram is declared (we don't
10508 -- want the check to apply when the access attribute is in
10509 -- the spec and there's some other generic body enclosing
10510 -- generic). Finally, there's no point applying the check
10511 -- when within an instance, because any violations will have
10512 -- been caught by the compilation of the generic unit.
10514 -- We relax this check in Relaxed_RM_Semantics mode for
10515 -- compatibility with legacy code for use by Ada source
10516 -- code analyzers (e.g. CodePeer).
10518 elsif Attr_Id
= Attribute_Access
10519 and then not Relaxed_RM_Semantics
10520 and then not In_Instance
10521 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
10522 and then Present
(Enclosing_Generic_Body
(N
))
10523 and then Enclosing_Generic_Body
(N
) /=
10524 Enclosing_Generic_Body
10525 (Enclosing_Generic_Unit
(Entity
(P
)))
10526 and then Subprogram_Access_Level
(Entity
(P
)) =
10527 Type_Access_Level
(Btyp
)
10528 and then Ekind
(Btyp
) /=
10529 E_Anonymous_Access_Subprogram_Type
10530 and then Ekind
(Btyp
) /=
10531 E_Anonymous_Access_Protected_Subprogram_Type
10533 -- The attribute type's ultimate ancestor must be
10534 -- declared within the same generic unit as the
10535 -- subprogram is declared (including within another
10536 -- nested generic unit). The error message is
10537 -- specialized to say "ancestor" for the case where the
10538 -- access type is not its own ancestor, since saying
10539 -- simply "access type" would be very confusing.
10541 if not Declared_Within_Generic_Unit
10543 Enclosing_Generic_Unit
(Entity
(P
)))
10546 ("''Access attribute not allowed in generic body",
10549 if Root_Type
(Btyp
) = Btyp
then
10552 "access type & is declared outside " &
10553 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10556 ("\because ancestor of " &
10557 "access type & is declared outside " &
10558 "generic unit (RM 3.10.2(32))", N
, Btyp
);
10562 ("\move ''Access to private part, or " &
10563 "(Ada 2005) use anonymous access type instead of &",
10566 -- If the ultimate ancestor of the attribute's type is
10567 -- a formal type, then the attribute is illegal because
10568 -- the actual type might be declared at a higher level.
10569 -- The error message is specialized to say "ancestor"
10570 -- for the case where the access type is not its own
10571 -- ancestor, since saying simply "access type" would be
10574 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
10575 if Root_Type
(Btyp
) = Btyp
then
10577 ("access type must not be a generic formal type",
10581 ("ancestor access type must not be a generic " &
10588 -- If this is a renaming, an inherited operation, or a
10589 -- subprogram instance, use the original entity. This may make
10590 -- the node type-inconsistent, so this transformation can only
10591 -- be done if the node will not be reanalyzed. In particular,
10592 -- if it is within a default expression, the transformation
10593 -- must be delayed until the default subprogram is created for
10594 -- it, when the enclosing subprogram is frozen.
10596 if Is_Entity_Name
(P
)
10597 and then Is_Overloadable
(Entity
(P
))
10598 and then Present
(Alias
(Entity
(P
)))
10599 and then Expander_Active
10602 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
10605 elsif Nkind
(P
) = N_Selected_Component
10606 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
10608 -- Protected operation. If operation is overloaded, must
10609 -- disambiguate. Prefix that denotes protected object itself
10610 -- is resolved with its own type.
10612 if Attr_Id
= Attribute_Unchecked_Access
then
10613 Error_Msg_Name_1
:= Aname
;
10615 ("attribute% cannot be applied to protected operation", P
);
10618 Resolve
(Prefix
(P
));
10619 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
10621 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
10622 -- statically illegal if F is an anonymous access to subprogram.
10624 elsif Nkind
(P
) = N_Explicit_Dereference
10625 and then Is_Entity_Name
(Prefix
(P
))
10626 and then Ekind
(Etype
(Entity
(Prefix
(P
)))) =
10627 E_Anonymous_Access_Subprogram_Type
10629 Error_Msg_N
("anonymous access to subprogram "
10630 & "has deeper accessibility than any master", P
);
10632 elsif Is_Overloaded
(P
) then
10634 -- Use the designated type of the context to disambiguate
10635 -- Note that this was not strictly conformant to Ada 95,
10636 -- but was the implementation adopted by most Ada 95 compilers.
10637 -- The use of the context type to resolve an Access attribute
10638 -- reference is now mandated in AI-235 for Ada 2005.
10641 Index
: Interp_Index
;
10645 Get_First_Interp
(P
, Index
, It
);
10646 while Present
(It
.Typ
) loop
10647 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
10648 Resolve
(P
, It
.Typ
);
10652 Get_Next_Interp
(Index
, It
);
10659 -- X'Access is illegal if X denotes a constant and the access type
10660 -- is access-to-variable. Same for 'Unchecked_Access. The rule
10661 -- does not apply to 'Unrestricted_Access. If the reference is a
10662 -- default-initialized aggregate component for a self-referential
10663 -- type the reference is legal.
10665 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
10666 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
10667 or else (Is_Record_Type
(Btyp
)
10669 Present
(Corresponding_Remote_Type
(Btyp
)))
10670 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10671 or else Ekind
(Btyp
)
10672 = E_Anonymous_Access_Protected_Subprogram_Type
10673 or else Is_Access_Constant
(Btyp
)
10674 or else Is_Variable
(P
)
10675 or else Attr_Id
= Attribute_Unrestricted_Access
)
10677 if Is_Entity_Name
(P
)
10678 and then Is_Type
(Entity
(P
))
10680 -- Legality of a self-reference through an access
10681 -- attribute has been verified in Analyze_Access_Attribute.
10685 elsif Comes_From_Source
(N
) then
10686 Error_Msg_F
("access-to-variable designates constant", P
);
10690 Des_Btyp
:= Designated_Type
(Btyp
);
10692 if Ada_Version
>= Ada_2005
10693 and then Is_Incomplete_Type
(Des_Btyp
)
10695 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
10696 -- imported entity, and the non-limited view is visible, make
10697 -- use of it. If it is an incomplete subtype, use the base type
10700 if From_Limited_With
(Des_Btyp
)
10701 and then Present
(Non_Limited_View
(Des_Btyp
))
10703 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
10705 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
10706 Des_Btyp
:= Etype
(Des_Btyp
);
10710 if (Attr_Id
= Attribute_Access
10712 Attr_Id
= Attribute_Unchecked_Access
)
10713 and then (Ekind
(Btyp
) = E_General_Access_Type
10714 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
10716 -- Ada 2005 (AI-230): Check the accessibility of anonymous
10717 -- access types for stand-alone objects, record and array
10718 -- components, and return objects. For a component definition
10719 -- the level is the same of the enclosing composite type.
10721 if Ada_Version
>= Ada_2005
10722 and then (Is_Local_Anonymous_Access
(Btyp
)
10724 -- Handle cases where Btyp is the anonymous access
10725 -- type of an Ada 2012 stand-alone object.
10727 or else Nkind
(Associated_Node_For_Itype
(Btyp
)) =
10728 N_Object_Declaration
)
10730 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10731 and then Attr_Id
= Attribute_Access
10733 -- In an instance, this is a runtime check, but one we know
10734 -- will fail, so generate an appropriate warning. As usual,
10735 -- this kind of warning is an error in SPARK mode.
10737 if In_Instance_Body
then
10738 Error_Msg_Warn
:= SPARK_Mode
/= On
;
10740 ("non-local pointer cannot point to local object<<", P
);
10741 Error_Msg_F
("\Program_Error [<<", P
);
10744 Make_Raise_Program_Error
(Loc
,
10745 Reason
=> PE_Accessibility_Check_Failed
));
10746 Set_Etype
(N
, Typ
);
10750 ("non-local pointer cannot point to local object", P
);
10754 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
10756 ("illegal attribute for discriminant-dependent component",
10760 -- Check static matching rule of 3.10.2(27). Nominal subtype
10761 -- of the prefix must statically match the designated type.
10763 Nom_Subt
:= Etype
(P
);
10765 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
10766 Nom_Subt
:= Base_Type
(Nom_Subt
);
10769 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
10771 -- If the attribute is in the context of an access
10772 -- parameter, then the prefix is allowed to be of
10773 -- the class-wide type (by AI-127).
10775 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
10776 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10777 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
10783 Desig
:= Designated_Type
(Typ
);
10785 if Is_Class_Wide_Type
(Desig
) then
10786 Desig
:= Etype
(Desig
);
10789 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
10794 ("type of prefix: & not compatible",
10797 ("\with &, the expected designated type",
10798 P
, Designated_Type
(Typ
));
10803 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
10805 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
10806 and then Is_Class_Wide_Type
(Nom_Subt
))
10809 ("type of prefix: & is not covered", P
, Nom_Subt
);
10811 ("\by &, the expected designated type" &
10812 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
10815 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
10816 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
10817 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
10818 and then Designated_Type
(Typ
) /= Nom_Subt
10820 Apply_Discriminant_Check
10821 (N
, Etype
(Designated_Type
(Typ
)));
10824 -- Ada 2005 (AI-363): Require static matching when designated
10825 -- type has discriminants and a constrained partial view, since
10826 -- in general objects of such types are mutable, so we can't
10827 -- allow the access value to designate a constrained object
10828 -- (because access values must be assumed to designate mutable
10829 -- objects when designated type does not impose a constraint).
10831 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
10834 elsif Has_Discriminants
(Designated_Type
(Typ
))
10835 and then not Is_Constrained
(Des_Btyp
)
10837 (Ada_Version
< Ada_2005
10839 not Object_Type_Has_Constrained_Partial_View
10840 (Typ
=> Designated_Type
(Base_Type
(Typ
)),
10841 Scop
=> Current_Scope
))
10847 ("object subtype must statically match "
10848 & "designated subtype", P
);
10850 if Is_Entity_Name
(P
)
10851 and then Is_Array_Type
(Designated_Type
(Typ
))
10854 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
10857 ("aliased object has explicit bounds??", D
);
10859 ("\declare without bounds (and with explicit "
10860 & "initialization)??", D
);
10862 ("\for use with unconstrained access??", D
);
10867 -- Check the static accessibility rule of 3.10.2(28). Note that
10868 -- this check is not performed for the case of an anonymous
10869 -- access type, since the access attribute is always legal
10870 -- in such a context.
10872 if Attr_Id
/= Attribute_Unchecked_Access
10873 and then Ekind
(Btyp
) = E_General_Access_Type
10875 Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10877 Accessibility_Message
;
10882 if Ekind_In
(Btyp
, E_Access_Protected_Subprogram_Type
,
10883 E_Anonymous_Access_Protected_Subprogram_Type
)
10885 if Is_Entity_Name
(P
)
10886 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
10888 Error_Msg_F
("context requires a protected subprogram", P
);
10890 -- Check accessibility of protected object against that of the
10891 -- access type, but only on user code, because the expander
10892 -- creates access references for handlers. If the context is an
10893 -- anonymous_access_to_protected, there are no accessibility
10894 -- checks either. Omit check entirely for Unrestricted_Access.
10896 elsif Object_Access_Level
(P
) > Deepest_Type_Access_Level
(Btyp
)
10897 and then Comes_From_Source
(N
)
10898 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
10899 and then Attr_Id
/= Attribute_Unrestricted_Access
10901 Accessibility_Message
;
10904 -- AI05-0225: If the context is not an access to protected
10905 -- function, the prefix must be a variable, given that it may
10906 -- be used subsequently in a protected call.
10908 elsif Nkind
(P
) = N_Selected_Component
10909 and then not Is_Variable
(Prefix
(P
))
10910 and then Ekind
(Entity
(Selector_Name
(P
))) /= E_Function
10913 ("target object of access to protected procedure "
10914 & "must be variable", N
);
10916 elsif Is_Entity_Name
(P
) then
10917 Check_Internal_Protected_Use
(N
, Entity
(P
));
10920 elsif Ekind_In
(Btyp
, E_Access_Subprogram_Type
,
10921 E_Anonymous_Access_Subprogram_Type
)
10922 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
10924 Error_Msg_F
("context requires a non-protected subprogram", P
);
10927 -- The context cannot be a pool-specific type, but this is a
10928 -- legality rule, not a resolution rule, so it must be checked
10929 -- separately, after possibly disambiguation (see AI-245).
10931 if Ekind
(Btyp
) = E_Access_Type
10932 and then Attr_Id
/= Attribute_Unrestricted_Access
10934 Wrong_Type
(N
, Typ
);
10937 -- The context may be a constrained access type (however ill-
10938 -- advised such subtypes might be) so in order to generate a
10939 -- constraint check when needed set the type of the attribute
10940 -- reference to the base type of the context.
10942 Set_Etype
(N
, Btyp
);
10944 -- Check for incorrect atomic/volatile reference (RM C.6(12))
10946 if Attr_Id
/= Attribute_Unrestricted_Access
then
10947 if Is_Atomic_Object
(P
)
10948 and then not Is_Atomic
(Designated_Type
(Typ
))
10951 ("access to atomic object cannot yield access-to-" &
10952 "non-atomic type", P
);
10954 elsif Is_Volatile_Object
(P
)
10955 and then not Is_Volatile
(Designated_Type
(Typ
))
10958 ("access to volatile object cannot yield access-to-" &
10959 "non-volatile type", P
);
10963 -- Check for unrestricted access where expected type is a thin
10964 -- pointer to an unconstrained array.
10966 if Non_Aliased_Prefix
(N
)
10967 and then Has_Size_Clause
(Typ
)
10968 and then RM_Size
(Typ
) = System_Address_Size
10971 DT
: constant Entity_Id
:= Designated_Type
(Typ
);
10973 if Is_Array_Type
(DT
) and then not Is_Constrained
(DT
) then
10975 ("illegal use of Unrestricted_Access attribute", P
);
10977 ("\attempt to generate thin pointer to unaliased "
10983 -- Mark that address of entity is taken
10985 if Is_Entity_Name
(P
) then
10986 Set_Address_Taken
(Entity
(P
));
10989 -- Deal with possible elaboration check
10991 if Is_Entity_Name
(P
) and then Is_Subprogram
(Entity
(P
)) then
10993 Subp_Id
: constant Entity_Id
:= Entity
(P
);
10994 Scop
: constant Entity_Id
:= Scope
(Subp_Id
);
10995 Subp_Decl
: constant Node_Id
:=
10996 Unit_Declaration_Node
(Subp_Id
);
10997 Flag_Id
: Entity_Id
;
10998 Subp_Body
: Node_Id
;
11000 -- If the access has been taken and the body of the subprogram
11001 -- has not been see yet, indirect calls must be protected with
11002 -- elaboration checks. We have the proper elaboration machinery
11003 -- for subprograms declared in packages, but within a block or
11004 -- a subprogram the body will appear in the same declarative
11005 -- part, and we must insert a check in the eventual body itself
11006 -- using the elaboration flag that we generate now. The check
11007 -- is then inserted when the body is expanded. This processing
11008 -- is not needed for a stand alone expression function because
11009 -- the internally generated spec and body are always inserted
11010 -- as a pair in the same declarative list.
11014 and then Comes_From_Source
(Subp_Id
)
11015 and then Comes_From_Source
(N
)
11016 and then In_Open_Scopes
(Scop
)
11017 and then Ekind_In
(Scop
, E_Block
, E_Procedure
, E_Function
)
11018 and then not Has_Completion
(Subp_Id
)
11019 and then No
(Elaboration_Entity
(Subp_Id
))
11020 and then Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11021 and then Nkind
(Original_Node
(Subp_Decl
)) /=
11022 N_Expression_Function
11024 -- Create elaboration variable for it
11026 Flag_Id
:= Make_Temporary
(Loc
, 'E');
11027 Set_Elaboration_Entity
(Subp_Id
, Flag_Id
);
11028 Set_Is_Frozen
(Flag_Id
);
11030 -- Insert declaration for flag after subprogram
11031 -- declaration. Note that attribute reference may
11032 -- appear within a nested scope.
11034 Insert_After_And_Analyze
(Subp_Decl
,
11035 Make_Object_Declaration
(Loc
,
11036 Defining_Identifier
=> Flag_Id
,
11037 Object_Definition
=>
11038 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
11040 Make_Integer_Literal
(Loc
, Uint_0
)));
11043 -- Taking the 'Access of an expression function freezes its
11044 -- expression (RM 13.14 10.3/3). This does not apply to an
11045 -- expression function that acts as a completion because the
11046 -- generated body is immediately analyzed and the expression
11047 -- is automatically frozen.
11049 if Is_Expression_Function
(Subp_Id
)
11050 and then Present
(Corresponding_Body
(Subp_Decl
))
11053 Unit_Declaration_Node
(Corresponding_Body
(Subp_Decl
));
11055 -- The body has already been analyzed when the expression
11056 -- function acts as a completion.
11058 if Analyzed
(Subp_Body
) then
11061 -- Attribute 'Access may appear within the generated body
11062 -- of the expression function subject to the attribute:
11064 -- function F is (... F'Access ...);
11066 -- If the expression function is on the scope stack, then
11067 -- the body is currently being analyzed. Do not reanalyze
11068 -- it because this will lead to infinite recursion.
11070 elsif In_Open_Scopes
(Subp_Id
) then
11073 -- If reference to the expression function appears in an
11074 -- inner scope, for example as an actual in an instance,
11075 -- this is not a freeze point either.
11077 elsif Scope
(Subp_Id
) /= Current_Scope
then
11080 -- Analyze the body of the expression function to freeze
11081 -- the expression. This takes care of the case where the
11082 -- 'Access is part of dispatch table initialization and
11083 -- the generated body of the expression function has not
11084 -- been analyzed yet.
11087 Analyze
(Subp_Body
);
11092 end Access_Attribute
;
11098 -- Deal with resolving the type for Address attribute, overloading
11099 -- is not permitted here, since there is no context to resolve it.
11101 when Attribute_Address | Attribute_Code_Address
=>
11102 Address_Attribute
: begin
11104 -- To be safe, assume that if the address of a variable is taken,
11105 -- it may be modified via this address, so note modification.
11107 if Is_Variable
(P
) then
11108 Note_Possible_Modification
(P
, Sure
=> False);
11111 if Nkind
(P
) in N_Subexpr
11112 and then Is_Overloaded
(P
)
11114 Get_First_Interp
(P
, Index
, It
);
11115 Get_Next_Interp
(Index
, It
);
11117 if Present
(It
.Nam
) then
11118 Error_Msg_Name_1
:= Aname
;
11120 ("prefix of % attribute cannot be overloaded", P
);
11124 if not Is_Entity_Name
(P
)
11125 or else not Is_Overloadable
(Entity
(P
))
11127 if not Is_Task_Type
(Etype
(P
))
11128 or else Nkind
(P
) = N_Explicit_Dereference
11134 -- If this is the name of a derived subprogram, or that of a
11135 -- generic actual, the address is that of the original entity.
11137 if Is_Entity_Name
(P
)
11138 and then Is_Overloadable
(Entity
(P
))
11139 and then Present
(Alias
(Entity
(P
)))
11142 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
11145 if Is_Entity_Name
(P
) then
11146 Set_Address_Taken
(Entity
(P
));
11149 if Nkind
(P
) = N_Slice
then
11151 -- Arr (X .. Y)'address is identical to Arr (X)'address,
11152 -- even if the array is packed and the slice itself is not
11153 -- addressable. Transform the prefix into an indexed component.
11155 -- Note that the transformation is safe only if we know that
11156 -- the slice is non-null. That is because a null slice can have
11157 -- an out of bounds index value.
11159 -- Right now, gigi blows up if given 'Address on a slice as a
11160 -- result of some incorrect freeze nodes generated by the front
11161 -- end, and this covers up that bug in one case, but the bug is
11162 -- likely still there in the cases not handled by this code ???
11164 -- It's not clear what 'Address *should* return for a null
11165 -- slice with out of bounds indexes, this might be worth an ARG
11168 -- One approach would be to do a length check unconditionally,
11169 -- and then do the transformation below unconditionally, but
11170 -- analyze with checks off, avoiding the problem of the out of
11171 -- bounds index. This approach would interpret the address of
11172 -- an out of bounds null slice as being the address where the
11173 -- array element would be if there was one, which is probably
11174 -- as reasonable an interpretation as any ???
11177 Loc
: constant Source_Ptr
:= Sloc
(P
);
11178 D
: constant Node_Id
:= Discrete_Range
(P
);
11182 if Is_Entity_Name
(D
)
11185 (Type_Low_Bound
(Entity
(D
)),
11186 Type_High_Bound
(Entity
(D
)))
11189 Make_Attribute_Reference
(Loc
,
11190 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
11191 Attribute_Name
=> Name_First
);
11193 elsif Nkind
(D
) = N_Range
11194 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
11196 Lo
:= Low_Bound
(D
);
11202 if Present
(Lo
) then
11204 Make_Indexed_Component
(Loc
,
11205 Prefix
=> Relocate_Node
(Prefix
(P
)),
11206 Expressions
=> New_List
(Lo
)));
11208 Analyze_And_Resolve
(P
);
11212 end Address_Attribute
;
11218 -- Prefix of Body_Version attribute can be a subprogram name which
11219 -- must not be resolved, since this is not a call.
11221 when Attribute_Body_Version
=>
11228 -- Prefix of Caller attribute is an entry name which must not
11229 -- be resolved, since this is definitely not an entry call.
11231 when Attribute_Caller
=>
11238 -- Shares processing with Address attribute
11244 -- If the prefix of the Count attribute is an entry name it must not
11245 -- be resolved, since this is definitely not an entry call. However,
11246 -- if it is an element of an entry family, the index itself may
11247 -- have to be resolved because it can be a general expression.
11249 when Attribute_Count
=>
11250 if Nkind
(P
) = N_Indexed_Component
11251 and then Is_Entity_Name
(Prefix
(P
))
11254 Indx
: constant Node_Id
:= First
(Expressions
(P
));
11255 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
11257 Resolve
(Indx
, Entry_Index_Type
(Fam
));
11258 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
11266 -- Prefix of the Elaborated attribute is a subprogram name which
11267 -- must not be resolved, since this is definitely not a call. Note
11268 -- that it is a library unit, so it cannot be overloaded here.
11270 when Attribute_Elaborated
=>
11277 -- Prefix of Enabled attribute is a check name, which must be treated
11278 -- specially and not touched by Resolve.
11280 when Attribute_Enabled
=>
11287 -- Do not resolve the prefix of Loop_Entry, instead wait until the
11288 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
11289 -- The delay ensures that any generated checks or temporaries are
11290 -- inserted before the relocated prefix.
11292 when Attribute_Loop_Entry
=>
11295 --------------------
11296 -- Mechanism_Code --
11297 --------------------
11299 -- Prefix of the Mechanism_Code attribute is a function name
11300 -- which must not be resolved. Should we check for overloaded ???
11302 when Attribute_Mechanism_Code
=>
11309 -- Most processing is done in sem_dist, after determining the
11310 -- context type. Node is rewritten as a conversion to a runtime call.
11312 when Attribute_Partition_ID
=>
11313 Process_Partition_Id
(N
);
11320 when Attribute_Pool_Address
=>
11327 -- We replace the Range attribute node with a range expression whose
11328 -- bounds are the 'First and 'Last attributes applied to the same
11329 -- prefix. The reason that we do this transformation here instead of
11330 -- in the expander is that it simplifies other parts of the semantic
11331 -- analysis which assume that the Range has been replaced; thus it
11332 -- must be done even when in semantic-only mode (note that the RM
11333 -- specifically mentions this equivalence, we take care that the
11334 -- prefix is only evaluated once).
11336 when Attribute_Range
=> Range_Attribute
:
11343 if not Is_Entity_Name
(P
)
11344 or else not Is_Type
(Entity
(P
))
11349 Dims
:= Expressions
(N
);
11352 Make_Attribute_Reference
(Loc
,
11353 Prefix
=> Duplicate_Subexpr
(P
, Name_Req
=> True),
11354 Attribute_Name
=> Name_Last
,
11355 Expressions
=> Dims
);
11358 Make_Attribute_Reference
(Loc
,
11360 Attribute_Name
=> Name_First
,
11361 Expressions
=> (Dims
));
11363 -- Do not share the dimension indicator, if present. Even
11364 -- though it is a static constant, its source location
11365 -- may be modified when printing expanded code and node
11366 -- sharing will lead to chaos in Sprint.
11368 if Present
(Dims
) then
11369 Set_Expressions
(LB
,
11370 New_List
(New_Copy_Tree
(First
(Dims
))));
11373 -- If the original was marked as Must_Not_Freeze (see code
11374 -- in Sem_Ch3.Make_Index), then make sure the rewriting
11375 -- does not freeze either.
11377 if Must_Not_Freeze
(N
) then
11378 Set_Must_Not_Freeze
(HB
);
11379 Set_Must_Not_Freeze
(LB
);
11380 Set_Must_Not_Freeze
(Prefix
(HB
));
11381 Set_Must_Not_Freeze
(Prefix
(LB
));
11384 if Raises_Constraint_Error
(Prefix
(N
)) then
11386 -- Preserve Sloc of prefix in the new bounds, so that
11387 -- the posted warning can be removed if we are within
11388 -- unreachable code.
11390 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
11391 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
11394 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
11395 Analyze_And_Resolve
(N
, Typ
);
11397 -- Ensure that the expanded range does not have side effects
11399 Force_Evaluation
(LB
);
11400 Force_Evaluation
(HB
);
11402 -- Normally after resolving attribute nodes, Eval_Attribute
11403 -- is called to do any possible static evaluation of the node.
11404 -- However, here since the Range attribute has just been
11405 -- transformed into a range expression it is no longer an
11406 -- attribute node and therefore the call needs to be avoided
11407 -- and is accomplished by simply returning from the procedure.
11410 end Range_Attribute
;
11416 -- We will only come here during the prescan of a spec expression
11417 -- containing a Result attribute. In that case the proper Etype has
11418 -- already been set, and nothing more needs to be done here.
11420 when Attribute_Result
=>
11423 ----------------------
11424 -- Unchecked_Access --
11425 ----------------------
11427 -- Processing is shared with Access
11429 -------------------------
11430 -- Unrestricted_Access --
11431 -------------------------
11433 -- Processing is shared with Access
11439 -- Resolve aggregate components in component associations
11441 when Attribute_Update
=>
11443 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
11444 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
11450 -- Set the Etype of the aggregate to that of the prefix, even
11451 -- though the aggregate may not be a proper representation of a
11452 -- value of the type (missing or duplicated associations, etc.)
11453 -- Complete resolution of the prefix. Note that in Ada 2012 it
11454 -- can be a qualified expression that is e.g. an aggregate.
11456 Set_Etype
(Aggr
, Typ
);
11457 Resolve
(Prefix
(N
), Typ
);
11459 -- For an array type, resolve expressions with the component
11460 -- type of the array, and apply constraint checks when needed.
11462 if Is_Array_Type
(Typ
) then
11463 Assoc
:= First
(Component_Associations
(Aggr
));
11464 while Present
(Assoc
) loop
11465 Expr
:= Expression
(Assoc
);
11466 Resolve
(Expr
, Component_Type
(Typ
));
11468 -- For scalar array components set Do_Range_Check when
11469 -- needed. Constraint checking on non-scalar components
11470 -- is done in Aggregate_Constraint_Checks, but only if
11471 -- full analysis is enabled. These flags are not set in
11472 -- the front-end in GnatProve mode.
11474 if Is_Scalar_Type
(Component_Type
(Typ
))
11475 and then not Is_OK_Static_Expression
(Expr
)
11477 if Is_Entity_Name
(Expr
)
11478 and then Etype
(Expr
) = Component_Type
(Typ
)
11483 Set_Do_Range_Check
(Expr
);
11487 -- The choices in the association are static constants,
11488 -- or static aggregates each of whose components belongs
11489 -- to the proper index type. However, they must also
11490 -- belong to the index subtype (s) of the prefix, which
11491 -- may be a subtype (e.g. given by a slice).
11493 -- Choices may also be identifiers with no staticness
11494 -- requirements, in which case they must resolve to the
11503 C
:= First
(Choices
(Assoc
));
11504 while Present
(C
) loop
11505 Indx
:= First_Index
(Etype
(Prefix
(N
)));
11507 if Nkind
(C
) /= N_Aggregate
then
11508 Analyze_And_Resolve
(C
, Etype
(Indx
));
11509 Apply_Constraint_Check
(C
, Etype
(Indx
));
11510 Check_Non_Static_Context
(C
);
11513 C_E
:= First
(Expressions
(C
));
11514 while Present
(C_E
) loop
11515 Analyze_And_Resolve
(C_E
, Etype
(Indx
));
11516 Apply_Constraint_Check
(C_E
, Etype
(Indx
));
11517 Check_Non_Static_Context
(C_E
);
11531 -- For a record type, use type of each component, which is
11532 -- recorded during analysis.
11535 Assoc
:= First
(Component_Associations
(Aggr
));
11536 while Present
(Assoc
) loop
11537 Comp
:= First
(Choices
(Assoc
));
11538 Expr
:= Expression
(Assoc
);
11540 if Nkind
(Comp
) /= N_Others_Choice
11541 and then not Error_Posted
(Comp
)
11543 Resolve
(Expr
, Etype
(Entity
(Comp
)));
11545 if Is_Scalar_Type
(Etype
(Entity
(Comp
)))
11546 and then not Is_OK_Static_Expression
(Expr
)
11548 Set_Do_Range_Check
(Expr
);
11561 -- Apply range check. Note that we did not do this during the
11562 -- analysis phase, since we wanted Eval_Attribute to have a
11563 -- chance at finding an illegal out of range value.
11565 when Attribute_Val
=>
11567 -- Note that we do our own Eval_Attribute call here rather than
11568 -- use the common one, because we need to do processing after
11569 -- the call, as per above comment.
11571 Eval_Attribute
(N
);
11573 -- Eval_Attribute may replace the node with a raise CE, or
11574 -- fold it to a constant. Obviously we only apply a scalar
11575 -- range check if this did not happen.
11577 if Nkind
(N
) = N_Attribute_Reference
11578 and then Attribute_Name
(N
) = Name_Val
11580 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
11589 -- Prefix of Version attribute can be a subprogram name which
11590 -- must not be resolved, since this is not a call.
11592 when Attribute_Version
=>
11595 ----------------------
11596 -- Other Attributes --
11597 ----------------------
11599 -- For other attributes, resolve prefix unless it is a type. If
11600 -- the attribute reference itself is a type name ('Base and 'Class)
11601 -- then this is only legal within a task or protected record.
11604 if not Is_Entity_Name
(P
) or else not Is_Type
(Entity
(P
)) then
11608 -- If the attribute reference itself is a type name ('Base,
11609 -- 'Class) then this is only legal within a task or protected
11610 -- record. What is this all about ???
11612 if Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
11613 if Is_Concurrent_Type
(Entity
(N
))
11614 and then In_Open_Scopes
(Entity
(P
))
11619 ("invalid use of subtype name in expression or call", N
);
11623 -- For attributes whose argument may be a string, complete
11624 -- resolution of argument now. This avoids premature expansion
11625 -- (and the creation of transient scopes) before the attribute
11626 -- reference is resolved.
11629 when Attribute_Value
=>
11630 Resolve
(First
(Expressions
(N
)), Standard_String
);
11632 when Attribute_Wide_Value
=>
11633 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
11635 when Attribute_Wide_Wide_Value
=>
11636 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
11638 when others => null;
11641 -- If the prefix of the attribute is a class-wide type then it
11642 -- will be expanded into a dispatching call to a predefined
11643 -- primitive. Therefore we must check for potential violation
11644 -- of such restriction.
11646 if Is_Class_Wide_Type
(Etype
(P
)) then
11647 Check_Restriction
(No_Dispatching_Calls
, N
);
11651 -- Normally the Freezing is done by Resolve but sometimes the Prefix
11652 -- is not resolved, in which case the freezing must be done now.
11654 -- For an elaboration check on a subprogram, we do not freeze its type.
11655 -- It may be declared in an unrelated scope, in particular in the case
11656 -- of a generic function whose type may remain unelaborated.
11658 if Attr_Id
= Attribute_Elaborated
then
11662 Freeze_Expression
(P
);
11665 -- Finally perform static evaluation on the attribute reference
11667 Analyze_Dimension
(N
);
11668 Eval_Attribute
(N
);
11669 end Resolve_Attribute
;
11671 ------------------------
11672 -- Set_Boolean_Result --
11673 ------------------------
11675 procedure Set_Boolean_Result
(N
: Node_Id
; B
: Boolean) is
11676 Loc
: constant Source_Ptr
:= Sloc
(N
);
11679 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
11681 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
11683 end Set_Boolean_Result
;
11685 --------------------------------
11686 -- Stream_Attribute_Available --
11687 --------------------------------
11689 function Stream_Attribute_Available
11691 Nam
: TSS_Name_Type
;
11692 Partial_View
: Node_Id
:= Empty
) return Boolean
11694 Etyp
: Entity_Id
:= Typ
;
11696 -- Start of processing for Stream_Attribute_Available
11699 -- We need some comments in this body ???
11701 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
11705 if Is_Class_Wide_Type
(Typ
) then
11706 return not Is_Limited_Type
(Typ
)
11707 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
11710 if Nam
= TSS_Stream_Input
11711 and then Is_Abstract_Type
(Typ
)
11712 and then not Is_Class_Wide_Type
(Typ
)
11717 if not (Is_Limited_Type
(Typ
)
11718 or else (Present
(Partial_View
)
11719 and then Is_Limited_Type
(Partial_View
)))
11724 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
11726 if Nam
= TSS_Stream_Input
11727 and then Ada_Version
>= Ada_2005
11728 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
11732 elsif Nam
= TSS_Stream_Output
11733 and then Ada_Version
>= Ada_2005
11734 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
11739 -- Case of Read and Write: check for attribute definition clause that
11740 -- applies to an ancestor type.
11742 while Etype
(Etyp
) /= Etyp
loop
11743 Etyp
:= Etype
(Etyp
);
11745 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
11750 if Ada_Version
< Ada_2005
then
11752 -- In Ada 95 mode, also consider a non-visible definition
11755 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11758 and then Stream_Attribute_Available
11759 (Btyp
, Nam
, Partial_View
=> Typ
);
11764 end Stream_Attribute_Available
;