current_symbol = current_symbol.parent_symbol;
current_struct = null;
}
+
+ public override void visit_begin_interface (Interface! iface) {
+ current_symbol = iface.symbol;
+
+ foreach (TypeReference base_type_reference in iface.get_base_types ()) {
+ current_source_file.add_symbol_dependency (base_type_reference.data_type.symbol, SourceFileDependencyType.HEADER_FULL);
+ }
+ }
+
+ public override void visit_end_interface (Interface! iface) {
+ current_symbol = current_symbol.parent_symbol;
+ }
public override void visit_constant (Constant! c) {
if (!current_source_file.pkg) {
}
}
+ private void find_base_method (Method! m, DataType! datatype) {
+ var sym = datatype.symbol.lookup (m.name);
+ if (sym != null && sym.node is Method) {
+ var base_method = (Method) sym.node;
+ if (base_method.is_abstract || base_method.is_virtual) {
+ if (!m.equals (base_method)) {
+ m.error = true;
+ Report.error (m.source_reference, "Return type and/or parameters of overriding method `%s' do not match overridden method `%s'.".printf (m.symbol.get_full_name (), base_method.symbol.get_full_name ()));
+ return;
+ }
+
+ m.base_method = base_method;
+ return;
+ }
+ }
+
+ // FIXME report error if multiple possible base methods are found
+ if (datatype is Class) {
+ var cl = (Class) datatype;
+ foreach (TypeReference type in cl.get_base_types ()) {
+ find_base_method (m, type.data_type);
+ if (m.base_method != null) {
+ return;
+ }
+ }
+ } else {
+ var iface = (Interface) datatype;
+ foreach (TypeReference type in iface.get_base_types ()) {
+ find_base_method (m, type.data_type);
+ if (m.base_method != null) {
+ return;
+ }
+ }
+ }
+ }
+
public override void visit_end_method (Method! m) {
current_symbol = current_symbol.parent_symbol;
current_return_type = null;
if (m.is_virtual || m.overrides) {
if (current_symbol.node is Class) {
- var cl = (Class) current_symbol.node;
- Class base_class;
- for (base_class = cl; base_class != null; base_class = base_class.base_class) {
- var sym = base_class.symbol.lookup (m.name);
- if (sym != null && sym.node is Method) {
- var base_method = (Method) sym.node;
- if (base_method.is_abstract || base_method.is_virtual) {
- if (!m.equals (base_method)) {
- m.error = true;
- Report.error (m.source_reference, "Return type and or parameters of overriding method `%s' do not match overridden method `%s'.".printf (m.symbol.get_full_name (), base_method.symbol.get_full_name ()));
- return;
- }
-
- m.base_method = base_method;
- break;
- }
- }
- }
- if (m.base_method == null) {
- /* FIXME: also look at interfaces implemented
- * by one of the base types
- */
- foreach (TypeReference type in cl.get_base_types ()) {
- if (type.data_type is Interface) {
- var iface = (Interface) type.data_type;
- var sym = iface.symbol.lookup (m.name);
- if (sym != null && sym.node is Method) {
- var base_method = (Method) sym.node;
- if (base_method.is_abstract || base_method.is_virtual) {
- m.base_method = base_method;
- break;
- }
- }
- }
- }
- }
+ find_base_method (m, (Class) current_symbol.node);
if (m.base_method == null) {
Report.error (m.source_reference, "%s: no suitable method found to override".printf (m.symbol.get_full_name ()));
}