Commit 02f05799 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Add support for class destructors, patch by Sebastian Dröge, fixes bug

2008-12-16  Jürg Billeter  <j@bitron.ch>

	* vala/valaclass.vala:
	* vala/valaparser.vala:
	* gobject/valaclassregisterfunction.vala:
	* gobject/valagobjectmodule.vala:

	Add support for class destructors, patch by Sebastian Dröge,
	fixes bug 564011

svn path=/trunk/; revision=2188
parent 16bac3b7
2008-12-16 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala:
* vala/valaparser.vala:
* gobject/valaclassregisterfunction.vala:
* gobject/valagobjectmodule.vala:
Add support for class destructors, patch by Sebastian Dröge,
fixes bug 564011
2008-12-16 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala:
......
......@@ -59,7 +59,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
}
public override string get_base_finalize_func_name () {
if (class_reference.has_class_private_fields) {
if (class_reference.class_destructor != null || class_reference.has_class_private_fields) {
return "%s_base_finalize".printf (class_reference.get_lower_case_cname (null));
} else {
return "NULL";
......
......@@ -207,7 +207,7 @@ public class Vala.GObjectModule : GTypeModule {
}
add_class_init_function (cl);
if (cl.has_class_private_fields) {
if (cl.class_destructor != null || cl.has_class_private_fields) {
add_base_finalize_function (cl);
}
......@@ -1166,6 +1166,10 @@ public class Vala.GObjectModule : GTypeModule {
var cblock = new CCodeBlock ();
if (cl.class_destructor != null) {
cblock.add_statement (cl.class_destructor.ccodenode);
}
cblock.add_statement (base_finalize_fragment);
function.block = cblock;
......
......@@ -190,6 +190,11 @@ public class Vala.Class : ObjectTypeSymbol {
}
}
}
/**
* Specifies the class destructor.
*/
public Destructor class_destructor { get; set; }
/**
* Specifies whether this class denotes an error base.
......@@ -462,6 +467,10 @@ public class Vala.Class : ObjectTypeSymbol {
if (destructor != null) {
destructor.accept (visitor);
}
if (class_destructor != null) {
class_destructor.accept (visitor);
}
foreach (Class cl in classes) {
cl.accept (visitor);
......@@ -907,6 +916,10 @@ public class Vala.Class : ObjectTypeSymbol {
destructor.check (analyzer);
}
if (class_destructor != null) {
class_destructor.check (analyzer);
}
foreach (Class cl in classes) {
cl.check (analyzer);
}
......
......@@ -2002,7 +2002,14 @@ public class Vala.Parser : CodeVisitor {
cl.static_constructor = c;
}
} else if (sym is Destructor) {
cl.destructor = (Destructor) sym;
var d = (Destructor) sym;
if (d.binding == MemberBinding.STATIC) {
Report.error (sym.source_reference, "static destructors not supported yet");
} else if (d.binding == MemberBinding.CLASS) {
cl.class_destructor = (Destructor) d;
} else {
cl.destructor = (Destructor) d;
}
} else {
Report.error (sym.source_reference, "unexpected declaration in class");
}
......@@ -2319,11 +2326,17 @@ public class Vala.Parser : CodeVisitor {
Destructor parse_destructor_declaration (Gee.List<Attribute>? attrs) throws ParseError {
var begin = get_location ();
var flags = parse_member_declaration_modifiers ();
expect (TokenType.TILDE);
parse_identifier ();
expect (TokenType.OPEN_PARENS);
expect (TokenType.CLOSE_PARENS);
var d = new Destructor (get_src_com (begin));
if (ModifierFlags.STATIC in flags) {
d.binding = MemberBinding.STATIC;
} else if (ModifierFlags.CLASS in flags) {
d.binding = MemberBinding.CLASS;
}
d.body = parse_block ();
return d;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment