all: cleanup more match statements (#6616)

pull/6615/head
JalonSolov 2020-10-15 01:08:27 -04:00 committed by GitHub
parent 3795aaab5c
commit a4cc1ab7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 66 deletions

View File

@ -169,15 +169,10 @@ fn get_prompt_offset(prompt string) int {
fn (r Readline) analyse(c int) Action {
match byte(c) {
`\0` { return .eof }
0x3 { return .eof } // End of Text
0x4 { return .eof } // End of Transmission
255 { return .eof }
`\n` { return .commit_line }
`\r` { return .commit_line }
`\0`, 0x3, 0x4, 255 { return .eof } // NUL, End of Text, End of Transmission
`\n`, `\r` { return .commit_line }
`\f` { return .clear_screen } // CTRL + L
`\b` { return .delete_left } // Backspace
127 { return .delete_left } // DEL
`\b`, 127 { return .delete_left } // BS, DEL
27 { return r.analyse_control() } // ESC
1 { return .move_cursor_begining } // ^A
5 { return .move_cursor_end } // ^E
@ -186,7 +181,8 @@ fn (r Readline) analyse(c int) Action {
Action.insert_character
} else {
Action.nothing
} }
}
}
}
}
@ -201,8 +197,7 @@ fn (r Readline) analyse_control() Action {
`B` { return .history_next }
`A` { return .history_previous }
`1` { return r.analyse_extended_control() }
`2` { return r.analyse_extended_control_no_eat(byte(sequence)) }
`3` { return r.analyse_extended_control_no_eat(byte(sequence)) }
`2`, `3` { return r.analyse_extended_control_no_eat(byte(sequence)) }
else {}
}
}

View File

@ -196,7 +196,7 @@ pub fn (x Expr) str() string {
EnumVal {
return '.$x.val'
}
FloatLiteral {
FloatLiteral, IntegerLiteral {
return x.val
}
Ident {
@ -205,9 +205,6 @@ pub fn (x Expr) str() string {
IndexExpr {
return '$x.left.str()[$x.index.str()]'
}
IntegerLiteral {
return x.val
}
InfixExpr {
return '$x.left.str() $x.op.str() $x.right.str()'
}

View File

@ -137,29 +137,20 @@ pub fn (mut d Doc) get_signature(stmt ast.Stmt, file &ast.File) string {
pub fn (d Doc) get_pos(stmt ast.Stmt) token.Position {
match stmt {
ast.FnDecl { return stmt.pos }
ast.StructDecl { return stmt.pos }
ast.EnumDecl { return stmt.pos }
ast.InterfaceDecl { return stmt.pos }
ast.ConstDecl { return stmt.pos }
ast.FnDecl, ast.StructDecl, ast.EnumDecl, ast.InterfaceDecl, ast.ConstDecl { return stmt.pos }
else { return token.Position{} }
}
}
pub fn (d Doc) get_type_name(decl ast.TypeDecl) string {
match decl {
ast.SumTypeDecl { return decl.name }
ast.FnTypeDecl { return decl.name }
ast.AliasTypeDecl { return decl.name }
ast.SumTypeDecl, ast.FnTypeDecl, ast.AliasTypeDecl { return decl.name }
}
}
pub fn (d Doc) get_name(stmt ast.Stmt) string {
match stmt {
ast.FnDecl { return stmt.name }
ast.StructDecl { return stmt.name }
ast.EnumDecl { return stmt.name }
ast.InterfaceDecl { return stmt.name }
ast.FnDecl, ast.StructDecl, ast.EnumDecl, ast.InterfaceDecl { return stmt.name }
ast.TypeDecl { return d.get_type_name(stmt) }
ast.ConstDecl { return 'Constants' }
else { return typeof(stmt) }

View File

@ -1314,19 +1314,7 @@ fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string {
fn (mut g Gen) gen_assert_single_expr(e ast.Expr, t table.Type) {
unknown_value := '*unknown value*'
match e {
ast.CallExpr {
g.write(ctoslit(unknown_value))
}
ast.CastExpr {
g.write(ctoslit(unknown_value))
}
ast.IndexExpr {
g.write(ctoslit(unknown_value))
}
ast.PrefixExpr {
g.write(ctoslit(unknown_value))
}
ast.MatchExpr {
ast.CallExpr, ast.CastExpr, ast.IndexExpr, ast.PrefixExpr, ast.MatchExpr {
g.write(ctoslit(unknown_value))
}
ast.Type {
@ -1364,9 +1352,8 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
op := if assign_stmt.op == .decl_assign { token.Kind.assign } else { assign_stmt.op }
is_decl := assign_stmt.op == .decl_assign
match assign_stmt.right[0] {
ast.CallExpr { return_type = it.return_type }
ast.CallExpr, ast.MatchExpr { return_type = it.return_type }
ast.IfExpr { return_type = it.typ }
ast.MatchExpr { return_type = it.return_type }
else {}
}
// Free the old value assigned to this string var (only if it's `str = [new value]`)
@ -3677,13 +3664,7 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
} else {
*/
match field.expr {
ast.CharLiteral {
g.const_decl_simple_define(name, val)
}
ast.FloatLiteral {
g.const_decl_simple_define(name, val)
}
ast.IntegerLiteral {
ast.CharLiteral, ast.FloatLiteral, ast.IntegerLiteral {
g.const_decl_simple_define(name, val)
}
ast.ArrayInit {
@ -4292,8 +4273,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype table.Type) ?bool {
return true
} else if sym.kind == .enum_ {
is_var := match expr {
ast.SelectorExpr { true }
ast.Ident { true }
ast.SelectorExpr, ast.Ident { true }
else { false }
}
if is_var {
@ -4953,9 +4933,7 @@ fn (mut g Gen) type_default(typ table.Type) string {
else {}
}
return match sym.kind {
.interface_ { '{0}' }
.sum_type { '{0}' }
.array_fixed { '{0}' }
.interface_, .sum_type, .array_fixed { '{0}' }
else { '0' }
}
// TODO this results in
@ -4963,21 +4941,10 @@ fn (mut g Gen) type_default(typ table.Type) string {
// - Empty ee= (Empty) { . = {0} } ;
/*
return match typ {
'bool'{ '0'}
'bool', 'i8', 'i16', 'i64', 'u16', 'u32', 'u64', 'byte', 'int', 'rune', 'byteptr', 'voidptr' {'0'}
'string'{ 'tos_lit("")'}
'i8'{ '0'}
'i16'{ '0'}
'i64'{ '0'}
'u16'{ '0'}
'u32'{ '0'}
'u64'{ '0'}
'byte'{ '0'}
'int'{ '0'}
'rune'{ '0'}
'f32'{ '0.0'}
'f64'{ '0.0'}
'byteptr'{ '0'}
'voidptr'{ '0'}
else { '{0} '}
}
*/