summaryrefslogtreecommitdiff
path: root/vala/valaproperty.vala
diff options
context:
space:
mode:
authorJuerg Billeter <j@bitron.ch>2008-05-28 16:07:50 +0000
committerJürg Billeter <juergbi@src.gnome.org>2008-05-28 16:07:50 +0000
commit0b8d57a0394926a1a3582c15a0a50c24fb6da749 (patch)
tree6f5ce3957af9c6f3dc6b88fdf5bc88a763cf01e3 /vala/valaproperty.vala
parent98ef51385999344aa8274d4268e9bc264f6d8ef8 (diff)
downloadvala-0b8d57a0394926a1a3582c15a0a50c24fb6da749.tar.gz
Compute Method.base_method and Property.base_property when needed so that
2008-05-28 Juerg Billeter <j@bitron.ch> * vala/valainterfacewriter.vala: * vala/valamethod.vala: * vala/valaproperty.vala: * vala/valasemanticanalyzer.vala: * gobject/valagidlwriter.vala: Compute Method.base_method and Property.base_property when needed so that we can already use them in the semantic analyzer svn path=/trunk/; revision=1460
Diffstat (limited to 'vala/valaproperty.vala')
-rw-r--r--vala/valaproperty.vala85
1 files changed, 83 insertions, 2 deletions
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 884c8bbc0..cc277e3ea 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -105,12 +105,22 @@ public class Vala.Property : Member, Lockable {
* Reference must be weak as virtual properties set base_property to
* themselves.
*/
- public weak Property base_property { get; set; }
+ public Property base_property {
+ get {
+ find_base_properties ();
+ return _base_property;
+ }
+ }
/**
* Specifies the abstract interface property this property implements.
*/
- public Property base_interface_property { get; set; }
+ public Property base_interface_property {
+ get {
+ find_base_properties ();
+ return _base_interface_property;
+ }
+ }
/**
* Specifies the default value of this property.
@@ -150,6 +160,10 @@ public class Vala.Property : Member, Lockable {
private string? _nick;
private string? _blurb;
+ private weak Property _base_property;
+ private Property _base_interface_property;
+ private bool base_properties_valid;
+
/**
* Creates a new property.
*
@@ -296,4 +310,71 @@ public class Vala.Property : Member, Lockable {
property_type = new_type;
}
}
+
+ private void find_base_properties () {
+ if (base_properties_valid) {
+ return;
+ }
+
+ if (parent_symbol is Class) {
+ /* VAPI classes don't specify overridden properties */
+ if (!parent_symbol.external_package) {
+ find_base_interface_property ((Class) parent_symbol);
+ if (is_virtual || overrides) {
+ find_base_class_property ((Class) parent_symbol);
+ }
+ } else if (is_virtual || is_abstract) {
+ _base_property = this;
+ }
+ } else if (parent_symbol is Interface) {
+ if (is_virtual || is_abstract) {
+ _base_interface_property = this;
+ }
+ }
+
+ base_properties_valid = true;
+ }
+
+ private void find_base_class_property (Class cl) {
+ var sym = cl.scope.lookup (name);
+ if (sym is Property) {
+ var base_property = (Property) sym;
+ if (base_property.is_abstract || base_property.is_virtual) {
+ if (!equals (base_property)) {
+ error = true;
+ Report.error (source_reference, "Type and/or accessors of overriding property `%s' do not match overridden property `%s'.".printf (get_full_name (), base_property.get_full_name ()));
+ return;
+ }
+
+ _base_property = base_property;
+ return;
+ }
+ }
+
+ if (cl.base_class != null) {
+ find_base_class_property (cl.base_class);
+ }
+ }
+
+ private void find_base_interface_property (Class cl) {
+ // FIXME report error if multiple possible base properties are found
+ foreach (DataType type in cl.get_base_types ()) {
+ if (type.data_type is Interface) {
+ var sym = type.data_type.scope.lookup (name);
+ if (sym is Property) {
+ var base_property = (Property) sym;
+ if (base_property.is_abstract) {
+ if (!equals (base_property)) {
+ error = true;
+ Report.error (source_reference, "Type and/or accessors of overriding property `%s' do not match overridden property `%s'.".printf (get_full_name (), base_property.get_full_name ()));
+ return;
+ }
+
+ _base_interface_property = base_property;
+ return;
+ }
+ }
+ }
+ }
+ }
}