aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2022-09-02 13:32:27 +0200
committerMarc Poulhiès <poulhies@adacore.com>2022-11-07 09:36:30 +0100
commitc7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1 (patch)
treeaebfb75b143909f01f1542cca47b6a6c1665a741 /gcc
parent03b4e4ae3b0d647a44c3dac09e27ab4151a84e85 (diff)
downloadgcc-c7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1.zip
gcc-c7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1.tar.gz
gcc-c7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1.tar.bz2
ada: Create operator nodes in functional style
A recent patch removed two rewritings, where we kept the operator node but replaced its operands. This patch removes explicit setting of the operands; instead, the operator is already created together with its operands, which seems a bit safer and more consistent with how we typically create operator nodes. It is a cleanup only; semantics is unaffected. gcc/ada/ * exp_ch4.adb (Expand_Modular_Addition): Rewrite using Make_XXX calls. (Expand_Modular_Op): Likewise. (Expand_Modular_Subtraction): Likewise. * exp_imgv.adb (Expand_User_Defined_Enumeration_Image): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch4.adb122
-rw-r--r--gcc/ada/exp_imgv.adb24
2 files changed, 76 insertions, 70 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index bbbcf4f..b9433c3 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4154,39 +4154,42 @@ package body Exp_Ch4 is
Mod_Minus_Right : constant Uint :=
Modulus (Typ) - Intval (Right_Opnd (N));
- Exprs : constant List_Id := New_List;
- Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc);
- Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
- Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract,
- Loc);
+ Cond_Expr : Node_Id;
+ Then_Expr : Node_Id;
+ Else_Expr : Node_Id;
begin
-- To prevent spurious visibility issues, convert all
-- operands to Standard.Unsigned.
- Set_Left_Opnd (Cond_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Cond_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Cond_Expr);
-
- Set_Left_Opnd (Then_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Then_Expr,
- Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
- Append_To (Exprs, Then_Expr);
-
- Set_Left_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Else_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Else_Expr);
+ Cond_Expr :=
+ Make_Op_Lt (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
+
+ Then_Expr :=
+ Make_Op_Add (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
+
+ Else_Expr :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
Rewrite (N,
Unchecked_Convert_To (Typ,
- Make_If_Expression (Loc, Expressions => Exprs)));
+ Make_If_Expression (Loc,
+ Expressions =>
+ New_List (Cond_Expr, Then_Expr, Else_Expr))));
end;
end if;
end Expand_Modular_Addition;
@@ -4202,7 +4205,7 @@ package body Exp_Ch4 is
-- backend does not have to deal with nonbinary-modulus ops.
Op_Expr : constant Node_Id := New_Op_Node (Nkind (N), Loc);
- Mod_Expr : constant Node_Id := New_Op_Node (N_Op_Mod, Loc);
+ Mod_Expr : Node_Id;
Target_Type : Entity_Id;
begin
@@ -4297,10 +4300,10 @@ package body Exp_Ch4 is
Force_Evaluation (Op_Expr, Mode => Strict);
end if;
- Set_Left_Opnd (Mod_Expr, Op_Expr);
-
- Set_Right_Opnd (Mod_Expr,
- Make_Integer_Literal (Loc, Modulus (Typ)));
+ Mod_Expr :=
+ Make_Op_Mod (Loc,
+ Left_Opnd => Op_Expr,
+ Right_Opnd => Make_Integer_Literal (Loc, Modulus (Typ)));
Rewrite (N,
Unchecked_Convert_To (Typ, Mod_Expr));
@@ -4331,37 +4334,40 @@ package body Exp_Ch4 is
Mod_Minus_Right : constant Uint :=
Modulus (Typ) - Intval (Right_Opnd (N));
- Exprs : constant List_Id := New_List;
- Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc);
- Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
- Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract,
- Loc);
+ Cond_Expr : Node_Id;
+ Then_Expr : Node_Id;
+ Else_Expr : Node_Id;
begin
- Set_Left_Opnd (Cond_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Cond_Expr,
- Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
- Append_To (Exprs, Cond_Expr);
-
- Set_Left_Opnd (Then_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Then_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Then_Expr);
-
- Set_Left_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Right_Opnd (N))));
- Append_To (Exprs, Else_Expr);
+ Cond_Expr :=
+ Make_Op_Lt (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
+
+ Then_Expr :=
+ Make_Op_Add (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
+
+ Else_Expr :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Right_Opnd (N))));
Rewrite (N,
Unchecked_Convert_To (Typ,
- Make_If_Expression (Loc, Expressions => Exprs)));
+ Make_If_Expression (Loc,
+ Expressions =>
+ New_List (Cond_Expr, Then_Expr, Else_Expr))));
end;
end if;
end Expand_Modular_Subtraction;
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index 51f1195..f2043f5 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -938,12 +938,12 @@ package body Exp_Imgv is
-- P3 : constant Natural := call_put_enumN (P1 + 1);
declare
- Add_Node : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
+ Add_Node : constant Node_Id :=
+ Make_Op_Add (Loc,
+ Left_Opnd => New_Occurrence_Of (P1_Id, Loc),
+ Right_Opnd => Make_Integer_Literal (Loc, Uint_1));
begin
- Set_Left_Opnd (Add_Node, New_Occurrence_Of (P1_Id, Loc));
- Set_Right_Opnd (Add_Node, Make_Integer_Literal (Loc, 1));
-
Append_To (Ins_List,
Make_Object_Declaration (Loc,
Defining_Identifier => P3_Id,
@@ -963,12 +963,12 @@ package body Exp_Imgv is
-- P4 : String renames call_put_enumS (P2 .. P3 - 1);
declare
- Sub_Node : constant Node_Id := New_Op_Node (N_Op_Subtract, Loc);
+ Sub_Node : constant Node_Id :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd => New_Occurrence_Of (P3_Id, Loc),
+ Right_Opnd => Make_Integer_Literal (Loc, Uint_1));
begin
- Set_Left_Opnd (Sub_Node, New_Occurrence_Of (P3_Id, Loc));
- Set_Right_Opnd (Sub_Node, Make_Integer_Literal (Loc, 1));
-
Append_To (Ins_List,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => P4_Id,
@@ -988,12 +988,12 @@ package body Exp_Imgv is
-- subtype S1 is String (1 .. P3 - P2);
declare
- HB : constant Node_Id := New_Op_Node (N_Op_Subtract, Loc);
+ HB : constant Node_Id :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd => New_Occurrence_Of (P3_Id, Loc),
+ Right_Opnd => New_Occurrence_Of (P2_Id, Loc));
begin
- Set_Left_Opnd (HB, New_Occurrence_Of (P3_Id, Loc));
- Set_Right_Opnd (HB, New_Occurrence_Of (P2_Id, Loc));
-
Append_To (Ins_List,
Make_Subtype_Declaration (Loc,
Defining_Identifier => S1_Id,