mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: make ".contains()" private, use "in" everywhere
This commit is contained in:
parent
63f2f2b294
commit
9853323157
@ -423,7 +423,7 @@ fn (p mut Parser) fn_decl() {
|
|||||||
}
|
}
|
||||||
if f.name == 'main' || f.name == 'WinMain' {
|
if f.name == 'main' || f.name == 'WinMain' {
|
||||||
p.genln('init_consts();')
|
p.genln('init_consts();')
|
||||||
if p.table.imports.contains('os') {
|
if 'os' in p.table.imports {
|
||||||
if f.name == 'main' {
|
if f.name == 'main' {
|
||||||
p.genln('os__args = os__init_os_args(argc, argv);')
|
p.genln('os__args = os__init_os_args(argc, argv);')
|
||||||
}
|
}
|
||||||
@ -604,6 +604,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) {
|
fn (p mut Parser) fn_call(f Fn, method_ph int, receiver_var, receiver_type string) {
|
||||||
if !f.is_public && !f.is_c && !p.pref.is_test && !f.is_interface && f.mod != p.mod {
|
if !f.is_public && !f.is_c && !p.pref.is_test && !f.is_interface && f.mod != p.mod {
|
||||||
|
if f.name == 'contains' {
|
||||||
|
println('use `value in numbers` instead of `numbers.contains(value)`')
|
||||||
|
}
|
||||||
p.error('function `$f.name` is private')
|
p.error('function `$f.name` is private')
|
||||||
}
|
}
|
||||||
p.calling_c = f.is_c
|
p.calling_c = f.is_c
|
||||||
|
@ -232,10 +232,11 @@ fn (v mut V) compile() {
|
|||||||
|
|
||||||
v.generate_hotcode_reloading_declarations()
|
v.generate_hotcode_reloading_declarations()
|
||||||
|
|
||||||
imports_json := v.table.imports.contains('json')
|
imports_json := 'json' in v.table.imports
|
||||||
// TODO remove global UI hack
|
// TODO remove global UI hack
|
||||||
if v.os == .mac && ((v.pref.build_mode == .embed_vlib && v.table.imports.contains('ui')) ||
|
if v.os == .mac && ((v.pref.build_mode == .embed_vlib && 'ui' in
|
||||||
(v.pref.build_mode == .build_module && v.dir.contains('/ui'))) {
|
v.table.imports) || (v.pref.build_mode == .build_module &&
|
||||||
|
v.dir.contains('/ui'))) {
|
||||||
cgen.genln('id defaultFont = 0; // main.v')
|
cgen.genln('id defaultFont = 0; // main.v')
|
||||||
}
|
}
|
||||||
// We need the cjson header for all the json decoding user will do in default mode
|
// We need the cjson header for all the json decoding user will do in default mode
|
||||||
@ -250,13 +251,13 @@ fn (v mut V) compile() {
|
|||||||
// TODO
|
// TODO
|
||||||
//cgen.genln('i64 total_m = 0; // For counting total RAM allocated')
|
//cgen.genln('i64 total_m = 0; // For counting total RAM allocated')
|
||||||
cgen.genln('int g_test_ok = 1; ')
|
cgen.genln('int g_test_ok = 1; ')
|
||||||
if v.table.imports.contains('json') {
|
if 'json' in v.table.imports {
|
||||||
cgen.genln('
|
cgen.genln('
|
||||||
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))
|
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))
|
||||||
')
|
')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if os.args.contains('-debug_alloc') {
|
if '-debug_alloc' in os.args {
|
||||||
cgen.genln('#define DEBUG_ALLOC 1')
|
cgen.genln('#define DEBUG_ALLOC 1')
|
||||||
}
|
}
|
||||||
cgen.genln('/*================================== FNS =================================*/')
|
cgen.genln('/*================================== FNS =================================*/')
|
||||||
@ -648,7 +649,7 @@ fn new_v(args[]string) &V {
|
|||||||
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
||||||
|
|
||||||
mut dir := args.last()
|
mut dir := args.last()
|
||||||
if args.contains('run') {
|
if 'run' in args {
|
||||||
dir = get_all_after(joined_args, 'run', '')
|
dir = get_all_after(joined_args, 'run', '')
|
||||||
}
|
}
|
||||||
if dir.ends_with('/') {
|
if dir.ends_with('/') {
|
||||||
@ -685,7 +686,7 @@ fn new_v(args[]string) &V {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
// TODO embed_vlib is temporarily the default mode. It's much slower.
|
// TODO embed_vlib is temporarily the default mode. It's much slower.
|
||||||
else if !args.contains('-embed_vlib') {
|
else if !('-embed_vlib' in args) {
|
||||||
build_mode = .embed_vlib
|
build_mode = .embed_vlib
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
@ -784,24 +785,24 @@ fn new_v(args[]string) &V {
|
|||||||
rdir := os.realpath( dir )
|
rdir := os.realpath( dir )
|
||||||
rdir_name := os.filename( rdir )
|
rdir_name := os.filename( rdir )
|
||||||
|
|
||||||
obfuscate := args.contains('-obf')
|
obfuscate := '-obf' in args
|
||||||
is_repl:=args.contains('-repl')
|
is_repl := '-repl' in args
|
||||||
pref := &Preferences {
|
pref := &Preferences {
|
||||||
is_test: is_test
|
is_test: is_test
|
||||||
is_script: is_script
|
is_script: is_script
|
||||||
is_so: args.contains('-shared')
|
is_so: '-shared' in args
|
||||||
is_prod: args.contains('-prod')
|
is_prod: '-prod' in args
|
||||||
is_verbose: args.contains('-verbose')
|
is_verbose: '-verbose' in args
|
||||||
is_debuggable: args.contains('-g') // -debuggable implys debug
|
is_debuggable: '-g' in args
|
||||||
is_debug: args.contains('-debug') || args.contains('-g')
|
is_debug: '-debug' in args || '-g' in args
|
||||||
obfuscate: obfuscate
|
obfuscate: obfuscate
|
||||||
is_prof: args.contains('-prof')
|
is_prof: '-prof' in args
|
||||||
is_live: args.contains('-live')
|
is_live: '-live' in args
|
||||||
sanitize: args.contains('-sanitize')
|
sanitize: '-sanitize' in args
|
||||||
nofmt: args.contains('-nofmt')
|
nofmt: '-nofmt' in args
|
||||||
show_c_cmd: args.contains('-show_c_cmd')
|
show_c_cmd: '-show_c_cmd' in args
|
||||||
translated: args.contains('translated')
|
translated: 'translated' in args
|
||||||
is_run: args.contains('run')
|
is_run: 'run' in args
|
||||||
is_repl: is_repl
|
is_repl: is_repl
|
||||||
build_mode: build_mode
|
build_mode: build_mode
|
||||||
cflags: cflags
|
cflags: cflags
|
||||||
|
@ -176,7 +176,7 @@ fn (p mut Parser) parse(pass Pass) {
|
|||||||
for p.tok == .key_import && p.peek() != .key_const {
|
for p.tok == .key_import && p.peek() != .key_const {
|
||||||
p.imports()
|
p.imports()
|
||||||
}
|
}
|
||||||
if p.table.imports.contains('builtin') {
|
if 'builtin' in p.table.imports {
|
||||||
p.error('module `builtin` cannot be imported')
|
p.error('module `builtin` cannot be imported')
|
||||||
}
|
}
|
||||||
// save file import table
|
// save file import table
|
||||||
@ -365,7 +365,7 @@ fn (p mut Parser) import_statement() {
|
|||||||
// add import to file scope import table
|
// add import to file scope import table
|
||||||
p.import_table.register_alias(mod_alias, mod)
|
p.import_table.register_alias(mod_alias, mod)
|
||||||
// Make sure there are no duplicate imports
|
// Make sure there are no duplicate imports
|
||||||
if p.table.imports.contains(mod) {
|
if mod in p.table.imports {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.log('adding import $mod')
|
p.log('adding import $mod')
|
||||||
@ -2888,7 +2888,7 @@ fn (p mut Parser) struct_init(typ string, is_c_struct_init bool) string {
|
|||||||
if !p.first_pass() && !t.has_field(field) {
|
if !p.first_pass() && !t.has_field(field) {
|
||||||
p.error('`$t.name` has no field `$field`')
|
p.error('`$t.name` has no field `$field`')
|
||||||
}
|
}
|
||||||
if inited_fields.contains(field) {
|
if field in inited_fields {
|
||||||
p.error('already initialized field `$field` in `$t.name`')
|
p.error('already initialized field `$field` in `$t.name`')
|
||||||
}
|
}
|
||||||
f := t.find_field(field)
|
f := t.find_field(field)
|
||||||
@ -2914,7 +2914,7 @@ fn (p mut Parser) struct_init(typ string, is_c_struct_init bool) string {
|
|||||||
for i, field in t.fields {
|
for i, field in t.fields {
|
||||||
// println('### field.name')
|
// println('### field.name')
|
||||||
// Skip if this field has already been assigned to
|
// Skip if this field has already been assigned to
|
||||||
if inited_fields.contains(field.name) {
|
if field.name in inited_fields {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
field_typ := field.typ
|
field_typ := field.typ
|
||||||
|
@ -245,7 +245,7 @@ fn new_table(obfuscate bool) &Table {
|
|||||||
|
|
||||||
// If `name` is a reserved C keyword, returns `v_name` instead.
|
// If `name` is a reserved C keyword, returns `v_name` instead.
|
||||||
fn (t mut Table) var_cgen_name(name string) string {
|
fn (t mut Table) var_cgen_name(name string) string {
|
||||||
if CReserved.contains(name) {
|
if name in CReserved {
|
||||||
return 'v_$name'
|
return 'v_$name'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -254,7 +254,7 @@ fn (t mut Table) var_cgen_name(name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (t mut Table) register_module(mod string) {
|
fn (t mut Table) register_module(mod string) {
|
||||||
if t.modules.contains(mod) {
|
if mod in t.modules {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.modules << mod
|
t.modules << mod
|
||||||
@ -710,7 +710,7 @@ fn (table mut Table) cgen_name(f &Fn) string {
|
|||||||
// Avoid name conflicts (with things like abs(), print() etc).
|
// Avoid name conflicts (with things like abs(), print() etc).
|
||||||
// Generate b_abs(), b_print()
|
// Generate b_abs(), b_print()
|
||||||
// TODO duplicate functionality
|
// TODO duplicate functionality
|
||||||
if f.mod == 'builtin' && CReserved.contains(f.name) {
|
if f.mod == 'builtin' && f.name in CReserved {
|
||||||
return 'v_$name'
|
return 'v_$name'
|
||||||
}
|
}
|
||||||
// Obfuscate but skip certain names
|
// Obfuscate but skip certain names
|
||||||
|
@ -529,7 +529,7 @@ pub fn (s string) find_between(start, end string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO generic
|
// TODO generic
|
||||||
pub fn (ar []string) contains(val string) bool {
|
fn (ar []string) contains(val string) bool {
|
||||||
for s in ar {
|
for s in ar {
|
||||||
if s == val {
|
if s == val {
|
||||||
return true
|
return true
|
||||||
@ -539,7 +539,7 @@ pub fn (ar []string) contains(val string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO generic
|
// TODO generic
|
||||||
pub fn (ar []int) contains(val int) bool {
|
fn (ar []int) contains(val int) bool {
|
||||||
for i, s in ar {
|
for i, s in ar {
|
||||||
if s == val {
|
if s == val {
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user