Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / sem_attr.adb
blobf5d12ed1c7b2451dd8338ad67badbfdf72c7a87f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ A T T R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
35 with Eval_Fat;
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;
42 with Lib; use Lib;
43 with Lib.Xref; use Lib.Xref;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Opt; use Opt;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Sdefault; use Sdefault;
51 with Sem; use Sem;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch10; use Sem_Ch10;
57 with Sem_Dim; use Sem_Dim;
58 with Sem_Dist; use Sem_Dist;
59 with Sem_Elab; use Sem_Elab;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Res; use Sem_Res;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Stand; use Stand;
66 with Sinfo; use Sinfo;
67 with Sinput; use Sinput;
68 with Stringt; use Stringt;
69 with Style;
70 with Stylesw; use Stylesw;
71 with Targparm; use Targparm;
72 with Ttypes; use Ttypes;
73 with Tbuild; use Tbuild;
74 with Uintp; use Uintp;
75 with Uname; use Uname;
76 with Urealp; use Urealp;
78 package body Sem_Attr is
80 True_Value : constant Uint := Uint_1;
81 False_Value : constant Uint := Uint_0;
82 -- Synonyms to be used when these constants are used as Boolean values
84 Bad_Attribute : exception;
85 -- Exception raised if an error is detected during attribute processing,
86 -- used so that we can abandon the processing so we don't run into
87 -- trouble with cascaded errors.
89 -- The following array is the list of attributes defined in the Ada 83 RM
90 -- that are not included in Ada 95, but still get recognized in GNAT.
92 Attribute_83 : constant Attribute_Class_Array := Attribute_Class_Array'(
93 Attribute_Address |
94 Attribute_Aft |
95 Attribute_Alignment |
96 Attribute_Base |
97 Attribute_Callable |
98 Attribute_Constrained |
99 Attribute_Count |
100 Attribute_Delta |
101 Attribute_Digits |
102 Attribute_Emax |
103 Attribute_Epsilon |
104 Attribute_First |
105 Attribute_First_Bit |
106 Attribute_Fore |
107 Attribute_Image |
108 Attribute_Large |
109 Attribute_Last |
110 Attribute_Last_Bit |
111 Attribute_Leading_Part |
112 Attribute_Length |
113 Attribute_Machine_Emax |
114 Attribute_Machine_Emin |
115 Attribute_Machine_Mantissa |
116 Attribute_Machine_Overflows |
117 Attribute_Machine_Radix |
118 Attribute_Machine_Rounds |
119 Attribute_Mantissa |
120 Attribute_Pos |
121 Attribute_Position |
122 Attribute_Pred |
123 Attribute_Range |
124 Attribute_Safe_Emax |
125 Attribute_Safe_Large |
126 Attribute_Safe_Small |
127 Attribute_Size |
128 Attribute_Small |
129 Attribute_Storage_Size |
130 Attribute_Succ |
131 Attribute_Terminated |
132 Attribute_Val |
133 Attribute_Value |
134 Attribute_Width => True,
135 others => False);
137 -- The following array is the list of attributes defined in the Ada 2005
138 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
139 -- but in Ada 95 they are considered to be implementation defined.
141 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
142 Attribute_Machine_Rounding |
143 Attribute_Mod |
144 Attribute_Priority |
145 Attribute_Stream_Size |
146 Attribute_Wide_Wide_Width => True,
147 others => False);
149 -- The following array contains all attributes that imply a modification
150 -- of their prefixes or result in an access value. Such prefixes can be
151 -- considered as lvalues.
153 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
154 Attribute_Class_Array'(
155 Attribute_Access |
156 Attribute_Address |
157 Attribute_Input |
158 Attribute_Read |
159 Attribute_Unchecked_Access |
160 Attribute_Unrestricted_Access => True,
161 others => False);
163 -----------------------
164 -- Local_Subprograms --
165 -----------------------
167 procedure Eval_Attribute (N : Node_Id);
168 -- Performs compile time evaluation of attributes where possible, leaving
169 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
170 -- set, and replacing the node with a literal node if the value can be
171 -- computed at compile time. All static attribute references are folded,
172 -- as well as a number of cases of non-static attributes that can always
173 -- be computed at compile time (e.g. floating-point model attributes that
174 -- are applied to non-static subtypes). Of course in such cases, the
175 -- Is_Static_Expression flag will not be set on the resulting literal.
176 -- Note that the only required action of this procedure is to catch the
177 -- static expression cases as described in the RM. Folding of other cases
178 -- is done where convenient, but some additional non-static folding is in
179 -- Expand_N_Attribute_Reference in cases where this is more convenient.
181 function Is_Anonymous_Tagged_Base
182 (Anon : Entity_Id;
183 Typ : Entity_Id)
184 return Boolean;
185 -- For derived tagged types that constrain parent discriminants we build
186 -- an anonymous unconstrained base type. We need to recognize the relation
187 -- between the two when analyzing an access attribute for a constrained
188 -- component, before the full declaration for Typ has been analyzed, and
189 -- where therefore the prefix of the attribute does not match the enclosing
190 -- scope.
192 -----------------------
193 -- Analyze_Attribute --
194 -----------------------
196 procedure Analyze_Attribute (N : Node_Id) is
197 Loc : constant Source_Ptr := Sloc (N);
198 Aname : constant Name_Id := Attribute_Name (N);
199 P : constant Node_Id := Prefix (N);
200 Exprs : constant List_Id := Expressions (N);
201 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
202 E1 : Node_Id;
203 E2 : Node_Id;
205 P_Type : Entity_Id;
206 -- Type of prefix after analysis
208 P_Base_Type : Entity_Id;
209 -- Base type of prefix after analysis
211 -----------------------
212 -- Local Subprograms --
213 -----------------------
215 procedure Analyze_Access_Attribute;
216 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
217 -- Internally, Id distinguishes which of the three cases is involved.
219 procedure Bad_Attribute_For_Predicate;
220 -- Output error message for use of a predicate (First, Last, Range) not
221 -- allowed with a type that has predicates. If the type is a generic
222 -- actual, then the message is a warning, and we generate code to raise
223 -- program error with an appropriate reason. No error message is given
224 -- for internally generated uses of the attributes. This legality rule
225 -- only applies to scalar types.
227 procedure Check_Ada_2012_Attribute;
228 -- Check that we are in Ada 2012 mode for an Ada 2012 attribute, and
229 -- issue appropriate messages if not (and return to caller even in
230 -- the error case).
232 procedure Check_Array_Or_Scalar_Type;
233 -- Common procedure used by First, Last, Range attribute to check
234 -- that the prefix is a constrained array or scalar type, or a name
235 -- of an array object, and that an argument appears only if appropriate
236 -- (i.e. only in the array case).
238 procedure Check_Array_Type;
239 -- Common semantic checks for all array attributes. Checks that the
240 -- prefix is a constrained array type or the name of an array object.
241 -- The error message for non-arrays is specialized appropriately.
243 procedure Check_Asm_Attribute;
244 -- Common semantic checks for Asm_Input and Asm_Output attributes
246 procedure Check_Component;
247 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
248 -- Position. Checks prefix is an appropriate selected component.
250 procedure Check_Decimal_Fixed_Point_Type;
251 -- Check that prefix of attribute N is a decimal fixed-point type
253 procedure Check_Dereference;
254 -- If the prefix of attribute is an object of an access type, then
255 -- introduce an explicit dereference, and adjust P_Type accordingly.
257 procedure Check_Discrete_Type;
258 -- Verify that prefix of attribute N is a discrete type
260 procedure Check_E0;
261 -- Check that no attribute arguments are present
263 procedure Check_Either_E0_Or_E1;
264 -- Check that there are zero or one attribute arguments present
266 procedure Check_E1;
267 -- Check that exactly one attribute argument is present
269 procedure Check_E2;
270 -- Check that two attribute arguments are present
272 procedure Check_Enum_Image;
273 -- If the prefix type is an enumeration type, set all its literals
274 -- as referenced, since the image function could possibly end up
275 -- referencing any of the literals indirectly. Same for Enum_Val.
276 -- Set the flag only if the reference is in the main code unit. Same
277 -- restriction when resolving 'Value; otherwise an improperly set
278 -- reference when analyzing an inlined body will lose a proper warning
279 -- on a useless with_clause.
281 procedure Check_First_Last_Valid;
282 -- Perform all checks for First_Valid and Last_Valid attributes
284 procedure Check_Fixed_Point_Type;
285 -- Verify that prefix of attribute N is a fixed type
287 procedure Check_Fixed_Point_Type_0;
288 -- Verify that prefix of attribute N is a fixed type and that
289 -- no attribute expressions are present
291 procedure Check_Floating_Point_Type;
292 -- Verify that prefix of attribute N is a float type
294 procedure Check_Floating_Point_Type_0;
295 -- Verify that prefix of attribute N is a float type and that
296 -- no attribute expressions are present
298 procedure Check_Floating_Point_Type_1;
299 -- Verify that prefix of attribute N is a float type and that
300 -- exactly one attribute expression is present
302 procedure Check_Floating_Point_Type_2;
303 -- Verify that prefix of attribute N is a float type and that
304 -- two attribute expressions are present
306 procedure Legal_Formal_Attribute;
307 -- Common processing for attributes Definite and Has_Discriminants.
308 -- Checks that prefix is generic indefinite formal type.
310 procedure Check_SPARK_Restriction_On_Attribute;
311 -- Issue an error in formal mode because attribute N is allowed
313 procedure Check_Integer_Type;
314 -- Verify that prefix of attribute N is an integer type
316 procedure Check_Modular_Integer_Type;
317 -- Verify that prefix of attribute N is a modular integer type
319 procedure Check_Not_CPP_Type;
320 -- Check that P (the prefix of the attribute) is not an CPP type
321 -- for which no Ada predefined primitive is available.
323 procedure Check_Not_Incomplete_Type;
324 -- Check that P (the prefix of the attribute) is not an incomplete
325 -- type or a private type for which no full view has been given.
327 procedure Check_Object_Reference (P : Node_Id);
328 -- Check that P is an object reference
330 procedure Check_Program_Unit;
331 -- Verify that prefix of attribute N is a program unit
333 procedure Check_Real_Type;
334 -- Verify that prefix of attribute N is fixed or float type
336 procedure Check_Scalar_Type;
337 -- Verify that prefix of attribute N is a scalar type
339 procedure Check_Standard_Prefix;
340 -- Verify that prefix of attribute N is package Standard
342 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
343 -- Validity checking for stream attribute. Nam is the TSS name of the
344 -- corresponding possible defined attribute function (e.g. for the
345 -- Read attribute, Nam will be TSS_Stream_Read).
347 procedure Check_PolyORB_Attribute;
348 -- Validity checking for PolyORB/DSA attribute
350 procedure Check_Task_Prefix;
351 -- Verify that prefix of attribute N is a task or task type
353 procedure Check_Type;
354 -- Verify that the prefix of attribute N is a type
356 procedure Check_Unit_Name (Nod : Node_Id);
357 -- Check that Nod is of the form of a library unit name, i.e that
358 -- it is an identifier, or a selected component whose prefix is
359 -- itself of the form of a library unit name. Note that this is
360 -- quite different from Check_Program_Unit, since it only checks
361 -- the syntactic form of the name, not the semantic identity. This
362 -- is because it is used with attributes (Elab_Body, Elab_Spec,
363 -- UET_Address and Elaborated) which can refer to non-visible unit.
365 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
366 pragma No_Return (Error_Attr);
367 procedure Error_Attr;
368 pragma No_Return (Error_Attr);
369 -- Posts error using Error_Msg_N at given node, sets type of attribute
370 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
371 -- semantic processing. The message typically contains a % insertion
372 -- character which is replaced by the attribute name. The call with
373 -- no arguments is used when the caller has already generated the
374 -- required error messages.
376 procedure Error_Attr_P (Msg : String);
377 pragma No_Return (Error_Attr);
378 -- Like Error_Attr, but error is posted at the start of the prefix
380 procedure Standard_Attribute (Val : Int);
381 -- Used to process attributes whose prefix is package Standard which
382 -- yield values of type Universal_Integer. The attribute reference
383 -- node is rewritten with an integer literal of the given value.
385 procedure Unexpected_Argument (En : Node_Id);
386 -- Signal unexpected attribute argument (En is the argument)
388 procedure Validate_Non_Static_Attribute_Function_Call;
389 -- Called when processing an attribute that is a function call to a
390 -- non-static function, i.e. an attribute function that either takes
391 -- non-scalar arguments or returns a non-scalar result. Verifies that
392 -- such a call does not appear in a preelaborable context.
394 ------------------------------
395 -- Analyze_Access_Attribute --
396 ------------------------------
398 procedure Analyze_Access_Attribute is
399 Acc_Type : Entity_Id;
401 Scop : Entity_Id;
402 Typ : Entity_Id;
404 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
405 -- Build an access-to-object type whose designated type is DT,
406 -- and whose Ekind is appropriate to the attribute type. The
407 -- type that is constructed is returned as the result.
409 procedure Build_Access_Subprogram_Type (P : Node_Id);
410 -- Build an access to subprogram whose designated type is the type of
411 -- the prefix. If prefix is overloaded, so is the node itself. The
412 -- result is stored in Acc_Type.
414 function OK_Self_Reference return Boolean;
415 -- An access reference whose prefix is a type can legally appear
416 -- within an aggregate, where it is obtained by expansion of
417 -- a defaulted aggregate. The enclosing aggregate that contains
418 -- the self-referenced is flagged so that the self-reference can
419 -- be expanded into a reference to the target object (see exp_aggr).
421 ------------------------------
422 -- Build_Access_Object_Type --
423 ------------------------------
425 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
426 Typ : constant Entity_Id :=
427 New_Internal_Entity
428 (E_Access_Attribute_Type, Current_Scope, Loc, 'A');
429 begin
430 Set_Etype (Typ, Typ);
431 Set_Is_Itype (Typ);
432 Set_Associated_Node_For_Itype (Typ, N);
433 Set_Directly_Designated_Type (Typ, DT);
434 return Typ;
435 end Build_Access_Object_Type;
437 ----------------------------------
438 -- Build_Access_Subprogram_Type --
439 ----------------------------------
441 procedure Build_Access_Subprogram_Type (P : Node_Id) is
442 Index : Interp_Index;
443 It : Interp;
445 procedure Check_Local_Access (E : Entity_Id);
446 -- Deal with possible access to local subprogram. If we have such
447 -- an access, we set a flag to kill all tracked values on any call
448 -- because this access value may be passed around, and any called
449 -- code might use it to access a local procedure which clobbers a
450 -- tracked value. If the scope is a loop or block, indicate that
451 -- value tracking is disabled for the enclosing subprogram.
453 function Get_Kind (E : Entity_Id) return Entity_Kind;
454 -- Distinguish between access to regular/protected subprograms
456 ------------------------
457 -- Check_Local_Access --
458 ------------------------
460 procedure Check_Local_Access (E : Entity_Id) is
461 begin
462 if not Is_Library_Level_Entity (E) then
463 Set_Suppress_Value_Tracking_On_Call (Current_Scope);
464 Set_Suppress_Value_Tracking_On_Call
465 (Nearest_Dynamic_Scope (Current_Scope));
466 end if;
467 end Check_Local_Access;
469 --------------
470 -- Get_Kind --
471 --------------
473 function Get_Kind (E : Entity_Id) return Entity_Kind is
474 begin
475 if Convention (E) = Convention_Protected then
476 return E_Access_Protected_Subprogram_Type;
477 else
478 return E_Access_Subprogram_Type;
479 end if;
480 end Get_Kind;
482 -- Start of processing for Build_Access_Subprogram_Type
484 begin
485 -- In the case of an access to subprogram, use the name of the
486 -- subprogram itself as the designated type. Type-checking in
487 -- this case compares the signatures of the designated types.
489 -- Note: This fragment of the tree is temporarily malformed
490 -- because the correct tree requires an E_Subprogram_Type entity
491 -- as the designated type. In most cases this designated type is
492 -- later overridden by the semantics with the type imposed by the
493 -- context during the resolution phase. In the specific case of
494 -- the expression Address!(Prim'Unrestricted_Access), used to
495 -- initialize slots of dispatch tables, this work will be done by
496 -- the expander (see Exp_Aggr).
498 -- The reason to temporarily add this kind of node to the tree
499 -- instead of a proper E_Subprogram_Type itype, is the following:
500 -- in case of errors found in the source file we report better
501 -- error messages. For example, instead of generating the
502 -- following error:
504 -- "expected access to subprogram with profile
505 -- defined at line X"
507 -- we currently generate:
509 -- "expected access to function Z defined at line X"
511 Set_Etype (N, Any_Type);
513 if not Is_Overloaded (P) then
514 Check_Local_Access (Entity (P));
516 if not Is_Intrinsic_Subprogram (Entity (P)) then
517 Acc_Type := Create_Itype (Get_Kind (Entity (P)), N);
518 Set_Is_Public (Acc_Type, False);
519 Set_Etype (Acc_Type, Acc_Type);
520 Set_Convention (Acc_Type, Convention (Entity (P)));
521 Set_Directly_Designated_Type (Acc_Type, Entity (P));
522 Set_Etype (N, Acc_Type);
523 Freeze_Before (N, Acc_Type);
524 end if;
526 else
527 Get_First_Interp (P, Index, It);
528 while Present (It.Nam) loop
529 Check_Local_Access (It.Nam);
531 if not Is_Intrinsic_Subprogram (It.Nam) then
532 Acc_Type := Create_Itype (Get_Kind (It.Nam), N);
533 Set_Is_Public (Acc_Type, False);
534 Set_Etype (Acc_Type, Acc_Type);
535 Set_Convention (Acc_Type, Convention (It.Nam));
536 Set_Directly_Designated_Type (Acc_Type, It.Nam);
537 Add_One_Interp (N, Acc_Type, Acc_Type);
538 Freeze_Before (N, Acc_Type);
539 end if;
541 Get_Next_Interp (Index, It);
542 end loop;
543 end if;
545 -- Cannot be applied to intrinsic. Looking at the tests above,
546 -- the only way Etype (N) can still be set to Any_Type is if
547 -- Is_Intrinsic_Subprogram was True for some referenced entity.
549 if Etype (N) = Any_Type then
550 Error_Attr_P ("prefix of % attribute cannot be intrinsic");
551 end if;
552 end Build_Access_Subprogram_Type;
554 ----------------------
555 -- OK_Self_Reference --
556 ----------------------
558 function OK_Self_Reference return Boolean is
559 Par : Node_Id;
561 begin
562 Par := Parent (N);
563 while Present (Par)
564 and then
565 (Nkind (Par) = N_Component_Association
566 or else Nkind (Par) in N_Subexpr)
567 loop
568 if Nkind_In (Par, N_Aggregate, N_Extension_Aggregate) then
569 if Etype (Par) = Typ then
570 Set_Has_Self_Reference (Par);
571 return True;
572 end if;
573 end if;
575 Par := Parent (Par);
576 end loop;
578 -- No enclosing aggregate, or not a self-reference
580 return False;
581 end OK_Self_Reference;
583 -- Start of processing for Analyze_Access_Attribute
585 begin
586 Check_SPARK_Restriction_On_Attribute;
587 Check_E0;
589 if Nkind (P) = N_Character_Literal then
590 Error_Attr_P
591 ("prefix of % attribute cannot be enumeration literal");
592 end if;
594 -- Case of access to subprogram
596 if Is_Entity_Name (P)
597 and then Is_Overloadable (Entity (P))
598 then
599 if Has_Pragma_Inline_Always (Entity (P)) then
600 Error_Attr_P
601 ("prefix of % attribute cannot be Inline_Always subprogram");
603 elsif Aname = Name_Unchecked_Access then
604 Error_Attr ("attribute% cannot be applied to a subprogram", P);
606 elsif Is_Ghost_Subprogram (Entity (P)) then
607 Error_Attr_P
608 ("prefix of % attribute cannot be a ghost subprogram");
609 end if;
611 -- Issue an error if the prefix denotes an eliminated subprogram
613 Check_For_Eliminated_Subprogram (P, Entity (P));
615 -- Check for obsolescent subprogram reference
617 Check_Obsolescent_2005_Entity (Entity (P), P);
619 -- Build the appropriate subprogram type
621 Build_Access_Subprogram_Type (P);
623 -- For P'Access or P'Unrestricted_Access, where P is a nested
624 -- subprogram, we might be passing P to another subprogram (but we
625 -- don't check that here), which might call P. P could modify
626 -- local variables, so we need to kill current values. It is
627 -- important not to do this for library-level subprograms, because
628 -- Kill_Current_Values is very inefficient in the case of library
629 -- level packages with lots of tagged types.
631 if Is_Library_Level_Entity (Entity (Prefix (N))) then
632 null;
634 -- Do not kill values on nodes initializing dispatch tables
635 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
636 -- is currently generated by the expander only for this
637 -- purpose. Done to keep the quality of warnings currently
638 -- generated by the compiler (otherwise any declaration of
639 -- a tagged type cleans constant indications from its scope).
641 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
642 and then (Etype (Parent (N)) = RTE (RE_Prim_Ptr)
643 or else
644 Etype (Parent (N)) = RTE (RE_Size_Ptr))
645 and then Is_Dispatching_Operation
646 (Directly_Designated_Type (Etype (N)))
647 then
648 null;
650 else
651 Kill_Current_Values;
652 end if;
654 -- In the static elaboration model, treat the attribute reference
655 -- as a call for elaboration purposes. Suppress this treatment
656 -- under debug flag. In any case, we are all done.
658 if not Dynamic_Elaboration_Checks and not Debug_Flag_Dot_UU then
659 Check_Elab_Call (N);
660 end if;
662 return;
664 -- Component is an operation of a protected type
666 elsif Nkind (P) = N_Selected_Component
667 and then Is_Overloadable (Entity (Selector_Name (P)))
668 then
669 if Ekind (Entity (Selector_Name (P))) = E_Entry then
670 Error_Attr_P ("prefix of % attribute must be subprogram");
671 end if;
673 Build_Access_Subprogram_Type (Selector_Name (P));
674 return;
675 end if;
677 -- Deal with incorrect reference to a type, but note that some
678 -- accesses are allowed: references to the current type instance,
679 -- or in Ada 2005 self-referential pointer in a default-initialized
680 -- aggregate.
682 if Is_Entity_Name (P) then
683 Typ := Entity (P);
685 -- The reference may appear in an aggregate that has been expanded
686 -- into a loop. Locate scope of type definition, if any.
688 Scop := Current_Scope;
689 while Ekind (Scop) = E_Loop loop
690 Scop := Scope (Scop);
691 end loop;
693 if Is_Type (Typ) then
695 -- OK if we are within the scope of a limited type
696 -- let's mark the component as having per object constraint
698 if Is_Anonymous_Tagged_Base (Scop, Typ) then
699 Typ := Scop;
700 Set_Entity (P, Typ);
701 Set_Etype (P, Typ);
702 end if;
704 if Typ = Scop then
705 declare
706 Q : Node_Id := Parent (N);
708 begin
709 while Present (Q)
710 and then Nkind (Q) /= N_Component_Declaration
711 loop
712 Q := Parent (Q);
713 end loop;
715 if Present (Q) then
716 Set_Has_Per_Object_Constraint
717 (Defining_Identifier (Q), True);
718 end if;
719 end;
721 if Nkind (P) = N_Expanded_Name then
722 Error_Msg_F
723 ("current instance prefix must be a direct name", P);
724 end if;
726 -- If a current instance attribute appears in a component
727 -- constraint it must appear alone; other contexts (spec-
728 -- expressions, within a task body) are not subject to this
729 -- restriction.
731 if not In_Spec_Expression
732 and then not Has_Completion (Scop)
733 and then not
734 Nkind_In (Parent (N), N_Discriminant_Association,
735 N_Index_Or_Discriminant_Constraint)
736 then
737 Error_Msg_N
738 ("current instance attribute must appear alone", N);
739 end if;
741 if Is_CPP_Class (Root_Type (Typ)) then
742 Error_Msg_N
743 ("??current instance unsupported for derivations of "
744 & "'C'P'P types", N);
745 end if;
747 -- OK if we are in initialization procedure for the type
748 -- in question, in which case the reference to the type
749 -- is rewritten as a reference to the current object.
751 elsif Ekind (Scop) = E_Procedure
752 and then Is_Init_Proc (Scop)
753 and then Etype (First_Formal (Scop)) = Typ
754 then
755 Rewrite (N,
756 Make_Attribute_Reference (Loc,
757 Prefix => Make_Identifier (Loc, Name_uInit),
758 Attribute_Name => Name_Unrestricted_Access));
759 Analyze (N);
760 return;
762 -- OK if a task type, this test needs sharpening up ???
764 elsif Is_Task_Type (Typ) then
765 null;
767 -- OK if self-reference in an aggregate in Ada 2005, and
768 -- the reference comes from a copied default expression.
770 -- Note that we check legality of self-reference even if the
771 -- expression comes from source, e.g. when a single component
772 -- association in an aggregate has a box association.
774 elsif Ada_Version >= Ada_2005
775 and then OK_Self_Reference
776 then
777 null;
779 -- OK if reference to current instance of a protected object
781 elsif Is_Protected_Self_Reference (P) then
782 null;
784 -- Otherwise we have an error case
786 else
787 Error_Attr ("% attribute cannot be applied to type", P);
788 return;
789 end if;
790 end if;
791 end if;
793 -- If we fall through, we have a normal access to object case.
794 -- Unrestricted_Access is legal wherever an allocator would be
795 -- legal, so its Etype is set to E_Allocator. The expected type
796 -- of the other attributes is a general access type, and therefore
797 -- we label them with E_Access_Attribute_Type.
799 if not Is_Overloaded (P) then
800 Acc_Type := Build_Access_Object_Type (P_Type);
801 Set_Etype (N, Acc_Type);
802 else
803 declare
804 Index : Interp_Index;
805 It : Interp;
806 begin
807 Set_Etype (N, Any_Type);
808 Get_First_Interp (P, Index, It);
809 while Present (It.Typ) loop
810 Acc_Type := Build_Access_Object_Type (It.Typ);
811 Add_One_Interp (N, Acc_Type, Acc_Type);
812 Get_Next_Interp (Index, It);
813 end loop;
814 end;
815 end if;
817 -- Special cases when we can find a prefix that is an entity name
819 declare
820 PP : Node_Id;
821 Ent : Entity_Id;
823 begin
824 PP := P;
825 loop
826 if Is_Entity_Name (PP) then
827 Ent := Entity (PP);
829 -- If we have an access to an object, and the attribute
830 -- comes from source, then set the object as potentially
831 -- source modified. We do this because the resulting access
832 -- pointer can be used to modify the variable, and we might
833 -- not detect this, leading to some junk warnings.
835 Set_Never_Set_In_Source (Ent, False);
837 -- Mark entity as address taken, and kill current values
839 Set_Address_Taken (Ent);
840 Kill_Current_Values (Ent);
841 exit;
843 elsif Nkind_In (PP, N_Selected_Component,
844 N_Indexed_Component)
845 then
846 PP := Prefix (PP);
848 else
849 exit;
850 end if;
851 end loop;
852 end;
854 -- Check for aliased view unless unrestricted case. We allow a
855 -- nonaliased prefix when within an instance because the prefix may
856 -- have been a tagged formal object, which is defined to be aliased
857 -- even when the actual might not be (other instance cases will have
858 -- been caught in the generic). Similarly, within an inlined body we
859 -- know that the attribute is legal in the original subprogram, and
860 -- therefore legal in the expansion.
862 if Aname /= Name_Unrestricted_Access
863 and then not Is_Aliased_View (P)
864 and then not In_Instance
865 and then not In_Inlined_Body
866 then
867 Error_Attr_P ("prefix of % attribute must be aliased");
868 Check_No_Implicit_Aliasing (P);
869 end if;
870 end Analyze_Access_Attribute;
872 ---------------------------------
873 -- Bad_Attribute_For_Predicate --
874 ---------------------------------
876 procedure Bad_Attribute_For_Predicate is
877 begin
878 if Is_Scalar_Type (P_Type)
879 and then Comes_From_Source (N)
880 then
881 Error_Msg_Name_1 := Aname;
882 Bad_Predicated_Subtype_Use
883 ("type& has predicates, attribute % not allowed", N, P_Type);
884 end if;
885 end Bad_Attribute_For_Predicate;
887 ------------------------------
888 -- Check_Ada_2012_Attribute --
889 ------------------------------
891 procedure Check_Ada_2012_Attribute is
892 begin
893 if Ada_Version < Ada_2012 then
894 Error_Msg_Name_1 := Aname;
895 Error_Msg_N
896 ("attribute % is an Ada 2012 feature", N);
897 Error_Msg_N
898 ("\unit must be compiled with -gnat2012 switch", N);
899 end if;
900 end Check_Ada_2012_Attribute;
902 --------------------------------
903 -- Check_Array_Or_Scalar_Type --
904 --------------------------------
906 procedure Check_Array_Or_Scalar_Type is
907 Index : Entity_Id;
909 D : Int;
910 -- Dimension number for array attributes
912 begin
913 -- Case of string literal or string literal subtype. These cases
914 -- cannot arise from legal Ada code, but the expander is allowed
915 -- to generate them. They require special handling because string
916 -- literal subtypes do not have standard bounds (the whole idea
917 -- of these subtypes is to avoid having to generate the bounds)
919 if Ekind (P_Type) = E_String_Literal_Subtype then
920 Set_Etype (N, Etype (First_Index (P_Base_Type)));
921 return;
923 -- Scalar types
925 elsif Is_Scalar_Type (P_Type) then
926 Check_Type;
928 if Present (E1) then
929 Error_Attr ("invalid argument in % attribute", E1);
930 else
931 Set_Etype (N, P_Base_Type);
932 return;
933 end if;
935 -- The following is a special test to allow 'First to apply to
936 -- private scalar types if the attribute comes from generated
937 -- code. This occurs in the case of Normalize_Scalars code.
939 elsif Is_Private_Type (P_Type)
940 and then Present (Full_View (P_Type))
941 and then Is_Scalar_Type (Full_View (P_Type))
942 and then not Comes_From_Source (N)
943 then
944 Set_Etype (N, Implementation_Base_Type (P_Type));
946 -- Array types other than string literal subtypes handled above
948 else
949 Check_Array_Type;
951 -- We know prefix is an array type, or the name of an array
952 -- object, and that the expression, if present, is static
953 -- and within the range of the dimensions of the type.
955 pragma Assert (Is_Array_Type (P_Type));
956 Index := First_Index (P_Base_Type);
958 if No (E1) then
960 -- First dimension assumed
962 Set_Etype (N, Base_Type (Etype (Index)));
964 else
965 D := UI_To_Int (Intval (E1));
967 for J in 1 .. D - 1 loop
968 Next_Index (Index);
969 end loop;
971 Set_Etype (N, Base_Type (Etype (Index)));
972 Set_Etype (E1, Standard_Integer);
973 end if;
974 end if;
975 end Check_Array_Or_Scalar_Type;
977 ----------------------
978 -- Check_Array_Type --
979 ----------------------
981 procedure Check_Array_Type is
982 D : Int;
983 -- Dimension number for array attributes
985 begin
986 -- If the type is a string literal type, then this must be generated
987 -- internally, and no further check is required on its legality.
989 if Ekind (P_Type) = E_String_Literal_Subtype then
990 return;
992 -- If the type is a composite, it is an illegal aggregate, no point
993 -- in going on.
995 elsif P_Type = Any_Composite then
996 raise Bad_Attribute;
997 end if;
999 -- Normal case of array type or subtype
1001 Check_Either_E0_Or_E1;
1002 Check_Dereference;
1004 if Is_Array_Type (P_Type) then
1005 if not Is_Constrained (P_Type)
1006 and then Is_Entity_Name (P)
1007 and then Is_Type (Entity (P))
1008 then
1009 -- Note: we do not call Error_Attr here, since we prefer to
1010 -- continue, using the relevant index type of the array,
1011 -- even though it is unconstrained. This gives better error
1012 -- recovery behavior.
1014 Error_Msg_Name_1 := Aname;
1015 Error_Msg_F
1016 ("prefix for % attribute must be constrained array", P);
1017 end if;
1019 -- The attribute reference freezes the type, and thus the
1020 -- component type, even if the attribute may not depend on the
1021 -- component. Diagnose arrays with incomplete components now.
1022 -- If the prefix is an access to array, this does not freeze
1023 -- the designated type.
1025 if Nkind (P) /= N_Explicit_Dereference then
1026 Check_Fully_Declared (Component_Type (P_Type), P);
1027 end if;
1029 D := Number_Dimensions (P_Type);
1031 else
1032 if Is_Private_Type (P_Type) then
1033 Error_Attr_P ("prefix for % attribute may not be private type");
1035 elsif Is_Access_Type (P_Type)
1036 and then Is_Array_Type (Designated_Type (P_Type))
1037 and then Is_Entity_Name (P)
1038 and then Is_Type (Entity (P))
1039 then
1040 Error_Attr_P ("prefix of % attribute cannot be access type");
1042 elsif Attr_Id = Attribute_First
1043 or else
1044 Attr_Id = Attribute_Last
1045 then
1046 Error_Attr ("invalid prefix for % attribute", P);
1048 else
1049 Error_Attr_P ("prefix for % attribute must be array");
1050 end if;
1051 end if;
1053 if Present (E1) then
1054 Resolve (E1, Any_Integer);
1055 Set_Etype (E1, Standard_Integer);
1057 if not Is_Static_Expression (E1)
1058 or else Raises_Constraint_Error (E1)
1059 then
1060 Flag_Non_Static_Expr
1061 ("expression for dimension must be static!", E1);
1062 Error_Attr;
1064 elsif UI_To_Int (Expr_Value (E1)) > D
1065 or else UI_To_Int (Expr_Value (E1)) < 1
1066 then
1067 Error_Attr ("invalid dimension number for array type", E1);
1068 end if;
1069 end if;
1071 if (Style_Check and Style_Check_Array_Attribute_Index)
1072 and then Comes_From_Source (N)
1073 then
1074 Style.Check_Array_Attribute_Index (N, E1, D);
1075 end if;
1076 end Check_Array_Type;
1078 -------------------------
1079 -- Check_Asm_Attribute --
1080 -------------------------
1082 procedure Check_Asm_Attribute is
1083 begin
1084 Check_Type;
1085 Check_E2;
1087 -- Check first argument is static string expression
1089 Analyze_And_Resolve (E1, Standard_String);
1091 if Etype (E1) = Any_Type then
1092 return;
1094 elsif not Is_OK_Static_Expression (E1) then
1095 Flag_Non_Static_Expr
1096 ("constraint argument must be static string expression!", E1);
1097 Error_Attr;
1098 end if;
1100 -- Check second argument is right type
1102 Analyze_And_Resolve (E2, Entity (P));
1104 -- Note: that is all we need to do, we don't need to check
1105 -- that it appears in a correct context. The Ada type system
1106 -- will do that for us.
1108 end Check_Asm_Attribute;
1110 ---------------------
1111 -- Check_Component --
1112 ---------------------
1114 procedure Check_Component is
1115 begin
1116 Check_E0;
1118 if Nkind (P) /= N_Selected_Component
1119 or else
1120 (Ekind (Entity (Selector_Name (P))) /= E_Component
1121 and then
1122 Ekind (Entity (Selector_Name (P))) /= E_Discriminant)
1123 then
1124 Error_Attr_P ("prefix for % attribute must be selected component");
1125 end if;
1126 end Check_Component;
1128 ------------------------------------
1129 -- Check_Decimal_Fixed_Point_Type --
1130 ------------------------------------
1132 procedure Check_Decimal_Fixed_Point_Type is
1133 begin
1134 Check_Type;
1136 if not Is_Decimal_Fixed_Point_Type (P_Type) then
1137 Error_Attr_P ("prefix of % attribute must be decimal type");
1138 end if;
1139 end Check_Decimal_Fixed_Point_Type;
1141 -----------------------
1142 -- Check_Dereference --
1143 -----------------------
1145 procedure Check_Dereference is
1146 begin
1148 -- Case of a subtype mark
1150 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
1151 return;
1152 end if;
1154 -- Case of an expression
1156 Resolve (P);
1158 if Is_Access_Type (P_Type) then
1160 -- If there is an implicit dereference, then we must freeze the
1161 -- designated type of the access type, since the type of the
1162 -- referenced array is this type (see AI95-00106).
1164 -- As done elsewhere, freezing must not happen when pre-analyzing
1165 -- a pre- or postcondition or a default value for an object or for
1166 -- a formal parameter.
1168 if not In_Spec_Expression then
1169 Freeze_Before (N, Designated_Type (P_Type));
1170 end if;
1172 Rewrite (P,
1173 Make_Explicit_Dereference (Sloc (P),
1174 Prefix => Relocate_Node (P)));
1176 Analyze_And_Resolve (P);
1177 P_Type := Etype (P);
1179 if P_Type = Any_Type then
1180 raise Bad_Attribute;
1181 end if;
1183 P_Base_Type := Base_Type (P_Type);
1184 end if;
1185 end Check_Dereference;
1187 -------------------------
1188 -- Check_Discrete_Type --
1189 -------------------------
1191 procedure Check_Discrete_Type is
1192 begin
1193 Check_Type;
1195 if not Is_Discrete_Type (P_Type) then
1196 Error_Attr_P ("prefix of % attribute must be discrete type");
1197 end if;
1198 end Check_Discrete_Type;
1200 --------------
1201 -- Check_E0 --
1202 --------------
1204 procedure Check_E0 is
1205 begin
1206 if Present (E1) then
1207 Unexpected_Argument (E1);
1208 end if;
1209 end Check_E0;
1211 --------------
1212 -- Check_E1 --
1213 --------------
1215 procedure Check_E1 is
1216 begin
1217 Check_Either_E0_Or_E1;
1219 if No (E1) then
1221 -- Special-case attributes that are functions and that appear as
1222 -- the prefix of another attribute. Error is posted on parent.
1224 if Nkind (Parent (N)) = N_Attribute_Reference
1225 and then Nam_In (Attribute_Name (Parent (N)), Name_Address,
1226 Name_Code_Address,
1227 Name_Access)
1228 then
1229 Error_Msg_Name_1 := Attribute_Name (Parent (N));
1230 Error_Msg_N ("illegal prefix for % attribute", Parent (N));
1231 Set_Etype (Parent (N), Any_Type);
1232 Set_Entity (Parent (N), Any_Type);
1233 raise Bad_Attribute;
1235 else
1236 Error_Attr ("missing argument for % attribute", N);
1237 end if;
1238 end if;
1239 end Check_E1;
1241 --------------
1242 -- Check_E2 --
1243 --------------
1245 procedure Check_E2 is
1246 begin
1247 if No (E1) then
1248 Error_Attr ("missing arguments for % attribute (2 required)", N);
1249 elsif No (E2) then
1250 Error_Attr ("missing argument for % attribute (2 required)", N);
1251 end if;
1252 end Check_E2;
1254 ---------------------------
1255 -- Check_Either_E0_Or_E1 --
1256 ---------------------------
1258 procedure Check_Either_E0_Or_E1 is
1259 begin
1260 if Present (E2) then
1261 Unexpected_Argument (E2);
1262 end if;
1263 end Check_Either_E0_Or_E1;
1265 ----------------------
1266 -- Check_Enum_Image --
1267 ----------------------
1269 procedure Check_Enum_Image is
1270 Lit : Entity_Id;
1272 begin
1273 -- When an enumeration type appears in an attribute reference, all
1274 -- literals of the type are marked as referenced. This must only be
1275 -- done if the attribute reference appears in the current source.
1276 -- Otherwise the information on references may differ between a
1277 -- normal compilation and one that performs inlining.
1279 if Is_Enumeration_Type (P_Base_Type)
1280 and then In_Extended_Main_Code_Unit (N)
1281 then
1282 Lit := First_Literal (P_Base_Type);
1283 while Present (Lit) loop
1284 Set_Referenced (Lit);
1285 Next_Literal (Lit);
1286 end loop;
1287 end if;
1288 end Check_Enum_Image;
1290 ----------------------------
1291 -- Check_First_Last_Valid --
1292 ----------------------------
1294 procedure Check_First_Last_Valid is
1295 begin
1296 Check_Ada_2012_Attribute;
1297 Check_Discrete_Type;
1299 -- Freeze the subtype now, so that the following test for predicates
1300 -- works (we set the predicates stuff up at freeze time)
1302 Insert_Actions (N, Freeze_Entity (P_Type, P));
1304 -- Now test for dynamic predicate
1306 if Has_Predicates (P_Type)
1307 and then No (Static_Predicate (P_Type))
1308 then
1309 Error_Attr_P
1310 ("prefix of % attribute may not have dynamic predicate");
1311 end if;
1313 -- Check non-static subtype
1315 if not Is_Static_Subtype (P_Type) then
1316 Error_Attr_P ("prefix of % attribute must be a static subtype");
1317 end if;
1319 -- Test case for no values
1321 if Expr_Value (Type_Low_Bound (P_Type)) >
1322 Expr_Value (Type_High_Bound (P_Type))
1323 or else (Has_Predicates (P_Type)
1324 and then Is_Empty_List (Static_Predicate (P_Type)))
1325 then
1326 Error_Attr_P
1327 ("prefix of % attribute must be subtype with "
1328 & "at least one value");
1329 end if;
1330 end Check_First_Last_Valid;
1332 ----------------------------
1333 -- Check_Fixed_Point_Type --
1334 ----------------------------
1336 procedure Check_Fixed_Point_Type is
1337 begin
1338 Check_Type;
1340 if not Is_Fixed_Point_Type (P_Type) then
1341 Error_Attr_P ("prefix of % attribute must be fixed point type");
1342 end if;
1343 end Check_Fixed_Point_Type;
1345 ------------------------------
1346 -- Check_Fixed_Point_Type_0 --
1347 ------------------------------
1349 procedure Check_Fixed_Point_Type_0 is
1350 begin
1351 Check_Fixed_Point_Type;
1352 Check_E0;
1353 end Check_Fixed_Point_Type_0;
1355 -------------------------------
1356 -- Check_Floating_Point_Type --
1357 -------------------------------
1359 procedure Check_Floating_Point_Type is
1360 begin
1361 Check_Type;
1363 if not Is_Floating_Point_Type (P_Type) then
1364 Error_Attr_P ("prefix of % attribute must be float type");
1365 end if;
1366 end Check_Floating_Point_Type;
1368 ---------------------------------
1369 -- Check_Floating_Point_Type_0 --
1370 ---------------------------------
1372 procedure Check_Floating_Point_Type_0 is
1373 begin
1374 Check_Floating_Point_Type;
1375 Check_E0;
1376 end Check_Floating_Point_Type_0;
1378 ---------------------------------
1379 -- Check_Floating_Point_Type_1 --
1380 ---------------------------------
1382 procedure Check_Floating_Point_Type_1 is
1383 begin
1384 Check_Floating_Point_Type;
1385 Check_E1;
1386 end Check_Floating_Point_Type_1;
1388 ---------------------------------
1389 -- Check_Floating_Point_Type_2 --
1390 ---------------------------------
1392 procedure Check_Floating_Point_Type_2 is
1393 begin
1394 Check_Floating_Point_Type;
1395 Check_E2;
1396 end Check_Floating_Point_Type_2;
1398 ------------------------
1399 -- Check_Integer_Type --
1400 ------------------------
1402 procedure Check_Integer_Type is
1403 begin
1404 Check_Type;
1406 if not Is_Integer_Type (P_Type) then
1407 Error_Attr_P ("prefix of % attribute must be integer type");
1408 end if;
1409 end Check_Integer_Type;
1411 --------------------------------
1412 -- Check_Modular_Integer_Type --
1413 --------------------------------
1415 procedure Check_Modular_Integer_Type is
1416 begin
1417 Check_Type;
1419 if not Is_Modular_Integer_Type (P_Type) then
1420 Error_Attr_P
1421 ("prefix of % attribute must be modular integer type");
1422 end if;
1423 end Check_Modular_Integer_Type;
1425 ------------------------
1426 -- Check_Not_CPP_Type --
1427 ------------------------
1429 procedure Check_Not_CPP_Type is
1430 begin
1431 if Is_Tagged_Type (Etype (P))
1432 and then Convention (Etype (P)) = Convention_CPP
1433 and then Is_CPP_Class (Root_Type (Etype (P)))
1434 then
1435 Error_Attr_P
1436 ("invalid use of % attribute with 'C'P'P tagged type");
1437 end if;
1438 end Check_Not_CPP_Type;
1440 -------------------------------
1441 -- Check_Not_Incomplete_Type --
1442 -------------------------------
1444 procedure Check_Not_Incomplete_Type is
1445 E : Entity_Id;
1446 Typ : Entity_Id;
1448 begin
1449 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1450 -- dereference we have to check wrong uses of incomplete types
1451 -- (other wrong uses are checked at their freezing point).
1453 -- Example 1: Limited-with
1455 -- limited with Pkg;
1456 -- package P is
1457 -- type Acc is access Pkg.T;
1458 -- X : Acc;
1459 -- S : Integer := X.all'Size; -- ERROR
1460 -- end P;
1462 -- Example 2: Tagged incomplete
1464 -- type T is tagged;
1465 -- type Acc is access all T;
1466 -- X : Acc;
1467 -- S : constant Integer := X.all'Size; -- ERROR
1468 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1470 if Ada_Version >= Ada_2005
1471 and then Nkind (P) = N_Explicit_Dereference
1472 then
1473 E := P;
1474 while Nkind (E) = N_Explicit_Dereference loop
1475 E := Prefix (E);
1476 end loop;
1478 Typ := Etype (E);
1480 if From_With_Type (Typ) then
1481 Error_Attr_P
1482 ("prefix of % attribute cannot be an incomplete type");
1484 else
1485 if Is_Access_Type (Typ) then
1486 Typ := Directly_Designated_Type (Typ);
1487 end if;
1489 if Is_Class_Wide_Type (Typ) then
1490 Typ := Root_Type (Typ);
1491 end if;
1493 -- A legal use of a shadow entity occurs only when the unit
1494 -- where the non-limited view resides is imported via a regular
1495 -- with clause in the current body. Such references to shadow
1496 -- entities may occur in subprogram formals.
1498 if Is_Incomplete_Type (Typ)
1499 and then From_With_Type (Typ)
1500 and then Present (Non_Limited_View (Typ))
1501 and then Is_Legal_Shadow_Entity_In_Body (Typ)
1502 then
1503 Typ := Non_Limited_View (Typ);
1504 end if;
1506 if Ekind (Typ) = E_Incomplete_Type
1507 and then No (Full_View (Typ))
1508 then
1509 Error_Attr_P
1510 ("prefix of % attribute cannot be an incomplete type");
1511 end if;
1512 end if;
1513 end if;
1515 if not Is_Entity_Name (P)
1516 or else not Is_Type (Entity (P))
1517 or else In_Spec_Expression
1518 then
1519 return;
1520 else
1521 Check_Fully_Declared (P_Type, P);
1522 end if;
1523 end Check_Not_Incomplete_Type;
1525 ----------------------------
1526 -- Check_Object_Reference --
1527 ----------------------------
1529 procedure Check_Object_Reference (P : Node_Id) is
1530 Rtyp : Entity_Id;
1532 begin
1533 -- If we need an object, and we have a prefix that is the name of
1534 -- a function entity, convert it into a function call.
1536 if Is_Entity_Name (P)
1537 and then Ekind (Entity (P)) = E_Function
1538 then
1539 Rtyp := Etype (Entity (P));
1541 Rewrite (P,
1542 Make_Function_Call (Sloc (P),
1543 Name => Relocate_Node (P)));
1545 Analyze_And_Resolve (P, Rtyp);
1547 -- Otherwise we must have an object reference
1549 elsif not Is_Object_Reference (P) then
1550 Error_Attr_P ("prefix of % attribute must be object");
1551 end if;
1552 end Check_Object_Reference;
1554 ----------------------------
1555 -- Check_PolyORB_Attribute --
1556 ----------------------------
1558 procedure Check_PolyORB_Attribute is
1559 begin
1560 Validate_Non_Static_Attribute_Function_Call;
1562 Check_Type;
1563 Check_Not_CPP_Type;
1565 if Get_PCS_Name /= Name_PolyORB_DSA then
1566 Error_Attr
1567 ("attribute% requires the 'Poly'O'R'B 'P'C'S", N);
1568 end if;
1569 end Check_PolyORB_Attribute;
1571 ------------------------
1572 -- Check_Program_Unit --
1573 ------------------------
1575 procedure Check_Program_Unit is
1576 begin
1577 if Is_Entity_Name (P) then
1578 declare
1579 K : constant Entity_Kind := Ekind (Entity (P));
1580 T : constant Entity_Id := Etype (Entity (P));
1582 begin
1583 if K in Subprogram_Kind
1584 or else K in Task_Kind
1585 or else K in Protected_Kind
1586 or else K = E_Package
1587 or else K in Generic_Unit_Kind
1588 or else (K = E_Variable
1589 and then
1590 (Is_Task_Type (T)
1591 or else
1592 Is_Protected_Type (T)))
1593 then
1594 return;
1595 end if;
1596 end;
1597 end if;
1599 Error_Attr_P ("prefix of % attribute must be program unit");
1600 end Check_Program_Unit;
1602 ---------------------
1603 -- Check_Real_Type --
1604 ---------------------
1606 procedure Check_Real_Type is
1607 begin
1608 Check_Type;
1610 if not Is_Real_Type (P_Type) then
1611 Error_Attr_P ("prefix of % attribute must be real type");
1612 end if;
1613 end Check_Real_Type;
1615 -----------------------
1616 -- Check_Scalar_Type --
1617 -----------------------
1619 procedure Check_Scalar_Type is
1620 begin
1621 Check_Type;
1623 if not Is_Scalar_Type (P_Type) then
1624 Error_Attr_P ("prefix of % attribute must be scalar type");
1625 end if;
1626 end Check_Scalar_Type;
1628 ------------------------------------------
1629 -- Check_SPARK_Restriction_On_Attribute --
1630 ------------------------------------------
1632 procedure Check_SPARK_Restriction_On_Attribute is
1633 begin
1634 Error_Msg_Name_1 := Aname;
1635 Check_SPARK_Restriction ("attribute % is not allowed", P);
1636 end Check_SPARK_Restriction_On_Attribute;
1638 ---------------------------
1639 -- Check_Standard_Prefix --
1640 ---------------------------
1642 procedure Check_Standard_Prefix is
1643 begin
1644 Check_E0;
1646 if Nkind (P) /= N_Identifier or else Chars (P) /= Name_Standard then
1647 Error_Attr ("only allowed prefix for % attribute is Standard", P);
1648 end if;
1649 end Check_Standard_Prefix;
1651 ----------------------------
1652 -- Check_Stream_Attribute --
1653 ----------------------------
1655 procedure Check_Stream_Attribute (Nam : TSS_Name_Type) is
1656 Etyp : Entity_Id;
1657 Btyp : Entity_Id;
1659 In_Shared_Var_Procs : Boolean;
1660 -- True when compiling System.Shared_Storage.Shared_Var_Procs body.
1661 -- For this runtime package (always compiled in GNAT mode), we allow
1662 -- stream attributes references for limited types for the case where
1663 -- shared passive objects are implemented using stream attributes,
1664 -- which is the default in GNAT's persistent storage implementation.
1666 begin
1667 Validate_Non_Static_Attribute_Function_Call;
1669 -- With the exception of 'Input, Stream attributes are procedures,
1670 -- and can only appear at the position of procedure calls. We check
1671 -- for this here, before they are rewritten, to give a more precise
1672 -- diagnostic.
1674 if Nam = TSS_Stream_Input then
1675 null;
1677 elsif Is_List_Member (N)
1678 and then not Nkind_In (Parent (N), N_Procedure_Call_Statement,
1679 N_Aggregate)
1680 then
1681 null;
1683 else
1684 Error_Attr
1685 ("invalid context for attribute%, which is a procedure", N);
1686 end if;
1688 Check_Type;
1689 Btyp := Implementation_Base_Type (P_Type);
1691 -- Stream attributes not allowed on limited types unless the
1692 -- attribute reference was generated by the expander (in which
1693 -- case the underlying type will be used, as described in Sinfo),
1694 -- or the attribute was specified explicitly for the type itself
1695 -- or one of its ancestors (taking visibility rules into account if
1696 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1697 -- (with no visibility restriction).
1699 declare
1700 Gen_Body : constant Node_Id := Enclosing_Generic_Body (N);
1701 begin
1702 if Present (Gen_Body) then
1703 In_Shared_Var_Procs :=
1704 Is_RTE (Corresponding_Spec (Gen_Body), RE_Shared_Var_Procs);
1705 else
1706 In_Shared_Var_Procs := False;
1707 end if;
1708 end;
1710 if (Comes_From_Source (N)
1711 and then not (In_Shared_Var_Procs or In_Instance))
1712 and then not Stream_Attribute_Available (P_Type, Nam)
1713 and then not Has_Rep_Pragma (Btyp, Name_Stream_Convert)
1714 then
1715 Error_Msg_Name_1 := Aname;
1717 if Is_Limited_Type (P_Type) then
1718 Error_Msg_NE
1719 ("limited type& has no% attribute", P, P_Type);
1720 Explain_Limited_Type (P_Type, P);
1721 else
1722 Error_Msg_NE
1723 ("attribute% for type& is not available", P, P_Type);
1724 end if;
1725 end if;
1727 -- Check restriction violations
1729 -- First check the No_Streams restriction, which prohibits the use
1730 -- of explicit stream attributes in the source program. We do not
1731 -- prevent the occurrence of stream attributes in generated code,
1732 -- for instance those generated implicitly for dispatching purposes.
1734 if Comes_From_Source (N) then
1735 Check_Restriction (No_Streams, P);
1736 end if;
1738 -- AI05-0057: if restriction No_Default_Stream_Attributes is active,
1739 -- it is illegal to use a predefined elementary type stream attribute
1740 -- either by itself, or more importantly as part of the attribute
1741 -- subprogram for a composite type. However, if the broader
1742 -- restriction No_Streams is active, stream operations are not
1743 -- generated, and there is no error.
1745 if Restriction_Active (No_Default_Stream_Attributes)
1746 and then not Restriction_Active (No_Streams)
1747 then
1748 declare
1749 T : Entity_Id;
1751 begin
1752 if Nam = TSS_Stream_Input
1753 or else
1754 Nam = TSS_Stream_Read
1755 then
1756 T :=
1757 Type_Without_Stream_Operation (P_Type, TSS_Stream_Read);
1758 else
1759 T :=
1760 Type_Without_Stream_Operation (P_Type, TSS_Stream_Write);
1761 end if;
1763 if Present (T) then
1764 Check_Restriction (No_Default_Stream_Attributes, N);
1766 Error_Msg_NE
1767 ("missing user-defined Stream Read or Write for type&",
1768 N, T);
1769 if not Is_Elementary_Type (P_Type) then
1770 Error_Msg_NE
1771 ("\which is a component of type&", N, P_Type);
1772 end if;
1773 end if;
1774 end;
1775 end if;
1777 -- Check special case of Exception_Id and Exception_Occurrence which
1778 -- are not allowed for restriction No_Exception_Registration.
1780 if Restriction_Check_Required (No_Exception_Registration)
1781 and then (Is_RTE (P_Type, RE_Exception_Id)
1782 or else
1783 Is_RTE (P_Type, RE_Exception_Occurrence))
1784 then
1785 Check_Restriction (No_Exception_Registration, P);
1786 end if;
1788 -- Here we must check that the first argument is an access type
1789 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1791 Analyze_And_Resolve (E1);
1792 Etyp := Etype (E1);
1794 -- Note: the double call to Root_Type here is needed because the
1795 -- root type of a class-wide type is the corresponding type (e.g.
1796 -- X for X'Class, and we really want to go to the root.)
1798 if not Is_Access_Type (Etyp)
1799 or else Root_Type (Root_Type (Designated_Type (Etyp))) /=
1800 RTE (RE_Root_Stream_Type)
1801 then
1802 Error_Attr
1803 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1);
1804 end if;
1806 -- Check that the second argument is of the right type if there is
1807 -- one (the Input attribute has only one argument so this is skipped)
1809 if Present (E2) then
1810 Analyze (E2);
1812 if Nam = TSS_Stream_Read
1813 and then not Is_OK_Variable_For_Out_Formal (E2)
1814 then
1815 Error_Attr
1816 ("second argument of % attribute must be a variable", E2);
1817 end if;
1819 Resolve (E2, P_Type);
1820 end if;
1822 Check_Not_CPP_Type;
1823 end Check_Stream_Attribute;
1825 -----------------------
1826 -- Check_Task_Prefix --
1827 -----------------------
1829 procedure Check_Task_Prefix is
1830 begin
1831 Analyze (P);
1833 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1834 -- task interface class-wide types.
1836 if Is_Task_Type (Etype (P))
1837 or else (Is_Access_Type (Etype (P))
1838 and then Is_Task_Type (Designated_Type (Etype (P))))
1839 or else (Ada_Version >= Ada_2005
1840 and then Ekind (Etype (P)) = E_Class_Wide_Type
1841 and then Is_Interface (Etype (P))
1842 and then Is_Task_Interface (Etype (P)))
1843 then
1844 Resolve (P);
1846 else
1847 if Ada_Version >= Ada_2005 then
1848 Error_Attr_P
1849 ("prefix of % attribute must be a task or a task " &
1850 "interface class-wide object");
1852 else
1853 Error_Attr_P ("prefix of % attribute must be a task");
1854 end if;
1855 end if;
1856 end Check_Task_Prefix;
1858 ----------------
1859 -- Check_Type --
1860 ----------------
1862 -- The possibilities are an entity name denoting a type, or an
1863 -- attribute reference that denotes a type (Base or Class). If
1864 -- the type is incomplete, replace it with its full view.
1866 procedure Check_Type is
1867 begin
1868 if not Is_Entity_Name (P)
1869 or else not Is_Type (Entity (P))
1870 then
1871 Error_Attr_P ("prefix of % attribute must be a type");
1873 elsif Is_Protected_Self_Reference (P) then
1874 Error_Attr_P
1875 ("prefix of % attribute denotes current instance "
1876 & "(RM 9.4(21/2))");
1878 elsif Ekind (Entity (P)) = E_Incomplete_Type
1879 and then Present (Full_View (Entity (P)))
1880 then
1881 P_Type := Full_View (Entity (P));
1882 Set_Entity (P, P_Type);
1883 end if;
1884 end Check_Type;
1886 ---------------------
1887 -- Check_Unit_Name --
1888 ---------------------
1890 procedure Check_Unit_Name (Nod : Node_Id) is
1891 begin
1892 if Nkind (Nod) = N_Identifier then
1893 return;
1895 elsif Nkind_In (Nod, N_Selected_Component, N_Expanded_Name) then
1896 Check_Unit_Name (Prefix (Nod));
1898 if Nkind (Selector_Name (Nod)) = N_Identifier then
1899 return;
1900 end if;
1901 end if;
1903 Error_Attr ("argument for % attribute must be unit name", P);
1904 end Check_Unit_Name;
1906 ----------------
1907 -- Error_Attr --
1908 ----------------
1910 procedure Error_Attr is
1911 begin
1912 Set_Etype (N, Any_Type);
1913 Set_Entity (N, Any_Type);
1914 raise Bad_Attribute;
1915 end Error_Attr;
1917 procedure Error_Attr (Msg : String; Error_Node : Node_Id) is
1918 begin
1919 Error_Msg_Name_1 := Aname;
1920 Error_Msg_N (Msg, Error_Node);
1921 Error_Attr;
1922 end Error_Attr;
1924 ------------------
1925 -- Error_Attr_P --
1926 ------------------
1928 procedure Error_Attr_P (Msg : String) is
1929 begin
1930 Error_Msg_Name_1 := Aname;
1931 Error_Msg_F (Msg, P);
1932 Error_Attr;
1933 end Error_Attr_P;
1935 ----------------------------
1936 -- Legal_Formal_Attribute --
1937 ----------------------------
1939 procedure Legal_Formal_Attribute is
1940 begin
1941 Check_E0;
1943 if not Is_Entity_Name (P)
1944 or else not Is_Type (Entity (P))
1945 then
1946 Error_Attr_P ("prefix of % attribute must be generic type");
1948 elsif Is_Generic_Actual_Type (Entity (P))
1949 or else In_Instance
1950 or else In_Inlined_Body
1951 then
1952 null;
1954 elsif Is_Generic_Type (Entity (P)) then
1955 if not Is_Indefinite_Subtype (Entity (P)) then
1956 Error_Attr_P
1957 ("prefix of % attribute must be indefinite generic type");
1958 end if;
1960 else
1961 Error_Attr_P
1962 ("prefix of % attribute must be indefinite generic type");
1963 end if;
1965 Set_Etype (N, Standard_Boolean);
1966 end Legal_Formal_Attribute;
1968 ------------------------
1969 -- Standard_Attribute --
1970 ------------------------
1972 procedure Standard_Attribute (Val : Int) is
1973 begin
1974 Check_Standard_Prefix;
1975 Rewrite (N, Make_Integer_Literal (Loc, Val));
1976 Analyze (N);
1977 end Standard_Attribute;
1979 -------------------------
1980 -- Unexpected Argument --
1981 -------------------------
1983 procedure Unexpected_Argument (En : Node_Id) is
1984 begin
1985 Error_Attr ("unexpected argument for % attribute", En);
1986 end Unexpected_Argument;
1988 -------------------------------------------------
1989 -- Validate_Non_Static_Attribute_Function_Call --
1990 -------------------------------------------------
1992 -- This function should be moved to Sem_Dist ???
1994 procedure Validate_Non_Static_Attribute_Function_Call is
1995 begin
1996 if In_Preelaborated_Unit
1997 and then not In_Subprogram_Or_Concurrent_Unit
1998 then
1999 Flag_Non_Static_Expr
2000 ("non-static function call in preelaborated unit!", N);
2001 end if;
2002 end Validate_Non_Static_Attribute_Function_Call;
2004 -- Start of processing for Analyze_Attribute
2006 begin
2007 -- Immediate return if unrecognized attribute (already diagnosed
2008 -- by parser, so there is nothing more that we need to do)
2010 if not Is_Attribute_Name (Aname) then
2011 raise Bad_Attribute;
2012 end if;
2014 -- Deal with Ada 83 issues
2016 if Comes_From_Source (N) then
2017 if not Attribute_83 (Attr_Id) then
2018 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2019 Error_Msg_Name_1 := Aname;
2020 Error_Msg_N ("(Ada 83) attribute% is not standard??", N);
2021 end if;
2023 if Attribute_Impl_Def (Attr_Id) then
2024 Check_Restriction (No_Implementation_Attributes, N);
2025 end if;
2026 end if;
2027 end if;
2029 -- Deal with Ada 2005 attributes that are
2031 if Attribute_05 (Attr_Id) and then Ada_Version < Ada_2005 then
2032 Check_Restriction (No_Implementation_Attributes, N);
2033 end if;
2035 -- Remote access to subprogram type access attribute reference needs
2036 -- unanalyzed copy for tree transformation. The analyzed copy is used
2037 -- for its semantic information (whether prefix is a remote subprogram
2038 -- name), the unanalyzed copy is used to construct new subtree rooted
2039 -- with N_Aggregate which represents a fat pointer aggregate.
2041 if Aname = Name_Access then
2042 Discard_Node (Copy_Separate_Tree (N));
2043 end if;
2045 -- Analyze prefix and exit if error in analysis. If the prefix is an
2046 -- incomplete type, use full view if available. Note that there are
2047 -- some attributes for which we do not analyze the prefix, since the
2048 -- prefix is not a normal name, or else needs special handling.
2050 if Aname /= Name_Elab_Body and then
2051 Aname /= Name_Elab_Spec and then
2052 Aname /= Name_Elab_Subp_Body and then
2053 Aname /= Name_UET_Address and then
2054 Aname /= Name_Enabled and then
2055 Aname /= Name_Old
2056 then
2057 Analyze (P);
2058 P_Type := Etype (P);
2060 if Is_Entity_Name (P)
2061 and then Present (Entity (P))
2062 and then Is_Type (Entity (P))
2063 then
2064 if Ekind (Entity (P)) = E_Incomplete_Type then
2065 P_Type := Get_Full_View (P_Type);
2066 Set_Entity (P, P_Type);
2067 Set_Etype (P, P_Type);
2069 elsif Entity (P) = Current_Scope
2070 and then Is_Record_Type (Entity (P))
2071 then
2072 -- Use of current instance within the type. Verify that if the
2073 -- attribute appears within a constraint, it yields an access
2074 -- type, other uses are illegal.
2076 declare
2077 Par : Node_Id;
2079 begin
2080 Par := Parent (N);
2081 while Present (Par)
2082 and then Nkind (Parent (Par)) /= N_Component_Definition
2083 loop
2084 Par := Parent (Par);
2085 end loop;
2087 if Present (Par)
2088 and then Nkind (Par) = N_Subtype_Indication
2089 then
2090 if Attr_Id /= Attribute_Access
2091 and then Attr_Id /= Attribute_Unchecked_Access
2092 and then Attr_Id /= Attribute_Unrestricted_Access
2093 then
2094 Error_Msg_N
2095 ("in a constraint the current instance can only"
2096 & " be used with an access attribute", N);
2097 end if;
2098 end if;
2099 end;
2100 end if;
2101 end if;
2103 if P_Type = Any_Type then
2104 raise Bad_Attribute;
2105 end if;
2107 P_Base_Type := Base_Type (P_Type);
2108 end if;
2110 -- Analyze expressions that may be present, exiting if an error occurs
2112 if No (Exprs) then
2113 E1 := Empty;
2114 E2 := Empty;
2116 else
2117 E1 := First (Exprs);
2119 -- Skip analysis for case of Restriction_Set, we do not expect
2120 -- the argument to be analyzed in this case.
2122 if Aname /= Name_Restriction_Set then
2123 Analyze (E1);
2125 -- Check for missing/bad expression (result of previous error)
2127 if No (E1) or else Etype (E1) = Any_Type then
2128 raise Bad_Attribute;
2129 end if;
2130 end if;
2132 E2 := Next (E1);
2134 if Present (E2) then
2135 Analyze (E2);
2137 if Etype (E2) = Any_Type then
2138 raise Bad_Attribute;
2139 end if;
2141 if Present (Next (E2)) then
2142 Unexpected_Argument (Next (E2));
2143 end if;
2144 end if;
2145 end if;
2147 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
2148 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
2150 if Ada_Version < Ada_2005
2151 and then Is_Overloaded (P)
2152 and then Aname /= Name_Access
2153 and then Aname /= Name_Address
2154 and then Aname /= Name_Code_Address
2155 and then Aname /= Name_Count
2156 and then Aname /= Name_Result
2157 and then Aname /= Name_Unchecked_Access
2158 then
2159 Error_Attr ("ambiguous prefix for % attribute", P);
2161 elsif Ada_Version >= Ada_2005
2162 and then Is_Overloaded (P)
2163 and then Aname /= Name_Access
2164 and then Aname /= Name_Address
2165 and then Aname /= Name_Code_Address
2166 and then Aname /= Name_Result
2167 and then Aname /= Name_Unchecked_Access
2168 then
2169 -- Ada 2005 (AI-345): Since protected and task types have primitive
2170 -- entry wrappers, the attributes Count, Caller and AST_Entry require
2171 -- a context check
2173 if Ada_Version >= Ada_2005
2174 and then Nam_In (Aname, Name_Count, Name_Caller, Name_AST_Entry)
2175 then
2176 declare
2177 Count : Natural := 0;
2178 I : Interp_Index;
2179 It : Interp;
2181 begin
2182 Get_First_Interp (P, I, It);
2183 while Present (It.Nam) loop
2184 if Comes_From_Source (It.Nam) then
2185 Count := Count + 1;
2186 else
2187 Remove_Interp (I);
2188 end if;
2190 Get_Next_Interp (I, It);
2191 end loop;
2193 if Count > 1 then
2194 Error_Attr ("ambiguous prefix for % attribute", P);
2195 else
2196 Set_Is_Overloaded (P, False);
2197 end if;
2198 end;
2200 else
2201 Error_Attr ("ambiguous prefix for % attribute", P);
2202 end if;
2203 end if;
2205 -- In SPARK, attributes of private types are only allowed if the full
2206 -- type declaration is visible.
2208 if Is_Entity_Name (P)
2209 and then Present (Entity (P)) -- needed in some cases
2210 and then Is_Type (Entity (P))
2211 and then Is_Private_Type (P_Type)
2212 and then not In_Open_Scopes (Scope (P_Type))
2213 and then not In_Spec_Expression
2214 then
2215 Check_SPARK_Restriction ("invisible attribute of type", N);
2216 end if;
2218 -- Remaining processing depends on attribute
2220 case Attr_Id is
2222 -- Attributes related to Ada 2012 iterators. Attribute specifications
2223 -- exist for these, but they cannot be queried.
2225 when Attribute_Constant_Indexing |
2226 Attribute_Default_Iterator |
2227 Attribute_Implicit_Dereference |
2228 Attribute_Iterator_Element |
2229 Attribute_Variable_Indexing =>
2230 Error_Msg_N ("illegal attribute", N);
2232 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
2233 -- were already rejected by the parser. Thus they shouldn't appear here.
2235 when Internal_Attribute_Id =>
2236 raise Program_Error;
2238 ------------------
2239 -- Abort_Signal --
2240 ------------------
2242 when Attribute_Abort_Signal =>
2243 Check_Standard_Prefix;
2244 Rewrite (N, New_Reference_To (Stand.Abort_Signal, Loc));
2245 Analyze (N);
2247 ------------
2248 -- Access --
2249 ------------
2251 when Attribute_Access =>
2252 Analyze_Access_Attribute;
2254 -------------
2255 -- Address --
2256 -------------
2258 when Attribute_Address =>
2259 Check_E0;
2261 -- Check for some junk cases, where we have to allow the address
2262 -- attribute but it does not make much sense, so at least for now
2263 -- just replace with Null_Address.
2265 -- We also do this if the prefix is a reference to the AST_Entry
2266 -- attribute. If expansion is active, the attribute will be
2267 -- replaced by a function call, and address will work fine and
2268 -- get the proper value, but if expansion is not active, then
2269 -- the check here allows proper semantic analysis of the reference.
2271 -- An Address attribute created by expansion is legal even when it
2272 -- applies to other entity-denoting expressions.
2274 if Is_Protected_Self_Reference (P) then
2276 -- Address attribute on a protected object self reference is legal
2278 null;
2280 elsif Is_Entity_Name (P) then
2281 declare
2282 Ent : constant Entity_Id := Entity (P);
2284 begin
2285 if Is_Subprogram (Ent) then
2286 Set_Address_Taken (Ent);
2287 Kill_Current_Values (Ent);
2289 -- An Address attribute is accepted when generated by the
2290 -- compiler for dispatching operation, and an error is
2291 -- issued once the subprogram is frozen (to avoid confusing
2292 -- errors about implicit uses of Address in the dispatch
2293 -- table initialization).
2295 if Has_Pragma_Inline_Always (Entity (P))
2296 and then Comes_From_Source (P)
2297 then
2298 Error_Attr_P
2299 ("prefix of % attribute cannot be Inline_Always" &
2300 " subprogram");
2302 -- It is illegal to apply 'Address to an intrinsic
2303 -- subprogram. This is now formalized in AI05-0095.
2304 -- In an instance, an attempt to obtain 'Address of an
2305 -- intrinsic subprogram (e.g the renaming of a predefined
2306 -- operator that is an actual) raises Program_Error.
2308 elsif Convention (Ent) = Convention_Intrinsic then
2309 if In_Instance then
2310 Rewrite (N,
2311 Make_Raise_Program_Error (Loc,
2312 Reason => PE_Address_Of_Intrinsic));
2314 else
2315 Error_Msg_N
2316 ("cannot take Address of intrinsic subprogram", N);
2317 end if;
2319 -- Issue an error if prefix denotes an eliminated subprogram
2321 else
2322 Check_For_Eliminated_Subprogram (P, Ent);
2323 end if;
2325 elsif Is_Object (Ent)
2326 or else Ekind (Ent) = E_Label
2327 then
2328 Set_Address_Taken (Ent);
2330 -- Deal with No_Implicit_Aliasing restriction
2332 if Restriction_Check_Required (No_Implicit_Aliasing) then
2333 if not Is_Aliased_View (P) then
2334 Check_Restriction (No_Implicit_Aliasing, P);
2335 else
2336 Check_No_Implicit_Aliasing (P);
2337 end if;
2338 end if;
2340 -- If we have an address of an object, and the attribute
2341 -- comes from source, then set the object as potentially
2342 -- source modified. We do this because the resulting address
2343 -- can potentially be used to modify the variable and we
2344 -- might not detect this, leading to some junk warnings.
2346 Set_Never_Set_In_Source (Ent, False);
2348 elsif (Is_Concurrent_Type (Etype (Ent))
2349 and then Etype (Ent) = Base_Type (Ent))
2350 or else Ekind (Ent) = E_Package
2351 or else Is_Generic_Unit (Ent)
2352 then
2353 Rewrite (N,
2354 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
2356 else
2357 Error_Attr ("invalid prefix for % attribute", P);
2358 end if;
2359 end;
2361 elsif Nkind (P) = N_Attribute_Reference
2362 and then Attribute_Name (P) = Name_AST_Entry
2363 then
2364 Rewrite (N,
2365 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
2367 elsif Is_Object_Reference (P) then
2368 null;
2370 elsif Nkind (P) = N_Selected_Component
2371 and then Is_Subprogram (Entity (Selector_Name (P)))
2372 then
2373 null;
2375 -- What exactly are we allowing here ??? and is this properly
2376 -- documented in the sinfo documentation for this node ???
2378 elsif not Comes_From_Source (N) then
2379 null;
2381 elsif Relaxed_RM_Semantics
2382 and then Nkind (P) = N_Attribute_Reference
2383 then
2384 null;
2386 else
2387 Error_Attr ("invalid prefix for % attribute", P);
2388 end if;
2390 Set_Etype (N, RTE (RE_Address));
2392 ------------------
2393 -- Address_Size --
2394 ------------------
2396 when Attribute_Address_Size =>
2397 Standard_Attribute (System_Address_Size);
2399 --------------
2400 -- Adjacent --
2401 --------------
2403 when Attribute_Adjacent =>
2404 Check_Floating_Point_Type_2;
2405 Set_Etype (N, P_Base_Type);
2406 Resolve (E1, P_Base_Type);
2407 Resolve (E2, P_Base_Type);
2409 ---------
2410 -- Aft --
2411 ---------
2413 when Attribute_Aft =>
2414 Check_Fixed_Point_Type_0;
2415 Set_Etype (N, Universal_Integer);
2417 ---------------
2418 -- Alignment --
2419 ---------------
2421 when Attribute_Alignment =>
2423 -- Don't we need more checking here, cf Size ???
2425 Check_E0;
2426 Check_Not_Incomplete_Type;
2427 Check_Not_CPP_Type;
2428 Set_Etype (N, Universal_Integer);
2430 ---------------
2431 -- Asm_Input --
2432 ---------------
2434 when Attribute_Asm_Input =>
2435 Check_Asm_Attribute;
2437 -- The back-end may need to take the address of E2
2439 if Is_Entity_Name (E2) then
2440 Set_Address_Taken (Entity (E2));
2441 end if;
2443 Set_Etype (N, RTE (RE_Asm_Input_Operand));
2445 ----------------
2446 -- Asm_Output --
2447 ----------------
2449 when Attribute_Asm_Output =>
2450 Check_Asm_Attribute;
2452 if Etype (E2) = Any_Type then
2453 return;
2455 elsif Aname = Name_Asm_Output then
2456 if not Is_Variable (E2) then
2457 Error_Attr
2458 ("second argument for Asm_Output is not variable", E2);
2459 end if;
2460 end if;
2462 Note_Possible_Modification (E2, Sure => True);
2464 -- The back-end may need to take the address of E2
2466 if Is_Entity_Name (E2) then
2467 Set_Address_Taken (Entity (E2));
2468 end if;
2470 Set_Etype (N, RTE (RE_Asm_Output_Operand));
2472 ---------------
2473 -- AST_Entry --
2474 ---------------
2476 when Attribute_AST_Entry => AST_Entry : declare
2477 Ent : Entity_Id;
2478 Pref : Node_Id;
2479 Ptyp : Entity_Id;
2481 Indexed : Boolean;
2482 -- Indicates if entry family index is present. Note the coding
2483 -- here handles the entry family case, but in fact it cannot be
2484 -- executed currently, because pragma AST_Entry does not permit
2485 -- the specification of an entry family.
2487 procedure Bad_AST_Entry;
2488 -- Signal a bad AST_Entry pragma
2490 function OK_Entry (E : Entity_Id) return Boolean;
2491 -- Checks that E is of an appropriate entity kind for an entry
2492 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2493 -- is set True for the entry family case). In the True case,
2494 -- makes sure that Is_AST_Entry is set on the entry.
2496 -------------------
2497 -- Bad_AST_Entry --
2498 -------------------
2500 procedure Bad_AST_Entry is
2501 begin
2502 Error_Attr_P ("prefix for % attribute must be task entry");
2503 end Bad_AST_Entry;
2505 --------------
2506 -- OK_Entry --
2507 --------------
2509 function OK_Entry (E : Entity_Id) return Boolean is
2510 Result : Boolean;
2512 begin
2513 if Indexed then
2514 Result := (Ekind (E) = E_Entry_Family);
2515 else
2516 Result := (Ekind (E) = E_Entry);
2517 end if;
2519 if Result then
2520 if not Is_AST_Entry (E) then
2521 Error_Msg_Name_2 := Aname;
2522 Error_Attr ("% attribute requires previous % pragma", P);
2523 end if;
2524 end if;
2526 return Result;
2527 end OK_Entry;
2529 -- Start of processing for AST_Entry
2531 begin
2532 Check_VMS (N);
2533 Check_E0;
2535 -- Deal with entry family case
2537 if Nkind (P) = N_Indexed_Component then
2538 Pref := Prefix (P);
2539 Indexed := True;
2540 else
2541 Pref := P;
2542 Indexed := False;
2543 end if;
2545 Ptyp := Etype (Pref);
2547 if Ptyp = Any_Type or else Error_Posted (Pref) then
2548 return;
2549 end if;
2551 -- If the prefix is a selected component whose prefix is of an
2552 -- access type, then introduce an explicit dereference.
2553 -- ??? Could we reuse Check_Dereference here?
2555 if Nkind (Pref) = N_Selected_Component
2556 and then Is_Access_Type (Ptyp)
2557 then
2558 Rewrite (Pref,
2559 Make_Explicit_Dereference (Sloc (Pref),
2560 Relocate_Node (Pref)));
2561 Analyze_And_Resolve (Pref, Designated_Type (Ptyp));
2562 end if;
2564 -- Prefix can be of the form a.b, where a is a task object
2565 -- and b is one of the entries of the corresponding task type.
2567 if Nkind (Pref) = N_Selected_Component
2568 and then OK_Entry (Entity (Selector_Name (Pref)))
2569 and then Is_Object_Reference (Prefix (Pref))
2570 and then Is_Task_Type (Etype (Prefix (Pref)))
2571 then
2572 null;
2574 -- Otherwise the prefix must be an entry of a containing task,
2575 -- or of a variable of the enclosing task type.
2577 else
2578 if Nkind_In (Pref, N_Identifier, N_Expanded_Name) then
2579 Ent := Entity (Pref);
2581 if not OK_Entry (Ent)
2582 or else not In_Open_Scopes (Scope (Ent))
2583 then
2584 Bad_AST_Entry;
2585 end if;
2587 else
2588 Bad_AST_Entry;
2589 end if;
2590 end if;
2592 Set_Etype (N, RTE (RE_AST_Handler));
2593 end AST_Entry;
2595 -----------------------------
2596 -- Atomic_Always_Lock_Free --
2597 -----------------------------
2599 when Attribute_Atomic_Always_Lock_Free =>
2600 Check_E0;
2601 Check_Type;
2602 Set_Etype (N, Standard_Boolean);
2604 ----------
2605 -- Base --
2606 ----------
2608 -- Note: when the base attribute appears in the context of a subtype
2609 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2610 -- the following circuit.
2612 when Attribute_Base => Base : declare
2613 Typ : Entity_Id;
2615 begin
2616 Check_E0;
2617 Find_Type (P);
2618 Typ := Entity (P);
2620 if Ada_Version >= Ada_95
2621 and then not Is_Scalar_Type (Typ)
2622 and then not Is_Generic_Type (Typ)
2623 then
2624 Error_Attr_P ("prefix of Base attribute must be scalar type");
2626 elsif Sloc (Typ) = Standard_Location
2627 and then Base_Type (Typ) = Typ
2628 and then Warn_On_Redundant_Constructs
2629 then
2630 Error_Msg_NE -- CODEFIX
2631 ("?r?redundant attribute, & is its own base type", N, Typ);
2632 end if;
2634 if Nkind (Parent (N)) /= N_Attribute_Reference then
2635 Error_Msg_Name_1 := Aname;
2636 Check_SPARK_Restriction
2637 ("attribute% is only allowed as prefix of another attribute", P);
2638 end if;
2640 Set_Etype (N, Base_Type (Entity (P)));
2641 Set_Entity (N, Base_Type (Entity (P)));
2642 Rewrite (N, New_Reference_To (Entity (N), Loc));
2643 Analyze (N);
2644 end Base;
2646 ---------
2647 -- Bit --
2648 ---------
2650 when Attribute_Bit => Bit :
2651 begin
2652 Check_E0;
2654 if not Is_Object_Reference (P) then
2655 Error_Attr_P ("prefix for % attribute must be object");
2657 -- What about the access object cases ???
2659 else
2660 null;
2661 end if;
2663 Set_Etype (N, Universal_Integer);
2664 end Bit;
2666 ---------------
2667 -- Bit_Order --
2668 ---------------
2670 when Attribute_Bit_Order => Bit_Order :
2671 begin
2672 Check_E0;
2673 Check_Type;
2675 if not Is_Record_Type (P_Type) then
2676 Error_Attr_P ("prefix of % attribute must be record type");
2677 end if;
2679 if Bytes_Big_Endian xor Reverse_Bit_Order (P_Type) then
2680 Rewrite (N,
2681 New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
2682 else
2683 Rewrite (N,
2684 New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
2685 end if;
2687 Set_Etype (N, RTE (RE_Bit_Order));
2688 Resolve (N);
2690 -- Reset incorrect indication of staticness
2692 Set_Is_Static_Expression (N, False);
2693 end Bit_Order;
2695 ------------------
2696 -- Bit_Position --
2697 ------------------
2699 -- Note: in generated code, we can have a Bit_Position attribute
2700 -- applied to a (naked) record component (i.e. the prefix is an
2701 -- identifier that references an E_Component or E_Discriminant
2702 -- entity directly, and this is interpreted as expected by Gigi.
2703 -- The following code will not tolerate such usage, but when the
2704 -- expander creates this special case, it marks it as analyzed
2705 -- immediately and sets an appropriate type.
2707 when Attribute_Bit_Position =>
2708 if Comes_From_Source (N) then
2709 Check_Component;
2710 end if;
2712 Set_Etype (N, Universal_Integer);
2714 ------------------
2715 -- Body_Version --
2716 ------------------
2718 when Attribute_Body_Version =>
2719 Check_E0;
2720 Check_Program_Unit;
2721 Set_Etype (N, RTE (RE_Version_String));
2723 --------------
2724 -- Callable --
2725 --------------
2727 when Attribute_Callable =>
2728 Check_E0;
2729 Set_Etype (N, Standard_Boolean);
2730 Check_Task_Prefix;
2732 ------------
2733 -- Caller --
2734 ------------
2736 when Attribute_Caller => Caller : declare
2737 Ent : Entity_Id;
2738 S : Entity_Id;
2740 begin
2741 Check_E0;
2743 if Nkind_In (P, N_Identifier, N_Expanded_Name) then
2744 Ent := Entity (P);
2746 if not Is_Entry (Ent) then
2747 Error_Attr ("invalid entry name", N);
2748 end if;
2750 else
2751 Error_Attr ("invalid entry name", N);
2752 return;
2753 end if;
2755 for J in reverse 0 .. Scope_Stack.Last loop
2756 S := Scope_Stack.Table (J).Entity;
2758 if S = Scope (Ent) then
2759 Error_Attr ("Caller must appear in matching accept or body", N);
2760 elsif S = Ent then
2761 exit;
2762 end if;
2763 end loop;
2765 Set_Etype (N, RTE (RO_AT_Task_Id));
2766 end Caller;
2768 -------------
2769 -- Ceiling --
2770 -------------
2772 when Attribute_Ceiling =>
2773 Check_Floating_Point_Type_1;
2774 Set_Etype (N, P_Base_Type);
2775 Resolve (E1, P_Base_Type);
2777 -----------
2778 -- Class --
2779 -----------
2781 when Attribute_Class =>
2782 Check_Restriction (No_Dispatch, N);
2783 Check_E0;
2784 Find_Type (N);
2786 -- Applying Class to untagged incomplete type is obsolescent in Ada
2787 -- 2005. Note that we can't test Is_Tagged_Type here on P_Type, since
2788 -- this flag gets set by Find_Type in this situation.
2790 if Restriction_Check_Required (No_Obsolescent_Features)
2791 and then Ada_Version >= Ada_2005
2792 and then Ekind (P_Type) = E_Incomplete_Type
2793 then
2794 declare
2795 DN : constant Node_Id := Declaration_Node (P_Type);
2796 begin
2797 if Nkind (DN) = N_Incomplete_Type_Declaration
2798 and then not Tagged_Present (DN)
2799 then
2800 Check_Restriction (No_Obsolescent_Features, P);
2801 end if;
2802 end;
2803 end if;
2805 ------------------
2806 -- Code_Address --
2807 ------------------
2809 when Attribute_Code_Address =>
2810 Check_E0;
2812 if Nkind (P) = N_Attribute_Reference
2813 and then Nam_In (Attribute_Name (P), Name_Elab_Body, Name_Elab_Spec)
2814 then
2815 null;
2817 elsif not Is_Entity_Name (P)
2818 or else (Ekind (Entity (P)) /= E_Function
2819 and then
2820 Ekind (Entity (P)) /= E_Procedure)
2821 then
2822 Error_Attr ("invalid prefix for % attribute", P);
2823 Set_Address_Taken (Entity (P));
2825 -- Issue an error if the prefix denotes an eliminated subprogram
2827 else
2828 Check_For_Eliminated_Subprogram (P, Entity (P));
2829 end if;
2831 Set_Etype (N, RTE (RE_Address));
2833 ----------------------
2834 -- Compiler_Version --
2835 ----------------------
2837 when Attribute_Compiler_Version =>
2838 Check_E0;
2839 Check_Standard_Prefix;
2840 Rewrite (N, Make_String_Literal (Loc, "GNAT " & Gnat_Version_String));
2841 Analyze_And_Resolve (N, Standard_String);
2843 --------------------
2844 -- Component_Size --
2845 --------------------
2847 when Attribute_Component_Size =>
2848 Check_E0;
2849 Set_Etype (N, Universal_Integer);
2851 -- Note: unlike other array attributes, unconstrained arrays are OK
2853 if Is_Array_Type (P_Type) and then not Is_Constrained (P_Type) then
2854 null;
2855 else
2856 Check_Array_Type;
2857 end if;
2859 -------------
2860 -- Compose --
2861 -------------
2863 when Attribute_Compose =>
2864 Check_Floating_Point_Type_2;
2865 Set_Etype (N, P_Base_Type);
2866 Resolve (E1, P_Base_Type);
2867 Resolve (E2, Any_Integer);
2869 -----------------
2870 -- Constrained --
2871 -----------------
2873 when Attribute_Constrained =>
2874 Check_E0;
2875 Set_Etype (N, Standard_Boolean);
2877 -- Case from RM J.4(2) of constrained applied to private type
2879 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
2880 Check_Restriction (No_Obsolescent_Features, P);
2882 if Warn_On_Obsolescent_Feature then
2883 Error_Msg_N
2884 ("constrained for private type is an " &
2885 "obsolescent feature (RM J.4)?j?", N);
2886 end if;
2888 -- If we are within an instance, the attribute must be legal
2889 -- because it was valid in the generic unit. Ditto if this is
2890 -- an inlining of a function declared in an instance.
2892 if In_Instance
2893 or else In_Inlined_Body
2894 then
2895 return;
2897 -- For sure OK if we have a real private type itself, but must
2898 -- be completed, cannot apply Constrained to incomplete type.
2900 elsif Is_Private_Type (Entity (P)) then
2902 -- Note: this is one of the Annex J features that does not
2903 -- generate a warning from -gnatwj, since in fact it seems
2904 -- very useful, and is used in the GNAT runtime.
2906 Check_Not_Incomplete_Type;
2907 return;
2908 end if;
2910 -- Normal (non-obsolescent case) of application to object of
2911 -- a discriminated type.
2913 else
2914 Check_Object_Reference (P);
2916 -- If N does not come from source, then we allow the
2917 -- the attribute prefix to be of a private type whose
2918 -- full type has discriminants. This occurs in cases
2919 -- involving expanded calls to stream attributes.
2921 if not Comes_From_Source (N) then
2922 P_Type := Underlying_Type (P_Type);
2923 end if;
2925 -- Must have discriminants or be an access type designating
2926 -- a type with discriminants. If it is a classwide type is ???
2927 -- has unknown discriminants.
2929 if Has_Discriminants (P_Type)
2930 or else Has_Unknown_Discriminants (P_Type)
2931 or else
2932 (Is_Access_Type (P_Type)
2933 and then Has_Discriminants (Designated_Type (P_Type)))
2934 then
2935 return;
2937 -- Also allow an object of a generic type if extensions allowed
2938 -- and allow this for any type at all.
2940 elsif (Is_Generic_Type (P_Type)
2941 or else Is_Generic_Actual_Type (P_Type))
2942 and then Extensions_Allowed
2943 then
2944 return;
2945 end if;
2946 end if;
2948 -- Fall through if bad prefix
2950 Error_Attr_P
2951 ("prefix of % attribute must be object of discriminated type");
2953 ---------------
2954 -- Copy_Sign --
2955 ---------------
2957 when Attribute_Copy_Sign =>
2958 Check_Floating_Point_Type_2;
2959 Set_Etype (N, P_Base_Type);
2960 Resolve (E1, P_Base_Type);
2961 Resolve (E2, P_Base_Type);
2963 -----------
2964 -- Count --
2965 -----------
2967 when Attribute_Count => Count :
2968 declare
2969 Ent : Entity_Id;
2970 S : Entity_Id;
2971 Tsk : Entity_Id;
2973 begin
2974 Check_E0;
2976 if Nkind_In (P, N_Identifier, N_Expanded_Name) then
2977 Ent := Entity (P);
2979 if Ekind (Ent) /= E_Entry then
2980 Error_Attr ("invalid entry name", N);
2981 end if;
2983 elsif Nkind (P) = N_Indexed_Component then
2984 if not Is_Entity_Name (Prefix (P))
2985 or else No (Entity (Prefix (P)))
2986 or else Ekind (Entity (Prefix (P))) /= E_Entry_Family
2987 then
2988 if Nkind (Prefix (P)) = N_Selected_Component
2989 and then Present (Entity (Selector_Name (Prefix (P))))
2990 and then Ekind (Entity (Selector_Name (Prefix (P)))) =
2991 E_Entry_Family
2992 then
2993 Error_Attr
2994 ("attribute % must apply to entry of current task", P);
2996 else
2997 Error_Attr ("invalid entry family name", P);
2998 end if;
2999 return;
3001 else
3002 Ent := Entity (Prefix (P));
3003 end if;
3005 elsif Nkind (P) = N_Selected_Component
3006 and then Present (Entity (Selector_Name (P)))
3007 and then Ekind (Entity (Selector_Name (P))) = E_Entry
3008 then
3009 Error_Attr
3010 ("attribute % must apply to entry of current task", P);
3012 else
3013 Error_Attr ("invalid entry name", N);
3014 return;
3015 end if;
3017 for J in reverse 0 .. Scope_Stack.Last loop
3018 S := Scope_Stack.Table (J).Entity;
3020 if S = Scope (Ent) then
3021 if Nkind (P) = N_Expanded_Name then
3022 Tsk := Entity (Prefix (P));
3024 -- The prefix denotes either the task type, or else a
3025 -- single task whose task type is being analyzed.
3027 if (Is_Type (Tsk)
3028 and then Tsk = S)
3030 or else (not Is_Type (Tsk)
3031 and then Etype (Tsk) = S
3032 and then not (Comes_From_Source (S)))
3033 then
3034 null;
3035 else
3036 Error_Attr
3037 ("Attribute % must apply to entry of current task", N);
3038 end if;
3039 end if;
3041 exit;
3043 elsif Ekind (Scope (Ent)) in Task_Kind
3044 and then
3045 not Ekind_In (S, E_Loop, E_Block, E_Entry, E_Entry_Family)
3046 then
3047 Error_Attr ("Attribute % cannot appear in inner unit", N);
3049 elsif Ekind (Scope (Ent)) = E_Protected_Type
3050 and then not Has_Completion (Scope (Ent))
3051 then
3052 Error_Attr ("attribute % can only be used inside body", N);
3053 end if;
3054 end loop;
3056 if Is_Overloaded (P) then
3057 declare
3058 Index : Interp_Index;
3059 It : Interp;
3061 begin
3062 Get_First_Interp (P, Index, It);
3064 while Present (It.Nam) loop
3065 if It.Nam = Ent then
3066 null;
3068 -- Ada 2005 (AI-345): Do not consider primitive entry
3069 -- wrappers generated for task or protected types.
3071 elsif Ada_Version >= Ada_2005
3072 and then not Comes_From_Source (It.Nam)
3073 then
3074 null;
3076 else
3077 Error_Attr ("ambiguous entry name", N);
3078 end if;
3080 Get_Next_Interp (Index, It);
3081 end loop;
3082 end;
3083 end if;
3085 Set_Etype (N, Universal_Integer);
3086 end Count;
3088 -----------------------
3089 -- Default_Bit_Order --
3090 -----------------------
3092 when Attribute_Default_Bit_Order => Default_Bit_Order :
3093 begin
3094 Check_Standard_Prefix;
3096 if Bytes_Big_Endian then
3097 Rewrite (N,
3098 Make_Integer_Literal (Loc, False_Value));
3099 else
3100 Rewrite (N,
3101 Make_Integer_Literal (Loc, True_Value));
3102 end if;
3104 Set_Etype (N, Universal_Integer);
3105 Set_Is_Static_Expression (N);
3106 end Default_Bit_Order;
3108 --------------
3109 -- Definite --
3110 --------------
3112 when Attribute_Definite =>
3113 Legal_Formal_Attribute;
3115 -----------
3116 -- Delta --
3117 -----------
3119 when Attribute_Delta =>
3120 Check_Fixed_Point_Type_0;
3121 Set_Etype (N, Universal_Real);
3123 ------------
3124 -- Denorm --
3125 ------------
3127 when Attribute_Denorm =>
3128 Check_Floating_Point_Type_0;
3129 Set_Etype (N, Standard_Boolean);
3131 ---------------------
3132 -- Descriptor_Size --
3133 ---------------------
3135 when Attribute_Descriptor_Size =>
3136 Check_E0;
3138 if not Is_Entity_Name (P)
3139 or else not Is_Type (Entity (P))
3140 then
3141 Error_Attr_P ("prefix of attribute % must denote a type");
3142 end if;
3144 Set_Etype (N, Universal_Integer);
3146 ------------
3147 -- Digits --
3148 ------------
3150 when Attribute_Digits =>
3151 Check_E0;
3152 Check_Type;
3154 if not Is_Floating_Point_Type (P_Type)
3155 and then not Is_Decimal_Fixed_Point_Type (P_Type)
3156 then
3157 Error_Attr_P
3158 ("prefix of % attribute must be float or decimal type");
3159 end if;
3161 Set_Etype (N, Universal_Integer);
3163 ---------------
3164 -- Elab_Body --
3165 ---------------
3167 -- Also handles processing for Elab_Spec and Elab_Subp_Body
3169 when Attribute_Elab_Body |
3170 Attribute_Elab_Spec |
3171 Attribute_Elab_Subp_Body =>
3173 Check_E0;
3174 Check_Unit_Name (P);
3175 Set_Etype (N, Standard_Void_Type);
3177 -- We have to manually call the expander in this case to get
3178 -- the necessary expansion (normally attributes that return
3179 -- entities are not expanded).
3181 Expand (N);
3183 ---------------
3184 -- Elab_Spec --
3185 ---------------
3187 -- Shares processing with Elab_Body
3189 ----------------
3190 -- Elaborated --
3191 ----------------
3193 when Attribute_Elaborated =>
3194 Check_E0;
3195 Check_Unit_Name (P);
3196 Set_Etype (N, Standard_Boolean);
3198 ----------
3199 -- Emax --
3200 ----------
3202 when Attribute_Emax =>
3203 Check_Floating_Point_Type_0;
3204 Set_Etype (N, Universal_Integer);
3206 -------------
3207 -- Enabled --
3208 -------------
3210 when Attribute_Enabled =>
3211 Check_Either_E0_Or_E1;
3213 if Present (E1) then
3214 if not Is_Entity_Name (E1) or else No (Entity (E1)) then
3215 Error_Msg_N ("entity name expected for Enabled attribute", E1);
3216 E1 := Empty;
3217 end if;
3218 end if;
3220 if Nkind (P) /= N_Identifier then
3221 Error_Msg_N ("identifier expected (check name)", P);
3222 elsif Get_Check_Id (Chars (P)) = No_Check_Id then
3223 Error_Msg_N ("& is not a recognized check name", P);
3224 end if;
3226 Set_Etype (N, Standard_Boolean);
3228 --------------
3229 -- Enum_Rep --
3230 --------------
3232 when Attribute_Enum_Rep => Enum_Rep : declare
3233 begin
3234 if Present (E1) then
3235 Check_E1;
3236 Check_Discrete_Type;
3237 Resolve (E1, P_Base_Type);
3239 else
3240 if not Is_Entity_Name (P)
3241 or else (not Is_Object (Entity (P))
3242 and then
3243 Ekind (Entity (P)) /= E_Enumeration_Literal)
3244 then
3245 Error_Attr_P
3246 ("prefix of % attribute must be " &
3247 "discrete type/object or enum literal");
3248 end if;
3249 end if;
3251 Set_Etype (N, Universal_Integer);
3252 end Enum_Rep;
3254 --------------
3255 -- Enum_Val --
3256 --------------
3258 when Attribute_Enum_Val => Enum_Val : begin
3259 Check_E1;
3260 Check_Type;
3262 if not Is_Enumeration_Type (P_Type) then
3263 Error_Attr_P ("prefix of % attribute must be enumeration type");
3264 end if;
3266 -- If the enumeration type has a standard representation, the effect
3267 -- is the same as 'Val, so rewrite the attribute as a 'Val.
3269 if not Has_Non_Standard_Rep (P_Base_Type) then
3270 Rewrite (N,
3271 Make_Attribute_Reference (Loc,
3272 Prefix => Relocate_Node (Prefix (N)),
3273 Attribute_Name => Name_Val,
3274 Expressions => New_List (Relocate_Node (E1))));
3275 Analyze_And_Resolve (N, P_Base_Type);
3277 -- Non-standard representation case (enumeration with holes)
3279 else
3280 Check_Enum_Image;
3281 Resolve (E1, Any_Integer);
3282 Set_Etype (N, P_Base_Type);
3283 end if;
3284 end Enum_Val;
3286 -------------
3287 -- Epsilon --
3288 -------------
3290 when Attribute_Epsilon =>
3291 Check_Floating_Point_Type_0;
3292 Set_Etype (N, Universal_Real);
3294 --------------
3295 -- Exponent --
3296 --------------
3298 when Attribute_Exponent =>
3299 Check_Floating_Point_Type_1;
3300 Set_Etype (N, Universal_Integer);
3301 Resolve (E1, P_Base_Type);
3303 ------------------
3304 -- External_Tag --
3305 ------------------
3307 when Attribute_External_Tag =>
3308 Check_E0;
3309 Check_Type;
3311 Set_Etype (N, Standard_String);
3313 if not Is_Tagged_Type (P_Type) then
3314 Error_Attr_P ("prefix of % attribute must be tagged");
3315 end if;
3317 ---------------
3318 -- Fast_Math --
3319 ---------------
3321 when Attribute_Fast_Math =>
3322 Check_Standard_Prefix;
3323 Rewrite (N, New_Occurrence_Of (Boolean_Literals (Fast_Math), Loc));
3325 -----------
3326 -- First --
3327 -----------
3329 when Attribute_First =>
3330 Check_Array_Or_Scalar_Type;
3331 Bad_Attribute_For_Predicate;
3333 ---------------
3334 -- First_Bit --
3335 ---------------
3337 when Attribute_First_Bit =>
3338 Check_Component;
3339 Set_Etype (N, Universal_Integer);
3341 -----------------
3342 -- First_Valid --
3343 -----------------
3345 when Attribute_First_Valid =>
3346 Check_First_Last_Valid;
3347 Set_Etype (N, P_Type);
3349 -----------------
3350 -- Fixed_Value --
3351 -----------------
3353 when Attribute_Fixed_Value =>
3354 Check_E1;
3355 Check_Fixed_Point_Type;
3356 Resolve (E1, Any_Integer);
3357 Set_Etype (N, P_Base_Type);
3359 -----------
3360 -- Floor --
3361 -----------
3363 when Attribute_Floor =>
3364 Check_Floating_Point_Type_1;
3365 Set_Etype (N, P_Base_Type);
3366 Resolve (E1, P_Base_Type);
3368 ----------
3369 -- Fore --
3370 ----------
3372 when Attribute_Fore =>
3373 Check_Fixed_Point_Type_0;
3374 Set_Etype (N, Universal_Integer);
3376 --------------
3377 -- Fraction --
3378 --------------
3380 when Attribute_Fraction =>
3381 Check_Floating_Point_Type_1;
3382 Set_Etype (N, P_Base_Type);
3383 Resolve (E1, P_Base_Type);
3385 --------------
3386 -- From_Any --
3387 --------------
3389 when Attribute_From_Any =>
3390 Check_E1;
3391 Check_PolyORB_Attribute;
3392 Set_Etype (N, P_Base_Type);
3394 -----------------------
3395 -- Has_Access_Values --
3396 -----------------------
3398 when Attribute_Has_Access_Values =>
3399 Check_Type;
3400 Check_E0;
3401 Set_Etype (N, Standard_Boolean);
3403 -----------------------
3404 -- Has_Tagged_Values --
3405 -----------------------
3407 when Attribute_Has_Tagged_Values =>
3408 Check_Type;
3409 Check_E0;
3410 Set_Etype (N, Standard_Boolean);
3412 -----------------------
3413 -- Has_Discriminants --
3414 -----------------------
3416 when Attribute_Has_Discriminants =>
3417 Legal_Formal_Attribute;
3419 --------------
3420 -- Identity --
3421 --------------
3423 when Attribute_Identity =>
3424 Check_E0;
3425 Analyze (P);
3427 if Etype (P) = Standard_Exception_Type then
3428 Set_Etype (N, RTE (RE_Exception_Id));
3430 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3431 -- task interface class-wide types.
3433 elsif Is_Task_Type (Etype (P))
3434 or else (Is_Access_Type (Etype (P))
3435 and then Is_Task_Type (Designated_Type (Etype (P))))
3436 or else (Ada_Version >= Ada_2005
3437 and then Ekind (Etype (P)) = E_Class_Wide_Type
3438 and then Is_Interface (Etype (P))
3439 and then Is_Task_Interface (Etype (P)))
3440 then
3441 Resolve (P);
3442 Set_Etype (N, RTE (RO_AT_Task_Id));
3444 else
3445 if Ada_Version >= Ada_2005 then
3446 Error_Attr_P
3447 ("prefix of % attribute must be an exception, a " &
3448 "task or a task interface class-wide object");
3449 else
3450 Error_Attr_P
3451 ("prefix of % attribute must be a task or an exception");
3452 end if;
3453 end if;
3455 -----------
3456 -- Image --
3457 -----------
3459 when Attribute_Image => Image :
3460 begin
3461 Check_SPARK_Restriction_On_Attribute;
3462 Check_Scalar_Type;
3463 Set_Etype (N, Standard_String);
3465 if Is_Real_Type (P_Type) then
3466 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3467 Error_Msg_Name_1 := Aname;
3468 Error_Msg_N
3469 ("(Ada 83) % attribute not allowed for real types", N);
3470 end if;
3471 end if;
3473 if Is_Enumeration_Type (P_Type) then
3474 Check_Restriction (No_Enumeration_Maps, N);
3475 end if;
3477 Check_E1;
3478 Resolve (E1, P_Base_Type);
3479 Check_Enum_Image;
3480 Validate_Non_Static_Attribute_Function_Call;
3481 end Image;
3483 ---------
3484 -- Img --
3485 ---------
3487 when Attribute_Img => Img :
3488 begin
3489 Check_E0;
3490 Set_Etype (N, Standard_String);
3492 if not Is_Scalar_Type (P_Type)
3493 or else (Is_Entity_Name (P) and then Is_Type (Entity (P)))
3494 then
3495 Error_Attr_P
3496 ("prefix of % attribute must be scalar object name");
3497 end if;
3499 Check_Enum_Image;
3500 end Img;
3502 -----------
3503 -- Input --
3504 -----------
3506 when Attribute_Input =>
3507 Check_E1;
3508 Check_Stream_Attribute (TSS_Stream_Input);
3509 Set_Etype (N, P_Base_Type);
3511 -------------------
3512 -- Integer_Value --
3513 -------------------
3515 when Attribute_Integer_Value =>
3516 Check_E1;
3517 Check_Integer_Type;
3518 Resolve (E1, Any_Fixed);
3520 -- Signal an error if argument type is not a specific fixed-point
3521 -- subtype. An error has been signalled already if the argument
3522 -- was not of a fixed-point type.
3524 if Etype (E1) = Any_Fixed and then not Error_Posted (E1) then
3525 Error_Attr ("argument of % must be of a fixed-point type", E1);
3526 end if;
3528 Set_Etype (N, P_Base_Type);
3530 -------------------
3531 -- Invalid_Value --
3532 -------------------
3534 when Attribute_Invalid_Value =>
3535 Check_E0;
3536 Check_Scalar_Type;
3537 Set_Etype (N, P_Base_Type);
3538 Invalid_Value_Used := True;
3540 -----------
3541 -- Large --
3542 -----------
3544 when Attribute_Large =>
3545 Check_E0;
3546 Check_Real_Type;
3547 Set_Etype (N, Universal_Real);
3549 ----------
3550 -- Last --
3551 ----------
3553 when Attribute_Last =>
3554 Check_Array_Or_Scalar_Type;
3555 Bad_Attribute_For_Predicate;
3557 --------------
3558 -- Last_Bit --
3559 --------------
3561 when Attribute_Last_Bit =>
3562 Check_Component;
3563 Set_Etype (N, Universal_Integer);
3565 ----------------
3566 -- Last_Valid --
3567 ----------------
3569 when Attribute_Last_Valid =>
3570 Check_First_Last_Valid;
3571 Set_Etype (N, P_Type);
3573 ------------------
3574 -- Leading_Part --
3575 ------------------
3577 when Attribute_Leading_Part =>
3578 Check_Floating_Point_Type_2;
3579 Set_Etype (N, P_Base_Type);
3580 Resolve (E1, P_Base_Type);
3581 Resolve (E2, Any_Integer);
3583 ------------
3584 -- Length --
3585 ------------
3587 when Attribute_Length =>
3588 Check_Array_Type;
3589 Set_Etype (N, Universal_Integer);
3591 ---------------
3592 -- Lock_Free --
3593 ---------------
3595 when Attribute_Lock_Free =>
3596 Check_E0;
3597 Set_Etype (N, Standard_Boolean);
3599 if not Is_Protected_Type (P_Type) then
3600 Error_Attr_P
3601 ("prefix of % attribute must be a protected object");
3602 end if;
3604 ----------------
3605 -- Loop_Entry --
3606 ----------------
3608 when Attribute_Loop_Entry => Loop_Entry : declare
3609 procedure Check_References_In_Prefix (Loop_Id : Entity_Id);
3610 -- Inspect the prefix for any uses of entities declared within the
3611 -- related loop. Loop_Id denotes the loop identifier.
3613 --------------------------------
3614 -- Check_References_In_Prefix --
3615 --------------------------------
3617 procedure Check_References_In_Prefix (Loop_Id : Entity_Id) is
3618 Loop_Decl : constant Node_Id := Label_Construct (Parent (Loop_Id));
3620 function Check_Reference (Nod : Node_Id) return Traverse_Result;
3621 -- Determine whether a reference mentions an entity declared
3622 -- within the related loop.
3624 function Declared_Within (Nod : Node_Id) return Boolean;
3625 -- Determine whether Nod appears in the subtree of Loop_Decl
3627 ---------------------
3628 -- Check_Reference --
3629 ---------------------
3631 function Check_Reference (Nod : Node_Id) return Traverse_Result is
3632 begin
3633 if Nkind (Nod) = N_Identifier
3634 and then Present (Entity (Nod))
3635 and then Declared_Within (Declaration_Node (Entity (Nod)))
3636 then
3637 Error_Attr
3638 ("prefix of attribute % cannot reference local entities",
3639 Nod);
3640 return Abandon;
3641 else
3642 return OK;
3643 end if;
3644 end Check_Reference;
3646 procedure Check_References is new Traverse_Proc (Check_Reference);
3648 ---------------------
3649 -- Declared_Within --
3650 ---------------------
3652 function Declared_Within (Nod : Node_Id) return Boolean is
3653 Stmt : Node_Id;
3655 begin
3656 Stmt := Nod;
3657 while Present (Stmt) loop
3658 if Stmt = Loop_Decl then
3659 return True;
3661 -- Prevent the search from going too far
3663 elsif Is_Body_Or_Package_Declaration (Stmt) then
3664 exit;
3665 end if;
3667 Stmt := Parent (Stmt);
3668 end loop;
3670 return False;
3671 end Declared_Within;
3673 -- Start of processing for Check_Prefix_For_Local_References
3675 begin
3676 Check_References (P);
3677 end Check_References_In_Prefix;
3679 -- Local variables
3681 Context : constant Node_Id := Parent (N);
3682 Attr : Node_Id;
3683 Enclosing_Loop : Node_Id;
3684 In_Loop_Assertion : Boolean := False;
3685 Loop_Id : Entity_Id := Empty;
3686 Scop : Entity_Id;
3687 Stmt : Node_Id;
3689 -- Start of processing for Loop_Entry
3691 begin
3692 Attr := N;
3694 -- Set the type of the attribute now to ensure the successfull
3695 -- continuation of analysis even if the attribute is misplaced.
3697 Set_Etype (Attr, P_Type);
3699 -- Attribute 'Loop_Entry may appear in several flavors:
3701 -- * Prefix'Loop_Entry - in this form, the attribute applies to the
3702 -- nearest enclosing loop.
3704 -- * Prefix'Loop_Entry (Expr) - depending on what Expr denotes, the
3705 -- attribute may be related to a loop denoted by label Expr or
3706 -- the prefix may denote an array object and Expr may act as an
3707 -- indexed component.
3709 -- * Prefix'Loop_Entry (Expr1, ..., ExprN) - the attribute applies
3710 -- to the nearest enclosing loop, all expressions are part of
3711 -- an indexed component.
3713 -- * Prefix'Loop_Entry (Expr) (...) (...) - depending on what Expr
3714 -- denotes, the attribute may be related to a loop denoted by
3715 -- label Expr or the prefix may denote a multidimensional array
3716 -- array object and Expr along with the rest of the expressions
3717 -- may act as indexed components.
3719 -- Regardless of variations, the attribute reference does not have an
3720 -- expression list. Instead, all available expressions are stored as
3721 -- indexed components.
3723 -- When the attribute is part of an indexed component, find the first
3724 -- expression as it will determine the semantics of 'Loop_Entry.
3726 if Nkind (Context) = N_Indexed_Component then
3727 E1 := First (Expressions (Context));
3728 E2 := Next (E1);
3730 -- The attribute reference appears in the following form:
3732 -- Prefix'Loop_Entry (Exp1, Expr2, ..., ExprN) [(...)]
3734 -- In this case, the loop name is omitted and no rewriting is
3735 -- required.
3737 if Present (E2) then
3738 null;
3740 -- The form of the attribute is:
3742 -- Prefix'Loop_Entry (Expr) [(...)]
3744 -- If Expr denotes a loop entry, the whole attribute and indexed
3745 -- component will have to be rewritten to reflect this relation.
3747 else
3748 pragma Assert (Present (E1));
3750 -- Do not expand the expression as it may have side effects.
3751 -- Simply preanalyze to determine whether it is a loop name or
3752 -- something else.
3754 Preanalyze_And_Resolve (E1);
3756 if Is_Entity_Name (E1)
3757 and then Present (Entity (E1))
3758 and then Ekind (Entity (E1)) = E_Loop
3759 then
3760 Loop_Id := Entity (E1);
3762 -- Transform the attribute and enclosing indexed component
3764 Set_Expressions (N, Expressions (Context));
3765 Rewrite (Context, N);
3766 Set_Etype (Context, P_Type);
3768 Attr := Context;
3769 end if;
3770 end if;
3771 end if;
3773 -- The prefix must denote an object
3775 if not Is_Object_Reference (P) then
3776 Error_Attr_P ("prefix of attribute % must denote an object");
3777 end if;
3779 -- The prefix cannot be of a limited type because the expansion of
3780 -- Loop_Entry must create a constant initialized by the evaluated
3781 -- prefix.
3783 if Is_Immutably_Limited_Type (Etype (P)) then
3784 Error_Attr_P ("prefix of attribute % cannot be limited");
3785 end if;
3787 -- Climb the parent chain to verify the location of the attribute and
3788 -- find the enclosing loop.
3790 Stmt := Attr;
3791 while Present (Stmt) loop
3793 -- Locate the enclosing Loop_Invariant / Loop_Variant pragma
3795 if Nkind (Original_Node (Stmt)) = N_Pragma
3796 and then
3797 Nam_In (Pragma_Name (Original_Node (Stmt)),
3798 Name_Loop_Invariant,
3799 Name_Loop_Variant)
3800 then
3801 In_Loop_Assertion := True;
3803 -- Locate the enclosing loop (if any). Note that Ada 2012 array
3804 -- iteration may be expanded into several nested loops, we are
3805 -- interested in the outermost one which has the loop identifier.
3807 elsif Nkind (Stmt) = N_Loop_Statement
3808 and then Present (Identifier (Stmt))
3809 then
3810 Enclosing_Loop := Stmt;
3812 -- The original attribute reference may lack a loop name. Use
3813 -- the name of the enclosing loop because it is the related
3814 -- loop.
3816 if No (Loop_Id) then
3817 Loop_Id := Entity (Identifier (Enclosing_Loop));
3818 end if;
3820 exit;
3822 -- Prevent the search from going too far
3824 elsif Is_Body_Or_Package_Declaration (Stmt) then
3825 exit;
3826 end if;
3828 Stmt := Parent (Stmt);
3829 end loop;
3831 -- Loop_Entry must appear within a Loop_Assertion pragma
3833 if not In_Loop_Assertion then
3834 Error_Attr
3835 ("attribute % must appear within pragma Loop_Variant or " &
3836 "Loop_Invariant", N);
3837 end if;
3839 -- A Loop_Entry that applies to a given loop statement shall not
3840 -- appear within a body of accept statement, if this construct is
3841 -- itself enclosed by the given loop statement.
3843 for Index in reverse 0 .. Scope_Stack.Last loop
3844 Scop := Scope_Stack.Table (Index).Entity;
3846 if Ekind (Scop) = E_Loop and then Scop = Loop_Id then
3847 exit;
3849 elsif Ekind_In (Scop, E_Block, E_Loop, E_Return_Statement) then
3850 null;
3852 else
3853 Error_Attr
3854 ("attribute % cannot appear in body or accept statement", N);
3855 exit;
3856 end if;
3857 end loop;
3859 -- The prefix cannot mention entities declared within the related
3860 -- loop because they will not be visible once the prefix is moved
3861 -- outside the loop.
3863 Check_References_In_Prefix (Loop_Id);
3865 -- The prefix must denote a static entity if the pragma does not
3866 -- apply to the innermost enclosing loop statement.
3868 if Present (Enclosing_Loop)
3869 and then Entity (Identifier (Enclosing_Loop)) /= Loop_Id
3870 and then not Is_Entity_Name (P)
3871 then
3872 Error_Attr_P ("prefix of attribute % must denote an entity");
3873 end if;
3874 end Loop_Entry;
3876 -------------
3877 -- Machine --
3878 -------------
3880 when Attribute_Machine =>
3881 Check_Floating_Point_Type_1;
3882 Set_Etype (N, P_Base_Type);
3883 Resolve (E1, P_Base_Type);
3885 ------------------
3886 -- Machine_Emax --
3887 ------------------
3889 when Attribute_Machine_Emax =>
3890 Check_Floating_Point_Type_0;
3891 Set_Etype (N, Universal_Integer);
3893 ------------------
3894 -- Machine_Emin --
3895 ------------------
3897 when Attribute_Machine_Emin =>
3898 Check_Floating_Point_Type_0;
3899 Set_Etype (N, Universal_Integer);
3901 ----------------------
3902 -- Machine_Mantissa --
3903 ----------------------
3905 when Attribute_Machine_Mantissa =>
3906 Check_Floating_Point_Type_0;
3907 Set_Etype (N, Universal_Integer);
3909 -----------------------
3910 -- Machine_Overflows --
3911 -----------------------
3913 when Attribute_Machine_Overflows =>
3914 Check_Real_Type;
3915 Check_E0;
3916 Set_Etype (N, Standard_Boolean);
3918 -------------------
3919 -- Machine_Radix --
3920 -------------------
3922 when Attribute_Machine_Radix =>
3923 Check_Real_Type;
3924 Check_E0;
3925 Set_Etype (N, Universal_Integer);
3927 ----------------------
3928 -- Machine_Rounding --
3929 ----------------------
3931 when Attribute_Machine_Rounding =>
3932 Check_Floating_Point_Type_1;
3933 Set_Etype (N, P_Base_Type);
3934 Resolve (E1, P_Base_Type);
3936 --------------------
3937 -- Machine_Rounds --
3938 --------------------
3940 when Attribute_Machine_Rounds =>
3941 Check_Real_Type;
3942 Check_E0;
3943 Set_Etype (N, Standard_Boolean);
3945 ------------------
3946 -- Machine_Size --
3947 ------------------
3949 when Attribute_Machine_Size =>
3950 Check_E0;
3951 Check_Type;
3952 Check_Not_Incomplete_Type;
3953 Set_Etype (N, Universal_Integer);
3955 --------------
3956 -- Mantissa --
3957 --------------
3959 when Attribute_Mantissa =>
3960 Check_E0;
3961 Check_Real_Type;
3962 Set_Etype (N, Universal_Integer);
3964 ---------
3965 -- Max --
3966 ---------
3968 when Attribute_Max =>
3969 Check_E2;
3970 Check_Scalar_Type;
3971 Resolve (E1, P_Base_Type);
3972 Resolve (E2, P_Base_Type);
3973 Set_Etype (N, P_Base_Type);
3975 ----------------------------------
3976 -- Max_Alignment_For_Allocation --
3977 -- Max_Size_In_Storage_Elements --
3978 ----------------------------------
3980 when Attribute_Max_Alignment_For_Allocation |
3981 Attribute_Max_Size_In_Storage_Elements =>
3982 Check_E0;
3983 Check_Type;
3984 Check_Not_Incomplete_Type;
3985 Set_Etype (N, Universal_Integer);
3987 -----------------------
3988 -- Maximum_Alignment --
3989 -----------------------
3991 when Attribute_Maximum_Alignment =>
3992 Standard_Attribute (Ttypes.Maximum_Alignment);
3994 --------------------
3995 -- Mechanism_Code --
3996 --------------------
3998 when Attribute_Mechanism_Code =>
3999 if not Is_Entity_Name (P)
4000 or else not Is_Subprogram (Entity (P))
4001 then
4002 Error_Attr_P ("prefix of % attribute must be subprogram");
4003 end if;
4005 Check_Either_E0_Or_E1;
4007 if Present (E1) then
4008 Resolve (E1, Any_Integer);
4009 Set_Etype (E1, Standard_Integer);
4011 if not Is_Static_Expression (E1) then
4012 Flag_Non_Static_Expr
4013 ("expression for parameter number must be static!", E1);
4014 Error_Attr;
4016 elsif UI_To_Int (Intval (E1)) > Number_Formals (Entity (P))
4017 or else UI_To_Int (Intval (E1)) < 0
4018 then
4019 Error_Attr ("invalid parameter number for % attribute", E1);
4020 end if;
4021 end if;
4023 Set_Etype (N, Universal_Integer);
4025 ---------
4026 -- Min --
4027 ---------
4029 when Attribute_Min =>
4030 Check_E2;
4031 Check_Scalar_Type;
4032 Resolve (E1, P_Base_Type);
4033 Resolve (E2, P_Base_Type);
4034 Set_Etype (N, P_Base_Type);
4036 ---------
4037 -- Mod --
4038 ---------
4040 when Attribute_Mod =>
4042 -- Note: this attribute is only allowed in Ada 2005 mode, but
4043 -- we do not need to test that here, since Mod is only recognized
4044 -- as an attribute name in Ada 2005 mode during the parse.
4046 Check_E1;
4047 Check_Modular_Integer_Type;
4048 Resolve (E1, Any_Integer);
4049 Set_Etype (N, P_Base_Type);
4051 -----------
4052 -- Model --
4053 -----------
4055 when Attribute_Model =>
4056 Check_Floating_Point_Type_1;
4057 Set_Etype (N, P_Base_Type);
4058 Resolve (E1, P_Base_Type);
4060 ----------------
4061 -- Model_Emin --
4062 ----------------
4064 when Attribute_Model_Emin =>
4065 Check_Floating_Point_Type_0;
4066 Set_Etype (N, Universal_Integer);
4068 -------------------
4069 -- Model_Epsilon --
4070 -------------------
4072 when Attribute_Model_Epsilon =>
4073 Check_Floating_Point_Type_0;
4074 Set_Etype (N, Universal_Real);
4076 --------------------
4077 -- Model_Mantissa --
4078 --------------------
4080 when Attribute_Model_Mantissa =>
4081 Check_Floating_Point_Type_0;
4082 Set_Etype (N, Universal_Integer);
4084 -----------------
4085 -- Model_Small --
4086 -----------------
4088 when Attribute_Model_Small =>
4089 Check_Floating_Point_Type_0;
4090 Set_Etype (N, Universal_Real);
4092 -------------
4093 -- Modulus --
4094 -------------
4096 when Attribute_Modulus =>
4097 Check_E0;
4098 Check_Modular_Integer_Type;
4099 Set_Etype (N, Universal_Integer);
4101 --------------------
4102 -- Null_Parameter --
4103 --------------------
4105 when Attribute_Null_Parameter => Null_Parameter : declare
4106 Parnt : constant Node_Id := Parent (N);
4107 GParnt : constant Node_Id := Parent (Parnt);
4109 procedure Bad_Null_Parameter (Msg : String);
4110 -- Used if bad Null parameter attribute node is found. Issues
4111 -- given error message, and also sets the type to Any_Type to
4112 -- avoid blowups later on from dealing with a junk node.
4114 procedure Must_Be_Imported (Proc_Ent : Entity_Id);
4115 -- Called to check that Proc_Ent is imported subprogram
4117 ------------------------
4118 -- Bad_Null_Parameter --
4119 ------------------------
4121 procedure Bad_Null_Parameter (Msg : String) is
4122 begin
4123 Error_Msg_N (Msg, N);
4124 Set_Etype (N, Any_Type);
4125 end Bad_Null_Parameter;
4127 ----------------------
4128 -- Must_Be_Imported --
4129 ----------------------
4131 procedure Must_Be_Imported (Proc_Ent : Entity_Id) is
4132 Pent : constant Entity_Id := Ultimate_Alias (Proc_Ent);
4134 begin
4135 -- Ignore check if procedure not frozen yet (we will get
4136 -- another chance when the default parameter is reanalyzed)
4138 if not Is_Frozen (Pent) then
4139 return;
4141 elsif not Is_Imported (Pent) then
4142 Bad_Null_Parameter
4143 ("Null_Parameter can only be used with imported subprogram");
4145 else
4146 return;
4147 end if;
4148 end Must_Be_Imported;
4150 -- Start of processing for Null_Parameter
4152 begin
4153 Check_Type;
4154 Check_E0;
4155 Set_Etype (N, P_Type);
4157 -- Case of attribute used as default expression
4159 if Nkind (Parnt) = N_Parameter_Specification then
4160 Must_Be_Imported (Defining_Entity (GParnt));
4162 -- Case of attribute used as actual for subprogram (positional)
4164 elsif Nkind (Parnt) in N_Subprogram_Call
4165 and then Is_Entity_Name (Name (Parnt))
4166 then
4167 Must_Be_Imported (Entity (Name (Parnt)));
4169 -- Case of attribute used as actual for subprogram (named)
4171 elsif Nkind (Parnt) = N_Parameter_Association
4172 and then Nkind (GParnt) in N_Subprogram_Call
4173 and then Is_Entity_Name (Name (GParnt))
4174 then
4175 Must_Be_Imported (Entity (Name (GParnt)));
4177 -- Not an allowed case
4179 else
4180 Bad_Null_Parameter
4181 ("Null_Parameter must be actual or default parameter");
4182 end if;
4183 end Null_Parameter;
4185 -----------------
4186 -- Object_Size --
4187 -----------------
4189 when Attribute_Object_Size =>
4190 Check_E0;
4191 Check_Type;
4192 Check_Not_Incomplete_Type;
4193 Set_Etype (N, Universal_Integer);
4195 ---------
4196 -- Old --
4197 ---------
4199 when Attribute_Old => Old : declare
4200 CS : Entity_Id;
4201 -- The enclosing scope, excluding loops for quantified expressions.
4202 -- During analysis, it is the postcondition subprogram. During
4203 -- pre-analysis, it is the scope of the subprogram declaration.
4205 Prag : Node_Id;
4206 -- During pre-analysis, Prag is the enclosing pragma node if any
4208 begin
4209 -- Find enclosing scopes, excluding loops
4211 CS := Current_Scope;
4212 while Ekind (CS) = E_Loop loop
4213 CS := Scope (CS);
4214 end loop;
4216 -- If we are in Spec_Expression mode, this should be the prescan of
4217 -- the postcondition (or contract case, or test case) pragma.
4219 if In_Spec_Expression then
4221 -- Check in postcondition, Test_Case or Contract_Cases
4223 Prag := N;
4224 while Present (Prag)
4225 and then not Nkind_In (Prag, N_Pragma,
4226 N_Function_Specification,
4227 N_Procedure_Specification,
4228 N_Aspect_Specification,
4229 N_Subprogram_Body)
4230 loop
4231 Prag := Parent (Prag);
4232 end loop;
4234 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4235 -- corresponding pragma. Do not issue errors when analyzing the
4236 -- aspect.
4238 if Nkind (Prag) = N_Aspect_Specification then
4239 null;
4241 elsif Nkind (Prag) /= N_Pragma then
4242 Error_Attr ("% attribute can only appear in postcondition", P);
4244 elsif Get_Pragma_Id (Prag) = Pragma_Test_Case then
4245 declare
4246 Arg_Ens : constant Node_Id :=
4247 Get_Ensures_From_CTC_Pragma (Prag);
4248 Arg : Node_Id;
4250 begin
4251 Arg := N;
4252 while Arg /= Prag and then Arg /= Arg_Ens loop
4253 Arg := Parent (Arg);
4254 end loop;
4256 if Arg /= Arg_Ens then
4257 Error_Attr ("% attribute misplaced inside test case", P);
4258 end if;
4259 end;
4261 elsif Get_Pragma_Id (Prag) = Pragma_Contract_Cases then
4262 declare
4263 Aggr : constant Node_Id :=
4264 Expression (First (Pragma_Argument_Associations (Prag)));
4265 Arg : Node_Id;
4267 begin
4268 Arg := N;
4269 while Arg /= Prag and then Parent (Parent (Arg)) /= Aggr loop
4270 Arg := Parent (Arg);
4271 end loop;
4273 -- At this point, Parent (Arg) should be a component
4274 -- association. Attribute Result is only allowed in
4275 -- the expression part of this association.
4277 if Nkind (Parent (Arg)) /= N_Component_Association
4278 or else Arg /= Expression (Parent (Arg))
4279 then
4280 Error_Attr
4281 ("% attribute misplaced inside contract cases", P);
4282 end if;
4283 end;
4285 elsif Get_Pragma_Id (Prag) /= Pragma_Postcondition then
4286 Error_Attr ("% attribute can only appear in postcondition", P);
4287 end if;
4289 -- Body case, where we must be inside a generated _Postcondition
4290 -- procedure, or else the attribute use is definitely misplaced. The
4291 -- postcondition itself may have generated transient scopes, and is
4292 -- not necessarily the current one.
4294 else
4295 while Present (CS) and then CS /= Standard_Standard loop
4296 if Chars (CS) = Name_uPostconditions then
4297 exit;
4298 else
4299 CS := Scope (CS);
4300 end if;
4301 end loop;
4303 if Chars (CS) /= Name_uPostconditions then
4304 Error_Attr ("% attribute can only appear in postcondition", P);
4305 end if;
4306 end if;
4308 -- If the attribute reference is generated for a Requires clause,
4309 -- then no expressions follow. Otherwise it is a primary, in which
4310 -- case, if expressions follow, the attribute reference must be
4311 -- an indexable object, so rewrite the node accordingly.
4313 if Present (E1) then
4314 Rewrite (N,
4315 Make_Indexed_Component (Loc,
4316 Prefix =>
4317 Make_Attribute_Reference (Loc,
4318 Prefix => Relocate_Node (Prefix (N)),
4319 Attribute_Name => Name_Old),
4320 Expressions => Expressions (N)));
4322 Analyze (N);
4323 return;
4324 end if;
4326 Check_E0;
4328 -- Prefix has not been analyzed yet, and its full analysis will
4329 -- take place during expansion (see below).
4331 Preanalyze_And_Resolve (P);
4332 P_Type := Etype (P);
4333 Set_Etype (N, P_Type);
4335 if Is_Limited_Type (P_Type) then
4336 Error_Attr ("attribute % cannot apply to limited objects", P);
4337 end if;
4339 if Is_Entity_Name (P)
4340 and then Is_Constant_Object (Entity (P))
4341 then
4342 Error_Msg_N
4343 ("??attribute Old applied to constant has no effect", P);
4344 end if;
4346 -- The attribute appears within a pre/postcondition, but refers to
4347 -- an entity in the enclosing subprogram. If it is a component of
4348 -- a formal its expansion might generate actual subtypes that may
4349 -- be referenced in an inner context, and which must be elaborated
4350 -- within the subprogram itself. If the prefix includes a function
4351 -- call it may involve finalization actions that should only be
4352 -- inserted when the attribute has been rewritten as a declarations.
4353 -- As a result, if the prefix is not a simple name we create
4354 -- a declaration for it now, and insert it at the start of the
4355 -- enclosing subprogram. This is properly an expansion activity
4356 -- but it has to be performed now to prevent out-of-order issues.
4358 -- This expansion is both harmful and not needed in SPARK mode, since
4359 -- the formal verification backend relies on the types of nodes
4360 -- (hence is not robust w.r.t. a change to base type here), and does
4361 -- not suffer from the out-of-order issue described above. Thus, this
4362 -- expansion is skipped in SPARK mode.
4364 if not Is_Entity_Name (P) and then not SPARK_Mode then
4365 P_Type := Base_Type (P_Type);
4366 Set_Etype (N, P_Type);
4367 Set_Etype (P, P_Type);
4368 Analyze_Dimension (N);
4369 Expand (N);
4370 end if;
4371 end Old;
4373 ----------------------
4374 -- Overlaps_Storage --
4375 ----------------------
4377 when Attribute_Overlaps_Storage =>
4378 Check_E1;
4380 -- Both arguments must be objects of any type
4382 Analyze_And_Resolve (P);
4383 Analyze_And_Resolve (E1);
4384 Check_Object_Reference (P);
4385 Check_Object_Reference (E1);
4386 Set_Etype (N, Standard_Boolean);
4388 ------------
4389 -- Output --
4390 ------------
4392 when Attribute_Output =>
4393 Check_E2;
4394 Check_Stream_Attribute (TSS_Stream_Output);
4395 Set_Etype (N, Standard_Void_Type);
4396 Resolve (N, Standard_Void_Type);
4398 ------------------
4399 -- Partition_ID --
4400 ------------------
4402 when Attribute_Partition_ID => Partition_Id :
4403 begin
4404 Check_E0;
4406 if P_Type /= Any_Type then
4407 if not Is_Library_Level_Entity (Entity (P)) then
4408 Error_Attr_P
4409 ("prefix of % attribute must be library-level entity");
4411 -- The defining entity of prefix should not be declared inside a
4412 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
4414 elsif Is_Entity_Name (P)
4415 and then Is_Pure (Entity (P))
4416 then
4417 Error_Attr_P ("prefix of% attribute must not be declared pure");
4418 end if;
4419 end if;
4421 Set_Etype (N, Universal_Integer);
4422 end Partition_Id;
4424 -------------------------
4425 -- Passed_By_Reference --
4426 -------------------------
4428 when Attribute_Passed_By_Reference =>
4429 Check_E0;
4430 Check_Type;
4431 Set_Etype (N, Standard_Boolean);
4433 ------------------
4434 -- Pool_Address --
4435 ------------------
4437 when Attribute_Pool_Address =>
4438 Check_E0;
4439 Set_Etype (N, RTE (RE_Address));
4441 ---------
4442 -- Pos --
4443 ---------
4445 when Attribute_Pos =>
4446 Check_Discrete_Type;
4447 Check_E1;
4449 if Is_Boolean_Type (P_Type) then
4450 Error_Msg_Name_1 := Aname;
4451 Error_Msg_Name_2 := Chars (P_Type);
4452 Check_SPARK_Restriction
4453 ("attribute% is not allowed for type%", P);
4454 end if;
4456 Resolve (E1, P_Base_Type);
4457 Set_Etype (N, Universal_Integer);
4459 --------------
4460 -- Position --
4461 --------------
4463 when Attribute_Position =>
4464 Check_Component;
4465 Set_Etype (N, Universal_Integer);
4467 ----------
4468 -- Pred --
4469 ----------
4471 when Attribute_Pred =>
4472 Check_Scalar_Type;
4473 Check_E1;
4475 if Is_Real_Type (P_Type) or else Is_Boolean_Type (P_Type) then
4476 Error_Msg_Name_1 := Aname;
4477 Error_Msg_Name_2 := Chars (P_Type);
4478 Check_SPARK_Restriction
4479 ("attribute% is not allowed for type%", P);
4480 end if;
4482 Resolve (E1, P_Base_Type);
4483 Set_Etype (N, P_Base_Type);
4485 -- Nothing to do for real type case
4487 if Is_Real_Type (P_Type) then
4488 null;
4490 -- If not modular type, test for overflow check required
4492 else
4493 if not Is_Modular_Integer_Type (P_Type)
4494 and then not Range_Checks_Suppressed (P_Base_Type)
4495 then
4496 Enable_Range_Check (E1);
4497 end if;
4498 end if;
4500 --------------
4501 -- Priority --
4502 --------------
4504 -- Ada 2005 (AI-327): Dynamic ceiling priorities
4506 when Attribute_Priority =>
4507 if Ada_Version < Ada_2005 then
4508 Error_Attr ("% attribute is allowed only in Ada 2005 mode", P);
4509 end if;
4511 Check_E0;
4513 -- The prefix must be a protected object (AARM D.5.2 (2/2))
4515 Analyze (P);
4517 if Is_Protected_Type (Etype (P))
4518 or else (Is_Access_Type (Etype (P))
4519 and then Is_Protected_Type (Designated_Type (Etype (P))))
4520 then
4521 Resolve (P, Etype (P));
4522 else
4523 Error_Attr_P ("prefix of % attribute must be a protected object");
4524 end if;
4526 Set_Etype (N, Standard_Integer);
4528 -- Must be called from within a protected procedure or entry of the
4529 -- protected object.
4531 declare
4532 S : Entity_Id;
4534 begin
4535 S := Current_Scope;
4536 while S /= Etype (P)
4537 and then S /= Standard_Standard
4538 loop
4539 S := Scope (S);
4540 end loop;
4542 if S = Standard_Standard then
4543 Error_Attr ("the attribute % is only allowed inside protected "
4544 & "operations", P);
4545 end if;
4546 end;
4548 Validate_Non_Static_Attribute_Function_Call;
4550 -----------
4551 -- Range --
4552 -----------
4554 when Attribute_Range =>
4555 Check_Array_Or_Scalar_Type;
4556 Bad_Attribute_For_Predicate;
4558 if Ada_Version = Ada_83
4559 and then Is_Scalar_Type (P_Type)
4560 and then Comes_From_Source (N)
4561 then
4562 Error_Attr
4563 ("(Ada 83) % attribute not allowed for scalar type", P);
4564 end if;
4566 ------------
4567 -- Result --
4568 ------------
4570 when Attribute_Result => Result : declare
4571 CS : Entity_Id;
4572 -- The enclosing scope, excluding loops for quantified expressions
4574 PS : Entity_Id;
4575 -- During analysis, CS is the postcondition subprogram and PS the
4576 -- source subprogram to which the postcondition applies. During
4577 -- pre-analysis, CS is the scope of the subprogram declaration.
4579 Prag : Node_Id;
4580 -- During pre-analysis, Prag is the enclosing pragma node if any
4582 begin
4583 -- Find the proper enclosing scope
4585 CS := Current_Scope;
4586 while Present (CS) loop
4588 -- Skip generated loops
4590 if Ekind (CS) = E_Loop then
4591 CS := Scope (CS);
4593 -- Skip the special _Parent scope generated to capture references
4594 -- to formals during the process of subprogram inlining.
4596 elsif Ekind (CS) = E_Function
4597 and then Chars (CS) = Name_uParent
4598 then
4599 CS := Scope (CS);
4600 else
4601 exit;
4602 end if;
4603 end loop;
4605 PS := Scope (CS);
4607 -- If the enclosing subprogram is always inlined, the enclosing
4608 -- postcondition will not be propagated to the expanded call.
4610 if not In_Spec_Expression
4611 and then Has_Pragma_Inline_Always (PS)
4612 and then Warn_On_Redundant_Constructs
4613 then
4614 Error_Msg_N
4615 ("postconditions on inlined functions not enforced?r?", N);
4616 end if;
4618 -- If we are in the scope of a function and in Spec_Expression mode,
4619 -- this is likely the prescan of the postcondition (or contract case,
4620 -- or test case) pragma, and we just set the proper type. If there is
4621 -- an error it will be caught when the real Analyze call is done.
4623 if Ekind (CS) = E_Function
4624 and then In_Spec_Expression
4625 then
4626 -- Check OK prefix
4628 if Chars (CS) /= Chars (P) then
4629 Error_Msg_Name_1 := Name_Result;
4631 Error_Msg_NE
4632 ("incorrect prefix for % attribute, expected &", P, CS);
4633 Error_Attr;
4634 end if;
4636 -- Check in postcondition, Test_Case or Contract_Cases of function
4638 Prag := N;
4639 while Present (Prag)
4640 and then not Nkind_In (Prag, N_Pragma,
4641 N_Function_Specification,
4642 N_Aspect_Specification,
4643 N_Subprogram_Body)
4644 loop
4645 Prag := Parent (Prag);
4646 end loop;
4648 -- In ASIS mode, the aspect itself is analyzed, in addition to the
4649 -- corresponding pragma. Do not issue errors when analyzing the
4650 -- aspect.
4652 if Nkind (Prag) = N_Aspect_Specification then
4653 null;
4655 elsif Nkind (Prag) /= N_Pragma then
4656 Error_Attr
4657 ("% attribute can only appear in postcondition of function",
4660 elsif Get_Pragma_Id (Prag) = Pragma_Test_Case then
4661 declare
4662 Arg_Ens : constant Node_Id :=
4663 Get_Ensures_From_CTC_Pragma (Prag);
4664 Arg : Node_Id;
4666 begin
4667 Arg := N;
4668 while Arg /= Prag and then Arg /= Arg_Ens loop
4669 Arg := Parent (Arg);
4670 end loop;
4672 if Arg /= Arg_Ens then
4673 Error_Attr ("% attribute misplaced inside test case", P);
4674 end if;
4675 end;
4677 elsif Get_Pragma_Id (Prag) = Pragma_Contract_Cases then
4678 declare
4679 Aggr : constant Node_Id :=
4680 Expression (First (Pragma_Argument_Associations (Prag)));
4681 Arg : Node_Id;
4683 begin
4684 Arg := N;
4685 while Arg /= Prag and then Parent (Parent (Arg)) /= Aggr loop
4686 Arg := Parent (Arg);
4687 end loop;
4689 -- At this point, Parent (Arg) should be a component
4690 -- association. Attribute Result is only allowed in
4691 -- the expression part of this association.
4693 if Nkind (Parent (Arg)) /= N_Component_Association
4694 or else Arg /= Expression (Parent (Arg))
4695 then
4696 Error_Attr
4697 ("% attribute misplaced inside contract cases", P);
4698 end if;
4699 end;
4701 elsif Get_Pragma_Id (Prag) /= Pragma_Postcondition then
4702 Error_Attr
4703 ("% attribute can only appear in postcondition of function",
4705 end if;
4707 -- The attribute reference is a primary. If expressions follow,
4708 -- the attribute reference is really an indexable object, so
4709 -- rewrite and analyze as an indexed component.
4711 if Present (E1) then
4712 Rewrite (N,
4713 Make_Indexed_Component (Loc,
4714 Prefix =>
4715 Make_Attribute_Reference (Loc,
4716 Prefix => Relocate_Node (Prefix (N)),
4717 Attribute_Name => Name_Result),
4718 Expressions => Expressions (N)));
4719 Analyze (N);
4720 return;
4721 end if;
4723 Set_Etype (N, Etype (CS));
4725 -- If several functions with that name are visible,
4726 -- the intended one is the current scope.
4728 if Is_Overloaded (P) then
4729 Set_Entity (P, CS);
4730 Set_Is_Overloaded (P, False);
4731 end if;
4733 -- Body case, where we must be inside a generated _Postcondition
4734 -- procedure, and the prefix must be on the scope stack, or else the
4735 -- attribute use is definitely misplaced. The postcondition itself
4736 -- may have generated transient scopes, and is not necessarily the
4737 -- current one.
4739 else
4740 while Present (CS) and then CS /= Standard_Standard loop
4741 if Chars (CS) = Name_uPostconditions then
4742 exit;
4743 else
4744 CS := Scope (CS);
4745 end if;
4746 end loop;
4748 PS := Scope (CS);
4750 if Chars (CS) = Name_uPostconditions
4751 and then Ekind (PS) = E_Function
4752 then
4753 -- Check OK prefix
4755 if Nkind_In (P, N_Identifier, N_Operator_Symbol)
4756 and then Chars (P) = Chars (PS)
4757 then
4758 null;
4760 -- Within an instance, the prefix designates the local renaming
4761 -- of the original generic.
4763 elsif Is_Entity_Name (P)
4764 and then Ekind (Entity (P)) = E_Function
4765 and then Present (Alias (Entity (P)))
4766 and then Chars (Alias (Entity (P))) = Chars (PS)
4767 then
4768 null;
4770 else
4771 Error_Msg_NE
4772 ("incorrect prefix for % attribute, expected &", P, PS);
4773 Error_Attr;
4774 end if;
4776 Rewrite (N, Make_Identifier (Sloc (N), Name_uResult));
4777 Analyze_And_Resolve (N, Etype (PS));
4779 else
4780 Error_Attr
4781 ("% attribute can only appear in postcondition of function",
4783 end if;
4784 end if;
4785 end Result;
4787 ------------------
4788 -- Range_Length --
4789 ------------------
4791 when Attribute_Range_Length =>
4792 Check_E0;
4793 Check_Discrete_Type;
4794 Set_Etype (N, Universal_Integer);
4796 ----------
4797 -- Read --
4798 ----------
4800 when Attribute_Read =>
4801 Check_E2;
4802 Check_Stream_Attribute (TSS_Stream_Read);
4803 Set_Etype (N, Standard_Void_Type);
4804 Resolve (N, Standard_Void_Type);
4805 Note_Possible_Modification (E2, Sure => True);
4807 ---------
4808 -- Ref --
4809 ---------
4811 when Attribute_Ref =>
4812 Check_E1;
4813 Analyze (P);
4815 if Nkind (P) /= N_Expanded_Name
4816 or else not Is_RTE (P_Type, RE_Address)
4817 then
4818 Error_Attr_P ("prefix of % attribute must be System.Address");
4819 end if;
4821 Analyze_And_Resolve (E1, Any_Integer);
4822 Set_Etype (N, RTE (RE_Address));
4824 ---------------
4825 -- Remainder --
4826 ---------------
4828 when Attribute_Remainder =>
4829 Check_Floating_Point_Type_2;
4830 Set_Etype (N, P_Base_Type);
4831 Resolve (E1, P_Base_Type);
4832 Resolve (E2, P_Base_Type);
4834 ---------------------
4835 -- Restriction_Set --
4836 ---------------------
4838 when Attribute_Restriction_Set => Restriction_Set : declare
4839 R : Restriction_Id;
4840 U : Node_Id;
4841 Unam : Unit_Name_Type;
4843 procedure Set_Result (B : Boolean);
4844 -- Replace restriction node by static constant False or True,
4845 -- depending on the value of B.
4847 ----------------
4848 -- Set_Result --
4849 ----------------
4851 procedure Set_Result (B : Boolean) is
4852 begin
4853 if B then
4854 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4855 else
4856 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4857 end if;
4859 Set_Is_Static_Expression (N);
4860 end Set_Result;
4862 -- Start of processing for Restriction_Set
4864 begin
4865 Check_E1;
4866 Analyze (P);
4868 if Nkind (P) /= N_Identifier or else Chars (P) /= Name_System then
4869 Set_Result (False);
4870 Error_Attr_P ("prefix of % attribute must be System");
4871 end if;
4873 -- No_Dependence case
4875 if Nkind (E1) = N_Parameter_Association then
4876 pragma Assert (Chars (Selector_Name (E1)) = Name_No_Dependence);
4877 U := Explicit_Actual_Parameter (E1);
4879 if not OK_No_Dependence_Unit_Name (U) then
4880 Set_Result (False);
4881 Error_Attr;
4882 end if;
4884 -- See if there is an entry already in the table. That's the
4885 -- case in which we can return True.
4887 for J in No_Dependences.First .. No_Dependences.Last loop
4888 if Designate_Same_Unit (U, No_Dependences.Table (J).Unit)
4889 and then No_Dependences.Table (J).Warn = False
4890 then
4891 Set_Result (True);
4892 return;
4893 end if;
4894 end loop;
4896 -- If not in the No_Dependence table, result is False
4898 Set_Result (False);
4900 -- In this case, we must ensure that the binder will reject any
4901 -- other unit in the partition that sets No_Dependence for this
4902 -- unit. We do that by making an entry in the special table kept
4903 -- for this purpose (if the entry is not there already).
4905 Unam := Get_Spec_Name (Get_Unit_Name (U));
4907 for J in Restriction_Set_Dependences.First ..
4908 Restriction_Set_Dependences.Last
4909 loop
4910 if Restriction_Set_Dependences.Table (J) = Unam then
4911 return;
4912 end if;
4913 end loop;
4915 Restriction_Set_Dependences.Append (Unam);
4917 -- Normal restriction case
4919 else
4920 if Nkind (E1) /= N_Identifier then
4921 Set_Result (False);
4922 Error_Attr ("attribute % requires restriction identifier", E1);
4924 else
4925 R := Get_Restriction_Id (Process_Restriction_Synonyms (E1));
4927 if R = Not_A_Restriction_Id then
4928 Set_Result (False);
4929 Error_Msg_Node_1 := E1;
4930 Error_Attr ("invalid restriction identifier &", E1);
4932 elsif R not in Partition_Boolean_Restrictions then
4933 Set_Result (False);
4934 Error_Msg_Node_1 := E1;
4935 Error_Attr
4936 ("& is not a boolean partition-wide restriction", E1);
4937 end if;
4939 if Restriction_Active (R) then
4940 Set_Result (True);
4941 else
4942 Check_Restriction (R, N);
4943 Set_Result (False);
4944 end if;
4945 end if;
4946 end if;
4947 end Restriction_Set;
4949 -----------
4950 -- Round --
4951 -----------
4953 when Attribute_Round =>
4954 Check_E1;
4955 Check_Decimal_Fixed_Point_Type;
4956 Set_Etype (N, P_Base_Type);
4958 -- Because the context is universal_real (3.5.10(12)) it is a
4959 -- legal context for a universal fixed expression. This is the
4960 -- only attribute whose functional description involves U_R.
4962 if Etype (E1) = Universal_Fixed then
4963 declare
4964 Conv : constant Node_Id := Make_Type_Conversion (Loc,
4965 Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc),
4966 Expression => Relocate_Node (E1));
4968 begin
4969 Rewrite (E1, Conv);
4970 Analyze (E1);
4971 end;
4972 end if;
4974 Resolve (E1, Any_Real);
4976 --------------
4977 -- Rounding --
4978 --------------
4980 when Attribute_Rounding =>
4981 Check_Floating_Point_Type_1;
4982 Set_Etype (N, P_Base_Type);
4983 Resolve (E1, P_Base_Type);
4985 ---------------
4986 -- Safe_Emax --
4987 ---------------
4989 when Attribute_Safe_Emax =>
4990 Check_Floating_Point_Type_0;
4991 Set_Etype (N, Universal_Integer);
4993 ----------------
4994 -- Safe_First --
4995 ----------------
4997 when Attribute_Safe_First =>
4998 Check_Floating_Point_Type_0;
4999 Set_Etype (N, Universal_Real);
5001 ----------------
5002 -- Safe_Large --
5003 ----------------
5005 when Attribute_Safe_Large =>
5006 Check_E0;
5007 Check_Real_Type;
5008 Set_Etype (N, Universal_Real);
5010 ---------------
5011 -- Safe_Last --
5012 ---------------
5014 when Attribute_Safe_Last =>
5015 Check_Floating_Point_Type_0;
5016 Set_Etype (N, Universal_Real);
5018 ----------------
5019 -- Safe_Small --
5020 ----------------
5022 when Attribute_Safe_Small =>
5023 Check_E0;
5024 Check_Real_Type;
5025 Set_Etype (N, Universal_Real);
5027 ------------------
5028 -- Same_Storage --
5029 ------------------
5031 when Attribute_Same_Storage =>
5032 Check_Ada_2012_Attribute;
5033 Check_E1;
5035 -- The arguments must be objects of any type
5037 Analyze_And_Resolve (P);
5038 Analyze_And_Resolve (E1);
5039 Check_Object_Reference (P);
5040 Check_Object_Reference (E1);
5041 Set_Etype (N, Standard_Boolean);
5043 --------------------------
5044 -- Scalar_Storage_Order --
5045 --------------------------
5047 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order :
5048 begin
5049 Check_E0;
5050 Check_Type;
5052 if not Is_Record_Type (P_Type) or else Is_Array_Type (P_Type) then
5053 Error_Attr_P
5054 ("prefix of % attribute must be record or array type");
5055 end if;
5057 if Bytes_Big_Endian xor Reverse_Storage_Order (P_Type) then
5058 Rewrite (N,
5059 New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
5060 else
5061 Rewrite (N,
5062 New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
5063 end if;
5065 Set_Etype (N, RTE (RE_Bit_Order));
5066 Resolve (N);
5068 -- Reset incorrect indication of staticness
5070 Set_Is_Static_Expression (N, False);
5071 end Scalar_Storage_Order;
5073 -----------
5074 -- Scale --
5075 -----------
5077 when Attribute_Scale =>
5078 Check_E0;
5079 Check_Decimal_Fixed_Point_Type;
5080 Set_Etype (N, Universal_Integer);
5082 -------------
5083 -- Scaling --
5084 -------------
5086 when Attribute_Scaling =>
5087 Check_Floating_Point_Type_2;
5088 Set_Etype (N, P_Base_Type);
5089 Resolve (E1, P_Base_Type);
5091 ------------------
5092 -- Signed_Zeros --
5093 ------------------
5095 when Attribute_Signed_Zeros =>
5096 Check_Floating_Point_Type_0;
5097 Set_Etype (N, Standard_Boolean);
5099 ----------
5100 -- Size --
5101 ----------
5103 when Attribute_Size | Attribute_VADS_Size => Size :
5104 begin
5105 Check_E0;
5107 -- If prefix is parameterless function call, rewrite and resolve
5108 -- as such.
5110 if Is_Entity_Name (P)
5111 and then Ekind (Entity (P)) = E_Function
5112 then
5113 Resolve (P);
5115 -- Similar processing for a protected function call
5117 elsif Nkind (P) = N_Selected_Component
5118 and then Ekind (Entity (Selector_Name (P))) = E_Function
5119 then
5120 Resolve (P);
5121 end if;
5123 if Is_Object_Reference (P) then
5124 Check_Object_Reference (P);
5126 elsif Is_Entity_Name (P)
5127 and then (Is_Type (Entity (P))
5128 or else Ekind (Entity (P)) = E_Enumeration_Literal)
5129 then
5130 null;
5132 elsif Nkind (P) = N_Type_Conversion
5133 and then not Comes_From_Source (P)
5134 then
5135 null;
5137 -- Some other compilers allow dubious use of X'???'Size
5139 elsif Relaxed_RM_Semantics
5140 and then Nkind (P) = N_Attribute_Reference
5141 then
5142 null;
5144 else
5145 Error_Attr_P ("invalid prefix for % attribute");
5146 end if;
5148 Check_Not_Incomplete_Type;
5149 Check_Not_CPP_Type;
5150 Set_Etype (N, Universal_Integer);
5151 end Size;
5153 -----------
5154 -- Small --
5155 -----------
5157 when Attribute_Small =>
5158 Check_E0;
5159 Check_Real_Type;
5160 Set_Etype (N, Universal_Real);
5162 ------------------
5163 -- Storage_Pool --
5164 ------------------
5166 when Attribute_Storage_Pool |
5167 Attribute_Simple_Storage_Pool => Storage_Pool :
5168 begin
5169 Check_E0;
5171 if Is_Access_Type (P_Type) then
5172 if Ekind (P_Type) = E_Access_Subprogram_Type then
5173 Error_Attr_P
5174 ("cannot use % attribute for access-to-subprogram type");
5175 end if;
5177 -- Set appropriate entity
5179 if Present (Associated_Storage_Pool (Root_Type (P_Type))) then
5180 Set_Entity (N, Associated_Storage_Pool (Root_Type (P_Type)));
5181 else
5182 Set_Entity (N, RTE (RE_Global_Pool_Object));
5183 end if;
5185 if Attr_Id = Attribute_Storage_Pool then
5186 if Present (Get_Rep_Pragma (Etype (Entity (N)),
5187 Name_Simple_Storage_Pool_Type))
5188 then
5189 Error_Msg_Name_1 := Aname;
5190 Error_Msg_N ("cannot use % attribute for type with simple "
5191 & "storage pool??", N);
5192 Error_Msg_N
5193 ("\Program_Error will be raised at run time??", N);
5195 Rewrite
5196 (N, Make_Raise_Program_Error
5197 (Sloc (N), Reason => PE_Explicit_Raise));
5198 end if;
5200 Set_Etype (N, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
5202 -- In the Simple_Storage_Pool case, verify that the pool entity is
5203 -- actually of a simple storage pool type, and set the attribute's
5204 -- type to the pool object's type.
5206 else
5207 if not Present (Get_Rep_Pragma (Etype (Entity (N)),
5208 Name_Simple_Storage_Pool_Type))
5209 then
5210 Error_Attr_P
5211 ("cannot use % attribute for type without simple " &
5212 "storage pool");
5213 end if;
5215 Set_Etype (N, Etype (Entity (N)));
5216 end if;
5218 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5219 -- Storage_Pool since this attribute is not defined for such
5220 -- types (RM E.2.3(22)).
5222 Validate_Remote_Access_To_Class_Wide_Type (N);
5224 else
5225 Error_Attr_P ("prefix of % attribute must be access type");
5226 end if;
5227 end Storage_Pool;
5229 ------------------
5230 -- Storage_Size --
5231 ------------------
5233 when Attribute_Storage_Size => Storage_Size :
5234 begin
5235 Check_E0;
5237 if Is_Task_Type (P_Type) then
5238 Set_Etype (N, Universal_Integer);
5240 -- Use with tasks is an obsolescent feature
5242 Check_Restriction (No_Obsolescent_Features, P);
5244 elsif Is_Access_Type (P_Type) then
5245 if Ekind (P_Type) = E_Access_Subprogram_Type then
5246 Error_Attr_P
5247 ("cannot use % attribute for access-to-subprogram type");
5248 end if;
5250 if Is_Entity_Name (P)
5251 and then Is_Type (Entity (P))
5252 then
5253 Check_Type;
5254 Set_Etype (N, Universal_Integer);
5256 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
5257 -- Storage_Size since this attribute is not defined for
5258 -- such types (RM E.2.3(22)).
5260 Validate_Remote_Access_To_Class_Wide_Type (N);
5262 -- The prefix is allowed to be an implicit dereference of an
5263 -- access value designating a task.
5265 else
5266 Check_Task_Prefix;
5267 Set_Etype (N, Universal_Integer);
5268 end if;
5270 else
5271 Error_Attr_P ("prefix of % attribute must be access or task type");
5272 end if;
5273 end Storage_Size;
5275 ------------------
5276 -- Storage_Unit --
5277 ------------------
5279 when Attribute_Storage_Unit =>
5280 Standard_Attribute (Ttypes.System_Storage_Unit);
5282 -----------------
5283 -- Stream_Size --
5284 -----------------
5286 when Attribute_Stream_Size =>
5287 Check_E0;
5288 Check_Type;
5290 if Is_Entity_Name (P)
5291 and then Is_Elementary_Type (Entity (P))
5292 then
5293 Set_Etype (N, Universal_Integer);
5294 else
5295 Error_Attr_P ("invalid prefix for % attribute");
5296 end if;
5298 ---------------
5299 -- Stub_Type --
5300 ---------------
5302 when Attribute_Stub_Type =>
5303 Check_Type;
5304 Check_E0;
5306 if Is_Remote_Access_To_Class_Wide_Type (Base_Type (P_Type)) then
5308 -- For a real RACW [sub]type, use corresponding stub type
5310 if not Is_Generic_Type (P_Type) then
5311 Rewrite (N,
5312 New_Occurrence_Of
5313 (Corresponding_Stub_Type (Base_Type (P_Type)), Loc));
5315 -- For a generic type (that has been marked as an RACW using the
5316 -- Remote_Access_Type aspect or pragma), use a generic RACW stub
5317 -- type. Note that if the actual is not a remote access type, the
5318 -- instantiation will fail.
5320 else
5321 -- Note: we go to the underlying type here because the view
5322 -- returned by RTE (RE_RACW_Stub_Type) might be incomplete.
5324 Rewrite (N,
5325 New_Occurrence_Of
5326 (Underlying_Type (RTE (RE_RACW_Stub_Type)), Loc));
5327 end if;
5329 else
5330 Error_Attr_P
5331 ("prefix of% attribute must be remote access to classwide");
5332 end if;
5334 ----------
5335 -- Succ --
5336 ----------
5338 when Attribute_Succ =>
5339 Check_Scalar_Type;
5340 Check_E1;
5342 if Is_Real_Type (P_Type) or else Is_Boolean_Type (P_Type) then
5343 Error_Msg_Name_1 := Aname;
5344 Error_Msg_Name_2 := Chars (P_Type);
5345 Check_SPARK_Restriction
5346 ("attribute% is not allowed for type%", P);
5347 end if;
5349 Resolve (E1, P_Base_Type);
5350 Set_Etype (N, P_Base_Type);
5352 -- Nothing to do for real type case
5354 if Is_Real_Type (P_Type) then
5355 null;
5357 -- If not modular type, test for overflow check required
5359 else
5360 if not Is_Modular_Integer_Type (P_Type)
5361 and then not Range_Checks_Suppressed (P_Base_Type)
5362 then
5363 Enable_Range_Check (E1);
5364 end if;
5365 end if;
5367 --------------------------------
5368 -- System_Allocator_Alignment --
5369 --------------------------------
5371 when Attribute_System_Allocator_Alignment =>
5372 Standard_Attribute (Ttypes.System_Allocator_Alignment);
5374 ---------
5375 -- Tag --
5376 ---------
5378 when Attribute_Tag => Tag :
5379 begin
5380 Check_E0;
5381 Check_Dereference;
5383 if not Is_Tagged_Type (P_Type) then
5384 Error_Attr_P ("prefix of % attribute must be tagged");
5386 -- Next test does not apply to generated code why not, and what does
5387 -- the illegal reference mean???
5389 elsif Is_Object_Reference (P)
5390 and then not Is_Class_Wide_Type (P_Type)
5391 and then Comes_From_Source (N)
5392 then
5393 Error_Attr_P
5394 ("% attribute can only be applied to objects " &
5395 "of class - wide type");
5396 end if;
5398 -- The prefix cannot be an incomplete type. However, references to
5399 -- 'Tag can be generated when expanding interface conversions, and
5400 -- this is legal.
5402 if Comes_From_Source (N) then
5403 Check_Not_Incomplete_Type;
5404 end if;
5406 -- Set appropriate type
5408 Set_Etype (N, RTE (RE_Tag));
5409 end Tag;
5411 -----------------
5412 -- Target_Name --
5413 -----------------
5415 when Attribute_Target_Name => Target_Name : declare
5416 TN : constant String := Sdefault.Target_Name.all;
5417 TL : Natural;
5419 begin
5420 Check_Standard_Prefix;
5422 TL := TN'Last;
5424 if TN (TL) = '/' or else TN (TL) = '\' then
5425 TL := TL - 1;
5426 end if;
5428 Rewrite (N,
5429 Make_String_Literal (Loc,
5430 Strval => TN (TN'First .. TL)));
5431 Analyze_And_Resolve (N, Standard_String);
5432 end Target_Name;
5434 ----------------
5435 -- Terminated --
5436 ----------------
5438 when Attribute_Terminated =>
5439 Check_E0;
5440 Set_Etype (N, Standard_Boolean);
5441 Check_Task_Prefix;
5443 ----------------
5444 -- To_Address --
5445 ----------------
5447 when Attribute_To_Address =>
5448 Check_E1;
5449 Analyze (P);
5451 if Nkind (P) /= N_Identifier or else Chars (P) /= Name_System then
5452 Error_Attr_P ("prefix of % attribute must be System");
5453 end if;
5455 Generate_Reference (RTE (RE_Address), P);
5456 Analyze_And_Resolve (E1, Any_Integer);
5457 Set_Etype (N, RTE (RE_Address));
5459 ------------
5460 -- To_Any --
5461 ------------
5463 when Attribute_To_Any =>
5464 Check_E1;
5465 Check_PolyORB_Attribute;
5466 Set_Etype (N, RTE (RE_Any));
5468 ----------------
5469 -- Truncation --
5470 ----------------
5472 when Attribute_Truncation =>
5473 Check_Floating_Point_Type_1;
5474 Resolve (E1, P_Base_Type);
5475 Set_Etype (N, P_Base_Type);
5477 ----------------
5478 -- Type_Class --
5479 ----------------
5481 when Attribute_Type_Class =>
5482 Check_E0;
5483 Check_Type;
5484 Check_Not_Incomplete_Type;
5485 Set_Etype (N, RTE (RE_Type_Class));
5487 --------------
5488 -- TypeCode --
5489 --------------
5491 when Attribute_TypeCode =>
5492 Check_E0;
5493 Check_PolyORB_Attribute;
5494 Set_Etype (N, RTE (RE_TypeCode));
5496 --------------
5497 -- Type_Key --
5498 --------------
5500 when Attribute_Type_Key =>
5501 Check_E0;
5502 Check_Type;
5504 -- This processing belongs in Eval_Attribute ???
5506 declare
5507 function Type_Key return String_Id;
5508 -- A very preliminary implementation. For now, a signature
5509 -- consists of only the type name. This is clearly incomplete
5510 -- (e.g., adding a new field to a record type should change the
5511 -- type's Type_Key attribute).
5513 --------------
5514 -- Type_Key --
5515 --------------
5517 function Type_Key return String_Id is
5518 Full_Name : constant String_Id :=
5519 Fully_Qualified_Name_String (Entity (P));
5521 begin
5522 -- Copy all characters in Full_Name but the trailing NUL
5524 Start_String;
5525 for J in 1 .. String_Length (Full_Name) - 1 loop
5526 Store_String_Char (Get_String_Char (Full_Name, Int (J)));
5527 end loop;
5529 Store_String_Chars ("'Type_Key");
5530 return End_String;
5531 end Type_Key;
5533 begin
5534 Rewrite (N, Make_String_Literal (Loc, Type_Key));
5535 end;
5537 Analyze_And_Resolve (N, Standard_String);
5539 -----------------
5540 -- UET_Address --
5541 -----------------
5543 when Attribute_UET_Address =>
5544 Check_E0;
5545 Check_Unit_Name (P);
5546 Set_Etype (N, RTE (RE_Address));
5548 -----------------------
5549 -- Unbiased_Rounding --
5550 -----------------------
5552 when Attribute_Unbiased_Rounding =>
5553 Check_Floating_Point_Type_1;
5554 Set_Etype (N, P_Base_Type);
5555 Resolve (E1, P_Base_Type);
5557 ----------------------
5558 -- Unchecked_Access --
5559 ----------------------
5561 when Attribute_Unchecked_Access =>
5562 if Comes_From_Source (N) then
5563 Check_Restriction (No_Unchecked_Access, N);
5564 end if;
5566 Analyze_Access_Attribute;
5568 -------------------------
5569 -- Unconstrained_Array --
5570 -------------------------
5572 when Attribute_Unconstrained_Array =>
5573 Check_E0;
5574 Check_Type;
5575 Check_Not_Incomplete_Type;
5576 Set_Etype (N, Standard_Boolean);
5578 ------------------------------
5579 -- Universal_Literal_String --
5580 ------------------------------
5582 -- This is a GNAT specific attribute whose prefix must be a named
5583 -- number where the expression is either a single numeric literal,
5584 -- or a numeric literal immediately preceded by a minus sign. The
5585 -- result is equivalent to a string literal containing the text of
5586 -- the literal as it appeared in the source program with a possible
5587 -- leading minus sign.
5589 when Attribute_Universal_Literal_String => Universal_Literal_String :
5590 begin
5591 Check_E0;
5593 if not Is_Entity_Name (P)
5594 or else Ekind (Entity (P)) not in Named_Kind
5595 then
5596 Error_Attr_P ("prefix for % attribute must be named number");
5598 else
5599 declare
5600 Expr : Node_Id;
5601 Negative : Boolean;
5602 S : Source_Ptr;
5603 Src : Source_Buffer_Ptr;
5605 begin
5606 Expr := Original_Node (Expression (Parent (Entity (P))));
5608 if Nkind (Expr) = N_Op_Minus then
5609 Negative := True;
5610 Expr := Original_Node (Right_Opnd (Expr));
5611 else
5612 Negative := False;
5613 end if;
5615 if not Nkind_In (Expr, N_Integer_Literal, N_Real_Literal) then
5616 Error_Attr
5617 ("named number for % attribute must be simple literal", N);
5618 end if;
5620 -- Build string literal corresponding to source literal text
5622 Start_String;
5624 if Negative then
5625 Store_String_Char (Get_Char_Code ('-'));
5626 end if;
5628 S := Sloc (Expr);
5629 Src := Source_Text (Get_Source_File_Index (S));
5631 while Src (S) /= ';' and then Src (S) /= ' ' loop
5632 Store_String_Char (Get_Char_Code (Src (S)));
5633 S := S + 1;
5634 end loop;
5636 -- Now we rewrite the attribute with the string literal
5638 Rewrite (N,
5639 Make_String_Literal (Loc, End_String));
5640 Analyze (N);
5641 end;
5642 end if;
5643 end Universal_Literal_String;
5645 -------------------------
5646 -- Unrestricted_Access --
5647 -------------------------
5649 -- This is a GNAT specific attribute which is like Access except that
5650 -- all scope checks and checks for aliased views are omitted.
5652 when Attribute_Unrestricted_Access =>
5654 -- If from source, deal with relevant restrictions
5656 if Comes_From_Source (N) then
5657 Check_Restriction (No_Unchecked_Access, N);
5659 if Nkind (P) in N_Has_Entity
5660 and then Present (Entity (P))
5661 and then Is_Object (Entity (P))
5662 then
5663 Check_Restriction (No_Implicit_Aliasing, N);
5664 end if;
5665 end if;
5667 if Is_Entity_Name (P) then
5668 Set_Address_Taken (Entity (P));
5669 end if;
5671 Analyze_Access_Attribute;
5673 ------------
5674 -- Update --
5675 ------------
5677 when Attribute_Update => Update : declare
5678 Comps : Elist_Id := No_Elist;
5680 procedure Check_Component_Reference
5681 (Comp : Entity_Id;
5682 Typ : Entity_Id);
5683 -- Comp is a record component (possibly a discriminant) and Typ is a
5684 -- record type. Determine whether Comp is a legal component of Typ.
5685 -- Emit an error if Comp mentions a discriminant or is not a unique
5686 -- component reference in the update aggregate.
5688 -------------------------------
5689 -- Check_Component_Reference --
5690 -------------------------------
5692 procedure Check_Component_Reference
5693 (Comp : Entity_Id;
5694 Typ : Entity_Id)
5696 Comp_Name : constant Name_Id := Chars (Comp);
5698 function Is_Duplicate_Component return Boolean;
5699 -- Determine whether component Comp already appears in list Comps
5701 ----------------------------
5702 -- Is_Duplicate_Component --
5703 ----------------------------
5705 function Is_Duplicate_Component return Boolean is
5706 Comp_Elmt : Elmt_Id;
5708 begin
5709 if Present (Comps) then
5710 Comp_Elmt := First_Elmt (Comps);
5711 while Present (Comp_Elmt) loop
5712 if Chars (Node (Comp_Elmt)) = Comp_Name then
5713 return True;
5714 end if;
5716 Next_Elmt (Comp_Elmt);
5717 end loop;
5718 end if;
5720 return False;
5721 end Is_Duplicate_Component;
5723 -- Local variables
5725 Comp_Or_Discr : Entity_Id;
5727 -- Start of processing for Check_Component_Reference
5729 begin
5730 -- Find the discriminant or component whose name corresponds to
5731 -- Comp. A simple character comparison is sufficient because all
5732 -- visible names within a record type are unique.
5734 Comp_Or_Discr := First_Entity (Typ);
5735 while Present (Comp_Or_Discr) loop
5736 if Chars (Comp_Or_Discr) = Comp_Name then
5737 exit;
5738 end if;
5740 Comp_Or_Discr := Next_Entity (Comp_Or_Discr);
5741 end loop;
5743 -- Diagnose possible erroneous references
5745 if Present (Comp_Or_Discr) then
5746 if Ekind (Comp_Or_Discr) = E_Discriminant then
5747 Error_Attr
5748 ("attribute % may not modify record discriminants", Comp);
5750 else pragma Assert (Ekind (Comp_Or_Discr) = E_Component);
5751 if Is_Duplicate_Component then
5752 Error_Msg_NE ("component & already updated", Comp, Comp);
5754 -- Mark this component as processed
5756 else
5757 if No (Comps) then
5758 Comps := New_Elmt_List;
5759 end if;
5761 Append_Elmt (Comp, Comps);
5762 end if;
5763 end if;
5765 -- The update aggregate mentions an entity that does not belong to
5766 -- the record type.
5768 else
5769 Error_Msg_NE
5770 ("& is not a component of aggregate subtype", Comp, Comp);
5771 end if;
5772 end Check_Component_Reference;
5774 -- Local variables
5776 Assoc : Node_Id;
5777 Comp : Node_Id;
5779 -- Start of processing for Update
5781 begin
5782 Check_E1;
5784 if not Is_Object_Reference (P) then
5785 Error_Attr_P ("prefix of attribute % must denote an object");
5787 elsif not Is_Array_Type (P_Type)
5788 and then not Is_Record_Type (P_Type)
5789 then
5790 Error_Attr_P ("prefix of attribute % must be a record or array");
5792 elsif Is_Immutably_Limited_Type (P_Type) then
5793 Error_Attr ("prefix of attribute % cannot be limited", N);
5795 elsif Nkind (E1) /= N_Aggregate then
5796 Error_Attr ("attribute % requires component association list", N);
5797 end if;
5799 -- Inspect the update aggregate, looking at all the associations and
5800 -- choices. Perform the following checks:
5802 -- 1) Legality of "others" in all cases
5803 -- 2) Component legality for records
5805 -- The remaining checks are performed on the expanded attribute
5807 Assoc := First (Component_Associations (E1));
5808 while Present (Assoc) loop
5809 Comp := First (Choices (Assoc));
5810 while Present (Comp) loop
5811 if Nkind (Comp) = N_Others_Choice then
5812 Error_Attr
5813 ("others choice not allowed in attribute %", Comp);
5815 elsif Is_Record_Type (P_Type) then
5816 Check_Component_Reference (Comp, P_Type);
5817 end if;
5819 Next (Comp);
5820 end loop;
5822 Next (Assoc);
5823 end loop;
5825 -- The type of attribute Update is that of the prefix
5827 Set_Etype (N, P_Type);
5828 end Update;
5830 ---------
5831 -- Val --
5832 ---------
5834 when Attribute_Val => Val : declare
5835 begin
5836 Check_E1;
5837 Check_Discrete_Type;
5839 if Is_Boolean_Type (P_Type) then
5840 Error_Msg_Name_1 := Aname;
5841 Error_Msg_Name_2 := Chars (P_Type);
5842 Check_SPARK_Restriction
5843 ("attribute% is not allowed for type%", P);
5844 end if;
5846 Resolve (E1, Any_Integer);
5847 Set_Etype (N, P_Base_Type);
5849 -- Note, we need a range check in general, but we wait for the
5850 -- Resolve call to do this, since we want to let Eval_Attribute
5851 -- have a chance to find an static illegality first!
5852 end Val;
5854 -----------
5855 -- Valid --
5856 -----------
5858 when Attribute_Valid =>
5859 Check_E0;
5861 -- Ignore check for object if we have a 'Valid reference generated
5862 -- by the expanded code, since in some cases valid checks can occur
5863 -- on items that are names, but are not objects (e.g. attributes).
5865 if Comes_From_Source (N) then
5866 Check_Object_Reference (P);
5867 end if;
5869 if not Is_Scalar_Type (P_Type) then
5870 Error_Attr_P ("object for % attribute must be of scalar type");
5871 end if;
5873 -- If the attribute appears within the subtype's own predicate
5874 -- function, then issue a warning that this will cause infinite
5875 -- recursion.
5877 declare
5878 Pred_Func : constant Entity_Id := Predicate_Function (P_Type);
5880 begin
5881 if Present (Pred_Func) and then Current_Scope = Pred_Func then
5882 Error_Msg_N
5883 ("attribute Valid requires a predicate check??", N);
5884 Error_Msg_N ("\and will result in infinite recursion??", N);
5885 end if;
5886 end;
5888 Set_Etype (N, Standard_Boolean);
5890 -------------------
5891 -- Valid_Scalars --
5892 -------------------
5894 when Attribute_Valid_Scalars =>
5895 Check_E0;
5896 Check_Object_Reference (P);
5898 if No_Scalar_Parts (P_Type) then
5899 Error_Attr_P ("??attribute % always True, no scalars to check");
5900 end if;
5902 Set_Etype (N, Standard_Boolean);
5904 -----------
5905 -- Value --
5906 -----------
5908 when Attribute_Value => Value :
5909 begin
5910 Check_SPARK_Restriction_On_Attribute;
5911 Check_E1;
5912 Check_Scalar_Type;
5914 -- Case of enumeration type
5916 -- When an enumeration type appears in an attribute reference, all
5917 -- literals of the type are marked as referenced. This must only be
5918 -- done if the attribute reference appears in the current source.
5919 -- Otherwise the information on references may differ between a
5920 -- normal compilation and one that performs inlining.
5922 if Is_Enumeration_Type (P_Type)
5923 and then In_Extended_Main_Code_Unit (N)
5924 then
5925 Check_Restriction (No_Enumeration_Maps, N);
5927 -- Mark all enumeration literals as referenced, since the use of
5928 -- the Value attribute can implicitly reference any of the
5929 -- literals of the enumeration base type.
5931 declare
5932 Ent : Entity_Id := First_Literal (P_Base_Type);
5933 begin
5934 while Present (Ent) loop
5935 Set_Referenced (Ent);
5936 Next_Literal (Ent);
5937 end loop;
5938 end;
5939 end if;
5941 -- Set Etype before resolving expression because expansion of
5942 -- expression may require enclosing type. Note that the type
5943 -- returned by 'Value is the base type of the prefix type.
5945 Set_Etype (N, P_Base_Type);
5946 Validate_Non_Static_Attribute_Function_Call;
5947 end Value;
5949 ----------------
5950 -- Value_Size --
5951 ----------------
5953 when Attribute_Value_Size =>
5954 Check_E0;
5955 Check_Type;
5956 Check_Not_Incomplete_Type;
5957 Set_Etype (N, Universal_Integer);
5959 -------------
5960 -- Version --
5961 -------------
5963 when Attribute_Version =>
5964 Check_E0;
5965 Check_Program_Unit;
5966 Set_Etype (N, RTE (RE_Version_String));
5968 ------------------
5969 -- Wchar_T_Size --
5970 ------------------
5972 when Attribute_Wchar_T_Size =>
5973 Standard_Attribute (Interfaces_Wchar_T_Size);
5975 ----------------
5976 -- Wide_Image --
5977 ----------------
5979 when Attribute_Wide_Image => Wide_Image :
5980 begin
5981 Check_SPARK_Restriction_On_Attribute;
5982 Check_Scalar_Type;
5983 Set_Etype (N, Standard_Wide_String);
5984 Check_E1;
5985 Resolve (E1, P_Base_Type);
5986 Validate_Non_Static_Attribute_Function_Call;
5987 end Wide_Image;
5989 ---------------------
5990 -- Wide_Wide_Image --
5991 ---------------------
5993 when Attribute_Wide_Wide_Image => Wide_Wide_Image :
5994 begin
5995 Check_Scalar_Type;
5996 Set_Etype (N, Standard_Wide_Wide_String);
5997 Check_E1;
5998 Resolve (E1, P_Base_Type);
5999 Validate_Non_Static_Attribute_Function_Call;
6000 end Wide_Wide_Image;
6002 ----------------
6003 -- Wide_Value --
6004 ----------------
6006 when Attribute_Wide_Value => Wide_Value :
6007 begin
6008 Check_SPARK_Restriction_On_Attribute;
6009 Check_E1;
6010 Check_Scalar_Type;
6012 -- Set Etype before resolving expression because expansion
6013 -- of expression may require enclosing type.
6015 Set_Etype (N, P_Type);
6016 Validate_Non_Static_Attribute_Function_Call;
6017 end Wide_Value;
6019 ---------------------
6020 -- Wide_Wide_Value --
6021 ---------------------
6023 when Attribute_Wide_Wide_Value => Wide_Wide_Value :
6024 begin
6025 Check_E1;
6026 Check_Scalar_Type;
6028 -- Set Etype before resolving expression because expansion
6029 -- of expression may require enclosing type.
6031 Set_Etype (N, P_Type);
6032 Validate_Non_Static_Attribute_Function_Call;
6033 end Wide_Wide_Value;
6035 ---------------------
6036 -- Wide_Wide_Width --
6037 ---------------------
6039 when Attribute_Wide_Wide_Width =>
6040 Check_E0;
6041 Check_Scalar_Type;
6042 Set_Etype (N, Universal_Integer);
6044 ----------------
6045 -- Wide_Width --
6046 ----------------
6048 when Attribute_Wide_Width =>
6049 Check_SPARK_Restriction_On_Attribute;
6050 Check_E0;
6051 Check_Scalar_Type;
6052 Set_Etype (N, Universal_Integer);
6054 -----------
6055 -- Width --
6056 -----------
6058 when Attribute_Width =>
6059 Check_SPARK_Restriction_On_Attribute;
6060 Check_E0;
6061 Check_Scalar_Type;
6062 Set_Etype (N, Universal_Integer);
6064 ---------------
6065 -- Word_Size --
6066 ---------------
6068 when Attribute_Word_Size =>
6069 Standard_Attribute (System_Word_Size);
6071 -----------
6072 -- Write --
6073 -----------
6075 when Attribute_Write =>
6076 Check_E2;
6077 Check_Stream_Attribute (TSS_Stream_Write);
6078 Set_Etype (N, Standard_Void_Type);
6079 Resolve (N, Standard_Void_Type);
6081 end case;
6083 -- All errors raise Bad_Attribute, so that we get out before any further
6084 -- damage occurs when an error is detected (for example, if we check for
6085 -- one attribute expression, and the check succeeds, we want to be able
6086 -- to proceed securely assuming that an expression is in fact present.
6088 -- Note: we set the attribute analyzed in this case to prevent any
6089 -- attempt at reanalysis which could generate spurious error msgs.
6091 exception
6092 when Bad_Attribute =>
6093 Set_Analyzed (N);
6094 Set_Etype (N, Any_Type);
6095 return;
6096 end Analyze_Attribute;
6098 --------------------
6099 -- Eval_Attribute --
6100 --------------------
6102 procedure Eval_Attribute (N : Node_Id) is
6103 Loc : constant Source_Ptr := Sloc (N);
6104 Aname : constant Name_Id := Attribute_Name (N);
6105 Id : constant Attribute_Id := Get_Attribute_Id (Aname);
6106 P : constant Node_Id := Prefix (N);
6108 C_Type : constant Entity_Id := Etype (N);
6109 -- The type imposed by the context
6111 E1 : Node_Id;
6112 -- First expression, or Empty if none
6114 E2 : Node_Id;
6115 -- Second expression, or Empty if none
6117 P_Entity : Entity_Id;
6118 -- Entity denoted by prefix
6120 P_Type : Entity_Id;
6121 -- The type of the prefix
6123 P_Base_Type : Entity_Id;
6124 -- The base type of the prefix type
6126 P_Root_Type : Entity_Id;
6127 -- The root type of the prefix type
6129 Static : Boolean;
6130 -- True if the result is Static. This is set by the general processing
6131 -- to true if the prefix is static, and all expressions are static. It
6132 -- can be reset as processing continues for particular attributes
6134 Lo_Bound, Hi_Bound : Node_Id;
6135 -- Expressions for low and high bounds of type or array index referenced
6136 -- by First, Last, or Length attribute for array, set by Set_Bounds.
6138 CE_Node : Node_Id;
6139 -- Constraint error node used if we have an attribute reference has
6140 -- an argument that raises a constraint error. In this case we replace
6141 -- the attribute with a raise constraint_error node. This is important
6142 -- processing, since otherwise gigi might see an attribute which it is
6143 -- unprepared to deal with.
6145 procedure Check_Concurrent_Discriminant (Bound : Node_Id);
6146 -- If Bound is a reference to a discriminant of a task or protected type
6147 -- occurring within the object's body, rewrite attribute reference into
6148 -- a reference to the corresponding discriminal. Use for the expansion
6149 -- of checks against bounds of entry family index subtypes.
6151 procedure Check_Expressions;
6152 -- In case where the attribute is not foldable, the expressions, if
6153 -- any, of the attribute, are in a non-static context. This procedure
6154 -- performs the required additional checks.
6156 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean;
6157 -- Determines if the given type has compile time known bounds. Note
6158 -- that we enter the case statement even in cases where the prefix
6159 -- type does NOT have known bounds, so it is important to guard any
6160 -- attempt to evaluate both bounds with a call to this function.
6162 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint);
6163 -- This procedure is called when the attribute N has a non-static
6164 -- but compile time known value given by Val. It includes the
6165 -- necessary checks for out of range values.
6167 function Fore_Value return Nat;
6168 -- Computes the Fore value for the current attribute prefix, which is
6169 -- known to be a static fixed-point type. Used by Fore and Width.
6171 function Is_VAX_Float (Typ : Entity_Id) return Boolean;
6172 -- Determine whether Typ denotes a VAX floating point type
6174 function Mantissa return Uint;
6175 -- Returns the Mantissa value for the prefix type
6177 procedure Set_Bounds;
6178 -- Used for First, Last and Length attributes applied to an array or
6179 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
6180 -- and high bound expressions for the index referenced by the attribute
6181 -- designator (i.e. the first index if no expression is present, and the
6182 -- N'th index if the value N is present as an expression). Also used for
6183 -- First and Last of scalar types and for First_Valid and Last_Valid.
6184 -- Static is reset to False if the type or index type is not statically
6185 -- constrained.
6187 function Statically_Denotes_Entity (N : Node_Id) return Boolean;
6188 -- Verify that the prefix of a potentially static array attribute
6189 -- satisfies the conditions of 4.9 (14).
6191 -----------------------------------
6192 -- Check_Concurrent_Discriminant --
6193 -----------------------------------
6195 procedure Check_Concurrent_Discriminant (Bound : Node_Id) is
6196 Tsk : Entity_Id;
6197 -- The concurrent (task or protected) type
6199 begin
6200 if Nkind (Bound) = N_Identifier
6201 and then Ekind (Entity (Bound)) = E_Discriminant
6202 and then Is_Concurrent_Record_Type (Scope (Entity (Bound)))
6203 then
6204 Tsk := Corresponding_Concurrent_Type (Scope (Entity (Bound)));
6206 if In_Open_Scopes (Tsk) and then Has_Completion (Tsk) then
6208 -- Find discriminant of original concurrent type, and use
6209 -- its current discriminal, which is the renaming within
6210 -- the task/protected body.
6212 Rewrite (N,
6213 New_Occurrence_Of
6214 (Find_Body_Discriminal (Entity (Bound)), Loc));
6215 end if;
6216 end if;
6217 end Check_Concurrent_Discriminant;
6219 -----------------------
6220 -- Check_Expressions --
6221 -----------------------
6223 procedure Check_Expressions is
6224 E : Node_Id;
6225 begin
6226 E := E1;
6227 while Present (E) loop
6228 Check_Non_Static_Context (E);
6229 Next (E);
6230 end loop;
6231 end Check_Expressions;
6233 ----------------------------------
6234 -- Compile_Time_Known_Attribute --
6235 ----------------------------------
6237 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint) is
6238 T : constant Entity_Id := Etype (N);
6240 begin
6241 Fold_Uint (N, Val, False);
6243 -- Check that result is in bounds of the type if it is static
6245 if Is_In_Range (N, T, Assume_Valid => False) then
6246 null;
6248 elsif Is_Out_Of_Range (N, T) then
6249 Apply_Compile_Time_Constraint_Error
6250 (N, "value not in range of}??", CE_Range_Check_Failed);
6252 elsif not Range_Checks_Suppressed (T) then
6253 Enable_Range_Check (N);
6255 else
6256 Set_Do_Range_Check (N, False);
6257 end if;
6258 end Compile_Time_Known_Attribute;
6260 -------------------------------
6261 -- Compile_Time_Known_Bounds --
6262 -------------------------------
6264 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean is
6265 begin
6266 return
6267 Compile_Time_Known_Value (Type_Low_Bound (Typ))
6268 and then
6269 Compile_Time_Known_Value (Type_High_Bound (Typ));
6270 end Compile_Time_Known_Bounds;
6272 ----------------
6273 -- Fore_Value --
6274 ----------------
6276 -- Note that the Fore calculation is based on the actual values
6277 -- of the bounds, and does not take into account possible rounding.
6279 function Fore_Value return Nat is
6280 Lo : constant Uint := Expr_Value (Type_Low_Bound (P_Type));
6281 Hi : constant Uint := Expr_Value (Type_High_Bound (P_Type));
6282 Small : constant Ureal := Small_Value (P_Type);
6283 Lo_Real : constant Ureal := Lo * Small;
6284 Hi_Real : constant Ureal := Hi * Small;
6285 T : Ureal;
6286 R : Nat;
6288 begin
6289 -- Bounds are given in terms of small units, so first compute
6290 -- proper values as reals.
6292 T := UR_Max (abs Lo_Real, abs Hi_Real);
6293 R := 2;
6295 -- Loop to compute proper value if more than one digit required
6297 while T >= Ureal_10 loop
6298 R := R + 1;
6299 T := T / Ureal_10;
6300 end loop;
6302 return R;
6303 end Fore_Value;
6305 ------------------
6306 -- Is_VAX_Float --
6307 ------------------
6309 function Is_VAX_Float (Typ : Entity_Id) return Boolean is
6310 begin
6311 return
6312 Is_Floating_Point_Type (Typ)
6313 and then
6314 (Float_Format = 'V' or else Float_Rep (Typ) = VAX_Native);
6315 end Is_VAX_Float;
6317 --------------
6318 -- Mantissa --
6319 --------------
6321 -- Table of mantissa values accessed by function Computed using
6322 -- the relation:
6324 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
6326 -- where D is T'Digits (RM83 3.5.7)
6328 Mantissa_Value : constant array (Nat range 1 .. 40) of Nat := (
6329 1 => 5,
6330 2 => 8,
6331 3 => 11,
6332 4 => 15,
6333 5 => 18,
6334 6 => 21,
6335 7 => 25,
6336 8 => 28,
6337 9 => 31,
6338 10 => 35,
6339 11 => 38,
6340 12 => 41,
6341 13 => 45,
6342 14 => 48,
6343 15 => 51,
6344 16 => 55,
6345 17 => 58,
6346 18 => 61,
6347 19 => 65,
6348 20 => 68,
6349 21 => 71,
6350 22 => 75,
6351 23 => 78,
6352 24 => 81,
6353 25 => 85,
6354 26 => 88,
6355 27 => 91,
6356 28 => 95,
6357 29 => 98,
6358 30 => 101,
6359 31 => 104,
6360 32 => 108,
6361 33 => 111,
6362 34 => 114,
6363 35 => 118,
6364 36 => 121,
6365 37 => 124,
6366 38 => 128,
6367 39 => 131,
6368 40 => 134);
6370 function Mantissa return Uint is
6371 begin
6372 return
6373 UI_From_Int (Mantissa_Value (UI_To_Int (Digits_Value (P_Type))));
6374 end Mantissa;
6376 ----------------
6377 -- Set_Bounds --
6378 ----------------
6380 procedure Set_Bounds is
6381 Ndim : Nat;
6382 Indx : Node_Id;
6383 Ityp : Entity_Id;
6385 begin
6386 -- For a string literal subtype, we have to construct the bounds.
6387 -- Valid Ada code never applies attributes to string literals, but
6388 -- it is convenient to allow the expander to generate attribute
6389 -- references of this type (e.g. First and Last applied to a string
6390 -- literal).
6392 -- Note that the whole point of the E_String_Literal_Subtype is to
6393 -- avoid this construction of bounds, but the cases in which we
6394 -- have to materialize them are rare enough that we don't worry!
6396 -- The low bound is simply the low bound of the base type. The
6397 -- high bound is computed from the length of the string and this
6398 -- low bound.
6400 if Ekind (P_Type) = E_String_Literal_Subtype then
6401 Ityp := Etype (First_Index (Base_Type (P_Type)));
6402 Lo_Bound := Type_Low_Bound (Ityp);
6404 Hi_Bound :=
6405 Make_Integer_Literal (Sloc (P),
6406 Intval =>
6407 Expr_Value (Lo_Bound) + String_Literal_Length (P_Type) - 1);
6409 Set_Parent (Hi_Bound, P);
6410 Analyze_And_Resolve (Hi_Bound, Etype (Lo_Bound));
6411 return;
6413 -- For non-array case, just get bounds of scalar type
6415 elsif Is_Scalar_Type (P_Type) then
6416 Ityp := P_Type;
6418 -- For a fixed-point type, we must freeze to get the attributes
6419 -- of the fixed-point type set now so we can reference them.
6421 if Is_Fixed_Point_Type (P_Type)
6422 and then not Is_Frozen (Base_Type (P_Type))
6423 and then Compile_Time_Known_Value (Type_Low_Bound (P_Type))
6424 and then Compile_Time_Known_Value (Type_High_Bound (P_Type))
6425 then
6426 Freeze_Fixed_Point_Type (Base_Type (P_Type));
6427 end if;
6429 -- For array case, get type of proper index
6431 else
6432 if No (E1) then
6433 Ndim := 1;
6434 else
6435 Ndim := UI_To_Int (Expr_Value (E1));
6436 end if;
6438 Indx := First_Index (P_Type);
6439 for J in 1 .. Ndim - 1 loop
6440 Next_Index (Indx);
6441 end loop;
6443 -- If no index type, get out (some other error occurred, and
6444 -- we don't have enough information to complete the job!)
6446 if No (Indx) then
6447 Lo_Bound := Error;
6448 Hi_Bound := Error;
6449 return;
6450 end if;
6452 Ityp := Etype (Indx);
6453 end if;
6455 -- A discrete range in an index constraint is allowed to be a
6456 -- subtype indication. This is syntactically a pain, but should
6457 -- not propagate to the entity for the corresponding index subtype.
6458 -- After checking that the subtype indication is legal, the range
6459 -- of the subtype indication should be transfered to the entity.
6460 -- The attributes for the bounds should remain the simple retrievals
6461 -- that they are now.
6463 Lo_Bound := Type_Low_Bound (Ityp);
6464 Hi_Bound := Type_High_Bound (Ityp);
6466 if not Is_Static_Subtype (Ityp) then
6467 Static := False;
6468 end if;
6469 end Set_Bounds;
6471 -------------------------------
6472 -- Statically_Denotes_Entity --
6473 -------------------------------
6475 function Statically_Denotes_Entity (N : Node_Id) return Boolean is
6476 E : Entity_Id;
6478 begin
6479 if not Is_Entity_Name (N) then
6480 return False;
6481 else
6482 E := Entity (N);
6483 end if;
6485 return
6486 Nkind (Parent (E)) /= N_Object_Renaming_Declaration
6487 or else Statically_Denotes_Entity (Renamed_Object (E));
6488 end Statically_Denotes_Entity;
6490 -- Start of processing for Eval_Attribute
6492 begin
6493 -- Acquire first two expressions (at the moment, no attributes take more
6494 -- than two expressions in any case).
6496 if Present (Expressions (N)) then
6497 E1 := First (Expressions (N));
6498 E2 := Next (E1);
6499 else
6500 E1 := Empty;
6501 E2 := Empty;
6502 end if;
6504 -- Special processing for Enabled attribute. This attribute has a very
6505 -- special prefix, and the easiest way to avoid lots of special checks
6506 -- to protect this special prefix from causing trouble is to deal with
6507 -- this attribute immediately and be done with it.
6509 if Id = Attribute_Enabled then
6511 -- We skip evaluation if the expander is not active. This is not just
6512 -- an optimization. It is of key importance that we not rewrite the
6513 -- attribute in a generic template, since we want to pick up the
6514 -- setting of the check in the instance, and testing expander active
6515 -- is as easy way of doing this as any.
6517 if Expander_Active then
6518 declare
6519 C : constant Check_Id := Get_Check_Id (Chars (P));
6520 R : Boolean;
6522 begin
6523 if No (E1) then
6524 if C in Predefined_Check_Id then
6525 R := Scope_Suppress.Suppress (C);
6526 else
6527 R := Is_Check_Suppressed (Empty, C);
6528 end if;
6530 else
6531 R := Is_Check_Suppressed (Entity (E1), C);
6532 end if;
6534 Rewrite (N, New_Occurrence_Of (Boolean_Literals (not R), Loc));
6535 end;
6536 end if;
6538 return;
6539 end if;
6541 -- Special processing for cases where the prefix is an object. For
6542 -- this purpose, a string literal counts as an object (attributes
6543 -- of string literals can only appear in generated code).
6545 if Is_Object_Reference (P) or else Nkind (P) = N_String_Literal then
6547 -- For Component_Size, the prefix is an array object, and we apply
6548 -- the attribute to the type of the object. This is allowed for
6549 -- both unconstrained and constrained arrays, since the bounds
6550 -- have no influence on the value of this attribute.
6552 if Id = Attribute_Component_Size then
6553 P_Entity := Etype (P);
6555 -- For First and Last, the prefix is an array object, and we apply
6556 -- the attribute to the type of the array, but we need a constrained
6557 -- type for this, so we use the actual subtype if available.
6559 elsif Id = Attribute_First
6560 or else
6561 Id = Attribute_Last
6562 or else
6563 Id = Attribute_Length
6564 then
6565 declare
6566 AS : constant Entity_Id := Get_Actual_Subtype_If_Available (P);
6568 begin
6569 if Present (AS) and then Is_Constrained (AS) then
6570 P_Entity := AS;
6572 -- If we have an unconstrained type we cannot fold
6574 else
6575 Check_Expressions;
6576 return;
6577 end if;
6578 end;
6580 -- For Size, give size of object if available, otherwise we
6581 -- cannot fold Size.
6583 elsif Id = Attribute_Size then
6584 if Is_Entity_Name (P)
6585 and then Known_Esize (Entity (P))
6586 then
6587 Compile_Time_Known_Attribute (N, Esize (Entity (P)));
6588 return;
6590 else
6591 Check_Expressions;
6592 return;
6593 end if;
6595 -- For Alignment, give size of object if available, otherwise we
6596 -- cannot fold Alignment.
6598 elsif Id = Attribute_Alignment then
6599 if Is_Entity_Name (P)
6600 and then Known_Alignment (Entity (P))
6601 then
6602 Fold_Uint (N, Alignment (Entity (P)), False);
6603 return;
6605 else
6606 Check_Expressions;
6607 return;
6608 end if;
6610 -- For Lock_Free, we apply the attribute to the type of the object.
6611 -- This is allowed since we have already verified that the type is a
6612 -- protected type.
6614 elsif Id = Attribute_Lock_Free then
6615 P_Entity := Etype (P);
6617 -- No other attributes for objects are folded
6619 else
6620 Check_Expressions;
6621 return;
6622 end if;
6624 -- Cases where P is not an object. Cannot do anything if P is
6625 -- not the name of an entity.
6627 elsif not Is_Entity_Name (P) then
6628 Check_Expressions;
6629 return;
6631 -- Otherwise get prefix entity
6633 else
6634 P_Entity := Entity (P);
6635 end if;
6637 -- At this stage P_Entity is the entity to which the attribute
6638 -- is to be applied. This is usually simply the entity of the
6639 -- prefix, except in some cases of attributes for objects, where
6640 -- as described above, we apply the attribute to the object type.
6642 -- First foldable possibility is a scalar or array type (RM 4.9(7))
6643 -- that is not generic (generic types are eliminated by RM 4.9(25)).
6644 -- Note we allow non-static non-generic types at this stage as further
6645 -- described below.
6647 if Is_Type (P_Entity)
6648 and then (Is_Scalar_Type (P_Entity) or Is_Array_Type (P_Entity))
6649 and then (not Is_Generic_Type (P_Entity))
6650 then
6651 P_Type := P_Entity;
6653 -- Second foldable possibility is an array object (RM 4.9(8))
6655 elsif (Ekind (P_Entity) = E_Variable
6656 or else
6657 Ekind (P_Entity) = E_Constant)
6658 and then Is_Array_Type (Etype (P_Entity))
6659 and then (not Is_Generic_Type (Etype (P_Entity)))
6660 then
6661 P_Type := Etype (P_Entity);
6663 -- If the entity is an array constant with an unconstrained nominal
6664 -- subtype then get the type from the initial value. If the value has
6665 -- been expanded into assignments, there is no expression and the
6666 -- attribute reference remains dynamic.
6668 -- We could do better here and retrieve the type ???
6670 if Ekind (P_Entity) = E_Constant
6671 and then not Is_Constrained (P_Type)
6672 then
6673 if No (Constant_Value (P_Entity)) then
6674 return;
6675 else
6676 P_Type := Etype (Constant_Value (P_Entity));
6677 end if;
6678 end if;
6680 -- Definite must be folded if the prefix is not a generic type,
6681 -- that is to say if we are within an instantiation. Same processing
6682 -- applies to the GNAT attributes Atomic_Always_Lock_Free,
6683 -- Has_Discriminants, Lock_Free, Type_Class, Has_Tagged_Value, and
6684 -- Unconstrained_Array.
6686 elsif (Id = Attribute_Atomic_Always_Lock_Free
6687 or else
6688 Id = Attribute_Definite
6689 or else
6690 Id = Attribute_Has_Access_Values
6691 or else
6692 Id = Attribute_Has_Discriminants
6693 or else
6694 Id = Attribute_Has_Tagged_Values
6695 or else
6696 Id = Attribute_Lock_Free
6697 or else
6698 Id = Attribute_Type_Class
6699 or else
6700 Id = Attribute_Unconstrained_Array
6701 or else
6702 Id = Attribute_Max_Alignment_For_Allocation)
6703 and then not Is_Generic_Type (P_Entity)
6704 then
6705 P_Type := P_Entity;
6707 -- We can fold 'Size applied to a type if the size is known (as happens
6708 -- for a size from an attribute definition clause). At this stage, this
6709 -- can happen only for types (e.g. record types) for which the size is
6710 -- always non-static. We exclude generic types from consideration (since
6711 -- they have bogus sizes set within templates).
6713 elsif Id = Attribute_Size
6714 and then Is_Type (P_Entity)
6715 and then (not Is_Generic_Type (P_Entity))
6716 and then Known_Static_RM_Size (P_Entity)
6717 then
6718 Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
6719 return;
6721 -- We can fold 'Alignment applied to a type if the alignment is known
6722 -- (as happens for an alignment from an attribute definition clause).
6723 -- At this stage, this can happen only for types (e.g. record
6724 -- types) for which the size is always non-static. We exclude
6725 -- generic types from consideration (since they have bogus
6726 -- sizes set within templates).
6728 elsif Id = Attribute_Alignment
6729 and then Is_Type (P_Entity)
6730 and then (not Is_Generic_Type (P_Entity))
6731 and then Known_Alignment (P_Entity)
6732 then
6733 Compile_Time_Known_Attribute (N, Alignment (P_Entity));
6734 return;
6736 -- If this is an access attribute that is known to fail accessibility
6737 -- check, rewrite accordingly.
6739 elsif Attribute_Name (N) = Name_Access
6740 and then Raises_Constraint_Error (N)
6741 then
6742 Rewrite (N,
6743 Make_Raise_Program_Error (Loc,
6744 Reason => PE_Accessibility_Check_Failed));
6745 Set_Etype (N, C_Type);
6746 return;
6748 -- No other cases are foldable (they certainly aren't static, and at
6749 -- the moment we don't try to fold any cases other than the ones above).
6751 else
6752 Check_Expressions;
6753 return;
6754 end if;
6756 -- If either attribute or the prefix is Any_Type, then propagate
6757 -- Any_Type to the result and don't do anything else at all.
6759 if P_Type = Any_Type
6760 or else (Present (E1) and then Etype (E1) = Any_Type)
6761 or else (Present (E2) and then Etype (E2) = Any_Type)
6762 then
6763 Set_Etype (N, Any_Type);
6764 return;
6765 end if;
6767 -- Scalar subtype case. We have not yet enforced the static requirement
6768 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
6769 -- of non-static attribute references (e.g. S'Digits for a non-static
6770 -- floating-point type, which we can compute at compile time).
6772 -- Note: this folding of non-static attributes is not simply a case of
6773 -- optimization. For many of the attributes affected, Gigi cannot handle
6774 -- the attribute and depends on the front end having folded them away.
6776 -- Note: although we don't require staticness at this stage, we do set
6777 -- the Static variable to record the staticness, for easy reference by
6778 -- those attributes where it matters (e.g. Succ and Pred), and also to
6779 -- be used to ensure that non-static folded things are not marked as
6780 -- being static (a check that is done right at the end).
6782 P_Root_Type := Root_Type (P_Type);
6783 P_Base_Type := Base_Type (P_Type);
6785 -- If the root type or base type is generic, then we cannot fold. This
6786 -- test is needed because subtypes of generic types are not always
6787 -- marked as being generic themselves (which seems odd???)
6789 if Is_Generic_Type (P_Root_Type)
6790 or else Is_Generic_Type (P_Base_Type)
6791 then
6792 return;
6793 end if;
6795 if Is_Scalar_Type (P_Type) then
6796 Static := Is_OK_Static_Subtype (P_Type);
6798 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
6799 -- since we can't do anything with unconstrained arrays. In addition,
6800 -- only the First, Last and Length attributes are possibly static.
6802 -- Atomic_Always_Lock_Free, Definite, Has_Access_Values,
6803 -- Has_Discriminants, Has_Tagged_Values, Lock_Free, Type_Class, and
6804 -- Unconstrained_Array are again exceptions, because they apply as well
6805 -- to unconstrained types.
6807 -- In addition Component_Size is an exception since it is possibly
6808 -- foldable, even though it is never static, and it does apply to
6809 -- unconstrained arrays. Furthermore, it is essential to fold this
6810 -- in the packed case, since otherwise the value will be incorrect.
6812 elsif Id = Attribute_Atomic_Always_Lock_Free
6813 or else
6814 Id = Attribute_Definite
6815 or else
6816 Id = Attribute_Has_Access_Values
6817 or else
6818 Id = Attribute_Has_Discriminants
6819 or else
6820 Id = Attribute_Has_Tagged_Values
6821 or else
6822 Id = Attribute_Lock_Free
6823 or else
6824 Id = Attribute_Type_Class
6825 or else
6826 Id = Attribute_Unconstrained_Array
6827 or else
6828 Id = Attribute_Component_Size
6829 then
6830 Static := False;
6832 elsif Id /= Attribute_Max_Alignment_For_Allocation then
6833 if not Is_Constrained (P_Type)
6834 or else (Id /= Attribute_First and then
6835 Id /= Attribute_Last and then
6836 Id /= Attribute_Length)
6837 then
6838 Check_Expressions;
6839 return;
6840 end if;
6842 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
6843 -- scalar case, we hold off on enforcing staticness, since there are
6844 -- cases which we can fold at compile time even though they are not
6845 -- static (e.g. 'Length applied to a static index, even though other
6846 -- non-static indexes make the array type non-static). This is only
6847 -- an optimization, but it falls out essentially free, so why not.
6848 -- Again we compute the variable Static for easy reference later
6849 -- (note that no array attributes are static in Ada 83).
6851 -- We also need to set Static properly for subsequent legality checks
6852 -- which might otherwise accept non-static constants in contexts
6853 -- where they are not legal.
6855 Static := Ada_Version >= Ada_95
6856 and then Statically_Denotes_Entity (P);
6858 declare
6859 N : Node_Id;
6861 begin
6862 N := First_Index (P_Type);
6864 -- The expression is static if the array type is constrained
6865 -- by given bounds, and not by an initial expression. Constant
6866 -- strings are static in any case.
6868 if Root_Type (P_Type) /= Standard_String then
6869 Static :=
6870 Static and then not Is_Constr_Subt_For_U_Nominal (P_Type);
6871 end if;
6873 while Present (N) loop
6874 Static := Static and then Is_Static_Subtype (Etype (N));
6876 -- If however the index type is generic, or derived from
6877 -- one, attributes cannot be folded.
6879 if Is_Generic_Type (Root_Type (Etype (N)))
6880 and then Id /= Attribute_Component_Size
6881 then
6882 return;
6883 end if;
6885 Next_Index (N);
6886 end loop;
6887 end;
6888 end if;
6890 -- Check any expressions that are present. Note that these expressions,
6891 -- depending on the particular attribute type, are either part of the
6892 -- attribute designator, or they are arguments in a case where the
6893 -- attribute reference returns a function. In the latter case, the
6894 -- rule in (RM 4.9(22)) applies and in particular requires the type
6895 -- of the expressions to be scalar in order for the attribute to be
6896 -- considered to be static.
6898 declare
6899 E : Node_Id;
6901 begin
6902 E := E1;
6903 while Present (E) loop
6905 -- If expression is not static, then the attribute reference
6906 -- result certainly cannot be static.
6908 if not Is_Static_Expression (E) then
6909 Static := False;
6910 end if;
6912 -- If the result is not known at compile time, or is not of
6913 -- a scalar type, then the result is definitely not static,
6914 -- so we can quit now.
6916 if not Compile_Time_Known_Value (E)
6917 or else not Is_Scalar_Type (Etype (E))
6918 then
6919 -- An odd special case, if this is a Pos attribute, this
6920 -- is where we need to apply a range check since it does
6921 -- not get done anywhere else.
6923 if Id = Attribute_Pos then
6924 if Is_Integer_Type (Etype (E)) then
6925 Apply_Range_Check (E, Etype (N));
6926 end if;
6927 end if;
6929 Check_Expressions;
6930 return;
6932 -- If the expression raises a constraint error, then so does
6933 -- the attribute reference. We keep going in this case because
6934 -- we are still interested in whether the attribute reference
6935 -- is static even if it is not static.
6937 elsif Raises_Constraint_Error (E) then
6938 Set_Raises_Constraint_Error (N);
6939 end if;
6941 Next (E);
6942 end loop;
6944 if Raises_Constraint_Error (Prefix (N)) then
6945 return;
6946 end if;
6947 end;
6949 -- Deal with the case of a static attribute reference that raises
6950 -- constraint error. The Raises_Constraint_Error flag will already
6951 -- have been set, and the Static flag shows whether the attribute
6952 -- reference is static. In any case we certainly can't fold such an
6953 -- attribute reference.
6955 -- Note that the rewriting of the attribute node with the constraint
6956 -- error node is essential in this case, because otherwise Gigi might
6957 -- blow up on one of the attributes it never expects to see.
6959 -- The constraint_error node must have the type imposed by the context,
6960 -- to avoid spurious errors in the enclosing expression.
6962 if Raises_Constraint_Error (N) then
6963 CE_Node :=
6964 Make_Raise_Constraint_Error (Sloc (N),
6965 Reason => CE_Range_Check_Failed);
6966 Set_Etype (CE_Node, Etype (N));
6967 Set_Raises_Constraint_Error (CE_Node);
6968 Check_Expressions;
6969 Rewrite (N, Relocate_Node (CE_Node));
6970 Set_Is_Static_Expression (N, Static);
6971 return;
6972 end if;
6974 -- At this point we have a potentially foldable attribute reference.
6975 -- If Static is set, then the attribute reference definitely obeys
6976 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
6977 -- folded. If Static is not set, then the attribute may or may not
6978 -- be foldable, and the individual attribute processing routines
6979 -- test Static as required in cases where it makes a difference.
6981 -- In the case where Static is not set, we do know that all the
6982 -- expressions present are at least known at compile time (we assumed
6983 -- above that if this was not the case, then there was no hope of static
6984 -- evaluation). However, we did not require that the bounds of the
6985 -- prefix type be compile time known, let alone static). That's because
6986 -- there are many attributes that can be computed at compile time on
6987 -- non-static subtypes, even though such references are not static
6988 -- expressions.
6990 -- For VAX float, the root type is an IEEE type. So make sure to use the
6991 -- base type instead of the root-type for floating point attributes.
6993 case Id is
6995 -- Attributes related to Ada 2012 iterators (placeholder ???)
6997 when Attribute_Constant_Indexing |
6998 Attribute_Default_Iterator |
6999 Attribute_Implicit_Dereference |
7000 Attribute_Iterator_Element |
7001 Attribute_Variable_Indexing => null;
7003 -- Internal attributes used to deal with Ada 2012 delayed aspects.
7004 -- These were already rejected by the parser. Thus they shouldn't
7005 -- appear here.
7007 when Internal_Attribute_Id =>
7008 raise Program_Error;
7010 --------------
7011 -- Adjacent --
7012 --------------
7014 when Attribute_Adjacent =>
7015 Fold_Ureal
7017 Eval_Fat.Adjacent
7018 (P_Base_Type, Expr_Value_R (E1), Expr_Value_R (E2)),
7019 Static);
7021 ---------
7022 -- Aft --
7023 ---------
7025 when Attribute_Aft =>
7026 Fold_Uint (N, Aft_Value (P_Type), True);
7028 ---------------
7029 -- Alignment --
7030 ---------------
7032 when Attribute_Alignment => Alignment_Block : declare
7033 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
7035 begin
7036 -- Fold if alignment is set and not otherwise
7038 if Known_Alignment (P_TypeA) then
7039 Fold_Uint (N, Alignment (P_TypeA), Is_Discrete_Type (P_TypeA));
7040 end if;
7041 end Alignment_Block;
7043 ---------------
7044 -- AST_Entry --
7045 ---------------
7047 -- Can only be folded in No_Ast_Handler case
7049 when Attribute_AST_Entry =>
7050 if not Is_AST_Entry (P_Entity) then
7051 Rewrite (N,
7052 New_Occurrence_Of (RTE (RE_No_AST_Handler), Loc));
7053 else
7054 null;
7055 end if;
7057 -----------------------------
7058 -- Atomic_Always_Lock_Free --
7059 -----------------------------
7061 -- Atomic_Always_Lock_Free attribute is a Boolean, thus no need to fold
7062 -- here.
7064 when Attribute_Atomic_Always_Lock_Free => Atomic_Always_Lock_Free :
7065 declare
7066 V : constant Entity_Id :=
7067 Boolean_Literals
7068 (Support_Atomic_Primitives_On_Target
7069 and then Support_Atomic_Primitives (P_Type));
7071 begin
7072 Rewrite (N, New_Occurrence_Of (V, Loc));
7074 -- Analyze and resolve as boolean. Note that this attribute is a
7075 -- static attribute in GNAT.
7077 Analyze_And_Resolve (N, Standard_Boolean);
7078 Static := True;
7079 end Atomic_Always_Lock_Free;
7081 ---------
7082 -- Bit --
7083 ---------
7085 -- Bit can never be folded
7087 when Attribute_Bit =>
7088 null;
7090 ------------------
7091 -- Body_Version --
7092 ------------------
7094 -- Body_version can never be static
7096 when Attribute_Body_Version =>
7097 null;
7099 -------------
7100 -- Ceiling --
7101 -------------
7103 when Attribute_Ceiling =>
7104 Fold_Ureal
7105 (N, Eval_Fat.Ceiling (P_Base_Type, Expr_Value_R (E1)), Static);
7107 --------------------
7108 -- Component_Size --
7109 --------------------
7111 when Attribute_Component_Size =>
7112 if Known_Static_Component_Size (P_Type) then
7113 Fold_Uint (N, Component_Size (P_Type), False);
7114 end if;
7116 -------------
7117 -- Compose --
7118 -------------
7120 when Attribute_Compose =>
7121 Fold_Ureal
7123 Eval_Fat.Compose (P_Base_Type, Expr_Value_R (E1), Expr_Value (E2)),
7124 Static);
7126 -----------------
7127 -- Constrained --
7128 -----------------
7130 -- Constrained is never folded for now, there may be cases that
7131 -- could be handled at compile time. To be looked at later.
7133 when Attribute_Constrained =>
7134 null;
7136 ---------------
7137 -- Copy_Sign --
7138 ---------------
7140 when Attribute_Copy_Sign =>
7141 Fold_Ureal
7143 Eval_Fat.Copy_Sign
7144 (P_Base_Type, Expr_Value_R (E1), Expr_Value_R (E2)),
7145 Static);
7147 --------------
7148 -- Definite --
7149 --------------
7151 when Attribute_Definite =>
7152 Rewrite (N, New_Occurrence_Of (
7153 Boolean_Literals (not Is_Indefinite_Subtype (P_Entity)), Loc));
7154 Analyze_And_Resolve (N, Standard_Boolean);
7156 -----------
7157 -- Delta --
7158 -----------
7160 when Attribute_Delta =>
7161 Fold_Ureal (N, Delta_Value (P_Type), True);
7163 ------------
7164 -- Denorm --
7165 ------------
7167 when Attribute_Denorm =>
7168 Fold_Uint
7169 (N, UI_From_Int (Boolean'Pos (Has_Denormals (P_Type))), True);
7171 ---------------------
7172 -- Descriptor_Size --
7173 ---------------------
7175 when Attribute_Descriptor_Size =>
7176 null;
7178 ------------
7179 -- Digits --
7180 ------------
7182 when Attribute_Digits =>
7183 Fold_Uint (N, Digits_Value (P_Type), True);
7185 ----------
7186 -- Emax --
7187 ----------
7189 when Attribute_Emax =>
7191 -- Ada 83 attribute is defined as (RM83 3.5.8)
7193 -- T'Emax = 4 * T'Mantissa
7195 Fold_Uint (N, 4 * Mantissa, True);
7197 --------------
7198 -- Enum_Rep --
7199 --------------
7201 when Attribute_Enum_Rep =>
7203 -- For an enumeration type with a non-standard representation use
7204 -- the Enumeration_Rep field of the proper constant. Note that this
7205 -- will not work for types Character/Wide_[Wide-]Character, since no
7206 -- real entities are created for the enumeration literals, but that
7207 -- does not matter since these two types do not have non-standard
7208 -- representations anyway.
7210 if Is_Enumeration_Type (P_Type)
7211 and then Has_Non_Standard_Rep (P_Type)
7212 then
7213 Fold_Uint (N, Enumeration_Rep (Expr_Value_E (E1)), Static);
7215 -- For enumeration types with standard representations and all
7216 -- other cases (i.e. all integer and modular types), Enum_Rep
7217 -- is equivalent to Pos.
7219 else
7220 Fold_Uint (N, Expr_Value (E1), Static);
7221 end if;
7223 --------------
7224 -- Enum_Val --
7225 --------------
7227 when Attribute_Enum_Val => Enum_Val : declare
7228 Lit : Node_Id;
7230 begin
7231 -- We have something like Enum_Type'Enum_Val (23), so search for a
7232 -- corresponding value in the list of Enum_Rep values for the type.
7234 Lit := First_Literal (P_Base_Type);
7235 loop
7236 if Enumeration_Rep (Lit) = Expr_Value (E1) then
7237 Fold_Uint (N, Enumeration_Pos (Lit), Static);
7238 exit;
7239 end if;
7241 Next_Literal (Lit);
7243 if No (Lit) then
7244 Apply_Compile_Time_Constraint_Error
7245 (N, "no representation value matches",
7246 CE_Range_Check_Failed,
7247 Warn => not Static);
7248 exit;
7249 end if;
7250 end loop;
7251 end Enum_Val;
7253 -------------
7254 -- Epsilon --
7255 -------------
7257 when Attribute_Epsilon =>
7259 -- Ada 83 attribute is defined as (RM83 3.5.8)
7261 -- T'Epsilon = 2.0**(1 - T'Mantissa)
7263 Fold_Ureal (N, Ureal_2 ** (1 - Mantissa), True);
7265 --------------
7266 -- Exponent --
7267 --------------
7269 when Attribute_Exponent =>
7270 Fold_Uint (N,
7271 Eval_Fat.Exponent (P_Base_Type, Expr_Value_R (E1)), Static);
7273 -----------
7274 -- First --
7275 -----------
7277 when Attribute_First => First_Attr :
7278 begin
7279 Set_Bounds;
7281 if Compile_Time_Known_Value (Lo_Bound) then
7282 if Is_Real_Type (P_Type) then
7283 Fold_Ureal (N, Expr_Value_R (Lo_Bound), Static);
7284 else
7285 Fold_Uint (N, Expr_Value (Lo_Bound), Static);
7286 end if;
7288 -- Replace VAX Float_Type'First with a reference to the temporary
7289 -- which represents the low bound of the type. This transformation
7290 -- is needed since the back end cannot evaluate 'First on VAX.
7292 elsif Is_VAX_Float (P_Type)
7293 and then Nkind (Lo_Bound) = N_Identifier
7294 then
7295 Rewrite (N, New_Reference_To (Entity (Lo_Bound), Sloc (N)));
7296 Analyze (N);
7298 else
7299 Check_Concurrent_Discriminant (Lo_Bound);
7300 end if;
7301 end First_Attr;
7303 -----------------
7304 -- First_Valid --
7305 -----------------
7307 when Attribute_First_Valid => First_Valid :
7308 begin
7309 if Has_Predicates (P_Type)
7310 and then Present (Static_Predicate (P_Type))
7311 then
7312 declare
7313 FirstN : constant Node_Id := First (Static_Predicate (P_Type));
7314 begin
7315 if Nkind (FirstN) = N_Range then
7316 Fold_Uint (N, Expr_Value (Low_Bound (FirstN)), Static);
7317 else
7318 Fold_Uint (N, Expr_Value (FirstN), Static);
7319 end if;
7320 end;
7322 else
7323 Set_Bounds;
7324 Fold_Uint (N, Expr_Value (Lo_Bound), Static);
7325 end if;
7326 end First_Valid;
7328 -----------------
7329 -- Fixed_Value --
7330 -----------------
7332 when Attribute_Fixed_Value =>
7333 null;
7335 -----------
7336 -- Floor --
7337 -----------
7339 when Attribute_Floor =>
7340 Fold_Ureal
7341 (N, Eval_Fat.Floor (P_Base_Type, Expr_Value_R (E1)), Static);
7343 ----------
7344 -- Fore --
7345 ----------
7347 when Attribute_Fore =>
7348 if Compile_Time_Known_Bounds (P_Type) then
7349 Fold_Uint (N, UI_From_Int (Fore_Value), Static);
7350 end if;
7352 --------------
7353 -- Fraction --
7354 --------------
7356 when Attribute_Fraction =>
7357 Fold_Ureal
7358 (N, Eval_Fat.Fraction (P_Base_Type, Expr_Value_R (E1)), Static);
7360 -----------------------
7361 -- Has_Access_Values --
7362 -----------------------
7364 when Attribute_Has_Access_Values =>
7365 Rewrite (N, New_Occurrence_Of
7366 (Boolean_Literals (Has_Access_Values (P_Root_Type)), Loc));
7367 Analyze_And_Resolve (N, Standard_Boolean);
7369 -----------------------
7370 -- Has_Discriminants --
7371 -----------------------
7373 when Attribute_Has_Discriminants =>
7374 Rewrite (N, New_Occurrence_Of (
7375 Boolean_Literals (Has_Discriminants (P_Entity)), Loc));
7376 Analyze_And_Resolve (N, Standard_Boolean);
7378 -----------------------
7379 -- Has_Tagged_Values --
7380 -----------------------
7382 when Attribute_Has_Tagged_Values =>
7383 Rewrite (N, New_Occurrence_Of
7384 (Boolean_Literals (Has_Tagged_Component (P_Root_Type)), Loc));
7385 Analyze_And_Resolve (N, Standard_Boolean);
7387 --------------
7388 -- Identity --
7389 --------------
7391 when Attribute_Identity =>
7392 null;
7394 -----------
7395 -- Image --
7396 -----------
7398 -- Image is a scalar attribute, but is never static, because it is
7399 -- not a static function (having a non-scalar argument (RM 4.9(22))
7400 -- However, we can constant-fold the image of an enumeration literal
7401 -- if names are available.
7403 when Attribute_Image =>
7404 if Is_Entity_Name (E1)
7405 and then Ekind (Entity (E1)) = E_Enumeration_Literal
7406 and then not Discard_Names (First_Subtype (Etype (E1)))
7407 and then not Global_Discard_Names
7408 then
7409 declare
7410 Lit : constant Entity_Id := Entity (E1);
7411 Str : String_Id;
7412 begin
7413 Start_String;
7414 Get_Unqualified_Decoded_Name_String (Chars (Lit));
7415 Set_Casing (All_Upper_Case);
7416 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7417 Str := End_String;
7418 Rewrite (N, Make_String_Literal (Loc, Strval => Str));
7419 Analyze_And_Resolve (N, Standard_String);
7420 Set_Is_Static_Expression (N, False);
7421 end;
7422 end if;
7424 ---------
7425 -- Img --
7426 ---------
7428 -- Img is a scalar attribute, but is never static, because it is
7429 -- not a static function (having a non-scalar argument (RM 4.9(22))
7431 when Attribute_Img =>
7432 null;
7434 -------------------
7435 -- Integer_Value --
7436 -------------------
7438 -- We never try to fold Integer_Value (though perhaps we could???)
7440 when Attribute_Integer_Value =>
7441 null;
7443 -------------------
7444 -- Invalid_Value --
7445 -------------------
7447 -- Invalid_Value is a scalar attribute that is never static, because
7448 -- the value is by design out of range.
7450 when Attribute_Invalid_Value =>
7451 null;
7453 -----------
7454 -- Large --
7455 -----------
7457 when Attribute_Large =>
7459 -- For fixed-point, we use the identity:
7461 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
7463 if Is_Fixed_Point_Type (P_Type) then
7464 Rewrite (N,
7465 Make_Op_Multiply (Loc,
7466 Left_Opnd =>
7467 Make_Op_Subtract (Loc,
7468 Left_Opnd =>
7469 Make_Op_Expon (Loc,
7470 Left_Opnd =>
7471 Make_Real_Literal (Loc, Ureal_2),
7472 Right_Opnd =>
7473 Make_Attribute_Reference (Loc,
7474 Prefix => P,
7475 Attribute_Name => Name_Mantissa)),
7476 Right_Opnd => Make_Real_Literal (Loc, Ureal_1)),
7478 Right_Opnd =>
7479 Make_Real_Literal (Loc, Small_Value (Entity (P)))));
7481 Analyze_And_Resolve (N, C_Type);
7483 -- Floating-point (Ada 83 compatibility)
7485 else
7486 -- Ada 83 attribute is defined as (RM83 3.5.8)
7488 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
7490 -- where
7492 -- T'Emax = 4 * T'Mantissa
7494 Fold_Ureal
7496 Ureal_2 ** (4 * Mantissa) * (Ureal_1 - Ureal_2 ** (-Mantissa)),
7497 True);
7498 end if;
7500 ---------------
7501 -- Lock_Free --
7502 ---------------
7504 when Attribute_Lock_Free => Lock_Free : declare
7505 V : constant Entity_Id := Boolean_Literals (Uses_Lock_Free (P_Type));
7507 begin
7508 Rewrite (N, New_Occurrence_Of (V, Loc));
7510 -- Analyze and resolve as boolean. Note that this attribute is a
7511 -- static attribute in GNAT.
7513 Analyze_And_Resolve (N, Standard_Boolean);
7514 Static := True;
7515 end Lock_Free;
7517 ----------
7518 -- Last --
7519 ----------
7521 when Attribute_Last => Last_Attr :
7522 begin
7523 Set_Bounds;
7525 if Compile_Time_Known_Value (Hi_Bound) then
7526 if Is_Real_Type (P_Type) then
7527 Fold_Ureal (N, Expr_Value_R (Hi_Bound), Static);
7528 else
7529 Fold_Uint (N, Expr_Value (Hi_Bound), Static);
7530 end if;
7532 -- Replace VAX Float_Type'Last with a reference to the temporary
7533 -- which represents the high bound of the type. This transformation
7534 -- is needed since the back end cannot evaluate 'Last on VAX.
7536 elsif Is_VAX_Float (P_Type)
7537 and then Nkind (Hi_Bound) = N_Identifier
7538 then
7539 Rewrite (N, New_Reference_To (Entity (Hi_Bound), Sloc (N)));
7540 Analyze (N);
7542 else
7543 Check_Concurrent_Discriminant (Hi_Bound);
7544 end if;
7545 end Last_Attr;
7547 ----------------
7548 -- Last_Valid --
7549 ----------------
7551 when Attribute_Last_Valid => Last_Valid :
7552 begin
7553 if Has_Predicates (P_Type)
7554 and then Present (Static_Predicate (P_Type))
7555 then
7556 declare
7557 LastN : constant Node_Id := Last (Static_Predicate (P_Type));
7558 begin
7559 if Nkind (LastN) = N_Range then
7560 Fold_Uint (N, Expr_Value (High_Bound (LastN)), Static);
7561 else
7562 Fold_Uint (N, Expr_Value (LastN), Static);
7563 end if;
7564 end;
7566 else
7567 Set_Bounds;
7568 Fold_Uint (N, Expr_Value (Hi_Bound), Static);
7569 end if;
7570 end Last_Valid;
7572 ------------------
7573 -- Leading_Part --
7574 ------------------
7576 when Attribute_Leading_Part =>
7577 Fold_Ureal
7579 Eval_Fat.Leading_Part
7580 (P_Base_Type, Expr_Value_R (E1), Expr_Value (E2)),
7581 Static);
7583 ------------
7584 -- Length --
7585 ------------
7587 when Attribute_Length => Length : declare
7588 Ind : Node_Id;
7590 begin
7591 -- If any index type is a formal type, or derived from one, the
7592 -- bounds are not static. Treating them as static can produce
7593 -- spurious warnings or improper constant folding.
7595 Ind := First_Index (P_Type);
7596 while Present (Ind) loop
7597 if Is_Generic_Type (Root_Type (Etype (Ind))) then
7598 return;
7599 end if;
7601 Next_Index (Ind);
7602 end loop;
7604 Set_Bounds;
7606 -- For two compile time values, we can compute length
7608 if Compile_Time_Known_Value (Lo_Bound)
7609 and then Compile_Time_Known_Value (Hi_Bound)
7610 then
7611 Fold_Uint (N,
7612 UI_Max (0, 1 + (Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound))),
7613 True);
7614 end if;
7616 -- One more case is where Hi_Bound and Lo_Bound are compile-time
7617 -- comparable, and we can figure out the difference between them.
7619 declare
7620 Diff : aliased Uint;
7622 begin
7623 case
7624 Compile_Time_Compare
7625 (Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
7627 when EQ =>
7628 Fold_Uint (N, Uint_1, False);
7630 when GT =>
7631 Fold_Uint (N, Uint_0, False);
7633 when LT =>
7634 if Diff /= No_Uint then
7635 Fold_Uint (N, Diff + 1, False);
7636 end if;
7638 when others =>
7639 null;
7640 end case;
7641 end;
7642 end Length;
7644 ----------------
7645 -- Loop_Entry --
7646 ----------------
7648 -- Loop_Entry acts as an alias of a constant initialized to the prefix
7649 -- of the said attribute at the point of entry into the related loop. As
7650 -- such, the attribute reference does not need to be evaluated because
7651 -- the prefix is the one that is evaluted.
7653 when Attribute_Loop_Entry =>
7654 null;
7656 -------------
7657 -- Machine --
7658 -------------
7660 when Attribute_Machine =>
7661 Fold_Ureal
7663 Eval_Fat.Machine
7664 (P_Base_Type, Expr_Value_R (E1), Eval_Fat.Round, N),
7665 Static);
7667 ------------------
7668 -- Machine_Emax --
7669 ------------------
7671 when Attribute_Machine_Emax =>
7672 Fold_Uint (N, Machine_Emax_Value (P_Type), Static);
7674 ------------------
7675 -- Machine_Emin --
7676 ------------------
7678 when Attribute_Machine_Emin =>
7679 Fold_Uint (N, Machine_Emin_Value (P_Type), Static);
7681 ----------------------
7682 -- Machine_Mantissa --
7683 ----------------------
7685 when Attribute_Machine_Mantissa =>
7686 Fold_Uint (N, Machine_Mantissa_Value (P_Type), Static);
7688 -----------------------
7689 -- Machine_Overflows --
7690 -----------------------
7692 when Attribute_Machine_Overflows =>
7694 -- Always true for fixed-point
7696 if Is_Fixed_Point_Type (P_Type) then
7697 Fold_Uint (N, True_Value, True);
7699 -- Floating point case
7701 else
7702 Fold_Uint (N,
7703 UI_From_Int (Boolean'Pos (Machine_Overflows_On_Target)),
7704 True);
7705 end if;
7707 -------------------
7708 -- Machine_Radix --
7709 -------------------
7711 when Attribute_Machine_Radix =>
7712 if Is_Fixed_Point_Type (P_Type) then
7713 if Is_Decimal_Fixed_Point_Type (P_Type)
7714 and then Machine_Radix_10 (P_Type)
7715 then
7716 Fold_Uint (N, Uint_10, True);
7717 else
7718 Fold_Uint (N, Uint_2, True);
7719 end if;
7721 -- All floating-point type always have radix 2
7723 else
7724 Fold_Uint (N, Uint_2, True);
7725 end if;
7727 ----------------------
7728 -- Machine_Rounding --
7729 ----------------------
7731 -- Note: for the folding case, it is fine to treat Machine_Rounding
7732 -- exactly the same way as Rounding, since this is one of the allowed
7733 -- behaviors, and performance is not an issue here. It might be a bit
7734 -- better to give the same result as it would give at run time, even
7735 -- though the non-determinism is certainly permitted.
7737 when Attribute_Machine_Rounding =>
7738 Fold_Ureal
7739 (N, Eval_Fat.Rounding (P_Base_Type, Expr_Value_R (E1)), Static);
7741 --------------------
7742 -- Machine_Rounds --
7743 --------------------
7745 when Attribute_Machine_Rounds =>
7747 -- Always False for fixed-point
7749 if Is_Fixed_Point_Type (P_Type) then
7750 Fold_Uint (N, False_Value, True);
7752 -- Else yield proper floating-point result
7754 else
7755 Fold_Uint
7756 (N, UI_From_Int (Boolean'Pos (Machine_Rounds_On_Target)), True);
7757 end if;
7759 ------------------
7760 -- Machine_Size --
7761 ------------------
7763 -- Note: Machine_Size is identical to Object_Size
7765 when Attribute_Machine_Size => Machine_Size : declare
7766 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
7768 begin
7769 if Known_Esize (P_TypeA) then
7770 Fold_Uint (N, Esize (P_TypeA), True);
7771 end if;
7772 end Machine_Size;
7774 --------------
7775 -- Mantissa --
7776 --------------
7778 when Attribute_Mantissa =>
7780 -- Fixed-point mantissa
7782 if Is_Fixed_Point_Type (P_Type) then
7784 -- Compile time foldable case
7786 if Compile_Time_Known_Value (Type_Low_Bound (P_Type))
7787 and then
7788 Compile_Time_Known_Value (Type_High_Bound (P_Type))
7789 then
7790 -- The calculation of the obsolete Ada 83 attribute Mantissa
7791 -- is annoying, because of AI00143, quoted here:
7793 -- !question 84-01-10
7795 -- Consider the model numbers for F:
7797 -- type F is delta 1.0 range -7.0 .. 8.0;
7799 -- The wording requires that F'MANTISSA be the SMALLEST
7800 -- integer number for which each bound of the specified
7801 -- range is either a model number or lies at most small
7802 -- distant from a model number. This means F'MANTISSA
7803 -- is required to be 3 since the range -7.0 .. 7.0 fits
7804 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
7805 -- number, namely, 7. Is this analysis correct? Note that
7806 -- this implies the upper bound of the range is not
7807 -- represented as a model number.
7809 -- !response 84-03-17
7811 -- The analysis is correct. The upper and lower bounds for
7812 -- a fixed point type can lie outside the range of model
7813 -- numbers.
7815 declare
7816 Siz : Uint;
7817 LBound : Ureal;
7818 UBound : Ureal;
7819 Bound : Ureal;
7820 Max_Man : Uint;
7822 begin
7823 LBound := Expr_Value_R (Type_Low_Bound (P_Type));
7824 UBound := Expr_Value_R (Type_High_Bound (P_Type));
7825 Bound := UR_Max (UR_Abs (LBound), UR_Abs (UBound));
7826 Max_Man := UR_Trunc (Bound / Small_Value (P_Type));
7828 -- If the Bound is exactly a model number, i.e. a multiple
7829 -- of Small, then we back it off by one to get the integer
7830 -- value that must be representable.
7832 if Small_Value (P_Type) * Max_Man = Bound then
7833 Max_Man := Max_Man - 1;
7834 end if;
7836 -- Now find corresponding size = Mantissa value
7838 Siz := Uint_0;
7839 while 2 ** Siz < Max_Man loop
7840 Siz := Siz + 1;
7841 end loop;
7843 Fold_Uint (N, Siz, True);
7844 end;
7846 else
7847 -- The case of dynamic bounds cannot be evaluated at compile
7848 -- time. Instead we use a runtime routine (see Exp_Attr).
7850 null;
7851 end if;
7853 -- Floating-point Mantissa
7855 else
7856 Fold_Uint (N, Mantissa, True);
7857 end if;
7859 ---------
7860 -- Max --
7861 ---------
7863 when Attribute_Max => Max :
7864 begin
7865 if Is_Real_Type (P_Type) then
7866 Fold_Ureal
7867 (N, UR_Max (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
7868 else
7869 Fold_Uint (N, UI_Max (Expr_Value (E1), Expr_Value (E2)), Static);
7870 end if;
7871 end Max;
7873 ----------------------------------
7874 -- Max_Alignment_For_Allocation --
7875 ----------------------------------
7877 -- Max_Alignment_For_Allocation is usually the Alignment. However,
7878 -- arrays are allocated with dope, so we need to take into account both
7879 -- the alignment of the array, which comes from the component alignment,
7880 -- and the alignment of the dope. Also, if the alignment is unknown, we
7881 -- use the max (it's OK to be pessimistic).
7883 when Attribute_Max_Alignment_For_Allocation =>
7884 declare
7885 A : Uint := UI_From_Int (Ttypes.Maximum_Alignment);
7886 begin
7887 if Known_Alignment (P_Type) and then
7888 (not Is_Array_Type (P_Type) or else Alignment (P_Type) > A)
7889 then
7890 A := Alignment (P_Type);
7891 end if;
7893 Fold_Uint (N, A, Static);
7894 end;
7896 ----------------------------------
7897 -- Max_Size_In_Storage_Elements --
7898 ----------------------------------
7900 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
7901 -- Storage_Unit boundary. We can fold any cases for which the size
7902 -- is known by the front end.
7904 when Attribute_Max_Size_In_Storage_Elements =>
7905 if Known_Esize (P_Type) then
7906 Fold_Uint (N,
7907 (Esize (P_Type) + System_Storage_Unit - 1) /
7908 System_Storage_Unit,
7909 Static);
7910 end if;
7912 --------------------
7913 -- Mechanism_Code --
7914 --------------------
7916 when Attribute_Mechanism_Code =>
7917 declare
7918 Val : Int;
7919 Formal : Entity_Id;
7920 Mech : Mechanism_Type;
7922 begin
7923 if No (E1) then
7924 Mech := Mechanism (P_Entity);
7926 else
7927 Val := UI_To_Int (Expr_Value (E1));
7929 Formal := First_Formal (P_Entity);
7930 for J in 1 .. Val - 1 loop
7931 Next_Formal (Formal);
7932 end loop;
7933 Mech := Mechanism (Formal);
7934 end if;
7936 if Mech < 0 then
7937 Fold_Uint (N, UI_From_Int (Int (-Mech)), True);
7938 end if;
7939 end;
7941 ---------
7942 -- Min --
7943 ---------
7945 when Attribute_Min => Min :
7946 begin
7947 if Is_Real_Type (P_Type) then
7948 Fold_Ureal
7949 (N, UR_Min (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
7950 else
7951 Fold_Uint
7952 (N, UI_Min (Expr_Value (E1), Expr_Value (E2)), Static);
7953 end if;
7954 end Min;
7956 ---------
7957 -- Mod --
7958 ---------
7960 when Attribute_Mod =>
7961 Fold_Uint
7962 (N, UI_Mod (Expr_Value (E1), Modulus (P_Base_Type)), Static);
7964 -----------
7965 -- Model --
7966 -----------
7968 when Attribute_Model =>
7969 Fold_Ureal
7970 (N, Eval_Fat.Model (P_Base_Type, Expr_Value_R (E1)), Static);
7972 ----------------
7973 -- Model_Emin --
7974 ----------------
7976 when Attribute_Model_Emin =>
7977 Fold_Uint (N, Model_Emin_Value (P_Base_Type), Static);
7979 -------------------
7980 -- Model_Epsilon --
7981 -------------------
7983 when Attribute_Model_Epsilon =>
7984 Fold_Ureal (N, Model_Epsilon_Value (P_Base_Type), Static);
7986 --------------------
7987 -- Model_Mantissa --
7988 --------------------
7990 when Attribute_Model_Mantissa =>
7991 Fold_Uint (N, Model_Mantissa_Value (P_Base_Type), Static);
7993 -----------------
7994 -- Model_Small --
7995 -----------------
7997 when Attribute_Model_Small =>
7998 Fold_Ureal (N, Model_Small_Value (P_Base_Type), Static);
8000 -------------
8001 -- Modulus --
8002 -------------
8004 when Attribute_Modulus =>
8005 Fold_Uint (N, Modulus (P_Type), True);
8007 --------------------
8008 -- Null_Parameter --
8009 --------------------
8011 -- Cannot fold, we know the value sort of, but the whole point is
8012 -- that there is no way to talk about this imaginary value except
8013 -- by using the attribute, so we leave it the way it is.
8015 when Attribute_Null_Parameter =>
8016 null;
8018 -----------------
8019 -- Object_Size --
8020 -----------------
8022 -- The Object_Size attribute for a type returns the Esize of the
8023 -- type and can be folded if this value is known.
8025 when Attribute_Object_Size => Object_Size : declare
8026 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
8028 begin
8029 if Known_Esize (P_TypeA) then
8030 Fold_Uint (N, Esize (P_TypeA), True);
8031 end if;
8032 end Object_Size;
8034 ----------------------
8035 -- Overlaps_Storage --
8036 ----------------------
8038 when Attribute_Overlaps_Storage =>
8039 null;
8041 -------------------------
8042 -- Passed_By_Reference --
8043 -------------------------
8045 -- Scalar types are never passed by reference
8047 when Attribute_Passed_By_Reference =>
8048 Fold_Uint (N, False_Value, True);
8050 ---------
8051 -- Pos --
8052 ---------
8054 when Attribute_Pos =>
8055 Fold_Uint (N, Expr_Value (E1), True);
8057 ----------
8058 -- Pred --
8059 ----------
8061 when Attribute_Pred => Pred :
8062 begin
8063 -- Floating-point case
8065 if Is_Floating_Point_Type (P_Type) then
8066 Fold_Ureal
8067 (N, Eval_Fat.Pred (P_Base_Type, Expr_Value_R (E1)), Static);
8069 -- Fixed-point case
8071 elsif Is_Fixed_Point_Type (P_Type) then
8072 Fold_Ureal
8073 (N, Expr_Value_R (E1) - Small_Value (P_Type), True);
8075 -- Modular integer case (wraps)
8077 elsif Is_Modular_Integer_Type (P_Type) then
8078 Fold_Uint (N, (Expr_Value (E1) - 1) mod Modulus (P_Type), Static);
8080 -- Other scalar cases
8082 else
8083 pragma Assert (Is_Scalar_Type (P_Type));
8085 if Is_Enumeration_Type (P_Type)
8086 and then Expr_Value (E1) =
8087 Expr_Value (Type_Low_Bound (P_Base_Type))
8088 then
8089 Apply_Compile_Time_Constraint_Error
8090 (N, "Pred of `&''First`",
8091 CE_Overflow_Check_Failed,
8092 Ent => P_Base_Type,
8093 Warn => not Static);
8095 Check_Expressions;
8096 return;
8097 end if;
8099 Fold_Uint (N, Expr_Value (E1) - 1, Static);
8100 end if;
8101 end Pred;
8103 -----------
8104 -- Range --
8105 -----------
8107 -- No processing required, because by this stage, Range has been
8108 -- replaced by First .. Last, so this branch can never be taken.
8110 when Attribute_Range =>
8111 raise Program_Error;
8113 ------------------
8114 -- Range_Length --
8115 ------------------
8117 when Attribute_Range_Length =>
8118 Set_Bounds;
8120 -- Can fold if both bounds are compile time known
8122 if Compile_Time_Known_Value (Hi_Bound)
8123 and then Compile_Time_Known_Value (Lo_Bound)
8124 then
8125 Fold_Uint (N,
8126 UI_Max
8127 (0, Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound) + 1),
8128 Static);
8129 end if;
8131 -- One more case is where Hi_Bound and Lo_Bound are compile-time
8132 -- comparable, and we can figure out the difference between them.
8134 declare
8135 Diff : aliased Uint;
8137 begin
8138 case
8139 Compile_Time_Compare
8140 (Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
8142 when EQ =>
8143 Fold_Uint (N, Uint_1, False);
8145 when GT =>
8146 Fold_Uint (N, Uint_0, False);
8148 when LT =>
8149 if Diff /= No_Uint then
8150 Fold_Uint (N, Diff + 1, False);
8151 end if;
8153 when others =>
8154 null;
8155 end case;
8156 end;
8158 ---------
8159 -- Ref --
8160 ---------
8162 when Attribute_Ref =>
8163 Fold_Uint (N, Expr_Value (E1), True);
8165 ---------------
8166 -- Remainder --
8167 ---------------
8169 when Attribute_Remainder => Remainder : declare
8170 X : constant Ureal := Expr_Value_R (E1);
8171 Y : constant Ureal := Expr_Value_R (E2);
8173 begin
8174 if UR_Is_Zero (Y) then
8175 Apply_Compile_Time_Constraint_Error
8176 (N, "division by zero in Remainder",
8177 CE_Overflow_Check_Failed,
8178 Warn => not Static);
8180 Check_Expressions;
8181 return;
8182 end if;
8184 Fold_Ureal (N, Eval_Fat.Remainder (P_Base_Type, X, Y), Static);
8185 end Remainder;
8187 -----------------
8188 -- Restriction --
8189 -----------------
8191 when Attribute_Restriction_Set => Restriction_Set : declare
8192 begin
8193 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
8194 Set_Is_Static_Expression (N);
8195 end Restriction_Set;
8197 -----------
8198 -- Round --
8199 -----------
8201 when Attribute_Round => Round :
8202 declare
8203 Sr : Ureal;
8204 Si : Uint;
8206 begin
8207 -- First we get the (exact result) in units of small
8209 Sr := Expr_Value_R (E1) / Small_Value (C_Type);
8211 -- Now round that exactly to an integer
8213 Si := UR_To_Uint (Sr);
8215 -- Finally the result is obtained by converting back to real
8217 Fold_Ureal (N, Si * Small_Value (C_Type), Static);
8218 end Round;
8220 --------------
8221 -- Rounding --
8222 --------------
8224 when Attribute_Rounding =>
8225 Fold_Ureal
8226 (N, Eval_Fat.Rounding (P_Base_Type, Expr_Value_R (E1)), Static);
8228 ---------------
8229 -- Safe_Emax --
8230 ---------------
8232 when Attribute_Safe_Emax =>
8233 Fold_Uint (N, Safe_Emax_Value (P_Type), Static);
8235 ----------------
8236 -- Safe_First --
8237 ----------------
8239 when Attribute_Safe_First =>
8240 Fold_Ureal (N, Safe_First_Value (P_Type), Static);
8242 ----------------
8243 -- Safe_Large --
8244 ----------------
8246 when Attribute_Safe_Large =>
8247 if Is_Fixed_Point_Type (P_Type) then
8248 Fold_Ureal
8249 (N, Expr_Value_R (Type_High_Bound (P_Base_Type)), Static);
8250 else
8251 Fold_Ureal (N, Safe_Last_Value (P_Type), Static);
8252 end if;
8254 ---------------
8255 -- Safe_Last --
8256 ---------------
8258 when Attribute_Safe_Last =>
8259 Fold_Ureal (N, Safe_Last_Value (P_Type), Static);
8261 ----------------
8262 -- Safe_Small --
8263 ----------------
8265 when Attribute_Safe_Small =>
8267 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
8268 -- for fixed-point, since is the same as Small, but we implement
8269 -- it for backwards compatibility.
8271 if Is_Fixed_Point_Type (P_Type) then
8272 Fold_Ureal (N, Small_Value (P_Type), Static);
8274 -- Ada 83 Safe_Small for floating-point cases
8276 else
8277 Fold_Ureal (N, Model_Small_Value (P_Type), Static);
8278 end if;
8280 ------------------
8281 -- Same_Storage --
8282 ------------------
8284 when Attribute_Same_Storage =>
8285 null;
8287 -----------
8288 -- Scale --
8289 -----------
8291 when Attribute_Scale =>
8292 Fold_Uint (N, Scale_Value (P_Type), True);
8294 -------------
8295 -- Scaling --
8296 -------------
8298 when Attribute_Scaling =>
8299 Fold_Ureal
8301 Eval_Fat.Scaling
8302 (P_Base_Type, Expr_Value_R (E1), Expr_Value (E2)),
8303 Static);
8305 ------------------
8306 -- Signed_Zeros --
8307 ------------------
8309 when Attribute_Signed_Zeros =>
8310 Fold_Uint
8311 (N, UI_From_Int (Boolean'Pos (Has_Signed_Zeros (P_Type))), Static);
8313 ----------
8314 -- Size --
8315 ----------
8317 -- Size attribute returns the RM size. All scalar types can be folded,
8318 -- as well as any types for which the size is known by the front end,
8319 -- including any type for which a size attribute is specified.
8321 when Attribute_Size | Attribute_VADS_Size => Size : declare
8322 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
8324 begin
8325 if RM_Size (P_TypeA) /= Uint_0 then
8327 -- VADS_Size case
8329 if Id = Attribute_VADS_Size or else Use_VADS_Size then
8330 declare
8331 S : constant Node_Id := Size_Clause (P_TypeA);
8333 begin
8334 -- If a size clause applies, then use the size from it.
8335 -- This is one of the rare cases where we can use the
8336 -- Size_Clause field for a subtype when Has_Size_Clause
8337 -- is False. Consider:
8339 -- type x is range 1 .. 64;
8340 -- for x'size use 12;
8341 -- subtype y is x range 0 .. 3;
8343 -- Here y has a size clause inherited from x, but normally
8344 -- it does not apply, and y'size is 2. However, y'VADS_Size
8345 -- is indeed 12 and not 2.
8347 if Present (S)
8348 and then Is_OK_Static_Expression (Expression (S))
8349 then
8350 Fold_Uint (N, Expr_Value (Expression (S)), True);
8352 -- If no size is specified, then we simply use the object
8353 -- size in the VADS_Size case (e.g. Natural'Size is equal
8354 -- to Integer'Size, not one less).
8356 else
8357 Fold_Uint (N, Esize (P_TypeA), True);
8358 end if;
8359 end;
8361 -- Normal case (Size) in which case we want the RM_Size
8363 else
8364 Fold_Uint (N,
8365 RM_Size (P_TypeA),
8366 Static and then Is_Discrete_Type (P_TypeA));
8367 end if;
8368 end if;
8369 end Size;
8371 -----------
8372 -- Small --
8373 -----------
8375 when Attribute_Small =>
8377 -- The floating-point case is present only for Ada 83 compatibility.
8378 -- Note that strictly this is an illegal addition, since we are
8379 -- extending an Ada 95 defined attribute, but we anticipate an
8380 -- ARG ruling that will permit this.
8382 if Is_Floating_Point_Type (P_Type) then
8384 -- Ada 83 attribute is defined as (RM83 3.5.8)
8386 -- T'Small = 2.0**(-T'Emax - 1)
8388 -- where
8390 -- T'Emax = 4 * T'Mantissa
8392 Fold_Ureal (N, Ureal_2 ** ((-(4 * Mantissa)) - 1), Static);
8394 -- Normal Ada 95 fixed-point case
8396 else
8397 Fold_Ureal (N, Small_Value (P_Type), True);
8398 end if;
8400 -----------------
8401 -- Stream_Size --
8402 -----------------
8404 when Attribute_Stream_Size =>
8405 null;
8407 ----------
8408 -- Succ --
8409 ----------
8411 when Attribute_Succ => Succ :
8412 begin
8413 -- Floating-point case
8415 if Is_Floating_Point_Type (P_Type) then
8416 Fold_Ureal
8417 (N, Eval_Fat.Succ (P_Base_Type, Expr_Value_R (E1)), Static);
8419 -- Fixed-point case
8421 elsif Is_Fixed_Point_Type (P_Type) then
8422 Fold_Ureal (N, Expr_Value_R (E1) + Small_Value (P_Type), Static);
8424 -- Modular integer case (wraps)
8426 elsif Is_Modular_Integer_Type (P_Type) then
8427 Fold_Uint (N, (Expr_Value (E1) + 1) mod Modulus (P_Type), Static);
8429 -- Other scalar cases
8431 else
8432 pragma Assert (Is_Scalar_Type (P_Type));
8434 if Is_Enumeration_Type (P_Type)
8435 and then Expr_Value (E1) =
8436 Expr_Value (Type_High_Bound (P_Base_Type))
8437 then
8438 Apply_Compile_Time_Constraint_Error
8439 (N, "Succ of `&''Last`",
8440 CE_Overflow_Check_Failed,
8441 Ent => P_Base_Type,
8442 Warn => not Static);
8444 Check_Expressions;
8445 return;
8446 else
8447 Fold_Uint (N, Expr_Value (E1) + 1, Static);
8448 end if;
8449 end if;
8450 end Succ;
8452 ----------------
8453 -- Truncation --
8454 ----------------
8456 when Attribute_Truncation =>
8457 Fold_Ureal
8459 Eval_Fat.Truncation (P_Base_Type, Expr_Value_R (E1)),
8460 Static);
8462 ----------------
8463 -- Type_Class --
8464 ----------------
8466 when Attribute_Type_Class => Type_Class : declare
8467 Typ : constant Entity_Id := Underlying_Type (P_Base_Type);
8468 Id : RE_Id;
8470 begin
8471 if Is_Descendent_Of_Address (Typ) then
8472 Id := RE_Type_Class_Address;
8474 elsif Is_Enumeration_Type (Typ) then
8475 Id := RE_Type_Class_Enumeration;
8477 elsif Is_Integer_Type (Typ) then
8478 Id := RE_Type_Class_Integer;
8480 elsif Is_Fixed_Point_Type (Typ) then
8481 Id := RE_Type_Class_Fixed_Point;
8483 elsif Is_Floating_Point_Type (Typ) then
8484 Id := RE_Type_Class_Floating_Point;
8486 elsif Is_Array_Type (Typ) then
8487 Id := RE_Type_Class_Array;
8489 elsif Is_Record_Type (Typ) then
8490 Id := RE_Type_Class_Record;
8492 elsif Is_Access_Type (Typ) then
8493 Id := RE_Type_Class_Access;
8495 elsif Is_Enumeration_Type (Typ) then
8496 Id := RE_Type_Class_Enumeration;
8498 elsif Is_Task_Type (Typ) then
8499 Id := RE_Type_Class_Task;
8501 -- We treat protected types like task types. It would make more
8502 -- sense to have another enumeration value, but after all the
8503 -- whole point of this feature is to be exactly DEC compatible,
8504 -- and changing the type Type_Class would not meet this requirement.
8506 elsif Is_Protected_Type (Typ) then
8507 Id := RE_Type_Class_Task;
8509 -- Not clear if there are any other possibilities, but if there
8510 -- are, then we will treat them as the address case.
8512 else
8513 Id := RE_Type_Class_Address;
8514 end if;
8516 Rewrite (N, New_Occurrence_Of (RTE (Id), Loc));
8517 end Type_Class;
8519 -----------------------
8520 -- Unbiased_Rounding --
8521 -----------------------
8523 when Attribute_Unbiased_Rounding =>
8524 Fold_Ureal
8526 Eval_Fat.Unbiased_Rounding (P_Base_Type, Expr_Value_R (E1)),
8527 Static);
8529 -------------------------
8530 -- Unconstrained_Array --
8531 -------------------------
8533 when Attribute_Unconstrained_Array => Unconstrained_Array : declare
8534 Typ : constant Entity_Id := Underlying_Type (P_Type);
8536 begin
8537 Rewrite (N, New_Occurrence_Of (
8538 Boolean_Literals (
8539 Is_Array_Type (P_Type)
8540 and then not Is_Constrained (Typ)), Loc));
8542 -- Analyze and resolve as boolean, note that this attribute is
8543 -- a static attribute in GNAT.
8545 Analyze_And_Resolve (N, Standard_Boolean);
8546 Static := True;
8547 end Unconstrained_Array;
8549 -- Attribute Update is never static
8551 ------------
8552 -- Update --
8553 ------------
8555 when Attribute_Update =>
8556 null;
8558 ---------------
8559 -- VADS_Size --
8560 ---------------
8562 -- Processing is shared with Size
8564 ---------
8565 -- Val --
8566 ---------
8568 when Attribute_Val => Val :
8569 begin
8570 if Expr_Value (E1) < Expr_Value (Type_Low_Bound (P_Base_Type))
8571 or else
8572 Expr_Value (E1) > Expr_Value (Type_High_Bound (P_Base_Type))
8573 then
8574 Apply_Compile_Time_Constraint_Error
8575 (N, "Val expression out of range",
8576 CE_Range_Check_Failed,
8577 Warn => not Static);
8579 Check_Expressions;
8580 return;
8582 else
8583 Fold_Uint (N, Expr_Value (E1), Static);
8584 end if;
8585 end Val;
8587 ----------------
8588 -- Value_Size --
8589 ----------------
8591 -- The Value_Size attribute for a type returns the RM size of the
8592 -- type. This an always be folded for scalar types, and can also
8593 -- be folded for non-scalar types if the size is set.
8595 when Attribute_Value_Size => Value_Size : declare
8596 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
8597 begin
8598 if RM_Size (P_TypeA) /= Uint_0 then
8599 Fold_Uint (N, RM_Size (P_TypeA), True);
8600 end if;
8601 end Value_Size;
8603 -------------
8604 -- Version --
8605 -------------
8607 -- Version can never be static
8609 when Attribute_Version =>
8610 null;
8612 ----------------
8613 -- Wide_Image --
8614 ----------------
8616 -- Wide_Image is a scalar attribute, but is never static, because it
8617 -- is not a static function (having a non-scalar argument (RM 4.9(22))
8619 when Attribute_Wide_Image =>
8620 null;
8622 ---------------------
8623 -- Wide_Wide_Image --
8624 ---------------------
8626 -- Wide_Wide_Image is a scalar attribute but is never static, because it
8627 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
8629 when Attribute_Wide_Wide_Image =>
8630 null;
8632 ---------------------
8633 -- Wide_Wide_Width --
8634 ---------------------
8636 -- Processing for Wide_Wide_Width is combined with Width
8638 ----------------
8639 -- Wide_Width --
8640 ----------------
8642 -- Processing for Wide_Width is combined with Width
8644 -----------
8645 -- Width --
8646 -----------
8648 -- This processing also handles the case of Wide_[Wide_]Width
8650 when Attribute_Width |
8651 Attribute_Wide_Width |
8652 Attribute_Wide_Wide_Width => Width :
8653 begin
8654 if Compile_Time_Known_Bounds (P_Type) then
8656 -- Floating-point types
8658 if Is_Floating_Point_Type (P_Type) then
8660 -- Width is zero for a null range (RM 3.5 (38))
8662 if Expr_Value_R (Type_High_Bound (P_Type)) <
8663 Expr_Value_R (Type_Low_Bound (P_Type))
8664 then
8665 Fold_Uint (N, Uint_0, True);
8667 else
8668 -- For floating-point, we have +N.dddE+nnn where length
8669 -- of ddd is determined by type'Digits - 1, but is one
8670 -- if Digits is one (RM 3.5 (33)).
8672 -- nnn is set to 2 for Short_Float and Float (32 bit
8673 -- floats), and 3 for Long_Float and Long_Long_Float.
8674 -- For machines where Long_Long_Float is the IEEE
8675 -- extended precision type, the exponent takes 4 digits.
8677 declare
8678 Len : Int :=
8679 Int'Max (2, UI_To_Int (Digits_Value (P_Type)));
8681 begin
8682 if Esize (P_Type) <= 32 then
8683 Len := Len + 6;
8684 elsif Esize (P_Type) = 64 then
8685 Len := Len + 7;
8686 else
8687 Len := Len + 8;
8688 end if;
8690 Fold_Uint (N, UI_From_Int (Len), True);
8691 end;
8692 end if;
8694 -- Fixed-point types
8696 elsif Is_Fixed_Point_Type (P_Type) then
8698 -- Width is zero for a null range (RM 3.5 (38))
8700 if Expr_Value (Type_High_Bound (P_Type)) <
8701 Expr_Value (Type_Low_Bound (P_Type))
8702 then
8703 Fold_Uint (N, Uint_0, True);
8705 -- The non-null case depends on the specific real type
8707 else
8708 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
8710 Fold_Uint
8711 (N, UI_From_Int (Fore_Value + 1) + Aft_Value (P_Type),
8712 True);
8713 end if;
8715 -- Discrete types
8717 else
8718 declare
8719 R : constant Entity_Id := Root_Type (P_Type);
8720 Lo : constant Uint := Expr_Value (Type_Low_Bound (P_Type));
8721 Hi : constant Uint := Expr_Value (Type_High_Bound (P_Type));
8722 W : Nat;
8723 Wt : Nat;
8724 T : Uint;
8725 L : Node_Id;
8726 C : Character;
8728 begin
8729 -- Empty ranges
8731 if Lo > Hi then
8732 W := 0;
8734 -- Width for types derived from Standard.Character
8735 -- and Standard.Wide_[Wide_]Character.
8737 elsif Is_Standard_Character_Type (P_Type) then
8738 W := 0;
8740 -- Set W larger if needed
8742 for J in UI_To_Int (Lo) .. UI_To_Int (Hi) loop
8744 -- All wide characters look like Hex_hhhhhhhh
8746 if J > 255 then
8748 -- No need to compute this more than once!
8750 exit;
8752 else
8753 C := Character'Val (J);
8755 -- Test for all cases where Character'Image
8756 -- yields an image that is longer than three
8757 -- characters. First the cases of Reserved_xxx
8758 -- names (length = 12).
8760 case C is
8761 when Reserved_128 | Reserved_129 |
8762 Reserved_132 | Reserved_153
8763 => Wt := 12;
8765 when BS | HT | LF | VT | FF | CR |
8766 SO | SI | EM | FS | GS | RS |
8767 US | RI | MW | ST | PM
8768 => Wt := 2;
8770 when NUL | SOH | STX | ETX | EOT |
8771 ENQ | ACK | BEL | DLE | DC1 |
8772 DC2 | DC3 | DC4 | NAK | SYN |
8773 ETB | CAN | SUB | ESC | DEL |
8774 BPH | NBH | NEL | SSA | ESA |
8775 HTS | HTJ | VTS | PLD | PLU |
8776 SS2 | SS3 | DCS | PU1 | PU2 |
8777 STS | CCH | SPA | EPA | SOS |
8778 SCI | CSI | OSC | APC
8779 => Wt := 3;
8781 when Space .. Tilde |
8782 No_Break_Space .. LC_Y_Diaeresis
8784 -- Special case of soft hyphen in Ada 2005
8786 if C = Character'Val (16#AD#)
8787 and then Ada_Version >= Ada_2005
8788 then
8789 Wt := 11;
8790 else
8791 Wt := 3;
8792 end if;
8793 end case;
8795 W := Int'Max (W, Wt);
8796 end if;
8797 end loop;
8799 -- Width for types derived from Standard.Boolean
8801 elsif R = Standard_Boolean then
8802 if Lo = 0 then
8803 W := 5; -- FALSE
8804 else
8805 W := 4; -- TRUE
8806 end if;
8808 -- Width for integer types
8810 elsif Is_Integer_Type (P_Type) then
8811 T := UI_Max (abs Lo, abs Hi);
8813 W := 2;
8814 while T >= 10 loop
8815 W := W + 1;
8816 T := T / 10;
8817 end loop;
8819 -- User declared enum type with discard names
8821 elsif Discard_Names (R) then
8823 -- If range is null, result is zero, that has already
8824 -- been dealt with, so what we need is the power of ten
8825 -- that accomodates the Pos of the largest value, which
8826 -- is the high bound of the range + one for the space.
8828 W := 1;
8829 T := Hi;
8830 while T /= 0 loop
8831 T := T / 10;
8832 W := W + 1;
8833 end loop;
8835 -- Only remaining possibility is user declared enum type
8836 -- with normal case of Discard_Names not active.
8838 else
8839 pragma Assert (Is_Enumeration_Type (P_Type));
8841 W := 0;
8842 L := First_Literal (P_Type);
8843 while Present (L) loop
8845 -- Only pay attention to in range characters
8847 if Lo <= Enumeration_Pos (L)
8848 and then Enumeration_Pos (L) <= Hi
8849 then
8850 -- For Width case, use decoded name
8852 if Id = Attribute_Width then
8853 Get_Decoded_Name_String (Chars (L));
8854 Wt := Nat (Name_Len);
8856 -- For Wide_[Wide_]Width, use encoded name, and
8857 -- then adjust for the encoding.
8859 else
8860 Get_Name_String (Chars (L));
8862 -- Character literals are always of length 3
8864 if Name_Buffer (1) = 'Q' then
8865 Wt := 3;
8867 -- Otherwise loop to adjust for upper/wide chars
8869 else
8870 Wt := Nat (Name_Len);
8872 for J in 1 .. Name_Len loop
8873 if Name_Buffer (J) = 'U' then
8874 Wt := Wt - 2;
8875 elsif Name_Buffer (J) = 'W' then
8876 Wt := Wt - 4;
8877 end if;
8878 end loop;
8879 end if;
8880 end if;
8882 W := Int'Max (W, Wt);
8883 end if;
8885 Next_Literal (L);
8886 end loop;
8887 end if;
8889 Fold_Uint (N, UI_From_Int (W), True);
8890 end;
8891 end if;
8892 end if;
8893 end Width;
8895 -- The following attributes denote functions that cannot be folded
8897 when Attribute_From_Any |
8898 Attribute_To_Any |
8899 Attribute_TypeCode =>
8900 null;
8902 -- The following attributes can never be folded, and furthermore we
8903 -- should not even have entered the case statement for any of these.
8904 -- Note that in some cases, the values have already been folded as
8905 -- a result of the processing in Analyze_Attribute.
8907 when Attribute_Abort_Signal |
8908 Attribute_Access |
8909 Attribute_Address |
8910 Attribute_Address_Size |
8911 Attribute_Asm_Input |
8912 Attribute_Asm_Output |
8913 Attribute_Base |
8914 Attribute_Bit_Order |
8915 Attribute_Bit_Position |
8916 Attribute_Callable |
8917 Attribute_Caller |
8918 Attribute_Class |
8919 Attribute_Code_Address |
8920 Attribute_Compiler_Version |
8921 Attribute_Count |
8922 Attribute_Default_Bit_Order |
8923 Attribute_Elaborated |
8924 Attribute_Elab_Body |
8925 Attribute_Elab_Spec |
8926 Attribute_Elab_Subp_Body |
8927 Attribute_Enabled |
8928 Attribute_External_Tag |
8929 Attribute_Fast_Math |
8930 Attribute_First_Bit |
8931 Attribute_Input |
8932 Attribute_Last_Bit |
8933 Attribute_Maximum_Alignment |
8934 Attribute_Old |
8935 Attribute_Output |
8936 Attribute_Partition_ID |
8937 Attribute_Pool_Address |
8938 Attribute_Position |
8939 Attribute_Priority |
8940 Attribute_Read |
8941 Attribute_Result |
8942 Attribute_Scalar_Storage_Order |
8943 Attribute_Simple_Storage_Pool |
8944 Attribute_Storage_Pool |
8945 Attribute_Storage_Size |
8946 Attribute_Storage_Unit |
8947 Attribute_Stub_Type |
8948 Attribute_System_Allocator_Alignment |
8949 Attribute_Tag |
8950 Attribute_Target_Name |
8951 Attribute_Terminated |
8952 Attribute_To_Address |
8953 Attribute_Type_Key |
8954 Attribute_UET_Address |
8955 Attribute_Unchecked_Access |
8956 Attribute_Universal_Literal_String |
8957 Attribute_Unrestricted_Access |
8958 Attribute_Valid |
8959 Attribute_Valid_Scalars |
8960 Attribute_Value |
8961 Attribute_Wchar_T_Size |
8962 Attribute_Wide_Value |
8963 Attribute_Wide_Wide_Value |
8964 Attribute_Word_Size |
8965 Attribute_Write =>
8967 raise Program_Error;
8968 end case;
8970 -- At the end of the case, one more check. If we did a static evaluation
8971 -- so that the result is now a literal, then set Is_Static_Expression
8972 -- in the constant only if the prefix type is a static subtype. For
8973 -- non-static subtypes, the folding is still OK, but not static.
8975 -- An exception is the GNAT attribute Constrained_Array which is
8976 -- defined to be a static attribute in all cases.
8978 if Nkind_In (N, N_Integer_Literal,
8979 N_Real_Literal,
8980 N_Character_Literal,
8981 N_String_Literal)
8982 or else (Is_Entity_Name (N)
8983 and then Ekind (Entity (N)) = E_Enumeration_Literal)
8984 then
8985 Set_Is_Static_Expression (N, Static);
8987 -- If this is still an attribute reference, then it has not been folded
8988 -- and that means that its expressions are in a non-static context.
8990 elsif Nkind (N) = N_Attribute_Reference then
8991 Check_Expressions;
8993 -- Note: the else case not covered here are odd cases where the
8994 -- processing has transformed the attribute into something other
8995 -- than a constant. Nothing more to do in such cases.
8997 else
8998 null;
8999 end if;
9000 end Eval_Attribute;
9002 ------------------------------
9003 -- Is_Anonymous_Tagged_Base --
9004 ------------------------------
9006 function Is_Anonymous_Tagged_Base
9007 (Anon : Entity_Id;
9008 Typ : Entity_Id)
9009 return Boolean
9011 begin
9012 return
9013 Anon = Current_Scope
9014 and then Is_Itype (Anon)
9015 and then Associated_Node_For_Itype (Anon) = Parent (Typ);
9016 end Is_Anonymous_Tagged_Base;
9018 --------------------------------
9019 -- Name_Implies_Lvalue_Prefix --
9020 --------------------------------
9022 function Name_Implies_Lvalue_Prefix (Nam : Name_Id) return Boolean is
9023 pragma Assert (Is_Attribute_Name (Nam));
9024 begin
9025 return Attribute_Name_Implies_Lvalue_Prefix (Get_Attribute_Id (Nam));
9026 end Name_Implies_Lvalue_Prefix;
9028 -----------------------
9029 -- Resolve_Attribute --
9030 -----------------------
9032 procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id) is
9033 Loc : constant Source_Ptr := Sloc (N);
9034 P : constant Node_Id := Prefix (N);
9035 Aname : constant Name_Id := Attribute_Name (N);
9036 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
9037 Btyp : constant Entity_Id := Base_Type (Typ);
9038 Des_Btyp : Entity_Id;
9039 Index : Interp_Index;
9040 It : Interp;
9041 Nom_Subt : Entity_Id;
9043 procedure Accessibility_Message;
9044 -- Error, or warning within an instance, if the static accessibility
9045 -- rules of 3.10.2 are violated.
9047 ---------------------------
9048 -- Accessibility_Message --
9049 ---------------------------
9051 procedure Accessibility_Message is
9052 Indic : Node_Id := Parent (Parent (N));
9054 begin
9055 -- In an instance, this is a runtime check, but one we
9056 -- know will fail, so generate an appropriate warning.
9058 if In_Instance_Body then
9059 Error_Msg_F
9060 ("??non-local pointer cannot point to local object", P);
9061 Error_Msg_F
9062 ("\??Program_Error will be raised at run time", P);
9063 Rewrite (N,
9064 Make_Raise_Program_Error (Loc,
9065 Reason => PE_Accessibility_Check_Failed));
9066 Set_Etype (N, Typ);
9067 return;
9069 else
9070 Error_Msg_F ("non-local pointer cannot point to local object", P);
9072 -- Check for case where we have a missing access definition
9074 if Is_Record_Type (Current_Scope)
9075 and then
9076 Nkind_In (Parent (N), N_Discriminant_Association,
9077 N_Index_Or_Discriminant_Constraint)
9078 then
9079 Indic := Parent (Parent (N));
9080 while Present (Indic)
9081 and then Nkind (Indic) /= N_Subtype_Indication
9082 loop
9083 Indic := Parent (Indic);
9084 end loop;
9086 if Present (Indic) then
9087 Error_Msg_NE
9088 ("\use an access definition for" &
9089 " the access discriminant of&",
9090 N, Entity (Subtype_Mark (Indic)));
9091 end if;
9092 end if;
9093 end if;
9094 end Accessibility_Message;
9096 -- Start of processing for Resolve_Attribute
9098 begin
9099 -- If error during analysis, no point in continuing, except for array
9100 -- types, where we get better recovery by using unconstrained indexes
9101 -- than nothing at all (see Check_Array_Type).
9103 if Error_Posted (N)
9104 and then Attr_Id /= Attribute_First
9105 and then Attr_Id /= Attribute_Last
9106 and then Attr_Id /= Attribute_Length
9107 and then Attr_Id /= Attribute_Range
9108 then
9109 return;
9110 end if;
9112 -- If attribute was universal type, reset to actual type
9114 if Etype (N) = Universal_Integer
9115 or else Etype (N) = Universal_Real
9116 then
9117 Set_Etype (N, Typ);
9118 end if;
9120 -- Remaining processing depends on attribute
9122 case Attr_Id is
9124 ------------
9125 -- Access --
9126 ------------
9128 -- For access attributes, if the prefix denotes an entity, it is
9129 -- interpreted as a name, never as a call. It may be overloaded,
9130 -- in which case resolution uses the profile of the context type.
9131 -- Otherwise prefix must be resolved.
9133 when Attribute_Access
9134 | Attribute_Unchecked_Access
9135 | Attribute_Unrestricted_Access =>
9137 Access_Attribute :
9138 begin
9139 if Is_Variable (P) then
9140 Note_Possible_Modification (P, Sure => False);
9141 end if;
9143 -- The following comes from a query by Adam Beneschan, concerning
9144 -- improper use of universal_access in equality tests involving
9145 -- anonymous access types. Another good reason for 'Ref, but
9146 -- for now disable the test, which breaks several filed tests.
9148 if Ekind (Typ) = E_Anonymous_Access_Type
9149 and then Nkind_In (Parent (N), N_Op_Eq, N_Op_Ne)
9150 and then False
9151 then
9152 Error_Msg_N ("need unique type to resolve 'Access", N);
9153 Error_Msg_N ("\qualify attribute with some access type", N);
9154 end if;
9156 if Is_Entity_Name (P) then
9157 if Is_Overloaded (P) then
9158 Get_First_Interp (P, Index, It);
9159 while Present (It.Nam) loop
9160 if Type_Conformant (Designated_Type (Typ), It.Nam) then
9161 Set_Entity (P, It.Nam);
9163 -- The prefix is definitely NOT overloaded anymore at
9164 -- this point, so we reset the Is_Overloaded flag to
9165 -- avoid any confusion when reanalyzing the node.
9167 Set_Is_Overloaded (P, False);
9168 Set_Is_Overloaded (N, False);
9169 Generate_Reference (Entity (P), P);
9170 exit;
9171 end if;
9173 Get_Next_Interp (Index, It);
9174 end loop;
9176 -- If Prefix is a subprogram name, it is frozen by this
9177 -- reference:
9179 -- If it is a type, there is nothing to resolve.
9180 -- If it is an object, complete its resolution.
9182 elsif Is_Overloadable (Entity (P)) then
9184 -- Avoid insertion of freeze actions in spec expression mode
9186 if not In_Spec_Expression then
9187 Freeze_Before (N, Entity (P));
9188 end if;
9190 elsif Is_Type (Entity (P)) then
9191 null;
9192 else
9193 Resolve (P);
9194 end if;
9196 Error_Msg_Name_1 := Aname;
9198 if not Is_Entity_Name (P) then
9199 null;
9201 elsif Is_Overloadable (Entity (P))
9202 and then Is_Abstract_Subprogram (Entity (P))
9203 then
9204 Error_Msg_F ("prefix of % attribute cannot be abstract", P);
9205 Set_Etype (N, Any_Type);
9207 elsif Convention (Entity (P)) = Convention_Intrinsic then
9208 if Ekind (Entity (P)) = E_Enumeration_Literal then
9209 Error_Msg_F
9210 ("prefix of % attribute cannot be enumeration literal",
9212 else
9213 Error_Msg_F
9214 ("prefix of % attribute cannot be intrinsic", P);
9215 end if;
9217 Set_Etype (N, Any_Type);
9218 end if;
9220 -- Assignments, return statements, components of aggregates,
9221 -- generic instantiations will require convention checks if
9222 -- the type is an access to subprogram. Given that there will
9223 -- also be accessibility checks on those, this is where the
9224 -- checks can eventually be centralized ???
9226 if Ekind_In (Btyp, E_Access_Subprogram_Type,
9227 E_Anonymous_Access_Subprogram_Type,
9228 E_Access_Protected_Subprogram_Type,
9229 E_Anonymous_Access_Protected_Subprogram_Type)
9230 then
9231 -- Deal with convention mismatch
9233 if Convention (Designated_Type (Btyp)) /=
9234 Convention (Entity (P))
9235 then
9236 Error_Msg_FE
9237 ("subprogram & has wrong convention", P, Entity (P));
9238 Error_Msg_FE
9239 ("\does not match convention of access type &",
9240 P, Btyp);
9242 if not Has_Convention_Pragma (Btyp) then
9243 Error_Msg_FE
9244 ("\probable missing pragma Convention for &",
9245 P, Btyp);
9246 end if;
9248 else
9249 Check_Subtype_Conformant
9250 (New_Id => Entity (P),
9251 Old_Id => Designated_Type (Btyp),
9252 Err_Loc => P);
9253 end if;
9255 if Attr_Id = Attribute_Unchecked_Access then
9256 Error_Msg_Name_1 := Aname;
9257 Error_Msg_F
9258 ("attribute% cannot be applied to a subprogram", P);
9260 elsif Aname = Name_Unrestricted_Access then
9261 null; -- Nothing to check
9263 -- Check the static accessibility rule of 3.10.2(32).
9264 -- This rule also applies within the private part of an
9265 -- instantiation. This rule does not apply to anonymous
9266 -- access-to-subprogram types in access parameters.
9268 elsif Attr_Id = Attribute_Access
9269 and then not In_Instance_Body
9270 and then
9271 (Ekind (Btyp) = E_Access_Subprogram_Type
9272 or else Is_Local_Anonymous_Access (Btyp))
9273 and then Subprogram_Access_Level (Entity (P)) >
9274 Type_Access_Level (Btyp)
9275 then
9276 Error_Msg_F
9277 ("subprogram must not be deeper than access type", P);
9279 -- Check the restriction of 3.10.2(32) that disallows the
9280 -- access attribute within a generic body when the ultimate
9281 -- ancestor of the type of the attribute is declared outside
9282 -- of the generic unit and the subprogram is declared within
9283 -- that generic unit. This includes any such attribute that
9284 -- occurs within the body of a generic unit that is a child
9285 -- of the generic unit where the subprogram is declared.
9287 -- The rule also prohibits applying the attribute when the
9288 -- access type is a generic formal access type (since the
9289 -- level of the actual type is not known). This restriction
9290 -- does not apply when the attribute type is an anonymous
9291 -- access-to-subprogram type. Note that this check was
9292 -- revised by AI-229, because the originally Ada 95 rule
9293 -- was too lax. The original rule only applied when the
9294 -- subprogram was declared within the body of the generic,
9295 -- which allowed the possibility of dangling references).
9296 -- The rule was also too strict in some case, in that it
9297 -- didn't permit the access to be declared in the generic
9298 -- spec, whereas the revised rule does (as long as it's not
9299 -- a formal type).
9301 -- There are a couple of subtleties of the test for applying
9302 -- the check that are worth noting. First, we only apply it
9303 -- when the levels of the subprogram and access type are the
9304 -- same (the case where the subprogram is statically deeper
9305 -- was applied above, and the case where the type is deeper
9306 -- is always safe). Second, we want the check to apply
9307 -- within nested generic bodies and generic child unit
9308 -- bodies, but not to apply to an attribute that appears in
9309 -- the generic unit's specification. This is done by testing
9310 -- that the attribute's innermost enclosing generic body is
9311 -- not the same as the innermost generic body enclosing the
9312 -- generic unit where the subprogram is declared (we don't
9313 -- want the check to apply when the access attribute is in
9314 -- the spec and there's some other generic body enclosing
9315 -- generic). Finally, there's no point applying the check
9316 -- when within an instance, because any violations will have
9317 -- been caught by the compilation of the generic unit.
9319 -- We relax this check in Relaxed_RM_Semantics mode for
9320 -- compatibility with legacy code for use by Ada source
9321 -- code analyzers (e.g. CodePeer).
9323 elsif Attr_Id = Attribute_Access
9324 and then not Relaxed_RM_Semantics
9325 and then not In_Instance
9326 and then Present (Enclosing_Generic_Unit (Entity (P)))
9327 and then Present (Enclosing_Generic_Body (N))
9328 and then Enclosing_Generic_Body (N) /=
9329 Enclosing_Generic_Body
9330 (Enclosing_Generic_Unit (Entity (P)))
9331 and then Subprogram_Access_Level (Entity (P)) =
9332 Type_Access_Level (Btyp)
9333 and then Ekind (Btyp) /=
9334 E_Anonymous_Access_Subprogram_Type
9335 and then Ekind (Btyp) /=
9336 E_Anonymous_Access_Protected_Subprogram_Type
9337 then
9338 -- The attribute type's ultimate ancestor must be
9339 -- declared within the same generic unit as the
9340 -- subprogram is declared. The error message is
9341 -- specialized to say "ancestor" for the case where the
9342 -- access type is not its own ancestor, since saying
9343 -- simply "access type" would be very confusing.
9345 if Enclosing_Generic_Unit (Entity (P)) /=
9346 Enclosing_Generic_Unit (Root_Type (Btyp))
9347 then
9348 Error_Msg_N
9349 ("''Access attribute not allowed in generic body",
9352 if Root_Type (Btyp) = Btyp then
9353 Error_Msg_NE
9354 ("\because " &
9355 "access type & is declared outside " &
9356 "generic unit (RM 3.10.2(32))", N, Btyp);
9357 else
9358 Error_Msg_NE
9359 ("\because ancestor of " &
9360 "access type & is declared outside " &
9361 "generic unit (RM 3.10.2(32))", N, Btyp);
9362 end if;
9364 Error_Msg_NE
9365 ("\move ''Access to private part, or " &
9366 "(Ada 2005) use anonymous access type instead of &",
9367 N, Btyp);
9369 -- If the ultimate ancestor of the attribute's type is
9370 -- a formal type, then the attribute is illegal because
9371 -- the actual type might be declared at a higher level.
9372 -- The error message is specialized to say "ancestor"
9373 -- for the case where the access type is not its own
9374 -- ancestor, since saying simply "access type" would be
9375 -- very confusing.
9377 elsif Is_Generic_Type (Root_Type (Btyp)) then
9378 if Root_Type (Btyp) = Btyp then
9379 Error_Msg_N
9380 ("access type must not be a generic formal type",
9382 else
9383 Error_Msg_N
9384 ("ancestor access type must not be a generic " &
9385 "formal type", N);
9386 end if;
9387 end if;
9388 end if;
9389 end if;
9391 -- If this is a renaming, an inherited operation, or a
9392 -- subprogram instance, use the original entity. This may make
9393 -- the node type-inconsistent, so this transformation can only
9394 -- be done if the node will not be reanalyzed. In particular,
9395 -- if it is within a default expression, the transformation
9396 -- must be delayed until the default subprogram is created for
9397 -- it, when the enclosing subprogram is frozen.
9399 if Is_Entity_Name (P)
9400 and then Is_Overloadable (Entity (P))
9401 and then Present (Alias (Entity (P)))
9402 and then Expander_Active
9403 then
9404 Rewrite (P,
9405 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
9406 end if;
9408 elsif Nkind (P) = N_Selected_Component
9409 and then Is_Overloadable (Entity (Selector_Name (P)))
9410 then
9411 -- Protected operation. If operation is overloaded, must
9412 -- disambiguate. Prefix that denotes protected object itself
9413 -- is resolved with its own type.
9415 if Attr_Id = Attribute_Unchecked_Access then
9416 Error_Msg_Name_1 := Aname;
9417 Error_Msg_F
9418 ("attribute% cannot be applied to protected operation", P);
9419 end if;
9421 Resolve (Prefix (P));
9422 Generate_Reference (Entity (Selector_Name (P)), P);
9424 -- Implement check implied by 3.10.2 (18.1/2) : F.all'access is
9425 -- statically illegal if F is an anonymous access to subprogram.
9427 elsif Nkind (P) = N_Explicit_Dereference
9428 and then Is_Entity_Name (Prefix (P))
9429 and then Ekind (Etype (Entity (Prefix (P)))) =
9430 E_Anonymous_Access_Subprogram_Type
9431 then
9432 Error_Msg_N ("anonymous access to subprogram "
9433 & "has deeper accessibility than any master", P);
9435 elsif Is_Overloaded (P) then
9437 -- Use the designated type of the context to disambiguate
9438 -- Note that this was not strictly conformant to Ada 95,
9439 -- but was the implementation adopted by most Ada 95 compilers.
9440 -- The use of the context type to resolve an Access attribute
9441 -- reference is now mandated in AI-235 for Ada 2005.
9443 declare
9444 Index : Interp_Index;
9445 It : Interp;
9447 begin
9448 Get_First_Interp (P, Index, It);
9449 while Present (It.Typ) loop
9450 if Covers (Designated_Type (Typ), It.Typ) then
9451 Resolve (P, It.Typ);
9452 exit;
9453 end if;
9455 Get_Next_Interp (Index, It);
9456 end loop;
9457 end;
9458 else
9459 Resolve (P);
9460 end if;
9462 -- X'Access is illegal if X denotes a constant and the access type
9463 -- is access-to-variable. Same for 'Unchecked_Access. The rule
9464 -- does not apply to 'Unrestricted_Access. If the reference is a
9465 -- default-initialized aggregate component for a self-referential
9466 -- type the reference is legal.
9468 if not (Ekind (Btyp) = E_Access_Subprogram_Type
9469 or else Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
9470 or else (Is_Record_Type (Btyp)
9471 and then
9472 Present (Corresponding_Remote_Type (Btyp)))
9473 or else Ekind (Btyp) = E_Access_Protected_Subprogram_Type
9474 or else Ekind (Btyp)
9475 = E_Anonymous_Access_Protected_Subprogram_Type
9476 or else Is_Access_Constant (Btyp)
9477 or else Is_Variable (P)
9478 or else Attr_Id = Attribute_Unrestricted_Access)
9479 then
9480 if Is_Entity_Name (P)
9481 and then Is_Type (Entity (P))
9482 then
9483 -- Legality of a self-reference through an access
9484 -- attribute has been verified in Analyze_Access_Attribute.
9486 null;
9488 elsif Comes_From_Source (N) then
9489 Error_Msg_F ("access-to-variable designates constant", P);
9490 end if;
9491 end if;
9493 Des_Btyp := Designated_Type (Btyp);
9495 if Ada_Version >= Ada_2005
9496 and then Is_Incomplete_Type (Des_Btyp)
9497 then
9498 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
9499 -- imported entity, and the non-limited view is visible, make
9500 -- use of it. If it is an incomplete subtype, use the base type
9501 -- in any case.
9503 if From_With_Type (Des_Btyp)
9504 and then Present (Non_Limited_View (Des_Btyp))
9505 then
9506 Des_Btyp := Non_Limited_View (Des_Btyp);
9508 elsif Ekind (Des_Btyp) = E_Incomplete_Subtype then
9509 Des_Btyp := Etype (Des_Btyp);
9510 end if;
9511 end if;
9513 if (Attr_Id = Attribute_Access
9514 or else
9515 Attr_Id = Attribute_Unchecked_Access)
9516 and then (Ekind (Btyp) = E_General_Access_Type
9517 or else Ekind (Btyp) = E_Anonymous_Access_Type)
9518 then
9519 -- Ada 2005 (AI-230): Check the accessibility of anonymous
9520 -- access types for stand-alone objects, record and array
9521 -- components, and return objects. For a component definition
9522 -- the level is the same of the enclosing composite type.
9524 if Ada_Version >= Ada_2005
9525 and then (Is_Local_Anonymous_Access (Btyp)
9527 -- Handle cases where Btyp is the anonymous access
9528 -- type of an Ada 2012 stand-alone object.
9530 or else Nkind (Associated_Node_For_Itype (Btyp)) =
9531 N_Object_Declaration)
9532 and then
9533 Object_Access_Level (P) > Deepest_Type_Access_Level (Btyp)
9534 and then Attr_Id = Attribute_Access
9535 then
9536 -- In an instance, this is a runtime check, but one we
9537 -- know will fail, so generate an appropriate warning.
9539 if In_Instance_Body then
9540 Error_Msg_F
9541 ("??non-local pointer cannot point to local object", P);
9542 Error_Msg_F
9543 ("\??Program_Error will be raised at run time", P);
9544 Rewrite (N,
9545 Make_Raise_Program_Error (Loc,
9546 Reason => PE_Accessibility_Check_Failed));
9547 Set_Etype (N, Typ);
9549 else
9550 Error_Msg_F
9551 ("non-local pointer cannot point to local object", P);
9552 end if;
9553 end if;
9555 if Is_Dependent_Component_Of_Mutable_Object (P) then
9556 Error_Msg_F
9557 ("illegal attribute for discriminant-dependent component",
9559 end if;
9561 -- Check static matching rule of 3.10.2(27). Nominal subtype
9562 -- of the prefix must statically match the designated type.
9564 Nom_Subt := Etype (P);
9566 if Is_Constr_Subt_For_U_Nominal (Nom_Subt) then
9567 Nom_Subt := Base_Type (Nom_Subt);
9568 end if;
9570 if Is_Tagged_Type (Designated_Type (Typ)) then
9572 -- If the attribute is in the context of an access
9573 -- parameter, then the prefix is allowed to be of the
9574 -- class-wide type (by AI-127).
9576 if Ekind (Typ) = E_Anonymous_Access_Type then
9577 if not Covers (Designated_Type (Typ), Nom_Subt)
9578 and then not Covers (Nom_Subt, Designated_Type (Typ))
9579 then
9580 declare
9581 Desig : Entity_Id;
9583 begin
9584 Desig := Designated_Type (Typ);
9586 if Is_Class_Wide_Type (Desig) then
9587 Desig := Etype (Desig);
9588 end if;
9590 if Is_Anonymous_Tagged_Base (Nom_Subt, Desig) then
9591 null;
9593 else
9594 Error_Msg_FE
9595 ("type of prefix: & not compatible",
9596 P, Nom_Subt);
9597 Error_Msg_FE
9598 ("\with &, the expected designated type",
9599 P, Designated_Type (Typ));
9600 end if;
9601 end;
9602 end if;
9604 elsif not Covers (Designated_Type (Typ), Nom_Subt)
9605 or else
9606 (not Is_Class_Wide_Type (Designated_Type (Typ))
9607 and then Is_Class_Wide_Type (Nom_Subt))
9608 then
9609 Error_Msg_FE
9610 ("type of prefix: & is not covered", P, Nom_Subt);
9611 Error_Msg_FE
9612 ("\by &, the expected designated type" &
9613 " (RM 3.10.2 (27))", P, Designated_Type (Typ));
9614 end if;
9616 if Is_Class_Wide_Type (Designated_Type (Typ))
9617 and then Has_Discriminants (Etype (Designated_Type (Typ)))
9618 and then Is_Constrained (Etype (Designated_Type (Typ)))
9619 and then Designated_Type (Typ) /= Nom_Subt
9620 then
9621 Apply_Discriminant_Check
9622 (N, Etype (Designated_Type (Typ)));
9623 end if;
9625 -- Ada 2005 (AI-363): Require static matching when designated
9626 -- type has discriminants and a constrained partial view, since
9627 -- in general objects of such types are mutable, so we can't
9628 -- allow the access value to designate a constrained object
9629 -- (because access values must be assumed to designate mutable
9630 -- objects when designated type does not impose a constraint).
9632 elsif Subtypes_Statically_Match (Des_Btyp, Nom_Subt) then
9633 null;
9635 elsif Has_Discriminants (Designated_Type (Typ))
9636 and then not Is_Constrained (Des_Btyp)
9637 and then
9638 (Ada_Version < Ada_2005
9639 or else
9640 not Object_Type_Has_Constrained_Partial_View
9641 (Typ => Designated_Type (Base_Type (Typ)),
9642 Scop => Current_Scope))
9643 then
9644 null;
9646 else
9647 Error_Msg_F
9648 ("object subtype must statically match "
9649 & "designated subtype", P);
9651 if Is_Entity_Name (P)
9652 and then Is_Array_Type (Designated_Type (Typ))
9653 then
9654 declare
9655 D : constant Node_Id := Declaration_Node (Entity (P));
9656 begin
9657 Error_Msg_N
9658 ("aliased object has explicit bounds??", D);
9659 Error_Msg_N
9660 ("\declare without bounds (and with explicit "
9661 & "initialization)??", D);
9662 Error_Msg_N
9663 ("\for use with unconstrained access??", D);
9664 end;
9665 end if;
9666 end if;
9668 -- Check the static accessibility rule of 3.10.2(28). Note that
9669 -- this check is not performed for the case of an anonymous
9670 -- access type, since the access attribute is always legal
9671 -- in such a context.
9673 if Attr_Id /= Attribute_Unchecked_Access
9674 and then Ekind (Btyp) = E_General_Access_Type
9675 and then
9676 Object_Access_Level (P) > Deepest_Type_Access_Level (Btyp)
9677 then
9678 Accessibility_Message;
9679 return;
9680 end if;
9681 end if;
9683 if Ekind_In (Btyp, E_Access_Protected_Subprogram_Type,
9684 E_Anonymous_Access_Protected_Subprogram_Type)
9685 then
9686 if Is_Entity_Name (P)
9687 and then not Is_Protected_Type (Scope (Entity (P)))
9688 then
9689 Error_Msg_F ("context requires a protected subprogram", P);
9691 -- Check accessibility of protected object against that of the
9692 -- access type, but only on user code, because the expander
9693 -- creates access references for handlers. If the context is an
9694 -- anonymous_access_to_protected, there are no accessibility
9695 -- checks either. Omit check entirely for Unrestricted_Access.
9697 elsif Object_Access_Level (P) > Deepest_Type_Access_Level (Btyp)
9698 and then Comes_From_Source (N)
9699 and then Ekind (Btyp) = E_Access_Protected_Subprogram_Type
9700 and then Attr_Id /= Attribute_Unrestricted_Access
9701 then
9702 Accessibility_Message;
9703 return;
9705 -- AI05-0225: If the context is not an access to protected
9706 -- function, the prefix must be a variable, given that it may
9707 -- be used subsequently in a protected call.
9709 elsif Nkind (P) = N_Selected_Component
9710 and then not Is_Variable (Prefix (P))
9711 and then Ekind (Entity (Selector_Name (P))) /= E_Function
9712 then
9713 Error_Msg_N
9714 ("target object of access to protected procedure "
9715 & "must be variable", N);
9717 elsif Is_Entity_Name (P) then
9718 Check_Internal_Protected_Use (N, Entity (P));
9719 end if;
9721 elsif Ekind_In (Btyp, E_Access_Subprogram_Type,
9722 E_Anonymous_Access_Subprogram_Type)
9723 and then Ekind (Etype (N)) = E_Access_Protected_Subprogram_Type
9724 then
9725 Error_Msg_F ("context requires a non-protected subprogram", P);
9726 end if;
9728 -- The context cannot be a pool-specific type, but this is a
9729 -- legality rule, not a resolution rule, so it must be checked
9730 -- separately, after possibly disambiguation (see AI-245).
9732 if Ekind (Btyp) = E_Access_Type
9733 and then Attr_Id /= Attribute_Unrestricted_Access
9734 then
9735 Wrong_Type (N, Typ);
9736 end if;
9738 -- The context may be a constrained access type (however ill-
9739 -- advised such subtypes might be) so in order to generate a
9740 -- constraint check when needed set the type of the attribute
9741 -- reference to the base type of the context.
9743 Set_Etype (N, Btyp);
9745 -- Check for incorrect atomic/volatile reference (RM C.6(12))
9747 if Attr_Id /= Attribute_Unrestricted_Access then
9748 if Is_Atomic_Object (P)
9749 and then not Is_Atomic (Designated_Type (Typ))
9750 then
9751 Error_Msg_F
9752 ("access to atomic object cannot yield access-to-" &
9753 "non-atomic type", P);
9755 elsif Is_Volatile_Object (P)
9756 and then not Is_Volatile (Designated_Type (Typ))
9757 then
9758 Error_Msg_F
9759 ("access to volatile object cannot yield access-to-" &
9760 "non-volatile type", P);
9761 end if;
9762 end if;
9764 if Is_Entity_Name (P) then
9765 Set_Address_Taken (Entity (P));
9766 end if;
9767 end Access_Attribute;
9769 -------------
9770 -- Address --
9771 -------------
9773 -- Deal with resolving the type for Address attribute, overloading
9774 -- is not permitted here, since there is no context to resolve it.
9776 when Attribute_Address | Attribute_Code_Address =>
9777 Address_Attribute : begin
9779 -- To be safe, assume that if the address of a variable is taken,
9780 -- it may be modified via this address, so note modification.
9782 if Is_Variable (P) then
9783 Note_Possible_Modification (P, Sure => False);
9784 end if;
9786 if Nkind (P) in N_Subexpr
9787 and then Is_Overloaded (P)
9788 then
9789 Get_First_Interp (P, Index, It);
9790 Get_Next_Interp (Index, It);
9792 if Present (It.Nam) then
9793 Error_Msg_Name_1 := Aname;
9794 Error_Msg_F
9795 ("prefix of % attribute cannot be overloaded", P);
9796 end if;
9797 end if;
9799 if not Is_Entity_Name (P)
9800 or else not Is_Overloadable (Entity (P))
9801 then
9802 if not Is_Task_Type (Etype (P))
9803 or else Nkind (P) = N_Explicit_Dereference
9804 then
9805 Resolve (P);
9806 end if;
9807 end if;
9809 -- If this is the name of a derived subprogram, or that of a
9810 -- generic actual, the address is that of the original entity.
9812 if Is_Entity_Name (P)
9813 and then Is_Overloadable (Entity (P))
9814 and then Present (Alias (Entity (P)))
9815 then
9816 Rewrite (P,
9817 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
9818 end if;
9820 if Is_Entity_Name (P) then
9821 Set_Address_Taken (Entity (P));
9822 end if;
9824 if Nkind (P) = N_Slice then
9826 -- Arr (X .. Y)'address is identical to Arr (X)'address,
9827 -- even if the array is packed and the slice itself is not
9828 -- addressable. Transform the prefix into an indexed component.
9830 -- Note that the transformation is safe only if we know that
9831 -- the slice is non-null. That is because a null slice can have
9832 -- an out of bounds index value.
9834 -- Right now, gigi blows up if given 'Address on a slice as a
9835 -- result of some incorrect freeze nodes generated by the front
9836 -- end, and this covers up that bug in one case, but the bug is
9837 -- likely still there in the cases not handled by this code ???
9839 -- It's not clear what 'Address *should* return for a null
9840 -- slice with out of bounds indexes, this might be worth an ARG
9841 -- discussion ???
9843 -- One approach would be to do a length check unconditionally,
9844 -- and then do the transformation below unconditionally, but
9845 -- analyze with checks off, avoiding the problem of the out of
9846 -- bounds index. This approach would interpret the address of
9847 -- an out of bounds null slice as being the address where the
9848 -- array element would be if there was one, which is probably
9849 -- as reasonable an interpretation as any ???
9851 declare
9852 Loc : constant Source_Ptr := Sloc (P);
9853 D : constant Node_Id := Discrete_Range (P);
9854 Lo : Node_Id;
9856 begin
9857 if Is_Entity_Name (D)
9858 and then
9859 Not_Null_Range
9860 (Type_Low_Bound (Entity (D)),
9861 Type_High_Bound (Entity (D)))
9862 then
9863 Lo :=
9864 Make_Attribute_Reference (Loc,
9865 Prefix => (New_Occurrence_Of (Entity (D), Loc)),
9866 Attribute_Name => Name_First);
9868 elsif Nkind (D) = N_Range
9869 and then Not_Null_Range (Low_Bound (D), High_Bound (D))
9870 then
9871 Lo := Low_Bound (D);
9873 else
9874 Lo := Empty;
9875 end if;
9877 if Present (Lo) then
9878 Rewrite (P,
9879 Make_Indexed_Component (Loc,
9880 Prefix => Relocate_Node (Prefix (P)),
9881 Expressions => New_List (Lo)));
9883 Analyze_And_Resolve (P);
9884 end if;
9885 end;
9886 end if;
9887 end Address_Attribute;
9889 ---------------
9890 -- AST_Entry --
9891 ---------------
9893 -- Prefix of the AST_Entry attribute is an entry name which must
9894 -- not be resolved, since this is definitely not an entry call.
9896 when Attribute_AST_Entry =>
9897 null;
9899 ------------------
9900 -- Body_Version --
9901 ------------------
9903 -- Prefix of Body_Version attribute can be a subprogram name which
9904 -- must not be resolved, since this is not a call.
9906 when Attribute_Body_Version =>
9907 null;
9909 ------------
9910 -- Caller --
9911 ------------
9913 -- Prefix of Caller attribute is an entry name which must not
9914 -- be resolved, since this is definitely not an entry call.
9916 when Attribute_Caller =>
9917 null;
9919 ------------------
9920 -- Code_Address --
9921 ------------------
9923 -- Shares processing with Address attribute
9925 -----------
9926 -- Count --
9927 -----------
9929 -- If the prefix of the Count attribute is an entry name it must not
9930 -- be resolved, since this is definitely not an entry call. However,
9931 -- if it is an element of an entry family, the index itself may
9932 -- have to be resolved because it can be a general expression.
9934 when Attribute_Count =>
9935 if Nkind (P) = N_Indexed_Component
9936 and then Is_Entity_Name (Prefix (P))
9937 then
9938 declare
9939 Indx : constant Node_Id := First (Expressions (P));
9940 Fam : constant Entity_Id := Entity (Prefix (P));
9941 begin
9942 Resolve (Indx, Entry_Index_Type (Fam));
9943 Apply_Range_Check (Indx, Entry_Index_Type (Fam));
9944 end;
9945 end if;
9947 ----------------
9948 -- Elaborated --
9949 ----------------
9951 -- Prefix of the Elaborated attribute is a subprogram name which
9952 -- must not be resolved, since this is definitely not a call. Note
9953 -- that it is a library unit, so it cannot be overloaded here.
9955 when Attribute_Elaborated =>
9956 null;
9958 -------------
9959 -- Enabled --
9960 -------------
9962 -- Prefix of Enabled attribute is a check name, which must be treated
9963 -- specially and not touched by Resolve.
9965 when Attribute_Enabled =>
9966 null;
9968 ----------------
9969 -- Loop_Entry --
9970 ----------------
9972 -- Do not resolve the prefix of Loop_Entry, instead wait until the
9973 -- attribute has been expanded (see Expand_Loop_Entry_Attributes).
9974 -- The delay ensures that any generated checks or temporaries are
9975 -- inserted before the relocated prefix.
9977 when Attribute_Loop_Entry =>
9978 null;
9980 --------------------
9981 -- Mechanism_Code --
9982 --------------------
9984 -- Prefix of the Mechanism_Code attribute is a function name
9985 -- which must not be resolved. Should we check for overloaded ???
9987 when Attribute_Mechanism_Code =>
9988 null;
9990 ------------------
9991 -- Partition_ID --
9992 ------------------
9994 -- Most processing is done in sem_dist, after determining the
9995 -- context type. Node is rewritten as a conversion to a runtime call.
9997 when Attribute_Partition_ID =>
9998 Process_Partition_Id (N);
9999 return;
10001 ------------------
10002 -- Pool_Address --
10003 ------------------
10005 when Attribute_Pool_Address =>
10006 Resolve (P);
10008 -----------
10009 -- Range --
10010 -----------
10012 -- We replace the Range attribute node with a range expression whose
10013 -- bounds are the 'First and 'Last attributes applied to the same
10014 -- prefix. The reason that we do this transformation here instead of
10015 -- in the expander is that it simplifies other parts of the semantic
10016 -- analysis which assume that the Range has been replaced; thus it
10017 -- must be done even when in semantic-only mode (note that the RM
10018 -- specifically mentions this equivalence, we take care that the
10019 -- prefix is only evaluated once).
10021 when Attribute_Range => Range_Attribute :
10022 declare
10023 LB : Node_Id;
10024 HB : Node_Id;
10025 Dims : List_Id;
10027 begin
10028 if not Is_Entity_Name (P)
10029 or else not Is_Type (Entity (P))
10030 then
10031 Resolve (P);
10032 end if;
10034 Dims := Expressions (N);
10036 HB :=
10037 Make_Attribute_Reference (Loc,
10038 Prefix =>
10039 Duplicate_Subexpr (P, Name_Req => True),
10040 Attribute_Name => Name_Last,
10041 Expressions => Dims);
10043 LB :=
10044 Make_Attribute_Reference (Loc,
10045 Prefix => P,
10046 Attribute_Name => Name_First,
10047 Expressions => (Dims));
10049 -- Do not share the dimension indicator, if present. Even
10050 -- though it is a static constant, its source location
10051 -- may be modified when printing expanded code and node
10052 -- sharing will lead to chaos in Sprint.
10054 if Present (Dims) then
10055 Set_Expressions (LB,
10056 New_List (New_Copy_Tree (First (Dims))));
10057 end if;
10059 -- If the original was marked as Must_Not_Freeze (see code
10060 -- in Sem_Ch3.Make_Index), then make sure the rewriting
10061 -- does not freeze either.
10063 if Must_Not_Freeze (N) then
10064 Set_Must_Not_Freeze (HB);
10065 Set_Must_Not_Freeze (LB);
10066 Set_Must_Not_Freeze (Prefix (HB));
10067 Set_Must_Not_Freeze (Prefix (LB));
10068 end if;
10070 if Raises_Constraint_Error (Prefix (N)) then
10072 -- Preserve Sloc of prefix in the new bounds, so that
10073 -- the posted warning can be removed if we are within
10074 -- unreachable code.
10076 Set_Sloc (LB, Sloc (Prefix (N)));
10077 Set_Sloc (HB, Sloc (Prefix (N)));
10078 end if;
10080 Rewrite (N, Make_Range (Loc, LB, HB));
10081 Analyze_And_Resolve (N, Typ);
10083 -- Ensure that the expanded range does not have side effects
10085 Force_Evaluation (LB);
10086 Force_Evaluation (HB);
10088 -- Normally after resolving attribute nodes, Eval_Attribute
10089 -- is called to do any possible static evaluation of the node.
10090 -- However, here since the Range attribute has just been
10091 -- transformed into a range expression it is no longer an
10092 -- attribute node and therefore the call needs to be avoided
10093 -- and is accomplished by simply returning from the procedure.
10095 return;
10096 end Range_Attribute;
10098 ------------
10099 -- Result --
10100 ------------
10102 -- We will only come here during the prescan of a spec expression
10103 -- containing a Result attribute. In that case the proper Etype has
10104 -- already been set, and nothing more needs to be done here.
10106 when Attribute_Result =>
10107 null;
10109 -----------------
10110 -- UET_Address --
10111 -----------------
10113 -- Prefix must not be resolved in this case, since it is not a
10114 -- real entity reference. No action of any kind is require!
10116 when Attribute_UET_Address =>
10117 return;
10119 ----------------------
10120 -- Unchecked_Access --
10121 ----------------------
10123 -- Processing is shared with Access
10125 -------------------------
10126 -- Unrestricted_Access --
10127 -------------------------
10129 -- Processing is shared with Access
10131 ---------
10132 -- Val --
10133 ---------
10135 -- Apply range check. Note that we did not do this during the
10136 -- analysis phase, since we wanted Eval_Attribute to have a
10137 -- chance at finding an illegal out of range value.
10139 when Attribute_Val =>
10141 -- Note that we do our own Eval_Attribute call here rather than
10142 -- use the common one, because we need to do processing after
10143 -- the call, as per above comment.
10145 Eval_Attribute (N);
10147 -- Eval_Attribute may replace the node with a raise CE, or
10148 -- fold it to a constant. Obviously we only apply a scalar
10149 -- range check if this did not happen!
10151 if Nkind (N) = N_Attribute_Reference
10152 and then Attribute_Name (N) = Name_Val
10153 then
10154 Apply_Scalar_Range_Check (First (Expressions (N)), Btyp);
10155 end if;
10157 return;
10159 -------------
10160 -- Version --
10161 -------------
10163 -- Prefix of Version attribute can be a subprogram name which
10164 -- must not be resolved, since this is not a call.
10166 when Attribute_Version =>
10167 null;
10169 ----------------------
10170 -- Other Attributes --
10171 ----------------------
10173 -- For other attributes, resolve prefix unless it is a type. If
10174 -- the attribute reference itself is a type name ('Base and 'Class)
10175 -- then this is only legal within a task or protected record.
10177 when others =>
10178 if not Is_Entity_Name (P) or else not Is_Type (Entity (P)) then
10179 Resolve (P);
10180 end if;
10182 -- If the attribute reference itself is a type name ('Base,
10183 -- 'Class) then this is only legal within a task or protected
10184 -- record. What is this all about ???
10186 if Is_Entity_Name (N) and then Is_Type (Entity (N)) then
10187 if Is_Concurrent_Type (Entity (N))
10188 and then In_Open_Scopes (Entity (P))
10189 then
10190 null;
10191 else
10192 Error_Msg_N
10193 ("invalid use of subtype name in expression or call", N);
10194 end if;
10195 end if;
10197 -- For attributes whose argument may be a string, complete
10198 -- resolution of argument now. This avoids premature expansion
10199 -- (and the creation of transient scopes) before the attribute
10200 -- reference is resolved.
10202 case Attr_Id is
10203 when Attribute_Value =>
10204 Resolve (First (Expressions (N)), Standard_String);
10206 when Attribute_Wide_Value =>
10207 Resolve (First (Expressions (N)), Standard_Wide_String);
10209 when Attribute_Wide_Wide_Value =>
10210 Resolve (First (Expressions (N)), Standard_Wide_Wide_String);
10212 when others => null;
10213 end case;
10215 -- If the prefix of the attribute is a class-wide type then it
10216 -- will be expanded into a dispatching call to a predefined
10217 -- primitive. Therefore we must check for potential violation
10218 -- of such restriction.
10220 if Is_Class_Wide_Type (Etype (P)) then
10221 Check_Restriction (No_Dispatching_Calls, N);
10222 end if;
10223 end case;
10225 -- Normally the Freezing is done by Resolve but sometimes the Prefix
10226 -- is not resolved, in which case the freezing must be done now.
10228 Freeze_Expression (P);
10230 -- Finally perform static evaluation on the attribute reference
10232 Analyze_Dimension (N);
10233 Eval_Attribute (N);
10234 end Resolve_Attribute;
10236 --------------------------------
10237 -- Stream_Attribute_Available --
10238 --------------------------------
10240 function Stream_Attribute_Available
10241 (Typ : Entity_Id;
10242 Nam : TSS_Name_Type;
10243 Partial_View : Node_Id := Empty) return Boolean
10245 Etyp : Entity_Id := Typ;
10247 -- Start of processing for Stream_Attribute_Available
10249 begin
10250 -- We need some comments in this body ???
10252 if Has_Stream_Attribute_Definition (Typ, Nam) then
10253 return True;
10254 end if;
10256 if Is_Class_Wide_Type (Typ) then
10257 return not Is_Limited_Type (Typ)
10258 or else Stream_Attribute_Available (Etype (Typ), Nam);
10259 end if;
10261 if Nam = TSS_Stream_Input
10262 and then Is_Abstract_Type (Typ)
10263 and then not Is_Class_Wide_Type (Typ)
10264 then
10265 return False;
10266 end if;
10268 if not (Is_Limited_Type (Typ)
10269 or else (Present (Partial_View)
10270 and then Is_Limited_Type (Partial_View)))
10271 then
10272 return True;
10273 end if;
10275 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
10277 if Nam = TSS_Stream_Input
10278 and then Ada_Version >= Ada_2005
10279 and then Stream_Attribute_Available (Etyp, TSS_Stream_Read)
10280 then
10281 return True;
10283 elsif Nam = TSS_Stream_Output
10284 and then Ada_Version >= Ada_2005
10285 and then Stream_Attribute_Available (Etyp, TSS_Stream_Write)
10286 then
10287 return True;
10288 end if;
10290 -- Case of Read and Write: check for attribute definition clause that
10291 -- applies to an ancestor type.
10293 while Etype (Etyp) /= Etyp loop
10294 Etyp := Etype (Etyp);
10296 if Has_Stream_Attribute_Definition (Etyp, Nam) then
10297 return True;
10298 end if;
10299 end loop;
10301 if Ada_Version < Ada_2005 then
10303 -- In Ada 95 mode, also consider a non-visible definition
10305 declare
10306 Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
10307 begin
10308 return Btyp /= Typ
10309 and then Stream_Attribute_Available
10310 (Btyp, Nam, Partial_View => Typ);
10311 end;
10312 end if;
10314 return False;
10315 end Stream_Attribute_Available;
10317 end Sem_Attr;