[vala/wip/attributes: 20/27] codegen: Add get_ccode_get_value_function
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 20/27] codegen: Add get_ccode_get_value_function
- Date: Tue, 28 Jun 2011 13:17:15 +0000 (UTC)
commit 252358506c60984c13795c952a57ddfd5899b580
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 28 14:15:13 2011 +0200
codegen: Add get_ccode_get_value_function
codegen/valaccodebasemodule.vala | 71 +++++++++++++++++++++++++++++++++++++-
codegen/valagobjectmodule.vala | 2 +-
codegen/valagsignalmodule.vala | 2 +-
codegen/valagtypemodule.vala | 4 +-
4 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index aca7917..500b30d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -582,7 +582,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
CCodeIdentifier get_value_getter_function (DataType type_reference) {
var array_type = type_reference as ArrayType;
if (type_reference.data_type != null) {
- return new CCodeIdentifier (type_reference.data_type.get_get_value_function ());
+ return new CCodeIdentifier (get_ccode_get_value_function (type_reference.data_type));
} else if (array_type != null && array_type.element_type.data_type == string_type.data_type) {
// G_TYPE_STRV
return new CCodeIdentifier ("g_value_get_boxed");
@@ -5654,6 +5654,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_ccode_attribute(sym).marshaller_type_name;
}
+ public static string get_ccode_get_value_function (CodeNode sym) {
+ return get_ccode_attribute(sym).get_value_function;
+ }
+
public override void visit_class (Class cl) {
}
@@ -6152,6 +6156,15 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
+ public string get_value_function {
+ get {
+ if (_get_value_function == null) {
+ _get_value_function = get_default_get_value_function ();
+ }
+ return _get_value_function;
+ }
+ }
+
private string _name;
private string _const_name;
private string _type_name;
@@ -6167,6 +6180,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _free_function;
private string _type_id;
private string _marshaller_type_name;
+ private string _get_value_function;
public CCodeAttribute (CodeNode node) {
this.node = node;
@@ -6200,6 +6214,7 @@ public class Vala.CCodeAttribute : AttributeCache {
_free_function = attr.get_string ("free_function");
_type_id = attr.get_string ("type_id");
_marshaller_type_name = attr.get_string ("marshaller_type_name");
+ _get_value_function = attr.get_string ("get_value_function");
}
}
@@ -6569,4 +6584,58 @@ public class Vala.CCodeAttribute : AttributeCache {
return CCodeBaseModule.get_ccode_marshaller_type_name (((DataType) node).dat_type);
}
}
+
+ private string get_default_get_value_function () {
+ if (sym is Class) {
+ var cl = (Class) sym;
+ if (cl.is_fundamental ()) {
+ return CCodeBaseModule.get_ccode_lower_case_cname (cl, "value_get_");
+ } else if (cl.base_class != null) {
+ return CCodeBaseModule.get_ccode_get_value_function (cl.base_class);
+ } else if (type_id == "G_TYPE_POINTER") {
+ return "g_value_get_pointer";
+ } else {
+ return "g_value_get_boxed";
+ }
+ } else if (sym is Enum) {
+ var en = (Enum) sym;
+ if (en.has_type_id) {
+ if (en.is_flags) {
+ return "g_value_get_flags";
+ } else {
+ return "g_value_get_enum";
+ }
+ } else {
+ if (en.is_flags) {
+ return "g_value_get_uint";
+ } else {
+ return "g_value_get_int";
+ }
+ }
+ } else if (sym is Interface) {
+ foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
+ var type_name = CCodeBaseModule.get_ccode_get_value_function (prereq.data_type);
+ if (type_name != "") {
+ return type_name;
+ }
+ }
+ return "g_value_get_pointer";
+ } else if (sym is Struct) {
+ var st = (Struct) sym;
+ var base_st = st.base_struct;
+ if (base_st != null) {
+ return CCodeBaseModule.get_ccode_get_value_function (base_st);
+ }
+ if (st.is_simple_type ()) {
+ Report.error (st.source_reference, "The type `%s` doesn't declare a GValue get function".printf (st.get_full_name ()));
+ } else if (st.has_type_id) {
+ return "g_value_get_boxed";
+ } else {
+ return "g_value_get_pointer";
+ }
+ } else {
+ return "g_value_get_pointer";
+ }
+ return "";
+ }
}
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 5960378..6d95c24 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -332,7 +332,7 @@ public class Vala.GObjectModule : GTypeModule {
} else {
var cgetcall = new CCodeFunctionCall ();
if (prop.property_type.data_type != null) {
- cgetcall.call = new CCodeIdentifier (prop.property_type.data_type.get_get_value_function ());
+ cgetcall.call = new CCodeIdentifier (get_ccode_get_value_function (prop.property_type.data_type));
} else {
cgetcall.call = new CCodeIdentifier ("g_value_get_pointer");
}
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index fead94b..16cbb09 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -254,7 +254,7 @@ public class Vala.GSignalModule : GObjectModule {
} else if (p.variable_type is ErrorType) {
get_value_function = "g_value_get_pointer";
} else {
- get_value_function = p.variable_type.data_type.get_get_value_function ();
+ get_value_function = get_ccode_get_value_function (p.variable_type.data_type);
}
var inner_fc = new CCodeFunctionCall (new CCodeIdentifier (get_value_function));
inner_fc.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 7c021d6..79bf407 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -145,7 +145,7 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_function_declaration (function);
- function = new CCodeFunction (cl.get_get_value_function (), "gpointer");
+ function = new CCodeFunction (get_ccode_get_value_function (cl), "gpointer");
function.add_parameter (new CCodeParameter ("value", "const GValue*"));
if (cl.access == SymbolAccessibility.PRIVATE) {
@@ -1073,7 +1073,7 @@ public class Vala.GTypeModule : GErrorModule {
}
private void add_g_value_get_function (Class cl) {
- var function = new CCodeFunction (cl.get_get_value_function (), "gpointer");
+ var function = new CCodeFunction (get_ccode_get_value_function (cl), "gpointer");
function.add_parameter (new CCodeParameter ("value", "const GValue*"));
if (cl.access == SymbolAccessibility.PRIVATE) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]