Commit 5018260d authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Fix base access with virtual interface methods, fixes bug 528457

2008-04-16  Juerg Billeter  <j@bitron.ch>

	* gobject/valaccodegenerator.vala,
	  gobject/valaccodegeneratorinvocationexpression.vala,
	  gobject/valaccodegeneratormemberaccess.vala:

	  Fix base access with virtual interface methods, fixes bug 528457

	* tests/classes-methods.vala: test base access

svn path=/trunk/; revision=1247
parent 4e1d4bca
2008-04-16 Jürg Billeter <j@bitron.ch>
* gobject/valaccodegenerator.vala,
gobject/valaccodegeneratorinvocationexpression.vala,
gobject/valaccodegeneratormemberaccess.vala:
Fix base access with virtual interface methods, fixes bug 528457
* tests/classes-methods.vala: test base access
2008-04-16 Jürg Billeter <j@bitron.ch>
* vala/valaparser.vala: improve error handling, fixes bug 528431
......
......@@ -3277,10 +3277,10 @@ public class Vala.CCodeGenerator : CodeGenerator {
var mt = (MethodType) expression_type;
var method = mt.method_symbol;
if (method.base_interface_method != null) {
method = method.base_interface_method;
} else if (method.base_method != null) {
if (method.base_method != null) {
method = method.base_method;
} else if (method.base_interface_method != null) {
method = method.base_interface_method;
}
return new CCodeIdentifier (generate_delegate_wrapper (method, dt.delegate_symbol));
......
......@@ -66,10 +66,10 @@ public class Vala.CCodeGenerator {
CCodeExpression instance;
if (m != null && m.instance) {
var base_method = m;
if (m.base_interface_method != null) {
base_method = m.base_interface_method;
} else if (m.base_method != null) {
if (m.base_method != null) {
base_method = m.base_method;
} else if (m.base_interface_method != null) {
base_method = m.base_interface_method;
}
DataType instance_expression_type;
......
......@@ -29,25 +29,23 @@ public class Vala.CCodeGenerator {
var m = (Method) expr.symbol_reference;
if (expr.inner is BaseAccess) {
if (m.base_interface_method != null) {
var base_iface = (Interface) m.base_interface_method.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));
expr.ccodenode = new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.name);
return;
} else if (m.base_method != null) {
if (m.base_method != null) {
var base_class = (Class) m.base_method.parent_symbol;
var vcast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (base_class.get_upper_case_cname (null))));
vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (current_class.get_lower_case_cname (null))));
expr.ccodenode = new CCodeMemberAccess.pointer (vcast, m.name);
return;
} else if (m.base_interface_method != null) {
var base_iface = (Interface) m.base_interface_method.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));
expr.ccodenode = new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.name);
return;
}
}
if (m.base_interface_method != null) {
expr.ccodenode = new CCodeIdentifier (m.base_interface_method.get_cname ());
} else if (m.base_method != null) {
if (m.base_method != null) {
var binding = CCodeMethodBinding.get (m.base_method);
if (!binding.has_wrapper) {
var inst = pub_inst;
......@@ -67,6 +65,8 @@ public class Vala.CCodeGenerator {
} else {
expr.ccodenode = new CCodeIdentifier (m.base_method.get_cname ());
}
} else if (m.base_interface_method != null) {
expr.ccodenode = new CCodeIdentifier (m.base_interface_method.get_cname ());
} else {
expr.ccodenode = new CCodeIdentifier (m.get_cname ());
}
......
......@@ -58,6 +58,8 @@ class Maman.SubBar : Bar {
test_classes_methods_ref_parameters ();
BaseAccess.test ();
return 0;
}
}
......@@ -91,3 +93,54 @@ abstract class Maman.AbstractDerived : AbstractBase {
class Maman.DeepDerived : AbstractDerived {
}
// http://bugzilla.gnome.org/show_bug.cgi?id=528457
namespace Maman.BaseAccess {
public interface IFoo : Object {
public abstract int interface_method ();
public abstract int virtual_interface_method ();
}
public class Foo : Object, IFoo {
public virtual int virtual_method () {
return 1;
}
public int interface_method () {
return 2;
}
public virtual int virtual_interface_method () {
return 3;
}
}
public class Bar : Foo {
public override int virtual_method () {
return base.virtual_method () * 10 + 4;
}
public override int virtual_interface_method () {
return base.virtual_interface_method () * 10 + 5;
}
}
public class FooBar : Foo, IFoo {
public int interface_method () {
return base.interface_method () * 10 + 6;
}
public int virtual_interface_method () {
return -1;
}
}
public void test () {
var bar = new Bar ();
var foobar = new FooBar ();
assert (bar.virtual_method () == 14);
assert (bar.virtual_interface_method () == 35);
assert (foobar.interface_method () == 26);
}
}
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