1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: public/private functions, remove lots of duplicate functionality

(string.eq, compare_strings, etc)
This commit is contained in:
Alexander Medvednikov
2019-06-27 13:14:59 +02:00
parent b846d02cb2
commit 76bf732e63
15 changed files with 109 additions and 120 deletions

View File

@ -9,6 +9,7 @@ v.c:
test: v
find .. -name '*_test.v' -print0 | xargs -0 -n1 ./v
echo "Building V examples..."
find ../examples -name '*.v' -print0 | xargs -0 -n1 ./v
clean:

View File

@ -493,7 +493,8 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
}
fn (p mut Parser) fn_call(f Fn, method_ph int, receiver_var, receiver_type string) {
if !f.is_public && !f.is_c && f.pkg != p.pkg && f.pkg != 'builtin' {
//if !f.is_public && !f.is_c && f.pkg != p.pkg && f.pkg != 'builtin' {
if !f.is_public && !f.is_c && !p.is_test && f.pkg != p.pkg {
p.error('function `$f.name` is private')
}
p.calling_c = f.is_c

View File

@ -1163,7 +1163,7 @@ fn (p mut Parser) bool_expression() string {
fn (p mut Parser) bterm() string {
ph := p.cgen.add_placeholder()
mut typ = p.expression()
is_str := typ.eq('string')
is_str := typ=='string'
tok := p.tok
// if tok in [ EQ, GT, LT, LE, GE, NE] {
if tok == EQ || tok == GT || tok == LT || tok == LE || tok == GE || tok == NE {
@ -1762,7 +1762,7 @@ fn (p mut Parser) expression() string {
p.cgen('/* expr start*/')
ph := p.cgen.add_placeholder()
mut typ := p.term()
is_str := typ.eq('string')
is_str := typ=='string'
// a << b ==> array2_push(&a, b)
if p.tok == LEFT_SHIFT {
if typ.contains('array_') {

View File

@ -442,7 +442,7 @@ fn (p mut Parser) _check_types(got, expected string, throw bool) bool {
return true
}
// Todo void* allows everything right now
if got.eq('void*') || expected.eq('void*') {
if got=='void*' || expected=='void*' {
// if !p.builtin_pkg {
if p.is_play {
return false
@ -451,17 +451,17 @@ fn (p mut Parser) _check_types(got, expected string, throw bool) bool {
}
// TODO only allow numeric consts to be assigned to bytes, and
// throw an error if they are bigger than 255
if got.eq('int') && expected.eq('byte') {
if got=='int' && expected=='byte' {
return true
}
if got.eq('byteptr') && expected.eq('byte*') {
if got=='byteptr' && expected=='byte*' {
return true
}
if got.eq('int') && expected.eq('byte*') {
if got=='int' && expected=='byte*' {
return true
}
// byteptr += int
if got.eq('int') && expected.eq('byteptr') {
if got=='int' && expected=='byteptr' {
return true
}
if got == 'Option' && expected.starts_with('Option_') {
@ -487,7 +487,7 @@ fn (p mut Parser) _check_types(got, expected string, throw bool) bool {
// return true
// }
// Allow pointer arithmetic
if expected.eq('void*') && got.eq('int') {
if expected=='void*' && got=='int' {
return true
}
}