From 28b7df87063086d0d647113322fe242da3ae5b04 Mon Sep 17 00:00:00 2001 From: Stefan Salewski Date: Wed, 4 Oct 2017 10:55:13 +0200 Subject: [PATCH] support for ModifierType --- tests/gen.nim | 82 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/tests/gen.nim b/tests/gen.nim index 89326ca..cdfb12b 100644 --- a/tests/gen.nim +++ b/tests/gen.nim @@ -1,5 +1,5 @@ # High level gobject-introspection based GTK3 bindings for the Nim programming language -# v 0.2 2017-OCT-02 +# v 0.2 2017-OCT-04 # (c) S. Salewski 2017 # https://wiki.gnome.org/Projects/GObjectIntrospection @@ -589,6 +589,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = methodBuffer.writeLine(" g_object_set_qdata(result.impl, Quark, addr(result[]))") ]# if isGObject: + assert (gCallableInfoGetCallerOwns(minfo) in {GITransfer.NOTHING, GITransfer.EVERYTHING}) # both occur, we dont care # CAUTION: some procs are advertised as constructor but do not construct new objects, # they just return existing ones as gdk_cursor_new_from_name() methodBuffer.writeLine(" let gobj = " & sym & arglist) @@ -614,6 +615,8 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = methodBuffer.writeLine(" g_object_unref(result.impl)") methodBuffer.writeLine(" assert(g_object_get_qdata(result.impl, Quark) == nil)") methodBuffer.writeLine(" g_object_set_qdata(result.impl, Quark, addr(result[]))") + elif gCallableInfoGetCallerOwns(minfo) == GITransfer.CONTAINER: + assert false elif gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: if sym == "g_closure_new_simple": let nMethods = gStructInfoGetNMethods(info) @@ -644,12 +647,19 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = methodBuffer.writeLine(" new(result, $1)" % freeMeName) methodBuffer.writeLine(" result.impl = " & sym & arglist) else: + assert gCallableInfoGetCallerOwns(minfo) == GITransfer.NOTHING methodBuffer.writeLine(" new(result)") methodBuffer.writeLine(" result.impl = " & sym & arglist) + #else: + # assert false for k, v in replist: let kk = if k[0] == '`': k[1 .. ^2] else: k methodBuffer.writeLine(" $1 = $2($3_00)" % [k, ct3nt(v), kk]) elif isProxyCandidate(ret2): + assert (gCallableInfoGetCallerOwns(minfo) in {GITransfer.NOTHING, GITransfer.EVERYTHING}) # both occur + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: echo "OOO1" + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.CONTAINER: echo "OOO2" + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.NOTHING: echo "OOO3" if info != nil: asym = asym.replace("new", "new" & manglename(gBaseInfoGetName(info))) if fixedProcNames.contains(sym): @@ -662,6 +672,10 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = let kk = if k[0] == '`': k[1 .. ^2] else: k methodBuffer.writeLine(" var $1_00 = $2($3)" % [kk, v, k]) if isGObject: + assert (gCallableInfoGetCallerOwns(minfo) in {GITransfer.NOTHING, GITransfer.EVERYTHING}) # both occur + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: echo "OOO1" + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.CONTAINER: echo "OOO2" + #if gCallableInfoGetCallerOwns(minfo) == GITransfer.NOTHING: echo "OOO3" methodBuffer.writeLine(" let gobj = " & sym & arglist) methodBuffer.writeLine(" if g_object_get_qdata(gobj, Quark) != nil:") methodBuffer.writeLine(" result = cast[$1](g_object_get_qdata(gobj, Quark))" % [genRec(ret2, true)]) @@ -705,12 +719,14 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = methodBuffer.writeLine(" new(result, $1)" % freeMeName) methodBuffer.writeLine(" result.impl = " & sym & arglist) else: + assert gCallableInfoGetCallerOwns(minfo) == GITransfer.NOTHING methodBuffer.writeLine(" new(result)") methodBuffer.writeLine(" result.impl = " & sym & arglist) for k, v in replist: let kk = if k[0] == '`': k[1 .. ^2] else: k methodBuffer.writeLine(" $1 = $2($3_00)" % [k, ct3nt(v), kk]) else: + #assert gCallableInfoGetCallerOwns(minfo) == GITransfer.NOTHING if asym == "newFromStreamAsync" and sym.contains("gdk_pixbuf_animation_new"): asym = "newAnimationFromStreamAsync" methodBuffer.writeLine("\nproc " & asym & EM & plist & " =") @@ -939,17 +955,20 @@ proc writeInterface(info: GIInterfaceInfo) = let mInfo = gInterfaceInfoGetMethod(info, j) writeMethod(info, minfo) -# the EventMask enum is very special, so we use a separate proc for it -proc writeEventMask(info: GIEnumInfo) = +# write a few of the strange enum sets +proc writeModifierType(info: GIEnumInfo) = + let we = gBaseInfoGetName(info) type T = tuple[v: int64; n: string] var s = newSeq[T]() var alias = newSeq[string]() - var flags = ($gBaseInfoGetName(info)).endsWith("Mask") + var flags = true#($gBaseInfoGetName(info)).endsWith("Flags") output.writeLine("type") let n = info.gEnumInfoGetNValues() - for j in 0 .. int: result = cmp(x.v, y.v) if result == 0: @@ -1032,8 +1054,9 @@ proc writeEnum(info: GIEnumInfo) = if flags: tname = tname[0 .. ^6] if flags: output.writeLine(" ", tname & "Flag" & EM, " {.size: sizeof(cint), pure.} = enum") - if s[0].v != 1 and s[1].v != 1: - output.writeLine(" ignoreThisDummyValue = 0") + # if s[0].v != 1 and s[1].v != 1: # wrong for 0, 2, ... + if s[0].v != 0 and s[0].v != 1: # flags may start with none = 0 or with flag1 = 1 + output.writeLine(" ignoreThisDummyValue = 0") # Nim needs start with 0 for these low level sets else: output.writeLine(" ", tname & EM, " {.size: sizeof(cint), pure.} = enum") var k: T @@ -1056,7 +1079,6 @@ proc writeEnum(info: GIEnumInfo) = if flags: output.writeLine("\n ", tname & "Flags" & EM, " {.size: sizeof(cint).} = set[$1Flag]" % [tname]) let nMethods = gEnumInfoGetNMethods(info) - ###assert(nMethods <= 0) for j in 0 ..