[vala/wip/gee: 2/4] Port to SortedMap
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/gee: 2/4] Port to SortedMap
- Date: Wed, 21 Sep 2016 10:36:46 +0000 (UTC)
commit 52b2ae244312034b74542d575ad1d77439cf29d0
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Wed Sep 21 11:09:54 2016 +0200
Port to SortedMap
https://bugzilla.gnome.org/show_bug.cgi?id=704754
codegen/valaccodebasemodule.vala | 47 +++++++------------------------
codegen/valaccodedelegatemodule.vala | 42 +++++++---------------------
codegen/valaccodemethodcallmodule.vala | 44 +++++++-----------------------
codegen/valaccodemethodmodule.vala | 39 +++++++++-----------------
codegen/valagasyncmodule.vala | 26 +++++++++---------
codegen/valagdbusclientmodule.vala | 8 +++---
codegen/valagtypemodule.vala | 32 +++++++--------------
7 files changed, 73 insertions(+), 165 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5a7a5f5..2e394b5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1461,7 +1461,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public virtual void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
}
- public virtual void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeParameter>
cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>?
carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+ public virtual void generate_cparameters (Method m, CCodeFile decl_space,
SortedMap<int,CCodeParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null,
Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
}
public void generate_property_accessor_declaration (PropertyAccessor acc, CCodeFile decl_space) {
@@ -4566,7 +4566,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
generate_type_declaration (expr.type_reference, cfile);
- var in_arg_map = new HashMap<int,CCodeExpression> ();
+ var in_arg_map = new TreeMap<int,CCodeExpression> ();
var out_arg_map = in_arg_map;
if (m != null && m.coroutine) {
@@ -4578,7 +4578,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
creation_call = finish_call;
// output arguments used separately
- out_arg_map = new HashMap<int,CCodeExpression> ();
+ out_arg_map = new TreeMap<int,CCodeExpression> ();
// pass GAsyncResult stored in closure to finish function
out_arg_map.set (get_param_pos (0.1), new CCodeMemberAccess.pointer (new
CCodeIdentifier ("_data_"), "_res_"));
}
@@ -4702,44 +4702,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- // append C arguments in the right order
-
- int last_pos;
- int min_pos;
-
if (async_call != creation_call) {
// don't append out arguments for .begin() calls
- last_pos = -1;
- while (true) {
- min_pos = -1;
- foreach (int pos in out_arg_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- creation_call.add_argument (out_arg_map.get (min_pos));
- last_pos = min_pos;
- }
+ out_arg_map.values.foreach ((arg) => {
+ creation_call.add_argument (arg);
+ return true;
+ });
}
if (async_call != null) {
- last_pos = -1;
- while (true) {
- min_pos = -1;
- foreach (int pos in in_arg_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- async_call.add_argument (in_arg_map.get (min_pos));
- last_pos = min_pos;
- }
+ in_arg_map.values.foreach ((arg) => {
+ async_call.add_argument (arg);
+ return true;
+ });
}
if (expr.is_yield_expression) {
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index e278360..4d520b7 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -207,7 +207,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
push_function (function);
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
if (d.has_target) {
var cparam = new CCodeParameter ("self", "gpointer");
@@ -264,26 +264,14 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
// append C parameters in the right order
- int last_pos = -1;
- int min_pos;
- while (true) {
- min_pos = -1;
- foreach (int pos in cparam_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- function.add_parameter (cparam_map.get (min_pos));
- last_pos = min_pos;
- }
-
+ cparam_map.values.foreach ((param) => {
+ function.add_parameter (param);
+ return true;
+ });
// definition
- var carg_map = new HashMap<int,CCodeExpression> ();
+ var carg_map = new TreeMap<int,CCodeExpression> ();
int i = 0;
if (m.binding == MemberBinding.INSTANCE || m.closure) {
@@ -389,20 +377,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_name (m)));
// append C arguments in the right order
- last_pos = -1;
- while (true) {
- min_pos = -1;
- foreach (int pos in carg_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- ccall.add_argument (carg_map.get (min_pos));
- last_pos = min_pos;
- }
+ carg_map.values.foreach ((arg) => {
+ ccall.add_argument (arg);
+ return true;
+ });
if (m.coroutine) {
ccall.add_argument (new CCodeConstant ("NULL"));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index e1a4cae..54c9afb 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -78,7 +78,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
deleg = ((DelegateType) itype).delegate_symbol;
}
- var in_arg_map = new HashMap<int,CCodeExpression> ();
+ var in_arg_map = new TreeMap<int,CCodeExpression> ();
var out_arg_map = in_arg_map;
if (m != null && m.coroutine) {
@@ -120,7 +120,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
ccall = finish_call;
// output arguments used separately
- out_arg_map = new HashMap<int,CCodeExpression> ();
+ out_arg_map = new TreeMap<int,CCodeExpression> ();
// pass GAsyncResult stored in closure to finish function
out_arg_map.set (get_param_pos (0.1), new CCodeMemberAccess.pointer (new
CCodeIdentifier ("_data_"), "_res_"));
}
@@ -648,43 +648,19 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
}
// append C arguments in the right order
-
- int last_pos;
- int min_pos;
-
if (async_call != ccall) {
// don't append out arguments for .begin() calls
- last_pos = -1;
- while (true) {
- min_pos = -1;
- foreach (int pos in out_arg_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- ccall.add_argument (out_arg_map.get (min_pos));
- last_pos = min_pos;
- }
+ out_arg_map.values.foreach ((arg) => {
+ ccall.add_argument (arg);
+ return true;
+ });
}
if (async_call != null) {
- last_pos = -1;
- while (true) {
- min_pos = -1;
- foreach (int pos in in_arg_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- async_call.add_argument (in_arg_map.get (min_pos));
- last_pos = min_pos;
- }
+ in_arg_map.values.foreach ((arg) => {
+ async_call.add_argument (arg);
+ return true;
+ });
}
if (expr.is_yield_expression) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 2bc181d..0c25842 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -173,7 +173,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
function.modifiers |= CCodeModifiers.DEPRECATED;
}
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
var cl = m.parent_symbol as Class;
@@ -198,7 +198,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
function.modifiers |= CCodeModifiers.INTERNAL;
}
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
bool etv_tmp = ellipses_to_valist;
ellipses_to_valist = false;
generate_cparameters (m, decl_space, cparam_map, function);
@@ -210,7 +210,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
// _constructv function
function = new CCodeFunction (get_ccode_constructv_name ((CreationMethod) m));
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, function);
decl_space.add_function_declaration (function);
@@ -416,7 +416,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
function.modifiers |= CCodeModifiers.INLINE;
}
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, cfile, cparam_map, function);
@@ -815,7 +815,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
* emitter! */
m.signal_reference == null) {
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
generate_vfunc (m, creturn_type, cparam_map, carg_map);
@@ -909,7 +909,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
return cparam;
}
- public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeParameter>
cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>?
carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+ public override void generate_cparameters (Method m, CCodeFile decl_space,
SortedMap<int,CCodeParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null,
Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
if (m.closure) {
var closure_block = current_closure_block;
int block_id = get_block_id (closure_block);
@@ -1011,33 +1011,22 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
// append C parameters in the right order
- int last_pos = -1;
- int min_pos;
- while (true) {
- min_pos = -1;
- foreach (int pos in cparam_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (min_pos == -1) {
- break;
- }
- func.add_parameter (cparam_map.get (min_pos));
+ cparam_map.keys.foreach ((pos) => {
+ func.add_parameter (cparam_map.get (pos));
if (vdeclarator != null) {
- vdeclarator.add_parameter (cparam_map.get (min_pos));
+ vdeclarator.add_parameter (cparam_map.get (pos));
}
if (vcall != null) {
- var arg = carg_map.get (min_pos);
+ var arg = carg_map.get (pos);
if (arg != null) {
vcall.add_argument (arg);
}
}
- last_pos = min_pos;
- }
+ return true;
+ });
}
- public void generate_vfunc (Method m, DataType return_type, Map<int,CCodeParameter> cparam_map,
Map<int,CCodeExpression> carg_map, string suffix = "", int direction = 3) {
+ public void generate_vfunc (Method m, DataType return_type, SortedMap<int,CCodeParameter> cparam_map,
Map<int,CCodeExpression> carg_map, string suffix = "", int direction = 3) {
push_context (new EmitContext ());
string cname = get_ccode_name (m);
@@ -1193,7 +1182,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
vfunc.modifiers |= CCodeModifiers.INTERNAL;
}
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
push_function (vfunc);
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 63469f1..2bc978a 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -155,7 +155,7 @@ public class Vala.GAsyncModule : GtkModule {
var dataname = Symbol.lower_case_to_camel_case (get_ccode_name (m)) + "Data";
var asyncfunc = new CCodeFunction (get_ccode_real_name (m), "void");
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
cparam_map.set (get_param_pos (-1), new CCodeParameter ("_callback_", "GAsyncReadyCallback"));
cparam_map.set (get_param_pos (-0.9), new CCodeParameter ("_user_data_", "gpointer"));
@@ -304,7 +304,7 @@ public class Vala.GAsyncModule : GtkModule {
var cl = m.parent_symbol as Class;
var asyncfunc = new CCodeFunction (get_ccode_name (m), "void");
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
if (m.is_private_symbol ()) {
@@ -321,7 +321,7 @@ public class Vala.GAsyncModule : GtkModule {
}
var finishfunc = new CCodeFunction (get_ccode_finish_name (m));
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
carg_map = new HashMap<int,CCodeExpression> ();
if (m.is_private_symbol ()) {
@@ -347,7 +347,7 @@ public class Vala.GAsyncModule : GtkModule {
function.modifiers |= CCodeModifiers.INTERNAL;
}
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, function, null, null, null,
1);
decl_space.add_function_declaration (function);
@@ -360,7 +360,7 @@ public class Vala.GAsyncModule : GtkModule {
function.modifiers |= CCodeModifiers.INTERNAL;
}
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, function, null, null, null,
2);
decl_space.add_function_declaration (function);
@@ -406,11 +406,11 @@ public class Vala.GAsyncModule : GtkModule {
if (m.is_abstract || m.is_virtual) {
// generate virtual function wrappers
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
generate_vfunc (m, new VoidType (), cparam_map, carg_map, "", 1);
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
carg_map = new HashMap<int,CCodeExpression> ();
generate_vfunc (m, m.return_type, cparam_map, carg_map, "_finish", 2);
}
@@ -437,7 +437,7 @@ public class Vala.GAsyncModule : GtkModule {
if (current_type_symbol is Class && !current_class.is_compact &&
!current_class.is_abstract) {
var vfunc = new CCodeFunction (get_ccode_name (m));
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
var carg_map = new HashMap<int,CCodeExpression> ();
push_function (vfunc);
@@ -459,7 +459,7 @@ public class Vala.GAsyncModule : GtkModule {
vfunc = new CCodeFunction (get_ccode_finish_name (m));
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
carg_map = new HashMap<int,CCodeExpression> ();
push_function (vfunc);
@@ -489,7 +489,7 @@ public class Vala.GAsyncModule : GtkModule {
var finishfunc = new CCodeFunction (get_ccode_finish_real_name (m));
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
cparam_map.set (get_param_pos (0.1), new CCodeParameter ("_res_", "GAsyncResult*"));
@@ -637,7 +637,7 @@ public class Vala.GAsyncModule : GtkModule {
// add vfunc field to the type struct
var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, new CCodeFunction ("fake"), vdeclarator,
null, null, 1);
@@ -647,7 +647,7 @@ public class Vala.GAsyncModule : GtkModule {
// add vfunc field to the type struct
vdeclarator = new CCodeFunctionDeclarator (get_ccode_finish_vfunc_name (m));
- cparam_map = new HashMap<int,CCodeParameter> ();
+ cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, new CCodeFunction ("fake"), vdeclarator,
null, null, 2);
@@ -725,7 +725,7 @@ public class Vala.GAsyncModule : GtkModule {
complete_async ();
}
- public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeParameter>
cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>?
carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+ public override void generate_cparameters (Method m, CCodeFile decl_space,
SortedMap<int,CCodeParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null,
Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
if (m.coroutine) {
decl_space.add_include ("gio/gio.h");
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index b12c958..408657f 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -48,7 +48,7 @@ public class Vala.GDBusClientModule : GDBusModule {
var func = new CCodeFunction (get_ccode_name (method));
func.modifiers = CCodeModifiers.STATIC;
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (method, cfile, cparam_map, func);
@@ -861,7 +861,7 @@ public class Vala.GDBusClientModule : GDBusModule {
var function = new CCodeFunction (proxy_name);
function.modifiers = CCodeModifiers.STATIC;
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, cfile, cparam_map, function);
@@ -885,7 +885,7 @@ public class Vala.GDBusClientModule : GDBusModule {
var function = new CCodeFunction (proxy_name, "void");
function.modifiers = CCodeModifiers.STATIC;
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
cparam_map.set (get_param_pos (-1), new CCodeParameter ("_callback_", "GAsyncReadyCallback"));
cparam_map.set (get_param_pos (-0.9), new CCodeParameter ("_user_data_", "gpointer"));
@@ -910,7 +910,7 @@ public class Vala.GDBusClientModule : GDBusModule {
var function = new CCodeFunction (proxy_name);
function.modifiers = CCodeModifiers.STATIC;
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
cparam_map.set (get_param_pos (0.1), new CCodeParameter ("_res_", "GAsyncResult*"));
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 0e8ff0d..8f50243 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -392,7 +392,7 @@ public class Vala.GTypeModule : GErrorModule {
// add vfunc field to the type struct
var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, decl_space, cparam_map, new CCodeFunction ("fake"), vdeclarator);
@@ -1492,34 +1492,24 @@ public class Vala.GTypeModule : GErrorModule {
string cast_args = get_ccode_name (base_type) + "*";
var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
- var cparam_map = new HashMap<int,CCodeParameter> ();
+ var cparam_map = new TreeMap<int,CCodeParameter> ();
generate_cparameters (m, cfile, cparam_map, new CCodeFunction ("fake"), vdeclarator);
// append C arguments in the right order
- int last_pos = -1;
- int min_pos;
- while (true) {
- min_pos = -1;
- foreach (int pos in cparam_map.keys) {
- if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
- min_pos = pos;
- }
- }
- if (last_pos != -1) { // Skip the 1st parameter
- if (min_pos == -1) {
- break;
- }
-
- var tmp = cparam_map.get (min_pos);
- if (tmp.ellipsis) {
+ bool first = true;
+ cparam_map.values.foreach ((param) => {
+ if (!first) {
+ if (param.ellipsis) {
cast_args += ", " + " ...";
} else {
- cast_args += ", " + tmp.type_name;
+ cast_args += ", " + param.type_name;
}
+ } else {
+ first = false;
}
- last_pos = min_pos;
- }
+ return true;
+ });
cast += "(" + cast_args + ")";
return new CCodeCastExpression (cfunc, cast);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]