[vala] codegen: Use a zero-initializer also for SimpleType structs
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use a zero-initializer also for SimpleType structs
- Date: Sat, 27 Aug 2011 19:26:04 +0000 (UTC)
commit 0d11812df3532cedbf1d58b39e09832e5a3acbf0
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Aug 27 20:30:17 2011 +0200
codegen: Use a zero-initializer also for SimpleType structs
codegen/valaccodebasemodule.vala | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e9c9a7a..3e5c125 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5425,9 +5425,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) {
var st = type.data_type as Struct;
var array_type = type as ArrayType;
- if (initializer_expression && !type.nullable &&
- ((st != null && !st.is_simple_type ()) ||
- (array_type != null && array_type.fixed_length))) {
+ if (type.data_type != null && get_ccode_default_value (type.data_type) != "") {
+ return new CCodeConstant (get_ccode_default_value (type.data_type));
+ } else if (initializer_expression && !type.nullable &&
+ (st != null || (array_type != null && array_type.fixed_length))) {
// 0-initialize struct with struct initializer { 0 }
// only allowed as initializer expression in C
var clist = new CCodeInitializerList ();
@@ -5438,8 +5439,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
|| type is PointerType || type is DelegateType
|| (array_type != null && !array_type.fixed_length)) {
return new CCodeConstant ("NULL");
- } else if (type.data_type != null && get_ccode_default_value (type.data_type) != "") {
- return new CCodeConstant (get_ccode_default_value (type.data_type));
} else if (type.type_parameter != null) {
return new CCodeConstant ("NULL");
} else if (type is ErrorType) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]