From 0ad22b7b7cb510771fbe6c0887c82b648b7b61f6 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Sun, 10 Mar 2019 17:08:42 -0600 Subject: [PATCH] Fix compilation errors in generated API --- godot/godotapigen.nim | 2 +- godot/nim/godotmacros.nim | 8 ++++---- godot/nim/godotnim.nim | 25 ++++++++++++++----------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/godot/godotapigen.nim b/godot/godotapigen.nim index 5ec1c73..fa736c5 100644 --- a/godot/godotapigen.nim +++ b/godot/godotapigen.nim @@ -474,7 +474,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string], newNode(nkBracketExpr).addChain( ident("array"), newIntLit(staticArgsLen), ident("pointer")), newNode(nkEmpty))) - argsAlloc.add(newCommand(ident("addr"), ident("argsStatic"))) + argsAlloc.add(newDotExpr(ident("argsStatic"), ident("addr"))) vars.add(newIdentDefs(argsName, newNode(nkEmpty), argsAlloc)) let argConversions = newNode(nkStmtList) diff --git a/godot/nim/godotmacros.nim b/godot/nim/godotmacros.nim index 052b2fc..f81c7e1 100644 --- a/godot/nim/godotmacros.nim +++ b/godot/nim/godotmacros.nim @@ -197,7 +197,7 @@ proc parseType(definition, callSite: NimNode): ObjectDecl = parseError(option, "valid type specifier expected") result.isTool = isTool - if result.parentName == "": result.parentName = "Object" + if result.parentName.len == 0: result.parentName = "Object" for statement in body: case statement.kind: of nnkVarSection: @@ -444,7 +444,7 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} = let objTy = newNimNode(nnkObjectTy) typeDef.add(newNimNode(nnkRefTy).add(objTy)) objTy.add(newEmptyNode()) - if obj.parentName == "": + if obj.parentName.len == 0: objTy.add(newEmptyNode()) else: objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName))) @@ -503,11 +503,11 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} = result.add(meth.nimNode) # Register Godot object - let parentName = if obj.parentName == "": newStrLitNode("Object") + let parentName = if obj.parentName.len == 0: newStrLitNode("Object") else: newStrLitNode(obj.parentName) let classNameLit = newStrLitNode(obj.name) let classNameIdent = ident(obj.name) - let isRef: bool = if obj.parentName == "": false + let isRef: bool = if obj.parentName.len == 0: false else: obj.parentName in refClasses # Wrapping bools with a newLit is required as a temporary workaround for # https://github.com/nim-lang/Nim/issues/7375 diff --git a/godot/nim/godotnim.nim b/godot/nim/godotnim.nim index 14b788b..8dfa276 100644 --- a/godot/nim/godotnim.nim +++ b/godot/nim/godotnim.nim @@ -202,7 +202,7 @@ macro baseNativeType(T: typedesc): cstring = if typeName == "NimGodotObject": break t = getType(t[1][1]) - if baseT == "": + if baseT.len == 0: result = newNilLit() else: let rStr = newNimNode(nnkRStrLit) @@ -343,20 +343,23 @@ proc newRStrLit(s: string): NimNode {.compileTime.} = result = newNimNode(nnkRStrLit) result.strVal = s -proc toGodotName(T: typedesc): string = +macro toGodotName(T: typedesc): string = + var godotName: string if T is GodotString or T is string: - "String" + godotName = "String" elif T is SomeFloat: - "float" + godotName = "float" elif T is SomeUnsignedInt or T is SomeSignedInt: - "int" - else: + godotName = "int" + if godotName.len == 0: let nameStr = (($T.getType()[1][1].symbol).split(':')[0]) - case nameStr: - of "File", "Directory", "Thread", "Mutex", "Semaphore": - "_" & nameStr - else: - nameStr + godotName = case nameStr: + of "File", "Directory", "Thread", "Mutex", "Semaphore": + "_" & nameStr + else: + nameStr + + result = newLit(godotName) macro asCString(s: static[string]): cstring = result = newNimNode(nnkCallStrLit).add(