[vala] Move add_symbol_declaration out of CCodeDeclarationSpace



commit ceb6c3877b526049ecc423ea7b12f7b545ce1f82
Author: Jürg Billeter <j bitron ch>
Date:   Fri Aug 13 13:08:36 2010 +0200

    Move add_symbol_declaration out of CCodeDeclarationSpace

 codegen/valaccodebasemodule.vala       |   27 ++++++++++++++++++++++-----
 codegen/valaccodedeclarationspace.vala |   17 -----------------
 codegen/valaccodedelegatemodule.vala   |    2 +-
 codegen/valaccodemethodmodule.vala     |    2 +-
 codegen/valaccodestructmodule.vala     |    2 +-
 codegen/valadbusclientmodule.vala      |    2 +-
 codegen/valadovabasemodule.vala        |   25 +++++++++++++++++++++----
 codegen/valadovadelegatemodule.vala    |    2 +-
 codegen/valadovaobjectmodule.vala      |   20 ++++++++++----------
 codegen/valadovastructmodule.vala      |    2 +-
 codegen/valadovavaluemodule.vala       |    2 +-
 codegen/valagasyncmodule.vala          |    2 +-
 codegen/valagdbusclientmodule.vala     |    2 +-
 codegen/valagdbusservermodule.vala     |    2 +-
 codegen/valagerrormodule.vala          |    2 +-
 codegen/valagtypemodule.vala           |    6 +++---
 16 files changed, 67 insertions(+), 50 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2b9a9ab..ef145a9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -540,6 +540,23 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
