[Ada] Simplify analysis of assignment statements
authorPiotr Trojanek <trojanek@adacore.com>
Sun, 15 Nov 2020 00:21:41 +0000 (01:21 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 30 Nov 2020 14:16:21 +0000 (09:16 -0500)
gcc/ada/

* sem_ch5.adb (Set_Assignment_Type): Combine calls to Ekind
using membership test.
(Should_Transform_BIP_Assignment): Replace assignment to a
"Result" variable with simple return statements; avoid repeated
calls to Unqual_Conv by declaring a local constant.

gcc/ada/sem_ch5.adb

index df412bd4714280db2e9b53132aa5a76e0900b777..52150df5e69ee357afb94b406a528e161c9aef9a 100644 (file)
@@ -303,9 +303,9 @@ package body Sem_Ch5 is
          --  also have an actual subtype.
 
          if Is_Entity_Name (Opnd)
-           and then (Ekind (Entity (Opnd)) = E_Out_Parameter
-                      or else Ekind (Entity (Opnd)) in
-                                E_In_Out_Parameter | E_Generic_In_Out_Parameter
+           and then (Ekind (Entity (Opnd)) in E_Out_Parameter
+                                            | E_In_Out_Parameter
+                                            | E_Generic_In_Out_Parameter
                       or else
                         (Ekind (Entity (Opnd)) = E_Variable
                           and then Nkind (Parent (Entity (Opnd))) =
@@ -349,8 +349,6 @@ package body Sem_Ch5 is
       function Should_Transform_BIP_Assignment
         (Typ : Entity_Id) return Boolean
       is
-         Result : Boolean;
-
       begin
          if Expander_Active
            and then not Is_Limited_View (Typ)
@@ -364,37 +362,33 @@ package body Sem_Ch5 is
             --  parameterless function call if it denotes a function.
             --  Finally, an attribute reference can be a function call.
 
-            case Nkind (Unqual_Conv (Rhs)) is
-               when N_Function_Call
-                  | N_Op
-               =>
-                  Result := True;
-
-               when N_Expanded_Name
-                  | N_Identifier
-               =>
-                  case Ekind (Entity (Unqual_Conv (Rhs))) is
-                     when E_Function
-                        | E_Operator
-                     =>
-                        Result := True;
-
-                     when others =>
-                        Result := False;
-                  end case;
-
-               when N_Attribute_Reference =>
-                  Result := Attribute_Name (Unqual_Conv (Rhs)) = Name_Input;
+            declare
+               Unqual_Rhs : constant Node_Id := Unqual_Conv (Rhs);
+            begin
+               case Nkind (Unqual_Rhs) is
+                  when N_Function_Call
+                     | N_Op
+                  =>
+                     return True;
+
+                  when N_Expanded_Name
+                     | N_Identifier
+                  =>
+                     return
+                       Ekind (Entity (Unqual_Rhs)) in E_Function | E_Operator;
+
                   --  T'Input will turn into a call whose result type is T
 
-               when others =>
-                  Result := False;
-            end case;
+                  when N_Attribute_Reference =>
+                     return Attribute_Name (Unqual_Rhs) = Name_Input;
+
+                  when others =>
+                     return False;
+               end case;
+            end;
          else
-            Result := False;
+            return False;
          end if;
-
-         return Result;
       end Should_Transform_BIP_Assignment;
 
       ------------------------------