Commit d38761c9 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

More parenthesis improvements

2008-11-30  Jürg Billeter  <j@bitron.ch>

	* 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
parent 1c44feaa
2008-11-30 Jürg Billeter <j@bitron.ch>
* 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 <j@bitron.ch>
* vala/valaforeachstatement.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 {
......
/* 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 (")");
}
}
......@@ -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));
......
......@@ -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);
......
......@@ -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;
......
......@@ -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"));
......
......@@ -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
......
......@@ -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"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment