fmt: align struct field comments (#7632)
parent
095857d59b
commit
dd516858d4
|
@ -18,8 +18,8 @@ pub mut:
|
|||
disable_help bool
|
||||
disable_version bool
|
||||
disable_flags bool
|
||||
sort_flags bool = true
|
||||
sort_commands bool = true
|
||||
sort_flags bool = true
|
||||
sort_commands bool = true
|
||||
parent &Command = 0
|
||||
commands []Command
|
||||
flags []Flag
|
||||
|
|
|
@ -4,7 +4,7 @@ module flag
|
|||
pub struct Flag {
|
||||
pub:
|
||||
name string // name as it appears on command line
|
||||
abbr byte // shortcut
|
||||
abbr byte // shortcut
|
||||
usage string // help message
|
||||
val_desc string // something like '<arg>' that appears in usage,
|
||||
// and also the default value, when the flag is not given
|
||||
|
|
10
vlib/gg/gg.v
10
vlib/gg/gg.v
|
@ -38,11 +38,11 @@ pub:
|
|||
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)
|
||||
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)
|
||||
|
|
|
@ -32,7 +32,7 @@ mut:
|
|||
dw_reserved0 u32
|
||||
dw_reserved1 u32
|
||||
c_file_name [260]u16 // max_path_len = 260
|
||||
c_alternate_file_name [14]u16 // 14
|
||||
c_alternate_file_name [14]u16 // 14
|
||||
dw_file_type u32
|
||||
dw_creator_type u32
|
||||
w_finder_flags u16
|
||||
|
|
|
@ -23,11 +23,11 @@ pub mut:
|
|||
// the exit code of the process, != -1 *only* when status is .exited *and* the process was not aborted
|
||||
status ProcessState = .not_started
|
||||
// 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
|
||||
env_is_custom bool // true, when the environment was customized with .set_environment
|
||||
env_is_custom bool // true, when the environment was customized with .set_environment
|
||||
env []string // the environment with which the process was started
|
||||
use_stdio_ctl bool // when true, then you can use p.stdin_write(), p.stdout_slurp() and p.stderr_slurp()
|
||||
use_stdio_ctl bool // when true, then you can use p.stdin_write(), p.stdout_slurp() and p.stderr_slurp()
|
||||
stdio_fd [3]int
|
||||
}
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ pub:
|
|||
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
|
||||
comments []Comment // comments before current const field
|
||||
}
|
||||
|
||||
// const declaration
|
||||
|
@ -176,7 +176,7 @@ pub:
|
|||
pos token.Position
|
||||
pub mut:
|
||||
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
|
||||
is_block bool // const() block
|
||||
}
|
||||
|
||||
|
@ -452,11 +452,11 @@ pub:
|
|||
global_scope &Scope
|
||||
pub mut:
|
||||
scope &Scope
|
||||
stmts []Stmt // all the statements in the source file
|
||||
stmts []Stmt // all the statements in the source file
|
||||
imports []Import // all the imports
|
||||
imported_symbols map[string]string // used for `import {symbol}`, it maps symbol => module.symbol
|
||||
errors []errors.Error // all the checker errors in the file
|
||||
warnings []errors.Warning // all the checker warings in the file
|
||||
errors []errors.Error // all the checker errors in the file
|
||||
warnings []errors.Warning // all the checker warings in the file
|
||||
generic_fns []&FnDecl
|
||||
}
|
||||
|
||||
|
@ -621,9 +621,9 @@ pub mut:
|
|||
|
||||
pub struct MatchBranch {
|
||||
pub:
|
||||
exprs []Expr // left side
|
||||
exprs []Expr // left side
|
||||
ecmnts [][]Comment // inline comments for each left side expr
|
||||
stmts []Stmt // right side
|
||||
stmts []Stmt // right side
|
||||
pos token.Position
|
||||
comments []Comment // comment above `xxx {`
|
||||
is_else bool
|
||||
|
@ -638,13 +638,13 @@ pub:
|
|||
pos token.Position
|
||||
has_exception bool
|
||||
pub mut:
|
||||
is_expr bool // returns a value
|
||||
is_expr bool // returns a value
|
||||
expected_type table.Type // for debugging only
|
||||
}
|
||||
|
||||
pub struct SelectBranch {
|
||||
pub:
|
||||
stmt Stmt // `a := <-ch` or `ch <- a`
|
||||
stmt Stmt // `a := <-ch` or `ch <- a`
|
||||
stmts []Stmt // right side
|
||||
pos token.Position
|
||||
comment Comment // comment above `select {`
|
||||
|
@ -696,7 +696,7 @@ pub mut:
|
|||
val_type table.Type
|
||||
cond_type table.Type
|
||||
kind table.Kind // array/map/string
|
||||
label string // `label: for {`
|
||||
label string // `label: for {`
|
||||
scope &Scope
|
||||
}
|
||||
|
||||
|
@ -778,8 +778,8 @@ pub:
|
|||
pos token.Position
|
||||
comments []Comment // comment after Enumfield in the same line
|
||||
next_comments []Comment // comments between current EnumField and next EnumField
|
||||
expr Expr // the value of current EnumField; 123 in `ename = 123`
|
||||
has_expr bool // true, when .expr has a value
|
||||
expr Expr // the value of current EnumField; 123 in `ename = 123`
|
||||
has_expr bool // true, when .expr has a value
|
||||
}
|
||||
|
||||
// enum declaration
|
||||
|
@ -787,10 +787,10 @@ pub struct EnumDecl {
|
|||
pub:
|
||||
name string
|
||||
is_pub bool
|
||||
is_flag bool // true when the enum has [flag] tag,for bit field enum
|
||||
is_multi_allowed bool // true when the enum has [_allow_multiple_values] tag
|
||||
comments []Comment // comments before the first EnumField
|
||||
fields []EnumField // all the enum fields
|
||||
is_flag bool // true when the enum has [flag] tag,for bit field enum
|
||||
is_multi_allowed bool // true when the enum has [_allow_multiple_values] tag
|
||||
comments []Comment // comments before the first EnumField
|
||||
fields []EnumField // all the enum fields
|
||||
attrs []table.Attr // attributes of enum declaration
|
||||
pos token.Position
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ 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
|
||||
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]!!`
|
||||
|
@ -883,7 +883,7 @@ pub:
|
|||
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{}]`
|
||||
is_interface bool // array of interfaces e.g. `[]Animal` `[Dog{}, Cat{}]`
|
||||
interface_type table.Type // Animal
|
||||
elem_type table.Type // element type
|
||||
typ table.Type // array type
|
||||
|
@ -939,8 +939,8 @@ 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)`
|
||||
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:
|
||||
|
@ -1085,13 +1085,13 @@ pub enum SqlStmtKind {
|
|||
pub struct SqlStmt {
|
||||
pub:
|
||||
kind SqlStmtKind
|
||||
db_expr Expr // `db` in `sql db {`
|
||||
db_expr Expr // `db` in `sql db {`
|
||||
object_var_name string // `user`
|
||||
table_type table.Type
|
||||
pos token.Position
|
||||
where_expr Expr
|
||||
updated_columns []string // for `update set x=y`
|
||||
update_exprs []Expr // for `update`
|
||||
update_exprs []Expr // for `update`
|
||||
pub mut:
|
||||
table_name string
|
||||
fields []table.Field
|
||||
|
@ -1211,10 +1211,10 @@ pub fn (stmt Stmt) check_c_expr() ? {
|
|||
// CTempVar is used in cgen only, to hold nodes for temporary variables
|
||||
pub struct CTempVar {
|
||||
pub:
|
||||
name string // the name of the C temporary variable; used by g.expr(x)
|
||||
orig Expr // the original expression, which produced the C temp variable; used by x.str()
|
||||
name string // the name of the C temporary variable; used by g.expr(x)
|
||||
orig Expr // the original expression, which produced the C temp variable; used by x.str()
|
||||
typ table.Type // the type of the original expression
|
||||
is_ptr bool // whether the type is a pointer
|
||||
is_ptr bool // whether the type is a pointer
|
||||
}
|
||||
|
||||
pub fn (stmt Stmt) position() token.Position {
|
||||
|
|
|
@ -41,7 +41,7 @@ pub mut:
|
|||
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
|
||||
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
|
||||
|
@ -49,24 +49,24 @@ pub mut:
|
|||
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
|
||||
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`?
|
||||
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
|
||||
expr_level int // to avoid infinite recursion segfaults due to compiler bugs
|
||||
inside_sql bool // to handle sql table fields pseudo variables
|
||||
cur_orm_ts table.TypeSymbol
|
||||
error_details []string
|
||||
vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path**
|
||||
vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path**
|
||||
vweb_gen_types []table.Type // vweb route checks
|
||||
prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
|
||||
prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
|
||||
loop_label string // set when inside a labelled for loop
|
||||
timers &util.Timers = util.new_timers(false)
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ pub struct Doc {
|
|||
prefs &pref.Preferences = new_vdoc_preferences()
|
||||
pub mut:
|
||||
base_path string
|
||||
table &table.Table = &table.Table{}
|
||||
table &table.Table = &table.Table{}
|
||||
checker checker.Checker = checker.Checker{
|
||||
table: 0
|
||||
cur_fn: 0
|
||||
|
|
137
vlib/v/fmt/fmt.v
137
vlib/v/fmt/fmt.v
|
@ -26,20 +26,20 @@ pub mut:
|
|||
indent int
|
||||
empty_line bool
|
||||
line_len int
|
||||
buffering bool // expressions will be analyzed later by adjust_complete_line() before finally written
|
||||
buffering bool // expressions will be analyzed later by adjust_complete_line() before finally written
|
||||
expr_bufs []string // and stored here in the meantime (expr_bufs.len-1 = penalties.len = precedences.len)
|
||||
penalties []int // how hard should it be to break line after each expression
|
||||
precedences []int // operator/parenthese precedences for operator at end of each expression
|
||||
par_level int // how many parentheses are put around the current expression
|
||||
array_init_break []bool // line breaks after elements in hierarchy level of multi dimensional array
|
||||
array_init_depth int // current level of hierarchie in array init
|
||||
penalties []int // how hard should it be to break line after each expression
|
||||
precedences []int // operator/parenthese precedences for operator at end of each expression
|
||||
par_level int // how many parentheses are put around the current expression
|
||||
array_init_break []bool // line breaks after elements in hierarchy level of multi dimensional array
|
||||
array_init_depth int // current level of hierarchie in array init
|
||||
single_line_if bool
|
||||
cur_mod string
|
||||
file ast.File
|
||||
did_imports bool
|
||||
is_assign bool
|
||||
auto_imports []string // automatically inserted imports that the user forgot to specify
|
||||
import_pos int // position of the imports in the resulting string for later autoimports insertion
|
||||
import_pos int // position of the imports in the resulting string for later autoimports insertion
|
||||
used_imports []string // to remove unused imports
|
||||
is_debug bool
|
||||
mod2alias map[string]string // for `import time as t`, will contain: 'time'=>'t'
|
||||
|
@ -580,6 +580,60 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
|
|||
f.writeln('\n')
|
||||
}
|
||||
|
||||
const (
|
||||
threshold_to_align_struct = 8
|
||||
)
|
||||
|
||||
struct CommentAndExprAlignInfo {
|
||||
mut:
|
||||
max_attrs_len int
|
||||
max_type_len int
|
||||
first_line int
|
||||
last_line int
|
||||
}
|
||||
|
||||
fn (mut list []CommentAndExprAlignInfo) add_new_info(attrs_len int, type_len int, line int) {
|
||||
list << CommentAndExprAlignInfo{
|
||||
max_attrs_len: attrs_len
|
||||
max_type_len: type_len
|
||||
first_line: line
|
||||
last_line: line
|
||||
}
|
||||
}
|
||||
|
||||
[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)
|
||||
return
|
||||
}
|
||||
i := list.len - 1
|
||||
if line - list[i].last_line > 1 {
|
||||
list.add_new_info(attrs_len, type_len, line)
|
||||
return
|
||||
}
|
||||
d_len := abs(list[i].max_attrs_len - attrs_len) + abs(list[i].max_type_len - type_len)
|
||||
if !(d_len < threshold_to_align_struct) {
|
||||
list.add_new_info(attrs_len, type_len, line)
|
||||
return
|
||||
}
|
||||
list[i].last_line = line
|
||||
if attrs_len > list[i].max_attrs_len {
|
||||
list[i].max_attrs_len = attrs_len
|
||||
}
|
||||
if type_len > list[i].max_type_len {
|
||||
list[i].max_type_len = type_len
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
||||
f.attrs(node.attrs)
|
||||
if node.is_pub {
|
||||
|
@ -605,14 +659,28 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||
}
|
||||
f.writeln(' {')
|
||||
mut max := 0
|
||||
mut max_type := 0
|
||||
mut max_type_len := 0
|
||||
mut comment_aligns := []CommentAndExprAlignInfo{}
|
||||
mut default_expr_aligns := []CommentAndExprAlignInfo{}
|
||||
mut field_types := []string{cap: node.fields.len}
|
||||
for field in node.fields {
|
||||
for i, field in node.fields {
|
||||
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
||||
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') {
|
||||
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
|
||||
for comment in field.comments {
|
||||
if comment.pos.pos >= end_pos {
|
||||
break
|
||||
if comment.pos.line_nr == field.pos.line_nr {
|
||||
comment_aligns.add_info(attrs_len, field_types[i].len, comment.pos.line_nr)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if comment.pos.pos > field.pos.pos {
|
||||
comments_len += '/* $comment.text */ '.len
|
||||
|
@ -621,19 +689,16 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||
if comments_len + field.name.len > max {
|
||||
max = comments_len + field.name.len
|
||||
}
|
||||
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
||||
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') {
|
||||
ft = f.short_module(ft)
|
||||
}
|
||||
field_types << ft
|
||||
if ft.len > max_type {
|
||||
max_type = ft.len
|
||||
if field.has_default_expr {
|
||||
default_expr_aligns.add_info(attrs_len, field_types[i].len, field.pos.line_nr)
|
||||
}
|
||||
}
|
||||
for embed in node.embeds {
|
||||
styp := f.table.type_to_str(embed.typ)
|
||||
f.writeln('\t$styp')
|
||||
}
|
||||
mut comment_align_i := 0
|
||||
mut default_expr_align_i := 0
|
||||
for i, field in node.fields {
|
||||
if i == node.mut_pos {
|
||||
f.writeln('mut:')
|
||||
|
@ -665,11 +730,21 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||
}
|
||||
f.write(strings.repeat(` `, max - field.name.len - comments_len))
|
||||
f.write(field_types[i])
|
||||
if field.attrs.len > 0 {
|
||||
f.write(strings.repeat(` `, max_type - field_types[i].len))
|
||||
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.inline_attrs(field.attrs)
|
||||
}
|
||||
if field.has_default_expr {
|
||||
mut align := default_expr_aligns[default_expr_align_i]
|
||||
if align.last_line < field.pos.line_nr {
|
||||
default_expr_align_i++
|
||||
align = default_expr_aligns[default_expr_align_i]
|
||||
}
|
||||
pad_len := align.max_attrs_len - attrs_len + align.max_type_len - field_types[i].len
|
||||
f.write(strings.repeat(` `, pad_len))
|
||||
f.write(' = ')
|
||||
f.prefix_expr_cast_expr(field.default_expr)
|
||||
}
|
||||
|
@ -678,6 +753,15 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||
if comments[comm_idx].pos.line_nr > field.pos.line_nr {
|
||||
f.writeln('')
|
||||
} else {
|
||||
if !field.has_default_expr {
|
||||
mut align := comment_aligns[comment_align_i]
|
||||
if align.last_line < field.pos.line_nr {
|
||||
comment_align_i++
|
||||
align = comment_aligns[comment_align_i]
|
||||
}
|
||||
pad_len := align.max_attrs_len - attrs_len + align.max_type_len - field_types[i].len
|
||||
f.write(strings.repeat(` `, pad_len))
|
||||
}
|
||||
f.write(' ')
|
||||
}
|
||||
f.comments(comments[comm_idx..], level: .indent)
|
||||
|
@ -1230,6 +1314,21 @@ fn (mut f Fmt) inline_attrs(attrs []table.Attr) {
|
|||
f.write(']')
|
||||
}
|
||||
|
||||
fn inline_attrs_len(attrs []table.Attr) int {
|
||||
if attrs.len == 0 {
|
||||
return 0
|
||||
}
|
||||
mut n := 2 // ' ['.len
|
||||
for i, attr in attrs {
|
||||
if i > 0 {
|
||||
n += 2 // '; '.len
|
||||
}
|
||||
n += '$attr'.len
|
||||
}
|
||||
n++ // ']'.len
|
||||
return n
|
||||
}
|
||||
|
||||
enum CommentsLevel {
|
||||
keep
|
||||
indent
|
||||
|
|
|
@ -3,12 +3,12 @@ struct Foo {
|
|||
}
|
||||
|
||||
struct Bar {
|
||||
f Foo = &Foo(0)
|
||||
f Foo = &Foo(0)
|
||||
z int [skip] = -1
|
||||
}
|
||||
|
||||
struct Baz {
|
||||
x int = 1 // It's one
|
||||
x int = 1 // It's one
|
||||
y string = 'one' // It's one written out
|
||||
z bool = true // Also one
|
||||
z bool = true // Also one
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ struct Foo {
|
|||
|
||||
struct Bar {
|
||||
f &Foo = &Foo(0)
|
||||
d Foo = Foo{0}
|
||||
d Foo = Foo{0}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
struct User {
|
||||
name string
|
||||
very_long_field bool
|
||||
age int
|
||||
name string // name
|
||||
name2 ustring // name2
|
||||
very_long_field bool
|
||||
age int // age
|
||||
very_long_type_field1 very_looooog_type // long
|
||||
very_long_type_field2 very_loooooooong_type // long
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
field1 int
|
||||
field2 string
|
||||
field1 int // f1
|
||||
field2 string // f2
|
||||
pub:
|
||||
public_field1 int
|
||||
public_field2 f64
|
||||
public_field1 int // f1
|
||||
public_field2 f64 // f2
|
||||
mut:
|
||||
mut_field string
|
||||
pub mut:
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
struct User {
|
||||
name string
|
||||
name string // name
|
||||
name2 ustring // name2
|
||||
very_long_field bool
|
||||
age int
|
||||
age int // age
|
||||
very_long_type_field1 very_looooog_type // long
|
||||
very_long_type_field2 very_loooooooong_type // long
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
field1 int
|
||||
field2 string
|
||||
field1 int // f1
|
||||
field2 string // f2
|
||||
pub:
|
||||
public_field1 int
|
||||
public_field2 f64
|
||||
public_field1 int // f1
|
||||
public_field2 f64 // f2
|
||||
mut:
|
||||
mut_field string
|
||||
pub mut:
|
||||
|
|
|
@ -54,28 +54,28 @@ mut:
|
|||
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
|
||||
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
|
||||
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 {...}`
|
||||
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<</+=/-= infix expr
|
||||
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<</+=/-= infix expr
|
||||
// inside_if_expr bool
|
||||
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)
|
||||
skip_stmt_pos bool // for handling if expressions + autofree (since both prepend C statements)
|
||||
right_is_opt bool
|
||||
autofree bool
|
||||
indent int
|
||||
|
@ -91,7 +91,7 @@ mut:
|
|||
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()
|
||||
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
|
||||
|
@ -129,7 +129,7 @@ mut:
|
|||
// 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
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -42,15 +42,15 @@ mut:
|
|||
inside_for bool
|
||||
inside_fn bool
|
||||
inside_str_interp bool
|
||||
or_is_handled bool // ignore `or` in this expression
|
||||
builtin_mod bool // are we in the `builtin` module?
|
||||
mod string // current module name
|
||||
or_is_handled bool // ignore `or` in this expression
|
||||
builtin_mod bool // are we in the `builtin` module?
|
||||
mod string // current module name
|
||||
attrs []table.Attr // attributes before next decl stmt
|
||||
expr_mod string // for constructing full type names in parse_type()
|
||||
expr_mod string // for constructing full type names in parse_type()
|
||||
scope &ast.Scope
|
||||
global_scope &ast.Scope
|
||||
imports map[string]string // alias => mod_name
|
||||
ast_imports []ast.Import // mod_names
|
||||
ast_imports []ast.Import // mod_names
|
||||
used_imports []string // alias
|
||||
imported_symbols map[string]string
|
||||
is_amp bool // for generating the right code for `&Foo{}`
|
||||
|
|
|
@ -56,18 +56,18 @@ pub mut:
|
|||
// verbosity VerboseLevel
|
||||
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
|
||||
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"
|
||||
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
|
||||
|
@ -87,8 +87,8 @@ pub mut:
|
|||
// 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
|
||||
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
|
||||
|
@ -103,7 +103,7 @@ pub mut:
|
|||
is_fmt bool
|
||||
is_vet 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
|
||||
lookup_path []string
|
||||
output_cross_c bool
|
||||
|
@ -115,17 +115,17 @@ pub mut:
|
|||
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']
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
|
||||
print_v_files bool // when true, just print the list of all parsed .v files then stop.
|
||||
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
|
||||
skip_warnings bool // like C's "-w", forces warnings to be ignored.
|
||||
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
|
||||
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
|
||||
fatal_errors bool // unconditionally exit after the first error with exit(1)
|
||||
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
|
||||
compile_defines []string // just ['vfmt']
|
||||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
|
||||
print_v_files bool // when true, just print the list of all parsed .v files then stop.
|
||||
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
|
||||
skip_warnings bool // like C's "-w", forces warnings to be ignored.
|
||||
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
|
||||
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
|
||||
fatal_errors bool // unconditionally exit after the first error with exit(1)
|
||||
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
|
||||
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
|
||||
is_parallel bool
|
||||
error_limit int
|
||||
|
@ -134,7 +134,7 @@ pub mut:
|
|||
experimental bool // enable experimental features
|
||||
show_timings bool // show how much time each compiler stage took
|
||||
is_ios_simulator bool
|
||||
is_apk bool // build as Android .apk format
|
||||
is_apk bool // build as Android .apk format
|
||||
cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successfull builds.
|
||||
build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache
|
||||
cache_manager vcache.CacheManager
|
||||
|
|
|
@ -37,9 +37,9 @@ pub mut:
|
|||
quote byte // which quote is used to denote current string: ' or "
|
||||
inter_quote byte
|
||||
line_ends []int // the positions of source lines ends (i.e. \n signs)
|
||||
nr_lines int // total number of lines in the source file that were scanned
|
||||
is_vh bool // Keep newlines
|
||||
is_fmt bool // Used for v fmt.
|
||||
nr_lines int // total number of lines in the source file that were scanned
|
||||
is_vh bool // Keep newlines
|
||||
is_fmt bool // Used for v fmt.
|
||||
comments_mode CommentsMode
|
||||
is_inside_toplvl_statement bool // *only* used in comments_mode: .toplevel_comments, toggled by parser
|
||||
all_tokens []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
|
||||
|
|
|
@ -7,10 +7,10 @@ module table
|
|||
pub struct Attr {
|
||||
pub:
|
||||
name string // [name]
|
||||
is_string bool // ['name']
|
||||
is_ctdefine bool // [if name]
|
||||
is_string bool // ['name']
|
||||
is_ctdefine bool // [if name]
|
||||
arg string // [name: arg]
|
||||
is_string_arg bool // [name: 'arg']
|
||||
is_string_arg bool // [name: 'arg']
|
||||
}
|
||||
|
||||
// no square brackets
|
||||
|
|
|
@ -209,7 +209,7 @@ fn testsuite_end() {
|
|||
|
||||
// utility code:
|
||||
struct SimpleTcpClientConfig {
|
||||
retries int = 20
|
||||
retries int = 20
|
||||
host string = 'static.dev'
|
||||
path string = '/'
|
||||
agent string = 'v/net.tcp.v'
|
||||
|
|
|
@ -2,33 +2,33 @@ module websocket
|
|||
|
||||
// MessageEventHandler represents a callback on a new message
|
||||
struct MessageEventHandler {
|
||||
handler SocketMessageFn // callback function
|
||||
handler SocketMessageFn // callback function
|
||||
handler2 SocketMessageFn2 // callback function with reference
|
||||
is_ref bool // true if has a reference object
|
||||
is_ref bool // true if has a reference object
|
||||
ref voidptr // referenced object
|
||||
}
|
||||
|
||||
// ErrorEventHandler represents a callback on error
|
||||
struct ErrorEventHandler {
|
||||
handler SocketErrorFn // callback function
|
||||
handler SocketErrorFn // callback function
|
||||
handler2 SocketErrorFn2 // callback function with reference
|
||||
is_ref bool // true if has a reference object
|
||||
is_ref bool // true if has a reference object
|
||||
ref voidptr // referenced object
|
||||
}
|
||||
|
||||
// OpenEventHandler represents a callback when connection is opened
|
||||
struct OpenEventHandler {
|
||||
handler SocketOpenFn // callback function
|
||||
handler SocketOpenFn // callback function
|
||||
handler2 SocketOpenFn2 // callback function with reference
|
||||
is_ref bool // true if has a reference object
|
||||
is_ref bool // true if has a reference object
|
||||
ref voidptr // referenced object
|
||||
}
|
||||
|
||||
// CloseEventHandler represents a callback on a closing event
|
||||
struct CloseEventHandler {
|
||||
handler SocketCloseFn // callback function
|
||||
handler SocketCloseFn // callback function
|
||||
handler2 SocketCloseFn2 // callback function with reference
|
||||
is_ref bool // true if has a reference object
|
||||
is_ref bool // true if has a reference object
|
||||
ref voidptr // referenced object
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ mut:
|
|||
header_len int = 2
|
||||
// size of total frame
|
||||
frame_size int = 2
|
||||
fin bool // true if final fragment of message
|
||||
rsv1 bool // reserved for future use in websocket RFC
|
||||
rsv2 bool // reserved for future use in websocket RFC
|
||||
rsv3 bool // reserved for future use in websocket RFC
|
||||
opcode OPCode // interpretation of the payload data
|
||||
has_mask bool // true if the payload data is masked
|
||||
payload_len int // payload length
|
||||
fin bool // true if final fragment of message
|
||||
rsv1 bool // reserved for future use in websocket RFC
|
||||
rsv2 bool // reserved for future use in websocket RFC
|
||||
rsv3 bool // reserved for future use in websocket RFC
|
||||
opcode OPCode // interpretation of the payload data
|
||||
has_mask bool // true if the payload data is masked
|
||||
payload_len int // payload length
|
||||
masking_key [4]byte // all frames from client to server is masked with this key
|
||||
}
|
||||
|
||||
|
|
|
@ -19,24 +19,24 @@ pub struct Client {
|
|||
is_server bool
|
||||
mut:
|
||||
ssl_conn &openssl.SSLConn // secure connection used when wss is used
|
||||
flags []Flag // flags used in handshake
|
||||
flags []Flag // flags used in handshake
|
||||
fragments []Fragment // current fragments
|
||||
message_callbacks []MessageEventHandler // all callbacks on_message
|
||||
error_callbacks []ErrorEventHandler // all callbacks on_error
|
||||
open_callbacks []OpenEventHandler // all callbacks on_open
|
||||
close_callbacks []CloseEventHandler // all callbacks on_close
|
||||
error_callbacks []ErrorEventHandler // all callbacks on_error
|
||||
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
|
||||
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
|
||||
panic_on_callback bool // set to true of callbacks can panic
|
||||
state State // current state of connection
|
||||
panic_on_callback bool // set to true of callbacks can panic
|
||||
state State // current state of connection
|
||||
logger &log.Log // logger used to log messages
|
||||
resource_name string // name of current resource
|
||||
last_pong_ut u64 // last time in unix time we got a pong message
|
||||
resource_name string // name of current resource
|
||||
last_pong_ut u64 // last time in unix time we got a pong message
|
||||
}
|
||||
|
||||
// Flag represents different types of headers in websocket handshake
|
||||
|
|
|
@ -11,13 +11,13 @@ import rand
|
|||
pub struct Server {
|
||||
mut:
|
||||
clients map[string]&ServerClient // clients connected to this server
|
||||
logger &log.Log // logger used to log
|
||||
ls net.TcpListener // listener used to get incoming connection to socket
|
||||
accept_client_callbacks []AcceptClientFn // accept client callback functions
|
||||
logger &log.Log // logger used to log
|
||||
ls net.TcpListener // listener used to get incoming connection to socket
|
||||
accept_client_callbacks []AcceptClientFn // accept client callback functions
|
||||
message_callbacks []MessageEventHandler // new message callback functions
|
||||
close_callbacks []CloseEventHandler // close message callback functions
|
||||
close_callbacks []CloseEventHandler // close message callback functions
|
||||
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)
|
||||
pub mut:
|
||||
ping_interval int = 30
|
||||
|
|
Loading…
Reference in New Issue