[vala] codegen: Use builder API to store properties
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use builder API to store properties
- Date: Sat, 16 Oct 2010 07:28:41 +0000 (UTC)
commit 711264541c09ecd5bccb3a90e821e61b71641b36
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 16 08:47:42 2010 +0200
codegen: Use builder API to store properties
codegen/valaccodeassignmentmodule.vala | 2 +-
codegen/valaccodebasemodule.vala | 29 ++++++++++++-----------------
codegen/valadovaassignmentmodule.vala | 2 +-
codegen/valadovabasemodule.vala | 9 ++++-----
4 files changed, 18 insertions(+), 24 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index e28f685..2c1284c 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -81,7 +81,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr);
}
- ccode.add_expression (get_property_set_call (prop, ma, cexpr, assignment.right));
+ store_property (prop, ma, cexpr, assignment.right);
// assignments are expressions, so return the current property value, except if we're sure that it can't be used
if (assignment.parent_node is ExpressionStatement) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2517c9a..0575c3e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3555,8 +3555,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
// increment/decrement property
var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
var cexpr = new CCodeBinaryExpression (op, get_variable_cexpression (temp_decl.name), new CCodeConstant ("1"));
- var ccall = get_property_set_call (prop, ma, cexpr);
- ccode.add_expression (ccall);
+ store_property (prop, ma, cexpr);
// return previous value
set_cvalue (expr, get_variable_cexpression (temp_decl.name));
@@ -4254,7 +4253,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
inst_ma.value_type = expr.type_reference;
set_cvalue (inst_ma, instance);
var ma = new MemberAccess (inst_ma, init.name);
- ccode.add_expression (get_property_set_call ((Property) init.symbol_reference, ma, get_cvalue (init.initializer)));
+ store_property ((Property) init.symbol_reference, ma, get_cvalue (init.initializer));
}
}
@@ -5162,7 +5161,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public CCodeExpression get_property_set_call (Property prop, MemberAccess ma, CCodeExpression cexpr, Expression? rhs = null) {
+ public void store_property (Property prop, MemberAccess ma, CCodeExpression cexpr, Expression? rhs = null) {
if (ma.inner is BaseAccess) {
if (prop.base_property != null) {
var base_class = (Class) prop.base_property.parent_symbol;
@@ -5172,7 +5171,8 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "set_%s".printf (prop.name)));
ccall.add_argument ((CCodeExpression) get_ccodenode (ma.inner));
ccall.add_argument (cexpr);
- return ccall;
+
+ ccode.add_expression (ccall);
} else if (prop.base_interface_property != null) {
var base_iface = (Interface) prop.base_interface_property.parent_symbol;
string parent_iface_var = "%s_%s_parent_iface".printf (current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
@@ -5180,8 +5180,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), "set_%s".printf (prop.name)));
ccall.add_argument ((CCodeExpression) get_ccodenode (ma.inner));
ccall.add_argument (cexpr);
- return ccall;
+
+ ccode.add_expression (ccall);
}
+ return;
}
var set_func = "g_object_set";
@@ -5219,14 +5221,12 @@ public class Vala.CCodeBaseModule : CodeGenerator {
} else {
// if instance is e.g. a function call, we can't take the address of the expression
// (tmp = expr, &tmp)
- var ccomma = new CCodeCommaExpression ();
var temp_var = get_temp_variable (ma.inner.target_type, true, null, false);
emit_temp_var (temp_var);
- ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), instance));
- ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_var.name)));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), instance));
- instance = ccomma;
+ instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_var.name));
}
}
@@ -5240,18 +5240,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var array_type = prop.property_type as ArrayType;
- CCodeExpression rv;
if (array_type != null && !prop.no_array_length) {
var temp_var = get_temp_variable (prop.property_type, true, null, false);
emit_temp_var (temp_var);
- var ccomma = new CCodeCommaExpression ();
- ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), cexpr));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), cexpr));
ccall.add_argument (get_variable_cexpression (temp_var.name));
- ccomma.append_expression (ccall);
- rv = ccomma;
} else {
ccall.add_argument (cexpr);
- rv = ccall;
}
if (array_type != null && !prop.no_array_length && rhs != null) {
@@ -5270,7 +5265,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument (new CCodeConstant ("NULL"));
}
- return rv;
+ ccode.add_expression (ccall);
}
/* indicates whether a given Expression eligable for an ADDRESS_OF operator
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index 2703dff..f39894c 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -71,7 +71,7 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr);
}
- ccode.add_expression (get_property_set_call (prop, ma, cexpr, assignment.right));
+ store_property (prop, ma, cexpr, assignment.right);
// assignments are expressions, so return the current property value, except if we're sure that it can't be used
if (assignment.parent_node is ExpressionStatement) {
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 8e42962..14b4282 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1377,8 +1377,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
// increment/decrement property
var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
var cexpr = new CCodeBinaryExpression (op, get_variable_cexpression (temp_decl.name), new CCodeConstant ("1"));
- var ccall = get_property_set_call (prop, ma, cexpr);
- ccode.add_expression (ccall);
+ store_property (prop, ma, cexpr);
// return previous value
set_cvalue (expr, new CCodeIdentifier (temp_decl.name));
@@ -1698,7 +1697,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
inst_ma.value_type = expr.type_reference;
set_cvalue (inst_ma, instance);
var ma = new MemberAccess (inst_ma, init.name);
- ccode.add_expression (get_property_set_call ((Property) init.symbol_reference, ma, get_cvalue (init.initializer)));
+ store_property ((Property) init.symbol_reference, ma, get_cvalue (init.initializer));
}
}
@@ -2144,7 +2143,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
}
}
- public CCodeFunctionCall get_property_set_call (Property prop, MemberAccess ma, CCodeExpression cexpr, Expression? rhs = null) {
+ public void store_property (Property prop, MemberAccess ma, CCodeExpression cexpr, Expression? rhs = null) {
string set_func;
var base_property = prop;
@@ -2166,7 +2165,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
ccall.add_argument (cexpr);
- return ccall;
+ ccode.add_expression (ccall);
}
public bool add_generated_external_symbol (Symbol external_symbol) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]