[Ada] Refactor repeated call to Next when pretty-printing if-expressions
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 8 Jan 2021 12:07:30 +0000 (13:07 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 5 May 2021 08:18:57 +0000 (04:18 -0400)
gcc/ada/

* pprint.adb (Expr_Name): Introduce local constants to make the
code more readable and avoid repeated calls to Next to reach the
ELSE part of an if-expression.

gcc/ada/pprint.adb

index 161b62a..e3e26e8 100644 (file)
@@ -410,12 +410,14 @@ package body Pprint is
 
             when N_If_Expression =>
                declare
-                  N : constant Node_Id := First (Expressions (Expr));
+                  Cond_Expr : constant Node_Id := First (Expressions (Expr));
+                  Then_Expr : constant Node_Id := Next (Cond_Expr);
+                  Else_Expr : constant Node_Id := Next (Then_Expr);
                begin
                   return
-                    "if " & Expr_Name (N) & " then "
-                      & Expr_Name (Next (N)) & " else "
-                      & Expr_Name (Next (Next (N)));
+                    "if " & Expr_Name (Cond_Expr) & " then "
+                      & Expr_Name (Then_Expr) & " else "
+                      & Expr_Name (Else_Expr);
                end;
 
             when N_Qualified_Expression =>