From: Rico Tzschichholz Date: Thu, 19 Apr 2018 14:58:20 +0000 (+0200) Subject: vala: Move creation of reference field from parser into property X-Git-Tag: 0.41.90~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2d2e183d307441dc22b8ec11b5a3f6a783573f1;p=thirdparty%2Fvala.git vala: Move creation of reference field from parser into property --- diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index e563580aa..b925babbc 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 51bc7a05f..3df315d1f 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 2a83295fb..ff953777c 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.