correct comparisons for nil strings/seqs

This commit is contained in:
Andreas Rumpf 2018-04-28 15:13:44 +02:00
commit f64f9e50cc
7 changed files with 91 additions and 23 deletions

View file

@ -980,10 +980,10 @@ proc genEcho(p: BProc, n: PNode) =
var a: TLoc
for it in n.sons:
if it.skipConv.kind == nkNilLit:
add(args, ", \"nil\"")
add(args, ", \"\"")
else:
initLocExpr(p, it, a)
addf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
addf(args, ", $1? ($1)->data:\"\"", [rdLoc(a)])
p.module.includeHeader("<base/log.h>")
linefmt(p, cpsStmts, """Genode::log(""$1);$n""", args)
else:
@ -1755,16 +1755,14 @@ proc genStrEquals(p: BProc, e: PNode, d: var TLoc) =
var x: TLoc
var a = e.sons[1]
var b = e.sons[2]
if (a.kind == nkNilLit) or (b.kind == nkNilLit):
binaryExpr(p, e, d, "($1 == $2)")
elif (a.kind in {nkStrLit..nkTripleStrLit}) and (a.strVal == ""):
if a.kind in {nkStrLit..nkTripleStrLit} and a.strVal == "":
initLocExpr(p, e.sons[2], x)
putIntoDest(p, d, e,
rfmt(nil, "(($1) && ($1)->$2 == 0)", rdLoc(x), lenField(p)))
elif (b.kind in {nkStrLit..nkTripleStrLit}) and (b.strVal == ""):
rfmt(nil, "(!($1) || ($1)->$2 == 0)", rdLoc(x), lenField(p)))
elif b.kind in {nkStrLit..nkTripleStrLit} and b.strVal == "":
initLocExpr(p, e.sons[1], x)
putIntoDest(p, d, e,
rfmt(nil, "(($1) && ($1)->$2 == 0)", rdLoc(x), lenField(p)))
rfmt(nil, "(!($1) || ($1)->$2 == 0)", rdLoc(x), lenField(p)))
else:
binaryExpr(p, e, d, "#eqStrings($1, $2)")