enum: make .str() print the name instead of the value

pull/4185/head
krischerven 2020-04-01 21:27:06 -04:00 committed by GitHub
parent 97fbc3dd61
commit 561b7a0ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -1167,6 +1167,17 @@ fn (g mut Gen) typeof_expr(node ast.TypeOf) {
} }
} }
fn (g mut Gen) enum_expr(node ast.Expr) {
match node {
ast.EnumVal {
g.write('$it.val.capitalize()')
}
else {
println(term.red('cgen.enum_expr(): bad node ' + typeof(node)))
}
}
}
fn (g mut Gen) assign_expr(node ast.AssignExpr) { fn (g mut Gen) assign_expr(node ast.AssignExpr) {
// g.write('/*assign_expr*/') // g.write('/*assign_expr*/')
mut is_call := false mut is_call := false
@ -2395,9 +2406,9 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
g.writeln('); println($tmp); string_free($tmp); //MEM2 $styp') g.writeln('); println($tmp); string_free($tmp); //MEM2 $styp')
} }
else if sym.kind == .enum_ { else if sym.kind == .enum_ {
g.write('println(int_str(') g.write('println(tos3("')
g.expr(node.args[0].expr) g.enum_expr(node.args[0].expr)
g.write('))') g.write('"))')
} }
else { else {
// `println(int_str(10))` // `println(int_str(10))`