all: update`import ()` and `[]array`

pull/4607/head
yuyi 2020-04-26 19:49:31 +08:00 committed by GitHub
parent 7b39ab6d06
commit 9f4d498ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 181 additions and 254 deletions

View File

@ -10,11 +10,11 @@ fn main() {
min_str_len := 20
max_str_len := 40
println('Generating $sample_size strings between $min_str_len - $max_str_len chars long...')
mut bytepile := []byte
mut bytepile := []byte{}
for _ in 0 .. sample_size * max_str_len {
bytepile << byte(40 + rand.next(125 - 40))
}
mut str_lens := []int
mut str_lens := []int{}
for _ in 0 .. sample_size {
str_lens << min_str_len + rand.next(max_str_len - min_str_len)
}

View File

@ -34,7 +34,7 @@ pub fn (mh mut TestMessageHandler) append_message(msg string) {
}
pub fn new_test_session(_vargs string) TestSession {
mut skip_files := []string
mut skip_files := []string{}
skip_files << '_non_existing_'
$if solaris {
skip_files << "examples/gg/gg2.v"
@ -59,7 +59,7 @@ pub fn (ts mut TestSession) init() {
pub fn (ts mut TestSession) test() {
ts.init()
mut remaining_files := []string
mut remaining_files := []string{}
for dot_relative_file in ts.files {
relative_file := dot_relative_file.replace('./', '')
file := os.real_path(relative_file)
@ -225,7 +225,7 @@ pub fn v_build_failing(zargs string, folder string) bool {
eprintln('v compiler args: "$vargs"')
mut session := new_test_session(vargs)
files := os.walk_ext(os.join_path(parent_dir, folder), '.v')
mut mains := []string
mut mains := []string{}
for f in files {
if !f.contains('modules') && !f.contains('preludes') {
$if windows {

View File

@ -51,7 +51,7 @@ fn (c Context) compare_versions() {
// The first is the baseline, against which all the others will be compared.
// It is the fastest, since hello_world.v has only a single println in it,
mut perf_files := []string
mut perf_files := []string{}
perf_files << c.compare_v_performance('source_hello', [
'vprod @DEBUG@ -o source.c examples/hello_world.v',
'vprod -o source.c examples/hello_world.v',
@ -147,7 +147,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
timestamp_b,_ := vgit.line_to_timestamp_and_commit(scripting.run('cd $c.b/ ; git rev-list -n1 --timestamp HEAD'))
debug_option_a := if timestamp_a > 1570877641 { '-g ' } else { '-debug ' }
debug_option_b := if timestamp_b > 1570877641 { '-g ' } else { '-debug ' }
mut hyperfine_commands_arguments := []string
mut hyperfine_commands_arguments := []string{}
for cmd in commands {
println(cmd)
}

View File

@ -20,7 +20,7 @@ fn (context Context) header() {
println('module ${context.module_name}')
println('')
allfiles := context.files.join(' ')
mut options := []string
mut options := []string{}
if context.prefix.len > 0 {
options << '-p ${context.prefix}'
}

View File

@ -74,7 +74,7 @@ fn main() {
eprintln('vfmt env_vflags_and_os_args: ' + args.str())
eprintln('vfmt possible_files: ' + possible_files.str())
}
mut files := []string
mut files := []string{}
for file in possible_files {
if !file.ends_with('.v') && !file.ends_with('.vv') {
verror('v fmt can only be used on .v files.\nOffending file: "$file"')
@ -90,7 +90,7 @@ fn main() {
vhelp.show_topic('fmt')
exit(0)
}
mut cli_args_no_files := []string
mut cli_args_no_files := []string{}
for a in os.args {
if a !in files {
cli_args_no_files << a
@ -287,7 +287,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
all_files_in_pfolder := os.ls(pfolder) or {
panic(err)
}
mut vfiles := []string
mut vfiles := []string{}
for f in all_files_in_pfolder {
vf := os.join_path(pfolder, f)
if f.starts_with('.') || !f.ends_with('.v') || os.is_dir(vf) {

View File

@ -70,7 +70,7 @@ fn main(){
exit(0)
}
mut files := []string
mut files := []string{}
locations := fp.finalize() or { eprintln('Error: ' + err) exit(1) }
for xloc in locations {
loc := os.real_path(xloc)

View File

@ -275,7 +275,7 @@ fn vpm_help() {
}
fn vcs_used_in_dir(dir string) ?[]string {
mut vcs := []string
mut vcs := []string{}
for repo_subfolder in supported_vcs_folders {
checked_folder := os.real_path(os.join_path(dir,repo_subfolder))
if os.is_dir(checked_folder) {
@ -292,7 +292,7 @@ fn get_installed_modules() []string {
dirs := os.ls(settings.vmodules_path) or {
return []
}
mut modules := []string
mut modules := []string{}
for dir in dirs {
adir := os.join_path(settings.vmodules_path,dir)
if dir in excluded_dirs || !os.is_dir(adir) {
@ -323,7 +323,7 @@ fn get_all_modules() []string {
}
s := r.text
mut read_len := 0
mut modules := []string
mut modules := []string{}
for read_len < s.len {
mut start_token := '<a href="/mod'
end_token := '</a>'
@ -359,7 +359,7 @@ fn resolve_dependencies(name, module_path string, module_names []string) {
return
}
vmod := parse_vmod(data)
mut deps := []string
mut deps := []string{}
// filter out dependencies that were already specified by the user
for d in vmod.deps {
if d !in module_names {
@ -440,7 +440,7 @@ fn verbose_println(s string) {
}
fn get_module_meta_info(name string) ?Mod {
mut errors := []string
mut errors := []string{}
for server_url in default_vpm_server_urls {
modurl := server_url + '/jsmod/$name'
verbose_println('Retrieving module metadata from: $modurl ...')

View File

@ -54,7 +54,7 @@ fn v_test_formatting(vargs string) {
}
fn v_files() []string {
mut files_that_can_be_formatted := []string
mut files_that_can_be_formatted := []string{}
all_test_files := os.walk_ext('.', '.v')
for tfile in all_test_files {
if tfile in known_failing_exceptions {

View File

@ -1,9 +1,7 @@
module main
import (
cli
os
)
import cli
import os
fn main() {
mut cmd := cli.Command{

View File

@ -1,8 +1,6 @@
module main
import (
some_module
)
import some_module
fn main(){
mut sub := some_module.get_subscriber()

View File

@ -1,8 +1,6 @@
module some_module
import (
eventbus
)
import eventbus
const (
eb = eventbus.new()

View File

@ -12,8 +12,8 @@ fn expr_to_rev_pol(expr string) ?[]string {
if expr == '' {
return error('err: empty expression')
}
mut stack := []string
mut rev_pol := []string
mut stack := []string{}
mut rev_pol := []string{}
mut pos := 0
for pos<expr.len {
mut end_pos := pos

View File

@ -9,7 +9,7 @@ const (
fn main() {
rand.seed(time.now().unix)
rand.next(MAX) // skip the first
mut arr := []int
mut arr := []int{}
for _ in 0..LEN {
arr << rand.next(MAX)
}

View File

@ -1,10 +1,8 @@
module main
import (
vweb
vweb.assets
time
)
import vweb
import vweb.assets
import time
const (
port = 8081

View File

@ -33,7 +33,7 @@ fn main() {
// Creates an array of words from a given string
fn extract_words(contents string) []string {
mut splitted := []string
mut splitted := []string{}
for space_splitted in contents.to_lower().split(' ') {
if space_splitted.contains('\n') {
splitted << space_splitted.split('\n')
@ -43,7 +43,7 @@ fn extract_words(contents string) []string {
}
}
mut results := []string
mut results := []string{}
for s in splitted {
result := filter_word(s)
if result == '' {

View File

@ -1,11 +1,9 @@
module main
import (
vweb
time
pg
json
)
import vweb
import time
import pg
import json
pub struct App {
mut:
@ -74,4 +72,3 @@ pub fn (app mut App) articles() {
fn (app mut App) time() {
app.vweb.text(time.now().format())
}

View File

@ -145,7 +145,7 @@ fn test_insert() {
// assert a[4] == 5
// assert a[3] == 2
// assert a.len == 5
// mut b := []f64
// mut b := []f64{}
// assert b.len == 0
// b.insert(0, f64(1.1))
// assert b.len == 1
@ -155,12 +155,12 @@ fn test_insert() {
// It depends on array.insert
// -----------------------------
// fn test_prepend() {
// mut a := []int
// mut a := []int{}
// assert a.len == 0
// a.prepend(1)
// assert a.len == 1
// assert a[0] == 1
// mut b := []f64
// mut b := []f64{}
// assert b.len == 0
// b.prepend(f64(1.1))
// assert b.len == 1

View File

@ -1,9 +1,7 @@
module cli
import (
term
strings
)
import term
import strings
const (
BASE_INDENT = 2

View File

@ -2,11 +2,9 @@
// but since Wayland isn't extremely adopted, we are covering almost all Linux distros.
module clipboard
import (
time
sync
math
)
import time
import sync
import math
#flag -lX11
#include <X11/Xlib.h>

View File

@ -7,9 +7,7 @@
module aes
import (
crypto.internal.subtle
)
import crypto.internal.subtle
pub const (
// The AES block size in bytes.

View File

@ -13,10 +13,8 @@
module aes
import (
crypto.cipher
crypto.internal.subtle
)
import crypto.cipher
import crypto.internal.subtle
struct AesCbc {
mut:

View File

@ -37,9 +37,7 @@
module aes
import (
encoding.binary
)
import encoding.binary
// Encrypt one block from src into dst, using the expanded key xk.
fn encrypt_block_generic(xk []u32, dst, src []byte) {

View File

@ -4,11 +4,6 @@
module aes
import (
// crypto.cipher
// crypto.internal.subtle
)
// new_cipher_generic creates and returns a new cipher.Block
// this is the generiv v version, no arch optimisations
fn new_cipher_generic(key []byte) AesCipher {

View File

@ -8,10 +8,8 @@
module md5
import (
math.bits
encoding.binary
)
import math.bits
import encoding.binary
fn block_generic(dig mut Digest, p []byte) {
// load state

View File

@ -7,10 +7,8 @@
// Last commit: https://github.com/golang/go/commit/3ce865d7a0b88714cc433454ae2370a105210c01
module sha512
import (
crypto
encoding.binary
)
import crypto
import encoding.binary
pub const (
// size is the size, in bytes, of a SHA-512 checksum.
@ -322,4 +320,3 @@ pub fn hexhash_512_224(s string) string {
pub fn hexhash_512_256(s string) string {
return sum512_256(s.bytes()).hex()
}

View File

@ -46,7 +46,7 @@ pub fn (r mut Reader) read() ?[]string {
// Once we have multi dimensional array
// pub fn (r mut Reader) read_all() ?[][]string {
// mut records := []string
// mut records := []string{}
// for {
// record := r.read_record() or {
// if error(err).error == err_eof.error {
@ -110,7 +110,7 @@ fn (r mut Reader) read_record() ?[]string {
}
break
}
mut fields := []string
mut fields := []string{}
mut i := -1
for {
// not quoted

View File

@ -1,6 +1,4 @@
import (
eventbus
)
import eventbus
struct EventData {
data string

View File

@ -63,7 +63,7 @@ pub fn (f Flag) str() string {
+' desc: $f.val_desc'
}
pub fn (af []Flag) str() string {
mut res := []string
mut res := []string{}
res << '\n []Flag = ['
for f in af {
res << f.str()
@ -140,8 +140,8 @@ fn (fs mut FlagParser) add_flag(name string, abbr byte, usage string, desc strin
// - found arguments and corresponding values are removed from args list
fn (fs mut FlagParser) parse_value(longhand string, shorthand byte) []string {
full := '--$longhand'
mut found_entries := []string
mut to_delete := []int
mut found_entries := []string{}
mut to_delete := []int{}
mut should_skip_one := false
for i, arg in fs.args {
if should_skip_one {
@ -257,7 +257,7 @@ pub fn (fs mut FlagParser) bool(name string, abbr byte, bdefault bool, usage str
pub fn (fs mut FlagParser) int_multi(name string, abbr byte, usage string) []int {
fs.add_flag(name, abbr, usage, '<multiple ints>')
parsed := fs.parse_value(name, abbr)
mut value := []int
mut value := []int{}
for val in parsed {
value << val.int()
}
@ -294,7 +294,7 @@ pub fn (fs mut FlagParser) int(name string, abbr byte, idefault int, usage strin
pub fn (fs mut FlagParser) float_multi(name string, abbr byte, usage string) []f64 {
fs.add_flag(name, abbr, usage, '<multiple floats>')
parsed := fs.parse_value(name, abbr)
mut value := []f64
mut value := []f64{}
for val in parsed {
value << val.f64()
}
@ -421,7 +421,7 @@ pub fn (fs FlagParser) usage() string {
use += 'This application does not expect any arguments\n\n'
goto end_of_arguments_handling
}
mut s:= []string
mut s:= []string{}
if positive_min_arg { s << 'at least $fs.min_free_args' }
if positive_max_arg { s << 'at most $fs.max_free_args' }
if positive_min_arg && positive_max_arg && fs.min_free_args == fs.max_free_args {

View File

@ -3,16 +3,15 @@
// that can be found in the LICENSE file.
module gg2
import (
glm
gx
os
sokol
sokol.sapp
sokol.sgl
sokol.gfx
sokol.sfons
)
import glm
import gx
import os
import sokol
import sokol.sapp
import sokol.sgl
import sokol.gfx
import sokol.sfons
const (
default_font_size = 24
)

View File

@ -1,10 +1,8 @@
module log
import (
os
time
term
)
import os
import time
import term
pub enum Level {
fatal = 1

View File

@ -48,7 +48,7 @@ pub fn log_factorial(n f64) f64 {
fn log_factorial_asymptotic_expansion(n int) f64 {
m := 6
mut term := []f64
mut term := []f64{}
xx := f64((n + 1) * (n + 1))
mut xj := f64(n + 1)

View File

@ -114,7 +114,7 @@ pub fn mode(arr []f64) f64 {
if arr.len == 0 {
return f64(0)
}
mut freqs := []int
mut freqs := []int{}
for v in arr {
freqs<<freq(arr,v)
}

View File

@ -247,7 +247,7 @@ fn test_range() {
}
fn test_passing_empty() {
data := []f64
data := []f64{}
assert stats.freq(data,0) == 0
assert stats.mean(data) == f64(0)
assert stats.geometric_mean(data) == f64(0)
@ -264,4 +264,3 @@ fn test_passing_empty() {
assert stats.max(data) == f64(0)
assert stats.range(data) == f64(0)
}

View File

@ -42,7 +42,7 @@ mut:
}
fn (dtp DTP) read() []byte {
mut data := []byte
mut data := []byte{}
for {
buf, len := dtp.sock.recv(1024)
if len == 0 { break }
@ -247,7 +247,7 @@ pub fn (ftp FTP) dir() ?[]string {
}
dtp.close()
mut dir := []string
mut dir := []string{}
sdir := string(byteptr(list_dir.data))
for lfile in sdir.split('\n') {
if lfile.len >1 {

View File

@ -3,11 +3,9 @@
// that can be found in the LICENSE file.
module http
import (
time
arrays
strings
)
import time
import arrays
import strings
pub struct Cookie {
pub mut:

View File

@ -1,7 +1,5 @@
import (
net.http
time
)
import net.http
import time
struct SetCookieTestCase {
cookie &http.Cookie

View File

@ -128,7 +128,7 @@ pub fn get_text(url string) string {
}
pub fn url_encode_form_data(data map[string]string) string {
mut pieces := []string
mut pieces := []string{}
for _key, _value in data {
key := urllib.query_escape(_key)
value := urllib.query_escape(_value)
@ -151,7 +151,7 @@ fn build_url_from_fetch(_url string, config FetchConfig) ?string {
if params.keys().len == 0 {
return url.str()
}
mut pieces := []string
mut pieces := []string{}
for key in params.keys() {
pieces << '${key}=${params[key]}'
}
@ -314,7 +314,7 @@ fn parse_response(resp string) Response {
fn (req &Request) build_request_headers(method, host_name, path string) string {
ua := req.user_agent
mut uheaders := []string
mut uheaders := []string{}
if 'Host' !in req.headers {
uheaders << 'Host: $host_name\r\n'
}
@ -338,7 +338,7 @@ fn (req &Request) build_request_cookies_header() string {
if req.cookies.keys().len < 1 {
return ''
}
mut cookie := []string
mut cookie := []string{}
for key, val in req.cookies {
cookie << '$key: $val'
}

View File

@ -257,7 +257,7 @@ fn escape(s string, mode EncodingMode) string {
return s
}
buf := [byte(0)].repeat(64)
mut t := []byte
mut t := []byte{}
required := s.len + 2 * hex_count
if required <= buf.len {
t = buf[..required]
@ -883,7 +883,7 @@ pub fn (v Values) encode() string {
return ''
}
mut buf := strings.new_builder(200)
mut keys := []string
mut keys := []string{}
for k, _ in v.data {
keys << k
}
@ -922,7 +922,7 @@ fn resolve_path(base, ref string) string {
if full == '' {
return ''
}
mut dst := []string
mut dst := []string{}
src := full.split('/')
for _, elem in src {
match elem {
@ -1131,4 +1131,3 @@ fn unhex(c byte) byte {
}
return 0
}

View File

@ -1,13 +1,11 @@
module main
import (
net.websocket
eventbus
time
readline
term
benchmark
)
import net.websocket
import eventbus
import time
import readline
import term
import benchmark
const (
eb = eventbus.new()

View File

@ -1,12 +1,10 @@
module websocket
import (
time
rand
math
crypto.sha1
encoding.base64
)
import time
import rand
import math
import crypto.sha1
import encoding.base64
fn htonl64(payload_len u64) byteptr {
mut ret := malloc(8)
@ -46,7 +44,7 @@ fn create_key_challenge_response(seckey string) string {
}
fn get_nonce() string {
mut nonce := []byte
mut nonce := []byte{}
alphanum := "0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz"
for i in 0..18 {
nonce << alphanum[rand.next(61)]

View File

@ -1,13 +1,11 @@
module websocket
import (
net
net.urllib
encoding.base64
eventbus
sync
net.websocket.logger
)
import net
import net.urllib
import encoding.base64
import eventbus
import sync
import net.websocket.logger
const (
l = logger.new("ws")
@ -542,7 +540,7 @@ pub fn (ws mut Client) read() int {
goto free_data
return -1
}
mut payload := []byte
mut payload := []byte{}
if payload_len > 0 {
payload = [`0`].repeat(int(payload_len))
C.memcpy(payload.data, &data[header_len], payload_len)

View File

@ -77,7 +77,7 @@ mut:
}
fn init_os_args_wide(argc int, argv &byteptr) []string {
mut args := []string
mut args := []string{}
for i in 0..argc {
args << string_from_wide(&u16(argv[i]))
}
@ -86,7 +86,7 @@ fn init_os_args_wide(argc int, argv &byteptr) []string {
pub fn ls(path string) ?[]string {
mut find_file_data := Win32finddata{}
mut dir_files := []string
mut dir_files := []string{}
// We can also check if the handle is valid. but using is_dir instead
// h_find_dir := C.FindFirstFile(path.str, &find_file_data)
// if (INVALID_HANDLE_VALUE == h_find_dir) {

View File

@ -3,7 +3,7 @@ import rand
import time
fn show_u32s(a []u32){
mut res := []string
mut res := []string{}
for x in a {
res << x.str()
}

View File

@ -3,7 +3,7 @@ import rand
import time
fn show_u64s(a []u64){
mut res := []string
mut res := []string{}
for x in a {
res << x.str()
}

View File

@ -2232,7 +2232,7 @@ pub fn (re mut RE) find(in_txt string) (int,int) {
// find all the non overlapping occurrences of the match pattern
pub fn (re mut RE) find_all(in_txt string) []int {
mut i := 0
mut res := []int
mut res := []int{}
mut ls := -1
for i < in_txt.len {
s,e := re.find(in_txt[i..])

View File

@ -3,10 +3,8 @@
* String to float Test
*
**********************************************************************/
import (
strconv
strconv.atofq
)
import strconv
import strconv.atofq
fn test_atof() {
//

View File

@ -2010,7 +2010,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
} else {
g.writeln('($styp){')
}
// mut fields := []string
// mut fields := []string{}
mut inited_fields := []string{} // TODO this is done in checker, move to ast node
/*
if struct_init.fields.len == 0 && struct_init.exprs.len > 0 {

View File

@ -367,7 +367,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
}
// Generate tmp vars for values that have to be freed.
/*
mut tmps := []string
mut tmps := []string{}
for arg in node.args {
if arg.typ == table.string_type_idx || is_print {
tmp := g.new_tmp_var()

View File

@ -1,14 +1,12 @@
module parser
import (
v.ast
v.gen
v.table
v.checker
// v.eval
v.pref
term
)
import v.ast
import v.gen
import v.table
import v.checker
//import v.eval
import v.pref
import term
fn test_eval() {
/*

View File

@ -1 +0,0 @@
empty import

View File

@ -1,7 +0,0 @@
import (
// no module
)
fn main() {
println('empty import')
}

View File

@ -1,7 +1,5 @@
import (
os
time
)
import os
import time
const (
vexe = os.getenv('VEXE')

View File

@ -1,11 +1,9 @@
import (
os
time as t
crypto.sha256
math
log as l
crypto.sha512
)
import os
import time as t
import crypto.sha256
import math
import log as l
import crypto.sha512
struct TestAliasInStruct {
time t.Time

View File

@ -1,10 +1,7 @@
// Build and run files in ./prod/ folder, comparing their output to *.expected.txt files.
// (Similar to REPL tests, but in -prod mode.)
// import os
import (
v.tests.repl.runner
benchmark
)
import v.tests.repl.runner
import benchmark
fn test_all_v_prod_files() {
// TODO: Fix running this test on Windows:

View File

@ -130,7 +130,7 @@ $diff
pub fn new_options() RunnerOptions {
vexec := full_path_to_v(5)
mut wd := os.getwd()
mut files := []string
mut files := []string{}
if os.args.len > 1 {
files = os.args[1..]
} else {
@ -148,7 +148,7 @@ pub fn new_options() RunnerOptions {
pub fn new_prod_options() RunnerOptions {
wd := os.getwd()
vexec := full_path_to_v(4)
mut files := []string
mut files := []string{}
if os.args.len > 1 {
files = os.args[1..]
} else {

View File

@ -8,8 +8,8 @@ fn test_typeof_on_simple_expressions() {
}
fn test_typeof_on_atypes() {
aint := []int
astring := []string
aint := []int{}
astring := []string{}
assert typeof(aint) == 'array_int'
assert typeof(astring) == 'array_string'
}

View File

@ -3,11 +3,9 @@ module assets
// this module provides an AssetManager for combining
// and caching javascript & css.
import (
os
time
crypto.md5
)
import os
import time
import crypto.md5
const (
UnknownAssetTypeError = 'vweb.assets: unknown asset type'

View File

@ -1,7 +1,5 @@
import (
vweb.assets
os
)
import vweb.assets
import os
// clean_cache_dir used before and after tests that write to a cache directory.
// Because of parallel compilation and therefore test running,

View File

@ -4,13 +4,11 @@
module vweb
import (
os
net
net.http
net.urllib
strings
)
import os
import net
import net.http
import net.urllib
import strings
pub const (
methods_with_form = ['POST', 'PUT', 'PATCH']
@ -186,7 +184,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
return
//continue
}
mut headers := []string
mut headers := []string{}
mut body := ''
mut in_headers := true
mut len := 0