ast: fix ParExpr.str(), RangeExpr.str(), SizeOf.str() (#6023)
parent
1fd499ed4a
commit
eb47ce1e83
|
@ -215,14 +215,23 @@ pub fn (x Expr) str() string {
|
||||||
return '${it.left.str()} $it.op.str() ${it.right.str()}'
|
return '${it.left.str()} $it.op.str() ${it.right.str()}'
|
||||||
}
|
}
|
||||||
ParExpr {
|
ParExpr {
|
||||||
return it.expr.str()
|
return '($it.expr)'
|
||||||
}
|
}
|
||||||
PrefixExpr {
|
PrefixExpr {
|
||||||
return it.op.str() + it.right.str()
|
return it.op.str() + it.right.str()
|
||||||
}
|
}
|
||||||
|
RangeExpr {
|
||||||
|
mut s := '..'
|
||||||
|
if it.has_low {s = '$it.low ' + s}
|
||||||
|
if it.has_high {s = s + ' $it.high'}
|
||||||
|
return s
|
||||||
|
}
|
||||||
SelectorExpr {
|
SelectorExpr {
|
||||||
return '${it.expr.str()}.${it.field_name}'
|
return '${it.expr.str()}.${it.field_name}'
|
||||||
}
|
}
|
||||||
|
SizeOf {
|
||||||
|
return 'sizeof($it.expr)'
|
||||||
|
}
|
||||||
StringInterLiteral {
|
StringInterLiteral {
|
||||||
mut res := []string{}
|
mut res := []string{}
|
||||||
res << "'"
|
res << "'"
|
||||||
|
@ -257,10 +266,9 @@ pub fn (x Expr) str() string {
|
||||||
UnsafeExpr {
|
UnsafeExpr {
|
||||||
return 'unsafe { $it.stmts.len stmts }'
|
return 'unsafe { $it.stmts.len stmts }'
|
||||||
}
|
}
|
||||||
else {
|
else {}
|
||||||
|
}
|
||||||
return '[unhandled expr type ${typeof(x)}]'
|
return '[unhandled expr type ${typeof(x)}]'
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (a CallArg) str() string {
|
pub fn (a CallArg) str() string {
|
||||||
|
|
|
@ -903,7 +903,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
||||||
ast.OrExpr {
|
ast.OrExpr {
|
||||||
// shouldn't happen, an or expression
|
// shouldn't happen, an or expression
|
||||||
// is always linked to a call expr
|
// is always linked to a call expr
|
||||||
panic('fmt: OrExpr should to linked to CallExpr')
|
panic('fmt: OrExpr should be linked to CallExpr')
|
||||||
}
|
}
|
||||||
ast.ParExpr {
|
ast.ParExpr {
|
||||||
f.write('(')
|
f.write('(')
|
||||||
|
|
Loading…
Reference in New Issue