From 786c6ba5a51f54c404dd491523788f7359a29a91 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Wed, 19 Oct 2022 12:39:42 +0200 Subject: ada: Remove redundant line in Analyze_Qualified_Expression The same statement is present a few lines above. gcc/ada/ * sem_ch4.adb (Analyze_Qualified_Expression): Remove redundant line. --- gcc/ada/sem_ch4.adb | 2 -- 1 file changed, 2 deletions(-) (limited to 'gcc/ada/sem_ch4.adb') diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index f136e9715d7..489fb47247a 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -4389,8 +4389,6 @@ package body Sem_Ch4 is end loop; end if; end if; - - Set_Etype (N, T); end Analyze_Qualified_Expression; ----------------------------------- -- cgit v1.2.1 From 270713d3f65243a089f4cdee04cd689422a95530 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 20 Oct 2022 11:05:16 +0200 Subject: ada: Minor consistency tweaks in Sem_Ch4 This ensures that, during the analysis of the qualified expressions, type conversions and unchecked type conversions, the determination of the type of the node and the analysis of its expression are done in the same order. No functional changes. gcc/ada/ * sem_ch4.adb (Analyze_Qualified_Expression): Analyze the expression only after setting the type. (Analyze_Unchecked_Type_Conversion): Likewise. (Analyze_Short_Circuit): Likewise for the operands. (Analyze_Type_Conversion): Minor tweaks. (Analyze_Unchecked_Expression): Likewise. --- gcc/ada/sem_ch4.adb | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'gcc/ada/sem_ch4.adb') diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 489fb47247a..0c02fd80675 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -4323,16 +4323,14 @@ package body Sem_Ch4 is ---------------------------------- procedure Analyze_Qualified_Expression (N : Node_Id) is - Mark : constant Entity_Id := Subtype_Mark (N); Expr : constant Node_Id := Expression (N); + Mark : constant Entity_Id := Subtype_Mark (N); + I : Interp_Index; It : Interp; T : Entity_Id; begin - Analyze_Expression (Expr); - - Set_Etype (N, Any_Type); Find_Type (Mark); T := Entity (Mark); @@ -4353,6 +4351,8 @@ package body Sem_Ch4 is Set_Etype (N, T); + Analyze_Expression (Expr); + if T = Any_Type then return; end if; @@ -5948,9 +5948,9 @@ package body Sem_Ch4 is It : Interp; begin + Set_Etype (N, Any_Type); Analyze_Expression (L); Analyze_Expression (R); - Set_Etype (N, Any_Type); if not Is_Overloaded (L) then if Root_Type (Etype (L)) = Standard_Boolean @@ -6083,7 +6083,9 @@ package body Sem_Ch4 is ----------------------------- procedure Analyze_Type_Conversion (N : Node_Id) is - Expr : constant Node_Id := Expression (N); + Expr : constant Node_Id := Expression (N); + Mark : constant Entity_Id := Subtype_Mark (N); + Typ : Entity_Id; begin @@ -6100,11 +6102,13 @@ package body Sem_Ch4 is -- Otherwise full type analysis is required, as well as some semantic -- checks to make sure the argument of the conversion is appropriate. - Find_Type (Subtype_Mark (N)); - Typ := Entity (Subtype_Mark (N)); + Find_Type (Mark); + Typ := Entity (Mark); Set_Etype (N, Typ); - Check_Fully_Declared (Typ, N); + Analyze_Expression (Expr); + + Check_Fully_Declared (Typ, N); Validate_Remote_Type_Type_Conversion (N); -- Only remaining step is validity checks on the argument. These @@ -6227,10 +6231,12 @@ package body Sem_Ch4 is ---------------------------------- procedure Analyze_Unchecked_Expression (N : Node_Id) is + Expr : constant Node_Id := Expression (N); + begin - Analyze (Expression (N), Suppress => All_Checks); - Set_Etype (N, Etype (Expression (N))); - Save_Interps (Expression (N), N); + Analyze (Expr, Suppress => All_Checks); + Set_Etype (N, Etype (Expr)); + Save_Interps (Expr, N); end Analyze_Unchecked_Expression; --------------------------------------- @@ -6238,10 +6244,13 @@ package body Sem_Ch4 is --------------------------------------- procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is + Expr : constant Node_Id := Expression (N); + Mark : constant Entity_Id := Subtype_Mark (N); + begin - Find_Type (Subtype_Mark (N)); - Analyze_Expression (Expression (N)); - Set_Etype (N, Entity (Subtype_Mark (N))); + Find_Type (Mark); + Set_Etype (N, Entity (Mark)); + Analyze_Expression (Expr); end Analyze_Unchecked_Type_Conversion; ------------------------------------ -- cgit v1.2.1 From 59ad8b684dd67e171141761f520c6a2ec70e5d6c Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 20 Oct 2022 20:41:08 +0200 Subject: ada: Implement RM 4.5.7(10/3) name resolution rule This rule deals with the specific case of a conditional expression that is the operand of a type conversion and effectively distributes the conversion to the dependent expressions with the help of the dynamic semantics. gcc/ada/ * sem_ch4.adb (Analyze_Case_Expression): Compute the interpretations of the expression only at the end of the analysis, but skip doing it if it is the operand of a type conversion. (Analyze_If_Expression): Likewise. * sem_res.adb (Resolve): Deal specially with conditional expression that is the operand of a type conversion. (Resolve_Dependent_Expression): New procedure. (Resolve_Case_Expression): Call Resolve_Dependent_Expression. (Resolve_If_Expression): Likewise. (Resolve_If_Expression.Apply_Check): Take result type as parameter. (Resolve_Type_Conversion): Do not warn about a redundant conversion when the operand is a conditional expression. --- gcc/ada/sem_ch4.adb | 129 +++++++++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 56 deletions(-) (limited to 'gcc/ada/sem_ch4.adb') diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 0c02fd80675..23040d7033b 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -1740,6 +1740,70 @@ package body Sem_Ch4 is return; end if; + -- 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 case 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 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); + return; + end if; + end if; + + -- RM 4.5.7(10/3): If the case_expression is the operand of a type + -- conversion, the type of the case_expression is the target type + -- of the conversion. + + if Nkind (Parent (N)) = N_Type_Conversion then + Set_Etype (N, Etype (Parent (N))); + return; + end if; + -- Loop through the interpretations of the first expression and check -- the other expressions if present. @@ -1763,25 +1827,6 @@ package body Sem_Ch4 is end loop; end if; - -- 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 no possible interpretation has been found, the type of the wrong -- alternative doesn't match any interpretation of the FIRST expression. @@ -1829,43 +1874,6 @@ package body Sem_Ch4 is Etype (Second_Expr)); end if; end if; - - 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; @@ -2555,6 +2563,15 @@ package body Sem_Ch4 is Analyze_Expression (Else_Expr); end if; + -- RM 4.5.7(10/3): If the if_expression is the operand of a type + -- conversion, the type of the if_expression is the target type + -- of the conversion. + + if Nkind (Parent (N)) = N_Type_Conversion then + Set_Etype (N, Etype (Parent (N))); + return; + end if; + -- Loop through the interpretations of the THEN expression and check the -- ELSE expression if present. -- cgit v1.2.1