summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-09-05 09:28:36 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-09-05 09:28:36 +0200
commit2ef65d5cdf3d65cbfab4c39796ddb4e70e9ebb37 (patch)
treee79c7e10fc0f5aa0c0c3549e0dab97f4f3ed941b /compiler
parentb67ea9e73b63c0caf4acc697095ab74a7bf83c3b (diff)
downloadNim-2ef65d5cdf3d65cbfab4c39796ddb4e70e9ebb37.tar.gz
C++ codgen: do not emit struct literals if not possible
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 4ba85c6b3..f5c793d29 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1175,7 +1175,10 @@ proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
 
 proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
   #echo rendertree e, " ", e.isDeepConstExpr
-  if handleConstExpr(p, e, d): return
+  # inheritance in C++ does not allow struct initialization so
+  # we skip this step here:
+  if not p.module.compileToCpp:
+    if handleConstExpr(p, e, d): return
   var tmp: TLoc
   var t = e.typ.skipTypes(abstractInst)
   getTemp(p, t, tmp)
@@ -2266,7 +2269,7 @@ proc getNullValueAux(p: BProc; t: PType; obj, cons: PNode, result: var Rope; cou
 proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Rope; count: var int) =
   var base = t.sons[0]
   let oldRes = result
-  result.add "{"
+  if not p.module.compileToCpp: result.add "{"
   let oldcount = count
   if base != nil:
     base = skipTypes(base, skipPtrs)
@@ -2277,7 +2280,7 @@ proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Ro
   getNullValueAux(p, t, obj, cons, result, count)
   # do not emit '{}' as that is not valid C:
   if oldcount == count: result = oldres
-  else: result.add "}"
+  elif not p.module.compileToCpp: result.add "}"
 
 proc genConstObjConstr(p: BProc; n: PNode): Rope =
   result = nil
@@ -2287,7 +2290,8 @@ proc genConstObjConstr(p: BProc; n: PNode): Rope =
   #  addf(result, "{$1}", [genTypeInfo(p.module, t)])
   #  inc count
   getNullValueAuxT(p, t, t, t.n, n, result, count)
-  #result = "{$1}$n" % [result]
+  if p.module.compileToCpp:
+    result = "{$1}$n" % [result]
 
 proc genConstSimpleList(p: BProc, n: PNode): Rope =
   var length = sonsLen(n)