From cf00b2fd9e00909ac6368ece9515f0e020d7813d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20M=20G=C3=B3mez?= Date: Fri, 29 Mar 2024 21:09:00 +0000 Subject: [PATCH] adds ccMember CC fixes #23434 (#23457) --- compiler/ast.nim | 1 + compiler/ccgtypes.nim | 4 +++- compiler/nir/ast2ir.nim | 2 +- compiler/nir/types2ir.nim | 2 +- compiler/pragmas.nim | 2 +- tests/cpp/t23434.nim | 17 +++++++++++++++++ 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 tests/cpp/t23434.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index ada4b66651fd..2db15901328a 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -36,6 +36,7 @@ type ccThisCall = "thiscall" # thiscall (parameters are pushed right-to-left) ccClosure = "closure" # proc has a closure ccNoConvention = "noconv" # needed for generating proper C procs sometimes + ccMember = "member" # proc is a (cpp) member TNodeKinds* = set[TNodeKind] diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 3d1a3af6f465..613beb9c52c2 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -288,7 +288,9 @@ const "N_STDCALL", "N_CDECL", "N_SAFECALL", "N_SYSCALL", # this is probably not correct for all platforms, # but one can #define it to what one wants - "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_THISCALL", "N_CLOSURE", "N_NOCONV"] + "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_THISCALL", "N_CLOSURE", "N_NOCONV", + "N_NOCONV" #ccMember is N_NOCONV + ] proc cacheGetType(tab: TypeCache; sig: SigHash): Rope = # returns nil if we need to declare this type diff --git a/compiler/nir/ast2ir.nim b/compiler/nir/ast2ir.nim index 907d45013ee8..20dfbf2a748a 100644 --- a/compiler/nir/ast2ir.nim +++ b/compiler/nir/ast2ir.nim @@ -2423,7 +2423,7 @@ proc addCallConv(c: var ProcCon; info: PackedLineInfo; callConv: TCallingConvent of ccInline: ann InlineCall of ccNoInline: ann NoinlineCall of ccThisCall: ann ThisCall - of ccNoConvention: ann NoCall + of ccNoConvention, ccMember: ann NoCall proc genProc(cOuter: var ProcCon; prc: PSym) = if prc.magic notin generatedMagics: return diff --git a/compiler/nir/types2ir.nim b/compiler/nir/types2ir.nim index cdadc4f0d0ec..8d9583486378 100644 --- a/compiler/nir/types2ir.nim +++ b/compiler/nir/types2ir.nim @@ -150,7 +150,7 @@ proc procToIr(c: var TypesCon; g: var TypeGraph; t: PType; addEnv = false): Type of ccInline: g.addAnnotation "__inline" of ccNoInline: g.addAnnotation "__noinline" of ccThisCall: g.addAnnotation "__thiscall" - of ccNoConvention: g.addAnnotation "" + of ccNoConvention, ccMember: g.addAnnotation "" for i in 0.." +line: 17 +""" +type SomeObject = object + value: int + +proc printValue(self: SomeObject) {.virtual.} = + echo "The value is ", self.value + +proc callAProc(p: proc(self: SomeObject){.noconv.}) = + let someObj = SomeObject(value: 4) + echo "calling param proc" + p(someObj) + +callAProc(printValue) \ No newline at end of file