From c3626bf2e61bc728c2e2698e2683674aa9664219 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 8 Oct 2020 08:02:04 +0300 Subject: [PATCH] vfmt: prepare for using .source_name in type_to_str --- vlib/v/parser/parse_type.v | 2 ++ vlib/v/parser/parser.v | 8 ++++---- vlib/v/parser/struct.v | 2 +- vlib/v/table/table.v | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 76a72b6201..54e882c008 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -334,6 +334,7 @@ pub fn (mut p Parser) parse_generic_template_type(name string) table.Type { idx = p.table.register_type_symbol(table.TypeSymbol{ name: name source_name: name + mod: p.mod kind: .any is_public: true }) @@ -372,6 +373,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) table.Type { kind: .generic_struct_inst name: bs_name source_name: bs_name + mod: p.mod info: table.GenericStructInst{ parent_idx: p.table.type_idxs[name] generic_types: generic_types diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ad46539ca5..8471a3cfbc 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1544,12 +1544,12 @@ fn (mut p Parser) import_syms(mut parent ast.Import) { idx := p.table.add_placeholder_type(name) typ := table.new_type(idx) prepend_mod_name := p.prepend_mod(alias) - p.table.register_type_symbol({ + p.table.register_type_symbol(table.TypeSymbol{ kind: .alias name: prepend_mod_name source_name: prepend_mod_name - parent_idx: idx mod: p.mod + parent_idx: idx info: table.Alias{ parent_type: typ language: table.Language.v @@ -1878,12 +1878,12 @@ fn (mut p Parser) type_decl() ast.TypeDecl { table.Language.v } prepend_mod_name := p.prepend_mod(name) - p.table.register_type_symbol({ + p.table.register_type_symbol(table.TypeSymbol{ kind: .alias name: prepend_mod_name source_name: prepend_mod_name - parent_idx: pid mod: p.mod + parent_idx: pid info: table.Alias{ parent_type: parent_type language: language diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index c15b5b7d0d..ab99d2ada7 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -228,6 +228,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { kind: .struct_ name: name source_name: name + mod: p.mod info: table.Struct{ fields: fields is_typedef: attrs.contains('typedef') @@ -235,7 +236,6 @@ fn (mut p Parser) struct_decl() ast.StructDecl { is_ref_only: attrs.contains('ref_only') generic_types: generic_types } - mod: p.mod is_public: is_pub } mut ret := 0 diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index e3335fc183..cff0af82b1 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -618,10 +618,15 @@ pub fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon, has_dec } pub fn (mut t Table) add_placeholder_type(name string) int { + mut modname := '' + if name.contains('.') { + modname = name.all_before_last('.') + } ph_type := TypeSymbol{ kind: .placeholder name: name source_name: name + mod: modname } // println('added placeholder: $name - $ph_type.idx') return t.register_type_symbol(ph_type)