]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dova: Support public and protected instance fields in classes
authorJürg Billeter <j@bitron.ch>
Tue, 13 Jul 2010 20:26:05 +0000 (22:26 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 13 Jul 2010 20:26:05 +0000 (22:26 +0200)
Internally handled as properties to avoid ABI issues.

Fixes bug 623503.

vala/valaclass.vala

index 1b675dad6253d772bef83db767665f1644f21a2c..b22b0093b814e6608fe06528571705bac1c2cbcf 100644 (file)
@@ -285,6 +285,32 @@ public class Vala.Class : ObjectTypeSymbol {
         * @param f a field
         */
        public void add_field (Field f) {
+               if (CodeContext.get ().profile == Profile.DOVA &&
+                   f.binding == MemberBinding.INSTANCE &&
+                   (f.access == SymbolAccessibility.PUBLIC || f.access == SymbolAccessibility.PROTECTED) &&
+                   name != "string" /* temporary workaround */) {
+                       // public/protected instance fields not supported, convert to automatic property
+
+                       var prop = new Property (f.name, f.field_type.copy (), null, null, f.source_reference, comment);
+                       prop.access = access;
+
+                       var get_type = prop.property_type.copy ();
+                       get_type.value_owned = true;
+
+                       prop.get_accessor = new PropertyAccessor (true, false, false, get_type, null, f.source_reference);
+                       prop.get_accessor.access = SymbolAccessibility.PUBLIC;
+
+                       prop.set_accessor = new PropertyAccessor (false, true, false, prop.property_type.copy (), null, f.source_reference);
+                       prop.set_accessor.access = SymbolAccessibility.PUBLIC;
+
+                       f.name = "_%s".printf (f.name);
+                       f.access = SymbolAccessibility.PRIVATE;
+                       prop.field = f;
+
+                       add_property (prop);
+                       return;
+               }
+
                fields.add (f);
                if (f.access == SymbolAccessibility.PRIVATE && f.binding == MemberBinding.INSTANCE) {
                        has_private_fields = true;