| ------------------------------------------------------------------------------ |
| -- -- |
| -- GNAT COMPILER COMPONENTS -- |
| -- -- |
| -- S E M _ C H 4 -- |
| -- -- |
| -- B o d y -- |
| -- -- |
| -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- |
| -- -- |
| -- GNAT is free software; you can redistribute it and/or modify it under -- |
| -- terms of the GNU General Public License as published by the Free Soft- -- |
| -- ware Foundation; either version 3, or (at your option) any later ver- -- |
| -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| -- for more details. You should have received a copy of the GNU General -- |
| -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| -- http://www.gnu.org/licenses for a complete copy of the license. -- |
| -- -- |
| -- GNAT was originally developed by the GNAT team at New York University. -- |
| -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| -- -- |
| ------------------------------------------------------------------------------ |
| |
| with Aspects; use Aspects; |
| with Atree; use Atree; |
| with Debug; use Debug; |
| with Einfo; use Einfo; |
| with Einfo.Entities; use Einfo.Entities; |
| with Einfo.Utils; use Einfo.Utils; |
| with Elists; use Elists; |
| with Errout; use Errout; |
| with Exp_Util; use Exp_Util; |
| with Itypes; use Itypes; |
| with Lib; use Lib; |
| with Lib.Xref; use Lib.Xref; |
| with Namet; use Namet; |
| with Namet.Sp; use Namet.Sp; |
| with Nlists; use Nlists; |
| with Nmake; use Nmake; |
| with Opt; use Opt; |
| with Output; use Output; |
| with Restrict; use Restrict; |
| with Rident; use Rident; |
| with Sem; use Sem; |
| with Sem_Aux; use Sem_Aux; |
| with Sem_Case; use Sem_Case; |
| with Sem_Cat; use Sem_Cat; |
| with Sem_Ch3; use Sem_Ch3; |
| with Sem_Ch6; use Sem_Ch6; |
| with Sem_Ch8; use Sem_Ch8; |
| with Sem_Dim; use Sem_Dim; |
| with Sem_Disp; use Sem_Disp; |
| with Sem_Dist; use Sem_Dist; |
| with Sem_Eval; use Sem_Eval; |
| with Sem_Res; use Sem_Res; |
| with Sem_Type; use Sem_Type; |
| with Sem_Util; use Sem_Util; |
| with Sem_Warn; use Sem_Warn; |
| with Stand; use Stand; |
| with Sinfo; use Sinfo; |
| with Sinfo.Nodes; use Sinfo.Nodes; |
| with Sinfo.Utils; use Sinfo.Utils; |
| with Snames; use Snames; |
| with Tbuild; use Tbuild; |
| with Uintp; use Uintp; |
| |
| package body Sem_Ch4 is |
| |
| -- Tables which speed up the identification of dangerous calls to Ada 2012 |
| -- functions with writable actuals (AI05-0144). |
| |
| -- The following table enumerates the Ada constructs which may evaluate in |
| -- arbitrary order. It does not cover all the language constructs which can |
| -- be evaluated in arbitrary order but the subset needed for AI05-0144. |
| |
| Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean := |
| (N_Aggregate => True, |
| N_Assignment_Statement => True, |
| N_Entry_Call_Statement => True, |
| N_Extension_Aggregate => True, |
| N_Full_Type_Declaration => True, |
| N_Indexed_Component => True, |
| N_Object_Declaration => True, |
| N_Pragma => True, |
| N_Range => True, |
| N_Slice => True, |
| N_Array_Type_Definition => True, |
| N_Membership_Test => True, |
| N_Binary_Op => True, |
| N_Subprogram_Call => True, |
| others => False); |
| |
| -- The following table enumerates the nodes on which we stop climbing when |
| -- locating the outermost Ada construct that can be evaluated in arbitrary |
| -- order. |
| |
| Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean := |
| (N_Aggregate => True, |
| N_Assignment_Statement => True, |
| N_Entry_Call_Statement => True, |
| N_Extended_Return_Statement => True, |
| N_Extension_Aggregate => True, |
| N_Full_Type_Declaration => True, |
| N_Object_Declaration => True, |
| N_Object_Renaming_Declaration => True, |
| N_Package_Specification => True, |
| N_Pragma => True, |
| N_Procedure_Call_Statement => True, |
| N_Simple_Return_Statement => True, |
| N_Has_Condition => True, |
| others => False); |
| |
| ----------------------- |
| -- Local Subprograms -- |
| ----------------------- |
| |
| procedure Analyze_Concatenation_Rest (N : Node_Id); |
| -- Does the "rest" of the work of Analyze_Concatenation, after the left |
| -- operand has been analyzed. See Analyze_Concatenation for details. |
| |
| procedure Analyze_Expression (N : Node_Id); |
| -- For expressions that are not names, this is just a call to analyze. If |
| -- the expression is a name, it may be a call to a parameterless function, |
| -- and if so must be converted into an explicit call node and analyzed as |
| -- such. This deproceduring must be done during the first pass of overload |
| -- resolution, because otherwise a procedure call with overloaded actuals |
| -- may fail to resolve. |
| |
| procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id); |
| -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an |
| -- operator name or an expanded name whose selector is an operator name, |
| -- and one possible interpretation is as a predefined operator. |
| |
| procedure Analyze_Overloaded_Selected_Component (N : Node_Id); |
| -- If the prefix of a selected_component is overloaded, the proper |
| -- interpretation that yields a record type with the proper selector |
| -- name must be selected. |
| |
| procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id); |
| -- Procedure to analyze a user defined binary operator, which is resolved |
| -- like a function, but instead of a list of actuals it is presented |
| -- with the left and right operands of an operator node. |
| |
| procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id); |
| -- Procedure to analyze a user defined unary operator, which is resolved |
| -- like a function, but instead of a list of actuals, it is presented with |
| -- the operand of the operator node. |
| |
| procedure Ambiguous_Operands (N : Node_Id); |
| -- For equality, membership, and comparison operators with overloaded |
| -- arguments, list possible interpretations. |
| |
| procedure Analyze_One_Call |
| (N : Node_Id; |
| Nam : Entity_Id; |
| Report : Boolean; |
| Success : out Boolean; |
| Skip_First : Boolean := False); |
| -- Check one interpretation of an overloaded subprogram name for |
| -- compatibility with the types of the actuals in a call. If there is a |
| -- single interpretation which does not match, post error if Report is |
| -- set to True. |
| -- |
| -- Nam is the entity that provides the formals against which the actuals |
| -- are checked. Nam is either the name of a subprogram, or the internal |
| -- subprogram type constructed for an access_to_subprogram. If the actuals |
| -- are compatible with Nam, then Nam is added to the list of candidate |
| -- interpretations for N, and Success is set to True. |
| -- |
| -- The flag Skip_First is used when analyzing a call that was rewritten |
| -- from object notation. In this case the first actual may have to receive |
| -- an explicit dereference, depending on the first formal of the operation |
| -- being called. The caller will have verified that the object is legal |
| -- for the call. If the remaining parameters match, the first parameter |
| -- will rewritten as a dereference if needed, prior to completing analysis. |
| |
| procedure Check_Misspelled_Selector |
| (Prefix : Entity_Id; |
| Sel : Node_Id); |
| -- Give possible misspelling message if Sel seems likely to be a mis- |
| -- spelling of one of the selectors of the Prefix. This is called by |
| -- Analyze_Selected_Component after producing an invalid selector error |
| -- message. |
| |
| function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean; |
| -- Verify that type T is declared in scope S. Used to find interpretations |
| -- for operators given by expanded names. This is abstracted as a separate |
| -- function to handle extensions to System, where S is System, but T is |
| -- declared in the extension. |
| |
| procedure Find_Arithmetic_Types |
| (L, R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- L and R are the operands of an arithmetic operator. Find consistent |
| -- pairs of interpretations for L and R that have a numeric type consistent |
| -- with the semantics of the operator. |
| |
| procedure Find_Comparison_Types |
| (L, R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- L and R are operands of a comparison operator. Find consistent pairs of |
| -- interpretations for L and R. |
| |
| procedure Find_Concatenation_Types |
| (L, R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- For the four varieties of concatenation |
| |
| procedure Find_Equality_Types |
| (L, R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- Ditto for equality operators |
| |
| procedure Find_Boolean_Types |
| (L, R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- Ditto for binary logical operations |
| |
| procedure Find_Negation_Types |
| (R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- Find consistent interpretation for operand of negation operator |
| |
| procedure Find_Non_Universal_Interpretations |
| (N : Node_Id; |
| R : Node_Id; |
| Op_Id : Entity_Id; |
| T1 : Entity_Id); |
| -- For equality and comparison operators, the result is always boolean, and |
| -- the legality of the operation is determined from the visibility of the |
| -- operand types. If one of the operands has a universal interpretation, |
| -- the legality check uses some compatible non-universal interpretation of |
| -- the other operand. N can be an operator node, or a function call whose |
| -- name is an operator designator. |
| |
| function Find_Primitive_Operation (N : Node_Id) return Boolean; |
| -- Find candidate interpretations for the name Obj.Proc when it appears in |
| -- a subprogram renaming declaration. |
| |
| procedure Find_Unary_Types |
| (R : Node_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- Unary arithmetic types: plus, minus, abs |
| |
| procedure Check_Arithmetic_Pair |
| (T1, T2 : Entity_Id; |
| Op_Id : Entity_Id; |
| N : Node_Id); |
| -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types |
| -- for left and right operand. Determine whether they constitute a valid |
| -- pair for the given operator, and record the corresponding interpretation |
| -- of the operator node. The node N may be an operator node (the usual |
| -- case) or a function call whose prefix is an operator designator. In |
| -- both cases Op_Id is the operator name itself. |
| |
| procedure Diagnose_Call (N : Node_Id; Nam : Node_Id); |
| -- Give detailed information on overloaded call where none of the |
| -- interpretations match. N is the call node, Nam the designator for |
| -- the overloaded entity being called. |
| |
| function Junk_Operand (N : Node_Id) return Boolean; |
| -- Test for an operand that is an inappropriate entity (e.g. a package |
| -- name or a label). If so, issue an error message and return True. If |
| -- the operand is not an inappropriate entity kind, return False. |
| |
| procedure Operator_Check (N : Node_Id); |
| -- Verify that an operator has received some valid interpretation. If none |
| -- was found, determine whether a use clause would make the operation |
| -- legal. The variable Candidate_Type (defined in Sem_Type) is set for |
| -- every type compatible with the operator, even if the operator for the |
| -- type is not directly visible. The routine uses this type to emit a more |
| -- informative message. |
| |
| function Has_Possible_Literal_Aspects (N : Node_Id) return Boolean; |
| -- Ada_2022: if an operand is a literal it may be subject to an |
| -- implicit conversion to a type for which a user-defined literal |
| -- function exists. During the first pass of type resolution we do |
| -- not know the context imposed on the literal, so we assume that |
| -- the literal type is a valid candidate and rely on the second pass |
| -- of resolution to find the type with the proper aspect. We only |
| -- add this interpretation if no other one was found, which may be |
| -- too restrictive but seems sufficient to handle most proper uses |
| -- of the new aspect. It is unclear whether a full implementation of |
| -- these aspects can be achieved without larger modifications to the |
| -- two-pass resolution algorithm. |
| |
| procedure Remove_Abstract_Operations (N : Node_Id); |
| -- Ada 2005: implementation of AI-310. An abstract non-dispatching |
| -- operation is not a candidate interpretation. |
| |
| function Try_Container_Indexing |
| (N : Node_Id; |
| Prefix : Node_Id; |
| Exprs : List_Id) return Boolean; |
| -- AI05-0139: Generalized indexing to support iterators over containers |
| -- ??? Need to provide a more detailed spec of what this function does |
| |
| function Try_Indexed_Call |
| (N : Node_Id; |
| Nam : Entity_Id; |
| Typ : Entity_Id; |
| Skip_First : Boolean) return Boolean; |
| -- If a function has defaults for all its actuals, a call to it may in fact |
| -- be an indexing on the result of the call. Try_Indexed_Call attempts the |
| -- interpretation as an indexing, prior to analysis as a call. If both are |
| -- possible, the node is overloaded with both interpretations (same symbol |
| -- but two different types). If the call is written in prefix form, the |
| -- prefix becomes the first parameter in the call, and only the remaining |
| -- actuals must be checked for the presence of defaults. |
| |
| function Try_Indirect_Call |
| (N : Node_Id; |
| Nam : Entity_Id; |
| Typ : Entity_Id) return Boolean; |
| -- Similarly, a function F that needs no actuals can return an access to a |
| -- subprogram, and the call F (X) interpreted as F.all (X). In this case |
| -- the call may be overloaded with both interpretations. |
| |
| procedure wpo (T : Entity_Id); |
| pragma Warnings (Off, wpo); |
| -- Used for debugging: obtain list of primitive operations even if |
| -- type is not frozen and dispatch table is not built yet. |
| |
| ------------------------ |
| -- Ambiguous_Operands -- |
| ------------------------ |
| |
| procedure Ambiguous_Operands (N : Node_Id) is |
| procedure List_Operand_Interps (Opnd : Node_Id); |
| |
| -------------------------- |
| -- List_Operand_Interps -- |
| -------------------------- |
| |
| procedure List_Operand_Interps (Opnd : Node_Id) is |
| Nam : Node_Id := Empty; |
| Err : Node_Id := N; |
| |
| begin |
| if Is_Overloaded (Opnd) then |
| if Nkind (Opnd) in N_Op then |
| Nam := Opnd; |
| |
| elsif Nkind (Opnd) = N_Function_Call then |
| Nam := Name (Opnd); |
| |
| elsif Ada_Version >= Ada_2012 then |
| declare |
| It : Interp; |
| I : Interp_Index; |
| |
| begin |
| Get_First_Interp (Opnd, I, It); |
| while Present (It.Nam) loop |
| if Has_Implicit_Dereference (It.Typ) then |
| Error_Msg_N |
| ("can be interpreted as implicit dereference", Opnd); |
| return; |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end; |
| |
| return; |
| end if; |
| |
| else |
| return; |
| end if; |
| |
| if Opnd = Left_Opnd (N) then |
| Error_Msg_N |
| ("\left operand has the following interpretations", N); |
| else |
| Error_Msg_N |
| ("\right operand has the following interpretations", N); |
| Err := Opnd; |
| end if; |
| |
| List_Interps (Nam, Err); |
| end List_Operand_Interps; |
| |
| -- Start of processing for Ambiguous_Operands |
| |
| begin |
| if Nkind (N) in N_Membership_Test then |
| Error_Msg_N ("ambiguous operands for membership", N); |
| |
| elsif Nkind (N) in N_Op_Eq | N_Op_Ne then |
| Error_Msg_N ("ambiguous operands for equality", N); |
| |
| else |
| Error_Msg_N ("ambiguous operands for comparison", N); |
| end if; |
| |
| if All_Errors_Mode then |
| List_Operand_Interps (Left_Opnd (N)); |
| List_Operand_Interps (Right_Opnd (N)); |
| else |
| Error_Msg_N ("\use -gnatf switch for details", N); |
| end if; |
| end Ambiguous_Operands; |
| |
| ----------------------- |
| -- Analyze_Aggregate -- |
| ----------------------- |
| |
| -- Most of the analysis of Aggregates requires that the type be known, and |
| -- is therefore put off until resolution of the context. Delta aggregates |
| -- have a base component that determines the enclosing aggregate type so |
| -- its type can be ascertained earlier. This also allows delta aggregates |
| -- to appear in the context of a record type with a private extension, as |
| -- per the latest update of AI12-0127. |
| |
| procedure Analyze_Aggregate (N : Node_Id) is |
| begin |
| if No (Etype (N)) then |
| if Nkind (N) = N_Delta_Aggregate then |
| declare |
| Base : constant Node_Id := Expression (N); |
| |
| I : Interp_Index; |
| It : Interp; |
| |
| begin |
| Analyze (Base); |
| |
| -- If the base is overloaded, propagate interpretations to the |
| -- enclosing aggregate. |
| |
| if Is_Overloaded (Base) then |
| Get_First_Interp (Base, I, It); |
| Set_Etype (N, Any_Type); |
| |
| while Present (It.Nam) loop |
| Add_One_Interp (N, It.Typ, It.Typ); |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| else |
| Set_Etype (N, Etype (Base)); |
| end if; |
| end; |
| |
| else |
| Set_Etype (N, Any_Composite); |
| end if; |
| end if; |
| end Analyze_Aggregate; |
| |
| ----------------------- |
| -- Analyze_Allocator -- |
| ----------------------- |
| |
| procedure Analyze_Allocator (N : Node_Id) is |
| Loc : constant Source_Ptr := Sloc (N); |
| Sav_Errs : constant Nat := Serious_Errors_Detected; |
| E : Node_Id := Expression (N); |
| Acc_Type : Entity_Id; |
| Type_Id : Entity_Id; |
| P : Node_Id; |
| C : Node_Id; |
| Onode : Node_Id; |
| |
| begin |
| -- Deal with allocator restrictions |
| |
| -- In accordance with H.4(7), the No_Allocators restriction only applies |
| -- to user-written allocators. The same consideration applies to the |
| -- No_Standard_Allocators_Before_Elaboration restriction. |
| |
| if Comes_From_Source (N) then |
| Check_Restriction (No_Allocators, N); |
| |
| -- Processing for No_Standard_Allocators_After_Elaboration, loop to |
| -- look at enclosing context, checking task/main subprogram case. |
| |
| C := N; |
| P := Parent (C); |
| while Present (P) loop |
| |
| -- For the task case we need a handled sequence of statements, |
| -- where the occurrence of the allocator is within the statements |
| -- and the parent is a task body |
| |
| if Nkind (P) = N_Handled_Sequence_Of_Statements |
| and then Is_List_Member (C) |
| and then List_Containing (C) = Statements (P) |
| then |
| Onode := Original_Node (Parent (P)); |
| |
| -- Check for allocator within task body, this is a definite |
| -- violation of No_Allocators_After_Elaboration we can detect |
| -- at compile time. |
| |
| if Nkind (Onode) = N_Task_Body then |
| Check_Restriction |
| (No_Standard_Allocators_After_Elaboration, N); |
| exit; |
| end if; |
| end if; |
| |
| -- The other case is appearance in a subprogram body. This is |
| -- a violation if this is a library level subprogram with no |
| -- parameters. Note that this is now a static error even if the |
| -- subprogram is not the main program (this is a change, in an |
| -- earlier version only the main program was affected, and the |
| -- check had to be done in the binder). |
| |
| if Nkind (P) = N_Subprogram_Body |
| and then Nkind (Parent (P)) = N_Compilation_Unit |
| and then No (Parameter_Specifications (Specification (P))) |
| then |
| Check_Restriction |
| (No_Standard_Allocators_After_Elaboration, N); |
| end if; |
| |
| C := P; |
| P := Parent (C); |
| end loop; |
| end if; |
| |
| -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if |
| -- any. The expected type for the name is any type. A non-overloading |
| -- rule then requires it to be of a type descended from |
| -- System.Storage_Pools.Subpools.Subpool_Handle. |
| |
| -- This isn't exactly what the AI says, but it seems to be the right |
| -- rule. The AI should be fixed.??? |
| |
| declare |
| Subpool : constant Node_Id := Subpool_Handle_Name (N); |
| |
| begin |
| if Present (Subpool) then |
| Analyze (Subpool); |
| |
| if Is_Overloaded (Subpool) then |
| Error_Msg_N ("ambiguous subpool handle", Subpool); |
| end if; |
| |
| -- Check that Etype (Subpool) is descended from Subpool_Handle |
| |
| Resolve (Subpool); |
| end if; |
| end; |
| |
| -- Analyze the qualified expression or subtype indication |
| |
| if Nkind (E) = N_Qualified_Expression then |
| Acc_Type := Create_Itype (E_Allocator_Type, N); |
| Set_Etype (Acc_Type, Acc_Type); |
| Find_Type (Subtype_Mark (E)); |
| |
| -- Analyze the qualified expression, and apply the name resolution |
| -- rule given in 4.7(3). |
| |
| Analyze (E); |
| Type_Id := Etype (E); |
| Set_Directly_Designated_Type (Acc_Type, Type_Id); |
| |
| -- A qualified expression requires an exact match of the type, |
| -- class-wide matching is not allowed. |
| |
| -- if Is_Class_Wide_Type (Type_Id) |
| -- and then Base_Type |
| -- (Etype (Expression (E))) /= Base_Type (Type_Id) |
| -- then |
| -- Wrong_Type (Expression (E), Type_Id); |
| -- end if; |
| |
| -- We don't analyze the qualified expression itself because it's |
| -- part of the allocator. It is fully analyzed and resolved when |
| -- the allocator is resolved with the context type. |
| |
| Set_Etype (E, Type_Id); |
| |
| -- Case where allocator has a subtype indication |
| |
| else |
| -- If the allocator includes a N_Subtype_Indication then a |
| -- constraint is present, otherwise the node is a subtype mark. |
| -- Introduce an explicit subtype declaration into the tree |
| -- defining some anonymous subtype and rewrite the allocator to |
| -- use this subtype rather than the subtype indication. |
| |
| -- It is important to introduce the explicit subtype declaration |
| -- so that the bounds of the subtype indication are attached to |
| -- the tree in case the allocator is inside a generic unit. |
| |
| -- Finally, if there is no subtype indication and the type is |
| -- a tagged unconstrained type with discriminants, the designated |
| -- object is constrained by their default values, and it is |
| -- simplest to introduce an explicit constraint now. In some cases |
| -- this is done during expansion, but freeze actions are certain |
| -- to be emitted in the proper order if constraint is explicit. |
| |
| if Is_Entity_Name (E) and then Expander_Active then |
| Find_Type (E); |
| Type_Id := Entity (E); |
| |
| if Is_Tagged_Type (Type_Id) |
| and then Has_Defaulted_Discriminants (Type_Id) |
| and then not Is_Constrained (Type_Id) |
| then |
| declare |
| Constr : constant List_Id := New_List; |
| Loc : constant Source_Ptr := Sloc (E); |
| Discr : Entity_Id := First_Discriminant (Type_Id); |
| |
| begin |
| while Present (Discr) loop |
| Append (Discriminant_Default_Value (Discr), Constr); |
| Next_Discriminant (Discr); |
| end loop; |
| |
| Rewrite (E, |
| Make_Subtype_Indication (Loc, |
| Subtype_Mark => New_Occurrence_Of (Type_Id, Loc), |
| Constraint => |
| Make_Index_Or_Discriminant_Constraint (Loc, |
| Constraints => Constr))); |
| end; |
| end if; |
| end if; |
| |
| if Nkind (E) = N_Subtype_Indication then |
| declare |
| Def_Id : Entity_Id; |
| Base_Typ : Entity_Id; |
| |
| begin |
| -- A constraint is only allowed for a composite type in Ada |
| -- 95. In Ada 83, a constraint is also allowed for an |
| -- access-to-composite type, but the constraint is ignored. |
| |
| Find_Type (Subtype_Mark (E)); |
| Base_Typ := Entity (Subtype_Mark (E)); |
| |
| if Is_Elementary_Type (Base_Typ) then |
| if not (Ada_Version = Ada_83 |
| and then Is_Access_Type (Base_Typ)) |
| then |
| Error_Msg_N ("constraint not allowed here", E); |
| |
| if Nkind (Constraint (E)) = |
| N_Index_Or_Discriminant_Constraint |
| then |
| Error_Msg_N -- CODEFIX |
| ("\if qualified expression was meant, " & |
| "use apostrophe", Constraint (E)); |
| end if; |
| end if; |
| |
| -- Get rid of the bogus constraint: |
| |
| Rewrite (E, New_Copy_Tree (Subtype_Mark (E))); |
| Analyze_Allocator (N); |
| return; |
| end if; |
| |
| -- In GNATprove mode we need to preserve the link between |
| -- the original subtype indication and the anonymous subtype, |
| -- to extend proofs to constrained access types. We only do |
| -- that outside of spec expressions, otherwise the declaration |
| -- cannot be inserted and analyzed. In such a case, GNATprove |
| -- later rejects the allocator as it is not used here in |
| -- a non-interfering context (SPARK 4.8(2) and 7.1.3(10)). |
| |
| if Expander_Active |
| or else (GNATprove_Mode and then not In_Spec_Expression) |
| then |
| Def_Id := Make_Temporary (Loc, 'S'); |
| |
| Insert_Action (E, |
| Make_Subtype_Declaration (Loc, |
| Defining_Identifier => Def_Id, |
| Subtype_Indication => Relocate_Node (E))); |
| |
| if Sav_Errs /= Serious_Errors_Detected |
| and then Nkind (Constraint (E)) = |
| N_Index_Or_Discriminant_Constraint |
| then |
| Error_Msg_N -- CODEFIX |
| ("if qualified expression was meant, use apostrophe!", |
| Constraint (E)); |
| end if; |
| |
| E := New_Occurrence_Of (Def_Id, Loc); |
| Rewrite (Expression (N), E); |
| end if; |
| end; |
| end if; |
| |
| Type_Id := Process_Subtype (E, N); |
| Acc_Type := Create_Itype (E_Allocator_Type, N); |
| Set_Etype (Acc_Type, Acc_Type); |
| Set_Directly_Designated_Type (Acc_Type, Type_Id); |
| Check_Fully_Declared (Type_Id, N); |
| |
| -- Ada 2005 (AI-231): If the designated type is itself an access |
| -- type that excludes null, its default initialization will |
| -- be a null object, and we can insert an unconditional raise |
| -- before the allocator. |
| |
| -- Ada 2012 (AI-104): A not null indication here is altogether |
| -- illegal. |
| |
| if Can_Never_Be_Null (Type_Id) then |
| declare |
| Not_Null_Check : constant Node_Id := |
| Make_Raise_Constraint_Error (Sloc (E), |
| Reason => CE_Null_Not_Allowed); |
| |
| begin |
| if Expander_Active then |
| Insert_Action (N, Not_Null_Check); |
| Analyze (Not_Null_Check); |
| |
| elsif Warn_On_Ada_2012_Compatibility then |
| Error_Msg_N |
| ("null value not allowed here in Ada 2012?y?", E); |
| end if; |
| end; |
| end if; |
| |
| -- Check for missing initialization. Skip this check if we already |
| -- had errors on analyzing the allocator, since in that case these |
| -- are probably cascaded errors. |
| |
| if not Is_Definite_Subtype (Type_Id) |
| and then Serious_Errors_Detected = Sav_Errs |
| then |
| -- The build-in-place machinery may produce an allocator when |
| -- the designated type is indefinite but the underlying type is |
| -- not. In this case the unknown discriminants are meaningless |
| -- and should not trigger error messages. Check the parent node |
| -- because the allocator is marked as coming from source. |
| |
| if Present (Underlying_Type (Type_Id)) |
| and then Is_Definite_Subtype (Underlying_Type (Type_Id)) |
| and then not Comes_From_Source (Parent (N)) |
| then |
| null; |
| |
| -- An unusual case arises when the parent of a derived type is |
| -- a limited record extension with unknown discriminants, and |
| -- its full view has no discriminants. |
| -- |
| -- A more general fix might be to create the proper underlying |
| -- type for such a derived type, but it is a record type with |
| -- no private attributes, so this required extending the |
| -- meaning of this attribute. ??? |
| |
| elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private |
| and then Present (Underlying_Type (Etype (Type_Id))) |
| and then |
| not Has_Discriminants (Underlying_Type (Etype (Type_Id))) |
| and then not Comes_From_Source (Parent (N)) |
| then |
| null; |
| |
| elsif Is_Class_Wide_Type (Type_Id) then |
| Error_Msg_N |
| ("initialization required in class-wide allocation", N); |
| |
| else |
| if Ada_Version < Ada_2005 |
| and then Is_Limited_Type (Type_Id) |
| then |
| Error_Msg_N ("unconstrained allocation not allowed", N); |
| |
| if Is_Array_Type (Type_Id) then |
| Error_Msg_N |
| ("\constraint with array bounds required", N); |
| |
| elsif Has_Unknown_Discriminants (Type_Id) then |
| null; |
| |
| else pragma Assert (Has_Discriminants (Type_Id)); |
| Error_Msg_N |
| ("\constraint with discriminant values required", N); |
| end if; |
| |
| -- Limited Ada 2005 and general nonlimited case. |
| -- This is an error, except in the case of an |
| -- uninitialized allocator that is generated |
| -- for a build-in-place function return of a |
| -- discriminated but compile-time-known-size |
| -- type. |
| |
| else |
| if Original_Node (N) /= N |
| and then Nkind (Original_Node (N)) = N_Allocator |
| then |
| declare |
| Qual : constant Node_Id := |
| Expression (Original_Node (N)); |
| pragma Assert |
| (Nkind (Qual) = N_Qualified_Expression); |
| Call : constant Node_Id := Expression (Qual); |
| pragma Assert |
| (Is_Expanded_Build_In_Place_Call (Call)); |
| begin |
| null; |
| end; |
| |
| else |
| Error_Msg_N |
| ("uninitialized unconstrained allocation not " |
| & "allowed", N); |
| |
| if Is_Array_Type (Type_Id) then |
| Error_Msg_N |
| ("\qualified expression or constraint with " |
| & "array bounds required", N); |
| |
| elsif Has_Unknown_Discriminants (Type_Id) then |
| Error_Msg_N ("\qualified expression required", N); |
| |
| else pragma Assert (Has_Discriminants (Type_Id)); |
| Error_Msg_N |
| ("\qualified expression or constraint with " |
| & "discriminant values required", N); |
| end if; |
| end if; |
| end if; |
| end if; |
| end if; |
| end if; |
| |
| if Is_Abstract_Type (Type_Id) then |
| Error_Msg_N ("cannot allocate abstract object", E); |
| end if; |
| |
| if Has_Task (Designated_Type (Acc_Type)) then |
| Check_Restriction (No_Tasking, N); |
| Check_Restriction (Max_Tasks, N); |
| Check_Restriction (No_Task_Allocators, N); |
| end if; |
| |
| -- Check restriction against dynamically allocated protected objects |
| |
| if Has_Protected (Designated_Type (Acc_Type)) then |
| Check_Restriction (No_Protected_Type_Allocators, N); |
| end if; |
| |
| -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access |
| -- type is nested, and the designated type needs finalization. The rule |
| -- is conservative in that class-wide types need finalization. |
| |
| if Needs_Finalization (Designated_Type (Acc_Type)) |
| and then not Is_Library_Level_Entity (Acc_Type) |
| then |
| Check_Restriction (No_Nested_Finalization, N); |
| end if; |
| |
| -- Check that an allocator of a nested access type doesn't create a |
| -- protected object when restriction No_Local_Protected_Objects applies. |
| |
| if Has_Protected (Designated_Type (Acc_Type)) |
| and then not Is_Library_Level_Entity (Acc_Type) |
| then |
| Check_Restriction (No_Local_Protected_Objects, N); |
| end if; |
| |
| -- Likewise for No_Local_Timing_Events |
| |
| if Has_Timing_Event (Designated_Type (Acc_Type)) |
| and then not Is_Library_Level_Entity (Acc_Type) |
| then |
| Check_Restriction (No_Local_Timing_Events, N); |
| end if; |
| |
| -- If the No_Streams restriction is set, check that the type of the |
| -- object is not, and does not contain, any subtype derived from |
| -- Ada.Streams.Root_Stream_Type. Note that we guard the call to |
| -- Has_Stream just for efficiency reasons. There is no point in |
| -- spending time on a Has_Stream check if the restriction is not set. |
| |
| if Restriction_Check_Required (No_Streams) then |
| if Has_Stream (Designated_Type (Acc_Type)) then |
| Check_Restriction (No_Streams, N); |
| end if; |
| end if; |
| |
| Set_Etype (N, Acc_Type); |
| |
| if not Is_Library_Level_Entity (Acc_Type) then |
| Check_Restriction (No_Local_Allocators, N); |
| end if; |
| |
| if Serious_Errors_Detected > Sav_Errs then |
| Set_Error_Posted (N); |
| Set_Etype (N, Any_Type); |
| end if; |
| end Analyze_Allocator; |
| |
| --------------------------- |
| -- Analyze_Arithmetic_Op -- |
| --------------------------- |
| |
| procedure Analyze_Arithmetic_Op (N : Node_Id) is |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id; |
| |
| begin |
| Candidate_Type := Empty; |
| Analyze_Expression (L); |
| Analyze_Expression (R); |
| |
| -- If the entity is already set, the node is the instantiation of a |
| -- generic node with a non-local reference, or was manufactured by a |
| -- call to Make_Op_xxx. In either case the entity is known to be valid, |
| -- and we do not need to collect interpretations, instead we just get |
| -- the single possible interpretation. |
| |
| Op_Id := Entity (N); |
| |
| if Present (Op_Id) then |
| if Ekind (Op_Id) = E_Operator then |
| Set_Etype (N, Any_Type); |
| Find_Arithmetic_Types (L, R, Op_Id, N); |
| else |
| Set_Etype (N, Any_Type); |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| -- Entity is not already set, so we do need to collect interpretations |
| |
| else |
| Set_Etype (N, Any_Type); |
| |
| Op_Id := Get_Name_Entity_Id (Chars (N)); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator |
| and then Present (Next_Entity (First_Entity (Op_Id))) |
| then |
| Find_Arithmetic_Types (L, R, Op_Id, N); |
| |
| -- The following may seem superfluous, because an operator cannot |
| -- be generic, but this ignores the cleverness of the author of |
| -- ACVC bc1013a. |
| |
| elsif Is_Overloadable (Op_Id) then |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| Operator_Check (N); |
| Check_Function_Writable_Actuals (N); |
| end Analyze_Arithmetic_Op; |
| |
| ------------------ |
| -- Analyze_Call -- |
| ------------------ |
| |
| -- Function, procedure, and entry calls are checked here. The Name in |
| -- the call may be overloaded. The actuals have been analyzed and may |
| -- themselves be overloaded. On exit from this procedure, the node N |
| -- may have zero, one or more interpretations. In the first case an |
| -- error message is produced. In the last case, the node is flagged |
| -- as overloaded and the interpretations are collected in All_Interp. |
| |
| -- If the name is an Access_To_Subprogram, it cannot be overloaded, but |
| -- the type-checking is similar to that of other calls. |
| |
| procedure Analyze_Call (N : Node_Id) is |
| Actuals : constant List_Id := Parameter_Associations (N); |
| Loc : constant Source_Ptr := Sloc (N); |
| Nam : Node_Id; |
| X : Interp_Index; |
| It : Interp; |
| Nam_Ent : Entity_Id := Empty; |
| Success : Boolean := False; |
| |
| Deref : Boolean := False; |
| -- Flag indicates whether an interpretation of the prefix is a |
| -- parameterless call that returns an access_to_subprogram. |
| |
| procedure Check_Writable_Actuals (N : Node_Id); |
| -- If the call has out or in-out parameters then mark its outermost |
| -- enclosing construct as a node on which the writable actuals check |
| -- must be performed. |
| |
| function Name_Denotes_Function return Boolean; |
| -- If the type of the name is an access to subprogram, this may be the |
| -- type of a name, or the return type of the function being called. If |
| -- the name is not an entity then it can denote a protected function. |
| -- Until we distinguish Etype from Return_Type, we must use this routine |
| -- to resolve the meaning of the name in the call. |
| |
| procedure No_Interpretation; |
| -- Output error message when no valid interpretation exists |
| |
| ---------------------------- |
| -- Check_Writable_Actuals -- |
| ---------------------------- |
| |
| -- The identification of conflicts in calls to functions with writable |
| -- actuals is performed in the analysis phase of the front end to ensure |
| -- that it reports exactly the same errors compiling with and without |
| -- expansion enabled. It is performed in two stages: |
| |
| -- 1) When a call to a function with out-mode parameters is found, |
| -- we climb to the outermost enclosing construct that can be |
| -- evaluated in arbitrary order and we mark it with the flag |
| -- Check_Actuals. |
| |
| -- 2) When the analysis of the marked node is complete, we traverse |
| -- its decorated subtree searching for conflicts (see function |
| -- Sem_Util.Check_Function_Writable_Actuals). |
| |
| -- The unique exception to this general rule is for aggregates, since |
| -- their analysis is performed by the front end in the resolution |
| -- phase. For aggregates we do not climb to their enclosing construct: |
| -- we restrict the analysis to the subexpressions initializing the |
| -- aggregate components. |
| |
| -- This implies that the analysis of expressions containing aggregates |
| -- is not complete, since there may be conflicts on writable actuals |
| -- involving subexpressions of the enclosing logical or arithmetic |
| -- expressions. However, we cannot wait and perform the analysis when |
| -- the whole subtree is resolved, since the subtrees may be transformed, |
| -- thus adding extra complexity and computation cost to identify and |
| -- report exactly the same errors compiling with and without expansion |
| -- enabled. |
| |
| procedure Check_Writable_Actuals (N : Node_Id) is |
| begin |
| if Comes_From_Source (N) |
| and then Present (Get_Subprogram_Entity (N)) |
| and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N)) |
| then |
| -- For procedures and entries there is no need to climb since |
| -- we only need to check if the actuals of this call invoke |
| -- functions whose out-mode parameters overlap. |
| |
| if Nkind (N) /= N_Function_Call then |
| Set_Check_Actuals (N); |
| |
| -- For calls to functions we climb to the outermost enclosing |
| -- construct where the out-mode actuals of this function may |
| -- introduce conflicts. |
| |
| else |
| declare |
| Outermost : Node_Id := Empty; -- init to avoid warning |
| P : Node_Id := N; |
| |
| begin |
| while Present (P) loop |
| -- For object declarations we can climb to the node from |
| -- its object definition branch or from its initializing |
| -- expression. We prefer to mark the child node as the |
| -- outermost construct to avoid adding further complexity |
| -- to the routine that will later take care of |
| -- performing the writable actuals check. |
| |
| if Has_Arbitrary_Evaluation_Order (Nkind (P)) |
| and then Nkind (P) not in |
| N_Assignment_Statement | N_Object_Declaration |
| then |
| Outermost := P; |
| end if; |
| |
| -- Avoid climbing more than needed |
| |
| exit when Stop_Subtree_Climbing (Nkind (P)) |
| or else (Nkind (P) = N_Range |
| and then |
| Nkind (Parent (P)) not in N_In | N_Not_In); |
| |
| P := Parent (P); |
| end loop; |
| |
| Set_Check_Actuals (Outermost); |
| end; |
| end if; |
| end if; |
| end Check_Writable_Actuals; |
| |
| --------------------------- |
| -- Name_Denotes_Function -- |
| --------------------------- |
| |
| function Name_Denotes_Function return Boolean is |
| begin |
| if Is_Entity_Name (Nam) then |
| return Ekind (Entity (Nam)) = E_Function; |
| elsif Nkind (Nam) = N_Selected_Component then |
| return Ekind (Entity (Selector_Name (Nam))) = E_Function; |
| else |
| return False; |
| end if; |
| end Name_Denotes_Function; |
| |
| ----------------------- |
| -- No_Interpretation -- |
| ----------------------- |
| |
| procedure No_Interpretation is |
| L : constant Boolean := Is_List_Member (N); |
| K : constant Node_Kind := Nkind (Parent (N)); |
| |
| begin |
| -- If the node is in a list whose parent is not an expression then it |
| -- must be an attempted procedure call. |
| |
| if L and then K not in N_Subexpr then |
| if Ekind (Entity (Nam)) = E_Generic_Procedure then |
| Error_Msg_NE |
| ("must instantiate generic procedure& before call", |
| Nam, Entity (Nam)); |
| else |
| Error_Msg_N ("procedure or entry name expected", Nam); |
| end if; |
| |
| -- Check for tasking cases where only an entry call will do |
| |
| elsif not L |
| and then K in N_Entry_Call_Alternative | N_Triggering_Alternative |
| then |
| Error_Msg_N ("entry name expected", Nam); |
| |
| -- Otherwise give general error message |
| |
| else |
| Error_Msg_N ("invalid prefix in call", Nam); |
| end if; |
| end No_Interpretation; |
| |
| -- Start of processing for Analyze_Call |
| |
| begin |
| -- Initialize the type of the result of the call to the error type, |
| -- which will be reset if the type is successfully resolved. |
| |
| Set_Etype (N, Any_Type); |
| |
| Nam := Name (N); |
| |
| if not Is_Overloaded (Nam) then |
| |
| -- Only one interpretation to check |
| |
| if Ekind (Etype (Nam)) = E_Subprogram_Type then |
| Nam_Ent := Etype (Nam); |
| |
| -- If the prefix is an access_to_subprogram, this may be an indirect |
| -- call. This is the case if the name in the call is not an entity |
| -- name, or if it is a function name in the context of a procedure |
| -- call. In this latter case, we have a call to a parameterless |
| -- function that returns a pointer_to_procedure which is the entity |
| -- being called. Finally, F (X) may be a call to a parameterless |
| -- function that returns a pointer to a function with parameters. |
| -- Note that if F returns an access-to-subprogram whose designated |
| -- type is an array, F (X) cannot be interpreted as an indirect call |
| -- through the result of the call to F. |
| |
| elsif Is_Access_Subprogram_Type (Base_Type (Etype (Nam))) |
| and then |
| (not Name_Denotes_Function |
| or else Nkind (N) = N_Procedure_Call_Statement |
| or else |
| (Nkind (Parent (N)) /= N_Explicit_Dereference |
| and then Is_Entity_Name (Nam) |
| and then No (First_Formal (Entity (Nam))) |
| and then not |
| Is_Array_Type (Etype (Designated_Type (Etype (Nam)))) |
| and then Present (Actuals))) |
| then |
| Nam_Ent := Designated_Type (Etype (Nam)); |
| Insert_Explicit_Dereference (Nam); |
| |
| -- Selected component case. Simple entry or protected operation, |
| -- where the entry name is given by the selector name. |
| |
| elsif Nkind (Nam) = N_Selected_Component then |
| Nam_Ent := Entity (Selector_Name (Nam)); |
| |
| if Ekind (Nam_Ent) not in E_Entry |
| | E_Entry_Family |
| | E_Function |
| | E_Procedure |
| then |
| Error_Msg_N ("name in call is not a callable entity", Nam); |
| Set_Etype (N, Any_Type); |
| return; |
| end if; |
| |
| -- If the name is an Indexed component, it can be a call to a member |
| -- of an entry family. The prefix must be a selected component whose |
| -- selector is the entry. Analyze_Procedure_Call normalizes several |
| -- kinds of call into this form. |
| |
| elsif Nkind (Nam) = N_Indexed_Component then |
| if Nkind (Prefix (Nam)) = N_Selected_Component then |
| Nam_Ent := Entity (Selector_Name (Prefix (Nam))); |
| else |
| Error_Msg_N ("name in call is not a callable entity", Nam); |
| Set_Etype (N, Any_Type); |
| return; |
| end if; |
| |
| elsif not Is_Entity_Name (Nam) then |
| Error_Msg_N ("name in call is not a callable entity", Nam); |
| Set_Etype (N, Any_Type); |
| return; |
| |
| else |
| Nam_Ent := Entity (Nam); |
| |
| -- If not overloadable, this may be a generalized indexing |
| -- operation with named associations. Rewrite again as an |
| -- indexed component and analyze as container indexing. |
| |
| if not Is_Overloadable (Nam_Ent) then |
| if Present |
| (Find_Value_Of_Aspect |
| (Etype (Nam_Ent), Aspect_Constant_Indexing)) |
| then |
| Replace (N, |
| Make_Indexed_Component (Sloc (N), |
| Prefix => Nam, |
| Expressions => Parameter_Associations (N))); |
| |
| if Try_Container_Indexing (N, Nam, Expressions (N)) then |
| return; |
| else |
| No_Interpretation; |
| end if; |
| |
| else |
| No_Interpretation; |
| end if; |
| |
| return; |
| end if; |
| end if; |
| |
| -- Operations generated for RACW stub types are called only through |
| -- dispatching, and can never be the static interpretation of a call. |
| |
| if Is_RACW_Stub_Type_Operation (Nam_Ent) then |
| No_Interpretation; |
| return; |
| end if; |
| |
| Analyze_One_Call (N, Nam_Ent, True, Success); |
| |
| -- If the nonoverloaded interpretation is a call to an abstract |
| -- nondispatching operation, then flag an error and return. |
| |
| -- Should this be incorporated in Remove_Abstract_Operations (which |
| -- currently only deals with cases where the name is overloaded)? ??? |
| |
| if Is_Overloadable (Nam_Ent) |
| and then Is_Abstract_Subprogram (Nam_Ent) |
| and then not Is_Dispatching_Operation (Nam_Ent) |
| then |
| Set_Etype (N, Any_Type); |
| |
| Error_Msg_Sloc := Sloc (Nam_Ent); |
| Error_Msg_NE |
| ("cannot call abstract operation& declared#", N, Nam_Ent); |
| |
| return; |
| end if; |
| |
| -- If this is an indirect call, the return type of the access_to |
| -- subprogram may be an incomplete type. At the point of the call, |
| -- use the full type if available, and at the same time update the |
| -- return type of the access_to_subprogram. |
| |
| if Success |
| and then Nkind (Nam) = N_Explicit_Dereference |
| and then Ekind (Etype (N)) = E_Incomplete_Type |
| and then Present (Full_View (Etype (N))) |
| then |
| Set_Etype (N, Full_View (Etype (N))); |
| Set_Etype (Nam_Ent, Etype (N)); |
| end if; |
| |
| -- Overloaded call |
| |
| else |
| -- An overloaded selected component must denote overloaded operations |
| -- of a concurrent type. The interpretations are attached to the |
| -- simple name of those operations. |
| |
| if Nkind (Nam) = N_Selected_Component then |
| Nam := Selector_Name (Nam); |
| end if; |
| |
| Get_First_Interp (Nam, X, It); |
| while Present (It.Nam) loop |
| Nam_Ent := It.Nam; |
| Deref := False; |
| |
| -- Name may be call that returns an access to subprogram, or more |
| -- generally an overloaded expression one of whose interpretations |
| -- yields an access to subprogram. If the name is an entity, we do |
| -- not dereference, because the node is a call that returns the |
| -- access type: note difference between f(x), where the call may |
| -- return an access subprogram type, and f(x)(y), where the type |
| -- returned by the call to f is implicitly dereferenced to analyze |
| -- the outer call. |
| |
| if Is_Access_Type (Nam_Ent) then |
| Nam_Ent := Designated_Type (Nam_Ent); |
| |
| elsif Is_Access_Type (Etype (Nam_Ent)) |
| and then |
| (not Is_Entity_Name (Nam) |
| or else Nkind (N) = N_Procedure_Call_Statement) |
| and then Ekind (Designated_Type (Etype (Nam_Ent))) |
| = E_Subprogram_Type |
| then |
| Nam_Ent := Designated_Type (Etype (Nam_Ent)); |
| |
| if Is_Entity_Name (Nam) then |
| Deref := True; |
| end if; |
| end if; |
| |
| -- If the call has been rewritten from a prefixed call, the first |
| -- parameter has been analyzed, but may need a subsequent |
| -- dereference, so skip its analysis now. |
| |
| if Is_Rewrite_Substitution (N) |
| and then Nkind (Original_Node (N)) = Nkind (N) |
| and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N))) |
| and then Present (Parameter_Associations (N)) |
| and then Present (Etype (First (Parameter_Associations (N)))) |
| then |
| Analyze_One_Call |
| (N, Nam_Ent, False, Success, Skip_First => True); |
| else |
| Analyze_One_Call (N, Nam_Ent, False, Success); |
| end if; |
| |
| -- If the interpretation succeeds, mark the proper type of the |
| -- prefix (any valid candidate will do). If not, remove the |
| -- candidate interpretation. If this is a parameterless call |
| -- on an anonymous access to subprogram, X is a variable with |
| -- an access discriminant D, the entity in the interpretation is |
| -- D, so rewrite X as X.D.all. |
| |
| if Success then |
| if Deref |
| and then Nkind (Parent (N)) /= N_Explicit_Dereference |
| then |
| if Ekind (It.Nam) = E_Discriminant |
| and then Has_Implicit_Dereference (It.Nam) |
| then |
| Rewrite (Name (N), |
| Make_Explicit_Dereference (Loc, |
| Prefix => |
| Make_Selected_Component (Loc, |
| Prefix => |
| New_Occurrence_Of (Entity (Nam), Loc), |
| Selector_Name => |
| New_Occurrence_Of (It.Nam, Loc)))); |
| |
| Analyze (N); |
| return; |
| |
| else |
| Set_Entity (Nam, It.Nam); |
| Insert_Explicit_Dereference (Nam); |
| Set_Etype (Nam, Nam_Ent); |
| end if; |
| |
| else |
| Set_Etype (Nam, It.Typ); |
| end if; |
| |
| elsif Nkind (Name (N)) in N_Function_Call | N_Selected_Component |
| then |
| Remove_Interp (X); |
| end if; |
| |
| Get_Next_Interp (X, It); |
| end loop; |
| |
| -- If the name is the result of a function call, it can only be a |
| -- call to a function returning an access to subprogram. Insert |
| -- explicit dereference. |
| |
| if Nkind (Nam) = N_Function_Call then |
| Insert_Explicit_Dereference (Nam); |
| end if; |
| |
| if Etype (N) = Any_Type then |
| |
| -- None of the interpretations is compatible with the actuals |
| |
| Diagnose_Call (N, Nam); |
| |
| -- Special checks for uninstantiated put routines |
| |
| if Nkind (N) = N_Procedure_Call_Statement |
| and then Is_Entity_Name (Nam) |
| and then Chars (Nam) = Name_Put |
| and then List_Length (Actuals) = 1 |
| then |
| declare |
| Arg : constant Node_Id := First (Actuals); |
| Typ : Entity_Id; |
| |
| begin |
| if Nkind (Arg) = N_Parameter_Association then |
| Typ := Etype (Explicit_Actual_Parameter (Arg)); |
| else |
| Typ := Etype (Arg); |
| end if; |
| |
| if Is_Signed_Integer_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Integer_'I'O!", Nam); |
| |
| elsif Is_Modular_Integer_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Modular_'I'O!", Nam); |
| |
| elsif Is_Floating_Point_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Float_'I'O!", Nam); |
| |
| elsif Is_Ordinary_Fixed_Point_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Fixed_'I'O!", Nam); |
| |
| elsif Is_Decimal_Fixed_Point_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Decimal_'I'O!", Nam); |
| |
| elsif Is_Enumeration_Type (Typ) then |
| Error_Msg_N |
| ("possible missing instantiation of " |
| & "'Text_'I'O.'Enumeration_'I'O!", Nam); |
| end if; |
| end; |
| end if; |
| |
| elsif not Is_Overloaded (N) |
| and then Is_Entity_Name (Nam) |
| then |
| -- Resolution yields a single interpretation. Verify that the |
| -- reference has capitalization consistent with the declaration. |
| |
| Set_Entity_With_Checks (Nam, Entity (Nam)); |
| Generate_Reference (Entity (Nam), Nam); |
| |
| Set_Etype (Nam, Etype (Entity (Nam))); |
| else |
| Remove_Abstract_Operations (N); |
| end if; |
| end if; |
| |
| -- Check the accessibility level for actuals for explicitly aliased |
| -- formals. |
| |
| if Nkind (N) = N_Function_Call |
| and then Comes_From_Source (N) |
| and then Present (Nam_Ent) |
| and then In_Return_Value (N) |
| then |
| declare |
| Form : Node_Id; |
| Act : Node_Id; |
| begin |
| Act := First_Actual (N); |
| Form := First_Formal (Nam_Ent); |
| |
| while Present (Form) and then Present (Act) loop |
| -- Check whether the formal is aliased and if the accessibility |
| -- level of the actual is deeper than the accessibility level |
| -- of the enclosing subprogram to which the current return |
| -- statement applies. |
| |
| -- Should we be checking Is_Entity_Name on Act? Won't this miss |
| -- other cases ??? |
| |
| if Is_Explicitly_Aliased (Form) |
| and then Is_Entity_Name (Act) |
| and then Static_Accessibility_Level |
| (Act, Zero_On_Dynamic_Level) |
| > Subprogram_Access_Level (Current_Subprogram) |
| then |
| Error_Msg_N ("actual for explicitly aliased formal is too" |
| & " short lived", Act); |
| end if; |
| |
| Next_Formal (Form); |
| Next_Actual (Act); |
| end loop; |
| end; |
| end if; |
| |
| if Ada_Version >= Ada_2012 then |
| |
| -- Check if the call contains a function with writable actuals |
| |
| Check_Writable_Actuals (N); |
| |
| -- If found and the outermost construct that can be evaluated in |
| -- an arbitrary order is precisely this call, then check all its |
| -- actuals. |
| |
| Check_Function_Writable_Actuals (N); |
| |
| -- The return type of the function may be incomplete. This can be |
| -- the case if the type is a generic formal, or a limited view. It |
| -- can also happen when the function declaration appears before the |
| -- full view of the type (which is legal in Ada 2012) and the call |
| -- appears in a different unit, in which case the incomplete view |
| -- must be replaced with the full view (or the nonlimited view) |
| -- to prevent subsequent type errors. Note that the usual install/ |
| -- removal of limited_with clauses is not sufficient to handle this |
| -- case, because the limited view may have been captured in another |
| -- compilation unit that defines the current function. |
| |
| if Is_Incomplete_Type (Etype (N)) then |
| if Present (Full_View (Etype (N))) then |
| if Is_Entity_Name (Nam) then |
| Set_Etype (Nam, Full_View (Etype (N))); |
| Set_Etype (Entity (Nam), Full_View (Etype (N))); |
| end if; |
| |
| Set_Etype (N, Full_View (Etype (N))); |
| |
| elsif From_Limited_With (Etype (N)) |
| and then Present (Non_Limited_View (Etype (N))) |
| then |
| Set_Etype (N, Non_Limited_View (Etype (N))); |
| |
| -- If there is no completion for the type, this may be because |
| -- there is only a limited view of it and there is nothing in |
| -- the context of the current unit that has required a regular |
| -- compilation of the unit containing the type. We recognize |
| -- this unusual case by the fact that unit is not analyzed. |
| -- Note that the call being analyzed is in a different unit from |
| -- the function declaration, and nothing indicates that the type |
| -- is a limited view. |
| |
| elsif Ekind (Scope (Etype (N))) = E_Package |
| and then Present (Limited_View (Scope (Etype (N)))) |
| and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N)))) |
| then |
| Error_Msg_NE |
| ("cannot call function that returns limited view of}", |
| N, Etype (N)); |
| |
| Error_Msg_NE |
| ("\there must be a regular with_clause for package & in the " |
| & "current unit, or in some unit in its context", |
| N, Scope (Etype (N))); |
| |
| Set_Etype (N, Any_Type); |
| end if; |
| end if; |
| end if; |
| end Analyze_Call; |
| |
| ----------------------------- |
| -- Analyze_Case_Expression -- |
| ----------------------------- |
| |
| procedure Analyze_Case_Expression (N : Node_Id) is |
| procedure Non_Static_Choice_Error (Choice : Node_Id); |
| -- Error routine invoked by the generic instantiation below when |
| -- the case expression has a non static choice. |
| |
| package Case_Choices_Analysis is new |
| Generic_Analyze_Choices |
| (Process_Associated_Node => No_OP); |
| use Case_Choices_Analysis; |
| |
| package Case_Choices_Checking is new |
| Generic_Check_Choices |
| (Process_Empty_Choice => No_OP, |
| Process_Non_Static_Choice => Non_Static_Choice_Error, |
| Process_Associated_Node => No_OP); |
| use Case_Choices_Checking; |
| |
| ----------------------------- |
| -- Non_Static_Choice_Error -- |
| ----------------------------- |
| |
| procedure Non_Static_Choice_Error (Choice : Node_Id) is |
| begin |
| Flag_Non_Static_Expr |
| ("choice given in case expression is not static!", Choice); |
| end Non_Static_Choice_Error; |
| |
| -- Local variables |
| |
| Expr : constant Node_Id := Expression (N); |
| Alt : Node_Id; |
| Exp_Type : Entity_Id; |
| Exp_Btype : Entity_Id; |
| |
| FirstX : Node_Id := Empty; |
| -- First expression in the case for which there is some type information |
| -- available, i.e. it is not Any_Type, which can happen because of some |
| -- error, or from the use of e.g. raise Constraint_Error. |
| |
| Others_Present : Boolean; |
| -- Indicates if Others was present |
| |
| Wrong_Alt : Node_Id := Empty; |
| -- For error reporting |
| |
| -- Start of processing for Analyze_Case_Expression |
| |
| begin |
| Analyze_And_Resolve (Expr, Any_Discrete); |
| Check_Unset_Reference (Expr); |
| Exp_Type := Etype (Expr); |
| Exp_Btype := Base_Type (Exp_Type); |
| |
| Alt := First (Alternatives (N)); |
| while Present (Alt) loop |
| if Error_Posted (Expression (Alt)) then |
| return; |
| end if; |
| |
| Analyze (Expression (Alt)); |
| |
| if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then |
| FirstX := Expression (Alt); |
| end if; |
| |
| Next (Alt); |
| end loop; |
| |
| -- Get our initial type from the first expression for which we got some |
| -- useful type information from the expression. |
| |
| if No (FirstX) then |
| return; |
| end if; |
| |
| if not Is_Overloaded (FirstX) then |
| Set_Etype (N, Etype (FirstX)); |
| |
| else |
| declare |
| I : Interp_Index; |
| It : Interp; |
| |
| begin |
| Set_Etype (N, Any_Type); |
| |
| Get_First_Interp (FirstX, I, It); |
| while Present (It.Nam) loop |
| |
| -- For each interpretation of the first expression, we only |
| -- add the interpretation if every other expression in the |
| -- case expression alternatives has a compatible type. |
| |
| Alt := Next (First (Alternatives (N))); |
| while Present (Alt) loop |
| exit when not Has_Compatible_Type (Expression (Alt), It.Typ); |
| Next (Alt); |
| end loop; |
| |
| if No (Alt) then |
| Add_One_Interp (N, It.Typ, It.Typ); |
| else |
| Wrong_Alt := Alt; |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end; |
| end if; |
| |
| Exp_Btype := Base_Type (Exp_Type); |
| |
| -- The expression must be of a discrete type which must be determinable |
| -- independently of the context in which the expression occurs, but |
| -- using the fact that the expression must be of a discrete type. |
| -- Moreover, the type this expression must not be a character literal |
| -- (which is always ambiguous). |
| |
| -- If error already reported by Resolve, nothing more to do |
| |
| if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then |
| return; |
| |
| -- Special casee message for character literal |
| |
| elsif Exp_Btype = Any_Character then |
| Error_Msg_N |
| ("character literal as case expression is ambiguous", Expr); |
| return; |
| end if; |
| |
| if Etype (N) = Any_Type and then Present (Wrong_Alt) then |
| Error_Msg_N |
| ("type incompatible with that of previous alternatives", |
| Expression (Wrong_Alt)); |
| return; |
| end if; |
| |
| -- If the case expression is a formal object of mode in out, then |
| -- treat it as having a nonstatic subtype by forcing use of the base |
| -- type (which has to get passed to Check_Case_Choices below). Also |
| -- use base type when the case expression is parenthesized. |
| |
| if Paren_Count (Expr) > 0 |
| or else (Is_Entity_Name (Expr) |
| and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter) |
| then |
| Exp_Type := Exp_Btype; |
| end if; |
| |
| -- The case expression alternatives cover the range of a static subtype |
| -- subject to aspect Static_Predicate. Do not check the choices when the |
| -- case expression has not been fully analyzed yet because this may lead |
| -- to bogus errors. |
| |
| if Is_OK_Static_Subtype (Exp_Type) |
| and then Has_Static_Predicate_Aspect (Exp_Type) |
| and then In_Spec_Expression |
| then |
| null; |
| |
| -- Call Analyze_Choices and Check_Choices to do the rest of the work |
| |
| else |
| Analyze_Choices (Alternatives (N), Exp_Type); |
| Check_Choices (N, Alternatives (N), Exp_Type, Others_Present); |
| |
| if Exp_Type = Universal_Integer and then not Others_Present then |
| Error_Msg_N |
| ("case on universal integer requires OTHERS choice", Expr); |
| end if; |
| end if; |
| end Analyze_Case_Expression; |
| |
| --------------------------- |
| -- Analyze_Comparison_Op -- |
| --------------------------- |
| |
| procedure Analyze_Comparison_Op (N : Node_Id) is |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id := Entity (N); |
| |
| begin |
| Set_Etype (N, Any_Type); |
| Candidate_Type := Empty; |
| |
| Analyze_Expression (L); |
| Analyze_Expression (R); |
| |
| if Present (Op_Id) then |
| if Ekind (Op_Id) = E_Operator then |
| Find_Comparison_Types (L, R, Op_Id, N); |
| else |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| if Is_Overloaded (L) then |
| Set_Etype (L, Intersect_Types (L, R)); |
| end if; |
| |
| else |
| Op_Id := Get_Name_Entity_Id (Chars (N)); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| Find_Comparison_Types (L, R, Op_Id, N); |
| else |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| Operator_Check (N); |
| Check_Function_Writable_Actuals (N); |
| end Analyze_Comparison_Op; |
| |
| --------------------------- |
| -- Analyze_Concatenation -- |
| --------------------------- |
| |
| procedure Analyze_Concatenation (N : Node_Id) is |
| |
| -- We wish to avoid deep recursion, because concatenations are often |
| -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left |
| -- operands nonrecursively until we find something that is not a |
| -- concatenation (A in this case), or has already been analyzed. We |
| -- analyze that, and then walk back up the tree following Parent |
| -- pointers, calling Analyze_Concatenation_Rest to do the rest of the |
| -- work at each level. The Parent pointers allow us to avoid recursion, |
| -- and thus avoid running out of memory. |
| |
| NN : Node_Id := N; |
| L : Node_Id; |
| |
| begin |
| Candidate_Type := Empty; |
| |
| -- The following code is equivalent to: |
| |
| -- Set_Etype (N, Any_Type); |
| -- Analyze_Expression (Left_Opnd (N)); |
| -- Analyze_Concatenation_Rest (N); |
| |
| -- where the Analyze_Expression call recurses back here if the left |
| -- operand is a concatenation. |
| |
| -- Walk down left operands |
| |
| loop |
| Set_Etype (NN, Any_Type); |
| L := Left_Opnd (NN); |
| exit when Nkind (L) /= N_Op_Concat or else Analyzed (L); |
| NN := L; |
| end loop; |
| |
| -- Now (given the above example) NN is A&B and L is A |
| |
| -- First analyze L ... |
| |
| Analyze_Expression (L); |
| |
| -- ... then walk NN back up until we reach N (where we started), calling |
| -- Analyze_Concatenation_Rest along the way. |
| |
| loop |
| Analyze_Concatenation_Rest (NN); |
| exit when NN = N; |
| NN := Parent (NN); |
| end loop; |
| end Analyze_Concatenation; |
| |
| -------------------------------- |
| -- Analyze_Concatenation_Rest -- |
| -------------------------------- |
| |
| -- If the only one-dimensional array type in scope is String, |
| -- this is the resulting type of the operation. Otherwise there |
| -- will be a concatenation operation defined for each user-defined |
| -- one-dimensional array. |
| |
| procedure Analyze_Concatenation_Rest (N : Node_Id) is |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id := Entity (N); |
| LT : Entity_Id; |
| RT : Entity_Id; |
| |
| begin |
| Analyze_Expression (R); |
| |
| -- If the entity is present, the node appears in an instance, and |
| -- denotes a predefined concatenation operation. The resulting type is |
| -- obtained from the arguments when possible. If the arguments are |
| -- aggregates, the array type and the concatenation type must be |
| -- visible. |
| |
| if Present (Op_Id) then |
| if Ekind (Op_Id) = E_Operator then |
| LT := Base_Type (Etype (L)); |
| RT := Base_Type (Etype (R)); |
| |
| if Is_Array_Type (LT) |
| and then (RT = LT or else RT = Base_Type (Component_Type (LT))) |
| then |
| Add_One_Interp (N, Op_Id, LT); |
| |
| elsif Is_Array_Type (RT) |
| and then LT = Base_Type (Component_Type (RT)) |
| then |
| Add_One_Interp (N, Op_Id, RT); |
| |
| -- If one operand is a string type or a user-defined array type, |
| -- and the other is a literal, result is of the specific type. |
| |
| elsif |
| (Root_Type (LT) = Standard_String |
| or else Scope (LT) /= Standard_Standard) |
| and then Etype (R) = Any_String |
| then |
| Add_One_Interp (N, Op_Id, LT); |
| |
| elsif |
| (Root_Type (RT) = Standard_String |
| or else Scope (RT) /= Standard_Standard) |
| and then Etype (L) = Any_String |
| then |
| Add_One_Interp (N, Op_Id, RT); |
| |
| elsif not Is_Generic_Type (Etype (Op_Id)) then |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| |
| else |
| -- Type and its operations must be visible |
| |
| Set_Entity (N, Empty); |
| Analyze_Concatenation (N); |
| end if; |
| |
| else |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| else |
| Op_Id := Get_Name_Entity_Id (Name_Op_Concat); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| |
| -- Do not consider operators declared in dead code, they |
| -- cannot be part of the resolution. |
| |
| if Is_Eliminated (Op_Id) then |
| null; |
| else |
| Find_Concatenation_Types (L, R, Op_Id, N); |
| end if; |
| |
| else |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| Operator_Check (N); |
| end Analyze_Concatenation_Rest; |
| |
| ------------------------- |
| -- Analyze_Equality_Op -- |
| ------------------------- |
| |
| procedure Analyze_Equality_Op (N : Node_Id) is |
| Loc : constant Source_Ptr := Sloc (N); |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id; |
| |
| begin |
| Set_Etype (N, Any_Type); |
| Candidate_Type := Empty; |
| |
| Analyze_Expression (L); |
| Analyze_Expression (R); |
| |
| -- If the entity is set, the node is a generic instance with a non-local |
| -- reference to the predefined operator or to a user-defined function. |
| -- It can also be an inequality that is expanded into the negation of a |
| -- call to a user-defined equality operator. |
| |
| -- For the predefined case, the result is Boolean, regardless of the |
| -- type of the operands. The operands may even be limited, if they are |
| -- generic actuals. If they are overloaded, label the left argument with |
| -- the common type that must be present, or with the type of the formal |
| -- of the user-defined function. |
| |
| if Present (Entity (N)) then |
| Op_Id := Entity (N); |
| |
| if Ekind (Op_Id) = E_Operator then |
| Add_One_Interp (N, Op_Id, Standard_Boolean); |
| else |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| if Is_Overloaded (L) then |
| if Ekind (Op_Id) = E_Operator then |
| Set_Etype (L, Intersect_Types (L, R)); |
| else |
| Set_Etype (L, Etype (First_Formal (Op_Id))); |
| end if; |
| end if; |
| |
| else |
| Op_Id := Get_Name_Entity_Id (Chars (N)); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| Find_Equality_Types (L, R, Op_Id, N); |
| else |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| -- If there was no match, and the operator is inequality, this may be |
| -- a case where inequality has not been made explicit, as for tagged |
| -- types. Analyze the node as the negation of an equality operation. |
| -- This cannot be done earlier, because before analysis we cannot rule |
| -- out the presence of an explicit inequality. |
| |
| if Etype (N) = Any_Type |
| and then Nkind (N) = N_Op_Ne |
| then |
| Op_Id := Get_Name_Entity_Id (Name_Op_Eq); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| Find_Equality_Types (L, R, Op_Id, N); |
| else |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| |
| if Etype (N) /= Any_Type then |
| Op_Id := Entity (N); |
| |
| Rewrite (N, |
| Make_Op_Not (Loc, |
| Right_Opnd => |
| Make_Op_Eq (Loc, |
| Left_Opnd => Left_Opnd (N), |
| Right_Opnd => Right_Opnd (N)))); |
| |
| Set_Entity (Right_Opnd (N), Op_Id); |
| Analyze (N); |
| end if; |
| end if; |
| |
| Operator_Check (N); |
| Check_Function_Writable_Actuals (N); |
| end Analyze_Equality_Op; |
| |
| ---------------------------------- |
| -- Analyze_Explicit_Dereference -- |
| ---------------------------------- |
| |
| procedure Analyze_Explicit_Dereference (N : Node_Id) is |
| Loc : constant Source_Ptr := Sloc (N); |
| P : constant Node_Id := Prefix (N); |
| T : Entity_Id; |
| I : Interp_Index; |
| It : Interp; |
| New_N : Node_Id; |
| |
| function Is_Function_Type return Boolean; |
| -- Check whether node may be interpreted as an implicit function call |
| |
| ---------------------- |
| -- Is_Function_Type -- |
| ---------------------- |
| |
| function Is_Function_Type return Boolean is |
| I : Interp_Index; |
| It : Interp; |
| |
| begin |
| if not Is_Overloaded (N) then |
| return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type |
| and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type; |
| |
| else |
| Get_First_Interp (N, I, It); |
| while Present (It.Nam) loop |
| if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type |
| or else Etype (Base_Type (It.Typ)) = Standard_Void_Type |
| then |
| return False; |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| return True; |
| end if; |
| end Is_Function_Type; |
| |
| -- Start of processing for Analyze_Explicit_Dereference |
| |
| begin |
| -- In formal verification mode, keep track of all reads and writes |
| -- through explicit dereferences. |
| |
| if GNATprove_Mode then |
| SPARK_Specific.Generate_Dereference (N); |
| end if; |
| |
| Analyze (P); |
| Set_Etype (N, Any_Type); |
| |
| -- Test for remote access to subprogram type, and if so return |
| -- after rewriting the original tree. |
| |
| if Remote_AST_E_Dereference (P) then |
| return; |
| end if; |
| |
| -- Normal processing for other than remote access to subprogram type |
| |
| if not Is_Overloaded (P) then |
| if Is_Access_Type (Etype (P)) then |
| |
| -- Set the Etype |
| |
| declare |
| DT : constant Entity_Id := Designated_Type (Etype (P)); |
| |
| begin |
| -- An explicit dereference is a legal occurrence of an |
| -- incomplete type imported through a limited_with clause, if |
| -- the full view is visible, or if we are within an instance |
| -- body, where the enclosing body has a regular with_clause |
| -- on the unit. |
| |
| if From_Limited_With (DT) |
| and then not From_Limited_With (Scope (DT)) |
| and then |
| (Is_Immediately_Visible (Scope (DT)) |
| or else |
| (Is_Child_Unit (Scope (DT)) |
| and then Is_Visible_Lib_Unit (Scope (DT))) |
| or else In_Instance_Body) |
| then |
| Set_Etype (N, Available_View (DT)); |
| |
| else |
| Set_Etype (N, DT); |
| end if; |
| end; |
| |
| elsif Etype (P) /= Any_Type then |
| Error_Msg_N ("prefix of dereference must be an access type", N); |
| return; |
| end if; |
| |
| else |
| Get_First_Interp (P, I, It); |
| while Present (It.Nam) loop |
| T := It.Typ; |
| |
| if Is_Access_Type (T) then |
| Add_One_Interp (N, Designated_Type (T), Designated_Type (T)); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| -- Error if no interpretation of the prefix has an access type |
| |
| if Etype (N) = Any_Type then |
| Error_Msg_N |
| ("access type required in prefix of explicit dereference", P); |
| Set_Etype (N, Any_Type); |
| return; |
| end if; |
| end if; |
| |
| if Is_Function_Type |
| and then Nkind (Parent (N)) /= N_Indexed_Component |
| |
| and then (Nkind (Parent (N)) /= N_Function_Call |
| or else N /= Name (Parent (N))) |
| |
| and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement |
| or else N /= Name (Parent (N))) |
| |
| and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration |
| and then (Nkind (Parent (N)) /= N_Attribute_Reference |
| or else |
| (Attribute_Name (Parent (N)) /= Name_Address |
| and then |
| Attribute_Name (Parent (N)) /= Name_Access)) |
| then |
| -- Name is a function call with no actuals, in a context that |
| -- requires deproceduring (including as an actual in an enclosing |
| -- function or procedure call). There are some pathological cases |
| -- where the prefix might include functions that return access to |
| -- subprograms and others that return a regular type. Disambiguation |
| -- of those has to take place in Resolve. |
| |
| New_N := |
| Make_Function_Call (Loc, |
| Name => Make_Explicit_Dereference (Loc, P), |
| Parameter_Associations => New_List); |
| |
| -- If the prefix is overloaded, remove operations that have formals, |
| -- we know that this is a parameterless call. |
| |
| if Is_Overloaded (P) then |
| Get_First_Interp (P, I, It); |
| while Present (It.Nam) loop |
| T := It.Typ; |
| |
| if No (First_Formal (Base_Type (Designated_Type (T)))) then |
| Set_Etype (P, T); |
| else |
| Remove_Interp (I); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end if; |
| |
| Rewrite (N, New_N); |
| Analyze (N); |
| |
| elsif not Is_Function_Type |
| and then Is_Overloaded (N) |
| then |
| -- The prefix may include access to subprograms and other access |
| -- types. If the context selects the interpretation that is a |
| -- function call (not a procedure call) we cannot rewrite the node |
| -- yet, but we include the result of the call interpretation. |
| |
| Get_First_Interp (N, I, It); |
| while Present (It.Nam) loop |
| if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type |
| and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type |
| and then Nkind (Parent (N)) /= N_Procedure_Call_Statement |
| then |
| Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ)); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end if; |
| |
| -- A value of remote access-to-class-wide must not be dereferenced |
| -- (RM E.2.2(16)). |
| |
| Validate_Remote_Access_To_Class_Wide_Type (N); |
| end Analyze_Explicit_Dereference; |
| |
| ------------------------ |
| -- Analyze_Expression -- |
| ------------------------ |
| |
| procedure Analyze_Expression (N : Node_Id) is |
| begin |
| |
| -- If the expression is an indexed component that will be rewritten |
| -- as a container indexing, it has already been analyzed. |
| |
| if Nkind (N) = N_Indexed_Component |
| and then Present (Generalized_Indexing (N)) |
| then |
| null; |
| |
| else |
| Analyze (N); |
| Check_Parameterless_Call (N); |
| end if; |
| end Analyze_Expression; |
| |
| ------------------------------------- |
| -- Analyze_Expression_With_Actions -- |
| ------------------------------------- |
| |
| procedure Analyze_Expression_With_Actions (N : Node_Id) is |
| |
| procedure Check_Action_OK (A : Node_Id); |
| -- Check that the action A is allowed as a declare_item of a declare |
| -- expression if N and A come from source. |
| |
| --------------------- |
| -- Check_Action_OK -- |
| --------------------- |
| |
| procedure Check_Action_OK (A : Node_Id) is |
| begin |
| if not Comes_From_Source (N) or else not Comes_From_Source (A) then |
| return; -- Allow anything in generated code |
| end if; |
| |
| case Nkind (A) is |
| when N_Object_Declaration => |
| if Nkind (Object_Definition (A)) = N_Access_Definition then |
| Error_Msg_N |
| ("anonymous access type not allowed in declare_expression", |
| Object_Definition (A)); |
| end if; |
| |
| if Aliased_Present (A) then |
| Error_Msg_N ("ALIASED not allowed in declare_expression", A); |
| end if; |
| |
| if Constant_Present (A) |
| and then not Is_Limited_Type (Etype (Defining_Identifier (A))) |
| then |
| return; -- nonlimited constants are OK |
| end if; |
| |
| when N_Object_Renaming_Declaration => |
| if Present (Access_Definition (A)) then |
| Error_Msg_N |
| ("anonymous access type not allowed in declare_expression", |
| Access_Definition (A)); |
| end if; |
| |
| if not Is_Limited_Type (Etype (Defining_Identifier (A))) then |
| return; -- ???For now; the RM rule is a bit more complicated |
| end if; |
| |
| when others => |
| null; -- Nothing else allowed, not even pragmas |
| end case; |
| |
| Error_Msg_N ("object renaming or constant declaration expected", A); |
| end Check_Action_OK; |
| |
| A : Node_Id; |
| EWA_Scop : Entity_Id; |
| |
| -- Start of processing for Analyze_Expression_With_Actions |
| |
| begin |
| -- Create a scope, which is needed to provide proper visibility of the |
| -- declare_items. |
| |
| EWA_Scop := New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B'); |
| Set_Etype (EWA_Scop, Standard_Void_Type); |
| Set_Scope (EWA_Scop, Current_Scope); |
| Set_Parent (EWA_Scop, N); |
| Push_Scope (EWA_Scop); |
| |
| -- If this Expression_With_Actions node comes from source, then it |
| -- represents a declare_expression; increment the counter to take note |
| -- of that. |
| |
| if Comes_From_Source (N) then |
| In_Declare_Expr := In_Declare_Expr + 1; |
| end if; |
| |
| A := First (Actions (N)); |
| while Present (A) loop |
| Analyze (A); |
| Check_Action_OK (A); |
| Next (A); |
| end loop; |
| |
| Analyze_Expression (Expression (N)); |
| Set_Etype (N, Etype (Expression (N))); |
| End_Scope; |
| |
| if Comes_From_Source (N) then |
| In_Declare_Expr := In_Declare_Expr - 1; |
| end if; |
| end Analyze_Expression_With_Actions; |
| |
| --------------------------- |
| -- Analyze_If_Expression -- |
| --------------------------- |
| |
| procedure Analyze_If_Expression (N : Node_Id) is |
| Condition : constant Node_Id := First (Expressions (N)); |
| Then_Expr : Node_Id; |
| Else_Expr : Node_Id; |
| |
| begin |
| -- Defend against error of missing expressions from previous error |
| |
| if No (Condition) then |
| Check_Error_Detected; |
| return; |
| end if; |
| |
| Then_Expr := Next (Condition); |
| |
| if No (Then_Expr) then |
| Check_Error_Detected; |
| return; |
| end if; |
| |
| Else_Expr := Next (Then_Expr); |
| |
| -- Analyze and resolve the condition. We need to resolve this now so |
| -- that it gets folded to True/False if possible, before we analyze |
| -- the THEN/ELSE branches, because when analyzing these branches, we |
| -- may call Is_Statically_Unevaluated, which expects the condition of |
| -- an enclosing IF to have been analyze/resolved/evaluated. |
| |
| Analyze_Expression (Condition); |
| Resolve (Condition, Any_Boolean); |
| |
| -- Analyze THEN expression and (if present) ELSE expression. For those |
| -- we delay resolution in the normal manner, because of overloading etc. |
| |
| Analyze_Expression (Then_Expr); |
| |
| if Present (Else_Expr) then |
| Analyze_Expression (Else_Expr); |
| end if; |
| |
| -- If then expression not overloaded, then that decides the type |
| |
| if not Is_Overloaded (Then_Expr) then |
| Set_Etype (N, Etype (Then_Expr)); |
| |
| -- Case where then expression is overloaded |
| |
| else |
| declare |
| I : Interp_Index; |
| It : Interp; |
| |
| begin |
| Set_Etype (N, Any_Type); |
| |
| -- Loop through interpretations of Then_Expr |
| |
| Get_First_Interp (Then_Expr, I, It); |
| while Present (It.Nam) loop |
| |
| -- Add possible interpretation of Then_Expr if no Else_Expr, or |
| -- Else_Expr is present and has a compatible type. |
| |
| if No (Else_Expr) |
| or else Has_Compatible_Type (Else_Expr, It.Typ) |
| then |
| Add_One_Interp (N, It.Typ, It.Typ); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| -- If no valid interpretation has been found, then the type of the |
| -- ELSE expression does not match any interpretation of the THEN |
| -- expression. |
| |
| if Etype (N) = Any_Type then |
| Error_Msg_N |
| ("type incompatible with that of THEN expression", |
| Else_Expr); |
| return; |
| end if; |
| end; |
| end if; |
| end Analyze_If_Expression; |
| |
| ------------------------------------ |
| -- Analyze_Indexed_Component_Form -- |
| ------------------------------------ |
| |
| procedure Analyze_Indexed_Component_Form (N : Node_Id) is |
| P : constant Node_Id := Prefix (N); |
| Exprs : constant List_Id := Expressions (N); |
| Exp : Node_Id; |
| P_T : Entity_Id; |
| E : Node_Id; |
| U_N : Entity_Id; |
| |
| procedure Process_Function_Call; |
| -- Prefix in indexed component form is an overloadable entity, so the |
| -- node is very likely a function call; reformat it as such. The only |
| -- exception is a call to a parameterless function that returns an |
| -- array type, or an access type thereof, in which case this will be |
| -- undone later by Resolve_Call or Resolve_Entry_Call. |
| |
| procedure Process_Indexed_Component; |
| -- Prefix in indexed component form is actually an indexed component. |
| -- This routine processes it, knowing that the prefix is already |
| -- resolved. |
| |
| procedure Process_Indexed_Component_Or_Slice; |
| -- An indexed component with a single index may designate a slice if |
| -- the index is a subtype mark. This routine disambiguates these two |
| -- cases by resolving the prefix to see if it is a subtype mark. |
| |
| procedure Process_Overloaded_Indexed_Component; |
| -- If the prefix of an indexed component is overloaded, the proper |
| -- interpretation is selected by the index types and the context. |
| |
| --------------------------- |
| -- Process_Function_Call -- |
| --------------------------- |
| |
| procedure Process_Function_Call is |
| Loc : constant Source_Ptr := Sloc (N); |
| Actual : Node_Id; |
| |
| begin |
| Change_Node (N, N_Function_Call); |
| Set_Name (N, P); |
| Set_Parameter_Associations (N, Exprs); |
| |
| -- Analyze actuals prior to analyzing the call itself |
| |
| Actual := First (Parameter_Associations (N)); |
| while Present (Actual) loop |
| Analyze (Actual); |
| Check_Parameterless_Call (Actual); |
| |
| -- Move to next actual. Note that we use Next, not Next_Actual |
| -- here. The reason for this is a bit subtle. If a function call |
| -- includes named associations, the parser recognizes the node |
| -- as a call, and it is analyzed as such. If all associations are |
| -- positional, the parser builds an indexed_component node, and |
| -- it is only after analysis of the prefix that the construct |
| -- is recognized as a call, in which case Process_Function_Call |
| -- rewrites the node and analyzes the actuals. If the list of |
| -- actuals is malformed, the parser may leave the node as an |
| -- indexed component (despite the presence of named associations). |
| -- The iterator Next_Actual is equivalent to Next if the list is |
| -- positional, but follows the normalized chain of actuals when |
| -- named associations are present. In this case normalization has |
| -- not taken place, and actuals remain unanalyzed, which leads to |
| -- subsequent crashes or loops if there is an attempt to continue |
| -- analysis of the program. |
| |
| -- IF there is a single actual and it is a type name, the node |
| -- can only be interpreted as a slice of a parameterless call. |
| -- Rebuild the node as such and analyze. |
| |
| if No (Next (Actual)) |
| and then Is_Entity_Name (Actual) |
| and then Is_Type (Entity (Actual)) |
| and then Is_Discrete_Type (Entity (Actual)) |
| and then not Is_Current_Instance (Actual) |
| then |
| Replace (N, |
| Make_Slice (Loc, |
| Prefix => P, |
| Discrete_Range => |
| New_Occurrence_Of (Entity (Actual), Loc))); |
| Analyze (N); |
| return; |
| |
| else |
| Next (Actual); |
| end if; |
| end loop; |
| |
| Analyze_Call (N); |
| end Process_Function_Call; |
| |
| ------------------------------- |
| -- Process_Indexed_Component -- |
| ------------------------------- |
| |
| procedure Process_Indexed_Component is |
| Exp : Node_Id; |
| Array_Type : Entity_Id; |
| Index : Node_Id; |
| Pent : Entity_Id := Empty; |
| |
| begin |
| Exp := First (Exprs); |
| |
| if Is_Overloaded (P) then |
| Process_Overloaded_Indexed_Component; |
| |
| else |
| Array_Type := Etype (P); |
| |
| if Is_Entity_Name (P) then |
| Pent := Entity (P); |
| elsif Nkind (P) = N_Selected_Component |
| and then Is_Entity_Name (Selector_Name (P)) |
| then |
| Pent := Entity (Selector_Name (P)); |
| end if; |
| |
| -- Prefix must be appropriate for an array type, taking into |
| -- account a possible implicit dereference. |
| |
| if Is_Access_Type (Array_Type) then |
| Error_Msg_NW |
| (Warn_On_Dereference, "?d?implicit dereference", N); |
| Array_Type := Implicitly_Designated_Type (Array_Type); |
| end if; |
| |
| if Is_Array_Type (Array_Type) then |
| |
| -- In order to correctly access First_Index component later, |
| -- replace string literal subtype by its parent type. |
| |
| if Ekind (Array_Type) = E_String_Literal_Subtype then |
| Array_Type := Etype (Array_Type); |
| end if; |
| |
| elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then |
| Analyze (Exp); |
| Set_Etype (N, Any_Type); |
| |
| if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then |
| Error_Msg_N ("invalid index type in entry name", N); |
| |
| elsif Present (Next (Exp)) then |
| Error_Msg_N ("too many subscripts in entry reference", N); |
| |
| else |
| Set_Etype (N, Etype (P)); |
| end if; |
| |
| return; |
| |
| elsif Is_Record_Type (Array_Type) |
| and then Remote_AST_I_Dereference (P) |
| then |
| return; |
| |
| elsif Try_Container_Indexing (N, P, Exprs) then |
| return; |
| |
| elsif Array_Type = Any_Type then |
| Set_Etype (N, Any_Type); |
| |
| -- In most cases the analysis of the prefix will have emitted |
| -- an error already, but if the prefix may be interpreted as a |
| -- call in prefixed notation, the report is left to the caller. |
| -- To prevent cascaded errors, report only if no previous ones. |
| |
| if Serious_Errors_Detected = 0 then |
| Error_Msg_N ("invalid prefix in indexed component", P); |
| |
| if Nkind (P) = N_Expanded_Name then |
| Error_Msg_NE ("\& is not visible", P, Selector_Name (P)); |
| end if; |
| end if; |
| |
| return; |
| |
| -- Here we definitely have a bad indexing |
| |
| else |
| if Nkind (Parent (N)) = N_Requeue_Statement |
| and then Present (Pent) and then Ekind (Pent) = E_Entry |
| then |
| Error_Msg_N |
| ("REQUEUE does not permit parameters", First (Exprs)); |
| |
| elsif Is_Entity_Name (P) |
| and then Etype (P) = Standard_Void_Type |
| then |
| Error_Msg_NE ("incorrect use of &", P, Entity (P)); |
| |
| else |
| Error_Msg_N ("array type required in indexed component", P); |
| end if; |
| |
| Set_Etype (N, Any_Type); |
| return; |
| end if; |
| |
| Index := First_Index (Array_Type); |
| while Present (Index) and then Present (Exp) loop |
| if not Has_Compatible_Type (Exp, Etype (Index)) then |
| Wrong_Type (Exp, Etype (Index)); |
| Set_Etype (N, Any_Type); |
| return; |
| end if; |
| |
| Next_Index (Index); |
| Next (Exp); |
| end loop; |
| |
| Set_Etype (N, Component_Type (Array_Type)); |
| Check_Implicit_Dereference (N, Etype (N)); |
| |
| if Present (Index) then |
| Error_Msg_N |
| ("too few subscripts in array reference", First (Exprs)); |
| |
| elsif Present (Exp) then |
| Error_Msg_N ("too many subscripts in array reference", Exp); |
| end if; |
| end if; |
| end Process_Indexed_Component; |
| |
| ---------------------------------------- |
| -- Process_Indexed_Component_Or_Slice -- |
| ---------------------------------------- |
| |
| procedure Process_Indexed_Component_Or_Slice is |
| begin |
| Exp := First (Exprs); |
| while Present (Exp) loop |
| Analyze_Expression (Exp); |
| Next (Exp); |
| end loop; |
| |
| Exp := First (Exprs); |
| |
| -- If one index is present, and it is a subtype name, then the node |
| -- denotes a slice (note that the case of an explicit range for a |
| -- slice was already built as an N_Slice node in the first place, |
| -- so that case is not handled here). |
| |
| -- We use a replace rather than a rewrite here because this is one |
| -- of the cases in which the tree built by the parser is plain wrong. |
| |
| if No (Next (Exp)) |
| and then Is_Entity_Name (Exp) |
| and then Is_Type (Entity (Exp)) |
| then |
| Replace (N, |
| Make_Slice (Sloc (N), |
| Prefix => P, |
| Discrete_Range => New_Copy (Exp))); |
| Analyze (N); |
| |
| -- Otherwise (more than one index present, or single index is not |
| -- a subtype name), then we have the indexed component case. |
| |
| else |
| Process_Indexed_Component; |
| end if; |
| end Process_Indexed_Component_Or_Slice; |
| |
| ------------------------------------------ |
| -- Process_Overloaded_Indexed_Component -- |
| ------------------------------------------ |
| |
| procedure Process_Overloaded_Indexed_Component is |
| Exp : Node_Id; |
| I : Interp_Index; |
| It : Interp; |
| Typ : Entity_Id; |
| Index : Node_Id; |
| Found : Boolean; |
| |
| begin |
| Set_Etype (N, Any_Type); |
| |
| Get_First_Interp (P, I, It); |
| while Present (It.Nam) loop |
| Typ := It.Typ; |
| |
| if Is_Access_Type (Typ) then |
| Typ := Designated_Type (Typ); |
| Error_Msg_NW |
| (Warn_On_Dereference, "?d?implicit dereference", N); |
| end if; |
| |
| if Is_Array_Type (Typ) then |
| |
| -- Got a candidate: verify that index types are compatible |
| |
| Index := First_Index (Typ); |
| Found := True; |
| Exp := First (Exprs); |
| while Present (Index) and then Present (Exp) loop |
| if Has_Compatible_Type (Exp, Etype (Index)) then |
| null; |
| else |
| Found := False; |
| Remove_Interp (I); |
| exit; |
| end if; |
| |
| Next_Index (Index); |
| Next (Exp); |
| end loop; |
| |
| if Found and then No (Index) and then No (Exp) then |
| declare |
| CT : constant Entity_Id := |
| Base_Type (Component_Type (Typ)); |
| begin |
| Add_One_Interp (N, CT, CT); |
| Check_Implicit_Dereference (N, CT); |
| end; |
| end if; |
| |
| elsif Try_Container_Indexing (N, P, Exprs) then |
| return; |
| |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| if Etype (N) = Any_Type then |
| Error_Msg_N ("no legal interpretation for indexed component", N); |
| Set_Is_Overloaded (N, False); |
| end if; |
| end Process_Overloaded_Indexed_Component; |
| |
| -- Start of processing for Analyze_Indexed_Component_Form |
| |
| begin |
| -- Get name of array, function or type |
| |
| Analyze (P); |
| |
| -- If P is an explicit dereference whose prefix is of a remote access- |
| -- to-subprogram type, then N has already been rewritten as a subprogram |
| -- call and analyzed. |
| |
| if Nkind (N) in N_Subprogram_Call then |
| return; |
| |
| -- When the prefix is attribute 'Loop_Entry and the sole expression of |
| -- the indexed component denotes a loop name, the indexed form is turned |
| -- into an attribute reference. |
| |
| elsif Nkind (N) = N_Attribute_Reference |
| and then Attribute_Name (N) = Name_Loop_Entry |
| then |
| return; |
| end if; |
| |
| pragma Assert (Nkind (N) = N_Indexed_Component); |
| |
| P_T := Base_Type (Etype (P)); |
| |
| if Is_Entity_Name (P) and then Present (Entity (P)) then |
| U_N := Entity (P); |
| |
| if Is_Type (U_N) then |
| |
| -- Reformat node as a type conversion |
| |
| E := Remove_Head (Exprs); |
| |
| if Present (First (Exprs)) then |
| Error_Msg_N |
| ("argument of type conversion must be single expression", N); |
| end if; |
| |
| Change_Node (N, N_Type_Conversion); |
| Set_Subtype_Mark (N, P); |
| Set_Etype (N, U_N); |
| Set_Expression (N, E); |
| |
| -- After changing the node, call for the specific Analysis |
| -- routine directly, to avoid a double call to the expander. |
| |
| Analyze_Type_Conversion (N); |
| return; |
| end if; |
| |
| if Is_Overloadable (U_N) then |
| Process_Function_Call; |
| |
| elsif Ekind (Etype (P)) = E_Subprogram_Type |
| or else (Is_Access_Type (Etype (P)) |
| and then |
| Ekind (Designated_Type (Etype (P))) = |
| E_Subprogram_Type) |
| then |
| -- Call to access_to-subprogram with possible implicit dereference |
| |
| Process_Function_Call; |
| |
| elsif Is_Generic_Subprogram (U_N) then |
| |
| -- A common beginner's (or C++ templates fan) error |
| |
| Error_Msg_N ("generic subprogram cannot be called", N); |
| Set_Etype (N, Any_Type); |
| return; |
| |
| else |
| Process_Indexed_Component_Or_Slice; |
| end if; |
| |
| -- If not an entity name, prefix is an expression that may denote |
| -- an array or an access-to-subprogram. |
| |
| else |
| if Ekind (P_T) = E_Subprogram_Type |
| or else (Is_Access_Type (P_T) |
| and then |
| Ekind (Designated_Type (P_T)) = E_Subprogram_Type) |
| then |
| Process_Function_Call; |
| |
| elsif Nkind (P) = N_Selected_Component |
| and then Present (Entity (Selector_Name (P))) |
| and then Is_Overloadable (Entity (Selector_Name (P))) |
| then |
| Process_Function_Call; |
| else |
| -- Indexed component, slice, or a call to a member of a family |
| -- entry, which will be converted to an entry call later. |
| |
| Process_Indexed_Component_Or_Slice; |
| end if; |
| end if; |
| |
| Analyze_Dimension (N); |
| end Analyze_Indexed_Component_Form; |
| |
| ------------------------ |
| -- Analyze_Logical_Op -- |
| ------------------------ |
| |
| procedure Analyze_Logical_Op (N : Node_Id) is |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id := Entity (N); |
| |
| begin |
| Set_Etype (N, Any_Type); |
| Candidate_Type := Empty; |
| |
| Analyze_Expression (L); |
| Analyze_Expression (R); |
| |
| if Present (Op_Id) then |
| |
| if Ekind (Op_Id) = E_Operator then |
| Find_Boolean_Types (L, R, Op_Id, N); |
| else |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| else |
| Op_Id := Get_Name_Entity_Id (Chars (N)); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| Find_Boolean_Types (L, R, Op_Id, N); |
| else |
| Analyze_User_Defined_Binary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| Operator_Check (N); |
| Check_Function_Writable_Actuals (N); |
| end Analyze_Logical_Op; |
| |
| --------------------------- |
| -- Analyze_Membership_Op -- |
| --------------------------- |
| |
| procedure Analyze_Membership_Op (N : Node_Id) is |
| Loc : constant Source_Ptr := Sloc (N); |
| L : constant Node_Id := Left_Opnd (N); |
| R : constant Node_Id := Right_Opnd (N); |
| |
| Index : Interp_Index; |
| It : Interp; |
| Found : Boolean := False; |
| I_F : Interp_Index; |
| T_F : Entity_Id; |
| |
| procedure Analyze_Set_Membership; |
| -- If a set of alternatives is present, analyze each and find the |
| -- common type to which they must all resolve. |
| |
| procedure Find_Interpretation; |
| function Find_Interpretation return Boolean; |
| -- Routine and wrapper to find a matching interpretation |
| |
| procedure Try_One_Interp (T1 : Entity_Id); |
| -- Routine to try one proposed interpretation. Note that the context |
| -- of the operation plays no role in resolving the arguments, so that |
| -- if there is more than one interpretation of the operands that is |
| -- compatible with a membership test, the operation is ambiguous. |
| |
| ---------------------------- |
| -- Analyze_Set_Membership -- |
| ---------------------------- |
| |
| procedure Analyze_Set_Membership is |
| Alt : Node_Id; |
| Index : Interp_Index; |
| It : Interp; |
| Candidate_Interps : Node_Id; |
| Common_Type : Entity_Id := Empty; |
| |
| begin |
| Analyze (L); |
| Candidate_Interps := L; |
| |
| if not Is_Overloaded (L) then |
| Common_Type := Etype (L); |
| |
| Alt := First (Alternatives (N)); |
| while Present (Alt) loop |
| Analyze (Alt); |
| |
| if not Has_Compatible_Type (Alt, Common_Type) then |
| Wrong_Type (Alt, Common_Type); |
| end if; |
| |
| Next (Alt); |
| end loop; |
| |
| else |
| Alt := First (Alternatives (N)); |
| while Present (Alt) loop |
| Analyze (Alt); |
| if not Is_Overloaded (Alt) then |
| Common_Type := Etype (Alt); |
| |
| else |
| Get_First_Interp (Alt, Index, It); |
| while Present (It.Typ) loop |
| if not |
| Has_Compatible_Type (Candidate_Interps, It.Typ) |
| then |
| Remove_Interp (Index); |
| end if; |
| |
| Get_Next_Interp (Index, It); |
| end loop; |
| |
| Get_First_Interp (Alt, Index, It); |
| |
| if No (It.Typ) then |
| Error_Msg_N ("alternative has no legal type", Alt); |
| return; |
| end if; |
| |
| -- If alternative is not overloaded, we have a unique type |
| -- for all of them. |
| |
| Set_Etype (Alt, It.Typ); |
| |
| -- If the alternative is an enumeration literal, use the one |
| -- for this interpretation. |
| |
| if Is_Entity_Name (Alt) then |
| Set_Entity (Alt, It.Nam); |
| end if; |
| |
| Get_Next_Interp (Index, It); |
| |
| if No (It.Typ) then |
| Set_Is_Overloaded (Alt, False); |
| Common_Type := Etype (Alt); |
| end if; |
| |
| Candidate_Interps := Alt; |
| end if; |
| |
| Next (Alt); |
| end loop; |
| end if; |
| |
| Set_Etype (N, Standard_Boolean); |
| |
| if Present (Common_Type) then |
| Set_Etype (L, Common_Type); |
| |
| -- The left operand may still be overloaded, to be resolved using |
| -- the Common_Type. |
| |
| else |
| Error_Msg_N ("cannot resolve membership operation", N); |
| end if; |
| end Analyze_Set_Membership; |
| |
| ------------------------- |
| -- Find_Interpretation -- |
| ------------------------- |
| |
| procedure Find_Interpretation is |
| begin |
| if not Is_Overloaded (L) then |
| Try_One_Interp (Etype (L)); |
| |
| else |
| Get_First_Interp (L, Index, It); |
| while Present (It.Typ) loop |
| Try_One_Interp (It.Typ); |
| Get_Next_Interp (Index, It); |
| end loop; |
| end if; |
| end Find_Interpretation; |
| |
| function Find_Interpretation return Boolean is |
| begin |
| Find_Interpretation; |
| |
| return Found; |
| end Find_Interpretation; |
| |
| -------------------- |
| -- Try_One_Interp -- |
| -------------------- |
| |
| procedure Try_One_Interp (T1 : Entity_Id) is |
| begin |
| if Has_Compatible_Type (R, T1, For_Comparison => True) then |
| if Found |
| and then Base_Type (T1) /= Base_Type (T_F) |
| then |
| It := Disambiguate (L, I_F, Index, Any_Type); |
| |
| if It = No_Interp then |
| Ambiguous_Operands (N); |
| Set_Etype (L, Any_Type); |
| return; |
| |
| else |
| T_F := It.Typ; |
| end if; |
| |
| else |
| Found := True; |
| T_F := T1; |
| I_F := Index; |
| end if; |
| |
| Set_Etype (L, T_F); |
| end if; |
| end Try_One_Interp; |
| |
| Op : Node_Id; |
| |
| -- Start of processing for Analyze_Membership_Op |
| |
| begin |
| Analyze_Expression (L); |
| |
| if No (R) then |
| pragma Assert (Ada_Version >= Ada_2012); |
| Analyze_Set_Membership; |
| Check_Function_Writable_Actuals (N); |
| return; |
| end if; |
| |
| if Nkind (R) = N_Range |
| or else (Nkind (R) = N_Attribute_Reference |
| and then Attribute_Name (R) = Name_Range) |
| then |
| Analyze (R); |
| |
| Find_Interpretation; |
| |
| -- If not a range, it can be a subtype mark, or else it is a degenerate |
| -- membership test with a singleton value, i.e. a test for equality, |
| -- if the types are compatible. |
| |
| else |
| Analyze (R); |
| |
| if Is_Entity_Name (R) and then Is_Type (Entity (R)) then |
| Find_Type (R); |
| Check_Fully_Declared (Entity (R), R); |
| |
| elsif Ada_Version >= Ada_2012 and then Find_Interpretation then |
| if Nkind (N) = N_In then |
| Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R); |
| else |
| Op := Make_Op_Ne (Loc, Left_Opnd => L, Right_Opnd => R); |
| end if; |
| |
| if Is_Record_Or_Limited_Type (Etype (L)) then |
| |
| -- We reset the Entity in order to use the primitive equality |
| -- of the type, as per RM 4.5.2 (28.1/4). |
| |
| Set_Entity (Op, Empty); |
| end if; |
| |
| Rewrite (N, Op); |
| Analyze (N); |
| return; |
| |
| else |
| -- In all versions of the language, if we reach this point there |
| -- is a previous error that will be diagnosed below. |
| |
| Find_Type (R); |
| end if; |
| end if; |
| |
| -- Compatibility between expression and subtype mark or range is |
| -- checked during resolution. The result of the operation is Boolean |
| -- in any case. |
| |
| Set_Etype (N, Standard_Boolean); |
| |
| if Comes_From_Source (N) |
| and then Present (Right_Opnd (N)) |
| and then Is_CPP_Class (Etype (Etype (Right_Opnd (N)))) |
| then |
| Error_Msg_N ("membership test not applicable to cpp-class types", N); |
| end if; |
| |
| Check_Function_Writable_Actuals (N); |
| end Analyze_Membership_Op; |
| |
| ----------------- |
| -- Analyze_Mod -- |
| ----------------- |
| |
| procedure Analyze_Mod (N : Node_Id) is |
| begin |
| -- A special warning check, if we have an expression of the form: |
| -- expr mod 2 * literal |
| -- where literal is 128 or less, then probably what was meant was |
| -- expr mod 2 ** literal |
| -- so issue an appropriate warning. |
| |
| if Warn_On_Suspicious_Modulus_Value |
| and then Nkind (Right_Opnd (N)) = N_Integer_Literal |
| and then Intval (Right_Opnd (N)) = Uint_2 |
| and then Nkind (Parent (N)) = N_Op_Multiply |
| and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal |
| and then Intval (Right_Opnd (Parent (N))) <= Uint_128 |
| then |
| Error_Msg_N |
| ("suspicious MOD value, was '*'* intended'??.m?", Parent (N)); |
| end if; |
| |
| -- Remaining processing is same as for other arithmetic operators |
| |
| Analyze_Arithmetic_Op (N); |
| end Analyze_Mod; |
| |
| ---------------------- |
| -- Analyze_Negation -- |
| ---------------------- |
| |
| procedure Analyze_Negation (N : Node_Id) is |
| R : constant Node_Id := Right_Opnd (N); |
| Op_Id : Entity_Id := Entity (N); |
| |
| begin |
| Set_Etype (N, Any_Type); |
| Candidate_Type := Empty; |
| |
| Analyze_Expression (R); |
| |
| if Present (Op_Id) then |
| if Ekind (Op_Id) = E_Operator then |
| Find_Negation_Types (R, Op_Id, N); |
| else |
| Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
| end if; |
| |
| else |
| Op_Id := Get_Name_Entity_Id (Chars (N)); |
| while Present (Op_Id) loop |
| if Ekind (Op_Id) = E_Operator then |
| Find_Negation_Types (R, Op_Id, N); |
| else |
| Analyze_User_Defined_Unary_Op (N, Op_Id); |
| end if; |
| |
| Op_Id := Homonym (Op_Id); |
| end loop; |
| end if; |
| |
| Operator_Check (N); |
| end Analyze_Negation; |
| |
| ------------------ |
| -- Analyze_Null -- |
| ------------------ |
| |
| procedure Analyze_Null (N : Node_Id) is |
| begin |
| Set_Etype (N, Universal_Access); |
| end Analyze_Null; |
| |
| ---------------------- |
| -- Analyze_One_Call -- |
| ---------------------- |
| |
| procedure Analyze_One_Call |
| (N : Node_Id; |
| Nam : Entity_Id; |
| Report : Boolean; |
| Success : out Boolean; |
| Skip_First : Boolean := False) |
| is |
| Actuals : constant List_Id := Parameter_Associations (N); |
| Prev_T : constant Entity_Id := Etype (N); |
| |
| -- Recognize cases of prefixed calls that have been rewritten in |
| -- various ways. The simplest case is a rewritten selected component, |
| -- but it can also be an already-examined indexed component, or a |
| -- prefix that is itself a rewritten prefixed call that is in turn |
| -- an indexed call (the syntactic ambiguity involving the indexing of |
| -- a function with defaulted parameters that returns an array). |
| -- A flag Maybe_Indexed_Call might be useful here ??? |
| |
| Must_Skip : constant Boolean := Skip_First |
| or else Nkind (Original_Node (N)) = N_Selected_Component |
| or else |
| (Nkind (Original_Node (N)) = N_Indexed_Component |
| and then Nkind (Prefix (Original_Node (N))) = |
| N_Selected_Component) |
| or else |
| (Nkind (Parent (N)) = N_Function_Call |
| and then Is_Array_Type (Etype (Name (N))) |
| and then Etype (Original_Node (N)) = |
| Component_Type (Etype (Name (N))) |
| and then Nkind (Original_Node (Parent (N))) = |
| N_Selected_Component); |
| |
| -- The first formal must be omitted from the match when trying to find |
| -- a primitive operation that is a possible interpretation, and also |
| -- after the call has been rewritten, because the corresponding actual |
| -- is already known to be compatible, and because this may be an |
| -- indexing of a call with default parameters. |
| |
| First_Form : Entity_Id; |
| Formal : Entity_Id; |
| Actual : Node_Id; |
| Is_Indexed : Boolean := False; |
| Is_Indirect : Boolean := False; |
| Subp_Type : constant Entity_Id := Etype (Nam); |
| Norm_OK : Boolean; |
| |
| function Compatible_Types_In_Predicate |
| (T1 : Entity_Id; |
| T2 : Entity_Id) return Boolean; |
| -- For an Ada 2012 predicate or invariant, a call may mention an |
| -- incomplete type, while resolution of the corresponding predicate |
| -- function may see the full view, as a consequence of the delayed |
| -- resolution of the corresponding expressions. This may occur in |
| -- the body of a predicate function, or in a call to such. Anomalies |
| -- involving private and full views can also happen. In each case, |
| -- rewrite node or add conversions to remove spurious type errors. |
| |
| procedure Indicate_Name_And_Type; |
| -- If candidate interpretation matches, indicate name and type of result |
| -- on call node. |
| |
| function Operator_Hidden_By (Fun : Entity_Id) return Boolean; |
| -- There may be a user-defined operator that hides the current |
| -- interpretation. We must check for this independently of the |
| -- analysis of the call with the user-defined operation, because |
| -- the parameter names may be wrong and yet the hiding takes place. |
| -- This fixes a problem with ACATS test B34014O. |
| -- |
| -- When the type Address is a visible integer type, and the DEC |
| -- system extension is visible, the predefined operator may be |
| -- hidden as well, by one of the address operations in auxdec. |
| -- Finally, the abstract operations on address do not hide the |
| -- predefined operator (this is the purpose of making them abstract). |
| |
| ----------------------------------- |
| -- Compatible_Types_In_Predicate -- |
| ----------------------------------- |
| |
| function Compatible_Types_In_Predicate |
| (T1 : Entity_Id; |
| T2 : Entity_Id) return Boolean |
| is |
| function Common_Type (T : Entity_Id) return Entity_Id; |
| -- Find non-private underlying full view if any, without going to |
| -- ancestor type (as opposed to Underlying_Type). |
| |
| ----------------- |
| -- Common_Type -- |
| ----------------- |
| |
| function Common_Type (T : Entity_Id) return Entity_Id is |
| CT : Entity_Id; |
| |
| begin |
| CT := T; |
| |
| if Is_Private_Type (CT) and then Present (Full_View (CT)) then |
| CT := Full_View (CT); |
| end if; |
| |
| if Is_Private_Type (CT) |
| and then Present (Underlying_Full_View (CT)) |
| then |
| CT := Underlying_Full_View (CT); |
| end if; |
| |
| return Base_Type (CT); |
| end Common_Type; |
| |
| -- Start of processing for Compatible_Types_In_Predicate |
| |
| begin |
| if (Ekind (Current_Scope) = E_Function |
| and then Is_Predicate_Function (Current_Scope)) |
| or else |
| (Ekind (Nam) = E_Function |
| and then Is_Predicate_Function (Nam)) |
| then |
| if Is_Incomplete_Type (T1) |
| and then Present (Full_View (T1)) |
| and then Full_View (T1) = T2 |
| then |
| Set_Etype (Formal, Etype (Actual)); |
| return True; |
| |
| elsif Common_Type (T1) = Common_Type (T2) then |
| Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual)); |
| return True; |
| |
| else |
| return False; |
| end if; |
| |
| else |
| return False; |
| end if; |
| end Compatible_Types_In_Predicate; |
| |
| ---------------------------- |
| -- Indicate_Name_And_Type -- |
| ---------------------------- |
| |
| procedure Indicate_Name_And_Type is |
| begin |
| Add_One_Interp (N, Nam, Etype (Nam)); |
| Check_Implicit_Dereference (N, Etype (Nam)); |
| Success := True; |
| |
| -- If the prefix of the call is a name, indicate the entity |
| -- being called. If it is not a name, it is an expression that |
| -- denotes an access to subprogram or else an entry or family. In |
| -- the latter case, the name is a selected component, and the entity |
| -- being called is noted on the selector. |
| |
| if not Is_Type (Nam) then |
| if Is_Entity_Name (Name (N)) then |
| Set_Entity (Name (N), Nam); |
| Set_Etype (Name (N), Etype (Nam)); |
| |
| elsif Nkind (Name (N)) = N_Selected_Component then |
| Set_Entity (Selector_Name (Name (N)), Nam); |
| end if; |
| end if; |
| |
| if Debug_Flag_E and not Report then |
| Write_Str (" Overloaded call "); |
| Write_Int (Int (N)); |
| Write_Str (" compatible with "); |
| Write_Int (Int (Nam)); |
| Write_Eol; |
| end if; |
| end Indicate_Name_And_Type; |
| |
| ------------------------ |
| -- Operator_Hidden_By -- |
| ------------------------ |
| |
| function Operator_Hidden_By (Fun : Entity_Id) return Boolean is |
| Act1 : constant Node_Id := First_Actual (N); |
| Act2 : constant Node_Id := Next_Actual (Act1); |
| Form1 : constant Entity_Id := First_Formal (Fun); |
| Form2 : constant Entity_Id := Next_Formal (Form1); |
| |
| begin |
| if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then |
| return False; |
| |
| elsif not Has_Compatible_Type (Act1, Etype (Form1)) then |
| return False; |
| |
| elsif Present (Form2) then |
| if No (Act2) |
| or else not Has_Compatible_Type (Act2, Etype (Form2)) |
| then |
| return False; |
| end if; |
| |
| elsif Present (Act2) then |
| return False; |
| end if; |
| |
| -- Now we know that the arity of the operator matches the function, |
| -- and the function call is a valid interpretation. The function |
| -- hides the operator if it has the right signature, or if one of |
| -- its operands is a non-abstract operation on Address when this is |
| -- a visible integer type. |
| |
| return Hides_Op (Fun, Nam) |
| or else Is_Descendant_Of_Address (Etype (Form1)) |
| or else |
| (Present (Form2) |
| and then Is_Descendant_Of_Address (Etype (Form2))); |
| end Operator_Hidden_By; |
| |
| -- Start of processing for Analyze_One_Call |
| |
| begin |
| Success := False; |
| |
| -- If the subprogram has no formals or if all the formals have defaults, |
| -- and the return type is an array type, the node may denote an indexing |
| -- of the result of a parameterless call. In Ada 2005, the subprogram |
| -- may have one non-defaulted formal, and the call may have been written |
| -- in prefix notation, so that the rebuilt parameter list has more than |
| -- one actual. |
| |
| if not Is_Overloadable (Nam) |
| and then Ekind (Nam) /= E_Subprogram_Type |
| and then Ekind (Nam) /= E_Entry_Family |
| then |
| return; |
| end if; |
| |
| -- An indexing requires at least one actual. The name of the call cannot |
| -- be an implicit indirect call, so it cannot be a generated explicit |
| -- dereference. |
| |
| if not Is_Empty_List (Actuals) |
| and then |
| (Needs_No_Actuals (Nam) |
| or else |
| (Needs_One_Actual (Nam) |
| and then Present (Next_Actual (First (Actuals))))) |
| then |
| if Is_Array_Type (Subp_Type) |
| and then |
| (Nkind (Name (N)) /= N_Explicit_Dereference |
| or else Comes_From_Source (Name (N))) |
| then |
| Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip); |
| |
| elsif Is_Access_Type (Subp_Type) |
| and then Is_Array_Type (Designated_Type (Subp_Type)) |
| then |
| Is_Indexed := |
| Try_Indexed_Call |
| (N, Nam, Designated_Type (Subp_Type), Must_Skip); |
| |
| -- The prefix can also be a parameterless function that returns an |
| -- access to subprogram, in which case this is an indirect call. |
| -- If this succeeds, an explicit dereference is added later on, |
| -- in Analyze_Call or Resolve_Call. |
| |
| elsif Is_Access_Type (Subp_Type) |
| and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type |
| then |
| Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type); |
| end if; |
| |
| end if; |
| |
| -- If the call has been transformed into a slice, it is of the form |
| -- F (Subtype) where F is parameterless. The node has been rewritten in |
| -- Try_Indexed_Call and there is nothing else to do. |
| |
| if Is_Indexed |
| and then Nkind (N) = N_Slice |
| then |
| return; |
| end if; |
| |
| Normalize_Actuals |
| (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK); |
| |
| if not Norm_OK then |
| |
| -- If an indirect call is a possible interpretation, indicate |
| -- success to the caller. This may be an indexing of an explicit |
| -- dereference of a call that returns an access type (see above). |
| |
| if Is_Indirect |
| or else (Is_Indexed |
| and then Nkind (Name (N)) = N_Explicit_Dereference |
| and then Comes_From_Source (Name (N))) |
| then |
| Success := True; |
| return; |
| |
| -- Mismatch in number or names of parameters |
| |
| elsif Debug_Flag_E then |
| Write_Str (" normalization fails in call "); |
| Write_Int (Int (N)); |
| Write_Str (" with subprogram "); |
| Write_Int (Int (Nam)); |
| Write_Eol; |
| end if; |
| |
| -- If the context expects a function call, discard any interpretation |
| -- that is a procedure. If the node is not overloaded, leave as is for |
| -- better error reporting when type mismatch is found. |
| |
| elsif Nkind (N) = N_Function_Call |
| and then Is_Overloaded (Name (N)) |
| and then Ekind (Nam) = E_Procedure |
| then |
| return; |
| |
| -- Ditto for function calls in a procedure context |
| |
| elsif Nkind (N) = N_Procedure_Call_Statement |
| and then Is_Overloaded (Name (N)) |
| and then Etype (Nam) /= Standard_Void_Type |
| then |
| return; |
| |
| elsif No (Actuals) then |
| |
| -- If Normalize succeeds, then there are default parameters for |
| -- all formals. |
| |
| Indicate_Name_And_Type; |
| |
| elsif Ekind (Nam) = E_Operator then |
| if Nkind (N) = N_Procedure_Call_Statement then |
| return; |
| end if; |
| |
| -- This can occur when the prefix of the call is an operator |
| -- name or an expanded name whose selector is an operator name. |
| |
| Analyze_Operator_Call (N, Nam); |
| |
| if Etype (N) /= Prev_T then |
| |
| -- Check that operator is not hidden by a function interpretation |
| |
| if Is_Overloaded (Name (N)) then |
| declare |
| I : Interp_Index; |
| It : Interp; |
| |
| begin |
| Get_First_Interp (Name (N), I, It); |
| while Present (It.Nam) loop |
| if Operator_Hidden_By (It.Nam) then |
| Set_Etype (N, Prev_T); |
| return; |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end; |
| end if; |
| |
| -- If operator matches formals, record its name on the call. |
| -- If the operator is overloaded, Resolve will select the |
| -- correct one from the list of interpretations. The call |
| -- node itself carries the first candidate. |
| |
| Set_Entity (Name (N), Nam); |
| Success := True; |
| |
| elsif Report and then Etype (N) = Any_Type then |
| Error_Msg_N ("incompatible arguments for operator", N); |
| end if; |
| |
| else |
| -- Normalize_Actuals has chained the named associations in the |
| -- correct order of the formals. |
| |
| Actual := First_Actual (N); |
| Formal := First_Formal (Nam); |
| First_Form := Formal; |
| |
| -- If we are analyzing a call rewritten from object notation, skip |
| -- first actual, which may be rewritten later as an explicit |
| -- dereference. |
| |
| if Must_Skip then |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| end if; |
| |
| while Present (Actual) and then Present (Formal) loop |
| if Nkind (Parent (Actual)) /= N_Parameter_Association |
| or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal) |
| then |
| -- The actual can be compatible with the formal, but we must |
| -- also check that the context is not an address type that is |
| -- visibly an integer type. In this case the use of literals is |
| -- illegal, except in the body of descendants of system, where |
| -- arithmetic operations on address are of course used. |
| |
| if Has_Compatible_Type (Actual, Etype (Formal)) |
| and then |
| (Etype (Actual) /= Universal_Integer |
| or else not Is_Descendant_Of_Address (Etype (Formal)) |
| or else In_Predefined_Unit (N)) |
| then |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| |
| -- In Allow_Integer_Address mode, we allow an actual integer to |
| -- match a formal address type and vice versa. We only do this |
| -- if we are certain that an error will otherwise be issued |
| |
| elsif Address_Integer_Convert_OK |
| (Etype (Actual), Etype (Formal)) |
| and then (Report and not Is_Indexed and not Is_Indirect) |
| then |
| -- Handle this case by introducing an unchecked conversion |
| |
| Rewrite (Actual, |
| Unchecked_Convert_To (Etype (Formal), |
| Relocate_Node (Actual))); |
| Analyze_And_Resolve (Actual, Etype (Formal)); |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| |
| -- Under relaxed RM semantics silently replace occurrences of |
| -- null by System.Address_Null. We only do this if we know that |
| -- an error will otherwise be issued. |
| |
| elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal)) |
| and then (Report and not Is_Indexed and not Is_Indirect) |
| then |
| Replace_Null_By_Null_Address (Actual); |
| Analyze_And_Resolve (Actual, Etype (Formal)); |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| |
| elsif Compatible_Types_In_Predicate |
| (Etype (Formal), Etype (Actual)) |
| then |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| |
| -- A current instance used as an actual of a function, |
| -- whose body has not been seen, may include a formal |
| -- whose type is an incomplete view of an enclosing |
| -- type declaration containing the current call (e.g. |
| -- in the Expression for a component declaration). |
| |
| -- In this case, update the signature of the subprogram |
| -- so the formal has the type of the full view. |
| |
| elsif Inside_Init_Proc |
| and then Nkind (Actual) = N_Identifier |
| and then Ekind (Etype (Formal)) = E_Incomplete_Type |
| and then Etype (Actual) = Full_View (Etype (Formal)) |
| then |
| Set_Etype (Formal, Etype (Actual)); |
| Next_Actual (Actual); |
| Next_Formal (Formal); |
| |
| -- Handle failed type check |
| |
| else |
| if Debug_Flag_E then |
| Write_Str (" type checking fails in call "); |
| Write_Int (Int (N)); |
| Write_Str (" with formal "); |
| Write_Int (Int (Formal)); |
| Write_Str (" in subprogram "); |
| Write_Int (Int (Nam)); |
| Write_Eol; |
| end if; |
| |
| -- Comment needed on the following test??? |
| |
| if Report and not Is_Indexed and not Is_Indirect then |
| |
| -- Ada 2005 (AI-251): Complete the error notification |
| -- to help new Ada 2005 users. |
| |
| if Is_Class_Wide_Type (Etype (Formal)) |
| and then Is_Interface (Etype (Etype (Formal))) |
| and then not Interface_Present_In_Ancestor |
| (Typ => Etype (Actual), |
| Iface => Etype (Etype (Formal))) |
| then |
| Error_Msg_NE |
| ("(Ada 2005) does not implement interface }", |
| Actual, Etype (Etype (Formal))); |
| end if; |
| |
| Wrong_Type (Actual, Etype (Formal)); |
| |
| if Nkind (Actual) = N_Op_Eq |
| and then Nkind (Left_Opnd (Actual)) = N_Identifier |
| then |
| Formal := First_Formal (Nam); |
| while Present (Formal) loop |
| if Chars (Left_Opnd (Actual)) = Chars (Formal) then |
| Error_Msg_N -- CODEFIX |
| ("possible misspelling of `='>`!", Actual); |
| exit; |
| end if; |
| |
| Next_Formal (Formal); |
| end loop; |
| end if; |
| |
| if All_Errors_Mode then |
| Error_Msg_Sloc := Sloc (Nam); |
| |
| if Etype (Formal) = Any_Type then |
| Error_Msg_N |
| ("there is no legal actual parameter", Actual); |
| end if; |
| |
| if Is_Overloadable (Nam) |
| and then Present (Alias (Nam)) |
| and then not Comes_From_Source (Nam) |
| then |
| Error_Msg_NE |
| ("\\ =='> in call to inherited operation & #!", |
| Actual, Nam); |
| |
| elsif Ekind (Nam) = E_Subprogram_Type then |
| declare |
| Access_To_Subprogram_Typ : |
| constant Entity_Id := |
| Defining_Identifier |
| (Associated_Node_For_Itype (Nam)); |
| begin |
| Error_Msg_NE |
| ("\\ =='> in call to dereference of &#!", |
| Actual, Access_To_Subprogram_Typ); |
| end; |
| |
| else |
| Error_Msg_NE |
| ("\\ =='> in call to &#!", Actual, Nam); |
| |
| end if; |
| end if; |
| end if; |
| |
| return; |
| end if; |
| |
| else |
| -- Normalize_Actuals has verified that a default value exists |
| -- for this formal. Current actual names a subsequent formal. |
| |
| Next_Formal (Formal); |
| end if; |
| end loop; |
| |
| -- Due to our current model of controlled type expansion we may |
| -- have resolved a user call to a non-visible controlled primitive |
| -- since these inherited subprograms may be generated in the current |
| -- scope. This is a side effect of the need for the expander to be |
| -- able to resolve internally generated calls. |
| |
| -- Specifically, the issue appears when predefined controlled |
| -- operations get called on a type extension whose parent is a |
| -- private extension completed with a controlled extension - see |
| -- below: |
| |
| -- package X is |
| -- type Par_Typ is tagged private; |
| -- private |
| -- type Par_Typ is new Controlled with null record; |
| -- end; |
| -- ... |
| -- procedure Main is |
| -- type Ext_Typ is new Par_Typ with null record; |
| -- Obj : Ext_Typ; |
| -- begin |
| -- Finalize (Obj); -- Will improperly resolve |
| -- end; |
| |
| -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such |
| -- primitives, but we still need to verify that Nam is indeed a |
| -- non-visible controlled subprogram. So, we do that here and issue |
| -- the appropriate error. |
| |
| if Is_Hidden (Nam) |
| and then not In_Instance |
| and then not Comes_From_Source (Nam) |
| and then Comes_From_Source (N) |
| |
| -- Verify Nam is a non-visible controlled primitive |
| |
| and then Chars (Nam) in Name_Adjust |
| | Name_Finalize |
| | Name_Initialize |
| and then Ekind (Nam) = E_Procedure |
| and then Is_Controlled (Etype (First_Form)) |
| and then No (Next_Formal (First_Form)) |
| and then not Is_Visibly_Controlled (Etype (First_Form)) |
| then |
| Error_Msg_Node_2 := Etype (First_Form); |
| Error_Msg_NE ("call to non-visible controlled primitive & on type" |
| & " &", N, Nam); |
| end if; |
| |
| -- On exit, all actuals match |
| |
| Indicate_Name_And_Type; |
| end if; |
| end Analyze_One_Call; |
| |
| --------------------------- |
| -- Analyze_Operator_Call -- |
| --------------------------- |
| |
| procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is |
| Op_Name : constant Name_Id := Chars (Op_Id); |
| Act1 : constant Node_Id := First_Actual (N); |
| Act2 : constant Node_Id := Next_Actual (Act1); |
| |
| begin |
| -- Binary operator case |
| |
| if Present (Act2) then |
| |
| -- If more than two operands, then not binary operator after all |
| |
| if Present (Next_Actual (Act2)) then |
| return; |
| end if; |
| |
| -- Otherwise action depends on operator |
| |
| case Op_Name is |
| when Name_Op_Add |
| | Name_Op_Divide |
| | Name_Op_Expon |
| | Name_Op_Mod |
| | Name_Op_Multiply |
| | Name_Op_Rem |
| | Name_Op_Subtract |
| => |
| Find_Arithmetic_Types (Act1, Act2, Op_Id, N); |
| |
| when Name_Op_And |
| | Name_Op_Or |
| | Name_Op_Xor |
| => |
| Find_Boolean_Types (Act1, Act2, Op_Id, N); |
| |
| when Name_Op_Ge |
| | Name_Op_Gt |
| | Name_Op_Le |
| | Name_Op_Lt |
| => |
| Find_Comparison_Types (Act1, Act2, Op_Id, N); |
| |
| when Name_Op_Eq |
| | Name_Op_Ne |
| => |
| Find_Equality_Types (Act1, Act2, Op_Id, N); |
| |
| when Name_Op_Concat => |
| Find_Concatenation_Types (Act1, Act2, Op_Id, N); |
| |
| -- Is this when others, or should it be an abort??? |
| |
| when others => |
| null; |
| end case; |
| |
| -- Unary operator case |
| |
| else |
| case Op_Name is |
| when Name_Op_Abs |
| | Name_Op_Add |
| | Name_Op_Subtract |
| => |
| Find_Unary_Types (Act1, Op_Id, N); |
| |
| when Name_Op_Not => |
| Find_Negation_Types (Act1, Op_Id, N); |
| |
| -- Is this when others correct, or should it be an abort??? |
| |
| when others => |
| null; |
| end case; |
| end if; |
| end Analyze_Operator_Call; |
| |
| ------------------------------------------- |
| -- Analyze_Overloaded_Selected_Component -- |
| ------------------------------------------- |
| |
| procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is |
| Nam : constant Node_Id := Prefix (N); |
| Sel : constant Node_Id := Selector_Name (N); |
| Comp : Entity_Id; |
| I : Interp_Index; |
| It : Interp; |
| T : Entity_Id; |
| |
| begin |
| Set_Etype (Sel, Any_Type); |
| |
| Get_First_Interp (Nam, I, It); |
| while Present (It.Typ) loop |
| if Is_Access_Type (It.Typ) then |
| T := Designated_Type (It.Typ); |
| Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N); |
| else |
| T := It.Typ; |
| end if; |
| |
| -- Locate the component. For a private prefix the selector can denote |
| -- a discriminant. |
| |
| if Is_Record_Type (T) or else Is_Private_Type (T) then |
| |
| -- If the prefix is a class-wide type, the visible components are |
| -- those of the base type. |
| |
| if Is_Class_Wide_Type (T) then |
| T := Etype (T); |
| end if; |
| |
| Comp := First_Entity (T); |
| while Present (Comp) loop |
| if Chars (Comp) = Chars (Sel) |
| and then Is_Visible_Component (Comp, Sel) |
| then |
| |
| -- AI05-105: if the context is an object renaming with |
| -- an anonymous access type, the expected type of the |
| -- object must be anonymous. This is a name resolution rule. |
| |
| if Nkind (Parent (N)) /= N_Object_Renaming_Declaration |
| or else No (Access_Definition (Parent (N))) |
| or else Is_Anonymous_Access_Type (Etype (Comp)) |
| then |
| Set_Entity (Sel, Comp); |
| Set_Etype (Sel, Etype (Comp)); |
| Add_One_Interp (N, Etype (Comp), Etype (Comp)); |
| Check_Implicit_Dereference (N, Etype (Comp)); |
| |
| -- This also specifies a candidate to resolve the name. |
| -- Further overloading will be resolved from context. |
| -- The selector name itself does not carry overloading |
| -- information. |
| |
| Set_Etype (Nam, It.Typ); |
| |
| else |
| -- Named access type in the context of a renaming |
| -- declaration with an access definition. Remove |
| -- inapplicable candidate. |
| |
| Remove_Interp (I); |
| end if; |
| end if; |
| |
| Next_Entity (Comp); |
| end loop; |
| |
| elsif Is_Concurrent_Type (T) then |
| Comp := First_Entity (T); |
| while Present (Comp) |
| and then Comp /= First_Private_Entity (T) |
| loop |
| if Chars (Comp) = Chars (Sel) then |
| if Is_Overloadable (Comp) then |
| Add_One_Interp (Sel, Comp, Etype (Comp)); |
| else |
| Set_Entity_With_Checks (Sel, Comp); |
| Generate_Reference (Comp, Sel); |
| end if; |
| |
| Set_Etype (Sel, Etype (Comp)); |
| Set_Etype (N, Etype (Comp)); |
| Set_Etype (Nam, It.Typ); |
| end if; |
| |
| Next_Entity (Comp); |
| end loop; |
| |
| Set_Is_Overloaded (N, Is_Overloaded (Sel)); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| |
| if Etype (N) = Any_Type |
| and then not Try_Object_Operation (N) |
| then |
| Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel); |
| Set_Entity (Sel, Any_Id); |
| Set_Etype (Sel, Any_Type); |
| end if; |
| end Analyze_Overloaded_Selected_Component; |
| |
| ---------------------------------- |
| -- Analyze_Qualified_Expression -- |
| ---------------------------------- |
| |
| procedure Analyze_Qualified_Expression (N : Node_Id) is |
| Mark : constant Entity_Id := Subtype_Mark (N); |
| Expr : constant Node_Id := Expression (N); |
| I : Interp_Index; |
| It : Interp; |
| T : Entity_Id; |
| |
| begin |
| Analyze_Expression (Expr); |
| |
| Set_Etype (N, Any_Type); |
| Find_Type (Mark); |
| T := Entity (Mark); |
| |
| if Nkind (Enclosing_Declaration (N)) in |
| N_Formal_Type_Declaration | |
| N_Full_Type_Declaration | |
| N_Incomplete_Type_Declaration | |
| N_Protected_Type_Declaration | |
| N_Private_Extension_Declaration | |
| N_Private_Type_Declaration | |
| N_Subtype_Declaration | |
| N_Task_Type_Declaration |
| and then T = Defining_Identifier (Enclosing_Declaration (N)) |
| then |
| Error_Msg_N ("current instance not allowed", Mark); |
| T := Any_Type; |
| end if; |
| |
| Set_Etype (N, T); |
| |
| if T = Any_Type then |
| return; |
| end if; |
| |
| Check_Fully_Declared (T, N); |
| |
| -- If expected type is class-wide, check for exact match before |
| -- expansion, because if the expression is a dispatching call it |
| -- may be rewritten as explicit dereference with class-wide result. |
| -- If expression is overloaded, retain only interpretations that |
| -- will yield exact matches. |
| |
| if Is_Class_Wide_Type (T) then |
| if not Is_Overloaded (Expr) then |
| if Base_Type (Etype (Expr)) /= Base_Type (T) |
| and then Etype (Expr) /= Raise_Type |
| then |
| if Nkind (Expr) = N_Aggregate then |
| Error_Msg_N ("type of aggregate cannot be class-wide", Expr); |
| else |
| Wrong_Type (Expr, T); |
| end if; |
| end if; |
| |
| else |
| Get_First_Interp (Expr, I, It); |
| |
| while Present (It.Nam) loop |
| if Base_Type (It.Typ) /= Base_Type (T) then |
| Remove_Interp (I); |
| end if; |
| |
| Get_Next_Interp (I, It); |
| end loop; |
| end if; |
| end if; |
| |
| Set_Etype (N, T); |
| end Analyze_Qualified_Expression; |
| |
| ----------------------------------- |
| -- Analyze_Quantified_Expression -- |
| ----------------------------------- |
| |
| procedure Analyze_Quantified_Expression (N : Node_Id) is |
| function Is_Empty_Range (Typ : Entity_Id) return Boolean; |
| -- If the iterator is part of a quantified expression, and the range is |
| -- known to be statically empty, emit a warning and replace expression |
| -- with its static value. Returns True if the replacement occurs. |
| |
| function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean; |
| -- Determine whether if expression If_Expr lacks an else part or if it |
| -- has one, it evaluates to True. |
| |
| -------------------- |
| -- Is_Empty_Range -- |
| -------------------- |
| |
| function Is_Empty_Range (Typ : Entity_Id) return Boolean is |
| Loc : constant Source_Ptr := Sloc (N); |
| |
| begin |
| if Is_Array_Type (Typ) |
| and then Compile_Time_Known_Bounds (Typ) |
| and then |
| (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) > |
| Expr_Value (Type_High_Bound (Etype (First_Index (Typ))))) |
| then |
| Preanalyze_And_Resolve (Condition (N), Standard_Boolean); |
| |
| if All_Present (N) then |
| Error_Msg_N |
| ("??quantified expression with ALL " |
| & "over a null range has value True", N); |
| Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); |
| |
| else |
| Error_Msg_N |
| ("??quantified expression with SOME " |
| & "over a null range has value False", N); |
| Rewrite (N, New_Occurrence_Of (Standard_False, Loc)); |
| end if; |
| |
| Analyze (N); |
| return True; |
| |
| else |
| return False; |
| end if; |
| end Is_Empty_Range; |
| |
| ----------------------------- |
| -- No_Else_Or_Trivial_True -- |
| ----------------------------- |
| |
| function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is |
| Else_Expr : constant Node_Id := |
| Next (Next (First (Expressions (If_Expr)))); |
| begin |
| return |
| No (Else_Expr) |
| or else (Compile_Time_Known_Value (Else_Expr) |
| and then Is_True (Expr_Value (Else_Expr))); |
| end No_Else_Or_Trivial_True; |
| |
| -- Local variables |
| |
| Cond : constant Node_Id := Condition (N); |
| Loop_Id : Entity_Id; |
| QE_Scop : Entity_Id; |
| |
| -- Start of processing for Analyze_Quantified_Expression |
| |
| begin |
| -- Create a scope to emulate the loop-like behavior of the quantified |
| -- expression. The scope is needed to provide proper visibility of the |
| -- loop variable. |
| |
| QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L'); |
| Set_Etype (QE_Scop, Standard_Void_Type); |
| Set_Scope (QE_Scop, Current_Scope); |
| Set_Parent (QE_Scop, N); |
| |
| Push_Scope (QE_Scop); |
| |
| -- All constituents are preanalyzed and resolved to avoid untimely |
| -- generation of various temporaries and types. Full analysis and |
| -- expansion is carried out when the quantified expression is |
| -- transformed into an expression with actions. |
| |
| if Present (Iterator_Specification (N)) then |
| Preanalyze (Iterator_Specification (N)); |
| |
| -- Do not proceed with the analysis when the range of iteration is |
| -- empty. The appropriate error is issued by Is_Empty_Range. |
| |
| if Is_Entity_Name (Name (Iterator_Specification (N))) |
| and then Is_Empty_Range (Etype (Name (Iterator_Specification (N)))) |
| then |
| return; |
| end if; |
| |
| else pragma Assert (Present (Loop_Parameter_Specification (N))); |
| declare |
| Loop_Par : constant Node_Id := Loop_Parameter_Specification (N); |
| |
| begin |
| Preanalyze (Loop_Par); |
| |
| if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call |
| and then Parent (Loop_Par) /= N |
| then |
| -- The parser cannot distinguish between a loop specification |
| -- and an iterator specification. If after preanalysis the |
| -- proper form has been recognized, rewrite the expression to |
| -- reflect the right kind. This is needed for proper ASIS |
| -- navigation. If expansion is enabled, the transformation is |
| -- performed when the expression is rewritten as a loop. |
| -- Is this still needed??? |
| |
| Set_Iterator_Specification (N, |
| New_Copy_Tree (Iterator_Specification (Parent (Loop_Par)))); |
| |
| Set_Defining_Identifier (Iterator_Specification (N), |
| Relocate_Node (Defining_Identifier (Loop_Par))); |
| Set_Name (Iterator_Specification (N), |
| Relocate_Node (Discrete_Subtype_Definition (Loop_Par))); |
|