From 83bfd0805eb54ed6b769370917659c8d8143a151 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Wed, 19 Feb 2020 17:16:38 +1100 Subject: [PATCH] v2: prefix functions with module, except in main & builtin --- vlib/v/parser/fn.v | 11 ++++++++--- vlib/v/parser/parser.v | 19 ++++++++----------- vlib/v/table/atype_symbols.v | 3 ++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 1a01e88ffa..b1ea627548 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -8,9 +8,14 @@ import ( v.table ) -pub fn (p mut Parser) call_expr(is_c bool) ast.CallExpr { +pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { tok := p.tok - fn_name := p.check_name() + name := p.check_name() + fn_name := if mod.len > 0 { + '${mod}.$name' + } else { + name + } p.check(.lpar) args := p.call_args() node := ast.CallExpr{ @@ -147,7 +152,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl { } else { p.table.register_fn(table.Fn{ - name: name + name: p.prepend_mod(name) args: args return_type: typ is_variadic: is_variadic diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 4c5373e857..60ffa8d47b 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -519,15 +519,12 @@ fn (p mut Parser) struct_init() ast.StructInit { pub fn (p mut Parser) name_expr() ast.Expr { mut node := ast.Expr{} - is_c := p.tok.lit == 'C' && p.peek_tok.kind == .dot - if is_c { - p.next() - p.check(.dot) - } - // TODO: type is getting skipped for call_expr hence current error - // strings.new_builder becomes new_builder. - //if p.peek_tok.kind == .dot && p.tok.lit in p.table.imports { - if p.peek_tok.kind == .dot && p.tok.lit in p.imports { + is_c := p.tok.lit == 'C' + mut mod := '' + if p.peek_tok.kind == .dot && (is_c || p.tok.lit in p.imports) { + if !is_c { + mod = p.tok.lit + } p.next() p.check(.dot) } @@ -563,13 +560,13 @@ pub fn (p mut Parser) name_expr() ast.Expr { // fn call else { // println('calling $p.tok.lit') - x := p.call_expr(is_c) // TODO `node,typ :=` should work + x := p.call_expr(is_c, mod) // TODO `node,typ :=` should work node = x } } else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c || // - p.tok.lit in ['array', 'string', 'ustring', 'mapnode', 'map']) && + p.tok.lit in table.builtin_type_names) && // (p.tok.lit.len == 1 || !p.tok.lit[p.tok.lit.len - 1].is_capital()) // diff --git a/vlib/v/table/atype_symbols.v b/vlib/v/table/atype_symbols.v index 52ca187317..db67f87328 100644 --- a/vlib/v/table/atype_symbols.v +++ b/vlib/v/table/atype_symbols.v @@ -43,7 +43,8 @@ pub const ( pub const ( builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64', - 'f32', 'f64', 'string', 'char', 'byte', 'bool', 'struct', 'array', 'array_fixed', 'map'] + 'f32', 'f64', 'string', 'char', 'byte', 'bool', 'struct', 'array', 'array_fixed', 'map', + 'mapnode', 'ustring'] ) pub struct MultiReturn {