1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Checks; use Checks;
31 with Debug; use Debug;
32 with Debug_A; use Debug_A;
33 with Einfo; use Einfo;
34 with Errout; use Errout;
35 with Expander; use Expander;
36 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
41 with Lib.Xref; use Lib.Xref;
42 with Namet; use Namet;
43 with Nmake; use Nmake;
44 with Nlists; use Nlists;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rtsfind; use Rtsfind;
50 with Sem_Aggr; use Sem_Aggr;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch4; use Sem_Ch4;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Dist; use Sem_Dist;
58 with Sem_Elab; use Sem_Elab;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Util; use Sem_Util;
62 with Sem_Type; use Sem_Type;
63 with Sem_Warn; use Sem_Warn;
64 with Sinfo; use Sinfo;
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_Discriminant_Use (N : Node_Id);
92 -- Enforce the restrictions on the use of discriminants when constraining
93 -- a component of a discriminated type (record or concurrent type).
95 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
96 -- Given a node for an operator associated with type T, check that
97 -- the operator is visible. Operators all of whose operands are
98 -- universal must be checked for visibility during resolution
99 -- because their type is not determinable based on their operands.
101 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
102 -- Given a call node, N, which is known to occur immediately within the
103 -- subprogram being called, determines whether it is a detectable case of
104 -- an infinite recursion, and if so, outputs appropriate messages. Returns
105 -- True if an infinite recursion is detected, and False otherwise.
107 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
108 -- If the type of the object being initialized uses the secondary stack
109 -- directly or indirectly, create a transient scope for the call to the
110 -- Init_Proc. This is because we do not create transient scopes for the
111 -- initialization of individual components within the init_proc itself.
112 -- Could be optimized away perhaps?
114 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
115 -- Utility to check whether the name in the call is a predefined
116 -- operator, in which case the call is made into an operator node.
117 -- An instance of an intrinsic conversion operation may be given
118 -- an operator name, but is not treated like an operator.
120 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
121 -- If a default expression in entry call N depends on the discriminants
122 -- of the task, it must be replaced with a reference to the discriminant
123 -- of the task being called.
125 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
126 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
127 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
128 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
129 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
130 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
131 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
132 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
133 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
134 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
135 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
136 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
137 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
138 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
139 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
140 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
141 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
142 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
143 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
144 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
145 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
146 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
147 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
148 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
149 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
150 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
151 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
152 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
153 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
158 function Operator_Kind
162 -- Utility to map the name of an operator into the corresponding Node. Used
163 -- by other node rewriting procedures.
165 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
166 -- Resolve actuals of call, and add default expressions for missing ones.
168 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
169 -- Called from Resolve_Call, when the prefix denotes an entry or element
170 -- of entry family. Actuals are resolved as for subprograms, and the node
171 -- is rebuilt as an entry call. Also called for protected operations. Typ
172 -- is the context type, which is used when the operation is a protected
173 -- function with no arguments, and the return value is indexed.
175 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
176 -- A call to a user-defined intrinsic operator is rewritten as a call
177 -- to the corresponding predefined operator, with suitable conversions.
179 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
180 -- If an operator node resolves to a call to a user-defined operator,
181 -- rewrite the node as a function call.
183 procedure Make_Call_Into_Operator
187 -- Inverse transformation: if an operator is given in functional notation,
188 -- then after resolving the node, transform into an operator node, so
189 -- that operands are resolved properly. Recall that predefined operators
190 -- do not have a full signature and special resolution rules apply.
192 procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id);
193 -- An operator can rename another, e.g. in an instantiation. In that
194 -- case, the proper operator node must be constructed.
196 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
197 -- The String_Literal_Subtype is built for all strings that are not
198 -- operands of a static concatenation operation. If the argument is not
199 -- a String the function is a no-op.
201 procedure Set_Slice_Subtype (N : Node_Id);
202 -- Build subtype of array type, with the range specified by the slice.
204 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
205 -- A universal_fixed expression in an universal context is unambiguous if
206 -- there is only one applicable fixed point type. Determining whether
207 -- there is only one requires a search over all visible entities, and
208 -- happens only in very pathological cases (see 6115-006).
210 function Valid_Conversion
215 -- Verify legality rules given in 4.6 (8-23). Target is the target
216 -- type of the conversion, which may be an implicit conversion of
217 -- an actual parameter to an anonymous access type (in which case
218 -- N denotes the actual parameter and N = Operand).
220 -------------------------
221 -- Ambiguous_Character --
222 -------------------------
224 procedure Ambiguous_Character (C : Node_Id) is
228 if Nkind (C) = N_Character_Literal then
229 Error_Msg_N ("ambiguous character literal", C);
231 ("\possible interpretations: Character, Wide_Character!", C);
233 E := Current_Entity (C);
237 while Present (E) loop
238 Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
243 end Ambiguous_Character;
245 -------------------------
246 -- Analyze_And_Resolve --
247 -------------------------
249 procedure Analyze_And_Resolve (N : Node_Id) is
252 Resolve (N, Etype (N));
253 end Analyze_And_Resolve;
255 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
259 end Analyze_And_Resolve;
261 -- Version withs check(s) suppressed
263 procedure Analyze_And_Resolve
268 Scop : Entity_Id := Current_Scope;
271 if Suppress = All_Checks then
273 Svg : constant Suppress_Record := Scope_Suppress;
276 Scope_Suppress := (others => True);
277 Analyze_And_Resolve (N, Typ);
278 Scope_Suppress := Svg;
283 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
286 Set_Scope_Suppress (Suppress, True);
287 Analyze_And_Resolve (N, Typ);
288 Set_Scope_Suppress (Suppress, Svg);
292 if Current_Scope /= Scop
293 and then Scope_Is_Transient
295 -- This can only happen if a transient scope was created
296 -- for an inner expression, which will be removed upon
297 -- completion of the analysis of an enclosing construct.
298 -- The transient scope must have the suppress status of
299 -- the enclosing environment, not of this Analyze call.
301 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
304 end Analyze_And_Resolve;
306 procedure Analyze_And_Resolve
310 Scop : Entity_Id := Current_Scope;
313 if Suppress = All_Checks then
315 Svg : constant Suppress_Record := Scope_Suppress;
318 Scope_Suppress := (others => True);
319 Analyze_And_Resolve (N);
320 Scope_Suppress := Svg;
325 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
328 Set_Scope_Suppress (Suppress, True);
329 Analyze_And_Resolve (N);
330 Set_Scope_Suppress (Suppress, Svg);
334 if Current_Scope /= Scop
335 and then Scope_Is_Transient
337 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
340 end Analyze_And_Resolve;
342 ----------------------------
343 -- Check_Discriminant_Use --
344 ----------------------------
346 procedure Check_Discriminant_Use (N : Node_Id) is
347 PN : constant Node_Id := Parent (N);
348 Disc : constant Entity_Id := Entity (N);
353 -- Any use in a default expression is legal.
355 if In_Default_Expression then
358 elsif Nkind (PN) = N_Range then
360 -- Discriminant cannot be used to constrain a scalar type.
364 if Nkind (P) = N_Range_Constraint
365 and then Nkind (Parent (P)) = N_Subtype_Indication
366 and then Nkind (Parent (Parent (P))) = N_Component_Declaration
368 Error_Msg_N ("discriminant cannot constrain scalar type", N);
370 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
372 -- The following check catches the unusual case where
373 -- a discriminant appears within an index constraint
374 -- that is part of a larger expression within a constraint
375 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
376 -- For now we only check case of record components, and
377 -- note that a similar check should also apply in the
378 -- case of discriminant constraints below. ???
380 -- Note that the check for N_Subtype_Declaration below is to
381 -- detect the valid use of discriminants in the constraints of a
382 -- subtype declaration when this subtype declaration appears
383 -- inside the scope of a record type (which is syntactically
384 -- illegal, but which may be created as part of derived type
385 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
388 if Ekind (Current_Scope) = E_Record_Type
389 and then Scope (Disc) = Current_Scope
391 (Nkind (Parent (P)) = N_Subtype_Indication
393 (Nkind (Parent (Parent (P))) = N_Component_Declaration
394 or else Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
395 and then Paren_Count (N) = 0)
398 ("discriminant must appear alone in component constraint", N);
402 -- Detect a common beginner error:
403 -- type R (D : Positive := 100) is record
404 -- Name: String (1 .. D);
407 -- The default value causes an object of type R to be
408 -- allocated with room for Positive'Last characters.
416 function Large_Storage_Type (T : Entity_Id) return Boolean;
417 -- Return True if type T has a large enough range that
418 -- any array whose index type covered the whole range of
419 -- the type would likely raise Storage_Error.
421 function Large_Storage_Type (T : Entity_Id) return Boolean is
426 T = Standard_Positive
428 T = Standard_Natural;
429 end Large_Storage_Type;
432 -- Check that the Disc has a large range
434 if not Large_Storage_Type (Etype (Disc)) then
438 -- If the enclosing type is limited, we allocate only the
439 -- default value, not the maximum, and there is no need for
442 if Is_Limited_Type (Scope (Disc)) then
446 -- Check that it is the high bound
448 if N /= High_Bound (PN)
449 or else not Present (Discriminant_Default_Value (Disc))
454 -- Check the array allows a large range at this bound.
455 -- First find the array
459 if Nkind (SI) /= N_Subtype_Indication then
463 T := Entity (Subtype_Mark (SI));
465 if not Is_Array_Type (T) then
469 -- Next, find the dimension
471 TB := First_Index (T);
472 CB := First (Constraints (P));
474 and then Present (TB)
475 and then Present (CB)
486 -- Now, check the dimension has a large range
488 if not Large_Storage_Type (Etype (TB)) then
492 -- Warn about the danger
495 ("creation of object of this type may raise Storage_Error?",
504 -- Legal case is in index or discriminant constraint
506 elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
507 or else Nkind (PN) = N_Discriminant_Association
509 if Paren_Count (N) > 0 then
511 ("discriminant in constraint must appear alone", N);
516 -- Otherwise, context is an expression. It should not be within
517 -- (i.e. a subexpression of) a constraint for a component.
523 while Nkind (P) /= N_Component_Declaration
524 and then Nkind (P) /= N_Subtype_Indication
525 and then Nkind (P) /= N_Entry_Declaration
532 -- If the discriminant is used in an expression that is a bound
533 -- of a scalar type, an Itype is created and the bounds are attached
534 -- to its range, not to the original subtype indication. Such use
535 -- is of course a double fault.
537 if (Nkind (P) = N_Subtype_Indication
539 (Nkind (Parent (P)) = N_Component_Declaration
540 or else Nkind (Parent (P)) = N_Derived_Type_Definition)
541 and then D = Constraint (P))
543 -- The constraint itself may be given by a subtype indication,
544 -- rather than by a more common discrete range.
546 or else (Nkind (P) = N_Subtype_Indication
547 and then Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
549 or else Nkind (P) = N_Entry_Declaration
550 or else Nkind (D) = N_Defining_Identifier
553 ("discriminant in constraint must appear alone", N);
556 end Check_Discriminant_Use;
558 --------------------------------
559 -- Check_For_Visible_Operator --
560 --------------------------------
562 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
563 Orig_Node : Node_Id := Original_Node (N);
566 if Comes_From_Source (Orig_Node)
567 and then not In_Open_Scopes (Scope (T))
568 and then not Is_Potentially_Use_Visible (T)
569 and then not In_Use (T)
570 and then not In_Use (Scope (T))
571 and then (not Present (Entity (N))
572 or else Ekind (Entity (N)) /= E_Function)
573 and then (Nkind (Orig_Node) /= N_Function_Call
574 or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
575 or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
576 and then not In_Instance
579 ("operator for} is not directly visible!", N, First_Subtype (T));
580 Error_Msg_N ("use clause would make operation legal!", N);
582 end Check_For_Visible_Operator;
584 ------------------------------
585 -- Check_Infinite_Recursion --
586 ------------------------------
588 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
593 -- Loop moving up tree, quitting if something tells us we are
594 -- definitely not in an infinite recursion situation.
599 exit when Nkind (P) = N_Subprogram_Body;
601 if Nkind (P) = N_Or_Else or else
602 Nkind (P) = N_And_Then or else
603 Nkind (P) = N_If_Statement or else
604 Nkind (P) = N_Case_Statement
608 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
609 and then C /= First (Statements (P))
618 Warn_On_Instance := True;
619 Error_Msg_N ("possible infinite recursion?", N);
620 Error_Msg_N ("\Storage_Error may be raised at run time?", N);
621 Warn_On_Instance := False;
624 end Check_Infinite_Recursion;
626 -------------------------------
627 -- Check_Initialization_Call --
628 -------------------------------
630 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
631 Typ : Entity_Id := Etype (First_Formal (Nam));
633 function Uses_SS (T : Entity_Id) return Boolean;
635 function Uses_SS (T : Entity_Id) return Boolean is
641 or else Has_Controlled_Component (T)
642 or else Functions_Return_By_DSP_On_Target
646 elsif Is_Array_Type (T) then
647 return Uses_SS (Component_Type (T));
649 elsif Is_Record_Type (T) then
650 Comp := First_Component (T);
652 while Present (Comp) loop
654 if Ekind (Comp) = E_Component
655 and then Nkind (Parent (Comp)) = N_Component_Declaration
657 Expr := Expression (Parent (Comp));
659 if Nkind (Expr) = N_Function_Call
660 and then Requires_Transient_Scope (Etype (Expr))
664 elsif Uses_SS (Etype (Comp)) then
669 Next_Component (Comp);
680 if Uses_SS (Typ) then
681 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
683 end Check_Initialization_Call;
685 ------------------------------
686 -- Check_Parameterless_Call --
687 ------------------------------
689 procedure Check_Parameterless_Call (N : Node_Id) is
693 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
697 -- Rewrite as call if overloadable entity that is (or could be, in
698 -- the overloaded case) a function call. If we know for sure that
699 -- the entity is an enumeration literal, we do not rewrite it.
701 if (Is_Entity_Name (N)
702 and then Is_Overloadable (Entity (N))
703 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
704 or else Is_Overloaded (N)))
706 -- Rewrite as call if it is an explicit deference of an expression of
707 -- a subprogram access type, and the suprogram type is not that of a
708 -- procedure or entry.
711 (Nkind (N) = N_Explicit_Dereference
712 and then Ekind (Etype (N)) = E_Subprogram_Type
713 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type)
715 -- Rewrite as call if it is a selected component which is a function,
716 -- this is the case of a call to a protected function (which may be
717 -- overloaded with other protected operations).
720 (Nkind (N) = N_Selected_Component
721 and then (Ekind (Entity (Selector_Name (N))) = E_Function
722 or else ((Ekind (Entity (Selector_Name (N))) = E_Entry
724 Ekind (Entity (Selector_Name (N))) = E_Procedure)
725 and then Is_Overloaded (Selector_Name (N)))))
727 -- If one of the above three conditions is met, rewrite as call.
728 -- Apply the rewriting only once.
731 if Nkind (Parent (N)) /= N_Function_Call
732 or else N /= Name (Parent (N))
736 -- If overloaded, overload set belongs to new copy.
738 Save_Interps (N, Nam);
740 -- Change node to parameterless function call (note that the
741 -- Parameter_Associations associations field is left set to Empty,
742 -- its normal default value since there are no parameters)
744 Change_Node (N, N_Function_Call);
746 Set_Sloc (N, Sloc (Nam));
750 elsif Nkind (N) = N_Parameter_Association then
751 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
753 end Check_Parameterless_Call;
755 ----------------------
756 -- Is_Predefined_Op --
757 ----------------------
759 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
761 return Is_Intrinsic_Subprogram (Nam)
762 and then not Is_Generic_Instance (Nam)
763 and then Chars (Nam) in Any_Operator_Name
764 and then (No (Alias (Nam))
765 or else Is_Predefined_Op (Alias (Nam)));
766 end Is_Predefined_Op;
768 -----------------------------
769 -- Make_Call_Into_Operator --
770 -----------------------------
772 procedure Make_Call_Into_Operator
777 Op_Name : constant Name_Id := Chars (Op_Id);
778 Act1 : Node_Id := First_Actual (N);
779 Act2 : Node_Id := Next_Actual (Act1);
780 Error : Boolean := False;
781 Is_Binary : constant Boolean := Present (Act2);
783 Opnd_Type : Entity_Id;
784 Orig_Type : Entity_Id := Empty;
787 type Kind_Test is access function (E : Entity_Id) return Boolean;
789 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
790 -- Determine whether E is an acess type declared by an access decla-
791 -- ration, and not an (anonymous) allocator type.
793 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
794 -- If the operand is not universal, and the operator is given by a
795 -- expanded name, verify that the operand has an interpretation with
796 -- a type defined in the given scope of the operator.
798 function Type_In_P (Test : Kind_Test) return Entity_Id;
799 -- Find a type of the given class in the package Pack that contains
802 -----------------------------
803 -- Is_Definite_Access_Type --
804 -----------------------------
806 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
807 Btyp : constant Entity_Id := Base_Type (E);
809 return Ekind (Btyp) = E_Access_Type
810 or else (Ekind (Btyp) = E_Access_Subprogram_Type
811 and then Comes_From_Source (Btyp));
812 end Is_Definite_Access_Type;
814 ---------------------------
815 -- Operand_Type_In_Scope --
816 ---------------------------
818 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
819 Nod : constant Node_Id := Right_Opnd (Op_Node);
824 if not Is_Overloaded (Nod) then
825 return Scope (Base_Type (Etype (Nod))) = S;
828 Get_First_Interp (Nod, I, It);
830 while Present (It.Typ) loop
832 if Scope (Base_Type (It.Typ)) = S then
836 Get_Next_Interp (I, It);
841 end Operand_Type_In_Scope;
847 function Type_In_P (Test : Kind_Test) return Entity_Id is
850 function In_Decl return Boolean;
851 -- Verify that node is not part of the type declaration for the
852 -- candidate type, which would otherwise be invisible.
858 function In_Decl return Boolean is
859 Decl_Node : constant Node_Id := Parent (E);
865 if Etype (E) = Any_Type then
868 elsif No (Decl_Node) then
873 and then Nkind (N2) /= N_Compilation_Unit
875 if N2 = Decl_Node then
886 -- Start of processing for Type_In_P
889 -- If the context type is declared in the prefix package, this
890 -- is the desired base type.
892 if Scope (Base_Type (Typ)) = Pack
895 return Base_Type (Typ);
898 E := First_Entity (Pack);
900 while Present (E) loop
915 ---------------------------
916 -- Operand_Type_In_Scope --
917 ---------------------------
919 -- Start of processing for Make_Call_Into_Operator
922 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
927 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
928 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
929 Save_Interps (Act1, Left_Opnd (Op_Node));
930 Save_Interps (Act2, Right_Opnd (Op_Node));
931 Act1 := Left_Opnd (Op_Node);
932 Act2 := Right_Opnd (Op_Node);
937 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
938 Save_Interps (Act1, Right_Opnd (Op_Node));
939 Act1 := Right_Opnd (Op_Node);
942 -- If the operator is denoted by an expanded name, and the prefix is
943 -- not Standard, but the operator is a predefined one whose scope is
944 -- Standard, then this is an implicit_operator, inserted as an
945 -- interpretation by the procedure of the same name. This procedure
946 -- overestimates the presence of implicit operators, because it does
947 -- not examine the type of the operands. Verify now that the operand
948 -- type appears in the given scope. If right operand is universal,
949 -- check the other operand. In the case of concatenation, either
950 -- argument can be the component type, so check the type of the result.
951 -- If both arguments are literals, look for a type of the right kind
952 -- defined in the given scope. This elaborate nonsense is brought to
953 -- you courtesy of b33302a. The type itself must be frozen, so we must
954 -- find the type of the proper class in the given scope.
956 -- A final wrinkle is the multiplication operator for fixed point
957 -- types, which is defined in Standard only, and not in the scope of
958 -- the fixed_point type itself.
960 if Nkind (Name (N)) = N_Expanded_Name then
961 Pack := Entity (Prefix (Name (N)));
963 -- If the entity being called is defined in the given package,
964 -- it is a renaming of a predefined operator, and known to be
967 if Scope (Entity (Name (N))) = Pack
968 and then Pack /= Standard_Standard
972 elsif (Op_Name = Name_Op_Multiply
973 or else Op_Name = Name_Op_Divide)
974 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
975 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
977 if Pack /= Standard_Standard then
982 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
984 if Op_Name = Name_Op_Concat then
985 Opnd_Type := Base_Type (Typ);
987 elsif (Scope (Opnd_Type) = Standard_Standard
989 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
991 and then not Comes_From_Source (Opnd_Type))
993 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
996 if Scope (Opnd_Type) = Standard_Standard then
998 -- Verify that the scope contains a type that corresponds to
999 -- the given literal. Optimize the case where Pack is Standard.
1001 if Pack /= Standard_Standard then
1003 if Opnd_Type = Universal_Integer then
1004 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1006 elsif Opnd_Type = Universal_Real then
1007 Orig_Type := Type_In_P (Is_Real_Type'Access);
1009 elsif Opnd_Type = Any_String then
1010 Orig_Type := Type_In_P (Is_String_Type'Access);
1012 elsif Opnd_Type = Any_Access then
1013 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1015 elsif Opnd_Type = Any_Composite then
1016 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1018 if Present (Orig_Type) then
1019 if Has_Private_Component (Orig_Type) then
1022 Set_Etype (Act1, Orig_Type);
1025 Set_Etype (Act2, Orig_Type);
1034 Error := No (Orig_Type);
1037 elsif Ekind (Opnd_Type) = E_Allocator_Type
1038 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1042 -- If the type is defined elsewhere, and the operator is not
1043 -- defined in the given scope (by a renaming declaration, e.g.)
1044 -- then this is an error as well. If an extension of System is
1045 -- present, and the type may be defined there, Pack must be
1048 elsif Scope (Opnd_Type) /= Pack
1049 and then Scope (Op_Id) /= Pack
1050 and then (No (System_Aux_Id)
1051 or else Scope (Opnd_Type) /= System_Aux_Id
1052 or else Pack /= Scope (System_Aux_Id))
1056 elsif Pack = Standard_Standard
1057 and then not Operand_Type_In_Scope (Standard_Standard)
1064 Error_Msg_Node_2 := Pack;
1066 ("& not declared in&", N, Selector_Name (Name (N)));
1067 Set_Etype (N, Any_Type);
1072 Set_Chars (Op_Node, Op_Name);
1073 Set_Etype (Op_Node, Base_Type (Etype (N)));
1074 Set_Entity (Op_Node, Op_Id);
1075 Generate_Reference (Op_Id, N, ' ');
1076 Rewrite (N, Op_Node);
1079 -- For predefined operators on literals, the operation freezes
1082 if Present (Orig_Type) then
1083 Set_Etype (Act1, Orig_Type);
1084 Freeze_Expression (Act1);
1086 end Make_Call_Into_Operator;
1092 function Operator_Kind
1094 Is_Binary : Boolean)
1101 if Op_Name = Name_Op_And then Kind := N_Op_And;
1102 elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
1103 elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
1104 elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
1105 elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
1106 elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
1107 elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
1108 elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
1109 elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
1110 elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
1111 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
1112 elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
1113 elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
1114 elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
1115 elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
1116 elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
1117 elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
1119 raise Program_Error;
1125 if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
1126 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
1127 elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
1128 elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
1130 raise Program_Error;
1137 -----------------------------
1138 -- Pre_Analyze_And_Resolve --
1139 -----------------------------
1141 procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1142 Save_Full_Analysis : constant Boolean := Full_Analysis;
1145 Full_Analysis := False;
1146 Expander_Mode_Save_And_Set (False);
1148 -- We suppress all checks for this analysis, since the checks will
1149 -- be applied properly, and in the right location, when the default
1150 -- expression is reanalyzed and reexpanded later on.
1152 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1154 Expander_Mode_Restore;
1155 Full_Analysis := Save_Full_Analysis;
1156 end Pre_Analyze_And_Resolve;
1158 -- Version without context type.
1160 procedure Pre_Analyze_And_Resolve (N : Node_Id) is
1161 Save_Full_Analysis : constant Boolean := Full_Analysis;
1164 Full_Analysis := False;
1165 Expander_Mode_Save_And_Set (False);
1168 Resolve (N, Etype (N), Suppress => All_Checks);
1170 Expander_Mode_Restore;
1171 Full_Analysis := Save_Full_Analysis;
1172 end Pre_Analyze_And_Resolve;
1174 ----------------------------------
1175 -- Replace_Actual_Discriminants --
1176 ----------------------------------
1178 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1179 Loc : constant Source_Ptr := Sloc (N);
1180 Tsk : Node_Id := Empty;
1182 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1188 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1192 if Nkind (Nod) = N_Identifier then
1193 Ent := Entity (Nod);
1196 and then Ekind (Ent) = E_Discriminant
1199 Make_Selected_Component (Loc,
1200 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1201 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1203 Set_Etype (Nod, Etype (Ent));
1211 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1213 -- Start of processing for Replace_Actual_Discriminants
1216 if not Expander_Active then
1220 if Nkind (Name (N)) = N_Selected_Component then
1221 Tsk := Prefix (Name (N));
1223 elsif Nkind (Name (N)) = N_Indexed_Component then
1224 Tsk := Prefix (Prefix (Name (N)));
1230 Replace_Discrs (Default);
1232 end Replace_Actual_Discriminants;
1238 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1240 I1 : Interp_Index := 0; -- prevent junk warning
1243 Found : Boolean := False;
1244 Seen : Entity_Id := Empty; -- prevent junk warning
1245 Ctx_Type : Entity_Id := Typ;
1246 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1247 Ambiguous : Boolean := False;
1249 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1250 -- Try and fix up a literal so that it matches its expected type. New
1251 -- literals are manufactured if necessary to avoid cascaded errors.
1253 procedure Resolution_Failed;
1254 -- Called when attempt at resolving current expression fails
1256 --------------------
1257 -- Patch_Up_Value --
1258 --------------------
1260 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1262 if Nkind (N) = N_Integer_Literal
1263 and then Is_Real_Type (Typ)
1266 Make_Real_Literal (Sloc (N),
1267 Realval => UR_From_Uint (Intval (N))));
1268 Set_Etype (N, Universal_Real);
1269 Set_Is_Static_Expression (N);
1271 elsif Nkind (N) = N_Real_Literal
1272 and then Is_Integer_Type (Typ)
1275 Make_Integer_Literal (Sloc (N),
1276 Intval => UR_To_Uint (Realval (N))));
1277 Set_Etype (N, Universal_Integer);
1278 Set_Is_Static_Expression (N);
1279 elsif Nkind (N) = N_String_Literal
1280 and then Is_Character_Type (Typ)
1282 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1284 Make_Character_Literal (Sloc (N),
1286 Char_Literal_Value => Char_Code (Character'Pos ('A'))));
1287 Set_Etype (N, Any_Character);
1288 Set_Is_Static_Expression (N);
1290 elsif Nkind (N) /= N_String_Literal
1291 and then Is_String_Type (Typ)
1294 Make_String_Literal (Sloc (N),
1295 Strval => End_String));
1297 elsif Nkind (N) = N_Range then
1298 Patch_Up_Value (Low_Bound (N), Typ);
1299 Patch_Up_Value (High_Bound (N), Typ);
1303 -----------------------
1304 -- Resolution_Failed --
1305 -----------------------
1307 procedure Resolution_Failed is
1309 Patch_Up_Value (N, Typ);
1311 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1312 Set_Is_Overloaded (N, False);
1314 -- The caller will return without calling the expander, so we need
1315 -- to set the analyzed flag. Note that it is fine to set Analyzed
1316 -- to True even if we are in the middle of a shallow analysis,
1317 -- (see the spec of sem for more details) since this is an error
1318 -- situation anyway, and there is no point in repeating the
1319 -- analysis later (indeed it won't work to repeat it later, since
1320 -- we haven't got a clear resolution of which entity is being
1323 Set_Analyzed (N, True);
1325 end Resolution_Failed;
1327 -- Start of processing for Resolve
1334 -- Access attribute on remote subprogram cannot be used for
1335 -- a non-remote access-to-subprogram type.
1337 if Nkind (N) = N_Attribute_Reference
1338 and then (Attribute_Name (N) = Name_Access
1339 or else Attribute_Name (N) = Name_Unrestricted_Access
1340 or else Attribute_Name (N) = Name_Unchecked_Access)
1341 and then Comes_From_Source (N)
1342 and then Is_Entity_Name (Prefix (N))
1343 and then Is_Subprogram (Entity (Prefix (N)))
1344 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1345 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1348 ("prefix must statically denote a non-remote subprogram", N);
1351 -- If the context is a Remote_Access_To_Subprogram, access attributes
1352 -- must be resolved with the corresponding fat pointer. There is no need
1353 -- to check for the attribute name since the return type of an
1354 -- attribute is never a remote type.
1356 if Nkind (N) = N_Attribute_Reference
1357 and then Comes_From_Source (N)
1358 and then (Is_Remote_Call_Interface (Typ)
1359 or else Is_Remote_Types (Typ))
1362 Attr : constant Attribute_Id :=
1363 Get_Attribute_Id (Attribute_Name (N));
1364 Pref : constant Node_Id := Prefix (N);
1367 Is_Remote : Boolean := True;
1370 -- Check that Typ is a fat pointer with a reference to a RAS as
1371 -- original access type.
1374 (Ekind (Typ) = E_Access_Subprogram_Type
1375 and then Present (Equivalent_Type (Typ)))
1377 (Ekind (Typ) = E_Record_Type
1378 and then Present (Corresponding_Remote_Type (Typ)))
1381 -- Prefix (N) must statically denote a remote subprogram
1382 -- declared in a package specification.
1384 if Attr = Attribute_Access then
1385 Decl := Unit_Declaration_Node (Entity (Pref));
1387 if Nkind (Decl) = N_Subprogram_Body then
1388 Spec := Corresponding_Spec (Decl);
1390 if not No (Spec) then
1391 Decl := Unit_Declaration_Node (Spec);
1395 Spec := Parent (Decl);
1397 if not Is_Entity_Name (Prefix (N))
1398 or else Nkind (Spec) /= N_Package_Specification
1400 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1404 ("prefix must statically denote a remote subprogram ",
1409 if Attr = Attribute_Access
1410 or else Attr = Attribute_Unchecked_Access
1411 or else Attr = Attribute_Unrestricted_Access
1413 Check_Subtype_Conformant
1414 (New_Id => Entity (Prefix (N)),
1415 Old_Id => Designated_Type
1416 (Corresponding_Remote_Type (Typ)),
1419 Process_Remote_AST_Attribute (N, Typ);
1426 Debug_A_Entry ("resolving ", N);
1428 if Is_Fixed_Point_Type (Typ) then
1429 Check_Restriction (No_Fixed_Point, N);
1431 elsif Is_Floating_Point_Type (Typ)
1432 and then Typ /= Universal_Real
1433 and then Typ /= Any_Real
1435 Check_Restriction (No_Floating_Point, N);
1438 -- Return if already analyzed
1440 if Analyzed (N) then
1441 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1444 -- Return if type = Any_Type (previous error encountered)
1446 elsif Etype (N) = Any_Type then
1447 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1451 Check_Parameterless_Call (N);
1453 -- If not overloaded, then we know the type, and all that needs doing
1454 -- is to check that this type is compatible with the context.
1456 if not Is_Overloaded (N) then
1457 Found := Covers (Typ, Etype (N));
1458 Expr_Type := Etype (N);
1460 -- In the overloaded case, we must select the interpretation that
1461 -- is compatible with the context (i.e. the type passed to Resolve)
1464 Get_First_Interp (N, I, It);
1466 -- Loop through possible interpretations
1468 Interp_Loop : while Present (It.Typ) loop
1470 -- We are only interested in interpretations that are compatible
1471 -- with the expected type, any other interpretations are ignored
1473 if Covers (Typ, It.Typ) then
1475 -- First matching interpretation
1481 Expr_Type := It.Typ;
1483 -- Matching intepretation that is not the first, maybe an
1484 -- error, but there are some cases where preference rules are
1485 -- used to choose between the two possibilities. These and
1486 -- some more obscure cases are handled in Disambiguate.
1489 Error_Msg_Sloc := Sloc (Seen);
1490 It1 := Disambiguate (N, I1, I, Typ);
1492 if It1 = No_Interp then
1494 -- Before we issue an ambiguity complaint, check for
1495 -- the case of a subprogram call where at least one
1496 -- of the arguments is Any_Type, and if so, suppress
1497 -- the message, since it is a cascaded error.
1499 if Nkind (N) = N_Function_Call
1500 or else Nkind (N) = N_Procedure_Call_Statement
1503 A : Node_Id := First_Actual (N);
1507 while Present (A) loop
1510 if Nkind (E) = N_Parameter_Association then
1511 E := Explicit_Actual_Parameter (E);
1514 if Etype (E) = Any_Type then
1515 if Debug_Flag_V then
1516 Write_Str ("Any_Type in call");
1527 elsif Nkind (N) in N_Binary_Op
1528 and then (Etype (Left_Opnd (N)) = Any_Type
1529 or else Etype (Right_Opnd (N)) = Any_Type)
1533 elsif Nkind (N) in N_Unary_Op
1534 and then Etype (Right_Opnd (N)) = Any_Type
1539 -- Not that special case, so issue message using the
1540 -- flag Ambiguous to control printing of the header
1541 -- message only at the start of an ambiguous set.
1543 if not Ambiguous then
1545 ("ambiguous expression (cannot resolve&)!",
1548 ("possible interpretation#!", N);
1552 Error_Msg_Sloc := Sloc (It.Nam);
1553 Error_Msg_N ("possible interpretation#!", N);
1555 -- Disambiguation has succeeded. Skip the remaining
1559 Expr_Type := It1.Typ;
1561 while Present (It.Typ) loop
1562 Get_Next_Interp (I, It);
1567 -- We have a matching interpretation, Expr_Type is the
1568 -- type from this interpretation, and Seen is the entity.
1570 -- For an operator, just set the entity name. The type will
1571 -- be set by the specific operator resolution routine.
1573 if Nkind (N) in N_Op then
1574 Set_Entity (N, Seen);
1575 Generate_Reference (Seen, N);
1577 elsif Nkind (N) = N_Character_Literal then
1578 Set_Etype (N, Expr_Type);
1580 -- For an explicit dereference, attribute reference, range,
1581 -- short-circuit form (which is not an operator node),
1582 -- or a call with a name that is an explicit dereference,
1583 -- there is nothing to be done at this point.
1585 elsif Nkind (N) = N_Explicit_Dereference
1586 or else Nkind (N) = N_Attribute_Reference
1587 or else Nkind (N) = N_And_Then
1588 or else Nkind (N) = N_Indexed_Component
1589 or else Nkind (N) = N_Or_Else
1590 or else Nkind (N) = N_Range
1591 or else Nkind (N) = N_Selected_Component
1592 or else Nkind (N) = N_Slice
1593 or else Nkind (Name (N)) = N_Explicit_Dereference
1597 -- For procedure or function calls, set the type of the
1598 -- name, and also the entity pointer for the prefix
1600 elsif (Nkind (N) = N_Procedure_Call_Statement
1601 or else Nkind (N) = N_Function_Call)
1602 and then (Is_Entity_Name (Name (N))
1603 or else Nkind (Name (N)) = N_Operator_Symbol)
1605 Set_Etype (Name (N), Expr_Type);
1606 Set_Entity (Name (N), Seen);
1607 Generate_Reference (Seen, Name (N));
1609 elsif Nkind (N) = N_Function_Call
1610 and then Nkind (Name (N)) = N_Selected_Component
1612 Set_Etype (Name (N), Expr_Type);
1613 Set_Entity (Selector_Name (Name (N)), Seen);
1614 Generate_Reference (Seen, Selector_Name (Name (N)));
1616 -- For all other cases, just set the type of the Name
1619 Set_Etype (Name (N), Expr_Type);
1622 -- Here if interpetation is incompatible with context type
1625 if Debug_Flag_V then
1626 Write_Str (" intepretation incompatible with context");
1631 -- Move to next interpretation
1633 exit Interp_Loop when not Present (It.Typ);
1635 Get_Next_Interp (I, It);
1636 end loop Interp_Loop;
1639 -- At this stage Found indicates whether or not an acceptable
1640 -- interpretation exists. If not, then we have an error, except
1641 -- that if the context is Any_Type as a result of some other error,
1642 -- then we suppress the error report.
1645 if Typ /= Any_Type then
1647 -- If type we are looking for is Void, then this is the
1648 -- procedure call case, and the error is simply that what
1649 -- we gave is not a procedure name (we think of procedure
1650 -- calls as expressions with types internally, but the user
1651 -- doesn't think of them this way!)
1653 if Typ = Standard_Void_Type then
1654 Error_Msg_N ("expect procedure name in procedure call", N);
1657 -- Otherwise we do have a subexpression with the wrong type
1659 -- Check for the case of an allocator which uses an access
1660 -- type instead of the designated type. This is a common
1661 -- error and we specialize the message, posting an error
1662 -- on the operand of the allocator, complaining that we
1663 -- expected the designated type of the allocator.
1665 elsif Nkind (N) = N_Allocator
1666 and then Ekind (Typ) in Access_Kind
1667 and then Ekind (Etype (N)) in Access_Kind
1668 and then Designated_Type (Etype (N)) = Typ
1670 Wrong_Type (Expression (N), Designated_Type (Typ));
1673 -- Check for an aggregate. Sometimes we can get bogus
1674 -- aggregates from misuse of parentheses, and we are
1675 -- about to complain about the aggregate without even
1676 -- looking inside it.
1678 -- Instead, if we have an aggregate of type Any_Composite,
1679 -- then analyze and resolve the component fields, and then
1680 -- only issue another message if we get no errors doing
1681 -- this (otherwise assume that the errors in the aggregate
1682 -- caused the problem).
1684 elsif Nkind (N) = N_Aggregate
1685 and then Etype (N) = Any_Composite
1688 -- Disable expansion in any case. If there is a type mismatch
1689 -- it may be fatal to try to expand the aggregate. The flag
1690 -- would otherwise be set to false when the error is posted.
1692 Expander_Active := False;
1695 procedure Check_Aggr (Aggr : Node_Id);
1696 -- Check one aggregate, and set Found to True if we
1697 -- have a definite error in any of its elements
1699 procedure Check_Elmt (Aelmt : Node_Id);
1700 -- Check one element of aggregate and set Found to
1701 -- True if we definitely have an error in the element.
1703 procedure Check_Aggr (Aggr : Node_Id) is
1707 if Present (Expressions (Aggr)) then
1708 Elmt := First (Expressions (Aggr));
1709 while Present (Elmt) loop
1715 if Present (Component_Associations (Aggr)) then
1716 Elmt := First (Component_Associations (Aggr));
1717 while Present (Elmt) loop
1718 Check_Elmt (Expression (Elmt));
1724 procedure Check_Elmt (Aelmt : Node_Id) is
1726 -- If we have a nested aggregate, go inside it (to
1727 -- attempt a naked analyze-resolve of the aggregate
1728 -- can cause undesirable cascaded errors). Do not
1729 -- resolve expression if it needs a type from context,
1730 -- as for integer * fixed expression.
1732 if Nkind (Aelmt) = N_Aggregate then
1738 if not Is_Overloaded (Aelmt)
1739 and then Etype (Aelmt) /= Any_Fixed
1741 Resolve (Aelmt, Etype (Aelmt));
1744 if Etype (Aelmt) = Any_Type then
1755 -- If an error message was issued already, Found got reset
1756 -- to True, so if it is still False, issue the standard
1757 -- Wrong_Type message.
1760 if Is_Overloaded (N)
1761 and then Nkind (N) = N_Function_Call
1763 Error_Msg_Node_2 := Typ;
1764 Error_Msg_NE ("no visible interpretation of&" &
1765 " matches expected type&", N, Name (N));
1767 if All_Errors_Mode then
1769 Index : Interp_Index;
1773 Error_Msg_N ("\possible interpretations:", N);
1774 Get_First_Interp (Name (N), Index, It);
1776 while Present (It.Nam) loop
1778 Error_Msg_Sloc := Sloc (It.Nam);
1779 Error_Msg_Node_2 := It.Typ;
1780 Error_Msg_NE ("\& declared#, type&",
1783 Get_Next_Interp (Index, It);
1787 Error_Msg_N ("\use -gnatf for details", N);
1790 Wrong_Type (N, Typ);
1798 -- Test if we have more than one interpretation for the context
1800 elsif Ambiguous then
1804 -- Here we have an acceptable interpretation for the context
1807 -- A user-defined operator is tranformed into a function call at
1808 -- this point, so that further processing knows that operators are
1809 -- really operators (i.e. are predefined operators). User-defined
1810 -- operators that are intrinsic are just renamings of the predefined
1811 -- ones, and need not be turned into calls either, but if they rename
1812 -- a different operator, we must transform the node accordingly.
1813 -- Instantiations of Unchecked_Conversion are intrinsic but are
1814 -- treated as functions, even if given an operator designator.
1816 if Nkind (N) in N_Op
1817 and then Present (Entity (N))
1818 and then Ekind (Entity (N)) /= E_Operator
1821 if not Is_Predefined_Op (Entity (N)) then
1822 Rewrite_Operator_As_Call (N, Entity (N));
1824 elsif Present (Alias (Entity (N))) then
1825 Rewrite_Renamed_Operator (N, Alias (Entity (N)));
1829 -- Propagate type information and normalize tree for various
1830 -- predefined operations. If the context only imposes a class of
1831 -- types, rather than a specific type, propagate the actual type
1834 if Typ = Any_Integer
1835 or else Typ = Any_Boolean
1836 or else Typ = Any_Modular
1837 or else Typ = Any_Real
1838 or else Typ = Any_Discrete
1840 Ctx_Type := Expr_Type;
1842 -- Any_Fixed is legal in a real context only if a specific
1843 -- fixed point type is imposed. If Norman Cohen can be
1844 -- confused by this, it deserves a separate message.
1847 and then Expr_Type = Any_Fixed
1849 Error_Msg_N ("Illegal context for mixed mode operation", N);
1850 Set_Etype (N, Universal_Real);
1851 Ctx_Type := Universal_Real;
1855 case N_Subexpr'(Nkind (N)) is
1857 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
1859 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
1861 when N_And_Then | N_Or_Else
1862 => Resolve_Short_Circuit (N, Ctx_Type);
1864 when N_Attribute_Reference
1865 => Resolve_Attribute (N, Ctx_Type);
1867 when N_Character_Literal
1868 => Resolve_Character_Literal (N, Ctx_Type);
1870 when N_Conditional_Expression
1871 => Resolve_Conditional_Expression (N, Ctx_Type);
1873 when N_Expanded_Name
1874 => Resolve_Entity_Name (N, Ctx_Type);
1876 when N_Extension_Aggregate
1877 => Resolve_Extension_Aggregate (N, Ctx_Type);
1879 when N_Explicit_Dereference
1880 => Resolve_Explicit_Dereference (N, Ctx_Type);
1882 when N_Function_Call
1883 => Resolve_Call (N, Ctx_Type);
1886 => Resolve_Entity_Name (N, Ctx_Type);
1888 when N_In | N_Not_In
1889 => Resolve_Membership_Op (N, Ctx_Type);
1891 when N_Indexed_Component
1892 => Resolve_Indexed_Component (N, Ctx_Type);
1894 when N_Integer_Literal
1895 => Resolve_Integer_Literal (N, Ctx_Type);
1897 when N_Null => Resolve_Null (N, Ctx_Type);
1899 when N_Op_And | N_Op_Or | N_Op_Xor
1900 => Resolve_Logical_Op (N, Ctx_Type);
1902 when N_Op_Eq | N_Op_Ne
1903 => Resolve_Equality_Op (N, Ctx_Type);
1905 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
1906 => Resolve_Comparison_Op (N, Ctx_Type);
1908 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
1910 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
1911 N_Op_Divide | N_Op_Mod | N_Op_Rem
1913 => Resolve_Arithmetic_Op (N, Ctx_Type);
1915 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
1917 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
1919 when N_Op_Plus | N_Op_Minus | N_Op_Abs
1920 => Resolve_Unary_Op (N, Ctx_Type);
1922 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
1924 when N_Procedure_Call_Statement
1925 => Resolve_Call (N, Ctx_Type);
1927 when N_Operator_Symbol
1928 => Resolve_Operator_Symbol (N, Ctx_Type);
1930 when N_Qualified_Expression
1931 => Resolve_Qualified_Expression (N, Ctx_Type);
1933 when N_Raise_xxx_Error
1934 => Set_Etype (N, Ctx_Type);
1936 when N_Range => Resolve_Range (N, Ctx_Type);
1939 => Resolve_Real_Literal (N, Ctx_Type);
1941 when N_Reference => Resolve_Reference (N, Ctx_Type);
1943 when N_Selected_Component
1944 => Resolve_Selected_Component (N, Ctx_Type);
1946 when N_Slice => Resolve_Slice (N, Ctx_Type);
1948 when N_String_Literal
1949 => Resolve_String_Literal (N, Ctx_Type);
1951 when N_Subprogram_Info
1952 => Resolve_Subprogram_Info (N, Ctx_Type);
1954 when N_Type_Conversion
1955 => Resolve_Type_Conversion (N, Ctx_Type);
1957 when N_Unchecked_Expression =>
1958 Resolve_Unchecked_Expression (N, Ctx_Type);
1960 when N_Unchecked_Type_Conversion =>
1961 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
1965 -- If the subexpression was replaced by a non-subexpression, then
1966 -- all we do is to expand it. The only legitimate case we know of
1967 -- is converting procedure call statement to entry call statements,
1968 -- but there may be others, so we are making this test general.
1970 if Nkind (N) not in N_Subexpr then
1971 Debug_A_Exit ("resolving ", N, " (done)");
1976 -- The expression is definitely NOT overloaded at this point, so
1977 -- we reset the Is_Overloaded flag to avoid any confusion when
1978 -- reanalyzing the node.
1980 Set_Is_Overloaded (N, False);
1982 -- Freeze expression type, entity if it is a name, and designated
1983 -- type if it is an allocator (RM 13.14(9,10)).
1985 -- Now that the resolution of the type of the node is complete,
1986 -- and we did not detect an error, we can expand this node. We
1987 -- skip the expand call if we are in a default expression, see
1988 -- section "Handling of Default Expressions" in Sem spec.
1990 Debug_A_Exit ("resolving ", N, " (done)");
1992 -- We unconditionally freeze the expression, even if we are in
1993 -- default expression mode (the Freeze_Expression routine tests
1994 -- this flag and only freezes static types if it is set).
1996 Freeze_Expression (N);
1998 -- Now we can do the expansion
2005 -- Version with check(s) suppressed
2007 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2009 if Suppress = All_Checks then
2011 Svg : constant Suppress_Record := Scope_Suppress;
2014 Scope_Suppress := (others => True);
2016 Scope_Suppress := Svg;
2021 Svg : constant Boolean := Get_Scope_Suppress (Suppress);
2024 Set_Scope_Suppress (Suppress, True);
2026 Set_Scope_Suppress (Suppress, Svg);
2031 ---------------------
2032 -- Resolve_Actuals --
2033 ---------------------
2035 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2036 Loc : constant Source_Ptr := Sloc (N);
2041 Prev : Node_Id := Empty;
2043 procedure Insert_Default;
2044 -- If the actual is missing in a call, insert in the actuals list
2045 -- an instance of the default expression. The insertion is always
2046 -- a named association.
2048 --------------------
2049 -- Insert_Default --
2050 --------------------
2052 procedure Insert_Default is
2057 -- Note that we do a full New_Copy_Tree, so that any associated
2058 -- Itypes are properly copied. This may not be needed any more,
2059 -- but it does no harm as a safety measure! Defaults of a generic
2060 -- formal may be out of bounds of the corresponding actual (see
2061 -- cc1311b) and an additional check may be required.
2063 if Present (Default_Value (F)) then
2065 Actval := New_Copy_Tree (Default_Value (F),
2066 New_Scope => Current_Scope, New_Sloc => Loc);
2068 if Is_Concurrent_Type (Scope (Nam))
2069 and then Has_Discriminants (Scope (Nam))
2071 Replace_Actual_Discriminants (N, Actval);
2074 if Is_Overloadable (Nam)
2075 and then Present (Alias (Nam))
2077 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2078 and then not Is_Tagged_Type (Etype (F))
2080 -- If default is a real literal, do not introduce a
2081 -- conversion whose effect may depend on the run-time
2082 -- size of universal real.
2084 if Nkind (Actval) = N_Real_Literal then
2085 Set_Etype (Actval, Base_Type (Etype (F)));
2087 Actval := Unchecked_Convert_To (Etype (F), Actval);
2091 if Is_Scalar_Type (Etype (F)) then
2092 Enable_Range_Check (Actval);
2095 Set_Parent (Actval, N);
2096 Analyze_And_Resolve (Actval, Etype (Actval));
2098 Set_Parent (Actval, N);
2100 -- Resolve aggregates with their base type, to avoid scope
2101 -- anomalies: the subtype was first built in the suprogram
2102 -- declaration, and the current call may be nested.
2104 if Nkind (Actval) = N_Aggregate
2105 and then Has_Discriminants (Etype (Actval))
2107 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2109 Analyze_And_Resolve (Actval, Etype (Actval));
2113 -- If default is a tag indeterminate function call, propagate
2114 -- tag to obtain proper dispatching.
2116 if Is_Controlling_Formal (F)
2117 and then Nkind (Default_Value (F)) = N_Function_Call
2119 Set_Is_Controlling_Actual (Actval);
2123 -- Missing argument in call, nothing to insert.
2127 -- If the default expression raises constraint error, then just
2128 -- silently replace it with an N_Raise_Constraint_Error node,
2129 -- since we already gave the warning on the subprogram spec.
2131 if Raises_Constraint_Error (Actval) then
2133 Make_Raise_Constraint_Error (Loc));
2134 Set_Raises_Constraint_Error (Actval);
2135 Set_Etype (Actval, Etype (F));
2139 Make_Parameter_Association (Loc,
2140 Explicit_Actual_Parameter => Actval,
2141 Selector_Name => Make_Identifier (Loc, Chars (F)));
2143 -- Case of insertion is first named actual
2145 if No (Prev) or else
2146 Nkind (Parent (Prev)) /= N_Parameter_Association
2148 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2149 Set_First_Named_Actual (N, Actval);
2152 if not Present (Parameter_Associations (N)) then
2153 Set_Parameter_Associations (N, New_List (Assoc));
2155 Append (Assoc, Parameter_Associations (N));
2159 Insert_After (Prev, Assoc);
2162 -- Case of insertion is not first named actual
2165 Set_Next_Named_Actual
2166 (Assoc, Next_Named_Actual (Parent (Prev)));
2167 Set_Next_Named_Actual (Parent (Prev), Actval);
2168 Append (Assoc, Parameter_Associations (N));
2171 Mark_Rewrite_Insertion (Assoc);
2172 Mark_Rewrite_Insertion (Actval);
2177 -- Start of processing for Resolve_Actuals
2180 A := First_Actual (N);
2181 F := First_Formal (Nam);
2183 while Present (F) loop
2186 and then (Nkind (Parent (A)) /= N_Parameter_Association
2188 Chars (Selector_Name (Parent (A))) = Chars (F))
2190 -- If the formal is Out or In_Out, do not resolve and expand the
2191 -- conversion, because it is subsequently expanded into explicit
2192 -- temporaries and assignments. However, the object of the
2193 -- conversion can be resolved. An exception is the case of
2194 -- a tagged type conversion with a class-wide actual. In that
2195 -- case we want the tag check to occur and no temporary will
2196 -- will be needed (no representation change can occur) and
2197 -- the parameter is passed by reference, so we go ahead and
2198 -- resolve the type conversion.
2200 if Ekind (F) /= E_In_Parameter
2201 and then Nkind (A) = N_Type_Conversion
2202 and then not Is_Class_Wide_Type (Etype (Expression (A)))
2204 if Conversion_OK (A)
2205 or else Valid_Conversion (A, Etype (A), Expression (A))
2207 Resolve (Expression (A), Etype (Expression (A)));
2211 Resolve (A, Etype (F));
2217 if Ekind (F) /= E_In_Parameter
2218 and then not Is_OK_Variable_For_Out_Formal (A)
2220 -- Specialize error message for protected procedure call
2221 -- within function call of the same protected object.
2223 if Is_Entity_Name (A)
2224 and then Chars (Entity (A)) = Name_uObject
2225 and then Ekind (Current_Scope) = E_Function
2226 and then Convention (Current_Scope) = Convention_Protected
2227 and then Ekind (Nam) /= E_Function
2229 Error_Msg_N ("within protected function, protected " &
2230 "object is constant", A);
2231 Error_Msg_N ("\cannot call operation that may modify it", A);
2233 Error_Msg_NE ("actual for& must be a variable", A, F);
2237 if Ekind (F) /= E_Out_Parameter then
2238 Check_Unset_Reference (A);
2241 and then Is_Entity_Name (A)
2242 and then Ekind (Entity (A)) = E_Out_Parameter
2244 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2248 -- Apply appropriate range checks for in, out, and in-out
2249 -- parameters. Out and in-out parameters also need a separate
2250 -- check, if there is a type conversion, to make sure the return
2251 -- value meets the constraints of the variable before the
2254 -- Gigi looks at the check flag and uses the appropriate types.
2255 -- For now since one flag is used there is an optimization which
2256 -- might not be done in the In Out case since Gigi does not do
2257 -- any analysis. More thought required about this ???
2259 if Ekind (F) = E_In_Parameter
2260 or else Ekind (F) = E_In_Out_Parameter
2262 if Is_Scalar_Type (Etype (A)) then
2263 Apply_Scalar_Range_Check (A, F_Typ);
2265 elsif Is_Array_Type (Etype (A)) then
2266 Apply_Length_Check (A, F_Typ);
2268 elsif Is_Record_Type (F_Typ)
2269 and then Has_Discriminants (F_Typ)
2270 and then Is_Constrained (F_Typ)
2271 and then (not Is_Derived_Type (F_Typ)
2272 or else Comes_From_Source (Nam))
2274 Apply_Discriminant_Check (A, F_Typ);
2276 elsif Is_Access_Type (F_Typ)
2277 and then Is_Array_Type (Designated_Type (F_Typ))
2278 and then Is_Constrained (Designated_Type (F_Typ))
2280 Apply_Length_Check (A, F_Typ);
2282 elsif Is_Access_Type (F_Typ)
2283 and then Has_Discriminants (Designated_Type (F_Typ))
2284 and then Is_Constrained (Designated_Type (F_Typ))
2286 Apply_Discriminant_Check (A, F_Typ);
2289 Apply_Range_Check (A, F_Typ);
2293 if Ekind (F) = E_Out_Parameter
2294 or else Ekind (F) = E_In_Out_Parameter
2297 if Nkind (A) = N_Type_Conversion then
2298 if Is_Scalar_Type (A_Typ) then
2299 Apply_Scalar_Range_Check
2300 (Expression (A), Etype (Expression (A)), A_Typ);
2303 (Expression (A), Etype (Expression (A)), A_Typ);
2307 if Is_Scalar_Type (F_Typ) then
2308 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2310 elsif Is_Array_Type (F_Typ)
2311 and then Ekind (F) = E_Out_Parameter
2313 Apply_Length_Check (A, F_Typ);
2316 Apply_Range_Check (A, A_Typ, F_Typ);
2321 -- An actual associated with an access parameter is implicitly
2322 -- converted to the anonymous access type of the formal and
2323 -- must satisfy the legality checks for access conversions.
2325 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2326 if not Valid_Conversion (A, F_Typ, A) then
2328 ("invalid implicit conversion for access parameter", A);
2332 -- Check bad case of atomic/volatile argument (RM C.6(12))
2334 if Is_By_Reference_Type (Etype (F))
2335 and then Comes_From_Source (N)
2337 if Is_Atomic_Object (A)
2338 and then not Is_Atomic (Etype (F))
2341 ("cannot pass atomic argument to non-atomic formal",
2344 elsif Is_Volatile_Object (A)
2345 and then not Is_Volatile (Etype (F))
2348 ("cannot pass volatile argument to non-volatile formal",
2353 -- Check that subprograms don't have improper controlling
2354 -- arguments (RM 3.9.2 (9))
2356 if Is_Controlling_Formal (F) then
2357 Set_Is_Controlling_Actual (A);
2358 elsif Nkind (A) = N_Explicit_Dereference then
2359 Validate_Remote_Access_To_Class_Wide_Type (A);
2362 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2363 and then not Is_Class_Wide_Type (F_Typ)
2364 and then not Is_Controlling_Formal (F)
2366 Error_Msg_N ("class-wide argument not allowed here!", A);
2367 if Is_Subprogram (Nam) then
2368 Error_Msg_Node_2 := F_Typ;
2370 ("& is not a primitive operation of &!", A, Nam);
2373 elsif Is_Access_Type (A_Typ)
2374 and then Is_Access_Type (F_Typ)
2375 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2376 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2377 or else (Nkind (A) = N_Attribute_Reference
2378 and then Is_Class_Wide_Type (Etype (Prefix (A)))))
2379 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2380 and then not Is_Controlling_Formal (F)
2383 ("access to class-wide argument not allowed here!", A);
2384 if Is_Subprogram (Nam) then
2385 Error_Msg_Node_2 := Designated_Type (F_Typ);
2387 ("& is not a primitive operation of &!", A, Nam);
2393 -- If it is a named association, treat the selector_name as
2394 -- a proper identifier, and mark the corresponding entity.
2396 if Nkind (Parent (A)) = N_Parameter_Association then
2397 Set_Entity (Selector_Name (Parent (A)), F);
2398 Generate_Reference (F, Selector_Name (Parent (A)));
2399 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2400 Generate_Reference (F_Typ, N, ' ');
2413 end Resolve_Actuals;
2415 -----------------------
2416 -- Resolve_Allocator --
2417 -----------------------
2419 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2420 E : constant Node_Id := Expression (N);
2422 Discrim : Entity_Id;
2427 -- Replace general access with specific type
2429 if Ekind (Etype (N)) = E_Allocator_Type then
2430 Set_Etype (N, Base_Type (Typ));
2433 if Is_Abstract (Typ) then
2434 Error_Msg_N ("type of allocator cannot be abstract", N);
2437 -- For qualified expression, resolve the expression using the
2438 -- given subtype (nothing to do for type mark, subtype indication)
2440 if Nkind (E) = N_Qualified_Expression then
2441 if Is_Class_Wide_Type (Etype (E))
2442 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2445 ("class-wide allocator not allowed for this access type", N);
2448 Resolve (Expression (E), Etype (E));
2449 Check_Unset_Reference (Expression (E));
2451 -- For a subtype mark or subtype indication, freeze the subtype
2454 Freeze_Expression (E);
2456 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2458 ("initialization required for access-to-constant allocator", N);
2461 -- A special accessibility check is needed for allocators that
2462 -- constrain access discriminants. The level of the type of the
2463 -- expression used to contrain an access discriminant cannot be
2464 -- deeper than the type of the allocator (in constrast to access
2465 -- parameters, where the level of the actual can be arbitrary).
2466 -- We can't use Valid_Conversion to perform this check because
2467 -- in general the type of the allocator is unrelated to the type
2468 -- of the access discriminant. Note that specialized checks are
2469 -- needed for the cases of a constraint expression which is an
2470 -- access attribute or an access discriminant.
2472 if Nkind (Original_Node (E)) = N_Subtype_Indication
2473 and then Ekind (Typ) /= E_Anonymous_Access_Type
2475 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2477 if Has_Discriminants (Subtyp) then
2478 Discrim := First_Discriminant (Base_Type (Subtyp));
2479 Constr := First (Constraints (Constraint (Original_Node (E))));
2481 while Present (Discrim) and then Present (Constr) loop
2482 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
2483 if Nkind (Constr) = N_Discriminant_Association then
2484 Disc_Exp := Original_Node (Expression (Constr));
2486 Disc_Exp := Original_Node (Constr);
2489 if Type_Access_Level (Etype (Disc_Exp))
2490 > Type_Access_Level (Typ)
2493 ("operand type has deeper level than allocator type",
2496 elsif Nkind (Disc_Exp) = N_Attribute_Reference
2497 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
2499 and then Object_Access_Level (Prefix (Disc_Exp))
2500 > Type_Access_Level (Typ)
2503 ("prefix of attribute has deeper level than"
2504 & " allocator type", Disc_Exp);
2506 -- When the operand is an access discriminant the check
2507 -- is against the level of the prefix object.
2509 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
2510 and then Nkind (Disc_Exp) = N_Selected_Component
2511 and then Object_Access_Level (Prefix (Disc_Exp))
2512 > Type_Access_Level (Typ)
2515 ("access discriminant has deeper level than"
2516 & " allocator type", Disc_Exp);
2519 Next_Discriminant (Discrim);
2526 -- Check for allocation from an empty storage pool
2528 if No_Pool_Assigned (Typ) then
2530 Loc : constant Source_Ptr := Sloc (N);
2533 Error_Msg_N ("?allocation from empty storage pool!", N);
2534 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
2536 Make_Raise_Storage_Error (Loc));
2539 end Resolve_Allocator;
2541 ---------------------------
2542 -- Resolve_Arithmetic_Op --
2543 ---------------------------
2545 -- Used for resolving all arithmetic operators except exponentiation
2547 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
2548 L : constant Node_Id := Left_Opnd (N);
2549 R : constant Node_Id := Right_Opnd (N);
2551 TL : Entity_Id := Base_Type (Etype (L));
2552 TR : Entity_Id := Base_Type (Etype (R));
2554 B_Typ : constant Entity_Id := Base_Type (Typ);
2555 -- We do the resolution using the base type, because intermediate values
2556 -- in expressions always are of the base type, not a subtype of it.
2558 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
2559 -- Return True iff given type is Integer or universal real/integer
2561 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
2562 -- Choose type of integer literal in fixed-point operation to conform
2563 -- to available fixed-point type. T is the type of the other operand,
2564 -- which is needed to determine the expected type of N.
2566 procedure Set_Operand_Type (N : Node_Id);
2567 -- Set operand type to T if universal
2569 function Universal_Interpretation (N : Node_Id) return Entity_Id;
2570 -- Find universal type of operand, if any.
2572 -----------------------------
2573 -- Is_Integer_Or_Universal --
2574 -----------------------------
2576 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
2578 Index : Interp_Index;
2582 if not Is_Overloaded (N) then
2584 return Base_Type (T) = Base_Type (Standard_Integer)
2585 or else T = Universal_Integer
2586 or else T = Universal_Real;
2588 Get_First_Interp (N, Index, It);
2590 while Present (It.Typ) loop
2592 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
2593 or else It.Typ = Universal_Integer
2594 or else It.Typ = Universal_Real
2599 Get_Next_Interp (Index, It);
2604 end Is_Integer_Or_Universal;
2606 ----------------------------
2607 -- Set_Mixed_Mode_Operand --
2608 ----------------------------
2610 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
2611 Index : Interp_Index;
2615 if Universal_Interpretation (N) = Universal_Integer then
2617 -- A universal integer literal is resolved as standard integer
2618 -- except in the case of a fixed-point result, where we leave
2619 -- it as universal (to be handled by Exp_Fixd later on)
2621 if Is_Fixed_Point_Type (T) then
2622 Resolve (N, Universal_Integer);
2624 Resolve (N, Standard_Integer);
2627 elsif Universal_Interpretation (N) = Universal_Real
2628 and then (T = Base_Type (Standard_Integer)
2629 or else T = Universal_Integer
2630 or else T = Universal_Real)
2632 -- A universal real can appear in a fixed-type context. We resolve
2633 -- the literal with that context, even though this might raise an
2634 -- exception prematurely (the other operand may be zero).
2638 elsif Etype (N) = Base_Type (Standard_Integer)
2639 and then T = Universal_Real
2640 and then Is_Overloaded (N)
2642 -- Integer arg in mixed-mode operation. Resolve with universal
2643 -- type, in case preference rule must be applied.
2645 Resolve (N, Universal_Integer);
2648 and then B_Typ /= Universal_Fixed
2650 -- Not a mixed-mode operation. Resolve with context.
2654 elsif Etype (N) = Any_Fixed then
2656 -- N may itself be a mixed-mode operation, so use context type.
2660 elsif Is_Fixed_Point_Type (T)
2661 and then B_Typ = Universal_Fixed
2662 and then Is_Overloaded (N)
2664 -- Must be (fixed * fixed) operation, operand must have one
2665 -- compatible interpretation.
2667 Resolve (N, Any_Fixed);
2669 elsif Is_Fixed_Point_Type (B_Typ)
2670 and then (T = Universal_Real
2671 or else Is_Fixed_Point_Type (T))
2672 and then Is_Overloaded (N)
2674 -- C * F(X) in a fixed context, where C is a real literal or a
2675 -- fixed-point expression. F must have either a fixed type
2676 -- interpretation or an integer interpretation, but not both.
2678 Get_First_Interp (N, Index, It);
2680 while Present (It.Typ) loop
2682 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
2684 if Analyzed (N) then
2685 Error_Msg_N ("ambiguous operand in fixed operation", N);
2687 Resolve (N, Standard_Integer);
2690 elsif Is_Fixed_Point_Type (It.Typ) then
2692 if Analyzed (N) then
2693 Error_Msg_N ("ambiguous operand in fixed operation", N);
2695 Resolve (N, It.Typ);
2699 Get_Next_Interp (Index, It);
2702 -- Reanalyze the literal with the fixed type of the context.
2705 Set_Analyzed (R, False);
2708 Set_Analyzed (L, False);
2713 Resolve (N, Etype (N));
2715 end Set_Mixed_Mode_Operand;
2717 ----------------------
2718 -- Set_Operand_Type --
2719 ----------------------
2721 procedure Set_Operand_Type (N : Node_Id) is
2723 if Etype (N) = Universal_Integer
2724 or else Etype (N) = Universal_Real
2728 end Set_Operand_Type;
2730 ------------------------------
2731 -- Universal_Interpretation --
2732 ------------------------------
2734 function Universal_Interpretation (N : Node_Id) return Entity_Id is
2735 Index : Interp_Index;
2739 if not Is_Overloaded (N) then
2741 if Etype (N) = Universal_Integer
2742 or else Etype (N) = Universal_Real
2750 Get_First_Interp (N, Index, It);
2752 while Present (It.Typ) loop
2754 if It.Typ = Universal_Integer
2755 or else It.Typ = Universal_Real
2760 Get_Next_Interp (Index, It);
2765 end Universal_Interpretation;
2767 -- Start of processing for Resolve_Arithmetic_Op
2770 if Comes_From_Source (N)
2771 and then Ekind (Entity (N)) = E_Function
2772 and then Is_Imported (Entity (N))
2773 and then Present (First_Rep_Item (Entity (N)))
2775 Resolve_Intrinsic_Operator (N, Typ);
2778 -- Special-case for mixed-mode universal expressions or fixed point
2779 -- type operation: each argument is resolved separately. The same
2780 -- treatment is required if one of the operands of a fixed point
2781 -- operation is universal real, since in this case we don't do a
2782 -- conversion to a specific fixed-point type (instead the expander
2783 -- takes care of the case).
2785 elsif (B_Typ = Universal_Integer
2786 or else B_Typ = Universal_Real)
2787 and then Present (Universal_Interpretation (L))
2788 and then Present (Universal_Interpretation (R))
2790 Resolve (L, Universal_Interpretation (L));
2791 Resolve (R, Universal_Interpretation (R));
2792 Set_Etype (N, B_Typ);
2794 elsif (B_Typ = Universal_Real
2795 or else Etype (N) = Universal_Fixed
2796 or else (Etype (N) = Any_Fixed
2797 and then Is_Fixed_Point_Type (B_Typ))
2798 or else (Is_Fixed_Point_Type (B_Typ)
2799 and then (Is_Integer_Or_Universal (L)
2801 Is_Integer_Or_Universal (R))))
2802 and then (Nkind (N) = N_Op_Multiply or else
2803 Nkind (N) = N_Op_Divide)
2805 if TL = Universal_Integer or else TR = Universal_Integer then
2806 Check_For_Visible_Operator (N, B_Typ);
2809 -- If context is a fixed type and one operand is integer, the
2810 -- other is resolved with the type of the context.
2812 if Is_Fixed_Point_Type (B_Typ)
2813 and then (Base_Type (TL) = Base_Type (Standard_Integer)
2814 or else TL = Universal_Integer)
2819 elsif Is_Fixed_Point_Type (B_Typ)
2820 and then (Base_Type (TR) = Base_Type (Standard_Integer)
2821 or else TR = Universal_Integer)
2827 Set_Mixed_Mode_Operand (L, TR);
2828 Set_Mixed_Mode_Operand (R, TL);
2831 if Etype (N) = Universal_Fixed
2832 or else Etype (N) = Any_Fixed
2834 if B_Typ = Universal_Fixed
2835 and then Nkind (Parent (N)) /= N_Type_Conversion
2836 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
2839 ("type cannot be determined from context!", N);
2841 ("\explicit conversion to result type required", N);
2843 Set_Etype (L, Any_Type);
2844 Set_Etype (R, Any_Type);
2848 and then Etype (N) = Universal_Fixed
2849 and then Nkind (Parent (N)) /= N_Type_Conversion
2850 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
2853 ("(Ada 83) fixed-point operation " &
2854 "needs explicit conversion",
2858 Set_Etype (N, B_Typ);
2861 elsif Is_Fixed_Point_Type (B_Typ)
2862 and then (Is_Integer_Or_Universal (L)
2863 or else Nkind (L) = N_Real_Literal
2864 or else Nkind (R) = N_Real_Literal
2866 Is_Integer_Or_Universal (R))
2868 Set_Etype (N, B_Typ);
2870 elsif Etype (N) = Any_Fixed then
2872 -- If no previous errors, this is only possible if one operand
2873 -- is overloaded and the context is universal. Resolve as such.
2875 Set_Etype (N, B_Typ);
2879 if (TL = Universal_Integer or else TL = Universal_Real)
2880 and then (TR = Universal_Integer or else TR = Universal_Real)
2882 Check_For_Visible_Operator (N, B_Typ);
2885 -- If the context is Universal_Fixed and the operands are also
2886 -- universal fixed, this is an error, unless there is only one
2887 -- applicable fixed_point type (usually duration).
2889 if B_Typ = Universal_Fixed
2890 and then Etype (L) = Universal_Fixed
2892 T := Unique_Fixed_Point_Type (N);
2894 if T = Any_Type then
2907 -- If one of the arguments was resolved to a non-universal type.
2908 -- label the result of the operation itself with the same type.
2909 -- Do the same for the universal argument, if any.
2911 T := Intersect_Types (L, R);
2912 Set_Etype (N, Base_Type (T));
2913 Set_Operand_Type (L);
2914 Set_Operand_Type (R);
2917 Generate_Operator_Reference (N);
2918 Eval_Arithmetic_Op (N);
2920 -- Set overflow and division checking bit. Much cleverer code needed
2921 -- here eventually and perhaps the Resolve routines should be separated
2922 -- for the various arithmetic operations, since they will need
2923 -- different processing. ???
2925 if Nkind (N) in N_Op then
2926 if not Overflow_Checks_Suppressed (Etype (N)) then
2927 Set_Do_Overflow_Check (N);
2930 if (Nkind (N) = N_Op_Divide
2931 or else Nkind (N) = N_Op_Rem
2932 or else Nkind (N) = N_Op_Mod)
2933 and then not Division_Checks_Suppressed (Etype (N))
2935 Set_Do_Division_Check (N);
2939 Check_Unset_Reference (L);
2940 Check_Unset_Reference (R);
2942 end Resolve_Arithmetic_Op;
2948 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
2949 Loc : constant Source_Ptr := Sloc (N);
2950 Subp : constant Node_Id := Name (N);
2958 -- The context imposes a unique interpretation with type Typ on
2959 -- a procedure or function call. Find the entity of the subprogram
2960 -- that yields the expected type, and propagate the corresponding
2961 -- formal constraints on the actuals. The caller has established
2962 -- that an interpretation exists, and emitted an error if not unique.
2964 -- First deal with the case of a call to an access-to-subprogram,
2965 -- dereference made explicit in Analyze_Call.
2967 if Ekind (Etype (Subp)) = E_Subprogram_Type then
2969 if not Is_Overloaded (Subp) then
2970 Nam := Etype (Subp);
2973 -- Find the interpretation whose type (a subprogram type)
2974 -- has a return type that is compatible with the context.
2975 -- Analysis of the node has established that one exists.
2977 Get_First_Interp (Subp, I, It);
2980 while Present (It.Typ) loop
2982 if Covers (Typ, Etype (It.Typ)) then
2987 Get_Next_Interp (I, It);
2991 raise Program_Error;
2995 -- If the prefix is not an entity, then resolve it
2997 if not Is_Entity_Name (Subp) then
2998 Resolve (Subp, Nam);
3001 -- If this is a procedure call which is really an entry call, do
3002 -- the conversion of the procedure call to an entry call. Protected
3003 -- operations use the same circuitry because the name in the call
3004 -- can be an arbitrary expression with special resolution rules.
3006 elsif Nkind (Subp) = N_Selected_Component
3007 or else Nkind (Subp) = N_Indexed_Component
3008 or else (Is_Entity_Name (Subp)
3009 and then Ekind (Entity (Subp)) = E_Entry)
3011 Resolve_Entry_Call (N, Typ);
3012 Check_Elab_Call (N);
3015 -- Normal subprogram call with name established in Resolve
3017 elsif not (Is_Type (Entity (Subp))) then
3018 Nam := Entity (Subp);
3019 Set_Entity_With_Style_Check (Subp, Nam);
3020 Generate_Reference (Nam, Subp);
3022 -- Otherwise we must have the case of an overloaded call
3025 pragma Assert (Is_Overloaded (Subp));
3026 Nam := Empty; -- We know that it will be assigned in loop below.
3028 Get_First_Interp (Subp, I, It);
3030 while Present (It.Typ) loop
3031 if Covers (Typ, It.Typ) then
3033 Set_Entity_With_Style_Check (Subp, Nam);
3034 Generate_Reference (Nam, Subp);
3038 Get_Next_Interp (I, It);
3042 -- Check that a call to Current_Task does not occur in an entry body
3044 if Is_RTE (Nam, RE_Current_Task) then
3054 if Nkind (P) = N_Entry_Body then
3056 ("& should not be used in entry body ('R'M C.7(17))",
3064 -- Check that a procedure call does not occur in the context
3065 -- of the entry call statement of a conditional or timed
3066 -- entry call. Note that the case of a call to a subprogram
3067 -- renaming of an entry will also be rejected. The test
3068 -- for N not being an N_Entry_Call_Statement is defensive,
3069 -- covering the possibility that the processing of entry
3070 -- calls might reach this point due to later modifications
3071 -- of the code above.
3073 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3074 and then Nkind (N) /= N_Entry_Call_Statement
3075 and then Entry_Call_Statement (Parent (N)) = N
3077 Error_Msg_N ("entry call required in select statement", N);
3080 -- Freeze the subprogram name if not in default expression. Note
3081 -- that we freeze procedure calls as well as function calls.
3082 -- Procedure calls are not frozen according to the rules (RM
3083 -- 13.14(14)) because it is impossible to have a procedure call to
3084 -- a non-frozen procedure in pure Ada, but in the code that we
3085 -- generate in the expander, this rule needs extending because we
3086 -- can generate procedure calls that need freezing.
3088 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3089 Freeze_Expression (Subp);
3092 -- For a predefined operator, the type of the result is the type
3093 -- imposed by context, except for a predefined operation on universal
3094 -- fixed. Otherwise The type of the call is the type returned by the
3095 -- subprogram being called.
3097 if Is_Predefined_Op (Nam) then
3099 if Etype (N) /= Universal_Fixed then
3103 -- If the subprogram returns an array type, and the context
3104 -- requires the component type of that array type, the node is
3105 -- really an indexing of the parameterless call. Resolve as such.
3107 elsif Needs_No_Actuals (Nam)
3109 ((Is_Array_Type (Etype (Nam))
3110 and then Covers (Typ, Component_Type (Etype (Nam))))
3111 or else (Is_Access_Type (Etype (Nam))
3112 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3115 Component_Type (Designated_Type (Etype (Nam))))))
3118 Index_Node : Node_Id;
3121 Check_Elab_Call (N);
3123 if Component_Type (Etype (Nam)) /= Any_Type then
3125 Make_Indexed_Component (Loc,
3127 Make_Function_Call (Loc,
3128 Name => New_Occurrence_Of (Nam, Loc)),
3129 Expressions => Parameter_Associations (N));
3131 -- Since we are correcting a node classification error made by
3132 -- the parser, we call Replace rather than Rewrite.
3134 Replace (N, Index_Node);
3135 Set_Etype (Prefix (N), Etype (Nam));
3137 Resolve_Indexed_Component (N, Typ);
3144 Set_Etype (N, Etype (Nam));
3147 -- In the case where the call is to an overloaded subprogram, Analyze
3148 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3149 -- such a case Normalize_Actuals needs to be called once more to order
3150 -- the actuals correctly. Otherwise the call will have the ordering
3151 -- given by the last overloaded subprogram whether this is the correct
3152 -- one being called or not.
3154 if Is_Overloaded (Subp) then
3155 Normalize_Actuals (N, Nam, False, Norm_OK);
3156 pragma Assert (Norm_OK);
3159 -- In any case, call is fully resolved now. Reset Overload flag, to
3160 -- prevent subsequent overload resolution if node is analyzed again
3162 Set_Is_Overloaded (Subp, False);
3163 Set_Is_Overloaded (N, False);
3165 -- If we are calling the current subprogram from immediately within
3166 -- its body, then that is the case where we can sometimes detect
3167 -- cases of infinite recursion statically. Do not try this in case
3168 -- restriction No_Recursion is in effect anyway.
3170 Scop := Current_Scope;
3173 and then not Restrictions (No_Recursion)
3174 and then Check_Infinite_Recursion (N)
3176 -- Here we detected and flagged an infinite recursion, so we do
3177 -- not need to test the case below for further warnings.
3181 -- If call is to immediately containing subprogram, then check for
3182 -- the case of a possible run-time detectable infinite recursion.
3185 while Scop /= Standard_Standard loop
3187 -- Although in general recursion is not statically checkable,
3188 -- the case of calling an immediately containing subprogram
3189 -- is easy to catch.
3191 Check_Restriction (No_Recursion, N);
3193 -- If the recursive call is to a parameterless procedure, then
3194 -- even if we can't statically detect infinite recursion, this
3195 -- is pretty suspicious, and we output a warning. Furthermore,
3196 -- we will try later to detect some cases here at run time by
3197 -- expanding checking code (see Detect_Infinite_Recursion in
3198 -- package Exp_Ch6).
3199 -- If the recursive call is within a handler we do not emit a
3200 -- warning, because this is a common idiom: loop until input
3201 -- is correct, catch illegal input in handler and restart.
3203 if No (First_Formal (Nam))
3204 and then Etype (Nam) = Standard_Void_Type
3205 and then not Error_Posted (N)
3206 and then Nkind (Parent (N)) /= N_Exception_Handler
3208 Set_Has_Recursive_Call (Nam);
3209 Error_Msg_N ("possible infinite recursion?", N);
3210 Error_Msg_N ("Storage_Error may be raised at run time?", N);
3216 Scop := Scope (Scop);
3220 -- If subprogram name is a predefined operator, it was given in
3221 -- functional notation. Replace call node with operator node, so
3222 -- that actuals can be resolved appropriately.
3224 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3225 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3228 elsif Present (Alias (Nam))
3229 and then Is_Predefined_Op (Alias (Nam))
3231 Resolve_Actuals (N, Nam);
3232 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3236 -- Create a transient scope if the resulting type requires it.
3237 -- There are 3 notable exceptions: in init_procs, the transient scope
3238 -- overhead is not needed and even incorrect due to the actual expansion
3239 -- of adjust calls; the second case is enumeration literal pseudo calls,
3240 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3241 -- source information functions) that do not use the secondary stack
3242 -- even though the return type is unconstrained.
3244 -- If this is an initialization call for a type whose initialization
3245 -- uses the secondary stack, we also need to create a transient scope
3246 -- for it, precisely because we will not do it within the init_proc
3250 and then Is_Type (Etype (Nam))
3251 and then Requires_Transient_Scope (Etype (Nam))
3252 and then Ekind (Nam) /= E_Enumeration_Literal
3253 and then not Within_Init_Proc
3254 and then not Is_Intrinsic_Subprogram (Nam)
3256 Establish_Transient_Scope
3257 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3259 elsif Chars (Nam) = Name_uInit_Proc
3260 and then not Within_Init_Proc
3262 Check_Initialization_Call (N, Nam);
3265 -- A protected function cannot be called within the definition of the
3266 -- enclosing protected type.
3268 if Is_Protected_Type (Scope (Nam))
3269 and then In_Open_Scopes (Scope (Nam))
3270 and then not Has_Completion (Scope (Nam))
3273 ("& cannot be called before end of protected definition", N, Nam);
3276 -- Propagate interpretation to actuals, and add default expressions
3279 if Present (First_Formal (Nam)) then
3280 Resolve_Actuals (N, Nam);
3282 -- Overloaded literals are rewritten as function calls, for
3283 -- purpose of resolution. After resolution, we can replace
3284 -- the call with the literal itself.
3286 elsif Ekind (Nam) = E_Enumeration_Literal then
3287 Copy_Node (Subp, N);
3288 Resolve_Entity_Name (N, Typ);
3290 -- Avoid validation, since it is a static function call.
3295 -- If the subprogram is a primitive operation, check whether or not
3296 -- it is a correct dispatching call.
3298 if Is_Overloadable (Nam)
3299 and then Is_Dispatching_Operation (Nam)
3301 Check_Dispatching_Call (N);
3303 -- If the subprogram is abstract, check that the call has a
3304 -- controlling argument (i.e. is dispatching) or is disptaching on
3307 if Is_Abstract (Nam)
3308 and then No (Controlling_Argument (N))
3309 and then not Is_Class_Wide_Type (Typ)
3310 and then not Is_Tag_Indeterminate (N)
3312 Error_Msg_N ("call to abstract subprogram must be dispatching", N);
3315 elsif Is_Abstract (Nam)
3316 and then not In_Instance
3318 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
3321 if Is_Intrinsic_Subprogram (Nam) then
3322 Check_Intrinsic_Call (N);
3325 -- If we fall through we definitely have a non-static call
3327 Check_Elab_Call (N);
3331 -------------------------------
3332 -- Resolve_Character_Literal --
3333 -------------------------------
3335 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3336 B_Typ : constant Entity_Id := Base_Type (Typ);
3340 -- Verify that the character does belong to the type of the context
3342 Set_Etype (N, B_Typ);
3343 Eval_Character_Literal (N);
3345 -- Wide_Character literals must always be defined, since the set of
3346 -- wide character literals is complete, i.e. if a character literal
3347 -- is accepted by the parser, then it is OK for wide character.
3349 if Root_Type (B_Typ) = Standard_Wide_Character then
3352 -- Always accept character literal for type Any_Character, which
3353 -- occurs in error situations and in comparisons of literals, both
3354 -- of which should accept all literals.
3356 elsif B_Typ = Any_Character then
3359 -- For Standard.Character or a type derived from it, check that
3360 -- the literal is in range
3362 elsif Root_Type (B_Typ) = Standard_Character then
3363 if In_Character_Range (Char_Literal_Value (N)) then
3367 -- If the entity is already set, this has already been resolved in
3368 -- a generic context, or comes from expansion. Nothing else to do.
3370 elsif Present (Entity (N)) then
3373 -- Otherwise we have a user defined character type, and we can use
3374 -- the standard visibility mechanisms to locate the referenced entity
3377 C := Current_Entity (N);
3379 while Present (C) loop
3380 if Etype (C) = B_Typ then
3381 Set_Entity_With_Style_Check (N, C);
3382 Generate_Reference (C, N);
3390 -- If we fall through, then the literal does not match any of the
3391 -- entries of the enumeration type. This isn't just a constraint
3392 -- error situation, it is an illegality (see RM 4.2).
3395 ("character not defined for }", N, First_Subtype (B_Typ));
3397 end Resolve_Character_Literal;
3399 ---------------------------
3400 -- Resolve_Comparison_Op --
3401 ---------------------------
3403 -- Context requires a boolean type, and plays no role in resolution.
3404 -- Processing identical to that for equality operators.
3406 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
3407 L : constant Node_Id := Left_Opnd (N);
3408 R : constant Node_Id := Right_Opnd (N);
3412 -- If this is an intrinsic operation which is not predefined, use
3413 -- the types of its declared arguments to resolve the possibly
3414 -- overloaded operands. Otherwise the operands are unambiguous and
3415 -- specify the expected type.
3417 if Scope (Entity (N)) /= Standard_Standard then
3418 T := Etype (First_Entity (Entity (N)));
3420 T := Find_Unique_Type (L, R);
3422 if T = Any_Fixed then
3423 T := Unique_Fixed_Point_Type (L);
3428 Generate_Reference (T, N, ' ');
3430 if T /= Any_Type then
3433 or else T = Any_Composite
3434 or else T = Any_Character
3436 if T = Any_Character then
3437 Ambiguous_Character (L);
3439 Error_Msg_N ("ambiguous operands for comparison", N);
3442 Set_Etype (N, Any_Type);
3446 if Comes_From_Source (N)
3447 and then Has_Unchecked_Union (T)
3450 ("cannot compare Unchecked_Union values", N);
3455 Check_Unset_Reference (L);
3456 Check_Unset_Reference (R);
3457 Generate_Operator_Reference (N);
3458 Eval_Relational_Op (N);
3462 end Resolve_Comparison_Op;
3464 ------------------------------------
3465 -- Resolve_Conditional_Expression --
3466 ------------------------------------
3468 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
3469 Condition : constant Node_Id := First (Expressions (N));
3470 Then_Expr : constant Node_Id := Next (Condition);
3471 Else_Expr : constant Node_Id := Next (Then_Expr);
3474 Resolve (Condition, Standard_Boolean);
3475 Resolve (Then_Expr, Typ);
3476 Resolve (Else_Expr, Typ);
3479 Eval_Conditional_Expression (N);
3480 end Resolve_Conditional_Expression;
3482 -----------------------------------------
3483 -- Resolve_Discrete_Subtype_Indication --
3484 -----------------------------------------
3486 procedure Resolve_Discrete_Subtype_Indication
3494 Analyze (Subtype_Mark (N));
3495 S := Entity (Subtype_Mark (N));
3497 if Nkind (Constraint (N)) /= N_Range_Constraint then
3498 Error_Msg_N ("expect range constraint for discrete type", N);
3499 Set_Etype (N, Any_Type);
3502 R := Range_Expression (Constraint (N));
3510 if Base_Type (S) /= Base_Type (Typ) then
3512 ("expect subtype of }", N, First_Subtype (Typ));
3514 -- Rewrite the constraint as a range of Typ
3515 -- to allow compilation to proceed further.
3518 Rewrite (Low_Bound (R),
3519 Make_Attribute_Reference (Sloc (Low_Bound (R)),
3520 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
3521 Attribute_Name => Name_First));
3522 Rewrite (High_Bound (R),
3523 Make_Attribute_Reference (Sloc (High_Bound (R)),
3524 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
3525 Attribute_Name => Name_First));
3529 Set_Etype (N, Etype (R));
3531 -- Additionally, we must check that the bounds are compatible
3532 -- with the given subtype, which might be different from the
3533 -- type of the context.
3535 Apply_Range_Check (R, S);
3537 -- ??? If the above check statically detects a Constraint_Error
3538 -- it replaces the offending bound(s) of the range R with a
3539 -- Constraint_Error node. When the itype which uses these bounds
3540 -- is frozen the resulting call to Duplicate_Subexpr generates
3541 -- a new temporary for the bounds.
3543 -- Unfortunately there are other itypes that are also made depend
3544 -- on these bounds, so when Duplicate_Subexpr is called they get
3545 -- a forward reference to the newly created temporaries and Gigi
3546 -- aborts on such forward references. This is probably sign of a
3547 -- more fundamental problem somewhere else in either the order of
3548 -- itype freezing or the way certain itypes are constructed.
3550 -- To get around this problem we call Remove_Side_Effects right
3551 -- away if either bounds of R are a Constraint_Error.
3554 L : Node_Id := Low_Bound (R);
3555 H : Node_Id := High_Bound (R);
3558 if Nkind (L) = N_Raise_Constraint_Error then
3559 Remove_Side_Effects (L);
3562 if Nkind (H) = N_Raise_Constraint_Error then
3563 Remove_Side_Effects (H);
3567 Check_Unset_Reference (Low_Bound (R));
3568 Check_Unset_Reference (High_Bound (R));
3571 end Resolve_Discrete_Subtype_Indication;
3573 -------------------------
3574 -- Resolve_Entity_Name --
3575 -------------------------
3577 -- Used to resolve identifiers and expanded names
3579 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
3580 E : constant Entity_Id := Entity (N);
3583 -- Replace named numbers by corresponding literals. Note that this is
3584 -- the one case where Resolve_Entity_Name must reset the Etype, since
3585 -- it is currently marked as universal.
3587 if Ekind (E) = E_Named_Integer then
3589 Eval_Named_Integer (N);
3591 elsif Ekind (E) = E_Named_Real then
3593 Eval_Named_Real (N);
3595 -- Allow use of subtype only if it is a concurrent type where we are
3596 -- currently inside the body. This will eventually be expanded
3597 -- into a call to Self (for tasks) or _object (for protected
3598 -- objects). Any other use of a subtype is invalid.
3600 elsif Is_Type (E) then
3601 if Is_Concurrent_Type (E)
3602 and then In_Open_Scopes (E)
3607 ("Invalid use of subtype mark in expression or call", N);
3610 -- Check discriminant use if entity is discriminant in current scope,
3611 -- i.e. discriminant of record or concurrent type currently being
3612 -- analyzed. Uses in corresponding body are unrestricted.
3614 elsif Ekind (E) = E_Discriminant
3615 and then Scope (E) = Current_Scope
3616 and then not Has_Completion (Current_Scope)
3618 Check_Discriminant_Use (N);
3620 -- A parameterless generic function cannot appear in a context that
3621 -- requires resolution.
3623 elsif Ekind (E) = E_Generic_Function then
3624 Error_Msg_N ("illegal use of generic function", N);
3626 elsif Ekind (E) = E_Out_Parameter
3628 and then (Nkind (Parent (N)) in N_Op
3629 or else (Nkind (Parent (N)) = N_Assignment_Statement
3630 and then N = Expression (Parent (N)))
3631 or else Nkind (Parent (N)) = N_Explicit_Dereference)
3633 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
3635 -- In all other cases, just do the possible static evaluation
3638 -- A deferred constant that appears in an expression must have
3639 -- a completion, unless it has been removed by in-place expansion
3642 if Ekind (E) = E_Constant
3643 and then Comes_From_Source (E)
3644 and then No (Constant_Value (E))
3645 and then Is_Frozen (Etype (E))
3646 and then not In_Default_Expression
3647 and then not Is_Imported (E)
3650 if No_Initialization (Parent (E))
3651 or else (Present (Full_View (E))
3652 and then No_Initialization (Parent (Full_View (E))))
3657 "deferred constant is frozen before completion", N);
3661 Eval_Entity_Name (N);
3663 end Resolve_Entity_Name;
3669 procedure Resolve_Entry (Entry_Name : Node_Id) is
3670 Loc : constant Source_Ptr := Sloc (Entry_Name);
3678 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
3679 -- If the bounds of the entry family being called depend on task
3680 -- discriminants, build a new index subtype where a discriminant is
3681 -- replaced with the value of the discriminant of the target task.
3682 -- The target task is the prefix of the entry name in the call.
3684 -----------------------
3685 -- Actual_Index_Type --
3686 -----------------------
3688 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
3689 Typ : Entity_Id := Entry_Index_Type (E);
3690 Tsk : Entity_Id := Scope (E);
3691 Lo : Node_Id := Type_Low_Bound (Typ);
3692 Hi : Node_Id := Type_High_Bound (Typ);
3695 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
3696 -- If the bound is given by a discriminant, replace with a reference
3697 -- to the discriminant of the same name in the target task.
3698 -- If the entry name is the target of a requeue statement and the
3699 -- entry is in the current protected object, the bound to be used
3700 -- is the discriminal of the object (see apply_range_checks for
3701 -- details of the transformation).
3703 -----------------------------
3704 -- Actual_Discriminant_Ref --
3705 -----------------------------
3707 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
3708 Typ : Entity_Id := Etype (Bound);
3712 Remove_Side_Effects (Bound);
3714 if not Is_Entity_Name (Bound)
3715 or else Ekind (Entity (Bound)) /= E_Discriminant
3719 elsif Is_Protected_Type (Tsk)
3720 and then In_Open_Scopes (Tsk)
3721 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
3723 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
3727 Make_Selected_Component (Loc,
3728 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
3729 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
3734 end Actual_Discriminant_Ref;
3736 -- Start of processing for Actual_Index_Type
3739 if not Has_Discriminants (Tsk)
3740 or else (not Is_Entity_Name (Lo)
3741 and then not Is_Entity_Name (Hi))
3743 return Entry_Index_Type (E);
3746 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
3747 Set_Etype (New_T, Base_Type (Typ));
3748 Set_Size_Info (New_T, Typ);
3749 Set_RM_Size (New_T, RM_Size (Typ));
3750 Set_Scalar_Range (New_T,
3751 Make_Range (Sloc (Entry_Name),
3752 Low_Bound => Actual_Discriminant_Ref (Lo),
3753 High_Bound => Actual_Discriminant_Ref (Hi)));
3757 end Actual_Index_Type;
3759 -- Start of processing of Resolve_Entry
3762 -- Find name of entry being called, and resolve prefix of name
3763 -- with its own type. The prefix can be overloaded, and the name
3764 -- and signature of the entry must be taken into account.
3766 if Nkind (Entry_Name) = N_Indexed_Component then
3768 -- Case of dealing with entry family within the current tasks
3770 E_Name := Prefix (Entry_Name);
3773 E_Name := Entry_Name;
3776 if Is_Entity_Name (E_Name) then
3777 -- Entry call to an entry (or entry family) in the current task.
3778 -- This is legal even though the task will deadlock. Rewrite as
3779 -- call to current task.
3781 -- This can also be a call to an entry in an enclosing task.
3782 -- If this is a single task, we have to retrieve its name,
3783 -- because the scope of the entry is the task type, not the
3784 -- object. If the enclosing task is a task type, the identity
3785 -- of the task is given by its own self variable.
3787 -- Finally this can be a requeue on an entry of the same task
3788 -- or protected object.
3790 S := Scope (Entity (E_Name));
3792 for J in reverse 0 .. Scope_Stack.Last loop
3794 if Is_Task_Type (Scope_Stack.Table (J).Entity)
3795 and then not Comes_From_Source (S)
3797 -- S is an enclosing task or protected object. The concurrent
3798 -- declaration has been converted into a type declaration, and
3799 -- the object itself has an object declaration that follows
3800 -- the type in the same declarative part.
3802 Tsk := Next_Entity (S);
3804 while Etype (Tsk) /= S loop
3811 elsif S = Scope_Stack.Table (J).Entity then
3813 -- Call to current task. Will be transformed into call to Self
3821 Make_Selected_Component (Loc,
3822 Prefix => New_Occurrence_Of (S, Loc),
3824 New_Occurrence_Of (Entity (E_Name), Loc));
3825 Rewrite (E_Name, New_N);
3828 elsif Nkind (Entry_Name) = N_Selected_Component
3829 and then Is_Overloaded (Prefix (Entry_Name))
3831 -- Use the entry name (which must be unique at this point) to
3832 -- find the prefix that returns the corresponding task type or
3836 Pref : Node_Id := Prefix (Entry_Name);
3839 Ent : Entity_Id := Entity (Selector_Name (Entry_Name));
3842 Get_First_Interp (Pref, I, It);
3844 while Present (It.Typ) loop
3846 if Scope (Ent) = It.Typ then
3847 Set_Etype (Pref, It.Typ);
3851 Get_Next_Interp (I, It);
3856 if Nkind (Entry_Name) = N_Selected_Component then
3857 Resolve (Prefix (Entry_Name), Etype (Prefix (Entry_Name)));
3859 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
3860 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
3861 Resolve (Prefix (Prefix (Entry_Name)),
3862 Etype (Prefix (Prefix (Entry_Name))));
3864 Index := First (Expressions (Entry_Name));
3865 Resolve (Index, Entry_Index_Type (Nam));
3867 -- Up to this point the expression could have been the actual
3868 -- in a simple entry call, and be given by a named association.
3870 if Nkind (Index) = N_Parameter_Association then
3871 Error_Msg_N ("expect expression for entry index", Index);
3873 Apply_Range_Check (Index, Actual_Index_Type (Nam));
3879 ------------------------
3880 -- Resolve_Entry_Call --
3881 ------------------------
3883 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
3884 Entry_Name : constant Node_Id := Name (N);
3885 Loc : constant Source_Ptr := Sloc (Entry_Name);
3887 First_Named : Node_Id;
3894 -- Processing of the name is similar for entry calls and protected
3895 -- operation calls. Once the entity is determined, we can complete
3896 -- the resolution of the actuals.
3898 -- The selector may be overloaded, in the case of a protected object
3899 -- with overloaded functions. The type of the context is used for
3902 if Nkind (Entry_Name) = N_Selected_Component
3903 and then Is_Overloaded (Selector_Name (Entry_Name))
3904 and then Typ /= Standard_Void_Type
3911 Get_First_Interp (Selector_Name (Entry_Name), I, It);
3913 while Present (It.Typ) loop
3915 if Covers (Typ, It.Typ) then
3916 Set_Entity (Selector_Name (Entry_Name), It.Nam);
3917 Set_Etype (Entry_Name, It.Typ);
3919 Generate_Reference (It.Typ, N, ' ');
3922 Get_Next_Interp (I, It);
3927 Resolve_Entry (Entry_Name);
3929 if Nkind (Entry_Name) = N_Selected_Component then
3931 -- Simple entry call.
3933 Nam := Entity (Selector_Name (Entry_Name));
3934 Obj := Prefix (Entry_Name);
3935 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
3937 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
3939 -- Call to member of entry family.
3941 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
3942 Obj := Prefix (Prefix (Entry_Name));
3943 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
3946 -- Use context type to disambiguate a protected function that can be
3947 -- called without actuals and that returns an array type, and where
3948 -- the argument list may be an indexing of the returned value.
3950 if Ekind (Nam) = E_Function
3951 and then Needs_No_Actuals (Nam)
3952 and then Present (Parameter_Associations (N))
3954 ((Is_Array_Type (Etype (Nam))
3955 and then Covers (Typ, Component_Type (Etype (Nam))))
3957 or else (Is_Access_Type (Etype (Nam))
3958 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3959 and then Covers (Typ,
3960 Component_Type (Designated_Type (Etype (Nam))))))
3963 Index_Node : Node_Id;
3967 Make_Indexed_Component (Loc,
3969 Make_Function_Call (Loc,
3970 Name => Relocate_Node (Entry_Name)),
3971 Expressions => Parameter_Associations (N));
3973 -- Since we are correcting a node classification error made by
3974 -- the parser, we call Replace rather than Rewrite.
3976 Replace (N, Index_Node);
3977 Set_Etype (Prefix (N), Etype (Nam));
3979 Resolve_Indexed_Component (N, Typ);
3984 -- The operation name may have been overloaded. Order the actuals
3985 -- according to the formals of the resolved entity.
3988 Normalize_Actuals (N, Nam, False, Norm_OK);
3989 pragma Assert (Norm_OK);
3992 Resolve_Actuals (N, Nam);
3993 Generate_Reference (Nam, Entry_Name);
3995 if Ekind (Nam) = E_Entry
3996 or else Ekind (Nam) = E_Entry_Family
3998 Check_Potentially_Blocking_Operation (N);
4001 -- Verify that a procedure call cannot masquerade as an entry
4002 -- call where an entry call is expected.
4004 if Ekind (Nam) = E_Procedure then
4006 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4007 and then N = Entry_Call_Statement (Parent (N))
4009 Error_Msg_N ("entry call required in select statement", N);
4011 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4012 and then N = Triggering_Statement (Parent (N))
4014 Error_Msg_N ("triggering statement cannot be procedure call", N);
4016 elsif Ekind (Scope (Nam)) = E_Task_Type
4017 and then not In_Open_Scopes (Scope (Nam))
4019 Error_Msg_N ("Task has no entry with this name", Entry_Name);
4023 -- After resolution, entry calls and protected procedure calls
4024 -- are changed into entry calls, for expansion. The structure
4025 -- of the node does not change, so it can safely be done in place.
4026 -- Protected function calls must keep their structure because they
4027 -- are subexpressions.
4029 if Ekind (Nam) /= E_Function then
4031 -- A protected operation that is not a function may modify the
4032 -- corresponding object, and cannot apply to a constant.
4033 -- If this is an internal call, the prefix is the type itself.
4035 if Is_Protected_Type (Scope (Nam))
4036 and then not Is_Variable (Obj)
4037 and then (not Is_Entity_Name (Obj)
4038 or else not Is_Type (Entity (Obj)))
4041 ("prefix of protected procedure or entry call must be variable",
4045 Actuals := Parameter_Associations (N);
4046 First_Named := First_Named_Actual (N);
4049 Make_Entry_Call_Statement (Loc,
4051 Parameter_Associations => Actuals));
4053 Set_First_Named_Actual (N, First_Named);
4054 Set_Analyzed (N, True);
4056 -- Protected functions can return on the secondary stack, in which
4057 -- case we must trigger the transient scope mechanism
4059 elsif Expander_Active
4060 and then Requires_Transient_Scope (Etype (Nam))
4062 Establish_Transient_Scope (N,
4063 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4066 end Resolve_Entry_Call;
4068 -------------------------
4069 -- Resolve_Equality_Op --
4070 -------------------------
4072 -- Both arguments must have the same type, and the boolean context
4073 -- does not participate in the resolution. The first pass verifies
4074 -- that the interpretation is not ambiguous, and the type of the left
4075 -- argument is correctly set, or is Any_Type in case of ambiguity.
4076 -- If both arguments are strings or aggregates, allocators, or Null,
4077 -- they are ambiguous even though they carry a single (universal) type.
4078 -- Diagnose this case here.
4080 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4081 L : constant Node_Id := Left_Opnd (N);
4082 R : constant Node_Id := Right_Opnd (N);
4083 T : Entity_Id := Find_Unique_Type (L, R);
4085 function Find_Unique_Access_Type return Entity_Id;
4086 -- In the case of allocators, make a last-ditch attempt to find a single
4087 -- access type with the right designated type. This is semantically
4088 -- dubious, and of no interest to any real code, but c48008a makes it
4091 -----------------------------
4092 -- Find_Unique_Access_Type --
4093 -----------------------------
4095 function Find_Unique_Access_Type return Entity_Id is
4098 S : Entity_Id := Current_Scope;
4101 if Ekind (Etype (R)) = E_Allocator_Type then
4102 Acc := Designated_Type (Etype (R));
4104 elsif Ekind (Etype (L)) = E_Allocator_Type then
4105 Acc := Designated_Type (Etype (L));
4111 while S /= Standard_Standard loop
4112 E := First_Entity (S);
4114 while Present (E) loop
4117 and then Is_Access_Type (E)
4118 and then Ekind (E) /= E_Allocator_Type
4119 and then Designated_Type (E) = Base_Type (Acc)
4131 end Find_Unique_Access_Type;
4133 -- Start of processing for Resolve_Equality_Op
4136 Set_Etype (N, Base_Type (Typ));
4137 Generate_Reference (T, N, ' ');
4139 if T = Any_Fixed then
4140 T := Unique_Fixed_Point_Type (L);
4143 if T /= Any_Type then
4146 or else T = Any_Composite
4147 or else T = Any_Character
4150 if T = Any_Character then
4151 Ambiguous_Character (L);
4153 Error_Msg_N ("ambiguous operands for equality", N);
4156 Set_Etype (N, Any_Type);
4159 elsif T = Any_Access
4160 or else Ekind (T) = E_Allocator_Type
4162 T := Find_Unique_Access_Type;
4165 Error_Msg_N ("ambiguous operands for equality", N);
4166 Set_Etype (N, Any_Type);
4171 if Comes_From_Source (N)
4172 and then Has_Unchecked_Union (T)
4175 ("cannot compare Unchecked_Union values", N);
4180 Check_Unset_Reference (L);
4181 Check_Unset_Reference (R);
4182 Generate_Operator_Reference (N);
4184 -- If this is an inequality, it may be the implicit inequality
4185 -- created for a user-defined operation, in which case the corres-
4186 -- ponding equality operation is not intrinsic, and the operation
4187 -- cannot be constant-folded. Else fold.
4189 if Nkind (N) = N_Op_Eq
4190 or else Comes_From_Source (Entity (N))
4191 or else Ekind (Entity (N)) = E_Operator
4192 or else Is_Intrinsic_Subprogram
4193 (Corresponding_Equality (Entity (N)))
4195 Eval_Relational_Op (N);
4196 elsif Nkind (N) = N_Op_Ne
4197 and then Is_Abstract (Entity (N))
4199 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4202 end Resolve_Equality_Op;
4204 ----------------------------------
4205 -- Resolve_Explicit_Dereference --
4206 ----------------------------------
4208 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4209 P : constant Node_Id := Prefix (N);
4214 -- Now that we know the type, check that this is not a
4215 -- dereference of an uncompleted type. Note that this
4216 -- is not entirely correct, because dereferences of
4217 -- private types are legal in default expressions.
4218 -- This consideration also applies to similar checks
4219 -- for allocators, qualified expressions, and type
4222 Check_Fully_Declared (Typ, N);
4224 if Is_Overloaded (P) then
4226 -- Use the context type to select the prefix that has the
4227 -- correct designated type.
4229 Get_First_Interp (P, I, It);
4230 while Present (It.Typ) loop
4231 exit when Is_Access_Type (It.Typ)
4232 and then Covers (Typ, Designated_Type (It.Typ));
4234 Get_Next_Interp (I, It);
4237 Resolve (P, It.Typ);
4238 Set_Etype (N, Designated_Type (It.Typ));
4241 Resolve (P, Etype (P));
4244 if Is_Access_Type (Etype (P)) then
4245 Apply_Access_Check (N);
4248 -- If the designated type is a packed unconstrained array type,
4249 -- and the explicit dereference is not in the context of an
4250 -- attribute reference, then we must compute and set the actual
4251 -- subtype, since it is needed by Gigi. The reason we exclude
4252 -- the attribute case is that this is handled fine by Gigi, and
4253 -- in fact we use such attributes to build the actual subtype.
4254 -- We also exclude generated code (which builds actual subtypes
4255 -- directly if they are needed).
4257 if Is_Array_Type (Etype (N))
4258 and then Is_Packed (Etype (N))
4259 and then not Is_Constrained (Etype (N))
4260 and then Nkind (Parent (N)) /= N_Attribute_Reference
4261 and then Comes_From_Source (N)
4263 Set_Etype (N, Get_Actual_Subtype (N));
4266 -- Note: there is no Eval processing required for an explicit
4267 -- deference, because the type is known to be an allocators, and
4268 -- allocator expressions can never be static.
4270 end Resolve_Explicit_Dereference;
4272 -------------------------------
4273 -- Resolve_Indexed_Component --
4274 -------------------------------
4276 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4277 Name : constant Node_Id := Prefix (N);
4279 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4283 if Is_Overloaded (Name) then
4285 -- Use the context type to select the prefix that yields the
4286 -- correct component type.
4291 I1 : Interp_Index := 0;
4292 P : constant Node_Id := Prefix (N);
4293 Found : Boolean := False;
4296 Get_First_Interp (P, I, It);
4298 while Present (It.Typ) loop
4300 if (Is_Array_Type (It.Typ)
4301 and then Covers (Typ, Component_Type (It.Typ)))
4302 or else (Is_Access_Type (It.Typ)
4303 and then Is_Array_Type (Designated_Type (It.Typ))
4305 (Typ, Component_Type (Designated_Type (It.Typ))))
4308 It := Disambiguate (P, I1, I, Any_Type);
4310 if It = No_Interp then
4311 Error_Msg_N ("ambiguous prefix for indexing", N);
4317 Array_Type := It.Typ;
4323 Array_Type := It.Typ;
4328 Get_Next_Interp (I, It);
4333 Array_Type := Etype (Name);
4336 Resolve (Name, Array_Type);
4337 Array_Type := Get_Actual_Subtype_If_Available (Name);
4339 -- If prefix is access type, dereference to get real array type.
4340 -- Note: we do not apply an access check because the expander always
4341 -- introduces an explicit dereference, and the check will happen there.
4343 if Is_Access_Type (Array_Type) then
4344 Array_Type := Designated_Type (Array_Type);
4347 -- If name was overloaded, set component type correctly now.
4349 Set_Etype (N, Component_Type (Array_Type));
4351 Index := First_Index (Array_Type);
4352 Expr := First (Expressions (N));
4354 -- The prefix may have resolved to a string literal, in which case
4355 -- its etype has a special representation. This is only possible
4356 -- currently if the prefix is a static concatenation, written in
4357 -- functional notation.
4359 if Ekind (Array_Type) = E_String_Literal_Subtype then
4360 Resolve (Expr, Standard_Positive);
4363 while Present (Index) and Present (Expr) loop
4364 Resolve (Expr, Etype (Index));
4365 Check_Unset_Reference (Expr);
4367 if Is_Scalar_Type (Etype (Expr)) then
4368 Apply_Scalar_Range_Check (Expr, Etype (Index));
4370 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
4378 Eval_Indexed_Component (N);
4380 end Resolve_Indexed_Component;
4382 -----------------------------
4383 -- Resolve_Integer_Literal --
4384 -----------------------------
4386 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
4389 Eval_Integer_Literal (N);
4390 end Resolve_Integer_Literal;
4392 ---------------------------------
4393 -- Resolve_Intrinsic_Operator --
4394 ---------------------------------
4396 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
4398 Arg1 : Node_Id := Left_Opnd (N);
4399 Arg2 : Node_Id := Right_Opnd (N);
4404 while Scope (Op) /= Standard_Standard loop
4406 pragma Assert (Present (Op));
4411 if Typ /= Etype (Arg1) or else Typ = Etype (Arg2) then
4412 Rewrite (Left_Opnd (N), Convert_To (Typ, Arg1));
4413 Rewrite (Right_Opnd (N), Convert_To (Typ, Arg2));
4415 Analyze (Left_Opnd (N));
4416 Analyze (Right_Opnd (N));
4419 Resolve_Arithmetic_Op (N, Typ);
4420 end Resolve_Intrinsic_Operator;
4422 ------------------------
4423 -- Resolve_Logical_Op --
4424 ------------------------
4426 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
4430 -- Predefined operations on scalar types yield the base type. On
4431 -- the other hand, logical operations on arrays yield the type of
4432 -- the arguments (and the context).
4434 if Is_Array_Type (Typ) then
4437 B_Typ := Base_Type (Typ);
4440 -- The following test is required because the operands of the operation
4441 -- may be literals, in which case the resulting type appears to be
4442 -- compatible with a signed integer type, when in fact it is compatible
4443 -- only with modular types. If the context itself is universal, the
4444 -- operation is illegal.
4446 if not Valid_Boolean_Arg (Typ) then
4447 Error_Msg_N ("invalid context for logical operation", N);
4448 Set_Etype (N, Any_Type);
4451 elsif Typ = Any_Modular then
4453 ("no modular type available in this context", N);
4454 Set_Etype (N, Any_Type);
4458 Resolve (Left_Opnd (N), B_Typ);
4459 Resolve (Right_Opnd (N), B_Typ);
4461 Check_Unset_Reference (Left_Opnd (N));
4462 Check_Unset_Reference (Right_Opnd (N));
4464 Set_Etype (N, B_Typ);
4465 Generate_Operator_Reference (N);
4466 Eval_Logical_Op (N);
4467 end Resolve_Logical_Op;
4469 ---------------------------
4470 -- Resolve_Membership_Op --
4471 ---------------------------
4473 -- The context can only be a boolean type, and does not determine
4474 -- the arguments. Arguments should be unambiguous, but the preference
4475 -- rule for universal types applies.
4477 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
4478 L : constant Node_Id := Left_Opnd (N);
4479 R : constant Node_Id := Right_Opnd (N);
4483 if L = Error or else R = Error then
4487 if not Is_Overloaded (R)
4489 (Etype (R) = Universal_Integer or else
4490 Etype (R) = Universal_Real)
4491 and then Is_Overloaded (L)
4495 T := Intersect_Types (L, R);
4499 Check_Unset_Reference (L);
4501 if Nkind (R) = N_Range
4502 and then not Is_Scalar_Type (T)
4504 Error_Msg_N ("scalar type required for range", R);
4507 if Is_Entity_Name (R) then
4508 Freeze_Expression (R);
4511 Check_Unset_Reference (R);
4514 Eval_Membership_Op (N);
4515 end Resolve_Membership_Op;
4521 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
4523 -- For now allow circumvention of the restriction against
4524 -- anonymous null access values via a debug switch to allow
4525 -- for easier trasition.
4528 and then Ekind (Typ) = E_Anonymous_Access_Type
4529 and then Comes_From_Source (N)
4531 -- In the common case of a call which uses an explicitly null
4532 -- value for an access parameter, give specialized error msg
4534 if Nkind (Parent (N)) = N_Procedure_Call_Statement
4536 Nkind (Parent (N)) = N_Function_Call
4539 ("null is not allowed as argument for an access parameter", N);
4541 -- Standard message for all other cases (are there any?)
4545 ("null cannot be of an anonymous access type", N);
4549 -- In a distributed context, null for a remote access to subprogram
4550 -- may need to be replaced with a special record aggregate. In this
4551 -- case, return after having done the transformation.
4553 if (Ekind (Typ) = E_Record_Type
4554 or else Is_Remote_Access_To_Subprogram_Type (Typ))
4555 and then Remote_AST_Null_Value (N, Typ)
4560 -- The null literal takes its type from the context.
4565 -----------------------
4566 -- Resolve_Op_Concat --
4567 -----------------------
4569 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
4570 Btyp : constant Entity_Id := Base_Type (Typ);
4571 Op1 : constant Node_Id := Left_Opnd (N);
4572 Op2 : constant Node_Id := Right_Opnd (N);
4574 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
4575 -- Internal procedure to resolve one operand of concatenation operator.
4576 -- The operand is either of the array type or of the component type.
4577 -- If the operand is an aggregate, and the component type is composite,
4578 -- this is ambiguous if component type has aggregates.
4580 -------------------------------
4581 -- Resolve_Concatenation_Arg --
4582 -------------------------------
4584 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
4588 or else (not Is_Overloaded (Arg)
4589 and then Etype (Arg) /= Any_Composite
4590 and then Covers (Component_Type (Typ), Etype (Arg)))
4592 Resolve (Arg, Component_Type (Typ));
4594 Resolve (Arg, Btyp);
4597 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
4599 if Nkind (Arg) = N_Aggregate
4600 and then Is_Composite_Type (Component_Type (Typ))
4602 if Is_Private_Type (Component_Type (Typ)) then
4603 Resolve (Arg, Btyp);
4606 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
4607 Set_Etype (Arg, Any_Type);
4611 if Is_Overloaded (Arg)
4612 and then Has_Compatible_Type (Arg, Typ)
4613 and then Etype (Arg) /= Any_Type
4615 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
4622 Get_First_Interp (Arg, I, It);
4624 while Present (It.Nam) loop
4626 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
4627 or else Base_Type (Etype (It.Nam)) =
4628 Base_Type (Component_Type (Typ))
4630 Error_Msg_Sloc := Sloc (It.Nam);
4631 Error_Msg_N ("\possible interpretation#", Arg);
4634 Get_Next_Interp (I, It);
4639 Resolve (Arg, Component_Type (Typ));
4641 if Arg = Left_Opnd (N) then
4642 Set_Is_Component_Left_Opnd (N);
4644 Set_Is_Component_Right_Opnd (N);
4649 Resolve (Arg, Btyp);
4652 Check_Unset_Reference (Arg);
4653 end Resolve_Concatenation_Arg;
4655 -- Start of processing for Resolve_Op_Concat
4658 Set_Etype (N, Btyp);
4660 if Is_Limited_Composite (Btyp) then
4661 Error_Msg_N ("concatenation not available for limited array", N);
4664 -- If the operands are themselves concatenations, resolve them as
4665 -- such directly. This removes several layers of recursion and allows
4666 -- GNAT to handle larger multiple concatenations.
4668 if Nkind (Op1) = N_Op_Concat
4669 and then not Is_Array_Type (Component_Type (Typ))
4670 and then Entity (Op1) = Entity (N)
4672 Resolve_Op_Concat (Op1, Typ);
4674 Resolve_Concatenation_Arg
4675 (Op1, Is_Component_Left_Opnd (N));
4678 if Nkind (Op2) = N_Op_Concat
4679 and then not Is_Array_Type (Component_Type (Typ))
4680 and then Entity (Op2) = Entity (N)
4682 Resolve_Op_Concat (Op2, Typ);
4684 Resolve_Concatenation_Arg
4685 (Op2, Is_Component_Right_Opnd (N));
4688 Generate_Operator_Reference (N);
4690 if Is_String_Type (Typ) then
4691 Eval_Concatenation (N);
4694 -- If this is not a static concatenation, but the result is a
4695 -- string type (and not an array of strings) insure that static
4696 -- string operands have their subtypes properly constructed.
4698 if Nkind (N) /= N_String_Literal
4699 and then Is_Character_Type (Component_Type (Typ))
4701 Set_String_Literal_Subtype (Op1, Typ);
4702 Set_String_Literal_Subtype (Op2, Typ);
4704 end Resolve_Op_Concat;
4706 ----------------------
4707 -- Resolve_Op_Expon --
4708 ----------------------
4710 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
4711 B_Typ : constant Entity_Id := Base_Type (Typ);
4714 -- Catch attempts to do fixed-point exponentation with universal
4715 -- operands, which is a case where the illegality is not caught
4716 -- during normal operator analysis.
4718 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
4719 Error_Msg_N ("exponentiation not available for fixed point", N);
4723 if Etype (Left_Opnd (N)) = Universal_Integer
4724 or else Etype (Left_Opnd (N)) = Universal_Real
4726 Check_For_Visible_Operator (N, B_Typ);
4729 -- We do the resolution using the base type, because intermediate values
4730 -- in expressions always are of the base type, not a subtype of it.
4732 Resolve (Left_Opnd (N), B_Typ);
4733 Resolve (Right_Opnd (N), Standard_Integer);
4735 Check_Unset_Reference (Left_Opnd (N));
4736 Check_Unset_Reference (Right_Opnd (N));
4738 Set_Etype (N, B_Typ);
4739 Generate_Operator_Reference (N);
4742 -- Set overflow checking bit. Much cleverer code needed here eventually
4743 -- and perhaps the Resolve routines should be separated for the various
4744 -- arithmetic operations, since they will need different processing. ???
4746 if Nkind (N) in N_Op then
4747 if not Overflow_Checks_Suppressed (Etype (N)) then
4748 Set_Do_Overflow_Check (N, True);
4752 end Resolve_Op_Expon;
4754 --------------------
4755 -- Resolve_Op_Not --
4756 --------------------
4758 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
4761 function Parent_Is_Boolean return Boolean;
4762 -- This function determines if the parent node is a boolean operator
4763 -- or operation (comparison op, membership test, or short circuit form)
4764 -- and the not in question is the left operand of this operation.
4765 -- Note that if the not is in parens, then false is returned.
4767 function Parent_Is_Boolean return Boolean is
4769 if Paren_Count (N) /= 0 then
4773 case Nkind (Parent (N)) is
4788 return Left_Opnd (Parent (N)) = N;
4794 end Parent_Is_Boolean;
4796 -- Start of processing for Resolve_Op_Not
4799 -- Predefined operations on scalar types yield the base type. On
4800 -- the other hand, logical operations on arrays yield the type of
4801 -- the arguments (and the context).
4803 if Is_Array_Type (Typ) then
4806 B_Typ := Base_Type (Typ);
4809 if not Valid_Boolean_Arg (Typ) then
4810 Error_Msg_N ("invalid operand type for operator&", N);
4811 Set_Etype (N, Any_Type);
4814 elsif (Typ = Universal_Integer
4815 or else Typ = Any_Modular)
4817 if Parent_Is_Boolean then
4819 ("operand of not must be enclosed in parentheses",
4823 ("no modular type available in this context", N);
4826 Set_Etype (N, Any_Type);
4830 if not Is_Boolean_Type (Typ)
4831 and then Parent_Is_Boolean
4833 Error_Msg_N ("?not expression should be parenthesized here", N);
4836 Resolve (Right_Opnd (N), B_Typ);
4837 Check_Unset_Reference (Right_Opnd (N));
4838 Set_Etype (N, B_Typ);
4839 Generate_Operator_Reference (N);
4844 -----------------------------
4845 -- Resolve_Operator_Symbol --
4846 -----------------------------
4848 -- Nothing to be done, all resolved already
4850 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
4853 end Resolve_Operator_Symbol;
4855 ----------------------------------
4856 -- Resolve_Qualified_Expression --
4857 ----------------------------------
4859 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
4860 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
4861 Expr : constant Node_Id := Expression (N);
4864 Resolve (Expr, Target_Typ);
4866 -- A qualified expression requires an exact match of the type,
4867 -- class-wide matching is not allowed.
4869 if Is_Class_Wide_Type (Target_Typ)
4870 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
4872 Wrong_Type (Expr, Target_Typ);
4875 -- If the target type is unconstrained, then we reset the type of
4876 -- the result from the type of the expression. For other cases, the
4877 -- actual subtype of the expression is the target type.
4879 if Is_Composite_Type (Target_Typ)
4880 and then not Is_Constrained (Target_Typ)
4882 Set_Etype (N, Etype (Expr));
4885 Eval_Qualified_Expression (N);
4886 end Resolve_Qualified_Expression;
4892 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
4893 L : constant Node_Id := Low_Bound (N);
4894 H : constant Node_Id := High_Bound (N);
4901 Check_Unset_Reference (L);
4902 Check_Unset_Reference (H);
4904 -- We have to check the bounds for being within the base range as
4905 -- required for a non-static context. Normally this is automatic
4906 -- and done as part of evaluating expressions, but the N_Range
4907 -- node is an exception, since in GNAT we consider this node to
4908 -- be a subexpression, even though in Ada it is not. The circuit
4909 -- in Sem_Eval could check for this, but that would put the test
4910 -- on the main evaluation path for expressions.
4912 Check_Non_Static_Context (L);
4913 Check_Non_Static_Context (H);
4917 --------------------------
4918 -- Resolve_Real_Literal --
4919 --------------------------
4921 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
4922 Actual_Typ : constant Entity_Id := Etype (N);
4925 -- Special processing for fixed-point literals to make sure that the
4926 -- value is an exact multiple of small where this is required. We
4927 -- skip this for the universal real case, and also for generic types.
4929 if Is_Fixed_Point_Type (Typ)
4930 and then Typ /= Universal_Fixed
4931 and then Typ /= Any_Fixed
4932 and then not Is_Generic_Type (Typ)
4935 Val : constant Ureal := Realval (N);
4936 Cintr : constant Ureal := Val / Small_Value (Typ);
4937 Cint : constant Uint := UR_Trunc (Cintr);
4938 Den : constant Uint := Norm_Den (Cintr);
4942 -- Case of literal is not an exact multiple of the Small
4946 -- For a source program literal for a decimal fixed-point
4947 -- type, this is statically illegal (RM 4.9(36)).
4949 if Is_Decimal_Fixed_Point_Type (Typ)
4950 and then Actual_Typ = Universal_Real
4951 and then Comes_From_Source (N)
4953 Error_Msg_N ("value has extraneous low order digits", N);
4956 -- Replace literal by a value that is the exact representation
4957 -- of a value of the type, i.e. a multiple of the small value,
4958 -- by truncation, since Machine_Rounds is false for all GNAT
4959 -- fixed-point types (RM 4.9(38)).
4961 Stat := Is_Static_Expression (N);
4963 Make_Real_Literal (Sloc (N),
4964 Realval => Small_Value (Typ) * Cint));
4966 Set_Is_Static_Expression (N, Stat);
4969 -- In all cases, set the corresponding integer field
4971 Set_Corresponding_Integer_Value (N, Cint);
4975 -- Now replace the actual type by the expected type as usual
4978 Eval_Real_Literal (N);
4979 end Resolve_Real_Literal;
4981 -----------------------
4982 -- Resolve_Reference --
4983 -----------------------
4985 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
4986 P : constant Node_Id := Prefix (N);
4989 -- Replace general access with specific type
4991 if Ekind (Etype (N)) = E_Allocator_Type then
4992 Set_Etype (N, Base_Type (Typ));
4995 Resolve (P, Designated_Type (Etype (N)));
4997 -- If we are taking the reference of a volatile entity, then treat
4998 -- it as a potential modification of this entity. This is much too
4999 -- conservative, but is neccessary because remove side effects can
5000 -- result in transformations of normal assignments into reference
5001 -- sequences that otherwise fail to notice the modification.
5003 if Is_Entity_Name (P) and then Is_Volatile (Entity (P)) then
5004 Note_Possible_Modification (P);
5006 end Resolve_Reference;
5008 --------------------------------
5009 -- Resolve_Selected_Component --
5010 --------------------------------
5012 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5014 Comp1 : Entity_Id := Empty; -- prevent junk warning
5015 P : constant Node_Id := Prefix (N);
5016 S : constant Node_Id := Selector_Name (N);
5017 T : Entity_Id := Etype (P);
5019 I1 : Interp_Index := 0; -- prevent junk warning
5025 if Is_Overloaded (P) then
5027 -- Use the context type to select the prefix that has a selector
5028 -- of the correct name and type.
5031 Get_First_Interp (P, I, It);
5033 Search : while Present (It.Typ) loop
5034 if Is_Access_Type (It.Typ) then
5035 T := Designated_Type (It.Typ);
5040 if Is_Record_Type (T) then
5041 Comp := First_Entity (T);
5043 while Present (Comp) loop
5045 if Chars (Comp) = Chars (S)
5046 and then Covers (Etype (Comp), Typ)
5055 It := Disambiguate (P, I1, I, Any_Type);
5057 if It = No_Interp then
5059 ("ambiguous prefix for selected component", N);
5066 if Scope (Comp1) /= It1.Typ then
5068 -- Resolution chooses the new interpretation.
5069 -- Find the component with the right name.
5071 Comp1 := First_Entity (It1.Typ);
5073 while Present (Comp1)
5074 and then Chars (Comp1) /= Chars (S)
5076 Comp1 := Next_Entity (Comp1);
5085 Comp := Next_Entity (Comp);
5090 Get_Next_Interp (I, It);
5094 Resolve (P, It1.Typ);
5096 Set_Entity (S, Comp1);
5099 -- Resolve prefix with its type.
5104 -- Deal with access type case
5106 if Is_Access_Type (Etype (P)) then
5107 Apply_Access_Check (N);
5108 T := Designated_Type (Etype (P));
5113 if Has_Discriminants (T)
5114 and then Present (Original_Record_Component (Entity (S)))
5115 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5116 and then Present (Discriminant_Checking_Func
5117 (Original_Record_Component (Entity (S))))
5118 and then not Discriminant_Checks_Suppressed (T)
5120 Set_Do_Discriminant_Check (N);
5123 if Ekind (Entity (S)) = E_Void then
5124 Error_Msg_N ("premature use of component", S);
5127 -- If the prefix is a record conversion, this may be a renamed
5128 -- discriminant whose bounds differ from those of the original
5129 -- one, so we must ensure that a range check is performed.
5131 if Nkind (P) = N_Type_Conversion
5132 and then Ekind (Entity (S)) = E_Discriminant
5134 Set_Etype (N, Base_Type (Typ));
5137 -- Note: No Eval processing is required, because the prefix is of a
5138 -- record type, or protected type, and neither can possibly be static.
5140 end Resolve_Selected_Component;
5146 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5147 B_Typ : constant Entity_Id := Base_Type (Typ);
5148 L : constant Node_Id := Left_Opnd (N);
5149 R : constant Node_Id := Right_Opnd (N);
5152 -- We do the resolution using the base type, because intermediate values
5153 -- in expressions always are of the base type, not a subtype of it.
5156 Resolve (R, Standard_Natural);
5158 Check_Unset_Reference (L);
5159 Check_Unset_Reference (R);
5161 Set_Etype (N, B_Typ);
5162 Generate_Operator_Reference (N);
5166 ---------------------------
5167 -- Resolve_Short_Circuit --
5168 ---------------------------
5170 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5171 B_Typ : constant Entity_Id := Base_Type (Typ);
5172 L : constant Node_Id := Left_Opnd (N);
5173 R : constant Node_Id := Right_Opnd (N);
5179 Check_Unset_Reference (L);
5180 Check_Unset_Reference (R);
5182 Set_Etype (N, B_Typ);
5183 Eval_Short_Circuit (N);
5184 end Resolve_Short_Circuit;
5190 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
5191 Name : constant Node_Id := Prefix (N);
5192 Drange : constant Node_Id := Discrete_Range (N);
5193 Array_Type : Entity_Id := Empty;
5197 if Is_Overloaded (Name) then
5199 -- Use the context type to select the prefix that yields the
5200 -- correct array type.
5204 I1 : Interp_Index := 0;
5206 P : constant Node_Id := Prefix (N);
5207 Found : Boolean := False;
5210 Get_First_Interp (P, I, It);
5212 while Present (It.Typ) loop
5214 if (Is_Array_Type (It.Typ)
5215 and then Covers (Typ, It.Typ))
5216 or else (Is_Access_Type (It.Typ)
5217 and then Is_Array_Type (Designated_Type (It.Typ))
5218 and then Covers (Typ, Designated_Type (It.Typ)))
5221 It := Disambiguate (P, I1, I, Any_Type);
5223 if It = No_Interp then
5224 Error_Msg_N ("ambiguous prefix for slicing", N);
5229 Array_Type := It.Typ;
5234 Array_Type := It.Typ;
5239 Get_Next_Interp (I, It);
5244 Array_Type := Etype (Name);
5247 Resolve (Name, Array_Type);
5249 if Is_Access_Type (Array_Type) then
5250 Apply_Access_Check (N);
5251 Array_Type := Designated_Type (Array_Type);
5253 elsif Is_Entity_Name (Name)
5254 or else (Nkind (Name) = N_Function_Call
5255 and then not Is_Constrained (Etype (Name)))
5257 Array_Type := Get_Actual_Subtype (Name);
5260 -- If name was overloaded, set slice type correctly now
5262 Set_Etype (N, Array_Type);
5264 -- If the range is specified by a subtype mark, no resolution
5267 if not Is_Entity_Name (Drange) then
5268 Index := First_Index (Array_Type);
5269 Resolve (Drange, Base_Type (Etype (Index)));
5271 if Nkind (Drange) = N_Range then
5272 Apply_Range_Check (Drange, Etype (Index));
5276 Set_Slice_Subtype (N);
5281 ----------------------------
5282 -- Resolve_String_Literal --
5283 ----------------------------
5285 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
5286 C_Typ : constant Entity_Id := Component_Type (Typ);
5287 R_Typ : constant Entity_Id := Root_Type (C_Typ);
5288 Loc : constant Source_Ptr := Sloc (N);
5289 Str : constant String_Id := Strval (N);
5290 Strlen : constant Nat := String_Length (Str);
5291 Subtype_Id : Entity_Id;
5292 Need_Check : Boolean;
5295 -- For a string appearing in a concatenation, defer creation of the
5296 -- string_literal_subtype until the end of the resolution of the
5297 -- concatenation, because the literal may be constant-folded away.
5298 -- This is a useful optimization for long concatenation expressions.
5300 -- If the string is an aggregate built for a single character (which
5301 -- happens in a non-static context) or a is null string to which special
5302 -- checks may apply, we build the subtype. Wide strings must also get
5303 -- a string subtype if they come from a one character aggregate. Strings
5304 -- generated by attributes might be static, but it is often hard to
5305 -- determine whether the enclosing context is static, so we generate
5306 -- subtypes for them as well, thus losing some rarer optimizations ???
5307 -- Same for strings that come from a static conversion.
5310 (Strlen = 0 and then Typ /= Standard_String)
5311 or else Nkind (Parent (N)) /= N_Op_Concat
5312 or else (N /= Left_Opnd (Parent (N))
5313 and then N /= Right_Opnd (Parent (N)))
5314 or else (Typ = Standard_Wide_String
5315 and then Nkind (Original_Node (N)) /= N_String_Literal);
5317 -- If the resolving type is itself a string literal subtype, we
5318 -- can just reuse it, since there is no point in creating another.
5320 if Ekind (Typ) = E_String_Literal_Subtype then
5323 elsif Nkind (Parent (N)) = N_Op_Concat
5324 and then not Need_Check
5325 and then Nkind (Original_Node (N)) /= N_Character_Literal
5326 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
5327 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
5328 and then Nkind (Original_Node (N)) /= N_Type_Conversion
5332 -- Otherwise we must create a string literal subtype. Note that the
5333 -- whole idea of string literal subtypes is simply to avoid the need
5334 -- for building a full fledged array subtype for each literal.
5336 Set_String_Literal_Subtype (N, Typ);
5337 Subtype_Id := Etype (N);
5340 if Nkind (Parent (N)) /= N_Op_Concat
5343 Set_Etype (N, Subtype_Id);
5344 Eval_String_Literal (N);
5347 if Is_Limited_Composite (Typ)
5348 or else Is_Private_Composite (Typ)
5350 Error_Msg_N ("string literal not available for private array", N);
5351 Set_Etype (N, Any_Type);
5355 -- The validity of a null string has been checked in the
5356 -- call to Eval_String_Literal.
5361 -- Always accept string literal with component type Any_Character,
5362 -- which occurs in error situations and in comparisons of literals,
5363 -- both of which should accept all literals.
5365 elsif R_Typ = Any_Character then
5368 -- If the type is bit-packed, then we always tranform the string
5369 -- literal into a full fledged aggregate.
5371 elsif Is_Bit_Packed_Array (Typ) then
5374 -- Deal with cases of Wide_String and String
5377 -- For Standard.Wide_String, or any other type whose component
5378 -- type is Standard.Wide_Character, we know that all the
5379 -- characters in the string must be acceptable, since the parser
5380 -- accepted the characters as valid character literals.
5382 if R_Typ = Standard_Wide_Character then
5385 -- For the case of Standard.String, or any other type whose
5386 -- component type is Standard.Character, we must make sure that
5387 -- there are no wide characters in the string, i.e. that it is
5388 -- entirely composed of characters in range of type String.
5390 -- If the string literal is the result of a static concatenation,
5391 -- the test has already been performed on the components, and need
5394 elsif R_Typ = Standard_Character
5395 and then Nkind (Original_Node (N)) /= N_Op_Concat
5397 for J in 1 .. Strlen loop
5398 if not In_Character_Range (Get_String_Char (Str, J)) then
5400 -- If we are out of range, post error. This is one of the
5401 -- very few places that we place the flag in the middle of
5402 -- a token, right under the offending wide character.
5405 ("literal out of range of type Character",
5406 Source_Ptr (Int (Loc) + J));
5411 -- If the root type is not a standard character, then we will convert
5412 -- the string into an aggregate and will let the aggregate code do
5420 -- See if the component type of the array corresponding to the
5421 -- string has compile time known bounds. If yes we can directly
5422 -- check whether the evaluation of the string will raise constraint
5423 -- error. Otherwise we need to transform the string literal into
5424 -- the corresponding character aggregate and let the aggregate
5425 -- code do the checking.
5427 if R_Typ = Standard_Wide_Character
5428 or else R_Typ = Standard_Character
5430 -- Check for the case of full range, where we are definitely OK
5432 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
5436 -- Here the range is not the complete base type range, so check
5439 Comp_Typ_Lo : constant Node_Id :=
5440 Type_Low_Bound (Component_Type (Typ));
5441 Comp_Typ_Hi : constant Node_Id :=
5442 Type_High_Bound (Component_Type (Typ));
5447 if Compile_Time_Known_Value (Comp_Typ_Lo)
5448 and then Compile_Time_Known_Value (Comp_Typ_Hi)
5450 for J in 1 .. Strlen loop
5451 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
5453 if Char_Val < Expr_Value (Comp_Typ_Lo)
5454 or else Char_Val > Expr_Value (Comp_Typ_Hi)
5456 Apply_Compile_Time_Constraint_Error
5457 (N, "character out of range?",
5458 Loc => Source_Ptr (Int (Loc) + J));
5468 -- If we got here we meed to transform the string literal into the
5469 -- equivalent qualified positional array aggregate. This is rather
5470 -- heavy artillery for this situation, but it is hard work to avoid.
5473 Lits : List_Id := New_List;
5474 P : Source_Ptr := Loc + 1;
5478 -- Build the character literals, we give them source locations
5479 -- that correspond to the string positions, which is a bit tricky
5480 -- given the possible presence of wide character escape sequences.
5482 for J in 1 .. Strlen loop
5483 C := Get_String_Char (Str, J);
5484 Set_Character_Literal_Name (C);
5487 Make_Character_Literal (P, Name_Find, C));
5489 if In_Character_Range (C) then
5492 -- Should we have a call to Skip_Wide here ???
5500 Make_Qualified_Expression (Loc,
5501 Subtype_Mark => New_Reference_To (Typ, Loc),
5503 Make_Aggregate (Loc, Expressions => Lits)));
5505 Analyze_And_Resolve (N, Typ);
5507 end Resolve_String_Literal;
5509 -----------------------------
5510 -- Resolve_Subprogram_Info --
5511 -----------------------------
5513 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
5516 end Resolve_Subprogram_Info;
5518 -----------------------------
5519 -- Resolve_Type_Conversion --
5520 -----------------------------
5522 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
5523 Target_Type : constant Entity_Id := Etype (N);
5524 Conv_OK : constant Boolean := Conversion_OK (N);
5526 Opnd_Type : Entity_Id;
5530 Operand := Expression (N);
5533 and then not Valid_Conversion (N, Target_Type, Operand)
5538 if Etype (Operand) = Any_Fixed then
5540 -- Mixed-mode operation involving a literal. Context must be a fixed
5541 -- type which is applied to the literal subsequently.
5543 if Is_Fixed_Point_Type (Typ) then
5544 Set_Etype (Operand, Universal_Real);
5546 elsif Is_Numeric_Type (Typ)
5547 and then (Nkind (Operand) = N_Op_Multiply
5548 or else Nkind (Operand) = N_Op_Divide)
5549 and then (Etype (Right_Opnd (Operand)) = Universal_Real
5550 or else Etype (Left_Opnd (Operand)) = Universal_Real)
5552 if Unique_Fixed_Point_Type (N) = Any_Type then
5553 return; -- expression is ambiguous.
5555 Set_Etype (Operand, Standard_Duration);
5558 if Etype (Right_Opnd (Operand)) = Universal_Real then
5559 Rop := New_Copy_Tree (Right_Opnd (Operand));
5561 Rop := New_Copy_Tree (Left_Opnd (Operand));
5564 Resolve (Rop, Standard_Long_Long_Float);
5566 if Realval (Rop) /= Ureal_0
5567 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
5569 Error_Msg_N ("universal real operand can only be interpreted?",
5571 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
5575 Error_Msg_N ("invalid context for mixed mode operation", N);
5576 Set_Etype (Operand, Any_Type);
5581 Opnd_Type := Etype (Operand);
5582 Resolve (Operand, Opnd_Type);
5584 -- Note: we do the Eval_Type_Conversion call before applying the
5585 -- required checks for a subtype conversion. This is important,
5586 -- since both are prepared under certain circumstances to change
5587 -- the type conversion to a constraint error node, but in the case
5588 -- of Eval_Type_Conversion this may reflect an illegality in the
5589 -- static case, and we would miss the illegality (getting only a
5590 -- warning message), if we applied the type conversion checks first.
5592 Eval_Type_Conversion (N);
5594 -- If after evaluation, we still have a type conversion, then we
5595 -- may need to apply checks required for a subtype conversion.
5597 -- Skip these type conversion checks if universal fixed operands
5598 -- operands involved, since range checks are handled separately for
5599 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
5601 if Nkind (N) = N_Type_Conversion
5602 and then not Is_Generic_Type (Root_Type (Target_Type))
5603 and then Target_Type /= Universal_Fixed
5604 and then Opnd_Type /= Universal_Fixed
5606 Apply_Type_Conversion_Checks (N);
5609 -- Issue warning for conversion of simple object to its own type
5611 if Warn_On_Redundant_Constructs
5612 and then Comes_From_Source (N)
5613 and then Nkind (N) = N_Type_Conversion
5614 and then Is_Entity_Name (Expression (N))
5615 and then Etype (Entity (Expression (N))) = Target_Type
5618 ("?useless conversion, & has this type",
5619 N, Entity (Expression (N)));
5621 end Resolve_Type_Conversion;
5623 ----------------------
5624 -- Resolve_Unary_Op --
5625 ----------------------
5627 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
5628 B_Typ : Entity_Id := Base_Type (Typ);
5629 R : constant Node_Id := Right_Opnd (N);
5632 -- Generate warning for expressions like -5 mod 3
5634 if Paren_Count (N) = 0
5635 and then Nkind (N) = N_Op_Minus
5636 and then Nkind (Right_Opnd (N)) = N_Op_Mod
5639 ("?unary minus expression should be parenthesized here", N);
5642 if Etype (R) = Universal_Integer
5643 or else Etype (R) = Universal_Real
5645 Check_For_Visible_Operator (N, B_Typ);
5648 Set_Etype (N, B_Typ);
5650 Check_Unset_Reference (R);
5651 Generate_Operator_Reference (N);
5654 -- Set overflow checking bit. Much cleverer code needed here eventually
5655 -- and perhaps the Resolve routines should be separated for the various
5656 -- arithmetic operations, since they will need different processing ???
5658 if Nkind (N) in N_Op then
5659 if not Overflow_Checks_Suppressed (Etype (N)) then
5660 Set_Do_Overflow_Check (N, True);
5664 end Resolve_Unary_Op;
5666 ----------------------------------
5667 -- Resolve_Unchecked_Expression --
5668 ----------------------------------
5670 procedure Resolve_Unchecked_Expression
5675 Resolve (Expression (N), Typ, Suppress => All_Checks);
5677 end Resolve_Unchecked_Expression;
5679 ---------------------------------------
5680 -- Resolve_Unchecked_Type_Conversion --
5681 ---------------------------------------
5683 procedure Resolve_Unchecked_Type_Conversion
5687 Operand : constant Node_Id := Expression (N);
5688 Opnd_Type : constant Entity_Id := Etype (Operand);
5691 -- Resolve operand using its own type.
5693 Resolve (Operand, Opnd_Type);
5694 Eval_Unchecked_Conversion (N);
5696 end Resolve_Unchecked_Type_Conversion;
5698 ------------------------------
5699 -- Rewrite_Operator_As_Call --
5700 ------------------------------
5702 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
5703 Loc : Source_Ptr := Sloc (N);
5704 Actuals : List_Id := New_List;
5708 if Nkind (N) in N_Binary_Op then
5709 Append (Left_Opnd (N), Actuals);
5712 Append (Right_Opnd (N), Actuals);
5715 Make_Function_Call (Sloc => Loc,
5716 Name => New_Occurrence_Of (Nam, Loc),
5717 Parameter_Associations => Actuals);
5719 Preserve_Comes_From_Source (New_N, N);
5720 Preserve_Comes_From_Source (Name (New_N), N);
5722 Set_Etype (N, Etype (Nam));
5723 end Rewrite_Operator_As_Call;
5725 ------------------------------
5726 -- Rewrite_Renamed_Operator --
5727 ------------------------------
5729 procedure Rewrite_Renamed_Operator (N : Node_Id; Op : Entity_Id) is
5730 Nam : constant Name_Id := Chars (Op);
5731 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
5735 if Chars (N) /= Nam then
5737 -- Rewrite the operator node using the real operator, not its
5740 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
5741 Set_Chars (Op_Node, Nam);
5742 Set_Etype (Op_Node, Etype (N));
5743 Set_Entity (Op_Node, Op);
5744 Set_Right_Opnd (Op_Node, Right_Opnd (N));
5746 Generate_Reference (Op, N);
5749 Set_Left_Opnd (Op_Node, Left_Opnd (N));
5752 Rewrite (N, Op_Node);
5754 end Rewrite_Renamed_Operator;
5756 -----------------------
5757 -- Set_Slice_Subtype --
5758 -----------------------
5760 -- Build an implicit subtype declaration to represent the type delivered
5761 -- by the slice. This is an abbreviated version of an array subtype. We
5762 -- define an index subtype for the slice, using either the subtype name
5763 -- or the discrete range of the slice. To be consistent with index usage
5764 -- elsewhere, we create a list header to hold the single index. This list
5765 -- is not otherwise attached to the syntax tree.
5767 procedure Set_Slice_Subtype (N : Node_Id) is
5768 Loc : constant Source_Ptr := Sloc (N);
5770 Index_List : List_Id := New_List;
5771 Index_Subtype : Entity_Id;
5772 Index_Type : Entity_Id;
5773 Slice_Subtype : Entity_Id;
5774 Drange : constant Node_Id := Discrete_Range (N);
5777 if Is_Entity_Name (Drange) then
5778 Index_Subtype := Entity (Drange);
5781 -- We force the evaluation of a range. This is definitely needed in
5782 -- the renamed case, and seems safer to do unconditionally. Note in
5783 -- any case that since we will create and insert an Itype referring
5784 -- to this range, we must make sure any side effect removal actions
5785 -- are inserted before the Itype definition.
5787 if Nkind (Drange) = N_Range then
5788 Force_Evaluation (Low_Bound (Drange));
5789 Force_Evaluation (High_Bound (Drange));
5792 Index_Type := Base_Type (Etype (Drange));
5794 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
5796 Set_Scalar_Range (Index_Subtype, Drange);
5797 Set_Etype (Index_Subtype, Index_Type);
5798 Set_Size_Info (Index_Subtype, Index_Type);
5799 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
5802 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
5804 Index := New_Occurrence_Of (Index_Subtype, Loc);
5805 Set_Etype (Index, Index_Subtype);
5806 Append (Index, Index_List);
5808 Set_Component_Type (Slice_Subtype, Component_Type (Etype (N)));
5809 Set_First_Index (Slice_Subtype, Index);
5810 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
5811 Set_Is_Constrained (Slice_Subtype, True);
5812 Init_Size_Align (Slice_Subtype);
5814 Check_Compile_Time_Size (Slice_Subtype);
5816 -- The Etype of the existing Slice node is reset to this slice
5817 -- subtype. Its bounds are obtained from its first index.
5819 Set_Etype (N, Slice_Subtype);
5821 -- In the packed case, this must be immediately frozen
5823 -- Couldn't we always freeze here??? and if we did, then the above
5824 -- call to Check_Compile_Time_Size could be eliminated, which would
5825 -- be nice, because then that routine could be made private to Freeze.
5827 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
5828 Freeze_Itype (Slice_Subtype, N);
5831 end Set_Slice_Subtype;
5833 --------------------------------
5834 -- Set_String_Literal_Subtype --
5835 --------------------------------
5837 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
5838 Subtype_Id : Entity_Id;
5841 if Nkind (N) /= N_String_Literal then
5845 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
5848 Set_Component_Type (Subtype_Id, Component_Type (Typ));
5849 Set_String_Literal_Length (Subtype_Id,
5850 UI_From_Int (String_Length (Strval (N))));
5851 Set_Etype (Subtype_Id, Base_Type (Typ));
5852 Set_Is_Constrained (Subtype_Id);
5854 -- The low bound is set from the low bound of the corresponding
5855 -- index type. Note that we do not store the high bound in the
5856 -- string literal subtype, but it can be deduced if necssary
5857 -- from the length and the low bound.
5859 Set_String_Literal_Low_Bound
5860 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
5862 Set_Etype (N, Subtype_Id);
5863 end Set_String_Literal_Subtype;
5865 -----------------------------
5866 -- Unique_Fixed_Point_Type --
5867 -----------------------------
5869 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
5870 T1 : Entity_Id := Empty;
5875 procedure Fixed_Point_Error;
5876 -- If true ambiguity, give details.
5878 procedure Fixed_Point_Error is
5880 Error_Msg_N ("ambiguous universal_fixed_expression", N);
5881 Error_Msg_NE ("\possible interpretation as}", N, T1);
5882 Error_Msg_NE ("\possible interpretation as}", N, T2);
5883 end Fixed_Point_Error;
5886 -- The operations on Duration are visible, so Duration is always a
5887 -- possible interpretation.
5889 T1 := Standard_Duration;
5891 Scop := Current_Scope;
5893 -- Look for fixed-point types in enclosing scopes.
5895 while Scop /= Standard_Standard loop
5896 T2 := First_Entity (Scop);
5898 while Present (T2) loop
5899 if Is_Fixed_Point_Type (T2)
5900 and then Current_Entity (T2) = T2
5901 and then Scope (Base_Type (T2)) = Scop
5903 if Present (T1) then
5914 Scop := Scope (Scop);
5917 -- Look for visible fixed type declarations in the context.
5919 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
5921 while Present (Item) loop
5923 if Nkind (Item) = N_With_Clause then
5924 Scop := Entity (Name (Item));
5925 T2 := First_Entity (Scop);
5927 while Present (T2) loop
5928 if Is_Fixed_Point_Type (T2)
5929 and then Scope (Base_Type (T2)) = Scop
5930 and then (Is_Potentially_Use_Visible (T2)
5931 or else In_Use (T2))
5933 if Present (T1) then
5948 if Nkind (N) = N_Real_Literal then
5949 Error_Msg_NE ("real literal interpreted as }?", N, T1);
5952 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
5956 end Unique_Fixed_Point_Type;
5958 ----------------------
5959 -- Valid_Conversion --
5960 ----------------------
5962 function Valid_Conversion
5968 Target_Type : Entity_Id := Base_Type (Target);
5969 Opnd_Type : Entity_Id := Etype (Operand);
5971 function Conversion_Check
5975 -- Little routine to post Msg if Valid is False, returns Valid value
5977 function Valid_Tagged_Conversion
5978 (Target_Type : Entity_Id;
5979 Opnd_Type : Entity_Id)
5981 -- Specifically test for validity of tagged conversions
5983 ----------------------
5984 -- Conversion_Check --
5985 ----------------------
5987 function Conversion_Check
5994 Error_Msg_N (Msg, Operand);
5998 end Conversion_Check;
6000 -----------------------------
6001 -- Valid_Tagged_Conversion --
6002 -----------------------------
6004 function Valid_Tagged_Conversion
6005 (Target_Type : Entity_Id;
6006 Opnd_Type : Entity_Id)
6010 -- Upward conversions are allowed (RM 4.6(22)).
6012 if Covers (Target_Type, Opnd_Type)
6013 or else Is_Ancestor (Target_Type, Opnd_Type)
6017 -- Downward conversion are allowed if the operand is
6018 -- is class-wide (RM 4.6(23)).
6020 elsif Is_Class_Wide_Type (Opnd_Type)
6021 and then Covers (Opnd_Type, Target_Type)
6025 elsif Covers (Opnd_Type, Target_Type)
6026 or else Is_Ancestor (Opnd_Type, Target_Type)
6029 Conversion_Check (False,
6030 "downward conversion of tagged objects not allowed");
6033 ("invalid tagged conversion, not compatible with}",
6034 N, First_Subtype (Opnd_Type));
6037 end Valid_Tagged_Conversion;
6039 -- Start of processing for Valid_Conversion
6042 Check_Parameterless_Call (Operand);
6044 if Is_Overloaded (Operand) then
6053 -- Remove procedure calls, which syntactically cannot appear
6054 -- in this context, but which cannot be removed by type checking,
6055 -- because the context does not impose a type.
6057 Get_First_Interp (Operand, I, It);
6059 while Present (It.Typ) loop
6061 if It.Typ = Standard_Void_Type then
6065 Get_Next_Interp (I, It);
6068 Get_First_Interp (Operand, I, It);
6073 Error_Msg_N ("illegal operand in conversion", Operand);
6077 Get_Next_Interp (I, It);
6079 if Present (It.Typ) then
6081 It1 := Disambiguate (Operand, I1, I, Any_Type);
6083 if It1 = No_Interp then
6084 Error_Msg_N ("ambiguous operand in conversion", Operand);
6086 Error_Msg_Sloc := Sloc (It.Nam);
6087 Error_Msg_N ("possible interpretation#!", Operand);
6089 Error_Msg_Sloc := Sloc (N1);
6090 Error_Msg_N ("possible interpretation#!", Operand);
6096 Set_Etype (Operand, It1.Typ);
6097 Opnd_Type := It1.Typ;
6101 if Chars (Current_Scope) = Name_Unchecked_Conversion then
6103 -- This check is dubious, what if there were a user defined
6104 -- scope whose name was Unchecked_Conversion ???
6108 elsif Is_Numeric_Type (Target_Type) then
6109 if Opnd_Type = Universal_Fixed then
6112 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
6113 "illegal operand for numeric conversion");
6116 elsif Is_Array_Type (Target_Type) then
6117 if not Is_Array_Type (Opnd_Type)
6118 or else Opnd_Type = Any_Composite
6119 or else Opnd_Type = Any_String
6122 ("illegal operand for array conversion", Operand);
6125 elsif Number_Dimensions (Target_Type) /=
6126 Number_Dimensions (Opnd_Type)
6129 ("incompatible number of dimensions for conversion", Operand);
6134 Target_Index : Node_Id := First_Index (Target_Type);
6135 Opnd_Index : Node_Id := First_Index (Opnd_Type);
6137 Target_Index_Type : Entity_Id;
6138 Opnd_Index_Type : Entity_Id;
6140 Target_Comp_Type : Entity_Id := Component_Type (Target_Type);
6141 Opnd_Comp_Type : Entity_Id := Component_Type (Opnd_Type);
6144 while Present (Target_Index) and then Present (Opnd_Index) loop
6145 Target_Index_Type := Etype (Target_Index);
6146 Opnd_Index_Type := Etype (Opnd_Index);
6148 if not (Is_Integer_Type (Target_Index_Type)
6149 and then Is_Integer_Type (Opnd_Index_Type))
6150 and then (Root_Type (Target_Index_Type)
6151 /= Root_Type (Opnd_Index_Type))
6154 ("incompatible index types for array conversion",
6159 Next_Index (Target_Index);
6160 Next_Index (Opnd_Index);
6163 if Base_Type (Target_Comp_Type) /=
6164 Base_Type (Opnd_Comp_Type)
6167 ("incompatible component types for array conversion",
6172 Is_Constrained (Target_Comp_Type)
6173 /= Is_Constrained (Opnd_Comp_Type)
6174 or else not Subtypes_Statically_Match
6175 (Target_Comp_Type, Opnd_Comp_Type)
6178 ("component subtypes must statically match", Operand);
6187 elsif (Ekind (Target_Type) = E_General_Access_Type
6188 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
6191 (Is_Access_Type (Opnd_Type)
6192 and then Ekind (Opnd_Type) /=
6193 E_Access_Subprogram_Type
6194 and then Ekind (Opnd_Type) /=
6195 E_Access_Protected_Subprogram_Type,
6196 "must be an access-to-object type")
6198 if Is_Access_Constant (Opnd_Type)
6199 and then not Is_Access_Constant (Target_Type)
6202 ("access-to-constant operand type not allowed", Operand);
6206 -- Check the static accessibility rule of 4.6(17). Note that
6207 -- the check is not enforced when within an instance body, since
6208 -- the RM requires such cases to be caught at run time.
6210 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
6211 if Type_Access_Level (Opnd_Type)
6212 > Type_Access_Level (Target_Type)
6214 -- In an instance, this is a run-time check, but one we
6215 -- know will fail, so generate an appropriate warning.
6216 -- The raise will be generated by Expand_N_Type_Conversion.
6218 if In_Instance_Body then
6220 ("?cannot convert local pointer to non-local access type",
6223 ("?Program_Error will be raised at run time", Operand);
6227 ("cannot convert local pointer to non-local access type",
6232 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
6234 -- When the operand is a selected access discriminant
6235 -- the check needs to be made against the level of the
6236 -- object denoted by the prefix of the selected name.
6237 -- (Object_Access_Level handles checking the prefix
6238 -- of the operand for this case.)
6240 if Nkind (Operand) = N_Selected_Component
6241 and then Object_Access_Level (Operand)
6242 > Type_Access_Level (Target_Type)
6244 -- In an instance, this is a run-time check, but one we
6245 -- know will fail, so generate an appropriate warning.
6246 -- The raise will be generated by Expand_N_Type_Conversion.
6248 if In_Instance_Body then
6250 ("?cannot convert access discriminant to non-local" &
6251 " access type", Operand);
6253 ("?Program_Error will be raised at run time", Operand);
6257 ("cannot convert access discriminant to non-local" &
6258 " access type", Operand);
6263 -- The case of a reference to an access discriminant
6264 -- from within a type declaration (which will appear
6265 -- as a discriminal) is always illegal because the
6266 -- level of the discriminant is considered to be
6267 -- deeper than any (namable) access type.
6269 if Is_Entity_Name (Operand)
6270 and then (Ekind (Entity (Operand)) = E_In_Parameter
6271 or else Ekind (Entity (Operand)) = E_Constant)
6272 and then Present (Discriminal_Link (Entity (Operand)))
6275 ("discriminant has deeper accessibility level than target",
6283 Target : constant Entity_Id := Designated_Type (Target_Type);
6284 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
6287 if Is_Tagged_Type (Target) then
6288 return Valid_Tagged_Conversion (Target, Opnd);
6291 if Base_Type (Target) /= Base_Type (Opnd) then
6293 ("target designated type not compatible with }",
6294 N, Base_Type (Opnd));
6297 elsif not Subtypes_Statically_Match (Target, Opnd)
6298 and then (not Has_Discriminants (Target)
6299 or else Is_Constrained (Target))
6302 ("target designated subtype not compatible with }",
6312 elsif Ekind (Target_Type) = E_Access_Subprogram_Type
6313 and then Conversion_Check
6314 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
6315 "illegal operand for access subprogram conversion")
6317 -- Check that the designated types are subtype conformant
6319 if not Subtype_Conformant (Designated_Type (Opnd_Type),
6320 Designated_Type (Target_Type))
6323 ("operand type is not subtype conformant with target type",
6327 -- Check the static accessibility rule of 4.6(20)
6329 if Type_Access_Level (Opnd_Type) >
6330 Type_Access_Level (Target_Type)
6333 ("operand type has deeper accessibility level than target",
6336 -- Check that if the operand type is declared in a generic body,
6337 -- then the target type must be declared within that same body
6338 -- (enforces last sentence of 4.6(20)).
6340 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
6342 O_Gen : constant Node_Id :=
6343 Enclosing_Generic_Body (Opnd_Type);
6346 Enclosing_Generic_Body (Target_Type);
6349 while Present (T_Gen) and then T_Gen /= O_Gen loop
6350 T_Gen := Enclosing_Generic_Body (T_Gen);
6353 if T_Gen /= O_Gen then
6355 ("target type must be declared in same generic body"
6356 & " as operand type", N);
6363 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
6364 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
6366 -- It is valid to convert from one RAS type to another provided
6367 -- that their specification statically match.
6369 Check_Subtype_Conformant
6371 Designated_Type (Corresponding_Remote_Type (Target_Type)),
6373 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
6378 elsif Is_Tagged_Type (Target_Type) then
6379 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
6381 -- Types derived from the same root type are convertible.
6383 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
6386 -- In an instance, there may be inconsistent views of the same
6387 -- type, or types derived from the same type.
6390 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
6394 -- Special check for common access type error case
6396 elsif Ekind (Target_Type) = E_Access_Type
6397 and then Is_Access_Type (Opnd_Type)
6399 Error_Msg_N ("target type must be general access type!", N);
6400 Error_Msg_NE ("add ALL to }!", N, Target_Type);
6405 Error_Msg_NE ("invalid conversion, not compatible with }",
6410 end Valid_Conversion;