[vala] codegen: Use append_array_size for field access
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use append_array_size for field access
- Date: Sat, 9 Oct 2010 17:07:52 +0000 (UTC)
commit 1771f9d54c25f97347068a500f7657d6459040f9
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 17:29:35 2010 +0200
codegen: Use append_array_size for field access
codegen/valaccodearraymodule.vala | 88 +--------------------------
codegen/valaccodebasemodule.vala | 14 ++++-
codegen/valaccodememberaccessmodule.vala | 98 +++++++++++++++++++++++++-----
3 files changed, 96 insertions(+), 104 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index cc137ee..3aa6628 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 || array_expr.symbol_reference is LocalVariable) {
+ if (array_expr.symbol_reference is FormalParameter || array_expr.symbol_reference is LocalVariable || array_expr.symbol_reference is Field) {
List<CCodeExpression> size = get_array_sizes (array_expr);
if (size != null && size.size >= dim) {
if (is_out) {
@@ -191,92 +191,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return size[dim - 1];
}
}
- } else if (array_expr.symbol_reference is Field) {
- var field = (Field) array_expr.symbol_reference;
- if (field.array_null_terminated) {
- var ma = (MemberAccess) array_expr;
-
- CCodeExpression carray_expr = null;
-
- if (field.binding == MemberBinding.INSTANCE) {
- var cl = field.parent_symbol as Class;
- bool is_gtypeinstance = (cl != null && !cl.is_compact);
-
- string array_cname = field.get_cname ();
- 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 ()) {
- carray_expr = new CCodeMemberAccess.pointer (inst, array_cname);
- } else {
- carray_expr = new CCodeMemberAccess (inst, array_cname);
- }
- } else {
- carray_expr = new CCodeIdentifier (field.get_cname ());
- }
-
- requires_array_length = true;
- var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
- len_call.add_argument (carray_expr);
- return len_call;
- } else if (!field.no_array_length) {
- var ma = (MemberAccess) array_expr;
-
- CCodeExpression length_expr = null;
-
- if (field.has_array_length_cexpr) {
- length_expr = new CCodeConstant (field.get_array_length_cexpr ());
- } else if (field.binding == MemberBinding.INSTANCE) {
- var cl = field.parent_symbol as Class;
- bool is_gtypeinstance = (cl != null && !cl.is_compact);
-
- string length_cname;
- if (field.has_array_length_cname) {
- length_cname = field.get_array_length_cname ();
- } else {
- length_cname = get_array_length_cname (field.name, dim);
- }
- 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 ()) {
- length_expr = new CCodeMemberAccess.pointer (inst, length_cname);
- } else {
- length_expr = new CCodeMemberAccess (inst, length_cname);
- }
-
- if (field.array_length_type != null) {
- // cast if field does not use int for array length
- var parent_expr = array_expr.parent_node as Expression;
- if (array_expr.lvalue) {
- // don't cast if array is used as lvalue
- } else if (parent_expr != null && parent_expr.symbol_reference is ArrayLengthField &&
- parent_expr.lvalue) {
- // don't cast if array length is used as lvalue
- } else {
- length_expr = new CCodeCastExpression (length_expr, "gint");
- }
- }
- } else {
- length_expr = new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim));
- }
-
- if (is_out) {
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
- } else {
- return length_expr;
- }
- }
} else if (array_expr.symbol_reference is Constant) {
var constant = (Constant) array_expr.symbol_reference;
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 344ec72..0c735e3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -934,7 +934,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (this_access, new CCodeIdentifier ("self"));
var ma = new MemberAccess (this_access, f.name);
ma.symbol_reference = f;
-
+ ma.value_type = f.variable_type.copy ();
+ visit_member_access (ma);
+
List<Expression> sizes = ((ArrayCreationExpression) f.initializer).get_sizes ();
for (int dim = 1; dim <= array_type.rank; dim++) {
var array_len_lhs = get_array_length_cexpression (ma, dim);
@@ -978,6 +980,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess (this_access, f.name);
ma.symbol_reference = f;
ma.value_type = f.variable_type.copy ();
+ visit_member_access (ma);
ccode.add_expression (get_unref_expression (lhs, f.variable_type, ma));
pop_context ();
@@ -1010,6 +1013,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));
}
@@ -1135,7 +1139,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var array_type = (ArrayType) f.variable_type;
var ma = new MemberAccess.simple (f.name);
ma.symbol_reference = f;
-
+ ma.value_type = f.variable_type.copy ();
+ visit_member_access (ma);
+
List<Expression> sizes = ((ArrayCreationExpression) f.initializer).get_sizes ();
for (int dim = 1; dim <= array_type.rank; dim++) {
var array_len_lhs = get_array_length_cexpression (ma, dim);
@@ -5505,6 +5511,8 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ma = new MemberAccess (this_access, f.name);
ma.symbol_reference = f;
+ ma.value_type = f.variable_type.copy ();
+ visit_member_access (ma);
cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (lhs, f.variable_type, ma)));
}
}
@@ -5541,6 +5549,8 @@ public class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (this_access, new CCodeIdentifier ("(*self)"));
var ma = new MemberAccess (this_access, f.name);
ma.symbol_reference = f;
+ ma.value_type = f.variable_type.copy ();
+ visit_member_access (ma);
copy = get_ref_cexpression (f.variable_type, copy, ma, f);
}
var dest = new CCodeMemberAccess.pointer (new CCodeIdentifier ("dest"), f.name);
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index fb8d085..a3cec43 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -96,15 +96,15 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
set_cvalue (expr, get_array_length_cexpression (expr.inner, 1));
} else if (expr.symbol_reference is Field) {
- var f = (Field) expr.symbol_reference;
- if (f.binding == MemberBinding.INSTANCE) {
- var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
+ var field = (Field) expr.symbol_reference;
+ if (field.binding == MemberBinding.INSTANCE) {
+ var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
var cl = instance_target_type.data_type as Class;
bool is_gtypeinstance = ((instance_target_type.data_type == cl) && (cl == null || !cl.is_compact));
CCodeExpression inst;
- if (is_gtypeinstance && f.access == SymbolAccessibility.PRIVATE) {
+ if (is_gtypeinstance && field.access == SymbolAccessibility.PRIVATE) {
inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
} else {
if (cl != null) {
@@ -113,20 +113,71 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
inst = pub_inst;
}
if (instance_target_type.data_type.is_reference_type () || (expr.inner != null && expr.inner.value_type is PointerType)) {
- set_cvalue (expr, new CCodeMemberAccess.pointer (inst, f.get_cname ()));
+ set_cvalue (expr, new CCodeMemberAccess.pointer (inst, field.get_cname ()));
} else {
if (inst is CCodeCommaExpression) {
var ccomma = inst as CCodeCommaExpression;
var inner = ccomma.get_inner ();
var last = inner.get (inner.size - 1);
- ccomma.set_expression (inner.size - 1, new CCodeMemberAccess (last, f.get_cname ()));
+ ccomma.set_expression (inner.size - 1, new CCodeMemberAccess (last, field.get_cname ()));
set_cvalue (expr, ccomma);
} else {
- set_cvalue (expr, new CCodeMemberAccess (inst, f.get_cname ()));
+ set_cvalue (expr, new CCodeMemberAccess (inst, field.get_cname ()));
}
}
- } else if (f.binding == MemberBinding.CLASS) {
- var cl = (Class) f.parent_symbol;
+
+ if (array_type != null) {
+ if (field.array_null_terminated) {
+ CCodeExpression carray_expr = null;
+ if (instance_target_type.data_type.is_reference_type () || (expr.inner != null && expr.inner.value_type is PointerType)) {
+ carray_expr = new CCodeMemberAccess.pointer (inst, field.get_cname ());
+ } else {
+ carray_expr = new CCodeMemberAccess (inst, field.get_cname ());
+ }
+
+ requires_array_length = true;
+ var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
+ len_call.add_argument (carray_expr);
+ append_array_size (expr, len_call);
+ } else if (!field.no_array_length) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ CCodeExpression length_expr = null;
+
+ if (field.has_array_length_cexpr) {
+ length_expr = new CCodeConstant (field.get_array_length_cexpr ());
+ } else {
+ string length_cname;
+ if (field.has_array_length_cname) {
+ length_cname = field.get_array_length_cname ();
+ } else {
+ length_cname = get_array_length_cname (field.name, dim);
+ }
+
+ if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
+ length_expr = new CCodeMemberAccess.pointer (inst, length_cname);
+ } else {
+ length_expr = new CCodeMemberAccess (inst, length_cname);
+ }
+
+ if (field.array_length_type != null) {
+ // cast if field does not use int for array length
+ var parent_expr = expr.parent_node as Expression;
+ if (expr.lvalue) {
+ // don't cast if array is used as lvalue
+ } else if (parent_expr != null && parent_expr.symbol_reference is ArrayLengthField &&
+ parent_expr.lvalue) {
+ // don't cast if array length is used as lvalue
+ } else {
+ length_expr = new CCodeCastExpression (length_expr, "gint");
+ }
+ }
+ }
+ append_array_size (expr, length_expr);
+ }
+ }
+ }
+ } else if (field.binding == MemberBinding.CLASS) {
+ var cl = (Class) field.parent_symbol;
var cast = new CCodeFunctionCall (new CCodeIdentifier (cl.get_upper_case_cname (null) + "_CLASS"));
CCodeExpression klass;
@@ -148,18 +199,35 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
cast.add_argument (klass);
- if (f.access == SymbolAccessibility.PRIVATE) {
+ if (field.access == SymbolAccessibility.PRIVATE) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (cl.get_upper_case_cname ())));
ccall.add_argument (klass);
- set_cvalue (expr, new CCodeMemberAccess.pointer (ccall, f.get_cname ()));
+ set_cvalue (expr, new CCodeMemberAccess.pointer (ccall, field.get_cname ()));
} else {
- set_cvalue (expr, new CCodeMemberAccess.pointer (cast, f.get_cname ()));
+ set_cvalue (expr, new CCodeMemberAccess.pointer (cast, field.get_cname ()));
}
} else {
- generate_field_declaration (f, cfile);
+ generate_field_declaration (field, cfile);
+
+ set_cvalue (expr, new CCodeIdentifier (field.get_cname ()));
- set_cvalue (expr, new CCodeIdentifier (f.get_cname ()));
+ if (array_type != null) {
+ if (field.array_null_terminated) {
+ requires_array_length = true;
+ var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
+ len_call.add_argument (new CCodeIdentifier (field.get_cname ()));
+ append_array_size (expr, len_call);
+ } else if (!field.no_array_length) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ if (field.has_array_length_cexpr) {
+ append_array_size (expr, new CCodeConstant (field.get_array_length_cexpr ()));
+ } else {
+ append_array_size (expr, new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim)));
+ }
+ }
+ }
+ }
}
} else if (expr.symbol_reference is EnumValue) {
var ev = (EnumValue) expr.symbol_reference;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]