]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[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 e6dc4199ae6f3323143eb4e76d86aa004585ab95..bb4c3b46b41fba536b1179728190f06202d8addd 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 24476194337a01eb03f9949aa42dc2953077319b..3ceb55d51dae62a4035516b5286fd1fa3f6122df 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 81f4d7c3b5af8f6910cfd2f396d05e3f3ca39be8..04a87fb4f9a96825229f01674664f92c547b76a1 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 1f21c3384c9739aba31d2bb7cd101d2ffa8e9c90..962941d6db2b1dca5916e11ec6209da99f73a21d 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 2ab273b3acf460ed6f4fb632a8da8182110c2b01..53b0ec994c914395f8f868cbf046b8d12e5c4319 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 915a7b48eca6dc745bb2c06e8f5954954a9f7a0b..c913e8b69d58412666f10f66dd9990993d5fffcd 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 5a57d62faae7947e430af4543e189d531a0b4a06..538f860089075117660268935bcbf35214806e0e 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 1d915ab0f28db5a44056ef57e69680ee0ee79a18..d0cbf3f740df1048c0452485b68002c880e4fcad 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))