[vala/wip/attributes: 86/100] codewriter: Get rid of all C bits



commit 8320b0dbd851a65e9816cabe6f0cefca3e723931
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Jun 30 13:04:47 2011 +0200

    codewriter: Get rid of all C bits

 vala/valacodewriter.vala |  410 ++-------------------------------------------
 1 files changed, 19 insertions(+), 391 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 370a62b..4de4b92 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -138,24 +138,6 @@ public class Vala.CodeWriter : CodeVisitor {
 			return;
 		}
 
-		write_indent ();
-		write_string ("[CCode (cprefix = \"%s\", lower_case_cprefix = \"%s\"".printf (ns.get_cprefix (), ns.get_lower_case_cprefix ()));
-
-		if (ns.source_reference != null && ns.parent_symbol == context.root) {
-			// Set GIR information only for the main namespace of the file.
-			if (ns.source_reference.file.gir_namespace != null) {
-				write_string (", ");
-				write_string ("gir_namespace = \"%s\"".printf (ns.source_reference.file.gir_namespace));
-			}
-			if (ns.source_reference.file.gir_version != null) {
-				write_string(", ");
-				write_string ("gir_version = \"%s\"".printf (ns.source_reference.file.gir_version));
-			}
-		}
-
-		write_string (")]");
-		write_newline ();
-
 		write_attributes (ns);
 
 		write_indent ();
@@ -256,55 +238,6 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (cl);
 		emit_experimental_attribute (cl);
 
-		write_indent ();
-		
-		write_string ("[CCode (");
-
-		if (cl.is_reference_counting () && type != CodeWriterType.FAST) {
-			if (cl.base_class == null || cl.base_class.get_ref_function () == null || cl.base_class.get_ref_function () != cl.get_ref_function ()) {
-				write_string ("ref_function = \"%s\", ".printf (cl.get_ref_function ()));
-				if (cl.ref_function_void) {
-					write_string ("ref_function_void = true, ");
-				}
-			}
-			if (cl.base_class == null || cl.base_class.get_unref_function () == null || cl.base_class.get_unref_function () != cl.get_unref_function ()) {
-				write_string ("unref_function = \"%s\", ".printf (cl.get_unref_function ()));
-			}
-		} else {
-			if (cl.get_dup_function () != null) {
-				write_string ("copy_function = \"%s\", ".printf (cl.get_dup_function ()));
-			}
-			if (cl.get_free_function () != cl.get_default_free_function ()) {
-				write_string ("free_function = \"%s\", ".printf (cl.get_free_function ()));
-			}
-		}
-
-		if (cl.get_cname () != cl.get_default_cname ()) {
-			write_string ("cname = \"%s\", ".printf (cl.get_cname ()));
-		}
-		if (cl.const_cname != null) {
-			write_string ("const_cname = \"%s\", ".printf (cl.const_cname));
-		}
-
-		if (cl.get_lower_case_cprefix () != "%s_".printf (cl.get_lower_case_cname (null))) {
-			write_string ("cprefix = \"%s\", ".printf (cl.get_lower_case_cprefix ()));
-		}
-
-		if (cl.type_check_function != null) {
-			write_string ("type_check_function = \"%s\", ".printf (cl.type_check_function ));
-		}
-
-		if (cl.get_type_id () != cl.get_default_type_id ()) {
-			write_string ("type_id = \"%s\", ".printf (cl.get_type_id ()));
-		}
-
-		if (cl.get_param_spec_function () != cl.get_default_param_spec_function ()) {
-			write_string ("param_spec_function = \"%s\", ".printf (cl.get_param_spec_function ()));
-		}
-
-		write_string ("cheader_filename = \"%s\")]".printf (get_cheaders(cl)));
-		write_newline ();
-
 		write_attributes (cl);
 		
 		write_indent ();
