diff options
author | Alexey Yerin <yyp@disroot.org> | 2023-06-15 20:19:57 +0300 |
---|---|---|
committer | Alexey Yerin <yyp@disroot.org> | 2023-06-15 20:21:12 +0300 |
commit | 2a7725de05f0c3971f46fdd429cff5742b0f9a09 (patch) | |
tree | 8bc3908198c42887e823f6427f7281214b39dc5e | |
parent | 5bbe71aa7e1e90851f586696304473d00d1c599d (diff) |
Add missing pointer in some cases when emitting parameters
This should hopefully work.
-rw-r--r-- | cmd/hare-gi/context.ha | 24 | ||||
-rw-r--r-- | cmd/hare-gi/emit.ha | 26 | ||||
-rw-r--r-- | cmd/hare-gi/populate.ha | 31 |
3 files changed, 59 insertions, 22 deletions
diff --git a/cmd/hare-gi/context.ha b/cmd/hare-gi/context.ha index f1ff3d1..a1b4edf 100644 --- a/cmd/hare-gi/context.ha +++ b/cmd/hare-gi/context.ha @@ -4,12 +4,22 @@ use io; use os; use strings; +type object_type = enum { + ALIAS, + CLASS, + INTERFACE, + RECORD, + ENUM, + UNION, + CALLBACK, +}; + type namespace = struct { gir::namespace, includes: []gir::include, - // C -> Hare type mappings - types: [](str, str), + // C -> (Hare type, object type) mappings + types: [](str, str, object_type), // All imported modules. Populated during emit_empty() imports: []ident, // A list of exported symbols to make sure nothing is emitted twice @@ -104,24 +114,24 @@ fn add_import(ns: *namespace, module: ident) void = { append(ns.imports, strings::dupall(module)); }; -fn lookup_type(ctx: *context, name: str) ((*namespace, str) | void) = { +fn lookup_type(ctx: *context, name: str) ((*namespace, str, object_type) | void) = { for (let i = 0z; i < len(ctx.namespaces); i += 1) { const ns = &ctx.namespaces[i]; match (lookup_type_in_namespace(ns, name)) { - case let ident: str => - return (ns, ident); + case let obj: (str, object_type) => + return (ns, obj.0, obj.1); case void => yield; }; }; }; -fn lookup_type_in_namespace(ns: *namespace, name: str) (str | void) = { +fn lookup_type_in_namespace(ns: *namespace, name: str) ((str, object_type) | void) = { for (let i = 0z; i < len(ns.types); i += 1) { // NOTE: sometimes the requested type doesn't have a prefix // (like Gtk from GtkWindow), the second check catches that if (ns.types[i].0 == name || ns.types[i].1 == name) { - return ns.types[i].1; + return (ns.types[i].1, ns.types[i].2); }; }; }; diff --git a/cmd/hare-gi/emit.ha b/cmd/hare-gi/emit.ha index fd37110..78f9e9f 100644 --- a/cmd/hare-gi/emit.ha +++ b/cmd/hare-gi/emit.ha @@ -596,6 +596,24 @@ fn emit_type(ctx: *context, t: (gir::any_type | gir::callback)) (void | io::erro if (len(second) == 0) { const parsed = parse_ctype(t.name); defer ctype_finish(parsed); + match (parsed) { + case let id: str => + match (lookup_type(ctx, id)) { + case let obj: (*namespace, str, object_type) => + const (_, id, objtype) = obj; + if (objtype != object_type::ALIAS + && objtype != object_type::ENUM + && objtype != object_type::BITFIELD + && objtype != object_type::CALLBACK) { + fmt::fprintf( + ctx.current.output, + "*", + )?; + }; + case => void; + }; + case => void; + }; return emit_c_type(ctx, parsed); } else { const ns = match (get_namespace(ctx, first)) { @@ -607,8 +625,8 @@ fn emit_type(ctx: *context, t: (gir::any_type | gir::callback)) (void | io::erro return; }; match (lookup_type_in_namespace(ns, second)) { - case let id: str => - emit_object(ctx, ns, id)?; + case let obj: (str, object_type) => + emit_object(ctx, ns, obj.0)?; case => fmt::fprintf(ctx.current.output, "#unresolved type {}#", t.name)?; @@ -663,8 +681,8 @@ fn emit_c_type(ctx: *context, type_: ctype) (void | io::error) = { }; case let id: str => match (lookup_type(ctx, id)) { - case let pair: (*namespace, str) => - emit_object(ctx, pair.0, pair.1)?; + case let obj: (*namespace, str, object_type) => + emit_object(ctx, obj.0, obj.1)?; case => fmt::fprintf(ctx.current.output, "#unresolved type {}#", id)?; diff --git a/cmd/hare-gi/populate.ha b/cmd/hare-gi/populate.ha index 31e663b..b84d86d 100644 --- a/cmd/hare-gi/populate.ha +++ b/cmd/hare-gi/populate.ha @@ -15,48 +15,57 @@ fn populate_namespace(ctx: *context, ns: *namespace) void = { for (let i = 0z; i < len(ns.aliases); i += 1) { const alias = &ns.aliases[i]; - populate_type(ctx, alias.c_type, alias.name); + populate_type(ctx, alias.c_type, alias.name, + object_type::ALIAS); }; for (let i = 0z; i < len(ns.classes); i += 1) { const class = &ns.classes[i]; if (len(class.c_type) > 0) { - populate_type(ctx, class.c_type, class.name); + populate_type(ctx, class.c_type, class.name, + object_type::CLASS); } else { - populate_type(ctx, class.glib_type_name, class.name); + populate_type(ctx, class.glib_type_name, class.name, + object_type::CLASS); }; }; for (let i = 0z; i < len(ns.interfaces); i += 1) { const iface = &ns.interfaces[i]; - populate_type(ctx, iface.c_type, iface.name); + populate_type(ctx, iface.c_type, iface.name, + object_type::INTERFACE); }; for (let i = 0z; i < len(ns.records); i += 1) { const record = &ns.records[i]; - populate_type(ctx, record.c_type, record.name); + populate_type(ctx, record.c_type, record.name, + object_type::RECORD); }; for (let i = 0z; i < len(ns.enums); i += 1) { const enumeration = &ns.enums[i]; - populate_type(ctx, enumeration.c_type, enumeration.name); + populate_type(ctx, enumeration.c_type, enumeration.name, + object_type::ENUM); }; for (let i = 0z; i < len(ns.unions); i += 1) { const union_ = &ns.unions[i]; - populate_type(ctx, union_.c_type, union_.name); + populate_type(ctx, union_.c_type, union_.name, + object_type::UNION); }; for (let i = 0z; i < len(ns.bitfields); i += 1) { const bitfield = &ns.bitfields[i]; - populate_type(ctx, bitfield.c_type, bitfield.name); + populate_type(ctx, bitfield.c_type, bitfield.name, + object_type::ENUM); }; for (let i = 0z; i < len(ns.callbacks); i += 1) { const callback = &ns.callbacks[i]; if (len(callback.c_type) > 0) { - populate_type(ctx, callback.c_type, callback.name); + populate_type(ctx, callback.c_type, callback.name, + object_type::CALLBACK); }; }; }; -fn populate_type(ctx: *context, c: str, name: str) void = { +fn populate_type(ctx: *context, c: str, name: str, objtype: object_type) void = { if (len(c) == 0) { return; }; const hare = strings::dup(fix_identifier(name)); - append(ctx.current.types, (c, hare)); + append(ctx.current.types, (c, hare, objtype)); }; |