[vala/wip/transform: 23/102] Serialize hash table
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 23/102] Serialize hash table
- Date: Tue, 23 Oct 2018 20:43:56 +0000 (UTC)
commit 8f4c490b40c0416d8adb97770acb63bd5dc3e62e
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Dec 30 11:27:19 2011 +0100
Serialize hash table
codegen/valagvarianttransformer.vala | 24 ++++++++++++++++++++----
vala/valacodebuilder.vala | 2 ++
2 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valagvarianttransformer.vala b/codegen/valagvarianttransformer.vala
index 211117b81..c2f09eb49 100644
--- a/codegen/valagvarianttransformer.vala
+++ b/codegen/valagvarianttransformer.vala
@@ -231,11 +231,19 @@ public class Vala.GVariantTransformer : CodeTransformer {
return expression (@"$builder.end ()");
}
- Expression? serialize_expression (DataType type, Expression expr) {
- if (type.data_type == context.analyzer.gvariant_type.data_type) {
- return expr;
- }
+ Expression? serialize_hash_table (ObjectType type, Expression expr) {
+ string temp = b.add_temp_declaration (expr.value_type, expr);
+
+ var builderinit = expression (@"new GLib.VariantBuilder (new GLib.VariantType
(\"$(get_type_signature (type))\"))");
+ var builder = b.add_temp_declaration (null, builderinit);
+
+ var for_each = expression (@"$temp.for_each ((k,v) => $builder.add (\"{?*}\", k, v))");
+ b.add_expression (for_each);
+ return expression (@"$builder.end ()");
+ }
+
+ Expression? serialize_expression (DataType type, Expression expr) {
BasicTypeInfo basic_type;
Expression result = null;
if (get_basic_type_info (get_type_signature (type), out basic_type)) {
@@ -244,6 +252,14 @@ public class Vala.GVariantTransformer : CodeTransformer {
result = serialize_array ((ArrayType) type, expr);
} else if (type.data_type is Struct) {
result = serialize_struct ((Struct) type.data_type, expr);
+ } else if (type is ObjectType) {
+ if (type.data_type == context.analyzer.gvariant_type.data_type) {
+ var variant_new = (ObjectCreationExpression) expression ("new
GLib.Variant.variant ()");
+ variant_new.add_argument (expr);
+ result = variant_new;
+ } else if (type.data_type.get_full_name () == "GLib.HashTable") {
+ result = serialize_hash_table ((ObjectType) type, expr);
+ }
}
return result;
}
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index f08fc92bb..c15fc05e8 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -38,6 +38,8 @@ public class Vala.CodeBuilder {
var statement_block = context.analyzer.get_current_block (insert_statement);
statement_block.insert_before (insert_statement, current_block);
+ this.insert_statement = current_block;
+
check_nodes.add (current_block);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]