1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Debug_A; use Debug_A;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nmake; use Nmake;
43 with Nlists; use Nlists;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rtsfind; use Rtsfind;
49 with Sem_Aggr; use Sem_Aggr;
50 with Sem_Attr; use Sem_Attr;
51 with Sem_Cat; use Sem_Cat;
52 with Sem_Ch4; use Sem_Ch4;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Dist; use Sem_Dist;
57 with Sem_Elab; use Sem_Elab;
58 with Sem_Eval; use Sem_Eval;
59 with Sem_Intr; use Sem_Intr;
60 with Sem_Util; use Sem_Util;
61 with Sem_Type; use Sem_Type;
62 with Sem_Warn; use Sem_Warn;
63 with Sinfo; use Sinfo;
64 with Snames; use Snames;
65 with Stand; use Stand;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Uintp; use Uintp;
70 with Urealp; use Urealp;
72 package body Sem_Res is
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 -- Second pass (top-down) type checking and overload resolution procedures
79 -- Typ is the type required by context. These procedures propagate the
80 -- type information recursively to the descendants of N. If the node
81 -- is not overloaded, its Etype is established in the first pass. If
82 -- overloaded, the Resolve routines set the correct type. For arith.
83 -- operators, the Etype is the base type of the context.
85 -- Note that Resolve_Attribute is separated off in Sem_Attr
87 procedure Ambiguous_Character (C : Node_Id);
88 -- Give list of candidate interpretations when a character literal cannot
91 procedure Check_Direct_Boolean_Op (N : Node_Id);
92 -- N is a binary operator node which may possibly operate on Boolean
93 -- operands. If the operator does have Boolean operands, then a call is
94 -- made to check the restriction No_Direct_Boolean_Operators.
96 procedure Check_Discriminant_Use (N : Node_Id);
97 -- Enforce the restrictions on the use of discriminants when constraining
98 -- a component of a discriminated type (record or concurrent type).
100 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
101 -- Given a node for an operator associated with type T, check that
102 -- the operator is visible. Operators all of whose operands are
103 -- universal must be checked for visibility during resolution
104 -- because their type is not determinable based on their operands.
106 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
107 -- Given a call node, N, which is known to occur immediately within the
108 -- subprogram being called, determines whether it is a detectable case of
109 -- an infinite recursion, and if so, outputs appropriate messages. Returns
110 -- True if an infinite recursion is detected, and False otherwise.
112 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
113 -- If the type of the object being initialized uses the secondary stack
114 -- directly or indirectly, create a transient scope for the call to the
115 -- init proc. This is because we do not create transient scopes for the
116 -- initialization of individual components within the init proc itself.
117 -- Could be optimized away perhaps?
119 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
120 -- Utility to check whether the name in the call is a predefined
121 -- operator, in which case the call is made into an operator node.
122 -- An instance of an intrinsic conversion operation may be given
123 -- an operator name, but is not treated like an operator.
125 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
126 -- If a default expression in entry call N depends on the discriminants
127 -- of the task, it must be replaced with a reference to the discriminant
128 -- of the task being called.
130 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
131 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
132 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
133 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
134 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
135 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
136 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
137 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
138 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
139 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
140 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
141 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
142 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
143 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
144 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
145 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
146 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
147 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
148 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
149 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
150 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
151 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
152 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
153 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
163 function Operator_Kind
167 -- Utility to map the name of an operator into the corresponding Node. Used
168 -- by other node rewriting procedures.
170 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
171 -- Resolve actuals of call, and add default expressions for missing ones.
173 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
174 -- Called from Resolve_Call, when the prefix denotes an entry or element
175 -- of entry family. Actuals are resolved as for subprograms, and the node
176 -- is rebuilt as an entry call. Also called for protected operations. Typ
177 -- is the context type, which is used when the operation is a protected
178 -- function with no arguments, and the return value is indexed.
180 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
181 -- A call to a user-defined intrinsic operator is rewritten as a call
182 -- to the corresponding predefined operator, with suitable conversions.
184 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
185 -- Ditto, for unary operators (only arithmetic ones).
187 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
188 -- If an operator node resolves to a call to a user-defined operator,
189 -- rewrite the node as a function call.
191 procedure Make_Call_Into_Operator
195 -- Inverse transformation: if an operator is given in functional notation,
196 -- then after resolving the node, transform into an operator node, so
197 -- that operands are resolved properly. Recall that predefined operators
198 -- do not have a full signature and special resolution rules apply.
200 procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id);
201 -- An operator can rename another, e.g. in an instantiation. In that
202 -- case, the proper operator node must be constructed.
204 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
205 -- The String_Literal_Subtype is built for all strings that are not
206 -- operands of a static concatenation operation. If the argument is
207 -- not a N_String_Literal node, then the call has no effect.
209 procedure Set_Slice_Subtype (N : Node_Id);
210 -- Build subtype of array type, with the range specified by the slice
212 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
213 -- A universal_fixed expression in an universal context is unambiguous
214 -- if there is only one applicable fixed point type. Determining whether
215 -- there is only one requires a search over all visible entities, and
216 -- happens only in very pathological cases (see 6115-006).
218 function Valid_Conversion
223 -- Verify legality rules given in 4.6 (8-23). Target is the target
224 -- type of the conversion, which may be an implicit conversion of
225 -- an actual parameter to an anonymous access type (in which case
226 -- N denotes the actual parameter and N = Operand).
228 -------------------------
229 -- Ambiguous_Character --
230 -------------------------
232 procedure Ambiguous_Character (C : Node_Id) is
236 if Nkind (C) = N_Character_Literal then
237 Error_Msg_N ("ambiguous character literal", C);
239 ("\possible interpretations: Character, Wide_Character!", C);
241 E := Current_Entity (C);
245 while Present (E) loop
246 Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
251 end Ambiguous_Character;
253 -------------------------
254 -- Analyze_And_Resolve --
255 -------------------------
257 procedure Analyze_And_Resolve (N : Node_Id) is
261 end Analyze_And_Resolve;
263 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
267 end Analyze_And_Resolve;
269 -- Version withs check(s) suppressed
271 procedure Analyze_And_Resolve
276 Scop : constant Entity_Id := Current_Scope;
279 if Suppress = All_Checks then
281 Svg : constant Suppress_Array := Scope_Suppress;
284 Scope_Suppress := (others => True);
285 Analyze_And_Resolve (N, Typ);
286 Scope_Suppress := Svg;
291 Svg : constant Boolean := Scope_Suppress (Suppress);
294 Scope_Suppress (Suppress) := True;
295 Analyze_And_Resolve (N, Typ);
296 Scope_Suppress (Suppress) := Svg;
300 if Current_Scope /= Scop
301 and then Scope_Is_Transient
303 -- This can only happen if a transient scope was created
304 -- for an inner expression, which will be removed upon
305 -- completion of the analysis of an enclosing construct.
306 -- The transient scope must have the suppress status of
307 -- the enclosing environment, not of this Analyze call.
309 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
312 end Analyze_And_Resolve;
314 procedure Analyze_And_Resolve
318 Scop : constant Entity_Id := Current_Scope;
321 if Suppress = All_Checks then
323 Svg : constant Suppress_Array := Scope_Suppress;
326 Scope_Suppress := (others => True);
327 Analyze_And_Resolve (N);
328 Scope_Suppress := Svg;
333 Svg : constant Boolean := Scope_Suppress (Suppress);
336 Scope_Suppress (Suppress) := True;
337 Analyze_And_Resolve (N);
338 Scope_Suppress (Suppress) := Svg;
342 if Current_Scope /= Scop
343 and then Scope_Is_Transient
345 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
348 end Analyze_And_Resolve;
350 -----------------------------
351 -- Check_Direct_Boolean_Op --
352 -----------------------------
354 procedure Check_Direct_Boolean_Op (N : Node_Id) is
356 if Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean then
357 Check_Restriction (No_Direct_Boolean_Operators, N);
359 end Check_Direct_Boolean_Op;
361 ----------------------------
362 -- Check_Discriminant_Use --
363 ----------------------------
365 procedure Check_Discriminant_Use (N : Node_Id) is
366 PN : constant Node_Id := Parent (N);
367 Disc : constant Entity_Id := Entity (N);
372 -- Any use in a default expression is legal.
374 if In_Default_Expression then
377 elsif Nkind (PN) = N_Range then
379 -- Discriminant cannot be used to constrain a scalar type.
383 if Nkind (P) = N_Range_Constraint
384 and then Nkind (Parent (P)) = N_Subtype_Indication
385 and then Nkind (Parent (Parent (P))) = N_Component_Definition
387 Error_Msg_N ("discriminant cannot constrain scalar type", N);
389 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
391 -- The following check catches the unusual case where
392 -- a discriminant appears within an index constraint
393 -- that is part of a larger expression within a constraint
394 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
395 -- For now we only check case of record components, and
396 -- note that a similar check should also apply in the
397 -- case of discriminant constraints below. ???
399 -- Note that the check for N_Subtype_Declaration below is to
400 -- detect the valid use of discriminants in the constraints of a
401 -- subtype declaration when this subtype declaration appears
402 -- inside the scope of a record type (which is syntactically
403 -- illegal, but which may be created as part of derived type
404 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
407 if Ekind (Current_Scope) = E_Record_Type
408 and then Scope (Disc) = Current_Scope
410 (Nkind (Parent (P)) = N_Subtype_Indication
412 (Nkind (Parent (Parent (P))) = N_Component_Definition
414 Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
415 and then Paren_Count (N) = 0)
418 ("discriminant must appear alone in component constraint", N);
422 -- Detect a common beginner error:
424 -- type R (D : Positive := 100) is record
425 -- Name : String (1 .. D);
428 -- The default value causes an object of type R to be
429 -- allocated with room for Positive'Last characters.
437 function Large_Storage_Type (T : Entity_Id) return Boolean;
438 -- Return True if type T has a large enough range that
439 -- any array whose index type covered the whole range of
440 -- the type would likely raise Storage_Error.
442 ------------------------
443 -- Large_Storage_Type --
444 ------------------------
446 function Large_Storage_Type (T : Entity_Id) return Boolean is
451 T = Standard_Positive
453 T = Standard_Natural;
454 end Large_Storage_Type;
457 -- Check that the Disc has a large range
459 if not Large_Storage_Type (Etype (Disc)) then
463 -- If the enclosing type is limited, we allocate only the
464 -- default value, not the maximum, and there is no need for
467 if Is_Limited_Type (Scope (Disc)) then
471 -- Check that it is the high bound
473 if N /= High_Bound (PN)
474 or else not Present (Discriminant_Default_Value (Disc))
479 -- Check the array allows a large range at this bound.
480 -- First find the array
484 if Nkind (SI) /= N_Subtype_Indication then
488 T := Entity (Subtype_Mark (SI));
490 if not Is_Array_Type (T) then
494 -- Next, find the dimension
496 TB := First_Index (T);
497 CB := First (Constraints (P));
499 and then Present (TB)
500 and then Present (CB)
511 -- Now, check the dimension has a large range
513 if not Large_Storage_Type (Etype (TB)) then
517 -- Warn about the danger
520 ("creation of & object may raise Storage_Error?",
529 -- Legal case is in index or discriminant constraint
531 elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
532 or else Nkind (PN) = N_Discriminant_Association
534 if Paren_Count (N) > 0 then
536 ("discriminant in constraint must appear alone", N);
541 -- Otherwise, context is an expression. It should not be within
542 -- (i.e. a subexpression of) a constraint for a component.
548 while Nkind (P) /= N_Component_Declaration
549 and then Nkind (P) /= N_Subtype_Indication
550 and then Nkind (P) /= N_Entry_Declaration
557 -- If the discriminant is used in an expression that is a bound
558 -- of a scalar type, an Itype is created and the bounds are attached
559 -- to its range, not to the original subtype indication. Such use
560 -- is of course a double fault.
562 if (Nkind (P) = N_Subtype_Indication
564 (Nkind (Parent (P)) = N_Component_Definition
566 Nkind (Parent (P)) = N_Derived_Type_Definition)
567 and then D = Constraint (P))
569 -- The constraint itself may be given by a subtype indication,
570 -- rather than by a more common discrete range.
572 or else (Nkind (P) = N_Subtype_Indication
574 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
575 or else Nkind (P) = N_Entry_Declaration
576 or else Nkind (D) = N_Defining_Identifier
579 ("discriminant in constraint must appear alone", N);
582 end Check_Discriminant_Use;
584 --------------------------------
585 -- Check_For_Visible_Operator --
586 --------------------------------
588 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
590 if Is_Invisible_Operator (N, T) then
592 ("operator for} is not directly visible!", N, First_Subtype (T));
593 Error_Msg_N ("use clause would make operation legal!", N);
595 end Check_For_Visible_Operator;
597 ------------------------------
598 -- Check_Infinite_Recursion --
599 ------------------------------
601 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
605 function Same_Argument_List return Boolean;
606 -- Check whether list of actuals is identical to list of formals
607 -- of called function (which is also the enclosing scope).
609 ------------------------
610 -- Same_Argument_List --
611 ------------------------
613 function Same_Argument_List return Boolean is
619 if not Is_Entity_Name (Name (N)) then
622 Subp := Entity (Name (N));
625 F := First_Formal (Subp);
626 A := First_Actual (N);
628 while Present (F) and then Present (A) loop
629 if not Is_Entity_Name (A)
630 or else Entity (A) /= F
640 end Same_Argument_List;
642 -- Start of processing for Check_Infinite_Recursion
645 -- Loop moving up tree, quitting if something tells us we are
646 -- definitely not in an infinite recursion situation.
651 exit when Nkind (P) = N_Subprogram_Body;
653 if Nkind (P) = N_Or_Else or else
654 Nkind (P) = N_And_Then or else
655 Nkind (P) = N_If_Statement or else
656 Nkind (P) = N_Case_Statement
660 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
661 and then C /= First (Statements (P))
663 -- If the call is the expression of a return statement and
664 -- the actuals are identical to the formals, it's worth a
665 -- warning. However, we skip this if there is an immediately
666 -- preceding raise statement, since the call is never executed.
668 -- Furthermore, this corresponds to a common idiom:
670 -- function F (L : Thing) return Boolean is
672 -- raise Program_Error;
676 -- for generating a stub function
678 if Nkind (Parent (N)) = N_Return_Statement
679 and then Same_Argument_List
681 exit when not Is_List_Member (Parent (N))
682 or else (Nkind (Prev (Parent (N))) /= N_Raise_Statement
684 (Nkind (Prev (Parent (N))) not in N_Raise_xxx_Error
686 Present (Condition (Prev (Parent (N))))));
696 Error_Msg_N ("possible infinite recursion?", N);
697 Error_Msg_N ("\Storage_Error may be raised at run time?", N);
700 end Check_Infinite_Recursion;
702 -------------------------------
703 -- Check_Initialization_Call --
704 -------------------------------
706 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
707 Typ : constant Entity_Id := Etype (First_Formal (Nam));
709 function Uses_SS (T : Entity_Id) return Boolean;
710 -- Check whether the creation of an object of the type will involve
711 -- use of the secondary stack. If T is a record type, this is true
712 -- if the expression for some component uses the secondary stack, eg.
713 -- through a call to a function that returns an unconstrained value.
714 -- False if T is controlled, because cleanups occur elsewhere.
720 function Uses_SS (T : Entity_Id) return Boolean is
725 if Is_Controlled (T) then
728 elsif Is_Array_Type (T) then
729 return Uses_SS (Component_Type (T));
731 elsif Is_Record_Type (T) then
732 Comp := First_Component (T);
734 while Present (Comp) loop
736 if Ekind (Comp) = E_Component
737 and then Nkind (Parent (Comp)) = N_Component_Declaration
739 Expr := Expression (Parent (Comp));
741 -- The expression for a dynamic component may be
742 -- rewritten as a dereference. Retrieve original
745 if Nkind (Original_Node (Expr)) = N_Function_Call
746 and then Requires_Transient_Scope (Etype (Expr))
750 elsif Uses_SS (Etype (Comp)) then
755 Next_Component (Comp);
765 -- Start of processing for Check_Initialization_Call
768 -- Nothing to do if functions do not use the secondary stack for
769 -- returns (i.e. they use a depressed stack pointer instead).
771 if Functions_Return_By_DSP_On_Target then
774 -- Otherwise establish a transient scope if the type needs it
776 elsif Uses_SS (Typ) then
777 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
779 end Check_Initialization_Call;
781 ------------------------------
782 -- Check_Parameterless_Call --
783 ------------------------------
785 procedure Check_Parameterless_Call (N : Node_Id) is
789 -- Defend against junk stuff if errors already detected
791 if Total_Errors_Detected /= 0 then
792 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
794 elsif Nkind (N) in N_Has_Chars
795 and then Chars (N) in Error_Name_Or_No_Name
803 -- Rewrite as call if overloadable entity that is (or could be, in
804 -- the overloaded case) a function call. If we know for sure that
805 -- the entity is an enumeration literal, we do not rewrite it.
807 if (Is_Entity_Name (N)
808 and then Is_Overloadable (Entity (N))
809 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
810 or else Is_Overloaded (N)))
812 -- Rewrite as call if it is an explicit deference of an expression of
813 -- a subprogram access type, and the suprogram type is not that of a
814 -- procedure or entry.
817 (Nkind (N) = N_Explicit_Dereference
818 and then Ekind (Etype (N)) = E_Subprogram_Type
819 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type)
821 -- Rewrite as call if it is a selected component which is a function,
822 -- this is the case of a call to a protected function (which may be
823 -- overloaded with other protected operations).
826 (Nkind (N) = N_Selected_Component
827 and then (Ekind (Entity (Selector_Name (N))) = E_Function
829 ((Ekind (Entity (Selector_Name (N))) = E_Entry
831 Ekind (Entity (Selector_Name (N))) = E_Procedure)
832 and then Is_Overloaded (Selector_Name (N)))))
834 -- If one of the above three conditions is met, rewrite as call.
835 -- Apply the rewriting only once.
838 if Nkind (Parent (N)) /= N_Function_Call
839 or else N /= Name (Parent (N))
843 -- If overloaded, overload set belongs to new copy.
845 Save_Interps (N, Nam);
847 -- Change node to parameterless function call (note that the
848 -- Parameter_Associations associations field is left set to Empty,
849 -- its normal default value since there are no parameters)
851 Change_Node (N, N_Function_Call);
853 Set_Sloc (N, Sloc (Nam));
857 elsif Nkind (N) = N_Parameter_Association then
858 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
860 end Check_Parameterless_Call;
862 ----------------------
863 -- Is_Predefined_Op --
864 ----------------------
866 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
868 return Is_Intrinsic_Subprogram (Nam)
869 and then not Is_Generic_Instance (Nam)
870 and then Chars (Nam) in Any_Operator_Name
871 and then (No (Alias (Nam))
872 or else Is_Predefined_Op (Alias (Nam)));
873 end Is_Predefined_Op;
875 -----------------------------
876 -- Make_Call_Into_Operator --
877 -----------------------------
879 procedure Make_Call_Into_Operator
884 Op_Name : constant Name_Id := Chars (Op_Id);
885 Act1 : Node_Id := First_Actual (N);
886 Act2 : Node_Id := Next_Actual (Act1);
887 Error : Boolean := False;
888 Is_Binary : constant Boolean := Present (Act2);
890 Opnd_Type : Entity_Id;
891 Orig_Type : Entity_Id := Empty;
894 type Kind_Test is access function (E : Entity_Id) return Boolean;
896 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
897 -- Determine whether E is an access type declared by an access decla-
898 -- ration, and not an (anonymous) allocator type.
900 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
901 -- If the operand is not universal, and the operator is given by a
902 -- expanded name, verify that the operand has an interpretation with
903 -- a type defined in the given scope of the operator.
905 function Type_In_P (Test : Kind_Test) return Entity_Id;
906 -- Find a type of the given class in the package Pack that contains
909 -----------------------------
910 -- Is_Definite_Access_Type --
911 -----------------------------
913 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
914 Btyp : constant Entity_Id := Base_Type (E);
916 return Ekind (Btyp) = E_Access_Type
917 or else (Ekind (Btyp) = E_Access_Subprogram_Type
918 and then Comes_From_Source (Btyp));
919 end Is_Definite_Access_Type;
921 ---------------------------
922 -- Operand_Type_In_Scope --
923 ---------------------------
925 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
926 Nod : constant Node_Id := Right_Opnd (Op_Node);
931 if not Is_Overloaded (Nod) then
932 return Scope (Base_Type (Etype (Nod))) = S;
935 Get_First_Interp (Nod, I, It);
937 while Present (It.Typ) loop
939 if Scope (Base_Type (It.Typ)) = S then
943 Get_Next_Interp (I, It);
948 end Operand_Type_In_Scope;
954 function Type_In_P (Test : Kind_Test) return Entity_Id is
957 function In_Decl return Boolean;
958 -- Verify that node is not part of the type declaration for the
959 -- candidate type, which would otherwise be invisible.
965 function In_Decl return Boolean is
966 Decl_Node : constant Node_Id := Parent (E);
972 if Etype (E) = Any_Type then
975 elsif No (Decl_Node) then
980 and then Nkind (N2) /= N_Compilation_Unit
982 if N2 = Decl_Node then
993 -- Start of processing for Type_In_P
996 -- If the context type is declared in the prefix package, this
997 -- is the desired base type.
999 if Scope (Base_Type (Typ)) = Pack
1002 return Base_Type (Typ);
1005 E := First_Entity (Pack);
1007 while Present (E) loop
1010 and then not In_Decl
1022 -- Start of processing for Make_Call_Into_Operator
1025 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1030 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1031 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1032 Save_Interps (Act1, Left_Opnd (Op_Node));
1033 Save_Interps (Act2, Right_Opnd (Op_Node));
1034 Act1 := Left_Opnd (Op_Node);
1035 Act2 := Right_Opnd (Op_Node);
1040 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1041 Save_Interps (Act1, Right_Opnd (Op_Node));
1042 Act1 := Right_Opnd (Op_Node);
1045 -- If the operator is denoted by an expanded name, and the prefix is
1046 -- not Standard, but the operator is a predefined one whose scope is
1047 -- Standard, then this is an implicit_operator, inserted as an
1048 -- interpretation by the procedure of the same name. This procedure
1049 -- overestimates the presence of implicit operators, because it does
1050 -- not examine the type of the operands. Verify now that the operand
1051 -- type appears in the given scope. If right operand is universal,
1052 -- check the other operand. In the case of concatenation, either
1053 -- argument can be the component type, so check the type of the result.
1054 -- If both arguments are literals, look for a type of the right kind
1055 -- defined in the given scope. This elaborate nonsense is brought to
1056 -- you courtesy of b33302a. The type itself must be frozen, so we must
1057 -- find the type of the proper class in the given scope.
1059 -- A final wrinkle is the multiplication operator for fixed point
1060 -- types, which is defined in Standard only, and not in the scope of
1061 -- the fixed_point type itself.
1063 if Nkind (Name (N)) = N_Expanded_Name then
1064 Pack := Entity (Prefix (Name (N)));
1066 -- If the entity being called is defined in the given package,
1067 -- it is a renaming of a predefined operator, and known to be
1070 if Scope (Entity (Name (N))) = Pack
1071 and then Pack /= Standard_Standard
1075 elsif (Op_Name = Name_Op_Multiply
1076 or else Op_Name = Name_Op_Divide)
1077 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1078 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1080 if Pack /= Standard_Standard then
1085 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1087 if Op_Name = Name_Op_Concat then
1088 Opnd_Type := Base_Type (Typ);
1090 elsif (Scope (Opnd_Type) = Standard_Standard
1092 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1094 and then not Comes_From_Source (Opnd_Type))
1096 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1099 if Scope (Opnd_Type) = Standard_Standard then
1101 -- Verify that the scope contains a type that corresponds to
1102 -- the given literal. Optimize the case where Pack is Standard.
1104 if Pack /= Standard_Standard then
1106 if Opnd_Type = Universal_Integer then
1107 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1109 elsif Opnd_Type = Universal_Real then
1110 Orig_Type := Type_In_P (Is_Real_Type'Access);
1112 elsif Opnd_Type = Any_String then
1113 Orig_Type := Type_In_P (Is_String_Type'Access);
1115 elsif Opnd_Type = Any_Access then
1116 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1118 elsif Opnd_Type = Any_Composite then
1119 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1121 if Present (Orig_Type) then
1122 if Has_Private_Component (Orig_Type) then
1125 Set_Etype (Act1, Orig_Type);
1128 Set_Etype (Act2, Orig_Type);
1137 Error := No (Orig_Type);
1140 elsif Ekind (Opnd_Type) = E_Allocator_Type
1141 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1145 -- If the type is defined elsewhere, and the operator is not
1146 -- defined in the given scope (by a renaming declaration, e.g.)
1147 -- then this is an error as well. If an extension of System is
1148 -- present, and the type may be defined there, Pack must be
1151 elsif Scope (Opnd_Type) /= Pack
1152 and then Scope (Op_Id) /= Pack
1153 and then (No (System_Aux_Id)
1154 or else Scope (Opnd_Type) /= System_Aux_Id
1155 or else Pack /= Scope (System_Aux_Id))
1159 elsif Pack = Standard_Standard
1160 and then not Operand_Type_In_Scope (Standard_Standard)
1167 Error_Msg_Node_2 := Pack;
1169 ("& not declared in&", N, Selector_Name (Name (N)));
1170 Set_Etype (N, Any_Type);
1175 Set_Chars (Op_Node, Op_Name);
1177 if not Is_Private_Type (Etype (N)) then
1178 Set_Etype (Op_Node, Base_Type (Etype (N)));
1180 Set_Etype (Op_Node, Etype (N));
1183 Set_Entity (Op_Node, Op_Id);
1184 Generate_Reference (Op_Id, N, ' ');
1185 Rewrite (N, Op_Node);
1187 -- If this is an arithmetic operator and the result type is private,
1188 -- the operands and the result must be wrapped in conversion to
1189 -- expose the underlying numeric type and expand the proper checks,
1190 -- e.g. on division.
1192 if Is_Private_Type (Typ) then
1194 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1195 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1196 Resolve_Intrinsic_Operator (N, Typ);
1198 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1199 Resolve_Intrinsic_Unary_Operator (N, Typ);
1208 -- For predefined operators on literals, the operation freezes
1211 if Present (Orig_Type) then
1212 Set_Etype (Act1, Orig_Type);
1213 Freeze_Expression (Act1);
1215 end Make_Call_Into_Operator;
1221 function Operator_Kind
1223 Is_Binary : Boolean)
1230 if Op_Name = Name_Op_And then Kind := N_Op_And;
1231 elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
1232 elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
1233 elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
1234 elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
1235 elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
1236 elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
1237 elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
1238 elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
1239 elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
1240 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
1241 elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
1242 elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
1243 elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
1244 elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
1245 elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
1246 elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
1248 raise Program_Error;
1254 if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
1255 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
1256 elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
1257 elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
1259 raise Program_Error;
1266 -----------------------------
1267 -- Pre_Analyze_And_Resolve --
1268 -----------------------------
1270 procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1271 Save_Full_Analysis : constant Boolean := Full_Analysis;
1274 Full_Analysis := False;
1275 Expander_Mode_Save_And_Set (False);
1277 -- We suppress all checks for this analysis, since the checks will
1278 -- be applied properly, and in the right location, when the default
1279 -- expression is reanalyzed and reexpanded later on.
1281 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1283 Expander_Mode_Restore;
1284 Full_Analysis := Save_Full_Analysis;
1285 end Pre_Analyze_And_Resolve;
1287 -- Version without context type.
1289 procedure Pre_Analyze_And_Resolve (N : Node_Id) is
1290 Save_Full_Analysis : constant Boolean := Full_Analysis;
1293 Full_Analysis := False;
1294 Expander_Mode_Save_And_Set (False);
1297 Resolve (N, Etype (N), Suppress => All_Checks);
1299 Expander_Mode_Restore;
1300 Full_Analysis := Save_Full_Analysis;
1301 end Pre_Analyze_And_Resolve;
1303 ----------------------------------
1304 -- Replace_Actual_Discriminants --
1305 ----------------------------------
1307 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1308 Loc : constant Source_Ptr := Sloc (N);
1309 Tsk : Node_Id := Empty;
1311 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1317 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1321 if Nkind (Nod) = N_Identifier then
1322 Ent := Entity (Nod);
1325 and then Ekind (Ent) = E_Discriminant
1328 Make_Selected_Component (Loc,
1329 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1330 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1332 Set_Etype (Nod, Etype (Ent));
1340 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1342 -- Start of processing for Replace_Actual_Discriminants
1345 if not Expander_Active then
1349 if Nkind (Name (N)) = N_Selected_Component then
1350 Tsk := Prefix (Name (N));
1352 elsif Nkind (Name (N)) = N_Indexed_Component then
1353 Tsk := Prefix (Prefix (Name (N)));
1359 Replace_Discrs (Default);
1361 end Replace_Actual_Discriminants;
1367 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1369 I1 : Interp_Index := 0; -- prevent junk warning
1372 Found : Boolean := False;
1373 Seen : Entity_Id := Empty; -- prevent junk warning
1374 Ctx_Type : Entity_Id := Typ;
1375 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1376 Err_Type : Entity_Id := Empty;
1377 Ambiguous : Boolean := False;
1379 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1380 -- Try and fix up a literal so that it matches its expected type. New
1381 -- literals are manufactured if necessary to avoid cascaded errors.
1383 procedure Resolution_Failed;
1384 -- Called when attempt at resolving current expression fails
1386 --------------------
1387 -- Patch_Up_Value --
1388 --------------------
1390 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1392 if Nkind (N) = N_Integer_Literal
1393 and then Is_Real_Type (Typ)
1396 Make_Real_Literal (Sloc (N),
1397 Realval => UR_From_Uint (Intval (N))));
1398 Set_Etype (N, Universal_Real);
1399 Set_Is_Static_Expression (N);
1401 elsif Nkind (N) = N_Real_Literal
1402 and then Is_Integer_Type (Typ)
1405 Make_Integer_Literal (Sloc (N),
1406 Intval => UR_To_Uint (Realval (N))));
1407 Set_Etype (N, Universal_Integer);
1408 Set_Is_Static_Expression (N);
1409 elsif Nkind (N) = N_String_Literal
1410 and then Is_Character_Type (Typ)
1412 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1414 Make_Character_Literal (Sloc (N),
1416 Char_Literal_Value => Char_Code (Character'Pos ('A'))));
1417 Set_Etype (N, Any_Character);
1418 Set_Is_Static_Expression (N);
1420 elsif Nkind (N) /= N_String_Literal
1421 and then Is_String_Type (Typ)
1424 Make_String_Literal (Sloc (N),
1425 Strval => End_String));
1427 elsif Nkind (N) = N_Range then
1428 Patch_Up_Value (Low_Bound (N), Typ);
1429 Patch_Up_Value (High_Bound (N), Typ);
1433 -----------------------
1434 -- Resolution_Failed --
1435 -----------------------
1437 procedure Resolution_Failed is
1439 Patch_Up_Value (N, Typ);
1441 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1442 Set_Is_Overloaded (N, False);
1444 -- The caller will return without calling the expander, so we need
1445 -- to set the analyzed flag. Note that it is fine to set Analyzed
1446 -- to True even if we are in the middle of a shallow analysis,
1447 -- (see the spec of sem for more details) since this is an error
1448 -- situation anyway, and there is no point in repeating the
1449 -- analysis later (indeed it won't work to repeat it later, since
1450 -- we haven't got a clear resolution of which entity is being
1453 Set_Analyzed (N, True);
1455 end Resolution_Failed;
1457 -- Start of processing for Resolve
1464 -- Access attribute on remote subprogram cannot be used for
1465 -- a non-remote access-to-subprogram type.
1467 if Nkind (N) = N_Attribute_Reference
1468 and then (Attribute_Name (N) = Name_Access
1469 or else Attribute_Name (N) = Name_Unrestricted_Access
1470 or else Attribute_Name (N) = Name_Unchecked_Access)
1471 and then Comes_From_Source (N)
1472 and then Is_Entity_Name (Prefix (N))
1473 and then Is_Subprogram (Entity (Prefix (N)))
1474 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1475 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1478 ("prefix must statically denote a non-remote subprogram", N);
1481 -- If the context is a Remote_Access_To_Subprogram, access attributes
1482 -- must be resolved with the corresponding fat pointer. There is no need
1483 -- to check for the attribute name since the return type of an
1484 -- attribute is never a remote type.
1486 if Nkind (N) = N_Attribute_Reference
1487 and then Comes_From_Source (N)
1488 and then (Is_Remote_Call_Interface (Typ)
1489 or else Is_Remote_Types (Typ))
1492 Attr : constant Attribute_Id :=
1493 Get_Attribute_Id (Attribute_Name (N));
1494 Pref : constant Node_Id := Prefix (N);
1497 Is_Remote : Boolean := True;
1500 -- Check that Typ is a fat pointer with a reference to a RAS as
1501 -- original access type.
1504 (Ekind (Typ) = E_Access_Subprogram_Type
1505 and then Present (Equivalent_Type (Typ)))
1507 (Ekind (Typ) = E_Record_Type
1508 and then Present (Corresponding_Remote_Type (Typ)))
1511 -- Prefix (N) must statically denote a remote subprogram
1512 -- declared in a package specification.
1514 if Attr = Attribute_Access then
1515 Decl := Unit_Declaration_Node (Entity (Pref));
1517 if Nkind (Decl) = N_Subprogram_Body then
1518 Spec := Corresponding_Spec (Decl);
1520 if not No (Spec) then
1521 Decl := Unit_Declaration_Node (Spec);
1525 Spec := Parent (Decl);
1527 if not Is_Entity_Name (Prefix (N))
1528 or else Nkind (Spec) /= N_Package_Specification
1530 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1534 ("prefix must statically denote a remote subprogram ",
1539 -- If we are generating code for a distributed program.
1540 -- perform semantic checks against the corresponding
1543 if (Attr = Attribute_Access
1544 or else Attr = Attribute_Unchecked_Access
1545 or else Attr = Attribute_Unrestricted_Access)
1546 and then Expander_Active
1548 Check_Subtype_Conformant
1549 (New_Id => Entity (Prefix (N)),
1550 Old_Id => Designated_Type
1551 (Corresponding_Remote_Type (Typ)),
1554 Process_Remote_AST_Attribute (N, Typ);
1561 Debug_A_Entry ("resolving ", N);
1563 if Comes_From_Source (N) then
1564 if Is_Fixed_Point_Type (Typ) then
1565 Check_Restriction (No_Fixed_Point, N);
1567 elsif Is_Floating_Point_Type (Typ)
1568 and then Typ /= Universal_Real
1569 and then Typ /= Any_Real
1571 Check_Restriction (No_Floating_Point, N);
1575 -- Return if already analyzed
1577 if Analyzed (N) then
1578 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1581 -- Return if type = Any_Type (previous error encountered)
1583 elsif Etype (N) = Any_Type then
1584 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1588 Check_Parameterless_Call (N);
1590 -- If not overloaded, then we know the type, and all that needs doing
1591 -- is to check that this type is compatible with the context.
1593 if not Is_Overloaded (N) then
1594 Found := Covers (Typ, Etype (N));
1595 Expr_Type := Etype (N);
1597 -- In the overloaded case, we must select the interpretation that
1598 -- is compatible with the context (i.e. the type passed to Resolve)
1601 Get_First_Interp (N, I, It);
1603 -- Loop through possible interpretations
1605 Interp_Loop : while Present (It.Typ) loop
1607 -- We are only interested in interpretations that are compatible
1608 -- with the expected type, any other interpretations are ignored
1610 if not Covers (Typ, It.Typ) then
1611 if Debug_Flag_V then
1612 Write_Str (" interpretation incompatible with context");
1617 -- First matching interpretation
1623 Expr_Type := It.Typ;
1625 -- Matching interpretation that is not the first, maybe an
1626 -- error, but there are some cases where preference rules are
1627 -- used to choose between the two possibilities. These and
1628 -- some more obscure cases are handled in Disambiguate.
1631 Error_Msg_Sloc := Sloc (Seen);
1632 It1 := Disambiguate (N, I1, I, Typ);
1634 -- Disambiguation has succeeded. Skip the remaining
1637 if It1 /= No_Interp then
1639 Expr_Type := It1.Typ;
1641 while Present (It.Typ) loop
1642 Get_Next_Interp (I, It);
1646 -- Before we issue an ambiguity complaint, check for
1647 -- the case of a subprogram call where at least one
1648 -- of the arguments is Any_Type, and if so, suppress
1649 -- the message, since it is a cascaded error.
1651 if Nkind (N) = N_Function_Call
1652 or else Nkind (N) = N_Procedure_Call_Statement
1655 A : Node_Id := First_Actual (N);
1659 while Present (A) loop
1662 if Nkind (E) = N_Parameter_Association then
1663 E := Explicit_Actual_Parameter (E);
1666 if Etype (E) = Any_Type then
1667 if Debug_Flag_V then
1668 Write_Str ("Any_Type in call");
1679 elsif Nkind (N) in N_Binary_Op
1680 and then (Etype (Left_Opnd (N)) = Any_Type
1681 or else Etype (Right_Opnd (N)) = Any_Type)
1685 elsif Nkind (N) in N_Unary_Op
1686 and then Etype (Right_Opnd (N)) = Any_Type
1691 -- Not that special case, so issue message using the
1692 -- flag Ambiguous to control printing of the header
1693 -- message only at the start of an ambiguous set.
1695 if not Ambiguous then
1697 ("ambiguous expression (cannot resolve&)!",
1701 ("possible interpretation#!", N);
1705 Error_Msg_Sloc := Sloc (It.Nam);
1707 -- By default, the error message refers to the candidate
1708 -- interpretation. But if it is a predefined operator,
1709 -- it is implicitly declared at the declaration of
1710 -- the type of the operand. Recover the sloc of that
1711 -- declaration for the error message.
1713 if Nkind (N) in N_Op
1714 and then Scope (It.Nam) = Standard_Standard
1715 and then not Is_Overloaded (Right_Opnd (N))
1716 and then Scope (Base_Type (Etype (Right_Opnd (N))))
1717 /= Standard_Standard
1719 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
1721 if Comes_From_Source (Err_Type)
1722 and then Present (Parent (Err_Type))
1724 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1727 elsif Nkind (N) in N_Binary_Op
1728 and then Scope (It.Nam) = Standard_Standard
1729 and then not Is_Overloaded (Left_Opnd (N))
1730 and then Scope (Base_Type (Etype (Left_Opnd (N))))
1731 /= Standard_Standard
1733 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
1735 if Comes_From_Source (Err_Type)
1736 and then Present (Parent (Err_Type))
1738 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1744 if Nkind (N) in N_Op
1745 and then Scope (It.Nam) = Standard_Standard
1746 and then Present (Err_Type)
1749 ("possible interpretation (predefined)#!", N);
1751 Error_Msg_N ("possible interpretation#!", N);
1757 -- We have a matching interpretation, Expr_Type is the
1758 -- type from this interpretation, and Seen is the entity.
1760 -- For an operator, just set the entity name. The type will
1761 -- be set by the specific operator resolution routine.
1763 if Nkind (N) in N_Op then
1764 Set_Entity (N, Seen);
1765 Generate_Reference (Seen, N);
1767 elsif Nkind (N) = N_Character_Literal then
1768 Set_Etype (N, Expr_Type);
1770 -- For an explicit dereference, attribute reference, range,
1771 -- short-circuit form (which is not an operator node),
1772 -- or a call with a name that is an explicit dereference,
1773 -- there is nothing to be done at this point.
1775 elsif Nkind (N) = N_Explicit_Dereference
1776 or else Nkind (N) = N_Attribute_Reference
1777 or else Nkind (N) = N_And_Then
1778 or else Nkind (N) = N_Indexed_Component
1779 or else Nkind (N) = N_Or_Else
1780 or else Nkind (N) = N_Range
1781 or else Nkind (N) = N_Selected_Component
1782 or else Nkind (N) = N_Slice
1783 or else Nkind (Name (N)) = N_Explicit_Dereference
1787 -- For procedure or function calls, set the type of the
1788 -- name, and also the entity pointer for the prefix
1790 elsif (Nkind (N) = N_Procedure_Call_Statement
1791 or else Nkind (N) = N_Function_Call)
1792 and then (Is_Entity_Name (Name (N))
1793 or else Nkind (Name (N)) = N_Operator_Symbol)
1795 Set_Etype (Name (N), Expr_Type);
1796 Set_Entity (Name (N), Seen);
1797 Generate_Reference (Seen, Name (N));
1799 elsif Nkind (N) = N_Function_Call
1800 and then Nkind (Name (N)) = N_Selected_Component
1802 Set_Etype (Name (N), Expr_Type);
1803 Set_Entity (Selector_Name (Name (N)), Seen);
1804 Generate_Reference (Seen, Selector_Name (Name (N)));
1806 -- For all other cases, just set the type of the Name
1809 Set_Etype (Name (N), Expr_Type);
1814 -- Move to next interpretation
1816 exit Interp_Loop when not Present (It.Typ);
1818 Get_Next_Interp (I, It);
1819 end loop Interp_Loop;
1822 -- At this stage Found indicates whether or not an acceptable
1823 -- interpretation exists. If not, then we have an error, except
1824 -- that if the context is Any_Type as a result of some other error,
1825 -- then we suppress the error report.
1828 if Typ /= Any_Type then
1830 -- If type we are looking for is Void, then this is the
1831 -- procedure call case, and the error is simply that what
1832 -- we gave is not a procedure name (we think of procedure
1833 -- calls as expressions with types internally, but the user
1834 -- doesn't think of them this way!)
1836 if Typ = Standard_Void_Type then
1838 -- Special case message if function used as a procedure
1840 if Nkind (N) = N_Procedure_Call_Statement
1841 and then Is_Entity_Name (Name (N))
1842 and then Ekind (Entity (Name (N))) = E_Function
1845 ("cannot use function & in a procedure call",
1846 Name (N), Entity (Name (N)));
1848 -- Otherwise give general message (not clear what cases
1849 -- this covers, but no harm in providing for them!)
1852 Error_Msg_N ("expect procedure name in procedure call", N);
1857 -- Otherwise we do have a subexpression with the wrong type
1859 -- Check for the case of an allocator which uses an access
1860 -- type instead of the designated type. This is a common
1861 -- error and we specialize the message, posting an error
1862 -- on the operand of the allocator, complaining that we
1863 -- expected the designated type of the allocator.
1865 elsif Nkind (N) = N_Allocator
1866 and then Ekind (Typ) in Access_Kind
1867 and then Ekind (Etype (N)) in Access_Kind
1868 and then Designated_Type (Etype (N)) = Typ
1870 Wrong_Type (Expression (N), Designated_Type (Typ));
1873 -- Check for view mismatch on Null in instances, for
1874 -- which the view-swapping mechanism has no identifier.
1876 elsif (In_Instance or else In_Inlined_Body)
1877 and then (Nkind (N) = N_Null)
1878 and then Is_Private_Type (Typ)
1879 and then Is_Access_Type (Full_View (Typ))
1881 Resolve (N, Full_View (Typ));
1885 -- Check for an aggregate. Sometimes we can get bogus
1886 -- aggregates from misuse of parentheses, and we are
1887 -- about to complain about the aggregate without even
1888 -- looking inside it.
1890 -- Instead, if we have an aggregate of type Any_Composite,
1891 -- then analyze and resolve the component fields, and then
1892 -- only issue another message if we get no errors doing
1893 -- this (otherwise assume that the errors in the aggregate
1894 -- caused the problem).
1896 elsif Nkind (N) = N_Aggregate
1897 and then Etype (N) = Any_Composite
1899 -- Disable expansion in any case. If there is a type mismatch
1900 -- it may be fatal to try to expand the aggregate. The flag
1901 -- would otherwise be set to false when the error is posted.
1903 Expander_Active := False;
1906 procedure Check_Aggr (Aggr : Node_Id);
1907 -- Check one aggregate, and set Found to True if we
1908 -- have a definite error in any of its elements
1910 procedure Check_Elmt (Aelmt : Node_Id);
1911 -- Check one element of aggregate and set Found to
1912 -- True if we definitely have an error in the element.
1914 procedure Check_Aggr (Aggr : Node_Id) is
1918 if Present (Expressions (Aggr)) then
1919 Elmt := First (Expressions (Aggr));
1920 while Present (Elmt) loop
1926 if Present (Component_Associations (Aggr)) then
1927 Elmt := First (Component_Associations (Aggr));
1928 while Present (Elmt) loop
1929 Check_Elmt (Expression (Elmt));
1939 procedure Check_Elmt (Aelmt : Node_Id) is
1941 -- If we have a nested aggregate, go inside it (to
1942 -- attempt a naked analyze-resolve of the aggregate
1943 -- can cause undesirable cascaded errors). Do not
1944 -- resolve expression if it needs a type from context,
1945 -- as for integer * fixed expression.
1947 if Nkind (Aelmt) = N_Aggregate then
1953 if not Is_Overloaded (Aelmt)
1954 and then Etype (Aelmt) /= Any_Fixed
1959 if Etype (Aelmt) = Any_Type then
1970 -- If an error message was issued already, Found got reset
1971 -- to True, so if it is still False, issue the standard
1972 -- Wrong_Type message.
1975 if Is_Overloaded (N)
1976 and then Nkind (N) = N_Function_Call
1979 Subp_Name : Node_Id;
1981 if Is_Entity_Name (Name (N)) then
1982 Subp_Name := Name (N);
1984 elsif Nkind (Name (N)) = N_Selected_Component then
1986 -- Protected operation: retrieve operation name.
1988 Subp_Name := Selector_Name (Name (N));
1990 raise Program_Error;
1993 Error_Msg_Node_2 := Typ;
1994 Error_Msg_NE ("no visible interpretation of&" &
1995 " matches expected type&", N, Subp_Name);
1998 if All_Errors_Mode then
2000 Index : Interp_Index;
2004 Error_Msg_N ("\possible interpretations:", N);
2005 Get_First_Interp (Name (N), Index, It);
2007 while Present (It.Nam) loop
2009 Error_Msg_Sloc := Sloc (It.Nam);
2010 Error_Msg_Node_2 := It.Typ;
2011 Error_Msg_NE ("\& declared#, type&",
2014 Get_Next_Interp (Index, It);
2018 Error_Msg_N ("\use -gnatf for details", N);
2021 Wrong_Type (N, Typ);
2029 -- Test if we have more than one interpretation for the context
2031 elsif Ambiguous then
2035 -- Here we have an acceptable interpretation for the context
2038 -- A user-defined operator is tranformed into a function call at
2039 -- this point, so that further processing knows that operators are
2040 -- really operators (i.e. are predefined operators). User-defined
2041 -- operators that are intrinsic are just renamings of the predefined
2042 -- ones, and need not be turned into calls either, but if they rename
2043 -- a different operator, we must transform the node accordingly.
2044 -- Instantiations of Unchecked_Conversion are intrinsic but are
2045 -- treated as functions, even if given an operator designator.
2047 if Nkind (N) in N_Op
2048 and then Present (Entity (N))
2049 and then Ekind (Entity (N)) /= E_Operator
2052 if not Is_Predefined_Op (Entity (N)) then
2053 Rewrite_Operator_As_Call (N, Entity (N));
2055 elsif Present (Alias (Entity (N))) then
2056 Rewrite_Renamed_Operator (N, Alias (Entity (N)));
2060 -- Propagate type information and normalize tree for various
2061 -- predefined operations. If the context only imposes a class of
2062 -- types, rather than a specific type, propagate the actual type
2065 if Typ = Any_Integer
2066 or else Typ = Any_Boolean
2067 or else Typ = Any_Modular
2068 or else Typ = Any_Real
2069 or else Typ = Any_Discrete
2071 Ctx_Type := Expr_Type;
2073 -- Any_Fixed is legal in a real context only if a specific
2074 -- fixed point type is imposed. If Norman Cohen can be
2075 -- confused by this, it deserves a separate message.
2078 and then Expr_Type = Any_Fixed
2080 Error_Msg_N ("Illegal context for mixed mode operation", N);
2081 Set_Etype (N, Universal_Real);
2082 Ctx_Type := Universal_Real;
2086 case N_Subexpr'(Nkind (N)) is
2088 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2090 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2092 when N_And_Then | N_Or_Else
2093 => Resolve_Short_Circuit (N, Ctx_Type);
2095 when N_Attribute_Reference
2096 => Resolve_Attribute (N, Ctx_Type);
2098 when N_Character_Literal
2099 => Resolve_Character_Literal (N, Ctx_Type);
2101 when N_Conditional_Expression
2102 => Resolve_Conditional_Expression (N, Ctx_Type);
2104 when N_Expanded_Name
2105 => Resolve_Entity_Name (N, Ctx_Type);
2107 when N_Extension_Aggregate
2108 => Resolve_Extension_Aggregate (N, Ctx_Type);
2110 when N_Explicit_Dereference
2111 => Resolve_Explicit_Dereference (N, Ctx_Type);
2113 when N_Function_Call
2114 => Resolve_Call (N, Ctx_Type);
2117 => Resolve_Entity_Name (N, Ctx_Type);
2119 when N_In | N_Not_In
2120 => Resolve_Membership_Op (N, Ctx_Type);
2122 when N_Indexed_Component
2123 => Resolve_Indexed_Component (N, Ctx_Type);
2125 when N_Integer_Literal
2126 => Resolve_Integer_Literal (N, Ctx_Type);
2128 when N_Null => Resolve_Null (N, Ctx_Type);
2130 when N_Op_And | N_Op_Or | N_Op_Xor
2131 => Resolve_Logical_Op (N, Ctx_Type);
2133 when N_Op_Eq | N_Op_Ne
2134 => Resolve_Equality_Op (N, Ctx_Type);
2136 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2137 => Resolve_Comparison_Op (N, Ctx_Type);
2139 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2141 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2142 N_Op_Divide | N_Op_Mod | N_Op_Rem
2144 => Resolve_Arithmetic_Op (N, Ctx_Type);
2146 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2148 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2150 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2151 => Resolve_Unary_Op (N, Ctx_Type);
2153 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2155 when N_Procedure_Call_Statement
2156 => Resolve_Call (N, Ctx_Type);
2158 when N_Operator_Symbol
2159 => Resolve_Operator_Symbol (N, Ctx_Type);
2161 when N_Qualified_Expression
2162 => Resolve_Qualified_Expression (N, Ctx_Type);
2164 when N_Raise_xxx_Error
2165 => Set_Etype (N, Ctx_Type);
2167 when N_Range => Resolve_Range (N, Ctx_Type);
2170 => Resolve_Real_Literal (N, Ctx_Type);
2172 when N_Reference => Resolve_Reference (N, Ctx_Type);
2174 when N_Selected_Component
2175 => Resolve_Selected_Component (N, Ctx_Type);
2177 when N_Slice => Resolve_Slice (N, Ctx_Type);
2179 when N_String_Literal
2180 => Resolve_String_Literal (N, Ctx_Type);
2182 when N_Subprogram_Info
2183 => Resolve_Subprogram_Info (N, Ctx_Type);
2185 when N_Type_Conversion
2186 => Resolve_Type_Conversion (N, Ctx_Type);
2188 when N_Unchecked_Expression =>
2189 Resolve_Unchecked_Expression (N, Ctx_Type);
2191 when N_Unchecked_Type_Conversion =>
2192 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2196 -- If the subexpression was replaced by a non-subexpression, then
2197 -- all we do is to expand it. The only legitimate case we know of
2198 -- is converting procedure call statement to entry call statements,
2199 -- but there may be others, so we are making this test general.
2201 if Nkind (N) not in N_Subexpr then
2202 Debug_A_Exit ("resolving ", N, " (done)");
2207 -- The expression is definitely NOT overloaded at this point, so
2208 -- we reset the Is_Overloaded flag to avoid any confusion when
2209 -- reanalyzing the node.
2211 Set_Is_Overloaded (N, False);
2213 -- Freeze expression type, entity if it is a name, and designated
2214 -- type if it is an allocator (RM 13.14(10,11,13)).
2216 -- Now that the resolution of the type of the node is complete,
2217 -- and we did not detect an error, we can expand this node. We
2218 -- skip the expand call if we are in a default expression, see
2219 -- section "Handling of Default Expressions" in Sem spec.
2221 Debug_A_Exit ("resolving ", N, " (done)");
2223 -- We unconditionally freeze the expression, even if we are in
2224 -- default expression mode (the Freeze_Expression routine tests
2225 -- this flag and only freezes static types if it is set).
2227 Freeze_Expression (N);
2229 -- Now we can do the expansion
2239 -- Version with check(s) suppressed
2241 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2243 if Suppress = All_Checks then
2245 Svg : constant Suppress_Array := Scope_Suppress;
2248 Scope_Suppress := (others => True);
2250 Scope_Suppress := Svg;
2255 Svg : constant Boolean := Scope_Suppress (Suppress);
2258 Scope_Suppress (Suppress) := True;
2260 Scope_Suppress (Suppress) := Svg;
2269 -- Version with implicit type
2271 procedure Resolve (N : Node_Id) is
2273 Resolve (N, Etype (N));
2276 ---------------------
2277 -- Resolve_Actuals --
2278 ---------------------
2280 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2281 Loc : constant Source_Ptr := Sloc (N);
2286 Prev : Node_Id := Empty;
2288 procedure Insert_Default;
2289 -- If the actual is missing in a call, insert in the actuals list
2290 -- an instance of the default expression. The insertion is always
2291 -- a named association.
2293 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2294 -- Check whether T1 and T2, or their full views, are derived from a
2295 -- common type. Used to enforce the restrictions on array conversions
2298 --------------------
2299 -- Insert_Default --
2300 --------------------
2302 procedure Insert_Default is
2307 -- Missing argument in call, nothing to insert
2309 if No (Default_Value (F)) then
2313 -- Note that we do a full New_Copy_Tree, so that any associated
2314 -- Itypes are properly copied. This may not be needed any more,
2315 -- but it does no harm as a safety measure! Defaults of a generic
2316 -- formal may be out of bounds of the corresponding actual (see
2317 -- cc1311b) and an additional check may be required.
2319 Actval := New_Copy_Tree (Default_Value (F),
2320 New_Scope => Current_Scope, New_Sloc => Loc);
2322 if Is_Concurrent_Type (Scope (Nam))
2323 and then Has_Discriminants (Scope (Nam))
2325 Replace_Actual_Discriminants (N, Actval);
2328 if Is_Overloadable (Nam)
2329 and then Present (Alias (Nam))
2331 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2332 and then not Is_Tagged_Type (Etype (F))
2334 -- If default is a real literal, do not introduce a
2335 -- conversion whose effect may depend on the run-time
2336 -- size of universal real.
2338 if Nkind (Actval) = N_Real_Literal then
2339 Set_Etype (Actval, Base_Type (Etype (F)));
2341 Actval := Unchecked_Convert_To (Etype (F), Actval);
2345 if Is_Scalar_Type (Etype (F)) then
2346 Enable_Range_Check (Actval);
2349 Set_Parent (Actval, N);
2351 -- Resolve aggregates with their base type, to avoid scope
2352 -- anomalies: the subtype was first built in the suprogram
2353 -- declaration, and the current call may be nested.
2355 if Nkind (Actval) = N_Aggregate
2356 and then Has_Discriminants (Etype (Actval))
2358 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2360 Analyze_And_Resolve (Actval, Etype (Actval));
2364 Set_Parent (Actval, N);
2366 -- See note above concerning aggregates.
2368 if Nkind (Actval) = N_Aggregate
2369 and then Has_Discriminants (Etype (Actval))
2371 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2373 -- Resolve entities with their own type, which may differ
2374 -- from the type of a reference in a generic context (the
2375 -- view swapping mechanism did not anticipate the re-analysis
2376 -- of default values in calls).
2378 elsif Is_Entity_Name (Actval) then
2379 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2382 Analyze_And_Resolve (Actval, Etype (Actval));
2386 -- If default is a tag indeterminate function call, propagate
2387 -- tag to obtain proper dispatching.
2389 if Is_Controlling_Formal (F)
2390 and then Nkind (Default_Value (F)) = N_Function_Call
2392 Set_Is_Controlling_Actual (Actval);
2397 -- If the default expression raises constraint error, then just
2398 -- silently replace it with an N_Raise_Constraint_Error node,
2399 -- since we already gave the warning on the subprogram spec.
2401 if Raises_Constraint_Error (Actval) then
2403 Make_Raise_Constraint_Error (Loc,
2404 Reason => CE_Range_Check_Failed));
2405 Set_Raises_Constraint_Error (Actval);
2406 Set_Etype (Actval, Etype (F));
2410 Make_Parameter_Association (Loc,
2411 Explicit_Actual_Parameter => Actval,
2412 Selector_Name => Make_Identifier (Loc, Chars (F)));
2414 -- Case of insertion is first named actual
2416 if No (Prev) or else
2417 Nkind (Parent (Prev)) /= N_Parameter_Association
2419 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2420 Set_First_Named_Actual (N, Actval);
2423 if not Present (Parameter_Associations (N)) then
2424 Set_Parameter_Associations (N, New_List (Assoc));
2426 Append (Assoc, Parameter_Associations (N));
2430 Insert_After (Prev, Assoc);
2433 -- Case of insertion is not first named actual
2436 Set_Next_Named_Actual
2437 (Assoc, Next_Named_Actual (Parent (Prev)));
2438 Set_Next_Named_Actual (Parent (Prev), Actval);
2439 Append (Assoc, Parameter_Associations (N));
2442 Mark_Rewrite_Insertion (Assoc);
2443 Mark_Rewrite_Insertion (Actval);
2452 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2453 FT1 : Entity_Id := T1;
2454 FT2 : Entity_Id := T2;
2457 if Is_Private_Type (T1)
2458 and then Present (Full_View (T1))
2460 FT1 := Full_View (T1);
2463 if Is_Private_Type (T2)
2464 and then Present (Full_View (T2))
2466 FT2 := Full_View (T2);
2469 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
2472 -- Start of processing for Resolve_Actuals
2475 A := First_Actual (N);
2476 F := First_Formal (Nam);
2478 while Present (F) loop
2479 if No (A) and then Needs_No_Actuals (Nam) then
2482 -- If we have an error in any actual or formal, indicated by
2483 -- a type of Any_Type, then abandon resolution attempt, and
2484 -- set result type to Any_Type.
2486 elsif (Present (A) and then Etype (A) = Any_Type)
2487 or else Etype (F) = Any_Type
2489 Set_Etype (N, Any_Type);
2494 and then (Nkind (Parent (A)) /= N_Parameter_Association
2496 Chars (Selector_Name (Parent (A))) = Chars (F))
2498 -- If the formal is Out or In_Out, do not resolve and expand the
2499 -- conversion, because it is subsequently expanded into explicit
2500 -- temporaries and assignments. However, the object of the
2501 -- conversion can be resolved. An exception is the case of
2502 -- a tagged type conversion with a class-wide actual. In that
2503 -- case we want the tag check to occur and no temporary will
2504 -- will be needed (no representation change can occur) and
2505 -- the parameter is passed by reference, so we go ahead and
2506 -- resolve the type conversion.
2508 if Ekind (F) /= E_In_Parameter
2509 and then Nkind (A) = N_Type_Conversion
2510 and then not Is_Class_Wide_Type (Etype (Expression (A)))
2512 if Ekind (F) = E_In_Out_Parameter
2513 and then Is_Array_Type (Etype (F))
2515 if Has_Aliased_Components (Etype (Expression (A)))
2516 /= Has_Aliased_Components (Etype (F))
2519 ("both component types in a view conversion must be"
2520 & " aliased, or neither", A);
2522 elsif not Same_Ancestor (Etype (F), Etype (Expression (A)))
2524 (Is_By_Reference_Type (Etype (F))
2525 or else Is_By_Reference_Type (Etype (Expression (A))))
2528 ("view conversion between unrelated by_reference "
2529 & "array types not allowed (\A\I-00246)?", A);
2533 if Conversion_OK (A)
2534 or else Valid_Conversion (A, Etype (A), Expression (A))
2536 Resolve (Expression (A));
2540 if Nkind (A) = N_Type_Conversion
2541 and then Is_Array_Type (Etype (F))
2542 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
2544 (Is_Limited_Type (Etype (F))
2545 or else Is_Limited_Type (Etype (Expression (A))))
2548 ("Conversion between unrelated limited array types "
2549 & "not allowed (\A\I-00246)?", A);
2551 -- Disable explanation (which produces additional errors)
2552 -- until AI is approved and warning becomes an error.
2554 -- if Is_Limited_Type (Etype (F)) then
2555 -- Explain_Limited_Type (Etype (F), A);
2558 -- if Is_Limited_Type (Etype (Expression (A))) then
2559 -- Explain_Limited_Type (Etype (Expression (A)), A);
2563 Resolve (A, Etype (F));
2569 -- Perform error checks for IN and IN OUT parameters
2571 if Ekind (F) /= E_Out_Parameter then
2573 -- Check unset reference. For scalar parameters, it is clearly
2574 -- wrong to pass an uninitialized value as either an IN or
2575 -- IN-OUT parameter. For composites, it is also clearly an
2576 -- error to pass a completely uninitialized value as an IN
2577 -- parameter, but the case of IN OUT is trickier. We prefer
2578 -- not to give a warning here. For example, suppose there is
2579 -- a routine that sets some component of a record to False.
2580 -- It is perfectly reasonable to make this IN-OUT and allow
2581 -- either initialized or uninitialized records to be passed
2584 -- For partially initialized composite values, we also avoid
2585 -- warnings, since it is quite likely that we are passing a
2586 -- partially initialized value and only the initialized fields
2587 -- will in fact be read in the subprogram.
2589 if Is_Scalar_Type (A_Typ)
2590 or else (Ekind (F) = E_In_Parameter
2591 and then not Is_Partially_Initialized_Type (A_Typ))
2593 Check_Unset_Reference (A);
2596 -- In Ada 83 we cannot pass an OUT parameter as an IN
2597 -- or IN OUT actual to a nested call, since this is a
2598 -- case of reading an out parameter, which is not allowed.
2601 and then Is_Entity_Name (A)
2602 and then Ekind (Entity (A)) = E_Out_Parameter
2604 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2608 if Ekind (F) /= E_In_Parameter
2609 and then not Is_OK_Variable_For_Out_Formal (A)
2611 Error_Msg_NE ("actual for& must be a variable", A, F);
2613 if Is_Entity_Name (A) then
2614 Kill_Checks (Entity (A));
2620 if Etype (A) = Any_Type then
2621 Set_Etype (N, Any_Type);
2625 -- Apply appropriate range checks for in, out, and in-out
2626 -- parameters. Out and in-out parameters also need a separate
2627 -- check, if there is a type conversion, to make sure the return
2628 -- value meets the constraints of the variable before the
2631 -- Gigi looks at the check flag and uses the appropriate types.
2632 -- For now since one flag is used there is an optimization which
2633 -- might not be done in the In Out case since Gigi does not do
2634 -- any analysis. More thought required about this ???
2636 if Ekind (F) = E_In_Parameter
2637 or else Ekind (F) = E_In_Out_Parameter
2639 if Is_Scalar_Type (Etype (A)) then
2640 Apply_Scalar_Range_Check (A, F_Typ);
2642 elsif Is_Array_Type (Etype (A)) then
2643 Apply_Length_Check (A, F_Typ);
2645 elsif Is_Record_Type (F_Typ)
2646 and then Has_Discriminants (F_Typ)
2647 and then Is_Constrained (F_Typ)
2648 and then (not Is_Derived_Type (F_Typ)
2649 or else Comes_From_Source (Nam))
2651 Apply_Discriminant_Check (A, F_Typ);
2653 elsif Is_Access_Type (F_Typ)
2654 and then Is_Array_Type (Designated_Type (F_Typ))
2655 and then Is_Constrained (Designated_Type (F_Typ))
2657 Apply_Length_Check (A, F_Typ);
2659 elsif Is_Access_Type (F_Typ)
2660 and then Has_Discriminants (Designated_Type (F_Typ))
2661 and then Is_Constrained (Designated_Type (F_Typ))
2663 Apply_Discriminant_Check (A, F_Typ);
2666 Apply_Range_Check (A, F_Typ);
2670 if Ekind (F) = E_Out_Parameter
2671 or else Ekind (F) = E_In_Out_Parameter
2673 if Nkind (A) = N_Type_Conversion then
2674 if Is_Scalar_Type (A_Typ) then
2675 Apply_Scalar_Range_Check
2676 (Expression (A), Etype (Expression (A)), A_Typ);
2679 (Expression (A), Etype (Expression (A)), A_Typ);
2683 if Is_Scalar_Type (F_Typ) then
2684 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2686 elsif Is_Array_Type (F_Typ)
2687 and then Ekind (F) = E_Out_Parameter
2689 Apply_Length_Check (A, F_Typ);
2692 Apply_Range_Check (A, A_Typ, F_Typ);
2697 -- An actual associated with an access parameter is implicitly
2698 -- converted to the anonymous access type of the formal and
2699 -- must satisfy the legality checks for access conversions.
2701 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2702 if not Valid_Conversion (A, F_Typ, A) then
2704 ("invalid implicit conversion for access parameter", A);
2708 -- Check bad case of atomic/volatile argument (RM C.6(12))
2710 if Is_By_Reference_Type (Etype (F))
2711 and then Comes_From_Source (N)
2713 if Is_Atomic_Object (A)
2714 and then not Is_Atomic (Etype (F))
2717 ("cannot pass atomic argument to non-atomic formal",
2720 elsif Is_Volatile_Object (A)
2721 and then not Is_Volatile (Etype (F))
2724 ("cannot pass volatile argument to non-volatile formal",
2729 -- Check that subprograms don't have improper controlling
2730 -- arguments (RM 3.9.2 (9))
2732 if Is_Controlling_Formal (F) then
2733 Set_Is_Controlling_Actual (A);
2734 elsif Nkind (A) = N_Explicit_Dereference then
2735 Validate_Remote_Access_To_Class_Wide_Type (A);
2738 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2739 and then not Is_Class_Wide_Type (F_Typ)
2740 and then not Is_Controlling_Formal (F)
2742 Error_Msg_N ("class-wide argument not allowed here!", A);
2744 if Is_Subprogram (Nam)
2745 and then Comes_From_Source (Nam)
2747 Error_Msg_Node_2 := F_Typ;
2749 ("& is not a primitive operation of &!", A, Nam);
2752 elsif Is_Access_Type (A_Typ)
2753 and then Is_Access_Type (F_Typ)
2754 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2755 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2756 or else (Nkind (A) = N_Attribute_Reference
2758 Is_Class_Wide_Type (Etype (Prefix (A)))))
2759 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2760 and then not Is_Controlling_Formal (F)
2763 ("access to class-wide argument not allowed here!", A);
2765 if Is_Subprogram (Nam)
2766 and then Comes_From_Source (Nam)
2768 Error_Msg_Node_2 := Designated_Type (F_Typ);
2770 ("& is not a primitive operation of &!", A, Nam);
2776 -- If it is a named association, treat the selector_name as
2777 -- a proper identifier, and mark the corresponding entity.
2779 if Nkind (Parent (A)) = N_Parameter_Association then
2780 Set_Entity (Selector_Name (Parent (A)), F);
2781 Generate_Reference (F, Selector_Name (Parent (A)));
2782 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2783 Generate_Reference (F_Typ, N, ' ');
2788 if Ekind (F) /= E_Out_Parameter then
2789 Check_Unset_Reference (A);
2794 -- Case where actual is not present
2802 end Resolve_Actuals;
2804 -----------------------
2805 -- Resolve_Allocator --
2806 -----------------------
2808 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2809 E : constant Node_Id := Expression (N);
2811 Discrim : Entity_Id;
2815 function In_Dispatching_Context return Boolean;
2816 -- If the allocator is an actual in a call, it is allowed to be
2817 -- class-wide when the context is not because it is a controlling
2820 ----------------------------
2821 -- In_Dispatching_Context --
2822 ----------------------------
2824 function In_Dispatching_Context return Boolean is
2825 Par : constant Node_Id := Parent (N);
2828 return (Nkind (Par) = N_Function_Call
2829 or else Nkind (Par) = N_Procedure_Call_Statement)
2830 and then Is_Entity_Name (Name (Par))
2831 and then Is_Dispatching_Operation (Entity (Name (Par)));
2832 end In_Dispatching_Context;
2834 -- Start of processing for Resolve_Allocator
2837 -- Replace general access with specific type
2839 if Ekind (Etype (N)) = E_Allocator_Type then
2840 Set_Etype (N, Base_Type (Typ));
2843 if Is_Abstract (Typ) then
2844 Error_Msg_N ("type of allocator cannot be abstract", N);
2847 -- For qualified expression, resolve the expression using the
2848 -- given subtype (nothing to do for type mark, subtype indication)
2850 if Nkind (E) = N_Qualified_Expression then
2851 if Is_Class_Wide_Type (Etype (E))
2852 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2853 and then not In_Dispatching_Context
2856 ("class-wide allocator not allowed for this access type", N);
2859 Resolve (Expression (E), Etype (E));
2860 Check_Unset_Reference (Expression (E));
2862 -- A qualified expression requires an exact match of the type,
2863 -- class-wide matching is not allowed.
2865 if (Is_Class_Wide_Type (Etype (Expression (E)))
2866 or else Is_Class_Wide_Type (Etype (E)))
2867 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
2869 Wrong_Type (Expression (E), Etype (E));
2872 -- For a subtype mark or subtype indication, freeze the subtype
2875 Freeze_Expression (E);
2877 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2879 ("initialization required for access-to-constant allocator", N);
2882 -- A special accessibility check is needed for allocators that
2883 -- constrain access discriminants. The level of the type of the
2884 -- expression used to contrain an access discriminant cannot be
2885 -- deeper than the type of the allocator (in constrast to access
2886 -- parameters, where the level of the actual can be arbitrary).
2887 -- We can't use Valid_Conversion to perform this check because
2888 -- in general the type of the allocator is unrelated to the type
2889 -- of the access discriminant. Note that specialized checks are
2890 -- needed for the cases of a constraint expression which is an
2891 -- access attribute or an access discriminant.
2893 if Nkind (Original_Node (E)) = N_Subtype_Indication
2894 and then Ekind (Typ) /= E_Anonymous_Access_Type
2896 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2898 if Has_Discriminants (Subtyp) then
2899 Discrim := First_Discriminant (Base_Type (Subtyp));
2900 Constr := First (Constraints (Constraint (Original_Node (E))));
2902 while Present (Discrim) and then Present (Constr) loop
2903 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
2904 if Nkind (Constr) = N_Discriminant_Association then
2905 Disc_Exp := Original_Node (Expression (Constr));
2907 Disc_Exp := Original_Node (Constr);
2910 if Type_Access_Level (Etype (Disc_Exp))
2911 > Type_Access_Level (Typ)
2914 ("operand type has deeper level than allocator type",
2917 elsif Nkind (Disc_Exp) = N_Attribute_Reference
2918 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
2920 and then Object_Access_Level (Prefix (Disc_Exp))
2921 > Type_Access_Level (Typ)
2924 ("prefix of attribute has deeper level than"
2925 & " allocator type", Disc_Exp);
2927 -- When the operand is an access discriminant the check
2928 -- is against the level of the prefix object.
2930 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
2931 and then Nkind (Disc_Exp) = N_Selected_Component
2932 and then Object_Access_Level (Prefix (Disc_Exp))
2933 > Type_Access_Level (Typ)
2936 ("access discriminant has deeper level than"
2937 & " allocator type", Disc_Exp);
2940 Next_Discriminant (Discrim);
2947 -- Check for allocation from an empty storage pool
2949 if No_Pool_Assigned (Typ) then
2951 Loc : constant Source_Ptr := Sloc (N);
2954 Error_Msg_N ("?allocation from empty storage pool!", N);
2955 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
2957 Make_Raise_Storage_Error (Loc,
2958 Reason => SE_Empty_Storage_Pool));
2961 end Resolve_Allocator;
2963 ---------------------------
2964 -- Resolve_Arithmetic_Op --
2965 ---------------------------
2967 -- Used for resolving all arithmetic operators except exponentiation
2969 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
2970 L : constant Node_Id := Left_Opnd (N);
2971 R : constant Node_Id := Right_Opnd (N);
2972 TL : constant Entity_Id := Base_Type (Etype (L));
2973 TR : constant Entity_Id := Base_Type (Etype (R));
2977 B_Typ : constant Entity_Id := Base_Type (Typ);
2978 -- We do the resolution using the base type, because intermediate values
2979 -- in expressions always are of the base type, not a subtype of it.
2981 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
2982 -- Return True iff given type is Integer or universal real/integer
2984 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
2985 -- Choose type of integer literal in fixed-point operation to conform
2986 -- to available fixed-point type. T is the type of the other operand,
2987 -- which is needed to determine the expected type of N.
2989 procedure Set_Operand_Type (N : Node_Id);
2990 -- Set operand type to T if universal
2992 -----------------------------
2993 -- Is_Integer_Or_Universal --
2994 -----------------------------
2996 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
2998 Index : Interp_Index;
3002 if not Is_Overloaded (N) then
3004 return Base_Type (T) = Base_Type (Standard_Integer)
3005 or else T = Universal_Integer
3006 or else T = Universal_Real;
3008 Get_First_Interp (N, Index, It);
3010 while Present (It.Typ) loop
3012 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
3013 or else It.Typ = Universal_Integer
3014 or else It.Typ = Universal_Real
3019 Get_Next_Interp (Index, It);
3024 end Is_Integer_Or_Universal;
3026 ----------------------------
3027 -- Set_Mixed_Mode_Operand --
3028 ----------------------------
3030 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
3031 Index : Interp_Index;
3035 if Universal_Interpretation (N) = Universal_Integer then
3037 -- A universal integer literal is resolved as standard integer
3038 -- except in the case of a fixed-point result, where we leave
3039 -- it as universal (to be handled by Exp_Fixd later on)
3041 if Is_Fixed_Point_Type (T) then
3042 Resolve (N, Universal_Integer);
3044 Resolve (N, Standard_Integer);
3047 elsif Universal_Interpretation (N) = Universal_Real
3048 and then (T = Base_Type (Standard_Integer)
3049 or else T = Universal_Integer
3050 or else T = Universal_Real)
3052 -- A universal real can appear in a fixed-type context. We resolve
3053 -- the literal with that context, even though this might raise an
3054 -- exception prematurely (the other operand may be zero).
3058 elsif Etype (N) = Base_Type (Standard_Integer)
3059 and then T = Universal_Real
3060 and then Is_Overloaded (N)
3062 -- Integer arg in mixed-mode operation. Resolve with universal
3063 -- type, in case preference rule must be applied.
3065 Resolve (N, Universal_Integer);
3068 and then B_Typ /= Universal_Fixed
3070 -- Not a mixed-mode operation. Resolve with context.
3074 elsif Etype (N) = Any_Fixed then
3076 -- N may itself be a mixed-mode operation, so use context type.
3080 elsif Is_Fixed_Point_Type (T)
3081 and then B_Typ = Universal_Fixed
3082 and then Is_Overloaded (N)
3084 -- Must be (fixed * fixed) operation, operand must have one
3085 -- compatible interpretation.
3087 Resolve (N, Any_Fixed);
3089 elsif Is_Fixed_Point_Type (B_Typ)
3090 and then (T = Universal_Real
3091 or else Is_Fixed_Point_Type (T))
3092 and then Is_Overloaded (N)
3094 -- C * F(X) in a fixed context, where C is a real literal or a
3095 -- fixed-point expression. F must have either a fixed type
3096 -- interpretation or an integer interpretation, but not both.
3098 Get_First_Interp (N, Index, It);
3100 while Present (It.Typ) loop
3101 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
3103 if Analyzed (N) then
3104 Error_Msg_N ("ambiguous operand in fixed operation", N);
3106 Resolve (N, Standard_Integer);
3109 elsif Is_Fixed_Point_Type (It.Typ) then
3111 if Analyzed (N) then
3112 Error_Msg_N ("ambiguous operand in fixed operation", N);
3114 Resolve (N, It.Typ);
3118 Get_Next_Interp (Index, It);
3121 -- Reanalyze the literal with the fixed type of the context.
3124 Set_Analyzed (R, False);
3127 Set_Analyzed (L, False);
3134 end Set_Mixed_Mode_Operand;
3136 ----------------------
3137 -- Set_Operand_Type --
3138 ----------------------
3140 procedure Set_Operand_Type (N : Node_Id) is
3142 if Etype (N) = Universal_Integer
3143 or else Etype (N) = Universal_Real
3147 end Set_Operand_Type;
3149 -- Start of processing for Resolve_Arithmetic_Op
3152 if Comes_From_Source (N)
3153 and then Ekind (Entity (N)) = E_Function
3154 and then Is_Imported (Entity (N))
3155 and then Is_Intrinsic_Subprogram (Entity (N))
3157 Resolve_Intrinsic_Operator (N, Typ);
3160 -- Special-case for mixed-mode universal expressions or fixed point
3161 -- type operation: each argument is resolved separately. The same
3162 -- treatment is required if one of the operands of a fixed point
3163 -- operation is universal real, since in this case we don't do a
3164 -- conversion to a specific fixed-point type (instead the expander
3165 -- takes care of the case).
3167 elsif (B_Typ = Universal_Integer
3168 or else B_Typ = Universal_Real)
3169 and then Present (Universal_Interpretation (L))
3170 and then Present (Universal_Interpretation (R))
3172 Resolve (L, Universal_Interpretation (L));
3173 Resolve (R, Universal_Interpretation (R));
3174 Set_Etype (N, B_Typ);
3176 elsif (B_Typ = Universal_Real
3177 or else Etype (N) = Universal_Fixed
3178 or else (Etype (N) = Any_Fixed
3179 and then Is_Fixed_Point_Type (B_Typ))
3180 or else (Is_Fixed_Point_Type (B_Typ)
3181 and then (Is_Integer_Or_Universal (L)
3183 Is_Integer_Or_Universal (R))))
3184 and then (Nkind (N) = N_Op_Multiply or else
3185 Nkind (N) = N_Op_Divide)
3187 if TL = Universal_Integer or else TR = Universal_Integer then
3188 Check_For_Visible_Operator (N, B_Typ);
3191 -- If context is a fixed type and one operand is integer, the
3192 -- other is resolved with the type of the context.
3194 if Is_Fixed_Point_Type (B_Typ)
3195 and then (Base_Type (TL) = Base_Type (Standard_Integer)
3196 or else TL = Universal_Integer)
3201 elsif Is_Fixed_Point_Type (B_Typ)
3202 and then (Base_Type (TR) = Base_Type (Standard_Integer)
3203 or else TR = Universal_Integer)
3209 Set_Mixed_Mode_Operand (L, TR);
3210 Set_Mixed_Mode_Operand (R, TL);
3213 if Etype (N) = Universal_Fixed
3214 or else Etype (N) = Any_Fixed
3216 if B_Typ = Universal_Fixed
3217 and then Nkind (Parent (N)) /= N_Type_Conversion
3218 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3221 ("type cannot be determined from context!", N);
3223 ("\explicit conversion to result type required", N);
3225 Set_Etype (L, Any_Type);
3226 Set_Etype (R, Any_Type);
3230 and then Etype (N) = Universal_Fixed
3231 and then Nkind (Parent (N)) /= N_Type_Conversion
3232 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3235 ("(Ada 83) fixed-point operation " &
3236 "needs explicit conversion",
3240 Set_Etype (N, B_Typ);
3243 elsif Is_Fixed_Point_Type (B_Typ)
3244 and then (Is_Integer_Or_Universal (L)
3245 or else Nkind (L) = N_Real_Literal
3246 or else Nkind (R) = N_Real_Literal
3248 Is_Integer_Or_Universal (R))
3250 Set_Etype (N, B_Typ);
3252 elsif Etype (N) = Any_Fixed then
3254 -- If no previous errors, this is only possible if one operand
3255 -- is overloaded and the context is universal. Resolve as such.
3257 Set_Etype (N, B_Typ);
3261 if (TL = Universal_Integer or else TL = Universal_Real)
3262 and then (TR = Universal_Integer or else TR = Universal_Real)
3264 Check_For_Visible_Operator (N, B_Typ);
3267 -- If the context is Universal_Fixed and the operands are also
3268 -- universal fixed, this is an error, unless there is only one
3269 -- applicable fixed_point type (usually duration).
3271 if B_Typ = Universal_Fixed
3272 and then Etype (L) = Universal_Fixed
3274 T := Unique_Fixed_Point_Type (N);
3276 if T = Any_Type then
3289 -- If one of the arguments was resolved to a non-universal type.
3290 -- label the result of the operation itself with the same type.
3291 -- Do the same for the universal argument, if any.
3293 T := Intersect_Types (L, R);
3294 Set_Etype (N, Base_Type (T));
3295 Set_Operand_Type (L);
3296 Set_Operand_Type (R);
3299 Generate_Operator_Reference (N, Typ);
3300 Eval_Arithmetic_Op (N);
3302 -- Set overflow and division checking bit. Much cleverer code needed
3303 -- here eventually and perhaps the Resolve routines should be separated
3304 -- for the various arithmetic operations, since they will need
3305 -- different processing. ???
3307 if Nkind (N) in N_Op then
3308 if not Overflow_Checks_Suppressed (Etype (N)) then
3309 Enable_Overflow_Check (N);
3312 -- Give warning if explicit division by zero
3314 if (Nkind (N) = N_Op_Divide
3315 or else Nkind (N) = N_Op_Rem
3316 or else Nkind (N) = N_Op_Mod)
3317 and then not Division_Checks_Suppressed (Etype (N))
3319 Rop := Right_Opnd (N);
3321 if Compile_Time_Known_Value (Rop)
3322 and then ((Is_Integer_Type (Etype (Rop))
3323 and then Expr_Value (Rop) = Uint_0)
3325 (Is_Real_Type (Etype (Rop))
3326 and then Expr_Value_R (Rop) = Ureal_0))
3328 Apply_Compile_Time_Constraint_Error
3329 (N, "division by zero?", CE_Divide_By_Zero,
3330 Loc => Sloc (Right_Opnd (N)));
3332 -- Otherwise just set the flag to check at run time
3335 Set_Do_Division_Check (N);
3340 Check_Unset_Reference (L);
3341 Check_Unset_Reference (R);
3342 end Resolve_Arithmetic_Op;
3348 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
3349 Loc : constant Source_Ptr := Sloc (N);
3350 Subp : constant Node_Id := Name (N);
3359 -- The context imposes a unique interpretation with type Typ on
3360 -- a procedure or function call. Find the entity of the subprogram
3361 -- that yields the expected type, and propagate the corresponding
3362 -- formal constraints on the actuals. The caller has established
3363 -- that an interpretation exists, and emitted an error if not unique.
3365 -- First deal with the case of a call to an access-to-subprogram,
3366 -- dereference made explicit in Analyze_Call.
3368 if Ekind (Etype (Subp)) = E_Subprogram_Type then
3369 if not Is_Overloaded (Subp) then
3370 Nam := Etype (Subp);
3373 -- Find the interpretation whose type (a subprogram type)
3374 -- has a return type that is compatible with the context.
3375 -- Analysis of the node has established that one exists.
3377 Get_First_Interp (Subp, I, It);
3380 while Present (It.Typ) loop
3381 if Covers (Typ, Etype (It.Typ)) then
3386 Get_Next_Interp (I, It);
3390 raise Program_Error;
3394 -- If the prefix is not an entity, then resolve it
3396 if not Is_Entity_Name (Subp) then
3397 Resolve (Subp, Nam);
3400 -- For an indirect call, we always invalidate checks, since we
3401 -- do not know whether the subprogram is local or global. Yes
3402 -- we could do better here, e.g. by knowing that there are no
3403 -- local subprograms, but it does not seem worth the effort.
3404 -- Similarly, we kill al knowledge of current constant values.
3406 Kill_Current_Values;
3408 -- If this is a procedure call which is really an entry call, do
3409 -- the conversion of the procedure call to an entry call. Protected
3410 -- operations use the same circuitry because the name in the call
3411 -- can be an arbitrary expression with special resolution rules.
3413 elsif Nkind (Subp) = N_Selected_Component
3414 or else Nkind (Subp) = N_Indexed_Component
3415 or else (Is_Entity_Name (Subp)
3416 and then Ekind (Entity (Subp)) = E_Entry)
3418 Resolve_Entry_Call (N, Typ);
3419 Check_Elab_Call (N);
3421 -- Kill checks and constant values, as above for indirect case
3422 -- Who knows what happens when another task is activated?
3424 Kill_Current_Values;
3427 -- Normal subprogram call with name established in Resolve
3429 elsif not (Is_Type (Entity (Subp))) then
3430 Nam := Entity (Subp);
3431 Set_Entity_With_Style_Check (Subp, Nam);
3432 Generate_Reference (Nam, Subp);
3434 -- Otherwise we must have the case of an overloaded call
3437 pragma Assert (Is_Overloaded (Subp));
3438 Nam := Empty; -- We know that it will be assigned in loop below.
3440 Get_First_Interp (Subp, I, It);
3442 while Present (It.Typ) loop
3443 if Covers (Typ, It.Typ) then
3445 Set_Entity_With_Style_Check (Subp, Nam);
3446 Generate_Reference (Nam, Subp);
3450 Get_Next_Interp (I, It);
3454 -- Check that a call to Current_Task does not occur in an entry body
3456 if Is_RTE (Nam, RE_Current_Task) then
3466 if Nkind (P) = N_Entry_Body then
3468 ("& should not be used in entry body ('R'M C.7(17))",
3476 -- Cannot call thread body directly
3478 if Is_Thread_Body (Nam) then
3479 Error_Msg_N ("cannot call thread body directly", N);
3482 -- If the subprogram is not global, then kill all checks. This is
3483 -- a bit conservative, since in many cases we could do better, but
3484 -- it is not worth the effort. Similarly, we kill constant values.
3485 -- However we do not need to do this for internal entities (unless
3486 -- they are inherited user-defined subprograms), since they are not
3487 -- in the business of molesting global values.
3489 if not Is_Library_Level_Entity (Nam)
3490 and then (Comes_From_Source (Nam)
3491 or else (Present (Alias (Nam))
3492 and then Comes_From_Source (Alias (Nam))))
3494 Kill_Current_Values;
3497 -- Check for call to obsolescent subprogram
3499 if Warn_On_Obsolescent_Feature then
3500 Decl := Parent (Parent (Nam));
3502 if Nkind (Decl) = N_Subprogram_Declaration
3503 and then Is_List_Member (Decl)
3504 and then Nkind (Next (Decl)) = N_Pragma
3507 P : constant Node_Id := Next (Decl);
3510 if Chars (P) = Name_Obsolescent then
3511 Error_Msg_NE ("call to obsolescent subprogram&?", N, Nam);
3513 if Pragma_Argument_Associations (P) /= No_List then
3514 Name_Buffer (1) := '|';
3515 Name_Buffer (2) := '?';
3517 Add_String_To_Name_Buffer
3519 (First (Pragma_Argument_Associations (P)))));
3520 Error_Msg_N (Name_Buffer (1 .. Name_Len), N);
3527 -- Check that a procedure call does not occur in the context
3528 -- of the entry call statement of a conditional or timed
3529 -- entry call. Note that the case of a call to a subprogram
3530 -- renaming of an entry will also be rejected. The test
3531 -- for N not being an N_Entry_Call_Statement is defensive,
3532 -- covering the possibility that the processing of entry
3533 -- calls might reach this point due to later modifications
3534 -- of the code above.
3536 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3537 and then Nkind (N) /= N_Entry_Call_Statement
3538 and then Entry_Call_Statement (Parent (N)) = N
3540 Error_Msg_N ("entry call required in select statement", N);
3543 -- Check that this is not a call to a protected procedure or
3544 -- entry from within a protected function.
3546 if Ekind (Current_Scope) = E_Function
3547 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
3548 and then Ekind (Nam) /= E_Function
3549 and then Scope (Nam) = Scope (Current_Scope)
3551 Error_Msg_N ("within protected function, protected " &
3552 "object is constant", N);
3553 Error_Msg_N ("\cannot call operation that may modify it", N);
3556 -- Freeze the subprogram name if not in default expression. Note
3557 -- that we freeze procedure calls as well as function calls.
3558 -- Procedure calls are not frozen according to the rules (RM
3559 -- 13.14(14)) because it is impossible to have a procedure call to
3560 -- a non-frozen procedure in pure Ada, but in the code that we
3561 -- generate in the expander, this rule needs extending because we
3562 -- can generate procedure calls that need freezing.
3564 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3565 Freeze_Expression (Subp);
3568 -- For a predefined operator, the type of the result is the type
3569 -- imposed by context, except for a predefined operation on universal
3570 -- fixed. Otherwise The type of the call is the type returned by the
3571 -- subprogram being called.
3573 if Is_Predefined_Op (Nam) then
3574 if Etype (N) /= Universal_Fixed then
3578 -- If the subprogram returns an array type, and the context
3579 -- requires the component type of that array type, the node is
3580 -- really an indexing of the parameterless call. Resolve as such.
3581 -- A pathological case occurs when the type of the component is
3582 -- an access to the array type. In this case the call is truly
3585 elsif Needs_No_Actuals (Nam)
3587 ((Is_Array_Type (Etype (Nam))
3588 and then Covers (Typ, Component_Type (Etype (Nam))))
3589 or else (Is_Access_Type (Etype (Nam))
3590 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3593 Component_Type (Designated_Type (Etype (Nam))))))
3596 Index_Node : Node_Id;
3598 Ret_Type : constant Entity_Id := Etype (Nam);
3601 if Is_Access_Type (Ret_Type)
3602 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
3605 ("cannot disambiguate function call and indexing", N);
3607 New_Subp := Relocate_Node (Subp);
3608 Set_Entity (Subp, Nam);
3610 if Component_Type (Ret_Type) /= Any_Type then
3612 Make_Indexed_Component (Loc,
3614 Make_Function_Call (Loc,
3616 Expressions => Parameter_Associations (N));
3618 -- Since we are correcting a node classification error made
3619 -- by the parser, we call Replace rather than Rewrite.
3621 Replace (N, Index_Node);
3622 Set_Etype (Prefix (N), Ret_Type);
3624 Resolve_Indexed_Component (N, Typ);
3625 Check_Elab_Call (Prefix (N));
3633 Set_Etype (N, Etype (Nam));
3636 -- In the case where the call is to an overloaded subprogram, Analyze
3637 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3638 -- such a case Normalize_Actuals needs to be called once more to order
3639 -- the actuals correctly. Otherwise the call will have the ordering
3640 -- given by the last overloaded subprogram whether this is the correct
3641 -- one being called or not.
3643 if Is_Overloaded (Subp) then
3644 Normalize_Actuals (N, Nam, False, Norm_OK);
3645 pragma Assert (Norm_OK);
3648 -- In any case, call is fully resolved now. Reset Overload flag, to
3649 -- prevent subsequent overload resolution if node is analyzed again
3651 Set_Is_Overloaded (Subp, False);
3652 Set_Is_Overloaded (N, False);
3654 -- If we are calling the current subprogram from immediately within
3655 -- its body, then that is the case where we can sometimes detect
3656 -- cases of infinite recursion statically. Do not try this in case
3657 -- restriction No_Recursion is in effect anyway.
3659 Scop := Current_Scope;
3662 and then not Restrictions (No_Recursion)
3663 and then Check_Infinite_Recursion (N)
3665 -- Here we detected and flagged an infinite recursion, so we do
3666 -- not need to test the case below for further warnings.
3670 -- If call is to immediately containing subprogram, then check for
3671 -- the case of a possible run-time detectable infinite recursion.
3674 while Scop /= Standard_Standard loop
3676 -- Although in general recursion is not statically checkable,
3677 -- the case of calling an immediately containing subprogram
3678 -- is easy to catch.
3680 Check_Restriction (No_Recursion, N);
3682 -- If the recursive call is to a parameterless procedure, then
3683 -- even if we can't statically detect infinite recursion, this
3684 -- is pretty suspicious, and we output a warning. Furthermore,
3685 -- we will try later to detect some cases here at run time by
3686 -- expanding checking code (see Detect_Infinite_Recursion in
3687 -- package Exp_Ch6).
3688 -- If the recursive call is within a handler we do not emit a
3689 -- warning, because this is a common idiom: loop until input
3690 -- is correct, catch illegal input in handler and restart.
3692 if No (First_Formal (Nam))
3693 and then Etype (Nam) = Standard_Void_Type
3694 and then not Error_Posted (N)
3695 and then Nkind (Parent (N)) /= N_Exception_Handler
3697 Set_Has_Recursive_Call (Nam);
3698 Error_Msg_N ("possible infinite recursion?", N);
3699 Error_Msg_N ("Storage_Error may be raised at run time?", N);
3705 Scop := Scope (Scop);
3709 -- If subprogram name is a predefined operator, it was given in
3710 -- functional notation. Replace call node with operator node, so
3711 -- that actuals can be resolved appropriately.
3713 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3714 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3717 elsif Present (Alias (Nam))
3718 and then Is_Predefined_Op (Alias (Nam))
3720 Resolve_Actuals (N, Nam);
3721 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3725 -- Create a transient scope if the resulting type requires it
3727 -- There are 3 notable exceptions: in init procs, the transient scope
3728 -- overhead is not needed and even incorrect due to the actual expansion
3729 -- of adjust calls; the second case is enumeration literal pseudo calls,
3730 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3731 -- source information functions) that do not use the secondary stack
3732 -- even though the return type is unconstrained.
3734 -- If this is an initialization call for a type whose initialization
3735 -- uses the secondary stack, we also need to create a transient scope
3736 -- for it, precisely because we will not do it within the init proc
3740 and then Is_Type (Etype (Nam))
3741 and then Requires_Transient_Scope (Etype (Nam))
3742 and then Ekind (Nam) /= E_Enumeration_Literal
3743 and then not Within_Init_Proc
3744 and then not Is_Intrinsic_Subprogram (Nam)
3746 Establish_Transient_Scope
3747 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3749 -- If the call appears within the bounds of a loop, it will
3750 -- be rewritten and reanalyzed, nothing left to do here.
3752 if Nkind (N) /= N_Function_Call then
3756 elsif Is_Init_Proc (Nam)
3757 and then not Within_Init_Proc
3759 Check_Initialization_Call (N, Nam);
3762 -- A protected function cannot be called within the definition of the
3763 -- enclosing protected type.
3765 if Is_Protected_Type (Scope (Nam))
3766 and then In_Open_Scopes (Scope (Nam))
3767 and then not Has_Completion (Scope (Nam))
3770 ("& cannot be called before end of protected definition", N, Nam);
3773 -- Propagate interpretation to actuals, and add default expressions
3776 if Present (First_Formal (Nam)) then
3777 Resolve_Actuals (N, Nam);
3779 -- Overloaded literals are rewritten as function calls, for
3780 -- purpose of resolution. After resolution, we can replace
3781 -- the call with the literal itself.
3783 elsif Ekind (Nam) = E_Enumeration_Literal then
3784 Copy_Node (Subp, N);
3785 Resolve_Entity_Name (N, Typ);
3787 -- Avoid validation, since it is a static function call
3792 -- If the subprogram is a primitive operation, check whether or not
3793 -- it is a correct dispatching call.
3795 if Is_Overloadable (Nam)
3796 and then Is_Dispatching_Operation (Nam)
3798 Check_Dispatching_Call (N);
3800 elsif Is_Abstract (Nam)
3801 and then not In_Instance
3803 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
3806 if Is_Intrinsic_Subprogram (Nam) then
3807 Check_Intrinsic_Call (N);
3811 Check_Elab_Call (N);
3814 -------------------------------
3815 -- Resolve_Character_Literal --
3816 -------------------------------
3818 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3819 B_Typ : constant Entity_Id := Base_Type (Typ);
3823 -- Verify that the character does belong to the type of the context
3825 Set_Etype (N, B_Typ);
3826 Eval_Character_Literal (N);
3828 -- Wide_Character literals must always be defined, since the set of
3829 -- wide character literals is complete, i.e. if a character literal
3830 -- is accepted by the parser, then it is OK for wide character.
3832 if Root_Type (B_Typ) = Standard_Wide_Character then
3835 -- Always accept character literal for type Any_Character, which
3836 -- occurs in error situations and in comparisons of literals, both
3837 -- of which should accept all literals.
3839 elsif B_Typ = Any_Character then
3842 -- For Standard.Character or a type derived from it, check that
3843 -- the literal is in range
3845 elsif Root_Type (B_Typ) = Standard_Character then
3846 if In_Character_Range (Char_Literal_Value (N)) then
3850 -- If the entity is already set, this has already been resolved in
3851 -- a generic context, or comes from expansion. Nothing else to do.
3853 elsif Present (Entity (N)) then
3856 -- Otherwise we have a user defined character type, and we can use
3857 -- the standard visibility mechanisms to locate the referenced entity
3860 C := Current_Entity (N);
3862 while Present (C) loop
3863 if Etype (C) = B_Typ then
3864 Set_Entity_With_Style_Check (N, C);
3865 Generate_Reference (C, N);
3873 -- If we fall through, then the literal does not match any of the
3874 -- entries of the enumeration type. This isn't just a constraint
3875 -- error situation, it is an illegality (see RM 4.2).
3878 ("character not defined for }", N, First_Subtype (B_Typ));
3879 end Resolve_Character_Literal;
3881 ---------------------------
3882 -- Resolve_Comparison_Op --
3883 ---------------------------
3885 -- Context requires a boolean type, and plays no role in resolution.
3886 -- Processing identical to that for equality operators. The result
3887 -- type is the base type, which matters when pathological subtypes of
3888 -- booleans with limited ranges are used.
3890 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
3891 L : constant Node_Id := Left_Opnd (N);
3892 R : constant Node_Id := Right_Opnd (N);
3896 Check_Direct_Boolean_Op (N);
3898 -- If this is an intrinsic operation which is not predefined, use
3899 -- the types of its declared arguments to resolve the possibly
3900 -- overloaded operands. Otherwise the operands are unambiguous and
3901 -- specify the expected type.
3903 if Scope (Entity (N)) /= Standard_Standard then
3904 T := Etype (First_Entity (Entity (N)));
3906 T := Find_Unique_Type (L, R);
3908 if T = Any_Fixed then
3909 T := Unique_Fixed_Point_Type (L);
3913 Set_Etype (N, Base_Type (Typ));
3914 Generate_Reference (T, N, ' ');
3916 if T /= Any_Type then
3918 or else T = Any_Composite
3919 or else T = Any_Character
3921 if T = Any_Character then
3922 Ambiguous_Character (L);
3924 Error_Msg_N ("ambiguous operands for comparison", N);
3927 Set_Etype (N, Any_Type);
3931 if Comes_From_Source (N)
3932 and then Has_Unchecked_Union (T)
3935 ("cannot compare Unchecked_Union values", N);
3940 Check_Unset_Reference (L);
3941 Check_Unset_Reference (R);
3942 Generate_Operator_Reference (N, T);
3943 Eval_Relational_Op (N);
3946 end Resolve_Comparison_Op;
3948 ------------------------------------
3949 -- Resolve_Conditional_Expression --
3950 ------------------------------------
3952 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
3953 Condition : constant Node_Id := First (Expressions (N));
3954 Then_Expr : constant Node_Id := Next (Condition);
3955 Else_Expr : constant Node_Id := Next (Then_Expr);
3958 Resolve (Condition, Standard_Boolean);
3959 Resolve (Then_Expr, Typ);
3960 Resolve (Else_Expr, Typ);
3963 Eval_Conditional_Expression (N);
3964 end Resolve_Conditional_Expression;
3966 -----------------------------------------
3967 -- Resolve_Discrete_Subtype_Indication --
3968 -----------------------------------------
3970 procedure Resolve_Discrete_Subtype_Indication
3978 Analyze (Subtype_Mark (N));
3979 S := Entity (Subtype_Mark (N));
3981 if Nkind (Constraint (N)) /= N_Range_Constraint then
3982 Error_Msg_N ("expect range constraint for discrete type", N);
3983 Set_Etype (N, Any_Type);
3986 R := Range_Expression (Constraint (N));
3994 if Base_Type (S) /= Base_Type (Typ) then
3996 ("expect subtype of }", N, First_Subtype (Typ));
3998 -- Rewrite the constraint as a range of Typ
3999 -- to allow compilation to proceed further.
4002 Rewrite (Low_Bound (R),
4003 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4004 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4005 Attribute_Name => Name_First));
4006 Rewrite (High_Bound (R),
4007 Make_Attribute_Reference (Sloc (High_Bound (R)),
4008 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4009 Attribute_Name => Name_First));
4013 Set_Etype (N, Etype (R));
4015 -- Additionally, we must check that the bounds are compatible
4016 -- with the given subtype, which might be different from the
4017 -- type of the context.
4019 Apply_Range_Check (R, S);
4021 -- ??? If the above check statically detects a Constraint_Error
4022 -- it replaces the offending bound(s) of the range R with a
4023 -- Constraint_Error node. When the itype which uses these bounds
4024 -- is frozen the resulting call to Duplicate_Subexpr generates
4025 -- a new temporary for the bounds.
4027 -- Unfortunately there are other itypes that are also made depend
4028 -- on these bounds, so when Duplicate_Subexpr is called they get
4029 -- a forward reference to the newly created temporaries and Gigi
4030 -- aborts on such forward references. This is probably sign of a
4031 -- more fundamental problem somewhere else in either the order of
4032 -- itype freezing or the way certain itypes are constructed.
4034 -- To get around this problem we call Remove_Side_Effects right
4035 -- away if either bounds of R are a Constraint_Error.
4038 L : constant Node_Id := Low_Bound (R);
4039 H : constant Node_Id := High_Bound (R);
4042 if Nkind (L) = N_Raise_Constraint_Error then
4043 Remove_Side_Effects (L);
4046 if Nkind (H) = N_Raise_Constraint_Error then
4047 Remove_Side_Effects (H);
4051 Check_Unset_Reference (Low_Bound (R));
4052 Check_Unset_Reference (High_Bound (R));
4055 end Resolve_Discrete_Subtype_Indication;
4057 -------------------------
4058 -- Resolve_Entity_Name --
4059 -------------------------
4061 -- Used to resolve identifiers and expanded names
4063 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4064 E : constant Entity_Id := Entity (N);
4067 -- If garbage from errors, set to Any_Type and return
4069 if No (E) and then Total_Errors_Detected /= 0 then
4070 Set_Etype (N, Any_Type);
4074 -- Replace named numbers by corresponding literals. Note that this is
4075 -- the one case where Resolve_Entity_Name must reset the Etype, since
4076 -- it is currently marked as universal.
4078 if Ekind (E) = E_Named_Integer then
4080 Eval_Named_Integer (N);
4082 elsif Ekind (E) = E_Named_Real then
4084 Eval_Named_Real (N);
4086 -- Allow use of subtype only if it is a concurrent type where we are
4087 -- currently inside the body. This will eventually be expanded
4088 -- into a call to Self (for tasks) or _object (for protected
4089 -- objects). Any other use of a subtype is invalid.
4091 elsif Is_Type (E) then
4092 if Is_Concurrent_Type (E)
4093 and then In_Open_Scopes (E)
4098 ("Invalid use of subtype mark in expression or call", N);
4101 -- Check discriminant use if entity is discriminant in current scope,
4102 -- i.e. discriminant of record or concurrent type currently being
4103 -- analyzed. Uses in corresponding body are unrestricted.
4105 elsif Ekind (E) = E_Discriminant
4106 and then Scope (E) = Current_Scope
4107 and then not Has_Completion (Current_Scope)
4109 Check_Discriminant_Use (N);
4111 -- A parameterless generic function cannot appear in a context that
4112 -- requires resolution.
4114 elsif Ekind (E) = E_Generic_Function then
4115 Error_Msg_N ("illegal use of generic function", N);
4117 elsif Ekind (E) = E_Out_Parameter
4119 and then (Nkind (Parent (N)) in N_Op
4120 or else (Nkind (Parent (N)) = N_Assignment_Statement
4121 and then N = Expression (Parent (N)))
4122 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4124 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
4126 -- In all other cases, just do the possible static evaluation
4129 -- A deferred constant that appears in an expression must have
4130 -- a completion, unless it has been removed by in-place expansion
4133 if Ekind (E) = E_Constant
4134 and then Comes_From_Source (E)
4135 and then No (Constant_Value (E))
4136 and then Is_Frozen (Etype (E))
4137 and then not In_Default_Expression
4138 and then not Is_Imported (E)
4141 if No_Initialization (Parent (E))
4142 or else (Present (Full_View (E))
4143 and then No_Initialization (Parent (Full_View (E))))
4148 "deferred constant is frozen before completion", N);
4152 Eval_Entity_Name (N);
4154 end Resolve_Entity_Name;
4160 procedure Resolve_Entry (Entry_Name : Node_Id) is
4161 Loc : constant Source_Ptr := Sloc (Entry_Name);
4169 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4170 -- If the bounds of the entry family being called depend on task
4171 -- discriminants, build a new index subtype where a discriminant is
4172 -- replaced with the value of the discriminant of the target task.
4173 -- The target task is the prefix of the entry name in the call.
4175 -----------------------
4176 -- Actual_Index_Type --
4177 -----------------------
4179 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4180 Typ : constant Entity_Id := Entry_Index_Type (E);
4181 Tsk : constant Entity_Id := Scope (E);
4182 Lo : constant Node_Id := Type_Low_Bound (Typ);
4183 Hi : constant Node_Id := Type_High_Bound (Typ);
4186 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4187 -- If the bound is given by a discriminant, replace with a reference
4188 -- to the discriminant of the same name in the target task.
4189 -- If the entry name is the target of a requeue statement and the
4190 -- entry is in the current protected object, the bound to be used
4191 -- is the discriminal of the object (see apply_range_checks for
4192 -- details of the transformation).
4194 -----------------------------
4195 -- Actual_Discriminant_Ref --
4196 -----------------------------
4198 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4199 Typ : constant Entity_Id := Etype (Bound);
4203 Remove_Side_Effects (Bound);
4205 if not Is_Entity_Name (Bound)
4206 or else Ekind (Entity (Bound)) /= E_Discriminant
4210 elsif Is_Protected_Type (Tsk)
4211 and then In_Open_Scopes (Tsk)
4212 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4214 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4218 Make_Selected_Component (Loc,
4219 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4220 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4225 end Actual_Discriminant_Ref;
4227 -- Start of processing for Actual_Index_Type
4230 if not Has_Discriminants (Tsk)
4231 or else (not Is_Entity_Name (Lo)
4232 and then not Is_Entity_Name (Hi))
4234 return Entry_Index_Type (E);
4237 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4238 Set_Etype (New_T, Base_Type (Typ));
4239 Set_Size_Info (New_T, Typ);
4240 Set_RM_Size (New_T, RM_Size (Typ));
4241 Set_Scalar_Range (New_T,
4242 Make_Range (Sloc (Entry_Name),
4243 Low_Bound => Actual_Discriminant_Ref (Lo),
4244 High_Bound => Actual_Discriminant_Ref (Hi)));
4248 end Actual_Index_Type;
4250 -- Start of processing of Resolve_Entry
4253 -- Find name of entry being called, and resolve prefix of name
4254 -- with its own type. The prefix can be overloaded, and the name
4255 -- and signature of the entry must be taken into account.
4257 if Nkind (Entry_Name) = N_Indexed_Component then
4259 -- Case of dealing with entry family within the current tasks
4261 E_Name := Prefix (Entry_Name);
4264 E_Name := Entry_Name;
4267 if Is_Entity_Name (E_Name) then
4268 -- Entry call to an entry (or entry family) in the current task.
4269 -- This is legal even though the task will deadlock. Rewrite as
4270 -- call to current task.
4272 -- This can also be a call to an entry in an enclosing task.
4273 -- If this is a single task, we have to retrieve its name,
4274 -- because the scope of the entry is the task type, not the
4275 -- object. If the enclosing task is a task type, the identity
4276 -- of the task is given by its own self variable.
4278 -- Finally this can be a requeue on an entry of the same task
4279 -- or protected object.
4281 S := Scope (Entity (E_Name));
4283 for J in reverse 0 .. Scope_Stack.Last loop
4285 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4286 and then not Comes_From_Source (S)
4288 -- S is an enclosing task or protected object. The concurrent
4289 -- declaration has been converted into a type declaration, and
4290 -- the object itself has an object declaration that follows
4291 -- the type in the same declarative part.
4293 Tsk := Next_Entity (S);
4295 while Etype (Tsk) /= S loop
4302 elsif S = Scope_Stack.Table (J).Entity then
4304 -- Call to current task. Will be transformed into call to Self
4312 Make_Selected_Component (Loc,
4313 Prefix => New_Occurrence_Of (S, Loc),
4315 New_Occurrence_Of (Entity (E_Name), Loc));
4316 Rewrite (E_Name, New_N);
4319 elsif Nkind (Entry_Name) = N_Selected_Component
4320 and then Is_Overloaded (Prefix (Entry_Name))
4322 -- Use the entry name (which must be unique at this point) to
4323 -- find the prefix that returns the corresponding task type or
4327 Pref : constant Node_Id := Prefix (Entry_Name);
4328 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4333 Get_First_Interp (Pref, I, It);
4335 while Present (It.Typ) loop
4337 if Scope (Ent) = It.Typ then
4338 Set_Etype (Pref, It.Typ);
4342 Get_Next_Interp (I, It);
4347 if Nkind (Entry_Name) = N_Selected_Component then
4348 Resolve (Prefix (Entry_Name));
4350 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4351 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4352 Resolve (Prefix (Prefix (Entry_Name)));
4353 Index := First (Expressions (Entry_Name));
4354 Resolve (Index, Entry_Index_Type (Nam));
4356 -- Up to this point the expression could have been the actual
4357 -- in a simple entry call, and be given by a named association.
4359 if Nkind (Index) = N_Parameter_Association then
4360 Error_Msg_N ("expect expression for entry index", Index);
4362 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4367 ------------------------
4368 -- Resolve_Entry_Call --
4369 ------------------------
4371 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4372 Entry_Name : constant Node_Id := Name (N);
4373 Loc : constant Source_Ptr := Sloc (Entry_Name);
4375 First_Named : Node_Id;
4382 -- We kill all checks here, because it does not seem worth the
4383 -- effort to do anything better, an entry call is a big operation.
4387 -- Processing of the name is similar for entry calls and protected
4388 -- operation calls. Once the entity is determined, we can complete
4389 -- the resolution of the actuals.
4391 -- The selector may be overloaded, in the case of a protected object
4392 -- with overloaded functions. The type of the context is used for
4395 if Nkind (Entry_Name) = N_Selected_Component
4396 and then Is_Overloaded (Selector_Name (Entry_Name))
4397 and then Typ /= Standard_Void_Type
4404 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4406 while Present (It.Typ) loop
4408 if Covers (Typ, It.Typ) then
4409 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4410 Set_Etype (Entry_Name, It.Typ);
4412 Generate_Reference (It.Typ, N, ' ');
4415 Get_Next_Interp (I, It);
4420 Resolve_Entry (Entry_Name);
4422 if Nkind (Entry_Name) = N_Selected_Component then
4424 -- Simple entry call.
4426 Nam := Entity (Selector_Name (Entry_Name));
4427 Obj := Prefix (Entry_Name);
4428 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4430 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4432 -- Call to member of entry family.
4434 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4435 Obj := Prefix (Prefix (Entry_Name));
4436 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4439 -- We cannot in general check the maximum depth of protected entry
4440 -- calls at compile time. But we can tell that any protected entry
4441 -- call at all violates a specified nesting depth of zero.
4443 if Is_Protected_Type (Scope (Nam)) then
4444 Check_Restriction (Max_Entry_Queue_Depth, N);
4447 -- Use context type to disambiguate a protected function that can be
4448 -- called without actuals and that returns an array type, and where
4449 -- the argument list may be an indexing of the returned value.
4451 if Ekind (Nam) = E_Function
4452 and then Needs_No_Actuals (Nam)
4453 and then Present (Parameter_Associations (N))
4455 ((Is_Array_Type (Etype (Nam))
4456 and then Covers (Typ, Component_Type (Etype (Nam))))
4458 or else (Is_Access_Type (Etype (Nam))
4459 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4460 and then Covers (Typ,
4461 Component_Type (Designated_Type (Etype (Nam))))))
4464 Index_Node : Node_Id;
4468 Make_Indexed_Component (Loc,
4470 Make_Function_Call (Loc,
4471 Name => Relocate_Node (Entry_Name)),
4472 Expressions => Parameter_Associations (N));
4474 -- Since we are correcting a node classification error made by
4475 -- the parser, we call Replace rather than Rewrite.
4477 Replace (N, Index_Node);
4478 Set_Etype (Prefix (N), Etype (Nam));
4480 Resolve_Indexed_Component (N, Typ);
4485 -- The operation name may have been overloaded. Order the actuals
4486 -- according to the formals of the resolved entity, and set the
4487 -- return type to that of the operation.
4490 Normalize_Actuals (N, Nam, False, Norm_OK);
4491 pragma Assert (Norm_OK);
4492 Set_Etype (N, Etype (Nam));
4495 Resolve_Actuals (N, Nam);
4496 Generate_Reference (Nam, Entry_Name);
4498 if Ekind (Nam) = E_Entry
4499 or else Ekind (Nam) = E_Entry_Family
4501 Check_Potentially_Blocking_Operation (N);
4504 -- Verify that a procedure call cannot masquerade as an entry
4505 -- call where an entry call is expected.
4507 if Ekind (Nam) = E_Procedure then
4508 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4509 and then N = Entry_Call_Statement (Parent (N))
4511 Error_Msg_N ("entry call required in select statement", N);
4513 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4514 and then N = Triggering_Statement (Parent (N))
4516 Error_Msg_N ("triggering statement cannot be procedure call", N);
4518 elsif Ekind (Scope (Nam)) = E_Task_Type
4519 and then not In_Open_Scopes (Scope (Nam))
4521 Error_Msg_N ("Task has no entry with this name", Entry_Name);
4525 -- After resolution, entry calls and protected procedure calls
4526 -- are changed into entry calls, for expansion. The structure
4527 -- of the node does not change, so it can safely be done in place.
4528 -- Protected function calls must keep their structure because they
4529 -- are subexpressions.
4531 if Ekind (Nam) /= E_Function then
4533 -- A protected operation that is not a function may modify the
4534 -- corresponding object, and cannot apply to a constant.
4535 -- If this is an internal call, the prefix is the type itself.
4537 if Is_Protected_Type (Scope (Nam))
4538 and then not Is_Variable (Obj)
4539 and then (not Is_Entity_Name (Obj)
4540 or else not Is_Type (Entity (Obj)))
4543 ("prefix of protected procedure or entry call must be variable",
4547 Actuals := Parameter_Associations (N);
4548 First_Named := First_Named_Actual (N);
4551 Make_Entry_Call_Statement (Loc,
4553 Parameter_Associations => Actuals));
4555 Set_First_Named_Actual (N, First_Named);
4556 Set_Analyzed (N, True);
4558 -- Protected functions can return on the secondary stack, in which
4559 -- case we must trigger the transient scope mechanism
4561 elsif Expander_Active
4562 and then Requires_Transient_Scope (Etype (Nam))
4564 Establish_Transient_Scope (N,
4565 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4567 end Resolve_Entry_Call;
4569 -------------------------
4570 -- Resolve_Equality_Op --
4571 -------------------------
4573 -- Both arguments must have the same type, and the boolean context
4574 -- does not participate in the resolution. The first pass verifies
4575 -- that the interpretation is not ambiguous, and the type of the left
4576 -- argument is correctly set, or is Any_Type in case of ambiguity.
4577 -- If both arguments are strings or aggregates, allocators, or Null,
4578 -- they are ambiguous even though they carry a single (universal) type.
4579 -- Diagnose this case here.
4581 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4582 L : constant Node_Id := Left_Opnd (N);
4583 R : constant Node_Id := Right_Opnd (N);
4584 T : Entity_Id := Find_Unique_Type (L, R);
4586 function Find_Unique_Access_Type return Entity_Id;
4587 -- In the case of allocators, make a last-ditch attempt to find a single
4588 -- access type with the right designated type. This is semantically
4589 -- dubious, and of no interest to any real code, but c48008a makes it
4592 -----------------------------
4593 -- Find_Unique_Access_Type --
4594 -----------------------------
4596 function Find_Unique_Access_Type return Entity_Id is
4599 S : Entity_Id := Current_Scope;
4602 if Ekind (Etype (R)) = E_Allocator_Type then
4603 Acc := Designated_Type (Etype (R));
4605 elsif Ekind (Etype (L)) = E_Allocator_Type then
4606 Acc := Designated_Type (Etype (L));
4612 while S /= Standard_Standard loop
4613 E := First_Entity (S);
4615 while Present (E) loop
4618 and then Is_Access_Type (E)
4619 and then Ekind (E) /= E_Allocator_Type
4620 and then Designated_Type (E) = Base_Type (Acc)
4632 end Find_Unique_Access_Type;
4634 -- Start of processing for Resolve_Equality_Op
4637 Check_Direct_Boolean_Op (N);
4639 Set_Etype (N, Base_Type (Typ));
4640 Generate_Reference (T, N, ' ');
4642 if T = Any_Fixed then
4643 T := Unique_Fixed_Point_Type (L);
4646 if T /= Any_Type then
4649 or else T = Any_Composite
4650 or else T = Any_Character
4653 if T = Any_Character then
4654 Ambiguous_Character (L);
4656 Error_Msg_N ("ambiguous operands for equality", N);
4659 Set_Etype (N, Any_Type);
4662 elsif T = Any_Access
4663 or else Ekind (T) = E_Allocator_Type
4665 T := Find_Unique_Access_Type;
4668 Error_Msg_N ("ambiguous operands for equality", N);
4669 Set_Etype (N, Any_Type);
4674 if Comes_From_Source (N)
4675 and then Has_Unchecked_Union (T)
4678 ("cannot compare Unchecked_Union values", N);
4684 if Warn_On_Redundant_Constructs
4685 and then Comes_From_Source (N)
4686 and then Is_Entity_Name (R)
4687 and then Entity (R) = Standard_True
4688 and then Comes_From_Source (R)
4690 Error_Msg_N ("comparison with True is redundant?", R);
4693 Check_Unset_Reference (L);
4694 Check_Unset_Reference (R);
4695 Generate_Operator_Reference (N, T);
4697 -- If this is an inequality, it may be the implicit inequality
4698 -- created for a user-defined operation, in which case the corres-
4699 -- ponding equality operation is not intrinsic, and the operation
4700 -- cannot be constant-folded. Else fold.
4702 if Nkind (N) = N_Op_Eq
4703 or else Comes_From_Source (Entity (N))
4704 or else Ekind (Entity (N)) = E_Operator
4705 or else Is_Intrinsic_Subprogram
4706 (Corresponding_Equality (Entity (N)))
4708 Eval_Relational_Op (N);
4709 elsif Nkind (N) = N_Op_Ne
4710 and then Is_Abstract (Entity (N))
4712 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4715 end Resolve_Equality_Op;
4717 ----------------------------------
4718 -- Resolve_Explicit_Dereference --
4719 ----------------------------------
4721 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4722 P : constant Node_Id := Prefix (N);
4727 -- Now that we know the type, check that this is not a
4728 -- dereference of an uncompleted type. Note that this
4729 -- is not entirely correct, because dereferences of
4730 -- private types are legal in default expressions.
4731 -- This consideration also applies to similar checks
4732 -- for allocators, qualified expressions, and type
4735 Check_Fully_Declared (Typ, N);
4737 if Is_Overloaded (P) then
4739 -- Use the context type to select the prefix that has the
4740 -- correct designated type.
4742 Get_First_Interp (P, I, It);
4743 while Present (It.Typ) loop
4744 exit when Is_Access_Type (It.Typ)
4745 and then Covers (Typ, Designated_Type (It.Typ));
4747 Get_Next_Interp (I, It);
4750 Resolve (P, It.Typ);
4751 Set_Etype (N, Designated_Type (It.Typ));
4757 if Is_Access_Type (Etype (P)) then
4758 Apply_Access_Check (N);
4761 -- If the designated type is a packed unconstrained array type,
4762 -- and the explicit dereference is not in the context of an
4763 -- attribute reference, then we must compute and set the actual
4764 -- subtype, since it is needed by Gigi. The reason we exclude
4765 -- the attribute case is that this is handled fine by Gigi, and
4766 -- in fact we use such attributes to build the actual subtype.
4767 -- We also exclude generated code (which builds actual subtypes
4768 -- directly if they are needed).
4770 if Is_Array_Type (Etype (N))
4771 and then Is_Packed (Etype (N))
4772 and then not Is_Constrained (Etype (N))
4773 and then Nkind (Parent (N)) /= N_Attribute_Reference
4774 and then Comes_From_Source (N)
4776 Set_Etype (N, Get_Actual_Subtype (N));
4779 -- Note: there is no Eval processing required for an explicit
4780 -- deference, because the type is known to be an allocators, and
4781 -- allocator expressions can never be static.
4783 end Resolve_Explicit_Dereference;
4785 -------------------------------
4786 -- Resolve_Indexed_Component --
4787 -------------------------------
4789 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4790 Name : constant Node_Id := Prefix (N);
4792 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4796 if Is_Overloaded (Name) then
4798 -- Use the context type to select the prefix that yields the
4799 -- correct component type.
4804 I1 : Interp_Index := 0;
4805 P : constant Node_Id := Prefix (N);
4806 Found : Boolean := False;
4809 Get_First_Interp (P, I, It);
4811 while Present (It.Typ) loop
4813 if (Is_Array_Type (It.Typ)
4814 and then Covers (Typ, Component_Type (It.Typ)))
4815 or else (Is_Access_Type (It.Typ)
4816 and then Is_Array_Type (Designated_Type (It.Typ))
4818 (Typ, Component_Type (Designated_Type (It.Typ))))
4821 It := Disambiguate (P, I1, I, Any_Type);
4823 if It = No_Interp then
4824 Error_Msg_N ("ambiguous prefix for indexing", N);
4830 Array_Type := It.Typ;
4836 Array_Type := It.Typ;
4841 Get_Next_Interp (I, It);
4846 Array_Type := Etype (Name);
4849 Resolve (Name, Array_Type);
4850 Array_Type := Get_Actual_Subtype_If_Available (Name);
4852 -- If prefix is access type, dereference to get real array type.
4853 -- Note: we do not apply an access check because the expander always
4854 -- introduces an explicit dereference, and the check will happen there.
4856 if Is_Access_Type (Array_Type) then
4857 Array_Type := Designated_Type (Array_Type);
4860 -- If name was overloaded, set component type correctly now.
4862 Set_Etype (N, Component_Type (Array_Type));
4864 Index := First_Index (Array_Type);
4865 Expr := First (Expressions (N));
4867 -- The prefix may have resolved to a string literal, in which case
4868 -- its etype has a special representation. This is only possible
4869 -- currently if the prefix is a static concatenation, written in
4870 -- functional notation.
4872 if Ekind (Array_Type) = E_String_Literal_Subtype then
4873 Resolve (Expr, Standard_Positive);
4876 while Present (Index) and Present (Expr) loop
4877 Resolve (Expr, Etype (Index));
4878 Check_Unset_Reference (Expr);
4880 if Is_Scalar_Type (Etype (Expr)) then
4881 Apply_Scalar_Range_Check (Expr, Etype (Index));
4883 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
4891 Eval_Indexed_Component (N);
4892 end Resolve_Indexed_Component;
4894 -----------------------------
4895 -- Resolve_Integer_Literal --
4896 -----------------------------
4898 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
4901 Eval_Integer_Literal (N);
4902 end Resolve_Integer_Literal;
4904 ---------------------------------
4905 -- Resolve_Intrinsic_Operator --
4906 ---------------------------------
4908 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
4909 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4917 while Scope (Op) /= Standard_Standard loop
4919 pragma Assert (Present (Op));
4924 -- If the operand type is private, rewrite with suitable
4925 -- conversions on the operands and the result, to expose
4926 -- the proper underlying numeric type.
4928 if Is_Private_Type (Typ) then
4929 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
4931 if Nkind (N) = N_Op_Expon then
4932 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
4934 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
4937 Save_Interps (Left_Opnd (N), Expression (Arg1));
4938 Save_Interps (Right_Opnd (N), Expression (Arg2));
4940 Set_Left_Opnd (N, Arg1);
4941 Set_Right_Opnd (N, Arg2);
4943 Set_Etype (N, Btyp);
4944 Rewrite (N, Unchecked_Convert_To (Typ, N));
4947 elsif Typ /= Etype (Left_Opnd (N))
4948 or else Typ /= Etype (Right_Opnd (N))
4950 -- Add explicit conversion where needed, and save interpretations
4951 -- if operands are overloaded.
4953 Arg1 := Convert_To (Typ, Left_Opnd (N));
4954 Arg2 := Convert_To (Typ, Right_Opnd (N));
4956 if Nkind (Arg1) = N_Type_Conversion then
4957 Save_Interps (Left_Opnd (N), Expression (Arg1));
4960 if Nkind (Arg2) = N_Type_Conversion then
4961 Save_Interps (Right_Opnd (N), Expression (Arg2));
4964 Rewrite (Left_Opnd (N), Arg1);
4965 Rewrite (Right_Opnd (N), Arg2);
4968 Resolve_Arithmetic_Op (N, Typ);
4971 Resolve_Arithmetic_Op (N, Typ);
4973 end Resolve_Intrinsic_Operator;
4975 --------------------------------------
4976 -- Resolve_Intrinsic_Unary_Operator --
4977 --------------------------------------
4979 procedure Resolve_Intrinsic_Unary_Operator
4983 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4990 while Scope (Op) /= Standard_Standard loop
4992 pragma Assert (Present (Op));
4997 if Is_Private_Type (Typ) then
4998 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
4999 Save_Interps (Right_Opnd (N), Expression (Arg2));
5001 Set_Right_Opnd (N, Arg2);
5003 Set_Etype (N, Btyp);
5004 Rewrite (N, Unchecked_Convert_To (Typ, N));
5008 Resolve_Unary_Op (N, Typ);
5010 end Resolve_Intrinsic_Unary_Operator;
5012 ------------------------
5013 -- Resolve_Logical_Op --
5014 ------------------------
5016 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5020 Check_Direct_Boolean_Op (N);
5022 -- Predefined operations on scalar types yield the base type. On
5023 -- the other hand, logical operations on arrays yield the type of
5024 -- the arguments (and the context).
5026 if Is_Array_Type (Typ) then
5029 B_Typ := Base_Type (Typ);
5032 -- The following test is required because the operands of the operation
5033 -- may be literals, in which case the resulting type appears to be
5034 -- compatible with a signed integer type, when in fact it is compatible
5035 -- only with modular types. If the context itself is universal, the
5036 -- operation is illegal.
5038 if not Valid_Boolean_Arg (Typ) then
5039 Error_Msg_N ("invalid context for logical operation", N);
5040 Set_Etype (N, Any_Type);
5043 elsif Typ = Any_Modular then
5045 ("no modular type available in this context", N);
5046 Set_Etype (N, Any_Type);
5048 elsif Is_Modular_Integer_Type (Typ)
5049 and then Etype (Left_Opnd (N)) = Universal_Integer
5050 and then Etype (Right_Opnd (N)) = Universal_Integer
5052 Check_For_Visible_Operator (N, B_Typ);
5055 Resolve (Left_Opnd (N), B_Typ);
5056 Resolve (Right_Opnd (N), B_Typ);
5058 Check_Unset_Reference (Left_Opnd (N));
5059 Check_Unset_Reference (Right_Opnd (N));
5061 Set_Etype (N, B_Typ);
5062 Generate_Operator_Reference (N, B_Typ);
5063 Eval_Logical_Op (N);
5064 end Resolve_Logical_Op;
5066 ---------------------------
5067 -- Resolve_Membership_Op --
5068 ---------------------------
5070 -- The context can only be a boolean type, and does not determine
5071 -- the arguments. Arguments should be unambiguous, but the preference
5072 -- rule for universal types applies.
5074 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5075 pragma Warnings (Off, Typ);
5077 L : constant Node_Id := Left_Opnd (N);
5078 R : constant Node_Id := Right_Opnd (N);
5082 if L = Error or else R = Error then
5086 if not Is_Overloaded (R)
5088 (Etype (R) = Universal_Integer or else
5089 Etype (R) = Universal_Real)
5090 and then Is_Overloaded (L)
5094 T := Intersect_Types (L, R);
5098 Check_Unset_Reference (L);
5100 if Nkind (R) = N_Range
5101 and then not Is_Scalar_Type (T)
5103 Error_Msg_N ("scalar type required for range", R);
5106 if Is_Entity_Name (R) then
5107 Freeze_Expression (R);
5110 Check_Unset_Reference (R);
5113 Eval_Membership_Op (N);
5114 end Resolve_Membership_Op;
5120 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5122 -- For now allow circumvention of the restriction against
5123 -- anonymous null access values via a debug switch to allow
5124 -- for easier transition.
5127 and then Ekind (Typ) = E_Anonymous_Access_Type
5128 and then Comes_From_Source (N)
5130 -- In the common case of a call which uses an explicitly null
5131 -- value for an access parameter, give specialized error msg
5133 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5135 Nkind (Parent (N)) = N_Function_Call
5138 ("null is not allowed as argument for an access parameter", N);
5140 -- Standard message for all other cases (are there any?)
5144 ("null cannot be of an anonymous access type", N);
5148 -- In a distributed context, null for a remote access to subprogram
5149 -- may need to be replaced with a special record aggregate. In this
5150 -- case, return after having done the transformation.
5152 if (Ekind (Typ) = E_Record_Type
5153 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5154 and then Remote_AST_Null_Value (N, Typ)
5159 -- The null literal takes its type from the context.
5164 -----------------------
5165 -- Resolve_Op_Concat --
5166 -----------------------
5168 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5169 Btyp : constant Entity_Id := Base_Type (Typ);
5170 Op1 : constant Node_Id := Left_Opnd (N);
5171 Op2 : constant Node_Id := Right_Opnd (N);
5173 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5174 -- Internal procedure to resolve one operand of concatenation operator.
5175 -- The operand is either of the array type or of the component type.
5176 -- If the operand is an aggregate, and the component type is composite,
5177 -- this is ambiguous if component type has aggregates.
5179 -------------------------------
5180 -- Resolve_Concatenation_Arg --
5181 -------------------------------
5183 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5187 or else (not Is_Overloaded (Arg)
5188 and then Etype (Arg) /= Any_Composite
5189 and then Covers (Component_Type (Typ), Etype (Arg)))
5191 Resolve (Arg, Component_Type (Typ));
5193 Resolve (Arg, Btyp);
5196 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5198 if Nkind (Arg) = N_Aggregate
5199 and then Is_Composite_Type (Component_Type (Typ))
5201 if Is_Private_Type (Component_Type (Typ)) then
5202 Resolve (Arg, Btyp);
5205 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
5206 Set_Etype (Arg, Any_Type);
5210 if Is_Overloaded (Arg)
5211 and then Has_Compatible_Type (Arg, Typ)
5212 and then Etype (Arg) /= Any_Type
5214 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
5221 Get_First_Interp (Arg, I, It);
5223 while Present (It.Nam) loop
5225 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5226 or else Base_Type (Etype (It.Nam)) =
5227 Base_Type (Component_Type (Typ))
5229 Error_Msg_Sloc := Sloc (It.Nam);
5230 Error_Msg_N ("\possible interpretation#", Arg);
5233 Get_Next_Interp (I, It);
5238 Resolve (Arg, Component_Type (Typ));
5240 if Nkind (Arg) = N_String_Literal then
5241 Set_Etype (Arg, Component_Type (Typ));
5244 if Arg = Left_Opnd (N) then
5245 Set_Is_Component_Left_Opnd (N);
5247 Set_Is_Component_Right_Opnd (N);
5252 Resolve (Arg, Btyp);
5255 Check_Unset_Reference (Arg);
5256 end Resolve_Concatenation_Arg;
5258 -- Start of processing for Resolve_Op_Concat
5261 Set_Etype (N, Btyp);
5263 if Is_Limited_Composite (Btyp) then
5264 Error_Msg_N ("concatenation not available for limited array", N);
5265 Explain_Limited_Type (Btyp, N);
5268 -- If the operands are themselves concatenations, resolve them as
5269 -- such directly. This removes several layers of recursion and allows
5270 -- GNAT to handle larger multiple concatenations.
5272 if Nkind (Op1) = N_Op_Concat
5273 and then not Is_Array_Type (Component_Type (Typ))
5274 and then Entity (Op1) = Entity (N)
5276 Resolve_Op_Concat (Op1, Typ);
5278 Resolve_Concatenation_Arg
5279 (Op1, Is_Component_Left_Opnd (N));
5282 if Nkind (Op2) = N_Op_Concat
5283 and then not Is_Array_Type (Component_Type (Typ))
5284 and then Entity (Op2) = Entity (N)
5286 Resolve_Op_Concat (Op2, Typ);
5288 Resolve_Concatenation_Arg
5289 (Op2, Is_Component_Right_Opnd (N));
5292 Generate_Operator_Reference (N, Typ);
5294 if Is_String_Type (Typ) then
5295 Eval_Concatenation (N);
5298 -- If this is not a static concatenation, but the result is a
5299 -- string type (and not an array of strings) insure that static
5300 -- string operands have their subtypes properly constructed.
5302 if Nkind (N) /= N_String_Literal
5303 and then Is_Character_Type (Component_Type (Typ))
5305 Set_String_Literal_Subtype (Op1, Typ);
5306 Set_String_Literal_Subtype (Op2, Typ);
5308 end Resolve_Op_Concat;
5310 ----------------------
5311 -- Resolve_Op_Expon --
5312 ----------------------
5314 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5315 B_Typ : constant Entity_Id := Base_Type (Typ);
5318 -- Catch attempts to do fixed-point exponentation with universal
5319 -- operands, which is a case where the illegality is not caught
5320 -- during normal operator analysis.
5322 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5323 Error_Msg_N ("exponentiation not available for fixed point", N);
5327 if Comes_From_Source (N)
5328 and then Ekind (Entity (N)) = E_Function
5329 and then Is_Imported (Entity (N))
5330 and then Is_Intrinsic_Subprogram (Entity (N))
5332 Resolve_Intrinsic_Operator (N, Typ);
5336 if Etype (Left_Opnd (N)) = Universal_Integer
5337 or else Etype (Left_Opnd (N)) = Universal_Real
5339 Check_For_Visible_Operator (N, B_Typ);
5342 -- We do the resolution using the base type, because intermediate values
5343 -- in expressions always are of the base type, not a subtype of it.
5345 Resolve (Left_Opnd (N), B_Typ);
5346 Resolve (Right_Opnd (N), Standard_Integer);
5348 Check_Unset_Reference (Left_Opnd (N));
5349 Check_Unset_Reference (Right_Opnd (N));
5351 Set_Etype (N, B_Typ);
5352 Generate_Operator_Reference (N, B_Typ);
5355 -- Set overflow checking bit. Much cleverer code needed here eventually
5356 -- and perhaps the Resolve routines should be separated for the various
5357 -- arithmetic operations, since they will need different processing. ???
5359 if Nkind (N) in N_Op then
5360 if not Overflow_Checks_Suppressed (Etype (N)) then
5361 Enable_Overflow_Check (N);
5364 end Resolve_Op_Expon;
5366 --------------------
5367 -- Resolve_Op_Not --
5368 --------------------
5370 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5373 function Parent_Is_Boolean return Boolean;
5374 -- This function determines if the parent node is a boolean operator
5375 -- or operation (comparison op, membership test, or short circuit form)
5376 -- and the not in question is the left operand of this operation.
5377 -- Note that if the not is in parens, then false is returned.
5379 function Parent_Is_Boolean return Boolean is
5381 if Paren_Count (N) /= 0 then
5385 case Nkind (Parent (N)) is
5400 return Left_Opnd (Parent (N)) = N;
5406 end Parent_Is_Boolean;
5408 -- Start of processing for Resolve_Op_Not
5411 -- Predefined operations on scalar types yield the base type. On
5412 -- the other hand, logical operations on arrays yield the type of
5413 -- the arguments (and the context).
5415 if Is_Array_Type (Typ) then
5418 B_Typ := Base_Type (Typ);
5421 if not Valid_Boolean_Arg (Typ) then
5422 Error_Msg_N ("invalid operand type for operator&", N);
5423 Set_Etype (N, Any_Type);
5426 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5427 if Parent_Is_Boolean then
5429 ("operand of not must be enclosed in parentheses",
5433 ("no modular type available in this context", N);
5436 Set_Etype (N, Any_Type);
5440 if not Is_Boolean_Type (Typ)
5441 and then Parent_Is_Boolean
5443 Error_Msg_N ("?not expression should be parenthesized here", N);
5446 Resolve (Right_Opnd (N), B_Typ);
5447 Check_Unset_Reference (Right_Opnd (N));
5448 Set_Etype (N, B_Typ);
5449 Generate_Operator_Reference (N, B_Typ);
5454 -----------------------------
5455 -- Resolve_Operator_Symbol --
5456 -----------------------------
5458 -- Nothing to be done, all resolved already
5460 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5461 pragma Warnings (Off, N);
5462 pragma Warnings (Off, Typ);
5466 end Resolve_Operator_Symbol;
5468 ----------------------------------
5469 -- Resolve_Qualified_Expression --
5470 ----------------------------------
5472 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5473 pragma Warnings (Off, Typ);
5475 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5476 Expr : constant Node_Id := Expression (N);
5479 Resolve (Expr, Target_Typ);
5481 -- A qualified expression requires an exact match of the type,
5482 -- class-wide matching is not allowed.
5484 if Is_Class_Wide_Type (Target_Typ)
5485 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5487 Wrong_Type (Expr, Target_Typ);
5490 -- If the target type is unconstrained, then we reset the type of
5491 -- the result from the type of the expression. For other cases, the
5492 -- actual subtype of the expression is the target type.
5494 if Is_Composite_Type (Target_Typ)
5495 and then not Is_Constrained (Target_Typ)
5497 Set_Etype (N, Etype (Expr));
5500 Eval_Qualified_Expression (N);
5501 end Resolve_Qualified_Expression;
5507 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5508 L : constant Node_Id := Low_Bound (N);
5509 H : constant Node_Id := High_Bound (N);
5516 Check_Unset_Reference (L);
5517 Check_Unset_Reference (H);
5519 -- We have to check the bounds for being within the base range as
5520 -- required for a non-static context. Normally this is automatic
5521 -- and done as part of evaluating expressions, but the N_Range
5522 -- node is an exception, since in GNAT we consider this node to
5523 -- be a subexpression, even though in Ada it is not. The circuit
5524 -- in Sem_Eval could check for this, but that would put the test
5525 -- on the main evaluation path for expressions.
5527 Check_Non_Static_Context (L);
5528 Check_Non_Static_Context (H);
5530 -- If bounds are static, constant-fold them, so size computations
5531 -- are identical between front-end and back-end. Do not perform this
5532 -- transformation while analyzing generic units, as type information
5533 -- would then be lost when reanalyzing the constant node in the
5536 if Is_Discrete_Type (Typ) and then Expander_Active then
5537 if Is_OK_Static_Expression (L) then
5538 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5541 if Is_OK_Static_Expression (H) then
5542 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5547 --------------------------
5548 -- Resolve_Real_Literal --
5549 --------------------------
5551 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5552 Actual_Typ : constant Entity_Id := Etype (N);
5555 -- Special processing for fixed-point literals to make sure that the
5556 -- value is an exact multiple of small where this is required. We
5557 -- skip this for the universal real case, and also for generic types.
5559 if Is_Fixed_Point_Type (Typ)
5560 and then Typ /= Universal_Fixed
5561 and then Typ /= Any_Fixed
5562 and then not Is_Generic_Type (Typ)
5565 Val : constant Ureal := Realval (N);
5566 Cintr : constant Ureal := Val / Small_Value (Typ);
5567 Cint : constant Uint := UR_Trunc (Cintr);
5568 Den : constant Uint := Norm_Den (Cintr);
5572 -- Case of literal is not an exact multiple of the Small
5576 -- For a source program literal for a decimal fixed-point
5577 -- type, this is statically illegal (RM 4.9(36)).
5579 if Is_Decimal_Fixed_Point_Type (Typ)
5580 and then Actual_Typ = Universal_Real
5581 and then Comes_From_Source (N)
5583 Error_Msg_N ("value has extraneous low order digits", N);
5586 -- Replace literal by a value that is the exact representation
5587 -- of a value of the type, i.e. a multiple of the small value,
5588 -- by truncation, since Machine_Rounds is false for all GNAT
5589 -- fixed-point types (RM 4.9(38)).
5591 Stat := Is_Static_Expression (N);
5593 Make_Real_Literal (Sloc (N),
5594 Realval => Small_Value (Typ) * Cint));
5596 Set_Is_Static_Expression (N, Stat);
5599 -- In all cases, set the corresponding integer field
5601 Set_Corresponding_Integer_Value (N, Cint);
5605 -- Now replace the actual type by the expected type as usual
5608 Eval_Real_Literal (N);
5609 end Resolve_Real_Literal;
5611 -----------------------
5612 -- Resolve_Reference --
5613 -----------------------
5615 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5616 P : constant Node_Id := Prefix (N);
5619 -- Replace general access with specific type
5621 if Ekind (Etype (N)) = E_Allocator_Type then
5622 Set_Etype (N, Base_Type (Typ));
5625 Resolve (P, Designated_Type (Etype (N)));
5627 -- If we are taking the reference of a volatile entity, then treat
5628 -- it as a potential modification of this entity. This is much too
5629 -- conservative, but is necessary because remove side effects can
5630 -- result in transformations of normal assignments into reference
5631 -- sequences that otherwise fail to notice the modification.
5633 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5634 Note_Possible_Modification (P);
5636 end Resolve_Reference;
5638 --------------------------------
5639 -- Resolve_Selected_Component --
5640 --------------------------------
5642 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5644 Comp1 : Entity_Id := Empty; -- prevent junk warning
5645 P : constant Node_Id := Prefix (N);
5646 S : constant Node_Id := Selector_Name (N);
5647 T : Entity_Id := Etype (P);
5649 I1 : Interp_Index := 0; -- prevent junk warning
5654 function Init_Component return Boolean;
5655 -- Check whether this is the initialization of a component within an
5656 -- init proc (by assignment or call to another init proc). If true,
5657 -- there is no need for a discriminant check.
5659 --------------------
5660 -- Init_Component --
5661 --------------------
5663 function Init_Component return Boolean is
5665 return Inside_Init_Proc
5666 and then Nkind (Prefix (N)) = N_Identifier
5667 and then Chars (Prefix (N)) = Name_uInit
5668 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5671 -- Start of processing for Resolve_Selected_Component
5674 if Is_Overloaded (P) then
5676 -- Use the context type to select the prefix that has a selector
5677 -- of the correct name and type.
5680 Get_First_Interp (P, I, It);
5682 Search : while Present (It.Typ) loop
5683 if Is_Access_Type (It.Typ) then
5684 T := Designated_Type (It.Typ);
5689 if Is_Record_Type (T) then
5690 Comp := First_Entity (T);
5692 while Present (Comp) loop
5694 if Chars (Comp) = Chars (S)
5695 and then Covers (Etype (Comp), Typ)
5704 It := Disambiguate (P, I1, I, Any_Type);
5706 if It = No_Interp then
5708 ("ambiguous prefix for selected component", N);
5715 if Scope (Comp1) /= It1.Typ then
5717 -- Resolution chooses the new interpretation.
5718 -- Find the component with the right name.
5720 Comp1 := First_Entity (It1.Typ);
5722 while Present (Comp1)
5723 and then Chars (Comp1) /= Chars (S)
5725 Comp1 := Next_Entity (Comp1);
5734 Comp := Next_Entity (Comp);
5739 Get_Next_Interp (I, It);
5742 Resolve (P, It1.Typ);
5744 Set_Entity (S, Comp1);
5747 -- Resolve prefix with its type
5752 -- Deal with access type case
5754 if Is_Access_Type (Etype (P)) then
5755 Apply_Access_Check (N);
5756 T := Designated_Type (Etype (P));
5761 if Has_Discriminants (T)
5762 and then (Ekind (Entity (S)) = E_Component
5764 Ekind (Entity (S)) = E_Discriminant)
5765 and then Present (Original_Record_Component (Entity (S)))
5766 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5767 and then Present (Discriminant_Checking_Func
5768 (Original_Record_Component (Entity (S))))
5769 and then not Discriminant_Checks_Suppressed (T)
5770 and then not Init_Component
5772 Set_Do_Discriminant_Check (N);
5775 if Ekind (Entity (S)) = E_Void then
5776 Error_Msg_N ("premature use of component", S);
5779 -- If the prefix is a record conversion, this may be a renamed
5780 -- discriminant whose bounds differ from those of the original
5781 -- one, so we must ensure that a range check is performed.
5783 if Nkind (P) = N_Type_Conversion
5784 and then Ekind (Entity (S)) = E_Discriminant
5785 and then Is_Discrete_Type (Typ)
5787 Set_Etype (N, Base_Type (Typ));
5790 -- Note: No Eval processing is required, because the prefix is of a
5791 -- record type, or protected type, and neither can possibly be static.
5793 end Resolve_Selected_Component;
5799 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5800 B_Typ : constant Entity_Id := Base_Type (Typ);
5801 L : constant Node_Id := Left_Opnd (N);
5802 R : constant Node_Id := Right_Opnd (N);
5805 -- We do the resolution using the base type, because intermediate values
5806 -- in expressions always are of the base type, not a subtype of it.
5809 Resolve (R, Standard_Natural);
5811 Check_Unset_Reference (L);
5812 Check_Unset_Reference (R);
5814 Set_Etype (N, B_Typ);
5815 Generate_Operator_Reference (N, B_Typ);
5819 ---------------------------
5820 -- Resolve_Short_Circuit --
5821 ---------------------------
5823 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5824 B_Typ : constant Entity_Id := Base_Type (Typ);
5825 L : constant Node_Id := Left_Opnd (N);
5826 R : constant Node_Id := Right_Opnd (N);
5832 Check_Unset_Reference (L);
5833 Check_Unset_Reference (R);
5835 Set_Etype (N, B_Typ);
5836 Eval_Short_Circuit (N);
5837 end Resolve_Short_Circuit;
5843 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
5844 Name : constant Node_Id := Prefix (N);
5845 Drange : constant Node_Id := Discrete_Range (N);
5846 Array_Type : Entity_Id := Empty;
5850 if Is_Overloaded (Name) then
5852 -- Use the context type to select the prefix that yields the
5853 -- correct array type.
5857 I1 : Interp_Index := 0;
5859 P : constant Node_Id := Prefix (N);
5860 Found : Boolean := False;
5863 Get_First_Interp (P, I, It);
5865 while Present (It.Typ) loop
5867 if (Is_Array_Type (It.Typ)
5868 and then Covers (Typ, It.Typ))
5869 or else (Is_Access_Type (It.Typ)
5870 and then Is_Array_Type (Designated_Type (It.Typ))
5871 and then Covers (Typ, Designated_Type (It.Typ)))
5874 It := Disambiguate (P, I1, I, Any_Type);
5876 if It = No_Interp then
5877 Error_Msg_N ("ambiguous prefix for slicing", N);
5882 Array_Type := It.Typ;
5887 Array_Type := It.Typ;
5892 Get_Next_Interp (I, It);
5897 Array_Type := Etype (Name);
5900 Resolve (Name, Array_Type);
5902 if Is_Access_Type (Array_Type) then
5903 Apply_Access_Check (N);
5904 Array_Type := Designated_Type (Array_Type);
5906 elsif Is_Entity_Name (Name)
5907 or else (Nkind (Name) = N_Function_Call
5908 and then not Is_Constrained (Etype (Name)))
5910 Array_Type := Get_Actual_Subtype (Name);
5913 -- If name was overloaded, set slice type correctly now
5915 Set_Etype (N, Array_Type);
5917 -- If the range is specified by a subtype mark, no resolution
5920 if not Is_Entity_Name (Drange) then
5921 Index := First_Index (Array_Type);
5922 Resolve (Drange, Base_Type (Etype (Index)));
5924 if Nkind (Drange) = N_Range then
5925 Apply_Range_Check (Drange, Etype (Index));
5929 Set_Slice_Subtype (N);
5933 ----------------------------
5934 -- Resolve_String_Literal --
5935 ----------------------------
5937 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
5938 C_Typ : constant Entity_Id := Component_Type (Typ);
5939 R_Typ : constant Entity_Id := Root_Type (C_Typ);
5940 Loc : constant Source_Ptr := Sloc (N);
5941 Str : constant String_Id := Strval (N);
5942 Strlen : constant Nat := String_Length (Str);
5943 Subtype_Id : Entity_Id;
5944 Need_Check : Boolean;
5947 -- For a string appearing in a concatenation, defer creation of the
5948 -- string_literal_subtype until the end of the resolution of the
5949 -- concatenation, because the literal may be constant-folded away.
5950 -- This is a useful optimization for long concatenation expressions.
5952 -- If the string is an aggregate built for a single character (which
5953 -- happens in a non-static context) or a is null string to which special
5954 -- checks may apply, we build the subtype. Wide strings must also get
5955 -- a string subtype if they come from a one character aggregate. Strings
5956 -- generated by attributes might be static, but it is often hard to
5957 -- determine whether the enclosing context is static, so we generate
5958 -- subtypes for them as well, thus losing some rarer optimizations ???
5959 -- Same for strings that come from a static conversion.
5962 (Strlen = 0 and then Typ /= Standard_String)
5963 or else Nkind (Parent (N)) /= N_Op_Concat
5964 or else (N /= Left_Opnd (Parent (N))
5965 and then N /= Right_Opnd (Parent (N)))
5966 or else (Typ = Standard_Wide_String
5967 and then Nkind (Original_Node (N)) /= N_String_Literal);
5969 -- If the resolving type is itself a string literal subtype, we
5970 -- can just reuse it, since there is no point in creating another.
5972 if Ekind (Typ) = E_String_Literal_Subtype then
5975 elsif Nkind (Parent (N)) = N_Op_Concat
5976 and then not Need_Check
5977 and then Nkind (Original_Node (N)) /= N_Character_Literal
5978 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
5979 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
5980 and then Nkind (Original_Node (N)) /= N_Type_Conversion
5984 -- Otherwise we must create a string literal subtype. Note that the
5985 -- whole idea of string literal subtypes is simply to avoid the need
5986 -- for building a full fledged array subtype for each literal.
5988 Set_String_Literal_Subtype (N, Typ);
5989 Subtype_Id := Etype (N);
5992 if Nkind (Parent (N)) /= N_Op_Concat
5995 Set_Etype (N, Subtype_Id);
5996 Eval_String_Literal (N);
5999 if Is_Limited_Composite (Typ)
6000 or else Is_Private_Composite (Typ)
6002 Error_Msg_N ("string literal not available for private array", N);
6003 Set_Etype (N, Any_Type);
6007 -- The validity of a null string has been checked in the
6008 -- call to Eval_String_Literal.
6013 -- Always accept string literal with component type Any_Character,
6014 -- which occurs in error situations and in comparisons of literals,
6015 -- both of which should accept all literals.
6017 elsif R_Typ = Any_Character then
6020 -- If the type is bit-packed, then we always tranform the string
6021 -- literal into a full fledged aggregate.
6023 elsif Is_Bit_Packed_Array (Typ) then
6026 -- Deal with cases of Wide_String and String
6029 -- For Standard.Wide_String, or any other type whose component
6030 -- type is Standard.Wide_Character, we know that all the
6031 -- characters in the string must be acceptable, since the parser
6032 -- accepted the characters as valid character literals.
6034 if R_Typ = Standard_Wide_Character then
6037 -- For the case of Standard.String, or any other type whose
6038 -- component type is Standard.Character, we must make sure that
6039 -- there are no wide characters in the string, i.e. that it is
6040 -- entirely composed of characters in range of type String.
6042 -- If the string literal is the result of a static concatenation,
6043 -- the test has already been performed on the components, and need
6046 elsif R_Typ = Standard_Character
6047 and then Nkind (Original_Node (N)) /= N_Op_Concat
6049 for J in 1 .. Strlen loop
6050 if not In_Character_Range (Get_String_Char (Str, J)) then
6052 -- If we are out of range, post error. This is one of the
6053 -- very few places that we place the flag in the middle of
6054 -- a token, right under the offending wide character.
6057 ("literal out of range of type Character",
6058 Source_Ptr (Int (Loc) + J));
6063 -- If the root type is not a standard character, then we will convert
6064 -- the string into an aggregate and will let the aggregate code do
6072 -- See if the component type of the array corresponding to the
6073 -- string has compile time known bounds. If yes we can directly
6074 -- check whether the evaluation of the string will raise constraint
6075 -- error. Otherwise we need to transform the string literal into
6076 -- the corresponding character aggregate and let the aggregate
6077 -- code do the checking.
6079 if R_Typ = Standard_Wide_Character
6080 or else R_Typ = Standard_Character
6082 -- Check for the case of full range, where we are definitely OK
6084 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6088 -- Here the range is not the complete base type range, so check
6091 Comp_Typ_Lo : constant Node_Id :=
6092 Type_Low_Bound (Component_Type (Typ));
6093 Comp_Typ_Hi : constant Node_Id :=
6094 Type_High_Bound (Component_Type (Typ));
6099 if Compile_Time_Known_Value (Comp_Typ_Lo)
6100 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6102 for J in 1 .. Strlen loop
6103 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6105 if Char_Val < Expr_Value (Comp_Typ_Lo)
6106 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6108 Apply_Compile_Time_Constraint_Error
6109 (N, "character out of range?", CE_Range_Check_Failed,
6110 Loc => Source_Ptr (Int (Loc) + J));
6120 -- If we got here we meed to transform the string literal into the
6121 -- equivalent qualified positional array aggregate. This is rather
6122 -- heavy artillery for this situation, but it is hard work to avoid.
6125 Lits : constant List_Id := New_List;
6126 P : Source_Ptr := Loc + 1;
6130 -- Build the character literals, we give them source locations
6131 -- that correspond to the string positions, which is a bit tricky
6132 -- given the possible presence of wide character escape sequences.
6134 for J in 1 .. Strlen loop
6135 C := Get_String_Char (Str, J);
6136 Set_Character_Literal_Name (C);
6139 Make_Character_Literal (P, Name_Find, C));
6141 if In_Character_Range (C) then
6144 -- Should we have a call to Skip_Wide here ???
6152 Make_Qualified_Expression (Loc,
6153 Subtype_Mark => New_Reference_To (Typ, Loc),
6155 Make_Aggregate (Loc, Expressions => Lits)));
6157 Analyze_And_Resolve (N, Typ);
6159 end Resolve_String_Literal;
6161 -----------------------------
6162 -- Resolve_Subprogram_Info --
6163 -----------------------------
6165 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6168 end Resolve_Subprogram_Info;
6170 -----------------------------
6171 -- Resolve_Type_Conversion --
6172 -----------------------------
6174 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6175 Target_Type : constant Entity_Id := Etype (N);
6176 Conv_OK : constant Boolean := Conversion_OK (N);
6178 Opnd_Type : Entity_Id;
6184 Operand := Expression (N);
6187 and then not Valid_Conversion (N, Target_Type, Operand)
6192 if Etype (Operand) = Any_Fixed then
6194 -- Mixed-mode operation involving a literal. Context must be a fixed
6195 -- type which is applied to the literal subsequently.
6197 if Is_Fixed_Point_Type (Typ) then
6198 Set_Etype (Operand, Universal_Real);
6200 elsif Is_Numeric_Type (Typ)
6201 and then (Nkind (Operand) = N_Op_Multiply
6202 or else Nkind (Operand) = N_Op_Divide)
6203 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6204 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6206 if Unique_Fixed_Point_Type (N) = Any_Type then
6207 return; -- expression is ambiguous.
6209 Set_Etype (Operand, Standard_Duration);
6212 if Etype (Right_Opnd (Operand)) = Universal_Real then
6213 Rop := New_Copy_Tree (Right_Opnd (Operand));
6215 Rop := New_Copy_Tree (Left_Opnd (Operand));
6218 Resolve (Rop, Standard_Long_Long_Float);
6220 if Realval (Rop) /= Ureal_0
6221 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6223 Error_Msg_N ("universal real operand can only be interpreted?",
6225 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
6228 elsif Is_Numeric_Type (Typ)
6229 and then Nkind (Operand) in N_Op
6230 and then Unique_Fixed_Point_Type (N) /= Any_Type
6232 Set_Etype (Operand, Standard_Duration);
6235 Error_Msg_N ("invalid context for mixed mode operation", N);
6236 Set_Etype (Operand, Any_Type);
6241 Opnd_Type := Etype (Operand);
6244 -- Note: we do the Eval_Type_Conversion call before applying the
6245 -- required checks for a subtype conversion. This is important,
6246 -- since both are prepared under certain circumstances to change
6247 -- the type conversion to a constraint error node, but in the case
6248 -- of Eval_Type_Conversion this may reflect an illegality in the
6249 -- static case, and we would miss the illegality (getting only a
6250 -- warning message), if we applied the type conversion checks first.
6252 Eval_Type_Conversion (N);
6254 -- If after evaluation, we still have a type conversion, then we
6255 -- may need to apply checks required for a subtype conversion.
6257 -- Skip these type conversion checks if universal fixed operands
6258 -- operands involved, since range checks are handled separately for
6259 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6261 if Nkind (N) = N_Type_Conversion
6262 and then not Is_Generic_Type (Root_Type (Target_Type))
6263 and then Target_Type /= Universal_Fixed
6264 and then Opnd_Type /= Universal_Fixed
6266 Apply_Type_Conversion_Checks (N);
6269 -- Issue warning for conversion of simple object to its own type
6270 -- We have to test the original nodes, since they may have been
6271 -- rewritten by various optimizations.
6273 Orig_N := Original_Node (N);
6275 if Warn_On_Redundant_Constructs
6276 and then Comes_From_Source (Orig_N)
6277 and then Nkind (Orig_N) = N_Type_Conversion
6279 Orig_N := Original_Node (Expression (Orig_N));
6280 Orig_T := Target_Type;
6282 -- If the node is part of a larger expression, the Target_Type
6283 -- may not be the original type of the node if the context is a
6284 -- condition. Recover original type to see if conversion is needed.
6286 if Is_Boolean_Type (Orig_T)
6287 and then Nkind (Parent (N)) in N_Op
6289 Orig_T := Etype (Parent (N));
6292 if Is_Entity_Name (Orig_N)
6293 and then Etype (Entity (Orig_N)) = Orig_T
6296 ("?useless conversion, & has this type", N, Entity (Orig_N));
6299 end Resolve_Type_Conversion;
6301 ----------------------
6302 -- Resolve_Unary_Op --
6303 ----------------------
6305 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6306 B_Typ : constant Entity_Id := Base_Type (Typ);
6307 R : constant Node_Id := Right_Opnd (N);
6313 -- Generate warning for expressions like abs (x mod 2)
6315 if Warn_On_Redundant_Constructs
6316 and then Nkind (N) = N_Op_Abs
6318 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6320 if OK and then Hi >= Lo and then Lo >= 0 then
6322 ("?abs applied to known non-negative value has no effect", N);
6326 -- Generate warning for expressions like -5 mod 3
6328 if Paren_Count (N) = 0
6329 and then Nkind (N) = N_Op_Minus
6330 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6331 and then Comes_From_Source (N)
6334 ("?unary minus expression should be parenthesized here", N);
6337 if Comes_From_Source (N)
6338 and then Ekind (Entity (N)) = E_Function
6339 and then Is_Imported (Entity (N))
6340 and then Is_Intrinsic_Subprogram (Entity (N))
6342 Resolve_Intrinsic_Unary_Operator (N, Typ);
6346 if Etype (R) = Universal_Integer
6347 or else Etype (R) = Universal_Real
6349 Check_For_Visible_Operator (N, B_Typ);
6352 Set_Etype (N, B_Typ);
6355 Check_Unset_Reference (R);
6356 Generate_Operator_Reference (N, B_Typ);
6359 -- Set overflow checking bit. Much cleverer code needed here eventually
6360 -- and perhaps the Resolve routines should be separated for the various
6361 -- arithmetic operations, since they will need different processing ???
6363 if Nkind (N) in N_Op then
6364 if not Overflow_Checks_Suppressed (Etype (N)) then
6365 Enable_Overflow_Check (N);
6368 end Resolve_Unary_Op;
6370 ----------------------------------
6371 -- Resolve_Unchecked_Expression --
6372 ----------------------------------
6374 procedure Resolve_Unchecked_Expression
6379 Resolve (Expression (N), Typ, Suppress => All_Checks);
6381 end Resolve_Unchecked_Expression;
6383 ---------------------------------------
6384 -- Resolve_Unchecked_Type_Conversion --
6385 ---------------------------------------
6387 procedure Resolve_Unchecked_Type_Conversion
6391 pragma Warnings (Off, Typ);
6393 Operand : constant Node_Id := Expression (N);
6394 Opnd_Type : constant Entity_Id := Etype (Operand);
6397 -- Resolve operand using its own type.
6399 Resolve (Operand, Opnd_Type);
6400 Eval_Unchecked_Conversion (N);
6402 end Resolve_Unchecked_Type_Conversion;
6404 ------------------------------
6405 -- Rewrite_Operator_As_Call --
6406 ------------------------------
6408 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6409 Loc : constant Source_Ptr := Sloc (N);
6410 Actuals : constant List_Id := New_List;
6414 if Nkind (N) in N_Binary_Op then
6415 Append (Left_Opnd (N), Actuals);
6418 Append (Right_Opnd (N), Actuals);
6421 Make_Function_Call (Sloc => Loc,
6422 Name => New_Occurrence_Of (Nam, Loc),
6423 Parameter_Associations => Actuals);
6425 Preserve_Comes_From_Source (New_N, N);
6426 Preserve_Comes_From_Source (Name (New_N), N);
6428 Set_Etype (N, Etype (Nam));
6429 end Rewrite_Operator_As_Call;
6431 ------------------------------
6432 -- Rewrite_Renamed_Operator --
6433 ------------------------------
6435 procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id) is
6436 Nam : constant Name_Id := Chars (Op);
6437 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6441 -- Rewrite the operator node using the real operator, not its
6442 -- renaming. Exclude user-defined intrinsic operations, which
6443 -- are treated separately.
6445 if Ekind (Op) /= E_Function then
6446 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6447 Set_Chars (Op_Node, Nam);
6448 Set_Etype (Op_Node, Etype (N));
6449 Set_Entity (Op_Node, Op);
6450 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6452 -- Indicate that both the original entity and its renaming
6453 -- are referenced at this point.
6455 Generate_Reference (Entity (N), N);
6456 Generate_Reference (Op, N);
6459 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6462 Rewrite (N, Op_Node);
6464 end Rewrite_Renamed_Operator;
6466 -----------------------
6467 -- Set_Slice_Subtype --
6468 -----------------------
6470 -- Build an implicit subtype declaration to represent the type delivered
6471 -- by the slice. This is an abbreviated version of an array subtype. We
6472 -- define an index subtype for the slice, using either the subtype name
6473 -- or the discrete range of the slice. To be consistent with index usage
6474 -- elsewhere, we create a list header to hold the single index. This list
6475 -- is not otherwise attached to the syntax tree.
6477 procedure Set_Slice_Subtype (N : Node_Id) is
6478 Loc : constant Source_Ptr := Sloc (N);
6479 Index_List : constant List_Id := New_List;
6481 Index_Subtype : Entity_Id;
6482 Index_Type : Entity_Id;
6483 Slice_Subtype : Entity_Id;
6484 Drange : constant Node_Id := Discrete_Range (N);
6487 if Is_Entity_Name (Drange) then
6488 Index_Subtype := Entity (Drange);
6491 -- We force the evaluation of a range. This is definitely needed in
6492 -- the renamed case, and seems safer to do unconditionally. Note in
6493 -- any case that since we will create and insert an Itype referring
6494 -- to this range, we must make sure any side effect removal actions
6495 -- are inserted before the Itype definition.
6497 if Nkind (Drange) = N_Range then
6498 Force_Evaluation (Low_Bound (Drange));
6499 Force_Evaluation (High_Bound (Drange));
6502 Index_Type := Base_Type (Etype (Drange));
6504 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6506 Set_Scalar_Range (Index_Subtype, Drange);
6507 Set_Etype (Index_Subtype, Index_Type);
6508 Set_Size_Info (Index_Subtype, Index_Type);
6509 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6512 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6514 Index := New_Occurrence_Of (Index_Subtype, Loc);
6515 Set_Etype (Index, Index_Subtype);
6516 Append (Index, Index_List);
6518 Set_First_Index (Slice_Subtype, Index);
6519 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6520 Set_Is_Constrained (Slice_Subtype, True);
6521 Init_Size_Align (Slice_Subtype);
6523 Check_Compile_Time_Size (Slice_Subtype);
6525 -- The Etype of the existing Slice node is reset to this slice
6526 -- subtype. Its bounds are obtained from its first index.
6528 Set_Etype (N, Slice_Subtype);
6530 -- In the packed case, this must be immediately frozen
6532 -- Couldn't we always freeze here??? and if we did, then the above
6533 -- call to Check_Compile_Time_Size could be eliminated, which would
6534 -- be nice, because then that routine could be made private to Freeze.
6536 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6537 Freeze_Itype (Slice_Subtype, N);
6540 end Set_Slice_Subtype;
6542 --------------------------------
6543 -- Set_String_Literal_Subtype --
6544 --------------------------------
6546 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6547 Subtype_Id : Entity_Id;
6550 if Nkind (N) /= N_String_Literal then
6553 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6556 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6557 (String_Length (Strval (N))));
6558 Set_Etype (Subtype_Id, Base_Type (Typ));
6559 Set_Is_Constrained (Subtype_Id);
6561 -- The low bound is set from the low bound of the corresponding
6562 -- index type. Note that we do not store the high bound in the
6563 -- string literal subtype, but it can be deduced if necssary
6564 -- from the length and the low bound.
6566 Set_String_Literal_Low_Bound
6567 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6569 Set_Etype (N, Subtype_Id);
6570 end Set_String_Literal_Subtype;
6572 -----------------------------
6573 -- Unique_Fixed_Point_Type --
6574 -----------------------------
6576 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6577 T1 : Entity_Id := Empty;
6582 procedure Fixed_Point_Error;
6583 -- If true ambiguity, give details.
6585 procedure Fixed_Point_Error is
6587 Error_Msg_N ("ambiguous universal_fixed_expression", N);
6588 Error_Msg_NE ("\possible interpretation as}", N, T1);
6589 Error_Msg_NE ("\possible interpretation as}", N, T2);
6590 end Fixed_Point_Error;
6593 -- The operations on Duration are visible, so Duration is always a
6594 -- possible interpretation.
6596 T1 := Standard_Duration;
6598 -- Look for fixed-point types in enclosing scopes.
6600 Scop := Current_Scope;
6601 while Scop /= Standard_Standard loop
6602 T2 := First_Entity (Scop);
6604 while Present (T2) loop
6605 if Is_Fixed_Point_Type (T2)
6606 and then Current_Entity (T2) = T2
6607 and then Scope (Base_Type (T2)) = Scop
6609 if Present (T1) then
6620 Scop := Scope (Scop);
6623 -- Look for visible fixed type declarations in the context.
6625 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
6627 while Present (Item) loop
6628 if Nkind (Item) = N_With_Clause then
6629 Scop := Entity (Name (Item));
6630 T2 := First_Entity (Scop);
6632 while Present (T2) loop
6633 if Is_Fixed_Point_Type (T2)
6634 and then Scope (Base_Type (T2)) = Scop
6635 and then (Is_Potentially_Use_Visible (T2)
6636 or else In_Use (T2))
6638 if Present (T1) then
6653 if Nkind (N) = N_Real_Literal then
6654 Error_Msg_NE ("real literal interpreted as }?", N, T1);
6657 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
6661 end Unique_Fixed_Point_Type;
6663 ----------------------
6664 -- Valid_Conversion --
6665 ----------------------
6667 function Valid_Conversion
6673 Target_Type : constant Entity_Id := Base_Type (Target);
6674 Opnd_Type : Entity_Id := Etype (Operand);
6676 function Conversion_Check
6680 -- Little routine to post Msg if Valid is False, returns Valid value
6682 function Valid_Tagged_Conversion
6683 (Target_Type : Entity_Id;
6684 Opnd_Type : Entity_Id)
6686 -- Specifically test for validity of tagged conversions
6688 ----------------------
6689 -- Conversion_Check --
6690 ----------------------
6692 function Conversion_Check
6699 Error_Msg_N (Msg, Operand);
6703 end Conversion_Check;
6705 -----------------------------
6706 -- Valid_Tagged_Conversion --
6707 -----------------------------
6709 function Valid_Tagged_Conversion
6710 (Target_Type : Entity_Id;
6711 Opnd_Type : Entity_Id)
6715 -- Upward conversions are allowed (RM 4.6(22)).
6717 if Covers (Target_Type, Opnd_Type)
6718 or else Is_Ancestor (Target_Type, Opnd_Type)
6722 -- Downward conversion are allowed if the operand is
6723 -- is class-wide (RM 4.6(23)).
6725 elsif Is_Class_Wide_Type (Opnd_Type)
6726 and then Covers (Opnd_Type, Target_Type)
6730 elsif Covers (Opnd_Type, Target_Type)
6731 or else Is_Ancestor (Opnd_Type, Target_Type)
6734 Conversion_Check (False,
6735 "downward conversion of tagged objects not allowed");
6738 ("invalid tagged conversion, not compatible with}",
6739 N, First_Subtype (Opnd_Type));
6742 end Valid_Tagged_Conversion;
6744 -- Start of processing for Valid_Conversion
6747 Check_Parameterless_Call (Operand);
6749 if Is_Overloaded (Operand) then
6758 -- Remove procedure calls, which syntactically cannot appear
6759 -- in this context, but which cannot be removed by type checking,
6760 -- because the context does not impose a type.
6762 Get_First_Interp (Operand, I, It);
6764 while Present (It.Typ) loop
6766 if It.Typ = Standard_Void_Type then
6770 Get_Next_Interp (I, It);
6773 Get_First_Interp (Operand, I, It);
6778 Error_Msg_N ("illegal operand in conversion", Operand);
6782 Get_Next_Interp (I, It);
6784 if Present (It.Typ) then
6786 It1 := Disambiguate (Operand, I1, I, Any_Type);
6788 if It1 = No_Interp then
6789 Error_Msg_N ("ambiguous operand in conversion", Operand);
6791 Error_Msg_Sloc := Sloc (It.Nam);
6792 Error_Msg_N ("possible interpretation#!", Operand);
6794 Error_Msg_Sloc := Sloc (N1);
6795 Error_Msg_N ("possible interpretation#!", Operand);
6801 Set_Etype (Operand, It1.Typ);
6802 Opnd_Type := It1.Typ;
6806 if Chars (Current_Scope) = Name_Unchecked_Conversion then
6808 -- This check is dubious, what if there were a user defined
6809 -- scope whose name was Unchecked_Conversion ???
6813 elsif Is_Numeric_Type (Target_Type) then
6814 if Opnd_Type = Universal_Fixed then
6817 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
6818 "illegal operand for numeric conversion");
6821 elsif Is_Array_Type (Target_Type) then
6822 if not Is_Array_Type (Opnd_Type)
6823 or else Opnd_Type = Any_Composite
6824 or else Opnd_Type = Any_String
6827 ("illegal operand for array conversion", Operand);
6830 elsif Number_Dimensions (Target_Type) /=
6831 Number_Dimensions (Opnd_Type)
6834 ("incompatible number of dimensions for conversion", Operand);
6839 Target_Index : Node_Id := First_Index (Target_Type);
6840 Opnd_Index : Node_Id := First_Index (Opnd_Type);
6842 Target_Index_Type : Entity_Id;
6843 Opnd_Index_Type : Entity_Id;
6845 Target_Comp_Type : constant Entity_Id :=
6846 Component_Type (Target_Type);
6847 Opnd_Comp_Type : constant Entity_Id :=
6848 Component_Type (Opnd_Type);
6851 while Present (Target_Index) and then Present (Opnd_Index) loop
6852 Target_Index_Type := Etype (Target_Index);
6853 Opnd_Index_Type := Etype (Opnd_Index);
6855 if not (Is_Integer_Type (Target_Index_Type)
6856 and then Is_Integer_Type (Opnd_Index_Type))
6857 and then (Root_Type (Target_Index_Type)
6858 /= Root_Type (Opnd_Index_Type))
6861 ("incompatible index types for array conversion",
6866 Next_Index (Target_Index);
6867 Next_Index (Opnd_Index);
6870 if Base_Type (Target_Comp_Type) /=
6871 Base_Type (Opnd_Comp_Type)
6874 ("incompatible component types for array conversion",
6879 Is_Constrained (Target_Comp_Type)
6880 /= Is_Constrained (Opnd_Comp_Type)
6881 or else not Subtypes_Statically_Match
6882 (Target_Comp_Type, Opnd_Comp_Type)
6885 ("component subtypes must statically match", Operand);
6894 elsif (Ekind (Target_Type) = E_General_Access_Type
6895 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
6898 (Is_Access_Type (Opnd_Type)
6899 and then Ekind (Opnd_Type) /=
6900 E_Access_Subprogram_Type
6901 and then Ekind (Opnd_Type) /=
6902 E_Access_Protected_Subprogram_Type,
6903 "must be an access-to-object type")
6905 if Is_Access_Constant (Opnd_Type)
6906 and then not Is_Access_Constant (Target_Type)
6909 ("access-to-constant operand type not allowed", Operand);
6913 -- Check the static accessibility rule of 4.6(17). Note that
6914 -- the check is not enforced when within an instance body, since
6915 -- the RM requires such cases to be caught at run time.
6917 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
6918 if Type_Access_Level (Opnd_Type)
6919 > Type_Access_Level (Target_Type)
6921 -- In an instance, this is a run-time check, but one we
6922 -- know will fail, so generate an appropriate warning.
6923 -- The raise will be generated by Expand_N_Type_Conversion.
6925 if In_Instance_Body then
6927 ("?cannot convert local pointer to non-local access type",
6930 ("?Program_Error will be raised at run time", Operand);
6934 ("cannot convert local pointer to non-local access type",
6939 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
6941 -- When the operand is a selected access discriminant
6942 -- the check needs to be made against the level of the
6943 -- object denoted by the prefix of the selected name.
6944 -- (Object_Access_Level handles checking the prefix
6945 -- of the operand for this case.)
6947 if Nkind (Operand) = N_Selected_Component
6948 and then Object_Access_Level (Operand)
6949 > Type_Access_Level (Target_Type)
6951 -- In an instance, this is a run-time check, but one we
6952 -- know will fail, so generate an appropriate warning.
6953 -- The raise will be generated by Expand_N_Type_Conversion.
6955 if In_Instance_Body then
6957 ("?cannot convert access discriminant to non-local" &
6958 " access type", Operand);
6960 ("?Program_Error will be raised at run time", Operand);
6964 ("cannot convert access discriminant to non-local" &
6965 " access type", Operand);
6970 -- The case of a reference to an access discriminant
6971 -- from within a type declaration (which will appear
6972 -- as a discriminal) is always illegal because the
6973 -- level of the discriminant is considered to be
6974 -- deeper than any (namable) access type.
6976 if Is_Entity_Name (Operand)
6977 and then (Ekind (Entity (Operand)) = E_In_Parameter
6978 or else Ekind (Entity (Operand)) = E_Constant)
6979 and then Present (Discriminal_Link (Entity (Operand)))
6982 ("discriminant has deeper accessibility level than target",
6990 Target : constant Entity_Id := Designated_Type (Target_Type);
6991 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
6994 if Is_Tagged_Type (Target) then
6995 return Valid_Tagged_Conversion (Target, Opnd);
6998 if Base_Type (Target) /= Base_Type (Opnd) then
7000 ("target designated type not compatible with }",
7001 N, Base_Type (Opnd));
7004 elsif not Subtypes_Statically_Match (Target, Opnd)
7005 and then (not Has_Discriminants (Target)
7006 or else Is_Constrained (Target))
7009 ("target designated subtype not compatible with }",
7019 elsif Ekind (Target_Type) = E_Access_Subprogram_Type
7020 and then Conversion_Check
7021 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7022 "illegal operand for access subprogram conversion")
7024 -- Check that the designated types are subtype conformant
7026 if not Subtype_Conformant (Designated_Type (Opnd_Type),
7027 Designated_Type (Target_Type))
7030 ("operand type is not subtype conformant with target type",
7034 -- Check the static accessibility rule of 4.6(20)
7036 if Type_Access_Level (Opnd_Type) >
7037 Type_Access_Level (Target_Type)
7040 ("operand type has deeper accessibility level than target",
7043 -- Check that if the operand type is declared in a generic body,
7044 -- then the target type must be declared within that same body
7045 -- (enforces last sentence of 4.6(20)).
7047 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7049 O_Gen : constant Node_Id :=
7050 Enclosing_Generic_Body (Opnd_Type);
7053 Enclosing_Generic_Body (Target_Type);
7056 while Present (T_Gen) and then T_Gen /= O_Gen loop
7057 T_Gen := Enclosing_Generic_Body (T_Gen);
7060 if T_Gen /= O_Gen then
7062 ("target type must be declared in same generic body"
7063 & " as operand type", N);
7070 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7071 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7073 -- It is valid to convert from one RAS type to another provided
7074 -- that their specification statically match.
7076 Check_Subtype_Conformant
7078 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7080 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7085 elsif Is_Tagged_Type (Target_Type) then
7086 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7088 -- Types derived from the same root type are convertible.
7090 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7093 -- In an instance, there may be inconsistent views of the same
7094 -- type, or types derived from the same type.
7097 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7101 -- Special check for common access type error case
7103 elsif Ekind (Target_Type) = E_Access_Type
7104 and then Is_Access_Type (Opnd_Type)
7106 Error_Msg_N ("target type must be general access type!", N);
7107 Error_Msg_NE ("add ALL to }!", N, Target_Type);
7112 Error_Msg_NE ("invalid conversion, not compatible with }",
7117 end Valid_Conversion;