@@ -422,29 +355,6 @@ public class Vala.CodeWriter : CodeVisitor {
 
 		write_indent ();
 
-		write_string ("[CCode (");
-
-		if (st.get_cname () != st.get_default_cname ()) {
-			write_string ("cname = \"%s\", ".printf (st.get_cname ()));
-		}
-
-		if (!st.has_type_id) {
-			write_string ("has_type_id = false, ");
-		} else if (!st.is_simple_type () && st.get_type_id () != "G_TYPE_POINTER") {
-			write_string ("type_id = \"%s\", ".printf (st.get_type_id ()));
-		}
-
-		if (!st.has_copy_function) {
-			write_string ("has_copy_function = false, ");
-		}
-
-		if (!st.has_destroy_function) {
-			write_string ("has_destroy_function = false, ");
-		}
-
-		write_string ("cheader_filename = \"%s\")]".printf (get_cheaders(st)));
-		write_newline ();
-
 		if (st.is_simple_type ()) {
 			write_indent ();
 			write_string ("[SimpleType]");
@@ -504,19 +414,6 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (iface);
 		emit_experimental_attribute (iface);
 
-		write_indent ();
-
-		write_string ("[CCode (cheader_filename = \"%s\"".printf (get_cheaders(iface)));
-		if (iface.get_lower_case_csuffix () != iface.get_default_lower_case_csuffix ())
-			write_string (", lower_case_csuffix = \"%s\"".printf (iface.get_lower_case_csuffix ()));
-		if (iface.get_type_cname () != iface.get_default_type_cname ())
-			write_string (", type_cname = \"%s\"".printf (iface.get_type_cname ()));
-		if (iface.get_type_id () != iface.get_default_type_id ())
-			write_string (", type_id = \"%s\"".printf (iface.get_type_id ()));
-
-		write_string (")]");
-		write_newline ();
-
 		write_attributes (iface);
 
 		write_indent ();
@@ -585,25 +482,6 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (en);
 		emit_experimental_attribute (en);
 
-		write_indent ();
-
-		write_string ("[CCode (cprefix = \"%s\", ".printf (en.get_cprefix ()));
-
-		if (!en.has_type_id) {
-			write_string ("has_type_id = false, ");
-		}
-
-		if (en.get_cname () != en.get_default_cname ()) {
-			write_string ("cname = \"%s\", ".printf (en.get_cname ()));
-		}
-
-		write_string ("cheader_filename = \"%s\")]".printf (get_cheaders(en)));
-
-		if (en.is_flags) {
-			write_indent ();
-			write_string ("[Flags]");
-		}
-
 		write_attributes (en);
 
 		write_indent ();
@@ -621,10 +499,8 @@ public class Vala.CodeWriter : CodeVisitor {
 				write_newline ();
 			}
 
-			if (ev.get_cname () != ev.get_default_cname ()) {
-				write_indent ();
-				write_string ("[CCode (cname = \"%s\")]".printf (ev.get_cname ()));
-			}
+			write_attributes (ev);
+
 			write_indent ();
 			write_identifier (ev.name);
 
@@ -666,10 +542,6 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (edomain);
 		emit_experimental_attribute (edomain);
 
-		write_indent ();
-
-		write_string ("[CCode (cprefix = \"%s\", cheader_filename = \"%s\")]".printf (edomain.get_cprefix (), get_cheaders(edomain)));
-
 		write_attributes (edomain);
 
 		write_indent ();
@@ -687,10 +559,8 @@ public class Vala.CodeWriter : CodeVisitor {
 				write_newline ();
 			}
 
-			if (ecode.get_cname () != ecode.get_default_cname ()) {
-				write_indent ();
-				write_string ("[CCode (cname = \"%s\")]".printf (ecode.get_cname ()));
-			}
+			write_attributes (ecode);
+
 			write_indent ();
 			write_identifier (ecode.name);
 		}
@@ -724,26 +594,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (c);
 		emit_experimental_attribute (c);
 
-		bool custom_cname = (c.get_cname () != c.get_default_cname ());
-		bool custom_cheaders = (c.parent_symbol is Namespace);
-		if (custom_cname || custom_cheaders) {
-			write_indent ();
-			write_string ("[CCode (");
-
-			if (custom_cname) {
-				write_string ("cname = \"%s\"".printf (c.get_cname ()));
-			}
-
-			if (custom_cheaders) {
-				if (custom_cname) {
-					write_string (", ");
-				}
-
-				write_string ("cheader_filename = \"%s\"".printf (get_cheaders(c)));
-			}
-
-			write_string (")]");
-		}
+		write_attributes (c);
 
 		write_indent ();
 		write_accessibility (c);
@@ -773,75 +624,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (f);
 		emit_experimental_attribute (f);
 
-		bool custom_cname = (f.get_cname () != f.get_default_cname ());
-		bool custom_ctype = (f.get_ctype () != null);
-		bool custom_cheaders = (f.parent_symbol is Namespace);
-		bool custom_array_length_cname = (f.get_array_length_cname () != null);
-		bool custom_array_length_type = (f.array_length_type != null);
-		if (custom_cname || custom_ctype || custom_cheaders || custom_array_length_cname || custom_array_length_type || (f.no_array_length && f.variable_type is ArrayType)) {
-			write_indent ();
-			write_string ("[CCode (");
-
-			if (custom_cname) {
-				write_string ("cname = \"%s\"".printf (f.get_cname ()));
-			}
-
-			if (custom_ctype) {
-				if (custom_cname) {
-					write_string (", ");
-				}
-
-				write_string ("type = \"%s\"".printf (f.get_ctype ()));
-			}
-
-			if (custom_cheaders) {
-				if (custom_cname || custom_ctype) {
-					write_string (", ");
-				}
-
-				write_string ("cheader_filename = \"%s\"".printf (get_cheaders(f)));
-			}
-
-			if (f.variable_type is ArrayType) {
-				if (f.no_array_length) {
-					if (custom_cname || custom_ctype || custom_cheaders) {
-						write_string (", ");
-					}
-
-					write_string ("array_length = false");
-
-					if (f.array_null_terminated) {
-						write_string (", array_null_terminated = true");
-					}
-				} else {
-					if (custom_array_length_cname) {
-						if (custom_cname || custom_ctype || custom_cheaders) {
-							write_string (", ");
-						}
-
-						write_string ("array_length_cname = \"%s\"".printf (f.get_array_length_cname ()));
-					}
-
-					if (custom_array_length_type) {
-						if (custom_cname || custom_ctype || custom_cheaders || custom_array_length_cname) {
-							write_string (", ");
-						}
-
-						write_string ("array_length_type = \"%s\"".printf (f.array_length_type));
-					}
-				}
-			} else if (f.variable_type is DelegateType) {
-				if (f.no_delegate_target) {
-					if (custom_cname || custom_ctype || custom_cheaders) {
-						write_string (", ");
-					}
-
-					write_string ("delegate_target = false");
-				}
-			}
-
-			write_string (")]");
-		}
+		write_attributes (f);
 
 		write_indent ();
 		write_accessibility (f);
@@ -881,11 +664,6 @@ public class Vala.CodeWriter : CodeVisitor {
 		}
 	}
 
