}
// connect inherited implementations
- foreach (Method m in iface.get_methods ()) {
- if (m.is_abstract) {
- Method cl_method = null;
- var base_class = cl;
- while (base_class != null && cl_method == null) {
- cl_method = base_class.scope.lookup (m.name) as Method;
- base_class = base_class.base_class;
- }
- if (base_class != null && cl_method.parent_symbol != cl) {
- // method inherited from base class
-
- var base_method = cl_method;
- if (cl_method.base_interface_method != null) {
- base_method = cl_method.base_interface_method;
- } else if (cl_method.base_method != null) {
- //FIXME should this ever be possible here?
- base_method = cl_method.base_method;
- }
+ var it = cl.get_implicit_implementations ().map_iterator ();
+ while (it.next ()) {
+ Method m = it.get_key ();
+ if (m.parent_symbol == iface) {
+ Method base_method = it.get_value ();
- generate_method_declaration (base_method, cfile);
+ generate_method_declaration (base_method, cfile);
- CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
- cfunc = cast_method_pointer (base_method, cfunc, iface);
- var ciface = new CCodeIdentifier ("iface");
- ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
- }
+ CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
+ cfunc = cast_method_pointer (m, cfunc, iface);
+ var ciface = new CCodeIdentifier ("iface");
+ ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
}
}
objects/chainup.vala \
objects/class_only.vala \
objects/classes.vala \
+ objects/classes-interfaces.vala \
+ objects/classes-implicit-implementation.vala \
objects/compact-class.vala \
objects/compact-class-destructor.vala \
objects/constructor-variadic.test \
--- /dev/null
+interface IFoo : Object {
+ public abstract int foo ();
+}
+
+interface IBar : Object {
+}
+
+class Bar : Object {
+ public int foo () {
+ assert_not_reached ();
+ return -1;
+ }
+}
+
+class Baz : Object {
+ public int foo () {
+ return 23;
+ }
+}
+
+class Foo : Bar, IFoo {
+ public int foo () {
+ return 42;
+ }
+}
+
+class Faz : Baz, IFoo, IBar {
+}
+
+void main () {
+ var foo = new Foo ();
+ assert (foo.foo () == 42);
+
+ var baz = new Baz ();
+ assert (baz.foo () == 23);
+}
--- /dev/null
+class Base : Object {
+ public void foo () {
+ }
+}
+
+interface IFoo : Base {
+ public abstract string foo ();
+}
+
+interface IBar : Base {
+ public abstract int foo ();
+}
+
+class Manam : Base, IFoo, IBar {
+ public int IBar.foo () {
+ return 23;
+ }
+ public string IFoo.foo () {
+ return "foo";
+ }
+}
+
+void main () {
+ var manam = new Manam ();
+ assert (((IFoo) manam).foo () == "foo");
+ assert (((IBar) manam).foo () == 23);
+}
private bool? _is_singleton;
private List<DataType> base_types = new ArrayList<DataType> ();
+ private HashMap<Method,Method> implicit_implementations = new HashMap<Method,Method> ();
/**
* Specifies the default construction method.
}
}
+ public HashMap<Method,Method> get_implicit_implementations () {
+ return implicit_implementations;
+ }
+
/**
* Adds the specified property as a member to this class.
*
impl.version.check (source_reference);
impl.used = true;
implemented = true;
+ if (impl.base_interface_method == null) {
+ implicit_implementations.set (m, impl);
+ }
break;
}
}