[vala] Add generic_type_pos CCode attribute for macros
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Add generic_type_pos CCode attribute for macros
- Date: Mon, 14 Sep 2009 21:58:43 +0000 (UTC)
commit d45ed8b40b82c636ab6c1378676a9a5b7b1e4876
Author: Jürg Billeter <j bitron ch>
Date: Mon Sep 14 23:57:37 2009 +0200
Add generic_type_pos CCode attribute for macros
codegen/valaccodearraymodule.vala | 21 ---------------------
codegen/valaccodemethodcallmodule.vala | 9 +++++++++
vala/valamethod.vala | 8 ++++++++
vapi/glib-2.0.vapi | 1 +
4 files changed, 18 insertions(+), 21 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index aa2867d..9dc70a4 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -859,27 +859,6 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
return add_func;
}
- public override void visit_method_call (MethodCall expr) {
- base.visit_method_call (expr);
-
- var ccall = expr.ccodenode as CCodeFunctionCall;
- if (ccall == null) {
- return;
- }
-
- var cid = ccall.call as CCodeIdentifier;
- if (cid == null || cid.name != "g_array_index") {
- return;
- }
-
- // insert type argument in calls to g_array_index macro
-
- var ma = (MemberAccess) expr.call;
- var element_type = ma.inner.value_type.get_type_arguments ().get (0);
-
- ccall.insert_argument (1, new CCodeIdentifier (element_type.get_cname ()));
- }
-
bool is_array_add (Assignment assignment) {
var binary = assignment.right as BinaryExpression;
if (binary != null && binary.left.value_type is ArrayType) {
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 1d1e87b..50cf4aa 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -188,6 +188,15 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (m.cinstance_parameter_position), cast);
}
+ if (m != null && m.has_generic_type_parameter) {
+ // insert type argument for macros
+ int type_param_index = 0;
+ foreach (var type_arg in ma.inner.value_type.get_type_arguments ()) {
+ in_arg_map.set (get_param_pos (m.generic_type_parameter_position + 0.01 * type_param_index), new CCodeIdentifier (type_arg.get_cname ()));
+ type_param_index++;
+ }
+ }
+
if (m is ArrayMoveMethod) {
var array_type = (ArrayType) ma.inner.value_type;
var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index bb4b8ef..a3cc995 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -216,6 +216,10 @@ public class Vala.Method : Member {
*/
public bool has_construct_function { get; set; default = true; }
+ public bool has_generic_type_parameter { get; set; }
+
+ public double generic_type_parameter_position { get; set; }
+
public weak Signal signal_reference { get; set; }
public bool coroutine { get; set; }
@@ -442,6 +446,10 @@ public class Vala.Method : Member {
if (a.has_argument ("has_construct_function")) {
has_construct_function = a.get_bool ("has_construct_function");
}
+ if (a.has_argument ("generic_type_pos")) {
+ has_generic_type_parameter = true;
+ generic_type_parameter_position = a.get_double ("generic_type_pos");
+ }
}
/**
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 37f7920..05f8b50 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -3413,6 +3413,7 @@ namespace GLib {
public void remove_range (uint index, uint length);
public void sort (CompareFunc compare_func);
public void sort_with_data (CompareDataFunc compare_func);
+ [CCode (generic_type_pos = 0.1)]
public G index (uint index);
public void set_size (uint length);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]