1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: cleanup more match statements (#6616)

This commit is contained in:
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 { fn (r Readline) analyse(c int) Action {
match byte(c) { match byte(c) {
`\0` { return .eof } `\0`, 0x3, 0x4, 255 { return .eof } // NUL, End of Text, End of Transmission
0x3 { return .eof } // End of Text `\n`, `\r` { return .commit_line }
0x4 { return .eof } // End of Transmission
255 { return .eof }
`\n` { return .commit_line }
`\r` { return .commit_line }
`\f` { return .clear_screen } // CTRL + L `\f` { return .clear_screen } // CTRL + L
`\b` { return .delete_left } // Backspace `\b`, 127 { return .delete_left } // BS, DEL
127 { return .delete_left } // DEL
27 { return r.analyse_control() } // ESC 27 { return r.analyse_control() } // ESC
1 { return .move_cursor_begining } // ^A 1 { return .move_cursor_begining } // ^A
5 { return .move_cursor_end } // ^E 5 { return .move_cursor_end } // ^E
@ -186,7 +181,8 @@ fn (r Readline) analyse(c int) Action {
Action.insert_character Action.insert_character
} else { } else {
Action.nothing Action.nothing
} } }
}
} }
} }
@ -201,8 +197,7 @@ fn (r Readline) analyse_control() Action {
`B` { return .history_next } `B` { return .history_next }
`A` { return .history_previous } `A` { return .history_previous }
`1` { return r.analyse_extended_control() } `1` { return r.analyse_extended_control() }
`2` { return r.analyse_extended_control_no_eat(byte(sequence)) } `2`, `3` { return r.analyse_extended_control_no_eat(byte(sequence)) }
`3` { return r.analyse_extended_control_no_eat(byte(sequence)) }
else {} else {}
} }
} }

View File

@ -196,7 +196,7 @@ pub fn (x Expr) str() string {
EnumVal { EnumVal {
return '.$x.val' return '.$x.val'
} }
FloatLiteral { FloatLiteral, IntegerLiteral {
return x.val return x.val
} }
Ident { Ident {
@ -205,9 +205,6 @@ pub fn (x Expr) str() string {
IndexExpr { IndexExpr {
return '$x.left.str()[$x.index.str()]' return '$x.left.str()[$x.index.str()]'
} }
IntegerLiteral {
return x.val
}
InfixExpr { InfixExpr {
return '$x.left.str() $x.op.str() $x.right.str()' 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 { pub fn (d Doc) get_pos(stmt ast.Stmt) token.Position {
match stmt { match stmt {
ast.FnDecl { return stmt.pos } ast.FnDecl, ast.StructDecl, ast.EnumDecl, ast.InterfaceDecl, ast.ConstDecl { return stmt.pos }
ast.StructDecl { return stmt.pos }
ast.EnumDecl { return stmt.pos }
ast.InterfaceDecl { return stmt.pos }
ast.ConstDecl { return stmt.pos }
else { return token.Position{} } else { return token.Position{} }
} }
} }
pub fn (d Doc) get_type_name(decl ast.TypeDecl) string { pub fn (d Doc) get_type_name(decl ast.TypeDecl) string {
match decl { match decl {
ast.SumTypeDecl { return decl.name } ast.SumTypeDecl, ast.FnTypeDecl, ast.AliasTypeDecl { return decl.name }
ast.FnTypeDecl { return decl.name }
ast.AliasTypeDecl { return decl.name }
} }
} }
pub fn (d Doc) get_name(stmt ast.Stmt) string { pub fn (d Doc) get_name(stmt ast.Stmt) string {
match stmt { match stmt {
ast.FnDecl { return stmt.name } ast.FnDecl, ast.StructDecl, ast.EnumDecl, ast.InterfaceDecl { return stmt.name }
ast.StructDecl { return stmt.name }
ast.EnumDecl { return stmt.name }
ast.InterfaceDecl { return stmt.name }
ast.TypeDecl { return d.get_type_name(stmt) } ast.TypeDecl { return d.get_type_name(stmt) }
ast.ConstDecl { return 'Constants' } ast.ConstDecl { return 'Constants' }
else { return typeof(stmt) } 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) { fn (mut g Gen) gen_assert_single_expr(e ast.Expr, t table.Type) {
unknown_value := '*unknown value*' unknown_value := '*unknown value*'
match e { match e {
ast.CallExpr { ast.CallExpr, ast.CastExpr, ast.IndexExpr, ast.PrefixExpr, ast.MatchExpr {
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 {
g.write(ctoslit(unknown_value)) g.write(ctoslit(unknown_value))
} }
ast.Type { 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 } op := if assign_stmt.op == .decl_assign { token.Kind.assign } else { assign_stmt.op }
is_decl := assign_stmt.op == .decl_assign is_decl := assign_stmt.op == .decl_assign
match assign_stmt.right[0] { 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.IfExpr { return_type = it.typ }
ast.MatchExpr { return_type = it.return_type }
else {} else {}
} }
// Free the old value assigned to this string var (only if it's `str = [new value]`) // 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 { } else {
*/ */
match field.expr { match field.expr {
ast.CharLiteral { ast.CharLiteral, ast.FloatLiteral, ast.IntegerLiteral {
g.const_decl_simple_define(name, val)
}
ast.FloatLiteral {
g.const_decl_simple_define(name, val)
}
ast.IntegerLiteral {
g.const_decl_simple_define(name, val) g.const_decl_simple_define(name, val)
} }
ast.ArrayInit { ast.ArrayInit {
@ -4292,8 +4273,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype table.Type) ?bool {
return true return true
} else if sym.kind == .enum_ { } else if sym.kind == .enum_ {
is_var := match expr { is_var := match expr {
ast.SelectorExpr { true } ast.SelectorExpr, ast.Ident { true }
ast.Ident { true }
else { false } else { false }
} }
if is_var { if is_var {
@ -4953,9 +4933,7 @@ fn (mut g Gen) type_default(typ table.Type) string {
else {} else {}
} }
return match sym.kind { return match sym.kind {
.interface_ { '{0}' } .interface_, .sum_type, .array_fixed { '{0}' }
.sum_type { '{0}' }
.array_fixed { '{0}' }
else { '0' } else { '0' }
} }
// TODO this results in // TODO this results in
@ -4963,21 +4941,10 @@ fn (mut g Gen) type_default(typ table.Type) string {
// - Empty ee= (Empty) { . = {0} } ; // - Empty ee= (Empty) { . = {0} } ;
/* /*
return match typ { return match typ {
'bool'{ '0'} 'bool', 'i8', 'i16', 'i64', 'u16', 'u32', 'u64', 'byte', 'int', 'rune', 'byteptr', 'voidptr' {'0'}
'string'{ 'tos_lit("")'} 'string'{ 'tos_lit("")'}
'i8'{ '0'}
'i16'{ '0'}
'i64'{ '0'}
'u16'{ '0'}
'u32'{ '0'}
'u64'{ '0'}
'byte'{ '0'}
'int'{ '0'}
'rune'{ '0'}
'f32'{ '0.0'} 'f32'{ '0.0'}
'f64'{ '0.0'} 'f64'{ '0.0'}
'byteptr'{ '0'}
'voidptr'{ '0'}
else { '{0} '} else { '{0} '}
} }
*/ */