Nim namespace for cpp (#7453)
- new option --usenamespace to generate nim cpp code in its own namespace Nim - minor changes for compatibility with the new Embarcadero = Borland C++-Builder (bcc)
This commit is contained in:
parent
70c0ff1be2
commit
0ce28d15cc
8 changed files with 44 additions and 7 deletions
|
|
@ -676,6 +676,12 @@ proc generateHeaders(m: BModule) =
|
|||
add(m.s[cfsHeaders], "#undef powerpc" & tnl)
|
||||
add(m.s[cfsHeaders], "#undef unix" & tnl)
|
||||
|
||||
proc openNamespaceNim(): Rope =
|
||||
result.add("namespace Nim {" & tnl)
|
||||
|
||||
proc closeNamespaceNim(): Rope =
|
||||
result.add("}" & tnl)
|
||||
|
||||
proc closureSetup(p: BProc, prc: PSym) =
|
||||
if tfCapturesEnv notin prc.typ.flags: return
|
||||
# prc.ast[paramsPos].last contains the type we're after:
|
||||
|
|
@ -918,6 +924,7 @@ proc addIntTypes(result: var Rope) {.inline.} =
|
|||
addf(result, "#define NIM_NEW_MANGLING_RULES" & tnl &
|
||||
"#define NIM_INTBITS $1" & tnl, [
|
||||
platform.CPU[targetCPU].intSize.rope])
|
||||
if useNimNamespace : result.add("#define USE_NIM_NAMESPACE" & tnl)
|
||||
|
||||
proc getCopyright(cfile: Cfile): Rope =
|
||||
if optCompileOnly in gGlobalOptions:
|
||||
|
|
@ -1083,7 +1090,11 @@ proc genMainProc(m: BModule) =
|
|||
appcg(m, m.s[cfsProcs], nimMain,
|
||||
[m.g.mainModInit, initStackBottomCall, rope(m.labels)])
|
||||
if optNoMain notin gGlobalOptions:
|
||||
if useNimNamespace:
|
||||
m.s[cfsProcs].add closeNamespaceNim() & "using namespace Nim;" & tnl
|
||||
|
||||
appcg(m, m.s[cfsProcs], otherMain, [])
|
||||
if useNimNamespace: m.s[cfsProcs].add openNamespaceNim()
|
||||
|
||||
proc getSomeInitName(m: PSym, suffix: string): Rope =
|
||||
assert m.kind == skModule
|
||||
|
|
@ -1191,7 +1202,9 @@ proc genModule(m: BModule, cfile: Cfile): Rope =
|
|||
add(result, genSectionStart(i))
|
||||
add(result, m.s[i])
|
||||
add(result, genSectionEnd(i))
|
||||
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
|
||||
add(result, m.s[cfsInitProc])
|
||||
if useNimNamespace: result.add closeNamespaceNim()
|
||||
|
||||
proc newPreInitProc(m: BModule): BProc =
|
||||
result = newProc(nil, m)
|
||||
|
|
@ -1330,11 +1343,13 @@ proc writeHeader(m: BModule) =
|
|||
add(result, genSectionStart(i))
|
||||
add(result, m.s[i])
|
||||
add(result, genSectionEnd(i))
|
||||
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
|
||||
add(result, m.s[cfsInitProc])
|
||||
|
||||
if optGenDynLib in gGlobalOptions:
|
||||
result.add("N_LIB_IMPORT ")
|
||||
result.addf("N_CDECL(void, NimMain)(void);$n", [])
|
||||
if useNimNamespace: result.add closeNamespaceNim()
|
||||
result.addf("#endif /* $1 */$n", [guard])
|
||||
writeRope(result, m.filename)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue