[vala] dova: Include dova-base.h/dova-types.h



commit ac01031d6f9ef50b301a549cb0fe8d0b50cc2f42
Author: Jürg Billeter <j bitron ch>
Date:   Fri Jul 16 18:05:29 2010 +0200

    dova: Include dova-base.h/dova-types.h

 codegen/valadovaassignmentmodule.vala  |    2 --
 codegen/valadovabasemodule.vala        |   26 ++++++++------------------
 codegen/valadovacontrolflowmodule.vala |    3 +--
 codegen/valadovaobjectmodule.vala      |   12 ------------
 codegen/valadovastructmodule.vala      |    2 --
 codegen/valadovavaluemodule.vala       |    7 -------
 compiler/valacompiler.vala             |    1 +
 vala/valacodecontext.vala              |    2 ++
 8 files changed, 12 insertions(+), 43 deletions(-)
---
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index 1c400b7..17fcfc5 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -161,8 +161,6 @@ internal class Vala.DovaAssignmentModule : DovaMemberAccessModule {
 		CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
 		CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
 
-		source_declarations.add_include ("string.h");
-
 		// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
 		// simple assignments do not work in C
 		var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 572270d..f67ca33 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -241,11 +241,18 @@ internal class Vala.DovaBaseModule : CCodeModule {
 
 		header_declarations = new CCodeDeclarationSpace ();
 
-
 		source_declarations = new CCodeDeclarationSpace ();
 		module_init_fragment = new CCodeFragment ();
 		source_type_member_definition = new CCodeFragment ();
 
+		if (context.nostdpkg) {
+			header_declarations.add_include ("dova-types.h");
+			source_declarations.add_include ("dova-types.h");
+		} else {
+			header_declarations.add_include ("dova-base.h");
+			source_declarations.add_include ("dova-base.h");
+		}
+
 		next_temp_var_id = 0;
 		variable_name_map.clear ();
 
@@ -1114,7 +1121,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 			var pointer_type = (PointerType) type;
 			return get_dup_func_expression (pointer_type.base_type, source_reference);
 		} else {
-			source_declarations.add_include ("stddef.h");
 			return new CCodeConstant ("NULL");
 		}
 	}
@@ -1140,7 +1146,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 				}
 			}
 			if (unref_function == null) {
-				source_declarations.add_include ("stddef.h");
 				return new CCodeConstant ("NULL");
 			}
 			return new CCodeIdentifier (unref_function);
@@ -1154,7 +1159,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 		} else if (type is PointerType) {
 			return new CCodeIdentifier ("free");
 		} else {
-			source_declarations.add_include ("stddef.h");
 			return new CCodeConstant ("NULL");
 		}
 	}
@@ -1179,8 +1183,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 		 * if foo is of static type non-null
 		 */
 
-		source_declarations.add_include ("stddef.h");
-
 		var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL"));
 		if (type.type_parameter != null) {
 			if (!(current_type_symbol is Class) || current_class.is_compact) {
@@ -1279,8 +1281,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 				var alloca_call = new CCodeFunctionCall (new CCodeIdentifier ("alloca"));
 				alloca_call.add_argument (value_size);
 
-				// memset needs string.h
-				source_declarations.add_include ("string.h");
 				var memset_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 				memset_call.add_argument (alloca_call);
 				memset_call.add_argument (new CCodeConstant ("0"));
@@ -1300,7 +1300,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 				vardecl.init0 = true;
 			} else if (local.variable_type.is_reference_type_or_type_parameter () ||
 			       local.variable_type.nullable) {
-				source_declarations.add_include ("stddef.h");
 				vardecl.initializer = new CCodeConstant ("NULL");
 				vardecl.init0 = true;
 			}
@@ -1501,7 +1500,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	}
 
 	public override void visit_boolean_literal (BooleanLiteral expr) {
-		source_declarations.add_include ("stdbool.h");
 		expr.ccodenode = new CCodeConstant (expr.value ? "true" : "false");
 	}
 
@@ -1552,7 +1550,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	}
 
 	public override void visit_null_literal (NullLiteral expr) {
-		source_declarations.add_include ("stddef.h");
 		expr.ccodenode = new CCodeConstant ("NULL");
 	}
 
@@ -1711,7 +1708,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 
 			var ctemp = get_variable_cexpression (decl.name);
 
