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

parser: minor cleanup in parse_type.v (#15011)

This commit is contained in:
yuyi 2022-07-11 13:03:08 +08:00 committed by GitHub
parent 7ff20c09ca
commit a6cc4c4c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,9 +8,7 @@ import v.ast
import v.util import v.util
import v.token import v.token
const ( const maximum_inline_sum_type_variants = 3
maximum_inline_sum_type_variants = 3
)
pub fn (mut p Parser) parse_array_type(expecting token.Kind) ast.Type { pub fn (mut p Parser) parse_array_type(expecting token.Kind) ast.Type {
p.check(expecting) p.check(expecting)
@ -74,7 +72,6 @@ pub fn (mut p Parser) parse_array_type(expecting token.Kind) ast.Type {
if fixed_size <= 0 { if fixed_size <= 0 {
p.error_with_pos('fixed size cannot be zero or negative', size_expr.pos()) p.error_with_pos('fixed size cannot be zero or negative', size_expr.pos())
} }
// sym := p.table.sym(elem_type)
idx := p.table.find_or_register_array_fixed(elem_type, fixed_size, size_expr) idx := p.table.find_or_register_array_fixed(elem_type, fixed_size, size_expr)
if elem_type.has_flag(.generic) { if elem_type.has_flag(.generic) {
return ast.new_type(idx).set_flag(.generic) return ast.new_type(idx).set_flag(.generic)
@ -225,7 +222,6 @@ pub fn (mut p Parser) parse_multi_return_type() ast.Type {
// given anon name based off signature when `name` is blank // given anon name based off signature when `name` is blank
pub fn (mut p Parser) parse_fn_type(name string) ast.Type { pub fn (mut p Parser) parse_fn_type(name string) ast.Type {
// p.warn('parse fn')
p.check(.key_fn) p.check(.key_fn)
for attr in p.attrs { for attr in p.attrs {
@ -371,7 +367,7 @@ pub fn (mut p Parser) parse_sum_type_variants() []ast.TypeNode {
} }
pub fn (mut p Parser) parse_type() ast.Type { pub fn (mut p Parser) parse_type() ast.Type {
// optional // optional or result
mut is_optional := false mut is_optional := false
mut is_result := false mut is_result := false
line_nr := p.tok.line_nr line_nr := p.tok.line_nr
@ -405,7 +401,7 @@ pub fn (mut p Parser) parse_type() ast.Type {
p.error_with_pos('cannot use `mut` on struct field type', p.tok.pos()) p.error_with_pos('cannot use `mut` on struct field type', p.tok.pos())
} }
} }
if p.tok.kind == .key_mut || is_shared { // || is_atomic { if p.tok.kind == .key_mut || is_shared {
nr_muls++ nr_muls++
p.next() p.next()
} }
@ -511,7 +507,8 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
p.error('imported types must start with a capital letter') p.error('imported types must start with a capital letter')
return 0 return 0
} }
} else if p.expr_mod != '' && !p.inside_generic_params { // p.expr_mod is from the struct and not from the generic parameter } else if p.expr_mod != '' && !p.inside_generic_params {
// p.expr_mod is from the struct and not from the generic parameter
name = p.expr_mod + '.' + name name = p.expr_mod + '.' + name
} else if name in p.imported_symbols { } else if name in p.imported_symbols {
name = p.imported_symbols[name] name = p.imported_symbols[name]
@ -636,7 +633,6 @@ pub fn (mut p Parser) find_type_or_add_placeholder(name string, language ast.Lan
} }
// not found - add placeholder // not found - add placeholder
idx = p.table.add_placeholder_type(name, language) idx = p.table.add_placeholder_type(name, language)
// println('NOT FOUND: $name - adding placeholder - $idx')
return ast.new_type(idx) return ast.new_type(idx)
} }