public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Reuse Is_Rewrite_Substitution where possible
@ 2022-05-10  8:21 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2022-05-10  8:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 466 bytes --]

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.

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

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 5309 bytes --]

diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb
--- a/gcc/ada/atree.adb
+++ b/gcc/ada/atree.adb
@@ -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);


diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -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
 


diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -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;


diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -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;
 


diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -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 :=


diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -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


diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -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);


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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))



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Ada] Reuse Is_Rewrite_Substitution where possible
@ 2018-05-30  8:59 Pierre-Marie de Rodat
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Marie de Rodat @ 2018-05-30  8:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Use a high-level Is_Rewrite_Substitution instead of a low-level inequality,
with the intention to improve the code easier to read. Semantics unaffected,
so no test provided.

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

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

gcc/ada/

	* errout.adb, exp_aggr.adb, exp_ch7.adb, exp_util.adb, lib.adb,
	sem_ch13.adb, sem_ch4.adb, sem_res.adb, sem_util.adb
	(Has_Original_Node): Refactor to use Is_Rewrite_Substitution.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 3849 bytes --]

--- gcc/ada/errout.adb
+++ gcc/ada/errout.adb
@@ -2387,7 +2387,7 @@ package body Errout is
          end loop;
 
          if Nkind (N) = N_Raise_Constraint_Error
-           and then Original_Node (N) /= N
+           and then Is_Rewrite_Substitution (N)
            and then No (Condition (N))
          then
             --  Warnings may have been posted on subexpressions of the original

--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -6089,7 +6089,7 @@ package body Exp_Aggr is
       --  that Convert_To_Positional succeeded and reanalyzed the rewritten
       --  aggregate.
 
-      elsif Analyzed (N) and then N /= Original_Node (N) then
+      elsif Analyzed (N) and then Is_Rewrite_Substitution (N) then
          return;
       end if;
 

--- gcc/ada/exp_ch7.adb
+++ gcc/ada/exp_ch7.adb
@@ -5255,7 +5255,7 @@ package body Exp_Ch7 is
             --  node. Inspect the original node to detect the initial placement
             --  of the call.
 
-            elsif Original_Node (N) /= N then
+            elsif Is_Rewrite_Substitution (N) then
                Detect_Subprogram_Call (Original_Node (N));
 
                if Must_Hook then

--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -4826,7 +4826,7 @@ package body Exp_Util is
                while Present (E) loop
                   Force_Evaluation (E);
 
-                  if Original_Node (E) /= E then
+                  if Is_Rewrite_Substitution (E) then
                      Set_Do_Range_Check
                        (E, Do_Range_Check (Original_Node (E)));
                   end if;

--- gcc/ada/lib.adb
+++ gcc/ada/lib.adb
@@ -1326,7 +1326,7 @@ package body Lib is
       Write_Str ("=");
       Write_Str (Node_Kind'Image (Nkind (Item)));
 
-      if Item /= Original_Node (Item) then
+      if Is_Rewrite_Substitution (Item) then
          Write_Str (", orig = ");
          Write_Int (Int (Original_Node (Item)));
          Write_Str ("=");

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -9643,7 +9643,7 @@ package body Sem_Ch13 is
                --  from the node, since we may have rewritten things and
                --  substituted an identifier representing the rewrite.
 
-               if Original_Node (Nod) /= Nod then
+               if Is_Rewrite_Substitution (Nod) then
                   Check_Expr_Constants (Original_Node (Nod));
 
                   --  If the node is an object declaration without initial

--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -1345,7 +1345,7 @@ package body Sem_Ch4 is
             --  parameter has been analyzed, but may need a subsequent
             --  dereference, so skip its analysis now.
 
-            if N /= Original_Node (N)
+            if Is_Rewrite_Substitution (N)
               and then Nkind (Original_Node (N)) = Nkind (N)
               and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
               and then Present (Parameter_Associations (N))

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -12691,7 +12691,7 @@ package body Sem_Res is
 
             if Ada_Version >= Ada_2012
               and then not Comes_From_Source (N)
-              and then N /= Original_Node (N)
+              and then Is_Rewrite_Substitution (N)
               and then Ekind (Target_Type) = E_General_Access_Type
               and then Ekind (Opnd_Type) = E_Anonymous_Access_Type
             then

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -15855,7 +15855,7 @@ package body Sem_Util is
       --  original node is a conversion, then Is_Variable will not be true
       --  but we still want to allow the conversion if it converts a variable).
 
-      elsif Original_Node (AV) /= AV then
+      elsif Is_Rewrite_Substitution (AV) then
 
          --  In Ada 2012, the explicit dereference may be a rewritten call to a
          --  Reference function.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-10  8:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:21 [Ada] Reuse Is_Rewrite_Substitution where possible Pierre-Marie de Rodat
  -- strict thread matches above, loose matches on Subject: below --
2018-05-30  8:59 Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).