diff options
author | Araq <rumpf_a@web.de> | 2017-02-14 14:39:53 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-02-14 14:39:53 +0100 |
commit | 57874ed9b8f1fba887083013d277b0ac7f3c5f35 (patch) | |
tree | 829b92a9b98a921387a197dce071d6dd391eb423 /compiler/cgen.nim | |
parent | f0aef9f4e2bba8f87d3060d920f6a470450ce41b (diff) | |
download | Nim-57874ed9b8f1fba887083013d277b0ac7f3c5f35.tar.gz |
C++ codegen: emit 'extern C' for importc'ed functions that we declare a prototype for
Diffstat (limited to 'compiler/cgen.nim')
-rw-r--r-- | compiler/cgen.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 62ed9ad6e..63a7cda0e 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -715,10 +715,13 @@ proc genProcAux(m: BModule, prc: PSym) = add(generatedProc, ~"}$N") add(m.s[cfsProcs], generatedProc) -proc crossesCppBoundary(m: BModule; sym: PSym): bool {.inline.} = - result = sfCompileToCpp in m.module.flags and +proc requiresExternC(m: BModule; sym: PSym): bool {.inline.} = + result = (sfCompileToCpp in m.module.flags and sfCompileToCpp notin sym.getModule().flags and - gCmd != cmdCompileToCpp + gCmd != cmdCompileToCpp) or ( + sym.flags * {sfImportc, sfInfixCall, sfCompilerProc} == {sfImportc} and + sym.magic == mNone and + gCmd == cmdCompileToCpp) proc genProcPrototype(m: BModule, sym: PSym) = useHeader(m, sym) @@ -732,7 +735,7 @@ proc genProcPrototype(m: BModule, sym: PSym) = var header = genProcHeader(m, sym) if sfNoReturn in sym.flags and hasDeclspec in extccomp.CC[cCompiler].props: header = "__declspec(noreturn) " & header - if sym.typ.callConv != ccInline and crossesCppBoundary(m, sym): + if sym.typ.callConv != ccInline and requiresExternC(m, sym): header = "extern \"C\" " & header if sfPure in sym.flags and hasAttribute in CC[cCompiler].props: header.add(" __attribute__((naked))") |