[vala/wip/transform: 16/99] Serialize hash table
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 16/99] Serialize hash table
- Date: Sun, 25 Sep 2016 19:17:42 +0000 (UTC)
commit 41c6b442f788e4f5b81397d9f12da8de95d1a6fb
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 f086d25..9600e2f 100644
--- a/codegen/valagvarianttransformer.vala
+++ b/codegen/valagvarianttransformer.vala
@@ -229,11 +229,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)) {
@@ -242,6 +250,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 f08fc92..c15fc05 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]