[vala] codegen: Use append_array_size for null literals
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use append_array_size for null literals
- Date: Sat, 9 Oct 2010 17:08:02 +0000 (UTC)
commit 9238d503ea1afff62434abbba70bdcb8f8e8f74d
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 17:45:10 2010 +0200
codegen: Use append_array_size for null literals
codegen/valaccodearraymodule.vala | 21 ++++++---------------
codegen/valaccodebasemodule.vala | 7 +++++++
2 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 96b9696..40c4e9b 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<CCodeExpression> size = get_array_sizes (array_expr);
- if (size != null && size.size >= dim) {
+ List<CCodeExpression> 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<CCodeExpression> 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 0c735e3..9e41f31 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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]