From 33694665f06a01ecc7e61a311a9d666f98028b97 Mon Sep 17 00:00:00 2001 From: zakuro Date: Tue, 12 Jan 2021 12:38:43 +0900 Subject: [PATCH] fmt: align each contiguous field of struct. not the whole. (#7981) --- cmd/tools/vdoc/vdoc.v | 2 +- cmd/tools/vvet/vvet.v | 2 +- doc/docs.md | 6 +- vlib/bitfield/bitfield.v | 2 +- vlib/builtin/array.v | 6 +- vlib/builtin/map.v | 20 +- vlib/cli/flag.v | 2 +- vlib/gg/gg.v | 70 +++--- vlib/os/file.c.v | 4 +- vlib/os/os_nix.c.v | 4 +- vlib/os/process.v | 8 +- vlib/semver/parse.v | 2 +- vlib/strings/builder.js.v | 2 +- vlib/time/stopwatch.v | 4 +- vlib/v/ast/ast.v | 294 +++++++++++------------ vlib/v/ast/walker/walker.v | 2 +- vlib/v/ast/walker/walker_test.v | 2 +- vlib/v/builder/builder.v | 16 +- vlib/v/builder/cc.v | 24 +- vlib/v/cflag/cflags.v | 8 +- vlib/v/checker/checker.v | 52 ++-- vlib/v/doc/doc.v | 8 +- vlib/v/fmt/fmt.v | 76 ++++-- vlib/v/fmt/tests/array_static_keep.vv | 2 +- vlib/v/fmt/tests/comments_keep.vv | 2 +- vlib/v/fmt/tests/generic_structs_keep.vv | 2 +- vlib/v/fmt/tests/structs_expected.vv | 10 +- vlib/v/gen/cgen.v | 190 +++++++-------- vlib/v/gen/x64/gen.v | 4 +- vlib/v/parser/parser.v | 2 +- vlib/v/pref/pref.v | 100 ++++---- vlib/v/scanner/scanner.v | 22 +- vlib/v/table/table.v | 6 +- vlib/v/table/types.v | 28 +-- vlib/v/util/suggestions.v | 4 +- vlib/v/vmod/vmod.v | 4 +- vlib/vweb/assets/assets.v | 6 +- vlib/vweb/vweb.v | 8 +- vlib/x/websocket/message.v | 2 +- vlib/x/websocket/websocket_client.v | 8 +- vlib/x/websocket/websocket_server.v | 14 +- 41 files changed, 533 insertions(+), 497 deletions(-) diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index 280083365b..86ceb708d4 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -29,7 +29,7 @@ enum OutputType { } struct VDoc { - cfg Config [required] + cfg Config [required] mut: docs []doc.Doc assets map[string]string diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 2f1cd6d704..d2e7745798 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -11,7 +11,7 @@ import v.table import v.token struct Vet { - opt Options + opt Options mut: errors []vet.Error file string diff --git a/doc/docs.md b/doc/docs.md index 7d61d30c41..cdc7d93fd3 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2426,10 +2426,10 @@ struct Foo { } struct User { - name string - age int + name string + age int // Use the `skip` attribute to skip certain fields - foo Foo [skip] + foo Foo [skip] // If the field name is different in JSON, it can be specified last_name string [json: lastName] } diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index 7e59e94038..c8cf9664d1 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -14,7 +14,7 @@ provides API (functions and methods) for accessing and modifying bit arrays. */ pub struct BitField { mut: - size int + size int // field *u32 field []u32 } diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index d24877d046..12b7186bb0 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -10,9 +10,9 @@ pub struct array { pub: element_size int // size in bytes of one element in the array. pub mut: - data voidptr - len int // length of the array. - cap int // capacity of the array. + data voidptr + len int // length of the array. + cap int // capacity of the array. } // array.data uses a void pointer, which allows implementing arrays without generics and without generating diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index d112cf45a1..a1ad407e7d 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -97,9 +97,9 @@ struct DenseArray { value_bytes int slot_bytes int // sum of 2 fields above mut: - cap int - len int - deletes u32 // count + cap int + len int + deletes u32 // count // array allocated (with `cap` bytes) on first deletion // has non-zero element when key deleted all_deleted &byte @@ -200,22 +200,22 @@ type MapFreeFn = fn (voidptr) pub struct map { // Number of bytes of a key - key_bytes int + key_bytes int // Number of bytes of a value - value_bytes int + value_bytes int mut: // Highest even index in the hashtable - even_index u32 + even_index u32 // Number of cached hashbits left for rehasing cached_hashbits byte // Used for right-shifting out used hashbits - shift byte + shift byte // Array storing key-values (ordered) - key_values DenseArray + key_values DenseArray // Pointer to meta-data: // - Odd indices store kv_index. // - Even indices store probe_count and hashbits. - metas &u32 + metas &u32 // Extra metas that allows for no ranging when incrementing // index in the hashmap extra_metas u32 @@ -226,7 +226,7 @@ mut: free_fn MapFreeFn pub mut: // Number of key-values currently in the hashmap - len int + len int } fn map_hash_string(pkey voidptr) u64 { diff --git a/vlib/cli/flag.v b/vlib/cli/flag.v index 351fc0c8d5..411968dd54 100644 --- a/vlib/cli/flag.v +++ b/vlib/cli/flag.v @@ -17,7 +17,7 @@ pub mut: required bool value string mut: - found bool + found bool } pub fn (flags []Flag) get_all_found() []Flag { diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 2e054ee24d..2828d7d34b 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -25,36 +25,36 @@ pub type FNChar = fn (c u32, x voidptr) pub struct Config { pub: - width int - height int - use_ortho bool - retina bool - resizable bool - user_data voidptr - font_size int - create_window bool + width int + height int + use_ortho bool + retina bool + resizable bool + user_data voidptr + font_size int + create_window bool // window_user_ptr voidptr - window_title string - borderless_window bool - always_on_top bool - bg_color gx.Color - init_fn FNCb = voidptr(0) - frame_fn FNCb = voidptr(0) - cleanup_fn FNCb = voidptr(0) - fail_fn FNFail = voidptr(0) - event_fn FNEvent = voidptr(0) - keydown_fn FNKeyDown = voidptr(0) + window_title string + borderless_window bool + always_on_top bool + bg_color gx.Color + init_fn FNCb = voidptr(0) + frame_fn FNCb = voidptr(0) + cleanup_fn FNCb = voidptr(0) + fail_fn FNFail = voidptr(0) + event_fn FNEvent = voidptr(0) + keydown_fn FNKeyDown = voidptr(0) // special case of event_fn - char_fn FNChar = voidptr(0) + char_fn FNChar = voidptr(0) // special case of event_fn - move_fn FNMove = voidptr(0) + move_fn FNMove = voidptr(0) // special case of event_fn - click_fn FNMove = voidptr(0) + click_fn FNMove = voidptr(0) // special case of event_fn // wait_events bool // set this to true for UIs, to save power - fullscreen bool - scale f32 = 1.0 - sample_count int + fullscreen bool + scale f32 = 1.0 + sample_count int // vid needs this // init_text bool font_path string @@ -63,7 +63,7 @@ pub: } pub struct Context { - render_text bool + render_text bool mut: // a cache with all images created by the user. used for sokol image init and to save space // (so that the user can store image ids, not entire Image objects) @@ -71,17 +71,17 @@ mut: needs_refresh bool = true ticks int pub mut: - scale f32 = 1.0 + scale f32 = 1.0 // will get set to 2.0 for retina, will remain 1.0 for normal - width int - height int - clear_pass C.sg_pass_action - window C.sapp_desc - timage_pip C.sgl_pipeline - config Config - ft &FT - font_inited bool - ui_mode bool // do not redraw everything 60 times/second, but only when the user requests + width int + height int + clear_pass C.sg_pass_action + window C.sapp_desc + timage_pip C.sgl_pipeline + config Config + ft &FT + font_inited bool + ui_mode bool // do not redraw everything 60 times/second, but only when the user requests } pub struct Size { diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 7aae4235bd..355cd15729 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -1,9 +1,9 @@ module os pub struct File { - cfile voidptr // Using void* instead of FILE* + cfile voidptr // Using void* instead of FILE* pub: - fd int + fd int pub mut: is_opened bool } diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index e6ebb01bc7..17d46f7917 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -179,9 +179,9 @@ pub fn exec(cmd string) ?Result { pub struct Command { mut: - f voidptr + f voidptr pub mut: - eof bool + eof bool pub: path string redirect_stdout bool diff --git a/vlib/os/process.v b/vlib/os/process.v index c667c2e247..fda1af57aa 100644 --- a/vlib/os/process.v +++ b/vlib/os/process.v @@ -16,12 +16,12 @@ pub enum ProcessState { [ref_only] pub struct Process { pub: - filename string // the process's command file path + filename string // the process's command file path pub mut: - pid int // the PID of the process - code int = -1 + pid int // the PID of the process + code int = -1 // the exit code of the process, != -1 *only* when status is .exited *and* the process was not aborted - status ProcessState = .not_started + status ProcessState = .not_started // the current status of the process err string // if the process fails, contains the reason why args []string // the arguments that the command takes diff --git a/vlib/semver/parse.v b/vlib/semver/parse.v index 1b119037c6..9acbeaf6a6 100644 --- a/vlib/semver/parse.v +++ b/vlib/semver/parse.v @@ -5,7 +5,7 @@ struct RawVersion { prerelease string metadata string mut: - raw_ints []string + raw_ints []string } const ( diff --git a/vlib/strings/builder.js.v b/vlib/strings/builder.js.v index 821ca419fa..fb8876e1b7 100644 --- a/vlib/strings/builder.js.v +++ b/vlib/strings/builder.js.v @@ -5,7 +5,7 @@ module strings pub struct Builder { mut: - buf []byte + buf []byte pub mut: len int initial_size int = 1 diff --git a/vlib/time/stopwatch.v b/vlib/time/stopwatch.v index fee22a90e9..49faedf524 100644 --- a/vlib/time/stopwatch.v +++ b/vlib/time/stopwatch.v @@ -11,8 +11,8 @@ pub struct StopWatch { mut: elapsed u64 pub mut: - start u64 - end u64 + start u64 + end u64 } pub fn new_stopwatch(opts StopWatchOptions) StopWatch { diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index ab63b56be4..0b4c7d5f37 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -52,7 +52,7 @@ pub: comments []Comment is_expr bool pub mut: - typ table.Type + typ table.Type } pub struct IntegerLiteral { @@ -107,12 +107,12 @@ pub: // `foo.bar` pub struct SelectorExpr { pub: - pos token.Position - expr Expr // expr.field_name - field_name string - is_mut bool // is used for the case `if mut ident.selector is MyType {`, it indicates if the root ident is mutable - mut_pos token.Position - next_token token.Kind + pos token.Position + expr Expr // expr.field_name + field_name string + is_mut bool // is used for the case `if mut ident.selector is MyType {`, it indicates if the root ident is mutable + mut_pos token.Position + next_token token.Kind pub mut: expr_type table.Type // type of `Foo` in `Foo.bar` typ table.Type // type of the entire thing (`Foo.bar`) @@ -152,8 +152,8 @@ pub: attrs []table.Attr is_public bool pub mut: - name string - typ table.Type + name string + typ table.Type } pub struct Field { @@ -161,17 +161,17 @@ pub: name string pos token.Position pub mut: - typ table.Type + typ table.Type } // const field in const declaration group pub struct ConstField { pub: - mod string - name string - expr Expr // the value expr of field; everything after `=` - is_pub bool - pos token.Position + mod string + name string + expr Expr // the value expr of field; everything after `=` + is_pub bool + pos token.Position pub mut: typ table.Type // the type of the const field, it can be any type in V comments []Comment // comments before current const field @@ -180,8 +180,8 @@ pub mut: // const declaration pub struct ConstDecl { pub: - is_pub bool - pos token.Position + is_pub bool + pos token.Position pub mut: fields []ConstField // all the const fields in the `const (...)` block end_comments []Comment // comments that after last const field @@ -203,7 +203,7 @@ pub: end_comments []Comment embeds []Embed pub mut: - fields []StructField + fields []StructField } pub struct Embed { @@ -255,8 +255,8 @@ pub mut: pub struct StructInit { pub: - pos token.Position - is_short bool + pos token.Position + is_short bool pub mut: pre_comments []Comment typ table.Type @@ -277,7 +277,7 @@ pub: mod_pos token.Position alias_pos token.Position pub mut: - syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}` + syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}` } // import symbol,for import {symbol} syntax @@ -292,7 +292,7 @@ pub struct AnonFn { pub: decl FnDecl pub mut: - typ table.Type // the type of anonymous fn. Both .typ and .decl.name are auto generated + typ table.Type // the type of anonymous fn. Both .typ and .decl.name are auto generated } // function or method declaration @@ -323,12 +323,12 @@ pub: is_direct_arr bool // direct array access attrs []table.Attr pub mut: - stmts []Stmt - return_type table.Type - comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl - next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl - source_file &File = 0 - scope &Scope + stmts []Stmt + return_type table.Type + comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl + next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl + source_file &File = 0 + scope &Scope } // break, continue @@ -342,9 +342,9 @@ pub: // function or method call expr pub struct CallExpr { pub: - pos token.Position - left Expr // `user` in `user.register()` - mod string + pos token.Position + left Expr // `user` in `user.register()` + mod string pub mut: name string // left.name() is_method bool @@ -374,10 +374,10 @@ pub struct AutofreeArgVar { // function call argument: `f(callarg)` pub struct CallArg { pub: - is_mut bool - share table.ShareType - expr Expr - comments []Comment + is_mut bool + share table.ShareType + expr Expr + comments []Comment pub mut: typ table.Type is_tmp_autofree bool // this tells cgen that a tmp variable has to be used for the arg expression in order to free it after the call @@ -392,7 +392,7 @@ pub: exprs []Expr comments []Comment pub mut: - types []table.Type + types []table.Type } /* @@ -417,15 +417,15 @@ pub: is_autofree_tmp bool is_arg bool // fn args should not be autofreed pub mut: - typ table.Type - sum_type_casts []table.Type // nested sum types require nested smart casting, for that a list of types is needed - pos token.Position - is_used bool - is_changed bool // to detect mutable vars that are never changed + typ table.Type + sum_type_casts []table.Type // nested sum types require nested smart casting, for that a list of types is needed + pos token.Position + is_used bool + is_changed bool // to detect mutable vars that are never changed // // (for setting the position after the or block for autofree) - is_or bool // `x := foo() or { ... }` - is_tmp bool // for tmp for loop vars, so that autofree can skip them + is_or bool // `x := foo() or { ... }` + is_tmp bool // for tmp for loop vars, so that autofree can skip them } // used for smartcasting only @@ -452,7 +452,7 @@ pub mut: pub struct GlobalDecl { pub: - pos token.Position + pos token.Position pub mut: fields []GlobalField end_comments []Comment @@ -463,9 +463,9 @@ pub mut: // That array is then passed to V's checker. pub struct File { pub: - path string // path of the source file - mod Module // the module of the source file (from `module xyz` at the top) - global_scope &Scope + path string // path of the source file + mod Module // the module of the source file (from `module xyz` at the top) + global_scope &Scope pub mut: scope &Scope stmts []Stmt // all the statements in the source file @@ -512,13 +512,13 @@ pub: pos token.Position mut_pos token.Position pub mut: - scope &Scope - obj ScopeObject - mod string - name string - kind IdentKind - info IdentInfo - is_mut bool + scope &Scope + obj ScopeObject + mod string + name string + kind IdentKind + info IdentInfo + is_mut bool } pub fn (i &Ident) var_info() IdentVar { @@ -537,8 +537,8 @@ pub fn (i &Ident) var_info() IdentVar { // See: token.Kind.is_infix pub struct InfixExpr { pub: - op token.Kind - pos token.Position + op token.Kind + pos token.Position pub mut: left Expr right Expr @@ -551,9 +551,9 @@ pub mut: // ++, -- pub struct PostfixExpr { pub: - op token.Kind - expr Expr - pos token.Position + op token.Kind + expr Expr + pos token.Position pub mut: auto_locked string } @@ -561,9 +561,9 @@ pub mut: // See: token.Kind.is_prefix pub struct PrefixExpr { pub: - op token.Kind - right Expr - pos token.Position + op token.Kind + right Expr + pos token.Position pub mut: right_type table.Type or_block OrExpr @@ -571,10 +571,10 @@ pub mut: pub struct IndexExpr { pub: - pos token.Position - left Expr - index Expr // [0], RangeExpr [start..end] or map[key] - or_expr OrExpr + pos token.Position + left Expr + index Expr // [0], RangeExpr [start..end] or map[key] + or_expr OrExpr pub mut: left_type table.Type // array, map, fixed array is_setter bool @@ -588,18 +588,18 @@ pub: pos token.Position post_comments []Comment pub mut: - branches []IfBranch // includes all `else if` branches - is_expr bool - typ table.Type - has_else bool + branches []IfBranch // includes all `else if` branches + is_expr bool + typ table.Type + has_else bool } pub struct IfBranch { pub: - cond Expr - pos token.Position - body_pos token.Position - comments []Comment + cond Expr + pos token.Position + body_pos token.Position + comments []Comment pub mut: stmts []Stmt smartcast bool // true when cond is `x is SumType`, set in checker.if_expr // no longer needed with union sum types TODO: remove @@ -618,17 +618,17 @@ pub: is_rlock bool pos token.Position pub mut: - lockeds []Ident // `x`, `y` in `lock x, y {` - is_expr bool - typ table.Type + lockeds []Ident // `x`, `y` in `lock x, y {` + is_expr bool + typ table.Type } pub struct MatchExpr { pub: - tok_kind token.Kind - cond Expr - branches []MatchBranch - pos token.Position + tok_kind token.Kind + cond Expr + branches []MatchBranch + pos token.Position pub mut: is_expr bool // returns a value return_type table.Type @@ -647,7 +647,7 @@ pub: is_else bool post_comments []Comment pub mut: - scope &Scope + scope &Scope } pub struct SelectExpr { @@ -684,7 +684,7 @@ pub: pos token.Position pub mut: // expr Expr - typ table.Type + typ table.Type } pub struct ForStmt { @@ -694,8 +694,8 @@ pub: is_inf bool // `for {}` pos token.Position pub mut: - label string // `label: for {` - scope &Scope + label string // `label: for {` + scope &Scope } pub struct ForInStmt { @@ -710,12 +710,12 @@ pub: val_is_mut bool // `for mut val in vals {` means that modifying `val` will modify the array // and the array cannot be indexed inside the loop pub mut: - key_type table.Type - val_type table.Type - cond_type table.Type - kind table.Kind // array/map/string - label string // `label: for {` - scope &Scope + key_type table.Type + val_type table.Type + cond_type table.Type + kind table.Kind // array/map/string + label string // `label: for {` + scope &Scope } pub struct ForCStmt { @@ -729,15 +729,15 @@ pub: stmts []Stmt pos token.Position pub mut: - label string // `label: for {` - scope &Scope + label string // `label: for {` + scope &Scope } // #include etc pub struct HashStmt { pub: - mod string - pos token.Position + mod string + pos token.Position pub mut: val string // example: 'include # please install openssl // comment' kind string // : 'include' @@ -755,11 +755,11 @@ pub: // variable assign statement pub struct AssignStmt { pub: - right []Expr - op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v - pos token.Position - comments []Comment - end_comments []Comment + right []Expr + op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v + pos token.Position + comments []Comment + end_comments []Comment pub mut: left []Expr left_types []table.Type @@ -771,9 +771,9 @@ pub mut: pub struct AsCast { pub: - expr Expr - typ table.Type - pos token.Position + expr Expr + typ table.Type + pos token.Position pub mut: expr_type table.Type } @@ -786,7 +786,7 @@ pub: mod string // for full path `mod_Enum_val` pos token.Position pub mut: - typ table.Type + typ table.Type } // enum field in enum declaration @@ -886,19 +886,19 @@ pub: pub struct ArrayInit { pub: - pos token.Position // `[]` in []Type{} position - elem_type_pos token.Position // `Type` in []Type{} position - exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array - ecmnts [][]Comment // optional iembed comments after each expr - is_fixed bool - has_val bool // fixed size literal `[expr, expr]!!` - mod string - len_expr Expr // len: expr - cap_expr Expr // cap: expr - default_expr Expr // init: expr - has_len bool - has_cap bool - has_default bool + pos token.Position // `[]` in []Type{} position + elem_type_pos token.Position // `Type` in []Type{} position + exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array + ecmnts [][]Comment // optional iembed comments after each expr + is_fixed bool + has_val bool // fixed size literal `[expr, expr]!!` + mod string + len_expr Expr // len: expr + cap_expr Expr // cap: expr + default_expr Expr // init: expr + has_len bool + has_cap bool + has_default bool pub mut: expr_types []table.Type // [Dog, Cat] // also used for interface_types is_interface bool // array of interfaces e.g. `[]Animal` `[Dog{}, Cat{}]` @@ -909,8 +909,8 @@ pub mut: pub struct ArrayDecompose { pub: - expr Expr - pos token.Position + expr Expr + pos token.Position pub mut: expr_type table.Type arg_type table.Type @@ -918,9 +918,9 @@ pub mut: pub struct ChanInit { pub: - pos token.Position - cap_expr Expr - has_cap bool + pos token.Position + cap_expr Expr + has_cap bool pub mut: typ table.Type elem_type table.Type @@ -928,9 +928,9 @@ pub mut: pub struct MapInit { pub: - pos token.Position - keys []Expr - vals []Expr + pos token.Position + keys []Expr + vals []Expr pub mut: typ table.Type key_type table.Type @@ -957,10 +957,10 @@ pub: // `string(x,y)`, while skipping the real pointer casts like `&string(x)`. pub struct CastExpr { pub: - expr Expr // `buf` in `string(buf, n)` - arg Expr // `n` in `string(buf, n)` - typ table.Type // `string` TODO rename to `type_to_cast_to` - pos token.Position + expr Expr // `buf` in `string(buf, n)` + arg Expr // `n` in `string(buf, n)` + typ table.Type // `string` TODO rename to `type_to_cast_to` + pos token.Position pub mut: typname string // TypeSymbol.name expr_type table.Type // `byteptr` @@ -970,7 +970,7 @@ pub mut: pub struct AssertStmt { pub: - pos token.Position + pos token.Position pub mut: expr Expr } @@ -978,9 +978,9 @@ pub mut: // `if [x := opt()] {` pub struct IfGuardExpr { pub: - var_name string - expr Expr - pos token.Position + var_name string + expr Expr + pos token.Position pub mut: expr_type table.Type } @@ -1016,8 +1016,8 @@ pub: exprs []Expr pos token.Position pub mut: - typ table.Type - scope &Scope + typ table.Type + scope &Scope } pub struct SizeOf { @@ -1038,8 +1038,8 @@ pub: pub struct TypeOf { pub: - expr Expr - pos token.Position + expr Expr + pos token.Position pub mut: expr_type table.Type } @@ -1054,8 +1054,8 @@ pub: pub struct ConcatExpr { pub: - vals []Expr - pos token.Position + vals []Expr + pos token.Position pub mut: return_type table.Type } @@ -1067,7 +1067,7 @@ pub: pos token.Position kind token.AtKind pub mut: - val string + val string } pub struct ComptimeSelector { @@ -1076,8 +1076,8 @@ pub: left Expr field_expr Expr pub mut: - left_type table.Type - typ table.Type + left_type table.Type + typ table.Type } pub struct ComptimeCall { @@ -1089,7 +1089,7 @@ pub: vweb_tmpl File args_var string pub mut: - sym table.TypeSymbol + sym table.TypeSymbol } pub struct None { @@ -1122,8 +1122,8 @@ pub: updated_columns []string // for `update set x=y` update_exprs []Expr // for `update` pub mut: - table_name string - fields []table.Field + table_name string + fields []table.Field } pub struct SqlExpr { @@ -1144,8 +1144,8 @@ pub: has_limit bool limit_expr Expr pub mut: - table_name string - fields []table.Field + table_name string + fields []table.Field } [inline] diff --git a/vlib/v/ast/walker/walker.v b/vlib/v/ast/walker/walker.v index 82464a5312..4aa1149d96 100644 --- a/vlib/v/ast/walker/walker.v +++ b/vlib/v/ast/walker/walker.v @@ -12,7 +12,7 @@ pub type InspectorFn = fn (node ast.Node, data voidptr) bool struct Inspector { inspector_callback InspectorFn mut: - data voidptr + data voidptr } pub fn (i &Inspector) visit(node ast.Node) ? { diff --git a/vlib/v/ast/walker/walker_test.v b/vlib/v/ast/walker/walker_test.v index 98a92377d4..b7a64a37a7 100644 --- a/vlib/v/ast/walker/walker_test.v +++ b/vlib/v/ast/walker/walker_test.v @@ -14,7 +14,7 @@ fn parse_text(text string) ast.File { } struct NodeByOffset { - pos int + pos int mut: node ast.Node } diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 547e152045..0c65ed464c 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -12,15 +12,15 @@ import v.depgraph pub struct Builder { pub: - compiled_dir string // contains os.real_path() of the dir of the final file beeing compiled, or the dir itself when doing `v .` - module_path string + compiled_dir string // contains os.real_path() of the dir of the final file beeing compiled, or the dir itself when doing `v .` + module_path string mut: - pref &pref.Preferences - checker checker.Checker - global_scope &ast.Scope - out_name_c string - out_name_js string - max_nr_errors int = 100 + pref &pref.Preferences + checker checker.Checker + global_scope &ast.Scope + out_name_c string + out_name_js string + max_nr_errors int = 100 pub mut: module_search_paths []string parsed_files []ast.File diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 6d5ef9250f..1c406fcdca 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -163,20 +163,20 @@ mut: shared_postfix string // .so, .dll // // - debug_mode bool - is_cc_tcc bool - is_cc_gcc bool - is_cc_msvc bool - is_cc_clang bool + debug_mode bool + is_cc_tcc bool + is_cc_gcc bool + is_cc_msvc bool + is_cc_clang bool // - env_cflags string // prepended *before* everything else - env_ldflags string // appended *after* everything else + env_cflags string // prepended *before* everything else + env_ldflags string // appended *after* everything else // - args []string // ordinary C options like `-O2` - wargs []string // for `-Wxyz` *exclusively* - o_args []string // for `-o target` - post_args []string // options that should go after .o_args - linker_flags []string // `-lm` + args []string // ordinary C options like `-O2` + wargs []string // for `-Wxyz` *exclusively* + o_args []string // for `-o target` + post_args []string // options that should go after .o_args + linker_flags []string // `-lm` } fn (mut v Builder) setup_ccompiler_options(ccompiler string) { diff --git a/vlib/v/cflag/cflags.v b/vlib/v/cflag/cflags.v index 1bc49705de..ea821a4fce 100644 --- a/vlib/v/cflag/cflags.v +++ b/vlib/v/cflag/cflags.v @@ -8,10 +8,10 @@ import os // parsed cflag pub struct CFlag { pub: - mod string // the module in which the flag was given - os string // eg. windows | darwin | linux - name string // eg. -I - value string // eg. /path/to/include + mod string // the module in which the flag was given + os string // eg. windows | darwin | linux + name string // eg. -I + value string // eg. /path/to/include pub mut: cached string // eg. ~/.vmodules/cache/ea/ea9878886727367672163.o (for .o files) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index dc0c024e73..96d77de2e4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -31,34 +31,34 @@ const ( ) pub struct Checker { - pref &pref.Preferences // Preferences shared from V struct + pref &pref.Preferences // Preferences shared from V struct pub mut: - table &table.Table - file &ast.File = 0 - nr_errors int - nr_warnings int - errors []errors.Error - warnings []errors.Warning - error_lines []int // to avoid printing multiple errors for the same line - expected_type table.Type - expected_or_type table.Type // fn() or { 'this type' } eg. string. expected or block type - cur_fn &ast.FnDecl // current function - const_decl string - const_deps []string - const_names []string - global_names []string - locked_names []string // vars that are currently locked - rlocked_names []string // vars that are currently read-locked - in_for_count int // if checker is currently in a for loop + table &table.Table + file &ast.File = 0 + nr_errors int + nr_warnings int + errors []errors.Error + warnings []errors.Warning + error_lines []int // to avoid printing multiple errors for the same line + expected_type table.Type + expected_or_type table.Type // fn() or { 'this type' } eg. string. expected or block type + cur_fn &ast.FnDecl // current function + const_decl string + const_deps []string + const_names []string + global_names []string + locked_names []string // vars that are currently locked + rlocked_names []string // vars that are currently read-locked + in_for_count int // if checker is currently in a for loop // checked_ident string // to avoid infinite checker loops - returns bool - scope_returns bool - mod string // current module name - is_builtin_mod bool // are we in `builtin`? - inside_unsafe bool - inside_const bool - skip_flags bool // should `#flag` and `#include` be skipped - cur_generic_type table.Type + returns bool + scope_returns bool + mod string // current module name + is_builtin_mod bool // are we in `builtin`? + inside_unsafe bool + inside_const bool + skip_flags bool // should `#flag` and `#include` be skipped + cur_generic_type table.Type mut: expr_level int // to avoid infinite recursion segfaults due to compiler bugs inside_sql bool // to handle sql table fields pseudo variables diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 4208ed6670..16f5fa847c 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -41,11 +41,11 @@ pub fn (sk SymbolKind) str() string { } pub struct Doc { - prefs &pref.Preferences = new_vdoc_preferences() + prefs &pref.Preferences = new_vdoc_preferences() pub mut: - base_path string - table &table.Table = &table.Table{} - checker checker.Checker = checker.Checker{ + base_path string + table &table.Table = &table.Table{} + checker checker.Checker = checker.Checker{ table: 0 cur_fn: 0 pref: 0 diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index ba5aa22754..ca6dc217a1 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -589,10 +589,56 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) { f.writeln('\n') } +[inline] +fn abs(v int) int { + return if v >= 0 { + v + } else { + -v + } +} + const ( threshold_to_align_struct = 8 ) +struct StructFieldAlignInfo { +mut: + first_line int + last_line int + max_type_len int + max_len int +} + +fn (mut list []StructFieldAlignInfo) add_new_info(len int, type_len int, line int) { + list << StructFieldAlignInfo{ + first_line: line + last_line: line + max_type_len: type_len + max_len: len + } +} + +[direct_array_access] +fn (mut list []StructFieldAlignInfo) add_info(len int, type_len int, line int) { + if list.len == 0 { + list.add_new_info(len, type_len, line) + return + } + i := list.len - 1 + if line - list[i].last_line > 1 { + list.add_new_info(len, type_len, line) + return + } + list[i].last_line = line + if len > list[i].max_len { + list[i].max_len = len + } + if type_len > list[i].max_type_len { + list[i].max_type_len = type_len + } +} + struct CommentAndExprAlignInfo { mut: max_attrs_len int @@ -610,15 +656,6 @@ fn (mut list []CommentAndExprAlignInfo) add_new_info(attrs_len int, type_len int } } -[inline] -fn abs(v int) int { - return if v >= 0 { - v - } else { - -v - } -} - fn (mut list []CommentAndExprAlignInfo) add_info(attrs_len int, type_len int, line int) { if list.len == 0 { list.add_new_info(attrs_len, type_len, line) @@ -667,8 +704,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { return } f.writeln(' {') - mut max := 0 - mut max_type_len := 0 + mut field_aligns := []StructFieldAlignInfo{} mut comment_aligns := []CommentAndExprAlignInfo{} mut default_expr_aligns := []CommentAndExprAlignInfo{} mut field_types := []string{cap: node.fields.len} @@ -678,9 +714,6 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { ft = f.short_module(ft) } field_types << ft - if ft.len > max_type_len { - max_type_len = ft.len - } attrs_len := inline_attrs_len(field.attrs) end_pos := field.pos.pos + field.pos.len mut comments_len := 0 // Length of comments between field name and type @@ -695,9 +728,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { comments_len += '/* $comment.text */ '.len } } - if comments_len + field.name.len > max { - max = comments_len + field.name.len - } + field_aligns.add_info(comments_len + field.name.len, ft.len, field.pos.line_nr) if field.has_default_expr { default_expr_aligns.add_info(attrs_len, field_types[i].len, field.pos.line_nr) } @@ -706,6 +737,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { styp := f.table.type_to_str(embed.typ) f.writeln('\t$styp') } + mut field_align_i := 0 mut comment_align_i := 0 mut default_expr_align_i := 0 for i, field in node.fields { @@ -737,13 +769,17 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { f.write(comment_text) comm_idx++ } - f.write(strings.repeat(` `, max - field.name.len - comments_len)) + mut field_align := field_aligns[field_align_i] + if field_align.last_line < field.pos.line_nr { + field_align_i++ + field_align = field_aligns[field_align_i] + } + f.write(strings.repeat(` `, field_align.max_len - field.name.len - comments_len)) f.write(field_types[i]) - after_type_pad_len := max_type_len - field_types[i].len attrs_len := inline_attrs_len(field.attrs) has_attrs := field.attrs.len > 0 if has_attrs { - f.write(strings.repeat(` `, after_type_pad_len)) + f.write(strings.repeat(` `, field_align.max_type_len - field_types[i].len)) f.inline_attrs(field.attrs) } if field.has_default_expr { diff --git a/vlib/v/fmt/tests/array_static_keep.vv b/vlib/v/fmt/tests/array_static_keep.vv index 50965259b7..1555780279 100644 --- a/vlib/v/fmt/tests/array_static_keep.vv +++ b/vlib/v/fmt/tests/array_static_keep.vv @@ -6,7 +6,7 @@ mut: } struct TileLine { - ypos int + ypos int mut: field [5]int points int diff --git a/vlib/v/fmt/tests/comments_keep.vv b/vlib/v/fmt/tests/comments_keep.vv index ce5fdcbc82..e44c28cc81 100644 --- a/vlib/v/fmt/tests/comments_keep.vv +++ b/vlib/v/fmt/tests/comments_keep.vv @@ -9,7 +9,7 @@ enum Abc { struct User { name string // name // middle comment - age int + age int // last comment // last comment2 } diff --git a/vlib/v/fmt/tests/generic_structs_keep.vv b/vlib/v/fmt/tests/generic_structs_keep.vv index cdee4c629a..8a4dd055ac 100644 --- a/vlib/v/fmt/tests/generic_structs_keep.vv +++ b/vlib/v/fmt/tests/generic_structs_keep.vv @@ -10,7 +10,7 @@ fn (f Foo) value() string { type DB = string struct Repo { - db DB + db DB pub mut: model T permission U diff --git a/vlib/v/fmt/tests/structs_expected.vv b/vlib/v/fmt/tests/structs_expected.vv index 8210c30bee..9299d67f99 100644 --- a/vlib/v/fmt/tests/structs_expected.vv +++ b/vlib/v/fmt/tests/structs_expected.vv @@ -8,13 +8,13 @@ struct User { } struct Foo { - field1 int // f1 - field2 string // f2 + field1 int // f1 + field2 string // f2 pub: public_field1 int // f1 public_field2 f64 // f2 mut: - mut_field string + mut_field string pub mut: pub_mut_field string } @@ -38,9 +38,9 @@ mut: 9 10 */ - somefield2 /* 11 */ int // 12 + somefield2 /* 11 */ int // 12 pub: - somefield3 int + somefield3 int /* 13 14 diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 21d25aef68..e9be899d7d 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -25,104 +25,104 @@ const ( ) struct Gen { - pref &pref.Preferences - module_built string + pref &pref.Preferences + module_built string mut: - table &table.Table - out strings.Builder - cheaders strings.Builder - includes strings.Builder // all C #includes required by V modules - typedefs strings.Builder - typedefs2 strings.Builder - type_definitions strings.Builder // typedefs, defines etc (everything that goes to the top of the file) - definitions strings.Builder // typedefs, defines etc (everything that goes to the top of the file) - inits map[string]strings.Builder // contents of `void _vinit/2{}` - cleanups map[string]strings.Builder // contents of `void _vcleanup(){}` - gowrappers strings.Builder // all go callsite wrappers - stringliterals strings.Builder // all string literals (they depend on tos3() beeing defined - auto_str_funcs strings.Builder // function bodies of all auto generated _str funcs - comptime_defines strings.Builder // custom defines, given by -d/-define flags on the CLI - pcs_declarations strings.Builder // -prof profile counter declarations for each function - hotcode_definitions strings.Builder // -live declarations & functions - shared_types strings.Builder // shared/lock types - channel_definitions strings.Builder // channel related code - options_typedefs strings.Builder // Option typedefs - options strings.Builder // `Option_xxxx` types - json_forward_decls strings.Builder // json type forward decls - enum_typedefs strings.Builder // enum types - sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc - file ast.File - fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0 - last_fn_c_name string - tmp_count int // counter for unique tmp vars (_tmp1, tmp2 etc) - tmp_count2 int // a separate tmp var counter for autofree fn calls - is_c_call bool // e.g. `C.printf("v")` - is_assign_lhs bool // inside left part of assign expr (for array_set(), etc) - is_assign_rhs bool // inside right part of assign after `=` (val expr) - is_array_set bool - is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&byte(0)` etc - is_sql bool // Inside `sql db{}` statement, generating sql instead of C (e.g. `and` instead of `&&` etc) - is_shared bool // for initialization of hidden mutex in `[rw]shared` literals - is_vlines_enabled bool // is it safe to generate #line directives when -g is passed - vlines_path string // set to the proper path for generating #line directives - optionals []string // to avoid duplicates TODO perf, use map - chan_pop_optionals []string // types for `x := <-ch or {...}` - chan_push_optionals []string // types for `ch <- x or {...}` - shareds []int // types with hidden mutex for which decl has been emitted - inside_ternary int // ?: comma separated statements on a single line - inside_map_postfix bool // inside map++/-- postfix expr - inside_map_infix bool // inside map< fn counter name - is_builtin_mod bool - hotcode_fn_names []string + ternary_names map[string]string + ternary_level_names map[string][]string + stmt_path_pos []int // positions of each statement start, for inserting C statements before the current statement + skip_stmt_pos bool // for handling if expressions + autofree (since both prepend C statements) + right_is_opt bool + is_autofree bool // false, inside the bodies of fns marked with [manualfree], otherwise === g.pref.autofree + indent int + empty_line bool + is_test bool + assign_op token.Kind // *=, =, etc (for array_set) + defer_stmts []ast.DeferStmt + defer_ifdef string + defer_profile_code string + str_types []string // types that need automatic str() generation + threaded_fns []string // for generating unique wrapper types and fns for `go xxx()` + array_fn_definitions []string // array equality functions that have been defined + map_fn_definitions []string // map equality functions that have been defined + struct_fn_definitions []string // struct equality functions that have been defined + auto_fn_definitions []string // auto generated functions defination list + is_json_fn bool // inside json.encode() + json_types []string // to avoid json gen duplicates + pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name + is_builtin_mod bool + hotcode_fn_names []string // cur_fn ast.FnDecl - cur_generic_type table.Type // `int`, `string`, etc in `foo()` - sql_i int - sql_stmt_name string - sql_side SqlExprSide // left or right, to distinguish idents in `name == name` - inside_vweb_tmpl bool - inside_return bool - inside_or_block bool - strs_to_free0 []string // strings.Builder + cur_generic_type table.Type // `int`, `string`, etc in `foo()` + sql_i int + sql_stmt_name string + sql_side SqlExprSide // left or right, to distinguish idents in `name == name` + inside_vweb_tmpl bool + inside_return bool + inside_or_block bool + strs_to_free0 []string // strings.Builder // strs_to_free []string // strings.Builder - inside_call bool - has_main bool - inside_const bool - comp_for_method string // $for method in T.methods {} - comp_for_field_var string // $for field in T.fields {}; the variable name - comp_for_field_value table.Field // value of the field variable - comp_for_field_type table.Type // type of the field variable inferred from `$if field.typ is T {}` - comptime_var_type_map map[string]table.Type + inside_call bool + has_main bool + inside_const bool + comp_for_method string // $for method in T.methods {} + comp_for_field_var string // $for field in T.fields {}; the variable name + comp_for_field_value table.Field // value of the field variable + comp_for_field_type table.Type // type of the field variable inferred from `$if field.typ is T {}` + comptime_var_type_map map[string]table.Type // tmp_arg_vars_to_free []string // autofree_pregen map[string]string // autofree_pregen_buf strings.Builder // autofree_tmp_vars []string // to avoid redefining the same tmp vars in a single function - called_fn_name string - cur_mod ast.Module - is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)` - is_fn_index_call bool + called_fn_name string + cur_mod ast.Module + is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)` + is_fn_index_call bool // nr_vars_to_free int // doing_autofree_tmp bool inside_lambda bool @@ -131,11 +131,11 @@ mut: // TypeOne, TypeTwo {} // where an aggregate (at least two types) is generated // sum type deref needs to know which index to deref because unions take care of the correct field - aggregate_type_idx int - returned_var_name string // to detect that a var doesn't need to be freed since it's being returned - branch_parent_pos int // used in BranchStmt (continue/break) for autofree stop position - timers &util.Timers = util.new_timers(false) - force_main_console bool // true when [console] used on fn main() + aggregate_type_idx int + returned_var_name string // to detect that a var doesn't need to be freed since it's being returned + branch_parent_pos int // used in BranchStmt (continue/break) for autofree stop position + timers &util.Timers = util.new_timers(false) + force_main_console bool // true when [console] used on fn main() } const ( diff --git a/vlib/v/gen/x64/gen.v b/vlib/v/gen/x64/gen.v index 5035f210d3..d4ff8834a9 100644 --- a/vlib/v/gen/x64/gen.v +++ b/vlib/v/gen/x64/gen.v @@ -13,8 +13,8 @@ import strings import v.table pub struct Gen { - out_name string - pref &pref.Preferences // Preferences shared from V struct + out_name string + pref &pref.Preferences // Preferences shared from V struct mut: table &table.Table buf []byte diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 4ca3acc6e9..efb38947ce 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -20,7 +20,7 @@ const ( ) pub struct Parser { - pref &pref.Preferences + pref &pref.Preferences mut: file_base string // "hello.v" file_name string // "/home/user/hello.v" diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 014da6f765..c49f2e6fd4 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -49,71 +49,71 @@ const ( pub struct Preferences { pub mut: - os OS // the OS to compile for - backend Backend - build_mode BuildMode - output_mode OutputMode = .stdout + os OS // the OS to compile for + backend Backend + build_mode BuildMode + output_mode OutputMode = .stdout // verbosity VerboseLevel - is_verbose bool + is_verbose bool // nofmt bool // disable vfmt - is_test bool // `v test string_test.v` - is_script bool // single file mode (`v program.v`), main function can be skipped - is_vsh bool // v script (`file.vsh`) file, the `os` module should be made global - is_livemain bool // main program that contains live/hot code - is_liveshared bool // a shared library, that will be used in a -live main program - is_shared bool // an ordinary shared library, -shared, no matter if it is live or not - is_prof bool // benchmark every function - profile_file string // the profile results will be stored inside profile_file - profile_no_inline bool // when true, [inline] functions would not be profiled - translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc - is_prod bool // use "-O2" - obfuscate bool // `v -obf program.v`, renames functions to "f_XXX" - is_repl bool - is_run bool - sanitize bool // use Clang's new "-fsanitize" option - is_debug bool // false by default, turned on by -g or -cg, it tells v to pass -g to the C backend compiler. - is_vlines bool // turned on by -g, false by default (it slows down .tmp.c generation slightly). - show_cc bool // -showcc, print cc command - show_c_output bool // -show-c-output, print all cc output even if the code was compiled correctly + is_test bool // `v test string_test.v` + is_script bool // single file mode (`v program.v`), main function can be skipped + is_vsh bool // v script (`file.vsh`) file, the `os` module should be made global + is_livemain bool // main program that contains live/hot code + is_liveshared bool // a shared library, that will be used in a -live main program + is_shared bool // an ordinary shared library, -shared, no matter if it is live or not + is_prof bool // benchmark every function + profile_file string // the profile results will be stored inside profile_file + profile_no_inline bool // when true, [inline] functions would not be profiled + translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc + is_prod bool // use "-O2" + obfuscate bool // `v -obf program.v`, renames functions to "f_XXX" + is_repl bool + is_run bool + sanitize bool // use Clang's new "-fsanitize" option + is_debug bool // false by default, turned on by -g or -cg, it tells v to pass -g to the C backend compiler. + is_vlines bool // turned on by -g, false by default (it slows down .tmp.c generation slightly). + show_cc bool // -showcc, print cc command + show_c_output bool // -show-c-output, print all cc output even if the code was compiled correctly // NB: passing -cg instead of -g will set is_vlines to false and is_debug to true, thus making v generate cleaner C files, // which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks). // use cached modules to speed up compilation. - use_cache bool // = true - retry_compilation bool = true - is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run + use_cache bool // = true + retry_compilation bool = true + is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run // TODO Convert this into a []string - cflags string // Additional options which will be passed to the C compiler. + cflags string // Additional options which will be passed to the C compiler. // For example, passing -cflags -Os will cause the C compiler to optimize the generated binaries for size. // You could pass several -cflags XXX arguments. They will be merged with each other. // You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'. - m64 bool // true = generate 64-bit code, defaults to x64 - ccompiler string // the name of the C compiler used - ccompiler_type CompilerType // the type of the C compiler used - third_party_option string - building_v bool - autofree bool // `v -manualfree` => false, `v -autofree` => true; false by default for now. + m64 bool // true = generate 64-bit code, defaults to x64 + ccompiler string // the name of the C compiler used + ccompiler_type CompilerType // the type of the C compiler used + third_party_option string + building_v bool + autofree bool // `v -manualfree` => false, `v -autofree` => true; false by default for now. // Disabling `free()` insertion results in better performance in some applications (e.g. compilers) - compress bool + compress bool // skip_builtin bool // Skips re-compilation of the builtin module // to increase compilation time. // This is on by default, since a vast majority of users do not // work on the builtin module itself. // generating_vh bool - enable_globals bool // allow __global for low level code - is_fmt bool - is_vet bool - is_bare bool - no_preludes bool // Prevents V from generating preludes in resulting .c files - custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files - lookup_path []string - output_cross_c bool - prealloc bool - vroot string - out_name_c string // full os.real_path to the generated .tmp.c file; set by builder. - out_name string - display_name string - bundle_id string - path string // Path to file/folder to compile + enable_globals bool // allow __global for low level code + is_fmt bool + is_vet bool + is_bare bool + no_preludes bool // Prevents V from generating preludes in resulting .c files + custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files + lookup_path []string + output_cross_c bool + prealloc bool + vroot string + out_name_c string // full os.real_path to the generated .tmp.c file; set by builder. + out_name string + display_name string + bundle_id string + path string // Path to file/folder to compile // -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another { will NOT get here }` compile_defines []string // just ['vfmt'] compile_defines_all []string // contains both: ['vfmt','another'] diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 58305176b1..a7d111522b 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -19,17 +19,17 @@ const ( pub struct Scanner { pub mut: - file_path string - text string - pos int - line_nr int - last_nl_pos int // for calculating column - is_inside_string bool - is_inter_start bool // for hacky string interpolation TODO simplify - is_inter_end bool - is_enclosed_inter bool - is_debug bool - line_comment string + file_path string + text string + pos int + line_nr int + last_nl_pos int // for calculating column + is_inside_string bool + is_inter_start bool // for hacky string interpolation TODO simplify + is_inter_end bool + is_enclosed_inter bool + is_debug bool + line_comment string // prev_tok TokenKind is_started bool is_print_line_on_error bool diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 218213d9f4..626ded342f 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -37,8 +37,8 @@ pub: ctdefine string // compile time define. myflag, when [if myflag] tag attrs []Attr pub mut: - name string - source_fn voidptr // set in the checker, while processing fn declarations + name string + source_fn voidptr // set in the checker, while processing fn declarations } fn (f &Fn) method_equals(o &Fn) bool { @@ -77,7 +77,7 @@ pub: name string is_mut bool mut: - typ Type + typ Type } pub fn new_table() &Table { diff --git a/vlib/v/table/types.v b/vlib/v/table/types.v index 335edc0a33..a73bbaecb8 100644 --- a/vlib/v/table/types.v +++ b/vlib/v/table/types.v @@ -35,14 +35,14 @@ pub struct TypeSymbol { pub: parent_idx int pub mut: - info TypeInfo - kind Kind - name string // the internal & source name of the type, i.e. `[5]int`. - cname string // the name with no dots for use in the generated C code - methods []Fn - mod string - is_public bool - language Language + info TypeInfo + kind Kind + name string // the internal & source name of the type, i.e. `[5]int`. + cname string // the name with no dots for use in the generated C code + methods []Fn + mod string + is_public bool + language Language } // max of 8 @@ -609,7 +609,7 @@ pub fn (kinds []Kind) str() string { pub struct Struct { pub: - attrs []Attr + attrs []Attr pub mut: embeds []Type fields []Field @@ -649,7 +649,7 @@ pub struct Aggregate { mut: fields []Field // used for faster lookup inside the module pub: - types []Type + types []Type } // NB: FExpr here is a actually an ast.Expr . @@ -659,7 +659,7 @@ pub type FExpr = byteptr | voidptr pub struct Field { pub: - name string + name string pub mut: typ Type default_expr FExpr @@ -681,15 +681,15 @@ fn (f &Field) equals(o &Field) bool { pub struct Array { pub: - nr_dims int + nr_dims int pub mut: elem_type Type } pub struct ArrayFixed { pub: - nr_dims int - size int + nr_dims int + size int pub mut: elem_type Type } diff --git a/vlib/v/util/suggestions.v b/vlib/v/util/suggestions.v index 2175b3d506..4ebd322a22 100644 --- a/vlib/v/util/suggestions.v +++ b/vlib/v/util/suggestions.v @@ -3,8 +3,8 @@ module util import strings struct Possibility { - value string - svalue string + value string + svalue string mut: similarity f32 } diff --git a/vlib/v/vmod/vmod.v b/vlib/v/vmod/vmod.v index 8f35966af6..32831ae6a6 100644 --- a/vlib/v/vmod/vmod.v +++ b/vlib/v/vmod/vmod.v @@ -23,7 +23,7 @@ pub struct ModFileAndFolder { pub: // vmod_file contains the full path of the found 'v.mod' file, or '' // if no 'v.mod' file was found in file_path_dir, or in its parent folders. - vmod_file string + vmod_file string // vmod_folder contains the file_path_dir, if there is no 'v.mod' file in // *any* of the parent folders, otherwise it is the first parent folder, // where a v.mod file was found. @@ -33,7 +33,7 @@ pub: [ref_only] pub struct ModFileCacher { mut: - cache map[string]ModFileAndFolder + cache map[string]ModFileAndFolder // folder_files caches os.ls(key) folder_files map[string][]string } diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v index 2b4d783837..5605ac63ee 100644 --- a/vlib/vweb/assets/assets.v +++ b/vlib/vweb/assets/assets.v @@ -12,11 +12,11 @@ const ( struct AssetManager { mut: - css []Asset - js []Asset + css []Asset + js []Asset pub mut: // when true assets will be minified - minify bool + minify bool // the directory to store the cached/combined files cache_dir string } diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 53712622ea..5264c8cdb2 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -41,11 +41,11 @@ pub const ( pub struct Context { mut: - content_type string = 'text/plain' - status string = '200 OK' + content_type string = 'text/plain' + status string = '200 OK' pub: - req http.Request - conn net.TcpConn + req http.Request + conn net.TcpConn // TODO Response pub mut: static_files map[string]string diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v index d1683ec999..8e71681dec 100644 --- a/vlib/x/websocket/message.v +++ b/vlib/x/websocket/message.v @@ -19,7 +19,7 @@ struct Fragment { struct Frame { mut: // length of the websocket header part - header_len int = 2 + header_len int = 2 // size of total frame frame_size int = 2 fin bool // true if final fragment of message diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index df3f7b083b..07046d31c1 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -16,7 +16,7 @@ const ( // Client represents websocket client pub struct Client { - is_server bool + is_server bool mut: ssl_conn &openssl.SSLConn // secure connection used when wss is used flags []Flag // flags used in handshake @@ -26,9 +26,9 @@ mut: open_callbacks []OpenEventHandler // all callbacks on_open close_callbacks []CloseEventHandler // all callbacks on_close pub: - is_ssl bool // true if secure socket is used - uri Uri // uri of current connection - id string // unique id of client + is_ssl bool // true if secure socket is used + uri Uri // uri of current connection + id string // unique id of client pub mut: conn net.TcpConn // underlying TCP socket connection nonce_size int = 16 // size of nounce used for masking diff --git a/vlib/x/websocket/websocket_server.v b/vlib/x/websocket/websocket_server.v index 398c2d82e8..295c47d4fe 100644 --- a/vlib/x/websocket/websocket_server.v +++ b/vlib/x/websocket/websocket_server.v @@ -15,12 +15,12 @@ mut: message_callbacks []MessageEventHandler // new message callback functions close_callbacks []CloseEventHandler // close message callback functions pub: - port int // port used as listen to incoming connections - is_ssl bool // true if secure connection (not supported yet on server) + port int // port used as listen to incoming connections + is_ssl bool // true if secure connection (not supported yet on server) pub mut: - clients map[string]&ServerClient // clients connected to this server - ping_interval int = 30 // interval for sending ping to clients (seconds) - state State // current state of connection + clients map[string]&ServerClient // clients connected to this server + ping_interval int = 30 // interval for sending ping to clients (seconds) + state State // current state of connection } // ServerClient represents a connected client @@ -29,8 +29,8 @@ pub: resource_name string // resource that the client access client_key string // unique key of client pub mut: - server &Server - client &Client + server &Server + client &Client } // new_server instance a new websocket server on provided port and route