[vala/wip/attributes: 10/27] codegen: Add get_ccode_lower_case_suffix



commit 3aeffc5fb24710bde95b00c2a7390d064a027258
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Jun 26 13:54:02 2011 +0200

    codegen: Add get_ccode_lower_case_suffix

 codegen/valaccodebasemodule.vala |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2a3db70..833d144 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5579,6 +5579,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).lower_case_prefix;
 	}
 
+	public static string get_ccode_lower_case_suffix (Symbol sym) {
+		return get_ccode_attribute(sym).lower_case_suffix;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -5987,12 +5991,22 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string get_lower_case_suffix {
+		get {
+			if (_lower_case_suffix == null) {
+				_lower_case_suffix = get_default_lower_case_suffix ();
+			}
+			return _lower_case_suffix;
+		}
+	}
+
 	private string _name;
 	private string _const_name;
 	private string _type_name;
 	private List<string> _header_filenames;
 	private string _prefix;
 	private string _lower_case_prefix;
+	private string _lower_case_suffix;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -6197,4 +6211,23 @@ public class Vala.CCodeAttribute : AttributeCache {
 			return "%s_".printf (sym.get_lower_case_cname (null));
 		}
 	}
+
+	private string get_default_lower_case_suffix () {
+		if (sym is ObjectTypeSymbol) {
+			var csuffix = Symbol.camel_case_to_lower_case (sym.name);
+
+			// remove underscores in some cases to avoid conflicts of type macros
+			if (csuffix.has_prefix ("type_")) {
+				csuffix = "type" + csuffix.substring ("type_".length);
+			} else if (csuffix.has_prefix ("is_")) {
+				csuffix = "is" + csuffix.substring ("is_".length);
+			}
+			if (csuffix.has_suffix ("_class")) {
+				csuffix = csuffix.substring (0, csuffix.length - "_class".length) + "class";
+			}
+			return csuffix;
+		} else {
+			return Symbol.camel_case_to_lower_case (sym.name);
+		}
+	}
 }



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