parser: minor cleanup in interface_decl() (#14257)

yuyi 2022-05-02 21:17:46 +08:00 committed by Jef Roosens
parent 374b6927bc
commit 93d49176c7
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 5 additions and 5 deletions

View File

@ -518,9 +518,9 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
// Parse fields or methods // Parse fields or methods
mut fields := []ast.StructField{cap: 20} mut fields := []ast.StructField{cap: 20}
mut methods := []ast.FnDecl{cap: 20} mut methods := []ast.FnDecl{cap: 20}
mut embeds := []ast.InterfaceEmbedding{}
mut is_mut := false mut is_mut := false
mut mut_pos := -1 mut mut_pos := -1
mut ifaces := []ast.InterfaceEmbedding{}
for p.tok.kind != .rcbr && p.tok.kind != .eof { for p.tok.kind != .rcbr && p.tok.kind != .eof {
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital() if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
&& (p.peek_tok.line_nr != p.tok.line_nr && (p.peek_tok.line_nr != p.tok.line_nr
@ -532,7 +532,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
iface_name = p.table.sym(iface_type).name iface_name = p.table.sym(iface_type).name
} }
comments := p.eat_comments() comments := p.eat_comments()
ifaces << ast.InterfaceEmbedding{ embeds << ast.InterfaceEmbedding{
name: iface_name name: iface_name
typ: iface_type typ: iface_type
pos: iface_pos pos: iface_pos
@ -558,7 +558,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
break break
} }
comments := p.eat_comments() comments := p.eat_comments()
ifaces << ast.InterfaceEmbedding{ embeds << ast.InterfaceEmbedding{
name: from_mod_name name: from_mod_name
typ: from_mod_typ typ: from_mod_typ
pos: p.prev_tok.pos() pos: p.prev_tok.pos()
@ -669,7 +669,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
} }
} }
} }
info.embeds = ifaces.map(it.typ) info.embeds = embeds.map(it.typ)
ts.info = info ts.info = info
p.top_level_statement_end() p.top_level_statement_end()
p.check(.rcbr) p.check(.rcbr)
@ -680,7 +680,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
typ: typ typ: typ
fields: fields fields: fields
methods: methods methods: methods
embeds: ifaces embeds: embeds
is_pub: is_pub is_pub: is_pub
attrs: attrs attrs: attrs
pos: pos pos: pos