From cecce80d428f7cbe0089da0feca83c33f745a58e Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 27 Jun 2018 22:46:46 +0200 Subject: Fix template codegen with static parameters (#8110) * Fix template codegen with static parameters Fixes #7477 * Move the test case to tstaticimportcpp --- compiler/ccgtypes.nim | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'compiler') diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 82508e37e..66ad34c32 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -734,6 +734,16 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = let cppName = getTypeName(m, t, sig) var i = 0 var chunkStart = 0 + + template addResultType(ty: untyped) = + if ty == nil or ty.kind == tyVoid: + result.add(~"void") + elif ty.kind == tyStatic: + internalAssert m.config, ty.n != nil + result.add ty.n.renderTree + else: + result.add getTypeDescAux(m, ty, check) + while i < cppName.data.len: if cppName.data[i] == '\'': var chunkEnd = i-1 @@ -743,13 +753,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = chunkStart = i let typeInSlot = resolveStarsInCppType(origTyp, idx + 1, stars) - if typeInSlot == nil or typeInSlot.kind == tyVoid: - result.add(~"void") - elif typeInSlot.kind == tyStatic: - internalAssert m.config, typeInSlot.n != nil - result.add typeInSlot.n.renderTree - else: - result.add getTypeDescAux(m, typeInSlot, check) + addResultType(typeInSlot) else: inc i @@ -759,7 +763,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = result = cppName & "<" for i in 1 .. origTyp.len-2: if i > 1: result.add(" COMMA ") - result.add(getTypeDescAux(m, origTyp.sons[i], check)) + addResultType(origTyp.sons[i]) result.add("> ") # always call for sideeffects: assert t.kind != tyTuple -- cgit 1.4.1-2-gfad0