From 4a88a28a3bf71dbd9baaf6a71b6d027ce9c59339 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 24 Oct 2019 12:47:21 +0300 Subject: [PATCH] make all necessary structs public --- vlib/benchmark/benchmark.v | 8 ++++---- vlib/builtin/map.v | 2 +- vlib/builtin/string.v | 4 ++-- vlib/compiler/parser.v | 8 +++++++- vlib/compiler/query.v | 2 +- vlib/compiler/table.v | 30 ++++++++++++++++-------------- vlib/os/os.v | 2 +- vlib/strings/builder_c.v | 2 +- vlib/strings/builder_js.v | 2 +- 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/vlib/benchmark/benchmark.v b/vlib/benchmark/benchmark.v index 40221f2fa7..e00e1f49a3 100644 --- a/vlib/benchmark/benchmark.v +++ b/vlib/benchmark/benchmark.v @@ -9,9 +9,9 @@ Example usage of this module: import benchmark mut bmark := benchmark.new_benchmark() // by default the benchmark will be verbose, i.e. it will include timing information -// if you want it to be silent, set bmark.verbose = false -for { - bmark.step() // call this when you want to advance the benchmark. +// if you want it to be silent, set bmark.verbose = false +for { + bmark.step() // call this when you want to advance the benchmark. // The timing info in bmark.step_message will be measured starting from the last call to bmark.step .... @@ -26,7 +26,7 @@ println( bmark.total_message('remarks about the benchmark') ) ``` */ -struct Benchmark{ +pub struct Benchmark{ pub mut: bench_start_time i64 bench_end_time i64 diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index c467b8cab2..595873d3f6 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -6,7 +6,7 @@ module builtin import strings -struct map { +pub struct map { element_size int root &mapnode pub: diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 58f96da0c3..e3b8691048 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -43,7 +43,7 @@ NB: A V string should be/is immutable from the point of view of import strconv -struct string { +pub struct string { //mut: //hash_cache int pub: @@ -51,7 +51,7 @@ pub: len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str). } -struct ustring { +pub struct ustring { pub: s string runes []int diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 29f9355252..39b1f96a9f 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -1100,6 +1100,9 @@ fn (p mut Parser) get_type() string { p.error('unknown type `$typ`') } } + else if !t.is_public && t.mod != p.mod && t.name != '' { + p.warn('type `$t.name` is private') + } } if typ == 'void' { p.error('unknown type `$typ`') @@ -3179,6 +3182,9 @@ fn (p mut Parser) array_init() string { fn (p mut Parser) struct_init(typ string) string { p.is_struct_init = true t := p.table.find_type(typ) + if !t.is_public && t.mod != p.mod { + p.warn('type `$t.name` is private') + } if p.gen_struct_init(typ, t) { return typ } p.scanner.fmt_out.cut(typ.len) ptr := typ.contains('*') @@ -4120,7 +4126,7 @@ fn (p mut Parser) js_decode() string { p.gen('json__jsdecode_$typ($cjson_tmp, &$tmp); cJSON_Delete($cjson_tmp);') opt_type := 'Option_$typ' p.cgen.typedefs << 'typedef Option $opt_type;' - p.table.register_type(opt_type) + p.table.register_builtin(opt_type) return opt_type } else if op == 'encode' { diff --git a/vlib/compiler/query.v b/vlib/compiler/query.v index 29ae37986d..19f1a89f2d 100644 --- a/vlib/compiler/query.v +++ b/vlib/compiler/query.v @@ -180,7 +180,7 @@ for (int i = 0; i < ${qprefix}rows.len; i++) { } else if query_one { opt_type := 'Option_$table_name' p.cgen.typedefs << 'typedef Option $opt_type;' - p.table.register_type( opt_type ) + p.table.register_builtin( opt_type ) return opt_type } else { p.register_array('array_$table_name') diff --git a/vlib/compiler/table.v b/vlib/compiler/table.v index a9dfab3530..0c29ef3748 100644 --- a/vlib/compiler/table.v +++ b/vlib/compiler/table.v @@ -234,8 +234,8 @@ fn new_table(obfuscate bool) &Table { mut t := &Table { obfuscate: obfuscate } - t.register_type('int') - t.register_type('size_t') + t.register_builtin('int') + t.register_builtin('size_t') t.register_type_with_parent('i8', 'int') t.register_type_with_parent('byte', 'int') t.register_type_with_parent('char', 'int') // for C functions only, to avoid warnings @@ -244,17 +244,17 @@ fn new_table(obfuscate bool) &Table { t.register_type_with_parent('u32', 'int') t.register_type_with_parent('i64', 'int') t.register_type_with_parent('u64', 'u32') - t.register_type('byteptr') - t.register_type('intptr') - t.register_type('f32') - t.register_type('f64') - t.register_type('rune') - t.register_type('bool') - t.register_type('void') - t.register_type('voidptr') - t.register_type('va_list') + t.register_builtin('byteptr') + t.register_builtin('intptr') + t.register_builtin('f32') + t.register_builtin('f64') + t.register_builtin('rune') + t.register_builtin('bool') + t.register_builtin('void') + t.register_builtin('voidptr') + t.register_builtin('va_list') for c in reserved_type_param_names { - t.register_type(c) + t.register_builtin(c) } t.register_const('stdin', 'int', 'main', true) t.register_const('stdout', 'int', 'main', true) @@ -390,14 +390,14 @@ fn (t &Table) known_const(name string) bool { return true } -fn (t mut Table) register_type(typ string) { +fn (t mut Table) register_builtin(typ string) { if typ.len == 0 { return } if typ in t.typesmap { return } - t.typesmap[typ] = Type{name:typ} + t.typesmap[typ] = Type{name:typ, is_public:true} } fn (p mut Parser) register_type_with_parent(strtyp, parent string) { @@ -405,6 +405,7 @@ fn (p mut Parser) register_type_with_parent(strtyp, parent string) { name: strtyp parent: parent mod: p.mod + is_public: true } p.table.register_type2(typ) } @@ -416,6 +417,7 @@ fn (t mut Table) register_type_with_parent(typ, parent string) { t.typesmap[typ] = Type { name: typ parent: parent + is_public: true //mod: mod } } diff --git a/vlib/os/os.v b/vlib/os/os.v index 8835b54d0b..d0200a3708 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -35,7 +35,7 @@ struct C.FILE { } -struct File { +pub struct File { cfile &FILE } diff --git a/vlib/strings/builder_c.v b/vlib/strings/builder_c.v index f401d08872..dadaefa61f 100644 --- a/vlib/strings/builder_c.v +++ b/vlib/strings/builder_c.v @@ -4,7 +4,7 @@ module strings -struct Builder { +pub struct Builder { mut: buf []byte pub: diff --git a/vlib/strings/builder_js.v b/vlib/strings/builder_js.v index 384f27936e..5dda15b5b8 100644 --- a/vlib/strings/builder_js.v +++ b/vlib/strings/builder_js.v @@ -4,7 +4,7 @@ module strings -struct Builder { +pub struct Builder { mut: buf []byte pub: