diff mbox series

[Ada] Simplify routines with a local Result variable

Message ID 20180524130945.GA92252@adacore.com
State New
Headers show
Series [Ada] Simplify routines with a local Result variable | expand

Commit Message

Pierre-Marie de Rodat May 24, 2018, 1:09 p.m. UTC
Local variable Result that is modified inside IF statements makes a seemingly
trivial code slightly hard to understand. This patch rewrites such a pattern.

Semantics unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

2018-05-24  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_elab.adb (Non_Private_View): Simplify by removing a local Result
	variable.
	* sem_prag.adb (Get_Base_Subprogram): Same as above.
diff mbox series

Patch

--- gcc/ada/sem_elab.adb
+++ gcc/ada/sem_elab.adb
@@ -8077,16 +8077,12 @@  package body Sem_Elab is
    ----------------------
 
    function Non_Private_View (Typ : Entity_Id) return Entity_Id is
-      Result : Entity_Id;
-
    begin
-      Result := Typ;
-
-      if Is_Private_Type (Result) and then Present (Full_View (Result)) then
-         Result := Full_View (Result);
+      if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
+         return Full_View (Typ);
+      else
+         return Typ;
       end if;
-
-      return Result;
    end Non_Private_View;
 
    -----------------------------

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -29765,23 +29765,19 @@  package body Sem_Prag is
    -------------------------
 
    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
-      Result : Entity_Id;
-
    begin
       --  Follow subprogram renaming chain
 
-      Result := Def_Id;
-
-      if Is_Subprogram (Result)
+      if Is_Subprogram (Def_Id)
         and then
-          Nkind (Parent (Declaration_Node (Result))) =
+          Nkind (Parent (Declaration_Node (Def_Id))) =
                                          N_Subprogram_Renaming_Declaration
-        and then Present (Alias (Result))
+        and then Present (Alias (Def_Id))
       then
-         Result := Alias (Result);
+         return Alias (Def_Id);
+      else
+         return Def_Id;
       end if;
-
-      return Result;
    end Get_Base_Subprogram;
 
    -----------------------