]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Move creation of reference field from parser into property d2d2e183d307441dc22b8ec11b5a3f6a783573f1
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 19 Apr 2018 14:58:20 +0000 (16:58 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 19 Apr 2018 15:41:10 +0000 (17:41 +0200)
vala/valagenieparser.vala
vala/valaparser.vala
vala/valaproperty.vala

index e563580aaa3328ad801e67f965ff15c6d7fc8585..b925babbc7cc972c5287f76ca100b49fcd72c9a3 100644 (file)
@@ -3202,22 +3202,6 @@ public class Vala.Genie.Parser : CodeVisitor {
                        expect_terminator ();
                }
 
-               if (!prop.is_abstract && scanner.source_file.file_type == SourceFileType.SOURCE) {
-                       var needs_var = (readonly && (prop.get_accessor != null && prop.get_accessor.body == null));
-
-                       if (!needs_var) {
-                               needs_var = (prop.get_accessor != null && prop.get_accessor.body == null) || (prop.set_accessor != null && prop.set_accessor.body == null);
-                       }
-
-                       if (needs_var) {
-                               /* automatic property accessor body generation */
-                               var variable_type = prop.property_type.copy ();
-                               prop.field = new Field ("_%s".printf (prop.name), variable_type, prop.initializer, prop.source_reference);
-                               prop.field.access = SymbolAccessibility.PRIVATE;
-                               prop.field.binding = prop.binding;
-                       }
-               }
-
                return prop;
        }
 
index 51bc7a05f072bc7a1f0f589fff61a14cfd9d587a..3df315d1fe9190d11e5a8654751bf93b11d391b0 100644 (file)
@@ -2882,28 +2882,6 @@ public class Vala.Parser : CodeVisitor {
                }
                expect (TokenType.CLOSE_BRACE);
 
-               if (!prop.is_abstract && prop.source_type == SourceFileType.SOURCE) {
-                       bool empty_get = (prop.get_accessor != null && prop.get_accessor.body == null);
-                       bool empty_set = (prop.set_accessor != null && prop.set_accessor.body == null);
-
-                       if (empty_get != empty_set) {
-                               if (empty_get) {
-                                       Report.error (prop.source_reference, "property getter must have a body");
-                               } else if (empty_set) {
-                                       Report.error (prop.source_reference, "property setter must have a body");
-                               }
-                               prop.error = true;
-                       }
-
-                       if (empty_get && empty_set) {
-                               /* automatic property accessor body generation */
-                               var variable_type = prop.property_type.copy ();
-                               prop.field = new Field ("_%s".printf (prop.name), variable_type, prop.initializer, prop.source_reference);
-                               prop.field.access = SymbolAccessibility.PRIVATE;
-                               prop.field.binding = prop.binding;
-                       }
-               }
-
                parent.add_property (prop);
        }
 
index 2a83295fb0763788791dd642502922fe885d9999..ff953777cbebcf3536f30f278cfabd9b30b2fa4a 100644 (file)
@@ -97,9 +97,34 @@ public class Vala.Property : Symbol, Lockable {
        public bool overrides { get; set; }
 
        /**
-        * Reference the the Field that holds this property
+        * Reference the Field that holds this property
         */
-       public Field field { get; set; }
+       public Field? field {
+               get {
+                       if (!_field_checked) {
+                               if (!is_abstract && source_type == SourceFileType.SOURCE) {
+                                       bool empty_get = (get_accessor != null && get_accessor.body == null);
+                                       bool empty_set = (set_accessor != null && set_accessor.body == null);
+                                       if (empty_get != empty_set) {
+                                               if (empty_get) {
+                                                       Report.error (source_reference, "Property getter must have a body");
+                                               } else if (empty_set) {
+                                                       Report.error (source_reference, "Property setter must have a body");
+                                               }
+                                               error = true;
+                                       }
+                                       if (empty_get && empty_set) {
+                                               /* automatic property accessor body generation */
+                                               _field = new Field ("_%s".printf (name), property_type.copy (), initializer, source_reference);
+                                               _field.access = SymbolAccessibility.PRIVATE;
+                                               _field.binding = binding;
+                                       }
+                               }
+                               _field_checked = true;
+                       }
+                       return _field;
+               }
+       }
 
        /**
         * Specifies whether this field may only be accessed with an instance of
@@ -198,6 +223,8 @@ public class Vala.Property : Symbol, Lockable {
        private string? _nick;
        private string? _blurb;
        private bool? _notify;
+       private Field? _field;
+       private bool _field_checked;
 
        /**
         * Creates a new property.