fmt: align each contiguous field of struct. not the whole. (#7981)

pull/8056/head
zakuro 2021-01-12 12:38:43 +09:00 committed by GitHub
parent 82a5300044
commit 33694665f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 533 additions and 497 deletions

View File

@ -29,7 +29,7 @@ enum OutputType {
} }
struct VDoc { struct VDoc {
cfg Config [required] cfg Config [required]
mut: mut:
docs []doc.Doc docs []doc.Doc
assets map[string]string assets map[string]string

View File

@ -11,7 +11,7 @@ import v.table
import v.token import v.token
struct Vet { struct Vet {
opt Options opt Options
mut: mut:
errors []vet.Error errors []vet.Error
file string file string

View File

@ -2426,10 +2426,10 @@ struct Foo {
} }
struct User { struct User {
name string name string
age int age int
// Use the `skip` attribute to skip certain fields // 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 // If the field name is different in JSON, it can be specified
last_name string [json: lastName] last_name string [json: lastName]
} }

View File

@ -14,7 +14,7 @@ provides API (functions and methods) for accessing and modifying bit arrays.
*/ */
pub struct BitField { pub struct BitField {
mut: mut:
size int size int
// field *u32 // field *u32
field []u32 field []u32
} }

View File

@ -10,9 +10,9 @@ pub struct array {
pub: pub:
element_size int // size in bytes of one element in the array. element_size int // size in bytes of one element in the array.
pub mut: pub mut:
data voidptr data voidptr
len int // length of the array. len int // length of the array.
cap int // capacity of the array. cap int // capacity of the array.
} }
// array.data uses a void pointer, which allows implementing arrays without generics and without generating // array.data uses a void pointer, which allows implementing arrays without generics and without generating

View File

@ -97,9 +97,9 @@ struct DenseArray {
value_bytes int value_bytes int
slot_bytes int // sum of 2 fields above slot_bytes int // sum of 2 fields above
mut: mut:
cap int cap int
len int len int
deletes u32 // count deletes u32 // count
// array allocated (with `cap` bytes) on first deletion // array allocated (with `cap` bytes) on first deletion
// has non-zero element when key deleted // has non-zero element when key deleted
all_deleted &byte all_deleted &byte
@ -200,22 +200,22 @@ type MapFreeFn = fn (voidptr)
pub struct map { pub struct map {
// Number of bytes of a key // Number of bytes of a key
key_bytes int key_bytes int
// Number of bytes of a value // Number of bytes of a value
value_bytes int value_bytes int
mut: mut:
// Highest even index in the hashtable // Highest even index in the hashtable
even_index u32 even_index u32
// Number of cached hashbits left for rehasing // Number of cached hashbits left for rehasing
cached_hashbits byte cached_hashbits byte
// Used for right-shifting out used hashbits // Used for right-shifting out used hashbits
shift byte shift byte
// Array storing key-values (ordered) // Array storing key-values (ordered)
key_values DenseArray key_values DenseArray
// Pointer to meta-data: // Pointer to meta-data:
// - Odd indices store kv_index. // - Odd indices store kv_index.
// - Even indices store probe_count and hashbits. // - Even indices store probe_count and hashbits.
metas &u32 metas &u32
// Extra metas that allows for no ranging when incrementing // Extra metas that allows for no ranging when incrementing
// index in the hashmap // index in the hashmap
extra_metas u32 extra_metas u32
@ -226,7 +226,7 @@ mut:
free_fn MapFreeFn free_fn MapFreeFn
pub mut: pub mut:
// Number of key-values currently in the hashmap // Number of key-values currently in the hashmap
len int len int
} }
fn map_hash_string(pkey voidptr) u64 { fn map_hash_string(pkey voidptr) u64 {

View File

@ -17,7 +17,7 @@ pub mut:
required bool required bool
value string value string
mut: mut:
found bool found bool
} }
pub fn (flags []Flag) get_all_found() []Flag { pub fn (flags []Flag) get_all_found() []Flag {

View File

@ -25,36 +25,36 @@ pub type FNChar = fn (c u32, x voidptr)
pub struct Config { pub struct Config {
pub: pub:
width int width int
height int height int
use_ortho bool use_ortho bool
retina bool retina bool
resizable bool resizable bool
user_data voidptr user_data voidptr
font_size int font_size int
create_window bool create_window bool
// window_user_ptr voidptr // window_user_ptr voidptr
window_title string window_title string
borderless_window bool borderless_window bool
always_on_top bool always_on_top bool
bg_color gx.Color bg_color gx.Color
init_fn FNCb = voidptr(0) init_fn FNCb = voidptr(0)
frame_fn FNCb = voidptr(0) frame_fn FNCb = voidptr(0)
cleanup_fn FNCb = voidptr(0) cleanup_fn FNCb = voidptr(0)
fail_fn FNFail = voidptr(0) fail_fn FNFail = voidptr(0)
event_fn FNEvent = voidptr(0) event_fn FNEvent = voidptr(0)
keydown_fn FNKeyDown = voidptr(0) keydown_fn FNKeyDown = voidptr(0)
// special case of event_fn // special case of event_fn
char_fn FNChar = voidptr(0) char_fn FNChar = voidptr(0)
// special case of event_fn // special case of event_fn
move_fn FNMove = voidptr(0) move_fn FNMove = voidptr(0)
// special case of event_fn // special case of event_fn
click_fn FNMove = voidptr(0) click_fn FNMove = voidptr(0)
// special case of event_fn // special case of event_fn
// wait_events bool // set this to true for UIs, to save power // wait_events bool // set this to true for UIs, to save power
fullscreen bool fullscreen bool
scale f32 = 1.0 scale f32 = 1.0
sample_count int sample_count int
// vid needs this // vid needs this
// init_text bool // init_text bool
font_path string font_path string
@ -63,7 +63,7 @@ pub:
} }
pub struct Context { pub struct Context {
render_text bool render_text bool
mut: mut:
// a cache with all images created by the user. used for sokol image init and to save space // 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) // (so that the user can store image ids, not entire Image objects)
@ -71,17 +71,17 @@ mut:
needs_refresh bool = true needs_refresh bool = true
ticks int ticks int
pub mut: pub mut:
scale f32 = 1.0 scale f32 = 1.0
// will get set to 2.0 for retina, will remain 1.0 for normal // will get set to 2.0 for retina, will remain 1.0 for normal
width int width int
height int height int
clear_pass C.sg_pass_action clear_pass C.sg_pass_action
window C.sapp_desc window C.sapp_desc
timage_pip C.sgl_pipeline timage_pip C.sgl_pipeline
config Config config Config
ft &FT ft &FT
font_inited bool font_inited bool
ui_mode bool // do not redraw everything 60 times/second, but only when the user requests ui_mode bool // do not redraw everything 60 times/second, but only when the user requests
} }
pub struct Size { pub struct Size {

View File

@ -1,9 +1,9 @@
module os module os
pub struct File { pub struct File {
cfile voidptr // Using void* instead of FILE* cfile voidptr // Using void* instead of FILE*
pub: pub:
fd int fd int
pub mut: pub mut:
is_opened bool is_opened bool
} }

View File

@ -179,9 +179,9 @@ pub fn exec(cmd string) ?Result {
pub struct Command { pub struct Command {
mut: mut:
f voidptr f voidptr
pub mut: pub mut:
eof bool eof bool
pub: pub:
path string path string
redirect_stdout bool redirect_stdout bool

View File

@ -16,12 +16,12 @@ pub enum ProcessState {
[ref_only] [ref_only]
pub struct Process { pub struct Process {
pub: pub:
filename string // the process's command file path filename string // the process's command file path
pub mut: pub mut:
pid int // the PID of the process pid int // the PID of the process
code int = -1 code int = -1
// the exit code of the process, != -1 *only* when status is .exited *and* the process was not aborted // 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 // the current status of the process
err string // if the process fails, contains the reason why err string // if the process fails, contains the reason why
args []string // the arguments that the command takes args []string // the arguments that the command takes

View File

@ -5,7 +5,7 @@ struct RawVersion {
prerelease string prerelease string
metadata string metadata string
mut: mut:
raw_ints []string raw_ints []string
} }
const ( const (

View File

@ -5,7 +5,7 @@ module strings
pub struct Builder { pub struct Builder {
mut: mut:
buf []byte buf []byte
pub mut: pub mut:
len int len int
initial_size int = 1 initial_size int = 1

View File

@ -11,8 +11,8 @@ pub struct StopWatch {
mut: mut:
elapsed u64 elapsed u64
pub mut: pub mut:
start u64 start u64
end u64 end u64
} }
pub fn new_stopwatch(opts StopWatchOptions) StopWatch { pub fn new_stopwatch(opts StopWatchOptions) StopWatch {

View File

@ -52,7 +52,7 @@ pub:
comments []Comment comments []Comment
is_expr bool is_expr bool
pub mut: pub mut:
typ table.Type typ table.Type
} }
pub struct IntegerLiteral { pub struct IntegerLiteral {
@ -107,12 +107,12 @@ pub:
// `foo.bar` // `foo.bar`
pub struct SelectorExpr { pub struct SelectorExpr {
pub: pub:
pos token.Position pos token.Position
expr Expr // expr.field_name expr Expr // expr.field_name
field_name string 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 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 mut_pos token.Position
next_token token.Kind next_token token.Kind
pub mut: pub mut:
expr_type table.Type // type of `Foo` in `Foo.bar` expr_type table.Type // type of `Foo` in `Foo.bar`
typ table.Type // type of the entire thing (`Foo.bar`) typ table.Type // type of the entire thing (`Foo.bar`)
@ -152,8 +152,8 @@ pub:
attrs []table.Attr attrs []table.Attr
is_public bool is_public bool
pub mut: pub mut:
name string name string
typ table.Type typ table.Type
} }
pub struct Field { pub struct Field {
@ -161,17 +161,17 @@ pub:
name string name string
pos token.Position pos token.Position
pub mut: pub mut:
typ table.Type typ table.Type
} }
// const field in const declaration group // const field in const declaration group
pub struct ConstField { pub struct ConstField {
pub: pub:
mod string mod string
name string name string
expr Expr // the value expr of field; everything after `=` expr Expr // the value expr of field; everything after `=`
is_pub bool is_pub bool
pos token.Position pos token.Position
pub mut: pub mut:
typ table.Type // the type of the const field, it can be any type in V typ table.Type // the type of the const field, it can be any type in V
comments []Comment // comments before current const field comments []Comment // comments before current const field
@ -180,8 +180,8 @@ pub mut:
// const declaration // const declaration
pub struct ConstDecl { pub struct ConstDecl {
pub: pub:
is_pub bool is_pub bool
pos token.Position pos token.Position
pub mut: pub mut:
fields []ConstField // all the const fields in the `const (...)` block fields []ConstField // all the const fields in the `const (...)` block
end_comments []Comment // comments that after last const field end_comments []Comment // comments that after last const field
@ -203,7 +203,7 @@ pub:
end_comments []Comment end_comments []Comment
embeds []Embed embeds []Embed
pub mut: pub mut:
fields []StructField fields []StructField
} }
pub struct Embed { pub struct Embed {
@ -255,8 +255,8 @@ pub mut:
pub struct StructInit { pub struct StructInit {
pub: pub:
pos token.Position pos token.Position
is_short bool is_short bool
pub mut: pub mut:
pre_comments []Comment pre_comments []Comment
typ table.Type typ table.Type
@ -277,7 +277,7 @@ pub:
mod_pos token.Position mod_pos token.Position
alias_pos token.Position alias_pos token.Position
pub mut: 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 // import symbol,for import {symbol} syntax
@ -292,7 +292,7 @@ pub struct AnonFn {
pub: pub:
decl FnDecl decl FnDecl
pub mut: 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 // function or method declaration
@ -323,12 +323,12 @@ pub:
is_direct_arr bool // direct array access is_direct_arr bool // direct array access
attrs []table.Attr attrs []table.Attr
pub mut: pub mut:
stmts []Stmt stmts []Stmt
return_type table.Type return_type table.Type
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl 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 next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl
source_file &File = 0 source_file &File = 0
scope &Scope scope &Scope
} }
// break, continue // break, continue
@ -342,9 +342,9 @@ pub:
// function or method call expr // function or method call expr
pub struct CallExpr { pub struct CallExpr {
pub: pub:
pos token.Position pos token.Position
left Expr // `user` in `user.register()` left Expr // `user` in `user.register()`
mod string mod string
pub mut: pub mut:
name string // left.name() name string // left.name()
is_method bool is_method bool
@ -374,10 +374,10 @@ pub struct AutofreeArgVar {
// function call argument: `f(callarg)` // function call argument: `f(callarg)`
pub struct CallArg { pub struct CallArg {
pub: pub:
is_mut bool is_mut bool
share table.ShareType share table.ShareType
expr Expr expr Expr
comments []Comment comments []Comment
pub mut: pub mut:
typ table.Type 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 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 exprs []Expr
comments []Comment comments []Comment
pub mut: pub mut:
types []table.Type types []table.Type
} }
/* /*
@ -417,15 +417,15 @@ pub:
is_autofree_tmp bool is_autofree_tmp bool
is_arg bool // fn args should not be autofreed is_arg bool // fn args should not be autofreed
pub mut: pub mut:
typ table.Type typ table.Type
sum_type_casts []table.Type // nested sum types require nested smart casting, for that a list of types is needed sum_type_casts []table.Type // nested sum types require nested smart casting, for that a list of types is needed
pos token.Position pos token.Position
is_used bool is_used bool
is_changed bool // to detect mutable vars that are never changed is_changed bool // to detect mutable vars that are never changed
// //
// (for setting the position after the or block for autofree) // (for setting the position after the or block for autofree)
is_or bool // `x := foo() or { ... }` is_or bool // `x := foo() or { ... }`
is_tmp bool // for tmp for loop vars, so that autofree can skip them is_tmp bool // for tmp for loop vars, so that autofree can skip them
} }
// used for smartcasting only // used for smartcasting only
@ -452,7 +452,7 @@ pub mut:
pub struct GlobalDecl { pub struct GlobalDecl {
pub: pub:
pos token.Position pos token.Position
pub mut: pub mut:
fields []GlobalField fields []GlobalField
end_comments []Comment end_comments []Comment
@ -463,9 +463,9 @@ pub mut:
// That array is then passed to V's checker. // That array is then passed to V's checker.
pub struct File { pub struct File {
pub: pub:
path string // path of the source file path string // path of the source file
mod Module // the module of the source file (from `module xyz` at the top) mod Module // the module of the source file (from `module xyz` at the top)
global_scope &Scope global_scope &Scope
pub mut: pub mut:
scope &Scope scope &Scope
stmts []Stmt // all the statements in the source file stmts []Stmt // all the statements in the source file
@ -512,13 +512,13 @@ pub:
pos token.Position pos token.Position
mut_pos token.Position mut_pos token.Position
pub mut: pub mut:
scope &Scope scope &Scope
obj ScopeObject obj ScopeObject
mod string mod string
name string name string
kind IdentKind kind IdentKind
info IdentInfo info IdentInfo
is_mut bool is_mut bool
} }
pub fn (i &Ident) var_info() IdentVar { pub fn (i &Ident) var_info() IdentVar {
@ -537,8 +537,8 @@ pub fn (i &Ident) var_info() IdentVar {
// See: token.Kind.is_infix // See: token.Kind.is_infix
pub struct InfixExpr { pub struct InfixExpr {
pub: pub:
op token.Kind op token.Kind
pos token.Position pos token.Position
pub mut: pub mut:
left Expr left Expr
right Expr right Expr
@ -551,9 +551,9 @@ pub mut:
// ++, -- // ++, --
pub struct PostfixExpr { pub struct PostfixExpr {
pub: pub:
op token.Kind op token.Kind
expr Expr expr Expr
pos token.Position pos token.Position
pub mut: pub mut:
auto_locked string auto_locked string
} }
@ -561,9 +561,9 @@ pub mut:
// See: token.Kind.is_prefix // See: token.Kind.is_prefix
pub struct PrefixExpr { pub struct PrefixExpr {
pub: pub:
op token.Kind op token.Kind
right Expr right Expr
pos token.Position pos token.Position
pub mut: pub mut:
right_type table.Type right_type table.Type
or_block OrExpr or_block OrExpr
@ -571,10 +571,10 @@ pub mut:
pub struct IndexExpr { pub struct IndexExpr {
pub: pub:
pos token.Position pos token.Position
left Expr left Expr
index Expr // [0], RangeExpr [start..end] or map[key] index Expr // [0], RangeExpr [start..end] or map[key]
or_expr OrExpr or_expr OrExpr
pub mut: pub mut:
left_type table.Type // array, map, fixed array left_type table.Type // array, map, fixed array
is_setter bool is_setter bool
@ -588,18 +588,18 @@ pub:
pos token.Position pos token.Position
post_comments []Comment post_comments []Comment
pub mut: pub mut:
branches []IfBranch // includes all `else if` branches branches []IfBranch // includes all `else if` branches
is_expr bool is_expr bool
typ table.Type typ table.Type
has_else bool has_else bool
} }
pub struct IfBranch { pub struct IfBranch {
pub: pub:
cond Expr cond Expr
pos token.Position pos token.Position
body_pos token.Position body_pos token.Position
comments []Comment comments []Comment
pub mut: pub mut:
stmts []Stmt 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 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 is_rlock bool
pos token.Position pos token.Position
pub mut: pub mut:
lockeds []Ident // `x`, `y` in `lock x, y {` lockeds []Ident // `x`, `y` in `lock x, y {`
is_expr bool is_expr bool
typ table.Type typ table.Type
} }
pub struct MatchExpr { pub struct MatchExpr {
pub: pub:
tok_kind token.Kind tok_kind token.Kind
cond Expr cond Expr
branches []MatchBranch branches []MatchBranch
pos token.Position pos token.Position
pub mut: pub mut:
is_expr bool // returns a value is_expr bool // returns a value
return_type table.Type return_type table.Type
@ -647,7 +647,7 @@ pub:
is_else bool is_else bool
post_comments []Comment post_comments []Comment
pub mut: pub mut:
scope &Scope scope &Scope
} }
pub struct SelectExpr { pub struct SelectExpr {
@ -684,7 +684,7 @@ pub:
pos token.Position pos token.Position
pub mut: pub mut:
// expr Expr // expr Expr
typ table.Type typ table.Type
} }
pub struct ForStmt { pub struct ForStmt {
@ -694,8 +694,8 @@ pub:
is_inf bool // `for {}` is_inf bool // `for {}`
pos token.Position pos token.Position
pub mut: pub mut:
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope
} }
pub struct ForInStmt { 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 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 // and the array cannot be indexed inside the loop
pub mut: pub mut:
key_type table.Type key_type table.Type
val_type table.Type val_type table.Type
cond_type table.Type cond_type table.Type
kind table.Kind // array/map/string kind table.Kind // array/map/string
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope
} }
pub struct ForCStmt { pub struct ForCStmt {
@ -729,15 +729,15 @@ pub:
stmts []Stmt stmts []Stmt
pos token.Position pos token.Position
pub mut: pub mut:
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope
} }
// #include etc // #include etc
pub struct HashStmt { pub struct HashStmt {
pub: pub:
mod string mod string
pos token.Position pos token.Position
pub mut: pub mut:
val string // example: 'include <openssl/rand.h> # please install openssl // comment' val string // example: 'include <openssl/rand.h> # please install openssl // comment'
kind string // : 'include' kind string // : 'include'
@ -755,11 +755,11 @@ pub:
// variable assign statement // variable assign statement
pub struct AssignStmt { pub struct AssignStmt {
pub: pub:
right []Expr right []Expr
op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v
pos token.Position pos token.Position
comments []Comment comments []Comment
end_comments []Comment end_comments []Comment
pub mut: pub mut:
left []Expr left []Expr
left_types []table.Type left_types []table.Type
@ -771,9 +771,9 @@ pub mut:
pub struct AsCast { pub struct AsCast {
pub: pub:
expr Expr expr Expr
typ table.Type typ table.Type
pos token.Position pos token.Position
pub mut: pub mut:
expr_type table.Type expr_type table.Type
} }
@ -786,7 +786,7 @@ pub:
mod string // for full path `mod_Enum_val` mod string // for full path `mod_Enum_val`
pos token.Position pos token.Position
pub mut: pub mut:
typ table.Type typ table.Type
} }
// enum field in enum declaration // enum field in enum declaration
@ -886,19 +886,19 @@ pub:
pub struct ArrayInit { pub struct ArrayInit {
pub: pub:
pos token.Position // `[]` in []Type{} position pos token.Position // `[]` in []Type{} position
elem_type_pos token.Position // `Type` in []Type{} position elem_type_pos token.Position // `Type` in []Type{} position
exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array
ecmnts [][]Comment // optional iembed comments after each expr ecmnts [][]Comment // optional iembed comments after each expr
is_fixed bool is_fixed bool
has_val bool // fixed size literal `[expr, expr]!!` has_val bool // fixed size literal `[expr, expr]!!`
mod string mod string
len_expr Expr // len: expr len_expr Expr // len: expr
cap_expr Expr // cap: expr cap_expr Expr // cap: expr
default_expr Expr // init: expr default_expr Expr // init: expr
has_len bool has_len bool
has_cap bool has_cap bool
has_default bool has_default bool
pub mut: pub mut:
expr_types []table.Type // [Dog, Cat] // also used for interface_types expr_types []table.Type // [Dog, Cat] // also used for interface_types
is_interface bool // array of interfaces e.g. `[]Animal` `[Dog{}, Cat{}]` is_interface bool // array of interfaces e.g. `[]Animal` `[Dog{}, Cat{}]`
@ -909,8 +909,8 @@ pub mut:
pub struct ArrayDecompose { pub struct ArrayDecompose {
pub: pub:
expr Expr expr Expr
pos token.Position pos token.Position
pub mut: pub mut:
expr_type table.Type expr_type table.Type
arg_type table.Type arg_type table.Type
@ -918,9 +918,9 @@ pub mut:
pub struct ChanInit { pub struct ChanInit {
pub: pub:
pos token.Position pos token.Position
cap_expr Expr cap_expr Expr
has_cap bool has_cap bool
pub mut: pub mut:
typ table.Type typ table.Type
elem_type table.Type elem_type table.Type
@ -928,9 +928,9 @@ pub mut:
pub struct MapInit { pub struct MapInit {
pub: pub:
pos token.Position pos token.Position
keys []Expr keys []Expr
vals []Expr vals []Expr
pub mut: pub mut:
typ table.Type typ table.Type
key_type table.Type key_type table.Type
@ -957,10 +957,10 @@ pub:
// `string(x,y)`, while skipping the real pointer casts like `&string(x)`. // `string(x,y)`, while skipping the real pointer casts like `&string(x)`.
pub struct CastExpr { pub struct CastExpr {
pub: pub:
expr Expr // `buf` in `string(buf, n)` expr Expr // `buf` in `string(buf, n)`
arg Expr // `n` in `string(buf, n)` arg Expr // `n` in `string(buf, n)`
typ table.Type // `string` TODO rename to `type_to_cast_to` typ table.Type // `string` TODO rename to `type_to_cast_to`
pos token.Position pos token.Position
pub mut: pub mut:
typname string // TypeSymbol.name typname string // TypeSymbol.name
expr_type table.Type // `byteptr` expr_type table.Type // `byteptr`
@ -970,7 +970,7 @@ pub mut:
pub struct AssertStmt { pub struct AssertStmt {
pub: pub:
pos token.Position pos token.Position
pub mut: pub mut:
expr Expr expr Expr
} }
@ -978,9 +978,9 @@ pub mut:
// `if [x := opt()] {` // `if [x := opt()] {`
pub struct IfGuardExpr { pub struct IfGuardExpr {
pub: pub:
var_name string var_name string
expr Expr expr Expr
pos token.Position pos token.Position
pub mut: pub mut:
expr_type table.Type expr_type table.Type
} }
@ -1016,8 +1016,8 @@ pub:
exprs []Expr exprs []Expr
pos token.Position pos token.Position
pub mut: pub mut:
typ table.Type typ table.Type
scope &Scope scope &Scope
} }
pub struct SizeOf { pub struct SizeOf {
@ -1038,8 +1038,8 @@ pub:
pub struct TypeOf { pub struct TypeOf {
pub: pub:
expr Expr expr Expr
pos token.Position pos token.Position
pub mut: pub mut:
expr_type table.Type expr_type table.Type
} }
@ -1054,8 +1054,8 @@ pub:
pub struct ConcatExpr { pub struct ConcatExpr {
pub: pub:
vals []Expr vals []Expr
pos token.Position pos token.Position
pub mut: pub mut:
return_type table.Type return_type table.Type
} }
@ -1067,7 +1067,7 @@ pub:
pos token.Position pos token.Position
kind token.AtKind kind token.AtKind
pub mut: pub mut:
val string val string
} }
pub struct ComptimeSelector { pub struct ComptimeSelector {
@ -1076,8 +1076,8 @@ pub:
left Expr left Expr
field_expr Expr field_expr Expr
pub mut: pub mut:
left_type table.Type left_type table.Type
typ table.Type typ table.Type
} }
pub struct ComptimeCall { pub struct ComptimeCall {
@ -1089,7 +1089,7 @@ pub:
vweb_tmpl File vweb_tmpl File
args_var string args_var string
pub mut: pub mut:
sym table.TypeSymbol sym table.TypeSymbol
} }
pub struct None { pub struct None {
@ -1122,8 +1122,8 @@ pub:
updated_columns []string // for `update set x=y` updated_columns []string // for `update set x=y`
update_exprs []Expr // for `update` update_exprs []Expr // for `update`
pub mut: pub mut:
table_name string table_name string
fields []table.Field fields []table.Field
} }
pub struct SqlExpr { pub struct SqlExpr {
@ -1144,8 +1144,8 @@ pub:
has_limit bool has_limit bool
limit_expr Expr limit_expr Expr
pub mut: pub mut:
table_name string table_name string
fields []table.Field fields []table.Field
} }
[inline] [inline]

View File

@ -12,7 +12,7 @@ pub type InspectorFn = fn (node ast.Node, data voidptr) bool
struct Inspector { struct Inspector {
inspector_callback InspectorFn inspector_callback InspectorFn
mut: mut:
data voidptr data voidptr
} }
pub fn (i &Inspector) visit(node ast.Node) ? { pub fn (i &Inspector) visit(node ast.Node) ? {

View File

@ -14,7 +14,7 @@ fn parse_text(text string) ast.File {
} }
struct NodeByOffset { struct NodeByOffset {
pos int pos int
mut: mut:
node ast.Node node ast.Node
} }

View File

@ -12,15 +12,15 @@ import v.depgraph
pub struct Builder { pub struct Builder {
pub: pub:
compiled_dir string // contains os.real_path() of the dir of the final file beeing compiled, or the dir itself when doing `v .` 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 module_path string
mut: mut:
pref &pref.Preferences pref &pref.Preferences
checker checker.Checker checker checker.Checker
global_scope &ast.Scope global_scope &ast.Scope
out_name_c string out_name_c string
out_name_js string out_name_js string
max_nr_errors int = 100 max_nr_errors int = 100
pub mut: pub mut:
module_search_paths []string module_search_paths []string
parsed_files []ast.File parsed_files []ast.File

View File

@ -163,20 +163,20 @@ mut:
shared_postfix string // .so, .dll shared_postfix string // .so, .dll
// //
// //
debug_mode bool debug_mode bool
is_cc_tcc bool is_cc_tcc bool
is_cc_gcc bool is_cc_gcc bool
is_cc_msvc bool is_cc_msvc bool
is_cc_clang bool is_cc_clang bool
// //
env_cflags string // prepended *before* everything else env_cflags string // prepended *before* everything else
env_ldflags string // appended *after* everything else env_ldflags string // appended *after* everything else
// //
args []string // ordinary C options like `-O2` args []string // ordinary C options like `-O2`
wargs []string // for `-Wxyz` *exclusively* wargs []string // for `-Wxyz` *exclusively*
o_args []string // for `-o target` o_args []string // for `-o target`
post_args []string // options that should go after .o_args post_args []string // options that should go after .o_args
linker_flags []string // `-lm` linker_flags []string // `-lm`
} }
fn (mut v Builder) setup_ccompiler_options(ccompiler string) { fn (mut v Builder) setup_ccompiler_options(ccompiler string) {

View File

@ -8,10 +8,10 @@ import os
// parsed cflag // parsed cflag
pub struct CFlag { pub struct CFlag {
pub: pub:
mod string // the module in which the flag was given mod string // the module in which the flag was given
os string // eg. windows | darwin | linux os string // eg. windows | darwin | linux
name string // eg. -I name string // eg. -I
value string // eg. /path/to/include value string // eg. /path/to/include
pub mut: pub mut:
cached string // eg. ~/.vmodules/cache/ea/ea9878886727367672163.o (for .o files) cached string // eg. ~/.vmodules/cache/ea/ea9878886727367672163.o (for .o files)
} }

View File

@ -31,34 +31,34 @@ const (
) )
pub struct Checker { pub struct Checker {
pref &pref.Preferences // Preferences shared from V struct pref &pref.Preferences // Preferences shared from V struct
pub mut: pub mut:
table &table.Table table &table.Table
file &ast.File = 0 file &ast.File = 0
nr_errors int nr_errors int
nr_warnings int nr_warnings int
errors []errors.Error errors []errors.Error
warnings []errors.Warning warnings []errors.Warning
error_lines []int // to avoid printing multiple errors for the same line error_lines []int // to avoid printing multiple errors for the same line
expected_type table.Type expected_type table.Type
expected_or_type table.Type // fn() or { 'this type' } eg. string. expected or block type expected_or_type table.Type // fn() or { 'this type' } eg. string. expected or block type
cur_fn &ast.FnDecl // current function cur_fn &ast.FnDecl // current function
const_decl string const_decl string
const_deps []string const_deps []string
const_names []string const_names []string
global_names []string global_names []string
locked_names []string // vars that are currently locked locked_names []string // vars that are currently locked
rlocked_names []string // vars that are currently read-locked rlocked_names []string // vars that are currently read-locked
in_for_count int // if checker is currently in a for loop in_for_count int // if checker is currently in a for loop
// checked_ident string // to avoid infinite checker loops // checked_ident string // to avoid infinite checker loops
returns bool returns bool
scope_returns bool scope_returns bool
mod string // current module name mod string // current module name
is_builtin_mod bool // are we in `builtin`? is_builtin_mod bool // are we in `builtin`?
inside_unsafe bool inside_unsafe bool
inside_const bool inside_const bool
skip_flags bool // should `#flag` and `#include` be skipped skip_flags bool // should `#flag` and `#include` be skipped
cur_generic_type table.Type cur_generic_type table.Type
mut: mut:
expr_level int // to avoid infinite recursion segfaults due to compiler bugs expr_level int // to avoid infinite recursion segfaults due to compiler bugs
inside_sql bool // to handle sql table fields pseudo variables inside_sql bool // to handle sql table fields pseudo variables

View File

@ -41,11 +41,11 @@ pub fn (sk SymbolKind) str() string {
} }
pub struct Doc { pub struct Doc {
prefs &pref.Preferences = new_vdoc_preferences() prefs &pref.Preferences = new_vdoc_preferences()
pub mut: pub mut:
base_path string base_path string
table &table.Table = &table.Table{} table &table.Table = &table.Table{}
checker checker.Checker = checker.Checker{ checker checker.Checker = checker.Checker{
table: 0 table: 0
cur_fn: 0 cur_fn: 0
pref: 0 pref: 0

View File

@ -589,10 +589,56 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
f.writeln('\n') f.writeln('\n')
} }
[inline]
fn abs(v int) int {
return if v >= 0 {
v
} else {
-v
}
}
const ( const (
threshold_to_align_struct = 8 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 { struct CommentAndExprAlignInfo {
mut: mut:
max_attrs_len int 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) { fn (mut list []CommentAndExprAlignInfo) add_info(attrs_len int, type_len int, line int) {
if list.len == 0 { if list.len == 0 {
list.add_new_info(attrs_len, type_len, line) list.add_new_info(attrs_len, type_len, line)
@ -667,8 +704,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
return return
} }
f.writeln(' {') f.writeln(' {')
mut max := 0 mut field_aligns := []StructFieldAlignInfo{}
mut max_type_len := 0
mut comment_aligns := []CommentAndExprAlignInfo{} mut comment_aligns := []CommentAndExprAlignInfo{}
mut default_expr_aligns := []CommentAndExprAlignInfo{} mut default_expr_aligns := []CommentAndExprAlignInfo{}
mut field_types := []string{cap: node.fields.len} 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) ft = f.short_module(ft)
} }
field_types << ft field_types << ft
if ft.len > max_type_len {
max_type_len = ft.len
}
attrs_len := inline_attrs_len(field.attrs) attrs_len := inline_attrs_len(field.attrs)
end_pos := field.pos.pos + field.pos.len end_pos := field.pos.pos + field.pos.len
mut comments_len := 0 // Length of comments between field name and type 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 comments_len += '/* $comment.text */ '.len
} }
} }
if comments_len + field.name.len > max { field_aligns.add_info(comments_len + field.name.len, ft.len, field.pos.line_nr)
max = comments_len + field.name.len
}
if field.has_default_expr { if field.has_default_expr {
default_expr_aligns.add_info(attrs_len, field_types[i].len, field.pos.line_nr) 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) styp := f.table.type_to_str(embed.typ)
f.writeln('\t$styp') f.writeln('\t$styp')
} }
mut field_align_i := 0
mut comment_align_i := 0 mut comment_align_i := 0
mut default_expr_align_i := 0 mut default_expr_align_i := 0
for i, field in node.fields { for i, field in node.fields {
@ -737,13 +769,17 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
f.write(comment_text) f.write(comment_text)
comm_idx++ 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]) f.write(field_types[i])
after_type_pad_len := max_type_len - field_types[i].len
attrs_len := inline_attrs_len(field.attrs) attrs_len := inline_attrs_len(field.attrs)
has_attrs := field.attrs.len > 0 has_attrs := field.attrs.len > 0
if has_attrs { 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) f.inline_attrs(field.attrs)
} }
if field.has_default_expr { if field.has_default_expr {

View File

@ -6,7 +6,7 @@ mut:
} }
struct TileLine { struct TileLine {
ypos int ypos int
mut: mut:
field [5]int field [5]int
points int points int

View File

@ -9,7 +9,7 @@ enum Abc {
struct User { struct User {
name string // name name string // name
// middle comment // middle comment
age int age int
// last comment // last comment
// last comment2 // last comment2
} }

View File

@ -10,7 +10,7 @@ fn (f Foo<int>) value() string {
type DB = string type DB = string
struct Repo <T, U> { struct Repo <T, U> {
db DB db DB
pub mut: pub mut:
model T model T
permission U permission U

View File

@ -8,13 +8,13 @@ struct User {
} }
struct Foo { struct Foo {
field1 int // f1 field1 int // f1
field2 string // f2 field2 string // f2
pub: pub:
public_field1 int // f1 public_field1 int // f1
public_field2 f64 // f2 public_field2 f64 // f2
mut: mut:
mut_field string mut_field string
pub mut: pub mut:
pub_mut_field string pub_mut_field string
} }
@ -38,9 +38,9 @@ mut:
9 9
10 10
*/ */
somefield2 /* 11 */ int // 12 somefield2 /* 11 */ int // 12
pub: pub:
somefield3 int somefield3 int
/* /*
13 13
14 14

View File

@ -25,104 +25,104 @@ const (
) )
struct Gen { struct Gen {
pref &pref.Preferences pref &pref.Preferences
module_built string module_built string
mut: mut:
table &table.Table table &table.Table
out strings.Builder out strings.Builder
cheaders strings.Builder cheaders strings.Builder
includes strings.Builder // all C #includes required by V modules includes strings.Builder // all C #includes required by V modules
typedefs strings.Builder typedefs strings.Builder
typedefs2 strings.Builder typedefs2 strings.Builder
type_definitions strings.Builder // typedefs, defines etc (everything that goes to the top of the file) 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) 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{}` inits map[string]strings.Builder // contents of `void _vinit/2{}`
cleanups map[string]strings.Builder // contents of `void _vcleanup(){}` cleanups map[string]strings.Builder // contents of `void _vcleanup(){}`
gowrappers strings.Builder // all go callsite wrappers gowrappers strings.Builder // all go callsite wrappers
stringliterals strings.Builder // all string literals (they depend on tos3() beeing defined 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 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 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 pcs_declarations strings.Builder // -prof profile counter declarations for each function
hotcode_definitions strings.Builder // -live declarations & functions hotcode_definitions strings.Builder // -live declarations & functions
shared_types strings.Builder // shared/lock types shared_types strings.Builder // shared/lock types
channel_definitions strings.Builder // channel related code channel_definitions strings.Builder // channel related code
options_typedefs strings.Builder // Option typedefs options_typedefs strings.Builder // Option typedefs
options strings.Builder // `Option_xxxx` types options strings.Builder // `Option_xxxx` types
json_forward_decls strings.Builder // json type forward decls json_forward_decls strings.Builder // json type forward decls
enum_typedefs strings.Builder // enum types enum_typedefs strings.Builder // enum types
sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc
file ast.File file ast.File
fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0 fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0
last_fn_c_name string last_fn_c_name string
tmp_count int // counter for unique tmp vars (_tmp1, tmp2 etc) tmp_count int // counter for unique tmp vars (_tmp1, tmp2 etc)
tmp_count2 int // a separate tmp var counter for autofree fn calls tmp_count2 int // a separate tmp var counter for autofree fn calls
is_c_call bool // e.g. `C.printf("v")` 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_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_assign_rhs bool // inside right part of assign after `=` (val expr)
is_array_set bool is_array_set bool
is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&byte(0)` etc 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_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_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 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 vlines_path string // set to the proper path for generating #line directives
optionals []string // to avoid duplicates TODO perf, use map optionals []string // to avoid duplicates TODO perf, use map
chan_pop_optionals []string // types for `x := <-ch or {...}` chan_pop_optionals []string // types for `x := <-ch or {...}`
chan_push_optionals []string // types for `ch <- x or {...}` chan_push_optionals []string // types for `ch <- x or {...}`
shareds []int // types with hidden mutex for which decl has been emitted shareds []int // types with hidden mutex for which decl has been emitted
inside_ternary int // ?: comma separated statements on a single line inside_ternary int // ?: comma separated statements on a single line
inside_map_postfix bool // inside map++/-- postfix expr inside_map_postfix bool // inside map++/-- postfix expr
inside_map_infix bool // inside map<</+=/-= infix expr inside_map_infix bool // inside map<</+=/-= infix expr
// inside_if_expr bool // inside_if_expr bool
ternary_names map[string]string ternary_names map[string]string
ternary_level_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 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) skip_stmt_pos bool // for handling if expressions + autofree (since both prepend C statements)
right_is_opt bool right_is_opt bool
is_autofree bool // false, inside the bodies of fns marked with [manualfree], otherwise === g.pref.autofree is_autofree bool // false, inside the bodies of fns marked with [manualfree], otherwise === g.pref.autofree
indent int indent int
empty_line bool empty_line bool
is_test bool is_test bool
assign_op token.Kind // *=, =, etc (for array_set) assign_op token.Kind // *=, =, etc (for array_set)
defer_stmts []ast.DeferStmt defer_stmts []ast.DeferStmt
defer_ifdef string defer_ifdef string
defer_profile_code string defer_profile_code string
str_types []string // types that need automatic str() generation str_types []string // types that need automatic str() generation
threaded_fns []string // for generating unique wrapper types and fns for `go xxx()` threaded_fns []string // for generating unique wrapper types and fns for `go xxx()`
array_fn_definitions []string // array equality functions that have been defined array_fn_definitions []string // array equality functions that have been defined
map_fn_definitions []string // map 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 struct_fn_definitions []string // struct equality functions that have been defined
auto_fn_definitions []string // auto generated functions defination list auto_fn_definitions []string // auto generated functions defination list
is_json_fn bool // inside json.encode() is_json_fn bool // inside json.encode()
json_types []string // to avoid json gen duplicates json_types []string // to avoid json gen duplicates
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
is_builtin_mod bool is_builtin_mod bool
hotcode_fn_names []string hotcode_fn_names []string
// cur_fn ast.FnDecl // cur_fn ast.FnDecl
cur_generic_type table.Type // `int`, `string`, etc in `foo<T>()` cur_generic_type table.Type // `int`, `string`, etc in `foo<T>()`
sql_i int sql_i int
sql_stmt_name string sql_stmt_name string
sql_side SqlExprSide // left or right, to distinguish idents in `name == name` sql_side SqlExprSide // left or right, to distinguish idents in `name == name`
inside_vweb_tmpl bool inside_vweb_tmpl bool
inside_return bool inside_return bool
inside_or_block bool inside_or_block bool
strs_to_free0 []string // strings.Builder strs_to_free0 []string // strings.Builder
// strs_to_free []string // strings.Builder // strs_to_free []string // strings.Builder
inside_call bool inside_call bool
has_main bool has_main bool
inside_const bool inside_const bool
comp_for_method string // $for method in T.methods {} 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_var string // $for field in T.fields {}; the variable name
comp_for_field_value table.Field // value of the field variable 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 {}` 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 comptime_var_type_map map[string]table.Type
// tmp_arg_vars_to_free []string // tmp_arg_vars_to_free []string
// autofree_pregen map[string]string // autofree_pregen map[string]string
// autofree_pregen_buf strings.Builder // autofree_pregen_buf strings.Builder
// autofree_tmp_vars []string // to avoid redefining the same tmp vars in a single function // autofree_tmp_vars []string // to avoid redefining the same tmp vars in a single function
called_fn_name string called_fn_name string
cur_mod ast.Module cur_mod ast.Module
is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)` is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)`
is_fn_index_call bool is_fn_index_call bool
// nr_vars_to_free int // nr_vars_to_free int
// doing_autofree_tmp bool // doing_autofree_tmp bool
inside_lambda bool inside_lambda bool
@ -131,11 +131,11 @@ mut:
// TypeOne, TypeTwo {} // TypeOne, TypeTwo {}
// where an aggregate (at least two types) is generated // 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 // sum type deref needs to know which index to deref because unions take care of the correct field
aggregate_type_idx int aggregate_type_idx int
returned_var_name string // to detect that a var doesn't need to be freed since it's being returned 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 branch_parent_pos int // used in BranchStmt (continue/break) for autofree stop position
timers &util.Timers = util.new_timers(false) timers &util.Timers = util.new_timers(false)
force_main_console bool // true when [console] used on fn main() force_main_console bool // true when [console] used on fn main()
} }
const ( const (

View File

@ -13,8 +13,8 @@ import strings
import v.table import v.table
pub struct Gen { pub struct Gen {
out_name string out_name string
pref &pref.Preferences // Preferences shared from V struct pref &pref.Preferences // Preferences shared from V struct
mut: mut:
table &table.Table table &table.Table
buf []byte buf []byte

View File

@ -20,7 +20,7 @@ const (
) )
pub struct Parser { pub struct Parser {
pref &pref.Preferences pref &pref.Preferences
mut: mut:
file_base string // "hello.v" file_base string // "hello.v"
file_name string // "/home/user/hello.v" file_name string // "/home/user/hello.v"

View File

@ -49,71 +49,71 @@ const (
pub struct Preferences { pub struct Preferences {
pub mut: pub mut:
os OS // the OS to compile for os OS // the OS to compile for
backend Backend backend Backend
build_mode BuildMode build_mode BuildMode
output_mode OutputMode = .stdout output_mode OutputMode = .stdout
// verbosity VerboseLevel // verbosity VerboseLevel
is_verbose bool is_verbose bool
// nofmt bool // disable vfmt // nofmt bool // disable vfmt
is_test bool // `v test string_test.v` is_test bool // `v test string_test.v`
is_script bool // single file mode (`v program.v`), main function can be skipped 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_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_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_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_shared bool // an ordinary shared library, -shared, no matter if it is live or not
is_prof bool // benchmark every function is_prof bool // benchmark every function
profile_file string // the profile results will be stored inside profile_file profile_file string // the profile results will be stored inside profile_file
profile_no_inline bool // when true, [inline] functions would not be profiled 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 translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc
is_prod bool // use "-O2" is_prod bool // use "-O2"
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX" obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
is_repl bool is_repl bool
is_run bool is_run bool
sanitize bool // use Clang's new "-fsanitize" option 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_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). 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_cc bool // -showcc, print cc command
show_c_output bool // -show-c-output, print all cc output even if the code was compiled correctly 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, // 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). // 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 cached modules to speed up compilation.
use_cache bool // = true use_cache bool // = true
retry_compilation 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 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 // 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. // 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 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'. // 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 m64 bool // true = generate 64-bit code, defaults to x64
ccompiler string // the name of the C compiler used ccompiler string // the name of the C compiler used
ccompiler_type CompilerType // the type of the C compiler used ccompiler_type CompilerType // the type of the C compiler used
third_party_option string third_party_option string
building_v bool building_v bool
autofree bool // `v -manualfree` => false, `v -autofree` => true; false by default for now. 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) // 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 // skip_builtin bool // Skips re-compilation of the builtin module
// to increase compilation time. // to increase compilation time.
// This is on by default, since a vast majority of users do not // This is on by default, since a vast majority of users do not
// work on the builtin module itself. // work on the builtin module itself.
// generating_vh bool // generating_vh bool
enable_globals bool // allow __global for low level code enable_globals bool // allow __global for low level code
is_fmt bool is_fmt bool
is_vet bool is_vet bool
is_bare bool is_bare bool
no_preludes bool // Prevents V from generating preludes in resulting .c files 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 custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files
lookup_path []string lookup_path []string
output_cross_c bool output_cross_c bool
prealloc bool prealloc bool
vroot string vroot string
out_name_c string // full os.real_path to the generated .tmp.c file; set by builder. out_name_c string // full os.real_path to the generated .tmp.c file; set by builder.
out_name string out_name string
display_name string display_name string
bundle_id string bundle_id string
path string // Path to file/folder to compile 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 }` // -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 []string // just ['vfmt']
compile_defines_all []string // contains both: ['vfmt','another'] compile_defines_all []string // contains both: ['vfmt','another']

View File

@ -19,17 +19,17 @@ const (
pub struct Scanner { pub struct Scanner {
pub mut: pub mut:
file_path string file_path string
text string text string
pos int pos int
line_nr int line_nr int
last_nl_pos int // for calculating column last_nl_pos int // for calculating column
is_inside_string bool is_inside_string bool
is_inter_start bool // for hacky string interpolation TODO simplify is_inter_start bool // for hacky string interpolation TODO simplify
is_inter_end bool is_inter_end bool
is_enclosed_inter bool is_enclosed_inter bool
is_debug bool is_debug bool
line_comment string line_comment string
// prev_tok TokenKind // prev_tok TokenKind
is_started bool is_started bool
is_print_line_on_error bool is_print_line_on_error bool

View File

@ -37,8 +37,8 @@ pub:
ctdefine string // compile time define. myflag, when [if myflag] tag ctdefine string // compile time define. myflag, when [if myflag] tag
attrs []Attr attrs []Attr
pub mut: pub mut:
name string name string
source_fn voidptr // set in the checker, while processing fn declarations source_fn voidptr // set in the checker, while processing fn declarations
} }
fn (f &Fn) method_equals(o &Fn) bool { fn (f &Fn) method_equals(o &Fn) bool {
@ -77,7 +77,7 @@ pub:
name string name string
is_mut bool is_mut bool
mut: mut:
typ Type typ Type
} }
pub fn new_table() &Table { pub fn new_table() &Table {

View File

@ -35,14 +35,14 @@ pub struct TypeSymbol {
pub: pub:
parent_idx int parent_idx int
pub mut: pub mut:
info TypeInfo info TypeInfo
kind Kind kind Kind
name string // the internal & source name of the type, i.e. `[5]int`. 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 cname string // the name with no dots for use in the generated C code
methods []Fn methods []Fn
mod string mod string
is_public bool is_public bool
language Language language Language
} }
// max of 8 // max of 8
@ -609,7 +609,7 @@ pub fn (kinds []Kind) str() string {
pub struct Struct { pub struct Struct {
pub: pub:
attrs []Attr attrs []Attr
pub mut: pub mut:
embeds []Type embeds []Type
fields []Field fields []Field
@ -649,7 +649,7 @@ pub struct Aggregate {
mut: mut:
fields []Field // used for faster lookup inside the module fields []Field // used for faster lookup inside the module
pub: pub:
types []Type types []Type
} }
// NB: FExpr here is a actually an ast.Expr . // NB: FExpr here is a actually an ast.Expr .
@ -659,7 +659,7 @@ pub type FExpr = byteptr | voidptr
pub struct Field { pub struct Field {
pub: pub:
name string name string
pub mut: pub mut:
typ Type typ Type
default_expr FExpr default_expr FExpr
@ -681,15 +681,15 @@ fn (f &Field) equals(o &Field) bool {
pub struct Array { pub struct Array {
pub: pub:
nr_dims int nr_dims int
pub mut: pub mut:
elem_type Type elem_type Type
} }
pub struct ArrayFixed { pub struct ArrayFixed {
pub: pub:
nr_dims int nr_dims int
size int size int
pub mut: pub mut:
elem_type Type elem_type Type
} }

View File

@ -3,8 +3,8 @@ module util
import strings import strings
struct Possibility { struct Possibility {
value string value string
svalue string svalue string
mut: mut:
similarity f32 similarity f32
} }

View File

@ -23,7 +23,7 @@ pub struct ModFileAndFolder {
pub: pub:
// vmod_file contains the full path of the found 'v.mod' file, or '' // 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. // 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 // 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, // *any* of the parent folders, otherwise it is the first parent folder,
// where a v.mod file was found. // where a v.mod file was found.
@ -33,7 +33,7 @@ pub:
[ref_only] [ref_only]
pub struct ModFileCacher { pub struct ModFileCacher {
mut: mut:
cache map[string]ModFileAndFolder cache map[string]ModFileAndFolder
// folder_files caches os.ls(key) // folder_files caches os.ls(key)
folder_files map[string][]string folder_files map[string][]string
} }

View File

@ -12,11 +12,11 @@ const (
struct AssetManager { struct AssetManager {
mut: mut:
css []Asset css []Asset
js []Asset js []Asset
pub mut: pub mut:
// when true assets will be minified // when true assets will be minified
minify bool minify bool
// the directory to store the cached/combined files // the directory to store the cached/combined files
cache_dir string cache_dir string
} }

View File

@ -41,11 +41,11 @@ pub const (
pub struct Context { pub struct Context {
mut: mut:
content_type string = 'text/plain' content_type string = 'text/plain'
status string = '200 OK' status string = '200 OK'
pub: pub:
req http.Request req http.Request
conn net.TcpConn conn net.TcpConn
// TODO Response // TODO Response
pub mut: pub mut:
static_files map[string]string static_files map[string]string

View File

@ -19,7 +19,7 @@ struct Fragment {
struct Frame { struct Frame {
mut: mut:
// length of the websocket header part // length of the websocket header part
header_len int = 2 header_len int = 2
// size of total frame // size of total frame
frame_size int = 2 frame_size int = 2
fin bool // true if final fragment of message fin bool // true if final fragment of message

View File

@ -16,7 +16,7 @@ const (
// Client represents websocket client // Client represents websocket client
pub struct Client { pub struct Client {
is_server bool is_server bool
mut: mut:
ssl_conn &openssl.SSLConn // secure connection used when wss is used ssl_conn &openssl.SSLConn // secure connection used when wss is used
flags []Flag // flags used in handshake flags []Flag // flags used in handshake
@ -26,9 +26,9 @@ mut:
open_callbacks []OpenEventHandler // all callbacks on_open open_callbacks []OpenEventHandler // all callbacks on_open
close_callbacks []CloseEventHandler // all callbacks on_close close_callbacks []CloseEventHandler // all callbacks on_close
pub: pub:
is_ssl bool // true if secure socket is used is_ssl bool // true if secure socket is used
uri Uri // uri of current connection uri Uri // uri of current connection
id string // unique id of client id string // unique id of client
pub mut: pub mut:
conn net.TcpConn // underlying TCP socket connection conn net.TcpConn // underlying TCP socket connection
nonce_size int = 16 // size of nounce used for masking nonce_size int = 16 // size of nounce used for masking

View File

@ -15,12 +15,12 @@ mut:
message_callbacks []MessageEventHandler // new message callback functions message_callbacks []MessageEventHandler // new message callback functions
close_callbacks []CloseEventHandler // close message callback functions close_callbacks []CloseEventHandler // close message callback functions
pub: pub:
port int // port used as listen to incoming connections port int // port used as listen to incoming connections
is_ssl bool // true if secure connection (not supported yet on server) is_ssl bool // true if secure connection (not supported yet on server)
pub mut: pub mut:
clients map[string]&ServerClient // clients connected to this server clients map[string]&ServerClient // clients connected to this server
ping_interval int = 30 // interval for sending ping to clients (seconds) ping_interval int = 30 // interval for sending ping to clients (seconds)
state State // current state of connection state State // current state of connection
} }
// ServerClient represents a connected client // ServerClient represents a connected client
@ -29,8 +29,8 @@ pub:
resource_name string // resource that the client access resource_name string // resource that the client access
client_key string // unique key of client client_key string // unique key of client
pub mut: pub mut:
server &Server server &Server
client &Client client &Client
} }
// new_server instance a new websocket server on provided port and route // new_server instance a new websocket server on provided port and route