From f9fc136c24fb41c6b2ead52689d7f0f9094a4cde Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 15 Feb 2022 17:17:39 +0800 Subject: [PATCH] all: rename InterfaceDecl.ifaces to InterfaceDecl.embeds (#13475) --- cmd/tools/vast/vast.v | 4 ++-- vlib/v/ast/ast.v | 9 ++++----- vlib/v/ast/table.v | 2 +- vlib/v/ast/types.v | 2 +- vlib/v/checker/checker.v | 10 +++++----- vlib/v/checker/interface.v | 27 +++++++++++++-------------- vlib/v/fmt/fmt.v | 6 +++--- vlib/v/parser/struct.v | 4 ++-- 8 files changed, 31 insertions(+), 33 deletions(-) diff --git a/cmd/tools/vast/vast.v b/cmd/tools/vast/vast.v index f6dd918a4f..d6e50f1af5 100644 --- a/cmd/tools/vast/vast.v +++ b/cmd/tools/vast/vast.v @@ -674,8 +674,8 @@ fn (t Tree) interface_decl(node ast.InterfaceDecl) &Node { obj.add('name_pos', t.pos(node.name_pos)) obj.add_terse('language', t.enum_node(node.language)) obj.add('pos', t.pos(node.pos)) - obj.add('are_ifaces_expanded', t.bool_node(node.are_ifaces_expanded)) - obj.add_terse('ifaces', t.array_node_interface_embedding(node.ifaces)) + obj.add('are_embeds_expanded', t.bool_node(node.are_embeds_expanded)) + obj.add_terse('embeds', t.array_node_interface_embedding(node.embeds)) obj.add_terse('attrs', t.array_node_attr(node.attrs)) return obj } diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index a90227f2b8..5fd8ec8767 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -362,11 +362,10 @@ pub: generic_types []Type attrs []Attr pub mut: - methods []FnDecl - fields []StructField - // - ifaces []InterfaceEmbedding - are_ifaces_expanded bool + methods []FnDecl + fields []StructField + embeds []InterfaceEmbedding + are_embeds_expanded bool } pub struct StructInitField { diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 1767d16a0b..7f4e6db9d5 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -429,7 +429,7 @@ pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) ? } else if sym.info is Interface { mut found_methods := []Fn{} mut embed_of_found_methods := []Type{} - for embed in sym.info.ifaces { + for embed in sym.info.embeds { embed_sym := t.sym(embed) if m := t.find_method(embed_sym, method_name) { found_methods << m diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 451e8fde6c..159c9ff93f 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -891,7 +891,7 @@ pub mut: types []Type // all types that implement this interface fields []StructField methods []Fn - ifaces []Type + embeds []Type // `I1 is I2` conversions conversions map[int][]Type // generic interface support diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 65020f66cb..a14c4daddc 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -500,11 +500,11 @@ pub fn (mut c Checker) expand_iface_embeds(idecl &ast.InterfaceDecl, level int, mut ares := []ast.InterfaceEmbedding{} for ie in iface_embeds { if iface_decl := c.table.interfaces[ie.typ] { - mut list := iface_decl.ifaces - if !iface_decl.are_ifaces_expanded { - list = c.expand_iface_embeds(idecl, level + 1, iface_decl.ifaces) - c.table.interfaces[ie.typ].ifaces = list - c.table.interfaces[ie.typ].are_ifaces_expanded = true + mut list := iface_decl.embeds + if !iface_decl.are_embeds_expanded { + list = c.expand_iface_embeds(idecl, level + 1, iface_decl.embeds) + c.table.interfaces[ie.typ].embeds = list + c.table.interfaces[ie.typ].are_embeds_expanded = true } for partial in list { res[partial.typ] = partial diff --git a/vlib/v/checker/interface.v b/vlib/v/checker/interface.v index d9a4dc08ac..fb7d8822ad 100644 --- a/vlib/v/checker/interface.v +++ b/vlib/v/checker/interface.v @@ -11,10 +11,10 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { mut decl_sym := c.table.sym(node.typ) is_js := node.language == .js if mut decl_sym.info is ast.Interface { - if node.ifaces.len > 0 { - all_ifaces := c.expand_iface_embeds(node, 0, node.ifaces) - // eprintln('> node.name: $node.name | node.ifaces.len: $node.ifaces.len | all_ifaces: $all_ifaces.len') - node.ifaces = all_ifaces + if node.embeds.len > 0 { + all_embeds := c.expand_iface_embeds(node, 0, node.embeds) + // eprintln('> node.name: $node.name | node.embeds.len: $node.embeds.len | all_embeds: $all_embeds.len') + node.embeds = all_embeds mut emnames := map[string]int{} mut emnames_ds := map[string]bool{} mut emnames_ds_info := map[string]bool{} @@ -29,12 +29,11 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { efnames[f.name] = i efnames_ds_info[f.name] = true } - // - for iface in all_ifaces { - isym := c.table.sym(iface.typ) + for embed in all_embeds { + isym := c.table.sym(embed.typ) if isym.kind != .interface_ { c.error('interface `$node.name` tries to embed `$isym.name`, but `$isym.name` is not an interface, but `$isym.kind`', - iface.pos) + embed.pos) continue } isym_info := isym.info as ast.Interface @@ -56,8 +55,8 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { decl_sym.methods << m.new_method_with_receiver_type(node.typ) } } - if iface_decl := c.table.interfaces[iface.typ] { - for f in iface_decl.fields { + if embed_decl := c.table.interfaces[embed.typ] { + for f in embed_decl.fields { if f.name in efnames { // already existing method name, check for conflicts ifield := node.fields[efnames[f.name]] @@ -65,7 +64,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { if ifield.typ != field.typ { exp := c.table.type_to_str(ifield.typ) got := c.table.type_to_str(field.typ) - c.error('embedded interface `$iface_decl.name` conflicts existing field: `$ifield.name`, expecting type: `$exp`, got type: `$got`', + c.error('embedded interface `$embed_decl.name` conflicts existing field: `$ifield.name`, expecting type: `$exp`, got type: `$got`', ifield.pos) } } @@ -74,7 +73,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { node.fields << f } } - for m in iface_decl.methods { + for m in embed_decl.methods { if m.name in emnames { // already existing field name, check for conflicts imethod := node.methods[emnames[m.name]] @@ -84,7 +83,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { if msg.len > 0 { em_sig := c.table.fn_signature(em_fn, skip_receiver: true) m_sig := c.table.fn_signature(m_fn, skip_receiver: true) - c.error('embedded interface `$iface_decl.name` causes conflict: $msg, for interface method `$em_sig` vs `$m_sig`', + c.error('embedded interface `$embed_decl.name` causes conflict: $msg, for interface method `$em_sig` vs `$m_sig`', imethod.pos) } } @@ -92,7 +91,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { } else { emnames[m.name] = node.methods.len mut new_method := m.new_method_with_receiver_type(node.typ) - new_method.pos = iface.pos + new_method.pos = embed.pos node.methods << new_method } } diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 47cb658fd5..0d4f3d0bee 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1071,9 +1071,9 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) { f.writeln('') } f.comments_before_field(node.pre_comments) - for iface in node.ifaces { - f.write('\t$iface.name') - f.comments(iface.comments, inline: true, has_nl: false, level: .indent) + for embed in node.embeds { + f.write('\t$embed.name') + f.comments(embed.comments, inline: true, has_nl: false, level: .indent) f.writeln('') } immut_fields := if node.mut_pos < 0 { node.fields } else { node.fields[..node.mut_pos] } diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 92ff8f6966..249f2a6ad9 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -648,7 +648,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { } } } - info.ifaces = ifaces.map(it.typ) + info.embeds = ifaces.map(it.typ) ts.info = info p.top_level_statement_end() p.check(.rcbr) @@ -659,7 +659,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { typ: typ fields: fields methods: methods - ifaces: ifaces + embeds: ifaces is_pub: is_pub attrs: attrs pos: pos