aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Taft <taft@adacore.com>2024-12-05 14:47:37 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-03 16:39:14 +0100
commitc3c701a5e905aa638605f5bedc6b37dbc5bc2ecf (patch)
tree37446dc29f1e181959700801455047e8eb0afadd
parent98e37c6ca5a0b3dd2729dcf3e79df40edb020f52 (diff)
downloadgcc-c3c701a5e905aa638605f5bedc6b37dbc5bc2ecf.zip
gcc-c3c701a5e905aa638605f5bedc6b37dbc5bc2ecf.tar.gz
gcc-c3c701a5e905aa638605f5bedc6b37dbc5bc2ecf.tar.bz2
ada: Fix comments and change subtype name in response to review
gcc/ada/ChangeLog: * pprint.adb (Expression_Image): Adjust and improve comments to match style recommendations, and change name of subtype from Not_Associative to Non_Associative, in response to code review.
-rw-r--r--gcc/ada/pprint.adb27
1 files changed, 17 insertions, 10 deletions
diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb
index 5958a6b4..8061d3d 100644
--- a/gcc/ada/pprint.adb
+++ b/gcc/ada/pprint.adb
@@ -64,9 +64,9 @@ package body Pprint is
-- otherwise only consider the right-hand side of an expression. If
-- Expand_Type is True and Expr is a type, try to expand Expr (an
-- internally generated type) into a user understandable name.
- -- If No_Parens is True, then suppress creating parentheses
- -- around expression. If False, check to see whether expression
- -- should be parenthesized.
+ -- If No_Parens is True, then suppress creating parentheses around
+ -- expression. If False, check to see whether expression should be
+ -- parenthesized.
function Count_Parentheses (S : String; C : Character) return Natural
with Pre => C in '(' | ')';
@@ -153,8 +153,8 @@ package body Pprint is
-- Print expression itself as "12345"
else
+ -- Suppress parens if is the only parameter
Append (Buf, Expr_Name (Elmt, No_Parens => List_Len = 1));
- -- Suppress parens if is the only parameter.
end if;
Next (Elmt);
@@ -189,24 +189,31 @@ package body Pprint is
Expand_Type : Boolean := True;
No_Parens : Boolean := False) return String
is
- -- Define subtype matching logical operations
+ -- Define a subtype matching logical operations
-- and [then], or [else], and xor.
- subtype Not_Associative is N_Subexpr
+ -- In Ada, these operations are non associative -- they
+ -- all have the same precedence, so parentheses
+ -- are needed to indicate the association of
+ -- operands in a sequence of distinct operations.
+ subtype Non_Associative is N_Subexpr
with Static_Predicate =>
- Not_Associative in
+ Non_Associative in
N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor;
begin
if not No_Parens
and then
(Paren_Count (Expr) > 0
or else
- (Nkind (Expr) in Not_Associative
+ (Nkind (Expr) in Non_Associative
and then
- Nkind (Parent (Expr)) in Not_Associative
+ Nkind (Parent (Expr)) in Non_Associative
and then
Nkind (Parent (Expr)) /= Nkind (Expr)))
then
- -- Parentheses are needed
+ -- Parentheses are needed, either because
+ -- Paren_Count is greater than zero, or because
+ -- this operation and its parent are non associative,
+ -- and are not the same operation.
return '(' &
Expr_Name (Expr, Take_Prefix, Expand_Type, No_Parens => True) &
')';