diff --git a/src/hcparse/hc_codegen.nim b/src/hcparse/hc_codegen.nim index 8753239..8ad864d 100644 --- a/src/hcparse/hc_codegen.nim +++ b/src/hcparse/hc_codegen.nim @@ -262,7 +262,7 @@ proc toNNode*[N]( isDistinct = false )) -func getCbindAs*(pr: CxxProc): CxxBind = +func getCbindAs*(pr: CxxProc, parent: Option[CxxObject]): CxxBind = result = pr.cbind if result.icpp.len == 0: if pr.isConstructor: @@ -273,7 +273,7 @@ func getCbindAs*(pr: CxxProc): CxxBind = if pr.isMethod(): if pr.isStatic(): result.icpp = staticMethod( - pr.getMethodOf().cxxStr(), pr.getIcppName()) + parent.get().name().cxxStr(), pr.getIcppName()) else: result.icpp.dotMethod(pr.getIcppName()) @@ -287,7 +287,8 @@ proc toNNode*[N]( def: CxxProc, conf: CodegenConf, anon: var seq[NimDecl[N]], - onConstructor: NimConstructorTarget = nctRegular + onConstructor: NimConstructorTarget = nctRegular, + parent: Option[CxxObject] = none CxxObject ): ProcDecl[N] = result = newProcDecl[N](def.nimName) @@ -327,7 +328,7 @@ proc toNNode*[N]( var ret = toNNode[N]( #[ V FIXME - does not account for template type parameters in parent classes ]# - def.methodOf.get().cxxTypeUse(), + parent.get().name().cxxTypeUse(), conf, anon) @@ -336,10 +337,10 @@ proc toNNode*[N]( result.addArgument("this", ret) - result.addPragma toNNode[N](def.getCbindAs(), conf, def.nimName) + result.addPragma toNNode[N](def.getCbindAs(parent), conf, def.nimName) else: - result.addPragma toNNode[N](def.getCbindAs(), conf, def.nimName) + result.addPragma toNNode[N](def.getCbindAs(parent), conf, def.nimName) @@ -385,14 +386,22 @@ proc toNNode*[N]( result.add toNimDecl(res) for meth in obj.methods: - result.add toNNode[N](meth, conf, anon, nctPtr) + result.add toNNode[N](meth, conf, anon, nctPtr, some obj) for n in obj.nested: result.add toNNode[N](n, conf, anon) - echov "super of", obj + # echov "super of", obj for super in obj.decl.store.getSuperTypes(obj.decl): - echov ">>", super + # echov ">>", super + var anon: seq[NimDecl[N]] + for meth in super.methods: + if not ( + meth.isStatic() or + meth.isConstructor() or + meth.isDestructor() + ): + result.add toNNode[N](meth, conf, anon, nctPtr, some obj) proc toNNode*[N](obj: CxxForward, conf: CodegenConf): ObjectDecl[N] = diff --git a/src/hcparse/hc_irgen.nim b/src/hcparse/hc_irgen.nim index f9ea086..4c537ea 100644 --- a/src/hcparse/hc_irgen.nim +++ b/src/hcparse/hc_irgen.nim @@ -365,7 +365,7 @@ proc toCxxProc*( result.constructorOf = some parent.get().name elif parent.isSome(): - result.methodOf = some parent.get().name + result.flags.incl cpfMethod # = some parent.get().name for argIdx, arg in pr.arguments: result.add toCxxArg(arg, conf, cache) diff --git a/src/hcparse/hc_tsreader.nim b/src/hcparse/hc_tsreader.nim index 129e8f6..dde23c2 100644 --- a/src/hcparse/hc_tsreader.nim +++ b/src/hcparse/hc_tsreader.nim @@ -314,7 +314,7 @@ proc toCxxProc*( ) if parent.isSome(): - result.methodOf = some parent.get().name() + result.flags.incl cpfMethod if node[0] of cppTypeQualifier: result.returnType.flags.incl ctfConst diff --git a/src/hcparse/interop_ir/wrap_store.nim b/src/hcparse/interop_ir/wrap_store.nim index b2ab431..cc7c6e6 100644 --- a/src/hcparse/interop_ir/wrap_store.nim +++ b/src/hcparse/interop_ir/wrap_store.nim @@ -288,6 +288,7 @@ type cpfSignal cpfVirtual cpfVariadic + cpfMethod CxxProc* = object of CxxBase kind*: CxxProcKind @@ -303,7 +304,6 @@ type constructorOf*: Option[CxxNamePair] destructorOf*: Option[CxxNamePair] - methodOf*: Option[CxxNamePair] CxxExprKind = enum cekIntLit @@ -905,9 +905,8 @@ func isConst*(pr: CxxProc): bool = cpfConst in pr.flags func isStatic*(pr: CxxProc): bool = cpfStatic in pr.flags func isConstructor*(pr: CxxProc): bool = pr.constructorOf.isSome() func isDestructor*(pr: CxxProc): bool = pr.destructorOf.isSome() -func isMethod*(pr: CxxProc): bool = pr.methodOf.isSome() -func getMethodOf*(pr: CxxProc): CxxNamePair = - pr.methodOf.get() +func isMethod*(pr: CxxProc): bool = cpfMethod in pr.flags + func isEmpty*(name: CxxName): bool = name.scopes.len == 0 or @@ -1586,9 +1585,6 @@ proc fixIdentsRec*( auxArg(use, cache) proc aux(decl: var CxxProc, cache: var StringNameCache) = - if decl.isMethod(): - aux(decl.methodOf.get()) - if decl.isConstructor(): aux(decl.constructorOf.get())