[vala/wip/attributes: 46/100] gidlparser: Drop usage of CodeNode.get_lower_case_cprefix



commit f5679ceebe1af36f4a2297ad630da13d8de2fa29
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 13:07:17 2011 +0200

    gidlparser: Drop usage of CodeNode.get_lower_case_cprefix

 vapigen/valagidlparser.vala |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 17b2e01..c2ae4fb 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -189,7 +189,7 @@ public class Vala.GIdlParser : CodeVisitor {
 	}
 
 	private string fix_const_name (string const_name, Symbol container) {
-		var pref = container.get_lower_case_cprefix ().up ();
+		var pref = get_lower_case_cprefix (container).up ();
 		if (const_name.has_prefix (pref)) {
 			return const_name.substring (pref.length);
 		}
@@ -202,12 +202,41 @@ public class Vala.GIdlParser : CodeVisitor {
 			return cname;
 		}
 		if (sym is Method) {
-			return "%s%s".printf (sym.parent_symbol.get_lower_case_cprefix (), sym.name);
+			return "%s%s".printf (get_lower_case_cprefix (sym.parent_symbol), sym.name);
 		} else {
 			return "%s%s".printf (sym.parent_symbol.get_cprefix (), sym.name);
 		}
 	}
 
+	private string get_lower_case_cprefix (Symbol sym) {
+		if (sym.name == null) {
+			return "";
+		}
+		string cprefix;
+		if (sym is Namespace) {
+			cprefix = sym.get_attribute_string ("CCode", "lower_case_cprefix");
+		} else {
+			cprefix = sym.get_attribute_string ("CCode", "cprefix");
+		}
+		if (cprefix != null) {
+			return cprefix;
+		}
+
+		var lower_case_csuffix = Symbol.camel_case_to_lower_case (sym.name);
+		if (sym is ObjectTypeSymbol) {
+			// remove underscores in some cases to avoid conflicts of type macros
+			if (lower_case_csuffix.has_prefix ("type_")) {
+				lower_case_csuffix = "type" + lower_case_csuffix.substring ("type_".length);
+			} else if (lower_case_csuffix.has_prefix ("is_")) {
+				lower_case_csuffix = "is" + lower_case_csuffix.substring ("is_".length);
+			}
+			if (lower_case_csuffix.has_suffix ("_class")) {
+				lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.length - "_class".length) + "class";
+			}
+		}
+		return "%s%s_".printf (get_lower_case_cprefix (sym.parent_symbol), lower_case_csuffix);
+	}
+
 	private string[] get_attributes_for_node (IdlNode node) {
 		string name;
 
@@ -231,7 +260,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			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);
+				var default_cname = "%s%s".printf (get_lower_case_cprefix (container), sym.name);
 				if (cname == default_cname) {
 					// same as default, remove the argument
 					a.args.remove ("cname");
@@ -2160,7 +2189,7 @@ public class Vala.GIdlParser : CodeVisitor {
 					}
 				} else if (nv[0] == "parent") {
 					container = get_container_from_name (eval (nv[1]));
-					var prefix = container.get_lower_case_cprefix ();
+					var prefix = get_lower_case_cprefix (container);
 					if (symbol.has_prefix (prefix)) {
 						m.name = symbol.substring (prefix.length);
 					}
@@ -2429,7 +2458,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
 	private Method parse_virtual (IdlNodeVFunc v, IdlNodeFunction? func, bool is_interface = false) {
 		weak IdlNode node = (IdlNode) v;
-		string symbol = "%s%s".printf (current_data_type.get_lower_case_cprefix(), node.name);
+		string symbol = "%s%s".printf (get_lower_case_cprefix (current_data_type), node.name);
 
 		if (func != null) {
 			symbol = func.symbol;



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