From d38761c9e4ea8ca573fff574b3b6e11aee107e0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sun, 30 Nov 2008 08:51:08 +0000 Subject: [PATCH] More parenthesis improvements MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2008-11-30 Jürg Billeter * ccode/valaccodeassignment.vala: * ccode/valaccodeconditionalexpression.vala: * gobject/valaccodearraymodule.vala: * gobject/valaccodeassignmentmodule.vala: * gobject/valaccodebasemodule.vala: * gobject/valaccodecontrolflowmodule.vala: * gobject/valaccodedelegatemodule.vala: * gobject/valaccodemethodcallmodule.vala: More parenthesis improvements svn path=/trunk/; revision=2092 --- ChangeLog | 13 +++++++++++++ ccode/valaccodeassignment.vala | 6 ++++++ ccode/valaccodeconditionalexpression.vala | 14 +++++++++----- gobject/valaccodearraymodule.vala | 14 +++++++------- gobject/valaccodeassignmentmodule.vala | 2 +- gobject/valaccodebasemodule.vala | 10 +++++----- gobject/valaccodecontrolflowmodule.vala | 4 ++-- gobject/valaccodedelegatemodule.vala | 2 +- gobject/valaccodemethodcallmodule.vala | 2 +- 9 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index cca6fd6b..50f285e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2008-11-30 Jürg Billeter + * ccode/valaccodeassignment.vala: + * ccode/valaccodeconditionalexpression.vala: + * gobject/valaccodearraymodule.vala: + * gobject/valaccodeassignmentmodule.vala: + * gobject/valaccodebasemodule.vala: + * gobject/valaccodecontrolflowmodule.vala: + * gobject/valaccodedelegatemodule.vala: + * gobject/valaccodemethodcallmodule.vala: + + More parenthesis improvements + +2008-11-30 Jürg Billeter + * vala/valaforeachstatement.vala: * ccode/valaccodebinaryexpression.vala: * ccode/valaccodecastexpression.vala: diff --git a/ccode/valaccodeassignment.vala b/ccode/valaccodeassignment.vala index 009b9305..37b48f33 100644 --- a/ccode/valaccodeassignment.vala +++ b/ccode/valaccodeassignment.vala @@ -78,6 +78,12 @@ public class Vala.CCodeAssignment : CCodeExpression { right.write (writer); } + + public override void write_inner (CCodeWriter writer) { + writer.write_string ("("); + this.write (writer); + writer.write_string (")"); + } } public enum Vala.CCodeAssignmentOperator { diff --git a/ccode/valaccodeconditionalexpression.vala b/ccode/valaccodeconditionalexpression.vala index 213ffe02..b894928d 100644 --- a/ccode/valaccodeconditionalexpression.vala +++ b/ccode/valaccodeconditionalexpression.vala @@ -1,6 +1,6 @@ /* valaccodeconditionalexpression.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2008 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,12 +48,16 @@ public class Vala.CCodeConditionalExpression : CCodeExpression { } public override void write (CCodeWriter writer) { - writer.write_string ("("); - condition.write (writer); + condition.write_inner (writer); writer.write_string (" ? "); - true_expression.write (writer); + true_expression.write_inner (writer); writer.write_string (" : "); - false_expression.write (writer); + false_expression.write_inner (writer); + } + + public override void write_inner (CCodeWriter writer) { + writer.write_string ("("); + this.write (writer); writer.write_string (")"); } } diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala index e726cd97..9f8edb7f 100644 --- a/gobject/valaccodearraymodule.vala +++ b/gobject/valaccodearraymodule.vala @@ -53,7 +53,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { temp_vars.insert (0, temp_var); - csize = new CCodeParenthesizedExpression (new CCodeAssignment (name_cnode, csize)); + csize = new CCodeAssignment (name_cnode, csize); } if (first) { @@ -147,7 +147,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { CCodeExpression length_expr = new CCodeIdentifier (get_array_length_cname (param.name, dim)); if (param.direction != ParameterDirection.IN) { // accessing argument of out/ref param - length_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, length_expr)); + length_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, length_expr); } if (is_out) { // passing array as out/ref @@ -283,8 +283,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { } else { // access to element in an array for (int i = 1; i < rank; i++) { - var cmul = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (cindex), head.get_array_length_cexpression (expr.container, i + 1)); - cindex = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cmul, new CCodeParenthesizedExpression ((CCodeExpression) indices[i].ccodenode)); + var cmul = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cindex, head.get_array_length_cexpression (expr.container, i + 1)); + cindex = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cmul, (CCodeExpression) indices[i].ccodenode); } expr.ccodenode = new CCodeElementAccess (ccontainer, cindex); } @@ -368,7 +368,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { var dest = new CCodeIdentifier ("dest"); var src_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, src, element_size)); var dest_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, dest, element_size)); - var dest_end_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, dest, length)), element_size)); + var dest_end_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, dest, length), element_size)); fun.block = new CCodeBlock (); @@ -381,14 +381,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { var czero1 = new CCodeFunctionCall (new CCodeIdentifier ("memset")); czero1.add_argument (src_address); czero1.add_argument (new CCodeConstant ("0")); - czero1.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, dest, src)), element_size)); + czero1.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, dest, src), element_size)); var czeroblock1 = new CCodeBlock (); czeroblock1.add_statement (new CCodeExpressionStatement (czero1)); var czero2 = new CCodeFunctionCall (new CCodeIdentifier ("memset")); czero2.add_argument (dest_end_address); czero2.add_argument (new CCodeConstant ("0")); - czero2.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, src, dest)), element_size)); + czero2.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, src, dest), element_size)); var czeroblock2 = new CCodeBlock (); czeroblock2.add_statement (new CCodeExpressionStatement (czero2)); diff --git a/gobject/valaccodeassignmentmodule.vala b/gobject/valaccodeassignmentmodule.vala index 91395801..2e6d947b 100644 --- a/gobject/valaccodeassignmentmodule.vala +++ b/gobject/valaccodeassignmentmodule.vala @@ -73,7 +73,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { } else { assert_not_reached (); } - cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), new CCodeParenthesizedExpression (cexpr)); + cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr); } var ccall = get_property_set_call (prop, ma, cexpr); diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index 5c398296..a1958fb9 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -231,7 +231,7 @@ public class Vala.CCodeBaseModule : CCodeModule { source_type_member_declaration.append (fun.copy ()); // (str1 != str2) - var cineq = new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("str1"), new CCodeIdentifier ("str2"))); + var cineq = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("str1"), new CCodeIdentifier ("str2")); fun.block = new CCodeBlock (); @@ -1721,10 +1721,10 @@ public class Vala.CCodeBaseModule : CCodeModule { bool uses_gfree = (type.data_type != null && !type.data_type.is_reference_counting () && type.data_type.get_free_function () == "g_free"); uses_gfree = uses_gfree || type is ArrayType; if (uses_gfree) { - return new CCodeParenthesizedExpression (cassign); + return cassign; } - return new CCodeConditionalExpression (cisnull, new CCodeConstant ("NULL"), new CCodeParenthesizedExpression (cassign)); + return new CCodeConditionalExpression (cisnull, new CCodeConstant ("NULL"), cassign); } public override void visit_end_full_expression (Expression expr) { @@ -2782,7 +2782,7 @@ public class Vala.CCodeBaseModule : CCodeModule { } else if (expr.operator == BinaryOperator.OR) { op = CCodeBinaryOperator.OR; } else if (expr.operator == BinaryOperator.IN) { - expr.ccodenode = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.BITWISE_AND, new CCodeParenthesizedExpression (cright), new CCodeParenthesizedExpression (cleft))), new CCodeParenthesizedExpression (cleft)); + expr.ccodenode = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeBinaryExpression (CCodeBinaryOperator.BITWISE_AND, cright, cleft), cleft); return; } else { assert_not_reached (); @@ -2986,7 +2986,7 @@ public class Vala.CCodeBaseModule : CCodeModule { var decl = get_temp_variable (expression_type, true, expression_type); temp_vars.insert (0, decl); temp_ref_vars.insert (0, decl); - cexpr = new CCodeParenthesizedExpression (new CCodeAssignment (new CCodeIdentifier (get_variable_cname (decl.name)), cexpr)); + cexpr = new CCodeAssignment (new CCodeIdentifier (get_variable_cname (decl.name)), cexpr); if (expression_type is ArrayType && expr != null) { var array_type = (ArrayType) expression_type; diff --git a/gobject/valaccodecontrolflowmodule.vala b/gobject/valaccodecontrolflowmodule.vala index e1b4bafe..bad51c28 100644 --- a/gobject/valaccodecontrolflowmodule.vala +++ b/gobject/valaccodecontrolflowmodule.vala @@ -113,7 +113,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule { var cname = new CCodeIdentifier ("%s_label%d".printf (temp_var.name, label_count++)); var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, czero, cname); var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string")); - var cinit = new CCodeParenthesizedExpression (new CCodeAssignment (cname, ccall)); + var cinit = new CCodeAssignment (cname, ccall); ccall.add_argument (cexpr); @@ -391,7 +391,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule { var ccond_term2 = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeElementAccess (new CCodeIdentifier (collection_backup.name), new CCodeIdentifier (it_name)), new CCodeConstant ("NULL")); var ccond_term = new CCodeBinaryExpression (CCodeBinaryOperator.AND, ccond_term1, ccond_term2); - ccond = new CCodeBinaryExpression (CCodeBinaryOperator.OR, new CCodeParenthesizedExpression (ccond_ind), new CCodeParenthesizedExpression (ccond_term)); + ccond = new CCodeBinaryExpression (CCodeBinaryOperator.OR, ccond_ind, ccond_term); } else { /* assert when trying to iterate over value-type arrays of unknown length */ var cassert = new CCodeFunctionCall (new CCodeIdentifier ("g_assert")); diff --git a/gobject/valaccodedelegatemodule.vala b/gobject/valaccodedelegatemodule.vala index c105cb7a..22beb360 100644 --- a/gobject/valaccodedelegatemodule.vala +++ b/gobject/valaccodedelegatemodule.vala @@ -97,7 +97,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (param.name)); if (param.direction != ParameterDirection.IN) { // accessing argument of out/ref param - target_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr)); + target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr); } if (is_out) { // passing array as out/ref diff --git a/gobject/valaccodemethodcallmodule.vala b/gobject/valaccodemethodcallmodule.vala index 56194771..6753a7c1 100644 --- a/gobject/valaccodemethodcallmodule.vala +++ b/gobject/valaccodemethodcallmodule.vala @@ -447,7 +447,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { var celems = (CCodeExpression) ma.inner.ccodenode; var array_type = (ArrayType) ma.inner.value_type; var csizeof = new CCodeIdentifier ("sizeof (%s)".printf (array_type.element_type.get_cname ())); - var cdelta = new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, temp_ref, clen)); + var cdelta = new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, temp_ref, clen); var ccheck = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, temp_ref, clen); var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset")); -- 2.11.4.GIT