-	// equality comparison with 3 digit precision
-	private bool float_equal (double d1, double d2) {
-		return ((int) (d1 * 1000)) == ((int) (d2 * 1000));
-	}
-
 	private void write_params (List<Parameter> params) {
 		write_string ("(");
 
@@ -900,46 +678,7 @@ public class Vala.CodeWriter : CodeVisitor {
 				continue;
 			}
 			
-
-			var ccode_params = new StringBuilder ();
-			var separator = "";
-
-			if (!float_equal (param.cparameter_position, i)) {
-				ccode_params.append_printf ("%spos = %g", separator, param.cparameter_position);
-				separator = ", ";
-			}
-			if (param.ctype != null) {
-				ccode_params.append_printf ("%stype = \"%s\"", separator, param.ctype);
-				separator = ", ";
-			}
-			if (param.no_array_length && param.variable_type is ArrayType) {
-				ccode_params.append_printf ("%sarray_length = false", separator);
-				separator = ", ";
-			}
-			if (param.array_null_terminated && param.variable_type is ArrayType) {
-				ccode_params.append_printf ("%sarray_null_terminated = true", separator);
-				separator = ", ";
-			}
-			if (param.array_length_type != null && param.variable_type is ArrayType) {
-				ccode_params.append_printf ("%sarray_length_type = \"%s\"", separator, param.array_length_type);
-				separator = ", ";
-			}
-			if (param.get_array_length_cname () != null && param.variable_type is ArrayType) {
-				ccode_params.append_printf ("%sarray_length_cname = \"%s\"", separator, param.get_array_length_cname ());
-				separator = ", ";
-			}
-			if (!float_equal (param.carray_length_parameter_position, i + 0.1)) {
-				ccode_params.append_printf ("%sarray_length_pos = %g", separator, param.carray_length_parameter_position);
-				separator = ", ";
-			}
-			if (!float_equal (param.cdelegate_target_parameter_position, i + 0.1)) {
-				ccode_params.append_printf ("%sdelegate_target_pos = %g", separator, param.cdelegate_target_parameter_position);
-				separator = ", ";
-			}
-
-			if (ccode_params.len > 0) {
-				write_string ("[CCode (%s)] ".printf (ccode_params.str));
-			}
+			write_attributes (param);
 
 			if (param.params_array) {
 				write_string ("params ");
@@ -988,19 +727,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (cb);
 		emit_experimental_attribute (cb);
 
-		write_indent ();
-
-		write_string ("[CCode (cheader_filename = \"%s\"".printf (get_cheaders(cb)));
-
-		if (!cb.has_target) {
-			write_string (", has_target = false");
-		} else if (!float_equal (cb.cinstance_parameter_position, -2)) {
-			write_string (", instance_pos = %g".printf (cb.cinstance_parameter_position));
-		} else if (cb.array_length_type != null) {
-			write_string (", array_length_type = \"%s\"".printf (cb.array_length_type));
-		}
-
-		write_string (")]");
+		write_attributes (cb);
 
 		write_indent ();
 
@@ -1101,81 +828,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (m);
 		emit_experimental_attribute (m);
 
-		var ccode_params = new StringBuilder ();
-		var separator = "";
-
-		if (m.get_cname () != m.get_default_cname ()) {
-			ccode_params.append_printf ("%scname = \"%s\"", separator, m.get_cname ());
-			separator = ", ";
-		}
-		if (m.parent_symbol is Namespace || get_cheaders (m) != get_cheaders (m.parent_symbol)) {
-			ccode_params.append_printf ("%scheader_filename = \"%s\"", separator, get_cheaders(m));
-			separator = ", ";
-		}
-		if (!float_equal (m.cinstance_parameter_position, 0)) {
-			ccode_params.append_printf ("%sinstance_pos = %g", separator, m.cinstance_parameter_position);
-			separator = ", ";
-		}
-		if (m.no_array_length && m.return_type is ArrayType) {
-			ccode_params.append_printf ("%sarray_length = false", separator);
-			separator = ", ";
-		}
-		if (!float_equal (m.carray_length_parameter_position, -3)) {
-			ccode_params.append_printf ("%sarray_length_pos = %g", separator, m.carray_length_parameter_position);
-			separator = ", ";
-		}
-		if (m.array_null_terminated && m.return_type is ArrayType) {
-			ccode_params.append_printf ("%sarray_null_terminated = true", separator);
-			separator = ", ";
-		}
-		if (m.array_length_type != null && m.return_type is ArrayType) {
-			ccode_params.append_printf ("%sarray_length_type = \"%s\"", separator, m.array_length_type);
-			separator = ", ";
-		}
-		if (!float_equal (m.cdelegate_target_parameter_position, -3)) {
-			ccode_params.append_printf ("%sdelegate_target_pos = %g", separator, m.cdelegate_target_parameter_position);
-			separator = ", ";
-		}
-		if (m.vfunc_name != m.name) {
-			ccode_params.append_printf ("%svfunc_name = \"%s\"", separator, m.vfunc_name);
-			separator = ", ";
-		}
-		if (m.coroutine && m.get_finish_cname () != m.get_default_finish_cname ()) {
-			ccode_params.append_printf ("%sfinish_name = \"%s\"", separator, m.get_finish_cname ());
-			separator = ", ";
-		}
-		if (m.sentinel != m.DEFAULT_SENTINEL) {
-			ccode_params.append_printf ("%ssentinel = \"%s\"", separator, m.sentinel);
-			separator = ", ";
-		}
-		if (m.custom_return_type_cname != null) {
-			ccode_params.append_printf ("%stype = \"%s\"", separator, m.custom_return_type_cname);
-			separator = ", ";
-		}
-		if (m.simple_generics) {
-			ccode_params.append_printf ("%ssimple_generics = true", separator);
-			separator = ", ";
-		}
-
-		var cm = m as CreationMethod;
-		if (cm != null) {
-			if (!m.has_new_function) {
-				ccode_params.append_printf ("%shas_new_function = false", separator);
-				separator = ", ";
-			}
-			if (!m.has_construct_function) {
-				ccode_params.append_printf ("%shas_construct_function = false", separator);
-				separator = ", ";
-			} else if (m.name == ".new" && m.get_real_cname () != cm.get_default_construct_function ()) {
-				ccode_params.append_printf ("%sconstruct_function = \"%s\"", separator, m.get_real_cname ());
-				separator = ", ";
-			}
-		}
-
-		if (ccode_params.len > 0) {
-			write_indent ();
-			write_string ("[CCode (%s)]".printf (ccode_params.str));
-		}
+		write_attributes (m);
 		
 		write_indent ();
 		write_accessibility (m);
@@ -1259,20 +912,12 @@ public class Vala.CodeWriter : CodeVisitor {
 		emit_deprecated_attribute (prop);
 		emit_experimental_attribute (prop);
 
-		if (prop.get_attribute ("NoAccessorMethod")) {
+		if (prop.get_attribute ("NoAccessorMethod") != null) {
 			write_indent ();
 			write_string ("[NoAccessorMethod]");
 		}
-		if (prop.property_type is ArrayType && prop.no_array_length) {
-			write_indent ();
-			write_string ("[CCode (array_length = false");
-
-			if (prop.array_null_terminated) {
-				write_string (", array_null_terminated = true");
-			}
 
-			write_string (")]");
-		}
+		write_attributes (prop);
 
 		write_indent ();
 		write_accessibility (prop);
@@ -1293,17 +938,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		write_identifier (prop.name);
 		write_string (" {");
 		if (prop.get_accessor != null) {
-			var ccode_params = new StringBuilder ();
-			var separator = "";
-
-			if (prop.get_accessor.get_cname () != prop.get_accessor.get_default_cname ()) {
-				ccode_params.append_printf ("%scname = \"%s\"", separator, prop.get_accessor.get_cname ());
-				separator = ", ";
-			}
-			if (ccode_params.len > 0) {
-				write_indent ();
-				write_string ("[CCode (%s)]".printf (ccode_params.str));
-			}
+			write_attributes (prop.get_accessor);
 
 			write_property_accessor_accessibility (prop.get_accessor);
 
@@ -1315,17 +950,7 @@ public class Vala.CodeWriter : CodeVisitor {
 			write_code_block (prop.get_accessor.body);
 		}
 		if (prop.set_accessor != null) {
-			var ccode_params = new StringBuilder ();
-			var separator = "";
-
-			if (prop.set_accessor.get_cname () != prop.set_accessor.get_default_cname ()) {
-				ccode_params.append_printf ("%scname = \"%s\"", separator, prop.set_accessor.get_cname ());
-				separator = ", ";
-			}
-			if (ccode_params.len > 0) {
-				write_indent ();
-				write_string ("[CCode (%s)]".printf (ccode_params.str));
-			}
+			write_attributes (prop.set_accessor);
 
 			write_property_accessor_accessibility (prop.set_accessor);
 
@@ -2073,7 +1698,11 @@ public class Vala.CodeWriter : CodeVisitor {
 
 					string separator = "";
 					foreach (string arg_name in keys) {
-						stream.printf ("%s%s = %s", separator, arg_name, attr.args.get (arg_name));
+						if (arg_name == "cheader_filename") {
+							stream.printf ("%scheader_filename = \"%s\"", separator, get_cheaders ((Symbol) node));
+						} else {
+							stream.printf ("%s%s = %s", separator, arg_name, attr.args.get (arg_name));
+						}
 						separator = ", ";
 					}
 
@@ -2086,8 +1715,7 @@ public class Vala.CodeWriter : CodeVisitor {
 	}
 
 	private bool filter_attribute (Attribute attr) {
-		if (attr.name == "CCode"
-		    || attr.name == "Compact" || attr.name == "Immutable"
+		if (attr.name == "Compact" || attr.name == "Immutable"
 		    || attr.name == "SimpleType" || attr.name == "IntegerType" || attr.name == "FloatingType"
 		    || attr.name == "Flags") {
 			return true;



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