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);
3810 -- If we fall through we definitely have a non-static call
3812 Check_Elab_Call (N);
3815 -------------------------------
3816 -- Resolve_Character_Literal --
3817 -------------------------------
3819 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3820 B_Typ : constant Entity_Id := Base_Type (Typ);
3824 -- Verify that the character does belong to the type of the context
3826 Set_Etype (N, B_Typ);
3827 Eval_Character_Literal (N);
3829 -- Wide_Character literals must always be defined, since the set of
3830 -- wide character literals is complete, i.e. if a character literal
3831 -- is accepted by the parser, then it is OK for wide character.
3833 if Root_Type (B_Typ) = Standard_Wide_Character then
3836 -- Always accept character literal for type Any_Character, which
3837 -- occurs in error situations and in comparisons of literals, both
3838 -- of which should accept all literals.
3840 elsif B_Typ = Any_Character then
3843 -- For Standard.Character or a type derived from it, check that
3844 -- the literal is in range
3846 elsif Root_Type (B_Typ) = Standard_Character then
3847 if In_Character_Range (Char_Literal_Value (N)) then
3851 -- If the entity is already set, this has already been resolved in
3852 -- a generic context, or comes from expansion. Nothing else to do.
3854 elsif Present (Entity (N)) then
3857 -- Otherwise we have a user defined character type, and we can use
3858 -- the standard visibility mechanisms to locate the referenced entity
3861 C := Current_Entity (N);
3863 while Present (C) loop
3864 if Etype (C) = B_Typ then
3865 Set_Entity_With_Style_Check (N, C);
3866 Generate_Reference (C, N);
3874 -- If we fall through, then the literal does not match any of the
3875 -- entries of the enumeration type. This isn't just a constraint
3876 -- error situation, it is an illegality (see RM 4.2).
3879 ("character not defined for }", N, First_Subtype (B_Typ));
3880 end Resolve_Character_Literal;
3882 ---------------------------
3883 -- Resolve_Comparison_Op --
3884 ---------------------------
3886 -- Context requires a boolean type, and plays no role in resolution.
3887 -- Processing identical to that for equality operators. The result
3888 -- type is the base type, which matters when pathological subtypes of
3889 -- booleans with limited ranges are used.
3891 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
3892 L : constant Node_Id := Left_Opnd (N);
3893 R : constant Node_Id := Right_Opnd (N);
3897 Check_Direct_Boolean_Op (N);
3899 -- If this is an intrinsic operation which is not predefined, use
3900 -- the types of its declared arguments to resolve the possibly
3901 -- overloaded operands. Otherwise the operands are unambiguous and
3902 -- specify the expected type.
3904 if Scope (Entity (N)) /= Standard_Standard then
3905 T := Etype (First_Entity (Entity (N)));
3907 T := Find_Unique_Type (L, R);
3909 if T = Any_Fixed then
3910 T := Unique_Fixed_Point_Type (L);
3914 Set_Etype (N, Base_Type (Typ));
3915 Generate_Reference (T, N, ' ');
3917 if T /= Any_Type then
3919 or else T = Any_Composite
3920 or else T = Any_Character
3922 if T = Any_Character then
3923 Ambiguous_Character (L);
3925 Error_Msg_N ("ambiguous operands for comparison", N);
3928 Set_Etype (N, Any_Type);
3932 if Comes_From_Source (N)
3933 and then Has_Unchecked_Union (T)
3936 ("cannot compare Unchecked_Union values", N);
3941 Check_Unset_Reference (L);
3942 Check_Unset_Reference (R);
3943 Generate_Operator_Reference (N, T);
3944 Eval_Relational_Op (N);
3947 end Resolve_Comparison_Op;
3949 ------------------------------------
3950 -- Resolve_Conditional_Expression --
3951 ------------------------------------
3953 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
3954 Condition : constant Node_Id := First (Expressions (N));
3955 Then_Expr : constant Node_Id := Next (Condition);
3956 Else_Expr : constant Node_Id := Next (Then_Expr);
3959 Resolve (Condition, Standard_Boolean);
3960 Resolve (Then_Expr, Typ);
3961 Resolve (Else_Expr, Typ);
3964 Eval_Conditional_Expression (N);
3965 end Resolve_Conditional_Expression;
3967 -----------------------------------------
3968 -- Resolve_Discrete_Subtype_Indication --
3969 -----------------------------------------
3971 procedure Resolve_Discrete_Subtype_Indication
3979 Analyze (Subtype_Mark (N));
3980 S := Entity (Subtype_Mark (N));
3982 if Nkind (Constraint (N)) /= N_Range_Constraint then
3983 Error_Msg_N ("expect range constraint for discrete type", N);
3984 Set_Etype (N, Any_Type);
3987 R := Range_Expression (Constraint (N));
3995 if Base_Type (S) /= Base_Type (Typ) then
3997 ("expect subtype of }", N, First_Subtype (Typ));
3999 -- Rewrite the constraint as a range of Typ
4000 -- to allow compilation to proceed further.
4003 Rewrite (Low_Bound (R),
4004 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4005 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4006 Attribute_Name => Name_First));
4007 Rewrite (High_Bound (R),
4008 Make_Attribute_Reference (Sloc (High_Bound (R)),
4009 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4010 Attribute_Name => Name_First));
4014 Set_Etype (N, Etype (R));
4016 -- Additionally, we must check that the bounds are compatible
4017 -- with the given subtype, which might be different from the
4018 -- type of the context.
4020 Apply_Range_Check (R, S);
4022 -- ??? If the above check statically detects a Constraint_Error
4023 -- it replaces the offending bound(s) of the range R with a
4024 -- Constraint_Error node. When the itype which uses these bounds
4025 -- is frozen the resulting call to Duplicate_Subexpr generates
4026 -- a new temporary for the bounds.
4028 -- Unfortunately there are other itypes that are also made depend
4029 -- on these bounds, so when Duplicate_Subexpr is called they get
4030 -- a forward reference to the newly created temporaries and Gigi
4031 -- aborts on such forward references. This is probably sign of a
4032 -- more fundamental problem somewhere else in either the order of
4033 -- itype freezing or the way certain itypes are constructed.
4035 -- To get around this problem we call Remove_Side_Effects right
4036 -- away if either bounds of R are a Constraint_Error.
4039 L : constant Node_Id := Low_Bound (R);
4040 H : constant Node_Id := High_Bound (R);
4043 if Nkind (L) = N_Raise_Constraint_Error then
4044 Remove_Side_Effects (L);
4047 if Nkind (H) = N_Raise_Constraint_Error then
4048 Remove_Side_Effects (H);
4052 Check_Unset_Reference (Low_Bound (R));
4053 Check_Unset_Reference (High_Bound (R));
4056 end Resolve_Discrete_Subtype_Indication;
4058 -------------------------
4059 -- Resolve_Entity_Name --
4060 -------------------------
4062 -- Used to resolve identifiers and expanded names
4064 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4065 E : constant Entity_Id := Entity (N);
4068 -- If garbage from errors, set to Any_Type and return
4070 if No (E) and then Total_Errors_Detected /= 0 then
4071 Set_Etype (N, Any_Type);
4075 -- Replace named numbers by corresponding literals. Note that this is
4076 -- the one case where Resolve_Entity_Name must reset the Etype, since
4077 -- it is currently marked as universal.
4079 if Ekind (E) = E_Named_Integer then
4081 Eval_Named_Integer (N);
4083 elsif Ekind (E) = E_Named_Real then
4085 Eval_Named_Real (N);
4087 -- Allow use of subtype only if it is a concurrent type where we are
4088 -- currently inside the body. This will eventually be expanded
4089 -- into a call to Self (for tasks) or _object (for protected
4090 -- objects). Any other use of a subtype is invalid.
4092 elsif Is_Type (E) then
4093 if Is_Concurrent_Type (E)
4094 and then In_Open_Scopes (E)
4099 ("Invalid use of subtype mark in expression or call", N);
4102 -- Check discriminant use if entity is discriminant in current scope,
4103 -- i.e. discriminant of record or concurrent type currently being
4104 -- analyzed. Uses in corresponding body are unrestricted.
4106 elsif Ekind (E) = E_Discriminant
4107 and then Scope (E) = Current_Scope
4108 and then not Has_Completion (Current_Scope)
4110 Check_Discriminant_Use (N);
4112 -- A parameterless generic function cannot appear in a context that
4113 -- requires resolution.
4115 elsif Ekind (E) = E_Generic_Function then
4116 Error_Msg_N ("illegal use of generic function", N);
4118 elsif Ekind (E) = E_Out_Parameter
4120 and then (Nkind (Parent (N)) in N_Op
4121 or else (Nkind (Parent (N)) = N_Assignment_Statement
4122 and then N = Expression (Parent (N)))
4123 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4125 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
4127 -- In all other cases, just do the possible static evaluation
4130 -- A deferred constant that appears in an expression must have
4131 -- a completion, unless it has been removed by in-place expansion
4134 if Ekind (E) = E_Constant
4135 and then Comes_From_Source (E)
4136 and then No (Constant_Value (E))
4137 and then Is_Frozen (Etype (E))
4138 and then not In_Default_Expression
4139 and then not Is_Imported (E)
4142 if No_Initialization (Parent (E))
4143 or else (Present (Full_View (E))
4144 and then No_Initialization (Parent (Full_View (E))))
4149 "deferred constant is frozen before completion", N);
4153 Eval_Entity_Name (N);
4155 end Resolve_Entity_Name;
4161 procedure Resolve_Entry (Entry_Name : Node_Id) is
4162 Loc : constant Source_Ptr := Sloc (Entry_Name);
4170 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4171 -- If the bounds of the entry family being called depend on task
4172 -- discriminants, build a new index subtype where a discriminant is
4173 -- replaced with the value of the discriminant of the target task.
4174 -- The target task is the prefix of the entry name in the call.
4176 -----------------------
4177 -- Actual_Index_Type --
4178 -----------------------
4180 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4181 Typ : constant Entity_Id := Entry_Index_Type (E);
4182 Tsk : constant Entity_Id := Scope (E);
4183 Lo : constant Node_Id := Type_Low_Bound (Typ);
4184 Hi : constant Node_Id := Type_High_Bound (Typ);
4187 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4188 -- If the bound is given by a discriminant, replace with a reference
4189 -- to the discriminant of the same name in the target task.
4190 -- If the entry name is the target of a requeue statement and the
4191 -- entry is in the current protected object, the bound to be used
4192 -- is the discriminal of the object (see apply_range_checks for
4193 -- details of the transformation).
4195 -----------------------------
4196 -- Actual_Discriminant_Ref --
4197 -----------------------------
4199 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4200 Typ : constant Entity_Id := Etype (Bound);
4204 Remove_Side_Effects (Bound);
4206 if not Is_Entity_Name (Bound)
4207 or else Ekind (Entity (Bound)) /= E_Discriminant
4211 elsif Is_Protected_Type (Tsk)
4212 and then In_Open_Scopes (Tsk)
4213 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4215 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4219 Make_Selected_Component (Loc,
4220 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4221 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4226 end Actual_Discriminant_Ref;
4228 -- Start of processing for Actual_Index_Type
4231 if not Has_Discriminants (Tsk)
4232 or else (not Is_Entity_Name (Lo)
4233 and then not Is_Entity_Name (Hi))
4235 return Entry_Index_Type (E);
4238 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4239 Set_Etype (New_T, Base_Type (Typ));
4240 Set_Size_Info (New_T, Typ);
4241 Set_RM_Size (New_T, RM_Size (Typ));
4242 Set_Scalar_Range (New_T,
4243 Make_Range (Sloc (Entry_Name),
4244 Low_Bound => Actual_Discriminant_Ref (Lo),
4245 High_Bound => Actual_Discriminant_Ref (Hi)));
4249 end Actual_Index_Type;
4251 -- Start of processing of Resolve_Entry
4254 -- Find name of entry being called, and resolve prefix of name
4255 -- with its own type. The prefix can be overloaded, and the name
4256 -- and signature of the entry must be taken into account.
4258 if Nkind (Entry_Name) = N_Indexed_Component then
4260 -- Case of dealing with entry family within the current tasks
4262 E_Name := Prefix (Entry_Name);
4265 E_Name := Entry_Name;
4268 if Is_Entity_Name (E_Name) then
4269 -- Entry call to an entry (or entry family) in the current task.
4270 -- This is legal even though the task will deadlock. Rewrite as
4271 -- call to current task.
4273 -- This can also be a call to an entry in an enclosing task.
4274 -- If this is a single task, we have to retrieve its name,
4275 -- because the scope of the entry is the task type, not the
4276 -- object. If the enclosing task is a task type, the identity
4277 -- of the task is given by its own self variable.
4279 -- Finally this can be a requeue on an entry of the same task
4280 -- or protected object.
4282 S := Scope (Entity (E_Name));
4284 for J in reverse 0 .. Scope_Stack.Last loop
4286 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4287 and then not Comes_From_Source (S)
4289 -- S is an enclosing task or protected object. The concurrent
4290 -- declaration has been converted into a type declaration, and
4291 -- the object itself has an object declaration that follows
4292 -- the type in the same declarative part.
4294 Tsk := Next_Entity (S);
4296 while Etype (Tsk) /= S loop
4303 elsif S = Scope_Stack.Table (J).Entity then
4305 -- Call to current task. Will be transformed into call to Self
4313 Make_Selected_Component (Loc,
4314 Prefix => New_Occurrence_Of (S, Loc),
4316 New_Occurrence_Of (Entity (E_Name), Loc));
4317 Rewrite (E_Name, New_N);
4320 elsif Nkind (Entry_Name) = N_Selected_Component
4321 and then Is_Overloaded (Prefix (Entry_Name))
4323 -- Use the entry name (which must be unique at this point) to
4324 -- find the prefix that returns the corresponding task type or
4328 Pref : constant Node_Id := Prefix (Entry_Name);
4329 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4334 Get_First_Interp (Pref, I, It);
4336 while Present (It.Typ) loop
4338 if Scope (Ent) = It.Typ then
4339 Set_Etype (Pref, It.Typ);
4343 Get_Next_Interp (I, It);
4348 if Nkind (Entry_Name) = N_Selected_Component then
4349 Resolve (Prefix (Entry_Name));
4351 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4352 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4353 Resolve (Prefix (Prefix (Entry_Name)));
4354 Index := First (Expressions (Entry_Name));
4355 Resolve (Index, Entry_Index_Type (Nam));
4357 -- Up to this point the expression could have been the actual
4358 -- in a simple entry call, and be given by a named association.
4360 if Nkind (Index) = N_Parameter_Association then
4361 Error_Msg_N ("expect expression for entry index", Index);
4363 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4368 ------------------------
4369 -- Resolve_Entry_Call --
4370 ------------------------
4372 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4373 Entry_Name : constant Node_Id := Name (N);
4374 Loc : constant Source_Ptr := Sloc (Entry_Name);
4376 First_Named : Node_Id;
4383 -- We kill all checks here, because it does not seem worth the
4384 -- effort to do anything better, an entry call is a big operation.
4388 -- Processing of the name is similar for entry calls and protected
4389 -- operation calls. Once the entity is determined, we can complete
4390 -- the resolution of the actuals.
4392 -- The selector may be overloaded, in the case of a protected object
4393 -- with overloaded functions. The type of the context is used for
4396 if Nkind (Entry_Name) = N_Selected_Component
4397 and then Is_Overloaded (Selector_Name (Entry_Name))
4398 and then Typ /= Standard_Void_Type
4405 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4407 while Present (It.Typ) loop
4409 if Covers (Typ, It.Typ) then
4410 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4411 Set_Etype (Entry_Name, It.Typ);
4413 Generate_Reference (It.Typ, N, ' ');
4416 Get_Next_Interp (I, It);
4421 Resolve_Entry (Entry_Name);
4423 if Nkind (Entry_Name) = N_Selected_Component then
4425 -- Simple entry call.
4427 Nam := Entity (Selector_Name (Entry_Name));
4428 Obj := Prefix (Entry_Name);
4429 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4431 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4433 -- Call to member of entry family.
4435 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4436 Obj := Prefix (Prefix (Entry_Name));
4437 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4440 -- We cannot in general check the maximum depth of protected entry
4441 -- calls at compile time. But we can tell that any protected entry
4442 -- call at all violates a specified nesting depth of zero.
4444 if Is_Protected_Type (Scope (Nam)) then
4445 Check_Restriction (Max_Entry_Queue_Depth, N);
4448 -- Use context type to disambiguate a protected function that can be
4449 -- called without actuals and that returns an array type, and where
4450 -- the argument list may be an indexing of the returned value.
4452 if Ekind (Nam) = E_Function
4453 and then Needs_No_Actuals (Nam)
4454 and then Present (Parameter_Associations (N))
4456 ((Is_Array_Type (Etype (Nam))
4457 and then Covers (Typ, Component_Type (Etype (Nam))))
4459 or else (Is_Access_Type (Etype (Nam))
4460 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4461 and then Covers (Typ,
4462 Component_Type (Designated_Type (Etype (Nam))))))
4465 Index_Node : Node_Id;
4469 Make_Indexed_Component (Loc,
4471 Make_Function_Call (Loc,
4472 Name => Relocate_Node (Entry_Name)),
4473 Expressions => Parameter_Associations (N));
4475 -- Since we are correcting a node classification error made by
4476 -- the parser, we call Replace rather than Rewrite.
4478 Replace (N, Index_Node);
4479 Set_Etype (Prefix (N), Etype (Nam));
4481 Resolve_Indexed_Component (N, Typ);
4486 -- The operation name may have been overloaded. Order the actuals
4487 -- according to the formals of the resolved entity, and set the
4488 -- return type to that of the operation.
4491 Normalize_Actuals (N, Nam, False, Norm_OK);
4492 pragma Assert (Norm_OK);
4493 Set_Etype (N, Etype (Nam));
4496 Resolve_Actuals (N, Nam);
4497 Generate_Reference (Nam, Entry_Name);
4499 if Ekind (Nam) = E_Entry
4500 or else Ekind (Nam) = E_Entry_Family
4502 Check_Potentially_Blocking_Operation (N);
4505 -- Verify that a procedure call cannot masquerade as an entry
4506 -- call where an entry call is expected.
4508 if Ekind (Nam) = E_Procedure then
4509 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4510 and then N = Entry_Call_Statement (Parent (N))
4512 Error_Msg_N ("entry call required in select statement", N);
4514 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4515 and then N = Triggering_Statement (Parent (N))
4517 Error_Msg_N ("triggering statement cannot be procedure call", N);
4519 elsif Ekind (Scope (Nam)) = E_Task_Type
4520 and then not In_Open_Scopes (Scope (Nam))
4522 Error_Msg_N ("Task has no entry with this name", Entry_Name);
4526 -- After resolution, entry calls and protected procedure calls
4527 -- are changed into entry calls, for expansion. The structure
4528 -- of the node does not change, so it can safely be done in place.
4529 -- Protected function calls must keep their structure because they
4530 -- are subexpressions.
4532 if Ekind (Nam) /= E_Function then
4534 -- A protected operation that is not a function may modify the
4535 -- corresponding object, and cannot apply to a constant.
4536 -- If this is an internal call, the prefix is the type itself.
4538 if Is_Protected_Type (Scope (Nam))
4539 and then not Is_Variable (Obj)
4540 and then (not Is_Entity_Name (Obj)
4541 or else not Is_Type (Entity (Obj)))
4544 ("prefix of protected procedure or entry call must be variable",
4548 Actuals := Parameter_Associations (N);
4549 First_Named := First_Named_Actual (N);
4552 Make_Entry_Call_Statement (Loc,
4554 Parameter_Associations => Actuals));
4556 Set_First_Named_Actual (N, First_Named);
4557 Set_Analyzed (N, True);
4559 -- Protected functions can return on the secondary stack, in which
4560 -- case we must trigger the transient scope mechanism
4562 elsif Expander_Active
4563 and then Requires_Transient_Scope (Etype (Nam))
4565 Establish_Transient_Scope (N,
4566 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4568 end Resolve_Entry_Call;
4570 -------------------------
4571 -- Resolve_Equality_Op --
4572 -------------------------
4574 -- Both arguments must have the same type, and the boolean context
4575 -- does not participate in the resolution. The first pass verifies
4576 -- that the interpretation is not ambiguous, and the type of the left
4577 -- argument is correctly set, or is Any_Type in case of ambiguity.
4578 -- If both arguments are strings or aggregates, allocators, or Null,
4579 -- they are ambiguous even though they carry a single (universal) type.
4580 -- Diagnose this case here.
4582 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4583 L : constant Node_Id := Left_Opnd (N);
4584 R : constant Node_Id := Right_Opnd (N);
4585 T : Entity_Id := Find_Unique_Type (L, R);
4587 function Find_Unique_Access_Type return Entity_Id;
4588 -- In the case of allocators, make a last-ditch attempt to find a single
4589 -- access type with the right designated type. This is semantically
4590 -- dubious, and of no interest to any real code, but c48008a makes it
4593 -----------------------------
4594 -- Find_Unique_Access_Type --
4595 -----------------------------
4597 function Find_Unique_Access_Type return Entity_Id is
4600 S : Entity_Id := Current_Scope;
4603 if Ekind (Etype (R)) = E_Allocator_Type then
4604 Acc := Designated_Type (Etype (R));
4606 elsif Ekind (Etype (L)) = E_Allocator_Type then
4607 Acc := Designated_Type (Etype (L));
4613 while S /= Standard_Standard loop
4614 E := First_Entity (S);
4616 while Present (E) loop
4619 and then Is_Access_Type (E)
4620 and then Ekind (E) /= E_Allocator_Type
4621 and then Designated_Type (E) = Base_Type (Acc)
4633 end Find_Unique_Access_Type;
4635 -- Start of processing for Resolve_Equality_Op
4638 Check_Direct_Boolean_Op (N);
4640 Set_Etype (N, Base_Type (Typ));
4641 Generate_Reference (T, N, ' ');
4643 if T = Any_Fixed then
4644 T := Unique_Fixed_Point_Type (L);
4647 if T /= Any_Type then
4650 or else T = Any_Composite
4651 or else T = Any_Character
4654 if T = Any_Character then
4655 Ambiguous_Character (L);
4657 Error_Msg_N ("ambiguous operands for equality", N);
4660 Set_Etype (N, Any_Type);
4663 elsif T = Any_Access
4664 or else Ekind (T) = E_Allocator_Type
4666 T := Find_Unique_Access_Type;
4669 Error_Msg_N ("ambiguous operands for equality", N);
4670 Set_Etype (N, Any_Type);
4675 if Comes_From_Source (N)
4676 and then Has_Unchecked_Union (T)
4679 ("cannot compare Unchecked_Union values", N);
4685 if Warn_On_Redundant_Constructs
4686 and then Comes_From_Source (N)
4687 and then Is_Entity_Name (R)
4688 and then Entity (R) = Standard_True
4689 and then Comes_From_Source (R)
4691 Error_Msg_N ("comparison with True is redundant?", R);
4694 Check_Unset_Reference (L);
4695 Check_Unset_Reference (R);
4696 Generate_Operator_Reference (N, T);
4698 -- If this is an inequality, it may be the implicit inequality
4699 -- created for a user-defined operation, in which case the corres-
4700 -- ponding equality operation is not intrinsic, and the operation
4701 -- cannot be constant-folded. Else fold.
4703 if Nkind (N) = N_Op_Eq
4704 or else Comes_From_Source (Entity (N))
4705 or else Ekind (Entity (N)) = E_Operator
4706 or else Is_Intrinsic_Subprogram
4707 (Corresponding_Equality (Entity (N)))
4709 Eval_Relational_Op (N);
4710 elsif Nkind (N) = N_Op_Ne
4711 and then Is_Abstract (Entity (N))
4713 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4716 end Resolve_Equality_Op;
4718 ----------------------------------
4719 -- Resolve_Explicit_Dereference --
4720 ----------------------------------
4722 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4723 P : constant Node_Id := Prefix (N);
4728 -- Now that we know the type, check that this is not a
4729 -- dereference of an uncompleted type. Note that this
4730 -- is not entirely correct, because dereferences of
4731 -- private types are legal in default expressions.
4732 -- This consideration also applies to similar checks
4733 -- for allocators, qualified expressions, and type
4736 Check_Fully_Declared (Typ, N);
4738 if Is_Overloaded (P) then
4740 -- Use the context type to select the prefix that has the
4741 -- correct designated type.
4743 Get_First_Interp (P, I, It);
4744 while Present (It.Typ) loop
4745 exit when Is_Access_Type (It.Typ)
4746 and then Covers (Typ, Designated_Type (It.Typ));
4748 Get_Next_Interp (I, It);
4751 Resolve (P, It.Typ);
4752 Set_Etype (N, Designated_Type (It.Typ));
4758 if Is_Access_Type (Etype (P)) then
4759 Apply_Access_Check (N);
4762 -- If the designated type is a packed unconstrained array type,
4763 -- and the explicit dereference is not in the context of an
4764 -- attribute reference, then we must compute and set the actual
4765 -- subtype, since it is needed by Gigi. The reason we exclude
4766 -- the attribute case is that this is handled fine by Gigi, and
4767 -- in fact we use such attributes to build the actual subtype.
4768 -- We also exclude generated code (which builds actual subtypes
4769 -- directly if they are needed).
4771 if Is_Array_Type (Etype (N))
4772 and then Is_Packed (Etype (N))
4773 and then not Is_Constrained (Etype (N))
4774 and then Nkind (Parent (N)) /= N_Attribute_Reference
4775 and then Comes_From_Source (N)
4777 Set_Etype (N, Get_Actual_Subtype (N));
4780 -- Note: there is no Eval processing required for an explicit
4781 -- deference, because the type is known to be an allocators, and
4782 -- allocator expressions can never be static.
4784 end Resolve_Explicit_Dereference;
4786 -------------------------------
4787 -- Resolve_Indexed_Component --
4788 -------------------------------
4790 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4791 Name : constant Node_Id := Prefix (N);
4793 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4797 if Is_Overloaded (Name) then
4799 -- Use the context type to select the prefix that yields the
4800 -- correct component type.
4805 I1 : Interp_Index := 0;
4806 P : constant Node_Id := Prefix (N);
4807 Found : Boolean := False;
4810 Get_First_Interp (P, I, It);
4812 while Present (It.Typ) loop
4814 if (Is_Array_Type (It.Typ)
4815 and then Covers (Typ, Component_Type (It.Typ)))
4816 or else (Is_Access_Type (It.Typ)
4817 and then Is_Array_Type (Designated_Type (It.Typ))
4819 (Typ, Component_Type (Designated_Type (It.Typ))))
4822 It := Disambiguate (P, I1, I, Any_Type);
4824 if It = No_Interp then
4825 Error_Msg_N ("ambiguous prefix for indexing", N);
4831 Array_Type := It.Typ;
4837 Array_Type := It.Typ;
4842 Get_Next_Interp (I, It);
4847 Array_Type := Etype (Name);
4850 Resolve (Name, Array_Type);
4851 Array_Type := Get_Actual_Subtype_If_Available (Name);
4853 -- If prefix is access type, dereference to get real array type.
4854 -- Note: we do not apply an access check because the expander always
4855 -- introduces an explicit dereference, and the check will happen there.
4857 if Is_Access_Type (Array_Type) then
4858 Array_Type := Designated_Type (Array_Type);
4861 -- If name was overloaded, set component type correctly now.
4863 Set_Etype (N, Component_Type (Array_Type));
4865 Index := First_Index (Array_Type);
4866 Expr := First (Expressions (N));
4868 -- The prefix may have resolved to a string literal, in which case
4869 -- its etype has a special representation. This is only possible
4870 -- currently if the prefix is a static concatenation, written in
4871 -- functional notation.
4873 if Ekind (Array_Type) = E_String_Literal_Subtype then
4874 Resolve (Expr, Standard_Positive);
4877 while Present (Index) and Present (Expr) loop
4878 Resolve (Expr, Etype (Index));
4879 Check_Unset_Reference (Expr);
4881 if Is_Scalar_Type (Etype (Expr)) then
4882 Apply_Scalar_Range_Check (Expr, Etype (Index));
4884 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
4892 Eval_Indexed_Component (N);
4893 end Resolve_Indexed_Component;
4895 -----------------------------
4896 -- Resolve_Integer_Literal --
4897 -----------------------------
4899 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
4902 Eval_Integer_Literal (N);
4903 end Resolve_Integer_Literal;
4905 ---------------------------------
4906 -- Resolve_Intrinsic_Operator --
4907 ---------------------------------
4909 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
4910 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4918 while Scope (Op) /= Standard_Standard loop
4920 pragma Assert (Present (Op));
4925 -- If the operand type is private, rewrite with suitable
4926 -- conversions on the operands and the result, to expose
4927 -- the proper underlying numeric type.
4929 if Is_Private_Type (Typ) then
4930 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
4932 if Nkind (N) = N_Op_Expon then
4933 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
4935 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
4938 Save_Interps (Left_Opnd (N), Expression (Arg1));
4939 Save_Interps (Right_Opnd (N), Expression (Arg2));
4941 Set_Left_Opnd (N, Arg1);
4942 Set_Right_Opnd (N, Arg2);
4944 Set_Etype (N, Btyp);
4945 Rewrite (N, Unchecked_Convert_To (Typ, N));
4948 elsif Typ /= Etype (Left_Opnd (N))
4949 or else Typ /= Etype (Right_Opnd (N))
4951 -- Add explicit conversion where needed, and save interpretations
4952 -- if operands are overloaded.
4954 Arg1 := Convert_To (Typ, Left_Opnd (N));
4955 Arg2 := Convert_To (Typ, Right_Opnd (N));
4957 if Nkind (Arg1) = N_Type_Conversion then
4958 Save_Interps (Left_Opnd (N), Expression (Arg1));
4961 if Nkind (Arg2) = N_Type_Conversion then
4962 Save_Interps (Right_Opnd (N), Expression (Arg2));
4965 Rewrite (Left_Opnd (N), Arg1);
4966 Rewrite (Right_Opnd (N), Arg2);
4969 Resolve_Arithmetic_Op (N, Typ);
4972 Resolve_Arithmetic_Op (N, Typ);
4974 end Resolve_Intrinsic_Operator;
4976 --------------------------------------
4977 -- Resolve_Intrinsic_Unary_Operator --
4978 --------------------------------------
4980 procedure Resolve_Intrinsic_Unary_Operator
4984 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4991 while Scope (Op) /= Standard_Standard loop
4993 pragma Assert (Present (Op));
4998 if Is_Private_Type (Typ) then
4999 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5000 Save_Interps (Right_Opnd (N), Expression (Arg2));
5002 Set_Right_Opnd (N, Arg2);
5004 Set_Etype (N, Btyp);
5005 Rewrite (N, Unchecked_Convert_To (Typ, N));
5009 Resolve_Unary_Op (N, Typ);
5011 end Resolve_Intrinsic_Unary_Operator;
5013 ------------------------
5014 -- Resolve_Logical_Op --
5015 ------------------------
5017 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5021 Check_Direct_Boolean_Op (N);
5023 -- Predefined operations on scalar types yield the base type. On
5024 -- the other hand, logical operations on arrays yield the type of
5025 -- the arguments (and the context).
5027 if Is_Array_Type (Typ) then
5030 B_Typ := Base_Type (Typ);
5033 -- The following test is required because the operands of the operation
5034 -- may be literals, in which case the resulting type appears to be
5035 -- compatible with a signed integer type, when in fact it is compatible
5036 -- only with modular types. If the context itself is universal, the
5037 -- operation is illegal.
5039 if not Valid_Boolean_Arg (Typ) then
5040 Error_Msg_N ("invalid context for logical operation", N);
5041 Set_Etype (N, Any_Type);
5044 elsif Typ = Any_Modular then
5046 ("no modular type available in this context", N);
5047 Set_Etype (N, Any_Type);
5049 elsif Is_Modular_Integer_Type (Typ)
5050 and then Etype (Left_Opnd (N)) = Universal_Integer
5051 and then Etype (Right_Opnd (N)) = Universal_Integer
5053 Check_For_Visible_Operator (N, B_Typ);
5056 Resolve (Left_Opnd (N), B_Typ);
5057 Resolve (Right_Opnd (N), B_Typ);
5059 Check_Unset_Reference (Left_Opnd (N));
5060 Check_Unset_Reference (Right_Opnd (N));
5062 Set_Etype (N, B_Typ);
5063 Generate_Operator_Reference (N, B_Typ);
5064 Eval_Logical_Op (N);
5065 end Resolve_Logical_Op;
5067 ---------------------------
5068 -- Resolve_Membership_Op --
5069 ---------------------------
5071 -- The context can only be a boolean type, and does not determine
5072 -- the arguments. Arguments should be unambiguous, but the preference
5073 -- rule for universal types applies.
5075 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5076 pragma Warnings (Off, Typ);
5078 L : constant Node_Id := Left_Opnd (N);
5079 R : constant Node_Id := Right_Opnd (N);
5083 if L = Error or else R = Error then
5087 if not Is_Overloaded (R)
5089 (Etype (R) = Universal_Integer or else
5090 Etype (R) = Universal_Real)
5091 and then Is_Overloaded (L)
5095 T := Intersect_Types (L, R);
5099 Check_Unset_Reference (L);
5101 if Nkind (R) = N_Range
5102 and then not Is_Scalar_Type (T)
5104 Error_Msg_N ("scalar type required for range", R);
5107 if Is_Entity_Name (R) then
5108 Freeze_Expression (R);
5111 Check_Unset_Reference (R);
5114 Eval_Membership_Op (N);
5115 end Resolve_Membership_Op;
5121 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5123 -- For now allow circumvention of the restriction against
5124 -- anonymous null access values via a debug switch to allow
5125 -- for easier transition.
5128 and then Ekind (Typ) = E_Anonymous_Access_Type
5129 and then Comes_From_Source (N)
5131 -- In the common case of a call which uses an explicitly null
5132 -- value for an access parameter, give specialized error msg
5134 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5136 Nkind (Parent (N)) = N_Function_Call
5139 ("null is not allowed as argument for an access parameter", N);
5141 -- Standard message for all other cases (are there any?)
5145 ("null cannot be of an anonymous access type", N);
5149 -- In a distributed context, null for a remote access to subprogram
5150 -- may need to be replaced with a special record aggregate. In this
5151 -- case, return after having done the transformation.
5153 if (Ekind (Typ) = E_Record_Type
5154 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5155 and then Remote_AST_Null_Value (N, Typ)
5160 -- The null literal takes its type from the context.
5165 -----------------------
5166 -- Resolve_Op_Concat --
5167 -----------------------
5169 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5170 Btyp : constant Entity_Id := Base_Type (Typ);
5171 Op1 : constant Node_Id := Left_Opnd (N);
5172 Op2 : constant Node_Id := Right_Opnd (N);
5174 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5175 -- Internal procedure to resolve one operand of concatenation operator.
5176 -- The operand is either of the array type or of the component type.
5177 -- If the operand is an aggregate, and the component type is composite,
5178 -- this is ambiguous if component type has aggregates.
5180 -------------------------------
5181 -- Resolve_Concatenation_Arg --
5182 -------------------------------
5184 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5188 or else (not Is_Overloaded (Arg)
5189 and then Etype (Arg) /= Any_Composite
5190 and then Covers (Component_Type (Typ), Etype (Arg)))
5192 Resolve (Arg, Component_Type (Typ));
5194 Resolve (Arg, Btyp);
5197 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5199 if Nkind (Arg) = N_Aggregate
5200 and then Is_Composite_Type (Component_Type (Typ))
5202 if Is_Private_Type (Component_Type (Typ)) then
5203 Resolve (Arg, Btyp);
5206 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
5207 Set_Etype (Arg, Any_Type);
5211 if Is_Overloaded (Arg)
5212 and then Has_Compatible_Type (Arg, Typ)
5213 and then Etype (Arg) /= Any_Type
5215 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
5222 Get_First_Interp (Arg, I, It);
5224 while Present (It.Nam) loop
5226 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5227 or else Base_Type (Etype (It.Nam)) =
5228 Base_Type (Component_Type (Typ))
5230 Error_Msg_Sloc := Sloc (It.Nam);
5231 Error_Msg_N ("\possible interpretation#", Arg);
5234 Get_Next_Interp (I, It);
5239 Resolve (Arg, Component_Type (Typ));
5241 if Nkind (Arg) = N_String_Literal then
5242 Set_Etype (Arg, Component_Type (Typ));
5245 if Arg = Left_Opnd (N) then
5246 Set_Is_Component_Left_Opnd (N);
5248 Set_Is_Component_Right_Opnd (N);
5253 Resolve (Arg, Btyp);
5256 Check_Unset_Reference (Arg);
5257 end Resolve_Concatenation_Arg;
5259 -- Start of processing for Resolve_Op_Concat
5262 Set_Etype (N, Btyp);
5264 if Is_Limited_Composite (Btyp) then
5265 Error_Msg_N ("concatenation not available for limited array", N);
5266 Explain_Limited_Type (Btyp, N);
5269 -- If the operands are themselves concatenations, resolve them as
5270 -- such directly. This removes several layers of recursion and allows
5271 -- GNAT to handle larger multiple concatenations.
5273 if Nkind (Op1) = N_Op_Concat
5274 and then not Is_Array_Type (Component_Type (Typ))
5275 and then Entity (Op1) = Entity (N)
5277 Resolve_Op_Concat (Op1, Typ);
5279 Resolve_Concatenation_Arg
5280 (Op1, Is_Component_Left_Opnd (N));
5283 if Nkind (Op2) = N_Op_Concat
5284 and then not Is_Array_Type (Component_Type (Typ))
5285 and then Entity (Op2) = Entity (N)
5287 Resolve_Op_Concat (Op2, Typ);
5289 Resolve_Concatenation_Arg
5290 (Op2, Is_Component_Right_Opnd (N));
5293 Generate_Operator_Reference (N, Typ);
5295 if Is_String_Type (Typ) then
5296 Eval_Concatenation (N);
5299 -- If this is not a static concatenation, but the result is a
5300 -- string type (and not an array of strings) insure that static
5301 -- string operands have their subtypes properly constructed.
5303 if Nkind (N) /= N_String_Literal
5304 and then Is_Character_Type (Component_Type (Typ))
5306 Set_String_Literal_Subtype (Op1, Typ);
5307 Set_String_Literal_Subtype (Op2, Typ);
5309 end Resolve_Op_Concat;
5311 ----------------------
5312 -- Resolve_Op_Expon --
5313 ----------------------
5315 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5316 B_Typ : constant Entity_Id := Base_Type (Typ);
5319 -- Catch attempts to do fixed-point exponentation with universal
5320 -- operands, which is a case where the illegality is not caught
5321 -- during normal operator analysis.
5323 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5324 Error_Msg_N ("exponentiation not available for fixed point", N);
5328 if Comes_From_Source (N)
5329 and then Ekind (Entity (N)) = E_Function
5330 and then Is_Imported (Entity (N))
5331 and then Is_Intrinsic_Subprogram (Entity (N))
5333 Resolve_Intrinsic_Operator (N, Typ);
5337 if Etype (Left_Opnd (N)) = Universal_Integer
5338 or else Etype (Left_Opnd (N)) = Universal_Real
5340 Check_For_Visible_Operator (N, B_Typ);
5343 -- We do the resolution using the base type, because intermediate values
5344 -- in expressions always are of the base type, not a subtype of it.
5346 Resolve (Left_Opnd (N), B_Typ);
5347 Resolve (Right_Opnd (N), Standard_Integer);
5349 Check_Unset_Reference (Left_Opnd (N));
5350 Check_Unset_Reference (Right_Opnd (N));
5352 Set_Etype (N, B_Typ);
5353 Generate_Operator_Reference (N, B_Typ);
5356 -- Set overflow checking bit. Much cleverer code needed here eventually
5357 -- and perhaps the Resolve routines should be separated for the various
5358 -- arithmetic operations, since they will need different processing. ???
5360 if Nkind (N) in N_Op then
5361 if not Overflow_Checks_Suppressed (Etype (N)) then
5362 Enable_Overflow_Check (N);
5365 end Resolve_Op_Expon;
5367 --------------------
5368 -- Resolve_Op_Not --
5369 --------------------
5371 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5374 function Parent_Is_Boolean return Boolean;
5375 -- This function determines if the parent node is a boolean operator
5376 -- or operation (comparison op, membership test, or short circuit form)
5377 -- and the not in question is the left operand of this operation.
5378 -- Note that if the not is in parens, then false is returned.
5380 function Parent_Is_Boolean return Boolean is
5382 if Paren_Count (N) /= 0 then
5386 case Nkind (Parent (N)) is
5401 return Left_Opnd (Parent (N)) = N;
5407 end Parent_Is_Boolean;
5409 -- Start of processing for Resolve_Op_Not
5412 -- Predefined operations on scalar types yield the base type. On
5413 -- the other hand, logical operations on arrays yield the type of
5414 -- the arguments (and the context).
5416 if Is_Array_Type (Typ) then
5419 B_Typ := Base_Type (Typ);
5422 if not Valid_Boolean_Arg (Typ) then
5423 Error_Msg_N ("invalid operand type for operator&", N);
5424 Set_Etype (N, Any_Type);
5427 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5428 if Parent_Is_Boolean then
5430 ("operand of not must be enclosed in parentheses",
5434 ("no modular type available in this context", N);
5437 Set_Etype (N, Any_Type);
5441 if not Is_Boolean_Type (Typ)
5442 and then Parent_Is_Boolean
5444 Error_Msg_N ("?not expression should be parenthesized here", N);
5447 Resolve (Right_Opnd (N), B_Typ);
5448 Check_Unset_Reference (Right_Opnd (N));
5449 Set_Etype (N, B_Typ);
5450 Generate_Operator_Reference (N, B_Typ);
5455 -----------------------------
5456 -- Resolve_Operator_Symbol --
5457 -----------------------------
5459 -- Nothing to be done, all resolved already
5461 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5462 pragma Warnings (Off, N);
5463 pragma Warnings (Off, Typ);
5467 end Resolve_Operator_Symbol;
5469 ----------------------------------
5470 -- Resolve_Qualified_Expression --
5471 ----------------------------------
5473 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5474 pragma Warnings (Off, Typ);
5476 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5477 Expr : constant Node_Id := Expression (N);
5480 Resolve (Expr, Target_Typ);
5482 -- A qualified expression requires an exact match of the type,
5483 -- class-wide matching is not allowed.
5485 if Is_Class_Wide_Type (Target_Typ)
5486 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5488 Wrong_Type (Expr, Target_Typ);
5491 -- If the target type is unconstrained, then we reset the type of
5492 -- the result from the type of the expression. For other cases, the
5493 -- actual subtype of the expression is the target type.
5495 if Is_Composite_Type (Target_Typ)
5496 and then not Is_Constrained (Target_Typ)
5498 Set_Etype (N, Etype (Expr));
5501 Eval_Qualified_Expression (N);
5502 end Resolve_Qualified_Expression;
5508 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5509 L : constant Node_Id := Low_Bound (N);
5510 H : constant Node_Id := High_Bound (N);
5517 Check_Unset_Reference (L);
5518 Check_Unset_Reference (H);
5520 -- We have to check the bounds for being within the base range as
5521 -- required for a non-static context. Normally this is automatic
5522 -- and done as part of evaluating expressions, but the N_Range
5523 -- node is an exception, since in GNAT we consider this node to
5524 -- be a subexpression, even though in Ada it is not. The circuit
5525 -- in Sem_Eval could check for this, but that would put the test
5526 -- on the main evaluation path for expressions.
5528 Check_Non_Static_Context (L);
5529 Check_Non_Static_Context (H);
5531 -- If bounds are static, constant-fold them, so size computations
5532 -- are identical between front-end and back-end. Do not perform this
5533 -- transformation while analyzing generic units, as type information
5534 -- would then be lost when reanalyzing the constant node in the
5537 if Is_Discrete_Type (Typ) and then Expander_Active then
5538 if Is_OK_Static_Expression (L) then
5539 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5542 if Is_OK_Static_Expression (H) then
5543 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5548 --------------------------
5549 -- Resolve_Real_Literal --
5550 --------------------------
5552 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5553 Actual_Typ : constant Entity_Id := Etype (N);
5556 -- Special processing for fixed-point literals to make sure that the
5557 -- value is an exact multiple of small where this is required. We
5558 -- skip this for the universal real case, and also for generic types.
5560 if Is_Fixed_Point_Type (Typ)
5561 and then Typ /= Universal_Fixed
5562 and then Typ /= Any_Fixed
5563 and then not Is_Generic_Type (Typ)
5566 Val : constant Ureal := Realval (N);
5567 Cintr : constant Ureal := Val / Small_Value (Typ);
5568 Cint : constant Uint := UR_Trunc (Cintr);
5569 Den : constant Uint := Norm_Den (Cintr);
5573 -- Case of literal is not an exact multiple of the Small
5577 -- For a source program literal for a decimal fixed-point
5578 -- type, this is statically illegal (RM 4.9(36)).
5580 if Is_Decimal_Fixed_Point_Type (Typ)
5581 and then Actual_Typ = Universal_Real
5582 and then Comes_From_Source (N)
5584 Error_Msg_N ("value has extraneous low order digits", N);
5587 -- Replace literal by a value that is the exact representation
5588 -- of a value of the type, i.e. a multiple of the small value,
5589 -- by truncation, since Machine_Rounds is false for all GNAT
5590 -- fixed-point types (RM 4.9(38)).
5592 Stat := Is_Static_Expression (N);
5594 Make_Real_Literal (Sloc (N),
5595 Realval => Small_Value (Typ) * Cint));
5597 Set_Is_Static_Expression (N, Stat);
5600 -- In all cases, set the corresponding integer field
5602 Set_Corresponding_Integer_Value (N, Cint);
5606 -- Now replace the actual type by the expected type as usual
5609 Eval_Real_Literal (N);
5610 end Resolve_Real_Literal;
5612 -----------------------
5613 -- Resolve_Reference --
5614 -----------------------
5616 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5617 P : constant Node_Id := Prefix (N);
5620 -- Replace general access with specific type
5622 if Ekind (Etype (N)) = E_Allocator_Type then
5623 Set_Etype (N, Base_Type (Typ));
5626 Resolve (P, Designated_Type (Etype (N)));
5628 -- If we are taking the reference of a volatile entity, then treat
5629 -- it as a potential modification of this entity. This is much too
5630 -- conservative, but is necessary because remove side effects can
5631 -- result in transformations of normal assignments into reference
5632 -- sequences that otherwise fail to notice the modification.
5634 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5635 Note_Possible_Modification (P);
5637 end Resolve_Reference;
5639 --------------------------------
5640 -- Resolve_Selected_Component --
5641 --------------------------------
5643 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5645 Comp1 : Entity_Id := Empty; -- prevent junk warning
5646 P : constant Node_Id := Prefix (N);
5647 S : constant Node_Id := Selector_Name (N);
5648 T : Entity_Id := Etype (P);
5650 I1 : Interp_Index := 0; -- prevent junk warning
5655 function Init_Component return Boolean;
5656 -- Check whether this is the initialization of a component within an
5657 -- init proc (by assignment or call to another init proc). If true,
5658 -- there is no need for a discriminant check.
5660 --------------------
5661 -- Init_Component --
5662 --------------------
5664 function Init_Component return Boolean is
5666 return Inside_Init_Proc
5667 and then Nkind (Prefix (N)) = N_Identifier
5668 and then Chars (Prefix (N)) = Name_uInit
5669 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5672 -- Start of processing for Resolve_Selected_Component
5675 if Is_Overloaded (P) then
5677 -- Use the context type to select the prefix that has a selector
5678 -- of the correct name and type.
5681 Get_First_Interp (P, I, It);
5683 Search : while Present (It.Typ) loop
5684 if Is_Access_Type (It.Typ) then
5685 T := Designated_Type (It.Typ);
5690 if Is_Record_Type (T) then
5691 Comp := First_Entity (T);
5693 while Present (Comp) loop
5695 if Chars (Comp) = Chars (S)
5696 and then Covers (Etype (Comp), Typ)
5705 It := Disambiguate (P, I1, I, Any_Type);
5707 if It = No_Interp then
5709 ("ambiguous prefix for selected component", N);
5716 if Scope (Comp1) /= It1.Typ then
5718 -- Resolution chooses the new interpretation.
5719 -- Find the component with the right name.
5721 Comp1 := First_Entity (It1.Typ);
5723 while Present (Comp1)
5724 and then Chars (Comp1) /= Chars (S)
5726 Comp1 := Next_Entity (Comp1);
5735 Comp := Next_Entity (Comp);
5740 Get_Next_Interp (I, It);
5743 Resolve (P, It1.Typ);
5745 Set_Entity (S, Comp1);
5748 -- Resolve prefix with its type
5753 -- Deal with access type case
5755 if Is_Access_Type (Etype (P)) then
5756 Apply_Access_Check (N);
5757 T := Designated_Type (Etype (P));
5762 if Has_Discriminants (T)
5763 and then (Ekind (Entity (S)) = E_Component
5765 Ekind (Entity (S)) = E_Discriminant)
5766 and then Present (Original_Record_Component (Entity (S)))
5767 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5768 and then Present (Discriminant_Checking_Func
5769 (Original_Record_Component (Entity (S))))
5770 and then not Discriminant_Checks_Suppressed (T)
5771 and then not Init_Component
5773 Set_Do_Discriminant_Check (N);
5776 if Ekind (Entity (S)) = E_Void then
5777 Error_Msg_N ("premature use of component", S);
5780 -- If the prefix is a record conversion, this may be a renamed
5781 -- discriminant whose bounds differ from those of the original
5782 -- one, so we must ensure that a range check is performed.
5784 if Nkind (P) = N_Type_Conversion
5785 and then Ekind (Entity (S)) = E_Discriminant
5786 and then Is_Discrete_Type (Typ)
5788 Set_Etype (N, Base_Type (Typ));
5791 -- Note: No Eval processing is required, because the prefix is of a
5792 -- record type, or protected type, and neither can possibly be static.
5794 end Resolve_Selected_Component;
5800 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5801 B_Typ : constant Entity_Id := Base_Type (Typ);
5802 L : constant Node_Id := Left_Opnd (N);
5803 R : constant Node_Id := Right_Opnd (N);
5806 -- We do the resolution using the base type, because intermediate values
5807 -- in expressions always are of the base type, not a subtype of it.
5810 Resolve (R, Standard_Natural);
5812 Check_Unset_Reference (L);
5813 Check_Unset_Reference (R);
5815 Set_Etype (N, B_Typ);
5816 Generate_Operator_Reference (N, B_Typ);
5820 ---------------------------
5821 -- Resolve_Short_Circuit --
5822 ---------------------------
5824 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5825 B_Typ : constant Entity_Id := Base_Type (Typ);
5826 L : constant Node_Id := Left_Opnd (N);
5827 R : constant Node_Id := Right_Opnd (N);
5833 Check_Unset_Reference (L);
5834 Check_Unset_Reference (R);
5836 Set_Etype (N, B_Typ);
5837 Eval_Short_Circuit (N);
5838 end Resolve_Short_Circuit;
5844 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
5845 Name : constant Node_Id := Prefix (N);
5846 Drange : constant Node_Id := Discrete_Range (N);
5847 Array_Type : Entity_Id := Empty;
5851 if Is_Overloaded (Name) then
5853 -- Use the context type to select the prefix that yields the
5854 -- correct array type.
5858 I1 : Interp_Index := 0;
5860 P : constant Node_Id := Prefix (N);
5861 Found : Boolean := False;
5864 Get_First_Interp (P, I, It);
5866 while Present (It.Typ) loop
5868 if (Is_Array_Type (It.Typ)
5869 and then Covers (Typ, It.Typ))
5870 or else (Is_Access_Type (It.Typ)
5871 and then Is_Array_Type (Designated_Type (It.Typ))
5872 and then Covers (Typ, Designated_Type (It.Typ)))
5875 It := Disambiguate (P, I1, I, Any_Type);
5877 if It = No_Interp then
5878 Error_Msg_N ("ambiguous prefix for slicing", N);
5883 Array_Type := It.Typ;
5888 Array_Type := It.Typ;
5893 Get_Next_Interp (I, It);
5898 Array_Type := Etype (Name);
5901 Resolve (Name, Array_Type);
5903 if Is_Access_Type (Array_Type) then
5904 Apply_Access_Check (N);
5905 Array_Type := Designated_Type (Array_Type);
5907 elsif Is_Entity_Name (Name)
5908 or else (Nkind (Name) = N_Function_Call
5909 and then not Is_Constrained (Etype (Name)))
5911 Array_Type := Get_Actual_Subtype (Name);
5914 -- If name was overloaded, set slice type correctly now
5916 Set_Etype (N, Array_Type);
5918 -- If the range is specified by a subtype mark, no resolution
5921 if not Is_Entity_Name (Drange) then
5922 Index := First_Index (Array_Type);
5923 Resolve (Drange, Base_Type (Etype (Index)));
5925 if Nkind (Drange) = N_Range then
5926 Apply_Range_Check (Drange, Etype (Index));
5930 Set_Slice_Subtype (N);
5934 ----------------------------
5935 -- Resolve_String_Literal --
5936 ----------------------------
5938 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
5939 C_Typ : constant Entity_Id := Component_Type (Typ);
5940 R_Typ : constant Entity_Id := Root_Type (C_Typ);
5941 Loc : constant Source_Ptr := Sloc (N);
5942 Str : constant String_Id := Strval (N);
5943 Strlen : constant Nat := String_Length (Str);
5944 Subtype_Id : Entity_Id;
5945 Need_Check : Boolean;
5948 -- For a string appearing in a concatenation, defer creation of the
5949 -- string_literal_subtype until the end of the resolution of the
5950 -- concatenation, because the literal may be constant-folded away.
5951 -- This is a useful optimization for long concatenation expressions.
5953 -- If the string is an aggregate built for a single character (which
5954 -- happens in a non-static context) or a is null string to which special
5955 -- checks may apply, we build the subtype. Wide strings must also get
5956 -- a string subtype if they come from a one character aggregate. Strings
5957 -- generated by attributes might be static, but it is often hard to
5958 -- determine whether the enclosing context is static, so we generate
5959 -- subtypes for them as well, thus losing some rarer optimizations ???
5960 -- Same for strings that come from a static conversion.
5963 (Strlen = 0 and then Typ /= Standard_String)
5964 or else Nkind (Parent (N)) /= N_Op_Concat
5965 or else (N /= Left_Opnd (Parent (N))
5966 and then N /= Right_Opnd (Parent (N)))
5967 or else (Typ = Standard_Wide_String
5968 and then Nkind (Original_Node (N)) /= N_String_Literal);
5970 -- If the resolving type is itself a string literal subtype, we
5971 -- can just reuse it, since there is no point in creating another.
5973 if Ekind (Typ) = E_String_Literal_Subtype then
5976 elsif Nkind (Parent (N)) = N_Op_Concat
5977 and then not Need_Check
5978 and then Nkind (Original_Node (N)) /= N_Character_Literal
5979 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
5980 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
5981 and then Nkind (Original_Node (N)) /= N_Type_Conversion
5985 -- Otherwise we must create a string literal subtype. Note that the
5986 -- whole idea of string literal subtypes is simply to avoid the need
5987 -- for building a full fledged array subtype for each literal.
5989 Set_String_Literal_Subtype (N, Typ);
5990 Subtype_Id := Etype (N);
5993 if Nkind (Parent (N)) /= N_Op_Concat
5996 Set_Etype (N, Subtype_Id);
5997 Eval_String_Literal (N);
6000 if Is_Limited_Composite (Typ)
6001 or else Is_Private_Composite (Typ)
6003 Error_Msg_N ("string literal not available for private array", N);
6004 Set_Etype (N, Any_Type);
6008 -- The validity of a null string has been checked in the
6009 -- call to Eval_String_Literal.
6014 -- Always accept string literal with component type Any_Character,
6015 -- which occurs in error situations and in comparisons of literals,
6016 -- both of which should accept all literals.
6018 elsif R_Typ = Any_Character then
6021 -- If the type is bit-packed, then we always tranform the string
6022 -- literal into a full fledged aggregate.
6024 elsif Is_Bit_Packed_Array (Typ) then
6027 -- Deal with cases of Wide_String and String
6030 -- For Standard.Wide_String, or any other type whose component
6031 -- type is Standard.Wide_Character, we know that all the
6032 -- characters in the string must be acceptable, since the parser
6033 -- accepted the characters as valid character literals.
6035 if R_Typ = Standard_Wide_Character then
6038 -- For the case of Standard.String, or any other type whose
6039 -- component type is Standard.Character, we must make sure that
6040 -- there are no wide characters in the string, i.e. that it is
6041 -- entirely composed of characters in range of type String.
6043 -- If the string literal is the result of a static concatenation,
6044 -- the test has already been performed on the components, and need
6047 elsif R_Typ = Standard_Character
6048 and then Nkind (Original_Node (N)) /= N_Op_Concat
6050 for J in 1 .. Strlen loop
6051 if not In_Character_Range (Get_String_Char (Str, J)) then
6053 -- If we are out of range, post error. This is one of the
6054 -- very few places that we place the flag in the middle of
6055 -- a token, right under the offending wide character.
6058 ("literal out of range of type Character",
6059 Source_Ptr (Int (Loc) + J));
6064 -- If the root type is not a standard character, then we will convert
6065 -- the string into an aggregate and will let the aggregate code do
6073 -- See if the component type of the array corresponding to the
6074 -- string has compile time known bounds. If yes we can directly
6075 -- check whether the evaluation of the string will raise constraint
6076 -- error. Otherwise we need to transform the string literal into
6077 -- the corresponding character aggregate and let the aggregate
6078 -- code do the checking.
6080 if R_Typ = Standard_Wide_Character
6081 or else R_Typ = Standard_Character
6083 -- Check for the case of full range, where we are definitely OK
6085 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6089 -- Here the range is not the complete base type range, so check
6092 Comp_Typ_Lo : constant Node_Id :=
6093 Type_Low_Bound (Component_Type (Typ));
6094 Comp_Typ_Hi : constant Node_Id :=
6095 Type_High_Bound (Component_Type (Typ));
6100 if Compile_Time_Known_Value (Comp_Typ_Lo)
6101 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6103 for J in 1 .. Strlen loop
6104 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6106 if Char_Val < Expr_Value (Comp_Typ_Lo)
6107 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6109 Apply_Compile_Time_Constraint_Error
6110 (N, "character out of range?", CE_Range_Check_Failed,
6111 Loc => Source_Ptr (Int (Loc) + J));
6121 -- If we got here we meed to transform the string literal into the
6122 -- equivalent qualified positional array aggregate. This is rather
6123 -- heavy artillery for this situation, but it is hard work to avoid.
6126 Lits : constant List_Id := New_List;
6127 P : Source_Ptr := Loc + 1;
6131 -- Build the character literals, we give them source locations
6132 -- that correspond to the string positions, which is a bit tricky
6133 -- given the possible presence of wide character escape sequences.
6135 for J in 1 .. Strlen loop
6136 C := Get_String_Char (Str, J);
6137 Set_Character_Literal_Name (C);
6140 Make_Character_Literal (P, Name_Find, C));
6142 if In_Character_Range (C) then
6145 -- Should we have a call to Skip_Wide here ???
6153 Make_Qualified_Expression (Loc,
6154 Subtype_Mark => New_Reference_To (Typ, Loc),
6156 Make_Aggregate (Loc, Expressions => Lits)));
6158 Analyze_And_Resolve (N, Typ);
6160 end Resolve_String_Literal;
6162 -----------------------------
6163 -- Resolve_Subprogram_Info --
6164 -----------------------------
6166 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6169 end Resolve_Subprogram_Info;
6171 -----------------------------
6172 -- Resolve_Type_Conversion --
6173 -----------------------------
6175 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6176 Target_Type : constant Entity_Id := Etype (N);
6177 Conv_OK : constant Boolean := Conversion_OK (N);
6179 Opnd_Type : Entity_Id;
6185 Operand := Expression (N);
6188 and then not Valid_Conversion (N, Target_Type, Operand)
6193 if Etype (Operand) = Any_Fixed then
6195 -- Mixed-mode operation involving a literal. Context must be a fixed
6196 -- type which is applied to the literal subsequently.
6198 if Is_Fixed_Point_Type (Typ) then
6199 Set_Etype (Operand, Universal_Real);
6201 elsif Is_Numeric_Type (Typ)
6202 and then (Nkind (Operand) = N_Op_Multiply
6203 or else Nkind (Operand) = N_Op_Divide)
6204 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6205 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6207 if Unique_Fixed_Point_Type (N) = Any_Type then
6208 return; -- expression is ambiguous.
6210 Set_Etype (Operand, Standard_Duration);
6213 if Etype (Right_Opnd (Operand)) = Universal_Real then
6214 Rop := New_Copy_Tree (Right_Opnd (Operand));
6216 Rop := New_Copy_Tree (Left_Opnd (Operand));
6219 Resolve (Rop, Standard_Long_Long_Float);
6221 if Realval (Rop) /= Ureal_0
6222 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6224 Error_Msg_N ("universal real operand can only be interpreted?",
6226 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
6229 elsif Is_Numeric_Type (Typ)
6230 and then Nkind (Operand) in N_Op
6231 and then Unique_Fixed_Point_Type (N) /= Any_Type
6233 Set_Etype (Operand, Standard_Duration);
6236 Error_Msg_N ("invalid context for mixed mode operation", N);
6237 Set_Etype (Operand, Any_Type);
6242 Opnd_Type := Etype (Operand);
6245 -- Note: we do the Eval_Type_Conversion call before applying the
6246 -- required checks for a subtype conversion. This is important,
6247 -- since both are prepared under certain circumstances to change
6248 -- the type conversion to a constraint error node, but in the case
6249 -- of Eval_Type_Conversion this may reflect an illegality in the
6250 -- static case, and we would miss the illegality (getting only a
6251 -- warning message), if we applied the type conversion checks first.
6253 Eval_Type_Conversion (N);
6255 -- If after evaluation, we still have a type conversion, then we
6256 -- may need to apply checks required for a subtype conversion.
6258 -- Skip these type conversion checks if universal fixed operands
6259 -- operands involved, since range checks are handled separately for
6260 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6262 if Nkind (N) = N_Type_Conversion
6263 and then not Is_Generic_Type (Root_Type (Target_Type))
6264 and then Target_Type /= Universal_Fixed
6265 and then Opnd_Type /= Universal_Fixed
6267 Apply_Type_Conversion_Checks (N);
6270 -- Issue warning for conversion of simple object to its own type
6271 -- We have to test the original nodes, since they may have been
6272 -- rewritten by various optimizations.
6274 Orig_N := Original_Node (N);
6276 if Warn_On_Redundant_Constructs
6277 and then Comes_From_Source (Orig_N)
6278 and then Nkind (Orig_N) = N_Type_Conversion
6280 Orig_N := Original_Node (Expression (Orig_N));
6281 Orig_T := Target_Type;
6283 -- If the node is part of a larger expression, the Target_Type
6284 -- may not be the original type of the node if the context is a
6285 -- condition. Recover original type to see if conversion is needed.
6287 if Is_Boolean_Type (Orig_T)
6288 and then Nkind (Parent (N)) in N_Op
6290 Orig_T := Etype (Parent (N));
6293 if Is_Entity_Name (Orig_N)
6294 and then Etype (Entity (Orig_N)) = Orig_T
6297 ("?useless conversion, & has this type", N, Entity (Orig_N));
6300 end Resolve_Type_Conversion;
6302 ----------------------
6303 -- Resolve_Unary_Op --
6304 ----------------------
6306 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6307 B_Typ : constant Entity_Id := Base_Type (Typ);
6308 R : constant Node_Id := Right_Opnd (N);
6314 -- Generate warning for expressions like abs (x mod 2)
6316 if Warn_On_Redundant_Constructs
6317 and then Nkind (N) = N_Op_Abs
6319 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6321 if OK and then Hi >= Lo and then Lo >= 0 then
6323 ("?abs applied to known non-negative value has no effect", N);
6327 -- Generate warning for expressions like -5 mod 3
6329 if Paren_Count (N) = 0
6330 and then Nkind (N) = N_Op_Minus
6331 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6332 and then Comes_From_Source (N)
6335 ("?unary minus expression should be parenthesized here", N);
6338 if Comes_From_Source (N)
6339 and then Ekind (Entity (N)) = E_Function
6340 and then Is_Imported (Entity (N))
6341 and then Is_Intrinsic_Subprogram (Entity (N))
6343 Resolve_Intrinsic_Unary_Operator (N, Typ);
6347 if Etype (R) = Universal_Integer
6348 or else Etype (R) = Universal_Real
6350 Check_For_Visible_Operator (N, B_Typ);
6353 Set_Etype (N, B_Typ);
6356 Check_Unset_Reference (R);
6357 Generate_Operator_Reference (N, B_Typ);
6360 -- Set overflow checking bit. Much cleverer code needed here eventually
6361 -- and perhaps the Resolve routines should be separated for the various
6362 -- arithmetic operations, since they will need different processing ???
6364 if Nkind (N) in N_Op then
6365 if not Overflow_Checks_Suppressed (Etype (N)) then
6366 Enable_Overflow_Check (N);
6369 end Resolve_Unary_Op;
6371 ----------------------------------
6372 -- Resolve_Unchecked_Expression --
6373 ----------------------------------
6375 procedure Resolve_Unchecked_Expression
6380 Resolve (Expression (N), Typ, Suppress => All_Checks);
6382 end Resolve_Unchecked_Expression;
6384 ---------------------------------------
6385 -- Resolve_Unchecked_Type_Conversion --
6386 ---------------------------------------
6388 procedure Resolve_Unchecked_Type_Conversion
6392 pragma Warnings (Off, Typ);
6394 Operand : constant Node_Id := Expression (N);
6395 Opnd_Type : constant Entity_Id := Etype (Operand);
6398 -- Resolve operand using its own type.
6400 Resolve (Operand, Opnd_Type);
6401 Eval_Unchecked_Conversion (N);
6403 end Resolve_Unchecked_Type_Conversion;
6405 ------------------------------
6406 -- Rewrite_Operator_As_Call --
6407 ------------------------------
6409 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6410 Loc : constant Source_Ptr := Sloc (N);
6411 Actuals : constant List_Id := New_List;
6415 if Nkind (N) in N_Binary_Op then
6416 Append (Left_Opnd (N), Actuals);
6419 Append (Right_Opnd (N), Actuals);
6422 Make_Function_Call (Sloc => Loc,
6423 Name => New_Occurrence_Of (Nam, Loc),
6424 Parameter_Associations => Actuals);
6426 Preserve_Comes_From_Source (New_N, N);
6427 Preserve_Comes_From_Source (Name (New_N), N);
6429 Set_Etype (N, Etype (Nam));
6430 end Rewrite_Operator_As_Call;
6432 ------------------------------
6433 -- Rewrite_Renamed_Operator --
6434 ------------------------------
6436 procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id) is
6437 Nam : constant Name_Id := Chars (Op);
6438 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6442 -- Rewrite the operator node using the real operator, not its
6443 -- renaming. Exclude user-defined intrinsic operations, which
6444 -- are treated separately.
6446 if Ekind (Op) /= E_Function then
6447 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6448 Set_Chars (Op_Node, Nam);
6449 Set_Etype (Op_Node, Etype (N));
6450 Set_Entity (Op_Node, Op);
6451 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6453 -- Indicate that both the original entity and its renaming
6454 -- are referenced at this point.
6456 Generate_Reference (Entity (N), N);
6457 Generate_Reference (Op, N);
6460 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6463 Rewrite (N, Op_Node);
6465 end Rewrite_Renamed_Operator;
6467 -----------------------
6468 -- Set_Slice_Subtype --
6469 -----------------------
6471 -- Build an implicit subtype declaration to represent the type delivered
6472 -- by the slice. This is an abbreviated version of an array subtype. We
6473 -- define an index subtype for the slice, using either the subtype name
6474 -- or the discrete range of the slice. To be consistent with index usage
6475 -- elsewhere, we create a list header to hold the single index. This list
6476 -- is not otherwise attached to the syntax tree.
6478 procedure Set_Slice_Subtype (N : Node_Id) is
6479 Loc : constant Source_Ptr := Sloc (N);
6480 Index_List : constant List_Id := New_List;
6482 Index_Subtype : Entity_Id;
6483 Index_Type : Entity_Id;
6484 Slice_Subtype : Entity_Id;
6485 Drange : constant Node_Id := Discrete_Range (N);
6488 if Is_Entity_Name (Drange) then
6489 Index_Subtype := Entity (Drange);
6492 -- We force the evaluation of a range. This is definitely needed in
6493 -- the renamed case, and seems safer to do unconditionally. Note in
6494 -- any case that since we will create and insert an Itype referring
6495 -- to this range, we must make sure any side effect removal actions
6496 -- are inserted before the Itype definition.
6498 if Nkind (Drange) = N_Range then
6499 Force_Evaluation (Low_Bound (Drange));
6500 Force_Evaluation (High_Bound (Drange));
6503 Index_Type := Base_Type (Etype (Drange));
6505 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6507 Set_Scalar_Range (Index_Subtype, Drange);
6508 Set_Etype (Index_Subtype, Index_Type);
6509 Set_Size_Info (Index_Subtype, Index_Type);
6510 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6513 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6515 Index := New_Occurrence_Of (Index_Subtype, Loc);
6516 Set_Etype (Index, Index_Subtype);
6517 Append (Index, Index_List);
6519 Set_First_Index (Slice_Subtype, Index);
6520 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6521 Set_Is_Constrained (Slice_Subtype, True);
6522 Init_Size_Align (Slice_Subtype);
6524 Check_Compile_Time_Size (Slice_Subtype);
6526 -- The Etype of the existing Slice node is reset to this slice
6527 -- subtype. Its bounds are obtained from its first index.
6529 Set_Etype (N, Slice_Subtype);
6531 -- In the packed case, this must be immediately frozen
6533 -- Couldn't we always freeze here??? and if we did, then the above
6534 -- call to Check_Compile_Time_Size could be eliminated, which would
6535 -- be nice, because then that routine could be made private to Freeze.
6537 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6538 Freeze_Itype (Slice_Subtype, N);
6541 end Set_Slice_Subtype;
6543 --------------------------------
6544 -- Set_String_Literal_Subtype --
6545 --------------------------------
6547 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6548 Subtype_Id : Entity_Id;
6551 if Nkind (N) /= N_String_Literal then
6554 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6557 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6558 (String_Length (Strval (N))));
6559 Set_Etype (Subtype_Id, Base_Type (Typ));
6560 Set_Is_Constrained (Subtype_Id);
6562 -- The low bound is set from the low bound of the corresponding
6563 -- index type. Note that we do not store the high bound in the
6564 -- string literal subtype, but it can be deduced if necssary
6565 -- from the length and the low bound.
6567 Set_String_Literal_Low_Bound
6568 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6570 Set_Etype (N, Subtype_Id);
6571 end Set_String_Literal_Subtype;
6573 -----------------------------
6574 -- Unique_Fixed_Point_Type --
6575 -----------------------------
6577 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6578 T1 : Entity_Id := Empty;
6583 procedure Fixed_Point_Error;
6584 -- If true ambiguity, give details.
6586 procedure Fixed_Point_Error is
6588 Error_Msg_N ("ambiguous universal_fixed_expression", N);
6589 Error_Msg_NE ("\possible interpretation as}", N, T1);
6590 Error_Msg_NE ("\possible interpretation as}", N, T2);
6591 end Fixed_Point_Error;
6594 -- The operations on Duration are visible, so Duration is always a
6595 -- possible interpretation.
6597 T1 := Standard_Duration;
6599 -- Look for fixed-point types in enclosing scopes.
6601 Scop := Current_Scope;
6602 while Scop /= Standard_Standard loop
6603 T2 := First_Entity (Scop);
6605 while Present (T2) loop
6606 if Is_Fixed_Point_Type (T2)
6607 and then Current_Entity (T2) = T2
6608 and then Scope (Base_Type (T2)) = Scop
6610 if Present (T1) then
6621 Scop := Scope (Scop);
6624 -- Look for visible fixed type declarations in the context.
6626 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
6628 while Present (Item) loop
6629 if Nkind (Item) = N_With_Clause then
6630 Scop := Entity (Name (Item));
6631 T2 := First_Entity (Scop);
6633 while Present (T2) loop
6634 if Is_Fixed_Point_Type (T2)
6635 and then Scope (Base_Type (T2)) = Scop
6636 and then (Is_Potentially_Use_Visible (T2)
6637 or else In_Use (T2))
6639 if Present (T1) then
6654 if Nkind (N) = N_Real_Literal then
6655 Error_Msg_NE ("real literal interpreted as }?", N, T1);
6658 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
6662 end Unique_Fixed_Point_Type;
6664 ----------------------
6665 -- Valid_Conversion --
6666 ----------------------
6668 function Valid_Conversion
6674 Target_Type : constant Entity_Id := Base_Type (Target);
6675 Opnd_Type : Entity_Id := Etype (Operand);
6677 function Conversion_Check
6681 -- Little routine to post Msg if Valid is False, returns Valid value
6683 function Valid_Tagged_Conversion
6684 (Target_Type : Entity_Id;
6685 Opnd_Type : Entity_Id)
6687 -- Specifically test for validity of tagged conversions
6689 ----------------------
6690 -- Conversion_Check --
6691 ----------------------
6693 function Conversion_Check
6700 Error_Msg_N (Msg, Operand);
6704 end Conversion_Check;
6706 -----------------------------
6707 -- Valid_Tagged_Conversion --
6708 -----------------------------
6710 function Valid_Tagged_Conversion
6711 (Target_Type : Entity_Id;
6712 Opnd_Type : Entity_Id)
6716 -- Upward conversions are allowed (RM 4.6(22)).
6718 if Covers (Target_Type, Opnd_Type)
6719 or else Is_Ancestor (Target_Type, Opnd_Type)
6723 -- Downward conversion are allowed if the operand is
6724 -- is class-wide (RM 4.6(23)).
6726 elsif Is_Class_Wide_Type (Opnd_Type)
6727 and then Covers (Opnd_Type, Target_Type)
6731 elsif Covers (Opnd_Type, Target_Type)
6732 or else Is_Ancestor (Opnd_Type, Target_Type)
6735 Conversion_Check (False,
6736 "downward conversion of tagged objects not allowed");
6739 ("invalid tagged conversion, not compatible with}",
6740 N, First_Subtype (Opnd_Type));
6743 end Valid_Tagged_Conversion;
6745 -- Start of processing for Valid_Conversion
6748 Check_Parameterless_Call (Operand);
6750 if Is_Overloaded (Operand) then
6759 -- Remove procedure calls, which syntactically cannot appear
6760 -- in this context, but which cannot be removed by type checking,
6761 -- because the context does not impose a type.
6763 Get_First_Interp (Operand, I, It);
6765 while Present (It.Typ) loop
6767 if It.Typ = Standard_Void_Type then
6771 Get_Next_Interp (I, It);
6774 Get_First_Interp (Operand, I, It);
6779 Error_Msg_N ("illegal operand in conversion", Operand);
6783 Get_Next_Interp (I, It);
6785 if Present (It.Typ) then
6787 It1 := Disambiguate (Operand, I1, I, Any_Type);
6789 if It1 = No_Interp then
6790 Error_Msg_N ("ambiguous operand in conversion", Operand);
6792 Error_Msg_Sloc := Sloc (It.Nam);
6793 Error_Msg_N ("possible interpretation#!", Operand);
6795 Error_Msg_Sloc := Sloc (N1);
6796 Error_Msg_N ("possible interpretation#!", Operand);
6802 Set_Etype (Operand, It1.Typ);
6803 Opnd_Type := It1.Typ;
6807 if Chars (Current_Scope) = Name_Unchecked_Conversion then
6809 -- This check is dubious, what if there were a user defined
6810 -- scope whose name was Unchecked_Conversion ???
6814 elsif Is_Numeric_Type (Target_Type) then
6815 if Opnd_Type = Universal_Fixed then
6818 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
6819 "illegal operand for numeric conversion");
6822 elsif Is_Array_Type (Target_Type) then
6823 if not Is_Array_Type (Opnd_Type)
6824 or else Opnd_Type = Any_Composite
6825 or else Opnd_Type = Any_String
6828 ("illegal operand for array conversion", Operand);
6831 elsif Number_Dimensions (Target_Type) /=
6832 Number_Dimensions (Opnd_Type)
6835 ("incompatible number of dimensions for conversion", Operand);
6840 Target_Index : Node_Id := First_Index (Target_Type);
6841 Opnd_Index : Node_Id := First_Index (Opnd_Type);
6843 Target_Index_Type : Entity_Id;
6844 Opnd_Index_Type : Entity_Id;
6846 Target_Comp_Type : constant Entity_Id :=
6847 Component_Type (Target_Type);
6848 Opnd_Comp_Type : constant Entity_Id :=
6849 Component_Type (Opnd_Type);
6852 while Present (Target_Index) and then Present (Opnd_Index) loop
6853 Target_Index_Type := Etype (Target_Index);
6854 Opnd_Index_Type := Etype (Opnd_Index);
6856 if not (Is_Integer_Type (Target_Index_Type)
6857 and then Is_Integer_Type (Opnd_Index_Type))
6858 and then (Root_Type (Target_Index_Type)
6859 /= Root_Type (Opnd_Index_Type))
6862 ("incompatible index types for array conversion",
6867 Next_Index (Target_Index);
6868 Next_Index (Opnd_Index);
6871 if Base_Type (Target_Comp_Type) /=
6872 Base_Type (Opnd_Comp_Type)
6875 ("incompatible component types for array conversion",
6880 Is_Constrained (Target_Comp_Type)
6881 /= Is_Constrained (Opnd_Comp_Type)
6882 or else not Subtypes_Statically_Match
6883 (Target_Comp_Type, Opnd_Comp_Type)
6886 ("component subtypes must statically match", Operand);
6895 elsif (Ekind (Target_Type) = E_General_Access_Type
6896 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
6899 (Is_Access_Type (Opnd_Type)
6900 and then Ekind (Opnd_Type) /=
6901 E_Access_Subprogram_Type
6902 and then Ekind (Opnd_Type) /=
6903 E_Access_Protected_Subprogram_Type,
6904 "must be an access-to-object type")
6906 if Is_Access_Constant (Opnd_Type)
6907 and then not Is_Access_Constant (Target_Type)
6910 ("access-to-constant operand type not allowed", Operand);
6914 -- Check the static accessibility rule of 4.6(17). Note that
6915 -- the check is not enforced when within an instance body, since
6916 -- the RM requires such cases to be caught at run time.
6918 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
6919 if Type_Access_Level (Opnd_Type)
6920 > Type_Access_Level (Target_Type)
6922 -- In an instance, this is a run-time check, but one we
6923 -- know will fail, so generate an appropriate warning.
6924 -- The raise will be generated by Expand_N_Type_Conversion.
6926 if In_Instance_Body then
6928 ("?cannot convert local pointer to non-local access type",
6931 ("?Program_Error will be raised at run time", Operand);
6935 ("cannot convert local pointer to non-local access type",
6940 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
6942 -- When the operand is a selected access discriminant
6943 -- the check needs to be made against the level of the
6944 -- object denoted by the prefix of the selected name.
6945 -- (Object_Access_Level handles checking the prefix
6946 -- of the operand for this case.)
6948 if Nkind (Operand) = N_Selected_Component
6949 and then Object_Access_Level (Operand)
6950 > Type_Access_Level (Target_Type)
6952 -- In an instance, this is a run-time check, but one we
6953 -- know will fail, so generate an appropriate warning.
6954 -- The raise will be generated by Expand_N_Type_Conversion.
6956 if In_Instance_Body then
6958 ("?cannot convert access discriminant to non-local" &
6959 " access type", Operand);
6961 ("?Program_Error will be raised at run time", Operand);
6965 ("cannot convert access discriminant to non-local" &
6966 " access type", Operand);
6971 -- The case of a reference to an access discriminant
6972 -- from within a type declaration (which will appear
6973 -- as a discriminal) is always illegal because the
6974 -- level of the discriminant is considered to be
6975 -- deeper than any (namable) access type.
6977 if Is_Entity_Name (Operand)
6978 and then (Ekind (Entity (Operand)) = E_In_Parameter
6979 or else Ekind (Entity (Operand)) = E_Constant)
6980 and then Present (Discriminal_Link (Entity (Operand)))
6983 ("discriminant has deeper accessibility level than target",
6991 Target : constant Entity_Id := Designated_Type (Target_Type);
6992 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
6995 if Is_Tagged_Type (Target) then
6996 return Valid_Tagged_Conversion (Target, Opnd);
6999 if Base_Type (Target) /= Base_Type (Opnd) then
7001 ("target designated type not compatible with }",
7002 N, Base_Type (Opnd));
7005 elsif not Subtypes_Statically_Match (Target, Opnd)
7006 and then (not Has_Discriminants (Target)
7007 or else Is_Constrained (Target))
7010 ("target designated subtype not compatible with }",
7020 elsif Ekind (Target_Type) = E_Access_Subprogram_Type
7021 and then Conversion_Check
7022 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7023 "illegal operand for access subprogram conversion")
7025 -- Check that the designated types are subtype conformant
7027 if not Subtype_Conformant (Designated_Type (Opnd_Type),
7028 Designated_Type (Target_Type))
7031 ("operand type is not subtype conformant with target type",
7035 -- Check the static accessibility rule of 4.6(20)
7037 if Type_Access_Level (Opnd_Type) >
7038 Type_Access_Level (Target_Type)
7041 ("operand type has deeper accessibility level than target",
7044 -- Check that if the operand type is declared in a generic body,
7045 -- then the target type must be declared within that same body
7046 -- (enforces last sentence of 4.6(20)).
7048 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7050 O_Gen : constant Node_Id :=
7051 Enclosing_Generic_Body (Opnd_Type);
7054 Enclosing_Generic_Body (Target_Type);
7057 while Present (T_Gen) and then T_Gen /= O_Gen loop
7058 T_Gen := Enclosing_Generic_Body (T_Gen);
7061 if T_Gen /= O_Gen then
7063 ("target type must be declared in same generic body"
7064 & " as operand type", N);
7071 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7072 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7074 -- It is valid to convert from one RAS type to another provided
7075 -- that their specification statically match.
7077 Check_Subtype_Conformant
7079 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7081 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7086 elsif Is_Tagged_Type (Target_Type) then
7087 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7089 -- Types derived from the same root type are convertible.
7091 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7094 -- In an instance, there may be inconsistent views of the same
7095 -- type, or types derived from the same type.
7098 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7102 -- Special check for common access type error case
7104 elsif Ekind (Target_Type) = E_Access_Type
7105 and then Is_Access_Type (Opnd_Type)
7107 Error_Msg_N ("target type must be general access type!", N);
7108 Error_Msg_NE ("add ALL to }!", N, Target_Type);
7113 Error_Msg_NE ("invalid conversion, not compatible with }",
7118 end Valid_Conversion;