-			source_declarations.add_include ("stddef.h");
 			var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ctemp, new CCodeConstant ("NULL"));
 			if (expression_type.type_parameter != null) {
 				// dup functions are optional for type parameters
@@ -1779,8 +1775,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 		if (expr.symbol_reference == null) {
 			// no creation method
 			if (expr.type_reference.data_type is Struct) {
-				// memset needs string.h
-				source_declarations.add_include ("string.h");
 				var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
 				creation_call.add_argument (new CCodeConstant ("0"));
@@ -2425,8 +2419,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	}
 
 	public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) {
-		source_declarations.add_include ("stddef.h");
-
 		var st = type.data_type as Struct;
 		var array_type = type as ArrayType;
 		if (type is GenericType) {
@@ -2436,8 +2428,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 			var alloca_call = new CCodeFunctionCall (new CCodeIdentifier ("alloca"));
 			alloca_call.add_argument (value_size);
 
-			// memset needs string.h
-			source_declarations.add_include ("string.h");
 			var memset_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 			memset_call.add_argument (alloca_call);
 			memset_call.add_argument (new CCodeConstant ("0"));
diff --git a/codegen/valadovacontrolflowmodule.vala b/codegen/valadovacontrolflowmodule.vala
index 6616dcc..ab142cb 100644
--- a/codegen/valadovacontrolflowmodule.vala
+++ b/codegen/valadovacontrolflowmodule.vala
@@ -1,6 +1,6 @@
 /* valadovacontrolflowmodule.vala
  *
- * Copyright (C) 2006-2009  Jürg Billeter
+ * Copyright (C) 2006-2010  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -79,7 +79,6 @@ internal class Vala.DovaControlFlowModule : DovaMethodModule {
 	public override void visit_loop (Loop stmt) {
 		stmt.accept_children (codegen);
 
-		source_declarations.add_include ("stdbool.h");
 		stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
 	}
 
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index 5da911c..ed01736 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -43,8 +43,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 			instance_struct.add_field ("DovaType *", "type");
 			decl_space.add_type_definition (instance_struct);
 		} else if (cl == type_class) {
-			decl_space.add_include ("stdbool.h");
-
 			var value_copy_function = new CCodeFunction ("dova_type_value_copy");
 			value_copy_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
 			value_copy_function.add_parameter (new CCodeFormalParameter ("dest", "void *"));
@@ -367,10 +365,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 	}
 
 	public CCodeBlock generate_type_get_function (TypeSymbol cl, Class? base_class) {
-		source_declarations.add_include ("stddef.h");
-		// calloc
-		source_declarations.add_include ("stdlib.h");
-
 		DataType? base_class_type = null;
 		if (base_class != null && cl is Class) {
 			foreach (DataType base_type in ((Class) cl).get_base_types ()) {
@@ -856,10 +850,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sTypePrivate".printf (iface.get_cname ()))));
 		source_declarations.add_type_definition (type_priv_struct);
 
-		source_declarations.add_include ("stddef.h");
-		// calloc
-		source_declarations.add_include ("stdlib.h");
-
 		var cdecl = new CCodeDeclaration ("DovaType *");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("%s_type".printf (iface.get_lower_case_cname ()), new CCodeConstant ("NULL")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
@@ -1606,8 +1596,6 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 			cdecl.add_declarator (new CCodeVariableDeclarator ("this"));
 			vblock.add_statement (cdecl);
 
-			source_declarations.add_include ("stddef.h");
-
 			var type_get = new CCodeFunctionCall (new CCodeIdentifier (current_class.get_lower_case_cname () + "_type_get"));
 			foreach (var type_param in current_class.get_type_parameters ()) {
 				type_get.add_argument (new CCodeIdentifier ("%s_type".printf (type_param.name.down ())));
diff --git a/codegen/valadovastructmodule.vala b/codegen/valadovastructmodule.vala
index 4cc286b..f0746b8 100644
--- a/codegen/valadovastructmodule.vala
+++ b/codegen/valadovastructmodule.vala
@@ -41,12 +41,10 @@ internal class Vala.DovaStructModule : DovaBaseModule {
 
 		if (st.is_boolean_type ()) {
 			// typedef for boolean types
-			decl_space.add_include ("stdbool.h");
 			st.set_cname ("bool");
 			return;
 		} else if (st.is_integer_type ()) {
 			// typedef for integral types
-			decl_space.add_include ("stdint.h");
 			st.set_cname ("%sint%d_t".printf (st.signed ? "" : "u", st.width));
 			return;
 		} else if (st.is_decimal_floating_type ()) {
diff --git a/codegen/valadovavaluemodule.vala b/codegen/valadovavaluemodule.vala
index f7c29d1..3cef0e9 100644
--- a/codegen/valadovavaluemodule.vala
+++ b/codegen/valadovavaluemodule.vala
@@ -358,8 +358,6 @@ internal class Vala.DovaValueModule : DovaObjectModule {
 			return;
 		}
 
-		decl_space.add_include ("stdint.h");
-
 		generate_class_declaration (type_class, decl_space);
 
 		var type_fun = new CCodeFunction ("%s_type_get".printf (st.get_lower_case_cname ()), "DovaType *");
@@ -410,11 +408,6 @@ internal class Vala.DovaValueModule : DovaObjectModule {
 	public override void visit_struct (Struct st) {
 		base.visit_struct (st);
 
-		source_declarations.add_include ("stddef.h");
-		// calloc
-		source_declarations.add_include ("stdlib.h");
-
-
 		var cdecl = new CCodeDeclaration ("int");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_%s_object_offset".printf (st.get_lower_case_cname ()), new CCodeConstant ("0")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 3c5f733..f271c6f 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -255,6 +255,7 @@ class Vala.Compiler {
 		} else {
 			Report.error (null, "Unknown profile %s".printf (profile));
 		}
+		context.nostdpkg = nostdpkg;
 
 		context.entry_point_name = entry_point;
 
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 0bce4bf..cd32378 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -149,6 +149,8 @@ public class Vala.CodeContext {
 
 	public bool version_header { get; set; }
 
+	public bool nostdpkg { get; set; }
+
 	/**
 	 * Returns true if the target version of glib is greater than or 
 	 * equal to the specified version.



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