2008-03-01 Jürg Billeter <j@bitron.ch>
+ * ccode/valaccodecommaexpression.vala,
+ ccode/valaccodeexpressionstatement.vala: improve C code output
+
+2008-03-01 Jürg Billeter <j@bitron.ch>
+
* gobject/valaccodegeneratorinvocationexpression.vala: fix argument
dependency in the C code for array and delegate arguments,
fixes bug 519597
/* valaccodecommaexpression.vala
*
- * Copyright (C) 2006-2007 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
public void append_expression (CCodeExpression! expr) {
inner.add (expr);
}
-
+
+ public Collection<CCodeExpression> get_inner () {
+ return new ReadOnlyCollection<CCodeExpression> (inner);
+ }
+
public override void write (CCodeWriter! writer) {
bool first = true;
/* valaccodeexpressionstatement.vala
*
- * Copyright (C) 2006-2007 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
}
public override void write (CCodeWriter! writer) {
+ if (expression is CCodeCommaExpression) {
+ // expand comma expression into multiple statements
+ // to improve code readability
+ var ccomma = expression as CCodeCommaExpression;
+
+ foreach (CCodeExpression expr in ccomma.get_inner ()) {
+ write_expression (writer, expr);
+ }
+ } else if (expression is CCodeParenthesizedExpression) {
+ var cpar = expression as CCodeParenthesizedExpression;
+
+ write_expression (writer, cpar.inner);
+ } else {
+ write_expression (writer, expression);
+ }
+ }
+
+ private void write_expression (CCodeWriter writer, CCodeExpression? expr) {
writer.write_indent (line);
- if (expression != null) {
- expression.write (writer);
+ if (expr != null) {
+ expr.write (writer);
}
writer.write_string (";");
writer.write_newline ();