[vala/switch-to-gir: 37/47] Allow setting cname of ErrorCode.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir: 37/47] Allow setting cname of ErrorCode.
- Date: Thu, 6 Jan 2011 11:52:40 +0000 (UTC)
commit b7bf175826aaa05c0feb73ed9012c1c3860c3ba9
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 62f1d07..8b4bc93 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 99853f4..7779030 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]