From: Jürg Billeter Date: Sat, 9 Oct 2010 15:45:10 +0000 (+0200) Subject: codegen: Use append_array_size for null literals X-Git-Tag: 0.11.1~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9238d503ea1afff62434abbba70bdcb8f8e8f74d;p=thirdparty%2Fvala.git codegen: Use append_array_size for null literals --- diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index 96b9696b4..40c4e9b9d 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -175,23 +175,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { array_expr = reftransfer_expr.inner; } - if (array_expr is ArrayCreationExpression || array_expr is MethodCall || array_expr is CastExpression || array_expr is SliceExpression) { - List size = get_array_sizes (array_expr); - if (size != null && size.size >= dim) { + List size = get_array_sizes (array_expr); + if (size != null && size.size >= dim) { + if (is_out) { + // passing array as out/ref + return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]); + } else { return size[dim - 1]; } - } else if (array_expr.symbol_reference != null) { - List size = get_array_sizes (array_expr); - if (size != null && size.size >= dim) { - if (is_out) { - // passing array as out/ref - return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]); - } else { - return size[dim - 1]; - } - } - } else if (array_expr is NullLiteral) { - return new CCodeConstant ("0"); } if (!is_out) { diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 0c735e364..9e41f3136 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3545,6 +3545,13 @@ public class Vala.CCodeBaseModule : CodeGenerator { cfile.add_include ("stddef.h"); } set_cvalue (expr, new CCodeConstant ("NULL")); + + var array_type = expr.target_type as ArrayType; + if (array_type != null) { + for (int dim = 1; dim <= array_type.rank; dim++) { + append_array_size (expr, new CCodeConstant ("0")); + } + } } public virtual string get_delegate_target_cname (string delegate_cname) {