[vala] codegen: Add get_array_size_cvalue and set_array_size_cvalue
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Add get_array_size_cvalue and set_array_size_cvalue
- Date: Thu, 28 Oct 2010 10:35:40 +0000 (UTC)
commit 19921c10220a238a3e8d67971da4bdcaac91ffc7
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 21 16:39:45 2010 +0200
codegen: Add get_array_size_cvalue and set_array_size_cvalue
codegen/valaccodearraymodule.vala | 48 +-----------------------------
codegen/valaccodeassignmentmodule.vala | 2 +-
codegen/valaccodebasemodule.vala | 19 ++++++++----
codegen/valaccodememberaccessmodule.vala | 18 +++++++++++
codegen/valaccodemethodcallmodule.vala | 2 +-
5 files changed, 34 insertions(+), 55 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index c906fb2..8e1af80 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -167,52 +167,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return "_%s_size_".printf (array_cname);
}
- public override CCodeExpression get_array_size_cexpression (Expression array_expr) {
- 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;
- return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_size_cname (get_variable_cname (local.name)));
- } else {
- var size_expr = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
- return size_expr;
- }
-
- } else if (array_expr.symbol_reference is Field) {
- var field = (Field) array_expr.symbol_reference;
- var ma = (MemberAccess) array_expr;
-
- CCodeExpression size_expr = null;
-
- if (field.binding == MemberBinding.INSTANCE) {
- var cl = field.parent_symbol as Class;
- bool is_gtypeinstance = (cl != null && !cl.is_compact);
-
- string size_cname = get_array_size_cname (field.name);
- CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);
-
- CCodeExpression inst;
- if (is_gtypeinstance && field.access == SymbolAccessibility.PRIVATE) {
- inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
- } else {
- inst = typed_inst;
- }
- if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
- size_expr = new CCodeMemberAccess.pointer (inst, size_cname);
- } else {
- size_expr = new CCodeMemberAccess (inst, size_cname);
- }
- } else {
- size_expr = new CCodeIdentifier (get_array_size_cname (field.get_cname ()));
- }
-
- return size_expr;
- }
-
- assert_not_reached ();
- }
-
public override void visit_element_access (ElementAccess expr) {
List<Expression> indices = expr.get_indices ();
int rank = indices.size;
@@ -779,7 +733,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_array_add_wrapper (array_type)));
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (array)));
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_length_cexpression (array)));
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_size_cexpression (array)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_size_cvalue (array.target_value)));
ccall.add_argument (handle_struct_argument (value_param, element, get_cvalue (element)));
set_cvalue (assignment, ccall);
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 8745541..f616800 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -140,7 +140,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
var array_local = array_var as LocalVariable;
if (array_var != null && array_var.is_internal_symbol ()
&& ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) {
- var lhs_array_size = get_array_size_cexpression (assignment.left);
+ var lhs_array_size = get_array_size_cvalue (assignment.left.target_value);
var rhs_array_len = get_array_length_cexpression (assignment.left, 1);
ccode.add_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4e52849..845293e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -964,7 +964,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
if (array_type.rank == 1 && f.is_internal_symbol ()) {
- var lhs_array_size = get_array_size_cexpression (ma);
+ var lhs_array_size = get_array_size_cvalue (ma.target_value);
var rhs_array_len = get_array_length_cexpression (ma, 1);
ccode.add_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
}
@@ -2068,7 +2068,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
}
if (array_type.rank == 1 && !local.captured) {
- var lhs_array_size = get_array_size_cexpression (ma);
+ var lhs_array_size = get_array_size_cvalue (ma.target_value);
var rhs_array_len = get_array_length_cexpression (ma, 1);
ccode.add_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
}
@@ -5888,10 +5888,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return "";
}
- public virtual CCodeExpression get_array_size_cexpression (Expression array_expr) {
- return new CCodeConstant ("");
- }
-
public virtual void add_simple_check (CodeNode node, bool always_fails = false) {
}
@@ -5917,6 +5913,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
glib_value.cvalue = cvalue;
}
+ public CCodeExpression? get_array_size_cvalue (TargetValue value) {
+ var glib_value = (GLibValue) value;
+ return glib_value.array_size_cvalue;
+ }
+
+ public void set_array_size_cvalue (TargetValue value, CCodeExpression? cvalue) {
+ var glib_value = (GLibValue) value;
+ glib_value.array_size_cvalue = cvalue;
+ }
+
public CCodeExpression? get_delegate_target (Expression expr) {
if (expr.target_value == null) {
return null;
@@ -5974,6 +5980,7 @@ public class Vala.GLibValue : TargetValue {
public CCodeExpression cvalue;
public List<CCodeExpression> array_length_cvalues;
+ public CCodeExpression? array_size_cvalue;
public CCodeExpression? delegate_target_cvalue;
public CCodeExpression? delegate_target_destroy_notify_cvalue;
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index d0b4eb3..b2fd332 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -198,6 +198,15 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
append_array_size (expr, length_expr);
}
+ if (array_type.rank == 1 && field.is_internal_symbol ()) {
+ string size_cname = get_array_size_cname (field.name);
+
+ if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
+ set_array_size_cvalue (expr.target_value, new CCodeMemberAccess.pointer (inst, size_cname));
+ } else {
+ set_array_size_cvalue (expr.target_value, new CCodeMemberAccess (inst, size_cname));
+ }
+ }
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
string target_cname = get_delegate_target_cname (field.get_cname ());
@@ -270,6 +279,9 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
append_array_size (expr, new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim)));
}
}
+ if (array_type.rank == 1 && field.is_internal_symbol ()) {
+ set_array_size_cvalue (expr.target_value, new CCodeIdentifier (get_array_size_cname (field.get_cname ())));
+ }
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
@@ -612,6 +624,9 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
result.append_array_length_cvalue (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (local.name), dim)));
}
+ if (array_type.rank == 1) {
+ result.array_size_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_size_cname (get_variable_cname (local.name)));
+ }
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (local.name)));
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
@@ -622,6 +637,9 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
result.append_array_length_cvalue (get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim)));
}
+ if (array_type.rank == 1) {
+ result.array_size_cvalue = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
+ }
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
if (current_method != null && current_method.coroutine) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 0083b63..c6c0140 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -729,7 +729,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var array_local = array_var as LocalVariable;
if (array_var != null && array_var.is_internal_symbol ()
&& ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) {
- ccomma.append_expression (new CCodeAssignment (get_array_size_cexpression (ma.inner), temp_ref));
+ ccomma.append_expression (new CCodeAssignment (get_array_size_cvalue (ma.inner.target_value), temp_ref));
}
set_cvalue (expr, ccomma);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]