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



commit 912abb185162740d00f5f35336b215e696e3e7b2
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 49806e0..73e15ea 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -664,6 +664,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 ed0960e..a41cc95 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]