mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
don't allow calling private functions/methods
This commit is contained in:
parent
2a3cf0bec9
commit
c860bac7bf
@ -33,7 +33,7 @@ mut:
|
||||
fn new_cgen(out_name_c string) *CGen {
|
||||
gen := &CGen {
|
||||
out_path: '$TmpPath/$out_name_c'
|
||||
out: os.create_file('$TmpPath/$out_name_c')
|
||||
out: os.create('$TmpPath/$out_name_c')
|
||||
}
|
||||
return gen
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ mut:
|
||||
name string
|
||||
is_c bool
|
||||
receiver_typ string
|
||||
is_private bool
|
||||
is_public bool
|
||||
is_method bool
|
||||
returns_error bool
|
||||
is_decl bool // type myfn fn(int, int)
|
||||
@ -94,11 +94,12 @@ fn (p mut Parser) is_sig() bool {
|
||||
(p.file_path.contains(TmpPath))
|
||||
}
|
||||
|
||||
fn new_fn(pkg string) *Fn {
|
||||
fn new_fn(pkg string, is_public bool) *Fn {
|
||||
mut f := &Fn {
|
||||
pkg: pkg
|
||||
local_vars: [Var{}
|
||||
; MaxLocalVars]
|
||||
is_public: is_public
|
||||
}
|
||||
return f
|
||||
}
|
||||
@ -112,7 +113,7 @@ fn (p mut Parser) fn_decl() {
|
||||
}
|
||||
p.returns = false
|
||||
p.next()
|
||||
mut f := new_fn(p.pkg)
|
||||
mut f := new_fn(p.pkg, is_pub)
|
||||
// Method receiver
|
||||
mut receiver_typ := ''
|
||||
if p.tok == LPAR {
|
||||
@ -493,6 +494,9 @@ 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' {
|
||||
p.error('$p.run function `$f.name` is private $f.is_public')
|
||||
}
|
||||
p.calling_c = f.is_c
|
||||
is_print := p.is_prod &&// Hide prints only in prod
|
||||
!p.is_test &&
|
||||
|
@ -515,7 +515,7 @@ mut args := ''
|
||||
'/usr/lib/x86_64-linux-gnu/crtn.o')
|
||||
println(ress)
|
||||
if ress.contains('error:') {
|
||||
os.exit(1)
|
||||
exit(1)
|
||||
}
|
||||
println('linux cross compilation done. resulting binary: "$c.out_name"')
|
||||
}
|
||||
|
@ -511,9 +511,6 @@ fn (p mut Parser) struct_decl() {
|
||||
}
|
||||
// `pub` access mod
|
||||
access_mod := if is_pub{PUBLIC} else { PRIVATE}
|
||||
if typ.name == 'Userf' {
|
||||
println('$field_name $access_mod mut=$is_mut')
|
||||
}
|
||||
p.fgen(' ')
|
||||
field_type := p.get_type()
|
||||
is_atomic := p.tok == ATOMIC
|
||||
@ -644,8 +641,8 @@ fn (p mut Parser) check(expected Token) {
|
||||
fn (p mut Parser) error(s string) {
|
||||
// Dump all vars and types for debugging
|
||||
if false {
|
||||
file_types := os.create_file('$TmpPath/types')
|
||||
file_vars := os.create_file('$TmpPath/vars')
|
||||
file_types := os.create('$TmpPath/types')
|
||||
file_vars := os.create('$TmpPath/vars')
|
||||
// ////debug("ALL T", q.J(p.table.types))
|
||||
// os.write_to_file('/var/tmp/lang.types', '')//pes(p.table.types))
|
||||
// //debug("ALL V", q.J(p.table.vars))
|
||||
@ -662,7 +659,7 @@ fn (p mut Parser) error(s string) {
|
||||
if p.file_path.contains('v/compiler') || cur_path.contains('v/compiler') {
|
||||
println('\n====================')
|
||||
println('It looks like you are building V. It is being frequently updated every day.' +
|
||||
' Most likely there was a change that lead to this error. ')
|
||||
' If you didn\'t modify the compiler\'s code, most likely there was a change that lead to this error. ')
|
||||
println('Try to run `git pull`, that will most likely fix it.')
|
||||
println('If `git pull` doesn\'t help, re-install V from source or download a precompiled' +
|
||||
' binary from https://vlang.io')
|
||||
|
@ -239,7 +239,7 @@ fn (t Token) str() string {
|
||||
fn (t Token) is_decl() bool {
|
||||
// TODO return t in [FUNC ,TIP, CONST, IMPORT_CONST ,AT ,EOF]
|
||||
return t == ENUM || t == INTERFACE || t == FUNC || t == STRUCT || t == TIP ||
|
||||
t == CONST || t == IMPORT_CONST || t == AT || t == EOF
|
||||
t == CONST || t == IMPORT_CONST || t == AT || t == PUB || t == EOF
|
||||
}
|
||||
|
||||
const (
|
||||
|
18
os/os.v
18
os/os.v
@ -21,6 +21,12 @@ import const (
|
||||
SEEK_END
|
||||
)
|
||||
|
||||
fn C.getline(voidptr, voidptr, voidptr) int
|
||||
|
||||
fn C.ftell(fp voidptr) int
|
||||
|
||||
fn todo_remove(){}
|
||||
|
||||
fn init_os_args(argc int, _argv *byteptr) []string {
|
||||
mut args := []string
|
||||
# char** argv = (char**) _argv;
|
||||
@ -38,8 +44,6 @@ fn parse_windows_cmd_line(cmd byteptr) []string {
|
||||
return s.split(' ')
|
||||
}
|
||||
|
||||
fn C.ftell(fp voidptr) int
|
||||
|
||||
// read_file reads the file in `path` and returns the contents.
|
||||
pub fn read_file(path string) ?string {
|
||||
mut res := ''
|
||||
@ -185,6 +189,7 @@ pub fn open_append(path string) File {
|
||||
return create_file(path)
|
||||
}
|
||||
|
||||
// TODO remove
|
||||
fn create_file(file string) File {
|
||||
return create_file2(file, 'w')
|
||||
}
|
||||
@ -227,7 +232,7 @@ fn (f File) write_at(data voidptr, size, pos int) {
|
||||
C.fseek(f.cfile, 0, SEEK_END)
|
||||
}
|
||||
|
||||
fn (f File) appendln(s string) {
|
||||
pub fn (f File) appendln(s string) {
|
||||
// C.fwrite(s.str, 1, s.len, f.cfile)
|
||||
// ss := s.clone()
|
||||
// TODO perf
|
||||
@ -236,7 +241,7 @@ fn (f File) appendln(s string) {
|
||||
C.fputs('\n', f.cfile)
|
||||
}
|
||||
|
||||
fn (f File) close() {
|
||||
pub fn (f File) close() {
|
||||
C.fclose(f.cfile)
|
||||
}
|
||||
|
||||
@ -319,10 +324,6 @@ pub fn getenv(key string) string {
|
||||
return tos2(s)
|
||||
}
|
||||
|
||||
fn exit(code int) {
|
||||
C.exit(code)
|
||||
}
|
||||
|
||||
// `file_exists` returns true if `path` exists.
|
||||
pub fn file_exists(path string) bool {
|
||||
// # return access( path.str, F_OK ) != -1 ;
|
||||
@ -397,7 +398,6 @@ pub fn filename(path string) string {
|
||||
return path.all_after('/')
|
||||
}
|
||||
|
||||
fn C.getline(voidptr, voidptr, voidptr) int
|
||||
|
||||
pub fn get_line() string {
|
||||
max := 256
|
||||
|
@ -28,13 +28,13 @@ fn chdir(path string) {
|
||||
C.chdir(path.cstr())
|
||||
}
|
||||
|
||||
fn getwd() string {
|
||||
pub fn getwd() string {
|
||||
cwd := malloc(1024)
|
||||
# if (getcwd(cwd, 1024)) return tos2(cwd);
|
||||
return ''
|
||||
}
|
||||
|
||||
fn ls(path string) []string {
|
||||
pub fn ls(path string) []string {
|
||||
mut res := []string
|
||||
# DIR *dir;
|
||||
# struct dirent *ent;
|
||||
|
20
rand/rand.v
20
rand/rand.v
@ -4,19 +4,29 @@
|
||||
|
||||
module rand
|
||||
|
||||
#include <time.h>
|
||||
//#include <time.h>
|
||||
|
||||
struct C.time_t{}
|
||||
fn C.rand() int
|
||||
|
||||
fn seed() {
|
||||
struct LOLLO {
|
||||
}
|
||||
|
||||
fn kek() {
|
||||
}
|
||||
|
||||
pub fn seed() {
|
||||
# time_t t;
|
||||
# srand((unsigned) time(&t));
|
||||
}
|
||||
|
||||
fn next(max int) int {
|
||||
fn ffkek() {
|
||||
}
|
||||
|
||||
pub fn next(max int) int {
|
||||
r := 0
|
||||
# r = rand(); // TODO parser bug `rand` module name conflict
|
||||
return r % max
|
||||
}
|
||||
|
||||
struct C.time_t{}
|
||||
fn C.rand() int
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user