+2008-07-22 Jared Moore <jaredm@svn.gnome.org>
+
+ * gobject/valaccodeclassbinding.vala:
+ * goblect/valaccodemethodbinding.vala:
+
+ Generate *_instance_init function for compact classes to initialize
+ fields, fixes bug 529679.
+
+ * tests/classes-fields.vala: add test case
+
2008-07-21 Jared Moore <jaredm@svn.gnome.org>
* vapi/packages/gtk+-2.0/gtk+-2.0.metadata:
codegen.source_type_member_definition.append (unref_fun);
}
} else if (!cl.is_static) {
+ add_instance_init_function (cl);
+
var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
if (cl.access == SymbolAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
instance_init.add_parameter (new CCodeFormalParameter ("self", "%s *".printf (cl.get_cname ())));
instance_init.modifiers = CCodeModifiers.STATIC;
+ if (cl.is_compact) {
+ // Add declaration, since the instance_init function is explicitly called
+ // by the creation methods
+ codegen.source_type_member_declaration.append (instance_init.copy ());
+ }
+
var init_block = new CCodeBlock ();
instance_init.block = init_block;
- if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
+ if (!cl.is_compact && (cl.has_private_fields || cl.get_type_parameters ().size > 0)) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_PRIVATE".printf (cl.get_upper_case_cname (null))));
ccall.add_argument (new CCodeIdentifier ("self"));
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), ccall)));
ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall));
cinit.append (cdecl);
+
+ var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (cl.get_lower_case_cname (null))));
+ cinitcall.add_argument (new CCodeIdentifier ("self"));
+ cinit.append (new CCodeExpressionStatement (cinitcall));
} else {
var st = (Struct) m.parent_symbol;
-Field Test: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
+Field Test: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
using GLib;
+[Compact]
+class CompactTest {
+ public int initialized_field = 24;
+}
+
class Maman.Foo : Object {
public int public_base_field = 2;
public class int public_class_field = 23;
var foo = new Foo ();
stdout.printf (" %d", foo.public_class_field);
- stdout.printf (" 24\n");
+ var compact = new CompactTest ();
+ stdout.printf (" %d", compact.initialized_field);
+
+ stdout.printf (" 25\n");
+
return 0;
}
}