[vala/wip/attributes: 4/32] On-demand Delegate.has_target



commit 141e49a2c867b8c568854e7c5402e9ad766e1e0d
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jul 6 21:25:30 2011 +0200

    On-demand Delegate.has_target

 vala/valadelegate.vala      |   21 +++++++++++++++++----
 vala/valagenieparser.vala   |    4 ++--
 vala/valagirparser.vala     |    1 +
 vala/valaparser.vala        |    3 +--
 vala/valasignal.vala        |    1 -
 vapigen/valagidlparser.vala |    1 +
 6 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index ddaba92..6d22fba 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -42,7 +42,22 @@ public class Vala.Delegate : TypeSymbol {
 	 * The reference to the object instance will be appended to the end of
 	 * the argument list in the generated C code.
 	 */
-	public bool has_target { get; set; }
+	public bool has_target {
+		get {
+			if (_has_target == null) {
+				_has_target = get_attribute_bool ("CCode", "has_target", true);
+			}
+			return _has_target;
+		}
+		set {
+			_has_target = value;
+			if (value) {
+				remove_attribute_argument ("CCode", "has_target");
+			} else {
+				set_attribute_bool ("CCode", "has_target", false);
+			}
+		}
+	}
 
 	public DataType? sender_type { get; set; }
 
@@ -85,6 +100,7 @@ public class Vala.Delegate : TypeSymbol {
 	private string cname;
 
 	private DataType _return_type;
+	private bool? _has_target;
 
 	/**
 	 * Creates a new delegate.
@@ -283,9 +299,6 @@ public class Vala.Delegate : TypeSymbol {
 		if (a.has_argument ("cname")) {
 			set_cname (a.get_string ("cname"));
 		}
-		if (a.has_argument ("has_target")) {
-			has_target = a.get_bool ("has_target");
-		}
 		if (a.has_argument ("instance_pos")) {
 			cinstance_parameter_position = a.get_double ("instance_pos");
 		}
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 0de741c..4f9c016 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -3683,8 +3683,8 @@ public class Vala.Genie.Parser : CodeVisitor {
 			d.access = get_access (sym.name);
 		}
 
-		if (!(ModifierFlags.STATIC in flags)) {
-			d.has_target = true;
+		if (ModifierFlags.STATIC in flags) {
+			d.has_target = false;
 		}
 		if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
 			d.external = true;
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 044f2d4..261d5a2 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2444,6 +2444,7 @@ public class Vala.GirParser : CodeVisitor {
 
 		if (element_name == "callback") {
 			s = new Delegate (name, return_type, current.source_reference);
+			((Delegate) s).has_target = false;
 		} else if (element_name == "constructor") {
 			if (name == "new") {
 				name = null;
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 60c7a60..6aedb92 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3374,8 +3374,7 @@ public class Vala.Parser : CodeVisitor {
 				// TODO enable warning in future releases
 				Report.warning (get_last_src (), "deprecated syntax, use [CCode (has_target = false)]");
 			}
-		} else {
-			d.has_target = true;
+			d.has_target = false;
 		}
 		if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
 			d.external = true;
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index ea4b767..ee0667e 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -126,7 +126,6 @@ public class Vala.Signal : Symbol, Lockable {
 		var actual_return_type = return_type.get_actual_type (sender_type, null, node_reference);
 
 		var generated_delegate = new Delegate (null, actual_return_type);
-		generated_delegate.has_target = true;
 		generated_delegate.access = SymbolAccessibility.PUBLIC;
 		generated_delegate.owner = scope;
 
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 92fdb04..55c414c 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -450,6 +450,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 		var cb = new Delegate (node.name, return_type, current_source_reference);
 		cb.access = SymbolAccessibility.PUBLIC;
+		cb.has_target = false;
 
 		bool check_has_target = true;
 		bool suppress_throws = false;



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