[vala] Fix temporary variable handling for class field initializers
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix temporary variable handling for class field initializers
- Date: Wed, 24 Mar 2010 07:40:34 +0000 (UTC)
commit 30f3bdf5503071f6a4cf6780494f5bddf49d68ed
Author: Jürg Billeter <j bitron ch>
Date: Tue Mar 23 18:07:11 2010 +0100
Fix temporary variable handling for class field initializers
codegen/valaccodebasemodule.vala | 26 ++++++++++++++++++++++++++
codegen/valagtypemodule.vala | 21 ---------------------
2 files changed, 26 insertions(+), 21 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e00f0d3..89ef3d5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1057,6 +1057,32 @@ internal class Vala.CCodeBaseModule : CCodeModule {
f.error = true;
return;
}
+
+ if (f.access == SymbolAccessibility.PRIVATE) {
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (cl.get_upper_case_cname ())));
+ ccall.add_argument (new CCodeIdentifier ("klass"));
+ lhs = new CCodeMemberAccess (ccall, f.get_cname (), true);
+ } else {
+ lhs = new CCodeMemberAccess (new CCodeIdentifier ("klass"), f.get_cname (), true);
+ }
+
+ if (f.initializer != null) {
+ var rhs = (CCodeExpression) f.initializer.ccodenode;
+
+ class_init_fragment.append (new CCodeExpressionStatement (new CCodeAssignment (lhs, rhs)));
+
+ append_temp_decl (class_init_fragment, temp_vars);
+
+ 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 ();
+ class_init_fragment.append (new CCodeExpressionStatement (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma)));
+ }
+
+ temp_vars.clear ();
+ temp_ref_vars.clear ();
+ }
} else {
generate_field_declaration (f, source_declarations);
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index b95e375..bda752c 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1290,27 +1290,6 @@ internal class Vala.GTypeModule : GErrorModule {
}
}
- /* initialize class fields */
- var fields = cl.get_fields ();
- foreach (Field field in fields) {
- if (field.binding != MemberBinding.CLASS || field.initializer == null) {
- continue;
- }
-
- CCodeExpression left;
-
- if (field.access == SymbolAccessibility.PRIVATE) {
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (cl.get_upper_case_cname ())));
- ccall.add_argument (new CCodeIdentifier ("klass"));
- left = new CCodeMemberAccess (ccall, field.get_cname (), true);
- } else {
- left = new CCodeMemberAccess (new CCodeIdentifier ("klass"), field.get_cname (), true);
- }
- CCodeExpression right = (CCodeExpression) field.initializer.ccodenode;
- CCodeAssignment assign = new CCodeAssignment (left, right);
- init_block.add_statement (new CCodeExpressionStatement (assign));
- }
-
generate_class_init (cl, init_block);
if (!cl.is_compact) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]