diff options
author | JCWasmx86 <JCWasmx86@t-online.de> | 2022-06-05 17:30:29 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-04-29 21:00:17 +0200 |
commit | 76c47b4935b715df54cca7b5bfd7bf45981d8b62 (patch) | |
tree | db1c28b2d4dbd5ab9c34cbb04d75df8295f7fc44 | |
parent | 3b68e09ca9f4ed8d0f0d760f7b1773f2b7ebb35b (diff) | |
download | vala-76c47b4935b715df54cca7b5bfd7bf45981d8b62.tar.gz |
Added struct generation:
Only message is:
(valadbusgen:196678): vala-CRITICAL **: 17:30:19.916: vala_collection_add: assertion 'self != NULL' failed
albeit I'm not sure whether it is the fault of the code or of my environment
-rw-r--r-- | dbusgen/valadbusparser.vala | 2 | ||||
-rw-r--r-- | dbusgen/valadbusvariantmodule.vala | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/dbusgen/valadbusparser.vala b/dbusgen/valadbusparser.vala index 5321340b5..4222fdc95 100644 --- a/dbusgen/valadbusparser.vala +++ b/dbusgen/valadbusparser.vala @@ -72,6 +72,7 @@ public class Vala.DBusParser : CodeVisitor { current_ns = context.root; dbus_module = new DBusVariantModule (context); + dbus_module.current_ns = context.root; context.accept (this); } @@ -136,6 +137,7 @@ public class Vala.DBusParser : CodeVisitor { var ns = new Namespace (ns_name, get_current_src ()); current_ns.add_namespace (ns); current_ns = ns; + dbus_module.current_ns = current_ns; } } diff --git a/dbusgen/valadbusvariantmodule.vala b/dbusgen/valadbusvariantmodule.vala index d584568bb..611611b06 100644 --- a/dbusgen/valadbusvariantmodule.vala +++ b/dbusgen/valadbusvariantmodule.vala @@ -26,6 +26,8 @@ public class Vala.DBusVariantModule { public Symbol root_symbol; + public Namespace current_ns; + public DataType void_type = new VoidType (); public DataType bool_type; public DataType char_type; @@ -162,6 +164,15 @@ public class Vala.DBusVariantModule { return get_complex_type (type); } + private string generate_struct_name (VariantType type) { + return "DBusProxyStruct" + ((string) type.peek_string ()) + .replace ("(", "_1") + .replace (")", "1_") + .replace ("{", "_2") + .replace ("}", "2_") + ; + } + private bool invalid_generic_type (VariantType type) { return type.equal (VariantType.BOOLEAN) || type.equal (VariantType.BYTE) @@ -195,7 +206,7 @@ public class Vala.DBusVariantModule { var invalid_generic_arg = invalid_generic_type (element.key()) || invalid_generic_type (element.value ()); var key = get_variant_type (element.key ()); var value = get_variant_type (element.value ()); - var valid_types = !((key is ArrayType) || (value is ArrayType) || invalid_generic_arg); + var valid_types = !((key is ArrayType) || (value is ArrayType) || (key is StructValueType) || (value is StructValueType) || invalid_generic_arg); if (key != null && value != null && valid_types) { res.add_type_argument (key); res.add_type_argument (value); @@ -209,6 +220,37 @@ public class Vala.DBusVariantModule { return array; } } + } else if (type.is_tuple ()) { + var generated_name = generate_struct_name (type); + foreach (var st in current_ns.get_structs ()) { + if (st.name == generated_name) { + return new StructValueType (st, null); + } + } + var n = type.n_items (); + var able_to_add_all = true; + unowned var sub = type.first (); + var sref = new SourceReference ( + new SourceFile (context, SourceFileType.NONE, "<artificial>", null, true), + new SourceLocation (null, 0, 0), + new SourceLocation (null, 0, 1)); + var new_struct = new Struct (generated_name, sref); + new_struct.access = SymbolAccessibility.PUBLIC; + for (var i = 0; i < n; i++) { + var dt = get_dbus_type (sub.dup_string ()); + if (dt == null) { + able_to_add_all = false; + break; + } + var field = new Field ("arg%d".printf (i), dt, null); + field.access = SymbolAccessibility.PUBLIC; + new_struct.add_field (field); + sub = sub.next(); + } + if (able_to_add_all) { + current_ns.add_struct (new_struct); + return new StructValueType (new_struct, null); + } } if (!skipped_generation) { |