[Ada] Reuse Is_Rewrite_Substitution where possible
authorPiotr Trojanek <trojanek@adacore.com>
Sat, 22 Jan 2022 18:38:10 +0000 (19:38 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 10 May 2022 08:19:28 +0000 (08:19 +0000)
Replace comparisons of Original_Node with semantically equivalent but
high-level calls to Is_Rewrite_Substitution. Offending occurrences found
with:

  $ grep -n "Original_Node (\([A-Za-z_]\+\)) /\?= \1" *.adb

Code cleanup only; semantics is unaffected.

gcc/ada/

* atree.adb, exp_ch6.adb, exp_ch9.adb, ghost.adb, sem_ch3.adb,
sem_ch4.adb, sem_res.adb, sem_util.adb: Use
Is_Rewrite_Substitution where possible.

gcc/ada/atree.adb
gcc/ada/exp_ch6.adb
gcc/ada/exp_ch9.adb
gcc/ada/ghost.adb
gcc/ada/sem_ch3.adb
gcc/ada/sem_ch4.adb
gcc/ada/sem_res.adb
gcc/ada/sem_util.adb

index e6dc419..bb4c3b4 100644 (file)
@@ -2146,7 +2146,7 @@ package body Atree is
       --  not already rewritten the node, as indicated by an Orig_Nodes entry
       --  that does not reference the Old_Node.
 
-      if Original_Node (Old_Node) = Old_Node then
+      if not Is_Rewrite_Substitution (Old_Node) then
          Sav_Node := New_Copy (Old_Node);
          Set_Original_Node (Sav_Node, Sav_Node);
          Set_Original_Node (Old_Node, Sav_Node);
index 2447619..3ceb55d 100644 (file)
@@ -3932,7 +3932,7 @@ package body Exp_Ch6 is
             --  First verify the actual is internal
 
             elsif not Comes_From_Source (Prev)
-              and then Original_Node (Prev) = Prev
+              and then not Is_Rewrite_Substitution (Prev)
 
               --  Next check that the actual is a constant
 
index 81f4d7c..04a87fb 100644 (file)
@@ -6338,7 +6338,7 @@ package body Exp_Ch9 is
 
             when N_Expression_With_Actions =>
                --  this may occur in the case of a Count attribute reference
-               if Original_Node (N) /= N
+               if Is_Rewrite_Substitution (N)
                  and then Is_Pure_Barrier (Original_Node (N)) /= Abandon
                then
                   return Skip;
index 1f21c33..962941d 100644 (file)
@@ -1079,7 +1079,7 @@ package body Ghost is
       function Ultimate_Original_Node (Nod : Node_Id) return Node_Id is
          Res : Node_Id := Nod;
       begin
-         while Original_Node (Res) /= Res loop
+         while Is_Rewrite_Substitution (Res) loop
             Res := Original_Node (Res);
          end loop;
 
index 2ab273b..53b0ec9 100644 (file)
@@ -20185,20 +20185,14 @@ package body Sem_Ch3 is
          =>
             return not Comes_From_Source (Exp)
               and then
-                --  If the conversion has been rewritten, check Original_Node
+                --  If the conversion has been rewritten, check Original_Node;
+                --  otherwise, check the expression of the compiler-generated
+                --  conversion (which is a conversion that we want to ignore
+                --  for purposes of the limited-initialization restrictions).
 
-                ((Original_Node (Exp) /= Exp
-                   and then
-                     OK_For_Limited_Init_In_05 (Typ, Original_Node (Exp)))
-
-                  --  Otherwise, check the expression of the compiler-generated
-                  --  conversion (which is a conversion that we want to ignore
-                  --  for purposes of the limited-initialization restrictions).
-
-                  or else
-                    (Original_Node (Exp) = Exp
-                      and then
-                        OK_For_Limited_Init_In_05 (Typ, Expression (Exp))));
+                (if Is_Rewrite_Substitution (Exp)
+                 then OK_For_Limited_Init_In_05 (Typ, Original_Node (Exp))
+                 else OK_For_Limited_Init_In_05 (Typ, Expression (Exp)));
 
          when N_Explicit_Dereference
             | N_Indexed_Component
@@ -20547,7 +20541,7 @@ package body Sem_Ch3 is
             --  its Original_Node points to the old Discr and the access type
             --  for Discr_Type has already been created.
 
-            if Original_Node (Discr) /= Discr then
+            if Is_Rewrite_Substitution (Discr) then
                Discr_Type := Etype (Discriminant_Type (Discr));
             else
                Discr_Type :=
index 915a7b4..c913e8b 100644 (file)
@@ -772,7 +772,7 @@ package body Sem_Ch4 is
                --  type.
 
                else
-                  if Original_Node (N) /= N
+                  if Is_Rewrite_Substitution (N)
                     and then Nkind (Original_Node (N)) = N_Allocator
                   then
                      declare
index 5a57d62..538f860 100644 (file)
@@ -2472,7 +2472,7 @@ package body Sem_Res is
       --  Declare_Expression and requires scope management.
 
       if Nkind (N) = N_Expression_With_Actions then
-         if Comes_From_Source (N) and then N = Original_Node (N) then
+         if Comes_From_Source (N) and then not Is_Rewrite_Substitution (N) then
             Resolve_Declare_Expression (N, Typ);
          else
             Resolve (Expression (N), Typ);
index 1d915ab..d0cbf3f 100644 (file)
@@ -10435,7 +10435,7 @@ package body Sem_Util is
          Discrim_Value_Status := Static_Expr;
       else
          if Ada_Version >= Ada_2022 then
-            if Original_Node (Discrim_Value) /= Discrim_Value
+            if Is_Rewrite_Substitution (Discrim_Value)
                and then Nkind (Discrim_Value) = N_Type_Conversion
                and then Etype (Original_Node (Discrim_Value))
                       = Etype (Expression (Discrim_Value))