[vala/wip/attributes: 5/12] codegen: Add get_ccode_prefix



commit 8c26b21279a98768b058c01dcd36b501f53666ed
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Jun 26 13:12:08 2011 +0200

    codegen: Add get_ccode_prefix

 codegen/valaccodebasemodule.vala |   38 +++++++++++++++++++++++++++++++++++++-
 codegen/valagtypemodule.vala     |    6 +++---
 2 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 356f752..e876b0b 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5578,6 +5578,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).header_filenames;
 	}
 
+	public static string get_ccode_prefix (Symbol sym) {
+		return get_ccode_attribute(sym).prefix;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -5969,10 +5973,20 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string prefix {
+		get {
+			if (_prefix == null) {
+				_prefix = get_default_prefix ();
+			}
+			return _prefix;
+		}
+	}
+
 	private string _name;
 	private string _const_name;
 	private string _type_name;
 	private List<string> _header_filenames;
+	private string _prefix;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -5990,6 +6004,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 					_header_filenames.add (header);
 				}
 			}
+			_prefix = attr.get_string ("cprefix");
 		}
 	}
 
@@ -6042,7 +6057,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 			} else if (sym is Signal) {
 				return Symbol.camel_case_to_lower_case (sym.name);
 			} else {
-				return "%s%s".printf (sym.parent_symbol.get_cprefix (), sym.name);
+				return "%s%s".printf (get_ccode_prefix (sym.parent_symbol), sym.name);
 			}
 		} else if (node is ObjectType) {
 			var type = (ObjectType) node;
@@ -6138,4 +6153,25 @@ public class Vala.CCodeAttribute : AttributeCache {
 			return headers;
 		}
 	}
+
+	private string get_default_prefix () {
+		if (sym is ObjectTypeSymbol) {
+			return name;
+		} else if (sym is Enum || sym is ErrorDomain) {
+			return "%s_".printf (((TypeSymbol) sym).get_upper_case_cname (null));
+		} else if (sym is Namespace) {
+			if (sym.name != null) {
+				var parent_prefix = "";
+				if (sym.parent_symbol != null) {
+					parent_prefix = CCodeBaseModule.get_ccode_prefix (sym.parent_symbol);
+				}
+				return "%s%s".printf (parent_prefix, sym.name);
+			} else {
+				return "";
+			}
+		} else if (sym.name != null) {
+			return sym.name;
+		}
+		return "";
+	}
 }
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 90bcf96..e2b0cd8 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -583,11 +583,11 @@ public class Vala.GTypeModule : GErrorModule {
 
 		if (is_gtypeinstance) {
 			if (is_fundamental) {
-				param_spec_struct = new CCodeStruct ( "_%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name));
+				param_spec_struct = new CCodeStruct ( "_%sParamSpec%s".printf(get_ccode_prefix (cl.parent_symbol), cl.name));
 				param_spec_struct.add_field ("GParamSpec", "parent_instance");
 				cfile.add_type_definition (param_spec_struct);
 
-				cfile.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (param_spec_struct.name), new CCodeVariableDeclarator ( "%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name))));
+				cfile.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (param_spec_struct.name), new CCodeVariableDeclarator ( "%sParamSpec%s".printf(get_ccode_prefix (cl.parent_symbol), cl.name))));
 
 
 				gvaluecollector_h_needed = true;
@@ -909,7 +909,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		push_function (function);
 
-		ccode.add_declaration ("%sParamSpec%s*".printf (cl.parent_symbol.get_cprefix (), cl.name), new CCodeVariableDeclarator ("spec"));
+		ccode.add_declaration ("%sParamSpec%s*".printf (get_ccode_prefix (cl.parent_symbol), cl.name), new CCodeVariableDeclarator ("spec"));
 
 		var subccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_is_a"));
 		subccall.add_argument (new CCodeIdentifier ("object_type"));



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