v2: prefix functions with module, except in main & builtin

pull/3779/head
joe-conigliaro 2020-02-19 17:16:38 +11:00
parent 9b271d1728
commit 83bfd0805e
3 changed files with 18 additions and 15 deletions

View File

@ -8,9 +8,14 @@ import (
v.table 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 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) p.check(.lpar)
args := p.call_args() args := p.call_args()
node := ast.CallExpr{ node := ast.CallExpr{
@ -147,7 +152,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
} }
else { else {
p.table.register_fn(table.Fn{ p.table.register_fn(table.Fn{
name: name name: p.prepend_mod(name)
args: args args: args
return_type: typ return_type: typ
is_variadic: is_variadic is_variadic: is_variadic

View File

@ -519,15 +519,12 @@ fn (p mut Parser) struct_init() ast.StructInit {
pub fn (p mut Parser) name_expr() ast.Expr { pub fn (p mut Parser) name_expr() ast.Expr {
mut node := ast.Expr{} mut node := ast.Expr{}
is_c := p.tok.lit == 'C' && p.peek_tok.kind == .dot is_c := p.tok.lit == 'C'
if is_c { mut mod := ''
p.next() if p.peek_tok.kind == .dot && (is_c || p.tok.lit in p.imports) {
p.check(.dot) if !is_c {
} mod = p.tok.lit
// 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 {
p.next() p.next()
p.check(.dot) p.check(.dot)
} }
@ -563,13 +560,13 @@ pub fn (p mut Parser) name_expr() ast.Expr {
// fn call // fn call
else { else {
// println('calling $p.tok.lit') // 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 node = x
} }
} }
else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c || 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()) (p.tok.lit.len == 1 || !p.tok.lit[p.tok.lit.len - 1].is_capital())
// //

View File

@ -43,7 +43,8 @@ pub const (
pub const ( pub const (
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64', 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 { pub struct MultiReturn {