+	public bool add_symbol_declaration (CCodeDeclarationSpace decl_space, Symbol sym, string name) {
+		if (decl_space.add_declaration (name)) {
+			return true;
+		}
+		if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
+			// add appropriate include file
+			foreach (string header_filename in sym.get_cheader_filenames ()) {
+				decl_space.add_include (header_filename, !sym.external_package);
+			}
+			// declaration complete
+			return true;
+		} else {
+			// require declaration
+			return false;
+		}
+	}
+
 	public CCodeIdentifier get_value_setter_function (DataType type_reference) {
 		var array_type = type_reference as ArrayType;
 		if (type_reference.data_type != null) {
@@ -736,7 +753,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public virtual bool generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (en, en.get_cname ())) {
+		if (add_symbol_declaration (decl_space, en, en.get_cname ())) {
 			return false;
 		}
 
@@ -839,7 +856,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public void generate_constant_declaration (Constant c, CCodeDeclarationSpace decl_space, bool definition = false) {
-		if (decl_space.add_symbol_declaration (c, c.get_cname ())) {
+		if (add_symbol_declaration (decl_space, c, c.get_cname ())) {
 			return;
 		}
 
@@ -890,7 +907,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public void generate_field_declaration (Field f, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (f, f.get_cname ())) {
+		if (add_symbol_declaration (decl_space, f, f.get_cname ())) {
 			return;
 		}
 
@@ -1339,7 +1356,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public void generate_property_accessor_declaration (PropertyAccessor acc, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (acc, acc.get_cname ())) {
+		if (add_symbol_declaration (decl_space, acc, acc.get_cname ())) {
 			return;
 		}
 
@@ -4173,7 +4190,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public virtual void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, cl.get_cname ())) {
+		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 	}
diff --git a/codegen/valaccodedeclarationspace.vala b/codegen/valaccodedeclarationspace.vala
index 4ff7640..73b2ff8 100644
--- a/codegen/valaccodedeclarationspace.vala
+++ b/codegen/valaccodedeclarationspace.vala
@@ -40,23 +40,6 @@ public class Vala.CCodeDeclarationSpace {
 		return false;
 	}
 
-	public bool add_symbol_declaration (Symbol sym, string name) {
-		if (add_declaration (name)) {
-			return true;
-		}
-		if (sym.external_package || (!is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
-			// add appropriate include file
-			foreach (string header_filename in sym.get_cheader_filenames ()) {
-				add_include (header_filename, !sym.external_package);
-			}
-			// declaration complete
-			return true;
-		} else {
-			// require declaration
-			return false;
-		}
-	}
-
 	public void add_include (string filename, bool local = false) {
 		if (!(filename in includes)) {
 			include_directives.append (new CCodeIncludeDirective (filename, local));
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index e18b1fb..3f7b285 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -28,7 +28,7 @@
  */
 public class Vala.CCodeDelegateModule : CCodeArrayModule {
 	public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (d, d.get_cname ())) {
+		if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 0df172f..bd47195 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -162,7 +162,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		if (m.is_async_callback) {
 			return;
 		}
-		if (decl_space.add_symbol_declaration (m, m.get_cname ())) {
+		if (add_symbol_declaration (decl_space, m, m.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 84697a5..6c4b7e9 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -26,7 +26,7 @@ using GLib;
 
 public class Vala.CCodeStructModule : CCodeBaseModule {
 	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (st, st.get_cname ())) {
+		if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 3d8703a..8194336 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -1039,7 +1039,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		string lower_cname = iface.get_lower_case_cprefix () + "dbus_proxy";
 
-		if (decl_space.add_symbol_declaration (iface, lower_cname + "_new")) {
+		if (add_symbol_declaration (decl_space, iface, lower_cname + "_new")) {
 			return;
 		}
 
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 5feabfd..1b38680 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -375,6 +375,23 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 	}
 
+	public bool add_symbol_declaration (CCodeDeclarationSpace decl_space, Symbol sym, string name) {
+		if (decl_space.add_declaration (name)) {
+			return true;
+		}
+		if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
+			// add appropriate include file
+			foreach (string header_filename in sym.get_cheader_filenames ()) {
+				decl_space.add_include (header_filename, !sym.external_package);
+			}
+			// declaration complete
+			return true;
+		} else {
+			// require declaration
+			return false;
+		}
+	}
+
 	public override void visit_source_file (SourceFile source_file) {
 		if (csource_filename == null) {
 			csource_filename = source_file.get_csource_filename ();
@@ -415,7 +432,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public void generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (en, en.get_cname ())) {
+		if (add_symbol_declaration (decl_space, en, en.get_cname ())) {
 			return;
 		}
 
@@ -445,7 +462,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public void generate_constant_declaration (Constant c, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (c, c.get_cname ())) {
+		if (add_symbol_declaration (decl_space, c, c.get_cname ())) {
 			return;
 		}
 
@@ -478,7 +495,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public void generate_field_declaration (Field f, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (f, f.get_cname ())) {
+		if (add_symbol_declaration (decl_space, f, f.get_cname ())) {
 			return;
 		}
 
@@ -1768,7 +1785,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public virtual void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, cl.get_cname ())) {
+		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 	}
diff --git a/codegen/valadovadelegatemodule.vala b/codegen/valadovadelegatemodule.vala
index 3d4672f..0b41a2a 100644
--- a/codegen/valadovadelegatemodule.vala
+++ b/codegen/valadovadelegatemodule.vala
@@ -26,7 +26,7 @@
  */
 public class Vala.DovaDelegateModule : DovaValueModule {
 	public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (d, d.get_cname ())) {
+		if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index c50a209..a32529b 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -22,7 +22,7 @@
 
 public class Vala.DovaObjectModule : DovaArrayModule {
 	public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, cl.get_cname ())) {
+		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 
@@ -137,7 +137,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	void generate_class_private_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, cl.get_cname () + "Private")) {
+		if (add_symbol_declaration (decl_space, cl, cl.get_cname () + "Private")) {
 			return;
 		}
 
@@ -306,7 +306,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public void declare_set_value_copy_function (CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (type_class, "dova_type_set_value_copy")) {
+		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_copy")) {
 			return;
 		}
 		decl_space.add_type_member_declaration (create_set_value_copy_function (true));
@@ -330,7 +330,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public void declare_set_value_equals_function (CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (type_class, "dova_type_set_value_equals")) {
+		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_equals")) {
 			return;
 		}
 		decl_space.add_type_member_declaration (create_set_value_equals_function (true));
@@ -354,7 +354,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public void declare_set_value_hash_function (CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (type_class, "dova_type_set_value_hash")) {
+		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_hash")) {
 			return;
 		}
 		decl_space.add_type_member_declaration (create_set_value_hash_function (true));
@@ -378,7 +378,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public void declare_set_value_to_any_function (CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (type_class, "dova_type_set_value_to_any")) {
+		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_to_any")) {
 			return;
 		}
 		decl_space.add_type_member_declaration (create_set_value_to_any_function (true));
@@ -402,7 +402,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public void declare_set_value_from_any_function (CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (type_class, "dova_type_set_value_from_any")) {
+		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_from_any")) {
 			return;
 		}
 		decl_space.add_type_member_declaration (create_set_value_from_any_function (true));
@@ -1076,7 +1076,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public override void generate_property_accessor_declaration (PropertyAccessor acc, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (acc.prop, acc.get_cname ())) {
+		if (add_symbol_declaration (decl_space, acc.prop, acc.get_cname ())) {
 			return;
 		}
 
@@ -1264,7 +1264,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (iface, iface.get_cname ())) {
+		if (add_symbol_declaration (decl_space, iface, iface.get_cname ())) {
 			return;
 		}
 
@@ -1311,7 +1311,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (m, m.get_cname ())) {
+		if (add_symbol_declaration (decl_space, m, m.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valadovastructmodule.vala b/codegen/valadovastructmodule.vala
index e934e80..4dee8f7 100644
--- a/codegen/valadovastructmodule.vala
+++ b/codegen/valadovastructmodule.vala
@@ -24,7 +24,7 @@ using GLib;
 
 public class Vala.DovaStructModule : DovaBaseModule {
 	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (st, st.get_cname ())) {
+		if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valadovavaluemodule.vala b/codegen/valadovavaluemodule.vala
index 08e2ec7..007025f 100644
--- a/codegen/valadovavaluemodule.vala
+++ b/codegen/valadovavaluemodule.vala
@@ -35,7 +35,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
 		base.generate_struct_declaration (st, decl_space);
 
-		if (decl_space.add_symbol_declaration (st, st.get_copy_function ())) {
+		if (add_symbol_declaration (decl_space, st, st.get_copy_function ())) {
 			return;
 		}
 
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index c8fb945..50b86fa 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -304,7 +304,7 @@ public class Vala.GAsyncModule : GSignalModule {
 
 	public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
 		if (m.coroutine) {
-			if (decl_space.add_symbol_declaration (m, m.get_cname ())) {
+			if (add_symbol_declaration (decl_space, m, m.get_cname ())) {
 				return;
 			}
 
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 45c18b6..7fb8079 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -172,7 +172,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		string get_type_name = "%sproxy_get_type".printf (iface.get_lower_case_cprefix ());
 
-		if (decl_space.add_symbol_declaration (iface, get_type_name)) {
+		if (add_symbol_declaration (decl_space, iface, get_type_name)) {
 			return;
 		}
 
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 8d22467..370d6b8 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -1076,7 +1076,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		string register_object_name = "%sregister_object".printf (sym.get_lower_case_cprefix ());
 
-		if (decl_space.add_symbol_declaration (sym, register_object_name)) {
+		if (add_symbol_declaration (decl_space, sym, register_object_name)) {
 			return;
 		}
 
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index dccb21b..90e99b1 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -29,7 +29,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 	private bool is_in_catch = false;
 
 	public override void generate_error_domain_declaration (ErrorDomain edomain, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (edomain, edomain.get_cname ())) {
+		if (add_symbol_declaration (decl_space, edomain, edomain.get_cname ())) {
 			return;
 		}
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 7e45efe..a22fbc4 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -47,7 +47,7 @@ public class Vala.GTypeModule : GErrorModule {
 	}
 
 	public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, cl.get_cname ())) {
+		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 
@@ -177,7 +177,7 @@ public class Vala.GTypeModule : GErrorModule {
 	}
 
 	public override void generate_class_struct_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (cl, "struct _" + cl.get_cname ())) {
+		if (add_symbol_declaration (decl_space, cl, "struct _" + cl.get_cname ())) {
 			return;
 		}
 
@@ -1828,7 +1828,7 @@ public class Vala.GTypeModule : GErrorModule {
 	}
 
 	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
-		if (decl_space.add_symbol_declaration (iface, iface.get_cname ())) {
+		if (add_symbol_declaration (decl_space, iface, iface.get_cname ())) {
 			return;
 		}
 



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