[vala] Retain array length across casts
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Retain array length across casts
- Date: Wed, 29 Jul 2009 21:29:35 +0000 (UTC)
commit edcd069d6b0b7b9e1ff2797d45ccbafe910a1357
Author: Jürg Billeter <j bitron ch>
Date: Wed Jul 29 23:29:09 2009 +0200
Retain array length across casts
codegen/valaccodearraymodule.vala | 5 ++---
codegen/valaccodebasemodule.vala | 9 +++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index ceba7d6..fbc17a6 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -161,9 +161,8 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
Gee.List<Expression> size = ((ArrayCreationExpression) array_expr).get_sizes ();
var length_expr = size[dim - 1];
return (CCodeExpression) get_ccodenode (length_expr);
- } else if (array_expr is MethodCall) {
- var invocation_expr = (MethodCall) array_expr;
- Gee.List<CCodeExpression> size = invocation_expr.get_array_sizes ();
+ } else if (array_expr is MethodCall || array_expr is CastExpression) {
+ Gee.List<CCodeExpression> size = array_expr.get_array_sizes ();
return size[dim - 1];
} else if (array_expr.symbol_reference != null) {
if (array_expr.symbol_reference is FormalParameter) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ac5769d..756275e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3391,6 +3391,15 @@ internal class Vala.CCodeBaseModule : CCodeModule {
Report.error (expr.source_reference, "Operation not supported for this type");
return;
}
+
+ // retain array length
+ var array_type = expr.type_reference as ArrayType;
+ if (array_type != null) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ expr.append_array_size (get_array_length_cexpression (expr.inner, dim));
+ }
+ }
+
expr.ccodenode = new CCodeCastExpression ((CCodeExpression) expr.inner.ccodenode, expr.type_reference.get_cname ());
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]