summaryrefslogtreecommitdiff
path: root/vala/valaproperty.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2018-04-19 16:58:20 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2018-04-19 17:41:10 +0200
commitd2d2e183d307441dc22b8ec11b5a3f6a783573f1 (patch)
tree4a40600989f84b873f1dbd2e5ae24a7e2792163c /vala/valaproperty.vala
parent3b8c0ba8dacbc6d6de0cd10eda949f4a1823b478 (diff)
downloadvala-d2d2e183d307441dc22b8ec11b5a3f6a783573f1.tar.gz
vala: Move creation of reference field from parser into property
Diffstat (limited to 'vala/valaproperty.vala')
-rw-r--r--vala/valaproperty.vala31
1 files changed, 29 insertions, 2 deletions
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.