[vala/switch-to-gir: 37/51] Allow setting cname of ErrorCode.



commit 6486ee96c616f7717553513213b6630c180c4611
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Dec 30 13:20:25 2010 +0100

    Allow setting cname of ErrorCode.

 vala/valacodewriter.vala |    4 ++++
 vala/valaerrorcode.vala  |   31 +++++++++++++++++++++++++++++--
 vala/valagirparser.vala  |    1 +
 3 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index b6e31c2..847852e 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -677,6 +677,10 @@ public class Vala.CodeWriter : CodeVisitor {
 	}
 
 	public override void visit_error_code (ErrorCode ecode) {
+		if (ecode.get_cname () != ecode.get_default_cname ()) {
+			write_indent ();
+			write_string ("[CCode (cname = \"%s\")]".printf (ecode.get_cname ()));
+		}
 		write_indent ();
 		write_identifier (ecode.name);
 		write_string (",");
diff --git a/vala/valaerrorcode.vala b/vala/valaerrorcode.vala
index 4102fed..eace48c 100644
--- a/vala/valaerrorcode.vala
+++ b/vala/valaerrorcode.vala
@@ -67,16 +67,41 @@ public class Vala.ErrorCode : TypeSymbol {
 
 	public override string get_cname (bool const_type = false) {
 		if (cname == null) {
-			var edomain = (ErrorDomain) parent_symbol;
-			cname = "%s%s".printf (edomain.get_cprefix (), name);
+			cname = get_default_cname ();
 		}
 		return cname;
 	}
 
+	public string get_default_cname () {
+		var edomain = (ErrorDomain) parent_symbol;
+		return "%s%s".printf (edomain.get_cprefix (), name);
+	}
+
+	public void set_cname (string value) {
+		this.cname = value;
+	}
+
 	public override string? get_lower_case_cname (string? infix) {
 		return get_cname ().down ();
 	}
 
+	private void process_ccode_attribute (Attribute a) {
+		if (a.has_argument ("cname")) {
+			cname = a.get_string ("cname");
+		}
+	}
+
+	/**
+	 * Process all associated attributes.
+	 */
+	public void process_attributes () {
+		foreach (Attribute a in attributes) {
+			if (a.name == "CCode") {
+				process_ccode_attribute (a);
+			}
+		}
+	}
+
 	public override bool check (CodeContext context) {
 		if (checked) {
 			return !error;
@@ -84,6 +109,8 @@ public class Vala.ErrorCode : TypeSymbol {
 
 		checked = true;
 
+		process_attributes ();
+
 		if (value != null) {
 			value.check (context);
 		}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 0a8b91b..e93b73d 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1708,6 +1708,7 @@ public class Vala.GirParser : CodeVisitor {
 		} else {
 			ec = new ErrorCode (name);
 		}
+		ec.set_cname (reader.get_attribute ("c:identifier"));
 
 		next ();
 		end_element ("member");



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