[vala/wip/attributes: 25/27] codegen: Add get_ccode_default_value
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 25/27] codegen: Add get_ccode_default_value
- Date: Tue, 28 Jun 2011 13:17:40 +0000 (UTC)
commit 34ae5ef4dcdf691c2dc1fc927b8b161919fbc3b9
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 28 15:07:54 2011 +0200
codegen: Add get_ccode_default_value
codegen/valaccodebasemodule.vala | 42 ++++++++++++++++++++++++++++++++++++-
codegen/valagtypemodule.vala | 2 +-
2 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7437046..8abfeae 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5447,8 +5447,8 @@ 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 && type.data_type.get_default_value () != null) {
- return new CCodeConstant (type.data_type.get_default_value ());
+ } 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) {
@@ -5671,6 +5671,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
+ public static string get_ccode_default_value (TypeSymbol sym) {
+ return get_ccode_attribute(sym).default_value;
+ }
+
public override void visit_class (Class cl) {
}
@@ -6205,6 +6209,15 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
+ public string default_value {
+ get {
+ if (_default_value == null) {
+ _default_value = get_default_default_value ();
+ }
+ return _default_value;
+ }
+ }
+
private string _name;
private string _const_name;
private string _type_name;
@@ -6224,6 +6237,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _set_value_function;
private string _take_value_function;
private string _param_spec_function;
+ private string _default_value;
public CCodeAttribute (CodeNode node) {
this.node = node;
@@ -6261,6 +6275,7 @@ public class Vala.CCodeAttribute : AttributeCache {
_set_value_function = attr.get_string ("set_value_function");
_take_value_function = attr.get_string ("take_value_function");
_param_spec_function = attr.get_string ("param_spec_function");
+ _default_value = attr.get_string ("default_value");
}
}
@@ -6816,4 +6831,27 @@ public class Vala.CCodeAttribute : AttributeCache {
}
return "";
}
+
+ private string get_default_default_value () {
+ if (sym is Enum) {
+ return "0";
+ }
+
+ var st = (Struct) sym;
+ var base_st = st.base_struct;
+
+ if (base_st != null) {
+ return CCodeBaseModule.get_ccode_default_value (base_st);
+ }
+
+ if (CodeContext.get ().profile == Profile.DOVA) {
+ if (st.is_boolean_type ()) {
+ return "false";
+ } else if (st.is_integer_type () || st.is_floating_type ()) {
+ return "0";
+ }
+ }
+
+ return "";
+ }
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 442281f..ee7e534 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1695,7 +1695,7 @@ public class Vala.GTypeModule : GErrorModule {
if (prop.initializer != null) {
cspec.add_argument ((CCodeExpression) get_ccodenode (prop.initializer));
} else {
- cspec.add_argument (new CCodeConstant (prop.property_type.data_type.get_default_value ()));
+ cspec.add_argument (new CCodeConstant (get_ccode_default_value (prop.property_type.data_type)));
}
} else if (prop.property_type.data_type is Struct) {
var st = (Struct) prop.property_type.data_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]