[vala] codegen: Use append_array_size for local variable access
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use append_array_size for local variable access
- Date: Sat, 9 Oct 2010 17:07:46 +0000 (UTC)
commit fe0b6648c9a1bc92fae91ec180e17b64dcbc85f3
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 16:39:44 2010 +0200
codegen: Use append_array_size for local variable access
codegen/valaccodearraymodule.vala | 22 +---------------------
codegen/valaccodebasemodule.vala | 9 +++++++++
codegen/valaccodememberaccessmodule.vala | 10 ++++++++++
codegen/valagasyncmodule.vala | 4 ++++
4 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 47f3301..cc137ee 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -181,7 +181,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return size[dim - 1];
}
} else if (array_expr.symbol_reference != null) {
- if (array_expr.symbol_reference is FormalParameter) {
+ if (array_expr.symbol_reference is FormalParameter || array_expr.symbol_reference is LocalVariable) {
List<CCodeExpression> size = get_array_sizes (array_expr);
if (size != null && size.size >= dim) {
if (is_out) {
@@ -191,26 +191,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return size[dim - 1];
}
}
- } else if (array_expr.symbol_reference is LocalVariable) {
- var local = (LocalVariable) array_expr.symbol_reference;
- if (local.captured) {
- // captured variables are stored on the heap
- var block = (Block) local.parent_symbol;
- var length_expr = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (local.name), dim));
- if (is_out) {
- // passing array as out/ref
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
- } else {
- return length_expr;
- }
- } else {
- var length_expr = get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim));
- if (is_out) {
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
- } else {
- return length_expr;
- }
- }
} else if (array_expr.symbol_reference is Field) {
var field = (Field) array_expr.symbol_reference;
if (field.array_null_terminated) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 06ba5c7..344ec72 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -953,6 +953,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
@@ -1737,6 +1738,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
free_block.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), get_variable_cname (local.name)), local.variable_type, ma)));
if (old_coroutine) {
@@ -1848,6 +1850,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
}
@@ -1976,6 +1979,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
rhs = get_cvalue (local.initializer);
@@ -3026,6 +3030,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
expr_list.append_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
@@ -3104,6 +3109,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
@@ -3126,6 +3132,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
}
@@ -3163,6 +3170,8 @@ public class Vala.CCodeBaseModule : CodeGenerator {
if (!local.unreachable && local.active && !local.floating && !local.captured && requires_destroy (local.variable_type)) {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
+ ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
}
}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index a2c7646..fb8d085 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -355,8 +355,18 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
// captured variables are stored on the heap
var block = (Block) local.parent_symbol;
set_cvalue (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_variable_cname (local.name)));
+ if (array_type != null) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ append_array_size (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (local.name), dim)));
+ }
+ }
} else {
set_cvalue (expr, get_variable_cexpression (local.name));
+ if (array_type != null) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ append_array_size (expr, get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim)));
+ }
+ }
if (expr.parent_node is ReturnStatement &&
current_return_type.value_owned &&
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 798168a..1288ed2 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -114,6 +114,8 @@ public class Vala.GAsyncModule : GSignalModule {
var v = new LocalVariable (m.return_type, ".result");
var ma = new MemberAccess.simple (".result");
ma.symbol_reference = v;
+ ma.value_type = v.variable_type.copy ();
+ visit_member_access (ma);
var unref_expr = get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "result"), m.return_type, ma);
freeblock.add_statement (new CCodeExpressionStatement (unref_expr));
}
@@ -571,6 +573,8 @@ public class Vala.GAsyncModule : GSignalModule {
foreach (LocalVariable local in temp_ref_vars) {
var ma = new MemberAccess.simple (local.name);
ma.symbol_reference = local;
+ ma.value_type = local.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (new CCodeIdentifier (local.name), local.variable_type, ma));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]