[vala/wip/attributes: 44/119] gidlparser: Drop usage of set_cname



commit 9b78c1f39a70109ab259093eea7bd1431b0b9cbb
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 12:15:01 2011 +0200

    gidlparser: Drop usage of set_cname

 vapigen/valagidlparser.vala |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index babd7f3..31bf858 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -215,6 +215,20 @@ public class Vala.GIdlParser : CodeVisitor {
 	}
 
 	private void add_symbol_to_container (Symbol container, Symbol sym) {
+		if (sym is Method) {
+			var a = sym.get_attribute ("CCode");
+			if (a != null && a.has_argument ("cname")) {
+				var cname = a.get_string ("cname");
+				var default_cname = "%s%s".printf (container.get_lower_case_cprefix (), sym.name);
+				if (cname == default_cname) {
+					// same as default, remove the argument
+					a.args.remove ("cname");
+					if (a.args.size == 0) {
+						sym.attributes.remove (a);
+					}
+				}
+			}
+		}
 		if (container is Class) {
 			unowned Class cl = (Class) container;
 
@@ -1281,7 +1295,7 @@ public class Vala.GIdlParser : CodeVisitor {
 					return_type.value_owned = false;
 					var m = new Method ("to_string", return_type, current_source_reference);
 					m.access = SymbolAccessibility.PUBLIC;
-					m.set_cname (eval(nv[1]));
+					m.set_attribute_string ("CCode", "cname", eval(nv[1]));
 					en.add_method (m);
 				} else if (nv[0] == "experimental") {
 					if (eval (nv[1]) == "1") {
@@ -2045,13 +2059,13 @@ public class Vala.GIdlParser : CodeVisitor {
 		bool add_ellipsis = false;
 		bool suppress_throws = false;
 		string? error_types = null;
+		Symbol? container = null;
 
 		var attributes = get_attributes (symbol);
 		if (attributes != null) {
 			foreach (string attr in attributes) {
 				var nv = attr.split ("=", 2);
 				if (nv[0] == "name") {
-					m.set_cname (m.name);
 					m.name = eval (nv[1]);
 				} else if (nv[0] == "hidden") {
 					if (eval (nv[1]) == "1") {
@@ -2133,10 +2147,9 @@ public class Vala.GIdlParser : CodeVisitor {
 						m.coroutine = true;
 					}
 				} else if (nv[0] == "parent") {
-					Symbol container = get_container_from_name (eval (nv[1]));
+					container = get_container_from_name (eval (nv[1]));
 					var prefix = container.get_lower_case_cprefix ();
 					if (symbol.has_prefix (prefix)) {
-						m.set_cname (m.name);
 						m.name = symbol.substring (prefix.length);
 					}
 				} else if (nv[0] == "experimental") {
@@ -2151,7 +2164,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			}
 		}
 
-		m.set_cname (symbol);
+		m.set_attribute_string ("CCode", "cname", symbol);
 		
 		bool first = true;
 		Parameter last_param = null;
@@ -2681,7 +2694,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		field.access = SymbolAccessibility.PUBLIC;
 
 		if (field_name != node.name) {
-			field.set_cname (node.name);
+			field.set_attribute_string ("CCode", "cname", node.name);
 		}
 
 		if (deprecated) {
@@ -2817,7 +2830,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			foreach (string attr in attributes) {
 				var nv = attr.split ("=", 2);
 				if (nv[0] == "name") {
-					sig.set_cname (sig.name);
+					sig.set_attribute_string ("CCode", "cname", sig.name);
 					sig.name = eval (nv[1]);
 				} else if (nv[0] == "has_emitter" && eval (nv[1]) == "1") {
 					sig.has_emitter = true;



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