[vala/staging: 1/4] vala: Move creation of reference field from parser into property



commit d2d2e183d307441dc22b8ec11b5a3f6a783573f1
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Apr 19 16:58:20 2018 +0200

    vala: Move creation of reference field from parser into property

 vala/valagenieparser.vala |   16 ----------------
 vala/valaparser.vala      |   22 ----------------------
 vala/valaproperty.vala    |   31 +++++++++++++++++++++++++++++--
 3 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index e563580..b925bab 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -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;
        }
 
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 51bc7a0..3df315d 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -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);
        }
 
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 2a83295..ff95377 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -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.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]